@applemusic-like-lyrics/core 0.0.1 → 0.0.2
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/README.md +24 -1
- package/dist/amll-core.js +2 -1
- package/dist/amll-core.js.map +1 -0
- package/dist/amll-core.mjs +452 -236
- package/dist/amll-core.mjs.map +1 -0
- package/dist/bg-render/pixi-renderer.d.ts +29 -2
- package/dist/index.d.ts +3 -0
- package/dist/lyric-player/index.d.ts +69 -6
- package/dist/lyric-player/lyric-line.d.ts +2 -0
- package/package.json +16 -1
package/dist/amll-core.mjs
CHANGED
|
@@ -1,27 +1,136 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { Container as
|
|
5
|
-
import { Application as
|
|
6
|
-
import { BlurFilter as
|
|
7
|
-
import { ColorMatrixFilter as
|
|
8
|
-
import { Texture as
|
|
9
|
-
import { Sprite as
|
|
10
|
-
import { create as
|
|
11
|
-
import
|
|
12
|
-
|
|
1
|
+
var D = Object.defineProperty;
|
|
2
|
+
var I = (c, t, e) => t in c ? D(c, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[t] = e;
|
|
3
|
+
var h = (c, t, e) => (I(c, typeof t != "symbol" ? t + "" : t, e), e);
|
|
4
|
+
import { Container as B } from "@pixi/display";
|
|
5
|
+
import { Application as k } from "@pixi/app";
|
|
6
|
+
import { BlurFilter as g } from "@pixi/filter-blur";
|
|
7
|
+
import { ColorMatrixFilter as P } from "@pixi/filter-color-matrix";
|
|
8
|
+
import { Texture as N } from "@pixi/core";
|
|
9
|
+
import { Sprite as S } from "@pixi/sprite";
|
|
10
|
+
import { create as O } from "jss";
|
|
11
|
+
import $ from "jss-preset-default";
|
|
12
|
+
const q = /^(((?<hour>[0-9]+):)?(?<min>[0-9]+):)?(?<sec>[0-9]+([\.:]([0-9]+))?)/;
|
|
13
|
+
function b(c) {
|
|
14
|
+
var e, n, s;
|
|
15
|
+
const t = q.exec(c);
|
|
16
|
+
if (t) {
|
|
17
|
+
const a = Number(((e = t.groups) == null ? void 0 : e.hour) || "0"), l = Number(((n = t.groups) == null ? void 0 : n.min) || "0"), i = Number(((s = t.groups) == null ? void 0 : s.sec.replace(/:/, ".")) || "0");
|
|
18
|
+
return Math.floor((a * 3600 + l * 60 + i) * 1e3);
|
|
19
|
+
} else
|
|
20
|
+
throw new TypeError("时间戳字符串解析失败");
|
|
21
|
+
}
|
|
22
|
+
function R(c) {
|
|
23
|
+
const e = new DOMParser().parseFromString(
|
|
24
|
+
c,
|
|
25
|
+
"application/xml"
|
|
26
|
+
);
|
|
27
|
+
let n = "v1";
|
|
28
|
+
for (const a of e.querySelectorAll("ttm\\:agent"))
|
|
29
|
+
if (a.getAttribute("type") === "person") {
|
|
30
|
+
const l = a.getAttribute("xml:id");
|
|
31
|
+
l && (n = l);
|
|
32
|
+
}
|
|
33
|
+
const s = [];
|
|
34
|
+
for (const a of e.querySelectorAll("body p[begin][end]")) {
|
|
35
|
+
const l = {
|
|
36
|
+
words: [],
|
|
37
|
+
startTime: b(a.getAttribute("begin") ?? "0:0"),
|
|
38
|
+
endTime: b(a.getAttribute("end") ?? "0:0"),
|
|
39
|
+
translatedLyric: "",
|
|
40
|
+
romanLyric: "",
|
|
41
|
+
isBG: !1,
|
|
42
|
+
isDuet: a.getAttribute("ttm:agent") !== n
|
|
43
|
+
};
|
|
44
|
+
let i = null;
|
|
45
|
+
for (const r of a.childNodes)
|
|
46
|
+
if (r.nodeType === Node.TEXT_NODE) {
|
|
47
|
+
const o = r.textContent ?? "";
|
|
48
|
+
/^(\s+)$/.test(o) ? l.words.push({
|
|
49
|
+
word: " ",
|
|
50
|
+
startTime: 0,
|
|
51
|
+
endTime: 0
|
|
52
|
+
}) : l.words.push({
|
|
53
|
+
word: o,
|
|
54
|
+
startTime: 0,
|
|
55
|
+
endTime: 0
|
|
56
|
+
});
|
|
57
|
+
} else if (r.nodeType === Node.ELEMENT_NODE) {
|
|
58
|
+
const o = r, d = o.getAttribute("ttm:role");
|
|
59
|
+
if (o.nodeName === "span" && d)
|
|
60
|
+
if (d === "x-bg") {
|
|
61
|
+
const u = {
|
|
62
|
+
words: [],
|
|
63
|
+
startTime: l.startTime,
|
|
64
|
+
endTime: l.endTime,
|
|
65
|
+
translatedLyric: "",
|
|
66
|
+
romanLyric: "",
|
|
67
|
+
isBG: !0,
|
|
68
|
+
isDuet: l.isDuet
|
|
69
|
+
};
|
|
70
|
+
for (const p of o.childNodes)
|
|
71
|
+
if (p.nodeType === Node.TEXT_NODE) {
|
|
72
|
+
const y = p.textContent ?? "";
|
|
73
|
+
/^(\s+)$/.test(y) ? u.words.push({
|
|
74
|
+
word: " ",
|
|
75
|
+
startTime: 0,
|
|
76
|
+
endTime: 0
|
|
77
|
+
}) : u.words.push({
|
|
78
|
+
word: y,
|
|
79
|
+
startTime: 0,
|
|
80
|
+
endTime: 0
|
|
81
|
+
});
|
|
82
|
+
} else if (p.nodeType === Node.ELEMENT_NODE) {
|
|
83
|
+
const y = p, T = y.getAttribute("ttm:role");
|
|
84
|
+
if (y.nodeName === "span" && T)
|
|
85
|
+
T === "x-translation" ? u.translatedLyric = y.innerHTML.trim() : T === "x-roman" && (u.romanLyric = y.innerHTML.trim());
|
|
86
|
+
else if (y.hasAttribute("begin") && y.hasAttribute("end")) {
|
|
87
|
+
const E = {
|
|
88
|
+
word: p.textContent,
|
|
89
|
+
startTime: b(y.getAttribute("begin")),
|
|
90
|
+
endTime: b(y.getAttribute("end"))
|
|
91
|
+
};
|
|
92
|
+
u.words.push(E);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const f = u.words[0];
|
|
96
|
+
u.startTime = f.startTime, f != null && f.word.startsWith("(") && (f.word = f.word.substring(1));
|
|
97
|
+
const m = u.words[u.words.length - 1];
|
|
98
|
+
u.endTime = m.endTime, m != null && m.word.endsWith(")") && (m.word = m.word.substring(
|
|
99
|
+
0,
|
|
100
|
+
m.word.length - 1
|
|
101
|
+
)), i = u;
|
|
102
|
+
} else
|
|
103
|
+
d === "x-translation" ? l.translatedLyric = o.innerHTML : d === "x-roman" && (l.romanLyric = o.innerHTML);
|
|
104
|
+
else if (o.hasAttribute("begin") && o.hasAttribute("end")) {
|
|
105
|
+
const u = {
|
|
106
|
+
word: r.textContent ?? "",
|
|
107
|
+
startTime: b(o.getAttribute("begin")),
|
|
108
|
+
endTime: b(o.getAttribute("end"))
|
|
109
|
+
};
|
|
110
|
+
l.words.push(u);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
s.push(l), i && s.push(i);
|
|
114
|
+
}
|
|
115
|
+
return console.log(s), s;
|
|
116
|
+
}
|
|
117
|
+
const ae = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
118
|
+
__proto__: null,
|
|
119
|
+
parseTTML: R
|
|
120
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
121
|
+
class F extends B {
|
|
13
122
|
constructor() {
|
|
14
123
|
super(...arguments);
|
|
15
|
-
|
|
124
|
+
h(this, "time", 0);
|
|
16
125
|
}
|
|
17
126
|
}
|
|
18
|
-
class
|
|
127
|
+
class _ {
|
|
19
128
|
constructor(t) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
129
|
+
h(this, "observer");
|
|
130
|
+
h(this, "app");
|
|
131
|
+
h(this, "curContainer");
|
|
132
|
+
h(this, "lastContainer", /* @__PURE__ */ new Set());
|
|
133
|
+
h(this, "onTick", (t) => {
|
|
25
134
|
for (const e of this.lastContainer)
|
|
26
135
|
e.alpha = Math.max(0, e.alpha - t / 60), e.alpha <= 0 && (this.app.stage.removeChild(e), this.lastContainer.delete(e));
|
|
27
136
|
if (this.curContainer) {
|
|
@@ -29,15 +138,15 @@ class B {
|
|
|
29
138
|
1,
|
|
30
139
|
this.curContainer.alpha + t / 60
|
|
31
140
|
);
|
|
32
|
-
const [e, n, s, a] = this.curContainer.children,
|
|
141
|
+
const [e, n, s, a] = this.curContainer.children, l = Math.max(this.app.screen.width, this.app.screen.height);
|
|
33
142
|
e.position.set(this.app.screen.width / 2, this.app.screen.height / 2), n.position.set(
|
|
34
143
|
this.app.screen.width / 2.5,
|
|
35
144
|
this.app.screen.height / 2.5
|
|
36
|
-
), s.position.set(this.app.screen.width / 2, this.app.screen.height / 2), a.position.set(this.app.screen.width / 2, this.app.screen.height / 2), e.width =
|
|
145
|
+
), s.position.set(this.app.screen.width / 2, this.app.screen.height / 2), a.position.set(this.app.screen.width / 2, this.app.screen.height / 2), e.width = l * Math.sqrt(2), e.height = e.width, n.width = l * 0.8, n.height = n.width, s.width = l * 0.5, s.height = s.width, a.width = l * 0.25, a.height = a.width, this.curContainer.time += t * this.flowSpeed, e.rotation += t / 1e3 * this.flowSpeed, n.rotation -= t / 500 * this.flowSpeed, s.rotation += t / 1e3 * this.flowSpeed, a.rotation -= t / 750 * this.flowSpeed, s.x = this.app.screen.width / 2 + this.app.screen.width / 4 * Math.cos(this.curContainer.time / 1e3 * 0.75), s.y = this.app.screen.height / 2 + this.app.screen.width / 4 * Math.cos(this.curContainer.time / 1e3 * 0.75), a.x = this.app.screen.width / 2 + this.app.screen.width / 4 * 0.1 + Math.cos(this.curContainer.time * 6e-3 * 0.75), a.y = this.app.screen.height / 2 + this.app.screen.width / 4 * 0.1 + Math.cos(this.curContainer.time * 6e-3 * 0.75);
|
|
37
146
|
}
|
|
38
147
|
});
|
|
39
|
-
|
|
40
|
-
|
|
148
|
+
h(this, "flowSpeed", 2);
|
|
149
|
+
h(this, "currerntRenderScale", 0.75);
|
|
41
150
|
this.canvas = t;
|
|
42
151
|
const e = t.getBoundingClientRect();
|
|
43
152
|
this.canvas.width = e.width * this.currerntRenderScale, this.canvas.height = e.height * this.currerntRenderScale, this.observer = new ResizeObserver(() => {
|
|
@@ -46,13 +155,26 @@ class B {
|
|
|
46
155
|
this.canvas.width * this.currerntRenderScale,
|
|
47
156
|
this.canvas.height * this.currerntRenderScale
|
|
48
157
|
), this.rebuildFilters();
|
|
49
|
-
}), this.observer.observe(t), this.app = new
|
|
158
|
+
}), this.observer.observe(t), this.app = new k({
|
|
50
159
|
view: t,
|
|
51
160
|
resizeTo: this.canvas,
|
|
52
161
|
powerPreference: "low-power",
|
|
53
162
|
backgroundAlpha: 0
|
|
54
163
|
}), this.rebuildFilters(), this.app.ticker.add(this.onTick), this.app.ticker.start();
|
|
55
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* 修改背景的流动速度,数字越大越快,默认为 2
|
|
167
|
+
* @param speed 背景的流动速度,默认为 2
|
|
168
|
+
*/
|
|
169
|
+
setFlowSpeed(t) {
|
|
170
|
+
this.flowSpeed = t;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* 修改背景的渲染比例,默认是 0.5
|
|
174
|
+
*
|
|
175
|
+
* 一般情况下这个程度既没有明显瑕疵也不会特别吃性能
|
|
176
|
+
* @param scale 背景的渲染比例
|
|
177
|
+
*/
|
|
56
178
|
setRenderScale(t) {
|
|
57
179
|
this.currerntRenderScale = t;
|
|
58
180
|
const e = this.canvas.getBoundingClientRect();
|
|
@@ -62,35 +184,51 @@ class B {
|
|
|
62
184
|
), this.rebuildFilters();
|
|
63
185
|
}
|
|
64
186
|
rebuildFilters() {
|
|
65
|
-
const t = Math.min(this.canvas.width, this.canvas.height), e = new
|
|
187
|
+
const t = Math.min(this.canvas.width, this.canvas.height), e = new P();
|
|
66
188
|
e.saturate(1.2, !1);
|
|
67
|
-
const n = new
|
|
189
|
+
const n = new P();
|
|
68
190
|
n.brightness(0.6, !1);
|
|
69
|
-
const s = new
|
|
70
|
-
s.contrast(0.3, !0), this.app.stage.filters = [], this.app.stage.filters.push(new
|
|
191
|
+
const s = new P();
|
|
192
|
+
s.contrast(0.3, !0), this.app.stage.filters = [], this.app.stage.filters.push(new g(5, 1)), this.app.stage.filters.push(new g(10, 1)), this.app.stage.filters.push(new g(20, 2)), this.app.stage.filters.push(new g(40, 2)), t > 512 && this.app.stage.filters.push(new g(80, 2)), t > 768 && this.app.stage.filters.push(new g(160, 4)), t > 768 * 2 && this.app.stage.filters.push(new g(320, 4)), this.app.stage.filters.push(e, n, s), this.app.stage.filters.push(new g(5, 1));
|
|
71
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* 修改背景动画帧率,默认是 30 FPS
|
|
196
|
+
*
|
|
197
|
+
* 如果设置成 0 则会停止动画
|
|
198
|
+
* @param fps 目标帧率,默认 30 FPS
|
|
199
|
+
*/
|
|
72
200
|
setFPS(t) {
|
|
73
201
|
this.app.ticker.maxFPS = t;
|
|
74
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* 暂停背景动画,画面即便是更新了图片也不会发生变化
|
|
205
|
+
*/
|
|
75
206
|
pause() {
|
|
76
207
|
this.app.ticker.stop(), this.app.render();
|
|
77
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* 恢复播放背景动画
|
|
211
|
+
*/
|
|
78
212
|
resume() {
|
|
79
213
|
this.app.ticker.start();
|
|
80
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* 设置背景专辑图片,图片材质加载并设置完成后会返回
|
|
217
|
+
* @param albumUrl 图片的目标链接
|
|
218
|
+
*/
|
|
81
219
|
async setAlbumImage(t) {
|
|
82
|
-
const e = await
|
|
83
|
-
s.anchor.set(0.5, 0.5), a.anchor.set(0.5, 0.5),
|
|
220
|
+
const e = await N.fromURL(t), n = new F(), s = new S(e), a = new S(e), l = new S(e), i = new S(e);
|
|
221
|
+
s.anchor.set(0.5, 0.5), a.anchor.set(0.5, 0.5), l.anchor.set(0.5, 0.5), i.anchor.set(0.5, 0.5), s.rotation = Math.random() * Math.PI * 2, a.rotation = Math.random() * Math.PI * 2, l.rotation = Math.random() * Math.PI * 2, i.rotation = Math.random() * Math.PI * 2, n.addChild(s, a, l, i), this.curContainer && this.lastContainer.add(this.curContainer), this.curContainer = n, this.app.stage.addChild(this.curContainer), this.curContainer.alpha = 0;
|
|
84
222
|
}
|
|
85
223
|
dispose() {
|
|
86
224
|
this.observer.disconnect(), this.app.ticker.remove(this.onTick);
|
|
87
225
|
}
|
|
88
226
|
}
|
|
89
|
-
class
|
|
227
|
+
class le extends _ {
|
|
90
228
|
constructor() {
|
|
91
229
|
const e = document.createElement("canvas");
|
|
92
230
|
super(e);
|
|
93
|
-
|
|
231
|
+
h(this, "element");
|
|
94
232
|
this.element = e, e.style.pointerEvents = "none", e.style.zIndex = "-1";
|
|
95
233
|
}
|
|
96
234
|
getElement() {
|
|
@@ -100,25 +238,25 @@ class Q extends B {
|
|
|
100
238
|
super.dispose(), this.element.remove();
|
|
101
239
|
}
|
|
102
240
|
}
|
|
103
|
-
const
|
|
104
|
-
function
|
|
241
|
+
const W = (c, t) => c.size === t.size && [...c].every((e) => t.has(e));
|
|
242
|
+
function G(c) {
|
|
105
243
|
const e = 2.5949095;
|
|
106
|
-
return
|
|
244
|
+
return c < 0.5 ? Math.pow(2 * c, 2) * ((e + 1) * 2 * c - e) / 2 : (Math.pow(2 * c - 2, 2) * ((e + 1) * (c * 2 - 2) + e) + 2) / 2;
|
|
107
245
|
}
|
|
108
|
-
const
|
|
109
|
-
class
|
|
246
|
+
const L = (c, t, e) => Math.max(c, Math.min(t, e));
|
|
247
|
+
class X {
|
|
110
248
|
constructor(t) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
249
|
+
h(this, "element", document.createElement("div"));
|
|
250
|
+
h(this, "dot0", document.createElement("span"));
|
|
251
|
+
h(this, "dot1", document.createElement("span"));
|
|
252
|
+
h(this, "dot2", document.createElement("span"));
|
|
253
|
+
h(this, "left", 0);
|
|
254
|
+
h(this, "top", 0);
|
|
255
|
+
h(this, "scale", 1);
|
|
256
|
+
h(this, "lastStyle", "");
|
|
257
|
+
h(this, "currentInterlude");
|
|
258
|
+
h(this, "currentTime", 0);
|
|
259
|
+
h(this, "targetBreatheDuration", 1500);
|
|
122
260
|
this.lyricPlayer = t, this.element.className = this.lyricPlayer.style.classes.interludeDots, this.element.appendChild(this.dot0), this.element.appendChild(this.dot1), this.element.appendChild(this.dot2);
|
|
123
261
|
}
|
|
124
262
|
getElement() {
|
|
@@ -137,38 +275,38 @@ class $ {
|
|
|
137
275
|
const n = this.currentInterlude[1] - this.currentInterlude[0], s = this.currentTime - this.currentInterlude[0];
|
|
138
276
|
if (s <= n) {
|
|
139
277
|
const a = n / Math.ceil(n / this.targetBreatheDuration);
|
|
140
|
-
let
|
|
141
|
-
|
|
278
|
+
let l = 1, i = 1;
|
|
279
|
+
l *= Math.sin(1.5 * Math.PI - s / a * 2) / 10 + 1, s < 1e3 && (l *= 1 - Math.pow((1e3 - s) / 1e3, 2)), s < 500 ? i = 0 : s < 1e3 && (i *= (s - 500) / 500), n - s < 750 && (l *= 1 - G(
|
|
142
280
|
(750 - (n - s)) / 750 / 2
|
|
143
|
-
)), n - s < 375 && (i *=
|
|
281
|
+
)), n - s < 375 && (i *= L(
|
|
144
282
|
0,
|
|
145
283
|
(n - s) / 375,
|
|
146
284
|
1
|
|
147
|
-
)),
|
|
148
|
-
const r =
|
|
285
|
+
)), l = Math.max(0, l), e += ` scale(${l})`;
|
|
286
|
+
const r = L(
|
|
149
287
|
0.25,
|
|
150
288
|
s * 3 / n * 0.75,
|
|
151
289
|
1
|
|
152
|
-
),
|
|
290
|
+
), o = L(
|
|
153
291
|
0.25,
|
|
154
292
|
(s - n / 3) * 3 / n * 0.75,
|
|
155
293
|
1
|
|
156
|
-
),
|
|
294
|
+
), d = L(
|
|
157
295
|
0.25,
|
|
158
296
|
(s - n / 3 * 2) * 3 / n * 0.75,
|
|
159
297
|
1
|
|
160
298
|
);
|
|
161
|
-
this.dot0.style.opacity = `${
|
|
299
|
+
this.dot0.style.opacity = `${L(
|
|
162
300
|
0,
|
|
163
301
|
Math.max(0, i * r),
|
|
164
302
|
1
|
|
165
|
-
)}`, this.dot1.style.opacity = `${
|
|
303
|
+
)}`, this.dot1.style.opacity = `${L(
|
|
166
304
|
0,
|
|
167
|
-
Math.max(0, i *
|
|
305
|
+
Math.max(0, i * o),
|
|
168
306
|
1
|
|
169
|
-
)}`, this.dot2.style.opacity = `${
|
|
307
|
+
)}`, this.dot2.style.opacity = `${L(
|
|
170
308
|
0,
|
|
171
|
-
Math.max(0, i *
|
|
309
|
+
Math.max(0, i * d),
|
|
172
310
|
1
|
|
173
311
|
)}`;
|
|
174
312
|
} else
|
|
@@ -181,27 +319,27 @@ class $ {
|
|
|
181
319
|
this.element.remove();
|
|
182
320
|
}
|
|
183
321
|
}
|
|
184
|
-
class
|
|
322
|
+
class x {
|
|
185
323
|
constructor(t = 0) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
324
|
+
h(this, "currentPosition", 0);
|
|
325
|
+
h(this, "targetPosition", 0);
|
|
326
|
+
h(this, "currentTime", 0);
|
|
327
|
+
h(this, "params", {});
|
|
328
|
+
h(this, "currentSolver");
|
|
329
|
+
h(this, "getV");
|
|
330
|
+
h(this, "queueParams");
|
|
331
|
+
h(this, "queuePosition");
|
|
194
332
|
this.targetPosition = t, this.currentPosition = this.targetPosition, this.currentSolver = () => this.targetPosition, this.getV = () => 0;
|
|
195
333
|
}
|
|
196
334
|
resetSolver() {
|
|
197
335
|
const t = this.getV(this.currentTime);
|
|
198
|
-
this.currentTime = 0, this.currentSolver =
|
|
336
|
+
this.currentTime = 0, this.currentSolver = Y(
|
|
199
337
|
this.currentPosition,
|
|
200
338
|
t,
|
|
201
339
|
this.targetPosition,
|
|
202
340
|
0,
|
|
203
341
|
this.params
|
|
204
|
-
), this.getV =
|
|
342
|
+
), this.getV = j(this.currentSolver);
|
|
205
343
|
}
|
|
206
344
|
arrived() {
|
|
207
345
|
return Math.abs(this.targetPosition - this.currentPosition) < 0.01 && this.getV(this.currentTime) < 0.01 && this.queueParams === void 0 && this.queuePosition === void 0;
|
|
@@ -233,37 +371,37 @@ class S {
|
|
|
233
371
|
return this.currentPosition;
|
|
234
372
|
}
|
|
235
373
|
}
|
|
236
|
-
function
|
|
237
|
-
const a = (s == null ? void 0 : s.soft) ?? !1,
|
|
238
|
-
if (a || 1 <= i / (2 * Math.sqrt(
|
|
239
|
-
const
|
|
240
|
-
return (
|
|
374
|
+
function Y(c, t, e, n = 0, s) {
|
|
375
|
+
const a = (s == null ? void 0 : s.soft) ?? !1, l = (s == null ? void 0 : s.stiffness) ?? 100, i = (s == null ? void 0 : s.damping) ?? 10, r = (s == null ? void 0 : s.mass) ?? 1, o = e - c;
|
|
376
|
+
if (a || 1 <= i / (2 * Math.sqrt(l * r))) {
|
|
377
|
+
const d = -Math.sqrt(l / r), u = -d * o - t;
|
|
378
|
+
return (f) => (f -= n, f < 0 ? c : e - (o + f * u) * Math.E ** (f * d));
|
|
241
379
|
} else {
|
|
242
|
-
const
|
|
243
|
-
4 * r *
|
|
244
|
-
),
|
|
245
|
-
return (
|
|
380
|
+
const d = Math.sqrt(
|
|
381
|
+
4 * r * l - i ** 2
|
|
382
|
+
), u = (i * o - 2 * r * t) / d, f = 0.5 * d / r, m = -(0.5 * i) / r;
|
|
383
|
+
return (p) => (p -= n, p < 0 ? c : e - (Math.cos(p * f) * o + Math.sin(p * f) * u) * Math.E ** (p * m));
|
|
246
384
|
}
|
|
247
385
|
}
|
|
248
|
-
function
|
|
249
|
-
return (e) => (
|
|
386
|
+
function V(c) {
|
|
387
|
+
return (e) => (c(e + 1e-3) - c(e - 1e-3)) / (2 * 1e-3);
|
|
250
388
|
}
|
|
251
|
-
function
|
|
252
|
-
return
|
|
389
|
+
function j(c) {
|
|
390
|
+
return V(c);
|
|
253
391
|
}
|
|
254
|
-
const
|
|
255
|
-
function
|
|
256
|
-
const n = 2 +
|
|
392
|
+
const w = /^[\p{Unified_Ideograph}\u0800-\u9FFC]+$/u;
|
|
393
|
+
function U(c, t = "rgba(0,0,0,1)", e = "rgba(0,0,0,0.5)") {
|
|
394
|
+
const n = 2 + c, s = c / n, a = (1 - s) / 2;
|
|
257
395
|
return [
|
|
258
396
|
`linear-gradient(to right,${t} ${a * 100}%,${e} ${(a + s) * 100}%)`,
|
|
259
397
|
s,
|
|
260
398
|
n
|
|
261
399
|
];
|
|
262
400
|
}
|
|
263
|
-
function
|
|
264
|
-
return
|
|
401
|
+
function v(c) {
|
|
402
|
+
return c.endTime - c.startTime >= 1e3 && c.word.length <= 7;
|
|
265
403
|
}
|
|
266
|
-
class
|
|
404
|
+
class H {
|
|
267
405
|
constructor(t, e = {
|
|
268
406
|
words: [],
|
|
269
407
|
translatedLyric: "",
|
|
@@ -273,22 +411,23 @@ class O {
|
|
|
273
411
|
isBG: !1,
|
|
274
412
|
isDuet: !1
|
|
275
413
|
}) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
414
|
+
h(this, "element", document.createElement("div"));
|
|
415
|
+
h(this, "left", 0);
|
|
416
|
+
h(this, "top", 0);
|
|
417
|
+
h(this, "scale", 1);
|
|
418
|
+
h(this, "blur", 0);
|
|
419
|
+
h(this, "delay", 0);
|
|
420
|
+
h(this, "splittedWords", []);
|
|
283
421
|
// 由 LyricPlayer 来设置
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
posX: new
|
|
287
|
-
posY: new
|
|
288
|
-
scale: new
|
|
422
|
+
h(this, "lineSize", [0, 0]);
|
|
423
|
+
h(this, "lineTransforms", {
|
|
424
|
+
posX: new x(0),
|
|
425
|
+
posY: new x(0),
|
|
426
|
+
scale: new x(1)
|
|
289
427
|
});
|
|
290
|
-
|
|
291
|
-
|
|
428
|
+
h(this, "isEnabled", !1);
|
|
429
|
+
h(this, "_hide", !0);
|
|
430
|
+
h(this, "lastStyle", "");
|
|
292
431
|
this.lyricPlayer = t, this.lyricLine = e, this.element.setAttribute(
|
|
293
432
|
"class",
|
|
294
433
|
this.lyricPlayer.style.classes.lyricLine
|
|
@@ -297,7 +436,7 @@ class O {
|
|
|
297
436
|
n.setAttribute("class", this.lyricPlayer.style.classes.lyricMainLine), s.setAttribute("class", this.lyricPlayer.style.classes.lyricSubLine), a.setAttribute("class", this.lyricPlayer.style.classes.lyricSubLine), this.rebuildElement(), this.rebuildStyle();
|
|
298
437
|
}
|
|
299
438
|
enable() {
|
|
300
|
-
this.element.classList.add("active");
|
|
439
|
+
this.isEnabled = !0, this.element.classList.add("active");
|
|
301
440
|
const t = this.element.children[0];
|
|
302
441
|
this.splittedWords.forEach((e) => {
|
|
303
442
|
e.elementAnimations.forEach((n) => {
|
|
@@ -305,8 +444,16 @@ class O {
|
|
|
305
444
|
});
|
|
306
445
|
}), t.classList.add("active");
|
|
307
446
|
}
|
|
447
|
+
measureSize() {
|
|
448
|
+
this._hide && (this.element.style.display = "", this.element.style.visibility = "hidden");
|
|
449
|
+
const t = [
|
|
450
|
+
this.element.clientWidth,
|
|
451
|
+
this.element.clientHeight
|
|
452
|
+
];
|
|
453
|
+
return this._hide && (this.element.style.display = "none", this.element.style.visibility = ""), t;
|
|
454
|
+
}
|
|
308
455
|
disable() {
|
|
309
|
-
this.element.classList.remove("active");
|
|
456
|
+
this.isEnabled = !1, this.element.classList.remove("active");
|
|
310
457
|
const t = this.element.children[0];
|
|
311
458
|
this.splittedWords.forEach((e) => {
|
|
312
459
|
e.elementAnimations.forEach((n) => {
|
|
@@ -330,30 +477,30 @@ class O {
|
|
|
330
477
|
}
|
|
331
478
|
rebuildStyle() {
|
|
332
479
|
if (this._hide) {
|
|
333
|
-
this.lastStyle !== "
|
|
480
|
+
this.lastStyle !== "display:none;transform:translate(0,-10000px);" && (this.lastStyle = "display:none;transform:translate(0,-10000px);", this.element.setAttribute(
|
|
334
481
|
"style",
|
|
335
|
-
"
|
|
482
|
+
"display:none;transform:translate(0,-10000px);"
|
|
336
483
|
));
|
|
337
484
|
return;
|
|
338
485
|
}
|
|
339
486
|
let t = `transform:translate(${this.lineTransforms.posX.getCurrentPosition()}px,${this.lineTransforms.posY.getCurrentPosition()}px) scale(${this.lineTransforms.scale.getCurrentPosition()});`;
|
|
340
|
-
this.lyricPlayer.
|
|
487
|
+
!this.lyricPlayer.getEnableSpring() && this.isInSight && (t += `transition-delay:${this.delay}ms;`), t += `filter:blur(${Math.min(32, this.blur)}px);`, t !== this.lastStyle && (this.lastStyle = t, this.element.setAttribute("style", t));
|
|
341
488
|
}
|
|
342
489
|
rebuildElement() {
|
|
343
490
|
const t = this.element.children[0], e = this.element.children[1], n = this.element.children[2];
|
|
344
491
|
this.splittedWords = [], this.lyricLine.words.forEach((r) => {
|
|
345
|
-
if (
|
|
492
|
+
if (w.test(r.word))
|
|
346
493
|
this.splittedWords.push({
|
|
347
494
|
...r,
|
|
348
495
|
width: 0,
|
|
349
496
|
height: 0,
|
|
350
497
|
elements: [],
|
|
351
498
|
elementAnimations: [],
|
|
352
|
-
shouldEmphasize:
|
|
499
|
+
shouldEmphasize: v(r)
|
|
353
500
|
});
|
|
354
501
|
else {
|
|
355
|
-
const
|
|
356
|
-
|
|
502
|
+
const o = /(\s*)(\S*)(\s*)/.exec(r.word);
|
|
503
|
+
o && (o[1].length > 0 && this.splittedWords.push({
|
|
357
504
|
word: " ",
|
|
358
505
|
startTime: 0,
|
|
359
506
|
endTime: 0,
|
|
@@ -363,15 +510,15 @@ class O {
|
|
|
363
510
|
elementAnimations: [],
|
|
364
511
|
shouldEmphasize: !1
|
|
365
512
|
}), this.splittedWords.push({
|
|
366
|
-
word:
|
|
513
|
+
word: o[2],
|
|
367
514
|
startTime: r.startTime,
|
|
368
515
|
endTime: r.endTime,
|
|
369
516
|
width: 0,
|
|
370
517
|
height: 0,
|
|
371
518
|
elements: [],
|
|
372
519
|
elementAnimations: [],
|
|
373
|
-
shouldEmphasize:
|
|
374
|
-
}),
|
|
520
|
+
shouldEmphasize: v(r)
|
|
521
|
+
}), o[3].length > 0 && this.splittedWords.push({
|
|
375
522
|
word: " ",
|
|
376
523
|
startTime: 0,
|
|
377
524
|
endTime: 0,
|
|
@@ -384,45 +531,45 @@ class O {
|
|
|
384
531
|
}
|
|
385
532
|
});
|
|
386
533
|
const s = [], a = [];
|
|
387
|
-
function
|
|
534
|
+
function l(r) {
|
|
388
535
|
for (; r.firstChild; )
|
|
389
|
-
r.firstChild.nodeType === Node.ELEMENT_NODE ? s.push(t.firstChild) : r.firstChild.nodeType === Node.TEXT_NODE && a.push(t.firstChild), r.removeChild(r.firstChild),
|
|
536
|
+
r.firstChild.nodeType === Node.ELEMENT_NODE ? s.push(t.firstChild) : r.firstChild.nodeType === Node.TEXT_NODE && a.push(t.firstChild), r.removeChild(r.firstChild), l(r.firstChild);
|
|
390
537
|
}
|
|
391
|
-
|
|
538
|
+
l(t);
|
|
392
539
|
let i = null;
|
|
393
540
|
this.splittedWords.forEach((r) => {
|
|
394
541
|
if (r.word.trim().length > 0)
|
|
395
542
|
if (r.shouldEmphasize) {
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
for (const
|
|
399
|
-
const
|
|
400
|
-
|
|
543
|
+
const o = s.pop() ?? document.createElement("span");
|
|
544
|
+
o.className = "emphasize", r.elements = [o];
|
|
545
|
+
for (const d of r.word) {
|
|
546
|
+
const u = s.pop() ?? document.createElement("span");
|
|
547
|
+
u.className = "", u.innerText = d, o.appendChild(u), r.elements.push(u);
|
|
401
548
|
}
|
|
402
|
-
if (r.elementAnimations = this.initEmphasizeAnimation(r), console.log(r.word,
|
|
549
|
+
if (r.elementAnimations = this.initEmphasizeAnimation(r), console.log(r.word, w.test(r.word)), i && !w.test(r.word))
|
|
403
550
|
if (i.childElementCount > 0)
|
|
404
|
-
i.appendChild(
|
|
551
|
+
i.appendChild(o);
|
|
405
552
|
else {
|
|
406
|
-
const
|
|
407
|
-
|
|
553
|
+
const d = s.pop() ?? document.createElement("span");
|
|
554
|
+
d.className = "", i.remove(), d.appendChild(i), d.appendChild(o), t.appendChild(d), i = d;
|
|
408
555
|
}
|
|
409
556
|
else
|
|
410
|
-
i =
|
|
557
|
+
i = w.test(r.word) ? null : o, t.appendChild(o);
|
|
411
558
|
} else {
|
|
412
|
-
const
|
|
413
|
-
if (
|
|
559
|
+
const o = s.pop() ?? document.createElement("span");
|
|
560
|
+
if (o.className = "", o.innerText = r.word, r.elements = [o], r.elementAnimations.push(this.initFloatAnimation(r, o)), i)
|
|
414
561
|
if (i.childElementCount > 0)
|
|
415
|
-
i.appendChild(
|
|
562
|
+
i.appendChild(o);
|
|
416
563
|
else {
|
|
417
|
-
const
|
|
418
|
-
|
|
564
|
+
const d = s.pop() ?? document.createElement("span");
|
|
565
|
+
d.className = "", i.remove(), d.appendChild(i), d.appendChild(o), t.appendChild(d), i = d;
|
|
419
566
|
}
|
|
420
567
|
else
|
|
421
|
-
i =
|
|
568
|
+
i = o, t.appendChild(o);
|
|
422
569
|
}
|
|
423
570
|
else if (r.word.length > 0) {
|
|
424
|
-
const
|
|
425
|
-
t.appendChild(
|
|
571
|
+
const o = a.pop() ?? document.createTextNode(" ");
|
|
572
|
+
t.appendChild(o), i = null;
|
|
426
573
|
} else
|
|
427
574
|
i = null;
|
|
428
575
|
}), e.innerText = this.lyricLine.translatedLyric, n.innerText = this.lyricLine.romanLyric;
|
|
@@ -449,7 +596,7 @@ class O {
|
|
|
449
596
|
}
|
|
450
597
|
initEmphasizeAnimation(t) {
|
|
451
598
|
const e = t.startTime - this.lyricLine.startTime, n = t.endTime - t.startTime;
|
|
452
|
-
return t.elements.map((s, a,
|
|
599
|
+
return t.elements.map((s, a, l) => {
|
|
453
600
|
if (a === 0)
|
|
454
601
|
return this.initFloatAnimation(t, s);
|
|
455
602
|
{
|
|
@@ -473,7 +620,7 @@ class O {
|
|
|
473
620
|
],
|
|
474
621
|
{
|
|
475
622
|
duration: Math.max(1e3, t.endTime - t.startTime),
|
|
476
|
-
delay: e + n / (
|
|
623
|
+
delay: e + n / (l.length - 1) * (a - 1),
|
|
477
624
|
id: "glow-word",
|
|
478
625
|
iterations: 1,
|
|
479
626
|
composite: "replace",
|
|
@@ -485,88 +632,88 @@ class O {
|
|
|
485
632
|
});
|
|
486
633
|
}
|
|
487
634
|
updateMaskImage() {
|
|
488
|
-
this.splittedWords.forEach((t) => {
|
|
635
|
+
this._hide && (this.element.style.display = "", this.element.style.visibility = "hidden"), this.splittedWords.forEach((t) => {
|
|
489
636
|
const e = t.elements[0];
|
|
490
637
|
if (e) {
|
|
491
638
|
t.width = e.clientWidth, t.height = e.clientHeight;
|
|
492
|
-
const [n, s, a] =
|
|
639
|
+
const [n, s, a] = U(
|
|
493
640
|
16 / t.width,
|
|
494
641
|
"rgba(0,0,0,0.75)",
|
|
495
642
|
"rgba(0,0,0,0.25)"
|
|
496
|
-
),
|
|
497
|
-
this.lyricPlayer.supportMaskImage ? (e.style.maskImage = n, e.style.maskOrigin = "left", e.style.maskSize =
|
|
643
|
+
), l = `${a * 100}% 100%`;
|
|
644
|
+
this.lyricPlayer.supportMaskImage ? (e.style.maskImage = n, e.style.maskOrigin = "left", e.style.maskSize = l) : (e.style.webkitMaskImage = n, e.style.webkitMaskOrigin = "left", e.style.webkitMaskSize = l);
|
|
498
645
|
const i = t.width + 16, r = `clamp(${-i}px,calc(${-i}px + (var(--amll-player-time) - ${t.startTime})*${i / Math.abs(t.endTime - t.startTime)}px),0px) 0px, left top`;
|
|
499
646
|
e.style.maskPosition = r, e.style.webkitMaskPosition = r;
|
|
500
647
|
}
|
|
501
|
-
});
|
|
648
|
+
}), this._hide && (this.element.style.display = "none", this.element.style.visibility = "");
|
|
502
649
|
}
|
|
503
650
|
getElement() {
|
|
504
651
|
return this.element;
|
|
505
652
|
}
|
|
506
|
-
setTransform(t = this.left, e = this.top, n = this.scale, s = 1, a = 0,
|
|
653
|
+
setTransform(t = this.left, e = this.top, n = this.scale, s = 1, a = 0, l = !1, i = 0) {
|
|
507
654
|
this.left = t, this.top = e, this.scale = n, this.delay = i * 1e3 | 0;
|
|
508
655
|
const r = this.element.children[0];
|
|
509
|
-
r.style.opacity = `${s}`,
|
|
656
|
+
r.style.opacity = `${s}`, l || !this.lyricPlayer.getEnableSpring() ? (this.blur = Math.min(32, a), l && this.element.classList.add(
|
|
510
657
|
this.lyricPlayer.style.classes.tmpDisableTransition
|
|
511
|
-
), this.lineTransforms.posX.setPosition(t), this.lineTransforms.posY.setPosition(e), this.lineTransforms.scale.setPosition(n), this.lyricPlayer.
|
|
658
|
+
), this.lineTransforms.posX.setPosition(t), this.lineTransforms.posY.setPosition(e), this.lineTransforms.scale.setPosition(n), this.lyricPlayer.getEnableSpring() ? this.rebuildStyle() : this.show(), l && requestAnimationFrame(() => {
|
|
512
659
|
this.element.classList.remove(
|
|
513
660
|
this.lyricPlayer.style.classes.tmpDisableTransition
|
|
514
661
|
);
|
|
515
662
|
})) : (this.lineTransforms.posX.setTargetPosition(t, i), this.lineTransforms.posY.setTargetPosition(e, i), this.lineTransforms.scale.setTargetPosition(n), this.blur !== Math.min(32, a) && (this.blur = Math.min(32, a), this.element.style.filter = `blur(${Math.min(32, a)}px)`));
|
|
516
663
|
}
|
|
517
664
|
update(t = 0) {
|
|
518
|
-
this.lyricPlayer.
|
|
665
|
+
this.lyricPlayer.getEnableSpring() && (this.lineTransforms.posX.update(t), this.lineTransforms.posY.update(t), this.lineTransforms.scale.update(t), this.isInSight ? this.show() : this.hide());
|
|
519
666
|
}
|
|
520
667
|
get isInSight() {
|
|
521
|
-
const t = this.lineTransforms.posX.getCurrentPosition(), e = this.lineTransforms.posY.getCurrentPosition(), n = t + this.lineSize[0], s = e + this.lineSize[1], a = this.lyricPlayer.pos[0],
|
|
522
|
-
return !(t > i || e > r || n < a || s <
|
|
668
|
+
const t = this.lineTransforms.posX.getCurrentPosition(), e = this.lineTransforms.posY.getCurrentPosition(), n = t + this.lineSize[0], s = e + this.lineSize[1], a = this.lyricPlayer.pos[0], l = this.lyricPlayer.pos[1], i = this.lyricPlayer.pos[0] + this.lyricPlayer.size[0], r = this.lyricPlayer.pos[1] + this.lyricPlayer.size[1];
|
|
669
|
+
return !(t > i || e > r || n < a || s < l);
|
|
523
670
|
}
|
|
524
671
|
dispose() {
|
|
525
672
|
this.element.remove();
|
|
526
673
|
}
|
|
527
674
|
}
|
|
528
|
-
const
|
|
529
|
-
class
|
|
675
|
+
const J = O($());
|
|
676
|
+
class he extends EventTarget {
|
|
530
677
|
constructor() {
|
|
531
678
|
super();
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
679
|
+
h(this, "element", document.createElement("div"));
|
|
680
|
+
h(this, "currentTime", 0);
|
|
681
|
+
h(this, "lyricLines", []);
|
|
682
|
+
h(this, "processedLines", []);
|
|
683
|
+
h(this, "lyricLinesEl", []);
|
|
684
|
+
h(this, "lyricLinesSize", /* @__PURE__ */ new Map());
|
|
685
|
+
h(this, "hotLines", /* @__PURE__ */ new Set());
|
|
686
|
+
h(this, "bufferedLines", /* @__PURE__ */ new Set());
|
|
687
|
+
h(this, "scrollToIndex", 0);
|
|
688
|
+
h(this, "resizeObserver", new ResizeObserver((e) => {
|
|
542
689
|
const n = e[0].contentRect;
|
|
543
690
|
this.size[0] = n.width, this.size[1] = n.height, this.pos[0] = n.left, this.pos[1] = n.top, this.rebuildStyle(), this.calcLayout(!0), this.lyricLinesEl.forEach((s) => s.updateMaskImage());
|
|
544
691
|
}));
|
|
545
|
-
|
|
692
|
+
h(this, "posXSpringParams", {
|
|
546
693
|
mass: 1,
|
|
547
694
|
damping: 10,
|
|
548
695
|
stiffness: 100
|
|
549
696
|
});
|
|
550
|
-
|
|
697
|
+
h(this, "posYSpringParams", {
|
|
551
698
|
mass: 1,
|
|
552
699
|
damping: 15,
|
|
553
700
|
stiffness: 100
|
|
554
701
|
});
|
|
555
|
-
|
|
702
|
+
h(this, "scaleSpringParams", {
|
|
556
703
|
mass: 1,
|
|
557
704
|
damping: 20,
|
|
558
705
|
stiffness: 100
|
|
559
706
|
});
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
707
|
+
h(this, "enableBlur", !0);
|
|
708
|
+
h(this, "interludeDots");
|
|
709
|
+
h(this, "interludeDotsSize", [0, 0]);
|
|
710
|
+
h(this, "supportPlusLighter", CSS.supports("mix-blend-mode", "plus-lighter"));
|
|
711
|
+
h(this, "supportMaskImage", CSS.supports("mask-image", "none"));
|
|
712
|
+
h(this, "disableSpring", !1);
|
|
713
|
+
h(this, "alignAnchor", 0.5);
|
|
714
|
+
h(this, "size", [0, 0]);
|
|
715
|
+
h(this, "pos", [0, 0]);
|
|
716
|
+
h(this, "style", J.createStyleSheet({
|
|
570
717
|
lyricPlayer: {
|
|
571
718
|
userSelect: "none",
|
|
572
719
|
padding: "1rem",
|
|
@@ -672,10 +819,10 @@ class Z extends EventTarget {
|
|
|
672
819
|
transition: "none !important"
|
|
673
820
|
}
|
|
674
821
|
}));
|
|
675
|
-
|
|
822
|
+
h(this, "onPageShow", () => {
|
|
676
823
|
this.calcLayout(!0);
|
|
677
824
|
});
|
|
678
|
-
this.interludeDots = new
|
|
825
|
+
this.interludeDots = new X(this), this.element.setAttribute("class", this.style.classes.lyricPlayer), this.disableSpring && this.element.classList.add(this.style.classes.disableSpring), this.rebuildStyle(), this.resizeObserver.observe(this.element), this.element.appendChild(this.interludeDots.getElement()), this.style.attach(), this.interludeDots.setTransform(0, 200), window.addEventListener("pageshow", this.onPageShow);
|
|
679
826
|
}
|
|
680
827
|
/**
|
|
681
828
|
* 设置是否使用物理弹簧算法实现歌词动画效果,默认启用
|
|
@@ -687,28 +834,39 @@ class Z extends EventTarget {
|
|
|
687
834
|
setEnableSpring(e = !0) {
|
|
688
835
|
this.disableSpring = !e, e ? this.element.classList.remove(this.style.classes.disableSpring) : this.element.classList.add(this.style.classes.disableSpring), this.calcLayout(!0);
|
|
689
836
|
}
|
|
837
|
+
/**
|
|
838
|
+
* 获取当前是否启用了物理弹簧
|
|
839
|
+
* @returns 是否启用物理弹簧
|
|
840
|
+
*/
|
|
841
|
+
getEnableSpring() {
|
|
842
|
+
return !this.disableSpring;
|
|
843
|
+
}
|
|
690
844
|
/**
|
|
691
845
|
* 获取当前播放时间里是否处于间奏区间
|
|
692
846
|
* 如果是则会返回单位为毫秒的始末时间
|
|
693
847
|
* 否则返回 undefined
|
|
848
|
+
*
|
|
849
|
+
* 这个只允许内部调用
|
|
694
850
|
* @returns [开始时间,结束时间] 或 undefined 如果不处于间奏区间
|
|
695
851
|
*/
|
|
696
852
|
getCurrentInterlude() {
|
|
697
|
-
var s, a,
|
|
853
|
+
var s, a, l;
|
|
698
854
|
if (this.bufferedLines.size > 0)
|
|
699
855
|
return;
|
|
700
856
|
const e = this.currentTime + 20, n = this.scrollToIndex;
|
|
701
857
|
if (n === 0) {
|
|
702
858
|
if ((s = this.processedLines[0]) != null && s.startTime && this.processedLines[0].startTime > e)
|
|
703
859
|
return [0, this.processedLines[0].startTime];
|
|
704
|
-
} else if ((a = this.processedLines[n]) != null && a.endTime && ((
|
|
860
|
+
} else if ((a = this.processedLines[n]) != null && a.endTime && ((l = this.processedLines[n + 1]) != null && l.startTime) && this.processedLines[n + 1].startTime > e && this.processedLines[n].endTime < e)
|
|
705
861
|
return [
|
|
706
862
|
this.processedLines[n].endTime,
|
|
707
863
|
this.processedLines[n + 1].startTime
|
|
708
864
|
];
|
|
709
865
|
}
|
|
710
866
|
/**
|
|
711
|
-
*
|
|
867
|
+
* 重建样式
|
|
868
|
+
*
|
|
869
|
+
* 这个只允许内部调用
|
|
712
870
|
*/
|
|
713
871
|
rebuildStyle() {
|
|
714
872
|
let e = "";
|
|
@@ -728,13 +886,13 @@ class Z extends EventTarget {
|
|
|
728
886
|
setLyricLines(e) {
|
|
729
887
|
this.lyricLines = e;
|
|
730
888
|
const n = 750;
|
|
731
|
-
this.processedLines = e.map((s, a,
|
|
889
|
+
this.processedLines = e.map((s, a, l) => {
|
|
732
890
|
if (s.isBG)
|
|
733
891
|
return {
|
|
734
892
|
...s
|
|
735
893
|
};
|
|
736
894
|
{
|
|
737
|
-
const i =
|
|
895
|
+
const i = l[a - 1], r = l[a - 2];
|
|
738
896
|
if (i != null && i.isBG && r) {
|
|
739
897
|
if (r.endTime < s.startTime)
|
|
740
898
|
return {
|
|
@@ -750,79 +908,118 @@ class Z extends EventTarget {
|
|
|
750
908
|
...s
|
|
751
909
|
};
|
|
752
910
|
}
|
|
753
|
-
}), this.processedLines.forEach((s, a,
|
|
754
|
-
const i =
|
|
755
|
-
r &&
|
|
756
|
-
}), this.processedLines.forEach((s, a,
|
|
911
|
+
}), this.processedLines.forEach((s, a, l) => {
|
|
912
|
+
const i = l[a + 1], r = s.words[s.words.length - 1];
|
|
913
|
+
r && v(r) && (i ? i.startTime > s.endTime && (s.endTime = Math.min(s.endTime + 1500, i.startTime)) : s.endTime = s.endTime + 1500);
|
|
914
|
+
}), this.processedLines.forEach((s, a, l) => {
|
|
757
915
|
if (s.isBG)
|
|
758
916
|
return;
|
|
759
|
-
const i =
|
|
917
|
+
const i = l[a + 1];
|
|
760
918
|
i != null && i.isBG && (i.startTime = Math.min(i.startTime, s.startTime));
|
|
761
919
|
}), this.lyricLinesEl.forEach((s) => s.dispose()), this.lyricLinesEl = this.processedLines.map(
|
|
762
|
-
(s) => new
|
|
763
|
-
), this.lyricLinesEl.forEach(
|
|
764
|
-
|
|
765
|
-
), this.setLinePosXSpringParams({}), this.setLinePosYSpringParams({}), this.setLineScaleSpringParams({}), this.setCurrentTime(0, !0), this.calcLayout(!0);
|
|
920
|
+
(s) => new H(this, s)
|
|
921
|
+
), this.lyricLinesEl.forEach((s) => {
|
|
922
|
+
this.element.appendChild(s.getElement()), s.updateMaskImage();
|
|
923
|
+
}), this.setLinePosXSpringParams({}), this.setLinePosYSpringParams({}), this.setLineScaleSpringParams({}), this.setCurrentTime(0, !0), this.calcLayout(!0);
|
|
766
924
|
}
|
|
925
|
+
/**
|
|
926
|
+
* 重新布局定位歌词行的位置,调用完成后再逐帧调用 `update`
|
|
927
|
+
* 函数即可让歌词通过动画移动到目标位置。
|
|
928
|
+
*
|
|
929
|
+
* 此函数还有一个 `reflow` 参数,用于指定是否需要重新计算布局
|
|
930
|
+
*
|
|
931
|
+
* 因为计算布局必定会导致浏览器重排布局,所以会大幅度影响流畅度和性能,故请只在以下情况下将其设置为 true:
|
|
932
|
+
*
|
|
933
|
+
* 1. 歌词页面大小发生改变时(这个组件会自行处理)
|
|
934
|
+
* 2. 加载了新的歌词时(不论前后歌词是否完全一样)
|
|
935
|
+
* 3. 用户自行跳转了歌曲播放位置(不论距离远近)
|
|
936
|
+
*
|
|
937
|
+
* @param reflow 是否进行重新布局(重新计算每行歌词大小)
|
|
938
|
+
*/
|
|
767
939
|
calcLayout(e = !1) {
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
];
|
|
773
|
-
this.lyricLinesSize.set(o, m), o.lineSize = m;
|
|
940
|
+
var d, u, f;
|
|
941
|
+
e && (this.lyricLinesEl.forEach((m) => {
|
|
942
|
+
const p = m.measureSize();
|
|
943
|
+
this.lyricLinesSize.set(m, p), m.lineSize = p;
|
|
774
944
|
}), this.interludeDotsSize[0] = this.interludeDots.getElement().clientWidth, this.interludeDotsSize[1] = this.interludeDots.getElement().clientHeight);
|
|
775
945
|
const n = 0.95;
|
|
776
946
|
let a = -this.lyricLinesEl.slice(0, this.scrollToIndex).reduce(
|
|
777
|
-
(
|
|
947
|
+
(m, p) => {
|
|
948
|
+
var y;
|
|
949
|
+
return m + (p.getLine().isBG ? 0 : ((y = this.lyricLinesSize.get(p)) == null ? void 0 : y[1]) ?? 0);
|
|
950
|
+
},
|
|
778
951
|
0
|
|
779
952
|
);
|
|
780
953
|
if (this.alignAnchor === "bottom") {
|
|
781
954
|
a += this.element.clientHeight / 2;
|
|
782
|
-
const
|
|
783
|
-
if (
|
|
784
|
-
const
|
|
785
|
-
a -=
|
|
955
|
+
const m = this.lyricLinesEl[this.scrollToIndex];
|
|
956
|
+
if (m) {
|
|
957
|
+
const p = ((d = this.lyricLinesSize.get(m)) == null ? void 0 : d[1]) ?? 0;
|
|
958
|
+
a -= p / 2;
|
|
786
959
|
}
|
|
787
960
|
} else if (typeof this.alignAnchor == "number") {
|
|
788
961
|
a += this.element.clientHeight * this.alignAnchor;
|
|
789
|
-
const
|
|
790
|
-
if (
|
|
791
|
-
const
|
|
792
|
-
a -=
|
|
962
|
+
const m = this.lyricLinesEl[this.scrollToIndex];
|
|
963
|
+
if (m) {
|
|
964
|
+
const p = ((u = this.lyricLinesSize.get(m)) == null ? void 0 : u[1]) ?? 0;
|
|
965
|
+
a -= p / 2;
|
|
793
966
|
}
|
|
794
967
|
}
|
|
795
|
-
const
|
|
968
|
+
const l = this.currentTime === 0 ? void 0 : this.getCurrentInterlude();
|
|
796
969
|
let i = 0;
|
|
797
|
-
if (
|
|
798
|
-
const
|
|
799
|
-
|
|
970
|
+
if (l && (i = l[1] - l[0], i >= 5e3)) {
|
|
971
|
+
const m = this.currentTime === 0 ? this.lyricLinesEl[0] : this.lyricLinesEl[this.scrollToIndex + 1];
|
|
972
|
+
m && (a -= ((f = this.lyricLinesSize.get(m)) == null ? void 0 : f[1]) ?? 0);
|
|
800
973
|
}
|
|
801
974
|
const r = Math.max(...this.bufferedLines);
|
|
802
|
-
let
|
|
803
|
-
this.lyricLinesEl.forEach((
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
975
|
+
let o = 0;
|
|
976
|
+
this.lyricLinesEl.forEach((m, p) => {
|
|
977
|
+
var C, z, A;
|
|
978
|
+
const y = this.bufferedLines.has(p), T = y || p >= this.scrollToIndex && p < r, E = m.getLine();
|
|
979
|
+
let M = 0;
|
|
980
|
+
E.isDuet && (M = this.size[0] - (((C = this.lyricLinesSize.get(m)) == null ? void 0 : C[0]) ?? 0)), p === this.scrollToIndex + 1 && i >= 5e3 && (this.interludeDots.setTransform(0, a), this.interludeDots.setInterlude(this.getCurrentInterlude()), a += this.interludeDotsSize[1]), m.setTransform(
|
|
981
|
+
M,
|
|
808
982
|
a,
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
this.enableBlur ? 3 * (
|
|
983
|
+
T ? 1 : n,
|
|
984
|
+
y ? 1 : 1 / 3,
|
|
985
|
+
this.enableBlur ? 3 * (T ? 0 : 1 + (p < this.scrollToIndex ? Math.abs(this.scrollToIndex - p) : Math.abs(p - Math.max(this.scrollToIndex, r)))) : 0,
|
|
812
986
|
e,
|
|
813
|
-
|
|
814
|
-
),
|
|
987
|
+
o
|
|
988
|
+
), E.isBG && T ? a += ((z = this.lyricLinesSize.get(m)) == null ? void 0 : z[1]) ?? 0 : E.isBG || (a += ((A = this.lyricLinesSize.get(m)) == null ? void 0 : A[1]) ?? 0), a >= 0 && (o += 0.05);
|
|
815
989
|
});
|
|
816
990
|
}
|
|
991
|
+
/**
|
|
992
|
+
* 获取当前歌词的播放位置
|
|
993
|
+
*
|
|
994
|
+
* 一般和最后调用 `setCurrentTime` 给予的参数一样
|
|
995
|
+
* @returns 当前播放位置
|
|
996
|
+
*/
|
|
817
997
|
getCurrentTime() {
|
|
818
998
|
return this.currentTime;
|
|
819
999
|
}
|
|
820
|
-
|
|
1000
|
+
/**
|
|
1001
|
+
* 获取当前歌词数组
|
|
1002
|
+
*
|
|
1003
|
+
* 一般和最后调用 `setLyricLines` 给予的参数一样
|
|
1004
|
+
* @returns 当前歌词数组
|
|
1005
|
+
*/
|
|
1006
|
+
getLyricLines() {
|
|
821
1007
|
return this.lyricLines;
|
|
822
1008
|
}
|
|
823
1009
|
getElement() {
|
|
824
1010
|
return this.element;
|
|
825
1011
|
}
|
|
1012
|
+
/**
|
|
1013
|
+
* 设置歌词行的对齐方式,默认为 `top`
|
|
1014
|
+
*
|
|
1015
|
+
* - 设置成 `top` 的话歌词将会向组件顶部对齐
|
|
1016
|
+
* - 设置成 `bottom` 的话歌词将会向组件底部对齐
|
|
1017
|
+
* - 设置成 [0.0-1.0] 之间任意数字的话则会根据当前组件高度从顶部向下位移为对齐位置垂直居中对齐
|
|
1018
|
+
* @param alignAnchor 歌词行对齐方式,详情见函数说明
|
|
1019
|
+
*/
|
|
1020
|
+
setAlignAnchor(e) {
|
|
1021
|
+
this.alignAnchor = e;
|
|
1022
|
+
}
|
|
826
1023
|
/**
|
|
827
1024
|
* 设置当前播放进度,单位为毫秒且**必须是整数**,此时将会更新内部的歌词进度信息
|
|
828
1025
|
* 内部会根据调用间隔和播放进度自动决定如何滚动和显示歌词,所以这个的调用频率越快越准确越好
|
|
@@ -832,44 +1029,51 @@ class Z extends EventTarget {
|
|
|
832
1029
|
*/
|
|
833
1030
|
setCurrentTime(e, n = !1) {
|
|
834
1031
|
this.currentTime = e, this.element.style.setProperty("--amll-player-time", `${e}`);
|
|
835
|
-
const s = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set(),
|
|
1032
|
+
const s = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set();
|
|
836
1033
|
this.hotLines.forEach((i) => {
|
|
837
1034
|
const r = this.processedLines[i];
|
|
838
1035
|
if (!r.isBG)
|
|
839
1036
|
if (r) {
|
|
840
|
-
const
|
|
841
|
-
if (
|
|
842
|
-
const
|
|
843
|
-
(
|
|
1037
|
+
const o = this.processedLines[i + 1];
|
|
1038
|
+
if (o != null && o.isBG) {
|
|
1039
|
+
const d = Math.min(r.startTime, o == null ? void 0 : o.startTime), u = Math.max(r.endTime, o == null ? void 0 : o.endTime);
|
|
1040
|
+
(d > e || u <= e) && (this.hotLines.delete(i), s.add(i), this.hotLines.delete(i + 1), s.add(i + 1), n && (this.lyricLinesEl[i].disable(), this.lyricLinesEl[i + 1].disable()));
|
|
844
1041
|
} else
|
|
845
1042
|
(r.startTime > e || r.endTime <= e) && (this.hotLines.delete(i), s.add(i), n && this.lyricLinesEl[i].disable());
|
|
846
1043
|
} else
|
|
847
1044
|
this.hotLines.delete(i), s.add(i), n && this.lyricLinesEl[i].disable();
|
|
848
|
-
}), this.processedLines.forEach((i, r,
|
|
849
|
-
var
|
|
850
|
-
!i.isBG && i.startTime <= e && i.endTime > e && (this.hotLines.has(r) || (this.hotLines.add(r),
|
|
1045
|
+
}), this.processedLines.forEach((i, r, o) => {
|
|
1046
|
+
var d;
|
|
1047
|
+
!i.isBG && i.startTime <= e && i.endTime > e && (this.hotLines.has(r) || (this.hotLines.add(r), l.add(r), n && this.lyricLinesEl[r].enable(), (d = o[r + 1]) != null && d.isBG && (this.hotLines.add(r + 1), l.add(r + 1), n && this.lyricLinesEl[r + 1].enable())));
|
|
851
1048
|
}), this.bufferedLines.forEach((i) => {
|
|
852
1049
|
this.hotLines.has(i) || (a.add(i), n && this.lyricLinesEl[i].disable());
|
|
853
1050
|
}), n ? (this.bufferedLines.size > 0 ? this.scrollToIndex = Math.min(...this.bufferedLines) : this.scrollToIndex = this.processedLines.findIndex(
|
|
854
1051
|
(i) => i.startTime >= e
|
|
855
|
-
), this.bufferedLines.clear(), this.hotLines.forEach((i) => this.bufferedLines.add(i)), this.calcLayout(!0)) : (a.size > 0 ||
|
|
1052
|
+
), this.bufferedLines.clear(), this.hotLines.forEach((i) => this.bufferedLines.add(i)), this.calcLayout(!0)) : (a.size > 0 || l.size > 0) && (a.size === 0 && l.size > 0 ? (l.forEach((i) => {
|
|
856
1053
|
this.bufferedLines.add(i), this.lyricLinesEl[i].enable();
|
|
857
|
-
}), this.scrollToIndex = Math.min(...this.bufferedLines)) :
|
|
1054
|
+
}), this.scrollToIndex = Math.min(...this.bufferedLines)) : l.size === 0 && a.size > 0 ? W(a, this.bufferedLines) && this.bufferedLines.forEach((i) => {
|
|
858
1055
|
this.hotLines.has(i) || (this.bufferedLines.delete(i), this.lyricLinesEl[i].disable());
|
|
859
|
-
}) : (
|
|
1056
|
+
}) : (l.forEach((i) => {
|
|
860
1057
|
this.bufferedLines.add(i), this.lyricLinesEl[i].enable();
|
|
861
1058
|
}), a.forEach((i) => {
|
|
862
1059
|
this.bufferedLines.delete(i), this.lyricLinesEl[i].disable();
|
|
863
1060
|
}), this.bufferedLines.size > 0 && (this.scrollToIndex = Math.min(...this.bufferedLines))), this.calcLayout());
|
|
864
1061
|
}
|
|
865
1062
|
/**
|
|
866
|
-
*
|
|
1063
|
+
* 更新动画,这个函数应该被逐帧调用或者在以下情况下调用一次:
|
|
1064
|
+
*
|
|
1065
|
+
* 1. 刚刚调用完设置歌词函数的时候
|
|
867
1066
|
* @param delta 距离上一次被调用到现在的时长,单位为毫秒(可为浮点数)
|
|
868
1067
|
*/
|
|
869
1068
|
update(e = 0) {
|
|
870
1069
|
const n = e / 1e3;
|
|
871
1070
|
this.interludeDots.update(e), this.lyricLinesEl.forEach((s) => s.update(n));
|
|
872
1071
|
}
|
|
1072
|
+
/**
|
|
1073
|
+
* 设置所有歌词行在横坐标上的弹簧属性,包括重量、弹力和阻力。
|
|
1074
|
+
*
|
|
1075
|
+
* @param params 需要设置的弹簧属性,提供的属性将会覆盖原来的属性,未提供的属性将会保持原样
|
|
1076
|
+
*/
|
|
873
1077
|
setLinePosXSpringParams(e) {
|
|
874
1078
|
this.posXSpringParams = {
|
|
875
1079
|
...this.posXSpringParams,
|
|
@@ -878,6 +1082,11 @@ class Z extends EventTarget {
|
|
|
878
1082
|
(n) => n.lineTransforms.posX.updateParams(this.posXSpringParams)
|
|
879
1083
|
);
|
|
880
1084
|
}
|
|
1085
|
+
/**
|
|
1086
|
+
* 设置所有歌词行在纵坐标上的弹簧属性,包括重量、弹力和阻力。
|
|
1087
|
+
*
|
|
1088
|
+
* @param params 需要设置的弹簧属性,提供的属性将会覆盖原来的属性,未提供的属性将会保持原样
|
|
1089
|
+
*/
|
|
881
1090
|
setLinePosYSpringParams(e) {
|
|
882
1091
|
this.posYSpringParams = {
|
|
883
1092
|
...this.posYSpringParams,
|
|
@@ -886,6 +1095,11 @@ class Z extends EventTarget {
|
|
|
886
1095
|
(n) => n.lineTransforms.posY.updateParams(this.posYSpringParams)
|
|
887
1096
|
);
|
|
888
1097
|
}
|
|
1098
|
+
/**
|
|
1099
|
+
* 设置所有歌词行在缩放大小上的弹簧属性,包括重量、弹力和阻力。
|
|
1100
|
+
*
|
|
1101
|
+
* @param params 需要设置的弹簧属性,提供的属性将会覆盖原来的属性,未提供的属性将会保持原样
|
|
1102
|
+
*/
|
|
889
1103
|
setLineScaleSpringParams(e) {
|
|
890
1104
|
this.scaleSpringParams = {
|
|
891
1105
|
...this.scaleSpringParams,
|
|
@@ -899,6 +1113,8 @@ class Z extends EventTarget {
|
|
|
899
1113
|
}
|
|
900
1114
|
}
|
|
901
1115
|
export {
|
|
902
|
-
|
|
903
|
-
|
|
1116
|
+
le as BackgroundRender,
|
|
1117
|
+
he as LyricPlayer,
|
|
1118
|
+
ae as ttml
|
|
904
1119
|
};
|
|
1120
|
+
//# sourceMappingURL=amll-core.mjs.map
|