(function(z,G){typeof exports=="object"&&typeof module<"u"?G(exports):typeof define=="function"&&define.amd?define(["exports"],G):(z=typeof globalThis<"u"?globalThis:z||self,G(z["fluid-svg"]={}))})(this,function(z){"use strict";function G(s,t=2,o=!0){const e=t/10,n=s[0],r=s[1],l=s[s.length-1];return(o?[l,...s,n,r]:s).reduce((f,h,i,a)=>{if(i<2||i>a.length-2)return f;const[S,b]=a[i-2],[m,w]=a[i-1],[d,$]=h,[k,T]=a[i+1],c=m+(d-S)*e,y=w+($-b)*e,F=d-(k-m)*e,A=$-(T-w)*e,E=`C ${c},${y} ${F},${A} ${d},${$}`;return f+E},`M ${n[0]},${n[1]} `)}const et=1/3,W=1/6,U=s=>Math.floor(s)|0,X=new Float64Array([1,1,0,-1,1,0,1,-1,0,-1,-1,0,1,0,1,-1,0,1,1,0,-1,-1,0,-1,0,1,1,0,-1,1,0,1,-1,0,-1,-1]);function H(s=Math.random){const t=nt(s),o=new Float64Array(t).map(r=>X[r%12*3]),e=new Float64Array(t).map(r=>X[r%12*3+1]),n=new Float64Array(t).map(r=>X[r%12*3+2]);return function(l,u,p){let f,h,i,a;const S=(l+u+p)*et,b=U(l+S),m=U(u+S),w=U(p+S),d=(b+m+w)*W,$=b-d,k=m-d,T=w-d,c=l-$,y=u-k,F=p-T;let A,E,C,x,g,P;c>=y?y>=F?(A=1,E=0,C=0,x=1,g=1,P=0):c>=F?(A=1,E=0,C=0,x=1,g=0,P=1):(A=0,E=0,C=1,x=1,g=0,P=1):y{const k=S[$],T=u(k[0]*n,k[1]*n,l);return tt(s,d,e,T)}),w=`${G(b,2,!1)} L ${h[0]},${h[1]} L ${i[0]},${i[1]} Z`;return{pointsOrigins:a,pointsPositions:b,pointsNoiseCoords:S,path:w,corners:[h,i]}}function st(s,t){let o,e,n,r;switch(s){case"top":o=[-.2,t],e=[1.2,t],n=[1.2,-.2],r=[-.2,-.2];break;case"right":o=[1-t,-.2],e=[1-t,1.2],n=[1.2,1.2],r=[1.2,-.2];break;case"bottom":o=[-.2,1-t],e=[1.2,1-t],n=[1.2,1.2],r=[-.2,1.2];break;case"left":o=[t,-.2],e=[t,1.2],n=[-.2,1.2],r=[-.2,-.2];break}return{start:o,end:e,corner1:n,corner2:r}}function rt(s,t,o){return t.map(n=>{switch(s){case"top":return[n[0],n[1]*o];case"right":return[n[0]*o,n[1]];case"bottom":return[n[0],n[1]*o];case"left":return[n[0]*o,n[1]]}})}function tt(s,t,o,e){let n;switch(s){case"top":n=[t[0],t[1]+e*o/2];break;case"right":n=[t[0]+e*o/2,t[1]];break;case"bottom":n=[t[0],t[1]+e*o/2];break;case"left":n=[t[0]+e*o/2,t[1]];break}return n}function ct(s,t,o,e,n,r){const{pointsOrigins:l,pointsNoiseCoords:u,corners:[p,f]}=t,h=l.map((S,b)=>{const m=u[b],w=r(m[0]*e,m[1]*e,n);return tt(s,S,o,w)}),a=`${G(h,2,!1)} L ${p[0]},${p[1]} L ${f[0]},${f[1]} Z`;return{...t,pointsPositions:h,path:a}}function it(s){const t=typeof s=="string"?document.querySelector(s):s;if(!t)return console.error("Fluid-Waves: SVG element not found"),{svgElement:null,pathElements:null};if(!(t instanceof SVGSVGElement))return console.error("Fluid-Waves: Element is not an SVG element"),{svgElement:null,pathElements:null};const o=Array.from(t.querySelectorAll("path"));return o.length===0?(console.error("Fluid-Waves: No PATH elements found"),{svgElement:t,pathElements:null}):{svgElement:t,pathElements:o}}function at(s,{position:t="bottom",speed:o=2,lowestWaveHeight:e=2,highestWaveHeight:n=8,smoothness:r=10,amplitude:l=1,complexity:u=2,differenceBetweenWaves:p=3}){const f=o/1e4,h=e/10,i=n/10,a=l/10,S=p/10,{svgElement:b,pathElements:m}=it(s);if(!b||!m)return;const w=i-h,d=m.map((g,P)=>m.length===1?h:i-w*(P/(m.length-1))),$=H();let k=0;const T=d.map((g,P)=>R(t,g,r,a,u,S*P,k,$));let c=null,y;function F(g){if(!m)return;y||(y=g-17);const P=g-y,j=P<17?P:17;k+=j*f,T.forEach((D,N)=>{const I=ct(t,D,a,u,k,$);m[N].setAttribute("d",I.path)}),c=requestAnimationFrame(F)}const A=new IntersectionObserver(([g])=>g.isIntersecting?E():C());A.observe(b);function E(){c||(c=requestAnimationFrame(F))}function C(){c&&(cancelAnimationFrame(c),c=null)}function x(){A.disconnect(),c&&cancelAnimationFrame(c)}return{destroy:x}}function lt(s,{position:t="bottom",lowestWaveHeight:o=2,highestWaveHeight:e=8,smoothness:n=10,amplitude:r=1,complexity:l=2,differenceBetweenWaves:u=3}){if(s<1)return console.error("Number of waves must be greater than 0"),[];const p=o/10,f=e/10,h=r/10,i=u/10,a=f-p,S=Array.from({length:s}).map((d,$)=>s===1?p:f-a*($/(s-1))),b=H();return S.map((d,$)=>R(t,d,n,h,l,i*$,0,b)).map(({path:d})=>d)}z.animateWaves=at,z.createCubicSpline=G,z.getRandomWaves=lt,Object.defineProperty(z,Symbol.toStringTag,{value:"Module"})});