itube-modern-player 0.8.2 → 0.8.4

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/core.js CHANGED
@@ -39,7 +39,7 @@ function I(r, t, e) {
39
39
  function x(r, t, e) {
40
40
  return Math.min(e, Math.max(t, r));
41
41
  }
42
- function _(r) {
42
+ function S(r) {
43
43
  if (!Number.isFinite(r) || r < 0) return "0:00";
44
44
  const t = Math.floor(r % 60), e = Math.floor(r / 60 % 60), i = Math.floor(r / 3600), s = i > 0 ? String(e).padStart(2, "0") : String(e), n = String(t).padStart(2, "0");
45
45
  return i > 0 ? `${i}:${s}:${n}` : `${s}:${n}`;
@@ -142,17 +142,17 @@ const g = (r, t = "0 0 24 24") => `<svg viewBox="${t}" fill="currentColor" aria-
142
142
  // Generic "channel" glyph (play badge) for preview meta when a channel is set.
143
143
  channel: g('<path d="M3 5h18a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1Zm7 3.5v7l6-3.5-6-3.5Z"/>')
144
144
  }, V = { en: G };
145
- function qt(r, t) {
145
+ function Vt(r, t) {
146
146
  V[r] = t;
147
147
  }
148
- function Vt(r) {
148
+ function Ot(r) {
149
149
  for (const [t, e] of Object.entries(r))
150
150
  e && (V[t] = e);
151
151
  }
152
152
  function at(r) {
153
153
  return r && V[r] || G;
154
154
  }
155
- function Ot() {
155
+ function Ht() {
156
156
  return Object.keys(V);
157
157
  }
158
158
  function lt(r) {
@@ -208,7 +208,7 @@ function ut(r, t = 1, e = 1e3, i = 100) {
208
208
  }, [, h] = l(0);
209
209
  let c = `M 0 ${i} L 0 ${h.toFixed(1)}`;
210
210
  for (let u = 0; u < s - 1; u++) {
211
- const [f, p] = l(u - 1), [m, v] = l(u), [y, d] = l(u + 1), [k, C] = l(u + 2), A = m + (y - f) * o, O = Math.min(i, Math.max(0, v + (d - p) * o)), P = y - (k - m) * o, R = Math.min(i, Math.max(0, d - (C - v) * o));
211
+ const [f, p] = l(u - 1), [m, v] = l(u), [y, d] = l(u + 1), [k, M] = l(u + 2), A = m + (y - f) * o, O = Math.min(i, Math.max(0, v + (d - p) * o)), P = y - (k - m) * o, R = Math.min(i, Math.max(0, d - (M - v) * o));
212
212
  c += ` C ${A.toFixed(1)} ${O.toFixed(1)} ${P.toFixed(1)} ${R.toFixed(1)} ${y.toFixed(1)} ${d.toFixed(1)}`;
213
213
  }
214
214
  return c += ` L ${e} ${i} Z`, c;
@@ -243,7 +243,7 @@ async function tt(r, t, e, i, s) {
243
243
  mt(c, s);
244
244
  const u = c.querySelector(":scope > Wrapper");
245
245
  if (u) {
246
- const v = S(u.querySelector("VASTAdTagURI"));
246
+ const v = _(u.querySelector("VASTAdTagURI"));
247
247
  if (!v) throw new Error("VAST wrapper without VASTAdTagURI");
248
248
  return tt(r, v, e, i + 1, s);
249
249
  }
@@ -257,35 +257,35 @@ async function tt(r, t, e, i, s) {
257
257
  roll: r.roll,
258
258
  mediaUrl: m.url,
259
259
  mediaType: m.type,
260
- clickThrough: S(p.querySelector("VideoClicks > ClickThrough")) ?? r.clickUrl,
261
- duration: D(S(p.querySelector(":scope > Duration"))),
260
+ clickThrough: _(p.querySelector("VideoClicks > ClickThrough")) ?? r.clickUrl,
261
+ duration: D(_(p.querySelector(":scope > Duration"))),
262
262
  skipOffset: vt(
263
263
  p.getAttribute("skipoffset"),
264
- D(S(p.querySelector(":scope > Duration")))
264
+ D(_(p.querySelector(":scope > Duration")))
265
265
  ),
266
266
  impressions: s.impressions,
267
267
  tracking: s.tracking,
268
- adTitle: S(f.querySelector(":scope > AdTitle")) ?? void 0
268
+ adTitle: _(f.querySelector(":scope > AdTitle")) ?? void 0
269
269
  };
270
270
  }
271
271
  function mt(r, t) {
272
272
  var e, i;
273
273
  for (const s of r.querySelectorAll("Impression")) {
274
- const n = S(s);
274
+ const n = _(s);
275
275
  n && t.impressions.push(n);
276
276
  }
277
277
  for (const s of r.querySelectorAll("Linear > TrackingEvents > Tracking")) {
278
- const n = s.getAttribute("event"), o = S(s);
278
+ const n = s.getAttribute("event"), o = _(s);
279
279
  !n || !o || ["start", "firstQuartile", "midpoint", "thirdQuartile", "complete", "skip", "pause", "resume"].includes(n) && ((e = t.tracking)[n] ?? (e[n] = [])).push(o);
280
280
  }
281
281
  for (const s of r.querySelectorAll("Linear > VideoClicks > ClickTracking")) {
282
- const n = S(s);
282
+ const n = _(s);
283
283
  n && ((i = t.tracking).click ?? (i.click = [])).push(n);
284
284
  }
285
285
  }
286
286
  function ft(r) {
287
287
  const e = [...r.querySelectorAll("MediaFiles > MediaFile")].map((o) => ({
288
- url: S(o) ?? "",
288
+ url: _(o) ?? "",
289
289
  type: o.getAttribute("type") ?? void 0,
290
290
  delivery: o.getAttribute("delivery") ?? "",
291
291
  bitrate: Number(o.getAttribute("bitrate") ?? 0),
@@ -309,7 +309,7 @@ function vt(r, t) {
309
309
  const e = r.trim().match(/^(\d+(?:\.\d+)?)%$/);
310
310
  return e ? t !== void 0 ? Number(e[1]) / 100 * t : void 0 : D(r);
311
311
  }
312
- function F(r) {
312
+ function $(r) {
313
313
  if (r)
314
314
  for (const t of r)
315
315
  try {
@@ -317,7 +317,7 @@ function F(r) {
317
317
  } catch {
318
318
  }
319
319
  }
320
- function S(r) {
320
+ function _(r) {
321
321
  return r?.textContent?.trim().replace(/^<!\[CDATA\[|\]\]>$/g, "").trim() || null;
322
322
  }
323
323
  class gt {
@@ -416,19 +416,19 @@ class gt {
416
416
  const v = a("button", "imp-ad__skip", { type: "button" });
417
417
  v.hidden = !0, p.append(v), s.append(n, h, c, p), this.host.container.append(s), this.layer = s;
418
418
  const y = t.skipOffset ?? this.opts.skipDelay, d = /* @__PURE__ */ new Set(), k = (w) => {
419
- d.has(w) || (d.add(w), F(t.tracking[w]));
419
+ d.has(w) || (d.add(w), $(t.tracking[w]));
420
420
  };
421
- let C = Date.now(), A = -1;
421
+ let M = Date.now(), A = -1;
422
422
  const O = setInterval(() => {
423
423
  if (n.paused) {
424
- C = Date.now();
424
+ M = Date.now();
425
425
  return;
426
426
  }
427
427
  if (n.currentTime !== A) {
428
- A = n.currentTime, C = Date.now();
428
+ A = n.currentTime, M = Date.now();
429
429
  return;
430
430
  }
431
- Date.now() - C >= this.opts.mediaTimeout && (this.host.emitter.emit("aderror", {
431
+ Date.now() - M >= this.opts.mediaTimeout && (this.host.emitter.emit("aderror", {
432
432
  roll: { roll: t.roll },
433
433
  error: new Error(`Ad media stalled for ${this.opts.mediaTimeout} ms — skipping`)
434
434
  }), P());
@@ -438,14 +438,14 @@ class gt {
438
438
  w ? (k("skip"), this.host.emitter.emit("adskip", { ad: t })) : k("complete"), this.host.emitter.emit("adend", { ad: t }), P();
439
439
  };
440
440
  n.addEventListener("playing", () => {
441
- F(t.impressions), k("start"), this.host.emitter.emit("adstart", { ad: t });
441
+ $(t.impressions), k("start"), this.host.emitter.emit("adstart", { ad: t });
442
442
  }, { once: !0, signal: l }), n.addEventListener("playing", () => {
443
443
  h.hidden = !0;
444
444
  }, { signal: l }), n.addEventListener("waiting", () => {
445
445
  h.hidden = !1;
446
446
  }, { signal: l }), n.addEventListener("timeupdate", () => {
447
447
  const w = n.currentTime, B = n.duration;
448
- if (Number.isFinite(B) && B > 0 && (f.textContent = _(Math.max(0, B - w)), w / B >= 0.25 && k("firstQuartile"), w / B >= 0.5 && k("midpoint"), w / B >= 0.75 && k("thirdQuartile")), y >= 0) {
448
+ if (Number.isFinite(B) && B > 0 && (f.textContent = S(Math.max(0, B - w)), w / B >= 0.25 && k("firstQuartile"), w / B >= 0.5 && k("midpoint"), w / B >= 0.75 && k("thirdQuartile")), y >= 0) {
449
449
  const U = Math.ceil(y - w);
450
450
  U > 0 ? (v.hidden = !1, v.disabled = !0, v.textContent = `${i.skipAdIn} ${U}`) : (v.hidden = !1, v.disabled = !1, v.textContent = i.skipAd);
451
451
  }
@@ -463,9 +463,9 @@ class gt {
463
463
  n.addEventListener("playing", () => {
464
464
  Q = !0;
465
465
  }, { once: !0, signal: l }), n.addEventListener("pause", () => {
466
- n.ended || !s.isConnected || (s.classList.add("imp-ad--paused"), Q && !N && (N = !0, F(t.tracking.pause), this.host.emitter.emit("adpause", { ad: t })));
466
+ n.ended || !s.isConnected || (s.classList.add("imp-ad--paused"), Q && !N && (N = !0, $(t.tracking.pause), this.host.emitter.emit("adpause", { ad: t })));
467
467
  }, { signal: l }), n.addEventListener("play", () => {
468
- s.classList.remove("imp-ad--paused"), N && (N = !1, F(t.tracking.resume), this.host.emitter.emit("adresume", { ad: t }));
468
+ s.classList.remove("imp-ad--paused"), N && (N = !1, $(t.tracking.resume), this.host.emitter.emit("adresume", { ad: t }));
469
469
  }, { signal: l }), s.addEventListener("click", (w) => {
470
470
  (w.target === s || s.classList.contains("imp-ad--paused")) && n.paused && n.play().catch(() => {
471
471
  });
@@ -615,8 +615,8 @@ class W {
615
615
  return null;
616
616
  }
617
617
  }
618
- const _t = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 6 6 6-6 6"/></svg>', St = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m15 6-6 6 6 6"/></svg>';
619
- class M {
618
+ const St = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 6 6 6-6 6"/></svg>', _t = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m15 6-6 6 6 6"/></svg>';
619
+ class C {
620
620
  constructor(t) {
621
621
  this.anchor = t, this.outsideListener = null, this.escListener = null, this.root = a("div", "imp-menu"), this.root.hidden = !0, this.backdrop = a("div", "imp-menu__backdrop"), this.backdrop.hidden = !0, this.backdrop.addEventListener("pointerdown", (e) => {
622
622
  e.preventDefault(), this.close();
@@ -654,7 +654,7 @@ class M {
654
654
  const o = a("span", "imp-menu__value");
655
655
  o.textContent = i.value ?? "";
656
656
  const l = a("span", "imp-menu__chevron");
657
- l.innerHTML = _t, s.append(n, o, l), s.addEventListener("click", () => this.renderSettingsDetail(t, i)), e.append(s);
657
+ l.innerHTML = St, s.append(n, o, l), s.addEventListener("click", () => this.renderSettingsDetail(t, i)), e.append(s);
658
658
  }
659
659
  this.root.append(e);
660
660
  }
@@ -676,7 +676,7 @@ class M {
676
676
  if (!e.section) return;
677
677
  this.root.textContent = "";
678
678
  const i = a("button", "imp-menu__item imp-menu__back", { type: "button" }), s = a("span", "imp-menu__chevron");
679
- s.innerHTML = St;
679
+ s.innerHTML = _t;
680
680
  const n = a("span", "imp-menu__label");
681
681
  n.textContent = e.label, i.append(s, n), i.addEventListener("click", () => this.renderSettingsRoot(t)), this.root.append(i), this.root.append(this.renderSection(e.section())), this.root.scrollTop = 0;
682
682
  }
@@ -719,17 +719,19 @@ class M {
719
719
  this.close(), this.backdrop.remove(), this.root.remove();
720
720
  }
721
721
  }
722
- class Lt {
722
+ let Lt = 0;
723
+ class Tt {
723
724
  constructor(t, e = "Seek") {
724
- this.cb = t, this.segments = [], this.duration = 0, this.chapters = [], this.thumbnails = null, this.scrubbing = !1, this.root = a("div", "imp-progress", { role: "slider", "aria-label": e, tabindex: "-1" }), this.buffered = a("div", "imp-progress__buffered"), this.track = a("div", "imp-progress__track"), this.handle = a("div", "imp-progress__handle"), this.tooltipThumb = a("div", "imp-progress__thumb"), this.tooltipChapter = a("div", "imp-progress__tooltip-chapter"), this.tooltipTime = a("div", "imp-progress__tooltip-time"), this.tooltipCaption = a("div", "imp-progress__caption"), this.tooltipCaption.append(this.tooltipChapter, this.tooltipTime), this.tooltip = a("div", "imp-progress__tooltip"), this.tooltip.append(this.tooltipThumb, this.tooltipCaption), this.heatmap = a("div", "imp-progress__heatmap"), this.heatmap.hidden = !0, this.root.append(this.heatmap, this.buffered, this.track, this.handle, this.tooltip), this.setChapters([]), this.bindPointer();
725
+ this.cb = t, this.segments = [], this.duration = 0, this.chapters = [], this.thumbnails = null, this.scrubbing = !1, this.heatmapClipRect = null, this.lastRatio = 0, this.root = a("div", "imp-progress", { role: "slider", "aria-label": e, tabindex: "-1" }), this.buffered = a("div", "imp-progress__buffered"), this.track = a("div", "imp-progress__track"), this.handle = a("div", "imp-progress__handle"), this.tooltipThumb = a("div", "imp-progress__thumb"), this.tooltipChapter = a("div", "imp-progress__tooltip-chapter"), this.tooltipTime = a("div", "imp-progress__tooltip-time"), this.tooltipCaption = a("div", "imp-progress__caption"), this.tooltipCaption.append(this.tooltipChapter, this.tooltipTime), this.tooltip = a("div", "imp-progress__tooltip"), this.tooltip.append(this.tooltipThumb, this.tooltipCaption), this.heatmap = a("div", "imp-progress__heatmap"), this.heatmap.hidden = !0, this.root.append(this.heatmap, this.buffered, this.track, this.handle, this.tooltip), this.setChapters([]), this.bindPointer();
725
726
  }
726
727
  /** Render the popularity curve (empty array hides it). */
727
728
  setHeatmap(t, e = 1) {
728
729
  if (t.length === 0) {
729
- this.heatmap.hidden = !0, this.heatmap.textContent = "";
730
+ this.heatmap.hidden = !0, this.heatmap.textContent = "", this.heatmapClipRect = null;
730
731
  return;
731
732
  }
732
- this.heatmap.innerHTML = `<svg viewBox="0 0 1000 100" preserveAspectRatio="none" aria-hidden="true"><path d="${ut(t, e)}"/></svg>`, this.heatmap.hidden = !1;
733
+ const i = ut(t, e), s = `imp-hm-clip-${++Lt}`;
734
+ this.heatmap.innerHTML = `<svg viewBox="0 0 1000 100" preserveAspectRatio="none" aria-hidden="true"><defs><clipPath id="${s}"><rect x="0" y="0" width="0" height="100"/></clipPath></defs><path d="${i}"/><path class="imp-progress__heatmap-played" d="${i}" clip-path="url(#${s})"/></svg>`, this.heatmapClipRect = this.heatmap.querySelector("clipPath rect"), this.heatmapClipRect?.setAttribute("width", String(this.lastRatio * 1e3)), this.heatmap.hidden = !1;
733
735
  }
734
736
  setDuration(t) {
735
737
  this.duration = Number.isFinite(t) ? t : 0, this.root.classList.toggle("imp-progress--live", !Number.isFinite(t)), this.chapters.length === 0 && this.setChapters([]);
@@ -755,7 +757,7 @@ class Lt {
755
757
  if (e !== this.duration && Number.isFinite(e) && this.setDuration(e), this.scrubbing) return;
756
758
  this.render(t);
757
759
  const s = this.duration > 0 ? x(i / this.duration, 0, 1) : 0;
758
- this.buffered.style.width = `${s * 100}%`, this.root.setAttribute("aria-valuemin", "0"), this.root.setAttribute("aria-valuemax", String(Math.round(this.duration))), this.root.setAttribute("aria-valuenow", String(Math.round(t))), this.root.setAttribute("aria-valuetext", `${_(t)} / ${_(this.duration)}`);
760
+ this.buffered.style.width = `${s * 100}%`, this.root.setAttribute("aria-valuemin", "0"), this.root.setAttribute("aria-valuemax", String(Math.round(this.duration))), this.root.setAttribute("aria-valuenow", String(Math.round(t))), this.root.setAttribute("aria-valuetext", `${S(t)} / ${S(this.duration)}`);
759
761
  }
760
762
  render(t) {
761
763
  for (const { chapter: i, fill: s } of this.segments) {
@@ -763,7 +765,7 @@ class Lt {
763
765
  s.style.transform = `scaleX(${o})`;
764
766
  }
765
767
  const e = this.duration > 0 ? x(t / this.duration, 0, 1) : 0;
766
- this.handle.style.left = `${e * 100}%`;
768
+ this.handle.style.left = `${e * 100}%`, this.lastRatio = e, this.heatmapClipRect?.setAttribute("width", String(e * 1e3));
767
769
  }
768
770
  timeFromEvent(t) {
769
771
  const e = this.root.getBoundingClientRect();
@@ -782,7 +784,7 @@ class Lt {
782
784
  }
783
785
  showTooltip(t) {
784
786
  const e = this.timeFromEvent(t);
785
- this.tooltipTime.textContent = _(e);
787
+ this.tooltipTime.textContent = S(e);
786
788
  const i = et(this.chapters, e), s = !!i?.title;
787
789
  this.tooltipChapter.textContent = i?.title ?? "", this.tooltipChapter.hidden = !s, this.tooltipCaption.classList.toggle("imp-progress__caption--time-only", !s);
788
790
  const n = this.thumbnails?.cueAt(e) ?? null;
@@ -794,11 +796,11 @@ class Lt {
794
796
  this.tooltip.classList.remove("imp-progress__tooltip--visible");
795
797
  }
796
798
  }
797
- class Tt {
799
+ class Bt {
798
800
  constructor(t) {
799
801
  this.player = t, this.rightItems = /* @__PURE__ */ new Map(), this.subtitlesBtn = null, this.settingsBtn = null, this.settingsMenu = null, this.subtitlesMenu = null, this.moreMenu = null, this.moreWrap = null, this.qualityBtn = null, this.qualityMenu = null, this.gearBtn = null, this.gearMenu = null, this.gear = { speed: !1, quality: !1, subtitles: !1 }, this.nextPreviewEl = null, this.nextPreviewOpts = null, this.scenesBtn = null, this.sceneTypeBtn = null, this.sceneTypeMenu = null, this.likeBtn = null, this.dislikeBtn = null, this.likeCountEl = null, this.dislikeCountEl = null, this.prevBtn = null, this.nextBtn = null, this.seekBackBtn = null, this.seekFwdBtn = null, this.centerPlayBtn = null, this.centerPrevBtn = null, this.centerNextBtn = null, this.collapsibles = [], this.overflowed = /* @__PURE__ */ new Set(), this.resizeObserver = null, this.reflowScheduled = !1, this.actionItems = [], this.wasPlayingBeforeScrub = !1, this.disposers = [], this.onWindowResize = null;
800
802
  const { labels: e, icons: i } = t, s = t.controlsOptions;
801
- this.root = a("div", "imp-controls"), this.progress = new Lt({
803
+ this.root = a("div", "imp-controls"), this.progress = new Tt({
802
804
  onSeek: (d) => t.seek(d),
803
805
  onScrubStart: () => {
804
806
  t.scrubbing = !0, this.wasPlayingBeforeScrub = !t.paused, t.pause();
@@ -839,7 +841,7 @@ class Tt {
839
841
  }
840
842
  const p = (d) => d === !1 ? "off" : d === "bar" ? "bar" : "gear", m = p(s.subtitles), v = p(s.quality), y = p(s.speed);
841
843
  if (this.gear = { speed: y === "gear", quality: v === "gear", subtitles: m === "gear" }, m === "bar") {
842
- this.subtitlesBtn = b("imp-btn--subtitles", e.subtitles, i.subtitles), this.subtitlesMenu = new M(this.subtitlesBtn);
844
+ this.subtitlesBtn = b("imp-btn--subtitles", e.subtitles, i.subtitles), this.subtitlesMenu = new C(this.subtitlesBtn);
843
845
  const d = a("div", "imp-controls__menu-anchor");
844
846
  d.append(this.subtitlesBtn, this.subtitlesMenu.root), this.subtitlesBtn.addEventListener("click", () => this.toggleSubtitlesMenu()), this.rightItems.set("subtitles", d), this.registerCollapsible({
845
847
  key: "subtitles",
@@ -850,7 +852,7 @@ class Tt {
850
852
  });
851
853
  }
852
854
  if (v === "bar") {
853
- this.qualityBtn = b("imp-btn--quality", e.quality, i.settings), this.qualityMenu = new M(this.qualityBtn);
855
+ this.qualityBtn = b("imp-btn--quality", e.quality, i.settings), this.qualityMenu = new C(this.qualityBtn);
854
856
  const d = a("div", "imp-controls__menu-anchor");
855
857
  d.append(this.qualityBtn, this.qualityMenu.root), this.qualityBtn.addEventListener("click", () => this.toggleQualityMenu()), this.rightItems.set("quality", d), this.registerCollapsible({
856
858
  key: "quality",
@@ -861,7 +863,7 @@ class Tt {
861
863
  });
862
864
  }
863
865
  if (y === "bar") {
864
- this.settingsBtn = b("imp-btn--speed", e.speed, i.speed), this.settingsMenu = new M(this.settingsBtn);
866
+ this.settingsBtn = b("imp-btn--speed", e.speed, i.speed), this.settingsMenu = new C(this.settingsBtn);
865
867
  const d = a("div", "imp-controls__menu-anchor");
866
868
  d.append(this.settingsBtn, this.settingsMenu.root), this.settingsBtn.addEventListener("click", () => this.toggleSettingsMenu()), this.rightItems.set("speed", d), this.registerCollapsible({
867
869
  key: "speed",
@@ -878,7 +880,7 @@ class Tt {
878
880
  available: () => t.chapterList.length > 0,
879
881
  section: () => this.simpleSection("scenes", e.scenes, i.scenes, () => t.toggleScenesPanel())
880
882
  })), s.sceneTypes !== !1) {
881
- this.sceneTypeBtn = a("button", "imp-btn imp-btn--scene-types", { type: "button" }), this.sceneTypeMenu = new M(this.sceneTypeBtn);
883
+ this.sceneTypeBtn = a("button", "imp-btn imp-btn--scene-types", { type: "button" }), this.sceneTypeMenu = new C(this.sceneTypeBtn);
882
884
  const d = a("div", "imp-controls__menu-anchor");
883
885
  d.append(this.sceneTypeBtn, this.sceneTypeMenu.root), this.sceneTypeBtn.addEventListener("click", () => this.toggleSceneTypeMenu()), this.rightItems.set("sceneTypes", d), this.refreshSceneTypeButton(), this.registerCollapsible({
884
886
  key: "sceneTypes",
@@ -949,7 +951,7 @@ class Tt {
949
951
  this.addStepBadge(d, f, "forward"), d.addEventListener("click", () => t.skip(f)), this.center.append(d);
950
952
  }
951
953
  if (s.playlist && t.hasPlaylist && (this.centerNextBtn = this.makeCenterButton("next", e.next, i.next), this.centerNextBtn.addEventListener("click", () => t.next()), this.center.append(this.centerNextBtn)), this.center.style.display = "none", this.setupNextPreview(), this.gear.speed || this.gear.quality || this.gear.subtitles) {
952
- this.gearBtn = b("imp-btn--settings", e.settings, i.settings), this.gearMenu = new M(this.gearBtn);
954
+ this.gearBtn = b("imp-btn--settings", e.settings, i.settings), this.gearMenu = new C(this.gearBtn);
953
955
  const d = a("div", "imp-controls__menu-anchor");
954
956
  d.append(this.gearBtn, this.gearMenu.root), this.gearBtn.addEventListener("click", () => this.toggleGearMenu()), this.rightItems.set("gear", d), this.registerCollapsible({
955
957
  key: "gear",
@@ -1093,7 +1095,7 @@ class Tt {
1093
1095
  this.player.markSourceDead(s), this.nextPreviewEl && !this.nextPreviewEl.hidden && this.showNextPreview(t);
1094
1096
  }, { once: !0 }), m.append(v), i.duration && s.duration) {
1095
1097
  const y = a("span", "imp-next-preview__duration");
1096
- y.textContent = _(s.duration), m.append(y);
1098
+ y.textContent = S(s.duration), m.append(y);
1097
1099
  }
1098
1100
  e.append(m);
1099
1101
  }
@@ -1159,7 +1161,7 @@ class Tt {
1159
1161
  for (const h of (i.custom ?? []).filter((c) => c.placement !== "bar"))
1160
1162
  this.actionItems.push({ value: `custom:${h.id}`, label: h.title, icon: h.icon, run: () => e.emit("customaction", { id: h.id }) });
1161
1163
  const o = b("imp-btn--more", s.more, n.more);
1162
- this.moreMenu = new M(o);
1164
+ this.moreMenu = new C(o);
1163
1165
  const l = a("div", "imp-controls__menu-anchor imp-controls__more");
1164
1166
  l.append(o, this.moreMenu.root), o.addEventListener("click", () => {
1165
1167
  this.closeMenus(this.moreMenu), this.moreMenu?.toggle(this.buildMoreSections());
@@ -1271,7 +1273,7 @@ class Tt {
1271
1273
  const t = this.player;
1272
1274
  this.disposers.push(
1273
1275
  t.on("timeupdate", ({ currentTime: e, duration: i }) => {
1274
- this.progress.update(e, i, t.bufferedEnd), this.timeLabel && (t.live ? (this.timeLabel.hidden = !0, this.liveBadge.hidden = !1) : (this.timeLabel.hidden = !1, this.liveBadge.hidden = !0, this.timeCurrent.textContent = _(e), this.timeTotal.textContent = ` / ${_(i)}`));
1276
+ this.progress.update(e, i, t.bufferedEnd), this.timeLabel && (t.live ? (this.timeLabel.hidden = !0, this.liveBadge.hidden = !1) : (this.timeLabel.hidden = !1, this.liveBadge.hidden = !0, this.timeCurrent.textContent = S(e), this.timeTotal.textContent = ` / ${S(i)}`));
1275
1277
  }),
1276
1278
  t.on("play", () => this.syncPlayState()),
1277
1279
  t.on("pause", () => this.syncPlayState()),
@@ -1330,7 +1332,7 @@ class Tt {
1330
1332
  this.disposers = [], this.resizeObserver?.disconnect(), this.onWindowResize && window.removeEventListener("resize", this.onWindowResize), this.gearMenu?.destroy(), this.sceneTypeMenu?.destroy(), this.settingsMenu?.destroy(), this.subtitlesMenu?.destroy(), this.qualityMenu?.destroy(), this.moreMenu?.destroy(), this.nextPreviewEl?.remove(), this.root.remove();
1331
1333
  }
1332
1334
  }
1333
- class Bt {
1335
+ class Et {
1334
1336
  constructor(t) {
1335
1337
  this.root = a("div", "imp-poster"), this.image = a("div", "imp-poster__image"), this.image.hidden = !0, this.img = T(""), this.image.append(this.img);
1336
1338
  const e = b("imp-poster__play", t.labels.play, t.icons.bigPlay);
@@ -1353,7 +1355,7 @@ class Bt {
1353
1355
  this.root.hidden = !0;
1354
1356
  }
1355
1357
  }
1356
- class Et {
1358
+ class Ct {
1357
1359
  constructor(t) {
1358
1360
  this.labels = t, this.channelUrl = null, this.custom = null, this.visible = { title: !0, description: !0, sponsor: !0 }, this.root = a("div", "imp-pause-screen"), this.root.hidden = !0, this.defaultContent = a("div", "imp-pause-screen__default"), this.channel = a("button", "imp-channel", { type: "button" }), this.channel.hidden = !0, this.channelAvatar = a("div", "imp-channel__avatar"), this.channelName = a("div", "imp-channel__name"), this.channel.append(this.channelName, this.channelAvatar), this.channel.addEventListener("click", () => {
1359
1361
  this.channelUrl && window.open(this.channelUrl, "_blank", "noopener");
@@ -1439,7 +1441,7 @@ class Mt {
1439
1441
  this.root.hidden = !0;
1440
1442
  }
1441
1443
  }
1442
- class Ct {
1444
+ class Pt {
1443
1445
  constructor(t) {
1444
1446
  this.player = t, this.root = a("div", "imp-upnext"), this.root.hidden = !0;
1445
1447
  }
@@ -1463,7 +1465,7 @@ class Ct {
1463
1465
  this.player.markSourceDead(t), this.root.hidden || this.show();
1464
1466
  }, { once: !0 }), l.append(h), t.duration) {
1465
1467
  const u = a("span", "imp-upnext__duration");
1466
- u.textContent = _(t.duration), l.append(u);
1468
+ u.textContent = S(t.duration), l.append(u);
1467
1469
  }
1468
1470
  const c = a("span", "imp-upnext__thumb-play");
1469
1471
  L(c, this.player.icons.bigPlay), l.append(c), l.addEventListener("click", () => this.player.next()), i.append(l);
@@ -1480,7 +1482,7 @@ class Ct {
1480
1482
  this.root.hidden = !0;
1481
1483
  }
1482
1484
  }
1483
- class Pt {
1485
+ class At {
1484
1486
  constructor(t, e = "sidebar", i) {
1485
1487
  this.player = t, this.root = a("div", `imp-playlist imp-playlist--${e}`), this.root.hidden = !0;
1486
1488
  const s = a("div", "imp-playlist__header"), n = a("div", "imp-playlist__heading");
@@ -1512,7 +1514,7 @@ class Pt {
1512
1514
  const o = a("div", "imp-playlist__meta"), l = a("div", "imp-playlist__title");
1513
1515
  if (l.textContent = t.title ?? `#${e + 1}`, o.append(l), t.duration) {
1514
1516
  const h = a("div", "imp-playlist__duration");
1515
- h.textContent = _(t.duration), o.append(h);
1517
+ h.textContent = S(t.duration), o.append(h);
1516
1518
  }
1517
1519
  i.append(s, o), i.addEventListener("click", () => {
1518
1520
  this.player.playItem(e), window.innerWidth <= 767 && this.hide();
@@ -1532,7 +1534,7 @@ class Pt {
1532
1534
  this.visible ? this.hide() : this.show();
1533
1535
  }
1534
1536
  }
1535
- class At {
1537
+ class Rt {
1536
1538
  constructor(t, e = "bottom") {
1537
1539
  this.player = t, this.items = [], this.root = a("div", `imp-playlist imp-scenes imp-playlist--${e}`), this.root.hidden = !0;
1538
1540
  const i = a("div", "imp-playlist__header"), s = a("span");
@@ -1551,9 +1553,9 @@ class At {
1551
1553
  c.style.width = `${n.xywh.w}px`, c.style.height = `${n.xywh.h}px`, c.style.backgroundImage = `url("${n.src}")`, c.style.backgroundPosition = `-${n.xywh.x}px -${n.xywh.y}px`, c.style.setProperty("--imp-sprite-w", String(n.xywh.w)), s.append(c);
1552
1554
  } else n && s.append(T(n.src));
1553
1555
  const o = a("div", "imp-playlist__meta"), l = a("div", "imp-playlist__title");
1554
- l.textContent = e.title || _(e.start);
1556
+ l.textContent = e.title || S(e.start);
1555
1557
  const h = a("div", "imp-playlist__duration");
1556
- h.textContent = _(e.start), o.append(l, h), i.append(s, o), i.addEventListener("click", () => {
1558
+ h.textContent = S(e.start), o.append(l, h), i.append(s, o), i.addEventListener("click", () => {
1557
1559
  this.player.seek(e.start), this.player.play(), window.innerWidth <= 767 && this.hide();
1558
1560
  }), this.list.append(i), this.items.push(i);
1559
1561
  }
@@ -1583,19 +1585,19 @@ function st(r) {
1583
1585
  const t = r.reason;
1584
1586
  t?.name === "AbortError" && /interrupted by a (new load request|call to pause)/i.test(t.message ?? "") && r.preventDefault();
1585
1587
  }
1586
- function Rt() {
1588
+ function Nt() {
1587
1589
  typeof window < "u" && ++it === 1 && window.addEventListener("unhandledrejection", st);
1588
1590
  }
1589
- function Nt() {
1591
+ function It() {
1590
1592
  typeof window < "u" && --it === 0 && window.removeEventListener("unhandledrejection", st);
1591
1593
  }
1592
- function $(r) {
1594
+ function F(r) {
1593
1595
  console.debug("[itube-player] play() rejected:", r);
1594
1596
  }
1595
1597
  function K(r) {
1596
1598
  return r ? typeof r == "string" ? [{ src: r, label: "Subtitles" }] : Array.isArray(r) ? r : [r] : [];
1597
1599
  }
1598
- const It = {
1600
+ const $t = {
1599
1601
  play: !0,
1600
1602
  progress: !0,
1601
1603
  time: !0,
@@ -1626,14 +1628,14 @@ const It = {
1626
1628
  hideDelay: 2500,
1627
1629
  revealBeforePlay: !0
1628
1630
  };
1629
- class Ht {
1631
+ class Zt {
1630
1632
  constructor(t, e = {}) {
1631
1633
  this.scrubbing = !1, this.emitter = new rt(), this.externalAdvance = !1, this.abort = new AbortController(), this.sources = [], this.deadSources = /* @__PURE__ */ new WeakSet(), this.currentIndex = -1, this.sourceController = null, this.loadToken = 0, this.chapters = [], this.currentChapter = null, this.sceneGroupList = [], this.activeSceneGroupId = "", this.progressiveQuality = -1, this.thumbTrack = null, this.shuffleMode = !1, this.autoAdvanceEnabled = !0, this.persistKey = null, this.persistVolume = !1, this.persistAutoAdvance = !1, this.decodeRecoveries = 0, this.adManager = null, this.playedOnce = !1, this.idleTimer = null, this.peekTimer = null, this.lastRetryAt = 0, this.retryTimer = null, this.errorResumeTime = 0, this.lastPlayheadTime = 0, this.pendingSeek = null, this.destroyed = !1, this.persistTimer = null;
1632
1634
  const i = typeof t == "string" ? document.querySelector(t) : t;
1633
1635
  if (!i) throw new Error(`[itube-player] mount target not found: ${String(t)}`);
1634
1636
  this.mount = i, this.options = e, this.labels = { ...G, ...at(e.language), ...e.labels }, this.icons = { ...ot, ...e.icons };
1635
1637
  const s = e.controls ?? {}, n = s.speed ?? s.settings ?? "gear";
1636
- if (this.controlsOptions = { ...It, ...s, speed: n, settings: n }, this.actionsOptions = e.actions ?? {}, this.playbackRates = e.playbackRates ?? [0.5, 1, 1.5, 2], this.seekStep = e.seekStep ?? 15, this.playlistOptions = { title: "", autoAdvance: !0, loop: !1, shuffle: !1, startIndex: 0, layout: "sidebar", externalAdvance: !1, ...e.playlist }, this.shuffleMode = this.playlistOptions.shuffle, this.externalAdvance = this.playlistOptions.externalAdvance, e.persist) {
1638
+ if (this.controlsOptions = { ...$t, ...s, speed: n, settings: n }, this.actionsOptions = e.actions ?? {}, this.playbackRates = e.playbackRates ?? [0.5, 1, 1.5, 2], this.seekStep = e.seekStep ?? 15, this.playlistOptions = { title: "", autoAdvance: !0, loop: !1, shuffle: !1, startIndex: 0, layout: "sidebar", externalAdvance: !1, ...e.playlist }, this.shuffleMode = this.playlistOptions.shuffle, this.externalAdvance = this.playlistOptions.externalAdvance, e.persist) {
1637
1639
  const y = e.persist === !0 ? {} : e.persist;
1638
1640
  this.persistKey = y.key ?? "itube-player", this.persistVolume = y.volume !== !1, this.persistAutoAdvance = y.autoAdvance !== !1;
1639
1641
  }
@@ -1644,7 +1646,12 @@ class Ht {
1644
1646
  const y = typeof l.borderRadius == "number" ? `${l.borderRadius}px` : l.borderRadius;
1645
1647
  this.container.style.setProperty("--imp-radius", y);
1646
1648
  }
1647
- l?.playButtonStyle === "inverted" && this.container.classList.add("imp-player--play-inverted"), this.video = e.videoElement ?? a("video", "imp-video"), this.video.classList.add("imp-video"), e.playsInline !== !1 && this.video.setAttribute("playsinline", ""), e.crossOrigin !== void 0 && (this.video.crossOrigin = e.crossOrigin), this.video.preload = "metadata", e.loop && (this.video.loop = !0);
1649
+ if (l?.playButtonStyle === "inverted" && this.container.classList.add("imp-player--play-inverted"), this.video = e.videoElement ?? a("video", "imp-video"), this.video.classList.add("imp-video"), e.videoElement && !e.videoElement.paused)
1650
+ try {
1651
+ e.videoElement.pause();
1652
+ } catch {
1653
+ }
1654
+ e.playsInline !== !1 && this.video.setAttribute("playsinline", ""), e.crossOrigin !== void 0 && (this.video.crossOrigin = e.crossOrigin), this.video.preload = "metadata", e.loop && (this.video.loop = !0);
1648
1655
  const h = this.persistVolume ? o : null;
1649
1656
  this.video.volume = x(h?.volume ?? e.volume ?? 1, 0, 1), (h?.muted ?? e.muted) && (this.video.muted = !0);
1650
1657
  const c = a("div", "imp-layer");
@@ -1654,7 +1661,7 @@ class Ht {
1654
1661
  this.clearError(), this.next();
1655
1662
  });
1656
1663
  const f = a("div", "imp-error__actions");
1657
- f.append(this.retryBtn, this.errorNextBtn), this.errorBox.append(this.errorText, f), this.pauseScreen = new Et(this.labels), this.poster = new Bt(this), this.related = new Mt(this), this.related.setOptions(e.related), this.upNext = new Ct(this), this.controls = new Tt(this), this.playlistPanel = new Pt(this, this.playlistOptions.layout, this.playlistOptions.title || void 0), this.scenesPanel = new At(this, e.scenes?.layout ?? "bottom");
1664
+ f.append(this.retryBtn, this.errorNextBtn), this.errorBox.append(this.errorText, f), this.pauseScreen = new Ct(this.labels), this.poster = new Et(this), this.related = new Mt(this), this.related.setOptions(e.related), this.upNext = new Pt(this), this.controls = new Bt(this), this.playlistPanel = new At(this, this.playlistOptions.layout, this.playlistOptions.title || void 0), this.scenesPanel = new Rt(this, e.scenes?.layout ?? "bottom");
1658
1665
  const p = a("div", "imp-layer__middle");
1659
1666
  p.append(this.spinner, this.errorBox, this.controls.center);
1660
1667
  const m = a("div", "imp-layer__bottom");
@@ -1667,7 +1674,7 @@ class Ht {
1667
1674
  if (!y) return;
1668
1675
  const d = this.lastPlayheadTime || this.video.currentTime;
1669
1676
  Number.isFinite(d) && d > 0 && (this.errorResumeTime = d), this.errorText.textContent = this.labels.videoNotFound, this.errorNextBtn.hidden = !this.hasNext, this.errorBox.hidden = !1, this.spinner.hidden = !0, this.poster.hide(), this.container.classList.add("imp-player--error");
1670
- }), Rt(), this.bindVideoEvents(), this.bindIdleHide(), e.keyboard !== !1 && this.bindKeyboard(), this.video.addEventListener("pointerup", (y) => {
1677
+ }), Nt(), this.bindVideoEvents(), this.bindIdleHide(), e.keyboard !== !1 && this.bindKeyboard(), this.video.addEventListener("pointerup", (y) => {
1671
1678
  if (!(this.adPlaying || !this.playedOnce)) {
1672
1679
  if (y.pointerType === "mouse") {
1673
1680
  this.togglePlay();
@@ -1727,11 +1734,11 @@ class Ht {
1727
1734
  if (i === "NotSupportedError" && this.video.readyState === 0) {
1728
1735
  const s = this.loadToken;
1729
1736
  this.video.addEventListener("loadedmetadata", () => {
1730
- s === this.loadToken && this.video.play().catch($);
1737
+ s === this.loadToken && this.video.play().catch(F);
1731
1738
  }, { once: !0, signal: this.abort.signal });
1732
1739
  return;
1733
1740
  }
1734
- i !== "AbortError" && ($(e), this.playedOnce || this.poster.show());
1741
+ i !== "AbortError" && (F(e), this.playedOnce || this.poster.show());
1735
1742
  }
1736
1743
  }
1737
1744
  pause() {
@@ -1860,7 +1867,7 @@ class Ht {
1860
1867
  this.video.currentTime = i;
1861
1868
  } catch {
1862
1869
  }
1863
- s && this.video.play().catch($);
1870
+ s && this.video.play().catch(F);
1864
1871
  }
1865
1872
  }, { once: !0, signal: this.abort.signal }), this.emitter.emit("qualitychange", { label: e[t].label ?? String(e[t].quality ?? t) });
1866
1873
  }
@@ -2077,7 +2084,7 @@ class Ht {
2077
2084
  }
2078
2085
  // === teardown =========================================================
2079
2086
  destroy() {
2080
- this.destroyed || (this.destroyed = !0, this.loadToken++, this.adManager?.destroy(), this.controls.destroy(), this.sourceController?.destroy(), this.abort.abort(), this.idleTimer && clearTimeout(this.idleTimer), this.peekTimer && clearTimeout(this.peekTimer), this.retryTimer && clearTimeout(this.retryTimer), this.persistTimer && (clearTimeout(this.persistTimer), this.persistTimer = null, this.persistState()), this.container.remove(), Nt(), this.emitter.emit("destroy", void 0), this.emitter.removeAll());
2087
+ this.destroyed || (this.destroyed = !0, this.loadToken++, this.adManager?.destroy(), this.controls.destroy(), this.sourceController?.destroy(), this.abort.abort(), this.idleTimer && clearTimeout(this.idleTimer), this.peekTimer && clearTimeout(this.peekTimer), this.retryTimer && clearTimeout(this.retryTimer), this.persistTimer && (clearTimeout(this.persistTimer), this.persistTimer = null, this.persistState()), this.container.remove(), It(), this.emitter.emit("destroy", void 0), this.emitter.removeAll());
2081
2088
  }
2082
2089
  // === internals ========================================================
2083
2090
  async loadItem(t, e, i = !1) {
@@ -2183,7 +2190,7 @@ class Ht {
2183
2190
  e.currentTime = n;
2184
2191
  } catch {
2185
2192
  }
2186
- o && e.play().catch($);
2193
+ o && e.play().catch(F);
2187
2194
  };
2188
2195
  e.readyState >= 1 ? l() : e.addEventListener("loadedmetadata", l, { once: !0, signal: this.abort.signal });
2189
2196
  return;
@@ -2304,21 +2311,21 @@ class Ht {
2304
2311
  }
2305
2312
  export {
2306
2313
  rt as Emitter,
2307
- Ht as Player,
2314
+ Zt as Player,
2308
2315
  W as ThumbnailTrack,
2309
2316
  ct as buildHeatmapValues,
2310
2317
  et as chapterAt,
2311
2318
  ot as defaultIcons,
2312
2319
  G as defaultLabels,
2313
- _ as formatTime,
2320
+ S as formatTime,
2314
2321
  at as getLocale,
2315
2322
  ut as heatmapPath,
2316
2323
  bt as isHlsSource,
2317
2324
  yt as loadChaptersVtt,
2318
2325
  j as normalizeChapters,
2319
- qt as registerLocale,
2320
- Vt as registerLocales,
2321
- Ot as registeredLanguages,
2326
+ Vt as registerLocale,
2327
+ Ot as registerLocales,
2328
+ Ht as registeredLanguages,
2322
2329
  pt as resolveVast
2323
2330
  };
2324
2331
  //# sourceMappingURL=core.js.map