@applemusic-like-lyrics/core 0.0.11 → 0.0.13
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 +4 -0
- package/dist/amll-core.js +1 -1
- package/dist/amll-core.js.map +1 -1
- package/dist/amll-core.mjs +531 -366
- package/dist/amll-core.mjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/lyric-player/index.d.ts +53 -2
- package/dist/lyric-player/lyric-line.d.ts +16 -1
- package/dist/utils/spring.d.ts +1 -0
- package/package.json +11 -6
package/dist/amll-core.mjs
CHANGED
|
@@ -1,133 +1,134 @@
|
|
|
1
|
-
import { Container as
|
|
2
|
-
import { Application as
|
|
1
|
+
import { Container as z } from "@pixi/display";
|
|
2
|
+
import { Application as A } from "@pixi/app";
|
|
3
3
|
import { BlurFilter as y } from "@pixi/filter-blur";
|
|
4
|
-
import { ColorMatrixFilter as
|
|
5
|
-
import { Texture as
|
|
6
|
-
import { Sprite as
|
|
4
|
+
import { ColorMatrixFilter as v } from "@pixi/filter-color-matrix";
|
|
5
|
+
import { Texture as I } from "@pixi/core";
|
|
6
|
+
import { Sprite as S } from "@pixi/sprite";
|
|
7
|
+
import { BulgePinchFilter as E } from "@pixi/filter-bulge-pinch";
|
|
7
8
|
import { create as D } from "jss";
|
|
8
|
-
import
|
|
9
|
-
const
|
|
9
|
+
import k from "jss-preset-default";
|
|
10
|
+
const B = /^(((?<hour>[0-9]+):)?(?<min>[0-9]+):)?(?<sec>[0-9]+([\.:]([0-9]+))?)/;
|
|
10
11
|
function T(h) {
|
|
11
|
-
const e =
|
|
12
|
+
const e = B.exec(h);
|
|
12
13
|
if (e) {
|
|
13
|
-
const t = Number(e.groups?.hour || "0"),
|
|
14
|
-
return Math.floor((t * 3600 +
|
|
14
|
+
const t = Number(e.groups?.hour || "0"), i = Number(e.groups?.min || "0"), s = Number(e.groups?.sec.replace(/:/, ".") || "0");
|
|
15
|
+
return Math.floor((t * 3600 + i * 60 + s) * 1e3);
|
|
15
16
|
} else
|
|
16
17
|
throw new TypeError("时间戳字符串解析失败");
|
|
17
18
|
}
|
|
18
|
-
function
|
|
19
|
+
function $(h) {
|
|
19
20
|
const t = new DOMParser().parseFromString(
|
|
20
21
|
h,
|
|
21
22
|
"application/xml"
|
|
22
23
|
);
|
|
23
|
-
let
|
|
24
|
-
for (const
|
|
25
|
-
if (
|
|
26
|
-
const
|
|
27
|
-
|
|
24
|
+
let i = "v1";
|
|
25
|
+
for (const r of t.querySelectorAll("ttm\\:agent"))
|
|
26
|
+
if (r.getAttribute("type") === "person") {
|
|
27
|
+
const n = r.getAttribute("xml:id");
|
|
28
|
+
n && (i = n);
|
|
28
29
|
}
|
|
29
|
-
const
|
|
30
|
-
for (const
|
|
31
|
-
const
|
|
30
|
+
const s = [];
|
|
31
|
+
for (const r of t.querySelectorAll("body p[begin][end]")) {
|
|
32
|
+
const n = {
|
|
32
33
|
words: [],
|
|
33
|
-
startTime: T(
|
|
34
|
-
endTime: T(
|
|
34
|
+
startTime: T(r.getAttribute("begin") ?? "0:0"),
|
|
35
|
+
endTime: T(r.getAttribute("end") ?? "0:0"),
|
|
35
36
|
translatedLyric: "",
|
|
36
37
|
romanLyric: "",
|
|
37
38
|
isBG: !1,
|
|
38
|
-
isDuet:
|
|
39
|
+
isDuet: r.getAttribute("ttm:agent") !== i
|
|
39
40
|
};
|
|
40
|
-
let
|
|
41
|
-
for (const
|
|
42
|
-
if (
|
|
43
|
-
const o =
|
|
44
|
-
/^(\s+)$/.test(o) ?
|
|
41
|
+
let a = null;
|
|
42
|
+
for (const l of r.childNodes)
|
|
43
|
+
if (l.nodeType === Node.TEXT_NODE) {
|
|
44
|
+
const o = l.textContent ?? "";
|
|
45
|
+
/^(\s+)$/.test(o) ? n.words.push({
|
|
45
46
|
word: " ",
|
|
46
47
|
startTime: 0,
|
|
47
48
|
endTime: 0
|
|
48
|
-
}) :
|
|
49
|
+
}) : n.words.push({
|
|
49
50
|
word: o,
|
|
50
51
|
startTime: 0,
|
|
51
52
|
endTime: 0
|
|
52
53
|
});
|
|
53
|
-
} else if (
|
|
54
|
-
const o =
|
|
54
|
+
} else if (l.nodeType === Node.ELEMENT_NODE) {
|
|
55
|
+
const o = l, c = o.getAttribute("ttm:role");
|
|
55
56
|
if (o.nodeName === "span" && c)
|
|
56
57
|
if (c === "x-bg") {
|
|
57
|
-
const
|
|
58
|
+
const m = {
|
|
58
59
|
words: [],
|
|
59
|
-
startTime:
|
|
60
|
-
endTime:
|
|
60
|
+
startTime: n.startTime,
|
|
61
|
+
endTime: n.endTime,
|
|
61
62
|
translatedLyric: "",
|
|
62
63
|
romanLyric: "",
|
|
63
64
|
isBG: !0,
|
|
64
|
-
isDuet:
|
|
65
|
+
isDuet: n.isDuet
|
|
65
66
|
};
|
|
66
|
-
for (const
|
|
67
|
-
if (
|
|
68
|
-
const
|
|
69
|
-
/^(\s+)$/.test(
|
|
67
|
+
for (const p of o.childNodes)
|
|
68
|
+
if (p.nodeType === Node.TEXT_NODE) {
|
|
69
|
+
const d = p.textContent ?? "";
|
|
70
|
+
/^(\s+)$/.test(d) ? m.words.push({
|
|
70
71
|
word: " ",
|
|
71
72
|
startTime: 0,
|
|
72
73
|
endTime: 0
|
|
73
|
-
}) :
|
|
74
|
-
word:
|
|
74
|
+
}) : m.words.push({
|
|
75
|
+
word: d,
|
|
75
76
|
startTime: 0,
|
|
76
77
|
endTime: 0
|
|
77
78
|
});
|
|
78
|
-
} else if (
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
else if (
|
|
79
|
+
} else if (p.nodeType === Node.ELEMENT_NODE) {
|
|
80
|
+
const d = p, g = d.getAttribute("ttm:role");
|
|
81
|
+
if (d.nodeName === "span" && g)
|
|
82
|
+
g === "x-translation" ? m.translatedLyric = d.innerHTML.trim() : g === "x-roman" && (m.romanLyric = d.innerHTML.trim());
|
|
83
|
+
else if (d.hasAttribute("begin") && d.hasAttribute("end")) {
|
|
83
84
|
const b = {
|
|
84
|
-
word:
|
|
85
|
-
startTime: T(
|
|
86
|
-
endTime: T(
|
|
85
|
+
word: p.textContent,
|
|
86
|
+
startTime: T(d.getAttribute("begin")),
|
|
87
|
+
endTime: T(d.getAttribute("end"))
|
|
87
88
|
};
|
|
88
|
-
|
|
89
|
+
m.words.push(b);
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
|
-
const u =
|
|
92
|
-
|
|
93
|
-
const f =
|
|
94
|
-
|
|
92
|
+
const u = m.words[0];
|
|
93
|
+
m.startTime = u.startTime, u?.word.startsWith("(") && (u.word = u.word.substring(1));
|
|
94
|
+
const f = m.words[m.words.length - 1];
|
|
95
|
+
m.endTime = f.endTime, f?.word.endsWith(")") && (f.word = f.word.substring(
|
|
95
96
|
0,
|
|
96
97
|
f.word.length - 1
|
|
97
|
-
)),
|
|
98
|
+
)), a = m;
|
|
98
99
|
} else
|
|
99
|
-
c === "x-translation" ?
|
|
100
|
+
c === "x-translation" ? n.translatedLyric = o.innerHTML : c === "x-roman" && (n.romanLyric = o.innerHTML);
|
|
100
101
|
else if (o.hasAttribute("begin") && o.hasAttribute("end")) {
|
|
101
|
-
const
|
|
102
|
-
word:
|
|
102
|
+
const m = {
|
|
103
|
+
word: l.textContent ?? "",
|
|
103
104
|
startTime: T(o.getAttribute("begin")),
|
|
104
105
|
endTime: T(o.getAttribute("end"))
|
|
105
106
|
};
|
|
106
|
-
|
|
107
|
+
n.words.push(m);
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
|
-
|
|
110
|
+
s.push(n), a && s.push(a);
|
|
110
111
|
}
|
|
111
|
-
return
|
|
112
|
+
return s;
|
|
112
113
|
}
|
|
113
|
-
const
|
|
114
|
+
const ae = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
114
115
|
__proto__: null,
|
|
115
|
-
parseTTML:
|
|
116
|
+
parseTTML: $
|
|
116
117
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
117
|
-
class
|
|
118
|
+
class O extends z {
|
|
118
119
|
time = 0;
|
|
119
120
|
}
|
|
120
|
-
class
|
|
121
|
+
class W {
|
|
121
122
|
constructor(e) {
|
|
122
123
|
this.canvas = e;
|
|
123
124
|
const t = e.getBoundingClientRect();
|
|
124
125
|
this.canvas.width = t.width * this.currerntRenderScale, this.canvas.height = t.height * this.currerntRenderScale, this.observer = new ResizeObserver(() => {
|
|
125
|
-
const
|
|
126
|
-
this.canvas.width = Math.max(1,
|
|
126
|
+
const i = e.getBoundingClientRect();
|
|
127
|
+
this.canvas.width = Math.max(1, i.width), this.canvas.height = Math.max(1, i.height), this.app.renderer.resize(
|
|
127
128
|
this.canvas.width * this.currerntRenderScale,
|
|
128
129
|
this.canvas.height * this.currerntRenderScale
|
|
129
130
|
), this.app.ticker.start(), this.rebuildFilters();
|
|
130
|
-
}), this.observer.observe(e), this.app = new
|
|
131
|
+
}), this.observer.observe(e), this.app = new A({
|
|
131
132
|
view: e,
|
|
132
133
|
resizeTo: this.canvas,
|
|
133
134
|
powerPreference: "low-power",
|
|
@@ -141,17 +142,17 @@ class N {
|
|
|
141
142
|
lastContainer = /* @__PURE__ */ new Set();
|
|
142
143
|
onTick = (e) => {
|
|
143
144
|
for (const t of this.lastContainer)
|
|
144
|
-
t.alpha = Math.max(0, t.alpha - e / 60), t.alpha <= 0 && (this.app.stage.removeChild(t), this.lastContainer.delete(t));
|
|
145
|
+
t.alpha = Math.max(0, t.alpha - e / 60), t.alpha <= 0 && (this.app.stage.removeChild(t), this.lastContainer.delete(t), t.destroy(!0));
|
|
145
146
|
if (this.curContainer) {
|
|
146
147
|
this.curContainer.alpha = Math.min(
|
|
147
148
|
1,
|
|
148
149
|
this.curContainer.alpha + e / 60
|
|
149
150
|
);
|
|
150
|
-
const [t,
|
|
151
|
-
t.position.set(this.app.screen.width / 2, this.app.screen.height / 2),
|
|
151
|
+
const [t, i, s, r] = this.curContainer.children, n = Math.max(this.app.screen.width, this.app.screen.height);
|
|
152
|
+
t.position.set(this.app.screen.width / 2, this.app.screen.height / 2), i.position.set(
|
|
152
153
|
this.app.screen.width / 2.5,
|
|
153
154
|
this.app.screen.height / 2.5
|
|
154
|
-
),
|
|
155
|
+
), s.position.set(this.app.screen.width / 2, this.app.screen.height / 2), r.position.set(this.app.screen.width / 2, this.app.screen.height / 2), t.width = n * Math.sqrt(2), t.height = t.width, i.width = n * 0.8, i.height = i.width, s.width = n * 0.5, s.height = s.width, r.width = n * 0.25, r.height = r.width, this.curContainer.time += e * this.flowSpeed, t.rotation += e / 1e3 * this.flowSpeed, i.rotation -= e / 500 * this.flowSpeed, s.rotation += e / 1e3 * this.flowSpeed, r.rotation -= e / 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), r.x = this.app.screen.width / 2 + this.app.screen.width / 4 * 0.1 + Math.cos(this.curContainer.time * 6e-3 * 0.75), r.y = this.app.screen.height / 2 + this.app.screen.width / 4 * 0.1 + Math.cos(this.curContainer.time * 6e-3 * 0.75), this.curContainer.alpha >= 1 && this.lastContainer.size === 0 && this.staticMode && this.app.ticker.stop();
|
|
155
156
|
}
|
|
156
157
|
};
|
|
157
158
|
flowSpeed = 2;
|
|
@@ -178,12 +179,38 @@ class N {
|
|
|
178
179
|
), this.rebuildFilters();
|
|
179
180
|
}
|
|
180
181
|
rebuildFilters() {
|
|
181
|
-
const e = Math.min(this.canvas.width, this.canvas.height), t = new
|
|
182
|
-
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
const
|
|
186
|
-
|
|
182
|
+
const e = Math.min(this.canvas.width, this.canvas.height), t = Math.max(this.canvas.width, this.canvas.height), i = new v();
|
|
183
|
+
i.saturate(1.2, !1);
|
|
184
|
+
const s = new v();
|
|
185
|
+
s.brightness(0.6, !1);
|
|
186
|
+
const r = new v();
|
|
187
|
+
r.contrast(0.3, !0), this.app.stage.filters?.forEach((n) => {
|
|
188
|
+
n.destroy();
|
|
189
|
+
}), this.app.stage.filters = [], this.app.stage.filters.push(new y(5, 1)), this.app.stage.filters.push(new y(10, 1)), this.app.stage.filters.push(new y(20, 2)), this.app.stage.filters.push(new y(40, 2)), this.app.stage.filters.push(new y(80, 2)), e > 768 && this.app.stage.filters.push(new y(160, 4)), e > 768 * 2 && this.app.stage.filters.push(new y(320, 4)), this.app.stage.filters.push(i, s, r), this.app.stage.filters.push(new y(5, 1)), Math.random() > 0.5 ? (this.app.stage.filters.push(
|
|
190
|
+
new E({
|
|
191
|
+
radius: (t + e) / 2,
|
|
192
|
+
strength: 1,
|
|
193
|
+
center: [0.25, 1]
|
|
194
|
+
})
|
|
195
|
+
), this.app.stage.filters.push(
|
|
196
|
+
new E({
|
|
197
|
+
radius: (t + e) / 2,
|
|
198
|
+
strength: 1,
|
|
199
|
+
center: [0.75, 0]
|
|
200
|
+
})
|
|
201
|
+
)) : (this.app.stage.filters.push(
|
|
202
|
+
new E({
|
|
203
|
+
radius: (t + e) / 2,
|
|
204
|
+
strength: 1,
|
|
205
|
+
center: [0.75, 1]
|
|
206
|
+
})
|
|
207
|
+
), this.app.stage.filters.push(
|
|
208
|
+
new E({
|
|
209
|
+
radius: (t + e) / 2,
|
|
210
|
+
strength: 1,
|
|
211
|
+
center: [0.25, 0]
|
|
212
|
+
})
|
|
213
|
+
));
|
|
187
214
|
}
|
|
188
215
|
/**
|
|
189
216
|
* 是否启用静态模式,即图片在更换后就会保持静止状态并禁用更新,以节省性能
|
|
@@ -218,14 +245,33 @@ class N {
|
|
|
218
245
|
* @param albumUrl 图片的目标链接
|
|
219
246
|
*/
|
|
220
247
|
async setAlbumImage(e) {
|
|
221
|
-
const t =
|
|
222
|
-
|
|
248
|
+
const t = new Image();
|
|
249
|
+
t.src = e, t.crossOrigin = "anonymous";
|
|
250
|
+
let i = 5, s;
|
|
251
|
+
for (; !s?.baseTexture?.resource?.valid && i > 0; )
|
|
252
|
+
try {
|
|
253
|
+
await t.decode(), s = I.from(t, {
|
|
254
|
+
resourceOptions: {
|
|
255
|
+
autoLoad: !1
|
|
256
|
+
}
|
|
257
|
+
}), await s.baseTexture.resource.load();
|
|
258
|
+
} catch (c) {
|
|
259
|
+
console.warn(
|
|
260
|
+
`failed on loading album image, retrying (${i})`,
|
|
261
|
+
e,
|
|
262
|
+
c
|
|
263
|
+
), s = void 0, i--;
|
|
264
|
+
}
|
|
265
|
+
if (!s)
|
|
266
|
+
return;
|
|
267
|
+
const r = new O(), n = new S(s), a = new S(s), l = new S(s), o = new S(s);
|
|
268
|
+
n.anchor.set(0.5, 0.5), a.anchor.set(0.5, 0.5), l.anchor.set(0.5, 0.5), o.anchor.set(0.5, 0.5), n.rotation = Math.random() * Math.PI * 2, a.rotation = Math.random() * Math.PI * 2, l.rotation = Math.random() * Math.PI * 2, o.rotation = Math.random() * Math.PI * 2, r.addChild(n, a, l, o), this.curContainer && this.lastContainer.add(this.curContainer), this.curContainer = r, this.app.stage.addChild(this.curContainer), this.curContainer.alpha = 0, this.app.ticker.start();
|
|
223
269
|
}
|
|
224
270
|
dispose() {
|
|
225
|
-
this.observer.disconnect(), this.app.ticker.remove(this.onTick);
|
|
271
|
+
this.observer.disconnect(), this.app.ticker.remove(this.onTick), this.app.destroy(!0);
|
|
226
272
|
}
|
|
227
273
|
}
|
|
228
|
-
class
|
|
274
|
+
class oe extends W {
|
|
229
275
|
element;
|
|
230
276
|
constructor() {
|
|
231
277
|
const e = document.createElement("canvas");
|
|
@@ -238,34 +284,35 @@ class te extends N {
|
|
|
238
284
|
super.dispose(), this.element.remove();
|
|
239
285
|
}
|
|
240
286
|
}
|
|
241
|
-
const
|
|
242
|
-
class
|
|
287
|
+
const N = (h, e) => h.size === e.size && [...h].every((t) => e.has(t));
|
|
288
|
+
class w {
|
|
243
289
|
currentPosition = 0;
|
|
244
290
|
targetPosition = 0;
|
|
245
291
|
currentTime = 0;
|
|
246
292
|
params = {};
|
|
247
293
|
currentSolver;
|
|
248
294
|
getV;
|
|
295
|
+
getV2;
|
|
249
296
|
queueParams;
|
|
250
297
|
queuePosition;
|
|
251
298
|
constructor(e = 0) {
|
|
252
|
-
this.targetPosition = e, this.currentPosition = this.targetPosition, this.currentSolver = () => this.targetPosition, this.getV = () => 0;
|
|
299
|
+
this.targetPosition = e, this.currentPosition = this.targetPosition, this.currentSolver = () => this.targetPosition, this.getV = () => 0, this.getV2 = () => 0;
|
|
253
300
|
}
|
|
254
301
|
resetSolver() {
|
|
255
302
|
const e = this.getV(this.currentTime);
|
|
256
|
-
this.currentTime = 0, this.currentSolver =
|
|
303
|
+
this.currentTime = 0, this.currentSolver = q(
|
|
257
304
|
this.currentPosition,
|
|
258
305
|
e,
|
|
259
306
|
this.targetPosition,
|
|
260
307
|
0,
|
|
261
308
|
this.params
|
|
262
|
-
), this.getV =
|
|
309
|
+
), this.getV = M(this.currentSolver), this.getV2 = M(this.getV);
|
|
263
310
|
}
|
|
264
311
|
arrived() {
|
|
265
|
-
return Math.abs(this.targetPosition - this.currentPosition) < 0.01 && this.getV(this.currentTime) < 0.01 && this.queueParams === void 0 && this.queuePosition === void 0;
|
|
312
|
+
return Math.abs(this.targetPosition - this.currentPosition) < 0.01 && this.getV(this.currentTime) < 0.01 && this.getV2(this.currentTime) < 0.01 && this.queueParams === void 0 && this.queuePosition === void 0;
|
|
266
313
|
}
|
|
267
314
|
setPosition(e) {
|
|
268
|
-
this.targetPosition = e, this.currentPosition = e, this.currentSolver = () => this.targetPosition, this.getV = () => 0;
|
|
315
|
+
this.targetPosition = e, this.currentPosition = e, this.currentSolver = () => this.targetPosition, this.getV = () => 0, this.getV2 = () => 0;
|
|
269
316
|
}
|
|
270
317
|
update(e = 0) {
|
|
271
318
|
this.currentTime += e, this.currentPosition = this.currentSolver(this.currentTime), this.queueParams && (this.queueParams.time -= e, this.queueParams.time <= 0 && this.updateParams({
|
|
@@ -274,15 +321,17 @@ class S {
|
|
|
274
321
|
}
|
|
275
322
|
updateParams(e, t = 0) {
|
|
276
323
|
t > 0 ? this.queueParams = {
|
|
324
|
+
...this.queuePosition ?? {},
|
|
277
325
|
...e,
|
|
278
326
|
time: t
|
|
279
|
-
} : (this.params = {
|
|
327
|
+
} : (this.queuePosition = void 0, this.params = {
|
|
280
328
|
...this.params,
|
|
281
329
|
...e
|
|
282
330
|
}, this.resetSolver());
|
|
283
331
|
}
|
|
284
332
|
setTargetPosition(e, t = 0) {
|
|
285
333
|
t > 0 ? this.queuePosition = {
|
|
334
|
+
...this.queuePosition ?? {},
|
|
286
335
|
position: e,
|
|
287
336
|
time: t
|
|
288
337
|
} : (this.queuePosition = void 0, this.targetPosition = e, this.resetSolver());
|
|
@@ -291,25 +340,25 @@ class S {
|
|
|
291
340
|
return this.currentPosition;
|
|
292
341
|
}
|
|
293
342
|
}
|
|
294
|
-
function
|
|
295
|
-
const
|
|
296
|
-
if (
|
|
297
|
-
const c = -Math.sqrt(
|
|
298
|
-
return (u) => (u -=
|
|
343
|
+
function q(h, e, t, i = 0, s) {
|
|
344
|
+
const r = s?.soft ?? !1, n = s?.stiffness ?? 100, a = s?.damping ?? 10, l = s?.mass ?? 1, o = t - h;
|
|
345
|
+
if (r || 1 <= a / (2 * Math.sqrt(n * l))) {
|
|
346
|
+
const c = -Math.sqrt(n / l), m = -c * o - e;
|
|
347
|
+
return (u) => (u -= i, u < 0 ? h : t - (o + u * m) * Math.E ** (u * c));
|
|
299
348
|
} else {
|
|
300
349
|
const c = Math.sqrt(
|
|
301
|
-
4 *
|
|
302
|
-
),
|
|
303
|
-
return (
|
|
350
|
+
4 * l * n - a ** 2
|
|
351
|
+
), m = (a * o - 2 * l * e) / c, u = 0.5 * c / l, f = -(0.5 * a) / l;
|
|
352
|
+
return (p) => (p -= i, p < 0 ? h : t - (Math.cos(p * u) * o + Math.sin(p * u) * m) * Math.E ** (p * f));
|
|
304
353
|
}
|
|
305
354
|
}
|
|
306
|
-
function
|
|
355
|
+
function F(h) {
|
|
307
356
|
return (t) => (h(t + 1e-3) - h(t - 1e-3)) / (2 * 1e-3);
|
|
308
357
|
}
|
|
309
|
-
function
|
|
310
|
-
return
|
|
358
|
+
function M(h) {
|
|
359
|
+
return F(h);
|
|
311
360
|
}
|
|
312
|
-
class
|
|
361
|
+
class R {
|
|
313
362
|
constructor(e) {
|
|
314
363
|
this.lyricPlayer = e, this.element.setAttribute(
|
|
315
364
|
"class",
|
|
@@ -323,8 +372,8 @@ class F {
|
|
|
323
372
|
// 由 LyricPlayer 来设置
|
|
324
373
|
lineSize = [0, 0];
|
|
325
374
|
lineTransforms = {
|
|
326
|
-
posX: new
|
|
327
|
-
posY: new
|
|
375
|
+
posX: new w(0),
|
|
376
|
+
posY: new w(0)
|
|
328
377
|
};
|
|
329
378
|
measureSize() {
|
|
330
379
|
return [
|
|
@@ -346,32 +395,32 @@ class F {
|
|
|
346
395
|
getElement() {
|
|
347
396
|
return this.element;
|
|
348
397
|
}
|
|
349
|
-
setTransform(e = this.left, t = this.top,
|
|
350
|
-
this.left = e, this.top = t, this.delay =
|
|
398
|
+
setTransform(e = this.left, t = this.top, i = !1, s = 0) {
|
|
399
|
+
this.left = e, this.top = t, this.delay = s * 1e3 | 0, i || !this.lyricPlayer.getEnableSpring() ? (i && this.element.classList.add(
|
|
351
400
|
this.lyricPlayer.style.classes.tmpDisableTransition
|
|
352
|
-
), this.lineTransforms.posX.setPosition(e), this.lineTransforms.posY.setPosition(t), this.lyricPlayer.getEnableSpring() ? this.rebuildStyle() : this.show(),
|
|
401
|
+
), this.lineTransforms.posX.setPosition(e), this.lineTransforms.posY.setPosition(t), this.lyricPlayer.getEnableSpring() ? this.rebuildStyle() : this.show(), i && requestAnimationFrame(() => {
|
|
353
402
|
this.element.classList.remove(
|
|
354
403
|
this.lyricPlayer.style.classes.tmpDisableTransition
|
|
355
404
|
);
|
|
356
|
-
})) : (this.lineTransforms.posX.setTargetPosition(e,
|
|
405
|
+
})) : (this.lineTransforms.posX.setTargetPosition(e, s), this.lineTransforms.posY.setTargetPosition(t, s));
|
|
357
406
|
}
|
|
358
407
|
update(e = 0) {
|
|
359
408
|
this.lyricPlayer.getEnableSpring() && (this.lineTransforms.posX.update(e), this.lineTransforms.posY.update(e), this.isInSight ? this.show() : this.hide());
|
|
360
409
|
}
|
|
361
410
|
get isInSight() {
|
|
362
|
-
const e = this.lineTransforms.posX.getCurrentPosition(), t = this.lineTransforms.posY.getCurrentPosition(),
|
|
363
|
-
return !(e > r || t >
|
|
411
|
+
const e = this.lineTransforms.posX.getCurrentPosition(), t = this.lineTransforms.posY.getCurrentPosition(), i = e + this.lineSize[0], s = t + this.lineSize[1], r = this.lyricPlayer.size[0], n = this.lyricPlayer.size[1];
|
|
412
|
+
return !(e > r || t > n || i < 0 || s < 0);
|
|
364
413
|
}
|
|
365
414
|
dispose() {
|
|
366
415
|
this.element.remove();
|
|
367
416
|
}
|
|
368
417
|
}
|
|
369
|
-
function
|
|
418
|
+
function _(h) {
|
|
370
419
|
const t = 2.5949095;
|
|
371
420
|
return h < 0.5 ? Math.pow(2 * h, 2) * ((t + 1) * 2 * h - t) / 2 : (Math.pow(2 * h - 2, 2) * ((t + 1) * (h * 2 - 2) + t) + 2) / 2;
|
|
372
421
|
}
|
|
373
|
-
const
|
|
374
|
-
class
|
|
422
|
+
const L = (h, e, t) => Math.max(h, Math.min(e, t));
|
|
423
|
+
class X {
|
|
375
424
|
constructor(e) {
|
|
376
425
|
this.lyricPlayer = e, this.element.className = this.lyricPlayer.style.classes.interludeDots, this.element.appendChild(this.dot0), this.element.appendChild(this.dot1), this.element.appendChild(this.dot2);
|
|
377
426
|
}
|
|
@@ -399,41 +448,41 @@ class R {
|
|
|
399
448
|
this.currentTime += e;
|
|
400
449
|
let t = "";
|
|
401
450
|
if (t += `transform:translate(${this.left}px, ${this.top}px)`, this.currentInterlude) {
|
|
402
|
-
const
|
|
403
|
-
if (
|
|
404
|
-
const
|
|
405
|
-
let
|
|
406
|
-
|
|
407
|
-
(750 - (
|
|
408
|
-
)),
|
|
451
|
+
const i = this.currentInterlude[1] - this.currentInterlude[0], s = this.currentTime - this.currentInterlude[0];
|
|
452
|
+
if (s <= i) {
|
|
453
|
+
const r = i / Math.ceil(i / this.targetBreatheDuration);
|
|
454
|
+
let n = 1, a = 1;
|
|
455
|
+
n *= Math.sin(1.5 * Math.PI - s / r * 2) / 10 + 1, s < 1e3 && (n *= 1 - Math.pow((1e3 - s) / 1e3, 2)), s < 500 ? a = 0 : s < 1e3 && (a *= (s - 500) / 500), i - s < 750 && (n *= 1 - _(
|
|
456
|
+
(750 - (i - s)) / 750 / 2
|
|
457
|
+
)), i - s < 375 && (a *= L(
|
|
409
458
|
0,
|
|
410
|
-
(
|
|
459
|
+
(i - s) / 375,
|
|
411
460
|
1
|
|
412
|
-
)),
|
|
413
|
-
const
|
|
461
|
+
)), n = Math.max(0, n), t += ` scale(${n})`;
|
|
462
|
+
const l = L(
|
|
414
463
|
0.25,
|
|
415
|
-
|
|
464
|
+
s * 3 / i * 0.75,
|
|
416
465
|
1
|
|
417
|
-
), o =
|
|
466
|
+
), o = L(
|
|
418
467
|
0.25,
|
|
419
|
-
(
|
|
468
|
+
(s - i / 3) * 3 / i * 0.75,
|
|
420
469
|
1
|
|
421
|
-
), c =
|
|
470
|
+
), c = L(
|
|
422
471
|
0.25,
|
|
423
|
-
(
|
|
472
|
+
(s - i / 3 * 2) * 3 / i * 0.75,
|
|
424
473
|
1
|
|
425
474
|
);
|
|
426
|
-
this.dot0.style.opacity = `${
|
|
475
|
+
this.dot0.style.opacity = `${L(
|
|
427
476
|
0,
|
|
428
|
-
Math.max(0,
|
|
477
|
+
Math.max(0, a * l),
|
|
429
478
|
1
|
|
430
|
-
)}`, this.dot1.style.opacity = `${
|
|
479
|
+
)}`, this.dot1.style.opacity = `${L(
|
|
431
480
|
0,
|
|
432
|
-
Math.max(0,
|
|
481
|
+
Math.max(0, a * o),
|
|
433
482
|
1
|
|
434
|
-
)}`, this.dot2.style.opacity = `${
|
|
483
|
+
)}`, this.dot2.style.opacity = `${L(
|
|
435
484
|
0,
|
|
436
|
-
Math.max(0,
|
|
485
|
+
Math.max(0, a * c),
|
|
437
486
|
1
|
|
438
487
|
)}`;
|
|
439
488
|
} else
|
|
@@ -446,19 +495,34 @@ class R {
|
|
|
446
495
|
this.element.remove();
|
|
447
496
|
}
|
|
448
497
|
}
|
|
449
|
-
const
|
|
450
|
-
function
|
|
451
|
-
const
|
|
498
|
+
const Y = /^[\p{Unified_Ideograph}\u0800-\u9FFC]+$/u;
|
|
499
|
+
function G(h, e = "rgba(0,0,0,1)", t = "rgba(0,0,0,0.5)") {
|
|
500
|
+
const i = 2 + h, s = h / i, r = (1 - s) / 2;
|
|
452
501
|
return [
|
|
453
|
-
`linear-gradient(to right,${e} ${
|
|
454
|
-
|
|
455
|
-
|
|
502
|
+
`linear-gradient(to right,${e} ${r * 100}%,${t} ${(r + s) * 100}%)`,
|
|
503
|
+
s,
|
|
504
|
+
i
|
|
456
505
|
];
|
|
457
506
|
}
|
|
507
|
+
function V(h, e) {
|
|
508
|
+
let t = [], i = [];
|
|
509
|
+
const s = [];
|
|
510
|
+
for (const r of h) {
|
|
511
|
+
const n = e(r);
|
|
512
|
+
t.push(n), i.push(r), n.length > 0 && n.trim().length === 0 ? (t.pop(), i.pop(), i.length === 1 ? s.push(i[0]) : i.length > 1 && s.push(i), s.push(r), t = [], i = []) : (!/^\s*[^\s]*\s*$/.test(t.join("")) || Y.test(n)) && (t.pop(), i.pop(), i.length === 1 ? s.push(i[0]) : i.length > 1 && s.push(i), t = [n], i = [r]);
|
|
513
|
+
}
|
|
514
|
+
return i.length === 1 ? s.push(i[0]) : s.push(i), s;
|
|
515
|
+
}
|
|
458
516
|
function x(h) {
|
|
459
517
|
return h.endTime - h.startTime >= 1e3 && h.word.length <= 7;
|
|
460
518
|
}
|
|
461
|
-
class
|
|
519
|
+
class H extends MouseEvent {
|
|
520
|
+
constructor(e, t) {
|
|
521
|
+
super(t.type, t), this.line = e;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
class j extends EventTarget {
|
|
525
|
+
// rome-ignore lint/correctness/noUnreachableSuper: <explanation>
|
|
462
526
|
constructor(e, t = {
|
|
463
527
|
words: [],
|
|
464
528
|
translatedLyric: "",
|
|
@@ -468,12 +532,12 @@ class Y {
|
|
|
468
532
|
isBG: !1,
|
|
469
533
|
isDuet: !1
|
|
470
534
|
}) {
|
|
471
|
-
this.lyricPlayer = e, this.lyricLine = t, this.element.setAttribute(
|
|
535
|
+
super(), this.lyricPlayer = e, this.lyricLine = t, this.element.setAttribute(
|
|
472
536
|
"class",
|
|
473
537
|
this.lyricPlayer.style.classes.lyricLine
|
|
474
538
|
), this.lyricLine.isBG && this.element.classList.add(this.lyricPlayer.style.classes.lyricBgLine), this.lyricLine.isDuet && this.element.classList.add(this.lyricPlayer.style.classes.lyricDuetLine), this.element.appendChild(document.createElement("div")), this.element.appendChild(document.createElement("div")), this.element.appendChild(document.createElement("div"));
|
|
475
|
-
const
|
|
476
|
-
|
|
539
|
+
const i = this.element.children[0], s = this.element.children[1], r = this.element.children[2];
|
|
540
|
+
i.setAttribute("class", this.lyricPlayer.style.classes.lyricMainLine), s.setAttribute("class", this.lyricPlayer.style.classes.lyricSubLine), r.setAttribute("class", this.lyricPlayer.style.classes.lyricSubLine), this.rebuildElement(), this.rebuildStyle();
|
|
477
541
|
}
|
|
478
542
|
element = document.createElement("div");
|
|
479
543
|
left = 0;
|
|
@@ -485,17 +549,34 @@ class Y {
|
|
|
485
549
|
// 由 LyricPlayer 来设置
|
|
486
550
|
lineSize = [0, 0];
|
|
487
551
|
lineTransforms = {
|
|
488
|
-
posX: new
|
|
489
|
-
posY: new
|
|
490
|
-
scale: new
|
|
552
|
+
posX: new w(0),
|
|
553
|
+
posY: new w(0),
|
|
554
|
+
scale: new w(1)
|
|
555
|
+
};
|
|
556
|
+
listenersMap = /* @__PURE__ */ new Map();
|
|
557
|
+
onMouseEvent = (e) => {
|
|
558
|
+
if (!this.dispatchEvent(new H(this, e)))
|
|
559
|
+
return e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation(), !1;
|
|
491
560
|
};
|
|
561
|
+
addEventListener(e, t, i) {
|
|
562
|
+
if (super.addEventListener(e, t, i), t) {
|
|
563
|
+
const s = this.listenersMap.get(e) ?? /* @__PURE__ */ new Set();
|
|
564
|
+
s.size === 0 && this.element.addEventListener(e, this.onMouseEvent), s.add(t), this.listenersMap.set(e, s);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
removeEventListener(e, t, i) {
|
|
568
|
+
if (super.removeEventListener(e, t, i), t) {
|
|
569
|
+
const s = this.listenersMap.get(e);
|
|
570
|
+
s && (s.delete(t), s.size === 0 && this.element.removeEventListener(e, this.onMouseEvent));
|
|
571
|
+
}
|
|
572
|
+
}
|
|
492
573
|
isEnabled = !1;
|
|
493
574
|
enable() {
|
|
494
575
|
this.isEnabled = !0, this.element.classList.add("active");
|
|
495
576
|
const e = this.element.children[0];
|
|
496
577
|
this.splittedWords.forEach((t) => {
|
|
497
|
-
t.elementAnimations.forEach((
|
|
498
|
-
|
|
578
|
+
t.elementAnimations.forEach((i) => {
|
|
579
|
+
i.currentTime = 0, i.playbackRate = 1, i.play();
|
|
499
580
|
});
|
|
500
581
|
}), e.classList.add("active");
|
|
501
582
|
}
|
|
@@ -511,8 +592,8 @@ class Y {
|
|
|
511
592
|
this.isEnabled = !1, this.element.classList.remove("active");
|
|
512
593
|
const e = this.element.children[0];
|
|
513
594
|
this.splittedWords.forEach((t) => {
|
|
514
|
-
t.elementAnimations.forEach((
|
|
515
|
-
|
|
595
|
+
t.elementAnimations.forEach((i) => {
|
|
596
|
+
i.id === "float-word" && (i.playbackRate = -1, i.play());
|
|
516
597
|
});
|
|
517
598
|
}), e.classList.remove("active");
|
|
518
599
|
}
|
|
@@ -544,84 +625,86 @@ class Y {
|
|
|
544
625
|
!this.lyricPlayer.getEnableSpring() && this.isInSight && (e += `transition-delay:${this.delay}ms;`), e += `filter:blur(${Math.min(32, this.blur)}px);`, e !== this.lastStyle && (this.lastStyle = e, this.element.setAttribute("style", e));
|
|
545
626
|
}
|
|
546
627
|
rebuildElement() {
|
|
547
|
-
const e = this.element.children[0], t = this.element.children[1],
|
|
628
|
+
const e = this.element.children[0], t = this.element.children[1], i = this.element.children[2];
|
|
548
629
|
if (this.lyricPlayer._getIsNonDynamic()) {
|
|
549
|
-
|
|
550
|
-
e.removeChild(e.firstChild), s(e.firstChild);
|
|
551
|
-
e.innerText = this.lyricLine.words.map((a) => a.word).join(""), t.innerText = this.lyricLine.translatedLyric, n.innerText = this.lyricLine.romanLyric;
|
|
630
|
+
e.innerText = this.lyricLine.words.map((r) => r.word).join(""), t.innerText = this.lyricLine.translatedLyric, i.innerText = this.lyricLine.romanLyric;
|
|
552
631
|
return;
|
|
553
632
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
word
|
|
560
|
-
startTime: 0,
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
633
|
+
const s = V(this.lyricLine.words, (r) => r.word);
|
|
634
|
+
e.innerHTML = "", this.splittedWords = [];
|
|
635
|
+
for (const r of s)
|
|
636
|
+
if (r instanceof Array) {
|
|
637
|
+
const n = r.map((o) => x(o)).reduce((o, c) => o || c, !1), a = r.reduce(
|
|
638
|
+
(o, c) => (o.endTime = Math.max(o.endTime, c.endTime), o.startTime = Math.min(o.startTime, c.startTime), o.word += c.word, o),
|
|
639
|
+
{ word: "", startTime: 1 / 0, endTime: -1 / 0 }
|
|
640
|
+
), l = document.createElement("span");
|
|
641
|
+
for (const o of r) {
|
|
642
|
+
const c = document.createElement("span"), m = this.initFloatAnimation(
|
|
643
|
+
a,
|
|
644
|
+
c
|
|
645
|
+
);
|
|
646
|
+
if (n) {
|
|
647
|
+
c.classList.add("emphasize");
|
|
648
|
+
const u = [];
|
|
649
|
+
for (const p of o.word.trim().split("")) {
|
|
650
|
+
const d = document.createElement("span");
|
|
651
|
+
d.innerText = p, u.push(d), c.appendChild(d);
|
|
652
|
+
}
|
|
653
|
+
const f = {
|
|
654
|
+
...o,
|
|
655
|
+
mainElement: c,
|
|
656
|
+
subElements: u,
|
|
657
|
+
elementAnimations: [m],
|
|
658
|
+
width: 0,
|
|
659
|
+
height: 0,
|
|
660
|
+
shouldEmphasize: n
|
|
661
|
+
};
|
|
662
|
+
f.elementAnimations.push(
|
|
663
|
+
...this.initEmphasizeAnimation(f)
|
|
664
|
+
), this.splittedWords.push(f);
|
|
665
|
+
} else
|
|
666
|
+
c.innerText = o.word, this.splittedWords.push({
|
|
667
|
+
...o,
|
|
668
|
+
mainElement: c,
|
|
669
|
+
subElements: [],
|
|
670
|
+
elementAnimations: [m],
|
|
671
|
+
width: 0,
|
|
672
|
+
height: 0,
|
|
673
|
+
shouldEmphasize: n
|
|
674
|
+
});
|
|
675
|
+
l.appendChild(c);
|
|
676
|
+
}
|
|
677
|
+
a.word.trimStart() !== a.word && e.appendChild(document.createTextNode(" ")), e.appendChild(l), a.word.trimEnd() !== a.word && e.appendChild(document.createTextNode(" "));
|
|
678
|
+
} else if (r.word.trim().length === 0)
|
|
679
|
+
e.appendChild(document.createTextNode(" "));
|
|
680
|
+
else {
|
|
681
|
+
const n = x(r), a = document.createElement("span"), l = {
|
|
682
|
+
...r,
|
|
683
|
+
mainElement: a,
|
|
684
|
+
subElements: [],
|
|
685
|
+
elementAnimations: [this.initFloatAnimation(r, a)],
|
|
571
686
|
width: 0,
|
|
572
687
|
height: 0,
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
for (; a.firstChild; )
|
|
582
|
-
a.firstChild.nodeType === Node.ELEMENT_NODE ? i.push(e.firstChild) : a.firstChild.nodeType === Node.TEXT_NODE && l.push(e.firstChild), a.removeChild(a.firstChild), s(a.firstChild);
|
|
583
|
-
}
|
|
584
|
-
s(e);
|
|
585
|
-
let r = null;
|
|
586
|
-
this.splittedWords.forEach((a) => {
|
|
587
|
-
if (a.word.trim().length > 0)
|
|
588
|
-
if (a.shouldEmphasize) {
|
|
589
|
-
const o = i.pop() ?? document.createElement("span");
|
|
590
|
-
o.className = "emphasize", a.elements = [o];
|
|
591
|
-
for (const c of a.word) {
|
|
592
|
-
const d = i.pop() ?? document.createElement("span");
|
|
593
|
-
d.className = "", d.innerText = c, o.appendChild(d), a.elements.push(d);
|
|
688
|
+
shouldEmphasize: n
|
|
689
|
+
};
|
|
690
|
+
if (n) {
|
|
691
|
+
a.classList.add("emphasize");
|
|
692
|
+
const o = [];
|
|
693
|
+
for (const c of r.word.trim().split("")) {
|
|
694
|
+
const m = document.createElement("span");
|
|
695
|
+
m.innerText = c, o.push(m), a.appendChild(m);
|
|
594
696
|
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
r = v.test(a.word) ? null : o, e.appendChild(o);
|
|
604
|
-
} else {
|
|
605
|
-
const o = i.pop() ?? document.createElement("span");
|
|
606
|
-
if (o.className = "", o.innerText = a.word, a.elements = [o], a.elementAnimations.push(this.initFloatAnimation(a, o)), r)
|
|
607
|
-
if (r.childElementCount > 0)
|
|
608
|
-
r.appendChild(o);
|
|
609
|
-
else {
|
|
610
|
-
const c = i.pop() ?? document.createElement("span");
|
|
611
|
-
c.className = "", r.remove(), c.appendChild(r), c.appendChild(o), e.appendChild(c), r = c;
|
|
612
|
-
}
|
|
613
|
-
else
|
|
614
|
-
r = o, e.appendChild(o);
|
|
615
|
-
}
|
|
616
|
-
else if (a.word.length > 0) {
|
|
617
|
-
const o = l.pop() ?? document.createTextNode(" ");
|
|
618
|
-
e.appendChild(o), r = null;
|
|
619
|
-
} else
|
|
620
|
-
r = null;
|
|
621
|
-
}), t.innerText = this.lyricLine.translatedLyric, n.innerText = this.lyricLine.romanLyric;
|
|
697
|
+
l.subElements = o, l.elementAnimations.push(
|
|
698
|
+
...this.initEmphasizeAnimation(l)
|
|
699
|
+
);
|
|
700
|
+
} else
|
|
701
|
+
a.innerText = r.word.trim();
|
|
702
|
+
r.word.trimStart() !== r.word && e.appendChild(document.createTextNode(" ")), e.appendChild(a), r.word.trimEnd() !== r.word && e.appendChild(document.createTextNode(" ")), this.splittedWords.push(l);
|
|
703
|
+
}
|
|
704
|
+
t.innerText = this.lyricLine.translatedLyric, i.innerText = this.lyricLine.romanLyric;
|
|
622
705
|
}
|
|
623
706
|
initFloatAnimation(e, t) {
|
|
624
|
-
const
|
|
707
|
+
const i = e.startTime - this.lyricLine.startTime, s = Math.max(1e3, e.endTime - e.startTime), r = t.animate(
|
|
625
708
|
[
|
|
626
709
|
{
|
|
627
710
|
transform: "translateY(0px)"
|
|
@@ -631,101 +714,117 @@ class Y {
|
|
|
631
714
|
}
|
|
632
715
|
],
|
|
633
716
|
{
|
|
634
|
-
duration: isFinite(
|
|
635
|
-
delay: isFinite(
|
|
717
|
+
duration: isFinite(s) ? s : 0,
|
|
718
|
+
delay: isFinite(i) ? i : 0,
|
|
636
719
|
id: "float-word",
|
|
637
720
|
composite: "add",
|
|
638
721
|
fill: "both"
|
|
639
722
|
}
|
|
640
723
|
);
|
|
641
|
-
return
|
|
724
|
+
return r.pause(), r;
|
|
642
725
|
}
|
|
643
726
|
initEmphasizeAnimation(e) {
|
|
644
|
-
const t = e.startTime - this.lyricLine.startTime,
|
|
645
|
-
return e.
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
transform: "translate3d(0, -2%, 20px)",
|
|
659
|
-
filter: "drop-shadow(0 0 0.05em var(--amll-lyric-view-color,white))"
|
|
660
|
-
},
|
|
661
|
-
{
|
|
662
|
-
offset: 1,
|
|
663
|
-
transform: "translate3d(0, 0px, 0)",
|
|
664
|
-
filter: "drop-shadow(0 0 0 var(--amll-lyric-view-color,white))"
|
|
665
|
-
}
|
|
666
|
-
],
|
|
727
|
+
const t = e.startTime - this.lyricLine.startTime, i = e.endTime - e.startTime;
|
|
728
|
+
return e.subElements.map((s, r, n) => {
|
|
729
|
+
const a = Math.max(1e3, e.endTime - e.startTime), l = t + i / n.length * r, o = s.animate(
|
|
730
|
+
[
|
|
731
|
+
{
|
|
732
|
+
offset: 0,
|
|
733
|
+
transform: "translate3d(0, 0, 0px)",
|
|
734
|
+
filter: "drop-shadow(0 0 0 var(--amll-lyric-view-color,white))"
|
|
735
|
+
},
|
|
736
|
+
{
|
|
737
|
+
offset: 0.5,
|
|
738
|
+
transform: "translate3d(0, -0.02em, 20px)",
|
|
739
|
+
filter: "drop-shadow(0 0 0.05em var(--amll-lyric-view-color,white))"
|
|
740
|
+
},
|
|
667
741
|
{
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
iterations: 1,
|
|
672
|
-
composite: "replace",
|
|
673
|
-
fill: "both"
|
|
742
|
+
offset: 1,
|
|
743
|
+
transform: "translate3d(0, 0, 0)",
|
|
744
|
+
filter: "drop-shadow(0 0 0 var(--amll-lyric-view-color,white))"
|
|
674
745
|
}
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
746
|
+
],
|
|
747
|
+
{
|
|
748
|
+
duration: isFinite(a) ? a : 0,
|
|
749
|
+
delay: isFinite(l) ? l : 0,
|
|
750
|
+
id: "glow-word",
|
|
751
|
+
iterations: 1,
|
|
752
|
+
composite: "replace",
|
|
753
|
+
easing: "ease-in-out",
|
|
754
|
+
fill: "both"
|
|
755
|
+
}
|
|
756
|
+
);
|
|
757
|
+
return o.pause(), o;
|
|
678
758
|
});
|
|
679
759
|
}
|
|
680
760
|
updateMaskImage() {
|
|
681
761
|
this._hide && (this.element.style.display = "", this.element.style.visibility = "hidden"), this.splittedWords.forEach((e) => {
|
|
682
|
-
const t = e.
|
|
762
|
+
const t = e.mainElement;
|
|
683
763
|
if (t) {
|
|
684
764
|
e.width = t.clientWidth, e.height = t.clientHeight;
|
|
685
|
-
const [
|
|
686
|
-
|
|
687
|
-
"rgba(0,0,0,
|
|
765
|
+
const i = e.height / 2, [s, r, n] = G(
|
|
766
|
+
i / e.width,
|
|
767
|
+
"rgba(0,0,0,1)",
|
|
688
768
|
"rgba(0,0,0,0.25)"
|
|
689
|
-
),
|
|
690
|
-
this.lyricPlayer.supportMaskImage ? (t.style.maskImage =
|
|
691
|
-
const
|
|
692
|
-
t.style.maskPosition =
|
|
769
|
+
), a = `${n * 100}% 100%`;
|
|
770
|
+
this.lyricPlayer.supportMaskImage ? (t.style.maskImage = s, t.style.maskOrigin = "left", t.style.maskSize = a) : (t.style.webkitMaskImage = s, t.style.webkitMaskOrigin = "left", t.style.webkitMaskSize = a);
|
|
771
|
+
const l = e.width + i, o = `clamp(${-l}px,calc(${-l}px + (var(--amll-player-time) - ${e.startTime})*${l / Math.abs(e.endTime - e.startTime)}px),0px) 0px, left top`;
|
|
772
|
+
t.style.maskPosition = o, t.style.webkitMaskPosition = o;
|
|
693
773
|
}
|
|
694
774
|
}), this._hide && (this.element.style.display = "none", this.element.style.visibility = "");
|
|
695
775
|
}
|
|
696
776
|
getElement() {
|
|
697
777
|
return this.element;
|
|
698
778
|
}
|
|
699
|
-
setTransform(e = this.left, t = this.top,
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
this.element.classList.remove(
|
|
779
|
+
setTransform(e = this.left, t = this.top, i = this.scale, s = 1, r = 0, n = !1, a = 0) {
|
|
780
|
+
const l = this.isInSight, o = this.lyricPlayer.getEnableSpring();
|
|
781
|
+
this.left = e, this.top = t, this.scale = i, this.delay = a * 1e3 | 0;
|
|
782
|
+
const c = this.element.children[0], m = this.element.children[1], u = this.element.children[2];
|
|
783
|
+
if (c.style.opacity = `${s}`, m.style.opacity = `${s / 2}`, u.style.opacity = `${s / 2}`, n || !o) {
|
|
784
|
+
if (this.blur = Math.min(32, r), n && this.element.classList.add(
|
|
706
785
|
this.lyricPlayer.style.classes.tmpDisableTransition
|
|
707
|
-
)
|
|
708
|
-
|
|
786
|
+
), this.lineTransforms.posX.setPosition(e), this.lineTransforms.posY.setPosition(t), this.lineTransforms.scale.setPosition(i), o)
|
|
787
|
+
this.rebuildStyle();
|
|
788
|
+
else {
|
|
789
|
+
const f = this.isInSight;
|
|
790
|
+
l || f ? this.show() : this.hide();
|
|
791
|
+
}
|
|
792
|
+
n && requestAnimationFrame(() => {
|
|
793
|
+
this.element.classList.remove(
|
|
794
|
+
this.lyricPlayer.style.classes.tmpDisableTransition
|
|
795
|
+
);
|
|
796
|
+
});
|
|
797
|
+
} else
|
|
798
|
+
this.lineTransforms.posX.setTargetPosition(e, a), this.lineTransforms.posY.setTargetPosition(t, a), this.lineTransforms.scale.setTargetPosition(i), this.blur !== Math.min(32, r) && (this.blur = Math.min(32, r), this.element.style.filter = `blur(${Math.min(32, r)}px)`);
|
|
709
799
|
}
|
|
710
800
|
update(e = 0) {
|
|
711
801
|
this.lyricPlayer.getEnableSpring() && (this.lineTransforms.posX.update(e), this.lineTransforms.posY.update(e), this.lineTransforms.scale.update(e), this.isInSight ? this.show() : this.hide());
|
|
712
802
|
}
|
|
803
|
+
_getDebugTargetPos() {
|
|
804
|
+
return `[位移: ${this.left}, ${this.top}; 缩放: ${this.scale}; 延时: ${this.delay}]`;
|
|
805
|
+
}
|
|
713
806
|
get isInSight() {
|
|
714
|
-
const e = this.lineTransforms.posX.getCurrentPosition(), t = this.lineTransforms.posY.getCurrentPosition(),
|
|
715
|
-
return !(e > r ||
|
|
807
|
+
const e = this.lineTransforms.posX.getCurrentPosition(), t = this.lineTransforms.posY.getCurrentPosition(), i = e + this.lineSize[0], s = t + this.lineSize[1], r = this.lyricPlayer.size[0], n = this.lyricPlayer.size[1];
|
|
808
|
+
return !(e > r || i < 0 || t > n || s < 0);
|
|
716
809
|
}
|
|
717
810
|
dispose() {
|
|
718
811
|
this.element.remove();
|
|
719
812
|
}
|
|
720
813
|
}
|
|
721
|
-
const
|
|
722
|
-
class
|
|
814
|
+
const U = D(k());
|
|
815
|
+
class J extends MouseEvent {
|
|
816
|
+
constructor(e, t, i) {
|
|
817
|
+
super(`line-${i.type}`, i), this.lineIndex = e, this.line = t;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
class le extends EventTarget {
|
|
723
821
|
element = document.createElement("div");
|
|
724
822
|
currentTime = 0;
|
|
725
823
|
lyricLines = [];
|
|
726
824
|
processedLines = [];
|
|
727
825
|
lyricLinesEl = [];
|
|
728
|
-
lyricLinesSize = /* @__PURE__ */ new
|
|
826
|
+
lyricLinesSize = /* @__PURE__ */ new WeakMap();
|
|
827
|
+
lyricLinesIndexes = /* @__PURE__ */ new WeakMap();
|
|
729
828
|
hotLines = /* @__PURE__ */ new Set();
|
|
730
829
|
bufferedLines = /* @__PURE__ */ new Set();
|
|
731
830
|
scrollToIndex = 0;
|
|
@@ -734,11 +833,12 @@ class ie extends EventTarget {
|
|
|
734
833
|
isScrolled = !1;
|
|
735
834
|
invokedByScrollEvent = !1;
|
|
736
835
|
scrollOffset = 0;
|
|
836
|
+
hidePassedLines = !1;
|
|
737
837
|
resizeObserver = new ResizeObserver((e) => {
|
|
738
838
|
const t = e[0].contentRect;
|
|
739
|
-
this.size[0] = t.width, this.size[1] = t.height
|
|
740
|
-
const
|
|
741
|
-
this.innerSize[0] =
|
|
839
|
+
this.size[0] = t.width, this.size[1] = t.height;
|
|
840
|
+
const i = getComputedStyle(e[0].target), s = this.element.clientWidth - parseFloat(i.paddingLeft) - parseFloat(i.paddingRight), r = this.element.clientHeight - parseFloat(i.paddingTop) - parseFloat(i.paddingBottom);
|
|
841
|
+
this.innerSize[0] = s, this.innerSize[1] = r, this.rebuildStyle(), this.calcLayout(!0, !0), this.lyricLinesEl.forEach((n) => n.updateMaskImage());
|
|
742
842
|
});
|
|
743
843
|
posXSpringParams = {
|
|
744
844
|
mass: 1,
|
|
@@ -755,7 +855,10 @@ class ie extends EventTarget {
|
|
|
755
855
|
damping: 20,
|
|
756
856
|
stiffness: 100
|
|
757
857
|
};
|
|
858
|
+
emUnit = Math.max(Math.min(innerHeight * 0.05, innerWidth * 0.1), 12);
|
|
859
|
+
padding = this.emUnit;
|
|
758
860
|
enableBlur = !0;
|
|
861
|
+
enableScale = !0;
|
|
759
862
|
interludeDots;
|
|
760
863
|
interludeDotsSize = [0, 0];
|
|
761
864
|
bottomLine;
|
|
@@ -767,7 +870,14 @@ class ie extends EventTarget {
|
|
|
767
870
|
isNonDynamic = !1;
|
|
768
871
|
size = [0, 0];
|
|
769
872
|
innerSize = [0, 0];
|
|
770
|
-
|
|
873
|
+
onLineClickedHandler = (e) => {
|
|
874
|
+
const t = new J(
|
|
875
|
+
this.lyricLinesIndexes.get(e.line) ?? -1,
|
|
876
|
+
e.line,
|
|
877
|
+
e
|
|
878
|
+
);
|
|
879
|
+
this.dispatchEvent(t) || (e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation());
|
|
880
|
+
};
|
|
771
881
|
_getIsNonDynamic() {
|
|
772
882
|
return this.isNonDynamic;
|
|
773
883
|
}
|
|
@@ -788,10 +898,28 @@ class ie extends EventTarget {
|
|
|
788
898
|
getEnableSpring() {
|
|
789
899
|
return !this.disableSpring;
|
|
790
900
|
}
|
|
791
|
-
|
|
901
|
+
/**
|
|
902
|
+
* 是否启用歌词行缩放效果,默认启用
|
|
903
|
+
*
|
|
904
|
+
* 如果启用,非选中的歌词行会轻微缩小以凸显当前播放歌词行效果
|
|
905
|
+
*
|
|
906
|
+
* 此效果对性能影响微乎其微,推荐启用
|
|
907
|
+
* @param enable 是否启用歌词行缩放效果
|
|
908
|
+
*/
|
|
909
|
+
setEnableScale(e = !0) {
|
|
910
|
+
this.enableScale = e, this.calcLayout();
|
|
911
|
+
}
|
|
912
|
+
/**
|
|
913
|
+
* 获取当前是否启用了歌词行缩放效果
|
|
914
|
+
* @returns 是否启用歌词行缩放效果
|
|
915
|
+
*/
|
|
916
|
+
getEnableScale() {
|
|
917
|
+
return this.enableScale;
|
|
918
|
+
}
|
|
919
|
+
style = U.createStyleSheet({
|
|
792
920
|
lyricPlayer: {
|
|
793
921
|
userSelect: "none",
|
|
794
|
-
fontSize: "var(--amll-lyric-player-font-size,max(5vh, 12px))",
|
|
922
|
+
fontSize: "var(--amll-lyric-player-font-size,max(min(5vh, 10vw), 12px))",
|
|
795
923
|
padding: "1em",
|
|
796
924
|
margin: "-1em",
|
|
797
925
|
width: "100%",
|
|
@@ -802,7 +930,12 @@ class ie extends EventTarget {
|
|
|
802
930
|
zIndex: 1,
|
|
803
931
|
color: "var(--amll-lyric-view-color,white)",
|
|
804
932
|
mixBlendMode: "plus-lighter",
|
|
805
|
-
contain: "strict"
|
|
933
|
+
contain: "strict",
|
|
934
|
+
"&:hover": {
|
|
935
|
+
"& $lyricLine": {
|
|
936
|
+
filter: "unset !important"
|
|
937
|
+
}
|
|
938
|
+
}
|
|
806
939
|
},
|
|
807
940
|
lyricLine: {
|
|
808
941
|
position: "absolute",
|
|
@@ -810,15 +943,24 @@ class ie extends EventTarget {
|
|
|
810
943
|
maxWidth: "var(--amll-lyric-player-width,100%)",
|
|
811
944
|
minWidth: "var(--amll-lyric-player-width,100%)",
|
|
812
945
|
width: "var(--amll-lyric-player-width,100%)",
|
|
813
|
-
padding: "2vh
|
|
946
|
+
padding: "2vh 1.05em",
|
|
947
|
+
margin: "0 -1em",
|
|
814
948
|
contain: "content",
|
|
815
949
|
willChange: "filter,transform,opacity",
|
|
816
|
-
transition: "filter 0.25s",
|
|
817
|
-
boxSizing: "
|
|
950
|
+
transition: "filter 0.25s, background-color 0.25s, box-shadow 0.25s",
|
|
951
|
+
boxSizing: "content-box",
|
|
952
|
+
borderRadius: "8px",
|
|
953
|
+
"&:hover": {
|
|
954
|
+
backgroundColor: "var(--amll-lyric-view-hover-bg-color,#fff1)",
|
|
955
|
+
boxShadow: "0 0 0 8px var(--amll-lyric-view-hover-bg-color,#fff1)"
|
|
956
|
+
},
|
|
957
|
+
"&:active": {
|
|
958
|
+
boxShadow: "0 0 0 4px var(--amll-lyric-view-hover-bg-color,#fff1)"
|
|
959
|
+
}
|
|
818
960
|
},
|
|
819
961
|
"@media (max-width: 1024px)": {
|
|
820
962
|
lyricLine: {
|
|
821
|
-
padding: "1vh
|
|
963
|
+
padding: "1vh 1em"
|
|
822
964
|
}
|
|
823
965
|
},
|
|
824
966
|
lyricDuetLine: {
|
|
@@ -844,7 +986,6 @@ class ie extends EventTarget {
|
|
|
844
986
|
},
|
|
845
987
|
"& > span": {
|
|
846
988
|
whiteSpace: "pre-wrap",
|
|
847
|
-
wordBreak: "keep-all",
|
|
848
989
|
maxLines: "1",
|
|
849
990
|
// willChange: "transform,display,mask-image",
|
|
850
991
|
"&.emphasize": {
|
|
@@ -856,12 +997,13 @@ class ie extends EventTarget {
|
|
|
856
997
|
}
|
|
857
998
|
},
|
|
858
999
|
lyricSubLine: {
|
|
859
|
-
fontSize: "max(
|
|
1000
|
+
fontSize: "max(0.5em, 10px)",
|
|
1001
|
+
transition: "opacity 0.3s 0.25s",
|
|
860
1002
|
opacity: 0.5
|
|
861
1003
|
},
|
|
862
1004
|
disableSpring: {
|
|
863
1005
|
"& > *": {
|
|
864
|
-
transition: "filter 0.25s, transform 0.5s"
|
|
1006
|
+
transition: "filter 0.25s, transform 0.5s, background-color 0.25s, box-shadow 0.25s"
|
|
865
1007
|
}
|
|
866
1008
|
},
|
|
867
1009
|
interludeDots: {
|
|
@@ -874,7 +1016,7 @@ class ie extends EventTarget {
|
|
|
874
1016
|
gap: "0.25em",
|
|
875
1017
|
left: "1em",
|
|
876
1018
|
"& > *": {
|
|
877
|
-
height: "
|
|
1019
|
+
height: "clamp(0.5em,1vh,3em)",
|
|
878
1020
|
display: "inline-block",
|
|
879
1021
|
borderRadius: "50%",
|
|
880
1022
|
aspectRatio: "1 / 1",
|
|
@@ -899,7 +1041,7 @@ class ie extends EventTarget {
|
|
|
899
1041
|
this.calcLayout(!0, !0);
|
|
900
1042
|
};
|
|
901
1043
|
constructor() {
|
|
902
|
-
super(), this.interludeDots = new
|
|
1044
|
+
super(), this.interludeDots = new X(this), this.bottomLine = new R(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.element.appendChild(this.bottomLine.getElement()), this.style.attach(), this.interludeDots.setTransform(0, 200), window.addEventListener("pageshow", this.onPageShow), this.element.addEventListener("wheel", (e) => {
|
|
903
1045
|
this.allowScroll && (this.isScrolled = !0, clearTimeout(this.scrolledHandler), this.scrolledHandler = setTimeout(() => {
|
|
904
1046
|
this.isScrolled = !1, this.scrollOffset = 0;
|
|
905
1047
|
}, 5e3), this.invokedByScrollEvent = !0, e.deltaMode === e.DOM_DELTA_PIXEL ? (this.scrollOffset += e.deltaY, this.calcLayout(!0)) : (this.scrollOffset += e.deltaY * 50, this.calcLayout(!1)), this.invokedByScrollEvent = !1);
|
|
@@ -940,7 +1082,14 @@ class ie extends EventTarget {
|
|
|
940
1082
|
*/
|
|
941
1083
|
rebuildStyle() {
|
|
942
1084
|
let e = "";
|
|
943
|
-
e += "--amll-lyric-player-width:", e += this.innerSize[0], e += "px;", e += "--amll-lyric-player-height:", e += this.innerSize[1], e += "px;", e += "--amll-player-time:", e += this.currentTime, e += ";", this.element.setAttribute("style", e);
|
|
1085
|
+
e += "--amll-lyric-player-width:", e += this.innerSize[0] - this.padding * 2, e += "px;", e += "--amll-lyric-player-height:", e += this.innerSize[1] - this.padding * 2, e += "px;", e += "--amll-player-time:", e += this.currentTime, e += ";", this.element.setAttribute("style", e);
|
|
1086
|
+
}
|
|
1087
|
+
/**
|
|
1088
|
+
* 设置是否隐藏已经播放过的歌词行,默认不隐藏
|
|
1089
|
+
* @param hide 是否隐藏已经播放过的歌词行,默认不隐藏
|
|
1090
|
+
*/
|
|
1091
|
+
setHidePassedLines(e) {
|
|
1092
|
+
this.hidePassedLines = e, this.calcLayout();
|
|
944
1093
|
}
|
|
945
1094
|
/**
|
|
946
1095
|
* 设置是否启用歌词行的模糊效果
|
|
@@ -957,24 +1106,29 @@ class ie extends EventTarget {
|
|
|
957
1106
|
this.lyricLines = e;
|
|
958
1107
|
const t = 750;
|
|
959
1108
|
this.processedLines = e.filter(
|
|
960
|
-
(i) => i.words.reduce((
|
|
961
|
-
).map((i,
|
|
1109
|
+
(i) => i.words.reduce((s, r) => s + r.word.trim().length, 0) > 0
|
|
1110
|
+
).map((i, s, r) => {
|
|
962
1111
|
if (i.isBG)
|
|
963
1112
|
return {
|
|
964
1113
|
...i
|
|
965
1114
|
};
|
|
1115
|
+
if (s === 0)
|
|
1116
|
+
return {
|
|
1117
|
+
...i,
|
|
1118
|
+
startTime: Math.max(i.startTime - t, 0)
|
|
1119
|
+
};
|
|
966
1120
|
{
|
|
967
|
-
const
|
|
968
|
-
if (
|
|
1121
|
+
const n = r[s - 1], a = r[s - 2];
|
|
1122
|
+
if (n?.isBG && a) {
|
|
969
1123
|
if (a.endTime < i.startTime)
|
|
970
1124
|
return {
|
|
971
1125
|
...i,
|
|
972
1126
|
startTime: Math.max(a.endTime, i.startTime - t) || i.startTime
|
|
973
1127
|
};
|
|
974
|
-
} else if (
|
|
1128
|
+
} else if (n?.endTime && n.endTime < i.startTime)
|
|
975
1129
|
return {
|
|
976
1130
|
...i,
|
|
977
|
-
startTime: Math.max(
|
|
1131
|
+
startTime: Math.max(n?.endTime, i.startTime - t) || i.startTime
|
|
978
1132
|
};
|
|
979
1133
|
return {
|
|
980
1134
|
...i
|
|
@@ -986,22 +1140,31 @@ class ie extends EventTarget {
|
|
|
986
1140
|
this.isNonDynamic = !1;
|
|
987
1141
|
break;
|
|
988
1142
|
}
|
|
989
|
-
this.processedLines.forEach((i,
|
|
990
|
-
const
|
|
991
|
-
a && x(a) && (
|
|
992
|
-
}), this.processedLines.forEach((i,
|
|
1143
|
+
this.processedLines.forEach((i, s, r) => {
|
|
1144
|
+
const n = r[s + 1], a = i.words[i.words.length - 1];
|
|
1145
|
+
a && x(a) && (n ? n.startTime > i.endTime && (i.endTime = Math.min(i.endTime + 1500, n.startTime)) : i.endTime = i.endTime + 1500);
|
|
1146
|
+
}), this.processedLines.forEach((i, s, r) => {
|
|
993
1147
|
if (i.isBG)
|
|
994
1148
|
return;
|
|
995
|
-
const
|
|
996
|
-
|
|
997
|
-
})
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1149
|
+
const n = r[s + 1];
|
|
1150
|
+
n?.isBG && (n.startTime = Math.min(n.startTime, i.startTime));
|
|
1151
|
+
}), this.lyricLinesEl.forEach((i) => {
|
|
1152
|
+
i.removeEventListener("click", this.onLineClickedHandler), i.removeEventListener("contextmenu", this.onLineClickedHandler), i.dispose();
|
|
1153
|
+
}), this.lyricLinesEl = this.processedLines.map((i) => {
|
|
1154
|
+
const s = new j(this, i);
|
|
1155
|
+
return s.addEventListener("click", this.onLineClickedHandler), s.addEventListener("contextmenu", this.onLineClickedHandler), s;
|
|
1156
|
+
}), this.lyricLinesEl.forEach((i, s) => {
|
|
1157
|
+
this.element.appendChild(i.getElement()), this.lyricLinesIndexes.set(i, s), i.updateMaskImage();
|
|
1003
1158
|
}), this.interludeDots.setInterlude(void 0), this.hotLines.clear(), this.bufferedLines.clear(), this.setLinePosXSpringParams({}), this.setLinePosYSpringParams({}), this.setLineScaleSpringParams({}), this.setCurrentTime(0, !0), this.calcLayout(!0, !0);
|
|
1004
1159
|
}
|
|
1160
|
+
/**
|
|
1161
|
+
* 重置用户滚动状态
|
|
1162
|
+
*
|
|
1163
|
+
* 请在用户完成滚动点击跳转歌词时调用本事件再调用 `calcLayout` 以正确滚动到目标位置
|
|
1164
|
+
*/
|
|
1165
|
+
resetScroll() {
|
|
1166
|
+
this.isScrolled = !1, this.scrollOffset = 0, this.invokedByScrollEvent = !1, clearTimeout(this.scrolledHandler), this.scrolledHandler = 0;
|
|
1167
|
+
}
|
|
1005
1168
|
/**
|
|
1006
1169
|
* 重新布局定位歌词行的位置,调用完成后再逐帧调用 `update`
|
|
1007
1170
|
* 函数即可让歌词通过动画移动到目标位置。
|
|
@@ -1020,44 +1183,46 @@ class ie extends EventTarget {
|
|
|
1020
1183
|
* @param reflow 是否进行重新布局(重新计算每行歌词大小)
|
|
1021
1184
|
*/
|
|
1022
1185
|
calcLayout(e = !1, t = !1) {
|
|
1023
|
-
t && (this.lyricLinesEl.forEach((
|
|
1024
|
-
const
|
|
1025
|
-
this.lyricLinesSize.set(
|
|
1186
|
+
t && (this.emUnit = parseFloat(getComputedStyle(this.element).fontSize), this.lyricLinesEl.forEach((p) => {
|
|
1187
|
+
const d = p.measureSize();
|
|
1188
|
+
this.lyricLinesSize.set(p, d), p.lineSize = d;
|
|
1026
1189
|
}), this.interludeDotsSize[0] = this.interludeDots.getElement().clientWidth, this.interludeDotsSize[1] = this.interludeDots.getElement().clientHeight, this.bottomLine.lineSize = this.bottomLine.measureSize());
|
|
1027
|
-
const
|
|
1028
|
-
let
|
|
1029
|
-
|
|
1030
|
-
const
|
|
1031
|
-
(
|
|
1190
|
+
const i = this.getCurrentInterlude();
|
|
1191
|
+
let s = -this.scrollOffset, r = this.scrollToIndex, n = 0;
|
|
1192
|
+
i ? (n = i[1] - i[0], n >= 5e3 && this.lyricLinesEl[i[2] + 1] && (r = i[2] + 1)) : this.interludeDots.setInterlude(void 0);
|
|
1193
|
+
const a = this.enableScale ? 0.95 : 1, l = this.lyricLinesEl.slice(0, r).reduce(
|
|
1194
|
+
(p, d) => p + (d.getLine().isBG ? 0 : this.lyricLinesSize.get(d)?.[1] ?? 0),
|
|
1032
1195
|
0
|
|
1033
1196
|
);
|
|
1034
|
-
|
|
1035
|
-
const o = this.lyricLinesEl[
|
|
1197
|
+
s -= l, s += this.size[1] * this.alignPosition;
|
|
1198
|
+
const o = this.lyricLinesEl[r];
|
|
1036
1199
|
if (o) {
|
|
1037
|
-
const
|
|
1200
|
+
const p = this.lyricLinesSize.get(o)?.[1] ?? 0;
|
|
1038
1201
|
switch (this.alignAnchor) {
|
|
1039
1202
|
case "bottom":
|
|
1040
|
-
|
|
1203
|
+
s -= p;
|
|
1041
1204
|
break;
|
|
1042
1205
|
case "center":
|
|
1043
|
-
|
|
1206
|
+
s -= p / 2;
|
|
1044
1207
|
break;
|
|
1045
1208
|
}
|
|
1046
1209
|
}
|
|
1047
1210
|
const c = Math.max(...this.bufferedLines);
|
|
1048
|
-
let
|
|
1049
|
-
this.lyricLinesEl.forEach((
|
|
1050
|
-
const
|
|
1051
|
-
P.isDuet && this.size[0] - (this.lyricLinesSize.get(
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1211
|
+
let m = 0, u = 0.05, f = !1;
|
|
1212
|
+
this.lyricLinesEl.forEach((p, d) => {
|
|
1213
|
+
const g = this.bufferedLines.has(d), b = g || d >= this.scrollToIndex && d < c, P = p.getLine();
|
|
1214
|
+
P.isDuet && this.size[0] - (this.lyricLinesSize.get(p)?.[0] ?? 0), !f && n >= 5e3 && (d === this.scrollToIndex && i?.[2] === -2 || d === this.scrollToIndex + 1) && (f = !0, this.interludeDots.setTransform(this.padding, s), i && this.interludeDots.setInterlude([i[0], i[1]]), s += this.interludeDotsSize[1]);
|
|
1215
|
+
const C = this.hidePassedLines && d < (i ? i[2] + 1 : this.scrollToIndex) ? 0 : g ? 1 : 1 / 3;
|
|
1216
|
+
p.setTransform(
|
|
1217
|
+
this.padding,
|
|
1218
|
+
s,
|
|
1219
|
+
b ? 1 : a,
|
|
1220
|
+
C,
|
|
1221
|
+
!this.invokedByScrollEvent && this.enableBlur ? b ? 0 : 1 + (d < this.scrollToIndex ? Math.abs(this.scrollToIndex - d) : Math.abs(d - Math.max(this.scrollToIndex, c))) : 0,
|
|
1057
1222
|
e,
|
|
1058
|
-
|
|
1059
|
-
), P.isBG && b ?
|
|
1060
|
-
}), this.bottomLine.setTransform(
|
|
1223
|
+
m
|
|
1224
|
+
), P.isBG && b ? s += this.lyricLinesSize.get(p)?.[1] ?? 0 : P.isBG || (s += this.lyricLinesSize.get(p)?.[1] ?? 0), s >= 0 && (m += u, u /= 1.2);
|
|
1225
|
+
}), this.bottomLine.setTransform(this.padding, s, e, m);
|
|
1061
1226
|
}
|
|
1062
1227
|
/**
|
|
1063
1228
|
* 获取当前歌词的播放位置
|
|
@@ -1120,35 +1285,35 @@ class ie extends EventTarget {
|
|
|
1120
1285
|
setCurrentTime(e, t = !1) {
|
|
1121
1286
|
if (this.currentTime = e, this.element.style.setProperty("--amll-player-time", `${e}`), this.isScrolled)
|
|
1122
1287
|
return;
|
|
1123
|
-
const
|
|
1124
|
-
this.hotLines.forEach((
|
|
1125
|
-
const
|
|
1126
|
-
if (
|
|
1127
|
-
if (
|
|
1288
|
+
const i = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set();
|
|
1289
|
+
this.hotLines.forEach((n) => {
|
|
1290
|
+
const a = this.processedLines[n];
|
|
1291
|
+
if (a) {
|
|
1292
|
+
if (a.isBG)
|
|
1128
1293
|
return;
|
|
1129
|
-
const
|
|
1130
|
-
if (
|
|
1131
|
-
const o = Math.min(
|
|
1132
|
-
(o > e || c <= e) && (this.hotLines.delete(
|
|
1294
|
+
const l = this.processedLines[n + 1];
|
|
1295
|
+
if (l?.isBG) {
|
|
1296
|
+
const o = Math.min(a.startTime, l?.startTime), c = Math.max(a.endTime, l?.endTime);
|
|
1297
|
+
(o > e || c <= e) && (this.hotLines.delete(n), i.add(n), this.hotLines.delete(n + 1), i.add(n + 1), t && (this.lyricLinesEl[n].disable(), this.lyricLinesEl[n + 1].disable()));
|
|
1133
1298
|
} else
|
|
1134
|
-
(
|
|
1299
|
+
(a.startTime > e || a.endTime <= e) && (this.hotLines.delete(n), i.add(n), t && this.lyricLinesEl[n].disable());
|
|
1135
1300
|
} else
|
|
1136
|
-
this.hotLines.delete(
|
|
1137
|
-
}), this.processedLines.forEach((
|
|
1138
|
-
!
|
|
1139
|
-
}), this.bufferedLines.forEach((
|
|
1140
|
-
this.hotLines.has(
|
|
1301
|
+
this.hotLines.delete(n), i.add(n), t && this.lyricLinesEl[n].disable();
|
|
1302
|
+
}), this.processedLines.forEach((n, a, l) => {
|
|
1303
|
+
!n.isBG && n.startTime <= e && n.endTime > e && (this.hotLines.has(a) || (this.hotLines.add(a), r.add(a), t && this.lyricLinesEl[a].enable(), l[a + 1]?.isBG && (this.hotLines.add(a + 1), r.add(a + 1), t && this.lyricLinesEl[a + 1].enable())));
|
|
1304
|
+
}), this.bufferedLines.forEach((n) => {
|
|
1305
|
+
this.hotLines.has(n) || (s.add(n), t && this.lyricLinesEl[n].disable());
|
|
1141
1306
|
}), t ? (this.bufferedLines.size > 0 ? this.scrollToIndex = Math.min(...this.bufferedLines) : this.scrollToIndex = this.processedLines.findIndex(
|
|
1142
|
-
(
|
|
1143
|
-
), this.bufferedLines.clear(), this.hotLines.forEach((
|
|
1144
|
-
this.bufferedLines.add(
|
|
1145
|
-
}), this.scrollToIndex = Math.min(...this.bufferedLines)) :
|
|
1146
|
-
this.hotLines.has(
|
|
1147
|
-
}) : (
|
|
1148
|
-
this.bufferedLines.add(
|
|
1149
|
-
}),
|
|
1150
|
-
this.bufferedLines.delete(
|
|
1151
|
-
}), this.bufferedLines.size > 0 && (this.scrollToIndex = Math.min(...this.bufferedLines))
|
|
1307
|
+
(n) => n.startTime >= e
|
|
1308
|
+
), this.bufferedLines.clear(), this.hotLines.forEach((n) => this.bufferedLines.add(n)), this.calcLayout(!0)) : (s.size > 0 || r.size > 0) && (s.size === 0 && r.size > 0 ? (r.forEach((n) => {
|
|
1309
|
+
this.bufferedLines.add(n), this.lyricLinesEl[n].enable();
|
|
1310
|
+
}), this.scrollToIndex = Math.min(...this.bufferedLines), this.calcLayout()) : r.size === 0 && s.size > 0 ? N(s, this.bufferedLines) && (this.bufferedLines.forEach((n) => {
|
|
1311
|
+
this.hotLines.has(n) || (this.bufferedLines.delete(n), this.lyricLinesEl[n].disable());
|
|
1312
|
+
}), this.calcLayout()) : (r.forEach((n) => {
|
|
1313
|
+
this.bufferedLines.add(n), this.lyricLinesEl[n].enable();
|
|
1314
|
+
}), s.forEach((n) => {
|
|
1315
|
+
this.bufferedLines.delete(n), this.lyricLinesEl[n].disable();
|
|
1316
|
+
}), this.bufferedLines.size > 0 && (this.scrollToIndex = Math.min(...this.bufferedLines)), this.calcLayout()));
|
|
1152
1317
|
}
|
|
1153
1318
|
/**
|
|
1154
1319
|
* 更新动画,这个函数应该被逐帧调用或者在以下情况下调用一次:
|
|
@@ -1158,7 +1323,7 @@ class ie extends EventTarget {
|
|
|
1158
1323
|
*/
|
|
1159
1324
|
update(e = 0) {
|
|
1160
1325
|
const t = e / 1e3;
|
|
1161
|
-
this.interludeDots.update(e), this.bottomLine.update(t), this.lyricLinesEl.forEach((
|
|
1326
|
+
this.interludeDots.update(e), this.bottomLine.update(t), this.lyricLinesEl.forEach((i) => i.update(t));
|
|
1162
1327
|
}
|
|
1163
1328
|
/**
|
|
1164
1329
|
* 设置所有歌词行在横坐标上的弹簧属性,包括重量、弹力和阻力。
|
|
@@ -1204,8 +1369,8 @@ class ie extends EventTarget {
|
|
|
1204
1369
|
}
|
|
1205
1370
|
}
|
|
1206
1371
|
export {
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1372
|
+
oe as BackgroundRender,
|
|
1373
|
+
le as LyricPlayer,
|
|
1374
|
+
ae as ttml
|
|
1210
1375
|
};
|
|
1211
1376
|
//# sourceMappingURL=amll-core.mjs.map
|