1 | /**
|
2 | * @license Angular v9.0.4
|
3 | * (c) 2010-2020 Google LLC. https://angular.io/
|
4 | * License: MIT
|
5 | */
|
6 |
|
7 | import { InjectionToken, Injectable, ɵɵdefineInjectable, ɵɵinject, Inject, Optional, EventEmitter, ɵfindLocaleData, ɵLocaleDataIndex, ɵgetLocaleCurrencyCode, ɵgetLocalePluralCase, LOCALE_ID, ɵregisterLocaleData, ɵisListLikeIterable, ɵstringify, Directive, IterableDiffers, KeyValueDiffers, ElementRef, Renderer2, Input, NgModuleRef, ComponentFactoryResolver, ViewContainerRef, isDevMode, TemplateRef, Host, Attribute, ɵlooseIdentical, WrappedValue, ɵisPromise, ɵisObservable, Pipe, ChangeDetectorRef, DEFAULT_CURRENCY_CODE, NgModule, Version, ErrorHandler } from '@angular/core';
|
8 |
|
9 | /**
|
10 | * @fileoverview added by tsickle
|
11 | * Generated from: packages/common/src/dom_adapter.ts
|
12 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
13 | */
|
14 | /**
|
15 | * @license
|
16 | * Copyright Google Inc. All Rights Reserved.
|
17 | *
|
18 | * Use of this source code is governed by an MIT-style license that can be
|
19 | * found in the LICENSE file at https://angular.io/license
|
20 | */
|
21 | /** @type {?} */
|
22 | let _DOM = (/** @type {?} */ (null));
|
23 | /**
|
24 | * @return {?}
|
25 | */
|
26 | function getDOM() {
|
27 | return _DOM;
|
28 | }
|
29 | /**
|
30 | * @param {?} adapter
|
31 | * @return {?}
|
32 | */
|
33 | function setDOM(adapter) {
|
34 | _DOM = adapter;
|
35 | }
|
36 | /**
|
37 | * @param {?} adapter
|
38 | * @return {?}
|
39 | */
|
40 | function setRootDomAdapter(adapter) {
|
41 | if (!_DOM) {
|
42 | _DOM = adapter;
|
43 | }
|
44 | }
|
45 | /* tslint:disable:requireParameterType */
|
46 | /**
|
47 | * Provides DOM operations in an environment-agnostic way.
|
48 | *
|
49 | * \@security Tread carefully! Interacting with the DOM directly is dangerous and
|
50 | * can introduce XSS risks.
|
51 | * @abstract
|
52 | */
|
53 | class DomAdapter {
|
54 | }
|
55 | if (false) {
|
56 | /**
|
57 | * @abstract
|
58 | * @param {?} el
|
59 | * @param {?} name
|
60 | * @return {?}
|
61 | */
|
62 | DomAdapter.prototype.getProperty = function (el, name) { };
|
63 | /**
|
64 | * @abstract
|
65 | * @param {?} el
|
66 | * @param {?} evt
|
67 | * @return {?}
|
68 | */
|
69 | DomAdapter.prototype.dispatchEvent = function (el, evt) { };
|
70 | /**
|
71 | * @abstract
|
72 | * @param {?} error
|
73 | * @return {?}
|
74 | */
|
75 | DomAdapter.prototype.log = function (error) { };
|
76 | /**
|
77 | * @abstract
|
78 | * @param {?} error
|
79 | * @return {?}
|
80 | */
|
81 | DomAdapter.prototype.logGroup = function (error) { };
|
82 | /**
|
83 | * @abstract
|
84 | * @return {?}
|
85 | */
|
86 | DomAdapter.prototype.logGroupEnd = function () { };
|
87 | /**
|
88 | * @abstract
|
89 | * @param {?} el
|
90 | * @return {?}
|
91 | */
|
92 | DomAdapter.prototype.remove = function (el) { };
|
93 | /**
|
94 | * @abstract
|
95 | * @param {?} tagName
|
96 | * @param {?=} doc
|
97 | * @return {?}
|
98 | */
|
99 | DomAdapter.prototype.createElement = function (tagName, doc) { };
|
100 | /**
|
101 | * @abstract
|
102 | * @return {?}
|
103 | */
|
104 | DomAdapter.prototype.createHtmlDocument = function () { };
|
105 | /**
|
106 | * @abstract
|
107 | * @return {?}
|
108 | */
|
109 | DomAdapter.prototype.getDefaultDocument = function () { };
|
110 | /**
|
111 | * @abstract
|
112 | * @param {?} node
|
113 | * @return {?}
|
114 | */
|
115 | DomAdapter.prototype.isElementNode = function (node) { };
|
116 | /**
|
117 | * @abstract
|
118 | * @param {?} node
|
119 | * @return {?}
|
120 | */
|
121 | DomAdapter.prototype.isShadowRoot = function (node) { };
|
122 | /**
|
123 | * @abstract
|
124 | * @param {?} el
|
125 | * @param {?} evt
|
126 | * @param {?} listener
|
127 | * @return {?}
|
128 | */
|
129 | DomAdapter.prototype.onAndCancel = function (el, evt, listener) { };
|
130 | /**
|
131 | * @abstract
|
132 | * @return {?}
|
133 | */
|
134 | DomAdapter.prototype.supportsDOMEvents = function () { };
|
135 | /**
|
136 | * @abstract
|
137 | * @param {?} doc
|
138 | * @param {?} target
|
139 | * @return {?}
|
140 | */
|
141 | DomAdapter.prototype.getGlobalEventTarget = function (doc, target) { };
|
142 | /**
|
143 | * @abstract
|
144 | * @return {?}
|
145 | */
|
146 | DomAdapter.prototype.getHistory = function () { };
|
147 | /**
|
148 | * @abstract
|
149 | * @return {?}
|
150 | */
|
151 | DomAdapter.prototype.getLocation = function () { };
|
152 | /**
|
153 | * This is the ambient Location definition, NOT Location from \@angular/common.
|
154 | * @abstract
|
155 | * @param {?} doc
|
156 | * @return {?}
|
157 | */
|
158 | DomAdapter.prototype.getBaseHref = function (doc) { };
|
159 | /**
|
160 | * @abstract
|
161 | * @return {?}
|
162 | */
|
163 | DomAdapter.prototype.resetBaseElement = function () { };
|
164 | /**
|
165 | * @abstract
|
166 | * @return {?}
|
167 | */
|
168 | DomAdapter.prototype.getUserAgent = function () { };
|
169 | /**
|
170 | * @abstract
|
171 | * @return {?}
|
172 | */
|
173 | DomAdapter.prototype.performanceNow = function () { };
|
174 | /**
|
175 | * @abstract
|
176 | * @return {?}
|
177 | */
|
178 | DomAdapter.prototype.supportsCookies = function () { };
|
179 | /**
|
180 | * @abstract
|
181 | * @param {?} name
|
182 | * @return {?}
|
183 | */
|
184 | DomAdapter.prototype.getCookie = function (name) { };
|
185 | }
|
186 |
|
187 | /**
|
188 | * @fileoverview added by tsickle
|
189 | * Generated from: packages/common/src/dom_tokens.ts
|
190 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
191 | */
|
192 | /**
|
193 | * A DI Token representing the main rendering context. In a browser this is the DOM Document.
|
194 | *
|
195 | * Note: Document might not be available in the Application Context when Application and Rendering
|
196 | * Contexts are not the same (e.g. when running the application in a Web Worker).
|
197 | *
|
198 | * \@publicApi
|
199 | * @type {?}
|
200 | */
|
201 | const DOCUMENT = new InjectionToken('DocumentToken');
|
202 |
|
203 | /**
|
204 | * @fileoverview added by tsickle
|
205 | * Generated from: packages/common/src/location/platform_location.ts
|
206 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
207 | */
|
208 | /**
|
209 | * This class should not be used directly by an application developer. Instead, use
|
210 | * {\@link Location}.
|
211 | *
|
212 | * `PlatformLocation` encapsulates all calls to DOM apis, which allows the Router to be platform
|
213 | * agnostic.
|
214 | * This means that we can have different implementation of `PlatformLocation` for the different
|
215 | * platforms that angular supports. For example, `\@angular/platform-browser` provides an
|
216 | * implementation specific to the browser environment, while `\@angular/platform-webworker` provides
|
217 | * one suitable for use with web workers.
|
218 | *
|
219 | * The `PlatformLocation` class is used directly by all implementations of {\@link LocationStrategy}
|
220 | * when they need to interact with the DOM apis like pushState, popState, etc...
|
221 | *
|
222 | * {\@link LocationStrategy} in turn is used by the {\@link Location} service which is used directly
|
223 | * by the {\@link Router} in order to navigate between routes. Since all interactions between {\@link
|
224 | * Router} /
|
225 | * {\@link Location} / {\@link LocationStrategy} and DOM apis flow through the `PlatformLocation`
|
226 | * class they are all platform independent.
|
227 | *
|
228 | * \@publicApi
|
229 | * @abstract
|
230 | */
|
231 | class PlatformLocation {
|
232 | }
|
233 | PlatformLocation.decorators = [
|
234 | { type: Injectable, args: [{
|
235 | providedIn: 'platform',
|
236 | // See #23917
|
237 | useFactory: useBrowserPlatformLocation
|
238 | },] }
|
239 | ];
|
240 | /** @nocollapse */ PlatformLocation.ɵprov = ɵɵdefineInjectable({ factory: useBrowserPlatformLocation, token: PlatformLocation, providedIn: "platform" });
|
241 | if (false) {
|
242 | /**
|
243 | * @abstract
|
244 | * @return {?}
|
245 | */
|
246 | PlatformLocation.prototype.getBaseHrefFromDOM = function () { };
|
247 | /**
|
248 | * @abstract
|
249 | * @return {?}
|
250 | */
|
251 | PlatformLocation.prototype.getState = function () { };
|
252 | /**
|
253 | * @abstract
|
254 | * @param {?} fn
|
255 | * @return {?}
|
256 | */
|
257 | PlatformLocation.prototype.onPopState = function (fn) { };
|
258 | /**
|
259 | * @abstract
|
260 | * @param {?} fn
|
261 | * @return {?}
|
262 | */
|
263 | PlatformLocation.prototype.onHashChange = function (fn) { };
|
264 | /**
|
265 | * @abstract
|
266 | * @return {?}
|
267 | */
|
268 | PlatformLocation.prototype.href = function () { };
|
269 | /**
|
270 | * @abstract
|
271 | * @return {?}
|
272 | */
|
273 | PlatformLocation.prototype.protocol = function () { };
|
274 | /**
|
275 | * @abstract
|
276 | * @return {?}
|
277 | */
|
278 | PlatformLocation.prototype.hostname = function () { };
|
279 | /**
|
280 | * @abstract
|
281 | * @return {?}
|
282 | */
|
283 | PlatformLocation.prototype.port = function () { };
|
284 | /**
|
285 | * @abstract
|
286 | * @return {?}
|
287 | */
|
288 | PlatformLocation.prototype.pathname = function () { };
|
289 | /**
|
290 | * @abstract
|
291 | * @return {?}
|
292 | */
|
293 | PlatformLocation.prototype.search = function () { };
|
294 | /**
|
295 | * @abstract
|
296 | * @return {?}
|
297 | */
|
298 | PlatformLocation.prototype.hash = function () { };
|
299 | /**
|
300 | * @abstract
|
301 | * @param {?} state
|
302 | * @param {?} title
|
303 | * @param {?} url
|
304 | * @return {?}
|
305 | */
|
306 | PlatformLocation.prototype.replaceState = function (state, title, url) { };
|
307 | /**
|
308 | * @abstract
|
309 | * @param {?} state
|
310 | * @param {?} title
|
311 | * @param {?} url
|
312 | * @return {?}
|
313 | */
|
314 | PlatformLocation.prototype.pushState = function (state, title, url) { };
|
315 | /**
|
316 | * @abstract
|
317 | * @return {?}
|
318 | */
|
319 | PlatformLocation.prototype.forward = function () { };
|
320 | /**
|
321 | * @abstract
|
322 | * @return {?}
|
323 | */
|
324 | PlatformLocation.prototype.back = function () { };
|
325 | }
|
326 | /**
|
327 | * @return {?}
|
328 | */
|
329 | function useBrowserPlatformLocation() {
|
330 | return ɵɵinject(BrowserPlatformLocation);
|
331 | }
|
332 | /**
|
333 | * \@description
|
334 | * Indicates when a location is initialized.
|
335 | *
|
336 | * \@publicApi
|
337 | * @type {?}
|
338 | */
|
339 | const LOCATION_INITIALIZED = new InjectionToken('Location Initialized');
|
340 | /**
|
341 | * \@description
|
342 | * A serializable version of the event from `onPopState` or `onHashChange`
|
343 | *
|
344 | * \@publicApi
|
345 | * @record
|
346 | */
|
347 | function LocationChangeEvent() { }
|
348 | if (false) {
|
349 | /** @type {?} */
|
350 | LocationChangeEvent.prototype.type;
|
351 | /** @type {?} */
|
352 | LocationChangeEvent.prototype.state;
|
353 | }
|
354 | /**
|
355 | * \@publicApi
|
356 | * @record
|
357 | */
|
358 | function LocationChangeListener() { }
|
359 | /**
|
360 | * `PlatformLocation` encapsulates all of the direct calls to platform APIs.
|
361 | * This class should not be used directly by an application developer. Instead, use
|
362 | * {\@link Location}.
|
363 | */
|
364 | class BrowserPlatformLocation extends PlatformLocation {
|
365 | /**
|
366 | * @param {?} _doc
|
367 | */
|
368 | constructor(_doc) {
|
369 | super();
|
370 | this._doc = _doc;
|
371 | this._init();
|
372 | }
|
373 | // This is moved to its own method so that `MockPlatformLocationStrategy` can overwrite it
|
374 | /**
|
375 | * \@internal
|
376 | * @return {?}
|
377 | */
|
378 | _init() {
|
379 | ((/** @type {?} */ (this))).location = getDOM().getLocation();
|
380 | this._history = getDOM().getHistory();
|
381 | }
|
382 | /**
|
383 | * @return {?}
|
384 | */
|
385 | getBaseHrefFromDOM() { return (/** @type {?} */ (getDOM().getBaseHref(this._doc))); }
|
386 | /**
|
387 | * @param {?} fn
|
388 | * @return {?}
|
389 | */
|
390 | onPopState(fn) {
|
391 | getDOM().getGlobalEventTarget(this._doc, 'window').addEventListener('popstate', fn, false);
|
392 | }
|
393 | /**
|
394 | * @param {?} fn
|
395 | * @return {?}
|
396 | */
|
397 | onHashChange(fn) {
|
398 | getDOM().getGlobalEventTarget(this._doc, 'window').addEventListener('hashchange', fn, false);
|
399 | }
|
400 | /**
|
401 | * @return {?}
|
402 | */
|
403 | get href() { return this.location.href; }
|
404 | /**
|
405 | * @return {?}
|
406 | */
|
407 | get protocol() { return this.location.protocol; }
|
408 | /**
|
409 | * @return {?}
|
410 | */
|
411 | get hostname() { return this.location.hostname; }
|
412 | /**
|
413 | * @return {?}
|
414 | */
|
415 | get port() { return this.location.port; }
|
416 | /**
|
417 | * @return {?}
|
418 | */
|
419 | get pathname() { return this.location.pathname; }
|
420 | /**
|
421 | * @return {?}
|
422 | */
|
423 | get search() { return this.location.search; }
|
424 | /**
|
425 | * @return {?}
|
426 | */
|
427 | get hash() { return this.location.hash; }
|
428 | /**
|
429 | * @param {?} newPath
|
430 | * @return {?}
|
431 | */
|
432 | set pathname(newPath) { this.location.pathname = newPath; }
|
433 | /**
|
434 | * @param {?} state
|
435 | * @param {?} title
|
436 | * @param {?} url
|
437 | * @return {?}
|
438 | */
|
439 | pushState(state, title, url) {
|
440 | if (supportsState()) {
|
441 | this._history.pushState(state, title, url);
|
442 | }
|
443 | else {
|
444 | this.location.hash = url;
|
445 | }
|
446 | }
|
447 | /**
|
448 | * @param {?} state
|
449 | * @param {?} title
|
450 | * @param {?} url
|
451 | * @return {?}
|
452 | */
|
453 | replaceState(state, title, url) {
|
454 | if (supportsState()) {
|
455 | this._history.replaceState(state, title, url);
|
456 | }
|
457 | else {
|
458 | this.location.hash = url;
|
459 | }
|
460 | }
|
461 | /**
|
462 | * @return {?}
|
463 | */
|
464 | forward() { this._history.forward(); }
|
465 | /**
|
466 | * @return {?}
|
467 | */
|
468 | back() { this._history.back(); }
|
469 | /**
|
470 | * @return {?}
|
471 | */
|
472 | getState() { return this._history.state; }
|
473 | }
|
474 | BrowserPlatformLocation.decorators = [
|
475 | { type: Injectable, args: [{
|
476 | providedIn: 'platform',
|
477 | // See #23917
|
478 | useFactory: createBrowserPlatformLocation,
|
479 | },] }
|
480 | ];
|
481 | /** @nocollapse */
|
482 | BrowserPlatformLocation.ctorParameters = () => [
|
483 | { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] }
|
484 | ];
|
485 | /** @nocollapse */ BrowserPlatformLocation.ɵprov = ɵɵdefineInjectable({ factory: createBrowserPlatformLocation, token: BrowserPlatformLocation, providedIn: "platform" });
|
486 | if (false) {
|
487 | /** @type {?} */
|
488 | BrowserPlatformLocation.prototype.location;
|
489 | /**
|
490 | * @type {?}
|
491 | * @private
|
492 | */
|
493 | BrowserPlatformLocation.prototype._history;
|
494 | /**
|
495 | * @type {?}
|
496 | * @private
|
497 | */
|
498 | BrowserPlatformLocation.prototype._doc;
|
499 | }
|
500 | /**
|
501 | * @return {?}
|
502 | */
|
503 | function supportsState() {
|
504 | return !!window.history.pushState;
|
505 | }
|
506 | /**
|
507 | * @return {?}
|
508 | */
|
509 | function createBrowserPlatformLocation() {
|
510 | return new BrowserPlatformLocation(ɵɵinject(DOCUMENT));
|
511 | }
|
512 |
|
513 | /**
|
514 | * @fileoverview added by tsickle
|
515 | * Generated from: packages/common/src/private_export.ts
|
516 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
517 | */
|
518 |
|
519 | /**
|
520 | * @fileoverview added by tsickle
|
521 | * Generated from: packages/common/src/location/util.ts
|
522 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
523 | */
|
524 | /**
|
525 | * @license
|
526 | * Copyright Google Inc. All Rights Reserved.
|
527 | *
|
528 | * Use of this source code is governed by an MIT-style license that can be
|
529 | * found in the LICENSE file at https://angular.io/license
|
530 | */
|
531 | /**
|
532 | * Joins two parts of a URL with a slash if needed.
|
533 | *
|
534 | * @param {?} start URL string
|
535 | * @param {?} end URL string
|
536 | *
|
537 | *
|
538 | * @return {?} The joined URL string.
|
539 | */
|
540 | function joinWithSlash(start, end) {
|
541 | if (start.length == 0) {
|
542 | return end;
|
543 | }
|
544 | if (end.length == 0) {
|
545 | return start;
|
546 | }
|
547 | /** @type {?} */
|
548 | let slashes = 0;
|
549 | if (start.endsWith('/')) {
|
550 | slashes++;
|
551 | }
|
552 | if (end.startsWith('/')) {
|
553 | slashes++;
|
554 | }
|
555 | if (slashes == 2) {
|
556 | return start + end.substring(1);
|
557 | }
|
558 | if (slashes == 1) {
|
559 | return start + end;
|
560 | }
|
561 | return start + '/' + end;
|
562 | }
|
563 | /**
|
564 | * Removes a trailing slash from a URL string if needed.
|
565 | * Looks for the first occurrence of either `#`, `?`, or the end of the
|
566 | * line as `/` characters and removes the trailing slash if one exists.
|
567 | *
|
568 | * @param {?} url URL string.
|
569 | *
|
570 | * @return {?} The URL string, modified if needed.
|
571 | */
|
572 | function stripTrailingSlash(url) {
|
573 | /** @type {?} */
|
574 | const match = url.match(/#|\?|$/);
|
575 | /** @type {?} */
|
576 | const pathEndIdx = match && match.index || url.length;
|
577 | /** @type {?} */
|
578 | const droppedSlashIdx = pathEndIdx - (url[pathEndIdx - 1] === '/' ? 1 : 0);
|
579 | return url.slice(0, droppedSlashIdx) + url.slice(pathEndIdx);
|
580 | }
|
581 | /**
|
582 | * Normalizes URL parameters by prepending with `?` if needed.
|
583 | *
|
584 | * @param {?} params String of URL parameters.
|
585 | *
|
586 | * @return {?} The normalized URL parameters string.
|
587 | */
|
588 | function normalizeQueryParams(params) {
|
589 | return params && params[0] !== '?' ? '?' + params : params;
|
590 | }
|
591 |
|
592 | /**
|
593 | * @fileoverview added by tsickle
|
594 | * Generated from: packages/common/src/location/location_strategy.ts
|
595 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
596 | */
|
597 | /**
|
598 | * Enables the `Location` service to read route state from the browser's URL.
|
599 | * Angular provides two strategies:
|
600 | * `HashLocationStrategy` and `PathLocationStrategy`.
|
601 | *
|
602 | * Applications should use the `Router` or `Location` services to
|
603 | * interact with application route state.
|
604 | *
|
605 | * For instance, `HashLocationStrategy` produces URLs like
|
606 | * <code class="no-auto-link">http://example.com#/foo</code>,
|
607 | * and `PathLocationStrategy` produces
|
608 | * <code class="no-auto-link">http://example.com/foo</code> as an equivalent URL.
|
609 | *
|
610 | * See these two classes for more.
|
611 | *
|
612 | * \@publicApi
|
613 | * @abstract
|
614 | */
|
615 | class LocationStrategy {
|
616 | }
|
617 | LocationStrategy.decorators = [
|
618 | { type: Injectable, args: [{ providedIn: 'root', useFactory: provideLocationStrategy },] }
|
619 | ];
|
620 | /** @nocollapse */ LocationStrategy.ɵprov = ɵɵdefineInjectable({ factory: provideLocationStrategy, token: LocationStrategy, providedIn: "root" });
|
621 | if (false) {
|
622 | /**
|
623 | * @abstract
|
624 | * @param {?=} includeHash
|
625 | * @return {?}
|
626 | */
|
627 | LocationStrategy.prototype.path = function (includeHash) { };
|
628 | /**
|
629 | * @abstract
|
630 | * @param {?} internal
|
631 | * @return {?}
|
632 | */
|
633 | LocationStrategy.prototype.prepareExternalUrl = function (internal) { };
|
634 | /**
|
635 | * @abstract
|
636 | * @param {?} state
|
637 | * @param {?} title
|
638 | * @param {?} url
|
639 | * @param {?} queryParams
|
640 | * @return {?}
|
641 | */
|
642 | LocationStrategy.prototype.pushState = function (state, title, url, queryParams) { };
|
643 | /**
|
644 | * @abstract
|
645 | * @param {?} state
|
646 | * @param {?} title
|
647 | * @param {?} url
|
648 | * @param {?} queryParams
|
649 | * @return {?}
|
650 | */
|
651 | LocationStrategy.prototype.replaceState = function (state, title, url, queryParams) { };
|
652 | /**
|
653 | * @abstract
|
654 | * @return {?}
|
655 | */
|
656 | LocationStrategy.prototype.forward = function () { };
|
657 | /**
|
658 | * @abstract
|
659 | * @return {?}
|
660 | */
|
661 | LocationStrategy.prototype.back = function () { };
|
662 | /**
|
663 | * @abstract
|
664 | * @param {?} fn
|
665 | * @return {?}
|
666 | */
|
667 | LocationStrategy.prototype.onPopState = function (fn) { };
|
668 | /**
|
669 | * @abstract
|
670 | * @return {?}
|
671 | */
|
672 | LocationStrategy.prototype.getBaseHref = function () { };
|
673 | }
|
674 | /**
|
675 | * @param {?} platformLocation
|
676 | * @return {?}
|
677 | */
|
678 | function provideLocationStrategy(platformLocation) {
|
679 | // See #23917
|
680 | /** @type {?} */
|
681 | const location = ɵɵinject(DOCUMENT).location;
|
682 | return new PathLocationStrategy(ɵɵinject((/** @type {?} */ (PlatformLocation))), location && location.origin || '');
|
683 | }
|
684 | /**
|
685 | * A predefined [DI token](guide/glossary#di-token) for the base href
|
686 | * to be used with the `PathLocationStrategy`.
|
687 | * The base href is the URL prefix that should be preserved when generating
|
688 | * and recognizing URLs.
|
689 | *
|
690 | * \@usageNotes
|
691 | *
|
692 | * The following example shows how to use this token to configure the root app injector
|
693 | * with a base href value, so that the DI framework can supply the dependency anywhere in the app.
|
694 | *
|
695 | * ```typescript
|
696 | * import {Component, NgModule} from '\@angular/core';
|
697 | * import {APP_BASE_HREF} from '\@angular/common';
|
698 | *
|
699 | * \@NgModule({
|
700 | * providers: [{provide: APP_BASE_HREF, useValue: '/my/app'}]
|
701 | * })
|
702 | * class AppModule {}
|
703 | * ```
|
704 | *
|
705 | * \@publicApi
|
706 | * @type {?}
|
707 | */
|
708 | const APP_BASE_HREF = new InjectionToken('appBaseHref');
|
709 | /**
|
710 | * \@description
|
711 | * A {\@link LocationStrategy} used to configure the {\@link Location} service to
|
712 | * represent its state in the
|
713 | * [path](https://en.wikipedia.org/wiki/Uniform_Resource_Locator#Syntax) of the
|
714 | * browser's URL.
|
715 | *
|
716 | * If you're using `PathLocationStrategy`, you must provide a {\@link APP_BASE_HREF}
|
717 | * or add a base element to the document. This URL prefix that will be preserved
|
718 | * when generating and recognizing URLs.
|
719 | *
|
720 | * For instance, if you provide an `APP_BASE_HREF` of `'/my/app'` and call
|
721 | * `location.go('/foo')`, the browser's URL will become
|
722 | * `example.com/my/app/foo`.
|
723 | *
|
724 | * Similarly, if you add `<base href='/my/app'/>` to the document and call
|
725 | * `location.go('/foo')`, the browser's URL will become
|
726 | * `example.com/my/app/foo`.
|
727 | *
|
728 | * \@usageNotes
|
729 | *
|
730 | * ### Example
|
731 | *
|
732 | * {\@example common/location/ts/path_location_component.ts region='LocationComponent'}
|
733 | *
|
734 | * \@publicApi
|
735 | */
|
736 | class PathLocationStrategy extends LocationStrategy {
|
737 | /**
|
738 | * @param {?} _platformLocation
|
739 | * @param {?=} href
|
740 | */
|
741 | constructor(_platformLocation, href) {
|
742 | super();
|
743 | this._platformLocation = _platformLocation;
|
744 | if (href == null) {
|
745 | href = this._platformLocation.getBaseHrefFromDOM();
|
746 | }
|
747 | if (href == null) {
|
748 | throw new Error(`No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document.`);
|
749 | }
|
750 | this._baseHref = href;
|
751 | }
|
752 | /**
|
753 | * @param {?} fn
|
754 | * @return {?}
|
755 | */
|
756 | onPopState(fn) {
|
757 | this._platformLocation.onPopState(fn);
|
758 | this._platformLocation.onHashChange(fn);
|
759 | }
|
760 | /**
|
761 | * @return {?}
|
762 | */
|
763 | getBaseHref() { return this._baseHref; }
|
764 | /**
|
765 | * @param {?} internal
|
766 | * @return {?}
|
767 | */
|
768 | prepareExternalUrl(internal) { return joinWithSlash(this._baseHref, internal); }
|
769 | /**
|
770 | * @param {?=} includeHash
|
771 | * @return {?}
|
772 | */
|
773 | path(includeHash = false) {
|
774 | /** @type {?} */
|
775 | const pathname = this._platformLocation.pathname + normalizeQueryParams(this._platformLocation.search);
|
776 | /** @type {?} */
|
777 | const hash = this._platformLocation.hash;
|
778 | return hash && includeHash ? `${pathname}${hash}` : pathname;
|
779 | }
|
780 | /**
|
781 | * @param {?} state
|
782 | * @param {?} title
|
783 | * @param {?} url
|
784 | * @param {?} queryParams
|
785 | * @return {?}
|
786 | */
|
787 | pushState(state, title, url, queryParams) {
|
788 | /** @type {?} */
|
789 | const externalUrl = this.prepareExternalUrl(url + normalizeQueryParams(queryParams));
|
790 | this._platformLocation.pushState(state, title, externalUrl);
|
791 | }
|
792 | /**
|
793 | * @param {?} state
|
794 | * @param {?} title
|
795 | * @param {?} url
|
796 | * @param {?} queryParams
|
797 | * @return {?}
|
798 | */
|
799 | replaceState(state, title, url, queryParams) {
|
800 | /** @type {?} */
|
801 | const externalUrl = this.prepareExternalUrl(url + normalizeQueryParams(queryParams));
|
802 | this._platformLocation.replaceState(state, title, externalUrl);
|
803 | }
|
804 | /**
|
805 | * @return {?}
|
806 | */
|
807 | forward() { this._platformLocation.forward(); }
|
808 | /**
|
809 | * @return {?}
|
810 | */
|
811 | back() { this._platformLocation.back(); }
|
812 | }
|
813 | PathLocationStrategy.decorators = [
|
814 | { type: Injectable }
|
815 | ];
|
816 | /** @nocollapse */
|
817 | PathLocationStrategy.ctorParameters = () => [
|
818 | { type: PlatformLocation },
|
819 | { type: String, decorators: [{ type: Optional }, { type: Inject, args: [APP_BASE_HREF,] }] }
|
820 | ];
|
821 | if (false) {
|
822 | /**
|
823 | * @type {?}
|
824 | * @private
|
825 | */
|
826 | PathLocationStrategy.prototype._baseHref;
|
827 | /**
|
828 | * @type {?}
|
829 | * @private
|
830 | */
|
831 | PathLocationStrategy.prototype._platformLocation;
|
832 | }
|
833 |
|
834 | /**
|
835 | * @fileoverview added by tsickle
|
836 | * Generated from: packages/common/src/location/hash_location_strategy.ts
|
837 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
838 | */
|
839 | /**
|
840 | * \@description
|
841 | * A {\@link LocationStrategy} used to configure the {\@link Location} service to
|
842 | * represent its state in the
|
843 | * [hash fragment](https://en.wikipedia.org/wiki/Uniform_Resource_Locator#Syntax)
|
844 | * of the browser's URL.
|
845 | *
|
846 | * For instance, if you call `location.go('/foo')`, the browser's URL will become
|
847 | * `example.com#/foo`.
|
848 | *
|
849 | * \@usageNotes
|
850 | *
|
851 | * ### Example
|
852 | *
|
853 | * {\@example common/location/ts/hash_location_component.ts region='LocationComponent'}
|
854 | *
|
855 | * \@publicApi
|
856 | */
|
857 | class HashLocationStrategy extends LocationStrategy {
|
858 | /**
|
859 | * @param {?} _platformLocation
|
860 | * @param {?=} _baseHref
|
861 | */
|
862 | constructor(_platformLocation, _baseHref) {
|
863 | super();
|
864 | this._platformLocation = _platformLocation;
|
865 | this._baseHref = '';
|
866 | if (_baseHref != null) {
|
867 | this._baseHref = _baseHref;
|
868 | }
|
869 | }
|
870 | /**
|
871 | * @param {?} fn
|
872 | * @return {?}
|
873 | */
|
874 | onPopState(fn) {
|
875 | this._platformLocation.onPopState(fn);
|
876 | this._platformLocation.onHashChange(fn);
|
877 | }
|
878 | /**
|
879 | * @return {?}
|
880 | */
|
881 | getBaseHref() { return this._baseHref; }
|
882 | /**
|
883 | * @param {?=} includeHash
|
884 | * @return {?}
|
885 | */
|
886 | path(includeHash = false) {
|
887 | // the hash value is always prefixed with a `#`
|
888 | // and if it is empty then it will stay empty
|
889 | /** @type {?} */
|
890 | let path = this._platformLocation.hash;
|
891 | if (path == null)
|
892 | path = '#';
|
893 | return path.length > 0 ? path.substring(1) : path;
|
894 | }
|
895 | /**
|
896 | * @param {?} internal
|
897 | * @return {?}
|
898 | */
|
899 | prepareExternalUrl(internal) {
|
900 | /** @type {?} */
|
901 | const url = joinWithSlash(this._baseHref, internal);
|
902 | return url.length > 0 ? ('#' + url) : url;
|
903 | }
|
904 | /**
|
905 | * @param {?} state
|
906 | * @param {?} title
|
907 | * @param {?} path
|
908 | * @param {?} queryParams
|
909 | * @return {?}
|
910 | */
|
911 | pushState(state, title, path, queryParams) {
|
912 | /** @type {?} */
|
913 | let url = this.prepareExternalUrl(path + normalizeQueryParams(queryParams));
|
914 | if (url.length == 0) {
|
915 | url = this._platformLocation.pathname;
|
916 | }
|
917 | this._platformLocation.pushState(state, title, url);
|
918 | }
|
919 | /**
|
920 | * @param {?} state
|
921 | * @param {?} title
|
922 | * @param {?} path
|
923 | * @param {?} queryParams
|
924 | * @return {?}
|
925 | */
|
926 | replaceState(state, title, path, queryParams) {
|
927 | /** @type {?} */
|
928 | let url = this.prepareExternalUrl(path + normalizeQueryParams(queryParams));
|
929 | if (url.length == 0) {
|
930 | url = this._platformLocation.pathname;
|
931 | }
|
932 | this._platformLocation.replaceState(state, title, url);
|
933 | }
|
934 | /**
|
935 | * @return {?}
|
936 | */
|
937 | forward() { this._platformLocation.forward(); }
|
938 | /**
|
939 | * @return {?}
|
940 | */
|
941 | back() { this._platformLocation.back(); }
|
942 | }
|
943 | HashLocationStrategy.decorators = [
|
944 | { type: Injectable }
|
945 | ];
|
946 | /** @nocollapse */
|
947 | HashLocationStrategy.ctorParameters = () => [
|
948 | { type: PlatformLocation },
|
949 | { type: String, decorators: [{ type: Optional }, { type: Inject, args: [APP_BASE_HREF,] }] }
|
950 | ];
|
951 | if (false) {
|
952 | /**
|
953 | * @type {?}
|
954 | * @private
|
955 | */
|
956 | HashLocationStrategy.prototype._baseHref;
|
957 | /**
|
958 | * @type {?}
|
959 | * @private
|
960 | */
|
961 | HashLocationStrategy.prototype._platformLocation;
|
962 | }
|
963 |
|
964 | /**
|
965 | * @fileoverview added by tsickle
|
966 | * Generated from: packages/common/src/location/location.ts
|
967 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
968 | */
|
969 | /**
|
970 | * \@publicApi
|
971 | * @record
|
972 | */
|
973 | function PopStateEvent() { }
|
974 | if (false) {
|
975 | /** @type {?|undefined} */
|
976 | PopStateEvent.prototype.pop;
|
977 | /** @type {?|undefined} */
|
978 | PopStateEvent.prototype.state;
|
979 | /** @type {?|undefined} */
|
980 | PopStateEvent.prototype.type;
|
981 | /** @type {?|undefined} */
|
982 | PopStateEvent.prototype.url;
|
983 | }
|
984 | /**
|
985 | * \@description
|
986 | *
|
987 | * A service that applications can use to interact with a browser's URL.
|
988 | *
|
989 | * Depending on the `LocationStrategy` used, `Location` persists
|
990 | * to the URL's path or the URL's hash segment.
|
991 | *
|
992 | * \@usageNotes
|
993 | *
|
994 | * It's better to use the `Router#navigate` service to trigger route changes. Use
|
995 | * `Location` only if you need to interact with or create normalized URLs outside of
|
996 | * routing.
|
997 | *
|
998 | * `Location` is responsible for normalizing the URL against the application's base href.
|
999 | * A normalized URL is absolute from the URL host, includes the application's base href, and has no
|
1000 | * trailing slash:
|
1001 | * - `/my/app/user/123` is normalized
|
1002 | * - `my/app/user/123` **is not** normalized
|
1003 | * - `/my/app/user/123/` **is not** normalized
|
1004 | *
|
1005 | * ### Example
|
1006 | *
|
1007 | * <code-example path='common/location/ts/path_location_component.ts'
|
1008 | * region='LocationComponent'></code-example>
|
1009 | *
|
1010 | * \@publicApi
|
1011 | */
|
1012 | class Location {
|
1013 | /**
|
1014 | * @param {?} platformStrategy
|
1015 | * @param {?} platformLocation
|
1016 | */
|
1017 | constructor(platformStrategy, platformLocation) {
|
1018 | /**
|
1019 | * \@internal
|
1020 | */
|
1021 | this._subject = new EventEmitter();
|
1022 | /**
|
1023 | * \@internal
|
1024 | */
|
1025 | this._urlChangeListeners = [];
|
1026 | this._platformStrategy = platformStrategy;
|
1027 | /** @type {?} */
|
1028 | const browserBaseHref = this._platformStrategy.getBaseHref();
|
1029 | this._platformLocation = platformLocation;
|
1030 | this._baseHref = stripTrailingSlash(_stripIndexHtml(browserBaseHref));
|
1031 | this._platformStrategy.onPopState((/**
|
1032 | * @param {?} ev
|
1033 | * @return {?}
|
1034 | */
|
1035 | (ev) => {
|
1036 | this._subject.emit({
|
1037 | 'url': this.path(true),
|
1038 | 'pop': true,
|
1039 | 'state': ev.state,
|
1040 | 'type': ev.type,
|
1041 | });
|
1042 | }));
|
1043 | }
|
1044 | /**
|
1045 | * Normalizes the URL path for this location.
|
1046 | *
|
1047 | * @param {?=} includeHash True to include an anchor fragment in the path.
|
1048 | *
|
1049 | * @return {?} The normalized URL path.
|
1050 | */
|
1051 | // TODO: vsavkin. Remove the boolean flag and always include hash once the deprecated router is
|
1052 | // removed.
|
1053 | path(includeHash = false) {
|
1054 | return this.normalize(this._platformStrategy.path(includeHash));
|
1055 | }
|
1056 | /**
|
1057 | * Reports the current state of the location history.
|
1058 | * @return {?} The current value of the `history.state` object.
|
1059 | */
|
1060 | getState() { return this._platformLocation.getState(); }
|
1061 | /**
|
1062 | * Normalizes the given path and compares to the current normalized path.
|
1063 | *
|
1064 | * @param {?} path The given URL path.
|
1065 | * @param {?=} query Query parameters.
|
1066 | *
|
1067 | * @return {?} True if the given URL path is equal to the current normalized path, false
|
1068 | * otherwise.
|
1069 | */
|
1070 | isCurrentPathEqualTo(path, query = '') {
|
1071 | return this.path() == this.normalize(path + normalizeQueryParams(query));
|
1072 | }
|
1073 | /**
|
1074 | * Normalizes a URL path by stripping any trailing slashes.
|
1075 | *
|
1076 | * @param {?} url String representing a URL.
|
1077 | *
|
1078 | * @return {?} The normalized URL string.
|
1079 | */
|
1080 | normalize(url) {
|
1081 | return Location.stripTrailingSlash(_stripBaseHref(this._baseHref, _stripIndexHtml(url)));
|
1082 | }
|
1083 | /**
|
1084 | * Normalizes an external URL path.
|
1085 | * If the given URL doesn't begin with a leading slash (`'/'`), adds one
|
1086 | * before normalizing. Adds a hash if `HashLocationStrategy` is
|
1087 | * in use, or the `APP_BASE_HREF` if the `PathLocationStrategy` is in use.
|
1088 | *
|
1089 | * @param {?} url String representing a URL.
|
1090 | *
|
1091 | * @return {?} A normalized platform-specific URL.
|
1092 | */
|
1093 | prepareExternalUrl(url) {
|
1094 | if (url && url[0] !== '/') {
|
1095 | url = '/' + url;
|
1096 | }
|
1097 | return this._platformStrategy.prepareExternalUrl(url);
|
1098 | }
|
1099 | // TODO: rename this method to pushState
|
1100 | /**
|
1101 | * Changes the browser's URL to a normalized version of a given URL, and pushes a
|
1102 | * new item onto the platform's history.
|
1103 | *
|
1104 | * @param {?} path URL path to normalize.
|
1105 | * @param {?=} query Query parameters.
|
1106 | * @param {?=} state Location history state.
|
1107 | *
|
1108 | * @return {?}
|
1109 | */
|
1110 | go(path, query = '', state = null) {
|
1111 | this._platformStrategy.pushState(state, '', path, query);
|
1112 | this._notifyUrlChangeListeners(this.prepareExternalUrl(path + normalizeQueryParams(query)), state);
|
1113 | }
|
1114 | /**
|
1115 | * Changes the browser's URL to a normalized version of the given URL, and replaces
|
1116 | * the top item on the platform's history stack.
|
1117 | *
|
1118 | * @param {?} path URL path to normalize.
|
1119 | * @param {?=} query Query parameters.
|
1120 | * @param {?=} state Location history state.
|
1121 | * @return {?}
|
1122 | */
|
1123 | replaceState(path, query = '', state = null) {
|
1124 | this._platformStrategy.replaceState(state, '', path, query);
|
1125 | this._notifyUrlChangeListeners(this.prepareExternalUrl(path + normalizeQueryParams(query)), state);
|
1126 | }
|
1127 | /**
|
1128 | * Navigates forward in the platform's history.
|
1129 | * @return {?}
|
1130 | */
|
1131 | forward() { this._platformStrategy.forward(); }
|
1132 | /**
|
1133 | * Navigates back in the platform's history.
|
1134 | * @return {?}
|
1135 | */
|
1136 | back() { this._platformStrategy.back(); }
|
1137 | /**
|
1138 | * Registers a URL change listener. Use to catch updates performed by the Angular
|
1139 | * framework that are not detectible through "popstate" or "hashchange" events.
|
1140 | *
|
1141 | * @param {?} fn The change handler function, which take a URL and a location history state.
|
1142 | * @return {?}
|
1143 | */
|
1144 | onUrlChange(fn) {
|
1145 | this._urlChangeListeners.push(fn);
|
1146 | this.subscribe((/**
|
1147 | * @param {?} v
|
1148 | * @return {?}
|
1149 | */
|
1150 | v => { this._notifyUrlChangeListeners(v.url, v.state); }));
|
1151 | }
|
1152 | /**
|
1153 | * \@internal
|
1154 | * @param {?=} url
|
1155 | * @param {?=} state
|
1156 | * @return {?}
|
1157 | */
|
1158 | _notifyUrlChangeListeners(url = '', state) {
|
1159 | this._urlChangeListeners.forEach((/**
|
1160 | * @param {?} fn
|
1161 | * @return {?}
|
1162 | */
|
1163 | fn => fn(url, state)));
|
1164 | }
|
1165 | /**
|
1166 | * Subscribes to the platform's `popState` events.
|
1167 | *
|
1168 | * @param {?} onNext
|
1169 | * @param {?=} onThrow
|
1170 | * @param {?=} onReturn
|
1171 | * @return {?} Subscribed events.
|
1172 | */
|
1173 | subscribe(onNext, onThrow, onReturn) {
|
1174 | return this._subject.subscribe({ next: onNext, error: onThrow, complete: onReturn });
|
1175 | }
|
1176 | }
|
1177 | /**
|
1178 | * Normalizes URL parameters by prepending with `?` if needed.
|
1179 | *
|
1180 | * @param params String of URL parameters.
|
1181 | *
|
1182 | * @return The normalized URL parameters string.
|
1183 | */
|
1184 | Location.normalizeQueryParams = normalizeQueryParams;
|
1185 | /**
|
1186 | * Joins two parts of a URL with a slash if needed.
|
1187 | *
|
1188 | * @param start URL string
|
1189 | * @param end URL string
|
1190 | *
|
1191 | *
|
1192 | * @return The joined URL string.
|
1193 | */
|
1194 | Location.joinWithSlash = joinWithSlash;
|
1195 | /**
|
1196 | * Removes a trailing slash from a URL string if needed.
|
1197 | * Looks for the first occurrence of either `#`, `?`, or the end of the
|
1198 | * line as `/` characters and removes the trailing slash if one exists.
|
1199 | *
|
1200 | * @param url URL string.
|
1201 | *
|
1202 | * @return The URL string, modified if needed.
|
1203 | */
|
1204 | Location.stripTrailingSlash = stripTrailingSlash;
|
1205 | Location.decorators = [
|
1206 | { type: Injectable, args: [{
|
1207 | providedIn: 'root',
|
1208 | // See #23917
|
1209 | useFactory: createLocation,
|
1210 | },] }
|
1211 | ];
|
1212 | /** @nocollapse */
|
1213 | Location.ctorParameters = () => [
|
1214 | { type: LocationStrategy },
|
1215 | { type: PlatformLocation }
|
1216 | ];
|
1217 | /** @nocollapse */ Location.ɵprov = ɵɵdefineInjectable({ factory: createLocation, token: Location, providedIn: "root" });
|
1218 | if (false) {
|
1219 | /**
|
1220 | * Normalizes URL parameters by prepending with `?` if needed.
|
1221 | *
|
1222 | * \@param params String of URL parameters.
|
1223 | *
|
1224 | * \@return The normalized URL parameters string.
|
1225 | * @type {?}
|
1226 | */
|
1227 | Location.normalizeQueryParams;
|
1228 | /**
|
1229 | * Joins two parts of a URL with a slash if needed.
|
1230 | *
|
1231 | * \@param start URL string
|
1232 | * \@param end URL string
|
1233 | *
|
1234 | *
|
1235 | * \@return The joined URL string.
|
1236 | * @type {?}
|
1237 | */
|
1238 | Location.joinWithSlash;
|
1239 | /**
|
1240 | * Removes a trailing slash from a URL string if needed.
|
1241 | * Looks for the first occurrence of either `#`, `?`, or the end of the
|
1242 | * line as `/` characters and removes the trailing slash if one exists.
|
1243 | *
|
1244 | * \@param url URL string.
|
1245 | *
|
1246 | * \@return The URL string, modified if needed.
|
1247 | * @type {?}
|
1248 | */
|
1249 | Location.stripTrailingSlash;
|
1250 | /**
|
1251 | * \@internal
|
1252 | * @type {?}
|
1253 | */
|
1254 | Location.prototype._subject;
|
1255 | /**
|
1256 | * \@internal
|
1257 | * @type {?}
|
1258 | */
|
1259 | Location.prototype._baseHref;
|
1260 | /**
|
1261 | * \@internal
|
1262 | * @type {?}
|
1263 | */
|
1264 | Location.prototype._platformStrategy;
|
1265 | /**
|
1266 | * \@internal
|
1267 | * @type {?}
|
1268 | */
|
1269 | Location.prototype._platformLocation;
|
1270 | /**
|
1271 | * \@internal
|
1272 | * @type {?}
|
1273 | */
|
1274 | Location.prototype._urlChangeListeners;
|
1275 | }
|
1276 | /**
|
1277 | * @return {?}
|
1278 | */
|
1279 | function createLocation() {
|
1280 | return new Location(ɵɵinject((/** @type {?} */ (LocationStrategy))), ɵɵinject((/** @type {?} */ (PlatformLocation))));
|
1281 | }
|
1282 | /**
|
1283 | * @param {?} baseHref
|
1284 | * @param {?} url
|
1285 | * @return {?}
|
1286 | */
|
1287 | function _stripBaseHref(baseHref, url) {
|
1288 | return baseHref && url.startsWith(baseHref) ? url.substring(baseHref.length) : url;
|
1289 | }
|
1290 | /**
|
1291 | * @param {?} url
|
1292 | * @return {?}
|
1293 | */
|
1294 | function _stripIndexHtml(url) {
|
1295 | return url.replace(/\/index.html$/, '');
|
1296 | }
|
1297 |
|
1298 | /**
|
1299 | * @fileoverview added by tsickle
|
1300 | * Generated from: packages/common/src/location/index.ts
|
1301 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
1302 | */
|
1303 |
|
1304 | /**
|
1305 | * @fileoverview added by tsickle
|
1306 | * Generated from: packages/common/src/i18n/currencies.ts
|
1307 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
1308 | */
|
1309 | /**
|
1310 | * @license
|
1311 | * Copyright Google Inc. All Rights Reserved.
|
1312 | *
|
1313 | * Use of this source code is governed by an MIT-style license that can be
|
1314 | * found in the LICENSE file at https://angular.io/license
|
1315 | */
|
1316 | // THIS CODE IS GENERATED - DO NOT MODIFY
|
1317 | // See angular/tools/gulp-tasks/cldr/extract.js
|
1318 | /**
|
1319 | * \@internal
|
1320 | * @type {?}
|
1321 | */
|
1322 | const CURRENCIES_EN = {
|
1323 | 'ADP': [undefined, undefined, 0],
|
1324 | 'AFN': [undefined, undefined, 0],
|
1325 | 'ALL': [undefined, undefined, 0],
|
1326 | 'AMD': [undefined, undefined, 2],
|
1327 | 'AOA': [undefined, 'Kz'],
|
1328 | 'ARS': [undefined, '$'],
|
1329 | 'AUD': ['A$', '$'],
|
1330 | 'BAM': [undefined, 'KM'],
|
1331 | 'BBD': [undefined, '$'],
|
1332 | 'BDT': [undefined, '৳'],
|
1333 | 'BHD': [undefined, undefined, 3],
|
1334 | 'BIF': [undefined, undefined, 0],
|
1335 | 'BMD': [undefined, '$'],
|
1336 | 'BND': [undefined, '$'],
|
1337 | 'BOB': [undefined, 'Bs'],
|
1338 | 'BRL': ['R$'],
|
1339 | 'BSD': [undefined, '$'],
|
1340 | 'BWP': [undefined, 'P'],
|
1341 | 'BYN': [undefined, 'р.', 2],
|
1342 | 'BYR': [undefined, undefined, 0],
|
1343 | 'BZD': [undefined, '$'],
|
1344 | 'CAD': ['CA$', '$', 2],
|
1345 | 'CHF': [undefined, undefined, 2],
|
1346 | 'CLF': [undefined, undefined, 4],
|
1347 | 'CLP': [undefined, '$', 0],
|
1348 | 'CNY': ['CN¥', '¥'],
|
1349 | 'COP': [undefined, '$', 2],
|
1350 | 'CRC': [undefined, '₡', 2],
|
1351 | 'CUC': [undefined, '$'],
|
1352 | 'CUP': [undefined, '$'],
|
1353 | 'CZK': [undefined, 'Kč', 2],
|
1354 | 'DJF': [undefined, undefined, 0],
|
1355 | 'DKK': [undefined, 'kr', 2],
|
1356 | 'DOP': [undefined, '$'],
|
1357 | 'EGP': [undefined, 'E£'],
|
1358 | 'ESP': [undefined, '₧', 0],
|
1359 | 'EUR': ['€'],
|
1360 | 'FJD': [undefined, '$'],
|
1361 | 'FKP': [undefined, '£'],
|
1362 | 'GBP': ['£'],
|
1363 | 'GEL': [undefined, '₾'],
|
1364 | 'GIP': [undefined, '£'],
|
1365 | 'GNF': [undefined, 'FG', 0],
|
1366 | 'GTQ': [undefined, 'Q'],
|
1367 | 'GYD': [undefined, '$', 2],
|
1368 | 'HKD': ['HK$', '$'],
|
1369 | 'HNL': [undefined, 'L'],
|
1370 | 'HRK': [undefined, 'kn'],
|
1371 | 'HUF': [undefined, 'Ft', 2],
|
1372 | 'IDR': [undefined, 'Rp', 2],
|
1373 | 'ILS': ['₪'],
|
1374 | 'INR': ['₹'],
|
1375 | 'IQD': [undefined, undefined, 0],
|
1376 | 'IRR': [undefined, undefined, 0],
|
1377 | 'ISK': [undefined, 'kr', 0],
|
1378 | 'ITL': [undefined, undefined, 0],
|
1379 | 'JMD': [undefined, '$'],
|
1380 | 'JOD': [undefined, undefined, 3],
|
1381 | 'JPY': ['¥', undefined, 0],
|
1382 | 'KHR': [undefined, '៛'],
|
1383 | 'KMF': [undefined, 'CF', 0],
|
1384 | 'KPW': [undefined, '₩', 0],
|
1385 | 'KRW': ['₩', undefined, 0],
|
1386 | 'KWD': [undefined, undefined, 3],
|
1387 | 'KYD': [undefined, '$'],
|
1388 | 'KZT': [undefined, '₸'],
|
1389 | 'LAK': [undefined, '₭', 0],
|
1390 | 'LBP': [undefined, 'L£', 0],
|
1391 | 'LKR': [undefined, 'Rs'],
|
1392 | 'LRD': [undefined, '$'],
|
1393 | 'LTL': [undefined, 'Lt'],
|
1394 | 'LUF': [undefined, undefined, 0],
|
1395 | 'LVL': [undefined, 'Ls'],
|
1396 | 'LYD': [undefined, undefined, 3],
|
1397 | 'MGA': [undefined, 'Ar', 0],
|
1398 | 'MGF': [undefined, undefined, 0],
|
1399 | 'MMK': [undefined, 'K', 0],
|
1400 | 'MNT': [undefined, '₮', 2],
|
1401 | 'MRO': [undefined, undefined, 0],
|
1402 | 'MUR': [undefined, 'Rs', 2],
|
1403 | 'MXN': ['MX$', '$'],
|
1404 | 'MYR': [undefined, 'RM'],
|
1405 | 'NAD': [undefined, '$'],
|
1406 | 'NGN': [undefined, '₦'],
|
1407 | 'NIO': [undefined, 'C$'],
|
1408 | 'NOK': [undefined, 'kr', 2],
|
1409 | 'NPR': [undefined, 'Rs'],
|
1410 | 'NZD': ['NZ$', '$'],
|
1411 | 'OMR': [undefined, undefined, 3],
|
1412 | 'PHP': [undefined, '₱'],
|
1413 | 'PKR': [undefined, 'Rs', 2],
|
1414 | 'PLN': [undefined, 'zł'],
|
1415 | 'PYG': [undefined, '₲', 0],
|
1416 | 'RON': [undefined, 'lei'],
|
1417 | 'RSD': [undefined, undefined, 0],
|
1418 | 'RUB': [undefined, '₽'],
|
1419 | 'RUR': [undefined, 'р.'],
|
1420 | 'RWF': [undefined, 'RF', 0],
|
1421 | 'SBD': [undefined, '$'],
|
1422 | 'SEK': [undefined, 'kr', 2],
|
1423 | 'SGD': [undefined, '$'],
|
1424 | 'SHP': [undefined, '£'],
|
1425 | 'SLL': [undefined, undefined, 0],
|
1426 | 'SOS': [undefined, undefined, 0],
|
1427 | 'SRD': [undefined, '$'],
|
1428 | 'SSP': [undefined, '£'],
|
1429 | 'STD': [undefined, undefined, 0],
|
1430 | 'STN': [undefined, 'Db'],
|
1431 | 'SYP': [undefined, '£', 0],
|
1432 | 'THB': [undefined, '฿'],
|
1433 | 'TMM': [undefined, undefined, 0],
|
1434 | 'TND': [undefined, undefined, 3],
|
1435 | 'TOP': [undefined, 'T$'],
|
1436 | 'TRL': [undefined, undefined, 0],
|
1437 | 'TRY': [undefined, '₺'],
|
1438 | 'TTD': [undefined, '$'],
|
1439 | 'TWD': ['NT$', '$', 2],
|
1440 | 'TZS': [undefined, undefined, 2],
|
1441 | 'UAH': [undefined, '₴'],
|
1442 | 'UGX': [undefined, undefined, 0],
|
1443 | 'USD': ['$'],
|
1444 | 'UYI': [undefined, undefined, 0],
|
1445 | 'UYU': [undefined, '$'],
|
1446 | 'UYW': [undefined, undefined, 4],
|
1447 | 'UZS': [undefined, undefined, 2],
|
1448 | 'VEF': [undefined, 'Bs', 2],
|
1449 | 'VND': ['₫', undefined, 0],
|
1450 | 'VUV': [undefined, undefined, 0],
|
1451 | 'XAF': ['FCFA', undefined, 0],
|
1452 | 'XCD': ['EC$', '$'],
|
1453 | 'XOF': ['CFA', undefined, 0],
|
1454 | 'XPF': ['CFPF', undefined, 0],
|
1455 | 'XXX': ['¤'],
|
1456 | 'YER': [undefined, undefined, 0],
|
1457 | 'ZAR': [undefined, 'R'],
|
1458 | 'ZMK': [undefined, undefined, 0],
|
1459 | 'ZMW': [undefined, 'ZK'],
|
1460 | 'ZWD': [undefined, undefined, 0]
|
1461 | };
|
1462 |
|
1463 | /**
|
1464 | * @fileoverview added by tsickle
|
1465 | * Generated from: packages/common/src/i18n/locale_data_api.ts
|
1466 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
1467 | */
|
1468 | /** @enum {number} */
|
1469 | const NumberFormatStyle = {
|
1470 | Decimal: 0,
|
1471 | Percent: 1,
|
1472 | Currency: 2,
|
1473 | Scientific: 3,
|
1474 | };
|
1475 | NumberFormatStyle[NumberFormatStyle.Decimal] = 'Decimal';
|
1476 | NumberFormatStyle[NumberFormatStyle.Percent] = 'Percent';
|
1477 | NumberFormatStyle[NumberFormatStyle.Currency] = 'Currency';
|
1478 | NumberFormatStyle[NumberFormatStyle.Scientific] = 'Scientific';
|
1479 | /** @enum {number} */
|
1480 | const Plural = {
|
1481 | Zero: 0,
|
1482 | One: 1,
|
1483 | Two: 2,
|
1484 | Few: 3,
|
1485 | Many: 4,
|
1486 | Other: 5,
|
1487 | };
|
1488 | Plural[Plural.Zero] = 'Zero';
|
1489 | Plural[Plural.One] = 'One';
|
1490 | Plural[Plural.Two] = 'Two';
|
1491 | Plural[Plural.Few] = 'Few';
|
1492 | Plural[Plural.Many] = 'Many';
|
1493 | Plural[Plural.Other] = 'Other';
|
1494 | /** @enum {number} */
|
1495 | const FormStyle = {
|
1496 | Format: 0,
|
1497 | Standalone: 1,
|
1498 | };
|
1499 | FormStyle[FormStyle.Format] = 'Format';
|
1500 | FormStyle[FormStyle.Standalone] = 'Standalone';
|
1501 | /** @enum {number} */
|
1502 | const TranslationWidth = {
|
1503 | /** 1 character for `en-US`. For example: 'S' */
|
1504 | Narrow: 0,
|
1505 | /** 3 characters for `en-US`. For example: 'Sun' */
|
1506 | Abbreviated: 1,
|
1507 | /** Full length for `en-US`. For example: "Sunday" */
|
1508 | Wide: 2,
|
1509 | /** 2 characters for `en-US`, For example: "Su" */
|
1510 | Short: 3,
|
1511 | };
|
1512 | TranslationWidth[TranslationWidth.Narrow] = 'Narrow';
|
1513 | TranslationWidth[TranslationWidth.Abbreviated] = 'Abbreviated';
|
1514 | TranslationWidth[TranslationWidth.Wide] = 'Wide';
|
1515 | TranslationWidth[TranslationWidth.Short] = 'Short';
|
1516 | /** @enum {number} */
|
1517 | const FormatWidth = {
|
1518 | /**
|
1519 | * For `en-US`, 'M/d/yy, h:mm a'`
|
1520 | * (Example: `6/15/15, 9:03 AM`)
|
1521 | */
|
1522 | Short: 0,
|
1523 | /**
|
1524 | * For `en-US`, `'MMM d, y, h:mm:ss a'`
|
1525 | * (Example: `Jun 15, 2015, 9:03:01 AM`)
|
1526 | */
|
1527 | Medium: 1,
|
1528 | /**
|
1529 | * For `en-US`, `'MMMM d, y, h:mm:ss a z'`
|
1530 | * (Example: `June 15, 2015 at 9:03:01 AM GMT+1`)
|
1531 | */
|
1532 | Long: 2,
|
1533 | /**
|
1534 | * For `en-US`, `'EEEE, MMMM d, y, h:mm:ss a zzzz'`
|
1535 | * (Example: `Monday, June 15, 2015 at 9:03:01 AM GMT+01:00`)
|
1536 | */
|
1537 | Full: 3,
|
1538 | };
|
1539 | FormatWidth[FormatWidth.Short] = 'Short';
|
1540 | FormatWidth[FormatWidth.Medium] = 'Medium';
|
1541 | FormatWidth[FormatWidth.Long] = 'Long';
|
1542 | FormatWidth[FormatWidth.Full] = 'Full';
|
1543 | /** @enum {number} */
|
1544 | const NumberSymbol = {
|
1545 | /**
|
1546 | * Decimal separator.
|
1547 | * For `en-US`, the dot character.
|
1548 | * Example : 2,345`.`67
|
1549 | */
|
1550 | Decimal: 0,
|
1551 | /**
|
1552 | * Grouping separator, typically for thousands.
|
1553 | * For `en-US`, the comma character.
|
1554 | * Example: 2`,`345.67
|
1555 | */
|
1556 | Group: 1,
|
1557 | /**
|
1558 | * List-item separator.
|
1559 | * Example: "one, two, and three"
|
1560 | */
|
1561 | List: 2,
|
1562 | /**
|
1563 | * Sign for percentage (out of 100).
|
1564 | * Example: 23.4%
|
1565 | */
|
1566 | PercentSign: 3,
|
1567 | /**
|
1568 | * Sign for positive numbers.
|
1569 | * Example: +23
|
1570 | */
|
1571 | PlusSign: 4,
|
1572 | /**
|
1573 | * Sign for negative numbers.
|
1574 | * Example: -23
|
1575 | */
|
1576 | MinusSign: 5,
|
1577 | /**
|
1578 | * Computer notation for exponential value (n times a power of 10).
|
1579 | * Example: 1.2E3
|
1580 | */
|
1581 | Exponential: 6,
|
1582 | /**
|
1583 | * Human-readable format of exponential.
|
1584 | * Example: 1.2x103
|
1585 | */
|
1586 | SuperscriptingExponent: 7,
|
1587 | /**
|
1588 | * Sign for permille (out of 1000).
|
1589 | * Example: 23.4‰
|
1590 | */
|
1591 | PerMille: 8,
|
1592 | /**
|
1593 | * Infinity, can be used with plus and minus.
|
1594 | * Example: ∞, +∞, -∞
|
1595 | */
|
1596 | Infinity: 9,
|
1597 | /**
|
1598 | * Not a number.
|
1599 | * Example: NaN
|
1600 | */
|
1601 | NaN: 10,
|
1602 | /**
|
1603 | * Symbol used between time units.
|
1604 | * Example: 10:52
|
1605 | */
|
1606 | TimeSeparator: 11,
|
1607 | /**
|
1608 | * Decimal separator for currency values (fallback to `Decimal`).
|
1609 | * Example: $2,345.67
|
1610 | */
|
1611 | CurrencyDecimal: 12,
|
1612 | /**
|
1613 | * Group separator for currency values (fallback to `Group`).
|
1614 | * Example: $2,345.67
|
1615 | */
|
1616 | CurrencyGroup: 13,
|
1617 | };
|
1618 | NumberSymbol[NumberSymbol.Decimal] = 'Decimal';
|
1619 | NumberSymbol[NumberSymbol.Group] = 'Group';
|
1620 | NumberSymbol[NumberSymbol.List] = 'List';
|
1621 | NumberSymbol[NumberSymbol.PercentSign] = 'PercentSign';
|
1622 | NumberSymbol[NumberSymbol.PlusSign] = 'PlusSign';
|
1623 | NumberSymbol[NumberSymbol.MinusSign] = 'MinusSign';
|
1624 | NumberSymbol[NumberSymbol.Exponential] = 'Exponential';
|
1625 | NumberSymbol[NumberSymbol.SuperscriptingExponent] = 'SuperscriptingExponent';
|
1626 | NumberSymbol[NumberSymbol.PerMille] = 'PerMille';
|
1627 | NumberSymbol[NumberSymbol.Infinity] = 'Infinity';
|
1628 | NumberSymbol[NumberSymbol.NaN] = 'NaN';
|
1629 | NumberSymbol[NumberSymbol.TimeSeparator] = 'TimeSeparator';
|
1630 | NumberSymbol[NumberSymbol.CurrencyDecimal] = 'CurrencyDecimal';
|
1631 | NumberSymbol[NumberSymbol.CurrencyGroup] = 'CurrencyGroup';
|
1632 | /** @enum {number} */
|
1633 | const WeekDay = {
|
1634 | Sunday: 0,
|
1635 | Monday: 1,
|
1636 | Tuesday: 2,
|
1637 | Wednesday: 3,
|
1638 | Thursday: 4,
|
1639 | Friday: 5,
|
1640 | Saturday: 6,
|
1641 | };
|
1642 | WeekDay[WeekDay.Sunday] = 'Sunday';
|
1643 | WeekDay[WeekDay.Monday] = 'Monday';
|
1644 | WeekDay[WeekDay.Tuesday] = 'Tuesday';
|
1645 | WeekDay[WeekDay.Wednesday] = 'Wednesday';
|
1646 | WeekDay[WeekDay.Thursday] = 'Thursday';
|
1647 | WeekDay[WeekDay.Friday] = 'Friday';
|
1648 | WeekDay[WeekDay.Saturday] = 'Saturday';
|
1649 | /**
|
1650 | * Retrieves the locale ID from the currently loaded locale.
|
1651 | * The loaded locale could be, for example, a global one rather than a regional one.
|
1652 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1653 | *
|
1654 | * \@publicApi
|
1655 | * @param {?} locale A locale code, such as `fr-FR`.
|
1656 | * @return {?} The locale code. For example, `fr`.
|
1657 | */
|
1658 | function getLocaleId(locale) {
|
1659 | return ɵfindLocaleData(locale)[ɵLocaleDataIndex.LocaleId];
|
1660 | }
|
1661 | /**
|
1662 | * Retrieves day period strings for the given locale.
|
1663 | *
|
1664 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1665 | *
|
1666 | * \@publicApi
|
1667 | * @param {?} locale A locale code for the locale format rules to use.
|
1668 | * @param {?} formStyle The required grammatical form.
|
1669 | * @param {?} width The required character width.
|
1670 | * @return {?} An array of localized period strings. For example, `[AM, PM]` for `en-US`.
|
1671 | */
|
1672 | function getLocaleDayPeriods(locale, formStyle, width) {
|
1673 | /** @type {?} */
|
1674 | const data = ɵfindLocaleData(locale);
|
1675 | /** @type {?} */
|
1676 | const amPmData = (/** @type {?} */ ([data[ɵLocaleDataIndex.DayPeriodsFormat], data[ɵLocaleDataIndex.DayPeriodsStandalone]]));
|
1677 | /** @type {?} */
|
1678 | const amPm = getLastDefinedValue(amPmData, formStyle);
|
1679 | return getLastDefinedValue(amPm, width);
|
1680 | }
|
1681 | /**
|
1682 | * Retrieves days of the week for the given locale, using the Gregorian calendar.
|
1683 | *
|
1684 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1685 | *
|
1686 | * \@publicApi
|
1687 | * @param {?} locale A locale code for the locale format rules to use.
|
1688 | * @param {?} formStyle The required grammatical form.
|
1689 | * @param {?} width The required character width.
|
1690 | * @return {?} An array of localized name strings.
|
1691 | * For example,`[Sunday, Monday, ... Saturday]` for `en-US`.
|
1692 | */
|
1693 | function getLocaleDayNames(locale, formStyle, width) {
|
1694 | /** @type {?} */
|
1695 | const data = ɵfindLocaleData(locale);
|
1696 | /** @type {?} */
|
1697 | const daysData = (/** @type {?} */ ([data[ɵLocaleDataIndex.DaysFormat], data[ɵLocaleDataIndex.DaysStandalone]]));
|
1698 | /** @type {?} */
|
1699 | const days = getLastDefinedValue(daysData, formStyle);
|
1700 | return getLastDefinedValue(days, width);
|
1701 | }
|
1702 | /**
|
1703 | * Retrieves months of the year for the given locale, using the Gregorian calendar.
|
1704 | *
|
1705 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1706 | *
|
1707 | * \@publicApi
|
1708 | * @param {?} locale A locale code for the locale format rules to use.
|
1709 | * @param {?} formStyle The required grammatical form.
|
1710 | * @param {?} width The required character width.
|
1711 | * @return {?} An array of localized name strings.
|
1712 | * For example, `[January, February, ...]` for `en-US`.
|
1713 | */
|
1714 | function getLocaleMonthNames(locale, formStyle, width) {
|
1715 | /** @type {?} */
|
1716 | const data = ɵfindLocaleData(locale);
|
1717 | /** @type {?} */
|
1718 | const monthsData = (/** @type {?} */ ([data[ɵLocaleDataIndex.MonthsFormat], data[ɵLocaleDataIndex.MonthsStandalone]]));
|
1719 | /** @type {?} */
|
1720 | const months = getLastDefinedValue(monthsData, formStyle);
|
1721 | return getLastDefinedValue(months, width);
|
1722 | }
|
1723 | /**
|
1724 | * Retrieves Gregorian-calendar eras for the given locale.
|
1725 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1726 | *
|
1727 | * \@publicApi
|
1728 | * @param {?} locale A locale code for the locale format rules to use.
|
1729 | * @param {?} width The required character width.
|
1730 | * @return {?} An array of localized era strings.
|
1731 | * For example, `[AD, BC]` for `en-US`.
|
1732 | */
|
1733 | function getLocaleEraNames(locale, width) {
|
1734 | /** @type {?} */
|
1735 | const data = ɵfindLocaleData(locale);
|
1736 | /** @type {?} */
|
1737 | const erasData = (/** @type {?} */ (data[ɵLocaleDataIndex.Eras]));
|
1738 | return getLastDefinedValue(erasData, width);
|
1739 | }
|
1740 | /**
|
1741 | * Retrieves the first day of the week for the given locale.
|
1742 | *
|
1743 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1744 | *
|
1745 | * \@publicApi
|
1746 | * @param {?} locale A locale code for the locale format rules to use.
|
1747 | * @return {?} A day index number, using the 0-based week-day index for `en-US`
|
1748 | * (Sunday = 0, Monday = 1, ...).
|
1749 | * For example, for `fr-FR`, returns 1 to indicate that the first day is Monday.
|
1750 | */
|
1751 | function getLocaleFirstDayOfWeek(locale) {
|
1752 | /** @type {?} */
|
1753 | const data = ɵfindLocaleData(locale);
|
1754 | return data[ɵLocaleDataIndex.FirstDayOfWeek];
|
1755 | }
|
1756 | /**
|
1757 | * Range of week days that are considered the week-end for the given locale.
|
1758 | *
|
1759 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1760 | *
|
1761 | * \@publicApi
|
1762 | * @param {?} locale A locale code for the locale format rules to use.
|
1763 | * @return {?} The range of day values, `[startDay, endDay]`.
|
1764 | */
|
1765 | function getLocaleWeekEndRange(locale) {
|
1766 | /** @type {?} */
|
1767 | const data = ɵfindLocaleData(locale);
|
1768 | return data[ɵLocaleDataIndex.WeekendRange];
|
1769 | }
|
1770 | /**
|
1771 | * Retrieves a localized date-value formating string.
|
1772 | *
|
1773 | * @see `FormatWidth` / [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1774 | *
|
1775 | * \@publicApi
|
1776 | * @param {?} locale A locale code for the locale format rules to use.
|
1777 | * @param {?} width The format type.
|
1778 | * @return {?} The localized formating string.
|
1779 | */
|
1780 | function getLocaleDateFormat(locale, width) {
|
1781 | /** @type {?} */
|
1782 | const data = ɵfindLocaleData(locale);
|
1783 | return getLastDefinedValue(data[ɵLocaleDataIndex.DateFormat], width);
|
1784 | }
|
1785 | /**
|
1786 | * Retrieves a localized time-value formatting string.
|
1787 | *
|
1788 | * @see `FormatWidth` / [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1789 | * \@publicApi
|
1790 | * @param {?} locale A locale code for the locale format rules to use.
|
1791 | * @param {?} width The format type.
|
1792 | * @return {?} The localized formatting string.
|
1793 | */
|
1794 | function getLocaleTimeFormat(locale, width) {
|
1795 | /** @type {?} */
|
1796 | const data = ɵfindLocaleData(locale);
|
1797 | return getLastDefinedValue(data[ɵLocaleDataIndex.TimeFormat], width);
|
1798 | }
|
1799 | /**
|
1800 | * Retrieves a localized date-time formatting string.
|
1801 | *
|
1802 | * @see `FormatWidth` / [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1803 | *
|
1804 | * \@publicApi
|
1805 | * @param {?} locale A locale code for the locale format rules to use.
|
1806 | * @param {?} width The format type.
|
1807 | * @return {?} The localized formatting string.
|
1808 | */
|
1809 | function getLocaleDateTimeFormat(locale, width) {
|
1810 | /** @type {?} */
|
1811 | const data = ɵfindLocaleData(locale);
|
1812 | /** @type {?} */
|
1813 | const dateTimeFormatData = (/** @type {?} */ (data[ɵLocaleDataIndex.DateTimeFormat]));
|
1814 | return getLastDefinedValue(dateTimeFormatData, width);
|
1815 | }
|
1816 | /**
|
1817 | * Retrieves a localized number symbol that can be used to replace placeholders in number formats.
|
1818 | * @see `NumberSymbol` / [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1819 | *
|
1820 | * \@publicApi
|
1821 | * @param {?} locale The locale code.
|
1822 | * @param {?} symbol The symbol to localize.
|
1823 | * @return {?} The character for the localized symbol.
|
1824 | */
|
1825 | function getLocaleNumberSymbol(locale, symbol) {
|
1826 | /** @type {?} */
|
1827 | const data = ɵfindLocaleData(locale);
|
1828 | /** @type {?} */
|
1829 | const res = data[ɵLocaleDataIndex.NumberSymbols][symbol];
|
1830 | if (typeof res === 'undefined') {
|
1831 | if (symbol === NumberSymbol.CurrencyDecimal) {
|
1832 | return data[ɵLocaleDataIndex.NumberSymbols][NumberSymbol.Decimal];
|
1833 | }
|
1834 | else if (symbol === NumberSymbol.CurrencyGroup) {
|
1835 | return data[ɵLocaleDataIndex.NumberSymbols][NumberSymbol.Group];
|
1836 | }
|
1837 | }
|
1838 | return res;
|
1839 | }
|
1840 | /**
|
1841 | * Retrieves a number format for a given locale.
|
1842 | *
|
1843 | * Numbers are formatted using patterns, like `#,###.00`. For example, the pattern `#,###.00`
|
1844 | * when used to format the number 12345.678 could result in "12'345,678". That would happen if the
|
1845 | * grouping separator for your language is an apostrophe, and the decimal separator is a comma.
|
1846 | *
|
1847 | * <b>Important:</b> The characters `.` `,` `0` `#` (and others below) are special placeholders
|
1848 | * that stand for the decimal separator, and so on, and are NOT real characters.
|
1849 | * You must NOT "translate" the placeholders. For example, don't change `.` to `,` even though in
|
1850 | * your language the decimal point is written with a comma. The symbols should be replaced by the
|
1851 | * local equivalents, using the appropriate `NumberSymbol` for your language.
|
1852 | *
|
1853 | * Here are the special characters used in number patterns:
|
1854 | *
|
1855 | * | Symbol | Meaning |
|
1856 | * |--------|---------|
|
1857 | * | . | Replaced automatically by the character used for the decimal point. |
|
1858 | * | , | Replaced by the "grouping" (thousands) separator. |
|
1859 | * | 0 | Replaced by a digit (or zero if there aren't enough digits). |
|
1860 | * | # | Replaced by a digit (or nothing if there aren't enough). |
|
1861 | * | ¤ | Replaced by a currency symbol, such as $ or USD. |
|
1862 | * | % | Marks a percent format. The % symbol may change position, but must be retained. |
|
1863 | * | E | Marks a scientific format. The E symbol may change position, but must be retained. |
|
1864 | * | ' | Special characters used as literal characters are quoted with ASCII single quotes. |
|
1865 | *
|
1866 | * @see `NumberFormatStyle` / [CLDR website](http://cldr.unicode.org/translation/number-patterns) / [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1867 | *
|
1868 | * \@publicApi
|
1869 | * @param {?} locale A locale code for the locale format rules to use.
|
1870 | * @param {?} type The type of numeric value to be formatted (such as `Decimal` or `Currency`.)
|
1871 | * @return {?} The localized format string.
|
1872 | */
|
1873 | function getLocaleNumberFormat(locale, type) {
|
1874 | /** @type {?} */
|
1875 | const data = ɵfindLocaleData(locale);
|
1876 | return data[ɵLocaleDataIndex.NumberFormats][type];
|
1877 | }
|
1878 | /**
|
1879 | * Retrieves the symbol used to represent the currency for the main country
|
1880 | * corresponding to a given locale. For example, '$' for `en-US`.
|
1881 | *
|
1882 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1883 | *
|
1884 | * \@publicApi
|
1885 | * @param {?} locale A locale code for the locale format rules to use.
|
1886 | * @return {?} The localized symbol character,
|
1887 | * or `null` if the main country cannot be determined.
|
1888 | */
|
1889 | function getLocaleCurrencySymbol(locale) {
|
1890 | /** @type {?} */
|
1891 | const data = ɵfindLocaleData(locale);
|
1892 | return data[ɵLocaleDataIndex.CurrencySymbol] || null;
|
1893 | }
|
1894 | /**
|
1895 | * Retrieves the name of the currency for the main country corresponding
|
1896 | * to a given locale. For example, 'US Dollar' for `en-US`.
|
1897 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1898 | *
|
1899 | * \@publicApi
|
1900 | * @param {?} locale A locale code for the locale format rules to use.
|
1901 | * @return {?} The currency name,
|
1902 | * or `null` if the main country cannot be determined.
|
1903 | */
|
1904 | function getLocaleCurrencyName(locale) {
|
1905 | /** @type {?} */
|
1906 | const data = ɵfindLocaleData(locale);
|
1907 | return data[ɵLocaleDataIndex.CurrencyName] || null;
|
1908 | }
|
1909 | /**
|
1910 | * Retrieves the default currency code for the given locale.
|
1911 | *
|
1912 | * The default is defined as the first currency which is still in use.
|
1913 | *
|
1914 | * \@publicApi
|
1915 | * @param {?} locale The code of the locale whose currency code we want.
|
1916 | * @return {?} The code of the default currency for the given locale.
|
1917 | *
|
1918 | */
|
1919 | function getLocaleCurrencyCode(locale) {
|
1920 | return ɵgetLocaleCurrencyCode(locale);
|
1921 | }
|
1922 | /**
|
1923 | * Retrieves the currency values for a given locale.
|
1924 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1925 | * @param {?} locale A locale code for the locale format rules to use.
|
1926 | * @return {?} The currency values.
|
1927 | */
|
1928 | function getLocaleCurrencies(locale) {
|
1929 | /** @type {?} */
|
1930 | const data = ɵfindLocaleData(locale);
|
1931 | return data[ɵLocaleDataIndex.Currencies];
|
1932 | }
|
1933 | /**
|
1934 | * \@alias core/ɵgetLocalePluralCase
|
1935 | * \@publicApi
|
1936 | * @type {?}
|
1937 | */
|
1938 | const getLocalePluralCase = ɵgetLocalePluralCase;
|
1939 | /**
|
1940 | * @param {?} data
|
1941 | * @return {?}
|
1942 | */
|
1943 | function checkFullData(data) {
|
1944 | if (!data[ɵLocaleDataIndex.ExtraData]) {
|
1945 | throw new Error(`Missing extra locale data for the locale "${data[ɵLocaleDataIndex.LocaleId]}". Use "registerLocaleData" to load new data. See the "I18n guide" on angular.io to know more.`);
|
1946 | }
|
1947 | }
|
1948 | /**
|
1949 | * Retrieves locale-specific rules used to determine which day period to use
|
1950 | * when more than one period is defined for a locale.
|
1951 | *
|
1952 | * There is a rule for each defined day period. The
|
1953 | * first rule is applied to the first day period and so on.
|
1954 | * Fall back to AM/PM when no rules are available.
|
1955 | *
|
1956 | * A rule can specify a period as time range, or as a single time value.
|
1957 | *
|
1958 | * This functionality is only available when you have loaded the full locale data.
|
1959 | * See the ["I18n guide"](guide/i18n#i18n-pipes).
|
1960 | *
|
1961 | * @see `getLocaleExtraDayPeriods()` / [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1962 | *
|
1963 | * \@publicApi
|
1964 | * @param {?} locale A locale code for the locale format rules to use.
|
1965 | * @return {?} The rules for the locale, a single time value or array of *from-time, to-time*,
|
1966 | * or null if no periods are available.
|
1967 | *
|
1968 | */
|
1969 | function getLocaleExtraDayPeriodRules(locale) {
|
1970 | /** @type {?} */
|
1971 | const data = ɵfindLocaleData(locale);
|
1972 | checkFullData(data);
|
1973 | /** @type {?} */
|
1974 | const rules = data[ɵLocaleDataIndex.ExtraData][2 /* ExtraDayPeriodsRules */] || [];
|
1975 | return rules.map((/**
|
1976 | * @param {?} rule
|
1977 | * @return {?}
|
1978 | */
|
1979 | (rule) => {
|
1980 | if (typeof rule === 'string') {
|
1981 | return extractTime(rule);
|
1982 | }
|
1983 | return [extractTime(rule[0]), extractTime(rule[1])];
|
1984 | }));
|
1985 | }
|
1986 | /**
|
1987 | * Retrieves locale-specific day periods, which indicate roughly how a day is broken up
|
1988 | * in different languages.
|
1989 | * For example, for `en-US`, periods are morning, noon, afternoon, evening, and midnight.
|
1990 | *
|
1991 | * This functionality is only available when you have loaded the full locale data.
|
1992 | * See the ["I18n guide"](guide/i18n#i18n-pipes).
|
1993 | *
|
1994 | * @see `getLocaleExtraDayPeriodRules()` / [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1995 | *
|
1996 | * \@publicApi
|
1997 | * @param {?} locale A locale code for the locale format rules to use.
|
1998 | * @param {?} formStyle The required grammatical form.
|
1999 | * @param {?} width The required character width.
|
2000 | * @return {?} The translated day-period strings.
|
2001 | */
|
2002 | function getLocaleExtraDayPeriods(locale, formStyle, width) {
|
2003 | /** @type {?} */
|
2004 | const data = ɵfindLocaleData(locale);
|
2005 | checkFullData(data);
|
2006 | /** @type {?} */
|
2007 | const dayPeriodsData = (/** @type {?} */ ([
|
2008 | data[ɵLocaleDataIndex.ExtraData][0 /* ExtraDayPeriodFormats */],
|
2009 | data[ɵLocaleDataIndex.ExtraData][1 /* ExtraDayPeriodStandalone */]
|
2010 | ]));
|
2011 | /** @type {?} */
|
2012 | const dayPeriods = getLastDefinedValue(dayPeriodsData, formStyle) || [];
|
2013 | return getLastDefinedValue(dayPeriods, width) || [];
|
2014 | }
|
2015 | /**
|
2016 | * Retrieves the first value that is defined in an array, going backwards from an index position.
|
2017 | *
|
2018 | * To avoid repeating the same data (as when the "format" and "standalone" forms are the same)
|
2019 | * add the first value to the locale data arrays, and add other values only if they are different.
|
2020 | *
|
2021 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
2022 | *
|
2023 | * \@publicApi
|
2024 | * @template T
|
2025 | * @param {?} data The data array to retrieve from.
|
2026 | * @param {?} index A 0-based index into the array to start from.
|
2027 | * @return {?} The value immediately before the given index position.
|
2028 | */
|
2029 | function getLastDefinedValue(data, index) {
|
2030 | for (let i = index; i > -1; i--) {
|
2031 | if (typeof data[i] !== 'undefined') {
|
2032 | return data[i];
|
2033 | }
|
2034 | }
|
2035 | throw new Error('Locale data API: locale data undefined');
|
2036 | }
|
2037 | /**
|
2038 | * Extracts the hours and minutes from a string like "15:45"
|
2039 | * @param {?} time
|
2040 | * @return {?}
|
2041 | */
|
2042 | function extractTime(time) {
|
2043 | const [h, m] = time.split(':');
|
2044 | return { hours: +h, minutes: +m };
|
2045 | }
|
2046 | /**
|
2047 | * Retrieves the currency symbol for a given currency code.
|
2048 | *
|
2049 | * For example, for the default `en-US` locale, the code `USD` can
|
2050 | * be represented by the narrow symbol `$` or the wide symbol `US$`.
|
2051 | *
|
2052 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
2053 | *
|
2054 | * \@publicApi
|
2055 | * @param {?} code The currency code.
|
2056 | * @param {?} format The format, `wide` or `narrow`.
|
2057 | * @param {?=} locale A locale code for the locale format rules to use.
|
2058 | *
|
2059 | * @return {?} The symbol, or the currency code if no symbol is available.
|
2060 | */
|
2061 | function getCurrencySymbol(code, format, locale = 'en') {
|
2062 | /** @type {?} */
|
2063 | const currency = getLocaleCurrencies(locale)[code] || CURRENCIES_EN[code] || [];
|
2064 | /** @type {?} */
|
2065 | const symbolNarrow = currency[1 /* SymbolNarrow */];
|
2066 | if (format === 'narrow' && typeof symbolNarrow === 'string') {
|
2067 | return symbolNarrow;
|
2068 | }
|
2069 | return currency[0 /* Symbol */] || code;
|
2070 | }
|
2071 | // Most currencies have cents, that's why the default is 2
|
2072 | /** @type {?} */
|
2073 | const DEFAULT_NB_OF_CURRENCY_DIGITS = 2;
|
2074 | /**
|
2075 | * Reports the number of decimal digits for a given currency.
|
2076 | * The value depends upon the presence of cents in that particular currency.
|
2077 | *
|
2078 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
2079 | *
|
2080 | * \@publicApi
|
2081 | * @param {?} code The currency code.
|
2082 | * @return {?} The number of decimal digits, typically 0 or 2.
|
2083 | */
|
2084 | function getNumberOfCurrencyDigits(code) {
|
2085 | /** @type {?} */
|
2086 | let digits;
|
2087 | /** @type {?} */
|
2088 | const currency = CURRENCIES_EN[code];
|
2089 | if (currency) {
|
2090 | digits = currency[2 /* NbOfDigits */];
|
2091 | }
|
2092 | return typeof digits === 'number' ? digits : DEFAULT_NB_OF_CURRENCY_DIGITS;
|
2093 | }
|
2094 |
|
2095 | /**
|
2096 | * @fileoverview added by tsickle
|
2097 | * Generated from: packages/common/src/i18n/format_date.ts
|
2098 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
2099 | */
|
2100 | /** @type {?} */
|
2101 | const ISO8601_DATE_REGEX = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
|
2102 | // 1 2 3 4 5 6 7 8 9 10 11
|
2103 | /** @type {?} */
|
2104 | const NAMED_FORMATS = {};
|
2105 | /** @type {?} */
|
2106 | const DATE_FORMATS_SPLIT = /((?:[^GyMLwWdEabBhHmsSzZO']+)|(?:'(?:[^']|'')*')|(?:G{1,5}|y{1,4}|M{1,5}|L{1,5}|w{1,2}|W{1}|d{1,2}|E{1,6}|a{1,5}|b{1,5}|B{1,5}|h{1,2}|H{1,2}|m{1,2}|s{1,2}|S{1,3}|z{1,4}|Z{1,5}|O{1,4}))([\s\S]*)/;
|
2107 | /** @enum {number} */
|
2108 | const ZoneWidth = {
|
2109 | Short: 0,
|
2110 | ShortGMT: 1,
|
2111 | Long: 2,
|
2112 | Extended: 3,
|
2113 | };
|
2114 | ZoneWidth[ZoneWidth.Short] = 'Short';
|
2115 | ZoneWidth[ZoneWidth.ShortGMT] = 'ShortGMT';
|
2116 | ZoneWidth[ZoneWidth.Long] = 'Long';
|
2117 | ZoneWidth[ZoneWidth.Extended] = 'Extended';
|
2118 | /** @enum {number} */
|
2119 | const DateType = {
|
2120 | FullYear: 0,
|
2121 | Month: 1,
|
2122 | Date: 2,
|
2123 | Hours: 3,
|
2124 | Minutes: 4,
|
2125 | Seconds: 5,
|
2126 | FractionalSeconds: 6,
|
2127 | Day: 7,
|
2128 | };
|
2129 | DateType[DateType.FullYear] = 'FullYear';
|
2130 | DateType[DateType.Month] = 'Month';
|
2131 | DateType[DateType.Date] = 'Date';
|
2132 | DateType[DateType.Hours] = 'Hours';
|
2133 | DateType[DateType.Minutes] = 'Minutes';
|
2134 | DateType[DateType.Seconds] = 'Seconds';
|
2135 | DateType[DateType.FractionalSeconds] = 'FractionalSeconds';
|
2136 | DateType[DateType.Day] = 'Day';
|
2137 | /** @enum {number} */
|
2138 | const TranslationType = {
|
2139 | DayPeriods: 0,
|
2140 | Days: 1,
|
2141 | Months: 2,
|
2142 | Eras: 3,
|
2143 | };
|
2144 | TranslationType[TranslationType.DayPeriods] = 'DayPeriods';
|
2145 | TranslationType[TranslationType.Days] = 'Days';
|
2146 | TranslationType[TranslationType.Months] = 'Months';
|
2147 | TranslationType[TranslationType.Eras] = 'Eras';
|
2148 | /**
|
2149 | * \@ngModule CommonModule
|
2150 | * \@description
|
2151 | *
|
2152 | * Formats a date according to locale rules.
|
2153 | *
|
2154 | * @see `DatePipe` / [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
2155 | *
|
2156 | * \@publicApi
|
2157 | * @param {?} value The date to format, as a Date, or a number (milliseconds since UTC epoch)
|
2158 | * or an [ISO date-time string](https://www.w3.org/TR/NOTE-datetime).
|
2159 | * @param {?} format The date-time components to include. See `DatePipe` for details.
|
2160 | * @param {?} locale A locale code for the locale format rules to use.
|
2161 | * @param {?=} timezone The time zone. A time zone offset from GMT (such as `'+0430'`),
|
2162 | * or a standard UTC/GMT or continental US time zone abbreviation.
|
2163 | * If not specified, uses host system settings.
|
2164 | *
|
2165 | * @return {?} The formatted date string.
|
2166 | *
|
2167 | */
|
2168 | function formatDate(value, format, locale, timezone) {
|
2169 | /** @type {?} */
|
2170 | let date = toDate(value);
|
2171 | /** @type {?} */
|
2172 | const namedFormat = getNamedFormat(locale, format);
|
2173 | format = namedFormat || format;
|
2174 | /** @type {?} */
|
2175 | let parts = [];
|
2176 | /** @type {?} */
|
2177 | let match;
|
2178 | while (format) {
|
2179 | match = DATE_FORMATS_SPLIT.exec(format);
|
2180 | if (match) {
|
2181 | parts = parts.concat(match.slice(1));
|
2182 | /** @type {?} */
|
2183 | const part = parts.pop();
|
2184 | if (!part) {
|
2185 | break;
|
2186 | }
|
2187 | format = part;
|
2188 | }
|
2189 | else {
|
2190 | parts.push(format);
|
2191 | break;
|
2192 | }
|
2193 | }
|
2194 | /** @type {?} */
|
2195 | let dateTimezoneOffset = date.getTimezoneOffset();
|
2196 | if (timezone) {
|
2197 | dateTimezoneOffset = timezoneToOffset(timezone, dateTimezoneOffset);
|
2198 | date = convertTimezoneToLocal(date, timezone, true);
|
2199 | }
|
2200 | /** @type {?} */
|
2201 | let text = '';
|
2202 | parts.forEach((/**
|
2203 | * @param {?} value
|
2204 | * @return {?}
|
2205 | */
|
2206 | value => {
|
2207 | /** @type {?} */
|
2208 | const dateFormatter = getDateFormatter(value);
|
2209 | text += dateFormatter ?
|
2210 | dateFormatter(date, locale, dateTimezoneOffset) :
|
2211 | value === '\'\'' ? '\'' : value.replace(/(^'|'$)/g, '').replace(/''/g, '\'');
|
2212 | }));
|
2213 | return text;
|
2214 | }
|
2215 | /**
|
2216 | * @param {?} locale
|
2217 | * @param {?} format
|
2218 | * @return {?}
|
2219 | */
|
2220 | function getNamedFormat(locale, format) {
|
2221 | /** @type {?} */
|
2222 | const localeId = getLocaleId(locale);
|
2223 | NAMED_FORMATS[localeId] = NAMED_FORMATS[localeId] || {};
|
2224 | if (NAMED_FORMATS[localeId][format]) {
|
2225 | return NAMED_FORMATS[localeId][format];
|
2226 | }
|
2227 | /** @type {?} */
|
2228 | let formatValue = '';
|
2229 | switch (format) {
|
2230 | case 'shortDate':
|
2231 | formatValue = getLocaleDateFormat(locale, FormatWidth.Short);
|
2232 | break;
|
2233 | case 'mediumDate':
|
2234 | formatValue = getLocaleDateFormat(locale, FormatWidth.Medium);
|
2235 | break;
|
2236 | case 'longDate':
|
2237 | formatValue = getLocaleDateFormat(locale, FormatWidth.Long);
|
2238 | break;
|
2239 | case 'fullDate':
|
2240 | formatValue = getLocaleDateFormat(locale, FormatWidth.Full);
|
2241 | break;
|
2242 | case 'shortTime':
|
2243 | formatValue = getLocaleTimeFormat(locale, FormatWidth.Short);
|
2244 | break;
|
2245 | case 'mediumTime':
|
2246 | formatValue = getLocaleTimeFormat(locale, FormatWidth.Medium);
|
2247 | break;
|
2248 | case 'longTime':
|
2249 | formatValue = getLocaleTimeFormat(locale, FormatWidth.Long);
|
2250 | break;
|
2251 | case 'fullTime':
|
2252 | formatValue = getLocaleTimeFormat(locale, FormatWidth.Full);
|
2253 | break;
|
2254 | case 'short':
|
2255 | /** @type {?} */
|
2256 | const shortTime = getNamedFormat(locale, 'shortTime');
|
2257 | /** @type {?} */
|
2258 | const shortDate = getNamedFormat(locale, 'shortDate');
|
2259 | formatValue = formatDateTime(getLocaleDateTimeFormat(locale, FormatWidth.Short), [shortTime, shortDate]);
|
2260 | break;
|
2261 | case 'medium':
|
2262 | /** @type {?} */
|
2263 | const mediumTime = getNamedFormat(locale, 'mediumTime');
|
2264 | /** @type {?} */
|
2265 | const mediumDate = getNamedFormat(locale, 'mediumDate');
|
2266 | formatValue = formatDateTime(getLocaleDateTimeFormat(locale, FormatWidth.Medium), [mediumTime, mediumDate]);
|
2267 | break;
|
2268 | case 'long':
|
2269 | /** @type {?} */
|
2270 | const longTime = getNamedFormat(locale, 'longTime');
|
2271 | /** @type {?} */
|
2272 | const longDate = getNamedFormat(locale, 'longDate');
|
2273 | formatValue =
|
2274 | formatDateTime(getLocaleDateTimeFormat(locale, FormatWidth.Long), [longTime, longDate]);
|
2275 | break;
|
2276 | case 'full':
|
2277 | /** @type {?} */
|
2278 | const fullTime = getNamedFormat(locale, 'fullTime');
|
2279 | /** @type {?} */
|
2280 | const fullDate = getNamedFormat(locale, 'fullDate');
|
2281 | formatValue =
|
2282 | formatDateTime(getLocaleDateTimeFormat(locale, FormatWidth.Full), [fullTime, fullDate]);
|
2283 | break;
|
2284 | }
|
2285 | if (formatValue) {
|
2286 | NAMED_FORMATS[localeId][format] = formatValue;
|
2287 | }
|
2288 | return formatValue;
|
2289 | }
|
2290 | /**
|
2291 | * @param {?} str
|
2292 | * @param {?} opt_values
|
2293 | * @return {?}
|
2294 | */
|
2295 | function formatDateTime(str, opt_values) {
|
2296 | if (opt_values) {
|
2297 | str = str.replace(/\{([^}]+)}/g, (/**
|
2298 | * @param {?} match
|
2299 | * @param {?} key
|
2300 | * @return {?}
|
2301 | */
|
2302 | function (match, key) {
|
2303 | return (opt_values != null && key in opt_values) ? opt_values[key] : match;
|
2304 | }));
|
2305 | }
|
2306 | return str;
|
2307 | }
|
2308 | /**
|
2309 | * @param {?} num
|
2310 | * @param {?} digits
|
2311 | * @param {?=} minusSign
|
2312 | * @param {?=} trim
|
2313 | * @param {?=} negWrap
|
2314 | * @return {?}
|
2315 | */
|
2316 | function padNumber(num, digits, minusSign = '-', trim, negWrap) {
|
2317 | /** @type {?} */
|
2318 | let neg = '';
|
2319 | if (num < 0 || (negWrap && num <= 0)) {
|
2320 | if (negWrap) {
|
2321 | num = -num + 1;
|
2322 | }
|
2323 | else {
|
2324 | num = -num;
|
2325 | neg = minusSign;
|
2326 | }
|
2327 | }
|
2328 | /** @type {?} */
|
2329 | let strNum = String(num);
|
2330 | while (strNum.length < digits) {
|
2331 | strNum = '0' + strNum;
|
2332 | }
|
2333 | if (trim) {
|
2334 | strNum = strNum.substr(strNum.length - digits);
|
2335 | }
|
2336 | return neg + strNum;
|
2337 | }
|
2338 | /**
|
2339 | * @param {?} milliseconds
|
2340 | * @param {?} digits
|
2341 | * @return {?}
|
2342 | */
|
2343 | function formatFractionalSeconds(milliseconds, digits) {
|
2344 | /** @type {?} */
|
2345 | const strMs = padNumber(milliseconds, 3);
|
2346 | return strMs.substr(0, digits);
|
2347 | }
|
2348 | /**
|
2349 | * Returns a date formatter that transforms a date into its locale digit representation
|
2350 | * @param {?} name
|
2351 | * @param {?} size
|
2352 | * @param {?=} offset
|
2353 | * @param {?=} trim
|
2354 | * @param {?=} negWrap
|
2355 | * @return {?}
|
2356 | */
|
2357 | function dateGetter(name, size, offset = 0, trim = false, negWrap = false) {
|
2358 | return (/**
|
2359 | * @param {?} date
|
2360 | * @param {?} locale
|
2361 | * @return {?}
|
2362 | */
|
2363 | function (date, locale) {
|
2364 | /** @type {?} */
|
2365 | let part = getDatePart(name, date);
|
2366 | if (offset > 0 || part > -offset) {
|
2367 | part += offset;
|
2368 | }
|
2369 | if (name === DateType.Hours) {
|
2370 | if (part === 0 && offset === -12) {
|
2371 | part = 12;
|
2372 | }
|
2373 | }
|
2374 | else if (name === DateType.FractionalSeconds) {
|
2375 | return formatFractionalSeconds(part, size);
|
2376 | }
|
2377 | /** @type {?} */
|
2378 | const localeMinus = getLocaleNumberSymbol(locale, NumberSymbol.MinusSign);
|
2379 | return padNumber(part, size, localeMinus, trim, negWrap);
|
2380 | });
|
2381 | }
|
2382 | /**
|
2383 | * @param {?} part
|
2384 | * @param {?} date
|
2385 | * @return {?}
|
2386 | */
|
2387 | function getDatePart(part, date) {
|
2388 | switch (part) {
|
2389 | case DateType.FullYear:
|
2390 | return date.getFullYear();
|
2391 | case DateType.Month:
|
2392 | return date.getMonth();
|
2393 | case DateType.Date:
|
2394 | return date.getDate();
|
2395 | case DateType.Hours:
|
2396 | return date.getHours();
|
2397 | case DateType.Minutes:
|
2398 | return date.getMinutes();
|
2399 | case DateType.Seconds:
|
2400 | return date.getSeconds();
|
2401 | case DateType.FractionalSeconds:
|
2402 | return date.getMilliseconds();
|
2403 | case DateType.Day:
|
2404 | return date.getDay();
|
2405 | default:
|
2406 | throw new Error(`Unknown DateType value "${part}".`);
|
2407 | }
|
2408 | }
|
2409 | /**
|
2410 | * Returns a date formatter that transforms a date into its locale string representation
|
2411 | * @param {?} name
|
2412 | * @param {?} width
|
2413 | * @param {?=} form
|
2414 | * @param {?=} extended
|
2415 | * @return {?}
|
2416 | */
|
2417 | function dateStrGetter(name, width, form = FormStyle.Format, extended = false) {
|
2418 | return (/**
|
2419 | * @param {?} date
|
2420 | * @param {?} locale
|
2421 | * @return {?}
|
2422 | */
|
2423 | function (date, locale) {
|
2424 | return getDateTranslation(date, locale, name, width, form, extended);
|
2425 | });
|
2426 | }
|
2427 | /**
|
2428 | * Returns the locale translation of a date for a given form, type and width
|
2429 | * @param {?} date
|
2430 | * @param {?} locale
|
2431 | * @param {?} name
|
2432 | * @param {?} width
|
2433 | * @param {?} form
|
2434 | * @param {?} extended
|
2435 | * @return {?}
|
2436 | */
|
2437 | function getDateTranslation(date, locale, name, width, form, extended) {
|
2438 | switch (name) {
|
2439 | case TranslationType.Months:
|
2440 | return getLocaleMonthNames(locale, form, width)[date.getMonth()];
|
2441 | case TranslationType.Days:
|
2442 | return getLocaleDayNames(locale, form, width)[date.getDay()];
|
2443 | case TranslationType.DayPeriods:
|
2444 | /** @type {?} */
|
2445 | const currentHours = date.getHours();
|
2446 | /** @type {?} */
|
2447 | const currentMinutes = date.getMinutes();
|
2448 | if (extended) {
|
2449 | /** @type {?} */
|
2450 | const rules = getLocaleExtraDayPeriodRules(locale);
|
2451 | /** @type {?} */
|
2452 | const dayPeriods = getLocaleExtraDayPeriods(locale, form, width);
|
2453 | /** @type {?} */
|
2454 | let result;
|
2455 | rules.forEach((/**
|
2456 | * @param {?} rule
|
2457 | * @param {?} index
|
2458 | * @return {?}
|
2459 | */
|
2460 | (rule, index) => {
|
2461 | if (Array.isArray(rule)) {
|
2462 | // morning, afternoon, evening, night
|
2463 | const { hours: hoursFrom, minutes: minutesFrom } = rule[0];
|
2464 | const { hours: hoursTo, minutes: minutesTo } = rule[1];
|
2465 | if (currentHours >= hoursFrom && currentMinutes >= minutesFrom &&
|
2466 | (currentHours < hoursTo ||
|
2467 | (currentHours === hoursTo && currentMinutes < minutesTo))) {
|
2468 | result = dayPeriods[index];
|
2469 | }
|
2470 | }
|
2471 | else { // noon or midnight
|
2472 | // noon or midnight
|
2473 | const { hours, minutes } = rule;
|
2474 | if (hours === currentHours && minutes === currentMinutes) {
|
2475 | result = dayPeriods[index];
|
2476 | }
|
2477 | }
|
2478 | }));
|
2479 | if (result) {
|
2480 | return result;
|
2481 | }
|
2482 | }
|
2483 | // if no rules for the day periods, we use am/pm by default
|
2484 | return getLocaleDayPeriods(locale, form, (/** @type {?} */ (width)))[currentHours < 12 ? 0 : 1];
|
2485 | case TranslationType.Eras:
|
2486 | return getLocaleEraNames(locale, (/** @type {?} */ (width)))[date.getFullYear() <= 0 ? 0 : 1];
|
2487 | default:
|
2488 | // This default case is not needed by TypeScript compiler, as the switch is exhaustive.
|
2489 | // However Closure Compiler does not understand that and reports an error in typed mode.
|
2490 | // The `throw new Error` below works around the problem, and the unexpected: never variable
|
2491 | // makes sure tsc still checks this code is unreachable.
|
2492 | /** @type {?} */
|
2493 | const unexpected = name;
|
2494 | throw new Error(`unexpected translation type ${unexpected}`);
|
2495 | }
|
2496 | }
|
2497 | /**
|
2498 | * Returns a date formatter that transforms a date and an offset into a timezone with ISO8601 or
|
2499 | * GMT format depending on the width (eg: short = +0430, short:GMT = GMT+4, long = GMT+04:30,
|
2500 | * extended = +04:30)
|
2501 | * @param {?} width
|
2502 | * @return {?}
|
2503 | */
|
2504 | function timeZoneGetter(width) {
|
2505 | return (/**
|
2506 | * @param {?} date
|
2507 | * @param {?} locale
|
2508 | * @param {?} offset
|
2509 | * @return {?}
|
2510 | */
|
2511 | function (date, locale, offset) {
|
2512 | /** @type {?} */
|
2513 | const zone = -1 * offset;
|
2514 | /** @type {?} */
|
2515 | const minusSign = getLocaleNumberSymbol(locale, NumberSymbol.MinusSign);
|
2516 | /** @type {?} */
|
2517 | const hours = zone > 0 ? Math.floor(zone / 60) : Math.ceil(zone / 60);
|
2518 | switch (width) {
|
2519 | case ZoneWidth.Short:
|
2520 | return ((zone >= 0) ? '+' : '') + padNumber(hours, 2, minusSign) +
|
2521 | padNumber(Math.abs(zone % 60), 2, minusSign);
|
2522 | case ZoneWidth.ShortGMT:
|
2523 | return 'GMT' + ((zone >= 0) ? '+' : '') + padNumber(hours, 1, minusSign);
|
2524 | case ZoneWidth.Long:
|
2525 | return 'GMT' + ((zone >= 0) ? '+' : '') + padNumber(hours, 2, minusSign) + ':' +
|
2526 | padNumber(Math.abs(zone % 60), 2, minusSign);
|
2527 | case ZoneWidth.Extended:
|
2528 | if (offset === 0) {
|
2529 | return 'Z';
|
2530 | }
|
2531 | else {
|
2532 | return ((zone >= 0) ? '+' : '') + padNumber(hours, 2, minusSign) + ':' +
|
2533 | padNumber(Math.abs(zone % 60), 2, minusSign);
|
2534 | }
|
2535 | default:
|
2536 | throw new Error(`Unknown zone width "${width}"`);
|
2537 | }
|
2538 | });
|
2539 | }
|
2540 | /** @type {?} */
|
2541 | const JANUARY = 0;
|
2542 | /** @type {?} */
|
2543 | const THURSDAY = 4;
|
2544 | /**
|
2545 | * @param {?} year
|
2546 | * @return {?}
|
2547 | */
|
2548 | function getFirstThursdayOfYear(year) {
|
2549 | /** @type {?} */
|
2550 | const firstDayOfYear = (new Date(year, JANUARY, 1)).getDay();
|
2551 | return new Date(year, 0, 1 + ((firstDayOfYear <= THURSDAY) ? THURSDAY : THURSDAY + 7) - firstDayOfYear);
|
2552 | }
|
2553 | /**
|
2554 | * @param {?} datetime
|
2555 | * @return {?}
|
2556 | */
|
2557 | function getThursdayThisWeek(datetime) {
|
2558 | return new Date(datetime.getFullYear(), datetime.getMonth(), datetime.getDate() + (THURSDAY - datetime.getDay()));
|
2559 | }
|
2560 | /**
|
2561 | * @param {?} size
|
2562 | * @param {?=} monthBased
|
2563 | * @return {?}
|
2564 | */
|
2565 | function weekGetter(size, monthBased = false) {
|
2566 | return (/**
|
2567 | * @param {?} date
|
2568 | * @param {?} locale
|
2569 | * @return {?}
|
2570 | */
|
2571 | function (date, locale) {
|
2572 | /** @type {?} */
|
2573 | let result;
|
2574 | if (monthBased) {
|
2575 | /** @type {?} */
|
2576 | const nbDaysBefore1stDayOfMonth = new Date(date.getFullYear(), date.getMonth(), 1).getDay() - 1;
|
2577 | /** @type {?} */
|
2578 | const today = date.getDate();
|
2579 | result = 1 + Math.floor((today + nbDaysBefore1stDayOfMonth) / 7);
|
2580 | }
|
2581 | else {
|
2582 | /** @type {?} */
|
2583 | const firstThurs = getFirstThursdayOfYear(date.getFullYear());
|
2584 | /** @type {?} */
|
2585 | const thisThurs = getThursdayThisWeek(date);
|
2586 | /** @type {?} */
|
2587 | const diff = thisThurs.getTime() - firstThurs.getTime();
|
2588 | result = 1 + Math.round(diff / 6.048e8); // 6.048e8 ms per week
|
2589 | }
|
2590 | return padNumber(result, size, getLocaleNumberSymbol(locale, NumberSymbol.MinusSign));
|
2591 | });
|
2592 | }
|
2593 | /** @type {?} */
|
2594 | const DATE_FORMATS = {};
|
2595 | // Based on CLDR formats:
|
2596 | // See complete list: http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
2597 | // See also explanations: http://cldr.unicode.org/translation/date-time
|
2598 | // TODO(ocombe): support all missing cldr formats: Y, U, Q, D, F, e, c, j, J, C, A, v, V, X, x
|
2599 | /**
|
2600 | * @param {?} format
|
2601 | * @return {?}
|
2602 | */
|
2603 | function getDateFormatter(format) {
|
2604 | if (DATE_FORMATS[format]) {
|
2605 | return DATE_FORMATS[format];
|
2606 | }
|
2607 | /** @type {?} */
|
2608 | let formatter;
|
2609 | switch (format) {
|
2610 | // Era name (AD/BC)
|
2611 | case 'G':
|
2612 | case 'GG':
|
2613 | case 'GGG':
|
2614 | formatter = dateStrGetter(TranslationType.Eras, TranslationWidth.Abbreviated);
|
2615 | break;
|
2616 | case 'GGGG':
|
2617 | formatter = dateStrGetter(TranslationType.Eras, TranslationWidth.Wide);
|
2618 | break;
|
2619 | case 'GGGGG':
|
2620 | formatter = dateStrGetter(TranslationType.Eras, TranslationWidth.Narrow);
|
2621 | break;
|
2622 | // 1 digit representation of the year, e.g. (AD 1 => 1, AD 199 => 199)
|
2623 | case 'y':
|
2624 | formatter = dateGetter(DateType.FullYear, 1, 0, false, true);
|
2625 | break;
|
2626 | // 2 digit representation of the year, padded (00-99). (e.g. AD 2001 => 01, AD 2010 => 10)
|
2627 | case 'yy':
|
2628 | formatter = dateGetter(DateType.FullYear, 2, 0, true, true);
|
2629 | break;
|
2630 | // 3 digit representation of the year, padded (000-999). (e.g. AD 2001 => 01, AD 2010 => 10)
|
2631 | case 'yyy':
|
2632 | formatter = dateGetter(DateType.FullYear, 3, 0, false, true);
|
2633 | break;
|
2634 | // 4 digit representation of the year (e.g. AD 1 => 0001, AD 2010 => 2010)
|
2635 | case 'yyyy':
|
2636 | formatter = dateGetter(DateType.FullYear, 4, 0, false, true);
|
2637 | break;
|
2638 | // Month of the year (1-12), numeric
|
2639 | case 'M':
|
2640 | case 'L':
|
2641 | formatter = dateGetter(DateType.Month, 1, 1);
|
2642 | break;
|
2643 | case 'MM':
|
2644 | case 'LL':
|
2645 | formatter = dateGetter(DateType.Month, 2, 1);
|
2646 | break;
|
2647 | // Month of the year (January, ...), string, format
|
2648 | case 'MMM':
|
2649 | formatter = dateStrGetter(TranslationType.Months, TranslationWidth.Abbreviated);
|
2650 | break;
|
2651 | case 'MMMM':
|
2652 | formatter = dateStrGetter(TranslationType.Months, TranslationWidth.Wide);
|
2653 | break;
|
2654 | case 'MMMMM':
|
2655 | formatter = dateStrGetter(TranslationType.Months, TranslationWidth.Narrow);
|
2656 | break;
|
2657 | // Month of the year (January, ...), string, standalone
|
2658 | case 'LLL':
|
2659 | formatter =
|
2660 | dateStrGetter(TranslationType.Months, TranslationWidth.Abbreviated, FormStyle.Standalone);
|
2661 | break;
|
2662 | case 'LLLL':
|
2663 | formatter =
|
2664 | dateStrGetter(TranslationType.Months, TranslationWidth.Wide, FormStyle.Standalone);
|
2665 | break;
|
2666 | case 'LLLLL':
|
2667 | formatter =
|
2668 | dateStrGetter(TranslationType.Months, TranslationWidth.Narrow, FormStyle.Standalone);
|
2669 | break;
|
2670 | // Week of the year (1, ... 52)
|
2671 | case 'w':
|
2672 | formatter = weekGetter(1);
|
2673 | break;
|
2674 | case 'ww':
|
2675 | formatter = weekGetter(2);
|
2676 | break;
|
2677 | // Week of the month (1, ...)
|
2678 | case 'W':
|
2679 | formatter = weekGetter(1, true);
|
2680 | break;
|
2681 | // Day of the month (1-31)
|
2682 | case 'd':
|
2683 | formatter = dateGetter(DateType.Date, 1);
|
2684 | break;
|
2685 | case 'dd':
|
2686 | formatter = dateGetter(DateType.Date, 2);
|
2687 | break;
|
2688 | // Day of the Week
|
2689 | case 'E':
|
2690 | case 'EE':
|
2691 | case 'EEE':
|
2692 | formatter = dateStrGetter(TranslationType.Days, TranslationWidth.Abbreviated);
|
2693 | break;
|
2694 | case 'EEEE':
|
2695 | formatter = dateStrGetter(TranslationType.Days, TranslationWidth.Wide);
|
2696 | break;
|
2697 | case 'EEEEE':
|
2698 | formatter = dateStrGetter(TranslationType.Days, TranslationWidth.Narrow);
|
2699 | break;
|
2700 | case 'EEEEEE':
|
2701 | formatter = dateStrGetter(TranslationType.Days, TranslationWidth.Short);
|
2702 | break;
|
2703 | // Generic period of the day (am-pm)
|
2704 | case 'a':
|
2705 | case 'aa':
|
2706 | case 'aaa':
|
2707 | formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Abbreviated);
|
2708 | break;
|
2709 | case 'aaaa':
|
2710 | formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Wide);
|
2711 | break;
|
2712 | case 'aaaaa':
|
2713 | formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Narrow);
|
2714 | break;
|
2715 | // Extended period of the day (midnight, at night, ...), standalone
|
2716 | case 'b':
|
2717 | case 'bb':
|
2718 | case 'bbb':
|
2719 | formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Abbreviated, FormStyle.Standalone, true);
|
2720 | break;
|
2721 | case 'bbbb':
|
2722 | formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Wide, FormStyle.Standalone, true);
|
2723 | break;
|
2724 | case 'bbbbb':
|
2725 | formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Narrow, FormStyle.Standalone, true);
|
2726 | break;
|
2727 | // Extended period of the day (midnight, night, ...), standalone
|
2728 | case 'B':
|
2729 | case 'BB':
|
2730 | case 'BBB':
|
2731 | formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Abbreviated, FormStyle.Format, true);
|
2732 | break;
|
2733 | case 'BBBB':
|
2734 | formatter =
|
2735 | dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Wide, FormStyle.Format, true);
|
2736 | break;
|
2737 | case 'BBBBB':
|
2738 | formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Narrow, FormStyle.Format, true);
|
2739 | break;
|
2740 | // Hour in AM/PM, (1-12)
|
2741 | case 'h':
|
2742 | formatter = dateGetter(DateType.Hours, 1, -12);
|
2743 | break;
|
2744 | case 'hh':
|
2745 | formatter = dateGetter(DateType.Hours, 2, -12);
|
2746 | break;
|
2747 | // Hour of the day (0-23)
|
2748 | case 'H':
|
2749 | formatter = dateGetter(DateType.Hours, 1);
|
2750 | break;
|
2751 | // Hour in day, padded (00-23)
|
2752 | case 'HH':
|
2753 | formatter = dateGetter(DateType.Hours, 2);
|
2754 | break;
|
2755 | // Minute of the hour (0-59)
|
2756 | case 'm':
|
2757 | formatter = dateGetter(DateType.Minutes, 1);
|
2758 | break;
|
2759 | case 'mm':
|
2760 | formatter = dateGetter(DateType.Minutes, 2);
|
2761 | break;
|
2762 | // Second of the minute (0-59)
|
2763 | case 's':
|
2764 | formatter = dateGetter(DateType.Seconds, 1);
|
2765 | break;
|
2766 | case 'ss':
|
2767 | formatter = dateGetter(DateType.Seconds, 2);
|
2768 | break;
|
2769 | // Fractional second
|
2770 | case 'S':
|
2771 | formatter = dateGetter(DateType.FractionalSeconds, 1);
|
2772 | break;
|
2773 | case 'SS':
|
2774 | formatter = dateGetter(DateType.FractionalSeconds, 2);
|
2775 | break;
|
2776 | case 'SSS':
|
2777 | formatter = dateGetter(DateType.FractionalSeconds, 3);
|
2778 | break;
|
2779 | // Timezone ISO8601 short format (-0430)
|
2780 | case 'Z':
|
2781 | case 'ZZ':
|
2782 | case 'ZZZ':
|
2783 | formatter = timeZoneGetter(ZoneWidth.Short);
|
2784 | break;
|
2785 | // Timezone ISO8601 extended format (-04:30)
|
2786 | case 'ZZZZZ':
|
2787 | formatter = timeZoneGetter(ZoneWidth.Extended);
|
2788 | break;
|
2789 | // Timezone GMT short format (GMT+4)
|
2790 | case 'O':
|
2791 | case 'OO':
|
2792 | case 'OOO':
|
2793 | // Should be location, but fallback to format O instead because we don't have the data yet
|
2794 | case 'z':
|
2795 | case 'zz':
|
2796 | case 'zzz':
|
2797 | formatter = timeZoneGetter(ZoneWidth.ShortGMT);
|
2798 | break;
|
2799 | // Timezone GMT long format (GMT+0430)
|
2800 | case 'OOOO':
|
2801 | case 'ZZZZ':
|
2802 | // Should be location, but fallback to format O instead because we don't have the data yet
|
2803 | case 'zzzz':
|
2804 | formatter = timeZoneGetter(ZoneWidth.Long);
|
2805 | break;
|
2806 | default:
|
2807 | return null;
|
2808 | }
|
2809 | DATE_FORMATS[format] = formatter;
|
2810 | return formatter;
|
2811 | }
|
2812 | /**
|
2813 | * @param {?} timezone
|
2814 | * @param {?} fallback
|
2815 | * @return {?}
|
2816 | */
|
2817 | function timezoneToOffset(timezone, fallback) {
|
2818 | // Support: IE 9-11 only, Edge 13-15+
|
2819 | // IE/Edge do not "understand" colon (`:`) in timezone
|
2820 | timezone = timezone.replace(/:/g, '');
|
2821 | /** @type {?} */
|
2822 | const requestedTimezoneOffset = Date.parse('Jan 01, 1970 00:00:00 ' + timezone) / 60000;
|
2823 | return isNaN(requestedTimezoneOffset) ? fallback : requestedTimezoneOffset;
|
2824 | }
|
2825 | /**
|
2826 | * @param {?} date
|
2827 | * @param {?} minutes
|
2828 | * @return {?}
|
2829 | */
|
2830 | function addDateMinutes(date, minutes) {
|
2831 | date = new Date(date.getTime());
|
2832 | date.setMinutes(date.getMinutes() + minutes);
|
2833 | return date;
|
2834 | }
|
2835 | /**
|
2836 | * @param {?} date
|
2837 | * @param {?} timezone
|
2838 | * @param {?} reverse
|
2839 | * @return {?}
|
2840 | */
|
2841 | function convertTimezoneToLocal(date, timezone, reverse) {
|
2842 | /** @type {?} */
|
2843 | const reverseValue = reverse ? -1 : 1;
|
2844 | /** @type {?} */
|
2845 | const dateTimezoneOffset = date.getTimezoneOffset();
|
2846 | /** @type {?} */
|
2847 | const timezoneOffset = timezoneToOffset(timezone, dateTimezoneOffset);
|
2848 | return addDateMinutes(date, reverseValue * (timezoneOffset - dateTimezoneOffset));
|
2849 | }
|
2850 | /**
|
2851 | * Converts a value to date.
|
2852 | *
|
2853 | * Supported input formats:
|
2854 | * - `Date`
|
2855 | * - number: timestamp
|
2856 | * - string: numeric (e.g. "1234"), ISO and date strings in a format supported by
|
2857 | * [Date.parse()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse).
|
2858 | * Note: ISO strings without time return a date without timeoffset.
|
2859 | *
|
2860 | * Throws if unable to convert to a date.
|
2861 | * @param {?} value
|
2862 | * @return {?}
|
2863 | */
|
2864 | function toDate(value) {
|
2865 | if (isDate(value)) {
|
2866 | return value;
|
2867 | }
|
2868 | if (typeof value === 'number' && !isNaN(value)) {
|
2869 | return new Date(value);
|
2870 | }
|
2871 | if (typeof value === 'string') {
|
2872 | value = value.trim();
|
2873 | /** @type {?} */
|
2874 | const parsedNb = parseFloat(value);
|
2875 | // any string that only contains numbers, like "1234" but not like "1234hello"
|
2876 | if (!isNaN((/** @type {?} */ (value)) - parsedNb)) {
|
2877 | return new Date(parsedNb);
|
2878 | }
|
2879 | if (/^(\d{4}-\d{1,2}-\d{1,2})$/.test(value)) {
|
2880 | /* For ISO Strings without time the day, month and year must be extracted from the ISO String
|
2881 | before Date creation to avoid time offset and errors in the new Date.
|
2882 | If we only replace '-' with ',' in the ISO String ("2015,01,01"), and try to create a new
|
2883 | date, some browsers (e.g. IE 9) will throw an invalid Date error.
|
2884 | If we leave the '-' ("2015-01-01") and try to create a new Date("2015-01-01") the timeoffset
|
2885 | is applied.
|
2886 | Note: ISO months are 0 for January, 1 for February, ... */
|
2887 | const [y, m, d] = value.split('-').map((/**
|
2888 | * @param {?} val
|
2889 | * @return {?}
|
2890 | */
|
2891 | (val) => +val));
|
2892 | return new Date(y, m - 1, d);
|
2893 | }
|
2894 | /** @type {?} */
|
2895 | let match;
|
2896 | if (match = value.match(ISO8601_DATE_REGEX)) {
|
2897 | return isoStringToDate(match);
|
2898 | }
|
2899 | }
|
2900 | /** @type {?} */
|
2901 | const date = new Date((/** @type {?} */ (value)));
|
2902 | if (!isDate(date)) {
|
2903 | throw new Error(`Unable to convert "${value}" into a date`);
|
2904 | }
|
2905 | return date;
|
2906 | }
|
2907 | /**
|
2908 | * Converts a date in ISO8601 to a Date.
|
2909 | * Used instead of `Date.parse` because of browser discrepancies.
|
2910 | * @param {?} match
|
2911 | * @return {?}
|
2912 | */
|
2913 | function isoStringToDate(match) {
|
2914 | /** @type {?} */
|
2915 | const date = new Date(0);
|
2916 | /** @type {?} */
|
2917 | let tzHour = 0;
|
2918 | /** @type {?} */
|
2919 | let tzMin = 0;
|
2920 | // match[8] means that the string contains "Z" (UTC) or a timezone like "+01:00" or "+0100"
|
2921 | /** @type {?} */
|
2922 | const dateSetter = match[8] ? date.setUTCFullYear : date.setFullYear;
|
2923 | /** @type {?} */
|
2924 | const timeSetter = match[8] ? date.setUTCHours : date.setHours;
|
2925 | // if there is a timezone defined like "+01:00" or "+0100"
|
2926 | if (match[9]) {
|
2927 | tzHour = Number(match[9] + match[10]);
|
2928 | tzMin = Number(match[9] + match[11]);
|
2929 | }
|
2930 | dateSetter.call(date, Number(match[1]), Number(match[2]) - 1, Number(match[3]));
|
2931 | /** @type {?} */
|
2932 | const h = Number(match[4] || 0) - tzHour;
|
2933 | /** @type {?} */
|
2934 | const m = Number(match[5] || 0) - tzMin;
|
2935 | /** @type {?} */
|
2936 | const s = Number(match[6] || 0);
|
2937 | /** @type {?} */
|
2938 | const ms = Math.round(parseFloat('0.' + (match[7] || 0)) * 1000);
|
2939 | timeSetter.call(date, h, m, s, ms);
|
2940 | return date;
|
2941 | }
|
2942 | /**
|
2943 | * @param {?} value
|
2944 | * @return {?}
|
2945 | */
|
2946 | function isDate(value) {
|
2947 | return value instanceof Date && !isNaN(value.valueOf());
|
2948 | }
|
2949 |
|
2950 | /**
|
2951 | * @fileoverview added by tsickle
|
2952 | * Generated from: packages/common/src/i18n/format_number.ts
|
2953 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
2954 | */
|
2955 | /** @type {?} */
|
2956 | const NUMBER_FORMAT_REGEXP = /^(\d+)?\.((\d+)(-(\d+))?)?$/;
|
2957 | /** @type {?} */
|
2958 | const MAX_DIGITS = 22;
|
2959 | /** @type {?} */
|
2960 | const DECIMAL_SEP = '.';
|
2961 | /** @type {?} */
|
2962 | const ZERO_CHAR = '0';
|
2963 | /** @type {?} */
|
2964 | const PATTERN_SEP = ';';
|
2965 | /** @type {?} */
|
2966 | const GROUP_SEP = ',';
|
2967 | /** @type {?} */
|
2968 | const DIGIT_CHAR = '#';
|
2969 | /** @type {?} */
|
2970 | const CURRENCY_CHAR = '¤';
|
2971 | /** @type {?} */
|
2972 | const PERCENT_CHAR = '%';
|
2973 | /**
|
2974 | * Transforms a number to a locale string based on a style and a format.
|
2975 | * @param {?} value
|
2976 | * @param {?} pattern
|
2977 | * @param {?} locale
|
2978 | * @param {?} groupSymbol
|
2979 | * @param {?} decimalSymbol
|
2980 | * @param {?=} digitsInfo
|
2981 | * @param {?=} isPercent
|
2982 | * @return {?}
|
2983 | */
|
2984 | function formatNumberToLocaleString(value, pattern, locale, groupSymbol, decimalSymbol, digitsInfo, isPercent = false) {
|
2985 | /** @type {?} */
|
2986 | let formattedText = '';
|
2987 | /** @type {?} */
|
2988 | let isZero = false;
|
2989 | if (!isFinite(value)) {
|
2990 | formattedText = getLocaleNumberSymbol(locale, NumberSymbol.Infinity);
|
2991 | }
|
2992 | else {
|
2993 | /** @type {?} */
|
2994 | let parsedNumber = parseNumber(value);
|
2995 | if (isPercent) {
|
2996 | parsedNumber = toPercent(parsedNumber);
|
2997 | }
|
2998 | /** @type {?} */
|
2999 | let minInt = pattern.minInt;
|
3000 | /** @type {?} */
|
3001 | let minFraction = pattern.minFrac;
|
3002 | /** @type {?} */
|
3003 | let maxFraction = pattern.maxFrac;
|
3004 | if (digitsInfo) {
|
3005 | /** @type {?} */
|
3006 | const parts = digitsInfo.match(NUMBER_FORMAT_REGEXP);
|
3007 | if (parts === null) {
|
3008 | throw new Error(`${digitsInfo} is not a valid digit info`);
|
3009 | }
|
3010 | /** @type {?} */
|
3011 | const minIntPart = parts[1];
|
3012 | /** @type {?} */
|
3013 | const minFractionPart = parts[3];
|
3014 | /** @type {?} */
|
3015 | const maxFractionPart = parts[5];
|
3016 | if (minIntPart != null) {
|
3017 | minInt = parseIntAutoRadix(minIntPart);
|
3018 | }
|
3019 | if (minFractionPart != null) {
|
3020 | minFraction = parseIntAutoRadix(minFractionPart);
|
3021 | }
|
3022 | if (maxFractionPart != null) {
|
3023 | maxFraction = parseIntAutoRadix(maxFractionPart);
|
3024 | }
|
3025 | else if (minFractionPart != null && minFraction > maxFraction) {
|
3026 | maxFraction = minFraction;
|
3027 | }
|
3028 | }
|
3029 | roundNumber(parsedNumber, minFraction, maxFraction);
|
3030 | /** @type {?} */
|
3031 | let digits = parsedNumber.digits;
|
3032 | /** @type {?} */
|
3033 | let integerLen = parsedNumber.integerLen;
|
3034 | /** @type {?} */
|
3035 | const exponent = parsedNumber.exponent;
|
3036 | /** @type {?} */
|
3037 | let decimals = [];
|
3038 | isZero = digits.every((/**
|
3039 | * @param {?} d
|
3040 | * @return {?}
|
3041 | */
|
3042 | d => !d));
|
3043 | // pad zeros for small numbers
|
3044 | for (; integerLen < minInt; integerLen++) {
|
3045 | digits.unshift(0);
|
3046 | }
|
3047 | // pad zeros for small numbers
|
3048 | for (; integerLen < 0; integerLen++) {
|
3049 | digits.unshift(0);
|
3050 | }
|
3051 | // extract decimals digits
|
3052 | if (integerLen > 0) {
|
3053 | decimals = digits.splice(integerLen, digits.length);
|
3054 | }
|
3055 | else {
|
3056 | decimals = digits;
|
3057 | digits = [0];
|
3058 | }
|
3059 | // format the integer digits with grouping separators
|
3060 | /** @type {?} */
|
3061 | const groups = [];
|
3062 | if (digits.length >= pattern.lgSize) {
|
3063 | groups.unshift(digits.splice(-pattern.lgSize, digits.length).join(''));
|
3064 | }
|
3065 | while (digits.length > pattern.gSize) {
|
3066 | groups.unshift(digits.splice(-pattern.gSize, digits.length).join(''));
|
3067 | }
|
3068 | if (digits.length) {
|
3069 | groups.unshift(digits.join(''));
|
3070 | }
|
3071 | formattedText = groups.join(getLocaleNumberSymbol(locale, groupSymbol));
|
3072 | // append the decimal digits
|
3073 | if (decimals.length) {
|
3074 | formattedText += getLocaleNumberSymbol(locale, decimalSymbol) + decimals.join('');
|
3075 | }
|
3076 | if (exponent) {
|
3077 | formattedText += getLocaleNumberSymbol(locale, NumberSymbol.Exponential) + '+' + exponent;
|
3078 | }
|
3079 | }
|
3080 | if (value < 0 && !isZero) {
|
3081 | formattedText = pattern.negPre + formattedText + pattern.negSuf;
|
3082 | }
|
3083 | else {
|
3084 | formattedText = pattern.posPre + formattedText + pattern.posSuf;
|
3085 | }
|
3086 | return formattedText;
|
3087 | }
|
3088 | /**
|
3089 | * \@ngModule CommonModule
|
3090 | * \@description
|
3091 | *
|
3092 | * Formats a number as currency using locale rules.
|
3093 | *
|
3094 | * @see `formatNumber()` / `DecimalPipe` / [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
3095 | *
|
3096 | * \@publicApi
|
3097 | * @param {?} value The number to format.
|
3098 | * @param {?} locale A locale code for the locale format rules to use.
|
3099 | * @param {?} currency A string containing the currency symbol or its name,
|
3100 | * such as "$" or "Canadian Dollar". Used in output string, but does not affect the operation
|
3101 | * of the function.
|
3102 | * @param {?=} currencyCode The [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217)
|
3103 | * currency code, such as `USD` for the US dollar and `EUR` for the euro.
|
3104 | * Used to determine the number of digits in the decimal part.
|
3105 | * @param {?=} digitsInfo
|
3106 | * @return {?} The formatted currency value.
|
3107 | *
|
3108 | */
|
3109 | function formatCurrency(value, locale, currency, currencyCode, digitsInfo) {
|
3110 | /** @type {?} */
|
3111 | const format = getLocaleNumberFormat(locale, NumberFormatStyle.Currency);
|
3112 | /** @type {?} */
|
3113 | const pattern = parseNumberFormat(format, getLocaleNumberSymbol(locale, NumberSymbol.MinusSign));
|
3114 | pattern.minFrac = getNumberOfCurrencyDigits((/** @type {?} */ (currencyCode)));
|
3115 | pattern.maxFrac = pattern.minFrac;
|
3116 | /** @type {?} */
|
3117 | const res = formatNumberToLocaleString(value, pattern, locale, NumberSymbol.CurrencyGroup, NumberSymbol.CurrencyDecimal, digitsInfo);
|
3118 | return res
|
3119 | .replace(CURRENCY_CHAR, currency)
|
3120 | // if we have 2 time the currency character, the second one is ignored
|
3121 | .replace(CURRENCY_CHAR, '')
|
3122 | // If there is a spacing between currency character and the value and
|
3123 | // the currency character is supressed by passing an empty string, the
|
3124 | // spacing character would remain as part of the string. Then we
|
3125 | // should remove it.
|
3126 | .trim();
|
3127 | }
|
3128 | /**
|
3129 | * \@ngModule CommonModule
|
3130 | * \@description
|
3131 | *
|
3132 | * Formats a number as a percentage according to locale rules.
|
3133 | *
|
3134 | * @see `formatNumber()` / `DecimalPipe` / [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
3135 | * \@publicApi
|
3136 | *
|
3137 | * @param {?} value The number to format.
|
3138 | * @param {?} locale A locale code for the locale format rules to use.
|
3139 | * @param {?=} digitsInfo
|
3140 | * @return {?} The formatted percentage value.
|
3141 | *
|
3142 | */
|
3143 | function formatPercent(value, locale, digitsInfo) {
|
3144 | /** @type {?} */
|
3145 | const format = getLocaleNumberFormat(locale, NumberFormatStyle.Percent);
|
3146 | /** @type {?} */
|
3147 | const pattern = parseNumberFormat(format, getLocaleNumberSymbol(locale, NumberSymbol.MinusSign));
|
3148 | /** @type {?} */
|
3149 | const res = formatNumberToLocaleString(value, pattern, locale, NumberSymbol.Group, NumberSymbol.Decimal, digitsInfo, true);
|
3150 | return res.replace(new RegExp(PERCENT_CHAR, 'g'), getLocaleNumberSymbol(locale, NumberSymbol.PercentSign));
|
3151 | }
|
3152 | /**
|
3153 | * \@ngModule CommonModule
|
3154 | * \@description
|
3155 | *
|
3156 | * Formats a number as text, with group sizing, separator, and other
|
3157 | * parameters based on the locale.
|
3158 | *
|
3159 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
3160 | *
|
3161 | * \@publicApi
|
3162 | * @param {?} value The number to format.
|
3163 | * @param {?} locale A locale code for the locale format rules to use.
|
3164 | * @param {?=} digitsInfo
|
3165 | * @return {?} The formatted text string.
|
3166 | */
|
3167 | function formatNumber(value, locale, digitsInfo) {
|
3168 | /** @type {?} */
|
3169 | const format = getLocaleNumberFormat(locale, NumberFormatStyle.Decimal);
|
3170 | /** @type {?} */
|
3171 | const pattern = parseNumberFormat(format, getLocaleNumberSymbol(locale, NumberSymbol.MinusSign));
|
3172 | return formatNumberToLocaleString(value, pattern, locale, NumberSymbol.Group, NumberSymbol.Decimal, digitsInfo);
|
3173 | }
|
3174 | /**
|
3175 | * @record
|
3176 | */
|
3177 | function ParsedNumberFormat() { }
|
3178 | if (false) {
|
3179 | /** @type {?} */
|
3180 | ParsedNumberFormat.prototype.minInt;
|
3181 | /** @type {?} */
|
3182 | ParsedNumberFormat.prototype.minFrac;
|
3183 | /** @type {?} */
|
3184 | ParsedNumberFormat.prototype.maxFrac;
|
3185 | /** @type {?} */
|
3186 | ParsedNumberFormat.prototype.posPre;
|
3187 | /** @type {?} */
|
3188 | ParsedNumberFormat.prototype.posSuf;
|
3189 | /** @type {?} */
|
3190 | ParsedNumberFormat.prototype.negPre;
|
3191 | /** @type {?} */
|
3192 | ParsedNumberFormat.prototype.negSuf;
|
3193 | /** @type {?} */
|
3194 | ParsedNumberFormat.prototype.gSize;
|
3195 | /** @type {?} */
|
3196 | ParsedNumberFormat.prototype.lgSize;
|
3197 | }
|
3198 | /**
|
3199 | * @param {?} format
|
3200 | * @param {?=} minusSign
|
3201 | * @return {?}
|
3202 | */
|
3203 | function parseNumberFormat(format, minusSign = '-') {
|
3204 | /** @type {?} */
|
3205 | const p = {
|
3206 | minInt: 1,
|
3207 | minFrac: 0,
|
3208 | maxFrac: 0,
|
3209 | posPre: '',
|
3210 | posSuf: '',
|
3211 | negPre: '',
|
3212 | negSuf: '',
|
3213 | gSize: 0,
|
3214 | lgSize: 0
|
3215 | };
|
3216 | /** @type {?} */
|
3217 | const patternParts = format.split(PATTERN_SEP);
|
3218 | /** @type {?} */
|
3219 | const positive = patternParts[0];
|
3220 | /** @type {?} */
|
3221 | const negative = patternParts[1];
|
3222 | /** @type {?} */
|
3223 | const positiveParts = positive.indexOf(DECIMAL_SEP) !== -1 ?
|
3224 | positive.split(DECIMAL_SEP) :
|
3225 | [
|
3226 | positive.substring(0, positive.lastIndexOf(ZERO_CHAR) + 1),
|
3227 | positive.substring(positive.lastIndexOf(ZERO_CHAR) + 1)
|
3228 | ];
|
3229 | /** @type {?} */
|
3230 | const integer = positiveParts[0];
|
3231 | /** @type {?} */
|
3232 | const fraction = positiveParts[1] || '';
|
3233 | p.posPre = integer.substr(0, integer.indexOf(DIGIT_CHAR));
|
3234 | for (let i = 0; i < fraction.length; i++) {
|
3235 | /** @type {?} */
|
3236 | const ch = fraction.charAt(i);
|
3237 | if (ch === ZERO_CHAR) {
|
3238 | p.minFrac = p.maxFrac = i + 1;
|
3239 | }
|
3240 | else if (ch === DIGIT_CHAR) {
|
3241 | p.maxFrac = i + 1;
|
3242 | }
|
3243 | else {
|
3244 | p.posSuf += ch;
|
3245 | }
|
3246 | }
|
3247 | /** @type {?} */
|
3248 | const groups = integer.split(GROUP_SEP);
|
3249 | p.gSize = groups[1] ? groups[1].length : 0;
|
3250 | p.lgSize = (groups[2] || groups[1]) ? (groups[2] || groups[1]).length : 0;
|
3251 | if (negative) {
|
3252 | /** @type {?} */
|
3253 | const trunkLen = positive.length - p.posPre.length - p.posSuf.length;
|
3254 | /** @type {?} */
|
3255 | const pos = negative.indexOf(DIGIT_CHAR);
|
3256 | p.negPre = negative.substr(0, pos).replace(/'/g, '');
|
3257 | p.negSuf = negative.substr(pos + trunkLen).replace(/'/g, '');
|
3258 | }
|
3259 | else {
|
3260 | p.negPre = minusSign + p.posPre;
|
3261 | p.negSuf = p.posSuf;
|
3262 | }
|
3263 | return p;
|
3264 | }
|
3265 | /**
|
3266 | * @record
|
3267 | */
|
3268 | function ParsedNumber() { }
|
3269 | if (false) {
|
3270 | /** @type {?} */
|
3271 | ParsedNumber.prototype.digits;
|
3272 | /** @type {?} */
|
3273 | ParsedNumber.prototype.exponent;
|
3274 | /** @type {?} */
|
3275 | ParsedNumber.prototype.integerLen;
|
3276 | }
|
3277 | // Transforms a parsed number into a percentage by multiplying it by 100
|
3278 | /**
|
3279 | * @param {?} parsedNumber
|
3280 | * @return {?}
|
3281 | */
|
3282 | function toPercent(parsedNumber) {
|
3283 | // if the number is 0, don't do anything
|
3284 | if (parsedNumber.digits[0] === 0) {
|
3285 | return parsedNumber;
|
3286 | }
|
3287 | // Getting the current number of decimals
|
3288 | /** @type {?} */
|
3289 | const fractionLen = parsedNumber.digits.length - parsedNumber.integerLen;
|
3290 | if (parsedNumber.exponent) {
|
3291 | parsedNumber.exponent += 2;
|
3292 | }
|
3293 | else {
|
3294 | if (fractionLen === 0) {
|
3295 | parsedNumber.digits.push(0, 0);
|
3296 | }
|
3297 | else if (fractionLen === 1) {
|
3298 | parsedNumber.digits.push(0);
|
3299 | }
|
3300 | parsedNumber.integerLen += 2;
|
3301 | }
|
3302 | return parsedNumber;
|
3303 | }
|
3304 | /**
|
3305 | * Parses a number.
|
3306 | * Significant bits of this parse algorithm came from https://github.com/MikeMcl/big.js/
|
3307 | * @param {?} num
|
3308 | * @return {?}
|
3309 | */
|
3310 | function parseNumber(num) {
|
3311 | /** @type {?} */
|
3312 | let numStr = Math.abs(num) + '';
|
3313 | /** @type {?} */
|
3314 | let exponent = 0;
|
3315 | /** @type {?} */
|
3316 | let digits;
|
3317 | /** @type {?} */
|
3318 | let integerLen;
|
3319 | /** @type {?} */
|
3320 | let i;
|
3321 | /** @type {?} */
|
3322 | let j;
|
3323 | /** @type {?} */
|
3324 | let zeros;
|
3325 | // Decimal point?
|
3326 | if ((integerLen = numStr.indexOf(DECIMAL_SEP)) > -1) {
|
3327 | numStr = numStr.replace(DECIMAL_SEP, '');
|
3328 | }
|
3329 | // Exponential form?
|
3330 | if ((i = numStr.search(/e/i)) > 0) {
|
3331 | // Work out the exponent.
|
3332 | if (integerLen < 0)
|
3333 | integerLen = i;
|
3334 | integerLen += +numStr.slice(i + 1);
|
3335 | numStr = numStr.substring(0, i);
|
3336 | }
|
3337 | else if (integerLen < 0) {
|
3338 | // There was no decimal point or exponent so it is an integer.
|
3339 | integerLen = numStr.length;
|
3340 | }
|
3341 | // Count the number of leading zeros.
|
3342 | for (i = 0; numStr.charAt(i) === ZERO_CHAR; i++) { /* empty */
|
3343 | }
|
3344 | if (i === (zeros = numStr.length)) {
|
3345 | // The digits are all zero.
|
3346 | digits = [0];
|
3347 | integerLen = 1;
|
3348 | }
|
3349 | else {
|
3350 | // Count the number of trailing zeros
|
3351 | zeros--;
|
3352 | while (numStr.charAt(zeros) === ZERO_CHAR)
|
3353 | zeros--;
|
3354 | // Trailing zeros are insignificant so ignore them
|
3355 | integerLen -= i;
|
3356 | digits = [];
|
3357 | // Convert string to array of digits without leading/trailing zeros.
|
3358 | for (j = 0; i <= zeros; i++, j++) {
|
3359 | digits[j] = Number(numStr.charAt(i));
|
3360 | }
|
3361 | }
|
3362 | // If the number overflows the maximum allowed digits then use an exponent.
|
3363 | if (integerLen > MAX_DIGITS) {
|
3364 | digits = digits.splice(0, MAX_DIGITS - 1);
|
3365 | exponent = integerLen - 1;
|
3366 | integerLen = 1;
|
3367 | }
|
3368 | return { digits, exponent, integerLen };
|
3369 | }
|
3370 | /**
|
3371 | * Round the parsed number to the specified number of decimal places
|
3372 | * This function changes the parsedNumber in-place
|
3373 | * @param {?} parsedNumber
|
3374 | * @param {?} minFrac
|
3375 | * @param {?} maxFrac
|
3376 | * @return {?}
|
3377 | */
|
3378 | function roundNumber(parsedNumber, minFrac, maxFrac) {
|
3379 | if (minFrac > maxFrac) {
|
3380 | throw new Error(`The minimum number of digits after fraction (${minFrac}) is higher than the maximum (${maxFrac}).`);
|
3381 | }
|
3382 | /** @type {?} */
|
3383 | let digits = parsedNumber.digits;
|
3384 | /** @type {?} */
|
3385 | let fractionLen = digits.length - parsedNumber.integerLen;
|
3386 | /** @type {?} */
|
3387 | const fractionSize = Math.min(Math.max(minFrac, fractionLen), maxFrac);
|
3388 | // The index of the digit to where rounding is to occur
|
3389 | /** @type {?} */
|
3390 | let roundAt = fractionSize + parsedNumber.integerLen;
|
3391 | /** @type {?} */
|
3392 | let digit = digits[roundAt];
|
3393 | if (roundAt > 0) {
|
3394 | // Drop fractional digits beyond `roundAt`
|
3395 | digits.splice(Math.max(parsedNumber.integerLen, roundAt));
|
3396 | // Set non-fractional digits beyond `roundAt` to 0
|
3397 | for (let j = roundAt; j < digits.length; j++) {
|
3398 | digits[j] = 0;
|
3399 | }
|
3400 | }
|
3401 | else {
|
3402 | // We rounded to zero so reset the parsedNumber
|
3403 | fractionLen = Math.max(0, fractionLen);
|
3404 | parsedNumber.integerLen = 1;
|
3405 | digits.length = Math.max(1, roundAt = fractionSize + 1);
|
3406 | digits[0] = 0;
|
3407 | for (let i = 1; i < roundAt; i++)
|
3408 | digits[i] = 0;
|
3409 | }
|
3410 | if (digit >= 5) {
|
3411 | if (roundAt - 1 < 0) {
|
3412 | for (let k = 0; k > roundAt; k--) {
|
3413 | digits.unshift(0);
|
3414 | parsedNumber.integerLen++;
|
3415 | }
|
3416 | digits.unshift(1);
|
3417 | parsedNumber.integerLen++;
|
3418 | }
|
3419 | else {
|
3420 | digits[roundAt - 1]++;
|
3421 | }
|
3422 | }
|
3423 | // Pad out with zeros to get the required fraction length
|
3424 | for (; fractionLen < Math.max(0, fractionSize); fractionLen++)
|
3425 | digits.push(0);
|
3426 | /** @type {?} */
|
3427 | let dropTrailingZeros = fractionSize !== 0;
|
3428 | // Minimal length = nb of decimals required + current nb of integers
|
3429 | // Any number besides that is optional and can be removed if it's a trailing 0
|
3430 | /** @type {?} */
|
3431 | const minLen = minFrac + parsedNumber.integerLen;
|
3432 | // Do any carrying, e.g. a digit was rounded up to 10
|
3433 | /** @type {?} */
|
3434 | const carry = digits.reduceRight((/**
|
3435 | * @param {?} carry
|
3436 | * @param {?} d
|
3437 | * @param {?} i
|
3438 | * @param {?} digits
|
3439 | * @return {?}
|
3440 | */
|
3441 | function (carry, d, i, digits) {
|
3442 | d = d + carry;
|
3443 | digits[i] = d < 10 ? d : d - 10; // d % 10
|
3444 | if (dropTrailingZeros) {
|
3445 | // Do not keep meaningless fractional trailing zeros (e.g. 15.52000 --> 15.52)
|
3446 | if (digits[i] === 0 && i >= minLen) {
|
3447 | digits.pop();
|
3448 | }
|
3449 | else {
|
3450 | dropTrailingZeros = false;
|
3451 | }
|
3452 | }
|
3453 | return d >= 10 ? 1 : 0; // Math.floor(d / 10);
|
3454 | }), 0);
|
3455 | if (carry) {
|
3456 | digits.unshift(carry);
|
3457 | parsedNumber.integerLen++;
|
3458 | }
|
3459 | }
|
3460 | /**
|
3461 | * @param {?} text
|
3462 | * @return {?}
|
3463 | */
|
3464 | function parseIntAutoRadix(text) {
|
3465 | /** @type {?} */
|
3466 | const result = parseInt(text);
|
3467 | if (isNaN(result)) {
|
3468 | throw new Error('Invalid integer literal when parsing ' + text);
|
3469 | }
|
3470 | return result;
|
3471 | }
|
3472 |
|
3473 | /**
|
3474 | * @fileoverview added by tsickle
|
3475 | * Generated from: packages/common/src/i18n/localization.ts
|
3476 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
3477 | */
|
3478 | /**
|
3479 | * \@publicApi
|
3480 | * @abstract
|
3481 | */
|
3482 | class NgLocalization {
|
3483 | }
|
3484 | if (false) {
|
3485 | /**
|
3486 | * @abstract
|
3487 | * @param {?} value
|
3488 | * @param {?=} locale
|
3489 | * @return {?}
|
3490 | */
|
3491 | NgLocalization.prototype.getPluralCategory = function (value, locale) { };
|
3492 | }
|
3493 | /**
|
3494 | * Returns the plural category for a given value.
|
3495 | * - "=value" when the case exists,
|
3496 | * - the plural category otherwise
|
3497 | * @param {?} value
|
3498 | * @param {?} cases
|
3499 | * @param {?} ngLocalization
|
3500 | * @param {?=} locale
|
3501 | * @return {?}
|
3502 | */
|
3503 | function getPluralCategory(value, cases, ngLocalization, locale) {
|
3504 | /** @type {?} */
|
3505 | let key = `=${value}`;
|
3506 | if (cases.indexOf(key) > -1) {
|
3507 | return key;
|
3508 | }
|
3509 | key = ngLocalization.getPluralCategory(value, locale);
|
3510 | if (cases.indexOf(key) > -1) {
|
3511 | return key;
|
3512 | }
|
3513 | if (cases.indexOf('other') > -1) {
|
3514 | return 'other';
|
3515 | }
|
3516 | throw new Error(`No plural message found for value "${value}"`);
|
3517 | }
|
3518 | /**
|
3519 | * Returns the plural case based on the locale
|
3520 | *
|
3521 | * \@publicApi
|
3522 | */
|
3523 | class NgLocaleLocalization extends NgLocalization {
|
3524 | /**
|
3525 | * @param {?} locale
|
3526 | */
|
3527 | constructor(locale) {
|
3528 | super();
|
3529 | this.locale = locale;
|
3530 | }
|
3531 | /**
|
3532 | * @param {?} value
|
3533 | * @param {?=} locale
|
3534 | * @return {?}
|
3535 | */
|
3536 | getPluralCategory(value, locale) {
|
3537 | /** @type {?} */
|
3538 | const plural = getLocalePluralCase(locale || this.locale)(value);
|
3539 | switch (plural) {
|
3540 | case Plural.Zero:
|
3541 | return 'zero';
|
3542 | case Plural.One:
|
3543 | return 'one';
|
3544 | case Plural.Two:
|
3545 | return 'two';
|
3546 | case Plural.Few:
|
3547 | return 'few';
|
3548 | case Plural.Many:
|
3549 | return 'many';
|
3550 | default:
|
3551 | return 'other';
|
3552 | }
|
3553 | }
|
3554 | }
|
3555 | NgLocaleLocalization.decorators = [
|
3556 | { type: Injectable }
|
3557 | ];
|
3558 | /** @nocollapse */
|
3559 | NgLocaleLocalization.ctorParameters = () => [
|
3560 | { type: String, decorators: [{ type: Inject, args: [LOCALE_ID,] }] }
|
3561 | ];
|
3562 | if (false) {
|
3563 | /**
|
3564 | * @type {?}
|
3565 | * @protected
|
3566 | */
|
3567 | NgLocaleLocalization.prototype.locale;
|
3568 | }
|
3569 |
|
3570 | /**
|
3571 | * @fileoverview added by tsickle
|
3572 | * Generated from: packages/common/src/i18n/locale_data.ts
|
3573 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
3574 | */
|
3575 | /**
|
3576 | * Register global data to be used internally by Angular. See the
|
3577 | * ["I18n guide"](guide/i18n#i18n-pipes) to know how to import additional locale data.
|
3578 | *
|
3579 | * The signature registerLocaleData(data: any, extraData?: any) is deprecated since v5.1
|
3580 | *
|
3581 | * \@publicApi
|
3582 | * @param {?} data
|
3583 | * @param {?=} localeId
|
3584 | * @param {?=} extraData
|
3585 | * @return {?}
|
3586 | */
|
3587 | function registerLocaleData(data, localeId, extraData) {
|
3588 | return ɵregisterLocaleData(data, localeId, extraData);
|
3589 | }
|
3590 |
|
3591 | /**
|
3592 | * @fileoverview added by tsickle
|
3593 | * Generated from: packages/common/src/cookie.ts
|
3594 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
3595 | */
|
3596 | /**
|
3597 | * @license
|
3598 | * Copyright Google Inc. All Rights Reserved.
|
3599 | *
|
3600 | * Use of this source code is governed by an MIT-style license that can be
|
3601 | * found in the LICENSE file at https://angular.io/license
|
3602 | */
|
3603 | /**
|
3604 | * @param {?} cookieStr
|
3605 | * @param {?} name
|
3606 | * @return {?}
|
3607 | */
|
3608 | function parseCookieValue(cookieStr, name) {
|
3609 | name = encodeURIComponent(name);
|
3610 | for (const cookie of cookieStr.split(';')) {
|
3611 | /** @type {?} */
|
3612 | const eqIndex = cookie.indexOf('=');
|
3613 | const [cookieName, cookieValue] = eqIndex == -1 ? [cookie, ''] : [cookie.slice(0, eqIndex), cookie.slice(eqIndex + 1)];
|
3614 | if (cookieName.trim() === name) {
|
3615 | return decodeURIComponent(cookieValue);
|
3616 | }
|
3617 | }
|
3618 | return null;
|
3619 | }
|
3620 |
|
3621 | /**
|
3622 | * @fileoverview added by tsickle
|
3623 | * Generated from: packages/common/src/directives/ng_class.ts
|
3624 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
3625 | */
|
3626 | /**
|
3627 | * \@ngModule CommonModule
|
3628 | *
|
3629 | * \@usageNotes
|
3630 | * ```
|
3631 | * <some-element [ngClass]="'first second'">...</some-element>
|
3632 | *
|
3633 | * <some-element [ngClass]="['first', 'second']">...</some-element>
|
3634 | *
|
3635 | * <some-element [ngClass]="{'first': true, 'second': true, 'third': false}">...</some-element>
|
3636 | *
|
3637 | * <some-element [ngClass]="stringExp|arrayExp|objExp">...</some-element>
|
3638 | *
|
3639 | * <some-element [ngClass]="{'class1 class2 class3' : true}">...</some-element>
|
3640 | * ```
|
3641 | *
|
3642 | * \@description
|
3643 | *
|
3644 | * Adds and removes CSS classes on an HTML element.
|
3645 | *
|
3646 | * The CSS classes are updated as follows, depending on the type of the expression evaluation:
|
3647 | * - `string` - the CSS classes listed in the string (space delimited) are added,
|
3648 | * - `Array` - the CSS classes declared as Array elements are added,
|
3649 | * - `Object` - keys are CSS classes that get added when the expression given in the value
|
3650 | * evaluates to a truthy value, otherwise they are removed.
|
3651 | *
|
3652 | * \@publicApi
|
3653 | */
|
3654 | class NgClass {
|
3655 | /**
|
3656 | * @param {?} _iterableDiffers
|
3657 | * @param {?} _keyValueDiffers
|
3658 | * @param {?} _ngEl
|
3659 | * @param {?} _renderer
|
3660 | */
|
3661 | constructor(_iterableDiffers, _keyValueDiffers, _ngEl, _renderer) {
|
3662 | this._iterableDiffers = _iterableDiffers;
|
3663 | this._keyValueDiffers = _keyValueDiffers;
|
3664 | this._ngEl = _ngEl;
|
3665 | this._renderer = _renderer;
|
3666 | this._iterableDiffer = null;
|
3667 | this._keyValueDiffer = null;
|
3668 | this._initialClasses = [];
|
3669 | this._rawClass = null;
|
3670 | }
|
3671 | /**
|
3672 | * @param {?} value
|
3673 | * @return {?}
|
3674 | */
|
3675 | set klass(value) {
|
3676 | this._removeClasses(this._initialClasses);
|
3677 | this._initialClasses = typeof value === 'string' ? value.split(/\s+/) : [];
|
3678 | this._applyClasses(this._initialClasses);
|
3679 | this._applyClasses(this._rawClass);
|
3680 | }
|
3681 | /**
|
3682 | * @param {?} value
|
3683 | * @return {?}
|
3684 | */
|
3685 | set ngClass(value) {
|
3686 | this._removeClasses(this._rawClass);
|
3687 | this._applyClasses(this._initialClasses);
|
3688 | this._iterableDiffer = null;
|
3689 | this._keyValueDiffer = null;
|
3690 | this._rawClass = typeof value === 'string' ? value.split(/\s+/) : value;
|
3691 | if (this._rawClass) {
|
3692 | if (ɵisListLikeIterable(this._rawClass)) {
|
3693 | this._iterableDiffer = this._iterableDiffers.find(this._rawClass).create();
|
3694 | }
|
3695 | else {
|
3696 | this._keyValueDiffer = this._keyValueDiffers.find(this._rawClass).create();
|
3697 | }
|
3698 | }
|
3699 | }
|
3700 | /**
|
3701 | * @return {?}
|
3702 | */
|
3703 | ngDoCheck() {
|
3704 | if (this._iterableDiffer) {
|
3705 | /** @type {?} */
|
3706 | const iterableChanges = this._iterableDiffer.diff((/** @type {?} */ (this._rawClass)));
|
3707 | if (iterableChanges) {
|
3708 | this._applyIterableChanges(iterableChanges);
|
3709 | }
|
3710 | }
|
3711 | else if (this._keyValueDiffer) {
|
3712 | /** @type {?} */
|
3713 | const keyValueChanges = this._keyValueDiffer.diff((/** @type {?} */ (this._rawClass)));
|
3714 | if (keyValueChanges) {
|
3715 | this._applyKeyValueChanges(keyValueChanges);
|
3716 | }
|
3717 | }
|
3718 | }
|
3719 | /**
|
3720 | * @private
|
3721 | * @param {?} changes
|
3722 | * @return {?}
|
3723 | */
|
3724 | _applyKeyValueChanges(changes) {
|
3725 | changes.forEachAddedItem((/**
|
3726 | * @param {?} record
|
3727 | * @return {?}
|
3728 | */
|
3729 | (record) => this._toggleClass(record.key, record.currentValue)));
|
3730 | changes.forEachChangedItem((/**
|
3731 | * @param {?} record
|
3732 | * @return {?}
|
3733 | */
|
3734 | (record) => this._toggleClass(record.key, record.currentValue)));
|
3735 | changes.forEachRemovedItem((/**
|
3736 | * @param {?} record
|
3737 | * @return {?}
|
3738 | */
|
3739 | (record) => {
|
3740 | if (record.previousValue) {
|
3741 | this._toggleClass(record.key, false);
|
3742 | }
|
3743 | }));
|
3744 | }
|
3745 | /**
|
3746 | * @private
|
3747 | * @param {?} changes
|
3748 | * @return {?}
|
3749 | */
|
3750 | _applyIterableChanges(changes) {
|
3751 | changes.forEachAddedItem((/**
|
3752 | * @param {?} record
|
3753 | * @return {?}
|
3754 | */
|
3755 | (record) => {
|
3756 | if (typeof record.item === 'string') {
|
3757 | this._toggleClass(record.item, true);
|
3758 | }
|
3759 | else {
|
3760 | throw new Error(`NgClass can only toggle CSS classes expressed as strings, got ${ɵstringify(record.item)}`);
|
3761 | }
|
3762 | }));
|
3763 | changes.forEachRemovedItem((/**
|
3764 | * @param {?} record
|
3765 | * @return {?}
|
3766 | */
|
3767 | (record) => this._toggleClass(record.item, false)));
|
3768 | }
|
3769 | /**
|
3770 | * Applies a collection of CSS classes to the DOM element.
|
3771 | *
|
3772 | * For argument of type Set and Array CSS class names contained in those collections are always
|
3773 | * added.
|
3774 | * For argument of type Map CSS class name in the map's key is toggled based on the value (added
|
3775 | * for truthy and removed for falsy).
|
3776 | * @private
|
3777 | * @param {?} rawClassVal
|
3778 | * @return {?}
|
3779 | */
|
3780 | _applyClasses(rawClassVal) {
|
3781 | if (rawClassVal) {
|
3782 | if (Array.isArray(rawClassVal) || rawClassVal instanceof Set) {
|
3783 | ((/** @type {?} */ (rawClassVal))).forEach((/**
|
3784 | * @param {?} klass
|
3785 | * @return {?}
|
3786 | */
|
3787 | (klass) => this._toggleClass(klass, true)));
|
3788 | }
|
3789 | else {
|
3790 | Object.keys(rawClassVal).forEach((/**
|
3791 | * @param {?} klass
|
3792 | * @return {?}
|
3793 | */
|
3794 | klass => this._toggleClass(klass, !!rawClassVal[klass])));
|
3795 | }
|
3796 | }
|
3797 | }
|
3798 | /**
|
3799 | * Removes a collection of CSS classes from the DOM element. This is mostly useful for cleanup
|
3800 | * purposes.
|
3801 | * @private
|
3802 | * @param {?} rawClassVal
|
3803 | * @return {?}
|
3804 | */
|
3805 | _removeClasses(rawClassVal) {
|
3806 | if (rawClassVal) {
|
3807 | if (Array.isArray(rawClassVal) || rawClassVal instanceof Set) {
|
3808 | ((/** @type {?} */ (rawClassVal))).forEach((/**
|
3809 | * @param {?} klass
|
3810 | * @return {?}
|
3811 | */
|
3812 | (klass) => this._toggleClass(klass, false)));
|
3813 | }
|
3814 | else {
|
3815 | Object.keys(rawClassVal).forEach((/**
|
3816 | * @param {?} klass
|
3817 | * @return {?}
|
3818 | */
|
3819 | klass => this._toggleClass(klass, false)));
|
3820 | }
|
3821 | }
|
3822 | }
|
3823 | /**
|
3824 | * @private
|
3825 | * @param {?} klass
|
3826 | * @param {?} enabled
|
3827 | * @return {?}
|
3828 | */
|
3829 | _toggleClass(klass, enabled) {
|
3830 | klass = klass.trim();
|
3831 | if (klass) {
|
3832 | klass.split(/\s+/g).forEach((/**
|
3833 | * @param {?} klass
|
3834 | * @return {?}
|
3835 | */
|
3836 | klass => {
|
3837 | if (enabled) {
|
3838 | this._renderer.addClass(this._ngEl.nativeElement, klass);
|
3839 | }
|
3840 | else {
|
3841 | this._renderer.removeClass(this._ngEl.nativeElement, klass);
|
3842 | }
|
3843 | }));
|
3844 | }
|
3845 | }
|
3846 | }
|
3847 | NgClass.decorators = [
|
3848 | { type: Directive, args: [{ selector: '[ngClass]' },] }
|
3849 | ];
|
3850 | /** @nocollapse */
|
3851 | NgClass.ctorParameters = () => [
|
3852 | { type: IterableDiffers },
|
3853 | { type: KeyValueDiffers },
|
3854 | { type: ElementRef },
|
3855 | { type: Renderer2 }
|
3856 | ];
|
3857 | NgClass.propDecorators = {
|
3858 | klass: [{ type: Input, args: ['class',] }],
|
3859 | ngClass: [{ type: Input, args: ['ngClass',] }]
|
3860 | };
|
3861 | if (false) {
|
3862 | /**
|
3863 | * @type {?}
|
3864 | * @private
|
3865 | */
|
3866 | NgClass.prototype._iterableDiffer;
|
3867 | /**
|
3868 | * @type {?}
|
3869 | * @private
|
3870 | */
|
3871 | NgClass.prototype._keyValueDiffer;
|
3872 | /**
|
3873 | * @type {?}
|
3874 | * @private
|
3875 | */
|
3876 | NgClass.prototype._initialClasses;
|
3877 | /**
|
3878 | * @type {?}
|
3879 | * @private
|
3880 | */
|
3881 | NgClass.prototype._rawClass;
|
3882 | /**
|
3883 | * @type {?}
|
3884 | * @private
|
3885 | */
|
3886 | NgClass.prototype._iterableDiffers;
|
3887 | /**
|
3888 | * @type {?}
|
3889 | * @private
|
3890 | */
|
3891 | NgClass.prototype._keyValueDiffers;
|
3892 | /**
|
3893 | * @type {?}
|
3894 | * @private
|
3895 | */
|
3896 | NgClass.prototype._ngEl;
|
3897 | /**
|
3898 | * @type {?}
|
3899 | * @private
|
3900 | */
|
3901 | NgClass.prototype._renderer;
|
3902 | }
|
3903 |
|
3904 | /**
|
3905 | * @fileoverview added by tsickle
|
3906 | * Generated from: packages/common/src/directives/ng_component_outlet.ts
|
3907 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
3908 | */
|
3909 | /**
|
3910 | * Instantiates a single {\@link Component} type and inserts its Host View into current View.
|
3911 | * `NgComponentOutlet` provides a declarative approach for dynamic component creation.
|
3912 | *
|
3913 | * `NgComponentOutlet` requires a component type, if a falsy value is set the view will clear and
|
3914 | * any existing component will get destroyed.
|
3915 | *
|
3916 | * \@usageNotes
|
3917 | *
|
3918 | * ### Fine tune control
|
3919 | *
|
3920 | * You can control the component creation process by using the following optional attributes:
|
3921 | *
|
3922 | * * `ngComponentOutletInjector`: Optional custom {\@link Injector} that will be used as parent for
|
3923 | * the Component. Defaults to the injector of the current view container.
|
3924 | *
|
3925 | * * `ngComponentOutletContent`: Optional list of projectable nodes to insert into the content
|
3926 | * section of the component, if exists.
|
3927 | *
|
3928 | * * `ngComponentOutletNgModuleFactory`: Optional module factory to allow dynamically loading other
|
3929 | * module, then load a component from that module.
|
3930 | *
|
3931 | * ### Syntax
|
3932 | *
|
3933 | * Simple
|
3934 | * ```
|
3935 | * <ng-container *ngComponentOutlet="componentTypeExpression"></ng-container>
|
3936 | * ```
|
3937 | *
|
3938 | * Customized injector/content
|
3939 | * ```
|
3940 | * <ng-container *ngComponentOutlet="componentTypeExpression;
|
3941 | * injector: injectorExpression;
|
3942 | * content: contentNodesExpression;">
|
3943 | * </ng-container>
|
3944 | * ```
|
3945 | *
|
3946 | * Customized ngModuleFactory
|
3947 | * ```
|
3948 | * <ng-container *ngComponentOutlet="componentTypeExpression;
|
3949 | * ngModuleFactory: moduleFactory;">
|
3950 | * </ng-container>
|
3951 | * ```
|
3952 | *
|
3953 | * ### A simple example
|
3954 | *
|
3955 | * {\@example common/ngComponentOutlet/ts/module.ts region='SimpleExample'}
|
3956 | *
|
3957 | * A more complete example with additional options:
|
3958 | *
|
3959 | * {\@example common/ngComponentOutlet/ts/module.ts region='CompleteExample'}
|
3960 | *
|
3961 | * \@publicApi
|
3962 | * \@ngModule CommonModule
|
3963 | */
|
3964 | class NgComponentOutlet {
|
3965 | /**
|
3966 | * @param {?} _viewContainerRef
|
3967 | */
|
3968 | constructor(_viewContainerRef) {
|
3969 | this._viewContainerRef = _viewContainerRef;
|
3970 | this._componentRef = null;
|
3971 | this._moduleRef = null;
|
3972 | }
|
3973 | /**
|
3974 | * @param {?} changes
|
3975 | * @return {?}
|
3976 | */
|
3977 | ngOnChanges(changes) {
|
3978 | this._viewContainerRef.clear();
|
3979 | this._componentRef = null;
|
3980 | if (this.ngComponentOutlet) {
|
3981 | /** @type {?} */
|
3982 | const elInjector = this.ngComponentOutletInjector || this._viewContainerRef.parentInjector;
|
3983 | if (changes['ngComponentOutletNgModuleFactory']) {
|
3984 | if (this._moduleRef)
|
3985 | this._moduleRef.destroy();
|
3986 | if (this.ngComponentOutletNgModuleFactory) {
|
3987 | /** @type {?} */
|
3988 | const parentModule = elInjector.get(NgModuleRef);
|
3989 | this._moduleRef = this.ngComponentOutletNgModuleFactory.create(parentModule.injector);
|
3990 | }
|
3991 | else {
|
3992 | this._moduleRef = null;
|
3993 | }
|
3994 | }
|
3995 | /** @type {?} */
|
3996 | const componentFactoryResolver = this._moduleRef ? this._moduleRef.componentFactoryResolver :
|
3997 | elInjector.get(ComponentFactoryResolver);
|
3998 | /** @type {?} */
|
3999 | const componentFactory = componentFactoryResolver.resolveComponentFactory(this.ngComponentOutlet);
|
4000 | this._componentRef = this._viewContainerRef.createComponent(componentFactory, this._viewContainerRef.length, elInjector, this.ngComponentOutletContent);
|
4001 | }
|
4002 | }
|
4003 | /**
|
4004 | * @return {?}
|
4005 | */
|
4006 | ngOnDestroy() {
|
4007 | if (this._moduleRef)
|
4008 | this._moduleRef.destroy();
|
4009 | }
|
4010 | }
|
4011 | NgComponentOutlet.decorators = [
|
4012 | { type: Directive, args: [{ selector: '[ngComponentOutlet]' },] }
|
4013 | ];
|
4014 | /** @nocollapse */
|
4015 | NgComponentOutlet.ctorParameters = () => [
|
4016 | { type: ViewContainerRef }
|
4017 | ];
|
4018 | NgComponentOutlet.propDecorators = {
|
4019 | ngComponentOutlet: [{ type: Input }],
|
4020 | ngComponentOutletInjector: [{ type: Input }],
|
4021 | ngComponentOutletContent: [{ type: Input }],
|
4022 | ngComponentOutletNgModuleFactory: [{ type: Input }]
|
4023 | };
|
4024 | if (false) {
|
4025 | /** @type {?} */
|
4026 | NgComponentOutlet.prototype.ngComponentOutlet;
|
4027 | /** @type {?} */
|
4028 | NgComponentOutlet.prototype.ngComponentOutletInjector;
|
4029 | /** @type {?} */
|
4030 | NgComponentOutlet.prototype.ngComponentOutletContent;
|
4031 | /** @type {?} */
|
4032 | NgComponentOutlet.prototype.ngComponentOutletNgModuleFactory;
|
4033 | /**
|
4034 | * @type {?}
|
4035 | * @private
|
4036 | */
|
4037 | NgComponentOutlet.prototype._componentRef;
|
4038 | /**
|
4039 | * @type {?}
|
4040 | * @private
|
4041 | */
|
4042 | NgComponentOutlet.prototype._moduleRef;
|
4043 | /**
|
4044 | * @type {?}
|
4045 | * @private
|
4046 | */
|
4047 | NgComponentOutlet.prototype._viewContainerRef;
|
4048 | }
|
4049 |
|
4050 | /**
|
4051 | * @fileoverview added by tsickle
|
4052 | * Generated from: packages/common/src/directives/ng_for_of.ts
|
4053 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
4054 | */
|
4055 | /**
|
4056 | * \@publicApi
|
4057 | * @template T, U
|
4058 | */
|
4059 | class NgForOfContext {
|
4060 | /**
|
4061 | * @param {?} $implicit
|
4062 | * @param {?} ngForOf
|
4063 | * @param {?} index
|
4064 | * @param {?} count
|
4065 | */
|
4066 | constructor($implicit, ngForOf, index, count) {
|
4067 | this.$implicit = $implicit;
|
4068 | this.ngForOf = ngForOf;
|
4069 | this.index = index;
|
4070 | this.count = count;
|
4071 | }
|
4072 | /**
|
4073 | * @return {?}
|
4074 | */
|
4075 | get first() { return this.index === 0; }
|
4076 | /**
|
4077 | * @return {?}
|
4078 | */
|
4079 | get last() { return this.index === this.count - 1; }
|
4080 | /**
|
4081 | * @return {?}
|
4082 | */
|
4083 | get even() { return this.index % 2 === 0; }
|
4084 | /**
|
4085 | * @return {?}
|
4086 | */
|
4087 | get odd() { return !this.even; }
|
4088 | }
|
4089 | if (false) {
|
4090 | /** @type {?} */
|
4091 | NgForOfContext.prototype.$implicit;
|
4092 | /** @type {?} */
|
4093 | NgForOfContext.prototype.ngForOf;
|
4094 | /** @type {?} */
|
4095 | NgForOfContext.prototype.index;
|
4096 | /** @type {?} */
|
4097 | NgForOfContext.prototype.count;
|
4098 | }
|
4099 | /**
|
4100 | * A [structural directive](guide/structural-directives) that renders
|
4101 | * a template for each item in a collection.
|
4102 | * The directive is placed on an element, which becomes the parent
|
4103 | * of the cloned templates.
|
4104 | *
|
4105 | * The `ngForOf` directive is generally used in the
|
4106 | * [shorthand form](guide/structural-directives#the-asterisk--prefix) `*ngFor`.
|
4107 | * In this form, the template to be rendered for each iteration is the content
|
4108 | * of an anchor element containing the directive.
|
4109 | *
|
4110 | * The following example shows the shorthand syntax with some options,
|
4111 | * contained in an `<li>` element.
|
4112 | *
|
4113 | * ```
|
4114 | * <li *ngFor="let item of items; index as i; trackBy: trackByFn">...</li>
|
4115 | * ```
|
4116 | *
|
4117 | * The shorthand form expands into a long form that uses the `ngForOf` selector
|
4118 | * on an `<ng-template>` element.
|
4119 | * The content of the `<ng-template>` element is the `<li>` element that held the
|
4120 | * short-form directive.
|
4121 | *
|
4122 | * Here is the expanded version of the short-form example.
|
4123 | *
|
4124 | * ```
|
4125 | * <ng-template ngFor let-item [ngForOf]="items" let-i="index" [ngForTrackBy]="trackByFn">
|
4126 | * <li>...</li>
|
4127 | * </ng-template>
|
4128 | * ```
|
4129 | *
|
4130 | * Angular automatically expands the shorthand syntax as it compiles the template.
|
4131 | * The context for each embedded view is logically merged to the current component
|
4132 | * context according to its lexical position.
|
4133 | *
|
4134 | * When using the shorthand syntax, Angular allows only [one structural directive
|
4135 | * on an element](guide/structural-directives#one-structural-directive-per-host-element).
|
4136 | * If you want to iterate conditionally, for example,
|
4137 | * put the `*ngIf` on a container element that wraps the `*ngFor` element.
|
4138 | * For futher discussion, see
|
4139 | * [Structural Directives](guide/structural-directives#one-per-element).
|
4140 | *
|
4141 | * \@usageNotes
|
4142 | *
|
4143 | * ### Local variables
|
4144 | *
|
4145 | * `NgForOf` provides exported values that can be aliased to local variables.
|
4146 | * For example:
|
4147 | *
|
4148 | * ```
|
4149 | * <li *ngFor="let user of users; index as i; first as isFirst">
|
4150 | * {{i}}/{{users.length}}. {{user}} <span *ngIf="isFirst">default</span>
|
4151 | * </li>
|
4152 | * ```
|
4153 | *
|
4154 | * The following exported values can be aliased to local variables:
|
4155 | *
|
4156 | * - `$implicit: T`: The value of the individual items in the iterable (`ngForOf`).
|
4157 | * - `ngForOf: NgIterable<T>`: The value of the iterable expression. Useful when the expression is
|
4158 | * more complex then a property access, for example when using the async pipe (`userStreams |
|
4159 | * async`).
|
4160 | * - `index: number`: The index of the current item in the iterable.
|
4161 | * - `first: boolean`: True when the item is the first item in the iterable.
|
4162 | * - `last: boolean`: True when the item is the last item in the iterable.
|
4163 | * - `even: boolean`: True when the item has an even index in the iterable.
|
4164 | * - `odd: boolean`: True when the item has an odd index in the iterable.
|
4165 | *
|
4166 | * ### Change propagation
|
4167 | *
|
4168 | * When the contents of the iterator changes, `NgForOf` makes the corresponding changes to the DOM:
|
4169 | *
|
4170 | * * When an item is added, a new instance of the template is added to the DOM.
|
4171 | * * When an item is removed, its template instance is removed from the DOM.
|
4172 | * * When items are reordered, their respective templates are reordered in the DOM.
|
4173 | *
|
4174 | * Angular uses object identity to track insertions and deletions within the iterator and reproduce
|
4175 | * those changes in the DOM. This has important implications for animations and any stateful
|
4176 | * controls that are present, such as `<input>` elements that accept user input. Inserted rows can
|
4177 | * be animated in, deleted rows can be animated out, and unchanged rows retain any unsaved state
|
4178 | * such as user input.
|
4179 | * For more on animations, see [Transitions and Triggers](guide/transition-and-triggers).
|
4180 | *
|
4181 | * The identities of elements in the iterator can change while the data does not.
|
4182 | * This can happen, for example, if the iterator is produced from an RPC to the server, and that
|
4183 | * RPC is re-run. Even if the data hasn't changed, the second response produces objects with
|
4184 | * different identities, and Angular must tear down the entire DOM and rebuild it (as if all old
|
4185 | * elements were deleted and all new elements inserted).
|
4186 | *
|
4187 | * To avoid this expensive operation, you can customize the default tracking algorithm.
|
4188 | * by supplying the `trackBy` option to `NgForOf`.
|
4189 | * `trackBy` takes a function that has two arguments: `index` and `item`.
|
4190 | * If `trackBy` is given, Angular tracks changes by the return value of the function.
|
4191 | *
|
4192 | * @see [Structural Directives](guide/structural-directives)
|
4193 | * \@ngModule CommonModule
|
4194 | * \@publicApi
|
4195 | * @template T, U
|
4196 | */
|
4197 | class NgForOf {
|
4198 | /**
|
4199 | * @param {?} _viewContainer
|
4200 | * @param {?} _template
|
4201 | * @param {?} _differs
|
4202 | */
|
4203 | constructor(_viewContainer, _template, _differs) {
|
4204 | this._viewContainer = _viewContainer;
|
4205 | this._template = _template;
|
4206 | this._differs = _differs;
|
4207 | this._ngForOf = null;
|
4208 | this._ngForOfDirty = true;
|
4209 | this._differ = null;
|
4210 | }
|
4211 | /**
|
4212 | * The value of the iterable expression, which can be used as a
|
4213 | * [template input variable](guide/structural-directives#template-input-variable).
|
4214 | * @param {?} ngForOf
|
4215 | * @return {?}
|
4216 | */
|
4217 | set ngForOf(ngForOf) {
|
4218 | this._ngForOf = ngForOf;
|
4219 | this._ngForOfDirty = true;
|
4220 | }
|
4221 | /**
|
4222 | * A function that defines how to track changes for items in the iterable.
|
4223 | *
|
4224 | * When items are added, moved, or removed in the iterable,
|
4225 | * the directive must re-render the appropriate DOM nodes.
|
4226 | * To minimize churn in the DOM, only nodes that have changed
|
4227 | * are re-rendered.
|
4228 | *
|
4229 | * By default, the change detector assumes that
|
4230 | * the object instance identifies the node in the iterable.
|
4231 | * When this function is supplied, the directive uses
|
4232 | * the result of calling this function to identify the item node,
|
4233 | * rather than the identity of the object itself.
|
4234 | *
|
4235 | * The function receives two inputs,
|
4236 | * the iteration index and the node object ID.
|
4237 | * @param {?} fn
|
4238 | * @return {?}
|
4239 | */
|
4240 | set ngForTrackBy(fn) {
|
4241 | if (isDevMode() && fn != null && typeof fn !== 'function') {
|
4242 | // TODO(vicb): use a log service once there is a public one available
|
4243 | if ((/** @type {?} */ (console)) && (/** @type {?} */ (console.warn))) {
|
4244 | console.warn(`trackBy must be a function, but received ${JSON.stringify(fn)}. ` +
|
4245 | `See https://angular.io/api/common/NgForOf#change-propagation for more information.`);
|
4246 | }
|
4247 | }
|
4248 | this._trackByFn = fn;
|
4249 | }
|
4250 | /**
|
4251 | * @return {?}
|
4252 | */
|
4253 | get ngForTrackBy() { return this._trackByFn; }
|
4254 | /**
|
4255 | * A reference to the template that is stamped out for each item in the iterable.
|
4256 | * @see [template reference variable](guide/template-syntax#template-reference-variables--var-)
|
4257 | * @param {?} value
|
4258 | * @return {?}
|
4259 | */
|
4260 | set ngForTemplate(value) {
|
4261 | // TODO(TS2.1): make TemplateRef<Partial<NgForRowOf<T>>> once we move to TS v2.1
|
4262 | // The current type is too restrictive; a template that just uses index, for example,
|
4263 | // should be acceptable.
|
4264 | if (value) {
|
4265 | this._template = value;
|
4266 | }
|
4267 | }
|
4268 | /**
|
4269 | * Applies the changes when needed.
|
4270 | * @return {?}
|
4271 | */
|
4272 | ngDoCheck() {
|
4273 | if (this._ngForOfDirty) {
|
4274 | this._ngForOfDirty = false;
|
4275 | // React on ngForOf changes only once all inputs have been initialized
|
4276 | /** @type {?} */
|
4277 | const value = this._ngForOf;
|
4278 | if (!this._differ && value) {
|
4279 | try {
|
4280 | this._differ = this._differs.find(value).create(this.ngForTrackBy);
|
4281 | }
|
4282 | catch (_a) {
|
4283 | throw new Error(`Cannot find a differ supporting object '${value}' of type '${getTypeName(value)}'. NgFor only supports binding to Iterables such as Arrays.`);
|
4284 | }
|
4285 | }
|
4286 | }
|
4287 | if (this._differ) {
|
4288 | /** @type {?} */
|
4289 | const changes = this._differ.diff(this._ngForOf);
|
4290 | if (changes)
|
4291 | this._applyChanges(changes);
|
4292 | }
|
4293 | }
|
4294 | /**
|
4295 | * @private
|
4296 | * @param {?} changes
|
4297 | * @return {?}
|
4298 | */
|
4299 | _applyChanges(changes) {
|
4300 | /** @type {?} */
|
4301 | const insertTuples = [];
|
4302 | changes.forEachOperation((/**
|
4303 | * @param {?} item
|
4304 | * @param {?} adjustedPreviousIndex
|
4305 | * @param {?} currentIndex
|
4306 | * @return {?}
|
4307 | */
|
4308 | (item, adjustedPreviousIndex, currentIndex) => {
|
4309 | if (item.previousIndex == null) {
|
4310 | // NgForOf is never "null" or "undefined" here because the differ detected
|
4311 | // that a new item needs to be inserted from the iterable. This implies that
|
4312 | // there is an iterable value for "_ngForOf".
|
4313 | /** @type {?} */
|
4314 | const view = this._viewContainer.createEmbeddedView(this._template, new NgForOfContext((/** @type {?} */ (null)), (/** @type {?} */ (this._ngForOf)), -1, -1), currentIndex === null ? undefined : currentIndex);
|
4315 | /** @type {?} */
|
4316 | const tuple = new RecordViewTuple(item, view);
|
4317 | insertTuples.push(tuple);
|
4318 | }
|
4319 | else if (currentIndex == null) {
|
4320 | this._viewContainer.remove(adjustedPreviousIndex === null ? undefined : adjustedPreviousIndex);
|
4321 | }
|
4322 | else if (adjustedPreviousIndex !== null) {
|
4323 | /** @type {?} */
|
4324 | const view = (/** @type {?} */ (this._viewContainer.get(adjustedPreviousIndex)));
|
4325 | this._viewContainer.move(view, currentIndex);
|
4326 | /** @type {?} */
|
4327 | const tuple = new RecordViewTuple(item, (/** @type {?} */ (view)));
|
4328 | insertTuples.push(tuple);
|
4329 | }
|
4330 | }));
|
4331 | for (let i = 0; i < insertTuples.length; i++) {
|
4332 | this._perViewChange(insertTuples[i].view, insertTuples[i].record);
|
4333 | }
|
4334 | for (let i = 0, ilen = this._viewContainer.length; i < ilen; i++) {
|
4335 | /** @type {?} */
|
4336 | const viewRef = (/** @type {?} */ (this._viewContainer.get(i)));
|
4337 | viewRef.context.index = i;
|
4338 | viewRef.context.count = ilen;
|
4339 | viewRef.context.ngForOf = (/** @type {?} */ (this._ngForOf));
|
4340 | }
|
4341 | changes.forEachIdentityChange((/**
|
4342 | * @param {?} record
|
4343 | * @return {?}
|
4344 | */
|
4345 | (record) => {
|
4346 | /** @type {?} */
|
4347 | const viewRef = (/** @type {?} */ (this._viewContainer.get(record.currentIndex)));
|
4348 | viewRef.context.$implicit = record.item;
|
4349 | }));
|
4350 | }
|
4351 | /**
|
4352 | * @private
|
4353 | * @param {?} view
|
4354 | * @param {?} record
|
4355 | * @return {?}
|
4356 | */
|
4357 | _perViewChange(view, record) {
|
4358 | view.context.$implicit = record.item;
|
4359 | }
|
4360 | /**
|
4361 | * Asserts the correct type of the context for the template that `NgForOf` will render.
|
4362 | *
|
4363 | * The presence of this method is a signal to the Ivy template type-check compiler that the
|
4364 | * `NgForOf` structural directive renders its template with a specific context type.
|
4365 | * @template T, U
|
4366 | * @param {?} dir
|
4367 | * @param {?} ctx
|
4368 | * @return {?}
|
4369 | */
|
4370 | static ngTemplateContextGuard(dir, ctx) {
|
4371 | return true;
|
4372 | }
|
4373 | }
|
4374 | NgForOf.decorators = [
|
4375 | { type: Directive, args: [{ selector: '[ngFor][ngForOf]' },] }
|
4376 | ];
|
4377 | /** @nocollapse */
|
4378 | NgForOf.ctorParameters = () => [
|
4379 | { type: ViewContainerRef },
|
4380 | { type: TemplateRef },
|
4381 | { type: IterableDiffers }
|
4382 | ];
|
4383 | NgForOf.propDecorators = {
|
4384 | ngForOf: [{ type: Input }],
|
4385 | ngForTrackBy: [{ type: Input }],
|
4386 | ngForTemplate: [{ type: Input }]
|
4387 | };
|
4388 | if (false) {
|
4389 | /**
|
4390 | * @type {?}
|
4391 | * @private
|
4392 | */
|
4393 | NgForOf.prototype._ngForOf;
|
4394 | /**
|
4395 | * @type {?}
|
4396 | * @private
|
4397 | */
|
4398 | NgForOf.prototype._ngForOfDirty;
|
4399 | /**
|
4400 | * @type {?}
|
4401 | * @private
|
4402 | */
|
4403 | NgForOf.prototype._differ;
|
4404 | /**
|
4405 | * @type {?}
|
4406 | * @private
|
4407 | */
|
4408 | NgForOf.prototype._trackByFn;
|
4409 | /**
|
4410 | * @type {?}
|
4411 | * @private
|
4412 | */
|
4413 | NgForOf.prototype._viewContainer;
|
4414 | /**
|
4415 | * @type {?}
|
4416 | * @private
|
4417 | */
|
4418 | NgForOf.prototype._template;
|
4419 | /**
|
4420 | * @type {?}
|
4421 | * @private
|
4422 | */
|
4423 | NgForOf.prototype._differs;
|
4424 | }
|
4425 | /**
|
4426 | * @template T, U
|
4427 | */
|
4428 | class RecordViewTuple {
|
4429 | /**
|
4430 | * @param {?} record
|
4431 | * @param {?} view
|
4432 | */
|
4433 | constructor(record, view) {
|
4434 | this.record = record;
|
4435 | this.view = view;
|
4436 | }
|
4437 | }
|
4438 | if (false) {
|
4439 | /** @type {?} */
|
4440 | RecordViewTuple.prototype.record;
|
4441 | /** @type {?} */
|
4442 | RecordViewTuple.prototype.view;
|
4443 | }
|
4444 | /**
|
4445 | * @param {?} type
|
4446 | * @return {?}
|
4447 | */
|
4448 | function getTypeName(type) {
|
4449 | return type['name'] || typeof type;
|
4450 | }
|
4451 |
|
4452 | /**
|
4453 | * @fileoverview added by tsickle
|
4454 | * Generated from: packages/common/src/directives/ng_if.ts
|
4455 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
4456 | */
|
4457 | /**
|
4458 | * A structural directive that conditionally includes a template based on the value of
|
4459 | * an expression coerced to Boolean.
|
4460 | * When the expression evaluates to true, Angular renders the template
|
4461 | * provided in a `then` clause, and when false or null,
|
4462 | * Angular renders the template provided in an optional `else` clause. The default
|
4463 | * template for the `else` clause is blank.
|
4464 | *
|
4465 | * A [shorthand form](guide/structural-directives#the-asterisk--prefix) of the directive,
|
4466 | * `*ngIf="condition"`, is generally used, provided
|
4467 | * as an attribute of the anchor element for the inserted template.
|
4468 | * Angular expands this into a more explicit version, in which the anchor element
|
4469 | * is contained in an `<ng-template>` element.
|
4470 | *
|
4471 | * Simple form with shorthand syntax:
|
4472 | *
|
4473 | * ```
|
4474 | * <div *ngIf="condition">Content to render when condition is true.</div>
|
4475 | * ```
|
4476 | *
|
4477 | * Simple form with expanded syntax:
|
4478 | *
|
4479 | * ```
|
4480 | * <ng-template [ngIf]="condition"><div>Content to render when condition is
|
4481 | * true.</div></ng-template>
|
4482 | * ```
|
4483 | *
|
4484 | * Form with an "else" block:
|
4485 | *
|
4486 | * ```
|
4487 | * <div *ngIf="condition; else elseBlock">Content to render when condition is true.</div>
|
4488 | * <ng-template #elseBlock>Content to render when condition is false.</ng-template>
|
4489 | * ```
|
4490 | *
|
4491 | * Shorthand form with "then" and "else" blocks:
|
4492 | *
|
4493 | * ```
|
4494 | * <div *ngIf="condition; then thenBlock else elseBlock"></div>
|
4495 | * <ng-template #thenBlock>Content to render when condition is true.</ng-template>
|
4496 | * <ng-template #elseBlock>Content to render when condition is false.</ng-template>
|
4497 | * ```
|
4498 | *
|
4499 | * Form with storing the value locally:
|
4500 | *
|
4501 | * ```
|
4502 | * <div *ngIf="condition as value; else elseBlock">{{value}}</div>
|
4503 | * <ng-template #elseBlock>Content to render when value is null.</ng-template>
|
4504 | * ```
|
4505 | *
|
4506 | * \@usageNotes
|
4507 | *
|
4508 | * The `*ngIf` directive is most commonly used to conditionally show an inline template,
|
4509 | * as seen in the following example.
|
4510 | * The default `else` template is blank.
|
4511 | *
|
4512 | * {\@example common/ngIf/ts/module.ts region='NgIfSimple'}
|
4513 | *
|
4514 | * ### Showing an alternative template using `else`
|
4515 | *
|
4516 | * To display a template when `expression` evaluates to false, use an `else` template
|
4517 | * binding as shown in the following example.
|
4518 | * The `else` binding points to an `<ng-template>` element labeled `#elseBlock`.
|
4519 | * The template can be defined anywhere in the component view, but is typically placed right after
|
4520 | * `ngIf` for readability.
|
4521 | *
|
4522 | * {\@example common/ngIf/ts/module.ts region='NgIfElse'}
|
4523 | *
|
4524 | * ### Using an external `then` template
|
4525 | *
|
4526 | * In the previous example, the then-clause template is specified inline, as the content of the
|
4527 | * tag that contains the `ngIf` directive. You can also specify a template that is defined
|
4528 | * externally, by referencing a labeled `<ng-template>` element. When you do this, you can
|
4529 | * change which template to use at runtime, as shown in the following example.
|
4530 | *
|
4531 | * {\@example common/ngIf/ts/module.ts region='NgIfThenElse'}
|
4532 | *
|
4533 | * ### Storing a conditional result in a variable
|
4534 | *
|
4535 | * You might want to show a set of properties from the same object. If you are waiting
|
4536 | * for asynchronous data, the object can be undefined.
|
4537 | * In this case, you can use `ngIf` and store the result of the condition in a local
|
4538 | * variable as shown in the the following example.
|
4539 | *
|
4540 | * {\@example common/ngIf/ts/module.ts region='NgIfAs'}
|
4541 | *
|
4542 | * This code uses only one `AsyncPipe`, so only one subscription is created.
|
4543 | * The conditional statement stores the result of `userStream|async` in the local variable `user`.
|
4544 | * You can then bind the local `user` repeatedly.
|
4545 | *
|
4546 | * The conditional displays the data only if `userStream` returns a value,
|
4547 | * so you don't need to use the
|
4548 | * [safe-navigation-operator](guide/template-syntax#safe-navigation-operator) (`?.`)
|
4549 | * to guard against null values when accessing properties.
|
4550 | * You can display an alternative template while waiting for the data.
|
4551 | *
|
4552 | * ### Shorthand syntax
|
4553 | *
|
4554 | * The shorthand syntax `*ngIf` expands into two separate template specifications
|
4555 | * for the "then" and "else" clauses. For example, consider the following shorthand statement,
|
4556 | * that is meant to show a loading page while waiting for data to be loaded.
|
4557 | *
|
4558 | * ```
|
4559 | * <div class="hero-list" *ngIf="heroes else loading">
|
4560 | * ...
|
4561 | * </div>
|
4562 | *
|
4563 | * <ng-template #loading>
|
4564 | * <div>Loading...</div>
|
4565 | * </ng-template>
|
4566 | * ```
|
4567 | *
|
4568 | * You can see that the "else" clause references the `<ng-template>`
|
4569 | * with the `#loading` label, and the template for the "then" clause
|
4570 | * is provided as the content of the anchor element.
|
4571 | *
|
4572 | * However, when Angular expands the shorthand syntax, it creates
|
4573 | * another `<ng-template>` tag, with `ngIf` and `ngIfElse` directives.
|
4574 | * The anchor element containing the template for the "then" clause becomes
|
4575 | * the content of this unlabeled `<ng-template>` tag.
|
4576 | *
|
4577 | * ```
|
4578 | * <ng-template [ngIf]="heroes" [ngIfElse]="loading">
|
4579 | * <div class="hero-list">
|
4580 | * ...
|
4581 | * </div>
|
4582 | * </ng-template>
|
4583 | *
|
4584 | * <ng-template #loading>
|
4585 | * <div>Loading...</div>
|
4586 | * </ng-template>
|
4587 | * ```
|
4588 | *
|
4589 | * The presence of the implicit template object has implications for the nesting of
|
4590 | * structural directives. For more on this subject, see
|
4591 | * [Structural Directives](https://angular.io/guide/structural-directives#one-per-element).
|
4592 | *
|
4593 | * \@ngModule CommonModule
|
4594 | * \@publicApi
|
4595 | * @template T
|
4596 | */
|
4597 | class NgIf {
|
4598 | /**
|
4599 | * @param {?} _viewContainer
|
4600 | * @param {?} templateRef
|
4601 | */
|
4602 | constructor(_viewContainer, templateRef) {
|
4603 | this._viewContainer = _viewContainer;
|
4604 | this._context = new NgIfContext();
|
4605 | this._thenTemplateRef = null;
|
4606 | this._elseTemplateRef = null;
|
4607 | this._thenViewRef = null;
|
4608 | this._elseViewRef = null;
|
4609 | this._thenTemplateRef = templateRef;
|
4610 | }
|
4611 | /**
|
4612 | * The Boolean expression to evaluate as the condition for showing a template.
|
4613 | * @param {?} condition
|
4614 | * @return {?}
|
4615 | */
|
4616 | set ngIf(condition) {
|
4617 | this._context.$implicit = this._context.ngIf = condition;
|
4618 | this._updateView();
|
4619 | }
|
4620 | /**
|
4621 | * A template to show if the condition expression evaluates to true.
|
4622 | * @param {?} templateRef
|
4623 | * @return {?}
|
4624 | */
|
4625 | set ngIfThen(templateRef) {
|
4626 | assertTemplate('ngIfThen', templateRef);
|
4627 | this._thenTemplateRef = templateRef;
|
4628 | this._thenViewRef = null; // clear previous view if any.
|
4629 | this._updateView();
|
4630 | }
|
4631 | /**
|
4632 | * A template to show if the condition expression evaluates to false.
|
4633 | * @param {?} templateRef
|
4634 | * @return {?}
|
4635 | */
|
4636 | set ngIfElse(templateRef) {
|
4637 | assertTemplate('ngIfElse', templateRef);
|
4638 | this._elseTemplateRef = templateRef;
|
4639 | this._elseViewRef = null; // clear previous view if any.
|
4640 | this._updateView();
|
4641 | }
|
4642 | /**
|
4643 | * @private
|
4644 | * @return {?}
|
4645 | */
|
4646 | _updateView() {
|
4647 | if (this._context.$implicit) {
|
4648 | if (!this._thenViewRef) {
|
4649 | this._viewContainer.clear();
|
4650 | this._elseViewRef = null;
|
4651 | if (this._thenTemplateRef) {
|
4652 | this._thenViewRef =
|
4653 | this._viewContainer.createEmbeddedView(this._thenTemplateRef, this._context);
|
4654 | }
|
4655 | }
|
4656 | }
|
4657 | else {
|
4658 | if (!this._elseViewRef) {
|
4659 | this._viewContainer.clear();
|
4660 | this._thenViewRef = null;
|
4661 | if (this._elseTemplateRef) {
|
4662 | this._elseViewRef =
|
4663 | this._viewContainer.createEmbeddedView(this._elseTemplateRef, this._context);
|
4664 | }
|
4665 | }
|
4666 | }
|
4667 | }
|
4668 | /**
|
4669 | * Asserts the correct type of the context for the template that `NgIf` will render.
|
4670 | *
|
4671 | * The presence of this method is a signal to the Ivy template type-check compiler that the
|
4672 | * `NgIf` structural directive renders its template with a specific context type.
|
4673 | * @template T
|
4674 | * @param {?} dir
|
4675 | * @param {?} ctx
|
4676 | * @return {?}
|
4677 | */
|
4678 | static ngTemplateContextGuard(dir, ctx) { return true; }
|
4679 | }
|
4680 | NgIf.decorators = [
|
4681 | { type: Directive, args: [{ selector: '[ngIf]' },] }
|
4682 | ];
|
4683 | /** @nocollapse */
|
4684 | NgIf.ctorParameters = () => [
|
4685 | { type: ViewContainerRef },
|
4686 | { type: TemplateRef }
|
4687 | ];
|
4688 | NgIf.propDecorators = {
|
4689 | ngIf: [{ type: Input }],
|
4690 | ngIfThen: [{ type: Input }],
|
4691 | ngIfElse: [{ type: Input }]
|
4692 | };
|
4693 | if (false) {
|
4694 | /**
|
4695 | * \@internal
|
4696 | * @type {?}
|
4697 | */
|
4698 | NgIf.ngIfUseIfTypeGuard;
|
4699 | /**
|
4700 | * Assert the correct type of the expression bound to the `ngIf` input within the template.
|
4701 | *
|
4702 | * The presence of this static field is a signal to the Ivy template type check compiler that
|
4703 | * when the `NgIf` structural directive renders its template, the type of the expression bound
|
4704 | * to `ngIf` should be narrowed in some way. For `NgIf`, the binding expression itself is used to
|
4705 | * narrow its type, which allows the strictNullChecks feature of TypeScript to work with `NgIf`.
|
4706 | * @type {?}
|
4707 | */
|
4708 | NgIf.ngTemplateGuard_ngIf;
|
4709 | /**
|
4710 | * @type {?}
|
4711 | * @private
|
4712 | */
|
4713 | NgIf.prototype._context;
|
4714 | /**
|
4715 | * @type {?}
|
4716 | * @private
|
4717 | */
|
4718 | NgIf.prototype._thenTemplateRef;
|
4719 | /**
|
4720 | * @type {?}
|
4721 | * @private
|
4722 | */
|
4723 | NgIf.prototype._elseTemplateRef;
|
4724 | /**
|
4725 | * @type {?}
|
4726 | * @private
|
4727 | */
|
4728 | NgIf.prototype._thenViewRef;
|
4729 | /**
|
4730 | * @type {?}
|
4731 | * @private
|
4732 | */
|
4733 | NgIf.prototype._elseViewRef;
|
4734 | /**
|
4735 | * @type {?}
|
4736 | * @private
|
4737 | */
|
4738 | NgIf.prototype._viewContainer;
|
4739 | }
|
4740 | /**
|
4741 | * \@publicApi
|
4742 | * @template T
|
4743 | */
|
4744 | class NgIfContext {
|
4745 | constructor() {
|
4746 | this.$implicit = (/** @type {?} */ (null));
|
4747 | this.ngIf = (/** @type {?} */ (null));
|
4748 | }
|
4749 | }
|
4750 | if (false) {
|
4751 | /** @type {?} */
|
4752 | NgIfContext.prototype.$implicit;
|
4753 | /** @type {?} */
|
4754 | NgIfContext.prototype.ngIf;
|
4755 | }
|
4756 | /**
|
4757 | * @param {?} property
|
4758 | * @param {?} templateRef
|
4759 | * @return {?}
|
4760 | */
|
4761 | function assertTemplate(property, templateRef) {
|
4762 | /** @type {?} */
|
4763 | const isTemplateRefOrNull = !!(!templateRef || templateRef.createEmbeddedView);
|
4764 | if (!isTemplateRefOrNull) {
|
4765 | throw new Error(`${property} must be a TemplateRef, but received '${ɵstringify(templateRef)}'.`);
|
4766 | }
|
4767 | }
|
4768 |
|
4769 | /**
|
4770 | * @fileoverview added by tsickle
|
4771 | * Generated from: packages/common/src/directives/ng_switch.ts
|
4772 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
4773 | */
|
4774 | class SwitchView {
|
4775 | /**
|
4776 | * @param {?} _viewContainerRef
|
4777 | * @param {?} _templateRef
|
4778 | */
|
4779 | constructor(_viewContainerRef, _templateRef) {
|
4780 | this._viewContainerRef = _viewContainerRef;
|
4781 | this._templateRef = _templateRef;
|
4782 | this._created = false;
|
4783 | }
|
4784 | /**
|
4785 | * @return {?}
|
4786 | */
|
4787 | create() {
|
4788 | this._created = true;
|
4789 | this._viewContainerRef.createEmbeddedView(this._templateRef);
|
4790 | }
|
4791 | /**
|
4792 | * @return {?}
|
4793 | */
|
4794 | destroy() {
|
4795 | this._created = false;
|
4796 | this._viewContainerRef.clear();
|
4797 | }
|
4798 | /**
|
4799 | * @param {?} created
|
4800 | * @return {?}
|
4801 | */
|
4802 | enforceState(created) {
|
4803 | if (created && !this._created) {
|
4804 | this.create();
|
4805 | }
|
4806 | else if (!created && this._created) {
|
4807 | this.destroy();
|
4808 | }
|
4809 | }
|
4810 | }
|
4811 | if (false) {
|
4812 | /**
|
4813 | * @type {?}
|
4814 | * @private
|
4815 | */
|
4816 | SwitchView.prototype._created;
|
4817 | /**
|
4818 | * @type {?}
|
4819 | * @private
|
4820 | */
|
4821 | SwitchView.prototype._viewContainerRef;
|
4822 | /**
|
4823 | * @type {?}
|
4824 | * @private
|
4825 | */
|
4826 | SwitchView.prototype._templateRef;
|
4827 | }
|
4828 | /**
|
4829 | * \@ngModule CommonModule
|
4830 | *
|
4831 | * \@description A structural directive that adds or removes templates (displaying or hiding views)
|
4832 | * when the next match expression matches the switch expression.
|
4833 | *
|
4834 | * The `[ngSwitch]` directive on a container specifies an expression to match against.
|
4835 | * The expressions to match are provided by `ngSwitchCase` directives on views within the container.
|
4836 | * - Every view that matches is rendered.
|
4837 | * - If there are no matches, a view with the `ngSwitchDefault` directive is rendered.
|
4838 | * - Elements within the `[NgSwitch]` statement but outside of any `NgSwitchCase`
|
4839 | * or `ngSwitchDefault` directive are preserved at the location.
|
4840 | *
|
4841 | * \@usageNotes
|
4842 | * Define a container element for the directive, and specify the switch expression
|
4843 | * to match against as an attribute:
|
4844 | *
|
4845 | * ```
|
4846 | * <container-element [ngSwitch]="switch_expression">
|
4847 | * ```
|
4848 | *
|
4849 | * Within the container, `*ngSwitchCase` statements specify the match expressions
|
4850 | * as attributes. Include `*ngSwitchDefault` as the final case.
|
4851 | *
|
4852 | * ```
|
4853 | * <container-element [ngSwitch]="switch_expression">
|
4854 | * <some-element *ngSwitchCase="match_expression_1">...</some-element>
|
4855 | * ...
|
4856 | * <some-element *ngSwitchDefault>...</some-element>
|
4857 | * </container-element>
|
4858 | * ```
|
4859 | *
|
4860 | * ### Usage Examples
|
4861 | *
|
4862 | * The following example shows how to use more than one case to display the same view:
|
4863 | *
|
4864 | * ```
|
4865 | * <container-element [ngSwitch]="switch_expression">
|
4866 | * <!-- the same view can be shown in more than one case -->
|
4867 | * <some-element *ngSwitchCase="match_expression_1">...</some-element>
|
4868 | * <some-element *ngSwitchCase="match_expression_2">...</some-element>
|
4869 | * <some-other-element *ngSwitchCase="match_expression_3">...</some-other-element>
|
4870 | * <!--default case when there are no matches -->
|
4871 | * <some-element *ngSwitchDefault>...</some-element>
|
4872 | * </container-element>
|
4873 | * ```
|
4874 | *
|
4875 | * The following example shows how cases can be nested:
|
4876 | * ```
|
4877 | * <container-element [ngSwitch]="switch_expression">
|
4878 | * <some-element *ngSwitchCase="match_expression_1">...</some-element>
|
4879 | * <some-element *ngSwitchCase="match_expression_2">...</some-element>
|
4880 | * <some-other-element *ngSwitchCase="match_expression_3">...</some-other-element>
|
4881 | * <ng-container *ngSwitchCase="match_expression_3">
|
4882 | * <!-- use a ng-container to group multiple root nodes -->
|
4883 | * <inner-element></inner-element>
|
4884 | * <inner-other-element></inner-other-element>
|
4885 | * </ng-container>
|
4886 | * <some-element *ngSwitchDefault>...</some-element>
|
4887 | * </container-element>
|
4888 | * ```
|
4889 | *
|
4890 | * \@publicApi
|
4891 | * @see `NgSwitchCase`
|
4892 | * @see `NgSwitchDefault`
|
4893 | * @see [Structural Directives](guide/structural-directives)
|
4894 | *
|
4895 | */
|
4896 | class NgSwitch {
|
4897 | constructor() {
|
4898 | this._defaultUsed = false;
|
4899 | this._caseCount = 0;
|
4900 | this._lastCaseCheckIndex = 0;
|
4901 | this._lastCasesMatched = false;
|
4902 | }
|
4903 | /**
|
4904 | * @param {?} newValue
|
4905 | * @return {?}
|
4906 | */
|
4907 | set ngSwitch(newValue) {
|
4908 | this._ngSwitch = newValue;
|
4909 | if (this._caseCount === 0) {
|
4910 | this._updateDefaultCases(true);
|
4911 | }
|
4912 | }
|
4913 | /**
|
4914 | * \@internal
|
4915 | * @return {?}
|
4916 | */
|
4917 | _addCase() { return this._caseCount++; }
|
4918 | /**
|
4919 | * \@internal
|
4920 | * @param {?} view
|
4921 | * @return {?}
|
4922 | */
|
4923 | _addDefault(view) {
|
4924 | if (!this._defaultViews) {
|
4925 | this._defaultViews = [];
|
4926 | }
|
4927 | this._defaultViews.push(view);
|
4928 | }
|
4929 | /**
|
4930 | * \@internal
|
4931 | * @param {?} value
|
4932 | * @return {?}
|
4933 | */
|
4934 | _matchCase(value) {
|
4935 | /** @type {?} */
|
4936 | const matched = value == this._ngSwitch;
|
4937 | this._lastCasesMatched = this._lastCasesMatched || matched;
|
4938 | this._lastCaseCheckIndex++;
|
4939 | if (this._lastCaseCheckIndex === this._caseCount) {
|
4940 | this._updateDefaultCases(!this._lastCasesMatched);
|
4941 | this._lastCaseCheckIndex = 0;
|
4942 | this._lastCasesMatched = false;
|
4943 | }
|
4944 | return matched;
|
4945 | }
|
4946 | /**
|
4947 | * @private
|
4948 | * @param {?} useDefault
|
4949 | * @return {?}
|
4950 | */
|
4951 | _updateDefaultCases(useDefault) {
|
4952 | if (this._defaultViews && useDefault !== this._defaultUsed) {
|
4953 | this._defaultUsed = useDefault;
|
4954 | for (let i = 0; i < this._defaultViews.length; i++) {
|
4955 | /** @type {?} */
|
4956 | const defaultView = this._defaultViews[i];
|
4957 | defaultView.enforceState(useDefault);
|
4958 | }
|
4959 | }
|
4960 | }
|
4961 | }
|
4962 | NgSwitch.decorators = [
|
4963 | { type: Directive, args: [{ selector: '[ngSwitch]' },] }
|
4964 | ];
|
4965 | NgSwitch.propDecorators = {
|
4966 | ngSwitch: [{ type: Input }]
|
4967 | };
|
4968 | if (false) {
|
4969 | /**
|
4970 | * @type {?}
|
4971 | * @private
|
4972 | */
|
4973 | NgSwitch.prototype._defaultViews;
|
4974 | /**
|
4975 | * @type {?}
|
4976 | * @private
|
4977 | */
|
4978 | NgSwitch.prototype._defaultUsed;
|
4979 | /**
|
4980 | * @type {?}
|
4981 | * @private
|
4982 | */
|
4983 | NgSwitch.prototype._caseCount;
|
4984 | /**
|
4985 | * @type {?}
|
4986 | * @private
|
4987 | */
|
4988 | NgSwitch.prototype._lastCaseCheckIndex;
|
4989 | /**
|
4990 | * @type {?}
|
4991 | * @private
|
4992 | */
|
4993 | NgSwitch.prototype._lastCasesMatched;
|
4994 | /**
|
4995 | * @type {?}
|
4996 | * @private
|
4997 | */
|
4998 | NgSwitch.prototype._ngSwitch;
|
4999 | }
|
5000 | /**
|
5001 | * \@ngModule CommonModule
|
5002 | *
|
5003 | * \@description
|
5004 | * Provides a switch case expression to match against an enclosing `ngSwitch` expression.
|
5005 | * When the expressions match, the given `NgSwitchCase` template is rendered.
|
5006 | * If multiple match expressions match the switch expression value, all of them are displayed.
|
5007 | *
|
5008 | * \@usageNotes
|
5009 | *
|
5010 | * Within a switch container, `*ngSwitchCase` statements specify the match expressions
|
5011 | * as attributes. Include `*ngSwitchDefault` as the final case.
|
5012 | *
|
5013 | * ```
|
5014 | * <container-element [ngSwitch]="switch_expression">
|
5015 | * <some-element *ngSwitchCase="match_expression_1">...</some-element>
|
5016 | * ...
|
5017 | * <some-element *ngSwitchDefault>...</some-element>
|
5018 | * </container-element>
|
5019 | * ```
|
5020 | *
|
5021 | * Each switch-case statement contains an in-line HTML template or template reference
|
5022 | * that defines the subtree to be selected if the value of the match expression
|
5023 | * matches the value of the switch expression.
|
5024 | *
|
5025 | * Unlike JavaScript, which uses strict equality, Angular uses loose equality.
|
5026 | * This means that the empty string, `""` matches 0.
|
5027 | *
|
5028 | * \@publicApi
|
5029 | * @see `NgSwitch`
|
5030 | * @see `NgSwitchDefault`
|
5031 | *
|
5032 | */
|
5033 | class NgSwitchCase {
|
5034 | /**
|
5035 | * @param {?} viewContainer
|
5036 | * @param {?} templateRef
|
5037 | * @param {?} ngSwitch
|
5038 | */
|
5039 | constructor(viewContainer, templateRef, ngSwitch) {
|
5040 | this.ngSwitch = ngSwitch;
|
5041 | ngSwitch._addCase();
|
5042 | this._view = new SwitchView(viewContainer, templateRef);
|
5043 | }
|
5044 | /**
|
5045 | * Performs case matching. For internal use only.
|
5046 | * @return {?}
|
5047 | */
|
5048 | ngDoCheck() { this._view.enforceState(this.ngSwitch._matchCase(this.ngSwitchCase)); }
|
5049 | }
|
5050 | NgSwitchCase.decorators = [
|
5051 | { type: Directive, args: [{ selector: '[ngSwitchCase]' },] }
|
5052 | ];
|
5053 | /** @nocollapse */
|
5054 | NgSwitchCase.ctorParameters = () => [
|
5055 | { type: ViewContainerRef },
|
5056 | { type: TemplateRef },
|
5057 | { type: NgSwitch, decorators: [{ type: Host }] }
|
5058 | ];
|
5059 | NgSwitchCase.propDecorators = {
|
5060 | ngSwitchCase: [{ type: Input }]
|
5061 | };
|
5062 | if (false) {
|
5063 | /**
|
5064 | * @type {?}
|
5065 | * @private
|
5066 | */
|
5067 | NgSwitchCase.prototype._view;
|
5068 | /**
|
5069 | * Stores the HTML template to be selected on match.
|
5070 | * @type {?}
|
5071 | */
|
5072 | NgSwitchCase.prototype.ngSwitchCase;
|
5073 | /**
|
5074 | * @type {?}
|
5075 | * @private
|
5076 | */
|
5077 | NgSwitchCase.prototype.ngSwitch;
|
5078 | }
|
5079 | /**
|
5080 | * \@ngModule CommonModule
|
5081 | *
|
5082 | * \@description
|
5083 | *
|
5084 | * Creates a view that is rendered when no `NgSwitchCase` expressions
|
5085 | * match the `NgSwitch` expression.
|
5086 | * This statement should be the final case in an `NgSwitch`.
|
5087 | *
|
5088 | * \@publicApi
|
5089 | * @see `NgSwitch`
|
5090 | * @see `NgSwitchCase`
|
5091 | *
|
5092 | */
|
5093 | class NgSwitchDefault {
|
5094 | /**
|
5095 | * @param {?} viewContainer
|
5096 | * @param {?} templateRef
|
5097 | * @param {?} ngSwitch
|
5098 | */
|
5099 | constructor(viewContainer, templateRef, ngSwitch) {
|
5100 | ngSwitch._addDefault(new SwitchView(viewContainer, templateRef));
|
5101 | }
|
5102 | }
|
5103 | NgSwitchDefault.decorators = [
|
5104 | { type: Directive, args: [{ selector: '[ngSwitchDefault]' },] }
|
5105 | ];
|
5106 | /** @nocollapse */
|
5107 | NgSwitchDefault.ctorParameters = () => [
|
5108 | { type: ViewContainerRef },
|
5109 | { type: TemplateRef },
|
5110 | { type: NgSwitch, decorators: [{ type: Host }] }
|
5111 | ];
|
5112 |
|
5113 | /**
|
5114 | * @fileoverview added by tsickle
|
5115 | * Generated from: packages/common/src/directives/ng_plural.ts
|
5116 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
5117 | */
|
5118 | /**
|
5119 | * \@ngModule CommonModule
|
5120 | *
|
5121 | * \@usageNotes
|
5122 | * ```
|
5123 | * <some-element [ngPlural]="value">
|
5124 | * <ng-template ngPluralCase="=0">there is nothing</ng-template>
|
5125 | * <ng-template ngPluralCase="=1">there is one</ng-template>
|
5126 | * <ng-template ngPluralCase="few">there are a few</ng-template>
|
5127 | * </some-element>
|
5128 | * ```
|
5129 | *
|
5130 | * \@description
|
5131 | *
|
5132 | * Adds / removes DOM sub-trees based on a numeric value. Tailored for pluralization.
|
5133 | *
|
5134 | * Displays DOM sub-trees that match the switch expression value, or failing that, DOM sub-trees
|
5135 | * that match the switch expression's pluralization category.
|
5136 | *
|
5137 | * To use this directive you must provide a container element that sets the `[ngPlural]` attribute
|
5138 | * to a switch expression. Inner elements with a `[ngPluralCase]` will display based on their
|
5139 | * expression:
|
5140 | * - if `[ngPluralCase]` is set to a value starting with `=`, it will only display if the value
|
5141 | * matches the switch expression exactly,
|
5142 | * - otherwise, the view will be treated as a "category match", and will only display if exact
|
5143 | * value matches aren't found and the value maps to its category for the defined locale.
|
5144 | *
|
5145 | * See http://cldr.unicode.org/index/cldr-spec/plural-rules
|
5146 | *
|
5147 | * \@publicApi
|
5148 | */
|
5149 | class NgPlural {
|
5150 | /**
|
5151 | * @param {?} _localization
|
5152 | */
|
5153 | constructor(_localization) {
|
5154 | this._localization = _localization;
|
5155 | this._caseViews = {};
|
5156 | }
|
5157 | /**
|
5158 | * @param {?} value
|
5159 | * @return {?}
|
5160 | */
|
5161 | set ngPlural(value) {
|
5162 | this._switchValue = value;
|
5163 | this._updateView();
|
5164 | }
|
5165 | /**
|
5166 | * @param {?} value
|
5167 | * @param {?} switchView
|
5168 | * @return {?}
|
5169 | */
|
5170 | addCase(value, switchView) { this._caseViews[value] = switchView; }
|
5171 | /**
|
5172 | * @private
|
5173 | * @return {?}
|
5174 | */
|
5175 | _updateView() {
|
5176 | this._clearViews();
|
5177 | /** @type {?} */
|
5178 | const cases = Object.keys(this._caseViews);
|
5179 | /** @type {?} */
|
5180 | const key = getPluralCategory(this._switchValue, cases, this._localization);
|
5181 | this._activateView(this._caseViews[key]);
|
5182 | }
|
5183 | /**
|
5184 | * @private
|
5185 | * @return {?}
|
5186 | */
|
5187 | _clearViews() {
|
5188 | if (this._activeView)
|
5189 | this._activeView.destroy();
|
5190 | }
|
5191 | /**
|
5192 | * @private
|
5193 | * @param {?} view
|
5194 | * @return {?}
|
5195 | */
|
5196 | _activateView(view) {
|
5197 | if (view) {
|
5198 | this._activeView = view;
|
5199 | this._activeView.create();
|
5200 | }
|
5201 | }
|
5202 | }
|
5203 | NgPlural.decorators = [
|
5204 | { type: Directive, args: [{ selector: '[ngPlural]' },] }
|
5205 | ];
|
5206 | /** @nocollapse */
|
5207 | NgPlural.ctorParameters = () => [
|
5208 | { type: NgLocalization }
|
5209 | ];
|
5210 | NgPlural.propDecorators = {
|
5211 | ngPlural: [{ type: Input }]
|
5212 | };
|
5213 | if (false) {
|
5214 | /**
|
5215 | * @type {?}
|
5216 | * @private
|
5217 | */
|
5218 | NgPlural.prototype._switchValue;
|
5219 | /**
|
5220 | * @type {?}
|
5221 | * @private
|
5222 | */
|
5223 | NgPlural.prototype._activeView;
|
5224 | /**
|
5225 | * @type {?}
|
5226 | * @private
|
5227 | */
|
5228 | NgPlural.prototype._caseViews;
|
5229 | /**
|
5230 | * @type {?}
|
5231 | * @private
|
5232 | */
|
5233 | NgPlural.prototype._localization;
|
5234 | }
|
5235 | /**
|
5236 | * \@ngModule CommonModule
|
5237 | *
|
5238 | * \@description
|
5239 | *
|
5240 | * Creates a view that will be added/removed from the parent {\@link NgPlural} when the
|
5241 | * given expression matches the plural expression according to CLDR rules.
|
5242 | *
|
5243 | * \@usageNotes
|
5244 | * ```
|
5245 | * <some-element [ngPlural]="value">
|
5246 | * <ng-template ngPluralCase="=0">...</ng-template>
|
5247 | * <ng-template ngPluralCase="other">...</ng-template>
|
5248 | * </some-element>
|
5249 | * ```
|
5250 | *
|
5251 | * See {\@link NgPlural} for more details and example.
|
5252 | *
|
5253 | * \@publicApi
|
5254 | */
|
5255 | class NgPluralCase {
|
5256 | /**
|
5257 | * @param {?} value
|
5258 | * @param {?} template
|
5259 | * @param {?} viewContainer
|
5260 | * @param {?} ngPlural
|
5261 | */
|
5262 | constructor(value, template, viewContainer, ngPlural) {
|
5263 | this.value = value;
|
5264 | /** @type {?} */
|
5265 | const isANumber = !isNaN(Number(value));
|
5266 | ngPlural.addCase(isANumber ? `=${value}` : value, new SwitchView(viewContainer, template));
|
5267 | }
|
5268 | }
|
5269 | NgPluralCase.decorators = [
|
5270 | { type: Directive, args: [{ selector: '[ngPluralCase]' },] }
|
5271 | ];
|
5272 | /** @nocollapse */
|
5273 | NgPluralCase.ctorParameters = () => [
|
5274 | { type: String, decorators: [{ type: Attribute, args: ['ngPluralCase',] }] },
|
5275 | { type: TemplateRef },
|
5276 | { type: ViewContainerRef },
|
5277 | { type: NgPlural, decorators: [{ type: Host }] }
|
5278 | ];
|
5279 | if (false) {
|
5280 | /** @type {?} */
|
5281 | NgPluralCase.prototype.value;
|
5282 | }
|
5283 |
|
5284 | /**
|
5285 | * @fileoverview added by tsickle
|
5286 | * Generated from: packages/common/src/directives/ng_style.ts
|
5287 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
5288 | */
|
5289 | /**
|
5290 | * \@ngModule CommonModule
|
5291 | *
|
5292 | * \@usageNotes
|
5293 | *
|
5294 | * Set the font of the containing element to the result of an expression.
|
5295 | *
|
5296 | * ```
|
5297 | * <some-element [ngStyle]="{'font-style': styleExp}">...</some-element>
|
5298 | * ```
|
5299 | *
|
5300 | * Set the width of the containing element to a pixel value returned by an expression.
|
5301 | *
|
5302 | * ```
|
5303 | * <some-element [ngStyle]="{'max-width.px': widthExp}">...</some-element>
|
5304 | * ```
|
5305 | *
|
5306 | * Set a collection of style values using an expression that returns key-value pairs.
|
5307 | *
|
5308 | * ```
|
5309 | * <some-element [ngStyle]="objExp">...</some-element>
|
5310 | * ```
|
5311 | *
|
5312 | * \@description
|
5313 | *
|
5314 | * An attribute directive that updates styles for the containing HTML element.
|
5315 | * Sets one or more style properties, specified as colon-separated key-value pairs.
|
5316 | * The key is a style name, with an optional `.<unit>` suffix
|
5317 | * (such as 'top.px', 'font-style.em').
|
5318 | * The value is an expression to be evaluated.
|
5319 | * The resulting non-null value, expressed in the given unit,
|
5320 | * is assigned to the given style property.
|
5321 | * If the result of evaluation is null, the corresponding style is removed.
|
5322 | *
|
5323 | * \@publicApi
|
5324 | */
|
5325 | class NgStyle {
|
5326 | /**
|
5327 | * @param {?} _ngEl
|
5328 | * @param {?} _differs
|
5329 | * @param {?} _renderer
|
5330 | */
|
5331 | constructor(_ngEl, _differs, _renderer) {
|
5332 | this._ngEl = _ngEl;
|
5333 | this._differs = _differs;
|
5334 | this._renderer = _renderer;
|
5335 | this._ngStyle = null;
|
5336 | this._differ = null;
|
5337 | }
|
5338 | /**
|
5339 | * @param {?} values
|
5340 | * @return {?}
|
5341 | */
|
5342 | set ngStyle(values) {
|
5343 | this._ngStyle = values;
|
5344 | if (!this._differ && values) {
|
5345 | this._differ = this._differs.find(values).create();
|
5346 | }
|
5347 | }
|
5348 | /**
|
5349 | * @return {?}
|
5350 | */
|
5351 | ngDoCheck() {
|
5352 | if (this._differ) {
|
5353 | /** @type {?} */
|
5354 | const changes = this._differ.diff((/** @type {?} */ (this._ngStyle)));
|
5355 | if (changes) {
|
5356 | this._applyChanges(changes);
|
5357 | }
|
5358 | }
|
5359 | }
|
5360 | /**
|
5361 | * @private
|
5362 | * @param {?} nameAndUnit
|
5363 | * @param {?} value
|
5364 | * @return {?}
|
5365 | */
|
5366 | _setStyle(nameAndUnit, value) {
|
5367 | const [name, unit] = nameAndUnit.split('.');
|
5368 | value = value != null && unit ? `${value}${unit}` : value;
|
5369 | if (value != null) {
|
5370 | this._renderer.setStyle(this._ngEl.nativeElement, name, (/** @type {?} */ (value)));
|
5371 | }
|
5372 | else {
|
5373 | this._renderer.removeStyle(this._ngEl.nativeElement, name);
|
5374 | }
|
5375 | }
|
5376 | /**
|
5377 | * @private
|
5378 | * @param {?} changes
|
5379 | * @return {?}
|
5380 | */
|
5381 | _applyChanges(changes) {
|
5382 | changes.forEachRemovedItem((/**
|
5383 | * @param {?} record
|
5384 | * @return {?}
|
5385 | */
|
5386 | (record) => this._setStyle(record.key, null)));
|
5387 | changes.forEachAddedItem((/**
|
5388 | * @param {?} record
|
5389 | * @return {?}
|
5390 | */
|
5391 | (record) => this._setStyle(record.key, record.currentValue)));
|
5392 | changes.forEachChangedItem((/**
|
5393 | * @param {?} record
|
5394 | * @return {?}
|
5395 | */
|
5396 | (record) => this._setStyle(record.key, record.currentValue)));
|
5397 | }
|
5398 | }
|
5399 | NgStyle.decorators = [
|
5400 | { type: Directive, args: [{ selector: '[ngStyle]' },] }
|
5401 | ];
|
5402 | /** @nocollapse */
|
5403 | NgStyle.ctorParameters = () => [
|
5404 | { type: ElementRef },
|
5405 | { type: KeyValueDiffers },
|
5406 | { type: Renderer2 }
|
5407 | ];
|
5408 | NgStyle.propDecorators = {
|
5409 | ngStyle: [{ type: Input, args: ['ngStyle',] }]
|
5410 | };
|
5411 | if (false) {
|
5412 | /**
|
5413 | * @type {?}
|
5414 | * @private
|
5415 | */
|
5416 | NgStyle.prototype._ngStyle;
|
5417 | /**
|
5418 | * @type {?}
|
5419 | * @private
|
5420 | */
|
5421 | NgStyle.prototype._differ;
|
5422 | /**
|
5423 | * @type {?}
|
5424 | * @private
|
5425 | */
|
5426 | NgStyle.prototype._ngEl;
|
5427 | /**
|
5428 | * @type {?}
|
5429 | * @private
|
5430 | */
|
5431 | NgStyle.prototype._differs;
|
5432 | /**
|
5433 | * @type {?}
|
5434 | * @private
|
5435 | */
|
5436 | NgStyle.prototype._renderer;
|
5437 | }
|
5438 |
|
5439 | /**
|
5440 | * @fileoverview added by tsickle
|
5441 | * Generated from: packages/common/src/directives/ng_template_outlet.ts
|
5442 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
5443 | */
|
5444 | /**
|
5445 | * \@ngModule CommonModule
|
5446 | *
|
5447 | * \@description
|
5448 | *
|
5449 | * Inserts an embedded view from a prepared `TemplateRef`.
|
5450 | *
|
5451 | * You can attach a context object to the `EmbeddedViewRef` by setting `[ngTemplateOutletContext]`.
|
5452 | * `[ngTemplateOutletContext]` should be an object, the object's keys will be available for binding
|
5453 | * by the local template `let` declarations.
|
5454 | *
|
5455 | * \@usageNotes
|
5456 | * ```
|
5457 | * <ng-container *ngTemplateOutlet="templateRefExp; context: contextExp"></ng-container>
|
5458 | * ```
|
5459 | *
|
5460 | * Using the key `$implicit` in the context object will set its value as default.
|
5461 | *
|
5462 | * ### Example
|
5463 | *
|
5464 | * {\@example common/ngTemplateOutlet/ts/module.ts region='NgTemplateOutlet'}
|
5465 | *
|
5466 | * \@publicApi
|
5467 | */
|
5468 | class NgTemplateOutlet {
|
5469 | /**
|
5470 | * @param {?} _viewContainerRef
|
5471 | */
|
5472 | constructor(_viewContainerRef) {
|
5473 | this._viewContainerRef = _viewContainerRef;
|
5474 | this._viewRef = null;
|
5475 | /**
|
5476 | * A context object to attach to the {\@link EmbeddedViewRef}. This should be an
|
5477 | * object, the object's keys will be available for binding by the local template `let`
|
5478 | * declarations.
|
5479 | * Using the key `$implicit` in the context object will set its value as default.
|
5480 | */
|
5481 | this.ngTemplateOutletContext = null;
|
5482 | /**
|
5483 | * A string defining the template reference and optionally the context object for the template.
|
5484 | */
|
5485 | this.ngTemplateOutlet = null;
|
5486 | }
|
5487 | /**
|
5488 | * @param {?} changes
|
5489 | * @return {?}
|
5490 | */
|
5491 | ngOnChanges(changes) {
|
5492 | /** @type {?} */
|
5493 | const recreateView = this._shouldRecreateView(changes);
|
5494 | if (recreateView) {
|
5495 | /** @type {?} */
|
5496 | const viewContainerRef = this._viewContainerRef;
|
5497 | if (this._viewRef) {
|
5498 | viewContainerRef.remove(viewContainerRef.indexOf(this._viewRef));
|
5499 | }
|
5500 | this._viewRef = this.ngTemplateOutlet ?
|
5501 | viewContainerRef.createEmbeddedView(this.ngTemplateOutlet, this.ngTemplateOutletContext) :
|
5502 | null;
|
5503 | }
|
5504 | else if (this._viewRef && this.ngTemplateOutletContext) {
|
5505 | this._updateExistingContext(this.ngTemplateOutletContext);
|
5506 | }
|
5507 | }
|
5508 | /**
|
5509 | * We need to re-create existing embedded view if:
|
5510 | * - templateRef has changed
|
5511 | * - context has changes
|
5512 | *
|
5513 | * We mark context object as changed when the corresponding object
|
5514 | * shape changes (new properties are added or existing properties are removed).
|
5515 | * In other words we consider context with the same properties as "the same" even
|
5516 | * if object reference changes (see https://github.com/angular/angular/issues/13407).
|
5517 | * @private
|
5518 | * @param {?} changes
|
5519 | * @return {?}
|
5520 | */
|
5521 | _shouldRecreateView(changes) {
|
5522 | /** @type {?} */
|
5523 | const ctxChange = changes['ngTemplateOutletContext'];
|
5524 | return !!changes['ngTemplateOutlet'] || (ctxChange && this._hasContextShapeChanged(ctxChange));
|
5525 | }
|
5526 | /**
|
5527 | * @private
|
5528 | * @param {?} ctxChange
|
5529 | * @return {?}
|
5530 | */
|
5531 | _hasContextShapeChanged(ctxChange) {
|
5532 | /** @type {?} */
|
5533 | const prevCtxKeys = Object.keys(ctxChange.previousValue || {});
|
5534 | /** @type {?} */
|
5535 | const currCtxKeys = Object.keys(ctxChange.currentValue || {});
|
5536 | if (prevCtxKeys.length === currCtxKeys.length) {
|
5537 | for (let propName of currCtxKeys) {
|
5538 | if (prevCtxKeys.indexOf(propName) === -1) {
|
5539 | return true;
|
5540 | }
|
5541 | }
|
5542 | return false;
|
5543 | }
|
5544 | return true;
|
5545 | }
|
5546 | /**
|
5547 | * @private
|
5548 | * @param {?} ctx
|
5549 | * @return {?}
|
5550 | */
|
5551 | _updateExistingContext(ctx) {
|
5552 | for (let propName of Object.keys(ctx)) {
|
5553 | ((/** @type {?} */ ((/** @type {?} */ (this._viewRef)).context)))[propName] = ((/** @type {?} */ (this.ngTemplateOutletContext)))[propName];
|
5554 | }
|
5555 | }
|
5556 | }
|
5557 | NgTemplateOutlet.decorators = [
|
5558 | { type: Directive, args: [{ selector: '[ngTemplateOutlet]' },] }
|
5559 | ];
|
5560 | /** @nocollapse */
|
5561 | NgTemplateOutlet.ctorParameters = () => [
|
5562 | { type: ViewContainerRef }
|
5563 | ];
|
5564 | NgTemplateOutlet.propDecorators = {
|
5565 | ngTemplateOutletContext: [{ type: Input }],
|
5566 | ngTemplateOutlet: [{ type: Input }]
|
5567 | };
|
5568 | if (false) {
|
5569 | /**
|
5570 | * @type {?}
|
5571 | * @private
|
5572 | */
|
5573 | NgTemplateOutlet.prototype._viewRef;
|
5574 | /**
|
5575 | * A context object to attach to the {\@link EmbeddedViewRef}. This should be an
|
5576 | * object, the object's keys will be available for binding by the local template `let`
|
5577 | * declarations.
|
5578 | * Using the key `$implicit` in the context object will set its value as default.
|
5579 | * @type {?}
|
5580 | */
|
5581 | NgTemplateOutlet.prototype.ngTemplateOutletContext;
|
5582 | /**
|
5583 | * A string defining the template reference and optionally the context object for the template.
|
5584 | * @type {?}
|
5585 | */
|
5586 | NgTemplateOutlet.prototype.ngTemplateOutlet;
|
5587 | /**
|
5588 | * @type {?}
|
5589 | * @private
|
5590 | */
|
5591 | NgTemplateOutlet.prototype._viewContainerRef;
|
5592 | }
|
5593 |
|
5594 | /**
|
5595 | * @fileoverview added by tsickle
|
5596 | * Generated from: packages/common/src/directives/index.ts
|
5597 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
5598 | */
|
5599 | /**
|
5600 | * A collection of Angular directives that are likely to be used in each and every Angular
|
5601 | * application.
|
5602 | * @type {?}
|
5603 | */
|
5604 | const COMMON_DIRECTIVES = [
|
5605 | NgClass,
|
5606 | NgComponentOutlet,
|
5607 | NgForOf,
|
5608 | NgIf,
|
5609 | NgTemplateOutlet,
|
5610 | NgStyle,
|
5611 | NgSwitch,
|
5612 | NgSwitchCase,
|
5613 | NgSwitchDefault,
|
5614 | NgPlural,
|
5615 | NgPluralCase,
|
5616 | ];
|
5617 |
|
5618 | /**
|
5619 | * @fileoverview added by tsickle
|
5620 | * Generated from: packages/common/src/pipes/invalid_pipe_argument_error.ts
|
5621 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
5622 | */
|
5623 | /**
|
5624 | * @param {?} type
|
5625 | * @param {?} value
|
5626 | * @return {?}
|
5627 | */
|
5628 | function invalidPipeArgumentError(type, value) {
|
5629 | return Error(`InvalidPipeArgument: '${value}' for pipe '${ɵstringify(type)}'`);
|
5630 | }
|
5631 |
|
5632 | /**
|
5633 | * @fileoverview added by tsickle
|
5634 | * Generated from: packages/common/src/pipes/async_pipe.ts
|
5635 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
5636 | */
|
5637 | /**
|
5638 | * @record
|
5639 | */
|
5640 | function SubscriptionStrategy() { }
|
5641 | if (false) {
|
5642 | /**
|
5643 | * @param {?} async
|
5644 | * @param {?} updateLatestValue
|
5645 | * @return {?}
|
5646 | */
|
5647 | SubscriptionStrategy.prototype.createSubscription = function (async, updateLatestValue) { };
|
5648 | /**
|
5649 | * @param {?} subscription
|
5650 | * @return {?}
|
5651 | */
|
5652 | SubscriptionStrategy.prototype.dispose = function (subscription) { };
|
5653 | /**
|
5654 | * @param {?} subscription
|
5655 | * @return {?}
|
5656 | */
|
5657 | SubscriptionStrategy.prototype.onDestroy = function (subscription) { };
|
5658 | }
|
5659 | class ObservableStrategy {
|
5660 | /**
|
5661 | * @param {?} async
|
5662 | * @param {?} updateLatestValue
|
5663 | * @return {?}
|
5664 | */
|
5665 | createSubscription(async, updateLatestValue) {
|
5666 | return async.subscribe({ next: updateLatestValue, error: (/**
|
5667 | * @param {?} e
|
5668 | * @return {?}
|
5669 | */
|
5670 | (e) => { throw e; }) });
|
5671 | }
|
5672 | /**
|
5673 | * @param {?} subscription
|
5674 | * @return {?}
|
5675 | */
|
5676 | dispose(subscription) { subscription.unsubscribe(); }
|
5677 | /**
|
5678 | * @param {?} subscription
|
5679 | * @return {?}
|
5680 | */
|
5681 | onDestroy(subscription) { subscription.unsubscribe(); }
|
5682 | }
|
5683 | class PromiseStrategy {
|
5684 | /**
|
5685 | * @param {?} async
|
5686 | * @param {?} updateLatestValue
|
5687 | * @return {?}
|
5688 | */
|
5689 | createSubscription(async, updateLatestValue) {
|
5690 | return async.then(updateLatestValue, (/**
|
5691 | * @param {?} e
|
5692 | * @return {?}
|
5693 | */
|
5694 | e => { throw e; }));
|
5695 | }
|
5696 | /**
|
5697 | * @param {?} subscription
|
5698 | * @return {?}
|
5699 | */
|
5700 | dispose(subscription) { }
|
5701 | /**
|
5702 | * @param {?} subscription
|
5703 | * @return {?}
|
5704 | */
|
5705 | onDestroy(subscription) { }
|
5706 | }
|
5707 | /** @type {?} */
|
5708 | const _promiseStrategy = new PromiseStrategy();
|
5709 | /** @type {?} */
|
5710 | const _observableStrategy = new ObservableStrategy();
|
5711 | /**
|
5712 | * \@ngModule CommonModule
|
5713 | * \@description
|
5714 | *
|
5715 | * Unwraps a value from an asynchronous primitive.
|
5716 | *
|
5717 | * The `async` pipe subscribes to an `Observable` or `Promise` and returns the latest value it has
|
5718 | * emitted. When a new value is emitted, the `async` pipe marks the component to be checked for
|
5719 | * changes. When the component gets destroyed, the `async` pipe unsubscribes automatically to avoid
|
5720 | * potential memory leaks.
|
5721 | *
|
5722 | * \@usageNotes
|
5723 | *
|
5724 | * ### Examples
|
5725 | *
|
5726 | * This example binds a `Promise` to the view. Clicking the `Resolve` button resolves the
|
5727 | * promise.
|
5728 | *
|
5729 | * {\@example common/pipes/ts/async_pipe.ts region='AsyncPipePromise'}
|
5730 | *
|
5731 | * It's also possible to use `async` with Observables. The example below binds the `time` Observable
|
5732 | * to the view. The Observable continuously updates the view with the current time.
|
5733 | *
|
5734 | * {\@example common/pipes/ts/async_pipe.ts region='AsyncPipeObservable'}
|
5735 | *
|
5736 | * \@publicApi
|
5737 | */
|
5738 | class AsyncPipe {
|
5739 | /**
|
5740 | * @param {?} _ref
|
5741 | */
|
5742 | constructor(_ref) {
|
5743 | this._ref = _ref;
|
5744 | this._latestValue = null;
|
5745 | this._latestReturnedValue = null;
|
5746 | this._subscription = null;
|
5747 | this._obj = null;
|
5748 | this._strategy = (/** @type {?} */ (null));
|
5749 | }
|
5750 | /**
|
5751 | * @return {?}
|
5752 | */
|
5753 | ngOnDestroy() {
|
5754 | if (this._subscription) {
|
5755 | this._dispose();
|
5756 | }
|
5757 | }
|
5758 | /**
|
5759 | * @param {?} obj
|
5760 | * @return {?}
|
5761 | */
|
5762 | transform(obj) {
|
5763 | if (!this._obj) {
|
5764 | if (obj) {
|
5765 | this._subscribe(obj);
|
5766 | }
|
5767 | this._latestReturnedValue = this._latestValue;
|
5768 | return this._latestValue;
|
5769 | }
|
5770 | if (obj !== this._obj) {
|
5771 | this._dispose();
|
5772 | return this.transform((/** @type {?} */ (obj)));
|
5773 | }
|
5774 | if (ɵlooseIdentical(this._latestValue, this._latestReturnedValue)) {
|
5775 | return this._latestReturnedValue;
|
5776 | }
|
5777 | this._latestReturnedValue = this._latestValue;
|
5778 | return WrappedValue.wrap(this._latestValue);
|
5779 | }
|
5780 | /**
|
5781 | * @private
|
5782 | * @param {?} obj
|
5783 | * @return {?}
|
5784 | */
|
5785 | _subscribe(obj) {
|
5786 | this._obj = obj;
|
5787 | this._strategy = this._selectStrategy(obj);
|
5788 | this._subscription = this._strategy.createSubscription(obj, (/**
|
5789 | * @param {?} value
|
5790 | * @return {?}
|
5791 | */
|
5792 | (value) => this._updateLatestValue(obj, value)));
|
5793 | }
|
5794 | /**
|
5795 | * @private
|
5796 | * @param {?} obj
|
5797 | * @return {?}
|
5798 | */
|
5799 | _selectStrategy(obj) {
|
5800 | if (ɵisPromise(obj)) {
|
5801 | return _promiseStrategy;
|
5802 | }
|
5803 | if (ɵisObservable(obj)) {
|
5804 | return _observableStrategy;
|
5805 | }
|
5806 | throw invalidPipeArgumentError(AsyncPipe, obj);
|
5807 | }
|
5808 | /**
|
5809 | * @private
|
5810 | * @return {?}
|
5811 | */
|
5812 | _dispose() {
|
5813 | this._strategy.dispose((/** @type {?} */ (this._subscription)));
|
5814 | this._latestValue = null;
|
5815 | this._latestReturnedValue = null;
|
5816 | this._subscription = null;
|
5817 | this._obj = null;
|
5818 | }
|
5819 | /**
|
5820 | * @private
|
5821 | * @param {?} async
|
5822 | * @param {?} value
|
5823 | * @return {?}
|
5824 | */
|
5825 | _updateLatestValue(async, value) {
|
5826 | if (async === this._obj) {
|
5827 | this._latestValue = value;
|
5828 | this._ref.markForCheck();
|
5829 | }
|
5830 | }
|
5831 | }
|
5832 | AsyncPipe.decorators = [
|
5833 | { type: Pipe, args: [{ name: 'async', pure: false },] }
|
5834 | ];
|
5835 | /** @nocollapse */
|
5836 | AsyncPipe.ctorParameters = () => [
|
5837 | { type: ChangeDetectorRef }
|
5838 | ];
|
5839 | if (false) {
|
5840 | /**
|
5841 | * @type {?}
|
5842 | * @private
|
5843 | */
|
5844 | AsyncPipe.prototype._latestValue;
|
5845 | /**
|
5846 | * @type {?}
|
5847 | * @private
|
5848 | */
|
5849 | AsyncPipe.prototype._latestReturnedValue;
|
5850 | /**
|
5851 | * @type {?}
|
5852 | * @private
|
5853 | */
|
5854 | AsyncPipe.prototype._subscription;
|
5855 | /**
|
5856 | * @type {?}
|
5857 | * @private
|
5858 | */
|
5859 | AsyncPipe.prototype._obj;
|
5860 | /**
|
5861 | * @type {?}
|
5862 | * @private
|
5863 | */
|
5864 | AsyncPipe.prototype._strategy;
|
5865 | /**
|
5866 | * @type {?}
|
5867 | * @private
|
5868 | */
|
5869 | AsyncPipe.prototype._ref;
|
5870 | }
|
5871 |
|
5872 | /**
|
5873 | * @fileoverview added by tsickle
|
5874 | * Generated from: packages/common/src/pipes/case_conversion_pipes.ts
|
5875 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
5876 | */
|
5877 | /**
|
5878 | * Transforms text to all lower case.
|
5879 | *
|
5880 | * @see `UpperCasePipe`
|
5881 | * @see `TitleCasePipe`
|
5882 | * \@usageNotes
|
5883 | *
|
5884 | * The following example defines a view that allows the user to enter
|
5885 | * text, and then uses the pipe to convert the input text to all lower case.
|
5886 | *
|
5887 | * <code-example path="common/pipes/ts/lowerupper_pipe.ts" region='LowerUpperPipe'></code-example>
|
5888 | *
|
5889 | * \@ngModule CommonModule
|
5890 | * \@publicApi
|
5891 | */
|
5892 | class LowerCasePipe {
|
5893 | /**
|
5894 | * @param {?} value The string to transform to lower case.
|
5895 | * @return {?}
|
5896 | */
|
5897 | transform(value) {
|
5898 | if (!value)
|
5899 | return value;
|
5900 | if (typeof value !== 'string') {
|
5901 | throw invalidPipeArgumentError(LowerCasePipe, value);
|
5902 | }
|
5903 | return value.toLowerCase();
|
5904 | }
|
5905 | }
|
5906 | LowerCasePipe.decorators = [
|
5907 | { type: Pipe, args: [{ name: 'lowercase' },] }
|
5908 | ];
|
5909 | //
|
5910 | // Regex below matches any Unicode word and compatible with ES5. In ES2018 the same result
|
5911 | // can be achieved by using /\p{L}\S*/gu and also known as Unicode Property Escapes
|
5912 | // (http://2ality.com/2017/07/regexp-unicode-property-escapes.html). Since there is no
|
5913 | // transpilation of this functionality down to ES5 without external tool, the only solution is
|
5914 | // to use already transpiled form. Example can be found here -
|
5915 | // https://mothereff.in/regexpu#input=var+regex+%3D+/%5Cp%7BL%7D/u%3B&unicodePropertyEscape=1
|
5916 | //
|
5917 | /** @type {?} */
|
5918 | const unicodeWordMatch = /(?:[A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF40\uDF42-\uDF49\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE83\uDE86-\uDE89\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46]|\uD808[\uDC00-\uDF99]|\uD809[\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D])\S*/g;
|
5919 | /**
|
5920 | * Transforms text to title case.
|
5921 | * Capitalizes the first letter of each word, and transforms the
|
5922 | * rest of the word to lower case.
|
5923 | * Words are delimited by any whitespace character, such as a space, tab, or line-feed character.
|
5924 | *
|
5925 | * @see `LowerCasePipe`
|
5926 | * @see `UpperCasePipe`
|
5927 | *
|
5928 | * \@usageNotes
|
5929 | * The following example shows the result of transforming various strings into title case.
|
5930 | *
|
5931 | * <code-example path="common/pipes/ts/titlecase_pipe.ts" region='TitleCasePipe'></code-example>
|
5932 | *
|
5933 | * \@ngModule CommonModule
|
5934 | * \@publicApi
|
5935 | */
|
5936 | class TitleCasePipe {
|
5937 | /**
|
5938 | * @param {?} value The string to transform to title case.
|
5939 | * @return {?}
|
5940 | */
|
5941 | transform(value) {
|
5942 | if (!value)
|
5943 | return value;
|
5944 | if (typeof value !== 'string') {
|
5945 | throw invalidPipeArgumentError(TitleCasePipe, value);
|
5946 | }
|
5947 | return value.replace(unicodeWordMatch, ((/**
|
5948 | * @param {?} txt
|
5949 | * @return {?}
|
5950 | */
|
5951 | txt => txt[0].toUpperCase() + txt.substr(1).toLowerCase())));
|
5952 | }
|
5953 | }
|
5954 | TitleCasePipe.decorators = [
|
5955 | { type: Pipe, args: [{ name: 'titlecase' },] }
|
5956 | ];
|
5957 | /**
|
5958 | * Transforms text to all upper case.
|
5959 | * @see `LowerCasePipe`
|
5960 | * @see `TitleCasePipe`
|
5961 | *
|
5962 | * \@ngModule CommonModule
|
5963 | * \@publicApi
|
5964 | */
|
5965 | class UpperCasePipe {
|
5966 | /**
|
5967 | * @param {?} value The string to transform to upper case.
|
5968 | * @return {?}
|
5969 | */
|
5970 | transform(value) {
|
5971 | if (!value)
|
5972 | return value;
|
5973 | if (typeof value !== 'string') {
|
5974 | throw invalidPipeArgumentError(UpperCasePipe, value);
|
5975 | }
|
5976 | return value.toUpperCase();
|
5977 | }
|
5978 | }
|
5979 | UpperCasePipe.decorators = [
|
5980 | { type: Pipe, args: [{ name: 'uppercase' },] }
|
5981 | ];
|
5982 |
|
5983 | /**
|
5984 | * @fileoverview added by tsickle
|
5985 | * Generated from: packages/common/src/pipes/date_pipe.ts
|
5986 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
5987 | */
|
5988 | // clang-format off
|
5989 | /**
|
5990 | * \@ngModule CommonModule
|
5991 | * \@description
|
5992 | *
|
5993 | * Formats a date value according to locale rules.
|
5994 | *
|
5995 | * Only the `en-US` locale data comes with Angular. To localize dates
|
5996 | * in another language, you must import the corresponding locale data.
|
5997 | * See the [I18n guide](guide/i18n#i18n-pipes) for more information.
|
5998 | *
|
5999 | * @see `formatDate()`
|
6000 | *
|
6001 | *
|
6002 | * \@usageNotes
|
6003 | *
|
6004 | * The result of this pipe is not reevaluated when the input is mutated. To avoid the need to
|
6005 | * reformat the date on every change-detection cycle, treat the date as an immutable object
|
6006 | * and change the reference when the pipe needs to run again.
|
6007 | *
|
6008 | * ### Pre-defined format options
|
6009 | *
|
6010 | * Examples are given in `en-US` locale.
|
6011 | *
|
6012 | * - `'short'`: equivalent to `'M/d/yy, h:mm a'` (`6/15/15, 9:03 AM`).
|
6013 | * - `'medium'`: equivalent to `'MMM d, y, h:mm:ss a'` (`Jun 15, 2015, 9:03:01 AM`).
|
6014 | * - `'long'`: equivalent to `'MMMM d, y, h:mm:ss a z'` (`June 15, 2015 at 9:03:01 AM
|
6015 | * GMT+1`).
|
6016 | * - `'full'`: equivalent to `'EEEE, MMMM d, y, h:mm:ss a zzzz'` (`Monday, June 15, 2015 at
|
6017 | * 9:03:01 AM GMT+01:00`).
|
6018 | * - `'shortDate'`: equivalent to `'M/d/yy'` (`6/15/15`).
|
6019 | * - `'mediumDate'`: equivalent to `'MMM d, y'` (`Jun 15, 2015`).
|
6020 | * - `'longDate'`: equivalent to `'MMMM d, y'` (`June 15, 2015`).
|
6021 | * - `'fullDate'`: equivalent to `'EEEE, MMMM d, y'` (`Monday, June 15, 2015`).
|
6022 | * - `'shortTime'`: equivalent to `'h:mm a'` (`9:03 AM`).
|
6023 | * - `'mediumTime'`: equivalent to `'h:mm:ss a'` (`9:03:01 AM`).
|
6024 | * - `'longTime'`: equivalent to `'h:mm:ss a z'` (`9:03:01 AM GMT+1`).
|
6025 | * - `'fullTime'`: equivalent to `'h:mm:ss a zzzz'` (`9:03:01 AM GMT+01:00`).
|
6026 | *
|
6027 | * ### Custom format options
|
6028 | *
|
6029 | * You can construct a format string using symbols to specify the components
|
6030 | * of a date-time value, as described in the following table.
|
6031 | * Format details depend on the locale.
|
6032 | * Fields marked with (*) are only available in the extra data set for the given locale.
|
6033 | *
|
6034 | * | Field type | Format | Description | Example Value |
|
6035 | * |--------------------|-------------|---------------------------------------------------------------|------------------------------------------------------------|
|
6036 | * | Era | G, GG & GGG | Abbreviated | AD |
|
6037 | * | | GGGG | Wide | Anno Domini |
|
6038 | * | | GGGGG | Narrow | A |
|
6039 | * | Year | y | Numeric: minimum digits | 2, 20, 201, 2017, 20173 |
|
6040 | * | | yy | Numeric: 2 digits + zero padded | 02, 20, 01, 17, 73 |
|
6041 | * | | yyy | Numeric: 3 digits + zero padded | 002, 020, 201, 2017, 20173 |
|
6042 | * | | yyyy | Numeric: 4 digits or more + zero padded | 0002, 0020, 0201, 2017, 20173 |
|
6043 | * | Month | M | Numeric: 1 digit | 9, 12 |
|
6044 | * | | MM | Numeric: 2 digits + zero padded | 09, 12 |
|
6045 | * | | MMM | Abbreviated | Sep |
|
6046 | * | | MMMM | Wide | September |
|
6047 | * | | MMMMM | Narrow | S |
|
6048 | * | Month standalone | L | Numeric: 1 digit | 9, 12 |
|
6049 | * | | LL | Numeric: 2 digits + zero padded | 09, 12 |
|
6050 | * | | LLL | Abbreviated | Sep |
|
6051 | * | | LLLL | Wide | September |
|
6052 | * | | LLLLL | Narrow | S |
|
6053 | * | Week of year | w | Numeric: minimum digits | 1... 53 |
|
6054 | * | | ww | Numeric: 2 digits + zero padded | 01... 53 |
|
6055 | * | Week of month | W | Numeric: 1 digit | 1... 5 |
|
6056 | * | Day of month | d | Numeric: minimum digits | 1 |
|
6057 | * | | dd | Numeric: 2 digits + zero padded | 01 |
|
6058 | * | Week day | E, EE & EEE | Abbreviated | Tue |
|
6059 | * | | EEEE | Wide | Tuesday |
|
6060 | * | | EEEEE | Narrow | T |
|
6061 | * | | EEEEEE | Short | Tu |
|
6062 | * | Period | a, aa & aaa | Abbreviated | am/pm or AM/PM |
|
6063 | * | | aaaa | Wide (fallback to `a` when missing) | ante meridiem/post meridiem |
|
6064 | * | | aaaaa | Narrow | a/p |
|
6065 | * | Period* | B, BB & BBB | Abbreviated | mid. |
|
6066 | * | | BBBB | Wide | am, pm, midnight, noon, morning, afternoon, evening, night |
|
6067 | * | | BBBBB | Narrow | md |
|
6068 | * | Period standalone* | b, bb & bbb | Abbreviated | mid. |
|
6069 | * | | bbbb | Wide | am, pm, midnight, noon, morning, afternoon, evening, night |
|
6070 | * | | bbbbb | Narrow | md |
|
6071 | * | Hour 1-12 | h | Numeric: minimum digits | 1, 12 |
|
6072 | * | | hh | Numeric: 2 digits + zero padded | 01, 12 |
|
6073 | * | Hour 0-23 | H | Numeric: minimum digits | 0, 23 |
|
6074 | * | | HH | Numeric: 2 digits + zero padded | 00, 23 |
|
6075 | * | Minute | m | Numeric: minimum digits | 8, 59 |
|
6076 | * | | mm | Numeric: 2 digits + zero padded | 08, 59 |
|
6077 | * | Second | s | Numeric: minimum digits | 0... 59 |
|
6078 | * | | ss | Numeric: 2 digits + zero padded | 00... 59 |
|
6079 | * | Fractional seconds | S | Numeric: 1 digit | 0... 9 |
|
6080 | * | | SS | Numeric: 2 digits + zero padded | 00... 99 |
|
6081 | * | | SSS | Numeric: 3 digits + zero padded (= milliseconds) | 000... 999 |
|
6082 | * | Zone | z, zz & zzz | Short specific non location format (fallback to O) | GMT-8 |
|
6083 | * | | zzzz | Long specific non location format (fallback to OOOO) | GMT-08:00 |
|
6084 | * | | Z, ZZ & ZZZ | ISO8601 basic format | -0800 |
|
6085 | * | | ZZZZ | Long localized GMT format | GMT-8:00 |
|
6086 | * | | ZZZZZ | ISO8601 extended format + Z indicator for offset 0 (= XXXXX) | -08:00 |
|
6087 | * | | O, OO & OOO | Short localized GMT format | GMT-8 |
|
6088 | * | | OOOO | Long localized GMT format | GMT-08:00 |
|
6089 | *
|
6090 | * Note that timezone correction is not applied to an ISO string that has no time component, such as "2016-09-19"
|
6091 | *
|
6092 | * ### Format examples
|
6093 | *
|
6094 | * These examples transform a date into various formats,
|
6095 | * assuming that `dateObj` is a JavaScript `Date` object for
|
6096 | * year: 2015, month: 6, day: 15, hour: 21, minute: 43, second: 11,
|
6097 | * given in the local time for the `en-US` locale.
|
6098 | *
|
6099 | * ```
|
6100 | * {{ dateObj | date }} // output is 'Jun 15, 2015'
|
6101 | * {{ dateObj | date:'medium' }} // output is 'Jun 15, 2015, 9:43:11 PM'
|
6102 | * {{ dateObj | date:'shortTime' }} // output is '9:43 PM'
|
6103 | * {{ dateObj | date:'mm:ss' }} // output is '43:11'
|
6104 | * ```
|
6105 | *
|
6106 | * ### Usage example
|
6107 | *
|
6108 | * The following component uses a date pipe to display the current date in different formats.
|
6109 | *
|
6110 | * ```
|
6111 | * \@Component({
|
6112 | * selector: 'date-pipe',
|
6113 | * template: `<div>
|
6114 | * <p>Today is {{today | date}}</p>
|
6115 | * <p>Or if you prefer, {{today | date:'fullDate'}}</p>
|
6116 | * <p>The time is {{today | date:'h:mm a z'}}</p>
|
6117 | * </div>`
|
6118 | * })
|
6119 | * // Get the current date and time as a date-time value.
|
6120 | * export class DatePipeComponent {
|
6121 | * today: number = Date.now();
|
6122 | * }
|
6123 | * ```
|
6124 | *
|
6125 | * \@publicApi
|
6126 | */
|
6127 | // clang-format on
|
6128 | class DatePipe {
|
6129 | /**
|
6130 | * @param {?} locale
|
6131 | */
|
6132 | constructor(locale) {
|
6133 | this.locale = locale;
|
6134 | }
|
6135 | /**
|
6136 | * @param {?} value The date expression: a `Date` object, a number
|
6137 | * (milliseconds since UTC epoch), or an ISO string (https://www.w3.org/TR/NOTE-datetime).
|
6138 | * @param {?=} format The date/time components to include, using predefined options or a
|
6139 | * custom format string.
|
6140 | * @param {?=} timezone A timezone offset (such as `'+0430'`), or a standard
|
6141 | * UTC/GMT or continental US timezone abbreviation.
|
6142 | * When not supplied, uses the end-user's local system timezone.
|
6143 | * @param {?=} locale A locale code for the locale format rules to use.
|
6144 | * When not supplied, uses the value of `LOCALE_ID`, which is `en-US` by default.
|
6145 | * See [Setting your app locale](guide/i18n#setting-up-the-locale-of-your-app).
|
6146 | * @return {?} A date string in the desired format.
|
6147 | */
|
6148 | transform(value, format = 'mediumDate', timezone, locale) {
|
6149 | if (value == null || value === '' || value !== value)
|
6150 | return null;
|
6151 | try {
|
6152 | return formatDate(value, format, locale || this.locale, timezone);
|
6153 | }
|
6154 | catch (error) {
|
6155 | throw invalidPipeArgumentError(DatePipe, error.message);
|
6156 | }
|
6157 | }
|
6158 | }
|
6159 | DatePipe.decorators = [
|
6160 | { type: Pipe, args: [{ name: 'date', pure: true },] }
|
6161 | ];
|
6162 | /** @nocollapse */
|
6163 | DatePipe.ctorParameters = () => [
|
6164 | { type: String, decorators: [{ type: Inject, args: [LOCALE_ID,] }] }
|
6165 | ];
|
6166 | if (false) {
|
6167 | /**
|
6168 | * @type {?}
|
6169 | * @private
|
6170 | */
|
6171 | DatePipe.prototype.locale;
|
6172 | }
|
6173 |
|
6174 | /**
|
6175 | * @fileoverview added by tsickle
|
6176 | * Generated from: packages/common/src/pipes/i18n_plural_pipe.ts
|
6177 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
6178 | */
|
6179 | /** @type {?} */
|
6180 | const _INTERPOLATION_REGEXP = /#/g;
|
6181 | /**
|
6182 | * \@ngModule CommonModule
|
6183 | * \@description
|
6184 | *
|
6185 | * Maps a value to a string that pluralizes the value according to locale rules.
|
6186 | *
|
6187 | * \@usageNotes
|
6188 | *
|
6189 | * ### Example
|
6190 | *
|
6191 | * {\@example common/pipes/ts/i18n_pipe.ts region='I18nPluralPipeComponent'}
|
6192 | *
|
6193 | * \@publicApi
|
6194 | */
|
6195 | class I18nPluralPipe {
|
6196 | /**
|
6197 | * @param {?} _localization
|
6198 | */
|
6199 | constructor(_localization) {
|
6200 | this._localization = _localization;
|
6201 | }
|
6202 | /**
|
6203 | * @param {?} value the number to be formatted
|
6204 | * @param {?} pluralMap an object that mimics the ICU format, see
|
6205 | * http://userguide.icu-project.org/formatparse/messages.
|
6206 | * @param {?=} locale a `string` defining the locale to use (uses the current {\@link LOCALE_ID} by
|
6207 | * default).
|
6208 | * @return {?}
|
6209 | */
|
6210 | transform(value, pluralMap, locale) {
|
6211 | if (value == null)
|
6212 | return '';
|
6213 | if (typeof pluralMap !== 'object' || pluralMap === null) {
|
6214 | throw invalidPipeArgumentError(I18nPluralPipe, pluralMap);
|
6215 | }
|
6216 | /** @type {?} */
|
6217 | const key = getPluralCategory(value, Object.keys(pluralMap), this._localization, locale);
|
6218 | return pluralMap[key].replace(_INTERPOLATION_REGEXP, value.toString());
|
6219 | }
|
6220 | }
|
6221 | I18nPluralPipe.decorators = [
|
6222 | { type: Pipe, args: [{ name: 'i18nPlural', pure: true },] }
|
6223 | ];
|
6224 | /** @nocollapse */
|
6225 | I18nPluralPipe.ctorParameters = () => [
|
6226 | { type: NgLocalization }
|
6227 | ];
|
6228 | if (false) {
|
6229 | /**
|
6230 | * @type {?}
|
6231 | * @private
|
6232 | */
|
6233 | I18nPluralPipe.prototype._localization;
|
6234 | }
|
6235 |
|
6236 | /**
|
6237 | * @fileoverview added by tsickle
|
6238 | * Generated from: packages/common/src/pipes/i18n_select_pipe.ts
|
6239 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
6240 | */
|
6241 | /**
|
6242 | * \@ngModule CommonModule
|
6243 | * \@description
|
6244 | *
|
6245 | * Generic selector that displays the string that matches the current value.
|
6246 | *
|
6247 | * If none of the keys of the `mapping` match the `value`, then the content
|
6248 | * of the `other` key is returned when present, otherwise an empty string is returned.
|
6249 | *
|
6250 | * \@usageNotes
|
6251 | *
|
6252 | * ### Example
|
6253 | *
|
6254 | * {\@example common/pipes/ts/i18n_pipe.ts region='I18nSelectPipeComponent'}
|
6255 | *
|
6256 | * \@publicApi
|
6257 | */
|
6258 | class I18nSelectPipe {
|
6259 | /**
|
6260 | * @param {?} value a string to be internationalized.
|
6261 | * @param {?} mapping an object that indicates the text that should be displayed
|
6262 | * for different values of the provided `value`.
|
6263 | * @return {?}
|
6264 | */
|
6265 | transform(value, mapping) {
|
6266 | if (value == null)
|
6267 | return '';
|
6268 | if (typeof mapping !== 'object' || typeof value !== 'string') {
|
6269 | throw invalidPipeArgumentError(I18nSelectPipe, mapping);
|
6270 | }
|
6271 | if (mapping.hasOwnProperty(value)) {
|
6272 | return mapping[value];
|
6273 | }
|
6274 | if (mapping.hasOwnProperty('other')) {
|
6275 | return mapping['other'];
|
6276 | }
|
6277 | return '';
|
6278 | }
|
6279 | }
|
6280 | I18nSelectPipe.decorators = [
|
6281 | { type: Pipe, args: [{ name: 'i18nSelect', pure: true },] }
|
6282 | ];
|
6283 |
|
6284 | /**
|
6285 | * @fileoverview added by tsickle
|
6286 | * Generated from: packages/common/src/pipes/json_pipe.ts
|
6287 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
6288 | */
|
6289 | /**
|
6290 | * \@ngModule CommonModule
|
6291 | * \@description
|
6292 | *
|
6293 | * Converts a value into its JSON-format representation. Useful for debugging.
|
6294 | *
|
6295 | * \@usageNotes
|
6296 | *
|
6297 | * The following component uses a JSON pipe to convert an object
|
6298 | * to JSON format, and displays the string in both formats for comparison.
|
6299 | *
|
6300 | * {\@example common/pipes/ts/json_pipe.ts region='JsonPipe'}
|
6301 | *
|
6302 | * \@publicApi
|
6303 | */
|
6304 | class JsonPipe {
|
6305 | /**
|
6306 | * @param {?} value A value of any type to convert into a JSON-format string.
|
6307 | * @return {?}
|
6308 | */
|
6309 | transform(value) { return JSON.stringify(value, null, 2); }
|
6310 | }
|
6311 | JsonPipe.decorators = [
|
6312 | { type: Pipe, args: [{ name: 'json', pure: false },] }
|
6313 | ];
|
6314 |
|
6315 | /**
|
6316 | * @fileoverview added by tsickle
|
6317 | * Generated from: packages/common/src/pipes/keyvalue_pipe.ts
|
6318 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
6319 | */
|
6320 | /**
|
6321 | * @template K, V
|
6322 | * @param {?} key
|
6323 | * @param {?} value
|
6324 | * @return {?}
|
6325 | */
|
6326 | function makeKeyValuePair(key, value) {
|
6327 | return { key: key, value: value };
|
6328 | }
|
6329 | /**
|
6330 | * A key value pair.
|
6331 | * Usually used to represent the key value pairs from a Map or Object.
|
6332 | *
|
6333 | * \@publicApi
|
6334 | * @record
|
6335 | * @template K, V
|
6336 | */
|
6337 | function KeyValue() { }
|
6338 | if (false) {
|
6339 | /** @type {?} */
|
6340 | KeyValue.prototype.key;
|
6341 | /** @type {?} */
|
6342 | KeyValue.prototype.value;
|
6343 | }
|
6344 | /**
|
6345 | * \@ngModule CommonModule
|
6346 | * \@description
|
6347 | *
|
6348 | * Transforms Object or Map into an array of key value pairs.
|
6349 | *
|
6350 | * The output array will be ordered by keys.
|
6351 | * By default the comparator will be by Unicode point value.
|
6352 | * You can optionally pass a compareFn if your keys are complex types.
|
6353 | *
|
6354 | * \@usageNotes
|
6355 | * ### Examples
|
6356 | *
|
6357 | * This examples show how an Object or a Map can be iterated by ngFor with the use of this keyvalue
|
6358 | * pipe.
|
6359 | *
|
6360 | * {\@example common/pipes/ts/keyvalue_pipe.ts region='KeyValuePipe'}
|
6361 | *
|
6362 | * \@publicApi
|
6363 | */
|
6364 | class KeyValuePipe {
|
6365 | /**
|
6366 | * @param {?} differs
|
6367 | */
|
6368 | constructor(differs) {
|
6369 | this.differs = differs;
|
6370 | this.keyValues = [];
|
6371 | }
|
6372 | /**
|
6373 | * @template K, V
|
6374 | * @param {?} input
|
6375 | * @param {?=} compareFn
|
6376 | * @return {?}
|
6377 | */
|
6378 | transform(input, compareFn = defaultComparator) {
|
6379 | if (!input || (!(input instanceof Map) && typeof input !== 'object')) {
|
6380 | return null;
|
6381 | }
|
6382 | if (!this.differ) {
|
6383 | // make a differ for whatever type we've been passed in
|
6384 | this.differ = this.differs.find(input).create();
|
6385 | }
|
6386 | /** @type {?} */
|
6387 | const differChanges = this.differ.diff((/** @type {?} */ (input)));
|
6388 | if (differChanges) {
|
6389 | this.keyValues = [];
|
6390 | differChanges.forEachItem((/**
|
6391 | * @param {?} r
|
6392 | * @return {?}
|
6393 | */
|
6394 | (r) => {
|
6395 | this.keyValues.push(makeKeyValuePair(r.key, (/** @type {?} */ (r.currentValue))));
|
6396 | }));
|
6397 | this.keyValues.sort(compareFn);
|
6398 | }
|
6399 | return this.keyValues;
|
6400 | }
|
6401 | }
|
6402 | KeyValuePipe.decorators = [
|
6403 | { type: Pipe, args: [{ name: 'keyvalue', pure: false },] }
|
6404 | ];
|
6405 | /** @nocollapse */
|
6406 | KeyValuePipe.ctorParameters = () => [
|
6407 | { type: KeyValueDiffers }
|
6408 | ];
|
6409 | if (false) {
|
6410 | /**
|
6411 | * @type {?}
|
6412 | * @private
|
6413 | */
|
6414 | KeyValuePipe.prototype.differ;
|
6415 | /**
|
6416 | * @type {?}
|
6417 | * @private
|
6418 | */
|
6419 | KeyValuePipe.prototype.keyValues;
|
6420 | /**
|
6421 | * @type {?}
|
6422 | * @private
|
6423 | */
|
6424 | KeyValuePipe.prototype.differs;
|
6425 | }
|
6426 | /**
|
6427 | * @template K, V
|
6428 | * @param {?} keyValueA
|
6429 | * @param {?} keyValueB
|
6430 | * @return {?}
|
6431 | */
|
6432 | function defaultComparator(keyValueA, keyValueB) {
|
6433 | /** @type {?} */
|
6434 | const a = keyValueA.key;
|
6435 | /** @type {?} */
|
6436 | const b = keyValueB.key;
|
6437 | // if same exit with 0;
|
6438 | if (a === b)
|
6439 | return 0;
|
6440 | // make sure that undefined are at the end of the sort.
|
6441 | if (a === undefined)
|
6442 | return 1;
|
6443 | if (b === undefined)
|
6444 | return -1;
|
6445 | // make sure that nulls are at the end of the sort.
|
6446 | if (a === null)
|
6447 | return 1;
|
6448 | if (b === null)
|
6449 | return -1;
|
6450 | if (typeof a == 'string' && typeof b == 'string') {
|
6451 | return a < b ? -1 : 1;
|
6452 | }
|
6453 | if (typeof a == 'number' && typeof b == 'number') {
|
6454 | return a - b;
|
6455 | }
|
6456 | if (typeof a == 'boolean' && typeof b == 'boolean') {
|
6457 | return a < b ? -1 : 1;
|
6458 | }
|
6459 | // `a` and `b` are of different types. Compare their string values.
|
6460 | /** @type {?} */
|
6461 | const aString = String(a);
|
6462 | /** @type {?} */
|
6463 | const bString = String(b);
|
6464 | return aString == bString ? 0 : aString < bString ? -1 : 1;
|
6465 | }
|
6466 |
|
6467 | /**
|
6468 | * @fileoverview added by tsickle
|
6469 | * Generated from: packages/common/src/pipes/number_pipe.ts
|
6470 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
6471 | */
|
6472 | /**
|
6473 | * \@ngModule CommonModule
|
6474 | * \@description
|
6475 | *
|
6476 | * Transforms a number into a string,
|
6477 | * formatted according to locale rules that determine group sizing and
|
6478 | * separator, decimal-point character, and other locale-specific
|
6479 | * configurations.
|
6480 | *
|
6481 | * If no parameters are specified, the function rounds off to the nearest value using this
|
6482 | * [rounding method](https://en.wikibooks.org/wiki/Arithmetic/Rounding).
|
6483 | * The behavior differs from that of the JavaScript ```Math.round()``` function.
|
6484 | * In the following case for example, the pipe rounds down where
|
6485 | * ```Math.round()``` rounds up:
|
6486 | *
|
6487 | * ```html
|
6488 | * -2.5 | number:'1.0-0'
|
6489 | * > -3
|
6490 | * Math.round(-2.5)
|
6491 | * > -2
|
6492 | * ```
|
6493 | *
|
6494 | * @see `formatNumber()`
|
6495 | *
|
6496 | * \@usageNotes
|
6497 | * The following code shows how the pipe transforms numbers
|
6498 | * into text strings, according to various format specifications,
|
6499 | * where the caller's default locale is `en-US`.
|
6500 | *
|
6501 | * ### Example
|
6502 | *
|
6503 | * <code-example path="common/pipes/ts/number_pipe.ts" region='NumberPipe'></code-example>
|
6504 | *
|
6505 | * \@publicApi
|
6506 | */
|
6507 | class DecimalPipe {
|
6508 | /**
|
6509 | * @param {?} _locale
|
6510 | */
|
6511 | constructor(_locale) {
|
6512 | this._locale = _locale;
|
6513 | }
|
6514 | /**
|
6515 | * @param {?} value The number to be formatted.
|
6516 | * @param {?=} digitsInfo Decimal representation options, specified by a string
|
6517 | * in the following format:<br>
|
6518 | * <code>{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}</code>.
|
6519 | * - `minIntegerDigits`: The minimum number of integer digits before the decimal point.
|
6520 | * Default is `1`.
|
6521 | * - `minFractionDigits`: The minimum number of digits after the decimal point.
|
6522 | * Default is `0`.
|
6523 | * - `maxFractionDigits`: The maximum number of digits after the decimal point.
|
6524 | * Default is `3`.
|
6525 | * @param {?=} locale A locale code for the locale format rules to use.
|
6526 | * When not supplied, uses the value of `LOCALE_ID`, which is `en-US` by default.
|
6527 | * See [Setting your app locale](guide/i18n#setting-up-the-locale-of-your-app).
|
6528 | * @return {?}
|
6529 | */
|
6530 | transform(value, digitsInfo, locale) {
|
6531 | if (isEmpty(value))
|
6532 | return null;
|
6533 | locale = locale || this._locale;
|
6534 | try {
|
6535 | /** @type {?} */
|
6536 | const num = strToNumber(value);
|
6537 | return formatNumber(num, locale, digitsInfo);
|
6538 | }
|
6539 | catch (error) {
|
6540 | throw invalidPipeArgumentError(DecimalPipe, error.message);
|
6541 | }
|
6542 | }
|
6543 | }
|
6544 | DecimalPipe.decorators = [
|
6545 | { type: Pipe, args: [{ name: 'number' },] }
|
6546 | ];
|
6547 | /** @nocollapse */
|
6548 | DecimalPipe.ctorParameters = () => [
|
6549 | { type: String, decorators: [{ type: Inject, args: [LOCALE_ID,] }] }
|
6550 | ];
|
6551 | if (false) {
|
6552 | /**
|
6553 | * @type {?}
|
6554 | * @private
|
6555 | */
|
6556 | DecimalPipe.prototype._locale;
|
6557 | }
|
6558 | /**
|
6559 | * \@ngModule CommonModule
|
6560 | * \@description
|
6561 | *
|
6562 | * Transforms a number to a percentage
|
6563 | * string, formatted according to locale rules that determine group sizing and
|
6564 | * separator, decimal-point character, and other locale-specific
|
6565 | * configurations.
|
6566 | *
|
6567 | * @see `formatPercent()`
|
6568 | *
|
6569 | * \@usageNotes
|
6570 | * The following code shows how the pipe transforms numbers
|
6571 | * into text strings, according to various format specifications,
|
6572 | * where the caller's default locale is `en-US`.
|
6573 | *
|
6574 | * <code-example path="common/pipes/ts/percent_pipe.ts" region='PercentPipe'></code-example>
|
6575 | *
|
6576 | * \@publicApi
|
6577 | */
|
6578 | class PercentPipe {
|
6579 | /**
|
6580 | * @param {?} _locale
|
6581 | */
|
6582 | constructor(_locale) {
|
6583 | this._locale = _locale;
|
6584 | }
|
6585 | /**
|
6586 | *
|
6587 | * @param {?} value The number to be formatted as a percentage.
|
6588 | * @param {?=} digitsInfo Decimal representation options, specified by a string
|
6589 | * in the following format:<br>
|
6590 | * <code>{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}</code>.
|
6591 | * - `minIntegerDigits`: The minimum number of integer digits before the decimal point.
|
6592 | * Default is `1`.
|
6593 | * - `minFractionDigits`: The minimum number of digits after the decimal point.
|
6594 | * Default is `0`.
|
6595 | * - `maxFractionDigits`: The maximum number of digits after the decimal point.
|
6596 | * Default is `0`.
|
6597 | * @param {?=} locale A locale code for the locale format rules to use.
|
6598 | * When not supplied, uses the value of `LOCALE_ID`, which is `en-US` by default.
|
6599 | * See [Setting your app locale](guide/i18n#setting-up-the-locale-of-your-app).
|
6600 | * @return {?}
|
6601 | */
|
6602 | transform(value, digitsInfo, locale) {
|
6603 | if (isEmpty(value))
|
6604 | return null;
|
6605 | locale = locale || this._locale;
|
6606 | try {
|
6607 | /** @type {?} */
|
6608 | const num = strToNumber(value);
|
6609 | return formatPercent(num, locale, digitsInfo);
|
6610 | }
|
6611 | catch (error) {
|
6612 | throw invalidPipeArgumentError(PercentPipe, error.message);
|
6613 | }
|
6614 | }
|
6615 | }
|
6616 | PercentPipe.decorators = [
|
6617 | { type: Pipe, args: [{ name: 'percent' },] }
|
6618 | ];
|
6619 | /** @nocollapse */
|
6620 | PercentPipe.ctorParameters = () => [
|
6621 | { type: String, decorators: [{ type: Inject, args: [LOCALE_ID,] }] }
|
6622 | ];
|
6623 | if (false) {
|
6624 | /**
|
6625 | * @type {?}
|
6626 | * @private
|
6627 | */
|
6628 | PercentPipe.prototype._locale;
|
6629 | }
|
6630 | /**
|
6631 | * \@ngModule CommonModule
|
6632 | * \@description
|
6633 | *
|
6634 | * Transforms a number to a currency string, formatted according to locale rules
|
6635 | * that determine group sizing and separator, decimal-point character,
|
6636 | * and other locale-specific configurations.
|
6637 | *
|
6638 | * {\@a currency-code-deprecation}
|
6639 | * <div class="alert is-helpful">
|
6640 | *
|
6641 | * **Deprecation notice:**
|
6642 | *
|
6643 | * The default currency code is currently always `USD` but this is deprecated from v9.
|
6644 | *
|
6645 | * **In v11 the default currency code will be taken from the current locale identified by
|
6646 | * the `LOCAL_ID` token. See the [i18n guide](guide/i18n#setting-up-the-locale-of-your-app) for
|
6647 | * more information.**
|
6648 | *
|
6649 | * If you need the previous behavior then set it by creating a `DEFAULT_CURRENCY_CODE` provider in
|
6650 | * your application `NgModule`:
|
6651 | *
|
6652 | * ```ts
|
6653 | * {provide: DEFAULT_CURRENCY_CODE, useValue: 'USD'}
|
6654 | * ```
|
6655 | *
|
6656 | * </div>
|
6657 | *
|
6658 | * @see `getCurrencySymbol()`
|
6659 | * @see `formatCurrency()`
|
6660 | *
|
6661 | * \@usageNotes
|
6662 | * The following code shows how the pipe transforms numbers
|
6663 | * into text strings, according to various format specifications,
|
6664 | * where the caller's default locale is `en-US`.
|
6665 | *
|
6666 | * <code-example path="common/pipes/ts/currency_pipe.ts" region='CurrencyPipe'></code-example>
|
6667 | *
|
6668 | * \@publicApi
|
6669 | */
|
6670 | class CurrencyPipe {
|
6671 | /**
|
6672 | * @param {?} _locale
|
6673 | * @param {?=} _defaultCurrencyCode
|
6674 | */
|
6675 | constructor(_locale, _defaultCurrencyCode = 'USD') {
|
6676 | this._locale = _locale;
|
6677 | this._defaultCurrencyCode = _defaultCurrencyCode;
|
6678 | }
|
6679 | /**
|
6680 | *
|
6681 | * @param {?} value The number to be formatted as currency.
|
6682 | * @param {?=} currencyCode The [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code,
|
6683 | * such as `USD` for the US dollar and `EUR` for the euro. The default currency code can be
|
6684 | * configured using the `DEFAULT_CURRENCY_CODE` injection token.
|
6685 | * @param {?=} display The format for the currency indicator. One of the following:
|
6686 | * - `code`: Show the code (such as `USD`).
|
6687 | * - `symbol`(default): Show the symbol (such as `$`).
|
6688 | * - `symbol-narrow`: Use the narrow symbol for locales that have two symbols for their
|
6689 | * currency.
|
6690 | * For example, the Canadian dollar CAD has the symbol `CA$` and the symbol-narrow `$`. If the
|
6691 | * locale has no narrow symbol, uses the standard symbol for the locale.
|
6692 | * - String: Use the given string value instead of a code or a symbol.
|
6693 | * For example, an empty string will suppress the currency & symbol.
|
6694 | * - Boolean (marked deprecated in v5): `true` for symbol and false for `code`.
|
6695 | *
|
6696 | * @param {?=} digitsInfo Decimal representation options, specified by a string
|
6697 | * in the following format:<br>
|
6698 | * <code>{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}</code>.
|
6699 | * - `minIntegerDigits`: The minimum number of integer digits before the decimal point.
|
6700 | * Default is `1`.
|
6701 | * - `minFractionDigits`: The minimum number of digits after the decimal point.
|
6702 | * Default is `2`.
|
6703 | * - `maxFractionDigits`: The maximum number of digits after the decimal point.
|
6704 | * Default is `2`.
|
6705 | * If not provided, the number will be formatted with the proper amount of digits,
|
6706 | * depending on what the [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) specifies.
|
6707 | * For example, the Canadian dollar has 2 digits, whereas the Chilean peso has none.
|
6708 | * @param {?=} locale A locale code for the locale format rules to use.
|
6709 | * When not supplied, uses the value of `LOCALE_ID`, which is `en-US` by default.
|
6710 | * See [Setting your app locale](guide/i18n#setting-up-the-locale-of-your-app).
|
6711 | * @return {?}
|
6712 | */
|
6713 | transform(value, currencyCode, display = 'symbol', digitsInfo, locale) {
|
6714 | if (isEmpty(value))
|
6715 | return null;
|
6716 | locale = locale || this._locale;
|
6717 | if (typeof display === 'boolean') {
|
6718 | if ((/** @type {?} */ (console)) && (/** @type {?} */ (console.warn))) {
|
6719 | console.warn(`Warning: the currency pipe has been changed in Angular v5. The symbolDisplay option (third parameter) is now a string instead of a boolean. The accepted values are "code", "symbol" or "symbol-narrow".`);
|
6720 | }
|
6721 | display = display ? 'symbol' : 'code';
|
6722 | }
|
6723 | /** @type {?} */
|
6724 | let currency = currencyCode || this._defaultCurrencyCode;
|
6725 | if (display !== 'code') {
|
6726 | if (display === 'symbol' || display === 'symbol-narrow') {
|
6727 | currency = getCurrencySymbol(currency, display === 'symbol' ? 'wide' : 'narrow', locale);
|
6728 | }
|
6729 | else {
|
6730 | currency = display;
|
6731 | }
|
6732 | }
|
6733 | try {
|
6734 | /** @type {?} */
|
6735 | const num = strToNumber(value);
|
6736 | return formatCurrency(num, locale, currency, currencyCode, digitsInfo);
|
6737 | }
|
6738 | catch (error) {
|
6739 | throw invalidPipeArgumentError(CurrencyPipe, error.message);
|
6740 | }
|
6741 | }
|
6742 | }
|
6743 | CurrencyPipe.decorators = [
|
6744 | { type: Pipe, args: [{ name: 'currency' },] }
|
6745 | ];
|
6746 | /** @nocollapse */
|
6747 | CurrencyPipe.ctorParameters = () => [
|
6748 | { type: String, decorators: [{ type: Inject, args: [LOCALE_ID,] }] },
|
6749 | { type: String, decorators: [{ type: Inject, args: [DEFAULT_CURRENCY_CODE,] }] }
|
6750 | ];
|
6751 | if (false) {
|
6752 | /**
|
6753 | * @type {?}
|
6754 | * @private
|
6755 | */
|
6756 | CurrencyPipe.prototype._locale;
|
6757 | /**
|
6758 | * @type {?}
|
6759 | * @private
|
6760 | */
|
6761 | CurrencyPipe.prototype._defaultCurrencyCode;
|
6762 | }
|
6763 | /**
|
6764 | * @param {?} value
|
6765 | * @return {?}
|
6766 | */
|
6767 | function isEmpty(value) {
|
6768 | return value == null || value === '' || value !== value;
|
6769 | }
|
6770 | /**
|
6771 | * Transforms a string into a number (if needed).
|
6772 | * @param {?} value
|
6773 | * @return {?}
|
6774 | */
|
6775 | function strToNumber(value) {
|
6776 | // Convert strings to numbers
|
6777 | if (typeof value === 'string' && !isNaN(Number(value) - parseFloat(value))) {
|
6778 | return Number(value);
|
6779 | }
|
6780 | if (typeof value !== 'number') {
|
6781 | throw new Error(`${value} is not a number`);
|
6782 | }
|
6783 | return value;
|
6784 | }
|
6785 |
|
6786 | /**
|
6787 | * @fileoverview added by tsickle
|
6788 | * Generated from: packages/common/src/pipes/slice_pipe.ts
|
6789 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
6790 | */
|
6791 | /**
|
6792 | * \@ngModule CommonModule
|
6793 | * \@description
|
6794 | *
|
6795 | * Creates a new `Array` or `String` containing a subset (slice) of the elements.
|
6796 | *
|
6797 | * \@usageNotes
|
6798 | *
|
6799 | * All behavior is based on the expected behavior of the JavaScript API `Array.prototype.slice()`
|
6800 | * and `String.prototype.slice()`.
|
6801 | *
|
6802 | * When operating on an `Array`, the returned `Array` is always a copy even when all
|
6803 | * the elements are being returned.
|
6804 | *
|
6805 | * When operating on a blank value, the pipe returns the blank value.
|
6806 | *
|
6807 | * ### List Example
|
6808 | *
|
6809 | * This `ngFor` example:
|
6810 | *
|
6811 | * {\@example common/pipes/ts/slice_pipe.ts region='SlicePipe_list'}
|
6812 | *
|
6813 | * produces the following:
|
6814 | *
|
6815 | * ```html
|
6816 | * <li>b</li>
|
6817 | * <li>c</li>
|
6818 | * ```
|
6819 | *
|
6820 | * ### String Examples
|
6821 | *
|
6822 | * {\@example common/pipes/ts/slice_pipe.ts region='SlicePipe_string'}
|
6823 | *
|
6824 | * \@publicApi
|
6825 | */
|
6826 | class SlicePipe {
|
6827 | /**
|
6828 | * @param {?} value
|
6829 | * @param {?} start
|
6830 | * @param {?=} end
|
6831 | * @return {?}
|
6832 | */
|
6833 | transform(value, start, end) {
|
6834 | if (value == null)
|
6835 | return value;
|
6836 | if (!this.supports(value)) {
|
6837 | throw invalidPipeArgumentError(SlicePipe, value);
|
6838 | }
|
6839 | return value.slice(start, end);
|
6840 | }
|
6841 | /**
|
6842 | * @private
|
6843 | * @param {?} obj
|
6844 | * @return {?}
|
6845 | */
|
6846 | supports(obj) { return typeof obj === 'string' || Array.isArray(obj); }
|
6847 | }
|
6848 | SlicePipe.decorators = [
|
6849 | { type: Pipe, args: [{ name: 'slice', pure: false },] }
|
6850 | ];
|
6851 |
|
6852 | /**
|
6853 | * @fileoverview added by tsickle
|
6854 | * Generated from: packages/common/src/pipes/index.ts
|
6855 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
6856 | */
|
6857 | /**
|
6858 | * A collection of Angular pipes that are likely to be used in each and every application.
|
6859 | * @type {?}
|
6860 | */
|
6861 | const COMMON_PIPES = [
|
6862 | AsyncPipe,
|
6863 | UpperCasePipe,
|
6864 | LowerCasePipe,
|
6865 | JsonPipe,
|
6866 | SlicePipe,
|
6867 | DecimalPipe,
|
6868 | PercentPipe,
|
6869 | TitleCasePipe,
|
6870 | CurrencyPipe,
|
6871 | DatePipe,
|
6872 | I18nPluralPipe,
|
6873 | I18nSelectPipe,
|
6874 | KeyValuePipe,
|
6875 | ];
|
6876 |
|
6877 | /**
|
6878 | * @fileoverview added by tsickle
|
6879 | * Generated from: packages/common/src/common_module.ts
|
6880 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
6881 | */
|
6882 | // Note: This does not contain the location providers,
|
6883 | // as they need some platform specific implementations to work.
|
6884 | /**
|
6885 | * Exports all the basic Angular directives and pipes,
|
6886 | * such as `NgIf`, `NgForOf`, `DecimalPipe`, and so on.
|
6887 | * Re-exported by `BrowserModule`, which is included automatically in the root
|
6888 | * `AppModule` when you create a new app with the CLI `new` command.
|
6889 | *
|
6890 | * * The `providers` options configure the NgModule's injector to provide
|
6891 | * localization dependencies to members.
|
6892 | * * The `exports` options make the declared directives and pipes available for import
|
6893 | * by other NgModules.
|
6894 | *
|
6895 | * \@publicApi
|
6896 | */
|
6897 | class CommonModule {
|
6898 | }
|
6899 | CommonModule.decorators = [
|
6900 | { type: NgModule, args: [{
|
6901 | declarations: [COMMON_DIRECTIVES, COMMON_PIPES],
|
6902 | exports: [COMMON_DIRECTIVES, COMMON_PIPES],
|
6903 | providers: [
|
6904 | { provide: NgLocalization, useClass: NgLocaleLocalization },
|
6905 | ],
|
6906 | },] }
|
6907 | ];
|
6908 |
|
6909 | /**
|
6910 | * @fileoverview added by tsickle
|
6911 | * Generated from: packages/common/src/platform_id.ts
|
6912 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
6913 | */
|
6914 | /**
|
6915 | * @license
|
6916 | * Copyright Google Inc. All Rights Reserved.
|
6917 | *
|
6918 | * Use of this source code is governed by an MIT-style license that can be
|
6919 | * found in the LICENSE file at https://angular.io/license
|
6920 | */
|
6921 | /** @type {?} */
|
6922 | const PLATFORM_BROWSER_ID = 'browser';
|
6923 | /** @type {?} */
|
6924 | const PLATFORM_SERVER_ID = 'server';
|
6925 | /** @type {?} */
|
6926 | const PLATFORM_WORKER_APP_ID = 'browserWorkerApp';
|
6927 | /** @type {?} */
|
6928 | const PLATFORM_WORKER_UI_ID = 'browserWorkerUi';
|
6929 | /**
|
6930 | * Returns whether a platform id represents a browser platform.
|
6931 | * \@publicApi
|
6932 | * @param {?} platformId
|
6933 | * @return {?}
|
6934 | */
|
6935 | function isPlatformBrowser(platformId) {
|
6936 | return platformId === PLATFORM_BROWSER_ID;
|
6937 | }
|
6938 | /**
|
6939 | * Returns whether a platform id represents a server platform.
|
6940 | * \@publicApi
|
6941 | * @param {?} platformId
|
6942 | * @return {?}
|
6943 | */
|
6944 | function isPlatformServer(platformId) {
|
6945 | return platformId === PLATFORM_SERVER_ID;
|
6946 | }
|
6947 | /**
|
6948 | * Returns whether a platform id represents a web worker app platform.
|
6949 | * \@publicApi
|
6950 | * @param {?} platformId
|
6951 | * @return {?}
|
6952 | */
|
6953 | function isPlatformWorkerApp(platformId) {
|
6954 | return platformId === PLATFORM_WORKER_APP_ID;
|
6955 | }
|
6956 | /**
|
6957 | * Returns whether a platform id represents a web worker UI platform.
|
6958 | * \@publicApi
|
6959 | * @param {?} platformId
|
6960 | * @return {?}
|
6961 | */
|
6962 | function isPlatformWorkerUi(platformId) {
|
6963 | return platformId === PLATFORM_WORKER_UI_ID;
|
6964 | }
|
6965 |
|
6966 | /**
|
6967 | * @fileoverview added by tsickle
|
6968 | * Generated from: packages/common/src/version.ts
|
6969 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
6970 | */
|
6971 | /**
|
6972 | * \@publicApi
|
6973 | * @type {?}
|
6974 | */
|
6975 | const VERSION = new Version('9.0.4');
|
6976 |
|
6977 | /**
|
6978 | * @fileoverview added by tsickle
|
6979 | * Generated from: packages/common/src/viewport_scroller.ts
|
6980 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
6981 | */
|
6982 | /**
|
6983 | * Defines a scroll position manager. Implemented by `BrowserViewportScroller`.
|
6984 | *
|
6985 | * \@publicApi
|
6986 | * @abstract
|
6987 | */
|
6988 | class ViewportScroller {
|
6989 | }
|
6990 | // De-sugared tree-shakable injection
|
6991 | // See #23917
|
6992 | /** @nocollapse */
|
6993 | /** @nocollapse */ ViewportScroller.ɵprov = ɵɵdefineInjectable({
|
6994 | token: ViewportScroller,
|
6995 | providedIn: 'root',
|
6996 | factory: (/**
|
6997 | * @nocollapse @return {?}
|
6998 | */
|
6999 | () => new BrowserViewportScroller(ɵɵinject(DOCUMENT), window, ɵɵinject(ErrorHandler)))
|
7000 | });
|
7001 | if (false) {
|
7002 | /**
|
7003 | * @nocollapse
|
7004 | * @type {?}
|
7005 | */
|
7006 | ViewportScroller.ɵprov;
|
7007 | /**
|
7008 | * Configures the top offset used when scrolling to an anchor.
|
7009 | * @abstract
|
7010 | * @param {?} offset A position in screen coordinates (a tuple with x and y values)
|
7011 | * or a function that returns the top offset position.
|
7012 | *
|
7013 | * @return {?}
|
7014 | */
|
7015 | ViewportScroller.prototype.setOffset = function (offset) { };
|
7016 | /**
|
7017 | * Retrieves the current scroll position.
|
7018 | * @abstract
|
7019 | * @return {?} A position in screen coordinates (a tuple with x and y values).
|
7020 | */
|
7021 | ViewportScroller.prototype.getScrollPosition = function () { };
|
7022 | /**
|
7023 | * Scrolls to a specified position.
|
7024 | * @abstract
|
7025 | * @param {?} position A position in screen coordinates (a tuple with x and y values).
|
7026 | * @return {?}
|
7027 | */
|
7028 | ViewportScroller.prototype.scrollToPosition = function (position) { };
|
7029 | /**
|
7030 | * Scrolls to an anchor element.
|
7031 | * @abstract
|
7032 | * @param {?} anchor The ID of the anchor element.
|
7033 | * @return {?}
|
7034 | */
|
7035 | ViewportScroller.prototype.scrollToAnchor = function (anchor) { };
|
7036 | /**
|
7037 | * Disables automatic scroll restoration provided by the browser.
|
7038 | * See also [window.history.scrollRestoration
|
7039 | * info](https://developers.google.com/web/updates/2015/09/history-api-scroll-restoration).
|
7040 | * @abstract
|
7041 | * @param {?} scrollRestoration
|
7042 | * @return {?}
|
7043 | */
|
7044 | ViewportScroller.prototype.setHistoryScrollRestoration = function (scrollRestoration) { };
|
7045 | }
|
7046 | /**
|
7047 | * Manages the scroll position for a browser window.
|
7048 | */
|
7049 | class BrowserViewportScroller {
|
7050 | /**
|
7051 | * @param {?} document
|
7052 | * @param {?} window
|
7053 | * @param {?} errorHandler
|
7054 | */
|
7055 | constructor(document, window, errorHandler) {
|
7056 | this.document = document;
|
7057 | this.window = window;
|
7058 | this.errorHandler = errorHandler;
|
7059 | this.offset = (/**
|
7060 | * @return {?}
|
7061 | */
|
7062 | () => [0, 0]);
|
7063 | }
|
7064 | /**
|
7065 | * Configures the top offset used when scrolling to an anchor.
|
7066 | * @param {?} offset A position in screen coordinates (a tuple with x and y values)
|
7067 | * or a function that returns the top offset position.
|
7068 | *
|
7069 | * @return {?}
|
7070 | */
|
7071 | setOffset(offset) {
|
7072 | if (Array.isArray(offset)) {
|
7073 | this.offset = (/**
|
7074 | * @return {?}
|
7075 | */
|
7076 | () => offset);
|
7077 | }
|
7078 | else {
|
7079 | this.offset = offset;
|
7080 | }
|
7081 | }
|
7082 | /**
|
7083 | * Retrieves the current scroll position.
|
7084 | * @return {?} The position in screen coordinates.
|
7085 | */
|
7086 | getScrollPosition() {
|
7087 | if (this.supportScrollRestoration()) {
|
7088 | return [this.window.scrollX, this.window.scrollY];
|
7089 | }
|
7090 | else {
|
7091 | return [0, 0];
|
7092 | }
|
7093 | }
|
7094 | /**
|
7095 | * Sets the scroll position.
|
7096 | * @param {?} position The new position in screen coordinates.
|
7097 | * @return {?}
|
7098 | */
|
7099 | scrollToPosition(position) {
|
7100 | if (this.supportScrollRestoration()) {
|
7101 | this.window.scrollTo(position[0], position[1]);
|
7102 | }
|
7103 | }
|
7104 | /**
|
7105 | * Scrolls to an anchor element.
|
7106 | * @param {?} anchor The ID of the anchor element.
|
7107 | * @return {?}
|
7108 | */
|
7109 | scrollToAnchor(anchor) {
|
7110 | if (this.supportScrollRestoration()) {
|
7111 | // Escape anything passed to `querySelector` as it can throw errors and stop the application
|
7112 | // from working if invalid values are passed.
|
7113 | if (this.window.CSS && this.window.CSS.escape) {
|
7114 | anchor = this.window.CSS.escape(anchor);
|
7115 | }
|
7116 | else {
|
7117 | anchor = anchor.replace(/(\"|\'\ |:|\.|\[|\]|,|=)/g, '\\$1');
|
7118 | }
|
7119 | try {
|
7120 | /** @type {?} */
|
7121 | const elSelectedById = this.document.querySelector(`#${anchor}`);
|
7122 | if (elSelectedById) {
|
7123 | this.scrollToElement(elSelectedById);
|
7124 | return;
|
7125 | }
|
7126 | /** @type {?} */
|
7127 | const elSelectedByName = this.document.querySelector(`[name='${anchor}']`);
|
7128 | if (elSelectedByName) {
|
7129 | this.scrollToElement(elSelectedByName);
|
7130 | return;
|
7131 | }
|
7132 | }
|
7133 | catch (e) {
|
7134 | this.errorHandler.handleError(e);
|
7135 | }
|
7136 | }
|
7137 | }
|
7138 | /**
|
7139 | * Disables automatic scroll restoration provided by the browser.
|
7140 | * @param {?} scrollRestoration
|
7141 | * @return {?}
|
7142 | */
|
7143 | setHistoryScrollRestoration(scrollRestoration) {
|
7144 | if (this.supportScrollRestoration()) {
|
7145 | /** @type {?} */
|
7146 | const history = this.window.history;
|
7147 | if (history && history.scrollRestoration) {
|
7148 | history.scrollRestoration = scrollRestoration;
|
7149 | }
|
7150 | }
|
7151 | }
|
7152 | /**
|
7153 | * @private
|
7154 | * @param {?} el
|
7155 | * @return {?}
|
7156 | */
|
7157 | scrollToElement(el) {
|
7158 | /** @type {?} */
|
7159 | const rect = el.getBoundingClientRect();
|
7160 | /** @type {?} */
|
7161 | const left = rect.left + this.window.pageXOffset;
|
7162 | /** @type {?} */
|
7163 | const top = rect.top + this.window.pageYOffset;
|
7164 | /** @type {?} */
|
7165 | const offset = this.offset();
|
7166 | this.window.scrollTo(left - offset[0], top - offset[1]);
|
7167 | }
|
7168 | /**
|
7169 | * We only support scroll restoration when we can get a hold of window.
|
7170 | * This means that we do not support this behavior when running in a web worker.
|
7171 | *
|
7172 | * Lifting this restriction right now would require more changes in the dom adapter.
|
7173 | * Since webworkers aren't widely used, we will lift it once RouterScroller is
|
7174 | * battle-tested.
|
7175 | * @private
|
7176 | * @return {?}
|
7177 | */
|
7178 | supportScrollRestoration() {
|
7179 | try {
|
7180 | return !!this.window && !!this.window.scrollTo;
|
7181 | }
|
7182 | catch (_a) {
|
7183 | return false;
|
7184 | }
|
7185 | }
|
7186 | }
|
7187 | if (false) {
|
7188 | /**
|
7189 | * @type {?}
|
7190 | * @private
|
7191 | */
|
7192 | BrowserViewportScroller.prototype.offset;
|
7193 | /**
|
7194 | * @type {?}
|
7195 | * @private
|
7196 | */
|
7197 | BrowserViewportScroller.prototype.document;
|
7198 | /**
|
7199 | * @type {?}
|
7200 | * @private
|
7201 | */
|
7202 | BrowserViewportScroller.prototype.window;
|
7203 | /**
|
7204 | * @type {?}
|
7205 | * @private
|
7206 | */
|
7207 | BrowserViewportScroller.prototype.errorHandler;
|
7208 | }
|
7209 | /**
|
7210 | * Provides an empty implementation of the viewport scroller. This will
|
7211 | * live in \@angular/common as it will be used by both platform-server and platform-webworker.
|
7212 | */
|
7213 | class NullViewportScroller {
|
7214 | /**
|
7215 | * Empty implementation
|
7216 | * @param {?} offset
|
7217 | * @return {?}
|
7218 | */
|
7219 | setOffset(offset) { }
|
7220 | /**
|
7221 | * Empty implementation
|
7222 | * @return {?}
|
7223 | */
|
7224 | getScrollPosition() { return [0, 0]; }
|
7225 | /**
|
7226 | * Empty implementation
|
7227 | * @param {?} position
|
7228 | * @return {?}
|
7229 | */
|
7230 | scrollToPosition(position) { }
|
7231 | /**
|
7232 | * Empty implementation
|
7233 | * @param {?} anchor
|
7234 | * @return {?}
|
7235 | */
|
7236 | scrollToAnchor(anchor) { }
|
7237 | /**
|
7238 | * Empty implementation
|
7239 | * @param {?} scrollRestoration
|
7240 | * @return {?}
|
7241 | */
|
7242 | setHistoryScrollRestoration(scrollRestoration) { }
|
7243 | }
|
7244 |
|
7245 | /**
|
7246 | * @fileoverview added by tsickle
|
7247 | * Generated from: packages/common/src/common.ts
|
7248 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
7249 | */
|
7250 |
|
7251 | /**
|
7252 | * @fileoverview added by tsickle
|
7253 | * Generated from: packages/common/public_api.ts
|
7254 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
7255 | */
|
7256 |
|
7257 | /**
|
7258 | * @fileoverview added by tsickle
|
7259 | * Generated from: packages/common/index.ts
|
7260 | * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
7261 | */
|
7262 |
|
7263 | /**
|
7264 | * Generated bundle index. Do not edit.
|
7265 | */
|
7266 |
|
7267 | export { APP_BASE_HREF, AsyncPipe, CommonModule, CurrencyPipe, DOCUMENT, DatePipe, DecimalPipe, FormStyle, FormatWidth, HashLocationStrategy, I18nPluralPipe, I18nSelectPipe, JsonPipe, KeyValuePipe, LOCATION_INITIALIZED, Location, LocationStrategy, LowerCasePipe, NgClass, NgComponentOutlet, NgForOf, NgForOfContext, NgIf, NgIfContext, NgLocaleLocalization, NgLocalization, NgPlural, NgPluralCase, NgStyle, NgSwitch, NgSwitchCase, NgSwitchDefault, NgTemplateOutlet, NumberFormatStyle, NumberSymbol, PathLocationStrategy, PercentPipe, PlatformLocation, Plural, SlicePipe, TitleCasePipe, TranslationWidth, UpperCasePipe, VERSION, ViewportScroller, WeekDay, formatCurrency, formatDate, formatNumber, formatPercent, getCurrencySymbol, getLocaleCurrencyCode, getLocaleCurrencyName, getLocaleCurrencySymbol, getLocaleDateFormat, getLocaleDateTimeFormat, getLocaleDayNames, getLocaleDayPeriods, getLocaleEraNames, getLocaleExtraDayPeriodRules, getLocaleExtraDayPeriods, getLocaleFirstDayOfWeek, getLocaleId, getLocaleMonthNames, getLocaleNumberFormat, getLocaleNumberSymbol, getLocalePluralCase, getLocaleTimeFormat, getLocaleWeekEndRange, getNumberOfCurrencyDigits, isPlatformBrowser, isPlatformServer, isPlatformWorkerApp, isPlatformWorkerUi, registerLocaleData, BrowserPlatformLocation as ɵBrowserPlatformLocation, DomAdapter as ɵDomAdapter, NullViewportScroller as ɵNullViewportScroller, PLATFORM_BROWSER_ID as ɵPLATFORM_BROWSER_ID, PLATFORM_SERVER_ID as ɵPLATFORM_SERVER_ID, PLATFORM_WORKER_APP_ID as ɵPLATFORM_WORKER_APP_ID, PLATFORM_WORKER_UI_ID as ɵPLATFORM_WORKER_UI_ID, useBrowserPlatformLocation as ɵangular_packages_common_common_a, createBrowserPlatformLocation as ɵangular_packages_common_common_b, createLocation as ɵangular_packages_common_common_c, provideLocationStrategy as ɵangular_packages_common_common_d, COMMON_DIRECTIVES as ɵangular_packages_common_common_e, COMMON_PIPES as ɵangular_packages_common_common_f, getDOM as ɵgetDOM, parseCookieValue as ɵparseCookieValue, setRootDomAdapter as ɵsetRootDomAdapter };
|
7268 | //# sourceMappingURL=common.js.map
|