@xpadev-net/niconicomments 0.2.68 → 0.2.70

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
@@ -961,41 +961,6 @@ export type DefaultCommand = {
961
961
  font?: CommentFont;
962
962
  loc?: CommentLoc;
963
963
  };
964
- export interface IRenderer {
965
- readonly canvas: HTMLCanvasElement;
966
- readonly video?: HTMLVideoElement;
967
- destroy(): void;
968
- drawVideo(enableLegacyPip: boolean): void;
969
- getFont(): string;
970
- getFillStyle(): string | CanvasGradient | CanvasPattern;
971
- setScale(scale: number, arg1?: number): void;
972
- fillRect(x: number, y: number, width: number, height: number): void;
973
- strokeRect(x: number, y: number, width: number, height: number): void;
974
- fillText(text: string, x: number, y: number): void;
975
- strokeText(text: string, x: number, y: number): void;
976
- quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;
977
- clearRect(x: number, y: number, width: number, height: number): void;
978
- setFont(font: string): void;
979
- setFillStyle(color: string): void;
980
- setStrokeStyle(color: string): void;
981
- setLineWidth(width: number): void;
982
- setGlobalAlpha(alpha: number): void;
983
- setSize(width: number, height: number): void;
984
- getSize(): {
985
- width: number;
986
- height: number;
987
- };
988
- measureText(text: string): TextMetrics;
989
- beginPath(): void;
990
- closePath(): void;
991
- moveTo(x: number, y: number): void;
992
- lineTo(x: number, y: number): void;
993
- stroke(): void;
994
- save(): void;
995
- restore(): void;
996
- getCanvas(): IRenderer;
997
- drawImage(image: IRenderer, x: number, y: number, width?: number, height?: number): void;
998
- }
999
964
  declare class BaseComment implements IComment {
1000
965
  protected readonly renderer: IRenderer;
1001
966
  protected cacheKey: string;
@@ -1008,7 +973,8 @@ declare class BaseComment implements IComment {
1008
973
  readonly pluginName: string;
1009
974
  image?: IRenderer | null;
1010
975
  buttonImage?: IRenderer | null;
1011
- constructor(comment: FormattedComment, renderer: IRenderer);
976
+ index: number;
977
+ constructor(comment: FormattedComment, renderer: IRenderer, index: number);
1012
978
  get invisible(): boolean;
1013
979
  get loc(): "ue" | "naka" | "shita";
1014
980
  get long(): number;
@@ -1043,7 +1009,7 @@ declare class FlashComment extends BaseComment {
1043
1009
  private _globalScale;
1044
1010
  readonly pluginName: string;
1045
1011
  buttonImage: IRenderer;
1046
- constructor(comment: FormattedComment, renderer: IRenderer);
1012
+ constructor(comment: FormattedComment, renderer: IRenderer, index: number);
1047
1013
  get content(): string;
1048
1014
  set content(input: string);
1049
1015
  convertComment(comment: FormattedComment): FormattedCommentWithSize;
@@ -1081,7 +1047,7 @@ declare class FlashComment extends BaseComment {
1081
1047
  }
1082
1048
  declare class HTML5Comment extends BaseComment {
1083
1049
  readonly pluginName: string;
1084
- constructor(comment: FormattedComment, context: IRenderer);
1050
+ constructor(comment: FormattedComment, context: IRenderer, index: number);
1085
1051
  get content(): string;
1086
1052
  set content(input: string);
1087
1053
  convertComment(comment: FormattedComment): FormattedCommentWithSize;
@@ -1575,42 +1541,105 @@ export declare const ZV1Thread: ObjectSchema<{
1575
1541
  }>;
1576
1542
  export type V1Thread = Output<typeof ZV1Thread>;
1577
1543
  export type v1Thread = V1Thread;
1578
- export interface IComment {
1579
- comment: FormattedCommentWithSize;
1580
- invisible: boolean;
1581
- loc: CommentLoc;
1582
- width: number;
1583
- long: number;
1584
- height: number;
1585
- vpos: number;
1586
- flash: boolean;
1587
- posY: number;
1588
- owner: boolean;
1589
- layer: number;
1590
- mail: string[];
1591
- content: string;
1592
- image?: IRenderer | null;
1593
- draw: (vpos: number, showCollision: boolean, cursor?: Position) => void;
1594
- isHovered: (cursor?: Position, posX?: number, posY?: number) => boolean;
1595
- }
1596
- export interface InputParser {
1597
- key: string[];
1598
- parse: (input: unknown) => FormattedComment[];
1599
- }
1600
- export interface IPluginConstructor {
1601
- id: string;
1602
- new (Canvas: IRenderer, comments: IComment[]): IPlugin;
1603
- }
1604
- export interface IPlugin {
1605
- draw?: (vpos: number) => void;
1606
- addComments?: (comments: IComment[]) => void;
1607
- transformComments?: (comments: IComment[]) => IComment[];
1608
- }
1609
- export type IPluginList = {
1610
- instance: IPlugin;
1611
- canvas: IRenderer;
1612
- }[];
1613
- declare const ZXml2jsPacket: ObjectSchema<{
1544
+ export declare const ZXml2jsChatItem: ObjectSchema<{
1545
+ _: StringSchema<string>;
1546
+ $: ObjectSchema<{
1547
+ no: OptionalSchema<StringSchema<string>, undefined, string | undefined>;
1548
+ vpos: StringSchema<string>;
1549
+ date: OptionalSchema<StringSchema<string>, "0", string>;
1550
+ date_usec: OptionalSchema<StringSchema<string>, "0", string>;
1551
+ user_id: OptionalSchema<StringSchema<string>, undefined, string | undefined>;
1552
+ owner: OptionalSchema<StringSchema<string>, "", string>;
1553
+ premium: OptionalSchema<StringSchema<string>, "", string>;
1554
+ mail: OptionalSchema<StringSchema<string>, "", string>;
1555
+ }, undefined, {
1556
+ owner: string;
1557
+ vpos: string;
1558
+ date: string;
1559
+ date_usec: string;
1560
+ premium: string;
1561
+ mail: string;
1562
+ user_id?: string | undefined;
1563
+ no?: string | undefined;
1564
+ }>;
1565
+ }, undefined, {
1566
+ _: string;
1567
+ $: {
1568
+ owner: string;
1569
+ vpos: string;
1570
+ date: string;
1571
+ date_usec: string;
1572
+ premium: string;
1573
+ mail: string;
1574
+ user_id?: string | undefined;
1575
+ no?: string | undefined;
1576
+ };
1577
+ }>;
1578
+ export type Xml2jsChatItem = Output<typeof ZXml2jsChatItem>;
1579
+ export declare const ZXml2jsChat: ObjectSchema<{
1580
+ chat: ArraySchema<ObjectSchema<{
1581
+ _: StringSchema<string>;
1582
+ $: ObjectSchema<{
1583
+ no: OptionalSchema<StringSchema<string>, undefined, string | undefined>;
1584
+ vpos: StringSchema<string>;
1585
+ date: OptionalSchema<StringSchema<string>, "0", string>;
1586
+ date_usec: OptionalSchema<StringSchema<string>, "0", string>;
1587
+ user_id: OptionalSchema<StringSchema<string>, undefined, string | undefined>;
1588
+ owner: OptionalSchema<StringSchema<string>, "", string>;
1589
+ premium: OptionalSchema<StringSchema<string>, "", string>;
1590
+ mail: OptionalSchema<StringSchema<string>, "", string>;
1591
+ }, undefined, {
1592
+ owner: string;
1593
+ vpos: string;
1594
+ date: string;
1595
+ date_usec: string;
1596
+ premium: string;
1597
+ mail: string;
1598
+ user_id?: string | undefined;
1599
+ no?: string | undefined;
1600
+ }>;
1601
+ }, undefined, {
1602
+ _: string;
1603
+ $: {
1604
+ owner: string;
1605
+ vpos: string;
1606
+ date: string;
1607
+ date_usec: string;
1608
+ premium: string;
1609
+ mail: string;
1610
+ user_id?: string | undefined;
1611
+ no?: string | undefined;
1612
+ };
1613
+ }>, {
1614
+ _: string;
1615
+ $: {
1616
+ owner: string;
1617
+ vpos: string;
1618
+ date: string;
1619
+ date_usec: string;
1620
+ premium: string;
1621
+ mail: string;
1622
+ user_id?: string | undefined;
1623
+ no?: string | undefined;
1624
+ };
1625
+ }[]>;
1626
+ }, undefined, {
1627
+ chat: {
1628
+ _: string;
1629
+ $: {
1630
+ owner: string;
1631
+ vpos: string;
1632
+ date: string;
1633
+ date_usec: string;
1634
+ premium: string;
1635
+ mail: string;
1636
+ user_id?: string | undefined;
1637
+ no?: string | undefined;
1638
+ };
1639
+ }[];
1640
+ }>;
1641
+ export type Xml2jsChat = Output<typeof ZXml2jsChat>;
1642
+ export declare const ZXml2jsPacket: ObjectSchema<{
1614
1643
  packet: ObjectSchema<{
1615
1644
  chat: ArraySchema<ObjectSchema<{
1616
1645
  _: StringSchema<string>;
@@ -1691,6 +1720,42 @@ declare const ZXml2jsPacket: ObjectSchema<{
1691
1720
  };
1692
1721
  }>;
1693
1722
  export type Xml2jsPacket = Output<typeof ZXml2jsPacket>;
1723
+ export interface IComment {
1724
+ comment: FormattedCommentWithSize;
1725
+ invisible: boolean;
1726
+ index: number;
1727
+ loc: CommentLoc;
1728
+ width: number;
1729
+ long: number;
1730
+ height: number;
1731
+ vpos: number;
1732
+ flash: boolean;
1733
+ posY: number;
1734
+ owner: boolean;
1735
+ layer: number;
1736
+ mail: string[];
1737
+ content: string;
1738
+ image?: IRenderer | null;
1739
+ draw: (vpos: number, showCollision: boolean, cursor?: Position) => void;
1740
+ isHovered: (cursor?: Position, posX?: number, posY?: number) => boolean;
1741
+ }
1742
+ export interface InputParser {
1743
+ key: string[];
1744
+ parse: (input: unknown) => FormattedComment[];
1745
+ }
1746
+ export interface IPluginConstructor {
1747
+ id: string;
1748
+ new (Canvas: IRenderer, comments: IComment[]): IPlugin;
1749
+ }
1750
+ export interface IPlugin {
1751
+ draw?: (vpos: number) => void;
1752
+ addComments?: (comments: IComment[]) => void;
1753
+ transformComments?: (comments: IComment[]) => IComment[];
1754
+ }
1755
+ export type IPluginList = {
1756
+ instance: IPlugin;
1757
+ canvas: IRenderer;
1758
+ }[];
1694
1759
  export declare const ZInputFormatType: UnionSchema<(LiteralSchema<"XMLDocument", "XMLDocument"> | LiteralSchema<"niconicome", "niconicome"> | LiteralSchema<"xml2js", "xml2js"> | LiteralSchema<"formatted", "formatted"> | LiteralSchema<"legacy", "legacy"> | LiteralSchema<"legacyOwner", "legacyOwner"> | LiteralSchema<"owner", "owner"> | LiteralSchema<"v1", "v1"> | LiteralSchema<"empty", "empty"> | LiteralSchema<"default", "default">)[], "default" | "XMLDocument" | "niconicome" | "xml2js" | "formatted" | "legacy" | "legacyOwner" | "owner" | "v1" | "empty">;
1695
1760
  export type InputFormatType = Output<typeof ZInputFormatType>;
1696
1761
  export type InputFormat = XMLDocument | Xml2jsPacket | FormattedComment[] | FormattedLegacyComment[] | RawApiResponse[] | OwnerComment[] | V1Thread[] | string | undefined;
@@ -1709,10 +1774,46 @@ export type BaseOptions = {
1709
1774
  showFPS: boolean;
1710
1775
  useLegacy: boolean;
1711
1776
  video: HTMLVideoElement | undefined;
1777
+ lazy: boolean;
1712
1778
  };
1713
1779
  export type Options = Partial<BaseOptions>;
1714
1780
  export type inputFormatType = InputFormatType;
1715
1781
  export type inputFormat = InputFormat;
1782
+ export interface IRenderer {
1783
+ readonly canvas: HTMLCanvasElement;
1784
+ readonly video?: HTMLVideoElement;
1785
+ destroy(): void;
1786
+ drawVideo(enableLegacyPip: boolean): void;
1787
+ getFont(): string;
1788
+ getFillStyle(): string | CanvasGradient | CanvasPattern;
1789
+ setScale(scale: number, arg1?: number): void;
1790
+ fillRect(x: number, y: number, width: number, height: number): void;
1791
+ strokeRect(x: number, y: number, width: number, height: number): void;
1792
+ fillText(text: string, x: number, y: number): void;
1793
+ strokeText(text: string, x: number, y: number): void;
1794
+ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;
1795
+ clearRect(x: number, y: number, width: number, height: number): void;
1796
+ setFont(font: string): void;
1797
+ setFillStyle(color: string): void;
1798
+ setStrokeStyle(color: string): void;
1799
+ setLineWidth(width: number): void;
1800
+ setGlobalAlpha(alpha: number): void;
1801
+ setSize(width: number, height: number): void;
1802
+ getSize(): {
1803
+ width: number;
1804
+ height: number;
1805
+ };
1806
+ measureText(text: string): TextMetrics;
1807
+ beginPath(): void;
1808
+ closePath(): void;
1809
+ moveTo(x: number, y: number): void;
1810
+ lineTo(x: number, y: number): void;
1811
+ stroke(): void;
1812
+ save(): void;
1813
+ restore(): void;
1814
+ getCanvas(): IRenderer;
1815
+ drawImage(image: IRenderer, x: number, y: number, width?: number, height?: number): void;
1816
+ }
1716
1817
  export type FormattedCommentWithFont = {
1717
1818
  id: number;
1718
1819
  vpos: number;
@@ -2615,6 +2716,53 @@ declare const typeGuard: {
2615
2716
  };
2616
2717
  };
2617
2718
  xmlDocument: (i: unknown) => i is XMLDocument;
2719
+ xml2js: {
2720
+ packet: (i: unknown) => i is {
2721
+ packet: {
2722
+ chat: {
2723
+ _: string;
2724
+ $: {
2725
+ owner: string;
2726
+ vpos: string;
2727
+ date: string;
2728
+ date_usec: string;
2729
+ premium: string;
2730
+ mail: string;
2731
+ user_id?: string | undefined;
2732
+ no?: string | undefined;
2733
+ };
2734
+ }[];
2735
+ };
2736
+ };
2737
+ chat: (i: unknown) => i is {
2738
+ chat: {
2739
+ _: string;
2740
+ $: {
2741
+ owner: string;
2742
+ vpos: string;
2743
+ date: string;
2744
+ date_usec: string;
2745
+ premium: string;
2746
+ mail: string;
2747
+ user_id?: string | undefined;
2748
+ no?: string | undefined;
2749
+ };
2750
+ }[];
2751
+ };
2752
+ chatItem: (i: unknown) => i is {
2753
+ _: string;
2754
+ $: {
2755
+ owner: string;
2756
+ vpos: string;
2757
+ date: string;
2758
+ date_usec: string;
2759
+ premium: string;
2760
+ mail: string;
2761
+ user_id?: string | undefined;
2762
+ no?: string | undefined;
2763
+ };
2764
+ };
2765
+ };
2618
2766
  legacyOwner: {
2619
2767
  comments: (i: unknown) => i is string;
2620
2768
  };
@@ -2816,8 +2964,10 @@ declare const parseCommandAndNicoScript: (comment: FormattedComment) => ParseCom
2816
2964
  declare const isFlashComment: (comment: FormattedComment) => boolean;
2817
2965
  declare const isReverseActive: (vpos: number, isOwner: boolean) => boolean;
2818
2966
  declare const isBanActive: (vpos: number) => boolean;
2819
- declare const processFixedComment: (comment: IComment, collision: CollisionItem, timeline: Timeline) => void;
2820
- declare const processMovableComment: (comment: IComment, collision: Collision, timeline: Timeline) => void;
2967
+ declare const processFixedComment: (comment: IComment, collision: CollisionItem, timeline: Timeline, lazy?: boolean) => void;
2968
+ declare const processMovableComment: (comment: IComment, collision: Collision, timeline: Timeline, lazy?: boolean) => void;
2969
+ declare const getFixedPosY: (comment: IComment, collision: CollisionItem) => number;
2970
+ declare const getMovablePosY: (comment: IComment, collision: Collision, beforeVpos: number) => number;
2821
2971
  declare const getPosY: (currentPos: number, targetComment: IComment, collision: IComment[] | undefined, isChanged?: boolean) => {
2822
2972
  currentPos: number;
2823
2973
  isChanged: boolean;
@@ -2869,10 +3019,12 @@ declare const index_d_getButtonParts: typeof getButtonParts;
2869
3019
  declare const index_d_getCharSize: typeof getCharSize;
2870
3020
  declare const index_d_getConfig: typeof getConfig;
2871
3021
  declare const index_d_getDefaultCommand: typeof getDefaultCommand;
3022
+ declare const index_d_getFixedPosY: typeof getFixedPosY;
2872
3023
  declare const index_d_getFlashFontIndex: typeof getFlashFontIndex;
2873
3024
  declare const index_d_getFlashFontName: typeof getFlashFontName;
2874
3025
  declare const index_d_getFontSizeAndScale: typeof getFontSizeAndScale;
2875
3026
  declare const index_d_getLineHeight: typeof getLineHeight;
3027
+ declare const index_d_getMovablePosY: typeof getMovablePosY;
2876
3028
  declare const index_d_getPosX: typeof getPosX;
2877
3029
  declare const index_d_getPosY: typeof getPosY;
2878
3030
  declare const index_d_getStrokeColor: typeof getStrokeColor;
@@ -2890,7 +3042,7 @@ declare const index_d_parseFont: typeof parseFont;
2890
3042
  declare const index_d_processFixedComment: typeof processFixedComment;
2891
3043
  declare const index_d_processMovableComment: typeof processMovableComment;
2892
3044
  declare namespace index_d {
2893
- export { index_d_addHTML5PartToResult as index_d_addHTML5PartToResult, index_d_arrayEqual as index_d_arrayEqual, index_d_arrayPush as index_d_arrayPush, index_d_buildAtButtonComment as index_d_buildAtButtonComment, index_d_changeCALayer as index_d_changeCALayer, index_d_getButtonParts as index_d_getButtonParts, index_d_getCharSize as index_d_getCharSize, index_d_getConfig as index_d_getConfig, index_d_getDefaultCommand as index_d_getDefaultCommand, index_d_getFlashFontIndex as index_d_getFlashFontIndex, index_d_getFlashFontName as index_d_getFlashFontName, index_d_getFontSizeAndScale as index_d_getFontSizeAndScale, index_d_getLineHeight as index_d_getLineHeight, index_d_getPosX as index_d_getPosX, index_d_getPosY as index_d_getPosY, index_d_getStrokeColor as index_d_getStrokeColor, index_d_hex2rgb as index_d_hex2rgb, index_d_hex2rgba as index_d_hex2rgba, index_d_isBanActive as index_d_isBanActive, index_d_isFlashComment as index_d_isFlashComment, index_d_isLineBreakResize as index_d_isLineBreakResize, index_d_isReverseActive as index_d_isReverseActive, index_d_measure as index_d_measure, index_d_nativeSort as index_d_nativeSort, index_d_parseCommandAndNicoScript as index_d_parseCommandAndNicoScript, index_d_parseContent as index_d_parseContent, index_d_parseFont as index_d_parseFont, index_d_processFixedComment as index_d_processFixedComment, index_d_processMovableComment as index_d_processMovableComment };
3045
+ export { index_d_addHTML5PartToResult as index_d_addHTML5PartToResult, index_d_arrayEqual as index_d_arrayEqual, index_d_arrayPush as index_d_arrayPush, index_d_buildAtButtonComment as index_d_buildAtButtonComment, index_d_changeCALayer as index_d_changeCALayer, index_d_getButtonParts as index_d_getButtonParts, index_d_getCharSize as index_d_getCharSize, index_d_getConfig as index_d_getConfig, index_d_getDefaultCommand as index_d_getDefaultCommand, index_d_getFixedPosY as index_d_getFixedPosY, index_d_getFlashFontIndex as index_d_getFlashFontIndex, index_d_getFlashFontName as index_d_getFlashFontName, index_d_getFontSizeAndScale as index_d_getFontSizeAndScale, index_d_getLineHeight as index_d_getLineHeight, index_d_getMovablePosY as index_d_getMovablePosY, index_d_getPosX as index_d_getPosX, index_d_getPosY as index_d_getPosY, index_d_getStrokeColor as index_d_getStrokeColor, index_d_hex2rgb as index_d_hex2rgb, index_d_hex2rgba as index_d_hex2rgba, index_d_isBanActive as index_d_isBanActive, index_d_isFlashComment as index_d_isFlashComment, index_d_isLineBreakResize as index_d_isLineBreakResize, index_d_isReverseActive as index_d_isReverseActive, index_d_measure as index_d_measure, index_d_nativeSort as index_d_nativeSort, index_d_parseCommandAndNicoScript as index_d_parseCommandAndNicoScript, index_d_parseContent as index_d_parseContent, index_d_parseFont as index_d_parseFont, index_d_processFixedComment as index_d_processFixedComment, index_d_processMovableComment as index_d_processMovableComment };
2894
3046
  }
2895
3047
  declare const definition: {
2896
3048
  colors: typeof colors$1;
@@ -2908,6 +3060,8 @@ declare class NiconiComments {
2908
3060
  showFPS: boolean;
2909
3061
  showCommentCount: boolean;
2910
3062
  private lastVpos;
3063
+ private processedCommentIndex;
3064
+ private comments;
2911
3065
  private readonly renderer;
2912
3066
  private readonly collision;
2913
3067
  private readonly timeline;
@@ -3013,6 +3167,53 @@ declare class NiconiComments {
3013
3167
  };
3014
3168
  };
3015
3169
  xmlDocument: (i: unknown) => i is XMLDocument;
3170
+ xml2js: {
3171
+ packet: (i: unknown) => i is {
3172
+ packet: {
3173
+ chat: {
3174
+ _: string;
3175
+ $: {
3176
+ owner: string;
3177
+ vpos: string;
3178
+ date: string;
3179
+ date_usec: string;
3180
+ premium: string;
3181
+ mail: string;
3182
+ user_id?: string | undefined;
3183
+ no?: string | undefined;
3184
+ };
3185
+ }[];
3186
+ };
3187
+ };
3188
+ chat: (i: unknown) => i is {
3189
+ chat: {
3190
+ _: string;
3191
+ $: {
3192
+ owner: string;
3193
+ vpos: string;
3194
+ date: string;
3195
+ date_usec: string;
3196
+ premium: string;
3197
+ mail: string;
3198
+ user_id?: string | undefined;
3199
+ no?: string | undefined;
3200
+ };
3201
+ }[];
3202
+ };
3203
+ chatItem: (i: unknown) => i is {
3204
+ _: string;
3205
+ $: {
3206
+ owner: string;
3207
+ vpos: string;
3208
+ date: string;
3209
+ date_usec: string;
3210
+ premium: string;
3211
+ mail: string;
3212
+ user_id?: string | undefined;
3213
+ no?: string | undefined;
3214
+ };
3215
+ };
3216
+ };
3016
3217
  legacyOwner: {
3017
3218
  comments: (i: unknown) => i is string;
3018
3219
  };
@@ -3219,7 +3420,7 @@ declare class NiconiComments {
3219
3420
  constructor(renderer: IRenderer | HTMLCanvasElement, data: InputFormat, initOptions?: Options);
3220
3421
  private preRendering;
3221
3422
  private getCommentPos;
3222
- private sortComment;
3423
+ private sortTimelineComment;
3223
3424
  addComments(...rawComments: FormattedComment[]): void;
3224
3425
  drawCanvas(vpos: number, forceRendering?: boolean, cursor?: Position): boolean;
3225
3426
  private _drawVideo;
package/dist/bundle.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- niconicomments.js v0.2.68
2
+ niconicomments.js v0.2.70
3
3
  (c) 2021 xpadev-net https://xpadev.net
4
4
  Released under the MIT License.
5
5
  */
@@ -71,6 +71,7 @@
71
71
  showFPS: false,
72
72
  useLegacy: false,
73
73
  video: undefined,
74
+ lazy: false,
74
75
  };
75
76
  let config;
76
77
  let options;
@@ -1509,6 +1510,26 @@
1509
1510
  comments: array(ZV1Comment),
1510
1511
  });
1511
1512
 
1513
+ const ZXml2jsChatItem = object({
1514
+ _: string(),
1515
+ $: object({
1516
+ no: optional(string()),
1517
+ vpos: string(),
1518
+ date: optional(string(), "0"),
1519
+ date_usec: optional(string(), "0"),
1520
+ user_id: optional(string()),
1521
+ owner: optional(string(), ""),
1522
+ premium: optional(string(), ""),
1523
+ mail: optional(string(), ""),
1524
+ }),
1525
+ });
1526
+ const ZXml2jsChat = object({
1527
+ chat: array(ZXml2jsChatItem),
1528
+ });
1529
+ const ZXml2jsPacket = object({
1530
+ packet: ZXml2jsChat,
1531
+ });
1532
+
1512
1533
  const ZInputFormatType = union([
1513
1534
  literal("XMLDocument"),
1514
1535
  literal("niconicome"),
@@ -1674,6 +1695,11 @@
1674
1695
  }
1675
1696
  return true;
1676
1697
  },
1698
+ xml2js: {
1699
+ packet: (i) => is(ZXml2jsPacket, i),
1700
+ chat: (i) => is(ZXml2jsChat, i),
1701
+ chatItem: (i) => is(ZXml2jsChatItem, i),
1702
+ },
1677
1703
  legacyOwner: {
1678
1704
  comments: (i) => is(string([
1679
1705
  custom((i) => {
@@ -2157,19 +2183,8 @@
2157
2183
  }
2158
2184
  return false;
2159
2185
  };
2160
- const processFixedComment = (comment, collision, timeline) => {
2161
- let posY = 0, isChanged = true, count = 0;
2162
- while (isChanged && count < 10) {
2163
- isChanged = false;
2164
- count++;
2165
- for (let j = 0; j < comment.long; j++) {
2166
- const result = getPosY(posY, comment, collision[comment.vpos + j]);
2167
- posY = result.currentPos;
2168
- isChanged = result.isChanged;
2169
- if (result.isBreak)
2170
- break;
2171
- }
2172
- }
2186
+ const processFixedComment = (comment, collision, timeline, lazy = false) => {
2187
+ const posY = lazy ? -1 : getFixedPosY(comment, collision);
2173
2188
  for (let j = 0; j < comment.long; j++) {
2174
2189
  const vpos = comment.vpos + j;
2175
2190
  arrayPush(timeline, vpos, comment);
@@ -2179,43 +2194,14 @@
2179
2194
  }
2180
2195
  comment.posY = posY;
2181
2196
  };
2182
- const processMovableComment = (comment, collision, timeline) => {
2197
+ const processMovableComment = (comment, collision, timeline, lazy = false) => {
2183
2198
  const beforeVpos = Math.round(-288 / ((1632 + comment.width) / (comment.long + 125))) - 100;
2184
- const posY = (() => {
2185
- if (config.canvasHeight < comment.height) {
2186
- return (comment.height - config.canvasHeight) / -2;
2187
- }
2188
- let posY = 0;
2189
- let isChanged = true;
2190
- while (isChanged) {
2191
- isChanged = false;
2192
- for (let j = beforeVpos, n = comment.long + 125; j < n; j++) {
2193
- const vpos = comment.vpos + j;
2194
- const leftPos = getPosX(comment.comment, vpos);
2195
- let isBreak = false;
2196
- if (leftPos + comment.width >= config.collisionRange.right &&
2197
- leftPos <= config.collisionRange.right) {
2198
- const result = getPosY(posY, comment, collision.right[vpos]);
2199
- posY = result.currentPos;
2200
- isChanged ||= result.isChanged;
2201
- isBreak = result.isBreak;
2202
- }
2203
- if (leftPos + comment.width >= config.collisionRange.left &&
2204
- leftPos <= config.collisionRange.left) {
2205
- const result = getPosY(posY, comment, collision.left[vpos]);
2206
- posY = result.currentPos;
2207
- isChanged ||= result.isChanged;
2208
- isBreak = result.isBreak;
2209
- }
2210
- if (isBreak)
2211
- return posY;
2212
- }
2213
- }
2214
- return posY;
2215
- })();
2199
+ const posY = lazy ? -1 : getMovablePosY(comment, collision, beforeVpos);
2216
2200
  for (let j = beforeVpos, n = comment.long + 125; j < n; j++) {
2217
2201
  const vpos = comment.vpos + j;
2218
2202
  const leftPos = getPosX(comment.comment, vpos);
2203
+ if (timeline[vpos]?.includes(comment))
2204
+ break;
2219
2205
  arrayPush(timeline, vpos, comment);
2220
2206
  if (leftPos + comment.width + config.collisionPadding >=
2221
2207
  config.collisionRange.right &&
@@ -2230,15 +2216,72 @@
2230
2216
  }
2231
2217
  comment.posY = posY;
2232
2218
  };
2219
+ const getFixedPosY = (comment, collision) => {
2220
+ let posY = 0, isChanged = true, count = 0;
2221
+ while (isChanged && count < 10) {
2222
+ isChanged = false;
2223
+ count++;
2224
+ for (let j = 0; j < comment.long; j++) {
2225
+ const result = getPosY(posY, comment, collision[comment.vpos + j]);
2226
+ posY = result.currentPos;
2227
+ isChanged = result.isChanged;
2228
+ if (result.isBreak)
2229
+ break;
2230
+ }
2231
+ }
2232
+ return posY;
2233
+ };
2234
+ const getMovablePosY = (comment, collision, beforeVpos) => {
2235
+ if (config.canvasHeight < comment.height) {
2236
+ return (comment.height - config.canvasHeight) / -2;
2237
+ }
2238
+ let posY = 0;
2239
+ let isChanged = true;
2240
+ let lastUpdatedIndex = undefined;
2241
+ while (isChanged) {
2242
+ isChanged = false;
2243
+ for (let j = beforeVpos, n = comment.long + 125; j < n; j += 5) {
2244
+ const vpos = comment.vpos + j;
2245
+ const leftPos = getPosX(comment.comment, vpos);
2246
+ let isBreak = false;
2247
+ if (lastUpdatedIndex !== undefined && lastUpdatedIndex === vpos) {
2248
+ return posY;
2249
+ }
2250
+ if (leftPos + comment.width >= config.collisionRange.right &&
2251
+ leftPos <= config.collisionRange.right) {
2252
+ const result = getPosY(posY, comment, collision.right[vpos]);
2253
+ posY = result.currentPos;
2254
+ isChanged ||= result.isChanged;
2255
+ if (result.isChanged)
2256
+ lastUpdatedIndex = vpos;
2257
+ isBreak = result.isBreak;
2258
+ }
2259
+ if (leftPos + comment.width >= config.collisionRange.left &&
2260
+ leftPos <= config.collisionRange.left) {
2261
+ const result = getPosY(posY, comment, collision.left[vpos]);
2262
+ posY = result.currentPos;
2263
+ isChanged ||= result.isChanged;
2264
+ if (result.isChanged)
2265
+ lastUpdatedIndex = vpos;
2266
+ isBreak = result.isBreak;
2267
+ }
2268
+ if (isBreak)
2269
+ return posY;
2270
+ }
2271
+ }
2272
+ return posY;
2273
+ };
2233
2274
  const getPosY = (currentPos, targetComment, collision, isChanged = false) => {
2234
2275
  let isBreak = false;
2235
2276
  if (!collision)
2236
2277
  return { currentPos, isChanged, isBreak };
2237
2278
  for (const collisionItem of collision) {
2238
- if (currentPos < collisionItem.posY + collisionItem.height &&
2239
- currentPos + targetComment.height > collisionItem.posY &&
2240
- collisionItem.owner === targetComment.owner &&
2241
- collisionItem.layer === targetComment.layer) {
2279
+ if (collisionItem.index === targetComment.index || collisionItem.posY < 0)
2280
+ continue;
2281
+ if (collisionItem.owner === targetComment.owner &&
2282
+ collisionItem.layer === targetComment.layer &&
2283
+ currentPos < collisionItem.posY + collisionItem.height &&
2284
+ currentPos + targetComment.height > collisionItem.posY) {
2242
2285
  if (collisionItem.posY + collisionItem.height > currentPos) {
2243
2286
  currentPos = collisionItem.posY + collisionItem.height;
2244
2287
  isChanged = true;
@@ -2786,10 +2829,12 @@
2786
2829
  getCharSize: getCharSize,
2787
2830
  getConfig: getConfig,
2788
2831
  getDefaultCommand: getDefaultCommand,
2832
+ getFixedPosY: getFixedPosY,
2789
2833
  getFlashFontIndex: getFlashFontIndex,
2790
2834
  getFlashFontName: getFlashFontName,
2791
2835
  getFontSizeAndScale: getFontSizeAndScale,
2792
2836
  getLineHeight: getLineHeight,
2837
+ getMovablePosY: getMovablePosY,
2793
2838
  getPosX: getPosX,
2794
2839
  getPosY: getPosY,
2795
2840
  getStrokeColor: getStrokeColor,
@@ -2817,13 +2862,15 @@
2817
2862
  pluginName = "BaseComment";
2818
2863
  image;
2819
2864
  buttonImage;
2820
- constructor(comment, renderer) {
2865
+ index;
2866
+ constructor(comment, renderer, index) {
2821
2867
  this.renderer = renderer;
2822
- this.posY = 0;
2868
+ this.posY = -1;
2823
2869
  this.pos = { x: 0, y: 0 };
2824
2870
  comment.content = comment.content.replace(/\t/g, "\u2003\u2003");
2825
2871
  this.comment = this.convertComment(comment);
2826
2872
  this.cacheKey = this.getCacheKey();
2873
+ this.index = index;
2827
2874
  }
2828
2875
  get invisible() {
2829
2876
  return this.comment.invisible;
@@ -3041,8 +3088,8 @@
3041
3088
  _globalScale;
3042
3089
  pluginName = "FlashComment";
3043
3090
  buttonImage;
3044
- constructor(comment, renderer) {
3045
- super(comment, renderer);
3091
+ constructor(comment, renderer, index) {
3092
+ super(comment, renderer, index);
3046
3093
  this._globalScale ??= getConfig(config.commentScale, true);
3047
3094
  this.buttonImage = renderer.getCanvas();
3048
3095
  }
@@ -3426,9 +3473,9 @@
3426
3473
 
3427
3474
  class HTML5Comment extends BaseComment {
3428
3475
  pluginName = "HTML5Comment";
3429
- constructor(comment, context) {
3430
- super(comment, context);
3431
- this.posY = 0;
3476
+ constructor(comment, context, index) {
3477
+ super(comment, context, index);
3478
+ this.posY = -1;
3432
3479
  }
3433
3480
  get content() {
3434
3481
  return this.comment.rawContent;
@@ -4360,26 +4407,6 @@
4360
4407
  };
4361
4408
  const date2time = (date) => Math.floor(Date.parse(date) / 1000);
4362
4409
 
4363
- const ZXml2jsChatItem = object({
4364
- _: string(),
4365
- $: object({
4366
- no: optional(string()),
4367
- vpos: string(),
4368
- date: optional(string(), "0"),
4369
- date_usec: optional(string(), "0"),
4370
- user_id: optional(string()),
4371
- owner: optional(string(), ""),
4372
- premium: optional(string(), ""),
4373
- mail: optional(string(), ""),
4374
- }),
4375
- });
4376
- const ZXml2jsChat = object({
4377
- chat: array(ZXml2jsChatItem),
4378
- });
4379
- const ZXml2jsPacket = object({
4380
- packet: ZXml2jsChat,
4381
- });
4382
-
4383
4410
  const Xml2jsParser = {
4384
4411
  key: ["xml2js"],
4385
4412
  parse: (input) => {
@@ -4627,13 +4654,13 @@
4627
4654
  CanvasRenderer: CanvasRenderer
4628
4655
  });
4629
4656
 
4630
- const createCommentInstance = (comment, context) => {
4657
+ const createCommentInstance = (comment, context, index) => {
4631
4658
  for (const plugin of config.commentPlugins) {
4632
4659
  if (plugin.condition(comment)) {
4633
- return new plugin.class(comment, context);
4660
+ return new plugin.class(comment, context, index);
4634
4661
  }
4635
4662
  }
4636
- return new HTML5Comment(comment, context);
4663
+ return new HTML5Comment(comment, context, index);
4637
4664
  };
4638
4665
 
4639
4666
  const definition = {
@@ -4662,6 +4689,8 @@
4662
4689
  showFPS;
4663
4690
  showCommentCount;
4664
4691
  lastVpos;
4692
+ processedCommentIndex;
4693
+ comments;
4665
4694
  renderer;
4666
4695
  collision;
4667
4696
  timeline;
@@ -4718,7 +4747,8 @@
4718
4747
  right: [],
4719
4748
  };
4720
4749
  this.lastVpos = -1;
4721
- this.preRendering(parsedData);
4750
+ this.processedCommentIndex = 0;
4751
+ this.comments = this.preRendering(parsedData);
4722
4752
  logger(`constructor complete: ${performance.now() - constructorStart}ms`);
4723
4753
  }
4724
4754
  preRendering(rawData) {
@@ -4726,12 +4756,12 @@
4726
4756
  if (options.keepCA) {
4727
4757
  rawData = changeCALayer(rawData);
4728
4758
  }
4729
- let instances = rawData.reduce((pv, val) => {
4730
- pv.push(createCommentInstance(val, this.renderer));
4759
+ let instances = rawData.reduce((pv, val, index) => {
4760
+ pv.push(createCommentInstance(val, this.renderer, index));
4731
4761
  return pv;
4732
4762
  }, []);
4733
- this.getCommentPos(instances);
4734
- this.sortComment();
4763
+ this.getCommentPos(instances, instances.length, options.lazy);
4764
+ this.sortTimelineComment();
4735
4765
  const plugins = [];
4736
4766
  for (const plugin of config.plugins) {
4737
4767
  try {
@@ -4751,22 +4781,29 @@
4751
4781
  }
4752
4782
  setPlugins(plugins);
4753
4783
  logger(`preRendering complete: ${performance.now() - preRenderingStart}ms`);
4784
+ return instances;
4754
4785
  }
4755
- getCommentPos(data) {
4786
+ getCommentPos(data, end, lazy = false) {
4756
4787
  const getCommentPosStart = performance.now();
4757
- for (const comment of data) {
4758
- if (comment.invisible)
4788
+ if (this.processedCommentIndex + 1 >= end)
4789
+ return;
4790
+ for (const comment of data.slice(this.processedCommentIndex, end)) {
4791
+ if (comment.invisible || (comment.posY > -1 && !lazy))
4759
4792
  continue;
4760
4793
  if (comment.loc === "naka") {
4761
- processMovableComment(comment, this.collision, this.timeline);
4794
+ processMovableComment(comment, this.collision, this.timeline, lazy);
4762
4795
  }
4763
4796
  else {
4764
- processFixedComment(comment, this.collision[comment.loc], this.timeline);
4797
+ processFixedComment(comment, this.collision[comment.loc], this.timeline, lazy);
4765
4798
  }
4799
+ this.processedCommentIndex = comment.index;
4800
+ }
4801
+ if (lazy) {
4802
+ this.processedCommentIndex = 0;
4766
4803
  }
4767
4804
  logger(`getCommentPos complete: ${performance.now() - getCommentPosStart}ms`);
4768
4805
  }
4769
- sortComment() {
4806
+ sortTimelineComment() {
4770
4807
  const sortCommentStart = performance.now();
4771
4808
  for (const vpos of Object.keys(this.timeline)) {
4772
4809
  const item = this.timeline[Number(vpos)];
@@ -4786,8 +4823,8 @@
4786
4823
  logger(`parseData complete: ${performance.now() - sortCommentStart}ms`);
4787
4824
  }
4788
4825
  addComments(...rawComments) {
4789
- const comments = rawComments.reduce((pv, val) => {
4790
- pv.push(createCommentInstance(val, this.renderer));
4826
+ const comments = rawComments.reduce((pv, val, index) => {
4827
+ pv.push(createCommentInstance(val, this.renderer, this.comments.length + index));
4791
4828
  return pv;
4792
4829
  }, []);
4793
4830
  for (const plugin of plugins) {
@@ -4862,6 +4899,7 @@
4862
4899
  if (comment.invisible) {
4863
4900
  continue;
4864
4901
  }
4902
+ this.getCommentPos(this.comments, comment.index + 1);
4865
4903
  comment.draw(vpos, this.showCollision, cursor);
4866
4904
  }
4867
4905
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xpadev-net/niconicomments",
3
- "version": "0.2.68",
3
+ "version": "0.2.70",
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",