@dan-uni/dan-any 1.1.1 → 1.2.2

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 (50) hide show
  1. package/dist/browser/157.min.js +20 -4
  2. package/dist/browser/17.min.js +13289 -0
  3. package/dist/browser/898.min.js +10 -0
  4. package/dist/browser/index.min.js +1 -13248
  5. package/dist/browser/plugins/bili-dedupe.min.js +1 -1
  6. package/dist/browser/plugins/index.min.js +1 -0
  7. package/dist/browser/plugins/stats.min.js +1 -0
  8. package/dist/browser/src/index.d.ts +4 -4
  9. package/dist/browser/src/plugins/bili-dedupe/index.d.ts +3 -5
  10. package/dist/browser/src/plugins/index.d.ts +2 -2
  11. package/dist/browser/src/plugins/stats/getLatestDan.d.ts +6 -0
  12. package/dist/browser/src/plugins/stats/index.d.ts +1 -0
  13. package/dist/browser/src/plugins/stats/index.test.d.ts +1 -0
  14. package/dist/node/157.js +20 -4
  15. package/dist/node/17.js +1864 -0
  16. package/dist/node/898.js +10 -0
  17. package/dist/node/index.js +1 -1823
  18. package/dist/node/plugins/bili-dedupe.js +1 -1
  19. package/dist/node/plugins/index.js +1 -0
  20. package/dist/node/plugins/stats.js +1 -0
  21. package/dist/node/src/index.d.ts +4 -4
  22. package/dist/node/src/plugins/bili-dedupe/index.d.ts +3 -5
  23. package/dist/node/src/plugins/index.d.ts +2 -2
  24. package/dist/node/src/plugins/stats/getLatestDan.d.ts +6 -0
  25. package/dist/node/src/plugins/stats/index.d.ts +1 -0
  26. package/dist/node/src/plugins/stats/index.test.d.ts +1 -0
  27. package/dist/umd/index.umd.min.js +65 -62
  28. package/dist/umd/plugins/bili-dedupe.umd.min.js +24997 -48
  29. package/dist/umd/plugins/bili-dedupe.umd.min.js.LICENSE.txt +34 -0
  30. package/dist/umd/plugins/index.umd.min.js +24971 -21
  31. package/dist/umd/plugins/index.umd.min.js.LICENSE.txt +34 -0
  32. package/dist/umd/plugins/stats.umd.min.js +39 -0
  33. package/dist/umd/src/index.d.ts +4 -4
  34. package/dist/umd/src/plugins/bili-dedupe/index.d.ts +3 -5
  35. package/dist/umd/src/plugins/index.d.ts +2 -2
  36. package/dist/umd/src/plugins/stats/getLatestDan.d.ts +6 -0
  37. package/dist/umd/src/plugins/stats/index.d.ts +1 -0
  38. package/dist/umd/src/plugins/stats/index.test.d.ts +1 -0
  39. package/package.json +1 -1
  40. package/rslib.config.ts +1 -0
  41. package/src/index.ts +8 -4
  42. package/src/plugins/bili-dedupe/index.test.ts +5 -2
  43. package/src/plugins/bili-dedupe/index.ts +13 -3
  44. package/src/plugins/index.ts +2 -3
  45. package/src/plugins/stats/getLatestDan.ts +13 -0
  46. package/src/plugins/stats/index.test.ts +39 -0
  47. package/src/plugins/stats/index.ts +1 -0
  48. package/dist/browser/42.min.js +0 -45
  49. package/dist/node/42.js +0 -45
  50. /package/dist/browser/{index.min.js.LICENSE.txt → 17.min.js.LICENSE.txt} +0 -0
