import { IS_IPHONE } from '../constants/env' ; import { RoutePath } from '../routes' ; export function isVerticalScrollable ( ) { return document . body . scrollHeight > document . body . clientHeight ; } export const disableImageContext = ( e ) : boolean => { e ?. preventDefault ?. ( ) ; e ?. stopPropagation ?. ( ) ; return false ; } ; export const disableImagePreviewContext = ( visible ) => { const backdrop = document . querySelector ( '.PhotoView-PhotoSlider__Backdrop' ) ; backdrop ?. addEventListener ( 'animationend' , ( ) => { const img = document . querySelector ( '.PhotoView__Photo' ) ; if ( img && visible ) { img . addEventListener ( 'contextmenu' , disableImageContext ) ; } } ) ; } ; export async function downloadImage ( imageSrc , filename = 'qrcode.jpg' ) { const headers = new Headers ( ) ; headers . append ( 'Access-Control-Allow-Origin' , location . href ) ; headers . append ( 'Access-Control-Allow-Credentials' , 'true' ) ; const image = await fetch ( imageSrc , { headers , } ) ; const imageBlog = await image . blob ( ) ; const imageURL = URL . createObjectURL ( imageBlog ) ; const link = document . createElement ( 'a' ) ; link . href = imageURL ; link . download = filename ; document . body . appendChild ( link ) ; link . click ( ) ; document . body . removeChild ( link ) ; } export const downloadCardBackPDF = ( selector ) => { if ( IS_IPHONE ) { return ; } const container = document . querySelector ( selector ) ; const nodeList = container ?. querySelectorAll ( 'a' ) ; nodeList ?. forEach ?. ( ( el ) => { el . addEventListener ( 'click' , async ( e ) => { const target = e . currentTarget as any ; e . stopPropagation ( ) ; if ( target . href ?. endsWith ( '.pdf' ) && ! target . download ) { e . preventDefault ( ) ; window . open ( `${ RoutePath . PDFViewer }?url=${ encodeURIComponent ( target . href ) }` ) ; } } ) ; } ) ; } ; export function isInStandaloneMode ( ) { return ( window . matchMedia ( '(display-mode: standalone)' ) . matches || ( window . navigator as any ) . standalone || document . referrer . includes ( 'android-app://' ) ) ; }