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iFAAiF;QACjF,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,eAAe,GAAG,KAAK,CAAC;IACpD,CAAC;IAED;;OAEG;IACH,gDAAuB,GAAvB;QACE,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;YACxB,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;IACH,qBAAC;AAAD,CAtIA,AAsIC,IAAA","file":"core/ripple/ripple-renderer.js","sourcesContent":["import {\n ElementRef,\n} from '@angular/core';\n\n/** TODO: internal */\nexport enum ForegroundRippleState {\n NEW,\n EXPANDING,\n FADING_OUT,\n}\n\n/**\n * Wrapper for a foreground ripple DOM element and its animation state.\n * TODO: internal\n */\nexport class ForegroundRipple {\n state = ForegroundRippleState.NEW;\n constructor(public rippleElement: Element) {}\n}\n\nconst RIPPLE_SPEED_PX_PER_SECOND = 1000;\nconst MIN_RIPPLE_FILL_TIME_SECONDS = 0.1;\nconst MAX_RIPPLE_FILL_TIME_SECONDS = 0.3;\n\n/**\n * Returns the distance from the point (x, y) to the furthest corner of a rectangle.\n */\nconst distanceToFurthestCorner = (x: number, y: number, rect: ClientRect) => {\n const distX = Math.max(Math.abs(x - rect.left), Math.abs(x - rect.right));\n const distY = Math.max(Math.abs(y - rect.top), Math.abs(y - rect.bottom));\n return Math.sqrt(distX * distX + distY * distY);\n};\n\n/**\n * Helper service that performs DOM manipulations. Not intended to be used outside this module.\n * The constructor takes a reference to the ripple directive's host element and a map of DOM\n * event handlers to be installed on the element that triggers ripple animations.\n * This will eventually become a custom renderer once Angular support exists.\n * TODO: internal\n */\nexport class RippleRenderer {\n private _backgroundDiv: HTMLElement;\n private _rippleElement: HTMLElement;\n private _triggerElement: HTMLElement;\n\n constructor(_elementRef: ElementRef, private _eventHandlers: Map<string, (e: Event) => void>) {\n this._rippleElement = _elementRef.nativeElement;\n // It might be nice to delay creating the background until it's needed, but doing this in\n // fadeInRippleBackground causes the first click event to not be handled reliably.\n this._backgroundDiv = document.createElement('div');\n this._backgroundDiv.classList.add('md-ripple-background');\n this._rippleElement.appendChild(this._backgroundDiv);\n }\n\n /**\n * Installs event handlers on the given trigger element, and removes event handlers from the\n * previous trigger if needed.\n */\n setTriggerElement(newTrigger: HTMLElement) {\n if (this._triggerElement !== newTrigger) {\n if (this._triggerElement) {\n this._eventHandlers.forEach((eventHandler, eventName) => {\n this._triggerElement.removeEventListener(eventName, eventHandler);\n });\n }\n this._triggerElement = newTrigger;\n if (this._triggerElement) {\n this._eventHandlers.forEach((eventHandler, eventName) => {\n this._triggerElement.addEventListener(eventName, eventHandler);\n });\n }\n }\n }\n\n /**\n * Installs event handlers on the host element of the md-ripple directive.\n */\n setTriggerElementToHost() {\n this.setTriggerElement(this._rippleElement);\n }\n\n /**\n * Removes event handlers from the current trigger element if needed.\n */\n clearTriggerElement() {\n this.setTriggerElement(null);\n }\n\n /**\n * Creates a foreground ripple and sets its animation to expand and fade in from the position\n * given by rippleOriginLeft and rippleOriginTop (or from the center of the <md-ripple>\n * bounding rect if centered is true).\n */\n createForegroundRipple(\n rippleOriginLeft: number,\n rippleOriginTop: number,\n color: string,\n centered: boolean,\n radius: number,\n speedFactor: number,\n transitionEndCallback: (r: ForegroundRipple, e: TransitionEvent) => void) {\n const parentRect = this._rippleElement.getBoundingClientRect();\n // Create a foreground ripple div with the size and position of the fully expanded ripple.\n // When the div is created, it's given a transform style that causes the ripple to be displayed\n // small and centered on the event location (or the center of the bounding rect if the centered\n // argument is true). Removing that transform causes the ripple to animate to its natural size.\n const startX = centered ? (parentRect.left + parentRect.width / 2) : rippleOriginLeft;\n const startY = centered ? (parentRect.top + parentRect.height / 2) : rippleOriginTop;\n const offsetX = startX - parentRect.left;\n const offsetY = startY - parentRect.top;\n const maxRadius = radius > 0 ? radius : distanceToFurthestCorner(startX, startY, parentRect);\n\n const rippleDiv = document.createElement('div');\n this._rippleElement.appendChild(rippleDiv);\n rippleDiv.classList.add('md-ripple-foreground');\n rippleDiv.style.left = `${offsetX - maxRadius}px`;\n rippleDiv.style.top = `${offsetY - maxRadius}px`;\n rippleDiv.style.width = `${2 * maxRadius}px`;\n rippleDiv.style.height = rippleDiv.style.width;\n // If color input is not set, this will default to the background color defined in CSS.\n rippleDiv.style.backgroundColor = color;\n // Start the ripple tiny.\n rippleDiv.style.transform = `scale(0.001)`;\n\n const fadeInSeconds = (1 / (speedFactor || 1)) * Math.max(\n MIN_RIPPLE_FILL_TIME_SECONDS,\n Math.min(MAX_RIPPLE_FILL_TIME_SECONDS, maxRadius / RIPPLE_SPEED_PX_PER_SECOND));\n rippleDiv.style.transitionDuration = `${fadeInSeconds}s`;\n\n // https://timtaubert.de/blog/2012/09/css-transitions-for-dynamically-created-dom-elements/\n window.getComputedStyle(rippleDiv).opacity;\n\n rippleDiv.classList.add('md-ripple-fade-in');\n // Clearing the transform property causes the ripple to animate to its full size.\n rippleDiv.style.transform = '';\n const ripple = new ForegroundRipple(rippleDiv);\n ripple.state = ForegroundRippleState.EXPANDING;\n\n rippleDiv.addEventListener('transitionend',\n (event: TransitionEvent) => transitionEndCallback(ripple, event));\n }\n\n /**\n * Fades out a foreground ripple after it has fully expanded and faded in.\n */\n fadeOutForegroundRipple(ripple: Element) {\n ripple.classList.remove('md-ripple-fade-in');\n ripple.classList.add('md-ripple-fade-out');\n }\n\n /**\n * Removes a foreground ripple from the DOM after it has faded out.\n */\n removeRippleFromDom(ripple: Element) {\n ripple.parentElement.removeChild(ripple);\n }\n\n /**\n * Fades in the ripple background.\n */\n fadeInRippleBackground(color: string) {\n this._backgroundDiv.classList.add('md-ripple-active');\n // If color is not set, this will default to the background color defined in CSS.\n this._backgroundDiv.style.backgroundColor = color;\n }\n\n /**\n * Fades out the ripple background.\n */\n fadeOutRippleBackground() {\n if (this._backgroundDiv) {\n this._backgroundDiv.classList.remove('md-ripple-active');\n }\n }\n}\n"],"sourceRoot":"/source/"}
\No newline at end of file