@dan-uni/dan-any 0.7.8 → 0.8.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.
- package/dist/index.js +16 -29
- package/dist/index.umd.min.js +171 -10719
- package/dist/src/ass-gen/index.d.ts +3 -2
- package/dist/src/ass-gen/types.d.ts +24 -0
- package/dist/src/ass-gen/util/layout.d.ts +3 -3
- package/dist/src/index.d.ts +5 -2
- package/package.json +4 -5
- package/rslib.config.ts +0 -1
- package/src/ass-gen/__tests__/canvas.test.ts +8 -4
- package/src/ass-gen/__tests__/generate.test.ts +10 -4
- package/src/ass-gen/index.ts +9 -3
- package/src/ass-gen/types.ts +25 -1
- package/src/ass-gen/util/layout.ts +12 -19
- package/src/index.test.ts +3 -1
- package/src/index.ts +13 -7
- package/src/proto/gen/bili/dm_pb.ts +1 -1
- package/src/proto/gen/danuni_pb.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -8,8 +8,6 @@ import { Expose, plainToInstance } from "class-transformer";
|
|
|
8
8
|
import { IsDate, IsEmail, IsEnum, IsInt, IsNotEmpty, IsNumber, IsOptional, IsString, Max, Min, validateOrReject } from "class-validator";
|
|
9
9
|
import hh_mm_ss from "hh-mm-ss";
|
|
10
10
|
import jssha from "jssha";
|
|
11
|
-
import { Canvas as external_fabric_Canvas } from "fabric";
|
|
12
|
-
import { StaticCanvas } from "fabric/node";
|
|
13
11
|
import { brotliCompressSync, brotliDecompressSync, gunzipSync, gzipSync } from "node:zlib";
|
|
14
12
|
import { decode, encode as external_base16384_encode } from "base16384";
|
|
15
13
|
var __webpack_require__ = {};
|
|
@@ -1134,14 +1132,14 @@ class UniPool {
|
|
|
1134
1132
|
return this.dans;
|
|
1135
1133
|
case 'danuni.bin':
|
|
1136
1134
|
return this.toPb();
|
|
1135
|
+
case 'bili.xml':
|
|
1136
|
+
return this.toBiliXML();
|
|
1137
1137
|
case 'dplayer.json':
|
|
1138
1138
|
return this.toDplayer();
|
|
1139
1139
|
case 'artplayer.json':
|
|
1140
1140
|
return this.toArtplayer();
|
|
1141
1141
|
case 'ddplay.json':
|
|
1142
1142
|
return this.toDDplay();
|
|
1143
|
-
case 'common.ass':
|
|
1144
|
-
return this.toASS();
|
|
1145
1143
|
default:
|
|
1146
1144
|
{
|
|
1147
1145
|
const message = '(err) Unknown format or unsupported now!';
|
|
@@ -1315,7 +1313,7 @@ class UniPool {
|
|
|
1315
1313
|
static fromASS(ass) {
|
|
1316
1314
|
return parseAssRawField(ass);
|
|
1317
1315
|
}
|
|
1318
|
-
toASS(options = {
|
|
1316
|
+
toASS(canvasCtx, options = {
|
|
1319
1317
|
substyle: {}
|
|
1320
1318
|
}) {
|
|
1321
1319
|
const fn = this.shared.SOID;
|
|
@@ -1323,7 +1321,7 @@ class UniPool {
|
|
|
1323
1321
|
filename: fn,
|
|
1324
1322
|
title: fn,
|
|
1325
1323
|
...options
|
|
1326
|
-
});
|
|
1324
|
+
}, canvasCtx);
|
|
1327
1325
|
}
|
|
1328
1326
|
}
|
|
1329
1327
|
const color_pad = (s)=>s.length < 2 ? `0${s}` : s;
|
|
@@ -1433,18 +1431,7 @@ const splitGrids = ({ fontSize, padding, playResY, bottomSpace })=>{
|
|
|
1433
1431
|
2: arrayOfLength(linesCount, 0)
|
|
1434
1432
|
};
|
|
1435
1433
|
};
|
|
1436
|
-
const
|
|
1437
|
-
let isWeb;
|
|
1438
|
-
try {
|
|
1439
|
-
isWeb = !!window;
|
|
1440
|
-
} catch {
|
|
1441
|
-
isWeb = false;
|
|
1442
|
-
}
|
|
1443
|
-
const Canvas = isWeb ? external_fabric_Canvas : StaticCanvas;
|
|
1444
|
-
const canvasContext = new Canvas(void 0, {
|
|
1445
|
-
width: 50,
|
|
1446
|
-
height: 50
|
|
1447
|
-
}).getContext();
|
|
1434
|
+
const measureTextWidthConstructor = (canvasContext)=>{
|
|
1448
1435
|
const supportTextMeasure = !!canvasContext.measureText("\u4E2D");
|
|
1449
1436
|
if (supportTextMeasure) return (fontName, fontSize, bold, text)=>{
|
|
1450
1437
|
canvasContext.font = `${bold ? 'bold' : 'normal'} ${fontSize}px ${fontName}`;
|
|
@@ -1453,7 +1440,7 @@ const measureTextWidth = (()=>{
|
|
|
1453
1440
|
};
|
|
1454
1441
|
console.warn('[Warn] node-canvas is installed without text measure support, layout may not be correct');
|
|
1455
1442
|
return (_fontName, fontSize, _bold, text)=>text.length * fontSize;
|
|
1456
|
-
}
|
|
1443
|
+
};
|
|
1457
1444
|
const resolveAvailableFixGrid = (grids, time)=>{
|
|
1458
1445
|
for (const [i, grid] of grids.entries())if (grid <= time) return i;
|
|
1459
1446
|
return -1;
|
|
@@ -1466,7 +1453,7 @@ const resolveAvailableScrollGrid = (grids, rectWidth, screenWidth, time, duratio
|
|
|
1466
1453
|
}
|
|
1467
1454
|
return -1;
|
|
1468
1455
|
};
|
|
1469
|
-
const initializeLayout = (config)=>{
|
|
1456
|
+
const initializeLayout = (config, canvasCtx)=>{
|
|
1470
1457
|
const { playResX, playResY, fontName, fontSize, bold, padding, scrollTime, fixTime, bottomSpace } = config;
|
|
1471
1458
|
const [paddingTop, paddingRight, paddingBottom, paddingLeft] = padding;
|
|
1472
1459
|
const defaultFontSize = fontSize[FontSize.NORMAL];
|
|
@@ -1475,7 +1462,7 @@ const initializeLayout = (config)=>{
|
|
|
1475
1462
|
return (danmaku)=>{
|
|
1476
1463
|
const targetGrids = grids[danmaku.type];
|
|
1477
1464
|
const danmakuFontSize = fontSize[danmaku.fontSizeType];
|
|
1478
|
-
const rectWidth =
|
|
1465
|
+
const rectWidth = measureTextWidthConstructor(canvasCtx)(fontName, danmakuFontSize, bold, danmaku.content) + paddingLeft + paddingRight;
|
|
1479
1466
|
const verticalOffset = paddingTop + Math.round((defaultFontSize - danmakuFontSize) / 2);
|
|
1480
1467
|
if (danmaku.type === DanmakuType.SCROLL) {
|
|
1481
1468
|
const scrollGrids = targetGrids;
|
|
@@ -1520,11 +1507,11 @@ const initializeLayout = (config)=>{
|
|
|
1520
1507
|
}
|
|
1521
1508
|
};
|
|
1522
1509
|
};
|
|
1523
|
-
const layoutDanmaku = (inputList, config)=>{
|
|
1510
|
+
const layoutDanmaku = (inputList, config, canvasCtx)=>{
|
|
1524
1511
|
const list = [
|
|
1525
1512
|
...UniPool2DanmakuLists(inputList)
|
|
1526
1513
|
].sort((x, y)=>x.time - y.time);
|
|
1527
|
-
const layout = initializeLayout(config);
|
|
1514
|
+
const layout = initializeLayout(config, canvasCtx);
|
|
1528
1515
|
return DanmakuList2UniPool(list.map(layout).filter((danmaku)=>!!danmaku));
|
|
1529
1516
|
};
|
|
1530
1517
|
const formatTime = (seconds)=>{
|
|
@@ -1759,10 +1746,10 @@ const ass_gen_config = (overrides = {})=>{
|
|
|
1759
1746
|
config.backColor = config.backColor && formatColor(hexColorToRGB(config.backColor));
|
|
1760
1747
|
return config;
|
|
1761
1748
|
};
|
|
1762
|
-
function generateASS(danmaku, options) {
|
|
1749
|
+
function generateASS(danmaku, options, canvasCtx) {
|
|
1763
1750
|
const config = ass_gen_config(options.substyle);
|
|
1764
1751
|
const mergedList = danmaku.merge(config.mergeIn);
|
|
1765
|
-
const layoutList = layoutDanmaku(mergedList, config);
|
|
1752
|
+
const layoutList = layoutDanmaku(mergedList, config, canvasCtx);
|
|
1766
1753
|
const content = ass_create(layoutList, danmaku, config, {
|
|
1767
1754
|
filename: options?.filename || 'unknown',
|
|
1768
1755
|
title: options?.title || 'unknown'
|
|
@@ -2072,14 +2059,14 @@ class src_UniPool {
|
|
|
2072
2059
|
return this.dans;
|
|
2073
2060
|
case 'danuni.bin':
|
|
2074
2061
|
return this.toPb();
|
|
2062
|
+
case 'bili.xml':
|
|
2063
|
+
return this.toBiliXML();
|
|
2075
2064
|
case 'dplayer.json':
|
|
2076
2065
|
return this.toDplayer();
|
|
2077
2066
|
case 'artplayer.json':
|
|
2078
2067
|
return this.toArtplayer();
|
|
2079
2068
|
case 'ddplay.json':
|
|
2080
2069
|
return this.toDDplay();
|
|
2081
|
-
case 'common.ass':
|
|
2082
|
-
return this.toASS();
|
|
2083
2070
|
default:
|
|
2084
2071
|
{
|
|
2085
2072
|
const message = '(err) Unknown format or unsupported now!';
|
|
@@ -2253,7 +2240,7 @@ class src_UniPool {
|
|
|
2253
2240
|
static fromASS(ass) {
|
|
2254
2241
|
return parseAssRawField(ass);
|
|
2255
2242
|
}
|
|
2256
|
-
toASS(options = {
|
|
2243
|
+
toASS(canvasCtx, options = {
|
|
2257
2244
|
substyle: {}
|
|
2258
2245
|
}) {
|
|
2259
2246
|
const fn = this.shared.SOID;
|
|
@@ -2261,7 +2248,7 @@ class src_UniPool {
|
|
|
2261
2248
|
filename: fn,
|
|
2262
2249
|
title: fn,
|
|
2263
2250
|
...options
|
|
2264
|
-
});
|
|
2251
|
+
}, canvasCtx);
|
|
2265
2252
|
}
|
|
2266
2253
|
}
|
|
2267
2254
|
export { UniDM, dm_gen_namespaceObject as UniDMTools, id_gen_namespaceObject as UniIDTools, src_UniPool as UniPool, platform_namespaceObject as platform };
|