@votax572002/fluxfx 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
- var ce=["normal","reduced-res","low-fps","survival"];var Q=class{constructor(e){this.idx=0;this.count=0;this.lastSampleAt=0;this.samples=new Float32Array(e)}push(e,t){this.samples[this.idx]=e,this.idx=(this.idx+1)%this.samples.length,this.count<this.samples.length&&this.count++,this.lastSampleAt=t}reset(){this.idx=0,this.count=0,this.lastSampleAt=0}isReady(e,t){return this.count>=this.samples.length&&e-this.lastSampleAt<=t}compute(){if(this.count===0)return{avgMs:0,slowRatio:0};let e=0,t=0;for(let i=0;i<this.count;i++){let r=this.samples[i];e+=r,r>26&&t++}return{avgMs:e/this.count,slowRatio:t/this.count}}},J=class{constructor(){this.mainChannel=new Q(30);this.gpuChannel=new Q(12);this.listeners=new Set;this.currentTier=0;this.lastEvalAt=0;this.lastTransitionAt=0;this.badChecks=0;this.goodChecks=0;this.lastAvgFrameMs=0;this.lastSlowRatio=0;this.survivalTimer=null}recordMainThread(e,t){e<=0||e>250||(this.mainChannel.push(e,t),this.maybeEvaluate(t))}recordGpuFrame(e,t,i){if(e<=0||e>250||t<=0)return;let r=e*(t/60);this.gpuChannel.push(r,i),this.maybeEvaluate(i)}resetMainThread(){this.mainChannel.reset()}resetAll(){this.mainChannel.reset(),this.gpuChannel.reset(),this.badChecks=0,this.goodChecks=0,this.lastAvgFrameMs=0,this.lastSlowRatio=0}onTierChange(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}get tier(){return this.currentTier}get label(){return ce[this.currentTier]}getSnapshot(){return{tier:this.currentTier,label:ce[this.currentTier],avgFrameMs:Math.round(this.lastAvgFrameMs*100)/100,slowFrameRatio:Math.round(this.lastSlowRatio*1e3)/1e3}}clearSurvivalProbe(){this.survivalTimer!==null&&(clearTimeout(this.survivalTimer),this.survivalTimer=null)}scheduleSurvivalProbe(){this.clearSurvivalProbe(),typeof setTimeout=="function"&&(this.survivalTimer=setTimeout(()=>{if(this.survivalTimer=null,this.currentTier===3){if(typeof document<"u"&&document.hidden){this.scheduleSurvivalProbe();return}this.mainChannel.reset(),this.gpuChannel.reset(),this.badChecks=0,this.goodChecks=0,this.setTier(2,performance.now())}},6e3))}maybeEvaluate(e){if(e-this.lastEvalAt<400)return;this.lastEvalAt=e;let t=this.mainChannel.isReady(e,1500),i=this.gpuChannel.isReady(e,2500);if(!t&&!i)return;let r=0,s=0;if(t){let a=this.mainChannel.compute();r=Math.max(r,a.avgMs),s=Math.max(s,a.slowRatio)}if(i){let a=this.gpuChannel.compute();r=Math.max(r,a.avgMs),s=Math.max(s,a.slowRatio)}if(this.lastAvgFrameMs=r,this.lastSlowRatio=s,r>22.5||s>=.35){this.badChecks++,this.goodChecks=0,this.badChecks>=2&&this.currentTier<3&&e-this.lastTransitionAt>=2e3&&(this.setTier(this.currentTier+1,e),this.badChecks=0);return}if(r<18.2&&s<.1){this.goodChecks++,this.badChecks=0,this.currentTier>0&&this.goodChecks>=3&&e-this.lastTransitionAt>=5e3&&(this.setTier(this.currentTier-1,e),this.goodChecks=0);return}this.badChecks=0,this.goodChecks=0}setTier(e,t){if(e===this.currentTier)return;let i=this.currentTier;this.currentTier=e,this.lastTransitionAt=t,e===3?this.scheduleSurvivalProbe():this.clearSurvivalProbe(),this.listeners.forEach(r=>r(e,i))}},D=new J;var Z=class{constructor(){this.listeners=new Set;this.visibilityListeners=new Set;this.rafId=null;this.startTime=0;this.lastTime=0;this.avgFrameTimeMs=0;this.isDocumentHidden=!1;this.handleVisibilityChange=()=>{this.isDocumentHidden=typeof document<"u"?document.hidden:!1,this.isDocumentHidden?(this.stopLoop(),D.resetAll()):this.listeners.size>0&&(this.lastTime=0,this.startLoop()),this.visibilityListeners.forEach(e=>{e(this.isDocumentHidden)})};this.tick=e=>{if(this.listeners.size===0||this.isDocumentHidden){this.stopLoop();return}this.startTime===0&&(this.startTime=e);let t=this.lastTime===0?16.67:e-this.lastTime,i=Math.min(t,100);this.lastTime=e,t>0&&t<500&&(this.avgFrameTimeMs=this.avgFrameTimeMs===0?t:this.avgFrameTimeMs*.9+t*.1),D.recordMainThread(t,e);let r=(e-this.startTime)*.001,s=i*.001;this.listeners.forEach(a=>{a(r,s,e)}),this.listeners.size>0&&!this.isDocumentHidden?this.rafId=window.requestAnimationFrame(this.tick):this.rafId=null};typeof document<"u"&&(this.isDocumentHidden=document.hidden,document.addEventListener("visibilitychange",this.handleVisibilityChange))}startLoop(){this.rafId!==null||typeof window>"u"||this.isDocumentHidden||(this.lastTime=0,this.rafId=window.requestAnimationFrame(this.tick))}stopLoop(){this.rafId!==null&&typeof window<"u"&&(window.cancelAnimationFrame(this.rafId),this.rafId=null),this.lastTime=0,this.avgFrameTimeMs=0,D.resetMainThread()}onVisibilityChange(e){return this.visibilityListeners.add(e),()=>{this.visibilityListeners.delete(e)}}add(e){return this.listeners.add(e),this.listeners.size===1&&this.startLoop(),()=>this.remove(e)}remove(e){this.listeners.delete(e),this.listeners.size===0&&this.stopLoop()}get isHidden(){return this.isDocumentHidden}get activeCount(){return this.listeners.size}get isRunning(){return this.rafId!==null}get frameTimeMs(){return!this.isRunning||this.avgFrameTimeMs<=0?0:Math.round(this.avgFrameTimeMs*100)/100}get fps(){return!this.isRunning||this.avgFrameTimeMs<=0?0:Math.round(1e3/this.avgFrameTimeMs)}},A=new Z;var y=class{static acquireVec2(e=0,t=0){let i=this.vec2Pool.pop()??new Float32Array(2);return i[0]=e,i[1]=t,i}static releaseVec2(e){this.vec2Pool.length<128&&this.vec2Pool.push(e)}static acquireVec3(e=0,t=0,i=0){let r=this.vec3Pool.pop()??new Float32Array(3);return r[0]=e,r[1]=t,r[2]=i,r}static releaseVec3(e){this.vec3Pool.length<128&&this.vec3Pool.push(e)}static acquireVec4(e=0,t=0,i=0,r=1){let s=this.vec4Pool.pop()??new Float32Array(4);return s[0]=e,s[1]=t,s[2]=i,s[3]=r,s}static releaseVec4(e){this.vec4Pool.length<128&&this.vec4Pool.push(e)}static hexToVec3Into(e,t){let i=e.charCodeAt(0)===35?e.slice(1):e;if(i.length===3){let s=parseInt(i[0],16),a=parseInt(i[1],16),n=parseInt(i[2],16);return t[0]=(s<<4|s)/255,t[1]=(a<<4|a)/255,t[2]=(n<<4|n)/255,t}let r=parseInt(i,16);return Number.isNaN(r)?(t[0]=1,t[1]=1,t[2]=1,t):(t[0]=(r>>16&255)/255,t[1]=(r>>8&255)/255,t[2]=(r&255)/255,t)}};y.vec2Pool=[],y.vec3Pool=[],y.vec4Pool=[],y.scratchVec2=new Float32Array(2),y.scratchVec3=new Float32Array(3),y.scratchVec4=new Float32Array(4);var $=class{constructor(e){this.samples=new Float32Array(30);this.sampleIdx=0;this.sampleCount=0;this.stableUpWindows=0;this.lastAdjustAt=0;this.minScale=Math.max(.5,e.minScale),this.maxScale=Math.max(this.minScale,e.maxScale),this.currentScale=this.maxScale,this.downThresholdMs=e.downThresholdMs??20.5,this.upThresholdMs=e.upThresholdMs??17.2,this.cooldownMs=e.cooldownMs??750}get scale(){return this.currentScale}setBounds(e,t){let i=Math.max(.5,e),r=Math.max(i,t),s=this.currentScale;return this.minScale=i,this.maxScale=r,this.currentScale=Math.min(r,Math.max(i,this.currentScale)),r>s&&(this.currentScale=r),this.sampleCount=0,this.sampleIdx=0,this.stableUpWindows=0,Math.abs(this.currentScale-s)>.01}recordFrame(e,t){if(this.minScale>=this.maxScale||e<=0||e>60)return!1;if(this.samples[this.sampleIdx]=e,this.sampleIdx=(this.sampleIdx+1)%this.samples.length,this.sampleCount<this.samples.length)return this.sampleCount++,!1;if(t-this.lastAdjustAt<this.cooldownMs)return!1;let i=0;for(let s=0;s<this.samples.length;s++)i+=this.samples[s];let r=i/this.samples.length;if(r>this.downThresholdMs&&this.currentScale>this.minScale)return this.currentScale=Math.max(this.minScale,Number((this.currentScale-.15).toFixed(2))),this.stableUpWindows=0,this.lastAdjustAt=t,!0;if(r<this.upThresholdMs&&this.currentScale<this.maxScale){if(this.stableUpWindows++,this.stableUpWindows>=2)return this.currentScale=Math.min(this.maxScale,Number((this.currentScale+.1).toFixed(2))),this.stableUpWindows=0,this.lastAdjustAt=t,!0}else this.stableUpWindows=0;return!1}};var V=null;function x(o,e="#ffffff"){if(typeof o!="string")return e;let t=o.trim();if(!t)return e;if(typeof document<"u"){if(!V){let i=document.createElement("canvas");i.width=1,i.height=1,V=i.getContext("2d")}if(V){V.fillStyle="#010203",V.fillStyle=t;let i=V.fillStyle;if(/^#[0-9a-f]{6}$/i.test(i))return i;let r=i.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);if(r)return"#"+[Number(r[1]),Number(r[2]),Number(r[3])].map(s=>Math.max(0,Math.min(255,s)).toString(16).padStart(2,"0")).join("")}}return e}function ue(o){let e=o.trim().toLowerCase();if(!e||e==="transparent"||e==="none")return null;let t=e.match(/^rgba?\(\s*([\d.]+)\s*[,\s]\s*([\d.]+)\s*[,\s]\s*([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/);if(t){let r=Math.max(0,Math.min(255,parseFloat(t[1])))/255,s=Math.max(0,Math.min(255,parseFloat(t[2])))/255,a=Math.max(0,Math.min(255,parseFloat(t[3])))/255,n=1;return t[4]!==void 0&&(n=t[4].endsWith("%")?parseFloat(t[4])/100:parseFloat(t[4])),[r,s,a,Math.max(0,Math.min(1,n))]}let i=e.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);if(i){let r=i[1],s=r.length===3?r.split("").map(a=>a+a).join(""):r;return[parseInt(s.slice(0,2),16)/255,parseInt(s.slice(2,4),16)/255,parseInt(s.slice(4,6),16)/255,1]}return null}function he(o,e,t){let i=r=>r<=.03928?r/12.92:Math.pow((r+.055)/1.055,2.4);return .2126*i(o)+.7152*i(e)+.0722*i(t)}function de(o){if(typeof document>"u"||typeof window>"u")return!0;let e=o;for(;e;){let a=(e.getAttribute("data-theme")||e.getAttribute("data-mode")||e.getAttribute("data-bs-theme")||"").trim().toLowerCase();if(a==="dark")return!0;if(a==="light")return!1;if(e.classList.contains("dark")||e.classList.contains("dark-mode"))return!0;if(e.classList.contains("light")||e.classList.contains("light-mode"))return!1;e=e.parentElement}let t=document.documentElement,i=document.body,r=(t?.getAttribute("data-theme")||t?.getAttribute("data-mode")||t?.getAttribute("data-bs-theme")||"").trim().toLowerCase();if(r==="dark")return!0;if(r==="light")return!1;if(t?.classList.contains("dark")||i?.classList.contains("dark"))return!0;if(t?.classList.contains("light")||i?.classList.contains("light"))return!1;let s=o;for(;s;){let a=window.getComputedStyle(s).backgroundColor,n=ue(a);if(n&&n[3]>.12)return he(n[0],n[1],n[2])<.42;s=s.parentElement}return typeof window.matchMedia=="function"?window.matchMedia("(prefers-color-scheme: dark)").matches:!0}function ee(o,e,t){let i=Math.max(o,e,t),r=Math.min(o,e,t),s=(i+r)*.5;if(i===r)return[0,0,s];let a=i-r,n=s>.5?a/(2-i-r):a/(i+r),l=0;return i===o?l=((e-t)/a+(e<t?6:0))/6:i===e?l=((t-o)/a+2)/6:l=((o-e)/a+4)/6,[l,n,s]}function fe(o,e,t){if(e===0)return[t,t,t];let i=(a,n,l)=>{let c=l;return c<0&&(c+=1),c>1&&(c-=1),c<1/6?a+(n-a)*6*c:c<1/2?n:c<2/3?a+(n-a)*(2/3-c)*6:a},r=t<.5?t*(1+e):t+e-t*e,s=2*t-r;return[i(s,r,o+1/3),i(s,r,o),i(s,r,o-1/3)]}function j(o,e){return o.map(([t,i,r])=>{let[s,a,n]=ee(t,i,r);if(e)return[t,i,r];let l=Math.min(a,.72)*.92,c=Math.max(.36,Math.min(.6,n*.78+.14));return fe(s,l,c)})}function me(o,e){if(typeof window>"u"||!o)return null;let t=o;for(;t;){if(t.getAttribute("data-fluxfx-canvas")!=="true"){let i=window.getComputedStyle(t).backgroundColor,r=ue(i);if(r&&r[3]>.14)return r}if(t===e)break;t=t.parentElement}return null}function pe(o,e){let[t,i,r]=ee(e[0],e[1],e[2]),s=he(e[0],e[1],e[2]);if(i<.2)return j(o,s<.42);let a=s<.38;return o.map(([n,l,c],u)=>{let[h,f,d]=ee(n,l,c),m=Math.abs(h-t),p=Math.min(m,1-m),v=h;if(p<.22){let U=[.46,.56,.34];v=(t+U[u%U.length])%1}let g=Math.max(.55,Math.min(.92,f<.35?.72:f)),b=a?Math.max(.68,Math.min(.86,d*.45+.48)):Math.max(.24,Math.min(.44,d*.5+.12)),S=Math.abs(b-r)<.22?a?Math.min(.88,r+.34):Math.max(.2,r-.34):b;return fe(v,g,S)})}var z=`#version 300 es
1
+ var xt=["normal","reduced-res","low-fps","survival"];var Je=class{constructor(e){this.idx=0;this.count=0;this.lastSampleAt=0;this.samples=new Float32Array(e)}push(e,t){this.samples[this.idx]=e,this.idx=(this.idx+1)%this.samples.length,this.count<this.samples.length&&this.count++,this.lastSampleAt=t}reset(){this.idx=0,this.count=0,this.lastSampleAt=0}isReady(e,t){return this.count>=this.samples.length&&e-this.lastSampleAt<=t}compute(){if(this.count===0)return{avgMs:0,slowRatio:0};let e=0,t=0;for(let o=0;o<this.count;o++){let r=this.samples[o];e+=r,r>26&&t++}return{avgMs:e/this.count,slowRatio:t/this.count}}},lt=class{constructor(){this.mainChannel=new Je(30);this.gpuChannel=new Je(12);this.listeners=new Set;this.currentTier=0;this.lastEvalAt=0;this.lastTransitionAt=0;this.badChecks=0;this.goodChecks=0;this.lastAvgFrameMs=0;this.lastSlowRatio=0;this.survivalTimer=null}recordMainThread(e,t){e<=0||e>250||(this.mainChannel.push(e,t),this.maybeEvaluate(t))}recordGpuFrame(e,t,o){if(e<=0||e>250||t<=0)return;let r=e*(t/60);this.gpuChannel.push(r,o),this.maybeEvaluate(o)}resetMainThread(){this.mainChannel.reset()}resetAll(){this.mainChannel.reset(),this.gpuChannel.reset(),this.badChecks=0,this.goodChecks=0,this.lastAvgFrameMs=0,this.lastSlowRatio=0}onTierChange(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}get tier(){return this.currentTier}get label(){return xt[this.currentTier]}getSnapshot(){return{tier:this.currentTier,label:xt[this.currentTier],avgFrameMs:Math.round(this.lastAvgFrameMs*100)/100,slowFrameRatio:Math.round(this.lastSlowRatio*1e3)/1e3}}clearSurvivalProbe(){this.survivalTimer!==null&&(clearTimeout(this.survivalTimer),this.survivalTimer=null)}scheduleSurvivalProbe(){this.clearSurvivalProbe(),typeof setTimeout=="function"&&(this.survivalTimer=setTimeout(()=>{if(this.survivalTimer=null,this.currentTier===3){if(typeof document<"u"&&document.hidden){this.scheduleSurvivalProbe();return}this.mainChannel.reset(),this.gpuChannel.reset(),this.badChecks=0,this.goodChecks=0,this.setTier(2,performance.now())}},6e3))}maybeEvaluate(e){if(e-this.lastEvalAt<400)return;this.lastEvalAt=e;let t=this.mainChannel.isReady(e,1500),o=this.gpuChannel.isReady(e,2500);if(!t&&!o)return;let r=0,s=0;if(t){let n=this.mainChannel.compute();r=Math.max(r,n.avgMs),s=Math.max(s,n.slowRatio)}if(o){let n=this.gpuChannel.compute();r=Math.max(r,n.avgMs),s=Math.max(s,n.slowRatio)}if(this.lastAvgFrameMs=r,this.lastSlowRatio=s,r>22.5||s>=.35){this.badChecks++,this.goodChecks=0,this.badChecks>=2&&this.currentTier<3&&e-this.lastTransitionAt>=2e3&&(this.setTier(this.currentTier+1,e),this.badChecks=0);return}if(r<18.2&&s<.1){this.goodChecks++,this.badChecks=0,this.currentTier>0&&this.goodChecks>=3&&e-this.lastTransitionAt>=5e3&&(this.setTier(this.currentTier-1,e),this.goodChecks=0);return}this.badChecks=0,this.goodChecks=0}setTier(e,t){if(e===this.currentTier)return;let o=this.currentTier;this.currentTier=e,this.lastTransitionAt=t,e===3?this.scheduleSurvivalProbe():this.clearSurvivalProbe(),this.listeners.forEach(r=>r(e,o))}},be=new lt;var ct=class{constructor(){this.listeners=new Set;this.visibilityListeners=new Set;this.rafId=null;this.startTime=0;this.lastTime=0;this.avgFrameTimeMs=0;this.isDocumentHidden=!1;this.handleVisibilityChange=()=>{this.isDocumentHidden=typeof document<"u"?document.hidden:!1,this.isDocumentHidden?(this.stopLoop(),be.resetAll()):this.listeners.size>0&&(this.lastTime=0,this.startLoop()),this.visibilityListeners.forEach(e=>{e(this.isDocumentHidden)})};this.tick=e=>{if(this.listeners.size===0||this.isDocumentHidden){this.stopLoop();return}this.startTime===0&&(this.startTime=e);let t=this.lastTime===0?16.67:e-this.lastTime,o=Math.min(t,100);this.lastTime=e,t>0&&t<500&&(this.avgFrameTimeMs=this.avgFrameTimeMs===0?t:this.avgFrameTimeMs*.9+t*.1),be.recordMainThread(t,e);let r=(e-this.startTime)*.001,s=o*.001;this.listeners.forEach(n=>{n(r,s,e)}),this.listeners.size>0&&!this.isDocumentHidden?this.rafId=window.requestAnimationFrame(this.tick):this.rafId=null};typeof document<"u"&&(this.isDocumentHidden=document.hidden,document.addEventListener("visibilitychange",this.handleVisibilityChange))}startLoop(){this.rafId!==null||typeof window>"u"||this.isDocumentHidden||(this.lastTime=0,this.rafId=window.requestAnimationFrame(this.tick))}stopLoop(){this.rafId!==null&&typeof window<"u"&&(window.cancelAnimationFrame(this.rafId),this.rafId=null),this.lastTime=0,this.avgFrameTimeMs=0,be.resetMainThread()}onVisibilityChange(e){return this.visibilityListeners.add(e),()=>{this.visibilityListeners.delete(e)}}add(e){return this.listeners.add(e),this.listeners.size===1&&this.startLoop(),()=>this.remove(e)}remove(e){this.listeners.delete(e),this.listeners.size===0&&this.stopLoop()}get isHidden(){return this.isDocumentHidden}get activeCount(){return this.listeners.size}get isRunning(){return this.rafId!==null}get frameTimeMs(){return!this.isRunning||this.avgFrameTimeMs<=0?0:Math.round(this.avgFrameTimeMs*100)/100}get fps(){return!this.isRunning||this.avgFrameTimeMs<=0?0:Math.round(1e3/this.avgFrameTimeMs)}},xe=new ct;var Y=class{static acquireVec2(e=0,t=0){let o=this.vec2Pool.pop()??new Float32Array(2);return o[0]=e,o[1]=t,o}static releaseVec2(e){this.vec2Pool.length<128&&this.vec2Pool.push(e)}static acquireVec3(e=0,t=0,o=0){let r=this.vec3Pool.pop()??new Float32Array(3);return r[0]=e,r[1]=t,r[2]=o,r}static releaseVec3(e){this.vec3Pool.length<128&&this.vec3Pool.push(e)}static acquireVec4(e=0,t=0,o=0,r=1){let s=this.vec4Pool.pop()??new Float32Array(4);return s[0]=e,s[1]=t,s[2]=o,s[3]=r,s}static releaseVec4(e){this.vec4Pool.length<128&&this.vec4Pool.push(e)}static hexToVec3Into(e,t){let o=e.charCodeAt(0)===35?e.slice(1):e;if(o.length===3){let s=parseInt(o[0],16),n=parseInt(o[1],16),l=parseInt(o[2],16);return t[0]=(s<<4|s)/255,t[1]=(n<<4|n)/255,t[2]=(l<<4|l)/255,t}let r=parseInt(o,16);return Number.isNaN(r)?(t[0]=1,t[1]=1,t[2]=1,t):(t[0]=(r>>16&255)/255,t[1]=(r>>8&255)/255,t[2]=(r&255)/255,t)}};Y.vec2Pool=[],Y.vec3Pool=[],Y.vec4Pool=[],Y.scratchVec2=new Float32Array(2),Y.scratchVec3=new Float32Array(3),Y.scratchVec4=new Float32Array(4);var et=class{constructor(e){this.samples=new Float32Array(30);this.sampleIdx=0;this.sampleCount=0;this.stableUpWindows=0;this.lastAdjustAt=0;this.minScale=Math.max(.5,e.minScale),this.maxScale=Math.max(this.minScale,e.maxScale),this.currentScale=this.maxScale,this.downThresholdMs=e.downThresholdMs??20.5,this.upThresholdMs=e.upThresholdMs??17.2,this.cooldownMs=e.cooldownMs??750}get scale(){return this.currentScale}setBounds(e,t){let o=Math.max(.5,e),r=Math.max(o,t),s=this.currentScale;return this.minScale=o,this.maxScale=r,this.currentScale=Math.min(r,Math.max(o,this.currentScale)),r>s&&(this.currentScale=r),this.sampleCount=0,this.sampleIdx=0,this.stableUpWindows=0,Math.abs(this.currentScale-s)>.01}recordFrame(e,t){if(this.minScale>=this.maxScale||e<=0||e>60)return!1;if(this.samples[this.sampleIdx]=e,this.sampleIdx=(this.sampleIdx+1)%this.samples.length,this.sampleCount<this.samples.length)return this.sampleCount++,!1;if(t-this.lastAdjustAt<this.cooldownMs)return!1;let o=0;for(let s=0;s<this.samples.length;s++)o+=this.samples[s];let r=o/this.samples.length;if(r>this.downThresholdMs&&this.currentScale>this.minScale)return this.currentScale=Math.max(this.minScale,Number((this.currentScale-.15).toFixed(2))),this.stableUpWindows=0,this.lastAdjustAt=t,!0;if(r<this.upThresholdMs&&this.currentScale<this.maxScale){if(this.stableUpWindows++,this.stableUpWindows>=2)return this.currentScale=Math.min(this.maxScale,Number((this.currentScale+.1).toFixed(2))),this.stableUpWindows=0,this.lastAdjustAt=t,!0}else this.stableUpWindows=0;return!1}};var He=null;function ee(i,e="#ffffff"){if(typeof i!="string")return e;let t=i.trim();if(!t)return e;if(typeof document<"u"){if(!He){let o=document.createElement("canvas");o.width=1,o.height=1,He=o.getContext("2d")}if(He){He.fillStyle="#010203",He.fillStyle=t;let o=He.fillStyle;if(/^#[0-9a-f]{6}$/i.test(o))return o;let r=o.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);if(r)return"#"+[Number(r[1]),Number(r[2]),Number(r[3])].map(s=>Math.max(0,Math.min(255,s)).toString(16).padStart(2,"0")).join("")}}return e}function Tt(i){let e=i.trim().toLowerCase();if(!e||e==="transparent"||e==="none")return null;let t=e.match(/^rgba?\(\s*([\d.]+)\s*[,\s]\s*([\d.]+)\s*[,\s]\s*([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/);if(t){let r=Math.max(0,Math.min(255,parseFloat(t[1])))/255,s=Math.max(0,Math.min(255,parseFloat(t[2])))/255,n=Math.max(0,Math.min(255,parseFloat(t[3])))/255,l=1;return t[4]!==void 0&&(l=t[4].endsWith("%")?parseFloat(t[4])/100:parseFloat(t[4])),[r,s,n,Math.max(0,Math.min(1,l))]}let o=e.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);if(o){let r=o[1],s=r.length===3?r.split("").map(n=>n+n).join(""):r;return[parseInt(s.slice(0,2),16)/255,parseInt(s.slice(2,4),16)/255,parseInt(s.slice(4,6),16)/255,1]}return null}function Mt(i,e,t){let o=r=>r<=.03928?r/12.92:Math.pow((r+.055)/1.055,2.4);return .2126*o(i)+.7152*o(e)+.0722*o(t)}function wt(i){if(typeof document>"u"||typeof window>"u")return!0;let e=i;for(;e;){let n=(e.getAttribute("data-theme")||e.getAttribute("data-mode")||e.getAttribute("data-bs-theme")||"").trim().toLowerCase();if(n==="dark")return!0;if(n==="light")return!1;if(e.classList.contains("dark")||e.classList.contains("dark-mode"))return!0;if(e.classList.contains("light")||e.classList.contains("light-mode"))return!1;e=e.parentElement}let t=document.documentElement,o=document.body,r=(t?.getAttribute("data-theme")||t?.getAttribute("data-mode")||t?.getAttribute("data-bs-theme")||"").trim().toLowerCase();if(r==="dark")return!0;if(r==="light")return!1;if(t?.classList.contains("dark")||o?.classList.contains("dark"))return!0;if(t?.classList.contains("light")||o?.classList.contains("light"))return!1;let s=i;for(;s;){let n=window.getComputedStyle(s).backgroundColor,l=Tt(n);if(l&&l[3]>.12)return Mt(l[0],l[1],l[2])<.42;s=s.parentElement}return typeof window.matchMedia=="function"?window.matchMedia("(prefers-color-scheme: dark)").matches:!0}function ut(i,e,t){let o=Math.max(i,e,t),r=Math.min(i,e,t),s=(o+r)*.5;if(o===r)return[0,0,s];let n=o-r,l=s>.5?n/(2-o-r):n/(o+r),a=0;return o===i?a=((e-t)/n+(e<t?6:0))/6:o===e?a=((t-i)/n+2)/6:a=((i-e)/n+4)/6,[a,l,s]}function Ct(i,e,t){if(e===0)return[t,t,t];let o=(n,l,a)=>{let d=a;return d<0&&(d+=1),d>1&&(d-=1),d<1/6?n+(l-n)*6*d:d<1/2?l:d<2/3?n+(l-n)*(2/3-d)*6:n},r=t<.5?t*(1+e):t+e-t*e,s=2*t-r;return[o(s,r,i+1/3),o(s,r,i),o(s,r,i-1/3)]}function tt(i,e){return i.map(([t,o,r])=>{let[s,n,l]=ut(t,o,r);if(e)return[t,o,r];let a=Math.min(n,.72)*.92,d=Math.max(.36,Math.min(.6,l*.78+.14));return Ct(s,a,d)})}function St(i,e){if(typeof window>"u"||!i)return null;let t=i;for(;t;){if(t.getAttribute("data-fluxfx-canvas")!=="true"){let o=window.getComputedStyle(t).backgroundColor,r=Tt(o);if(r&&r[3]>.14)return r}if(t===e)break;t=t.parentElement}return null}function Et(i,e){let[t,o,r]=ut(e[0],e[1],e[2]),s=Mt(e[0],e[1],e[2]);if(o<.2)return tt(i,s<.42);let n=s<.38;return i.map(([l,a,d],u)=>{let[f,h,p]=ut(l,a,d),v=Math.abs(f-t),b=Math.min(v,1-v),w=f;if(b<.22){let F=[.46,.56,.34];w=(t+F[u%F.length])%1}let k=Math.max(.55,Math.min(.92,h<.35?.72:h)),E=n?Math.max(.68,Math.min(.86,p*.45+.48)):Math.max(.24,Math.min(.44,p*.5+.12)),R=Math.abs(E-r)<.22?n?Math.min(.88,r+.34):Math.max(.2,r-.34):E;return Ct(w,k,R)})}var Ye=`#version 300 es
2
2
  precision highp float;
3
3
  layout(location = 0) in vec2 aPosition;
4
4
  out vec2 vUv;
5
5
  void main() {
6
6
  vUv = aPosition * 0.5 + 0.5;
7
7
  gl_Position = vec4(aPosition, 0.0, 1.0);
8
- }`,T=class{static hashSource(e,t){let i=e+"|"+t,r=2166136261;for(let s=0;s<i.length;s++)r^=i.charCodeAt(s),r=Math.imul(r,16777619);return(r>>>0).toString(36)}static compileShader(e,t,i){let r=e.createShader(t);if(!r)throw new Error("[FluxFX] Failed to create WebGLShader");if(e.shaderSource(r,i),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS)){let s=e.getShaderInfoLog(r);throw e.deleteShader(r),new Error(`[FluxFX] Shader compile error:
9
- ${s}`)}return r}static getOrCreateProgram(e,t,i=z){let r=this.contextCache.get(e);r||(r=new Map,this.contextCache.set(e,r));let s=this.hashSource(i,t),a=r.get(s);if(a)return a;e.getExtension("KHR_parallel_shader_compile");let n=this.compileShader(e,e.VERTEX_SHADER,i),l=this.compileShader(e,e.FRAGMENT_SHADER,t),c=e.createProgram();if(!c)throw e.deleteShader(n),e.deleteShader(l),new Error("[FluxFX] Failed to create WebGLProgram");if(e.attachShader(c,n),e.attachShader(c,l),e.linkProgram(c),e.deleteShader(n),e.deleteShader(l),!e.getProgramParameter(c,e.LINK_STATUS)){let h=e.getProgramInfoLog(c);throw e.deleteProgram(c),new Error(`[FluxFX] Program link error:
10
- ${h}`)}let u={program:c,uniforms:new Map};return r.set(s,u),u}static getUniformLocation(e,t,i){if(t.uniforms.has(i))return t.uniforms.get(i)??null;let r=e.getUniformLocation(t.program,i);return t.uniforms.set(i,r),r}static precompile(e,t){for(let i=0;i<t.length;i++)this.getOrCreateProgram(e,t[i])}static disposeContext(e){let t=this.contextCache.get(e);t&&(t.forEach(i=>e.deleteProgram(i.program)),t.clear(),this.contextCache.delete(e))}};T.contextCache=new WeakMap;var ke=`
8
+ }`,$=class{static hashSource(e,t){let o=e+"|"+t,r=2166136261;for(let s=0;s<o.length;s++)r^=o.charCodeAt(s),r=Math.imul(r,16777619);return(r>>>0).toString(36)}static compileShader(e,t,o){let r=e.createShader(t);if(!r)throw new Error("[FluxFX] Failed to create WebGLShader");if(e.shaderSource(r,o),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS)){let s=e.getShaderInfoLog(r);throw e.deleteShader(r),new Error(`[FluxFX] Shader compile error:
9
+ ${s}`)}return r}static getOrCreateProgram(e,t,o=Ye){let r=this.contextCache.get(e);r||(r=new Map,this.contextCache.set(e,r));let s=this.hashSource(o,t),n=r.get(s);if(n)return n;e.getExtension("KHR_parallel_shader_compile");let l=this.compileShader(e,e.VERTEX_SHADER,o),a=this.compileShader(e,e.FRAGMENT_SHADER,t),d=e.createProgram();if(!d)throw e.deleteShader(l),e.deleteShader(a),new Error("[FluxFX] Failed to create WebGLProgram");if(e.attachShader(d,l),e.attachShader(d,a),e.linkProgram(d),e.deleteShader(l),e.deleteShader(a),!e.getProgramParameter(d,e.LINK_STATUS)){let f=e.getProgramInfoLog(d);throw e.deleteProgram(d),new Error(`[FluxFX] Program link error:
10
+ ${f}`)}let u={program:d,uniforms:new Map};return r.set(s,u),u}static getUniformLocation(e,t,o){if(t.uniforms.has(o))return t.uniforms.get(o)??null;let r=e.getUniformLocation(t.program,o);return t.uniforms.set(o,r),r}static precompile(e,t){for(let o=0;o<t.length;o++)this.getOrCreateProgram(e,t[o])}static disposeContext(e){let t=this.contextCache.get(e);t&&(t.forEach(o=>e.deleteProgram(o.program)),t.clear(),this.contextCache.delete(e))}};$.contextCache=new WeakMap;var nr=`
11
11
  let gl = null;
12
12
  let canvas = null;
13
13
  let displayProgram = null;
@@ -74,6 +74,7 @@ let lastAdjust = 0;
74
74
  const displayLocs = new Map();
75
75
  const feedbackLocs = new Map();
76
76
  const customUniforms = new Map();
77
+ const customTextures = new Map();
77
78
 
78
79
  const mouse = new Float32Array([0.5, 0.5]);
79
80
  const targetMouse = new Float32Array([0.5, 0.5]);
@@ -352,6 +353,53 @@ function bindCommonUniforms(prog, cache, resW, resH) {
352
353
  });
353
354
  }
354
355
 
356
+ function destroyCustomTextures() {
357
+ if (!gl) {
358
+ customTextures.clear();
359
+ return;
360
+ }
361
+ customTextures.forEach((entry) => {
362
+ if (entry.tex) gl.deleteTexture(entry.tex);
363
+ });
364
+ customTextures.clear();
365
+ }
366
+
367
+ function uploadCustomTexture(name, unit, bitmap, w, h) {
368
+ if (!gl || contextLost) {
369
+ if (bitmap && typeof bitmap.close === 'function') bitmap.close();
370
+ return;
371
+ }
372
+ let entry = customTextures.get(name);
373
+ let tex = entry ? entry.tex : null;
374
+ if (!tex) {
375
+ tex = gl.createTexture();
376
+ }
377
+ gl.activeTexture(gl.TEXTURE0 + unit);
378
+ gl.bindTexture(gl.TEXTURE_2D, tex);
379
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
380
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
381
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
382
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
383
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, bitmap);
384
+ gl.bindTexture(gl.TEXTURE_2D, null);
385
+ if (bitmap && typeof bitmap.close === 'function') bitmap.close();
386
+
387
+ customTextures.set(name, { unit: unit, tex: tex, width: w, height: h });
388
+ customUniforms.set(name + 'Size', [w, h]);
389
+ customUniforms.set(name + 'Ready', 1.0);
390
+ }
391
+
392
+ function bindCustomTextures(prog, cache) {
393
+ if (customTextures.size === 0) return;
394
+ customTextures.forEach((entry, name) => {
395
+ const loc = getLoc(prog, cache, name);
396
+ if (!loc) return;
397
+ gl.activeTexture(gl.TEXTURE0 + entry.unit);
398
+ gl.bindTexture(gl.TEXTURE_2D, entry.tex);
399
+ gl.uniform1i(loc, entry.unit);
400
+ });
401
+ }
402
+
355
403
  function drawFrame() {
356
404
  if (!gl || !displayProgram || contextLost) return;
357
405
 
@@ -367,6 +415,7 @@ function drawFrame() {
367
415
  const prevLoc = getLoc(feedbackProgram, feedbackLocs, 'uPrevFrame');
368
416
  if (prevLoc) gl.uniform1i(prevLoc, 0);
369
417
 
418
+ bindCustomTextures(feedbackProgram, feedbackLocs);
370
419
  bindCommonUniforms(feedbackProgram, feedbackLocs, fboW, fboH);
371
420
  gl.drawArrays(gl.TRIANGLES, 0, 3);
372
421
 
@@ -388,6 +437,7 @@ function drawFrame() {
388
437
  if (pfLoc) gl.uniform1i(pfLoc, 0);
389
438
  }
390
439
 
440
+ bindCustomTextures(displayProgram, displayLocs);
391
441
  bindCommonUniforms(displayProgram, displayLocs, canvas.width, canvas.height);
392
442
  gl.drawArrays(gl.TRIANGLES, 0, 3);
393
443
  }
@@ -538,6 +588,7 @@ function onContextLost(e) {
538
588
  contextLost = true;
539
589
  stopLoop();
540
590
  pingPong = null;
591
+ customTextures.clear();
541
592
  displayProgram = null;
542
593
  feedbackProgram = null;
543
594
  }
@@ -547,6 +598,7 @@ function onContextRestored() {
547
598
  try {
548
599
  contextLost = false;
549
600
  buildGLPipeline();
601
+ self.postMessage({ type: 'needTextures' });
550
602
  drawFrame();
551
603
  if (!reducedMotion) {
552
604
  startLoopIfAllowed();
@@ -729,6 +781,21 @@ self.onmessage = function(e) {
729
781
  boostInteraction(1200);
730
782
  if (reducedMotion && !contextLost) drawFrame();
731
783
  break;
784
+ case 'texture':
785
+ uploadCustomTexture(msg.name, msg.unit, msg.bitmap, msg.width, msg.height);
786
+ boostInteraction(600);
787
+ if (reducedMotion && !contextLost) drawFrame();
788
+ break;
789
+ case 'clearTexture': {
790
+ const existingTex = customTextures.get(msg.name);
791
+ if (existingTex) {
792
+ if (gl && existingTex.tex) gl.deleteTexture(existingTex.tex);
793
+ customTextures.delete(msg.name);
794
+ }
795
+ customUniforms.set(msg.name + 'Ready', 0.0);
796
+ if (reducedMotion && !contextLost) drawFrame();
797
+ break;
798
+ }
732
799
  case 'reducedMotion':
733
800
  reducedMotion = !!msg.value;
734
801
  if (reducedMotion) {
@@ -773,6 +840,7 @@ self.onmessage = function(e) {
773
840
  }
774
841
  if (gl) {
775
842
  destroyPingPong();
843
+ destroyCustomTextures();
776
844
  if (displayProgram) gl.deleteProgram(displayProgram);
777
845
  if (feedbackProgram) gl.deleteProgram(feedbackProgram);
778
846
  if (vbo) gl.deleteBuffer(vbo);
@@ -787,7 +855,7 @@ self.onmessage = function(e) {
787
855
  break;
788
856
  }
789
857
  };
790
- `,te=null;function ie(){if(typeof window>"u"||typeof Worker>"u"||typeof OffscreenCanvas>"u"||typeof HTMLCanvasElement>"u"||!("transferControlToOffscreen"in HTMLCanvasElement.prototype))return!1;let o=typeof navigator<"u"?navigator.userAgent:"";return!(/iP(ad|hone|od)/i.test(o)||/^((?!chrome|android).)*safari/i.test(o))}function ve(){if(!te){let o=new Blob([ke],{type:"application/javascript"});te=URL.createObjectURL(o)}return new Worker(te)}var ge=z;var O={low:{max:1,min:.65,retinaMin:.85,fboMaxDim:512},medium:{max:2,min:.75,retinaMin:1,fboMaxDim:896},high:{max:2,min:1,retinaMin:1.25,fboMaxDim:1152}},De=new Float32Array([-1,-1,3,-1,-1,3]),Pe=12;function ye(){if(typeof navigator>"u")return!1;let o=navigator.userAgent||"";return/Safari/i.test(o)&&!/Chrome|Chromium|Edg|CriOS|FxiOS|OPR/i.test(o)}function be(){if(typeof navigator>"u")return 8;let o=navigator.userAgent||"",e=/Mobi|Android|iPhone|iPad|iPod/i.test(o);return ye()||e?6:8}function X(){return typeof performance<"u"?performance.now():Date.now()}var re=30,se=60,H=1800;function q(o,e){return 1-Math.exp(-o*e)}var C=class C{constructor(e,t){this.resizeObserver=null;this.visibilityObserver=null;this.reducedMotionQuery=null;this.dprMediaQuery=null;this.worker=null;this.isOffscreen=!1;this.gl=null;this.programEntry=null;this.feedbackProgramEntry=null;this.vao=null;this.vbo=null;this.dynamicRes=null;this.lastRenderNow=0;this.lastDrawNow=0;this.lastTargetFps=0;this.prevFrameDrew=!1;this.avgDrawDeltaMs=0;this.boostUntil=0;this.reportedFps=0;this.reportedFrameTimeMs=0;this.elapsedSec=0;this.lastDeltaSec=.01667;this.currentSpeed=1;this.targetSpeed=1;this.needsResize=!1;this.pingPong=null;this.fboW=1;this.fboH=1;this.fboFormat=0;this.fboType=0;this.readIdx=0;this.writeIdx=1;this.customUniforms=new Map;this.mouse=y.acquireVec2(.5,.5);this.targetMouse=y.acquireVec2(.5,.5);this.mouseVel=y.acquireVec2(0,0);this.mouseDown=0;this.mouseActive=0;this.targetMouseActive=0;this.isPointerInside=!1;this.scroll=0;this.targetScroll=0;this.scrollVel=0;this.hasScrollListener=!1;this.width=1;this.height=1;this.isPaused=!1;this.isHiddenByViewport=!1;this.isContextLost=!1;this.isReducedMotion=!1;this.isDestroyed=!1;this.wakeCallback=null;this.ambientFps=re;this.activeFps=se;this.protectionTier=D.tier;this.isSurvivalSuspended=!1;this.unsubscribeGuard=null;this.isBudgetSuspended=!1;this.lastActiveAt=X();this.hasDocVisibilityListener=!1;this.hasPointerListener=!1;this.countedContext=!1;this.isBodyMount=!1;this.origBodyMinHeight="";this.themeMode="auto";this.resolvedDarkTheme=!0;this.currentTheme=1;this.themeTweenRaf=0;this.colorSchemeQuery=null;this.themeMutationObserver=null;this.basePaletteRgb=[];this.activePaletteRgb=[];this.scrollStopsRgb=[];this.lastScrollColorT=-1;this.hasScrollColorListener=!1;this.scrollColorRaf=0;this.hasTouchListener=!1;this.touchBurstTimer=0;this.touchLeaveTimer=0;this.layerMode="background";this.adaptToSurface=!1;this.rawBasePaletteRgb=[];this.lastSurfaceEl=null;this.lastSurfaceKey="";this.lastSurfaceCheckAt=0;this.isSurfaceAdapted=!1;this.handleThemeChange=()=>{if(this.isDestroyed)return;let e=this.detectDarkTheme(this.themeMode);e!==this.resolvedDarkTheme&&(this.resolvedDarkTheme=e,this.startThemeTransition(e))};this.handleScrollColorEvent=()=>{this.isDestroyed||this.scrollStopsRgb.length<2||this.scrollColorRaf||(this.scrollColorRaf=requestAnimationFrame(()=>{if(this.scrollColorRaf=0,this.isDestroyed||this.scrollStopsRgb.length<2)return;let e=this.computeScrollProgress();this.updateScrollColorShift(e)}))};this.handleTouchStart=e=>{if(!this.interactive||this.isPaused||this.isHiddenByViewport||this.isReducedMotion)return;let t=e.touches[0];if(!t)return;if(this.isShadowedByChildInteractive(t.target)){this.isPointerInside&&this.handlePointerLeave();return}let i=this.getLocalTouchCoords(t);if(!i)return;this.touchLeaveTimer&&(window.clearTimeout(this.touchLeaveTimer),this.touchLeaveTimer=0),this.touchBurstTimer&&(window.clearTimeout(this.touchBurstTimer),this.touchBurstTimer=0);let[r,s]=i;this.inspectSurfaceFromTarget(t.target,!0),this.isPointerInside=!0,this.targetMouseActive=1,this.mouseDown=1,this.boostInteraction(H),this.isOffscreen&&this.worker?(this.worker.postMessage({type:"mouseEnter",x:r,y:s}),this.worker.postMessage({type:"mouseDown",down:!0})):(this.mouse[0]=r,this.mouse[1]=s,this.targetMouse[0]=r,this.targetMouse[1]=s,this.mouseVel[0]=0,this.mouseVel[1]=0),this.touchBurstTimer=window.setTimeout(()=>{this.touchBurstTimer=0,!this.isDestroyed&&(this.mouseDown=0,this.isOffscreen&&this.worker&&this.worker.postMessage({type:"mouseDown",down:!1}))},160)};this.handleTouchMove=e=>{if(!this.interactive||this.isPaused||this.isHiddenByViewport||this.isReducedMotion)return;let t=e.touches[0];if(!t)return;if(this.isShadowedByChildInteractive(t.target)){this.isPointerInside&&this.handlePointerLeave();return}let i=this.getLocalTouchCoords(t);if(!i)return;let[r,s]=i;this.inspectSurfaceFromTarget(t.target),this.boostInteraction(H),this.targetMouseActive=1,this.isOffscreen&&this.worker?this.worker.postMessage({type:"mouse",x:r,y:s}):(this.targetMouse[0]=r,this.targetMouse[1]=s)};this.handleTouchEnd=()=>{this.isDestroyed||(this.mouseDown=0,this.isOffscreen&&this.worker&&this.worker.postMessage({type:"mouseDown",down:!1}),this.touchLeaveTimer&&window.clearTimeout(this.touchLeaveTimer),this.touchLeaveTimer=window.setTimeout(()=>{this.touchLeaveTimer=0,this.isDestroyed||this.handlePointerLeave()},550))};this.handleContextLost=e=>{e.preventDefault(),this.isContextLost=!0,this.resetFrameTracking(),this.gl&&T.disposeContext(this.gl),this.programEntry=null,this.feedbackProgramEntry=null,this.pingPong=null,this.vao=null,this.vbo=null,this.wakeCallback?.()};this.handleContextRestored=()=>{if(!(this.isDestroyed||!this.gl))try{this.isContextLost=!1,this.initMainThreadPipeline(this.gl),this.drawMainThreadFrame(),this.wakeCallback?.()}catch(e){console.error("[FluxFX] Failed to restore WebGL2 context:",e)}};this.handleProtectionTierChange=e=>{this.isDestroyed||this.protectionTier===e||(this.protectionTier=e,this.applyProtectionState(),this.isDestroyed||this.pushUniformBatch({uQuality:this.computeEffectiveQuality()}))};this.handleDprChange=()=>{this.isDestroyed||(this.syncDprBounds(),this.watchDevicePixelRatio())};this.handleReducedMotionChange=e=>{this.applyReducedMotionState(this.respectReducedMotion&&e.matches)};this.handlePointerEnter=e=>{if(this.isPaused||this.isHiddenByViewport||this.isReducedMotion)return;if(this.isShadowedByChildInteractive(e.target)){this.isPointerInside&&this.handlePointerLeave();return}let t=this.getLocalPointerCoords(e);if(!t)return;let[i,r]=t;this.isPointerInside=!0,this.targetMouseActive=1,this.boostInteraction(H),this.protectionTier>=3&&this.applyProtectionState(),this.lastActiveAt=X(),this.isBudgetSuspended&&!this.isPaused&&this.restoreContextFromBudget(),this.isOffscreen&&this.worker?this.worker.postMessage({type:"mouseEnter",x:i,y:r}):(this.mouse[0]=i,this.mouse[1]=r,this.targetMouse[0]=i,this.targetMouse[1]=r,this.mouseVel[0]=0,this.mouseVel[1]=0)};this.handlePointerMove=e=>{if(this.isPaused||this.isHiddenByViewport||this.isReducedMotion)return;if(this.isShadowedByChildInteractive(e.target)){this.isPointerInside&&this.handlePointerLeave();return}let t=this.getLocalPointerCoords(e);if(!t){this.isPointerInside&&this.handlePointerLeave();return}let[i,r]=t;if(!this.isPointerInside){this.handlePointerEnter(e),this.inspectSurfaceFromTarget(e.target,!0);return}this.inspectSurfaceFromTarget(e.target),this.boostInteraction(H),this.isOffscreen&&this.worker?this.worker.postMessage({type:"mouse",x:i,y:r}):(this.targetMouse[0]=i,this.targetMouse[1]=r)};this.handlePointerLeave=()=>{!this.isPointerInside&&this.targetMouseActive===0||(this.isPointerInside=!1,this.targetMouseActive=0,this.lastSurfaceEl=null,this.lastSurfaceKey="",this.isSurfaceAdapted&&(this.isSurfaceAdapted=!1,this.startPaletteTween(this.basePaletteRgb,240)),this.mouseDown=0,this.mouseVel[0]=0,this.mouseVel[1]=0,this.isOffscreen&&this.worker&&this.worker.postMessage({type:"mouseLeave"}),this.protectionTier>=3&&this.applyProtectionState())};this.handlePointerDown=e=>{if(!(this.isPaused||this.isHiddenByViewport||this.isReducedMotion)){if(this.isShadowedByChildInteractive(e.target)){this.isPointerInside&&this.handlePointerLeave();return}this.isPointerInside||this.handlePointerEnter(e),this.mouseDown=1,this.boostInteraction(H),this.protectionTier>=3&&this.applyProtectionState(),this.isOffscreen&&this.worker&&this.worker.postMessage({type:"mouseDown",down:!0})}};this.handlePointerUp=()=>{this.mouseDown!==0&&(this.mouseDown=0,this.isOffscreen&&this.worker&&this.worker.postMessage({type:"mouseDown",down:!1}),this.protectionTier>=3&&this.applyProtectionState())};this.handleScroll=()=>{if(!this.trackScroll||this.isDestroyed)return;let e=this.computeScrollProgress();this.boostInteraction(1200),this.isOffscreen&&this.worker?this.worker.postMessage({type:"scroll",progress:e}):(this.targetScroll=e,this.isReducedMotion&&!this.isPaused&&!this.isHiddenByViewport&&(this.scroll=e,this.scrollVel=0,this.drawMainThreadFrame()))};this.handleDocVisibility=()=>{!this.isOffscreen||!this.worker||(document.hidden?(this.resetFrameTracking(),this.worker.postMessage({type:"pause"})):!this.isPaused&&!this.isHiddenByViewport&&this.worker.postMessage({type:"resume"}))};this.container=e,this.options={...t},this.interactive=t.interactive??!0,this.respectReducedMotion=t.respectReducedMotion??!0,this.trackScroll=t.trackScroll??!1,this.feedbackScale=t.feedbackScale??.5,this.feedbackFloat=t.feedbackFloat??!0,C.instances.add(this);let i=t.quality??"medium",r=O[i]??O.medium;this.baseFeedbackMaxDim=t.feedbackMaxDim??r.fboMaxDim;let s=this.resolveTierConfig();this.ambientFps=s.ambientFps,this.activeFps=s.activeFps,this.feedbackMaxDim=s.feedbackMaxDim,this.isSurvivalSuspended=s.suspended,typeof window<"u"&&typeof window.matchMedia=="function"&&(this.reducedMotionQuery=window.matchMedia("(prefers-reduced-motion: reduce)"),this.isReducedMotion=this.respectReducedMotion&&this.reducedMotionQuery.matches),this.isBodyMount=typeof document<"u"&&this.container===document.body,window.getComputedStyle(this.container).position==="static"&&(this.container.style.position="relative"),this.container.style.isolation="isolate",this.isBodyMount&&(this.origBodyMinHeight=this.container.style.minHeight,this.container.style.minHeight||(this.container.style.minHeight="100dvh")),this.canvas=document.createElement("canvas"),this.canvas.setAttribute("data-fluxfx-canvas","true"),this.canvas.style.position=this.isBodyMount?"fixed":"absolute",this.canvas.style.inset="0",this.canvas.style.width="100%",this.canvas.style.height="100%",this.canvas.style.zIndex="-1",this.canvas.style.pointerEvents="none",this.canvas.style.display="block",this.container.prepend(this.canvas),this.layerMode=t.layer??"background",this.adaptToSurface=t.adaptToSurface??!1,this.applyCanvasLayerStyle(),this.themeMode=t.theme??"auto",this.resolvedDarkTheme=this.detectDarkTheme(this.themeMode),this.currentTheme=this.resolvedDarkTheme?1:0;let n=this.container.getBoundingClientRect();if(this.width=Math.max(1,Math.floor(n.width)),this.height=Math.max(1,Math.floor(n.height)),this.trackScroll){let p=this.computeScrollProgress();this.scroll=p,this.targetScroll=p}let{minDpr:l,maxDpr:c}=this.resolveDprBounds(),u=t.dynamicResolution??!0,h=t.offscreen??!0;this.seedUniformsFromOptions(t,!0);let f=typeof window<"u"&&window.innerHeight||0,d=typeof window<"u"&&window.innerWidth||0,m=(t.pauseWhenHidden??!0)&&f>0&&(n.bottom<-50||n.top>f+50||n.right<-50||n.left>d+50);m&&(this.isHiddenByViewport=!0),C.ensureContextBudget(this,m)?h&&ie()?this.initOffscreenMode(t,l,c,u):this.initMainThreadMode(t,l,c,u):(this.isBudgetSuspended=!0,this.applyBudgetFallbackStyle()),this.bindObservers(t.pauseWhenHidden??!0),this.unsubscribeGuard=D.onTierChange(this.handleProtectionTierChange)}static acquireRecycledMainContext(){for(;this.recycledMainContexts.length>0;){let e=this.recycledMainContexts.pop();if(!e.gl.isContextLost())return e}return null}static recycleMainContext(e,t){let i=Math.max(this._maxContexts,be());return this.recycledMainContexts.length>=i?!1:(this.recycledMainContexts.push({canvas:e,gl:t}),!0)}static get activeContexts(){return this._activeContexts}static get maxActiveContexts(){return this._maxContexts}static get suspendedContexts(){let e=0;return this.instances.forEach(t=>{!t.isDestroyed&&t.isBudgetSuspended&&e++}),e}static setMaxActiveContexts(e){let t=Math.max(1,Math.floor(e));t!==this._maxContexts&&(this._maxContexts=t,this.enforceContextBudget(),this.reclaimBudgetForWaiting())}static pickEvictionVictim(e,t){let i=null,r=null;return this.instances.forEach(s=>{s===e||s.isDestroyed||s.isBudgetSuspended||!s.countedContext||(s.isHiddenByViewport||s.isPaused?(!i||s.lastActiveAt<i.lastActiveAt)&&(i=s):t&&!s.isPointerInside&&s.mouseDown===0&&(!r||s.lastActiveAt<r.lastActiveAt)&&(r=s))}),i??r}static ensureContextBudget(e,t){if(this._activeContexts<this._maxContexts)return!0;if(t)return!1;let i=this.pickEvictionVictim(e,!0);return i?(i.suspendContextForBudget(),this._activeContexts<this._maxContexts):!1}static enforceContextBudget(){for(;this._activeContexts>this._maxContexts;){let e=this.pickEvictionVictim(null,!0);if(!e)break;e.suspendContextForBudget()}}static reclaimBudgetForWaiting(){for(;this._activeContexts<this._maxContexts;){let e=null;if(this.instances.forEach(t=>{t.isDestroyed||!t.isBudgetSuspended||t.isPaused||t.isHiddenByViewport||(!e||t.lastActiveAt>e.lastActiveAt)&&(e=t)}),!e||!e.restoreContextFromBudget())break}}static getRenderStats(){let e=0,t=0,i=0;return this.instances.forEach(r=>{r.isDestroyed||r.isPaused||r.isHiddenByViewport||r.isReducedMotion||r.isContextLost||r.isSurvivalSuspended||r.reportedFps>0&&(e++,r.reportedFps>t&&(t=r.reportedFps,i=r.reportedFrameTimeMs))}),{activeRendering:e,fps:t,frameTimeMs:i}}boostInteraction(e=H){let t=performance.now()+e;t>this.boostUntil&&(this.boostUntil=t)}resetFrameTracking(){this.lastRenderNow=0,this.lastDrawNow=0,this.lastTargetFps=0,this.prevFrameDrew=!1,this.avgDrawDeltaMs=0,this.reportedFps=0,this.reportedFrameTimeMs=0}resolveTierConfig(){let e=this.baseFeedbackMaxDim;return this.protectionTier===1?{ambientFps:re,activeFps:se,feedbackMaxDim:Math.max(256,Math.round(e*.75)),suspended:!1}:this.protectionTier===2?{ambientFps:20,activeFps:30,feedbackMaxDim:Math.max(256,Math.round(e*.55)),suspended:!1}:this.protectionTier>=3?{ambientFps:15,activeFps:30,feedbackMaxDim:Math.max(256,Math.round(e*.5)),suspended:!this.isPointerInside&&this.mouseDown===0}:{ambientFps:re,activeFps:se,feedbackMaxDim:e,suspended:!1}}resolveDprBounds(){let e=this.options.quality??"medium",t=O[e]??O.medium,i=typeof window<"u"&&window.devicePixelRatio||1,r=i>=1.5,s=this.options.maxDpr??Math.min(i,t.max),a=r?t.retinaMin:t.min,n=this.options.minDpr??Math.min(a,s);if(this.protectionTier===1){let l=Math.max(.65,Number((s*.75).toFixed(2)));return{minDpr:Math.min(n,l),maxDpr:l}}if(this.protectionTier>=2){let l=Math.max(.55,Math.min(n,Number((s*.6).toFixed(2))));return{minDpr:l,maxDpr:l}}return{minDpr:n,maxDpr:s}}computeScrollProgress(){if(typeof window>"u")return 0;let e=this.container.getBoundingClientRect(),t=window.innerHeight||1,i=t+e.height;return i<=0?0:Math.min(1,Math.max(0,(t-e.top)/i))}markContextActive(){this.countedContext||(this.countedContext=!0,C._activeContexts++,C._activeContexts>Pe&&console.warn(`[FluxFX] ${C._activeContexts} active WebGL contexts detected. Browsers typically cap contexts around 8\u201316; consider limiting simultaneous WebGL backgrounds.`))}markContextReleased(){this.countedContext&&(this.countedContext=!1,C._activeContexts=Math.max(0,C._activeContexts-1))}uniformVec3Css(e,t,i=1){let r=this.customUniforms.get(e),s=t[0],a=t[1],n=t[2];return r&&typeof r!="number"&&r.length>=3&&(s=Math.round(Math.min(1,Math.max(0,r[0]))*255),a=Math.round(Math.min(1,Math.max(0,r[1]))*255),n=Math.round(Math.min(1,Math.max(0,r[2]??0))*255)),i<1?`rgba(${s}, ${a}, ${n}, ${i})`:`rgb(${s}, ${a}, ${n})`}applyBudgetFallbackStyle(){if(this.isDestroyed)return;let e=this.customUniforms.get("uTransparentBg"),t=typeof e=="number"&&e>.5,i=this.customUniforms.get("uBgColor"),r=i&&typeof i!="number"&&i.length>=3&&i[0]+i[1]+(i[2]??0)>.003,s=this.uniformVec3Css("uColor1",[99,102,241],t?.38:.45),a=this.uniformVec3Css("uColor2",[6,182,212],t?.32:.38),n=this.uniformVec3Css("uColor3",[244,63,94],t?.22:.28),l=t?"transparent":r?this.uniformVec3Css("uBgColor",[6,8,16],1):"#070a14";this.canvas.style.background=`radial-gradient(circle at 22% 28%, ${s}, transparent 60%), radial-gradient(circle at 78% 72%, ${a}, transparent 62%), radial-gradient(circle at 55% 45%, ${n}, transparent 68%), ${l}`}syncDocVisibilityListener(){typeof document>"u"||(this.isOffscreen&&!this.hasDocVisibilityListener?(document.addEventListener("visibilitychange",this.handleDocVisibility),this.hasDocVisibilityListener=!0):!this.isOffscreen&&this.hasDocVisibilityListener&&(document.removeEventListener("visibilitychange",this.handleDocVisibility),this.hasDocVisibilityListener=!1))}releaseMainThreadContext(e){if(!this.gl){e||this.canvas.remove();return}let t=this.gl;if(t.isContextLost())this.pingPong=null,T.disposeContext(t),e||this.canvas.remove();else{this.destroyPingPongMain(),this.vbo&&t.deleteBuffer(this.vbo),this.vao&&t.deleteVertexArray(this.vao),T.disposeContext(t),t.bindFramebuffer(t.FRAMEBUFFER,null),t.bindVertexArray(null),t.bindBuffer(t.ARRAY_BUFFER,null),t.useProgram(null),t.viewport(0,0,1,1),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),this.canvas.width=1,this.canvas.height=1;let r=this.canvas;if(e){let s=this.canvas.cloneNode(!1);this.canvas.replaceWith(s),this.canvas=s}else this.canvas.remove();!C.recycleMainContext(r,t)&&!ye()&&t.getExtension("WEBGL_lose_context")?.loseContext()}this.gl=null}suspendContextForBudget(){this.isDestroyed||this.isBudgetSuspended||(this.isBudgetSuspended=!0,this.resetFrameTracking(),this.canvas.removeEventListener("webglcontextlost",this.handleContextLost,!1),this.canvas.removeEventListener("webglcontextrestored",this.handleContextRestored,!1),this.isOffscreen&&this.worker&&(this.worker.postMessage({type:"destroy"}),this.worker=null),this.isOffscreen=!1,this.syncDocVisibilityListener(),this.releaseMainThreadContext(!0),this.programEntry=null,this.feedbackProgramEntry=null,this.vao=null,this.vbo=null,this.dynamicRes=null,this.isContextLost=!1,this.markContextReleased(),this.applyBudgetFallbackStyle(),this.wakeCallback?.())}restoreContextFromBudget(){if(this.isDestroyed||!this.isBudgetSuspended||!C.ensureContextBudget(this,!1))return!1;let e=this.canvas.cloneNode(!1);e.style.background="",this.canvas.replaceWith(e),this.canvas=e;let t=this.container.getBoundingClientRect();this.width=Math.max(1,Math.floor(t.width)),this.height=Math.max(1,Math.floor(t.height));let{minDpr:i,maxDpr:r}=this.resolveDprBounds(),s=this.options.dynamicResolution??!0,a=this.options.offscreen??!0;return this.isBudgetSuspended=!1,this.isContextLost=!1,this.lastActiveAt=X(),a&&ie()?this.initOffscreenMode(this.options,i,r,s):this.initMainThreadMode(this.options,i,r,s),this.syncDocVisibilityListener(),this.wakeCallback?.(),this.countedContext}computeEffectiveQuality(){let e=this.options.quality??"medium",t=e==="high"?1:e==="low"?0:.5;return this.protectionTier>=2?t=0:this.protectionTier===1&&(t=Math.min(t,.5)),t}shouldPreserveBg(){return typeof this.options.preserveBg=="boolean"?this.options.preserveBg:this.layerMode==="overlay"}applyCanvasLayerStyle(){if(this.layerMode==="overlay"){this.canvas.style.zIndex="10";let e=typeof this.options.overlayOpacity=="number"?Math.max(.05,Math.min(1,this.options.overlayOpacity)):.78;this.canvas.style.opacity=String(e)}else this.canvas.style.zIndex="-1",this.canvas.style.opacity="1"}startPaletteTween(e,t=220){if(e.length===0)return;this.themeTweenRaf&&(cancelAnimationFrame(this.themeTweenRaf),this.themeTweenRaf=0);let i=this.toTriplet(this.activePaletteRgb.length>0?this.activePaletteRgb:this.basePaletteRgb),r=this.toTriplet(e);if(this.isReducedMotion||typeof requestAnimationFrame!="function"){this.activePaletteRgb=r,this.pushUniformBatch({uColor1:r[0],uColor2:r[1],uColor3:r[2]});return}let s=performance.now();this.boostInteraction(420);let a=n=>{if(this.isDestroyed){this.themeTweenRaf=0;return}let l=Math.min(1,(n-s)/t),c=l<.5?2*l*l:1-Math.pow(-2*l+2,2)/2,u=(m,p)=>[m[0]+(p[0]-m[0])*c,m[1]+(p[1]-m[1])*c,m[2]+(p[2]-m[2])*c],h=u(i[0],r[0]),f=u(i[1],r[1]),d=u(i[2],r[2]);this.activePaletteRgb=[h,f,d],this.pushUniformBatch({uColor1:h,uColor2:f,uColor3:d}),l<1?this.themeTweenRaf=requestAnimationFrame(a):this.themeTweenRaf=0};this.themeTweenRaf=requestAnimationFrame(a)}inspectSurfaceFromTarget(e,t=!1){if(!this.adaptToSurface||this.isDestroyed)return;let i=e instanceof HTMLElement?e:null,r=performance.now();if(!t&&i===this.lastSurfaceEl&&r-this.lastSurfaceCheckAt<180)return;this.lastSurfaceEl=i,this.lastSurfaceCheckAt=r;let s=me(i,this.container);if(!s){this.isSurfaceAdapted&&(this.isSurfaceAdapted=!1,this.lastSurfaceKey="",this.startPaletteTween(this.basePaletteRgb,220));return}let a=`${Math.round(s[0]*255)},${Math.round(s[1]*255)},${Math.round(s[2]*255)}`;if(!t&&a===this.lastSurfaceKey)return;this.lastSurfaceKey=a;let n=this.rawBasePaletteRgb.length>0?this.rawBasePaletteRgb:this.basePaletteRgb;if(n.length===0)return;let l=pe(n,[s[0],s[1],s[2]]);this.isSurfaceAdapted=!0,this.startPaletteTween(l,220)}parseColorList(e){if(!e)return[];let t=Array.isArray(e)?e:String(e).split(",").map(s=>s.trim()).filter(Boolean);if(t.length===0)return[];let i=x(t[0],"#6366f1"),r=[];for(let s=0;s<t.length;s++){let a=x(t[s],i),n=y.hexToVec3Into(a,y.scratchVec3);r.push([n[0],n[1],n[2]])}return r}parseScrollStops(e){if(!Array.isArray(e)||e.length===0)return[];let t=[];for(let i=0;i<e.length;i++){let r=e[i],s=Array.isArray(r)?r[0]:r;if(typeof s=="string"&&s.trim()){let a=x(s,"#6366f1"),n=y.hexToVec3Into(a,y.scratchVec3);t.push([n[0],n[1],n[2]])}}return t}detectDarkTheme(e){return e==="dark"?!0:e==="light"?!1:de(this.container)}resolveTargetPalette(e){let t=e?this.parseColorList(this.options.darkColors):this.parseColorList(this.options.lightColors);if(t.length>0)return t;let i=this.parseColorList(this.options.colors);return i.length>0?j(i,e):this.basePaletteRgb}toTriplet(e){let t=e[0]??[.39,.4,.95],i=e[1]??t,r=e[2]??i;return[[t[0],t[1],t[2]],[i[0],i[1],i[2]],[r[0],r[1],r[2]]]}pushUniformBatch(e){if(!this.isDestroyed){for(let[t,i]of Object.entries(e))this.customUniforms.set(t,i);if(this.isBudgetSuspended){this.applyBudgetFallbackStyle();return}this.isOffscreen&&this.worker?this.worker.postMessage({type:"uniformsBatch",uniforms:e}):this.isReducedMotion&&!this.isPaused&&!this.isHiddenByViewport&&this.drawMainThreadFrame()}}startThemeTransition(e){this.themeTweenRaf&&(cancelAnimationFrame(this.themeTweenRaf),this.themeTweenRaf=0);let t=e?1:0,i=this.resolveTargetPalette(e);i.length>0&&(this.basePaletteRgb=i);let r=this.currentTheme,s=this.toTriplet(this.activePaletteRgb.length>0?this.activePaletteRgb:this.basePaletteRgb),a=this.toTriplet(this.basePaletteRgb);if(this.isReducedMotion||typeof requestAnimationFrame!="function"){this.currentTheme=t,this.activePaletteRgb=a,this.pushUniformBatch({uTheme:t,uColor1:a[0],uColor2:a[1],uColor3:a[2]});return}let n=performance.now(),l=280;this.boostInteraction(500);let c=u=>{if(this.isDestroyed){this.themeTweenRaf=0;return}let h=Math.min(1,(u-n)/l),f=h<.5?2*h*h:1-Math.pow(-2*h+2,2)/2;this.currentTheme=r+(t-r)*f;let d=(g,b)=>[g[0]+(b[0]-g[0])*f,g[1]+(b[1]-g[1])*f,g[2]+(b[2]-g[2])*f],m=d(s[0],a[0]),p=d(s[1],a[1]),v=d(s[2],a[2]);this.activePaletteRgb=[m,p,v],this.pushUniformBatch({uTheme:this.currentTheme,uColor1:m,uColor2:p,uColor3:v}),h<1?this.themeTweenRaf=requestAnimationFrame(c):(this.themeTweenRaf=0,this.scrollStopsRgb.length>=2&&(this.lastScrollColorT=-1,this.updateScrollColorShift(this.computeScrollProgress())))};this.themeTweenRaf=requestAnimationFrame(c)}bindThemeWatchers(){if(this.unbindThemeWatchers(),!(typeof window>"u"||typeof document>"u")&&(typeof window.matchMedia=="function"&&(this.colorSchemeQuery=window.matchMedia("(prefers-color-scheme: dark)"),typeof this.colorSchemeQuery.addEventListener=="function"&&this.colorSchemeQuery.addEventListener("change",this.handleThemeChange)),typeof MutationObserver<"u")){this.themeMutationObserver=new MutationObserver(this.handleThemeChange);let e=["class","data-theme","data-mode","data-bs-theme","style"];this.themeMutationObserver.observe(document.documentElement,{attributes:!0,attributeFilter:e}),document.body&&this.themeMutationObserver.observe(document.body,{attributes:!0,attributeFilter:e}),this.container!==document.body&&this.container!==document.documentElement&&this.themeMutationObserver.observe(this.container,{attributes:!0,attributeFilter:e})}}unbindThemeWatchers(){this.themeTweenRaf&&(cancelAnimationFrame(this.themeTweenRaf),this.themeTweenRaf=0),this.colorSchemeQuery&&typeof this.colorSchemeQuery.removeEventListener=="function"&&this.colorSchemeQuery.removeEventListener("change",this.handleThemeChange),this.colorSchemeQuery=null,this.themeMutationObserver?.disconnect(),this.themeMutationObserver=null}updateScrollColorShift(e){if(this.scrollStopsRgb.length<2)return;let t=Math.min(1,Math.max(0,e));if(Math.abs(t-this.lastScrollColorT)<.002)return;this.lastScrollColorT=t;let i=j(this.scrollStopsRgb,this.resolvedDarkTheme),r=i.length-1,s=t*r,a=Math.min(r-1,Math.floor(s)),n=s-a,l=i[a],c=i[a+1],u=i[Math.min(i.length-1,a+2)]??l,h=[l[0]+(c[0]-l[0])*n,l[1]+(c[1]-l[1])*n,l[2]+(c[2]-l[2])*n],f=[c[0]+(u[0]-c[0])*n,c[1]+(u[1]-c[1])*n,c[2]+(u[2]-c[2])*n],d=this.basePaletteRgb[2]??u;this.activePaletteRgb=[h,f,d],this.pushUniformBatch({uColor1:h,uColor2:f,uColor3:d})}syncScrollColorListener(){if(typeof window>"u")return;let e=this.scrollStopsRgb.length>=2;e&&!this.hasScrollColorListener?(window.addEventListener("scroll",this.handleScrollColorEvent,{passive:!0}),this.hasScrollColorListener=!0,this.lastScrollColorT=-1,this.updateScrollColorShift(this.computeScrollProgress())):!e&&this.hasScrollColorListener&&(window.removeEventListener("scroll",this.handleScrollColorEvent),this.hasScrollColorListener=!1,this.scrollColorRaf&&(cancelAnimationFrame(this.scrollColorRaf),this.scrollColorRaf=0))}getLocalTouchCoords(e){let t=this.container.getBoundingClientRect();if(t.width<=0||t.height<=0)return null;let i=(e.clientX-t.left)/t.width,r=1-(e.clientY-t.top)/t.height;return i<0||i>1||r<0||r>1?null:[i,r]}syncTouchListener(){typeof window>"u"||(this.interactive&&!this.hasTouchListener?(this.container.addEventListener("touchstart",this.handleTouchStart,{passive:!0}),this.container.addEventListener("touchmove",this.handleTouchMove,{passive:!0}),this.container.addEventListener("touchend",this.handleTouchEnd,{passive:!0}),this.container.addEventListener("touchcancel",this.handleTouchEnd,{passive:!0}),this.hasTouchListener=!0):!this.interactive&&this.hasTouchListener&&(this.container.removeEventListener("touchstart",this.handleTouchStart),this.container.removeEventListener("touchmove",this.handleTouchMove),this.container.removeEventListener("touchend",this.handleTouchEnd),this.container.removeEventListener("touchcancel",this.handleTouchEnd),this.hasTouchListener=!1))}seedUniformsFromOptions(e,t=!1){let i={};if(typeof e.speed=="number"?(this.targetSpeed=e.speed,t&&(this.currentSpeed=e.speed),this.customUniforms.set("uSpeed",e.speed),i.uSpeed=e.speed):this.customUniforms.has("uSpeed")||(this.targetSpeed=1,this.currentSpeed=1,this.customUniforms.set("uSpeed",1),i.uSpeed=1),t||e.quality!==void 0){let n=this.computeEffectiveQuality();this.customUniforms.set("uQuality",n),i.uQuality=n}e.scrollColors!==void 0&&(this.scrollStopsRgb=this.parseScrollStops(e.scrollColors),this.lastScrollColorT=-1);let r=this.resolvedDarkTheme;e.theme!==void 0&&(this.themeMode=e.theme);let s=this.detectDarkTheme(this.themeMode);if(this.resolvedDarkTheme=s,t&&(this.currentTheme=s?1:0,this.customUniforms.set("uTheme",this.currentTheme),i.uTheme=this.currentTheme),t||e.colors!==void 0||e.lightColors!==void 0||e.darkColors!==void 0||e.theme!==void 0||e.scrollColors!==void 0){let n=this.parseColorList(this.options.colors);n.length>0&&(this.rawBasePaletteRgb=n);let l=this.resolveTargetPalette(s);if(l.length>0)if(this.basePaletteRgb=l,this.rawBasePaletteRgb.length===0&&(this.rawBasePaletteRgb=l),!t&&s!==r)this.startThemeTransition(s);else{let[c,u,h]=this.toTriplet(l);this.activePaletteRgb=[c,u,h],this.customUniforms.set("uColor1",c),this.customUniforms.set("uColor2",u),this.customUniforms.set("uColor3",h),i.uColor1=c,i.uColor2=u,i.uColor3=h,t||(this.currentTheme=s?1:0,this.customUniforms.set("uTheme",this.currentTheme),i.uTheme=this.currentTheme)}}if(e.uniforms)for(let[n,l]of Object.entries(e.uniforms))this.customUniforms.set(n,l),i[n]=typeof l=="number"?l:Array.from(l);return this.shouldPreserveBg()&&(this.customUniforms.set("uTransparentBg",1),i.uTransparentBg=1),i}fallbackToMainThread(e,t,i,r){if(this.isDestroyed)return;this.worker&&(this.worker.terminate(),this.worker=null),this.isOffscreen=!1,this.resetFrameTracking(),this.markContextReleased();let s=this.canvas.cloneNode(!1);this.canvas.replaceWith(s),this.canvas=s,this.initMainThreadMode(e,t,i,r)}initOffscreenMode(e,t,i,r){try{let s=ve(),a=this.canvas.transferControlToOffscreen();this.worker=s,this.isOffscreen=!0,this.markContextActive(),s.onmessage=l=>{if(l.data?.type==="error")this.fallbackToMainThread(e,t,i,r);else if(l.data?.type==="stats"){this.reportedFps=typeof l.data.fps=="number"?l.data.fps:0,this.reportedFrameTimeMs=typeof l.data.frameTimeMs=="number"?l.data.frameTimeMs:0;let c=typeof l.data.targetFps=="number"?l.data.targetFps:0;this.reportedFrameTimeMs>0&&c>0&&D.recordGpuFrame(this.reportedFrameTimeMs,c,performance.now())}},s.onerror=()=>{this.fallbackToMainThread(e,t,i,r)};let n={};this.customUniforms.forEach((l,c)=>{n[c]=typeof l=="number"?l:Array.from(l)}),s.postMessage({type:"init",canvas:a,width:this.width,height:this.height,minDpr:t,maxDpr:i,dynamicRes:r,reducedMotion:this.isReducedMotion,vertexShader:e.vertexShader??ge,fragmentShader:e.fragmentShader,feedbackShader:e.feedbackShader??null,feedbackScale:this.feedbackScale,feedbackMaxDim:this.feedbackMaxDim,feedbackFloat:this.feedbackFloat,initialScroll:this.scroll,ambientFps:this.ambientFps,activeFps:this.activeFps,survivalPaused:this.isSurvivalSuspended,uniforms:n},[a])}catch{this.isOffscreen=!1,this.markContextReleased(),this.initMainThreadMode(e,t,i,r)}}computeFboDimsMain(e,t){let i=Math.max(1,Math.floor(e*this.feedbackScale)),r=Math.max(1,Math.floor(t*this.feedbackScale)),s=Math.max(i,r);if(s>this.feedbackMaxDim){let a=this.feedbackMaxDim/s;i=Math.max(1,Math.floor(i*a)),r=Math.max(1,Math.floor(r*a))}return[i,r]}destroyPingPongMain(){if(!this.pingPong||!this.gl){this.pingPong=null;return}for(let e=0;e<2;e++)this.gl.deleteFramebuffer(this.pingPong[e].fbo),this.gl.deleteTexture(this.pingPong[e].tex);this.pingPong=null}createPingPongMain(e){if(this.destroyPingPongMain(),!this.options.feedbackShader||this.isContextLost)return;let[t,i]=this.computeFboDimsMain(this.canvas.width,this.canvas.height);this.fboW=t,this.fboH=i;let r=e.RGBA8,s=e.UNSIGNED_BYTE;this.feedbackFloat&&(e.getExtension("EXT_color_buffer_float")||e.getExtension("EXT_color_buffer_half_float"))&&(r=e.RGBA16F,s=e.HALF_FLOAT);let n=(c,u)=>{let h=[];for(let f=0;f<2;f++){let d=e.createTexture(),m=e.createFramebuffer();if(!d||!m)return d&&e.deleteTexture(d),m&&e.deleteFramebuffer(m),h.forEach(p=>{e.deleteFramebuffer(p.fbo),e.deleteTexture(p.tex)}),null;if(e.bindTexture(e.TEXTURE_2D,d),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texImage2D(e.TEXTURE_2D,0,c,this.fboW,this.fboH,0,e.RGBA,u,null),e.bindFramebuffer(e.FRAMEBUFFER,m),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,d,0),e.checkFramebufferStatus(e.FRAMEBUFFER)!==e.FRAMEBUFFER_COMPLETE)return e.deleteFramebuffer(m),e.deleteTexture(d),h.forEach(p=>{e.deleteFramebuffer(p.fbo),e.deleteTexture(p.tex)}),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindTexture(e.TEXTURE_2D,null),null;e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),h.push({fbo:m,tex:d})}return e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindTexture(e.TEXTURE_2D,null),[h[0],h[1]]},l=n(r,s);!l&&r!==e.RGBA8&&(r=e.RGBA8,s=e.UNSIGNED_BYTE,l=n(r,s)),this.fboFormat=r,this.fboType=s,this.pingPong=l,this.readIdx=0,this.writeIdx=1}resizePingPongMain(){if(!this.pingPong||!this.gl||this.isContextLost)return;let[e,t]=this.computeFboDimsMain(this.canvas.width,this.canvas.height);if(e===this.fboW&&t===this.fboH)return;let i=this.gl,r=this.fboW,s=this.fboH,a=this.pingPong[this.readIdx],n=[];for(let l=0;l<2;l++){let c=i.createTexture(),u=i.createFramebuffer();i.bindTexture(i.TEXTURE_2D,c),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texImage2D(i.TEXTURE_2D,0,this.fboFormat,e,t,0,i.RGBA,this.fboType,null),i.bindFramebuffer(i.FRAMEBUFFER,u),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,c,0),n.push({fbo:u,tex:c})}i.bindFramebuffer(i.READ_FRAMEBUFFER,a.fbo),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,n[0].fbo),i.blitFramebuffer(0,0,r,s,0,0,e,t,i.COLOR_BUFFER_BIT,i.LINEAR),i.bindFramebuffer(i.READ_FRAMEBUFFER,null),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,null),i.bindTexture(i.TEXTURE_2D,null);for(let l=0;l<2;l++)i.deleteFramebuffer(this.pingPong[l].fbo),i.deleteTexture(this.pingPong[l].tex);this.pingPong=[n[0],n[1]],this.fboW=e,this.fboH=t,this.readIdx=0,this.writeIdx=1}initMainThreadPipeline(e){let t=this.options.vertexShader??z;this.programEntry=T.getOrCreateProgram(e,this.options.fragmentShader,t),this.options.feedbackShader?this.feedbackProgramEntry=T.getOrCreateProgram(e,this.options.feedbackShader,t):this.feedbackProgramEntry=null,this.vao=e.createVertexArray(),e.bindVertexArray(this.vao),this.vbo=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.vbo),e.bufferData(e.ARRAY_BUFFER,De,e.STATIC_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),e.bindVertexArray(null),this.needsResize=!1,this.applyCanvasSize(),this.options.feedbackShader&&this.createPingPongMain(e)}initMainThreadMode(e,t,i,r){let s=null,a=C.acquireRecycledMainContext();if(a?(a.canvas.style.background="",this.canvas.replaceWith(a.canvas),this.canvas=a.canvas,s=a.gl):s=this.canvas.getContext("webgl2",{alpha:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance",preserveDrawingBuffer:!1}),!s){console.warn("[FluxFX] WebGL2 is not supported on this device."),this.isBudgetSuspended=!0,this.applyBudgetFallbackStyle();return}this.gl=s,this.markContextActive(),this.canvas.addEventListener("webglcontextlost",this.handleContextLost,!1),this.canvas.addEventListener("webglcontextrestored",this.handleContextRestored,!1),this.dynamicRes=new $({minScale:r?t:i,maxScale:i}),this.initMainThreadPipeline(s),this.drawMainThreadFrame()}applyCanvasSize(){if(!this.gl||!this.dynamicRes||this.isContextLost)return;let e=this.dynamicRes.scale,t=Math.max(1,Math.round(this.width*e)),i=Math.max(1,Math.round(this.height*e));(this.canvas.width!==t||this.canvas.height!==i)&&(this.canvas.width=t,this.canvas.height=i,this.gl.viewport(0,0,t,i)),this.pingPong&&this.resizePingPongMain()}bindCommonUniformsMain(e,t,i,r){let s=T.getUniformLocation(e,t,"uTime");s&&e.uniform1f(s,this.elapsedSec);let a=T.getUniformLocation(e,t,"uDelta");a&&e.uniform1f(a,this.lastDeltaSec);let n=T.getUniformLocation(e,t,"uResolution");n&&e.uniform2f(n,i,r);let l=T.getUniformLocation(e,t,"uCanvasResolution");l&&e.uniform2f(l,this.canvas.width,this.canvas.height);let c=T.getUniformLocation(e,t,"uDpr");c&&this.dynamicRes&&e.uniform1f(c,this.dynamicRes.scale);let u=T.getUniformLocation(e,t,"uMouse");u&&e.uniform2f(u,this.mouse[0],this.mouse[1]);let h=T.getUniformLocation(e,t,"uMouseVel");h&&e.uniform2f(h,this.mouseVel[0],this.mouseVel[1]);let f=T.getUniformLocation(e,t,"uMouseDown");f&&e.uniform1f(f,this.mouseDown);let d=T.getUniformLocation(e,t,"uMouseActive");d&&e.uniform1f(d,this.mouseActive);let m=T.getUniformLocation(e,t,"uScroll");m&&e.uniform1f(m,this.scroll);let p=T.getUniformLocation(e,t,"uScrollVel");p&&e.uniform1f(p,this.scrollVel),this.customUniforms.forEach((v,g)=>{let b=T.getUniformLocation(e,t,g);b&&(g==="uSpeed"?e.uniform1f(b,this.currentSpeed):typeof v=="number"?e.uniform1f(b,v):v.length===2?e.uniform2f(b,v[0],v[1]):v.length===3?e.uniform3f(b,v[0],v[1],v[2]):v.length===4&&e.uniform4f(b,v[0],v[1],v[2],v[3]))})}drawMainThreadFrame(){if(!this.gl||!this.programEntry||this.isContextLost)return;let e=this.gl;if(e.bindVertexArray(this.vao),this.feedbackProgramEntry&&this.pingPong){e.bindFramebuffer(e.FRAMEBUFFER,this.pingPong[this.writeIdx].fbo),e.viewport(0,0,this.fboW,this.fboH),e.useProgram(this.feedbackProgramEntry.program),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.pingPong[this.readIdx].tex);let t=T.getUniformLocation(e,this.feedbackProgramEntry,"uPrevFrame");t&&e.uniform1i(t,0),this.bindCommonUniformsMain(e,this.feedbackProgramEntry,this.fboW,this.fboH),e.drawArrays(e.TRIANGLES,0,3);let i=this.readIdx;this.readIdx=this.writeIdx,this.writeIdx=i,e.bindFramebuffer(e.FRAMEBUFFER,null),e.viewport(0,0,this.canvas.width,this.canvas.height)}if(e.useProgram(this.programEntry.program),this.pingPong){e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.pingPong[this.readIdx].tex);let t=T.getUniformLocation(e,this.programEntry,"uFeedback");t&&e.uniform1i(t,0);let i=T.getUniformLocation(e,this.programEntry,"uPrevFrame");i&&e.uniform1i(i,0)}this.bindCommonUniformsMain(e,this.programEntry,this.canvas.width,this.canvas.height),e.drawArrays(e.TRIANGLES,0,3)}render(e,t){if(this.isOffscreen||this.isPaused||this.isHiddenByViewport||this.isReducedMotion||this.isContextLost||this.isSurvivalSuspended||this.isBudgetSuspended||this.isDestroyed||!this.gl||!this.programEntry)return;let i=performance.now(),r=this.lastRenderNow?Math.min(i-this.lastRenderNow,100):16.67;this.lastRenderNow=i,this.prevFrameDrew&&(this.dynamicRes&&this.dynamicRes.recordFrame(r,i)&&(this.needsResize=!0),this.prevFrameDrew=!1);let a=i<this.boostUntil||this.mouseDown>.5?this.activeFps:this.ambientFps,n=1e3/a-2;if(this.lastDrawNow>0&&i-this.lastDrawNow<n)return;let l=this.lastDrawNow?i-this.lastDrawNow:1e3/a,c=Math.min(l,100);this.lastDrawNow=i,a!==this.lastTargetFps?(this.lastTargetFps=a,this.avgDrawDeltaMs=0):l>0&&l<500&&(this.avgDrawDeltaMs=this.avgDrawDeltaMs===0?l:this.avgDrawDeltaMs*.85+l*.15),this.avgDrawDeltaMs>0&&(this.reportedFps=Math.round(1e3/this.avgDrawDeltaMs),this.reportedFrameTimeMs=Math.round(this.avgDrawDeltaMs*100)/100),l>0&&l<500&&D.recordGpuFrame(l,a,i);let u=Math.max(.001,Math.min(c*.001,.05));if(this.lastDeltaSec=u,this.currentSpeed+=(this.targetSpeed-this.currentSpeed)*q(7.5,u),this.elapsedSec+=u*this.currentSpeed,this.needsResize&&(this.needsResize=!1,this.applyCanvasSize()),this.mouseActive+=(this.targetMouseActive-this.mouseActive)*q(7,u),this.mouseActive<.001&&this.targetMouseActive===0&&(this.mouseActive=0),this.targetMouseActive>.5){let h=this.mouse[0],f=this.mouse[1],d=q(13,u);this.mouse[0]+=(this.targetMouse[0]-this.mouse[0])*d,this.mouse[1]+=(this.targetMouse[1]-this.mouse[1])*d,this.mouseVel[0]=Math.max(-8,Math.min(8,(this.mouse[0]-h)/u)),this.mouseVel[1]=Math.max(-8,Math.min(8,(this.mouse[1]-f)/u))}else this.mouseVel[0]=0,this.mouseVel[1]=0;if(this.trackScroll){let h=this.scroll;this.scroll+=(this.targetScroll-this.scroll)*q(9.5,u),this.scrollVel=Math.max(-6,Math.min(6,(this.scroll-h)/u))}this.drawMainThreadFrame(),this.prevFrameDrew=!0}applyProtectionState(){if(this.isDestroyed||this.isBudgetSuspended)return;let e=this.resolveTierConfig(),{minDpr:t,maxDpr:i}=this.resolveDprBounds(),s=this.options.dynamicResolution??!0?t:i,a=this.isSurvivalSuspended,n=this.feedbackMaxDim;this.ambientFps=e.ambientFps,this.activeFps=e.activeFps,this.feedbackMaxDim=e.feedbackMaxDim,this.isSurvivalSuspended=e.suspended,this.isSurvivalSuspended&&!a&&this.resetFrameTracking(),this.isOffscreen&&this.worker?this.worker.postMessage({type:"protection",minDpr:s,maxDpr:i,feedbackMaxDim:this.feedbackMaxDim,ambientFps:this.ambientFps,activeFps:this.activeFps,suspended:this.isSurvivalSuspended}):((this.dynamicRes?.setBounds(s,i)??!1)||n!==this.feedbackMaxDim)&&(this.isReducedMotion&&!this.isPaused&&!this.isHiddenByViewport?(this.needsResize=!1,this.applyCanvasSize(),this.drawMainThreadFrame()):this.needsResize=!0),a!==this.isSurvivalSuspended&&this.wakeCallback?.()}syncDprBounds(){this.applyProtectionState()}watchDevicePixelRatio(){if(this.dprMediaQuery&&(this.dprMediaQuery.removeEventListener("change",this.handleDprChange),this.dprMediaQuery=null),typeof window>"u"||typeof window.matchMedia!="function")return;let e=window.devicePixelRatio||1;this.dprMediaQuery=window.matchMedia(`(resolution: ${e}dppx)`),this.dprMediaQuery.addEventListener("change",this.handleDprChange)}updateOptions(e){if(this.isDestroyed)return;let t=this.options.quality;this.options={...this.options,...e},e.layer!==void 0&&(this.layerMode=e.layer),(e.layer!==void 0||e.overlayOpacity!==void 0)&&this.applyCanvasLayerStyle(),typeof e.adaptToSurface=="boolean"&&(this.adaptToSurface=e.adaptToSurface,!this.adaptToSurface&&this.isSurfaceAdapted&&(this.isSurfaceAdapted=!1,this.lastSurfaceEl=null,this.lastSurfaceKey="",this.startPaletteTween(this.basePaletteRgb,200)));let i=this.seedUniformsFromOptions(e,!1);if(e.preserveBg!==void 0||e.layer!==void 0){let s=this.shouldPreserveBg()?1:Number(this.customUniforms.get("uTransparentBg")??0);this.customUniforms.set("uTransparentBg",s),i.uTransparentBg=s}if(this.boostInteraction(1200),e.quality!==void 0&&e.quality!==t){let r=O[e.quality]??O.medium;this.baseFeedbackMaxDim=this.options.feedbackMaxDim??r.fboMaxDim}if(e.feedbackMaxDim!==void 0&&(this.baseFeedbackMaxDim=e.feedbackMaxDim),(e.quality!==void 0&&e.quality!==t||e.feedbackMaxDim!==void 0||e.minDpr!==void 0||e.maxDpr!==void 0||e.dynamicResolution!==void 0)&&this.syncDprBounds(),typeof e.interactive=="boolean"&&e.interactive!==this.interactive&&(this.interactive=e.interactive,this.syncPointerListener(),this.syncTouchListener()),typeof e.trackScroll=="boolean"&&e.trackScroll!==this.trackScroll&&(this.trackScroll=e.trackScroll,this.syncScrollListener()),e.scrollColors!==void 0&&this.syncScrollColorListener(),typeof e.respectReducedMotion=="boolean"){this.respectReducedMotion=e.respectReducedMotion;let r=this.reducedMotionQuery?.matches??!1;this.applyReducedMotionState(this.respectReducedMotion&&r)}if(this.isBudgetSuspended){this.applyBudgetFallbackStyle();return}this.isOffscreen&&this.worker?Object.keys(i).length>0&&this.worker.postMessage({type:"uniformsBatch",uniforms:i}):this.isReducedMotion&&(this.needsResize&&(this.needsResize=!1,this.applyCanvasSize()),this.drawMainThreadFrame())}applyReducedMotionState(e){this.isReducedMotion!==e&&(this.isReducedMotion=e,this.resetFrameTracking(),this.isOffscreen&&this.worker?this.worker.postMessage({type:"reducedMotion",value:e}):e&&(this.needsResize&&(this.needsResize=!1,this.applyCanvasSize()),this.drawMainThreadFrame()),this.wakeCallback?.())}getLocalPointerCoords(e){let t=this.container.getBoundingClientRect();if(t.width<=0||t.height<=0||e.clientX<t.left||e.clientX>t.right||e.clientY<t.top||e.clientY>t.bottom)return null;let i=(e.clientX-t.left)/t.width,r=1-(e.clientY-t.top)/t.height;return[i,r]}syncInteractiveAttr(){if(this.interactive&&!this.isDestroyed){this.container.setAttribute("data-fluxfx-interactive","true");return}let e=!1;C.instances.forEach(t=>{t!==this&&!t.isDestroyed&&t.interactive&&t.container===this.container&&(e=!0)}),e||this.container.removeAttribute("data-fluxfx-interactive")}isShadowedByChildInteractive(e){if(!(e instanceof Element))return!1;let t=e.closest('[data-fluxfx-interactive="true"]');return!!(t&&t!==this.container&&this.container.contains(t))}syncPointerListener(){this.syncInteractiveAttr(),this.interactive&&!this.hasPointerListener?(this.container.addEventListener("pointerenter",this.handlePointerEnter,{passive:!0}),this.container.addEventListener("pointermove",this.handlePointerMove,{passive:!0}),this.container.addEventListener("pointerleave",this.handlePointerLeave,{passive:!0}),this.container.addEventListener("pointerdown",this.handlePointerDown,{passive:!0}),window.addEventListener("pointerup",this.handlePointerUp,{passive:!0}),window.addEventListener("pointercancel",this.handlePointerUp,{passive:!0}),this.hasPointerListener=!0):!this.interactive&&this.hasPointerListener&&(this.container.removeEventListener("pointerenter",this.handlePointerEnter),this.container.removeEventListener("pointermove",this.handlePointerMove),this.container.removeEventListener("pointerleave",this.handlePointerLeave),this.container.removeEventListener("pointerdown",this.handlePointerDown),window.removeEventListener("pointerup",this.handlePointerUp),window.removeEventListener("pointercancel",this.handlePointerUp),this.handlePointerLeave(),this.hasPointerListener=!1)}syncScrollListener(){this.trackScroll&&!this.hasScrollListener?(window.addEventListener("scroll",this.handleScroll,{passive:!0}),this.hasScrollListener=!0,this.handleScroll()):!this.trackScroll&&this.hasScrollListener&&(window.removeEventListener("scroll",this.handleScroll),this.hasScrollListener=!1)}bindObservers(e){typeof ResizeObserver<"u"&&(this.resizeObserver=new ResizeObserver(t=>{let i=t[0];if(!i)return;let r=Math.max(1,Math.floor(i.contentRect.width)),s=Math.max(1,Math.floor(i.contentRect.height));r===this.width&&s===this.height||(this.width=r,this.height=s,this.boostInteraction(600),this.trackScroll&&this.handleScroll(),this.isOffscreen&&this.worker?this.worker.postMessage({type:"resize",width:this.width,height:this.height}):this.isReducedMotion&&!this.isPaused&&!this.isHiddenByViewport?(this.needsResize=!1,this.applyCanvasSize(),this.drawMainThreadFrame()):this.needsResize=!0)}),this.resizeObserver.observe(this.container)),e&&typeof IntersectionObserver<"u"&&(this.visibilityObserver=new IntersectionObserver(t=>{let i=t[0]?.isIntersecting??!0;if(this.isHiddenByViewport=!i,i){if(this.lastActiveAt=X(),this.isBudgetSuspended&&!this.isPaused){this.restoreContextFromBudget();return}}else this.handlePointerLeave(),this.resetFrameTracking();this.isOffscreen&&this.worker&&this.worker.postMessage({type:i&&!this.isPaused?"resume":"pause"}),this.wakeCallback?.()},{rootMargin:"50px"}),this.visibilityObserver.observe(this.container)),this.reducedMotionQuery&&this.reducedMotionQuery.addEventListener("change",this.handleReducedMotionChange),this.isOffscreen&&typeof document<"u"&&document.addEventListener("visibilitychange",this.handleDocVisibility),this.watchDevicePixelRatio(),this.bindThemeWatchers(),this.syncPointerListener(),this.syncTouchListener(),this.syncScrollListener(),this.syncScrollColorListener()}setUniform(e,t){if(!this.isDestroyed){if(this.customUniforms.set(e,t),e==="uSpeed"&&typeof t=="number"&&(this.targetSpeed=t),this.boostInteraction(1200),this.isBudgetSuspended){this.applyBudgetFallbackStyle();return}this.isOffscreen&&this.worker?this.worker.postMessage({type:"uniform",name:e,value:typeof t=="number"?t:Array.from(t)}):this.isReducedMotion&&this.drawMainThreadFrame()}}setColor(e,t){let i=x(t,"#ffffff"),r=y.hexToVec3Into(i,y.scratchVec3);this.setUniform(e,[r[0],r[1],r[2]])}get isIdle(){return this.isDestroyed||this.isPaused||this.isHiddenByViewport||this.isReducedMotion||this.isContextLost}onWake(e){this.wakeCallback=e}pause(){this.isPaused||this.isDestroyed||(this.isPaused=!0,this.resetFrameTracking(),this.handlePointerLeave(),this.isOffscreen&&this.worker&&this.worker.postMessage({type:"pause"}))}resume(){if(!(!this.isPaused||this.isDestroyed)){if(this.isPaused=!1,this.lastRenderNow=0,this.lastDrawNow=0,this.lastActiveAt=X(),this.isBudgetSuspended&&!this.isHiddenByViewport){this.restoreContextFromBudget();return}this.isOffscreen&&this.worker&&!this.isHiddenByViewport?this.worker.postMessage({type:"resume"}):this.isReducedMotion&&!this.isHiddenByViewport&&(this.needsResize&&(this.needsResize=!1,this.applyCanvasSize()),this.drawMainThreadFrame())}}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.wakeCallback=null,this.unsubscribeGuard?.(),this.unsubscribeGuard=null,this.unbindThemeWatchers(),this.touchBurstTimer&&(window.clearTimeout(this.touchBurstTimer),this.touchBurstTimer=0),this.touchLeaveTimer&&(window.clearTimeout(this.touchLeaveTimer),this.touchLeaveTimer=0),this.hasTouchListener&&(this.container.removeEventListener("touchstart",this.handleTouchStart),this.container.removeEventListener("touchmove",this.handleTouchMove),this.container.removeEventListener("touchend",this.handleTouchEnd),this.container.removeEventListener("touchcancel",this.handleTouchEnd),this.hasTouchListener=!1),this.hasScrollColorListener&&(window.removeEventListener("scroll",this.handleScrollColorEvent),this.hasScrollColorListener=!1),this.scrollColorRaf&&(cancelAnimationFrame(this.scrollColorRaf),this.scrollColorRaf=0),this.isBodyMount&&(this.container.style.minHeight=this.origBodyMinHeight),C.instances.delete(this),this.syncInteractiveAttr(),this.resetFrameTracking(),this.resizeObserver?.disconnect(),this.resizeObserver=null,this.visibilityObserver?.disconnect(),this.visibilityObserver=null,this.reducedMotionQuery&&(this.reducedMotionQuery.removeEventListener("change",this.handleReducedMotionChange),this.reducedMotionQuery=null),this.dprMediaQuery&&(this.dprMediaQuery.removeEventListener("change",this.handleDprChange),this.dprMediaQuery=null),typeof document<"u"&&document.removeEventListener("visibilitychange",this.handleDocVisibility),this.hasPointerListener&&(this.container.removeEventListener("pointerenter",this.handlePointerEnter),this.container.removeEventListener("pointermove",this.handlePointerMove),this.container.removeEventListener("pointerleave",this.handlePointerLeave),this.container.removeEventListener("pointerdown",this.handlePointerDown),window.removeEventListener("pointerup",this.handlePointerUp),window.removeEventListener("pointercancel",this.handlePointerUp),this.hasPointerListener=!1),this.hasScrollListener&&(window.removeEventListener("scroll",this.handleScroll),this.hasScrollListener=!1),this.canvas.removeEventListener("webglcontextlost",this.handleContextLost,!1),this.canvas.removeEventListener("webglcontextrestored",this.handleContextRestored,!1),this.isOffscreen&&this.worker&&(this.worker.postMessage({type:"destroy"}),this.worker=null),this.releaseMainThreadContext(!1),this.markContextReleased(),y.releaseVec2(this.mouse),y.releaseVec2(this.targetMouse),y.releaseVec2(this.mouseVel),this.customUniforms.clear(),C.reclaimBudgetForWaiting())}};C._activeContexts=0,C._maxContexts=be(),C.instances=new Set,C.recycledMainContexts=[];var L=C;var Y=class{constructor(){this.plugins=new Map;this.activeByElement=new WeakMap;this.activeSet=new Set;this.visibilityObserver=null;this.visibilityCallbacks=new WeakMap;this.removeTicker=null;this.removeVisibilitySub=null}ensureObserver(){return typeof window>"u"||typeof IntersectionObserver>"u"?null:(this.visibilityObserver||(this.visibilityObserver=new IntersectionObserver(e=>{for(let t=0;t<e.length;t++){let i=e[t],r=this.visibilityCallbacks.get(i.target);r&&r.forEach(s=>s(i.isIntersecting))}},{rootMargin:"50px"})),this.visibilityObserver)}ensureVisibilitySub(){this.removeVisibilitySub||(this.removeVisibilitySub=A.onVisibilityChange(e=>{this.activeSet.forEach(t=>{t.faulted||(e?t.instance.pause?.():t.visible&&t.instance.resume?.())}),this.syncTickerState()}))}hasActiveTickWork(){let e=!1;return this.activeSet.forEach(t=>{e||!t.visible||t.faulted||!t.instance.update||t.instance.isIdle?.()||(e=!0)}),e}syncTickerState(){this.hasActiveTickWork()?this.ensureTicker():this.removeTicker&&(this.removeTicker(),this.removeTicker=null)}ensureTicker(){this.removeTicker||(this.removeTicker=A.add((e,t)=>{let i=!1;this.activeSet.forEach(r=>{if(!(!r.visible||r.faulted||!r.instance.update)&&!r.instance.isIdle?.()){try{r.instance.update(e,t)}catch(s){r.faulted=!0,console.error(`[FluxFX] Runtime error in "${r.name}" (auto-paused):`,s);return}r.instance.isIdle?.()||(i=!0)}}),i||this.syncTickerState()}))}cleanupEmptyEngine(){this.syncTickerState(),this.activeSet.size===0&&this.removeVisibilitySub&&(this.removeVisibilitySub(),this.removeVisibilitySub=null)}bindWake(e){e.instance.onWake?.(()=>{this.activeSet.has(e)&&this.syncTickerState()})}register(e){return this.plugins.set(e.name,e),this}has(e){return this.plugins.has(e)}setMaxWebGLContexts(e){L.setMaxActiveContexts(e)}getStats(){let e=0,t=0,i=!1,r=A.isHidden;this.activeSet.forEach(u=>{u.visible&&e++;let h=u.instance.isIdle?.()??!1;r||!u.visible||u.faulted||h?t++:!u.instance.isWebGL&&u.instance.isIdle&&(i=!0)});let s=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,a=L.getRenderStats(),n=A.fps,l=A.frameTimeMs;!r&&a.activeRendering>0&&!i?(n=a.fps,l=a.frameTimeMs):r&&(n=0,l=0);let c=D.getSnapshot();return{mounted:this.activeSet.size,visible:e,pausedEffects:t,activeLoops:A.isRunning?1:0,registered:this.plugins.size,webglContexts:L.activeContexts,activeContexts:L.activeContexts,maxWebGLContexts:L.maxActiveContexts,suspendedContexts:L.suspendedContexts,fps:n,frameTimeMs:l,reducedMotion:s,protectionTier:c.tier,protectionLabel:c.label}}apply(e,t,i={}){let r=this.plugins.get(t);if(!r)return console.warn(`[FluxFX] Effect "${t}" is not registered.`),()=>{};let s=this.activeByElement.get(e);s||(s=new Map,this.activeByElement.set(e,s));let a=s.get(t);a&&a.destroy();let n;try{n=r.mount(e,i)}catch(f){return console.error(`[FluxFX] Failed to mount "${t}":`,f),()=>{}}let l=i.pauseWhenHidden??!0,c=null,u=!1,h={el:e,name:t,plugin:r,instance:n,options:{...i},visible:!0,faulted:!1,destroy:()=>{if(!u){u=!0,c?.(),this.activeSet.delete(h),s?.delete(t);try{h.instance.destroy()}catch(f){console.error(`[FluxFX] Cleanup error in "${t}":`,f)}this.cleanupEmptyEngine()}}};if(l){let f=this.ensureObserver();if(f){let d=this.visibilityCallbacks.get(e);d||(d=new Set,this.visibilityCallbacks.set(e,d),f.observe(e));let m=p=>{h.visible=p,p&&!A.isHidden?h.instance.resume?.():h.instance.pause?.(),this.syncTickerState()};d.add(m),c=()=>{d?.delete(m),d&&d.size===0&&(f.unobserve(e),this.visibilityCallbacks.delete(e))}}}return s.set(t,h),this.activeSet.add(h),this.bindWake(h),this.ensureVisibilitySub(),A.isHidden&&h.instance.pause?.(),this.syncTickerState(),h.destroy}update(e,t,i={}){let s=this.activeByElement.get(e)?.get(t);if(!s)return!1;s.options={...s.options,...i};let a=s.options;if(s.instance.setOptions)try{return s.instance.setOptions(a),this.syncTickerState(),!0}catch(n){return console.error(`[FluxFX] Hot-update error in "${t}":`,n),!1}try{return s.instance.destroy(),s.instance=s.plugin.mount(e,a),s.faulted=!1,this.bindWake(s),(!s.visible||A.isHidden)&&s.instance.pause?.(),this.syncTickerState(),!0}catch(n){return s.faulted=!0,console.error(`[FluxFX] Fallback remount error in "${t}":`,n),this.syncTickerState(),!1}}scan(e=document){if(typeof document>"u")return;e.querySelectorAll("[data-fx]").forEach(i=>{let r=i.getAttribute("data-fx");if(!r)return;let s=r.trim().split(/\s+/).filter(Boolean),a=this.parseDatasetOptions(i),n=this.activeByElement.get(i);s.forEach(l=>{n?.has(l)||this.apply(i,l,a)})})}init(e){typeof document>"u"||(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>this.scan(e??document),{once:!0}):this.scan(e??document))}destroyAll(){let e=Array.from(this.activeSet);for(let t=0;t<e.length;t++)e[t].destroy()}parseDatasetOptions(e){let t={},i=new Set(["preserveBg","adaptToSurface","interactive","trackScroll","glare","offscreen","dynamicResolution","pauseWhenHidden","respectReducedMotion"]),r=new Set(["colors","lightColors","darkColors","scrollColors"]);for(let[s,a]of Object.entries(e.dataset)){if(!s.startsWith("fx")||s==="fx"||a===void 0)continue;let n=s.slice(2),l=n.charAt(0).toLowerCase()+n.slice(1),c=a.trim(),u=c.toLowerCase();c===""&&i.has(l)||u==="true"?t[l]=!0:u==="false"?t[l]=!1:r.has(l)?t[l]=c.split(",").map(h=>h.trim()).filter(Boolean):c!==""&&!Number.isNaN(Number(c))?t[l]=Number(c):t[l]=c}return t}},K=new Y;function Ae(o){if(o==null)return!1;let e=String(o).trim().toLowerCase();if(!e)return!1;if(e==="transparent"||e==="none")return!0;let t=e.match(/^rgba?\(\s*[\d.]+\s*,\s*[\d.]+\s*,\s*[\d.]+(?:\s*,\s*([\d.]+))?\s*\)$/);return t&&t[1]!==void 0?parseFloat(t[1])<=.001:!1}function xe(o){let e=o.replace("#","").trim(),t=e.length===3?e.split("").map(a=>a+a).join(""):e;if(t.length!==6)return!0;let i=parseInt(t.slice(0,2),16)/255,r=parseInt(t.slice(2,4),16)/255,s=parseInt(t.slice(4,6),16)/255;return .2126*i+.7152*r+.0722*s>.45}function Te(o,e){if(Array.isArray(o.colors)&&o.colors.length>0){let s=o.colors.filter(Boolean);if(s.length===1){let c=x(s[0],e[0]);return[c,c,c]}if(s.length===2){let c=x(s[0],e[0]),u=x(s[1],e[1]);return[c,u,u]}let a=x(s[0],e[0]),n=x(s[1]??a,e[1]),l=x(s[2]??n,e[2]);return[a,n,l]}if(typeof o.colors=="string"){let s=o.colors.split(",").map(a=>a.trim()).filter(Boolean);if(s.length===1){let a=x(s[0],e[0]);return[a,a,a]}if(s.length===2){let a=x(s[0],e[0]),n=x(s[1],e[1]);return[a,n,n]}if(s.length>2)return[x(s[0],e[0]),x(s[1],e[1]),x(s[2],e[2])]}if(o.color1===void 0&&o.color2===void 0&&o.color3===void 0)return e;let t=x(o.color1,e[0]),i=o.color2!==void 0?x(o.color2,t):t,r=o.color3!==void 0?x(o.color3,i):i;return[t,i,r]}function B(o,e){let t=Ae(o.bgColor),i=!t&&o.bgColor!==void 0&&String(o.bgColor).trim()!=="",r=i?x(o.bgColor,e):e,s=y.hexToVec3Into(r,y.scratchVec3);return{uBgColor:[s[0],s[1],s[2]],uHasBgColor:i?1:0,uTransparentBg:t?1:0,bgHex:r,hasBgColor:i,transparentBg:t}}function Be(o){return o==="high"?.65:o==="low"?.35:.5}function P(o){return{name:o.name,mount(e,t){let i=t.quality??"medium",r=new L(e,{fragmentShader:o.fragmentShader,vertexShader:o.vertexShader,feedbackShader:o.feedbackShader,feedbackScale:o.feedbackShader?Be(i):void 0,feedbackFloat:o.feedbackShader?o.feedbackFloat??!0:void 0,feedbackMaxDim:typeof t.feedbackMaxDim=="number"?t.feedbackMaxDim:void 0,speed:typeof t.speed=="number"?t.speed:1,quality:i,colors:Te(t,o.defaultColors),uniforms:o.resolveUniforms?o.resolveUniforms(t):void 0,theme:t.theme,lightColors:t.lightColors,darkColors:t.darkColors,scrollColors:t.scrollColors,trackScroll:t.trackScroll,layer:t.layer,preserveBg:t.preserveBg,adaptToSurface:t.adaptToSurface,overlayOpacity:t.overlayOpacity,interactive:t.interactive!==!1,dynamicResolution:t.dynamicResolution,minDpr:t.minDpr,maxDpr:t.maxDpr,offscreen:t.offscreen,pauseWhenHidden:t.pauseWhenHidden,respectReducedMotion:t.respectReducedMotion});return{isWebGL:!0,update(s,a){r.render(s,a)},setOptions(s){r.updateOptions({speed:typeof s.speed=="number"?s.speed:1,quality:s.quality,colors:Te(s,o.defaultColors),uniforms:o.resolveUniforms?o.resolveUniforms(s):void 0,theme:s.theme,lightColors:s.lightColors,darkColors:s.darkColors,scrollColors:s.scrollColors,trackScroll:s.trackScroll,layer:s.layer,preserveBg:s.preserveBg,adaptToSurface:s.adaptToSurface,overlayOpacity:s.overlayOpacity,interactive:s.interactive!==!1,dynamicResolution:s.dynamicResolution,minDpr:s.minDpr,maxDpr:s.maxDpr,feedbackMaxDim:typeof s.feedbackMaxDim=="number"?s.feedbackMaxDim:void 0,respectReducedMotion:s.respectReducedMotion})},isIdle(){return r.isIdle},onWake(s){r.onWake(s)},pause(){r.pause()},resume(){r.resume()},destroy(){r.destroy()}}}}}var Ue=`#version 300 es
858
+ `,dt=null;function ft(){if(typeof window>"u"||typeof Worker>"u"||typeof OffscreenCanvas>"u"||typeof HTMLCanvasElement>"u"||!("transferControlToOffscreen"in HTMLCanvasElement.prototype))return!1;let i=typeof navigator<"u"?navigator.userAgent:"";return!(/iP(ad|hone|od)/i.test(i)||/^((?!chrome|android).)*safari/i.test(i))}function Rt(){if(!dt){let i=new Blob([nr],{type:"application/javascript"});dt=URL.createObjectURL(i)}return new Worker(dt)}var Lt=Ye;var We={low:{max:1,min:.65,retinaMin:.85,fboMaxDim:512},medium:{max:2,min:.75,retinaMin:1,fboMaxDim:896},high:{max:2,min:1,retinaMin:1.25,fboMaxDim:1152}},ar=new Float32Array([-1,-1,3,-1,-1,3]),lr=12;function Ft(){if(typeof navigator>"u")return!1;let i=navigator.userAgent||"";return/Safari/i.test(i)&&!/Chrome|Chromium|Edg|CriOS|FxiOS|OPR/i.test(i)}function kt(){if(typeof navigator>"u")return 8;let i=navigator.userAgent||"",e=/Mobi|Android|iPhone|iPad|iPod/i.test(i);return Ft()||e?6:8}function je(){return typeof performance<"u"?performance.now():Date.now()}var ht=30,mt=60,ze=1800;function rt(i,e){return 1-Math.exp(-i*e)}var re=class re{constructor(e,t){this.resizeObserver=null;this.visibilityObserver=null;this.reducedMotionQuery=null;this.dprMediaQuery=null;this.worker=null;this.isOffscreen=!1;this.gl=null;this.programEntry=null;this.feedbackProgramEntry=null;this.vao=null;this.vbo=null;this.dynamicRes=null;this.lastRenderNow=0;this.lastDrawNow=0;this.lastTargetFps=0;this.prevFrameDrew=!1;this.avgDrawDeltaMs=0;this.boostUntil=0;this.reportedFps=0;this.reportedFrameTimeMs=0;this.elapsedSec=0;this.lastDeltaSec=.01667;this.currentSpeed=1;this.targetSpeed=1;this.needsResize=!1;this.pingPong=null;this.fboW=1;this.fboH=1;this.fboFormat=0;this.fboType=0;this.readIdx=0;this.writeIdx=1;this.customUniforms=new Map;this.textureUrls=new Map;this.textureUnits=new Map;this.loadedImages=new Map;this.mainTextures=new Map;this.textureLoadTokens=new Map;this.nextTextureUnit=1;this.mouse=Y.acquireVec2(.5,.5);this.targetMouse=Y.acquireVec2(.5,.5);this.mouseVel=Y.acquireVec2(0,0);this.mouseDown=0;this.mouseActive=0;this.targetMouseActive=0;this.isPointerInside=!1;this.scroll=0;this.targetScroll=0;this.scrollVel=0;this.hasScrollListener=!1;this.width=1;this.height=1;this.isPaused=!1;this.isHiddenByViewport=!1;this.isContextLost=!1;this.isReducedMotion=!1;this.isDestroyed=!1;this.wakeCallback=null;this.ambientFps=ht;this.activeFps=mt;this.protectionTier=be.tier;this.isSurvivalSuspended=!1;this.unsubscribeGuard=null;this.isBudgetSuspended=!1;this.lastActiveAt=je();this.hasDocVisibilityListener=!1;this.hasPointerListener=!1;this.countedContext=!1;this.isBodyMount=!1;this.origBodyMinHeight="";this.themeMode="auto";this.resolvedDarkTheme=!0;this.currentTheme=1;this.themeTweenRaf=0;this.colorSchemeQuery=null;this.themeMutationObserver=null;this.basePaletteRgb=[];this.activePaletteRgb=[];this.scrollStopsRgb=[];this.lastScrollColorT=-1;this.hasScrollColorListener=!1;this.scrollColorRaf=0;this.hasTouchListener=!1;this.touchBurstTimer=0;this.touchLeaveTimer=0;this.layerMode="background";this.adaptToSurface=!1;this.rawBasePaletteRgb=[];this.lastSurfaceEl=null;this.lastSurfaceKey="";this.lastSurfaceCheckAt=0;this.isSurfaceAdapted=!1;this.handleThemeChange=()=>{if(this.isDestroyed)return;let e=this.detectDarkTheme(this.themeMode);e!==this.resolvedDarkTheme&&(this.resolvedDarkTheme=e,this.startThemeTransition(e))};this.handleScrollColorEvent=()=>{this.isDestroyed||this.scrollStopsRgb.length<2||this.scrollColorRaf||(this.scrollColorRaf=requestAnimationFrame(()=>{if(this.scrollColorRaf=0,this.isDestroyed||this.scrollStopsRgb.length<2)return;let e=this.computeScrollProgress();this.updateScrollColorShift(e)}))};this.handleTouchStart=e=>{if(!this.interactive||this.isPaused||this.isHiddenByViewport||this.isReducedMotion)return;let t=e.touches[0];if(!t)return;if(this.isShadowedByChildInteractive(t.target)){this.isPointerInside&&this.handlePointerLeave();return}let o=this.getLocalTouchCoords(t);if(!o)return;this.touchLeaveTimer&&(window.clearTimeout(this.touchLeaveTimer),this.touchLeaveTimer=0),this.touchBurstTimer&&(window.clearTimeout(this.touchBurstTimer),this.touchBurstTimer=0);let[r,s]=o;this.inspectSurfaceFromTarget(t.target,!0),this.isPointerInside=!0,this.targetMouseActive=1,this.mouseDown=1,this.boostInteraction(ze),this.isOffscreen&&this.worker?(this.worker.postMessage({type:"mouseEnter",x:r,y:s}),this.worker.postMessage({type:"mouseDown",down:!0})):(this.mouse[0]=r,this.mouse[1]=s,this.targetMouse[0]=r,this.targetMouse[1]=s,this.mouseVel[0]=0,this.mouseVel[1]=0),this.touchBurstTimer=window.setTimeout(()=>{this.touchBurstTimer=0,!this.isDestroyed&&(this.mouseDown=0,this.isOffscreen&&this.worker&&this.worker.postMessage({type:"mouseDown",down:!1}))},160)};this.handleTouchMove=e=>{if(!this.interactive||this.isPaused||this.isHiddenByViewport||this.isReducedMotion)return;let t=e.touches[0];if(!t)return;if(this.isShadowedByChildInteractive(t.target)){this.isPointerInside&&this.handlePointerLeave();return}let o=this.getLocalTouchCoords(t);if(!o)return;let[r,s]=o;this.inspectSurfaceFromTarget(t.target),this.boostInteraction(ze),this.targetMouseActive=1,this.isOffscreen&&this.worker?this.worker.postMessage({type:"mouse",x:r,y:s}):(this.targetMouse[0]=r,this.targetMouse[1]=s)};this.handleTouchEnd=()=>{this.isDestroyed||(this.mouseDown=0,this.isOffscreen&&this.worker&&this.worker.postMessage({type:"mouseDown",down:!1}),this.touchLeaveTimer&&window.clearTimeout(this.touchLeaveTimer),this.touchLeaveTimer=window.setTimeout(()=>{this.touchLeaveTimer=0,this.isDestroyed||this.handlePointerLeave()},550))};this.handleContextLost=e=>{e.preventDefault(),this.isContextLost=!0,this.resetFrameTracking(),this.gl&&$.disposeContext(this.gl),this.programEntry=null,this.feedbackProgramEntry=null,this.pingPong=null,this.mainTextures.clear(),this.vao=null,this.vbo=null,this.wakeCallback?.()};this.handleContextRestored=()=>{if(!(this.isDestroyed||!this.gl))try{this.isContextLost=!1,this.initMainThreadPipeline(this.gl),this.reuploadLoadedTextures(),this.drawMainThreadFrame(),this.wakeCallback?.()}catch(e){console.error("[FluxFX] Failed to restore WebGL2 context:",e)}};this.handleProtectionTierChange=e=>{this.isDestroyed||this.protectionTier===e||(this.protectionTier=e,this.applyProtectionState(),this.isDestroyed||this.pushUniformBatch({uQuality:this.computeEffectiveQuality()}))};this.handleDprChange=()=>{this.isDestroyed||(this.syncDprBounds(),this.watchDevicePixelRatio())};this.handleReducedMotionChange=e=>{this.applyReducedMotionState(this.respectReducedMotion&&e.matches)};this.handlePointerEnter=e=>{if(this.isPaused||this.isHiddenByViewport||this.isReducedMotion)return;if(this.isShadowedByChildInteractive(e.target)){this.isPointerInside&&this.handlePointerLeave();return}let t=this.getLocalPointerCoords(e);if(!t)return;let[o,r]=t;this.isPointerInside=!0,this.targetMouseActive=1,this.boostInteraction(ze),this.protectionTier>=3&&this.applyProtectionState(),this.lastActiveAt=je(),this.isBudgetSuspended&&!this.isPaused&&this.restoreContextFromBudget(),this.isOffscreen&&this.worker?this.worker.postMessage({type:"mouseEnter",x:o,y:r}):(this.mouse[0]=o,this.mouse[1]=r,this.targetMouse[0]=o,this.targetMouse[1]=r,this.mouseVel[0]=0,this.mouseVel[1]=0)};this.handlePointerMove=e=>{if(this.isPaused||this.isHiddenByViewport||this.isReducedMotion)return;if(this.isShadowedByChildInteractive(e.target)){this.isPointerInside&&this.handlePointerLeave();return}let t=this.getLocalPointerCoords(e);if(!t){this.isPointerInside&&this.handlePointerLeave();return}let[o,r]=t;if(!this.isPointerInside){this.handlePointerEnter(e),this.inspectSurfaceFromTarget(e.target,!0);return}this.inspectSurfaceFromTarget(e.target),this.boostInteraction(ze),this.isOffscreen&&this.worker?this.worker.postMessage({type:"mouse",x:o,y:r}):(this.targetMouse[0]=o,this.targetMouse[1]=r)};this.handlePointerLeave=()=>{!this.isPointerInside&&this.targetMouseActive===0||(this.isPointerInside=!1,this.targetMouseActive=0,this.lastSurfaceEl=null,this.lastSurfaceKey="",this.isSurfaceAdapted&&(this.isSurfaceAdapted=!1,this.startPaletteTween(this.basePaletteRgb,240)),this.mouseDown=0,this.mouseVel[0]=0,this.mouseVel[1]=0,this.isOffscreen&&this.worker&&this.worker.postMessage({type:"mouseLeave"}),this.protectionTier>=3&&this.applyProtectionState())};this.handlePointerDown=e=>{if(!(this.isPaused||this.isHiddenByViewport||this.isReducedMotion)){if(this.isShadowedByChildInteractive(e.target)){this.isPointerInside&&this.handlePointerLeave();return}this.isPointerInside||this.handlePointerEnter(e),this.mouseDown=1,this.boostInteraction(ze),this.protectionTier>=3&&this.applyProtectionState(),this.isOffscreen&&this.worker&&this.worker.postMessage({type:"mouseDown",down:!0})}};this.handlePointerUp=()=>{this.mouseDown!==0&&(this.mouseDown=0,this.isOffscreen&&this.worker&&this.worker.postMessage({type:"mouseDown",down:!1}),this.protectionTier>=3&&this.applyProtectionState())};this.handleScroll=()=>{if(!this.trackScroll||this.isDestroyed)return;let e=this.computeScrollProgress();this.boostInteraction(1200),this.isOffscreen&&this.worker?this.worker.postMessage({type:"scroll",progress:e}):(this.targetScroll=e,this.isReducedMotion&&!this.isPaused&&!this.isHiddenByViewport&&(this.scroll=e,this.scrollVel=0,this.drawMainThreadFrame()))};this.handleDocVisibility=()=>{!this.isOffscreen||!this.worker||(document.hidden?(this.resetFrameTracking(),this.worker.postMessage({type:"pause"})):!this.isPaused&&!this.isHiddenByViewport&&this.worker.postMessage({type:"resume"}))};this.container=e,this.options={...t},this.interactive=t.interactive??!0,this.respectReducedMotion=t.respectReducedMotion??!0,this.trackScroll=t.trackScroll??!1,this.feedbackScale=t.feedbackScale??.5,this.feedbackFloat=t.feedbackFloat??!0,re.instances.add(this);let o=t.quality??"medium",r=We[o]??We.medium;this.baseFeedbackMaxDim=t.feedbackMaxDim??r.fboMaxDim;let s=this.resolveTierConfig();this.ambientFps=s.ambientFps,this.activeFps=s.activeFps,this.feedbackMaxDim=s.feedbackMaxDim,this.isSurvivalSuspended=s.suspended,typeof window<"u"&&typeof window.matchMedia=="function"&&(this.reducedMotionQuery=window.matchMedia("(prefers-reduced-motion: reduce)"),this.isReducedMotion=this.respectReducedMotion&&this.reducedMotionQuery.matches),this.isBodyMount=typeof document<"u"&&this.container===document.body,window.getComputedStyle(this.container).position==="static"&&(this.container.style.position="relative"),this.container.style.isolation="isolate",this.isBodyMount&&(this.origBodyMinHeight=this.container.style.minHeight,this.container.style.minHeight||(this.container.style.minHeight="100dvh")),this.canvas=document.createElement("canvas"),this.canvas.setAttribute("data-fluxfx-canvas","true"),this.canvas.style.position=this.isBodyMount?"fixed":"absolute",this.canvas.style.inset="0",this.canvas.style.width="100%",this.canvas.style.height="100%",this.canvas.style.zIndex="-1",this.canvas.style.pointerEvents="none",this.canvas.style.display="block",this.container.prepend(this.canvas),this.layerMode=t.layer??"background",this.adaptToSurface=t.adaptToSurface??!1,this.applyCanvasLayerStyle(),this.themeMode=t.theme??"auto",this.resolvedDarkTheme=this.detectDarkTheme(this.themeMode),this.currentTheme=this.resolvedDarkTheme?1:0;let l=this.container.getBoundingClientRect();if(this.width=Math.max(1,Math.floor(l.width)),this.height=Math.max(1,Math.floor(l.height)),this.trackScroll){let b=this.computeScrollProgress();this.scroll=b,this.targetScroll=b}let{minDpr:a,maxDpr:d}=this.resolveDprBounds(),u=t.dynamicResolution??!0,f=t.offscreen??!0;this.seedUniformsFromOptions(t,!0);let h=typeof window<"u"&&window.innerHeight||0,p=typeof window<"u"&&window.innerWidth||0,v=(t.pauseWhenHidden??!0)&&h>0&&(l.bottom<-50||l.top>h+50||l.right<-50||l.left>p+50);v&&(this.isHiddenByViewport=!0),re.ensureContextBudget(this,v)?f&&ft()?this.initOffscreenMode(t,a,d,u):this.initMainThreadMode(t,a,d,u):(this.isBudgetSuspended=!0,this.applyBudgetFallbackStyle()),this.bindObservers(t.pauseWhenHidden??!0),this.unsubscribeGuard=be.onTierChange(this.handleProtectionTierChange),this.syncTexturesFromOptions(t.textures)}static acquireRecycledMainContext(){for(;this.recycledMainContexts.length>0;){let e=this.recycledMainContexts.pop();if(!e.gl.isContextLost())return e}return null}static recycleMainContext(e,t){let o=Math.max(this._maxContexts,kt());return this.recycledMainContexts.length>=o?!1:(this.recycledMainContexts.push({canvas:e,gl:t}),!0)}static get activeContexts(){return this._activeContexts}static get maxActiveContexts(){return this._maxContexts}static get suspendedContexts(){let e=0;return this.instances.forEach(t=>{!t.isDestroyed&&t.isBudgetSuspended&&e++}),e}static setMaxActiveContexts(e){let t=Math.max(1,Math.floor(e));t!==this._maxContexts&&(this._maxContexts=t,this.enforceContextBudget(),this.reclaimBudgetForWaiting())}static pickEvictionVictim(e,t){let o=null,r=null;return this.instances.forEach(s=>{s===e||s.isDestroyed||s.isBudgetSuspended||!s.countedContext||(s.isHiddenByViewport||s.isPaused?(!o||s.lastActiveAt<o.lastActiveAt)&&(o=s):t&&!s.isPointerInside&&s.mouseDown===0&&(!r||s.lastActiveAt<r.lastActiveAt)&&(r=s))}),o??r}static ensureContextBudget(e,t){if(this._activeContexts<this._maxContexts)return!0;if(t)return!1;let o=this.pickEvictionVictim(e,!0);return o?(o.suspendContextForBudget(),this._activeContexts<this._maxContexts):!1}static enforceContextBudget(){for(;this._activeContexts>this._maxContexts;){let e=this.pickEvictionVictim(null,!0);if(!e)break;e.suspendContextForBudget()}}static reclaimBudgetForWaiting(){for(;this._activeContexts<this._maxContexts;){let e=null;if(this.instances.forEach(t=>{t.isDestroyed||!t.isBudgetSuspended||t.isPaused||t.isHiddenByViewport||(!e||t.lastActiveAt>e.lastActiveAt)&&(e=t)}),!e||!e.restoreContextFromBudget())break}}static getRenderStats(){let e=0,t=0,o=0;return this.instances.forEach(r=>{r.isDestroyed||r.isPaused||r.isHiddenByViewport||r.isReducedMotion||r.isContextLost||r.isSurvivalSuspended||r.reportedFps>0&&(e++,r.reportedFps>t&&(t=r.reportedFps,o=r.reportedFrameTimeMs))}),{activeRendering:e,fps:t,frameTimeMs:o}}boostInteraction(e=ze){let t=performance.now()+e;t>this.boostUntil&&(this.boostUntil=t)}resetFrameTracking(){this.lastRenderNow=0,this.lastDrawNow=0,this.lastTargetFps=0,this.prevFrameDrew=!1,this.avgDrawDeltaMs=0,this.reportedFps=0,this.reportedFrameTimeMs=0}resolveTierConfig(){let e=this.baseFeedbackMaxDim;return this.protectionTier===1?{ambientFps:ht,activeFps:mt,feedbackMaxDim:Math.max(256,Math.round(e*.75)),suspended:!1}:this.protectionTier===2?{ambientFps:20,activeFps:30,feedbackMaxDim:Math.max(256,Math.round(e*.55)),suspended:!1}:this.protectionTier>=3?{ambientFps:15,activeFps:30,feedbackMaxDim:Math.max(256,Math.round(e*.5)),suspended:!this.isPointerInside&&this.mouseDown===0}:{ambientFps:ht,activeFps:mt,feedbackMaxDim:e,suspended:!1}}resolveDprBounds(){let e=this.options.quality??"medium",t=We[e]??We.medium,o=typeof window<"u"&&window.devicePixelRatio||1,r=o>=1.5,s=this.options.maxDpr??Math.min(o,t.max),n=r?t.retinaMin:t.min,l=this.options.minDpr??Math.min(n,s);if(this.protectionTier===1){let a=Math.max(.65,Number((s*.75).toFixed(2)));return{minDpr:Math.min(l,a),maxDpr:a}}if(this.protectionTier>=2){let a=Math.max(.55,Math.min(l,Number((s*.6).toFixed(2))));return{minDpr:a,maxDpr:a}}return{minDpr:l,maxDpr:s}}computeScrollProgress(){if(typeof window>"u")return 0;let e=this.container.getBoundingClientRect(),t=window.innerHeight||1,o=t+e.height;return o<=0?0:Math.min(1,Math.max(0,(t-e.top)/o))}markContextActive(){this.countedContext||(this.countedContext=!0,re._activeContexts++,re._activeContexts>lr&&console.warn(`[FluxFX] ${re._activeContexts} active WebGL contexts detected. Browsers typically cap contexts around 8\u201316; consider limiting simultaneous WebGL backgrounds.`))}markContextReleased(){this.countedContext&&(this.countedContext=!1,re._activeContexts=Math.max(0,re._activeContexts-1))}uniformVec3Css(e,t,o=1){let r=this.customUniforms.get(e),s=t[0],n=t[1],l=t[2];return r&&typeof r!="number"&&r.length>=3&&(s=Math.round(Math.min(1,Math.max(0,r[0]))*255),n=Math.round(Math.min(1,Math.max(0,r[1]))*255),l=Math.round(Math.min(1,Math.max(0,r[2]??0))*255)),o<1?`rgba(${s}, ${n}, ${l}, ${o})`:`rgb(${s}, ${n}, ${l})`}applyBudgetFallbackStyle(){if(this.isDestroyed)return;let e=this.customUniforms.get("uTransparentBg"),t=typeof e=="number"&&e>.5,o=this.customUniforms.get("uBgColor"),r=o&&typeof o!="number"&&o.length>=3&&o[0]+o[1]+(o[2]??0)>.003,s=this.uniformVec3Css("uColor1",[99,102,241],t?.38:.45),n=this.uniformVec3Css("uColor2",[6,182,212],t?.32:.38),l=this.uniformVec3Css("uColor3",[244,63,94],t?.22:.28),a=t?"transparent":r?this.uniformVec3Css("uBgColor",[6,8,16],1):"#070a14";this.canvas.style.background=`radial-gradient(circle at 22% 28%, ${s}, transparent 60%), radial-gradient(circle at 78% 72%, ${n}, transparent 62%), radial-gradient(circle at 55% 45%, ${l}, transparent 68%), ${a}`}syncDocVisibilityListener(){typeof document>"u"||(this.isOffscreen&&!this.hasDocVisibilityListener?(document.addEventListener("visibilitychange",this.handleDocVisibility),this.hasDocVisibilityListener=!0):!this.isOffscreen&&this.hasDocVisibilityListener&&(document.removeEventListener("visibilitychange",this.handleDocVisibility),this.hasDocVisibilityListener=!1))}releaseMainThreadContext(e){if(!this.gl){e||this.canvas.remove();return}let t=this.gl;if(t.isContextLost())this.pingPong=null,this.mainTextures.clear(),$.disposeContext(t),e||this.canvas.remove();else{this.destroyPingPongMain(),this.destroyMainTextures(),this.vbo&&t.deleteBuffer(this.vbo),this.vao&&t.deleteVertexArray(this.vao),$.disposeContext(t),t.bindFramebuffer(t.FRAMEBUFFER,null),t.bindVertexArray(null),t.bindBuffer(t.ARRAY_BUFFER,null),t.useProgram(null),t.viewport(0,0,1,1),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),this.canvas.width=1,this.canvas.height=1;let r=this.canvas;if(e){let s=this.canvas.cloneNode(!1);this.canvas.replaceWith(s),this.canvas=s}else this.canvas.remove();!re.recycleMainContext(r,t)&&!Ft()&&t.getExtension("WEBGL_lose_context")?.loseContext()}this.gl=null}suspendContextForBudget(){this.isDestroyed||this.isBudgetSuspended||(this.isBudgetSuspended=!0,this.resetFrameTracking(),this.canvas.removeEventListener("webglcontextlost",this.handleContextLost,!1),this.canvas.removeEventListener("webglcontextrestored",this.handleContextRestored,!1),this.isOffscreen&&this.worker&&(this.worker.postMessage({type:"destroy"}),this.worker=null),this.isOffscreen=!1,this.syncDocVisibilityListener(),this.releaseMainThreadContext(!0),this.programEntry=null,this.feedbackProgramEntry=null,this.vao=null,this.vbo=null,this.dynamicRes=null,this.isContextLost=!1,this.markContextReleased(),this.applyBudgetFallbackStyle(),this.wakeCallback?.())}restoreContextFromBudget(){if(this.isDestroyed||!this.isBudgetSuspended||!re.ensureContextBudget(this,!1))return!1;let e=this.canvas.cloneNode(!1);e.style.background="",this.canvas.replaceWith(e),this.canvas=e;let t=this.container.getBoundingClientRect();this.width=Math.max(1,Math.floor(t.width)),this.height=Math.max(1,Math.floor(t.height));let{minDpr:o,maxDpr:r}=this.resolveDprBounds(),s=this.options.dynamicResolution??!0,n=this.options.offscreen??!0;return this.isBudgetSuspended=!1,this.isContextLost=!1,this.lastActiveAt=je(),n&&ft()?this.initOffscreenMode(this.options,o,r,s):this.initMainThreadMode(this.options,o,r,s),this.reuploadLoadedTextures(),this.syncDocVisibilityListener(),this.wakeCallback?.(),this.countedContext}computeEffectiveQuality(){let e=this.options.quality??"medium",t=e==="high"?1:e==="low"?0:.5;return this.protectionTier>=2?t=0:this.protectionTier===1&&(t=Math.min(t,.5)),t}shouldPreserveBg(){return typeof this.options.preserveBg=="boolean"?this.options.preserveBg:this.layerMode==="overlay"}applyCanvasLayerStyle(){if(this.layerMode==="overlay"){this.canvas.style.zIndex="10";let e=typeof this.options.overlayOpacity=="number"?Math.max(.05,Math.min(1,this.options.overlayOpacity)):.78;this.canvas.style.opacity=String(e)}else this.canvas.style.zIndex="-1",this.canvas.style.opacity="1"}startPaletteTween(e,t=220){if(e.length===0)return;this.themeTweenRaf&&(cancelAnimationFrame(this.themeTweenRaf),this.themeTweenRaf=0);let o=this.toTriplet(this.activePaletteRgb.length>0?this.activePaletteRgb:this.basePaletteRgb),r=this.toTriplet(e);if(this.isReducedMotion||typeof requestAnimationFrame!="function"){this.activePaletteRgb=r,this.pushUniformBatch({uColor1:r[0],uColor2:r[1],uColor3:r[2]});return}let s=performance.now();this.boostInteraction(420);let n=l=>{if(this.isDestroyed){this.themeTweenRaf=0;return}let a=Math.min(1,(l-s)/t),d=a<.5?2*a*a:1-Math.pow(-2*a+2,2)/2,u=(v,b)=>[v[0]+(b[0]-v[0])*d,v[1]+(b[1]-v[1])*d,v[2]+(b[2]-v[2])*d],f=u(o[0],r[0]),h=u(o[1],r[1]),p=u(o[2],r[2]);this.activePaletteRgb=[f,h,p],this.pushUniformBatch({uColor1:f,uColor2:h,uColor3:p}),a<1?this.themeTweenRaf=requestAnimationFrame(n):this.themeTweenRaf=0};this.themeTweenRaf=requestAnimationFrame(n)}inspectSurfaceFromTarget(e,t=!1){if(!this.adaptToSurface||this.isDestroyed)return;let o=e instanceof HTMLElement?e:null,r=performance.now();if(!t&&o===this.lastSurfaceEl&&r-this.lastSurfaceCheckAt<180)return;this.lastSurfaceEl=o,this.lastSurfaceCheckAt=r;let s=St(o,this.container);if(!s){this.isSurfaceAdapted&&(this.isSurfaceAdapted=!1,this.lastSurfaceKey="",this.startPaletteTween(this.basePaletteRgb,220));return}let n=`${Math.round(s[0]*255)},${Math.round(s[1]*255)},${Math.round(s[2]*255)}`;if(!t&&n===this.lastSurfaceKey)return;this.lastSurfaceKey=n;let l=this.rawBasePaletteRgb.length>0?this.rawBasePaletteRgb:this.basePaletteRgb;if(l.length===0)return;let a=Et(l,[s[0],s[1],s[2]]);this.isSurfaceAdapted=!0,this.startPaletteTween(a,220)}parseColorList(e){if(!e)return[];let t=Array.isArray(e)?e:String(e).split(",").map(s=>s.trim()).filter(Boolean);if(t.length===0)return[];let o=ee(t[0],"#6366f1"),r=[];for(let s=0;s<t.length;s++){let n=ee(t[s],o),l=Y.hexToVec3Into(n,Y.scratchVec3);r.push([l[0],l[1],l[2]])}return r}parseScrollStops(e){if(!Array.isArray(e)||e.length===0)return[];let t=[];for(let o=0;o<e.length;o++){let r=e[o],s=Array.isArray(r)?r[0]:r;if(typeof s=="string"&&s.trim()){let n=ee(s,"#6366f1"),l=Y.hexToVec3Into(n,Y.scratchVec3);t.push([l[0],l[1],l[2]])}}return t}detectDarkTheme(e){return e==="dark"?!0:e==="light"?!1:wt(this.container)}resolveTargetPalette(e){let t=e?this.parseColorList(this.options.darkColors):this.parseColorList(this.options.lightColors);if(t.length>0)return t;let o=this.parseColorList(this.options.colors);return o.length>0?tt(o,e):this.basePaletteRgb}toTriplet(e){let t=e[0]??[.39,.4,.95],o=e[1]??t,r=e[2]??o;return[[t[0],t[1],t[2]],[o[0],o[1],o[2]],[r[0],r[1],r[2]]]}pushUniformBatch(e){if(!this.isDestroyed){for(let[t,o]of Object.entries(e))this.customUniforms.set(t,o);if(this.isBudgetSuspended){this.applyBudgetFallbackStyle();return}this.isOffscreen&&this.worker?this.worker.postMessage({type:"uniformsBatch",uniforms:e}):this.isReducedMotion&&!this.isPaused&&!this.isHiddenByViewport&&this.drawMainThreadFrame()}}startThemeTransition(e){this.themeTweenRaf&&(cancelAnimationFrame(this.themeTweenRaf),this.themeTweenRaf=0);let t=e?1:0,o=this.resolveTargetPalette(e);o.length>0&&(this.basePaletteRgb=o);let r=this.currentTheme,s=this.toTriplet(this.activePaletteRgb.length>0?this.activePaletteRgb:this.basePaletteRgb),n=this.toTriplet(this.basePaletteRgb);if(this.isReducedMotion||typeof requestAnimationFrame!="function"){this.currentTheme=t,this.activePaletteRgb=n,this.pushUniformBatch({uTheme:t,uColor1:n[0],uColor2:n[1],uColor3:n[2]});return}let l=performance.now(),a=280;this.boostInteraction(500);let d=u=>{if(this.isDestroyed){this.themeTweenRaf=0;return}let f=Math.min(1,(u-l)/a),h=f<.5?2*f*f:1-Math.pow(-2*f+2,2)/2;this.currentTheme=r+(t-r)*h;let p=(k,E)=>[k[0]+(E[0]-k[0])*h,k[1]+(E[1]-k[1])*h,k[2]+(E[2]-k[2])*h],v=p(s[0],n[0]),b=p(s[1],n[1]),w=p(s[2],n[2]);this.activePaletteRgb=[v,b,w],this.pushUniformBatch({uTheme:this.currentTheme,uColor1:v,uColor2:b,uColor3:w}),f<1?this.themeTweenRaf=requestAnimationFrame(d):(this.themeTweenRaf=0,this.scrollStopsRgb.length>=2&&(this.lastScrollColorT=-1,this.updateScrollColorShift(this.computeScrollProgress())))};this.themeTweenRaf=requestAnimationFrame(d)}bindThemeWatchers(){if(this.unbindThemeWatchers(),!(typeof window>"u"||typeof document>"u")&&(typeof window.matchMedia=="function"&&(this.colorSchemeQuery=window.matchMedia("(prefers-color-scheme: dark)"),typeof this.colorSchemeQuery.addEventListener=="function"&&this.colorSchemeQuery.addEventListener("change",this.handleThemeChange)),typeof MutationObserver<"u")){this.themeMutationObserver=new MutationObserver(this.handleThemeChange);let e=["class","data-theme","data-mode","data-bs-theme","style"];this.themeMutationObserver.observe(document.documentElement,{attributes:!0,attributeFilter:e}),document.body&&this.themeMutationObserver.observe(document.body,{attributes:!0,attributeFilter:e}),this.container!==document.body&&this.container!==document.documentElement&&this.themeMutationObserver.observe(this.container,{attributes:!0,attributeFilter:e})}}unbindThemeWatchers(){this.themeTweenRaf&&(cancelAnimationFrame(this.themeTweenRaf),this.themeTweenRaf=0),this.colorSchemeQuery&&typeof this.colorSchemeQuery.removeEventListener=="function"&&this.colorSchemeQuery.removeEventListener("change",this.handleThemeChange),this.colorSchemeQuery=null,this.themeMutationObserver?.disconnect(),this.themeMutationObserver=null}updateScrollColorShift(e){if(this.scrollStopsRgb.length<2)return;let t=Math.min(1,Math.max(0,e));if(Math.abs(t-this.lastScrollColorT)<.002)return;this.lastScrollColorT=t;let o=tt(this.scrollStopsRgb,this.resolvedDarkTheme),r=o.length-1,s=t*r,n=Math.min(r-1,Math.floor(s)),l=s-n,a=o[n],d=o[n+1],u=o[Math.min(o.length-1,n+2)]??a,f=[a[0]+(d[0]-a[0])*l,a[1]+(d[1]-a[1])*l,a[2]+(d[2]-a[2])*l],h=[d[0]+(u[0]-d[0])*l,d[1]+(u[1]-d[1])*l,d[2]+(u[2]-d[2])*l],p=this.basePaletteRgb[2]??u;this.activePaletteRgb=[f,h,p],this.pushUniformBatch({uColor1:f,uColor2:h,uColor3:p})}syncScrollColorListener(){if(typeof window>"u")return;let e=this.scrollStopsRgb.length>=2;e&&!this.hasScrollColorListener?(window.addEventListener("scroll",this.handleScrollColorEvent,{passive:!0}),this.hasScrollColorListener=!0,this.lastScrollColorT=-1,this.updateScrollColorShift(this.computeScrollProgress())):!e&&this.hasScrollColorListener&&(window.removeEventListener("scroll",this.handleScrollColorEvent),this.hasScrollColorListener=!1,this.scrollColorRaf&&(cancelAnimationFrame(this.scrollColorRaf),this.scrollColorRaf=0))}getLocalTouchCoords(e){let t=this.container.getBoundingClientRect();if(t.width<=0||t.height<=0)return null;let o=(e.clientX-t.left)/t.width,r=1-(e.clientY-t.top)/t.height;return o<0||o>1||r<0||r>1?null:[o,r]}syncTouchListener(){typeof window>"u"||(this.interactive&&!this.hasTouchListener?(this.container.addEventListener("touchstart",this.handleTouchStart,{passive:!0}),this.container.addEventListener("touchmove",this.handleTouchMove,{passive:!0}),this.container.addEventListener("touchend",this.handleTouchEnd,{passive:!0}),this.container.addEventListener("touchcancel",this.handleTouchEnd,{passive:!0}),this.hasTouchListener=!0):!this.interactive&&this.hasTouchListener&&(this.container.removeEventListener("touchstart",this.handleTouchStart),this.container.removeEventListener("touchmove",this.handleTouchMove),this.container.removeEventListener("touchend",this.handleTouchEnd),this.container.removeEventListener("touchcancel",this.handleTouchEnd),this.hasTouchListener=!1))}seedUniformsFromOptions(e,t=!1){let o={};if(typeof e.speed=="number"?(this.targetSpeed=e.speed,t&&(this.currentSpeed=e.speed),this.customUniforms.set("uSpeed",e.speed),o.uSpeed=e.speed):this.customUniforms.has("uSpeed")||(this.targetSpeed=1,this.currentSpeed=1,this.customUniforms.set("uSpeed",1),o.uSpeed=1),t||e.quality!==void 0){let l=this.computeEffectiveQuality();this.customUniforms.set("uQuality",l),o.uQuality=l}e.scrollColors!==void 0&&(this.scrollStopsRgb=this.parseScrollStops(e.scrollColors),this.lastScrollColorT=-1);let r=this.resolvedDarkTheme;e.theme!==void 0&&(this.themeMode=e.theme);let s=this.detectDarkTheme(this.themeMode);if(this.resolvedDarkTheme=s,t&&(this.currentTheme=s?1:0,this.customUniforms.set("uTheme",this.currentTheme),o.uTheme=this.currentTheme),t||e.colors!==void 0||e.lightColors!==void 0||e.darkColors!==void 0||e.theme!==void 0||e.scrollColors!==void 0){let l=this.parseColorList(this.options.colors);l.length>0&&(this.rawBasePaletteRgb=l);let a=this.resolveTargetPalette(s);if(a.length>0)if(this.basePaletteRgb=a,this.rawBasePaletteRgb.length===0&&(this.rawBasePaletteRgb=a),!t&&s!==r)this.startThemeTransition(s);else{let[d,u,f]=this.toTriplet(a);this.activePaletteRgb=[d,u,f],this.customUniforms.set("uColor1",d),this.customUniforms.set("uColor2",u),this.customUniforms.set("uColor3",f),o.uColor1=d,o.uColor2=u,o.uColor3=f,t||(this.currentTheme=s?1:0,this.customUniforms.set("uTheme",this.currentTheme),o.uTheme=this.currentTheme)}}if(e.uniforms)for(let[l,a]of Object.entries(e.uniforms))this.customUniforms.set(l,a),o[l]=typeof a=="number"?a:Array.from(a);return this.shouldPreserveBg()&&(this.customUniforms.set("uTransparentBg",1),o.uTransparentBg=1),o}fallbackToMainThread(e,t,o,r){if(this.isDestroyed)return;this.worker&&(this.worker.terminate(),this.worker=null),this.isOffscreen=!1,this.resetFrameTracking(),this.markContextReleased();let s=this.canvas.cloneNode(!1);this.canvas.replaceWith(s),this.canvas=s,this.initMainThreadMode(e,t,o,r)}initOffscreenMode(e,t,o,r){try{let s=Rt(),n=this.canvas.transferControlToOffscreen();this.worker=s,this.isOffscreen=!0,this.markContextActive(),s.onmessage=a=>{if(a.data?.type==="error")this.fallbackToMainThread(e,t,o,r);else if(a.data?.type==="stats"){this.reportedFps=typeof a.data.fps=="number"?a.data.fps:0,this.reportedFrameTimeMs=typeof a.data.frameTimeMs=="number"?a.data.frameTimeMs:0;let d=typeof a.data.targetFps=="number"?a.data.targetFps:0;this.reportedFrameTimeMs>0&&d>0&&be.recordGpuFrame(this.reportedFrameTimeMs,d,performance.now())}else a.data?.type==="needTextures"&&this.reuploadLoadedTextures()},s.onerror=()=>{this.fallbackToMainThread(e,t,o,r)};let l={};this.customUniforms.forEach((a,d)=>{l[d]=typeof a=="number"?a:Array.from(a)}),s.postMessage({type:"init",canvas:n,width:this.width,height:this.height,minDpr:t,maxDpr:o,dynamicRes:r,reducedMotion:this.isReducedMotion,vertexShader:e.vertexShader??Lt,fragmentShader:e.fragmentShader,feedbackShader:e.feedbackShader??null,feedbackScale:this.feedbackScale,feedbackMaxDim:this.feedbackMaxDim,feedbackFloat:this.feedbackFloat,initialScroll:this.scroll,ambientFps:this.ambientFps,activeFps:this.activeFps,survivalPaused:this.isSurvivalSuspended,uniforms:l},[n])}catch{this.isOffscreen=!1,this.markContextReleased(),this.initMainThreadMode(e,t,o,r)}}computeFboDimsMain(e,t){let o=Math.max(1,Math.floor(e*this.feedbackScale)),r=Math.max(1,Math.floor(t*this.feedbackScale)),s=Math.max(o,r);if(s>this.feedbackMaxDim){let n=this.feedbackMaxDim/s;o=Math.max(1,Math.floor(o*n)),r=Math.max(1,Math.floor(r*n))}return[o,r]}destroyPingPongMain(){if(!this.pingPong||!this.gl){this.pingPong=null;return}for(let e=0;e<2;e++)this.gl.deleteFramebuffer(this.pingPong[e].fbo),this.gl.deleteTexture(this.pingPong[e].tex);this.pingPong=null}createPingPongMain(e){if(this.destroyPingPongMain(),!this.options.feedbackShader||this.isContextLost)return;let[t,o]=this.computeFboDimsMain(this.canvas.width,this.canvas.height);this.fboW=t,this.fboH=o;let r=e.RGBA8,s=e.UNSIGNED_BYTE;this.feedbackFloat&&(e.getExtension("EXT_color_buffer_float")||e.getExtension("EXT_color_buffer_half_float"))&&(r=e.RGBA16F,s=e.HALF_FLOAT);let l=(d,u)=>{let f=[];for(let h=0;h<2;h++){let p=e.createTexture(),v=e.createFramebuffer();if(!p||!v)return p&&e.deleteTexture(p),v&&e.deleteFramebuffer(v),f.forEach(b=>{e.deleteFramebuffer(b.fbo),e.deleteTexture(b.tex)}),null;if(e.bindTexture(e.TEXTURE_2D,p),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texImage2D(e.TEXTURE_2D,0,d,this.fboW,this.fboH,0,e.RGBA,u,null),e.bindFramebuffer(e.FRAMEBUFFER,v),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,p,0),e.checkFramebufferStatus(e.FRAMEBUFFER)!==e.FRAMEBUFFER_COMPLETE)return e.deleteFramebuffer(v),e.deleteTexture(p),f.forEach(b=>{e.deleteFramebuffer(b.fbo),e.deleteTexture(b.tex)}),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindTexture(e.TEXTURE_2D,null),null;e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),f.push({fbo:v,tex:p})}return e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindTexture(e.TEXTURE_2D,null),[f[0],f[1]]},a=l(r,s);!a&&r!==e.RGBA8&&(r=e.RGBA8,s=e.UNSIGNED_BYTE,a=l(r,s)),this.fboFormat=r,this.fboType=s,this.pingPong=a,this.readIdx=0,this.writeIdx=1}resizePingPongMain(){if(!this.pingPong||!this.gl||this.isContextLost)return;let[e,t]=this.computeFboDimsMain(this.canvas.width,this.canvas.height);if(e===this.fboW&&t===this.fboH)return;let o=this.gl,r=this.fboW,s=this.fboH,n=this.pingPong[this.readIdx],l=[];for(let a=0;a<2;a++){let d=o.createTexture(),u=o.createFramebuffer();o.bindTexture(o.TEXTURE_2D,d),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),o.texImage2D(o.TEXTURE_2D,0,this.fboFormat,e,t,0,o.RGBA,this.fboType,null),o.bindFramebuffer(o.FRAMEBUFFER,u),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,d,0),l.push({fbo:u,tex:d})}o.bindFramebuffer(o.READ_FRAMEBUFFER,n.fbo),o.bindFramebuffer(o.DRAW_FRAMEBUFFER,l[0].fbo),o.blitFramebuffer(0,0,r,s,0,0,e,t,o.COLOR_BUFFER_BIT,o.LINEAR),o.bindFramebuffer(o.READ_FRAMEBUFFER,null),o.bindFramebuffer(o.DRAW_FRAMEBUFFER,null),o.bindTexture(o.TEXTURE_2D,null);for(let a=0;a<2;a++)o.deleteFramebuffer(this.pingPong[a].fbo),o.deleteTexture(this.pingPong[a].tex);this.pingPong=[l[0],l[1]],this.fboW=e,this.fboH=t,this.readIdx=0,this.writeIdx=1}initMainThreadPipeline(e){let t=this.options.vertexShader??Ye;this.programEntry=$.getOrCreateProgram(e,this.options.fragmentShader,t),this.options.feedbackShader?this.feedbackProgramEntry=$.getOrCreateProgram(e,this.options.feedbackShader,t):this.feedbackProgramEntry=null,this.vao=e.createVertexArray(),e.bindVertexArray(this.vao),this.vbo=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.vbo),e.bufferData(e.ARRAY_BUFFER,ar,e.STATIC_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),e.bindVertexArray(null),this.needsResize=!1,this.applyCanvasSize(),this.options.feedbackShader&&this.createPingPongMain(e)}initMainThreadMode(e,t,o,r){let s=null,n=re.acquireRecycledMainContext();if(n?(n.canvas.style.background="",this.canvas.replaceWith(n.canvas),this.canvas=n.canvas,s=n.gl):s=this.canvas.getContext("webgl2",{alpha:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance",preserveDrawingBuffer:!1}),!s){console.warn("[FluxFX] WebGL2 is not supported on this device."),this.isBudgetSuspended=!0,this.applyBudgetFallbackStyle();return}this.gl=s,this.markContextActive(),this.canvas.addEventListener("webglcontextlost",this.handleContextLost,!1),this.canvas.addEventListener("webglcontextrestored",this.handleContextRestored,!1),this.dynamicRes=new et({minScale:r?t:o,maxScale:o}),this.initMainThreadPipeline(s),this.reuploadLoadedTextures(),this.drawMainThreadFrame()}applyCanvasSize(){if(!this.gl||!this.dynamicRes||this.isContextLost)return;let e=this.dynamicRes.scale,t=Math.max(1,Math.round(this.width*e)),o=Math.max(1,Math.round(this.height*e));(this.canvas.width!==t||this.canvas.height!==o)&&(this.canvas.width=t,this.canvas.height=o,this.gl.viewport(0,0,t,o)),this.pingPong&&this.resizePingPongMain()}bindCommonUniformsMain(e,t,o,r){let s=$.getUniformLocation(e,t,"uTime");s&&e.uniform1f(s,this.elapsedSec);let n=$.getUniformLocation(e,t,"uDelta");n&&e.uniform1f(n,this.lastDeltaSec);let l=$.getUniformLocation(e,t,"uResolution");l&&e.uniform2f(l,o,r);let a=$.getUniformLocation(e,t,"uCanvasResolution");a&&e.uniform2f(a,this.canvas.width,this.canvas.height);let d=$.getUniformLocation(e,t,"uDpr");d&&this.dynamicRes&&e.uniform1f(d,this.dynamicRes.scale);let u=$.getUniformLocation(e,t,"uMouse");u&&e.uniform2f(u,this.mouse[0],this.mouse[1]);let f=$.getUniformLocation(e,t,"uMouseVel");f&&e.uniform2f(f,this.mouseVel[0],this.mouseVel[1]);let h=$.getUniformLocation(e,t,"uMouseDown");h&&e.uniform1f(h,this.mouseDown);let p=$.getUniformLocation(e,t,"uMouseActive");p&&e.uniform1f(p,this.mouseActive);let v=$.getUniformLocation(e,t,"uScroll");v&&e.uniform1f(v,this.scroll);let b=$.getUniformLocation(e,t,"uScrollVel");b&&e.uniform1f(b,this.scrollVel),this.customUniforms.forEach((w,k)=>{let E=$.getUniformLocation(e,t,k);E&&(k==="uSpeed"?e.uniform1f(E,this.currentSpeed):typeof w=="number"?e.uniform1f(E,w):w.length===2?e.uniform2f(E,w[0],w[1]):w.length===3?e.uniform3f(E,w[0],w[1],w[2]):w.length===4&&e.uniform4f(E,w[0],w[1],w[2],w[3]))})}drawMainThreadFrame(){if(!this.gl||!this.programEntry||this.isContextLost)return;let e=this.gl;if(e.bindVertexArray(this.vao),this.feedbackProgramEntry&&this.pingPong){e.bindFramebuffer(e.FRAMEBUFFER,this.pingPong[this.writeIdx].fbo),e.viewport(0,0,this.fboW,this.fboH),e.useProgram(this.feedbackProgramEntry.program),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.pingPong[this.readIdx].tex);let t=$.getUniformLocation(e,this.feedbackProgramEntry,"uPrevFrame");t&&e.uniform1i(t,0),this.bindMainTextures(e,this.feedbackProgramEntry),this.bindCommonUniformsMain(e,this.feedbackProgramEntry,this.fboW,this.fboH),e.drawArrays(e.TRIANGLES,0,3);let o=this.readIdx;this.readIdx=this.writeIdx,this.writeIdx=o,e.bindFramebuffer(e.FRAMEBUFFER,null),e.viewport(0,0,this.canvas.width,this.canvas.height)}if(e.useProgram(this.programEntry.program),this.pingPong){e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.pingPong[this.readIdx].tex);let t=$.getUniformLocation(e,this.programEntry,"uFeedback");t&&e.uniform1i(t,0);let o=$.getUniformLocation(e,this.programEntry,"uPrevFrame");o&&e.uniform1i(o,0)}this.bindMainTextures(e,this.programEntry),this.bindCommonUniformsMain(e,this.programEntry,this.canvas.width,this.canvas.height),e.drawArrays(e.TRIANGLES,0,3)}render(e,t){if(this.isOffscreen||this.isPaused||this.isHiddenByViewport||this.isReducedMotion||this.isContextLost||this.isSurvivalSuspended||this.isBudgetSuspended||this.isDestroyed||!this.gl||!this.programEntry)return;let o=performance.now(),r=this.lastRenderNow?Math.min(o-this.lastRenderNow,100):16.67;this.lastRenderNow=o,this.prevFrameDrew&&(this.dynamicRes&&this.dynamicRes.recordFrame(r,o)&&(this.needsResize=!0),this.prevFrameDrew=!1);let n=o<this.boostUntil||this.mouseDown>.5?this.activeFps:this.ambientFps,l=1e3/n-2;if(this.lastDrawNow>0&&o-this.lastDrawNow<l)return;let a=this.lastDrawNow?o-this.lastDrawNow:1e3/n,d=Math.min(a,100);this.lastDrawNow=o,n!==this.lastTargetFps?(this.lastTargetFps=n,this.avgDrawDeltaMs=0):a>0&&a<500&&(this.avgDrawDeltaMs=this.avgDrawDeltaMs===0?a:this.avgDrawDeltaMs*.85+a*.15),this.avgDrawDeltaMs>0&&(this.reportedFps=Math.round(1e3/this.avgDrawDeltaMs),this.reportedFrameTimeMs=Math.round(this.avgDrawDeltaMs*100)/100),a>0&&a<500&&be.recordGpuFrame(a,n,o);let u=Math.max(.001,Math.min(d*.001,.05));if(this.lastDeltaSec=u,this.currentSpeed+=(this.targetSpeed-this.currentSpeed)*rt(7.5,u),this.elapsedSec+=u*this.currentSpeed,this.needsResize&&(this.needsResize=!1,this.applyCanvasSize()),this.mouseActive+=(this.targetMouseActive-this.mouseActive)*rt(7,u),this.mouseActive<.001&&this.targetMouseActive===0&&(this.mouseActive=0),this.targetMouseActive>.5){let f=this.mouse[0],h=this.mouse[1],p=rt(13,u);this.mouse[0]+=(this.targetMouse[0]-this.mouse[0])*p,this.mouse[1]+=(this.targetMouse[1]-this.mouse[1])*p,this.mouseVel[0]=Math.max(-8,Math.min(8,(this.mouse[0]-f)/u)),this.mouseVel[1]=Math.max(-8,Math.min(8,(this.mouse[1]-h)/u))}else this.mouseVel[0]=0,this.mouseVel[1]=0;if(this.trackScroll){let f=this.scroll;this.scroll+=(this.targetScroll-this.scroll)*rt(9.5,u),this.scrollVel=Math.max(-6,Math.min(6,(this.scroll-f)/u))}this.drawMainThreadFrame(),this.prevFrameDrew=!0}applyProtectionState(){if(this.isDestroyed||this.isBudgetSuspended)return;let e=this.resolveTierConfig(),{minDpr:t,maxDpr:o}=this.resolveDprBounds(),s=this.options.dynamicResolution??!0?t:o,n=this.isSurvivalSuspended,l=this.feedbackMaxDim;this.ambientFps=e.ambientFps,this.activeFps=e.activeFps,this.feedbackMaxDim=e.feedbackMaxDim,this.isSurvivalSuspended=e.suspended,this.isSurvivalSuspended&&!n&&this.resetFrameTracking(),this.isOffscreen&&this.worker?this.worker.postMessage({type:"protection",minDpr:s,maxDpr:o,feedbackMaxDim:this.feedbackMaxDim,ambientFps:this.ambientFps,activeFps:this.activeFps,suspended:this.isSurvivalSuspended}):((this.dynamicRes?.setBounds(s,o)??!1)||l!==this.feedbackMaxDim)&&(this.isReducedMotion&&!this.isPaused&&!this.isHiddenByViewport?(this.needsResize=!1,this.applyCanvasSize(),this.drawMainThreadFrame()):this.needsResize=!0),n!==this.isSurvivalSuspended&&this.wakeCallback?.()}syncDprBounds(){this.applyProtectionState()}watchDevicePixelRatio(){if(this.dprMediaQuery&&(this.dprMediaQuery.removeEventListener("change",this.handleDprChange),this.dprMediaQuery=null),typeof window>"u"||typeof window.matchMedia!="function")return;let e=window.devicePixelRatio||1;this.dprMediaQuery=window.matchMedia(`(resolution: ${e}dppx)`),this.dprMediaQuery.addEventListener("change",this.handleDprChange)}updateOptions(e){if(this.isDestroyed)return;let t=this.options.quality;this.options={...this.options,...e},e.layer!==void 0&&(this.layerMode=e.layer),(e.layer!==void 0||e.overlayOpacity!==void 0)&&this.applyCanvasLayerStyle(),typeof e.adaptToSurface=="boolean"&&(this.adaptToSurface=e.adaptToSurface,!this.adaptToSurface&&this.isSurfaceAdapted&&(this.isSurfaceAdapted=!1,this.lastSurfaceEl=null,this.lastSurfaceKey="",this.startPaletteTween(this.basePaletteRgb,200)));let o=this.seedUniformsFromOptions(e,!1);if(e.preserveBg!==void 0||e.layer!==void 0){let s=this.shouldPreserveBg()?1:Number(this.customUniforms.get("uTransparentBg")??0);this.customUniforms.set("uTransparentBg",s),o.uTransparentBg=s}if(this.boostInteraction(1200),e.quality!==void 0&&e.quality!==t){let r=We[e.quality]??We.medium;this.baseFeedbackMaxDim=this.options.feedbackMaxDim??r.fboMaxDim}if(e.feedbackMaxDim!==void 0&&(this.baseFeedbackMaxDim=e.feedbackMaxDim),(e.quality!==void 0&&e.quality!==t||e.feedbackMaxDim!==void 0||e.minDpr!==void 0||e.maxDpr!==void 0||e.dynamicResolution!==void 0)&&this.syncDprBounds(),typeof e.interactive=="boolean"&&e.interactive!==this.interactive&&(this.interactive=e.interactive,this.syncPointerListener(),this.syncTouchListener()),typeof e.trackScroll=="boolean"&&e.trackScroll!==this.trackScroll&&(this.trackScroll=e.trackScroll,this.syncScrollListener()),e.scrollColors!==void 0&&this.syncScrollColorListener(),typeof e.respectReducedMotion=="boolean"){this.respectReducedMotion=e.respectReducedMotion;let r=this.reducedMotionQuery?.matches??!1;this.applyReducedMotionState(this.respectReducedMotion&&r)}if(this.isBudgetSuspended){this.applyBudgetFallbackStyle();return}this.isOffscreen&&this.worker?Object.keys(o).length>0&&this.worker.postMessage({type:"uniformsBatch",uniforms:o}):this.isReducedMotion&&(this.needsResize&&(this.needsResize=!1,this.applyCanvasSize()),this.drawMainThreadFrame()),e.textures!==void 0&&this.syncTexturesFromOptions(e.textures)}applyReducedMotionState(e){this.isReducedMotion!==e&&(this.isReducedMotion=e,this.resetFrameTracking(),this.isOffscreen&&this.worker?this.worker.postMessage({type:"reducedMotion",value:e}):e&&(this.needsResize&&(this.needsResize=!1,this.applyCanvasSize()),this.drawMainThreadFrame()),this.wakeCallback?.())}getLocalPointerCoords(e){let t=this.container.getBoundingClientRect();if(t.width<=0||t.height<=0||e.clientX<t.left||e.clientX>t.right||e.clientY<t.top||e.clientY>t.bottom)return null;let o=(e.clientX-t.left)/t.width,r=1-(e.clientY-t.top)/t.height;return[o,r]}syncInteractiveAttr(){if(this.interactive&&!this.isDestroyed){this.container.setAttribute("data-fluxfx-interactive","true");return}let e=!1;re.instances.forEach(t=>{t!==this&&!t.isDestroyed&&t.interactive&&t.container===this.container&&(e=!0)}),e||this.container.removeAttribute("data-fluxfx-interactive")}isShadowedByChildInteractive(e){if(!(e instanceof Element))return!1;let t=e.closest('[data-fluxfx-interactive="true"]');return!!(t&&t!==this.container&&this.container.contains(t))}syncPointerListener(){this.syncInteractiveAttr(),this.interactive&&!this.hasPointerListener?(this.container.addEventListener("pointerenter",this.handlePointerEnter,{passive:!0}),this.container.addEventListener("pointermove",this.handlePointerMove,{passive:!0}),this.container.addEventListener("pointerleave",this.handlePointerLeave,{passive:!0}),this.container.addEventListener("pointerdown",this.handlePointerDown,{passive:!0}),window.addEventListener("pointerup",this.handlePointerUp,{passive:!0}),window.addEventListener("pointercancel",this.handlePointerUp,{passive:!0}),this.hasPointerListener=!0):!this.interactive&&this.hasPointerListener&&(this.container.removeEventListener("pointerenter",this.handlePointerEnter),this.container.removeEventListener("pointermove",this.handlePointerMove),this.container.removeEventListener("pointerleave",this.handlePointerLeave),this.container.removeEventListener("pointerdown",this.handlePointerDown),window.removeEventListener("pointerup",this.handlePointerUp),window.removeEventListener("pointercancel",this.handlePointerUp),this.handlePointerLeave(),this.hasPointerListener=!1)}syncScrollListener(){this.trackScroll&&!this.hasScrollListener?(window.addEventListener("scroll",this.handleScroll,{passive:!0}),this.hasScrollListener=!0,this.handleScroll()):!this.trackScroll&&this.hasScrollListener&&(window.removeEventListener("scroll",this.handleScroll),this.hasScrollListener=!1)}bindObservers(e){typeof ResizeObserver<"u"&&(this.resizeObserver=new ResizeObserver(t=>{let o=t[0];if(!o)return;let r=Math.max(1,Math.floor(o.contentRect.width)),s=Math.max(1,Math.floor(o.contentRect.height));r===this.width&&s===this.height||(this.width=r,this.height=s,this.boostInteraction(600),this.trackScroll&&this.handleScroll(),this.isOffscreen&&this.worker?this.worker.postMessage({type:"resize",width:this.width,height:this.height}):this.isReducedMotion&&!this.isPaused&&!this.isHiddenByViewport?(this.needsResize=!1,this.applyCanvasSize(),this.drawMainThreadFrame()):this.needsResize=!0)}),this.resizeObserver.observe(this.container)),e&&typeof IntersectionObserver<"u"&&(this.visibilityObserver=new IntersectionObserver(t=>{let o=t[0]?.isIntersecting??!0;if(this.isHiddenByViewport=!o,o){if(this.lastActiveAt=je(),this.isBudgetSuspended&&!this.isPaused){this.restoreContextFromBudget();return}}else this.handlePointerLeave(),this.resetFrameTracking();this.isOffscreen&&this.worker&&this.worker.postMessage({type:o&&!this.isPaused?"resume":"pause"}),this.wakeCallback?.()},{rootMargin:"50px"}),this.visibilityObserver.observe(this.container)),this.reducedMotionQuery&&this.reducedMotionQuery.addEventListener("change",this.handleReducedMotionChange),this.isOffscreen&&typeof document<"u"&&document.addEventListener("visibilitychange",this.handleDocVisibility),this.watchDevicePixelRatio(),this.bindThemeWatchers(),this.syncPointerListener(),this.syncTouchListener(),this.syncScrollListener(),this.syncScrollColorListener()}setUniform(e,t){if(!this.isDestroyed){if(this.customUniforms.set(e,t),e==="uSpeed"&&typeof t=="number"&&(this.targetSpeed=t),this.boostInteraction(1200),this.isBudgetSuspended){this.applyBudgetFallbackStyle();return}this.isOffscreen&&this.worker?this.worker.postMessage({type:"uniform",name:e,value:typeof t=="number"?t:Array.from(t)}):this.isReducedMotion&&this.drawMainThreadFrame()}}setColor(e,t){let o=ee(t,"#ffffff"),r=Y.hexToVec3Into(o,Y.scratchVec3);this.setUniform(e,[r[0],r[1],r[2]])}get isIdle(){return this.isDestroyed||this.isPaused||this.isHiddenByViewport||this.isReducedMotion||this.isContextLost}onWake(e){this.wakeCallback=e}pause(){this.isPaused||this.isDestroyed||(this.isPaused=!0,this.resetFrameTracking(),this.handlePointerLeave(),this.isOffscreen&&this.worker&&this.worker.postMessage({type:"pause"}))}resume(){if(!(!this.isPaused||this.isDestroyed)){if(this.isPaused=!1,this.lastRenderNow=0,this.lastDrawNow=0,this.lastActiveAt=je(),this.isBudgetSuspended&&!this.isHiddenByViewport){this.restoreContextFromBudget();return}this.isOffscreen&&this.worker&&!this.isHiddenByViewport?this.worker.postMessage({type:"resume"}):this.isReducedMotion&&!this.isHiddenByViewport&&(this.needsResize&&(this.needsResize=!1,this.applyCanvasSize()),this.drawMainThreadFrame())}}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.wakeCallback=null,this.unsubscribeGuard?.(),this.unsubscribeGuard=null,this.unbindThemeWatchers(),this.touchBurstTimer&&(window.clearTimeout(this.touchBurstTimer),this.touchBurstTimer=0),this.touchLeaveTimer&&(window.clearTimeout(this.touchLeaveTimer),this.touchLeaveTimer=0),this.hasTouchListener&&(this.container.removeEventListener("touchstart",this.handleTouchStart),this.container.removeEventListener("touchmove",this.handleTouchMove),this.container.removeEventListener("touchend",this.handleTouchEnd),this.container.removeEventListener("touchcancel",this.handleTouchEnd),this.hasTouchListener=!1),this.hasScrollColorListener&&(window.removeEventListener("scroll",this.handleScrollColorEvent),this.hasScrollColorListener=!1),this.scrollColorRaf&&(cancelAnimationFrame(this.scrollColorRaf),this.scrollColorRaf=0),this.isBodyMount&&(this.container.style.minHeight=this.origBodyMinHeight),re.instances.delete(this),this.syncInteractiveAttr(),this.resetFrameTracking(),this.resizeObserver?.disconnect(),this.resizeObserver=null,this.visibilityObserver?.disconnect(),this.visibilityObserver=null,this.reducedMotionQuery&&(this.reducedMotionQuery.removeEventListener("change",this.handleReducedMotionChange),this.reducedMotionQuery=null),this.dprMediaQuery&&(this.dprMediaQuery.removeEventListener("change",this.handleDprChange),this.dprMediaQuery=null),typeof document<"u"&&document.removeEventListener("visibilitychange",this.handleDocVisibility),this.hasPointerListener&&(this.container.removeEventListener("pointerenter",this.handlePointerEnter),this.container.removeEventListener("pointermove",this.handlePointerMove),this.container.removeEventListener("pointerleave",this.handlePointerLeave),this.container.removeEventListener("pointerdown",this.handlePointerDown),window.removeEventListener("pointerup",this.handlePointerUp),window.removeEventListener("pointercancel",this.handlePointerUp),this.hasPointerListener=!1),this.hasScrollListener&&(window.removeEventListener("scroll",this.handleScroll),this.hasScrollListener=!1),this.canvas.removeEventListener("webglcontextlost",this.handleContextLost,!1),this.canvas.removeEventListener("webglcontextrestored",this.handleContextRestored,!1),this.isOffscreen&&this.worker&&(this.worker.postMessage({type:"destroy"}),this.worker=null),this.releaseMainThreadContext(!1),this.markContextReleased(),Y.releaseVec2(this.mouse),Y.releaseVec2(this.targetMouse),Y.releaseVec2(this.mouseVel),this.customUniforms.clear(),this.textureUrls.clear(),this.textureUnits.clear(),this.loadedImages.clear(),this.textureLoadTokens.clear(),re.reclaimBudgetForWaiting())}resolveTextureUrl(e){let t=e.trim();if(!t)return"";if(/^(data:|blob:)/i.test(t)||typeof window>"u")return t;try{return new URL(t,window.location.href).href}catch{return t}}destroyMainTextures(){if(!this.gl||this.mainTextures.size===0){this.mainTextures.clear();return}let e=this.gl;this.mainTextures.forEach(t=>{e.deleteTexture(t.tex)}),this.mainTextures.clear()}bindMainTextures(e,t){this.mainTextures.size!==0&&this.mainTextures.forEach((o,r)=>{let s=$.getUniformLocation(e,t,r);s&&(e.activeTexture(e.TEXTURE0+o.unit),e.bindTexture(e.TEXTURE_2D,o.tex),e.uniform1i(s,o.unit))})}uploadImageTexture(e,t,o,r){if(this.isDestroyed)return;let s=this.textureUnits.get(e);s===void 0&&(s=this.nextTextureUnit++,this.textureUnits.set(e,s));let n=`${e}Size`,l=`${e}Ready`;if(this.customUniforms.set(n,[o,r]),this.customUniforms.set(l,1),this.isOffscreen&&this.worker&&typeof createImageBitmap=="function"){createImageBitmap(t).then(a=>{if(this.isDestroyed||!this.isOffscreen||!this.worker){a.close();return}this.worker.postMessage({type:"texture",name:e,unit:s,bitmap:a,width:o,height:r},[a]),this.boostInteraction(600),this.wakeCallback?.()}).catch(()=>{});return}if(this.gl&&!this.isContextLost){let a=this.gl,u=this.mainTextures.get(e)?.tex??null;u||(u=a.createTexture()),u&&(a.activeTexture(a.TEXTURE0+s),a.bindTexture(a.TEXTURE_2D,u),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,t),a.bindTexture(a.TEXTURE_2D,null),this.mainTextures.set(e,{unit:s,tex:u}),this.pushUniformBatch({[n]:[o,r],[l]:1}),this.boostInteraction(600),this.wakeCallback?.(),!this.isPaused&&!this.isHiddenByViewport&&this.drawMainThreadFrame())}}reuploadLoadedTextures(){this.loadedImages.forEach((e,t)=>{this.uploadImageTexture(t,e.img,e.width,e.height)})}clearTextureSlot(e){if(this.textureUrls.delete(e),this.loadedImages.delete(e),this.textureLoadTokens.set(e,(this.textureLoadTokens.get(e)??0)+1),this.customUniforms.set(`${e}Ready`,0),this.isOffscreen&&this.worker)this.worker.postMessage({type:"clearTexture",name:e});else if(this.gl&&!this.isContextLost){let t=this.mainTextures.get(e);t&&(this.gl.deleteTexture(t.tex),this.mainTextures.delete(e)),this.pushUniformBatch({[`${e}Ready`]:0})}}syncTexturesFromOptions(e){if(!(!e||typeof window>"u"||typeof Image>"u"))for(let[t,o]of Object.entries(e)){let r=o?this.resolveTextureUrl(o):"",s=this.textureUrls.get(t)??"";if(!r){s?this.clearTextureSlot(t):this.customUniforms.set(`${t}Ready`,0);continue}if(r===s)continue;this.textureUrls.set(t,r),this.customUniforms.has(`${t}Ready`)||this.customUniforms.set(`${t}Ready`,0);let n=(this.textureLoadTokens.get(t)??0)+1;this.textureLoadTokens.set(t,n);let l=new Image;if(!/^(data:|blob:)/i.test(r))try{new URL(r,window.location.href).origin!==window.location.origin&&(l.crossOrigin="anonymous")}catch{}l.decoding="async",l.onload=()=>{if(this.isDestroyed||this.textureLoadTokens.get(t)!==n)return;let a=l.naturalWidth||l.width||1,d=l.naturalHeight||l.height||1;this.loadedImages.set(t,{url:r,img:l,width:a,height:d}),this.uploadImageTexture(t,l,a,d)},l.onerror=()=>{this.isDestroyed||this.textureLoadTokens.get(t)!==n||console.warn(`[FluxFX] Failed to load texture "${t}" from: ${r}`)},l.src=r}}};re._activeContexts=0,re._maxContexts=kt(),re.instances=new Set,re.recycledMainContexts=[];var he=re;var it=class{constructor(){this.plugins=new Map;this.activeByElement=new WeakMap;this.activeSet=new Set;this.visibilityObserver=null;this.visibilityCallbacks=new WeakMap;this.removeTicker=null;this.removeVisibilitySub=null;this.hasResizeListener=!1;this.resizeRaf=0;this.handleViewportResize=()=>{this.resizeRaf||(this.resizeRaf=requestAnimationFrame(()=>{this.resizeRaf=0;let e=!1;this.activeSet.forEach(t=>{if(!this.hasDeviceConstraints(t.options))return;let o=this.isDeviceAllowed(t.options);o&&!t.instance?this.mountEntryInstance(t)&&(e=!0):!o&&t.instance&&(this.unmountEntryInstance(t),e=!0)}),e&&this.syncTickerState()}))}}isDeviceAllowed(e){if(typeof window>"u")return!0;let t=window.innerWidth||document.documentElement?.clientWidth||1024,o=typeof e.mobileBreakpoint=="number"&&e.mobileBreakpoint>0?e.mobileBreakpoint:768;if(e.disableOnMobile&&t<o||e.disableOnDesktop&&t>=o)return!1;let r=typeof e.device=="string"?e.device.trim().toLowerCase():"all";return!(r==="desktop"&&t<o||r==="mobile"&&t>=o||r==="tablet"&&(t<o||t>=1024)||typeof e.minWidth=="number"&&t<e.minWidth||typeof e.maxWidth=="number"&&t>e.maxWidth)}hasDeviceConstraints(e){return!!(e.device&&e.device!=="all"||e.disableOnMobile||e.disableOnDesktop||typeof e.minWidth=="number"||typeof e.maxWidth=="number")}mountEntryInstance(e){if(e.instance)return!0;try{let t=e.plugin.mount(e.el,e.options);return e.instance=t,e.faulted=!1,this.bindWake(e),this.attachEntryObserver(e),(!e.visible||xe.isHidden)&&t.pause?.(),!0}catch(t){return e.faulted=!0,console.error(`[FluxFX] Failed to mount "${e.name}":`,t),!1}}unmountEntryInstance(e){if(e.unobserve?.(),e.unobserve=null,!!e.instance){try{e.instance.destroy()}catch(t){console.error(`[FluxFX] Device toggle cleanup error in "${e.name}":`,t)}e.instance=null,e.visible=!0}}attachEntryObserver(e){if(!(e.options.pauseWhenHidden??!0)||e.unobserve)return;let o=this.ensureObserver();if(!o)return;let r=this.visibilityCallbacks.get(e.el);r||(r=new Set,this.visibilityCallbacks.set(e.el,r),o.observe(e.el));let s=n=>{e.visible=n,e.instance&&(n&&!xe.isHidden?e.instance.resume?.():e.instance.pause?.(),this.syncTickerState())};r.add(s),e.unobserve=()=>{r?.delete(s),r&&r.size===0&&(o.unobserve(e.el),this.visibilityCallbacks.delete(e.el))}}syncResizeWatcher(){if(typeof window>"u")return;let e=!1;this.activeSet.forEach(t=>{!e&&this.hasDeviceConstraints(t.options)&&(e=!0)}),e&&!this.hasResizeListener?(window.addEventListener("resize",this.handleViewportResize,{passive:!0}),this.hasResizeListener=!0):!e&&this.hasResizeListener&&(window.removeEventListener("resize",this.handleViewportResize),this.hasResizeListener=!1,this.resizeRaf&&(cancelAnimationFrame(this.resizeRaf),this.resizeRaf=0))}ensureObserver(){return typeof window>"u"||typeof IntersectionObserver>"u"?null:(this.visibilityObserver||(this.visibilityObserver=new IntersectionObserver(e=>{for(let t=0;t<e.length;t++){let o=e[t],r=this.visibilityCallbacks.get(o.target);r&&r.forEach(s=>s(o.isIntersecting))}},{rootMargin:"50px"})),this.visibilityObserver)}ensureVisibilitySub(){this.removeVisibilitySub||(this.removeVisibilitySub=xe.onVisibilityChange(e=>{this.activeSet.forEach(t=>{t.faulted||!t.instance||(e?t.instance.pause?.():t.visible&&t.instance.resume?.())}),this.syncTickerState()}))}hasActiveTickWork(){let e=!1;return this.activeSet.forEach(t=>{e||!t.visible||t.faulted||!t.instance?.update||t.instance.isIdle?.()||(e=!0)}),e}syncTickerState(){this.hasActiveTickWork()?this.ensureTicker():this.removeTicker&&(this.removeTicker(),this.removeTicker=null)}ensureTicker(){this.removeTicker||(this.removeTicker=xe.add((e,t)=>{let o=!1;this.activeSet.forEach(r=>{if(!(!r.visible||r.faulted||!r.instance?.update)&&!r.instance.isIdle?.()){try{r.instance.update(e,t)}catch(s){r.faulted=!0,console.error(`[FluxFX] Runtime error in "${r.name}" (auto-paused):`,s);return}r.instance.isIdle?.()||(o=!0)}}),o||this.syncTickerState()}))}cleanupEmptyEngine(){this.syncTickerState(),this.syncResizeWatcher(),this.activeSet.size===0&&this.removeVisibilitySub&&(this.removeVisibilitySub(),this.removeVisibilitySub=null)}bindWake(e){e.instance?.onWake?.(()=>{this.activeSet.has(e)&&this.syncTickerState()})}register(e){return this.plugins.set(e.name,e),this}has(e){return this.plugins.has(e)}setMaxWebGLContexts(e){he.setMaxActiveContexts(e)}getStats(){let e=0,t=0,o=!1,r=xe.isHidden;this.activeSet.forEach(u=>{if(!u.instance){t++;return}u.visible&&e++;let f=u.instance.isIdle?.()??!1;r||!u.visible||u.faulted||f?t++:!u.instance.isWebGL&&u.instance.isIdle&&(o=!0)});let s=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,n=he.getRenderStats(),l=xe.fps,a=xe.frameTimeMs;!r&&n.activeRendering>0&&!o?(l=n.fps,a=n.frameTimeMs):r&&(l=0,a=0);let d=be.getSnapshot();return{mounted:this.activeSet.size,visible:e,pausedEffects:t,activeLoops:xe.isRunning?1:0,registered:this.plugins.size,webglContexts:he.activeContexts,activeContexts:he.activeContexts,maxWebGLContexts:he.maxActiveContexts,suspendedContexts:he.suspendedContexts,fps:l,frameTimeMs:a,reducedMotion:s,protectionTier:d.tier,protectionLabel:d.label}}apply(e,t,o={}){let r=this.plugins.get(t);if(!r)return console.warn(`[FluxFX] Effect "${t}" is not registered.`),()=>{};let s=this.activeByElement.get(e);s||(s=new Map,this.activeByElement.set(e,s));let n=s.get(t);n&&n.destroy();let l=!1,a={el:e,name:t,plugin:r,instance:null,options:{...o},visible:!0,faulted:!1,unobserve:null,destroy:()=>{l||(l=!0,this.unmountEntryInstance(a),this.activeSet.delete(a),s?.delete(t),this.cleanupEmptyEngine())}};return this.isDeviceAllowed(a.options)&&!this.mountEntryInstance(a)?(s?.delete(t),()=>{}):(s.set(t,a),this.activeSet.add(a),this.ensureVisibilitySub(),this.syncResizeWatcher(),this.syncTickerState(),a.destroy)}update(e,t,o={}){let s=this.activeByElement.get(e)?.get(t);if(!s)return!1;s.options={...s.options,...o};let n=s.options;if(this.syncResizeWatcher(),!this.isDeviceAllowed(n))return this.unmountEntryInstance(s),this.syncTickerState(),!0;if(!s.instance){let a=this.mountEntryInstance(s);return this.syncTickerState(),a}if(s.instance.setOptions)try{return s.instance.setOptions(n),this.syncTickerState(),!0}catch(a){return console.error(`[FluxFX] Hot-update error in "${t}":`,a),!1}try{return s.instance.destroy(),s.instance=s.plugin.mount(e,n),s.faulted=!1,this.bindWake(s),(!s.visible||xe.isHidden)&&s.instance.pause?.(),this.syncTickerState(),!0}catch(a){return s.faulted=!0,console.error(`[FluxFX] Fallback remount error in "${t}":`,a),this.syncTickerState(),!1}}scan(e=document){if(typeof document>"u")return;e.querySelectorAll("[data-fx]").forEach(o=>{let r=o.getAttribute("data-fx");if(!r)return;let s=r.trim().split(/\s+/).filter(Boolean),n=this.parseDatasetOptions(o),l=this.activeByElement.get(o);s.forEach(a=>{l?.has(a)||this.apply(o,a,n)})})}init(e){typeof document>"u"||(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>this.scan(e??document),{once:!0}):this.scan(e??document))}destroyAll(){let e=Array.from(this.activeSet);for(let t=0;t<e.length;t++)e[t].destroy()}parseDatasetOptions(e){let t={},o=new Set(["preserveBg","adaptToSurface","interactive","trackScroll","glare","offscreen","dynamicResolution","pauseWhenHidden","respectReducedMotion","ambient","clickReveal","focused","wrap","clickToFocus","disableOnMobile","disableOnDesktop","clamp","invert","returnToIdle","once","crossfade"]),r=new Set(["colors","lightColors","darkColors","scrollColors","frames"]);for(let[s,n]of Object.entries(e.dataset)){if(!s.startsWith("fx")||s==="fx"||n===void 0)continue;let l=s.slice(2),a=l.charAt(0).toLowerCase()+l.slice(1),d=n.trim(),u=d.toLowerCase();d===""&&o.has(a)||u==="true"?t[a]=!0:u==="false"?t[a]=!1:r.has(a)?t[a]=d.split(",").map(f=>f.trim()).filter(Boolean):d!==""&&!Number.isNaN(Number(d))?t[a]=Number(d):t[a]=d}return t}},ot=new it;function cr(i){if(i==null)return!1;let e=String(i).trim().toLowerCase();if(!e)return!1;if(e==="transparent"||e==="none")return!0;let t=e.match(/^rgba?\(\s*[\d.]+\s*,\s*[\d.]+\s*,\s*[\d.]+(?:\s*,\s*([\d.]+))?\s*\)$/);return t&&t[1]!==void 0?parseFloat(t[1])<=.001:!1}function Pt(i){let e=i.replace("#","").trim(),t=e.length===3?e.split("").map(n=>n+n).join(""):e;if(t.length!==6)return!0;let o=parseInt(t.slice(0,2),16)/255,r=parseInt(t.slice(2,4),16)/255,s=parseInt(t.slice(4,6),16)/255;return .2126*o+.7152*r+.0722*s>.45}function Dt(i,e){if(Array.isArray(i.colors)&&i.colors.length>0){let s=i.colors.filter(Boolean);if(s.length===1){let d=ee(s[0],e[0]);return[d,d,d]}if(s.length===2){let d=ee(s[0],e[0]),u=ee(s[1],e[1]);return[d,u,u]}let n=ee(s[0],e[0]),l=ee(s[1]??n,e[1]),a=ee(s[2]??l,e[2]);return[n,l,a]}if(typeof i.colors=="string"){let s=i.colors.split(",").map(n=>n.trim()).filter(Boolean);if(s.length===1){let n=ee(s[0],e[0]);return[n,n,n]}if(s.length===2){let n=ee(s[0],e[0]),l=ee(s[1],e[1]);return[n,l,l]}if(s.length>2)return[ee(s[0],e[0]),ee(s[1],e[1]),ee(s[2],e[2])]}if(i.color1===void 0&&i.color2===void 0&&i.color3===void 0)return e;let t=ee(i.color1,e[0]),o=i.color2!==void 0?ee(i.color2,t):t,r=i.color3!==void 0?ee(i.color3,o):o;return[t,o,r]}function ne(i,e){let t=cr(i.bgColor),o=!t&&i.bgColor!==void 0&&String(i.bgColor).trim()!=="",r=o?ee(i.bgColor,e):e,s=Y.hexToVec3Into(r,Y.scratchVec3);return{uBgColor:[s[0],s[1],s[2]],uHasBgColor:o?1:0,uTransparentBg:t?1:0,bgHex:r,hasBgColor:o,transparentBg:t}}function ur(i){return i==="high"?.65:i==="low"?.35:.5}function se(i){return{name:i.name,mount(e,t){let o=t.quality??"medium",r=new he(e,{fragmentShader:i.fragmentShader,vertexShader:i.vertexShader,feedbackShader:i.feedbackShader,feedbackScale:i.feedbackShader?ur(o):void 0,feedbackFloat:i.feedbackShader?i.feedbackFloat??!0:void 0,feedbackMaxDim:typeof t.feedbackMaxDim=="number"?t.feedbackMaxDim:void 0,speed:typeof t.speed=="number"?t.speed:1,quality:o,colors:Dt(t,i.defaultColors),uniforms:i.resolveUniforms?i.resolveUniforms(t):void 0,textures:i.resolveTextures?i.resolveTextures(t):void 0,theme:t.theme,lightColors:t.lightColors,darkColors:t.darkColors,scrollColors:t.scrollColors,trackScroll:t.trackScroll,layer:t.layer,preserveBg:t.preserveBg,adaptToSurface:t.adaptToSurface,overlayOpacity:t.overlayOpacity,interactive:t.interactive!==!1,dynamicResolution:t.dynamicResolution,minDpr:t.minDpr,maxDpr:t.maxDpr,offscreen:t.offscreen,pauseWhenHidden:t.pauseWhenHidden,respectReducedMotion:t.respectReducedMotion});return{isWebGL:!0,update(s,n){r.render(s,n)},setOptions(s){r.updateOptions({speed:typeof s.speed=="number"?s.speed:1,quality:s.quality,colors:Dt(s,i.defaultColors),uniforms:i.resolveUniforms?i.resolveUniforms(s):void 0,textures:i.resolveTextures?i.resolveTextures(s):void 0,theme:s.theme,lightColors:s.lightColors,darkColors:s.darkColors,scrollColors:s.scrollColors,trackScroll:s.trackScroll,layer:s.layer,preserveBg:s.preserveBg,adaptToSurface:s.adaptToSurface,overlayOpacity:s.overlayOpacity,interactive:s.interactive!==!1,dynamicResolution:s.dynamicResolution,minDpr:s.minDpr,maxDpr:s.maxDpr,feedbackMaxDim:typeof s.feedbackMaxDim=="number"?s.feedbackMaxDim:void 0,respectReducedMotion:s.respectReducedMotion})},isIdle(){return r.isIdle},onWake(s){r.onWake(s)},pause(){r.pause()},resume(){r.resume()},destroy(){r.destroy()}}}}}var dr=`#version 300 es
791
859
  precision highp float;
792
860
 
793
861
  in vec2 vUv;
@@ -797,6 +865,7 @@ uniform float uTime;
797
865
  uniform vec2 uResolution;
798
866
  uniform vec2 uMouse;
799
867
  uniform float uMouseActive;
868
+ uniform float uMouseDown;
800
869
  uniform vec3 uBgColor;
801
870
  uniform float uHasBgColor;
802
871
  uniform float uTransparentBg;
@@ -813,7 +882,7 @@ float hash(vec2 p) {
813
882
  float noise(vec2 p) {
814
883
  vec2 i = floor(p);
815
884
  vec2 f = fract(p);
816
- vec2 u = f * f * (3.0 - 2.0 * f);
885
+ vec2 u = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);
817
886
  return mix(
818
887
  mix(hash(i + vec2(0.0, 0.0)), hash(i + vec2(1.0, 0.0)), u.x),
819
888
  mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), u.x),
@@ -826,15 +895,16 @@ float fbm(vec2 p) {
826
895
  float amp = 0.5;
827
896
  float norm = 0.0;
828
897
  mat2 rot = mat2(0.8, 0.6, -0.6, 0.8);
829
- int octaves = uQuality < 0.25 ? 2 : (uQuality < 0.75 ? 3 : 4);
830
- for (int i = 0; i < 4; i++) {
898
+ // Keep >= 3 octaves even on low quality so aurora curves stay silky smooth
899
+ int octaves = uQuality < 0.25 ? 3 : (uQuality < 0.75 ? 4 : 5);
900
+ for (int i = 0; i < 5; i++) {
831
901
  if (i >= octaves) break;
832
902
  value += amp * noise(p);
833
903
  norm += amp;
834
904
  p = rot * p * 2.02;
835
905
  amp *= 0.5;
836
906
  }
837
- return (value / max(norm, 0.001)) * 0.9375;
907
+ return value / max(norm, 0.001);
838
908
  }
839
909
 
840
910
  void main() {
@@ -843,52 +913,66 @@ void main() {
843
913
  vec2 p = (uv - 0.5) * vec2(aspect, 1.0);
844
914
 
845
915
  vec2 m = (uMouse - 0.5) * vec2(aspect, 1.0);
846
- float mouseDist = length(p - m);
847
- p += normalize(p - m + 0.0001) * exp(-mouseDist * 2.5) * 0.08 * uMouseActive;
916
+ vec2 diff = p - m;
917
+ float mouseDist = length(diff);
918
+ vec2 pushDir = mouseDist > 0.0005 ? diff / mouseDist : vec2(0.0);
919
+ float mouseInfluence = exp(-mouseDist * 2.1) * uMouseActive;
920
+ p += pushDir * mouseInfluence * (0.16 + 0.08 * uMouseDown);
921
+
922
+ float t = uTime * 0.28;
923
+
924
+ // Two-stage smooth domain warp for organic northern-lights waves
925
+ vec2 q = vec2(
926
+ fbm(p * 1.15 + vec2(t * 0.55, -t * 0.30)),
927
+ fbm(p * 1.15 + vec2(-t * 0.40, t * 0.35) + vec2(4.2, 1.8))
928
+ );
929
+ float f = fbm(p * 1.45 + 1.15 * q + vec2(t * 0.22, -t * 0.14));
848
930
 
849
- float t = uTime * 0.25;
931
+ // Sweeping gaussian aurora curtains (smooth flowing veils, zero repeating stripe grid)
932
+ float d1 = abs(p.y + 0.10 - (f - 0.5) * 0.85 - 0.18 * sin(p.x * 1.55 + t * 0.85));
933
+ float d2 = abs(p.y - 0.14 + (q.x - 0.5) * 0.78 - 0.20 * cos(p.x * 1.35 - t * 0.72));
934
+ float d3 = abs((p.y * 0.85 - p.x * 0.26) - (q.y - 0.5) * 0.72 + 0.14 * sin(p.x * 2.0 + t * 1.05));
850
935
 
851
- vec2 q = vec2(fbm(p * 1.4 + vec2(t, -t * 0.5)), fbm(p * 1.4 + vec2(-t * 0.6, t * 0.4)));
852
- float f = fbm(p * 1.8 + 1.6 * q + vec2(t * 0.3, 0.0));
936
+ float band1 = exp(-d1 * d1 * 6.2);
937
+ float band2 = exp(-d2 * d2 * 7.2) * smoothstep(0.14, 0.86, f);
938
+ float band3 = exp(-d3 * d3 * 8.8) * smoothstep(0.18, 0.88, q.x);
853
939
 
854
- float ribbon1 = smoothstep(0.15, 0.85, sin(p.y * 3.0 + f * 4.5 + t) * 0.5 + 0.5);
855
- float ribbon2 = smoothstep(0.2, 0.9, cos(p.x * 2.2 - f * 3.8 - t * 1.2) * 0.5 + 0.5);
940
+ // Subtle vertical curtain shimmer rays
941
+ float ray = smoothstep(0.28, 0.84, fbm(vec2(p.x * 3.6 + q.x * 1.3, p.y * 0.85 - t * 0.55)));
942
+ float w1 = clamp(band1 * (0.68 + 0.52 * ray) + mouseInfluence * 0.16, 0.0, 1.0);
943
+ float w2 = clamp(band2 * (0.68 + 0.48 * ray), 0.0, 1.0);
944
+ float w3 = clamp(band3 * (0.58 + 0.52 * ray), 0.0, 1.0);
856
945
 
857
- float m1 = smoothstep(0.1, 0.9, ribbon1) * 0.85;
858
- float m2 = smoothstep(0.2, 0.85, ribbon2 * f) * 0.9;
859
- float m3 = smoothstep(0.25, 0.9, f * ribbon1) * 0.65;
860
- float grain = (hash(gl_FragCoord.xy + fract(uTime)) - 0.5) * 0.02;
946
+ // Unified weighted palette blend prevents muddy color overlap
947
+ float totalW = w1 + w2 + w3;
948
+ vec3 ribbonCol = (uColor1 * w1 + uColor2 * w2 + uColor3 * w3) / max(totalW, 0.001);
949
+ float coreGlow = clamp((band1 * band2 + band2 * band3) * 1.25, 0.0, 1.0);
950
+ ribbonCol = mix(ribbonCol, mix(ribbonCol, vec3(1.0), 0.38), coreGlow * 0.5);
951
+
952
+ float intensity = clamp(max(w1, max(w2, w3)) * 0.78 + totalW * 0.18, 0.0, 1.0);
953
+ float grain = (hash(gl_FragCoord.xy + fract(uTime * 0.25)) - 0.5) * 0.012;
861
954
 
862
955
  if (uTransparentBg > 0.5) {
863
- float w1 = smoothstep(0.18, 0.9, ribbon1) * 0.85;
864
- float w2 = smoothstep(0.22, 0.88, ribbon2 * f) * 0.9;
865
- float w3 = smoothstep(0.28, 0.92, f * ribbon1) * 0.65;
866
- float wSum = w1 + w2 + w3 + 0.0001;
867
- vec3 ribbonCol = (uColor1 * w1 + uColor2 * w2 + uColor3 * w3) / wSum;
868
- ribbonCol = clamp(ribbonCol + uColor3 * w3 * 0.35 + vec3(grain), 0.0, 1.0);
869
- float alpha = clamp(max(max(w1, w2), w3), 0.0, 1.0);
870
- fragColor = vec4(ribbonCol * alpha, alpha);
956
+ vec3 premult = clamp(ribbonCol + vec3(grain), 0.0, 1.0);
957
+ fragColor = vec4(premult * intensity, intensity);
871
958
  return;
872
959
  }
873
960
 
874
- float darkAmt = clamp(uTheme, 0.0, 1.0);
875
- vec3 baseDark = uHasBgColor > 0.5 ? uBgColor : vec3(0.03, 0.04, 0.09);
876
- vec3 baseLight = uHasBgColor > 0.5 ? uBgColor : vec3(0.96, 0.95, 0.925);
961
+ float bgLum = dot(uBgColor, vec3(0.2126, 0.7152, 0.0722));
962
+ float darkAmt = uHasBgColor > 0.5 ? smoothstep(0.55, 0.25, bgLum) : clamp(uTheme, 0.0, 1.0);
963
+ vec3 baseDark = uHasBgColor > 0.5 ? uBgColor : vec3(0.028, 0.038, 0.085);
964
+ vec3 baseLight = uHasBgColor > 0.5 ? uBgColor : vec3(0.968, 0.965, 0.955);
877
965
 
878
- vec3 darkCol = mix(baseDark, uColor1, m1);
879
- darkCol = mix(darkCol, uColor2, m2);
880
- darkCol += uColor3 * m3;
881
- float darkVig = 1.0 - dot(uv - 0.5, uv - 0.5) * 0.75;
882
- darkCol = max(darkCol * darkVig + grain, vec3(0.0));
966
+ vec3 darkCol = mix(baseDark, clamp(baseDark * 0.35 + ribbonCol * 1.1, 0.0, 1.0), intensity);
967
+ float darkVig = 1.0 - dot(uv - 0.5, uv - 0.5) * 0.26;
968
+ darkCol = clamp(darkCol * darkVig + grain, 0.0, 1.0);
883
969
 
884
- vec3 lightCol = mix(baseLight, uColor1, m1 * 0.44);
885
- lightCol = mix(lightCol, uColor2, m2 * 0.40);
886
- lightCol = mix(lightCol, uColor3, m3 * 0.34);
887
- float lightVig = 1.0 - dot(uv - 0.5, uv - 0.5) * 0.14;
888
- lightCol = clamp(lightCol * lightVig + grain * 0.5, 0.0, 1.0);
970
+ vec3 lightCol = mix(baseLight, ribbonCol, intensity * 0.65);
971
+ float lightVig = 1.0 - dot(uv - 0.5, uv - 0.5) * 0.06;
972
+ lightCol = clamp(lightCol * lightVig + grain * 0.45, 0.0, 1.0);
889
973
 
890
974
  fragColor = vec4(mix(lightCol, darkCol, darkAmt), 1.0);
891
- }`,Me=P({name:"aurora",fragmentShader:Ue,defaultColors:["#4f46e5","#06b6d4","#ec4899"],resolveUniforms(o){let e=B(o,"#080a17");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg}}});var _e=`#version 300 es
975
+ }`,At=se({name:"aurora",fragmentShader:dr,defaultColors:["#4f46e5","#06b6d4","#ec4899"],resolveUniforms(i){let e=ne(i,"#080a17");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg}}});var fr=`#version 300 es
892
976
  precision highp float;
893
977
 
894
978
  in vec2 vUv;
@@ -969,7 +1053,7 @@ void main() {
969
1053
  lightCol = clamp(lightCol, 0.0, 1.0);
970
1054
 
971
1055
  fragColor = vec4(mix(lightCol, darkCol, darkAmt), 1.0);
972
- }`,Ce=P({name:"liquid-metal",fragmentShader:_e,defaultColors:["#18181b","#94a3b8","#38bdf8"],resolveUniforms(o){let e=B(o,"#0f172a");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg}}});var Ie=`#version 300 es
1056
+ }`,Bt=se({name:"liquid-metal",fragmentShader:fr,defaultColors:["#18181b","#94a3b8","#38bdf8"],resolveUniforms(i){let e=ne(i,"#0f172a");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg}}});var hr=`#version 300 es
973
1057
  precision highp float;
974
1058
 
975
1059
  in vec2 vUv;
@@ -1070,7 +1154,7 @@ void main() {
1070
1154
  dye = clamp(dye, vec2(0.0), vec2(1.0));
1071
1155
 
1072
1156
  fragColor = vec4(encodedVel, dye);
1073
- }`,Ve=`#version 300 es
1157
+ }`,mr=`#version 300 es
1074
1158
  precision highp float;
1075
1159
 
1076
1160
  in vec2 vUv;
@@ -1151,7 +1235,7 @@ void main() {
1151
1235
  } else {
1152
1236
  fragColor = vec4(opaqueCol, 1.0);
1153
1237
  }
1154
- }`,we=P({name:"fluid",fragmentShader:Ve,feedbackShader:Ie,feedbackFloat:!0,defaultColors:["#6366f1","#06b6d4","#f43f5e"],resolveUniforms(o){let e=B(o,"#060810");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg,uDissipation:typeof o.dissipation=="number"?o.dissipation:.975,uRadius:typeof o.radius=="number"?o.radius:.0045,uSwirl:typeof o.swirl=="number"?o.swirl:1.4}}});var Oe=`#version 300 es
1238
+ }`,Ut=se({name:"fluid",fragmentShader:mr,feedbackShader:hr,feedbackFloat:!0,defaultColors:["#6366f1","#06b6d4","#f43f5e"],resolveUniforms(i){let e=ne(i,"#060810");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg,uDissipation:typeof i.dissipation=="number"?i.dissipation:.975,uRadius:typeof i.radius=="number"?i.radius:.0045,uSwirl:typeof i.swirl=="number"?i.swirl:1.4}}});var pr=`#version 300 es
1155
1239
  precision highp float;
1156
1240
 
1157
1241
  in vec2 vUv;
@@ -1247,7 +1331,7 @@ void main() {
1247
1331
  vec2 encVel = clamp(vel * 0.5 + 0.5, vec2(0.02), vec2(0.98));
1248
1332
 
1249
1333
  fragColor = vec4(encVel, ink);
1250
- }`,He=`#version 300 es
1334
+ }`,vr=`#version 300 es
1251
1335
  precision highp float;
1252
1336
 
1253
1337
  in vec2 vUv;
@@ -1332,7 +1416,7 @@ void main() {
1332
1416
  lightCol = clamp(lightCol * lightVig + grain * 0.5, 0.0, 1.0);
1333
1417
 
1334
1418
  fragColor = vec4(mix(lightCol, darkCol, darkAmt), 1.0);
1335
- }`,Se=P({name:"ink",fragmentShader:He,feedbackShader:Oe,feedbackFloat:!0,defaultColors:["#1e1b4b","#0284c7","#e11d48"],resolveUniforms(o){let e=B(o,"#060810");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg,uDissipation:typeof o.dissipation=="number"?o.dissipation:.982,uRadius:typeof o.radius=="number"?o.radius:.004,uCurl:typeof o.curl=="number"?o.curl:1.75}}});var We=`#version 300 es
1419
+ }`,It=se({name:"ink",fragmentShader:vr,feedbackShader:pr,feedbackFloat:!0,defaultColors:["#1e1b4b","#0284c7","#e11d48"],resolveUniforms(i){let e=ne(i,"#060810");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg,uDissipation:typeof i.dissipation=="number"?i.dissipation:.982,uRadius:typeof i.radius=="number"?i.radius:.004,uCurl:typeof i.curl=="number"?i.curl:1.75}}});var gr=`#version 300 es
1336
1420
  precision highp float;
1337
1421
 
1338
1422
  in vec2 vUv;
@@ -1438,7 +1522,7 @@ void main() {
1438
1522
  vec2 encVel = clamp(vel * 0.5 + 0.5, vec2(0.02), vec2(0.98));
1439
1523
 
1440
1524
  fragColor = vec4(encVel, ink);
1441
- }`,Ge=`#version 300 es
1525
+ }`,br=`#version 300 es
1442
1526
  precision highp float;
1443
1527
 
1444
1528
  in vec2 vUv;
@@ -1518,4 +1602,559 @@ void main() {
1518
1602
  } else {
1519
1603
  fragColor = vec4(opaqueCol, 1.0);
1520
1604
  }
1521
- }`,Re=P({name:"aetheria",fragmentShader:Ge,feedbackShader:We,feedbackFloat:!0,defaultColors:["#1e3a5f","#2d3748","#0284c7"],resolveUniforms(o){let e=B(o,"#f5f3ee"),t=typeof o.lightMode=="number"||typeof o.lightMode=="boolean"||e.hasBgColor,i=xe(e.bgHex)?1:0,r=typeof o.lightMode=="number"?o.lightMode:typeof o.lightMode=="boolean"?o.lightMode?1:0:i;return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uHasExplicitLightMode:t?1:0,uTransparentBg:e.uTransparentBg,uLightMode:r,uAbsorptionGain:typeof o.absorptionGain=="number"?o.absorptionGain:1.45,uDissipation:typeof o.dissipation=="number"?o.dissipation:.978,uRadius:typeof o.radius=="number"?o.radius:.0032,uCurl:typeof o.curl=="number"?o.curl:1.85}}});var Le={name:"tilt-3d",mount(o,e){let t=typeof e.maxTilt=="number"?e.maxTilt:12,i=typeof e.scale=="number"?e.scale:1.03,r=typeof e.perspective=="number"?e.perspective:900,s=e.glare!==!1,a=e.respectReducedMotion??!0,n=o.style.transform,l=o.style.position,c=o.style.overflow,u=o.style.willChange,h=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(prefers-reduced-motion: reduce)"):null,f=a&&(h?.matches??!1);f||(o.style.willChange="transform");let d=null;s&&(getComputedStyle(o).position==="static"&&(o.style.position="relative"),o.style.overflow="hidden",d=document.createElement("div"),Object.assign(d.style,{position:"absolute",inset:"0",pointerEvents:"none",borderRadius:"inherit",opacity:"0",transition:"opacity 0.25s ease",zIndex:"2"}),o.appendChild(d));let m=0,p=0,v=1,g=0,b=0,S=1,U=50,W=50,E=!1,F=!1,M=null,w=null,k=!0,G=()=>{k=!0},Fe=()=>{let R=o.getBoundingClientRect();w={left:R.left,top:R.top,width:R.width,height:R.height},k=!1},oe=R=>{let _=a&&R.matches;f!==_&&(f=_,f?(m=0,p=0,v=1,g=0,b=0,S=1,E=!1,d&&(d.style.opacity="0"),o.style.transform=n,o.style.willChange=u):(o.style.willChange="transform",k=!0),M?.())},ae=()=>{k=!0},ne=R=>{if(F||f||((k||!w)&&Fe(),!w||w.width<=0||w.height<=0))return;let _=(R.clientX-w.left)/w.width,I=(R.clientY-w.top)/w.height;m=(.5-I)*t*2,p=(_-.5)*t*2,v=i,U=_*100,W=I*100,E=!0,d&&(d.style.opacity="1"),M?.()},le=()=>{f||(m=0,p=0,v=1,d&&(d.style.opacity="0"),(Math.abs(g)>.01||Math.abs(b)>.01||Math.abs(S-1)>.001)&&(E=!0,F||M?.()))},N=null;return typeof ResizeObserver<"u"&&(N=new ResizeObserver(G),N.observe(o)),h&&typeof h.addEventListener=="function"&&h.addEventListener("change",oe),o.addEventListener("pointerenter",ae,{passive:!0}),o.addEventListener("pointermove",ne,{passive:!0}),o.addEventListener("pointerleave",le,{passive:!0}),window.addEventListener("resize",G,{passive:!0}),window.addEventListener("scroll",G,{passive:!0,capture:!0}),{update(R,_){if(!E||F||f)return;let I=1-Math.exp(-12*_);if(g+=(m-g)*I,b+=(p-b)*I,S+=(v-S)*I,d&&(d.style.background=`radial-gradient(circle at ${U.toFixed(1)}% ${W.toFixed(1)}%, rgba(255,255,255,0.22), transparent 60%)`),Math.abs(m-g)<.02&&Math.abs(p-b)<.02&&Math.abs(v-S)<.001){g=m,b=p,S=v,E=!1,o.style.transform=v===1&&m===0&&p===0?n:`perspective(${r}px) rotateX(${g.toFixed(2)}deg) rotateY(${b.toFixed(2)}deg) scale3d(${S.toFixed(3)}, ${S.toFixed(3)}, 1)`;return}o.style.transform=`perspective(${r}px) rotateX(${g.toFixed(2)}deg) rotateY(${b.toFixed(2)}deg) scale3d(${S.toFixed(3)}, ${S.toFixed(3)}, 1)`},isIdle(){return!E||F||f},onWake(R){M=R},pause(){F=!0},resume(){F=!1,k=!0,E&&!f&&M?.()},destroy(){M=null,E=!1,w=null,N?.disconnect(),N=null,h&&typeof h.removeEventListener=="function"&&h.removeEventListener("change",oe),o.removeEventListener("pointerenter",ae),o.removeEventListener("pointermove",ne),o.removeEventListener("pointerleave",le),window.removeEventListener("resize",G),window.removeEventListener("scroll",G,!0),d?.remove(),o.style.transform=n,o.style.position=l,o.style.overflow=c,o.style.willChange=u}}}};var Ee={name:"magnetic",mount(o,e){let t=typeof e.strength=="number"?e.strength:.35,i=e.respectReducedMotion??!0,r=o.style.transform,s=o.style.willChange,a=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(prefers-reduced-motion: reduce)"):null,n=i&&(a?.matches??!1);n||(o.style.willChange="transform");let l=0,c=0,u=0,h=0,f=!1,d=!1,m=null,p=null,v=!0,g=()=>{v=!0},b=()=>{let M=o.getBoundingClientRect();p={left:M.left-u,top:M.top-h,width:M.width,height:M.height},v=!1},S=M=>{let w=i&&M.matches;n!==w&&(n=w,n?(l=0,c=0,u=0,h=0,f=!1,o.style.transform=r,o.style.willChange=s):(o.style.willChange="transform",v=!0),m?.())},U=()=>{v=!0},W=M=>{if(d||n||((v||!p)&&b(),!p||p.width<=0||p.height<=0))return;let w=p.left+p.width*.5,k=p.top+p.height*.5;l=(M.clientX-w)*t,c=(M.clientY-k)*t,f=!0,m?.()},E=()=>{n||(l=0,c=0,(Math.abs(u)>.01||Math.abs(h)>.01)&&(f=!0,d||m?.()))},F=null;return typeof ResizeObserver<"u"&&(F=new ResizeObserver(g),F.observe(o)),a&&typeof a.addEventListener=="function"&&a.addEventListener("change",S),o.addEventListener("pointerenter",U,{passive:!0}),o.addEventListener("pointermove",W,{passive:!0}),o.addEventListener("pointerleave",E,{passive:!0}),window.addEventListener("resize",g,{passive:!0}),window.addEventListener("scroll",g,{passive:!0,capture:!0}),{update(M,w){if(!f||d||n)return;let k=1-Math.exp(-10*w);if(u+=(l-u)*k,h+=(c-h)*k,Math.abs(l-u)<.05&&Math.abs(c-h)<.05){u=l,h=c,f=!1,o.style.transform=l===0&&c===0?r:`translate3d(${u.toFixed(2)}px, ${h.toFixed(2)}px, 0)`;return}o.style.transform=`translate3d(${u.toFixed(2)}px, ${h.toFixed(2)}px, 0)`},isIdle(){return!f||d||n},onWake(M){m=M},pause(){d=!0},resume(){d=!1,v=!0,f&&!n&&m?.()},destroy(){m=null,f=!1,p=null,F?.disconnect(),F=null,a&&typeof a.removeEventListener=="function"&&a.removeEventListener("change",S),o.removeEventListener("pointerenter",U),o.removeEventListener("pointermove",W),o.removeEventListener("pointerleave",E),window.removeEventListener("resize",g),window.removeEventListener("scroll",g,!0),o.style.transform=r,o.style.willChange=s}}}};K.register(Me).register(Ce).register(we).register(Se).register(Re).register(Le).register(Ee);var At=K;typeof window<"u"&&(window.FluxFX=K);export{Y as FluxEngine,At as FluxFX,L as WebGLQuad,P as createWebGLEffect};
1605
+ }`,Ot=se({name:"aetheria",fragmentShader:br,feedbackShader:gr,feedbackFloat:!0,defaultColors:["#1e3a5f","#2d3748","#0284c7"],resolveUniforms(i){let e=ne(i,"#f5f3ee"),t=typeof i.lightMode=="number"||typeof i.lightMode=="boolean"||e.hasBgColor,o=Pt(e.bgHex)?1:0,r=typeof i.lightMode=="number"?i.lightMode:typeof i.lightMode=="boolean"?i.lightMode?1:0:o;return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uHasExplicitLightMode:t?1:0,uTransparentBg:e.uTransparentBg,uLightMode:r,uAbsorptionGain:typeof i.absorptionGain=="number"?i.absorptionGain:1.45,uDissipation:typeof i.dissipation=="number"?i.dissipation:.978,uRadius:typeof i.radius=="number"?i.radius:.0032,uCurl:typeof i.curl=="number"?i.curl:1.85}}});var yr=`#version 300 es
1606
+ precision highp float;
1607
+
1608
+ in vec2 vUv;
1609
+ out vec4 fragColor;
1610
+
1611
+ uniform float uTime;
1612
+ uniform vec2 uResolution;
1613
+ uniform vec2 uMouse;
1614
+ uniform float uMouseActive;
1615
+ uniform float uMouseDown;
1616
+ uniform float uScroll;
1617
+ uniform vec3 uBgColor;
1618
+ uniform float uHasBgColor;
1619
+ uniform float uTransparentBg;
1620
+ uniform float uTheme;
1621
+ uniform float uQuality;
1622
+ uniform vec3 uColor1;
1623
+ uniform vec3 uColor2;
1624
+ uniform vec3 uColor3;
1625
+ uniform float uShape;
1626
+ uniform float uDepth;
1627
+ uniform float uGloss;
1628
+ uniform float uDistortion;
1629
+
1630
+ mat2 rot2(float a) {
1631
+ float c = cos(a);
1632
+ float s = sin(a);
1633
+ return mat2(c, -s, s, c);
1634
+ }
1635
+
1636
+ float smin(float a, float b, float k) {
1637
+ float h = clamp(0.5 + 0.5 * (b - a) / max(k, 0.0001), 0.0, 1.0);
1638
+ return mix(b, a, h) - k * h * (1.0 - h);
1639
+ }
1640
+
1641
+ float sdSphere(vec3 p, float r) {
1642
+ return length(p) - r;
1643
+ }
1644
+
1645
+ float sdTorus(vec3 p, vec2 t) {
1646
+ vec2 q = vec2(length(p.xz) - t.x, p.y);
1647
+ return length(q) - t.y;
1648
+ }
1649
+
1650
+ float sdOctahedron(vec3 p, float s) {
1651
+ p = abs(p);
1652
+ float m = p.x + p.y + p.z - s;
1653
+ vec3 q;
1654
+ if (3.0 * p.x < m) q = p.xyz;
1655
+ else if (3.0 * p.y < m) q = p.yzx;
1656
+ else if (3.0 * p.z < m) q = p.zxy;
1657
+ else return m * 0.57735027;
1658
+ float k = clamp(0.5 * (q.z - q.y + s), 0.0, s);
1659
+ return length(vec3(q.x, q.y - s + k, q.z - k));
1660
+ }
1661
+
1662
+ float mapScene(vec3 p, float t) {
1663
+ vec3 q = p;
1664
+ float twist = uDistortion * (0.65 + 0.35 * sin(t * 0.7));
1665
+ q.xz *= rot2(t * 0.42 + q.y * twist + uScroll * 1.5);
1666
+ q.yz *= rot2(t * 0.31);
1667
+
1668
+ float dMain;
1669
+ if (uShape < 0.5) {
1670
+ // Prism: faceted crystal + smooth-blended core sphere
1671
+ float oct = sdOctahedron(q, 0.76) - 0.05;
1672
+ float core = sdSphere(q, 0.48);
1673
+ dMain = smin(oct, core, 0.18);
1674
+ } else if (uShape < 1.5) {
1675
+ // Torus: twisted orbital ring + inner core
1676
+ float tor = sdTorus(q, vec2(0.62, 0.23));
1677
+ float core = sdSphere(q * 1.15, 0.34);
1678
+ dMain = smin(tor, core, 0.24);
1679
+ } else {
1680
+ // Orb: breathing sculpted sphere
1681
+ float disp = sin(q.x * 4.2 + t * 1.4) * sin(q.y * 4.2 - t * 1.1) * sin(q.z * 4.2 + t * 0.9);
1682
+ dMain = sdSphere(q, 0.62) + disp * (0.04 + uDistortion * 0.12);
1683
+ }
1684
+
1685
+ // Orbiting 3D satellites smoothly fusing into the main form
1686
+ vec3 orb1 = vec3(cos(t * 0.95) * 0.72, sin(t * 1.2) * 0.36, sin(t * 0.95) * 0.72);
1687
+ vec3 orb2 = vec3(sin(t * 0.75 + 2.1) * 0.68, cos(t * 1.05) * 0.42, cos(t * 0.75 + 2.1) * 0.68);
1688
+ float dOrbs = smin(sdSphere(p - orb1, 0.17), sdSphere(p - orb2, 0.14), 0.25);
1689
+
1690
+ float d = smin(dMain, dOrbs, 0.28);
1691
+
1692
+ if (uDistortion > 0.01 && uShape < 1.5) {
1693
+ float ripple = sin(q.x * 5.0 + t * 1.5) * sin(q.y * 5.0 - t * 1.2) * sin(q.z * 5.0 + t);
1694
+ d += ripple * uDistortion * 0.055;
1695
+ }
1696
+
1697
+ return d;
1698
+ }
1699
+
1700
+ vec3 calcNormal(vec3 p, float t) {
1701
+ vec2 e = vec2(0.0025, -0.0025);
1702
+ return normalize(
1703
+ e.xyy * mapScene(p + e.xyy, t) +
1704
+ e.yyx * mapScene(p + e.yyx, t) +
1705
+ e.yxy * mapScene(p + e.yxy, t) +
1706
+ e.xxx * mapScene(p + e.xxx, t)
1707
+ );
1708
+ }
1709
+
1710
+ float calcAO(vec3 pos, vec3 nor, float t) {
1711
+ int taps = uQuality < 0.25 ? 2 : (uQuality < 0.75 ? 3 : 4);
1712
+ float occ = 0.0;
1713
+ float sca = 1.0;
1714
+ for (int i = 0; i < 4; i++) {
1715
+ if (i >= taps) break;
1716
+ float h = 0.025 + 0.11 * float(i) / 3.0;
1717
+ float d = mapScene(pos + h * nor, t);
1718
+ occ += (h - d) * sca;
1719
+ sca *= 0.88;
1720
+ }
1721
+ return clamp(1.0 - 2.2 * occ, 0.0, 1.0);
1722
+ }
1723
+
1724
+ void main() {
1725
+ float aspect = uResolution.x / max(uResolution.y, 1.0);
1726
+ vec2 uv = (vUv - 0.5) * vec2(aspect, 1.0) * 2.0;
1727
+
1728
+ float t = uTime * 0.85;
1729
+ float camDist = 2.75 / clamp(uDepth, 0.45, 2.2);
1730
+ camDist -= uMouseDown * 0.22;
1731
+
1732
+ // Interactive 3D camera orbit from pointer position
1733
+ vec2 mOffset = (uMouse - 0.5) * 1.55 * uMouseActive;
1734
+ vec3 ro = vec3(0.0, 0.08 * sin(t * 0.4), camDist);
1735
+ ro.xz *= rot2(-mOffset.x + sin(t * 0.22) * 0.18);
1736
+ ro.yz *= rot2(mOffset.y * 0.65);
1737
+
1738
+ vec3 ta = vec3(0.0, 0.0, 0.0);
1739
+ vec3 ww = normalize(ta - ro);
1740
+ vec3 uu = normalize(cross(ww, vec3(0.0, 1.0, 0.0)));
1741
+ vec3 vv = cross(uu, ww);
1742
+ vec3 rd = normalize(uv.x * uu + uv.y * vv + 1.55 * ww);
1743
+
1744
+ int maxSteps = uQuality < 0.25 ? 32 : (uQuality < 0.75 ? 48 : 72);
1745
+ float maxDist = 7.0;
1746
+ float dTotal = 0.0;
1747
+ float minDist = 1e5;
1748
+ bool hit = false;
1749
+
1750
+ for (int i = 0; i < 72; i++) {
1751
+ if (i >= maxSteps) break;
1752
+ vec3 p = ro + rd * dTotal;
1753
+ float d = mapScene(p, t);
1754
+ minDist = min(minDist, max(d, 0.0));
1755
+ if (d < 0.0018) {
1756
+ hit = true;
1757
+ break;
1758
+ }
1759
+ if (dTotal > maxDist) break;
1760
+ dTotal += d * 0.85;
1761
+ }
1762
+
1763
+ float darkAmt = clamp(uTheme, 0.0, 1.0);
1764
+ vec3 baseDark = uHasBgColor > 0.5 ? uBgColor : vec3(0.03, 0.04, 0.085);
1765
+ vec3 baseLight = uHasBgColor > 0.5 ? uBgColor : vec3(0.955, 0.95, 0.935);
1766
+ vec3 bgCol = mix(baseLight, baseDark, darkAmt);
1767
+
1768
+ // Volumetric aura around the 3D object
1769
+ float aura = exp(-minDist * 4.5);
1770
+ vec3 auraCol = mix(uColor1, uColor2, 0.5 + 0.5 * sin(uv.x + uv.y + t * 0.5));
1771
+ auraCol = mix(auraCol, uColor3, aura * 0.45);
1772
+
1773
+ if (!hit) {
1774
+ if (uTransparentBg > 0.5) {
1775
+ float alpha = clamp(aura * 0.52, 0.0, 1.0);
1776
+ fragColor = vec4(auraCol * alpha, alpha);
1777
+ return;
1778
+ }
1779
+ vec3 sky = bgCol + auraCol * aura * mix(0.18, 0.36, darkAmt);
1780
+ float vig = 1.0 - dot(vUv - 0.5, vUv - 0.5) * mix(0.14, 0.65, darkAmt);
1781
+ fragColor = vec4(clamp(sky * vig, 0.0, 1.0), 1.0);
1782
+ return;
1783
+ }
1784
+
1785
+ vec3 pos = ro + rd * dTotal;
1786
+ vec3 nor = calcNormal(pos, t);
1787
+ float ao = calcAO(pos, nor, t);
1788
+ vec3 viewDir = -rd;
1789
+
1790
+ // 3-point 3D studio lighting
1791
+ vec3 keyDir = normalize(vec3(0.65, 0.8, 0.6));
1792
+ vec3 fillDir = normalize(vec3(-0.75, -0.35, 0.45));
1793
+ vec3 rimDir = normalize(vec3(-0.2, 0.5, -0.85));
1794
+
1795
+ float keyDiff = max(dot(nor, keyDir), 0.0);
1796
+ float fillDiff = max(dot(nor, fillDir), 0.0);
1797
+ float rimDiff = max(dot(nor, rimDir), 0.0);
1798
+
1799
+ vec3 halfKey = normalize(keyDir + viewDir);
1800
+ vec3 halfRim = normalize(rimDir + viewDir);
1801
+ float glossPow = mix(14.0, 64.0, clamp(uGloss * 0.6, 0.0, 1.0));
1802
+ float specKey = pow(max(dot(nor, halfKey), 0.0), glossPow) * uGloss;
1803
+ float specRim = pow(max(dot(nor, halfRim), 0.0), glossPow * 0.7) * uGloss;
1804
+
1805
+ float fresnel = pow(1.0 - max(dot(nor, viewDir), 0.0), 3.0);
1806
+ float irid = 0.5 + 0.5 * sin(dot(nor, viewDir) * 5.5 + pos.y * 2.5 + t * 0.8);
1807
+
1808
+ vec3 baseAlbedo = mix(uColor1, uColor2, 0.5 + 0.5 * nor.y);
1809
+ baseAlbedo = mix(baseAlbedo, uColor3, fresnel * 0.65 + irid * 0.25);
1810
+
1811
+ vec3 litCol = baseAlbedo * (0.24 + keyDiff * 0.78 + fillDiff * 0.32) * ao;
1812
+ litCol += mix(vec3(1.0), uColor3, 0.35) * specKey * 0.95;
1813
+ litCol += uColor2 * rimDiff * 0.42 + uColor3 * specRim * 0.45;
1814
+ litCol += mix(uColor2, uColor3, irid) * fresnel * 0.55;
1815
+
1816
+ // Depth fog blend for smooth silhouette edges
1817
+ float fog = smoothstep(1.2, 5.2, dTotal);
1818
+ if (uTransparentBg > 0.5) {
1819
+ vec3 col = clamp(mix(litCol, auraCol, fog * 0.35), 0.0, 1.0);
1820
+ float alpha = clamp(0.96 - fog * 0.25 + fresnel * 0.15, 0.0, 1.0);
1821
+ fragColor = vec4(col * alpha, alpha);
1822
+ return;
1823
+ }
1824
+
1825
+ vec3 finalCol = mix(litCol, bgCol + auraCol * 0.25, fog * 0.45);
1826
+ float vig = 1.0 - dot(vUv - 0.5, vUv - 0.5) * mix(0.12, 0.55, darkAmt);
1827
+ fragColor = vec4(clamp(finalCol * vig, 0.0, 1.0), 1.0);
1828
+ }`;function xr(i){if(typeof i=="number")return i;let e=String(i??"prism").trim().toLowerCase();return e==="torus"?1:e==="orb"||e==="sphere"?2:0}var _t=se({name:"prism-3d",fragmentShader:yr,defaultColors:["#6366f1","#06b6d4","#f472b6"],resolveUniforms(i){let e=ne(i,"#070a16");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg,uShape:xr(i.shape),uDepth:typeof i.depth=="number"?i.depth:1,uGloss:typeof i.gloss=="number"?i.gloss:1,uDistortion:typeof i.distortion=="number"?i.distortion:.35}}});var Tr=`#version 300 es
1829
+ precision highp float;
1830
+
1831
+ in vec2 vUv;
1832
+ out vec4 fragColor;
1833
+
1834
+ uniform sampler2D uPrevFrame;
1835
+ uniform float uTime;
1836
+ uniform float uDelta;
1837
+ uniform vec2 uResolution;
1838
+ uniform vec2 uMouse;
1839
+ uniform vec2 uMouseVel;
1840
+ uniform float uMouseDown;
1841
+ uniform float uMouseActive;
1842
+ uniform float uSpeed;
1843
+ uniform float uDissipation;
1844
+ uniform float uRadius;
1845
+ uniform float uAmbient;
1846
+ uniform float uClickReveal;
1847
+
1848
+ float hash21(vec2 p) {
1849
+ p = fract(p * vec2(123.34, 456.21));
1850
+ p += dot(p, p + 45.32);
1851
+ return fract(p.x * p.y);
1852
+ }
1853
+
1854
+ float valueNoise(vec2 p) {
1855
+ vec2 i = floor(p);
1856
+ vec2 f = fract(p);
1857
+ vec2 u = f * f * (3.0 - 2.0 * f);
1858
+ float a = hash21(i);
1859
+ float b = hash21(i + vec2(1.0, 0.0));
1860
+ float c = hash21(i + vec2(0.0, 1.0));
1861
+ float d = hash21(i + vec2(1.0, 1.0));
1862
+ return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
1863
+ }
1864
+
1865
+ float sdSegment(vec2 p, vec2 a, vec2 b) {
1866
+ vec2 pa = p - a;
1867
+ vec2 ba = b - a;
1868
+ float h = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-6), 0.0, 1.0);
1869
+ return length(pa - ba * h);
1870
+ }
1871
+
1872
+ void main() {
1873
+ vec2 texel = 1.0 / max(uResolution, vec2(1.0));
1874
+ float dt = clamp(uDelta, 0.004, 0.033);
1875
+ float aspect = uResolution.x / max(uResolution.y, 1.0);
1876
+ float speed = clamp(uSpeed, 0.25, 3.0);
1877
+
1878
+ vec4 c = texture(uPrevFrame, vUv);
1879
+ vec4 l = texture(uPrevFrame, vUv - vec2(texel.x, 0.0));
1880
+ vec4 r = texture(uPrevFrame, vUv + vec2(texel.x, 0.0));
1881
+ vec4 d = texture(uPrevFrame, vUv - vec2(0.0, texel.y));
1882
+ vec4 u = texture(uPrevFrame, vUv + vec2(0.0, texel.y));
1883
+
1884
+ float blurMask = (l.r + r.r + d.r + u.r) * 0.25;
1885
+ float hold = pow(clamp(uDissipation, 0.85, 0.9995), dt * 60.0 * speed);
1886
+
1887
+ float n = valueNoise(vUv * 14.0 + vec2(uTime * 0.25, -uTime * 0.18));
1888
+ float prevMask = mix(c.r, blurMask, 0.14) * hold;
1889
+ if (uDissipation < 0.9985) {
1890
+ prevMask = max(0.0, prevMask - dt * 0.015 * (1.0 + (1.0 - n) * 0.6));
1891
+ }
1892
+
1893
+ float brushVal = 0.0;
1894
+ vec2 p = vUv * vec2(aspect, 1.0);
1895
+ float baseRad = clamp(uRadius, 0.02, 0.65);
1896
+
1897
+ if (uMouseActive > 0.01) {
1898
+ vec2 curM = uMouse * vec2(aspect, 1.0);
1899
+ vec2 prevM = clamp(uMouse - uMouseVel * dt, vec2(0.0), vec2(1.0)) * vec2(aspect, 1.0);
1900
+ float dist = sdSegment(p, prevM, curM);
1901
+
1902
+ float velBoost = 1.0 + min(length(uMouseVel) * 0.12, 0.45);
1903
+ float clickBoost = (uClickReveal > 0.5 && uMouseDown > 0.5) ? 1.5 : 1.0;
1904
+ float rad = baseRad * velBoost * clickBoost;
1905
+
1906
+ float organicDist = dist + (n - 0.5) * rad * 0.28;
1907
+ float stroke = 1.0 - smoothstep(rad * 0.24, rad, organicDist);
1908
+ brushVal = max(brushVal, stroke * clamp(uMouseActive, 0.0, 1.0));
1909
+ }
1910
+
1911
+ if (uAmbient > 0.5 && uMouseActive < 0.25) {
1912
+ float t = uTime * 0.55 * speed;
1913
+ vec2 ambCenter = vec2(
1914
+ 0.5 + 0.13 * sin(t) + 0.04 * cos(t * 2.1),
1915
+ 0.54 + 0.11 * cos(t * 0.82)
1916
+ ) * vec2(aspect, 1.0);
1917
+ float ambDist = length(p - ambCenter);
1918
+ float ambRad = baseRad * 0.88;
1919
+ float ambStroke = 1.0 - smoothstep(ambRad * 0.25, ambRad, ambDist + (n - 0.5) * ambRad * 0.28);
1920
+ brushVal = max(brushVal, ambStroke * 0.82 * (1.0 - smoothstep(0.0, 0.25, uMouseActive)));
1921
+ }
1922
+
1923
+ float nextMask = clamp(max(prevMask, brushVal), 0.0, 1.0);
1924
+ float freshEdge = clamp(mix(c.g * 0.88, brushVal, 0.45), 0.0, 1.0);
1925
+
1926
+ fragColor = vec4(nextMask, freshEdge, 0.0, 1.0);
1927
+ }`,Mr=`#version 300 es
1928
+ precision highp float;
1929
+
1930
+ in vec2 vUv;
1931
+ out vec4 fragColor;
1932
+
1933
+ uniform sampler2D uFeedback;
1934
+ uniform sampler2D uBaseTex;
1935
+ uniform sampler2D uRevealTex;
1936
+ uniform vec2 uBaseTexSize;
1937
+ uniform vec2 uRevealTexSize;
1938
+ uniform float uBaseTexReady;
1939
+ uniform float uRevealTexReady;
1940
+
1941
+ uniform float uTime;
1942
+ uniform vec2 uResolution;
1943
+ uniform vec3 uBgColor;
1944
+ uniform float uHasBgColor;
1945
+ uniform float uTransparentBg;
1946
+ uniform vec3 uColor1;
1947
+ uniform vec3 uColor2;
1948
+
1949
+ uniform float uFit;
1950
+ uniform vec2 uPosition;
1951
+ uniform float uSoftness;
1952
+ uniform float uEdgeNoise;
1953
+ uniform float uEdgeGlow;
1954
+
1955
+ float hash21(vec2 p) {
1956
+ p = fract(p * vec2(127.1, 311.7));
1957
+ p += dot(p, p + 34.23);
1958
+ return fract(p.x * p.y);
1959
+ }
1960
+
1961
+ float valueNoise(vec2 p) {
1962
+ vec2 i = floor(p);
1963
+ vec2 f = fract(p);
1964
+ vec2 u = f * f * (3.0 - 2.0 * f);
1965
+ return mix(
1966
+ mix(hash21(i), hash21(i + vec2(1.0, 0.0)), u.x),
1967
+ mix(hash21(i + vec2(0.0, 1.0)), hash21(i + vec2(1.0, 1.0)), u.x),
1968
+ u.y
1969
+ );
1970
+ }
1971
+
1972
+ float fbm(vec2 p) {
1973
+ float v = 0.0;
1974
+ float a = 0.5;
1975
+ mat2 rot = mat2(0.8, 0.6, -0.6, 0.8);
1976
+ for (int i = 0; i < 4; i++) {
1977
+ v += a * valueNoise(p);
1978
+ p = rot * p * 2.07 + vec2(17.1, 31.7);
1979
+ a *= 0.5;
1980
+ }
1981
+ return v;
1982
+ }
1983
+
1984
+ vec2 computeFitUv(vec2 uv, vec2 res, vec2 texSize, float fitMode, vec2 align) {
1985
+ float canvasAspect = res.x / max(res.y, 1.0);
1986
+ float texAspect = texSize.x / max(texSize.y, 1.0);
1987
+ float r = canvasAspect / max(texAspect, 0.0001);
1988
+
1989
+ vec2 scale = vec2(1.0);
1990
+ if (fitMode < 0.5) {
1991
+ // cover
1992
+ if (r > 1.0) {
1993
+ scale = vec2(1.0, 1.0 / r);
1994
+ } else {
1995
+ scale = vec2(r, 1.0);
1996
+ }
1997
+ } else {
1998
+ // contain
1999
+ if (r > 1.0) {
2000
+ scale = vec2(r, 1.0);
2001
+ } else {
2002
+ scale = vec2(1.0, 1.0 / r);
2003
+ }
2004
+ }
2005
+
2006
+ return (uv - align) * scale + align;
2007
+ }
2008
+
2009
+ void main() {
2010
+ if (uBaseTexReady < 0.5) {
2011
+ if (uHasBgColor > 0.5 && uTransparentBg < 0.5) {
2012
+ fragColor = vec4(uBgColor, 1.0);
2013
+ } else {
2014
+ fragColor = vec4(0.0);
2015
+ }
2016
+ return;
2017
+ }
2018
+
2019
+ vec2 baseUv = computeFitUv(vUv, uResolution, max(uBaseTexSize, vec2(1.0)), uFit, uPosition);
2020
+ bool inBase = baseUv.x >= 0.0 && baseUv.x <= 1.0 && baseUv.y >= 0.0 && baseUv.y <= 1.0;
2021
+
2022
+ if (!inBase) {
2023
+ if (uHasBgColor > 0.5 && uTransparentBg < 0.5) {
2024
+ fragColor = vec4(uBgColor, 1.0);
2025
+ } else {
2026
+ fragColor = vec4(0.0);
2027
+ }
2028
+ return;
2029
+ }
2030
+
2031
+ vec2 baseSampleUv = vec2(baseUv.x, 1.0 - baseUv.y);
2032
+ vec4 baseCol = texture(uBaseTex, baseSampleUv);
2033
+
2034
+ if (uRevealTexReady < 0.5) {
2035
+ if (uHasBgColor > 0.5 && uTransparentBg < 0.5) {
2036
+ fragColor = vec4(mix(uBgColor, baseCol.rgb, baseCol.a), 1.0);
2037
+ } else {
2038
+ fragColor = vec4(baseCol.rgb * baseCol.a, baseCol.a);
2039
+ }
2040
+ return;
2041
+ }
2042
+
2043
+ vec2 fboTexel = 1.0 / max(vec2(textureSize(uFeedback, 0)), vec2(1.0));
2044
+ float m = texture(uFeedback, vUv).r;
2045
+ float mL = texture(uFeedback, vUv - vec2(fboTexel.x * 2.0, 0.0)).r;
2046
+ float mR = texture(uFeedback, vUv + vec2(fboTexel.x * 2.0, 0.0)).r;
2047
+ float mD = texture(uFeedback, vUv - vec2(0.0, fboTexel.y * 2.0)).r;
2048
+ float mU = texture(uFeedback, vUv + vec2(0.0, fboTexel.y * 2.0)).r;
2049
+ vec2 grad = vec2(mR - mL, mU - mD);
2050
+
2051
+ float aspect = uResolution.x / max(uResolution.y, 1.0);
2052
+ vec2 noiseCoord = vUv * vec2(aspect, 1.0) * 16.0;
2053
+ float nMacro = fbm(noiseCoord + vec2(uTime * 0.08, -uTime * 0.06));
2054
+ float nGrain = hash21(floor(vUv * uResolution * 0.55) + fract(uTime * 0.25));
2055
+ float dissolveNoise = mix(nMacro, nGrain, 0.24);
2056
+
2057
+ // Zero noise outside touched mask (m=0) or inside solid core (m=1)
2058
+ float edgeEnvelope = sin(clamp(m, 0.0, 1.0) * 3.14159265);
2059
+ float perturbed = m + (dissolveNoise - 0.5) * clamp(uEdgeNoise, 0.0, 0.9) * edgeEnvelope;
2060
+ float soft = clamp(uSoftness, 0.015, 0.49);
2061
+ float revealMask = smoothstep(0.5 - soft, 0.5 + soft, perturbed) * smoothstep(0.0, 0.02, m);
2062
+
2063
+ vec2 revUv = computeFitUv(vUv, uResolution, max(uRevealTexSize, vec2(1.0)), uFit, uPosition);
2064
+ vec2 revSampleUv = clamp(vec2(revUv.x, 1.0 - revUv.y) + grad * 0.0045 * edgeEnvelope, 0.0, 1.0);
2065
+ vec4 revCol = texture(uRevealTex, revSampleUv);
2066
+
2067
+ vec3 col = mix(baseCol.rgb, revCol.rgb, revealMask);
2068
+ float outAlpha = mix(baseCol.a, revCol.a, revealMask);
2069
+
2070
+ float edgeBand = 4.0 * revealMask * (1.0 - revealMask);
2071
+ vec3 shimmer = mix(uColor1, uColor2, 0.5 + 0.5 * nMacro);
2072
+ col = clamp(col + shimmer * edgeBand * clamp(uEdgeGlow, 0.0, 1.5) * 0.5, 0.0, 1.0);
2073
+
2074
+ if (uHasBgColor > 0.5 && uTransparentBg < 0.5) {
2075
+ fragColor = vec4(mix(uBgColor, col, outAlpha), 1.0);
2076
+ return;
2077
+ }
2078
+
2079
+ fragColor = vec4(col * outAlpha, outAlpha);
2080
+ }`;function wr(i){return String(i??"cover").trim().toLowerCase()==="contain"?1:0}function Cr(i){let e=String(i??"center").trim().toLowerCase();return e==="bottom"?[.5,0]:e==="top"?[.5,1]:[.5,.5]}function Vt(i){return typeof i=="string"?i.trim():""}function Ht(i,e){if(typeof i=="boolean")return i?1:0;if(typeof i=="string"){let t=i.trim().toLowerCase();if(t==="true")return 1;if(t==="false")return 0}return typeof i=="number"?i>.5?1:0:e?1:0}var Wt=se({name:"brush-reveal",fragmentShader:Mr,feedbackShader:Tr,feedbackFloat:!0,defaultColors:["#ff6b2b","#ffd166","#ffffff"],resolveTextures(i){return{uBaseTex:Vt(i.baseImage??i.image),uRevealTex:Vt(i.revealImage)}},resolveUniforms(i){let e=ne(i,"#000000");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg,uRadius:typeof i.radius=="number"?i.radius:.13,uSoftness:typeof i.softness=="number"?i.softness:.22,uEdgeNoise:typeof i.edgeNoise=="number"?i.edgeNoise:.38,uEdgeGlow:typeof i.edgeGlow=="number"?i.edgeGlow:.24,uDissipation:typeof i.dissipation=="number"?i.dissipation:.985,uFit:wr(i.fit),uPosition:Cr(i.position),uAmbient:Ht(i.ambient,!1),uClickReveal:Ht(i.clickReveal,!0)}}});var Sr=`#version 300 es
2081
+ precision highp float;
2082
+
2083
+ in vec2 vUv;
2084
+ out vec4 fragColor;
2085
+
2086
+ uniform float uTime;
2087
+ uniform vec2 uResolution;
2088
+ uniform vec2 uMouse;
2089
+ uniform float uMouseActive;
2090
+ uniform float uScroll;
2091
+ uniform vec3 uBgColor;
2092
+ uniform float uHasBgColor;
2093
+ uniform float uTransparentBg;
2094
+ uniform float uTheme;
2095
+ uniform vec3 uColor1;
2096
+ uniform vec3 uColor2;
2097
+ uniform vec3 uColor3;
2098
+ uniform float uSpotRadius;
2099
+ uniform float uSpotIntensity;
2100
+ uniform vec2 uSpotPosition;
2101
+
2102
+ float hash21(vec2 p) {
2103
+ p = fract(p * vec2(127.1, 311.7));
2104
+ p += dot(p, p + 34.23);
2105
+ return fract(p.x * p.y);
2106
+ }
2107
+
2108
+ void main() {
2109
+ float aspect = uResolution.x / max(uResolution.y, 1.0);
2110
+ float darkAmt = clamp(uTheme, 0.0, 1.0);
2111
+
2112
+ // Base cyclorama studio tone: uses bgColor if set, otherwise uColor1 tinted studio backdrop
2113
+ vec3 defaultDark = mix(vec3(0.055, 0.06, 0.075), uColor1, 0.35);
2114
+ vec3 defaultLight = mix(vec3(0.945, 0.935, 0.92), uColor1, 0.65);
2115
+ vec3 baseCol = uHasBgColor > 0.5 ? uBgColor : mix(defaultLight, defaultDark, darkAmt);
2116
+
2117
+ // Smooth cursor-reactive studio spotlight tracking (returns to uSpotPosition when pointer leaves)
2118
+ vec2 baseOrigin = clamp(uSpotPosition + vec2(0.0, -uScroll * 0.04), vec2(0.08), vec2(0.92));
2119
+ vec2 spotOrigin = mix(baseOrigin, clamp(uMouse, vec2(0.05), vec2(0.95)), clamp(uMouseActive, 0.0, 1.0));
2120
+
2121
+ vec2 delta = (vUv - spotOrigin) * vec2(aspect, 1.0);
2122
+ float dist = length(delta);
2123
+
2124
+ float rad = clamp(uSpotRadius, 0.18, 1.45);
2125
+ float coreGlow = exp(-(dist * dist) / (rad * rad * 0.42));
2126
+ float wideHalo = exp(-(dist * dist) / (rad * rad * 1.65));
2127
+
2128
+ // Subtle vertical studio floor gradient & overhead rim wash
2129
+ float floorGrad = smoothstep(0.0, 0.36, vUv.y);
2130
+ float topWash = smoothstep(0.35, 1.0, vUv.y) * 0.12;
2131
+ float breathe = 0.96 + 0.04 * sin(uTime * 0.75);
2132
+
2133
+ vec3 spotColor = mix(uColor2, uColor3, coreGlow * 0.65);
2134
+ float intensity = clamp(uSpotIntensity, 0.0, 2.5) * breathe;
2135
+
2136
+ vec3 col = baseCol;
2137
+ col = mix(col, spotColor, wideHalo * 0.42 * intensity);
2138
+ col += spotColor * coreGlow * mix(0.28, 0.52, darkAmt) * intensity;
2139
+ col += uColor2 * topWash * intensity * 0.35;
2140
+
2141
+ // Soft studio cyclorama floor shadow near bottom
2142
+ col *= mix(0.84, 1.0, floorGrad);
2143
+
2144
+ // Subtle edge vignette for depth
2145
+ vec2 vigUv = vUv - 0.5;
2146
+ float vig = 1.0 - dot(vigUv, vigUv) * mix(0.16, 0.48, darkAmt);
2147
+ col *= vig;
2148
+
2149
+ // Fine dithering grain to eliminate 8-bit gradient banding
2150
+ float grain = (hash21(gl_FragCoord.xy + fract(uTime * 0.17)) - 0.5) * 0.014;
2151
+ col = clamp(col + vec3(grain), 0.0, 1.0);
2152
+
2153
+ if (uTransparentBg > 0.5) {
2154
+ float alpha = clamp((wideHalo * 0.45 + coreGlow * 0.55) * intensity, 0.0, 1.0);
2155
+ fragColor = vec4(spotColor * alpha, alpha);
2156
+ return;
2157
+ }
2158
+
2159
+ fragColor = vec4(col, 1.0);
2160
+ }`;function Er(i){if(Array.isArray(i)&&i.length>=2){let t=Number(i[0]),o=Number(i[1]);if(!Number.isNaN(t)&&!Number.isNaN(o))return[t,o]}let e=String(i??"center").trim().toLowerCase();return e==="left"?[.34,.52]:e==="right"?[.66,.52]:[.5,.52]}var zt=se({name:"spotlight",fragmentShader:Sr,defaultColors:["#14161a","#4b5563","#f8fafc"],resolveUniforms(i){let e=ne(i,"#121316");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg,uSpotRadius:typeof i.spotRadius=="number"?i.spotRadius:.62,uSpotIntensity:typeof i.spotIntensity=="number"?i.spotIntensity:1,uSpotPosition:Er(i.spotPosition)}}});var Nt={name:"tilt-3d",mount(i,e){let t=typeof e.maxTilt=="number"?e.maxTilt:12,o=typeof e.scale=="number"?e.scale:1.03,r=typeof e.perspective=="number"?e.perspective:900,s=e.glare!==!1,n=e.respectReducedMotion??!0,l=i.style.transform,a=i.style.position,d=i.style.overflow,u=i.style.willChange,f=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(prefers-reduced-motion: reduce)"):null,h=n&&(f?.matches??!1);h||(i.style.willChange="transform");let p=null;s&&(getComputedStyle(i).position==="static"&&(i.style.position="relative"),i.style.overflow="hidden",p=document.createElement("div"),Object.assign(p.style,{position:"absolute",inset:"0",pointerEvents:"none",borderRadius:"inherit",opacity:"0",transition:"opacity 0.25s ease",zIndex:"2"}),i.appendChild(p));let v=0,b=0,w=1,k=0,E=0,R=1,F=50,O=50,V=!1,B=!1,P=null,T=null,A=!0,U=()=>{A=!0},G=()=>{let c=i.getBoundingClientRect();T={left:c.left,top:c.top,width:c.width,height:c.height},A=!1},H=c=>{let m=n&&c.matches;h!==m&&(h=m,h?(v=0,b=0,w=1,k=0,E=0,R=1,V=!1,p&&(p.style.opacity="0"),i.style.transform=l,i.style.willChange=u):(i.style.willChange="transform",A=!0),P?.())},q=()=>{A=!0},K=c=>{if(B||h||((A||!T)&&G(),!T||T.width<=0||T.height<=0))return;let m=(c.clientX-T.left)/T.width,g=(c.clientY-T.top)/T.height;v=(.5-g)*t*2,b=(m-.5)*t*2,w=o,F=m*100,O=g*100,V=!0,p&&(p.style.opacity="1"),P?.()},x=()=>{h||(v=0,b=0,w=1,p&&(p.style.opacity="0"),(Math.abs(k)>.01||Math.abs(E)>.01||Math.abs(R-1)>.001)&&(V=!0,B||P?.()))},S=null;return typeof ResizeObserver<"u"&&(S=new ResizeObserver(U),S.observe(i)),f&&typeof f.addEventListener=="function"&&f.addEventListener("change",H),i.addEventListener("pointerenter",q,{passive:!0}),i.addEventListener("pointermove",K,{passive:!0}),i.addEventListener("pointerleave",x,{passive:!0}),window.addEventListener("resize",U,{passive:!0}),window.addEventListener("scroll",U,{passive:!0,capture:!0}),{update(c,m){if(!V||B||h)return;let g=1-Math.exp(-12*m);if(k+=(v-k)*g,E+=(b-E)*g,R+=(w-R)*g,p&&(p.style.background=`radial-gradient(circle at ${F.toFixed(1)}% ${O.toFixed(1)}%, rgba(255,255,255,0.22), transparent 60%)`),Math.abs(v-k)<.02&&Math.abs(b-E)<.02&&Math.abs(w-R)<.001){k=v,E=b,R=w,V=!1,i.style.transform=w===1&&v===0&&b===0?l:`perspective(${r}px) rotateX(${k.toFixed(2)}deg) rotateY(${E.toFixed(2)}deg) scale3d(${R.toFixed(3)}, ${R.toFixed(3)}, 1)`;return}i.style.transform=`perspective(${r}px) rotateX(${k.toFixed(2)}deg) rotateY(${E.toFixed(2)}deg) scale3d(${R.toFixed(3)}, ${R.toFixed(3)}, 1)`},isIdle(){return!V||B||h},onWake(c){P=c},pause(){B=!0},resume(){B=!1,A=!0,V&&!h&&P?.()},destroy(){P=null,V=!1,T=null,S?.disconnect(),S=null,f&&typeof f.removeEventListener=="function"&&f.removeEventListener("change",H),i.removeEventListener("pointerenter",q),i.removeEventListener("pointermove",K),i.removeEventListener("pointerleave",x),window.removeEventListener("resize",U),window.removeEventListener("scroll",U,!0),p?.remove(),i.style.transform=l,i.style.position=a,i.style.overflow=d,i.style.willChange=u}}}};var Gt={name:"magnetic",mount(i,e){let t=typeof e.strength=="number"?e.strength:.35,o=e.respectReducedMotion??!0,r=i.style.transform,s=i.style.willChange,n=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(prefers-reduced-motion: reduce)"):null,l=o&&(n?.matches??!1);l||(i.style.willChange="transform");let a=0,d=0,u=0,f=0,h=!1,p=!1,v=null,b=null,w=!0,k=()=>{w=!0},E=()=>{let P=i.getBoundingClientRect();b={left:P.left-u,top:P.top-f,width:P.width,height:P.height},w=!1},R=P=>{let T=o&&P.matches;l!==T&&(l=T,l?(a=0,d=0,u=0,f=0,h=!1,i.style.transform=r,i.style.willChange=s):(i.style.willChange="transform",w=!0),v?.())},F=()=>{w=!0},O=P=>{if(p||l||((w||!b)&&E(),!b||b.width<=0||b.height<=0))return;let T=b.left+b.width*.5,A=b.top+b.height*.5;a=(P.clientX-T)*t,d=(P.clientY-A)*t,h=!0,v?.()},V=()=>{l||(a=0,d=0,(Math.abs(u)>.01||Math.abs(f)>.01)&&(h=!0,p||v?.()))},B=null;return typeof ResizeObserver<"u"&&(B=new ResizeObserver(k),B.observe(i)),n&&typeof n.addEventListener=="function"&&n.addEventListener("change",R),i.addEventListener("pointerenter",F,{passive:!0}),i.addEventListener("pointermove",O,{passive:!0}),i.addEventListener("pointerleave",V,{passive:!0}),window.addEventListener("resize",k,{passive:!0}),window.addEventListener("scroll",k,{passive:!0,capture:!0}),{update(P,T){if(!h||p||l)return;let A=1-Math.exp(-10*T);if(u+=(a-u)*A,f+=(d-f)*A,Math.abs(a-u)<.05&&Math.abs(d-f)<.05){u=a,f=d,h=!1,i.style.transform=a===0&&d===0?r:`translate3d(${u.toFixed(2)}px, ${f.toFixed(2)}px, 0)`;return}i.style.transform=`translate3d(${u.toFixed(2)}px, ${f.toFixed(2)}px, 0)`},isIdle(){return!h||p||l},onWake(P){v=P},pause(){p=!0},resume(){p=!1,w=!0,h&&!l&&v?.()},destroy(){v=null,h=!1,b=null,B?.disconnect(),B=null,n&&typeof n.removeEventListener=="function"&&n.removeEventListener("change",R),i.removeEventListener("pointerenter",F),i.removeEventListener("pointermove",O),i.removeEventListener("pointerleave",V),window.removeEventListener("resize",k),window.removeEventListener("scroll",k,!0),i.style.transform=r,i.style.willChange=s}}}};function ke(i,e,t){return Math.min(t,Math.max(e,i))}function Be(i,e){return typeof i=="number"&&!Number.isNaN(i)?i:e}function pt(i,e){if(typeof i=="boolean")return i;if(typeof i=="string"){let t=i.trim().toLowerCase();if(t==="true")return!0;if(t==="false")return!1}return e}function Rr(i){return i===!1?0:i===!0||i===void 0?18:typeof i=="number"&&!Number.isNaN(i)?i:18}function Xt(i,e){let t=Math.round(Be(i.activeIndex,0));return{activeIndex:e>0?ke(t,0,e-1):0,focused:pt(i.focused,!1),wrap:pt(i.wrap,!0),clickToFocus:pt(i.clickToFocus,!0),spread:Be(i.spread,25),depthScale:ke(Be(i.depthScale,.22),.05,.45),curve:Be(i.curve,10),parallax:Rr(i.parallax),focusOffsetX:Be(i.focusOffsetX,-15),focusScale:ke(Be(i.focusScale,1.07),.8,1.4),perspective:Be(i.perspective,1100),respectReducedMotion:i.respectReducedMotion??!0,onChange:typeof i.onChange=="function"?i.onChange:void 0}}function Qt(i){let e=Array.from(i.querySelectorAll("[data-fx-slide]"));return e.length>0?e:Array.from(i.children).filter(t=>t instanceof HTMLElement&&!t.hasAttribute("data-fluxfx-canvas"))}function st(i,e,t,o){let r=i-e;if(o&&t>2){let s=t/2;for(;r>s;)r-=t;for(;r<-s;)r+=t}return r}var $t={name:"depth-carousel",mount(i,e){let t=i.style.position,o=i.style.perspective,r=i.style.transformStyle;typeof window<"u"&&getComputedStyle(i).position==="static"&&(i.style.position="relative");let s=Qt(i),n=new Map,l=()=>{s=Qt(i);for(let c of s)n.has(c)||n.set(c,{el:c,transform:c.style.transform,opacity:c.style.opacity,zIndex:c.style.zIndex,filter:c.style.filter,pointerEvents:c.style.pointerEvents,willChange:c.style.willChange})};l();let a=Xt(e,s.length);i.style.perspective=`${a.perspective}px`,i.style.transformStyle="preserve-3d";let d=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(prefers-reduced-motion: reduce)"):null,u=a.respectReducedMotion&&(d?.matches??!1),f=a.activeIndex,h=a.activeIndex,p=a.focused?1:0,v=a.focused?1:0,b=0,w=0,k=0,E=0,R=!0,F=!1,O=null,V=null,B=null,P=!1,T=(c=!1)=>{(c||u)&&(f=h,p=v,b=k,w=E);let m=s.length;if(m!==0)for(let g=0;g<m;g++){let M=s[g],L=st(g,f,m,a.wrap),_=Math.abs(L),Z=L*a.spread,ue=Math.max(.45,1-_*a.depthScale),Te=-_*160,Ue=ke(-L*a.curve,-32,32),Ce=_>2.35?0:Math.max(.18,1-_*.32),ie=_<.5,Xe=ie?a.focusOffsetX:Z*1.45,Ke=ie?a.focusScale:ue*.85,Fe=ie?1:0,Ie=Z+(Xe-Z)*p,De=ue+(Ke-ue)*p,Oe=Te*(1-p*.5),ye=Ue*(1-p),Qe=Ce+(Fe-Ce)*p,$e=Math.max(.25,1-_*.25),Ze=b*a.parallax*$e,_e=w*(a.parallax*.55)*$e,bt=Math.max(1,20-Math.round(_*4)),Se=_>1.2&&p<.5?Math.min(2.5,(_-1.2)*1.5):0;u||(M.style.willChange="transform, opacity"),M.style.zIndex=String(bt),M.style.opacity=Qe.toFixed(3),M.style.pointerEvents=Qe<.08?"none":"auto",M.style.filter=Se>.1?`blur(${Se.toFixed(2)}px)`:"",M.style.transform=`translate3d(calc(${Ie.toFixed(2)}% + ${Ze.toFixed(2)}px), ${_e.toFixed(2)}px, ${Oe.toFixed(1)}px) rotateY(${ye.toFixed(2)}deg) scale(${De.toFixed(4)})`;let C=g===Math.round(h)?"true":"false";M.getAttribute("data-fx-active")!==C&&M.setAttribute("data-fx-active",C)}},A=()=>{let c=ke(Math.round(h),0,Math.max(0,s.length-1)),m=s[c]??null;a.onChange?.({index:c,focused:v>.5,element:m}),i.dispatchEvent(new CustomEvent("fluxfx:change",{bubbles:!0,detail:{index:c,focused:v>.5,element:m}}))},U=(c,m)=>{let g=s.length;if(g===0)return;let M=c;a.wrap?M=(c%g+g)%g:M=ke(c,0,g-1);let L=h,_=v;if(a.wrap&&g>2){let Z=st(M,f,g,!0);h=f+Z,h=M}else h=M;typeof m=="boolean"&&(v=m?1:0),(h!==L||v!==_)&&A(),R=!0,u?(T(!0),R=!1):F||O?.()},G=c=>{if(F||u)return;let m=i.getBoundingClientRect();m.width<=0||m.height<=0||(k=ke(((c.clientX-m.left)/m.width-.5)*2,-1,1),E=ke(((c.clientY-m.top)/m.height-.5)*2,-1,1),V!==null&&B===c.pointerId&&Math.abs(c.clientX-V)>22&&(P=!0),R=!0,O?.())},H=()=>{u||(k=0,E=0,R=!0,F||O?.())},q=c=>{F||c.button!==0||(V=c.clientX,B=c.pointerId,P=!1)},K=c=>{if(V===null||B!==c.pointerId)return;let m=c.clientX-V;if(V=null,B=null,Math.abs(m)>48&&v<.5){let g=m<0?1:-1;U(h+g)}},x=c=>{if(F)return;if(P){P=!1;return}let m=c.target;if(m){if(m.closest("[data-fx-prev]")){U(h-1,!1);return}if(m.closest("[data-fx-next]")){U(h+1,!1);return}for(let g=0;g<s.length;g++)if(s[g]===m||s[g].contains(m)){g!==Math.round(h)?U(g,!1):a.clickToFocus&&U(g,v<.5);return}}},S=c=>{u=a.respectReducedMotion&&c.matches,u&&(T(!0),R=!1),O?.()};return d&&typeof d.addEventListener=="function"&&d.addEventListener("change",S),i.addEventListener("pointermove",G,{passive:!0}),i.addEventListener("pointerleave",H,{passive:!0}),i.addEventListener("pointerdown",q,{passive:!0}),window.addEventListener("pointerup",K,{passive:!0}),i.addEventListener("click",x),T(!0),R=!1,{update(c,m){if(!R||F||u)return;let g=Math.min(m,.05),M=1-Math.exp(-10.5*g),L=1-Math.exp(-8*g),_=st(h,f,s.length,a.wrap);f+=_*M,a.wrap&&s.length>0&&(f=(f%s.length+s.length)%s.length),p+=(v-p)*M,b+=(k-b)*L,w+=(E-w)*L,T(!1);let Z=Math.abs(st(h,f,s.length,a.wrap))<.002,ue=Math.abs(v-p)<.003,Te=Math.abs(k-b)<.003&&Math.abs(E-w)<.003;Z&&ue&&Te&&(T(!0),R=!1)},setOptions(c){l();let m=a;a=Xt(c,s.length),a.perspective!==m.perspective&&(i.style.perspective=`${a.perspective}px`);let g=c.focused!==void 0?a.focused:v>.5,M=c.activeIndex!==void 0?a.activeIndex:h,L=Math.round(M)!==Math.round(h)||g!==v>.5;h=M,v=g?1:0,L&&A(),R=!0,u?(T(!0),R=!1):F||O?.()},isIdle(){return!R||F||u},onWake(c){O=c},pause(){F=!0},resume(){F=!1,R&&!u&&O?.()},destroy(){O=null,R=!1,d&&typeof d.removeEventListener=="function"&&d.removeEventListener("change",S),i.removeEventListener("pointermove",G),i.removeEventListener("pointerleave",H),i.removeEventListener("pointerdown",q),window.removeEventListener("pointerup",K),i.removeEventListener("click",x),n.forEach(c=>{c.el.style.transform=c.transform,c.el.style.opacity=c.opacity,c.el.style.zIndex=c.zIndex,c.el.style.filter=c.filter,c.el.style.pointerEvents=c.pointerEvents,c.el.style.willChange=c.willChange,c.el.removeAttribute("data-fx-active")}),n.clear(),i.style.position=t,i.style.perspective=o,i.style.transformStyle=r}}}};function ce(i){return Math.min(1,Math.max(0,i))}function ve(i,e,t){return Math.min(t,Math.max(e,i))}function le(i,e){return typeof i=="number"&&!Number.isNaN(i)?i:e}function nt(i,e){if(typeof i=="boolean")return i;if(typeof i=="string"){let t=i.trim().toLowerCase();if(t==="true")return!0;if(t==="false")return!1}return e}function me(i,e=""){return typeof i=="string"?i.trim():e}function Lr(i){return Array.isArray(i)?i.filter(e=>typeof e=="string"&&e.trim().length>0).map(e=>e.trim()):typeof i=="string"&&i.trim().length>0?i.split(",").map(e=>e.trim()).filter(Boolean):[]}function kr(i){let e=i.trim().replace(/^#/,"");if(e.length===3){let t=parseInt(e[0]+e[0],16),o=parseInt(e[1]+e[1],16),r=parseInt(e[2]+e[2],16);return[t,o,r].some(Number.isNaN)?null:[t,o,r]}if(e.length===6){let t=parseInt(e.slice(0,2),16),o=parseInt(e.slice(2,4),16),r=parseInt(e.slice(4,6),16);return[t,o,r].some(Number.isNaN)?null:[t,o,r]}return null}function qt(i){let e=me(i.trigger,"cursor").toLowerCase(),t=e==="scroll"||e==="both"?e:"cursor",o=me(i.axis,"x").toLowerCase(),r=o==="y"||o==="xy"?o:"x",s=me(i.mode,"auto").toLowerCase(),n=s==="atlas"||s==="video"||s==="sprite"?s:"auto",a=me(i.trackTarget,"window").toLowerCase()==="element"?"element":"window",u=me(i.fit,"contain").toLowerCase()==="cover"?"cover":"contain",f=me(i.position,"center").toLowerCase(),h=f==="top"||f==="bottom"?f:"center",p=Math.max(1,Math.round(le(i.cols,1))),v=Math.max(1,Math.round(le(i.rows,1))),b=p*v>1?p*v:48;return{videoSrc:me(i.videoSrc)||me(i.src),spriteSrc:me(i.spriteSrc),frames:Lr(i.frames),poster:me(i.poster),cols:p,rows:v,frameCount:ve(Math.round(le(i.frameCount,b)),2,180),mode:n,trigger:t,axis:r,trackTarget:a,sensitivity:ve(le(i.sensitivity,1),.1,4),damping:ve(le(i.damping,10),1,40),idlePosition:ce(le(i.idlePosition,.5)),idleTimeout:Math.max(0,le(i.idleTimeout,0)),returnToIdle:nt(i.returnToIdle,!0),invert:nt(i.invert,!1),clamp:nt(i.clamp,!0),fit:u,position:h,startOffset:Math.max(0,le(i.startOffset,0)),endOffset:Math.max(0,le(i.endOffset,0)),chromaKey:me(i.chromaKey),chromaTolerance:ve(le(i.chromaTolerance,.22),.01,.65),chromaSoftness:ve(le(i.chromaSoftness,.12),0,.45),crossfade:nt(i.crossfade,!1),targetFps:ve(Math.round(le(i.targetFps,0)),0,120),tileInset:ve(le(i.tileInset,.016),0,.08),maxCacheWidth:ve(Math.round(le(i.maxCacheWidth,720)),160,1920),blendMode:me(i.blendMode,"normal")||"normal",respectReducedMotion:i.respectReducedMotion??!0,onProgress:typeof i.onProgress=="function"?i.onProgress:void 0}}function pe(i,e,t,o,r,s,n,l,a=0,d=0,u=t,f=o){if(u<=0||f<=0||r<=0||s<=0)return;let h=n==="cover"?Math.max(r/u,s/f):Math.min(r/u,s/f),p=u*h,v=f*h,b=(r-p)*.5,w=(s-v)*.5;l==="top"?w=0:l==="bottom"&&(w=s-v),i.drawImage(e,a,d,u,f,b,w,p,v)}function Fr(i,e,t,o,r,s){if(!o)return;let n=i.getImageData(0,0,e,t),l=n.data,a=null;if(o.toLowerCase()==="auto"?a=[l[0],l[1],l[2]]:a=kr(o),!a)return;let[d,u,f]=a,h=u>d+28&&u>f+28,p=f>d+28&&f>u+28,v=441.67295593,b=r*v,w=Math.max(4,s*v);for(let k=0;k<l.length;k+=4){let E=l[k+3];if(E===0)continue;let R=l[k],F=l[k+1],O=l[k+2],V=R-d,B=F-u,P=O-f,T=Math.sqrt(V*V+B*B+P*P);if(h){let A=Math.max(R,O),U=F-A;if(U>0){let q=ce(U/Math.max(18,u*.25));F=Math.round(F-U*(.68+.32*q)),l[k+1]=F}let G=v*(1-ce(U/Math.max(40,u*.68))),H=U>12?Math.min(T,G*.92+T*.25):T+65;if(H<=b)l[k+3]=0;else if(H<b+w){let q=(H-b)/w,K=q*q*(3-2*q);l[k+3]=Math.round(E*K)}}else if(p){let A=Math.max(R,F),U=O-A;U>0&&(l[k+2]=Math.round(O-U*.72));let G=v*(1-ce(U/Math.max(40,f*.68))),H=U>12?Math.min(T,G*.92+T*.25):T+65;if(H<=b)l[k+3]=0;else if(H<b+w){let q=(H-b)/w,K=q*q*(3-2*q);l[k+3]=Math.round(E*K)}}else if(T<=b)l[k+3]=0;else if(T<b+w){let A=(T-b)/w,U=A*A*(3-2*A);l[k+3]=Math.round(E*U)}}i.putImageData(n,0,0)}var Yt={name:"motion-scrub",mount(i,e){let t=i.style.position,o=i.style.overflow;typeof window<"u"&&getComputedStyle(i).position==="static"&&(i.style.position="relative"),i.style.overflow=i.style.overflow||"hidden";let r=qt(e),s=document.createElement("canvas");s.setAttribute("data-fluxfx-scrub-canvas","true"),Object.assign(s.style,{position:"absolute",inset:"0",width:"100%",height:"100%",display:"block",pointerEvents:"none",zIndex:"0",mixBlendMode:r.blendMode});let n=document.createElement("video");n.muted=!0,n.playsInline=!0,n.preload="auto",n.setAttribute("aria-hidden","true"),Object.assign(n.style,{position:"absolute",inset:"0",width:"100%",height:"100%",pointerEvents:"none",zIndex:"0",display:"none",mixBlendMode:r.blendMode}),i.prepend(n),i.prepend(s);let l=s.getContext("2d",{alpha:!0}),a=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(prefers-reduced-motion: reduce)"):null,d=r.respectReducedMotion&&(a?.matches??!1),u=r.idlePosition,f=r.idlePosition,h=r.idlePosition,p=r.idlePosition,v=r.idlePosition,b=r.idlePosition,w=.5,k=.5,E=!1,R=!1,F=!1,O=null,V=null,B=0,P="atlas",T=[],A=null,U=null,G=!1,H=-1,q=0,K=!1,x=null,S=0,c=0,m=0,g=()=>{V!==null&&(window.clearTimeout(V),V=null)},M=()=>{g(),!(!r.returnToIdle||r.idleTimeout<=0||r.trigger==="scroll")&&(V=window.setTimeout(()=>{V=null,!(F||d)&&(f=r.idlePosition,p=r.idlePosition,b=r.idlePosition,E=!0,R||O?.())},r.idleTimeout))},L=()=>{for(let C=0;C<T.length;C++){let y=T[C];if(y&&"close"in y&&typeof y.close=="function")try{y.close()}catch{}}T=[],A=null,G=!1,H=-1},_=()=>{let C=i.getBoundingClientRect(),y=Math.min(window.devicePixelRatio||1,2),D=Math.max(1,Math.round(C.width*y)),W=Math.max(1,Math.round(C.height*y));(D!==c||W!==m)&&(c=D,m=W,s.width=D,s.height=W,H=-1)},Z=C=>{if(T[C])return T[C];for(let y=1;y<T.length;y++){if(C-y>=0&&T[C-y])return T[C-y];if(C+y<T.length&&T[C+y])return T[C+y]}return null},ue=C=>{let y=Math.max(.05,C),D=Math.min(r.startOffset,y-.05),W=Math.max(D+.05,y-r.endOffset);return{start:D,span:Math.max(.05,W-D)}},Te=C=>{if(!S||n.readyState<1)return;let{start:y,span:D}=ue(S),W=ve(y+C*D,0,Math.max(0,S-.001));if(K){x=W;return}if(!(Math.abs(n.currentTime-W)<.008))if(K=!0,typeof n.fastSeek=="function")try{n.fastSeek(W)}catch{n.currentTime=W}else n.currentTime=W},Ue=()=>{if(K=!1,P==="video"&&l&&s.style.display!=="none"&&n.videoWidth>0&&(_(),l.clearRect(0,0,c,m),pe(l,n,n.videoWidth,n.videoHeight,c,m,r.fit,r.position)),x!==null&&P==="video"){let C=x;x=null,Math.abs(n.currentTime-C)>=.008&&(K=!0,n.currentTime=C)}};n.addEventListener("seeked",Ue);let Ce=(C,y,D)=>{let W={progress:C,frame:y,totalFrames:D,ready:G,mode:P};r.onProgress?.(W),i.dispatchEvent(new CustomEvent("fluxfx:scrub",{bubbles:!0,detail:W}))},ie=(C,y=!1)=>{let D=ce(C);if(P==="video"){n.style.display!=="none"&&(n.style.objectFit=r.fit,n.style.objectPosition=r.position==="top"?"center top":r.position==="bottom"?"center bottom":"center center"),Te(D);let j=r.frameCount,X=Math.round(D*(j-1));(y||X!==H)&&(H=X,Ce(D,X,j));return}if(!l)return;if(_(),l.imageSmoothingEnabled=!0,l.imageSmoothingQuality="high",P==="sprite"&&T.length>0){if(r.axis==="xy"&&r.cols>1&&r.rows>1){let Me=ce(h)*(r.cols-1),Ee=ce(v)*(r.rows-1),we=Math.floor(Me),Re=Math.floor(Ee),Ve=Math.min(r.cols-1,we+1),Le=Math.min(r.rows-1,Re+1),Pe=Me-we,ae=Ee-Re,Ae=Math.round(Ee)*r.cols+Math.round(Me),fe=T[Ae]??Z(Ae);if(!fe)return;let ge="width"in fe?fe.width:0,qe="height"in fe?fe.height:0;l.clearRect(0,0,c,m),l.save();let er=(h-.5)*c*.018,yt=1.032+Math.abs(h-.5)*.012;if(l.translate(c*.5+er,m),l.rotate((h-.5)*.022),l.scale(yt,yt),l.translate(-c*.5,-m),!r.crossfade)l.globalAlpha=1,pe(l,fe,ge,qe,c,m,r.fit,r.position);else{let rr=T[Re*r.cols+we]??fe,ir=T[Re*r.cols+Ve]??fe,or=T[Le*r.cols+we]??fe,sr=T[Le*r.cols+Ve]??fe;l.globalAlpha=1,pe(l,rr,ge,qe,c,m,r.fit,r.position),Ve!==we&&Pe>.01&&(l.globalAlpha=Pe,pe(l,ir,ge,qe,c,m,r.fit,r.position)),Le!==Re&&ae>.01&&(l.globalAlpha=ae,pe(l,or,ge,qe,c,m,r.fit,r.position)),Ve!==we&&Le!==Re&&Pe>.01&&ae>.01&&(l.globalAlpha=Pe*ae,pe(l,sr,ge,qe,c,m,r.fit,r.position))}l.restore();let tr=r.cols*r.rows;(y||Ae!==H)&&(H=Ae,Ce(D,Ae,tr));return}let X=Math.max(1,Math.min(r.frameCount,T.length)),oe=D*(X-1),te=Math.floor(oe),de=Math.min(X-1,te+1),I=oe-te,Q=Math.round(oe);if(!r.crossfade&&!y&&Q===H)return;let N=T[Q]??Z(Q);if(!N)return;let z="width"in N?N.width:0,J="height"in N?N.height:0;if(l.clearRect(0,0,c,m),!r.crossfade)l.globalAlpha=1,pe(l,N,z,J,c,m,r.fit,r.position);else{let Me=T[te]??N,Ee=T[de]??N;l.globalAlpha=1,pe(l,Me,z,J,c,m,r.fit,r.position),de!==te&&I>.01&&(l.globalAlpha=I,pe(l,Ee,z,J,c,m,r.fit,r.position))}(y||Q!==H)&&(H=Q,Ce(D,Q,X));return}if(P==="sprite"&&A){let j="naturalWidth"in A&&A.naturalWidth>0?A.naturalWidth:A.width,X="naturalHeight"in A&&A.naturalHeight>0?A.naturalHeight:A.height;if(j<=0||X<=0)return;let oe=j/r.cols,te=X/r.rows,de=Math.max(1,Math.min(r.frameCount,r.cols*r.rows)),I=Math.round(D*(de-1));if(!y&&I===H)return;let Q=I%r.cols,N=Math.floor(I/r.cols),z=oe*r.tileInset,J=te*r.tileInset;l.clearRect(0,0,c,m),pe(l,A,j,X,c,m,r.fit,r.position,Q*oe+z,N*te+J,oe-z*2,te-J*2),H=I,Ce(D,I,de);return}let W=T.length;if(W>0){let j=Math.round(D*(W-1));if(!y&&j===H)return;let X=Z(j);if(X){H=j;let oe="width"in X?X.width:0,te="height"in X?X.height:0;l.clearRect(0,0,c,m),pe(l,X,oe,te,c,m,r.fit,r.position),Ce(D,j,W);return}}U&&U.complete&&U.naturalWidth>0&&(l.clearRect(0,0,c,m),pe(l,U,U.naturalWidth,U.naturalHeight,c,m,r.fit,r.position))},Xe=async(C,y,D,W=0,j=0,X=y,oe=D)=>{if(X<=0||oe<=0)return null;let te=Math.min(1,r.maxCacheWidth/X),de=Math.max(1,Math.round(X*te)),I=Math.max(1,Math.round(oe*te)),Q=document.createElement("canvas");Q.width=de,Q.height=I;let N=Q.getContext("2d",{willReadFrequently:!!r.chromaKey});if(!N)return null;if(N.imageSmoothingEnabled=!0,N.imageSmoothingQuality="high",N.drawImage(C,W,j,X,oe,0,0,de,I),r.chromaKey&&Fr(N,de,I,r.chromaKey,r.chromaTolerance,r.chromaSoftness),typeof createImageBitmap=="function")try{return await createImageBitmap(Q)}catch{return Q}return Q},Ke=async()=>{let C=++B;if(L(),s.style.mixBlendMode=r.blendMode,n.style.mixBlendMode=r.blendMode,s.style.display="block",n.style.display="none",r.poster){let I=new Image;I.crossOrigin="anonymous",I.onload=()=>{C!==B||F||(U=I,G||ie(u,!0))},I.src=r.poster}if((r.mode==="sprite"||r.mode==="auto"&&r.spriteSrc)&&r.spriteSrc){P="sprite";let I=new Image;I.crossOrigin="anonymous",I.onload=async()=>{if(C!==B||F)return;let Q=I.naturalWidth,N=I.naturalHeight,z=Math.max(1,Math.min(r.frameCount,r.cols*r.rows));if(Q>0&&N>0){let J=Q/r.cols,Me=N/r.rows,Ee=J*r.tileInset,we=Me*r.tileInset,Re=Math.max(1,J-Ee*2),Ve=Math.max(1,Me-we*2);T=new Array(z).fill(null);let Le=ve(Math.round(u*(z-1)),0,z-1),Pe=[Le];for(let ae=0;ae<z;ae++)ae!==Le&&Pe.push(ae);try{for(let ae of Pe){if(C!==B||F)return;let Ae=ae%r.cols,fe=Math.floor(ae/r.cols),ge=await Xe(I,Q,N,Ae*J+Ee,fe*Me+we,Re,Ve);if(C!==B||F){ge&&"close"in ge&&typeof ge.close=="function"&&ge.close();return}T[ae]=ge,G=!0,ae===Le&&ie(u,!0)}}catch{A=I,G=!0}}else A=I,G=!0;C===B&&!F&&ie(u,!0)},I.src=r.spriteSrc;return}if(r.frames.length>0&&!r.videoSrc){P="frames",T=new Array(r.frames.length).fill(null),await Promise.all(r.frames.map((I,Q)=>new Promise(N=>{let z=new Image;z.crossOrigin="anonymous",z.onload=async()=>{if(C!==B||F){N();return}let J=await Xe(z,z.naturalWidth,z.naturalHeight);if(C!==B||F){J&&"close"in J&&typeof J.close=="function"&&J.close(),N();return}T[Q]=J,G=!0,Q===Math.round(u*(r.frames.length-1))&&ie(u,!0),N()},z.onerror=()=>N(),z.src=I}))),C===B&&!F&&ie(u,!0);return}if(!r.videoSrc)return;let y=I=>new Promise(Q=>{let N=()=>{J(),Q(!0)},z=()=>{J(),Q(!1)},J=()=>{n.removeEventListener("loadeddata",N),n.removeEventListener("error",z)};n.crossOrigin=I?"anonymous":"",I||n.removeAttribute("crossorigin"),n.addEventListener("loadeddata",N,{once:!0}),n.addEventListener("error",z,{once:!0}),n.src=r.videoSrc,n.load()}),D=await y(!0),W=D;if(D||(D=await y(!1),W=!1),!D||C!==B||F||(S=Number.isFinite(n.duration)?n.duration:0,!S||n.videoWidth<=0))return;if(r.mode==="video"||!W){P="video",s.style.display="none",n.style.display="block",G=!0,ie(u,!0);return}P="atlas";let j=r.frameCount;T=new Array(j).fill(null);let{start:X,span:oe}=ue(S),te=ve(Math.round(u*(j-1)),0,j-1),de=[te];for(let I=0;I<j;I++)I!==te&&de.push(I);for(let I of de){if(C!==B||F)return;let Q=ve(X+I/Math.max(1,j-1)*oe,0,Math.max(0,S-.002));if(!await new Promise(z=>{let J=()=>{n.removeEventListener("seeked",J),z(!0)};n.addEventListener("seeked",J,{once:!0}),n.currentTime=Q})||C!==B||F)return;try{let z=await Xe(n,n.videoWidth,n.videoHeight);if(C!==B||F){z&&"close"in z&&typeof z.close=="function"&&z.close();return}T[I]=z,G=!0,(I===te||I===Math.round(u*(j-1)))&&ie(u,!0)}catch{P="video",s.style.display="none",n.style.display="block",G=!0,ie(u,!0);return}await new Promise(z=>setTimeout(z,0))}C===B&&!F&&(n.removeAttribute("src"),n.load(),ie(u,!0))},Fe=C=>{let y=(C-.5)*r.sensitivity+.5,D=r.invert?1-y:y;return r.clamp?ce(D):D},Ie=C=>{let y=r.idlePosition;r.trigger!=="scroll"&&(p=ce(Fe(w)),b=ce(Fe(k)));let D=.5;if(r.axis==="x"?D=w:r.axis==="y"?D=k:D=w*.65+k*.35,r.trigger==="cursor")y=Fe(D);else if(r.trigger==="scroll"){let W=C??De();y=Fe(W)}else{let W=C??De();y=Fe(D*.5+W*.5)}return ce(y)},De=()=>{if(typeof window>"u")return .5;let C=i.getBoundingClientRect(),y=window.innerHeight||document.documentElement.clientHeight||800,D=y+C.height;return D<=0?.5:ce((y-C.top)/D)},Oe=C=>{if(R||d||r.trigger==="scroll")return;let y=i.getBoundingClientRect();if(r.trackTarget==="element"){if(y.width<=0||y.height<=0)return;w=(C.clientX-y.left)/y.width,k=(C.clientY-y.top)/y.height}else{let D=window.innerWidth||document.documentElement.clientWidth||1,W=window.innerHeight||document.documentElement.clientHeight||1,j=y.width>0?y.left+y.width*.5:D*.5,X=y.height>0?y.top+y.height*.44:W*.5,oe=Math.max(220,D*.38),te=Math.max(180,W*.36);w=ce(.5+(C.clientX-j)/(oe*2)),k=ce(.5+(C.clientY-X)/(te*2))}f=Ie(),E=!0,M(),O?.()},ye=()=>{d||!r.returnToIdle||r.trigger==="scroll"||(g(),f=r.idlePosition,p=r.idlePosition,b=r.idlePosition,E=!0,R||O?.())},Qe=()=>{R||d||r.trigger==="cursor"||(f=Ie(De()),E=!0,O?.())},$e=()=>{_(),ie(u,!0)},Ze=C=>{let y=r.respectReducedMotion&&C.matches;d!==y&&(d=y,d&&(g(),u=r.idlePosition,f=r.idlePosition,h=r.idlePosition,p=r.idlePosition,v=r.idlePosition,b=r.idlePosition,E=!1,ie(u,!0)),O?.())},_e=null;typeof ResizeObserver<"u"&&(_e=new ResizeObserver($e),_e.observe(i)),a&&typeof a.addEventListener=="function"&&a.addEventListener("change",Ze);let Se=r.trackTarget==="element"?i:window;return Se.addEventListener("pointermove",Oe,{passive:!0}),r.trackTarget==="element"?i.addEventListener("pointerleave",ye,{passive:!0}):document.addEventListener("pointerleave",ye,{passive:!0}),window.addEventListener("scroll",Qe,{passive:!0}),(r.trigger==="scroll"||r.trigger==="both")&&(u=Ie(De()),f=u),Ke(),{update(C,y){if(!E||R||d)return;let D=1-Math.exp(-r.damping*y);if(u+=(f-u)*D,h+=(p-h)*D,v+=(b-v)*D,Math.abs(f-u)<8e-4&&Math.abs(p-h)<8e-4&&Math.abs(b-v)<8e-4&&(u=f,h=p,v=b,E=!1),r.targetFps>0&&E){let W=1/r.targetFps;if(C-q<W*.92)return}q=C,ie(u)},setOptions(C){let y=r;r=qt(C),s.style.mixBlendMode=r.blendMode,n.style.mixBlendMode=r.blendMode,y.trackTarget!==r.trackTarget&&(Se.removeEventListener("pointermove",Oe),i.removeEventListener("pointerleave",ye),document.removeEventListener("pointerleave",ye),Se=r.trackTarget==="element"?i:window,Se.addEventListener("pointermove",Oe,{passive:!0}),r.trackTarget==="element"?i.addEventListener("pointerleave",ye,{passive:!0}):document.addEventListener("pointerleave",ye,{passive:!0})),y.videoSrc!==r.videoSrc||y.spriteSrc!==r.spriteSrc||y.mode!==r.mode||y.frameCount!==r.frameCount||y.cols!==r.cols||y.rows!==r.rows||y.chromaKey!==r.chromaKey||y.chromaTolerance!==r.chromaTolerance||y.chromaSoftness!==r.chromaSoftness||y.tileInset!==r.tileInset||y.startOffset!==r.startOffset||y.endOffset!==r.endOffset||y.maxCacheWidth!==r.maxCacheWidth||y.frames.join("|")!==r.frames.join("|")?Ke():ie(u,!0),(r.trigger==="scroll"||r.trigger==="both")&&(f=Ie(De()),E=!0),O?.()},resize:$e,isIdle(){return!E||R||d},onWake(C){O=C},pause(){R=!0,g()},resume(){R=!1,E&&!d&&O?.()},destroy(){F=!0,B++,O=null,E=!1,g(),L(),_e?.disconnect(),_e=null,a&&typeof a.removeEventListener=="function"&&a.removeEventListener("change",Ze),Se.removeEventListener("pointermove",Oe),i.removeEventListener("pointerleave",ye),document.removeEventListener("pointerleave",ye),window.removeEventListener("scroll",Qe),n.removeEventListener("seeked",Ue),n.removeAttribute("src"),n.load(),n.remove(),s.remove(),i.style.position=t,i.style.overflow=o}}}};function Ne(i){return Math.min(1,Math.max(0,i))}function vt(i,e,t){return Math.min(t,Math.max(e,i))}function gt(i,e){return typeof i=="number"&&!Number.isNaN(i)?i:e}function Dr(i,e){if(typeof i=="boolean")return i;if(typeof i=="string"){let t=i.trim().toLowerCase();if(t==="true")return!0;if(t==="false")return!1}return e}function jt(i){return{pathSelector:typeof i.pathSelector=="string"&&i.pathSelector.trim()?i.pathSelector.trim():"[data-fx-path], path",damping:vt(gt(i.damping,10),1,40),offsetTop:vt(gt(i.offsetTop,.72),.05,.98),offsetBottom:vt(gt(i.offsetBottom,.35),.02,.95),once:Dr(i.once,!1),respectReducedMotion:i.respectReducedMotion??!0,onWaypoint:typeof i.onWaypoint=="function"?i.onWaypoint:void 0}}var Pr=0,Kt={name:"scroll-path",mount(i,e){let t=jt(e),o=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(prefers-reduced-motion: reduce)"):null,r=t.respectReducedMotion&&(o?.matches??!1),s=i.querySelector(t.pathSelector),n=s?.ownerSVGElement??null,l=Array.from(i.querySelectorAll("[data-fx-waypoint]")),a=s?s.style.strokeDasharray:"",d=s?s.style.strokeDashoffset:"",u=s?s.getAttribute("mask"):null,f=i.style.getPropertyValue("--fx-scroll-progress"),h=0,p=!1,v=null,b=null,w=null;(()=>{if(!s||typeof s.getTotalLength!="function")return;h=Math.max(1,s.getTotalLength());let x=s.getAttribute("stroke-dasharray")||(typeof window<"u"?getComputedStyle(s).strokeDasharray:"none");if(x&&x!=="none"&&x!=="0px"&&!x.startsWith(`${Math.round(h)}`)&&n){p=!0;let c="http://www.w3.org/2000/svg",m=n.querySelector("defs");m||(m=document.createElementNS(c,"defs"),n.prepend(m),w=m);let g=`fluxfx-scroll-mask-${++Pr}`,M=document.createElementNS(c,"mask");M.setAttribute("id",g),M.setAttribute("maskUnits","userSpaceOnUse");let L=s.cloneNode(!1);L.removeAttribute("id"),L.removeAttribute("data-fx-path"),L.removeAttribute("stroke-dasharray"),L.removeAttribute("stroke-dashoffset"),L.setAttribute("fill","none"),L.setAttribute("stroke","#ffffff");let _=parseFloat(s.getAttribute("stroke-width")||getComputedStyle(s).strokeWidth||"3");L.setAttribute("stroke-width",String(Math.max(4,_+6))),L.style.strokeDasharray=`${h}`,L.style.strokeDashoffset=`${h}`,M.appendChild(L),m.appendChild(M),s.setAttribute("mask",`url(#${g})`),b=M,v=L}else p=!1,s.style.strokeDasharray=`${h}`,s.style.strokeDashoffset=`${h}`})();let E=new WeakMap,R=0,F=0,O=!1,V=!1,B=null,P=()=>{if(typeof window>"u")return!1;let S=getComputedStyle(i).overflowY;return(S==="auto"||S==="scroll")&&i.scrollHeight>i.clientHeight+4},T=()=>{if(typeof window>"u")return 1;if(P()){let L=Math.max(1,i.scrollHeight-i.clientHeight);return Ne(i.scrollTop/L)}let x=i.getBoundingClientRect(),S=window.innerHeight||document.documentElement.clientHeight||800,c=S*t.offsetTop,m=S*t.offsetBottom,g=Math.max(1,x.height+(c-m)),M=c-x.top;return Ne(M/g)},A=x=>{let S=Ne(x);if(i.style.setProperty("--fx-scroll-progress",S.toFixed(4)),s&&h>0){let M=h*(1-S);p&&v?v.style.strokeDashoffset=M.toFixed(2):s.style.strokeDashoffset=M.toFixed(2)}let c=i.getBoundingClientRect(),m=P(),g=Math.max(1,m?i.scrollHeight:c.height);for(let M=0;M<l.length;M++){let L=l[M],_=L.getAttribute("data-fx-at"),Z;if(_!==null&&!Number.isNaN(Number(_)))Z=Ne(Number(_));else if(m)Z=Ne((L.offsetTop-i.clientHeight*.35)/g);else{let Ue=L.getBoundingClientRect();Z=Ne((Ue.top-c.top)/g)}let ue=E.get(L)??!1,Te=S>=Z||t.once&&ue;Te!==ue&&(E.set(L,Te),Te?(L.setAttribute("data-fx-reached","true"),t.onWaypoint?.({element:L,index:M,progress:S}),L.dispatchEvent(new CustomEvent("fluxfx:waypoint",{bubbles:!0,detail:{element:L,index:M,progress:S}}))):t.once||L.removeAttribute("data-fx-reached"))}},U=()=>{F=r?1:T(),r?(R=1,O=!1,A(1)):(O=!0,B?.())},G=()=>{V||r||(F=T(),Math.abs(F-R)>5e-4&&(O=!0,B?.()))},H=()=>{s&&typeof s.getTotalLength=="function"&&(h=Math.max(1,s.getTotalLength()),p&&v?v.style.strokeDasharray=`${h}`:s.style.strokeDasharray=`${h}`),U()},q=x=>{let S=t.respectReducedMotion&&x.matches;r!==S&&(r=S,U())},K=null;return typeof ResizeObserver<"u"&&(K=new ResizeObserver(H),K.observe(i)),o&&typeof o.addEventListener=="function"&&o.addEventListener("change",q),i.addEventListener("scroll",G,{passive:!0}),window.addEventListener("scroll",G,{passive:!0}),window.addEventListener("resize",H,{passive:!0}),R=r?1:T(),F=R,A(R),{update(x,S){if(!O||V||r)return;let c=1-Math.exp(-t.damping*S);R+=(F-R)*c,Math.abs(F-R)<8e-4&&(R=F,O=!1),A(R)},setOptions(x){t=jt(x),U()},resize:H,isIdle(){return!O||V||r},onWake(x){B=x},pause(){V=!0},resume(){V=!1,U()},destroy(){B=null,O=!1,K?.disconnect(),K=null,o&&typeof o.removeEventListener=="function"&&o.removeEventListener("change",q),i.removeEventListener("scroll",G),window.removeEventListener("scroll",G),window.removeEventListener("resize",H),s&&(s.style.strokeDasharray=a,s.style.strokeDashoffset=d,u!==null?s.setAttribute("mask",u):s.removeAttribute("mask")),b?.remove(),w?.remove();for(let x of l)x.removeAttribute("data-fx-reached");f?i.style.setProperty("--fx-scroll-progress",f):i.style.removeProperty("--fx-scroll-progress")}}}};function Ge(i,e,t){return Math.min(t,Math.max(e,i))}function Ar(i){return Ge(i,0,1)}function at(i,e){return typeof i=="number"&&!Number.isNaN(i)?i:e}function Zt(i){return{cardSelector:typeof i.cardSelector=="string"&&i.cardSelector.trim()?i.cardSelector.trim():"[data-fx-stack-card]",tabSelector:typeof i.tabSelector=="string"&&i.tabSelector.trim()?i.tabSelector.trim():"[data-fx-stack-tab]",stickyTop:typeof i.stickyTop=="number"&&!Number.isNaN(i.stickyTop)?i.stickyTop:void 0,offsetStep:Ge(at(i.offsetStep,16),0,80),scaleStep:Ge(at(i.scaleStep,.045),0,.2),opacityStep:Ge(at(i.opacityStep,.08),0,.4),damping:Ge(at(i.damping,14),1,45),respectReducedMotion:i.respectReducedMotion??!0,onChange:typeof i.onChange=="function"?i.onChange:void 0}}function Br(i){return{position:i.style.position,top:i.style.top,zIndex:i.style.zIndex,transform:i.style.transform,transformOrigin:i.style.transformOrigin,opacity:i.style.opacity,willChange:i.style.willChange,transition:i.style.transition}}function Ur(i,e){i.style.position=e.position,i.style.top=e.top,i.style.zIndex=e.zIndex,i.style.transform=e.transform,i.style.transformOrigin=e.transformOrigin,i.style.opacity=e.opacity,i.style.willChange=e.willChange,i.style.transition=e.transition,delete i.dataset.stackDepth,delete i.dataset.active}var Jt={name:"card-stack",mount(i,e){let t=Zt(e),o=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(prefers-reduced-motion: reduce)"):null,r=t.respectReducedMotion&&(o?.matches??!1),s=i.querySelector("[data-fx-stack-nav]"),n=[],l=[],a=new Map,d=i.style.getPropertyValue("--fx-stack-active"),u=()=>{let x=Array.from(i.querySelectorAll(t.cardSelector)),S=x.length>0?x:Array.from(i.children).filter(c=>c instanceof HTMLElement&&!c.hasAttribute("data-fx-stack-nav"));for(let c of S)a.has(c)||a.set(c,Br(c));n=S,l=Array.from(i.querySelectorAll(t.tabSelector))};u();let f=()=>{if(typeof window>"u")return!1;let S=getComputedStyle(i).overflowY;return(S==="auto"||S==="scroll")&&i.scrollHeight>i.clientHeight+4},h=x=>{if(t.stickyTop!==void 0)return t.stickyTop;let S=s?s.offsetHeight+12:0;return x?12+S:92+S},p=[],v=[],b=n.map(()=>0),w=n.map(()=>0),k=-1,E=!1,R=!1,F=null,O=()=>{if(n.length===0)return;let x=f(),S=h(x);for(let g=0;g<n.length;g++)n[g].style.position="static",n[g].style.transform="none";let c=i.getBoundingClientRect(),m=x?i.scrollTop:0;p=new Array(n.length),v=new Array(n.length);for(let g=0;g<n.length;g++){let M=n[g],L=M.getBoundingClientRect();p[g]=L.top-c.top+m,v[g]=Math.max(120,L.height||M.offsetHeight||360)}for(let g=0;g<n.length;g++){let M=n[g];M.style.position="sticky",M.style.top=`${S}px`,M.style.zIndex=String(g+1),M.style.transformOrigin="center top",M.style.willChange="transform, opacity"}},V=x=>{if(x===k)return;k=x,i.style.setProperty("--fx-stack-active",String(x));for(let c=0;c<n.length;c++)n[c].dataset.active=c===x?"true":"false";for(let c=0;c<l.length;c++){let m=c===x;l[c].dataset.active=m?"true":"false",l[c].classList.toggle("is-active",m)}let S=n[x]??null;t.onChange?.({index:x,total:n.length,focused:!1,element:S}),i.dispatchEvent(new CustomEvent("fluxfx:stackchange",{bubbles:!0,detail:{index:x,total:n.length,element:S}}))},B=()=>{if(n.length===0)return;let x=f(),S=h(x),c=x?-i.scrollTop:i.getBoundingClientRect().top,m=new Array(n.length).fill(0),g=0;for(let M=1;M<n.length;M++){let L=c+p[M],_=Math.max(140,Math.min(v[M]*.85,460)),Z=r?0:Ar((S+_-L)/_);m[M]=Z,L<=S+_*.55&&(g=M)}for(let M=0;M<n.length;M++){let L=0;for(let _=M+1;_<n.length;_++)L+=m[_];w[M]=L}V(g)},P=x=>{for(let S=0;S<n.length;S++){let c=r?0:x[S]??0,m=-c*t.offsetStep,g=Math.max(.55,1-c*t.scaleStep),M=Math.max(.25,1-c*t.opacityStep),L=n[S];L.style.transform=c<.001?"translate3d(0px, 0px, 0px) scale(1)":`translate3d(0px, ${m.toFixed(2)}px, 0px) scale(${g.toFixed(4)})`,L.style.opacity=M.toFixed(3),L.dataset.stackDepth=c.toFixed(3)}},T=()=>{O(),B(),b=w.slice(),P(b),E=!1},A=()=>{if(!R){if(B(),r){b=w.slice(),P(b);return}for(let x=0;x<w.length;x++)if(Math.abs((w[x]??0)-(b[x]??0))>5e-4){E=!0,F?.();break}}},U=()=>{O(),B(),E=!0,F?.()},G=x=>{let c=x.target?.closest(t.tabSelector);if(!c||!i.contains(c))return;let m=c.getAttribute("data-fx-stack-tab"),g=m!==null&&m!==""&&!Number.isNaN(Number(m))?Number(m):-1,M=g>=0?g:l.indexOf(c);if(M<0||M>=n.length)return;let L=f(),_=h(L);if(L){let Z=Math.max(0,(p[M]??0)-_+2);i.scrollTo({top:Z,behavior:r?"auto":"smooth"})}else{let Z=i.getBoundingClientRect().top+window.scrollY,ue=Math.max(0,Z+(p[M]??0)-_+2);window.scrollTo({top:ue,behavior:r?"auto":"smooth"})}},H=x=>{r=t.respectReducedMotion&&x.matches,T()};T();let q=()=>{f()||A()};typeof window<"u"&&(window.addEventListener("scroll",q,{passive:!0}),window.addEventListener("resize",U,{passive:!0})),i.addEventListener("scroll",A,{passive:!0}),i.addEventListener("click",G),o?.addEventListener("change",H);let K=typeof ResizeObserver<"u"?new ResizeObserver(()=>U()):null;return K?.observe(i),{onWake(x){F=x},isIdle(){return!E},pause(){R=!0},resume(){R=!1,A()},update(x,S){if(R||!E||r)return;let c=1-Math.exp(-t.damping*Ge(S,.001,.05)),m=0;for(let g=0;g<w.length;g++){let M=w[g]??0,L=b[g]??0,_=Math.abs(M-L);_<5e-4?b[g]=M:(b[g]=L+(M-L)*c,_>m&&(m=_))}P(b),m<5e-4&&(E=!1)},updateOptions(x){t=Zt(x),r=t.respectReducedMotion&&(o?.matches??!1),u(),T()},destroy(){K?.disconnect(),i.removeEventListener("scroll",A),i.removeEventListener("click",G),typeof window<"u"&&(window.removeEventListener("scroll",q),window.removeEventListener("resize",U)),o?.removeEventListener("change",H),d?i.style.setProperty("--fx-stack-active",d):i.style.removeProperty("--fx-stack-active"),a.forEach((x,S)=>Ur(S,x));for(let x of l)delete x.dataset.active,x.classList.remove("is-active")}}}};ot.register(At).register(Bt).register(Ut).register(It).register(Ot).register(_t).register(Wt).register(zt).register(Nt).register(Gt).register($t).register(Yt).register(Kt).register(Jt);var Ni=ot;typeof window<"u"&&(window.FluxFX=ot);export{it as FluxEngine,Ni as FluxFX,he as WebGLQuad,se as createWebGLEffect};