1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import { ɵglobal, NgZone, PLATFORM_INITIALIZER, createPlatformFactory, platformCore, NgModule, APP_ID } from '@angular/core';
|
8 | import { ɵBrowserDomAdapter, BrowserModule, ɵELEMENT_PROBE_PROVIDERS } from '@angular/platform-browser';
|
9 | import { ɵgetDOM } from '@angular/common';
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | class BrowserDetection {
|
17 | |
18 |
|
19 |
|
20 | constructor(ua) {
|
21 | this._overrideUa = ua;
|
22 | }
|
23 | |
24 |
|
25 |
|
26 |
|
27 | get _ua() {
|
28 | if (typeof this._overrideUa === 'string') {
|
29 | return this._overrideUa;
|
30 | }
|
31 | return ɵgetDOM() ? ɵgetDOM().getUserAgent() : '';
|
32 | }
|
33 | |
34 |
|
35 |
|
36 | static setup() {
|
37 | return new BrowserDetection(null);
|
38 | }
|
39 | |
40 |
|
41 |
|
42 | get isFirefox() {
|
43 | return this._ua.indexOf('Firefox') > -1;
|
44 | }
|
45 | |
46 |
|
47 |
|
48 | get isAndroid() {
|
49 | return this._ua.indexOf('Mozilla/5.0') > -1 && this._ua.indexOf('Android') > -1 &&
|
50 | this._ua.indexOf('AppleWebKit') > -1 && this._ua.indexOf('Chrome') == -1 &&
|
51 | this._ua.indexOf('IEMobile') == -1;
|
52 | }
|
53 | |
54 |
|
55 |
|
56 | get isEdge() {
|
57 | return this._ua.indexOf('Edge') > -1;
|
58 | }
|
59 | |
60 |
|
61 |
|
62 | get isIE() {
|
63 | return this._ua.indexOf('Trident') > -1;
|
64 | }
|
65 | |
66 |
|
67 |
|
68 | get isWebkit() {
|
69 | return this._ua.indexOf('AppleWebKit') > -1 && this._ua.indexOf('Edge') == -1 &&
|
70 | this._ua.indexOf('IEMobile') == -1;
|
71 | }
|
72 | |
73 |
|
74 |
|
75 | get isIOS7() {
|
76 | return (this._ua.indexOf('iPhone OS 7') > -1 || this._ua.indexOf('iPad OS 7') > -1) &&
|
77 | this._ua.indexOf('IEMobile') == -1;
|
78 | }
|
79 | |
80 |
|
81 |
|
82 | get isSlow() {
|
83 | return this.isAndroid || this.isIE || this.isIOS7;
|
84 | }
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | |
90 |
|
91 |
|
92 | get supportsNativeIntlApi() {
|
93 | return !!(( (ɵglobal))).Intl && (( (ɵglobal))).Intl !== (( (ɵglobal))).IntlPolyfill;
|
94 | }
|
95 | |
96 |
|
97 |
|
98 | get isChromeDesktop() {
|
99 | return this._ua.indexOf('Chrome') > -1 && this._ua.indexOf('Mobile Safari') == -1 &&
|
100 | this._ua.indexOf('Edge') == -1;
|
101 | }
|
102 |
|
103 |
|
104 | |
105 |
|
106 |
|
107 | get isOldChrome() {
|
108 | return this._ua.indexOf('Chrome') > -1 && this._ua.indexOf('Chrome/3') > -1 &&
|
109 | this._ua.indexOf('Edge') == -1;
|
110 | }
|
111 | |
112 |
|
113 |
|
114 | get supportsCustomElements() {
|
115 | return (typeof (( (ɵglobal))).customElements !== 'undefined');
|
116 | }
|
117 | |
118 |
|
119 |
|
120 | get supportsDeprecatedCustomCustomElementsV0() {
|
121 | return (typeof (( (document))).registerElement !== 'undefined');
|
122 | }
|
123 | |
124 |
|
125 |
|
126 | get supportsRegExUnicodeFlag() {
|
127 | return RegExp.prototype.hasOwnProperty('unicode');
|
128 | }
|
129 | |
130 |
|
131 |
|
132 | get supportsShadowDom() {
|
133 |
|
134 | const testEl = document.createElement('div');
|
135 | return (typeof testEl.attachShadow !== 'undefined');
|
136 | }
|
137 | |
138 |
|
139 |
|
140 | get supportsDeprecatedShadowDomV0() {
|
141 |
|
142 | const testEl = ( (document.createElement('div')));
|
143 | return (typeof testEl.createShadowRoot !== 'undefined');
|
144 | }
|
145 | }
|
146 | if (false) {
|
147 | |
148 |
|
149 |
|
150 |
|
151 | BrowserDetection.prototype._overrideUa;
|
152 | }
|
153 |
|
154 | const browserDetection = BrowserDetection.setup();
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 | function dispatchEvent(element, eventType) {
|
161 |
|
162 | const evt = ɵgetDOM().getDefaultDocument().createEvent('Event');
|
163 | evt.initEvent(eventType, true, true);
|
164 | ɵgetDOM().dispatchEvent(element, evt);
|
165 | }
|
166 |
|
167 |
|
168 |
|
169 |
|
170 | function createMouseEvent(eventType) {
|
171 |
|
172 | const evt = ɵgetDOM().getDefaultDocument().createEvent('MouseEvent');
|
173 | evt.initEvent(eventType, true, true);
|
174 | return evt;
|
175 | }
|
176 |
|
177 |
|
178 |
|
179 |
|
180 | function el(html) {
|
181 | return ( (getContent(createTemplate(html)).firstChild));
|
182 | }
|
183 |
|
184 |
|
185 |
|
186 |
|
187 | function normalizeCSS(css) {
|
188 | return css.replace(/\s+/g, ' ')
|
189 | .replace(/:\s/g, ':')
|
190 | .replace(/'/g, '"')
|
191 | .replace(/ }/g, '}')
|
192 | .replace(/url\((\"|\s)(.+)(\"|\s)\)(\s*)/g, ( |
193 |
|
194 |
|
195 |
|
196 | (...match) => `url("${match[2]}")`))
|
197 | .replace(/\[(.+)=([^"\]]+)\]/g, ( |
198 |
|
199 |
|
200 |
|
201 | (...match) => `[${match[1]}="${match[2]}"]`));
|
202 | }
|
203 |
|
204 |
|
205 |
|
206 |
|
207 | function getAttributeMap(element) {
|
208 |
|
209 | const res = new Map();
|
210 |
|
211 | const elAttrs = element.attributes;
|
212 | for (let i = 0; i < elAttrs.length; i++) {
|
213 |
|
214 | const attrib = elAttrs.item(i);
|
215 | res.set(attrib.name, attrib.value);
|
216 | }
|
217 | return res;
|
218 | }
|
219 |
|
220 | const _selfClosingTags = ['br', 'hr', 'input'];
|
221 |
|
222 |
|
223 |
|
224 |
|
225 | function stringifyElement(el /** TODO #9100 */) {
|
226 |
|
227 | let result = '';
|
228 | if (ɵgetDOM().isElementNode(el)) {
|
229 |
|
230 | const tagName = el.tagName.toLowerCase();
|
231 |
|
232 | result += `<${tagName}`;
|
233 |
|
234 |
|
235 | const attributeMap = getAttributeMap(el);
|
236 |
|
237 | const sortedKeys = Array.from(attributeMap.keys()).sort();
|
238 | for (const key of sortedKeys) {
|
239 |
|
240 | const lowerCaseKey = key.toLowerCase();
|
241 |
|
242 | let attValue = attributeMap.get(key);
|
243 | if (typeof attValue !== 'string') {
|
244 | result += ` ${lowerCaseKey}`;
|
245 | }
|
246 | else {
|
247 |
|
248 | if (lowerCaseKey === 'style') {
|
249 | attValue = attValue.split(/; ?/).filter(( |
250 |
|
251 |
|
252 |
|
253 | s => !!s)).sort().map(( |
254 |
|
255 |
|
256 |
|
257 | s => `${s};`)).join(' ');
|
258 | }
|
259 | result += ` ${lowerCaseKey}="${attValue}"`;
|
260 | }
|
261 | }
|
262 | result += '>';
|
263 |
|
264 |
|
265 | const childrenRoot = templateAwareRoot(el);
|
266 |
|
267 | const children = childrenRoot ? childrenRoot.childNodes : [];
|
268 | for (let j = 0; j < children.length; j++) {
|
269 | result += stringifyElement(children[j]);
|
270 | }
|
271 |
|
272 | if (_selfClosingTags.indexOf(tagName) == -1) {
|
273 | result += `</${tagName}>`;
|
274 | }
|
275 | }
|
276 | else if (isCommentNode(el)) {
|
277 | result += `<!--${el.nodeValue}-->`;
|
278 | }
|
279 | else {
|
280 | result += el.textContent;
|
281 | }
|
282 | return result;
|
283 | }
|
284 |
|
285 |
|
286 |
|
287 | function createNgZone() {
|
288 | return new NgZone({ enableLongStackTrace: true, shouldCoalesceEventChangeDetection: false });
|
289 | }
|
290 |
|
291 |
|
292 |
|
293 |
|
294 | function isCommentNode(node) {
|
295 | return node.nodeType === Node.COMMENT_NODE;
|
296 | }
|
297 |
|
298 |
|
299 |
|
300 |
|
301 | function isTextNode(node) {
|
302 | return node.nodeType === Node.TEXT_NODE;
|
303 | }
|
304 |
|
305 |
|
306 |
|
307 |
|
308 | function getContent(node) {
|
309 | if ('content' in node) {
|
310 | return (( (node))).content;
|
311 | }
|
312 | else {
|
313 | return node;
|
314 | }
|
315 | }
|
316 |
|
317 |
|
318 |
|
319 |
|
320 | function templateAwareRoot(el) {
|
321 | return ɵgetDOM().isElementNode(el) && el.nodeName === 'TEMPLATE' ? getContent(el) : el;
|
322 | }
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 | function setCookie(name, value) {
|
329 |
|
330 |
|
331 | document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value);
|
332 | }
|
333 |
|
334 |
|
335 |
|
336 | function supportsWebAnimation() {
|
337 | return typeof (( (Element))).prototype['animate'] === 'function';
|
338 | }
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 | function hasStyle(element, styleName, styleValue) {
|
346 |
|
347 | const value = element.style[styleName] || '';
|
348 | return styleValue ? value == styleValue : value.length > 0;
|
349 | }
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 | function hasClass(element, className) {
|
356 | return element.classList.contains(className);
|
357 | }
|
358 |
|
359 |
|
360 |
|
361 |
|
362 | function sortedClassList(element) {
|
363 | return Array.prototype.slice.call(element.classList, 0).sort();
|
364 | }
|
365 |
|
366 |
|
367 |
|
368 |
|
369 | function createTemplate(html) {
|
370 |
|
371 | const t = ɵgetDOM().getDefaultDocument().createElement('template');
|
372 | t.innerHTML = html;
|
373 | return t;
|
374 | }
|
375 |
|
376 |
|
377 |
|
378 |
|
379 | function childNodesAsList(el) {
|
380 |
|
381 | const childNodes = el.childNodes;
|
382 |
|
383 | const res = [];
|
384 | for (let i = 0; i < childNodes.length; i++) {
|
385 | res[i] = childNodes[i];
|
386 | }
|
387 | return res;
|
388 | }
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 | function initBrowserTests() {
|
399 | ɵBrowserDomAdapter.makeCurrent();
|
400 | BrowserDetection.setup();
|
401 | }
|
402 |
|
403 | const _TEST_BROWSER_PLATFORM_PROVIDERS = [{ provide: PLATFORM_INITIALIZER, useValue: initBrowserTests, multi: true }];
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 | const platformBrowserTesting = createPlatformFactory(platformCore, 'browserTesting', _TEST_BROWSER_PLATFORM_PROVIDERS);
|
411 | const ɵ0 = createNgZone;
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 | class BrowserTestingModule {
|
418 | }
|
419 | BrowserTestingModule.decorators = [
|
420 | { type: NgModule, args: [{
|
421 | exports: [BrowserModule],
|
422 | providers: [
|
423 | { provide: APP_ID, useValue: 'a' },
|
424 | ɵELEMENT_PROBE_PROVIDERS,
|
425 | { provide: NgZone, useFactory: ɵ0 },
|
426 | ]
|
427 | },] }
|
428 | ];
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 | export { BrowserTestingModule, platformBrowserTesting, createNgZone as ɵangular_packages_platform_browser_testing_testing_a };
|
453 |
|