1 | /**
|
---|
2 | * @license Angular v12.2.9
|
---|
3 | * (c) 2010-2021 Google LLC. https://angular.io/
|
---|
4 | * License: MIT
|
---|
5 | */
|
---|
6 |
|
---|
7 | import { ɵDomAdapter, ɵsetRootDomAdapter, ɵparseCookieValue, ɵgetDOM, DOCUMENT, ɵPLATFORM_BROWSER_ID, XhrFactory, CommonModule } from '@angular/common';
|
---|
8 | export { ɵgetDOM } from '@angular/common';
|
---|
9 | import { InjectionToken, ApplicationInitStatus, APP_INITIALIZER, Injector, setTestabilityGetter, ɵglobal, Injectable, ApplicationRef, NgZone, ɵgetDebugNodeR2, NgProbeToken, Optional, Inject, ViewEncapsulation, APP_ID, RendererStyleFlags2, ɵConsole, NgModule, ɵɵdefineInjectable, ɵɵinject, forwardRef, SecurityContext, ɵallowSanitizationBypassAndThrow, ɵunwrapSafeValue, ɵgetSanitizationBypassType, ɵ_sanitizeUrl, ɵ_sanitizeHtml, ɵbypassSanitizationTrustHtml, ɵbypassSanitizationTrustStyle, ɵbypassSanitizationTrustScript, ɵbypassSanitizationTrustUrl, ɵbypassSanitizationTrustResourceUrl, INJECTOR, ErrorHandler, ɵsetDocument, PLATFORM_ID, PLATFORM_INITIALIZER, Sanitizer, createPlatformFactory, platformCore, ɵINJECTOR_SCOPE, RendererFactory2, Testability, ApplicationModule, SkipSelf, Version } from '@angular/core';
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * @license
|
---|
13 | * Copyright Google LLC All Rights Reserved.
|
---|
14 | *
|
---|
15 | * Use of this source code is governed by an MIT-style license that can be
|
---|
16 | * found in the LICENSE file at https://angular.io/license
|
---|
17 | */
|
---|
18 | /**
|
---|
19 | * Provides DOM operations in any browser environment.
|
---|
20 | *
|
---|
21 | * @security Tread carefully! Interacting with the DOM directly is dangerous and
|
---|
22 | * can introduce XSS risks.
|
---|
23 | */
|
---|
24 | class GenericBrowserDomAdapter extends ɵDomAdapter {
|
---|
25 | constructor() {
|
---|
26 | super(...arguments);
|
---|
27 | this.supportsDOMEvents = true;
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * @license
|
---|
33 | * Copyright Google LLC All Rights Reserved.
|
---|
34 | *
|
---|
35 | * Use of this source code is governed by an MIT-style license that can be
|
---|
36 | * found in the LICENSE file at https://angular.io/license
|
---|
37 | */
|
---|
38 | /**
|
---|
39 | * A `DomAdapter` powered by full browser DOM APIs.
|
---|
40 | *
|
---|
41 | * @security Tread carefully! Interacting with the DOM directly is dangerous and
|
---|
42 | * can introduce XSS risks.
|
---|
43 | */
|
---|
44 | /* tslint:disable:requireParameterType no-console */
|
---|
45 | class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
---|
46 | static makeCurrent() {
|
---|
47 | ɵsetRootDomAdapter(new BrowserDomAdapter());
|
---|
48 | }
|
---|
49 | onAndCancel(el, evt, listener) {
|
---|
50 | el.addEventListener(evt, listener, false);
|
---|
51 | // Needed to follow Dart's subscription semantic, until fix of
|
---|
52 | // https://code.google.com/p/dart/issues/detail?id=17406
|
---|
53 | return () => {
|
---|
54 | el.removeEventListener(evt, listener, false);
|
---|
55 | };
|
---|
56 | }
|
---|
57 | dispatchEvent(el, evt) {
|
---|
58 | el.dispatchEvent(evt);
|
---|
59 | }
|
---|
60 | remove(node) {
|
---|
61 | if (node.parentNode) {
|
---|
62 | node.parentNode.removeChild(node);
|
---|
63 | }
|
---|
64 | }
|
---|
65 | createElement(tagName, doc) {
|
---|
66 | doc = doc || this.getDefaultDocument();
|
---|
67 | return doc.createElement(tagName);
|
---|
68 | }
|
---|
69 | createHtmlDocument() {
|
---|
70 | return document.implementation.createHTMLDocument('fakeTitle');
|
---|
71 | }
|
---|
72 | getDefaultDocument() {
|
---|
73 | return document;
|
---|
74 | }
|
---|
75 | isElementNode(node) {
|
---|
76 | return node.nodeType === Node.ELEMENT_NODE;
|
---|
77 | }
|
---|
78 | isShadowRoot(node) {
|
---|
79 | return node instanceof DocumentFragment;
|
---|
80 | }
|
---|
81 | /** @deprecated No longer being used in Ivy code. To be removed in version 14. */
|
---|
82 | getGlobalEventTarget(doc, target) {
|
---|
83 | if (target === 'window') {
|
---|
84 | return window;
|
---|
85 | }
|
---|
86 | if (target === 'document') {
|
---|
87 | return doc;
|
---|
88 | }
|
---|
89 | if (target === 'body') {
|
---|
90 | return doc.body;
|
---|
91 | }
|
---|
92 | return null;
|
---|
93 | }
|
---|
94 | getBaseHref(doc) {
|
---|
95 | const href = getBaseElementHref();
|
---|
96 | return href == null ? null : relativePath(href);
|
---|
97 | }
|
---|
98 | resetBaseElement() {
|
---|
99 | baseElement = null;
|
---|
100 | }
|
---|
101 | getUserAgent() {
|
---|
102 | return window.navigator.userAgent;
|
---|
103 | }
|
---|
104 | getCookie(name) {
|
---|
105 | return ɵparseCookieValue(document.cookie, name);
|
---|
106 | }
|
---|
107 | }
|
---|
108 | let baseElement = null;
|
---|
109 | function getBaseElementHref() {
|
---|
110 | baseElement = baseElement || document.querySelector('base');
|
---|
111 | return baseElement ? baseElement.getAttribute('href') : null;
|
---|
112 | }
|
---|
113 | // based on urlUtils.js in AngularJS 1
|
---|
114 | let urlParsingNode;
|
---|
115 | function relativePath(url) {
|
---|
116 | urlParsingNode = urlParsingNode || document.createElement('a');
|
---|
117 | urlParsingNode.setAttribute('href', url);
|
---|
118 | const pathName = urlParsingNode.pathname;
|
---|
119 | return pathName.charAt(0) === '/' ? pathName : `/${pathName}`;
|
---|
120 | }
|
---|
121 |
|
---|
122 | /**
|
---|
123 | * @license
|
---|
124 | * Copyright Google LLC All Rights Reserved.
|
---|
125 | *
|
---|
126 | * Use of this source code is governed by an MIT-style license that can be
|
---|
127 | * found in the LICENSE file at https://angular.io/license
|
---|
128 | */
|
---|
129 | /**
|
---|
130 | * An id that identifies a particular application being bootstrapped, that should
|
---|
131 | * match across the client/server boundary.
|
---|
132 | */
|
---|
133 | const TRANSITION_ID = new InjectionToken('TRANSITION_ID');
|
---|
134 | function appInitializerFactory(transitionId, document, injector) {
|
---|
135 | return () => {
|
---|
136 | // Wait for all application initializers to be completed before removing the styles set by
|
---|
137 | // the server.
|
---|
138 | injector.get(ApplicationInitStatus).donePromise.then(() => {
|
---|
139 | const dom = ɵgetDOM();
|
---|
140 | const styles = document.querySelectorAll(`style[ng-transition="${transitionId}"]`);
|
---|
141 | for (let i = 0; i < styles.length; i++) {
|
---|
142 | dom.remove(styles[i]);
|
---|
143 | }
|
---|
144 | });
|
---|
145 | };
|
---|
146 | }
|
---|
147 | const SERVER_TRANSITION_PROVIDERS = [
|
---|
148 | {
|
---|
149 | provide: APP_INITIALIZER,
|
---|
150 | useFactory: appInitializerFactory,
|
---|
151 | deps: [TRANSITION_ID, DOCUMENT, Injector],
|
---|
152 | multi: true
|
---|
153 | },
|
---|
154 | ];
|
---|
155 |
|
---|
156 | /**
|
---|
157 | * @license
|
---|
158 | * Copyright Google LLC All Rights Reserved.
|
---|
159 | *
|
---|
160 | * Use of this source code is governed by an MIT-style license that can be
|
---|
161 | * found in the LICENSE file at https://angular.io/license
|
---|
162 | */
|
---|
163 | class BrowserGetTestability {
|
---|
164 | static init() {
|
---|
165 | setTestabilityGetter(new BrowserGetTestability());
|
---|
166 | }
|
---|
167 | addToWindow(registry) {
|
---|
168 | ɵglobal['getAngularTestability'] = (elem, findInAncestors = true) => {
|
---|
169 | const testability = registry.findTestabilityInTree(elem, findInAncestors);
|
---|
170 | if (testability == null) {
|
---|
171 | throw new Error('Could not find testability for element.');
|
---|
172 | }
|
---|
173 | return testability;
|
---|
174 | };
|
---|
175 | ɵglobal['getAllAngularTestabilities'] = () => registry.getAllTestabilities();
|
---|
176 | ɵglobal['getAllAngularRootElements'] = () => registry.getAllRootElements();
|
---|
177 | const whenAllStable = (callback /** TODO #9100 */) => {
|
---|
178 | const testabilities = ɵglobal['getAllAngularTestabilities']();
|
---|
179 | let count = testabilities.length;
|
---|
180 | let didWork = false;
|
---|
181 | const decrement = function (didWork_ /** TODO #9100 */) {
|
---|
182 | didWork = didWork || didWork_;
|
---|
183 | count--;
|
---|
184 | if (count == 0) {
|
---|
185 | callback(didWork);
|
---|
186 | }
|
---|
187 | };
|
---|
188 | testabilities.forEach(function (testability /** TODO #9100 */) {
|
---|
189 | testability.whenStable(decrement);
|
---|
190 | });
|
---|
191 | };
|
---|
192 | if (!ɵglobal['frameworkStabilizers']) {
|
---|
193 | ɵglobal['frameworkStabilizers'] = [];
|
---|
194 | }
|
---|
195 | ɵglobal['frameworkStabilizers'].push(whenAllStable);
|
---|
196 | }
|
---|
197 | findTestabilityInTree(registry, elem, findInAncestors) {
|
---|
198 | if (elem == null) {
|
---|
199 | return null;
|
---|
200 | }
|
---|
201 | const t = registry.getTestability(elem);
|
---|
202 | if (t != null) {
|
---|
203 | return t;
|
---|
204 | }
|
---|
205 | else if (!findInAncestors) {
|
---|
206 | return null;
|
---|
207 | }
|
---|
208 | if (ɵgetDOM().isShadowRoot(elem)) {
|
---|
209 | return this.findTestabilityInTree(registry, elem.host, true);
|
---|
210 | }
|
---|
211 | return this.findTestabilityInTree(registry, elem.parentElement, true);
|
---|
212 | }
|
---|
213 | }
|
---|
214 |
|
---|
215 | /**
|
---|
216 | * @license
|
---|
217 | * Copyright Google LLC All Rights Reserved.
|
---|
218 | *
|
---|
219 | * Use of this source code is governed by an MIT-style license that can be
|
---|
220 | * found in the LICENSE file at https://angular.io/license
|
---|
221 | */
|
---|
222 | /**
|
---|
223 | * A factory for `HttpXhrBackend` that uses the `XMLHttpRequest` browser API.
|
---|
224 | */
|
---|
225 | class BrowserXhr {
|
---|
226 | build() {
|
---|
227 | return new XMLHttpRequest();
|
---|
228 | }
|
---|
229 | }
|
---|
230 | BrowserXhr.decorators = [
|
---|
231 | { type: Injectable }
|
---|
232 | ];
|
---|
233 |
|
---|
234 | /**
|
---|
235 | * @license
|
---|
236 | * Copyright Google LLC All Rights Reserved.
|
---|
237 | *
|
---|
238 | * Use of this source code is governed by an MIT-style license that can be
|
---|
239 | * found in the LICENSE file at https://angular.io/license
|
---|
240 | */
|
---|
241 | const CAMEL_CASE_REGEXP = /([A-Z])/g;
|
---|
242 | const DASH_CASE_REGEXP = /-([a-z])/g;
|
---|
243 | function camelCaseToDashCase(input) {
|
---|
244 | return input.replace(CAMEL_CASE_REGEXP, (...m) => '-' + m[1].toLowerCase());
|
---|
245 | }
|
---|
246 | function dashCaseToCamelCase(input) {
|
---|
247 | return input.replace(DASH_CASE_REGEXP, (...m) => m[1].toUpperCase());
|
---|
248 | }
|
---|
249 | /**
|
---|
250 | * Exports the value under a given `name` in the global property `ng`. For example `ng.probe` if
|
---|
251 | * `name` is `'probe'`.
|
---|
252 | * @param name Name under which it will be exported. Keep in mind this will be a property of the
|
---|
253 | * global `ng` object.
|
---|
254 | * @param value The value to export.
|
---|
255 | */
|
---|
256 | function exportNgVar(name, value) {
|
---|
257 | if (typeof COMPILED === 'undefined' || !COMPILED) {
|
---|
258 | // Note: we can't export `ng` when using closure enhanced optimization as:
|
---|
259 | // - closure declares globals itself for minified names, which sometimes clobber our `ng` global
|
---|
260 | // - we can't declare a closure extern as the namespace `ng` is already used within Google
|
---|
261 | // for typings for angularJS (via `goog.provide('ng....')`).
|
---|
262 | const ng = ɵglobal['ng'] = ɵglobal['ng'] || {};
|
---|
263 | ng[name] = value;
|
---|
264 | }
|
---|
265 | }
|
---|
266 |
|
---|
267 | /**
|
---|
268 | * @license
|
---|
269 | * Copyright Google LLC All Rights Reserved.
|
---|
270 | *
|
---|
271 | * Use of this source code is governed by an MIT-style license that can be
|
---|
272 | * found in the LICENSE file at https://angular.io/license
|
---|
273 | */
|
---|
274 | const ɵ0 = () => ({
|
---|
275 | 'ApplicationRef': ApplicationRef,
|
---|
276 | 'NgZone': NgZone,
|
---|
277 | });
|
---|
278 | const CORE_TOKENS = (ɵ0)();
|
---|
279 | const INSPECT_GLOBAL_NAME = 'probe';
|
---|
280 | const CORE_TOKENS_GLOBAL_NAME = 'coreTokens';
|
---|
281 | /**
|
---|
282 | * Returns a {@link DebugElement} for the given native DOM element, or
|
---|
283 | * null if the given native element does not have an Angular view associated
|
---|
284 | * with it.
|
---|
285 | */
|
---|
286 | function inspectNativeElementR2(element) {
|
---|
287 | return ɵgetDebugNodeR2(element);
|
---|
288 | }
|
---|
289 | function _createNgProbeR2(coreTokens) {
|
---|
290 | exportNgVar(INSPECT_GLOBAL_NAME, inspectNativeElementR2);
|
---|
291 | exportNgVar(CORE_TOKENS_GLOBAL_NAME, Object.assign(Object.assign({}, CORE_TOKENS), _ngProbeTokensToMap(coreTokens || [])));
|
---|
292 | return () => inspectNativeElementR2;
|
---|
293 | }
|
---|
294 | function _ngProbeTokensToMap(tokens) {
|
---|
295 | return tokens.reduce((prev, t) => (prev[t.name] = t.token, prev), {});
|
---|
296 | }
|
---|
297 | /**
|
---|
298 | * In Ivy, we don't support NgProbe because we have our own set of testing utilities
|
---|
299 | * with more robust functionality.
|
---|
300 | *
|
---|
301 | * We shouldn't bring in NgProbe because it prevents DebugNode and friends from
|
---|
302 | * tree-shaking properly.
|
---|
303 | */
|
---|
304 | const ELEMENT_PROBE_PROVIDERS__POST_R3__ = [];
|
---|
305 | /**
|
---|
306 | * Providers which support debugging Angular applications (e.g. via `ng.probe`).
|
---|
307 | */
|
---|
308 | const ELEMENT_PROBE_PROVIDERS__PRE_R3__ = [
|
---|
309 | {
|
---|
310 | provide: APP_INITIALIZER,
|
---|
311 | useFactory: _createNgProbeR2,
|
---|
312 | deps: [
|
---|
313 | [NgProbeToken, new Optional()],
|
---|
314 | ],
|
---|
315 | multi: true,
|
---|
316 | },
|
---|
317 | ];
|
---|
318 | const ELEMENT_PROBE_PROVIDERS = ELEMENT_PROBE_PROVIDERS__PRE_R3__;
|
---|
319 |
|
---|
320 | /**
|
---|
321 | * @license
|
---|
322 | * Copyright Google LLC All Rights Reserved.
|
---|
323 | *
|
---|
324 | * Use of this source code is governed by an MIT-style license that can be
|
---|
325 | * found in the LICENSE file at https://angular.io/license
|
---|
326 | */
|
---|
327 | /**
|
---|
328 | * The injection token for the event-manager plug-in service.
|
---|
329 | *
|
---|
330 | * @publicApi
|
---|
331 | */
|
---|
332 | const EVENT_MANAGER_PLUGINS = new InjectionToken('EventManagerPlugins');
|
---|
333 | /**
|
---|
334 | * An injectable service that provides event management for Angular
|
---|
335 | * through a browser plug-in.
|
---|
336 | *
|
---|
337 | * @publicApi
|
---|
338 | */
|
---|
339 | class EventManager {
|
---|
340 | /**
|
---|
341 | * Initializes an instance of the event-manager service.
|
---|
342 | */
|
---|
343 | constructor(plugins, _zone) {
|
---|
344 | this._zone = _zone;
|
---|
345 | this._eventNameToPlugin = new Map();
|
---|
346 | plugins.forEach(p => p.manager = this);
|
---|
347 | this._plugins = plugins.slice().reverse();
|
---|
348 | }
|
---|
349 | /**
|
---|
350 | * Registers a handler for a specific element and event.
|
---|
351 | *
|
---|
352 | * @param element The HTML element to receive event notifications.
|
---|
353 | * @param eventName The name of the event to listen for.
|
---|
354 | * @param handler A function to call when the notification occurs. Receives the
|
---|
355 | * event object as an argument.
|
---|
356 | * @returns A callback function that can be used to remove the handler.
|
---|
357 | */
|
---|
358 | addEventListener(element, eventName, handler) {
|
---|
359 | const plugin = this._findPluginFor(eventName);
|
---|
360 | return plugin.addEventListener(element, eventName, handler);
|
---|
361 | }
|
---|
362 | /**
|
---|
363 | * Registers a global handler for an event in a target view.
|
---|
364 | *
|
---|
365 | * @param target A target for global event notifications. One of "window", "document", or "body".
|
---|
366 | * @param eventName The name of the event to listen for.
|
---|
367 | * @param handler A function to call when the notification occurs. Receives the
|
---|
368 | * event object as an argument.
|
---|
369 | * @returns A callback function that can be used to remove the handler.
|
---|
370 | * @deprecated No longer being used in Ivy code. To be removed in version 14.
|
---|
371 | */
|
---|
372 | addGlobalEventListener(target, eventName, handler) {
|
---|
373 | const plugin = this._findPluginFor(eventName);
|
---|
374 | return plugin.addGlobalEventListener(target, eventName, handler);
|
---|
375 | }
|
---|
376 | /**
|
---|
377 | * Retrieves the compilation zone in which event listeners are registered.
|
---|
378 | */
|
---|
379 | getZone() {
|
---|
380 | return this._zone;
|
---|
381 | }
|
---|
382 | /** @internal */
|
---|
383 | _findPluginFor(eventName) {
|
---|
384 | const plugin = this._eventNameToPlugin.get(eventName);
|
---|
385 | if (plugin) {
|
---|
386 | return plugin;
|
---|
387 | }
|
---|
388 | const plugins = this._plugins;
|
---|
389 | for (let i = 0; i < plugins.length; i++) {
|
---|
390 | const plugin = plugins[i];
|
---|
391 | if (plugin.supports(eventName)) {
|
---|
392 | this._eventNameToPlugin.set(eventName, plugin);
|
---|
393 | return plugin;
|
---|
394 | }
|
---|
395 | }
|
---|
396 | throw new Error(`No event manager plugin found for event ${eventName}`);
|
---|
397 | }
|
---|
398 | }
|
---|
399 | EventManager.decorators = [
|
---|
400 | { type: Injectable }
|
---|
401 | ];
|
---|
402 | EventManager.ctorParameters = () => [
|
---|
403 | { type: Array, decorators: [{ type: Inject, args: [EVENT_MANAGER_PLUGINS,] }] },
|
---|
404 | { type: NgZone }
|
---|
405 | ];
|
---|
406 | class EventManagerPlugin {
|
---|
407 | constructor(_doc) {
|
---|
408 | this._doc = _doc;
|
---|
409 | }
|
---|
410 | addGlobalEventListener(element, eventName, handler) {
|
---|
411 | const target = ɵgetDOM().getGlobalEventTarget(this._doc, element);
|
---|
412 | if (!target) {
|
---|
413 | throw new Error(`Unsupported event target ${target} for event ${eventName}`);
|
---|
414 | }
|
---|
415 | return this.addEventListener(target, eventName, handler);
|
---|
416 | }
|
---|
417 | }
|
---|
418 |
|
---|
419 | /**
|
---|
420 | * @license
|
---|
421 | * Copyright Google LLC All Rights Reserved.
|
---|
422 | *
|
---|
423 | * Use of this source code is governed by an MIT-style license that can be
|
---|
424 | * found in the LICENSE file at https://angular.io/license
|
---|
425 | */
|
---|
426 | class SharedStylesHost {
|
---|
427 | constructor() {
|
---|
428 | /** @internal */
|
---|
429 | this._stylesSet = new Set();
|
---|
430 | }
|
---|
431 | addStyles(styles) {
|
---|
432 | const additions = new Set();
|
---|
433 | styles.forEach(style => {
|
---|
434 | if (!this._stylesSet.has(style)) {
|
---|
435 | this._stylesSet.add(style);
|
---|
436 | additions.add(style);
|
---|
437 | }
|
---|
438 | });
|
---|
439 | this.onStylesAdded(additions);
|
---|
440 | }
|
---|
441 | onStylesAdded(additions) { }
|
---|
442 | getAllStyles() {
|
---|
443 | return Array.from(this._stylesSet);
|
---|
444 | }
|
---|
445 | }
|
---|
446 | SharedStylesHost.decorators = [
|
---|
447 | { type: Injectable }
|
---|
448 | ];
|
---|
449 | class DomSharedStylesHost extends SharedStylesHost {
|
---|
450 | constructor(_doc) {
|
---|
451 | super();
|
---|
452 | this._doc = _doc;
|
---|
453 | // Maps all registered host nodes to a list of style nodes that have been added to the host node.
|
---|
454 | this._hostNodes = new Map();
|
---|
455 | this._hostNodes.set(_doc.head, []);
|
---|
456 | }
|
---|
457 | _addStylesToHost(styles, host, styleNodes) {
|
---|
458 | styles.forEach((style) => {
|
---|
459 | const styleEl = this._doc.createElement('style');
|
---|
460 | styleEl.textContent = style;
|
---|
461 | styleNodes.push(host.appendChild(styleEl));
|
---|
462 | });
|
---|
463 | }
|
---|
464 | addHost(hostNode) {
|
---|
465 | const styleNodes = [];
|
---|
466 | this._addStylesToHost(this._stylesSet, hostNode, styleNodes);
|
---|
467 | this._hostNodes.set(hostNode, styleNodes);
|
---|
468 | }
|
---|
469 | removeHost(hostNode) {
|
---|
470 | const styleNodes = this._hostNodes.get(hostNode);
|
---|
471 | if (styleNodes) {
|
---|
472 | styleNodes.forEach(removeStyle);
|
---|
473 | }
|
---|
474 | this._hostNodes.delete(hostNode);
|
---|
475 | }
|
---|
476 | onStylesAdded(additions) {
|
---|
477 | this._hostNodes.forEach((styleNodes, hostNode) => {
|
---|
478 | this._addStylesToHost(additions, hostNode, styleNodes);
|
---|
479 | });
|
---|
480 | }
|
---|
481 | ngOnDestroy() {
|
---|
482 | this._hostNodes.forEach(styleNodes => styleNodes.forEach(removeStyle));
|
---|
483 | }
|
---|
484 | }
|
---|
485 | DomSharedStylesHost.decorators = [
|
---|
486 | { type: Injectable }
|
---|
487 | ];
|
---|
488 | DomSharedStylesHost.ctorParameters = () => [
|
---|
489 | { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] }
|
---|
490 | ];
|
---|
491 | function removeStyle(styleNode) {
|
---|
492 | ɵgetDOM().remove(styleNode);
|
---|
493 | }
|
---|
494 |
|
---|
495 | /**
|
---|
496 | * @license
|
---|
497 | * Copyright Google LLC All Rights Reserved.
|
---|
498 | *
|
---|
499 | * Use of this source code is governed by an MIT-style license that can be
|
---|
500 | * found in the LICENSE file at https://angular.io/license
|
---|
501 | */
|
---|
502 | const NAMESPACE_URIS = {
|
---|
503 | 'svg': 'http://www.w3.org/2000/svg',
|
---|
504 | 'xhtml': 'http://www.w3.org/1999/xhtml',
|
---|
505 | 'xlink': 'http://www.w3.org/1999/xlink',
|
---|
506 | 'xml': 'http://www.w3.org/XML/1998/namespace',
|
---|
507 | 'xmlns': 'http://www.w3.org/2000/xmlns/',
|
---|
508 | };
|
---|
509 | const COMPONENT_REGEX = /%COMP%/g;
|
---|
510 | const NG_DEV_MODE = typeof ngDevMode === 'undefined' || !!ngDevMode;
|
---|
511 | const COMPONENT_VARIABLE = '%COMP%';
|
---|
512 | const HOST_ATTR = `_nghost-${COMPONENT_VARIABLE}`;
|
---|
513 | const CONTENT_ATTR = `_ngcontent-${COMPONENT_VARIABLE}`;
|
---|
514 | function shimContentAttribute(componentShortId) {
|
---|
515 | return CONTENT_ATTR.replace(COMPONENT_REGEX, componentShortId);
|
---|
516 | }
|
---|
517 | function shimHostAttribute(componentShortId) {
|
---|
518 | return HOST_ATTR.replace(COMPONENT_REGEX, componentShortId);
|
---|
519 | }
|
---|
520 | function flattenStyles(compId, styles, target) {
|
---|
521 | for (let i = 0; i < styles.length; i++) {
|
---|
522 | let style = styles[i];
|
---|
523 | if (Array.isArray(style)) {
|
---|
524 | flattenStyles(compId, style, target);
|
---|
525 | }
|
---|
526 | else {
|
---|
527 | style = style.replace(COMPONENT_REGEX, compId);
|
---|
528 | target.push(style);
|
---|
529 | }
|
---|
530 | }
|
---|
531 | return target;
|
---|
532 | }
|
---|
533 | function decoratePreventDefault(eventHandler) {
|
---|
534 | // `DebugNode.triggerEventHandler` needs to know if the listener was created with
|
---|
535 | // decoratePreventDefault or is a listener added outside the Angular context so it can handle the
|
---|
536 | // two differently. In the first case, the special '__ngUnwrap__' token is passed to the unwrap
|
---|
537 | // the listener (see below).
|
---|
538 | return (event) => {
|
---|
539 | // Ivy uses '__ngUnwrap__' as a special token that allows us to unwrap the function
|
---|
540 | // so that it can be invoked programmatically by `DebugNode.triggerEventHandler`. The debug_node
|
---|
541 | // can inspect the listener toString contents for the existence of this special token. Because
|
---|
542 | // the token is a string literal, it is ensured to not be modified by compiled code.
|
---|
543 | if (event === '__ngUnwrap__') {
|
---|
544 | return eventHandler;
|
---|
545 | }
|
---|
546 | const allowDefaultBehavior = eventHandler(event);
|
---|
547 | if (allowDefaultBehavior === false) {
|
---|
548 | // TODO(tbosch): move preventDefault into event plugins...
|
---|
549 | event.preventDefault();
|
---|
550 | event.returnValue = false;
|
---|
551 | }
|
---|
552 | return undefined;
|
---|
553 | };
|
---|
554 | }
|
---|
555 | let hasLoggedNativeEncapsulationWarning = false;
|
---|
556 | class DomRendererFactory2 {
|
---|
557 | constructor(eventManager, sharedStylesHost, appId) {
|
---|
558 | this.eventManager = eventManager;
|
---|
559 | this.sharedStylesHost = sharedStylesHost;
|
---|
560 | this.appId = appId;
|
---|
561 | this.rendererByCompId = new Map();
|
---|
562 | this.defaultRenderer = new DefaultDomRenderer2(eventManager);
|
---|
563 | }
|
---|
564 | createRenderer(element, type) {
|
---|
565 | if (!element || !type) {
|
---|
566 | return this.defaultRenderer;
|
---|
567 | }
|
---|
568 | switch (type.encapsulation) {
|
---|
569 | case ViewEncapsulation.Emulated: {
|
---|
570 | let renderer = this.rendererByCompId.get(type.id);
|
---|
571 | if (!renderer) {
|
---|
572 | renderer = new EmulatedEncapsulationDomRenderer2(this.eventManager, this.sharedStylesHost, type, this.appId);
|
---|
573 | this.rendererByCompId.set(type.id, renderer);
|
---|
574 | }
|
---|
575 | renderer.applyToHost(element);
|
---|
576 | return renderer;
|
---|
577 | }
|
---|
578 | // @ts-ignore TODO: Remove as part of FW-2290. TS complains about us dealing with an enum
|
---|
579 | // value that is not known (but previously was the value for ViewEncapsulation.Native)
|
---|
580 | case 1:
|
---|
581 | case ViewEncapsulation.ShadowDom:
|
---|
582 | // TODO(FW-2290): remove the `case 1:` fallback logic and the warning in v12.
|
---|
583 | if ((typeof ngDevMode === 'undefined' || ngDevMode) &&
|
---|
584 | // @ts-ignore TODO: Remove as part of FW-2290. TS complains about us dealing with an
|
---|
585 | // enum value that is not known (but previously was the value for
|
---|
586 | // ViewEncapsulation.Native)
|
---|
587 | !hasLoggedNativeEncapsulationWarning && type.encapsulation === 1) {
|
---|
588 | hasLoggedNativeEncapsulationWarning = true;
|
---|
589 | console.warn('ViewEncapsulation.Native is no longer supported. Falling back to ViewEncapsulation.ShadowDom. The fallback will be removed in v12.');
|
---|
590 | }
|
---|
591 | return new ShadowDomRenderer(this.eventManager, this.sharedStylesHost, element, type);
|
---|
592 | default: {
|
---|
593 | if (!this.rendererByCompId.has(type.id)) {
|
---|
594 | const styles = flattenStyles(type.id, type.styles, []);
|
---|
595 | this.sharedStylesHost.addStyles(styles);
|
---|
596 | this.rendererByCompId.set(type.id, this.defaultRenderer);
|
---|
597 | }
|
---|
598 | return this.defaultRenderer;
|
---|
599 | }
|
---|
600 | }
|
---|
601 | }
|
---|
602 | begin() { }
|
---|
603 | end() { }
|
---|
604 | }
|
---|
605 | DomRendererFactory2.decorators = [
|
---|
606 | { type: Injectable }
|
---|
607 | ];
|
---|
608 | DomRendererFactory2.ctorParameters = () => [
|
---|
609 | { type: EventManager },
|
---|
610 | { type: DomSharedStylesHost },
|
---|
611 | { type: String, decorators: [{ type: Inject, args: [APP_ID,] }] }
|
---|
612 | ];
|
---|
613 | class DefaultDomRenderer2 {
|
---|
614 | constructor(eventManager) {
|
---|
615 | this.eventManager = eventManager;
|
---|
616 | this.data = Object.create(null);
|
---|
617 | }
|
---|
618 | destroy() { }
|
---|
619 | createElement(name, namespace) {
|
---|
620 | if (namespace) {
|
---|
621 | // In cases where Ivy (not ViewEngine) is giving us the actual namespace, the look up by key
|
---|
622 | // will result in undefined, so we just return the namespace here.
|
---|
623 | return document.createElementNS(NAMESPACE_URIS[namespace] || namespace, name);
|
---|
624 | }
|
---|
625 | return document.createElement(name);
|
---|
626 | }
|
---|
627 | createComment(value) {
|
---|
628 | return document.createComment(value);
|
---|
629 | }
|
---|
630 | createText(value) {
|
---|
631 | return document.createTextNode(value);
|
---|
632 | }
|
---|
633 | appendChild(parent, newChild) {
|
---|
634 | parent.appendChild(newChild);
|
---|
635 | }
|
---|
636 | insertBefore(parent, newChild, refChild) {
|
---|
637 | if (parent) {
|
---|
638 | parent.insertBefore(newChild, refChild);
|
---|
639 | }
|
---|
640 | }
|
---|
641 | removeChild(parent, oldChild) {
|
---|
642 | if (parent) {
|
---|
643 | parent.removeChild(oldChild);
|
---|
644 | }
|
---|
645 | }
|
---|
646 | selectRootElement(selectorOrNode, preserveContent) {
|
---|
647 | let el = typeof selectorOrNode === 'string' ? document.querySelector(selectorOrNode) :
|
---|
648 | selectorOrNode;
|
---|
649 | if (!el) {
|
---|
650 | throw new Error(`The selector "${selectorOrNode}" did not match any elements`);
|
---|
651 | }
|
---|
652 | if (!preserveContent) {
|
---|
653 | el.textContent = '';
|
---|
654 | }
|
---|
655 | return el;
|
---|
656 | }
|
---|
657 | parentNode(node) {
|
---|
658 | return node.parentNode;
|
---|
659 | }
|
---|
660 | nextSibling(node) {
|
---|
661 | return node.nextSibling;
|
---|
662 | }
|
---|
663 | setAttribute(el, name, value, namespace) {
|
---|
664 | if (namespace) {
|
---|
665 | name = namespace + ':' + name;
|
---|
666 | // TODO(FW-811): Ivy may cause issues here because it's passing around
|
---|
667 | // full URIs for namespaces, therefore this lookup will fail.
|
---|
668 | const namespaceUri = NAMESPACE_URIS[namespace];
|
---|
669 | if (namespaceUri) {
|
---|
670 | el.setAttributeNS(namespaceUri, name, value);
|
---|
671 | }
|
---|
672 | else {
|
---|
673 | el.setAttribute(name, value);
|
---|
674 | }
|
---|
675 | }
|
---|
676 | else {
|
---|
677 | el.setAttribute(name, value);
|
---|
678 | }
|
---|
679 | }
|
---|
680 | removeAttribute(el, name, namespace) {
|
---|
681 | if (namespace) {
|
---|
682 | // TODO(FW-811): Ivy may cause issues here because it's passing around
|
---|
683 | // full URIs for namespaces, therefore this lookup will fail.
|
---|
684 | const namespaceUri = NAMESPACE_URIS[namespace];
|
---|
685 | if (namespaceUri) {
|
---|
686 | el.removeAttributeNS(namespaceUri, name);
|
---|
687 | }
|
---|
688 | else {
|
---|
689 | // TODO(FW-811): Since ivy is passing around full URIs for namespaces
|
---|
690 | // this could result in properties like `http://www.w3.org/2000/svg:cx="123"`,
|
---|
691 | // which is wrong.
|
---|
692 | el.removeAttribute(`${namespace}:${name}`);
|
---|
693 | }
|
---|
694 | }
|
---|
695 | else {
|
---|
696 | el.removeAttribute(name);
|
---|
697 | }
|
---|
698 | }
|
---|
699 | addClass(el, name) {
|
---|
700 | el.classList.add(name);
|
---|
701 | }
|
---|
702 | removeClass(el, name) {
|
---|
703 | el.classList.remove(name);
|
---|
704 | }
|
---|
705 | setStyle(el, style, value, flags) {
|
---|
706 | if (flags & (RendererStyleFlags2.DashCase | RendererStyleFlags2.Important)) {
|
---|
707 | el.style.setProperty(style, value, flags & RendererStyleFlags2.Important ? 'important' : '');
|
---|
708 | }
|
---|
709 | else {
|
---|
710 | el.style[style] = value;
|
---|
711 | }
|
---|
712 | }
|
---|
713 | removeStyle(el, style, flags) {
|
---|
714 | if (flags & RendererStyleFlags2.DashCase) {
|
---|
715 | el.style.removeProperty(style);
|
---|
716 | }
|
---|
717 | else {
|
---|
718 | // IE requires '' instead of null
|
---|
719 | // see https://github.com/angular/angular/issues/7916
|
---|
720 | el.style[style] = '';
|
---|
721 | }
|
---|
722 | }
|
---|
723 | setProperty(el, name, value) {
|
---|
724 | NG_DEV_MODE && checkNoSyntheticProp(name, 'property');
|
---|
725 | el[name] = value;
|
---|
726 | }
|
---|
727 | setValue(node, value) {
|
---|
728 | node.nodeValue = value;
|
---|
729 | }
|
---|
730 | listen(target, event, callback) {
|
---|
731 | NG_DEV_MODE && checkNoSyntheticProp(event, 'listener');
|
---|
732 | if (typeof target === 'string') {
|
---|
733 | return this.eventManager.addGlobalEventListener(target, event, decoratePreventDefault(callback));
|
---|
734 | }
|
---|
735 | return this.eventManager.addEventListener(target, event, decoratePreventDefault(callback));
|
---|
736 | }
|
---|
737 | }
|
---|
738 | const ɵ0$1 = () => '@'.charCodeAt(0);
|
---|
739 | const AT_CHARCODE = (ɵ0$1)();
|
---|
740 | function checkNoSyntheticProp(name, nameKind) {
|
---|
741 | if (name.charCodeAt(0) === AT_CHARCODE) {
|
---|
742 | throw new Error(`Unexpected synthetic ${nameKind} ${name} found. Please make sure that:
|
---|
743 | - Either \`BrowserAnimationsModule\` or \`NoopAnimationsModule\` are imported in your application.
|
---|
744 | - There is corresponding configuration for the animation named \`${name}\` defined in the \`animations\` field of the \`@Component\` decorator (see https://angular.io/api/core/Component#animations).`);
|
---|
745 | }
|
---|
746 | }
|
---|
747 | class EmulatedEncapsulationDomRenderer2 extends DefaultDomRenderer2 {
|
---|
748 | constructor(eventManager, sharedStylesHost, component, appId) {
|
---|
749 | super(eventManager);
|
---|
750 | this.component = component;
|
---|
751 | const styles = flattenStyles(appId + '-' + component.id, component.styles, []);
|
---|
752 | sharedStylesHost.addStyles(styles);
|
---|
753 | this.contentAttr = shimContentAttribute(appId + '-' + component.id);
|
---|
754 | this.hostAttr = shimHostAttribute(appId + '-' + component.id);
|
---|
755 | }
|
---|
756 | applyToHost(element) {
|
---|
757 | super.setAttribute(element, this.hostAttr, '');
|
---|
758 | }
|
---|
759 | createElement(parent, name) {
|
---|
760 | const el = super.createElement(parent, name);
|
---|
761 | super.setAttribute(el, this.contentAttr, '');
|
---|
762 | return el;
|
---|
763 | }
|
---|
764 | }
|
---|
765 | class ShadowDomRenderer extends DefaultDomRenderer2 {
|
---|
766 | constructor(eventManager, sharedStylesHost, hostEl, component) {
|
---|
767 | super(eventManager);
|
---|
768 | this.sharedStylesHost = sharedStylesHost;
|
---|
769 | this.hostEl = hostEl;
|
---|
770 | this.shadowRoot = hostEl.attachShadow({ mode: 'open' });
|
---|
771 | this.sharedStylesHost.addHost(this.shadowRoot);
|
---|
772 | const styles = flattenStyles(component.id, component.styles, []);
|
---|
773 | for (let i = 0; i < styles.length; i++) {
|
---|
774 | const styleEl = document.createElement('style');
|
---|
775 | styleEl.textContent = styles[i];
|
---|
776 | this.shadowRoot.appendChild(styleEl);
|
---|
777 | }
|
---|
778 | }
|
---|
779 | nodeOrShadowRoot(node) {
|
---|
780 | return node === this.hostEl ? this.shadowRoot : node;
|
---|
781 | }
|
---|
782 | destroy() {
|
---|
783 | this.sharedStylesHost.removeHost(this.shadowRoot);
|
---|
784 | }
|
---|
785 | appendChild(parent, newChild) {
|
---|
786 | return super.appendChild(this.nodeOrShadowRoot(parent), newChild);
|
---|
787 | }
|
---|
788 | insertBefore(parent, newChild, refChild) {
|
---|
789 | return super.insertBefore(this.nodeOrShadowRoot(parent), newChild, refChild);
|
---|
790 | }
|
---|
791 | removeChild(parent, oldChild) {
|
---|
792 | return super.removeChild(this.nodeOrShadowRoot(parent), oldChild);
|
---|
793 | }
|
---|
794 | parentNode(node) {
|
---|
795 | return this.nodeOrShadowRoot(super.parentNode(this.nodeOrShadowRoot(node)));
|
---|
796 | }
|
---|
797 | }
|
---|
798 |
|
---|
799 | /**
|
---|
800 | * @license
|
---|
801 | * Copyright Google LLC All Rights Reserved.
|
---|
802 | *
|
---|
803 | * Use of this source code is governed by an MIT-style license that can be
|
---|
804 | * found in the LICENSE file at https://angular.io/license
|
---|
805 | */
|
---|
806 | class DomEventsPlugin extends EventManagerPlugin {
|
---|
807 | constructor(doc) {
|
---|
808 | super(doc);
|
---|
809 | }
|
---|
810 | // This plugin should come last in the list of plugins, because it accepts all
|
---|
811 | // events.
|
---|
812 | supports(eventName) {
|
---|
813 | return true;
|
---|
814 | }
|
---|
815 | addEventListener(element, eventName, handler) {
|
---|
816 | element.addEventListener(eventName, handler, false);
|
---|
817 | return () => this.removeEventListener(element, eventName, handler);
|
---|
818 | }
|
---|
819 | removeEventListener(target, eventName, callback) {
|
---|
820 | return target.removeEventListener(eventName, callback);
|
---|
821 | }
|
---|
822 | }
|
---|
823 | DomEventsPlugin.decorators = [
|
---|
824 | { type: Injectable }
|
---|
825 | ];
|
---|
826 | DomEventsPlugin.ctorParameters = () => [
|
---|
827 | { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] }
|
---|
828 | ];
|
---|
829 |
|
---|
830 | /**
|
---|
831 | * @license
|
---|
832 | * Copyright Google LLC All Rights Reserved.
|
---|
833 | *
|
---|
834 | * Use of this source code is governed by an MIT-style license that can be
|
---|
835 | * found in the LICENSE file at https://angular.io/license
|
---|
836 | */
|
---|
837 | /**
|
---|
838 | * Supported HammerJS recognizer event names.
|
---|
839 | */
|
---|
840 | const EVENT_NAMES = {
|
---|
841 | // pan
|
---|
842 | 'pan': true,
|
---|
843 | 'panstart': true,
|
---|
844 | 'panmove': true,
|
---|
845 | 'panend': true,
|
---|
846 | 'pancancel': true,
|
---|
847 | 'panleft': true,
|
---|
848 | 'panright': true,
|
---|
849 | 'panup': true,
|
---|
850 | 'pandown': true,
|
---|
851 | // pinch
|
---|
852 | 'pinch': true,
|
---|
853 | 'pinchstart': true,
|
---|
854 | 'pinchmove': true,
|
---|
855 | 'pinchend': true,
|
---|
856 | 'pinchcancel': true,
|
---|
857 | 'pinchin': true,
|
---|
858 | 'pinchout': true,
|
---|
859 | // press
|
---|
860 | 'press': true,
|
---|
861 | 'pressup': true,
|
---|
862 | // rotate
|
---|
863 | 'rotate': true,
|
---|
864 | 'rotatestart': true,
|
---|
865 | 'rotatemove': true,
|
---|
866 | 'rotateend': true,
|
---|
867 | 'rotatecancel': true,
|
---|
868 | // swipe
|
---|
869 | 'swipe': true,
|
---|
870 | 'swipeleft': true,
|
---|
871 | 'swiperight': true,
|
---|
872 | 'swipeup': true,
|
---|
873 | 'swipedown': true,
|
---|
874 | // tap
|
---|
875 | 'tap': true,
|
---|
876 | 'doubletap': true
|
---|
877 | };
|
---|
878 | /**
|
---|
879 | * DI token for providing [HammerJS](https://hammerjs.github.io/) support to Angular.
|
---|
880 | * @see `HammerGestureConfig`
|
---|
881 | *
|
---|
882 | * @ngModule HammerModule
|
---|
883 | * @publicApi
|
---|
884 | */
|
---|
885 | const HAMMER_GESTURE_CONFIG = new InjectionToken('HammerGestureConfig');
|
---|
886 | /**
|
---|
887 | * Injection token used to provide a {@link HammerLoader} to Angular.
|
---|
888 | *
|
---|
889 | * @publicApi
|
---|
890 | */
|
---|
891 | const HAMMER_LOADER = new InjectionToken('HammerLoader');
|
---|
892 | /**
|
---|
893 | * An injectable [HammerJS Manager](https://hammerjs.github.io/api/#hammermanager)
|
---|
894 | * for gesture recognition. Configures specific event recognition.
|
---|
895 | * @publicApi
|
---|
896 | */
|
---|
897 | class HammerGestureConfig {
|
---|
898 | constructor() {
|
---|
899 | /**
|
---|
900 | * A set of supported event names for gestures to be used in Angular.
|
---|
901 | * Angular supports all built-in recognizers, as listed in
|
---|
902 | * [HammerJS documentation](https://hammerjs.github.io/).
|
---|
903 | */
|
---|
904 | this.events = [];
|
---|
905 | /**
|
---|
906 | * Maps gesture event names to a set of configuration options
|
---|
907 | * that specify overrides to the default values for specific properties.
|
---|
908 | *
|
---|
909 | * The key is a supported event name to be configured,
|
---|
910 | * and the options object contains a set of properties, with override values
|
---|
911 | * to be applied to the named recognizer event.
|
---|
912 | * For example, to disable recognition of the rotate event, specify
|
---|
913 | * `{"rotate": {"enable": false}}`.
|
---|
914 | *
|
---|
915 | * Properties that are not present take the HammerJS default values.
|
---|
916 | * For information about which properties are supported for which events,
|
---|
917 | * and their allowed and default values, see
|
---|
918 | * [HammerJS documentation](https://hammerjs.github.io/).
|
---|
919 | *
|
---|
920 | */
|
---|
921 | this.overrides = {};
|
---|
922 | }
|
---|
923 | /**
|
---|
924 | * Creates a [HammerJS Manager](https://hammerjs.github.io/api/#hammermanager)
|
---|
925 | * and attaches it to a given HTML element.
|
---|
926 | * @param element The element that will recognize gestures.
|
---|
927 | * @returns A HammerJS event-manager object.
|
---|
928 | */
|
---|
929 | buildHammer(element) {
|
---|
930 | const mc = new Hammer(element, this.options);
|
---|
931 | mc.get('pinch').set({ enable: true });
|
---|
932 | mc.get('rotate').set({ enable: true });
|
---|
933 | for (const eventName in this.overrides) {
|
---|
934 | mc.get(eventName).set(this.overrides[eventName]);
|
---|
935 | }
|
---|
936 | return mc;
|
---|
937 | }
|
---|
938 | }
|
---|
939 | HammerGestureConfig.decorators = [
|
---|
940 | { type: Injectable }
|
---|
941 | ];
|
---|
942 | /**
|
---|
943 | * Event plugin that adds Hammer support to an application.
|
---|
944 | *
|
---|
945 | * @ngModule HammerModule
|
---|
946 | */
|
---|
947 | class HammerGesturesPlugin extends EventManagerPlugin {
|
---|
948 | constructor(doc, _config, console, loader) {
|
---|
949 | super(doc);
|
---|
950 | this._config = _config;
|
---|
951 | this.console = console;
|
---|
952 | this.loader = loader;
|
---|
953 | this._loaderPromise = null;
|
---|
954 | }
|
---|
955 | supports(eventName) {
|
---|
956 | if (!EVENT_NAMES.hasOwnProperty(eventName.toLowerCase()) && !this.isCustomEvent(eventName)) {
|
---|
957 | return false;
|
---|
958 | }
|
---|
959 | if (!window.Hammer && !this.loader) {
|
---|
960 | if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
---|
961 | this.console.warn(`The "${eventName}" event cannot be bound because Hammer.JS is not ` +
|
---|
962 | `loaded and no custom loader has been specified.`);
|
---|
963 | }
|
---|
964 | return false;
|
---|
965 | }
|
---|
966 | return true;
|
---|
967 | }
|
---|
968 | addEventListener(element, eventName, handler) {
|
---|
969 | const zone = this.manager.getZone();
|
---|
970 | eventName = eventName.toLowerCase();
|
---|
971 | // If Hammer is not present but a loader is specified, we defer adding the event listener
|
---|
972 | // until Hammer is loaded.
|
---|
973 | if (!window.Hammer && this.loader) {
|
---|
974 | this._loaderPromise = this._loaderPromise || this.loader();
|
---|
975 | // This `addEventListener` method returns a function to remove the added listener.
|
---|
976 | // Until Hammer is loaded, the returned function needs to *cancel* the registration rather
|
---|
977 | // than remove anything.
|
---|
978 | let cancelRegistration = false;
|
---|
979 | let deregister = () => {
|
---|
980 | cancelRegistration = true;
|
---|
981 | };
|
---|
982 | this._loaderPromise
|
---|
983 | .then(() => {
|
---|
984 | // If Hammer isn't actually loaded when the custom loader resolves, give up.
|
---|
985 | if (!window.Hammer) {
|
---|
986 | if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
---|
987 | this.console.warn(`The custom HAMMER_LOADER completed, but Hammer.JS is not present.`);
|
---|
988 | }
|
---|
989 | deregister = () => { };
|
---|
990 | return;
|
---|
991 | }
|
---|
992 | if (!cancelRegistration) {
|
---|
993 | // Now that Hammer is loaded and the listener is being loaded for real,
|
---|
994 | // the deregistration function changes from canceling registration to removal.
|
---|
995 | deregister = this.addEventListener(element, eventName, handler);
|
---|
996 | }
|
---|
997 | })
|
---|
998 | .catch(() => {
|
---|
999 | if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
---|
1000 | this.console.warn(`The "${eventName}" event cannot be bound because the custom ` +
|
---|
1001 | `Hammer.JS loader failed.`);
|
---|
1002 | }
|
---|
1003 | deregister = () => { };
|
---|
1004 | });
|
---|
1005 | // Return a function that *executes* `deregister` (and not `deregister` itself) so that we
|
---|
1006 | // can change the behavior of `deregister` once the listener is added. Using a closure in
|
---|
1007 | // this way allows us to avoid any additional data structures to track listener removal.
|
---|
1008 | return () => {
|
---|
1009 | deregister();
|
---|
1010 | };
|
---|
1011 | }
|
---|
1012 | return zone.runOutsideAngular(() => {
|
---|
1013 | // Creating the manager bind events, must be done outside of angular
|
---|
1014 | const mc = this._config.buildHammer(element);
|
---|
1015 | const callback = function (eventObj) {
|
---|
1016 | zone.runGuarded(function () {
|
---|
1017 | handler(eventObj);
|
---|
1018 | });
|
---|
1019 | };
|
---|
1020 | mc.on(eventName, callback);
|
---|
1021 | return () => {
|
---|
1022 | mc.off(eventName, callback);
|
---|
1023 | // destroy mc to prevent memory leak
|
---|
1024 | if (typeof mc.destroy === 'function') {
|
---|
1025 | mc.destroy();
|
---|
1026 | }
|
---|
1027 | };
|
---|
1028 | });
|
---|
1029 | }
|
---|
1030 | isCustomEvent(eventName) {
|
---|
1031 | return this._config.events.indexOf(eventName) > -1;
|
---|
1032 | }
|
---|
1033 | }
|
---|
1034 | HammerGesturesPlugin.decorators = [
|
---|
1035 | { type: Injectable }
|
---|
1036 | ];
|
---|
1037 | HammerGesturesPlugin.ctorParameters = () => [
|
---|
1038 | { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
|
---|
1039 | { type: HammerGestureConfig, decorators: [{ type: Inject, args: [HAMMER_GESTURE_CONFIG,] }] },
|
---|
1040 | { type: ɵConsole },
|
---|
1041 | { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [HAMMER_LOADER,] }] }
|
---|
1042 | ];
|
---|
1043 | /**
|
---|
1044 | * In Ivy, support for Hammer gestures is optional, so applications must
|
---|
1045 | * import the `HammerModule` at root to turn on support. This means that
|
---|
1046 | * Hammer-specific code can be tree-shaken away if not needed.
|
---|
1047 | */
|
---|
1048 | const HAMMER_PROVIDERS__POST_R3__ = [];
|
---|
1049 | /**
|
---|
1050 | * In View Engine, support for Hammer gestures is built-in by default.
|
---|
1051 | */
|
---|
1052 | const HAMMER_PROVIDERS__PRE_R3__ = [
|
---|
1053 | {
|
---|
1054 | provide: EVENT_MANAGER_PLUGINS,
|
---|
1055 | useClass: HammerGesturesPlugin,
|
---|
1056 | multi: true,
|
---|
1057 | deps: [DOCUMENT, HAMMER_GESTURE_CONFIG, ɵConsole, [new Optional(), HAMMER_LOADER]]
|
---|
1058 | },
|
---|
1059 | { provide: HAMMER_GESTURE_CONFIG, useClass: HammerGestureConfig, deps: [] },
|
---|
1060 | ];
|
---|
1061 | const HAMMER_PROVIDERS = HAMMER_PROVIDERS__PRE_R3__;
|
---|
1062 | /**
|
---|
1063 | * Adds support for HammerJS.
|
---|
1064 | *
|
---|
1065 | * Import this module at the root of your application so that Angular can work with
|
---|
1066 | * HammerJS to detect gesture events.
|
---|
1067 | *
|
---|
1068 | * Note that applications still need to include the HammerJS script itself. This module
|
---|
1069 | * simply sets up the coordination layer between HammerJS and Angular's EventManager.
|
---|
1070 | *
|
---|
1071 | * @publicApi
|
---|
1072 | */
|
---|
1073 | class HammerModule {
|
---|
1074 | }
|
---|
1075 | HammerModule.decorators = [
|
---|
1076 | { type: NgModule, args: [{ providers: HAMMER_PROVIDERS__PRE_R3__ },] }
|
---|
1077 | ];
|
---|
1078 |
|
---|
1079 | /**
|
---|
1080 | * @license
|
---|
1081 | * Copyright Google LLC All Rights Reserved.
|
---|
1082 | *
|
---|
1083 | * Use of this source code is governed by an MIT-style license that can be
|
---|
1084 | * found in the LICENSE file at https://angular.io/license
|
---|
1085 | */
|
---|
1086 | /**
|
---|
1087 | * Defines supported modifiers for key events.
|
---|
1088 | */
|
---|
1089 | const MODIFIER_KEYS = ['alt', 'control', 'meta', 'shift'];
|
---|
1090 | const DOM_KEY_LOCATION_NUMPAD = 3;
|
---|
1091 | // Map to convert some key or keyIdentifier values to what will be returned by getEventKey
|
---|
1092 | const _keyMap = {
|
---|
1093 | // The following values are here for cross-browser compatibility and to match the W3C standard
|
---|
1094 | // cf https://www.w3.org/TR/DOM-Level-3-Events-key/
|
---|
1095 | '\b': 'Backspace',
|
---|
1096 | '\t': 'Tab',
|
---|
1097 | '\x7F': 'Delete',
|
---|
1098 | '\x1B': 'Escape',
|
---|
1099 | 'Del': 'Delete',
|
---|
1100 | 'Esc': 'Escape',
|
---|
1101 | 'Left': 'ArrowLeft',
|
---|
1102 | 'Right': 'ArrowRight',
|
---|
1103 | 'Up': 'ArrowUp',
|
---|
1104 | 'Down': 'ArrowDown',
|
---|
1105 | 'Menu': 'ContextMenu',
|
---|
1106 | 'Scroll': 'ScrollLock',
|
---|
1107 | 'Win': 'OS'
|
---|
1108 | };
|
---|
1109 | // There is a bug in Chrome for numeric keypad keys:
|
---|
1110 | // https://code.google.com/p/chromium/issues/detail?id=155654
|
---|
1111 | // 1, 2, 3 ... are reported as A, B, C ...
|
---|
1112 | const _chromeNumKeyPadMap = {
|
---|
1113 | 'A': '1',
|
---|
1114 | 'B': '2',
|
---|
1115 | 'C': '3',
|
---|
1116 | 'D': '4',
|
---|
1117 | 'E': '5',
|
---|
1118 | 'F': '6',
|
---|
1119 | 'G': '7',
|
---|
1120 | 'H': '8',
|
---|
1121 | 'I': '9',
|
---|
1122 | 'J': '*',
|
---|
1123 | 'K': '+',
|
---|
1124 | 'M': '-',
|
---|
1125 | 'N': '.',
|
---|
1126 | 'O': '/',
|
---|
1127 | '\x60': '0',
|
---|
1128 | '\x90': 'NumLock'
|
---|
1129 | };
|
---|
1130 | const ɵ0$2 = (event) => event.altKey, ɵ1 = (event) => event.ctrlKey, ɵ2 = (event) => event.metaKey, ɵ3 = (event) => event.shiftKey;
|
---|
1131 | /**
|
---|
1132 | * Retrieves modifiers from key-event objects.
|
---|
1133 | */
|
---|
1134 | const MODIFIER_KEY_GETTERS = {
|
---|
1135 | 'alt': ɵ0$2,
|
---|
1136 | 'control': ɵ1,
|
---|
1137 | 'meta': ɵ2,
|
---|
1138 | 'shift': ɵ3
|
---|
1139 | };
|
---|
1140 | /**
|
---|
1141 | * @publicApi
|
---|
1142 | * A browser plug-in that provides support for handling of key events in Angular.
|
---|
1143 | */
|
---|
1144 | class KeyEventsPlugin extends EventManagerPlugin {
|
---|
1145 | /**
|
---|
1146 | * Initializes an instance of the browser plug-in.
|
---|
1147 | * @param doc The document in which key events will be detected.
|
---|
1148 | */
|
---|
1149 | constructor(doc) {
|
---|
1150 | super(doc);
|
---|
1151 | }
|
---|
1152 | /**
|
---|
1153 | * Reports whether a named key event is supported.
|
---|
1154 | * @param eventName The event name to query.
|
---|
1155 | * @return True if the named key event is supported.
|
---|
1156 | */
|
---|
1157 | supports(eventName) {
|
---|
1158 | return KeyEventsPlugin.parseEventName(eventName) != null;
|
---|
1159 | }
|
---|
1160 | /**
|
---|
1161 | * Registers a handler for a specific element and key event.
|
---|
1162 | * @param element The HTML element to receive event notifications.
|
---|
1163 | * @param eventName The name of the key event to listen for.
|
---|
1164 | * @param handler A function to call when the notification occurs. Receives the
|
---|
1165 | * event object as an argument.
|
---|
1166 | * @returns The key event that was registered.
|
---|
1167 | */
|
---|
1168 | addEventListener(element, eventName, handler) {
|
---|
1169 | const parsedEvent = KeyEventsPlugin.parseEventName(eventName);
|
---|
1170 | const outsideHandler = KeyEventsPlugin.eventCallback(parsedEvent['fullKey'], handler, this.manager.getZone());
|
---|
1171 | return this.manager.getZone().runOutsideAngular(() => {
|
---|
1172 | return ɵgetDOM().onAndCancel(element, parsedEvent['domEventName'], outsideHandler);
|
---|
1173 | });
|
---|
1174 | }
|
---|
1175 | static parseEventName(eventName) {
|
---|
1176 | const parts = eventName.toLowerCase().split('.');
|
---|
1177 | const domEventName = parts.shift();
|
---|
1178 | if ((parts.length === 0) || !(domEventName === 'keydown' || domEventName === 'keyup')) {
|
---|
1179 | return null;
|
---|
1180 | }
|
---|
1181 | const key = KeyEventsPlugin._normalizeKey(parts.pop());
|
---|
1182 | let fullKey = '';
|
---|
1183 | MODIFIER_KEYS.forEach(modifierName => {
|
---|
1184 | const index = parts.indexOf(modifierName);
|
---|
1185 | if (index > -1) {
|
---|
1186 | parts.splice(index, 1);
|
---|
1187 | fullKey += modifierName + '.';
|
---|
1188 | }
|
---|
1189 | });
|
---|
1190 | fullKey += key;
|
---|
1191 | if (parts.length != 0 || key.length === 0) {
|
---|
1192 | // returning null instead of throwing to let another plugin process the event
|
---|
1193 | return null;
|
---|
1194 | }
|
---|
1195 | // NOTE: Please don't rewrite this as so, as it will break JSCompiler property renaming.
|
---|
1196 | // The code must remain in the `result['domEventName']` form.
|
---|
1197 | // return {domEventName, fullKey};
|
---|
1198 | const result = {};
|
---|
1199 | result['domEventName'] = domEventName;
|
---|
1200 | result['fullKey'] = fullKey;
|
---|
1201 | return result;
|
---|
1202 | }
|
---|
1203 | static getEventFullKey(event) {
|
---|
1204 | let fullKey = '';
|
---|
1205 | let key = getEventKey(event);
|
---|
1206 | key = key.toLowerCase();
|
---|
1207 | if (key === ' ') {
|
---|
1208 | key = 'space'; // for readability
|
---|
1209 | }
|
---|
1210 | else if (key === '.') {
|
---|
1211 | key = 'dot'; // because '.' is used as a separator in event names
|
---|
1212 | }
|
---|
1213 | MODIFIER_KEYS.forEach(modifierName => {
|
---|
1214 | if (modifierName != key) {
|
---|
1215 | const modifierGetter = MODIFIER_KEY_GETTERS[modifierName];
|
---|
1216 | if (modifierGetter(event)) {
|
---|
1217 | fullKey += modifierName + '.';
|
---|
1218 | }
|
---|
1219 | }
|
---|
1220 | });
|
---|
1221 | fullKey += key;
|
---|
1222 | return fullKey;
|
---|
1223 | }
|
---|
1224 | /**
|
---|
1225 | * Configures a handler callback for a key event.
|
---|
1226 | * @param fullKey The event name that combines all simultaneous keystrokes.
|
---|
1227 | * @param handler The function that responds to the key event.
|
---|
1228 | * @param zone The zone in which the event occurred.
|
---|
1229 | * @returns A callback function.
|
---|
1230 | */
|
---|
1231 | static eventCallback(fullKey, handler, zone) {
|
---|
1232 | return (event /** TODO #9100 */) => {
|
---|
1233 | if (KeyEventsPlugin.getEventFullKey(event) === fullKey) {
|
---|
1234 | zone.runGuarded(() => handler(event));
|
---|
1235 | }
|
---|
1236 | };
|
---|
1237 | }
|
---|
1238 | /** @internal */
|
---|
1239 | static _normalizeKey(keyName) {
|
---|
1240 | // TODO: switch to a Map if the mapping grows too much
|
---|
1241 | switch (keyName) {
|
---|
1242 | case 'esc':
|
---|
1243 | return 'escape';
|
---|
1244 | default:
|
---|
1245 | return keyName;
|
---|
1246 | }
|
---|
1247 | }
|
---|
1248 | }
|
---|
1249 | KeyEventsPlugin.decorators = [
|
---|
1250 | { type: Injectable }
|
---|
1251 | ];
|
---|
1252 | KeyEventsPlugin.ctorParameters = () => [
|
---|
1253 | { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] }
|
---|
1254 | ];
|
---|
1255 | function getEventKey(event) {
|
---|
1256 | let key = event.key;
|
---|
1257 | if (key == null) {
|
---|
1258 | key = event.keyIdentifier;
|
---|
1259 | // keyIdentifier is defined in the old draft of DOM Level 3 Events implemented by Chrome and
|
---|
1260 | // Safari cf
|
---|
1261 | // https://www.w3.org/TR/2007/WD-DOM-Level-3-Events-20071221/events.html#Events-KeyboardEvents-Interfaces
|
---|
1262 | if (key == null) {
|
---|
1263 | return 'Unidentified';
|
---|
1264 | }
|
---|
1265 | if (key.startsWith('U+')) {
|
---|
1266 | key = String.fromCharCode(parseInt(key.substring(2), 16));
|
---|
1267 | if (event.location === DOM_KEY_LOCATION_NUMPAD && _chromeNumKeyPadMap.hasOwnProperty(key)) {
|
---|
1268 | // There is a bug in Chrome for numeric keypad keys:
|
---|
1269 | // https://code.google.com/p/chromium/issues/detail?id=155654
|
---|
1270 | // 1, 2, 3 ... are reported as A, B, C ...
|
---|
1271 | key = _chromeNumKeyPadMap[key];
|
---|
1272 | }
|
---|
1273 | }
|
---|
1274 | }
|
---|
1275 | return _keyMap[key] || key;
|
---|
1276 | }
|
---|
1277 |
|
---|
1278 | /**
|
---|
1279 | * @license
|
---|
1280 | * Copyright Google LLC All Rights Reserved.
|
---|
1281 | *
|
---|
1282 | * Use of this source code is governed by an MIT-style license that can be
|
---|
1283 | * found in the LICENSE file at https://angular.io/license
|
---|
1284 | */
|
---|
1285 | /**
|
---|
1286 | * DomSanitizer helps preventing Cross Site Scripting Security bugs (XSS) by sanitizing
|
---|
1287 | * values to be safe to use in the different DOM contexts.
|
---|
1288 | *
|
---|
1289 | * For example, when binding a URL in an `<a [href]="someValue">` hyperlink, `someValue` will be
|
---|
1290 | * sanitized so that an attacker cannot inject e.g. a `javascript:` URL that would execute code on
|
---|
1291 | * the website.
|
---|
1292 | *
|
---|
1293 | * In specific situations, it might be necessary to disable sanitization, for example if the
|
---|
1294 | * application genuinely needs to produce a `javascript:` style link with a dynamic value in it.
|
---|
1295 | * Users can bypass security by constructing a value with one of the `bypassSecurityTrust...`
|
---|
1296 | * methods, and then binding to that value from the template.
|
---|
1297 | *
|
---|
1298 | * These situations should be very rare, and extraordinary care must be taken to avoid creating a
|
---|
1299 | * Cross Site Scripting (XSS) security bug!
|
---|
1300 | *
|
---|
1301 | * When using `bypassSecurityTrust...`, make sure to call the method as early as possible and as
|
---|
1302 | * close as possible to the source of the value, to make it easy to verify no security bug is
|
---|
1303 | * created by its use.
|
---|
1304 | *
|
---|
1305 | * It is not required (and not recommended) to bypass security if the value is safe, e.g. a URL that
|
---|
1306 | * does not start with a suspicious protocol, or an HTML snippet that does not contain dangerous
|
---|
1307 | * code. The sanitizer leaves safe values intact.
|
---|
1308 | *
|
---|
1309 | * @security Calling any of the `bypassSecurityTrust...` APIs disables Angular's built-in
|
---|
1310 | * sanitization for the value passed in. Carefully check and audit all values and code paths going
|
---|
1311 | * into this call. Make sure any user data is appropriately escaped for this security context.
|
---|
1312 | * For more detail, see the [Security Guide](https://g.co/ng/security).
|
---|
1313 | *
|
---|
1314 | * @publicApi
|
---|
1315 | */
|
---|
1316 | class DomSanitizer {
|
---|
1317 | }
|
---|
1318 | DomSanitizer.ɵprov = ɵɵdefineInjectable({ factory: function DomSanitizer_Factory() { return ɵɵinject(DomSanitizerImpl); }, token: DomSanitizer, providedIn: "root" });
|
---|
1319 | DomSanitizer.decorators = [
|
---|
1320 | { type: Injectable, args: [{ providedIn: 'root', useExisting: forwardRef(() => DomSanitizerImpl) },] }
|
---|
1321 | ];
|
---|
1322 | function domSanitizerImplFactory(injector) {
|
---|
1323 | return new DomSanitizerImpl(injector.get(DOCUMENT));
|
---|
1324 | }
|
---|
1325 | class DomSanitizerImpl extends DomSanitizer {
|
---|
1326 | constructor(_doc) {
|
---|
1327 | super();
|
---|
1328 | this._doc = _doc;
|
---|
1329 | }
|
---|
1330 | sanitize(ctx, value) {
|
---|
1331 | if (value == null)
|
---|
1332 | return null;
|
---|
1333 | switch (ctx) {
|
---|
1334 | case SecurityContext.NONE:
|
---|
1335 | return value;
|
---|
1336 | case SecurityContext.HTML:
|
---|
1337 | if (ɵallowSanitizationBypassAndThrow(value, "HTML" /* Html */)) {
|
---|
1338 | return ɵunwrapSafeValue(value);
|
---|
1339 | }
|
---|
1340 | return ɵ_sanitizeHtml(this._doc, String(value)).toString();
|
---|
1341 | case SecurityContext.STYLE:
|
---|
1342 | if (ɵallowSanitizationBypassAndThrow(value, "Style" /* Style */)) {
|
---|
1343 | return ɵunwrapSafeValue(value);
|
---|
1344 | }
|
---|
1345 | return value;
|
---|
1346 | case SecurityContext.SCRIPT:
|
---|
1347 | if (ɵallowSanitizationBypassAndThrow(value, "Script" /* Script */)) {
|
---|
1348 | return ɵunwrapSafeValue(value);
|
---|
1349 | }
|
---|
1350 | throw new Error('unsafe value used in a script context');
|
---|
1351 | case SecurityContext.URL:
|
---|
1352 | const type = ɵgetSanitizationBypassType(value);
|
---|
1353 | if (ɵallowSanitizationBypassAndThrow(value, "URL" /* Url */)) {
|
---|
1354 | return ɵunwrapSafeValue(value);
|
---|
1355 | }
|
---|
1356 | return ɵ_sanitizeUrl(String(value));
|
---|
1357 | case SecurityContext.RESOURCE_URL:
|
---|
1358 | if (ɵallowSanitizationBypassAndThrow(value, "ResourceURL" /* ResourceUrl */)) {
|
---|
1359 | return ɵunwrapSafeValue(value);
|
---|
1360 | }
|
---|
1361 | throw new Error('unsafe value used in a resource URL context (see https://g.co/ng/security#xss)');
|
---|
1362 | default:
|
---|
1363 | throw new Error(`Unexpected SecurityContext ${ctx} (see https://g.co/ng/security#xss)`);
|
---|
1364 | }
|
---|
1365 | }
|
---|
1366 | bypassSecurityTrustHtml(value) {
|
---|
1367 | return ɵbypassSanitizationTrustHtml(value);
|
---|
1368 | }
|
---|
1369 | bypassSecurityTrustStyle(value) {
|
---|
1370 | return ɵbypassSanitizationTrustStyle(value);
|
---|
1371 | }
|
---|
1372 | bypassSecurityTrustScript(value) {
|
---|
1373 | return ɵbypassSanitizationTrustScript(value);
|
---|
1374 | }
|
---|
1375 | bypassSecurityTrustUrl(value) {
|
---|
1376 | return ɵbypassSanitizationTrustUrl(value);
|
---|
1377 | }
|
---|
1378 | bypassSecurityTrustResourceUrl(value) {
|
---|
1379 | return ɵbypassSanitizationTrustResourceUrl(value);
|
---|
1380 | }
|
---|
1381 | }
|
---|
1382 | DomSanitizerImpl.ɵprov = ɵɵdefineInjectable({ factory: function DomSanitizerImpl_Factory() { return domSanitizerImplFactory(ɵɵinject(INJECTOR)); }, token: DomSanitizerImpl, providedIn: "root" });
|
---|
1383 | DomSanitizerImpl.decorators = [
|
---|
1384 | { type: Injectable, args: [{ providedIn: 'root', useFactory: domSanitizerImplFactory, deps: [Injector] },] }
|
---|
1385 | ];
|
---|
1386 | DomSanitizerImpl.ctorParameters = () => [
|
---|
1387 | { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] }
|
---|
1388 | ];
|
---|
1389 |
|
---|
1390 | /**
|
---|
1391 | * @license
|
---|
1392 | * Copyright Google LLC All Rights Reserved.
|
---|
1393 | *
|
---|
1394 | * Use of this source code is governed by an MIT-style license that can be
|
---|
1395 | * found in the LICENSE file at https://angular.io/license
|
---|
1396 | */
|
---|
1397 | function initDomAdapter() {
|
---|
1398 | BrowserDomAdapter.makeCurrent();
|
---|
1399 | BrowserGetTestability.init();
|
---|
1400 | }
|
---|
1401 | function errorHandler() {
|
---|
1402 | return new ErrorHandler();
|
---|
1403 | }
|
---|
1404 | function _document() {
|
---|
1405 | // Tell ivy about the global document
|
---|
1406 | ɵsetDocument(document);
|
---|
1407 | return document;
|
---|
1408 | }
|
---|
1409 | const ɵ0$3 = ɵPLATFORM_BROWSER_ID;
|
---|
1410 | const INTERNAL_BROWSER_PLATFORM_PROVIDERS = [
|
---|
1411 | { provide: PLATFORM_ID, useValue: ɵ0$3 },
|
---|
1412 | { provide: PLATFORM_INITIALIZER, useValue: initDomAdapter, multi: true },
|
---|
1413 | { provide: DOCUMENT, useFactory: _document, deps: [] },
|
---|
1414 | ];
|
---|
1415 | const BROWSER_SANITIZATION_PROVIDERS__PRE_R3__ = [
|
---|
1416 | { provide: Sanitizer, useExisting: DomSanitizer },
|
---|
1417 | { provide: DomSanitizer, useClass: DomSanitizerImpl, deps: [DOCUMENT] },
|
---|
1418 | ];
|
---|
1419 | const BROWSER_SANITIZATION_PROVIDERS__POST_R3__ = [];
|
---|
1420 | /**
|
---|
1421 | * @security Replacing built-in sanitization providers exposes the application to XSS risks.
|
---|
1422 | * Attacker-controlled data introduced by an unsanitized provider could expose your
|
---|
1423 | * application to XSS risks. For more detail, see the [Security Guide](https://g.co/ng/security).
|
---|
1424 | * @publicApi
|
---|
1425 | */
|
---|
1426 | const BROWSER_SANITIZATION_PROVIDERS = BROWSER_SANITIZATION_PROVIDERS__PRE_R3__;
|
---|
1427 | /**
|
---|
1428 | * A factory function that returns a `PlatformRef` instance associated with browser service
|
---|
1429 | * providers.
|
---|
1430 | *
|
---|
1431 | * @publicApi
|
---|
1432 | */
|
---|
1433 | const platformBrowser = createPlatformFactory(platformCore, 'browser', INTERNAL_BROWSER_PLATFORM_PROVIDERS);
|
---|
1434 | const BROWSER_MODULE_PROVIDERS = [
|
---|
1435 | BROWSER_SANITIZATION_PROVIDERS,
|
---|
1436 | { provide: ɵINJECTOR_SCOPE, useValue: 'root' },
|
---|
1437 | { provide: ErrorHandler, useFactory: errorHandler, deps: [] },
|
---|
1438 | {
|
---|
1439 | provide: EVENT_MANAGER_PLUGINS,
|
---|
1440 | useClass: DomEventsPlugin,
|
---|
1441 | multi: true,
|
---|
1442 | deps: [DOCUMENT, NgZone, PLATFORM_ID]
|
---|
1443 | },
|
---|
1444 | { provide: EVENT_MANAGER_PLUGINS, useClass: KeyEventsPlugin, multi: true, deps: [DOCUMENT] },
|
---|
1445 | HAMMER_PROVIDERS,
|
---|
1446 | {
|
---|
1447 | provide: DomRendererFactory2,
|
---|
1448 | useClass: DomRendererFactory2,
|
---|
1449 | deps: [EventManager, DomSharedStylesHost, APP_ID]
|
---|
1450 | },
|
---|
1451 | { provide: RendererFactory2, useExisting: DomRendererFactory2 },
|
---|
1452 | { provide: SharedStylesHost, useExisting: DomSharedStylesHost },
|
---|
1453 | { provide: DomSharedStylesHost, useClass: DomSharedStylesHost, deps: [DOCUMENT] },
|
---|
1454 | { provide: Testability, useClass: Testability, deps: [NgZone] },
|
---|
1455 | { provide: EventManager, useClass: EventManager, deps: [EVENT_MANAGER_PLUGINS, NgZone] },
|
---|
1456 | { provide: XhrFactory, useClass: BrowserXhr, deps: [] },
|
---|
1457 | ELEMENT_PROBE_PROVIDERS,
|
---|
1458 | ];
|
---|
1459 | /**
|
---|
1460 | * Exports required infrastructure for all Angular apps.
|
---|
1461 | * Included by default in all Angular apps created with the CLI
|
---|
1462 | * `new` command.
|
---|
1463 | * Re-exports `CommonModule` and `ApplicationModule`, making their
|
---|
1464 | * exports and providers available to all apps.
|
---|
1465 | *
|
---|
1466 | * @publicApi
|
---|
1467 | */
|
---|
1468 | class BrowserModule {
|
---|
1469 | constructor(parentModule) {
|
---|
1470 | if (parentModule) {
|
---|
1471 | throw new Error(`BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead.`);
|
---|
1472 | }
|
---|
1473 | }
|
---|
1474 | /**
|
---|
1475 | * Configures a browser-based app to transition from a server-rendered app, if
|
---|
1476 | * one is present on the page.
|
---|
1477 | *
|
---|
1478 | * @param params An object containing an identifier for the app to transition.
|
---|
1479 | * The ID must match between the client and server versions of the app.
|
---|
1480 | * @returns The reconfigured `BrowserModule` to import into the app's root `AppModule`.
|
---|
1481 | */
|
---|
1482 | static withServerTransition(params) {
|
---|
1483 | return {
|
---|
1484 | ngModule: BrowserModule,
|
---|
1485 | providers: [
|
---|
1486 | { provide: APP_ID, useValue: params.appId },
|
---|
1487 | { provide: TRANSITION_ID, useExisting: APP_ID },
|
---|
1488 | SERVER_TRANSITION_PROVIDERS,
|
---|
1489 | ],
|
---|
1490 | };
|
---|
1491 | }
|
---|
1492 | }
|
---|
1493 | BrowserModule.decorators = [
|
---|
1494 | { type: NgModule, args: [{ providers: BROWSER_MODULE_PROVIDERS, exports: [CommonModule, ApplicationModule] },] }
|
---|
1495 | ];
|
---|
1496 | BrowserModule.ctorParameters = () => [
|
---|
1497 | { type: BrowserModule, decorators: [{ type: Optional }, { type: SkipSelf }, { type: Inject, args: [BrowserModule,] }] }
|
---|
1498 | ];
|
---|
1499 |
|
---|
1500 | /**
|
---|
1501 | * @license
|
---|
1502 | * Copyright Google LLC All Rights Reserved.
|
---|
1503 | *
|
---|
1504 | * Use of this source code is governed by an MIT-style license that can be
|
---|
1505 | * found in the LICENSE file at https://angular.io/license
|
---|
1506 | */
|
---|
1507 | /**
|
---|
1508 | * Factory to create a `Meta` service instance for the current DOM document.
|
---|
1509 | */
|
---|
1510 | function createMeta() {
|
---|
1511 | return new Meta(ɵɵinject(DOCUMENT));
|
---|
1512 | }
|
---|
1513 | /**
|
---|
1514 | * A service for managing HTML `<meta>` tags.
|
---|
1515 | *
|
---|
1516 | * Properties of the `MetaDefinition` object match the attributes of the
|
---|
1517 | * HTML `<meta>` tag. These tags define document metadata that is important for
|
---|
1518 | * things like configuring a Content Security Policy, defining browser compatibility
|
---|
1519 | * and security settings, setting HTTP Headers, defining rich content for social sharing,
|
---|
1520 | * and Search Engine Optimization (SEO).
|
---|
1521 | *
|
---|
1522 | * To identify specific `<meta>` tags in a document, use an attribute selection
|
---|
1523 | * string in the format `"tag_attribute='value string'"`.
|
---|
1524 | * For example, an `attrSelector` value of `"name='description'"` matches a tag
|
---|
1525 | * whose `name` attribute has the value `"description"`.
|
---|
1526 | * Selectors are used with the `querySelector()` Document method,
|
---|
1527 | * in the format `meta[{attrSelector}]`.
|
---|
1528 | *
|
---|
1529 | * @see [HTML meta tag](https://developer.mozilla.org/docs/Web/HTML/Element/meta)
|
---|
1530 | * @see [Document.querySelector()](https://developer.mozilla.org/docs/Web/API/Document/querySelector)
|
---|
1531 | *
|
---|
1532 | *
|
---|
1533 | * @publicApi
|
---|
1534 | */
|
---|
1535 | class Meta {
|
---|
1536 | constructor(_doc) {
|
---|
1537 | this._doc = _doc;
|
---|
1538 | this._dom = ɵgetDOM();
|
---|
1539 | }
|
---|
1540 | /**
|
---|
1541 | * Retrieves or creates a specific `<meta>` tag element in the current HTML document.
|
---|
1542 | * In searching for an existing tag, Angular attempts to match the `name` or `property` attribute
|
---|
1543 | * values in the provided tag definition, and verifies that all other attribute values are equal.
|
---|
1544 | * If an existing element is found, it is returned and is not modified in any way.
|
---|
1545 | * @param tag The definition of a `<meta>` element to match or create.
|
---|
1546 | * @param forceCreation True to create a new element without checking whether one already exists.
|
---|
1547 | * @returns The existing element with the same attributes and values if found,
|
---|
1548 | * the new element if no match is found, or `null` if the tag parameter is not defined.
|
---|
1549 | */
|
---|
1550 | addTag(tag, forceCreation = false) {
|
---|
1551 | if (!tag)
|
---|
1552 | return null;
|
---|
1553 | return this._getOrCreateElement(tag, forceCreation);
|
---|
1554 | }
|
---|
1555 | /**
|
---|
1556 | * Retrieves or creates a set of `<meta>` tag elements in the current HTML document.
|
---|
1557 | * In searching for an existing tag, Angular attempts to match the `name` or `property` attribute
|
---|
1558 | * values in the provided tag definition, and verifies that all other attribute values are equal.
|
---|
1559 | * @param tags An array of tag definitions to match or create.
|
---|
1560 | * @param forceCreation True to create new elements without checking whether they already exist.
|
---|
1561 | * @returns The matching elements if found, or the new elements.
|
---|
1562 | */
|
---|
1563 | addTags(tags, forceCreation = false) {
|
---|
1564 | if (!tags)
|
---|
1565 | return [];
|
---|
1566 | return tags.reduce((result, tag) => {
|
---|
1567 | if (tag) {
|
---|
1568 | result.push(this._getOrCreateElement(tag, forceCreation));
|
---|
1569 | }
|
---|
1570 | return result;
|
---|
1571 | }, []);
|
---|
1572 | }
|
---|
1573 | /**
|
---|
1574 | * Retrieves a `<meta>` tag element in the current HTML document.
|
---|
1575 | * @param attrSelector The tag attribute and value to match against, in the format
|
---|
1576 | * `"tag_attribute='value string'"`.
|
---|
1577 | * @returns The matching element, if any.
|
---|
1578 | */
|
---|
1579 | getTag(attrSelector) {
|
---|
1580 | if (!attrSelector)
|
---|
1581 | return null;
|
---|
1582 | return this._doc.querySelector(`meta[${attrSelector}]`) || null;
|
---|
1583 | }
|
---|
1584 | /**
|
---|
1585 | * Retrieves a set of `<meta>` tag elements in the current HTML document.
|
---|
1586 | * @param attrSelector The tag attribute and value to match against, in the format
|
---|
1587 | * `"tag_attribute='value string'"`.
|
---|
1588 | * @returns The matching elements, if any.
|
---|
1589 | */
|
---|
1590 | getTags(attrSelector) {
|
---|
1591 | if (!attrSelector)
|
---|
1592 | return [];
|
---|
1593 | const list /*NodeList*/ = this._doc.querySelectorAll(`meta[${attrSelector}]`);
|
---|
1594 | return list ? [].slice.call(list) : [];
|
---|
1595 | }
|
---|
1596 | /**
|
---|
1597 | * Modifies an existing `<meta>` tag element in the current HTML document.
|
---|
1598 | * @param tag The tag description with which to replace the existing tag content.
|
---|
1599 | * @param selector A tag attribute and value to match against, to identify
|
---|
1600 | * an existing tag. A string in the format `"tag_attribute=`value string`"`.
|
---|
1601 | * If not supplied, matches a tag with the same `name` or `property` attribute value as the
|
---|
1602 | * replacement tag.
|
---|
1603 | * @return The modified element.
|
---|
1604 | */
|
---|
1605 | updateTag(tag, selector) {
|
---|
1606 | if (!tag)
|
---|
1607 | return null;
|
---|
1608 | selector = selector || this._parseSelector(tag);
|
---|
1609 | const meta = this.getTag(selector);
|
---|
1610 | if (meta) {
|
---|
1611 | return this._setMetaElementAttributes(tag, meta);
|
---|
1612 | }
|
---|
1613 | return this._getOrCreateElement(tag, true);
|
---|
1614 | }
|
---|
1615 | /**
|
---|
1616 | * Removes an existing `<meta>` tag element from the current HTML document.
|
---|
1617 | * @param attrSelector A tag attribute and value to match against, to identify
|
---|
1618 | * an existing tag. A string in the format `"tag_attribute=`value string`"`.
|
---|
1619 | */
|
---|
1620 | removeTag(attrSelector) {
|
---|
1621 | this.removeTagElement(this.getTag(attrSelector));
|
---|
1622 | }
|
---|
1623 | /**
|
---|
1624 | * Removes an existing `<meta>` tag element from the current HTML document.
|
---|
1625 | * @param meta The tag definition to match against to identify an existing tag.
|
---|
1626 | */
|
---|
1627 | removeTagElement(meta) {
|
---|
1628 | if (meta) {
|
---|
1629 | this._dom.remove(meta);
|
---|
1630 | }
|
---|
1631 | }
|
---|
1632 | _getOrCreateElement(meta, forceCreation = false) {
|
---|
1633 | if (!forceCreation) {
|
---|
1634 | const selector = this._parseSelector(meta);
|
---|
1635 | // It's allowed to have multiple elements with the same name so it's not enough to
|
---|
1636 | // just check that element with the same name already present on the page. We also need to
|
---|
1637 | // check if element has tag attributes
|
---|
1638 | const elem = this.getTags(selector).filter(elem => this._containsAttributes(meta, elem))[0];
|
---|
1639 | if (elem !== undefined)
|
---|
1640 | return elem;
|
---|
1641 | }
|
---|
1642 | const element = this._dom.createElement('meta');
|
---|
1643 | this._setMetaElementAttributes(meta, element);
|
---|
1644 | const head = this._doc.getElementsByTagName('head')[0];
|
---|
1645 | head.appendChild(element);
|
---|
1646 | return element;
|
---|
1647 | }
|
---|
1648 | _setMetaElementAttributes(tag, el) {
|
---|
1649 | Object.keys(tag).forEach((prop) => el.setAttribute(this._getMetaKeyMap(prop), tag[prop]));
|
---|
1650 | return el;
|
---|
1651 | }
|
---|
1652 | _parseSelector(tag) {
|
---|
1653 | const attr = tag.name ? 'name' : 'property';
|
---|
1654 | return `${attr}="${tag[attr]}"`;
|
---|
1655 | }
|
---|
1656 | _containsAttributes(tag, elem) {
|
---|
1657 | return Object.keys(tag).every((key) => elem.getAttribute(this._getMetaKeyMap(key)) === tag[key]);
|
---|
1658 | }
|
---|
1659 | _getMetaKeyMap(prop) {
|
---|
1660 | return META_KEYS_MAP[prop] || prop;
|
---|
1661 | }
|
---|
1662 | }
|
---|
1663 | Meta.ɵprov = ɵɵdefineInjectable({ factory: createMeta, token: Meta, providedIn: "root" });
|
---|
1664 | Meta.decorators = [
|
---|
1665 | { type: Injectable, args: [{ providedIn: 'root', useFactory: createMeta, deps: [] },] }
|
---|
1666 | ];
|
---|
1667 | Meta.ctorParameters = () => [
|
---|
1668 | { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] }
|
---|
1669 | ];
|
---|
1670 | /**
|
---|
1671 | * Mapping for MetaDefinition properties with their correct meta attribute names
|
---|
1672 | */
|
---|
1673 | const META_KEYS_MAP = {
|
---|
1674 | httpEquiv: 'http-equiv'
|
---|
1675 | };
|
---|
1676 |
|
---|
1677 | /**
|
---|
1678 | * @license
|
---|
1679 | * Copyright Google LLC All Rights Reserved.
|
---|
1680 | *
|
---|
1681 | * Use of this source code is governed by an MIT-style license that can be
|
---|
1682 | * found in the LICENSE file at https://angular.io/license
|
---|
1683 | */
|
---|
1684 | /**
|
---|
1685 | * Factory to create Title service.
|
---|
1686 | */
|
---|
1687 | function createTitle() {
|
---|
1688 | return new Title(ɵɵinject(DOCUMENT));
|
---|
1689 | }
|
---|
1690 | /**
|
---|
1691 | * A service that can be used to get and set the title of a current HTML document.
|
---|
1692 | *
|
---|
1693 | * Since an Angular application can't be bootstrapped on the entire HTML document (`<html>` tag)
|
---|
1694 | * it is not possible to bind to the `text` property of the `HTMLTitleElement` elements
|
---|
1695 | * (representing the `<title>` tag). Instead, this service can be used to set and get the current
|
---|
1696 | * title value.
|
---|
1697 | *
|
---|
1698 | * @publicApi
|
---|
1699 | */
|
---|
1700 | class Title {
|
---|
1701 | constructor(_doc) {
|
---|
1702 | this._doc = _doc;
|
---|
1703 | }
|
---|
1704 | /**
|
---|
1705 | * Get the title of the current HTML document.
|
---|
1706 | */
|
---|
1707 | getTitle() {
|
---|
1708 | return this._doc.title;
|
---|
1709 | }
|
---|
1710 | /**
|
---|
1711 | * Set the title of the current HTML document.
|
---|
1712 | * @param newTitle
|
---|
1713 | */
|
---|
1714 | setTitle(newTitle) {
|
---|
1715 | this._doc.title = newTitle || '';
|
---|
1716 | }
|
---|
1717 | }
|
---|
1718 | Title.ɵprov = ɵɵdefineInjectable({ factory: createTitle, token: Title, providedIn: "root" });
|
---|
1719 | Title.decorators = [
|
---|
1720 | { type: Injectable, args: [{ providedIn: 'root', useFactory: createTitle, deps: [] },] }
|
---|
1721 | ];
|
---|
1722 | Title.ctorParameters = () => [
|
---|
1723 | { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] }
|
---|
1724 | ];
|
---|
1725 |
|
---|
1726 | /**
|
---|
1727 | * @license
|
---|
1728 | * Copyright Google LLC All Rights Reserved.
|
---|
1729 | *
|
---|
1730 | * Use of this source code is governed by an MIT-style license that can be
|
---|
1731 | * found in the LICENSE file at https://angular.io/license
|
---|
1732 | */
|
---|
1733 | const win = typeof window !== 'undefined' && window || {};
|
---|
1734 |
|
---|
1735 | /**
|
---|
1736 | * @license
|
---|
1737 | * Copyright Google LLC All Rights Reserved.
|
---|
1738 | *
|
---|
1739 | * Use of this source code is governed by an MIT-style license that can be
|
---|
1740 | * found in the LICENSE file at https://angular.io/license
|
---|
1741 | */
|
---|
1742 | class ChangeDetectionPerfRecord {
|
---|
1743 | constructor(msPerTick, numTicks) {
|
---|
1744 | this.msPerTick = msPerTick;
|
---|
1745 | this.numTicks = numTicks;
|
---|
1746 | }
|
---|
1747 | }
|
---|
1748 | /**
|
---|
1749 | * Entry point for all Angular profiling-related debug tools. This object
|
---|
1750 | * corresponds to the `ng.profiler` in the dev console.
|
---|
1751 | */
|
---|
1752 | class AngularProfiler {
|
---|
1753 | constructor(ref) {
|
---|
1754 | this.appRef = ref.injector.get(ApplicationRef);
|
---|
1755 | }
|
---|
1756 | // tslint:disable:no-console
|
---|
1757 | /**
|
---|
1758 | * Exercises change detection in a loop and then prints the average amount of
|
---|
1759 | * time in milliseconds how long a single round of change detection takes for
|
---|
1760 | * the current state of the UI. It runs a minimum of 5 rounds for a minimum
|
---|
1761 | * of 500 milliseconds.
|
---|
1762 | *
|
---|
1763 | * Optionally, a user may pass a `config` parameter containing a map of
|
---|
1764 | * options. Supported options are:
|
---|
1765 | *
|
---|
1766 | * `record` (boolean) - causes the profiler to record a CPU profile while
|
---|
1767 | * it exercises the change detector. Example:
|
---|
1768 | *
|
---|
1769 | * ```
|
---|
1770 | * ng.profiler.timeChangeDetection({record: true})
|
---|
1771 | * ```
|
---|
1772 | */
|
---|
1773 | timeChangeDetection(config) {
|
---|
1774 | const record = config && config['record'];
|
---|
1775 | const profileName = 'Change Detection';
|
---|
1776 | // Profiler is not available in Android browsers without dev tools opened
|
---|
1777 | const isProfilerAvailable = win.console.profile != null;
|
---|
1778 | if (record && isProfilerAvailable) {
|
---|
1779 | win.console.profile(profileName);
|
---|
1780 | }
|
---|
1781 | const start = performanceNow();
|
---|
1782 | let numTicks = 0;
|
---|
1783 | while (numTicks < 5 || (performanceNow() - start) < 500) {
|
---|
1784 | this.appRef.tick();
|
---|
1785 | numTicks++;
|
---|
1786 | }
|
---|
1787 | const end = performanceNow();
|
---|
1788 | if (record && isProfilerAvailable) {
|
---|
1789 | win.console.profileEnd(profileName);
|
---|
1790 | }
|
---|
1791 | const msPerTick = (end - start) / numTicks;
|
---|
1792 | win.console.log(`ran ${numTicks} change detection cycles`);
|
---|
1793 | win.console.log(`${msPerTick.toFixed(2)} ms per check`);
|
---|
1794 | return new ChangeDetectionPerfRecord(msPerTick, numTicks);
|
---|
1795 | }
|
---|
1796 | }
|
---|
1797 | function performanceNow() {
|
---|
1798 | return win.performance && win.performance.now ? win.performance.now() :
|
---|
1799 | new Date().getTime();
|
---|
1800 | }
|
---|
1801 |
|
---|
1802 | /**
|
---|
1803 | * @license
|
---|
1804 | * Copyright Google LLC All Rights Reserved.
|
---|
1805 | *
|
---|
1806 | * Use of this source code is governed by an MIT-style license that can be
|
---|
1807 | * found in the LICENSE file at https://angular.io/license
|
---|
1808 | */
|
---|
1809 | const PROFILER_GLOBAL_NAME = 'profiler';
|
---|
1810 | /**
|
---|
1811 | * Enabled Angular debug tools that are accessible via your browser's
|
---|
1812 | * developer console.
|
---|
1813 | *
|
---|
1814 | * Usage:
|
---|
1815 | *
|
---|
1816 | * 1. Open developer console (e.g. in Chrome Ctrl + Shift + j)
|
---|
1817 | * 1. Type `ng.` (usually the console will show auto-complete suggestion)
|
---|
1818 | * 1. Try the change detection profiler `ng.profiler.timeChangeDetection()`
|
---|
1819 | * then hit Enter.
|
---|
1820 | *
|
---|
1821 | * @publicApi
|
---|
1822 | */
|
---|
1823 | function enableDebugTools(ref) {
|
---|
1824 | exportNgVar(PROFILER_GLOBAL_NAME, new AngularProfiler(ref));
|
---|
1825 | return ref;
|
---|
1826 | }
|
---|
1827 | /**
|
---|
1828 | * Disables Angular tools.
|
---|
1829 | *
|
---|
1830 | * @publicApi
|
---|
1831 | */
|
---|
1832 | function disableDebugTools() {
|
---|
1833 | exportNgVar(PROFILER_GLOBAL_NAME, null);
|
---|
1834 | }
|
---|
1835 |
|
---|
1836 | /**
|
---|
1837 | * @license
|
---|
1838 | * Copyright Google LLC All Rights Reserved.
|
---|
1839 | *
|
---|
1840 | * Use of this source code is governed by an MIT-style license that can be
|
---|
1841 | * found in the LICENSE file at https://angular.io/license
|
---|
1842 | */
|
---|
1843 | function escapeHtml(text) {
|
---|
1844 | const escapedText = {
|
---|
1845 | '&': '&a;',
|
---|
1846 | '"': '&q;',
|
---|
1847 | '\'': '&s;',
|
---|
1848 | '<': '&l;',
|
---|
1849 | '>': '&g;',
|
---|
1850 | };
|
---|
1851 | return text.replace(/[&"'<>]/g, s => escapedText[s]);
|
---|
1852 | }
|
---|
1853 | function unescapeHtml(text) {
|
---|
1854 | const unescapedText = {
|
---|
1855 | '&a;': '&',
|
---|
1856 | '&q;': '"',
|
---|
1857 | '&s;': '\'',
|
---|
1858 | '&l;': '<',
|
---|
1859 | '&g;': '>',
|
---|
1860 | };
|
---|
1861 | return text.replace(/&[^;]+;/g, s => unescapedText[s]);
|
---|
1862 | }
|
---|
1863 | /**
|
---|
1864 | * Create a `StateKey<T>` that can be used to store value of type T with `TransferState`.
|
---|
1865 | *
|
---|
1866 | * Example:
|
---|
1867 | *
|
---|
1868 | * ```
|
---|
1869 | * const COUNTER_KEY = makeStateKey<number>('counter');
|
---|
1870 | * let value = 10;
|
---|
1871 | *
|
---|
1872 | * transferState.set(COUNTER_KEY, value);
|
---|
1873 | * ```
|
---|
1874 | *
|
---|
1875 | * @publicApi
|
---|
1876 | */
|
---|
1877 | function makeStateKey(key) {
|
---|
1878 | return key;
|
---|
1879 | }
|
---|
1880 | /**
|
---|
1881 | * A key value store that is transferred from the application on the server side to the application
|
---|
1882 | * on the client side.
|
---|
1883 | *
|
---|
1884 | * `TransferState` will be available as an injectable token. To use it import
|
---|
1885 | * `ServerTransferStateModule` on the server and `BrowserTransferStateModule` on the client.
|
---|
1886 | *
|
---|
1887 | * The values in the store are serialized/deserialized using JSON.stringify/JSON.parse. So only
|
---|
1888 | * boolean, number, string, null and non-class objects will be serialized and deserialized in a
|
---|
1889 | * non-lossy manner.
|
---|
1890 | *
|
---|
1891 | * @publicApi
|
---|
1892 | */
|
---|
1893 | class TransferState {
|
---|
1894 | constructor() {
|
---|
1895 | this.store = {};
|
---|
1896 | this.onSerializeCallbacks = {};
|
---|
1897 | }
|
---|
1898 | /** @internal */
|
---|
1899 | static init(initState) {
|
---|
1900 | const transferState = new TransferState();
|
---|
1901 | transferState.store = initState;
|
---|
1902 | return transferState;
|
---|
1903 | }
|
---|
1904 | /**
|
---|
1905 | * Get the value corresponding to a key. Return `defaultValue` if key is not found.
|
---|
1906 | */
|
---|
1907 | get(key, defaultValue) {
|
---|
1908 | return this.store[key] !== undefined ? this.store[key] : defaultValue;
|
---|
1909 | }
|
---|
1910 | /**
|
---|
1911 | * Set the value corresponding to a key.
|
---|
1912 | */
|
---|
1913 | set(key, value) {
|
---|
1914 | this.store[key] = value;
|
---|
1915 | }
|
---|
1916 | /**
|
---|
1917 | * Remove a key from the store.
|
---|
1918 | */
|
---|
1919 | remove(key) {
|
---|
1920 | delete this.store[key];
|
---|
1921 | }
|
---|
1922 | /**
|
---|
1923 | * Test whether a key exists in the store.
|
---|
1924 | */
|
---|
1925 | hasKey(key) {
|
---|
1926 | return this.store.hasOwnProperty(key);
|
---|
1927 | }
|
---|
1928 | /**
|
---|
1929 | * Register a callback to provide the value for a key when `toJson` is called.
|
---|
1930 | */
|
---|
1931 | onSerialize(key, callback) {
|
---|
1932 | this.onSerializeCallbacks[key] = callback;
|
---|
1933 | }
|
---|
1934 | /**
|
---|
1935 | * Serialize the current state of the store to JSON.
|
---|
1936 | */
|
---|
1937 | toJson() {
|
---|
1938 | // Call the onSerialize callbacks and put those values into the store.
|
---|
1939 | for (const key in this.onSerializeCallbacks) {
|
---|
1940 | if (this.onSerializeCallbacks.hasOwnProperty(key)) {
|
---|
1941 | try {
|
---|
1942 | this.store[key] = this.onSerializeCallbacks[key]();
|
---|
1943 | }
|
---|
1944 | catch (e) {
|
---|
1945 | console.warn('Exception in onSerialize callback: ', e);
|
---|
1946 | }
|
---|
1947 | }
|
---|
1948 | }
|
---|
1949 | return JSON.stringify(this.store);
|
---|
1950 | }
|
---|
1951 | }
|
---|
1952 | TransferState.decorators = [
|
---|
1953 | { type: Injectable }
|
---|
1954 | ];
|
---|
1955 | function initTransferState(doc, appId) {
|
---|
1956 | // Locate the script tag with the JSON data transferred from the server.
|
---|
1957 | // The id of the script tag is set to the Angular appId + 'state'.
|
---|
1958 | const script = doc.getElementById(appId + '-state');
|
---|
1959 | let initialState = {};
|
---|
1960 | if (script && script.textContent) {
|
---|
1961 | try {
|
---|
1962 | // Avoid using any here as it triggers lint errors in google3 (any is not allowed).
|
---|
1963 | initialState = JSON.parse(unescapeHtml(script.textContent));
|
---|
1964 | }
|
---|
1965 | catch (e) {
|
---|
1966 | console.warn('Exception while restoring TransferState for app ' + appId, e);
|
---|
1967 | }
|
---|
1968 | }
|
---|
1969 | return TransferState.init(initialState);
|
---|
1970 | }
|
---|
1971 | /**
|
---|
1972 | * NgModule to install on the client side while using the `TransferState` to transfer state from
|
---|
1973 | * server to client.
|
---|
1974 | *
|
---|
1975 | * @publicApi
|
---|
1976 | */
|
---|
1977 | class BrowserTransferStateModule {
|
---|
1978 | }
|
---|
1979 | BrowserTransferStateModule.decorators = [
|
---|
1980 | { type: NgModule, args: [{
|
---|
1981 | providers: [{ provide: TransferState, useFactory: initTransferState, deps: [DOCUMENT, APP_ID] }],
|
---|
1982 | },] }
|
---|
1983 | ];
|
---|
1984 |
|
---|
1985 | /**
|
---|
1986 | * @license
|
---|
1987 | * Copyright Google LLC All Rights Reserved.
|
---|
1988 | *
|
---|
1989 | * Use of this source code is governed by an MIT-style license that can be
|
---|
1990 | * found in the LICENSE file at https://angular.io/license
|
---|
1991 | */
|
---|
1992 | /**
|
---|
1993 | * Predicates for use with {@link DebugElement}'s query functions.
|
---|
1994 | *
|
---|
1995 | * @publicApi
|
---|
1996 | */
|
---|
1997 | class By {
|
---|
1998 | /**
|
---|
1999 | * Match all nodes.
|
---|
2000 | *
|
---|
2001 | * @usageNotes
|
---|
2002 | * ### Example
|
---|
2003 | *
|
---|
2004 | * {@example platform-browser/dom/debug/ts/by/by.ts region='by_all'}
|
---|
2005 | */
|
---|
2006 | static all() {
|
---|
2007 | return () => true;
|
---|
2008 | }
|
---|
2009 | /**
|
---|
2010 | * Match elements by the given CSS selector.
|
---|
2011 | *
|
---|
2012 | * @usageNotes
|
---|
2013 | * ### Example
|
---|
2014 | *
|
---|
2015 | * {@example platform-browser/dom/debug/ts/by/by.ts region='by_css'}
|
---|
2016 | */
|
---|
2017 | static css(selector) {
|
---|
2018 | return (debugElement) => {
|
---|
2019 | return debugElement.nativeElement != null ?
|
---|
2020 | elementMatches(debugElement.nativeElement, selector) :
|
---|
2021 | false;
|
---|
2022 | };
|
---|
2023 | }
|
---|
2024 | /**
|
---|
2025 | * Match nodes that have the given directive present.
|
---|
2026 | *
|
---|
2027 | * @usageNotes
|
---|
2028 | * ### Example
|
---|
2029 | *
|
---|
2030 | * {@example platform-browser/dom/debug/ts/by/by.ts region='by_directive'}
|
---|
2031 | */
|
---|
2032 | static directive(type) {
|
---|
2033 | return (debugNode) => debugNode.providerTokens.indexOf(type) !== -1;
|
---|
2034 | }
|
---|
2035 | }
|
---|
2036 | function elementMatches(n, selector) {
|
---|
2037 | if (ɵgetDOM().isElementNode(n)) {
|
---|
2038 | return n.matches && n.matches(selector) ||
|
---|
2039 | n.msMatchesSelector && n.msMatchesSelector(selector) ||
|
---|
2040 | n.webkitMatchesSelector && n.webkitMatchesSelector(selector);
|
---|
2041 | }
|
---|
2042 | return false;
|
---|
2043 | }
|
---|
2044 |
|
---|
2045 | /**
|
---|
2046 | * @license
|
---|
2047 | * Copyright Google LLC All Rights Reserved.
|
---|
2048 | *
|
---|
2049 | * Use of this source code is governed by an MIT-style license that can be
|
---|
2050 | * found in the LICENSE file at https://angular.io/license
|
---|
2051 | */
|
---|
2052 |
|
---|
2053 | /**
|
---|
2054 | * @license
|
---|
2055 | * Copyright Google LLC All Rights Reserved.
|
---|
2056 | *
|
---|
2057 | * Use of this source code is governed by an MIT-style license that can be
|
---|
2058 | * found in the LICENSE file at https://angular.io/license
|
---|
2059 | */
|
---|
2060 | /**
|
---|
2061 | * @publicApi
|
---|
2062 | */
|
---|
2063 | const VERSION = new Version('12.2.9');
|
---|
2064 |
|
---|
2065 | /**
|
---|
2066 | * @license
|
---|
2067 | * Copyright Google LLC All Rights Reserved.
|
---|
2068 | *
|
---|
2069 | * Use of this source code is governed by an MIT-style license that can be
|
---|
2070 | * found in the LICENSE file at https://angular.io/license
|
---|
2071 | */
|
---|
2072 |
|
---|
2073 | /**
|
---|
2074 | * @license
|
---|
2075 | * Copyright Google LLC All Rights Reserved.
|
---|
2076 | *
|
---|
2077 | * Use of this source code is governed by an MIT-style license that can be
|
---|
2078 | * found in the LICENSE file at https://angular.io/license
|
---|
2079 | */
|
---|
2080 | // This file only reexports content of the `src` folder. Keep it that way.
|
---|
2081 |
|
---|
2082 | /**
|
---|
2083 | * @license
|
---|
2084 | * Copyright Google LLC All Rights Reserved.
|
---|
2085 | *
|
---|
2086 | * Use of this source code is governed by an MIT-style license that can be
|
---|
2087 | * found in the LICENSE file at https://angular.io/license
|
---|
2088 | */
|
---|
2089 |
|
---|
2090 | /**
|
---|
2091 | * Generated bundle index. Do not edit.
|
---|
2092 | */
|
---|
2093 |
|
---|
2094 | export { BrowserModule, BrowserTransferStateModule, By, DomSanitizer, EVENT_MANAGER_PLUGINS, EventManager, HAMMER_GESTURE_CONFIG, HAMMER_LOADER, HammerGestureConfig, HammerModule, Meta, Title, TransferState, VERSION, disableDebugTools, enableDebugTools, makeStateKey, platformBrowser, BROWSER_SANITIZATION_PROVIDERS as ɵBROWSER_SANITIZATION_PROVIDERS, BROWSER_SANITIZATION_PROVIDERS__POST_R3__ as ɵBROWSER_SANITIZATION_PROVIDERS__POST_R3__, BrowserDomAdapter as ɵBrowserDomAdapter, BrowserGetTestability as ɵBrowserGetTestability, DomEventsPlugin as ɵDomEventsPlugin, DomRendererFactory2 as ɵDomRendererFactory2, DomSanitizerImpl as ɵDomSanitizerImpl, DomSharedStylesHost as ɵDomSharedStylesHost, ELEMENT_PROBE_PROVIDERS as ɵELEMENT_PROBE_PROVIDERS, ELEMENT_PROBE_PROVIDERS__POST_R3__ as ɵELEMENT_PROBE_PROVIDERS__POST_R3__, HAMMER_PROVIDERS__POST_R3__ as ɵHAMMER_PROVIDERS__POST_R3__, HammerGesturesPlugin as ɵHammerGesturesPlugin, INTERNAL_BROWSER_PLATFORM_PROVIDERS as ɵINTERNAL_BROWSER_PLATFORM_PROVIDERS, KeyEventsPlugin as ɵKeyEventsPlugin, NAMESPACE_URIS as ɵNAMESPACE_URIS, SharedStylesHost as ɵSharedStylesHost, TRANSITION_ID as ɵTRANSITION_ID, errorHandler as ɵangular_packages_platform_browser_platform_browser_a, _document as ɵangular_packages_platform_browser_platform_browser_b, BROWSER_MODULE_PROVIDERS as ɵangular_packages_platform_browser_platform_browser_c, createMeta as ɵangular_packages_platform_browser_platform_browser_d, createTitle as ɵangular_packages_platform_browser_platform_browser_e, initTransferState as ɵangular_packages_platform_browser_platform_browser_f, EventManagerPlugin as ɵangular_packages_platform_browser_platform_browser_g, HAMMER_PROVIDERS__PRE_R3__ as ɵangular_packages_platform_browser_platform_browser_h, HAMMER_PROVIDERS as ɵangular_packages_platform_browser_platform_browser_i, domSanitizerImplFactory as ɵangular_packages_platform_browser_platform_browser_j, appInitializerFactory as ɵangular_packages_platform_browser_platform_browser_k, SERVER_TRANSITION_PROVIDERS as ɵangular_packages_platform_browser_platform_browser_l, _createNgProbeR2 as ɵangular_packages_platform_browser_platform_browser_m, ELEMENT_PROBE_PROVIDERS__PRE_R3__ as ɵangular_packages_platform_browser_platform_browser_n, BrowserXhr as ɵangular_packages_platform_browser_platform_browser_o, GenericBrowserDomAdapter as ɵangular_packages_platform_browser_platform_browser_p, escapeHtml as ɵescapeHtml, flattenStyles as ɵflattenStyles, initDomAdapter as ɵinitDomAdapter, shimContentAttribute as ɵshimContentAttribute, shimHostAttribute as ɵshimHostAttribute };
|
---|
2095 | //# sourceMappingURL=platform-browser.js.map
|
---|