@xpadev-net/niconicomments 0.2.25 → 0.2.27
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.d.ts +115 -46
- package/dist/bundle.js +334 -180
- package/package.json +2 -2
package/dist/bundle.d.ts
CHANGED
|
@@ -1,27 +1,11 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
[key: string]: string;
|
|
3
|
-
};
|
|
4
|
-
declare const commentYPaddingTop = 0.08;
|
|
5
|
-
declare const commentYMarginBottom = 0.24;
|
|
6
|
-
declare const fontSize: typeFontSize;
|
|
7
|
-
declare const lineHeight: typeFontSize;
|
|
8
|
-
declare const doubleResizeMaxWidth: typeDoubleResizeMaxWidth;
|
|
1
|
+
declare const defaultConfig: Config;
|
|
9
2
|
declare const defaultOptions: Options;
|
|
10
|
-
declare
|
|
11
|
-
declare
|
|
12
|
-
declare const
|
|
13
|
-
declare const
|
|
14
|
-
declare const commentDrawRange = 1450;
|
|
15
|
-
declare const commentDrawPadding: number;
|
|
16
|
-
declare const collisionRange: {
|
|
17
|
-
left: number;
|
|
18
|
-
right: number;
|
|
19
|
-
};
|
|
20
|
-
declare const sameCARange = 3600;
|
|
21
|
-
declare const sameCAGap = 100;
|
|
22
|
-
declare const sameCAMinScore = 10;
|
|
3
|
+
declare let config: Config;
|
|
4
|
+
declare let options: Options;
|
|
5
|
+
declare const setConfig: (value: Config) => Config;
|
|
6
|
+
declare const setOptions: (value: Options) => Options;
|
|
23
7
|
|
|
24
|
-
|
|
8
|
+
|
|
25
9
|
type inputFormatType =
|
|
26
10
|
| "niconicome"
|
|
27
11
|
| "formatted"
|
|
@@ -30,31 +14,38 @@ type inputFormatType =
|
|
|
30
14
|
| "owner"
|
|
31
15
|
| "v1"
|
|
32
16
|
| "default";
|
|
17
|
+
type modeType = "default" | "html5" | "flash";
|
|
33
18
|
type InitOptions = {
|
|
34
|
-
|
|
35
|
-
formatted?: boolean;
|
|
36
|
-
format?: inputFormatType;
|
|
37
|
-
video?: HTMLVideoElement | undefined;
|
|
38
|
-
showCollision?: boolean;
|
|
39
|
-
showFPS?: boolean;
|
|
40
|
-
showCommentCount?: boolean;
|
|
41
|
-
drawAllImageOnLoad?: boolean;
|
|
19
|
+
config?: ConfigNullable;
|
|
42
20
|
debug?: boolean;
|
|
21
|
+
drawAllImageOnLoad?: boolean;
|
|
43
22
|
enableLegacyPiP?: boolean;
|
|
23
|
+
format?: inputFormatType;
|
|
24
|
+
formatted?: boolean;
|
|
44
25
|
keepCA?: boolean;
|
|
26
|
+
mode?: modeType;
|
|
27
|
+
scale?: number;
|
|
28
|
+
showCollision?: boolean;
|
|
29
|
+
showCommentCount?: boolean;
|
|
30
|
+
showFPS?: boolean;
|
|
31
|
+
useLegacy?: boolean;
|
|
32
|
+
video?: HTMLVideoElement | undefined;
|
|
45
33
|
};
|
|
46
34
|
type Options = {
|
|
47
|
-
|
|
48
|
-
formatted: boolean;
|
|
49
|
-
format: inputFormatType;
|
|
50
|
-
video: HTMLVideoElement | undefined;
|
|
51
|
-
showCollision: boolean;
|
|
52
|
-
showFPS: boolean;
|
|
53
|
-
showCommentCount: boolean;
|
|
54
|
-
drawAllImageOnLoad: boolean;
|
|
35
|
+
config: ConfigNullable;
|
|
55
36
|
debug: boolean;
|
|
37
|
+
drawAllImageOnLoad: boolean;
|
|
56
38
|
enableLegacyPiP: boolean;
|
|
39
|
+
format: inputFormatType;
|
|
40
|
+
formatted: boolean;
|
|
57
41
|
keepCA: boolean;
|
|
42
|
+
mode: modeType;
|
|
43
|
+
scale: number;
|
|
44
|
+
showCollision: boolean;
|
|
45
|
+
showCommentCount: boolean;
|
|
46
|
+
showFPS: boolean;
|
|
47
|
+
useLegacy: boolean;
|
|
48
|
+
video: HTMLVideoElement | undefined;
|
|
58
49
|
};
|
|
59
50
|
type rawApiResponse = {
|
|
60
51
|
[key: string]: apiPing | apiThread | apiLeaf | apiGlobalNumRes | apiChat;
|
|
@@ -218,8 +209,9 @@ type typeFontSize = {
|
|
|
218
209
|
};
|
|
219
210
|
type typeDoubleResizeMaxWidth = {
|
|
220
211
|
[key in "full" | "normal"]: {
|
|
221
|
-
|
|
212
|
+
html5: number;
|
|
222
213
|
default: number;
|
|
214
|
+
flash: number;
|
|
223
215
|
};
|
|
224
216
|
};
|
|
225
217
|
type v1Thread = {
|
|
@@ -248,10 +240,83 @@ type ownerComment = {
|
|
|
248
240
|
command: string;
|
|
249
241
|
comment: string;
|
|
250
242
|
};
|
|
243
|
+
type Config = {
|
|
244
|
+
colors: { [key: string]: string };
|
|
245
|
+
commentYPaddingTop: number;
|
|
246
|
+
commentYMarginBottom: number;
|
|
247
|
+
fontSize: typeFontSize;
|
|
248
|
+
lineHeight: typeFontSize;
|
|
249
|
+
doubleResizeMaxWidth: typeDoubleResizeMaxWidth;
|
|
250
|
+
contextStrokeColor: string;
|
|
251
|
+
contextStrokeInversionColor: string;
|
|
252
|
+
contextStrokeOpacity: number;
|
|
253
|
+
contextFillLiveOpacity: number;
|
|
254
|
+
contextLineWidth: number;
|
|
255
|
+
fpsInterval: number;
|
|
256
|
+
cacheAge: number;
|
|
257
|
+
canvasWidth: number;
|
|
258
|
+
canvasHeight: number;
|
|
259
|
+
commentDrawRange: number;
|
|
260
|
+
commentDrawPadding: number;
|
|
261
|
+
collisionWidth: number;
|
|
262
|
+
collisionRange: { [key in "left" | "right"]: number };
|
|
263
|
+
sameCARange: number;
|
|
264
|
+
sameCAGap: number;
|
|
265
|
+
sameCAMinScore: number;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
type ConfigNullable = {
|
|
269
|
+
colors?: { [key: string]: string };
|
|
270
|
+
commentYPaddingTop?: number;
|
|
271
|
+
commentYMarginBottom?: number;
|
|
272
|
+
fontSize?: typeFontSize;
|
|
273
|
+
lineHeight?: typeFontSize;
|
|
274
|
+
doubleResizeMaxWidth?: typeDoubleResizeMaxWidth;
|
|
275
|
+
fpsInterval?: number;
|
|
276
|
+
cacheAge?: number;
|
|
277
|
+
canvasWidth?: number;
|
|
278
|
+
canvasHeight?: number;
|
|
279
|
+
commentDrawRange?: number;
|
|
280
|
+
commentDrawPadding?: number;
|
|
281
|
+
collisionWidth?: number;
|
|
282
|
+
collisionRange?: { [key in "left" | "right"]: number };
|
|
283
|
+
sameCARange?: number;
|
|
284
|
+
sameCAGap?: number;
|
|
285
|
+
sameCAMinScore?: number;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
type ConfigKeys =
|
|
289
|
+
| "colors"
|
|
290
|
+
| "commentYPaddingTop"
|
|
291
|
+
| "commentYMarginBottom"
|
|
292
|
+
| "fontSize"
|
|
293
|
+
| "lineHeight"
|
|
294
|
+
| "doubleResizeMaxWidth"
|
|
295
|
+
| "fpsInterval"
|
|
296
|
+
| "cacheAge"
|
|
297
|
+
| "canvasWidth"
|
|
298
|
+
| "canvasHeight"
|
|
299
|
+
| "commentDrawRange"
|
|
300
|
+
| "commentDrawPadding"
|
|
301
|
+
| "collisionWidth"
|
|
302
|
+
| "collisionRange"
|
|
303
|
+
| "sameCARange"
|
|
304
|
+
| "sameCAGap"
|
|
305
|
+
| "sameCAMinScore";
|
|
306
|
+
|
|
307
|
+
type T_Type =
|
|
308
|
+
| "string"
|
|
309
|
+
| "number"
|
|
310
|
+
| "bigint"
|
|
311
|
+
| "boolean"
|
|
312
|
+
| "symbol"
|
|
313
|
+
| "undefined"
|
|
314
|
+
| "object"
|
|
315
|
+
| "function";
|
|
251
316
|
|
|
252
317
|
declare const convert2formattedComment: (data: unknown, type: inputFormatType) => formattedComment[];
|
|
253
318
|
|
|
254
|
-
|
|
319
|
+
|
|
255
320
|
declare class NiconiComments {
|
|
256
321
|
enableLegacyPiP: boolean;
|
|
257
322
|
showCollision: boolean;
|
|
@@ -266,10 +331,9 @@ declare class NiconiComments {
|
|
|
266
331
|
private readonly canvas;
|
|
267
332
|
private readonly collision;
|
|
268
333
|
private readonly context;
|
|
269
|
-
private readonly keepCA;
|
|
270
334
|
private readonly nicoScripts;
|
|
271
335
|
private readonly timeline;
|
|
272
|
-
private readonly
|
|
336
|
+
private readonly mode;
|
|
273
337
|
constructor(canvas: HTMLCanvasElement, data: (rawApiResponse | formattedComment)[], initOptions?: InitOptions);
|
|
274
338
|
preRendering(rawData: formattedComment[], drawAll: boolean): void;
|
|
275
339
|
getFont(parsedData: formattedComment[]): formattedCommentWithFont[];
|
|
@@ -297,7 +361,7 @@ declare class NiconiComments {
|
|
|
297
361
|
clear(): void;
|
|
298
362
|
}
|
|
299
363
|
|
|
300
|
-
|
|
364
|
+
|
|
301
365
|
declare const typeGuard: {
|
|
302
366
|
formatted: {
|
|
303
367
|
comment: (i: unknown) => i is formattedComment;
|
|
@@ -346,9 +410,14 @@ declare const typeGuard: {
|
|
|
346
410
|
key: (i: unknown) => i is "full" | "ender" | "_live" | "invisible";
|
|
347
411
|
};
|
|
348
412
|
};
|
|
413
|
+
config: {
|
|
414
|
+
initOptions: (item: unknown) => item is InitOptions;
|
|
415
|
+
config: (item: unknown) => item is ConfigNullable;
|
|
416
|
+
configKey: (item: unknown) => item is ConfigKeys;
|
|
417
|
+
};
|
|
349
418
|
};
|
|
350
419
|
|
|
351
|
-
|
|
420
|
+
|
|
352
421
|
declare const groupBy: (array: formattedCommentWithFont[]) => groupedComments;
|
|
353
422
|
declare const getPosY: (currentPos: number, targetComment: parsedComment, collision: number[] | undefined, data: parsedComment[]) => {
|
|
354
423
|
currentPos: number;
|
|
@@ -356,7 +425,7 @@ declare const getPosY: (currentPos: number, targetComment: parsedComment, collis
|
|
|
356
425
|
isBreak: boolean;
|
|
357
426
|
};
|
|
358
427
|
declare const getPosX: (width: number, vpos: number, long: number) => number;
|
|
359
|
-
declare const parseFont: (font: commentFont, size: string | number,
|
|
428
|
+
declare const parseFont: (font: commentFont, size: string | number, mode?: modeType) => string;
|
|
360
429
|
declare const arrayPush: (array: {
|
|
361
430
|
[key: number]: number[];
|
|
362
431
|
}, key: string | number, push: number) => void;
|
|
@@ -364,5 +433,5 @@ declare const hex2rgb: (hex: string) => number[];
|
|
|
364
433
|
declare const replaceAll: (string: string, target: string, replace: string) => string;
|
|
365
434
|
declare const changeCALayer: (rawData: formattedComment[]) => formattedComment[];
|
|
366
435
|
|
|
367
|
-
|
|
436
|
+
|
|
368
437
|
export default NiconiComments;
|
package/dist/bundle.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
niconicomments.js v0.2.
|
|
2
|
+
niconicomments.js v0.2.27
|
|
3
3
|
(c) 2021 xpadev-net https://xpadev.net
|
|
4
4
|
Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
var typeGuard = {
|
|
38
38
|
formatted: {
|
|
39
39
|
comment: function (i) {
|
|
40
|
-
return
|
|
40
|
+
return objectVerify(i, [
|
|
41
41
|
"id",
|
|
42
42
|
"vpos",
|
|
43
43
|
"content",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
return true;
|
|
62
62
|
},
|
|
63
63
|
legacyComment: function (i) {
|
|
64
|
-
return
|
|
64
|
+
return objectVerify(i, [
|
|
65
65
|
"id",
|
|
66
66
|
"vpos",
|
|
67
67
|
"content",
|
|
@@ -106,15 +106,15 @@
|
|
|
106
106
|
},
|
|
107
107
|
apiChat: function (i) {
|
|
108
108
|
return typeof i === "object" &&
|
|
109
|
-
|
|
109
|
+
objectVerify(i, ["content", "date", "no", "thread", "vpos"]);
|
|
110
110
|
},
|
|
111
111
|
apiGlobalNumRes: function (i) {
|
|
112
|
-
return
|
|
112
|
+
return objectVerify(i, ["num_res", "thread"]);
|
|
113
113
|
},
|
|
114
|
-
apiLeaf: function (i) { return
|
|
115
|
-
apiPing: function (i) { return
|
|
114
|
+
apiLeaf: function (i) { return objectVerify(i, ["count", "thread"]); },
|
|
115
|
+
apiPing: function (i) { return objectVerify(i, ["content"]); },
|
|
116
116
|
apiThread: function (i) {
|
|
117
|
-
return
|
|
117
|
+
return objectVerify(i, [
|
|
118
118
|
"resultcode",
|
|
119
119
|
"revision",
|
|
120
120
|
"server_time",
|
|
@@ -182,7 +182,7 @@
|
|
|
182
182
|
},
|
|
183
183
|
owner: {
|
|
184
184
|
comment: function (i) {
|
|
185
|
-
return
|
|
185
|
+
return objectVerify(i, ["time", "command", "comment"]);
|
|
186
186
|
},
|
|
187
187
|
comments: function (i) {
|
|
188
188
|
if (typeof i !== "object")
|
|
@@ -197,7 +197,7 @@
|
|
|
197
197
|
},
|
|
198
198
|
v1: {
|
|
199
199
|
comment: function (i) {
|
|
200
|
-
return
|
|
200
|
+
return objectVerify(i, [
|
|
201
201
|
"id",
|
|
202
202
|
"no",
|
|
203
203
|
"vposMs",
|
|
@@ -214,7 +214,7 @@
|
|
|
214
214
|
]);
|
|
215
215
|
},
|
|
216
216
|
thread: function (i) {
|
|
217
|
-
if (!
|
|
217
|
+
if (!objectVerify(i, ["id", "fork", "commentCount", "comments"]))
|
|
218
218
|
return false;
|
|
219
219
|
for (var _i = 0, _a = Object.keys(i.comments); _i < _a.length; _i++) {
|
|
220
220
|
var item = _a[_i];
|
|
@@ -269,8 +269,127 @@
|
|
|
269
269
|
},
|
|
270
270
|
},
|
|
271
271
|
},
|
|
272
|
+
config: {
|
|
273
|
+
initOptions: function (item) {
|
|
274
|
+
if (typeof item !== "object" || !item)
|
|
275
|
+
return false;
|
|
276
|
+
var keys = {
|
|
277
|
+
useLegacy: isBoolean,
|
|
278
|
+
formatted: isBoolean,
|
|
279
|
+
showCollision: isBoolean,
|
|
280
|
+
showFPS: isBoolean,
|
|
281
|
+
showCommentCount: isBoolean,
|
|
282
|
+
drawAllImageOnLoad: isBoolean,
|
|
283
|
+
debug: isBoolean,
|
|
284
|
+
enableLegacyPiP: isBoolean,
|
|
285
|
+
keepCA: isBoolean,
|
|
286
|
+
scale: isNumber,
|
|
287
|
+
config: typeGuard.config.config,
|
|
288
|
+
format: function (i) {
|
|
289
|
+
return typeof i === "string" &&
|
|
290
|
+
!!i.match(/^(niconicome|formatted|legacy|legacyOwner|owner|v1|default)$/);
|
|
291
|
+
},
|
|
292
|
+
video: function (i) {
|
|
293
|
+
return typeof i === "object" && i.nodeName === "VIDEO";
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
for (var key in keys) {
|
|
297
|
+
if (item[key] !== undefined &&
|
|
298
|
+
!keys[key](item[key])) {
|
|
299
|
+
console.warn("[Incorrect input] var: initOptions, key: ".concat(key, ", value: ").concat(item[key]));
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return true;
|
|
304
|
+
},
|
|
305
|
+
config: function (item) {
|
|
306
|
+
if (!isStringKeyObject(item))
|
|
307
|
+
return false;
|
|
308
|
+
var isFontSize = function (i) {
|
|
309
|
+
if (!isStringKeyObject(i))
|
|
310
|
+
return false;
|
|
311
|
+
return (Object.keys(i).reduce(function (pv, cv) {
|
|
312
|
+
var _a, _b;
|
|
313
|
+
return pv +
|
|
314
|
+
Number(!cv.match(/^(ue|shita|naka)$/) ||
|
|
315
|
+
typeof i[cv] !== "object" ||
|
|
316
|
+
!((_a = i[cv]) === null || _a === void 0 ? void 0 : _a.default) ||
|
|
317
|
+
!((_b = i[cv]) === null || _b === void 0 ? void 0 : _b.resized));
|
|
318
|
+
}, 0) === 0);
|
|
319
|
+
};
|
|
320
|
+
var isDoubleResizeMaxWidth = function (i) {
|
|
321
|
+
if (!isStringKeyObject(i))
|
|
322
|
+
return false;
|
|
323
|
+
return (typeof i === "object" &&
|
|
324
|
+
Object.keys(i).reduce(function (pv, cv) {
|
|
325
|
+
var _a, _b, _c;
|
|
326
|
+
return pv +
|
|
327
|
+
Number(!cv.match(/^(full|normal)$/) ||
|
|
328
|
+
typeof i[cv] !== "object" ||
|
|
329
|
+
!((_a = i[cv]) === null || _a === void 0 ? void 0 : _a.default) ||
|
|
330
|
+
!((_b = i[cv]) === null || _b === void 0 ? void 0 : _b.html5) ||
|
|
331
|
+
!((_c = i[cv]) === null || _c === void 0 ? void 0 : _c.flash));
|
|
332
|
+
}, 0) === 0);
|
|
333
|
+
};
|
|
334
|
+
var keys = {
|
|
335
|
+
commentYPaddingTop: isNumber,
|
|
336
|
+
commentYMarginBottom: isNumber,
|
|
337
|
+
fpsInterval: isNumber,
|
|
338
|
+
cacheAge: isNumber,
|
|
339
|
+
canvasWidth: isNumber,
|
|
340
|
+
canvasHeight: isNumber,
|
|
341
|
+
commentDrawRange: isNumber,
|
|
342
|
+
commentDrawPadding: isNumber,
|
|
343
|
+
collisionWidth: isNumber,
|
|
344
|
+
sameCARange: isNumber,
|
|
345
|
+
sameCAGap: isNumber,
|
|
346
|
+
sameCAMinScore: isNumber,
|
|
347
|
+
contextStrokeOpacity: isNumber,
|
|
348
|
+
contextFillLiveOpacity: isNumber,
|
|
349
|
+
contextLineWidth: isNumber,
|
|
350
|
+
contextStrokeColor: isString,
|
|
351
|
+
contextStrokeInversionColor: isString,
|
|
352
|
+
colors: function (i) {
|
|
353
|
+
return typeof i === "object" &&
|
|
354
|
+
Object.keys(i).reduce(function (pv, cv) {
|
|
355
|
+
return pv +
|
|
356
|
+
Number(typeof i[cv] !== "string");
|
|
357
|
+
}, 0) === 0;
|
|
358
|
+
},
|
|
359
|
+
fontSize: isFontSize,
|
|
360
|
+
lineHeight: isFontSize,
|
|
361
|
+
doubleResizeMaxWidth: isDoubleResizeMaxWidth,
|
|
362
|
+
collisionRange: function (i) {
|
|
363
|
+
return typeof i === "object" &&
|
|
364
|
+
Object.keys(i).reduce(function (pv, cv) {
|
|
365
|
+
return pv +
|
|
366
|
+
Number(!cv.match(/^(left|right)$/) ||
|
|
367
|
+
typeof i[cv] !== "number");
|
|
368
|
+
}, 0) === 0;
|
|
369
|
+
},
|
|
370
|
+
};
|
|
371
|
+
for (var key in item) {
|
|
372
|
+
if (item[key] !== undefined &&
|
|
373
|
+
!keys[key](item[key])) {
|
|
374
|
+
console.warn("[Incorrect input] var: initOptions, key: ".concat(key, ", value: ").concat(item[key]));
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return true;
|
|
379
|
+
},
|
|
380
|
+
configKey: function (item) {
|
|
381
|
+
return typeof item === "string" &&
|
|
382
|
+
!!item.match(/^(colors|commentYPaddingTop|commentYMarginBottom|fontSize|lineHeight|doubleResizeMaxWidth|fpsInterval|cacheAge|canvasWidth|canvasHeight|commentDrawRange|commentDrawPadding|collisionWidth|collisionRange|sameCARange|sameCAGap|sameCAMinScore)$/);
|
|
383
|
+
},
|
|
384
|
+
},
|
|
385
|
+
};
|
|
386
|
+
var isBoolean = function (i) { return typeof i === "boolean"; };
|
|
387
|
+
var isNumber = function (i) { return typeof i === "number"; };
|
|
388
|
+
var isString = function (i) { return typeof i === "string"; };
|
|
389
|
+
var isStringKeyObject = function (i) {
|
|
390
|
+
return typeof i === "object";
|
|
272
391
|
};
|
|
273
|
-
var
|
|
392
|
+
var objectVerify = function (item, keys) {
|
|
274
393
|
if (typeof item !== "object" || !item)
|
|
275
394
|
return false;
|
|
276
395
|
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
|
|
@@ -409,13 +528,16 @@
|
|
|
409
528
|
var fromLegacyOwner = function (data) {
|
|
410
529
|
var data_ = [], comments = data.split("\n");
|
|
411
530
|
for (var i = 0; i < comments.length; i++) {
|
|
412
|
-
var
|
|
531
|
+
var value = comments[i];
|
|
532
|
+
if (!value)
|
|
533
|
+
continue;
|
|
534
|
+
var commentData = value.split(":");
|
|
413
535
|
if (commentData.length < 3) {
|
|
414
536
|
continue;
|
|
415
537
|
}
|
|
416
538
|
else if (commentData.length > 3) {
|
|
417
539
|
for (var j = 3; j < commentData.length; j++) {
|
|
418
|
-
commentData[2] += ":"
|
|
540
|
+
commentData[2] += ":".concat(commentData[j]);
|
|
419
541
|
}
|
|
420
542
|
}
|
|
421
543
|
var tmpParam = {
|
|
@@ -547,102 +669,118 @@
|
|
|
547
669
|
return Math.floor(new Date(date).getTime() / 1000);
|
|
548
670
|
};
|
|
549
671
|
|
|
550
|
-
var
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
var commentYPaddingTop = 0.08;
|
|
580
|
-
var commentYMarginBottom = 0.24;
|
|
581
|
-
var fontSize = {
|
|
582
|
-
small: {
|
|
583
|
-
default: 47,
|
|
584
|
-
resized: 26.1,
|
|
585
|
-
},
|
|
586
|
-
medium: {
|
|
587
|
-
default: 74,
|
|
588
|
-
resized: 38.7,
|
|
672
|
+
var defaultConfig = {
|
|
673
|
+
colors: {
|
|
674
|
+
white: "#FFFFFF",
|
|
675
|
+
red: "#FF0000",
|
|
676
|
+
pink: "#FF8080",
|
|
677
|
+
orange: "#FFC000",
|
|
678
|
+
yellow: "#FFFF00",
|
|
679
|
+
green: "#00FF00",
|
|
680
|
+
cyan: "#00FFFF",
|
|
681
|
+
blue: "#0000FF",
|
|
682
|
+
purple: "#C000FF",
|
|
683
|
+
black: "#000000",
|
|
684
|
+
white2: "#CCCC99",
|
|
685
|
+
niconicowhite: "#CCCC99",
|
|
686
|
+
red2: "#CC0033",
|
|
687
|
+
truered: "#CC0033",
|
|
688
|
+
pink2: "#FF33CC",
|
|
689
|
+
orange2: "#FF6600",
|
|
690
|
+
passionorange: "#FF6600",
|
|
691
|
+
yellow2: "#999900",
|
|
692
|
+
madyellow: "#999900",
|
|
693
|
+
green2: "#00CC66",
|
|
694
|
+
elementalgreen: "#00CC66",
|
|
695
|
+
cyan2: "#00CCCC",
|
|
696
|
+
blue2: "#3399FF",
|
|
697
|
+
marinblue: "#3399FF",
|
|
698
|
+
purple2: "#6633CC",
|
|
699
|
+
nobleviolet: "#6633CC",
|
|
700
|
+
black2: "#666666",
|
|
589
701
|
},
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
702
|
+
commentYPaddingTop: 0.08,
|
|
703
|
+
commentYMarginBottom: 0.24,
|
|
704
|
+
fontSize: {
|
|
705
|
+
small: {
|
|
706
|
+
default: 47,
|
|
707
|
+
resized: 26.1,
|
|
708
|
+
},
|
|
709
|
+
medium: {
|
|
710
|
+
default: 74,
|
|
711
|
+
resized: 38.7,
|
|
712
|
+
},
|
|
713
|
+
big: {
|
|
714
|
+
default: 110,
|
|
715
|
+
resized: 61,
|
|
716
|
+
},
|
|
603
717
|
},
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
718
|
+
lineHeight: {
|
|
719
|
+
small: {
|
|
720
|
+
default: 1,
|
|
721
|
+
resized: 1,
|
|
722
|
+
},
|
|
723
|
+
medium: {
|
|
724
|
+
default: 1,
|
|
725
|
+
resized: 1,
|
|
726
|
+
},
|
|
727
|
+
big: {
|
|
728
|
+
default: 1.03,
|
|
729
|
+
resized: 1.01,
|
|
730
|
+
},
|
|
607
731
|
},
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
732
|
+
doubleResizeMaxWidth: {
|
|
733
|
+
full: {
|
|
734
|
+
html5: 3020,
|
|
735
|
+
default: 3550,
|
|
736
|
+
flash: 3550,
|
|
737
|
+
},
|
|
738
|
+
normal: {
|
|
739
|
+
html5: 2540,
|
|
740
|
+
default: 2650,
|
|
741
|
+
flash: 2650,
|
|
742
|
+
},
|
|
613
743
|
},
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
744
|
+
contextStrokeColor: "#000000",
|
|
745
|
+
contextStrokeInversionColor: "#FFFFFF",
|
|
746
|
+
contextStrokeOpacity: 0.7,
|
|
747
|
+
contextFillLiveOpacity: 0.5,
|
|
748
|
+
contextLineWidth: 4,
|
|
749
|
+
fpsInterval: 500,
|
|
750
|
+
cacheAge: 2000,
|
|
751
|
+
canvasWidth: 1920,
|
|
752
|
+
canvasHeight: 1080,
|
|
753
|
+
commentDrawRange: 1450,
|
|
754
|
+
commentDrawPadding: 235,
|
|
755
|
+
collisionWidth: 40,
|
|
756
|
+
collisionRange: {
|
|
757
|
+
left: 40,
|
|
758
|
+
right: 1880,
|
|
617
759
|
},
|
|
760
|
+
sameCARange: 3600,
|
|
761
|
+
sameCAGap: 100,
|
|
762
|
+
sameCAMinScore: 10,
|
|
618
763
|
};
|
|
619
764
|
var defaultOptions = {
|
|
765
|
+
config: {},
|
|
766
|
+
debug: false,
|
|
620
767
|
drawAllImageOnLoad: false,
|
|
768
|
+
enableLegacyPiP: false,
|
|
621
769
|
format: "default",
|
|
622
770
|
formatted: false,
|
|
623
|
-
debug: false,
|
|
624
|
-
enableLegacyPiP: false,
|
|
625
771
|
keepCA: false,
|
|
772
|
+
mode: "default",
|
|
773
|
+
scale: 1,
|
|
626
774
|
showCollision: false,
|
|
627
775
|
showCommentCount: false,
|
|
628
776
|
showFPS: false,
|
|
629
777
|
useLegacy: false,
|
|
630
778
|
video: undefined,
|
|
631
779
|
};
|
|
632
|
-
var
|
|
633
|
-
var
|
|
634
|
-
var
|
|
635
|
-
var
|
|
636
|
-
var commentDrawRange = 1450;
|
|
637
|
-
var commentDrawPadding = (canvasWidth - commentDrawRange) / 2;
|
|
638
|
-
var collisionWidth = 40;
|
|
639
|
-
var collisionRange = {
|
|
640
|
-
left: collisionWidth,
|
|
641
|
-
right: canvasWidth - collisionWidth,
|
|
642
|
-
};
|
|
643
|
-
var sameCARange = 3600;
|
|
644
|
-
var sameCAGap = 100;
|
|
645
|
-
var sameCAMinScore = 10;
|
|
780
|
+
var config;
|
|
781
|
+
var options;
|
|
782
|
+
var setConfig = function (value) { return (config = value); };
|
|
783
|
+
var setOptions = function (value) { return (options = value); };
|
|
646
784
|
|
|
647
785
|
var groupBy = function (array) {
|
|
648
786
|
var data = ["defont", "gothic", "mincho"].reduce(function (pv, font) {
|
|
@@ -675,17 +813,17 @@
|
|
|
675
813
|
currentPos = collisionItem.posY + collisionItem.height;
|
|
676
814
|
isChanged = true;
|
|
677
815
|
}
|
|
678
|
-
if (currentPos + targetComment.height > canvasHeight) {
|
|
679
|
-
if (canvasHeight < targetComment.height) {
|
|
816
|
+
if (currentPos + targetComment.height > config.canvasHeight) {
|
|
817
|
+
if (config.canvasHeight < targetComment.height) {
|
|
680
818
|
if (targetComment.mail.includes("naka")) {
|
|
681
|
-
currentPos = (targetComment.height - canvasHeight) / -2;
|
|
819
|
+
currentPos = (targetComment.height - config.canvasHeight) / -2;
|
|
682
820
|
}
|
|
683
821
|
else {
|
|
684
822
|
currentPos = 0;
|
|
685
823
|
}
|
|
686
824
|
}
|
|
687
825
|
else {
|
|
688
|
-
currentPos = Math.floor(Math.random() * (canvasHeight - targetComment.height));
|
|
826
|
+
currentPos = Math.floor(Math.random() * (config.canvasHeight - targetComment.height));
|
|
689
827
|
}
|
|
690
828
|
isBreak = true;
|
|
691
829
|
break;
|
|
@@ -695,18 +833,20 @@
|
|
|
695
833
|
return { currentPos: currentPos, isChanged: isChanged, isBreak: isBreak };
|
|
696
834
|
};
|
|
697
835
|
var getPosX = function (width, vpos, long) {
|
|
698
|
-
return (commentDrawRange -
|
|
699
|
-
((((width + commentDrawRange) * ((vpos + 100) / 100)) / 4) * 300) /
|
|
700
|
-
|
|
836
|
+
return (config.commentDrawRange -
|
|
837
|
+
((((width + config.commentDrawRange) * ((vpos + 100) / 100)) / 4) * 300) /
|
|
838
|
+
long +
|
|
839
|
+
config.commentDrawPadding);
|
|
701
840
|
};
|
|
702
|
-
var parseFont = function (font, size,
|
|
841
|
+
var parseFont = function (font, size, mode) {
|
|
842
|
+
if (mode === void 0) { mode = "default"; }
|
|
703
843
|
switch (font) {
|
|
704
844
|
case "gothic":
|
|
705
845
|
return "normal 400 ".concat(size, "px \"\u6E38\u30B4\u30B7\u30C3\u30AF\u4F53\", \"\u6E38\u30B4\u30B7\u30C3\u30AF\", \"Yu Gothic\", YuGothic, yugothic, YuGo-Medium");
|
|
706
846
|
case "mincho":
|
|
707
847
|
return "normal 400 ".concat(size, "px \"\u6E38\u660E\u671D\u4F53\", \"\u6E38\u660E\u671D\", \"Yu Mincho\", YuMincho, yumincho, YuMin-Medium");
|
|
708
848
|
default:
|
|
709
|
-
if (
|
|
849
|
+
if (mode === "html5") {
|
|
710
850
|
return "normal 600 ".concat(size, "px Arial, \"\uFF2D\uFF33 \uFF30\u30B4\u30B7\u30C3\u30AF\", \"MS PGothic\", MSPGothic, MS-PGothic");
|
|
711
851
|
}
|
|
712
852
|
else {
|
|
@@ -768,8 +908,8 @@
|
|
|
768
908
|
.filter(function (e) { return !e.match(/@[\d.]+|184|device:.+|patissier|ca/); })
|
|
769
909
|
.join("")), lastComment = index[key];
|
|
770
910
|
if (lastComment !== undefined) {
|
|
771
|
-
if (value.vpos - lastComment.vpos > sameCAGap ||
|
|
772
|
-
Math.abs(value.date - lastComment.date) < sameCARange) {
|
|
911
|
+
if (value.vpos - lastComment.vpos > config.sameCAGap ||
|
|
912
|
+
Math.abs(value.date - lastComment.date) < config.sameCARange) {
|
|
773
913
|
data.push(value);
|
|
774
914
|
index[key] = value;
|
|
775
915
|
}
|
|
@@ -781,7 +921,7 @@
|
|
|
781
921
|
}
|
|
782
922
|
for (var _a = 0, data_1 = data; _a < data_1.length; _a++) {
|
|
783
923
|
var value = data_1[_a];
|
|
784
|
-
if (userList[value.user_id] || 0 >= sameCAMinScore)
|
|
924
|
+
if (userList[value.user_id] || 0 >= config.sameCAMinScore)
|
|
785
925
|
value.layer = value.user_id;
|
|
786
926
|
}
|
|
787
927
|
return data;
|
|
@@ -792,32 +932,44 @@
|
|
|
792
932
|
function NiconiComments(canvas, data, initOptions) {
|
|
793
933
|
if (initOptions === void 0) { initOptions = {}; }
|
|
794
934
|
var _this = this;
|
|
795
|
-
var options = Object.assign(defaultOptions, initOptions);
|
|
796
|
-
isDebug = options.debug;
|
|
797
935
|
var constructorStart = performance.now();
|
|
936
|
+
if (!typeGuard.config.initOptions(initOptions))
|
|
937
|
+
throw new Error("Please see document: https://xpadev-net.github.io/niconicomments/#p_options");
|
|
938
|
+
setOptions(Object.assign(defaultOptions, initOptions));
|
|
939
|
+
if (!typeGuard.config.config(options.config)) {
|
|
940
|
+
console.warn(options.config);
|
|
941
|
+
throw new Error("Please see document: https://xpadev-net.github.io/niconicomments/#p_config");
|
|
942
|
+
}
|
|
943
|
+
setConfig(Object.assign(defaultConfig, options.config));
|
|
944
|
+
isDebug = options.debug;
|
|
798
945
|
this.canvas = canvas;
|
|
799
946
|
var context = canvas.getContext("2d");
|
|
800
947
|
if (!context)
|
|
801
948
|
throw new Error("Fail to get CanvasRenderingContext2D");
|
|
802
949
|
this.context = context;
|
|
803
|
-
this.context.strokeStyle = "rgba(
|
|
950
|
+
this.context.strokeStyle = "rgba(".concat(hex2rgb(config.contextStrokeColor).join(","), ",").concat(config.contextStrokeOpacity, ")");
|
|
804
951
|
this.context.textAlign = "start";
|
|
805
952
|
this.context.textBaseline = "alphabetic";
|
|
806
|
-
this.context.lineWidth =
|
|
807
|
-
var formatType = options.format;
|
|
953
|
+
this.context.lineWidth = config.contextLineWidth;
|
|
954
|
+
var formatType = options.format, mode = options.mode;
|
|
808
955
|
if (options.formatted) {
|
|
809
|
-
console.warn("Deprecated: options.formatted is no longer recommended. Please use options.format");
|
|
956
|
+
console.warn("Deprecated: options.formatted is no longer recommended. Please use options.format. https://xpadev-net.github.io/niconicomments/#p_format");
|
|
810
957
|
}
|
|
811
958
|
if (formatType === "default") {
|
|
812
959
|
formatType = options.formatted ? "formatted" : "legacy";
|
|
813
960
|
}
|
|
961
|
+
if (options.useLegacy) {
|
|
962
|
+
console.warn("Deprecated: options.useLegacy is no longer recommended. Please use options.mode. https://xpadev-net.github.io/niconicomments/#p_mode");
|
|
963
|
+
}
|
|
964
|
+
if (mode === "default" && options.useLegacy) {
|
|
965
|
+
mode = "html5";
|
|
966
|
+
}
|
|
814
967
|
var parsedData = convert2formattedComment(data, formatType);
|
|
815
968
|
this.video = options.video || undefined;
|
|
816
969
|
this.showCollision = options.showCollision;
|
|
817
970
|
this.showFPS = options.showFPS;
|
|
818
971
|
this.showCommentCount = options.showCommentCount;
|
|
819
972
|
this.enableLegacyPiP = options.enableLegacyPiP;
|
|
820
|
-
this.keepCA = options.keepCA;
|
|
821
973
|
this.cacheIndex = {};
|
|
822
974
|
this.timeline = {};
|
|
823
975
|
this.nicoScripts = { reverse: [], default: [], replace: [], ban: [] };
|
|
@@ -827,20 +979,20 @@
|
|
|
827
979
|
}, {});
|
|
828
980
|
this.data = [];
|
|
829
981
|
this.lastVpos = -1;
|
|
830
|
-
this.
|
|
982
|
+
this.mode = mode;
|
|
831
983
|
this.preRendering(parsedData, options.drawAllImageOnLoad);
|
|
832
984
|
this.fpsCount = 0;
|
|
833
985
|
this.fps = 0;
|
|
834
986
|
window.setInterval(function () {
|
|
835
|
-
_this.fps = _this.fpsCount * (1000 / fpsInterval);
|
|
987
|
+
_this.fps = _this.fpsCount * (1000 / config.fpsInterval);
|
|
836
988
|
_this.fpsCount = 0;
|
|
837
|
-
}, fpsInterval);
|
|
989
|
+
}, config.fpsInterval);
|
|
838
990
|
logger("constructor complete: ".concat(performance.now() - constructorStart, "ms"));
|
|
839
991
|
}
|
|
840
992
|
NiconiComments.prototype.preRendering = function (rawData, drawAll) {
|
|
841
993
|
var _this = this;
|
|
842
994
|
var preRenderingStart = performance.now();
|
|
843
|
-
if (
|
|
995
|
+
if (options.keepCA) {
|
|
844
996
|
rawData = changeCALayer(rawData);
|
|
845
997
|
}
|
|
846
998
|
var parsedData = this.getCommentPos(this.getCommentSize(this.getFont(rawData)));
|
|
@@ -868,11 +1020,11 @@
|
|
|
868
1020
|
for (var _i = 0, _a = Object.keys(groupedData); _i < _a.length; _i++) {
|
|
869
1021
|
var font = _a[_i];
|
|
870
1022
|
for (var _b = 0, _c = Object.keys(groupedData[font]); _b < _c.length; _b++) {
|
|
871
|
-
var
|
|
872
|
-
var value = groupedData[font][
|
|
1023
|
+
var fontSize = _c[_b];
|
|
1024
|
+
var value = groupedData[font][fontSize];
|
|
873
1025
|
if (!value)
|
|
874
1026
|
continue;
|
|
875
|
-
this.context.font = parseFont(font,
|
|
1027
|
+
this.context.font = parseFont(font, fontSize, this.mode);
|
|
876
1028
|
for (var _d = 0, value_1 = value; _d < value_1.length; _d++) {
|
|
877
1029
|
var comment = value_1[_d];
|
|
878
1030
|
if (comment.invisible) {
|
|
@@ -880,14 +1032,21 @@
|
|
|
880
1032
|
}
|
|
881
1033
|
var measure = this.measureText(comment);
|
|
882
1034
|
var size = parsedData[comment.index];
|
|
1035
|
+
if (options.scale !== 1 && size.layer === -1) {
|
|
1036
|
+
measure.height *= options.scale;
|
|
1037
|
+
measure.width *= options.scale;
|
|
1038
|
+
measure.width_max *= options.scale;
|
|
1039
|
+
measure.width_min *= options.scale;
|
|
1040
|
+
measure.fontSize *= options.scale;
|
|
1041
|
+
}
|
|
883
1042
|
size.height = measure.height;
|
|
884
1043
|
size.width = measure.width;
|
|
885
1044
|
size.width_max = measure.width_max;
|
|
886
1045
|
size.width_min = measure.width_min;
|
|
887
1046
|
size.lineHeight = measure.lineHeight;
|
|
1047
|
+
size.fontSize = measure.fontSize;
|
|
888
1048
|
if (measure.resized) {
|
|
889
|
-
|
|
890
|
-
this.context.font = parseFont(font, fontSize_1, this.useLegacy);
|
|
1049
|
+
this.context.font = parseFont(font, fontSize, this.mode);
|
|
891
1050
|
}
|
|
892
1051
|
result[comment.index] = size;
|
|
893
1052
|
}
|
|
@@ -905,8 +1064,8 @@
|
|
|
905
1064
|
if (comment.loc === "naka") {
|
|
906
1065
|
var posY = 0;
|
|
907
1066
|
var beforeVpos = Math.round(-288 / ((1632 + comment.width_max) / (comment.long + 125))) - 100;
|
|
908
|
-
if (canvasHeight < comment.height) {
|
|
909
|
-
posY = (comment.height - canvasHeight) / -2;
|
|
1067
|
+
if (config.canvasHeight < comment.height) {
|
|
1068
|
+
posY = (comment.height - config.canvasHeight) / -2;
|
|
910
1069
|
}
|
|
911
1070
|
else {
|
|
912
1071
|
var isBreak = false, isChanged = true, count = 0;
|
|
@@ -916,8 +1075,8 @@
|
|
|
916
1075
|
for (var j = beforeVpos; j < comment.long + 125; j++) {
|
|
917
1076
|
var vpos = comment.vpos + j;
|
|
918
1077
|
var left_pos = getPosX(comment.width_max, j, comment.long);
|
|
919
|
-
if (left_pos + comment.width_max >= collisionRange.right &&
|
|
920
|
-
left_pos <= collisionRange.right) {
|
|
1078
|
+
if (left_pos + comment.width_max >= config.collisionRange.right &&
|
|
1079
|
+
left_pos <= config.collisionRange.right) {
|
|
921
1080
|
var result = getPosY(posY, comment, _this.collision.right[vpos], data);
|
|
922
1081
|
posY = result.currentPos;
|
|
923
1082
|
isChanged = result.isChanged;
|
|
@@ -925,8 +1084,8 @@
|
|
|
925
1084
|
if (isBreak)
|
|
926
1085
|
break;
|
|
927
1086
|
}
|
|
928
|
-
if (left_pos + comment.width_max >= collisionRange.left &&
|
|
929
|
-
left_pos <= collisionRange.left) {
|
|
1087
|
+
if (left_pos + comment.width_max >= config.collisionRange.left &&
|
|
1088
|
+
left_pos <= config.collisionRange.left) {
|
|
930
1089
|
var result = getPosY(posY, comment, _this.collision.left[vpos], data);
|
|
931
1090
|
posY = result.currentPos;
|
|
932
1091
|
isChanged = result.isChanged;
|
|
@@ -944,10 +1103,10 @@
|
|
|
944
1103
|
var vpos = comment.vpos + j;
|
|
945
1104
|
var left_pos = getPosX(comment.width_max, j, comment.long);
|
|
946
1105
|
arrayPush(_this.timeline, vpos, index);
|
|
947
|
-
if (left_pos + comment.width_max >= collisionRange.right) {
|
|
1106
|
+
if (left_pos + comment.width_max >= config.collisionRange.right) {
|
|
948
1107
|
arrayPush(_this.collision.right, vpos, index);
|
|
949
1108
|
}
|
|
950
|
-
if (left_pos <= collisionRange.left) {
|
|
1109
|
+
if (left_pos <= config.collisionRange.left) {
|
|
951
1110
|
arrayPush(_this.collision.left, vpos, index);
|
|
952
1111
|
}
|
|
953
1112
|
}
|
|
@@ -1016,28 +1175,28 @@
|
|
|
1016
1175
|
NiconiComments.prototype.measureText = function (comment) {
|
|
1017
1176
|
var width_arr = [], lines = comment.content.split("\n");
|
|
1018
1177
|
if (!comment.lineHeight)
|
|
1019
|
-
comment.lineHeight = lineHeight[comment.size].default;
|
|
1178
|
+
comment.lineHeight = config.lineHeight[comment.size].default;
|
|
1020
1179
|
if (!comment.resized && !comment.ender) {
|
|
1021
1180
|
if (comment.size === "big" && lines.length > 2) {
|
|
1022
|
-
comment.fontSize = fontSize.big.resized;
|
|
1023
|
-
comment.lineHeight = lineHeight.big.resized;
|
|
1181
|
+
comment.fontSize = config.fontSize.big.resized;
|
|
1182
|
+
comment.lineHeight = config.lineHeight.big.resized;
|
|
1024
1183
|
comment.resized = true;
|
|
1025
1184
|
comment.resizedY = true;
|
|
1026
|
-
this.context.font = parseFont(comment.font, comment.fontSize, this.
|
|
1185
|
+
this.context.font = parseFont(comment.font, comment.fontSize, this.mode);
|
|
1027
1186
|
}
|
|
1028
1187
|
else if (comment.size === "medium" && lines.length > 4) {
|
|
1029
|
-
comment.fontSize = fontSize.medium.resized;
|
|
1030
|
-
comment.lineHeight = lineHeight.medium.resized;
|
|
1188
|
+
comment.fontSize = config.fontSize.medium.resized;
|
|
1189
|
+
comment.lineHeight = config.lineHeight.medium.resized;
|
|
1031
1190
|
comment.resized = true;
|
|
1032
1191
|
comment.resizedY = true;
|
|
1033
|
-
this.context.font = parseFont(comment.font, comment.fontSize, this.
|
|
1192
|
+
this.context.font = parseFont(comment.font, comment.fontSize, this.mode);
|
|
1034
1193
|
}
|
|
1035
1194
|
else if (comment.size === "small" && lines.length > 6) {
|
|
1036
|
-
comment.fontSize = fontSize.small.resized;
|
|
1037
|
-
comment.lineHeight = lineHeight.small.resized;
|
|
1195
|
+
comment.fontSize = config.fontSize.small.resized;
|
|
1196
|
+
comment.lineHeight = config.lineHeight.small.resized;
|
|
1038
1197
|
comment.resized = true;
|
|
1039
1198
|
comment.resizedY = true;
|
|
1040
|
-
this.context.font = parseFont(comment.font, comment.fontSize, this.
|
|
1199
|
+
this.context.font = parseFont(comment.font, comment.fontSize, this.mode);
|
|
1041
1200
|
}
|
|
1042
1201
|
}
|
|
1043
1202
|
for (var i = 0; i < lines.length; i++) {
|
|
@@ -1045,11 +1204,12 @@
|
|
|
1045
1204
|
width_arr.push(measure.width);
|
|
1046
1205
|
}
|
|
1047
1206
|
var width = width_arr.reduce(function (p, c) { return p + c; }, 0) / width_arr.length;
|
|
1048
|
-
var width_max = Math.max.apply(Math, width_arr)
|
|
1207
|
+
var width_max = Math.max.apply(Math, width_arr);
|
|
1208
|
+
var width_min = Math.min.apply(Math, width_arr), height = comment.fontSize *
|
|
1049
1209
|
comment.lineHeight *
|
|
1050
|
-
(1 + commentYPaddingTop) *
|
|
1210
|
+
(1 + config.commentYPaddingTop) *
|
|
1051
1211
|
lines.length +
|
|
1052
|
-
commentYMarginBottom * comment.fontSize;
|
|
1212
|
+
config.commentYMarginBottom * comment.fontSize;
|
|
1053
1213
|
if (comment.loc !== "naka" && !comment.resizedY) {
|
|
1054
1214
|
if ((comment.full && width_max > 1930) ||
|
|
1055
1215
|
(!comment.full && width_max > 1440)) {
|
|
@@ -1060,7 +1220,7 @@
|
|
|
1060
1220
|
}
|
|
1061
1221
|
comment.resized = true;
|
|
1062
1222
|
comment.resizedX = true;
|
|
1063
|
-
this.context.font = parseFont(comment.font, comment.fontSize, this.
|
|
1223
|
+
this.context.font = parseFont(comment.font, comment.fontSize, this.mode);
|
|
1064
1224
|
return this.measureText(comment);
|
|
1065
1225
|
}
|
|
1066
1226
|
}
|
|
@@ -1069,34 +1229,30 @@
|
|
|
1069
1229
|
((comment.full && width_max > 2120) ||
|
|
1070
1230
|
(!comment.full && width_max > 1440)) &&
|
|
1071
1231
|
!comment.resizedX) {
|
|
1072
|
-
comment.fontSize = fontSize[comment.size].default;
|
|
1073
|
-
comment.lineHeight = lineHeight[comment.size].default * 1.05;
|
|
1232
|
+
comment.fontSize = config.fontSize[comment.size].default;
|
|
1233
|
+
comment.lineHeight = config.lineHeight[comment.size].default * 1.05;
|
|
1074
1234
|
comment.resized = true;
|
|
1075
1235
|
comment.resizedX = true;
|
|
1076
|
-
this.context.font = parseFont(comment.font, comment.fontSize, this.
|
|
1236
|
+
this.context.font = parseFont(comment.font, comment.fontSize, this.mode);
|
|
1077
1237
|
return this.measureText(comment);
|
|
1078
1238
|
}
|
|
1079
1239
|
else if (comment.loc !== "naka" && comment.resizedY && comment.resizedX) {
|
|
1080
1240
|
if (comment.full &&
|
|
1081
|
-
width_max >
|
|
1082
|
-
|
|
1083
|
-
while (width_max >
|
|
1084
|
-
doubleResizeMaxWidth.full[this.useLegacy ? "legacy" : "default"]) {
|
|
1241
|
+
width_max > config.doubleResizeMaxWidth.full[this.mode]) {
|
|
1242
|
+
while (width_max > config.doubleResizeMaxWidth.full[this.mode]) {
|
|
1085
1243
|
width_max /= 1.1;
|
|
1086
1244
|
comment.fontSize -= 1;
|
|
1087
1245
|
}
|
|
1088
|
-
this.context.font = parseFont(comment.font, comment.fontSize, this.
|
|
1246
|
+
this.context.font = parseFont(comment.font, comment.fontSize, this.mode);
|
|
1089
1247
|
return this.measureText(comment);
|
|
1090
1248
|
}
|
|
1091
1249
|
else if (!comment.full &&
|
|
1092
|
-
width_max >
|
|
1093
|
-
|
|
1094
|
-
while (width_max >
|
|
1095
|
-
doubleResizeMaxWidth.normal[this.useLegacy ? "legacy" : "default"]) {
|
|
1250
|
+
width_max > config.doubleResizeMaxWidth.normal[this.mode]) {
|
|
1251
|
+
while (width_max > config.doubleResizeMaxWidth.normal[this.mode]) {
|
|
1096
1252
|
width_max /= 1.1;
|
|
1097
1253
|
comment.fontSize -= 1;
|
|
1098
1254
|
}
|
|
1099
|
-
this.context.font = parseFont(comment.font, comment.fontSize, this.
|
|
1255
|
+
this.context.font = parseFont(comment.font, comment.fontSize, this.mode);
|
|
1100
1256
|
return this.measureText(comment);
|
|
1101
1257
|
}
|
|
1102
1258
|
}
|
|
@@ -1127,23 +1283,23 @@
|
|
|
1127
1283
|
if (range.start < vpos && vpos < range.end)
|
|
1128
1284
|
return;
|
|
1129
1285
|
}
|
|
1130
|
-
var posX = (canvasWidth - comment.width_max) / 2, posY = comment.posY;
|
|
1286
|
+
var posX = (config.canvasWidth - comment.width_max) / 2, posY = comment.posY;
|
|
1131
1287
|
if (comment.loc === "naka") {
|
|
1132
1288
|
if (reverse) {
|
|
1133
1289
|
posX =
|
|
1134
|
-
canvasWidth +
|
|
1290
|
+
config.canvasWidth +
|
|
1135
1291
|
comment.width_max -
|
|
1136
1292
|
getPosX(comment.width_max, vpos - comment.vpos, comment.long);
|
|
1137
1293
|
}
|
|
1138
1294
|
else {
|
|
1139
1295
|
posX = getPosX(comment.width_max, vpos - comment.vpos, comment.long);
|
|
1140
1296
|
}
|
|
1141
|
-
if (posX > canvasWidth || posX + comment.width_max < 0) {
|
|
1297
|
+
if (posX > config.canvasWidth || posX + comment.width_max < 0) {
|
|
1142
1298
|
return;
|
|
1143
1299
|
}
|
|
1144
1300
|
}
|
|
1145
1301
|
else if (comment.loc === "shita") {
|
|
1146
|
-
posY = canvasHeight - comment.posY - comment.height;
|
|
1302
|
+
posY = config.canvasHeight - comment.posY - comment.height;
|
|
1147
1303
|
}
|
|
1148
1304
|
if (comment.image && comment.image !== true) {
|
|
1149
1305
|
this.context.drawImage(comment.image, posX, posY);
|
|
@@ -1155,7 +1311,7 @@
|
|
|
1155
1311
|
lines.forEach(function (_, index) {
|
|
1156
1312
|
var linePosY = (Number(index) + 1) *
|
|
1157
1313
|
(comment.fontSize * comment.lineHeight) *
|
|
1158
|
-
(1 + commentYPaddingTop);
|
|
1314
|
+
(1 + config.commentYPaddingTop);
|
|
1159
1315
|
_this.context.strokeStyle = "rgba(255,255,0,0.5)";
|
|
1160
1316
|
_this.context.strokeRect(posX, posY + linePosY, comment.width_max, comment.fontSize * comment.lineHeight * -1);
|
|
1161
1317
|
});
|
|
@@ -1163,7 +1319,7 @@
|
|
|
1163
1319
|
if (isDebug) {
|
|
1164
1320
|
var font = this.context.font;
|
|
1165
1321
|
var fillStyle = this.context.fillStyle;
|
|
1166
|
-
this.context.font = parseFont("defont", 30
|
|
1322
|
+
this.context.font = parseFont("defont", 30);
|
|
1167
1323
|
this.context.fillStyle = "#ff00ff";
|
|
1168
1324
|
this.context.fillText(comment.mail.join(","), posX, posY + 30);
|
|
1169
1325
|
this.context.font = font;
|
|
@@ -1190,7 +1346,7 @@
|
|
|
1190
1346
|
if (_this.cacheIndex[cacheKey] === i) {
|
|
1191
1347
|
delete _this.cacheIndex[cacheKey];
|
|
1192
1348
|
}
|
|
1193
|
-
}, value.long * 10 + cacheAge);
|
|
1349
|
+
}, value.long * 10 + config.cacheAge);
|
|
1194
1350
|
return;
|
|
1195
1351
|
}
|
|
1196
1352
|
}
|
|
@@ -1200,26 +1356,24 @@
|
|
|
1200
1356
|
var context = image.getContext("2d");
|
|
1201
1357
|
if (!context)
|
|
1202
1358
|
throw new Error("Fail to get CanvasRenderingContext2D");
|
|
1203
|
-
context.strokeStyle = "rgba(
|
|
1359
|
+
context.strokeStyle = "rgba(".concat(hex2rgb(value.color === "#000000"
|
|
1360
|
+
? config.contextStrokeInversionColor
|
|
1361
|
+
: config.contextStrokeColor).join(","), ",").concat(config.contextStrokeOpacity, ")");
|
|
1204
1362
|
context.textAlign = "start";
|
|
1205
1363
|
context.textBaseline = "alphabetic";
|
|
1206
1364
|
context.lineWidth = 4;
|
|
1207
|
-
context.font = parseFont(value.font, value.fontSize, this.
|
|
1365
|
+
context.font = parseFont(value.font, value.fontSize, this.mode);
|
|
1208
1366
|
if (value._live) {
|
|
1209
|
-
|
|
1210
|
-
context.fillStyle = "rgba(".concat(rgb[0], ",").concat(rgb[1], ",").concat(rgb[2], ",0.5)");
|
|
1367
|
+
context.fillStyle = "rgba(".concat(hex2rgb(value.color).join(","), ",").concat(config.contextFillLiveOpacity, ")");
|
|
1211
1368
|
}
|
|
1212
1369
|
else {
|
|
1213
1370
|
context.fillStyle = value.color;
|
|
1214
1371
|
}
|
|
1215
|
-
if (value.color === "#000000") {
|
|
1216
|
-
context.strokeStyle = "rgba(255,255,255,0.7)";
|
|
1217
|
-
}
|
|
1218
1372
|
var lines = value.content.split("\n");
|
|
1219
1373
|
lines.forEach(function (line, index) {
|
|
1220
1374
|
var posY = (index + 1) *
|
|
1221
1375
|
(value.fontSize * value.lineHeight) *
|
|
1222
|
-
(1 + commentYPaddingTop);
|
|
1376
|
+
(1 + config.commentYPaddingTop);
|
|
1223
1377
|
context.strokeText(line, 0, posY);
|
|
1224
1378
|
context.fillText(line, 0, posY);
|
|
1225
1379
|
});
|
|
@@ -1234,7 +1388,7 @@
|
|
|
1234
1388
|
if (_this.cacheIndex[cacheKey] === i) {
|
|
1235
1389
|
delete _this.cacheIndex[cacheKey];
|
|
1236
1390
|
}
|
|
1237
|
-
}, value.long * 10 + cacheAge);
|
|
1391
|
+
}, value.long * 10 + config.cacheAge);
|
|
1238
1392
|
};
|
|
1239
1393
|
NiconiComments.prototype.parseCommand = function (comment) {
|
|
1240
1394
|
var metadata = comment.mail;
|
|
@@ -1262,11 +1416,11 @@
|
|
|
1262
1416
|
}
|
|
1263
1417
|
else if (result.size === undefined && typeGuard.comment.size(command)) {
|
|
1264
1418
|
result.size = command;
|
|
1265
|
-
result.fontSize = fontSize[command].default;
|
|
1419
|
+
result.fontSize = config.fontSize[command].default;
|
|
1266
1420
|
}
|
|
1267
1421
|
else {
|
|
1268
1422
|
if (result.color === undefined) {
|
|
1269
|
-
var color = colors[command];
|
|
1423
|
+
var color = config.colors[command];
|
|
1270
1424
|
if (color) {
|
|
1271
1425
|
result.color = color;
|
|
1272
1426
|
continue;
|
|
@@ -1462,7 +1616,7 @@
|
|
|
1462
1616
|
}
|
|
1463
1617
|
if (!data.size) {
|
|
1464
1618
|
data.size = size || "medium";
|
|
1465
|
-
data.fontSize = fontSize[data.size].default;
|
|
1619
|
+
data.fontSize = config.fontSize[data.size].default;
|
|
1466
1620
|
}
|
|
1467
1621
|
if (!data.font) {
|
|
1468
1622
|
data.font = font || "defont";
|
|
@@ -1515,16 +1669,16 @@
|
|
|
1515
1669
|
}
|
|
1516
1670
|
}
|
|
1517
1671
|
if (this.showFPS) {
|
|
1518
|
-
this.context.font = parseFont("defont", 60
|
|
1672
|
+
this.context.font = parseFont("defont", 60);
|
|
1519
1673
|
this.context.fillStyle = "#00FF00";
|
|
1520
|
-
this.context.strokeStyle = "rgba(
|
|
1674
|
+
this.context.strokeStyle = "rgba(".concat(hex2rgb(config.contextStrokeColor).join(","), ",").concat(config.contextStrokeOpacity, ")");
|
|
1521
1675
|
this.context.strokeText("FPS:".concat(this.fps), 100, 100);
|
|
1522
1676
|
this.context.fillText("FPS:".concat(this.fps), 100, 100);
|
|
1523
1677
|
}
|
|
1524
1678
|
if (this.showCommentCount) {
|
|
1525
|
-
this.context.font = parseFont("defont", 60
|
|
1679
|
+
this.context.font = parseFont("defont", 60);
|
|
1526
1680
|
this.context.fillStyle = "#00FF00";
|
|
1527
|
-
this.context.strokeStyle = "rgba(
|
|
1681
|
+
this.context.strokeStyle = "rgba(".concat(hex2rgb(config.contextStrokeColor).join(","), ",").concat(config.contextStrokeOpacity, ")");
|
|
1528
1682
|
if (timelineRange) {
|
|
1529
1683
|
this.context.strokeText("Count:".concat(timelineRange.length), 100, 200);
|
|
1530
1684
|
this.context.fillText("Count:".concat(timelineRange.length), 100, 200);
|
|
@@ -1537,7 +1691,7 @@
|
|
|
1537
1691
|
logger("drawCanvas complete: ".concat(performance.now() - drawCanvasStart, "ms"));
|
|
1538
1692
|
};
|
|
1539
1693
|
NiconiComments.prototype.clear = function () {
|
|
1540
|
-
this.context.clearRect(0, 0, canvasWidth, canvasHeight);
|
|
1694
|
+
this.context.clearRect(0, 0, config.canvasWidth, config.canvasHeight);
|
|
1541
1695
|
};
|
|
1542
1696
|
return NiconiComments;
|
|
1543
1697
|
}());
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xpadev-net/niconicomments",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.27",
|
|
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
|
-
"types": "dist/
|
|
6
|
+
"types": "dist/bundle.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
9
|
"build": "rollup -c rollup.config.js",
|