@applemusic-like-lyrics/core 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,60 +1,60 @@
1
1
  import { Container as v } from "@pixi/display";
2
2
  import { Application as M } from "@pixi/app";
3
3
  import { BlurFilter as y } from "@pixi/filter-blur";
4
- import { ColorMatrixFilter as w } from "@pixi/filter-color-matrix";
4
+ import { ColorMatrixFilter as E } from "@pixi/filter-color-matrix";
5
5
  import { Texture as C } from "@pixi/core";
6
6
  import { Sprite as L } from "@pixi/sprite";
7
7
  import { create as z } from "jss";
8
8
  import A from "jss-preset-default";
9
9
  const D = /^(((?<hour>[0-9]+):)?(?<min>[0-9]+):)?(?<sec>[0-9]+([\.:]([0-9]+))?)/;
10
- function T(c) {
11
- const e = D.exec(c);
10
+ function T(d) {
11
+ const e = D.exec(d);
12
12
  if (e) {
13
13
  const t = Number(e.groups?.hour || "0"), i = Number(e.groups?.min || "0"), n = Number(e.groups?.sec.replace(/:/, ".") || "0");
14
14
  return Math.floor((t * 3600 + i * 60 + n) * 1e3);
15
15
  } else
16
16
  throw new TypeError("时间戳字符串解析失败");
17
17
  }
18
- function I(c) {
18
+ function I(d) {
19
19
  const t = new DOMParser().parseFromString(
20
- c,
20
+ d,
21
21
  "application/xml"
22
22
  );
23
23
  let i = "v1";
24
- for (const h of t.querySelectorAll("ttm\\:agent"))
25
- if (h.getAttribute("type") === "person") {
26
- const s = h.getAttribute("xml:id");
24
+ for (const a of t.querySelectorAll("ttm\\:agent"))
25
+ if (a.getAttribute("type") === "person") {
26
+ const s = a.getAttribute("xml:id");
27
27
  s && (i = s);
28
28
  }
29
29
  const n = [];
30
- for (const h of t.querySelectorAll("body p[begin][end]")) {
30
+ for (const a of t.querySelectorAll("body p[begin][end]")) {
31
31
  const s = {
32
32
  words: [],
33
- startTime: T(h.getAttribute("begin") ?? "0:0"),
34
- endTime: T(h.getAttribute("end") ?? "0:0"),
33
+ startTime: T(a.getAttribute("begin") ?? "0:0"),
34
+ endTime: T(a.getAttribute("end") ?? "0:0"),
35
35
  translatedLyric: "",
36
36
  romanLyric: "",
37
37
  isBG: !1,
38
- isDuet: h.getAttribute("ttm:agent") !== i
38
+ isDuet: a.getAttribute("ttm:agent") !== i
39
39
  };
40
40
  let r = null;
41
- for (const a of h.childNodes)
42
- if (a.nodeType === Node.TEXT_NODE) {
43
- const l = a.textContent ?? "";
44
- /^(\s+)$/.test(l) ? s.words.push({
41
+ for (const l of a.childNodes)
42
+ if (l.nodeType === Node.TEXT_NODE) {
43
+ const h = l.textContent ?? "";
44
+ /^(\s+)$/.test(h) ? s.words.push({
45
45
  word: " ",
46
46
  startTime: 0,
47
47
  endTime: 0
48
48
  }) : s.words.push({
49
- word: l,
49
+ word: h,
50
50
  startTime: 0,
51
51
  endTime: 0
52
52
  });
53
- } else if (a.nodeType === Node.ELEMENT_NODE) {
54
- const l = a, o = l.getAttribute("ttm:role");
55
- if (l.nodeName === "span" && o)
53
+ } else if (l.nodeType === Node.ELEMENT_NODE) {
54
+ const h = l, o = h.getAttribute("ttm:role");
55
+ if (h.nodeName === "span" && o)
56
56
  if (o === "x-bg") {
57
- const d = {
57
+ const c = {
58
58
  words: [],
59
59
  startTime: s.startTime,
60
60
  endTime: s.endTime,
@@ -63,47 +63,47 @@ function I(c) {
63
63
  isBG: !0,
64
64
  isDuet: s.isDuet
65
65
  };
66
- for (const p of l.childNodes)
67
- if (p.nodeType === Node.TEXT_NODE) {
68
- const f = p.textContent ?? "";
69
- /^(\s+)$/.test(f) ? d.words.push({
66
+ for (const u of h.childNodes)
67
+ if (u.nodeType === Node.TEXT_NODE) {
68
+ const f = u.textContent ?? "";
69
+ /^(\s+)$/.test(f) ? c.words.push({
70
70
  word: " ",
71
71
  startTime: 0,
72
72
  endTime: 0
73
- }) : d.words.push({
73
+ }) : c.words.push({
74
74
  word: f,
75
75
  startTime: 0,
76
76
  endTime: 0
77
77
  });
78
- } else if (p.nodeType === Node.ELEMENT_NODE) {
79
- const f = p, S = f.getAttribute("ttm:role");
80
- if (f.nodeName === "span" && S)
81
- S === "x-translation" ? d.translatedLyric = f.innerHTML.trim() : S === "x-roman" && (d.romanLyric = f.innerHTML.trim());
78
+ } else if (u.nodeType === Node.ELEMENT_NODE) {
79
+ const f = u, b = f.getAttribute("ttm:role");
80
+ if (f.nodeName === "span" && b)
81
+ b === "x-translation" ? c.translatedLyric = f.innerHTML.trim() : b === "x-roman" && (c.romanLyric = f.innerHTML.trim());
82
82
  else if (f.hasAttribute("begin") && f.hasAttribute("end")) {
83
83
  const x = {
84
- word: p.textContent,
84
+ word: u.textContent,
85
85
  startTime: T(f.getAttribute("begin")),
86
86
  endTime: T(f.getAttribute("end"))
87
87
  };
88
- d.words.push(x);
88
+ c.words.push(x);
89
89
  }
90
90
  }
91
- const m = d.words[0];
92
- d.startTime = m.startTime, m?.word.startsWith("(") && (m.word = m.word.substring(1));
93
- const u = d.words[d.words.length - 1];
94
- d.endTime = u.endTime, u?.word.endsWith(")") && (u.word = u.word.substring(
91
+ const m = c.words[0];
92
+ c.startTime = m.startTime, m?.word.startsWith("(") && (m.word = m.word.substring(1));
93
+ const p = c.words[c.words.length - 1];
94
+ c.endTime = p.endTime, p?.word.endsWith(")") && (p.word = p.word.substring(
95
95
  0,
96
- u.word.length - 1
97
- )), r = d;
96
+ p.word.length - 1
97
+ )), r = c;
98
98
  } else
99
- o === "x-translation" ? s.translatedLyric = l.innerHTML : o === "x-roman" && (s.romanLyric = l.innerHTML);
100
- else if (l.hasAttribute("begin") && l.hasAttribute("end")) {
101
- const d = {
102
- word: a.textContent ?? "",
103
- startTime: T(l.getAttribute("begin")),
104
- endTime: T(l.getAttribute("end"))
99
+ o === "x-translation" ? s.translatedLyric = h.innerHTML : o === "x-roman" && (s.romanLyric = h.innerHTML);
100
+ else if (h.hasAttribute("begin") && h.hasAttribute("end")) {
101
+ const c = {
102
+ word: l.textContent ?? "",
103
+ startTime: T(h.getAttribute("begin")),
104
+ endTime: T(h.getAttribute("end"))
105
105
  };
106
- s.words.push(d);
106
+ s.words.push(c);
107
107
  }
108
108
  }
109
109
  n.push(s), r && n.push(r);
@@ -146,11 +146,11 @@ class k {
146
146
  1,
147
147
  this.curContainer.alpha + e / 60
148
148
  );
149
- const [t, i, n, h] = this.curContainer.children, s = Math.max(this.app.screen.width, this.app.screen.height);
149
+ const [t, i, n, a] = this.curContainer.children, s = Math.max(this.app.screen.width, this.app.screen.height);
150
150
  t.position.set(this.app.screen.width / 2, this.app.screen.height / 2), i.position.set(
151
151
  this.app.screen.width / 2.5,
152
152
  this.app.screen.height / 2.5
153
- ), n.position.set(this.app.screen.width / 2, this.app.screen.height / 2), h.position.set(this.app.screen.width / 2, this.app.screen.height / 2), t.width = s * Math.sqrt(2), t.height = t.width, i.width = s * 0.8, i.height = i.width, n.width = s * 0.5, n.height = n.width, h.width = s * 0.25, h.height = h.width, this.curContainer.time += e * this.flowSpeed, t.rotation += e / 1e3 * this.flowSpeed, i.rotation -= e / 500 * this.flowSpeed, n.rotation += e / 1e3 * this.flowSpeed, h.rotation -= e / 750 * this.flowSpeed, n.x = this.app.screen.width / 2 + this.app.screen.width / 4 * Math.cos(this.curContainer.time / 1e3 * 0.75), n.y = this.app.screen.height / 2 + this.app.screen.width / 4 * Math.cos(this.curContainer.time / 1e3 * 0.75), h.x = this.app.screen.width / 2 + this.app.screen.width / 4 * 0.1 + Math.cos(this.curContainer.time * 6e-3 * 0.75), h.y = this.app.screen.height / 2 + this.app.screen.width / 4 * 0.1 + Math.cos(this.curContainer.time * 6e-3 * 0.75);
153
+ ), n.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), t.width = s * Math.sqrt(2), t.height = t.width, i.width = s * 0.8, i.height = i.width, n.width = s * 0.5, n.height = n.width, a.width = s * 0.25, a.height = a.width, this.curContainer.time += e * this.flowSpeed, t.rotation += e / 1e3 * this.flowSpeed, i.rotation -= e / 500 * this.flowSpeed, n.rotation += e / 1e3 * this.flowSpeed, a.rotation -= e / 750 * this.flowSpeed, n.x = this.app.screen.width / 2 + this.app.screen.width / 4 * Math.cos(this.curContainer.time / 1e3 * 0.75), n.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);
154
154
  }
155
155
  };
156
156
  flowSpeed = 2;
@@ -177,11 +177,11 @@ class k {
177
177
  ), this.rebuildFilters();
178
178
  }
179
179
  rebuildFilters() {
180
- const e = Math.min(this.canvas.width, this.canvas.height), t = new w();
180
+ const e = Math.min(this.canvas.width, this.canvas.height), t = new E();
181
181
  t.saturate(1.2, !1);
182
- const i = new w();
182
+ const i = new E();
183
183
  i.brightness(0.6, !1);
184
- const n = new w();
184
+ const n = new E();
185
185
  n.contrast(0.3, !0), 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)), e > 512 && 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(t, i, n), this.app.stage.filters.push(new y(5, 1));
186
186
  }
187
187
  /**
@@ -210,8 +210,8 @@ class k {
210
210
  * @param albumUrl 图片的目标链接
211
211
  */
212
212
  async setAlbumImage(e) {
213
- const t = await C.fromURL(e), i = new B(), n = new L(t), h = new L(t), s = new L(t), r = new L(t);
214
- n.anchor.set(0.5, 0.5), h.anchor.set(0.5, 0.5), s.anchor.set(0.5, 0.5), r.anchor.set(0.5, 0.5), n.rotation = Math.random() * Math.PI * 2, h.rotation = Math.random() * Math.PI * 2, s.rotation = Math.random() * Math.PI * 2, r.rotation = Math.random() * Math.PI * 2, i.addChild(n, h, s, r), this.curContainer && this.lastContainer.add(this.curContainer), this.curContainer = i, this.app.stage.addChild(this.curContainer), this.curContainer.alpha = 0;
213
+ const t = await C.fromURL(e), i = new B(), n = new L(t), a = new L(t), s = new L(t), r = new L(t);
214
+ n.anchor.set(0.5, 0.5), a.anchor.set(0.5, 0.5), s.anchor.set(0.5, 0.5), r.anchor.set(0.5, 0.5), n.rotation = Math.random() * Math.PI * 2, a.rotation = Math.random() * Math.PI * 2, s.rotation = Math.random() * Math.PI * 2, r.rotation = Math.random() * Math.PI * 2, i.addChild(n, a, s, r), this.curContainer && this.lastContainer.add(this.curContainer), this.curContainer = i, this.app.stage.addChild(this.curContainer), this.curContainer.alpha = 0;
215
215
  }
216
216
  dispose() {
217
217
  this.observer.disconnect(), this.app.ticker.remove(this.onTick);
@@ -230,13 +230,13 @@ class Z extends k {
230
230
  super.dispose(), this.element.remove();
231
231
  }
232
232
  }
233
- const N = (c, e) => c.size === e.size && [...c].every((t) => e.has(t));
234
- function O(c) {
233
+ const N = (d, e) => d.size === e.size && [...d].every((t) => e.has(t));
234
+ function O(d) {
235
235
  const t = 2.5949095;
236
- return c < 0.5 ? Math.pow(2 * c, 2) * ((t + 1) * 2 * c - t) / 2 : (Math.pow(2 * c - 2, 2) * ((t + 1) * (c * 2 - 2) + t) + 2) / 2;
236
+ return d < 0.5 ? Math.pow(2 * d, 2) * ((t + 1) * 2 * d - t) / 2 : (Math.pow(2 * d - 2, 2) * ((t + 1) * (d * 2 - 2) + t) + 2) / 2;
237
237
  }
238
- const g = (c, e, t) => Math.max(c, Math.min(e, t));
239
- class W {
238
+ const g = (d, e, t) => Math.max(d, Math.min(e, t));
239
+ class $ {
240
240
  constructor(e) {
241
241
  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);
242
242
  }
@@ -266,20 +266,20 @@ class W {
266
266
  if (t += `transform:translate(${this.left}px, ${this.top}px)`, this.currentInterlude) {
267
267
  const i = this.currentInterlude[1] - this.currentInterlude[0], n = this.currentTime - this.currentInterlude[0];
268
268
  if (n <= i) {
269
- const h = i / Math.ceil(i / this.targetBreatheDuration);
269
+ const a = i / Math.ceil(i / this.targetBreatheDuration);
270
270
  let s = 1, r = 1;
271
- s *= Math.sin(1.5 * Math.PI - n / h * 2) / 10 + 1, n < 1e3 && (s *= 1 - Math.pow((1e3 - n) / 1e3, 2)), n < 500 ? r = 0 : n < 1e3 && (r *= (n - 500) / 500), i - n < 750 && (s *= 1 - O(
271
+ s *= Math.sin(1.5 * Math.PI - n / a * 2) / 10 + 1, n < 1e3 && (s *= 1 - Math.pow((1e3 - n) / 1e3, 2)), n < 500 ? r = 0 : n < 1e3 && (r *= (n - 500) / 500), i - n < 750 && (s *= 1 - O(
272
272
  (750 - (i - n)) / 750 / 2
273
273
  )), i - n < 375 && (r *= g(
274
274
  0,
275
275
  (i - n) / 375,
276
276
  1
277
277
  )), s = Math.max(0, s), t += ` scale(${s})`;
278
- const a = g(
278
+ const l = g(
279
279
  0.25,
280
280
  n * 3 / i * 0.75,
281
281
  1
282
- ), l = g(
282
+ ), h = g(
283
283
  0.25,
284
284
  (n - i / 3) * 3 / i * 0.75,
285
285
  1
@@ -290,11 +290,11 @@ class W {
290
290
  );
291
291
  this.dot0.style.opacity = `${g(
292
292
  0,
293
- Math.max(0, r * a),
293
+ Math.max(0, r * l),
294
294
  1
295
295
  )}`, this.dot1.style.opacity = `${g(
296
296
  0,
297
- Math.max(0, r * l),
297
+ Math.max(0, r * h),
298
298
  1
299
299
  )}`, this.dot2.style.opacity = `${g(
300
300
  0,
@@ -311,7 +311,7 @@ class W {
311
311
  this.element.remove();
312
312
  }
313
313
  }
314
- class P {
314
+ class S {
315
315
  currentPosition = 0;
316
316
  targetPosition = 0;
317
317
  currentTime = 0;
@@ -325,7 +325,7 @@ class P {
325
325
  }
326
326
  resetSolver() {
327
327
  const e = this.getV(this.currentTime);
328
- this.currentTime = 0, this.currentSolver = $(
328
+ this.currentTime = 0, this.currentSolver = q(
329
329
  this.currentPosition,
330
330
  e,
331
331
  this.targetPosition,
@@ -363,35 +363,35 @@ class P {
363
363
  return this.currentPosition;
364
364
  }
365
365
  }
366
- function $(c, e, t, i = 0, n) {
367
- const h = n?.soft ?? !1, s = n?.stiffness ?? 100, r = n?.damping ?? 10, a = n?.mass ?? 1, l = t - c;
368
- if (h || 1 <= r / (2 * Math.sqrt(s * a))) {
369
- const o = -Math.sqrt(s / a), d = -o * l - e;
370
- return (m) => (m -= i, m < 0 ? c : t - (l + m * d) * Math.E ** (m * o));
366
+ function q(d, e, t, i = 0, n) {
367
+ const a = n?.soft ?? !1, s = n?.stiffness ?? 100, r = n?.damping ?? 10, l = n?.mass ?? 1, h = t - d;
368
+ if (a || 1 <= r / (2 * Math.sqrt(s * l))) {
369
+ const o = -Math.sqrt(s / l), c = -o * h - e;
370
+ return (m) => (m -= i, m < 0 ? d : t - (h + m * c) * Math.E ** (m * o));
371
371
  } else {
372
372
  const o = Math.sqrt(
373
- 4 * a * s - r ** 2
374
- ), d = (r * l - 2 * a * e) / o, m = 0.5 * o / a, u = -(0.5 * r) / a;
375
- return (p) => (p -= i, p < 0 ? c : t - (Math.cos(p * m) * l + Math.sin(p * m) * d) * Math.E ** (p * u));
373
+ 4 * l * s - r ** 2
374
+ ), c = (r * h - 2 * l * e) / o, m = 0.5 * o / l, p = -(0.5 * r) / l;
375
+ return (u) => (u -= i, u < 0 ? d : t - (Math.cos(u * m) * h + Math.sin(u * m) * c) * Math.E ** (u * p));
376
376
  }
377
377
  }
378
- function q(c) {
379
- return (t) => (c(t + 1e-3) - c(t - 1e-3)) / (2 * 1e-3);
378
+ function F(d) {
379
+ return (t) => (d(t + 1e-3) - d(t - 1e-3)) / (2 * 1e-3);
380
380
  }
381
- function R(c) {
382
- return q(c);
381
+ function R(d) {
382
+ return F(d);
383
383
  }
384
- const b = /^[\p{Unified_Ideograph}\u0800-\u9FFC]+$/u;
385
- function F(c, e = "rgba(0,0,0,1)", t = "rgba(0,0,0,0.5)") {
386
- const i = 2 + c, n = c / i, h = (1 - n) / 2;
384
+ const w = /^[\p{Unified_Ideograph}\u0800-\u9FFC]+$/u;
385
+ function W(d, e = "rgba(0,0,0,1)", t = "rgba(0,0,0,0.5)") {
386
+ const i = 2 + d, n = d / i, a = (1 - n) / 2;
387
387
  return [
388
- `linear-gradient(to right,${e} ${h * 100}%,${t} ${(h + n) * 100}%)`,
388
+ `linear-gradient(to right,${e} ${a * 100}%,${t} ${(a + n) * 100}%)`,
389
389
  n,
390
390
  i
391
391
  ];
392
392
  }
393
- function E(c) {
394
- return c.endTime - c.startTime >= 1e3 && c.word.length <= 7;
393
+ function P(d) {
394
+ return d.endTime - d.startTime >= 1e3 && d.word.length <= 7;
395
395
  }
396
396
  class _ {
397
397
  constructor(e, t = {
@@ -407,8 +407,8 @@ class _ {
407
407
  "class",
408
408
  this.lyricPlayer.style.classes.lyricLine
409
409
  ), 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"));
410
- const i = this.element.children[0], n = this.element.children[1], h = this.element.children[2];
411
- i.setAttribute("class", this.lyricPlayer.style.classes.lyricMainLine), n.setAttribute("class", this.lyricPlayer.style.classes.lyricSubLine), h.setAttribute("class", this.lyricPlayer.style.classes.lyricSubLine), this.rebuildElement(), this.rebuildStyle();
410
+ const i = this.element.children[0], n = this.element.children[1], a = this.element.children[2];
411
+ i.setAttribute("class", this.lyricPlayer.style.classes.lyricMainLine), n.setAttribute("class", this.lyricPlayer.style.classes.lyricSubLine), a.setAttribute("class", this.lyricPlayer.style.classes.lyricSubLine), this.rebuildElement(), this.rebuildStyle();
412
412
  }
413
413
  element = document.createElement("div");
414
414
  left = 0;
@@ -420,9 +420,9 @@ class _ {
420
420
  // 由 LyricPlayer 来设置
421
421
  lineSize = [0, 0];
422
422
  lineTransforms = {
423
- posX: new P(0),
424
- posY: new P(0),
425
- scale: new P(1)
423
+ posX: new S(0),
424
+ posY: new S(0),
425
+ scale: new S(1)
426
426
  };
427
427
  isEnabled = !1;
428
428
  enable() {
@@ -480,19 +480,11 @@ class _ {
480
480
  }
481
481
  rebuildElement() {
482
482
  const e = this.element.children[0], t = this.element.children[1], i = this.element.children[2];
483
- this.splittedWords = [], this.lyricLine.words.forEach((a) => {
484
- if (b.test(a.word))
485
- this.splittedWords.push({
486
- ...a,
487
- width: 0,
488
- height: 0,
489
- elements: [],
490
- elementAnimations: [],
491
- shouldEmphasize: E(a)
492
- });
493
- else {
494
- const l = /^(\s*)(\S*)(\s*)$/.exec(a.word);
495
- l ? (l[1].length > 0 && this.splittedWords.push({
483
+ this.splittedWords = [], this.lyricLine.words.forEach((l) => {
484
+ const h = l.word.split(/\s+/), o = h.reduce((m, p) => m + p.length, 0);
485
+ let c = 0;
486
+ h.forEach((m, p) => {
487
+ p > 0 && this.splittedWords.push({
496
488
  word: " ",
497
489
  startTime: 0,
498
490
  endTime: 0,
@@ -502,81 +494,63 @@ class _ {
502
494
  elementAnimations: [],
503
495
  shouldEmphasize: !1
504
496
  }), this.splittedWords.push({
505
- word: l[2],
506
- startTime: a.startTime,
507
- endTime: a.endTime,
508
- width: 0,
509
- height: 0,
510
- elements: [],
511
- elementAnimations: [],
512
- shouldEmphasize: E(a)
513
- }), l[3].length > 0 && this.splittedWords.push({
514
- word: " ",
515
- startTime: 0,
516
- endTime: 0,
497
+ word: m,
498
+ startTime: l.startTime + (l.endTime - l.startTime) / o * c,
499
+ endTime: l.startTime + (l.endTime - l.startTime) / o * (c + m.length),
517
500
  width: 0,
518
501
  height: 0,
519
502
  elements: [],
520
503
  elementAnimations: [],
521
- shouldEmphasize: !1
522
- })) : a.word.trim().length > 0 && this.splittedWords.push({
523
- word: a.word.trim(),
524
- startTime: a.startTime,
525
- endTime: a.endTime,
526
- width: 0,
527
- height: 0,
528
- elements: [],
529
- elementAnimations: [],
530
- shouldEmphasize: E(a)
531
- });
532
- }
504
+ shouldEmphasize: P(l)
505
+ }), c += m.length;
506
+ });
533
507
  });
534
- const n = [], h = [];
535
- function s(a) {
536
- for (; a.firstChild; )
537
- a.firstChild.nodeType === Node.ELEMENT_NODE ? n.push(e.firstChild) : a.firstChild.nodeType === Node.TEXT_NODE && h.push(e.firstChild), a.removeChild(a.firstChild), s(a.firstChild);
508
+ const n = [], a = [];
509
+ function s(l) {
510
+ for (; l.firstChild; )
511
+ l.firstChild.nodeType === Node.ELEMENT_NODE ? n.push(e.firstChild) : l.firstChild.nodeType === Node.TEXT_NODE && a.push(e.firstChild), l.removeChild(l.firstChild), s(l.firstChild);
538
512
  }
539
513
  s(e);
540
514
  let r = null;
541
- this.splittedWords.forEach((a) => {
542
- if (a.word.trim().length > 0)
543
- if (a.shouldEmphasize) {
544
- const l = n.pop() ?? document.createElement("span");
545
- l.className = "emphasize", a.elements = [l];
546
- for (const o of a.word) {
547
- const d = n.pop() ?? document.createElement("span");
548
- d.className = "", d.innerText = o, l.appendChild(d), a.elements.push(d);
515
+ this.splittedWords.forEach((l) => {
516
+ if (l.word.trim().length > 0)
517
+ if (l.shouldEmphasize) {
518
+ const h = n.pop() ?? document.createElement("span");
519
+ h.className = "emphasize", l.elements = [h];
520
+ for (const o of l.word) {
521
+ const c = n.pop() ?? document.createElement("span");
522
+ c.className = "", c.innerText = o, h.appendChild(c), l.elements.push(c);
549
523
  }
550
- if (a.elementAnimations = this.initEmphasizeAnimation(a), console.log(a.word, b.test(a.word)), r && !b.test(a.word))
524
+ if (l.elementAnimations = this.initEmphasizeAnimation(l), console.log(l.word, w.test(l.word)), r && !w.test(l.word))
551
525
  if (r.childElementCount > 0)
552
- r.appendChild(l);
526
+ r.appendChild(h);
553
527
  else {
554
528
  const o = n.pop() ?? document.createElement("span");
555
- o.className = "", r.remove(), o.appendChild(r), o.appendChild(l), e.appendChild(o), r = o;
529
+ o.className = "", r.remove(), o.appendChild(r), o.appendChild(h), e.appendChild(o), r = o;
556
530
  }
557
531
  else
558
- r = b.test(a.word) ? null : l, e.appendChild(l);
532
+ r = w.test(l.word) ? null : h, e.appendChild(h);
559
533
  } else {
560
- const l = n.pop() ?? document.createElement("span");
561
- if (l.className = "", l.innerText = a.word, a.elements = [l], a.elementAnimations.push(this.initFloatAnimation(a, l)), r)
534
+ const h = n.pop() ?? document.createElement("span");
535
+ if (h.className = "", h.innerText = l.word, l.elements = [h], l.elementAnimations.push(this.initFloatAnimation(l, h)), r)
562
536
  if (r.childElementCount > 0)
563
- r.appendChild(l);
537
+ r.appendChild(h);
564
538
  else {
565
539
  const o = n.pop() ?? document.createElement("span");
566
- o.className = "", r.remove(), o.appendChild(r), o.appendChild(l), e.appendChild(o), r = o;
540
+ o.className = "", r.remove(), o.appendChild(r), o.appendChild(h), e.appendChild(o), r = o;
567
541
  }
568
542
  else
569
- r = l, e.appendChild(l);
543
+ r = h, e.appendChild(h);
570
544
  }
571
- else if (a.word.length > 0) {
572
- const l = h.pop() ?? document.createTextNode(" ");
573
- e.appendChild(l), r = null;
545
+ else if (l.word.length > 0) {
546
+ const h = a.pop() ?? document.createTextNode(" ");
547
+ e.appendChild(h), r = null;
574
548
  } else
575
549
  r = null;
576
550
  }), t.innerText = this.lyricLine.translatedLyric, i.innerText = this.lyricLine.romanLyric;
577
551
  }
578
552
  initFloatAnimation(e, t) {
579
- const i = t.animate(
553
+ const i = e.startTime - this.lyricLine.startTime, n = Math.max(1e3, e.endTime - e.startTime), a = t.animate(
580
554
  [
581
555
  {
582
556
  transform: "translateY(0px)"
@@ -586,19 +560,19 @@ class _ {
586
560
  }
587
561
  ],
588
562
  {
589
- duration: Math.max(1e3, e.endTime - e.startTime),
590
- delay: e.startTime - this.lyricLine.startTime,
563
+ duration: isFinite(n) ? n : 0,
564
+ delay: isFinite(i) ? i : 0,
591
565
  id: "float-word",
592
566
  composite: "add",
593
567
  fill: "both"
594
568
  }
595
569
  );
596
- return i.pause(), i;
570
+ return a.pause(), a;
597
571
  }
598
572
  initEmphasizeAnimation(e) {
599
573
  const t = e.startTime - this.lyricLine.startTime, i = e.endTime - e.startTime;
600
- return e.elements.map((n, h, s) => {
601
- if (h === 0)
574
+ return e.elements.map((n, a, s) => {
575
+ if (a === 0)
602
576
  return this.initFloatAnimation(e, n);
603
577
  {
604
578
  const r = n.animate(
@@ -621,7 +595,7 @@ class _ {
621
595
  ],
622
596
  {
623
597
  duration: Math.max(1e3, e.endTime - e.startTime),
624
- delay: t + i / (s.length - 1) * (h - 1),
598
+ delay: t + i / (s.length - 1) * (a - 1),
625
599
  id: "glow-word",
626
600
  iterations: 1,
627
601
  composite: "replace",
@@ -637,37 +611,37 @@ class _ {
637
611
  const t = e.elements[0];
638
612
  if (t) {
639
613
  e.width = t.clientWidth, e.height = t.clientHeight;
640
- const [i, n, h] = F(
614
+ const [i, n, a] = W(
641
615
  16 / e.width,
642
616
  "rgba(0,0,0,0.75)",
643
617
  "rgba(0,0,0,0.25)"
644
- ), s = `${h * 100}% 100%`;
618
+ ), s = `${a * 100}% 100%`;
645
619
  this.lyricPlayer.supportMaskImage ? (t.style.maskImage = i, t.style.maskOrigin = "left", t.style.maskSize = s) : (t.style.webkitMaskImage = i, t.style.webkitMaskOrigin = "left", t.style.webkitMaskSize = s);
646
- const r = e.width + 16, a = `clamp(${-r}px,calc(${-r}px + (var(--amll-player-time) - ${e.startTime})*${r / Math.abs(e.endTime - e.startTime)}px),0px) 0px, left top`;
647
- t.style.maskPosition = a, t.style.webkitMaskPosition = a;
620
+ const r = e.width + 16, l = `clamp(${-r}px,calc(${-r}px + (var(--amll-player-time) - ${e.startTime})*${r / Math.abs(e.endTime - e.startTime)}px),0px) 0px, left top`;
621
+ t.style.maskPosition = l, t.style.webkitMaskPosition = l;
648
622
  }
649
623
  }), this._hide && (this.element.style.display = "none", this.element.style.visibility = "");
650
624
  }
651
625
  getElement() {
652
626
  return this.element;
653
627
  }
654
- setTransform(e = this.left, t = this.top, i = this.scale, n = 1, h = 0, s = !1, r = 0) {
628
+ setTransform(e = this.left, t = this.top, i = this.scale, n = 1, a = 0, s = !1, r = 0) {
655
629
  this.left = e, this.top = t, this.scale = i, this.delay = r * 1e3 | 0;
656
- const a = this.element.children[0];
657
- a.style.opacity = `${n}`, s || !this.lyricPlayer.getEnableSpring() ? (this.blur = Math.min(32, h), s && this.element.classList.add(
630
+ const l = this.element.children[0];
631
+ l.style.opacity = `${n}`, s || !this.lyricPlayer.getEnableSpring() ? (this.blur = Math.min(32, a), s && this.element.classList.add(
658
632
  this.lyricPlayer.style.classes.tmpDisableTransition
659
633
  ), this.lineTransforms.posX.setPosition(e), this.lineTransforms.posY.setPosition(t), this.lineTransforms.scale.setPosition(i), this.lyricPlayer.getEnableSpring() ? this.rebuildStyle() : this.show(), s && requestAnimationFrame(() => {
660
634
  this.element.classList.remove(
661
635
  this.lyricPlayer.style.classes.tmpDisableTransition
662
636
  );
663
- })) : (this.lineTransforms.posX.setTargetPosition(e, r), this.lineTransforms.posY.setTargetPosition(t, r), this.lineTransforms.scale.setTargetPosition(i), this.blur !== Math.min(32, h) && (this.blur = Math.min(32, h), this.element.style.filter = `blur(${Math.min(32, h)}px)`));
637
+ })) : (this.lineTransforms.posX.setTargetPosition(e, r), this.lineTransforms.posY.setTargetPosition(t, r), this.lineTransforms.scale.setTargetPosition(i), this.blur !== Math.min(32, a) && (this.blur = Math.min(32, a), this.element.style.filter = `blur(${Math.min(32, a)}px)`));
664
638
  }
665
639
  update(e = 0) {
666
640
  this.lyricPlayer.getEnableSpring() && (this.lineTransforms.posX.update(e), this.lineTransforms.posY.update(e), this.lineTransforms.scale.update(e), this.isInSight ? this.show() : this.hide());
667
641
  }
668
642
  get isInSight() {
669
- const e = this.lineTransforms.posX.getCurrentPosition(), t = this.lineTransforms.posY.getCurrentPosition(), i = e + this.lineSize[0], n = t + this.lineSize[1], h = this.lyricPlayer.pos[0], s = this.lyricPlayer.pos[1], r = this.lyricPlayer.pos[0] + this.lyricPlayer.size[0], a = this.lyricPlayer.pos[1] + this.lyricPlayer.size[1];
670
- return !(e > r || t > a || i < h || n < s);
643
+ const e = this.lineTransforms.posX.getCurrentPosition(), t = this.lineTransforms.posY.getCurrentPosition(), i = e + this.lineSize[0], n = t + this.lineSize[1], a = this.lyricPlayer.pos[0], s = this.lyricPlayer.pos[1], r = this.lyricPlayer.pos[0] + this.lyricPlayer.size[0], l = this.lyricPlayer.pos[1] + this.lyricPlayer.size[1];
644
+ return !(e > r || t > l || i < a || n < s);
671
645
  }
672
646
  dispose() {
673
647
  this.element.remove();
@@ -839,7 +813,7 @@ class ee extends EventTarget {
839
813
  this.calcLayout(!0);
840
814
  };
841
815
  constructor() {
842
- super(), this.interludeDots = new W(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);
816
+ super(), this.interludeDots = new $(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);
843
817
  }
844
818
  /**
845
819
  * 获取当前播放时间里是否处于间奏区间
@@ -855,11 +829,12 @@ class ee extends EventTarget {
855
829
  const e = this.currentTime + 20, t = this.scrollToIndex;
856
830
  if (t === 0) {
857
831
  if (this.processedLines[0]?.startTime && this.processedLines[0].startTime > e)
858
- return [0, this.processedLines[0].startTime];
832
+ return [0, this.processedLines[0].startTime, -2];
859
833
  } else if (this.processedLines[t]?.endTime && this.processedLines[t + 1]?.startTime && this.processedLines[t + 1].startTime > e && this.processedLines[t].endTime < e)
860
834
  return [
861
835
  this.processedLines[t].endTime,
862
- this.processedLines[t + 1].startTime
836
+ this.processedLines[t + 1].startTime,
837
+ t
863
838
  ];
864
839
  }
865
840
  /**
@@ -885,13 +860,15 @@ class ee extends EventTarget {
885
860
  setLyricLines(e) {
886
861
  this.lyricLines = e;
887
862
  const t = 750;
888
- this.processedLines = e.map((i, n, h) => {
863
+ this.processedLines = e.filter(
864
+ (i) => i.words.reduce((n, a) => n + a.word.trim().length, 0) > 0
865
+ ).map((i, n, a) => {
889
866
  if (i.isBG)
890
867
  return {
891
868
  ...i
892
869
  };
893
870
  {
894
- const s = h[n - 1], r = h[n - 2];
871
+ const s = a[n - 1], r = a[n - 2];
895
872
  if (s?.isBG && r) {
896
873
  if (r.endTime < i.startTime)
897
874
  return {
@@ -907,13 +884,13 @@ class ee extends EventTarget {
907
884
  ...i
908
885
  };
909
886
  }
910
- }), this.processedLines.forEach((i, n, h) => {
911
- const s = h[n + 1], r = i.words[i.words.length - 1];
912
- r && E(r) && (s ? s.startTime > i.endTime && (i.endTime = Math.min(i.endTime + 1500, s.startTime)) : i.endTime = i.endTime + 1500);
913
- }), this.processedLines.forEach((i, n, h) => {
887
+ }), this.processedLines.forEach((i, n, a) => {
888
+ const s = a[n + 1], r = i.words[i.words.length - 1];
889
+ r && P(r) && (s ? s.startTime > i.endTime && (i.endTime = Math.min(i.endTime + 1500, s.startTime)) : i.endTime = i.endTime + 1500);
890
+ }), this.processedLines.forEach((i, n, a) => {
914
891
  if (i.isBG)
915
892
  return;
916
- const s = h[n + 1];
893
+ const s = a[n + 1];
917
894
  s?.isBG && (s.startTime = Math.min(s.startTime, i.startTime));
918
895
  }), this.lyricLinesEl.forEach((i) => i.dispose()), this.lyricLinesEl = this.processedLines.map(
919
896
  (i) => new _(this, i)
@@ -936,50 +913,50 @@ class ee extends EventTarget {
936
913
  * @param reflow 是否进行重新布局(重新计算每行歌词大小)
937
914
  */
938
915
  calcLayout(e = !1) {
939
- e && (this.lyricLinesEl.forEach((l) => {
940
- const o = l.measureSize();
941
- this.lyricLinesSize.set(l, o), l.lineSize = o;
916
+ e && (this.lyricLinesEl.forEach((o) => {
917
+ const c = o.measureSize();
918
+ this.lyricLinesSize.set(o, c), o.lineSize = c;
942
919
  }), this.interludeDotsSize[0] = this.interludeDots.getElement().clientWidth, this.interludeDotsSize[1] = this.interludeDots.getElement().clientHeight);
943
920
  const t = 0.95;
944
921
  let n = -this.lyricLinesEl.slice(0, this.scrollToIndex).reduce(
945
- (l, o) => l + (o.getLine().isBG ? 0 : this.lyricLinesSize.get(o)?.[1] ?? 0),
922
+ (o, c) => o + (c.getLine().isBG ? 0 : this.lyricLinesSize.get(c)?.[1] ?? 0),
946
923
  0
947
924
  );
948
925
  if (this.alignAnchor === "bottom") {
949
926
  n += this.element.clientHeight / 2;
950
- const l = this.lyricLinesEl[this.scrollToIndex];
951
- if (l) {
952
- const o = this.lyricLinesSize.get(l)?.[1] ?? 0;
953
- n -= o / 2;
927
+ const o = this.lyricLinesEl[this.scrollToIndex];
928
+ if (o) {
929
+ const c = this.lyricLinesSize.get(o)?.[1] ?? 0;
930
+ n -= c / 2;
954
931
  }
955
932
  } else if (typeof this.alignAnchor == "number") {
956
933
  n += this.element.clientHeight * this.alignAnchor;
957
- const l = this.lyricLinesEl[this.scrollToIndex];
958
- if (l) {
959
- const o = this.lyricLinesSize.get(l)?.[1] ?? 0;
960
- n -= o / 2;
934
+ const o = this.lyricLinesEl[this.scrollToIndex];
935
+ if (o) {
936
+ const c = this.lyricLinesSize.get(o)?.[1] ?? 0;
937
+ n -= c / 2;
961
938
  }
962
939
  }
963
- const h = this.currentTime === 0 ? void 0 : this.getCurrentInterlude();
940
+ const a = this.getCurrentInterlude();
964
941
  let s = 0;
965
- if (h && (s = h[1] - h[0], s >= 5e3)) {
966
- const l = this.currentTime === 0 ? this.lyricLinesEl[0] : this.lyricLinesEl[this.scrollToIndex + 1];
967
- l && (n -= this.lyricLinesSize.get(l)?.[1] ?? 0);
942
+ if (a && (s = a[1] - a[0], s >= 5e3)) {
943
+ const o = this.lyricLinesEl[a[2] + 1];
944
+ o && (n -= this.lyricLinesSize.get(o)?.[1] ?? 0);
968
945
  }
969
946
  const r = Math.max(...this.bufferedLines);
970
- let a = 0;
971
- this.lyricLinesEl.forEach((l, o) => {
972
- const d = this.bufferedLines.has(o), m = d || o >= this.scrollToIndex && o < r, u = l.getLine();
973
- let p = 0;
974
- u.isDuet && (p = this.size[0] - (this.lyricLinesSize.get(l)?.[0] ?? 0)), o === this.scrollToIndex + 1 && s >= 5e3 && (this.interludeDots.setTransform(0, n), this.interludeDots.setInterlude(this.getCurrentInterlude()), n += this.interludeDotsSize[1]), l.setTransform(
975
- p,
947
+ let l = 0, h = !1;
948
+ this.lyricLinesEl.forEach((o, c) => {
949
+ const m = this.bufferedLines.has(c), p = m || c >= this.scrollToIndex && c < r, u = o.getLine();
950
+ let f = 0;
951
+ u.isDuet && (f = this.size[0] - (this.lyricLinesSize.get(o)?.[0] ?? 0)), !h && s >= 5e3 && (c === this.scrollToIndex && a?.[2] === -2 || c === this.scrollToIndex + 1) && (h = !0, this.interludeDots.setTransform(0, n), a && this.interludeDots.setInterlude([a[0], a[1]]), n += this.interludeDotsSize[1]), o.setTransform(
952
+ f,
976
953
  n,
977
- m ? 1 : t,
978
- d ? 1 : 1 / 3,
979
- this.enableBlur ? 3 * (m ? 0 : 1 + (o < this.scrollToIndex ? Math.abs(this.scrollToIndex - o) : Math.abs(o - Math.max(this.scrollToIndex, r)))) : 0,
954
+ p ? 1 : t,
955
+ m ? 1 : 1 / 3,
956
+ this.enableBlur ? 3 * (p ? 0 : 1 + (c < this.scrollToIndex ? Math.abs(this.scrollToIndex - c) : Math.abs(c - Math.max(this.scrollToIndex, r)))) : 0,
980
957
  e,
981
- a
982
- ), u.isBG && m ? n += this.lyricLinesSize.get(l)?.[1] ?? 0 : u.isBG || (n += this.lyricLinesSize.get(l)?.[1] ?? 0), n >= 0 && (a += 0.05);
958
+ l
959
+ ), u.isBG && p ? n += this.lyricLinesSize.get(o)?.[1] ?? 0 : u.isBG || (n += this.lyricLinesSize.get(o)?.[1] ?? 0), n >= 0 && (l += 0.05);
983
960
  });
984
961
  }
985
962
  /**
@@ -1023,30 +1000,30 @@ class ee extends EventTarget {
1023
1000
  */
1024
1001
  setCurrentTime(e, t = !1) {
1025
1002
  this.currentTime = e, this.element.style.setProperty("--amll-player-time", `${e}`);
1026
- const i = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), h = /* @__PURE__ */ new Set();
1003
+ const i = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
1027
1004
  this.hotLines.forEach((s) => {
1028
1005
  const r = this.processedLines[s];
1029
1006
  if (!r.isBG)
1030
1007
  if (r) {
1031
- const a = this.processedLines[s + 1];
1032
- if (a?.isBG) {
1033
- const l = Math.min(r.startTime, a?.startTime), o = Math.max(r.endTime, a?.endTime);
1034
- (l > e || o <= e) && (this.hotLines.delete(s), i.add(s), this.hotLines.delete(s + 1), i.add(s + 1), t && (this.lyricLinesEl[s].disable(), this.lyricLinesEl[s + 1].disable()));
1008
+ const l = this.processedLines[s + 1];
1009
+ if (l?.isBG) {
1010
+ const h = Math.min(r.startTime, l?.startTime), o = Math.max(r.endTime, l?.endTime);
1011
+ (h > e || o <= e) && (this.hotLines.delete(s), i.add(s), this.hotLines.delete(s + 1), i.add(s + 1), t && (this.lyricLinesEl[s].disable(), this.lyricLinesEl[s + 1].disable()));
1035
1012
  } else
1036
1013
  (r.startTime > e || r.endTime <= e) && (this.hotLines.delete(s), i.add(s), t && this.lyricLinesEl[s].disable());
1037
1014
  } else
1038
1015
  this.hotLines.delete(s), i.add(s), t && this.lyricLinesEl[s].disable();
1039
- }), this.processedLines.forEach((s, r, a) => {
1040
- !s.isBG && s.startTime <= e && s.endTime > e && (this.hotLines.has(r) || (this.hotLines.add(r), h.add(r), t && this.lyricLinesEl[r].enable(), a[r + 1]?.isBG && (this.hotLines.add(r + 1), h.add(r + 1), t && this.lyricLinesEl[r + 1].enable())));
1016
+ }), this.processedLines.forEach((s, r, l) => {
1017
+ !s.isBG && s.startTime <= e && s.endTime > e && (this.hotLines.has(r) || (this.hotLines.add(r), a.add(r), t && this.lyricLinesEl[r].enable(), l[r + 1]?.isBG && (this.hotLines.add(r + 1), a.add(r + 1), t && this.lyricLinesEl[r + 1].enable())));
1041
1018
  }), this.bufferedLines.forEach((s) => {
1042
1019
  this.hotLines.has(s) || (n.add(s), t && this.lyricLinesEl[s].disable());
1043
1020
  }), t ? (this.bufferedLines.size > 0 ? this.scrollToIndex = Math.min(...this.bufferedLines) : this.scrollToIndex = this.processedLines.findIndex(
1044
1021
  (s) => s.startTime >= e
1045
- ), this.bufferedLines.clear(), this.hotLines.forEach((s) => this.bufferedLines.add(s)), this.calcLayout(!0)) : (n.size > 0 || h.size > 0) && (n.size === 0 && h.size > 0 ? (h.forEach((s) => {
1022
+ ), this.bufferedLines.clear(), this.hotLines.forEach((s) => this.bufferedLines.add(s)), this.calcLayout(!0)) : (n.size > 0 || a.size > 0) && (n.size === 0 && a.size > 0 ? (a.forEach((s) => {
1046
1023
  this.bufferedLines.add(s), this.lyricLinesEl[s].enable();
1047
- }), this.scrollToIndex = Math.min(...this.bufferedLines)) : h.size === 0 && n.size > 0 ? N(n, this.bufferedLines) && this.bufferedLines.forEach((s) => {
1024
+ }), this.scrollToIndex = Math.min(...this.bufferedLines)) : a.size === 0 && n.size > 0 ? N(n, this.bufferedLines) && this.bufferedLines.forEach((s) => {
1048
1025
  this.hotLines.has(s) || (this.bufferedLines.delete(s), this.lyricLinesEl[s].disable());
1049
- }) : (h.forEach((s) => {
1026
+ }) : (a.forEach((s) => {
1050
1027
  this.bufferedLines.add(s), this.lyricLinesEl[s].enable();
1051
1028
  }), n.forEach((s) => {
1052
1029
  this.bufferedLines.delete(s), this.lyricLinesEl[s].disable();