@dan-uni/dan-any 0.0.7 → 0.1.0
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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/utils/dm-gen.d.ts +14 -5
- package/package.json +1 -1
- package/src/index.test.ts +7 -0
- package/src/index.ts +3 -0
- package/src/utils/dm-gen.ts +63 -24
- package/CHANGELOG.md +0 -9
package/dist/utils/dm-gen.d.ts
CHANGED
|
@@ -142,7 +142,8 @@ export interface UniDMObj {
|
|
|
142
142
|
attr: DMAttr[];
|
|
143
143
|
platform: platfrom | string;
|
|
144
144
|
SPMO: string;
|
|
145
|
-
extra: string;
|
|
145
|
+
extra: string | Extra;
|
|
146
|
+
extraStr: string;
|
|
146
147
|
DMID: string;
|
|
147
148
|
}
|
|
148
149
|
/**
|
|
@@ -154,7 +155,7 @@ export declare class UniDM {
|
|
|
154
155
|
*/
|
|
155
156
|
FCID: string;
|
|
156
157
|
/**
|
|
157
|
-
* 弹幕出现位置(单位ms)
|
|
158
|
+
* 弹幕出现位置(单位s;精度为ms,即保留三位小数)
|
|
158
159
|
*/
|
|
159
160
|
progress: number;
|
|
160
161
|
/**
|
|
@@ -236,7 +237,7 @@ export declare class UniDM {
|
|
|
236
237
|
*/
|
|
237
238
|
FCID: string,
|
|
238
239
|
/**
|
|
239
|
-
* 弹幕出现位置(单位ms)
|
|
240
|
+
* 弹幕出现位置(单位s;精度为ms,即保留三位小数)
|
|
240
241
|
*/
|
|
241
242
|
progress?: number,
|
|
242
243
|
/**
|
|
@@ -308,7 +309,7 @@ export declare class UniDM {
|
|
|
308
309
|
* - Artplayer: style不为空时,将其JSON.stringify()存入
|
|
309
310
|
*/
|
|
310
311
|
extraStr?: string | undefined, DMID?: string | undefined);
|
|
311
|
-
static create(args
|
|
312
|
+
static create(args?: Partial<UniDMObj>): UniDM;
|
|
312
313
|
get extra(): Extra;
|
|
313
314
|
get isFrom3rdPlatform(): boolean;
|
|
314
315
|
/**
|
|
@@ -317,8 +318,16 @@ export declare class UniDM {
|
|
|
317
318
|
* @description 同一FCID下唯一
|
|
318
319
|
*/
|
|
319
320
|
toDMID(): string;
|
|
321
|
+
minify(): Partial<UniDMObj> & Pick<UniDMObj, "FCID">;
|
|
320
322
|
downgradeAdvcancedDan(): this | undefined;
|
|
321
|
-
|
|
323
|
+
/**
|
|
324
|
+
* 将各种类型的时间进行格式化
|
|
325
|
+
* @param oriCtime
|
|
326
|
+
* @param tsUnit 当`oriCtime`为数字类型表时间戳时的单位;
|
|
327
|
+
* 为 毫秒(ms)/秒(s)
|
|
328
|
+
* @returns {Date}
|
|
329
|
+
*/
|
|
330
|
+
static transCtime(oriCtime: ctime, tsUnit?: 'ms' | 's'): Date;
|
|
322
331
|
static transMode(oriMode: number, fmt: 'bili' | 'dplayer' | 'artplayer' | 'ddplay'): Modes;
|
|
323
332
|
static fromBili(args: DMBili, SPMO?: string, cid?: bigint): UniDM;
|
|
324
333
|
static fromBiliCommand(args: DMBiliCommand, SPMO?: string, cid?: bigint): UniDM;
|
package/package.json
CHANGED
package/src/index.test.ts
CHANGED
package/src/index.ts
CHANGED
package/src/utils/dm-gen.ts
CHANGED
|
@@ -256,7 +256,8 @@ export interface UniDMObj {
|
|
|
256
256
|
attr: DMAttr[]
|
|
257
257
|
platform: platfrom | string
|
|
258
258
|
SPMO: string
|
|
259
|
-
extra: string
|
|
259
|
+
extra: string | Extra
|
|
260
|
+
extraStr: string
|
|
260
261
|
DMID: string
|
|
261
262
|
}
|
|
262
263
|
|
|
@@ -274,7 +275,7 @@ export class UniDM {
|
|
|
274
275
|
*/
|
|
275
276
|
public FCID: string,
|
|
276
277
|
/**
|
|
277
|
-
* 弹幕出现位置(单位ms)
|
|
278
|
+
* 弹幕出现位置(单位s;精度为ms,即保留三位小数)
|
|
278
279
|
*/
|
|
279
280
|
public progress: number = 0,
|
|
280
281
|
/**
|
|
@@ -359,25 +360,31 @@ export class UniDM {
|
|
|
359
360
|
if (pool < Pools.Def || pool > Pools.Ix) this.pool = Pools.Def
|
|
360
361
|
// if (attr < 0 || attr > 0b111) this.attr = 0
|
|
361
362
|
if (!DMID) DMID = this.toDMID()
|
|
363
|
+
|
|
364
|
+
this.progress = Number.parseFloat(progress.toFixed(3))
|
|
362
365
|
}
|
|
363
|
-
static create(args
|
|
364
|
-
return
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
366
|
+
static create(args?: Partial<UniDMObj>) {
|
|
367
|
+
return args
|
|
368
|
+
? new UniDM(
|
|
369
|
+
args.FCID || ID.fromNull().toString(),
|
|
370
|
+
args.progress,
|
|
371
|
+
args.mode,
|
|
372
|
+
args.fontsize,
|
|
373
|
+
args.color,
|
|
374
|
+
args.senderID,
|
|
375
|
+
args.content,
|
|
376
|
+
args.ctime,
|
|
377
|
+
args.weight,
|
|
378
|
+
args.pool,
|
|
379
|
+
args.attr,
|
|
380
|
+
args.platform,
|
|
381
|
+
args.SPMO,
|
|
382
|
+
typeof args.extra === 'object'
|
|
383
|
+
? JSON.stringify(args.extra)
|
|
384
|
+
: args.extra || args.extraStr,
|
|
385
|
+
args.DMID,
|
|
386
|
+
)
|
|
387
|
+
: new UniDM(ID.fromNull().toString())
|
|
381
388
|
}
|
|
382
389
|
get extra() {
|
|
383
390
|
const extra = JSON.parse(this.extraStr || '{}')
|
|
@@ -396,15 +403,47 @@ export class UniDM {
|
|
|
396
403
|
toDMID() {
|
|
397
404
|
return createDMID(this.content, this.senderID, this.ctime)
|
|
398
405
|
}
|
|
406
|
+
minify() {
|
|
407
|
+
type UObj = Partial<UniDMObj> & Pick<UniDMObj, 'FCID'>
|
|
408
|
+
const def: UObj = UniDM.create(),
|
|
409
|
+
dan: UObj = UniDM.create(this)
|
|
410
|
+
// const prototypes = Object.getOwnPropertyNames(this)
|
|
411
|
+
for (const key in dan) {
|
|
412
|
+
const k = key as keyof UObj,
|
|
413
|
+
v = dan[k]
|
|
414
|
+
// if (key in prototypes) continue
|
|
415
|
+
if (key === 'FCID') continue
|
|
416
|
+
else if (!v) delete dan[k]
|
|
417
|
+
else if (v === def[k]) delete dan[k]
|
|
418
|
+
else {
|
|
419
|
+
if (k === 'attr' && Array.isArray(v) && v.length === 0) delete dan[k]
|
|
420
|
+
if (k === 'extraStr' && v === '{}') delete dan[k]
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return JSON.parse(JSON.stringify(dan)) as UObj
|
|
424
|
+
}
|
|
399
425
|
downgradeAdvcancedDan() {
|
|
400
426
|
if (!this.extra) return this
|
|
401
427
|
else {
|
|
402
428
|
// TODO 分别对 mode7/8/9 command artplayer等正常播放器无法绘制的弹幕做降级处理
|
|
403
429
|
}
|
|
404
430
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
431
|
+
/**
|
|
432
|
+
* 将各种类型的时间进行格式化
|
|
433
|
+
* @param oriCtime
|
|
434
|
+
* @param tsUnit 当`oriCtime`为数字类型表时间戳时的单位;
|
|
435
|
+
* 为 毫秒(ms)/秒(s)
|
|
436
|
+
* @returns {Date}
|
|
437
|
+
*/
|
|
438
|
+
static transCtime(oriCtime: ctime, tsUnit?: 'ms' | 's'): Date {
|
|
439
|
+
function isMsTs(ts: number | bigint) {
|
|
440
|
+
if (tsUnit === 'ms') return true
|
|
441
|
+
else if (tsUnit === 's') return false
|
|
442
|
+
else return ts < 100000000
|
|
443
|
+
}
|
|
444
|
+
if (typeof oriCtime === 'number' || typeof oriCtime === 'bigint')
|
|
445
|
+
if (isMsTs(oriCtime)) return new Date(Number(oriCtime))
|
|
446
|
+
else return new Date(Number(oriCtime) * 1000)
|
|
408
447
|
else if (typeof oriCtime === 'string') {
|
|
409
448
|
if (/^\d+n$/.test(oriCtime))
|
|
410
449
|
return new Date(Number(oriCtime.slice(0, -1)))
|
|
@@ -522,7 +561,7 @@ export class UniDM {
|
|
|
522
561
|
// color: args.color,
|
|
523
562
|
senderID: senderID.toString(),
|
|
524
563
|
// content: args.content,
|
|
525
|
-
ctime: this.transCtime(args.ctime),
|
|
564
|
+
ctime: this.transCtime(args.ctime, 's'),
|
|
526
565
|
weight: args.weight ? args.weight : pool === Pools.Ix ? 1 : 0,
|
|
527
566
|
pool,
|
|
528
567
|
attr: DMAttrUtils.fromBin(args.attr, 'bili'),
|