import { __name } from '../chunk-PAWJFY3S.mjs';
import { createContext, forwardRef, useSyncExternalStore, useId, useState, useEffect, useRef, useMemo, useContext, useCallback, useImperativeHandle } from 'react';
import { jsx, jsxs } from 'react/jsx-runtime';
import { useHotkey, useIsPhone } from '@djangocfg/ui-core/hooks';
import { Play, SkipBack, SkipForward, Repeat, VolumeX, Volume2, Music, AlertTriangle, RotateCcw, Pause, LoaderCircle } from 'lucide-react';
import { Tooltip, TooltipTrigger, TooltipContent, Popover, PopoverTrigger, PopoverContent, Slider } from '@djangocfg/ui-core/components';
import { useThemeColor, alpha } from '@djangocfg/ui-core/styles/palette';

// src/tools/media/AudioPlayer/audio/audioContext.ts
var _ctx = null;
function getAudioContext() {
  if (_ctx) return _ctx;
  const w = window;
  const Ctor = w.AudioContext ?? w.webkitAudioContext;
  if (!Ctor) {
    throw new Error("Web Audio API is not supported in this environment");
  }
  _ctx = new Ctor({ latencyHint: "interactive" });
  return _ctx;
}
__name(getAudioContext, "getAudioContext");
async function unlockAudioContext() {
  const ctx = getAudioContext();
  if (ctx.state === "suspended") {
    try {
      await ctx.resume();
    } catch {
    }
  }
}
__name(unlockAudioContext, "unlockAudioContext");

// src/tools/media/AudioPlayer/utils/bucketize.ts
function bucketize(channel2, buckets) {
  const out = new Float32Array(buckets);
  if (buckets <= 0 || channel2.length === 0) return out;
  const samplesPerBucket = Math.max(1, Math.floor(channel2.length / buckets));
  let peakMax = 0;
  for (let b = 0; b < buckets; b++) {
    const start = b * samplesPerBucket;
    const end = Math.min(start + samplesPerBucket, channel2.length);
    let max = 0;
    for (let i = start; i < end; i++) {
      const v = channel2[i];
      const abs = v < 0 ? -v : v;
      if (abs > max) max = abs;
    }
    out[b] = max;
    if (max > peakMax) peakMax = max;
  }
  if (peakMax > 0 && peakMax < 1) {
    const scale = 1 / peakMax;
    for (let i = 0; i < out.length; i++) out[i] *= scale;
  }
  return out;
}
__name(bucketize, "bucketize");

// src/tools/media/AudioPlayer/audio/decodePeaks.ts
var SAMPLE_RATE = 22050;
var DEFAULT_BUCKETS = 1800;
function getOfflineCtor() {
  const w = window;
  const Ctor = w.OfflineAudioContext ?? w.webkitOfflineAudioContext;
  if (!Ctor) throw new Error("OfflineAudioContext is not supported");
  return Ctor;
}
__name(getOfflineCtor, "getOfflineCtor");
async function decodePeaks(src, buckets = DEFAULT_BUCKETS, signal) {
  const response = await fetch(src, { signal, credentials: "same-origin" });
  if (!response.ok) {
    throw new Error(`Failed to fetch audio for peaks (${response.status})`);
  }
  const arr = await response.arrayBuffer();
  const Ctor = getOfflineCtor();
  const ctx = new Ctor(1, 1, SAMPLE_RATE);
  const audio = await ctx.decodeAudioData(arr);
  const channel2 = audio.getChannelData(0);
  return bucketize(channel2, buckets);
}
__name(decodePeaks, "decodePeaks");

// src/tools/media/AudioPlayer/audio/peaksCache.ts
var cache = /* @__PURE__ */ new Map();
var inflight = /* @__PURE__ */ new Map();
async function getPeaks(src, buckets) {
  const hit = cache.get(src);
  if (hit) return hit;
  const flying = inflight.get(src);
  if (flying) return flying;
  const promise = decodePeaks(src, buckets).then((peaks) => {
    cache.set(src, peaks);
    return peaks;
  });
  inflight.set(src, promise);
  try {
    return await promise;
  } finally {
    inflight.delete(src);
  }
}
__name(getPeaks, "getPeaks");
function setPeaks(src, peaks) {
  cache.set(src, peaks);
}
__name(setPeaks, "setPeaks");
function getPeaksFromCache(src) {
  return cache.get(src);
}
__name(getPeaksFromCache, "getPeaksFromCache");

// src/tools/media/AudioPlayer/store/activePlayerBus.ts
var CHANNEL = "djangocfg-audioplayer:active";
var activeId = null;
var lastActiveId = null;
var listeners = /* @__PURE__ */ new Set();
var pausers = /* @__PURE__ */ new Map();
var channel = null;
function getChannel() {
  if (typeof BroadcastChannel === "undefined") return null;
  if (channel) return channel;
  channel = new BroadcastChannel(CHANNEL);
  channel.addEventListener("message", (e) => {
    const next = typeof e.data === "string" ? e.data : null;
    if (next === activeId) return;
    activeId = next;
    if (next) lastActiveId = next;
    for (const [id, pause] of pausers) {
      if (id !== next) pause();
    }
    for (const l of listeners) l(next);
  });
  return channel;
}
__name(getChannel, "getChannel");
function registerPlayer(id, pause) {
  pausers.set(id, pause);
  return () => {
    pausers.delete(id);
    if (activeId === id) activeId = null;
  };
}
__name(registerPlayer, "registerPlayer");
function setActivePlayer(id) {
  if (activeId === id) return;
  activeId = id;
  if (id) lastActiveId = id;
  for (const [pid, pause] of pausers) {
    if (pid !== id) pause();
  }
  for (const l of listeners) l(id);
  getChannel()?.postMessage(id);
}
__name(setActivePlayer, "setActivePlayer");
function getActivePlayer() {
  return activeId;
}
__name(getActivePlayer, "getActivePlayer");
function getLastActivePlayer() {
  return lastActiveId;
}
__name(getLastActivePlayer, "getLastActivePlayer");
function subscribeActivePlayer(cb) {
  listeners.add(cb);
  getChannel();
  return () => listeners.delete(cb);
}
__name(subscribeActivePlayer, "subscribeActivePlayer");

// src/tools/media/AudioPlayer/store/createLevelsStore.ts
function createLevelsStore(initial) {
  let current = initial ?? new Float32Array(0);
  let active = false;
  const listeners3 = /* @__PURE__ */ new Set();
  return {
    subscribe(cb) {
      listeners3.add(cb);
      return () => listeners3.delete(cb);
    },
    getCurrent() {
      return current;
    },
    set(next) {
      current = next;
      for (const cb of listeners3) cb();
    },
    setActive(value) {
      active = value;
    },
    isActive() {
      return active;
    }
  };
}
__name(createLevelsStore, "createLevelsStore");

// src/tools/media/AudioPlayer/store/preferencesStore.ts
var STORAGE_KEY = "djangocfg-audioplayer:prefs";
var DEFAULT_VOLUME = 1;
var DEFAULT_MUTED = false;
var cached = null;
var listeners2 = /* @__PURE__ */ new Set();
var storageBound = false;
function clamp01(v) {
  if (!Number.isFinite(v)) return DEFAULT_VOLUME;
  return v < 0 ? 0 : v > 1 ? 1 : v;
}
__name(clamp01, "clamp01");
function readFromStorage() {
  if (typeof window === "undefined") {
    return { volume: DEFAULT_VOLUME, muted: DEFAULT_MUTED };
  }
  try {
    const raw = window.localStorage.getItem(STORAGE_KEY);
    if (!raw) return { volume: DEFAULT_VOLUME, muted: DEFAULT_MUTED };
    const parsed = JSON.parse(raw);
    return {
      volume: typeof parsed?.volume === "number" ? clamp01(parsed.volume) : DEFAULT_VOLUME,
      muted: typeof parsed?.muted === "boolean" ? parsed.muted : DEFAULT_MUTED
    };
  } catch {
    return { volume: DEFAULT_VOLUME, muted: DEFAULT_MUTED };
  }
}
__name(readFromStorage, "readFromStorage");
function writeToStorage(prefs) {
  if (typeof window === "undefined") return;
  try {
    window.localStorage.setItem(STORAGE_KEY, JSON.stringify(prefs));
  } catch {
  }
}
__name(writeToStorage, "writeToStorage");
function bindStorage() {
  if (storageBound || typeof window === "undefined") return;
  storageBound = true;
  window.addEventListener("storage", (e) => {
    if (e.key !== STORAGE_KEY) return;
    cached = readFromStorage();
    for (const cb of listeners2) cb(cached);
  });
}
__name(bindStorage, "bindStorage");
function getPreferences() {
  if (!cached) cached = readFromStorage();
  bindStorage();
  return cached;
}
__name(getPreferences, "getPreferences");
function update(next, persist = true) {
  cached = next;
  if (persist) writeToStorage(next);
  for (const cb of listeners2) cb(next);
}
__name(update, "update");
function setStoredVolume(volume) {
  const current = getPreferences();
  const v = clamp01(volume);
  if (v === current.volume) return;
  update({ ...current, volume: v });
}
__name(setStoredVolume, "setStoredVolume");
function setStoredMuted(muted) {
  const current = getPreferences();
  if (muted === current.muted) return;
  update({ ...current, muted });
}
__name(setStoredMuted, "setStoredMuted");
function subscribePreferences(cb) {
  listeners2.add(cb);
  bindStorage();
  return () => listeners2.delete(cb);
}
__name(subscribePreferences, "subscribePreferences");

