(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular-ru/cdk/number'), require('@angular-ru/cdk/object'), require('@angular-ru/cdk/string'), require('@angular-ru/cdk/utils'), require('rxjs'), require('@angular/forms'), require('@angular/common'), require('@angular-ru/cdk/array'), require('@angular-ru/cdk/forms')) :
    typeof define === 'function' && define.amd ? define('@angular-ru/cdk/directives', ['exports', '@angular/core', '@angular-ru/cdk/number', '@angular-ru/cdk/object', '@angular-ru/cdk/string', '@angular-ru/cdk/utils', 'rxjs', '@angular/forms', '@angular/common', '@angular-ru/cdk/array', '@angular-ru/cdk/forms'], factory) :
    (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['angular-ru'] = global['angular-ru'] || {}, global['angular-ru'].cdk = global['angular-ru'].cdk || {}, global['angular-ru'].cdk.directives = {}), global.ng.core, global['angular-ru'].cdk.number, global['angular-ru'].cdk.object, global['angular-ru'].cdk.string, global['angular-ru'].cdk.utils, global.rxjs, global.ng.forms, global.ng.common, global['angular-ru'].cdk.array, global['angular-ru'].cdk.forms));
}(this, (function (exports, i0, number, object, string, utils, rxjs, i1, common, array, i1$1) { 'use strict';

    function _interopNamespace(e) {
        if (e && e.__esModule) return e;
        var n = Object.create(null);
        if (e) {
            Object.keys(e).forEach(function (k) {
                if (k !== 'default') {
                    var d = Object.getOwnPropertyDescriptor(e, k);
                    Object.defineProperty(n, k, d.get ? d : {
                        enumerable: true,
                        get: function () {
                            return e[k];
                        }
                    });
                }
            });
        }
        n['default'] = e;
        return Object.freeze(n);
    }

    var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
    var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
    var i1__namespace$1 = /*#__PURE__*/_interopNamespace(i1$1);

    var AMOUNT_FORMAT_OPTIONS = new i0.InjectionToken('AMOUNT_FORMAT_OPTIONS');
    var DEFAULT_AMOUNT_OPTIONS = { lang: 'ru-RU' };

    var AmountFormatDirective = /** @class */ (function () {
        function AmountFormatDirective(el, globalOptions, ngControl, ngZone, cd) {
            this.el = el;
            this.ngControl = ngControl;
            this.ngZone = ngZone;
            this.cd = cd;
            this.subscriptions = new rxjs.Subscription();
            this.previousLang = null;
            this.maximumFractionDigits = 3;
            this.isInsideAngularZone = true;
            this.options = {};
            this.markedAsDirty = true;
            this.cursorPointer = 0;
            this.setFirstLocalOptionsByGlobal(globalOptions);
        }
        Object.defineProperty(AmountFormatDirective.prototype, "isInAngularZone", {
            get: function () {
                return this.isInsideAngularZone;
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(AmountFormatDirective.prototype, "amountFormatOptions", {
            get: function () {
                return this.options;
            },
            set: function (options) {
                this.options = Object.assign(Object.assign({}, this.options), (options !== null && options !== void 0 ? options : {}));
                this.recalculateWhenChangesOptions();
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(AmountFormatDirective.prototype, "dirty", {
            get: function () {
                return this.markedAsDirty;
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(AmountFormatDirective.prototype, "element", {
            get: function () {
                return this.el.nativeElement;
            },
            enumerable: false,
            configurable: true
        });
        AmountFormatDirective.prototype.setLang = function (lang) {
            this.options.lang = lang;
            this.recalculateWhenChangesOptions();
        };
        AmountFormatDirective.prototype.getCursorPosition = function () {
            return this.cursorPointer;
        };
        AmountFormatDirective.prototype.ngOnInit = function () {
            this.setupElementType();
            this.subscribeToElementEvents();
        };
        AmountFormatDirective.prototype.ngAfterViewInit = function () {
            this.format();
        };
        AmountFormatDirective.prototype.ngOnDestroy = function () {
            this.unsubscribeFromElementEvents();
        };
        AmountFormatDirective.prototype.subscribeToElementEvents = function () {
            var _this = this;
            var _a;
            (_a = this.ngZone) === null || _a === void 0 ? void 0 : _a.runOutsideAngular(function () {
                _this.subscriptions.add(rxjs.fromEvent(_this.element, 'input').subscribe(function () {
                    _this.isInsideAngularZone = i0.NgZone.isInAngularZone();
                    _this.format();
                }));
                _this.subscriptions.add(rxjs.fromEvent(_this.element, 'blur').subscribe(function () {
                    _this.isInsideAngularZone = i0.NgZone.isInAngularZone();
                    _this.formatOnBlur();
                }));
            });
        };
        AmountFormatDirective.prototype.unsubscribeFromElementEvents = function () {
            this.subscriptions.unsubscribe();
        };
        AmountFormatDirective.prototype.formatOnBlur = function () {
            var _a;
            if (this.isIncorrectPreviewAfterBlur()) {
                this.element.value = (_a = string.removeLastSymbol(this.element.value)) !== null && _a !== void 0 ? _a : '';
            }
        };
        AmountFormatDirective.prototype.format = function () {
            var _a, _b;
            var fraction = this.getFractionSeparator();
            this.cursorPointer = (_a = this.element.selectionStart) !== null && _a !== void 0 ? _a : 0;
            var isInSafeSelectionPosition = this.cursorPointer !== this.element.value.length;
            this.replaceAllInvalidSymbolsBeforeTranslation();
            if (this.viewModelIsOnlyMinus()) {
                this.resetModelValue();
                // Note: should be set custom view model value
                // because when we trigger ngControl?.reset
                // it's also reset view model
                this.element.value = '-';
                return;
            }
            var originValueBeforeReset = this.element.value;
            var numberValue = this.getNumberValueWithGaussRounded();
            this.setModelValueBy(numberValue);
            this.element.value = originValueBeforeReset;
            var stringValue = this.prepareConvertedToLocaleValue(numberValue, fraction);
            // Note: we should reset view model value
            // when user set invalid number value as `15,,,,,0` or `15.00.00.00.00`
            this.element.value = isNaN((_b = this.ngControl) === null || _b === void 0 ? void 0 : _b.value) ? '' : stringValue;
            this.setSelectionRangeBy(isInSafeSelectionPosition, stringValue);
            this.preventExpressionChangedAfter();
        };
        AmountFormatDirective.prototype.isIncorrectPreviewAfterBlur = function () {
            return this.lastSymbolIsFraction() || this.viewModelIsOnlyMinus();
        };
        /**
         * note: after reset model value then control override view model
         */
        AmountFormatDirective.prototype.resetModelValue = function (value) {
            if (value === void 0) { value = null; }
            var _a;
            (_a = this.ngControl) === null || _a === void 0 ? void 0 : _a.reset(value);
        };
        AmountFormatDirective.prototype.replaceAllInvalidSymbolsBeforeTranslation = function () {
            var fraction = this.getFractionSeparator();
            this.element.value = this.removeNonNumericSymbols();
            this.element.value = this.replaceInvalidFractionPosition(fraction);
            this.element.value = this.removeDuplicateMinusOrFractionSymbol(fraction);
        };
        AmountFormatDirective.prototype.getMaximumFractionDigits = function () {
            var _a, _b;
            return (_b = (_a = this.options.formatOptions) === null || _a === void 0 ? void 0 : _a.maximumFractionDigits) !== null && _b !== void 0 ? _b : this.maximumFractionDigits;
        };
        AmountFormatDirective.prototype.getLastSymbolsAsZeroDot = function (fraction) {
            var _a, _b, _c;
            var maximumFractionDigits = this.getMaximumFractionDigits();
            var lastSymbolsAsZeroDot = maximumFractionDigits === 0
                ? ''
                : (_c = (_b = (_a = this.element.value.match(new RegExp("(\\" + fraction + ")(.+)?"))) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.replace(/,|./, '')) !== null && _c !== void 0 ? _c : '';
            var isOverflowGaussRound = lastSymbolsAsZeroDot.length > this.maximumFractionDigits;
            if (isOverflowGaussRound) {
                var parsedDot = number.gaussRound(number.toNumber("0" + fraction + lastSymbolsAsZeroDot, this.options.lang), maximumFractionDigits);
                lastSymbolsAsZeroDot = isNaN(parsedDot) ? '' : parsedDot.toString().replace(/0\./, '');
            }
            return lastSymbolsAsZeroDot;
        };
        AmountFormatDirective.prototype.prepareConvertedToLocaleValue = function (numberValueWithGaussRounded, fraction) {
            var lastSymbolAsFraction = this.lastSymbolIsFraction();
            var convertedToLocaleValue = this.getConvertedToLocaleString(numberValueWithGaussRounded);
            if (lastSymbolAsFraction) {
                convertedToLocaleValue = "" + convertedToLocaleValue + fraction;
            }
            else {
                var lastSymbolsAsZeroDot = this.getLastSymbolsAsZeroDot(fraction);
                if (utils.checkValueIsFilled(lastSymbolsAsZeroDot)) {
                    var splitValues = convertedToLocaleValue.split(fraction);
                    var beforePoint = splitValues === null || splitValues === void 0 ? void 0 : splitValues[0];
                    if (utils.checkValueIsFilled(beforePoint)) {
                        convertedToLocaleValue = "" + beforePoint + fraction + lastSymbolsAsZeroDot;
                    }
                    else {
                        convertedToLocaleValue = "0" + fraction + lastSymbolsAsZeroDot;
                    }
                }
            }
            return convertedToLocaleValue.replace(/\s/g, ' ');
        };
        AmountFormatDirective.prototype.setModelValueBy = function (numberValue) {
            if (isNaN(numberValue)) {
                this.resetModelValue();
            }
            else {
                this.resetModelValue(numberValue);
            }
        };
        AmountFormatDirective.prototype.getConvertedToLocaleString = function (numberValue) {
            return (isNaN(numberValue) ? '' : numberValue).toLocaleString(this.options.lang, this.options.formatOptions);
        };
        AmountFormatDirective.prototype.getNumberValueWithGaussRounded = function () {
            var maximumFractionDigits = this.getMaximumFractionDigits();
            return number.gaussRound(number.toNumber(this.element.value, this.options.lang), maximumFractionDigits);
        };
        AmountFormatDirective.prototype.lastSymbolIsFraction = function () {
            return string.getLastSymbol(this.element.value) === this.getFractionSeparator();
        };
        AmountFormatDirective.prototype.replaceInvalidFractionPosition = function (fraction) {
            return this.element.value.replace(new RegExp("\\" + fraction + "+$", 'g'), fraction);
        };
        AmountFormatDirective.prototype.removeDuplicateMinusOrFractionSymbol = function (fraction) {
            var value = this.element.value;
            var count = 0;
            value = value.replace(new RegExp("\\" + fraction, 'g'), function () {
                count++;
                return count > 1 ? '' : fraction;
            });
            if (value.indexOf('-') !== 0) {
                value = value.replace(/-/g, '');
            }
            return value;
        };
        AmountFormatDirective.prototype.viewModelIsOnlyMinus = function () {
            return this.element.value === '-';
        };
        AmountFormatDirective.prototype.getFractionSeparator = function () {
            var _a;
            return number.getFractionSeparator((_a = this.options.lang) !== null && _a !== void 0 ? _a : DEFAULT_AMOUNT_OPTIONS.lang);
        };
        AmountFormatDirective.prototype.removeNonNumericSymbols = function () {
            return this.viewModelIsOnlyMinus() ? this.element.value : string.removeNonNumericSymbols(this.element.value);
        };
        AmountFormatDirective.prototype.setSelectionRangeBy = function (safePosition, value) {
            try {
                if (safePosition) {
                    this.element.setSelectionRange(this.cursorPointer, this.cursorPointer);
                }
                else {
                    this.cursorPointer = value.length;
                    this.element.setSelectionRange(this.cursorPointer, this.cursorPointer);
                }
            }
            catch (_a) {
                // Caretaker note:
                // this situation can happen if <input type=number />
                // at some point, the directive may not have time to work and set the value `type=text`
            }
        };
        AmountFormatDirective.prototype.setFirstLocalOptionsByGlobal = function (options) {
            this.options = object.deepClone(options);
            this.previousLang = this.options.lang;
        };
        AmountFormatDirective.prototype.recalculateWhenChangesOptions = function () {
            var _a;
            var value = number.toNumber(this.element.value, (_a = this.previousLang) !== null && _a !== void 0 ? _a : this.options.lang);
            this.element.value = value.toLocaleString(this.options.lang, this.options.formatOptions);
            this.previousLang = this.options.lang;
            this.format();
        };
        AmountFormatDirective.prototype.preventExpressionChangedAfter = function () {
            if (this.markedAsDirty) {
                utils.detectChanges(this.cd);
                this.markedAsDirty = false;
            }
        };
        AmountFormatDirective.prototype.setupElementType = function () {
            this.el.nativeElement.setAttribute('type', 'text');
        };
        return AmountFormatDirective;
    }());
    /** @nocollapse */ /** @nocollapse */ AmountFormatDirective.ɵfac = function AmountFormatDirective_Factory(t) { return new (t || AmountFormatDirective)(i0__namespace.ɵɵdirectiveInject(i0__namespace.ElementRef), i0__namespace.ɵɵdirectiveInject(AMOUNT_FORMAT_OPTIONS), i0__namespace.ɵɵdirectiveInject(i1__namespace.NgControl, 8), i0__namespace.ɵɵdirectiveInject(i0__namespace.NgZone, 8), i0__namespace.ɵɵdirectiveInject(i0__namespace.ChangeDetectorRef, 8)); };
    /** @nocollapse */ /** @nocollapse */ AmountFormatDirective.ɵdir = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineDirective({ type: AmountFormatDirective, selectors: [["", "amountFormat", ""]], inputs: { amountFormatOptions: "amountFormatOptions" } });
    (function () {
        (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(AmountFormatDirective, [{
                type: i0.Directive,
                args: [{ selector: '[amountFormat]' }]
            }], function () {
            return [{ type: i0__namespace.ElementRef }, { type: undefined, decorators: [{
                            type: i0.Inject,
                            args: [AMOUNT_FORMAT_OPTIONS]
                        }] }, { type: i1__namespace.NgControl, decorators: [{
                            type: i0.Optional
                        }] }, { type: i0__namespace.NgZone, decorators: [{
                            type: i0.Optional
                        }] }, { type: i0__namespace.ChangeDetectorRef, decorators: [{
                            type: i0.Optional
                        }] }];
        }, { amountFormatOptions: [{
                    type: i0.Input
                }] });
    })();

    var AmountFormatModule = /** @class */ (function () {
        function AmountFormatModule() {
        }
        AmountFormatModule.forRoot = function (options) {
            if (options === void 0) { options = {}; }
            return {
                ngModule: AmountFormatModule,
                providers: [{ provide: AMOUNT_FORMAT_OPTIONS, useValue: Object.assign(Object.assign({}, DEFAULT_AMOUNT_OPTIONS), options) }]
            };
        };
        return AmountFormatModule;
    }());
    /** @nocollapse */ /** @nocollapse */ AmountFormatModule.ɵfac = function AmountFormatModule_Factory(t) { return new (t || AmountFormatModule)(); };
    /** @nocollapse */ /** @nocollapse */ AmountFormatModule.ɵmod = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineNgModule({ type: AmountFormatModule });
    /** @nocollapse */ /** @nocollapse */ AmountFormatModule.ɵinj = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineInjector({ imports: [[common.CommonModule]] });
    (function () {
        (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(AmountFormatModule, [{
                type: i0.NgModule,
                args: [{
                        imports: [common.CommonModule],
                        exports: [AmountFormatDirective],
                        declarations: [AmountFormatDirective]
                    }]
            }], null, null);
    })();
    (function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0__namespace.ɵɵsetNgModuleScope(AmountFormatModule, { declarations: [AmountFormatDirective], imports: [common.CommonModule], exports: [AmountFormatDirective] }); })();

    var ConvertCaseDirective = /** @class */ (function () {
        function ConvertCaseDirective(el, ngControl) {
            this.el = el;
            this.ngControl = ngControl;
            this.toUpperCase = true;
            this.toLowerCase = false;
        }
        Object.defineProperty(ConvertCaseDirective.prototype, "element", {
            get: function () {
                return this.el.nativeElement;
            },
            enumerable: false,
            configurable: true
        });
        ConvertCaseDirective.prototype.ngAfterViewInit = function () {
            if (this.element.value) {
                this.onInput();
            }
        };
        ConvertCaseDirective.prototype.onInput = function () {
            var _a;
            var dirtyValue = string.toStringVal(this.element.value);
            this.element.value = this.toLowerCase ? dirtyValue.toLowerCase() : dirtyValue.toUpperCase();
            (_a = this.ngControl) === null || _a === void 0 ? void 0 : _a.reset(this.element.value);
        };
        return ConvertCaseDirective;
    }());
    /** @nocollapse */ /** @nocollapse */ ConvertCaseDirective.ɵfac = function ConvertCaseDirective_Factory(t) { return new (t || ConvertCaseDirective)(i0__namespace.ɵɵdirectiveInject(i0__namespace.ElementRef), i0__namespace.ɵɵdirectiveInject(i1__namespace.NgControl, 8)); };
    /** @nocollapse */ /** @nocollapse */ ConvertCaseDirective.ɵdir = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineDirective({ type: ConvertCaseDirective, selectors: [["", "convertCase", ""]], hostBindings: function ConvertCaseDirective_HostBindings(rf, ctx) {
            if (rf & 1) {
                i0__namespace.ɵɵlistener("input", function ConvertCaseDirective_input_HostBindingHandler() { return ctx.onInput(); });
            }
        }, inputs: { toUpperCase: "toUpperCase", toLowerCase: "toLowerCase" } });
    (function () {
        (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(ConvertCaseDirective, [{
                type: i0.Directive,
                args: [{ selector: '[convertCase]' }]
            }], function () {
            return [{ type: i0__namespace.ElementRef }, { type: i1__namespace.NgControl, decorators: [{
                            type: i0.Optional
                        }] }];
        }, { toUpperCase: [{
                    type: i0.Input
                }], toLowerCase: [{
                    type: i0.Input
                }], onInput: [{
                    type: i0.HostListener,
                    args: ['input']
                }] });
    })();

    var ConvertCaseModule = /** @class */ (function () {
        function ConvertCaseModule() {
        }
        return ConvertCaseModule;
    }());
    /** @nocollapse */ /** @nocollapse */ ConvertCaseModule.ɵfac = function ConvertCaseModule_Factory(t) { return new (t || ConvertCaseModule)(); };
    /** @nocollapse */ /** @nocollapse */ ConvertCaseModule.ɵmod = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineNgModule({ type: ConvertCaseModule });
    /** @nocollapse */ /** @nocollapse */ ConvertCaseModule.ɵinj = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineInjector({ imports: [[common.CommonModule]] });
    (function () {
        (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(ConvertCaseModule, [{
                type: i0.NgModule,
                args: [{
                        declarations: [ConvertCaseDirective],
                        imports: [common.CommonModule],
                        exports: [ConvertCaseDirective]
                    }]
            }], null, null);
    })();
    (function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0__namespace.ɵɵsetNgModuleScope(ConvertCaseModule, { declarations: [ConvertCaseDirective], imports: [common.CommonModule], exports: [ConvertCaseDirective] }); })();

    var DisableControlDirective = /** @class */ (function () {
        function DisableControlDirective(ngControl) {
            this.ngControl = ngControl;
        }
        Object.defineProperty(DisableControlDirective.prototype, "disableControl", {
            set: function (condition) {
                var _a, _b, _c;
                var action = condition ? 'disable' : 'enable';
                (_c = (_b = (_a = this.ngControl) === null || _a === void 0 ? void 0 : _a.control) === null || _b === void 0 ? void 0 : _b[action]) === null || _c === void 0 ? void 0 : _c.call(_b);
            },
            enumerable: false,
            configurable: true
        });
        return DisableControlDirective;
    }());
    /** @nocollapse */ /** @nocollapse */ DisableControlDirective.ɵfac = function DisableControlDirective_Factory(t) { return new (t || DisableControlDirective)(i0__namespace.ɵɵdirectiveInject(i1__namespace.NgControl, 8)); };
    /** @nocollapse */ /** @nocollapse */ DisableControlDirective.ɵdir = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineDirective({ type: DisableControlDirective, selectors: [["", "disableControl", ""]], inputs: { disableControl: "disableControl" } });
    (function () {
        (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(DisableControlDirective, [{
                type: i0.Directive,
                args: [{ selector: '[disableControl]' }]
            }], function () {
            return [{ type: i1__namespace.NgControl, decorators: [{
                            type: i0.Optional
                        }] }];
        }, { disableControl: [{
                    type: i0.Input
                }] });
    })();

    var DisableControlModule = /** @class */ (function () {
        function DisableControlModule() {
        }
        return DisableControlModule;
    }());
    /** @nocollapse */ /** @nocollapse */ DisableControlModule.ɵfac = function DisableControlModule_Factory(t) { return new (t || DisableControlModule)(); };
    /** @nocollapse */ /** @nocollapse */ DisableControlModule.ɵmod = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineNgModule({ type: DisableControlModule });
    /** @nocollapse */ /** @nocollapse */ DisableControlModule.ɵinj = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineInjector({ imports: [[common.CommonModule]] });
    (function () {
        (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(DisableControlModule, [{
                type: i0.NgModule,
                args: [{
                        declarations: [DisableControlDirective],
                        imports: [common.CommonModule],
                        exports: [DisableControlDirective]
                    }]
            }], null, null);
    })();
    (function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0__namespace.ɵɵsetNgModuleScope(DisableControlModule, { declarations: [DisableControlDirective], imports: [common.CommonModule], exports: [DisableControlDirective] }); })();

    var MIN_DELAY = 500;
    var InitialFocusDirective = /** @class */ (function () {
        function InitialFocusDirective(element, ngZone) {
            this.element = element;
            this.ngZone = ngZone;
            this.focusDelay = MIN_DELAY;
            this.className = 'initial-focused';
            this.timeoutId = null;
        }
        Object.defineProperty(InitialFocusDirective.prototype, "el", {
            get: function () {
                return this.element.nativeElement;
            },
            enumerable: false,
            configurable: true
        });
        InitialFocusDirective.prototype.ngAfterViewInit = function () {
            var _this = this;
            this.ngZone.runOutsideAngular(function () {
                window.clearInterval(_this.timeoutId);
                // eslint-disable-next-line no-restricted-properties
                _this.timeoutId = window.setInterval(function () { return _this.focus(); }, _this.focusDelay);
            });
        };
        InitialFocusDirective.prototype.ngOnDestroy = function () {
            window.clearInterval(this.timeoutId);
        };
        InitialFocusDirective.prototype.isFocused = function () {
            return this.elementIsActive() || this.el.classList.contains(this.className);
        };
        InitialFocusDirective.prototype.elementIsActive = function () {
            return document.activeElement === this.element.nativeElement;
        };
        InitialFocusDirective.prototype.focus = function () {
            if (this.isFocused()) {
                window.clearInterval(this.timeoutId);
                return;
            }
            this.el.focus();
            this.el.setSelectionRange(this.el.value.length, this.el.value.length);
            if (this.elementIsActive()) {
                this.el.classList.add(this.className);
                window.clearInterval(this.timeoutId);
            }
        };
        return InitialFocusDirective;
    }());
    /** @nocollapse */ /** @nocollapse */ InitialFocusDirective.ɵfac = function InitialFocusDirective_Factory(t) { return new (t || InitialFocusDirective)(i0__namespace.ɵɵdirectiveInject(i0__namespace.ElementRef), i0__namespace.ɵɵdirectiveInject(i0__namespace.NgZone)); };
    /** @nocollapse */ /** @nocollapse */ InitialFocusDirective.ɵdir = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineDirective({ type: InitialFocusDirective, selectors: [["", "initialFocus", ""]], inputs: { focusDelay: "focusDelay" } });
    (function () {
        (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(InitialFocusDirective, [{
                type: i0.Directive,
                args: [{ selector: '[initialFocus]' }]
            }], function () { return [{ type: i0__namespace.ElementRef }, { type: i0__namespace.NgZone }]; }, { focusDelay: [{
                    type: i0.Input
                }] });
    })();

    var InitialFocusModule = /** @class */ (function () {
        function InitialFocusModule() {
        }
        return InitialFocusModule;
    }());
    /** @nocollapse */ /** @nocollapse */ InitialFocusModule.ɵfac = function InitialFocusModule_Factory(t) { return new (t || InitialFocusModule)(); };
    /** @nocollapse */ /** @nocollapse */ InitialFocusModule.ɵmod = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineNgModule({ type: InitialFocusModule });
    /** @nocollapse */ /** @nocollapse */ InitialFocusModule.ɵinj = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineInjector({ imports: [[common.CommonModule]] });
    (function () {
        (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(InitialFocusModule, [{
                type: i0.NgModule,
                args: [{
                        imports: [common.CommonModule],
                        declarations: [InitialFocusDirective],
                        exports: [InitialFocusDirective]
                    }]
            }], null, null);
    })();
    (function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0__namespace.ɵɵsetNgModuleScope(InitialFocusModule, { declarations: [InitialFocusDirective], imports: [common.CommonModule], exports: [InitialFocusDirective] }); })();

    var InputFilterConfig = /** @class */ (function () {
        function InputFilterConfig() {
            this.default = null;
        }
        return InputFilterConfig;
    }());
    /** @nocollapse */ /** @nocollapse */ InputFilterConfig.ɵfac = function InputFilterConfig_Factory(t) { return new (t || InputFilterConfig)(); };
    /** @nocollapse */ /** @nocollapse */ InputFilterConfig.ɵprov = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineInjectable({ token: InputFilterConfig, factory: InputFilterConfig.ɵfac });
    (function () {
        (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(InputFilterConfig, [{
                type: i0.Injectable
            }], null, null);
    })();

    var InputFilterDirective = /** @class */ (function () {
        function InputFilterDirective(elementRef, config) {
            this.elementRef = elementRef;
            this.config = config;
            this.inputFilter = null;
            this.manualEvent = null;
        }
        InputFilterDirective.prototype.onInput = function (baseEvent) {
            var _a, _b;
            if (this.manualEvent === baseEvent) {
                return;
            }
            var predicate = this.getPredicate();
            var baseValue = this.elementRef.nativeElement.value;
            var preparedValue = string.filter(baseValue, predicate);
            if (preparedValue === baseValue) {
                return;
            }
            this.manualEvent = new InputEvent('input', Object.assign(Object.assign({}, baseEvent), { data: preparedValue }));
            this.elementRef.nativeElement.value = (_b = (_a = this.manualEvent) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : '';
            this.elementRef.nativeElement.dispatchEvent(this.manualEvent);
        };
        InputFilterDirective.prototype.getPredicate = function () {
            var _a, _b;
            var isInputPredicate = Array.isArray(this.inputFilter)
                ? array.hasItems(this.inputFilter)
                : utils.checkValueIsFilled(this.inputFilter);
            var predicate = isInputPredicate
                ? this.inputFilter
                : (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.default) !== null && _b !== void 0 ? _b : [];
            return predicate;
        };
        return InputFilterDirective;
    }());
    /** @nocollapse */ /** @nocollapse */ InputFilterDirective.ɵfac = function InputFilterDirective_Factory(t) { return new (t || InputFilterDirective)(i0__namespace.ɵɵdirectiveInject(i0__namespace.ElementRef), i0__namespace.ɵɵdirectiveInject(InputFilterConfig, 8)); };
    /** @nocollapse */ /** @nocollapse */ InputFilterDirective.ɵdir = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineDirective({ type: InputFilterDirective, selectors: [["", "inputFilter", ""]], hostBindings: function InputFilterDirective_HostBindings(rf, ctx) {
            if (rf & 1) {
                i0__namespace.ɵɵlistener("input", function InputFilterDirective_input_HostBindingHandler($event) { return ctx.onInput($event); });
            }
        }, inputs: { inputFilter: "inputFilter" }, features: [i0__namespace.ɵɵProvidersFeature([i1$1.ControlValueInterceptor])] });
    (function () {
        (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(InputFilterDirective, [{
                type: i0.Directive,
                args: [{
                        selector: '[inputFilter]',
                        providers: [i1$1.ControlValueInterceptor]
                    }]
            }], function () {
            return [{ type: i0__namespace.ElementRef }, { type: undefined, decorators: [{
                            type: i0.Optional
                        }, {
                            type: i0.Inject,
                            args: [InputFilterConfig]
                        }] }];
        }, { inputFilter: [{
                    type: i0.Input
                }], onInput: [{
                    type: i0.HostListener,
                    args: ['input', ['$event']]
                }] });
    })();

    var InputFilterModule = /** @class */ (function () {
        function InputFilterModule() {
        }
        InputFilterModule.forRoot = function (config) {
            return {
                ngModule: InputFilterModule,
                providers: [
                    {
                        provide: InputFilterConfig,
                        useValue: config
                    }
                ]
            };
        };
        InputFilterModule.forChild = function (config) {
            return {
                ngModule: InputFilterModule,
                providers: [
                    {
                        provide: InputFilterConfig,
                        useValue: config
                    }
                ]
            };
        };
        return InputFilterModule;
    }());
    /** @nocollapse */ /** @nocollapse */ InputFilterModule.ɵfac = function InputFilterModule_Factory(t) { return new (t || InputFilterModule)(); };
    /** @nocollapse */ /** @nocollapse */ InputFilterModule.ɵmod = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineNgModule({ type: InputFilterModule });
    /** @nocollapse */ /** @nocollapse */ InputFilterModule.ɵinj = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineInjector({ imports: [[common.CommonModule]] });
    (function () {
        (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(InputFilterModule, [{
                type: i0.NgModule,
                args: [{
                        imports: [common.CommonModule],
                        declarations: [InputFilterDirective],
                        exports: [InputFilterDirective]
                    }]
            }], null, null);
    })();
    (function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0__namespace.ɵɵsetNgModuleScope(InputFilterModule, { declarations: [InputFilterDirective], imports: [common.CommonModule], exports: [InputFilterDirective] }); })();

    var SplitStringDirective = /** @class */ (function () {
        function SplitStringDirective(interceptor) {
            var _this = this;
            this.defaultSplitOptions = {
                separator: /[,;\n]/g,
                joinWith: ', '
            };
            interceptor.attach({
                toModelValue: function (viewValue) { return _this.splitAndTrimViewValue(viewValue); },
                toViewValue: function (modelValue) {
                    var _a, _b;
                    return Array.isArray(modelValue)
                        ? modelValue.join((_b = (_a = _this.splitOptions) === null || _a === void 0 ? void 0 : _a.joinWith) !== null && _b !== void 0 ? _b : _this.defaultSplitOptions.joinWith)
                        : modelValue;
                }
            });
        }
        SplitStringDirective.prototype.splitAndTrimViewValue = function (viewValue) {
            var _a, _b;
            var separator = (_b = (_a = this.splitOptions) === null || _a === void 0 ? void 0 : _a.separator) !== null && _b !== void 0 ? _b : this.defaultSplitOptions.separator;
            return viewValue.split(separator).map(string.trim).filter(utils.checkValueIsFilled);
        };
        return SplitStringDirective;
    }());
    /** @nocollapse */ /** @nocollapse */ SplitStringDirective.ɵfac = function SplitStringDirective_Factory(t) { return new (t || SplitStringDirective)(i0__namespace.ɵɵdirectiveInject(i1__namespace$1.ControlValueInterceptor)); };
    /** @nocollapse */ /** @nocollapse */ SplitStringDirective.ɵdir = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineDirective({ type: SplitStringDirective, selectors: [["", "splitString", ""]], inputs: { splitOptions: "splitOptions" }, features: [i0__namespace.ɵɵProvidersFeature([i1$1.ControlValueInterceptor])] });
    (function () {
        (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(SplitStringDirective, [{
                type: i0.Directive,
                args: [{
                        selector: '[splitString]',
                        providers: [i1$1.ControlValueInterceptor]
                    }]
            }], function () { return [{ type: i1__namespace$1.ControlValueInterceptor }]; }, { splitOptions: [{
                    type: i0.Input
                }] });
    })();

    var SplitStringModule = /** @class */ (function () {
        function SplitStringModule() {
        }
        return SplitStringModule;
    }());
    /** @nocollapse */ /** @nocollapse */ SplitStringModule.ɵfac = function SplitStringModule_Factory(t) { return new (t || SplitStringModule)(); };
    /** @nocollapse */ /** @nocollapse */ SplitStringModule.ɵmod = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineNgModule({ type: SplitStringModule });
    /** @nocollapse */ /** @nocollapse */ SplitStringModule.ɵinj = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineInjector({ imports: [[common.CommonModule]] });
    (function () {
        (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(SplitStringModule, [{
                type: i0.NgModule,
                args: [{
                        declarations: [SplitStringDirective],
                        imports: [common.CommonModule],
                        exports: [SplitStringDirective]
                    }]
            }], null, null);
    })();
    (function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0__namespace.ɵɵsetNgModuleScope(SplitStringModule, { declarations: [SplitStringDirective], imports: [common.CommonModule], exports: [SplitStringDirective] }); })();

    var TrimInputDirective = /** @class */ (function () {
        function TrimInputDirective(el, ngControl) {
            this.el = el;
            this.ngControl = ngControl;
        }
        Object.defineProperty(TrimInputDirective.prototype, "formControlName", {
            set: function (name) {
                var _a, _b, _c, _d;
                this.previousValue = (_d = (_c = (_b = (_a = this.ngControl) === null || _a === void 0 ? void 0 : _a.control) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.get(this.name)) === null || _d === void 0 ? void 0 : _d.value;
                this.previousName = this.name;
                this.name = name;
            },
            enumerable: false,
            configurable: true
        });
        TrimInputDirective.prototype.ngOnInit = function () {
            this.trimValue();
        };
        TrimInputDirective.prototype.onEnter = function () {
            this.trimValue();
        };
        TrimInputDirective.prototype.onBlur = function () {
            this.trimValue();
        };
        TrimInputDirective.prototype.trimValue = function () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
            this.el.nativeElement.value = (_a = this.el.nativeElement.value) === null || _a === void 0 ? void 0 : _a.toString().trim();
            var control = ((_c = (_b = this.ngControl) === null || _b === void 0 ? void 0 : _b.control) === null || _c === void 0 ? void 0 : _c.parent)
                ? (_f = (_e = (_d = this.ngControl) === null || _d === void 0 ? void 0 : _d.control) === null || _e === void 0 ? void 0 : _e.parent) === null || _f === void 0 ? void 0 : _f.get(this.name)
                : (_h = (_g = this.ngControl) === null || _g === void 0 ? void 0 : _g.control) === null || _h === void 0 ? void 0 : _h.get(this.name);
            if (utils.isNotNil(control)) {
                var modelValue = (_l = ((_k = (_j = this.ngControl) === null || _j === void 0 ? void 0 : _j.value) !== null && _k !== void 0 ? _k : control === null || control === void 0 ? void 0 : control.value)) === null || _l === void 0 ? void 0 : _l.toString().trim();
                if (((_m = this.ngControl) === null || _m === void 0 ? void 0 : _m.control) === control) {
                    (_p = (_o = this.ngControl) === null || _o === void 0 ? void 0 : _o.control) === null || _p === void 0 ? void 0 : _p.setValue(modelValue, { emitEvent: false });
                }
                else {
                    control === null || control === void 0 ? void 0 : control.setValue(modelValue, { emitEvent: false });
                    (_r = (_q = control === null || control === void 0 ? void 0 : control.parent) === null || _q === void 0 ? void 0 : _q.get(this.previousName)) === null || _r === void 0 ? void 0 : _r.setValue(this.previousValue, { emitEvent: false });
                }
            }
        };
        return TrimInputDirective;
    }());
    /** @nocollapse */ /** @nocollapse */ TrimInputDirective.ɵfac = function TrimInputDirective_Factory(t) { return new (t || TrimInputDirective)(i0__namespace.ɵɵdirectiveInject(i0__namespace.ElementRef), i0__namespace.ɵɵdirectiveInject(i1__namespace.NgControl, 8)); };
    /** @nocollapse */ /** @nocollapse */ TrimInputDirective.ɵdir = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineDirective({ type: TrimInputDirective, selectors: [["", "trimInput", ""]], hostBindings: function TrimInputDirective_HostBindings(rf, ctx) {
            if (rf & 1) {
                i0__namespace.ɵɵlistener("keydown.enter", function TrimInputDirective_keydown_enter_HostBindingHandler() { return ctx.onEnter(); })("blur", function TrimInputDirective_blur_HostBindingHandler() { return ctx.onBlur(); });
            }
        }, inputs: { formControlName: "formControlName" } });
    (function () {
        (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(TrimInputDirective, [{
                type: i0.Directive,
                args: [{ selector: '[trimInput]' }]
            }], function () {
            return [{ type: i0__namespace.ElementRef }, { type: i1__namespace.NgControl, decorators: [{
                            type: i0.Optional
                        }] }];
        }, { formControlName: [{
                    type: i0.Input
                }], onEnter: [{
                    type: i0.HostListener,
                    args: ['keydown.enter']
                }], onBlur: [{
                    type: i0.HostListener,
                    args: ['blur']
                }] });
    })();

    var TrimInputModule = /** @class */ (function () {
        function TrimInputModule() {
        }
        return TrimInputModule;
    }());
    /** @nocollapse */ /** @nocollapse */ TrimInputModule.ɵfac = function TrimInputModule_Factory(t) { return new (t || TrimInputModule)(); };
    /** @nocollapse */ /** @nocollapse */ TrimInputModule.ɵmod = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineNgModule({ type: TrimInputModule });
    /** @nocollapse */ /** @nocollapse */ TrimInputModule.ɵinj = /** @pureOrBreakMyCode */ i0__namespace.ɵɵdefineInjector({ imports: [[common.CommonModule]] });
    (function () {
        (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(TrimInputModule, [{
                type: i0.NgModule,
                args: [{
                        imports: [common.CommonModule],
                        declarations: [TrimInputDirective],
                        exports: [TrimInputDirective]
                    }]
            }], null, null);
    })();
    (function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0__namespace.ɵɵsetNgModuleScope(TrimInputModule, { declarations: [TrimInputDirective], imports: [common.CommonModule], exports: [TrimInputDirective] }); })();

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

    exports.AMOUNT_FORMAT_OPTIONS = AMOUNT_FORMAT_OPTIONS;
    exports.AmountFormatDirective = AmountFormatDirective;
    exports.AmountFormatModule = AmountFormatModule;
    exports.ConvertCaseDirective = ConvertCaseDirective;
    exports.ConvertCaseModule = ConvertCaseModule;
    exports.DEFAULT_AMOUNT_OPTIONS = DEFAULT_AMOUNT_OPTIONS;
    exports.DisableControlDirective = DisableControlDirective;
    exports.DisableControlModule = DisableControlModule;
    exports.InitialFocusDirective = InitialFocusDirective;
    exports.InitialFocusModule = InitialFocusModule;
    exports.InputFilterConfig = InputFilterConfig;
    exports.InputFilterDirective = InputFilterDirective;
    exports.InputFilterModule = InputFilterModule;
    exports.SplitStringDirective = SplitStringDirective;
    exports.SplitStringModule = SplitStringModule;
    exports.TrimInputDirective = TrimInputDirective;
    exports.TrimInputModule = TrimInputModule;

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

})));
//# sourceMappingURL=angular-ru-cdk-directives.umd.js.map
