UNPKG

4.49 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8/* eslint-disable */
9import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
10import { isPlatformBrowser } from '@angular/common';
11import * as i0 from "@angular/core";
12// Whether the current platform supports the V8 Break Iterator. The V8 check
13// is necessary to detect all Blink based browsers.
14let hasV8BreakIterator;
15// We need a try/catch around the reference to `Intl`, because accessing it in some cases can
16// cause IE to throw. These cases are tied to particular versions of Windows and can happen if
17// the consumer is providing a polyfilled `Map`. See:
18// https://github.com/Microsoft/ChakraCore/issues/3189
19// https://github.com/angular/components/issues/15687
20try {
21 hasV8BreakIterator = (typeof Intl !== 'undefined' && Intl.v8BreakIterator);
22}
23catch (_a) {
24 hasV8BreakIterator = false;
25}
26/**
27 * Service to detect the current platform by comparing the userAgent strings and
28 * checking browser-specific global properties.
29 */
30export class Platform {
31 constructor(_platformId) {
32 this._platformId = _platformId;
33 // We want to use the Angular platform check because if the Document is shimmed
34 // without the navigator, the following checks will fail. This is preferred because
35 // sometimes the Document may be shimmed without the user's knowledge or intention
36 /** Whether the Angular application is being rendered in the browser. */
37 this.isBrowser = this._platformId ?
38 isPlatformBrowser(this._platformId) : typeof document === 'object' && !!document;
39 /** Whether the current browser is Microsoft Edge. */
40 this.EDGE = this.isBrowser && /(edge)/i.test(navigator.userAgent);
41 /** Whether the current rendering engine is Microsoft Trident. */
42 this.TRIDENT = this.isBrowser && /(msie|trident)/i.test(navigator.userAgent);
43 // EdgeHTML and Trident mock Blink specific things and need to be excluded from this check.
44 /** Whether the current rendering engine is Blink. */
45 this.BLINK = this.isBrowser && (!!(window.chrome || hasV8BreakIterator) &&
46 typeof CSS !== 'undefined' && !this.EDGE && !this.TRIDENT);
47 // Webkit is part of the userAgent in EdgeHTML, Blink and Trident. Therefore we need to
48 // ensure that Webkit runs standalone and is not used as another engine's base.
49 /** Whether the current rendering engine is WebKit. */
50 this.WEBKIT = this.isBrowser &&
51 /AppleWebKit/i.test(navigator.userAgent) && !this.BLINK && !this.EDGE && !this.TRIDENT;
52 /** Whether the current platform is Apple iOS. */
53 this.IOS = this.isBrowser && /iPad|iPhone|iPod/.test(navigator.userAgent) &&
54 !('MSStream' in window);
55 // It's difficult to detect the plain Gecko engine, because most of the browsers identify
56 // them self as Gecko-like browsers and modify the userAgent's according to that.
57 // Since we only cover one explicit Firefox case, we can simply check for Firefox
58 // instead of having an unstable check for Gecko.
59 /** Whether the current browser is Firefox. */
60 this.FIREFOX = this.isBrowser && /(firefox|minefield)/i.test(navigator.userAgent);
61 /** Whether the current platform is Android. */
62 // Trident on mobile adds the android platform to the userAgent to trick detections.
63 this.ANDROID = this.isBrowser && /android/i.test(navigator.userAgent) && !this.TRIDENT;
64 // Safari browsers will include the Safari keyword in their userAgent. Some browsers may fake
65 // this and just place the Safari keyword in the userAgent. To be more safe about Safari every
66 // Safari browser should also use Webkit as its layout engine.
67 /** Whether the current browser is Safari. */
68 this.SAFARI = this.isBrowser && /safari/i.test(navigator.userAgent) && this.WEBKIT;
69 }
70}
71Platform.ɵprov = i0.ɵɵdefineInjectable({ factory: function Platform_Factory() { return new Platform(i0.ɵɵinject(i0.PLATFORM_ID)); }, token: Platform, providedIn: "root" });
72Platform.decorators = [
73 { type: Injectable, args: [{ providedIn: 'root' },] }
74];
75Platform.ctorParameters = () => [
76 { type: Object, decorators: [{ type: Inject, args: [PLATFORM_ID,] }] }
77];
78//# sourceMappingURL=platform.js.map
\No newline at end of file