// src/tools/media/AudioPlayer/utils/clamp.ts
function clamp(value, min, max) {
  if (value < min) return min;
  if (value > max) return max;
  return value;
}
__name(clamp, "clamp");
var AudioRefCtx = createContext(null);
AudioRefCtx.displayName = "AudioPlayerAudioRefCtx";
var ControlsCtx = createContext(null);
ControlsCtx.displayName = "AudioPlayerControlsCtx";
var LevelsCtx = createContext(null);
LevelsCtx.displayName = "AudioPlayerLevelsCtx";
var MetaCtx = createContext(null);
MetaCtx.displayName = "AudioPlayerMetaCtx";
var StateCtx = createContext(null);
StateCtx.displayName = "AudioPlayerStateCtx";
var TRACKED = [
  "play",
  "pause",
  "ended",
  "loadstart",
  "loadedmetadata",
  "durationchange",
  "emptied",
  "waiting",
  "canplay",
  "error"
];
var LOAD_WATCHDOG_MS = 12e3;
var SYNTHETIC_NETWORK_ERROR = 2;
function readSnapshot(audio, stalled) {
  const nativeCode = audio.error?.code ?? null;
  return {
    paused: audio.paused,
    ended: audio.ended,
    duration: Number.isFinite(audio.duration) ? audio.duration : 0,
    ready: audio.readyState >= 2,
    errorCode: nativeCode ?? (stalled ? SYNTHETIC_NETWORK_ERROR : null)
  };
}
__name(readSnapshot, "readSnapshot");
function snapshotsEqual(a, b) {
  return a.paused === b.paused && a.ended === b.ended && a.duration === b.duration && a.ready === b.ready && a.errorCode === b.errorCode;
}
__name(snapshotsEqual, "snapshotsEqual");
function createAudioSnapshotSource(audio) {
  let stalled = false;
  let cached2 = readSnapshot(audio, stalled);
  return {
    subscribe(cb) {
      let watchdog = null;
      const clearWatchdog = /* @__PURE__ */ __name(() => {
        if (watchdog !== null) {
          clearTimeout(watchdog);
          watchdog = null;
        }
      }, "clearWatchdog");
      const refresh = /* @__PURE__ */ __name(() => {
        const next = readSnapshot(audio, stalled);
        if (!snapshotsEqual(cached2, next)) {
          cached2 = next;
          cb();
        }
      }, "refresh");
      const armWatchdog = /* @__PURE__ */ __name(() => {
        clearWatchdog();
        if (audio.readyState >= 2 || audio.error) return;
        watchdog = setTimeout(() => {
          watchdog = null;
          if (audio.readyState < 2 && !audio.error) {
            stalled = true;
            refresh();
          }
        }, LOAD_WATCHDOG_MS);
      }, "armWatchdog");
      const onProgress = /* @__PURE__ */ __name((e) => {
        if (e.type === "loadstart" || e.type === "emptied") {
          stalled = false;
          armWatchdog();
        } else if (audio.readyState >= 2 || audio.error) {
          clearWatchdog();
          if (stalled) stalled = false;
        }
        refresh();
      }, "onProgress");
      for (const e of TRACKED) audio.addEventListener(e, onProgress);
      armWatchdog();
      refresh();
      return () => {
        clearWatchdog();
        for (const e of TRACKED) audio.removeEventListener(e, onProgress);
      };
    },
    getSnapshot() {
      return cached2;
    },
    getServerSnapshot() {
      return cached2;
    }
  };
}
__name(createAudioSnapshotSource, "createAudioSnapshotSource");
function errorCodeToReason(code) {
  if (code === 2) return "network";
  if (code === 3) return "decode";
  if (code === 4) return "unsupported";
  return "unknown";
}
__name(errorCodeToReason, "errorCodeToReason");
function snapshotToState(snap, hasSrc, peaks) {
  if (snap.errorCode !== null) {
    return { kind: "error", reason: errorCodeToReason(snap.errorCode), duration: snap.duration };
  }
  if (!hasSrc) return { kind: "idle" };
  if (!snap.ready) return { kind: "loading" };
  const kind = snap.ended ? "ended" : snap.paused ? "paused" : "playing";
  return { kind, duration: snap.duration, peaks };
}
__name(snapshotToState, "snapshotToState");
function useAudioElementState(source, hasSrc, peaks) {
  const snap = useSyncExternalStore(source.subscribe, source.getSnapshot, source.getServerSnapshot);
  return snapshotToState(snap, hasSrc, peaks);
}
__name(useAudioElementState, "useAudioElementState");
function createAudioElement() {
  const a = new Audio();
  a.crossOrigin = "anonymous";
  a.preload = "metadata";
  return a;
}
__name(createAudioElement, "createAudioElement");
function PlayerProvider(props) {
  const {
    src,
    peaks: peaksProp,
    title,
    artist,
    album,
    cover,
    autoplay = false,
    loop = false,
    initialVolume,
    muted: mutedProp,
    preload = "metadata",
    exclusive = true,
    onPrev,
    onNext,
    onPlay,
    onPause,
    onEnded,
    onError,
    children
  } = props;
  const volumeIsControlled = initialVolume !== void 0;
  const mutedIsControlled = mutedProp !== void 0;
  const playerId = useId();
  const [audio] = useState(createAudioElement);
  const [source] = useState(() => createAudioSnapshotSource(audio));
  const [levelsStore] = useState(() => createLevelsStore());
  const [activePeaks, setActivePeaks] = useState(
    () => peaksProp ?? getPeaksFromCache(src)
  );
  useEffect(() => {
    if (peaksProp && getPeaksFromCache(src) === void 0) {
      setPeaks(src, peaksProp);
    }
  }, [src, peaksProp]);
  useEffect(() => {
    if (audio.src !== src) {
      audio.src = src;
      audio.load();
    }
  }, [audio, src]);
  useEffect(() => {
    audio.preload = preload;
  }, [audio, preload]);
  useEffect(() => {
    audio.loop = loop;
  }, [audio, loop]);
  useEffect(() => {
    const stored = getPreferences();
    audio.volume = clamp(volumeIsControlled ? initialVolume : stored.volume, 0, 1);
    audio.muted = mutedIsControlled ? Boolean(mutedProp) : stored.muted;
  }, [audio]);
  useEffect(() => {
    if (!volumeIsControlled || initialVolume === void 0) return;
    audio.volume = clamp(initialVolume, 0, 1);
  }, [audio, volumeIsControlled, initialVolume]);
  useEffect(() => {
    if (!mutedIsControlled || mutedProp === void 0) return;
    audio.muted = mutedProp;
  }, [audio, mutedIsControlled, mutedProp]);
  useEffect(() => {
    if (volumeIsControlled && mutedIsControlled) return;
    return subscribePreferences((prefs) => {
      if (!volumeIsControlled && audio.volume !== prefs.volume) {
        audio.volume = prefs.volume;
      }
      if (!mutedIsControlled && audio.muted !== prefs.muted) {
        audio.muted = prefs.muted;
      }
    });
  }, [audio, volumeIsControlled, mutedIsControlled]);
  useEffect(() => {
    setActivePeaks(peaksProp ?? getPeaksFromCache(src));
  }, [src, peaksProp]);
  useEffect(() => {
    const handlePlay = /* @__PURE__ */ __name(() => onPlay?.(), "handlePlay");
    const handlePause = /* @__PURE__ */ __name(() => onPause?.(), "handlePause");
    const handleEnded = /* @__PURE__ */ __name(() => onEnded?.(), "handleEnded");
    const handleError = /* @__PURE__ */ __name((e) => {
      const code = audio.error?.code ?? null;
      const reason = code === 2 ? "network" : code === 3 ? "decode" : code === 4 ? "unsupported" : "unknown";
      onError?.(reason, e);
    }, "handleError");
    audio.addEventListener("play", handlePlay);
    audio.addEventListener("pause", handlePause);
    audio.addEventListener("ended", handleEnded);
    audio.addEventListener("error", handleError);
    return () => {
      audio.removeEventListener("play", handlePlay);
      audio.removeEventListener("pause", handlePause);
      audio.removeEventListener("ended", handleEnded);
      audio.removeEventListener("error", handleError);
    };
  }, [audio, onEnded, onError, onPause, onPlay]);
  const exclusiveRef = useRef(exclusive);
  exclusiveRef.current = exclusive;
  const playerIdRef = useRef(playerId);
  playerIdRef.current = playerId;
  useEffect(() => {
    if (!exclusive) return;
    const unregister = registerPlayer(playerId, () => {
      audio.pause();
    });
    const onPlayHandler = /* @__PURE__ */ __name(() => setActivePlayer(playerId), "onPlayHandler");
    audio.addEventListener("play", onPlayHandler);
    return () => {
      audio.removeEventListener("play", onPlayHandler);
      unregister();
    };
  }, [audio, exclusive, playerId]);
  useEffect(() => {
    return () => {
      try {
        audio.pause();
        audio.removeAttribute("src");
        audio.load();
      } catch {
      }
    };
  }, [audio]);
  const controls = useMemo(() => {
    const playFn = /* @__PURE__ */ __name(async () => {
      if (exclusiveRef.current) setActivePlayer(playerIdRef.current);
      try {
        await unlockAudioContext();
      } catch {
      }
      try {
        await audio.play();
      } catch (e) {
        const isAbort = e instanceof DOMException && e.name === "AbortError";
        if (!isAbort) onError?.("unknown", e);
      }
    }, "playFn");
    const pauseFn = /* @__PURE__ */ __name(() => {
      audio.pause();
    }, "pauseFn");
    return {
      play: playFn,
      pause: pauseFn,
      toggle: /* @__PURE__ */ __name(async () => {
        if (audio.paused || audio.ended) await playFn();
        else pauseFn();
      }, "toggle"),
      seek: /* @__PURE__ */ __name((seconds) => {
        if (!Number.isFinite(seconds)) return;
        const dur = Number.isFinite(audio.duration) ? audio.duration : 0;
        audio.currentTime = clamp(seconds, 0, dur || seconds);
      }, "seek"),
      seekTo: /* @__PURE__ */ __name((ratio) => {
        const r = clamp(ratio, 0, 1);
        const dur = Number.isFinite(audio.duration) ? audio.duration : 0;
        if (dur > 0) audio.currentTime = r * dur;
      }, "seekTo"),
      setVolume: /* @__PURE__ */ __name((v) => {
        const next = clamp(v, 0, 1);
        audio.volume = next;
        if (next > 0 && audio.muted) audio.muted = false;
        if (!volumeIsControlled) setStoredVolume(next);
        if (!mutedIsControlled && next > 0) setStoredMuted(false);
      }, "setVolume"),
      toggleMute: /* @__PURE__ */ __name(() => {
        const next = !audio.muted;
        audio.muted = next;
        if (!mutedIsControlled) setStoredMuted(next);
      }, "toggleMute"),
      toggleLoop: /* @__PURE__ */ __name(() => {
        audio.loop = !audio.loop;
      }, "toggleLoop")
    };
  }, [audio, volumeIsControlled, mutedIsControlled]);
  useEffect(() => {
    if (!autoplay) return;
    void controls.play();
  }, [autoplay, controls]);
  const state = useAudioElementState(source, Boolean(audio.src), activePeaks);
  const meta = useMemo(
    () => ({
      src,
      title,
      artist,
      album,
      cover,
      hasPrev: Boolean(onPrev),
      hasNext: Boolean(onNext)
    }),
    [src, title, artist, album, cover, onPrev, onNext]
  );
  return /* @__PURE__ */ jsx(AudioRefCtx.Provider, { value: audio, children: /* @__PURE__ */ jsx(MetaCtx.Provider, { value: meta, children: /* @__PURE__ */ jsx(StateCtx.Provider, { value: state, children: /* @__PURE__ */ jsx(ControlsCtx.Provider, { value: controls, children: /* @__PURE__ */ jsx(LevelsCtx.Provider, { value: levelsStore, children }) }) }) }) });
}
__name(PlayerProvider, "PlayerProvider");
function useCtxOrThrow(ctx, name) {
  const value = useContext(ctx);
  if (value === null) {
    throw new Error(`${name} must be used inside <PlayerProvider>`);
  }
  return value;
}
__name(useCtxOrThrow, "useCtxOrThrow");
var usePlayerState = /* @__PURE__ */ __name(() => useCtxOrThrow(StateCtx, "usePlayerState"), "usePlayerState");
var usePlayerControls = /* @__PURE__ */ __name(() => useCtxOrThrow(ControlsCtx, "usePlayerControls"), "usePlayerControls");
var usePlayerLevels = /* @__PURE__ */ __name(() => useCtxOrThrow(LevelsCtx, "usePlayerLevels"), "usePlayerLevels");
var usePlayerMeta = /* @__PURE__ */ __name(() => useCtxOrThrow(MetaCtx, "usePlayerMeta"), "usePlayerMeta");
var usePlayerAudio = /* @__PURE__ */ __name(() => useCtxOrThrow(AudioRefCtx, "usePlayerAudio"), "usePlayerAudio");
var usePlayerPaused = /* @__PURE__ */ __name(() => {
  const s = usePlayerState();
  return s.kind !== "playing";
}, "usePlayerPaused");
var usePlayerDuration = /* @__PURE__ */ __name(() => {
  const s = usePlayerState();
  return "duration" in s ? s.duration : 0;
}, "usePlayerDuration");
function useElementWidth(el) {
  const [w, setW] = useState(0);
  useEffect(() => {
    if (!el || typeof ResizeObserver === "undefined") return;
    setW(el.clientWidth);
    const obs = new ResizeObserver((entries) => {
      for (const entry of entries) {
        const next = entry.contentRect.width;
        setW((prev) => Math.abs(prev - next) < 0.5 ? prev : next);
      }
    });
    obs.observe(el);
    return () => obs.disconnect();
  }, [el]);
  return w;
}
__name(useElementWidth, "useElementWidth");
var OPTS = { preventDefault: true };
var BINDINGS = [
  { label: "Play / pause", hint: "Space" },
  { label: "Seek +5s", hint: "\u2192" },
  { label: "Seek \u22125s", hint: "\u2190" },
  { label: "Volume up", hint: "\u2191" },
  { label: "Volume down", hint: "\u2193" },
  { label: "Toggle mute", hint: "M" },
  { label: "Toggle loop", hint: "L" }
];
function useKeyboardShortcuts({
  audio,
  controls,
  enabled = true
}) {
  const refToggle = useHotkey(["space", "k"], () => void controls.toggle(), {
    ...OPTS,
    enabled,
    description: "Play / pause"
  });
  const refForward = useHotkey("right", () => controls.seek(audio.currentTime + 5), {
    ...OPTS,
    enabled,
    description: "Seek +5s"
  });
  const refBackward = useHotkey("left", () => controls.seek(audio.currentTime - 5), {
    ...OPTS,
    enabled,
    description: "Seek \u22125s"
  });
  const refVolUp = useHotkey("up", () => controls.setVolume(clamp(audio.volume + 0.05, 0, 1)), {
    ...OPTS,
    enabled,
    description: "Volume up"
  });
  const refVolDown = useHotkey("down", () => controls.setVolume(clamp(audio.volume - 0.05, 0, 1)), {
    ...OPTS,
    enabled,
    description: "Volume down"
  });
  const refMute = useHotkey("m", () => controls.toggleMute(), {
    ...OPTS,
    enabled,
    description: "Toggle mute"
  });
  const refLoop = useHotkey("l", () => controls.toggleLoop(), {
    ...OPTS,
    enabled,
    description: "Toggle loop"
  });
  const ref = useCallback(
    (instance) => {
      refToggle(instance);
      refForward(instance);
      refBackward(instance);
      refVolUp(instance);
      refVolDown(instance);
      refMute(instance);
      refLoop(instance);
    },
    [refToggle, refForward, refBackward, refVolUp, refVolDown, refMute, refLoop]
  );
  return { ref, bindings: BINDINGS };
}
__name(useKeyboardShortcuts, "useKeyboardShortcuts");
var ACTIONS = [
  "play",
  "pause",
  "previoustrack",
  "nexttrack",
  "seekbackward",
  "seekforward"
];
function useMediaSession(audio, meta, controls, onPrev, onNext) {
  useEffect(() => {
    if (typeof navigator === "undefined" || !("mediaSession" in navigator)) return;
    const ms = navigator.mediaSession;
    try {
      ms.metadata = new MediaMetadata({
        title: meta.title ?? "",
        artist: meta.artist ?? "",
        album: meta.album ?? "",
        artwork: meta.cover ? [{ src: meta.cover, sizes: "512x512", type: "image/jpeg" }] : []
      });
    } catch {
    }
    const handlers = {
      play: /* @__PURE__ */ __name(() => {
        void controls.play();
      }, "play"),
      pause: /* @__PURE__ */ __name(() => controls.pause(), "pause"),
      previoustrack: onPrev ?? null,
      nexttrack: onNext ?? null,
      seekbackward: /* @__PURE__ */ __name((details) => {
        const offset = details.seekOffset ?? 10;
        controls.seek(audio.currentTime - offset);
      }, "seekbackward"),
      seekforward: /* @__PURE__ */ __name((details) => {
        const offset = details.seekOffset ?? 10;
        controls.seek(audio.currentTime + offset);
      }, "seekforward")
    };
    for (const a of ACTIONS) {
      try {
        ms.setActionHandler(a, handlers[a] ?? null);
      } catch {
      }
    }
    return () => {
      for (const a of ACTIONS) {
        try {
          ms.setActionHandler(a, null);
        } catch {
        }
      }
    };
  }, [audio, controls, meta.title, meta.artist, meta.album, meta.cover, onPrev, onNext]);
}
__name(useMediaSession, "useMediaSession");
function PlayButton({ size = "default" }) {
  const state = usePlayerState();
  const { toggle, play } = usePlayerControls();
  const dim = size === "compact" ? 28 : 36;
  const icon = size === "compact" ? 14 : 16;
  let label = "Play";
  let Icon = Play;
  let onClick = /* @__PURE__ */ __name(() => void toggle(), "onClick");
  let disabled = false;
  switch (state.kind) {
    case "idle":
      Icon = Play;
      disabled = true;
      break;
    case "loading":
    case "decoding":
      Icon = LoaderCircle;
      label = "Loading";
      disabled = true;
      break;
    case "playing":
      Icon = Pause;
      label = "Pause";
      break;
    case "paused":
      Icon = Play;
      label = "Play";
      break;
    case "ended":
      Icon = RotateCcw;
      label = "Replay";
      onClick = /* @__PURE__ */ __name(() => void play(), "onClick");
      break;
    case "error":
      Icon = Play;
      label = "Retry";
      onClick = /* @__PURE__ */ __name(() => void play(), "onClick");
      break;
  }
  const button = /* @__PURE__ */ jsx(
    "button",
    {
      type: "button",
      onClick,
      disabled,
      "aria-label": label,
      className: "audioplayer-press grid place-items-center rounded-full bg-foreground text-background transition-colors hover:bg-foreground/90 disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60",
      style: { width: dim, height: dim },
      children: /* @__PURE__ */ jsx(
        Icon,
        {
          size: icon,
          strokeWidth: 2,
          className: state.kind === "loading" || state.kind === "decoding" ? "animate-spin" : ""
        }
      )
    }
  );
  return /* @__PURE__ */ jsxs(Tooltip, { children: [
    /* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: button }),
    /* @__PURE__ */ jsx(TooltipContent, { side: "top", children: /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5", children: [
      label,
      /* @__PURE__ */ jsx("kbd", { className: "rounded border border-border/40 bg-muted px-1 font-mono text-[10px] text-muted-foreground", children: "Space" })
    ] }) })
  ] });
}
__name(PlayButton, "PlayButton");
var IconButton = forwardRef(/* @__PURE__ */ __name(function IconButton2({ label, shortcut, active, children, noTooltip, className = "", ...rest }, ref) {
  const stateClasses = active ? "bg-primary/10 text-primary hover:bg-primary/15" : "text-muted-foreground hover:bg-accent hover:text-foreground";
  const button = /* @__PURE__ */ jsx(
    "button",
    {
      ref,
      type: "button",
      "aria-label": label,
      "aria-pressed": active,
      className: `audioplayer-press grid h-8 w-8 place-items-center rounded-md transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60 disabled:opacity-50 disabled:pointer-events-none ${stateClasses} ${className}`,
      ...rest,
      children
    }
  );
  if (noTooltip) return button;
  return /* @__PURE__ */ jsxs(Tooltip, { children: [
    /* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: button }),
    /* @__PURE__ */ jsx(TooltipContent, { side: "top", children: /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5", children: [
      label,
      shortcut && /* @__PURE__ */ jsx("kbd", { className: "rounded border border-border/40 bg-muted px-1 font-mono text-[10px] text-muted-foreground", children: shortcut })
    ] }) })
  ] });
}, "IconButton"));
function SkipButton({ direction, onClick }) {
  if (!onClick) return null;
  const Icon = direction === "prev" ? SkipBack : SkipForward;
  const label = direction === "prev" ? "Previous track" : "Next track";
  return /* @__PURE__ */ jsx(IconButton, { label, shortcut: direction === "prev" ? "\u2190" : "\u2192", onClick, children: /* @__PURE__ */ jsx(Icon, { size: 16, strokeWidth: 1.75 }) });
}
__name(SkipButton, "SkipButton");
function LoopButton() {
  const audio = usePlayerAudio();
  const { toggleLoop } = usePlayerControls();
  const [loop, setLoop] = useState(audio.loop);
  useEffect(() => {
    setLoop(audio.loop);
  }, [audio]);
  return /* @__PURE__ */ jsx(
    IconButton,
    {
      label: loop ? "Disable loop" : "Enable loop",
      shortcut: "L",
      active: loop,
      onClick: () => {
        toggleLoop();
        setLoop(audio.loop);
      },
      children: /* @__PURE__ */ jsx(Repeat, { size: 16, strokeWidth: 1.75 })
    }
  );
}
__name(LoopButton, "LoopButton");
function isIosSafari() {
  if (typeof navigator === "undefined") return false;
  const ua = navigator.userAgent;
  const iOS = /iPad|iPhone|iPod/.test(ua) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1;
  return iOS;
}
__name(isIosSafari, "isIosSafari");
var HIDE_VOLUME = isIosSafari();
function VolumeControl() {
  const audio = usePlayerAudio();
  const { setVolume, toggleMute } = usePlayerControls();
  const [volume, setVol] = useState(audio.volume);
  const [muted, setMuted] = useState(audio.muted);
  const [isOpen, setOpen] = useState(false);
  useEffect(() => {
    const sync = /* @__PURE__ */ __name(() => {
      setVol(audio.volume);
      setMuted(audio.muted);
    }, "sync");
    audio.addEventListener("volumechange", sync);
    return () => audio.removeEventListener("volumechange", sync);
  }, [audio]);
  if (HIDE_VOLUME) {
    return /* @__PURE__ */ jsx(
      IconButton,
      {
        label: muted ? "Unmute" : "Mute",
        shortcut: "M",
        active: muted,
        onClick: () => {
          toggleMute();
          setMuted(audio.muted);
        },
        children: muted || volume === 0 ? /* @__PURE__ */ jsx(VolumeX, { size: 16, strokeWidth: 1.75 }) : /* @__PURE__ */ jsx(Volume2, { size: 16, strokeWidth: 1.75 })
      }
    );
  }
  const Icon = muted || volume === 0 ? VolumeX : Volume2;
  const handleChange = /* @__PURE__ */ __name((v) => {
    setVolume(v);
    setVol(v);
    if (v > 0) setMuted(false);
  }, "handleChange");
  return /* @__PURE__ */ jsxs(Popover, { open: isOpen, onOpenChange: setOpen, children: [
    /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
      IconButton,
      {
        label: isOpen ? "Close volume" : "Volume",
        noTooltip: isOpen,
        active: muted,
        children: /* @__PURE__ */ jsx(Icon, { size: 16, strokeWidth: 1.75 })
      }
    ) }),
    /* @__PURE__ */ jsxs(
      PopoverContent,
      {
        side: "top",
        align: "center",
        sideOffset: 6,
        className: "flex w-14! flex-col items-center gap-2 p-3!",
        onOpenAutoFocus: (e) => e.preventDefault(),
        children: [
          /* @__PURE__ */ jsx("span", { className: "w-full text-center tabular-nums text-[10px] text-muted-foreground", children: Math.round((muted ? 0 : volume) * 100) }),
          /* @__PURE__ */ jsx(
            Slider,
            {
              orientation: "vertical",
              min: 0,
              max: 1,
              step: 0.01,
              value: [muted ? 0 : volume],
              onValueChange: ([v]) => handleChange(v),
              "aria-label": "Volume",
              className: "h-32"
            }
          )
        ]
      }
    )
  ] });
}
__name(VolumeControl, "VolumeControl");

