UNPKG

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