import { BehaviorSubject } from 'rxjs'; import { ImageRatio } from './file-upload.module'; import { TsFileImageDimensionConstraints } from './image-dimension-constraints'; import { TsImageDimensions } from './image-dimensions'; import { TsFileAcceptedMimeTypes } from './mime-types'; /** * The structure of the object to track file validations internally */ export interface TsFileValidations { fileType: boolean; fileSize: boolean; imageDimensions: boolean; imageRatio: boolean; } /** * Manage a single selected file * * @param file - The selected file * @param imageDimensionConstraints - An array of image dimension constraints {@link TsFileImageDimensionConstraints} * @param typeConstraint - An array of allowed MIME types {@link TsFileAcceptedMimeTypes} * @param maxSize - The maximum size in kilobytes * @param ratioConstraint - An array of allowed image ratios in form of ImageRatio */ export declare class TsSelectedFile { file: File; private imageDimensionConstraints; private typeConstraint; private maxSize; private ratioConstraint; name: string | undefined; mimeType: string; dimensions: TsImageDimensions | undefined; ratio: number | undefined; size: number; validations: TsFileValidations; private fileReader; /** * Only needed to appease TypeScript when defining `fileLoaded$` */ private fileReference?; /** * BehaviorSubject to alert consumers when all calculations are complete */ fileLoaded$: BehaviorSubject; constructor(file: File, imageDimensionConstraints: TsFileImageDimensionConstraints | undefined, typeConstraint: TsFileAcceptedMimeTypes[] | undefined, maxSize: number, ratioConstraint: Array | undefined); /** * Get the image width * * @returns The width of the image if it exists */ get width(): number; /** * Get the image height * * @returns The height of the image if it exists */ get height(): number; /** * Get a boolean representing if the file is a CSV * * @returns Is a CSV */ get isCSV(): boolean; /** * Get a boolean representing if the file is an image * * @returns Is an image */ get isImage(): boolean; /** * Get a boolean representing if the file is a video * * @returns Is a video */ get isVideo(): boolean; /** * Get the file contents * * @returns The FileReader results */ get fileContents(): string; /** * Get the validation status * * @returns Is valid */ get isValid(): boolean; /** * Determine the dimensions and ratio of an image * * @param callback - A function to call after the dimensions have been calculated (asynchronously) */ private determineImageDimensions; /** * Validate the image dimensions * * @param constraints - The constraints this the image dimensions must fit * @returns The validation result */ private validateImageDimensions; /** * Validate the image ratios * * @param constraints - The constrains that the image ratio must fit * @returns The validation result */ private validateImageRatio; /** * A utility function to determine whether two numbers are the same * * @param number1 - one number * @param number2 - another number * @returns Whether these two numbers are the same */ private isSame; }