UNPKG

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