| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- /**
- * @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,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- // Whether the current platform supports the V8 Break Iterator. The V8 check
- // is necessary to detect all Blink based browsers.
- /** @type {?} */
- var hasV8BreakIterator;
- // We need a try/catch around the reference to `Intl`, because accessing it in some cases can
- // cause IE to throw. These cases are tied to particular versions of Windows and can happen if
- // the consumer is providing a polyfilled `Map`. See:
- // https://github.com/Microsoft/ChakraCore/issues/3189
- // https://github.com/angular/components/issues/15687
- try {
- hasV8BreakIterator = (typeof Intl !== 'undefined' && ((/** @type {?} */ (Intl))).v8BreakIterator);
- }
- catch (_a) {
- hasV8BreakIterator = false;
- }
- /**
- * Service to detect the current platform by comparing the userAgent strings and
- * checking browser-specific global properties.
- */
- var Platform = /** @class */ (function () {
- /**
- * @breaking-change 8.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.
- */
- // EdgeHTML and Trident mock Blink specific things and need to be excluded from this check.
- this.BLINK = this.isBrowser && (!!(((/** @type {?} */ (window))).chrome || hasV8BreakIterator) &&
- typeof CSS !== 'undefined' && !this.EDGE && !this.TRIDENT);
- /**
- * Whether the current rendering engine is WebKit.
- */
- // Webkit is part of the userAgent in EdgeHTML, Blink and Trident. Therefore we need to
- // ensure that Webkit runs standalone and is not used as another engine's base.
- 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) &&
- !('MSStream' in window);
- /**
- * Whether the current browser is Firefox.
- */
- // It's difficult to detect the plain Gecko engine, because most of the browsers identify
- // them self as Gecko-like browsers and modify the userAgent's according to that.
- // Since we only cover one explicit Firefox case, we can simply check for Firefox
- // instead of having an unstable check for Gecko.
- this.FIREFOX = this.isBrowser && /(firefox|minefield)/i.test(navigator.userAgent);
- /**
- * Whether the current platform is Android.
- */
- // Trident on mobile adds the android platform to the userAgent to trick detections.
- this.ANDROID = this.isBrowser && /android/i.test(navigator.userAgent) && !this.TRIDENT;
- /**
- * Whether the current browser is Safari.
- */
- // Safari browsers will include the Safari keyword in their userAgent. Some browsers may fake
- // this and just place the Safari keyword in the userAgent. To be more safe about Safari every
- // Safari browser should also use Webkit as its layout engine.
- 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,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- var PlatformModule = /** @class */ (function () {
- function PlatformModule() {
- }
- PlatformModule.decorators = [
- { type: NgModule, args: [{},] },
- ];
- return PlatformModule;
- }());
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- /**
- * Cached result Set of input types support by the current browser.
- * @type {?}
- */
- var supportedInputTypes;
- /**
- * Types of `<input>` that *might* be supported.
- * @type {?}
- */
- var candidateInputTypes = [
- // `color` must come first. Chrome 56 shows a warning if we change the type to `color` after
- // first changing it to something else:
- // The specified value "" does not conform to the required format.
- // The format is "#rrggbb" where rr, gg, bb are two-digit hexadecimal numbers.
- '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;
- }
- /** @type {?} */
- var featureTestInput = document.createElement('input');
- supportedInputTypes = new Set(candidateInputTypes.filter((/**
- * @param {?} value
- * @return {?}
- */
- function (value) {
- featureTestInput.setAttribute('type', value);
- return featureTestInput.type === value;
- })));
- return supportedInputTypes;
- }
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- /**
- * Cached result of whether the user's browser supports passive event listeners.
- * @type {?}
- */
- var 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: (/**
- * @return {?}
- */
- function () { return supportsPassiveEvents = true; })
- }));
- }
- finally {
- supportsPassiveEvents = supportsPassiveEvents || false;
- }
- }
- return supportsPassiveEvents;
- }
- /**
- * Normalizes an `AddEventListener` object to something that can be passed
- * to `addEventListener` on any browser, no matter whether it supports the
- * `options` parameter.
- * @param {?} options Object to be normalized.
- * @return {?}
- */
- function normalizePassiveListenerOptions(options) {
- return supportsPassiveEventListeners() ? options : !!options.capture;
- }
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- /** @enum {number} */
- var RtlScrollAxisType = {
- /**
- * scrollLeft is 0 when scrolled all the way left and (scrollWidth - clientWidth) when scrolled
- * all the way right.
- */
- NORMAL: 0,
- /**
- * scrollLeft is -(scrollWidth - clientWidth) when scrolled all the way left and 0 when scrolled
- * all the way right.
- */
- NEGATED: 1,
- /**
- * scrollLeft is (scrollWidth - clientWidth) when scrolled all the way left and 0 when scrolled
- * all the way right.
- */
- INVERTED: 2,
- };
- RtlScrollAxisType[RtlScrollAxisType.NORMAL] = 'NORMAL';
- RtlScrollAxisType[RtlScrollAxisType.NEGATED] = 'NEGATED';
- RtlScrollAxisType[RtlScrollAxisType.INVERTED] = 'INVERTED';
- /**
- * Cached result of the way the browser handles the horizontal scroll axis in RTL mode.
- * @type {?}
- */
- var rtlScrollAxisType;
- /**
- * Check whether the browser supports scroll behaviors.
- * @return {?}
- */
- function supportsScrollBehavior() {
- return !!(typeof document == 'object' && 'scrollBehavior' in (/** @type {?} */ (document.documentElement)).style);
- }
- /**
- * Checks the type of RTL scroll axis used by this browser. As of time of writing, Chrome is NORMAL,
- * Firefox & Safari are NEGATED, and IE & Edge are INVERTED.
- * @return {?}
- */
- function getRtlScrollAxisType() {
- // We can't check unless we're on the browser. Just assume 'normal' if we're not.
- if (typeof document !== 'object' || !document) {
- return RtlScrollAxisType.NORMAL;
- }
- if (!rtlScrollAxisType) {
- // Create a 1px wide scrolling container and a 2px wide content element.
- /** @type {?} */
- var scrollContainer = document.createElement('div');
- /** @type {?} */
- var containerStyle = scrollContainer.style;
- scrollContainer.dir = 'rtl';
- containerStyle.height = '1px';
- containerStyle.width = '1px';
- containerStyle.overflow = 'auto';
- containerStyle.visibility = 'hidden';
- containerStyle.pointerEvents = 'none';
- containerStyle.position = 'absolute';
- /** @type {?} */
- var content = document.createElement('div');
- /** @type {?} */
- var contentStyle = content.style;
- contentStyle.width = '2px';
- contentStyle.height = '1px';
- scrollContainer.appendChild(content);
- document.body.appendChild(scrollContainer);
- rtlScrollAxisType = RtlScrollAxisType.NORMAL;
- // The viewport starts scrolled all the way to the right in RTL mode. If we are in a NORMAL
- // browser this would mean that the scrollLeft should be 1. If it's zero instead we know we're
- // dealing with one of the other two types of browsers.
- if (scrollContainer.scrollLeft === 0) {
- // In a NEGATED browser the scrollLeft is always somewhere in [-maxScrollAmount, 0]. For an
- // INVERTED browser it is always somewhere in [0, maxScrollAmount]. We can determine which by
- // setting to the scrollLeft to 1. This is past the max for a NEGATED browser, so it will
- // return 0 when we read it again.
- scrollContainer.scrollLeft = 1;
- rtlScrollAxisType =
- scrollContainer.scrollLeft === 0 ? RtlScrollAxisType.NEGATED : RtlScrollAxisType.INVERTED;
- }
- (/** @type {?} */ (scrollContainer.parentNode)).removeChild(scrollContainer);
- }
- return rtlScrollAxisType;
- }
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- /** @type {?} */
- var shadowDomIsSupported;
- /**
- * Checks whether the user's browser support Shadow DOM.
- * @return {?}
- */
- function _supportsShadowDom() {
- if (shadowDomIsSupported == null) {
- /** @type {?} */
- var head = typeof document !== 'undefined' ? document.head : null;
- shadowDomIsSupported = !!(head && (((/** @type {?} */ (head))).createShadowRoot || head.attachShadow));
- }
- return shadowDomIsSupported;
- }
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- export { Platform, PlatformModule, getSupportedInputTypes, supportsPassiveEventListeners, normalizePassiveListenerOptions, supportsScrollBehavior, getRtlScrollAxisType, RtlScrollAxisType, _supportsShadowDom };
- //# sourceMappingURL=platform.es5.js.map
|