import e from"../../../../@babel/runtime/helpers/esm/extends.js";import t from"../../../../@babel/runtime/helpers/esm/toConsumableArray.js";import r from"../../../../@babel/runtime/helpers/esm/objectWithoutProperties.js";import*as n from"react";import i from"../../../../prop-types/index.js";import o from"../../../../clsx/dist/clsx.m.js";import s from"../styles/withStyles.js";import a from"./Ripple.js";import l from"../../../../react-transition-group/esm/TransitionGroup.js";var c=80,u=function(e){return{root:{overflow:"hidden",pointerEvents:"none",position:"absolute",zIndex:0,top:0,right:0,bottom:0,left:0,borderRadius:"inherit"},ripple:{opacity:0,position:"absolute"},rippleVisible:{opacity:.3,transform:"scale(1)",animation:"$enter ".concat(550,"ms ").concat(e.transitions.easing.easeInOut)},ripplePulsate:{animationDuration:"".concat(e.transitions.duration.shorter,"ms")},child:{opacity:1,display:"block",width:"100%",height:"100%",borderRadius:"50%",backgroundColor:"currentColor"},childLeaving:{opacity:0,animation:"$exit ".concat(550,"ms ").concat(e.transitions.easing.easeInOut)},childPulsate:{position:"absolute",left:0,top:0,animation:"$pulsate 2500ms ".concat(e.transitions.easing.easeInOut," 200ms infinite")},"@keyframes enter":{"0%":{transform:"scale(0)",opacity:.1},"100%":{transform:"scale(1)",opacity:.3}},"@keyframes exit":{"0%":{opacity:1},"100%":{opacity:0}},"@keyframes pulsate":{"0%":{transform:"scale(1)"},"50%":{transform:"scale(0.92)"},"100%":{transform:"scale(1)"}}}},p=n.forwardRef((function(i,s){var c=i.center,u=void 0!==c&&c,p=i.classes,m=i.className,f=r(i,["center","classes","className"]),h=n.useState([]),d=h[0],b=h[1],v=n.useRef(0),y=n.useRef(null);n.useEffect((function(){y.current&&(y.current(),y.current=null)}),[d]);var g=n.useRef(!1),M=n.useRef(null),R=n.useRef(null),w=n.useRef(null);n.useEffect((function(){return function(){clearTimeout(M.current)}}),[]);var x=n.useCallback((function(e){var r=e.pulsate,i=e.rippleX,o=e.rippleY,s=e.rippleSize,l=e.cb;b((function(e){return[].concat(t(e),[n.createElement(a,{key:v.current,classes:p,timeout:550,pulsate:r,rippleX:i,rippleY:o,rippleSize:s})])})),v.current+=1,y.current=l}),[p]),k=n.useCallback((function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0,n=t.pulsate,i=void 0!==n&&n,o=t.center,s=void 0===o?u||t.pulsate:o,a=t.fakeElement,l=void 0!==a&&a;if("mousedown"===e.type&&g.current)g.current=!1;else{"touchstart"===e.type&&(g.current=!0);var c,p,m,f=l?null:w.current,h=f?f.getBoundingClientRect():{width:0,height:0,left:0,top:0};if(s||0===e.clientX&&0===e.clientY||!e.clientX&&!e.touches)c=Math.round(h.width/2),p=Math.round(h.height/2);else{var d=e.touches?e.touches[0]:e,b=d.clientX,v=d.clientY;c=Math.round(b-h.left),p=Math.round(v-h.top)}if(s)(m=Math.sqrt((2*Math.pow(h.width,2)+Math.pow(h.height,2))/3))%2==0&&(m+=1);else{var y=2*Math.max(Math.abs((f?f.clientWidth:0)-c),c)+2,k=2*Math.max(Math.abs((f?f.clientHeight:0)-p),p)+2;m=Math.sqrt(Math.pow(y,2)+Math.pow(k,2))}e.touches?null===R.current&&(R.current=function(){x({pulsate:i,rippleX:c,rippleY:p,rippleSize:m,cb:r})},M.current=setTimeout((function(){R.current&&(R.current(),R.current=null)}),80)):x({pulsate:i,rippleX:c,rippleY:p,rippleSize:m,cb:r})}}),[u,x]),j=n.useCallback((function(){k({},{pulsate:!0})}),[k]),E=n.useCallback((function(e,t){if(clearTimeout(M.current),"touchend"===e.type&&R.current)return e.persist(),R.current(),R.current=null,void(M.current=setTimeout((function(){E(e,t)})));R.current=null,b((function(e){return e.length>0?e.slice(1):e})),y.current=t}),[]);return n.useImperativeHandle(s,(function(){return{pulsate:j,start:k,stop:E}}),[j,k,E]),n.createElement("span",e({className:o(p.root,m),ref:w},f),n.createElement(l,{component:null,exit:!0},d))}));"production"!==process.env.NODE_ENV&&(p.propTypes={center:i.bool,classes:i.object.isRequired,className:i.string});var m=s(u,{flip:!1,name:"MuiTouchRipple"})(n.memo(p));export default m;export{c as DELAY_RIPPLE,u as styles};
//# sourceMappingURL=TouchRipple.js.map
