get-support.js 1020 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { getWindow, getDocument } from 'ssr-window';
  2. let support;
  3. function calcSupport() {
  4. const window = getWindow();
  5. const document = getDocument();
  6. return {
  7. smoothScroll: document.documentElement && 'scrollBehavior' in document.documentElement.style,
  8. touch: !!('ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch),
  9. passiveListener: function checkPassiveListener() {
  10. let supportsPassive = false;
  11. try {
  12. const opts = Object.defineProperty({}, 'passive', {
  13. // eslint-disable-next-line
  14. get() {
  15. supportsPassive = true;
  16. }
  17. });
  18. window.addEventListener('testPassiveListener', null, opts);
  19. } catch (e) {// No support
  20. }
  21. return supportsPassive;
  22. }(),
  23. gestures: function checkGestures() {
  24. return 'ongesturestart' in window;
  25. }()
  26. };
  27. }
  28. function getSupport() {
  29. if (!support) {
  30. support = calcSupport();
  31. }
  32. return support;
  33. }
  34. export { getSupport };