export function getRenderedPictureVariant(params, variants) {
    const variantName = params.variant ?? "auto";
    const variant = variantName.toLocaleLowerCase() === "auto" && params.aspectRatio
        ? getBestMatchingVariant(variants, params.aspectRatio)
        : variants.find((v) => v.name.toLowerCase() == variantName.toLowerCase()) ?? variants[0];
    return variant;
}
export function getBestMatchingVariant(variants, aspectRatio) {
    if (!aspectRatio)
        return (variants.find((v) => v.name.toLowerCase() == "default") ?? variants[0]);
    let minDistance = 1000000;
    let bestMatch = undefined;
    for (let i = 0; i < variants.length; i++) {
        const variant = variants[i];
        if (!variant.src)
            continue;
        const distance = Math.abs(aspectRatio - variant.aspectRatio);
        if (distance < minDistance) {
            minDistance = distance;
            bestMatch = variant;
        }
    }
    return bestMatch ?? variants[0];
}
//# sourceMappingURL=picture-shared.js.map