theme-lib
Version:
This is a simple example Angular Library published to npm.
1,664 lines (1,648 loc) • 1.73 MB
JavaScript
import { InjectionToken, Inject, Injectable, Optional, NgModule, NgZone, ApplicationRef, ComponentFactoryResolver, Directive, Injector, Component, Input, HostBinding, ChangeDetectionStrategy, ChangeDetectorRef, EventEmitter, Output, ElementRef, forwardRef, HostListener, TemplateRef, ViewChild, ViewChildren, ViewContainerRef, Type, Renderer2, PLATFORM_ID, Host, ContentChildren, defineInjectable, inject, ContentChild, LOCALE_ID } from '@angular/core';
import { __extends, __read, __spread, __values, __assign } from 'tslib';
import { ReplaySubject, Subject, Observable, fromEvent, merge, BehaviorSubject, of, forkJoin, interval, timer, defer } from 'rxjs';
import { map, filter, pairwise, distinctUntilChanged, startWith, share, debounceTime, delay, repeat, switchMap, takeUntil, takeWhile, take } from 'rxjs/operators';
import { CommonModule, isPlatformBrowser, DOCUMENT, Location, DatePipe, getLocaleFirstDayOfWeek, TranslationWidth, getLocaleMonthNames, FormStyle, getLocaleDayNames } from '@angular/common';
import { FormsModule, NG_VALUE_ACCESSOR, NG_VALIDATORS, Validators } from '@angular/forms';
import { RouterModule, NavigationEnd, Router, ActivatedRoute } from '@angular/router';
import { FocusTrap, FocusTrapFactory, InteractivityChecker } from '@angular/cdk/a11y';
import { CdkPortal, CdkPortalOutlet, ComponentPortal, DomPortalOutlet, PortalInjector, PortalModule, TemplatePortal } from '@angular/cdk/portal';
import { FlexibleConnectedPositionStrategy, Overlay, OverlayConfig, OverlayContainer, OverlayKeyboardDispatcher, OverlayModule, OverlayPositionBuilder, OverlayRef, ScrollStrategyOptions, ViewportRuler, GlobalPositionStrategy, ScrollDispatcher, BlockScrollStrategy } from '@angular/cdk/overlay';
import { Platform } from '@angular/cdk/platform';
import { Directionality } from '@angular/cdk/bidi';
import { animate, state, style, transition, trigger } from '@angular/animations';
import { DomSanitizer } from '@angular/platform-browser';
import 'intersection-observer';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var NB_THEME_OPTIONS = new InjectionToken('Nebular Theme Options');
/** @type {?} */
var NB_MEDIA_BREAKPOINTS = new InjectionToken('Nebular Media Breakpoints');
/** @type {?} */
var NB_BUILT_IN_JS_THEMES = new InjectionToken('Nebular Built-in JS Themes');
/** @type {?} */
var NB_JS_THEMES = new InjectionToken('Nebular JS Themes');
/*
* We're providing browser apis with tokens to improve testing capabilities.
* */
/** @type {?} */
var NB_WINDOW = new InjectionToken('Window');
/** @type {?} */
var NB_DOCUMENT = new InjectionToken('Document');
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NbColorHelper = /** @class */ (function () {
function NbColorHelper() {
}
/**
* @param {?} color
* @param {?} weight
* @return {?}
*/
NbColorHelper.shade = /**
* @param {?} color
* @param {?} weight
* @return {?}
*/
function (color, weight) {
return NbColorHelper.mix('#000000', color, weight);
};
/**
* @param {?} color
* @param {?} weight
* @return {?}
*/
NbColorHelper.tint = /**
* @param {?} color
* @param {?} weight
* @return {?}
*/
function (color, weight) {
return NbColorHelper.mix('#ffffff', color, weight);
};
/**
* @param {?} color1
* @param {?} color2
* @param {?} weight
* @return {?}
*/
NbColorHelper.mix = /**
* @param {?} color1
* @param {?} color2
* @param {?} weight
* @return {?}
*/
function (color1, color2, weight) {
/** @type {?} */
var d2h = function (d) { return d.toString(16); };
/** @type {?} */
var h2d = function (h) { return parseInt(h, 16); };
/** @type {?} */
var result = '#';
for (var i = 1; i < 7; i += 2) {
/** @type {?} */
var firstPart = h2d(color1.substr(i, 2));
/** @type {?} */
var secondPart = h2d(color2.substr(i, 2));
/** @type {?} */
var resultPart = d2h(Math.floor(secondPart + (firstPart - secondPart) * (weight / 100.0)));
result += ('0' + resultPart).slice(-2);
}
return result;
};
/**
* @param {?} hex
* @param {?} alpha
* @return {?}
*/
NbColorHelper.hexToRgbA = /**
* @param {?} hex
* @param {?} alpha
* @return {?}
*/
function (hex, alpha) {
/** @type {?} */
var c;
if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)) {
c = hex.substring(1).split('');
if (c.length === 3) {
c = [c[0], c[0], c[1], c[1], c[2], c[2]];
}
c = '0x' + c.join('');
return 'rgba(' + [(c >> 16) & 255, (c >> 8) & 255, c & 255].join(',') + ',' + alpha + ')';
}
throw new Error('Bad Hex');
};
return NbColorHelper;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var palette = {
primary: '#8a7fff',
success: '#40dc7e',
info: '#4ca6ff',
warning: '#ffa100',
danger: '#ff4c6a',
};
/** @type {?} */
var DEFAULT_THEME = {
name: 'default',
variables: {
fontMain: '"Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
fontSecondary: '"Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
bg: '#ffffff',
fg: '#a4abb3',
fgHeading: '#2a2a2a',
fgText: '#3b3b3b',
fgHighlight: '#41d974',
layoutBg: '#ebeff5',
separator: '#ebeef2',
primary: palette.primary,
success: palette.success,
info: palette.info,
warning: palette.warning,
danger: palette.danger,
primaryLight: NbColorHelper.tint(palette.primary, 15),
successLight: NbColorHelper.tint(palette.success, 15),
infoLight: NbColorHelper.tint(palette.info, 15),
warningLight: NbColorHelper.tint(palette.warning, 15),
dangerLight: NbColorHelper.tint(palette.danger, 15),
},
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var palette$1 = {
primary: '#7659ff',
success: '#00d977',
info: '#0088ff',
warning: '#ffa100',
danger: '#ff386a',
};
/** @type {?} */
var COSMIC_THEME = {
name: 'cosmic',
base: 'default',
variables: {
bg: '#3d3780',
fg: '#a1a1e5',
fgHeading: '#ffffff',
fgText: '#d1d1ff',
fgHighlight: '#00f9a6',
layoutBg: '#2f296b',
separator: '#342e73',
primary: palette$1.primary,
success: palette$1.success,
info: palette$1.info,
warning: palette$1.warning,
danger: palette$1.danger,
primaryLight: NbColorHelper.tint(palette$1.primary, 20),
successLight: NbColorHelper.tint(palette$1.success, 20),
infoLight: NbColorHelper.tint(palette$1.info, 20),
warningLight: NbColorHelper.tint(palette$1.warning, 20),
dangerLight: NbColorHelper.tint(palette$1.danger, 20),
},
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var palette$2 = {
primary: '#73a1ff',
success: '#5dcfe3',
info: '#ba7fec',
warning: '#ffa36b',
danger: '#ff6b83',
};
/** @type {?} */
var CORPORATE_THEME = {
name: 'corporate',
base: 'default',
variables: {
fg: '#f1f5f8',
bg: '#ffffff',
fgHeading: '#181818',
fgText: '#4b4b4b',
fgHighlight: '#a4abb3',
layoutBg: '#f1f5f8',
separator: '#cdd5dc',
primary: palette$2.primary,
success: palette$2.success,
info: palette$2.info,
warning: palette$2.warning,
danger: palette$2.danger,
primaryLight: NbColorHelper.tint(palette$2.primary, 15),
successLight: NbColorHelper.tint(palette$2.success, 15),
infoLight: NbColorHelper.tint(palette$2.info, 15),
warningLight: NbColorHelper.tint(palette$2.warning, 15),
dangerLight: NbColorHelper.tint(palette$2.danger, 15),
},
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var BUILT_IN_THEMES = [
DEFAULT_THEME,
COSMIC_THEME,
CORPORATE_THEME,
];
/*
* Js Themes registry - provides access to the JS themes' variables.
* Usually shouldn't be used directly, but through the NbThemeService class methods (getJsTheme).
*/
var NbJSThemesRegistry = /** @class */ (function () {
function NbJSThemesRegistry(builtInThemes, newThemes) {
if (newThemes === void 0) { newThemes = []; }
var _this = this;
this.themes = {};
/** @type {?} */
var themes = this.combineByNames(newThemes, builtInThemes);
themes.forEach(function (theme) {
_this.register(theme, theme.name, theme.base);
});
}
/*
* Registers a new JS theme
* @param config any
* @param themeName string
* @param baseTheme string
*/
/*
* Registers a new JS theme
* @param config any
* @param themeName string
* @param baseTheme string
*/
/**
* @param {?} config
* @param {?} themeName
* @param {?} baseTheme
* @return {?}
*/
NbJSThemesRegistry.prototype.register = /*
* Registers a new JS theme
* @param config any
* @param themeName string
* @param baseTheme string
*/
/**
* @param {?} config
* @param {?} themeName
* @param {?} baseTheme
* @return {?}
*/
function (config, themeName, baseTheme) {
/** @type {?} */
var base = this.has(baseTheme) ? this.get(baseTheme) : {};
this.themes[themeName] = this.mergeDeep({}, base, config);
};
/*
* Checks whether the theme is registered
* @param themeName
* @returns boolean
*/
/*
* Checks whether the theme is registered
* @param themeName
* @returns boolean
*/
/**
* @param {?} themeName
* @return {?}
*/
NbJSThemesRegistry.prototype.has = /*
* Checks whether the theme is registered
* @param themeName
* @returns boolean
*/
/**
* @param {?} themeName
* @return {?}
*/
function (themeName) {
return !!this.themes[themeName];
};
/*
* Return a theme
* @param themeName
* @returns NbJSThemeOptions
*/
/*
* Return a theme
* @param themeName
* @returns NbJSThemeOptions
*/
/**
* @param {?} themeName
* @return {?}
*/
NbJSThemesRegistry.prototype.get = /*
* Return a theme
* @param themeName
* @returns NbJSThemeOptions
*/
/**
* @param {?} themeName
* @return {?}
*/
function (themeName) {
if (!this.themes[themeName]) {
throw Error("NbThemeConfig: no theme '" + themeName + "' found registered.");
}
return JSON.parse(JSON.stringify(this.themes[themeName]));
};
/**
* @private
* @param {?} newThemes
* @param {?} oldThemes
* @return {?}
*/
NbJSThemesRegistry.prototype.combineByNames = /**
* @private
* @param {?} newThemes
* @param {?} oldThemes
* @return {?}
*/
function (newThemes, oldThemes) {
var _this = this;
if (newThemes) {
/** @type {?} */
var mergedThemes_1 = [];
newThemes.forEach(function (theme) {
/** @type {?} */
var sameOld = oldThemes.find(function (tm) { return tm.name === theme.name; })
|| (/** @type {?} */ ({}));
/** @type {?} */
var mergedTheme = _this.mergeDeep({}, sameOld, theme);
mergedThemes_1.push(mergedTheme);
});
oldThemes.forEach(function (theme) {
if (!mergedThemes_1.find(function (tm) { return tm.name === theme.name; })) {
mergedThemes_1.push(theme);
}
});
return mergedThemes_1;
}
return oldThemes;
};
/**
* @private
* @param {?} item
* @return {?}
*/
NbJSThemesRegistry.prototype.isObject = /**
* @private
* @param {?} item
* @return {?}
*/
function (item) {
return item && typeof item === 'object' && !Array.isArray(item);
};
// TODO: move to helpers
// TODO: move to helpers
/**
* @private
* @param {?} target
* @param {...?} sources
* @return {?}
*/
NbJSThemesRegistry.prototype.mergeDeep =
// TODO: move to helpers
/**
* @private
* @param {?} target
* @param {...?} sources
* @return {?}
*/
function (target) {
var sources = [];
for (var _i = 1; _i < arguments.length; _i++) {
sources[_i - 1] = arguments[_i];
}
var _a, _b;
if (!sources.length) {
return target;
}
/** @type {?} */
var source = sources.shift();
if (this.isObject(target) && this.isObject(source)) {
for (var key in source) {
if (this.isObject(source[key])) {
if (!target[key]) {
Object.assign(target, (_a = {}, _a[key] = {}, _a));
}
this.mergeDeep(target[key], source[key]);
}
else {
Object.assign(target, (_b = {}, _b[key] = source[key], _b));
}
}
}
return this.mergeDeep.apply(this, __spread([target], sources));
};
NbJSThemesRegistry.decorators = [
{ type: Injectable }
];
/** @nocollapse */
NbJSThemesRegistry.ctorParameters = function () { return [
{ type: Array, decorators: [{ type: Inject, args: [NB_BUILT_IN_JS_THEMES,] }] },
{ type: Array, decorators: [{ type: Inject, args: [NB_JS_THEMES,] }] }
]; };
return NbJSThemesRegistry;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var DEFAULT_MEDIA_BREAKPOINTS = [
{
name: 'xs',
width: 0,
},
{
name: 'is',
width: 400,
},
{
name: 'sm',
width: 576,
},
{
name: 'md',
width: 768,
},
{
name: 'lg',
width: 992,
},
{
name: 'xl',
width: 1200,
},
{
name: 'xxl',
width: 1400,
},
{
name: 'xxxl',
width: 1600,
},
];
/*
* Manages media breakpoints
*
* Provides access to available media breakpoints to convert window width to a configured breakpoint,
* e.g. 200px - *xs* breakpoint
*/
var NbMediaBreakpointsService = /** @class */ (function () {
function NbMediaBreakpointsService(breakpoints) {
this.breakpoints = breakpoints;
this.breakpointsMap = this.breakpoints.reduce(function (res, b) {
res[b.name] = b.width;
return res;
}, {});
}
/*
* Returns a configured breakpoint by width
* @param width number
* @returns {Z|{name: string, width: number}}
*/
/*
* Returns a configured breakpoint by width
* @param width number
* @returns {Z|{name: string, width: number}}
*/
/**
* @param {?} width
* @return {?}
*/
NbMediaBreakpointsService.prototype.getByWidth = /*
* Returns a configured breakpoint by width
* @param width number
* @returns {Z|{name: string, width: number}}
*/
/**
* @param {?} width
* @return {?}
*/
function (width) {
/** @type {?} */
var unknown = { name: 'unknown', width: width };
/** @type {?} */
var breakpoints = this.getBreakpoints();
return breakpoints
.find(function (point, index) {
/** @type {?} */
var next = breakpoints[index + 1];
return width >= point.width && (!next || width < next.width);
}) || unknown;
};
/*
* Returns a configured breakpoint by name
* @param name string
* @returns NbMediaBreakpoint
*/
/*
* Returns a configured breakpoint by name
* @param name string
* @returns NbMediaBreakpoint
*/
/**
* @param {?} name
* @return {?}
*/
NbMediaBreakpointsService.prototype.getByName = /*
* Returns a configured breakpoint by name
* @param name string
* @returns NbMediaBreakpoint
*/
/**
* @param {?} name
* @return {?}
*/
function (name) {
/** @type {?} */
var unknown = { name: 'unknown', width: NaN };
/** @type {?} */
var breakpoints = this.getBreakpoints();
return breakpoints.find(function (point) { return name === point.name; }) || unknown;
};
/*
* Returns a list of configured breakpoints for the theme
* @returns NbMediaBreakpoint[]
*/
/*
* Returns a list of configured breakpoints for the theme
* @returns NbMediaBreakpoint[]
*/
/**
* @return {?}
*/
NbMediaBreakpointsService.prototype.getBreakpoints = /*
* Returns a list of configured breakpoints for the theme
* @returns NbMediaBreakpoint[]
*/
/**
* @return {?}
*/
function () {
return this.breakpoints;
};
/*
* Returns a map of configured breakpoints for the theme
* @returns {[p: string]: number}
*/
/*
* Returns a map of configured breakpoints for the theme
* @returns {[p: string]: number}
*/
/**
* @return {?}
*/
NbMediaBreakpointsService.prototype.getBreakpointsMap = /*
* Returns a map of configured breakpoints for the theme
* @returns {[p: string]: number}
*/
/**
* @return {?}
*/
function () {
return this.breakpointsMap;
};
NbMediaBreakpointsService.decorators = [
{ type: Injectable }
];
/** @nocollapse */
NbMediaBreakpointsService.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: Inject, args: [NB_MEDIA_BREAKPOINTS,] }] }
]; };
return NbMediaBreakpointsService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/*
* Main Nebular service. Includes various helper methods.
*/
var NbThemeService = /** @class */ (function () {
function NbThemeService(options, breakpointService, jsThemesRegistry) {
this.options = options;
this.breakpointService = breakpointService;
this.jsThemesRegistry = jsThemesRegistry;
this.themeChanges$ = new ReplaySubject(1);
this.appendLayoutClass$ = new Subject();
this.removeLayoutClass$ = new Subject();
this.changeWindowWidth$ = new ReplaySubject(2);
if (options && options.name) {
this.changeTheme(options.name);
}
}
/*
* Change current application theme
* @param {string} name
*/
/*
* Change current application theme
* @param {string} name
*/
/**
* @param {?} name
* @return {?}
*/
NbThemeService.prototype.changeTheme = /*
* Change current application theme
* @param {string} name
*/
/**
* @param {?} name
* @return {?}
*/
function (name) {
this.themeChanges$.next({ name: name, previous: this.currentTheme });
this.currentTheme = name;
};
/**
* @param {?} width
* @return {?}
*/
NbThemeService.prototype.changeWindowWidth = /**
* @param {?} width
* @return {?}
*/
function (width) {
this.changeWindowWidth$.next(width);
};
/*
* Returns a theme object with variables (color/paddings/etc) on a theme change.
* Once subscribed - returns current theme.
*
* @returns {Observable<NbJSThemeOptions>}
*/
/*
* Returns a theme object with variables (color/paddings/etc) on a theme change.
* Once subscribed - returns current theme.
*
* @returns {Observable<NbJSThemeOptions>}
*/
/**
* @return {?}
*/
NbThemeService.prototype.getJsTheme = /*
* Returns a theme object with variables (color/paddings/etc) on a theme change.
* Once subscribed - returns current theme.
*
* @returns {Observable<NbJSThemeOptions>}
*/
/**
* @return {?}
*/
function () {
var _this = this;
return this.onThemeChange().pipe(map(function (theme) {
return _this.jsThemesRegistry.get(theme.name);
}));
};
/*
* Triggers media query breakpoint change
* Returns a pair where the first item is previous media breakpoint and the second item is current breakpoit.
* ```ts
* [{ name: 'xs', width: 0 }, { name: 'md', width: 768 }] // change from `xs` to `md`
* ```
* @returns {Observable<[NbMediaBreakpoint, NbMediaBreakpoint]>}
*/
/*
* Triggers media query breakpoint change
* Returns a pair where the first item is previous media breakpoint and the second item is current breakpoit.
* ```ts
* [{ name: 'xs', width: 0 }, { name: 'md', width: 768 }] // change from `xs` to `md`
* ```
* @returns {Observable<[NbMediaBreakpoint, NbMediaBreakpoint]>}
*/
/**
* @return {?}
*/
NbThemeService.prototype.onMediaQueryChange = /*
* Triggers media query breakpoint change
* Returns a pair where the first item is previous media breakpoint and the second item is current breakpoit.
* ```ts
* [{ name: 'xs', width: 0 }, { name: 'md', width: 768 }] // change from `xs` to `md`
* ```
* @returns {Observable<[NbMediaBreakpoint, NbMediaBreakpoint]>}
*/
/**
* @return {?}
*/
function () {
var _this = this;
return this.changeWindowWidth$
.pipe(startWith(undefined), pairwise(), map(function (_a) {
var _b = __read(_a, 2), prevWidth = _b[0], width = _b[1];
return [
_this.breakpointService.getByWidth(prevWidth),
_this.breakpointService.getByWidth(width),
];
}), filter(function (_a) {
var _b = __read(_a, 2), prevPoint = _b[0], point = _b[1];
return prevPoint.name !== point.name;
}), distinctUntilChanged(null, function (params) { return params[0].name + params[1].name; }), share());
};
/*
* Triggered when current theme is changed
* @returns {Observable<any>}
*/
/*
* Triggered when current theme is changed
* @returns {Observable<any>}
*/
/**
* @return {?}
*/
NbThemeService.prototype.onThemeChange = /*
* Triggered when current theme is changed
* @returns {Observable<any>}
*/
/**
* @return {?}
*/
function () {
return this.themeChanges$.pipe(share());
};
/*
* Append a class to nb-layout
* @param {string} className
*/
/*
* Append a class to nb-layout
* @param {string} className
*/
/**
* @param {?} className
* @return {?}
*/
NbThemeService.prototype.appendLayoutClass = /*
* Append a class to nb-layout
* @param {string} className
*/
/**
* @param {?} className
* @return {?}
*/
function (className) {
this.appendLayoutClass$.next(className);
};
/*
* Triggered when a new class is added to nb-layout through `appendLayoutClass` method
* @returns {Observable<any>}
*/
/*
* Triggered when a new class is added to nb-layout through `appendLayoutClass` method
* @returns {Observable<any>}
*/
/**
* @return {?}
*/
NbThemeService.prototype.onAppendLayoutClass = /*
* Triggered when a new class is added to nb-layout through `appendLayoutClass` method
* @returns {Observable<any>}
*/
/**
* @return {?}
*/
function () {
return this.appendLayoutClass$.pipe(share());
};
/*
* Removes a class from nb-layout
* @param {string} className
*/
/*
* Removes a class from nb-layout
* @param {string} className
*/
/**
* @param {?} className
* @return {?}
*/
NbThemeService.prototype.removeLayoutClass = /*
* Removes a class from nb-layout
* @param {string} className
*/
/**
* @param {?} className
* @return {?}
*/
function (className) {
this.removeLayoutClass$.next(className);
};
/*
* Triggered when a class is removed from nb-layout through `removeLayoutClass` method
* @returns {Observable<any>}
*/
/*
* Triggered when a class is removed from nb-layout through `removeLayoutClass` method
* @returns {Observable<any>}
*/
/**
* @return {?}
*/
NbThemeService.prototype.onRemoveLayoutClass = /*
* Triggered when a class is removed from nb-layout through `removeLayoutClass` method
* @returns {Observable<any>}
*/
/**
* @return {?}
*/
function () {
return this.removeLayoutClass$.pipe(share());
};
NbThemeService.decorators = [
{ type: Injectable }
];
/** @nocollapse */
NbThemeService.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: Inject, args: [NB_THEME_OPTIONS,] }] },
{ type: NbMediaBreakpointsService },
{ type: NbJSThemesRegistry }
]; };
return NbThemeService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/*
* Service to control the global page spinner.
*/
var NbSpinnerService = /** @class */ (function () {
function NbSpinnerService(document) {
this.document = document;
this.loaders = [];
this.selector = 'nb-global-spinner';
}
/*
* Appends new loader to the list of loader to be completed before
* spinner will be hidden
* @param method Promise<any>
*/
/*
* Appends new loader to the list of loader to be completed before
* spinner will be hidden
* @param method Promise<any>
*/
/**
* @param {?} method
* @return {?}
*/
NbSpinnerService.prototype.registerLoader = /*
* Appends new loader to the list of loader to be completed before
* spinner will be hidden
* @param method Promise<any>
*/
/**
* @param {?} method
* @return {?}
*/
function (method) {
this.loaders.push(method);
};
/*
* Clears the list of loader
*/
/*
* Clears the list of loader
*/
/**
* @return {?}
*/
NbSpinnerService.prototype.clear = /*
* Clears the list of loader
*/
/**
* @return {?}
*/
function () {
this.loaders = [];
};
/*
* Start the loader process, show spinnder and execute loaders
*/
/*
* Start the loader process, show spinnder and execute loaders
*/
/**
* @return {?}
*/
NbSpinnerService.prototype.load = /*
* Start the loader process, show spinnder and execute loaders
*/
/**
* @return {?}
*/
function () {
this.showSpinner();
this.executeAll();
};
/**
* @private
* @param {?=} done
* @return {?}
*/
NbSpinnerService.prototype.executeAll = /**
* @private
* @param {?=} done
* @return {?}
*/
function (done) {
var _this = this;
if (done === void 0) { done = function () { }; }
Promise.all(this.loaders).then(function (values) {
_this.hideSpinner();
done.call(null, values);
})
.catch(function (error) {
// TODO: Promise.reject
console.error(error);
});
};
// TODO is there any better way of doing this?
// TODO is there any better way of doing this?
/**
* @private
* @return {?}
*/
NbSpinnerService.prototype.showSpinner =
// TODO is there any better way of doing this?
/**
* @private
* @return {?}
*/
function () {
/** @type {?} */
var el = this.getSpinnerElement();
if (el) {
el.style['display'] = 'block';
}
};
/**
* @private
* @return {?}
*/
NbSpinnerService.prototype.hideSpinner = /**
* @private
* @return {?}
*/
function () {
/** @type {?} */
var el = this.getSpinnerElement();
if (el) {
el.style['display'] = 'none';
}
};
/**
* @private
* @return {?}
*/
NbSpinnerService.prototype.getSpinnerElement = /**
* @private
* @return {?}
*/
function () {
return this.document.getElementById(this.selector);
};
NbSpinnerService.decorators = [
{ type: Injectable }
];
/** @nocollapse */
NbSpinnerService.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: Inject, args: [NB_DOCUMENT,] }] }
]; };
return NbSpinnerService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @enum {string} */
var NbLayoutDirection = {
LTR: 'ltr',
RTL: 'rtl',
};
/*
* Layout direction setting injection token.
* */
/** @type {?} */
var NB_LAYOUT_DIRECTION = new InjectionToken('Layout direction');
/*
* Layout Direction Service.
* Allows to set or get layout direction and listen to its changes
*/
var NbLayoutDirectionService = /** @class */ (function () {
function NbLayoutDirectionService(direction) {
if (direction === void 0) { direction = NbLayoutDirection.LTR; }
this.direction = direction;
this.$directionChange = new ReplaySubject(1);
this.setDirection(direction);
}
/*
* Returns true if layout direction set to left to right.
* @returns boolean.
* */
/*
* Returns true if layout direction set to left to right.
* @returns boolean.
* */
/**
* @return {?}
*/
NbLayoutDirectionService.prototype.isLtr = /*
* Returns true if layout direction set to left to right.
* @returns boolean.
* */
/**
* @return {?}
*/
function () {
return this.direction === NbLayoutDirection.LTR;
};
/*
* Returns true if layout direction set to right to left.
* @returns boolean.
* */
/*
* Returns true if layout direction set to right to left.
* @returns boolean.
* */
/**
* @return {?}
*/
NbLayoutDirectionService.prototype.isRtl = /*
* Returns true if layout direction set to right to left.
* @returns boolean.
* */
/**
* @return {?}
*/
function () {
return this.direction === NbLayoutDirection.RTL;
};
/*
* Returns current layout direction.
* @returns NbLayoutDirection.
* */
/*
* Returns current layout direction.
* @returns NbLayoutDirection.
* */
/**
* @return {?}
*/
NbLayoutDirectionService.prototype.getDirection = /*
* Returns current layout direction.
* @returns NbLayoutDirection.
* */
/**
* @return {?}
*/
function () {
return this.direction;
};
/*
* Sets layout direction
* @param {NbLayoutDirection} direction
*/
/*
* Sets layout direction
* @param {NbLayoutDirection} direction
*/
/**
* @param {?} direction
* @return {?}
*/
NbLayoutDirectionService.prototype.setDirection = /*
* Sets layout direction
* @param {NbLayoutDirection} direction
*/
/**
* @param {?} direction
* @return {?}
*/
function (direction) {
this.direction = direction;
this.$directionChange.next(direction);
};
/*
* Triggered when direction was changed.
* @returns Observable<NbLayoutDirection>.
*/
/*
* Triggered when direction was changed.
* @returns Observable<NbLayoutDirection>.
*/
/**
* @return {?}
*/
NbLayoutDirectionService.prototype.onDirectionChange = /*
* Triggered when direction was changed.
* @returns Observable<NbLayoutDirection>.
*/
/**
* @return {?}
*/
function () {
return this.$directionChange.pipe(share());
};
NbLayoutDirectionService.decorators = [
{ type: Injectable }
];
/** @nocollapse */
NbLayoutDirectionService.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [NB_LAYOUT_DIRECTION,] }] }
]; };
return NbLayoutDirectionService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/*
* Layout scroll service. Provides information about current scroll position,
* as well as methods to update position of the scroll.
*
* The reason we added this service is that in Nebular there are two scroll modes:
* - the default mode when scroll is on body
* - and the `withScroll` mode, when scroll is removed from the body and moved to an element inside of the
* `nb-layout` component
*/
var NbLayoutScrollService = /** @class */ (function () {
function NbLayoutScrollService() {
this.scrollPositionReq$ = new Subject();
this.manualScroll$ = new Subject();
this.scroll$ = new Subject();
}
/*
* Returns scroll position
*
* @returns {Observable<NbScrollPosition>}
*/
/*
* Returns scroll position
*
* @returns {Observable<NbScrollPosition>}
*/
/**
* @return {?}
*/
NbLayoutScrollService.prototype.getPosition = /*
* Returns scroll position
*
* @returns {Observable<NbScrollPosition>}
*/
/**
* @return {?}
*/
function () {
var _this = this;
return Observable.create(function (observer) {
/** @type {?} */
var listener = new Subject();
listener.subscribe(observer);
_this.scrollPositionReq$.next({ listener: listener });
return function () { return listener.complete(); };
});
};
/*
* Sets scroll position
*
* @param {number} x
* @param {number} y
*/
/*
* Sets scroll position
*
* @param {number} x
* @param {number} y
*/
/**
* @param {?=} x
* @param {?=} y
* @return {?}
*/
NbLayoutScrollService.prototype.scrollTo = /*
* Sets scroll position
*
* @param {number} x
* @param {number} y
*/
/**
* @param {?=} x
* @param {?=} y
* @return {?}
*/
function (x, y) {
if (x === void 0) { x = null; }
if (y === void 0) { y = null; }
this.manualScroll$.next({ x: x, y: y });
};
/*
* Returns a stream of scroll events
*
* @returns {Observable<any>}
*/
/*
* Returns a stream of scroll events
*
* @returns {Observable<any>}
*/
/**
* @return {?}
*/
NbLayoutScrollService.prototype.onScroll = /*
* Returns a stream of scroll events
*
* @returns {Observable<any>}
*/
/**
* @return {?}
*/
function () {
return this.scroll$.pipe(share());
};
/*
* @private
* @returns Observable<NbScrollPosition>.
*/
/*
* @private
* @returns Observable<NbScrollPosition>.
*/
/**
* @return {?}
*/
NbLayoutScrollService.prototype.onManualScroll = /*
* @private
* @returns Observable<NbScrollPosition>.
*/
/**
* @return {?}
*/
function () {
return this.manualScroll$.pipe(share());
};
/*
* @private
* @returns {Subject<any>}
*/
/*
* @private
* @returns {Subject<any>}
*/
/**
* @return {?}
*/
NbLayoutScrollService.prototype.onGetPosition = /*
* @private
* @returns {Subject<any>}
*/
/**
* @return {?}
*/
function () {
return this.scrollPositionReq$;
};
/*
* @private
* @param {any} event
*/
/*
* @private
* @param {any} event
*/
/**
* @param {?} event
* @return {?}
*/
NbLayoutScrollService.prototype.fireScrollChange = /*
* @private
* @param {any} event
*/
/**
* @param {?} event
* @return {?}
*/
function (event) {
this.scroll$.next(event);
};
NbLayoutScrollService.decorators = [
{ type: Injectable }
];
return NbLayoutScrollService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/*
* Simple helper service to return Layout dimensions
* Depending of current Layout scroll mode (default or `withScroll` when scroll is moved to an element
* inside of the layout) corresponding dimensions will be returns - of `documentElement` in first case and
* `.scrollable-container` in the second.
*/
var NbLayoutRulerService = /** @class */ (function () {
function NbLayoutRulerService() {
this.contentDimensionsReq$ = new Subject();
}
/*
* Content dimensions
* @returns {Observable<NbLayoutDimensions>}
*/
/*
* Content dimensions
* @returns {Observable<NbLayoutDimensions>}
*/
/**
* @return {?}
*/
NbLayoutRulerService.prototype.getDimensions = /*
* Content dimensions
* @returns {Observable<NbLayoutDimensions>}
*/
/**
* @return {?}
*/
function () {
var _this = this;
return Observable.create(function (observer) {
/** @type {?} */
var listener = new Subject();
listener.subscribe(observer);
_this.contentDimensionsReq$.next({ listener: listener });
return function () { return listener.complete(); };
});
};
/*
* @private
* @returns {Subject<any>}
*/
/*
* @private
* @returns {Subject<any>}
*/
/**
* @return {?}
*/
NbLayoutRulerService.prototype.onGetDimensions = /*
* @private
* @returns {Subject<any>}
*/
/**
* @return {?}
*/
function () {
return this.contentDimensionsReq$;
};
NbLayoutRulerService.decorators = [
{ type: Injectable }
];
return NbLayoutRulerService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NbSharedModule = /** @class */ (function () {
function NbSharedModule() {
}
NbSharedModule.decorators = [
{ type: NgModule, args: [{
exports: [
CommonModule,
// TODO: probably we don't need FormsModule in SharedModule
FormsModule,
RouterModule,
],
},] }
];
return NbSharedModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/*
* Overrides angular cdk focus trap to keep restore functionality inside trap.
* */
var /*
* Overrides angular cdk focus trap to keep restore functionality inside trap.
* */
NbFocusTrap = /** @class */ (function (_super) {
__extends(NbFocusTrap, _super);
function NbFocusTrap(element, checker, ngZone, document, deferAnchors) {
var _this = _super.call(this, element, checker, ngZone, document, deferAnchors) || this;
_this.element = element;
_this.checker = checker;
_this.ngZone = ngZone;
_this.document = document;
_this.savePreviouslyFocusedElement();
return _this;
}
/**
* @return {?}
*/
NbFocusTrap.prototype.restoreFocus = /**
* @return {?}
*/
function () {
this.previouslyFocusedElement.focus();
this.destroy();
};
/**
* @return {?}
*/
NbFocusTrap.prototype.blurPreviouslyFocusedElement = /**
* @return {?}
*/
function () {
this.previouslyFocusedElement.blur();
};
/**
* @protected
* @return {?}
*/
NbFocusTrap.prototype.savePreviouslyFocusedElement = /**
* @protected
* @return {?}
*/
function () {
this.previouslyFocusedElement = (/** @type {?} */ (this.document.activeElement));
};
return NbFocusTrap;
}(FocusTrap));
var NbFocusTrapFactoryService = /** @class */ (function (_super) {
__extends(NbFocusTrapFactoryService, _super);
function NbFocusTrapFactoryService(checker, ngZone, document) {
var _this = _super.call(this, checker, ngZone, document) || this;
_this.checker = checker;
_this.ngZone = ngZone;
_this.document = document;
return _this;
}
/**
* @param {?} element
* @param {?=} deferCaptureElements
* @return {?}
*/
NbFocusTrapFactoryService.prototype.create = /**
* @param {?} element
* @param {?=} deferCaptureElements
* @return {?}
*/
function (element, deferCaptureElements) {
return new NbFocusTrap(element, this.checker, this.ngZone, this.document, deferCaptureElements);
};
NbFocusTrapFactoryService.decorators = [
{ type: Injectable }
];
/** @nocollapse */
NbFocusTrapFactoryService.ctorParameters = function () { return [
{ type: InteractivityChecker },
{ type: NgZone },
{ type: undefined, decorators: [{ type: Inject, args: [NB_DOCUMENT,] }] }
]; };
return NbFocusTrapFactoryService;
}(FocusTrapFactory));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NbA11yModule = /** @class */ (function () {
function NbA11yModule() {
}
/**
* @return {?}
*/
NbA11yModule.forRoot = /**
* @return {?}
*/
function () {
return (/** @type {?} */ ({
ngModule: NbA11yModule,
providers: [NbFocusTrapFactoryService],
}));
};
NbA11yModule.decorators = [
{ type: NgModule, args: [{},] }
];
return NbA11yModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NbPortalDirective = /** @class */ (function (_super) {
__extends(NbPortalDirective, _super);
function NbPortalDirective() {
return _super !== null && _super.apply(this, arguments) || this;
}
NbPortalDirective.decorators = [
{ type: Directive, args: [{ selector: '[nbPortal]' },] }
];
return NbPortalDirective;
}(CdkPortal));
var NbPortalOutletDirective = /** @class */ (function (_super) {
__extends(NbPortalOutletDirective, _super);
function NbPortalOutletDirective() {
return _super !== null && _super.apply(this, arguments) || this;
}
NbPortalOutletDirective.decorators = [
{ type: Directive, args: [{ selector: '[nbPortalOutlet]' },] }
];
return NbPortalOutletDirective;
}(CdkPortalOutlet));
/**
* @template T
*/
var /**
* @template T
*/
NbComponentPortal = /** @class */ (function (_super) {
__extends(NbComponentPortal, _super);
function NbComponentPortal(component, vcr, injector, cfr) {
var _this = _super.call(this, component, vcr, injector) || this;
_this.cfr = cfr;
return _this;
}
return NbComponentPortal;
}(ComponentPortal));
/*
* TODO remove after @angular/cdk@7.0.0 relased
* */
var /*
* TODO remove after @angular/cdk@7.0.0 relased
* */
NbDomPortalOutlet = /** @class */ (function (_super) {
__extends(NbDomPortalOutlet, _super);
function NbDomPortalOutlet(outletElement, componentFactoryResolver, appRef, defaultInjector) {
var _this = _super.call(this, outletElement, componentFactoryResolver, appRef, defaultInjector) || this;
_this.outletElement = outletElement;
_this.componentFactoryResolver = componentFactoryResolver;
_this.appRef = appRef;
_this.defaultInjector = defaultInjector;
return _this;
}
/*
* Attach the given ComponentPortal to DOM element using the ComponentFactoryResolver.
* @param portal Portal to be attached
* @returns Reference to the created component.
*/
/*
* Attach the given ComponentPortal to DOM element using the ComponentFactoryResolver.
* @param portal Portal to be attached
* @returns Reference to the created component.
*/
/**
* @template T
* @param {?} portal
* @return {?}
*/
NbDomPortalOutlet.prototype.attachComponentPortal = /*
* Attach the given ComponentPortal to DOM element using the ComponentFactoryResolver.
* @param portal Portal to be attached
* @returns Reference to the created component.
*/
/**
* @template T
* @param {?} portal
* @return {?}
*/
function (portal) {
var _this = this;
/** @type {?} */
var resolver = portal.cfr || this.componentFactoryResolver;
/** @type {?} */
var componentFactory = resolver.resolveComponentFactory(portal.component);
/** @type {?} */
var componentRef;
// If the portal specifies a ViewContainerRef, we will use that as the attachment point
// for the component (in terms of Angular's component tree, not rendering).
// When the ViewContainerRef is missing, we use the factory to create the component directly
// and then manually attach the view to the application.
if (portal.viewContainerRef) {
componentRef = portal.viewContainerRef.createComponent(componentFactory, portal.viewContainerRef.length, portal.injector || portal.viewContainerRef.parentInjector);
this.setDisposeFn(function () { return componentRef.destroy(); });
}
else {
componentRef = componentFactory.create(portal.injector || this.defaultInjector);
this.appRef.attachView(componentRef.hostView);
this.setDisposeFn(function () {
_this.appRef.detachView(componentRef.hostView);
componentRef.destroy();
});
}
// At this point the component has been instantiated, so we move it to the location in the DOM
// where we want it to be rendered.
this.outletElement.appendChild(this.getComponentRootNode(componentRef));
return componentRef;
};
/* Gets the root HTMLElement for an instantiated component. */
/* Gets the root HTMLElement for an instantiated component. */
/**
* @private
* @param {?} componentRef
* @return {?}
*/
NbDomPortalOutlet.prototype.getComponentRootNode = /* Gets the root HTMLElement for an instantiated