@uvalib/web-components 1.11.1 → 1.12.0

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +192 -54
  3. package/dist/base.css +56 -2
  4. package/dist/components/uvalib-audio/UvalibAudio.d.ts +186 -0
  5. package/dist/components/uvalib-audio/UvalibAudio.js +1154 -0
  6. package/dist/components/uvalib-audio/UvalibAudio.js.map +1 -0
  7. package/dist/components/uvalib-audio/uvalib-audio.d.ts +1 -0
  8. package/dist/components/uvalib-audio/uvalib-audio.js +4 -0
  9. package/dist/components/uvalib-audio/uvalib-audio.js.map +1 -0
  10. package/dist/components/uvalib-pagefind-search/UvalibPagefindSearch.d.ts +25 -5
  11. package/dist/components/uvalib-pagefind-search/UvalibPagefindSearch.js +62 -9
  12. package/dist/components/uvalib-pagefind-search/UvalibPagefindSearch.js.map +1 -1
  13. package/dist/custom-elements.json +8486 -7187
  14. package/dist/edition-epub.css +511 -0
  15. package/dist/edition-print.css +51 -0
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.js +1 -0
  18. package/dist/index.js.map +1 -1
  19. package/dist/styles/base.js +55 -1
  20. package/dist/styles/base.js.map +1 -1
  21. package/dist/styles/edition.d.ts +6 -0
  22. package/dist/styles/edition.js +20 -0
  23. package/dist/styles/edition.js.map +1 -1
  24. package/dist-cdn/base.css +56 -2
  25. package/dist-cdn/chunks/{base-DtkA4Pgg.js → base-D_oPO5cX.js} +56 -2
  26. package/dist-cdn/chunks/{base-DtkA4Pgg.js.map → base-D_oPO5cX.js.map} +1 -1
  27. package/dist-cdn/custom-elements.json +8486 -7187
  28. package/dist-cdn/edition-epub.css +511 -0
  29. package/dist-cdn/edition-print.css +51 -0
  30. package/dist-cdn/manifest.json +6 -3
  31. package/dist-cdn/site-page.js +1 -1
  32. package/dist-cdn/site-style.js +1 -1
  33. package/dist-cdn/skills/uvalib-web-components/SKILL.md +35 -4
  34. package/dist-cdn/skills/uvalib-web-components/reference/components.md +53 -1
  35. package/dist-cdn/uvalib-audio.js +747 -0
  36. package/dist-cdn/uvalib-audio.js.map +1 -0
  37. package/dist-cdn/uvalib-pagefind-search.js +70 -44
  38. package/dist-cdn/uvalib-pagefind-search.js.map +1 -1
  39. package/package.json +7 -1
  40. package/skills/uvalib-web-components/SKILL.md +35 -4
  41. package/skills/uvalib-web-components/reference/components.md +53 -1
