@xpadev-net/niconicomments 0.2.34 → 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 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
- | "default";
408
- type inputFormat =
409
- | XMLDocument
410
- | formattedComment[]
411
- | formattedLegacyComment[]
412
- | rawApiResponse[]
413
- | ownerComment[]
414
- | v1Thread[]
415
- | string;
416
- type modeType = "default" | "html5" | "flash";
417
- type Options = {
418
- config: ConfigNullable;
419
- debug: boolean;
420
- enableLegacyPiP: boolean;
421
- format: inputFormatType;
422
- formatted: boolean;
423
- keepCA: boolean;
424
- mode: modeType;
425
- scale: number;
426
- showCollision: boolean;
427
- showCommentCount: boolean;
428
- showFPS: boolean;
429
- useLegacy: boolean;
430
- video: HTMLVideoElement | undefined;
431
- };
432
- type InitOptions = Partial<Options>;
433
-
434
- type formattedCommentWithFont = {
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 measureInput = {
575
- font: commentFont;
576
- content: commentContentItem[];
577
- lineHeight: number;
578
- charSize: number;
579
- lineCount: number;
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(rawData: formattedComment[]): void;
599
- getCommentPos(data: IComment[]): IComment[];
600
- sortComment(parsedData: IComment[]): IComment[];
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: number[] | undefined, data: IComment[]) => {
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]: number[];
683
- }, key: string | number, push: number) => void;
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.34
2
+ niconicomments.js v0.2.36
3
3
  (c) 2021 xpadev-net https://xpadev.net
4
4
  Released under the MIT License.
5
5
  */
@@ -132,7 +132,6 @@
132
132
  "date",
133
133
  "date_usec",
134
134
  "anonymity",
135
- "user_id",
136
135
  "mail",
137
136
  "leaf",
138
137
  "premium",
@@ -305,7 +304,10 @@
305
304
 
