(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('rxjs/operators'), require('ng-zorro-antd/core/environments'), require('ng-zorro-antd/core/util'), require('@angular/common'), require('ng-zorro-antd/core/polyfill'), require('@angular/cdk/layout')) :
    typeof define === 'function' && define.amd ? define('ng-zorro-antd/core/services', ['exports', '@angular/core', 'rxjs', 'rxjs/operators', 'ng-zorro-antd/core/environments', 'ng-zorro-antd/core/util', '@angular/common', 'ng-zorro-antd/core/polyfill', '@angular/cdk/layout'], factory) :
    (global = global || self, factory((global['ng-zorro-antd'] = global['ng-zorro-antd'] || {}, global['ng-zorro-antd'].core = global['ng-zorro-antd'].core || {}, global['ng-zorro-antd'].core.services = {}), global.ng.core, global.rxjs, global.rxjs.operators, global['ng-zorro-antd'].core.environments, global['ng-zorro-antd'].core.util, global.ng.common, global['ng-zorro-antd'].core.polyfill, global.ng.cdk.layout));
}(this, (function (exports, i0, rxjs, operators, environments, util, i1, polyfill, i2) { 'use strict';

    /**
     * @fileoverview added by tsickle
     * Generated from: resize.ts
     * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    /** @type {?} */
    var NOOP = ( /**
     * @return {?}
     */function () { });
    var ɵ0 = NOOP;
    var NzResizeService = /** @class */ (function () {
        /**
         * @param {?} ngZone
         * @param {?} rendererFactory2
         */
        function NzResizeService(ngZone, rendererFactory2) {
            var _this = this;
            this.ngZone = ngZone;
            this.rendererFactory2 = rendererFactory2;
            this.resizeSource$ = new rxjs.Subject();
            this.listeners = 0;
            this.disposeHandle = NOOP;
            this.handler = ( /**
             * @return {?}
             */function () {
                _this.ngZone.run(( /**
                 * @return {?}
                 */function () {
                    _this.resizeSource$.next();
                }));
            });
            this.renderer = this.rendererFactory2.createRenderer(null, null);
        }
        /**
         * @return {?}
         */
        NzResizeService.prototype.subscribe = function () {
            var _this = this;
            this.registerListener();
            return this.resizeSource$.pipe(operators.auditTime(16), operators.finalize(( /**
             * @return {?}
             */function () { return _this.unregisterListener(); })));
        };
        /**
         * @return {?}
         */
        NzResizeService.prototype.unsubscribe = function () {
            this.unregisterListener();
        };
        /**
         * @private
         * @return {?}
         */
        NzResizeService.prototype.registerListener = function () {
            var _this = this;
            if (this.listeners === 0) {
                this.ngZone.runOutsideAngular(( /**
                 * @return {?}
                 */function () {
                    _this.disposeHandle = _this.renderer.listen('window', 'resize', _this.handler);
                }));
            }
            this.listeners += 1;
        };
        /**
         * @private
         * @return {?}
         */
        NzResizeService.prototype.unregisterListener = function () {
            this.listeners -= 1;
            if (this.listeners === 0) {
                this.disposeHandle();
                this.disposeHandle = NOOP;
            }
        };
        return NzResizeService;
    }());
    NzResizeService.decorators = [
        { type: i0.Injectable, args: [{
                    providedIn: 'root'
                },] }
    ];
    /** @nocollapse */
    NzResizeService.ctorParameters = function () { return [
        { type: i0.NgZone },
        { type: i0.RendererFactory2 }
    ]; };
    /** @nocollapse */ NzResizeService.ɵprov = i0.ɵɵdefineInjectable({ factory: function NzResizeService_Factory() { return new NzResizeService(i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i0.RendererFactory2)); }, token: NzResizeService, providedIn: "root" });
    if (false) {
        /**
         * @type {?}
         * @private
         */
        NzResizeService.prototype.resizeSource$;
        /**
         * @type {?}
         * @private
         */
        NzResizeService.prototype.listeners;
        /**
         * @type {?}
         * @private
         */
        NzResizeService.prototype.renderer;
        /**
         * @type {?}
         * @private
         */
        NzResizeService.prototype.disposeHandle;
        /**
         * @type {?}
         * @private
         */
        NzResizeService.prototype.handler;
        /**
         * @type {?}
         * @private
         */
        NzResizeService.prototype.ngZone;
        /**
         * @type {?}
         * @private
         */
        NzResizeService.prototype.rendererFactory2;
    }

    /**
     * @fileoverview added by tsickle
     * Generated from: singleton.ts
     * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    /**
     * @record
     */
    function SingletonRegistryItem() { }
    if (false) {
        /** @type {?} */
        SingletonRegistryItem.prototype.target;
    }
    /**
     * When running in test, singletons should not be destroyed. So we keep references of singletons
     * in this global variable.
     * @type {?}
     */
    var testSingleRegistry = new Map();
    /**
     * Some singletons should have life cycle that is same to Angular's. This service make sure that
     * those singletons get destroyed in HMR.
     */
    var NzSingletonService = /** @class */ (function () {
        function NzSingletonService() {
            /**
             * This registry is used to register singleton in dev mode.
             * So that singletons get destroyed when hot module reload happens.
             *
             * This works in prod mode too but with no specific effect.
             */
            this._singletonRegistry = new Map();
        }
        Object.defineProperty(NzSingletonService.prototype, "singletonRegistry", {
            /**
             * @private
             * @return {?}
             */
            get: function () {
                return environments.environment.isTestMode ? testSingleRegistry : this._singletonRegistry;
            },
            enumerable: false,
            configurable: true
        });
        /**
         * @param {?} key
         * @param {?} target
         * @return {?}
         */
        NzSingletonService.prototype.registerSingletonWithKey = function (key, target) {
            /** @type {?} */
            var alreadyHave = this.singletonRegistry.has(key);
            /** @type {?} */
            var item = alreadyHave ? ( /** @type {?} */(this.singletonRegistry.get(key))) : this.withNewTarget(target);
            if (!alreadyHave) {
                this.singletonRegistry.set(key, item);
            }
        };
        /**
         * @template T
         * @param {?} key
         * @return {?}
         */
        NzSingletonService.prototype.getSingletonWithKey = function (key) {
            return this.singletonRegistry.has(key) ? (( /** @type {?} */(( /** @type {?} */(this.singletonRegistry.get(key))).target))) : null;
        };
        /**
         * @private
         * @param {?} target
         * @return {?}
         */
        NzSingletonService.prototype.withNewTarget = function (target) {
            return {
                target: target
            };
        };
        return NzSingletonService;
    }());
    NzSingletonService.decorators = [
        { type: i0.Injectable, args: [{
                    providedIn: 'root'
                },] }
    ];
    /** @nocollapse */ NzSingletonService.ɵprov = i0.ɵɵdefineInjectable({ factory: function NzSingletonService_Factory() { return new NzSingletonService(); }, token: NzSingletonService, providedIn: "root" });
    if (false) {
        /**
         * This registry is used to register singleton in dev mode.
         * So that singletons get destroyed when hot module reload happens.
         *
         * This works in prod mode too but with no specific effect.
         * @type {?}
         * @private
         */
        NzSingletonService.prototype._singletonRegistry;
    }

    /**
     * @fileoverview added by tsickle
     * Generated from: drag.ts
     * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    /**
     * @record
     */
    function Point() { }
    if (false) {
        /** @type {?} */
        Point.prototype.x;
        /** @type {?} */
        Point.prototype.y;
    }
    /**
     * @record
     */
    function HandlerItem() { }
    if (false) {
        /**
         * @param {?} e
         * @return {?}
         */
        HandlerItem.prototype.handler = function (e) { };
        /**
         * @return {?}
         */
        HandlerItem.prototype.teardown = function () { };
    }
    /**
     * @param {?} event
     * @return {?}
     */
    function getPagePosition(event) {
        /** @type {?} */
        var e = util.getEventPosition(event);
        return {
            x: e.pageX,
            y: e.pageY
        };
    }
    /**
     * This module provide a global dragging service to other components.
     */
    var NzDragService = /** @class */ (function () {
        /**
         * @param {?} rendererFactory2
         */
        function NzDragService(rendererFactory2) {
            this.draggingThreshold = 5;
            this.currentDraggingSequence = null;
            this.currentStartingPoint = null;
            this.handleRegistry = new Set();
            this.renderer = rendererFactory2.createRenderer(null, null);
        }
        /**
         * @param {?} event
         * @return {?}
         */
        NzDragService.prototype.requestDraggingSequence = function (event) {
            var _this = this;
            if (!this.handleRegistry.size) {
                this.registerDraggingHandler(util.isTouchEvent(event));
            }
            // Complete last dragging sequence if a new target is dragged.
            if (this.currentDraggingSequence) {
                this.currentDraggingSequence.complete();
            }
            this.currentStartingPoint = getPagePosition(event);
            this.currentDraggingSequence = new rxjs.Subject();
            return this.currentDraggingSequence.pipe(operators.map(( /**
             * @param {?} e
             * @return {?}
             */function (e) {
                return {
                    x: e.pageX - ( /** @type {?} */(_this.currentStartingPoint)).x,
                    y: e.pageY - ( /** @type {?} */(_this.currentStartingPoint)).y
                };
            })), operators.filter(( /**
             * @param {?} e
             * @return {?}
             */function (e) { return Math.abs(e.x) > _this.draggingThreshold || Math.abs(e.y) > _this.draggingThreshold; })), operators.finalize(( /**
             * @return {?}
             */function () { return _this.teardownDraggingSequence(); })));
        };
        /**
         * @private
         * @param {?} isTouch
         * @return {?}
         */
        NzDragService.prototype.registerDraggingHandler = function (isTouch) {
            var _this = this;
            if (isTouch) {
                this.handleRegistry.add({
                    teardown: this.renderer.listen('document', 'touchmove', ( /**
                     * @param {?} e
                     * @return {?}
                     */function (e) {
                        if (_this.currentDraggingSequence) {
                            _this.currentDraggingSequence.next(e.touches[0] || e.changedTouches[0]);
                        }
                    }))
                });
                this.handleRegistry.add({
                    teardown: this.renderer.listen('document', 'touchend', ( /**
                     * @return {?}
                     */function () {
                        if (_this.currentDraggingSequence) {
                            _this.currentDraggingSequence.complete();
                        }
                    }))
                });
            }
            else {
                this.handleRegistry.add({
                    teardown: this.renderer.listen('document', 'mousemove', ( /**
                     * @param {?} e
                     * @return {?}
                     */function (/**
                     * @param {?} e
                     * @return {?}
                     */ e) {
                        if (_this.currentDraggingSequence) {
                            _this.currentDraggingSequence.next(e);
                        }
                    }))
                });
                this.handleRegistry.add({
                    teardown: this.renderer.listen('document', 'mouseup', ( /**
                     * @return {?}
                     */function () {
                        if (_this.currentDraggingSequence) {
                            _this.currentDraggingSequence.complete();
                        }
                    }))
                });
            }
        };
        /**
         * @private
         * @return {?}
         */
        NzDragService.prototype.teardownDraggingSequence = function () {
            this.currentDraggingSequence = null;
        };
        return NzDragService;
    }());
    NzDragService.decorators = [
        { type: i0.Injectable, args: [{
                    providedIn: 'root'
                },] }
    ];
    /** @nocollapse */
    NzDragService.ctorParameters = function () { return [
        { type: i0.RendererFactory2 }
    ]; };
    /** @nocollapse */ NzDragService.ɵprov = i0.ɵɵdefineInjectable({ factory: function NzDragService_Factory() { return new NzDragService(i0.ɵɵinject(i0.RendererFactory2)); }, token: NzDragService, providedIn: "root" });
    if (false) {
        /**
         * @type {?}
         * @private
         */
        NzDragService.prototype.draggingThreshold;
        /**
         * @type {?}
         * @private
         */
        NzDragService.prototype.currentDraggingSequence;
        /**
         * @type {?}
         * @private
         */
        NzDragService.prototype.currentStartingPoint;
        /**
         * @type {?}
         * @private
         */
        NzDragService.prototype.handleRegistry;
        /**
         * @type {?}
         * @private
         */
        NzDragService.prototype.renderer;
    }

    /**
     * @fileoverview added by tsickle
     * Generated from: scroll.ts
     * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    /**
     * @param {?} t
     * @param {?} b
     * @param {?} c
     * @param {?} d
     * @return {?}
     */
    function easeInOutCubic(t, b, c, d) {
        /** @type {?} */
        var cc = c - b;
        /** @type {?} */
        var tt = t / (d / 2);
        if (tt < 1) {
            return (cc / 2) * tt * tt * tt + b;
        }
        else {
            return (cc / 2) * ((tt -= 2) * tt * tt + 2) + b;
        }
    }
    var NzScrollService = /** @class */ (function () {
        /**
         * @param {?} doc
         */
        function NzScrollService(doc) {
            this.doc = doc;
        }
        /**
         * Set the position of the scroll bar of `el`.
         * @param {?} el
         * @param {?=} topValue
         * @return {?}
         */
        NzScrollService.prototype.setScrollTop = function (el, topValue) {
            if (topValue === void 0) { topValue = 0; }
            if (el === window) {
                this.doc.body.scrollTop = topValue;
                ( /** @type {?} */(this.doc.documentElement)).scrollTop = topValue;
            }
            else {
                (( /** @type {?} */(el))).scrollTop = topValue;
            }
        };
        /**
         * Get position of `el` against window.
         * @param {?} el
         * @return {?}
         */
        NzScrollService.prototype.getOffset = function (el) {
            /** @type {?} */
            var ret = {
                top: 0,
                left: 0
            };
            if (!el || !el.getClientRects().length) {
                return ret;
            }
            /** @type {?} */
            var rect = el.getBoundingClientRect();
            if (rect.width || rect.height) {
                /** @type {?} */
                var doc = ( /** @type {?} */(el.ownerDocument)).documentElement;
                ret.top = rect.top - ( /** @type {?} */(doc)).clientTop;
                ret.left = rect.left - ( /** @type {?} */(doc)).clientLeft;
            }
            else {
                ret.top = rect.top;
                ret.left = rect.left;
            }
            return ret;
        };
        /**
         * Get the position of the scoll bar of `el`.
         * @param {?=} el
         * @param {?=} top
         * @return {?}
         */
        // TODO: remove '| Window' as the fallback already happens here
        NzScrollService.prototype.getScroll = function (el, top) {
            if (top === void 0) { top = true; }
            /** @type {?} */
            var target = el ? el : window;
            /** @type {?} */
            var prop = top ? 'pageYOffset' : 'pageXOffset';
            /** @type {?} */
            var method = top ? 'scrollTop' : 'scrollLeft';
            /** @type {?} */
            var isWindow = target === window;
            // @ts-ignore
            /** @type {?} */
            var ret = isWindow ? target[prop] : target[method];
            if (isWindow && typeof ret !== 'number') {
                ret = ( /** @type {?} */(this.doc.documentElement))[method];
            }
            return ret;
        };
        /**
         * Scroll `el` to some position with animation.
         *
         * @param {?} containerEl container, `window` by default
         * @param {?=} targetTopValue Scroll to `top`, 0 by default
         * @param {?=} easing Transition curve, `easeInOutCubic` by default
         * @param {?=} callback callback invoked when transition is done
         * @return {?}
         */
        NzScrollService.prototype.scrollTo = function (containerEl, targetTopValue, easing, callback) {
            var _this = this;
            if (targetTopValue === void 0) { targetTopValue = 0; }
            /** @type {?} */
            var target = containerEl ? containerEl : window;
            /** @type {?} */
            var scrollTop = this.getScroll(target);
            /** @type {?} */
            var startTime = Date.now();
            /** @type {?} */
            var frameFunc = ( /**
             * @return {?}
             */function () {
                /** @type {?} */
                var timestamp = Date.now();
                /** @type {?} */
                var time = timestamp - startTime;
                _this.setScrollTop(target, (easing || easeInOutCubic)(time, scrollTop, targetTopValue, 450));
                if (time < 450) {
                    polyfill.reqAnimFrame(frameFunc);
                }
                else {
                    if (callback) {
                        callback();
                    }
                }
            });
            polyfill.reqAnimFrame(frameFunc);
        };
        return NzScrollService;
    }());
    NzScrollService.decorators = [
        { type: i0.Injectable, args: [{
                    providedIn: 'root'
                },] }
    ];
    /** @nocollapse */
    NzScrollService.ctorParameters = function () { return [
        { type: undefined, decorators: [{ type: i0.Inject, args: [i1.DOCUMENT,] }] }
    ]; };
    /** @nocollapse */ NzScrollService.ɵprov = i0.ɵɵdefineInjectable({ factory: function NzScrollService_Factory() { return new NzScrollService(i0.ɵɵinject(i1.DOCUMENT)); }, token: NzScrollService, providedIn: "root" });
    if (false) {
        /**
         * @type {?}
         * @private
         */
        NzScrollService.prototype.doc;
    }

    /**
     * @fileoverview added by tsickle
     * Generated from: breakpoint.ts
     * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    /** @enum {string} */
    var NzBreakpointEnum = {
        xxl: "xxl",
        xl: "xl",
        lg: "lg",
        md: "md",
        sm: "sm",
        xs: "xs",
    };
    /** @type {?} */
    var gridResponsiveMap = {
        xs: '(max-width: 575px)',
        sm: '(min-width: 576px)',
        md: '(min-width: 768px)',
        lg: '(min-width: 992px)',
        xl: '(min-width: 1200px)',
        xxl: '(min-width: 1600px)'
    };
    /** @type {?} */
    var siderResponsiveMap = {
        xs: '(max-width: 479.98px)',
        sm: '(max-width: 575.98px)',
        md: '(max-width: 767.98px)',
        lg: '(max-width: 991.98px)',
        xl: '(max-width: 1199.98px)',
        xxl: '(max-width: 1599.98px)'
    };
    var NzBreakpointService = /** @class */ (function () {
        /**
         * @param {?} resizeService
         * @param {?} mediaMatcher
         */
        function NzBreakpointService(resizeService, mediaMatcher) {
            this.resizeService = resizeService;
            this.mediaMatcher = mediaMatcher;
            this.resizeService.subscribe().subscribe(( /**
             * @return {?}
             */function () { }));
        }
        /**
         * @param {?} breakpointMap
         * @param {?=} fullMap
         * @return {?}
         */
        NzBreakpointService.prototype.subscribe = function (breakpointMap, fullMap) {
            var _this = this;
            if (fullMap) {
                /** @type {?} */
                var get = ( /**
                 * @return {?}
                 */function () { return _this.matchMedia(breakpointMap, true); });
                return this.resizeService.subscribe().pipe(operators.map(get), operators.startWith(get()), operators.distinctUntilChanged(( /**
                 * @param {?} x
                 * @param {?} y
                 * @return {?}
                 */function (x, y) { return x[0] === y[0]; })), operators.map(( /**
                 * @param {?} x
                 * @return {?}
                 */function (/**
                 * @param {?} x
                 * @return {?}
                 */ x) { return x[1]; })));
            }
            else {
                /** @type {?} */
                var get = ( /**
                 * @return {?}
                 */function () { return _this.matchMedia(breakpointMap); });
                return this.resizeService.subscribe().pipe(operators.map(get), operators.startWith(get()), operators.distinctUntilChanged());
            }
        };
        /**
         * @private
         * @param {?} breakpointMap
         * @param {?=} fullMap
         * @return {?}
         */
        NzBreakpointService.prototype.matchMedia = function (breakpointMap, fullMap) {
            var _this = this;
            /** @type {?} */
            var bp = NzBreakpointEnum.md;
            /** @type {?} */
            var breakpointBooleanMap = {};
            Object.keys(breakpointMap).map(( /**
             * @param {?} breakpoint
             * @return {?}
             */function (/**
             * @param {?} breakpoint
             * @return {?}
             */ breakpoint) {
                /** @type {?} */
                var castBP = ( /** @type {?} */(breakpoint));
                /** @type {?} */
                var matched = _this.mediaMatcher.matchMedia(gridResponsiveMap[castBP]).matches;
                breakpointBooleanMap[( /** @type {?} */(breakpoint))] = matched;
                if (matched) {
                    bp = castBP;
                }
            }));
            if (fullMap) {
                return [bp, ( /** @type {?} */(breakpointBooleanMap))];
            }
            else {
                return bp;
            }
        };
        return NzBreakpointService;
    }());
    NzBreakpointService.decorators = [
        { type: i0.Injectable, args: [{
                    providedIn: 'root'
                },] }
    ];
    /** @nocollapse */
    NzBreakpointService.ctorParameters = function () { return [
        { type: NzResizeService },
        { type: i2.MediaMatcher }
    ]; };
    /** @nocollapse */ NzBreakpointService.ɵprov = i0.ɵɵdefineInjectable({ factory: function NzBreakpointService_Factory() { return new NzBreakpointService(i0.ɵɵinject(NzResizeService), i0.ɵɵinject(i2.MediaMatcher)); }, token: NzBreakpointService, providedIn: "root" });
    if (false) {
        /**
         * @type {?}
         * @private
         */
        NzBreakpointService.prototype.resizeService;
        /**
         * @type {?}
         * @private
         */
        NzBreakpointService.prototype.mediaMatcher;
    }

    /**
     * @fileoverview added by tsickle
     * Generated from: public-api.ts
     * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */

    /**
     * @fileoverview added by tsickle
     * Generated from: ng-zorro-antd-core-services.ts
     * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */

    exports.NzBreakpointEnum = NzBreakpointEnum;
    exports.NzBreakpointService = NzBreakpointService;
    exports.NzDragService = NzDragService;
    exports.NzResizeService = NzResizeService;
    exports.NzScrollService = NzScrollService;
    exports.NzSingletonService = NzSingletonService;
    exports.gridResponsiveMap = gridResponsiveMap;
    exports.siderResponsiveMap = siderResponsiveMap;

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

})));
//# sourceMappingURL=ng-zorro-antd-core-services.umd.js.map