// src/tools/media/AudioPlayer/utils/formatTime.ts
function formatTime(seconds) {
  if (!Number.isFinite(seconds) || seconds < 0) return "0:00";
  const total = Math.floor(seconds);
  const s = total % 60;
  const m = Math.floor(total / 60) % 60;
  const h = Math.floor(total / 3600);
  const ss = s.toString().padStart(2, "0");
  if (h > 0) {
    const mm = m.toString().padStart(2, "0");
    return `${h}:${mm}:${ss}`;
  }
  return `${m}:${ss}`;
}
__name(formatTime, "formatTime");
var READ_INTERVAL_MS = 200;
function TimeDisplay() {
  const audio = usePlayerAudio();
  const duration = usePlayerDuration();
  const currentRef = useRef(null);
  useEffect(() => {
    const el = currentRef.current;
    if (!el) return;
    let last = -1;
    const write = /* @__PURE__ */ __name(() => {
      const t = audio.currentTime;
      if (Math.abs(t - last) < 0.5) return;
      last = t;
      el.textContent = formatTime(t);
    }, "write");
    write();
    const onSeek = /* @__PURE__ */ __name(() => write(), "onSeek");
    audio.addEventListener("seeked", onSeek);
    audio.addEventListener("timeupdate", onSeek);
    const timer = setInterval(() => {
      if (!audio.paused) write();
    }, READ_INTERVAL_MS);
    return () => {
      audio.removeEventListener("seeked", onSeek);
      audio.removeEventListener("timeupdate", onSeek);
      clearInterval(timer);
    };
  }, [audio]);
  return /* @__PURE__ */ jsxs("span", { className: "tabular-nums text-xs text-muted-foreground", children: [
    /* @__PURE__ */ jsx("span", { ref: currentRef, children: formatTime(audio.currentTime) }),
    " / ",
    formatTime(duration)
  ] });
}
__name(TimeDisplay, "TimeDisplay");
function ControlsRow({ onPrev, onNext, showTime = false }) {
  return /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3", children: [
    /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
      /* @__PURE__ */ jsx(SkipButton, { direction: "prev", onClick: onPrev }),
      /* @__PURE__ */ jsx(PlayButton, {}),
      /* @__PURE__ */ jsx(SkipButton, { direction: "next", onClick: onNext })
    ] }),
    /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
      showTime && /* @__PURE__ */ jsx(TimeDisplay, {}),
      /* @__PURE__ */ jsx(VolumeControl, {}),
      /* @__PURE__ */ jsx(LoopButton, {})
    ] })
  ] });
}
__name(ControlsRow, "ControlsRow");
function CoverPlaceholder({ size }) {
  const inset = Math.max(4, Math.round(size * 0.14));
  const iconSize = Math.round(size * 0.4);
  return /* @__PURE__ */ jsxs(
    "div",
    {
      className: "relative grid place-items-center rounded-md bg-muted",
      style: { width: size, height: size },
      "aria-hidden": "true",
      children: [
        /* @__PURE__ */ jsx(
          "span",
          {
            className: "absolute rounded-sm bg-muted-foreground/10",
            style: { inset }
          }
        ),
        /* @__PURE__ */ jsx(
          Music,
          {
            className: "relative text-muted-foreground",
            style: { width: iconSize, height: iconSize },
            strokeWidth: 1.5
          }
        )
      ]
    }
  );
}
__name(CoverPlaceholder, "CoverPlaceholder");
function Cover({ src, alt, size }) {
  const [errored, setErrored] = useState(false);
  if (!src || errored) return /* @__PURE__ */ jsx(CoverPlaceholder, { size });
  return /* @__PURE__ */ jsx(
    "img",
    {
      src,
      alt: alt ?? "",
      width: size,
      height: size,
      loading: "lazy",
      decoding: "async",
      onError: () => setErrored(true),
      className: "block rounded-md object-cover",
      style: { width: size, height: size }
    }
  );
}
__name(Cover, "Cover");
var VAR = "--audioplayer-pulse";
var MAX_SCALE = 0.03;
var SMOOTH = 0.18;
function ReactivePulse({ enabled, children }) {
  const ref = useRef(null);
  const store = usePlayerLevels();
  useEffect(() => {
    if (!enabled) {
      ref.current?.style.setProperty(VAR, "1");
      return;
    }
    const el = ref.current;
    if (!el) return;
    if (typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) {
      el.style.setProperty(VAR, "1");
      return;
    }
    let raf = 0;
    let env = 0;
    const tick = /* @__PURE__ */ __name(() => {
      const buf = store.getCurrent();
      let energy = 0;
      const usable = Math.min(buf.length, 32);
      if (usable > 0) {
        for (let i = 0; i < usable; i++) energy += buf[i];
        energy /= usable;
      }
      env = env + (energy - env) * SMOOTH;
      const scale = 1 + Math.min(MAX_SCALE, env * MAX_SCALE * 1.5);
      el.style.setProperty(VAR, scale.toFixed(4));
      raf = requestAnimationFrame(tick);
    }, "tick");
    raf = requestAnimationFrame(tick);
    return () => cancelAnimationFrame(raf);
  }, [enabled, store]);
  return /* @__PURE__ */ jsx(
    "div",
    {
      ref,
      className: "audioplayer-pulse",
      style: {
        transform: "scale(var(--audioplayer-pulse, 1))",
        transformOrigin: "center",
        willChange: enabled ? "transform" : void 0
      },
      children
    }
  );
}
__name(ReactivePulse, "ReactivePulse");
var REASONS = {
  network: "Network error while loading audio.",
  decode: "We can't decode this audio.",
  unsupported: "This audio format is not supported.",
  unknown: "Audio playback failed."
};
function ErrorState() {
  const state = usePlayerState();
  const { play } = usePlayerControls();
  if (state.kind !== "error") return null;
  const message = REASONS[state.reason] ?? REASONS.unknown;
  return /* @__PURE__ */ jsxs(
    "div",
    {
      role: "alert",
      className: "flex items-center gap-3 rounded-md bg-destructive/10 px-3 py-2 text-xs text-destructive",
      children: [
        /* @__PURE__ */ jsx(AlertTriangle, { size: 14, strokeWidth: 1.75 }),
        /* @__PURE__ */ jsx("span", { className: "flex-1", children: message }),
        /* @__PURE__ */ jsxs(
          "button",
          {
            type: "button",
            onClick: () => void play(),
            className: "audioplayer-press inline-flex items-center gap-1 rounded-md px-2 py-1 text-destructive hover:bg-destructive/15 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/40",
            children: [
              /* @__PURE__ */ jsx(RotateCcw, { size: 12, strokeWidth: 2 }),
              "Retry"
            ]
          }
        )
      ]
    }
  );
}
__name(ErrorState, "ErrorState");
function Title() {
  const { title } = usePlayerMeta();
  if (!title) return null;
  return /* @__PURE__ */ jsx("p", { className: "truncate text-sm font-medium text-foreground", title, children: title });
}
__name(Title, "Title");
function Artist() {
  const { artist, album } = usePlayerMeta();
  if (!artist && !album) return null;
  const text = [artist, album].filter(Boolean).join(" \xB7 ");
  return /* @__PURE__ */ jsx("p", { className: "truncate text-xs text-muted-foreground", title: text, children: text });
}
__name(Artist, "Artist");
function usePeaks(opts) {
  const { src, enabled = true, triggerRef, decodeOnMount = false } = opts;
  const cached2 = getPeaksFromCache(src) ?? null;
  const [peaks, setLocal] = useState(cached2);
  const [loading, setLoading] = useState(!cached2 && enabled);
  const [error, setError] = useState(null);
  useEffect(() => {
    if (!enabled) return;
    const hit = getPeaksFromCache(src);
    if (hit) {
      setLocal(hit);
      setLoading(false);
      return;
    }
    setLocal(null);
    setLoading(true);
    let cancelled = false;
    let started = false;
    const startDecode = /* @__PURE__ */ __name(() => {
      if (started) return;
      started = true;
      getPeaks(src).then((p) => {
        if (cancelled) return;
        setLocal(p);
        setLoading(false);
      }).catch((e) => {
        if (cancelled) return;
        setError(e);
        setLoading(false);
      });
    }, "startDecode");
    if (decodeOnMount || !triggerRef?.current || typeof IntersectionObserver === "undefined") {
      startDecode();
      return () => {
        cancelled = true;
      };
    }
    const obs = new IntersectionObserver(
      (entries) => {
        for (const entry of entries) {
          if (entry.isIntersecting) {
            startDecode();
            obs.disconnect();
            break;
          }
        }
      },
      { rootMargin: "200px" }
    );
    obs.observe(triggerRef.current);
    return () => {
      cancelled = true;
      obs.disconnect();
    };
  }, [src, enabled, decodeOnMount, triggerRef]);
  return { peaks, loading, error };
}
__name(usePeaks, "usePeaks");
var BAR_COUNT = 28;
function BarsWaveform({ height, barWidth, barGap, bars = BAR_COUNT }) {
  const paused = usePlayerPaused();
  const items = useMemo(() => {
    return Array.from({ length: bars }, (_, i) => ({
      delay: `${i % 7 * 90}ms`,
      duration: `${800 + i % 5 * 120}ms`
    }));
  }, [bars]);
  return /* @__PURE__ */ jsx(
    "div",
    {
      className: "audioplayer-bars flex w-full items-center justify-between",
      style: { height, gap: barGap },
      "data-mode": "bars",
      "aria-hidden": "true",
      children: items.map((it, i) => /* @__PURE__ */ jsx(
        "span",
        {
          className: "rounded-sm bg-primary",
          style: {
            width: barWidth,
            height: "40%",
            animation: paused ? void 0 : `audioplayer-bar ${it.duration} ${it.delay} ease-in-out infinite`,
            transformOrigin: "center"
          }
        },
        i
      ))
    }
  );
}
__name(BarsWaveform, "BarsWaveform");

