canIUse.js 1.6 KB

12345678910111213141516171819202122232425262728293031
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. import * as browser from './browser.js';
  6. import * as platform from '../common/platform.js';
  7. /**
  8. * Browser feature we can support in current platform, browser and environment.
  9. */
  10. export const BrowserFeatures = {
  11. clipboard: {
  12. writeText: (platform.isNative
  13. || (document.queryCommandSupported && document.queryCommandSupported('copy'))
  14. || !!(navigator && navigator.clipboard && navigator.clipboard.writeText)),
  15. readText: (platform.isNative
  16. || !!(navigator && navigator.clipboard && navigator.clipboard.readText))
  17. },
  18. keyboard: (() => {
  19. if (platform.isNative || browser.isStandalone) {
  20. return 0 /* Always */;
  21. }
  22. if (navigator.keyboard || browser.isSafari) {
  23. return 1 /* FullScreen */;
  24. }
  25. return 2 /* None */;
  26. })(),
  27. // 'ontouchstart' in window always evaluates to true with typescript's modern typings. This causes `window` to be
  28. // `never` later in `window.navigator`. That's why we need the explicit `window as Window` cast
  29. touch: 'ontouchstart' in window || navigator.maxTouchPoints > 0,
  30. pointerEvents: window.PointerEvent && ('ontouchstart' in window || window.navigator.maxTouchPoints > 0 || navigator.maxTouchPoints > 0)
  31. };