@limetech/mdc-ripple
Version:
The Material Components for the web Ink Ripple effect for web element interactions
75 lines • 3.12 kB
JavaScript
/**
* Stores result from supportsCssVariables to avoid redundant processing to
* detect CSS custom variable support.
*/
var supportsCssVariables_;
function detectEdgePseudoVarBug(windowObj) {
// Detect versions of Edge with buggy var() support
// See: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/11495448/
var document = windowObj.document;
var node = document.createElement('div');
node.className = 'mdc-ripple-surface--test-edge-var-bug';
// Append to head instead of body because this script might be invoked in the
// head, in which case the body doesn't exist yet. The probe works either way.
document.head.appendChild(node);
// The bug exists if ::before style ends up propagating to the parent element.
// Additionally, getComputedStyle returns null in iframes with display: "none" in Firefox,
// but Firefox is known to support CSS custom properties correctly.
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=548397
var computedStyle = windowObj.getComputedStyle(node);
var hasPseudoVarBug = computedStyle !== null && computedStyle.borderTopStyle === 'solid';
if (node.parentNode) {
node.parentNode.removeChild(node);
}
return hasPseudoVarBug;
}
export function supportsCssVariables(windowObj, forceRefresh) {
if (forceRefresh === void 0) { forceRefresh = false; }
var CSS = windowObj.CSS;
var supportsCssVars = supportsCssVariables_;
if (typeof supportsCssVariables_ === 'boolean' && !forceRefresh) {
return supportsCssVariables_;
}
var supportsFunctionPresent = CSS && typeof CSS.supports === 'function';
if (!supportsFunctionPresent) {
return false;
}
var explicitlySupportsCssVars = CSS.supports('--css-vars', 'yes');
// See: https://bugs.webkit.org/show_bug.cgi?id=154669
// See: README section on Safari
var weAreFeatureDetectingSafari10plus = (CSS.supports('(--css-vars: yes)') &&
CSS.supports('color', '#00000000'));
if (explicitlySupportsCssVars || weAreFeatureDetectingSafari10plus) {
supportsCssVars = !detectEdgePseudoVarBug(windowObj);
}
else {
supportsCssVars = false;
}
if (!forceRefresh) {
supportsCssVariables_ = supportsCssVars;
}
return supportsCssVars;
}
export function getNormalizedEventCoords(evt, pageOffset, clientRect) {
if (!evt) {
return { x: 0, y: 0 };
}
var x = pageOffset.x, y = pageOffset.y;
var documentX = x + clientRect.left;
var documentY = y + clientRect.top;
var normalizedX;
var normalizedY;
// Determine touch point relative to the ripple container.
if (evt.type === 'touchstart') {
var touchEvent = evt;
normalizedX = touchEvent.changedTouches[0].pageX - documentX;
normalizedY = touchEvent.changedTouches[0].pageY - documentY;
}
else {
var mouseEvent = evt;
normalizedX = mouseEvent.pageX - documentX;
normalizedY = mouseEvent.pageY - documentY;
}
return { x: normalizedX, y: normalizedY };
}
//# sourceMappingURL=util.js.map