@angular/cdk
Version:
Angular Material Component Development Kit
197 lines (189 loc) • 6.75 kB
JavaScript
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Inject, Injectable, Optional, PLATFORM_ID, NgModule, defineInjectable, inject } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
// Whether the current platform supports the V8 Break Iterator. The V8 check
// is necessary to detect all Blink based browsers.
var /** @type {?} */ hasV8BreakIterator = (typeof Intl !== 'undefined' && (/** @type {?} */ (Intl)).v8BreakIterator);
/**
* Service to detect the current platform by comparing the userAgent strings and
* checking browser-specific global properties.
*/
var Platform = /** @class */ (function () {
/**
* @breaking-change v7.0.0 remove optional decorator
*/
function Platform(_platformId) {
this._platformId = _platformId;
/**
* Whether the Angular application is being rendered in the browser.
* We want to use the Angular platform check because if the Document is shimmed
* without the navigator, the following checks will fail. This is preferred because
* sometimes the Document may be shimmed without the user's knowledge or intention
*/
this.isBrowser = this._platformId ?
isPlatformBrowser(this._platformId) : typeof document === 'object' && !!document;
/**
* Whether the current browser is Microsoft Edge.
*/
this.EDGE = this.isBrowser && /(edge)/i.test(navigator.userAgent);
/**
* Whether the current rendering engine is Microsoft Trident.
*/
this.TRIDENT = this.isBrowser && /(msie|trident)/i.test(navigator.userAgent);
/**
* Whether the current rendering engine is Blink.
*/
this.BLINK = this.isBrowser && (!!((/** @type {?} */ (window)).chrome || hasV8BreakIterator) &&
typeof CSS !== 'undefined' && !this.EDGE && !this.TRIDENT);
/**
* Whether the current rendering engine is WebKit.
*/
this.WEBKIT = this.isBrowser &&
/AppleWebKit/i.test(navigator.userAgent) && !this.BLINK && !this.EDGE && !this.TRIDENT;
/**
* Whether the current platform is Apple iOS.
*/
this.IOS = this.isBrowser && /iPad|iPhone|iPod/.test(navigator.userAgent) &&
!(/** @type {?} */ (window)).MSStream;
/**
* Whether the current browser is Firefox.
*/
this.FIREFOX = this.isBrowser && /(firefox|minefield)/i.test(navigator.userAgent);
/**
* Whether the current platform is Android.
*/
this.ANDROID = this.isBrowser && /android/i.test(navigator.userAgent) && !this.TRIDENT;
/**
* Whether the current browser is Safari.
*/
this.SAFARI = this.isBrowser && /safari/i.test(navigator.userAgent) && this.WEBKIT;
}
Platform.decorators = [
{ type: Injectable, args: [{ providedIn: 'root' },] },
];
/** @nocollapse */
Platform.ctorParameters = function () { return [
{ type: Object, decorators: [{ type: Optional }, { type: Inject, args: [PLATFORM_ID,] },] },
]; };
/** @nocollapse */ Platform.ngInjectableDef = defineInjectable({ factory: function Platform_Factory() { return new Platform(inject(PLATFORM_ID, 8)); }, token: Platform, providedIn: "root" });
return Platform;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* Cached result of whether the user's browser supports passive event listeners.
*/
var /** @type {?} */ supportsPassiveEvents;
/**
* Checks whether the user's browser supports passive event listeners.
* See: https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
* @return {?}
*/
function supportsPassiveEventListeners() {
if (supportsPassiveEvents == null && typeof window !== 'undefined') {
try {
window.addEventListener('test', /** @type {?} */ ((null)), Object.defineProperty({}, 'passive', {
get: function () { return supportsPassiveEvents = true; }
}));
}
finally {
supportsPassiveEvents = supportsPassiveEvents || false;
}
}
return supportsPassiveEvents;
}
/**
* Check whether the browser supports scroll behaviors.
* @return {?}
*/
function supportsScrollBehavior() {
return !!(document && document.documentElement && document.documentElement.style &&
'scrollBehavior' in document.documentElement.style);
}
/**
* Cached result Set of input types support by the current browser.
*/
var /** @type {?} */ supportedInputTypes;
/**
* Types of `<input>` that *might* be supported.
*/
var /** @type {?} */ candidateInputTypes = [
'color',
'button',
'checkbox',
'date',
'datetime-local',
'email',
'file',
'hidden',
'image',
'month',
'number',
'password',
'radio',
'range',
'reset',
'search',
'submit',
'tel',
'text',
'time',
'url',
'week',
];
/**
* @return {?} The input types supported by this browser.
*/
function getSupportedInputTypes() {
// Result is cached.
if (supportedInputTypes) {
return supportedInputTypes;
}
// We can't check if an input type is not supported until we're on the browser, so say that
// everything is supported when not on the browser. We don't use `Platform` here since it's
// just a helper function and can't inject it.
if (typeof document !== 'object' || !document) {
supportedInputTypes = new Set(candidateInputTypes);
return supportedInputTypes;
}
var /** @type {?} */ featureTestInput = document.createElement('input');
supportedInputTypes = new Set(candidateInputTypes.filter(function (value) {
featureTestInput.setAttribute('type', value);
return featureTestInput.type === value;
}));
return supportedInputTypes;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var PlatformModule = /** @class */ (function () {
function PlatformModule() {
}
PlatformModule.decorators = [
{ type: NgModule },
];
return PlatformModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
export { Platform, supportsPassiveEventListeners, supportsScrollBehavior, getSupportedInputTypes, PlatformModule };
//# sourceMappingURL=platform.es5.js.map