@votax572002/fluxfx 0.1.5 → 0.1.7

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.
@@ -1,13 +1,13 @@
1
- "use strict";var FluxFXCDN=(()=>{var he=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var pt=Object.getOwnPropertyNames;var vt=Object.prototype.hasOwnProperty;var gt=(o,e)=>{for(var t in e)he(o,t,{get:e[t],enumerable:!0})},bt=(o,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of pt(e))!vt.call(o,r)&&r!==t&&he(o,r,{get:()=>e[r],enumerable:!(i=mt(e,r))||i.enumerable});return o};var xt=o=>bt(he({},"__esModule",{value:!0}),o);var Gt={};gt(Gt,{default:()=>zt});var Le=["normal","reduced-res","low-fps","survival"];var se=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}}},me=class{constructor(){this.mainChannel=new se(30);this.gpuChannel=new se(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 Le[this.currentTier]}getSnapshot(){return{tier:this.currentTier,label:Le[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 n=this.mainChannel.compute();r=Math.max(r,n.avgMs),s=Math.max(s,n.slowRatio)}if(i){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 i=this.currentTier;this.currentTier=e,this.lastTransitionAt=t,e===3?this.scheduleSurvivalProbe():this.clearSurvivalProbe(),this.listeners.forEach(r=>r(e,i))}},V=new me;var pe=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(),V.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),V.recordMainThread(t,e);let r=(e-this.startTime)*.001,s=i*.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,V.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)}},z=new pe;var S=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),n=parseInt(i[1],16),l=parseInt(i[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(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)}};S.vec2Pool=[],S.vec3Pool=[],S.vec4Pool=[],S.scratchVec2=new Float32Array(2),S.scratchVec3=new Float32Array(3),S.scratchVec4=new Float32Array(4);var oe=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 $=null;function E(o,e="#ffffff"){if(typeof o!="string")return e;let t=o.trim();if(!t)return e;if(typeof document<"u"){if(!$){let i=document.createElement("canvas");i.width=1,i.height=1,$=i.getContext("2d")}if($){$.fillStyle="#010203",$.fillStyle=t;let i=$.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 Fe(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,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 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(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 ke(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 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,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 n=window.getComputedStyle(s).backgroundColor,l=Fe(n);if(l&&l[3]>.12)return ke(l[0],l[1],l[2])<.42;s=s.parentElement}return typeof window.matchMedia=="function"?window.matchMedia("(prefers-color-scheme: dark)").matches:!0}function ve(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 n=i-r,l=s>.5?n/(2-i-r):n/(i+r),a=0;return i===o?a=((e-t)/n+(e<t?6:0))/6:i===e?a=((t-o)/n+2)/6:a=((o-e)/n+4)/6,[a,l,s]}function Pe(o,e,t){if(e===0)return[t,t,t];let i=(n,l,a)=>{let c=a;return c<0&&(c+=1),c>1&&(c-=1),c<1/6?n+(l-n)*6*c:c<1/2?l:c<2/3?n+(l-n)*(2/3-c)*6:n},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 ae(o,e){return o.map(([t,i,r])=>{let[s,n,l]=ve(t,i,r);if(e)return[t,i,r];let a=Math.min(n,.72)*.92,c=Math.max(.36,Math.min(.6,l*.78+.14));return Pe(s,a,c)})}function Ae(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=Fe(i);if(r&&r[3]>.14)return r}if(t===e)break;t=t.parentElement}return null}function Be(o,e){let[t,i,r]=ve(e[0],e[1],e[2]),s=ke(e[0],e[1],e[2]);if(i<.2)return ae(o,s<.42);let n=s<.38;return o.map(([l,a,c],u)=>{let[f,h,m]=ve(l,a,c),p=Math.abs(f-t),v=Math.min(p,1-p),g=f;if(v<.22){let F=[.46,.56,.34];g=(t+F[u%F.length])%1}let y=Math.max(.55,Math.min(.92,h<.35?.72:h)),T=n?Math.max(.68,Math.min(.86,m*.45+.48)):Math.max(.24,Math.min(.44,m*.5+.12)),M=Math.abs(T-r)<.22?n?Math.min(.88,r+.34):Math.max(.2,r-.34):T;return Pe(g,y,M)})}var te=`#version 300 es
1
+ "use strict";var FluxFXCDN=(()=>{var lt=Object.defineProperty;var cr=Object.getOwnPropertyDescriptor;var ur=Object.getOwnPropertyNames;var dr=Object.prototype.hasOwnProperty;var fr=(i,e)=>{for(var t in e)lt(i,t,{get:e[t],enumerable:!0})},hr=(i,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ur(e))!dr.call(i,r)&&r!==t&&lt(i,r,{get:()=>e[r],enumerable:!(o=cr(e,r))||o.enumerable});return i};var mr=i=>hr(lt({},"__esModule",{value:!0}),i);var Qr={};fr(Qr,{default:()=>Gr});var Mt=["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}}},ct=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 Mt[this.currentTier]}getSnapshot(){return{tier:this.currentTier,label:Mt[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))}},ge=new ct;var ut=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(),ge.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),ge.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,ge.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 ut;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 wt(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 Ct(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 St(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=wt(n);if(l&&l[3]>.12)return Ct(l[0],l[1],l[2])<.42;s=s.parentElement}return typeof window.matchMedia=="function"?window.matchMedia("(prefers-color-scheme: dark)").matches:!0}function dt(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 Et(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]=dt(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 Et(s,a,d)})}function Rt(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=wt(o);if(r&&r[3]>.14)return r}if(t===e)break;t=t.parentElement}return null}function Lt(i,e){let[t,o,r]=dt(e[0],e[1],e[2]),s=Ct(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]=dt(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 Et(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
- }`,C=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=te){let r=this.contextCache.get(e);r||(r=new Map,this.contextCache.set(e,r));let s=this.hashSource(i,t),n=r.get(s);if(n)return n;e.getExtension("KHR_parallel_shader_compile");let l=this.compileShader(e,e.VERTEX_SHADER,i),a=this.compileShader(e,e.FRAGMENT_SHADER,t),c=e.createProgram();if(!c)throw e.deleteShader(l),e.deleteShader(a),new Error("[FluxFX] Failed to create WebGLProgram");if(e.attachShader(c,l),e.attachShader(c,a),e.linkProgram(c),e.deleteShader(l),e.deleteShader(a),!e.getProgramParameter(c,e.LINK_STATUS)){let f=e.getProgramInfoLog(c);throw e.deleteProgram(c),new Error(`[FluxFX] Program link error:
10
- ${f}`)}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))}};C.contextCache=new WeakMap;var yt=`
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 pr=`
11
11
  let gl = null;
12
12
  let canvas = null;
13
13
  let displayProgram = null;
@@ -855,7 +855,7 @@ self.onmessage = function(e) {
855
855
  break;
856
856
  }
857
857
  };
