export function isBase64(base64) {
    if (typeof base64 !== 'string')
        return false;
    let base64Data = base64;
    let isPng = false;
    let isJpeg = false;
    if (base64.startsWith('data:image/png;base64,')) {
        base64Data = base64.substring(22);
        isPng = true;
    }
    else if (base64.startsWith('data:image/jpeg;base64,')) {
        base64Data = base64.substring(23);
        isJpeg = true;
    }
    const base64Regex = /^[A-Za-z0-9+/]*={0,2}$/;
    if (!base64Regex.test(base64Data) || base64Data.length % 4 !== 0) {
        return false;
    }
    let binary;
    try {
        binary = atob(base64Data);
    }
    catch (e) {
        return false;
    }
    if (isPng || (!isJpeg && base64Data.startsWith('iVBORw0KGgo'))) {
        const pngHeader = binary.substring(0, 8);
        if (pngHeader === '\x89PNG\r\n\x1a\n')
            return true;
    }
    else if (isJpeg || base64Data.startsWith('/9j/')) {
        const jpegHeader = binary.substring(0, 3);
        if (jpegHeader === '\xFF\xD8\xFF')
            return true;
    }
    return false;
}
export function isBase64Doc(base64) {
    if (typeof base64 !== 'string')
        return false;
    let base64Data = base64;
    let isPdf = false;
    if (base64.startsWith('data:application/pdf;base64,')) {
        base64Data = base64.substring(28);
        isPdf = true;
    }
    const base64Regex = /^[A-Za-z0-9+/]*={0,2}$/;
    if (!base64Regex.test(base64Data) || base64Data.length % 4 !== 0) {
        return false;
    }
    try {
        atob(base64Data);
    }
    catch (e) {
        return false;
    }
    if (isPdf)
        return true;
    return false;
}
//# sourceMappingURL=Images.js.map