@xpadev-net/niconicomments 0.2.26 → 0.2.28

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 (5) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +42 -42
  3. package/dist/bundle.d.ts +683 -367
  4. package/dist/bundle.js +2767 -1507
  5. package/package.json +61 -61
package/dist/bundle.d.ts CHANGED
@@ -1,368 +1,684 @@
1
- declare const colors: {
2
- [key: string]: string;
3
- };
4
- declare const commentYPaddingTop = 0.08;
5
- declare const commentYMarginBottom = 0.24;
6
- declare const fontSize: typeFontSize;
7
- declare const lineHeight: typeFontSize;
8
- declare const doubleResizeMaxWidth: typeDoubleResizeMaxWidth;
9
- declare const defaultOptions: Options;
10
- declare const fpsInterval = 500;
11
- declare const cacheAge = 2000;
12
- declare const canvasWidth = 1920;
13
- declare const canvasHeight = 1080;
14
- declare const commentDrawRange = 1450;
15
- declare const commentDrawPadding: number;
16
- declare const collisionRange: {
17
- left: number;
18
- right: number;
19
- };
20
- declare const sameCARange = 3600;
21
- declare const sameCAGap = 100;
22
- declare const sameCAMinScore = 10;
23
-
24
- //# sourceMappingURL=definition.d.ts.map
25
- type inputFormatType =
26
- | "niconicome"
27
- | "formatted"
28
- | "legacy"
29
- | "legacyOwner"
30
- | "owner"
31
- | "v1"
32
- | "default";
33
- type InitOptions = {
34
- useLegacy?: boolean;
35
- formatted?: boolean;
36
- format?: inputFormatType;
37
- video?: HTMLVideoElement | undefined;
38
- showCollision?: boolean;
39
- showFPS?: boolean;
40
- showCommentCount?: boolean;
41
- drawAllImageOnLoad?: boolean;
42
- debug?: boolean;
43
- enableLegacyPiP?: boolean;
44
- keepCA?: boolean;
45
- };
46
- type Options = {
47
- useLegacy: boolean;
48
- formatted: boolean;
49
- format: inputFormatType;
50
- video: HTMLVideoElement | undefined;
51
- showCollision: boolean;
52
- showFPS: boolean;
53
- showCommentCount: boolean;
54
- drawAllImageOnLoad: boolean;
55
- debug: boolean;
56
- enableLegacyPiP: boolean;
57
- keepCA: boolean;
58
- };
59
- type rawApiResponse = {
60
- [key: string]: apiPing | apiThread | apiLeaf | apiGlobalNumRes | apiChat;
61
- };
62
- type apiPing = {
63
- content: string;
64
- };
65
- type apiThread = {
66
- resultcode: number;
67
- thread: string;
68
- server_time: number;
69
- ticket: string;
70
- revision: number;
71
- };
72
- type apiLeaf = {
73
- thread: string;
74
- count: number;
75
- };
76
- type apiGlobalNumRes = {
77
- thread: string;
78
- num_res: number;
79
- };
80
- type apiChat = {
81
- thread: string;
82
- no: number;
83
- vpos: number;
84
- date: number;
85
- date_usec: number;
86
- nicoru: number;
87
- premium: number;
88
- anonymity: number;
89
- user_id: string;
90
- mail: string;
91
- content: string;
92
- deleted: number;
93
- };
94
- type formattedComment = {
95
- id: number;
96
- vpos: number;
97
- content: string;
98
- date: number;
99
- date_usec: number;
100
- owner: boolean;
101
- premium: boolean;
102
- mail: string[];
103
- user_id: number;
104
- layer: number;
105
- };
106
- type formattedLegacyComment = {
107
- id: number;
108
- vpos: number;
109
- content: string;
110
- date: number;
111
- date_usec: number;
112
- owner: boolean;
113
- premium: boolean;
114
- mail: string[];
115
- };
116
- type formattedCommentWithFont = formattedComment & {
117
- loc: commentLoc;
118
- size: commentSize;
119
- fontSize: number;
120
- font: commentFont;
121
- color: string;
122
- full: boolean;
123
- ender: boolean;
124
- _live: boolean;
125
- long: number;
126
- invisible: boolean;
127
- };
128
- type formattedCommentWithSize = formattedCommentWithFont & {
129
- height: number;
130
- width: number;
131
- width_max: number;
132
- width_min: number;
133
- lineHeight: number;
134
- };
135
- type parsedComment = formattedCommentWithSize & {
136
- posY: number;
137
- image?: HTMLCanvasElement | boolean;
138
- };
139
- type groupedResult = formattedCommentWithFont & {
140
- index: number;
141
- };
142
- type groupedComments = {
143
- [key in commentFont]: { [key: string]: groupedResult[] };
144
- };
145
- type commentFont = "defont" | "mincho" | "gothic";
146
- type commentSize = "big" | "medium" | "small";
147
- type commentLoc = "ue" | "naka" | "shita";
148
- type collision = { [key in collisionPos]: collisionItem };
149
- type collisionPos = "ue" | "shita" | "right" | "left";
150
- type collisionItem = { [p: number]: number[] };
151
- type nicoScript = {
152
- reverse: nicoScriptReverse[];
153
- ban: nicoScriptBan[];
154
- default: nicoScriptDefault[];
155
- replace: nicoScriptReplace[];
156
- };
157
- type nicoScriptReverse = {
158
- target: nicoScriptReverseTarget;
159
- start: number;
160
- end: number;
161
- };
162
- type nicoScriptReverseTarget = "コメ" | "投コメ" | "全";
163
- type nicoScriptReplace = {
164
- start: number;
165
- long: number | undefined;
166
- keyword: string;
167
- replace: string;
168
- range: nicoScriptReplaceRange;
169
- target: nicoScriptReplaceTarget;
170
- condition: nicoScriptReplaceCondition;
171
- color: string | undefined;
172
- size: commentSize | undefined;
173
- font: commentFont | undefined;
174
- loc: commentLoc | undefined;
175
- no: number;
176
- };
177
- type nicoScriptReplaceRange = "単" | "全";
178
- type nicoScriptReplaceTarget = "コメ" | "投コメ" | "全" | "含まない" | "含む";
179
- type nicoScriptReplaceCondition = "完全一致" | "部分一致";
180
- type nicoScriptBan = {
181
- start: number;
182
- end: number;
183
- };
184
- type nicoScriptDefault = {
185
- start: number;
186
- long: number | undefined;
187
- color: string | undefined;
188
- size: commentSize | undefined;
189
- font: commentFont | undefined;
190
- loc: commentLoc | undefined;
191
- };
192
- type measureTextResult = {
193
- width: number;
194
- width_max: number;
195
- width_min: number;
196
- height: number;
197
- resized: boolean;
198
- fontSize: number;
199
- lineHeight: number;
200
- };
201
- type parsedCommand = {
202
- loc: commentLoc | undefined;
203
- size: commentSize | undefined;
204
- fontSize: number | undefined;
205
- color: string | undefined;
206
- font: commentFont | undefined;
207
- full: boolean;
208
- ender: boolean;
209
- _live: boolean;
210
- invisible: boolean;
211
- long: number | undefined;
212
- };
213
- type typeFontSize = {
214
- [key in commentSize]: {
215
- default: number;
216
- resized: number;
217
- };
218
- };
219
- type typeDoubleResizeMaxWidth = {
220
- [key in "full" | "normal"]: {
221
- legacy: number;
222
- default: number;
223
- };
224
- };
225
- type v1Thread = {
226
- id: string;
227
- fork: string;
228
- commentCount: number;
229
- comments: { [key: string]: v1Comment };
230
- };
231
- type v1Comment = {
232
- id: string;
233
- no: number;
234
- vposMs: number;
235
- body: string;
236
- commands: string[];
237
- userId: string;
238
- isPremium: boolean;
239
- score: number;
240
- postedAt: string;
241
- nicoruCount: number;
242
- nicoruId: undefined;
243
- source: string;
244
- isMyPost: boolean;
245
- };
246
- type ownerComment = {
247
- time: string;
248
- command: string;
249
- comment: string;
250
- };
251
-
252
- declare const convert2formattedComment: (data: unknown, type: inputFormatType) => formattedComment[];
253
-
254
- //# sourceMappingURL=inputParser.d.ts.map
255
- declare class NiconiComments {
256
- enableLegacyPiP: boolean;
257
- showCollision: boolean;
258
- showFPS: boolean;
259
- showCommentCount: boolean;
260
- video: HTMLVideoElement | undefined;
261
- private data;
262
- private fps;
263
- private fpsCount;
264
- private lastVpos;
265
- private readonly cacheIndex;
266
- private readonly canvas;
267
- private readonly collision;
268
- private readonly context;
269
- private readonly keepCA;
270
- private readonly nicoScripts;
271
- private readonly timeline;
272
- private readonly useLegacy;
273
- constructor(canvas: HTMLCanvasElement, data: (rawApiResponse | formattedComment)[], initOptions?: InitOptions);
274
- preRendering(rawData: formattedComment[], drawAll: boolean): void;
275
- getFont(parsedData: formattedComment[]): formattedCommentWithFont[];
276
- getCommentSize(parsedData: formattedCommentWithFont[]): formattedCommentWithSize[];
277
- getCommentPos(data: parsedComment[]): parsedComment[];
278
- sortComment(parsedData: parsedComment[]): parsedComment[];
279
- measureText(comment: {
280
- content: string;
281
- resized?: boolean;
282
- ender: boolean;
283
- size: commentSize;
284
- fontSize: number;
285
- resizedY?: boolean;
286
- resizedX?: boolean;
287
- font: commentFont;
288
- loc: commentLoc;
289
- full: boolean;
290
- lineHeight?: number;
291
- }): measureTextResult;
292
- drawText(comment: parsedComment, vpos: number): void;
293
- getTextImage(i: number, preRendering?: boolean): void;
294
- parseCommand(comment: formattedComment): parsedCommand;
295
- parseCommandAndNicoscript(comment: formattedComment): formattedCommentWithFont;
296
- drawCanvas(vpos: number, forceRendering?: boolean): void;
297
- clear(): void;
298
- }
299
-
300
- //# sourceMappingURL=main.d.ts.map
301
- declare const typeGuard: {
302
- formatted: {
303
- comment: (i: unknown) => i is formattedComment;
304
- comments: (i: unknown) => i is formattedComment[];
305
- legacyComment: (i: unknown) => i is formattedLegacyComment;
306
- legacyComments: (i: unknown) => i is formattedLegacyComment[];
307
- };
308
- legacy: {
309
- rawApiResponses: (i: unknown) => i is rawApiResponse[];
310
- apiChat: (i: unknown) => i is apiChat;
311
- apiGlobalNumRes: (i: unknown) => i is apiGlobalNumRes;
312
- apiLeaf: (i: unknown) => i is apiLeaf;
313
- apiPing: (i: unknown) => i is apiPing;
314
- apiThread: (i: unknown) => i is apiThread;
315
- };
316
- niconicome: {
317
- xmlDocument: (i: unknown) => i is XMLDocument;
318
- };
319
- legacyOwner: {
320
- comments: (i: unknown) => i is string;
321
- };
322
- owner: {
323
- comment: (i: unknown) => i is ownerComment;
324
- comments: (i: unknown) => i is ownerComment[];
325
- };
326
- v1: {
327
- comment: (i: unknown) => i is apiThread;
328
- thread: (i: unknown) => i is v1Thread;
329
- threads: (i: unknown) => i is v1Thread[];
330
- };
331
- nicoScript: {
332
- range: {
333
- target: (i: unknown) => i is nicoScriptReverseTarget;
334
- };
335
- replace: {
336
- range: (i: unknown) => i is nicoScriptReplaceRange;
337
- target: (i: unknown) => i is nicoScriptReplaceTarget;
338
- condition: (i: unknown) => i is nicoScriptReplaceCondition;
339
- };
340
- };
341
- comment: {
342
- font: (i: unknown) => i is commentFont;
343
- loc: (i: unknown) => i is commentLoc;
344
- size: (i: unknown) => i is commentSize;
345
- command: {
346
- key: (i: unknown) => i is "full" | "ender" | "_live" | "invisible";
347
- };
348
- };
349
- };
350
-
351
- //# sourceMappingURL=typeGuard.d.ts.map
352
- declare const groupBy: (array: formattedCommentWithFont[]) => groupedComments;
353
- declare const getPosY: (currentPos: number, targetComment: parsedComment, collision: number[] | undefined, data: parsedComment[]) => {
354
- currentPos: number;
355
- isChanged: boolean;
356
- isBreak: boolean;
357
- };
358
- declare const getPosX: (width: number, vpos: number, long: number) => number;
359
- declare const parseFont: (font: commentFont, size: string | number, useLegacy: boolean) => string;
360
- declare const arrayPush: (array: {
361
- [key: number]: number[];
362
- }, key: string | number, push: number) => void;
363
- declare const hex2rgb: (hex: string) => number[];
364
- declare const replaceAll: (string: string, target: string, replace: string) => string;
365
- declare const changeCALayer: (rawData: formattedComment[]) => formattedComment[];
366
-
367
- //# sourceMappingURL=util.d.ts.map
1
+ declare class FlashComment implements IComment {
2
+ private readonly context;
3
+ readonly comment: formattedCommentWithSize;
4
+ private readonly _globalScale;
5
+ private scale;
6
+ posY: number;
7
+ image?: HTMLCanvasElement | null;
8
+ constructor(comment: formattedComment, context: CanvasRenderingContext2D);
9
+ get invisible(): boolean;
10
+ get loc(): commentLoc;
11
+ get long(): number;
12
+ get vpos(): number;
13
+ get width(): number;
14
+ get height(): number;
15
+ get flash(): boolean;
16
+ get layer(): number;
17
+ get owner(): boolean;
18
+ get mail(): string[];
19
+ get lineCount(): number;
20
+ parseCommand(comment: formattedComment): parsedCommand;
21
+ parseCommandAndNicoscript(comment: formattedComment): formattedCommentWithFont;
22
+ measureText(comment: measureTextInput): measureTextResult;
23
+ getCommentSize(parsedData: formattedCommentWithFont): formattedCommentWithSize;
24
+ draw(vpos: number, showCollision: boolean, debug: boolean): void;
25
+ getTextImage(): HTMLCanvasElement | null;
26
+ }
27
+
28
+
29
+ declare class HTML5Comment implements IComment {
30
+ private readonly context;
31
+ readonly comment: formattedCommentWithSize;
32
+ posY: number;
33
+ image?: HTMLCanvasElement | null;
34
+ constructor(comment: formattedComment, context: CanvasRenderingContext2D);
35
+ get invisible(): boolean;
36
+ get loc(): commentLoc;
37
+ get long(): number;
38
+ get vpos(): number;
39
+ get width(): number;
40
+ get height(): number;
41
+ get flash(): boolean;
42
+ get layer(): number;
43
+ get owner(): boolean;
44
+ get mail(): string[];
45
+ get lineCount(): number;
46
+ parseCommand(comment: formattedComment): parsedCommand;
47
+ parseCommandAndNicoscript(comment: formattedComment): formattedCommentWithFont;
48
+ measureText(comment: measureTextInput): measureTextResult;
49
+ getCommentSize(parsedData: formattedCommentWithFont): formattedCommentWithSize;
50
+ draw(vpos: number, showCollision: boolean, debug: boolean): void;
51
+ getTextImage(): HTMLCanvasElement | null;
52
+ }
53
+
54
+
55
+ declare let imageCache: {
56
+ [key: string]: {
57
+ image: HTMLCanvasElement;
58
+ timeout: number;
59
+ };
60
+ };
61
+ declare const resetImageCache: () => void;
62
+
63
+
64
+ declare const canvas: HTMLCanvasElement;
65
+ declare const context: CanvasRenderingContext2D;
66
+
67
+
68
+ declare let nicoScripts: nicoScript;
69
+ declare const resetNicoScripts: () => void;
70
+
71
+
72
+ declare const colors: {
73
+ white: string;
74
+ red: string;
75
+ pink: string;
76
+ orange: string;
77
+ yellow: string;
78
+ green: string;
79
+ cyan: string;
80
+ blue: string;
81
+ purple: string;
82
+ black: string;
83
+ white2: string;
84
+ niconicowhite: string;
85
+ red2: string;
86
+ truered: string;
87
+ pink2: string;
88
+ orange2: string;
89
+ passionorange: string;
90
+ yellow2: string;
91
+ madyellow: string;
92
+ green2: string;
93
+ elementalgreen: string;
94
+ cyan2: string;
95
+ blue2: string;
96
+ marinblue: string;
97
+ purple2: string;
98
+ nobleviolet: string;
99
+ black2: string;
100
+ };
101
+
102
+
103
+ declare const defaultConfig: Config;
104
+ declare const defaultOptions: Options;
105
+ declare let config: Config;
106
+ declare let options: Options;
107
+ declare const setConfig: (value: Config) => Config;
108
+ declare const setOptions: (value: Options) => Options;
109
+
110
+
111
+ declare const fontTemplates: {
112
+ arial: {
113
+ font: string;
114
+ offset: number;
115
+ weight: number;
116
+ };
117
+ gothic: {
118
+ font: string;
119
+ offset: number;
120
+ weight: number;
121
+ };
122
+ gulim: {
123
+ font: string;
124
+ offset: number;
125
+ weight: number;
126
+ };
127
+ mincho: {
128
+ font: string;
129
+ offset: number;
130
+ weight: number;
131
+ };
132
+ simsun: {
133
+ font: string;
134
+ offset: number;
135
+ weight: number;
136
+ };
137
+ macGothicPro6: {
138
+ font: string;
139
+ offset: number;
140
+ weight: number;
141
+ };
142
+ macGothicPro3: {
143
+ font: string;
144
+ offset: number;
145
+ weight: number;
146
+ };
147
+ macMincho: {
148
+ font: string;
149
+ offset: number;
150
+ weight: number;
151
+ };
152
+ macGothic1: {
153
+ font: string;
154
+ offset: number;
155
+ weight: number;
156
+ };
157
+ macGothic2: {
158
+ font: string;
159
+ offset: number;
160
+ weight: number;
161
+ };
162
+ sansSerif600: {
163
+ font: string;
164
+ offset: number;
165
+ weight: number;
166
+ };
167
+ sansSerif400: {
168
+ font: string;
169
+ offset: number;
170
+ weight: number;
171
+ };
172
+ serif: {
173
+ font: string;
174
+ offset: number;
175
+ weight: number;
176
+ };
177
+ };
178
+ declare const fonts: {
179
+ win7: {
180
+ defont: FontItem;
181
+ gothic: FontItem;
182
+ mincho: FontItem;
183
+ };
184
+ win8_1: {
185
+ defont: FontItem;
186
+ gothic: FontItem;
187
+ mincho: FontItem;
188
+ };
189
+ win: {
190
+ defont: FontItem;
191
+ gothic: FontItem;
192
+ mincho: FontItem;
193
+ };
194
+ mac10_9: {
195
+ defont: FontItem;
196
+ gothic: FontItem;
197
+ mincho: FontItem;
198
+ };
199
+ mac10_11: {
200
+ defont: FontItem;
201
+ gothic: FontItem;
202
+ mincho: FontItem;
203
+ };
204
+ mac: {
205
+ defont: FontItem;
206
+ gothic: FontItem;
207
+ mincho: FontItem;
208
+ };
209
+ other: {
210
+ defont: FontItem;
211
+ gothic: FontItem;
212
+ mincho: FontItem;
213
+ };
214
+ };
215
+
216
+
217
+ interface IComment {
218
+ comment: formattedCommentWithSize;
219
+ invisible: boolean;
220
+ loc: commentLoc;
221
+ width: number;
222
+ long: number;
223
+ height: number;
224
+ vpos: number;
225
+ flash: boolean;
226
+ posY: number;
227
+ owner: boolean;
228
+ layer: number;
229
+ mail: string[];
230
+ image?: HTMLCanvasElement | null;
231
+ getTextImage: (vpos: number) => void;
232
+ draw: (vpos: number, showCollision: boolean, isDebug: boolean) => void;
233
+ }
234
+
235
+ type configItem<T> = T | { html5: T; flash: T };
236
+ type configSizeItem<T> = { big: T; medium: T; small: T };
237
+ type configResizedItem<T> = { default: T; resized: T };
238
+
239
+ type commentStageSize = { width: number; fullWidth: number; height: number };
240
+
241
+ type flashCharList = {
242
+ [key in "simsunStrong" | "simsunWeak" | "gulim" | "gothic"]: string;
243
+ };
244
+ type flashMode = "xp" | "vista";
245
+ type flashScriptChar = {
246
+ [key in "super" | "sub"]: string;
247
+ };
248
+ type fontList = {
249
+ [key in "gulim" | "simsun"]: string;
250
+ };
251
+ type lineCounts = {
252
+ [key in "default" | "resized" | "doubleResized"]: configSizeItem<number>;
253
+ };
254
+ type typeDoubleResizeMaxWidth = {
255
+ [key in "full" | "normal"]: number;
256
+ };
257
+
258
+ type Config = {
259
+ cacheAge: number;
260
+ canvasHeight: number;
261
+ canvasWidth: number;
262
+ collisionRange: { [key in "left" | "right"]: number };
263
+ colors: { [key: string]: string };
264
+ commentDrawPadding: configItem<number>;
265
+ commentDrawRange: configItem<number>;
266
+ commentScale: configItem<number>;
267
+ commentStageSize: configItem<commentStageSize>;
268
+ commentYMarginBottom: configSizeItem<number>;
269
+ commentYOffset: configSizeItem<configResizedItem<number>>;
270
+ commentYPaddingTop: configSizeItem<number>;
271
+ contextFillLiveOpacity: number;
272
+ contextLineWidth: number;
273
+ contextStrokeColor: string;
274
+ contextStrokeInversionColor: string;
275
+ contextStrokeOpacity: number;
276
+ doubleResizeMaxWidth: configItem<typeDoubleResizeMaxWidth>;
277
+ flashChar: flashCharList;
278
+ flashMode: flashMode;
279
+ flashScriptChar: flashScriptChar;
280
+ flashThreshold: number;
281
+ font: fontList;
282
+ fonts: platformFont;
283
+ fontSize: configItem<configSizeItem<configResizedItem<number>>>;
284
+ fpsInterval: number;
285
+ hiResCommentCorrection: number;
286
+ lineCounts: configItem<lineCounts>;
287
+ lineHeight: configItem<configSizeItem<configResizedItem<number>>>;
288
+ minFontSize: number;
289
+ sameCAGap: number;
290
+ sameCAMinScore: number;
291
+ sameCARange: number;
292
+ };
293
+
294
+ type ConfigNullable = Partial<Config>;
295
+
296
+ type platform =
297
+ | "win7"
298
+ | "win8_1"
299
+ | "win"
300
+ | "mac10_9"
301
+ | "mac10_11"
302
+ | "mac"
303
+ | "other";
304
+ type HTML5Fonts = "gothic" | "mincho" | "defont";
305
+ type FontItem = {
306
+ font: string;
307
+ offset: number;
308
+ weight: number;
309
+ };
310
+ type platformFont = {
311
+ [key in HTML5Fonts]: FontItem;
312
+ };
313
+
314
+ type formattedComment = {
315
+ id: number;
316
+ vpos: number;
317
+ content: string;
318
+ date: number;
319
+ date_usec: number;
320
+ owner: boolean;
321
+ premium: boolean;
322
+ mail: string[];
323
+ user_id: number;
324
+ layer: number;
325
+ };
326
+ type formattedLegacyComment = {
327
+ id: number;
328
+ vpos: number;
329
+ content: string;
330
+ date: number;
331
+ date_usec: number;
332
+ owner: boolean;
333
+ premium: boolean;
334
+ mail: string[];
335
+ };
336
+
337
+ type rawApiResponse = {
338
+ [key: string]: apiPing | apiThread | apiLeaf | apiGlobalNumRes | apiChat;
339
+ };
340
+ type apiPing = {
341
+ content: string;
342
+ };
343
+ type apiThread = {
344
+ resultcode: number;
345
+ thread: string;
346
+ server_time: number;
347
+ ticket: string;
348
+ revision: number;
349
+ };
350
+ type apiLeaf = {
351
+ thread: string;
352
+ count: number;
353
+ };
354
+ type apiGlobalNumRes = {
355
+ thread: string;
356
+ num_res: number;
357
+ };
358
+ type apiChat = {
359
+ thread: string;
360
+ no: number;
361
+ vpos: number;
362
+ date: number;
363
+ date_usec: number;
364
+ nicoru: number;
365
+ premium: number;
366
+ anonymity: number;
367
+ user_id: string;
368
+ mail: string;
369
+ content: string;
370
+ deleted: number;
371
+ };
372
+
373
+ type ownerComment = {
374
+ time: string;
375
+ command: string;
376
+ comment: string;
377
+ };
378
+
379
+ type v1Thread = {
380
+ id: string;
381
+ fork: string;
382
+ commentCount: number;
383
+ comments: { [key: string]: v1Comment };
384
+ };
385
+ type v1Comment = {
386
+ id: string;
387
+ no: number;
388
+ vposMs: number;
389
+ body: string;
390
+ commands: string[];
391
+ userId: string;
392
+ isPremium: boolean;
393
+ score: number;
394
+ postedAt: string;
395
+ nicoruCount: number;
396
+ nicoruId: undefined;
397
+ source: string;
398
+ isMyPost: boolean;
399
+ };
400
+
401
+ type inputFormatType =
402
+ | "niconicome"
403
+ | "formatted"
404
+ | "legacy"
405
+ | "legacyOwner"
406
+ | "owner"
407
+ | "v1"
408
+ | "default";
409
+ type modeType = "default" | "html5" | "flash";
410
+ type Options = {
411
+ config: ConfigNullable;
412
+ debug: boolean;
413
+ enableLegacyPiP: boolean;
414
+ format: inputFormatType;
415
+ formatted: boolean;
416
+ keepCA: boolean;
417
+ mode: modeType;
418
+ scale: number;
419
+ showCollision: boolean;
420
+ showCommentCount: boolean;
421
+ showFPS: boolean;
422
+ useLegacy: boolean;
423
+ video: HTMLVideoElement | undefined;
424
+ };
425
+ type InitOptions = Partial<Options>;
426
+
427
+ type formattedCommentWithFont = {
428
+ id: number;
429
+ vpos: number;
430
+ date: number;
431
+ date_usec: number;
432
+ owner: boolean;
433
+ premium: boolean;
434
+ mail: string[];
435
+ user_id: number;
436
+ layer: number;
437
+ loc: commentLoc;
438
+ size: commentSize;
439
+ fontSize: number;
440
+ font: commentFont;
441
+ color: string;
442
+ full: boolean;
443
+ ender: boolean;
444
+ _live: boolean;
445
+ long: number;
446
+ invisible: boolean;
447
+ content: commentContentItem[];
448
+ flash: boolean;
449
+ lineCount: number;
450
+ lineOffset: number;
451
+ };
452
+ type formattedCommentWithSize = formattedCommentWithFont & {
453
+ height: number;
454
+ width: number;
455
+ lineHeight: number;
456
+ resized: boolean;
457
+ resizedX: boolean;
458
+ resizedY: boolean;
459
+ content: commentMeasuredContentItem[];
460
+ charSize: number;
461
+ };
462
+ type parsedComment = formattedCommentWithSize & {
463
+ posY: number;
464
+ image?: HTMLCanvasElement | boolean;
465
+ };
466
+ type commentContentItem = {
467
+ content: string;
468
+ font?: commentFlashFont;
469
+ width?: number[];
470
+ };
471
+ type commentMeasuredContentItem = commentContentItem & {
472
+ width: number[];
473
+ };
474
+ type commentContentIndex = {
475
+ index: number;
476
+ font: "gothic" | "gulim" | "simsunStrong" | "simsunWeak";
477
+ };
478
+ type commentFont = "defont" | "mincho" | "gothic" | "gulim" | "simsun";
479
+ type commentFlashFont = "defont" | "gulim" | "simsun";
480
+ type commentSize = "big" | "medium" | "small";
481
+ type commentLoc = "ue" | "naka" | "shita";
482
+ type collision = { [key in collisionPos]: collisionItem };
483
+ type collisionPos = "ue" | "shita" | "right" | "left";
484
+ type collisionItem = { [p: number]: number[] };
485
+ type nicoScript = {
486
+ reverse: nicoScriptReverse[];
487
+ ban: nicoScriptBan[];
488
+ default: nicoScriptDefault[];
489
+ replace: nicoScriptReplace[];
490
+ };
491
+ type nicoScriptReverse = {
492
+ target: nicoScriptReverseTarget;
493
+ start: number;
494
+ end: number;
495
+ };
496
+ type nicoScriptReverseTarget = "コメ" | "投コメ" | "全";
497
+ type nicoScriptReplace = {
498
+ start: number;
499
+ long: number | undefined;
500
+ keyword: string;
501
+ replace: string;
502
+ range: nicoScriptReplaceRange;
503
+ target: nicoScriptReplaceTarget;
504
+ condition: nicoScriptReplaceCondition;
505
+ color: string | undefined;
506
+ size: commentSize | undefined;
507
+ font: commentFont | undefined;
508
+ loc: commentLoc | undefined;
509
+ no: number;
510
+ };
511
+ type nicoScriptReplaceRange = "単" | "全";
512
+ type nicoScriptReplaceTarget = "コメ" | "投コメ" | "全" | "含まない" | "含む";
513
+ type nicoScriptReplaceCondition = "完全一致" | "部分一致";
514
+ type nicoScriptBan = {
515
+ start: number;
516
+ end: number;
517
+ };
518
+ type nicoScriptDefault = {
519
+ start: number;
520
+ long: number | undefined;
521
+ color: string | undefined;
522
+ size: commentSize | undefined;
523
+ font: commentFont | undefined;
524
+ loc: commentLoc | undefined;
525
+ };
526
+ type measureTextResult = {
527
+ width: number;
528
+ height: number;
529
+ resized: boolean;
530
+ resizedX: boolean;
531
+ resizedY: boolean;
532
+ fontSize: number;
533
+ lineHeight: number;
534
+ content: commentMeasuredContentItem[];
535
+ charSize: number;
536
+ };
537
+ type parsedCommand = {
538
+ loc: commentLoc | undefined;
539
+ size: commentSize | undefined;
540
+ fontSize: number | undefined;
541
+ color: string | undefined;
542
+ font: commentFont | undefined;
543
+ full: boolean;
544
+ ender: boolean;
545
+ _live: boolean;
546
+ invisible: boolean;
547
+ long: number | undefined;
548
+ };
549
+
550
+ type measureTextInput = {
551
+ content: commentContentItem[];
552
+ resized?: boolean;
553
+ ender: boolean;
554
+ size: commentSize;
555
+ fontSize: number;
556
+ resizedY?: boolean;
557
+ resizedX?: boolean;
558
+ font: commentFont;
559
+ loc: commentLoc;
560
+ full: boolean;
561
+ flash: boolean;
562
+ lineCount: number;
563
+ lineHeight?: number;
564
+ charSize?: number;
565
+ };
566
+
567
+ type measureInput = {
568
+ font: commentFont;
569
+ content: commentContentItem[];
570
+ lineHeight: number;
571
+ charSize: number;
572
+ lineCount: number;
573
+ };
574
+
575
+ declare const convert2formattedComment: (data: unknown, type: inputFormatType) => formattedComment[];
576
+
577
+
578
+ declare class NiconiComments {
579
+ enableLegacyPiP: boolean;
580
+ showCollision: boolean;
581
+ showFPS: boolean;
582
+ showCommentCount: boolean;
583
+ video: HTMLVideoElement | undefined;
584
+ private data;
585
+ private lastVpos;
586
+ private readonly canvas;
587
+ private readonly collision;
588
+ private readonly context;
589
+ private readonly timeline;
590
+ constructor(canvas: HTMLCanvasElement, data: (rawApiResponse | formattedComment)[], initOptions?: InitOptions);
591
+ preRendering(rawData: formattedComment[]): void;
592
+ getCommentPos(data: IComment[]): IComment[];
593
+ sortComment(parsedData: IComment[]): IComment[];
594
+ drawCanvas(vpos: number, forceRendering?: boolean): void;
595
+ clear(): void;
596
+ }
597
+
598
+
599
+ declare const getLineHeight: (fontSize: commentSize, isFlash: boolean, resized?: boolean) => number;
600
+ declare const getCharSize: (fontSize: commentSize, isFlash: boolean) => number;
601
+ declare const measure: (comment: measureInput) => {
602
+ height: number;
603
+ width: number;
604
+ lineWidth: number[];
605
+ itemWidth: number[][];
606
+ };
607
+ declare const getFontSizeAndScale: (charSize: number) => {
608
+ scale: number;
609
+ fontSize: number;
610
+ };
611
+
612
+
613
+ declare const typeGuard: {
614
+ formatted: {
615
+ comment: (i: unknown) => i is formattedComment;
616
+ comments: (i: unknown) => i is formattedComment[];
617
+ legacyComment: (i: unknown) => i is formattedLegacyComment;
618
+ legacyComments: (i: unknown) => i is formattedLegacyComment[];
619
+ };
620
+ legacy: {
621
+ rawApiResponses: (i: unknown) => i is rawApiResponse[];
622
+ apiChat: (i: unknown) => i is apiChat;
623
+ apiGlobalNumRes: (i: unknown) => i is apiGlobalNumRes;
624
+ apiLeaf: (i: unknown) => i is apiLeaf;
625
+ apiPing: (i: unknown) => i is apiPing;
626
+ apiThread: (i: unknown) => i is apiThread;
627
+ };
628
+ niconicome: {
629
+ xmlDocument: (i: unknown) => i is XMLDocument;
630
+ };
631
+ legacyOwner: {
632
+ comments: (i: unknown) => i is string;
633
+ };
634
+ owner: {
635
+ comment: (i: unknown) => i is ownerComment;
636
+ comments: (i: unknown) => i is ownerComment[];
637
+ };
638
+ v1: {
639
+ comment: (i: unknown) => i is apiThread;
640
+ thread: (i: unknown) => i is v1Thread;
641
+ threads: (i: unknown) => i is v1Thread[];
642
+ };
643
+ nicoScript: {
644
+ range: {
645
+ target: (i: unknown) => i is nicoScriptReverseTarget;
646
+ };
647
+ replace: {
648
+ range: (i: unknown) => i is nicoScriptReplaceRange;
649
+ target: (i: unknown) => i is nicoScriptReplaceTarget;
650
+ condition: (i: unknown) => i is nicoScriptReplaceCondition;
651
+ };
652
+ };
653
+ comment: {
654
+ font: (i: unknown) => i is commentFont;
655
+ loc: (i: unknown) => i is commentLoc;
656
+ size: (i: unknown) => i is commentSize;
657
+ command: {
658
+ key: (i: unknown) => i is "full" | "ender" | "_live" | "invisible";
659
+ };
660
+ };
661
+ config: {
662
+ initOptions: (item: unknown) => item is Partial<Options>;
663
+ };
664
+ };
665
+
666
+
667
+ declare const getPosY: (currentPos: number, targetComment: IComment, collision: number[] | undefined, data: IComment[]) => {
668
+ currentPos: number;
669
+ isChanged: boolean;
670
+ isBreak: boolean;
671
+ };
672
+ declare const getPosX: (width: number, vpos: number, long: number, isFlash: boolean) => number;
673
+ declare const parseFont: (font: commentFont, size: string | number) => string;
674
+ declare const arrayPush: (array: {
675
+ [key: number]: number[];
676
+ }, key: string | number, push: number) => void;
677
+ declare const hex2rgb: (hex: string) => number[];
678
+ declare const replaceAll: (string: string, target: string, replace: string) => string;
679
+ declare const changeCALayer: (rawData: formattedComment[]) => formattedComment[];
680
+ declare const getConfig: <T>(input: configItem<T>, isFlash?: boolean) => T;
681
+ declare const isFlashComment: (comment: formattedComment) => boolean;
682
+
683
+
368
684
  export default NiconiComments;