858
- `,ge=null;function be(){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 Ue(){if(!ge){let o=new Blob([yt],{type:"application/javascript"});ge=URL.createObjectURL(o)}return new Worker(ge)}var Ie=te;var q={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}},Tt=new Float32Array([-1,-1,3,-1,-1,3]),Mt=12;function Oe(){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 _e(){if(typeof navigator>"u")return 8;let o=navigator.userAgent||"",e=/Mobi|Android|iPhone|iPad|iPod/i.test(o);return Oe()||e?6:8}function ie(){return typeof performance<"u"?performance.now():Date.now()}var xe=30,ye=60,Y=1800;function ne(o,e){return 1-Math.exp(-o*e)}var k=class k{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=S.acquireVec2(.5,.5);this.targetMouse=S.acquireVec2(.5,.5);this.mouseVel=S.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=xe;this.activeFps=ye;this.protectionTier=V.tier;this.isSurvivalSuspended=!1;this.unsubscribeGuard=null;this.isBudgetSuspended=!1;this.lastActiveAt=ie();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(Y),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(Y),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&&C.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[i,r]=t;this.isPointerInside=!0,this.targetMouseActive=1,this.boostInteraction(Y),this.protectionTier>=3&&this.applyProtectionState(),this.lastActiveAt=ie(),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(Y),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(Y),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,k.instances.add(this);let i=t.quality??"medium",r=q[i]??q.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 v=this.computeScrollProgress();this.scroll=v,this.targetScroll=v}let{minDpr:a,maxDpr:c}=this.resolveDprBounds(),u=t.dynamicResolution??!0,f=t.offscreen??!0;this.seedUniformsFromOptions(t,!0);let h=typeof window<"u"&&window.innerHeight||0,m=typeof window<"u"&&window.innerWidth||0,p=(t.pauseWhenHidden??!0)&&h>0&&(l.bottom<-50||l.top>h+50||l.right<-50||l.left>m+50);p&&(this.isHiddenByViewport=!0),k.ensureContextBudget(this,p)?f&&be()?this.initOffscreenMode(t,a,c,u):this.initMainThreadMode(t,a,c,u):(this.isBudgetSuspended=!0,this.applyBudgetFallbackStyle()),this.bindObservers(t.pauseWhenHidden??!0),this.unsubscribeGuard=V.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 i=Math.max(this._maxContexts,_e());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=Y){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:xe,activeFps:ye,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:xe,activeFps:ye,feedbackMaxDim:e,suspended:!1}}resolveDprBounds(){let e=this.options.quality??"medium",t=q[e]??q.medium,i=typeof window<"u"&&window.devicePixelRatio||1,r=i>=1.5,s=this.options.maxDpr??Math.min(i,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,i=t+e.height;return i<=0?0:Math.min(1,Math.max(0,(t-e.top)/i))}markContextActive(){this.countedContext||(this.countedContext=!0,k._activeContexts++,k._activeContexts>Mt&&console.warn(`[FluxFX] ${k._activeContexts} active WebGL contexts detected. Browsers typically cap contexts around 8\u201316; consider limiting simultaneous WebGL backgrounds.`))}markContextReleased(){this.countedContext&&(this.countedContext=!1,k._activeContexts=Math.max(0,k._activeContexts-1))}uniformVec3Css(e,t,i=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)),i<1?`rgba(${s}, ${n}, ${l}, ${i})`:`rgb(${s}, ${n}, ${l})`}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),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(),C.disposeContext(t),e||this.canvas.remove();else{this.destroyPingPongMain(),this.destroyMainTextures(),this.vbo&&t.deleteBuffer(this.vbo),this.vao&&t.deleteVertexArray(this.vao),C.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();!k.recycleMainContext(r,t)&&!Oe()&&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||!k.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,n=this.options.offscreen??!0;return this.isBudgetSuspended=!1,this.isContextLost=!1,this.lastActiveAt=ie(),n&&be()?this.initOffscreenMode(this.options,i,r,s):this.initMainThreadMode(this.options,i,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 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 n=l=>{if(this.isDestroyed){this.themeTweenRaf=0;return}let a=Math.min(1,(l-s)/t),c=a<.5?2*a*a:1-Math.pow(-2*a+2,2)/2,u=(p,v)=>[p[0]+(v[0]-p[0])*c,p[1]+(v[1]-p[1])*c,p[2]+(v[2]-p[2])*c],f=u(i[0],r[0]),h=u(i[1],r[1]),m=u(i[2],r[2]);this.activePaletteRgb=[f,h,m],this.pushUniformBatch({uColor1:f,uColor2:h,uColor3:m}),a<1?this.themeTweenRaf=requestAnimationFrame(n):this.themeTweenRaf=0};this.themeTweenRaf=requestAnimationFrame(n)}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=Ae(i,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=Be(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 i=E(t[0],"#6366f1"),r=[];for(let s=0;s<t.length;s++){let n=E(t[s],i),l=S.hexToVec3Into(n,S.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 i=0;i<e.length;i++){let r=e[i],s=Array.isArray(r)?r[0]:r;if(typeof s=="string"&&s.trim()){let n=E(s,"#6366f1"),l=S.hexToVec3Into(n,S.scratchVec3);t.push([l[0],l[1],l[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?ae(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),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 c=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 m=(y,T)=>[y[0]+(T[0]-y[0])*h,y[1]+(T[1]-y[1])*h,y[2]+(T[2]-y[2])*h],p=m(s[0],n[0]),v=m(s[1],n[1]),g=m(s[2],n[2]);this.activePaletteRgb=[p,v,g],this.pushUniformBatch({uTheme:this.currentTheme,uColor1:p,uColor2:v,uColor3:g}),f<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=ae(this.scrollStopsRgb,this.resolvedDarkTheme),r=i.length-1,s=t*r,n=Math.min(r-1,Math.floor(s)),l=s-n,a=i[n],c=i[n+1],u=i[Math.min(i.length-1,n+2)]??a,f=[a[0]+(c[0]-a[0])*l,a[1]+(c[1]-a[1])*l,a[2]+(c[2]-a[2])*l],h=[c[0]+(u[0]-c[0])*l,c[1]+(u[1]-c[1])*l,c[2]+(u[2]-c[2])*l],m=this.basePaletteRgb[2]??u;this.activePaletteRgb=[f,h,m],this.pushUniformBatch({uColor1:f,uColor2:h,uColor3:m})}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 l=this.computeEffectiveQuality();this.customUniforms.set("uQuality",l),i.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),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 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[c,u,f]=this.toTriplet(a);this.activePaletteRgb=[c,u,f],this.customUniforms.set("uColor1",c),this.customUniforms.set("uColor2",u),this.customUniforms.set("uColor3",f),i.uColor1=c,i.uColor2=u,i.uColor3=f,t||(this.currentTheme=s?1:0,this.customUniforms.set("uTheme",this.currentTheme),i.uTheme=this.currentTheme)}}if(e.uniforms)for(let[l,a]of Object.entries(e.uniforms))this.customUniforms.set(l,a),i[l]=typeof a=="number"?a:Array.from(a);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=Ue(),n=this.canvas.transferControlToOffscreen();this.worker=s,this.isOffscreen=!0,this.markContextActive(),s.onmessage=a=>{if(a.data?.type==="error")this.fallbackToMainThread(e,t,i,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 c=typeof a.data.targetFps=="number"?a.data.targetFps:0;this.reportedFrameTimeMs>0&&c>0&&V.recordGpuFrame(this.reportedFrameTimeMs,c,performance.now())}else a.data?.type==="needTextures"&&this.reuploadLoadedTextures()},s.onerror=()=>{this.fallbackToMainThread(e,t,i,r)};let l={};this.customUniforms.forEach((a,c)=>{l[c]=typeof a=="number"?a:Array.from(a)}),s.postMessage({type:"init",canvas:n,width:this.width,height:this.height,minDpr:t,maxDpr:i,dynamicRes:r,reducedMotion:this.isReducedMotion,vertexShader:e.vertexShader??Ie,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,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 n=this.feedbackMaxDim/s;i=Math.max(1,Math.floor(i*n)),r=Math.max(1,Math.floor(r*n))}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 l=(c,u)=>{let f=[];for(let h=0;h<2;h++){let m=e.createTexture(),p=e.createFramebuffer();if(!m||!p)return m&&e.deleteTexture(m),p&&e.deleteFramebuffer(p),f.forEach(v=>{e.deleteFramebuffer(v.fbo),e.deleteTexture(v.tex)}),null;if(e.bindTexture(e.TEXTURE_2D,m),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,p),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,m,0),e.checkFramebufferStatus(e.FRAMEBUFFER)!==e.FRAMEBUFFER_COMPLETE)return e.deleteFramebuffer(p),e.deleteTexture(m),f.forEach(v=>{e.deleteFramebuffer(v.fbo),e.deleteTexture(v.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:p,tex:m})}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 i=this.gl,r=this.fboW,s=this.fboH,n=this.pingPong[this.readIdx],l=[];for(let a=0;a<2;a++){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),l.push({fbo:u,tex:c})}i.bindFramebuffer(i.READ_FRAMEBUFFER,n.fbo),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,l[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 a=0;a<2;a++)i.deleteFramebuffer(this.pingPong[a].fbo),i.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??te;this.programEntry=C.getOrCreateProgram(e,this.options.fragmentShader,t),this.options.feedbackShader?this.feedbackProgramEntry=C.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,Tt,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,n=k.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 oe({minScale:r?t:i,maxScale:i}),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)),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=C.getUniformLocation(e,t,"uTime");s&&e.uniform1f(s,this.elapsedSec);let n=C.getUniformLocation(e,t,"uDelta");n&&e.uniform1f(n,this.lastDeltaSec);let l=C.getUniformLocation(e,t,"uResolution");l&&e.uniform2f(l,i,r);let a=C.getUniformLocation(e,t,"uCanvasResolution");a&&e.uniform2f(a,this.canvas.width,this.canvas.height);let c=C.getUniformLocation(e,t,"uDpr");c&&this.dynamicRes&&e.uniform1f(c,this.dynamicRes.scale);let u=C.getUniformLocation(e,t,"uMouse");u&&e.uniform2f(u,this.mouse[0],this.mouse[1]);let f=C.getUniformLocation(e,t,"uMouseVel");f&&e.uniform2f(f,this.mouseVel[0],this.mouseVel[1]);let h=C.getUniformLocation(e,t,"uMouseDown");h&&e.uniform1f(h,this.mouseDown);let m=C.getUniformLocation(e,t,"uMouseActive");m&&e.uniform1f(m,this.mouseActive);let p=C.getUniformLocation(e,t,"uScroll");p&&e.uniform1f(p,this.scroll);let v=C.getUniformLocation(e,t,"uScrollVel");v&&e.uniform1f(v,this.scrollVel),this.customUniforms.forEach((g,y)=>{let T=C.getUniformLocation(e,t,y);T&&(y==="uSpeed"?e.uniform1f(T,this.currentSpeed):typeof g=="number"?e.uniform1f(T,g):g.length===2?e.uniform2f(T,g[0],g[1]):g.length===3?e.uniform3f(T,g[0],g[1],g[2]):g.length===4&&e.uniform4f(T,g[0],g[1],g[2],g[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=C.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 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=C.getUniformLocation(e,this.programEntry,"uFeedback");t&&e.uniform1i(t,0);let i=C.getUniformLocation(e,this.programEntry,"uPrevFrame");i&&e.uniform1i(i,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 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 n=i<this.boostUntil||this.mouseDown>.5?this.activeFps:this.ambientFps,l=1e3/n-2;if(this.lastDrawNow>0&&i-this.lastDrawNow<l)return;let a=this.lastDrawNow?i-this.lastDrawNow:1e3/n,c=Math.min(a,100);this.lastDrawNow=i,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&&V.recordGpuFrame(a,n,i);let u=Math.max(.001,Math.min(c*.001,.05));if(this.lastDeltaSec=u,this.currentSpeed+=(this.targetSpeed-this.currentSpeed)*ne(7.5,u),this.elapsedSec+=u*this.currentSpeed,this.needsResize&&(this.needsResize=!1,this.applyCanvasSize()),this.mouseActive+=(this.targetMouseActive-this.mouseActive)*ne(7,u),this.mouseActive<.001&&this.targetMouseActive===0&&(this.mouseActive=0),this.targetMouseActive>.5){let f=this.mouse[0],h=this.mouse[1],m=ne(13,u);this.mouse[0]+=(this.targetMouse[0]-this.mouse[0])*m,this.mouse[1]+=(this.targetMouse[1]-this.mouse[1])*m,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)*ne(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:i}=this.resolveDprBounds(),s=this.options.dynamicResolution??!0?t:i,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:i,feedbackMaxDim:this.feedbackMaxDim,ambientFps:this.ambientFps,activeFps:this.activeFps,suspended:this.isSurvivalSuspended}):((this.dynamicRes?.setBounds(s,i)??!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 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=q[e.quality]??q.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()),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 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;k.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=ie(),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=E(t,"#ffffff"),r=S.hexToVec3Into(i,S.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=ie(),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),k.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(),S.releaseVec2(this.mouse),S.releaseVec2(this.targetMouse),S.releaseVec2(this.mouseVel),this.customUniforms.clear(),this.textureUrls.clear(),this.textureUnits.clear(),this.loadedImages.clear(),this.textureLoadTokens.clear(),k.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((i,r)=>{let s=C.getUniformLocation(e,t,r);s&&(e.activeTexture(e.TEXTURE0+i.unit),e.bindTexture(e.TEXTURE_2D,i.tex),e.uniform1i(s,i.unit))})}uploadImageTexture(e,t,i,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,[i,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:i,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]:[i,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,i]of Object.entries(e)){let r=i?this.resolveTextureUrl(i):"",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,c=l.naturalHeight||l.height||1;this.loadedImages.set(t,{url:r,img:l,width:a,height:c}),this.uploadImageTexture(t,l,a,c)},l.onerror=()=>{this.isDestroyed||this.textureLoadTokens.get(t)!==n||console.warn(`[FluxFX] Failed to load texture "${t}" from: ${r}`)},l.src=r}}};k._activeContexts=0,k._maxContexts=_e(),k.instances=new Set,k.recycledMainContexts=[];var H=k;var le=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 i=this.isDeviceAllowed(t.options);i&&!t.instance?this.mountEntryInstance(t)&&(e=!0):!i&&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,i=typeof e.mobileBreakpoint=="number"&&e.mobileBreakpoint>0?e.mobileBreakpoint:768;if(e.disableOnMobile&&t<i||e.disableOnDesktop&&t>=i)return!1;let r=typeof e.device=="string"?e.device.trim().toLowerCase():"all";return!(r==="desktop"&&t<i||r==="mobile"&&t>=i||r==="tablet"&&(t<i||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||z.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 i=this.ensureObserver();if(!i)return;let r=this.visibilityCallbacks.get(e.el);r||(r=new Set,this.visibilityCallbacks.set(e.el,r),i.observe(e.el));let s=n=>{e.visible=n,e.instance&&(n&&!z.isHidden?e.instance.resume?.():e.instance.pause?.(),this.syncTickerState())};r.add(s),e.unobserve=()=>{r?.delete(s),r&&r.size===0&&(i.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 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=z.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=z.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.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){H.setMaxActiveContexts(e)}getStats(){let e=0,t=0,i=!1,r=z.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&&(i=!0)});let s=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,n=H.getRenderStats(),l=z.fps,a=z.frameTimeMs;!r&&n.activeRendering>0&&!i?(l=n.fps,a=n.frameTimeMs):r&&(l=0,a=0);let c=V.getSnapshot();return{mounted:this.activeSet.size,visible:e,pausedEffects:t,activeLoops:z.isRunning?1:0,registered:this.plugins.size,webglContexts:H.activeContexts,activeContexts:H.activeContexts,maxWebGLContexts:H.maxActiveContexts,suspendedContexts:H.suspendedContexts,fps:l,frameTimeMs:a,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 n=s.get(t);n&&n.destroy();let l=!1,a={el:e,name:t,plugin:r,instance:null,options:{...i},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,i={}){let s=this.activeByElement.get(e)?.get(t);if(!s)return!1;s.options={...s.options,...i};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||z.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(i=>{let r=i.getAttribute("data-fx");if(!r)return;let s=r.trim().split(/\s+/).filter(Boolean),n=this.parseDatasetOptions(i),l=this.activeByElement.get(i);s.forEach(a=>{l?.has(a)||this.apply(i,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={},i=new Set(["preserveBg","adaptToSurface","interactive","trackScroll","glare","offscreen","dynamicResolution","pauseWhenHidden","respectReducedMotion","ambient","clickReveal","focused","wrap","clickToFocus","disableOnMobile","disableOnDesktop"]),r=new Set(["colors","lightColors","darkColors","scrollColors"]);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),c=n.trim(),u=c.toLowerCase();c===""&&i.has(a)||u==="true"?t[a]=!0:u==="false"?t[a]=!1:r.has(a)?t[a]=c.split(",").map(f=>f.trim()).filter(Boolean):c!==""&&!Number.isNaN(Number(c))?t[a]=Number(c):t[a]=c}return t}},ce=new le;function Ct(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 He(o){let e=o.replace("#","").trim(),t=e.length===3?e.split("").map(n=>n+n).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 Ve(o,e){if(Array.isArray(o.colors)&&o.colors.length>0){let s=o.colors.filter(Boolean);if(s.length===1){let c=E(s[0],e[0]);return[c,c,c]}if(s.length===2){let c=E(s[0],e[0]),u=E(s[1],e[1]);return[c,u,u]}let n=E(s[0],e[0]),l=E(s[1]??n,e[1]),a=E(s[2]??l,e[2]);return[n,l,a]}if(typeof o.colors=="string"){let s=o.colors.split(",").map(n=>n.trim()).filter(Boolean);if(s.length===1){let n=E(s[0],e[0]);return[n,n,n]}if(s.length===2){let n=E(s[0],e[0]),l=E(s[1],e[1]);return[n,l,l]}if(s.length>2)return[E(s[0],e[0]),E(s[1],e[1]),E(s[2],e[2])]}if(o.color1===void 0&&o.color2===void 0&&o.color3===void 0)return e;let t=E(o.color1,e[0]),i=o.color2!==void 0?E(o.color2,t):t,r=o.color3!==void 0?E(o.color3,i):i;return[t,i,r]}function A(o,e){let t=Ct(o.bgColor),i=!t&&o.bgColor!==void 0&&String(o.bgColor).trim()!=="",r=i?E(o.bgColor,e):e,s=S.hexToVec3Into(r,S.scratchVec3);return{uBgColor:[s[0],s[1],s[2]],uHasBgColor:i?1:0,uTransparentBg:t?1:0,bgHex:r,hasBgColor:i,transparentBg:t}}function wt(o){return o==="high"?.65:o==="low"?.35:.5}function B(o){return{name:o.name,mount(e,t){let i=t.quality??"medium",r=new H(e,{fragmentShader:o.fragmentShader,vertexShader:o.vertexShader,feedbackShader:o.feedbackShader,feedbackScale:o.feedbackShader?wt(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:Ve(t,o.defaultColors),uniforms:o.resolveUniforms?o.resolveUniforms(t):void 0,textures:o.resolveTextures?o.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:Ve(s,o.defaultColors),uniforms:o.resolveUniforms?o.resolveUniforms(s):void 0,textures:o.resolveTextures?o.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 Rt=`#version 300 es
858
+ `,ft=null;function ht(){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 kt(){if(!ft){let i=new Blob([pr],{type:"application/javascript"});ft=URL.createObjectURL(i)}return new Worker(ft)}var Ft=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}},vr=new Float32Array([-1,-1,3,-1,-1,3]),gr=12;function Pt(){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 Dt(){if(typeof navigator>"u")return 8;let i=navigator.userAgent||"",e=/Mobi|Android|iPhone|iPad|iPod/i.test(i);return Pt()||e?6:8}function je(){return typeof performance<"u"?performance.now():Date.now()}var mt=30,pt=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=mt;this.activeFps=pt;this.protectionTier=ge.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&&ht()?this.initOffscreenMode(t,a,d,u):this.initMainThreadMode(t,a,d,u):(this.isBudgetSuspended=!0,this.applyBudgetFallbackStyle()),this.bindObservers(t.pauseWhenHidden??!0),this.unsubscribeGuard=ge.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,Dt());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:mt,activeFps:pt,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:mt,activeFps:pt,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>gr&&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)&&!Pt()&&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&&ht()?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=Rt(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=Lt(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:St(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=kt(),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&&ge.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??Ft,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,vr,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&&ge.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=Dt(),re.instances=new Set,re.recycledMainContexts=[];var be=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){be.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=be.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=ge.getSnapshot();return{mounted:this.activeSet.size,visible:e,pausedEffects:t,activeLoops:xe.isRunning?1:0,registered:this.plugins.size,webglContexts:be.activeContexts,activeContexts:be.activeContexts,maxWebGLContexts:be.maxActiveContexts,suspendedContexts:be.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 br(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 Bt(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 At(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 se(i,e){let t=br(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 yr(i){return i==="high"?.65:i==="low"?.35:.5}function ne(i){return{name:i.name,mount(e,t){let o=t.quality??"medium",r=new be(e,{fragmentShader:i.fragmentShader,vertexShader:i.vertexShader,feedbackShader:i.feedbackShader,feedbackScale:i.feedbackShader?yr(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:At(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:At(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 xr=`#version 300 es
859
859
  precision highp float;