@@ -0,0 +1,34 @@
1
+ /*!
2
+ * The buffer module from node.js, for the browser.
3
+ *
4
+ * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
5
+ * @license MIT
6
+ */
7
+
8
+ /*!
9
+ * The buffer module from node.js, for the browser.
10
+ *
11
+ * @author Feross Aboukhadijeh <https://feross.org>
12
+ * @license MIT
13
+ */
14
+
15
+ /*! *****************************************************************************
16
+ Copyright (C) Microsoft. All rights reserved.
17
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
18
+ this file except in compliance with the License. You may obtain a copy of the
19
+ License at http://www.apache.org/licenses/LICENSE-2.0
20
+
21
+ THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
23
+ WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
24
+ MERCHANTABLITY OR NON-INFRINGEMENT.
25
+
26
+ See the Apache Version 2.0 License for specific language governing permissions
27
+ and limitations under the License.
28
+ ***************************************************************************** */
29
+
30
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
31
+
32
+ /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
33
+
34
+ /*! zero-fill. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
@@ -0,0 +1,39 @@
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_require__ = {};
9
+ (()=>{
10
+ __webpack_require__.d = (exports1, definition)=>{
11
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
12
+ enumerable: true,
13
+ get: definition[key]
14
+ });
15
+ };
16
+ })();
17
+ (()=>{
18
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.r = (exports1)=>{
22
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
23
+ value: 'Module'
24
+ });
25
+ Object.defineProperty(exports1, '__esModule', {
26
+ value: true
27
+ });
28
+ };
29
+ })();
30
+ var __webpack_exports__ = {};
31
+ __webpack_require__.r(__webpack_exports__);
32
+ __webpack_require__.d(__webpack_exports__, {
33
+ getLatestDan: ()=>getLatestDan
34
+ });
35
+ function getLatestDan(that) {
36
+ return 0 === that.dans.length ? null : that.dans.reduce((latest, current)=>current.ctime > latest.ctime ? current : latest);
37
+ }
38
+ return __webpack_exports__;
39
+ })());
@@ -120,8 +120,8 @@ export type DM_format = 'danuni.json' | 'danuni.pb.bin' | 'bili.xml' | 'bili.pb.
120
120
  type shareItems = Partial<Pick<UniDMTools.UniDMObj, 'SOID' | 'senderID' | 'platform' | 'SOID' | 'pool' | 'mode' | 'color'>>;
121
121
  type statItems = Partial<Pick<UniDMTools.UniDMObj, 'SOID' | 'mode' | 'fontsize' | 'color' | 'senderID' | 'content' | 'weight' | 'pool' | 'platform'>>;
122
122
  type Stats<T extends keyof statItems> = Map<statItems[T], number>;
123
- type UniPoolPipe = (that: UniPool) => Promise<UniPool>;
124
- type UniPoolPipeSync = (that: UniPool) => UniPool;
123
+ type UniPoolPipe = (that: UniPool) => Promise<any>;
124
+ type UniPoolPipeSync = (that: UniPool) => any;
125
125
  export interface Options {
126
126
  dedupe?: boolean;
127
127
  /**
@@ -145,8 +145,8 @@ export declare class UniPool {
145
145
  */
146
146
  fromConverted: boolean;
147
147
  });
148
- pipe(fn: UniPoolPipe): Promise<UniPool>;
149
- pipeSync(fn: UniPoolPipeSync): UniPool;
148
+ pipe<T extends (...args: any) => any = UniPoolPipe>(fn: T): Promise<ReturnType<T>>;
149
+ pipeSync<T extends (...args: any) => any = UniPoolPipeSync>(fn: T): ReturnType<T>;
150
150
  /**
151
151
  * @deprecated 使用 `getShared` 代替
152
152
  */
@@ -1,5 +1,3 @@
1
- import type { UniPool } from '../..';
2
- /**
3
- * 用于过滤直接从B站api获取到的弹幕中去除dmid重复的弹幕
4
- */
5
- export default function bili_dedupe(that: UniPool): UniPool;
1
+ import { UniPool } from '../..';
2
+ export declare function to_bili_deduped(that: UniPool): UniPool;
3
+ export declare function bili_dedupe(that: UniPool): void;
@@ -1,2 +1,2 @@
1
- import bili_dedupe from './bili-dedupe';
2
- export { bili_dedupe };
1
+ export * as bili_dedupe from './bili-dedupe';
2
+ export * as stats from './stats';
@@ -0,0 +1,6 @@
1
+ import type { UniDM, UniPool } from '../..';
2
+ /**
3
+ * 从弹幕池中查找出最新的一条弹幕
4
+ * 按照弹幕的创建时间(ctime)排序,返回最新的一条
5
+ */
6
+ export default function getLatestDan(that: UniPool): UniDM | null;
@@ -0,0 +1 @@
1
+ export { default as getLatestDan } from './getLatestDan';
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dan-uni/dan-any",
3
3
  "type": "module",
4
- "version": "1.1.1",
4
+ "version": "1.2.2",
5
5
  "description": "A danmaku transformer lib, supporting danmaku from different platforms.",
6
6
  "author": "rinne",
7
7
  "license": "LGPL-3.0-or-later",
package/rslib.config.ts CHANGED
@@ -9,6 +9,7 @@ export default defineConfig({
9
9
  index: './src/index.ts',
10
10
  'plugins/index': './src/plugins/index.ts',
11
11
  'plugins/bili-dedupe': './src/plugins/bili-dedupe/index.ts',
12
+ 'plugins/stats': './src/plugins/stats/index.ts',
12
13
  },
13
14
  },
