@dan-uni/dan-any 0.7.6 → 0.7.8
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 +14 -2
- package/dist/index.umd.min.js +10638 -98
- package/package.json +3 -2
- package/rslib.config.ts +1 -0
- package/src/ass-gen/__tests__/898651903.xml.ass +1 -1
- package/src/ass-gen/__tests__/canvas.test.ts +2 -2
- package/src/ass-gen/util/layout.ts +13 -2
- package/src/utils/dm-gen.ts +2 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assertType, it } from 'vitest'
|
|
1
|
+
import { assert, assertType, it } from 'vitest'
|
|
2
2
|
|
|
3
3
|
import { measureTextWidth } from '../util/layout'
|
|
4
4
|
|
|
@@ -7,5 +7,5 @@ it('canvas measureTextWidth', () => {
|
|
|
7
7
|
const width = measureTextWidth('SimHei', 25, false, text)
|
|
8
8
|
assertType<number>(width)
|
|
9
9
|
console.info(width, text.length)
|
|
10
|
-
|
|
10
|
+
assert(width >= 25 * text.length)
|
|
11
11
|
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Canvas as WebCanvas } from 'fabric'
|
|
2
|
+
import { StaticCanvas as NodeCanvas } from 'fabric/node'
|
|
2
3
|
import type { UniPool } from '../..'
|
|
3
4
|
import type { Danmaku, SubtitleStyle } from '../types'
|
|
4
5
|
|
|
@@ -78,7 +79,17 @@ const splitGrids = ({
|
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
export const measureTextWidth = (() => {
|
|
81
|
-
|
|
82
|
+
let isWeb
|
|
83
|
+
try {
|
|
84
|
+
isWeb = !!window
|
|
85
|
+
} catch {
|
|
86
|
+
isWeb = false
|
|
87
|
+
}
|
|
88
|
+
const Canvas = isWeb ? WebCanvas : NodeCanvas
|
|
89
|
+
const canvasContext = new Canvas(undefined, {
|
|
90
|
+
width: 50,
|
|
91
|
+
height: 50,
|
|
92
|
+
}).getContext()
|
|
82
93
|
const supportTextMeasure = !!canvasContext.measureText('中')
|
|
83
94
|
|
|
84
95
|
if (supportTextMeasure) {
|
package/src/utils/dm-gen.ts
CHANGED
|
@@ -469,6 +469,8 @@ export class UniDM {
|
|
|
469
469
|
if (this.options.dmid === undefined || this.options.dmid === true)
|
|
470
470
|
this.options.dmid = createDMID
|
|
471
471
|
|
|
472
|
+
this.content = String(this.content)
|
|
473
|
+
|
|
472
474
|
if (!this.SOID) this.SOID = def.SOID
|
|
473
475
|
if (!this.progress) this.progress = def.progress
|
|
474
476
|
if (!this.mode) this.mode = def.mode
|