import { __decorate, __param, __awaiter, __generator, __extends, __spread } from 'tslib';
import { Optional, Inject, PLATFORM_ID, ɵɵdefineInjectable, ɵɵinject, Injectable } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { mapTo, map, distinctUntilChanged, shareReplay, debounceTime, startWith } from 'rxjs/operators';
import { of, fromEvent, Observable, merge } from 'rxjs';

var hasV8BreakIterator = (typeof Intl !== 'undefined' && Intl.v8BreakIterator);
var Platform = /** @class */ (function () {
    function Platform(_platformId) {
        this._platformId = _platformId;
    }
    Object.defineProperty(Platform.prototype, "isBrowser", {
        // Browser check.
        get: function () {
            return this._platformId
                ? isPlatformBrowser(this._platformId)
                : typeof document === 'object' && !!document;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Platform.prototype, "isTrident", {
        // Rendering engines.
        get: function () {
            return this.isBrowser && /(msie|trident)/i.test(navigator.userAgent);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Platform.prototype, "isBlink", {
        get: function () {
            return this.isBrowser && (!!(window.chrome || hasV8BreakIterator) &&
                typeof CSS !== 'undefined' && !this.isEdge && !this.isTrident);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Platform.prototype, "isWebkit", {
        get: function () {
            return this.isBrowser && /AppleWebKit/i.test(navigator.userAgent)
                && !this.isBlink && !this.isEdge && !this.isTrident;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Platform.prototype, "isChrome", {
        // Browsers.
        get: function () {
            return this.isBrowser && /Google Inc./.test(navigator.vendor);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Platform.prototype, "isEdge", {
        get: function () {
            return this.isBrowser && /(edge)/i.test(navigator.userAgent);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Platform.prototype, "isFirefox", {
        get: function () {
            return this.isBrowser && /(firefox|minefield)/i.test(navigator.userAgent);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Platform.prototype, "isSafari", {
        get: function () {
            return this.isBrowser && /safari/i.test(navigator.userAgent) && this.isWebkit;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Platform.prototype, "isIos", {
        // Platforms.
        get: function () {
            return this.isBrowser && /iPad|iPhone|iPod/.test(navigator.userAgent) && !('MSStream' in window);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Platform.prototype, "isAndroid", {
        get: function () {
            return this.isBrowser && /android/i.test(navigator.userAgent) && !this.isTrident;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Platform.prototype, "isDesktop", {
        get: function () {
            return this.isBrowser && !(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/.test(navigator.userAgent));
        },
        enumerable: true,
        configurable: true
    });
    Platform.ctorParameters = function () { return [
        { type: Object, decorators: [{ type: Optional }, { type: Inject, args: [PLATFORM_ID,] }] }
    ]; };
    Platform.ɵprov = ɵɵdefineInjectable({ factory: function Platform_Factory() { return new Platform(ɵɵinject(PLATFORM_ID, 8)); }, token: Platform, providedIn: "root" });
    Platform = __decorate([
        Injectable({
            providedIn: 'root'
        }),
        __param(0, Optional()), __param(0, Inject(PLATFORM_ID))
    ], Platform);
    return Platform;
}());

var FileLoader = /** @class */ (function () {
    function FileLoader() {
    }
    FileLoader.prototype.toFile = function (dataUri, name) {
        if (name === void 0) { name = 'file'; }
        try {
            // Convert base64 to raw binary data held in a string.
            var byteString = window.atob(dataUri.split(',')[1]);
            // Separate out the mime component.
            var mimeString = dataUri.split(',')[0].split(':')[1].split(';')[0];
            // Write the bytes of the string to an ArrayBuffer.
            var arrayBuffer = new ArrayBuffer(byteString.length);
            var uint8Array = new Uint8Array(arrayBuffer);
            for (var index = 0; index < byteString.length; index++) {
                uint8Array[index] = byteString.charCodeAt(index);
            }
            var dataView = new DataView(arrayBuffer);
            var blob = new Blob([dataView.buffer], { type: mimeString });
            // Convert the blob to a file.
            blob.lastModifiedDate = new Date();
            blob.name = name;
            return blob;
        }
        catch (_a) {
            return null;
        }
    };
    FileLoader.prototype.asDataUrl = function (file) {
        return this.read(file, 'dataurl');
    };
    FileLoader.prototype.asArrayBuffer = function (file) {
        return this.read(file, 'arraybuffer');
    };
    FileLoader.prototype.read = function (file, type) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, new Promise(function (resolve, reject) {
                        if (!file || !(file instanceof File)) {
                            return reject('Invalid file');
                        }
                        var reader = new FileReader();
                        reader.onerror = function () { return reject('Error file read'); };
                        reader.onabort = function () { return reject('Abort file read'); };
                        reader.onload = function () {
                            var result = reader.result;
                            return resolve(result);
                        };
                        if (type === 'dataurl') {
                            reader.readAsDataURL(file);
                        }
                        else if (type === 'arraybuffer') {
                            reader.readAsArrayBuffer(file);
                        }
                    })];
            });
        });
    };
    FileLoader.ɵprov = ɵɵdefineInjectable({ factory: function FileLoader_Factory() { return new FileLoader(); }, token: FileLoader, providedIn: "root" });
    FileLoader = __decorate([
        Injectable({
            providedIn: 'root'
        })
    ], FileLoader);
    return FileLoader;
}());

var ImageConverter = /** @class */ (function () {
    function ImageConverter(_platform, _fileLoader) {
        this._platform = _platform;
        this._fileLoader = _fileLoader;
        // Data.
        this._types = ['image/png', 'image/jpeg'];
        this.calculateOffsetAndDimensions = function (image, canvasWidth, canvasHeight) {
            var originalWidth = image.width;
            var originalHeight = image.height;
            var widthRatio = canvasWidth / originalWidth;
            var heightRatio = canvasHeight / originalHeight;
            var width;
            var height;
            if (originalWidth > originalHeight) {
                height = originalHeight * heightRatio;
                width = (originalWidth / originalHeight) * height;
            }
            else {
                width = originalWidth * widthRatio;
                height = (originalHeight / originalWidth) * width;
            }
            var xOffset = 0;
            var yOffset = 0;
            if (canvasHeight === height) {
                xOffset = -((width - canvasWidth) / 2);
            }
            else if (canvasWidth === width) {
                yOffset = -((height - canvasHeight) / 2);
            }
            return { xOffset: xOffset, yOffset: yOffset, width: width, height: height };
        };
    }
    ImageConverter.prototype.toDataUri = function (contents, options) {
        if (options === void 0) { options = null; }
        return __awaiter(this, void 0, void 0, function () {
            var image, canvasWidth, canvasHeight, canvas, context, _a, width, height, xOffset, yOffset;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        // Check if the current platform is a browser.
                        if (!this._platform.isBrowser) {
                            return [2 /*return*/, null];
                        }
                        return [4 /*yield*/, this.getImage(contents)];
                    case 1:
                        image = _b.sent();
                        canvasWidth = (options && options.width) || image.width;
                        canvasHeight = (options && options.height) || image.height;
                        canvas = document.createElement('canvas');
                        context = canvas.getContext('2d');
                        canvas.width = canvasWidth;
                        canvas.height = canvasHeight;
                        // Check if dimensions where supplied, else create the image.
                        if (!options) {
                            // Draw the image.
                            context.drawImage(image, 0, 0);
                            // Convert the canvas to a data url.
                            return [2 /*return*/, canvas.toDataURL(this._types[0])];
                        }
                        _a = this.calculateOffsetAndDimensions(image, canvasWidth, canvasHeight), width = _a.width, height = _a.height, xOffset = _a.xOffset, yOffset = _a.yOffset;
                        // Draw the image.
                        context.drawImage(image, 0, 0, image.width, image.height, xOffset, yOffset, width, height);
                        // Convert the canvas to a data url.
                        return [2 /*return*/, canvas.toDataURL(this._types[0])];
                }
            });
        });
    };
    ImageConverter.prototype.fileToImage = function (file, types) {
        if (types === void 0) { types = this._types; }
        return __awaiter(this, void 0, void 0, function () {
            var dataUri;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        // Check if the file matches an image.
                        if (!types.includes(file.type)) {
                            throw new Error('The selected file does not meet the required format.');
                        }
                        return [4 /*yield*/, this._fileLoader.asDataUrl(file)];
                    case 1:
                        dataUri = _a.sent();
                        return [4 /*yield*/, this.stringToImage(dataUri)];
                    case 2: 
                    // Convert the data URI to a image element.
                    return [2 /*return*/, _a.sent()];
                }
            });
        });
    };
    ImageConverter.prototype.stringToImage = function (src) {
        return new Promise(function (resolve, reject) {
            var image = new Image();
            image.src = src;
            image.onload = function () { return resolve(image); };
            image.onerror = function (error) { return reject(error); };
        });
    };
    ImageConverter.prototype.getImage = function (contents) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                // If the contents is already an HTML image element just return it.
                if (contents instanceof HTMLImageElement) {
                    return [2 /*return*/, contents];
                }
                // If the contents is a file convert it to an HTML image element.
                if (contents instanceof File) {
                    return [2 /*return*/, this.fileToImage(contents)];
                }
                // If the contents is a string convert it to an HTML image element.
                if (typeof contents === 'string') {
                    return [2 /*return*/, this.stringToImage(contents)];
                }
                return [2 /*return*/];
            });
        });
    };
    ImageConverter.ctorParameters = function () { return [
        { type: Platform },
        { type: FileLoader }
    ]; };
    ImageConverter.ɵprov = ɵɵdefineInjectable({ factory: function ImageConverter_Factory() { return new ImageConverter(ɵɵinject(Platform), ɵɵinject(FileLoader)); }, token: ImageConverter, providedIn: "root" });
    ImageConverter = __decorate([
        Injectable({
            providedIn: 'root'
        })
    ], ImageConverter);
    return ImageConverter;
}());

var Languages = /** @class */ (function () {
    function Languages() {
        this.getLanguages = function () {
            if (typeof navigator !== 'object') {
                return null;
            }
            var t = 'anguage';
            var n = navigator;
            var f = n['l' + t + 's'];
            var data = f && f.length ? f : (t = n['l' + t] ||
                n['browserL' + t] ||
                n['userL' + t]) ? [t] : t;
            return typeof data === 'string'
                ? data
                : data.join(';');
        };
    }
    Object.defineProperty(Languages.prototype, "all", {
        get: function () {
            // Get the languages.
            var data = this.getLanguages();
            // Parse all languages by using a regex.
            var strings = (data || '')
                .match(/((([a-zA-Z]+(-[a-zA-Z0-9]+){0,2})|\*)(;q=[0-1](\.[0-9]+)?)?)*/g);
            // Get the content by parsing the strings.
            var content = strings.map(function (item) {
                if (!item) {
                    return null;
                }
                var bits = item.split(';');
                var ietf = bits[0].split('-');
                var hasScript = ietf.length === 3;
                return {
                    code: ietf[0],
                    script: hasScript ? ietf[1] : null,
                    region: hasScript ? ietf[2] : ietf[1],
                    quality: bits[1] ? parseFloat(bits[1].split('=')[1]) : 1.0
                };
            });
            // Filter out all the empty items
            // and sort them by the quality.
            return content
                .filter(function (item) { return !!item; })
                .sort(function (a, b) { return b.quality - a.quality; });
        },
        enumerable: true,
        configurable: true
    });
    Languages.ɵprov = ɵɵdefineInjectable({ factory: function Languages_Factory() { return new Languages(); }, token: Languages, providedIn: "root" });
    Languages = __decorate([
        Injectable({
            providedIn: 'root'
        })
    ], Languages);
    return Languages;
}());

var Network = /** @class */ (function () {
    function Network(_platform) {
        this._platform = _platform;
        // Data.
        this._online$ = of(true);
        this.getOnlineObservable();
    }
    Network.prototype.online = function () {
        return this._online$;
    };
    Network.prototype.getOnlineObservable = function () {
        // Validate we are on a browser.
        if (!this._platform.isBrowser) {
            return;
        }
        // Get all the events from the window.
        var online$ = fromEvent(window, 'online').pipe(mapTo(true));
        var offline$ = fromEvent(window, 'offline').pipe(mapTo(false));
        var now$ = new Observable(function (subscriber) {
            subscriber.next(navigator.onLine);
            subscriber.complete();
        });
        // Merge all event so we get notified when
        // a user is online/offline.
        this._online$ = merge(now$, online$, offline$).pipe(map(function (value) { return value; }), distinctUntilChanged(), shareReplay(1));
    };
    Network.ctorParameters = function () { return [
        { type: Platform }
    ]; };
    Network.ɵprov = ɵɵdefineInjectable({ factory: function Network_Factory() { return new Network(ɵɵinject(Platform)); }, token: Network, providedIn: "root" });
    Network = __decorate([
        Injectable({
            providedIn: 'root'
        })
    ], Network);
    return Network;
}());

var Patch = /** @class */ (function () {
    function Patch(_platform) {
        this._platform = _platform;
        this._hasPatchedMobileVerticalHeight = false;
        // Subscriptions.
        this._subscriptions = [];
    }
    Patch.prototype.mobileVerticalHeight = function () {
        // Check if the user has already patched
        // the mobile vertical height.
        if (this._hasPatchedMobileVerticalHeight) {
            return;
        }
        this.periodicallySetDocumentVerticalProperty();
        this._hasPatchedMobileVerticalHeight = true;
    };
    Patch.prototype.ngOnDestroy = function () {
        this._subscriptions.forEach(function (subscription) { return subscription.unsubscribe(); });
    };
    Patch.prototype.periodicallySetDocumentVerticalProperty = function () {
        // Validate we are using a browser.
        if (!this._platform.isBrowser) {
            return;
        }
        // Listen to a debounced window resize event.
        var resize$ = fromEvent(window, 'resize').pipe(debounceTime(25), startWith(0));
        // Subscribe to the resize observable.
        var subscription = resize$.subscribe(function () {
            var verticalHeight = window.innerHeight * 0.01;
            var element = document.documentElement;
            if (!element.style) {
                return;
            }
            if (!element.style.setProperty) {
                return;
            }
            document.documentElement.style.setProperty('--vh', verticalHeight + "px");
        });
        // Save the subscription so we can destroy it later.
        this._subscriptions.push(subscription);
    };
    Patch.ctorParameters = function () { return [
        { type: Platform }
    ]; };
    Patch.ɵprov = ɵɵdefineInjectable({ factory: function Patch_Factory() { return new Patch(ɵɵinject(Platform)); }, token: Patch, providedIn: "root" });
    Patch = __decorate([
        Injectable({
            providedIn: 'root'
        })
    ], Patch);
    return Patch;
}());

var Exif = /** @class */ (function () {
    function Exif(_platform, _fileLoader) {
        this._platform = _platform;
        this._fileLoader = _fileLoader;
        this.transformImage = function (image, type, orientation, quality) {
            if (quality === void 0) { quality = 100; }
            // Create the canvas and context.
            var canvas = document.createElement('canvas');
            var context = canvas.getContext('2d');
            // Set the canvas size based on the image.
            var width = image.width, height = image.height;
            canvas.width = width;
            canvas.height = height;
            // Validate the orientation is correct
            // else flip the canvas sizes.
            if (4 < orientation && orientation < 9) {
                canvas.width = height;
                canvas.height = width;
            }
            // Transform the context based on the orientation.
            switch (orientation) {
                case 2:
                    context.transform(-1, 0, 0, 1, width, 0);
                    break;
                case 3:
                    context.transform(-1, 0, 0, -1, width, height);
                    break;
                case 4:
                    context.transform(1, 0, 0, -1, 0, height);
                    break;
                case 5:
                    context.transform(0, 1, 1, 0, 0, 0);
                    break;
                case 6:
                    context.transform(0, 1, -1, 0, height, 0);
                    break;
                case 7:
                    context.transform(0, -1, -1, 0, height, width);
                    break;
                case 8:
                    context.transform(0, -1, 1, 0, 0, width);
                    break;
                default:
                    break;
            }
            // Draw the image on the context and return the data URL.
            context.drawImage(image, 0, 0, width, height);
            return canvas.toDataURL(type, quality / 100);
        };
        this.getSupportedCanvasType = function (fileType) {
            switch (fileType) {
                case 'image/jpeg':
                case 'image/jpg':
                    return 'image/jpeg';
                case 'image/x-windows-bmp':
                case 'image/bmp':
                    return 'image/bmp';
                default:
                    return 'image/png';
            }
        };
        this.getOrientation = function (buffer) {
            // Create a new data view.
            var view = new DataView(buffer);
            if (view.getUint16(0, false) !== 0xFFD8) {
                return -2;
            }
            var length = view.byteLength;
            var offset = 2;
            while (offset < length) {
                if (view.getUint16(offset + 2, false) <= 8) {
                    return -1;
                }
                var marker = view.getUint16(offset, false);
                offset += 2;
                if (marker === 0xFFE1) {
                    if (view.getUint32(offset += 2, false) !== 0x45786966) {
                        return -1;
                    }
                    var little = view.getUint16(offset += 6, false) === 0x4949;
                    offset += view.getUint32(offset + 4, little);
                    var tags = view.getUint16(offset, little);
                    offset += 2;
                    for (var index = 0; index < tags; index++) {
                        if (view.getUint16(offset + index * 12, little) === 0x0112) {
                            return view.getUint16(offset + index * 12 + 8, little);
                        }
                    }
                }
                else if ((marker & 0xFF00) !== 0xFF00) {
                    break;
                }
                else {
                    offset += view.getUint16(offset, false);
                }
            }
            return -1;
        };
    }
    Exif.prototype.strip = function (file, quality) {
        if (quality === void 0) { quality = 100; }
        return __awaiter(this, void 0, void 0, function () {
            var arrayBuffer, dataUrl, imageElement, orientation_1, canvasType, imageUrl, _a;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        // Validate we are on a browser.
                        if (!this._platform.isBrowser) {
                            return [2 /*return*/, file];
                        }
                        // Validate the file exists and is
                        // an instance of a File object.
                        if (!file || !(file instanceof File)) {
                            return [2 /*return*/, file];
                        }
                        _b.label = 1;
                    case 1:
                        _b.trys.push([1, 5, , 6]);
                        return [4 /*yield*/, this._fileLoader.asArrayBuffer(file)];
                    case 2:
                        arrayBuffer = _b.sent();
                        return [4 /*yield*/, this._fileLoader.asDataUrl(file)];
                    case 3:
                        dataUrl = _b.sent();
                        return [4 /*yield*/, this.createImageElement(dataUrl)];
                    case 4:
                        imageElement = _b.sent();
                        orientation_1 = this.getOrientation(arrayBuffer);
                        canvasType = this.getSupportedCanvasType(file.type);
                        imageUrl = this.transformImage(imageElement, canvasType, orientation_1, quality);
                        // Transform the image url to a file.
                        return [2 /*return*/, this._fileLoader.toFile(imageUrl, file.name)];
                    case 5:
                        _a = _b.sent();
                        // When something goes wrong we
                        // just return the default file.
                        return [2 /*return*/, file];
                    case 6: return [2 /*return*/];
                }
            });
        });
    };
    Exif.prototype.createImageElement = function (dataUrl) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, new Promise(function (resolve, reject) {
                        var image = new Image();
                        image.src = dataUrl;
                        image.onerror = function () { return reject('Error image create'); };
                        image.onabort = function () { return reject('Abort image create'); };
                        image.onload = function () { return resolve(image); };
                    })];
            });
        });
    };
    Exif.ctorParameters = function () { return [
        { type: Platform },
        { type: FileLoader }
    ]; };
    Exif.ɵprov = ɵɵdefineInjectable({ factory: function Exif_Factory() { return new Exif(ɵɵinject(Platform), ɵɵinject(FileLoader)); }, token: Exif, providedIn: "root" });
    Exif = __decorate([
        Injectable({
            providedIn: 'root'
        })
    ], Exif);
    return Exif;
}());

