@arraypress/waveform-bar 1.5.0 → 1.6.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.
@@ -191,7 +191,6 @@
191
191
  .wb-artwork {
192
192
  width: 40px;
193
193
  height: 40px;
194
- border-radius: 6px;
195
194
  background: linear-gradient(135deg, var(--wb-accent), var(--wb-accent-light));
196
195
  display: flex;
197
196
  align-items: center;
@@ -435,6 +435,7 @@ var WaveformBar = class {
435
435
  this._initPlayer();
436
436
  this._bindTriggers();
437
437
  this._observeDOM();
438
+ this._watchTheme();
438
439
  if (this.config.persist) {
439
440
  this._restoreVolume();
440
441
  this._restoreFavorites();
@@ -461,6 +462,15 @@ var WaveformBar = class {
461
462
  this.player.destroy();
462
463
  this.player = null;
463
464
  }
465
+ if (this._themeObserver) {
466
+ this._themeObserver.disconnect();
467
+ this._themeObserver = null;
468
+ }
469
+ if (this._themeMq && this._themeMqHandler) {
470
+ this._themeMq.removeEventListener("change", this._themeMqHandler);
471
+ this._themeMq = null;
472
+ this._themeMqHandler = null;
473
+ }
464
474
  if (this._docClickVolume) {
465
475
  document.removeEventListener("click", this._docClickVolume);
466
476
  this._docClickVolume = null;
@@ -1698,6 +1708,43 @@ var WaveformBar = class {
1698
1708
  if (window.matchMedia?.("(prefers-color-scheme: light)").matches) return "light";
1699
1709
  return "dark";
1700
1710
  }
1711
+ /**
1712
+ * Re-detect the page theme and toggle the bar's `wb-light` class (on the bar
1713
+ * and the queue panel) to match, so the bar adapts to a runtime light/dark
1714
+ * switch — not just the theme present when it was first shown. No-op when
1715
+ * `config.theme` is set explicitly.
1716
+ * @private
1717
+ */
1718
+ _refreshTheme() {
1719
+ if (this.config && this.config.theme) return;
1720
+ const theme = this._detectTheme();
1721
+ if (theme === this._resolvedTheme) return;
1722
+ this._resolvedTheme = theme;
1723
+ const light = theme === "light";
1724
+ if (this.barEl) this.barEl.classList.toggle("wb-light", light);
1725
+ if (this.queueEl) this.queueEl.classList.toggle("wb-light", light);
1726
+ }
1727
+ /**
1728
+ * Watch the document for theme changes — a class/attribute flip on
1729
+ * `<html>`/`<body>` (Tailwind `dark`, `data-theme`, `data-color-scheme`) or
1730
+ * an OS `prefers-color-scheme` change — and re-detect. Event-driven
1731
+ * (MutationObserver + matchMedia), never a timer. Torn down in destroy().
1732
+ * @private
1733
+ */
1734
+ _watchTheme() {
1735
+ if (typeof document === "undefined") return;
1736
+ const refresh = () => requestAnimationFrame(() => this._refreshTheme());
1737
+ const opts = { attributes: true, attributeFilter: ["class", "data-theme", "data-color-scheme", "style"] };
1738
+ this._themeObserver = new MutationObserver(refresh);
1739
+ this._themeObserver.observe(document.documentElement, opts);
1740
+ if (document.body) this._themeObserver.observe(document.body, opts);
1741
+ try {
1742
+ this._themeMq = window.matchMedia("(prefers-color-scheme: dark)");
1743
+ this._themeMqHandler = refresh;
1744
+ this._themeMq.addEventListener("change", this._themeMqHandler);
1745
+ } catch (e) {
1746
+ }
1747
+ }
1701
1748
  _updateFavoriteUI() {
1702
1749
  if (!this.favBtnEl) return;
1703
1750
  const fav = this.isFavorited();
@@ -436,6 +436,7 @@
436
436
  this._initPlayer();
437
437
  this._bindTriggers();
438
438
  this._observeDOM();
439
+ this._watchTheme();
439
440
  if (this.config.persist) {
440
441
  this._restoreVolume();
441
442
  this._restoreFavorites();
@@ -462,6 +463,15 @@
462
463
  this.player.destroy();
463
464
  this.player = null;
464
465
  }
466
+ if (this._themeObserver) {
467
+ this._themeObserver.disconnect();
468
+ this._themeObserver = null;
469
+ }
470
+ if (this._themeMq && this._themeMqHandler) {
471
+ this._themeMq.removeEventListener("change", this._themeMqHandler);
472
+ this._themeMq = null;
473
+ this._themeMqHandler = null;
474
+ }
465
475
  if (this._docClickVolume) {
466
476
  document.removeEventListener("click", this._docClickVolume);
467
477
  this._docClickVolume = null;
@@ -1699,6 +1709,43 @@
1699
1709
  if (window.matchMedia?.("(prefers-color-scheme: light)").matches) return "light";
1700
1710
  return "dark";
1701
1711
  }
1712
+ /**
1713
+ * Re-detect the page theme and toggle the bar's `wb-light` class (on the bar
1714
+ * and the queue panel) to match, so the bar adapts to a runtime light/dark
1715
+ * switch — not just the theme present when it was first shown. No-op when
1716
+ * `config.theme` is set explicitly.
1717
+ * @private
1718
+ */
1719
+ _refreshTheme() {
1720
+ if (this.config && this.config.theme) return;
1721
+ const theme = this._detectTheme();
1722
+ if (theme === this._resolvedTheme) return;
1723
+ this._resolvedTheme = theme;
1724
+ const light = theme === "light";
1725
+ if (this.barEl) this.barEl.classList.toggle("wb-light", light);
1726
+ if (this.queueEl) this.queueEl.classList.toggle("wb-light", light);
1727
+ }
1728
+ /**
1729
+ * Watch the document for theme changes — a class/attribute flip on
1730
+ * `<html>`/`<body>` (Tailwind `dark`, `data-theme`, `data-color-scheme`) or
1731
+ * an OS `prefers-color-scheme` change — and re-detect. Event-driven
1732
+ * (MutationObserver + matchMedia), never a timer. Torn down in destroy().
1733
+ * @private
1734
+ */
1735
+ _watchTheme() {
1736
+ if (typeof document === "undefined") return;
1737
+ const refresh = () => requestAnimationFrame(() => this._refreshTheme());
1738
+ const opts = { attributes: true, attributeFilter: ["class", "data-theme", "data-color-scheme", "style"] };
1739
+ this._themeObserver = new MutationObserver(refresh);
1740
+ this._themeObserver.observe(document.documentElement, opts);
1741
+ if (document.body) this._themeObserver.observe(document.body, opts);
1742
+ try {
1743
+ this._themeMq = window.matchMedia("(prefers-color-scheme: dark)");
1744
+ this._themeMqHandler = refresh;
1745
+ this._themeMq.addEventListener("change", this._themeMqHandler);
1746
+ } catch (e) {
1747
+ }
1748
+ }
1702
1749
  _updateFavoriteUI() {
1703
1750
  if (!this.favBtnEl) return;
1704
1751
  const fav = this.isFavorited();
@@ -1 +1 @@
1
- .waveform-bar,.wb-queue-panel{--wb-bg: rgba(17, 17, 17, .95);--wb-border: rgba(255, 255, 255, .1);--wb-text: #ffffff;--wb-text-muted: rgba(255, 255, 255, .5);--wb-accent: #fafafa;--wb-accent-light: #e4e4e7;--wb-on-accent: #18181b;--wb-hover: rgba(255, 255, 255, .08);--wb-tag-bg: rgba(255, 255, 255, .08);--wb-tag-text: rgba(255, 255, 255, .7);--wb-fav-color: #ef4444;--wb-cart-color: #4ade80}.waveform-bar.wb-light,.wb-queue-panel.wb-light{--wb-bg: rgba(255, 255, 255, .95);--wb-border: rgba(0, 0, 0, .1);--wb-text: #1a1a1a;--wb-text-muted: rgba(0, 0, 0, .5);--wb-accent: #18181b;--wb-accent-light: #3f3f46;--wb-on-accent: #fafafa;--wb-hover: rgba(0, 0, 0, .05);--wb-tag-bg: rgba(0, 0, 0, .06);--wb-tag-text: rgba(0, 0, 0, .6)}.waveform-bar.wb-light{box-shadow:0 -1px 8px #00000014}.wb-queue-panel.wb-light{box-shadow:0 -2px 16px #0000001a}.wb-light .wb-volume-popup{box-shadow:0 -2px 12px #0000001a}.waveform-bar{position:fixed;bottom:0;left:0;right:0;background:var(--wb-bg);backdrop-filter:blur(20px);-webkit-backdrop-filter:blur(20px);border-top:1px solid var(--wb-border);z-index:9999;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif;color:var(--wb-text);transform:translateY(100%);opacity:0;transition:transform .5s cubic-bezier(.16,1,.3,1),opacity .4s ease}.waveform-bar.wb-active{transform:translateY(0);opacity:1}.waveform-bar *{box-sizing:border-box}.wb-inner{max-width:var(--wb-max-width, 1400px);margin:0 auto;padding:.5rem 1.5rem;display:flex;align-items:center;gap:.75rem}.wb-left{display:flex;align-items:center;gap:.75rem;flex-shrink:0}.wb-centre{flex:1;min-width:120px;display:flex;align-items:center;gap:.75rem}.wb-right{display:flex;align-items:center;gap:.5rem;flex-shrink:0}.wb-controls{display:flex;align-items:center;gap:.125rem;flex-shrink:0}.wb-btn{width:36px;height:36px;border-radius:50%;border:none;background:transparent;color:var(--wb-text);cursor:pointer;display:flex;align-items:center;justify-content:center;transition:all .15s;padding:0}.wb-btn:hover{background:var(--wb-hover);color:var(--wb-accent)}.wb-btn.wb-disabled{opacity:.25;pointer-events:none}.wb-share.wb-copied{color:#4ade80}.wb-btn-sm{width:32px;height:32px}.wb-play{width:40px;height:40px;background:var(--wb-accent);color:var(--wb-on-accent)}.wb-play:hover{background:var(--wb-accent-light);color:var(--wb-on-accent);transform:scale(1.05)}.wb-track{display:flex;align-items:center;gap:.625rem;min-width:0;max-width:200px;overflow:hidden}.wb-artwork{width:40px;height:40px;border-radius:6px;background:linear-gradient(135deg,var(--wb-accent),var(--wb-accent-light));display:flex;align-items:center;justify-content:center;flex-shrink:0;overflow:hidden}.wb-artwork img{width:100%;height:100%;object-fit:cover}.wb-track-text{min-width:0;overflow:hidden;width:140px}.wb-title,.wb-artist{white-space:nowrap;line-height:1.3;display:block;overflow:hidden}.wb-title{font-size:.8rem;font-weight:600;color:var(--wb-text)}.wb-artist{font-size:.7rem;color:var(--wb-text-muted)}.wb-title.wb-scrolling,.wb-artist.wb-scrolling{overflow:visible}.wb-title.wb-scrolling .wb-scroll-inner,.wb-artist.wb-scrolling .wb-scroll-inner{display:inline-block;padding-right:3rem;animation:wb-marquee var(--wb-scroll-duration, 8s) ease-in-out infinite}@keyframes wb-marquee{0%,10%{transform:translate(0)}45%,55%{transform:translate(var(--wb-scroll-distance, -100px))}90%,to{transform:translate(0)}}.wb-time{font-size:.7rem;color:var(--wb-text-muted);white-space:nowrap;flex-shrink:0;font-variant-numeric:tabular-nums;min-width:70px;text-align:left}.wb-waveform-container{flex:1;min-width:0;width:100%}.wb-waveform-container .waveform-player{width:100%;background:transparent!important;border:none!important}.wb-waveform-container .waveform-player-inner{width:100%;padding:0!important}.wb-waveform-container .waveform-body{width:100%;gap:0!important}.wb-waveform-container .waveform-track{width:100%;padding:0!important}.wb-waveform-container .waveform-marker.wb-marker-active{animation:wb-marker-pulse 2s ease-in-out infinite}@keyframes wb-marker-pulse{0%,to{opacity:1}50%{opacity:.3}}.wb-meta{display:none;align-items:center;gap:.375rem;flex-shrink:0}.wb-tag{display:inline-block;padding:.15rem .5rem;background:var(--wb-tag-bg);color:var(--wb-tag-text);border-radius:4px;font-size:.6rem;font-weight:600;text-transform:uppercase;letter-spacing:.03em;white-space:nowrap}.wb-tag-bpm{color:var(--wb-accent);background:color-mix(in srgb,var(--wb-accent) 12%,transparent)}.wb-tag-key{color:#4ade80;background:#4ade801f}.wb-actions{display:flex;align-items:center;gap:.25rem;flex-shrink:0}.wb-fav-active{color:var(--wb-fav-color)!important}.wb-fav-active:hover{background:#ef44441a}.wb-action-done{color:var(--wb-cart-color)!important;animation:wb-flash .3s ease}@keyframes wb-flash{0%{transform:scale(1)}50%{transform:scale(1.3)}to{transform:scale(1)}}.wb-volume{position:relative;flex-shrink:0}.wb-mute.wb-muted{opacity:.4}.wb-volume-popup{position:absolute;bottom:calc(100% + 12px);left:50%;transform:translate(-50%) translateY(8px);background:var(--wb-bg);backdrop-filter:blur(20px);-webkit-backdrop-filter:blur(20px);border:1px solid var(--wb-border);border-radius:10px;padding:1rem .5rem;box-shadow:0 -8px 30px #0006;z-index:10000;display:flex;align-items:center;justify-content:center;opacity:0;visibility:hidden;pointer-events:none;transition:opacity .2s ease,transform .2s ease,visibility .2s}.wb-volume-popup.wb-volume-open{opacity:1;visibility:visible;pointer-events:auto;transform:translate(-50%) translateY(0)}.wb-volume-slider{-webkit-appearance:none;appearance:none;writing-mode:vertical-lr;direction:rtl;width:6px;height:100px;background:transparent;outline:none;cursor:pointer}.wb-volume-slider::-webkit-slider-runnable-track{width:6px;background:var(--wb-border);border-radius:3px}.wb-volume-slider::-webkit-slider-thumb{-webkit-appearance:none;width:16px;height:16px;background:var(--wb-accent);border-radius:50%;cursor:pointer;margin-left:-5px;transition:transform .15s}.wb-volume-slider::-webkit-slider-thumb:hover{transform:scale(1.2)}.wb-volume-slider::-moz-range-track{width:6px;background:var(--wb-border);border-radius:3px;border:none}.wb-volume-slider::-moz-range-thumb{width:16px;height:16px;background:var(--wb-accent);border:none;border-radius:50%;cursor:pointer}.wb-volume-slider::-moz-range-thumb:hover{transform:scale(1.2)}.wb-repeat{opacity:.4;transition:opacity .15s,color .15s}.wb-repeat.wb-repeat-active{opacity:1;color:var(--wb-accent)}.wb-repeat.wb-repeat-active:hover{background:color-mix(in srgb,var(--wb-accent) 12%,transparent)}.wb-queue-btn.wb-active{color:var(--wb-accent);background:color-mix(in srgb,var(--wb-accent) 12%,transparent)}.wb-queue-panel{position:fixed;bottom:68px;width:340px;max-height:400px;background:var(--wb-bg);backdrop-filter:blur(20px);-webkit-backdrop-filter:blur(20px);border:1px solid var(--wb-border);border-radius:12px;z-index:9999;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif;color:var(--wb-text);display:flex;flex-direction:column;box-shadow:0 -8px 40px #0006;overflow:hidden;opacity:0;visibility:hidden;pointer-events:none;transform:translateY(8px);transition:opacity .2s ease,transform .2s ease,visibility .2s}.wb-queue-panel.wb-queue-open{opacity:1;visibility:visible;pointer-events:auto;transform:translateY(0)}.wb-queue-header{display:flex;align-items:center;justify-content:space-between;padding:.75rem 1rem;border-bottom:1px solid var(--wb-border);flex-shrink:0}.wb-queue-title{font-size:.85rem;font-weight:600;display:flex;align-items:center;gap:.5rem}.wb-queue-title svg{width:16px;height:16px}.wb-queue-count{background:color-mix(in srgb,var(--wb-accent) 15%,transparent);color:var(--wb-accent);padding:.1rem .45rem;border-radius:10px;font-size:.7rem;font-weight:600}.wb-queue-clear{background:transparent;border:none;color:var(--wb-text-muted);cursor:pointer;font-size:.7rem;padding:.25rem .5rem;border-radius:4px;transition:all .15s;width:auto;height:auto}.wb-queue-clear:hover{color:var(--wb-accent);background:var(--wb-hover)}.wb-queue-body{flex:1;overflow-y:auto;padding:.375rem}.wb-queue-body::-webkit-scrollbar{width:5px}.wb-queue-body::-webkit-scrollbar-track{background:transparent}.wb-queue-body::-webkit-scrollbar-thumb{background:var(--wb-border);border-radius:3px}.wb-queue-label{padding:.4rem .5rem .2rem;font-size:.6rem;font-weight:600;text-transform:uppercase;letter-spacing:.08em;color:var(--wb-text-muted)}.wb-queue-item{display:flex;align-items:center;gap:.5rem;padding:.4rem .5rem;border-radius:6px;transition:background .15s;cursor:pointer}.wb-queue-item:hover{background:var(--wb-hover)}.wb-queue-current{background:color-mix(in srgb,var(--wb-accent) 10%,transparent)}.wb-queue-num{width:18px;text-align:center;font-size:.7rem;color:var(--wb-text-muted);flex-shrink:0;display:flex;align-items:center;justify-content:center}.wb-queue-current .wb-queue-num{color:var(--wb-accent)}.wb-queue-info{flex:1;min-width:0}.wb-queue-item-title{font-size:.75rem;font-weight:500;color:var(--wb-text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.wb-queue-current .wb-queue-item-title{color:var(--wb-accent)}.wb-queue-played .wb-queue-item-title{color:var(--wb-text-muted)}.wb-queue-item-artist{font-size:.65rem;color:var(--wb-text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.wb-queue-remove{opacity:0;transition:opacity .15s;background:transparent;border:none;color:var(--wb-text-muted);cursor:pointer;padding:.2rem;border-radius:4px;display:flex;align-items:center;justify-content:center;flex-shrink:0}.wb-queue-item:hover .wb-queue-remove{opacity:1}.wb-queue-remove:hover{color:#ef4444;background:#ef44441a}.wb-queue-empty{display:flex;flex-direction:column;align-items:center;padding:2.5rem 1rem;color:var(--wb-text-muted);text-align:center}.wb-queue-empty svg{opacity:.3;margin-bottom:.5rem}.wb-queue-empty p{font-size:.8rem;margin:0}.wb-icon-swap .wb-show-pause{display:none}.wb-icon-swap .wb-show-play,.wb-icon-swap.wb-playing .wb-show-pause{display:inline}.wb-icon-swap.wb-playing .wb-show-play{display:none}.wb-eq-bars{display:inline-flex;gap:2px;align-items:flex-end;height:14px;vertical-align:middle}.wb-eq-bars span{width:3px;height:4px;background:currentColor;border-radius:1px;opacity:.3}.wb-playing .wb-eq-bars span{opacity:1;animation:wb-eq .8s ease-in-out infinite}.wb-playing .wb-eq-bars span:nth-child(1){animation-delay:0s}.wb-playing .wb-eq-bars span:nth-child(2){animation-delay:.15s}.wb-playing .wb-eq-bars span:nth-child(3){animation-delay:.3s}.wb-playing .wb-eq-bars span:nth-child(4){animation-delay:.45s}@keyframes wb-eq{0%,to{height:4px}50%{height:14px}}.wb-card-highlight{transition:border-color .2s,box-shadow .2s}.wb-card-highlight.wb-current{border-color:var(--wb-accent);box-shadow:0 0 0 1px var(--wb-accent)}.wb-current .wb-accent-current{color:var(--wb-accent)}.wb-pulse-playing.wb-playing{animation:wb-pulse 2s ease-in-out infinite}@keyframes wb-pulse{0%,to{opacity:1}50%{opacity:.7}}.wb-show-if-fav{display:none}.wb-favorited .wb-show-if-fav{display:inline}.wb-favorited .wb-hide-if-fav,.wb-show-if-cart{display:none}.wb-in-cart .wb-show-if-cart{display:inline}.wb-in-cart .wb-hide-if-cart{display:none}@media(max-width:768px){.wb-inner{padding:.5rem 1rem;gap:.5rem;flex-wrap:wrap}.wb-left{width:auto;min-width:auto;flex:1}.wb-centre{order:10;flex-basis:100%;min-width:100%}.wb-right{order:2}.wb-track-text{width:auto;max-width:200px}.wb-meta{display:none!important}.wb-actions,.wb-time{display:none}.wb-queue-panel{left:0;right:0;width:auto;bottom:90px;border-radius:12px 12px 0 0;max-height:50vh}.wb-volume-popup{left:auto;right:0;transform:none}}@media(max-width:480px){.wb-left{gap:.5rem}.wb-track-text{width:auto;max-width:140px}.wb-prev,.wb-next,.wb-repeat,.wb-volume{display:none}.wb-queue-panel{bottom:85px}}.waveform-bar.wb-top{top:0;bottom:auto;border-top:none;border-bottom:1px solid var(--wb-border);transform:translateY(-100%)}.waveform-bar.wb-top.wb-active{transform:translateY(0)}.wb-collapse{flex-shrink:0}.waveform-bar.wb-collapsed{left:auto;right:1rem;bottom:1rem;border:1px solid var(--wb-border);border-radius:999px;overflow:hidden;box-shadow:0 6px 24px #00000040}.waveform-bar.wb-top.wb-collapsed{top:1rem;bottom:auto}.waveform-bar.wb-collapsed .wb-inner{max-width:none;padding:.3rem .45rem;gap:.25rem}.waveform-bar.wb-collapsed .wb-centre,.waveform-bar.wb-collapsed .wb-right,.waveform-bar.wb-collapsed .wb-track,.waveform-bar.wb-collapsed .wb-repeat{display:none}
1
+ .waveform-bar,.wb-queue-panel{--wb-bg: rgba(17, 17, 17, .95);--wb-border: rgba(255, 255, 255, .1);--wb-text: #ffffff;--wb-text-muted: rgba(255, 255, 255, .5);--wb-accent: #fafafa;--wb-accent-light: #e4e4e7;--wb-on-accent: #18181b;--wb-hover: rgba(255, 255, 255, .08);--wb-tag-bg: rgba(255, 255, 255, .08);--wb-tag-text: rgba(255, 255, 255, .7);--wb-fav-color: #ef4444;--wb-cart-color: #4ade80}.waveform-bar.wb-light,.wb-queue-panel.wb-light{--wb-bg: rgba(255, 255, 255, .95);--wb-border: rgba(0, 0, 0, .1);--wb-text: #1a1a1a;--wb-text-muted: rgba(0, 0, 0, .5);--wb-accent: #18181b;--wb-accent-light: #3f3f46;--wb-on-accent: #fafafa;--wb-hover: rgba(0, 0, 0, .05);--wb-tag-bg: rgba(0, 0, 0, .06);--wb-tag-text: rgba(0, 0, 0, .6)}.waveform-bar.wb-light{box-shadow:0 -1px 8px #00000014}.wb-queue-panel.wb-light{box-shadow:0 -2px 16px #0000001a}.wb-light .wb-volume-popup{box-shadow:0 -2px 12px #0000001a}.waveform-bar{position:fixed;bottom:0;left:0;right:0;background:var(--wb-bg);backdrop-filter:blur(20px);-webkit-backdrop-filter:blur(20px);border-top:1px solid var(--wb-border);z-index:9999;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif;color:var(--wb-text);transform:translateY(100%);opacity:0;transition:transform .5s cubic-bezier(.16,1,.3,1),opacity .4s ease}.waveform-bar.wb-active{transform:translateY(0);opacity:1}.waveform-bar *{box-sizing:border-box}.wb-inner{max-width:var(--wb-max-width, 1400px);margin:0 auto;padding:.5rem 1.5rem;display:flex;align-items:center;gap:.75rem}.wb-left{display:flex;align-items:center;gap:.75rem;flex-shrink:0}.wb-centre{flex:1;min-width:120px;display:flex;align-items:center;gap:.75rem}.wb-right{display:flex;align-items:center;gap:.5rem;flex-shrink:0}.wb-controls{display:flex;align-items:center;gap:.125rem;flex-shrink:0}.wb-btn{width:36px;height:36px;border-radius:50%;border:none;background:transparent;color:var(--wb-text);cursor:pointer;display:flex;align-items:center;justify-content:center;transition:all .15s;padding:0}.wb-btn:hover{background:var(--wb-hover);color:var(--wb-accent)}.wb-btn.wb-disabled{opacity:.25;pointer-events:none}.wb-share.wb-copied{color:#4ade80}.wb-btn-sm{width:32px;height:32px}.wb-play{width:40px;height:40px;background:var(--wb-accent);color:var(--wb-on-accent)}.wb-play:hover{background:var(--wb-accent-light);color:var(--wb-on-accent);transform:scale(1.05)}.wb-track{display:flex;align-items:center;gap:.625rem;min-width:0;max-width:200px;overflow:hidden}.wb-artwork{width:40px;height:40px;background:linear-gradient(135deg,var(--wb-accent),var(--wb-accent-light));display:flex;align-items:center;justify-content:center;flex-shrink:0;overflow:hidden}.wb-artwork img{width:100%;height:100%;object-fit:cover}.wb-track-text{min-width:0;overflow:hidden;width:140px}.wb-title,.wb-artist{white-space:nowrap;line-height:1.3;display:block;overflow:hidden}.wb-title{font-size:.8rem;font-weight:600;color:var(--wb-text)}.wb-artist{font-size:.7rem;color:var(--wb-text-muted)}.wb-title.wb-scrolling,.wb-artist.wb-scrolling{overflow:visible}.wb-title.wb-scrolling .wb-scroll-inner,.wb-artist.wb-scrolling .wb-scroll-inner{display:inline-block;padding-right:3rem;animation:wb-marquee var(--wb-scroll-duration, 8s) ease-in-out infinite}@keyframes wb-marquee{0%,10%{transform:translate(0)}45%,55%{transform:translate(var(--wb-scroll-distance, -100px))}90%,to{transform:translate(0)}}.wb-time{font-size:.7rem;color:var(--wb-text-muted);white-space:nowrap;flex-shrink:0;font-variant-numeric:tabular-nums;min-width:70px;text-align:left}.wb-waveform-container{flex:1;min-width:0;width:100%}.wb-waveform-container .waveform-player{width:100%;background:transparent!important;border:none!important}.wb-waveform-container .waveform-player-inner{width:100%;padding:0!important}.wb-waveform-container .waveform-body{width:100%;gap:0!important}.wb-waveform-container .waveform-track{width:100%;padding:0!important}.wb-waveform-container .waveform-marker.wb-marker-active{animation:wb-marker-pulse 2s ease-in-out infinite}@keyframes wb-marker-pulse{0%,to{opacity:1}50%{opacity:.3}}.wb-meta{display:none;align-items:center;gap:.375rem;flex-shrink:0}.wb-tag{display:inline-block;padding:.15rem .5rem;background:var(--wb-tag-bg);color:var(--wb-tag-text);border-radius:4px;font-size:.6rem;font-weight:600;text-transform:uppercase;letter-spacing:.03em;white-space:nowrap}.wb-tag-bpm{color:var(--wb-accent);background:color-mix(in srgb,var(--wb-accent) 12%,transparent)}.wb-tag-key{color:#4ade80;background:#4ade801f}.wb-actions{display:flex;align-items:center;gap:.25rem;flex-shrink:0}.wb-fav-active{color:var(--wb-fav-color)!important}.wb-fav-active:hover{background:#ef44441a}.wb-action-done{color:var(--wb-cart-color)!important;animation:wb-flash .3s ease}@keyframes wb-flash{0%{transform:scale(1)}50%{transform:scale(1.3)}to{transform:scale(1)}}.wb-volume{position:relative;flex-shrink:0}.wb-mute.wb-muted{opacity:.4}.wb-volume-popup{position:absolute;bottom:calc(100% + 12px);left:50%;transform:translate(-50%) translateY(8px);background:var(--wb-bg);backdrop-filter:blur(20px);-webkit-backdrop-filter:blur(20px);border:1px solid var(--wb-border);border-radius:10px;padding:1rem .5rem;box-shadow:0 -8px 30px #0006;z-index:10000;display:flex;align-items:center;justify-content:center;opacity:0;visibility:hidden;pointer-events:none;transition:opacity .2s ease,transform .2s ease,visibility .2s}.wb-volume-popup.wb-volume-open{opacity:1;visibility:visible;pointer-events:auto;transform:translate(-50%) translateY(0)}.wb-volume-slider{-webkit-appearance:none;appearance:none;writing-mode:vertical-lr;direction:rtl;width:6px;height:100px;background:transparent;outline:none;cursor:pointer}.wb-volume-slider::-webkit-slider-runnable-track{width:6px;background:var(--wb-border);border-radius:3px}.wb-volume-slider::-webkit-slider-thumb{-webkit-appearance:none;width:16px;height:16px;background:var(--wb-accent);border-radius:50%;cursor:pointer;margin-left:-5px;transition:transform .15s}.wb-volume-slider::-webkit-slider-thumb:hover{transform:scale(1.2)}.wb-volume-slider::-moz-range-track{width:6px;background:var(--wb-border);border-radius:3px;border:none}.wb-volume-slider::-moz-range-thumb{width:16px;height:16px;background:var(--wb-accent);border:none;border-radius:50%;cursor:pointer}.wb-volume-slider::-moz-range-thumb:hover{transform:scale(1.2)}.wb-repeat{opacity:.4;transition:opacity .15s,color .15s}.wb-repeat.wb-repeat-active{opacity:1;color:var(--wb-accent)}.wb-repeat.wb-repeat-active:hover{background:color-mix(in srgb,var(--wb-accent) 12%,transparent)}.wb-queue-btn.wb-active{color:var(--wb-accent);background:color-mix(in srgb,var(--wb-accent) 12%,transparent)}.wb-queue-panel{position:fixed;bottom:68px;width:340px;max-height:400px;background:var(--wb-bg);backdrop-filter:blur(20px);-webkit-backdrop-filter:blur(20px);border:1px solid var(--wb-border);border-radius:12px;z-index:9999;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif;color:var(--wb-text);display:flex;flex-direction:column;box-shadow:0 -8px 40px #0006;overflow:hidden;opacity:0;visibility:hidden;pointer-events:none;transform:translateY(8px);transition:opacity .2s ease,transform .2s ease,visibility .2s}.wb-queue-panel.wb-queue-open{opacity:1;visibility:visible;pointer-events:auto;transform:translateY(0)}.wb-queue-header{display:flex;align-items:center;justify-content:space-between;padding:.75rem 1rem;border-bottom:1px solid var(--wb-border);flex-shrink:0}.wb-queue-title{font-size:.85rem;font-weight:600;display:flex;align-items:center;gap:.5rem}.wb-queue-title svg{width:16px;height:16px}.wb-queue-count{background:color-mix(in srgb,var(--wb-accent) 15%,transparent);color:var(--wb-accent);padding:.1rem .45rem;border-radius:10px;font-size:.7rem;font-weight:600}.wb-queue-clear{background:transparent;border:none;color:var(--wb-text-muted);cursor:pointer;font-size:.7rem;padding:.25rem .5rem;border-radius:4px;transition:all .15s;width:auto;height:auto}.wb-queue-clear:hover{color:var(--wb-accent);background:var(--wb-hover)}.wb-queue-body{flex:1;overflow-y:auto;padding:.375rem}.wb-queue-body::-webkit-scrollbar{width:5px}.wb-queue-body::-webkit-scrollbar-track{background:transparent}.wb-queue-body::-webkit-scrollbar-thumb{background:var(--wb-border);border-radius:3px}.wb-queue-label{padding:.4rem .5rem .2rem;font-size:.6rem;font-weight:600;text-transform:uppercase;letter-spacing:.08em;color:var(--wb-text-muted)}.wb-queue-item{display:flex;align-items:center;gap:.5rem;padding:.4rem .5rem;border-radius:6px;transition:background .15s;cursor:pointer}.wb-queue-item:hover{background:var(--wb-hover)}.wb-queue-current{background:color-mix(in srgb,var(--wb-accent) 10%,transparent)}.wb-queue-num{width:18px;text-align:center;font-size:.7rem;color:var(--wb-text-muted);flex-shrink:0;display:flex;align-items:center;justify-content:center}.wb-queue-current .wb-queue-num{color:var(--wb-accent)}.wb-queue-info{flex:1;min-width:0}.wb-queue-item-title{font-size:.75rem;font-weight:500;color:var(--wb-text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.wb-queue-current .wb-queue-item-title{color:var(--wb-accent)}.wb-queue-played .wb-queue-item-title{color:var(--wb-text-muted)}.wb-queue-item-artist{font-size:.65rem;color:var(--wb-text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.wb-queue-remove{opacity:0;transition:opacity .15s;background:transparent;border:none;color:var(--wb-text-muted);cursor:pointer;padding:.2rem;border-radius:4px;display:flex;align-items:center;justify-content:center;flex-shrink:0}.wb-queue-item:hover .wb-queue-remove{opacity:1}.wb-queue-remove:hover{color:#ef4444;background:#ef44441a}.wb-queue-empty{display:flex;flex-direction:column;align-items:center;padding:2.5rem 1rem;color:var(--wb-text-muted);text-align:center}.wb-queue-empty svg{opacity:.3;margin-bottom:.5rem}.wb-queue-empty p{font-size:.8rem;margin:0}.wb-icon-swap .wb-show-pause{display:none}.wb-icon-swap .wb-show-play,.wb-icon-swap.wb-playing .wb-show-pause{display:inline}.wb-icon-swap.wb-playing .wb-show-play{display:none}.wb-eq-bars{display:inline-flex;gap:2px;align-items:flex-end;height:14px;vertical-align:middle}.wb-eq-bars span{width:3px;height:4px;background:currentColor;border-radius:1px;opacity:.3}.wb-playing .wb-eq-bars span{opacity:1;animation:wb-eq .8s ease-in-out infinite}.wb-playing .wb-eq-bars span:nth-child(1){animation-delay:0s}.wb-playing .wb-eq-bars span:nth-child(2){animation-delay:.15s}.wb-playing .wb-eq-bars span:nth-child(3){animation-delay:.3s}.wb-playing .wb-eq-bars span:nth-child(4){animation-delay:.45s}@keyframes wb-eq{0%,to{height:4px}50%{height:14px}}.wb-card-highlight{transition:border-color .2s,box-shadow .2s}.wb-card-highlight.wb-current{border-color:var(--wb-accent);box-shadow:0 0 0 1px var(--wb-accent)}.wb-current .wb-accent-current{color:var(--wb-accent)}.wb-pulse-playing.wb-playing{animation:wb-pulse 2s ease-in-out infinite}@keyframes wb-pulse{0%,to{opacity:1}50%{opacity:.7}}.wb-show-if-fav{display:none}.wb-favorited .wb-show-if-fav{display:inline}.wb-favorited .wb-hide-if-fav,.wb-show-if-cart{display:none}.wb-in-cart .wb-show-if-cart{display:inline}.wb-in-cart .wb-hide-if-cart{display:none}@media(max-width:768px){.wb-inner{padding:.5rem 1rem;gap:.5rem;flex-wrap:wrap}.wb-left{width:auto;min-width:auto;flex:1}.wb-centre{order:10;flex-basis:100%;min-width:100%}.wb-right{order:2}.wb-track-text{width:auto;max-width:200px}.wb-meta{display:none!important}.wb-actions,.wb-time{display:none}.wb-queue-panel{left:0;right:0;width:auto;bottom:90px;border-radius:12px 12px 0 0;max-height:50vh}.wb-volume-popup{left:auto;right:0;transform:none}}@media(max-width:480px){.wb-left{gap:.5rem}.wb-track-text{width:auto;max-width:140px}.wb-prev,.wb-next,.wb-repeat,.wb-volume{display:none}.wb-queue-panel{bottom:85px}}.waveform-bar.wb-top{top:0;bottom:auto;border-top:none;border-bottom:1px solid var(--wb-border);transform:translateY(-100%)}.waveform-bar.wb-top.wb-active{transform:translateY(0)}.wb-collapse{flex-shrink:0}.waveform-bar.wb-collapsed{left:auto;right:1rem;bottom:1rem;border:1px solid var(--wb-border);border-radius:999px;overflow:hidden;box-shadow:0 6px 24px #00000040}.waveform-bar.wb-top.wb-collapsed{top:1rem;bottom:auto}.waveform-bar.wb-collapsed .wb-inner{max-width:none;padding:.3rem .45rem;gap:.25rem}.waveform-bar.wb-collapsed .wb-centre,.waveform-bar.wb-collapsed .wb-right,.waveform-bar.wb-collapsed .wb-track,.waveform-bar.wb-collapsed .wb-repeat{display:none}
@@ -1,4 +1,4 @@
1
- (()=>{var n={play:'<svg viewBox="0 0 24 24" width="20" height="20" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>',pause:'<svg viewBox="0 0 24 24" width="20" height="20" fill="currentColor"><path d="M6 4h4v16H6zM14 4h4v16h-4z"/></svg>',prev:'<svg viewBox="0 0 24 24" width="18" height="18" fill="currentColor"><path d="M6 6h2v12H6zm3.5 6l8.5 6V6z"/></svg>',next:'<svg viewBox="0 0 24 24" width="18" height="18" fill="currentColor"><path d="M6 18l8.5-6L6 6v12zM16 6v12h2V6h-2z"/></svg>',queue:'<svg viewBox="0 0 24 24" width="18" height="18" fill="currentColor"><path d="M3 13h2v-2H3v2zm0 4h2v-2H3v2zm0-8h2V7H3v2zm4 4h14v-2H7v2zm0 4h14v-2H7v2zM7 7v2h14V7H7z"/></svg>',share:'<svg viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"/><polyline points="16 6 12 2 8 6"/><line x1="12" y1="2" x2="12" y2="15"/></svg>',music:'<svg viewBox="0 0 24 24" width="18" height="18" fill="currentColor" opacity="0.5"><path d="M12 3v10.55c-.59-.34-1.27-.55-2-.55C7.79 13 6 14.79 6 17s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z"/></svg>',collapse:'<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>',expand:'<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="18 15 12 9 6 15"/></svg>',volHigh:'<svg viewBox="0 0 24 24" width="18" height="18" fill="currentColor"><path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z"/></svg>',volLow:'<svg viewBox="0 0 24 24" width="18" height="18" fill="currentColor"><path d="M18.5 12c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM5 9v6h4l5 5V4L9 9H5z"/></svg>',volMute:'<svg viewBox="0 0 24 24" width="18" height="18" fill="currentColor"><path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51C20.63 14.91 21 13.5 21 12c0-4.28-2.99-7.86-7-8.77v2.06c2.89.86 5 3.54 5 6.71zM4.27 3L3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06c1.38-.31 2.63-.95 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4L9.91 6.09 12 8.18V4z"/></svg>',heart:'<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/></svg>',heartFilled:'<svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/></svg>',cart:'<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2"><circle cx="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/><path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"/></svg>',close:'<svg viewBox="0 0 24 24" width="14" height="14" fill="currentColor"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>',speaker:'<svg viewBox="0 0 24 24" width="14" height="14" fill="currentColor"><path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02z"/></svg>',repeatOff:'<svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor"><path d="M7 7h10v3l4-4-4-4v3H5v6h2V7zm10 10H7v-3l-4 4 4 4v-3h12v-6h-2v4z"/></svg>',repeatAll:'<svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor"><path d="M7 7h10v3l4-4-4-4v3H5v6h2V7zm10 10H7v-3l-4 4 4 4v-3h12v-6h-2v4z"/></svg>',repeatOne:'<svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor"><path d="M7 7h10v3l4-4-4-4v3H5v6h2V7zm10 10H7v-3l-4 4 4 4v-3h12v-6h-2v4z"/><text x="12" y="15" text-anchor="middle" font-size="7" font-weight="bold" fill="currentColor">1</text></svg>'};function d(a){return a?a.split("/").pop().split(".")[0].replace(/[-_]/g," ").replace(/\b\w/g,t=>t.toUpperCase()):"Untitled"}function h(a){if(!a)return"";let t=document.createElement("div");return t.textContent=a,t.innerHTML}function m(a){if(typeof a!="string"||a==="")return!1;try{let t=new URL(a,location.href);return t.protocol==="http:"||t.protocol==="https:"}catch{return!1}}function v(a){if(!a||isNaN(a))return"0:00";let t=Math.floor(a/60),e=Math.floor(a%60);return`${t}:${e.toString().padStart(2,"0")}`}function f(a){let t=a.dataset.wbUrl||a.dataset.url;if(!t)return null;let e={};try{let r=JSON.parse(a.dataset.wbMeta||a.dataset.meta||"{}");e=r&&typeof r=="object"&&!Array.isArray(r)?r:{}}catch{}let i=[];try{let r=JSON.parse(a.dataset.wbMarkers||a.dataset.markers||"null");i=Array.isArray(r)?r:[]}catch{}i=i.map(r=>r&&typeof r=="object"?{...r,time:Number(r.time)}:null).filter(r=>r&&Number.isFinite(r.time));let s=null;try{let r=JSON.parse(a.dataset.wbWaveform||a.dataset.waveform||"null");s=Array.isArray(r)?r:null}catch{}return{url:t,id:a.dataset.wbId||a.dataset.id||t,title:a.dataset.wbTitle||a.dataset.title||d(t),artist:a.dataset.wbArtist||a.dataset.artist||"",artwork:a.dataset.wbArtwork||a.dataset.artwork||"",album:a.dataset.wbAlbum||a.dataset.album||"",link:a.dataset.wbLink||a.dataset.link||"",duration:a.dataset.wbDuration||a.dataset.duration||"",bpm:a.dataset.wbBpm||a.dataset.bpm||"",key:a.dataset.wbKey||a.dataset.key||"",waveform:s,markers:i,favorited:a.dataset.wbFavorited==="true",inCart:a.dataset.wbInCart==="true",meta:e}}function y(a,t){try{sessionStorage.setItem(a,JSON.stringify(t))}catch{}}function _(a){try{let t=sessionStorage.getItem(a);if(!t)return null;let e=JSON.parse(t);return!e||!e.queue||!e.queue.length?null:e}catch{return sessionStorage.removeItem(a),null}}function g(a,t,e,i){try{localStorage.setItem(a+"-vol",JSON.stringify({v:t,m:e,b:i}))}catch{}}function E(a){try{let t=JSON.parse(localStorage.getItem(a+"-vol"));return t?{volume:t.v!=null?t.v:1,muted:t.m||!1,volumeBeforeMute:t.b||1}:null}catch{return null}}function b(a,t){try{localStorage.setItem(a+"-favs",JSON.stringify([...t]))}catch{}}function k(a){try{let t=JSON.parse(localStorage.getItem(a+"-favs"));return Array.isArray(t)?new Set(t):new Set}catch{return new Set}}function w(a,t){if(!(!a||!a.endpoint)){if(typeof a.endpoint=="function"){try{a.endpoint(t)}catch(e){console.warn("[WaveformBar] Action callback error:",e)}return}typeof a.endpoint=="string"&&fetch(a.endpoint,{method:a.method||"POST",headers:{"Content-Type":"application/json",...a.headers||{}},body:JSON.stringify(t)}).catch(e=>console.warn("[WaveformBar] Action request failed:",e))}}function q(a){let t='<div class="wb-left">';t+='<div class="wb-controls">',a.showPrevNext&&(t+=`<button class="wb-btn wb-prev" aria-label="Previous" title="Previous">${n.prev}</button>`),t+=`<button class="wb-btn wb-play" aria-label="Play/Pause" title="Play">
1
+ (()=>{var n={play:'<svg viewBox="0 0 24 24" width="20" height="20" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>',pause:'<svg viewBox="0 0 24 24" width="20" height="20" fill="currentColor"><path d="M6 4h4v16H6zM14 4h4v16h-4z"/></svg>',prev:'<svg viewBox="0 0 24 24" width="18" height="18" fill="currentColor"><path d="M6 6h2v12H6zm3.5 6l8.5 6V6z"/></svg>',next:'<svg viewBox="0 0 24 24" width="18" height="18" fill="currentColor"><path d="M6 18l8.5-6L6 6v12zM16 6v12h2V6h-2z"/></svg>',queue:'<svg viewBox="0 0 24 24" width="18" height="18" fill="currentColor"><path d="M3 13h2v-2H3v2zm0 4h2v-2H3v2zm0-8h2V7H3v2zm4 4h14v-2H7v2zm0 4h14v-2H7v2zM7 7v2h14V7H7z"/></svg>',share:'<svg viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"/><polyline points="16 6 12 2 8 6"/><line x1="12" y1="2" x2="12" y2="15"/></svg>',music:'<svg viewBox="0 0 24 24" width="18" height="18" fill="currentColor" opacity="0.5"><path d="M12 3v10.55c-.59-.34-1.27-.55-2-.55C7.79 13 6 14.79 6 17s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z"/></svg>',collapse:'<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>',expand:'<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="18 15 12 9 6 15"/></svg>',volHigh:'<svg viewBox="0 0 24 24" width="18" height="18" fill="currentColor"><path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z"/></svg>',volLow:'<svg viewBox="0 0 24 24" width="18" height="18" fill="currentColor"><path d="M18.5 12c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM5 9v6h4l5 5V4L9 9H5z"/></svg>',volMute:'<svg viewBox="0 0 24 24" width="18" height="18" fill="currentColor"><path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51C20.63 14.91 21 13.5 21 12c0-4.28-2.99-7.86-7-8.77v2.06c2.89.86 5 3.54 5 6.71zM4.27 3L3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06c1.38-.31 2.63-.95 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4L9.91 6.09 12 8.18V4z"/></svg>',heart:'<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/></svg>',heartFilled:'<svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/></svg>',cart:'<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2"><circle cx="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/><path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"/></svg>',close:'<svg viewBox="0 0 24 24" width="14" height="14" fill="currentColor"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>',speaker:'<svg viewBox="0 0 24 24" width="14" height="14" fill="currentColor"><path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02z"/></svg>',repeatOff:'<svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor"><path d="M7 7h10v3l4-4-4-4v3H5v6h2V7zm10 10H7v-3l-4 4 4 4v-3h12v-6h-2v4z"/></svg>',repeatAll:'<svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor"><path d="M7 7h10v3l4-4-4-4v3H5v6h2V7zm10 10H7v-3l-4 4 4 4v-3h12v-6h-2v4z"/></svg>',repeatOne:'<svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor"><path d="M7 7h10v3l4-4-4-4v3H5v6h2V7zm10 10H7v-3l-4 4 4 4v-3h12v-6h-2v4z"/><text x="12" y="15" text-anchor="middle" font-size="7" font-weight="bold" fill="currentColor">1</text></svg>'};function d(a){return a?a.split("/").pop().split(".")[0].replace(/[-_]/g," ").replace(/\b\w/g,t=>t.toUpperCase()):"Untitled"}function h(a){if(!a)return"";let t=document.createElement("div");return t.textContent=a,t.innerHTML}function p(a){if(typeof a!="string"||a==="")return!1;try{let t=new URL(a,location.href);return t.protocol==="http:"||t.protocol==="https:"}catch{return!1}}function v(a){if(!a||isNaN(a))return"0:00";let t=Math.floor(a/60),e=Math.floor(a%60);return`${t}:${e.toString().padStart(2,"0")}`}function f(a){let t=a.dataset.wbUrl||a.dataset.url;if(!t)return null;let e={};try{let r=JSON.parse(a.dataset.wbMeta||a.dataset.meta||"{}");e=r&&typeof r=="object"&&!Array.isArray(r)?r:{}}catch{}let i=[];try{let r=JSON.parse(a.dataset.wbMarkers||a.dataset.markers||"null");i=Array.isArray(r)?r:[]}catch{}i=i.map(r=>r&&typeof r=="object"?{...r,time:Number(r.time)}:null).filter(r=>r&&Number.isFinite(r.time));let s=null;try{let r=JSON.parse(a.dataset.wbWaveform||a.dataset.waveform||"null");s=Array.isArray(r)?r:null}catch{}return{url:t,id:a.dataset.wbId||a.dataset.id||t,title:a.dataset.wbTitle||a.dataset.title||d(t),artist:a.dataset.wbArtist||a.dataset.artist||"",artwork:a.dataset.wbArtwork||a.dataset.artwork||"",album:a.dataset.wbAlbum||a.dataset.album||"",link:a.dataset.wbLink||a.dataset.link||"",duration:a.dataset.wbDuration||a.dataset.duration||"",bpm:a.dataset.wbBpm||a.dataset.bpm||"",key:a.dataset.wbKey||a.dataset.key||"",waveform:s,markers:i,favorited:a.dataset.wbFavorited==="true",inCart:a.dataset.wbInCart==="true",meta:e}}function y(a,t){try{sessionStorage.setItem(a,JSON.stringify(t))}catch{}}function _(a){try{let t=sessionStorage.getItem(a);if(!t)return null;let e=JSON.parse(t);return!e||!e.queue||!e.queue.length?null:e}catch{return sessionStorage.removeItem(a),null}}function g(a,t,e,i){try{localStorage.setItem(a+"-vol",JSON.stringify({v:t,m:e,b:i}))}catch{}}function E(a){try{let t=JSON.parse(localStorage.getItem(a+"-vol"));return t?{volume:t.v!=null?t.v:1,muted:t.m||!1,volumeBeforeMute:t.b||1}:null}catch{return null}}function b(a,t){try{localStorage.setItem(a+"-favs",JSON.stringify([...t]))}catch{}}function k(a){try{let t=JSON.parse(localStorage.getItem(a+"-favs"));return Array.isArray(t)?new Set(t):new Set}catch{return new Set}}function w(a,t){if(!(!a||!a.endpoint)){if(typeof a.endpoint=="function"){try{a.endpoint(t)}catch(e){console.warn("[WaveformBar] Action callback error:",e)}return}typeof a.endpoint=="string"&&fetch(a.endpoint,{method:a.method||"POST",headers:{"Content-Type":"application/json",...a.headers||{}},body:JSON.stringify(t)}).catch(e=>console.warn("[WaveformBar] Action request failed:",e))}}function q(a){let t='<div class="wb-left">';t+='<div class="wb-controls">',a.showPrevNext&&(t+=`<button class="wb-btn wb-prev" aria-label="Previous" title="Previous">${n.prev}</button>`),t+=`<button class="wb-btn wb-play" aria-label="Play/Pause" title="Play">
2
2
  <span class="wb-icon-play">${n.play}</span>
3
3
  <span class="wb-icon-pause" style="display:none">${n.pause}</span>
4
4
  </button>`,a.showPrevNext&&(t+=`<button class="wb-btn wb-next" aria-label="Next" title="Next">${n.next}</button>`),a.showRepeat&&(t+=`<button class="wb-btn wb-btn-sm wb-repeat" aria-label="Repeat" title="Repeat: Off">${n.repeatOff}</button>`),t+="</div>",t+=`<div class="wb-track">
@@ -22,7 +22,7 @@
22
22
  <button class="wb-btn wb-btn-sm wb-queue-clear" aria-label="Clear queue">Clear</button>
23
23
  </div>
24
24
  <div class="wb-queue-body"></div>
25
- `,a}function S(a,t,e,i,s){if(!a)return;let r=Math.max(0,e.length-1-i);if(t&&(t.textContent=r),e.length===0){a.innerHTML=`<div class="wb-queue-empty">${n.queue}<p>Queue is empty</p></div>`;return}let l="";if(i>=0&&i<e.length){let o=e[i];l+='<div class="wb-queue-label">Now Playing</div>',l+=`<div class="wb-queue-item wb-queue-current" data-qi="${i}">
25
+ `,a}function T(a,t,e,i,s){if(!a)return;let r=Math.max(0,e.length-1-i);if(t&&(t.textContent=r),e.length===0){a.innerHTML=`<div class="wb-queue-empty">${n.queue}<p>Queue is empty</p></div>`;return}let l="";if(i>=0&&i<e.length){let o=e[i];l+='<div class="wb-queue-label">Now Playing</div>',l+=`<div class="wb-queue-item wb-queue-current" data-qi="${i}">
26
26
  <span class="wb-queue-num">${n.speaker}</span>
27
27
  <div class="wb-queue-info">
28
28
  <div class="wb-queue-item-title">${h(o.title)}</div>
@@ -41,7 +41,7 @@
41
41
  <div class="wb-queue-item-title">${h(c.title)}</div>
42
42
  <div class="wb-queue-item-artist">${h(c.artist)}</div>
43
43
  </div>
44
- </div>`}}a.innerHTML=l,a.querySelectorAll(".wb-queue-item[data-qi]").forEach(o=>{o.addEventListener("click",c=>{c.target.closest(".wb-queue-remove")||s.onSkipTo&&s.onSkipTo(parseInt(o.dataset.qi))})}),a.querySelectorAll(".wb-queue-remove").forEach(o=>{o.addEventListener("click",c=>{c.stopPropagation(),s.onRemove&&s.onRemove(parseInt(o.dataset.qi))})})}var T={persist:!0,autoResume:!0,continuous:!0,repeat:"off",showRepeat:!0,showQueue:!0,showPrevNext:!0,showVolume:!0,showMute:!0,showMeta:!0,showTime:!0,showTrackLink:!0,maxMeta:3,defaultArtwork:null,theme:null,wide:!1,maxWidth:null,position:"bottom",collapsible:!1,waveform:!0,errorText:null,share:!1,shareParam:"wt",waveformStyle:"mirror",waveformHeight:32,barWidth:2,barSpacing:2,waveformColor:null,progressColor:null,markerColor:"rgba(255, 255, 255, 0.25)",volume:1,storageKey:"waveform-bar",actions:null,onPlay:null,onPause:null,onTrackChange:null,onQueueChange:null,onVolumeChange:null,onFavorite:null,onCart:null},p=class{constructor(){this.config=null,this.player=null,this.queue=[],this.currentIndex=-1,this.isPlaying=!1,this.isInitialized=!1,this.queueOpen=!1,this.volume=1,this.isMuted=!1,this._volumeBeforeMute=1,this._lastPosition=0,this._favorites=new Set,this._cartItems=new Set,this._observer=null,this._activeMarkers=null,this._currentMarkerIndex=-1,this.repeat="off",this._loadSeq=0,this._restoreSeekTimeout=null,this._externalPlayers=new Map,this.barEl=null,this.queueEl=null,this.waveformContainer=null,this.volumePopupEl=null,this.titleEl=null,this.artistEl=null,this.metaEl=null,this.playBtnEl=null,this.repeatBtnEl=null,this.queueBtnEl=null,this.queueBodyEl=null,this.queueCountEl=null,this.volumeSliderEl=null,this.muteBtnEl=null,this.favBtnEl=null,this.cartBtnEl=null,this.timeCurrentEl=null,this.timeTotalEl=null}init(t={}){this.isInitialized&&this.destroy(),this.config={...T,...t};let e=Number(this.config.volume);if(this.volume=Number.isFinite(e)?Math.max(0,Math.min(1,e)):1,this._shareTarget=this._readShareTarget(),this._shareSeek=this._shareTarget&&!this._shareTarget.id&&!this._shareTarget.url?this._shareTarget.time:null,typeof window.WaveformPlayer>"u")return console.error("[WaveformBar] WaveformPlayer is required."),this;if(this._createBar(),this._createQueue(),this._initPlayer(),this._bindTriggers(),this._observeDOM(),this.config.persist&&(this._restoreVolume(),this._restoreFavorites()),this._seedFromAttributes(),this.config.persist&&this._restoreState(),this._shareTarget&&(this._shareTarget.id||this._shareTarget.url)){let i=this._resolveSharedTrack(this._shareTarget);i&&this._loadSharedTrack(i,this._shareTarget.time)}return this.isInitialized=!0,this._beforeUnloadHandler=()=>this._saveState(),window.addEventListener("beforeunload",this._beforeUnloadHandler),this}destroy(){return this.player&&(this.player.destroy(),this.player=null),this._docClickVolume&&(document.removeEventListener("click",this._docClickVolume),this._docClickVolume=null),this._docClickQueue&&(document.removeEventListener("click",this._docClickQueue),this._docClickQueue=null),this._docClickTriggers&&(document.removeEventListener("click",this._docClickTriggers),this._docClickTriggers=null),this._externalListenersBound&&(document.removeEventListener("waveformplayer:request-play",this._onExtRequestPlay),document.removeEventListener("waveformplayer:request-pause",this._onExtRequestPause),document.removeEventListener("waveformplayer:request-seek",this._onExtRequestSeek),document.removeEventListener("waveformplayer:destroy",this._onExtDestroy),this._onExtRequestPlay=null,this._onExtRequestPause=null,this._onExtRequestSeek=null,this._onExtDestroy=null,this._externalListenersBound=!1),this._externalPlayers=new Map,this._restoreSeekTimeout&&(clearTimeout(this._restoreSeekTimeout),this._restoreSeekTimeout=null),clearTimeout(this._shareFlashTimeout),this._shareFlashTimeout=null,this._loadSeq++,this.barEl&&(this.barEl.remove(),this.barEl=null),this.queueEl&&(this.queueEl.remove(),this.queueEl=null),this._observer&&(this._observer.disconnect(),this._observer=null),this._beforeUnloadHandler&&(window.removeEventListener("beforeunload",this._beforeUnloadHandler),this._beforeUnloadHandler=null),this.volumePopupEl=null,this.queueBtnEl=null,this.titleEl=null,this.artistEl=null,this.metaEl=null,this.playBtnEl=null,this.repeatBtnEl=null,this.waveformContainer=null,this.queueBodyEl=null,this.queueCountEl=null,this.muteBtnEl=null,this.volumeSliderEl=null,this.favBtnEl=null,this.cartBtnEl=null,this.timeCurrentEl=null,this.timeTotalEl=null,document.querySelectorAll(".wb-current,.wb-playing").forEach(t=>t.classList.remove("wb-current","wb-playing")),this.queue=[],this.currentIndex=-1,this.isPlaying=!1,this.queueOpen=!1,this.isInitialized=!1,this.config=null,this}_createBar(){this.barEl=document.createElement("div"),this.barEl.className="waveform-bar";let t=this.config.theme||this._detectTheme();t==="light"&&this.barEl.classList.add("wb-light"),this._resolvedTheme=t;let e=this.config.maxWidth||(this.config.wide?"100%":null);e&&this.barEl.style.setProperty("--wb-max-width",e),this.config.position==="top"&&this.barEl.classList.add("wb-top"),this.barEl.id="waveform-bar",this.barEl.innerHTML=q(this.config),document.body.appendChild(this.barEl),this.titleEl=this.barEl.querySelector(".wb-title"),this.artistEl=this.barEl.querySelector(".wb-artist"),this.metaEl=this.barEl.querySelector(".wb-meta"),this.playBtnEl=this.barEl.querySelector(".wb-play"),this.waveformContainer=this.barEl.querySelector(".wb-waveform-container"),this.queueBtnEl=this.barEl.querySelector(".wb-queue-btn"),this.shareBtnEl=this.barEl.querySelector(".wb-share"),this.muteBtnEl=this.barEl.querySelector(".wb-mute"),this.volumeSliderEl=this.barEl.querySelector(".wb-volume-slider"),this.favBtnEl=this.barEl.querySelector(".wb-fav"),this.cartBtnEl=this.barEl.querySelector(".wb-cart"),this.timeCurrentEl=this.barEl.querySelector(".wb-time-current"),this.timeTotalEl=this.barEl.querySelector(".wb-time-total"),this.collapseBtnEl=this.barEl.querySelector(".wb-collapse"),this.playBtnEl.addEventListener("click",()=>this.togglePlay()),this.collapseBtnEl&&(this.collapseBtnEl.addEventListener("click",()=>this.toggleCollapse()),this._readCollapsed()&&this.collapse());let i=this.barEl.querySelector(".wb-prev"),s=this.barEl.querySelector(".wb-next");i&&i.addEventListener("click",()=>this.previous()),s&&s.addEventListener("click",()=>this.next()),this.shareBtnEl&&this.shareBtnEl.addEventListener("click",()=>this._share()),this.repeatBtnEl=this.barEl.querySelector(".wb-repeat"),this.repeatBtnEl&&(this.repeat=this.config.repeat||"off",this._updateRepeatButton(),this.repeatBtnEl.addEventListener("click",()=>this.cycleRepeat())),this.queueBtnEl&&this.queueBtnEl.addEventListener("click",()=>this.toggleQueuePanel()),this.volumePopupEl=this.barEl.querySelector(".wb-volume-popup");let r=this.barEl.querySelector(".wb-volume");if(this.muteBtnEl&&this.muteBtnEl.addEventListener("click",l=>{l.stopPropagation(),this.toggleMute()}),r&&this.volumePopupEl){let l;r.addEventListener("mouseenter",()=>{clearTimeout(l),this.openVolumePopup()}),r.addEventListener("mouseleave",()=>{l=setTimeout(()=>this.closeVolumePopup(),300)})}this.volumeSliderEl&&this.volumeSliderEl.addEventListener("input",l=>{l.stopPropagation(),this.setVolume(parseInt(l.target.value)/100)}),this._docClickVolume=l=>{this.volumePopupEl?.classList.contains("wb-volume-open")&&!this.barEl?.querySelector(".wb-volume")?.contains(l.target)&&this.closeVolumePopup()},document.addEventListener("click",this._docClickVolume),this.favBtnEl&&this.favBtnEl.addEventListener("click",()=>this.toggleFavorite()),this.cartBtnEl&&this.cartBtnEl.addEventListener("click",()=>this.addToCart()),this.config.showTrackLink&&this.barEl.querySelector(".wb-track").addEventListener("click",()=>{let l=this.getCurrentTrack();l&&l.link&&m(l.link)&&(window.location.href=l.link)})}_createQueue(){this.config.showQueue&&(this.queueEl=x(),this._resolvedTheme==="light"&&this.queueEl.classList.add("wb-light"),document.body.appendChild(this.queueEl),this.queueBodyEl=this.queueEl.querySelector(".wb-queue-body"),this.queueCountEl=this.queueEl.querySelector(".wb-queue-count"),this.queueEl.querySelector(".wb-queue-clear").addEventListener("click",()=>this.clearQueue()),this._docClickQueue=t=>{this.queueOpen&&!this.queueEl?.contains(t.target)&&!this.queueBtnEl?.contains(t.target)&&this.closeQueuePanel()},document.addEventListener("click",this._docClickQueue))}_initPlayer(){let t={showControls:!1,showInfo:!1,waveformStyle:this.config.waveform===!1?"seekbar":this.config.waveformStyle,height:this.config.waveformHeight,barWidth:this.config.barWidth,barSpacing:this.config.barSpacing,errorText:this.config.errorText,singlePlay:!1,onPlay:()=>{this.isPlaying=!0,this._updatePlayButton(),this._syncPageState(),this._pumpExternalPlayState(!0);let e=this.getCurrentTrack();this._emit("play",{track:e}),this.config.onPlay&&this.config.onPlay(e)},onPause:()=>{this.isPlaying=!1,this._updatePlayButton(),this._syncPageState(),this._pumpExternalPlayState(!1),this._saveState();let e=this.getCurrentTrack();this._emit("pause",{track:e}),this.config.onPause&&this.config.onPause(e)},onEnd:()=>{if(this.isPlaying=!1,this._updatePlayButton(),this._syncPageState(),this._pumpExternalPlayState(!1),this.timeCurrentEl&&(this.timeCurrentEl.textContent="0:00"),this.repeat==="one"){this.player&&(this.player.seekTo(0),this.player.play().catch(()=>{}));return}this.config.continuous&&this.currentIndex<this.queue.length-1?(this.currentIndex++,this._loadCurrentTrack()):this.repeat==="all"&&this.queue.length>0&&(this.currentIndex=0,this._loadCurrentTrack())},onError:()=>{this.isPlaying=!1,this._updatePlayButton(),this._syncPageState(),this._pumpExternalPlayState(!1);let e=this.getCurrentTrack();this._emit("error",{track:e}),this.config.continuous&&this.currentIndex<this.queue.length-1&&(this.currentIndex++,this._loadCurrentTrack())},onTimeUpdate:(e,i)=>{this._lastPosition=e,this.timeCurrentEl&&(this.timeCurrentEl.textContent=v(e)),this.timeTotalEl&&(this.timeTotalEl.textContent=v(i)),this._pumpExternalProgress(e,i),(!this._lastSaveTime||e-this._lastSaveTime>2)&&(this._lastSaveTime=e,this._saveState()),this._activeMarkers&&this._checkMarkerBoundary(e)},onLoad:()=>{this._shareSeek!=null&&this.player&&(this.player.seekTo(this._shareSeek),this._shareSeek=null)}};this.config.waveformColor&&(t.waveformColor=this.config.waveformColor),this.config.progressColor&&(t.progressColor=this.config.progressColor),this.player=new window.WaveformPlayer(this.waveformContainer,t),this.player.setVolume(this.volume)}_bindTriggers(){this._docClickTriggers||(this._docClickTriggers=t=>{let e=t.target?.closest?.("[data-wb-queue]");if(e){t.preventDefault();let s=f(e);s&&this.addToQueue(s);return}let i=t.target?.closest?.("[data-wb-play]");if(i){t.preventDefault();let s=f(i);s&&this.play(s)}},document.addEventListener("click",this._docClickTriggers)),this._attachExternalPlayers()}_attachExternalPlayers(){this._externalListenersBound||(this._externalListenersBound=!0,this._onExtRequestPlay=s=>{let r=s.detail;!r||!r.url||(s.preventDefault(),this.play(r))},this._onExtRequestPause=s=>{let r=s.detail;if(!r||!r.url)return;let l=this.getCurrentTrack();l&&l.url===r.url&&(s.preventDefault(),this.isPlaying&&this.togglePlay())},this._onExtRequestSeek=s=>{let r=s.detail;if(!r||!r.url||typeof r.percent!="number")return;let l=this.getCurrentTrack();l&&l.url===r.url&&this.player&&this.player.audio&&(s.preventDefault(),this.player.seekToPercent(r.percent))},this._onExtDestroy=s=>{let r=s.detail&&s.detail.player;!r||!this._externalPlayers||this._externalPlayers.forEach(l=>l.delete(r))},document.addEventListener("waveformplayer:request-play",this._onExtRequestPlay),document.addEventListener("waveformplayer:request-pause",this._onExtRequestPause),document.addEventListener("waveformplayer:request-seek",this._onExtRequestSeek),document.addEventListener("waveformplayer:destroy",this._onExtDestroy));let t=this._externalPlayers||new Map;this._externalPlayers=new Map;let e=window.WaveformPlayer;if(!e||!e.instances)return;let i=[];if(document.querySelectorAll('[data-waveform-player][data-audio-mode="external"]').forEach(s=>{let r=e.instances.get(s.id);if(!r||!r.options||!r.options.url)return;let l=r.options.url;this._externalPlayers.has(l)||this._externalPlayers.set(l,new Set),this._externalPlayers.get(l).add(r),t.get(l)&&t.get(l).has(r)||i.push({inst:r,url:l})}),i.length){let s=this.getCurrentTrack(),r=s?s.url:null;i.forEach(({inst:l,url:u})=>{let o=u===r;typeof l.setPlayingState=="function"&&l.setPlayingState(o&&this.isPlaying),o&&typeof l.setProgress=="function"&&this.player&&this.player.audio&&l.setProgress(this.player.audio.currentTime||0,this.player.audio.duration||0)})}}_pumpExternalPlayState(t){if(!this._externalPlayers||this._externalPlayers.size===0)return;let e=this.getCurrentTrack(),i=e?e.url:null;this._externalPlayers.forEach((s,r)=>{let l=r===i;s.forEach(u=>{typeof u.setPlayingState=="function"&&u.setPlayingState(l&&t)})})}_pumpExternalProgress(t,e){if(!this._externalPlayers||this._externalPlayers.size===0)return;let i=this.getCurrentTrack();if(!i)return;let s=this._externalPlayers.get(i.url);s&&s.forEach(r=>{typeof r.setProgress=="function"&&r.setProgress(t,e)})}_observeDOM(){typeof MutationObserver>"u"||(this._observer=new MutationObserver(()=>{this._attachExternalPlayers(),this._syncPageState()}),this._observer.observe(document.body,{childList:!0,subtree:!0}))}play(t){let e=typeof t=="string"?{url:t,id:t,title:d(t)}:t;if(!e||!e.url)return this;let i=this.getCurrentTrack();if(i&&i.url===e.url)return this.togglePlay(),this;let s=this.queue.findIndex(r=>r.url===e.url);if(s>=0)this.queue[s]={...this.queue[s],...e},this.currentIndex=s;else{let r=this.currentIndex+1;this.queue.splice(r,0,e),this.currentIndex=r}return this._loadCurrentTrack(),this}addToQueue(t){let e=typeof t=="string"?{url:t,id:t,title:d(t)}:t;return!e||!e.url?this:this.queue.find(i=>i.url===e.url)?this:(this.queue.push(e),this._renderQueue(),this._saveState(),this._updateNavButtons(),this.currentIndex===-1&&(this.currentIndex=0,this._loadCurrentTrack()),this.config.onQueueChange&&this.config.onQueueChange(this.queue,this.currentIndex),this)}togglePlay(){return this.player?(this.isPlaying?this.player.pause():this.player.play(),this):this}pause(){return this.player&&this.isPlaying&&this.player.pause(),this}next(){return this.currentIndex<this.queue.length-1?(this.currentIndex++,this._loadCurrentTrack()):this.repeat==="all"&&this.queue.length>0&&(this.currentIndex=0,this._loadCurrentTrack()),this}previous(){return this.player&&this.player.audio&&this.player.audio.currentTime>3?(this.player.seekTo(0),this):(this.currentIndex>0?(this.currentIndex--,this._loadCurrentTrack()):this.repeat==="all"&&this.queue.length>0&&(this.currentIndex=this.queue.length-1,this._loadCurrentTrack()),this)}skipTo(t){return t<0||t>=this.queue.length?this:t===this.currentIndex?(this.togglePlay(),this):(this.currentIndex=t,this._loadCurrentTrack(),this)}seekToMarker(t){if(!this._activeMarkers||t<0||t>=this._activeMarkers.length)return this;let e=this._activeMarkers[t];return this.player&&(this.player.seekTo(e.time),this.isPlaying||this.togglePlay()),this}seekToMarkerByLabel(t){if(!this._activeMarkers)return this;let e=this._activeMarkers.findIndex(i=>(i.label||i.title||"").toLowerCase()===t.toLowerCase());return e>=0&&this.seekToMarker(e),this}setVolume(t){return this.volume=Math.max(0,Math.min(1,t)),this.isMuted=this.volume===0,this.player&&this.player.setVolume(this.volume),this._updateVolumeUI(),g(this.config.storageKey,this.volume,this.isMuted,this._volumeBeforeMute),this._emit("volumechange",{volume:this.volume}),this.config.onVolumeChange&&this.config.onVolumeChange(this.volume),this}getVolume(){return this.volume}toggleMute(){return this.isMuted?this.setVolume(this._volumeBeforeMute||1):(this._volumeBeforeMute=this.volume,this.isMuted=!0,this.player&&this.player.setVolume(0),this._updateVolumeUI(),g(this.config.storageKey,this.volume,this.isMuted,this._volumeBeforeMute)),this}toggleFavorite(){let t=this.getCurrentTrack();if(!t)return this;let e=t.id||t.url,i=this._favorites.has(e);return i?this._favorites.delete(e):this._favorites.add(e),this._updateFavoriteUI(),this._syncFavoriteAttributes(t.url,!i),b(this.config.storageKey,this._favorites),this._emit("favorite",{track:t,favorited:!i}),this.config.onFavorite&&this.config.onFavorite(t,!i),this.config.actions?.favorite&&w(this.config.actions.favorite,{action:"favorite",id:e,url:t.url,title:t.title,favorited:!i}),this}addToCart(){let t=this.getCurrentTrack();if(!t)return this;let e=t.id||t.url;return this._cartItems.add(e),this.cartBtnEl&&(this.cartBtnEl.classList.add("wb-action-done"),setTimeout(()=>{this.cartBtnEl&&this.cartBtnEl.classList.remove("wb-action-done")},1500)),this._syncCartAttributes(t.url,!0),this._emit("cart",{track:t}),this.config.onCart&&this.config.onCart(t),this.config.actions?.cart&&w(this.config.actions.cart,{action:"cart",id:e,url:t.url,title:t.title}),this}isFavorited(t){if(!t){let e=this.getCurrentTrack();t=e?e.id||e.url:null}return t?this._favorites.has(t):!1}isInCart(t){if(!t){let e=this.getCurrentTrack();t=e?e.id||e.url:null}return t?this._cartItems.has(t):!1}removeFromQueue(t){return t<0||t>=this.queue.length||t===this.currentIndex?this:(this.queue.splice(t,1),t<this.currentIndex&&this.currentIndex--,this._renderQueue(),this._saveState(),this._updateNavButtons(),this._emit("queuechange",{queue:this.queue,currentIndex:this.currentIndex}),this.config.onQueueChange&&this.config.onQueueChange(this.queue,this.currentIndex),this)}clearQueue(){let t=this.getCurrentTrack();return this.queue=t?[t]:[],this.currentIndex=t?0:-1,this._renderQueue(),this._saveState(),this._updateNavButtons(),this._emit("queuechange",{queue:this.queue,currentIndex:this.currentIndex}),this.config.onQueueChange&&this.config.onQueueChange(this.queue,this.currentIndex),this}getCurrentTrack(){return this.currentIndex>=0&&this.currentIndex<this.queue.length?this.queue[this.currentIndex]:null}getQueue(){return[...this.queue]}getCurrentIndex(){return this.currentIndex}isCurrentlyPlaying(t){let e=this.getCurrentTrack();return this.isPlaying&&e&&e.url===t}isCurrentTrack(t){let e=this.getCurrentTrack();return e&&e.url===t}getPlayer(){return this.player}_emit(t,e={}){this.barEl&&this.barEl.dispatchEvent(new CustomEvent("waveformbar:"+t,{bubbles:!0,detail:e}))}show(){return this.barEl&&this.barEl.classList.add("wb-active"),this}hide(){return this.barEl&&this.barEl.classList.remove("wb-active"),this.closeQueuePanel(),this.closeVolumePopup(),this}toggleQueuePanel(){return this.queueOpen?this.closeQueuePanel():this.openQueuePanel()}openQueuePanel(){if(!this.queueEl)return this;if(this.queueOpen=!0,this.closeVolumePopup(),this.queueBtnEl){let t=this.queueBtnEl.getBoundingClientRect();this.queueEl.style.right=window.innerWidth-t.right+"px"}return this.queueEl.classList.add("wb-queue-open"),this.queueBtnEl&&this.queueBtnEl.classList.add("wb-active"),this._renderQueue(),this}closeQueuePanel(){return this.queueEl?(this.queueOpen=!1,this.queueEl.classList.remove("wb-queue-open"),this.queueBtnEl&&this.queueBtnEl.classList.remove("wb-active"),this):this}toggleVolumePopup(){return this.volumePopupEl?.classList.contains("wb-volume-open")?this.closeVolumePopup():this.openVolumePopup(),this}openVolumePopup(){return this.volumePopupEl?(this.closeQueuePanel(),this.volumePopupEl.classList.add("wb-volume-open"),this.muteBtnEl&&this.muteBtnEl.classList.add("wb-active"),this):this}closeVolumePopup(){return this.volumePopupEl?(this.volumePopupEl.classList.remove("wb-volume-open"),this.muteBtnEl&&this.muteBtnEl.classList.remove("wb-active"),this):this}_readShareTarget(){let t;try{t=new URLSearchParams(window.location.search)}catch{return null}let e=t.get(this.config.shareParam),i=t.get("wid"),s=t.get("wu");if(e==null&&i==null&&s==null)return null;let r=0;if(e!=null){let u=Number(e);Number.isFinite(u)&&u>=0&&(r=u)}let l=s&&m(s)?s:null;return{time:r,id:i||null,url:l,title:t.get("wtitle"),artist:t.get("wartist")}}_resolveSharedTrack(t){let e=document.querySelectorAll("[data-wb-play], [data-wb-queue]");if(t.id){for(let i of e)if(i.dataset.wbId===t.id||i.dataset.id===t.id){let s=f(i);if(s)return s}}if(t.url){for(let i of e)if(i.dataset.wbUrl===t.url||i.dataset.url===t.url){let s=f(i);if(s)return s}return{url:t.url,id:t.id||t.url,title:t.title||d(t.url),artist:t.artist||""}}return null}_loadSharedTrack(t,e){if(!t||!t.url||!this.player)return;let i=this.queue.findIndex(l=>l.url===t.url);i>=0?(this.queue[i]={...this.queue[i],...t},this.currentIndex=i):(this.queue.push(t),this.currentIndex=this.queue.length-1),this.show(),this._updateTrackDisplay(t),this._updateFavoriteUI(),this._updateNavButtons();let s={autoplay:!1};if(t.waveform&&(s.waveform=t.waveform),t.markers&&t.markers.length){let l=this.config.markerColor;s.markers=t.markers.map(u=>({...u,color:u.color||l})),this._activeMarkers=t.markers}else s.markers=[],this._activeMarkers=null;this._currentMarkerIndex=-1;let r=++this._loadSeq;this._restoreSeekTimeout&&(clearTimeout(this._restoreSeekTimeout),this._restoreSeekTimeout=null),this.player.loadTrack(t.url,t.title,t.artist,s).then(()=>{this._loadSeq===r&&(this.player&&this.player.setVolume(this.isMuted?0:this.volume),e>0&&(this._restoreSeekTimeout=setTimeout(()=>{this._restoreSeekTimeout=null,this._loadSeq===r&&this.player&&(this.player.seekTo(e),this._lastPosition=e)},100)))}).catch(()=>{}),this._renderQueue(),this._syncPageState(),this._saveState(),this._updateNavButtons(),this._emit("trackchange",{track:t,index:this.currentIndex}),this.config.onTrackChange&&this.config.onTrackChange(t,this.currentIndex)}_share(){let t=this.getCurrentTrack(),e=this.player&&this.player.audio?this.player.audio.currentTime:0,i=Math.max(0,Math.floor(e||0)),s;try{let r=new URL(window.location.href),l=r.searchParams;l.set(this.config.shareParam,String(i)),t&&(t.id&&t.id!==t.url&&l.set("wid",t.id),t.url&&l.set("wu",t.url),t.title&&l.set("wtitle",t.title),t.artist&&l.set("wartist",t.artist)),s=r.toString()}catch{return}navigator.clipboard&&navigator.clipboard.writeText&&navigator.clipboard.writeText(s).catch(()=>{}),navigator.share&&navigator.share({title:t&&t.title||void 0,url:s}).catch(()=>{}),this._flashShareCopied(),this._emit("share",{url:s,time:i,track:t})}_flashShareCopied(){this.shareBtnEl&&(this.shareBtnEl.classList.add("wb-copied"),this.shareBtnEl.setAttribute("title","Link copied!"),clearTimeout(this._shareFlashTimeout),this._shareFlashTimeout=setTimeout(()=>{this.shareBtnEl&&(this.shareBtnEl.classList.remove("wb-copied"),this.shareBtnEl.setAttribute("title","Copy share link"))},1500))}collapse(){return this.isCollapsed=!0,this.barEl&&this.barEl.classList.add("wb-collapsed"),this._updateCollapseButton(),this._saveCollapsed(),this._emit("collapse",{collapsed:!0}),this}expand(){return this.isCollapsed=!1,this.barEl&&this.barEl.classList.remove("wb-collapsed"),this._updateCollapseButton(),this._saveCollapsed(),this._emit("collapse",{collapsed:!1}),this}toggleCollapse(){return this.isCollapsed?this.expand():this.collapse()}_updateCollapseButton(){if(!this.collapseBtnEl)return;this.collapseBtnEl.innerHTML=this.isCollapsed?n.expand:n.collapse;let t=this.isCollapsed?"Expand":"Collapse";this.collapseBtnEl.setAttribute("aria-label",t),this.collapseBtnEl.setAttribute("title",t)}_saveCollapsed(){if(this.config.persist)try{sessionStorage.setItem(this.config.storageKey+"-collapsed",this.isCollapsed?"1":"0")}catch{}}_readCollapsed(){if(!this.config.persist)return!1;try{return sessionStorage.getItem(this.config.storageKey+"-collapsed")==="1"}catch{return!1}}_loadCurrentTrack(){let t=this.getCurrentTrack();if(!t||!this.player)return;this._loadSeq++,this._restoreSeekTimeout&&(clearTimeout(this._restoreSeekTimeout),this._restoreSeekTimeout=null),this._pumpExternalPlayState(!1),this.show(),this._updateTrackDisplay(t),this._updateFavoriteUI();let e={artwork:t.artwork,album:t.album};if(t.waveform&&(e.waveform=t.waveform),t.markers&&t.markers.length){let i=this.config.markerColor;e.markers=t.markers.map(s=>({...s,color:s.color||i}))}else e.markers=[];this.player.loadTrack(t.url,t.title,t.artist,e),this._activeMarkers=t.markers&&t.markers.length?t.markers:null,this._currentMarkerIndex=-1,this.player&&this.player.setVolume(this.isMuted?0:this.volume),this._renderQueue(),this._syncPageState(),this._saveState(),this._updateNavButtons(),this._emit("trackchange",{track:t,index:this.currentIndex}),this.config.onTrackChange&&this.config.onTrackChange(t,this.currentIndex)}_updateTrackDisplay(t){this.titleEl&&this._setScrollText(this.titleEl,t.title||"Untitled"),this.artistEl&&this._setScrollText(this.artistEl,t.artist||"");let e=this.barEl.querySelector(".wb-artwork");if(e){let s=t.artwork||this.config.defaultArtwork;e.innerHTML=s?`<img src="${h(s)}" alt="${h(t.title)}" />`:n.music}this.metaEl&&this.config.showMeta&&this._renderMeta(t);let i=this.barEl.querySelector(".wb-track");i&&(i.style.cursor=t.link?"pointer":"default"),this.timeCurrentEl&&(this.timeCurrentEl.textContent="0:00"),this.timeTotalEl&&(this.timeTotalEl.textContent="0:00")}_setScrollText(t,e){t.classList.remove("wb-scrolling"),t.textContent=e,requestAnimationFrame(()=>{if(t.scrollWidth>t.clientWidth){let i=t.scrollWidth-t.clientWidth,s=Math.max(4,i/20);t.innerHTML=`<span class="wb-scroll-inner">${h(e)}</span>`,t.style.setProperty("--wb-scroll-distance",`-${i+48}px`),t.style.setProperty("--wb-scroll-duration",`${s}s`),t.classList.add("wb-scrolling")}})}_renderMeta(t){if(!this.metaEl)return;let e=[];if(t.bpm&&e.push({label:t.bpm+" BPM",type:"bpm"}),t.key&&e.push({label:t.key,type:"key"}),t.duration&&e.push({label:t.duration,type:"duration"}),t.meta)for(let[s,r]of Object.entries(t.meta))r&&e.length<this.config.maxMeta&&e.push({label:String(r),type:s});let i=e.slice(0,this.config.maxMeta);this.metaEl.style.display=i.length?"flex":"none",this.metaEl.innerHTML=i.map(s=>`<span class="wb-tag wb-tag-${h(s.type)}">${h(s.label)}</span>`).join("")}_updatePlayButton(){if(!this.playBtnEl)return;let t=this.playBtnEl.querySelector(".wb-icon-play"),e=this.playBtnEl.querySelector(".wb-icon-pause");t&&(t.style.display=this.isPlaying?"none":"block"),e&&(e.style.display=this.isPlaying?"block":"none"),this.playBtnEl.title=this.isPlaying?"Pause":"Play"}_updateNavButtons(){let t=this.barEl?.querySelector(".wb-prev"),e=this.barEl?.querySelector(".wb-next");this.repeat==="all"?(t&&t.classList.remove("wb-disabled"),e&&e.classList.remove("wb-disabled")):(t&&t.classList.toggle("wb-disabled",this.currentIndex<=0),e&&e.classList.toggle("wb-disabled",this.currentIndex>=this.queue.length-1))}cycleRepeat(){let t=["off","all","one"],e=t.indexOf(this.repeat);return this.repeat=t[(e+1)%t.length],this._updateRepeatButton(),this._updateNavButtons(),this._emit("repeatchange",{mode:this.repeat}),this}setRepeat(t){return["off","all","one"].includes(t)&&(this.repeat=t,this._updateRepeatButton(),this._updateNavButtons(),this._emit("repeatchange",{mode:this.repeat})),this}_updateRepeatButton(){if(!this.repeatBtnEl)return;let t={off:n.repeatOff,all:n.repeatAll,one:n.repeatOne},e={off:"Repeat: Off",all:"Repeat: All",one:"Repeat: One"};this.repeatBtnEl.innerHTML=t[this.repeat],this.repeatBtnEl.title=e[this.repeat],this.repeatBtnEl.classList.toggle("wb-repeat-active",this.repeat!=="off")}_checkMarkerBoundary(t){if(!this._activeMarkers)return;let e=-1;for(let l=this._activeMarkers.length-1;l>=0;l--)if(t>=this._activeMarkers[l].time){e=l;break}if(e===this._currentMarkerIndex||(this._currentMarkerIndex=e,e<0))return;let i=this._activeMarkers[e],s=this.getCurrentTrack();i.title&&this.titleEl&&this._setScrollText(this.titleEl,i.title),i.artist&&this.artistEl&&this._setScrollText(this.artistEl,i.artist);let r=this.waveformContainer?.querySelectorAll(".waveform-marker");if(r&&r.forEach((l,u)=>l.classList.toggle("wb-marker-active",u===e)),i.artwork){let l=this.barEl.querySelector(".wb-artwork");l&&(l.innerHTML=`<img src="${h(i.artwork)}" alt="${h(i.title||"")}" />`)}if(this.metaEl&&(i.bpm||i.key)){let l={...s||{},bpm:i.bpm||"",key:i.key||""};this._renderMeta(l)}this._emit("markerchange",{marker:i,index:e,track:s})}_updateVolumeUI(){this.volumeSliderEl&&(this.volumeSliderEl.value=this.isMuted?0:Math.round(this.volume*100)),this.muteBtnEl&&(this.isMuted||this.volume===0?(this.muteBtnEl.innerHTML=n.volMute,this.muteBtnEl.classList.add("wb-muted"),this.muteBtnEl.title="Unmute"):this.volume<.5?(this.muteBtnEl.innerHTML=n.volLow,this.muteBtnEl.classList.remove("wb-muted"),this.muteBtnEl.title="Mute"):(this.muteBtnEl.innerHTML=n.volHigh,this.muteBtnEl.classList.remove("wb-muted"),this.muteBtnEl.title="Mute"))}_detectTheme(){let t=document.documentElement,e=document.body,i=["dark","dark-mode","theme-dark"],s=["light","light-mode","theme-light"];for(let r of i)if(t.classList.contains(r)||e.classList.contains(r))return"dark";if(t.getAttribute("data-theme")==="dark"||e.getAttribute("data-theme")==="dark")return"dark";for(let r of s)if(t.classList.contains(r)||e.classList.contains(r))return"light";if(t.getAttribute("data-theme")==="light"||e.getAttribute("data-theme")==="light")return"light";try{let l=getComputedStyle(e).backgroundColor.match(/\d+/g);if(l&&l.length>=3){let u=(l[0]*299+l[1]*587+l[2]*114)/1e3;if(u>128)return"light";if(u<128)return"dark"}}catch{}return window.matchMedia?.("(prefers-color-scheme: light)").matches?"light":"dark"}_updateFavoriteUI(){if(!this.favBtnEl)return;let t=this.isFavorited();this.favBtnEl.innerHTML=t?n.heartFilled:n.heart,this.favBtnEl.classList.toggle("wb-fav-active",t)}_renderQueue(){S(this.queueBodyEl,this.queueCountEl,this.queue,this.currentIndex,{onSkipTo:t=>this.skipTo(t),onRemove:t=>this.removeFromQueue(t)})}_syncPageState(){let t=this.getCurrentTrack(),e=t?t.url:null;document.querySelectorAll("[data-wb-play]").forEach(i=>{let s=i.dataset.wbUrl||i.dataset.url,r=i.dataset.wbId||i.dataset.id||s,l=s&&s===e;i.classList.toggle("wb-current",l),i.classList.toggle("wb-playing",l&&this.isPlaying),i.classList.toggle("wb-favorited",this._favorites.has(r)),i.classList.toggle("wb-in-cart",this._cartItems.has(r))})}_seedFromAttributes(){let t=!1,e=!1;document.querySelectorAll("[data-wb-play]").forEach(i=>{let s=i.dataset.wbId||i.dataset.id||i.dataset.wbUrl||i.dataset.url;s&&(i.dataset.wbFavorited==="true"&&(this._favorites.add(s),t=!0),i.dataset.wbInCart==="true"&&(this._cartItems.add(s),e=!0))}),t&&b(this.config.storageKey,this._favorites)}_syncFavoriteAttributes(t,e){document.querySelectorAll("[data-wb-play]").forEach(i=>{(i.dataset.wbUrl||i.dataset.url)===t&&(i.dataset.wbFavorited=e?"true":"false",i.classList.toggle("wb-favorited",e))})}_syncCartAttributes(t,e){document.querySelectorAll("[data-wb-play]").forEach(i=>{(i.dataset.wbUrl||i.dataset.url)===t&&(i.dataset.wbInCart=e?"true":"false",i.classList.toggle("wb-in-cart",e))})}_saveState(){this.config.persist&&y(this.config.storageKey,{queue:this.queue,currentIndex:this.currentIndex,position:this._lastPosition||0,isPlaying:this.isPlaying})}_restoreState(){if(!this.config.persist)return;let t=_(this.config.storageKey);if(!t)return;this.queue=t.queue,this.currentIndex=t.currentIndex;let e=this.getCurrentTrack();if(!e)return;this.show(),this._updateTrackDisplay(e),this._updateFavoriteUI(),this._updateNavButtons();let i={autoplay:!1};if(e.waveform&&(i.waveform=e.waveform),e.markers&&e.markers.length){let r=this.config.markerColor;i.markers=e.markers.map(l=>({...l,color:l.color||r})),this._activeMarkers=e.markers}else i.markers=[],this._activeMarkers=null;this._currentMarkerIndex=-1;let s=++this._loadSeq;this._restoreSeekTimeout&&(clearTimeout(this._restoreSeekTimeout),this._restoreSeekTimeout=null),this.player.loadTrack(e.url,e.title,e.artist,i).then(()=>{if(this._loadSeq===s){if(this.player&&this.player.setVolume(this.isMuted?0:this.volume),t.isPlaying&&this.config.autoResume)try{let r=this.player.play();r&&typeof r.catch=="function"&&r.catch(()=>{this.isPlaying=!1,this._updatePlayButton(),this._syncPageState()})}catch{this.isPlaying=!1,this._updatePlayButton(),this._syncPageState()}t.position>0&&(this._restoreSeekTimeout=setTimeout(()=>{this._restoreSeekTimeout=null,this._loadSeq===s&&this.player&&(this.player.seekTo(t.position),this._lastPosition=t.position)},100))}}).catch(()=>{}),this._renderQueue(),this._syncPageState()}_restoreVolume(){let t=E(this.config.storageKey);if(!t)return;let e=Number(t.volume);this.volume=Number.isFinite(e)?Math.max(0,Math.min(1,e)):1,this.isMuted=t.muted,this._volumeBeforeMute=t.volumeBeforeMute,this.player&&this.player.setVolume(this.isMuted?0:this.volume),this._updateVolumeUI()}_restoreFavorites(){this._favorites=k(this.config.storageKey)}};var C=new p;typeof window<"u"&&(window.WaveformBar=C);var D=C;})();
44
+ </div>`}}a.innerHTML=l,a.querySelectorAll(".wb-queue-item[data-qi]").forEach(o=>{o.addEventListener("click",c=>{c.target.closest(".wb-queue-remove")||s.onSkipTo&&s.onSkipTo(parseInt(o.dataset.qi))})}),a.querySelectorAll(".wb-queue-remove").forEach(o=>{o.addEventListener("click",c=>{c.stopPropagation(),s.onRemove&&s.onRemove(parseInt(o.dataset.qi))})})}var C={persist:!0,autoResume:!0,continuous:!0,repeat:"off",showRepeat:!0,showQueue:!0,showPrevNext:!0,showVolume:!0,showMute:!0,showMeta:!0,showTime:!0,showTrackLink:!0,maxMeta:3,defaultArtwork:null,theme:null,wide:!1,maxWidth:null,position:"bottom",collapsible:!1,waveform:!0,errorText:null,share:!1,shareParam:"wt",waveformStyle:"mirror",waveformHeight:32,barWidth:2,barSpacing:2,waveformColor:null,progressColor:null,markerColor:"rgba(255, 255, 255, 0.25)",volume:1,storageKey:"waveform-bar",actions:null,onPlay:null,onPause:null,onTrackChange:null,onQueueChange:null,onVolumeChange:null,onFavorite:null,onCart:null},m=class{constructor(){this.config=null,this.player=null,this.queue=[],this.currentIndex=-1,this.isPlaying=!1,this.isInitialized=!1,this.queueOpen=!1,this.volume=1,this.isMuted=!1,this._volumeBeforeMute=1,this._lastPosition=0,this._favorites=new Set,this._cartItems=new Set,this._observer=null,this._activeMarkers=null,this._currentMarkerIndex=-1,this.repeat="off",this._loadSeq=0,this._restoreSeekTimeout=null,this._externalPlayers=new Map,this.barEl=null,this.queueEl=null,this.waveformContainer=null,this.volumePopupEl=null,this.titleEl=null,this.artistEl=null,this.metaEl=null,this.playBtnEl=null,this.repeatBtnEl=null,this.queueBtnEl=null,this.queueBodyEl=null,this.queueCountEl=null,this.volumeSliderEl=null,this.muteBtnEl=null,this.favBtnEl=null,this.cartBtnEl=null,this.timeCurrentEl=null,this.timeTotalEl=null}init(t={}){this.isInitialized&&this.destroy(),this.config={...C,...t};let e=Number(this.config.volume);if(this.volume=Number.isFinite(e)?Math.max(0,Math.min(1,e)):1,this._shareTarget=this._readShareTarget(),this._shareSeek=this._shareTarget&&!this._shareTarget.id&&!this._shareTarget.url?this._shareTarget.time:null,typeof window.WaveformPlayer>"u")return console.error("[WaveformBar] WaveformPlayer is required."),this;if(this._createBar(),this._createQueue(),this._initPlayer(),this._bindTriggers(),this._observeDOM(),this._watchTheme(),this.config.persist&&(this._restoreVolume(),this._restoreFavorites()),this._seedFromAttributes(),this.config.persist&&this._restoreState(),this._shareTarget&&(this._shareTarget.id||this._shareTarget.url)){let i=this._resolveSharedTrack(this._shareTarget);i&&this._loadSharedTrack(i,this._shareTarget.time)}return this.isInitialized=!0,this._beforeUnloadHandler=()=>this._saveState(),window.addEventListener("beforeunload",this._beforeUnloadHandler),this}destroy(){return this.player&&(this.player.destroy(),this.player=null),this._themeObserver&&(this._themeObserver.disconnect(),this._themeObserver=null),this._themeMq&&this._themeMqHandler&&(this._themeMq.removeEventListener("change",this._themeMqHandler),this._themeMq=null,this._themeMqHandler=null),this._docClickVolume&&(document.removeEventListener("click",this._docClickVolume),this._docClickVolume=null),this._docClickQueue&&(document.removeEventListener("click",this._docClickQueue),this._docClickQueue=null),this._docClickTriggers&&(document.removeEventListener("click",this._docClickTriggers),this._docClickTriggers=null),this._externalListenersBound&&(document.removeEventListener("waveformplayer:request-play",this._onExtRequestPlay),document.removeEventListener("waveformplayer:request-pause",this._onExtRequestPause),document.removeEventListener("waveformplayer:request-seek",this._onExtRequestSeek),document.removeEventListener("waveformplayer:destroy",this._onExtDestroy),this._onExtRequestPlay=null,this._onExtRequestPause=null,this._onExtRequestSeek=null,this._onExtDestroy=null,this._externalListenersBound=!1),this._externalPlayers=new Map,this._restoreSeekTimeout&&(clearTimeout(this._restoreSeekTimeout),this._restoreSeekTimeout=null),clearTimeout(this._shareFlashTimeout),this._shareFlashTimeout=null,this._loadSeq++,this.barEl&&(this.barEl.remove(),this.barEl=null),this.queueEl&&(this.queueEl.remove(),this.queueEl=null),this._observer&&(this._observer.disconnect(),this._observer=null),this._beforeUnloadHandler&&(window.removeEventListener("beforeunload",this._beforeUnloadHandler),this._beforeUnloadHandler=null),this.volumePopupEl=null,this.queueBtnEl=null,this.titleEl=null,this.artistEl=null,this.metaEl=null,this.playBtnEl=null,this.repeatBtnEl=null,this.waveformContainer=null,this.queueBodyEl=null,this.queueCountEl=null,this.muteBtnEl=null,this.volumeSliderEl=null,this.favBtnEl=null,this.cartBtnEl=null,this.timeCurrentEl=null,this.timeTotalEl=null,document.querySelectorAll(".wb-current,.wb-playing").forEach(t=>t.classList.remove("wb-current","wb-playing")),this.queue=[],this.currentIndex=-1,this.isPlaying=!1,this.queueOpen=!1,this.isInitialized=!1,this.config=null,this}_createBar(){this.barEl=document.createElement("div"),this.barEl.className="waveform-bar";let t=this.config.theme||this._detectTheme();t==="light"&&this.barEl.classList.add("wb-light"),this._resolvedTheme=t;let e=this.config.maxWidth||(this.config.wide?"100%":null);e&&this.barEl.style.setProperty("--wb-max-width",e),this.config.position==="top"&&this.barEl.classList.add("wb-top"),this.barEl.id="waveform-bar",this.barEl.innerHTML=q(this.config),document.body.appendChild(this.barEl),this.titleEl=this.barEl.querySelector(".wb-title"),this.artistEl=this.barEl.querySelector(".wb-artist"),this.metaEl=this.barEl.querySelector(".wb-meta"),this.playBtnEl=this.barEl.querySelector(".wb-play"),this.waveformContainer=this.barEl.querySelector(".wb-waveform-container"),this.queueBtnEl=this.barEl.querySelector(".wb-queue-btn"),this.shareBtnEl=this.barEl.querySelector(".wb-share"),this.muteBtnEl=this.barEl.querySelector(".wb-mute"),this.volumeSliderEl=this.barEl.querySelector(".wb-volume-slider"),this.favBtnEl=this.barEl.querySelector(".wb-fav"),this.cartBtnEl=this.barEl.querySelector(".wb-cart"),this.timeCurrentEl=this.barEl.querySelector(".wb-time-current"),this.timeTotalEl=this.barEl.querySelector(".wb-time-total"),this.collapseBtnEl=this.barEl.querySelector(".wb-collapse"),this.playBtnEl.addEventListener("click",()=>this.togglePlay()),this.collapseBtnEl&&(this.collapseBtnEl.addEventListener("click",()=>this.toggleCollapse()),this._readCollapsed()&&this.collapse());let i=this.barEl.querySelector(".wb-prev"),s=this.barEl.querySelector(".wb-next");i&&i.addEventListener("click",()=>this.previous()),s&&s.addEventListener("click",()=>this.next()),this.shareBtnEl&&this.shareBtnEl.addEventListener("click",()=>this._share()),this.repeatBtnEl=this.barEl.querySelector(".wb-repeat"),this.repeatBtnEl&&(this.repeat=this.config.repeat||"off",this._updateRepeatButton(),this.repeatBtnEl.addEventListener("click",()=>this.cycleRepeat())),this.queueBtnEl&&this.queueBtnEl.addEventListener("click",()=>this.toggleQueuePanel()),this.volumePopupEl=this.barEl.querySelector(".wb-volume-popup");let r=this.barEl.querySelector(".wb-volume");if(this.muteBtnEl&&this.muteBtnEl.addEventListener("click",l=>{l.stopPropagation(),this.toggleMute()}),r&&this.volumePopupEl){let l;r.addEventListener("mouseenter",()=>{clearTimeout(l),this.openVolumePopup()}),r.addEventListener("mouseleave",()=>{l=setTimeout(()=>this.closeVolumePopup(),300)})}this.volumeSliderEl&&this.volumeSliderEl.addEventListener("input",l=>{l.stopPropagation(),this.setVolume(parseInt(l.target.value)/100)}),this._docClickVolume=l=>{this.volumePopupEl?.classList.contains("wb-volume-open")&&!this.barEl?.querySelector(".wb-volume")?.contains(l.target)&&this.closeVolumePopup()},document.addEventListener("click",this._docClickVolume),this.favBtnEl&&this.favBtnEl.addEventListener("click",()=>this.toggleFavorite()),this.cartBtnEl&&this.cartBtnEl.addEventListener("click",()=>this.addToCart()),this.config.showTrackLink&&this.barEl.querySelector(".wb-track").addEventListener("click",()=>{let l=this.getCurrentTrack();l&&l.link&&p(l.link)&&(window.location.href=l.link)})}_createQueue(){this.config.showQueue&&(this.queueEl=x(),this._resolvedTheme==="light"&&this.queueEl.classList.add("wb-light"),document.body.appendChild(this.queueEl),this.queueBodyEl=this.queueEl.querySelector(".wb-queue-body"),this.queueCountEl=this.queueEl.querySelector(".wb-queue-count"),this.queueEl.querySelector(".wb-queue-clear").addEventListener("click",()=>this.clearQueue()),this._docClickQueue=t=>{this.queueOpen&&!this.queueEl?.contains(t.target)&&!this.queueBtnEl?.contains(t.target)&&this.closeQueuePanel()},document.addEventListener("click",this._docClickQueue))}_initPlayer(){let t={showControls:!1,showInfo:!1,waveformStyle:this.config.waveform===!1?"seekbar":this.config.waveformStyle,height:this.config.waveformHeight,barWidth:this.config.barWidth,barSpacing:this.config.barSpacing,errorText:this.config.errorText,singlePlay:!1,onPlay:()=>{this.isPlaying=!0,this._updatePlayButton(),this._syncPageState(),this._pumpExternalPlayState(!0);let e=this.getCurrentTrack();this._emit("play",{track:e}),this.config.onPlay&&this.config.onPlay(e)},onPause:()=>{this.isPlaying=!1,this._updatePlayButton(),this._syncPageState(),this._pumpExternalPlayState(!1),this._saveState();let e=this.getCurrentTrack();this._emit("pause",{track:e}),this.config.onPause&&this.config.onPause(e)},onEnd:()=>{if(this.isPlaying=!1,this._updatePlayButton(),this._syncPageState(),this._pumpExternalPlayState(!1),this.timeCurrentEl&&(this.timeCurrentEl.textContent="0:00"),this.repeat==="one"){this.player&&(this.player.seekTo(0),this.player.play().catch(()=>{}));return}this.config.continuous&&this.currentIndex<this.queue.length-1?(this.currentIndex++,this._loadCurrentTrack()):this.repeat==="all"&&this.queue.length>0&&(this.currentIndex=0,this._loadCurrentTrack())},onError:()=>{this.isPlaying=!1,this._updatePlayButton(),this._syncPageState(),this._pumpExternalPlayState(!1);let e=this.getCurrentTrack();this._emit("error",{track:e}),this.config.continuous&&this.currentIndex<this.queue.length-1&&(this.currentIndex++,this._loadCurrentTrack())},onTimeUpdate:(e,i)=>{this._lastPosition=e,this.timeCurrentEl&&(this.timeCurrentEl.textContent=v(e)),this.timeTotalEl&&(this.timeTotalEl.textContent=v(i)),this._pumpExternalProgress(e,i),(!this._lastSaveTime||e-this._lastSaveTime>2)&&(this._lastSaveTime=e,this._saveState()),this._activeMarkers&&this._checkMarkerBoundary(e)},onLoad:()=>{this._shareSeek!=null&&this.player&&(this.player.seekTo(this._shareSeek),this._shareSeek=null)}};this.config.waveformColor&&(t.waveformColor=this.config.waveformColor),this.config.progressColor&&(t.progressColor=this.config.progressColor),this.player=new window.WaveformPlayer(this.waveformContainer,t),this.player.setVolume(this.volume)}_bindTriggers(){this._docClickTriggers||(this._docClickTriggers=t=>{let e=t.target?.closest?.("[data-wb-queue]");if(e){t.preventDefault();let s=f(e);s&&this.addToQueue(s);return}let i=t.target?.closest?.("[data-wb-play]");if(i){t.preventDefault();let s=f(i);s&&this.play(s)}},document.addEventListener("click",this._docClickTriggers)),this._attachExternalPlayers()}_attachExternalPlayers(){this._externalListenersBound||(this._externalListenersBound=!0,this._onExtRequestPlay=s=>{let r=s.detail;!r||!r.url||(s.preventDefault(),this.play(r))},this._onExtRequestPause=s=>{let r=s.detail;if(!r||!r.url)return;let l=this.getCurrentTrack();l&&l.url===r.url&&(s.preventDefault(),this.isPlaying&&this.togglePlay())},this._onExtRequestSeek=s=>{let r=s.detail;if(!r||!r.url||typeof r.percent!="number")return;let l=this.getCurrentTrack();l&&l.url===r.url&&this.player&&this.player.audio&&(s.preventDefault(),this.player.seekToPercent(r.percent))},this._onExtDestroy=s=>{let r=s.detail&&s.detail.player;!r||!this._externalPlayers||this._externalPlayers.forEach(l=>l.delete(r))},document.addEventListener("waveformplayer:request-play",this._onExtRequestPlay),document.addEventListener("waveformplayer:request-pause",this._onExtRequestPause),document.addEventListener("waveformplayer:request-seek",this._onExtRequestSeek),document.addEventListener("waveformplayer:destroy",this._onExtDestroy));let t=this._externalPlayers||new Map;this._externalPlayers=new Map;let e=window.WaveformPlayer;if(!e||!e.instances)return;let i=[];if(document.querySelectorAll('[data-waveform-player][data-audio-mode="external"]').forEach(s=>{let r=e.instances.get(s.id);if(!r||!r.options||!r.options.url)return;let l=r.options.url;this._externalPlayers.has(l)||this._externalPlayers.set(l,new Set),this._externalPlayers.get(l).add(r),t.get(l)&&t.get(l).has(r)||i.push({inst:r,url:l})}),i.length){let s=this.getCurrentTrack(),r=s?s.url:null;i.forEach(({inst:l,url:u})=>{let o=u===r;typeof l.setPlayingState=="function"&&l.setPlayingState(o&&this.isPlaying),o&&typeof l.setProgress=="function"&&this.player&&this.player.audio&&l.setProgress(this.player.audio.currentTime||0,this.player.audio.duration||0)})}}_pumpExternalPlayState(t){if(!this._externalPlayers||this._externalPlayers.size===0)return;let e=this.getCurrentTrack(),i=e?e.url:null;this._externalPlayers.forEach((s,r)=>{let l=r===i;s.forEach(u=>{typeof u.setPlayingState=="function"&&u.setPlayingState(l&&t)})})}_pumpExternalProgress(t,e){if(!this._externalPlayers||this._externalPlayers.size===0)return;let i=this.getCurrentTrack();if(!i)return;let s=this._externalPlayers.get(i.url);s&&s.forEach(r=>{typeof r.setProgress=="function"&&r.setProgress(t,e)})}_observeDOM(){typeof MutationObserver>"u"||(this._observer=new MutationObserver(()=>{this._attachExternalPlayers(),this._syncPageState()}),this._observer.observe(document.body,{childList:!0,subtree:!0}))}play(t){let e=typeof t=="string"?{url:t,id:t,title:d(t)}:t;if(!e||!e.url)return this;let i=this.getCurrentTrack();if(i&&i.url===e.url)return this.togglePlay(),this;let s=this.queue.findIndex(r=>r.url===e.url);if(s>=0)this.queue[s]={...this.queue[s],...e},this.currentIndex=s;else{let r=this.currentIndex+1;this.queue.splice(r,0,e),this.currentIndex=r}return this._loadCurrentTrack(),this}addToQueue(t){let e=typeof t=="string"?{url:t,id:t,title:d(t)}:t;return!e||!e.url?this:this.queue.find(i=>i.url===e.url)?this:(this.queue.push(e),this._renderQueue(),this._saveState(),this._updateNavButtons(),this.currentIndex===-1&&(this.currentIndex=0,this._loadCurrentTrack()),this.config.onQueueChange&&this.config.onQueueChange(this.queue,this.currentIndex),this)}togglePlay(){return this.player?(this.isPlaying?this.player.pause():this.player.play(),this):this}pause(){return this.player&&this.isPlaying&&this.player.pause(),this}next(){return this.currentIndex<this.queue.length-1?(this.currentIndex++,this._loadCurrentTrack()):this.repeat==="all"&&this.queue.length>0&&(this.currentIndex=0,this._loadCurrentTrack()),this}previous(){return this.player&&this.player.audio&&this.player.audio.currentTime>3?(this.player.seekTo(0),this):(this.currentIndex>0?(this.currentIndex--,this._loadCurrentTrack()):this.repeat==="all"&&this.queue.length>0&&(this.currentIndex=this.queue.length-1,this._loadCurrentTrack()),this)}skipTo(t){return t<0||t>=this.queue.length?this:t===this.currentIndex?(this.togglePlay(),this):(this.currentIndex=t,this._loadCurrentTrack(),this)}seekToMarker(t){if(!this._activeMarkers||t<0||t>=this._activeMarkers.length)return this;let e=this._activeMarkers[t];return this.player&&(this.player.seekTo(e.time),this.isPlaying||this.togglePlay()),this}seekToMarkerByLabel(t){if(!this._activeMarkers)return this;let e=this._activeMarkers.findIndex(i=>(i.label||i.title||"").toLowerCase()===t.toLowerCase());return e>=0&&this.seekToMarker(e),this}setVolume(t){return this.volume=Math.max(0,Math.min(1,t)),this.isMuted=this.volume===0,this.player&&this.player.setVolume(this.volume),this._updateVolumeUI(),g(this.config.storageKey,this.volume,this.isMuted,this._volumeBeforeMute),this._emit("volumechange",{volume:this.volume}),this.config.onVolumeChange&&this.config.onVolumeChange(this.volume),this}getVolume(){return this.volume}toggleMute(){return this.isMuted?this.setVolume(this._volumeBeforeMute||1):(this._volumeBeforeMute=this.volume,this.isMuted=!0,this.player&&this.player.setVolume(0),this._updateVolumeUI(),g(this.config.storageKey,this.volume,this.isMuted,this._volumeBeforeMute)),this}toggleFavorite(){let t=this.getCurrentTrack();if(!t)return this;let e=t.id||t.url,i=this._favorites.has(e);return i?this._favorites.delete(e):this._favorites.add(e),this._updateFavoriteUI(),this._syncFavoriteAttributes(t.url,!i),b(this.config.storageKey,this._favorites),this._emit("favorite",{track:t,favorited:!i}),this.config.onFavorite&&this.config.onFavorite(t,!i),this.config.actions?.favorite&&w(this.config.actions.favorite,{action:"favorite",id:e,url:t.url,title:t.title,favorited:!i}),this}addToCart(){let t=this.getCurrentTrack();if(!t)return this;let e=t.id||t.url;return this._cartItems.add(e),this.cartBtnEl&&(this.cartBtnEl.classList.add("wb-action-done"),setTimeout(()=>{this.cartBtnEl&&this.cartBtnEl.classList.remove("wb-action-done")},1500)),this._syncCartAttributes(t.url,!0),this._emit("cart",{track:t}),this.config.onCart&&this.config.onCart(t),this.config.actions?.cart&&w(this.config.actions.cart,{action:"cart",id:e,url:t.url,title:t.title}),this}isFavorited(t){if(!t){let e=this.getCurrentTrack();t=e?e.id||e.url:null}return t?this._favorites.has(t):!1}isInCart(t){if(!t){let e=this.getCurrentTrack();t=e?e.id||e.url:null}return t?this._cartItems.has(t):!1}removeFromQueue(t){return t<0||t>=this.queue.length||t===this.currentIndex?this:(this.queue.splice(t,1),t<this.currentIndex&&this.currentIndex--,this._renderQueue(),this._saveState(),this._updateNavButtons(),this._emit("queuechange",{queue:this.queue,currentIndex:this.currentIndex}),this.config.onQueueChange&&this.config.onQueueChange(this.queue,this.currentIndex),this)}clearQueue(){let t=this.getCurrentTrack();return this.queue=t?[t]:[],this.currentIndex=t?0:-1,this._renderQueue(),this._saveState(),this._updateNavButtons(),this._emit("queuechange",{queue:this.queue,currentIndex:this.currentIndex}),this.config.onQueueChange&&this.config.onQueueChange(this.queue,this.currentIndex),this}getCurrentTrack(){return this.currentIndex>=0&&this.currentIndex<this.queue.length?this.queue[this.currentIndex]:null}getQueue(){return[...this.queue]}getCurrentIndex(){return this.currentIndex}isCurrentlyPlaying(t){let e=this.getCurrentTrack();return this.isPlaying&&e&&e.url===t}isCurrentTrack(t){let e=this.getCurrentTrack();return e&&e.url===t}getPlayer(){return this.player}_emit(t,e={}){this.barEl&&this.barEl.dispatchEvent(new CustomEvent("waveformbar:"+t,{bubbles:!0,detail:e}))}show(){return this.barEl&&this.barEl.classList.add("wb-active"),this}hide(){return this.barEl&&this.barEl.classList.remove("wb-active"),this.closeQueuePanel(),this.closeVolumePopup(),this}toggleQueuePanel(){return this.queueOpen?this.closeQueuePanel():this.openQueuePanel()}openQueuePanel(){if(!this.queueEl)return this;if(this.queueOpen=!0,this.closeVolumePopup(),this.queueBtnEl){let t=this.queueBtnEl.getBoundingClientRect();this.queueEl.style.right=window.innerWidth-t.right+"px"}return this.queueEl.classList.add("wb-queue-open"),this.queueBtnEl&&this.queueBtnEl.classList.add("wb-active"),this._renderQueue(),this}closeQueuePanel(){return this.queueEl?(this.queueOpen=!1,this.queueEl.classList.remove("wb-queue-open"),this.queueBtnEl&&this.queueBtnEl.classList.remove("wb-active"),this):this}toggleVolumePopup(){return this.volumePopupEl?.classList.contains("wb-volume-open")?this.closeVolumePopup():this.openVolumePopup(),this}openVolumePopup(){return this.volumePopupEl?(this.closeQueuePanel(),this.volumePopupEl.classList.add("wb-volume-open"),this.muteBtnEl&&this.muteBtnEl.classList.add("wb-active"),this):this}closeVolumePopup(){return this.volumePopupEl?(this.volumePopupEl.classList.remove("wb-volume-open"),this.muteBtnEl&&this.muteBtnEl.classList.remove("wb-active"),this):this}_readShareTarget(){let t;try{t=new URLSearchParams(window.location.search)}catch{return null}let e=t.get(this.config.shareParam),i=t.get("wid"),s=t.get("wu");if(e==null&&i==null&&s==null)return null;let r=0;if(e!=null){let u=Number(e);Number.isFinite(u)&&u>=0&&(r=u)}let l=s&&p(s)?s:null;return{time:r,id:i||null,url:l,title:t.get("wtitle"),artist:t.get("wartist")}}_resolveSharedTrack(t){let e=document.querySelectorAll("[data-wb-play], [data-wb-queue]");if(t.id){for(let i of e)if(i.dataset.wbId===t.id||i.dataset.id===t.id){let s=f(i);if(s)return s}}if(t.url){for(let i of e)if(i.dataset.wbUrl===t.url||i.dataset.url===t.url){let s=f(i);if(s)return s}return{url:t.url,id:t.id||t.url,title:t.title||d(t.url),artist:t.artist||""}}return null}_loadSharedTrack(t,e){if(!t||!t.url||!this.player)return;let i=this.queue.findIndex(l=>l.url===t.url);i>=0?(this.queue[i]={...this.queue[i],...t},this.currentIndex=i):(this.queue.push(t),this.currentIndex=this.queue.length-1),this.show(),this._updateTrackDisplay(t),this._updateFavoriteUI(),this._updateNavButtons();let s={autoplay:!1};if(t.waveform&&(s.waveform=t.waveform),t.markers&&t.markers.length){let l=this.config.markerColor;s.markers=t.markers.map(u=>({...u,color:u.color||l})),this._activeMarkers=t.markers}else s.markers=[],this._activeMarkers=null;this._currentMarkerIndex=-1;let r=++this._loadSeq;this._restoreSeekTimeout&&(clearTimeout(this._restoreSeekTimeout),this._restoreSeekTimeout=null),this.player.loadTrack(t.url,t.title,t.artist,s).then(()=>{this._loadSeq===r&&(this.player&&this.player.setVolume(this.isMuted?0:this.volume),e>0&&(this._restoreSeekTimeout=setTimeout(()=>{this._restoreSeekTimeout=null,this._loadSeq===r&&this.player&&(this.player.seekTo(e),this._lastPosition=e)},100)))}).catch(()=>{}),this._renderQueue(),this._syncPageState(),this._saveState(),this._updateNavButtons(),this._emit("trackchange",{track:t,index:this.currentIndex}),this.config.onTrackChange&&this.config.onTrackChange(t,this.currentIndex)}_share(){let t=this.getCurrentTrack(),e=this.player&&this.player.audio?this.player.audio.currentTime:0,i=Math.max(0,Math.floor(e||0)),s;try{let r=new URL(window.location.href),l=r.searchParams;l.set(this.config.shareParam,String(i)),t&&(t.id&&t.id!==t.url&&l.set("wid",t.id),t.url&&l.set("wu",t.url),t.title&&l.set("wtitle",t.title),t.artist&&l.set("wartist",t.artist)),s=r.toString()}catch{return}navigator.clipboard&&navigator.clipboard.writeText&&navigator.clipboard.writeText(s).catch(()=>{}),navigator.share&&navigator.share({title:t&&t.title||void 0,url:s}).catch(()=>{}),this._flashShareCopied(),this._emit("share",{url:s,time:i,track:t})}_flashShareCopied(){this.shareBtnEl&&(this.shareBtnEl.classList.add("wb-copied"),this.shareBtnEl.setAttribute("title","Link copied!"),clearTimeout(this._shareFlashTimeout),this._shareFlashTimeout=setTimeout(()=>{this.shareBtnEl&&(this.shareBtnEl.classList.remove("wb-copied"),this.shareBtnEl.setAttribute("title","Copy share link"))},1500))}collapse(){return this.isCollapsed=!0,this.barEl&&this.barEl.classList.add("wb-collapsed"),this._updateCollapseButton(),this._saveCollapsed(),this._emit("collapse",{collapsed:!0}),this}expand(){return this.isCollapsed=!1,this.barEl&&this.barEl.classList.remove("wb-collapsed"),this._updateCollapseButton(),this._saveCollapsed(),this._emit("collapse",{collapsed:!1}),this}toggleCollapse(){return this.isCollapsed?this.expand():this.collapse()}_updateCollapseButton(){if(!this.collapseBtnEl)return;this.collapseBtnEl.innerHTML=this.isCollapsed?n.expand:n.collapse;let t=this.isCollapsed?"Expand":"Collapse";this.collapseBtnEl.setAttribute("aria-label",t),this.collapseBtnEl.setAttribute("title",t)}_saveCollapsed(){if(this.config.persist)try{sessionStorage.setItem(this.config.storageKey+"-collapsed",this.isCollapsed?"1":"0")}catch{}}_readCollapsed(){if(!this.config.persist)return!1;try{return sessionStorage.getItem(this.config.storageKey+"-collapsed")==="1"}catch{return!1}}_loadCurrentTrack(){let t=this.getCurrentTrack();if(!t||!this.player)return;this._loadSeq++,this._restoreSeekTimeout&&(clearTimeout(this._restoreSeekTimeout),this._restoreSeekTimeout=null),this._pumpExternalPlayState(!1),this.show(),this._updateTrackDisplay(t),this._updateFavoriteUI();let e={artwork:t.artwork,album:t.album};if(t.waveform&&(e.waveform=t.waveform),t.markers&&t.markers.length){let i=this.config.markerColor;e.markers=t.markers.map(s=>({...s,color:s.color||i}))}else e.markers=[];this.player.loadTrack(t.url,t.title,t.artist,e),this._activeMarkers=t.markers&&t.markers.length?t.markers:null,this._currentMarkerIndex=-1,this.player&&this.player.setVolume(this.isMuted?0:this.volume),this._renderQueue(),this._syncPageState(),this._saveState(),this._updateNavButtons(),this._emit("trackchange",{track:t,index:this.currentIndex}),this.config.onTrackChange&&this.config.onTrackChange(t,this.currentIndex)}_updateTrackDisplay(t){this.titleEl&&this._setScrollText(this.titleEl,t.title||"Untitled"),this.artistEl&&this._setScrollText(this.artistEl,t.artist||"");let e=this.barEl.querySelector(".wb-artwork");if(e){let s=t.artwork||this.config.defaultArtwork;e.innerHTML=s?`<img src="${h(s)}" alt="${h(t.title)}" />`:n.music}this.metaEl&&this.config.showMeta&&this._renderMeta(t);let i=this.barEl.querySelector(".wb-track");i&&(i.style.cursor=t.link?"pointer":"default"),this.timeCurrentEl&&(this.timeCurrentEl.textContent="0:00"),this.timeTotalEl&&(this.timeTotalEl.textContent="0:00")}_setScrollText(t,e){t.classList.remove("wb-scrolling"),t.textContent=e,requestAnimationFrame(()=>{if(t.scrollWidth>t.clientWidth){let i=t.scrollWidth-t.clientWidth,s=Math.max(4,i/20);t.innerHTML=`<span class="wb-scroll-inner">${h(e)}</span>`,t.style.setProperty("--wb-scroll-distance",`-${i+48}px`),t.style.setProperty("--wb-scroll-duration",`${s}s`),t.classList.add("wb-scrolling")}})}_renderMeta(t){if(!this.metaEl)return;let e=[];if(t.bpm&&e.push({label:t.bpm+" BPM",type:"bpm"}),t.key&&e.push({label:t.key,type:"key"}),t.duration&&e.push({label:t.duration,type:"duration"}),t.meta)for(let[s,r]of Object.entries(t.meta))r&&e.length<this.config.maxMeta&&e.push({label:String(r),type:s});let i=e.slice(0,this.config.maxMeta);this.metaEl.style.display=i.length?"flex":"none",this.metaEl.innerHTML=i.map(s=>`<span class="wb-tag wb-tag-${h(s.type)}">${h(s.label)}</span>`).join("")}_updatePlayButton(){if(!this.playBtnEl)return;let t=this.playBtnEl.querySelector(".wb-icon-play"),e=this.playBtnEl.querySelector(".wb-icon-pause");t&&(t.style.display=this.isPlaying?"none":"block"),e&&(e.style.display=this.isPlaying?"block":"none"),this.playBtnEl.title=this.isPlaying?"Pause":"Play"}_updateNavButtons(){let t=this.barEl?.querySelector(".wb-prev"),e=this.barEl?.querySelector(".wb-next");this.repeat==="all"?(t&&t.classList.remove("wb-disabled"),e&&e.classList.remove("wb-disabled")):(t&&t.classList.toggle("wb-disabled",this.currentIndex<=0),e&&e.classList.toggle("wb-disabled",this.currentIndex>=this.queue.length-1))}cycleRepeat(){let t=["off","all","one"],e=t.indexOf(this.repeat);return this.repeat=t[(e+1)%t.length],this._updateRepeatButton(),this._updateNavButtons(),this._emit("repeatchange",{mode:this.repeat}),this}setRepeat(t){return["off","all","one"].includes(t)&&(this.repeat=t,this._updateRepeatButton(),this._updateNavButtons(),this._emit("repeatchange",{mode:this.repeat})),this}_updateRepeatButton(){if(!this.repeatBtnEl)return;let t={off:n.repeatOff,all:n.repeatAll,one:n.repeatOne},e={off:"Repeat: Off",all:"Repeat: All",one:"Repeat: One"};this.repeatBtnEl.innerHTML=t[this.repeat],this.repeatBtnEl.title=e[this.repeat],this.repeatBtnEl.classList.toggle("wb-repeat-active",this.repeat!=="off")}_checkMarkerBoundary(t){if(!this._activeMarkers)return;let e=-1;for(let l=this._activeMarkers.length-1;l>=0;l--)if(t>=this._activeMarkers[l].time){e=l;break}if(e===this._currentMarkerIndex||(this._currentMarkerIndex=e,e<0))return;let i=this._activeMarkers[e],s=this.getCurrentTrack();i.title&&this.titleEl&&this._setScrollText(this.titleEl,i.title),i.artist&&this.artistEl&&this._setScrollText(this.artistEl,i.artist);let r=this.waveformContainer?.querySelectorAll(".waveform-marker");if(r&&r.forEach((l,u)=>l.classList.toggle("wb-marker-active",u===e)),i.artwork){let l=this.barEl.querySelector(".wb-artwork");l&&(l.innerHTML=`<img src="${h(i.artwork)}" alt="${h(i.title||"")}" />`)}if(this.metaEl&&(i.bpm||i.key)){let l={...s||{},bpm:i.bpm||"",key:i.key||""};this._renderMeta(l)}this._emit("markerchange",{marker:i,index:e,track:s})}_updateVolumeUI(){this.volumeSliderEl&&(this.volumeSliderEl.value=this.isMuted?0:Math.round(this.volume*100)),this.muteBtnEl&&(this.isMuted||this.volume===0?(this.muteBtnEl.innerHTML=n.volMute,this.muteBtnEl.classList.add("wb-muted"),this.muteBtnEl.title="Unmute"):this.volume<.5?(this.muteBtnEl.innerHTML=n.volLow,this.muteBtnEl.classList.remove("wb-muted"),this.muteBtnEl.title="Mute"):(this.muteBtnEl.innerHTML=n.volHigh,this.muteBtnEl.classList.remove("wb-muted"),this.muteBtnEl.title="Mute"))}_detectTheme(){let t=document.documentElement,e=document.body,i=["dark","dark-mode","theme-dark"],s=["light","light-mode","theme-light"];for(let r of i)if(t.classList.contains(r)||e.classList.contains(r))return"dark";if(t.getAttribute("data-theme")==="dark"||e.getAttribute("data-theme")==="dark")return"dark";for(let r of s)if(t.classList.contains(r)||e.classList.contains(r))return"light";if(t.getAttribute("data-theme")==="light"||e.getAttribute("data-theme")==="light")return"light";try{let l=getComputedStyle(e).backgroundColor.match(/\d+/g);if(l&&l.length>=3){let u=(l[0]*299+l[1]*587+l[2]*114)/1e3;if(u>128)return"light";if(u<128)return"dark"}}catch{}return window.matchMedia?.("(prefers-color-scheme: light)").matches?"light":"dark"}_refreshTheme(){if(this.config&&this.config.theme)return;let t=this._detectTheme();if(t===this._resolvedTheme)return;this._resolvedTheme=t;let e=t==="light";this.barEl&&this.barEl.classList.toggle("wb-light",e),this.queueEl&&this.queueEl.classList.toggle("wb-light",e)}_watchTheme(){if(typeof document>"u")return;let t=()=>requestAnimationFrame(()=>this._refreshTheme()),e={attributes:!0,attributeFilter:["class","data-theme","data-color-scheme","style"]};this._themeObserver=new MutationObserver(t),this._themeObserver.observe(document.documentElement,e),document.body&&this._themeObserver.observe(document.body,e);try{this._themeMq=window.matchMedia("(prefers-color-scheme: dark)"),this._themeMqHandler=t,this._themeMq.addEventListener("change",this._themeMqHandler)}catch{}}_updateFavoriteUI(){if(!this.favBtnEl)return;let t=this.isFavorited();this.favBtnEl.innerHTML=t?n.heartFilled:n.heart,this.favBtnEl.classList.toggle("wb-fav-active",t)}_renderQueue(){T(this.queueBodyEl,this.queueCountEl,this.queue,this.currentIndex,{onSkipTo:t=>this.skipTo(t),onRemove:t=>this.removeFromQueue(t)})}_syncPageState(){let t=this.getCurrentTrack(),e=t?t.url:null;document.querySelectorAll("[data-wb-play]").forEach(i=>{let s=i.dataset.wbUrl||i.dataset.url,r=i.dataset.wbId||i.dataset.id||s,l=s&&s===e;i.classList.toggle("wb-current",l),i.classList.toggle("wb-playing",l&&this.isPlaying),i.classList.toggle("wb-favorited",this._favorites.has(r)),i.classList.toggle("wb-in-cart",this._cartItems.has(r))})}_seedFromAttributes(){let t=!1,e=!1;document.querySelectorAll("[data-wb-play]").forEach(i=>{let s=i.dataset.wbId||i.dataset.id||i.dataset.wbUrl||i.dataset.url;s&&(i.dataset.wbFavorited==="true"&&(this._favorites.add(s),t=!0),i.dataset.wbInCart==="true"&&(this._cartItems.add(s),e=!0))}),t&&b(this.config.storageKey,this._favorites)}_syncFavoriteAttributes(t,e){document.querySelectorAll("[data-wb-play]").forEach(i=>{(i.dataset.wbUrl||i.dataset.url)===t&&(i.dataset.wbFavorited=e?"true":"false",i.classList.toggle("wb-favorited",e))})}_syncCartAttributes(t,e){document.querySelectorAll("[data-wb-play]").forEach(i=>{(i.dataset.wbUrl||i.dataset.url)===t&&(i.dataset.wbInCart=e?"true":"false",i.classList.toggle("wb-in-cart",e))})}_saveState(){this.config.persist&&y(this.config.storageKey,{queue:this.queue,currentIndex:this.currentIndex,position:this._lastPosition||0,isPlaying:this.isPlaying})}_restoreState(){if(!this.config.persist)return;let t=_(this.config.storageKey);if(!t)return;this.queue=t.queue,this.currentIndex=t.currentIndex;let e=this.getCurrentTrack();if(!e)return;this.show(),this._updateTrackDisplay(e),this._updateFavoriteUI(),this._updateNavButtons();let i={autoplay:!1};if(e.waveform&&(i.waveform=e.waveform),e.markers&&e.markers.length){let r=this.config.markerColor;i.markers=e.markers.map(l=>({...l,color:l.color||r})),this._activeMarkers=e.markers}else i.markers=[],this._activeMarkers=null;this._currentMarkerIndex=-1;let s=++this._loadSeq;this._restoreSeekTimeout&&(clearTimeout(this._restoreSeekTimeout),this._restoreSeekTimeout=null),this.player.loadTrack(e.url,e.title,e.artist,i).then(()=>{if(this._loadSeq===s){if(this.player&&this.player.setVolume(this.isMuted?0:this.volume),t.isPlaying&&this.config.autoResume)try{let r=this.player.play();r&&typeof r.catch=="function"&&r.catch(()=>{this.isPlaying=!1,this._updatePlayButton(),this._syncPageState()})}catch{this.isPlaying=!1,this._updatePlayButton(),this._syncPageState()}t.position>0&&(this._restoreSeekTimeout=setTimeout(()=>{this._restoreSeekTimeout=null,this._loadSeq===s&&this.player&&(this.player.seekTo(t.position),this._lastPosition=t.position)},100))}}).catch(()=>{}),this._renderQueue(),this._syncPageState()}_restoreVolume(){let t=E(this.config.storageKey);if(!t)return;let e=Number(t.volume);this.volume=Number.isFinite(e)?Math.max(0,Math.min(1,e)):1,this.isMuted=t.muted,this._volumeBeforeMute=t.volumeBeforeMute,this.player&&this.player.setVolume(this.isMuted?0:this.volume),this._updateVolumeUI()}_restoreFavorites(){this._favorites=k(this.config.storageKey)}};var S=new m;typeof window<"u"&&(window.WaveformBar=S);var D=S;})();
45
45
  /**
46
46
  * WaveformBar v1.0.0
47
47
  * Persistent bottom audio player bar for WaveformPlayer
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arraypress/waveform-bar",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Persistent bottom audio player bar for WaveformPlayer - queue management, page persistence, and seamless playback.",
5
5
  "main": "dist/waveform-bar.js",
6
6
  "module": "dist/waveform-bar.esm.js",
@@ -191,7 +191,6 @@
191
191
  .wb-artwork {
192
192
  width: 40px;
193
193
  height: 40px;
194
- border-radius: 6px;
195
194
  background: linear-gradient(135deg, var(--wb-accent), var(--wb-accent-light));
196
195
  display: flex;
197
196
  align-items: center;
package/src/js/core.js CHANGED
@@ -152,6 +152,7 @@ export class WaveformBar {
152
152
  this._initPlayer();
153
153
  this._bindTriggers();
154
154
  this._observeDOM();
155
+ this._watchTheme();
155
156
 
156
157
  if (this.config.persist) {
157
158
  this._restoreVolume();
@@ -193,6 +194,15 @@ export class WaveformBar {
193
194
  this.player.destroy();
194
195
  this.player = null;
195
196
  }
197
+ if (this._themeObserver) {
198
+ this._themeObserver.disconnect();
199
+ this._themeObserver = null;
200
+ }
201
+ if (this._themeMq && this._themeMqHandler) {
202
+ this._themeMq.removeEventListener('change', this._themeMqHandler);
203
+ this._themeMq = null;
204
+ this._themeMqHandler = null;
205
+ }
196
206
  if (this._docClickVolume) {
197
207
  document.removeEventListener('click', this._docClickVolume);
198
208
  this._docClickVolume = null;
@@ -1726,6 +1736,44 @@ export class WaveformBar {
1726
1736
  return 'dark';
1727
1737
  }
1728
1738
 
1739
+ /**
1740
+ * Re-detect the page theme and toggle the bar's `wb-light` class (on the bar
1741
+ * and the queue panel) to match, so the bar adapts to a runtime light/dark
1742
+ * switch — not just the theme present when it was first shown. No-op when
1743
+ * `config.theme` is set explicitly.
1744
+ * @private
1745
+ */
1746
+ _refreshTheme() {
1747
+ if (this.config && this.config.theme) return;
1748
+ const theme = this._detectTheme();
1749
+ if (theme === this._resolvedTheme) return;
1750
+ this._resolvedTheme = theme;
1751
+ const light = theme === 'light';
1752
+ if (this.barEl) this.barEl.classList.toggle('wb-light', light);
1753
+ if (this.queueEl) this.queueEl.classList.toggle('wb-light', light);
1754
+ }
1755
+
1756
+ /**
1757
+ * Watch the document for theme changes — a class/attribute flip on
1758
+ * `<html>`/`<body>` (Tailwind `dark`, `data-theme`, `data-color-scheme`) or
1759
+ * an OS `prefers-color-scheme` change — and re-detect. Event-driven
1760
+ * (MutationObserver + matchMedia), never a timer. Torn down in destroy().
1761
+ * @private
1762
+ */
1763
+ _watchTheme() {
1764
+ if (typeof document === 'undefined') return;
1765
+ const refresh = () => requestAnimationFrame(() => this._refreshTheme());
1766
+ const opts = {attributes: true, attributeFilter: ['class', 'data-theme', 'data-color-scheme', 'style']};
1767
+ this._themeObserver = new MutationObserver(refresh);
1768
+ this._themeObserver.observe(document.documentElement, opts);
1769
+ if (document.body) this._themeObserver.observe(document.body, opts);
1770
+ try {
1771
+ this._themeMq = window.matchMedia('(prefers-color-scheme: dark)');
1772
+ this._themeMqHandler = refresh;
1773
+ this._themeMq.addEventListener('change', this._themeMqHandler);
1774
+ } catch (e) { /* no matchMedia */ }
1775
+ }
1776
+
1729
1777
  _updateFavoriteUI() {
1730
1778
  if (!this.favBtnEl) return;
1731
1779
  const fav = this.isFavorited();