@dan-uni/dan-any 1.0.1 → 1.1.1

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 (106) hide show
  1. package/dist/browser/157.min.js +14 -0
  2. package/dist/browser/42.min.js +45 -0
  3. package/dist/{index.min.js → browser/index.min.js} +15 -50
  4. package/dist/browser/plugins/bili-dedupe.min.js +1 -0
  5. package/dist/browser/plugins/index.min.js +1 -0
  6. package/dist/browser/src/plugins/bili-dedupe/index.d.ts +5 -0
  7. package/dist/browser/src/plugins/index.d.ts +2 -0
  8. package/dist/browser/src/utils/dm-gen.test.d.ts +1 -0
  9. package/dist/node/157.js +14 -0
  10. package/dist/node/42.js +45 -0
  11. package/dist/{index.js → node/index.js} +4 -45
  12. package/dist/node/plugins/bili-dedupe.js +1 -0
  13. package/dist/node/plugins/index.js +1 -0
  14. package/dist/node/src/ass-gen/__tests__/canvas.test.d.ts +1 -0
  15. package/dist/node/src/ass-gen/__tests__/generate.test.d.ts +1 -0
  16. package/dist/node/src/ass-gen/ass/create.d.ts +4 -0
  17. package/dist/node/src/ass-gen/ass/dialogue.d.ts +16 -0
  18. package/dist/node/src/ass-gen/ass/event.d.ts +2 -0
  19. package/dist/node/src/ass-gen/ass/info.d.ts +8 -0
  20. package/dist/node/src/ass-gen/ass/raw.d.ts +14 -0
  21. package/dist/node/src/ass-gen/ass/style.d.ts +2 -0
  22. package/dist/node/src/ass-gen/config.d.ts +2 -0
  23. package/dist/node/src/ass-gen/index.d.ts +30 -0
  24. package/dist/node/src/ass-gen/types.d.ts +71 -0
  25. package/dist/node/src/ass-gen/util/color.d.ts +18 -0
  26. package/dist/node/src/ass-gen/util/danconvert.d.ts +5 -0
  27. package/dist/node/src/ass-gen/util/index.d.ts +4 -0
  28. package/dist/node/src/ass-gen/util/lang.d.ts +3 -0
  29. package/dist/node/src/ass-gen/util/layout.d.ts +4 -0
  30. package/dist/node/src/index.d.ts +255 -0
  31. package/dist/node/src/index.test.d.ts +1 -0
  32. package/dist/node/src/plugins/bili-dedupe/index.d.ts +5 -0
  33. package/dist/node/src/plugins/bili-dedupe/index.test.d.ts +1 -0
  34. package/dist/node/src/plugins/index.d.ts +2 -0
  35. package/dist/node/src/proto/gen/bili/dm_pb.d.ts +3426 -0
  36. package/dist/node/src/proto/gen/danuni_pb.d.ts +172 -0
  37. package/dist/node/src/utils/dm-gen.d.ts +309 -0
  38. package/dist/node/src/utils/dm-gen.test.d.ts +1 -0
  39. package/dist/node/src/utils/id-gen.d.ts +50 -0
  40. package/dist/node/src/utils/platform.d.ts +24 -0
  41. package/dist/{index.umd.min.js → umd/index.umd.min.js} +12 -6
  42. package/dist/umd/plugins/bili-dedupe.umd.min.js +79 -0
  43. package/dist/umd/plugins/index.umd.min.js +98 -0
  44. package/dist/umd/src/ass-gen/__tests__/canvas.test.d.ts +1 -0
  45. package/dist/umd/src/ass-gen/__tests__/generate.test.d.ts +1 -0
  46. package/dist/umd/src/ass-gen/ass/create.d.ts +4 -0
  47. package/dist/umd/src/ass-gen/ass/dialogue.d.ts +16 -0
  48. package/dist/umd/src/ass-gen/ass/event.d.ts +2 -0
  49. package/dist/umd/src/ass-gen/ass/info.d.ts +8 -0
  50. package/dist/umd/src/ass-gen/ass/raw.d.ts +14 -0
  51. package/dist/umd/src/ass-gen/ass/style.d.ts +2 -0
  52. package/dist/umd/src/ass-gen/config.d.ts +2 -0
  53. package/dist/umd/src/ass-gen/index.d.ts +30 -0
  54. package/dist/umd/src/ass-gen/types.d.ts +71 -0
  55. package/dist/umd/src/ass-gen/util/color.d.ts +18 -0
  56. package/dist/umd/src/ass-gen/util/danconvert.d.ts +5 -0
  57. package/dist/umd/src/ass-gen/util/index.d.ts +4 -0
  58. package/dist/umd/src/ass-gen/util/lang.d.ts +3 -0
  59. package/dist/umd/src/ass-gen/util/layout.d.ts +4 -0
  60. package/dist/umd/src/index.d.ts +255 -0
  61. package/dist/umd/src/index.test.d.ts +1 -0
  62. package/dist/umd/src/plugins/bili-dedupe/index.d.ts +5 -0
  63. package/dist/umd/src/plugins/bili-dedupe/index.test.d.ts +1 -0
  64. package/dist/umd/src/plugins/index.d.ts +2 -0
  65. package/dist/umd/src/proto/gen/bili/dm_pb.d.ts +3426 -0
  66. package/dist/umd/src/proto/gen/danuni_pb.d.ts +172 -0
  67. package/dist/umd/src/utils/dm-gen.d.ts +309 -0
  68. package/dist/umd/src/utils/dm-gen.test.d.ts +1 -0
  69. package/dist/umd/src/utils/id-gen.d.ts +50 -0
  70. package/dist/umd/src/utils/platform.d.ts +24 -0
  71. package/package.json +8 -8
  72. package/plugins/package.json +6 -0
  73. package/rslib.config.ts +10 -0
  74. package/src/plugins/bili-dedupe/index.test.ts +40 -0
  75. package/src/plugins/bili-dedupe/index.ts +19 -0
  76. package/src/plugins/index.ts +3 -0
  77. package/src/proto/gen/bili/dm_pb.ts +1 -1
  78. package/src/proto/gen/danuni_pb.ts +1 -1
  79. /package/dist/{index.min.js.LICENSE.txt → browser/index.min.js.LICENSE.txt} +0 -0
  80. /package/dist/{rslib-runtime.min.js → browser/rslib-runtime.min.js} +0 -0
  81. /package/dist/{src → browser/src}/ass-gen/__tests__/canvas.test.d.ts +0 -0
  82. /package/dist/{src → browser/src}/ass-gen/__tests__/generate.test.d.ts +0 -0
  83. /package/dist/{src → browser/src}/ass-gen/ass/create.d.ts +0 -0
  84. /package/dist/{src → browser/src}/ass-gen/ass/dialogue.d.ts +0 -0
  85. /package/dist/{src → browser/src}/ass-gen/ass/event.d.ts +0 -0
  86. /package/dist/{src → browser/src}/ass-gen/ass/info.d.ts +0 -0
  87. /package/dist/{src → browser/src}/ass-gen/ass/raw.d.ts +0 -0
  88. /package/dist/{src → browser/src}/ass-gen/ass/style.d.ts +0 -0
  89. /package/dist/{src → browser/src}/ass-gen/config.d.ts +0 -0
  90. /package/dist/{src → browser/src}/ass-gen/index.d.ts +0 -0
  91. /package/dist/{src → browser/src}/ass-gen/types.d.ts +0 -0
  92. /package/dist/{src → browser/src}/ass-gen/util/color.d.ts +0 -0
  93. /package/dist/{src → browser/src}/ass-gen/util/danconvert.d.ts +0 -0
  94. /package/dist/{src → browser/src}/ass-gen/util/index.d.ts +0 -0
  95. /package/dist/{src → browser/src}/ass-gen/util/lang.d.ts +0 -0
  96. /package/dist/{src → browser/src}/ass-gen/util/layout.d.ts +0 -0
  97. /package/dist/{src → browser/src}/index.d.ts +0 -0
  98. /package/dist/{src → browser/src}/index.test.d.ts +0 -0
  99. /package/dist/{src/utils/dm-gen.test.d.ts → browser/src/plugins/bili-dedupe/index.test.d.ts} +0 -0
  100. /package/dist/{src → browser/src}/proto/gen/bili/dm_pb.d.ts +0 -0
  101. /package/dist/{src → browser/src}/proto/gen/danuni_pb.d.ts +0 -0
  102. /package/dist/{src → browser/src}/utils/dm-gen.d.ts +0 -0
  103. /package/dist/{src → browser/src}/utils/id-gen.d.ts +0 -0
  104. /package/dist/{src → browser/src}/utils/platform.d.ts +0 -0
  105. /package/dist/{rslib-runtime.js → node/rslib-runtime.js} +0 -0
  106. /package/dist/{index.umd.min.js.LICENSE.txt → umd/index.umd.min.js.LICENSE.txt} +0 -0