860
860
 
861
861
  in vec2 vUv;
@@ -972,7 +972,7 @@ void main() {
972
972
  lightCol = clamp(lightCol * lightVig + grain * 0.45, 0.0, 1.0);
973
973
 
974
974
  fragColor = vec4(mix(lightCol, darkCol, darkAmt), 1.0);
975
- }`,We=B({name:"aurora",fragmentShader:Rt,defaultColors:["#4f46e5","#06b6d4","#ec4899"],resolveUniforms(o){let e=A(o,"#080a17");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg}}});var St=`#version 300 es
975
+ }`,Ut=ne({name:"aurora",fragmentShader:xr,defaultColors:["#4f46e5","#06b6d4","#ec4899"],resolveUniforms(i){let e=se(i,"#080a17");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg}}});var Tr=`#version 300 es
976
976
  precision highp float;
977
977
 
978
978
  in vec2 vUv;
@@ -1053,7 +1053,7 @@ void main() {
1053
1053
  lightCol = clamp(lightCol, 0.0, 1.0);
1054
1054
 
1055
1055
  fragColor = vec4(mix(lightCol, darkCol, darkAmt), 1.0);
1056
- }`,ze=B({name:"liquid-metal",fragmentShader:St,defaultColors:["#18181b","#94a3b8","#38bdf8"],resolveUniforms(o){let e=A(o,"#0f172a");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg}}});var Et=`#version 300 es
1056
+ }`,It=ne({name:"liquid-metal",fragmentShader:Tr,defaultColors:["#18181b","#94a3b8","#38bdf8"],resolveUniforms(i){let e=se(i,"#0f172a");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg}}});var Mr=`#version 300 es
1057
1057
  precision highp float;