function coerceBooleanProperty(value) {
    return value != null && "" + value !== 'false';
}

function mixinDisabled(base) {
    return /** @class */ (function (_super) {
        __extends(class_1, _super);
        function class_1() {
            var args = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                args[_i] = arguments[_i];
            }
            var _this = _super.apply(this, __spread(args)) || this;
            _this._disable = false;
            return _this;
        }
        Object.defineProperty(class_1.prototype, "disabled", {
            get: function () {
                return this._disable;
            },
            set: function (value) {
                this._disable = coerceBooleanProperty(value);
            },
            enumerable: true,
            configurable: true
        });
        return class_1;
    }(base));
}

function mixinLoad(base) {
    return /** @class */ (function (_super) {
        __extends(class_1, _super);
        function class_1() {
            var args = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                args[_i] = arguments[_i];
            }
            var _this = _super.apply(this, __spread(args)) || this;
            _this._loading = false;
            return _this;
        }
        Object.defineProperty(class_1.prototype, "loading", {
            get: function () {
                return this._loading;
            },
            set: function (value) {
                this._loading = coerceBooleanProperty(value);
            },
            enumerable: true,
            configurable: true
        });
        return class_1;
    }(base));
}

function mixinError(base) {
    return /** @class */ (function (_super) {
        __extends(class_1, _super);
        function class_1() {
            var args = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                args[_i] = arguments[_i];
            }
            var _this = _super.apply(this, __spread(args)) || this;
            _this._error = false;
            return _this;
        }
        Object.defineProperty(class_1.prototype, "error", {
            get: function () {
                return this._error;
            },
            set: function (value) {
                this._error = coerceBooleanProperty(value);
            },
            enumerable: true,
            configurable: true
        });
        return class_1;
    }(base));
}

