UNPKG

17.8 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common')) :
3 typeof define === 'function' && define.amd ? define('@angular/cdk/platform', ['exports', '@angular/core', '@angular/common'], factory) :
4 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.ng = global.ng || {}, global.ng.cdk = global.ng.cdk || {}, global.ng.cdk.platform = {}), global.ng.core, global.ng.common));
5}(this, (function (exports, i0, common) { 'use strict';
6
7 function _interopNamespace(e) {
8 if (e && e.__esModule) return e;
9 var n = Object.create(null);
10 if (e) {
11 Object.keys(e).forEach(function (k) {
12 if (k !== 'default') {
13 var d = Object.getOwnPropertyDescriptor(e, k);
14 Object.defineProperty(n, k, d.get ? d : {
15 enumerable: true,
16 get: function () {
17 return e[k];
18 }
19 });
20 }
21 });
22 }
23 n['default'] = e;
24 return Object.freeze(n);
25 }
26
27 var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
28
29 /**
30 * @license
31 * Copyright Google LLC All Rights Reserved.
32 *
33 * Use of this source code is governed by an MIT-style license that can be
34 * found in the LICENSE file at https://angular.io/license
35 */
36 // Whether the current platform supports the V8 Break Iterator. The V8 check
37 // is necessary to detect all Blink based browsers.
38 var hasV8BreakIterator;
39 // We need a try/catch around the reference to `Intl`, because accessing it in some cases can
40 // cause IE to throw. These cases are tied to particular versions of Windows and can happen if
41 // the consumer is providing a polyfilled `Map`. See:
42 // https://github.com/Microsoft/ChakraCore/issues/3189
43 // https://github.com/angular/components/issues/15687
44 try {
45 hasV8BreakIterator = (typeof Intl !== 'undefined' && Intl.v8BreakIterator);
46 }
47 catch (_a) {
48 hasV8BreakIterator = false;
49 }
50 /**
51 * Service to detect the current platform by comparing the userAgent strings and
52 * checking browser-specific global properties.
53 */
54 var Platform = /** @class */ (function () {
55 function Platform(_platformId) {
56 this._platformId = _platformId;
57 // We want to use the Angular platform check because if the Document is shimmed
58 // without the navigator, the following checks will fail. This is preferred because
59 // sometimes the Document may be shimmed without the user's knowledge or intention
60 /** Whether the Angular application is being rendered in the browser. */
61 this.isBrowser = this._platformId ?
62 common.isPlatformBrowser(this._platformId) : typeof document === 'object' && !!document;
63 /** Whether the current browser is Microsoft Edge. */
64 this.EDGE = this.isBrowser && /(edge)/i.test(navigator.userAgent);
65 /** Whether the current rendering engine is Microsoft Trident. */
66 this.TRIDENT = this.isBrowser && /(msie|trident)/i.test(navigator.userAgent);
67 // EdgeHTML and Trident mock Blink specific things and need to be excluded from this check.
68 /** Whether the current rendering engine is Blink. */
69 this.BLINK = this.isBrowser && (!!(window.chrome || hasV8BreakIterator) &&
70 typeof CSS !== 'undefined' && !this.EDGE && !this.TRIDENT);
71 // Webkit is part of the userAgent in EdgeHTML, Blink and Trident. Therefore we need to
72 // ensure that Webkit runs standalone and is not used as another engine's base.
73 /** Whether the current rendering engine is WebKit. */
74 this.WEBKIT = this.isBrowser &&
75 /AppleWebKit/i.test(navigator.userAgent) && !this.BLINK && !this.EDGE && !this.TRIDENT;
76 /** Whether the current platform is Apple iOS. */
77 this.IOS = this.isBrowser && /iPad|iPhone|iPod/.test(navigator.userAgent) &&
78 !('MSStream' in window);
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 /** Whether the current browser is Firefox. */
84 this.FIREFOX = this.isBrowser && /(firefox|minefield)/i.test(navigator.userAgent);
85 /** Whether the current platform is Android. */
86 // Trident on mobile adds the android platform to the userAgent to trick detections.
87 this.ANDROID = this.isBrowser && /android/i.test(navigator.userAgent) && !this.TRIDENT;
88 // Safari browsers will include the Safari keyword in their userAgent. Some browsers may fake
89 // this and just place the Safari keyword in the userAgent. To be more safe about Safari every
90 // Safari browser should also use Webkit as its layout engine.
91 /** Whether the current browser is Safari. */
92 this.SAFARI = this.isBrowser && /safari/i.test(navigator.userAgent) && this.WEBKIT;
93 }
94 return Platform;
95 }());
96 Platform.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function Platform_Factory() { return new Platform(i0__namespace.ɵɵinject(i0__namespace.PLATFORM_ID)); }, token: Platform, providedIn: "root" });
97 Platform.decorators = [
98 { type: i0.Injectable, args: [{ providedIn: 'root' },] }
99 ];
100 Platform.ctorParameters = function () { return [
101 { type: Object, decorators: [{ type: i0.Inject, args: [i0.PLATFORM_ID,] }] }
102 ]; };
103
104 /**
105 * @license
106 * Copyright Google LLC All Rights Reserved.
107 *
108 * Use of this source code is governed by an MIT-style license that can be
109 * found in the LICENSE file at https://angular.io/license
110 */
111 var PlatformModule = /** @class */ (function () {
112 function PlatformModule() {
113 }
114 return PlatformModule;
115 }());
116 PlatformModule.decorators = [
117 { type: i0.NgModule, args: [{},] }
118 ];
119
120 /**
121 * @license
122 * Copyright Google LLC All Rights Reserved.
123 *
124 * Use of this source code is governed by an MIT-style license that can be
125 * found in the LICENSE file at https://angular.io/license
126 */
127 /** Cached result Set of input types support by the current browser. */
128 var supportedInputTypes;
129 /** Types of `<input>` that *might* be supported. */
130 var candidateInputTypes = [
131 // `color` must come first. Chrome 56 shows a warning if we change the type to `color` after
132 // first changing it to something else:
133 // The specified value "" does not conform to the required format.
134 // The format is "#rrggbb" where rr, gg, bb are two-digit hexadecimal numbers.
135 'color',
136 'button',
137 'checkbox',
138 'date',
139 'datetime-local',
140 'email',
141 'file',
142 'hidden',
143 'image',
144 'month',
145 'number',
146 'password',
147 'radio',
148 'range',
149 'reset',
150 'search',
151 'submit',
152 'tel',
153 'text',
154 'time',
155 'url',
156 'week',
157 ];
158 /** @returns The input types supported by this browser. */
159 function getSupportedInputTypes() {
160 // Result is cached.
161 if (supportedInputTypes) {
162 return supportedInputTypes;
163 }
164 // We can't check if an input type is not supported until we're on the browser, so say that
165 // everything is supported when not on the browser. We don't use `Platform` here since it's
166 // just a helper function and can't inject it.
167 if (typeof document !== 'object' || !document) {
168 supportedInputTypes = new Set(candidateInputTypes);
169 return supportedInputTypes;
170 }
171 var featureTestInput = document.createElement('input');
172 supportedInputTypes = new Set(candidateInputTypes.filter(function (value) {
173 featureTestInput.setAttribute('type', value);
174 return featureTestInput.type === value;
175 }));
176 return supportedInputTypes;
177 }
178
179 /**
180 * @license
181 * Copyright Google LLC All Rights Reserved.
182 *
183 * Use of this source code is governed by an MIT-style license that can be
184 * found in the LICENSE file at https://angular.io/license
185 */
186 /** Cached result of whether the user's browser supports passive event listeners. */
187 var supportsPassiveEvents;
188 /**
189 * Checks whether the user's browser supports passive event listeners.
190 * See: https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
191 */
192 function supportsPassiveEventListeners() {
193 if (supportsPassiveEvents == null && typeof window !== 'undefined') {
194 try {
195 window.addEventListener('test', null, Object.defineProperty({}, 'passive', {
196 get: function () { return supportsPassiveEvents = true; }
197 }));
198 }
199 finally {
200 supportsPassiveEvents = supportsPassiveEvents || false;
201 }
202 }
203 return supportsPassiveEvents;
204 }
205 /**
206 * Normalizes an `AddEventListener` object to something that can be passed
207 * to `addEventListener` on any browser, no matter whether it supports the
208 * `options` parameter.
209 * @param options Object to be normalized.
210 */
211 function normalizePassiveListenerOptions(options) {
212 return supportsPassiveEventListeners() ? options : !!options.capture;
213 }
214
215 /**
216 * @license
217 * Copyright Google LLC All Rights Reserved.
218 *
219 * Use of this source code is governed by an MIT-style license that can be
220 * found in the LICENSE file at https://angular.io/license
221 */
222 /** Cached result of the way the browser handles the horizontal scroll axis in RTL mode. */
223 var rtlScrollAxisType;
224 /** Cached result of the check that indicates whether the browser supports scroll behaviors. */
225 var scrollBehaviorSupported;
226 /** Check whether the browser supports scroll behaviors. */
227 function supportsScrollBehavior() {
228 if (scrollBehaviorSupported == null) {
229 // If we're not in the browser, it can't be supported. Also check for `Element`, because
230 // some projects stub out the global `document` during SSR which can throw us off.
231 if (typeof document !== 'object' || !document || typeof Element !== 'function' || !Element) {
232 scrollBehaviorSupported = false;
233 return scrollBehaviorSupported;
234 }
235 // If the element can have a `scrollBehavior` style, we can be sure that it's supported.
236 if ('scrollBehavior' in document.documentElement.style) {
237 scrollBehaviorSupported = true;
238 }
239 else {
240 // At this point we have 3 possibilities: `scrollTo` isn't supported at all, it's
241 // supported but it doesn't handle scroll behavior, or it has been polyfilled.
242 var scrollToFunction = Element.prototype.scrollTo;
243 if (scrollToFunction) {
244 // We can detect if the function has been polyfilled by calling `toString` on it. Native
245 // functions are obfuscated using `[native code]`, whereas if it was overwritten we'd get
246 // the actual function source. Via https://davidwalsh.name/detect-native-function. Consider
247 // polyfilled functions as supporting scroll behavior.
248 scrollBehaviorSupported = !/\{\s*\[native code\]\s*\}/.test(scrollToFunction.toString());
249 }
250 else {
251 scrollBehaviorSupported = false;
252 }
253 }
254 }
255 return scrollBehaviorSupported;
256 }
257 /**
258 * Checks the type of RTL scroll axis used by this browser. As of time of writing, Chrome is NORMAL,
259 * Firefox & Safari are NEGATED, and IE & Edge are INVERTED.
260 */
261 function getRtlScrollAxisType() {
262 // We can't check unless we're on the browser. Just assume 'normal' if we're not.
263 if (typeof document !== 'object' || !document) {
264 return 0 /* NORMAL */;
265 }
266 if (rtlScrollAxisType == null) {
267 // Create a 1px wide scrolling container and a 2px wide content element.
268 var scrollContainer = document.createElement('div');
269 var containerStyle = scrollContainer.style;
270 scrollContainer.dir = 'rtl';
271 containerStyle.width = '1px';
272 containerStyle.overflow = 'auto';
273 containerStyle.visibility = 'hidden';
274 containerStyle.pointerEvents = 'none';
275 containerStyle.position = 'absolute';
276 var content = document.createElement('div');
277 var contentStyle = content.style;
278 contentStyle.width = '2px';
279 contentStyle.height = '1px';
280 scrollContainer.appendChild(content);
281 document.body.appendChild(scrollContainer);
282 rtlScrollAxisType = 0 /* NORMAL */;
283 // The viewport starts scrolled all the way to the right in RTL mode. If we are in a NORMAL
284 // browser this would mean that the scrollLeft should be 1. If it's zero instead we know we're
285 // dealing with one of the other two types of browsers.
286 if (scrollContainer.scrollLeft === 0) {
287 // In a NEGATED browser the scrollLeft is always somewhere in [-maxScrollAmount, 0]. For an
288 // INVERTED browser it is always somewhere in [0, maxScrollAmount]. We can determine which by
289 // setting to the scrollLeft to 1. This is past the max for a NEGATED browser, so it will
290 // return 0 when we read it again.
291 scrollContainer.scrollLeft = 1;
292 rtlScrollAxisType =
293 scrollContainer.scrollLeft === 0 ? 1 /* NEGATED */ : 2 /* INVERTED */;
294 }
295 scrollContainer.parentNode.removeChild(scrollContainer);
296 }
297 return rtlScrollAxisType;
298 }
299
300 /**
301 * @license
302 * Copyright Google LLC All Rights Reserved.
303 *
304 * Use of this source code is governed by an MIT-style license that can be
305 * found in the LICENSE file at https://angular.io/license
306 */
307 var shadowDomIsSupported;
308 /** Checks whether the user's browser support Shadow DOM. */
309 function _supportsShadowDom() {
310 if (shadowDomIsSupported == null) {
311 var head = typeof document !== 'undefined' ? document.head : null;
312 shadowDomIsSupported = !!(head && (head.createShadowRoot || head.attachShadow));
313 }
314 return shadowDomIsSupported;
315 }
316 /** Gets the shadow root of an element, if supported and the element is inside the Shadow DOM. */
317 function _getShadowRoot(element) {
318 if (_supportsShadowDom()) {
319 var rootNode = element.getRootNode ? element.getRootNode() : null;
320 // Note that this should be caught by `_supportsShadowDom`, but some
321 // teams have been able to hit this code path on unsupported browsers.
322 if (typeof ShadowRoot !== 'undefined' && ShadowRoot && rootNode instanceof ShadowRoot) {
323 return rootNode;
324 }
325 }
326 return null;
327 }
328 /**
329 * Gets the currently-focused element on the page while
330 * also piercing through Shadow DOM boundaries.
331 */
332 function _getFocusedElementPierceShadowDom() {
333 var activeElement = typeof document !== 'undefined' && document ?
334 document.activeElement : null;
335 while (activeElement && activeElement.shadowRoot) {
336 var newActiveElement = activeElement.shadowRoot.activeElement;
337 if (newActiveElement === activeElement) {
338 break;
339 }
340 else {
341 activeElement = newActiveElement;
342 }
343 }
344 return activeElement;
345 }
346 /** Gets the target of an event while accounting for Shadow DOM. */
347 function _getEventTarget(event) {
348 // If an event is bound outside the Shadow DOM, the `event.target` will
349 // point to the shadow root so we have to use `composedPath` instead.
350 return (event.composedPath ? event.composedPath()[0] : event.target);
351 }
352
353 /**
354 * @license
355 * Copyright Google LLC All Rights Reserved.
356 *
357 * Use of this source code is governed by an MIT-style license that can be
358 * found in the LICENSE file at https://angular.io/license
359 */
360
361 /**
362 * Generated bundle index. Do not edit.
363 */
364
365 exports.Platform = Platform;
366 exports.PlatformModule = PlatformModule;
367 exports._getEventTarget = _getEventTarget;
368 exports._getFocusedElementPierceShadowDom = _getFocusedElementPierceShadowDom;
369 exports._getShadowRoot = _getShadowRoot;
370 exports._supportsShadowDom = _supportsShadowDom;
371 exports.getRtlScrollAxisType = getRtlScrollAxisType;
372 exports.getSupportedInputTypes = getSupportedInputTypes;
373 exports.normalizePassiveListenerOptions = normalizePassiveListenerOptions;
374 exports.supportsPassiveEventListeners = supportsPassiveEventListeners;
375 exports.supportsScrollBehavior = supportsScrollBehavior;
376
377 Object.defineProperty(exports, '__esModule', { value: true });
378
379})));
380//# sourceMappingURL=cdk-platform.umd.js.map