@xpadev-net/niconicomments 0.2.31 → 0.2.33
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/README.ja.md +41 -0
- package/README.md +13 -14
- package/dist/bundle.d.ts +100 -97
- package/dist/bundle.js +332 -524
- package/package.json +11 -11
package/README.ja.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# [niconicomments](https://xpadev.net/niconicomments/)
|
|
2
|
+
[](https://github.com/xpadev-net/niconicomments/blob/master/LICENSE)
|
|
3
|
+
|
|
4
|
+
[English](https://github.com/xpadev-net/niconicomments/blob/develop/README.md)
|
|
5
|
+
|
|
6
|
+
ニコニコ動画の公式プレイヤー互換の高パフォーマンスなコメント描画ライブラリ
|
|
7
|
+
High peformance High compatibility comment drawing library
|
|
8
|
+
Reference: https://xpadev-net.github.io/niconicomments/
|
|
9
|
+
Github: https://github.com/xpadev-net/niconicomments
|
|
10
|
+
npm: https://www.npmjs.com/package/@xpadev-net/niconicomments
|
|
11
|
+
|
|
12
|
+
## [重要]このライブラリを使用される方へ
|
|
13
|
+
ニコニコ運営が画面にコメントを流すアドオンを特許侵害だと騒ぎ立てて潰して回っているようです
|
|
14
|
+
このライブラリ本体は描画部分のみのため特許侵害に当たるとは考えていませんが、ニコニコ動画運営(とその近辺の人)に叩かれる可能性があります
|
|
15
|
+
(名前は出しませんがすでにいくつかのOSSに被害が出ています)
|
|
16
|
+
また、このライブラリを使用するかどうかに関わらず、リアルタイムでコメントを取得、画面を描画、コメントの投稿という一連の流れを実装した場合、ニコニコの特許を侵害する可能性があります
|
|
17
|
+
詳しくはこちら[ニコニコが保有する特許について](https://github.com/xpadev-net/niconicomments/blob/develop/ABOUT_PATENT.md)を参照してください
|
|
18
|
+
**※当ライブラリを削除する予定は一切ありません**
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
```html
|
|
22
|
+
<script src="https://cdn.jsdelivr.net/npm/@xpadev-net/niconicomments@latest/dist/bundle.min.js"></script>
|
|
23
|
+
```
|
|
24
|
+
or
|
|
25
|
+
```
|
|
26
|
+
npm i @xpadev-net/niconicomments
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Examples
|
|
30
|
+
```javascript
|
|
31
|
+
const canvas = document.getElementById("canvas");
|
|
32
|
+
const video = document.getElementById("video");
|
|
33
|
+
const req = await fetch("sample.json");
|
|
34
|
+
const res = await req.json();
|
|
35
|
+
const niconiComments = new NiconiComments(canvas, res);
|
|
36
|
+
//video.ontimeupdateを使用すると、呼び出し回数の関係でコメントカクつく
|
|
37
|
+
setInterval(() => niconiComments.drawCanvas(Math.floor(video.currentTime * 100)), 10);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Sample
|
|
41
|
+
[サンプル](https://xpadev-net.github.io/niconicomments/sample/)
|
package/README.md
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
# [niconicomments](https://xpadev.net/niconicomments/)
|
|
2
2
|
[](https://github.com/xpadev-net/niconicomments/blob/master/LICENSE)
|
|
3
|
-
[](https://lgtm.com/projects/g/xpadev-net/niconicomments/alerts/)
|
|
4
|
-
[](https://lgtm.com/projects/g/xpadev-net/niconicomments/context:javascript)
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
[日本語](https://github.com/xpadev-net/niconicomments/blob/develop/README.ja.md)
|
|
5
|
+
|
|
6
|
+
Comment rendering library that is somewhat compatible with the official Nico Nico Douga player
|
|
8
7
|
Reference: https://xpadev-net.github.io/niconicomments/
|
|
9
8
|
Github: https://github.com/xpadev-net/niconicomments
|
|
10
9
|
npm: https://www.npmjs.com/package/@xpadev-net/niconicomments
|
|
11
10
|
|
|
12
|
-
##
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
## For users who use this library for domestic use in Japan
|
|
12
|
+
This library may infringe on Dwango's patents depending on how it is used
|
|
13
|
+
Please carefully review the following applicable patents and case law before using this library with caution.
|
|
14
|
+
[JP,2006-333851](https://www.j-platpat.inpit.go.jp/c1800/PU/JP-2006-333851/7294651F33633E1EBF3DEC66FAE0ECAD878D19E1829C378FC81D26BBD0A4263B/10/en)
|
|
15
|
+
[JP,2010-267283](https://www.j-platpat.inpit.go.jp/c1800/PU/JP-4734471/9085C128B7ED7D57F6C2F09D9BE4FCB496E638331DB9EC7ADE1E3A44999A3878/15/en)
|
|
16
|
+
[JP,2018-202475](https://www.j-platpat.inpit.go.jp/c1800/PU/JP-6526304/D8AF77CFB92D96C785FEECBD690C53E2F9023F1739E7A5BBDAB588E2ECAC5316/15/en)
|
|
17
|
+
[2018: Case No. Heisei 28 (wa) 38565, Patent Infringement Injunction, etc. Patent Right Civil Litigation](https://www.courts.go.jp/app/files/hanrei_jp/073/088073_hanrei.pdf)
|
|
18
|
+
[2022: Heisei 30 (ne) 10077 Appeal for Patent Infringement Injunction, etc. Patent Right Civil Litigation](https://www.courts.go.jp/app/files/hanrei_jp/418/091418_hanrei.pdf)
|
|
19
19
|
|
|
20
20
|
## Installation
|
|
21
21
|
```html
|
|
@@ -33,10 +33,9 @@ const video = document.getElementById("video");
|
|
|
33
33
|
const req = await fetch("sample.json");
|
|
34
34
|
const res = await req.json();
|
|
35
35
|
const niconiComments = new NiconiComments(canvas, res);
|
|
36
|
-
//video.ontimeupdate
|
|
36
|
+
//If video.ontimeupdate is used, the comments will be choppy due to the small number of calls.
|
|
37
37
|
setInterval(() => niconiComments.drawCanvas(Math.floor(video.currentTime * 100)), 10);
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
## Sample
|
|
41
|
-
[
|
|
42
|
-
[CodePen](https://codepen.io/xpadev-net/pen/mdBdQmX)
|
|
41
|
+
[Sample](https://xpadev-net.github.io/niconicomments/sample/)
|
package/dist/bundle.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ declare class FlashComment implements IComment {
|
|
|
3
3
|
readonly comment: formattedCommentWithSize;
|
|
4
4
|
private readonly _globalScale;
|
|
5
5
|
private scale;
|
|
6
|
+
private scaleX;
|
|
6
7
|
posY: number;
|
|
7
8
|
image?: HTMLCanvasElement | null;
|
|
8
9
|
constructor(comment: formattedComment, context: CanvasRenderingContext2D);
|
|
@@ -43,7 +44,6 @@ declare class HTML5Comment implements IComment {
|
|
|
43
44
|
get owner(): boolean;
|
|
44
45
|
get mail(): string[];
|
|
45
46
|
get lineCount(): number;
|
|
46
|
-
parseCommand(comment: formattedComment): parsedCommand;
|
|
47
47
|
parseCommandAndNicoscript(comment: formattedComment): formattedCommentWithFont;
|
|
48
48
|
measureText(comment: measureTextInput): measureTextResult;
|
|
49
49
|
getCommentSize(parsedData: formattedCommentWithFont): formattedCommentWithSize;
|
|
@@ -216,66 +216,68 @@ declare const fonts: {
|
|
|
216
216
|
};
|
|
217
217
|
|
|
218
218
|
|
|
219
|
-
type configItem<T> = T | { html5: T; flash: T };
|
|
220
|
-
type configSizeItem<T> = { big: T; medium: T; small: T };
|
|
221
|
-
type configResizedItem<T> = { default: T; resized: T };
|
|
222
|
-
|
|
223
|
-
type commentStageSize = { width: number; fullWidth: number; height: number };
|
|
224
|
-
|
|
225
|
-
type flashCharList = {
|
|
226
|
-
[key in "simsunStrong" | "simsunWeak" | "gulim" | "gothic"]: string;
|
|
227
|
-
};
|
|
228
|
-
type flashMode = "xp" | "vista";
|
|
229
|
-
type flashScriptChar = {
|
|
230
|
-
[key in "super" | "sub"]: string;
|
|
231
|
-
};
|
|
232
|
-
type fontList = {
|
|
233
|
-
[key in "gulim" | "simsun"]: string;
|
|
234
|
-
};
|
|
235
|
-
type lineCounts = {
|
|
236
|
-
[key in "default" | "resized" | "doubleResized"]: configSizeItem<number>;
|
|
237
|
-
};
|
|
238
|
-
type typeDoubleResizeMaxWidth = {
|
|
239
|
-
[key in "full" | "normal"]: number;
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
type Config = {
|
|
243
|
-
cacheAge: number;
|
|
244
|
-
canvasHeight: number;
|
|
245
|
-
canvasWidth: number;
|
|
246
|
-
collisionRange: { [key in "left" | "right"]: number };
|
|
247
|
-
colors: { [key: string]: string };
|
|
248
|
-
commentDrawPadding:
|
|
249
|
-
commentDrawRange:
|
|
250
|
-
commentScale: configItem<number>;
|
|
251
|
-
commentStageSize: configItem<commentStageSize>;
|
|
252
|
-
commentYMarginBottom: configSizeItem<number>;
|
|
253
|
-
commentYOffset: configSizeItem<configResizedItem<number>>;
|
|
254
|
-
commentYPaddingTop: configResizedItem<number>;
|
|
255
|
-
contextFillLiveOpacity: number;
|
|
256
|
-
contextLineWidth: number;
|
|
257
|
-
contextStrokeColor: string;
|
|
258
|
-
contextStrokeInversionColor: string;
|
|
259
|
-
contextStrokeOpacity: number;
|
|
260
|
-
doubleResizeMaxWidth: configItem<typeDoubleResizeMaxWidth>;
|
|
261
|
-
flashChar: flashCharList;
|
|
262
|
-
flashMode: flashMode;
|
|
263
|
-
flashScriptChar: flashScriptChar;
|
|
264
|
-
flashThreshold: number;
|
|
265
|
-
font: fontList;
|
|
266
|
-
fonts: platformFont;
|
|
267
|
-
fontSize: configItem<configSizeItem<configResizedItem<number>>>;
|
|
268
|
-
fpsInterval: number;
|
|
269
|
-
hiResCommentCorrection: number;
|
|
270
|
-
lineCounts: configItem<lineCounts>;
|
|
271
|
-
lineHeight: configItem<configSizeItem<configResizedItem<number>>>;
|
|
272
|
-
minFontSize: number;
|
|
273
|
-
sameCAGap: number;
|
|
274
|
-
sameCAMinScore: number;
|
|
275
|
-
sameCARange: number;
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
219
|
+
type configItem<T> = T | { html5: T; flash: T };
|
|
220
|
+
type configSizeItem<T> = { big: T; medium: T; small: T };
|
|
221
|
+
type configResizedItem<T> = { default: T; resized: T };
|
|
222
|
+
|
|
223
|
+
type commentStageSize = { width: number; fullWidth: number; height: number };
|
|
224
|
+
|
|
225
|
+
type flashCharList = {
|
|
226
|
+
[key in "simsunStrong" | "simsunWeak" | "gulim" | "gothic"]: string;
|
|
227
|
+
};
|
|
228
|
+
type flashMode = "xp" | "vista";
|
|
229
|
+
type flashScriptChar = {
|
|
230
|
+
[key in "super" | "sub"]: string;
|
|
231
|
+
};
|
|
232
|
+
type fontList = {
|
|
233
|
+
[key in "gulim" | "simsun"]: string;
|
|
234
|
+
};
|
|
235
|
+
type lineCounts = {
|
|
236
|
+
[key in "default" | "resized" | "doubleResized"]: configSizeItem<number>;
|
|
237
|
+
};
|
|
238
|
+
type typeDoubleResizeMaxWidth = {
|
|
239
|
+
[key in "full" | "normal"]: number;
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
type Config = {
|
|
243
|
+
cacheAge: number;
|
|
244
|
+
canvasHeight: number;
|
|
245
|
+
canvasWidth: number;
|
|
246
|
+
collisionRange: { [key in "left" | "right"]: number };
|
|
247
|
+
colors: { [key: string]: string };
|
|
248
|
+
commentDrawPadding: number;
|
|
249
|
+
commentDrawRange: number;
|
|
250
|
+
commentScale: configItem<number>;
|
|
251
|
+
commentStageSize: configItem<commentStageSize>;
|
|
252
|
+
commentYMarginBottom: configSizeItem<number>;
|
|
253
|
+
commentYOffset: configSizeItem<configResizedItem<number>>;
|
|
254
|
+
commentYPaddingTop: configResizedItem<number>;
|
|
255
|
+
contextFillLiveOpacity: number;
|
|
256
|
+
contextLineWidth: number;
|
|
257
|
+
contextStrokeColor: string;
|
|
258
|
+
contextStrokeInversionColor: string;
|
|
259
|
+
contextStrokeOpacity: number;
|
|
260
|
+
doubleResizeMaxWidth: configItem<typeDoubleResizeMaxWidth>;
|
|
261
|
+
flashChar: flashCharList;
|
|
262
|
+
flashMode: flashMode;
|
|
263
|
+
flashScriptChar: flashScriptChar;
|
|
264
|
+
flashThreshold: number;
|
|
265
|
+
font: fontList;
|
|
266
|
+
fonts: platformFont;
|
|
267
|
+
fontSize: configItem<configSizeItem<configResizedItem<number>>>;
|
|
268
|
+
fpsInterval: number;
|
|
269
|
+
hiResCommentCorrection: number;
|
|
270
|
+
lineCounts: configItem<lineCounts>;
|
|
271
|
+
lineHeight: configItem<configSizeItem<configResizedItem<number>>>;
|
|
272
|
+
minFontSize: number;
|
|
273
|
+
sameCAGap: number;
|
|
274
|
+
sameCAMinScore: number;
|
|
275
|
+
sameCARange: number;
|
|
276
|
+
letterSpacing: number;
|
|
277
|
+
scriptCharOffset: number;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
type ConfigNullable = Partial<Config>;
|
|
279
281
|
|
|
280
282
|
type platform =
|
|
281
283
|
| "win7"
|
|
@@ -400,39 +402,39 @@ interface IComment {
|
|
|
400
402
|
draw: (vpos: number, showCollision: boolean, isDebug: boolean) => void;
|
|
401
403
|
}
|
|
402
404
|
|
|
403
|
-
type inputFormatType =
|
|
404
|
-
| "niconicome"
|
|
405
|
-
| "formatted"
|
|
406
|
-
| "legacy"
|
|
407
|
-
| "legacyOwner"
|
|
408
|
-
| "owner"
|
|
409
|
-
| "v1"
|
|
410
|
-
| "default";
|
|
411
|
-
type inputFormat =
|
|
412
|
-
| XMLDocument
|
|
413
|
-
| formattedComment[]
|
|
414
|
-
| formattedLegacyComment[]
|
|
415
|
-
| rawApiResponse[]
|
|
416
|
-
| ownerComment[]
|
|
417
|
-
| v1Thread[]
|
|
418
|
-
| string;
|
|
419
|
-
type modeType = "default" | "html5" | "flash";
|
|
420
|
-
type Options = {
|
|
421
|
-
config: ConfigNullable;
|
|
422
|
-
debug: boolean;
|
|
423
|
-
enableLegacyPiP: boolean;
|
|
424
|
-
format: inputFormatType;
|
|
425
|
-
formatted: boolean;
|
|
426
|
-
keepCA: boolean;
|
|
427
|
-
mode: modeType;
|
|
428
|
-
scale: number;
|
|
429
|
-
showCollision: boolean;
|
|
430
|
-
showCommentCount: boolean;
|
|
431
|
-
showFPS: boolean;
|
|
432
|
-
useLegacy: boolean;
|
|
433
|
-
video: HTMLVideoElement | undefined;
|
|
434
|
-
};
|
|
435
|
-
type InitOptions = Partial<Options>;
|
|
405
|
+
type inputFormatType =
|
|
406
|
+
| "niconicome"
|
|
407
|
+
| "formatted"
|
|
408
|
+
| "legacy"
|
|
409
|
+
| "legacyOwner"
|
|
410
|
+
| "owner"
|
|
411
|
+
| "v1"
|
|
412
|
+
| "default";
|
|
413
|
+
type inputFormat =
|
|
414
|
+
| XMLDocument
|
|
415
|
+
| formattedComment[]
|
|
416
|
+
| formattedLegacyComment[]
|
|
417
|
+
| rawApiResponse[]
|
|
418
|
+
| ownerComment[]
|
|
419
|
+
| v1Thread[]
|
|
420
|
+
| string;
|
|
421
|
+
type modeType = "default" | "html5" | "flash";
|
|
422
|
+
type Options = {
|
|
423
|
+
config: ConfigNullable;
|
|
424
|
+
debug: boolean;
|
|
425
|
+
enableLegacyPiP: boolean;
|
|
426
|
+
format: inputFormatType;
|
|
427
|
+
formatted: boolean;
|
|
428
|
+
keepCA: boolean;
|
|
429
|
+
mode: modeType;
|
|
430
|
+
scale: number;
|
|
431
|
+
showCollision: boolean;
|
|
432
|
+
showCommentCount: boolean;
|
|
433
|
+
showFPS: boolean;
|
|
434
|
+
useLegacy: boolean;
|
|
435
|
+
video: HTMLVideoElement | undefined;
|
|
436
|
+
};
|
|
437
|
+
type InitOptions = Partial<Options>;
|
|
436
438
|
|
|
437
439
|
type formattedCommentWithFont = {
|
|
438
440
|
id: number;
|
|
@@ -597,7 +599,7 @@ declare class NiconiComments {
|
|
|
597
599
|
private readonly collision;
|
|
598
600
|
private readonly context;
|
|
599
601
|
private readonly timeline;
|
|
600
|
-
constructor(canvas: HTMLCanvasElement, data: inputFormat
|
|
602
|
+
constructor(canvas: HTMLCanvasElement, data: inputFormat, initOptions?: InitOptions);
|
|
601
603
|
preRendering(rawData: formattedComment[]): void;
|
|
602
604
|
getCommentPos(data: IComment[]): IComment[];
|
|
603
605
|
sortComment(parsedData: IComment[]): IComment[];
|
|
@@ -646,7 +648,7 @@ declare const typeGuard: {
|
|
|
646
648
|
comments: (i: unknown) => i is ownerComment[];
|
|
647
649
|
};
|
|
648
650
|
v1: {
|
|
649
|
-
comment: (i: unknown) => i is
|
|
651
|
+
comment: (i: unknown) => i is v1Comment;
|
|
650
652
|
thread: (i: unknown) => i is v1Thread;
|
|
651
653
|
threads: (i: unknown) => i is v1Thread[];
|
|
652
654
|
};
|
|
@@ -679,7 +681,7 @@ declare const getPosY: (currentPos: number, targetComment: IComment, collision:
|
|
|
679
681
|
isChanged: boolean;
|
|
680
682
|
isBreak: boolean;
|
|
681
683
|
};
|
|
682
|
-
declare const getPosX: (width: number, vpos: number, long: number
|
|
684
|
+
declare const getPosX: (width: number, vpos: number, long: number) => number;
|
|
683
685
|
declare const parseFont: (font: commentFont, size: string | number) => string;
|
|
684
686
|
declare const arrayPush: (array: {
|
|
685
687
|
[key: number]: number[];
|
|
@@ -689,6 +691,7 @@ declare const replaceAll: (string: string, target: string, replace: string) => s
|
|
|
689
691
|
declare const changeCALayer: (rawData: formattedComment[]) => formattedComment[];
|
|
690
692
|
declare const getConfig: <T>(input: configItem<T>, isFlash?: boolean) => T;
|
|
691
693
|
declare const isFlashComment: (comment: formattedComment) => boolean;
|
|
694
|
+
declare const parseCommandAndNicoScript: (comment: formattedComment) => formattedCommentWithFont;
|
|
692
695
|
|
|
693
696
|
|
|
694
697
|
export default NiconiComments;
|