const DIRECT_VIDEO_EXTENSIONS = [
    "mp4",
    "mov",
    "m4v",
    "mkv",
    "webm",
    "mpeg",
    "mpg",
    "avi",
    "wmv",
    "flv",
    "m3u8",
];
const DIRECT_AUDIO_EXTENSIONS = [
    "mp3",
    "m4a",
    "wav",
    "flac",
    "aac",
    "ogg",
    "opus",
    "aiff",
    "wma",
];
export const DIRECT_MEDIA_EXTENSIONS = [
    ...DIRECT_VIDEO_EXTENSIONS,
    ...DIRECT_AUDIO_EXTENSIONS,
];
const DIRECT_VIDEO_EXTENSION_SET = new Set(DIRECT_VIDEO_EXTENSIONS);
const DIRECT_AUDIO_EXTENSION_SET = new Set(DIRECT_AUDIO_EXTENSIONS);
const DIRECT_MEDIA_EXTENSION_SET = new Set(DIRECT_MEDIA_EXTENSIONS);
const DIRECT_MEDIA_TYPE_BY_EXTENSION = new Map([
    ["mp4", "video/mp4"],
    ["mov", "video/quicktime"],
    ["m4v", "video/mp4"],
    ["mkv", "video/x-matroska"],
    ["mpeg", "video/mpeg"],
    ["mpg", "video/mpeg"],
    ["avi", "video/x-msvideo"],
    ["wmv", "video/x-ms-wmv"],
    ["flv", "video/x-flv"],
    ["m3u8", "application/vnd.apple.mpegurl"],
    ["mp3", "audio/mpeg"],
    ["m4a", "audio/mp4"],
    ["wav", "audio/wav"],
    ["flac", "audio/flac"],
    ["aac", "audio/aac"],
    ["ogg", "audio/ogg"],
    ["opus", "audio/ogg"],
    ["aiff", "audio/aiff"],
    ["wma", "audio/x-ms-wma"],
]);
export function normalizePathForExtension(value) {
    try {
        return new URL(value).pathname;
    }
    catch {
        return value.split(/[?#]/, 1)[0] ?? value;
    }
}
export function resolveDirectMediaExtension(value) {
    const match = normalizePathForExtension(value)
        .toLowerCase()
        .match(/\.([a-z0-9]+)$/i);
    return match?.[1] ?? null;
}
export function isDirectMediaUrl(url) {
    const ext = resolveDirectMediaExtension(url);
    return ext ? DIRECT_MEDIA_EXTENSION_SET.has(ext) : false;
}
export function isDirectMediaExtension(ext) {
    const normalized = ext.trim().replace(/^\./, "").toLowerCase();
    return DIRECT_MEDIA_EXTENSION_SET.has(normalized);
}
export function inferDirectMediaKind(value) {
    const ext = resolveDirectMediaExtension(value);
    if (!ext)
        return null;
    if (DIRECT_VIDEO_EXTENSION_SET.has(ext))
        return "video";
    if (DIRECT_AUDIO_EXTENSION_SET.has(ext))
        return "audio";
    return null;
}
export function isDirectVideoInput(value) {
    return inferDirectMediaKind(value) === "video";
}
export function resolveDirectMediaType(value, kindHint = null) {
    const ext = resolveDirectMediaExtension(value);
    if (ext === "webm") {
        return kindHint === "audio" ? "audio/webm" : "video/webm";
    }
    const detected = ext ? (DIRECT_MEDIA_TYPE_BY_EXTENSION.get(ext) ?? null) : null;
    if (detected)
        return detected;
    if (!kindHint)
        return null;
    return kindHint === "video" ? "video/mp4" : "audio/mpeg";
}
//# sourceMappingURL=direct-media.js.map