1058
1058
 
1059
1059
  in vec2 vUv;
@@ -1154,7 +1154,7 @@ void main() {
1154
1154
  dye = clamp(dye, vec2(0.0), vec2(1.0));
1155
1155
 
1156
1156
  fragColor = vec4(encodedVel, dye);
1157
- }`,Lt=`#version 300 es
1157
+ }`,wr=`#version 300 es
1158
1158
  precision highp float;
1159
1159
 
1160
1160
  in vec2 vUv;
@@ -1235,7 +1235,7 @@ void main() {
1235
1235
  } else {
1236
1236
  fragColor = vec4(opaqueCol, 1.0);
1237
1237
  }
1238
- }`,Ge=B({name:"fluid",fragmentShader:Lt,feedbackShader:Et,feedbackFloat:!0,defaultColors:["#6366f1","#06b6d4","#f43f5e"],resolveUniforms(o){let e=A(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 Ft=`#version 300 es
1238
+ }`,Ot=ne({name:"fluid",fragmentShader:wr,feedbackShader:Mr,feedbackFloat:!0,defaultColors:["#6366f1","#06b6d4","#f43f5e"],resolveUniforms(i){let e=se(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 Cr=`#version 300 es
1239
1239
  precision highp float;
1240
1240
 
1241
1241
  in vec2 vUv;
@@ -1331,7 +1331,7 @@ void main() {
1331
1331
  vec2 encVel = clamp(vel * 0.5 + 0.5, vec2(0.02), vec2(0.98));
1332
1332
 
1333
1333
  fragColor = vec4(encVel, ink);
1334
- }`,kt=`#version 300 es
1334
+ }`,Sr=`#version 300 es
1335
1335
  precision highp float;
1336
1336
 
1337
1337
  in vec2 vUv;
@@ -1416,7 +1416,7 @@ void main() {
1416
1416
  lightCol = clamp(lightCol * lightVig + grain * 0.5, 0.0, 1.0);
1417
1417
 
1418
1418
  fragColor = vec4(mix(lightCol, darkCol, darkAmt), 1.0);
1419
- }`,Xe=B({name:"ink",fragmentShader:kt,feedbackShader:Ft,feedbackFloat:!0,defaultColors:["#1e1b4b","#0284c7","#e11d48"],resolveUniforms(o){let e=A(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 Dt=`#version 300 es
1419
+ }`,_t=ne({name:"ink",fragmentShader:Sr,feedbackShader:Cr,feedbackFloat:!0,defaultColors:["#1e1b4b","#0284c7","#e11d48"],resolveUniforms(i){let e=se(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 Er=`#version 300 es
1420
1420
  precision highp float;