14
15
  lib: [
package/src/index.ts CHANGED
@@ -185,8 +185,8 @@ type statItems = Partial<
185
185
  >
186
186
  type Stats<T extends keyof statItems> = Map<statItems[T], number>
187
187
 
188
- type UniPoolPipe = (that: UniPool) => Promise<UniPool>
189
- type UniPoolPipeSync = (that: UniPool) => UniPool
188
+ type UniPoolPipe = (that: UniPool) => Promise<any>
189
+ type UniPoolPipeSync = (that: UniPool) => any
190
190
 
191
191
  export interface Options {
192
192
  dedupe?: boolean
@@ -211,10 +211,14 @@ export class UniPool {
211
211
  if (options.dedupe !== false) options.dedupe = true
212
212
  if (this.options.dedupe) this.dedupe()
213
213
  }
214
- async pipe(fn: UniPoolPipe): Promise<UniPool> {
214
+ async pipe<T extends (...args: any) => any = UniPoolPipe>(
215
+ fn: T,
216
+ ): Promise<ReturnType<T>> {
215
217
  return fn(this)
216
218
  }
217
- pipeSync(fn: UniPoolPipeSync): UniPool {
219
+ pipeSync<T extends (...args: any) => any = UniPoolPipeSync>(
220
+ fn: T,
221
+ ): ReturnType<T> {
218
222
  return fn(this)
219
223
  }
220
224
  /**
@@ -1,7 +1,7 @@
1
1
  //基于以下注释,根据vitest生成测试用例
2
2
  import { describe, expect, it } from 'vitest'
3
3
 
4
- import bili_dedupe from '.'
4
+ import { bili_dedupe, to_bili_deduped } from '.'
5
5
  import { UniPool } from '../..'
6
6
 
7
7
  const xml = `<i>
@@ -34,7 +34,10 @@ describe('其它', () => {
34
34
  it('B站dmid去重(仅限主站直接获取的弹幕)', () => {
35
35
  const ori = pool.dans.length
36
36
  expect(ori).toBe(15)
37
- const n = pool.pipeSync(bili_dedupe)
37
+ const n = pool.pipeSync(to_bili_deduped)
38
38
  expect(n.dans.length).toBe(13)
39
+ expect(pool.dans.length).toBe(15)
40
+ pool.pipeSync(bili_dedupe)
41
+ expect(pool.dans.length).toBe(13)
39
42
  })
40
43
  })
@@ -1,11 +1,12 @@
1
- import type { UniDM, UniPool } from '../..'
1
+ import type { UniDM } from '../..'
2
2
 
3
+ import { UniPool } from '../..'
3
4
  import { PlatformVideoSource } from '../../utils/platform'
4
5
 
5
6
  /**
6
7
  * 用于过滤直接从B站api获取到的弹幕中去除dmid重复的弹幕
7
8
  */
8
- export default function bili_dedupe(that: UniPool): UniPool {
9
+ function main(that: UniPool) {
9
10
  that.dans.forEach((d) => {
10
11
  if (d.platform !== PlatformVideoSource.Bilibili)
11
12
  throw new Error('bili-dedupe: 仅支持B站(主站)的弹幕')
@@ -14,6 +15,15 @@ export default function bili_dedupe(that: UniPool): UniPool {
14
15
  })
15
16
  const map = new Map<bigint, UniDM>()
16
17
  that.dans.forEach((d) => map.set(d.extra.bili!.dmid!, d)) // 已由上方的检查保证存在
18
+ return map
19
+ }
20
+
21
+ export function to_bili_deduped(that: UniPool): UniPool {
22
+ const map = main(that)
23
+ return new UniPool([...map.values()], that.options, that.info)
24
+ }
25
+
26
+ export function bili_dedupe(that: UniPool): void {
27
+ const map = main(that)
17
28
  that.dans = [...map.values()]
18
- return that
19
29
  }
@@ -1,3 +1,2 @@
1
- import bili_dedupe from './bili-dedupe'
2
-
3
- export { bili_dedupe }
1
+ export * as bili_dedupe from './bili-dedupe'
2
+ export * as stats from './stats'
@@ -0,0 +1,13 @@
1
+ import type { UniDM, UniPool } from '../..'
2
+
3
+ /**
4
+ * 从弹幕池中查找出最新的一条弹幕
5
+ * 按照弹幕的创建时间(ctime)排序,返回最新的一条
6
+ */
7
+ export default function getLatestDan(that: UniPool): UniDM | null {
8
+ return that.dans.length === 0
9
+ ? null
10
+ : that.dans.reduce((latest, current) =>
11
+ current.ctime > latest.ctime ? current : latest,
12
+ )
13
+ }
@@ -0,0 +1,39 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { UniPool } from '../..'
4
+ import getLatestDan from './getLatestDan'
5
+
6
+ const xml = `<i>
7
+ <chatserver>chat.bilibili.com</chatserver>
8
+ <chatid>1156756312</chatid>
9
+ <mission>0</mission>
10
+ <maxlimit>2947</maxlimit>
11
+ <state>0</state>
12
+ <real_name>0</real_name>
13
+ <source>k-v</source>
14
+ <d p="13.213,1,25,16777215,1686314041,3,ff41173d,1335658005672492032">喜欢</d>
15
+ <d p="13.213,1,25,16777215,1686590010,0,296b35b5,1337972999512832512">来了 哈哈~~</d>
16
+ <d p="13.246,1,25,16777215,1686276875,0,5664cfc4,1335346233459549696">就是</d>
17
+ <d p="13.266,1,25,16777215,1686283375,0,c7e6646f,1335400761013670912">什么鬼?</d>
18
+ <d p="13.284,1,25,16777215,1686291338,0,38662881,1335467554877267456">哇哦</d>
19
+ <d p="13.306,1,25,16777215,1686268410,0,4c01de10,1335275224983600896">试试</d>
20
+ <d p="13.331,1,25,16777215,1686948453,3,56a3c5d5,1340979831550069760">不喜欢</d>
21
+ <d p="13.374,1,25,16777215,1686300770,3,647fe355,1335546672880933888">不喜欢</d>
22
+ <d p="13.376,1,25,16777215,1686297921,0,469d94b8,1335522778300134400">哦豁</d>
23
+ <d p="13.419,1,25,8700107,1686268005,0,be402447,1335271828100244224">太酷啦</d>
24
+ <d p="13.419,1,25,16777215,1686316828,3,7ffb6619,1335681385016736768">喜欢</d>
25
+ <d p="13.459,1,25,16777215,1686299729,0,45834405,1335537942797634048">一般,不好看</d>
26
+ <d p="13.462,1,25,16777215,1686302133,0,3cab672c,1335558106620590080">哈哈哈</d>
27
+ <d p="13.481,1,25,16777215,1686297342,0,ce67fafd,1335517923728804864">?</d>
28
+ <d p="13.499,1,25,16777215,1686301548,3,2848bf1c,1335553202649003264">不喜欢</d>
29
+ </i>`
30
+
31
+ describe('统计', () => {
32
+ it('获取最新的一条弹幕', () => {
33
+ const pool = UniPool.fromBiliXML(xml)
34
+ const latest = pool.pipeSync(getLatestDan)
35
+ expect(latest).not.toBeNull()
36
+ expect(latest?.content).toBe('不喜欢')
37
+ expect(latest?.ctime).toStrictEqual(new Date(1686948453 * 1000))
38
+ })
39
+ })
@@ -0,0 +1 @@
1
+ export { default as getLatestDan } from './getLatestDan'
@@ -1,45 +0,0 @@
1
- import { __webpack_require__ } from "./rslib-runtime.min.js";
2
- var platform_namespaceObject = {};
3
- __webpack_require__.r(platform_namespaceObject);
4
- __webpack_require__.d(platform_namespaceObject, {
5
- PlatformDanmakuOnlySource: ()=>platform_PlatformDanmakuOnlySource,
6
- PlatformDanmakuOnlySources: ()=>PlatformDanmakuOnlySources,
7
- PlatformDanmakuSources: ()=>PlatformDanmakuSources,
8
- PlatformInfoSource: ()=>platform_PlatformInfoSource,
9
- PlatformInfoSources: ()=>PlatformInfoSources,
10
- PlatformSources: ()=>PlatformSources,
11
- PlatformVideoSource: ()=>platform_PlatformVideoSource,
12
- PlatformVideoSources: ()=>PlatformVideoSources
13
- });
14
- var platform_PlatformInfoSource = /*#__PURE__*/ function(PlatformInfoSource) {
15
- PlatformInfoSource["Bangumi"] = "bgm";
16
- PlatformInfoSource["TMDB"] = "tmdb";
17
- return PlatformInfoSource;
18
- }({});
19
- const PlatformInfoSources = Object.values(platform_PlatformInfoSource);
20
- var platform_PlatformVideoSource = /*#__PURE__*/ function(PlatformVideoSource) {
21
- PlatformVideoSource["Acfun"] = "acfun";
22
- PlatformVideoSource["Baha"] = "baha";
23
- PlatformVideoSource["Bilibili"] = "bili";
24
- PlatformVideoSource["BilibiliGlobal"] = "bglobal";
25
- PlatformVideoSource["Iqiyi"] = "iqiyi";
26
- PlatformVideoSource["Tencent"] = "tencent";
27
- PlatformVideoSource["Youku"] = "youku";
28
- return PlatformVideoSource;
29
- }({});
30
- const PlatformVideoSources = Object.values(platform_PlatformVideoSource);
31
- var platform_PlatformDanmakuOnlySource = /*#__PURE__*/ function(PlatformDanmakuOnlySource) {
32
- PlatformDanmakuOnlySource["DanDanPlay"] = "ddplay";
33
- PlatformDanmakuOnlySource["TuCao"] = "tucao";
34
- return PlatformDanmakuOnlySource;
35
- }({});
36
- const PlatformDanmakuOnlySources = Object.values(platform_PlatformDanmakuOnlySource);
37
- const PlatformDanmakuSources = [
38
- ...PlatformVideoSources,
39
- ...PlatformDanmakuOnlySources
40
- ];
41
- const PlatformSources = [
42
- ...PlatformInfoSources,
43
- ...PlatformDanmakuSources
44
- ];
45
- export { PlatformDanmakuSources, platform_PlatformDanmakuOnlySource, platform_PlatformVideoSource, platform_namespaceObject as platform };
package/dist/node/42.js DELETED
@@ -1,45 +0,0 @@
1
- import { __webpack_require__ } from "./rslib-runtime.js";
2
- var platform_namespaceObject = {};
3
- __webpack_require__.r(platform_namespaceObject);
4
- __webpack_require__.d(platform_namespaceObject, {
5
- PlatformDanmakuOnlySource: ()=>platform_PlatformDanmakuOnlySource,
6
- PlatformDanmakuOnlySources: ()=>PlatformDanmakuOnlySources,
7
- PlatformDanmakuSources: ()=>PlatformDanmakuSources,
8
- PlatformInfoSource: ()=>platform_PlatformInfoSource,
9
- PlatformInfoSources: ()=>PlatformInfoSources,
10
- PlatformSources: ()=>PlatformSources,
11
- PlatformVideoSource: ()=>platform_PlatformVideoSource,
12
- PlatformVideoSources: ()=>PlatformVideoSources
13
- });
14
- var platform_PlatformInfoSource = /*#__PURE__*/ function(PlatformInfoSource) {
15
- PlatformInfoSource["Bangumi"] = "bgm";
16
- PlatformInfoSource["TMDB"] = "tmdb";
17
- return PlatformInfoSource;
18
- }({});
19
- const PlatformInfoSources = Object.values(platform_PlatformInfoSource);
20
- var platform_PlatformVideoSource = /*#__PURE__*/ function(PlatformVideoSource) {
21
- PlatformVideoSource["Acfun"] = "acfun";
22
- PlatformVideoSource["Baha"] = "baha";
23
- PlatformVideoSource["Bilibili"] = "bili";
24
- PlatformVideoSource["BilibiliGlobal"] = "bglobal";
25
- PlatformVideoSource["Iqiyi"] = "iqiyi";
26
- PlatformVideoSource["Tencent"] = "tencent";
27
- PlatformVideoSource["Youku"] = "youku";
28
- return PlatformVideoSource;
29
- }({});
30
- const PlatformVideoSources = Object.values(platform_PlatformVideoSource);
31
- var platform_PlatformDanmakuOnlySource = /*#__PURE__*/ function(PlatformDanmakuOnlySource) {
32
- PlatformDanmakuOnlySource["DanDanPlay"] = "ddplay";
33
- PlatformDanmakuOnlySource["TuCao"] = "tucao";
34
- return PlatformDanmakuOnlySource;
35
- }({});
36
- const PlatformDanmakuOnlySources = Object.values(platform_PlatformDanmakuOnlySource);
37
- const PlatformDanmakuSources = [
38
- ...PlatformVideoSources,
39
- ...PlatformDanmakuOnlySources
40
- ];
41
- const PlatformSources = [
42
- ...PlatformInfoSources,
43
- ...PlatformDanmakuSources
44
- ];
45
- export { PlatformDanmakuSources, platform_PlatformDanmakuOnlySource, platform_PlatformVideoSource, platform_namespaceObject as platform };