@xpadev-net/niconicomments 0.2.53 → 0.2.55

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
@@ -30,6 +30,7 @@ declare class BaseComment implements IComment {
30
30
  draw(vpos: number, showCollision: boolean, debug: boolean): void;
31
31
  protected _draw(posX: number, posY: number): void;
32
32
  protected _drawRectColor(posX: number, posY: number): void;
33
+ protected _drawBackgroundColor(posX: number, posY: number): void;
33
34
  protected _drawDebugInfo(posX: number, posY: number, debug: boolean): void;
34
35
  protected _drawCollision(posX: number, posY: number, showCollision: boolean): void;
35
36
  protected getTextImage(): Canvas | null;
@@ -440,194 +441,197 @@ type inputFormatType = InputFormatType;
440
441
  */
441
442
  type inputFormat = InputFormat;
442
443
 
443
- type FormattedCommentWithFont = {
444
- id: number;
445
- vpos: number;
446
- date: number;
447
- date_usec: number;
448
- owner: boolean;
449
- premium: boolean;
450
- mail: string[];
451
- user_id: number;
452
- layer: number;
453
- loc: CommentLoc;
454
- size: CommentSize;
455
- fontSize: number;
456
- font: CommentFont;
457
- color: string;
458
- strokeColor?: string;
459
- wakuColor?: string;
460
- full: boolean;
461
- ender: boolean;
462
- _live: boolean;
463
- long: number;
464
- invisible: boolean;
465
- content: CommentContentItem[];
466
- rawContent: string;
467
- flash: boolean;
468
- lineCount: number;
469
- lineOffset: number;
470
- };
471
- type FormattedCommentWithSize = FormattedCommentWithFont & {
472
- height: number;
473
- width: number;
474
- lineHeight: number;
475
- resized: boolean;
476
- resizedX: boolean;
477
- resizedY: boolean;
478
- content: CommentMeasuredContentItem[];
479
- charSize: number;
480
- };
481
- type ParseContentResult = {
482
- content: CommentContentItem[];
483
- lineCount: number;
484
- lineOffset: number;
485
- };
486
- type ParseCommandAndNicoScriptResult = {
487
- flash: boolean;
488
- loc: CommentLoc;
489
- size: CommentSize;
490
- fontSize: number;
491
- color: string;
492
- strokeColor?: string;
493
- wakuColor?: string;
494
- font: CommentFont;
495
- full: boolean;
496
- ender: boolean;
497
- _live: boolean;
498
- invisible: boolean;
499
- long: number;
500
- };
501
- type CommentContentItem = {
502
- content: string;
503
- slicedContent: string[];
504
- font?: CommentFlashFont;
505
- width?: number[];
506
- };
507
- type CommentMeasuredContentItem = CommentContentItem & {
508
- width: number[];
509
- };
510
- type CommentContentIndex = {
511
- index: number;
512
- font: "gothic" | "gulim" | "simsunStrong" | "simsunWeak";
513
- };
514
- type CommentFont = "defont" | "mincho" | "gothic" | "gulim" | "simsun";
515
- type CommentFlashFont = "defont" | "gulim" | "simsun";
516
- type CommentSize = "big" | "medium" | "small";
517
- type CommentLoc = "ue" | "naka" | "shita";
518
- type Collision = { [key in CollisionPos]: CollisionItem };
519
- type Timeline = { [key: number]: IComment[] };
520
- type CollisionPos = "ue" | "shita" | "right" | "left";
521
- type CollisionItem = { [p: number]: IComment[] };
522
- type NicoScript = {
523
- reverse: NicoScriptReverse[];
524
- ban: NicoScriptBan[];
525
- default: NicoScriptDefault[];
526
- replace: NicoScriptReplace[];
527
- seekDisable: NicoScriptSeekDisable[];
528
- jump: NicoScriptJump[];
529
- };
530
- type NicoScriptSeekDisable = {
531
- start: number;
532
- end: number;
533
- };
534
- type NicoScriptJump = {
535
- start: number;
536
- end?: number;
537
- to: string;
538
- message?: string;
539
- };
540
- type NicoScriptReverse = {
541
- target: NicoScriptReverseTarget;
542
- start: number;
543
- end: number;
544
- };
545
- type NicoScriptReverseTarget = "コメ" | "投コメ" | "全";
546
- type NicoScriptReplace = {
547
- start: number;
548
- long: number | undefined;
549
- keyword: string;
550
- replace: string;
551
- range: NicoScriptReplaceRange;
552
- target: NicoScriptReplaceTarget;
553
- condition: NicoScriptReplaceCondition;
554
- color: string | undefined;
555
- size: CommentSize | undefined;
556
- font: CommentFont | undefined;
557
- loc: CommentLoc | undefined;
558
- no: number;
559
- };
560
- type NicoScriptReplaceRange = "単" | "全";
561
- type NicoScriptReplaceTarget =
562
- | "コメ"
563
- | "投コメ"
564
- | ""
565
- | "含まない"
566
- | "含む";
567
- type NicoScriptReplaceCondition = "完全一致" | "部分一致";
568
- type NicoScriptBan = {
569
- start: number;
570
- end: number;
571
- };
572
- type NicoScriptDefault = {
573
- start: number;
574
- long: number | undefined;
575
- color: string | undefined;
576
- size: CommentSize | undefined;
577
- font: CommentFont | undefined;
578
- loc: CommentLoc | undefined;
579
- };
580
- type MeasureTextResult = {
581
- width: number;
582
- height: number;
583
- resized: boolean;
584
- resizedX: boolean;
585
- resizedY: boolean;
586
- fontSize: number;
587
- lineHeight: number;
588
- content: CommentMeasuredContentItem[];
589
- charSize: number;
590
- };
591
- type ParsedCommand = {
592
- loc: CommentLoc | undefined;
593
- size: CommentSize | undefined;
594
- fontSize: number | undefined;
595
- color: string | undefined;
596
- strokeColor?: string;
597
- wakuColor?: string;
598
- font: CommentFont | undefined;
599
- full: boolean;
600
- ender: boolean;
601
- _live: boolean;
602
- invisible: boolean;
603
- long: number | undefined;
604
- };
605
-
606
- type MeasureTextInput = {
607
- content: CommentContentItem[];
608
- resized?: boolean;
609
- ender: boolean;
610
- size: CommentSize;
611
- fontSize: number;
612
- resizedY?: boolean;
613
- resizedX?: boolean;
614
- font: CommentFont;
615
- loc: CommentLoc;
616
- full: boolean;
617
- flash: boolean;
618
- lineCount: number;
619
- lineHeight?: number;
620
- charSize?: number;
621
- };
622
-
623
- type MeasureInput = {
624
- font: CommentFont;
625
- content: CommentContentItem[];
626
- lineHeight: number;
627
- charSize: number;
628
- lineCount: number;
629
- };
630
-
444
+ type FormattedCommentWithFont = {
445
+ id: number;
446
+ vpos: number;
447
+ date: number;
448
+ date_usec: number;
449
+ owner: boolean;
450
+ premium: boolean;
451
+ mail: string[];
452
+ user_id: number;
453
+ layer: number;
454
+ loc: CommentLoc;
455
+ size: CommentSize;
456
+ fontSize: number;
457
+ font: CommentFont;
458
+ color: string;
459
+ strokeColor?: string;
460
+ wakuColor?: string;
461
+ fillColor?: string;
462
+ full: boolean;
463
+ ender: boolean;
464
+ _live: boolean;
465
+ long: number;
466
+ invisible: boolean;
467
+ content: CommentContentItem[];
468
+ rawContent: string;
469
+ flash: boolean;
470
+ lineCount: number;
471
+ lineOffset: number;
472
+ };
473
+ type FormattedCommentWithSize = FormattedCommentWithFont & {
474
+ height: number;
475
+ width: number;
476
+ lineHeight: number;
477
+ resized: boolean;
478
+ resizedX: boolean;
479
+ resizedY: boolean;
480
+ content: CommentMeasuredContentItem[];
481
+ charSize: number;
482
+ };
483
+ type ParseContentResult = {
484
+ content: CommentContentItem[];
485
+ lineCount: number;
486
+ lineOffset: number;
487
+ };
488
+ type ParseCommandAndNicoScriptResult = {
489
+ flash: boolean;
490
+ loc: CommentLoc;
491
+ size: CommentSize;
492
+ fontSize: number;
493
+ color: string;
494
+ strokeColor?: string;
495
+ wakuColor?: string;
496
+ fillColor?: string;
497
+ font: CommentFont;
498
+ full: boolean;
499
+ ender: boolean;
500
+ _live: boolean;
501
+ invisible: boolean;
502
+ long: number;
503
+ };
504
+ type CommentContentItem = {
505
+ content: string;
506
+ slicedContent: string[];
507
+ font?: CommentFlashFont;
508
+ width?: number[];
509
+ };
510
+ type CommentMeasuredContentItem = CommentContentItem & {
511
+ width: number[];
512
+ };
513
+ type CommentContentIndex = {
514
+ index: number;
515
+ font: "gothic" | "gulim" | "simsunStrong" | "simsunWeak";
516
+ };
517
+ type CommentFont = "defont" | "mincho" | "gothic" | "gulim" | "simsun";
518
+ type CommentFlashFont = "defont" | "gulim" | "simsun";
519
+ type CommentSize = "big" | "medium" | "small";
520
+ type CommentLoc = "ue" | "naka" | "shita";
521
+ type Collision = { [key in CollisionPos]: CollisionItem };
522
+ type Timeline = { [key: number]: IComment[] };
523
+ type CollisionPos = "ue" | "shita" | "right" | "left";
524
+ type CollisionItem = { [p: number]: IComment[] };
525
+ type NicoScript = {
526
+ reverse: NicoScriptReverse[];
527
+ ban: NicoScriptBan[];
528
+ default: NicoScriptDefault[];
529
+ replace: NicoScriptReplace[];
530
+ seekDisable: NicoScriptSeekDisable[];
531
+ jump: NicoScriptJump[];
532
+ };
533
+ type NicoScriptSeekDisable = {
534
+ start: number;
535
+ end: number;
536
+ };
537
+ type NicoScriptJump = {
538
+ start: number;
539
+ end?: number;
540
+ to: string;
541
+ message?: string;
542
+ };
543
+ type NicoScriptReverse = {
544
+ target: NicoScriptReverseTarget;
545
+ start: number;
546
+ end: number;
547
+ };
548
+ type NicoScriptReverseTarget = "コメ" | "投コメ" | "全";
549
+ type NicoScriptReplace = {
550
+ start: number;
551
+ long: number | undefined;
552
+ keyword: string;
553
+ replace: string;
554
+ range: NicoScriptReplaceRange;
555
+ target: NicoScriptReplaceTarget;
556
+ condition: NicoScriptReplaceCondition;
557
+ color: string | undefined;
558
+ size: CommentSize | undefined;
559
+ font: CommentFont | undefined;
560
+ loc: CommentLoc | undefined;
561
+ no: number;
562
+ };
563
+ type NicoScriptReplaceRange = "単" | "";
564
+ type NicoScriptReplaceTarget =
565
+ | "コメ"
566
+ | "投コメ"
567
+ | ""
568
+ | "含まない"
569
+ | "含む";
570
+ type NicoScriptReplaceCondition = "完全一致" | "部分一致";
571
+ type NicoScriptBan = {
572
+ start: number;
573
+ end: number;
574
+ };
575
+ type NicoScriptDefault = {
576
+ start: number;
577
+ long: number | undefined;
578
+ color: string | undefined;
579
+ size: CommentSize | undefined;
580
+ font: CommentFont | undefined;
581
+ loc: CommentLoc | undefined;
582
+ };
583
+ type MeasureTextResult = {
584
+ width: number;
585
+ height: number;
586
+ resized: boolean;
587
+ resizedX: boolean;
588
+ resizedY: boolean;
589
+ fontSize: number;
590
+ lineHeight: number;
591
+ content: CommentMeasuredContentItem[];
592
+ charSize: number;
593
+ };
594
+ type ParsedCommand = {
595
+ loc: CommentLoc | undefined;
596
+ size: CommentSize | undefined;
597
+ fontSize: number | undefined;
598
+ color: string | undefined;
599
+ strokeColor?: string;
600
+ wakuColor?: string;
601
+ fillColor?: string;
602
+ font: CommentFont | undefined;
603
+ full: boolean;
604
+ ender: boolean;
605
+ _live: boolean;
606
+ invisible: boolean;
607
+ long: number | undefined;
608
+ };
609
+
610
+ type MeasureTextInput = {
611
+ content: CommentContentItem[];
612
+ resized?: boolean;
613
+ ender: boolean;
614
+ size: CommentSize;
615
+ fontSize: number;
616
+ resizedY?: boolean;
617
+ resizedX?: boolean;
618
+ font: CommentFont;
619
+ loc: CommentLoc;
620
+ full: boolean;
621
+ flash: boolean;
622
+ lineCount: number;
623
+ lineHeight?: number;
624
+ charSize?: number;
625
+ };
626
+
627
+ type MeasureInput = {
628
+ font: CommentFont;
629
+ content: CommentContentItem[];
630
+ lineHeight: number;
631
+ charSize: number;
632
+ lineCount: number;
633
+ };
634
+
631
635
  type ValueOf<T> = T[keyof T];
632
636
 
633
637
  declare let imageCache: {
package/dist/bundle.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- niconicomments.js v0.2.53
2
+ niconicomments.js v0.2.55
3
3
  (c) 2021 xpadev-net https://xpadev.net
4
4
  Released under the MIT License.
5
5
  */
@@ -187,12 +187,13 @@
187
187
  };
188
188
  const getStrokeColor = (comment) => {
189
189
  if (comment.strokeColor) {
190
- const length = comment.strokeColor.length;
190
+ const color = comment.strokeColor.slice(1);
191
+ const length = color.length;
191
192
  if (length === 3 || length === 6) {
192
- return `rgba(${hex2rgb(comment.strokeColor).join(",")},${config.contextStrokeOpacity})`;
193
+ return `rgba(${hex2rgb(color).join(",")},${config.contextStrokeOpacity})`;
193
194
  }
194
195
  else if (length === 4 || length === 8) {
195
- return `rgba(${hex2rgba(comment.strokeColor).join(",")})`;
196
+ return `rgba(${hex2rgba(color).join(",")})`;
196
197
  }
197
198
  }
198
199
  return `rgba(${hex2rgb(comment.color === "#000000"
@@ -549,6 +550,7 @@
549
550
  invisible: commands.invisible,
550
551
  strokeColor: commands.strokeColor,
551
552
  wakuColor: commands.wakuColor,
553
+ fillColor: commands.fillColor,
552
554
  };
553
555
  };
554
556
  const parseBrackets = (input) => {
@@ -743,6 +745,11 @@
743
745
  result.wakuColor ??= rectColor;
744
746
  return;
745
747
  }
748
+ const fillColor = getColor(command.match(/^nico:fill:(.+)$/));
749
+ if (fillColor) {
750
+ result.fillColor ??= fillColor;
751
+ return;
752
+ }
746
753
  if (typeGuard.comment.loc(command)) {
747
754
  result.loc ??= command;
748
755
  return;
@@ -777,7 +784,7 @@
777
784
  return colors[value];
778
785
  }
779
786
  else if (typeGuard.comment.colorCodeAllowAlpha(value)) {
780
- return value.slice(1);
787
+ return value;
781
788
  }
782
789
  return;
783
790
  };
@@ -1381,6 +1388,7 @@
1381
1388
  const posY = this.comment.loc === "shita"
1382
1389
  ? config.canvasHeight - this.posY - this.comment.height
1383
1390
  : this.posY;
1391
+ this._drawBackgroundColor(posX, posY);
1384
1392
  this._draw(posX, posY);
1385
1393
  this._drawRectColor(posX, posY);
1386
1394
  this._drawCollision(posX, posY, showCollision);
@@ -1410,6 +1418,14 @@
1410
1418
  this.context.restore();
1411
1419
  }
1412
1420
  }
1421
+ _drawBackgroundColor(posX, posY) {
1422
+ if (this.comment.fillColor) {
1423
+ this.context.save();
1424
+ this.context.fillStyle = this.comment.fillColor;
1425
+ this.context.fillRect(posX, posY, this.comment.width, this.comment.height);
1426
+ this.context.restore();
1427
+ }
1428
+ }
1413
1429
  _drawDebugInfo(posX, posY, debug) {
1414
1430
  if (debug) {
1415
1431
  this.context.save();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xpadev-net/niconicomments",
3
- "version": "0.2.53",
3
+ "version": "0.2.55",
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",