1421
1421
 
1422
1422
  in vec2 vUv;
@@ -1522,7 +1522,7 @@ void main() {
1522
1522
  vec2 encVel = clamp(vel * 0.5 + 0.5, vec2(0.02), vec2(0.98));
1523
1523
 
1524
1524
  fragColor = vec4(encVel, ink);
1525
- }`,Pt=`#version 300 es
1525
+ }`,Rr=`#version 300 es
1526
1526
  precision highp float;
1527
1527
 
1528
1528
  in vec2 vUv;
@@ -1602,7 +1602,7 @@ void main() {
1602
1602
  } else {
1603
1603
  fragColor = vec4(opaqueCol, 1.0);
1604
1604
  }
1605
- }`,Ne=B({name:"aetheria",fragmentShader:Pt,feedbackShader:Dt,feedbackFloat:!0,defaultColors:["#1e3a5f","#2d3748","#0284c7"],resolveUniforms(o){let e=A(o,"#f5f3ee"),t=typeof o.lightMode=="number"||typeof o.lightMode=="boolean"||e.hasBgColor,i=He(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 At=`#version 300 es
1605
+ }`,Vt=ne({name:"aetheria",fragmentShader:Rr,feedbackShader:Er,feedbackFloat:!0,defaultColors:["#1e3a5f","#2d3748","#0284c7"],resolveUniforms(i){let e=se(i,"#f5f3ee"),t=typeof i.lightMode=="number"||typeof i.lightMode=="boolean"||e.hasBgColor,o=Bt(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 Lr=`#version 300 es
1606
1606
  precision highp float;
1607
1607
 
1608
1608
  in vec2 vUv;
@@ -1825,7 +1825,7 @@ void main() {
1825
1825
  vec3 finalCol = mix(litCol, bgCol + auraCol * 0.25, fog * 0.45);
1826
1826
  float vig = 1.0 - dot(vUv - 0.5, vUv - 0.5) * mix(0.12, 0.55, darkAmt);
1827
1827
  fragColor = vec4(clamp(finalCol * vig, 0.0, 1.0), 1.0);
1828
- }`;function Bt(o){if(typeof o=="number")return o;let e=String(o??"prism").trim().toLowerCase();return e==="torus"?1:e==="orb"||e==="sphere"?2:0}var Qe=B({name:"prism-3d",fragmentShader:At,defaultColors:["#6366f1","#06b6d4","#f472b6"],resolveUniforms(o){let e=A(o,"#070a16");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg,uShape:Bt(o.shape),uDepth:typeof o.depth=="number"?o.depth:1,uGloss:typeof o.gloss=="number"?o.gloss:1,uDistortion:typeof o.distortion=="number"?o.distortion:.35}}});var Ut=`#version 300 es
1828
+ }`;function kr(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 Ht=ne({name:"prism-3d",fragmentShader:Lr,defaultColors:["#6366f1","#06b6d4","#f472b6"],resolveUniforms(i){let e=se(i,"#070a16");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg,uShape:kr(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 Fr=`#version 300 es
1829
1829
  precision highp float;
1830
1830
 
1831
1831
  in vec2 vUv;
@@ -1924,7 +1924,7 @@ void main() {
1924
1924
  float freshEdge = clamp(mix(c.g * 0.88, brushVal, 0.45), 0.0, 1.0);
1925
1925
 
1926
1926
  fragColor = vec4(nextMask, freshEdge, 0.0, 1.0);
1927
- }`,It=`#version 300 es
1927
+ }`,Dr=`#version 300 es
1928
1928
  precision highp float;
1929
1929
 
1930
1930
  in vec2 vUv;
@@ -2077,7 +2077,7 @@ void main() {
2077
2077
  }
2078
2078
 
2079
2079
  fragColor = vec4(col * outAlpha, outAlpha);
2080
- }`;function _t(o){return String(o??"cover").trim().toLowerCase()==="contain"?1:0}function Ot(o){let e=String(o??"center").trim().toLowerCase();return e==="bottom"?[.5,0]:e==="top"?[.5,1]:[.5,.5]}function $e(o){return typeof o=="string"?o.trim():""}function qe(o,e){if(typeof o=="boolean")return o?1:0;if(typeof o=="string"){let t=o.trim().toLowerCase();if(t==="true")return 1;if(t==="false")return 0}return typeof o=="number"?o>.5?1:0:e?1:0}var Ye=B({name:"brush-reveal",fragmentShader:It,feedbackShader:Ut,feedbackFloat:!0,defaultColors:["#ff6b2b","#ffd166","#ffffff"],resolveTextures(o){return{uBaseTex:$e(o.baseImage??o.image),uRevealTex:$e(o.revealImage)}},resolveUniforms(o){let e=A(o,"#000000");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg,uRadius:typeof o.radius=="number"?o.radius:.13,uSoftness:typeof o.softness=="number"?o.softness:.22,uEdgeNoise:typeof o.edgeNoise=="number"?o.edgeNoise:.38,uEdgeGlow:typeof o.edgeGlow=="number"?o.edgeGlow:.24,uDissipation:typeof o.dissipation=="number"?o.dissipation:.985,uFit:_t(o.fit),uPosition:Ot(o.position),uAmbient:qe(o.ambient,!1),uClickReveal:qe(o.clickReveal,!0)}}});var Vt=`#version 300 es
2080
+ }`;function Pr(i){return String(i??"cover").trim().toLowerCase()==="contain"?1:0}function Ar(i){let e=String(i??"center").trim().toLowerCase();return e==="bottom"?[.5,0]:e==="top"?[.5,1]:[.5,.5]}function Wt(i){return typeof i=="string"?i.trim():""}function zt(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 Nt=ne({name:"brush-reveal",fragmentShader:Dr,feedbackShader:Fr,feedbackFloat:!0,defaultColors:["#ff6b2b","#ffd166","#ffffff"],resolveTextures(i){return{uBaseTex:Wt(i.baseImage??i.image),uRevealTex:Wt(i.revealImage)}},resolveUniforms(i){let e=se(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:Pr(i.fit),uPosition:Ar(i.position),uAmbient:zt(i.ambient,!1),uClickReveal:zt(i.clickReveal,!0)}}});var Br=`#version 300 es
2081
2081
  precision highp float;
2082
2082
 
2083
2083
  in vec2 vUv;
@@ -2157,4 +2157,4 @@ void main() {
2157
2157
  }
2158
2158
 
2159
2159
  fragColor = vec4(col, 1.0);