@@ -0,0 +1,747 @@
1
+ import { a as e, d as t, f as n, i as r, l as i, m as a, n as o, o as s, p as c, r as l, t as u } from "./chunks/UvalibElement-pGONDAwB.js";
2
+ import { a as d, i as f } from "./chunks/analytics-DTTihuBD.js";
3
+ import { t as p } from "./chunks/inline-copy-BANQSMIR.js";
4
+ import { n as m, r as h, t as g } from "./chunks/source-children-BHsDwCvL.js";
5
+ import { t as _ } from "./chunks/accessible-DJv7YOtS.js";
6
+ // src/components/uvalib-audio/UvalibAudio.ts
7
+ var v = "uvalib-audio", y = 0, b = [
8
+ .75,
9
+ 1,
10
+ 1.25,
11
+ 1.5,
12
+ 1.75,
13
+ 2
14
+ ], x = {
15
+ back: 15,
16
+ forward: 30
17
+ }, S = {
18
+ announce: 600,
19
+ save: 5e3,
20
+ speed: 1e3
21
+ }, C = 5e3;
22
+ function w(e) {
23
+ let t = m(e);
24
+ if (t) {
25
+ if (/^\d+(\.\d+)?$/.test(t)) return Number(t);
26
+ if (/^\d+(:\d{1,2}){1,2}$/.test(t)) return t.split(":").reduce((e, t) => e * 60 + Number(t), 0);
27
+ }
28
+ }
29
+ function T(e) {
30
+ let t = Math.max(0, Math.floor(e || 0)), n = Math.floor(t / 3600), r = Math.floor(t % 3600 / 60), i = String(t % 60).padStart(2, "0");
31
+ return n ? `${n}:${String(r).padStart(2, "0")}:${i}` : `${r}:${i}`;
32
+ }
33
+ var E = (e, t) => `${e} ${t}${e === 1 ? "" : "s"}`;
34
+ function D(e) {
35
+ let t = Math.max(0, Math.floor(e || 0)), n = [], r = Math.floor(t / 3600), i = Math.floor(t % 3600 / 60);
36
+ return r && n.push(E(r, "hour")), i && n.push(E(i, "minute")), (t % 60 || !n.length) && n.push(E(t % 60, "second")), n.join(" ");
37
+ }
38
+ function O(e) {
39
+ let t = m(e);
40
+ if (!/^\d+$/.test(t)) return t;
41
+ let n = Number(t), r = [
42
+ "bytes",
43
+ "KB",
44
+ "MB",
45
+ "GB",
46
+ "TB"
47
+ ], i = 0, a = n;
48
+ for (; a >= 1e3 && i < r.length - 1;) a /= 1e3, i++;
49
+ return i === 0 ? `${n} ${n === 1 ? "byte" : "bytes"}` : `${(a < 10 ? Math.round(a * 10) / 10 : Math.round(a)).toLocaleString("en-US")} ${r[i]}`;
50
+ }
51
+ var k = (e, t) => {
52
+ if (h(e, t)) return !0;
53
+ try {
54
+ let n = new URL(e, t);
55
+ return n.protocol === "blob:" || n.protocol === "data:" && /^data:audio\//i.test(e);
56
+ } catch {
57
+ return !1;
58
+ }
59
+ }, A = [
60
+ "hreflang",
61
+ "type",
62
+ "target",
63
+ "rel",
64
+ "download",
65
+ "lang"
66
+ ], j = /* @__PURE__ */ new Set(), M = t`<svg class="icon" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="M4 2.5v11l9.5-5.5z" fill="currentColor"/></svg>`, N = t`<svg class="icon" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="M3.5 2.5h3v11h-3zM9.5 2.5h3v11h-3z" fill="currentColor"/></svg>`, P = t`<svg class="icon" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="M3 8a5 5 0 1 0 1.6-3.7" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/><path d="M2.2 1.8v3.6h3.6" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>`, F = t`<svg class="icon" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="M13 8a5 5 0 1 1-1.6-3.7" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/><path d="M13.8 1.8v3.6h-3.6" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>`, I = (e) => `
67
+ ${e} { display: block; container-type: inline-size; font-size: 1rem; line-height: 1.5; }
68
+ ${e} .player {
69
+ box-sizing: border-box;
70
+ display: grid;
71
+ gap: 0.5rem;
72
+ margin: 0 0 1rem;
73
+ padding: 0.75rem;
74
+ border: 1px solid transparent;
75
+ }
76
+ ${e} .now { display: flex; align-items: center; min-block-size: 44px; margin: 0; overflow-wrap: anywhere; }
77
+ ${e} .controls {
78
+ display: grid;
79
+ grid-template-columns: auto minmax(6rem, 1fr) auto;
80
+ grid-template-areas: 'buttons seek speed';
81
+ gap: 0.5rem 0.75rem;
82
+ align-items: center;
83
+ }
84
+ ${e} .buttons { grid-area: buttons; display: flex; gap: 0.5rem; }
85
+ ${e} .seek { grid-area: seek; display: flex; align-items: center; gap: 0.5rem; min-inline-size: 0; block-size: 44px; }
86
+ ${e} .seek input { flex: 1; min-inline-size: 0; block-size: 44px; margin: 0; }
87
+ ${e} .time { white-space: nowrap; font-variant-numeric: tabular-nums; }
88
+ ${e} .speed { grid-area: speed; display: flex; align-items: center; gap: 0.5rem; block-size: 44px; }
89
+ ${e} .speed select { box-sizing: border-box; min-block-size: 44px; font: inherit; }
90
+ ${e} button, ${e} .link-button {
91
+ box-sizing: border-box;
92
+ min-block-size: 44px;
93
+ min-inline-size: 44px;
94
+ margin: 0;
95
+ font: inherit;
96
+ line-height: 1.2;
97
+ cursor: pointer;
98
+ }
99
+ ${e} .ctl { display: inline-flex; align-items: center; justify-content: center; gap: 0.375rem; padding: 0.25rem 0.5rem; white-space: nowrap; }
100
+ ${e} .ctl.play { min-inline-size: 5.5rem; }
101
+ ${e} .icon { flex: none; inline-size: 1em; block-size: 1em; }
102
+ ${e} .download { margin: 0 0 1rem; }
103
+ /* One inner span keeps the spaces around “·” (a flex container would drop them). */
104
+ ${e} .download a, ${e} .chapter a { display: inline-flex; align-items: center; min-block-size: 44px; }
105
+ ${e} .chapters { margin: 0; padding: 0; list-style: none; }
106
+ ${e} .chapter {
107
+ display: grid;
108
+ grid-template-columns: minmax(0, 1fr) auto;
109
+ align-items: center;
110
+ column-gap: 0.75rem;
111
+ box-sizing: border-box;
112
+ margin: 0;
113
+ padding: 0.25rem 0;
114
+ border-block-end: 1px solid transparent;
115
+ }
116
+ ${e} .chapter-play {
117
+ display: flex;
118
+ align-items: center;
119
+ gap: 0.75rem;
120
+ min-inline-size: 0;
121
+ padding: 0.25rem 0.5rem;
122
+ border: 0;
123
+ background: none;
124
+ color: inherit;
125
+ text-align: start;
126
+ }
127
+ ${e} .chip { display: inline-flex; flex: none; align-items: center; justify-content: center; gap: 0.375rem; box-sizing: border-box; inline-size: 5rem; min-block-size: 2rem; }
128
+ ${e} .chapter-title { min-inline-size: 0; overflow-wrap: anywhere; }
129
+ ${e} .duration { white-space: nowrap; font-variant-numeric: tabular-nums; }
130
+ ${e} .more { grid-column: 1 / -1; display: flex; flex-wrap: wrap; column-gap: 1rem; padding-inline-start: calc(0.5rem + 5rem + 0.75rem); }
131
+ ${e} .error { grid-column: 1 / -1; margin: 0; padding-inline: 0.5rem; }
132
+ ${e} .visually-hidden {
133
+ position: absolute;
134
+ width: 1px;
135
+ height: 1px;
136
+ margin: -1px;
137
+ padding: 0;
138
+ overflow: hidden;
139
+ clip: rect(0, 0, 0, 0);
140
+ white-space: nowrap;
141
+ border: 0;
142
+ }
143
+ ${e}[hidden], ${e} [hidden] { display: none !important; }
144
+ @container (width < 44rem) {
145
+ ${e} .controls {
146
+ grid-template-columns: auto auto;
147
+ grid-template-areas: 'seek seek' 'buttons speed';
148
+ justify-content: space-between;
149
+ }
150
+ }
151
+ @container (width < 26rem) {
152
+ ${e} .controls { grid-template-columns: auto; grid-template-areas: 'seek' 'buttons' 'speed'; justify-content: stretch; }
153
+ ${e} .more { padding-inline-start: 0.5rem; }
154
+ }
155
+ `, L = c(I(":host")), R = c("var(--uva-color-text, var(--uva-grey-darkest, #2b2b2b))"), z = c("var(--uva-color-text-muted, #4b5563)"), B = c("var(--uva-color-link, var(--uva-brand-blue, #232d4b))"), V = c("var(--uva-color-button-bg, var(--uva-blue-alt, #007bac))"), H = c("var(--uva-color-button-hover-bg, var(--uva-blue-alt-A, #005679))"), U = c("var(--uva-color-button-text, #ffffff)"), W = c("var(--uva-color-surface-raised, #ffffff)"), G = c("var(--uva-color-table-border, var(--uva-grey-100, #dadada))"), K = c("var(--uva-color-accent-bg, var(--uva-brand-blue, #232d4b))"), q = c("var(--uva-color-on-accent, #ffffff)"), J = c("var(--uva-color-current, var(--uva-brand-orange, #e57200))"), Y = c("var(--uva-color-control-border, var(--uva-grey, #808080))"), X = class extends u {
156
+ static {
157
+ this.styles = [
158
+ _,
159
+ L,
160
+ n`
161
+ :host {
162
+ color: ${R};
163
+ }
164
+ .player {
165
+ border-color: ${G};
166
+ border-radius: 5px;
167
+ background: ${W};
168
+ }
169
+ .now .state {
170
+ font-weight: 700;
171
+ }
172
+ .ctl {
173
+ border: 2px solid ${V};
174
+ border-radius: 5px;
175
+ background: ${W};
176
+ color: ${B};
177
+ }
178
+ .ctl.play {
179
+ background: ${V};
180
+ color: ${U};
181
+ }
182
+ .ctl:hover {
183
+ border-color: ${H};
184
+ text-decoration: underline;
185
+ }
186
+ .ctl.play:hover {
187
+ background: ${H};
188
+ }
189
+ .resume {
190
+ padding: 0.25rem 0.75rem;
191
+ border: 2px solid ${V};
192
+ border-radius: 5px;
193
+ background: ${V};
194
+ color: ${U};
195
+ text-align: start;
196
+ }
197
+ .resume:hover {
198
+ background: ${H};
199
+ border-color: ${H};
200
+ }
201
+ .seek input {
202
+ accent-color: ${V};
203
+ }
204
+ .speed label {
205
+ font-weight: 600;
206
+ }
207
+ .speed select {
208
+ padding: 0.25rem 0.5rem;
209
+ border: 1px solid ${Y};
210
+ border-radius: 5px;
211
+ background: ${W};
212
+ color: ${R};
213
+ }
214
+ a {
215
+ color: ${B};
216
+ }
217
+ .chapter {
218
+ border-block-end-color: ${G};
219
+ padding-inline-start: 4px;
220
+ border-inline-start: 4px solid transparent;
221
+ }
222
+ .chapter[aria-current] {
223
+ border-inline-start-color: ${J};
224
+ }
225
+ .chapter-play {
226
+ border-radius: 5px;
227
+ }
228
+ .chip {
229
+ padding: 0.125rem 0.5rem;
230
+ border: 2px solid ${V};
231
+ border-radius: 5px;
232
+ color: ${B};
233
+ font-weight: 600;
234
+ }
235
+ .chapter-play:hover .chip {
236
+ border-color: ${H};
237
+ }
238
+ .chapter-play:hover .chapter-title {
239
+ text-decoration: underline;
240
+ }
241
+ .chapter[aria-current] .chip {
242
+ background: ${V};
243
+ color: ${U};
244
+ }
245
+ .marker {
246
+ display: inline-block;
247
+ margin-inline-start: 0.5rem;
248
+ padding: 0 0.375rem;
249
+ border: 1px solid transparent;
250
+ border-radius: 3px;
251
+ background: ${K};
252
+ color: ${q};
253
+ font-size: 0.875rem;
254
+ font-weight: 700;
255
+ white-space: nowrap;
256
+ }
257
+ .duration {
258
+ color: ${z};
259
+ }
260
+ .error {
261
+ font-weight: 600;
262
+ }
263
+ @media (forced-colors: active) {
264
+ .player,
265
+ .ctl,
266
+ .resume,
267
+ .chip {
268
+ border-color: ButtonText;
269
+ }
270
+ .ctl,
271
+ .chip {
272
+ color: ButtonText;
273
+ }
274
+ .chapter[aria-current] {
275
+ border-inline-start-color: Highlight;
276
+ }
277
+ .chapter[aria-current] .chip,
278
+ .marker {
279
+ forced-color-adjust: none;
280
+ border-color: Highlight;
281
+ background: Highlight;
282
+ color: HighlightText;
283
+ }
284
+ }
285
+ @media (prefers-reduced-motion: reduce) {
286
+ * {
287
+ transition: none !important;
288
+ animation: none !important;
289
+ }
290
+ }
291
+ `
292
+ ];
293
+ }
294
+ constructor() {
295
+ super(), this.label = "", this.continuous = !1, this.noResume = !1, this.storageKey = "", this.downloadHref = "", this.downloadLabel = "Download the whole recording", this.downloadSize = "", this.chapters = [], this.currentIndex = -1, this.isPlaying = !1, this.finished = !1, this.time = 0, this.speed = 1, this.failed = /* @__PURE__ */ new Set(), this.loaded = /* @__PURE__ */ new Map(), this.announcement = "", this.uid = `${v}-${++y}`, this.sourceKey = "", this.restored = !1, this.srcIndex = -1, this.played = /* @__PURE__ */ new Set(), this.completed = /* @__PURE__ */ new Set(), this.lastSave = 0, this.reportedSpeed = 1, this.warned = /* @__PURE__ */ new Set(), this.save = () => {
296
+ let e = this.currentIndex, t = this.chapters[e];
297
+ if (!t || this.finished || this.failed.has(e)) return;
298
+ let n = this.audio, r = this.srcIndex === e && n ? n.currentTime : this.pendingTime ?? this.time;
299
+ this.lastSave = Date.now(), this.write({
300
+ src: t.src,
301
+ chapter: e,
302
+ time: Math.floor(r || 0),
303
+ speed: this.speed
304
+ });
305
+ }, this.onSeekInput = (e) => {
306
+ this.adoptResume(), this.resume = void 0, this.seek(Number(e.target.value));
307
+ }, this.onSpeed = (e) => {
308
+ let t = Number(e.target.value);
309
+ if (!b.includes(t)) return;
310
+ this.speed = t;
311
+ let n = this.audio;
312
+ n && (n.defaultPlaybackRate = n.playbackRate = t), this.announce(`Speed ${t} times`), this.save(), clearTimeout(this.speedTimer), this.speedTimer = setTimeout(() => this.flushSpeed(), S.speed);
313
+ }, this.onResume = () => {
314
+ let e = this.resume;
315
+ e && (d(this, [
316
+ v,
317
+ "resume",
318
+ `chapter ${e.index + 1}`,
319
+ e.index + 1
320
+ ]), this.play(e.index, e.time));
321
+ }, this.onPlay = () => {
322
+ for (let e of j) e !== this && e.pause();
323
+ let e = this.currentIndex, t = this.chapters[e];
324
+ this.isPlaying = !0, t && (this.played.has(e) || (this.played.add(e), d(this, [
325
+ v,
326
+ "play",
327
+ `chapter ${e + 1}`,
328
+ e + 1
329
+ ])), this.announce(`Playing ${t.title}`), this.claimMediaSession(t));
330
+ }, this.onPause = () => {
331
+ this.isPlaying = !1, this.audio?.ended || !this.isConnected || this.failed.has(this.srcIndex) || (this.save(), this.announce("Paused"), this.setPlaybackState("paused"));
332
+ }, this.onTime = () => {
333
+ let e = this.audio;
334
+ if (!e || this.srcIndex !== this.currentIndex) return;
335
+ let t = Math.floor(e.currentTime);
336
+ t !== this.time && (this.time = t), this.isPlaying && Date.now() - this.lastSave >= S.save && this.save();
337
+ }, this.onMeta = () => {
338
+ let e = this.audio, t = this.srcIndex;
339
+ !e || t < 0 || (Number.isFinite(e.duration) && e.duration > 0 && (this.loaded = new Map(this.loaded).set(t, e.duration)), e.playbackRate = this.speed, this.pendingTime !== void 0 && (e.currentTime = Math.min(this.pendingTime, e.duration || this.pendingTime), this.pendingTime = void 0));
340
+ }, this.onEnded = () => {
341
+ let e = this.currentIndex, t = this.chapters[e];
342
+ if (this.isPlaying = !1, !t) return;
343
+ this.completed.has(e) || (this.completed.add(e), d(this, [
344
+ v,
345
+ "complete",
346
+ `chapter ${e + 1}`,
347
+ e + 1
348
+ ]));
349
+ let n = this.chapters[e + 1];
350
+ n ? this.continuous ? this.play(e + 1, 0) : (this.write({
351
+ src: n.src,
352
+ chapter: e + 1,
353
+ time: 0,
354
+ speed: this.speed
355
+ }), this.announce(`Finished ${t.title}`), this.setPlaybackState("paused")) : (this.finished = !0, this.write(null), this.announce("Finished"), this.setPlaybackState("none"));
356
+ }, this.onError = () => {
357
+ this.srcIndex >= 0 && this.audio?.error && this.fail(this.srcIndex);
358
+ }, this.onDownload = (e) => () => d(this, [
359
+ v,
360
+ "download",
361
+ e
362
+ ]), this.source = new g(this, () => this.lightDom, (e) => this.read(e));
363
+ }
364
+ get current() {
365
+ return this.currentIndex;
366
+ }
367
+ get playing() {
368
+ return this.isPlaying;
369
+ }
370
+ createRenderRoot() {
371
+ let e = super.createRenderRoot();
372
+ if (e instanceof ShadowRoot && this.noStyle) {
373
+ let t = L.styleSheet;
374
+ t && (e.adoptedStyleSheets = [t]);
375
+ }
376
+ return e;
377
+ }
378
+ connectedCallback() {
379
+ if (super.connectedCallback(), this.lightDom && this.noStyle) {
380
+ let e = this.getRootNode();
381
+ l(`${v}::structure`, c(I(v)), {
382
+ root: e instanceof ShadowRoot || e instanceof Document ? e : void 0,
383
+ scope: !1
384
+ });
385
+ }
386
+ j.add(this), window.addEventListener("pagehide", this.save);
387
+ }
388
+ disconnectedCallback() {
389
+ super.disconnectedCallback(), j.delete(this), window.removeEventListener("pagehide", this.save), this.save(), this.audio?.pause(), this.releaseMediaSession(), clearTimeout(this.announceTimer), clearTimeout(this.clearTimer), this.flushSpeed();
390
+ }
391
+ warnOnce(e, t) {
392
+ this.warned.has(e) || (this.warned.add(e), console.warn(`${v}: ${t}`));
393
+ }
394
+ read(e) {
395
+ let t = e.find((e) => e instanceof Element && (e.localName === "ol" || e.localName === "ul")), n = this.ownerDocument, r = n.baseURI, i = [], a = "";
396
+ for (let e of t ? [...t.children] : []) {
397
+ if (e.localName !== "li") continue;
398
+ let t = [...e.querySelectorAll("a[href]")], o = t[0], s = o?.getAttribute("href") ?? "";
399
+ if (!o || !k(s, r)) {
400
+ this.warnOnce("chapter", "ignoring a list item without a link to its audio file.");
401
+ continue;
402
+ }
403
+ let c = p(o.childNodes, n), l = [];
404
+ for (let e of t.slice(1)) {
405
+ let t = e.getAttribute("href") ?? "";
406
+ if (!h(t, r)) continue;
407
+ let i = A.flatMap((t) => {
408
+ let n = e.getAttribute(t);
409
+ return n === null ? [] : [[t, n]];
410
+ }), o = p(e.childNodes, n);
411
+ l.push({
412
+ href: t,
413
+ nodes: o.nodes,
414
+ attrs: i
415
+ }), a += `|x${t}${o.key}${JSON.stringify(i)}`;
416
+ }
417
+ let u;
418
+ if (e.hasAttribute("data-download")) {
419
+ let t = m(e.getAttribute("data-download")) || s;
420
+ k(t, r) && (u = {
421
+ href: t,
422
+ size: O(e.getAttribute("data-size"))
423
+ });
424
+ }
425
+ let d = w(o.getAttribute("data-duration"));
426
+ i.push({
427
+ src: new URL(s, r).href,
428
+ href: s,
429
+ title: m(o.textContent) || `Chapter ${i.length + 1}`,
430
+ nodes: c.nodes,
431
+ duration: d,
432
+ extras: l,
433
+ download: u
434
+ }), a += `|${s}${c.key}${d}${u?.href}${u?.size}`;
435
+ }
436
+ a !== this.sourceKey && (this.sourceKey = a, this.chapters = i);
437
+ }
438
+ get storeKey() {
439
+ let e = m(this.storageKey);
440
+ return `${v}:${location.pathname}${e ? `#${e}` : ""}`;
441
+ }
442
+ readSaved() {
443
+ if (!this.noResume) try {
444
+ let e = localStorage.getItem(this.storeKey), t = e ? JSON.parse(e) : void 0;
445
+ return t && typeof t.chapter == "number" && typeof t.time == "number" ? t : void 0;
446
+ } catch {
447
+ return;
448
+ }
449
+ }
450
+ write(e) {
451
+ if (!this.noResume) try {
452
+ e ? localStorage.setItem(this.storeKey, JSON.stringify(e)) : localStorage.removeItem(this.storeKey);
453
+ } catch {}
454
+ }
455
+ willUpdate(e) {
456
+ if (super.willUpdate(e), this.restored || !this.chapters.length) return;
457
+ this.restored = !0;
458
+ let t = this.readSaved();
459
+ if (!t) return;
460
+ b.includes(t.speed) && (this.speed = this.reportedSpeed = t.speed);
461
+ let n = t.src ? this.chapters.findIndex((e) => e.src === t.src) : -1;
462
+ n < 0 && !t.src && t.chapter < this.chapters.length && (n = t.chapter), n < 0 || n === 0 && t.time < 1 || (this.resume = {
463
+ index: n,
464
+ time: Math.max(0, t.time)
465
+ });
466
+ }
467
+ get audio() {
468
+ return this.renderRoot?.querySelector?.("audio") ?? null;
469
+ }
470
+ durationOf(e) {
471
+ return this.loaded.get(e) ?? this.chapters[e]?.duration;
472
+ }
473
+ async play(e = this.currentIndex < 0 ? 0 : this.currentIndex, t) {
474
+ await this.updateComplete;
475
+ let n = this.chapters[e], r = this.audio;
476
+ if (n && r) {
477
+ if (this.resume = void 0, this.finished = !1, e !== this.srcIndex) {
478
+ let i = t ?? (e === this.currentIndex ? this.pendingTime ?? this.time : 0);
479
+ this.currentIndex = e, this.srcIndex = e, this.time = Math.floor(i), this.pendingTime = i || void 0, this.failed.has(e) && (this.failed.delete(e), this.failed = new Set(this.failed)), r.src = n.src, r.defaultPlaybackRate = r.playbackRate = this.speed;
480
+ } else t === void 0 ? r.ended && this.seek(0) : this.seek(t);
481
+ this.currentIndex = e;
482
+ try {
483
+ await r.play();
484
+ } catch (t) {
485
+ let n = t?.name;
486
+ n !== "AbortError" && n !== "NotAllowedError" && this.fail(e);
487
+ }
488
+ }
489
+ }
490
+ pause() {
491
+ this.audio?.pause();
492
+ }
493
+ toggle(e) {
494
+ if (e === this.currentIndex && this.isPlaying) this.pause();
495
+ else {
496
+ let t = e !== this.currentIndex && this.resume?.index === e ? this.resume.time : void 0;
497
+ this.play(e, t);
498
+ }
499
+ }
500
+ seek(e) {
501
+ let t = this.currentIndex, n = this.durationOf(t), r = Math.max(0, n ? Math.min(e, n) : e), i = this.audio;
502
+ i && this.srcIndex === t && i.readyState >= 1 ? i.currentTime = r : this.pendingTime = r, this.time = Math.floor(r);
503
+ }
504
+ currentPosition() {
505
+ let e = this.audio;
506
+ return e && this.srcIndex === this.currentIndex && this.srcIndex >= 0 ? e.currentTime : this.time;
507
+ }
508
+ adoptResume() {
509
+ this.currentIndex >= 0 || (this.currentIndex = this.resume?.index ?? 0, this.time = this.resume?.time ?? 0, this.pendingTime = this.time || void 0, this.resume = void 0);
510
+ }
511
+ skip(e) {
512
+ this.adoptResume(), this.resume = void 0, this.seek(this.currentPosition() + e), this.announce(`At ${D(this.time)}`, !0), this.save();
513
+ }
514
+ flushSpeed() {
515
+ clearTimeout(this.speedTimer), this.speedTimer = void 0, this.speed !== this.reportedSpeed && (this.reportedSpeed = this.speed, d(this, [
516
+ v,
517
+ "speed",
518
+ String(this.speed),
519
+ this.speed
520
+ ]));
521
+ }
522
+ fail(e) {
523
+ this.failed.has(e) || (this.failed = new Set(this.failed).add(e), e === this.currentIndex && (this.isPlaying = !1), this.announce("This chapter could not be played"), f(this, v, "chapter-load"));
524
+ }
525
+ claimMediaSession(e) {
526
+ let t = navigator.mediaSession;
527
+ if (t) try {
528
+ typeof MediaMetadata == "function" && (t.metadata = new MediaMetadata({
529
+ title: e.title,
530
+ album: m(this.label) || m(this.ownerDocument.title)
531
+ })), t.playbackState = "playing";
532
+ let n = (e, n) => {
533
+ try {
534
+ t.setActionHandler(e, n);
535
+ } catch {}
536
+ }, r = this.currentIndex;
537
+ n("play", () => void this.play()), n("pause", () => this.pause()), n("seekbackward", (e) => this.skip(-(e.seekOffset ?? x.back))), n("seekforward", (e) => this.skip(e.seekOffset ?? x.forward)), n("seekto", (e) => e.seekTime !== void 0 && this.seek(e.seekTime)), n("previoustrack", r > 0 ? () => void this.play(r - 1, 0) : null), n("nexttrack", r < this.chapters.length - 1 ? () => void this.play(r + 1, 0) : null), Z.owner = this;
538
+ } catch {}
539
+ }
540
+ setPlaybackState(e) {
541
+ if (Z.owner === this && navigator.mediaSession) try {
542
+ navigator.mediaSession.playbackState = e;
543
+ } catch {}
544
+ }
545
+ releaseMediaSession() {
546
+ let e = navigator.mediaSession;
547
+ if (Z.owner === this && e) {
548
+ Z.owner = void 0;
549
+ for (let t of [
550
+ "play",
551
+ "pause",
552
+ "seekbackward",
553
+ "seekforward",
554
+ "seekto",
555
+ "previoustrack",
556
+ "nexttrack"
557
+ ]) try {
558
+ e.setActionHandler(t, null);
559
+ } catch {}
560
+ try {
561
+ e.metadata = null, e.playbackState = "none";
562
+ } catch {}
563
+ }
564
+ }
565
+ announce(e, t = !1) {
566
+ clearTimeout(this.announceTimer);
567
+ let n = () => {
568
+ clearTimeout(this.clearTimer), this.announcement === e ? (this.announcement = "", this.updateComplete.then(() => requestAnimationFrame(() => this.announcement = e))) : this.announcement = e, this.clearTimer = setTimeout(() => this.announcement = "", C);
569
+ };
570
+ this.announceTimer = setTimeout(n, t ? S.announce : 0);
571
+ }
572
+ sizeText(e) {
573
+ return e ? i`<span aria-hidden="true"> · </span><span class="visually-hidden">, </span>${e}` : s;
574
+ }
575
+ renderNow() {
576
+ let e = this.resume, t = e && this.chapters[e.index];
577
+ if (t) return i`<button type="button" class="resume" @click=${this.onResume}>
578
+ Resume “${t.title}” ${e.time >= 1 ? `at ${T(e.time)}` : "from the start"}
579
+ </button>`;
580
+ let n = this.chapters[this.currentIndex];
581
+ if (!n) return i`<span class="state">Not playing</span>`;
582
+ let r = this.failed.has(this.currentIndex) ? "Could not play" : this.finished ? "Finished" : this.isPlaying ? "Now playing" : "Paused";
583
+ return i`<span><span class="state">${r}:</span> ${n.title}</span>`;
584
+ }
585
+ renderPlayer() {
586
+ let e = this.uid, t = this.currentIndex < 0 ? this.resume?.index ?? 0 : this.currentIndex, n = this.durationOf(t) ?? 0, r = this.currentIndex < 0 ? this.resume?.time ?? 0 : this.time, a = this.isPlaying;
587
+ return i`<div
588
+ class="player"
589
+ part="player"
590
+ role="group"
591
+ aria-label=${m(this.label) || "Player"}
592
+ >
593
+ <p class="now" part="now">${this.renderNow()}</p>
594
+ <div class="controls" part="controls">
595
+ <div class="buttons">
596
+ <button type="button" class="ctl back" @click=${() => this.skip(-x.back)}>
597
+ ${P}<span class="visually-hidden">Back </span>${x.back}<span
598
+ class="visually-hidden"
599
+ >
600
+ seconds</span
601
+ >
602
+ </button>
603
+ <button
604
+ type="button"
605
+ class="ctl play"
606
+ @click=${() => a ? this.pause() : this.toggle(t)}
607
+ >
608
+ ${a ? N : M}<span>${a ? "Pause" : "Play"}</span>
609
+ </button>
610
+ <button type="button" class="ctl forward" @click=${() => this.skip(x.forward)}>
611
+ <span class="visually-hidden">Forward </span>${x.forward}<span
612
+ class="visually-hidden"
613
+ >
614
+ seconds</span
615
+ >${F}
616
+ </button>
617
+ </div>
618
+ <div class="seek">
619
+ <label class="visually-hidden" for="${e}-seek">Position</label>
620
+ <input
621
+ id="${e}-seek"
622
+ type="range"
623
+ min="0"
624
+ max=${Math.max(1, Math.ceil(n))}
625
+ step="1"
626
+ .value=${String(Math.min(r, Math.ceil(n) || r))}
627
+ aria-valuetext="${D(r)} of ${n ? D(n) : "unknown length"}"
628
+ ?disabled=${!n}
629
+ @input=${this.onSeekInput}
630
+ @change=${(e) => e.stopPropagation()}
631
+ />
632
+ <span class="time"
633
+ >${T(r)}<span aria-hidden="true"> / </span
634
+ ><span class="visually-hidden"> of </span>${n ? T(n) : "–:––"}</span
635
+ >
636
+ </div>
637
+ <div class="speed">
638
+ <label for="${e}-speed">Speed</label>
639
+ <select
640
+ id="${e}-speed"
641
+ @change=${(e) => {
642
+ e.stopPropagation(), this.onSpeed(e);
643
+ }}
644
+ @input=${(e) => e.stopPropagation()}
645
+ >
646
+ ${b.map((e) => i`<option value=${e} ?selected=${e === this.speed}>${e}×</option>`)}
647
+ </select>
648
+ </div>
649
+ </div>
650
+ </div>`;
651
+ }
652
+ renderDownload() {
653
+ let e = m(this.downloadHref);
654
+ return e ? k(e, this.ownerDocument.baseURI) ? i`<p class="download" part="download">
655
+ <a href=${e} download @click=${this.onDownload("recording")}
656
+ ><span
657
+ >${m(this.downloadLabel) || "Download the whole recording"}${this.sizeText(O(this.downloadSize))}</span
658
+ ></a
659
+ >
660
+ </p>` : (this.warnOnce("download", "ignoring download-href: it is not http(s), blob: or relative."), s) : s;
661
+ }
662
+ renderChapter(e, t) {
663
+ let n = t === this.currentIndex, r = n && this.isPlaying, a = this.failed.has(t), o = this.chapters[t]?.duration;
664
+ return i`<li class="chapter" part="chapter" aria-current=${n ? "true" : s}>
665
+ <button type="button" class="chapter-play" @click=${() => this.toggle(t)}>
666
+ <span class="chip"
667
+ >${r ? N : M}<span>${r ? "Pause" : "Play"}</span></span
668
+ >
669
+ <span class="chapter-title"
670
+ >${e.nodes}${n ? i` <span class="marker"
671
+ >${a ? "Not played" : r ? "Now playing" : this.finished ? "Finished" : "Paused"}</span
672
+ >` : s}</span
673
+ >
674
+ </button>
675
+ <span class="duration"
676
+ >${o === void 0 ? s : i`<span aria-hidden="true">${T(o)}</span
677
+ ><span class="visually-hidden">${D(o)}</span>`}</span
678
+ >
679
+ ${e.extras.length || e.download ? i`<span class="more"
680
+ >${e.extras.map((e) => i`<a
681
+ href=${e.href}
682
+ hreflang=${Q(e, "hreflang")}
683
+ type=${Q(e, "type")}
684
+ target=${Q(e, "target")}
685
+ rel=${Q(e, "rel")}
686
+ lang=${Q(e, "lang")}
687
+ download=${Q(e, "download")}
688
+ ><span>${e.nodes}</span></a
689
+ >`)}${e.download ? i`<a
690
+ href=${e.download.href}
691
+ download
692
+ @click=${this.onDownload(`chapter ${t + 1}`)}
693
+ ><span
694
+ >Download<span class="visually-hidden"> ${e.title}</span>${this.sizeText(e.download.size)}</span
695
+ ></a
696
+ >` : s}</span
697
+ >` : s}
698
+ ${a ? i`<p class="error" role="note">
699
+ This chapter could not be played.
700
+ <a href=${e.href}>Open its file<span class="visually-hidden"> (${e.title})</span></a>
701
+ </p>` : s}
702
+ </li>`;
703
+ }
704
+ render() {
705
+ let e = this.chapters;
706
+ return e.length ? i`${this.renderPlayer()}${this.renderDownload()}
707
+ <ol class="chapters" part="list">
708
+ ${e.map((e, t) => this.renderChapter(e, t))}
709
+ </ol>
710
+ <audio
711
+ preload="none"
712
+ @play=${this.onPlay}
713
+ @pause=${this.onPause}
714
+ @timeupdate=${this.onTime}
715
+ @loadedmetadata=${this.onMeta}
716
+ @ended=${this.onEnded}
717
+ @error=${this.onError}
718
+ ></audio>
719
+ <span class="visually-hidden" role="status" aria-live="polite" aria-atomic="true"
720
+ >${this.announcement}</span
721
+ >` : s;
722
+ }
723
+ };
724
+ o([e({ type: String })], X.prototype, "label", void 0), o([e({
725
+ type: Boolean,
726
+ reflect: !0
727
+ })], X.prototype, "continuous", void 0), o([e({
728
+ type: Boolean,
729
+ attribute: "no-resume"
730
+ })], X.prototype, "noResume", void 0), o([e({
731
+ type: String,
732
+ attribute: "storage-key"
733
+ })], X.prototype, "storageKey", void 0), o([e({
734
+ type: String,
735
+ attribute: "download-href"
736
+ })], X.prototype, "downloadHref", void 0), o([e({
737
+ type: String,
738
+ attribute: "download-label"
739
+ })], X.prototype, "downloadLabel", void 0), o([e({
740
+ type: String,
741
+ attribute: "download-size"
742
+ })], X.prototype, "downloadSize", void 0), o([r()], X.prototype, "chapters", void 0), o([r()], X.prototype, "currentIndex", void 0), o([r()], X.prototype, "isPlaying", void 0), o([r()], X.prototype, "finished", void 0), o([r()], X.prototype, "time", void 0), o([r()], X.prototype, "speed", void 0), o([r()], X.prototype, "resume", void 0), o([r()], X.prototype, "failed", void 0), o([r()], X.prototype, "loaded", void 0), o([r()], X.prototype, "announcement", void 0);
743
+ var Z = {}, Q = (e, t) => e.attrs.find(([e]) => e === t)?.[1] ?? s;
744
+ // src/components/uvalib-audio/uvalib-audio.ts
745
+ a("uvalib-audio", X);
746
+
747
+ //# sourceMappingURL=uvalib-audio.js.map