cdk-platform.umd.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. (function (global, factory) {
  9. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common')) :
  10. typeof define === 'function' && define.amd ? define('@angular/cdk/platform', ['exports', '@angular/core', '@angular/common'], factory) :
  11. (factory((global.ng = global.ng || {}, global.ng.cdk = global.ng.cdk || {}, global.ng.cdk.platform = {}),global.ng.core,global.ng.common));
  12. }(this, (function (exports,core,common) { 'use strict';
  13. /**
  14. * @fileoverview added by tsickle
  15. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  16. */
  17. // Whether the current platform supports the V8 Break Iterator. The V8 check
  18. // is necessary to detect all Blink based browsers.
  19. /** @type {?} */
  20. var hasV8BreakIterator;
  21. // We need a try/catch around the reference to `Intl`, because accessing it in some cases can
  22. // cause IE to throw. These cases are tied to particular versions of Windows and can happen if
  23. // the consumer is providing a polyfilled `Map`. See:
  24. // https://github.com/Microsoft/ChakraCore/issues/3189
  25. // https://github.com/angular/components/issues/15687
  26. try {
  27. hasV8BreakIterator = (typeof Intl !== 'undefined' && ((/** @type {?} */ (Intl))).v8BreakIterator);
  28. }
  29. catch (_a) {
  30. hasV8BreakIterator = false;
  31. }
  32. /**
  33. * Service to detect the current platform by comparing the userAgent strings and
  34. * checking browser-specific global properties.
  35. */
  36. var Platform = /** @class */ (function () {
  37. /**
  38. * @breaking-change 8.0.0 remove optional decorator
  39. */
  40. function Platform(_platformId) {
  41. this._platformId = _platformId;
  42. /**
  43. * Whether the Angular application is being rendered in the browser.
  44. * We want to use the Angular platform check because if the Document is shimmed
  45. * without the navigator, the following checks will fail. This is preferred because
  46. * sometimes the Document may be shimmed without the user's knowledge or intention
  47. */
  48. this.isBrowser = this._platformId ?
  49. common.isPlatformBrowser(this._platformId) : typeof document === 'object' && !!document;
  50. /**
  51. * Whether the current browser is Microsoft Edge.
  52. */
  53. this.EDGE = this.isBrowser && /(edge)/i.test(navigator.userAgent);
  54. /**
  55. * Whether the current rendering engine is Microsoft Trident.
  56. */
  57. this.TRIDENT = this.isBrowser && /(msie|trident)/i.test(navigator.userAgent);
  58. /**
  59. * Whether the current rendering engine is Blink.
  60. */
  61. // EdgeHTML and Trident mock Blink specific things and need to be excluded from this check.
  62. this.BLINK = this.isBrowser && (!!(((/** @type {?} */ (window))).chrome || hasV8BreakIterator) &&
  63. typeof CSS !== 'undefined' && !this.EDGE && !this.TRIDENT);
  64. /**
  65. * Whether the current rendering engine is WebKit.
  66. */
  67. // Webkit is part of the userAgent in EdgeHTML, Blink and Trident. Therefore we need to
  68. // ensure that Webkit runs standalone and is not used as another engine's base.
  69. this.WEBKIT = this.isBrowser &&
  70. /AppleWebKit/i.test(navigator.userAgent) && !this.BLINK && !this.EDGE && !this.TRIDENT;
  71. /**
  72. * Whether the current platform is Apple iOS.
  73. */
  74. this.IOS = this.isBrowser && /iPad|iPhone|iPod/.test(navigator.userAgent) &&
  75. !('MSStream' in window);
  76. /**
  77. * Whether the current browser is Firefox.
  78. */
  79. // It's difficult to detect the plain Gecko engine, because most of the browsers identify
  80. // them self as Gecko-like browsers and modify the userAgent's according to that.
  81. // Since we only cover one explicit Firefox case, we can simply check for Firefox
  82. // instead of having an unstable check for Gecko.
  83. this.FIREFOX = this.isBrowser && /(firefox|minefield)/i.test(navigator.userAgent);
  84. /**
  85. * Whether the current platform is Android.
  86. */
  87. // Trident on mobile adds the android platform to the userAgent to trick detections.
  88. this.ANDROID = this.isBrowser && /android/i.test(navigator.userAgent) && !this.TRIDENT;
  89. /**
  90. * Whether the current browser is Safari.
  91. */
  92. // Safari browsers will include the Safari keyword in their userAgent. Some browsers may fake
  93. // this and just place the Safari keyword in the userAgent. To be more safe about Safari every
  94. // Safari browser should also use Webkit as its layout engine.
  95. this.SAFARI = this.isBrowser && /safari/i.test(navigator.userAgent) && this.WEBKIT;
  96. }
  97. Platform.decorators = [
  98. { type: core.Injectable, args: [{ providedIn: 'root' },] },
  99. ];
  100. /** @nocollapse */
  101. Platform.ctorParameters = function () { return [
  102. { type: Object, decorators: [{ type: core.Optional }, { type: core.Inject, args: [core.PLATFORM_ID,] }] }
  103. ]; };
  104. /** @nocollapse */ Platform.ngInjectableDef = core.ɵɵdefineInjectable({ factory: function Platform_Factory() { return new Platform(core.ɵɵinject(core.PLATFORM_ID, 8)); }, token: Platform, providedIn: "root" });
  105. return Platform;
  106. }());
  107. /**
  108. * @fileoverview added by tsickle
  109. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  110. */
  111. var PlatformModule = /** @class */ (function () {
  112. function PlatformModule() {
  113. }
  114. PlatformModule.decorators = [
  115. { type: core.NgModule, args: [{},] },
  116. ];
  117. return PlatformModule;
  118. }());
  119. /**
  120. * @fileoverview added by tsickle
  121. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  122. */
  123. /**
  124. * Cached result Set of input types support by the current browser.
  125. * @type {?}
  126. */
  127. var supportedInputTypes;
  128. /**
  129. * Types of `<input>` that *might* be supported.
  130. * @type {?}
  131. */
  132. var candidateInputTypes = [
  133. // `color` must come first. Chrome 56 shows a warning if we change the type to `color` after
  134. // first changing it to something else:
  135. // The specified value "" does not conform to the required format.
  136. // The format is "#rrggbb" where rr, gg, bb are two-digit hexadecimal numbers.
  137. 'color',
  138. 'button',
  139. 'checkbox',
  140. 'date',
  141. 'datetime-local',
  142. 'email',
  143. 'file',
  144. 'hidden',
  145. 'image',
  146. 'month',
  147. 'number',
  148. 'password',
  149. 'radio',
  150. 'range',
  151. 'reset',
  152. 'search',
  153. 'submit',
  154. 'tel',
  155. 'text',
  156. 'time',
  157. 'url',
  158. 'week',
  159. ];
  160. /**
  161. * @return {?} The input types supported by this browser.
  162. */
  163. function getSupportedInputTypes() {
  164. // Result is cached.
  165. if (supportedInputTypes) {
  166. return supportedInputTypes;
  167. }
  168. // We can't check if an input type is not supported until we're on the browser, so say that
  169. // everything is supported when not on the browser. We don't use `Platform` here since it's
  170. // just a helper function and can't inject it.
  171. if (typeof document !== 'object' || !document) {
  172. supportedInputTypes = new Set(candidateInputTypes);
  173. return supportedInputTypes;
  174. }
  175. /** @type {?} */
  176. var featureTestInput = document.createElement('input');
  177. supportedInputTypes = new Set(candidateInputTypes.filter((/**
  178. * @param {?} value
  179. * @return {?}
  180. */
  181. function (value) {
  182. featureTestInput.setAttribute('type', value);
  183. return featureTestInput.type === value;
  184. })));
  185. return supportedInputTypes;
  186. }
  187. /**
  188. * @fileoverview added by tsickle
  189. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  190. */
  191. /**
  192. * Cached result of whether the user's browser supports passive event listeners.
  193. * @type {?}
  194. */
  195. var supportsPassiveEvents;
  196. /**
  197. * Checks whether the user's browser supports passive event listeners.
  198. * See: https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
  199. * @return {?}
  200. */
  201. function supportsPassiveEventListeners() {
  202. if (supportsPassiveEvents == null && typeof window !== 'undefined') {
  203. try {
  204. window.addEventListener('test', (/** @type {?} */ (null)), Object.defineProperty({}, 'passive', {
  205. get: (/**
  206. * @return {?}
  207. */
  208. function () { return supportsPassiveEvents = true; })
  209. }));
  210. }
  211. finally {
  212. supportsPassiveEvents = supportsPassiveEvents || false;
  213. }
  214. }
  215. return supportsPassiveEvents;
  216. }
  217. /**
  218. * Normalizes an `AddEventListener` object to something that can be passed
  219. * to `addEventListener` on any browser, no matter whether it supports the
  220. * `options` parameter.
  221. * @param {?} options Object to be normalized.
  222. * @return {?}
  223. */
  224. function normalizePassiveListenerOptions(options) {
  225. return supportsPassiveEventListeners() ? options : !!options.capture;
  226. }
  227. /**
  228. * @fileoverview added by tsickle
  229. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  230. */
  231. /** @enum {number} */
  232. var RtlScrollAxisType = {
  233. /**
  234. * scrollLeft is 0 when scrolled all the way left and (scrollWidth - clientWidth) when scrolled
  235. * all the way right.
  236. */
  237. NORMAL: 0,
  238. /**
  239. * scrollLeft is -(scrollWidth - clientWidth) when scrolled all the way left and 0 when scrolled
  240. * all the way right.
  241. */
  242. NEGATED: 1,
  243. /**
  244. * scrollLeft is (scrollWidth - clientWidth) when scrolled all the way left and 0 when scrolled
  245. * all the way right.
  246. */
  247. INVERTED: 2,
  248. };
  249. RtlScrollAxisType[RtlScrollAxisType.NORMAL] = 'NORMAL';
  250. RtlScrollAxisType[RtlScrollAxisType.NEGATED] = 'NEGATED';
  251. RtlScrollAxisType[RtlScrollAxisType.INVERTED] = 'INVERTED';
  252. /**
  253. * Cached result of the way the browser handles the horizontal scroll axis in RTL mode.
  254. * @type {?}
  255. */
  256. var rtlScrollAxisType;
  257. /**
  258. * Check whether the browser supports scroll behaviors.
  259. * @return {?}
  260. */
  261. function supportsScrollBehavior() {
  262. return !!(typeof document == 'object' && 'scrollBehavior' in (/** @type {?} */ (document.documentElement)).style);
  263. }
  264. /**
  265. * Checks the type of RTL scroll axis used by this browser. As of time of writing, Chrome is NORMAL,
  266. * Firefox & Safari are NEGATED, and IE & Edge are INVERTED.
  267. * @return {?}
  268. */
  269. function getRtlScrollAxisType() {
  270. // We can't check unless we're on the browser. Just assume 'normal' if we're not.
  271. if (typeof document !== 'object' || !document) {
  272. return RtlScrollAxisType.NORMAL;
  273. }
  274. if (!rtlScrollAxisType) {
  275. // Create a 1px wide scrolling container and a 2px wide content element.
  276. /** @type {?} */
  277. var scrollContainer = document.createElement('div');
  278. /** @type {?} */
  279. var containerStyle = scrollContainer.style;
  280. scrollContainer.dir = 'rtl';
  281. containerStyle.height = '1px';
  282. containerStyle.width = '1px';
  283. containerStyle.overflow = 'auto';
  284. containerStyle.visibility = 'hidden';
  285. containerStyle.pointerEvents = 'none';
  286. containerStyle.position = 'absolute';
  287. /** @type {?} */
  288. var content = document.createElement('div');
  289. /** @type {?} */
  290. var contentStyle = content.style;
  291. contentStyle.width = '2px';
  292. contentStyle.height = '1px';
  293. scrollContainer.appendChild(content);
  294. document.body.appendChild(scrollContainer);
  295. rtlScrollAxisType = RtlScrollAxisType.NORMAL;
  296. // The viewport starts scrolled all the way to the right in RTL mode. If we are in a NORMAL
  297. // browser this would mean that the scrollLeft should be 1. If it's zero instead we know we're
  298. // dealing with one of the other two types of browsers.
  299. if (scrollContainer.scrollLeft === 0) {
  300. // In a NEGATED browser the scrollLeft is always somewhere in [-maxScrollAmount, 0]. For an
  301. // INVERTED browser it is always somewhere in [0, maxScrollAmount]. We can determine which by
  302. // setting to the scrollLeft to 1. This is past the max for a NEGATED browser, so it will
  303. // return 0 when we read it again.
  304. scrollContainer.scrollLeft = 1;
  305. rtlScrollAxisType =
  306. scrollContainer.scrollLeft === 0 ? RtlScrollAxisType.NEGATED : RtlScrollAxisType.INVERTED;
  307. }
  308. (/** @type {?} */ (scrollContainer.parentNode)).removeChild(scrollContainer);
  309. }
  310. return rtlScrollAxisType;
  311. }
  312. /**
  313. * @fileoverview added by tsickle
  314. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  315. */
  316. /** @type {?} */
  317. var shadowDomIsSupported;
  318. /**
  319. * Checks whether the user's browser support Shadow DOM.
  320. * @return {?}
  321. */
  322. function _supportsShadowDom() {
  323. if (shadowDomIsSupported == null) {
  324. /** @type {?} */
  325. var head = typeof document !== 'undefined' ? document.head : null;
  326. shadowDomIsSupported = !!(head && (((/** @type {?} */ (head))).createShadowRoot || head.attachShadow));
  327. }
  328. return shadowDomIsSupported;
  329. }
  330. exports.Platform = Platform;
  331. exports.PlatformModule = PlatformModule;
  332. exports.getSupportedInputTypes = getSupportedInputTypes;
  333. exports.supportsPassiveEventListeners = supportsPassiveEventListeners;
  334. exports.normalizePassiveListenerOptions = normalizePassiveListenerOptions;
  335. exports.supportsScrollBehavior = supportsScrollBehavior;
  336. exports.getRtlScrollAxisType = getRtlScrollAxisType;
  337. exports.RtlScrollAxisType = RtlScrollAxisType;
  338. exports._supportsShadowDom = _supportsShadowDom;
  339. Object.defineProperty(exports, '__esModule', { value: true });
  340. })));
  341. //# sourceMappingURL=cdk-platform.umd.js.map