function mixinHideErrors(base) {
    return /** @class */ (function (_super) {
        __extends(class_1, _super);
        function class_1() {
            var args = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                args[_i] = arguments[_i];
            }
            var _this = _super.apply(this, __spread(args)) || this;
            _this._hideErrors = false;
            return _this;
        }
        Object.defineProperty(class_1.prototype, "hideErrors", {
            get: function () {
                return this._hideErrors;
            },
            set: function (value) {
                this._hideErrors = coerceBooleanProperty(value);
            },
            enumerable: true,
            configurable: true
        });
        return class_1;
    }(base));
}

function mixinFocused(base) {
    return /** @class */ (function (_super) {
        __extends(class_1, _super);
        function class_1() {
            var args = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                args[_i] = arguments[_i];
            }
            var _this = _super.apply(this, __spread(args)) || this;
            _this._focused = false;
            return _this;
        }
        Object.defineProperty(class_1.prototype, "focused", {
            get: function () {
                return this._focused;
            },
            set: function (value) {
                this._focused = coerceBooleanProperty(value);
            },
            enumerable: true,
            configurable: true
        });
        return class_1;
    }(base));
}

function mixinGrouped(base) {
    return /** @class */ (function (_super) {
        __extends(class_1, _super);
        function class_1() {
            var args = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                args[_i] = arguments[_i];
            }
            var _this = _super.apply(this, __spread(args)) || this;
            _this._grouped = false;
            return _this;
        }
        Object.defineProperty(class_1.prototype, "grouped", {
            get: function () {
                return this._grouped;
            },
            set: function (value) {
                this._grouped = coerceBooleanProperty(value);
            },
            enumerable: true,
            configurable: true
        });
        return class_1;
    }(base));
}

