UNPKG

@ngez/core

Version:

A collection of minimalistic, easy-to-use and fully customizable Angular components, directives and services

1,422 lines (1,407 loc) 162 kB
import { ActiveDescendantKeyManager } from '@angular/cdk/a11y'; import { TemplatePortal } from '@angular/cdk/portal'; import { UP_ARROW, DOWN_ARROW, ENTER, TAB, ESCAPE } from '@angular/cdk/keycodes'; import { Overlay, ConnectionPositionPair } from '@angular/cdk/overlay'; import { faAngleUp, faAngleDown } from '@fortawesome/free-solid-svg-icons'; import { RouterLink, RouterLinkWithHref, Router, NavigationEnd } from '@angular/router'; import { HttpClient } from '@angular/common/http'; import { filter, map, tap } from 'rxjs/operators'; import { DomSanitizer } from '@angular/platform-browser'; import { faClone } from '@fortawesome/free-regular-svg-icons'; import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; import { __extends, __awaiter, __generator, __spread, __rest, __assign } from 'tslib'; import { DOCUMENT, CommonModule, isPlatformBrowser } from '@angular/common'; import { merge, ReplaySubject, of, fromEvent } from 'rxjs'; import { Component, Input, Output, EventEmitter, HostListener, ElementRef, TemplateRef, ViewChild, ContentChildren, Directive, ViewContainerRef, forwardRef, Optional, Inject, NgModule, ViewEncapsulation, PLATFORM_ID, Injectable, ContentChild, HostBinding, InjectionToken, Renderer2, Pipe } from '@angular/core'; import { NG_VALUE_ACCESSOR, FormGroup, NG_VALIDATORS } from '@angular/forms'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgEzAutocompleteOptionComponent = /** @class */ (function () { function NgEzAutocompleteOptionComponent(element) { this.element = element; this.disabled = false; this.selected = new EventEmitter(); this.active = false; } /** * @return {?} */ NgEzAutocompleteOptionComponent.prototype.setActiveStyles = /** * @return {?} */ function () { this.active = true; }; /** * @return {?} */ NgEzAutocompleteOptionComponent.prototype.setInactiveStyles = /** * @return {?} */ function () { this.active = false; }; /** * @return {?} */ NgEzAutocompleteOptionComponent.prototype.onSelect = /** * @return {?} */ function () { if (!this.disabled) this.selected.emit(this); }; /** * @return {?} */ NgEzAutocompleteOptionComponent.prototype.getOffsetHeight = /** * @return {?} */ function () { /** @type {?} */ var element = (/** @type {?} */ (this.element.nativeElement)); return element.getBoundingClientRect().height; }; NgEzAutocompleteOptionComponent.decorators = [ { type: Component, args: [{ selector: 'ngez-autocomplete-option', template: "<div [class.active]=\"active\" [class.disabled]=\"disabled\" class=\"ngez-autocomplete-option\">\r\n <ng-content></ng-content>\r\n</div>", styles: [".ngez-autocomplete-option{display:block;padding:8px;width:auto}.ngez-autocomplete-option.disabled{cursor:not-allowed}.ngez-autocomplete-option.active{background-color:#000b29;color:#fff}.ngez-autocomplete-option:hover:not(.disabled){background-color:#000b29;color:#fff;cursor:pointer}"] }] } ]; /** @nocollapse */ NgEzAutocompleteOptionComponent.ctorParameters = function () { return [ { type: ElementRef } ]; }; NgEzAutocompleteOptionComponent.propDecorators = { value: [{ type: Input }], disabled: [{ type: Input }], selected: [{ type: Output }], onSelect: [{ type: HostListener, args: ['click',] }] }; return NgEzAutocompleteOptionComponent; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ var defaultConfig = { maxHeight: 256 }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgEzAutocompleteComponent = /** @class */ (function () { function NgEzAutocompleteComponent() { this.defaultConfig = defaultConfig; this.opened = new EventEmitter(); this.closed = new EventEmitter(); } /** * @return {?} */ NgEzAutocompleteComponent.prototype.ngAfterViewInit = /** * @return {?} */ function () { this.keyboardEventsManager = new ActiveDescendantKeyManager(this.options).withWrap(true); }; /** * @return {?} */ NgEzAutocompleteComponent.prototype.reset = /** * @return {?} */ function () { this.keyboardEventsManager.setActiveItem(-1); }; /** * @param {?} event * @return {?} */ NgEzAutocompleteComponent.prototype.handleKeyDown = /** * @param {?} event * @return {?} */ function (event) { event.stopImmediatePropagation(); if (this.keyboardEventsManager) { if (event.keyCode === DOWN_ARROW || event.keyCode === UP_ARROW || event.keyCode === TAB) { // passing the event to key manager so we get a change fired this.keyboardEventsManager.onKeydown(event); return false; } else if (event.keyCode === ENTER) { // when we hit enter, the keyboardManager should call the selectItem method of the `ListItemComponent` this.keyboardEventsManager.activeItem.onSelect(); return false; } } }; /** * @return {?} */ NgEzAutocompleteComponent.prototype.getScrollTop = /** * @return {?} */ function () { /** @type {?} */ var index = this.keyboardEventsManager.activeItemIndex; /** @type {?} */ var option = this.keyboardEventsManager.activeItem; /** @type {?} */ var offset = this.options.toArray().slice(0, index + 1).reduce(function (offset, option) { return offset + option.getOffsetHeight(); }, 0); /** @type {?} */ var currentScrollPosition = this.panel.nativeElement.scrollTop; if (offset - option.getOffsetHeight() < currentScrollPosition) return offset - option.getOffsetHeight() + 3; /** @type {?} */ var optionHeight = option.getOffsetHeight(); /** @type {?} */ var panelHeight = this.panel.nativeElement.getBoundingClientRect().height; if (offset > currentScrollPosition + panelHeight) return Math.max(0, offset - panelHeight); return currentScrollPosition; }; /** * @return {?} */ NgEzAutocompleteComponent.prototype.setScrollTop = /** * @return {?} */ function () { if (!this.panel) return; /** @type {?} */ var scrollTop = this.getScrollTop(); this.panel.nativeElement.scrollTop = scrollTop; }; NgEzAutocompleteComponent.decorators = [ { type: Component, args: [{ selector: 'ngez-autocomplete', template: "<ng-template>\r\n <div #panel [style.max-height.px]=\"config && config.maxHeight ? config.maxHeight : defaultConfig.maxHeight\" class=\"ngez-autocomplete\">\r\n <div class=\"ngez-autocomplete-content\">\r\n <ng-content></ng-content>\r\n </div>\r\n </div>\r\n</ng-template>", host: { 'style.max-height.px': "config.maxHeight" }, styles: [".ngez-autocomplete{width:100%;background-color:#fff;overflow-x:hidden;box-shadow:0 2px 4px -1px rgba(0,0,0,.2),0 4px 5px 0 rgba(0,0,0,.14),0 1px 10px 0 rgba(0,0,0,.12)}.ngez-autocomplete-content{display:flex;flex-direction:column}"] }] } ]; NgEzAutocompleteComponent.propDecorators = { config: [{ type: Input }], opened: [{ type: Output }], closed: [{ type: Output }], template: [{ type: ViewChild, args: [TemplateRef,] }], panel: [{ type: ViewChild, args: ['panel',] }], options: [{ type: ContentChildren, args: [NgEzAutocompleteOptionComponent, { descendants: true },] }] }; return NgEzAutocompleteComponent; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgEzAutocompleteDirective = /** @class */ (function () { function NgEzAutocompleteDirective(element, overlay, viewContainerRef, document) { this.element = element; this.overlay = overlay; this.viewContainerRef = viewContainerRef; this.document = document; this.text$ = new ReplaySubject(1); this.isOpen = false; this.isDisabled = false; } /** * @return {?} */ NgEzAutocompleteDirective.prototype.ngOnDestroy = /** * @return {?} */ function () { if (this.overlayRef) this.overlayRef.dispose(); this.unsubscribe(); }; /** * @private * @param {?} e * @return {?} */ NgEzAutocompleteDirective.prototype.onValueChange = /** * @private * @param {?} e * @return {?} */ function (e) { this.text$.next(this.element.nativeElement.value); this.open(); }; /** * @private * @param {?} event * @return {?} */ NgEzAutocompleteDirective.prototype.onKeyDown = /** * @private * @param {?} event * @return {?} */ function (event) { /** @type {?} */ var keyCode = event.keyCode; if (keyCode === ESCAPE) { event.preventDefault(); } /** @type {?} */ var prevActiveItem = this.autocomplete.keyboardEventsManager.activeItem; /** @type {?} */ var isArrowKey = keyCode === UP_ARROW || keyCode === DOWN_ARROW; if (this.isOpen) { this.autocomplete.handleKeyDown(event); if (isArrowKey) { this.scrollToOption(); } } else if (isArrowKey) this.open(); }; /** * @return {?} */ NgEzAutocompleteDirective.prototype.open = /** * @return {?} */ function () { var _this = this; if (this.isOpen || this.isDisabled) return; this.isOpen = true; /** @type {?} */ var positions = [ new ConnectionPositionPair({ originX: 'start', originY: 'bottom' }, { overlayX: 'start', overlayY: 'top' }), new ConnectionPositionPair({ originX: 'start', originY: 'top' }, { overlayX: 'start', overlayY: 'bottom' }) ]; /** @type {?} */ var positionStrategy = this.overlay.position().flexibleConnectedTo(this.element) .withPush(true) .withPositions(positions); var _a = this.autocomplete, config = _a.config, template = _a.template; this.overlayRef = this.overlay.create({ disposeOnNavigation: true, hasBackdrop: false, scrollStrategy: this.overlay.scrollStrategies.close(), positionStrategy: positionStrategy, width: this.element.nativeElement.offsetWidth, maxHeight: config && config.maxHeight ? config.maxHeight : defaultConfig.maxHeight }); /** @type {?} */ var autocompletePortal = new TemplatePortal(template, this.viewContainerRef); this.overlayRef.attach(autocompletePortal); this.subscription = this.getAutocompleteClosingActions().subscribe(function (event) { _this.setValueAndClose(event); }); this.autocomplete.opened.emit(); }; /** * @return {?} */ NgEzAutocompleteDirective.prototype.close = /** * @return {?} */ function () { if (!this.isOpen) return; this.isOpen = false; this.autocomplete.closed.emit(); this.autocomplete.reset(); this.overlayRef.detach(); this.unsubscribe(); }; /** * @return {?} */ NgEzAutocompleteDirective.prototype.toggle = /** * @return {?} */ function () { this.isOpen ? this.close() : this.open(); }; /** * @param {?} value * @return {?} */ NgEzAutocompleteDirective.prototype.writeValue = /** * @param {?} value * @return {?} */ function (value) { this.setValue(value); }; /** * @param {?} fn * @return {?} */ NgEzAutocompleteDirective.prototype.registerOnChange = /** * @param {?} fn * @return {?} */ function (fn) { this.onChange = fn; }; /** * @param {?} fn * @return {?} */ NgEzAutocompleteDirective.prototype.registerOnTouched = /** * @param {?} fn * @return {?} */ function (fn) { this.onTouched = fn; }; /** * @param {?} isDisabled * @return {?} */ NgEzAutocompleteDirective.prototype.setDisabledState = /** * @param {?} isDisabled * @return {?} */ function (isDisabled) { this.element.nativeElement.disabled = isDisabled; this.isDisabled = isDisabled; }; /** * @private * @param {?} value * @return {?} */ NgEzAutocompleteDirective.prototype.setValue = /** * @private * @param {?} value * @return {?} */ function (value) { var config = this.autocomplete.config; /** @type {?} */ var text = value != null && config && config.labelExtractor ? config.labelExtractor(value) : value; this.element.nativeElement.value = text; }; /** * @private * @return {?} */ NgEzAutocompleteDirective.prototype.scrollToOption = /** * @private * @return {?} */ function () { this.autocomplete.setScrollTop(); }; /** * @private * @return {?} */ NgEzAutocompleteDirective.prototype.getAutocompleteClosingActions = /** * @private * @return {?} */ function () { return merge.apply(void 0, __spread(this.autocomplete.options.map(function (option) { return option.selected; }), [this.getOutsideClickStream(), this.autocomplete.keyboardEventsManager.tabOut, this.overlayRef.keydownEvents().pipe(filter(function (event) { return event.keyCode === ESCAPE; }))])).pipe(map(function (event) { return event instanceof NgEzAutocompleteOptionComponent ? event : null; })); }; /** * @private * @return {?} */ NgEzAutocompleteDirective.prototype.getOutsideClickStream = /** * @private * @return {?} */ function () { var _this = this; if (!this.document) return of(null); return fromEvent(this.document, 'click') .pipe(filter(function (event) { /** @type {?} */ var clickTarget = (/** @type {?} */ (event.target)); return clickTarget !== _this.element.nativeElement && (!!_this.overlayRef && !_this.overlayRef.overlayElement.contains(clickTarget)); })); }; /** * @private * @param {?} event * @return {?} */ NgEzAutocompleteDirective.prototype.setValueAndClose = /** * @private * @param {?} event * @return {?} */ function (event) { if (event) { this.element.nativeElement.focus(); this.setValue(event.value); this.onChange(event.value); } this.close(); }; /** * @private * @return {?} */ NgEzAutocompleteDirective.prototype.unsubscribe = /** * @private * @return {?} */ function () { if (this.subscription) this.subscription.unsubscribe(); }; NgEzAutocompleteDirective.decorators = [ { type: Directive, args: [{ selector: '[ngezAutocomplete]', exportAs: 'ngezAutocomplete', providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(function () { return NgEzAutocompleteDirective; }), multi: true }] },] } ]; /** @nocollapse */ NgEzAutocompleteDirective.ctorParameters = function () { return [ { type: ElementRef }, { type: Overlay }, { type: ViewContainerRef }, { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DOCUMENT,] }] } ]; }; NgEzAutocompleteDirective.propDecorators = { autocomplete: [{ type: Input, args: ['ngezAutocomplete',] }], onValueChange: [{ type: HostListener, args: ['input', ['$event'],] }], onKeyDown: [{ type: HostListener, args: ['keydown', ['$event'],] }] }; return NgEzAutocompleteDirective; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgEzAutocompleteModule = /** @class */ (function () { function NgEzAutocompleteModule() { } NgEzAutocompleteModule.decorators = [ { type: NgModule, args: [{ declarations: [ NgEzAutocompleteComponent, NgEzAutocompleteDirective, NgEzAutocompleteOptionComponent ], exports: [NgEzAutocompleteComponent, NgEzAutocompleteDirective, NgEzAutocompleteOptionComponent], entryComponents: [NgEzAutocompleteComponent], providers: [Overlay] },] } ]; return NgEzAutocompleteModule; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgEzNavListComponent = /** @class */ (function () { function NgEzNavListComponent(router) { this.router = router; this.routerLinkActiveOptions = { exact: false }; this.faAngleUp = faAngleUp; this.faAngleDown = faAngleDown; this.open = false; this.active = false; } /** * @return {?} */ NgEzNavListComponent.prototype.ngOnChanges = /** * @return {?} */ function () { this.update(); }; /** * @return {?} */ NgEzNavListComponent.prototype.ngOnInit = /** * @return {?} */ function () { var _this = this; this.navigationSubscription = this.router.events .pipe(filter(function (e) { return e instanceof NavigationEnd; })) .subscribe(function (e) { return _this.update(); }); }; /** * @return {?} */ NgEzNavListComponent.prototype.ngAfterContentInit = /** * @return {?} */ function () { var _this = this; this.linksQueryListChangesSubscription = this.links.changes.subscribe(function (c) { return _this.update(); }); this.linksWithHrefsQueryListChangesSubscription = this.linksWithHrefs.changes.subscribe(function (c) { return _this.update(); }); this.update(); }; /** * @return {?} */ NgEzNavListComponent.prototype.ngOnDestroy = /** * @return {?} */ function () { if (this.navigationSubscription) this.navigationSubscription.unsubscribe(); if (this.linksQueryListChangesSubscription) this.linksQueryListChangesSubscription.unsubscribe(); if (this.linksWithHrefsQueryListChangesSubscription) this.linksWithHrefsQueryListChangesSubscription.unsubscribe(); }; /** * @return {?} */ NgEzNavListComponent.prototype.onToggle = /** * @return {?} */ function () { this.open = !this.open; }; /** * @private * @return {?} */ NgEzNavListComponent.prototype.update = /** * @private * @return {?} */ function () { if (!this.links || !this.linksWithHrefs || !this.router.navigated) return; this.active = this.hasActiveLinks(); if (!this.open) this.open = this.active; }; /** * @private * @param {?} router * @return {?} */ NgEzNavListComponent.prototype.isLinkActive = /** * @private * @param {?} router * @return {?} */ function (router) { var _this = this; return function (link) { return router.isActive(link.urlTree, _this.exact); }; }; /** * @private * @return {?} */ NgEzNavListComponent.prototype.hasActiveLinks = /** * @private * @return {?} */ function () { return this.links.some(this.isLinkActive(this.router)) || this.linksWithHrefs.some(this.isLinkActive(this.router)); }; Object.defineProperty(NgEzNavListComponent.prototype, "exact", { get: /** * @private * @return {?} */ function () { return this.routerLinkActiveOptions ? this.routerLinkActiveOptions.exact : false; }, enumerable: true, configurable: true }); NgEzNavListComponent.decorators = [ { type: Component, args: [{ selector: 'ngez-nav-list', template: "<div class=\"ngez-nav-list\">\r\n <button (click)=\"onToggle()\" class=\"ngez-nav-list-header\" [class.active]=\"active\">\r\n <span>{{title}}</span>\r\n <fa-icon [icon]=\"open ? faAngleUp : faAngleDown\"></fa-icon>\r\n </button>\r\n <div *ngIf=\"open\" class=\"ngez-nav-list-content\">\r\n <ng-content></ng-content>\r\n </div>\r\n</div>", encapsulation: ViewEncapsulation.None, styles: [".ngez-nav-list{display:flex;flex-direction:column}.ngez-nav-list-header{display:flex;flex-direction:row;justify-content:space-between;border:none;background-color:transparent;margin-right:0;padding-left:6px;padding-top:8px;padding-bottom:10px;cursor:pointer;outline:0}.ngez-nav-list-header.active{color:#d70026}.ngez-nav-list-header:hover{color:#d70026;background-color:#f2f2f2}.ngez-nav-list-content{padding-left:18px}.ngez-nav-list-content a{display:flex;flex-direction:row;justify-content:space-between;border:none;background-color:transparent;padding:6px;text-decoration:none;cursor:pointer}.ngez-nav-list-content a.active{color:#d70026}.ngez-nav-list-content a:hover{background-color:#f2f2f2;color:#d70026}"] }] } ]; /** @nocollapse */ NgEzNavListComponent.ctorParameters = function () { return [ { type: Router } ]; }; NgEzNavListComponent.propDecorators = { title: [{ type: Input }], routerLinkActiveOptions: [{ type: Input }], lists: [{ type: ContentChildren, args: [NgEzNavListComponent,] }], links: [{ type: ContentChildren, args: [RouterLink,] }], linksWithHrefs: [{ type: ContentChildren, args: [RouterLinkWithHref,] }] }; return NgEzNavListComponent; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgEzNestedNavComponent = /** @class */ (function () { function NgEzNestedNavComponent() { } NgEzNestedNavComponent.decorators = [ { type: Component, args: [{ selector: 'ngez-nested-nav', template: "<ng-content></ng-content>", styles: [":host{display:block}"] }] } ]; return NgEzNestedNavComponent; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgEzNestedNavModule = /** @class */ (function () { function NgEzNestedNavModule() { } NgEzNestedNavModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule, FontAwesomeModule], declarations: [NgEzNestedNavComponent, NgEzNavListComponent], exports: [NgEzNestedNavComponent, NgEzNavListComponent] },] } ]; return NgEzNestedNavModule; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgEzOutsideClickDirective = /** @class */ (function () { function NgEzOutsideClickDirective(element, document, platformId) { this.element = element; this.document = document; this.platformId = platformId; this.outsideClick = new EventEmitter(); } /** * @return {?} */ NgEzOutsideClickDirective.prototype.ngOnInit = /** * @return {?} */ function () { var _this = this; if (!isPlatformBrowser(this.platformId)) return; setTimeout(function () { _this.subscription = fromEvent(_this.document, 'click') .pipe(filter(function (event) { /** @type {?} */ var clickTarget = (/** @type {?} */ (event.target)); return !_this.isOrContainsClickTarget(_this.element.nativeElement, clickTarget); })) .subscribe(function (event) { return _this.outsideClick.emit(event); }); }, 0); }; /** * @return {?} */ NgEzOutsideClickDirective.prototype.ngOnDestroy = /** * @return {?} */ function () { if (this.subscription) this.subscription.unsubscribe(); }; /** * @private * @param {?} element * @param {?} clickTarget * @return {?} */ NgEzOutsideClickDirective.prototype.isOrContainsClickTarget = /** * @private * @param {?} element * @param {?} clickTarget * @return {?} */ function (element, clickTarget) { return element == clickTarget || element.contains(clickTarget); }; NgEzOutsideClickDirective.decorators = [ { type: Directive, args: [{ selector: '[ngezOutsideClick]' },] } ]; /** @nocollapse */ NgEzOutsideClickDirective.ctorParameters = function () { return [ { type: ElementRef }, { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DOCUMENT,] }] }, { type: Object, decorators: [{ type: Inject, args: [PLATFORM_ID,] }] } ]; }; NgEzOutsideClickDirective.propDecorators = { outsideClick: [{ type: Output, args: ['ngezOutsideClick',] }] }; return NgEzOutsideClickDirective; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgEzOutsideClickModule = /** @class */ (function () { function NgEzOutsideClickModule() { } NgEzOutsideClickModule.decorators = [ { type: NgModule, args: [{ declarations: [NgEzOutsideClickDirective], exports: [NgEzOutsideClickDirective] },] } ]; return NgEzOutsideClickModule; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgEzReloadDirective = /** @class */ (function () { function NgEzReloadDirective() { this.reload = new EventEmitter(); } /** * @private * @return {?} */ NgEzReloadDirective.prototype.onClick = /** * @private * @return {?} */ function () { this.reload.emit(); }; NgEzReloadDirective.decorators = [ { type: Directive, args: [{ selector: '[ngezReload]' },] } ]; NgEzReloadDirective.propDecorators = { reload: [{ type: Output }], onClick: [{ type: HostListener, args: ['click',] }] }; return NgEzReloadDirective; }()); /** * @license * Copyright (C) 2006 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Split {\@code prettyPrint} into multiple timeouts so as not to interfere with * UI events. * If set to {\@code false}, {\@code prettyPrint()} is synchronous. * @type {?} */ var PR_SHOULD_USE_CONTINUATION = true; if (typeof window !== 'undefined') { window['PR_SHOULD_USE_CONTINUATION'] = PR_SHOULD_USE_CONTINUATION; } /** @type {?} */ var win = (typeof window !== 'undefined') ? window : {}; // Keyword lists for various languages. // We use things that coerce to strings to make them compact when minified // and to defeat aggressive optimizers that fold large string constants. /** @type {?} */ var FLOW_CONTROL_KEYWORDS = ["break,continue,do,else,for,if,return,while"]; /** @type {?} */ var C_KEYWORDS = [FLOW_CONTROL_KEYWORDS, "auto,case,char,const,default," + "double,enum,extern,float,goto,inline,int,long,register,restrict,short,signed," + "sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"]; /** @type {?} */ var COMMON_KEYWORDS = [C_KEYWORDS, "catch,class,delete,false,import," + "new,operator,private,protected,public,this,throw,true,try,typeof"]; /** @type {?} */ var CPP_KEYWORDS = [COMMON_KEYWORDS, "alignas,alignof,align_union,asm,axiom,bool," + "concept,concept_map,const_cast,constexpr,decltype,delegate," + "dynamic_cast,explicit,export,friend,generic,late_check," + "mutable,namespace,noexcept,noreturn,nullptr,property,reinterpret_cast,static_assert," + "static_cast,template,typeid,typename,using,virtual,where"]; /** @type {?} */ var JAVA_KEYWORDS = [COMMON_KEYWORDS, "abstract,assert,boolean,byte,extends,finally,final,implements,import," + "instanceof,interface,null,native,package,strictfp,super,synchronized," + "throws,transient"]; /** @type {?} */ var CSHARP_KEYWORDS = [COMMON_KEYWORDS, "abstract,add,alias,as,ascending,async,await,base,bool,by,byte,checked,decimal,delegate,descending," + "dynamic,event,finally,fixed,foreach,from,get,global,group,implicit,in,interface," + "internal,into,is,join,let,lock,null,object,out,override,orderby,params," + "partial,readonly,ref,remove,sbyte,sealed,select,set,stackalloc,string,select,uint,ulong," + "unchecked,unsafe,ushort,value,var,virtual,where,yield"]; /** @type {?} */ var COFFEE_KEYWORDS = "all,and,by,catch,class,else,extends,false,finally," + "for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then," + "throw,true,try,unless,until,when,while,yes"; /** @type {?} */ var JSCRIPT_KEYWORDS = [COMMON_KEYWORDS, "abstract,async,await,constructor,debugger,enum,eval,export,from,function," + "get,import,implements,instanceof,interface,let,null,of,set,undefined," + "var,with,yield,Infinity,NaN"]; /** @type {?} */ var PERL_KEYWORDS = "caller,delete,die,do,dump,elsif,eval,exit,foreach,for," + "goto,if,import,last,local,my,next,no,our,print,package,redo,require," + "sub,undef,unless,until,use,wantarray,while,BEGIN,END"; /** @type {?} */ var PYTHON_KEYWORDS = [FLOW_CONTROL_KEYWORDS, "and,as,assert,class,def,del," + "elif,except,exec,finally,from,global,import,in,is,lambda," + "nonlocal,not,or,pass,print,raise,try,with,yield," + "False,True,None"]; /** @type {?} */ var RUBY_KEYWORDS = [FLOW_CONTROL_KEYWORDS, "alias,and,begin,case,class," + "def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo," + "rescue,retry,self,super,then,true,undef,unless,until,when,yield," + "BEGIN,END"]; /** @type {?} */ var SH_KEYWORDS = [FLOW_CONTROL_KEYWORDS, "case,done,elif,esac,eval,fi," + "function,in,local,set,then,until"]; /** @type {?} */ var ALL_KEYWORDS = [ CPP_KEYWORDS, CSHARP_KEYWORDS, JAVA_KEYWORDS, JSCRIPT_KEYWORDS, PERL_KEYWORDS, PYTHON_KEYWORDS, RUBY_KEYWORDS, SH_KEYWORDS ]; /** @type {?} */ var C_TYPES = /^(DIR|FILE|array|vector|(de|priority_)?queue|(forward_)?list|stack|(const_)?(reverse_)?iterator|(unordered_)?(multi)?(set|map)|bitset|u?(int|float)\d*)\b/; // token style names. correspond to css classes /** * token style for a string literal * @const * @type {?} */ var PR_STRING = 'str'; /** * token style for a keyword * @const * @type {?} */ var PR_KEYWORD = 'kwd'; /** * token style for a comment * @const * @type {?} */ var PR_COMMENT = 'com'; /** * token style for a type * @const * @type {?} */ var PR_TYPE = 'typ'; /** * token style for a literal value. e.g. 1, null, true. * @const * @type {?} */ var PR_LITERAL = 'lit'; /** * token style for a punctuation string. * @const * @type {?} */ var PR_PUNCTUATION = 'pun'; /** * token style for plain text. * @const * @type {?} */ var PR_PLAIN = 'pln'; /** * token style for an sgml tag. * @const * @type {?} */ var PR_TAG = 'tag'; /** * token style for a markup declaration such as a DOCTYPE. * @const * @type {?} */ var PR_DECLARATION = 'dec'; /** * token style for embedded source. * @const * @type {?} */ var PR_SOURCE = 'src'; /** * token style for an sgml attribute name. * @const * @type {?} */ var PR_ATTRIB_NAME = 'atn'; /** * token style for an sgml attribute value. * @const * @type {?} */ var PR_ATTRIB_VALUE = 'atv'; /** @type {?} */ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|[!=]=?=?|\\#|%=?|&&?=?|\\(|\\*=?|[+\\-]=|->|\\/=?|::?|<<?=?|>>?>?=?|,|;|\\?|@|\\[|~|{|\\^\\^?=?|\\|\\|?=?|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*'; /** * @param {?} regexs * @return {?} */ function combinePrefixPatterns(regexs) { /** @type {?} */ var capturedGroupIndex = 0; /** @type {?} */ var needToFoldCase = false; /** @type {?} */ var ignoreCase = false; for (var i = 0, n = regexs.length; i < n; ++i) { /** @type {?} */ var regex = regexs[i]; if (regex.ignoreCase) { ignoreCase = true; } else if (/[a-z]/i.test(regex.source.replace(/\\u[0-9a-f]{4}|\\x[0-9a-f]{2}|\\[^ux]/gi, ''))) { needToFoldCase = true; ignoreCase = false; break; } } /** @type {?} */ var escapeCharToCodeUnit = { 'b': 8, 't': 9, 'n': 0xa, 'v': 0xb, 'f': 0xc, 'r': 0xd }; /** * @param {?} charsetPart * @return {?} */ function decodeEscape(charsetPart) { /** @type {?} */ var cc0 = charsetPart.charCodeAt(0); if (cc0 !== 92 /* \\ */) { return cc0; } /** @type {?} */ var c1 = charsetPart.charAt(1); cc0 = escapeCharToCodeUnit[c1]; if (cc0) { return cc0; } else if ('0' <= c1 && c1 <= '7') { return parseInt(charsetPart.substring(1), 8); } else if (c1 === 'u' || c1 === 'x') { return parseInt(charsetPart.substring(2), 16); } else { return charsetPart.charCodeAt(1); } } /** * @param {?} charCode * @return {?} */ function encodeEscape(charCode) { if (charCode < 0x20) { return (charCode < 0x10 ? '\\x0' : '\\x') + charCode.toString(16); } /** @type {?} */ var ch = String.fromCharCode(charCode); return (ch === '\\' || ch === '-' || ch === ']' || ch === '^') ? "\\" + ch : ch; } /** * @param {?} charSet * @return {?} */ function caseFoldCharset(charSet) { /** @type {?} */ var charsetParts = charSet.substring(1, charSet.length - 1).match(new RegExp('\\\\u[0-9A-Fa-f]{4}' + '|\\\\x[0-9A-Fa-f]{2}' + '|\\\\[0-3][0-7]{0,2}' + '|\\\\[0-7]{1,2}' + '|\\\\[\\s\\S]' + '|-' + '|[^-\\\\]', 'g')); /** @type {?} */ var ranges = []; /** @type {?} */ var inverse = charsetParts[0] === '^'; /** @type {?} */ var out = ['[']; if (inverse) { out.push('^'); } for (var i = inverse ? 1 : 0, n = charsetParts.length; i < n; ++i) { /** @type {?} */ var p = charsetParts[i]; if (/\\[bdsw]/i.test(p)) { // Don't muck with named groups. out.push(p); } else { /** @type {?} */ var start = decodeEscape(p); /** @type {?} */ var end; if (i + 2 < n && '-' === charsetParts[i + 1]) { end = decodeEscape(charsetParts[i + 2]); i += 2; } else { end = start; } ranges.push([start, end]); // If the range might intersect letters, then expand it. // This case handling is too simplistic. // It does not deal with non-latin case folding. // It works for latin source code identifiers though. if (!(end < 65 || start > 122)) { if (!(end < 65 || start > 90)) { ranges.push([Math.max(65, start) | 32, Math.min(end, 90) | 32]); } if (!(end < 97 || start > 122)) { ranges.push([Math.max(97, start) & ~32, Math.min(end, 122) & ~32]); } } } } // [[1, 10], [3, 4], [8, 12], [14, 14], [16, 16], [17, 17]] // -> [[1, 12], [14, 14], [16, 17]] ranges.sort(function (a, b) { return (a[0] - b[0]) || (b[1] - a[1]); }); /** @type {?} */ var consolidatedRanges = []; /** @type {?} */ var lastRange = []; for (var i = 0; i < ranges.length; ++i) { /** @type {?} */ var range = ranges[i]; if (range[0] <= lastRange[1] + 1) { lastRange[1] = Math.max(lastRange[1], range[1]); } else { consolidatedRanges.push(lastRange = range); } } for (var i = 0; i < consolidatedRanges.length; ++i) { /** @type {?} */ var range = consolidatedRanges[i]; out.push(encodeEscape(range[0])); if (range[1] > range[0]) { if (range[1] + 1 > range[0]) { out.push('-'); } out.push(encodeEscape(range[1])); } } out.push(']'); return out.join(''); } /** * @param {?} regex * @return {?} */ function allowAnywhereFoldCaseAndRenumberGroups(regex) { // Split into character sets, escape sequences, punctuation strings // like ('(', '(?:', ')', '^'), and runs of characters that do not // include any of the above. /** @type {?} */ var parts = regex.source.match(new RegExp('(?:' + '\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]' // a character set + '|\\\\u[A-Fa-f0-9]{4}' // a unicode escape + '|\\\\x[A-Fa-f0-9]{2}' // a hex escape + '|\\\\[0-9]+' // a back-reference or octal escape + '|\\\\[^ux0-9]' // other escape sequence + '|\\(\\?[:!=]' // start of a non-capturing group + '|[\\(\\)\\^]' // start/end of a group, or line start + '|[^\\x5B\\x5C\\(\\)\\^]+' // run of other characters + ')', 'g')); /** @type {?} */ var n = parts.length; // Maps captured group numbers to the number they will occupy in // the output or to -1 if that has not been determined, or to // undefined if they need not be capturing in the output. /** @type {?} */ var capturedGroups = []; // Walk over and identify back references to build the capturedGroups // mapping. for (var i = 0, groupIndex = 0; i < n; ++i) { /** @type {?} */ var p = parts[i]; if (p === '(') { // groups are 1-indexed, so max group index is count of '(' ++groupIndex; } else if ('\\' === p.charAt(0)) { /** @type {?} */ var decimalValue = +p.substring(1); if (decimalValue) { if (decimalValue <= groupIndex) { capturedGroups[decimalValue] = -1; } else { // Replace with an unambiguous escape sequence so that // an octal escape sequence does not turn into a backreference // to a capturing group from an earlier regex. parts[i] = encodeEscape(decimalValue); } } } } // Renumber groups and reduce capturing groups to non-capturing groups // where possible. for (var i = 1; i < capturedGroups.length; ++i) { if (-1 === capturedGroups[i]) { capturedGroups[i] = ++capturedGroupIndex; } } for (var i = 0, groupIndex = 0; i < n; ++i) { /** @type {?} */ var p = parts[i]; if (p === '(') { ++groupIndex; if (!capturedGroups[groupIndex]) { parts[i] = '(?:'; } } else if ('\\' === p.charAt(0)) { /** @type {?} */ var decimalValue = +p.substring(1); if (decimalValue && decimalValue <= groupIndex) { parts[i] = '\\' + capturedGroups[decimalValue]; } } } // Remove any prefix anchors so that the output will match anywhere. // ^^ really does mean an anchored match though. for (var i = 0; i < n; ++i) { if ('^' === parts[i] && '^' !== parts[i + 1]) { parts[i] = ''; } } // Expand letters to groups to handle mixing of case-sensitive and // case-insensitive patterns if necessary. if (regex.ignoreCase && needToFoldCase) { for (var i = 0; i < n; ++i) { /** @type {?} */ var p = parts[i]; /** @type {?} */ var ch0 = p.charAt(0); if (p.length >= 2 && ch0 === '[') { parts[i] = caseFoldCharset(p); } else if (ch0 !== '\\') { // TODO: handle letters in numeric escapes. parts[i] = p.replace(/[a-zA-Z]/g, function (ch) { /** @type {?} */ var cc = ch.charCodeAt(0); return '[' + String.fromCharCode(cc & ~32, cc | 32) + ']'; }); } } } return parts.join(''); } /** @type {?} */ var rewritten = []; for (var i = 0, n = regexs.length; i < n; ++i) { /** @type {?} */ var regex = regexs[i]; if (regex.global || regex.multiline) { throw new Error('' + regex); } rewritten.push('(?:' + allowAnywhereFoldCaseAndRenumberGroups(regex) + ')'); } return new RegExp(rewritten.join('|'), ignoreCase ? 'gi' : 'g'); } /** * @param {?} node * @param {?} isPreformatted * @return {?} */ function extractSourceSpans(node, isPreformatted) { /** @type {?} */ var nocode = /(?:^|\s)nocode(?:\s|$)/; /** @type {?} */ var chunks = []; /** @type {?} */ var length = 0; /** @type {?} */ var spans = []; /** @type {?} */ var k = 0; /** * @param {?} node * @return {?} */ function walk(node) { /** @type {?} */ var type = node.nodeType; if (type == 1) { // Element if (nocode.test(node.className)) { return; } for (var child = node.firstChild; child; child = child.nextSibling) { walk(child); } /** @type {?} */ var nodeName = node.nodeName.toLowerCase(); if ('br' === nodeName || 'li' === nodeName) { chunks[k] = '\n'; spans[k << 1] = length++; spans[(k++ << 1) | 1] = node; } } else if (type == 3 || type == 4) { // Text // Text /** @type {?} */ var text = node.nodeValue; if (text.length) { if (!isPreformatted) { text = text.replace(/[ \t\r\n]+/g, ' '); } else { text = text.replace(/\r\n?/g, '\n'); // Normalize newlines. } // TODO: handle tabs here? chunks[k] = text; spans[k << 1] = length; length += text.length; spans[(k++ << 1) | 1] = node; } } } walk(node); return { sourceCode: chunks.join('').replace(/\n$/, ''), spans: spans }; } /** * @param {?} sourceNode * @param {?} basePos * @param {?} sourceCode * @param {?} langHandler * @param {?} out * @return {?} */ function appendDecorations(sourceNode, basePos, sourceCode, langHandler, out) { if (!sourceCode) { return; } /** @type {?} */ var job = { sourceNode: sourceNode, pre: 1, langExtension: null, numberLines: null, sourceCode: sourceCode, spans: null, basePos: basePos, decorations: null }; langHandler(job); out.push.apply(out, job.decorations); } /** * @param {?} shortcutStylePatterns * @param {?} fallthroughStylePatterns * @return {?} */ function createSimpleLexer(shortcutStylePatterns, fallthroughStylePatterns) { /** @type {?} */ var shortcuts = {}; /** @type {?} */ var tokenizer; (function () { /** @type {?} */ var allPatterns = shortcutStylePatterns.concat(fallthroughStylePatterns); /** @type {?} */ var allRegexs = []; /** @type {?} */ var regexKeys = {}; for (var i = 0, n = allPatterns.length; i < n; ++i) { /** @type {?} */ var patternParts = allPatterns[i]; /** @type {?} */ var shortcutChars = patternParts[3]; if (shortcutChars) { for (var c = shortcutChars.length; --c >= 0;) { shortcuts[shortcutChars.charAt(c)] = patternParts; } } /** @type {?} */ var regex = patternParts[1]; /** @type {?} */ var k = '' + regex; if (!regexKeys.hasOwnProperty(k)) { allRegexs.push(regex); regexKeys[k] = null; } } allRegexs.push(/[\0-\uffff]/); tokenizer = combinePrefixPatterns(allRegexs); })(); /** @type {?} */ var nPatterns = fallthroughStylePatterns.length; /** @type {?} */ var decorate = function (job) { /** @type {?} */ var sourceCode = job.sourceCode; /** @type {?} */ var basePos = job.basePos; /** @type {?} */ var sourceNode = job.sourceNode; /** @type {?} */ var decorations = [basePos, PR_PLAIN]; /** @type {?} */ var pos = 0;