// src/tools/media/AudioPlayer/audio/mediaElementSourceCache.ts
var cache2 = /* @__PURE__ */ new WeakMap();
function getMediaElementSource(el) {
  const hit = cache2.get(el);
  if (hit) return hit;
  const ctx = getAudioContext();
  const node = ctx.createMediaElementSource(el);
  node.connect(ctx.destination);
  cache2.set(el, node);
  return node;
}
__name(getMediaElementSource, "getMediaElementSource");

// src/tools/media/AudioPlayer/hooks/useAnalyser.ts
var FFT_SIZE = 1024;
var READ_INTERVAL_MS2 = 33;
var SMOOTHING = 0.8;
function useAnalyser(audio, store, enabled) {
  useEffect(() => {
    if (!enabled) return;
    let analyser = null;
    let interval = null;
    let buffer = new Uint8Array(0);
    let normalized = new Float32Array(0);
    let cancelled = false;
    try {
      const ctx = getAudioContext();
      const source = getMediaElementSource(audio);
      analyser = ctx.createAnalyser();
      analyser.fftSize = FFT_SIZE;
      analyser.smoothingTimeConstant = SMOOTHING;
      source.connect(analyser);
      buffer = new Uint8Array(analyser.frequencyBinCount);
      normalized = new Float32Array(analyser.frequencyBinCount);
      store.setActive(true);
      const tick = /* @__PURE__ */ __name(() => {
        if (cancelled || !analyser) return;
        if (typeof document !== "undefined" && document.hidden) return;
        analyser.getByteFrequencyData(buffer);
        for (let i = 0; i < buffer.length; i++) normalized[i] = buffer[i] / 255;
        store.set(normalized);
      }, "tick");
      interval = setInterval(tick, READ_INTERVAL_MS2);
    } catch {
      store.setActive(false);
    }
    return () => {
      cancelled = true;
      if (interval) clearInterval(interval);
      if (analyser) {
        try {
          analyser.disconnect();
        } catch {
        }
      }
      store.setActive(false);
    };
  }, [audio, store, enabled]);
}
__name(useAnalyser, "useAnalyser");