@@ -0,0 +1,98 @@
1
+ (function(root, factory) {
2
+ if ('object' == typeof exports && 'object' == typeof module) module.exports = factory();
3
+ else if ('function' == typeof define && define.amd) define([], factory);
4
+ else if ('object' == typeof exports) exports["@dan-uni/dan-any"] = factory();
5
+ else root["@dan-uni/dan-any"] = factory();
6
+ })(globalThis, ()=>(()=>{
7
+ "use strict";
8
+ var __webpack_modules__ = {
9
+ "./src/plugins/bili-dedupe/index.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
10
+ __webpack_require__.d(__webpack_exports__, {
11
+ default: ()=>bili_dedupe
12
+ });
13
+ var platform_PlatformInfoSource = /*#__PURE__*/ function(PlatformInfoSource) {
14
+ PlatformInfoSource["Bangumi"] = "bgm";
15
+ PlatformInfoSource["TMDB"] = "tmdb";
16
+ return PlatformInfoSource;
17
+ }({});
18
+ const PlatformInfoSources = Object.values(platform_PlatformInfoSource);
19
+ var platform_PlatformVideoSource = /*#__PURE__*/ function(PlatformVideoSource) {
20
+ PlatformVideoSource["Acfun"] = "acfun";
21
+ PlatformVideoSource["Baha"] = "baha";
22
+ PlatformVideoSource["Bilibili"] = "bili";
23
+ PlatformVideoSource["BilibiliGlobal"] = "bglobal";
24
+ PlatformVideoSource["Iqiyi"] = "iqiyi";
25
+ PlatformVideoSource["Tencent"] = "tencent";
26
+ PlatformVideoSource["Youku"] = "youku";
27
+ return PlatformVideoSource;
28
+ }({});
29
+ const PlatformVideoSources = Object.values(platform_PlatformVideoSource);
30
+ var platform_PlatformDanmakuOnlySource = /*#__PURE__*/ function(PlatformDanmakuOnlySource) {
31
+ PlatformDanmakuOnlySource["DanDanPlay"] = "ddplay";
32
+ PlatformDanmakuOnlySource["TuCao"] = "tucao";
33
+ return PlatformDanmakuOnlySource;
34
+ }({});
35
+ const PlatformDanmakuOnlySources = Object.values(platform_PlatformDanmakuOnlySource);
36
+ const PlatformDanmakuSources = [
37
+ ...PlatformVideoSources,
38
+ ...PlatformDanmakuOnlySources
39
+ ];
40
+ [
41
+ ...PlatformInfoSources,
42
+ ...PlatformDanmakuSources
43
+ ];
44
+ function bili_dedupe(that) {
45
+ that.dans.forEach((d)=>{
46
+ if (d.platform !== platform_PlatformVideoSource.Bilibili) throw new Error('bili-dedupe: 仅支持B站(主站)的弹幕');
47
+ if (!d.extra.bili?.dmid) throw new Error('bili-dedupe: 弹幕缺少bili extra dmid字段');
48
+ });
49
+ const map = new Map();
50
+ that.dans.forEach((d)=>map.set(d.extra.bili.dmid, d));
51
+ that.dans = [
52
+ ...map.values()
53
+ ];
54
+ return that;
55
+ }
56
+ }
57
+ };
58
+ var __webpack_module_cache__ = {};
59
+ function __webpack_require__(moduleId) {
60
+ var cachedModule = __webpack_module_cache__[moduleId];
61
+ if (void 0 !== cachedModule) return cachedModule.exports;
62
+ var module1 = __webpack_module_cache__[moduleId] = {
63
+ exports: {}
64
+ };
65
+ __webpack_modules__[moduleId](module1, module1.exports, __webpack_require__);
66
+ return module1.exports;
67
+ }
68
+ (()=>{
69
+ __webpack_require__.d = (exports1, definition)=>{
70
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
71
+ enumerable: true,
72
+ get: definition[key]
73
+ });
74
+ };
75
+ })();
76
+ (()=>{
77
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
78
+ })();
79
+ (()=>{
80
+ __webpack_require__.r = (exports1)=>{
81
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
82
+ value: 'Module'
83
+ });
84
+ Object.defineProperty(exports1, '__esModule', {
85
+ value: true
86
+ });
87
+ };
88
+ })();
89
+ var __webpack_exports__ = {};
90
+ (()=>{
91
+ __webpack_require__.r(__webpack_exports__);
92
+ __webpack_require__.d(__webpack_exports__, {
93
+ bili_dedupe: ()=>_bili_dedupe__rspack_import_0["default"]
94
+ });
95
+ var _bili_dedupe__rspack_import_0 = __webpack_require__("./src/plugins/bili-dedupe/index.ts");
96
+ })();
97
+ return __webpack_exports__;
98
+ })());
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import type { UniPool } from '../..';
2
+ import type { Context, SubtitleStyle } from '../types';
3
+ import type { RawConfig } from './raw';
4
+ export declare const ass: (list: UniPool, rawList: UniPool, config: SubtitleStyle, context?: Context, rawConfig?: RawConfig) => string;
@@ -0,0 +1,16 @@
1
+ import type { RGB } from '../types';
2
+ import { DanmakuType } from '../types';
3
+ export declare const dialogue: (danmaku: {
4
+ type: (typeof DanmakuType)[keyof typeof DanmakuType];
5
+ color: RGB;
6
+ fontSizeType: number;
7
+ content: string;
8
+ time: number;
9
+ start: number;
10
+ end: number;
11
+ top: number;
12
+ left: number;
13
+ }, config: {
14
+ scrollTime: number;
15
+ fixTime: number;
16
+ }) => string;
@@ -0,0 +1,2 @@
1
+ import type { Danmaku, SubtitleStyle } from '../types';
2
+ export declare const event: (list: Danmaku[], config: SubtitleStyle) => string;
@@ -0,0 +1,8 @@
1
+ import type { Context } from '../types';
2
+ type ExtraInfo = Context;
3
+ type Resolution = {
4
+ playResX: number;
5
+ playResY: number;
6
+ };
7
+ export declare const info: ({ playResX, playResY }: Resolution, { filename, title }: ExtraInfo) => string;
8
+ export {};
@@ -0,0 +1,14 @@
1
+ import type { Context, Danmaku, SubtitleStyle } from '../types';
2
+ type compressType = 'brotli' | 'gzip';
3
+ type baseType = 'base64' | 'base18384';
4
+ export interface RawConfig {
5
+ compressType: compressType;
6
+ baseType: baseType;
7
+ }
8
+ export declare function raw(list: Danmaku[], config: SubtitleStyle, context: Context, compressType?: compressType, baseType?: baseType): string;
9
+ export declare function deRaw(ass: string): {
10
+ list: Danmaku[];
11
+ config: SubtitleStyle;
12
+ context: Context;
13
+ } | undefined;
14
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { SubtitleStyle } from '../types';
2
+ export declare const style: ({ fontName, fontSize, color: configColor, outlineColor, backColor, bold, outline, shadow, opacity, }: SubtitleStyle) => string;
@@ -0,0 +1,2 @@
1
+ import type { SubtitleStyle } from './types';
2
+ export declare const getConfig: (overrides?: {}) => SubtitleStyle;
@@ -0,0 +1,30 @@
1
+ import type { Options as UniPoolOptions } from '..';
2
+ import type { RawConfig } from './ass/raw';
3
+ import type { CanvasCtx, SubtitleStyle } from './types';
4
+ import { UniPool } from '..';
5
+ export { CanvasCtx };
6
+ export type Options = {
7
+ filename?: string;
8
+ title?: string;
9
+ substyle?: Partial<SubtitleStyle>;
10
+ raw?: RawConfig;
11
+ };
12
+ /**
13
+ * 使用bilibili弹幕(XMl)生成ASS字幕文件
14
+ * @param {string} danmaku XML弹幕文件内容
15
+ * @param {Options} options 杂项
16
+ * @returns {string} 返回ASS字幕文件内容
17
+ * @description 杂项相关
18
+ `filename`: 还原文件为XML时使用的默认文件名
19
+ `title`: ASS [Script Info] Title 项的值,显示于播放器字幕选择
20
+ `substyle`: ASS字幕样式
21
+ * @example ```ts
22
+ import fs from 'fs'
23
+ const filename = 'example.xml'
24
+ const xmlText = fs.readFileSync(filename, 'utf-8')
25
+ const assText = generateASS(xmlText, { filename, title: 'Quick Example' })
26
+ fs.writeFileSync(`${filename}.ass`, assText, 'utf-8')
27
+ ```
28
+ */
29
+ export declare function generateASS(danmaku: UniPool, options: Options, canvasCtx: CanvasCtx): string;
30
+ export declare function parseAssRawField(ass: string, options?: UniPoolOptions): UniPool;
@@ -0,0 +1,71 @@
1
+ import type { CanvasRenderingContext2D as NodeCRCtx2D } from 'canvas';
2
+ import type { UniDM } from '../utils/dm-gen';
3
+ /**
4
+ * 请根据您的使用环境提供一个 50x50 的 2D Canvas 上下文
5
+ * @example
6
+ * // Node.js + canvas
7
+ * import { createCanvas } from 'canvas'
8
+ * const canvas = createCanvas(50, 50)
9
+ * const ctx = canvas.getContext('2d')
10
+ * @example
11
+ * // Node.js + Fabric.js
12
+ * import { StaticCanvas } from 'fabric/node'
13
+ * const ctx = new StaticCanvas(null, { width: 50, height: 50 }).getContext()
14
+ * @example
15
+ * // Browser + Native Canvas
16
+ * const canvas = document.createElement('canvas')
17
+ * canvas.width = 50
18
+ * canvas.height = 50
19
+ * const ctx = canvas.getContext('2d')
20
+ * @example
21
+ * // Browser + Fabric.js
22
+ * import { Canvas } from 'fabric'
23
+ * const ctx = new Canvas('canvas', { width: 50, height: 50 }).getContext()
24
+ */
25
+ export type CanvasCtx = NodeCRCtx2D | CanvasRenderingContext2D;
26
+ export interface Context {
27
+ filename: string;
28
+ title: string;
29
+ }
30
+ export interface SubtitleStyle {
31
+ fontSize: number[];
32
+ fontName: string;
33
+ color: string;
34
+ outlineColor?: string;
35
+ backColor?: string;
36
+ outline: number;
37
+ shadow: number;
38
+ bold: boolean;
39
+ padding: number[];
40
+ playResX: number;
41
+ playResY: number;
42
+ scrollTime: number;
43
+ fixTime: number;
44
+ opacity: number;
45
+ bottomSpace: number;
46
+ includeRaw: boolean;
47
+ mergeIn: number;
48
+ }
49
+ export type RGB = {
50
+ r: number;
51
+ g: number;
52
+ b: number;
53
+ };
54
+ export declare const DanmakuType: {
55
+ SCROLL: number;
56
+ BOTTOM: number;
57
+ TOP: number;
58
+ };
59
+ export declare const FontSize: {
60
+ SMALL: number;
61
+ NORMAL: number;
62
+ LARGE: number;
63
+ };
64
+ export type Danmaku = {
65
+ time: number;
66
+ type: number;
67
+ fontSizeType: number;
68
+ color: RGB;
69
+ content: string;
70
+ extra: UniDM;
71
+ };
@@ -0,0 +1,18 @@
1
+ import type { RGB } from '../types';
2
+ export declare const hexColorToRGB: (hex: string) => {
3
+ r: number;
4
+ g: number;
5
+ b: number;
6
+ };
7
+ export declare const decimalColorToRGB: (decimal: number) => {
8
+ r: number;
9
+ g: number;
10
+ b: number;
11
+ };
12
+ export declare const formatColor: ({ r, g, b }: RGB, opacity?: number) => string;
13
+ export declare const getDecoratingColor: (color: RGB) => {
14
+ r: number;
15
+ g: number;
16
+ b: number;
17
+ };
18
+ export declare const isWhite: (color: RGB) => boolean;
@@ -0,0 +1,5 @@
1
+ import type { Options as UniPoolOptions } from '../..';
2
+ import type { Danmaku } from '../types';
3
+ import { UniPool } from '../..';
4
+ export declare function UniPool2DanmakuLists(UP: UniPool): Danmaku[];
5
+ export declare function DanmakuList2UniPool(d: Danmaku[], options?: UniPoolOptions): UniPool;
@@ -0,0 +1,4 @@
1
+ export { decimalColorToRGB, formatColor, getDecoratingColor, hexColorToRGB, isWhite, } from './color';
2
+ export { DanmakuList2UniPool, UniPool2DanmakuLists } from './danconvert';
3
+ export { arrayOfLength, assign, uniqueArray } from './lang';
4
+ export { layoutDanmaku } from './layout';
@@ -0,0 +1,3 @@
1
+ export declare const assign: <T extends object>(source: T, ...targets: Partial<T>[]) => T;
2
+ export declare const arrayOfLength: <T>(length: number, defaultValue: T) => T[];
3
+ export declare const uniqueArray: <T>(array: T[]) => T[];
@@ -0,0 +1,4 @@
1
+ import type { UniPool } from '../..';
2
+ import type { CanvasCtx, SubtitleStyle } from '../types';
3
+ export declare const measureTextWidthConstructor: (canvasContext: CanvasCtx) => (fontName: string, fontSize: number, bold: boolean, text: string) => number;
4
+ export declare const layoutDanmaku: (inputList: UniPool, config: SubtitleStyle, canvasCtx: CanvasCtx) => UniPool;
@@ -0,0 +1,255 @@
1
+ import 'reflect-metadata/lite';
2
+ import type { Options as AssGenOptions, CanvasCtx } from './ass-gen';
3
+ import type { CommandDm as DM_JSON_BiliCommandGrpc } from './proto/gen/bili/dm_pb';
4
+ import { UniDM } from './utils/dm-gen';
5
+ import * as UniDMTools from './utils/dm-gen';
6
+ import * as UniIDTools from './utils/id-gen';
7
+ import * as platform from './utils/platform';
8
+ interface DanUniConvertTip {
9
+ meassage: string;
10
+ version: string;
11
+ data?: string;
12
+ }
13
+ export interface DM_XML_Bili {
14
+ i: {
15
+ chatserver: string;
16
+ chatid: bigint;
17
+ mission: number;
18
+ maxlimit: number;
19
+ state: number;
20
+ real_name: number;
21
+ source: string;
22
+ d: {
23
+ '#text': string;
24
+ '@_p': string;
25
+ }[];
26
+ };
27
+ }
28
+ export interface DM_JSON_BiliUp {
29
+ /** 接口状态码,0 表示成功 */
30
+ code: number;
31
+ /** 文本形式的状态码,约定为字符串 "0" */
32
+ message: string;
33
+ /** TTL(time to live) 标识,本接口常量为 1 */
34
+ ttl: number;
35
+ data: {
36
+ /** 分页元信息 */
37
+ page: {
38
+ /** 当前页序号,从 1 开始 */
39
+ num: number;
40
+ /** 每页返回的弹幕条数 */
41
+ size: number;
42
+ /** 总页数 */
43
+ total: number;
44
+ };
45
+ result: {
46
+ /** 弹幕 ID,int64 */
47
+ id: bigint;
48
+ /** 弹幕 ID 字符串形式 */
49
+ id_str: string;
50
+ /** 弹幕类型:1 表示视频弹幕(当前接口恒为 1) */
51
+ type: number;
52
+ aid: bigint;
53
+ bvid: string;
54
+ oid: bigint;
55
+ mid: bigint;
56
+ /** 发送者 mid 的 CRC 哈希(正常接口里用的是这个,保护隐私) */
57
+ mid_hash: string;
58
+ /** 弹幕池 */
59
+ pool: number;
60
+ /** 属性位字符串,逗号分隔的数字列表,对应 attr 二进制位 */
61
+ attrs: string;
62
+ /** 弹幕出现时间,单位毫秒(注意,此处与protobuf接口保持一致,但xml中progress是秒) */
63
+ progress: number;
64
+ mode: number;
65
+ /** 弹幕内容, content */
66
+ msg: string;
67
+ state: number;
68
+ fontsize: number;
69
+ /** 弹幕颜色,需将16进制转化为普通弹幕的10进制,示例:"ffffff" */
70
+ color: string;
71
+ /** 发送时间戳,单位秒 */
72
+ ctime: number;
73
+ /** 发送者昵称 */
74
+ uname: string;
75
+ /** 发送者头像链接 */
76
+ uface: string;
77
+ /** 视频主标题 */
78
+ title: string;
79
+ self_seen: boolean;
80
+ /** 弹幕点赞数 */
81
+ like_count: number;
82
+ user_like: number;
83
+ /** 分 P 标题 */
84
+ p_title: string;
85
+ /** 视频封面链接 */
86
+ cover: string;
87
+ is_charge: boolean;
88
+ is_charge_plus: boolean;
89
+ following: boolean;
90
+ extra_cps: null;
91
+ }[];
92
+ };
93
+ }
94
+ export interface DM_JSON_Dplayer {
95
+ code: number;
96
+ /**
97
+ * progress,mode,color,midHash,content
98
+ */
99
+ data: [number, number, number, string, string][];
100
+ }
101
+ export interface DM_JSON_Artplayer {
102
+ danmuku: {
103
+ text: string;
104
+ time?: number;
105
+ mode?: number;
106
+ color?: string;
107
+ border?: boolean;
108
+ style?: {};
109
+ }[];
110
+ }
111
+ export interface DM_JSON_DDPlay {
112
+ count: number | string;
113
+ comments: {
114
+ cid: bigint;
115
+ p: string;
116
+ m: string;
117
+ }[];
118
+ }
119
+ export type DM_format = 'danuni.json' | 'danuni.pb.bin' | 'bili.xml' | 'bili.pb.bin' | 'bili.cmd.pb.bin' | 'bili.up.json' | 'dplayer.json' | 'artplayer.json' | 'ddplay.json' | 'common.ass';
120
+ type shareItems = Partial<Pick<UniDMTools.UniDMObj, 'SOID' | 'senderID' | 'platform' | 'SOID' | 'pool' | 'mode' | 'color'>>;
121
+ type statItems = Partial<Pick<UniDMTools.UniDMObj, 'SOID' | 'mode' | 'fontsize' | 'color' | 'senderID' | 'content' | 'weight' | 'pool' | 'platform'>>;
122
+ type Stats<T extends keyof statItems> = Map<statItems[T], number>;
123
+ type UniPoolPipe = (that: UniPool) => Promise<UniPool>;
124
+ type UniPoolPipeSync = (that: UniPool) => UniPool;
125
+ export interface Options {
126
+ dedupe?: boolean;
127
+ /**
128
+ * @description
129
+ * 当为`false`时,关闭DMID生成; 当为正整数时,表示生成DMID的截取位数; 或可传入一个DMID生成器实例
130
+ */
131
+ dmid?: boolean | number | UniIDTools.DMIDGenerator;
132
+ }
133
+ export declare class UniPool {
134
+ dans: UniDM[];
135
+ options: Options;
136
+ info: {
137
+ /**
138
+ * 是否从已被转换过的第三方格式弹幕再次转换而来
139
+ */
140
+ fromConverted: boolean;
141
+ };
142
+ constructor(dans: UniDM[], options?: Options, info?: {
143
+ /**
144
+ * 是否从已被转换过的第三方格式弹幕再次转换而来
145
+ */
146
+ fromConverted: boolean;
147
+ });
148
+ pipe(fn: UniPoolPipe): Promise<UniPool>;
149
+ pipeSync(fn: UniPoolPipeSync): UniPool;
150
+ /**
151
+ * @deprecated 使用 `getShared` 代替
152
+ */
153
+ get shared(): shareItems;
154
+ getShared<K extends keyof shareItems>(key: K): shareItems[K];
155
+ getStat<K extends keyof statItems>(key: K): Stats<K>;
156
+ getMost<K extends keyof statItems>(key: K): {
157
+ val: Partial<Pick<UniDMTools.UniDMObj, "SOID" | "mode" | "fontsize" | "color" | "senderID" | "content" | "weight" | "pool" | "platform">>[K] | undefined;
158
+ count: number;
159
+ };
160
+ /**
161
+ * @deprecated 使用 `getMost` 代替
162
+ */
163
+ get most(): {
164
+ mode: UniDMTools.Modes;
165
+ fontsize: number;
166
+ color: number;
167
+ senderID: string;
168
+ content: string;
169
+ weight: number;
170
+ pool: UniDMTools.Pools;
171
+ platform: string | undefined;
172
+ };
173
+ static create(options?: Options): UniPool;
174
+ /**
175
+ * 合并弹幕/弹幕库
176
+ */
177
+ assign(dans: UniPool | UniDM | UniDM[]): UniPool;
178
+ /**
179
+ * 按共通属性拆分弹幕库
180
+ */
181
+ split(key: keyof shareItems): UniPool[];
182
+ /**
183
+ * 基于DMID的基本去重功能,用于解决该class下dans为array而非Set的问题
184
+ */
185
+ private dedupe;
186
+ /**
187
+ * 合并一定时间段内的重复弹幕,防止同屏出现过多
188
+ * @param lifetime 查重时间区段,单位秒 (默认为 0,表示不查重)
189
+ */
190
+ merge(lifetime?: number): UniPool;
191
+ minify(): (Partial<UniDMTools.UniDMObj> & Pick<UniDMTools.UniDMObj, "SOID">)[];
192
+ static import(file: unknown, options?: Options,
193
+ /**
194
+ * 加载指定解析模块,为空则全选
195
+ */
196
+ mod?: ('json' | 'str' | 'bin')[]): {
197
+ pool: UniPool;
198
+ fmt: DM_format;
199
+ };
200
+ convert2(format: DM_format, continue_on_error?: boolean): string | Uint8Array<ArrayBuffer> | UniDM[] | (DM_JSON_Dplayer & {
201
+ danuni?: DanUniConvertTip;
202
+ }) | (DM_JSON_Artplayer & {
203
+ danuni?: DanUniConvertTip;
204
+ }) | (DM_JSON_DDPlay & {
205
+ danuni?: DanUniConvertTip;
206
+ });
207
+ static fromPb(bin: Uint8Array | ArrayBuffer, options?: Options): UniPool;
208
+ /**
209
+ * 转为 protobuf 二进制
210
+ */
211
+ toPb(): Uint8Array<ArrayBuffer>;
212
+ static fromBiliXML(xml: string, options?: Options): UniPool;
213
+ toBiliXML(options?: {
214
+ /**
215
+ * 当SOID非来源bili时,若此处指定则使用该值为cid,否则使用SOID
216
+ */
217
+ cid?: bigint;
218
+ /**
219
+ * 当仅含有来自bili的弹幕时,启用将保持发送者标识不含`@`
220
+ * @description
221
+ * bili的弹幕含midHash(crc),不启用该处使用senderID填充,启用则去除`@bili`部分,提高兼容性
222
+ */
223
+ avoidSenderIDWithAt?: boolean;
224
+ }): string;
225
+ static fromBiliGrpc(bin: Uint8Array | ArrayBuffer, options?: Options): UniPool;
226
+ /**
227
+ * @param bin 符合`DmWebViewReplySchema`(bili视频meta)的protobuf二进制
228
+ */
229
+ static fromBiliCommandGrpc(bin: Uint8Array | ArrayBuffer, options?: Options): UniPool;
230
+ static fromBiliUp(json: DM_JSON_BiliUp, options?: Options): UniPool;
231
+ static fromDplayer(json: DM_JSON_Dplayer & {
232
+ danuni?: DanUniConvertTip;
233
+ }, playerID: string, domain?: string, options?: Options): UniPool;
234
+ toDplayer(): DM_JSON_Dplayer & {
235
+ danuni?: DanUniConvertTip;
236
+ };
237
+ static fromArtplayer(json: DM_JSON_Artplayer & {
238
+ danuni?: DanUniConvertTip;
239
+ }, playerID: string, domain?: string, options?: Options): UniPool;
240
+ toArtplayer(): DM_JSON_Artplayer & {
241
+ danuni?: DanUniConvertTip;
242
+ };
243
+ static fromDDPlay(json: DM_JSON_DDPlay & {
244
+ danuni?: DanUniConvertTip;
245
+ }, episodeId: string, options?: Options): UniPool;
246
+ toDDplay(): DM_JSON_DDPlay & {
247
+ danuni?: DanUniConvertTip;
248
+ };
249
+ static fromASS(ass: string, options?: Options): UniPool;
250
+ /**
251
+ * 转换为ASS字幕格式的弹幕,需播放器支持多行ASS渲染
252
+ */
253
+ toASS(canvasCtx: CanvasCtx, options?: AssGenOptions): string;
254
+ }
255
+ export { platform, UniDM, UniDMTools, UniIDTools, type DM_JSON_BiliCommandGrpc, };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { UniPool } from '../..';
2
+ /**
3
+ * 用于过滤直接从B站api获取到的弹幕中去除dmid重复的弹幕
4
+ */
5
+ export default function bili_dedupe(that: UniPool): UniPool;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import bili_dedupe from './bili-dedupe';
2
+ export { bili_dedupe };