UNPKG

1.46 kBTypeScriptView Raw
1interface Comment {
2 text?: string;
3 /**
4 * @default rtl
5 */
6 mode?: 'ltr' | 'rtl' | 'top' | 'bottom';
7 /**
8 * Specified in seconds. Not required in live mode.
9 * @default media?.currentTime
10 */
11 time?: number;
12 style?: Partial<CSSStyleDeclaration> | CanvasRenderingContext2D;
13 /**
14 * A custom render to draw comment.
15 * When it exist, `text` and `style` will be ignored.
16 */
17 render?(): HTMLElement | HTMLCanvasElement;
18}
19
20interface DanmakuOption {
21 /**
22 * The stage to display comments will be appended to container.
23 */
24 container: HTMLElement;
25 /**
26 * If it's not provided, Danmaku will be in live mode.
27 */
28 media?: HTMLMediaElement;
29 /**
30 * Preseted comments, used in media mode
31 */
32 comments?: Comment[];
33 /**
34 * Canvas engine may more efficient than DOM however it costs more memory.
35 * @default dom
36 */
37 engine?: 'dom' | 'canvas';
38 /**
39 * The speed of comments in `ltr` and `rtl` mode.
40 */
41 speed?: number;
42}
43
44declare class Danmaku {
45 constructor(option: DanmakuOption);
46 /**
47 * The speed of comments in `ltr` and `rtl` mode.
48 */
49 get speed(): number;
50 set speed(s: number);
51 /**
52 * Destroy the instance and release memory.
53 */
54 destroy(): Danmaku;
55 emit(comment: Comment): Danmaku;
56 show(): Danmaku;
57 hide(): Danmaku;
58 /**
59 * Clear current stage.
60 */
61 clear(): Danmaku;
62 /**
63 * Do it when you resize container.
64 */
65 resize(): Danmaku;
66}
67
68export default Danmaku;