// src/tools/media/AudioPlayer/parts/Waveform/waveformInteraction.ts
var HOVER_X = "--hp";
var HOVER_OPACITY = "--ho";
var TOOLTIP_LABEL = "--ht";
function attachSeek(container, audio, options = {}) {
  let dragging = false;
  let movedDuringDrag = false;
  const { startsPlayback = true, onPlayRequest } = options;
  const ratioFor = /* @__PURE__ */ __name((clientX) => {
    const rect = container.getBoundingClientRect();
    if (rect.width === 0) return 0;
    return Math.max(0, Math.min(1, (clientX - rect.left) / rect.width));
  }, "ratioFor");
  const seekTo = /* @__PURE__ */ __name((clientX) => {
    const dur = Number.isFinite(audio.duration) ? audio.duration : 0;
    if (dur > 0) audio.currentTime = ratioFor(clientX) * dur;
  }, "seekTo");
  const onPointerDown = /* @__PURE__ */ __name((e) => {
    if (e.button !== 0 && e.pointerType === "mouse") return;
    dragging = true;
    movedDuringDrag = false;
    container.setPointerCapture?.(e.pointerId);
    seekTo(e.clientX);
  }, "onPointerDown");
  const onPointerMove = /* @__PURE__ */ __name((e) => {
    if (!dragging) return;
    movedDuringDrag = true;
    seekTo(e.clientX);
  }, "onPointerMove");
  const onPointerEnd = /* @__PURE__ */ __name((e) => {
    if (!dragging) return;
    const wasDrag = movedDuringDrag;
    dragging = false;
    movedDuringDrag = false;
    try {
      container.releasePointerCapture?.(e.pointerId);
    } catch {
    }
    if (!wasDrag && startsPlayback && (audio.paused || audio.ended)) {
      onPlayRequest?.();
    }
  }, "onPointerEnd");
  container.addEventListener("pointerdown", onPointerDown);
  container.addEventListener("pointermove", onPointerMove);
  container.addEventListener("pointerup", onPointerEnd);
  container.addEventListener("pointercancel", onPointerEnd);
  return () => {
    container.removeEventListener("pointerdown", onPointerDown);
    container.removeEventListener("pointermove", onPointerMove);
    container.removeEventListener("pointerup", onPointerEnd);
    container.removeEventListener("pointercancel", onPointerEnd);
  };
}
__name(attachSeek, "attachSeek");
function attachHover(container, audio) {
  const tooltip = container.querySelector("[data-audioplayer-time-tip]");
  const onMove = /* @__PURE__ */ __name((e) => {
    const rect = container.getBoundingClientRect();
    if (rect.width === 0) return;
    const x = Math.max(0, Math.min(rect.width, e.clientX - rect.left));
    container.style.setProperty(HOVER_X, `${x}px`);
    container.style.setProperty(HOVER_OPACITY, "1");
    if (tooltip) {
      const dur = Number.isFinite(audio.duration) ? audio.duration : 0;
      const t = x / rect.width * dur;
      tooltip.textContent = formatTime(t);
      tooltip.style.setProperty(TOOLTIP_LABEL, "1");
    }
  }, "onMove");
  const onLeave = /* @__PURE__ */ __name(() => {
    container.style.setProperty(HOVER_OPACITY, "0");
    if (tooltip) tooltip.style.setProperty(TOOLTIP_LABEL, "0");
  }, "onLeave");
  container.addEventListener("pointermove", onMove);
  container.addEventListener("pointerleave", onLeave);
  return () => {
    container.removeEventListener("pointermove", onMove);
    container.removeEventListener("pointerleave", onLeave);
  };
}
__name(attachHover, "attachHover");

