@xpadev-net/niconicomments 0.2.35 → 0.2.36
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 +189 -187
- package/dist/bundle.js +149 -44
- package/package.json +7 -2
package/dist/bundle.d.ts
CHANGED
|
@@ -397,187 +397,189 @@ interface IComment {
|
|
|
397
397
|
draw: (vpos: number, showCollision: boolean, isDebug: boolean) => void;
|
|
398
398
|
}
|
|
399
399
|
|
|
400
|
-
type inputFormatType =
|
|
401
|
-
| "niconicome"
|
|
402
|
-
| "formatted"
|
|
403
|
-
| "legacy"
|
|
404
|
-
| "legacyOwner"
|
|
405
|
-
| "owner"
|
|
406
|
-
| "v1"
|
|
407
|
-
| "
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
|
411
|
-
|
|
|
412
|
-
|
|
|
413
|
-
|
|
|
414
|
-
|
|
|
415
|
-
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
type
|
|
435
|
-
id: number;
|
|
436
|
-
vpos: number;
|
|
437
|
-
date: number;
|
|
438
|
-
date_usec: number;
|
|
439
|
-
owner: boolean;
|
|
440
|
-
premium: boolean;
|
|
441
|
-
mail: string[];
|
|
442
|
-
user_id: number;
|
|
443
|
-
layer: number;
|
|
444
|
-
loc: commentLoc;
|
|
445
|
-
size: commentSize;
|
|
446
|
-
fontSize: number;
|
|
447
|
-
font: commentFont;
|
|
448
|
-
color: string;
|
|
449
|
-
full: boolean;
|
|
450
|
-
ender: boolean;
|
|
451
|
-
_live: boolean;
|
|
452
|
-
long: number;
|
|
453
|
-
invisible: boolean;
|
|
454
|
-
content: commentContentItem[];
|
|
455
|
-
flash: boolean;
|
|
456
|
-
lineCount: number;
|
|
457
|
-
lineOffset: number;
|
|
458
|
-
};
|
|
459
|
-
type formattedCommentWithSize = formattedCommentWithFont & {
|
|
460
|
-
height: number;
|
|
461
|
-
width: number;
|
|
462
|
-
lineHeight: number;
|
|
463
|
-
resized: boolean;
|
|
464
|
-
resizedX: boolean;
|
|
465
|
-
resizedY: boolean;
|
|
466
|
-
content: commentMeasuredContentItem[];
|
|
467
|
-
charSize: number;
|
|
468
|
-
};
|
|
469
|
-
type parsedComment = formattedCommentWithSize & {
|
|
470
|
-
posY: number;
|
|
471
|
-
image?: HTMLCanvasElement | boolean;
|
|
472
|
-
};
|
|
473
|
-
type commentContentItem = {
|
|
474
|
-
content: string;
|
|
475
|
-
font?: commentFlashFont;
|
|
476
|
-
width?: number[];
|
|
477
|
-
};
|
|
478
|
-
type commentMeasuredContentItem = commentContentItem & {
|
|
479
|
-
width: number[];
|
|
480
|
-
};
|
|
481
|
-
type commentContentIndex = {
|
|
482
|
-
index: number;
|
|
483
|
-
font: "gothic" | "gulim" | "simsunStrong" | "simsunWeak";
|
|
484
|
-
};
|
|
485
|
-
type commentFont = "defont" | "mincho" | "gothic" | "gulim" | "simsun";
|
|
486
|
-
type commentFlashFont = "defont" | "gulim" | "simsun";
|
|
487
|
-
type commentSize = "big" | "medium" | "small";
|
|
488
|
-
type commentLoc = "ue" | "naka" | "shita";
|
|
489
|
-
type collision = { [key in collisionPos]: collisionItem };
|
|
490
|
-
type collisionPos = "ue" | "shita" | "right" | "left";
|
|
491
|
-
type collisionItem = { [p: number]: number[] };
|
|
492
|
-
type nicoScript = {
|
|
493
|
-
reverse: nicoScriptReverse[];
|
|
494
|
-
ban: nicoScriptBan[];
|
|
495
|
-
default: nicoScriptDefault[];
|
|
496
|
-
replace: nicoScriptReplace[];
|
|
497
|
-
};
|
|
498
|
-
type nicoScriptReverse = {
|
|
499
|
-
target: nicoScriptReverseTarget;
|
|
500
|
-
start: number;
|
|
501
|
-
end: number;
|
|
502
|
-
};
|
|
503
|
-
type nicoScriptReverseTarget = "コメ" | "投コメ" | "全";
|
|
504
|
-
type nicoScriptReplace = {
|
|
505
|
-
start: number;
|
|
506
|
-
long: number | undefined;
|
|
507
|
-
keyword: string;
|
|
508
|
-
replace: string;
|
|
509
|
-
range: nicoScriptReplaceRange;
|
|
510
|
-
target: nicoScriptReplaceTarget;
|
|
511
|
-
condition: nicoScriptReplaceCondition;
|
|
512
|
-
color: string | undefined;
|
|
513
|
-
size: commentSize | undefined;
|
|
514
|
-
font: commentFont | undefined;
|
|
515
|
-
loc: commentLoc | undefined;
|
|
516
|
-
no: number;
|
|
517
|
-
};
|
|
518
|
-
type nicoScriptReplaceRange = "単" | "全";
|
|
519
|
-
type nicoScriptReplaceTarget = "コメ" | "投コメ" | "全" | "含まない" | "含む";
|
|
520
|
-
type nicoScriptReplaceCondition = "完全一致" | "部分一致";
|
|
521
|
-
type nicoScriptBan = {
|
|
522
|
-
start: number;
|
|
523
|
-
end: number;
|
|
524
|
-
};
|
|
525
|
-
type nicoScriptDefault = {
|
|
526
|
-
start: number;
|
|
527
|
-
long: number | undefined;
|
|
528
|
-
color: string | undefined;
|
|
529
|
-
size: commentSize | undefined;
|
|
530
|
-
font: commentFont | undefined;
|
|
531
|
-
loc: commentLoc | undefined;
|
|
532
|
-
};
|
|
533
|
-
type measureTextResult = {
|
|
534
|
-
width: number;
|
|
535
|
-
height: number;
|
|
536
|
-
resized: boolean;
|
|
537
|
-
resizedX: boolean;
|
|
538
|
-
resizedY: boolean;
|
|
539
|
-
fontSize: number;
|
|
540
|
-
lineHeight: number;
|
|
541
|
-
content: commentMeasuredContentItem[];
|
|
542
|
-
charSize: number;
|
|
543
|
-
};
|
|
544
|
-
type parsedCommand = {
|
|
545
|
-
loc: commentLoc | undefined;
|
|
546
|
-
size: commentSize | undefined;
|
|
547
|
-
fontSize: number | undefined;
|
|
548
|
-
color: string | undefined;
|
|
549
|
-
font: commentFont | undefined;
|
|
550
|
-
full: boolean;
|
|
551
|
-
ender: boolean;
|
|
552
|
-
_live: boolean;
|
|
553
|
-
invisible: boolean;
|
|
554
|
-
long: number | undefined;
|
|
555
|
-
};
|
|
556
|
-
|
|
557
|
-
type measureTextInput = {
|
|
558
|
-
content: commentContentItem[];
|
|
559
|
-
resized?: boolean;
|
|
560
|
-
ender: boolean;
|
|
561
|
-
size: commentSize;
|
|
562
|
-
fontSize: number;
|
|
563
|
-
resizedY?: boolean;
|
|
564
|
-
resizedX?: boolean;
|
|
565
|
-
font: commentFont;
|
|
566
|
-
loc: commentLoc;
|
|
567
|
-
full: boolean;
|
|
568
|
-
flash: boolean;
|
|
569
|
-
lineCount: number;
|
|
570
|
-
lineHeight?: number;
|
|
571
|
-
charSize?: number;
|
|
572
|
-
};
|
|
400
|
+
type inputFormatType =
|
|
401
|
+
| "niconicome"
|
|
402
|
+
| "formatted"
|
|
403
|
+
| "legacy"
|
|
404
|
+
| "legacyOwner"
|
|
405
|
+
| "owner"
|
|
406
|
+
| "v1"
|
|
407
|
+
| "empty"
|
|
408
|
+
| "default";
|
|
409
|
+
type inputFormat =
|
|
410
|
+
| XMLDocument
|
|
411
|
+
| formattedComment[]
|
|
412
|
+
| formattedLegacyComment[]
|
|
413
|
+
| rawApiResponse[]
|
|
414
|
+
| ownerComment[]
|
|
415
|
+
| v1Thread[]
|
|
416
|
+
| string
|
|
417
|
+
| undefined;
|
|
418
|
+
type modeType = "default" | "html5" | "flash";
|
|
419
|
+
type Options = {
|
|
420
|
+
config: ConfigNullable;
|
|
421
|
+
debug: boolean;
|
|
422
|
+
enableLegacyPiP: boolean;
|
|
423
|
+
format: inputFormatType;
|
|
424
|
+
formatted: boolean;
|
|
425
|
+
keepCA: boolean;
|
|
426
|
+
mode: modeType;
|
|
427
|
+
scale: number;
|
|
428
|
+
showCollision: boolean;
|
|
429
|
+
showCommentCount: boolean;
|
|
430
|
+
showFPS: boolean;
|
|
431
|
+
useLegacy: boolean;
|
|
432
|
+
video: HTMLVideoElement | undefined;
|
|
433
|
+
};
|
|
434
|
+
type InitOptions = Partial<Options>;
|
|
573
435
|
|
|
574
|
-
type
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
436
|
+
type formattedCommentWithFont = {
|
|
437
|
+
id: number;
|
|
438
|
+
vpos: number;
|
|
439
|
+
date: number;
|
|
440
|
+
date_usec: number;
|
|
441
|
+
owner: boolean;
|
|
442
|
+
premium: boolean;
|
|
443
|
+
mail: string[];
|
|
444
|
+
user_id: number;
|
|
445
|
+
layer: number;
|
|
446
|
+
loc: commentLoc;
|
|
447
|
+
size: commentSize;
|
|
448
|
+
fontSize: number;
|
|
449
|
+
font: commentFont;
|
|
450
|
+
color: string;
|
|
451
|
+
full: boolean;
|
|
452
|
+
ender: boolean;
|
|
453
|
+
_live: boolean;
|
|
454
|
+
long: number;
|
|
455
|
+
invisible: boolean;
|
|
456
|
+
content: commentContentItem[];
|
|
457
|
+
flash: boolean;
|
|
458
|
+
lineCount: number;
|
|
459
|
+
lineOffset: number;
|
|
460
|
+
};
|
|
461
|
+
type formattedCommentWithSize = formattedCommentWithFont & {
|
|
462
|
+
height: number;
|
|
463
|
+
width: number;
|
|
464
|
+
lineHeight: number;
|
|
465
|
+
resized: boolean;
|
|
466
|
+
resizedX: boolean;
|
|
467
|
+
resizedY: boolean;
|
|
468
|
+
content: commentMeasuredContentItem[];
|
|
469
|
+
charSize: number;
|
|
470
|
+
};
|
|
471
|
+
type parsedComment = formattedCommentWithSize & {
|
|
472
|
+
posY: number;
|
|
473
|
+
image?: HTMLCanvasElement | boolean;
|
|
474
|
+
};
|
|
475
|
+
type commentContentItem = {
|
|
476
|
+
content: string;
|
|
477
|
+
font?: commentFlashFont;
|
|
478
|
+
width?: number[];
|
|
479
|
+
};
|
|
480
|
+
type commentMeasuredContentItem = commentContentItem & {
|
|
481
|
+
width: number[];
|
|
482
|
+
};
|
|
483
|
+
type commentContentIndex = {
|
|
484
|
+
index: number;
|
|
485
|
+
font: "gothic" | "gulim" | "simsunStrong" | "simsunWeak";
|
|
486
|
+
};
|
|
487
|
+
type commentFont = "defont" | "mincho" | "gothic" | "gulim" | "simsun";
|
|
488
|
+
type commentFlashFont = "defont" | "gulim" | "simsun";
|
|
489
|
+
type commentSize = "big" | "medium" | "small";
|
|
490
|
+
type commentLoc = "ue" | "naka" | "shita";
|
|
491
|
+
type collision = { [key in collisionPos]: collisionItem };
|
|
492
|
+
type collisionPos = "ue" | "shita" | "right" | "left";
|
|
493
|
+
type collisionItem = { [p: number]: IComment[] };
|
|
494
|
+
type nicoScript = {
|
|
495
|
+
reverse: nicoScriptReverse[];
|
|
496
|
+
ban: nicoScriptBan[];
|
|
497
|
+
default: nicoScriptDefault[];
|
|
498
|
+
replace: nicoScriptReplace[];
|
|
499
|
+
};
|
|
500
|
+
type nicoScriptReverse = {
|
|
501
|
+
target: nicoScriptReverseTarget;
|
|
502
|
+
start: number;
|
|
503
|
+
end: number;
|
|
504
|
+
};
|
|
505
|
+
type nicoScriptReverseTarget = "コメ" | "投コメ" | "全";
|
|
506
|
+
type nicoScriptReplace = {
|
|
507
|
+
start: number;
|
|
508
|
+
long: number | undefined;
|
|
509
|
+
keyword: string;
|
|
510
|
+
replace: string;
|
|
511
|
+
range: nicoScriptReplaceRange;
|
|
512
|
+
target: nicoScriptReplaceTarget;
|
|
513
|
+
condition: nicoScriptReplaceCondition;
|
|
514
|
+
color: string | undefined;
|
|
515
|
+
size: commentSize | undefined;
|
|
516
|
+
font: commentFont | undefined;
|
|
517
|
+
loc: commentLoc | undefined;
|
|
518
|
+
no: number;
|
|
519
|
+
};
|
|
520
|
+
type nicoScriptReplaceRange = "単" | "全";
|
|
521
|
+
type nicoScriptReplaceTarget = "コメ" | "投コメ" | "全" | "含まない" | "含む";
|
|
522
|
+
type nicoScriptReplaceCondition = "完全一致" | "部分一致";
|
|
523
|
+
type nicoScriptBan = {
|
|
524
|
+
start: number;
|
|
525
|
+
end: number;
|
|
526
|
+
};
|
|
527
|
+
type nicoScriptDefault = {
|
|
528
|
+
start: number;
|
|
529
|
+
long: number | undefined;
|
|
530
|
+
color: string | undefined;
|
|
531
|
+
size: commentSize | undefined;
|
|
532
|
+
font: commentFont | undefined;
|
|
533
|
+
loc: commentLoc | undefined;
|
|
534
|
+
};
|
|
535
|
+
type measureTextResult = {
|
|
536
|
+
width: number;
|
|
537
|
+
height: number;
|
|
538
|
+
resized: boolean;
|
|
539
|
+
resizedX: boolean;
|
|
540
|
+
resizedY: boolean;
|
|
541
|
+
fontSize: number;
|
|
542
|
+
lineHeight: number;
|
|
543
|
+
content: commentMeasuredContentItem[];
|
|
544
|
+
charSize: number;
|
|
545
|
+
};
|
|
546
|
+
type parsedCommand = {
|
|
547
|
+
loc: commentLoc | undefined;
|
|
548
|
+
size: commentSize | undefined;
|
|
549
|
+
fontSize: number | undefined;
|
|
550
|
+
color: string | undefined;
|
|
551
|
+
font: commentFont | undefined;
|
|
552
|
+
full: boolean;
|
|
553
|
+
ender: boolean;
|
|
554
|
+
_live: boolean;
|
|
555
|
+
invisible: boolean;
|
|
556
|
+
long: number | undefined;
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
type measureTextInput = {
|
|
560
|
+
content: commentContentItem[];
|
|
561
|
+
resized?: boolean;
|
|
562
|
+
ender: boolean;
|
|
563
|
+
size: commentSize;
|
|
564
|
+
fontSize: number;
|
|
565
|
+
resizedY?: boolean;
|
|
566
|
+
resizedX?: boolean;
|
|
567
|
+
font: commentFont;
|
|
568
|
+
loc: commentLoc;
|
|
569
|
+
full: boolean;
|
|
570
|
+
flash: boolean;
|
|
571
|
+
lineCount: number;
|
|
572
|
+
lineHeight?: number;
|
|
573
|
+
charSize?: number;
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
type measureInput = {
|
|
577
|
+
font: commentFont;
|
|
578
|
+
content: commentContentItem[];
|
|
579
|
+
lineHeight: number;
|
|
580
|
+
charSize: number;
|
|
581
|
+
lineCount: number;
|
|
582
|
+
};
|
|
581
583
|
|
|
582
584
|
declare const convert2formattedComment: (data: unknown, type: inputFormatType) => formattedComment[];
|
|
583
585
|
|
|
@@ -588,16 +590,16 @@ declare class NiconiComments {
|
|
|
588
590
|
showFPS: boolean;
|
|
589
591
|
showCommentCount: boolean;
|
|
590
592
|
video: HTMLVideoElement | undefined;
|
|
591
|
-
private data;
|
|
592
593
|
private lastVpos;
|
|
593
594
|
private readonly canvas;
|
|
594
595
|
private readonly collision;
|
|
595
596
|
private readonly context;
|
|
596
597
|
private readonly timeline;
|
|
597
598
|
constructor(canvas: HTMLCanvasElement, data: inputFormat, initOptions?: InitOptions);
|
|
598
|
-
preRendering
|
|
599
|
-
getCommentPos
|
|
600
|
-
sortComment
|
|
599
|
+
private preRendering;
|
|
600
|
+
private getCommentPos;
|
|
601
|
+
private sortComment;
|
|
602
|
+
addComments(...rawComments: formattedComment[]): void;
|
|
601
603
|
drawCanvas(vpos: number, forceRendering?: boolean): void;
|
|
602
604
|
clear(): void;
|
|
603
605
|
}
|
|
@@ -671,7 +673,7 @@ declare const typeGuard: {
|
|
|
671
673
|
};
|
|
672
674
|
|
|
673
675
|
|
|
674
|
-
declare const getPosY: (currentPos: number, targetComment: IComment, collision:
|
|
676
|
+
declare const getPosY: (currentPos: number, targetComment: IComment, collision: IComment[] | undefined) => {
|
|
675
677
|
currentPos: number;
|
|
676
678
|
isChanged: boolean;
|
|
677
679
|
isBreak: boolean;
|
|
@@ -679,8 +681,8 @@ declare const getPosY: (currentPos: number, targetComment: IComment, collision:
|
|
|
679
681
|
declare const getPosX: (width: number, vpos: number, long: number) => number;
|
|
680
682
|
declare const parseFont: (font: commentFont, size: string | number) => string;
|
|
681
683
|
declare const arrayPush: (array: {
|
|
682
|
-
[key: number]:
|
|
683
|
-
}, key: string | number, push:
|
|
684
|
+
[key: number]: IComment[];
|
|
685
|
+
}, key: string | number, push: IComment) => void;
|
|
684
686
|
declare const hex2rgb: (hex: string) => number[];
|
|
685
687
|
declare const replaceAll: (string: string, target: string, replace: string) => string;
|
|
686
688
|
declare const changeCALayer: (rawData: formattedComment[]) => formattedComment[];
|
package/dist/bundle.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
niconicomments.js v0.2.
|
|
2
|
+
niconicomments.js v0.2.36
|
|
3
3
|
(c) 2021 xpadev-net https://xpadev.net
|
|
4
4
|
Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -304,7 +304,10 @@
|
|
|
304
304
|
|
|
305
305
|
var convert2formattedComment = function (data, type) {
|
|
306
306
|
var result = [];
|
|
307
|
-
if (type === "
|
|
307
|
+
if (type === "empty" && data === undefined) {
|
|
308
|
+
return [];
|
|
309
|
+
}
|
|
310
|
+
else if (type === "niconicome" && typeGuard.niconicome.xmlDocument(data)) {
|
|
308
311
|
result = fromNiconicome(data);
|
|
309
312
|
}
|
|
310
313
|
else if (type === "formatted" && typeGuard.formatted.legacyComments(data)) {
|
|
@@ -944,15 +947,12 @@
|
|
|
944
947
|
};
|
|
945
948
|
};
|
|
946
949
|
|
|
947
|
-
var getPosY = function (currentPos, targetComment, collision
|
|
950
|
+
var getPosY = function (currentPos, targetComment, collision) {
|
|
948
951
|
var isChanged = false, isBreak = false;
|
|
949
952
|
if (!collision)
|
|
950
953
|
return { currentPos: currentPos, isChanged: isChanged, isBreak: isBreak };
|
|
951
954
|
for (var _i = 0, collision_1 = collision; _i < collision_1.length; _i++) {
|
|
952
|
-
var
|
|
953
|
-
var collisionItem = data[index];
|
|
954
|
-
if (!collisionItem)
|
|
955
|
-
continue;
|
|
955
|
+
var collisionItem = collision_1[_i];
|
|
956
956
|
if (currentPos < collisionItem.posY + collisionItem.height &&
|
|
957
957
|
currentPos + targetComment.height > collisionItem.posY &&
|
|
958
958
|
collisionItem.owner === targetComment.owner &&
|
|
@@ -1046,7 +1046,7 @@
|
|
|
1046
1046
|
userList[value.user_id] +=
|
|
1047
1047
|
(value.content.match(/\r\n|\n|\r/g) || []).length / 2;
|
|
1048
1048
|
}
|
|
1049
|
-
var key = "".concat(value.content, "@@").concat(
|
|
1049
|
+
var key = "".concat(value.content, "@@").concat(__spreadArray([], value.mail, true).sort()
|
|
1050
1050
|
.filter(function (e) { return !e.match(/@[\d.]+|184|device:.+|patissier|ca/); })
|
|
1051
1051
|
.join("")), lastComment = index[key];
|
|
1052
1052
|
if (lastComment !== undefined) {
|
|
@@ -2373,7 +2373,6 @@
|
|
|
2373
2373
|
pv[value] = [];
|
|
2374
2374
|
return pv;
|
|
2375
2375
|
}, {});
|
|
2376
|
-
this.data = [];
|
|
2377
2376
|
this.lastVpos = -1;
|
|
2378
2377
|
this.preRendering(parsedData);
|
|
2379
2378
|
logger("constructor complete: ".concat(performance.now() - constructorStart, "ms"));
|
|
@@ -2384,7 +2383,7 @@
|
|
|
2384
2383
|
if (options.keepCA) {
|
|
2385
2384
|
rawData = changeCALayer(rawData);
|
|
2386
2385
|
}
|
|
2387
|
-
|
|
2386
|
+
this.getCommentPos(rawData.reduce(function (pv, val) {
|
|
2388
2387
|
if (isFlashComment(val)) {
|
|
2389
2388
|
pv.push(new FlashComment(val, _this.context));
|
|
2390
2389
|
}
|
|
@@ -2393,13 +2392,13 @@
|
|
|
2393
2392
|
}
|
|
2394
2393
|
return pv;
|
|
2395
2394
|
}, []));
|
|
2396
|
-
this.
|
|
2395
|
+
this.sortComment();
|
|
2397
2396
|
logger("preRendering complete: ".concat(performance.now() - preRenderingStart, "ms"));
|
|
2398
2397
|
};
|
|
2399
2398
|
NiconiComments.prototype.getCommentPos = function (data) {
|
|
2400
2399
|
var _this = this;
|
|
2401
2400
|
var getCommentPosStart = performance.now();
|
|
2402
|
-
data.forEach(function (comment
|
|
2401
|
+
data.forEach(function (comment) {
|
|
2403
2402
|
if (comment.invisible)
|
|
2404
2403
|
return;
|
|
2405
2404
|
if (comment.loc === "naka") {
|
|
@@ -2419,7 +2418,7 @@
|
|
|
2419
2418
|
var left_pos = getPosX(comment.width, j, comment.long);
|
|
2420
2419
|
if (left_pos + comment.width >= config.collisionRange.right &&
|
|
2421
2420
|
left_pos <= config.collisionRange.right) {
|
|
2422
|
-
var result = getPosY(posY, comment, _this.collision.right[vpos]
|
|
2421
|
+
var result = getPosY(posY, comment, _this.collision.right[vpos]);
|
|
2423
2422
|
posY = result.currentPos;
|
|
2424
2423
|
isChanged = result.isChanged;
|
|
2425
2424
|
isBreak = result.isBreak;
|
|
@@ -2428,7 +2427,7 @@
|
|
|
2428
2427
|
}
|
|
2429
2428
|
if (left_pos + comment.width >= config.collisionRange.left &&
|
|
2430
2429
|
left_pos <= config.collisionRange.left) {
|
|
2431
|
-
var result = getPosY(posY, comment, _this.collision.left[vpos]
|
|
2430
|
+
var result = getPosY(posY, comment, _this.collision.left[vpos]);
|
|
2432
2431
|
posY = result.currentPos;
|
|
2433
2432
|
isChanged = result.isChanged;
|
|
2434
2433
|
isBreak = result.isBreak;
|
|
@@ -2444,14 +2443,14 @@
|
|
|
2444
2443
|
for (var j = beforeVpos; j < comment.long + 125; j++) {
|
|
2445
2444
|
var vpos = comment.vpos + j;
|
|
2446
2445
|
var left_pos = getPosX(comment.width, j, comment.long);
|
|
2447
|
-
arrayPush(_this.timeline, vpos,
|
|
2446
|
+
arrayPush(_this.timeline, vpos, comment);
|
|
2448
2447
|
if (left_pos + comment.width >= config.collisionRange.right &&
|
|
2449
2448
|
left_pos <= config.collisionRange.right) {
|
|
2450
|
-
arrayPush(_this.collision.right, vpos,
|
|
2449
|
+
arrayPush(_this.collision.right, vpos, comment);
|
|
2451
2450
|
}
|
|
2452
2451
|
if (left_pos + comment.width >= config.collisionRange.left &&
|
|
2453
2452
|
left_pos <= config.collisionRange.left) {
|
|
2454
|
-
arrayPush(_this.collision.left, vpos,
|
|
2453
|
+
arrayPush(_this.collision.left, vpos, comment);
|
|
2455
2454
|
}
|
|
2456
2455
|
}
|
|
2457
2456
|
comment.posY = posY;
|
|
@@ -2468,7 +2467,7 @@
|
|
|
2468
2467
|
isChanged = false;
|
|
2469
2468
|
count++;
|
|
2470
2469
|
for (var j = 0; j < comment.long; j++) {
|
|
2471
|
-
var result = getPosY(posY, comment, collision[comment.vpos + j]
|
|
2470
|
+
var result = getPosY(posY, comment, collision[comment.vpos + j]);
|
|
2472
2471
|
posY = result.currentPos;
|
|
2473
2472
|
isChanged = result.isChanged;
|
|
2474
2473
|
if (result.isBreak)
|
|
@@ -2477,14 +2476,14 @@
|
|
|
2477
2476
|
}
|
|
2478
2477
|
for (var j = 0; j < comment.long; j++) {
|
|
2479
2478
|
var vpos = comment.vpos + j;
|
|
2480
|
-
arrayPush(_this.timeline, vpos,
|
|
2479
|
+
arrayPush(_this.timeline, vpos, comment);
|
|
2481
2480
|
if (j > comment.long - 20)
|
|
2482
2481
|
continue;
|
|
2483
2482
|
if (comment.loc === "ue") {
|
|
2484
|
-
arrayPush(_this.collision.ue, vpos,
|
|
2483
|
+
arrayPush(_this.collision.ue, vpos, comment);
|
|
2485
2484
|
}
|
|
2486
2485
|
else {
|
|
2487
|
-
arrayPush(_this.collision.shita, vpos,
|
|
2486
|
+
arrayPush(_this.collision.shita, vpos, comment);
|
|
2488
2487
|
}
|
|
2489
2488
|
}
|
|
2490
2489
|
comment.posY = posY;
|
|
@@ -2493,28 +2492,141 @@
|
|
|
2493
2492
|
logger("getCommentPos complete: ".concat(performance.now() - getCommentPosStart, "ms"));
|
|
2494
2493
|
return data;
|
|
2495
2494
|
};
|
|
2496
|
-
NiconiComments.prototype.sortComment = function (
|
|
2497
|
-
var _a;
|
|
2495
|
+
NiconiComments.prototype.sortComment = function () {
|
|
2498
2496
|
var sortCommentStart = performance.now();
|
|
2499
|
-
for (var _i = 0,
|
|
2500
|
-
var vpos =
|
|
2497
|
+
for (var _i = 0, _a = Object.keys(this.timeline); _i < _a.length; _i++) {
|
|
2498
|
+
var vpos = _a[_i];
|
|
2501
2499
|
var item = this.timeline[Number(vpos)];
|
|
2502
2500
|
if (!item)
|
|
2503
2501
|
continue;
|
|
2504
2502
|
var owner = [], user = [];
|
|
2505
|
-
for (var
|
|
2506
|
-
var
|
|
2507
|
-
if (
|
|
2508
|
-
owner.push(
|
|
2503
|
+
for (var _b = 0, item_1 = item; _b < item_1.length; _b++) {
|
|
2504
|
+
var comment = item_1[_b];
|
|
2505
|
+
if (comment === null || comment === void 0 ? void 0 : comment.owner) {
|
|
2506
|
+
owner.push(comment);
|
|
2509
2507
|
}
|
|
2510
2508
|
else {
|
|
2511
|
-
user.push(
|
|
2509
|
+
user.push(comment);
|
|
2512
2510
|
}
|
|
2513
2511
|
}
|
|
2514
2512
|
this.timeline[Number(vpos)] = user.concat(owner);
|
|
2515
2513
|
}
|
|
2516
2514
|
logger("parseData complete: ".concat(performance.now() - sortCommentStart, "ms"));
|
|
2517
|
-
|
|
2515
|
+
};
|
|
2516
|
+
NiconiComments.prototype.addComments = function () {
|
|
2517
|
+
var _this = this;
|
|
2518
|
+
var _a, _b, _c;
|
|
2519
|
+
var rawComments = [];
|
|
2520
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2521
|
+
rawComments[_i] = arguments[_i];
|
|
2522
|
+
}
|
|
2523
|
+
var comments = rawComments.reduce(function (pv, val) {
|
|
2524
|
+
if (isFlashComment(val)) {
|
|
2525
|
+
pv.push(new FlashComment(val, _this.context));
|
|
2526
|
+
}
|
|
2527
|
+
else {
|
|
2528
|
+
pv.push(new HTML5Comment(val, _this.context));
|
|
2529
|
+
}
|
|
2530
|
+
return pv;
|
|
2531
|
+
}, []);
|
|
2532
|
+
var _loop_1 = function (comment) {
|
|
2533
|
+
if (comment.invisible)
|
|
2534
|
+
return "continue";
|
|
2535
|
+
if (comment.loc === "naka") {
|
|
2536
|
+
var posY = 0;
|
|
2537
|
+
var beforeVpos = Math.round(-288 / ((1632 + comment.width) / (comment.long + 125))) -
|
|
2538
|
+
100;
|
|
2539
|
+
if (config.canvasHeight < comment.height) {
|
|
2540
|
+
posY = (comment.height - config.canvasHeight) / -2;
|
|
2541
|
+
}
|
|
2542
|
+
else {
|
|
2543
|
+
var isBreak = false, isChanged = true, count = 0;
|
|
2544
|
+
while (isChanged && count < 10) {
|
|
2545
|
+
isChanged = false;
|
|
2546
|
+
count++;
|
|
2547
|
+
for (var j = beforeVpos; j < comment.long + 125; j++) {
|
|
2548
|
+
var vpos = comment.vpos + j;
|
|
2549
|
+
var left_pos = getPosX(comment.width, j, comment.long);
|
|
2550
|
+
if (left_pos + comment.width >= config.collisionRange.right &&
|
|
2551
|
+
left_pos <= config.collisionRange.right) {
|
|
2552
|
+
var collision = (_a = this_1.collision.right[vpos]) === null || _a === void 0 ? void 0 : _a.filter(function (val) { return val.vpos <= comment.vpos; });
|
|
2553
|
+
var result = getPosY(posY, comment, collision);
|
|
2554
|
+
posY = result.currentPos;
|
|
2555
|
+
isChanged = result.isChanged;
|
|
2556
|
+
isBreak = result.isBreak;
|
|
2557
|
+
if (isBreak)
|
|
2558
|
+
break;
|
|
2559
|
+
}
|
|
2560
|
+
if (left_pos + comment.width >= config.collisionRange.left &&
|
|
2561
|
+
left_pos <= config.collisionRange.left) {
|
|
2562
|
+
var collision = (_b = this_1.collision.left[vpos]) === null || _b === void 0 ? void 0 : _b.filter(function (val) { return val.vpos <= comment.vpos; });
|
|
2563
|
+
var result = getPosY(posY, comment, collision);
|
|
2564
|
+
posY = result.currentPos;
|
|
2565
|
+
isChanged = result.isChanged;
|
|
2566
|
+
isBreak = result.isBreak;
|
|
2567
|
+
if (isBreak)
|
|
2568
|
+
break;
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
if (isBreak) {
|
|
2572
|
+
break;
|
|
2573
|
+
}
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
for (var j = beforeVpos; j < comment.long + 125; j++) {
|
|
2577
|
+
var vpos = comment.vpos + j;
|
|
2578
|
+
var left_pos = getPosX(comment.width, j, comment.long);
|
|
2579
|
+
arrayPush(this_1.timeline, vpos, comment);
|
|
2580
|
+
if (left_pos + comment.width >= config.collisionRange.right &&
|
|
2581
|
+
left_pos <= config.collisionRange.right) {
|
|
2582
|
+
arrayPush(this_1.collision.right, vpos, comment);
|
|
2583
|
+
}
|
|
2584
|
+
if (left_pos + comment.width >= config.collisionRange.left &&
|
|
2585
|
+
left_pos <= config.collisionRange.left) {
|
|
2586
|
+
arrayPush(this_1.collision.left, vpos, comment);
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
comment.posY = posY;
|
|
2590
|
+
}
|
|
2591
|
+
else {
|
|
2592
|
+
var posY = 0, isChanged = true, count = 0, collision = void 0;
|
|
2593
|
+
if (comment.loc === "ue") {
|
|
2594
|
+
collision = this_1.collision.ue;
|
|
2595
|
+
}
|
|
2596
|
+
else {
|
|
2597
|
+
collision = this_1.collision.shita;
|
|
2598
|
+
}
|
|
2599
|
+
while (isChanged && count < 10) {
|
|
2600
|
+
isChanged = false;
|
|
2601
|
+
count++;
|
|
2602
|
+
for (var j = 0; j < comment.long; j++) {
|
|
2603
|
+
var result = getPosY(posY, comment, (_c = collision[comment.vpos + j]) === null || _c === void 0 ? void 0 : _c.filter(function (val) { return val.vpos <= comment.vpos; }));
|
|
2604
|
+
posY = result.currentPos;
|
|
2605
|
+
isChanged = result.isChanged;
|
|
2606
|
+
if (result.isBreak)
|
|
2607
|
+
break;
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
for (var j = 0; j < comment.long; j++) {
|
|
2611
|
+
var vpos = comment.vpos + j;
|
|
2612
|
+
arrayPush(this_1.timeline, vpos, comment);
|
|
2613
|
+
if (j > comment.long - 20)
|
|
2614
|
+
continue;
|
|
2615
|
+
if (comment.loc === "ue") {
|
|
2616
|
+
arrayPush(this_1.collision.ue, vpos, comment);
|
|
2617
|
+
}
|
|
2618
|
+
else {
|
|
2619
|
+
arrayPush(this_1.collision.shita, vpos, comment);
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
comment.posY = posY;
|
|
2623
|
+
}
|
|
2624
|
+
};
|
|
2625
|
+
var this_1 = this;
|
|
2626
|
+
for (var _d = 0, comments_1 = comments; _d < comments_1.length; _d++) {
|
|
2627
|
+
var comment = comments_1[_d];
|
|
2628
|
+
_loop_1(comment);
|
|
2629
|
+
}
|
|
2518
2630
|
};
|
|
2519
2631
|
NiconiComments.prototype.drawCanvas = function (vpos, forceRendering) {
|
|
2520
2632
|
if (forceRendering === void 0) { forceRendering = false; }
|
|
@@ -2541,28 +2653,21 @@
|
|
|
2541
2653
|
this.context.fillStyle = "red";
|
|
2542
2654
|
if (leftCollision) {
|
|
2543
2655
|
for (var _i = 0, leftCollision_1 = leftCollision; _i < leftCollision_1.length; _i++) {
|
|
2544
|
-
var
|
|
2545
|
-
|
|
2546
|
-
if (!value)
|
|
2547
|
-
continue;
|
|
2548
|
-
this.context.fillRect(config.collisionRange.left, value.posY, config.contextLineWidth, value.height);
|
|
2656
|
+
var comment = leftCollision_1[_i];
|
|
2657
|
+
this.context.fillRect(config.collisionRange.left, comment.posY, config.contextLineWidth, comment.height);
|
|
2549
2658
|
}
|
|
2550
2659
|
}
|
|
2551
2660
|
if (rightCollision) {
|
|
2552
2661
|
for (var _a = 0, rightCollision_1 = rightCollision; _a < rightCollision_1.length; _a++) {
|
|
2553
|
-
var
|
|
2554
|
-
|
|
2555
|
-
if (!value)
|
|
2556
|
-
continue;
|
|
2557
|
-
this.context.fillRect(config.collisionRange.right, value.posY, config.contextLineWidth * -1, value.height);
|
|
2662
|
+
var comment = rightCollision_1[_a];
|
|
2663
|
+
this.context.fillRect(config.collisionRange.right, comment.posY, config.contextLineWidth * -1, comment.height);
|
|
2558
2664
|
}
|
|
2559
2665
|
}
|
|
2560
2666
|
}
|
|
2561
2667
|
if (timelineRange) {
|
|
2562
2668
|
for (var _b = 0, timelineRange_1 = timelineRange; _b < timelineRange_1.length; _b++) {
|
|
2563
|
-
var
|
|
2564
|
-
|
|
2565
|
-
if (!comment || comment.invisible) {
|
|
2669
|
+
var comment = timelineRange_1[_b];
|
|
2670
|
+
if (comment.invisible) {
|
|
2566
2671
|
continue;
|
|
2567
2672
|
}
|
|
2568
2673
|
comment.draw(vpos, this.showCollision, isDebug);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xpadev-net/niconicomments",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.36",
|
|
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",
|
|
@@ -24,7 +24,12 @@
|
|
|
24
24
|
"url": "git+https://github.com/xpadev-net/niconicomments.git"
|
|
25
25
|
},
|
|
26
26
|
"keywords": [
|
|
27
|
-
"
|
|
27
|
+
"canvas",
|
|
28
|
+
"comment",
|
|
29
|
+
"danmaku",
|
|
30
|
+
"html5",
|
|
31
|
+
"niconico",
|
|
32
|
+
"nicovide"
|
|
28
33
|
],
|
|
29
34
|
"author": "xpadev(xpadev.net)",
|
|
30
35
|
"bugs": {
|