@xpadev-net/niconicomments 0.2.55 → 0.2.56

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.
Files changed (3) hide show
  1. package/dist/bundle.d.ts +193 -239
  2. package/dist/bundle.js +168 -104
  3. package/package.json +23 -23
package/dist/bundle.d.ts CHANGED
@@ -44,8 +44,6 @@ declare class BaseComment implements IComment {
44
44
 
45
45
  declare class FlashComment extends BaseComment {
46
46
  private _globalScale;
47
- private scale;
48
- private scaleX;
49
47
  readonly pluginName: string;
50
48
  constructor(comment: FormattedComment, context: Context2D);
51
49
  get content(): string;
@@ -91,151 +89,148 @@ declare const index_d$3_FlashComment: typeof FlashComment;
91
89
  type index_d$3_HTML5Comment = HTML5Comment;
92
90
  declare const index_d$3_HTML5Comment: typeof HTML5Comment;
93
91
  declare namespace index_d$3 {
94
- export {
95
- index_d$3_BaseComment as BaseComment,
96
- index_d$3_FlashComment as FlashComment,
97
- index_d$3_HTML5Comment as HTML5Comment,
98
- };
92
+ export { index_d$3_BaseComment as BaseComment, index_d$3_FlashComment as FlashComment, index_d$3_HTML5Comment as HTML5Comment };
99
93
  }
100
94
 
101
- type ConfigItem<T> = T | { html5: T; flash: T };
102
- type ConfigSizeItem<T> = { big: T; medium: T; small: T };
103
- type ConfigResizedItem<T> = { default: T; resized: T };
104
-
105
- type CommentStageSize = {
106
- width: number;
107
- fullWidth: number;
108
- height: number;
109
- };
110
-
111
- type FlashCharList = {
112
- [key in "simsunStrong" | "simsunWeak" | "gulim" | "gothic"]: string;
113
- };
114
- type FlashMode = "xp" | "vista";
115
- type FlashScriptChar = {
116
- [key in "super" | "sub"]: string;
117
- };
118
- type FontList = {
119
- [key in "gulim" | "simsun"]: string;
120
- };
121
- type LineCounts = {
122
- [key in "default" | "resized" | "doubleResized"]: ConfigSizeItem<number>;
123
- };
124
- type TypeDoubleResizeMaxWidth = {
125
- [key in "full" | "normal"]: number;
126
- };
127
-
128
- type BaseConfig = {
129
- cacheAge: number;
130
- canvasHeight: number;
131
- canvasWidth: number;
132
- collisionRange: { [key in "left" | "right"]: number };
133
- colors: { [key: string]: string };
134
- commentDrawPadding: number;
135
- commentDrawRange: number;
136
- commentScale: ConfigItem<number>;
137
- CommentStageSize: ConfigItem<CommentStageSize>;
138
- commentYMarginBottom: ConfigSizeItem<number>;
139
- commentYOffset: ConfigSizeItem<ConfigResizedItem<number>>;
140
- commentYPaddingTop: ConfigResizedItem<number>;
141
- contextFillLiveOpacity: number;
142
- contextLineWidth: number;
143
- contextStrokeColor: string;
144
- contextStrokeInversionColor: string;
145
- contextStrokeOpacity: number;
146
- doubleResizeMaxWidth: ConfigItem<TypeDoubleResizeMaxWidth>;
147
- flashChar: FlashCharList;
148
- FlashMode: FlashMode;
149
- FlashScriptChar: FlashScriptChar;
150
- flashThreshold: number;
151
- font: FontList;
152
- fonts: PlatformFont;
153
- fontSize: ConfigItem<ConfigSizeItem<ConfigResizedItem<number>>>;
154
- fpsInterval: number;
155
- hiResCommentCorrection: number;
156
- lineCounts: ConfigItem<LineCounts>;
157
- lineHeight: ConfigItem<ConfigSizeItem<ConfigResizedItem<number>>>;
158
- minFontSize: number;
159
- sameCAGap: number;
160
- sameCAMinScore: number;
161
- sameCARange: number;
162
- sameCATimestampRange: number;
163
- letterSpacing: number;
164
- scriptCharOffset: number;
165
- plugins: IPluginConstructor[];
166
- commentPlugins: {
167
- class: typeof BaseComment;
168
- condition: (comment: FormattedComment) => boolean;
169
- }[];
170
- commentLimit: number | undefined;
171
- hideCommentOrder: "asc" | "desc";
172
- lineBreakCount: { [key in CommentSize]: number };
173
- nakaCommentSpeedOffset: number;
174
- };
175
-
95
+ type ConfigItem<T> = T | MultiConfigItem<T>;
96
+ type MultiConfigItem<T> = { html5: T; flash: T };
97
+ type ConfigSizeItem<T> = { big: T; medium: T; small: T };
98
+ type ConfigResizedItem<T> = { default: T; resized: T };
99
+
100
+ type CommentStageSize = {
101
+ width: number;
102
+ fullWidth: number;
103
+ height: number;
104
+ };
105
+
106
+ type FlashCharList = {
107
+ [key in "simsunStrong" | "simsunWeak" | "gulim" | "gothic"]: string;
108
+ };
109
+ type FlashMode = "xp" | "vista";
110
+ type FlashScriptChar = {
111
+ [key in "super" | "sub"]: string;
112
+ };
113
+ type FontList = {
114
+ [key in "gulim" | "simsun"]: string;
115
+ };
116
+ type LineCounts = {
117
+ [key in "default" | "resized" | "doubleResized"]: ConfigSizeItem<number>;
118
+ };
119
+ type TypeDoubleResizeMaxWidth = {
120
+ [key in "full" | "normal"]: number;
121
+ };
122
+
123
+ type BaseConfig = {
124
+ cacheAge: number;
125
+ canvasHeight: number;
126
+ canvasWidth: number;
127
+ collisionRange: { [key in "left" | "right"]: number };
128
+ colors: { [key: string]: string };
129
+ commentDrawPadding: number;
130
+ commentDrawRange: number;
131
+ commentScale: ConfigItem<number>;
132
+ CommentStageSize: ConfigItem<CommentStageSize>;
133
+ commentYMarginBottom: ConfigSizeItem<number>;
134
+ commentYOffset: ConfigSizeItem<ConfigResizedItem<number>>;
135
+ commentYPaddingTop: ConfigResizedItem<number>;
136
+ contextFillLiveOpacity: number;
137
+ contextLineWidth: number;
138
+ contextStrokeColor: string;
139
+ contextStrokeInversionColor: string;
140
+ contextStrokeOpacity: number;
141
+ doubleResizeMaxWidth: ConfigItem<TypeDoubleResizeMaxWidth>;
142
+ flashChar: FlashCharList;
143
+ FlashMode: FlashMode;
144
+ FlashScriptChar: FlashScriptChar;
145
+ flashThreshold: number;
146
+ font: FontList;
147
+ fonts: PlatformFont;
148
+ fontSize: ConfigItem<ConfigSizeItem<ConfigResizedItem<number>>>;
149
+ fpsInterval: number;
150
+ hiResCommentCorrection: number;
151
+ lineCounts: ConfigItem<LineCounts>;
152
+ lineHeight: ConfigItem<ConfigSizeItem<ConfigResizedItem<number>>>;
153
+ minFontSize: number;
154
+ sameCAGap: number;
155
+ sameCAMinScore: number;
156
+ sameCARange: number;
157
+ sameCATimestampRange: number;
158
+ letterSpacing: number;
159
+ scriptCharOffset: number;
160
+ plugins: IPluginConstructor[];
161
+ commentPlugins: {
162
+ class: typeof BaseComment;
163
+ condition: (comment: FormattedComment) => boolean;
164
+ }[];
165
+ commentLimit: number | undefined;
166
+ hideCommentOrder: "asc" | "desc";
167
+ lineBreakCount: { [key in CommentSize]: number };
168
+ nakaCommentSpeedOffset: number;
169
+ };
170
+
176
171
  type Config = Partial<BaseConfig>;
177
172
 
178
- interface CommentEventBase {
179
- type: CommentEventName;
180
- timeStamp: number;
181
- vpos: number;
182
- }
183
-
184
- interface SeekDisableEvent extends CommentEventBase {
185
- type: "seekDisable";
186
- }
187
-
188
- type SeekDisableEventHandler = (event: SeekDisableEvent) => unknown;
189
-
190
- interface SeekEnableEvent extends CommentEventBase {
191
- type: "seekEnable";
192
- }
193
- type SeekEnableEventHandler = (event: SeekEnableEvent) => unknown;
194
-
195
- interface CommentDisableEvent extends CommentEventBase {
196
- type: "commentDisable";
197
- }
198
- type CommentDisableEventHandler = (
199
- event: CommentDisableEvent
200
- ) => unknown;
201
-
202
- interface CommentEnableEvent extends CommentEventBase {
203
- type: "commentEnable";
204
- }
205
- type CommentEnableEventHandler = (event: CommentEnableEvent) => unknown;
206
-
207
- interface JumpEvent extends CommentEventBase {
208
- type: "jump";
209
- to: string;
210
- message?: string;
211
- }
212
- type JumpEventHandler = (event: JumpEvent) => unknown;
213
-
214
- type CommentEventName =
215
- | "seekDisable"
216
- | "seekEnable"
217
- | "commentDisable"
218
- | "commentEnable"
219
- | "jump";
220
- type CommentEventHandler =
221
- | SeekDisableEventHandler
222
- | SeekEnableEventHandler
223
- | CommentDisableEventHandler
224
- | CommentEnableEventHandler
225
- | JumpEventHandler;
226
- interface CommentEventHandlerMap {
227
- seekDisable: SeekDisableEventHandler;
228
- seekEnable: SeekEnableEventHandler;
229
- commentDisable: CommentDisableEventHandler;
230
- commentEnable: CommentEnableEventHandler;
231
- jump: JumpEventHandler;
232
- }
233
- interface CommentEventMap {
234
- seekDisable: SeekDisableEvent;
235
- seekEnable: SeekEnableEvent;
236
- commentDisable: CommentDisableEvent;
237
- commentEnable: CommentEnableEvent;
238
- jump: JumpEvent;
173
+ interface CommentEventBase {
174
+ type: CommentEventName;
175
+ timeStamp: number;
176
+ vpos: number;
177
+ }
178
+
179
+ interface SeekDisableEvent extends CommentEventBase {
180
+ type: "seekDisable";
181
+ }
182
+
183
+ type SeekDisableEventHandler = (event: SeekDisableEvent) => unknown;
184
+
185
+ interface SeekEnableEvent extends CommentEventBase {
186
+ type: "seekEnable";
187
+ }
188
+ type SeekEnableEventHandler = (event: SeekEnableEvent) => unknown;
189
+
190
+ interface CommentDisableEvent extends CommentEventBase {
191
+ type: "commentDisable";
192
+ }
193
+ type CommentDisableEventHandler = (
194
+ event: CommentDisableEvent,
195
+ ) => unknown;
196
+
197
+ interface CommentEnableEvent extends CommentEventBase {
198
+ type: "commentEnable";
199
+ }
200
+ type CommentEnableEventHandler = (event: CommentEnableEvent) => unknown;
201
+
202
+ interface JumpEvent extends CommentEventBase {
203
+ type: "jump";
204
+ to: string;
205
+ message?: string;
206
+ }
207
+ type JumpEventHandler = (event: JumpEvent) => unknown;
208
+
209
+ type CommentEventName =
210
+ | "seekDisable"
211
+ | "seekEnable"
212
+ | "commentDisable"
213
+ | "commentEnable"
214
+ | "jump";
215
+ type CommentEventHandler =
216
+ | SeekDisableEventHandler
217
+ | SeekEnableEventHandler
218
+ | CommentDisableEventHandler
219
+ | CommentEnableEventHandler
220
+ | JumpEventHandler;
221
+ interface CommentEventHandlerMap {
222
+ seekDisable: SeekDisableEventHandler;
223
+ seekEnable: SeekEnableEventHandler;
224
+ commentDisable: CommentDisableEventHandler;
225
+ commentEnable: CommentEnableEventHandler;
226
+ jump: JumpEventHandler;
227
+ }
228
+ interface CommentEventMap {
229
+ seekDisable: SeekDisableEvent;
230
+ seekEnable: SeekEnableEvent;
231
+ commentDisable: CommentDisableEvent;
232
+ commentEnable: CommentEnableEvent;
233
+ jump: JumpEvent;
239
234
  }
240
235
 
241
236
  type Platform =
@@ -385,15 +380,20 @@ interface IComment {
385
380
  draw: (vpos: number, showCollision: boolean, isDebug: boolean) => void;
386
381
  }
387
382
 
388
- interface IPluginConstructor {
389
- id: string;
390
- new (Canvas: Canvas, comments: IComment[]): IPlugin;
391
- }
392
-
393
- interface IPlugin {
394
- draw(vpos: number): void;
395
- addComments(comments: IComment[]): void;
396
- }
383
+ interface IPluginConstructor {
384
+ id: string;
385
+ new (Canvas: Canvas, comments: IComment[]): IPlugin;
386
+ }
387
+
388
+ interface IPlugin {
389
+ draw(vpos: number): void;
390
+ addComments(comments: IComment[]): void;
391
+ }
392
+
393
+ type IPluginList = {
394
+ instance: IPlugin;
395
+ canvas: HTMLCanvasElement;
396
+ }[];
397
397
 
398
398
  type InputFormatType =
399
399
  | "XMLDocument"
@@ -479,6 +479,8 @@ type FormattedCommentWithSize = FormattedCommentWithFont & {
479
479
  resizedY: boolean;
480
480
  content: CommentMeasuredContentItem[];
481
481
  charSize: number;
482
+ scale: number;
483
+ scaleX: number;
482
484
  };
483
485
  type ParseContentResult = {
484
486
  content: CommentContentItem[];
@@ -510,9 +512,14 @@ type CommentContentItem = {
510
512
  type CommentMeasuredContentItem = CommentContentItem & {
511
513
  width: number[];
512
514
  };
515
+ type CommentFlashFontParsed =
516
+ | "gothic"
517
+ | "gulim"
518
+ | "simsunStrong"
519
+ | "simsunWeak";
513
520
  type CommentContentIndex = {
514
521
  index: number;
515
- font: "gothic" | "gulim" | "simsunStrong" | "simsunWeak";
522
+ font: CommentFlashFontParsed;
516
523
  };
517
524
  type CommentFont = "defont" | "mincho" | "gothic" | "gulim" | "simsun";
518
525
  type CommentFlashFont = "defont" | "gulim" | "simsun";
@@ -590,6 +597,8 @@ type MeasureTextResult = {
590
597
  lineHeight: number;
591
598
  content: CommentMeasuredContentItem[];
592
599
  charSize: number;
600
+ scaleX: number;
601
+ scale: number;
593
602
  };
594
603
  type ParsedCommand = {
595
604
  loc: CommentLoc | undefined;
@@ -605,6 +614,7 @@ type ParsedCommand = {
605
614
  _live: boolean;
606
615
  invisible: boolean;
607
616
  long: number | undefined;
617
+ button: boolean;
608
618
  };
609
619
 
610
620
  type MeasureTextInput = {
@@ -622,6 +632,7 @@ type MeasureTextInput = {
622
632
  lineCount: number;
623
633
  lineHeight?: number;
624
634
  charSize?: number;
635
+ scale: number;
625
636
  };
626
637
 
627
638
  type MeasureInput = {
@@ -645,8 +656,8 @@ declare const resetImageCache: () => void;
645
656
  declare let nicoScripts: NicoScript;
646
657
  declare const resetNicoScripts: () => void;
647
658
 
648
- declare let plugins: IPlugin[];
649
- declare const setPlugins: (input: IPlugin[]) => void;
659
+ declare let plugins: IPluginList;
660
+ declare const setPlugins: (input: IPluginList) => void;
650
661
 
651
662
  declare const index_d$2_imageCache: typeof imageCache;
652
663
  declare const index_d$2_nicoScripts: typeof nicoScripts;
@@ -655,14 +666,7 @@ declare const index_d$2_resetImageCache: typeof resetImageCache;
655
666
  declare const index_d$2_resetNicoScripts: typeof resetNicoScripts;
656
667
  declare const index_d$2_setPlugins: typeof setPlugins;
657
668
  declare namespace index_d$2 {
658
- export {
659
- index_d$2_imageCache as imageCache,
660
- index_d$2_nicoScripts as nicoScripts,
661
- index_d$2_plugins as plugins,
662
- index_d$2_resetImageCache as resetImageCache,
663
- index_d$2_resetNicoScripts as resetNicoScripts,
664
- index_d$2_setPlugins as setPlugins,
665
- };
669
+ export { index_d$2_imageCache as imageCache, index_d$2_nicoScripts as nicoScripts, index_d$2_plugins as plugins, index_d$2_resetImageCache as resetImageCache, index_d$2_resetNicoScripts as resetNicoScripts, index_d$2_setPlugins as setPlugins };
666
670
  }
667
671
 
668
672
  declare const colors: {
@@ -697,9 +701,7 @@ declare const colors: {
697
701
 
698
702
  declare const colors$1_colors: typeof colors;
699
703
  declare namespace colors$1 {
700
- export {
701
- colors$1_colors as colors,
702
- };
704
+ export { colors$1_colors as colors };
703
705
  }
704
706
 
705
707
  declare let defaultConfig: BaseConfig;
@@ -718,15 +720,7 @@ declare const config$1_setConfig: typeof setConfig;
718
720
  declare const config$1_setOptions: typeof setOptions;
719
721
  declare const config$1_updateConfig: typeof updateConfig;
720
722
  declare namespace config$1 {
721
- export {
722
- config$1_config as config,
723
- config$1_defaultConfig as defaultConfig,
724
- config$1_defaultOptions as defaultOptions,
725
- config$1_options as options,
726
- config$1_setConfig as setConfig,
727
- config$1_setOptions as setOptions,
728
- config$1_updateConfig as updateConfig,
729
- };
723
+ export { config$1_config as config, config$1_defaultConfig as defaultConfig, config$1_defaultOptions as defaultOptions, config$1_options as options, config$1_setConfig as setConfig, config$1_setOptions as setOptions, config$1_updateConfig as updateConfig };
730
724
  }
731
725
 
732
726
  declare const fontTemplates: {
@@ -837,19 +831,14 @@ declare const fonts: {
837
831
  declare const fonts$1_fontTemplates: typeof fontTemplates;
838
832
  declare const fonts$1_fonts: typeof fonts;
839
833
  declare namespace fonts$1 {
840
- export {
841
- fonts$1_fontTemplates as fontTemplates,
842
- fonts$1_fonts as fonts,
843
- };
834
+ export { fonts$1_fontTemplates as fontTemplates, fonts$1_fonts as fonts };
844
835
  }
845
836
 
846
837
  declare const initConfig: () => void;
847
838
 
848
839
  declare const initConfig$1_initConfig: typeof initConfig;
849
840
  declare namespace initConfig$1 {
850
- export {
851
- initConfig$1_initConfig as initConfig,
852
- };
841
+ export { initConfig$1_initConfig as initConfig };
853
842
  }
854
843
 
855
844
  declare class CanvasRenderingContext2DError extends Error {
@@ -887,12 +876,7 @@ declare const index_d$1_InvalidOptionError: typeof InvalidOptionError;
887
876
  type index_d$1_NotImplementedError = NotImplementedError;
888
877
  declare const index_d$1_NotImplementedError: typeof NotImplementedError;
889
878
  declare namespace index_d$1 {
890
- export {
891
- index_d$1_CanvasRenderingContext2DError as CanvasRenderingContext2DError,
892
- index_d$1_InvalidFormatError as InvalidFormatError,
893
- index_d$1_InvalidOptionError as InvalidOptionError,
894
- index_d$1_NotImplementedError as NotImplementedError,
895
- };
879
+ export { index_d$1_CanvasRenderingContext2DError as CanvasRenderingContext2DError, index_d$1_InvalidFormatError as InvalidFormatError, index_d$1_InvalidOptionError as InvalidOptionError, index_d$1_NotImplementedError as NotImplementedError };
896
880
  }
897
881
 
898
882
  declare const registerHandler: <K extends keyof CommentEventHandlerMap>(eventName: K, handler: CommentEventHandlerMap[K]) => void;
@@ -903,19 +887,13 @@ declare const eventHandler_d_registerHandler: typeof registerHandler;
903
887
  declare const eventHandler_d_removeHandler: typeof removeHandler;
904
888
  declare const eventHandler_d_triggerHandler: typeof triggerHandler;
905
889
  declare namespace eventHandler_d {
906
- export {
907
- eventHandler_d_registerHandler as registerHandler,
908
- eventHandler_d_removeHandler as removeHandler,
909
- eventHandler_d_triggerHandler as triggerHandler,
910
- };
890
+ export { eventHandler_d_registerHandler as registerHandler, eventHandler_d_removeHandler as removeHandler, eventHandler_d_triggerHandler as triggerHandler };
911
891
  }
912
892
 
913
893
  declare const convert2formattedComment: (data: unknown, type: InputFormatType) => FormattedComment[];
914
894
 
915
895
  declare namespace inputParser_d {
916
- export {
917
- convert2formattedComment as default,
918
- };
896
+ export { convert2formattedComment as default };
919
897
  }
920
898
 
921
899
  declare const typeGuard: {
@@ -970,12 +948,17 @@ declare const typeGuard: {
970
948
  config: {
971
949
  initOptions: (item: unknown) => item is Partial<BaseOptions>;
972
950
  };
951
+ internal: {
952
+ CommentMeasuredContentItem: (i: unknown) => i is CommentMeasuredContentItem;
953
+ CommentMeasuredContentItemArray: (i: unknown) => i is CommentMeasuredContentItem[];
954
+ MultiConfigItem: <T>(i: unknown) => i is MultiConfigItem<T>;
955
+ HTML5Fonts: (i: unknown) => i is HTML5Fonts;
956
+ MeasureInput: (i: unknown) => i is MeasureInput;
957
+ };
973
958
  };
974
959
 
975
960
  declare namespace typeGuard_d {
976
- export {
977
- typeGuard as default,
978
- };
961
+ export { typeGuard as default };
979
962
  }
980
963
 
981
964
  declare const ArrayPush: (array: {
@@ -1015,7 +998,7 @@ declare const changeCALayer: (rawData: FormattedComment[]) => FormattedComment[]
1015
998
  declare const getConfig: <T>(input: ConfigItem<T>, isFlash?: boolean) => T;
1016
999
 
1017
1000
  declare const getFlashFontIndex: (part: string) => CommentContentIndex[];
1018
- declare const getFlashFontName: (font: string) => CommentFlashFont;
1001
+ declare const getFlashFontName: (font: CommentFlashFontParsed) => CommentFlashFont;
1019
1002
  declare const parseContent: (content: string) => CommentContentItem[];
1020
1003
 
1021
1004
  declare const getLineHeight: (fontSize: CommentSize, isFlash: boolean, resized?: boolean) => number;
@@ -1060,34 +1043,7 @@ declare const index_d_parseFont: typeof parseFont;
1060
1043
  declare const index_d_processFixedComment: typeof processFixedComment;
1061
1044
  declare const index_d_processMovableComment: typeof processMovableComment;
1062
1045
  declare namespace index_d {
1063
- export {
1064
- index_d_ArrayEqual as ArrayEqual,
1065
- index_d_ArrayPush as ArrayPush,
1066
- index_d_changeCALayer as changeCALayer,
1067
- index_d_getCharSize as getCharSize,
1068
- index_d_getConfig as getConfig,
1069
- index_d_getDefaultCommand as getDefaultCommand,
1070
- index_d_getFlashFontIndex as getFlashFontIndex,
1071
- index_d_getFlashFontName as getFlashFontName,
1072
- index_d_getFontSizeAndScale as getFontSizeAndScale,
1073
- index_d_getLineHeight as getLineHeight,
1074
- index_d_getPosX as getPosX,
1075
- index_d_getPosY as getPosY,
1076
- index_d_getStrokeColor as getStrokeColor,
1077
- index_d_hex2rgb as hex2rgb,
1078
- index_d_hex2rgba as hex2rgba,
1079
- index_d_isBanActive as isBanActive,
1080
- index_d_isFlashComment as isFlashComment,
1081
- index_d_isLineBreakResize as isLineBreakResize,
1082
- index_d_isReverseActive as isReverseActive,
1083
- index_d_measure as measure,
1084
- index_d_nativeSort as nativeSort,
1085
- index_d_parseCommandAndNicoScript as parseCommandAndNicoScript,
1086
- index_d_parseContent as parseContent,
1087
- index_d_parseFont as parseFont,
1088
- index_d_processFixedComment as processFixedComment,
1089
- index_d_processMovableComment as processMovableComment,
1090
- };
1046
+ export { index_d_ArrayEqual as ArrayEqual, index_d_ArrayPush as ArrayPush, index_d_changeCALayer as changeCALayer, index_d_getCharSize as getCharSize, index_d_getConfig as getConfig, index_d_getDefaultCommand as getDefaultCommand, index_d_getFlashFontIndex as getFlashFontIndex, index_d_getFlashFontName as getFlashFontName, index_d_getFontSizeAndScale as getFontSizeAndScale, index_d_getLineHeight as getLineHeight, index_d_getPosX as getPosX, index_d_getPosY as getPosY, index_d_getStrokeColor as getStrokeColor, index_d_hex2rgb as hex2rgb, index_d_hex2rgba as hex2rgba, index_d_isBanActive as isBanActive, index_d_isFlashComment as isFlashComment, index_d_isLineBreakResize as isLineBreakResize, index_d_isReverseActive as isReverseActive, index_d_measure as measure, index_d_nativeSort as nativeSort, index_d_parseCommandAndNicoScript as parseCommandAndNicoScript, index_d_parseContent as parseContent, index_d_parseFont as parseFont, index_d_processFixedComment as processFixedComment, index_d_processMovableComment as processMovableComment };
1091
1047
  }
1092
1048
 
1093
1049
  declare const definition: {
@@ -1099,16 +1055,7 @@ declare const definition: {
1099
1055
 
1100
1056
  declare const internal_definition: typeof definition;
1101
1057
  declare namespace internal {
1102
- export {
1103
- index_d$3 as comments,
1104
- index_d$2 as contexts,
1105
- internal_definition as definition,
1106
- index_d$1 as errors,
1107
- eventHandler_d as eventHandler,
1108
- inputParser_d as inputParser,
1109
- typeGuard_d as typeGuard,
1110
- index_d as utils,
1111
- };
1058
+ export { index_d$3 as comments, index_d$2 as contexts, internal_definition as definition, index_d$1 as errors, eventHandler_d as eventHandler, inputParser_d as inputParser, typeGuard_d as typeGuard, index_d as utils };
1112
1059
  }
1113
1060
 
1114
1061
  declare class NiconiComments {
@@ -1174,6 +1121,13 @@ declare class NiconiComments {
1174
1121
  config: {
1175
1122
  initOptions: (item: unknown) => item is Partial<BaseOptions>;
1176
1123
  };
1124
+ internal: {
1125
+ CommentMeasuredContentItem: (i: unknown) => i is CommentMeasuredContentItem;
1126
+ CommentMeasuredContentItemArray: (i: unknown) => i is CommentMeasuredContentItem[];
1127
+ MultiConfigItem: <T>(i: unknown) => i is MultiConfigItem<T>;
1128
+ HTML5Fonts: (i: unknown) => i is HTML5Fonts;
1129
+ MeasureInput: (i: unknown) => i is MeasureInput;
1130
+ };
1177
1131
  };
1178
1132
  static default: typeof NiconiComments;
1179
1133
  static FlashComment: {
@@ -1197,4 +1151,4 @@ declare class NiconiComments {
1197
1151
  clear(): void;
1198
1152
  }
1199
1153
 
1200
- export { ApiChat, ApiGlobalNumRes, ApiLeaf, ApiPing, ApiThread, BaseConfig, BaseOptions, Canvas, Collision, CollisionItem, CollisionPos, CommentContentIndex, CommentContentItem, CommentDisableEvent, CommentDisableEventHandler, CommentEnableEvent, CommentEnableEventHandler, CommentEventBase, CommentEventHandler, CommentEventHandlerMap, CommentEventMap, CommentEventName, CommentFlashFont, CommentFont, CommentLoc, CommentMeasuredContentItem, CommentSize, CommentStageSize, Config, ConfigItem, Context2D, FlashMode, FlashScriptChar, FontItem, FormattedComment, FormattedCommentWithFont, FormattedCommentWithSize, FormattedLegacyComment, HTML5Fonts, IComment, IPlugin, IPluginConstructor, InputFormat, InputFormatType, JumpEvent, JumpEventHandler, MeasureInput, MeasureTextInput, MeasureTextResult, NicoScript, NicoScriptReplace, NicoScriptReplaceCondition, NicoScriptReplaceRange, NicoScriptReplaceTarget, NicoScriptReverseTarget, Options, OwnerComment, ParseCommandAndNicoScriptResult, ParseContentResult, ParsedCommand, Platform, PlatformFont, RawApiResponse, SeekDisableEvent, SeekDisableEventHandler, SeekEnableEvent, SeekEnableEventHandler, Timeline, V1Comment, V1Thread, ValueOf, NiconiComments as default, formattedComment, formattedLegacyComment, inputFormat, inputFormatType, ownerComment, rawApiResponse, v1Thread };
1154
+ export { type ApiChat, type ApiGlobalNumRes, type ApiLeaf, type ApiPing, type ApiThread, type BaseConfig, type BaseOptions, type Canvas, type Collision, type CollisionItem, type CollisionPos, type CommentContentIndex, type CommentContentItem, type CommentDisableEvent, type CommentDisableEventHandler, type CommentEnableEvent, type CommentEnableEventHandler, type CommentEventBase, type CommentEventHandler, type CommentEventHandlerMap, type CommentEventMap, type CommentEventName, type CommentFlashFont, type CommentFlashFontParsed, type CommentFont, type CommentLoc, type CommentMeasuredContentItem, type CommentSize, type CommentStageSize, type Config, type ConfigItem, type Context2D, type FlashMode, type FlashScriptChar, type FontItem, type FormattedComment, type FormattedCommentWithFont, type FormattedCommentWithSize, type FormattedLegacyComment, type HTML5Fonts, type IComment, type IPlugin, type IPluginConstructor, type IPluginList, type InputFormat, type InputFormatType, type JumpEvent, type JumpEventHandler, type MeasureInput, type MeasureTextInput, type MeasureTextResult, type MultiConfigItem, type NicoScript, type NicoScriptReplace, type NicoScriptReplaceCondition, type NicoScriptReplaceRange, type NicoScriptReplaceTarget, type NicoScriptReverseTarget, type Options, type OwnerComment, type ParseCommandAndNicoScriptResult, type ParseContentResult, type ParsedCommand, type Platform, type PlatformFont, type RawApiResponse, type SeekDisableEvent, type SeekDisableEventHandler, type SeekEnableEvent, type SeekEnableEventHandler, type Timeline, type V1Comment, type V1Thread, type ValueOf, NiconiComments as default, type formattedComment, type formattedLegacyComment, type inputFormat, type inputFormatType, type ownerComment, type rawApiResponse, type v1Thread };
package/dist/bundle.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- niconicomments.js v0.2.55
2
+ niconicomments.js v0.2.56
3
3
  (c) 2021 xpadev-net https://xpadev.net
4
4
  Released under the MIT License.
5
5
  */
@@ -442,6 +442,20 @@
442
442
  return true;
443
443
  },
444
444
  },
445
+ internal: {
446
+ CommentMeasuredContentItem: (i) => objectVerify(i, ["content", "slicedContent", "width"]),
447
+ CommentMeasuredContentItemArray: (i) => Array.isArray(i) &&
448
+ i.every(typeGuard.internal.CommentMeasuredContentItem),
449
+ MultiConfigItem: (i) => typeof i === "object" && objectVerify(i, ["html5", "flash"]),
450
+ HTML5Fonts: (i) => i === "defont" || i === "mincho" || i === "gothic",
451
+ MeasureInput: (i) => objectVerify(i, [
452
+ "font",
453
+ "content",
454
+ "lineHeight",
455
+ "charSize",
456
+ "lineCount",
457
+ ]),
458
+ },
445
459
  };
446
460
  const objectVerify = (item, keys) => {
447
461
  if (typeof item !== "object" || !item)
@@ -468,13 +482,10 @@
468
482
  });
469
483
 
470
484
  const getConfig = (input, isFlash = false) => {
471
- if (Object.prototype.hasOwnProperty.call(input, "html5") &&
472
- Object.prototype.hasOwnProperty.call(input, "flash")) {
485
+ if (typeGuard.internal.MultiConfigItem(input)) {
473
486
  return input[isFlash ? "flash" : "html5"];
474
487
  }
475
- else {
476
- return input;
477
- }
488
+ return input;
478
489
  };
479
490
 
480
491
  const isLineBreakResize = (comment) => {
@@ -624,8 +635,14 @@
624
635
  });
625
636
  };
626
637
  const processNicoscript = (comment, commands) => {
627
- const nicoscript = comment.content.match(/^[@\uff20](\u30c7\u30d5\u30a9\u30eb\u30c8|\u7f6e\u63db|\u9006|\u30b3\u30e1\u30f3\u30c8\u7981\u6b62|\u30b7\u30fc\u30af\u7981\u6b62|\u30b8\u30e3\u30f3\u30d7)(.*)/);
628
- if (!nicoscript || !comment.owner)
638
+ const nicoscript = comment.content.match(/^[@\uff20](\u30c7\u30d5\u30a9\u30eb\u30c8|\u7f6e\u63db|\u9006|\u30b3\u30e1\u30f3\u30c8\u7981\u6b62|\u30b7\u30fc\u30af\u7981\u6b62|\u30b8\u30e3\u30f3\u30d7|\u30dc\u30bf\u30f3)(?:\s(.+))?/);
639
+ if (!nicoscript)
640
+ return;
641
+ if (nicoscript[1] === "\u30dc\u30bf\u30f3" && nicoscript[2]) {
642
+ processAtButton(commands);
643
+ return;
644
+ }
645
+ if (!comment.owner)
629
646
  return;
630
647
  commands.invisible = true;
631
648
  if (nicoscript[1] === "\u30c7\u30d5\u30a9\u30eb\u30c8") {
@@ -704,6 +721,10 @@
704
721
  message: options[2],
705
722
  });
706
723
  };
724
+ const processAtButton = (commands) => {
725
+ commands.invisible = false;
726
+ commands.button = true;
727
+ };
707
728
  const parseCommands = (comment) => {
708
729
  const commands = comment.mail, isFlash = isFlashComment(comment);
709
730
  const result = {
@@ -719,6 +740,7 @@
719
740
  _live: false,
720
741
  invisible: false,
721
742
  long: undefined,
743
+ button: false,
722
744
  };
723
745
  for (const command of commands) {
724
746
  parseCommand(comment, command, result, isFlash);
@@ -1091,7 +1113,7 @@
1091
1113
  return index;
1092
1114
  };
1093
1115
  const getFlashFontName = (font) => {
1094
- if (font.match("^simsun.+"))
1116
+ if (font === "simsunStrong" || font === "simsunWeak")
1095
1117
  return "simsun";
1096
1118
  if (font === "gothic")
1097
1119
  return "defont";
@@ -1201,6 +1223,13 @@
1201
1223
  });
1202
1224
  };
1203
1225
 
1226
+ class TypeGuardError extends Error {
1227
+ constructor(options = {}) {
1228
+ super("Type Guard Error\nAn error occurred due to unexpected values\nPlease contact the developer on GitHub", options);
1229
+ }
1230
+ }
1231
+ TypeGuardError.prototype.name = "TypeGuardError";
1232
+
1204
1233
  const getLineHeight = (fontSize, isFlash, resized = false) => {
1205
1234
  const lineCounts = getConfig(config.lineCounts, isFlash), CommentStageSize = getConfig(config.CommentStageSize, isFlash), lineHeight = CommentStageSize.height / lineCounts.doubleResized[fontSize], defaultLineCount = lineCounts.default[fontSize];
1206
1235
  if (resized) {
@@ -1231,7 +1260,10 @@
1231
1260
  context.font = parseFont(item.font || comment.font, fontSize);
1232
1261
  const width = [];
1233
1262
  for (let j = 0, n = lines.length; j < n; j++) {
1234
- const measure = context.measureText(lines[j]);
1263
+ const line = lines[j];
1264
+ if (line === undefined)
1265
+ throw new TypeGuardError();
1266
+ const measure = context.measureText(line);
1235
1267
  currentWidth += measure.width;
1236
1268
  width.push(measure.width);
1237
1269
  if (j < lines.length - 1) {
@@ -1495,15 +1527,10 @@
1495
1527
 
1496
1528
  class FlashComment extends BaseComment {
1497
1529
  _globalScale;
1498
- scale;
1499
- scaleX;
1500
1530
  pluginName = "FlashComment";
1501
1531
  constructor(comment, context) {
1502
1532
  super(comment, context);
1503
- this.scale ??= 1;
1504
- this.scaleX ??= 1;
1505
1533
  this._globalScale ??= getConfig(config.commentScale, true);
1506
- this.posY ??= 0;
1507
1534
  }
1508
1535
  get content() {
1509
1536
  return this.comment.rawContent;
@@ -1529,44 +1556,48 @@
1529
1556
  delete this.image;
1530
1557
  }
1531
1558
  convertComment(comment) {
1532
- this.scale = 1;
1533
- this.scaleX = 1;
1534
1559
  this._globalScale = getConfig(config.commentScale, true);
1535
- this.posY = 0;
1536
1560
  return this.getCommentSize(this.parseCommandAndNicoscript(comment));
1537
1561
  }
1538
1562
  getCommentSize(parsedData) {
1539
- this.context.save();
1540
- this.context.font = parseFont(parsedData.font, parsedData.fontSize);
1541
- const size = parsedData;
1542
1563
  if (parsedData.invisible) {
1543
- size.height = 0;
1544
- size.width = 0;
1545
- size.lineHeight = 0;
1546
- size.fontSize = 0;
1547
- size.resized = false;
1548
- size.resizedX = false;
1549
- size.resizedY = false;
1550
- size.charSize = 0;
1551
- this.context.restore();
1552
- return size;
1564
+ return {
1565
+ ...parsedData,
1566
+ height: 0,
1567
+ width: 0,
1568
+ lineHeight: 0,
1569
+ fontSize: 0,
1570
+ resized: false,
1571
+ resizedX: false,
1572
+ resizedY: false,
1573
+ charSize: 0,
1574
+ scale: 1,
1575
+ scaleX: 1,
1576
+ content: [],
1577
+ };
1553
1578
  }
1554
- const measure = this.measureText(parsedData);
1555
- if (options.scale !== 1 && size.layer === -1) {
1579
+ this.context.save();
1580
+ this.context.font = parseFont(parsedData.font, parsedData.fontSize);
1581
+ const measure = this.measureText({ ...parsedData, scale: 1 });
1582
+ if (options.scale !== 1 && parsedData.layer === -1) {
1556
1583
  measure.height *= options.scale;
1557
1584
  measure.width *= options.scale;
1558
1585
  }
1559
- size.height = measure.height * this._globalScale;
1560
- size.width = measure.width * this._globalScale;
1561
- size.lineHeight = measure.lineHeight;
1562
- size.fontSize = measure.fontSize;
1563
- size.content = measure.content;
1564
- size.resized = measure.resized;
1565
- size.resizedX = measure.resizedX;
1566
- size.resizedY = measure.resizedY;
1567
- size.charSize = measure.charSize;
1568
1586
  this.context.restore();
1569
- return size;
1587
+ return {
1588
+ ...parsedData,
1589
+ height: measure.height * this._globalScale,
1590
+ width: measure.width * this._globalScale,
1591
+ lineHeight: measure.lineHeight,
1592
+ fontSize: measure.fontSize,
1593
+ resized: measure.resized,
1594
+ resizedX: measure.resizedX,
1595
+ resizedY: measure.resizedY,
1596
+ charSize: measure.charSize,
1597
+ scale: measure.scale,
1598
+ scaleX: measure.scaleX,
1599
+ content: measure.content,
1600
+ };
1570
1601
  }
1571
1602
  parseCommandAndNicoscript(comment) {
1572
1603
  const data = parseCommandAndNicoScript(comment);
@@ -1615,32 +1646,34 @@
1615
1646
  const { width_arr, spacedWidth_arr } = this._measureContent(comment);
1616
1647
  const leadLine = (function () {
1617
1648
  let max = 0, index = -1;
1618
- for (let i = 0, l = spacedWidth_arr.length; i < l; i++) {
1619
- const val = spacedWidth_arr[i];
1620
- if (val && max < val) {
1649
+ spacedWidth_arr.forEach((val, i) => {
1650
+ if (max < val) {
1621
1651
  max = val;
1622
1652
  index = i;
1623
1653
  }
1624
- }
1654
+ });
1625
1655
  return { max, index };
1626
1656
  })();
1627
1657
  const width = leadLine.max;
1628
- this.scaleX = leadLine.max / (width_arr[leadLine.index] || 1);
1629
- const width_max = width * this.scale;
1658
+ const scaleX = leadLine.max / (width_arr[leadLine.index] ?? 1);
1659
+ const width_max = width * comment.scale;
1630
1660
  const height = (comment.fontSize * comment.lineHeight * lineCount +
1631
1661
  config.commentYPaddingTop[comment.resizedY ? "resized" : "default"]) *
1632
- this.scale;
1662
+ comment.scale;
1633
1663
  if (comment.loc !== "naka") {
1634
1664
  const widthLimit = getConfig(config.CommentStageSize, true)[comment.full ? "fullWidth" : "width"];
1635
1665
  if (width_max > widthLimit && !comment.resizedX) {
1636
1666
  comment.fontSize = configFontSize[comment.size].default;
1637
1667
  comment.lineHeight = configLineHeight[comment.size].default;
1638
- this.scale = widthLimit / width_max;
1668
+ comment.scale = widthLimit / width_max;
1639
1669
  comment.resizedX = true;
1640
1670
  comment.resized = true;
1641
1671
  return this.measureText(comment);
1642
1672
  }
1643
1673
  }
1674
+ if (!typeGuard.internal.CommentMeasuredContentItemArray(comment.content)) {
1675
+ throw new TypeGuardError();
1676
+ }
1644
1677
  return {
1645
1678
  width: width_max,
1646
1679
  charSize: 0,
@@ -1651,6 +1684,8 @@
1651
1684
  content: comment.content,
1652
1685
  resizedX: !!comment.resizedX,
1653
1686
  resizedY: !!comment.resizedY,
1687
+ scale: comment.scale,
1688
+ scaleX,
1654
1689
  };
1655
1690
  }
1656
1691
  _measureContent(comment) {
@@ -1690,13 +1725,13 @@
1690
1725
  for (let i = 0, n = this.comment.lineCount; i < n; i++) {
1691
1726
  const linePosY = ((i + 1) * (this.comment.fontSize * this.comment.lineHeight) +
1692
1727
  config.commentYPaddingTop[this.comment.resizedY ? "resized" : "default"]) *
1693
- this.scale;
1728
+ this.comment.scale;
1694
1729
  this.context.strokeStyle = `rgba(255,255,0,0.25)`;
1695
1730
  this.context.strokeRect(posX, posY + linePosY * this._globalScale, this.comment.width, this.comment.fontSize *
1696
1731
  this.comment.lineHeight *
1697
1732
  -1 *
1698
1733
  this._globalScale *
1699
- this.scale *
1734
+ this.comment.scale *
1700
1735
  (this.comment.layer === -1 ? options.scale : 1));
1701
1736
  }
1702
1737
  this.context.restore();
@@ -1713,9 +1748,9 @@
1713
1748
  context.lineWidth = 4;
1714
1749
  context.font = parseFont(this.comment.font, this.comment.fontSize);
1715
1750
  const scale = this._globalScale *
1716
- this.scale *
1751
+ this.comment.scale *
1717
1752
  (this.comment.layer === -1 ? options.scale : 1);
1718
- context.scale(scale * this.scaleX, scale);
1753
+ context.scale(scale * this.comment.scaleX, scale);
1719
1754
  const lineOffset = this.comment.lineOffset;
1720
1755
  const offsetKey = this.comment.resizedY ? "resized" : "default";
1721
1756
  const offsetY = config.commentYPaddingTop[offsetKey] +
@@ -1780,38 +1815,46 @@
1780
1815
  return this.getCommentSize(this.parseCommandAndNicoscript(comment));
1781
1816
  }
1782
1817
  getCommentSize(parsedData) {
1783
- this.context.save();
1784
- this.context.font = parseFont(parsedData.font, parsedData.fontSize);
1785
- const size = parsedData;
1786
1818
  if (parsedData.invisible) {
1787
- size.height = 0;
1788
- size.width = 0;
1789
- size.lineHeight = 0;
1790
- size.fontSize = 0;
1791
- size.resized = false;
1792
- size.resizedX = false;
1793
- size.resizedY = false;
1794
- size.charSize = 0;
1795
1819
  this.context.restore();
1796
- return size;
1820
+ return {
1821
+ ...parsedData,
1822
+ height: 0,
1823
+ width: 0,
1824
+ lineHeight: 0,
1825
+ fontSize: 0,
1826
+ resized: false,
1827
+ resizedX: false,
1828
+ resizedY: false,
1829
+ charSize: 0,
1830
+ content: [],
1831
+ scaleX: 1,
1832
+ scale: 1,
1833
+ };
1797
1834
  }
1798
- const measure = this.measureText(parsedData);
1799
- if (options.scale !== 1 && size.layer === -1) {
1835
+ this.context.save();
1836
+ this.context.font = parseFont(parsedData.font, parsedData.fontSize);
1837
+ const measure = this.measureText({ ...parsedData, scale: 1 });
1838
+ if (options.scale !== 1 && parsedData.layer === -1) {
1800
1839
  measure.height *= options.scale;
1801
1840
  measure.width *= options.scale;
1802
1841
  measure.fontSize *= options.scale;
1803
1842
  }
1804
- size.height = measure.height;
1805
- size.width = measure.width;
1806
- size.lineHeight = measure.lineHeight;
1807
- size.fontSize = measure.fontSize;
1808
- size.content = measure.content;
1809
- size.resized = measure.resized;
1810
- size.resizedX = measure.resizedX;
1811
- size.resizedY = measure.resizedY;
1812
- size.charSize = measure.charSize;
1813
1843
  this.context.restore();
1814
- return size;
1844
+ return {
1845
+ ...parsedData,
1846
+ height: measure.height,
1847
+ width: measure.width,
1848
+ lineHeight: measure.lineHeight,
1849
+ fontSize: measure.fontSize,
1850
+ resized: measure.resized,
1851
+ resizedX: measure.resizedX,
1852
+ resizedY: measure.resizedY,
1853
+ charSize: measure.charSize,
1854
+ content: measure.content,
1855
+ scaleX: measure.scaleX,
1856
+ scale: measure.scale,
1857
+ };
1815
1858
  }
1816
1859
  parseCommandAndNicoscript(comment) {
1817
1860
  const data = parseCommandAndNicoScript(comment);
@@ -1865,21 +1908,28 @@
1865
1908
  continue;
1866
1909
  item.width = itemWidth[i];
1867
1910
  }
1868
- comment.fontSize = (comment.charSize || 0) * 0.8;
1911
+ comment.fontSize = (comment.charSize ?? 0) * 0.8;
1912
+ if (!typeGuard.internal.CommentMeasuredContentItemArray(comment.content)) {
1913
+ throw new TypeGuardError();
1914
+ }
1869
1915
  return {
1870
1916
  width: width * scale,
1871
1917
  height: height * scale,
1872
1918
  resized: !!comment.resized,
1873
1919
  fontSize: comment.fontSize,
1874
- lineHeight: comment.lineHeight || 0,
1920
+ lineHeight: comment.lineHeight ?? 0,
1875
1921
  content: comment.content,
1876
1922
  resizedX: !!comment.resizedX,
1877
1923
  resizedY: !!comment.resizedY,
1878
- charSize: comment.charSize || 0,
1924
+ charSize: comment.charSize ?? 0,
1925
+ scaleX: 1,
1926
+ scale: 1,
1879
1927
  };
1880
1928
  }
1881
1929
  _measureComment(comment) {
1882
1930
  const widthLimit = getConfig(config.CommentStageSize, false)[comment.full ? "fullWidth" : "width"];
1931
+ if (!typeGuard.internal.MeasureInput(comment))
1932
+ throw new TypeGuardError();
1883
1933
  const measureResult = measure(comment, this.context);
1884
1934
  if (comment.loc !== "naka" && measureResult.width > widthLimit) {
1885
1935
  return this._processResizeX(comment, measureResult.width);
@@ -1893,9 +1943,11 @@
1893
1943
  const scale = widthLimit / width;
1894
1944
  comment.resizedX = true;
1895
1945
  let _comment = { ...comment };
1896
- _comment.charSize = (_comment.charSize || 0) * scale;
1897
- _comment.lineHeight = (_comment.lineHeight || 0) * scale;
1946
+ _comment.charSize = (_comment.charSize ?? 0) * scale;
1947
+ _comment.lineHeight = (_comment.lineHeight ?? 0) * scale;
1898
1948
  _comment.fontSize = _comment.charSize * 0.8;
1949
+ if (!typeGuard.internal.MeasureInput(_comment))
1950
+ throw new TypeGuardError();
1899
1951
  let result = measure(_comment, this.context);
1900
1952
  if (result.width > widthLimit) {
1901
1953
  while (result.width >= widthLimit) {
@@ -1919,7 +1971,7 @@
1919
1971
  _comment = lastComment;
1920
1972
  }
1921
1973
  if (comment.resizedY) {
1922
- const scale = (_comment.charSize || 0) / (comment.charSize || 0);
1974
+ const scale = (_comment.charSize ?? 0) / (comment.charSize ?? 0);
1923
1975
  comment.charSize = scale * charSize;
1924
1976
  comment.lineHeight = scale * lineHeight;
1925
1977
  }
@@ -1927,7 +1979,9 @@
1927
1979
  comment.charSize = _comment.charSize;
1928
1980
  comment.lineHeight = _comment.lineHeight;
1929
1981
  }
1930
- comment.fontSize = (comment.charSize || 0) * 0.8;
1982
+ comment.fontSize = (comment.charSize ?? 0) * 0.8;
1983
+ if (!typeGuard.internal.MeasureInput(comment))
1984
+ throw new TypeGuardError();
1931
1985
  return measure(comment, this.context);
1932
1986
  }
1933
1987
  _drawCollision(posX, posY, showCollision) {
@@ -1937,11 +1991,12 @@
1937
1991
  this.context.strokeStyle = "rgba(0,255,255,1)";
1938
1992
  this.context.strokeRect(posX, posY, this.comment.width, this.comment.height);
1939
1993
  for (let i = 0, n = this.comment.lineCount; i < n; i++) {
1994
+ if (!typeGuard.internal.HTML5Fonts(this.comment.font))
1995
+ throw new TypeGuardError();
1940
1996
  const linePosY = (this.comment.lineHeight * (i + 1) +
1941
1997
  (this.comment.charSize - this.comment.lineHeight) / 2 +
1942
1998
  this.comment.lineHeight * -0.16 +
1943
- (config.fonts[this.comment.font]?.offset ||
1944
- 0)) *
1999
+ (config.fonts[this.comment.font]?.offset || 0)) *
1945
2000
  scale;
1946
2001
  this.context.strokeStyle = "rgba(255,255,0,0.5)";
1947
2002
  this.context.strokeRect(posX, posY + linePosY, this.comment.width, this.comment.fontSize * -1 * scale);
@@ -1969,6 +2024,8 @@
1969
2024
  (this.comment.layer === -1 ? options.scale : 1);
1970
2025
  context.scale(drawScale, drawScale);
1971
2026
  let lineCount = 0;
2027
+ if (!typeGuard.internal.HTML5Fonts(this.comment.font))
2028
+ throw new TypeGuardError();
1972
2029
  const offsetY = (this.comment.charSize - this.comment.lineHeight) / 2 +
1973
2030
  this.comment.lineHeight * -0.16 +
1974
2031
  (config.fonts[this.comment.font]?.offset || 0);
@@ -2484,16 +2541,16 @@
2484
2541
  return data_;
2485
2542
  };
2486
2543
  const fromFormatted = (data) => {
2487
- const tmpData = data;
2488
- if (!typeGuard.formatted.comments(data)) {
2489
- for (const item of tmpData) {
2490
- item.layer = -1;
2491
- item.user_id = 0;
2492
- if (!item.date_usec)
2493
- item.date_usec = 0;
2544
+ return data.map((comment) => {
2545
+ if (typeGuard.formatted.legacyComment(comment)) {
2546
+ return {
2547
+ ...comment,
2548
+ layer: -1,
2549
+ user_id: 0,
2550
+ };
2494
2551
  }
2495
- }
2496
- return tmpData;
2552
+ return comment;
2553
+ });
2497
2554
  };
2498
2555
  const fromLegacy = (data) => {
2499
2556
  const data_ = [], userList = [];
@@ -2760,10 +2817,12 @@
2760
2817
  this.showCommentCount = options.showCommentCount;
2761
2818
  this.enableLegacyPiP = options.enableLegacyPiP;
2762
2819
  this.timeline = {};
2763
- this.collision = ["ue", "shita", "right", "left"].reduce((pv, value) => {
2764
- pv[value] = [];
2765
- return pv;
2766
- }, {});
2820
+ this.collision = {
2821
+ ue: [],
2822
+ shita: [],
2823
+ left: [],
2824
+ right: [],
2825
+ };
2767
2826
  this.lastVpos = -1;
2768
2827
  this.preRendering(parsedData);
2769
2828
  logger(`constructor complete: ${performance.now() - constructorStart}ms`);
@@ -2782,7 +2841,11 @@
2782
2841
  const plugins = [];
2783
2842
  for (const plugin of config.plugins) {
2784
2843
  try {
2785
- plugins.push(new plugin(this.canvas, instances));
2844
+ const canvas = generateCanvas();
2845
+ plugins.push({
2846
+ canvas,
2847
+ instance: new plugin(canvas, instances),
2848
+ });
2786
2849
  }
2787
2850
  catch (e) {
2788
2851
  console.error("Failed to init plugin");
@@ -2831,7 +2894,7 @@
2831
2894
  }, []);
2832
2895
  for (const plugin of plugins) {
2833
2896
  try {
2834
- plugin.addComments(comments);
2897
+ plugin.instance.addComments(comments);
2835
2898
  }
2836
2899
  catch (e) {
2837
2900
  console.error("Failed to add comments");
@@ -2871,7 +2934,8 @@
2871
2934
  this._drawComments(timelineRange, vpos);
2872
2935
  for (const plugin of plugins) {
2873
2936
  try {
2874
- plugin.draw(vpos);
2937
+ plugin.instance.draw(vpos);
2938
+ this.context.drawImage(plugin.canvas, 0, 0);
2875
2939
  }
2876
2940
  catch (e) {
2877
2941
  console.error(`Failed to draw comments`);
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@xpadev-net/niconicomments",
3
- "version": "0.2.55",
3
+ "version": "0.2.56",
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",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/xpadev-net/niconicomments.git"
9
+ "url": "https://github.com/xpadev-net/niconicomments.git"
10
10
  },
11
11
  "keywords": [
12
12
  "canvas",
@@ -27,35 +27,35 @@
27
27
  "homepage": "https://xpadev-net.github.io/niconicomments/",
28
28
  "license": "MIT",
29
29
  "devDependencies": {
30
- "@babel/core": "^7.21.8",
31
- "@babel/preset-env": "^7.21.5",
32
- "@playwright/test": "^1.33.0",
30
+ "@babel/core": "^7.22.17",
31
+ "@babel/preset-env": "^7.22.15",
32
+ "@playwright/test": "^1.37.1",
33
33
  "@rollup/plugin-babel": "^6.0.3",
34
- "@rollup/plugin-commonjs": "^25.0.0",
34
+ "@rollup/plugin-commonjs": "^25.0.4",
35
35
  "@rollup/plugin-json": "^6.0.0",
36
- "@rollup/plugin-node-resolve": "^15.0.2",
37
- "@rollup/plugin-typescript": "^11.1.1",
38
- "@types/node": "^20.2.1",
39
- "@typescript-eslint/eslint-plugin": "^5.59.6",
40
- "@typescript-eslint/parser": "^5.59.6",
41
- "concurrently": "^8.0.1",
36
+ "@rollup/plugin-node-resolve": "^15.2.1",
37
+ "@rollup/plugin-typescript": "^11.1.3",
38
+ "@types/node": "^20.6.0",
39
+ "@typescript-eslint/eslint-plugin": "^6.6.0",
40
+ "@typescript-eslint/parser": "^6.6.0",
41
+ "concurrently": "^8.2.1",
42
42
  "copyfiles": "^2.4.1",
43
- "eslint": "^8.40.0",
44
- "eslint-config-prettier": "^8.8.0",
45
- "eslint-plugin-jsdoc": "^44.2.4",
43
+ "eslint": "^8.49.0",
44
+ "eslint-config-prettier": "^9.0.0",
45
+ "eslint-plugin-jsdoc": "^46.6.0",
46
46
  "eslint-plugin-simple-import-sort": "^10.0.0",
47
47
  "husky": "^8.0.3",
48
- "lint-staged": "^13.2.2",
48
+ "lint-staged": "^14.0.1",
49
49
  "lite-server": "^2.6.1",
50
- "prettier": "2.8.8",
50
+ "prettier": "^3.0.3",
51
51
  "rimraf": "^5.0.1",
52
- "rollup": "^3.22.0",
53
- "rollup-plugin-dts": "^5.3.0",
52
+ "rollup": "^3.29.1",
53
+ "rollup-plugin-dts": "^6.0.2",
54
54
  "rollup-plugin-typescript-paths": "^1.4.0",
55
- "tslib": "^2.5.2",
56
- "typedoc": "^0.24.7",
57
- "typedoc-plugin-missing-exports": "^1.0.0",
58
- "typescript": "^5.0.4"
55
+ "tslib": "^2.6.2",
56
+ "typedoc": "^0.25.1",
57
+ "typedoc-plugin-missing-exports": "^2.1.0",
58
+ "typescript": "^5.2.2"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "npx rimraf dist&&npm run build:ts&&npm run build:dts",