util.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * Stores result from supportsCssVariables to avoid redundant processing to
  3. * detect CSS custom variable support.
  4. */
  5. var supportsCssVariables_;
  6. export function supportsCssVariables(windowObj, forceRefresh) {
  7. if (forceRefresh === void 0) { forceRefresh = false; }
  8. var CSS = windowObj.CSS;
  9. var supportsCssVars = supportsCssVariables_;
  10. if (typeof supportsCssVariables_ === 'boolean' && !forceRefresh) {
  11. return supportsCssVariables_;
  12. }
  13. var supportsFunctionPresent = CSS && typeof CSS.supports === 'function';
  14. if (!supportsFunctionPresent) {
  15. return false;
  16. }
  17. var explicitlySupportsCssVars = CSS.supports('--css-vars', 'yes');
  18. // See: https://bugs.webkit.org/show_bug.cgi?id=154669
  19. // See: README section on Safari
  20. var weAreFeatureDetectingSafari10plus = (CSS.supports('(--css-vars: yes)') && CSS.supports('color', '#00000000'));
  21. supportsCssVars =
  22. explicitlySupportsCssVars || weAreFeatureDetectingSafari10plus;
  23. if (!forceRefresh) {
  24. supportsCssVariables_ = supportsCssVars;
  25. }
  26. return supportsCssVars;
  27. }
  28. export function getNormalizedEventCoords(evt, pageOffset, clientRect) {
  29. if (!evt) {
  30. return { x: 0, y: 0 };
  31. }
  32. var x = pageOffset.x, y = pageOffset.y;
  33. var documentX = x + clientRect.left;
  34. var documentY = y + clientRect.top;
  35. var normalizedX;
  36. var normalizedY;
  37. // Determine touch point relative to the ripple container.
  38. if (evt.type === 'touchstart') {
  39. var touchEvent = evt;
  40. normalizedX = touchEvent.changedTouches[0].pageX - documentX;
  41. normalizedY = touchEvent.changedTouches[0].pageY - documentY;
  42. }
  43. else {
  44. var mouseEvent = evt;
  45. normalizedX = mouseEvent.pageX - documentX;
  46. normalizedY = mouseEvent.pageY - documentY;
  47. }
  48. return { x: normalizedX, y: normalizedY };
  49. }
  50. //# sourceMappingURL=util.js.map