2160
- }`;function Ht(o){if(Array.isArray(o)&&o.length>=2){let t=Number(o[0]),i=Number(o[1]);if(!Number.isNaN(t)&&!Number.isNaN(i))return[t,i]}let e=String(o??"center").trim().toLowerCase();return e==="left"?[.34,.52]:e==="right"?[.66,.52]:[.5,.52]}var je=B({name:"spotlight",fragmentShader:Vt,defaultColors:["#14161a","#4b5563","#f8fafc"],resolveUniforms(o){let e=A(o,"#121316");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg,uSpotRadius:typeof o.spotRadius=="number"?o.spotRadius:.62,uSpotIntensity:typeof o.spotIntensity=="number"?o.spotIntensity:1,uSpotPosition:Ht(o.spotPosition)}}});var Ke={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,n=e.respectReducedMotion??!0,l=o.style.transform,a=o.style.position,c=o.style.overflow,u=o.style.willChange,f=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(prefers-reduced-motion: reduce)"):null,h=n&&(f?.matches??!1);h||(o.style.willChange="transform");let m=null;s&&(getComputedStyle(o).position==="static"&&(o.style.position="relative"),o.style.overflow="hidden",m=document.createElement("div"),Object.assign(m.style,{position:"absolute",inset:"0",pointerEvents:"none",borderRadius:"inherit",opacity:"0",transition:"opacity 0.25s ease",zIndex:"2"}),o.appendChild(m));let p=0,v=0,g=1,y=0,T=0,M=1,F=50,U=50,D=!1,P=!1,w=null,R=null,I=!0,O=()=>{I=!0},re=()=>{let d=o.getBoundingClientRect();R={left:d.left,top:d.top,width:d.width,height:d.height},I=!1},j=d=>{let b=n&&d.matches;h!==b&&(h=b,h?(p=0,v=0,g=1,y=0,T=0,M=1,D=!1,m&&(m.style.opacity="0"),o.style.transform=l,o.style.willChange=u):(o.style.willChange="transform",I=!0),w?.())},K=()=>{I=!0},Z=d=>{if(P||h||((I||!R)&&re(),!R||R.width<=0||R.height<=0))return;let b=(d.clientX-R.left)/R.width,x=(d.clientY-R.top)/R.height;p=(.5-x)*t*2,v=(b-.5)*t*2,g=i,F=b*100,U=x*100,D=!0,m&&(m.style.opacity="1"),w?.()},J=()=>{h||(p=0,v=0,g=1,m&&(m.style.opacity="0"),(Math.abs(y)>.01||Math.abs(T)>.01||Math.abs(M-1)>.001)&&(D=!0,P||w?.()))},X=null;return typeof ResizeObserver<"u"&&(X=new ResizeObserver(O),X.observe(o)),f&&typeof f.addEventListener=="function"&&f.addEventListener("change",j),o.addEventListener("pointerenter",K,{passive:!0}),o.addEventListener("pointermove",Z,{passive:!0}),o.addEventListener("pointerleave",J,{passive:!0}),window.addEventListener("resize",O,{passive:!0}),window.addEventListener("scroll",O,{passive:!0,capture:!0}),{update(d,b){if(!D||P||h)return;let x=1-Math.exp(-12*b);if(y+=(p-y)*x,T+=(v-T)*x,M+=(g-M)*x,m&&(m.style.background=`radial-gradient(circle at ${F.toFixed(1)}% ${U.toFixed(1)}%, rgba(255,255,255,0.22), transparent 60%)`),Math.abs(p-y)<.02&&Math.abs(v-T)<.02&&Math.abs(g-M)<.001){y=p,T=v,M=g,D=!1,o.style.transform=g===1&&p===0&&v===0?l:`perspective(${r}px) rotateX(${y.toFixed(2)}deg) rotateY(${T.toFixed(2)}deg) scale3d(${M.toFixed(3)}, ${M.toFixed(3)}, 1)`;return}o.style.transform=`perspective(${r}px) rotateX(${y.toFixed(2)}deg) rotateY(${T.toFixed(2)}deg) scale3d(${M.toFixed(3)}, ${M.toFixed(3)}, 1)`},isIdle(){return!D||P||h},onWake(d){w=d},pause(){P=!0},resume(){P=!1,I=!0,D&&!h&&w?.()},destroy(){w=null,D=!1,R=null,X?.disconnect(),X=null,f&&typeof f.removeEventListener=="function"&&f.removeEventListener("change",j),o.removeEventListener("pointerenter",K),o.removeEventListener("pointermove",Z),o.removeEventListener("pointerleave",J),window.removeEventListener("resize",O),window.removeEventListener("scroll",O,!0),m?.remove(),o.style.transform=l,o.style.position=a,o.style.overflow=c,o.style.willChange=u}}}};var Ze={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,n=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(prefers-reduced-motion: reduce)"):null,l=i&&(n?.matches??!1);l||(o.style.willChange="transform");let a=0,c=0,u=0,f=0,h=!1,m=!1,p=null,v=null,g=!0,y=()=>{g=!0},T=()=>{let w=o.getBoundingClientRect();v={left:w.left-u,top:w.top-f,width:w.width,height:w.height},g=!1},M=w=>{let R=i&&w.matches;l!==R&&(l=R,l?(a=0,c=0,u=0,f=0,h=!1,o.style.transform=r,o.style.willChange=s):(o.style.willChange="transform",g=!0),p?.())},F=()=>{g=!0},U=w=>{if(m||l||((g||!v)&&T(),!v||v.width<=0||v.height<=0))return;let R=v.left+v.width*.5,I=v.top+v.height*.5;a=(w.clientX-R)*t,c=(w.clientY-I)*t,h=!0,p?.()},D=()=>{l||(a=0,c=0,(Math.abs(u)>.01||Math.abs(f)>.01)&&(h=!0,m||p?.()))},P=null;return typeof ResizeObserver<"u"&&(P=new ResizeObserver(y),P.observe(o)),n&&typeof n.addEventListener=="function"&&n.addEventListener("change",M),o.addEventListener("pointerenter",F,{passive:!0}),o.addEventListener("pointermove",U,{passive:!0}),o.addEventListener("pointerleave",D,{passive:!0}),window.addEventListener("resize",y,{passive:!0}),window.addEventListener("scroll",y,{passive:!0,capture:!0}),{update(w,R){if(!h||m||l)return;let I=1-Math.exp(-10*R);if(u+=(a-u)*I,f+=(c-f)*I,Math.abs(a-u)<.05&&Math.abs(c-f)<.05){u=a,f=c,h=!1,o.style.transform=a===0&&c===0?r:`translate3d(${u.toFixed(2)}px, ${f.toFixed(2)}px, 0)`;return}o.style.transform=`translate3d(${u.toFixed(2)}px, ${f.toFixed(2)}px, 0)`},isIdle(){return!h||m||l},onWake(w){p=w},pause(){m=!0},resume(){m=!1,g=!0,h&&!l&&p?.()},destroy(){p=null,h=!1,v=null,P?.disconnect(),P=null,n&&typeof n.removeEventListener=="function"&&n.removeEventListener("change",M),o.removeEventListener("pointerenter",F),o.removeEventListener("pointermove",U),o.removeEventListener("pointerleave",D),window.removeEventListener("resize",y),window.removeEventListener("scroll",y,!0),o.style.transform=r,o.style.willChange=s}}}};function G(o,e,t){return Math.min(t,Math.max(e,o))}function Q(o,e){return typeof o=="number"&&!Number.isNaN(o)?o:e}function Te(o,e){if(typeof o=="boolean")return o;if(typeof o=="string"){let t=o.trim().toLowerCase();if(t==="true")return!0;if(t==="false")return!1}return e}function Wt(o){return o===!1?0:o===!0||o===void 0?18:typeof o=="number"&&!Number.isNaN(o)?o:18}function Je(o,e){let t=Math.round(Q(o.activeIndex,0));return{activeIndex:e>0?G(t,0,e-1):0,focused:Te(o.focused,!1),wrap:Te(o.wrap,!0),clickToFocus:Te(o.clickToFocus,!0),spread:Q(o.spread,25),depthScale:G(Q(o.depthScale,.22),.05,.45),curve:Q(o.curve,10),parallax:Wt(o.parallax),focusOffsetX:Q(o.focusOffsetX,-15),focusScale:G(Q(o.focusScale,1.07),.8,1.4),perspective:Q(o.perspective,1100),respectReducedMotion:o.respectReducedMotion??!0,onChange:typeof o.onChange=="function"?o.onChange:void 0}}function et(o){let e=Array.from(o.querySelectorAll("[data-fx-slide]"));return e.length>0?e:Array.from(o.children).filter(t=>t instanceof HTMLElement&&!t.hasAttribute("data-fluxfx-canvas"))}function ue(o,e,t,i){let r=o-e;if(i&&t>2){let s=t/2;for(;r>s;)r-=t;for(;r<-s;)r+=t}return r}var tt={name:"depth-carousel",mount(o,e){let t=o.style.position,i=o.style.perspective,r=o.style.transformStyle;typeof window<"u"&&getComputedStyle(o).position==="static"&&(o.style.position="relative");let s=et(o),n=new Map,l=()=>{s=et(o);for(let d of s)n.has(d)||n.set(d,{el:d,transform:d.style.transform,opacity:d.style.opacity,zIndex:d.style.zIndex,filter:d.style.filter,pointerEvents:d.style.pointerEvents,willChange:d.style.willChange})};l();let a=Je(e,s.length);o.style.perspective=`${a.perspective}px`,o.style.transformStyle="preserve-3d";let c=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(prefers-reduced-motion: reduce)"):null,u=a.respectReducedMotion&&(c?.matches??!1),f=a.activeIndex,h=a.activeIndex,m=a.focused?1:0,p=a.focused?1:0,v=0,g=0,y=0,T=0,M=!0,F=!1,U=null,D=null,P=null,w=!1,R=(d=!1)=>{(d||u)&&(f=h,m=p,v=y,g=T);let b=s.length;if(b!==0)for(let x=0;x<b;x++){let L=s[x],W=ue(x,f,b,a.wrap),_=Math.abs(W),N=W*a.spread,ee=Math.max(.45,1-_*a.depthScale),de=-_*160,rt=G(-W*a.curve,-32,32),Ce=_>2.35?0:Math.max(.18,1-_*.32),fe=_<.5,st=fe?a.focusOffsetX:N*1.45,ot=fe?a.focusScale:ee*.85,at=fe?1:0,nt=N+(st-N)*m,lt=ee+(ot-ee)*m,ct=de*(1-m*.5),ut=rt*(1-m),we=Ce+(at-Ce)*m,Re=Math.max(.25,1-_*.25),dt=v*a.parallax*Re,ft=g*(a.parallax*.55)*Re,ht=Math.max(1,20-Math.round(_*4)),Se=_>1.2&&m<.5?Math.min(2.5,(_-1.2)*1.5):0;u||(L.style.willChange="transform, opacity"),L.style.zIndex=String(ht),L.style.opacity=we.toFixed(3),L.style.pointerEvents=we<.08?"none":"auto",L.style.filter=Se>.1?`blur(${Se.toFixed(2)}px)`:"",L.style.transform=`translate3d(calc(${nt.toFixed(2)}% + ${dt.toFixed(2)}px), ${ft.toFixed(2)}px, ${ct.toFixed(1)}px) rotateY(${ut.toFixed(2)}deg) scale(${lt.toFixed(4)})`;let Ee=x===Math.round(h)?"true":"false";L.getAttribute("data-fx-active")!==Ee&&L.setAttribute("data-fx-active",Ee)}},I=()=>{let d=G(Math.round(h),0,Math.max(0,s.length-1)),b=s[d]??null;a.onChange?.({index:d,focused:p>.5,element:b}),o.dispatchEvent(new CustomEvent("fluxfx:change",{bubbles:!0,detail:{index:d,focused:p>.5,element:b}}))},O=(d,b)=>{let x=s.length;if(x===0)return;let L=d;a.wrap?L=(d%x+x)%x:L=G(d,0,x-1);let W=h,_=p;if(a.wrap&&x>2){let N=ue(L,f,x,!0);h=f+N,h=L}else h=L;typeof b=="boolean"&&(p=b?1:0),(h!==W||p!==_)&&I(),M=!0,u?(R(!0),M=!1):F||U?.()},re=d=>{if(F||u)return;let b=o.getBoundingClientRect();b.width<=0||b.height<=0||(y=G(((d.clientX-b.left)/b.width-.5)*2,-1,1),T=G(((d.clientY-b.top)/b.height-.5)*2,-1,1),D!==null&&P===d.pointerId&&Math.abs(d.clientX-D)>22&&(w=!0),M=!0,U?.())},j=()=>{u||(y=0,T=0,M=!0,F||U?.())},K=d=>{F||d.button!==0||(D=d.clientX,P=d.pointerId,w=!1)},Z=d=>{if(D===null||P!==d.pointerId)return;let b=d.clientX-D;if(D=null,P=null,Math.abs(b)>48&&p<.5){let x=b<0?1:-1;O(h+x)}},J=d=>{if(F)return;if(w){w=!1;return}let b=d.target;if(b){if(b.closest("[data-fx-prev]")){O(h-1,!1);return}if(b.closest("[data-fx-next]")){O(h+1,!1);return}for(let x=0;x<s.length;x++)if(s[x]===b||s[x].contains(b)){x!==Math.round(h)?O(x,!1):a.clickToFocus&&O(x,p<.5);return}}},X=d=>{u=a.respectReducedMotion&&d.matches,u&&(R(!0),M=!1),U?.()};return c&&typeof c.addEventListener=="function"&&c.addEventListener("change",X),o.addEventListener("pointermove",re,{passive:!0}),o.addEventListener("pointerleave",j,{passive:!0}),o.addEventListener("pointerdown",K,{passive:!0}),window.addEventListener("pointerup",Z,{passive:!0}),o.addEventListener("click",J),R(!0),M=!1,{update(d,b){if(!M||F||u)return;let x=Math.min(b,.05),L=1-Math.exp(-10.5*x),W=1-Math.exp(-8*x),_=ue(h,f,s.length,a.wrap);f+=_*L,a.wrap&&s.length>0&&(f=(f%s.length+s.length)%s.length),m+=(p-m)*L,v+=(y-v)*W,g+=(T-g)*W,R(!1);let N=Math.abs(ue(h,f,s.length,a.wrap))<.002,ee=Math.abs(p-m)<.003,de=Math.abs(y-v)<.003&&Math.abs(T-g)<.003;N&&ee&&de&&(R(!0),M=!1)},setOptions(d){l();let b=a;a=Je(d,s.length),a.perspective!==b.perspective&&(o.style.perspective=`${a.perspective}px`);let x=d.focused!==void 0?a.focused:p>.5,L=d.activeIndex!==void 0?a.activeIndex:h,W=Math.round(L)!==Math.round(h)||x!==p>.5;h=L,p=x?1:0,W&&I(),M=!0,u?(R(!0),M=!1):F||U?.()},isIdle(){return!M||F||u},onWake(d){U=d},pause(){F=!0},resume(){F=!1,M&&!u&&U?.()},destroy(){U=null,M=!1,c&&typeof c.removeEventListener=="function"&&c.removeEventListener("change",X),o.removeEventListener("pointermove",re),o.removeEventListener("pointerleave",j),o.removeEventListener("pointerdown",K),window.removeEventListener("pointerup",Z),o.removeEventListener("click",J),n.forEach(d=>{d.el.style.transform=d.transform,d.el.style.opacity=d.opacity,d.el.style.zIndex=d.zIndex,d.el.style.filter=d.filter,d.el.style.pointerEvents=d.pointerEvents,d.el.style.willChange=d.willChange,d.el.removeAttribute("data-fx-active")}),n.clear(),o.style.position=t,o.style.perspective=i,o.style.transformStyle=r}}}};ce.register(We).register(ze).register(Ge).register(Xe).register(Ne).register(Qe).register(Ye).register(je).register(Ke).register(Ze).register(tt);var Me=ce;typeof window<"u"&&(window.FluxFX=ce);function it(){Me.init()}typeof document<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",it,{once:!0}):it());var zt=Me;return xt(Gt);})();
2160
+ }`;function Ur(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 Xt=ne({name:"spotlight",fragmentShader:Br,defaultColors:["#14161a","#4b5563","#f8fafc"],resolveUniforms(i){let e=se(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:Ur(i.spotPosition)}}});var Gt={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},X=()=>{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)&&X(),!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 Qt={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 vt(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 Ir(i){return i===!1?0:i===!0||i===void 0?18:typeof i=="number"&&!Number.isNaN(i)?i:18}function $t(i,e){let t=Math.round(Be(i.activeIndex,0));return{activeIndex:e>0?ke(t,0,e-1):0,focused:vt(i.focused,!1),wrap:vt(i.wrap,!0),clickToFocus:vt(i.clickToFocus,!0),spread:Be(i.spread,25),depthScale:ke(Be(i.depthScale,.22),.05,.45),curve:Be(i.curve,10),parallax:Ir(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 Yt={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=$t(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,Ge=ie?a.focusOffsetX:Z*1.45,Ke=ie?a.focusScale:ue*.85,Fe=ie?1:0,Ie=Z+(Ge-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,xt=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(xt),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?.()},X=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",X,{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=$t(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",X),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 pe(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 he(i,e=""){return typeof i=="string"?i.trim():e}function Or(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 _r(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 jt(i){let e=he(i.trigger,"cursor").toLowerCase(),t=e==="scroll"||e==="both"?e:"cursor",o=he(i.axis,"x").toLowerCase(),r=o==="y"||o==="xy"?o:"x",s=he(i.mode,"auto").toLowerCase(),n=s==="atlas"||s==="video"||s==="sprite"?s:"auto",a=he(i.trackTarget,"window").toLowerCase()==="element"?"element":"window",u=he(i.fit,"contain").toLowerCase()==="cover"?"cover":"contain",f=he(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:he(i.videoSrc)||he(i.src),spriteSrc:he(i.spriteSrc),frames:Or(i.frames),poster:he(i.poster),cols:p,rows:v,frameCount:pe(Math.round(le(i.frameCount,b)),2,180),mode:n,trigger:t,axis:r,trackTarget:a,sensitivity:pe(le(i.sensitivity,1),.1,4),damping:pe(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:he(i.chromaKey),chromaTolerance:pe(le(i.chromaTolerance,.22),.01,.65),chromaSoftness:pe(le(i.chromaSoftness,.12),0,.45),crossfade:nt(i.crossfade,!1),targetFps:pe(Math.round(le(i.targetFps,0)),0,120),tileInset:pe(le(i.tileInset,.016),0,.08),maxCacheWidth:pe(Math.round(le(i.maxCacheWidth,720)),160,1920),blendMode:he(i.blendMode,"normal")||"normal",respectReducedMotion:i.respectReducedMotion??!0,onProgress:typeof i.onProgress=="function"?i.onProgress:void 0}}function me(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 Vr(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=_r(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 X=v*(1-ce(U/Math.max(40,u*.68))),H=U>12?Math.min(T,X*.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 X=v*(1-ce(U/Math.max(40,f*.68))),H=U>12?Math.min(T,X*.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 Kt={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=jt(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,X=!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,X=!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=pe(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),me(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:X,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,G=Math.round(D*(j-1));(y||G!==H)&&(H=G,Ce(D,G,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 ve="width"in fe?fe.width:0,qe="height"in fe?fe.height:0;l.clearRect(0,0,c,m),l.save();let ir=(h-.5)*c*.018,Tt=1.032+Math.abs(h-.5)*.012;if(l.translate(c*.5+ir,m),l.rotate((h-.5)*.022),l.scale(Tt,Tt),l.translate(-c*.5,-m),!r.crossfade)l.globalAlpha=1,me(l,fe,ve,qe,c,m,r.fit,r.position);else{let sr=T[Re*r.cols+we]??fe,nr=T[Re*r.cols+Ve]??fe,ar=T[Le*r.cols+we]??fe,lr=T[Le*r.cols+Ve]??fe;l.globalAlpha=1,me(l,sr,ve,qe,c,m,r.fit,r.position),Ve!==we&&Pe>.01&&(l.globalAlpha=Pe,me(l,nr,ve,qe,c,m,r.fit,r.position)),Le!==Re&&ae>.01&&(l.globalAlpha=ae,me(l,ar,ve,qe,c,m,r.fit,r.position)),Ve!==we&&Le!==Re&&Pe>.01&&ae>.01&&(l.globalAlpha=Pe*ae,me(l,lr,ve,qe,c,m,r.fit,r.position))}l.restore();let or=r.cols*r.rows;(y||Ae!==H)&&(H=Ae,Ce(D,Ae,or));return}let G=Math.max(1,Math.min(r.frameCount,T.length)),oe=D*(G-1),te=Math.floor(oe),de=Math.min(G-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,me(l,N,z,J,c,m,r.fit,r.position);else{let Me=T[te]??N,Ee=T[de]??N;l.globalAlpha=1,me(l,Me,z,J,c,m,r.fit,r.position),de!==te&&I>.01&&(l.globalAlpha=I,me(l,Ee,z,J,c,m,r.fit,r.position))}(y||Q!==H)&&(H=Q,Ce(D,Q,G));return}if(P==="sprite"&&A){let j="naturalWidth"in A&&A.naturalWidth>0?A.naturalWidth:A.width,G="naturalHeight"in A&&A.naturalHeight>0?A.naturalHeight:A.height;if(j<=0||G<=0)return;let oe=j/r.cols,te=G/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),me(l,A,j,G,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 G=Z(j);if(G){H=j;let oe="width"in G?G.width:0,te="height"in G?G.height:0;l.clearRect(0,0,c,m),me(l,G,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),me(l,U,U.naturalWidth,U.naturalHeight,c,m,r.fit,r.position))},Ge=async(C,y,D,W=0,j=0,G=y,oe=D)=>{if(G<=0||oe<=0)return null;let te=Math.min(1,r.maxCacheWidth/G),de=Math.max(1,Math.round(G*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,G,oe,0,0,de,I),r.chromaKey&&Vr(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,X||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=pe(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),ve=await Ge(I,Q,N,Ae*J+Ee,fe*Me+we,Re,Ve);if(C!==B||F){ve&&"close"in ve&&typeof ve.close=="function"&&ve.close();return}T[ae]=ve,X=!0,ae===Le&&ie(u,!0)}}catch{A=I,X=!0}}else A=I,X=!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 Ge(z,z.naturalWidth,z.naturalHeight);if(C!==B||F){J&&"close"in J&&typeof J.close=="function"&&J.close(),N();return}T[Q]=J,X=!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",X=!0,ie(u,!0);return}P="atlas";let j=r.frameCount;T=new Array(j).fill(null);let{start:G,span:oe}=ue(S),te=pe(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=pe(G+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 Ge(n,n.videoWidth,n.videoHeight);if(C!==B||F){z&&"close"in z&&typeof z.close=="function"&&z.close();return}T[I]=z,X=!0,(I===te||I===Math.round(u*(j-1)))&&ie(u,!0)}catch{P="video",s.style.display="none",n.style.display="block",X=!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,G=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-G)/(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=jt(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 gt(i,e,t){return Math.min(t,Math.max(e,i))}function bt(i,e){return typeof i=="number"&&!Number.isNaN(i)?i:e}function Hr(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 Zt(i){return{pathSelector:typeof i.pathSelector=="string"&&i.pathSelector.trim()?i.pathSelector.trim():"[data-fx-path], path",damping:gt(bt(i.damping,10),1,40),offsetTop:gt(bt(i.offsetTop,.72),.05,.98),offsetBottom:gt(bt(i.offsetBottom,.35),.02,.95),once:Hr(i.once,!1),respectReducedMotion:i.respectReducedMotion??!0,onWaypoint:typeof i.onWaypoint=="function"?i.onWaypoint:void 0}}var Wr=0,Jt={name:"scroll-path",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(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-${++Wr}`,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?.())},X=()=>{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",X,{passive:!0}),window.addEventListener("scroll",X,{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=Zt(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",X),window.removeEventListener("scroll",X),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 Xe(i,e,t){return Math.min(t,Math.max(e,i))}function zr(i){return Xe(i,0,1)}function at(i,e){return typeof i=="number"&&!Number.isNaN(i)?i:e}function er(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:Xe(at(i.offsetStep,16),0,80),scaleStep:Xe(at(i.scaleStep,.045),0,.2),opacityStep:Xe(at(i.opacityStep,.08),0,.4),damping:Xe(at(i.damping,14),1,45),respectReducedMotion:i.respectReducedMotion??!0,onChange:typeof i.onChange=="function"?i.onChange:void 0}}function Nr(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 Xr(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 tr={name:"card-stack",mount(i,e){let t=er(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,Nr(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:zr((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?.()},X=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",X),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*Xe(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=er(x),r=t.respectReducedMotion&&(o?.matches??!1),u(),T()},destroy(){K?.disconnect(),i.removeEventListener("scroll",A),i.removeEventListener("click",X),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)=>Xr(S,x));for(let x of l)delete x.dataset.active,x.classList.remove("is-active")}}}};ot.register(Ut).register(It).register(Ot).register(_t).register(Vt).register(Ht).register(Nt).register(Xt).register(Gt).register(Qt).register(Yt).register(Kt).register(Jt).register(tr);var yt=ot;typeof window<"u"&&(window.FluxFX=ot);function rr(){yt.init()}typeof document<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",rr,{once:!0}):rr());var Gr=yt;return mr(Qr);})();