// src/tools/media/AudioPlayer/utils/dpr.ts
var MAX_DPR = 2;
var MAX_BACKING_WIDTH = 2048;
function getDpr() {
  if (typeof window === "undefined") return 1;
  const dpr = window.devicePixelRatio ?? 1;
  return Math.min(Math.max(dpr, 1), MAX_DPR);
}
__name(getDpr, "getDpr");
function backingWidth(cssWidth, dpr = getDpr()) {
  return Math.min(Math.round(cssWidth * dpr), MAX_BACKING_WIDTH);
}
__name(backingWidth, "backingWidth");
function backingHeight(cssHeight, dpr = getDpr()) {
  return Math.round(cssHeight * dpr);
}
__name(backingHeight, "backingHeight");

// src/tools/media/AudioPlayer/parts/Waveform/waveformRenderer.ts
function resizeCanvas(canvas) {
  const cssW = canvas.clientWidth;
  const cssH = canvas.clientHeight;
  if (cssW === 0 || cssH === 0) return null;
  const dpr = getDpr();
  const w = backingWidth(cssW, dpr);
  const h = backingHeight(cssH, dpr);
  if (canvas.width !== w) canvas.width = w;
  if (canvas.height !== h) canvas.height = h;
  const ctx = canvas.getContext("2d", { alpha: true, desynchronized: true });
  if (!ctx) return null;
  ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  return { ctx, cssW, cssH };
}
__name(resizeCanvas, "resizeCanvas");
function paintPeaks(canvas, peaks, opts) {
  const sized = resizeCanvas(canvas);
  if (!sized) return;
  const { ctx, cssW, cssH } = sized;
  ctx.clearRect(0, 0, cssW, cssH);
  if (opts.background) {
    ctx.fillStyle = opts.background;
    ctx.fillRect(0, 0, cssW, cssH);
  }
  if (peaks.length === 0) return;
  const step = Math.max(1, opts.barWidth + opts.barGap);
  const numBars = Math.max(1, Math.floor(cssW / step));
  const mid = cssH / 2;
  const minH = opts.minBarHeight ?? 1;
  ctx.fillStyle = opts.color;
  for (let i = 0; i < numBars; i++) {
    const peakIdx = Math.min(peaks.length - 1, Math.floor(i / numBars * peaks.length));
    const amp = peaks[peakIdx];
    const h = Math.max(minH, amp * cssH);
    const x = i * step;
    ctx.fillRect(x, mid - h / 2, opts.barWidth, h);
  }
}
__name(paintPeaks, "paintPeaks");
function paintLive(canvas, levels, opts) {
  const sized = resizeCanvas(canvas);
  if (!sized) return;
  const { ctx, cssW, cssH } = sized;
  ctx.clearRect(0, 0, cssW, cssH);
  if (levels.length === 0) return;
  const step = Math.max(1, opts.barWidth + opts.barGap);
  const numBars = Math.max(1, Math.floor(cssW / step));
  const mid = cssH / 2;
  const minH = opts.minBarHeight ?? 1;
  const usable = Math.floor(levels.length * 0.7);
  ctx.fillStyle = opts.color;
  for (let i = 0; i < numBars; i++) {
    const idx = Math.min(usable - 1, Math.floor(i / numBars * usable));
    const v = levels[idx] ?? 0;
    const h = Math.max(minH, v * cssH);
    ctx.fillRect(i * step, mid - h / 2, opts.barWidth, h);
  }
}
__name(paintLive, "paintLive");
function LiveWaveform({ height, barWidth, barGap, seekStartsPlayback }) {
  const audio = usePlayerAudio();
  const controls = usePlayerControls();
  const store = usePlayerLevels();
  const [container, setContainer] = useState(null);
  const canvasRef = useRef(null);
  const fgHex = useThemeColor("primary");
  const mutedHex = useThemeColor("muted-foreground");
  const colorRef = useRef(fgHex);
  colorRef.current = fgHex;
  useElementWidth(container);
  useAnalyser(audio, store, true);
  useEffect(() => {
    const canvas = canvasRef.current;
    if (!canvas) return;
    let raf = 0;
    const tick = /* @__PURE__ */ __name(() => {
      if (typeof document !== "undefined" && document.hidden) {
        raf = requestAnimationFrame(tick);
        return;
      }
      paintLive(canvas, store.getCurrent(), {
        color: colorRef.current,
        barWidth,
        barGap,
        minBarHeight: 1
      });
      raf = requestAnimationFrame(tick);
    }, "tick");
    raf = requestAnimationFrame(tick);
    return () => cancelAnimationFrame(raf);
  }, [store, barWidth, barGap]);
  useEffect(() => {
    if (!container) return;
    const detachSeek = attachSeek(container, audio, {
      startsPlayback: seekStartsPlayback,
      onPlayRequest: /* @__PURE__ */ __name(() => void controls.play(), "onPlayRequest")
    });
    const detachHover = attachHover(container, audio);
    return () => {
      detachSeek();
      detachHover();
    };
  }, [audio, container, controls, seekStartsPlayback]);
  return /* @__PURE__ */ jsxs(
    "div",
    {
      ref: setContainer,
      className: "audioplayer-waveform relative w-full select-none cursor-pointer",
      style: { height },
      "data-mode": "live",
      children: [
        /* @__PURE__ */ jsx("canvas", { ref: canvasRef, className: "absolute inset-0 h-full w-full", "aria-hidden": "true" }),
        /* @__PURE__ */ jsx(
          "div",
          {
            className: "audioplayer-hover pointer-events-none absolute top-0 bottom-0 w-px transition-opacity",
            style: {
              left: "var(--hp, -10px)",
              opacity: "var(--ho, 0)",
              backgroundColor: alpha(mutedHex, 0.5)
            },
            "aria-hidden": "true"
          }
        ),
        /* @__PURE__ */ jsx(
          "div",
          {
            "data-audioplayer-time-tip": true,
            className: "audioplayer-tip pointer-events-none absolute -top-7 -translate-x-1/2 rounded bg-foreground px-1.5 py-0.5 text-[10px] tabular-nums text-background transition-opacity",
            style: {
              left: "var(--hp, -100px)",
              opacity: "var(--ht, 0)"
            },
            "aria-hidden": "true"
          }
        )
      ]
    }
  );
}
__name(LiveWaveform, "LiveWaveform");
var VAR2 = "--p";
function usePlayheadLoop(audio, el, enabled = true) {
  useEffect(() => {
    if (!enabled || !el) return;
    let raf = 0;
    let lastPct = -1;
    const writePct = /* @__PURE__ */ __name(() => {
      const dur = audio.duration;
      if (!Number.isFinite(dur) || dur <= 0) return;
      const pct = Math.max(0, Math.min(100, audio.currentTime / dur * 100));
      if (Math.abs(pct - lastPct) < 0.01) return;
      lastPct = pct;
      el.style.setProperty(VAR2, `${pct.toFixed(2)}%`);
    }, "writePct");
    const tick = /* @__PURE__ */ __name(() => {
      if (typeof document !== "undefined" && document.hidden) {
        raf = 0;
        return;
      }
      writePct();
      raf = requestAnimationFrame(tick);
    }, "tick");
    const start = /* @__PURE__ */ __name(() => {
      if (raf) return;
      raf = requestAnimationFrame(tick);
    }, "start");
    const stop = /* @__PURE__ */ __name(() => {
      if (!raf) return;
      cancelAnimationFrame(raf);
      raf = 0;
      writePct();
    }, "stop");
    if (!audio.paused) start();
    const onPlay = /* @__PURE__ */ __name(() => start(), "onPlay");
    const onPauseOrEnd = /* @__PURE__ */ __name(() => stop(), "onPauseOrEnd");
    const onSeek = /* @__PURE__ */ __name(() => writePct(), "onSeek");
    const onVisibility = /* @__PURE__ */ __name(() => {
      if (document.hidden) stop();
      else if (!audio.paused) start();
    }, "onVisibility");
    audio.addEventListener("play", onPlay);
    audio.addEventListener("pause", onPauseOrEnd);
    audio.addEventListener("ended", onPauseOrEnd);
    audio.addEventListener("seeked", onSeek);
    audio.addEventListener("timeupdate", writePct);
    document.addEventListener("visibilitychange", onVisibility);
    return () => {
      stop();
      audio.removeEventListener("play", onPlay);
      audio.removeEventListener("pause", onPauseOrEnd);
      audio.removeEventListener("ended", onPauseOrEnd);
      audio.removeEventListener("seeked", onSeek);
      audio.removeEventListener("timeupdate", writePct);
      document.removeEventListener("visibilitychange", onVisibility);
    };
  }, [audio, el, enabled]);
}
__name(usePlayheadLoop, "usePlayheadLoop");
function useThemeWatcher(cb) {
  useEffect(() => {
    const root = document.documentElement;
    const obs = new MutationObserver(cb);
    obs.observe(root, { attributes: true, attributeFilter: ["class", "data-theme"] });
    const mq = window.matchMedia?.("(prefers-color-scheme: dark)");
    const onMq = /* @__PURE__ */ __name(() => cb(), "onMq");
    mq?.addEventListener?.("change", onMq);
    return () => {
      obs.disconnect();
      mq?.removeEventListener?.("change", onMq);
    };
  }, [cb]);
}
__name(useThemeWatcher, "useThemeWatcher");
function PeaksWaveform({ peaks, height, barWidth, barGap, seekStartsPlayback }) {
  const audio = usePlayerAudio();
  const controls = usePlayerControls();
  const [container, setContainer] = useState(null);
  const bgCanvasRef = useRef(null);
  const fgCanvasRef = useRef(null);
  const width = useElementWidth(container);
  const fgHex = useThemeColor("primary");
  const mutedHex = useThemeColor("muted-foreground");
  const repaint = useCallback(() => {
    const bg = bgCanvasRef.current;
    const fg = fgCanvasRef.current;
    if (!bg || !fg) return;
    paintPeaks(bg, peaks, { color: alpha(mutedHex, 0.4), barWidth, barGap, minBarHeight: 1 });
    paintPeaks(fg, peaks, { color: fgHex, barWidth, barGap, minBarHeight: 1 });
  }, [peaks, barWidth, barGap, fgHex, mutedHex]);
  useEffect(repaint, [repaint, width]);
  useThemeWatcher(repaint);
  usePlayheadLoop(audio, container, true);
  useEffect(() => {
    if (!container) return;
    const detachSeek = attachSeek(container, audio, {
      startsPlayback: seekStartsPlayback,
      onPlayRequest: /* @__PURE__ */ __name(() => void controls.play(), "onPlayRequest")
    });
    const detachHover = attachHover(container, audio);
    return () => {
      detachSeek();
      detachHover();
    };
  }, [audio, container, controls, seekStartsPlayback]);
  return /* @__PURE__ */ jsxs(
    "div",
    {
      ref: setContainer,
      className: "audioplayer-waveform relative w-full select-none cursor-pointer",
      style: { height, ["--p"]: "0%" },
      "data-mode": "peaks",
      children: [
        /* @__PURE__ */ jsx("canvas", { ref: bgCanvasRef, className: "absolute inset-0 h-full w-full", "aria-hidden": "true" }),
        /* @__PURE__ */ jsx(
          "div",
          {
            className: "audioplayer-fg-clip absolute inset-0",
            style: {
              clipPath: "polygon(0 0, var(--p) 0, var(--p) 100%, 0 100%)",
              willChange: "clip-path"
            },
            children: /* @__PURE__ */ jsx("canvas", { ref: fgCanvasRef, className: "absolute inset-0 h-full w-full", "aria-hidden": "true" })
          }
        ),
        /* @__PURE__ */ jsx(
          "div",
          {
            className: "audioplayer-cursor pointer-events-none absolute top-0 bottom-0 w-px",
            style: { left: "var(--p)", backgroundColor: alpha(fgHex, 0.7) },
            "aria-hidden": "true"
          }
        ),
        /* @__PURE__ */ jsx(
          "div",
          {
            className: "audioplayer-hover pointer-events-none absolute top-0 bottom-0 w-px transition-opacity",
            style: {
              left: "var(--hp, -10px)",
              opacity: "var(--ho, 0)",
              backgroundColor: alpha(mutedHex, 0.5)
            },
            "aria-hidden": "true"
          }
        ),
        /* @__PURE__ */ jsx(
          "div",
          {
            "data-audioplayer-time-tip": true,
            className: "audioplayer-tip pointer-events-none absolute -top-7 -translate-x-1/2 rounded bg-foreground px-1.5 py-0.5 text-[10px] tabular-nums text-background transition-opacity",
            style: {
              left: "var(--hp, -100px)",
              opacity: "var(--ht, 0)"
            },
            "aria-hidden": "true"
          }
        )
      ]
    }
  );
}
__name(PeaksWaveform, "PeaksWaveform");
function ProgressBar({ height = 4, seekStartsPlayback }) {
  const audio = usePlayerAudio();
  const controls = usePlayerControls();
  const [container, setContainer] = useState(null);
  const fgHex = useThemeColor("primary");
  const mutedHex = useThemeColor("muted-foreground");
  usePlayheadLoop(audio, container, true);
  useEffect(() => {
    if (!container) return;
    const detachSeek = attachSeek(container, audio, {
      startsPlayback: seekStartsPlayback,
      onPlayRequest: /* @__PURE__ */ __name(() => void controls.play(), "onPlayRequest")
    });
    const detachHover = attachHover(container, audio);
    return () => {
      detachSeek();
      detachHover();
    };
  }, [audio, container, controls, seekStartsPlayback]);
  return /* @__PURE__ */ jsxs(
    "div",
    {
      ref: setContainer,
      className: "audioplayer-waveform relative w-full select-none cursor-pointer",
      style: { ["--p"]: "0%" },
      "data-mode": "progress",
      children: [
        /* @__PURE__ */ jsx(
          "div",
          {
            className: "rounded-full",
            style: { height, backgroundColor: alpha(mutedHex, 0.25) }
          }
        ),
        /* @__PURE__ */ jsx(
          "div",
          {
            className: "absolute inset-y-0 left-0 rounded-full",
            style: {
              width: "var(--p)",
              backgroundColor: fgHex
            },
            "aria-hidden": "true"
          }
        ),
        /* @__PURE__ */ jsx(
          "div",
          {
            className: "audioplayer-hover pointer-events-none absolute -top-1 -bottom-1 w-px transition-opacity",
            style: {
              left: "var(--hp, -10px)",
              opacity: "var(--ho, 0)",
              backgroundColor: alpha(mutedHex, 0.5)
            },
            "aria-hidden": "true"
          }
        ),
        /* @__PURE__ */ jsx(
          "div",
          {
            "data-audioplayer-time-tip": true,
            className: "audioplayer-tip pointer-events-none absolute -top-7 -translate-x-1/2 rounded bg-foreground px-1.5 py-0.5 text-[10px] tabular-nums text-background transition-opacity",
            style: {
              left: "var(--hp, -100px)",
              opacity: "var(--ht, 0)"
            },
            "aria-hidden": "true"
          }
        )
      ]
    }
  );
}
__name(ProgressBar, "ProgressBar");
function WaveformSkeleton({ height }) {
  return /* @__PURE__ */ jsxs(
    "div",
    {
      className: "audioplayer-skeleton relative w-full overflow-hidden",
      style: { height },
      "aria-hidden": "true",
      children: [
        /* @__PURE__ */ jsx("div", { className: "absolute inset-x-0 top-1/2 h-px -translate-y-1/2 bg-muted-foreground/30" }),
        /* @__PURE__ */ jsx("div", { className: "absolute inset-0 audioplayer-shimmer" })
      ]
    }
  );
}
__name(WaveformSkeleton, "WaveformSkeleton");
function Waveform({ config, height, seekStartsPlayback }) {
  const meta = usePlayerMeta();
  const triggerRef = useRef(null);
  const mode = config?.mode ?? "peaks";
  const barWidth = config?.barWidth ?? 2;
  const barGap = config?.barGap ?? 1;
  const peaksEnabled = mode === "peaks";
  const { peaks, loading, error } = usePeaks({
    src: meta.src,
    enabled: peaksEnabled,
    triggerRef,
    decodeOnMount: config?.decodeOnMount
  });
  if (mode === "none") return null;
  if (mode === "progress")
    return /* @__PURE__ */ jsx(ProgressBar, { height: Math.min(height, 6), seekStartsPlayback });
  if (mode === "bars") return /* @__PURE__ */ jsx(BarsWaveform, { height, barWidth, barGap });
  if (mode === "live")
    return /* @__PURE__ */ jsx(
      LiveWaveform,
      {
        height,
        barWidth,
        barGap,
        seekStartsPlayback
      }
    );
  if (loading || !peaks && !error) {
    return /* @__PURE__ */ jsx("div", { ref: triggerRef, children: /* @__PURE__ */ jsx(WaveformSkeleton, { height }) });
  }
  if (!peaks) {
    return /* @__PURE__ */ jsx(ProgressBar, { height: Math.min(height, 6), seekStartsPlayback });
  }
  return /* @__PURE__ */ jsx("div", { ref: triggerRef, children: /* @__PURE__ */ jsx(
    PeaksWaveform,
    {
      peaks,
      height,
      barWidth,
      barGap,
      seekStartsPlayback
    }
  ) });
}
__name(Waveform, "Waveform");
function DefaultLayout({ waveform, reactiveCover, onPrev, onNext, seekStartsPlayback }) {
  const meta = usePlayerMeta();
  const cover = /* @__PURE__ */ jsx(Cover, { src: meta.cover, alt: meta.title ? `${meta.title} cover` : "", size: 56 });
  return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3.5 p-4", children: [
    /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
      reactiveCover === "subtle" ? /* @__PURE__ */ jsx(ReactivePulse, { enabled: true, children: cover }) : cover,
      /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
        /* @__PURE__ */ jsx(Title, {}),
        /* @__PURE__ */ jsx(Artist, {})
      ] })
    ] }),
    /* @__PURE__ */ jsx(
      Waveform,
      {
        config: waveform,
        height: waveform?.height ?? 40,
        seekStartsPlayback
      }
    ),
    /* @__PURE__ */ jsx(ErrorState, {}),
    /* @__PURE__ */ jsx(ControlsRow, { onPrev, onNext, showTime: true })
  ] });
}
__name(DefaultLayout, "DefaultLayout");
function CompactLayout({ waveform, seekStartsPlayback }) {
  return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 p-2", children: [
    /* @__PURE__ */ jsx(PlayButton, { size: "compact" }),
    /* @__PURE__ */ jsx("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ jsx(
      Waveform,
      {
        config: waveform,
        height: waveform?.height ?? 24,
        seekStartsPlayback
      }
    ) }),
    /* @__PURE__ */ jsx(TimeDisplay, {}),
    /* @__PURE__ */ jsx(VolumeControl, {})
  ] });
}
__name(CompactLayout, "CompactLayout");
var COMPACT_BREAKPOINT = 480;
function PlayerShell({
  className = "",
  variant = "auto",
  waveform,
  reactiveCover = false,
  onPrev,
  onNext,
  enableKeyboardShortcuts = true,
  ariaLabel,
  seekStartsPlayback = true,
  autoFocus = false,
  handleRef
}) {
  const [container, setContainer] = useState(null);
  const audio = usePlayerAudio();
  const controls = usePlayerControls();
  const meta = usePlayerMeta();
  const width = useElementWidth(container);
  const isPhone = useIsPhone();
  const resolvedVariant = variant === "auto" ? isPhone || width > 0 && width < COMPACT_BREAKPOINT ? "compact" : "default" : variant;
  useMediaSession(audio, meta, controls, onPrev, onNext);
  const hotkeys = useKeyboardShortcuts({
    audio,
    controls,
    enabled: enableKeyboardShortcuts
  });
  const setRootRef = useCallback(
    (node) => {
      setContainer(node);
      hotkeys.ref(node);
    },
    [hotkeys]
  );
  useImperativeHandle(
    handleRef,
    () => ({
      audio,
      play: /* @__PURE__ */ __name(() => controls.play(), "play"),
      pause: /* @__PURE__ */ __name(() => controls.pause(), "pause"),
      seek: /* @__PURE__ */ __name((s) => controls.seek(s), "seek"),
      getCurrentTime: /* @__PURE__ */ __name(() => audio.currentTime, "getCurrentTime"),
      getDuration: /* @__PURE__ */ __name(() => Number.isFinite(audio.duration) ? audio.duration : 0, "getDuration"),
      focus: /* @__PURE__ */ __name(() => container?.focus(), "focus")
    }),
    [audio, controls, container]
  );
  useEffect(() => {
    if (!container || container.hasAttribute("tabindex")) return;
    container.setAttribute("tabindex", "0");
  }, [container]);
  useEffect(() => {
    if (!autoFocus || !container) return;
    container.focus({ preventScroll: true });
  }, [autoFocus, container]);
  return /* @__PURE__ */ jsx(
    "div",
    {
      ref: setRootRef,
      role: "group",
      "aria-label": ariaLabel ?? "Audio player",
      className: `audioplayer @container/player rounded-lg border border-border/60 bg-card text-foreground shadow-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 ${className}`,
      children: resolvedVariant === "compact" ? /* @__PURE__ */ jsx(CompactLayout, { waveform, seekStartsPlayback }) : /* @__PURE__ */ jsx(
        DefaultLayout,
        {
          waveform,
          reactiveCover,
          onPrev,
          onNext,
          seekStartsPlayback
        }
      )
    }
  );
}
__name(PlayerShell, "PlayerShell");
var Player = forwardRef(/* @__PURE__ */ __name(function Player2(props, ref) {
  const {
    src,
    peaks,
    title,
    artist,
    album,
    cover,
    autoplay,
    loop,
    initialVolume,
    muted,
    preload,
    exclusive,
    onPrev,
    onNext,
    onPlay,
    onPause,
    onEnded,
    onError,
    onTimeUpdate,
    variant,
    waveform,
    reactiveCover,
    className,
    ariaLabel,
    enableKeyboardShortcuts,
    seekStartsPlayback,
    autoFocus
  } = props;
  return /* @__PURE__ */ jsx(
    PlayerProvider,
    {
      src,
      peaks,
      title,
      artist,
      album,
      cover,
      autoplay,
      loop,
      initialVolume,
      muted,
      preload,
      exclusive,
      onPrev,
      onNext,
      onPlay,
      onPause,
      onEnded,
      onError,
      children: /* @__PURE__ */ jsx(
        PlayerShell,
        {
          className,
          variant,
          waveform,
          reactiveCover,
          onPrev,
          onNext,
          enableKeyboardShortcuts,
          ariaLabel,
          seekStartsPlayback,
          autoFocus,
          handleRef: ref
        }
      )
    }
  );
}, "Player"));
Player.displayName = "AudioPlayer";
var getServerSnapshot = /* @__PURE__ */ __name(() => null, "getServerSnapshot");
function useActivePlayer() {
  return useSyncExternalStore(subscribeActivePlayer, getActivePlayer, getServerSnapshot);
}
__name(useActivePlayer, "useActivePlayer");
function useLastActivePlayer() {
  return useSyncExternalStore(subscribeActivePlayer, getLastActivePlayer, getServerSnapshot);
}
__name(useLastActivePlayer, "useLastActivePlayer");
function useIsActivePlayer(id) {
  const active = useActivePlayer();
  return Boolean(id) && active === id;
}
__name(useIsActivePlayer, "useIsActivePlayer");
var SSR = { volume: 1, muted: false };
function getServerSnapshot2() {
  return SSR;
}
__name(getServerSnapshot2, "getServerSnapshot");
function usePlayerPreferences() {
  return useSyncExternalStore(subscribePreferences, getPreferences, getServerSnapshot2);
}
__name(usePlayerPreferences, "usePlayerPreferences");

export { Player as LazyPlayer, Player, PlayerProvider, getActivePlayer, getLastActivePlayer, getPreferences, setActivePlayer, setStoredMuted, setStoredVolume, subscribeActivePlayer, subscribePreferences, useActivePlayer, useIsActivePlayer, useLastActivePlayer, usePlayerAudio, usePlayerControls, usePlayerDuration, usePlayerLevels, usePlayerMeta, usePlayerPaused, usePlayerPreferences, usePlayerState };
//# sourceMappingURL=index.mjs.map
//# sourceMappingURL=index.mjs.map