306
305
  var convert2formattedComment = function (data, type) {
307
306
  var result = [];
308
- if (type === "niconicome" && typeGuard.niconicome.xmlDocument(data)) {
307
+ if (type === "empty" && data === undefined) {
308
+ return [];
309
+ }
310
+ else if (type === "niconicome" && typeGuard.niconicome.xmlDocument(data)) {
309
311
  result = fromNiconicome(data);
310
312
  }
311
313
  else if (type === "formatted" && typeGuard.formatted.legacyComments(data)) {
@@ -945,15 +947,12 @@
945
947
  };
946
948
  };
947
949
 
948
- var getPosY = function (currentPos, targetComment, collision, data) {
950
+ var getPosY = function (currentPos, targetComment, collision) {
949
951
  var isChanged = false, isBreak = false;
950
952
  if (!collision)
951
953
  return { currentPos: currentPos, isChanged: isChanged, isBreak: isBreak };
952
954
  for (var _i = 0, collision_1 = collision; _i < collision_1.length; _i++) {
953
- var index = collision_1[_i];
954
- var collisionItem = data[index];
955
- if (!collisionItem)
956
- continue;
955
+ var collisionItem = collision_1[_i];
957
956
  if (currentPos < collisionItem.posY + collisionItem.height &&
958
957
  currentPos + targetComment.height > collisionItem.posY &&
959
958
  collisionItem.owner === targetComment.owner &&
@@ -1047,7 +1046,7 @@
1047
1046
  userList[value.user_id] +=
1048
1047
  (value.content.match(/\r\n|\n|\r/g) || []).length / 2;
1049
1048
  }
1050
- var key = "".concat(value.content, "@@").concat(Array.from(new Set(__spreadArray([], value.mail, true).sort()))
1049
+ var key = "".concat(value.content, "@@").concat(__spreadArray([], value.mail, true).sort()
1051
1050
  .filter(function (e) { return !e.match(/@[\d.]+|184|device:.+|patissier|ca/); })
1052
1051
  .join("")), lastComment = index[key];
1053
1052
  if (lastComment !== undefined) {
@@ -2374,7 +2373,6 @@
2374
2373
  pv[value] = [];
2375
2374
  return pv;
2376
2375
  }, {});
2377
- this.data = [];
2378
2376
  this.lastVpos = -1;
2379
2377
  this.preRendering(parsedData);
2380
2378
  logger("constructor complete: ".concat(performance.now() - constructorStart, "ms"));
@@ -2385,7 +2383,7 @@
2385
2383
  if (options.keepCA) {
2386
2384
  rawData = changeCALayer(rawData);
2387
2385
  }
2388
- var parsedData = this.getCommentPos(rawData.reduce(function (pv, val) {
2386
+ this.getCommentPos(rawData.reduce(function (pv, val) {
2389
2387
  if (isFlashComment(val)) {
2390
2388
  pv.push(new FlashComment(val, _this.context));
2391
2389
  }
@@ -2394,13 +2392,13 @@
2394
2392
  }
2395
2393
  return pv;
2396
2394
  }, []));
2397
- this.data = this.sortComment(parsedData);
2395
+ this.sortComment();
2398
2396
  logger("preRendering complete: ".concat(performance.now() - preRenderingStart, "ms"));
2399
2397
  };
2400
2398
  NiconiComments.prototype.getCommentPos = function (data) {
2401
2399
  var _this = this;
2402
2400
  var getCommentPosStart = performance.now();
2403
- data.forEach(function (comment, index) {
2401
+ data.forEach(function (comment) {
2404
2402
  if (comment.invisible)
2405
2403
  return;
2406
2404
  if (comment.loc === "naka") {
@@ -2420,7 +2418,7 @@
2420
2418
  var left_pos = getPosX(comment.width, j, comment.long);
2421
2419
  if (left_pos + comment.width >= config.collisionRange.right &&
2422
2420
  left_pos <= config.collisionRange.right) {
2423
- var result = getPosY(posY, comment, _this.collision.right[vpos], data);
2421
+ var result = getPosY(posY, comment, _this.collision.right[vpos]);
2424
2422
  posY = result.currentPos;
2425
2423
  isChanged = result.isChanged;
2426
2424
  isBreak = result.isBreak;
@@ -2429,7 +2427,7 @@
2429
2427
  }
2430
2428
  if (left_pos + comment.width >= config.collisionRange.left &&
2431
2429
  left_pos <= config.collisionRange.left) {
2432
- var result = getPosY(posY, comment, _this.collision.left[vpos], data);
2430
+ var result = getPosY(posY, comment, _this.collision.left[vpos]);
2433
2431
  posY = result.currentPos;
2434
2432
  isChanged = result.isChanged;
2435
2433
  isBreak = result.isBreak;
@@ -2445,14 +2443,14 @@
2445
2443
  for (var j = beforeVpos; j < comment.long + 125; j++) {
2446
2444
  var vpos = comment.vpos + j;
2447
2445
  var left_pos = getPosX(comment.width, j, comment.long);
2448
- arrayPush(_this.timeline, vpos, index);
2446
+ arrayPush(_this.timeline, vpos, comment);
2449
2447
  if (left_pos + comment.width >= config.collisionRange.right &&
2450
2448
  left_pos <= config.collisionRange.right) {
2451
- arrayPush(_this.collision.right, vpos, index);
2449
+ arrayPush(_this.collision.right, vpos, comment);
2452
2450
  }
2453
2451
  if (left_pos + comment.width >= config.collisionRange.left &&
2454
2452
  left_pos <= config.collisionRange.left) {
2455
- arrayPush(_this.collision.left, vpos, index);
2453
+ arrayPush(_this.collision.left, vpos, comment);
2456
2454
  }
2457
2455
  }
2458
2456
  comment.posY = posY;
@@ -2469,7 +2467,7 @@
2469
2467
  isChanged = false;
2470
2468
  count++;
2471
2469
  for (var j = 0; j < comment.long; j++) {
2472
- var result = getPosY(posY, comment, collision[comment.vpos + j], data);
2470
+ var result = getPosY(posY, comment, collision[comment.vpos + j]);
2473
2471
  posY = result.currentPos;
2474
2472
  isChanged = result.isChanged;
2475
2473
  if (result.isBreak)
@@ -2478,14 +2476,14 @@
2478
2476
  }
2479
2477
  for (var j = 0; j < comment.long; j++) {
2480
2478
  var vpos = comment.vpos + j;
2481
- arrayPush(_this.timeline, vpos, index);
2479
+ arrayPush(_this.timeline, vpos, comment);
2482
2480
  if (j > comment.long - 20)
2483
2481
  continue;
2484
2482
  if (comment.loc === "ue") {
2485
- arrayPush(_this.collision.ue, vpos, index);
2483
+ arrayPush(_this.collision.ue, vpos, comment);
2486
2484
  }
2487
2485
  else {
2488
- arrayPush(_this.collision.shita, vpos, index);
2486
+ arrayPush(_this.collision.shita, vpos, comment);
2489
2487
  }
2490
2488
  }
2491
2489
  comment.posY = posY;
@@ -2494,28 +2492,141 @@
2494
2492
  logger("getCommentPos complete: ".concat(performance.now() - getCommentPosStart, "ms"));
2495
2493
  return data;
2496
2494
  };
2497
- NiconiComments.prototype.sortComment = function (parsedData) {
2498
- var _a;
2495
+ NiconiComments.prototype.sortComment = function () {
2499
2496
  var sortCommentStart = performance.now();
2500
- for (var _i = 0, _b = Object.keys(this.timeline); _i < _b.length; _i++) {
2501
- var vpos = _b[_i];
2497
+ for (var _i = 0, _a = Object.keys(this.timeline); _i < _a.length; _i++) {
2498
+ var vpos = _a[_i];
2502
2499
  var item = this.timeline[Number(vpos)];
2503
2500
  if (!item)
2504
2501
  continue;
2505
2502
  var owner = [], user = [];
2506
- for (var _c = 0, item_1 = item; _c < item_1.length; _c++) {
2507
- var index = item_1[_c];
2508
- if ((_a = parsedData[index]) === null || _a === void 0 ? void 0 : _a.owner) {
2509
- owner.push(index);
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);
2510
2507
  }
2511
2508
  else {
2512
- user.push(index);
2509
+ user.push(comment);
2513
2510
  }
2514
2511
  }
2515
2512
  this.timeline[Number(vpos)] = user.concat(owner);
2516
2513
  }
2517
2514
  logger("parseData complete: ".concat(performance.now() - sortCommentStart, "ms"));
2518
- return parsedData;
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
+ }
2519
2630
  };
2520
2631
  NiconiComments.prototype.drawCanvas = function (vpos, forceRendering) {
2521
2632
  if (forceRendering === void 0) { forceRendering = false; }
@@ -2542,28 +2653,21 @@
2542
2653
  this.context.fillStyle = "red";
2543
2654
  if (leftCollision) {
2544
2655
  for (var _i = 0, leftCollision_1 = leftCollision; _i < leftCollision_1.length; _i++) {
2545
- var index = leftCollision_1[_i];
2546
- var value = this.data[index];
2547
- if (!value)
2548
- continue;
2549
- 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);
2550
2658
  }
2551
2659
  }
2552
2660
  if (rightCollision) {
2553
2661
  for (var _a = 0, rightCollision_1 = rightCollision; _a < rightCollision_1.length; _a++) {
2554
- var index = rightCollision_1[_a];
2555
- var value = this.data[index];
2556
- if (!value)
2557
- continue;
2558
- 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);
2559
2664
  }
2560
2665
  }
2561
2666
  }
2562
2667
  if (timelineRange) {
2563
2668
  for (var _b = 0, timelineRange_1 = timelineRange; _b < timelineRange_1.length; _b++) {
2564
- var index = timelineRange_1[_b];
2565
- var comment = this.data[index];
2566
- if (!comment || comment.invisible) {
2669
+ var comment = timelineRange_1[_b];
2670
+ if (comment.invisible) {
2567
2671
  continue;
2568
2672
  }
2569
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.34",
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
- "niconico"
27
+ "canvas",
28
+ "comment",
29
+ "danmaku",
30
+ "html5",
31
+ "niconico",
32
+ "nicovide"
28
33
  ],
29
34
  "author": "xpadev(xpadev.net)",
30
35
  "bugs": {