UNPKG

9.55 kBJavaScriptView Raw
1/**
2 * @license Angular v10.0.1
3 * (c) 2010-2020 Google LLC. https://angular.io/
4 * License: MIT
5 */
6
7import { ɵglobal, NgZone, PLATFORM_INITIALIZER, createPlatformFactory, platformCore, NgModule, APP_ID } from '@angular/core';
8import { ɵBrowserDomAdapter, BrowserModule, ɵELEMENT_PROBE_PROVIDERS } from '@angular/platform-browser';
9import { ɵgetDOM } from '@angular/common';
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 */
18class BrowserDetection {
19 constructor(ua) {
20 this._overrideUa = ua;
21 }
22 get _ua() {
23 if (typeof this._overrideUa === 'string') {
24 return this._overrideUa;
25 }
26 return ɵgetDOM() ? ɵgetDOM().getUserAgent() : '';
27 }
28 static setup() {
29 return new BrowserDetection(null);
30 }
31 get isFirefox() {
32 return this._ua.indexOf('Firefox') > -1;
33 }
34 get isAndroid() {
35 return this._ua.indexOf('Mozilla/5.0') > -1 && this._ua.indexOf('Android') > -1 &&
36 this._ua.indexOf('AppleWebKit') > -1 && this._ua.indexOf('Chrome') == -1 &&
37 this._ua.indexOf('IEMobile') == -1;
38 }
39 get isEdge() {
40 return this._ua.indexOf('Edge') > -1;
41 }
42 get isIE() {
43 return this._ua.indexOf('Trident') > -1;
44 }
45 get isWebkit() {
46 return this._ua.indexOf('AppleWebKit') > -1 && this._ua.indexOf('Edge') == -1 &&
47 this._ua.indexOf('IEMobile') == -1;
48 }
49 get isIOS7() {
50 return (this._ua.indexOf('iPhone OS 7') > -1 || this._ua.indexOf('iPad OS 7') > -1) &&
51 this._ua.indexOf('IEMobile') == -1;
52 }
53 get isSlow() {
54 return this.isAndroid || this.isIE || this.isIOS7;
55 }
56 // The Intl API is only natively supported in Chrome, Firefox, IE11 and Edge.
57 // This detector is needed in tests to make the difference between:
58 // 1) IE11/Edge: they have a native Intl API, but with some discrepancies
59 // 2) IE9/IE10: they use the polyfill, and so no discrepancies
60 get supportsNativeIntlApi() {
61 return !!ɵglobal.Intl && ɵglobal.Intl !== ɵglobal.IntlPolyfill;
62 }
63 get isChromeDesktop() {
64 return this._ua.indexOf('Chrome') > -1 && this._ua.indexOf('Mobile Safari') == -1 &&
65 this._ua.indexOf('Edge') == -1;
66 }
67 // "Old Chrome" means Chrome 3X, where there are some discrepancies in the Intl API.
68 // Android 4.4 and 5.X have such browsers by default (respectively 30 and 39).
69 get isOldChrome() {
70 return this._ua.indexOf('Chrome') > -1 && this._ua.indexOf('Chrome/3') > -1 &&
71 this._ua.indexOf('Edge') == -1;
72 }
73 get supportsCustomElements() {
74 return (typeof ɵglobal.customElements !== 'undefined');
75 }
76 get supportsDeprecatedCustomCustomElementsV0() {
77 return (typeof document.registerElement !== 'undefined');
78 }
79 get supportsRegExUnicodeFlag() {
80 return RegExp.prototype.hasOwnProperty('unicode');
81 }
82 get supportsShadowDom() {
83 const testEl = document.createElement('div');
84 return (typeof testEl.attachShadow !== 'undefined');
85 }
86 get supportsDeprecatedShadowDomV0() {
87 const testEl = document.createElement('div');
88 return (typeof testEl.createShadowRoot !== 'undefined');
89 }
90}
91const browserDetection = BrowserDetection.setup();
92function dispatchEvent(element, eventType) {
93 const evt = ɵgetDOM().getDefaultDocument().createEvent('Event');
94 evt.initEvent(eventType, true, true);
95 ɵgetDOM().dispatchEvent(element, evt);
96}
97function createMouseEvent(eventType) {
98 const evt = ɵgetDOM().getDefaultDocument().createEvent('MouseEvent');
99 evt.initEvent(eventType, true, true);
100 return evt;
101}
102function el(html) {
103 return getContent(createTemplate(html)).firstChild;
104}
105function normalizeCSS(css) {
106 return css.replace(/\s+/g, ' ')
107 .replace(/:\s/g, ':')
108 .replace(/'/g, '"')
109 .replace(/ }/g, '}')
110 .replace(/url\((\"|\s)(.+)(\"|\s)\)(\s*)/g, (...match) => `url("${match[2]}")`)
111 .replace(/\[(.+)=([^"\]]+)\]/g, (...match) => `[${match[1]}="${match[2]}"]`);
112}
113function getAttributeMap(element) {
114 const res = new Map();
115 const elAttrs = element.attributes;
116 for (let i = 0; i < elAttrs.length; i++) {
117 const attrib = elAttrs.item(i);
118 res.set(attrib.name, attrib.value);
119 }
120 return res;
121}
122const _selfClosingTags = ['br', 'hr', 'input'];
123function stringifyElement(el /** TODO #9100 */) {
124 let result = '';
125 if (ɵgetDOM().isElementNode(el)) {
126 const tagName = el.tagName.toLowerCase();
127 // Opening tag
128 result += `<${tagName}`;
129 // Attributes in an ordered way
130 const attributeMap = getAttributeMap(el);
131 const sortedKeys = Array.from(attributeMap.keys()).sort();
132 for (const key of sortedKeys) {
133 const lowerCaseKey = key.toLowerCase();
134 let attValue = attributeMap.get(key);
135 if (typeof attValue !== 'string') {
136 result += ` ${lowerCaseKey}`;
137 }
138 else {
139 // Browsers order style rules differently. Order them alphabetically for consistency.
140 if (lowerCaseKey === 'style') {
141 attValue = attValue.split(/; ?/).filter(s => !!s).sort().map(s => `${s};`).join(' ');
142 }
143 result += ` ${lowerCaseKey}="${attValue}"`;
144 }
145 }
146 result += '>';
147 // Children
148 const childrenRoot = templateAwareRoot(el);
149 const children = childrenRoot ? childrenRoot.childNodes : [];
150 for (let j = 0; j < children.length; j++) {
151 result += stringifyElement(children[j]);
152 }
153 // Closing tag
154 if (_selfClosingTags.indexOf(tagName) == -1) {
155 result += `</${tagName}>`;
156 }
157 }
158 else if (isCommentNode(el)) {
159 result += `<!--${el.nodeValue}-->`;
160 }
161 else {
162 result += el.textContent;
163 }
164 return result;
165}
166function createNgZone() {
167 return new NgZone({ enableLongStackTrace: true, shouldCoalesceEventChangeDetection: false });
168}
169function isCommentNode(node) {
170 return node.nodeType === Node.COMMENT_NODE;
171}
172function isTextNode(node) {
173 return node.nodeType === Node.TEXT_NODE;
174}
175function getContent(node) {
176 if ('content' in node) {
177 return node.content;
178 }
179 else {
180 return node;
181 }
182}
183function templateAwareRoot(el) {
184 return ɵgetDOM().isElementNode(el) && el.nodeName === 'TEMPLATE' ? getContent(el) : el;
185}
186function setCookie(name, value) {
187 // document.cookie is magical, assigning into it assigns/overrides one cookie value, but does
188 // not clear other cookies.
189 document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value);
190}
191function supportsWebAnimation() {
192 return typeof Element.prototype['animate'] === 'function';
193}
194function hasStyle(element, styleName, styleValue) {
195 const value = element.style[styleName] || '';
196 return styleValue ? value == styleValue : value.length > 0;
197}
198function hasClass(element, className) {
199 return element.classList.contains(className);
200}
201function sortedClassList(element) {
202 return Array.prototype.slice.call(element.classList, 0).sort();
203}
204function createTemplate(html) {
205 const t = ɵgetDOM().getDefaultDocument().createElement('template');
206 t.innerHTML = html;
207 return t;
208}
209function childNodesAsList(el) {
210 const childNodes = el.childNodes;
211 const res = [];
212 for (let i = 0; i < childNodes.length; i++) {
213 res[i] = childNodes[i];
214 }
215 return res;
216}
217
218/**
219 * @license
220 * Copyright Google LLC All Rights Reserved.
221 *
222 * Use of this source code is governed by an MIT-style license that can be
223 * found in the LICENSE file at https://angular.io/license
224 */
225function initBrowserTests() {
226 ɵBrowserDomAdapter.makeCurrent();
227 BrowserDetection.setup();
228}
229const _TEST_BROWSER_PLATFORM_PROVIDERS = [{ provide: PLATFORM_INITIALIZER, useValue: initBrowserTests, multi: true }];
230/**
231 * Platform for testing
232 *
233 * @publicApi
234 */
235const platformBrowserTesting = createPlatformFactory(platformCore, 'browserTesting', _TEST_BROWSER_PLATFORM_PROVIDERS);
236const ɵ0 = createNgZone;
237/**
238 * NgModule for testing.
239 *
240 * @publicApi
241 */
242class BrowserTestingModule {
243}
244BrowserTestingModule.decorators = [
245 { type: NgModule, args: [{
246 exports: [BrowserModule],
247 providers: [
248 { provide: APP_ID, useValue: 'a' },
249 ɵELEMENT_PROBE_PROVIDERS,
250 { provide: NgZone, useFactory: ɵ0 },
251 ]
252 },] }
253];
254
255/**
256 * @license
257 * Copyright Google LLC All Rights Reserved.
258 *
259 * Use of this source code is governed by an MIT-style license that can be
260 * found in the LICENSE file at https://angular.io/license
261 */
262
263/**
264 * @license
265 * Copyright Google LLC All Rights Reserved.
266 *
267 * Use of this source code is governed by an MIT-style license that can be
268 * found in the LICENSE file at https://angular.io/license
269 */
270
271/**
272 * @license
273 * Copyright Google LLC All Rights Reserved.
274 *
275 * Use of this source code is governed by an MIT-style license that can be
276 * found in the LICENSE file at https://angular.io/license
277 */
278
279/**
280 * Generated bundle index. Do not edit.
281 */
282
283export { BrowserTestingModule, platformBrowserTesting, ɵ0, createNgZone as ɵangular_packages_platform_browser_testing_testing_a };
284//# sourceMappingURL=testing.js.map