(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('rxjs/operators'), require('rxjs')) :
    typeof define === 'function' && define.amd ? define('@bravobit/bb-foundation', ['exports', '@angular/core', '@angular/common', 'rxjs/operators', 'rxjs'], factory) :
    (global = global || self, factory((global.bravobit = global.bravobit || {}, global.bravobit['bb-foundation'] = {}), global.ng.core, global.ng.common, global.rxjs.operators, global.rxjs));
}(this, (function (exports, core, common, operators, rxjs) { 'use strict';

    /*! *****************************************************************************
    Copyright (c) Microsoft Corporation. All rights reserved.
    Licensed under the Apache License, Version 2.0 (the "License"); you may not use
    this file except in compliance with the License. You may obtain a copy of the
    License at http://www.apache.org/licenses/LICENSE-2.0

    THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
    WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
    MERCHANTABLITY OR NON-INFRINGEMENT.

    See the Apache Version 2.0 License for specific language governing permissions
    and limitations under the License.
    ***************************************************************************** */
    /* global Reflect, Promise */

    var extendStatics = function(d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };

    function __extends(d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    }

    var __assign = function() {
        __assign = Object.assign || function __assign(t) {
            for (var s, i = 1, n = arguments.length; i < n; i++) {
                s = arguments[i];
                for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
            }
            return t;
        };
        return __assign.apply(this, arguments);
    };

    function __rest(s, e) {
        var t = {};
        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
            t[p] = s[p];
        if (s != null && typeof Object.getOwnPropertySymbols === "function")
            for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
                if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                    t[p[i]] = s[p[i]];
            }
        return t;
    }

    function __decorate(decorators, target, key, desc) {
        var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
        if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
        else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
        return c > 3 && r && Object.defineProperty(target, key, r), r;
    }

    function __param(paramIndex, decorator) {
        return function (target, key) { decorator(target, key, paramIndex); }
    }

    function __metadata(metadataKey, metadataValue) {
        if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
    }

    function __awaiter(thisArg, _arguments, P, generator) {
        return new (P || (P = Promise))(function (resolve, reject) {
            function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
            function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
            function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
            step((generator = generator.apply(thisArg, _arguments || [])).next());
        });
    }

    function __generator(thisArg, body) {
        var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
        return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
        function verb(n) { return function (v) { return step([n, v]); }; }
        function step(op) {
            if (f) throw new TypeError("Generator is already executing.");
            while (_) try {
                if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
                if (y = 0, t) op = [op[0] & 2, t.value];
                switch (op[0]) {
                    case 0: case 1: t = op; break;
                    case 4: _.label++; return { value: op[1], done: false };
                    case 5: _.label++; y = op[1]; op = [0]; continue;
                    case 7: op = _.ops.pop(); _.trys.pop(); continue;
                    default:
                        if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                        if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                        if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                        if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                        if (t[2]) _.ops.pop();
                        _.trys.pop(); continue;
                }
                op = body.call(thisArg, _);
            } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
            if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
        }
    }

    function __exportStar(m, exports) {
        for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
    }

    function __values(o) {
        var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
        if (m) return m.call(o);
        return {
            next: function () {
                if (o && i >= o.length) o = void 0;
                return { value: o && o[i++], done: !o };
            }
        };
    }

    function __read(o, n) {
        var m = typeof Symbol === "function" && o[Symbol.iterator];
        if (!m) return o;
        var i = m.call(o), r, ar = [], e;
        try {
            while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
        }
        catch (error) { e = { error: error }; }
        finally {
            try {
                if (r && !r.done && (m = i["return"])) m.call(i);
            }
            finally { if (e) throw e.error; }
        }
        return ar;
    }

    function __spread() {
        for (var ar = [], i = 0; i < arguments.length; i++)
            ar = ar.concat(__read(arguments[i]));
        return ar;
    }

    function __spreadArrays() {
        for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
        for (var r = Array(s), k = 0, i = 0; i < il; i++)
            for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
                r[k] = a[j];
        return r;
    };

    function __await(v) {
        return this instanceof __await ? (this.v = v, this) : new __await(v);
    }

    function __asyncGenerator(thisArg, _arguments, generator) {
        if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
        var g = generator.apply(thisArg, _arguments || []), i, q = [];
        return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
        function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
        function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
        function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
        function fulfill(value) { resume("next", value); }
        function reject(value) { resume("throw", value); }
        function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
    }

    function __asyncDelegator(o) {
        var i, p;
        return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
        function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
    }

    function __asyncValues(o) {
        if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
        var m = o[Symbol.asyncIterator], i;
        return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
        function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
        function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
    }

    function __makeTemplateObject(cooked, raw) {
        if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
        return cooked;
    };

    function __importStar(mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
        result.default = mod;
        return result;
    }

    function __importDefault(mod) {
        return (mod && mod.__esModule) ? mod : { default: mod };
    }

    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
                    ? common.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: core.Optional }, { type: core.Inject, args: [core.PLATFORM_ID,] }] }
        ]; };
        Platform.ɵprov = core["ɵɵdefineInjectable"]({ factory: function Platform_Factory() { return new Platform(core["ɵɵinject"](core.PLATFORM_ID, 8)); }, token: Platform, providedIn: "root" });
        Platform = __decorate([
            core.Injectable({
                providedIn: 'root'
            }),
            __param(0, core.Optional()), __param(0, core.Inject(core.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 = core["ɵɵdefineInjectable"]({ factory: function FileLoader_Factory() { return new FileLoader(); }, token: FileLoader, providedIn: "root" });
        FileLoader = __decorate([
            core.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 = core["ɵɵdefineInjectable"]({ factory: function ImageConverter_Factory() { return new ImageConverter(core["ɵɵinject"](Platform), core["ɵɵinject"](FileLoader)); }, token: ImageConverter, providedIn: "root" });
        ImageConverter = __decorate([
            core.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 = core["ɵɵdefineInjectable"]({ factory: function Languages_Factory() { return new Languages(); }, token: Languages, providedIn: "root" });
        Languages = __decorate([
            core.Injectable({
                providedIn: 'root'
            })
        ], Languages);
        return Languages;
    }());

    var Network = /** @class */ (function () {
        function Network(_platform) {
            this._platform = _platform;
            // Data.
            this._online$ = rxjs.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$ = rxjs.fromEvent(window, 'online').pipe(operators.mapTo(true));
            var offline$ = rxjs.fromEvent(window, 'offline').pipe(operators.mapTo(false));
            var now$ = new rxjs.Observable(function (subscriber) {
                subscriber.next(navigator.onLine);
                subscriber.complete();
            });
            // Merge all event so we get notified when
            // a user is online/offline.
            this._online$ = rxjs.merge(now$, online$, offline$).pipe(operators.map(function (value) { return value; }), operators.distinctUntilChanged(), operators.shareReplay(1));
        };
        Network.ctorParameters = function () { return [
            { type: Platform }
        ]; };
        Network.ɵprov = core["ɵɵdefineInjectable"]({ factory: function Network_Factory() { return new Network(core["ɵɵinject"](Platform)); }, token: Network, providedIn: "root" });
        Network = __decorate([
            core.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$ = rxjs.fromEvent(window, 'resize').pipe(operators.debounceTime(25), operators.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 = core["ɵɵdefineInjectable"]({ factory: function Patch_Factory() { return new Patch(core["ɵɵinject"](Platform)); }, token: Patch, providedIn: "root" });
        Patch = __decorate([
            core.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 = core["ɵɵdefineInjectable"]({ factory: function Exif_Factory() { return new Exif(core["ɵɵinject"](Platform), core["ɵɵinject"](FileLoader)); }, token: Exif, providedIn: "root" });
        Exif = __decorate([
            core.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;
    }

    exports.BbRegex = BbRegex;
    exports.BbValidator = BbValidator;
    exports.Exif = Exif;
    exports.FileLoader = FileLoader;
    exports.ImageConverter = ImageConverter;
    exports.Languages = Languages;
    exports.Network = Network;
    exports.Patch = Patch;
    exports.Platform = Platform;
    exports.coerceBooleanProperty = coerceBooleanProperty;
    exports.mixinDisabled = mixinDisabled;
    exports.mixinError = mixinError;
    exports.mixinFocused = mixinFocused;
    exports.mixinGrouped = mixinGrouped;
    exports.mixinHideErrors = mixinHideErrors;
    exports.mixinLoad = mixinLoad;
    exports.mixinReadonly = mixinReadonly;
    exports.mixinRequired = mixinRequired;

    Object.defineProperty(exports, '__esModule', { value: true });

})));
//# sourceMappingURL=bravobit-bb-foundation.umd.js.map
