update danmuku fontSize

This commit is contained in:
Harvey committed 2022-05-13 17:06:10 +08:00
1 parent fd40fa71f6
commit a043a55b38
3 files changed
+33 -7

No files matched your search

@@ -233,7 +233,7 @@ class Danmuku {
speed: 'number',
margin: 'array',
opacity: 'number',
fontSize: 'number',
fontSize: 'number|string',
filter: 'function',
antiOverlap: 'boolean',
useWorker: 'boolean',
@@ -265,6 +265,17 @@ class Danmuku {
}
return Danmuku.option.margin[1];
}
get fontSize() {
const { clamp } = this.utils;
const value = this.option.fontSize;
const { clientHeight } = this.$player;
if (typeof value === 'number') return clamp(value, 12, 200);
if (typeof value === 'string' && value.endsWith('%')) {
const ratio = parseFloat(value) / 100;
return clamp(clientHeight * ratio, 12, 200);
}
return this.option.fontSize;
}
filter(state, callback) {
return this.queue.filter((danmu)=>danmu.$state === state
).map(callback);
@@ -368,7 +379,6 @@ class Danmuku {
if (option.fontSize) this.reset();
this.option.speed = clamp(this.option.speed, 1, 10);
this.option.opacity = clamp(this.option.opacity, 0, 1);
this.option.fontSize = clamp(this.option.fontSize, 12, 100);
this.art.emit('artplayerPluginDanmuku:config', this.option);
return this;
}
@@ -443,7 +453,7 @@ class Danmuku {
this.$danmuku.appendChild(danmu.$ref);
danmu.$ref.style.left = `${clientWidth}px`;
danmu.$ref.style.opacity = this.option.opacity;
danmu.$ref.style.fontSize = `${this.option.fontSize}px`;
danmu.$ref.style.fontSize = `${this.fontSize}px`;
danmu.$ref.style.color = danmu.color || '#fff';
danmu.$ref.style.border = danmu.border ? `1px solid ${danmu.color || '#fff'}` : 'none';
danmu.$ref.style.marginLeft = '0px';