function mixinReadonly(base) {
    return /** @class */ (function (_super) {
        __extends(class_1, _super);
        function class_1() {
            var args = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                args[_i] = arguments[_i];
            }
            var _this = _super.apply(this, __spread(args)) || this;
            _this._readonly = false;
            return _this;
        }
        Object.defineProperty(class_1.prototype, "readonly", {
            get: function () {
                return this._readonly;
            },
            set: function (value) {
                this._readonly = coerceBooleanProperty(value);
            },
            enumerable: true,
            configurable: true
        });
        return class_1;
    }(base));
}

function mixinRequired(base) {
    return /** @class */ (function (_super) {
        __extends(class_1, _super);
        function class_1() {
            var args = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                args[_i] = arguments[_i];
            }
            var _this = _super.apply(this, __spread(args)) || this;
            _this._required = false;
            return _this;
        }
        Object.defineProperty(class_1.prototype, "required", {
            get: function () {
                return this._required;
            },
            set: function (value) {
                this._required = coerceBooleanProperty(value);
            },
            enumerable: true,
            configurable: true
        });
        return class_1;
    }(base));
}

var BbRegex = {
    email: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
    fullNumber: /^\d*[1-9]\d*$/
};

var BbValidator = /** @class */ (function () {
    function BbValidator() {
    }
    BbValidator.email = function (control) {
        if (isEmptyInputValue(control.value)) {
            return null;
        }
        return BbRegex.email.test(control.value) ? null : { email: true };
    };
    BbValidator.fullNumber = function (control) {
        if (isEmptyInputValue(control.value)) {
            return null;
        }
        return BbRegex.fullNumber.test(control.value) ? null : { fullNumber: true };
    };
    BbValidator.maxFileSize = function (bytes) {
        var validator = function (control) {
            var value = control.value;
            // Validate if the value is a file.
            if (!(value instanceof File)) {
                return null;
            }
            if (value.size <= bytes) {
                return null;
            }
            var maxSize = '0 Bytes';
            if (bytes !== 0) {
                var k = 1024;
                var dm = 2;
                var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
                var index = Math.floor(Math.log(bytes) / Math.log(k));
                maxSize = parseFloat((bytes / Math.pow(k, index)).toFixed(dm)) + ' ' + sizes[index];
            }
            return { maxFileSize: { maxSize: maxSize } };
        };
        return validator;
    };
    return BbValidator;
}());
function isEmptyInputValue(value) {
    // We don't check for string here so it also works with arrays.
    return value == null || value.length === 0;
}

/*
 * Public API Surface of bb-foundation
 */

/**
 * Generated bundle index. Do not edit.
 */

export { BbRegex, BbValidator, Exif, FileLoader, ImageConverter, Languages, Network, Patch, Platform, coerceBooleanProperty, mixinDisabled, mixinError, mixinFocused, mixinGrouped, mixinHideErrors, mixinLoad, mixinReadonly, mixinRequired };
//# sourceMappingURL=bravobit-bb-foundation.js.map
