@braccato/core 0.1.4 → 0.1.6
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/dist/index.js +531 -455
- package/package.json +8 -4
package/dist/index.js
CHANGED
|
@@ -1,241 +1,238 @@
|
|
|
1
|
-
import { LitElement as
|
|
1
|
+
import { LitElement as lt, unsafeCSS as X, html as dt } from "lit";
|
|
2
2
|
import { property as D } from "lit/decorators.js";
|
|
3
|
-
function
|
|
3
|
+
function B(t) {
|
|
4
4
|
if (!t) return 0;
|
|
5
5
|
if (typeof t == "number") return t;
|
|
6
6
|
const e = t.match(/^([\d.]+)(h|m|s|ms)$/);
|
|
7
7
|
if (e) {
|
|
8
|
-
const
|
|
9
|
-
if (o === "h") return Math.round(
|
|
10
|
-
if (o === "m") return Math.round(
|
|
11
|
-
if (o === "s") return Math.round(
|
|
12
|
-
if (o === "ms") return Math.round(
|
|
8
|
+
const n = Number.parseFloat(e[1]), o = e[2];
|
|
9
|
+
if (o === "h") return Math.round(n * 36e5);
|
|
10
|
+
if (o === "m") return Math.round(n * 6e4);
|
|
11
|
+
if (o === "s") return Math.round(n * 1e3);
|
|
12
|
+
if (o === "ms") return Math.round(n);
|
|
13
13
|
}
|
|
14
|
-
const
|
|
15
|
-
let
|
|
14
|
+
const r = t.split(":").map((n) => n.replace(/[^0-9.]/g, ""));
|
|
15
|
+
let a = 0;
|
|
16
16
|
try {
|
|
17
|
-
return
|
|
17
|
+
return r.length === 1 ? a = Number.parseFloat(r[0]) * 1e3 : r.length === 2 ? a = Number.parseInt(r[0], 10) * 6e4 + Number.parseFloat(r[1]) * 1e3 : r.length === 3 && (a = Number.parseInt(r[0], 10) * 36e5 + Number.parseInt(r[1], 10) * 6e4 + Number.parseFloat(r[2]) * 1e3), Math.round(a);
|
|
18
18
|
} catch {
|
|
19
19
|
return 0;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
for (const
|
|
26
|
-
if (
|
|
22
|
+
function I(t, e) {
|
|
23
|
+
const r = t.getAttribute(e);
|
|
24
|
+
if (r !== null) return r;
|
|
25
|
+
for (const a of t.attributes)
|
|
26
|
+
if (a.localName === e) return a.value;
|
|
27
27
|
return null;
|
|
28
28
|
}
|
|
29
|
-
function
|
|
29
|
+
function Y(t) {
|
|
30
30
|
const e = {
|
|
31
31
|
text: "",
|
|
32
|
-
begin:
|
|
33
|
-
end:
|
|
34
|
-
role:
|
|
32
|
+
begin: I(t, "begin") ? B(I(t, "begin")) : void 0,
|
|
33
|
+
end: I(t, "end") ? B(I(t, "end")) : void 0,
|
|
34
|
+
role: I(t, "role") ?? void 0,
|
|
35
35
|
children: []
|
|
36
36
|
};
|
|
37
|
-
for (const
|
|
38
|
-
if (
|
|
39
|
-
const
|
|
40
|
-
e.text +=
|
|
41
|
-
} else
|
|
37
|
+
for (const r of t.childNodes)
|
|
38
|
+
if (r.nodeType === 3) {
|
|
39
|
+
const a = r.textContent ?? "";
|
|
40
|
+
e.text += a, e.children.push({ text: a, children: [] });
|
|
41
|
+
} else r.nodeType === 1 && e.children.push(Y(r));
|
|
42
42
|
return e;
|
|
43
43
|
}
|
|
44
|
-
function $(t, e,
|
|
45
|
-
let
|
|
46
|
-
const
|
|
44
|
+
function $(t, e, r = !1) {
|
|
45
|
+
let a = "";
|
|
46
|
+
const n = [];
|
|
47
47
|
let o = !1;
|
|
48
|
-
for (const
|
|
49
|
-
const s =
|
|
50
|
-
if (
|
|
51
|
-
if (s && !
|
|
52
|
-
const c = $(
|
|
53
|
-
|
|
54
|
-
} else if (
|
|
55
|
-
const c =
|
|
56
|
-
|
|
57
|
-
startTimeMs:
|
|
58
|
-
durationMs:
|
|
48
|
+
for (const i of t) {
|
|
49
|
+
const s = r || i.role === "x-bg";
|
|
50
|
+
if (i.children.length > 0)
|
|
51
|
+
if (s && !r) {
|
|
52
|
+
const c = $(i.children, e, !0);
|
|
53
|
+
a += c.text, n.push(...c.parts), c.isWordSynced && (o = !0);
|
|
54
|
+
} else if (i.begin !== void 0 && i.end !== void 0) {
|
|
55
|
+
const c = i.children.map((f) => f.text).join("") || i.text;
|
|
56
|
+
n.push({
|
|
57
|
+
startTimeMs: i.begin,
|
|
58
|
+
durationMs: i.end - i.begin,
|
|
59
59
|
words: c,
|
|
60
60
|
isBackground: s || void 0
|
|
61
|
-
}),
|
|
61
|
+
}), a += c, o = !0;
|
|
62
62
|
} else {
|
|
63
|
-
const c = $(
|
|
64
|
-
|
|
63
|
+
const c = $(i.children, e, s);
|
|
64
|
+
a += c.text, n.push(...c.parts), c.isWordSynced && (o = !0);
|
|
65
65
|
}
|
|
66
|
-
else if (
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
startTimeMs:
|
|
70
|
-
durationMs:
|
|
71
|
-
words:
|
|
66
|
+
else if (i.text)
|
|
67
|
+
if (a += i.text, i.begin !== void 0 && i.end !== void 0)
|
|
68
|
+
n.push({
|
|
69
|
+
startTimeMs: i.begin,
|
|
70
|
+
durationMs: i.end - i.begin,
|
|
71
|
+
words: i.text,
|
|
72
72
|
isBackground: s || void 0
|
|
73
73
|
}), o = !0;
|
|
74
74
|
else {
|
|
75
|
-
const c =
|
|
76
|
-
|
|
75
|
+
const c = n[n.length - 1];
|
|
76
|
+
n.push({
|
|
77
77
|
startTimeMs: c ? c.startTimeMs + c.durationMs : e,
|
|
78
78
|
durationMs: 0,
|
|
79
|
-
words:
|
|
79
|
+
words: i.text,
|
|
80
80
|
isBackground: s || void 0
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
return o ? { parts:
|
|
84
|
+
return o ? { parts: n, text: a, isWordSynced: o } : { parts: [], text: a, isWordSynced: !1 };
|
|
85
85
|
}
|
|
86
|
-
function
|
|
86
|
+
function ut(t, e, r) {
|
|
87
87
|
if (t.length === 0) return t;
|
|
88
|
-
const
|
|
88
|
+
const a = [], n = (s, c) => ({
|
|
89
89
|
startTimeMs: s,
|
|
90
90
|
durationMs: c,
|
|
91
91
|
words: "",
|
|
92
92
|
parts: [],
|
|
93
93
|
isInstrumental: !0
|
|
94
94
|
});
|
|
95
|
-
t[0].startTimeMs >
|
|
95
|
+
t[0].startTimeMs > r && a.push(n(0, t[0].startTimeMs));
|
|
96
96
|
for (let s = 0; s < t.length; s++)
|
|
97
|
-
if (
|
|
98
|
-
const c = t[s].startTimeMs + t[s].durationMs,
|
|
99
|
-
|
|
97
|
+
if (a.push(t[s]), s < t.length - 1) {
|
|
98
|
+
const c = t[s].startTimeMs + t[s].durationMs, f = t[s + 1].startTimeMs - c;
|
|
99
|
+
f > r && a.push(n(c, f));
|
|
100
100
|
}
|
|
101
|
-
const o = t[t.length - 1],
|
|
102
|
-
return e -
|
|
103
|
-
}
|
|
104
|
-
function
|
|
105
|
-
const
|
|
106
|
-
if (!
|
|
107
|
-
const s =
|
|
108
|
-
let
|
|
109
|
-
const m = /* @__PURE__ */ new Map(),
|
|
110
|
-
...
|
|
111
|
-
...
|
|
101
|
+
const o = t[t.length - 1], i = o.startTimeMs + o.durationMs;
|
|
102
|
+
return e - i > r && a.push(n(i, e - i)), a;
|
|
103
|
+
}
|
|
104
|
+
function mt(t, e = {}) {
|
|
105
|
+
const r = t.replace(/\\"/g, '"'), a = new DOMParser().parseFromString(r, "text/xml"), n = a.querySelector("tt"), o = (n ? I(n, "lang") : null) ?? void 0, i = a.querySelector("body");
|
|
106
|
+
if (!i) return { lyrics: [], isWordSynced: !1, language: o };
|
|
107
|
+
const s = i.getAttribute("dur"), c = s ? B(s) : 0, f = i.querySelectorAll("p"), d = /* @__PURE__ */ new Map();
|
|
108
|
+
let l = !1;
|
|
109
|
+
const m = /* @__PURE__ */ new Map(), p = [
|
|
110
|
+
...a.querySelectorAll("agent"),
|
|
111
|
+
...a.getElementsByTagNameNS("http://www.w3.org/ns/ttml#metadata", "agent")
|
|
112
112
|
];
|
|
113
|
-
let
|
|
114
|
-
for (const
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
for (const
|
|
119
|
-
const
|
|
120
|
-
(
|
|
121
|
-
),
|
|
122
|
-
|
|
123
|
-
agent:
|
|
124
|
-
durationMs:
|
|
125
|
-
parts:
|
|
126
|
-
startTimeMs:
|
|
127
|
-
words:
|
|
128
|
-
key:
|
|
113
|
+
let w = 0;
|
|
114
|
+
for (const _ of p) {
|
|
115
|
+
const h = I(_, "id"), M = I(_, "type");
|
|
116
|
+
h && (m.has(h) || (M === "person" || M === "character" ? (w++, m.set(h, `v${w}`)) : m.set(h, "v1000")));
|
|
117
|
+
}
|
|
118
|
+
for (const _ of f) {
|
|
119
|
+
const h = B(I(_, "begin") ?? void 0), M = B(I(_, "end") ?? void 0), L = I(_, "key") ?? String(d.size), k = I(_, "agent") ?? void 0, S = k ? m.get(k) ?? k : void 0, y = Array.from(_.childNodes).filter((g) => g.nodeType === 1 || g.nodeType === 3).map(
|
|
120
|
+
(g) => g.nodeType === 1 ? Y(g) : { text: g.textContent ?? "", children: [] }
|
|
121
|
+
), u = $(y, h);
|
|
122
|
+
u.isWordSynced && (l = !0), d.set(L, {
|
|
123
|
+
agent: S,
|
|
124
|
+
durationMs: M - h,
|
|
125
|
+
parts: u.parts,
|
|
126
|
+
startTimeMs: h,
|
|
127
|
+
words: u.text,
|
|
128
|
+
key: L
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
|
-
const
|
|
132
|
-
for (const
|
|
133
|
-
const
|
|
134
|
-
if (!
|
|
135
|
-
const
|
|
136
|
-
for (const
|
|
137
|
-
const
|
|
138
|
-
if (
|
|
139
|
-
const
|
|
140
|
-
|
|
131
|
+
const b = a.querySelectorAll("translations");
|
|
132
|
+
for (const _ of b) {
|
|
133
|
+
const h = _.getAttribute("lang");
|
|
134
|
+
if (!h) continue;
|
|
135
|
+
const M = _.querySelectorAll("translation");
|
|
136
|
+
for (const L of M) {
|
|
137
|
+
const k = L.getAttribute("for"), S = L.querySelector("text"), y = S == null ? void 0 : S.textContent;
|
|
138
|
+
if (k && y) {
|
|
139
|
+
const u = d.get(k);
|
|
140
|
+
u && (u.translation = { text: y, lang: h });
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
const v =
|
|
145
|
-
for (const
|
|
146
|
-
const
|
|
147
|
-
for (const
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
), M = $(N, A.startTimeMs);
|
|
159
|
-
S += M.text, l.push(...M.parts);
|
|
144
|
+
const v = a.querySelectorAll("transliterations");
|
|
145
|
+
for (const _ of v) {
|
|
146
|
+
const h = _.querySelectorAll("transliteration");
|
|
147
|
+
for (const M of h) {
|
|
148
|
+
const L = M.querySelectorAll("text");
|
|
149
|
+
for (const k of L) {
|
|
150
|
+
const S = k.getAttribute("for");
|
|
151
|
+
if (!S) continue;
|
|
152
|
+
const y = d.get(S);
|
|
153
|
+
if (!y) continue;
|
|
154
|
+
const u = Array.from(k.childNodes).filter((A) => A.nodeType === 1 || A.nodeType === 3).map(
|
|
155
|
+
(A) => A.nodeType === 1 ? Y(A) : { text: A.textContent ?? "", children: [] }
|
|
156
|
+
), g = $(u, y.startTimeMs);
|
|
157
|
+
y.romanization = g.text, g.parts.length > 0 && (y.timedRomanization = g.parts);
|
|
160
158
|
}
|
|
161
|
-
A.romanization = S, l.length > 0 && (A.timedRomanization = l);
|
|
162
159
|
}
|
|
163
160
|
}
|
|
164
|
-
let P = Array.from(
|
|
165
|
-
const
|
|
166
|
-
return c > 0 && (P =
|
|
161
|
+
let P = Array.from(d.values());
|
|
162
|
+
const T = e.instrumentalGapMs ?? 5e3;
|
|
163
|
+
return c > 0 && (P = ut(P, c, T)), { lyrics: P, isWordSynced: l, language: o };
|
|
167
164
|
}
|
|
168
|
-
const
|
|
165
|
+
const ft = {
|
|
169
166
|
detect(t) {
|
|
170
167
|
return t.includes("<tt") && t.includes("</tt>");
|
|
171
168
|
},
|
|
172
169
|
parse(t, e = 0) {
|
|
173
|
-
return
|
|
170
|
+
return mt(t).lyrics;
|
|
174
171
|
}
|
|
175
|
-
},
|
|
176
|
-
function
|
|
172
|
+
}, pt = ["ti", "ar", "al", "au", "lr", "length", "by", "offset", "re", "tool", "ve", "#"];
|
|
173
|
+
function tt(t) {
|
|
177
174
|
if (!t) return 0;
|
|
178
175
|
if (typeof t == "number") return t;
|
|
179
176
|
const e = t.split(":");
|
|
180
|
-
let
|
|
177
|
+
let r = 0;
|
|
181
178
|
try {
|
|
182
179
|
if (e.length === 1)
|
|
183
|
-
|
|
180
|
+
r = Number.parseFloat(e[0]) * 1e3;
|
|
184
181
|
else if (e.length === 2) {
|
|
185
|
-
const
|
|
186
|
-
|
|
182
|
+
const a = Number.parseInt(e[0], 10), n = Number.parseFloat(e[1]);
|
|
183
|
+
r = a * 60 * 1e3 + n * 1e3;
|
|
187
184
|
} else if (e.length === 3) {
|
|
188
|
-
const
|
|
189
|
-
|
|
185
|
+
const a = Number.parseInt(e[0], 10), n = Number.parseInt(e[1], 10), o = Number.parseFloat(e[2]);
|
|
186
|
+
r = a * 3600 * 1e3 + n * 60 * 1e3 + o * 1e3;
|
|
190
187
|
}
|
|
191
|
-
return Math.round(
|
|
188
|
+
return Math.round(r);
|
|
192
189
|
} catch {
|
|
193
190
|
return 0;
|
|
194
191
|
}
|
|
195
192
|
}
|
|
196
|
-
function
|
|
197
|
-
var
|
|
198
|
-
const
|
|
199
|
-
`),
|
|
200
|
-
for (const
|
|
201
|
-
const s =
|
|
202
|
-
if (c &&
|
|
193
|
+
function ht(t, e) {
|
|
194
|
+
var r;
|
|
195
|
+
const a = t.split(`
|
|
196
|
+
`), n = [], o = {};
|
|
197
|
+
for (const i of a) {
|
|
198
|
+
const s = i.trim(), c = s.match(/^\[(\w+):(.*)\]$/);
|
|
199
|
+
if (c && pt.includes(c[1])) {
|
|
203
200
|
o[c[1]] = c[2];
|
|
204
201
|
continue;
|
|
205
202
|
}
|
|
206
|
-
const
|
|
207
|
-
for (const
|
|
208
|
-
|
|
209
|
-
if (
|
|
210
|
-
const m = s.replace(
|
|
211
|
-
let
|
|
212
|
-
m.split(
|
|
213
|
-
if (
|
|
214
|
-
let
|
|
215
|
-
|
|
203
|
+
const f = /\[(\d+:\d+\.\d+)\]/g, d = /<(\d+:\d+\.\d+)>/g, l = [];
|
|
204
|
+
for (const T of s.matchAll(f))
|
|
205
|
+
l.push(tt(T[1]));
|
|
206
|
+
if (l.length === 0) continue;
|
|
207
|
+
const m = s.replace(f, "").trim(), p = [];
|
|
208
|
+
let w = null, b = "";
|
|
209
|
+
m.split(d).forEach((T, _) => {
|
|
210
|
+
if (_ % 2 === 0) {
|
|
211
|
+
let h = T;
|
|
212
|
+
h.length > 0 && h[0] === " " && (h = h.substring(1)), h.length > 0 && h[h.length - 1] === " " && (h = h.substring(0, h.length - 1)), b += h, p.length > 0 && p[p.length - 1].startTimeMs && (p[p.length - 1].words += h);
|
|
216
213
|
} else {
|
|
217
|
-
const
|
|
218
|
-
|
|
214
|
+
const h = tt(T);
|
|
215
|
+
w !== null && p.length > 0 && (p[p.length - 1].durationMs = h - w), p.push({ startTimeMs: h, words: "", durationMs: 0 }), w = h;
|
|
219
216
|
}
|
|
220
217
|
});
|
|
221
|
-
const v = Math.min(...
|
|
222
|
-
|
|
218
|
+
const v = Math.min(...l), P = Math.max(...l) - v;
|
|
219
|
+
n.push({
|
|
223
220
|
startTimeMs: v,
|
|
224
|
-
words:
|
|
221
|
+
words: b.trim(),
|
|
225
222
|
durationMs: P,
|
|
226
|
-
parts:
|
|
223
|
+
parts: p.length > 0 ? p : void 0
|
|
227
224
|
});
|
|
228
225
|
}
|
|
229
|
-
for (let
|
|
230
|
-
const s = i
|
|
231
|
-
if (
|
|
232
|
-
const c = i
|
|
226
|
+
for (let i = 0; i < n.length; i++) {
|
|
227
|
+
const s = n[i];
|
|
228
|
+
if (i + 1 < n.length) {
|
|
229
|
+
const c = n[i + 1];
|
|
233
230
|
if (s.durationMs === 0 && (s.durationMs = Math.max(c.startTimeMs - s.startTimeMs, 0)), s.parts && s.parts.length > 0) {
|
|
234
|
-
let
|
|
235
|
-
for (const
|
|
236
|
-
|
|
237
|
-
const
|
|
238
|
-
|
|
231
|
+
let f = c.startTimeMs;
|
|
232
|
+
for (const l of s.parts)
|
|
233
|
+
f = Math.max(f, l.startTimeMs);
|
|
234
|
+
const d = s.parts[s.parts.length - 1];
|
|
235
|
+
d.durationMs = Math.max(c.startTimeMs - d.startTimeMs, 0), s.durationMs = Math.max(f - s.startTimeMs, 0);
|
|
239
236
|
}
|
|
240
237
|
} else if (s.durationMs === 0 && (s.durationMs = e - s.startTimeMs), s.parts && s.parts.length > 0) {
|
|
241
238
|
const c = s.parts[s.parts.length - 1];
|
|
@@ -243,130 +240,130 @@ function mt(t, e) {
|
|
|
243
240
|
}
|
|
244
241
|
}
|
|
245
242
|
if (o.offset) {
|
|
246
|
-
let
|
|
247
|
-
Number.isNaN(
|
|
248
|
-
for (const s of
|
|
249
|
-
s.startTimeMs -=
|
|
250
|
-
c.startTimeMs -=
|
|
243
|
+
let i = Number(o.offset);
|
|
244
|
+
Number.isNaN(i) && (i = 0), i = i * 1e3;
|
|
245
|
+
for (const s of n)
|
|
246
|
+
s.startTimeMs -= i, (r = s.parts) == null || r.forEach((c) => {
|
|
247
|
+
c.startTimeMs -= i;
|
|
251
248
|
});
|
|
252
249
|
}
|
|
253
|
-
return
|
|
250
|
+
return n;
|
|
254
251
|
}
|
|
255
|
-
function
|
|
256
|
-
for (const
|
|
257
|
-
if (
|
|
258
|
-
for (let
|
|
259
|
-
const o =
|
|
260
|
-
if (o.words === " " &&
|
|
261
|
-
const s = o.durationMs -
|
|
252
|
+
function bt(t) {
|
|
253
|
+
for (const a of t)
|
|
254
|
+
if (a.parts)
|
|
255
|
+
for (let n = 1; n < a.parts.length; n++) {
|
|
256
|
+
const o = a.parts[n], i = a.parts[n - 1];
|
|
257
|
+
if (o.words === " " && i.words !== " ") {
|
|
258
|
+
const s = o.durationMs - i.durationMs;
|
|
262
259
|
if (Math.abs(s) <= 15 || o.durationMs <= 100) {
|
|
263
260
|
const c = o.durationMs;
|
|
264
|
-
|
|
261
|
+
i.durationMs += c, o.durationMs -= c, o.startTimeMs += c;
|
|
265
262
|
}
|
|
266
263
|
}
|
|
267
264
|
}
|
|
268
|
-
let e = 0,
|
|
269
|
-
for (const
|
|
270
|
-
if (!(!
|
|
271
|
-
for (let
|
|
272
|
-
const o =
|
|
273
|
-
o.words !== " " && (o.durationMs <= 100 && e++,
|
|
265
|
+
let e = 0, r = 0;
|
|
266
|
+
for (const a of t)
|
|
267
|
+
if (!(!a.parts || a.parts.length === 0))
|
|
268
|
+
for (let n = 0; n < a.parts.length - 2; n++) {
|
|
269
|
+
const o = a.parts[n];
|
|
270
|
+
o.words !== " " && (o.durationMs <= 100 && e++, r++);
|
|
274
271
|
}
|
|
275
|
-
if (
|
|
276
|
-
for (let
|
|
277
|
-
const
|
|
278
|
-
if (!(!
|
|
279
|
-
for (let o = 0; o <
|
|
280
|
-
const
|
|
281
|
-
if (
|
|
272
|
+
if (r > 0 && e / r > 0.5)
|
|
273
|
+
for (let a = 0; a < t.length; a++) {
|
|
274
|
+
const n = t[a];
|
|
275
|
+
if (!(!n.parts || n.parts.length === 0))
|
|
276
|
+
for (let o = 0; o < n.parts.length; o++) {
|
|
277
|
+
const i = n.parts[o];
|
|
278
|
+
if (i.words !== " " && i.durationMs <= 400) {
|
|
282
279
|
let s = null;
|
|
283
|
-
o + 1 <
|
|
280
|
+
o + 1 < n.parts.length ? s = n.parts[o + 1] : a + 1 < t.length && t[a + 1].parts && t[a + 1].parts.length > 0 && (s = t[a + 1].parts[0]), s === null ? i.durationMs = 300 : s.words === " " ? (i.durationMs += s.durationMs, s.startTimeMs += s.durationMs, s.durationMs = 0) : i.durationMs = s.startTimeMs - i.startTimeMs;
|
|
284
281
|
}
|
|
285
282
|
}
|
|
286
283
|
}
|
|
287
284
|
}
|
|
288
|
-
const
|
|
285
|
+
const gt = {
|
|
289
286
|
detect(t) {
|
|
290
287
|
return /\[\d+:\d+\.\d+\]/.test(t);
|
|
291
288
|
},
|
|
292
289
|
parse(t, e = 0) {
|
|
293
|
-
const
|
|
294
|
-
return
|
|
290
|
+
const r = ht(t, e);
|
|
291
|
+
return bt(r), r;
|
|
295
292
|
}
|
|
296
293
|
};
|
|
297
|
-
function
|
|
294
|
+
function et(t) {
|
|
298
295
|
const e = t.trim().match(/^(\d+):(\d+):(\d+)[,.](\d+)$/);
|
|
299
296
|
if (!e) return 0;
|
|
300
|
-
const
|
|
301
|
-
return
|
|
297
|
+
const r = Number.parseInt(e[1], 10), a = Number.parseInt(e[2], 10), n = Number.parseInt(e[3], 10), o = Number.parseInt(e[4].padEnd(3, "0").slice(0, 3), 10);
|
|
298
|
+
return r * 36e5 + a * 6e4 + n * 1e3 + o;
|
|
302
299
|
}
|
|
303
|
-
const
|
|
300
|
+
const yt = {
|
|
304
301
|
detect(t) {
|
|
305
302
|
return /\d+\r?\n\d{2}:\d{2}:\d{2}[,.]\d+ --> \d{2}:\d{2}:\d{2}[,.]\d+/.test(t);
|
|
306
303
|
},
|
|
307
304
|
parse(t, e = 0) {
|
|
308
|
-
const
|
|
309
|
-
for (const
|
|
310
|
-
const o =
|
|
305
|
+
const r = t.trim().split(/\r?\n\r?\n/), a = [];
|
|
306
|
+
for (const n of r) {
|
|
307
|
+
const o = n.split(/\r?\n/);
|
|
311
308
|
if (o.length < 2) continue;
|
|
312
|
-
const
|
|
313
|
-
if (!
|
|
314
|
-
const [s, c] =
|
|
309
|
+
const i = o.find((p) => p.includes("-->"));
|
|
310
|
+
if (!i) continue;
|
|
311
|
+
const [s, c] = i.split("-->").map((p) => p.trim()), f = et(s), d = et(c), l = o.indexOf(i), m = o.slice(l + 1).join(`
|
|
315
312
|
`).replace(/<[^>]+>/g, "").trim();
|
|
316
|
-
m &&
|
|
317
|
-
startTimeMs:
|
|
313
|
+
m && a.push({
|
|
314
|
+
startTimeMs: f,
|
|
318
315
|
words: m,
|
|
319
|
-
durationMs:
|
|
316
|
+
durationMs: d - f
|
|
320
317
|
});
|
|
321
318
|
}
|
|
322
|
-
return
|
|
319
|
+
return a;
|
|
323
320
|
}
|
|
324
|
-
},
|
|
321
|
+
}, ct = {
|
|
325
322
|
detect(t) {
|
|
326
323
|
return !0;
|
|
327
324
|
},
|
|
328
325
|
parse(t, e = 0) {
|
|
329
326
|
return t.split(`
|
|
330
|
-
`).map((
|
|
327
|
+
`).map((r) => ({
|
|
331
328
|
startTimeMs: 0,
|
|
332
|
-
words:
|
|
329
|
+
words: r,
|
|
333
330
|
durationMs: 0
|
|
334
331
|
}));
|
|
335
332
|
}
|
|
336
|
-
},
|
|
333
|
+
}, St = {
|
|
337
334
|
detect(t) {
|
|
338
335
|
return /\[\d+,\d+\]/.test(t) && /\(\d+,\d+\)/.test(t);
|
|
339
336
|
},
|
|
340
337
|
parse(t, e = 0) {
|
|
341
|
-
const
|
|
342
|
-
`),
|
|
343
|
-
for (const
|
|
344
|
-
const o =
|
|
338
|
+
const r = t.split(`
|
|
339
|
+
`), a = [];
|
|
340
|
+
for (const n of r) {
|
|
341
|
+
const o = n.trim().match(/^\[(\d+),(\d+)\](.*)$/);
|
|
345
342
|
if (!o) continue;
|
|
346
|
-
const
|
|
347
|
-
let
|
|
348
|
-
const
|
|
349
|
-
for (const m of c.matchAll(
|
|
350
|
-
const
|
|
351
|
-
|
|
343
|
+
const i = Number.parseInt(o[1], 10), s = Number.parseInt(o[2], 10), c = o[3], f = [];
|
|
344
|
+
let d = "";
|
|
345
|
+
const l = /([^(]*)\((\d+),(\d+)\)/g;
|
|
346
|
+
for (const m of c.matchAll(l)) {
|
|
347
|
+
const p = m[1], w = Number.parseInt(m[2], 10), b = Number.parseInt(m[3], 10);
|
|
348
|
+
d += p, f.push({ startTimeMs: w, words: p, durationMs: b });
|
|
352
349
|
}
|
|
353
|
-
|
|
354
|
-
startTimeMs:
|
|
355
|
-
words:
|
|
350
|
+
a.push({
|
|
351
|
+
startTimeMs: i,
|
|
352
|
+
words: d,
|
|
356
353
|
durationMs: s,
|
|
357
|
-
parts:
|
|
354
|
+
parts: f.length > 0 ? f : void 0
|
|
358
355
|
});
|
|
359
356
|
}
|
|
360
|
-
return
|
|
357
|
+
return a;
|
|
361
358
|
}
|
|
362
|
-
},
|
|
363
|
-
function
|
|
364
|
-
for (const e of
|
|
359
|
+
}, vt = [ft, gt, yt, St, ct];
|
|
360
|
+
function wt(t) {
|
|
361
|
+
for (const e of vt)
|
|
365
362
|
if (e.detect(t)) return e;
|
|
366
|
-
return
|
|
363
|
+
return ct;
|
|
367
364
|
}
|
|
368
|
-
const
|
|
369
|
-
function
|
|
365
|
+
const Tt = 25e3;
|
|
366
|
+
function _t() {
|
|
370
367
|
return {
|
|
371
368
|
skipScrolls: 0,
|
|
372
369
|
skipScrollsDecayTimes: [],
|
|
@@ -378,38 +375,38 @@ function vt() {
|
|
|
378
375
|
queuedScroll: !1
|
|
379
376
|
};
|
|
380
377
|
}
|
|
381
|
-
function
|
|
378
|
+
function Mt(t) {
|
|
382
379
|
t.skipScrollsDecayTimes = [], t.doneFirstInstantScroll = !1, t.queuedScroll = !1;
|
|
383
380
|
}
|
|
384
|
-
function
|
|
385
|
-
t.wasUserScrolling = !0, t.scrollResumeTime = Date.now() +
|
|
381
|
+
function rt(t) {
|
|
382
|
+
t.wasUserScrolling = !0, t.scrollResumeTime = Date.now() + Tt;
|
|
386
383
|
}
|
|
387
|
-
function
|
|
384
|
+
function at(t) {
|
|
388
385
|
t.scrollResumeTime = 0;
|
|
389
386
|
}
|
|
390
|
-
function
|
|
387
|
+
function At(t) {
|
|
391
388
|
return t.scrollResumeTime > Date.now();
|
|
392
389
|
}
|
|
393
|
-
function
|
|
394
|
-
let
|
|
395
|
-
for (;
|
|
390
|
+
function Et(t, e) {
|
|
391
|
+
let r = 0;
|
|
392
|
+
for (; r < t.skipScrollsDecayTimes.length && !(t.skipScrollsDecayTimes[r] > e); r++)
|
|
396
393
|
;
|
|
397
|
-
t.skipScrollsDecayTimes = t.skipScrollsDecayTimes.slice(
|
|
394
|
+
t.skipScrollsDecayTimes = t.skipScrollsDecayTimes.slice(r), t.skipScrolls -= r, t.skipScrolls < 1 && (t.skipScrolls = 1);
|
|
398
395
|
}
|
|
399
|
-
const
|
|
400
|
-
function
|
|
396
|
+
const W = "braccato--animating", G = "braccato--pre-animating", q = "braccato--paused", nt = "braccato--active", Ct = "braccato--user-scrolling", Lt = 0.5, xt = 0.5, Nt = 0.62, kt = 0.37, It = 150, Q = /* @__PURE__ */ new Map();
|
|
397
|
+
function Dt(t) {
|
|
401
398
|
return t ? t.endsWith("ms") ? Number.parseFloat(t.slice(0, -2)) : t.endsWith("s") ? Number.parseFloat(t.slice(0, -1)) * 1e3 : 0 : 0;
|
|
402
399
|
}
|
|
403
|
-
function
|
|
404
|
-
let
|
|
405
|
-
return
|
|
400
|
+
function U(t, e) {
|
|
401
|
+
let r = Q.get(e);
|
|
402
|
+
return r === void 0 && (r = Dt(getComputedStyle(t).getPropertyValue(e)), Q.set(e, r)), r;
|
|
406
403
|
}
|
|
407
|
-
function
|
|
404
|
+
function it(t) {
|
|
408
405
|
t.offsetHeight;
|
|
409
406
|
}
|
|
410
|
-
function
|
|
407
|
+
function Rt() {
|
|
411
408
|
return {
|
|
412
|
-
scroll:
|
|
409
|
+
scroll: _t(),
|
|
413
410
|
selectedElementIndex: 0,
|
|
414
411
|
lastTime: 0,
|
|
415
412
|
lastPlayState: !1,
|
|
@@ -417,152 +414,229 @@ function Dt() {
|
|
|
417
414
|
lastActiveElements: []
|
|
418
415
|
};
|
|
419
416
|
}
|
|
420
|
-
function
|
|
421
|
-
|
|
417
|
+
function Pt(t) {
|
|
418
|
+
Mt(t.scroll), t.lastActiveElements = [], Q.clear();
|
|
422
419
|
}
|
|
423
|
-
function
|
|
424
|
-
const
|
|
425
|
-
let { currentTime:
|
|
420
|
+
function zt(t, e) {
|
|
421
|
+
const r = Date.now();
|
|
422
|
+
let { currentTime: a, isPlaying: n, smoothScroll: o } = e;
|
|
426
423
|
const {
|
|
427
|
-
eventCreationTime:
|
|
424
|
+
eventCreationTime: i,
|
|
428
425
|
lyricsData: s,
|
|
429
426
|
scrollContainer: c,
|
|
430
|
-
scrollPosRatio:
|
|
431
|
-
endingThreshold:
|
|
432
|
-
earlyScrollConsider:
|
|
433
|
-
queueScrollMs: m =
|
|
427
|
+
scrollPosRatio: f = kt,
|
|
428
|
+
endingThreshold: d = xt,
|
|
429
|
+
earlyScrollConsider: l = Nt,
|
|
430
|
+
queueScrollMs: m = It
|
|
434
431
|
} = e;
|
|
435
|
-
if (
|
|
436
|
-
const
|
|
437
|
-
t.lastTime =
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
const { lines:
|
|
441
|
-
P === "richsync" ?
|
|
442
|
-
const
|
|
443
|
-
let
|
|
444
|
-
const
|
|
445
|
-
let
|
|
446
|
-
for (let
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
const
|
|
450
|
-
if (
|
|
451
|
-
|
|
452
|
-
const
|
|
453
|
-
if (
|
|
454
|
-
|
|
455
|
-
const
|
|
456
|
-
if (
|
|
457
|
-
for (const
|
|
458
|
-
|
|
459
|
-
|
|
432
|
+
if (a === 0 && !n) return;
|
|
433
|
+
const p = Math.abs(a - t.lastTime - (i - t.lastEventCreationTime) / 1e3) > Lt;
|
|
434
|
+
t.lastTime = a, t.lastPlayState = n, t.lastEventCreationTime = i;
|
|
435
|
+
const w = n ? r - i : 0;
|
|
436
|
+
a += w / 1e3;
|
|
437
|
+
const { lines: b, container: v, syncType: P } = s;
|
|
438
|
+
P === "richsync" ? a += U(v, "--braccato-richsync-timing-offset") / 1e3 : a += U(v, "--braccato-timing-offset") / 1e3;
|
|
439
|
+
const T = a + U(v, "--braccato-scroll-timing-offset") / 1e3, _ = c.getBoundingClientRect().height;
|
|
440
|
+
let h = c.scrollTop;
|
|
441
|
+
const M = [], L = [];
|
|
442
|
+
let k = p;
|
|
443
|
+
for (let y = 0; y < b.length; y++) {
|
|
444
|
+
const u = b[y], g = u.time, A = y + 1 < b.length ? b[y + 1].time : Number.POSITIVE_INFINITY;
|
|
445
|
+
T >= g - l && (T < A || T < g + u.duration) ? (M.push(u), !t.lastActiveElements.includes(u) && T >= g && (k = !0), t.selectedElementIndex = y, u.isScrolled || (u.element.classList.add(nt), u.isScrolled = !0)) : u.isScrolled && (u.element.classList.remove(nt), u.isScrolled = !1);
|
|
446
|
+
const x = n ? 2 : 0, N = Math.max(A, g + u.duration + 0.05);
|
|
447
|
+
if (a + x >= g && a < N) {
|
|
448
|
+
u.isSelected = !0;
|
|
449
|
+
const O = a - g, z = (r - u.animationStartTimeMs) / 1e3 - O;
|
|
450
|
+
if (u.accumulatedOffsetMs = u.accumulatedOffsetMs / 1.08, u.accumulatedOffsetMs += z * 1e3 * 0.4, u.isAnimating && Math.abs(u.accumulatedOffsetMs) > 100 && n && (u.isAnimating = !1), n !== u.isAnimationPlayStatePlaying) {
|
|
451
|
+
u.isAnimationPlayStatePlaying = n;
|
|
452
|
+
const J = [u, ...u.parts];
|
|
453
|
+
if (n) {
|
|
454
|
+
for (const F of J)
|
|
455
|
+
F.element.classList.remove(q);
|
|
456
|
+
u.isAnimating = !1;
|
|
460
457
|
} else
|
|
461
|
-
for (const
|
|
462
|
-
|
|
458
|
+
for (const F of J)
|
|
459
|
+
F.animationStartTimeMs > r ? (F.element.classList.remove(W), F.element.classList.remove(G)) : F.element.classList.add(q);
|
|
463
460
|
}
|
|
464
|
-
|
|
465
|
-
} else if (
|
|
466
|
-
const
|
|
467
|
-
for (const
|
|
468
|
-
|
|
469
|
-
|
|
461
|
+
u.isAnimating || L.push(u);
|
|
462
|
+
} else if (u.isSelected) {
|
|
463
|
+
const O = [u, ...u.parts];
|
|
464
|
+
for (const z of O)
|
|
465
|
+
z.element.style.setProperty("--braccato-swipe-delay", ""), z.element.style.setProperty("--braccato-anim-delay", ""), z.element.classList.remove(W), z.element.classList.remove(G), z.element.classList.remove(q), z.animationStartTimeMs = Number.POSITIVE_INFINITY;
|
|
466
|
+
u.isSelected = !1, u.isAnimating = !1;
|
|
470
467
|
}
|
|
471
468
|
}
|
|
472
|
-
if (
|
|
473
|
-
for (const
|
|
474
|
-
const
|
|
475
|
-
for (const
|
|
476
|
-
const
|
|
477
|
-
|
|
469
|
+
if (L.length > 0) {
|
|
470
|
+
for (const y of L) {
|
|
471
|
+
const u = [y, ...y.parts];
|
|
472
|
+
for (const g of u) {
|
|
473
|
+
const A = a - g.time;
|
|
474
|
+
g.element.classList.remove(W), g.element.classList.remove(q), g.element.style.setProperty("--braccato-swipe-delay", `${-A - g.duration * 0.1}s`), g.element.style.setProperty("--braccato-anim-delay", `${-A}s`), g.element.classList.add(G);
|
|
478
475
|
}
|
|
479
476
|
}
|
|
480
|
-
|
|
481
|
-
for (const
|
|
482
|
-
const
|
|
483
|
-
for (const
|
|
484
|
-
const
|
|
485
|
-
|
|
477
|
+
it(L[0].element);
|
|
478
|
+
for (const y of L) {
|
|
479
|
+
const u = [y, ...y.parts];
|
|
480
|
+
for (const g of u) {
|
|
481
|
+
const A = a - g.time;
|
|
482
|
+
g.element.classList.add(W), g.animationStartTimeMs = r - A * 1e3;
|
|
486
483
|
}
|
|
487
|
-
|
|
484
|
+
y.isAnimating = !0, y.lastAnimSetupAt = r, y.isAnimationPlayStatePlaying = !0, y.accumulatedOffsetMs = 0;
|
|
488
485
|
}
|
|
489
486
|
}
|
|
490
|
-
const
|
|
491
|
-
if (
|
|
492
|
-
|
|
493
|
-
const
|
|
494
|
-
let
|
|
495
|
-
if (
|
|
496
|
-
if (
|
|
497
|
-
if (
|
|
487
|
+
const S = t.scroll;
|
|
488
|
+
if (S.scrollResumeTime < r || S.scrollPos === -1) {
|
|
489
|
+
M.length === 0 && M.push(b[0]), t.lastActiveElements = M.filter((N) => T >= N.time);
|
|
490
|
+
const y = _ * f, u = M[M.length - 1], g = M.filter((N, O) => T < N.time + N.duration - d || O === M.length - 1).map((N) => N.position + N.height / 2);
|
|
491
|
+
let x = g.reduce((N, O) => N + O, 0) / g.length - y;
|
|
492
|
+
if (x = Math.min(x, M[0].position), x = Math.max(x, u.position - _ + u.height), x = Math.min(x, u.position), x = Math.max(0, x), h === 0 && !S.doneFirstInstantScroll && (o = !1, S.doneFirstInstantScroll = !0, S.nextScrollAllowedTime = 0), S.wasUserScrolling || k || S.queuedScroll)
|
|
493
|
+
if (r > S.nextScrollAllowedTime) {
|
|
494
|
+
if (S.queuedScroll = !1, o && Math.abs(h - x) > 2) {
|
|
498
495
|
v.style.transitionTimingFunction = "", v.style.transitionProperty = "", v.style.transitionDuration = "";
|
|
499
|
-
const
|
|
500
|
-
v.style.transition = "none", v.style.transform = `translate(0px, ${-(
|
|
496
|
+
const N = U(v, "transition-duration");
|
|
497
|
+
v.style.transition = "none", v.style.transform = `translate(0px, ${-(h - x)}px)`, it(v), v.style.transition = "", v.style.transform = "translate(0px, 0px)", S.nextScrollAllowedTime = N + r + 20;
|
|
501
498
|
}
|
|
502
|
-
|
|
503
|
-
} else (
|
|
499
|
+
h = x, S.scrollPos = h, c.scrollTop = h, S.skipScrolls += 1, S.skipScrollsDecayTimes.push(r + 2e3);
|
|
500
|
+
} else (S.nextScrollAllowedTime - r < m || p) && (S.queuedScroll = !0);
|
|
504
501
|
}
|
|
505
|
-
|
|
502
|
+
S.wasUserScrolling && S.scrollResumeTime < r && (v.classList.remove(Ct), S.wasUserScrolling = !1), Et(S, r);
|
|
506
503
|
}
|
|
507
|
-
const
|
|
508
|
-
function
|
|
509
|
-
|
|
504
|
+
const C = "http://www.w3.org/2000/svg", Ot = "braccato--instrumental", Ft = "braccato--instrumental-icon", Bt = "braccato--instrumental-bg", Wt = "braccato--instrumental-fill", qt = "braccato--wave-clip", Ut = "braccato--wave-rect", $t = "braccato--wave-path", st = "M10 21q-1.65 0-2.825-1.175T6 17t1.175-2.825T10 13q.575 0 1.063.138t.937.412V4q0-.425.288-.712T13 3h4q.425 0 .713.288T18 4v2q0 .425-.288.713T17 7h-3v10q0 1.65-1.175 2.825T10 21";
|
|
505
|
+
function Gt(t, e) {
|
|
506
|
+
const r = document.createElement("div");
|
|
507
|
+
r.classList.add(Ot), r.style.setProperty("--braccato-duration", `${t}ms`);
|
|
508
|
+
const a = document.createElementNS(C, "svg");
|
|
509
|
+
a.classList.add(Ft), a.setAttribute("viewBox", "0 0 24 24");
|
|
510
|
+
const n = document.createElementNS(C, "defs"), o = `braccato-glow-${e}`, i = `braccato-wave-clip-${e}`, s = document.createElementNS(C, "filter");
|
|
511
|
+
s.setAttribute("id", o), s.setAttribute("x", "-100%"), s.setAttribute("y", "-100%"), s.setAttribute("width", "300%"), s.setAttribute("height", "300%");
|
|
512
|
+
const c = document.createElementNS(C, "feGaussianBlur");
|
|
513
|
+
c.setAttribute("in", "SourceGraphic"), c.setAttribute("stdDeviation", "5"), c.setAttribute("result", "blur"), s.appendChild(c);
|
|
514
|
+
const f = document.createElementNS(C, "feColorMatrix");
|
|
515
|
+
f.setAttribute("in", "blur"), f.setAttribute("type", "matrix"), f.setAttribute("values", "1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0.6 0"), f.setAttribute("result", "fadedBlur"), s.appendChild(f);
|
|
516
|
+
const d = document.createElementNS(C, "feMerge"), l = document.createElementNS(C, "feMergeNode");
|
|
517
|
+
l.setAttribute("in", "fadedBlur"), d.appendChild(l);
|
|
518
|
+
const m = document.createElementNS(C, "feMergeNode");
|
|
519
|
+
m.setAttribute("in", "SourceGraphic"), d.appendChild(m), s.appendChild(d), n.appendChild(s);
|
|
520
|
+
const p = document.createElementNS(C, "clipPath");
|
|
521
|
+
p.setAttribute("id", i), p.classList.add(qt);
|
|
522
|
+
const w = document.createElementNS(C, "path");
|
|
523
|
+
w.classList.add(Ut), w.setAttribute("d", "M -4 3.9 L 30 3.9 L 30 30 L -4 30 Z"), p.appendChild(w);
|
|
524
|
+
const b = document.createElementNS(C, "path");
|
|
525
|
+
b.classList.add($t), b.setAttribute("d", "M -4 3 Q 1 2 5 3 Q 10 4 14 3 Q 18 2 22 3 Q 26 4 30 3 L 30 4 L -4 4 Z"), p.appendChild(b), n.appendChild(p), a.appendChild(n);
|
|
526
|
+
const v = document.createElementNS(C, "path");
|
|
527
|
+
v.classList.add(Bt), v.setAttribute("d", st), a.appendChild(v);
|
|
528
|
+
const P = document.createElementNS(C, "g");
|
|
529
|
+
P.setAttribute("filter", `url(#${o})`);
|
|
530
|
+
const T = document.createElementNS(C, "path");
|
|
531
|
+
return T.classList.add(Wt), T.setAttribute("clip-path", `url(#${i})`), T.setAttribute("d", st), P.appendChild(T), a.appendChild(P), r.appendChild(a), r;
|
|
532
|
+
}
|
|
533
|
+
const Ht = /[\p{Script=Arabic}\p{Script=Hebrew}\p{Script=Syriac}\p{Script=Thaana}]/u;
|
|
534
|
+
function j(t) {
|
|
535
|
+
return Ht.test(t);
|
|
536
|
+
}
|
|
537
|
+
const Yt = /[\s\p{Dash_Punctuation}]/u, Qt = /\s+$/, jt = 5;
|
|
538
|
+
function Vt(t) {
|
|
539
|
+
const e = t.replace(Qt, "");
|
|
540
|
+
return e.length <= jt ? !1 : !Yt.test(e);
|
|
541
|
+
}
|
|
542
|
+
function Zt(t) {
|
|
543
|
+
try {
|
|
544
|
+
const e = new Intl.Segmenter(void 0, { granularity: "word" }), r = Array.from(e.segment(t), (n) => n.segment);
|
|
545
|
+
if (r.length > 1) return r;
|
|
546
|
+
const a = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
547
|
+
return Array.from(a.segment(t), (n) => n.segment);
|
|
548
|
+
} catch {
|
|
549
|
+
return Array.from(t);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
function Kt(t) {
|
|
553
|
+
if (!Vt(t.words))
|
|
554
|
+
return [{ ...t, isWrapAfter: !1 }];
|
|
555
|
+
const e = Zt(t.words);
|
|
556
|
+
if (e.length <= 1)
|
|
557
|
+
return [{ ...t, isWrapAfter: !1 }];
|
|
558
|
+
const r = t.durationMs / e.length;
|
|
559
|
+
return e.map((a, n) => ({
|
|
560
|
+
startTimeMs: t.startTimeMs + n * r,
|
|
561
|
+
durationMs: r,
|
|
562
|
+
words: a,
|
|
563
|
+
isBackground: t.isBackground,
|
|
564
|
+
isWrapAfter: n < e.length - 1
|
|
565
|
+
}));
|
|
566
|
+
}
|
|
567
|
+
const Jt = "braccato--line", Xt = "braccato--word", te = "braccato--break", V = "braccato-background-lyric", Z = "braccato-rtl", ee = "braccato-zero-dur-animate", re = "braccato--romanized", ae = "braccato--translated", ne = /[\s\p{Dash_Punctuation}]/u;
|
|
568
|
+
function ie(t, e) {
|
|
569
|
+
for (let r = e - 1; r >= 0; r--)
|
|
570
|
+
if (!t[r].isInstrumental && t[r].agent) return t[r].agent;
|
|
571
|
+
for (let r = e + 1; r < t.length; r++)
|
|
572
|
+
if (!t[r].isInstrumental && t[r].agent) return t[r].agent;
|
|
573
|
+
}
|
|
574
|
+
function se(t, e) {
|
|
575
|
+
var r, a;
|
|
576
|
+
for (let n = e - 1; n >= 0; n--)
|
|
577
|
+
if (!t[n].isInstrumental && ((r = t[n].words) != null && r.trim())) return j(t[n].words);
|
|
578
|
+
for (let n = e + 1; n < t.length; n++)
|
|
579
|
+
if (!t[n].isInstrumental && ((a = t[n].words) != null && a.trim())) return j(t[n].words);
|
|
580
|
+
return !1;
|
|
510
581
|
}
|
|
511
|
-
const zt = "braccato--line", Ot = "braccato--word", Ft = "braccato--break", B = "braccato-background-lyric", at = "braccato-rtl", Ut = "braccato-zero-dur-animate", qt = "braccato--romanized", Wt = "braccato--translated";
|
|
512
582
|
function H(t, e) {
|
|
513
|
-
const
|
|
514
|
-
|
|
583
|
+
const r = document.createElement("span");
|
|
584
|
+
r.classList.add(te), r.style.order = String(e), t.appendChild(r);
|
|
515
585
|
}
|
|
516
|
-
function
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
const o = () => {
|
|
586
|
+
function oe(t, e) {
|
|
587
|
+
let r = [], a = !1;
|
|
588
|
+
const n = () => {
|
|
520
589
|
if (r.length > 0) {
|
|
521
|
-
const
|
|
522
|
-
for (const
|
|
523
|
-
|
|
590
|
+
const o = document.createElement("span");
|
|
591
|
+
for (const i of r) o.appendChild(i);
|
|
592
|
+
a && o.classList.add(V), t.appendChild(o), r = [];
|
|
524
593
|
}
|
|
525
594
|
};
|
|
526
|
-
for (const
|
|
527
|
-
const
|
|
528
|
-
|
|
595
|
+
for (const o of e) {
|
|
596
|
+
const i = o.classList.contains(V);
|
|
597
|
+
a !== i && (n(), a = i), r.push(o);
|
|
598
|
+
const s = o.textContent ?? "", c = s.length > 0 && ne.test(s[s.length - 1]), f = o.dataset.wrapAfter === "true";
|
|
599
|
+
(c || f) && n();
|
|
529
600
|
}
|
|
530
|
-
|
|
601
|
+
n();
|
|
531
602
|
}
|
|
532
|
-
function
|
|
533
|
-
let
|
|
534
|
-
const
|
|
603
|
+
function ot(t, e, r, a) {
|
|
604
|
+
let n = [], o = !0;
|
|
605
|
+
const i = [];
|
|
535
606
|
for (const s of t) {
|
|
536
|
-
const c =
|
|
537
|
-
!c && s.words.trim().length > 0 && (o = !1,
|
|
538
|
-
const
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
607
|
+
const c = j(s.words);
|
|
608
|
+
!c && s.words.trim().length > 0 && (o = !1, n.reverse().forEach((d) => i.push(d)), n = []);
|
|
609
|
+
const f = Kt(s);
|
|
610
|
+
for (const d of f) {
|
|
611
|
+
const l = document.createElement("span");
|
|
612
|
+
l.classList.add(Xt), d.durationMs === 0 && l.classList.add(ee), c && l.classList.add(Z);
|
|
613
|
+
const m = {
|
|
614
|
+
time: d.startTimeMs / 1e3,
|
|
615
|
+
duration: d.durationMs / 1e3,
|
|
616
|
+
element: l,
|
|
617
|
+
animationStartTimeMs: Number.POSITIVE_INFINITY
|
|
618
|
+
};
|
|
619
|
+
l.textContent = d.words, l.dataset.time = String(m.time), l.dataset.duration = String(m.duration), l.dataset.content = d.words, l.style.setProperty("--braccato-duration", `${d.durationMs}ms`), d.durationMs > a && (l.dataset.longWord = "true"), d.isBackground && l.classList.add(V), d.isWrapAfter && (l.dataset.wrapAfter = "true"), d.words.trim().length === 0 && (l.style.display = "inline"), d.words.trim().length !== 0 && e.parts.push(m), c ? n.push(l) : i.push(l);
|
|
620
|
+
}
|
|
547
621
|
}
|
|
548
|
-
if (o &&
|
|
549
|
-
|
|
550
|
-
for (const s of
|
|
551
|
-
} else
|
|
552
|
-
|
|
622
|
+
if (o && n.length > 0) {
|
|
623
|
+
r.classList.add(Z);
|
|
624
|
+
for (const s of n) i.push(s);
|
|
625
|
+
} else n.length > 0 && n.reverse().forEach((s) => i.push(s));
|
|
626
|
+
oe(r, i);
|
|
553
627
|
}
|
|
554
|
-
function
|
|
555
|
-
const { longWordThreshold:
|
|
628
|
+
function ce(t, e, r = {}) {
|
|
629
|
+
const { longWordThreshold: a = 1500, lineSyncedAnimationDelay: n = 50, disableRichsync: o = !1 } = r;
|
|
556
630
|
e.replaceChildren();
|
|
557
|
-
let s = t.every((
|
|
631
|
+
let s = t.every((d) => d.startTimeMs === 0) ? "none" : "synced";
|
|
558
632
|
const c = [];
|
|
559
|
-
for (let
|
|
560
|
-
const
|
|
561
|
-
m.classList.add(
|
|
562
|
-
const
|
|
633
|
+
for (let d = 0; d < t.length; d++) {
|
|
634
|
+
const l = t[d], m = l.isInstrumental ? Gt(l.durationMs, d) : document.createElement("div");
|
|
635
|
+
m.classList.add(Jt);
|
|
636
|
+
const p = {
|
|
563
637
|
element: m,
|
|
564
|
-
time:
|
|
565
|
-
duration:
|
|
638
|
+
time: l.startTimeMs / 1e3,
|
|
639
|
+
duration: l.durationMs / 1e3,
|
|
566
640
|
parts: [],
|
|
567
641
|
isScrolled: !1,
|
|
568
642
|
animationStartTimeMs: Number.POSITIVE_INFINITY,
|
|
@@ -574,32 +648,34 @@ function $t(t, e, a = {}) {
|
|
|
574
648
|
height: -1,
|
|
575
649
|
position: -1
|
|
576
650
|
};
|
|
577
|
-
if (
|
|
578
|
-
m.dataset.instrumental = "true", m.dataset.time = String(
|
|
651
|
+
if (l.isInstrumental) {
|
|
652
|
+
m.dataset.instrumental = "true", m.dataset.time = String(p.time), m.dataset.duration = String(p.duration), m.dataset.lineNumber = String(d);
|
|
653
|
+
const b = ie(t, d);
|
|
654
|
+
b && (m.dataset.agent = b), se(t, d) && m.classList.add(Z), c.push(p), e.appendChild(m);
|
|
579
655
|
continue;
|
|
580
656
|
}
|
|
581
|
-
let
|
|
582
|
-
if ((
|
|
583
|
-
startTimeMs:
|
|
584
|
-
words:
|
|
657
|
+
let w = l.parts ?? [];
|
|
658
|
+
if ((w.length === 0 || o) && (w = l.words.split(" ").map((b, v) => ({
|
|
659
|
+
startTimeMs: l.startTimeMs + v * n,
|
|
660
|
+
words: b.trim().length < 1 ? b : `${b} `,
|
|
585
661
|
durationMs: 0
|
|
586
|
-
}))),
|
|
662
|
+
}))), w.every((b) => b.durationMs === 0) || (s = "richsync"), ot(w, p, m, a), H(m, 1), m.dataset.time = String(p.time), m.dataset.duration = String(p.duration), m.dataset.lineNumber = String(d), m.style.setProperty("--braccato-duration", `${l.durationMs}ms`), l.agent && (m.dataset.agent = l.agent), l.romanization) {
|
|
587
663
|
H(m, 4);
|
|
588
|
-
const
|
|
589
|
-
|
|
590
|
-
${
|
|
664
|
+
const b = document.createElement("div");
|
|
665
|
+
b.classList.add(re), b.style.order = "5", l.timedRomanization && l.timedRomanization.length > 0 && !o ? ot(l.timedRomanization, p, b, a) : b.textContent = `
|
|
666
|
+
${l.romanization}`, m.appendChild(b);
|
|
591
667
|
}
|
|
592
|
-
if (
|
|
668
|
+
if (l.translation) {
|
|
593
669
|
H(m, 6);
|
|
594
|
-
const
|
|
595
|
-
|
|
596
|
-
${
|
|
670
|
+
const b = document.createElement("div");
|
|
671
|
+
b.classList.add(ae), b.style.order = "7", b.textContent = `
|
|
672
|
+
${l.translation.text}`, m.appendChild(b);
|
|
597
673
|
}
|
|
598
|
-
c.push(
|
|
674
|
+
c.push(p), e.appendChild(m);
|
|
599
675
|
}
|
|
600
676
|
e.dataset.sync = s;
|
|
601
|
-
const
|
|
602
|
-
return
|
|
677
|
+
const f = document.createElement("div");
|
|
678
|
+
return f.className = "braccato--spacer", f.style.height = "100px", e.appendChild(f), {
|
|
603
679
|
lines: c,
|
|
604
680
|
syncType: s,
|
|
605
681
|
width: e.clientWidth,
|
|
@@ -607,13 +683,13 @@ ${f.translation.text}`, m.appendChild(g);
|
|
|
607
683
|
container: e
|
|
608
684
|
};
|
|
609
685
|
}
|
|
610
|
-
const jt = ":host{display:block;overflow-y:auto;position:relative;container-type:size;scrollbar-width:none}:host::-webkit-scrollbar{display:none}:host(:has(.braccato--user-scrolling)){scrollbar-width:thin;scrollbar-color:rgba(255,255,255,.15) transparent}:host(:has(.braccato--user-scrolling))::-webkit-scrollbar{display:block;width:6px}:host(:has(.braccato--user-scrolling))::-webkit-scrollbar-thumb{background:#ffffff26;border-radius:3px}:host(:has(.braccato--user-scrolling))::-webkit-scrollbar-track{background:transparent}.braccato-container{font-family:var(--braccato-font-family);font-size:var(--braccato-font-size);font-weight:var(--braccato-font-weight);isolation:isolate;line-height:var(--braccato-line-height);position:relative;z-index:1;transition:transform var(--braccato-scroll-duration) var(--braccato-scroll-timing-function) 0s;padding-top:2rem;padding-bottom:var(--braccato-padding-bottom)}.braccato-container>div{cursor:pointer;padding:var(--braccato-padding) 0;transform-origin:left center;word-break:break-word;transition:filter calc(var(--braccato-duration) / 3) .4s,opacity calc(var(--braccato-duration) / 2) .166s,transform .166s var(--braccato-anim-delay, 0s)}.braccato-container:has(.braccato--active):not(.braccato--user-scrolling)>div:not(.braccato--active):not(.braccato--active~div){opacity:.33;filter:blur(2.5px)}.braccato-container>div.braccato--active{opacity:1;filter:blur(0px)}.braccato-container>div.braccato--active~div{opacity:.66;filter:blur(0px)}.braccato-container>.braccato--animating{opacity:1!important;filter:blur(0px)!important}.braccato-container>div:hover{opacity:1!important;filter:blur(0px)!important;transform:scale(var(--braccato-hover-scale, 1.01));transition:all .3s ease}.braccato--active{cursor:default}:not(.braccato-background-lyric){order:0}.braccato-background-lyric{order:2}.braccato--line>span>span.braccato-background-lyric{font-size:.675em;font-weight:400}.braccato--line{transform:scale(var(--braccato-scale));transition-property:transform;transition-duration:var(--braccato-scale-transition-duration);transition-timing-function:ease;display:flex;flex-flow:row wrap;align-items:start;align-content:flex-start;padding-left:.25em;padding-right:.25em;box-sizing:border-box}.braccato--line.braccato--animating{transform:scale(var(--braccato-active-scale));transition-delay:var(--braccato-anim-delay)}.braccato--line>span{color:var(--braccato-inactive-color);display:inline-block;white-space:pre-wrap}.braccato--word{white-space:pre;display:inline-block;transform:translateY(0);position:relative}.braccato--line.braccato--pre-animating,.braccato--line.braccato--pre-animating .braccato--word{will-change:transform}.braccato--break{flex-basis:100%;height:0}.braccato--word.braccato--animating{animation:braccato-wobble var(--braccato-wobble-duration) forwards ease;animation-delay:var(--braccato-anim-delay);animation-play-state:running}.braccato--word.braccato--animating.braccato--paused{animation-play-state:paused}.braccato--word:after{position:absolute;content:attr(data-content);top:-2rem;left:-2rem;white-space:pre-wrap;padding:2rem;pointer-events:none;color:transparent;box-sizing:content-box;width:100%;background-image:linear-gradient(90deg,var(--braccato-active-color) calc(100% * var(--lyric-transition-amount-start) - 4rem * var(--lyric-transition-amount-start) + 2rem),#00000000 calc(100% * var(--lyric-transition-amount-end) - 4rem * var(--lyric-transition-amount-end) + 2rem + 1px));opacity:0;--lyric-transition-amount-start: -.2;--lyric-transition-amount-end: -.1;--braccato-glow-color: color(display-p3 1 1 1 / .0001);transition:--lyric-transition-amount-start 1s linear 1000s,--lyric-transition-amount-end 1s linear 1000s,opacity .5s ease;-webkit-background-clip:text;background-clip:text}.braccato--word[data-long-word]:after{--braccato-glow-color: color(display-p3 1 1 1 / 1)}.braccato--word.braccato--pre-animating:not(.braccato--animating):after{transition:none;--lyric-transition-amount-start: -.2;--lyric-transition-amount-end: -.1;opacity:0}.braccato--word.braccato--pre-animating:not(.braccato--animating):not(.braccato-zero-dur-animate):after{opacity:1}.braccato--word.braccato--animating:after{opacity:1;animation:braccato-glow max(calc(var(--braccato-duration) * 1.2),1.2s) forwards ease;animation-delay:var(--braccato-anim-delay);animation-play-state:running;--lyric-transition-amount-start: 1.4;--lyric-transition-amount-end: 1.5;transition-property:--lyric-transition-amount-start,--lyric-transition-amount-end,opacity;transition-duration:calc(var(--braccato-duration) * 1.6),calc(var(--braccato-duration) * 1.6),var(--braccato-highlight-fade-in-duration);transition-timing-function:linear,linear,ease;transition-delay:var(--braccato-swipe-delay),var(--braccato-swipe-delay),var(--braccato-anim-delay)}.braccato--word.braccato--animating.braccato--paused:after{transition-duration:100000000s,100000000s,100000000s;--lyric-transition-amount-start: 10;--lyric-transition-amount-end: 10;opacity:.5;animation-play-state:paused}.braccato--translated,.braccato--romanized{display:block;font-size:var(--braccato-translated-font-size);font-weight:var(--braccato-translated-font-weight);font-family:var(--braccato-translated-font-family);color:var(--braccato-translated-color);white-space:normal;line-height:1.1;margin-top:8px}.braccato--romanized>span{color:var(--braccato-inactive-color);display:inline-block;white-space:pre-wrap}.braccato--romanized{width:fit-content;font-size:calc(var(--braccato-translated-font-size) / 1.25);background:#ffffff0d;padding:.375rem .75rem;border:1px solid rgba(255,255,255,.1);border-radius:1rem}.braccato-rtl{direction:rtl}.braccato-rtl.braccato--word:after{background-image:linear-gradient(270deg,var(--braccato-active-color) calc(100% * var(--lyric-transition-amount-start) - 4rem * var(--lyric-transition-amount-start) + 2rem),#00000000 calc(100% * var(--lyric-transition-amount-end) - 4rem * var(--lyric-transition-amount-end) + 2rem + 1px))}.braccato--line[data-agent=v2],.braccato--line[data-agent=v3]{justify-content:flex-end;text-align:right;transform-origin:right center!important}.braccato--line[data-agent=v1000]{justify-content:center;text-align:center;transform-origin:center center!important}.braccato--spacer{padding:0;margin:0}.braccato-autoscroll-btn{font-family:var(--braccato-font-family);position:absolute;display:block;font-size:1.75rem;font-weight:600;white-space:normal;line-height:1.1;width:fit-content;background:#ffffff0d;padding:.5rem 1rem;border:1px solid rgba(255,255,255,.1);border-radius:1rem;color:#fff;left:50%;transform:translate(-50%,2em);-webkit-backdrop-filter:blur(5px);backdrop-filter:blur(5px);pointer-events:auto;cursor:pointer;-webkit-user-select:none;user-select:none;z-index:100;transition:opacity .15s linear .05s,transform .2s cubic-bezier(.5,1,.89,1)}.braccato-autoscroll-btn[hidden]{transition:opacity .1s linear,transform .15s ease-in;opacity:0;pointer-events:none;transform:translate(-50%,-3em)}@keyframes braccato-wobble{0%{transform:translateY(0)}to{transform:translateY(-.0375em)}}@keyframes braccato-glow{0%{filter:drop-shadow(0 0 .8rem var(--braccato-glow-color))}to{filter:drop-shadow(0 0 0rem var(--braccato-glow-color))}}", Ht = ':host{--braccato-text-color: color(display-p3 1 1 1 / 1);--braccato-glow-color: color(display-p3 1 1 1 / .5);--braccato-active-color: var(--braccato-text-color);--braccato-inactive-color: color( from var(--braccato-text-color) display-p3 r g b / var(--braccato-inactive-opacity, .3) );--braccato-active-opacity: 1;--braccato-inactive-opacity: .3;--braccato-richsync-timing-offset: .15s;--braccato-timing-offset: .115s;--braccato-scroll-timing-offset: .5s;--braccato-font-family: "Satoshi", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;--braccato-font-size: 3rem;--braccato-font-weight: 600;--braccato-line-height: 1.333;--braccato-translated-font-size: 2rem;--braccato-translated-font-weight: 600;--braccato-translated-font-family: var(--braccato-font-family);--braccato-translated-color: color(display-p3 1 1 1 / var(--braccato-translated-opacity, .6));--braccato-scale-transition-duration: .166s;--braccato-highlight-fade-in-duration: .33s;--braccato-highlight-fade-out-duration: .5s;--braccato-wobble-duration: 1s;--braccato-padding: 1.25rem;--braccato-padding-bottom: 50cqh;--braccato-scale: .95;--braccato-active-scale: 1;--braccato-scroll-duration: .75s;--braccato-scroll-timing-function: cubic-bezier(.86, 0, .07, 1)}';
|
|
611
|
-
var
|
|
612
|
-
for (var
|
|
613
|
-
(
|
|
614
|
-
return
|
|
686
|
+
const le = ':host{display:block;overflow-y:auto;position:relative;container-type:size;scrollbar-width:none}:host::-webkit-scrollbar{display:none}:host(:has(.braccato--user-scrolling)){scrollbar-width:thin;scrollbar-color:rgba(255,255,255,.15) transparent}:host(:has(.braccato--user-scrolling))::-webkit-scrollbar{display:block;width:6px}:host(:has(.braccato--user-scrolling))::-webkit-scrollbar-thumb{background:#ffffff26;border-radius:3px}:host(:has(.braccato--user-scrolling))::-webkit-scrollbar-track{background:transparent}.braccato-container{font-family:var(--braccato-font-family);font-size:var(--braccato-font-size);font-weight:var(--braccato-font-weight);isolation:isolate;line-height:var(--braccato-line-height);position:relative;z-index:1;transition:transform var(--braccato-scroll-duration) var(--braccato-scroll-timing-function) 0s;padding-top:2rem;padding-bottom:var(--braccato-padding-bottom)}.braccato-container>div{cursor:pointer;padding:var(--braccato-padding) 0;transform-origin:left center;word-break:break-word;transition:filter calc(var(--braccato-duration) / 3) .4s,opacity calc(var(--braccato-duration) / 2) .166s,transform .166s var(--braccato-anim-delay, 0s)}.braccato-container:has(.braccato--active):not(.braccato--user-scrolling)>div:not(.braccato--active):not(.braccato--active~div){opacity:.33;filter:blur(2.5px)}.braccato-container>div.braccato--active{opacity:1;filter:blur(0px)}.braccato-container>div.braccato--active~div{opacity:.66;filter:blur(0px)}.braccato-container>.braccato--animating{opacity:1!important;filter:blur(0px)!important}.braccato-container>div:hover{opacity:1!important;filter:blur(0px)!important;transform:scale(var(--braccato-hover-scale, 1.01));transition:all .3s ease}.braccato--active{cursor:default}:not(.braccato-background-lyric){order:0}.braccato-background-lyric{order:2}.braccato--line>span>span.braccato-background-lyric{font-size:.675em;font-weight:400}.braccato--line{transform:scale(var(--braccato-scale));transition-property:transform;transition-duration:var(--braccato-scale-transition-duration);transition-timing-function:ease;display:flex;flex-flow:row wrap;align-items:start;align-content:flex-start;padding-left:.25em;padding-right:.25em;box-sizing:border-box}.braccato--line.braccato--animating{transform:scale(var(--braccato-active-scale));transition-delay:var(--braccato-anim-delay)}.braccato--line>span{color:var(--braccato-inactive-color);display:inline-block;white-space:pre-wrap}.braccato--word{white-space:pre;display:inline-block;transform:translateY(0);position:relative}.braccato--line.braccato--pre-animating,.braccato--line.braccato--pre-animating .braccato--word{will-change:transform}.braccato--break{flex-basis:100%;height:0}.braccato--word.braccato--animating{animation:braccato-wobble var(--braccato-wobble-duration) forwards ease;animation-delay:var(--braccato-anim-delay);animation-play-state:running}.braccato--word.braccato--animating.braccato--paused{animation-play-state:paused}.braccato--word:after{position:absolute;content:attr(data-content);top:-2rem;left:-2rem;white-space:pre-wrap;padding:2rem;pointer-events:none;color:transparent;box-sizing:content-box;width:100%;background-image:linear-gradient(90deg,var(--braccato-active-color) calc(100% * var(--lyric-transition-amount-start) - 4rem * var(--lyric-transition-amount-start) + 2rem),#00000000 calc(100% * var(--lyric-transition-amount-end) - 4rem * var(--lyric-transition-amount-end) + 2rem + 1px));opacity:0;--lyric-transition-amount-start: -.2;--lyric-transition-amount-end: -.1;--braccato-glow-color: color(display-p3 1 1 1 / .0001);transition:--lyric-transition-amount-start 1s linear 1000s,--lyric-transition-amount-end 1s linear 1000s,opacity .5s ease;-webkit-background-clip:text;background-clip:text}.braccato--word[data-long-word]:after{--braccato-glow-color: color(display-p3 1 1 1 / 1)}.braccato--word.braccato--pre-animating:not(.braccato--animating):after{transition:none;--lyric-transition-amount-start: -.2;--lyric-transition-amount-end: -.1;opacity:0}.braccato--word.braccato--pre-animating:not(.braccato--animating):not(.braccato-zero-dur-animate):after{opacity:1}.braccato--word.braccato--animating:after{opacity:1;animation:braccato-glow max(calc(var(--braccato-duration) * 1.2),1.2s) forwards ease;animation-delay:var(--braccato-anim-delay);animation-play-state:running;--lyric-transition-amount-start: 1.4;--lyric-transition-amount-end: 1.5;transition-property:--lyric-transition-amount-start,--lyric-transition-amount-end,opacity;transition-duration:calc(var(--braccato-duration) * 1.6),calc(var(--braccato-duration) * 1.6),var(--braccato-highlight-fade-in-duration);transition-timing-function:linear,linear,ease;transition-delay:var(--braccato-swipe-delay),var(--braccato-swipe-delay),var(--braccato-anim-delay)}.braccato--word.braccato--animating.braccato--paused:after{transition-duration:100000000s,100000000s,100000000s;--lyric-transition-amount-start: 10;--lyric-transition-amount-end: 10;opacity:.5;animation-play-state:paused}.braccato--translated,.braccato--romanized{display:block;font-size:var(--braccato-translated-font-size);font-weight:var(--braccato-translated-font-weight);font-family:var(--braccato-translated-font-family);color:var(--braccato-translated-color);white-space:normal;line-height:1.1;margin-top:8px}.braccato--romanized>span{color:var(--braccato-inactive-color);display:inline-block;white-space:pre-wrap}.braccato--romanized{width:fit-content;font-size:calc(var(--braccato-translated-font-size) / 1.25);background:#ffffff0d;padding:.375rem .75rem;border:1px solid rgba(255,255,255,.1);border-radius:1rem}.braccato-rtl{direction:rtl}.braccato-rtl.braccato--word:after{background-image:linear-gradient(270deg,var(--braccato-active-color) calc(100% * var(--lyric-transition-amount-start) - 4rem * var(--lyric-transition-amount-start) + 2rem),#00000000 calc(100% * var(--lyric-transition-amount-end) - 4rem * var(--lyric-transition-amount-end) + 2rem + 1px))}.braccato--line[data-agent=v2],.braccato--line[data-agent=v3]{justify-content:flex-end;text-align:right;transform-origin:right center!important}.braccato--line[data-agent=v1000]{justify-content:center;text-align:center;transform-origin:center center!important}.braccato--instrumental-icon{height:var(--braccato-font-size);width:calc(var(--braccato-font-size) + var(--braccato-font-size) / 3);overflow:visible;margin-left:calc(var(--braccato-font-size) / -3)}.braccato-rtl.braccato--instrumental .braccato--instrumental-icon,.braccato--instrumental[data-agent=v2] .braccato--instrumental-icon,.braccato--instrumental[data-agent=v3] .braccato--instrumental-icon{margin-left:0;margin-right:calc(var(--braccato-font-size) / -3)}.braccato--instrumental[data-agent=v1000] .braccato--instrumental-icon{margin-left:0;margin-right:0}.braccato--instrumental-bg{fill:var(--braccato-inactive-color)}.braccato--instrumental-fill{fill:var(--braccato-active-color);transition:opacity var(--braccato-highlight-fade-out-duration, .5s) ease;opacity:0}.braccato--instrumental.braccato--animating .braccato--instrumental-fill{transition:none;opacity:1}.braccato--instrumental:not(.braccato--pre-animating) .braccato--wave-clip{transition-property:transform;transition-duration:1000000s;transition-delay:0s;transform:translateY(0)}.braccato--instrumental.braccato--pre-animating:not(.braccato--animating) .braccato--wave-clip{animation:none;transform:translateY(78%)}.braccato--instrumental.braccato--animating .braccato--wave-clip{transition-property:transform;transition-duration:calc(var(--braccato-duration, 1ms) * 1);transition-timing-function:linear;transition-delay:var(--braccato-anim-delay);transform:translateY(-4%)}.braccato--paused .braccato--wave-clip{transition-duration:100000000s!important;transform:translateY(100%)!important}.braccato--wave-path{transform-box:fill-box;transform-origin:bottom;animation:braccato-wave 1.25s ease-in-out infinite;animation-play-state:paused;transform:scaleY(1.2)}.braccato--instrumental.braccato--animating:not(.braccato--paused) .braccato--wave-path{animation-play-state:running;transform:scaleY(0);transition-property:transform;transition-duration:calc(var(--braccato-duration, 1ms) * 1);transition-timing-function:ease-in;transition-delay:var(--braccato-anim-delay)}.braccato--instrumental.braccato--animating.braccato--paused .braccato--wave-path{transform:scaleY(.0001);transition-duration:10000000000s;transition-property:transform;transition-timing-function:ease-out;transition-delay:0s}@keyframes braccato-wave{0%,to{d:path("M -4 3 Q 1 2 5 3 Q 10 4 14 3 Q 18 2 22 3 Q 26 4 30 3 L 30 4 L -4 4 Z")}50%{d:path("M -4 3 Q 1 4 5 3 Q 10 2 14 3 Q 18 4 22 3 Q 26 2 30 3 L 30 4 L -4 4 Z")}}.braccato--spacer{padding:0;margin:0}.braccato-autoscroll-btn{font-family:var(--braccato-font-family);position:absolute;display:block;font-size:1.75rem;font-weight:600;white-space:normal;line-height:1.1;width:fit-content;background:#ffffff0d;padding:.5rem 1rem;border:1px solid rgba(255,255,255,.1);border-radius:1rem;color:#fff;left:50%;transform:translate(-50%,2em);-webkit-backdrop-filter:blur(5px);backdrop-filter:blur(5px);pointer-events:auto;cursor:pointer;-webkit-user-select:none;user-select:none;z-index:100;transition:opacity .15s linear .05s,transform .2s cubic-bezier(.5,1,.89,1)}.braccato-autoscroll-btn[hidden]{transition:opacity .1s linear,transform .15s ease-in;opacity:0;pointer-events:none;transform:translate(-50%,-3em)}@keyframes braccato-wobble{0%{transform:translateY(0)}to{transform:translateY(-.0375em)}}@keyframes braccato-glow{0%{filter:drop-shadow(0 0 .8rem var(--braccato-glow-color))}to{filter:drop-shadow(0 0 0rem var(--braccato-glow-color))}}', de = ':host{--braccato-text-color: color(display-p3 1 1 1 / 1);--braccato-glow-color: color(display-p3 1 1 1 / .5);--braccato-active-color: var(--braccato-text-color);--braccato-inactive-color: color( from var(--braccato-text-color) display-p3 r g b / var(--braccato-inactive-opacity, .3) );--braccato-active-opacity: 1;--braccato-inactive-opacity: .3;--braccato-richsync-timing-offset: .15s;--braccato-timing-offset: .115s;--braccato-scroll-timing-offset: .5s;--braccato-font-family: "Satoshi", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;--braccato-font-size: 3rem;--braccato-font-weight: 600;--braccato-line-height: 1.333;--braccato-translated-font-size: 2rem;--braccato-translated-font-weight: 600;--braccato-translated-font-family: var(--braccato-font-family);--braccato-translated-color: color(display-p3 1 1 1 / var(--braccato-translated-opacity, .6));--braccato-scale-transition-duration: .166s;--braccato-highlight-fade-in-duration: .33s;--braccato-highlight-fade-out-duration: .5s;--braccato-wobble-duration: 1s;--braccato-padding: 1.25rem;--braccato-padding-bottom: 50cqh;--braccato-scale: .95;--braccato-active-scale: 1;--braccato-scroll-duration: .75s;--braccato-scroll-timing-function: cubic-bezier(.86, 0, .07, 1)}';
|
|
687
|
+
var ue = Object.defineProperty, R = (t, e, r, a) => {
|
|
688
|
+
for (var n = void 0, o = t.length - 1, i; o >= 0; o--)
|
|
689
|
+
(i = t[o]) && (n = i(e, r, n) || n);
|
|
690
|
+
return n && ue(e, r, n), n;
|
|
615
691
|
};
|
|
616
|
-
function
|
|
692
|
+
function me() {
|
|
617
693
|
if (!(typeof CSS > "u" || !CSS.registerProperty))
|
|
618
694
|
try {
|
|
619
695
|
CSS.registerProperty({
|
|
@@ -630,16 +706,16 @@ function Yt() {
|
|
|
630
706
|
} catch {
|
|
631
707
|
}
|
|
632
708
|
}
|
|
633
|
-
|
|
634
|
-
const
|
|
709
|
+
me();
|
|
710
|
+
const K = class K extends lt {
|
|
635
711
|
constructor() {
|
|
636
|
-
super(...arguments), this.lyrics = [], this.currentTime = 0, this.playing = !1, this.scrollMode = "internal", this.scrollContainer = null, this.dir = "auto", this.longWordThreshold = 1500, this.lineSyncedDelay = 50, this.disableRichsync = !1, this.debug = !1, this.source = null, this.src = null, this._lyricsData = null, this._animState =
|
|
712
|
+
super(...arguments), this.lyrics = [], this.currentTime = 0, this.playing = !1, this.scrollMode = "internal", this.scrollContainer = null, this.dir = "auto", this.longWordThreshold = 1500, this.lineSyncedDelay = 50, this.disableRichsync = !1, this.debug = !1, this.source = null, this.src = null, this._lyricsData = null, this._animState = Rt(), this._rafId = null, this._lastLyrics = [], this._resizeObserver = null, this._mediaElement = null, this._lastSrc = null, this._srcAbortController = null, this._tickCount = 0, this._onScroll = () => {
|
|
637
713
|
const e = this._animState.scroll;
|
|
638
714
|
if (e.skipScrolls > 0) {
|
|
639
715
|
e.skipScrolls--;
|
|
640
716
|
return;
|
|
641
717
|
}
|
|
642
|
-
|
|
718
|
+
At(e) ? rt(e) : (rt(e), this.dispatchEvent(
|
|
643
719
|
new CustomEvent("braccato:scroll-state", {
|
|
644
720
|
detail: { userScrolling: !0 },
|
|
645
721
|
bubbles: !0,
|
|
@@ -660,39 +736,39 @@ const V = class V extends st {
|
|
|
660
736
|
e.has("lyrics") && this.lyrics !== this._lastLyrics && (this._lastLyrics = this.lyrics, this._injectLyrics()), e.has("source") && this._resolveMediaElement(), e.has("src") && this.src !== this._lastSrc && (this._lastSrc = this.src, this._fetchLyricsFromSrc());
|
|
661
737
|
}
|
|
662
738
|
render() {
|
|
663
|
-
return
|
|
739
|
+
return dt`<div class="braccato-container" part="container"></div>`;
|
|
664
740
|
}
|
|
665
741
|
// -- Lyric Injection --------------------------
|
|
666
742
|
_log(...e) {
|
|
667
743
|
this.debug && console.log("[braccato]", ...e);
|
|
668
744
|
}
|
|
669
745
|
_injectLyrics() {
|
|
670
|
-
var
|
|
671
|
-
const e = (
|
|
746
|
+
var n, o, i, s;
|
|
747
|
+
const e = (n = this.shadowRoot) == null ? void 0 : n.querySelector(".braccato-container");
|
|
672
748
|
if (!e) {
|
|
673
749
|
this._log("_injectLyrics: no container found in shadowRoot");
|
|
674
750
|
return;
|
|
675
751
|
}
|
|
676
|
-
if (
|
|
752
|
+
if (Pt(this._animState), !this.lyrics || this.lyrics.length === 0) {
|
|
677
753
|
this._log("_injectLyrics: no lyrics, clearing"), e.replaceChildren(), this._lyricsData = null;
|
|
678
754
|
return;
|
|
679
755
|
}
|
|
680
|
-
const
|
|
756
|
+
const r = {
|
|
681
757
|
longWordThreshold: this.longWordThreshold,
|
|
682
758
|
lineSyncedAnimationDelay: this.lineSyncedDelay,
|
|
683
759
|
disableRichsync: this.disableRichsync
|
|
684
760
|
};
|
|
685
|
-
this._lyricsData =
|
|
761
|
+
this._lyricsData = ce(this.lyrics, e, r), this._log("_injectLyrics: rendered", {
|
|
686
762
|
lineCount: this._lyricsData.lines.length,
|
|
687
763
|
syncType: this._lyricsData.syncType,
|
|
688
764
|
firstLineTime: (o = this._lyricsData.lines[0]) == null ? void 0 : o.time,
|
|
689
|
-
lastLineTime: (
|
|
765
|
+
lastLineTime: (i = this._lyricsData.lines[this._lyricsData.lines.length - 1]) == null ? void 0 : i.time,
|
|
690
766
|
containerSize: { w: e.clientWidth, h: e.clientHeight }
|
|
691
767
|
});
|
|
692
768
|
for (let c = 0; c < this._lyricsData.lines.length; c++)
|
|
693
|
-
this._lyricsData.lines[c].element.addEventListener("click", (
|
|
694
|
-
const
|
|
695
|
-
this._log("_injectLyrics: scrollContainer",
|
|
769
|
+
this._lyricsData.lines[c].element.addEventListener("click", (d) => this._handleLineClick(d, c));
|
|
770
|
+
const a = this._getScrollContainer();
|
|
771
|
+
this._log("_injectLyrics: scrollContainer", a.tagName, a.className), a.addEventListener("scroll", this._onScroll, { passive: !0 }), (s = this._resizeObserver) == null || s.disconnect(), this._resizeObserver = new ResizeObserver(() => this._recalculatePositions()), this._resizeObserver.observe(e), this._recalculatePositions(), this.dispatchEvent(
|
|
696
772
|
new CustomEvent("braccato:lyrics-loaded", {
|
|
697
773
|
detail: { syncType: this._lyricsData.syncType, lineCount: this._lyricsData.lines.length },
|
|
698
774
|
bubbles: !0,
|
|
@@ -705,9 +781,9 @@ const V = class V extends st {
|
|
|
705
781
|
if (!this._lyricsData) return;
|
|
706
782
|
const e = this._lyricsData.container;
|
|
707
783
|
this._lyricsData.width = e.clientWidth, this._lyricsData.height = e.clientHeight;
|
|
708
|
-
for (const
|
|
709
|
-
const
|
|
710
|
-
|
|
784
|
+
for (const r of this._lyricsData.lines) {
|
|
785
|
+
const a = r.element.getBoundingClientRect(), n = e.getBoundingClientRect();
|
|
786
|
+
r.position = a.top - n.top + e.scrollTop, r.height = a.height;
|
|
711
787
|
}
|
|
712
788
|
this._animState.scroll.wasUserScrolling = !0;
|
|
713
789
|
}
|
|
@@ -724,24 +800,24 @@ const V = class V extends st {
|
|
|
724
800
|
_tick() {
|
|
725
801
|
if (!this._lyricsData || this._lyricsData.syncType === "none") return;
|
|
726
802
|
if (this._tickCount++, this.debug && this._tickCount % 60 === 0) {
|
|
727
|
-
const
|
|
803
|
+
const n = this._lyricsData.lines.filter((i) => i.isScrolled), o = this._lyricsData.lines.filter((i) => i.isAnimating);
|
|
728
804
|
this._log("tick", {
|
|
729
805
|
currentTime: this.currentTime,
|
|
730
806
|
currentTimeSec: this.currentTime / 1e3,
|
|
731
807
|
playing: this.playing,
|
|
732
808
|
syncType: this._lyricsData.syncType,
|
|
733
|
-
activeLineCount:
|
|
809
|
+
activeLineCount: n.length,
|
|
734
810
|
animatingLineCount: o.length,
|
|
735
811
|
selectedIndex: this._animState.selectedElementIndex,
|
|
736
812
|
scrollResumeTime: this._animState.scroll.scrollResumeTime,
|
|
737
813
|
isUserScrolling: this._animState.scroll.wasUserScrolling
|
|
738
814
|
});
|
|
739
815
|
}
|
|
740
|
-
const e = this._mediaElement,
|
|
741
|
-
|
|
742
|
-
currentTime:
|
|
816
|
+
const e = this._mediaElement, r = e ? e.currentTime * 1e3 : this.currentTime, a = e ? !e.paused : this.playing;
|
|
817
|
+
zt(this._animState, {
|
|
818
|
+
currentTime: r / 1e3,
|
|
743
819
|
eventCreationTime: Date.now(),
|
|
744
|
-
isPlaying:
|
|
820
|
+
isPlaying: a,
|
|
745
821
|
smoothScroll: !0,
|
|
746
822
|
lyricsData: this._lyricsData,
|
|
747
823
|
scrollContainer: this._getScrollContainer()
|
|
@@ -752,18 +828,18 @@ const V = class V extends st {
|
|
|
752
828
|
return this.scrollMode === "external" && this.scrollContainer ? this.scrollContainer : this;
|
|
753
829
|
}
|
|
754
830
|
// -- Events --------------------------
|
|
755
|
-
_handleLineClick(e,
|
|
756
|
-
var o,
|
|
757
|
-
const
|
|
758
|
-
if (!
|
|
759
|
-
const
|
|
760
|
-
if (this._log("lineClick", { lineIndex:
|
|
831
|
+
_handleLineClick(e, r) {
|
|
832
|
+
var o, i;
|
|
833
|
+
const a = (o = this._lyricsData) == null ? void 0 : o.lines[r];
|
|
834
|
+
if (!a) return;
|
|
835
|
+
const n = a.time * 1e3;
|
|
836
|
+
if (this._log("lineClick", { lineIndex: r, time: n, lineTimeSec: a.time, currentTime: this.currentTime }), e.altKey && ((i = this._lyricsData) == null ? void 0 : i.syncType) === "richsync") {
|
|
761
837
|
const s = e.target.closest(".braccato--word");
|
|
762
838
|
if (s) {
|
|
763
|
-
const c = Number.parseFloat(s.dataset.time || "0") * 1e3,
|
|
839
|
+
const c = Number.parseFloat(s.dataset.time || "0") * 1e3, f = a.parts.findIndex((d) => d.element === s);
|
|
764
840
|
this.dispatchEvent(
|
|
765
841
|
new CustomEvent("braccato:word-click", {
|
|
766
|
-
detail: { time: c, lineIndex:
|
|
842
|
+
detail: { time: c, lineIndex: r, wordIndex: f },
|
|
767
843
|
bubbles: !0,
|
|
768
844
|
composed: !0
|
|
769
845
|
})
|
|
@@ -771,13 +847,13 @@ const V = class V extends st {
|
|
|
771
847
|
return;
|
|
772
848
|
}
|
|
773
849
|
}
|
|
774
|
-
this._mediaElement && (this._mediaElement.currentTime =
|
|
850
|
+
this._mediaElement && (this._mediaElement.currentTime = n / 1e3, this._mediaElement.paused && this._mediaElement.play()), this.dispatchEvent(
|
|
775
851
|
new CustomEvent("braccato:line-click", {
|
|
776
|
-
detail: { time:
|
|
852
|
+
detail: { time: n, lineIndex: r },
|
|
777
853
|
bubbles: !0,
|
|
778
854
|
composed: !0
|
|
779
855
|
})
|
|
780
|
-
),
|
|
856
|
+
), at(this._animState.scroll);
|
|
781
857
|
}
|
|
782
858
|
// -- Source Binding --------------------------
|
|
783
859
|
_resolveMediaElement() {
|
|
@@ -789,26 +865,26 @@ const V = class V extends st {
|
|
|
789
865
|
e instanceof HTMLMediaElement ? this._mediaElement = e : (this._mediaElement = null, this._log("source: no media element found for selector", this.source));
|
|
790
866
|
}
|
|
791
867
|
async _fetchLyricsFromSrc() {
|
|
792
|
-
var
|
|
793
|
-
if ((
|
|
868
|
+
var r;
|
|
869
|
+
if ((r = this._srcAbortController) == null || r.abort(), !this.src) {
|
|
794
870
|
this.lyrics = [];
|
|
795
871
|
return;
|
|
796
872
|
}
|
|
797
873
|
const e = new AbortController();
|
|
798
874
|
this._srcAbortController = e;
|
|
799
875
|
try {
|
|
800
|
-
const
|
|
801
|
-
if (!
|
|
802
|
-
this._emitError(new Error(`Failed to fetch lyrics: ${
|
|
876
|
+
const a = await fetch(this.src, { signal: e.signal });
|
|
877
|
+
if (!a.ok) {
|
|
878
|
+
this._emitError(new Error(`Failed to fetch lyrics: ${a.status} ${a.statusText}`));
|
|
803
879
|
return;
|
|
804
880
|
}
|
|
805
|
-
const
|
|
881
|
+
const n = await a.text();
|
|
806
882
|
if (e.signal.aborted) return;
|
|
807
|
-
const o = this._mediaElement ? this._mediaElement.duration * 1e3 : 3e5,
|
|
808
|
-
this.lyrics =
|
|
809
|
-
} catch (
|
|
810
|
-
if (
|
|
811
|
-
this._emitError(
|
|
883
|
+
const o = this._mediaElement ? this._mediaElement.duration * 1e3 : 3e5, i = wt(n);
|
|
884
|
+
this.lyrics = i.parse(n, o);
|
|
885
|
+
} catch (a) {
|
|
886
|
+
if (a instanceof DOMException && a.name === "AbortError") return;
|
|
887
|
+
this._emitError(a instanceof Error ? a : new Error(String(a)));
|
|
812
888
|
}
|
|
813
889
|
}
|
|
814
890
|
_emitError(e) {
|
|
@@ -822,51 +898,51 @@ const V = class V extends st {
|
|
|
822
898
|
}
|
|
823
899
|
// -- Public Methods --------------------------
|
|
824
900
|
resumeAutoscroll() {
|
|
825
|
-
|
|
901
|
+
at(this._animState.scroll);
|
|
826
902
|
}
|
|
827
903
|
recalculatePositions() {
|
|
828
904
|
this._recalculatePositions();
|
|
829
905
|
}
|
|
830
906
|
};
|
|
831
|
-
|
|
832
|
-
let
|
|
833
|
-
|
|
907
|
+
K.styles = [X(de), X(le)];
|
|
908
|
+
let E = K;
|
|
909
|
+
R([
|
|
834
910
|
D({ type: Array })
|
|
835
|
-
],
|
|
836
|
-
|
|
911
|
+
], E.prototype, "lyrics");
|
|
912
|
+
R([
|
|
837
913
|
D({ attribute: "current-time", type: Number })
|
|
838
|
-
],
|
|
839
|
-
|
|
914
|
+
], E.prototype, "currentTime");
|
|
915
|
+
R([
|
|
840
916
|
D({ type: Boolean, reflect: !0 })
|
|
841
|
-
],
|
|
842
|
-
|
|
917
|
+
], E.prototype, "playing");
|
|
918
|
+
R([
|
|
843
919
|
D({ attribute: "scroll-mode", type: String, reflect: !0 })
|
|
844
|
-
],
|
|
845
|
-
|
|
920
|
+
], E.prototype, "scrollMode");
|
|
921
|
+
R([
|
|
846
922
|
D({ attribute: !1 })
|
|
847
|
-
],
|
|
848
|
-
|
|
923
|
+
], E.prototype, "scrollContainer");
|
|
924
|
+
R([
|
|
849
925
|
D({ type: String, reflect: !0 })
|
|
850
|
-
],
|
|
851
|
-
|
|
926
|
+
], E.prototype, "dir");
|
|
927
|
+
R([
|
|
852
928
|
D({ attribute: "long-word-threshold", type: Number })
|
|
853
|
-
],
|
|
854
|
-
|
|
929
|
+
], E.prototype, "longWordThreshold");
|
|
930
|
+
R([
|
|
855
931
|
D({ attribute: "line-synced-delay", type: Number })
|
|
856
|
-
],
|
|
857
|
-
|
|
932
|
+
], E.prototype, "lineSyncedDelay");
|
|
933
|
+
R([
|
|
858
934
|
D({ attribute: "disable-richsync", type: Boolean })
|
|
859
|
-
],
|
|
860
|
-
|
|
935
|
+
], E.prototype, "disableRichsync");
|
|
936
|
+
R([
|
|
861
937
|
D({ type: Boolean })
|
|
862
|
-
],
|
|
863
|
-
|
|
938
|
+
], E.prototype, "debug");
|
|
939
|
+
R([
|
|
864
940
|
D({ type: String, reflect: !0 })
|
|
865
|
-
],
|
|
866
|
-
|
|
941
|
+
], E.prototype, "source");
|
|
942
|
+
R([
|
|
867
943
|
D({ type: String, reflect: !0 })
|
|
868
|
-
],
|
|
869
|
-
customElements.define("braccato-lyrics",
|
|
944
|
+
], E.prototype, "src");
|
|
945
|
+
customElements.define("braccato-lyrics", E);
|
|
870
946
|
export {
|
|
871
|
-
|
|
947
|
+
E as BraccatoElement
|
|
872
948
|
};
|