@dan-uni/dan-any 1.3.3 → 1.3.5

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.
@@ -11461,7 +11461,7 @@ __webpack_require__.d(platform_namespaceObject, {
11461
11461
  PlatformVideoSource: ()=>platform_PlatformVideoSource,
11462
11462
  PlatformVideoSources: ()=>PlatformVideoSources
11463
11463
  });
11464
- var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.3.3","TB":"https://github.com/ani-uni/danuni/tree/master/packages/dan-any#readme"}');
11464
+ var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.3.5","TB":"https://github.com/ani-uni/danuni/tree/master/packages/dan-any#readme"}');
11465
11465
  const color_pad = (s)=>s.length < 2 ? `0${s}` : s;
11466
11466
  const decimalToHex = (n)=>color_pad(n.toString(16));
11467
11467
  const isDarkColor = ({ r, g, b })=>0.299 * r + 0.587 * g + 0.114 * b < 0x30;
@@ -12086,7 +12086,7 @@ class UniDM {
12086
12086
  style: this.extra.artplayer?.style
12087
12087
  };
12088
12088
  }
12089
- static fromDDplay(args, episodeId, domain = platform_PlatformDanmakuOnlySource.DanDanPlay, options) {
12089
+ static fromDDPlay(args, episodeId, domain = platform_PlatformDanmakuOnlySource.DanDanPlay, options) {
12090
12090
  const SOID = id_gen_UniID.fromUnknown(`def_${platform_PlatformDanmakuOnlySource.DanDanPlay}+${episodeId}`, domain);
12091
12091
  return this.create({
12092
12092
  ...args,
@@ -12098,7 +12098,7 @@ class UniDM {
12098
12098
  DMID: args.cid.toString()
12099
12099
  }, options);
12100
12100
  }
12101
- toDDplay() {
12101
+ toDDPlay() {
12102
12102
  let mode = 1;
12103
12103
  if (2 === this.mode) mode = 5;
12104
12104
  else if (1 === this.mode) mode = 4;
@@ -12302,8 +12302,8 @@ _ts_decorate([
12302
12302
  Expose(),
12303
12303
  _ts_metadata("design:type", Function),
12304
12304
  _ts_metadata("design:paramtypes", []),
12305
- _ts_metadata("design:returntype", "u" < typeof DMDDplay ? Object : DMDDplay)
12306
- ], UniDM.prototype, "toDDplay", null);
12305
+ _ts_metadata("design:returntype", "u" < typeof DMDDPlay ? Object : DMDDPlay)
12306
+ ], UniDM.prototype, "toDDPlay", null);
12307
12307
  const DanmakuType = {
12308
12308
  SCROLL: 1,
12309
12309
  BOTTOM: 2,
@@ -12764,7 +12764,7 @@ var src_DM_format = /*#__PURE__*/ function(DM_format) {
12764
12764
  DM_format["BiliUpJson"] = "bili.up.json";
12765
12765
  DM_format["DplayerJson"] = "dplayer.json";
12766
12766
  DM_format["ArtplayerJson"] = "artplayer.json";
12767
- DM_format["DdplayJson"] = "ddplay.json";
12767
+ DM_format["DDPlayJson"] = "ddplay.json";
12768
12768
  DM_format["CommonAss"] = "common.ass";
12769
12769
  return DM_format;
12770
12770
  }({});
@@ -13128,22 +13128,57 @@ class UniPool {
13128
13128
  }
13129
13129
  throw new Error(errmesg ?? err);
13130
13130
  }
13131
- convert2(format, continue_on_error = false) {
13131
+ convert2(format, file_wrapper = false, continue_on_error = false) {
13132
13132
  switch(format){
13133
- case 'danuni.json':
13133
+ case "danuni.json":
13134
+ if (file_wrapper) return new File([
13135
+ src_JSON.stringify(this.dans)
13136
+ ], "danuni.json", {
13137
+ type: 'application/json'
13138
+ });
13134
13139
  return this.dans;
13135
- case 'danuni.min.json':
13140
+ case "danuni.min.json":
13141
+ if (file_wrapper) return new File([
13142
+ src_JSON.stringify(this.minify())
13143
+ ], "danuni.min.json", {
13144
+ type: 'application/json'
13145
+ });
13136
13146
  return this.minify();
13137
- case 'danuni.binpb':
13147
+ case "danuni.binpb":
13148
+ if (file_wrapper) return new File([
13149
+ this.toPb()
13150
+ ], "danuni.binpb", {
13151
+ type: 'application/protobuf'
13152
+ });
13138
13153
  return this.toPb();
13139
- case 'bili.xml':
13154
+ case "bili.xml":
13155
+ if (file_wrapper) return new File([
13156
+ this.toBiliXML()
13157
+ ], "bili.xml", {
13158
+ type: 'application/xml'
13159
+ });
13140
13160
  return this.toBiliXML();
13141
- case 'dplayer.json':
13161
+ case "dplayer.json":
13162
+ if (file_wrapper) return new File([
13163
+ src_JSON.stringify(this.toDplayer())
13164
+ ], "dplayer.json", {
13165
+ type: 'application/json'
13166
+ });
13142
13167
  return this.toDplayer();
13143
- case 'artplayer.json':
13168
+ case "artplayer.json":
13169
+ if (file_wrapper) return new File([
13170
+ src_JSON.stringify(this.toArtplayer())
13171
+ ], "artplayer.json", {
13172
+ type: 'application/json'
13173
+ });
13144
13174
  return this.toArtplayer();
13145
- case 'ddplay.json':
13146
- return this.toDDplay();
13175
+ case "ddplay.json":
13176
+ if (file_wrapper) return new File([
13177
+ src_JSON.stringify(this.toDDPlay())
13178
+ ], "ddplay.json", {
13179
+ type: 'application/json'
13180
+ });
13181
+ return this.toDDPlay();
13147
13182
  default:
13148
13183
  {
13149
13184
  const message = '(err) Unknown format or unsupported now!';
@@ -13335,7 +13370,7 @@ class UniPool {
13335
13370
  static fromDDPlay(json, episodeId, options) {
13336
13371
  return new UniPool(json.comments.map((d)=>{
13337
13372
  const p_arr = d.p.split(',');
13338
- return UniDM.fromDDplay({
13373
+ return UniDM.fromDDPlay({
13339
13374
  cid: d.cid,
13340
13375
  color: Number.parseInt(p_arr[2]),
13341
13376
  m: d.m,
@@ -13347,7 +13382,7 @@ class UniPool {
13347
13382
  fromConverted: !!json.danuni
13348
13383
  });
13349
13384
  }
13350
- toDDplay() {
13385
+ toDDPlay() {
13351
13386
  const episodeId = this.dans[0].SOID.split('@')[0].replaceAll(`def_${platform_PlatformDanmakuOnlySource.DanDanPlay}+`, '');
13352
13387
  return {
13353
13388
  danuni: {
@@ -13356,7 +13391,7 @@ class UniPool {
13356
13391
  },
13357
13392
  count: this.dans.length,
13358
13393
  comments: this.dans.map((dan)=>{
13359
- const d = dan.toDDplay();
13394
+ const d = dan.toDDPlay();
13360
13395
  return {
13361
13396
  cid: d.cid,
13362
13397
  p: `${d.progress},${d.mode},${d.color},${d.uid}`,
@@ -127,7 +127,7 @@ export declare enum DM_format {
127
127
  BiliUpJson = "bili.up.json",
128
128
  DplayerJson = "dplayer.json",
129
129
  ArtplayerJson = "artplayer.json",
130
- DdplayJson = "ddplay.json",
130
+ DDPlayJson = "ddplay.json",
131
131
  CommonAss = "common.ass"
132
132
  }
133
133
  type shareItems = Partial<Pick<UniDMTools.UniDMObj, 'SOID' | 'senderID' | 'platform' | 'SOID' | 'pool' | 'mode' | 'color'>>;
@@ -141,6 +141,22 @@ export interface Options {
141
141
  */
142
142
  dmid?: boolean | number | UniIDTools.DMIDGenerator;
143
143
  }
144
+ type Convert2Format = DM_format.DanuniJson | DM_format.DanuniMinJson | DM_format.DanuniPbBin | DM_format.BiliXml | DM_format.DplayerJson | DM_format.ArtplayerJson | DM_format.DDPlayJson;
145
+ type Convert2ResultMap = {
146
+ [DM_format.DanuniJson]: UniDM[];
147
+ [DM_format.DanuniMinJson]: DM_JSON_DanuniMin;
148
+ [DM_format.DanuniPbBin]: Uint8Array;
149
+ [DM_format.BiliXml]: string;
150
+ [DM_format.DplayerJson]: DM_JSON_Dplayer & {
151
+ danuni?: DanUniConvertTip;
152
+ };
153
+ [DM_format.ArtplayerJson]: DM_JSON_Artplayer & {
154
+ danuni?: DanUniConvertTip;
155
+ };
156
+ [DM_format.DDPlayJson]: DM_JSON_DDPlay & {
157
+ danuni?: DanUniConvertTip;
158
+ };
159
+ };
144
160
  export declare class UniPool {
145
161
  dans: UniDM[];
146
162
  options: Options;
@@ -207,13 +223,8 @@ export declare class UniPool {
207
223
  pool: UniPool;
208
224
  fmt: DM_format;
209
225
  };
210
- convert2(format: DM_format, continue_on_error?: boolean): string | Uint8Array<ArrayBuffer> | UniDM[] | (Partial<UniDMTools.UniDMObj> & Pick<UniDMTools.UniDMObj, "SOID">)[] | (DM_JSON_Dplayer & {
211
- danuni?: DanUniConvertTip;
212
- }) | (DM_JSON_Artplayer & {
213
- danuni?: DanUniConvertTip;
214
- }) | (DM_JSON_DDPlay & {
215
- danuni?: DanUniConvertTip;
216
- });
226
+ convert2<T extends Convert2Format>(format: T, file_wrapper: true, continue_on_error?: boolean): File;
227
+ convert2<T extends Convert2Format>(format: T, file_wrapper?: false, continue_on_error?: boolean): Convert2ResultMap[T];
217
228
  static fromMin(json: DM_JSON_DanuniMin, options?: Options): UniPool;
218
229
  static fromPb(bin: Uint8Array | ArrayBuffer, options?: Options): UniPool;
219
230
  /**
@@ -254,7 +265,7 @@ export declare class UniPool {
254
265
  static fromDDPlay(json: DM_JSON_DDPlay & {
255
266
  danuni?: DanUniConvertTip;
256
267
  }, episodeId: string, options?: Options): UniPool;
257
- toDDplay(): DM_JSON_DDPlay & {
268
+ toDDPlay(): DM_JSON_DDPlay & {
258
269
  danuni?: DanUniConvertTip;
259
270
  };
260
271
  static fromASS(ass: string, options?: Options): UniPool;
@@ -62,7 +62,7 @@ interface DMArtplayer {
62
62
  border?: boolean;
63
63
  style?: object;
64
64
  }
65
- interface DMDDplay {
65
+ interface DMDDPlay {
66
66
  cid: bigint;
67
67
  /**
68
68
  * content
@@ -303,7 +303,7 @@ export declare class UniDM {
303
303
  toDplayer(): DMDplayer;
304
304
  static fromArtplayer(args: DMArtplayer, playerID: string, domain: string, options?: Options): UniDM;
305
305
  toArtplayer(): DMArtplayer;
306
- static fromDDplay(args: DMDDplay, episodeId: string, domain?: PlatformDanmakuOnlySource, options?: Options): UniDM;
307
- toDDplay(): DMDDplay;
306
+ static fromDDPlay(args: DMDDPlay, episodeId: string, domain?: PlatformDanmakuOnlySource, options?: Options): UniDM;
307
+ toDDPlay(): DMDDPlay;
308
308
  }
309
309
  export {};
@@ -39,7 +39,7 @@ __webpack_require__.d(platform_namespaceObject, {
39
39
  PlatformVideoSource: ()=>platform_PlatformVideoSource,
40
40
  PlatformVideoSources: ()=>PlatformVideoSources
41
41
  });
42
- var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.3.3","TB":"https://github.com/ani-uni/danuni/tree/master/packages/dan-any#readme"}');
42
+ var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.3.5","TB":"https://github.com/ani-uni/danuni/tree/master/packages/dan-any#readme"}');
43
43
  const color_pad = (s)=>s.length < 2 ? `0${s}` : s;
44
44
  const decimalToHex = (n)=>color_pad(n.toString(16));
45
45
  const isDarkColor = ({ r, g, b })=>0.299 * r + 0.587 * g + 0.114 * b < 0x30;
@@ -663,7 +663,7 @@ class UniDM {
663
663
  style: this.extra.artplayer?.style
664
664
  };
665
665
  }
666
- static fromDDplay(args, episodeId, domain = platform_PlatformDanmakuOnlySource.DanDanPlay, options) {
666
+ static fromDDPlay(args, episodeId, domain = platform_PlatformDanmakuOnlySource.DanDanPlay, options) {
667
667
  const SOID = id_gen_UniID.fromUnknown(`def_${platform_PlatformDanmakuOnlySource.DanDanPlay}+${episodeId}`, domain);
668
668
  return this.create({
669
669
  ...args,
@@ -675,7 +675,7 @@ class UniDM {
675
675
  DMID: args.cid.toString()
676
676
  }, options);
677
677
  }
678
- toDDplay() {
678
+ toDDPlay() {
679
679
  let mode = 1;
680
680
  if (2 === this.mode) mode = 5;
681
681
  else if (1 === this.mode) mode = 4;
@@ -879,8 +879,8 @@ _ts_decorate([
879
879
  Expose(),
880
880
  _ts_metadata("design:type", Function),
881
881
  _ts_metadata("design:paramtypes", []),
882
- _ts_metadata("design:returntype", "u" < typeof DMDDplay ? Object : DMDDplay)
883
- ], UniDM.prototype, "toDDplay", null);
882
+ _ts_metadata("design:returntype", "u" < typeof DMDDPlay ? Object : DMDDPlay)
883
+ ], UniDM.prototype, "toDDPlay", null);
884
884
  const DanmakuType = {
885
885
  SCROLL: 1,
886
886
  BOTTOM: 2,
@@ -1339,7 +1339,7 @@ var src_DM_format = /*#__PURE__*/ function(DM_format) {
1339
1339
  DM_format["BiliUpJson"] = "bili.up.json";
1340
1340
  DM_format["DplayerJson"] = "dplayer.json";
1341
1341
  DM_format["ArtplayerJson"] = "artplayer.json";
1342
- DM_format["DdplayJson"] = "ddplay.json";
1342
+ DM_format["DDPlayJson"] = "ddplay.json";
1343
1343
  DM_format["CommonAss"] = "common.ass";
1344
1344
  return DM_format;
1345
1345
  }({});
@@ -1703,22 +1703,57 @@ class UniPool {
1703
1703
  }
1704
1704
  throw new Error(errmesg ?? err);
1705
1705
  }
1706
- convert2(format, continue_on_error = false) {
1706
+ convert2(format, file_wrapper = false, continue_on_error = false) {
1707
1707
  switch(format){
1708
- case 'danuni.json':
1708
+ case "danuni.json":
1709
+ if (file_wrapper) return new File([
1710
+ src_JSON.stringify(this.dans)
1711
+ ], "danuni.json", {
1712
+ type: 'application/json'
1713
+ });
1709
1714
  return this.dans;
1710
- case 'danuni.min.json':
1715
+ case "danuni.min.json":
1716
+ if (file_wrapper) return new File([
1717
+ src_JSON.stringify(this.minify())
1718
+ ], "danuni.min.json", {
1719
+ type: 'application/json'
1720
+ });
1711
1721
  return this.minify();
1712
- case 'danuni.binpb':
1722
+ case "danuni.binpb":
1723
+ if (file_wrapper) return new File([
1724
+ this.toPb()
1725
+ ], "danuni.binpb", {
1726
+ type: 'application/protobuf'
1727
+ });
1713
1728
  return this.toPb();
1714
- case 'bili.xml':
1729
+ case "bili.xml":
1730
+ if (file_wrapper) return new File([
1731
+ this.toBiliXML()
1732
+ ], "bili.xml", {
1733
+ type: 'application/xml'
1734
+ });
1715
1735
  return this.toBiliXML();
1716
- case 'dplayer.json':
1736
+ case "dplayer.json":
1737
+ if (file_wrapper) return new File([
1738
+ src_JSON.stringify(this.toDplayer())
1739
+ ], "dplayer.json", {
1740
+ type: 'application/json'
1741
+ });
1717
1742
  return this.toDplayer();
1718
- case 'artplayer.json':
1743
+ case "artplayer.json":
1744
+ if (file_wrapper) return new File([
1745
+ src_JSON.stringify(this.toArtplayer())
1746
+ ], "artplayer.json", {
1747
+ type: 'application/json'
1748
+ });
1719
1749
  return this.toArtplayer();
1720
- case 'ddplay.json':
1721
- return this.toDDplay();
1750
+ case "ddplay.json":
1751
+ if (file_wrapper) return new File([
1752
+ src_JSON.stringify(this.toDDPlay())
1753
+ ], "ddplay.json", {
1754
+ type: 'application/json'
1755
+ });
1756
+ return this.toDDPlay();
1722
1757
  default:
1723
1758
  {
1724
1759
  const message = '(err) Unknown format or unsupported now!';
@@ -1910,7 +1945,7 @@ class UniPool {
1910
1945
  static fromDDPlay(json, episodeId, options) {
1911
1946
  return new UniPool(json.comments.map((d)=>{
1912
1947
  const p_arr = d.p.split(',');
1913
- return UniDM.fromDDplay({
1948
+ return UniDM.fromDDPlay({
1914
1949
  cid: d.cid,
1915
1950
  color: Number.parseInt(p_arr[2]),
1916
1951
  m: d.m,
@@ -1922,7 +1957,7 @@ class UniPool {
1922
1957
  fromConverted: !!json.danuni
1923
1958
  });
1924
1959
  }
1925
- toDDplay() {
1960
+ toDDPlay() {
1926
1961
  const episodeId = this.dans[0].SOID.split('@')[0].replaceAll(`def_${platform_PlatformDanmakuOnlySource.DanDanPlay}+`, '');
1927
1962
  return {
1928
1963
  danuni: {
@@ -1931,7 +1966,7 @@ class UniPool {
1931
1966
  },
1932
1967
  count: this.dans.length,
1933
1968
  comments: this.dans.map((dan)=>{
1934
- const d = dan.toDDplay();
1969
+ const d = dan.toDDPlay();
1935
1970
  return {
1936
1971
  cid: d.cid,
1937
1972
  p: `${d.progress},${d.mode},${d.color},${d.uid}`,
@@ -127,7 +127,7 @@ export declare enum DM_format {
127
127
  BiliUpJson = "bili.up.json",
128
128
  DplayerJson = "dplayer.json",
129
129
  ArtplayerJson = "artplayer.json",
130
- DdplayJson = "ddplay.json",
130
+ DDPlayJson = "ddplay.json",
131
131
  CommonAss = "common.ass"
132
132
  }
133
133
  type shareItems = Partial<Pick<UniDMTools.UniDMObj, 'SOID' | 'senderID' | 'platform' | 'SOID' | 'pool' | 'mode' | 'color'>>;
@@ -141,6 +141,22 @@ export interface Options {
141
141
  */
142
142
  dmid?: boolean | number | UniIDTools.DMIDGenerator;
143
143
  }
144
+ type Convert2Format = DM_format.DanuniJson | DM_format.DanuniMinJson | DM_format.DanuniPbBin | DM_format.BiliXml | DM_format.DplayerJson | DM_format.ArtplayerJson | DM_format.DDPlayJson;
145
+ type Convert2ResultMap = {
146
+ [DM_format.DanuniJson]: UniDM[];
147
+ [DM_format.DanuniMinJson]: DM_JSON_DanuniMin;
148
+ [DM_format.DanuniPbBin]: Uint8Array;
149
+ [DM_format.BiliXml]: string;
150
+ [DM_format.DplayerJson]: DM_JSON_Dplayer & {
151
+ danuni?: DanUniConvertTip;
152
+ };
153
+ [DM_format.ArtplayerJson]: DM_JSON_Artplayer & {
154
+ danuni?: DanUniConvertTip;
155
+ };
156
+ [DM_format.DDPlayJson]: DM_JSON_DDPlay & {
157
+ danuni?: DanUniConvertTip;
158
+ };
159
+ };
144
160
  export declare class UniPool {
145
161
  dans: UniDM[];
146
162
  options: Options;
@@ -207,13 +223,8 @@ export declare class UniPool {
207
223
  pool: UniPool;
208
224
  fmt: DM_format;
209
225
  };
210
- convert2(format: DM_format, continue_on_error?: boolean): string | Uint8Array<ArrayBuffer> | UniDM[] | (Partial<UniDMTools.UniDMObj> & Pick<UniDMTools.UniDMObj, "SOID">)[] | (DM_JSON_Dplayer & {
211
- danuni?: DanUniConvertTip;
212
- }) | (DM_JSON_Artplayer & {
213
- danuni?: DanUniConvertTip;
214
- }) | (DM_JSON_DDPlay & {
215
- danuni?: DanUniConvertTip;
216
- });
226
+ convert2<T extends Convert2Format>(format: T, file_wrapper: true, continue_on_error?: boolean): File;
227
+ convert2<T extends Convert2Format>(format: T, file_wrapper?: false, continue_on_error?: boolean): Convert2ResultMap[T];
217
228
  static fromMin(json: DM_JSON_DanuniMin, options?: Options): UniPool;
218
229
  static fromPb(bin: Uint8Array | ArrayBuffer, options?: Options): UniPool;
219
230
  /**
@@ -254,7 +265,7 @@ export declare class UniPool {
254
265
  static fromDDPlay(json: DM_JSON_DDPlay & {
255
266
  danuni?: DanUniConvertTip;
256
267
  }, episodeId: string, options?: Options): UniPool;
257
- toDDplay(): DM_JSON_DDPlay & {
268
+ toDDPlay(): DM_JSON_DDPlay & {
258
269
  danuni?: DanUniConvertTip;
259
270
  };
260
271
  static fromASS(ass: string, options?: Options): UniPool;
@@ -62,7 +62,7 @@ interface DMArtplayer {
62
62
  border?: boolean;
63
63
  style?: object;
64
64
  }
65
- interface DMDDplay {
65
+ interface DMDDPlay {
66
66
  cid: bigint;
67
67
  /**
68
68
  * content
@@ -303,7 +303,7 @@ export declare class UniDM {
303
303
  toDplayer(): DMDplayer;
304
304
  static fromArtplayer(args: DMArtplayer, playerID: string, domain: string, options?: Options): UniDM;
305
305
  toArtplayer(): DMArtplayer;
306
- static fromDDplay(args: DMDDplay, episodeId: string, domain?: PlatformDanmakuOnlySource, options?: Options): UniDM;
307
- toDDplay(): DMDDplay;
306
+ static fromDDPlay(args: DMDDPlay, episodeId: string, domain?: PlatformDanmakuOnlySource, options?: Options): UniDM;
307
+ toDDPlay(): DMDDPlay;
308
308
  }
309
309
  export {};
@@ -21770,7 +21770,7 @@ and limitations under the License.
21770
21770
  function timestamp_timestampMs(timestamp) {
21771
21771
  return 1000 * Number(timestamp.seconds) + Math.round(timestamp.nanos / 1000000);
21772
21772
  }
21773
- var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.3.3","TB":"https://github.com/ani-uni/danuni/tree/master/packages/dan-any#readme"}');
21773
+ var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.3.5","TB":"https://github.com/ani-uni/danuni/tree/master/packages/dan-any#readme"}');
21774
21774
  const color_pad = (s)=>s.length < 2 ? `0${s}` : s;
21775
21775
  const decimalToHex = (n)=>color_pad(n.toString(16));
21776
21776
  const isDarkColor = ({ r, g, b })=>0.299 * r + 0.587 * g + 0.114 * b < 0x30;
@@ -24573,7 +24573,7 @@ and limitations under the License.
24573
24573
  style: this.extra.artplayer?.style
24574
24574
  };
24575
24575
  }
24576
- static fromDDplay(args, episodeId, domain = platform.PlatformDanmakuOnlySource.DanDanPlay, options) {
24576
+ static fromDDPlay(args, episodeId, domain = platform.PlatformDanmakuOnlySource.DanDanPlay, options) {
24577
24577
  const SOID = id_gen_UniID.fromUnknown(`def_${platform.PlatformDanmakuOnlySource.DanDanPlay}+${episodeId}`, domain);
24578
24578
  return this.create({
24579
24579
  ...args,
@@ -24585,7 +24585,7 @@ and limitations under the License.
24585
24585
  DMID: args.cid.toString()
24586
24586
  }, options);
24587
24587
  }
24588
- toDDplay() {
24588
+ toDDPlay() {
24589
24589
  let mode = 1;
24590
24590
  if (2 === this.mode) mode = 5;
24591
24591
  else if (1 === this.mode) mode = 4;
@@ -24789,8 +24789,8 @@ and limitations under the License.
24789
24789
  Expose(),
24790
24790
  _ts_metadata("design:type", Function),
24791
24791
  _ts_metadata("design:paramtypes", []),
24792
- _ts_metadata("design:returntype", "u" < typeof DMDDplay ? Object : DMDDplay)
24793
- ], UniDM.prototype, "toDDplay", null);
24792
+ _ts_metadata("design:returntype", "u" < typeof DMDDPlay ? Object : DMDDPlay)
24793
+ ], UniDM.prototype, "toDDPlay", null);
24794
24794
  const DanmakuType = {
24795
24795
  SCROLL: 1,
24796
24796
  BOTTOM: 2,
@@ -25252,7 +25252,7 @@ and limitations under the License.
25252
25252
  DM_format["BiliUpJson"] = "bili.up.json";
25253
25253
  DM_format["DplayerJson"] = "dplayer.json";
25254
25254
  DM_format["ArtplayerJson"] = "artplayer.json";
25255
- DM_format["DdplayJson"] = "ddplay.json";
25255
+ DM_format["DDPlayJson"] = "ddplay.json";
25256
25256
  DM_format["CommonAss"] = "common.ass";
25257
25257
  return DM_format;
25258
25258
  }({});
@@ -25616,22 +25616,57 @@ and limitations under the License.
25616
25616
  }
25617
25617
  throw new Error(errmesg ?? err);
25618
25618
  }
25619
- convert2(format, continue_on_error = false) {
25619
+ convert2(format, file_wrapper = false, continue_on_error = false) {
25620
25620
  switch(format){
25621
- case 'danuni.json':
25621
+ case "danuni.json":
25622
+ if (file_wrapper) return new File([
25623
+ src_JSON.stringify(this.dans)
25624
+ ], "danuni.json", {
25625
+ type: 'application/json'
25626
+ });
25622
25627
  return this.dans;
25623
- case 'danuni.min.json':
25628
+ case "danuni.min.json":
25629
+ if (file_wrapper) return new File([
25630
+ src_JSON.stringify(this.minify())
25631
+ ], "danuni.min.json", {
25632
+ type: 'application/json'
25633
+ });
25624
25634
  return this.minify();
25625
- case 'danuni.binpb':
25635
+ case "danuni.binpb":
25636
+ if (file_wrapper) return new File([
25637
+ this.toPb()
25638
+ ], "danuni.binpb", {
25639
+ type: 'application/protobuf'
25640
+ });
25626
25641
  return this.toPb();
25627
- case 'bili.xml':
25642
+ case "bili.xml":
25643
+ if (file_wrapper) return new File([
25644
+ this.toBiliXML()
25645
+ ], "bili.xml", {
25646
+ type: 'application/xml'
25647
+ });
25628
25648
  return this.toBiliXML();
25629
- case 'dplayer.json':
25649
+ case "dplayer.json":
25650
+ if (file_wrapper) return new File([
25651
+ src_JSON.stringify(this.toDplayer())
25652
+ ], "dplayer.json", {
25653
+ type: 'application/json'
25654
+ });
25630
25655
  return this.toDplayer();
25631
- case 'artplayer.json':
25656
+ case "artplayer.json":
25657
+ if (file_wrapper) return new File([
25658
+ src_JSON.stringify(this.toArtplayer())
25659
+ ], "artplayer.json", {
25660
+ type: 'application/json'
25661
+ });
25632
25662
  return this.toArtplayer();
25633
- case 'ddplay.json':
25634
- return this.toDDplay();
25663
+ case "ddplay.json":
25664
+ if (file_wrapper) return new File([
25665
+ src_JSON.stringify(this.toDDPlay())
25666
+ ], "ddplay.json", {
25667
+ type: 'application/json'
25668
+ });
25669
+ return this.toDDPlay();
25635
25670
  default:
25636
25671
  {
25637
25672
  const message = '(err) Unknown format or unsupported now!';
@@ -25823,7 +25858,7 @@ and limitations under the License.
25823
25858
  static fromDDPlay(json, episodeId, options) {
25824
25859
  return new UniPool(json.comments.map((d)=>{
25825
25860
  const p_arr = d.p.split(',');
25826
- return UniDM.fromDDplay({
25861
+ return UniDM.fromDDPlay({
25827
25862
  cid: d.cid,
25828
25863
  color: Number.parseInt(p_arr[2]),
25829
25864
  m: d.m,
@@ -25835,7 +25870,7 @@ and limitations under the License.
25835
25870
  fromConverted: !!json.danuni
25836
25871
  });
25837
25872
  }
25838
- toDDplay() {
25873
+ toDDPlay() {
25839
25874
  const episodeId = this.dans[0].SOID.split('@')[0].replaceAll(`def_${platform.PlatformDanmakuOnlySource.DanDanPlay}+`, '');
25840
25875
  return {
25841
25876
  danuni: {
@@ -25844,7 +25879,7 @@ and limitations under the License.
25844
25879
  },
25845
25880
  count: this.dans.length,
25846
25881
  comments: this.dans.map((dan)=>{
25847
- const d = dan.toDDplay();
25882
+ const d = dan.toDDPlay();
25848
25883
  return {
25849
25884
  cid: d.cid,
25850
25885
  p: `${d.progress},${d.mode},${d.color},${d.uid}`,
@@ -21060,7 +21060,7 @@
21060
21060
  function timestamp_timestampMs(timestamp) {
21061
21061
  return 1000 * Number(timestamp.seconds) + Math.round(timestamp.nanos / 1000000);
21062
21062
  }
21063
- var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.3.3","TB":"https://github.com/ani-uni/danuni/tree/master/packages/dan-any#readme"}');
21063
+ var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.3.5","TB":"https://github.com/ani-uni/danuni/tree/master/packages/dan-any#readme"}');
21064
21064
  const color_pad = (s)=>s.length < 2 ? `0${s}` : s;
21065
21065
  const decimalToHex = (n)=>color_pad(n.toString(16));
21066
21066
  const isDarkColor = ({ r, g, b })=>0.299 * r + 0.587 * g + 0.114 * b < 0x30;
@@ -23843,7 +23843,7 @@
23843
23843
  style: this.extra.artplayer?.style
23844
23844
  };
23845
23845
  }
23846
- static fromDDplay(args, episodeId, domain = platform.PlatformDanmakuOnlySource.DanDanPlay, options) {
23846
+ static fromDDPlay(args, episodeId, domain = platform.PlatformDanmakuOnlySource.DanDanPlay, options) {
23847
23847
  const SOID = id_gen_UniID.fromUnknown(`def_${platform.PlatformDanmakuOnlySource.DanDanPlay}+${episodeId}`, domain);
23848
23848
  return this.create({
23849
23849
  ...args,
@@ -23855,7 +23855,7 @@
23855
23855
  DMID: args.cid.toString()
23856
23856
  }, options);
23857
23857
  }
23858
- toDDplay() {
23858
+ toDDPlay() {
23859
23859
  let mode = 1;
23860
23860
  if (2 === this.mode) mode = 5;
23861
23861
  else if (1 === this.mode) mode = 4;
@@ -24059,8 +24059,8 @@
24059
24059
  Expose(),
24060
24060
  _ts_metadata("design:type", Function),
24061
24061
  _ts_metadata("design:paramtypes", []),
24062
- _ts_metadata("design:returntype", "u" < typeof DMDDplay ? Object : DMDDplay)
24063
- ], UniDM.prototype, "toDDplay", null);
24062
+ _ts_metadata("design:returntype", "u" < typeof DMDDPlay ? Object : DMDDPlay)
24063
+ ], UniDM.prototype, "toDDPlay", null);
24064
24064
  const DanmakuType = {
24065
24065
  SCROLL: 1,
24066
24066
  BOTTOM: 2,
@@ -24872,22 +24872,57 @@
24872
24872
  }
24873
24873
  throw new Error(errmesg ?? err);
24874
24874
  }
24875
- convert2(format, continue_on_error = false) {
24875
+ convert2(format, file_wrapper = false, continue_on_error = false) {
24876
24876
  switch(format){
24877
- case 'danuni.json':
24877
+ case "danuni.json":
24878
+ if (file_wrapper) return new File([
24879
+ src_JSON.stringify(this.dans)
24880
+ ], "danuni.json", {
24881
+ type: 'application/json'
24882
+ });
24878
24883
  return this.dans;
24879
- case 'danuni.min.json':
24884
+ case "danuni.min.json":
24885
+ if (file_wrapper) return new File([
24886
+ src_JSON.stringify(this.minify())
24887
+ ], "danuni.min.json", {
24888
+ type: 'application/json'
24889
+ });
24880
24890
  return this.minify();
24881
- case 'danuni.binpb':
24891
+ case "danuni.binpb":
24892
+ if (file_wrapper) return new File([
24893
+ this.toPb()
24894
+ ], "danuni.binpb", {
24895
+ type: 'application/protobuf'
24896
+ });
24882
24897
  return this.toPb();
24883
- case 'bili.xml':
24898
+ case "bili.xml":
24899
+ if (file_wrapper) return new File([
24900
+ this.toBiliXML()
24901
+ ], "bili.xml", {
24902
+ type: 'application/xml'
24903
+ });
24884
24904
  return this.toBiliXML();
24885
- case 'dplayer.json':
24905
+ case "dplayer.json":
24906
+ if (file_wrapper) return new File([
24907
+ src_JSON.stringify(this.toDplayer())
24908
+ ], "dplayer.json", {
24909
+ type: 'application/json'
24910
+ });
24886
24911
  return this.toDplayer();
24887
- case 'artplayer.json':
24912
+ case "artplayer.json":
24913
+ if (file_wrapper) return new File([
24914
+ src_JSON.stringify(this.toArtplayer())
24915
+ ], "artplayer.json", {
24916
+ type: 'application/json'
24917
+ });
24888
24918
  return this.toArtplayer();
24889
- case 'ddplay.json':
24890
- return this.toDDplay();
24919
+ case "ddplay.json":
24920
+ if (file_wrapper) return new File([
24921
+ src_JSON.stringify(this.toDDPlay())
24922
+ ], "ddplay.json", {
24923
+ type: 'application/json'
24924
+ });
24925
+ return this.toDDPlay();
24891
24926
  default:
24892
24927
  {
24893
24928
  const message = '(err) Unknown format or unsupported now!';
@@ -25079,7 +25114,7 @@
25079
25114
  static fromDDPlay(json, episodeId, options) {
25080
25115
  return new UniPool(json.comments.map((d)=>{
25081
25116
  const p_arr = d.p.split(',');
25082
- return UniDM.fromDDplay({
25117
+ return UniDM.fromDDPlay({
25083
25118
  cid: d.cid,
25084
25119
  color: Number.parseInt(p_arr[2]),
25085
25120
  m: d.m,
@@ -25091,7 +25126,7 @@
25091
25126
  fromConverted: !!json.danuni
25092
25127
  });
25093
25128
  }
25094
- toDDplay() {
25129
+ toDDPlay() {
25095
25130
  const episodeId = this.dans[0].SOID.split('@')[0].replaceAll(`def_${platform.PlatformDanmakuOnlySource.DanDanPlay}+`, '');
25096
25131
  return {
25097
25132
  danuni: {
@@ -25100,7 +25135,7 @@
25100
25135
  },
25101
25136
  count: this.dans.length,
25102
25137
  comments: this.dans.map((dan)=>{
25103
- const d = dan.toDDplay();
25138
+ const d = dan.toDDPlay();
25104
25139
  return {
25105
25140
  cid: d.cid,
25106
25141
  p: `${d.progress},${d.mode},${d.color},${d.uid}`,
@@ -21060,7 +21060,7 @@
21060
21060
  function timestamp_timestampMs(timestamp) {
21061
21061
  return 1000 * Number(timestamp.seconds) + Math.round(timestamp.nanos / 1000000);
21062
21062
  }
21063
- var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.3.3","TB":"https://github.com/ani-uni/danuni/tree/master/packages/dan-any#readme"}');
21063
+ var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.3.5","TB":"https://github.com/ani-uni/danuni/tree/master/packages/dan-any#readme"}');
21064
21064
  const color_pad = (s)=>s.length < 2 ? `0${s}` : s;
21065
21065
  const decimalToHex = (n)=>color_pad(n.toString(16));
21066
21066
  const isDarkColor = ({ r, g, b })=>0.299 * r + 0.587 * g + 0.114 * b < 0x30;
@@ -23843,7 +23843,7 @@
23843
23843
  style: this.extra.artplayer?.style
23844
23844
  };
23845
23845
  }
23846
- static fromDDplay(args, episodeId, domain = platform.PlatformDanmakuOnlySource.DanDanPlay, options) {
23846
+ static fromDDPlay(args, episodeId, domain = platform.PlatformDanmakuOnlySource.DanDanPlay, options) {
23847
23847
  const SOID = id_gen_UniID.fromUnknown(`def_${platform.PlatformDanmakuOnlySource.DanDanPlay}+${episodeId}`, domain);
23848
23848
  return this.create({
23849
23849
  ...args,
@@ -23855,7 +23855,7 @@
23855
23855
  DMID: args.cid.toString()
23856
23856
  }, options);
23857
23857
  }
23858
- toDDplay() {
23858
+ toDDPlay() {
23859
23859
  let mode = 1;
23860
23860
  if (2 === this.mode) mode = 5;
23861
23861
  else if (1 === this.mode) mode = 4;
@@ -24059,8 +24059,8 @@
24059
24059
  Expose(),
24060
24060
  _ts_metadata("design:type", Function),
24061
24061
  _ts_metadata("design:paramtypes", []),
24062
- _ts_metadata("design:returntype", "u" < typeof DMDDplay ? Object : DMDDplay)
24063
- ], UniDM.prototype, "toDDplay", null);
24062
+ _ts_metadata("design:returntype", "u" < typeof DMDDPlay ? Object : DMDDPlay)
24063
+ ], UniDM.prototype, "toDDPlay", null);
24064
24064
  const DanmakuType = {
24065
24065
  SCROLL: 1,
24066
24066
  BOTTOM: 2,
@@ -24872,22 +24872,57 @@
24872
24872
  }
24873
24873
  throw new Error(errmesg ?? err);
24874
24874
  }
24875
- convert2(format, continue_on_error = false) {
24875
+ convert2(format, file_wrapper = false, continue_on_error = false) {
24876
24876
  switch(format){
24877
- case 'danuni.json':
24877
+ case "danuni.json":
24878
+ if (file_wrapper) return new File([
24879
+ src_JSON.stringify(this.dans)
24880
+ ], "danuni.json", {
24881
+ type: 'application/json'
24882
+ });
24878
24883
  return this.dans;
24879
- case 'danuni.min.json':
24884
+ case "danuni.min.json":
24885
+ if (file_wrapper) return new File([
24886
+ src_JSON.stringify(this.minify())
24887
+ ], "danuni.min.json", {
24888
+ type: 'application/json'
24889
+ });
24880
24890
  return this.minify();
24881
- case 'danuni.binpb':
24891
+ case "danuni.binpb":
24892
+ if (file_wrapper) return new File([
24893
+ this.toPb()
24894
+ ], "danuni.binpb", {
24895
+ type: 'application/protobuf'
24896
+ });
24882
24897
  return this.toPb();
24883
- case 'bili.xml':
24898
+ case "bili.xml":
24899
+ if (file_wrapper) return new File([
24900
+ this.toBiliXML()
24901
+ ], "bili.xml", {
24902
+ type: 'application/xml'
24903
+ });
24884
24904
  return this.toBiliXML();
24885
- case 'dplayer.json':
24905
+ case "dplayer.json":
24906
+ if (file_wrapper) return new File([
24907
+ src_JSON.stringify(this.toDplayer())
24908
+ ], "dplayer.json", {
24909
+ type: 'application/json'
24910
+ });
24886
24911
  return this.toDplayer();
24887
- case 'artplayer.json':
24912
+ case "artplayer.json":
24913
+ if (file_wrapper) return new File([
24914
+ src_JSON.stringify(this.toArtplayer())
24915
+ ], "artplayer.json", {
24916
+ type: 'application/json'
24917
+ });
24888
24918
  return this.toArtplayer();
24889
- case 'ddplay.json':
24890
- return this.toDDplay();
24919
+ case "ddplay.json":
24920
+ if (file_wrapper) return new File([
24921
+ src_JSON.stringify(this.toDDPlay())
24922
+ ], "ddplay.json", {
24923
+ type: 'application/json'
24924
+ });
24925
+ return this.toDDPlay();
24891
24926
  default:
24892
24927
  {
24893
24928
  const message = '(err) Unknown format or unsupported now!';
@@ -25079,7 +25114,7 @@
25079
25114
  static fromDDPlay(json, episodeId, options) {
25080
25115
  return new UniPool(json.comments.map((d)=>{
25081
25116
  const p_arr = d.p.split(',');
25082
- return UniDM.fromDDplay({
25117
+ return UniDM.fromDDPlay({
25083
25118
  cid: d.cid,
25084
25119
  color: Number.parseInt(p_arr[2]),
25085
25120
  m: d.m,
@@ -25091,7 +25126,7 @@
25091
25126
  fromConverted: !!json.danuni
25092
25127
  });
25093
25128
  }
25094
- toDDplay() {
25129
+ toDDPlay() {
25095
25130
  const episodeId = this.dans[0].SOID.split('@')[0].replaceAll(`def_${platform.PlatformDanmakuOnlySource.DanDanPlay}+`, '');
25096
25131
  return {
25097
25132
  danuni: {
@@ -25100,7 +25135,7 @@
25100
25135
  },
25101
25136
  count: this.dans.length,
25102
25137
  comments: this.dans.map((dan)=>{
25103
- const d = dan.toDDplay();
25138
+ const d = dan.toDDPlay();
25104
25139
  return {
25105
25140
  cid: d.cid,
25106
25141
  p: `${d.progress},${d.mode},${d.color},${d.uid}`,
@@ -127,7 +127,7 @@ export declare enum DM_format {
127
127
  BiliUpJson = "bili.up.json",
128
128
  DplayerJson = "dplayer.json",
129
129
  ArtplayerJson = "artplayer.json",
130
- DdplayJson = "ddplay.json",
130
+ DDPlayJson = "ddplay.json",
131
131
  CommonAss = "common.ass"
132
132
  }
133
133
  type shareItems = Partial<Pick<UniDMTools.UniDMObj, 'SOID' | 'senderID' | 'platform' | 'SOID' | 'pool' | 'mode' | 'color'>>;
@@ -141,6 +141,22 @@ export interface Options {
141
141
  */
142
142
  dmid?: boolean | number | UniIDTools.DMIDGenerator;
143
143
  }
144
+ type Convert2Format = DM_format.DanuniJson | DM_format.DanuniMinJson | DM_format.DanuniPbBin | DM_format.BiliXml | DM_format.DplayerJson | DM_format.ArtplayerJson | DM_format.DDPlayJson;
145
+ type Convert2ResultMap = {
146
+ [DM_format.DanuniJson]: UniDM[];
147
+ [DM_format.DanuniMinJson]: DM_JSON_DanuniMin;
148
+ [DM_format.DanuniPbBin]: Uint8Array;
149
+ [DM_format.BiliXml]: string;
150
+ [DM_format.DplayerJson]: DM_JSON_Dplayer & {
151
+ danuni?: DanUniConvertTip;
152
+ };
153
+ [DM_format.ArtplayerJson]: DM_JSON_Artplayer & {
154
+ danuni?: DanUniConvertTip;
155
+ };
156
+ [DM_format.DDPlayJson]: DM_JSON_DDPlay & {
157
+ danuni?: DanUniConvertTip;
158
+ };
159
+ };
144
160
  export declare class UniPool {
145
161
  dans: UniDM[];
146
162
  options: Options;
@@ -207,13 +223,8 @@ export declare class UniPool {
207
223
  pool: UniPool;
208
224
  fmt: DM_format;
209
225
  };
210
- convert2(format: DM_format, continue_on_error?: boolean): string | Uint8Array<ArrayBuffer> | UniDM[] | (Partial<UniDMTools.UniDMObj> & Pick<UniDMTools.UniDMObj, "SOID">)[] | (DM_JSON_Dplayer & {
211
- danuni?: DanUniConvertTip;
212
- }) | (DM_JSON_Artplayer & {
213
- danuni?: DanUniConvertTip;
214
- }) | (DM_JSON_DDPlay & {
215
- danuni?: DanUniConvertTip;
216
- });
226
+ convert2<T extends Convert2Format>(format: T, file_wrapper: true, continue_on_error?: boolean): File;
227
+ convert2<T extends Convert2Format>(format: T, file_wrapper?: false, continue_on_error?: boolean): Convert2ResultMap[T];
217
228
  static fromMin(json: DM_JSON_DanuniMin, options?: Options): UniPool;
218
229
  static fromPb(bin: Uint8Array | ArrayBuffer, options?: Options): UniPool;
219
230
  /**
@@ -254,7 +265,7 @@ export declare class UniPool {
254
265
  static fromDDPlay(json: DM_JSON_DDPlay & {
255
266
  danuni?: DanUniConvertTip;
256
267
  }, episodeId: string, options?: Options): UniPool;
257
- toDDplay(): DM_JSON_DDPlay & {
268
+ toDDPlay(): DM_JSON_DDPlay & {
258
269
  danuni?: DanUniConvertTip;
259
270
  };
260
271
  static fromASS(ass: string, options?: Options): UniPool;
@@ -62,7 +62,7 @@ interface DMArtplayer {
62
62
  border?: boolean;
63
63
  style?: object;
64
64
  }
65
- interface DMDDplay {
65
+ interface DMDDPlay {
66
66
  cid: bigint;
67
67
  /**
68
68
  * content
@@ -303,7 +303,7 @@ export declare class UniDM {
303
303
  toDplayer(): DMDplayer;
304
304
  static fromArtplayer(args: DMArtplayer, playerID: string, domain: string, options?: Options): UniDM;
305
305
  toArtplayer(): DMArtplayer;
306
- static fromDDplay(args: DMDDplay, episodeId: string, domain?: PlatformDanmakuOnlySource, options?: Options): UniDM;
307
- toDDplay(): DMDDplay;
306
+ static fromDDPlay(args: DMDDPlay, episodeId: string, domain?: PlatformDanmakuOnlySource, options?: Options): UniDM;
307
+ toDDPlay(): DMDDPlay;
308
308
  }
309
309
  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.3.3",
4
+ "version": "1.3.5",
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/src/index.test.ts CHANGED
@@ -85,9 +85,9 @@ describe('转化自', () => {
85
85
  const imp2 = UniPool.import(pb, undefined, 'test-danuni.binpb')
86
86
  expect(imp2).toEqual(imp)
87
87
  })
88
- it('DDplay[双向]', () => {
88
+ it('DDPlay[双向]', () => {
89
89
  const pool = UniPool.fromBiliXML(xml)
90
- const ddplay = pool.toDDplay()
90
+ const ddplay = pool.toDDPlay()
91
91
  console.info(UniPool.fromDDPlay(ddplay, '1'))
92
92
  const imp = UniPool.import(ddplay)
93
93
  expect(imp.fmt).toBe('ddplay.json')
package/src/index.ts CHANGED
@@ -165,7 +165,7 @@ export enum DM_format {
165
165
  BiliUpJson = 'bili.up.json',
166
166
  DplayerJson = 'dplayer.json',
167
167
  ArtplayerJson = 'artplayer.json',
168
- DdplayJson = 'ddplay.json',
168
+ DDPlayJson = 'ddplay.json',
169
169
  CommonAss = 'common.ass',
170
170
  }
171
171
 
@@ -200,6 +200,24 @@ export interface Options {
200
200
  dmid?: boolean | number | UniIDTools.DMIDGenerator
201
201
  }
202
202
 
203
+ type Convert2Format =
204
+ | DM_format.DanuniJson
205
+ | DM_format.DanuniMinJson
206
+ | DM_format.DanuniPbBin
207
+ | DM_format.BiliXml
208
+ | DM_format.DplayerJson
209
+ | DM_format.ArtplayerJson
210
+ | DM_format.DDPlayJson
211
+ type Convert2ResultMap = {
212
+ [DM_format.DanuniJson]: UniDM[]
213
+ [DM_format.DanuniMinJson]: DM_JSON_DanuniMin
214
+ [DM_format.DanuniPbBin]: Uint8Array
215
+ [DM_format.BiliXml]: string
216
+ [DM_format.DplayerJson]: DM_JSON_Dplayer & { danuni?: DanUniConvertTip }
217
+ [DM_format.ArtplayerJson]: DM_JSON_Artplayer & { danuni?: DanUniConvertTip }
218
+ [DM_format.DDPlayJson]: DM_JSON_DDPlay & { danuni?: DanUniConvertTip }
219
+ }
220
+
203
221
  export class UniPool {
204
222
  constructor(
205
223
  public dans: UniDM[],
@@ -517,13 +535,13 @@ export class UniPool {
517
535
  ),
518
536
  fmt: DM_format.ArtplayerJson,
519
537
  }),
520
- [DM_format.DdplayJson]: (
538
+ [DM_format.DDPlayJson]: (
521
539
  json: DM_JSON_DDPlay & {
522
540
  danuni?: DanUniConvertTip
523
541
  },
524
542
  ) => ({
525
543
  pool: this.fromDDPlay(json, json.danuni?.data ?? '', options),
526
- fmt: DM_format.DdplayJson,
544
+ fmt: DM_format.DDPlayJson,
527
545
  }),
528
546
  [DM_format.CommonAss]: (file: string) => ({
529
547
  pool: this.fromASS(file, options),
@@ -553,8 +571,8 @@ export class UniPool {
553
571
  return handlers[DM_format.DplayerJson](fileParser(file, 'json'))
554
572
  else if (fn.endsWith(DM_format.ArtplayerJson))
555
573
  return handlers[DM_format.ArtplayerJson](fileParser(file, 'json'))
556
- else if (fn.endsWith(DM_format.DdplayJson))
557
- return handlers[DM_format.DdplayJson](fileParser(file, 'json'))
574
+ else if (fn.endsWith(DM_format.DDPlayJson))
575
+ return handlers[DM_format.DDPlayJson](fileParser(file, 'json'))
558
576
  else if (fn.endsWith(DM_format.CommonAss))
559
577
  return handlers[DM_format.CommonAss](fileParser(file, 'string'))
560
578
  } catch {}
@@ -585,7 +603,7 @@ export class UniPool {
585
603
  Array.isArray(json.comments) &&
586
604
  json.comments.every((d) => d.m)
587
605
  ) {
588
- return handlers[DM_format.DdplayJson](json)
606
+ return handlers[DM_format.DDPlayJson](json)
589
607
  } else if (
590
608
  json.code == 0 &&
591
609
  json.data &&
@@ -669,27 +687,87 @@ export class UniPool {
669
687
  }
670
688
  throw new Error(errmesg ?? err)
671
689
  }
672
- convert2(format: DM_format, continue_on_error = false) {
690
+ convert2<T extends Convert2Format>(
691
+ format: T,
692
+ file_wrapper: true,
693
+ continue_on_error?: boolean,
694
+ ): File
695
+ convert2<T extends Convert2Format>(
696
+ format: T,
697
+ file_wrapper?: false,
698
+ continue_on_error?: boolean,
699
+ ): Convert2ResultMap[T]
700
+ convert2(
701
+ format: DM_format,
702
+ file_wrapper = false,
703
+ continue_on_error = false,
704
+ ): File | Convert2ResultMap[Convert2Format] | string {
673
705
  switch (format) {
674
- case 'danuni.json':
675
- return this.dans
676
- case 'danuni.min.json':
677
- return this.minify()
678
- case 'danuni.binpb':
679
- return this.toPb()
680
- case 'bili.xml':
681
- return this.toBiliXML()
682
- // case 'bili.binpb':
706
+ case DM_format.DanuniJson:
707
+ if (file_wrapper)
708
+ return new File([JSON.stringify(this.dans)], DM_format.DanuniJson, {
709
+ type: 'application/json',
710
+ })
711
+ else return this.dans
712
+ case DM_format.DanuniMinJson:
713
+ if (file_wrapper)
714
+ return new File(
715
+ [JSON.stringify(this.minify())],
716
+ DM_format.DanuniMinJson,
717
+ {
718
+ type: 'application/json',
719
+ },
720
+ )
721
+ else return this.minify()
722
+ case DM_format.DanuniPbBin:
723
+ if (file_wrapper)
724
+ return new File([this.toPb()], DM_format.DanuniPbBin, {
725
+ type: 'application/protobuf',
726
+ })
727
+ else return this.toPb()
728
+ case DM_format.BiliXml:
729
+ if (file_wrapper)
730
+ return new File([this.toBiliXML()], DM_format.BiliXml, {
731
+ type: 'application/xml',
732
+ })
733
+ else return this.toBiliXML()
734
+ // case DM_format.BiliPbBin:
683
735
  // return this.toBiliBin()
684
- // case 'bili.cmd.binpb':
736
+ // case DM_format.BiliCmdPbBin:
685
737
  // return this.toBiliCmdBin()
686
- case 'dplayer.json':
738
+ // case DM_format.BiliUpJson:
739
+ // return this.toBiliUp()
740
+ case DM_format.DplayerJson:
741
+ if (file_wrapper)
742
+ return new File(
743
+ [JSON.stringify(this.toDplayer())],
744
+ DM_format.DplayerJson,
745
+ {
746
+ type: 'application/json',
747
+ },
748
+ )
687
749
  return this.toDplayer()
688
- case 'artplayer.json':
750
+ case DM_format.ArtplayerJson:
751
+ if (file_wrapper)
752
+ return new File(
753
+ [JSON.stringify(this.toArtplayer())],
754
+ DM_format.ArtplayerJson,
755
+ {
756
+ type: 'application/json',
757
+ },
758
+ )
689
759
  return this.toArtplayer()
690
- case 'ddplay.json':
691
- return this.toDDplay()
692
- // case 'common.ass':
760
+ case DM_format.DDPlayJson:
761
+ if (file_wrapper)
762
+ return new File(
763
+ [JSON.stringify(this.toDDPlay())],
764
+ DM_format.DDPlayJson,
765
+ {
766
+ type: 'application/json',
767
+ },
768
+ )
769
+ return this.toDDPlay()
770
+ // case DM_format.CommonAss:
693
771
  // return this.toASS()
694
772
  default: {
695
773
  const message = '(err) Unknown format or unsupported now!'
@@ -977,7 +1055,7 @@ export class UniPool {
977
1055
  return new UniPool(
978
1056
  json.comments.map((d) => {
979
1057
  const p_arr = d.p.split(',')
980
- return UniDM.fromDDplay(
1058
+ return UniDM.fromDDPlay(
981
1059
  {
982
1060
  cid: d.cid,
983
1061
  color: Number.parseInt(p_arr[2]),
@@ -995,7 +1073,7 @@ export class UniPool {
995
1073
  { fromConverted: !!json.danuni },
996
1074
  )
997
1075
  }
998
- toDDplay(): DM_JSON_DDPlay & { danuni?: DanUniConvertTip } {
1076
+ toDDPlay(): DM_JSON_DDPlay & { danuni?: DanUniConvertTip } {
999
1077
  const episodeId = this.dans[0].SOID.split('@')[0].replaceAll(
1000
1078
  `def_${platform.PlatformDanmakuOnlySource.DanDanPlay}+`,
1001
1079
  '',
@@ -1004,7 +1082,7 @@ export class UniPool {
1004
1082
  danuni: { ...DanUniConvertTipTemplate, data: episodeId },
1005
1083
  count: this.dans.length,
1006
1084
  comments: this.dans.map((dan) => {
1007
- const d = dan.toDDplay()
1085
+ const d = dan.toDDPlay()
1008
1086
  return {
1009
1087
  cid: d.cid,
1010
1088
  p: `${d.progress},${d.mode},${d.color},${d.uid}`,
@@ -203,7 +203,7 @@ interface DMArtplayer {
203
203
  border?: boolean
204
204
  style?: object
205
205
  }
206
- interface DMDDplay {
206
+ interface DMDDPlay {
207
207
  cid: bigint
208
208
  /**
209
209
  * content
@@ -1029,8 +1029,8 @@ export class UniDM {
1029
1029
  style: this.extra.artplayer?.style,
1030
1030
  }
1031
1031
  }
1032
- static fromDDplay(
1033
- args: DMDDplay,
1032
+ static fromDDPlay(
1033
+ args: DMDDPlay,
1034
1034
  episodeId: string,
1035
1035
  domain = PlatformDanmakuOnlySource.DanDanPlay,
1036
1036
  options?: Options,
@@ -1056,7 +1056,7 @@ export class UniDM {
1056
1056
  )
1057
1057
  }
1058
1058
  @Expose()
1059
- toDDplay(): DMDDplay {
1059
+ toDDPlay(): DMDDPlay {
1060
1060
  let mode = 1
1061
1061
  if (this.mode === Modes.Top) mode = 5
1062
1062
  else if (this.mode === Modes.Bottom) mode = 4