import e from"lottie-web";export{default as LottiePlayer}from"lottie-web";import t,{useState as n,useRef as r,useEffect as o}from"react";function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n0&&void 0!==arguments[0]?arguments[0]:{};if(T.current){null===(t=E.current)||void 0===t||t.destroy();var r=l(l(l({},i),n),{},{container:T.current});return E.current=e.loadAnimation(r),L(!!E.current),function(){var e;null===(e=E.current)||void 0===e||e.destroy(),E.current=void 0}}}();return function(){return null==t?void 0:t()}}),[u,d]),o((function(){E.current&&(E.current.autoplay=!!m)}),[m]),o((function(){E.current&&(p?Array.isArray(p)&&p.length&&((E.current.currentRawFramep[1])&&(E.current.currentRawFrame=p[0]),E.current.setSegment(p[0],p[1])):E.current.resetSegments(!0))}),[p]),o((function(){var e=[{name:"complete",handler:y},{name:"loopComplete",handler:v},{name:"enterFrame",handler:g},{name:"segmentStart",handler:b},{name:"config_ready",handler:S},{name:"data_ready",handler:h},{name:"data_failed",handler:w},{name:"loaded_images",handler:A},{name:"DOMLoaded",handler:O},{name:"destroy",handler:D}].filter((function(e){return null!=e.handler}));if(e.length){var t=e.map((function(e){var t;return null===(t=E.current)||void 0===t||t.addEventListener(e.name,e.handler),function(){var t;null===(t=E.current)||void 0===t||t.removeEventListener(e.name,e.handler)}}));return function(){t.forEach((function(e){return e()}))}}}),[y,v,g,b,S,h,w,A,O,D]),{View:t.createElement("div",l({style:a,ref:T},P)),play:function(){var e;null===(e=E.current)||void 0===e||e.play()},stop:function(){var e;null===(e=E.current)||void 0===e||e.stop()},pause:function(){var e;null===(e=E.current)||void 0===e||e.pause()},setSpeed:function(e){var t;null===(t=E.current)||void 0===t||t.setSpeed(e)},goToAndStop:function(e,t){var n;null===(n=E.current)||void 0===n||n.goToAndStop(e,t)},goToAndPlay:function(e,t){var n;null===(n=E.current)||void 0===n||n.goToAndPlay(e,t)},setDirection:function(e){var t;null===(t=E.current)||void 0===t||t.setDirection(e)},playSegments:function(e,t){var n;null===(n=E.current)||void 0===n||n.playSegments(e,t)},setSubframe:function(e){var t;null===(t=E.current)||void 0===t||t.setSubframe(e)},getDuration:function(e){var t;return null===(t=E.current)||void 0===t?void 0:t.getDuration(e)},destroy:function(){var e;null===(e=E.current)||void 0===e||e.destroy(),E.current=void 0},animationContainerRef:T,animationLoaded:R,animationItem:E.current}};var m=function(e){var t=e.wrapperRef,n=e.animationItem,r=e.mode,i=e.actions;o((function(){var e=t.current;if(e&&n&&i.length){n.stop();var o,a,u,l,s;switch(r){case"scroll":return l=null,s=function(){var t,r,o,a=(r=(t=e.getBoundingClientRect()).top,o=t.height,(window.innerHeight-r)/(window.innerHeight+o)),u=i.find((function(e){var t=e.visibility;return t&&a>=t[0]&&a<=t[1]}));if(u){if("seek"===u.type&&u.visibility&&2===u.frames.length){var s=u.frames[0]+Math.ceil((a-u.visibility[0])/(u.visibility[1]-u.visibility[0])*u.frames[1]); //! goToAndStop must be relative to the start of the current segment n.goToAndStop(s-n.firstFrame-1,!0)}"loop"===u.type&&(null===l||l!==u.frames||n.isPaused)&&(n.playSegments(u.frames,!0),l=u.frames),"play"===u.type&&n.isPaused&&(n.resetSegments(!0),n.play()),"stop"===u.type&&n.goToAndStop(u.frames[0]-n.firstFrame-1,!0)}},document.addEventListener("scroll",s),function(){document.removeEventListener("scroll",s)};case"cursor":return o=function(t,r){var o,a,u,l,s=t,c=r;if(-1!==s&&-1!==c){var f=(o=s,a=c,l=(u=e.getBoundingClientRect()).top,{x:(o-u.left)/u.width,y:(a-l)/u.height});s=f.x,c=f.y}var d=i.find((function(e){var t=e.position;return t&&Array.isArray(t.x)&&Array.isArray(t.y)?s>=t.x[0]&&s<=t.x[1]&&c>=t.y[0]&&c<=t.y[1]:!(!t||Number.isNaN(t.x)||Number.isNaN(t.y))&&s===t.x&&c===t.y}));if(d){if("seek"===d.type&&d.position&&Array.isArray(d.position.x)&&Array.isArray(d.position.y)&&2===d.frames.length){var m=(s-d.position.x[0])/(d.position.x[1]-d.position.x[0]),p=(c-d.position.y[0])/(d.position.y[1]-d.position.y[0]);n.playSegments(d.frames,!0),n.goToAndStop(Math.ceil((m+p)/2*(d.frames[1]-d.frames[0])),!0)}"loop"===d.type&&n.playSegments(d.frames,!0),"play"===d.type&&(n.isPaused&&n.resetSegments(!1),n.playSegments(d.frames)),"stop"===d.type&&n.goToAndStop(d.frames[0],!0)}},a=function(e){o(e.clientX,e.clientY)},u=function(){o(-1,-1)},e.addEventListener("mousemove",a),e.addEventListener("mouseout",u),function(){e.removeEventListener("mousemove",a),e.removeEventListener("mouseout",u)}}}}),[r,n])},p=function(e){var t=e.actions,n=e.mode,r=e.lottieObj,o=r.animationItem,i=r.View,a=r.animationContainerRef;return m({actions:t,animationItem:o,mode:n,wrapperRef:a}),i},y=["style","interactivity"],v=function(e){var t,n,r,i=e.style,a=e.interactivity,u=s(e,y),l=d(u,i),c=l.View,f=l.play,m=l.stop,v=l.pause,g=l.setSpeed,b=l.goToAndStop,S=l.goToAndPlay,h=l.setDirection,w=l.playSegments,A=l.setSubframe,O=l.getDuration,D=l.destroy,P=l.animationContainerRef,j=l.animationLoaded,R=l.animationItem;return o((function(){e.lottieRef&&(e.lottieRef.current={play:f,stop:m,pause:v,setSpeed:g,goToAndPlay:S,goToAndStop:b,setDirection:h,playSegments:w,setSubframe:A,getDuration:O,destroy:D,animationContainerRef:P,animationLoaded:j,animationItem:R})}),[null===(t=e.lottieRef)||void 0===t?void 0:t.current]),p({lottieObj:{View:c,play:f,stop:m,pause:v,setSpeed:g,goToAndStop:b,goToAndPlay:S,setDirection:h,playSegments:w,setSubframe:A,getDuration:O,destroy:D,animationContainerRef:P,animationLoaded:j,animationItem:R},actions:null!==(n=null==a?void 0:a.actions)&&void 0!==n?n:[],mode:null!==(r=null==a?void 0:a.mode)&&void 0!==r?r:"scroll"})};export{v as default,d as useLottie,p as useLottieInteractivity};