Skip to content

Commit 67defd3

Browse files
committed
core: 修正歌词布局排版
1 parent ec60216 commit 67defd3

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

packages/core/src/lyric-player/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,17 @@ export class LyricPlayer extends EventTarget implements HasElement, Disposable {
427427
);
428428
let style = "";
429429
style += "--amll-lp-width:";
430-
style += `${this.innerSize[0] - this.padding * 2}px;`;
430+
const width = this.innerSize[0] - this._baseFontSize * 2;
431+
style += `${width.toFixed(4)}px;`;
431432
style += "--amll-lp-height:";
432-
style += `${this.innerSize[1] - this.padding * 2}px;`;
433+
style += `${(this.innerSize[1] - this._baseFontSize * 2).toFixed(4)}px;`;
434+
// 原本想用 calc 来计算的,但是发现算式复杂之后无法解析,所以只能用 JS 来计算直接结果了
435+
style += "--amll-lp-line-width:";
436+
if (this.innerSize[0] < 768) {
437+
style += `${width.toFixed(4)}px;`;
438+
} else {
439+
style += `${(width * 0.8).toFixed(4)}px;`;
440+
}
433441

434442
// style += "--amll-player-time:";
435443
// style += this.currentTime;

packages/core/src/styles/index.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
/* 给歌词视图元素应用的样式 */
66
.amll-lyric-player {
7-
--amll-lp-line-width-aspect: 0.9;
7+
--amll-lp-line-width-aspect: 0.8;
88
--amll-lp-line-padding-x: 1em;
9-
--amll-lp-bg-line-scale: 70%;
9+
--amll-lp-bg-line-scale: 0.7;
1010
user-select: none;
1111
font-size: var(--amll-lp-font-size, max(max(4.7vh, 3.2vw), 12px));
1212
padding: 1em;

packages/core/src/styles/lyric-player.module.css

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
position: absolute;
88
backface-visibility: hidden;
99
transform-origin: left;
10-
width: calc(var(--amll-lp-line-width-aspect, 1) * (var(--amll-lp-width, 100%) - (var(--amll-lp-line-padding-x, 1em) * 2)));
10+
width: var(--amll-lp-line-width, 100%);
11+
min-width: var(--amll-lp-line-width, 100%);
12+
max-width: var(--amll-lp-line-width, 100%);
1113
height: fit-content;
1214
padding: 2vh var(--amll-lp-line-padding-x, 1em);
1315
contain: content;
@@ -28,10 +30,10 @@
2830

2931
.lyricBgLine {
3032
opacity: 0;
31-
font-size: max(var(--amll-lp-bg-line-scale, 70%), 10px);
33+
font-size: max(calc(100% * var(--amll-lp-bg-line-scale, 70%)), 10px);
3234
transition: opacity 0.25s, scale 0.5s, filter 0.2s, background-color 0.25s, box-shadow 0.25s;
3335
/* 因为字体大小缩小了,故内边距要和主行字体大小统一,行边距计算公式为 100% / font-size 转 em 单位 */
34-
padding: 1vh calc(var(--amll-lp-line-padding-x, 1em) / var(--amll-lp-bg-line-scale, 70%));
36+
padding: 1vh calc(var(--amll-lp-line-padding-x, 1em) / var(--amll-lp-bg-line-scale, 0.7));
3537

3638
&.active {
3739
transition: opacity 0.5s 0.25s, scale 1.5s cubic-bezier(0, 1, 0, 1) 0.25s, filter 0.2s, background-color 0.25s, box-shadow 0.25s;
@@ -93,7 +95,7 @@
9395
height: clamp(0.5em, 1vh, 3em);
9496
transform-origin: center;
9597
width: fit-content;
96-
padding: 2.5% 1em;
98+
padding: 2.5% var(--amll-lp-line-padding-x, 1em);
9799
position: absolute;
98100
display: flex;
99101
gap: 0.25em;

0 commit comments

Comments
 (0)