function normalizeSplatLabel(label: string) { return String(label || "").trim().toLowerCase(); } function parseResolutionScore(label: string) { const normalized = normalizeSplatLabel(label); if (!normalized) return 0; if ( normalized.includes("full") || normalized.includes("origin") || normalized.includes("source") || normalized.includes("max") ) { return Number.MAX_SAFE_INTEGER; } const match = normalized.match(/(\d+(?:\.\d+)?)\s*([km]?)/); if (!match) return 0; const value = Number(match[1]); if (!Number.isFinite(value)) return 0; const unit = match[2]; if (unit === "m") return Math.round(value * 1_000_000); if (unit === "k") return Math.round(value * 1_000); return Math.round(value); } function compareSplatEntries( a: [string, string], b: [string, string] ) { const scoreDelta = parseResolutionScore(b[0]) - parseResolutionScore(a[0]); if (scoreDelta !== 0) return scoreDelta; return a[0].localeCompare(b[0], "en"); } export function getSortedWorldLabsSplatEntries( spzUrls?: Record | null ) { return Object.entries(spzUrls || {}) .filter( (entry): entry is [string, string] => Boolean(entry[0]) && typeof entry[1] === "string" && entry[1].trim().length > 0 ) .sort(compareSplatEntries); } export function pickBestWorldLabsSplatEntry( spzUrls?: Record | null ) { return getSortedWorldLabsSplatEntries(spzUrls)[0] || null; } export function pickBestWorldLabsSplatUrl( spzUrls?: Record | null ) { return pickBestWorldLabsSplatEntry(spzUrls)?.[1] || null; }