@votax572002/fluxfx 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -0
- package/dist/fluxfx.min.js +946 -112
- package/dist/index.cjs +946 -112
- package/dist/index.d.cts +234 -15
- package/dist/index.d.ts +234 -15
- package/dist/index.js +946 -112
- package/dist/react.cjs +946 -112
- package/dist/react.d.cts +191 -46
- package/dist/react.d.ts +191 -46
- package/dist/react.js +946 -112
- package/package.json +48 -48
package/dist/react.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
"use strict";"use client";var pe=Object.create;var A=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var ge=Object.getOwnPropertyNames;var be=Object.getPrototypeOf,ye=Object.prototype.hasOwnProperty;var xe=(o,e)=>{for(var r in e)A(o,r,{get:e[r],enumerable:!0})},q=(o,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ge(e))!ye.call(o,i)&&i!==r&&A(o,i,{get:()=>e[i],enumerable:!(t=ve(e,i))||t.enumerable});return o};var Me=(o,e,r)=>(r=o!=null?pe(be(o)):{},q(e||!o||!o.__esModule?A(r,"default",{value:o,enumerable:!0}):r,o)),Re=o=>q(A({},"__esModule",{value:!0}),o);var Ne={};xe(Ne,{Aetheria:()=>qe,Aurora:()=>Be,Fluid:()=>Xe,Ink:()=>Ge,LiquidMetal:()=>He,Magnetic:()=>ze,TiltCard:()=>We,useFX:()=>E});module.exports=Re(Ne);var x=Me(require("react"),1);var I=class{constructor(){this.listeners=new Set;this.rafId=null;this.startTime=0;this.lastTime=0;this.isDocumentHidden=!1;this.handleVisibilityChange=()=>{this.isDocumentHidden=document.hidden,this.isDocumentHidden?this.stopLoop():this.listeners.size>0&&(this.lastTime=0,this.startLoop())};this.tick=e=>{if(this.listeners.size===0||this.isDocumentHidden){this.stopLoop();return}this.startTime===0&&(this.startTime=e);let r=this.lastTime===0?16.67:Math.min(e-this.lastTime,100);this.lastTime=e;let t=(e-this.startTime)*.001,i=r*.001;this.listeners.forEach(s=>{s(t,i,e)}),this.rafId=window.requestAnimationFrame(this.tick)};typeof document<"u"&&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)}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 activeCount(){return this.listeners.size}get isRunning(){return this.rafId!==null}},B=new I;var v=class{static acquireVec2(e=0,r=0){let t=this.vec2Pool.pop()??new Float32Array(2);return t[0]=e,t[1]=r,t}static releaseVec2(e){this.vec2Pool.length<128&&this.vec2Pool.push(e)}static acquireVec3(e=0,r=0,t=0){let i=this.vec3Pool.pop()??new Float32Array(3);return i[0]=e,i[1]=r,i[2]=t,i}static releaseVec3(e){this.vec3Pool.length<128&&this.vec3Pool.push(e)}static acquireVec4(e=0,r=0,t=0,i=1){let s=this.vec4Pool.pop()??new Float32Array(4);return s[0]=e,s[1]=r,s[2]=t,s[3]=i,s}static releaseVec4(e){this.vec4Pool.length<128&&this.vec4Pool.push(e)}static hexToVec3Into(e,r){let t=e.charCodeAt(0)===35?e.slice(1):e;if(t.length===3){let s=parseInt(t[0],16),a=parseInt(t[1],16),n=parseInt(t[2],16);return r[0]=(s<<4|s)/255,r[1]=(a<<4|a)/255,r[2]=(n<<4|n)/255,r}let i=parseInt(t,16);return Number.isNaN(i)?(r[0]=1,r[1]=1,r[2]=1,r):(r[0]=(i>>16&255)/255,r[1]=(i>>8&255)/255,r[2]=(i&255)/255,r)}};v.vec2Pool=[],v.vec3Pool=[],v.vec4Pool=[],v.scratchVec2=new Float32Array(2),v.scratchVec3=new Float32Array(3),v.scratchVec4=new Float32Array(4);var D=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,r){let t=Math.max(.5,e),i=Math.max(t,r),s=this.currentScale;return this.minScale=t,this.maxScale=i,this.currentScale=Math.min(i,Math.max(t,this.currentScale)),i>s&&(this.currentScale=i),this.sampleCount=0,this.sampleIdx=0,this.stableUpWindows=0,Math.abs(this.currentScale-s)>.01}recordFrame(e,r){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(r-this.lastAdjustAt<this.cooldownMs)return!1;let t=0;for(let s=0;s<this.samples.length;s++)t+=this.samples[s];let i=t/this.samples.length;if(i>this.downThresholdMs&&this.currentScale>this.minScale)return this.currentScale=Math.max(this.minScale,Number((this.currentScale-.15).toFixed(2))),this.stableUpWindows=0,this.lastAdjustAt=r,!0;if(i<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=r,!0}else this.stableUpWindows=0;return!1}};var L=null;function l(o,e="#ffffff"){if(typeof o!="string")return e;let r=o.trim();if(!r)return e;if(typeof document<"u"){if(!L){let t=document.createElement("canvas");t.width=1,t.height=1,L=t.getContext("2d")}if(L){L.fillStyle="#010203",L.fillStyle=r;let t=L.fillStyle;if(/^#[0-9a-f]{6}$/i.test(t))return t;let i=t.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);if(i)return"#"+[Number(i[1]),Number(i[2]),Number(i[3])].map(s=>Math.max(0,Math.min(255,s)).toString(16).padStart(2,"0")).join("")}}return e}var P=`#version 300 es
|
|
2
|
+
"use strict";"use client";var gt=Object.create;var ne=Object.defineProperty;var bt=Object.getOwnPropertyDescriptor;var xt=Object.getOwnPropertyNames;var yt=Object.getPrototypeOf,Tt=Object.prototype.hasOwnProperty;var Mt=(s,e)=>{for(var t in e)ne(s,t,{get:e[t],enumerable:!0})},De=(s,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of xt(e))!Tt.call(s,r)&&r!==t&&ne(s,r,{get:()=>e[r],enumerable:!(i=bt(e,r))||i.enumerable});return s};var Ct=(s,e,t)=>(t=s!=null?gt(yt(s)):{},De(e||!s||!s.__esModule?ne(t,"default",{value:s,enumerable:!0}):t,s)),wt=s=>De(ne({},"__esModule",{value:!0}),s);var si={};Mt(si,{Aetheria:()=>Zt,Aurora:()=>qt,BrushReveal:()=>ti,DepthCarousel:()=>ri,Fluid:()=>Kt,Ink:()=>Jt,LiquidMetal:()=>$t,Magnetic:()=>jt,Prism3D:()=>ei,Spotlight:()=>ii,TiltCard:()=>Yt,useFX:()=>H});module.exports=wt(si);var P=Ct(require("react"),1);var Pe=["normal","reduced-res","low-fps","survival"];var le=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}}},ge=class{constructor(){this.mainChannel=new le(30);this.gpuChannel=new le(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 Pe[this.currentTier]}getSnapshot(){return{tier:this.currentTier,label:Pe[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,o=0;if(t){let n=this.mainChannel.compute();r=Math.max(r,n.avgMs),o=Math.max(o,n.slowRatio)}if(i){let n=this.gpuChannel.compute();r=Math.max(r,n.avgMs),o=Math.max(o,n.slowRatio)}if(this.lastAvgFrameMs=r,this.lastSlowRatio=o,r>22.5||o>=.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&&o<.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))}},W=new ge;var be=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(),W.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),W.recordMainThread(t,e);let r=(e-this.startTime)*.001,o=i*.001;this.listeners.forEach(n=>{n(r,o,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,W.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)}},N=new be;var k=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 o=this.vec4Pool.pop()??new Float32Array(4);return o[0]=e,o[1]=t,o[2]=i,o[3]=r,o}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 o=parseInt(i[0],16),n=parseInt(i[1],16),l=parseInt(i[2],16);return t[0]=(o<<4|o)/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)}};k.vec2Pool=[],k.vec3Pool=[],k.vec4Pool=[],k.scratchVec2=new Float32Array(2),k.scratchVec3=new Float32Array(3),k.scratchVec4=new Float32Array(4);var ce=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),o=this.currentScale;return this.minScale=i,this.maxScale=r,this.currentScale=Math.min(r,Math.max(i,this.currentScale)),r>o&&(this.currentScale=r),this.sampleCount=0,this.sampleIdx=0,this.stableUpWindows=0,Math.abs(this.currentScale-o)>.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 o=0;o<this.samples.length;o++)i+=this.samples[o];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 te=null;function D(s,e="#ffffff"){if(typeof s!="string")return e;let t=s.trim();if(!t)return e;if(typeof document<"u"){if(!te){let i=document.createElement("canvas");i.width=1,i.height=1,te=i.getContext("2d")}if(te){te.fillStyle="#010203",te.fillStyle=t;let i=te.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(o=>Math.max(0,Math.min(255,o)).toString(16).padStart(2,"0")).join("")}}return e}function Ae(s){let e=s.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,o=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,o,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],o=r.length===3?r.split("").map(n=>n+n).join(""):r;return[parseInt(o.slice(0,2),16)/255,parseInt(o.slice(2,4),16)/255,parseInt(o.slice(4,6),16)/255,1]}return null}function Be(s,e,t){let i=r=>r<=.03928?r/12.92:Math.pow((r+.055)/1.055,2.4);return .2126*i(s)+.7152*i(e)+.0722*i(t)}function Ue(s){if(typeof document>"u"||typeof window>"u")return!0;let e=s;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 o=s;for(;o;){let n=window.getComputedStyle(o).backgroundColor,l=Ae(n);if(l&&l[3]>.12)return Be(l[0],l[1],l[2])<.42;o=o.parentElement}return typeof window.matchMedia=="function"?window.matchMedia("(prefers-color-scheme: dark)").matches:!0}function xe(s,e,t){let i=Math.max(s,e,t),r=Math.min(s,e,t),o=(i+r)*.5;if(i===r)return[0,0,o];let n=i-r,l=o>.5?n/(2-i-r):n/(i+r),a=0;return i===s?a=((e-t)/n+(e<t?6:0))/6:i===e?a=((t-s)/n+2)/6:a=((s-e)/n+4)/6,[a,l,o]}function Ie(s,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,o=2*t-r;return[i(o,r,s+1/3),i(o,r,s),i(o,r,s-1/3)]}function ue(s,e){return s.map(([t,i,r])=>{let[o,n,l]=xe(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 Ie(o,a,c)})}function Oe(s,e){if(typeof window>"u"||!s)return null;let t=s;for(;t;){if(t.getAttribute("data-fluxfx-canvas")!=="true"){let i=window.getComputedStyle(t).backgroundColor,r=Ae(i);if(r&&r[3]>.14)return r}if(t===e)break;t=t.parentElement}return null}function _e(s,e){let[t,i,r]=xe(e[0],e[1],e[2]),o=Be(e[0],e[1],e[2]);if(i<.2)return ue(s,o<.42);let n=o<.38;return s.map(([l,a,c],u)=>{let[d,f,h]=xe(l,a,c),m=Math.abs(d-t),v=Math.min(m,1-m),g=d;if(v<.22){let T=[.46,.56,.34];g=(t+T[u%T.length])%1}let b=Math.max(.55,Math.min(.92,f<.35?.72:f)),x=n?Math.max(.68,Math.min(.86,h*.45+.48)):Math.max(.24,Math.min(.44,h*.5+.12)),y=Math.abs(x-r)<.22?n?Math.min(.88,r+.34):Math.max(.2,r-.34):x;return Ie(g,b,y)})}var oe=`#version 300 es
|
|
3
3
|
precision highp float;
|
|
4
4
|
layout(location = 0) in vec2 aPosition;
|
|
5
5
|
out vec2 vUv;
|
|
6
6
|
void main() {
|
|
7
7
|
vUv = aPosition * 0.5 + 0.5;
|
|
8
8
|
gl_Position = vec4(aPosition, 0.0, 1.0);
|
|
9
|
-
}`,
|
|
10
|
-
${
|
|
11
|
-
${
|
|
9
|
+
}`,F=class{static hashSource(e,t){let i=e+"|"+t,r=2166136261;for(let o=0;o<i.length;o++)r^=i.charCodeAt(o),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 o=e.getShaderInfoLog(r);throw e.deleteShader(r),new Error(`[FluxFX] Shader compile error:
|
|
10
|
+
${o}`)}return r}static getOrCreateProgram(e,t,i=oe){let r=this.contextCache.get(e);r||(r=new Map,this.contextCache.set(e,r));let o=this.hashSource(i,t),n=r.get(o);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 d=e.getProgramInfoLog(c);throw e.deleteProgram(c),new Error(`[FluxFX] Program link error:
|
|
11
|
+
${d}`)}let u={program:c,uniforms:new Map};return r.set(o,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))}};F.contextCache=new WeakMap;var Rt=`
|
|
12
12
|
let gl = null;
|
|
13
13
|
let canvas = null;
|
|
14
14
|
let displayProgram = null;
|
|
@@ -19,12 +19,27 @@ let rafId = 0;
|
|
|
19
19
|
|
|
20
20
|
let running = false;
|
|
21
21
|
let pausedByHost = false;
|
|
22
|
+
let survivalPaused = false;
|
|
22
23
|
let reducedMotion = false;
|
|
23
24
|
let contextLost = false;
|
|
24
25
|
let needsResize = false;
|
|
25
26
|
|
|
27
|
+
const AMBIENT_FPS = 30;
|
|
28
|
+
const ACTIVE_FPS = 60;
|
|
29
|
+
const INTERACTION_BOOST_MS = 1800;
|
|
30
|
+
let ambientFps = AMBIENT_FPS;
|
|
31
|
+
let activeFps = ACTIVE_FPS;
|
|
32
|
+
const STATS_REPORT_INTERVAL_MS = 350;
|
|
33
|
+
|
|
34
|
+
let boostUntil = 0;
|
|
35
|
+
let lastRafTime = 0;
|
|
36
|
+
let lastDrawTime = 0;
|
|
37
|
+
let lastTargetFps = 0;
|
|
38
|
+
let prevFrameDrew = false;
|
|
39
|
+
let avgDrawDeltaMs = 0;
|
|
40
|
+
let lastStatsReport = 0;
|
|
41
|
+
|
|
26
42
|
let elapsedSec = 0;
|
|
27
|
-
let lastFrameTime = 0;
|
|
28
43
|
let lastDeltaSec = 0.01667;
|
|
29
44
|
let currentSpeed = 1.0;
|
|
30
45
|
let targetSpeed = 1.0;
|
|
@@ -60,6 +75,7 @@ let lastAdjust = 0;
|
|
|
60
75
|
const displayLocs = new Map();
|
|
61
76
|
const feedbackLocs = new Map();
|
|
62
77
|
const customUniforms = new Map();
|
|
78
|
+
const customTextures = new Map();
|
|
63
79
|
|
|
64
80
|
const mouse = new Float32Array([0.5, 0.5]);
|
|
65
81
|
const targetMouse = new Float32Array([0.5, 0.5]);
|
|
@@ -82,7 +98,12 @@ function cancelFrame(id) {
|
|
|
82
98
|
else clearTimeout(id);
|
|
83
99
|
}
|
|
84
100
|
|
|
85
|
-
|
|
101
|
+
function boostInteraction(durationMs) {
|
|
102
|
+
const until = performance.now() + (durationMs || INTERACTION_BOOST_MS);
|
|
103
|
+
if (until > boostUntil) boostUntil = until;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Frame-rate independent exponential smoothing (identical feel at 30Hz, 60Hz, 120Hz ProMotion)
|
|
86
107
|
function damp(lambda, dt) {
|
|
87
108
|
return 1 - Math.exp(-lambda * dt);
|
|
88
109
|
}
|
|
@@ -138,7 +159,7 @@ function applyUniform(prog, cache, name, val) {
|
|
|
138
159
|
function computeFboDims(canvasW, canvasH) {
|
|
139
160
|
let w = Math.max(1, Math.floor(canvasW * feedbackScale));
|
|
140
161
|
let h = Math.max(1, Math.floor(canvasH * feedbackScale));
|
|
141
|
-
// Cap longest edge so 4K/5K Retina screens stay locked at
|
|
162
|
+
// Cap longest edge so 4K/5K Retina screens stay locked at target FPS
|
|
142
163
|
const longest = Math.max(w, h);
|
|
143
164
|
if (longest > feedbackMaxDim) {
|
|
144
165
|
const ratio = feedbackMaxDim / longest;
|
|
@@ -258,9 +279,9 @@ function applySize() {
|
|
|
258
279
|
canvas.width = w;
|
|
259
280
|
canvas.height = h;
|
|
260
281
|
gl.viewport(0, 0, w, h);
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
282
|
+
}
|
|
283
|
+
if (pingPong) {
|
|
284
|
+
resizePingPong(canvas.width, canvas.height);
|
|
264
285
|
}
|
|
265
286
|
}
|
|
266
287
|
|
|
@@ -333,6 +354,53 @@ function bindCommonUniforms(prog, cache, resW, resH) {
|
|
|
333
354
|
});
|
|
334
355
|
}
|
|
335
356
|
|
|
357
|
+
function destroyCustomTextures() {
|
|
358
|
+
if (!gl) {
|
|
359
|
+
customTextures.clear();
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
customTextures.forEach((entry) => {
|
|
363
|
+
if (entry.tex) gl.deleteTexture(entry.tex);
|
|
364
|
+
});
|
|
365
|
+
customTextures.clear();
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function uploadCustomTexture(name, unit, bitmap, w, h) {
|
|
369
|
+
if (!gl || contextLost) {
|
|
370
|
+
if (bitmap && typeof bitmap.close === 'function') bitmap.close();
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
let entry = customTextures.get(name);
|
|
374
|
+
let tex = entry ? entry.tex : null;
|
|
375
|
+
if (!tex) {
|
|
376
|
+
tex = gl.createTexture();
|
|
377
|
+
}
|
|
378
|
+
gl.activeTexture(gl.TEXTURE0 + unit);
|
|
379
|
+
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
380
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
381
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
382
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
383
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
384
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, bitmap);
|
|
385
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
386
|
+
if (bitmap && typeof bitmap.close === 'function') bitmap.close();
|
|
387
|
+
|
|
388
|
+
customTextures.set(name, { unit: unit, tex: tex, width: w, height: h });
|
|
389
|
+
customUniforms.set(name + 'Size', [w, h]);
|
|
390
|
+
customUniforms.set(name + 'Ready', 1.0);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function bindCustomTextures(prog, cache) {
|
|
394
|
+
if (customTextures.size === 0) return;
|
|
395
|
+
customTextures.forEach((entry, name) => {
|
|
396
|
+
const loc = getLoc(prog, cache, name);
|
|
397
|
+
if (!loc) return;
|
|
398
|
+
gl.activeTexture(gl.TEXTURE0 + entry.unit);
|
|
399
|
+
gl.bindTexture(gl.TEXTURE_2D, entry.tex);
|
|
400
|
+
gl.uniform1i(loc, entry.unit);
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
|
|
336
404
|
function drawFrame() {
|
|
337
405
|
if (!gl || !displayProgram || contextLost) return;
|
|
338
406
|
|
|
@@ -348,6 +416,7 @@ function drawFrame() {
|
|
|
348
416
|
const prevLoc = getLoc(feedbackProgram, feedbackLocs, 'uPrevFrame');
|
|
349
417
|
if (prevLoc) gl.uniform1i(prevLoc, 0);
|
|
350
418
|
|
|
419
|
+
bindCustomTextures(feedbackProgram, feedbackLocs);
|
|
351
420
|
bindCommonUniforms(feedbackProgram, feedbackLocs, fboW, fboH);
|
|
352
421
|
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
353
422
|
|
|
@@ -369,6 +438,7 @@ function drawFrame() {
|
|
|
369
438
|
if (pfLoc) gl.uniform1i(pfLoc, 0);
|
|
370
439
|
}
|
|
371
440
|
|
|
441
|
+
bindCustomTextures(displayProgram, displayLocs);
|
|
372
442
|
bindCommonUniforms(displayProgram, displayLocs, canvas.width, canvas.height);
|
|
373
443
|
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
374
444
|
}
|
|
@@ -410,29 +480,69 @@ function stopLoop() {
|
|
|
410
480
|
running = false;
|
|
411
481
|
cancelFrame(rafId);
|
|
412
482
|
rafId = 0;
|
|
413
|
-
|
|
483
|
+
lastRafTime = 0;
|
|
484
|
+
lastDrawTime = 0;
|
|
485
|
+
lastTargetFps = 0;
|
|
486
|
+
prevFrameDrew = false;
|
|
487
|
+
avgDrawDeltaMs = 0;
|
|
488
|
+
lastStatsReport = 0;
|
|
489
|
+
self.postMessage({ type: 'stats', fps: 0, frameTimeMs: 0, targetFps: 0 });
|
|
414
490
|
}
|
|
415
491
|
|
|
416
492
|
function startLoopIfAllowed() {
|
|
417
|
-
if (running || pausedByHost || reducedMotion || contextLost || !gl) return;
|
|
493
|
+
if (running || pausedByHost || survivalPaused || reducedMotion || contextLost || !gl) return;
|
|
418
494
|
running = true;
|
|
419
|
-
|
|
495
|
+
lastRafTime = 0;
|
|
496
|
+
lastDrawTime = 0;
|
|
497
|
+
prevFrameDrew = false;
|
|
420
498
|
rafId = scheduleFrame(render);
|
|
421
499
|
}
|
|
422
500
|
|
|
423
501
|
function render(now) {
|
|
424
502
|
if (!running || !gl || contextLost) return;
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
503
|
+
|
|
504
|
+
const rafDelta = lastRafTime ? Math.min(now - lastRafTime, 100) : 16.67;
|
|
505
|
+
lastRafTime = now;
|
|
506
|
+
|
|
507
|
+
// Measure dynamic resolution only on frames immediately following a GPU draw
|
|
508
|
+
if (prevFrameDrew) {
|
|
509
|
+
if (updateDynamicRes(rafDelta, now)) {
|
|
510
|
+
needsResize = true;
|
|
511
|
+
}
|
|
512
|
+
prevFrameDrew = false;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
const isBoosted = now < boostUntil || mouseDown > 0.5;
|
|
516
|
+
const targetFps = isBoosted ? activeFps : ambientFps;
|
|
517
|
+
const minIntervalMs = (1000 / targetFps) - 2.0;
|
|
518
|
+
|
|
519
|
+
if (lastDrawTime > 0 && (now - lastDrawTime) < minIntervalMs) {
|
|
520
|
+
rafId = scheduleFrame(render);
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
const rawDrawDelta = lastDrawTime ? (now - lastDrawTime) : (1000 / targetFps);
|
|
525
|
+
const drawDelta = Math.min(rawDrawDelta, 100);
|
|
526
|
+
lastDrawTime = now;
|
|
527
|
+
|
|
528
|
+
if (targetFps !== lastTargetFps) {
|
|
529
|
+
lastTargetFps = targetFps;
|
|
530
|
+
avgDrawDeltaMs = 0;
|
|
531
|
+
} else if (rawDrawDelta > 0 && rawDrawDelta < 500) {
|
|
532
|
+
avgDrawDeltaMs =
|
|
533
|
+
avgDrawDeltaMs === 0
|
|
534
|
+
? rawDrawDelta
|
|
535
|
+
: avgDrawDeltaMs * 0.85 + rawDrawDelta * 0.15;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
const dt = Math.max(0.001, Math.min(drawDelta * 0.001, 0.05));
|
|
428
539
|
lastDeltaSec = dt;
|
|
429
540
|
|
|
430
541
|
// Smoothly ramp speed and integrate phase time (zero jump when speed changes)
|
|
431
542
|
currentSpeed += (targetSpeed - currentSpeed) * damp(7.5, dt);
|
|
432
543
|
elapsedSec += dt * currentSpeed;
|
|
433
544
|
|
|
434
|
-
|
|
435
|
-
if (needsResize || dprChanged) {
|
|
545
|
+
if (needsResize) {
|
|
436
546
|
needsResize = false;
|
|
437
547
|
applySize();
|
|
438
548
|
}
|
|
@@ -459,6 +569,17 @@ function render(now) {
|
|
|
459
569
|
scrollVel = Math.max(-6, Math.min(6, (scrollProgress - prevS) / dt));
|
|
460
570
|
|
|
461
571
|
drawFrame();
|
|
572
|
+
prevFrameDrew = true;
|
|
573
|
+
|
|
574
|
+
if (avgDrawDeltaMs > 0 && now - lastStatsReport >= STATS_REPORT_INTERVAL_MS) {
|
|
575
|
+
lastStatsReport = now;
|
|
576
|
+
self.postMessage({
|
|
577
|
+
type: 'stats',
|
|
578
|
+
fps: Math.round(1000 / avgDrawDeltaMs),
|
|
579
|
+
frameTimeMs: Math.round(avgDrawDeltaMs * 100) / 100,
|
|
580
|
+
targetFps: targetFps,
|
|
581
|
+
});
|
|
582
|
+
}
|
|
462
583
|
|
|
463
584
|
rafId = scheduleFrame(render);
|
|
464
585
|
}
|
|
@@ -468,6 +589,7 @@ function onContextLost(e) {
|
|
|
468
589
|
contextLost = true;
|
|
469
590
|
stopLoop();
|
|
470
591
|
pingPong = null;
|
|
592
|
+
customTextures.clear();
|
|
471
593
|
displayProgram = null;
|
|
472
594
|
feedbackProgram = null;
|
|
473
595
|
}
|
|
@@ -477,6 +599,7 @@ function onContextRestored() {
|
|
|
477
599
|
try {
|
|
478
600
|
contextLost = false;
|
|
479
601
|
buildGLPipeline();
|
|
602
|
+
self.postMessage({ type: 'needTextures' });
|
|
480
603
|
drawFrame();
|
|
481
604
|
if (!reducedMotion) {
|
|
482
605
|
startLoopIfAllowed();
|
|
@@ -499,6 +622,9 @@ self.onmessage = function(e) {
|
|
|
499
622
|
minScale = msg.minDpr;
|
|
500
623
|
dynamicRes = msg.dynamicRes;
|
|
501
624
|
reducedMotion = !!msg.reducedMotion;
|
|
625
|
+
ambientFps = msg.ambientFps || AMBIENT_FPS;
|
|
626
|
+
activeFps = msg.activeFps || ACTIVE_FPS;
|
|
627
|
+
survivalPaused = !!msg.survivalPaused;
|
|
502
628
|
savedVertexSrc = msg.vertexShader;
|
|
503
629
|
savedFragmentSrc = msg.fragmentShader;
|
|
504
630
|
savedFeedbackSrc = msg.feedbackShader || null;
|
|
@@ -549,6 +675,7 @@ self.onmessage = function(e) {
|
|
|
549
675
|
case 'resize':
|
|
550
676
|
width = msg.width;
|
|
551
677
|
height = msg.height;
|
|
678
|
+
boostInteraction(600);
|
|
552
679
|
if (reducedMotion && !pausedByHost && !contextLost) {
|
|
553
680
|
needsResize = false;
|
|
554
681
|
applySize();
|
|
@@ -557,6 +684,34 @@ self.onmessage = function(e) {
|
|
|
557
684
|
needsResize = true;
|
|
558
685
|
}
|
|
559
686
|
break;
|
|
687
|
+
case 'protection':
|
|
688
|
+
ambientFps = msg.ambientFps || AMBIENT_FPS;
|
|
689
|
+
activeFps = msg.activeFps || ACTIVE_FPS;
|
|
690
|
+
minScale = msg.minDpr;
|
|
691
|
+
baseDpr = msg.maxDpr;
|
|
692
|
+
dprScale = baseDpr;
|
|
693
|
+
if (typeof msg.feedbackMaxDim === 'number') {
|
|
694
|
+
feedbackMaxDim = msg.feedbackMaxDim;
|
|
695
|
+
}
|
|
696
|
+
sampleCount = 0;
|
|
697
|
+
sampleIdx = 0;
|
|
698
|
+
stableWindows = 0;
|
|
699
|
+
if (msg.suspended) {
|
|
700
|
+
survivalPaused = true;
|
|
701
|
+
stopLoop();
|
|
702
|
+
} else {
|
|
703
|
+
const wasSuspended = survivalPaused;
|
|
704
|
+
survivalPaused = false;
|
|
705
|
+
if (reducedMotion && !pausedByHost && !contextLost) {
|
|
706
|
+
needsResize = false;
|
|
707
|
+
applySize();
|
|
708
|
+
drawFrame();
|
|
709
|
+
} else {
|
|
710
|
+
needsResize = true;
|
|
711
|
+
if (wasSuspended) startLoopIfAllowed();
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
break;
|
|
560
715
|
case 'dprBounds':
|
|
561
716
|
minScale = msg.minDpr;
|
|
562
717
|
baseDpr = msg.maxDpr;
|
|
@@ -580,11 +735,13 @@ self.onmessage = function(e) {
|
|
|
580
735
|
mouseVel[0] = 0;
|
|
581
736
|
mouseVel[1] = 0;
|
|
582
737
|
targetMouseActive = 1;
|
|
738
|
+
boostInteraction(INTERACTION_BOOST_MS);
|
|
583
739
|
break;
|
|
584
740
|
case 'mouse':
|
|
585
741
|
targetMouse[0] = msg.x;
|
|
586
742
|
targetMouse[1] = msg.y;
|
|
587
743
|
targetMouseActive = 1;
|
|
744
|
+
boostInteraction(INTERACTION_BOOST_MS);
|
|
588
745
|
break;
|
|
589
746
|
case 'mouseLeave':
|
|
590
747
|
targetMouseActive = 0;
|
|
@@ -594,9 +751,11 @@ self.onmessage = function(e) {
|
|
|
594
751
|
break;
|
|
595
752
|
case 'mouseDown':
|
|
596
753
|
mouseDown = msg.down ? 1 : 0;
|
|
754
|
+
boostInteraction(INTERACTION_BOOST_MS);
|
|
597
755
|
break;
|
|
598
756
|
case 'scroll':
|
|
599
757
|
targetScroll = msg.progress;
|
|
758
|
+
boostInteraction(1200);
|
|
600
759
|
if (reducedMotion && !pausedByHost && !contextLost) {
|
|
601
760
|
scrollProgress = targetScroll;
|
|
602
761
|
scrollVel = 0;
|
|
@@ -608,6 +767,7 @@ self.onmessage = function(e) {
|
|
|
608
767
|
if (msg.name === 'uSpeed' && typeof msg.value === 'number') {
|
|
609
768
|
targetSpeed = msg.value;
|
|
610
769
|
}
|
|
770
|
+
boostInteraction(1200);
|
|
611
771
|
if (reducedMotion && !contextLost) drawFrame();
|
|
612
772
|
break;
|
|
613
773
|
case 'uniformsBatch':
|
|
@@ -619,8 +779,24 @@ self.onmessage = function(e) {
|
|
|
619
779
|
}
|
|
620
780
|
}
|
|
621
781
|
}
|
|
782
|
+
boostInteraction(1200);
|
|
783
|
+
if (reducedMotion && !contextLost) drawFrame();
|
|
784
|
+
break;
|
|
785
|
+
case 'texture':
|
|
786
|
+
uploadCustomTexture(msg.name, msg.unit, msg.bitmap, msg.width, msg.height);
|
|
787
|
+
boostInteraction(600);
|
|
622
788
|
if (reducedMotion && !contextLost) drawFrame();
|
|
623
789
|
break;
|
|
790
|
+
case 'clearTexture': {
|
|
791
|
+
const existingTex = customTextures.get(msg.name);
|
|
792
|
+
if (existingTex) {
|
|
793
|
+
if (gl && existingTex.tex) gl.deleteTexture(existingTex.tex);
|
|
794
|
+
customTextures.delete(msg.name);
|
|
795
|
+
}
|
|
796
|
+
customUniforms.set(msg.name + 'Ready', 0.0);
|
|
797
|
+
if (reducedMotion && !contextLost) drawFrame();
|
|
798
|
+
break;
|
|
799
|
+
}
|
|
624
800
|
case 'reducedMotion':
|
|
625
801
|
reducedMotion = !!msg.value;
|
|
626
802
|
if (reducedMotion) {
|
|
@@ -665,11 +841,14 @@ self.onmessage = function(e) {
|
|
|
665
841
|
}
|
|
666
842
|
if (gl) {
|
|
667
843
|
destroyPingPong();
|
|
844
|
+
destroyCustomTextures();
|
|
668
845
|
if (displayProgram) gl.deleteProgram(displayProgram);
|
|
669
846
|
if (feedbackProgram) gl.deleteProgram(feedbackProgram);
|
|
670
847
|
if (vbo) gl.deleteBuffer(vbo);
|
|
671
848
|
if (vao) gl.deleteVertexArray(vao);
|
|
672
|
-
gl.
|
|
849
|
+
if (!gl.isContextLost()) {
|
|
850
|
+
gl.getExtension('WEBGL_lose_context')?.loseContext();
|
|
851
|
+
}
|
|
673
852
|
}
|
|
674
853
|
gl = null;
|
|
675
854
|
canvas = null;
|
|
@@ -677,7 +856,7 @@ self.onmessage = function(e) {
|
|
|
677
856
|
break;
|
|
678
857
|
}
|
|
679
858
|
};
|
|
680
|
-
`,H=null;function N(){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 Q(){if(!H){let o=new Blob([we],{type:"application/javascript"});H=URL.createObjectURL(o)}return new Worker(H)}var j=P;var k={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}},Ee=new Float32Array([-1,-1,3,-1,-1,3]),Fe=12;function U(o,e){return 1-Math.exp(-o*e)}var w=class w{constructor(e,r){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.elapsedSec=0;this.lastDeltaSec=.01667;this.currentSpeed=1;this.targetSpeed=1;this.needsResize=!1;this.pingPong=null;this.fboW=1;this.fboH=1;this.fboFormat=0;this.fboType=0;this.readIdx=0;this.writeIdx=1;this.customUniforms=new Map;this.mouse=v.acquireVec2(.5,.5);this.targetMouse=v.acquireVec2(.5,.5);this.mouseVel=v.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.hasPointerListener=!1;this.countedContext=!1;this.handleContextLost=e=>{e.preventDefault(),this.isContextLost=!0,this.lastRenderNow=0,this.gl&&g.disposeContext(this.gl),this.programEntry=null,this.feedbackProgramEntry=null,this.pingPong=null,this.vao=null,this.vbo=null};this.handleContextRestored=()=>{if(!(this.isDestroyed||!this.gl))try{this.isContextLost=!1,this.initMainThreadPipeline(this.gl),this.drawMainThreadFrame()}catch(e){console.error("[FluxFX] Failed to restore WebGL2 context:",e)}};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;let r=this.getLocalPointerCoords(e);if(!r)return;let[t,i]=r;this.isPointerInside=!0,this.targetMouseActive=1,this.isOffscreen&&this.worker?this.worker.postMessage({type:"mouseEnter",x:t,y:i}):(this.mouse[0]=t,this.mouse[1]=i,this.targetMouse[0]=t,this.targetMouse[1]=i,this.mouseVel[0]=0,this.mouseVel[1]=0)};this.handlePointerMove=e=>{if(this.isPaused||this.isHiddenByViewport||this.isReducedMotion)return;let r=this.getLocalPointerCoords(e);if(!r){this.isPointerInside&&this.handlePointerLeave();return}let[t,i]=r;if(!this.isPointerInside){this.handlePointerEnter(e);return}this.isOffscreen&&this.worker?this.worker.postMessage({type:"mouse",x:t,y:i}):(this.targetMouse[0]=t,this.targetMouse[1]=i)};this.handlePointerLeave=()=>{!this.isPointerInside&&this.targetMouseActive===0||(this.isPointerInside=!1,this.targetMouseActive=0,this.mouseDown=0,this.mouseVel[0]=0,this.mouseVel[1]=0,this.isOffscreen&&this.worker&&this.worker.postMessage({type:"mouseLeave"}))};this.handlePointerDown=e=>{this.isPaused||this.isHiddenByViewport||this.isReducedMotion||(this.isPointerInside||this.handlePointerEnter(e),this.mouseDown=1,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.handleScroll=()=>{if(!this.trackScroll||this.isDestroyed)return;let e=this.computeScrollProgress();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.worker.postMessage({type:"pause"}):!this.isPaused&&!this.isHiddenByViewport&&this.worker.postMessage({type:"resume"}))};this.container=e,this.options={...r},this.interactive=r.interactive??!0,this.respectReducedMotion=r.respectReducedMotion??!0,this.trackScroll=r.trackScroll??!1,this.feedbackScale=r.feedbackScale??.5,this.feedbackFloat=r.feedbackFloat??!0;let t=r.quality??"medium",i=k[t]??k.medium;this.feedbackMaxDim=r.feedbackMaxDim??i.fboMaxDim,typeof window<"u"&&typeof window.matchMedia=="function"&&(this.reducedMotionQuery=window.matchMedia("(prefers-reduced-motion: reduce)"),this.isReducedMotion=this.respectReducedMotion&&this.reducedMotionQuery.matches),window.getComputedStyle(this.container).position==="static"&&(this.container.style.position="relative"),this.container.style.isolation="isolate",this.canvas=document.createElement("canvas"),this.canvas.setAttribute("data-fluxfx-canvas","true"),this.canvas.style.position="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);let a=this.container.getBoundingClientRect();if(this.width=Math.max(1,Math.floor(a.width)),this.height=Math.max(1,Math.floor(a.height)),this.trackScroll){let f=this.computeScrollProgress();this.scroll=f,this.targetScroll=f}let{minDpr:n,maxDpr:u}=this.resolveDprBounds(),c=r.dynamicResolution??!0,d=r.offscreen??!0;this.seedUniformsFromOptions(r,!0),d&&N()?this.initOffscreenMode(r,n,u,c):this.initMainThreadMode(r,n,u,c),this.bindObservers(r.pauseWhenHidden??!0)}static get activeContexts(){return this._activeContexts}resolveDprBounds(){let e=this.options.quality??"medium",r=k[e]??k.medium,t=typeof window<"u"&&window.devicePixelRatio||1,i=t>=1.5,s=this.options.maxDpr??Math.min(t,r.max),a=i?r.retinaMin:r.min;return{minDpr:this.options.minDpr??Math.min(a,s),maxDpr:s}}computeScrollProgress(){if(typeof window>"u")return 0;let e=this.container.getBoundingClientRect(),r=window.innerHeight||1,t=r+e.height;return t<=0?0:Math.min(1,Math.max(0,(r-e.top)/t))}markContextActive(){this.countedContext||(this.countedContext=!0,w._activeContexts++,w._activeContexts>Fe&&console.warn(`[FluxFX] ${w._activeContexts} active WebGL contexts detected. Browsers typically cap contexts around 8\u201316; consider limiting simultaneous WebGL backgrounds.`))}markContextReleased(){this.countedContext&&(this.countedContext=!1,w._activeContexts=Math.max(0,w._activeContexts-1))}seedUniformsFromOptions(e,r=!1){let t={};if(typeof e.speed=="number"?(this.targetSpeed=e.speed,r&&(this.currentSpeed=e.speed),this.customUniforms.set("uSpeed",e.speed),t.uSpeed=e.speed):this.customUniforms.has("uSpeed")||(this.targetSpeed=1,this.currentSpeed=1,this.customUniforms.set("uSpeed",1),t.uSpeed=1),e.colors&&e.colors.length>0){let i=Array.isArray(e.colors)?e.colors:String(e.colors).split(",").map(n=>n.trim()).filter(Boolean),s=l(i[0],"#ffffff"),a=Math.min(i.length,3);for(let n=0;n<a;n++){let u=l(i[n],s),c=v.hexToVec3Into(u,v.scratchVec3),d=[c[0],c[1],c[2]];this.customUniforms.set(`uColor${n+1}`,d),t[`uColor${n+1}`]=d}if(a===1){let n=this.customUniforms.get("uColor1");this.customUniforms.set("uColor2",[n[0],n[1],n[2]]),t.uColor2=[n[0],n[1],n[2]]}}if(e.uniforms)for(let[i,s]of Object.entries(e.uniforms))this.customUniforms.set(i,s),t[i]=typeof s=="number"?s:Array.from(s);return t}fallbackToMainThread(e,r,t,i){if(this.isDestroyed)return;this.worker&&(this.worker.terminate(),this.worker=null),this.isOffscreen=!1,this.markContextReleased();let s=this.canvas.cloneNode(!1);this.canvas.replaceWith(s),this.canvas=s,this.initMainThreadMode(e,r,t,i)}initOffscreenMode(e,r,t,i){try{let s=Q(),a=this.canvas.transferControlToOffscreen();this.worker=s,this.isOffscreen=!0,this.markContextActive(),s.onmessage=u=>{u.data?.type==="error"&&this.fallbackToMainThread(e,r,t,i)},s.onerror=()=>{this.fallbackToMainThread(e,r,t,i)};let n={};this.customUniforms.forEach((u,c)=>{n[c]=typeof u=="number"?u:Array.from(u)}),s.postMessage({type:"init",canvas:a,width:this.width,height:this.height,minDpr:r,maxDpr:t,dynamicRes:i,reducedMotion:this.isReducedMotion,vertexShader:e.vertexShader??j,fragmentShader:e.fragmentShader,feedbackShader:e.feedbackShader??null,feedbackScale:this.feedbackScale,feedbackMaxDim:this.feedbackMaxDim,feedbackFloat:this.feedbackFloat,initialScroll:this.scroll,uniforms:n},[a])}catch{this.isOffscreen=!1,this.markContextReleased(),this.initMainThreadMode(e,r,t,i)}}computeFboDimsMain(e,r){let t=Math.max(1,Math.floor(e*this.feedbackScale)),i=Math.max(1,Math.floor(r*this.feedbackScale)),s=Math.max(t,i);if(s>this.feedbackMaxDim){let a=this.feedbackMaxDim/s;t=Math.max(1,Math.floor(t*a)),i=Math.max(1,Math.floor(i*a))}return[t,i]}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[r,t]=this.computeFboDimsMain(this.canvas.width,this.canvas.height);this.fboW=r,this.fboH=t;let i=e.RGBA8,s=e.UNSIGNED_BYTE;this.feedbackFloat&&(e.getExtension("EXT_color_buffer_float")||e.getExtension("EXT_color_buffer_half_float"))&&(i=e.RGBA16F,s=e.HALF_FLOAT);let n=(c,d)=>{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(b=>{e.deleteFramebuffer(b.fbo),e.deleteTexture(b.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,d,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(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:p,tex:m})}return e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindTexture(e.TEXTURE_2D,null),[f[0],f[1]]},u=n(i,s);!u&&i!==e.RGBA8&&(i=e.RGBA8,s=e.UNSIGNED_BYTE,u=n(i,s)),this.fboFormat=i,this.fboType=s,this.pingPong=u,this.readIdx=0,this.writeIdx=1}resizePingPongMain(){if(!this.pingPong||!this.gl||this.isContextLost)return;let[e,r]=this.computeFboDimsMain(this.canvas.width,this.canvas.height);if(e===this.fboW&&r===this.fboH)return;let t=this.gl,i=this.fboW,s=this.fboH,a=this.pingPong[this.readIdx],n=[];for(let u=0;u<2;u++){let c=t.createTexture(),d=t.createFramebuffer();t.bindTexture(t.TEXTURE_2D,c),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texImage2D(t.TEXTURE_2D,0,this.fboFormat,e,r,0,t.RGBA,this.fboType,null),t.bindFramebuffer(t.FRAMEBUFFER,d),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,c,0),n.push({fbo:d,tex:c})}t.bindFramebuffer(t.READ_FRAMEBUFFER,a.fbo),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,n[0].fbo),t.blitFramebuffer(0,0,i,s,0,0,e,r,t.COLOR_BUFFER_BIT,t.LINEAR),t.bindFramebuffer(t.READ_FRAMEBUFFER,null),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),t.bindTexture(t.TEXTURE_2D,null);for(let u=0;u<2;u++)t.deleteFramebuffer(this.pingPong[u].fbo),t.deleteTexture(this.pingPong[u].tex);this.pingPong=[n[0],n[1]],this.fboW=e,this.fboH=r,this.readIdx=0,this.writeIdx=1}initMainThreadPipeline(e){let r=this.options.vertexShader??P;this.programEntry=g.getOrCreateProgram(e,this.options.fragmentShader,r),this.options.feedbackShader?this.feedbackProgramEntry=g.getOrCreateProgram(e,this.options.feedbackShader,r):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,Ee,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,r,t,i){let s=this.canvas.getContext("webgl2",{alpha:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance",preserveDrawingBuffer:!1});if(!s){console.warn("[FluxFX] WebGL2 is not supported on this device.");return}this.gl=s,this.markContextActive(),this.canvas.addEventListener("webglcontextlost",this.handleContextLost,!1),this.canvas.addEventListener("webglcontextrestored",this.handleContextRestored,!1),this.dynamicRes=new D({minScale:i?r:t,maxScale:t}),this.initMainThreadPipeline(s),this.drawMainThreadFrame()}applyCanvasSize(){if(!this.gl||!this.dynamicRes||this.isContextLost)return;let e=this.dynamicRes.scale,r=Math.max(1,Math.round(this.width*e)),t=Math.max(1,Math.round(this.height*e));(this.canvas.width!==r||this.canvas.height!==t)&&(this.canvas.width=r,this.canvas.height=t,this.gl.viewport(0,0,r,t),this.pingPong&&this.resizePingPongMain())}bindCommonUniformsMain(e,r,t,i){let s=g.getUniformLocation(e,r,"uTime");s&&e.uniform1f(s,this.elapsedSec);let a=g.getUniformLocation(e,r,"uDelta");a&&e.uniform1f(a,this.lastDeltaSec);let n=g.getUniformLocation(e,r,"uResolution");n&&e.uniform2f(n,t,i);let u=g.getUniformLocation(e,r,"uCanvasResolution");u&&e.uniform2f(u,this.canvas.width,this.canvas.height);let c=g.getUniformLocation(e,r,"uDpr");c&&this.dynamicRes&&e.uniform1f(c,this.dynamicRes.scale);let d=g.getUniformLocation(e,r,"uMouse");d&&e.uniform2f(d,this.mouse[0],this.mouse[1]);let f=g.getUniformLocation(e,r,"uMouseVel");f&&e.uniform2f(f,this.mouseVel[0],this.mouseVel[1]);let h=g.getUniformLocation(e,r,"uMouseDown");h&&e.uniform1f(h,this.mouseDown);let m=g.getUniformLocation(e,r,"uMouseActive");m&&e.uniform1f(m,this.mouseActive);let p=g.getUniformLocation(e,r,"uScroll");p&&e.uniform1f(p,this.scroll);let b=g.getUniformLocation(e,r,"uScrollVel");b&&e.uniform1f(b,this.scrollVel),this.customUniforms.forEach((y,S)=>{let R=g.getUniformLocation(e,r,S);R&&(S==="uSpeed"?e.uniform1f(R,this.currentSpeed):typeof y=="number"?e.uniform1f(R,y):y.length===2?e.uniform2f(R,y[0],y[1]):y.length===3?e.uniform3f(R,y[0],y[1],y[2]):y.length===4&&e.uniform4f(R,y[0],y[1],y[2],y[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 r=g.getUniformLocation(e,this.feedbackProgramEntry,"uPrevFrame");r&&e.uniform1i(r,0),this.bindCommonUniformsMain(e,this.feedbackProgramEntry,this.fboW,this.fboH),e.drawArrays(e.TRIANGLES,0,3);let t=this.readIdx;this.readIdx=this.writeIdx,this.writeIdx=t,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 r=g.getUniformLocation(e,this.programEntry,"uFeedback");r&&e.uniform1i(r,0);let t=g.getUniformLocation(e,this.programEntry,"uPrevFrame");t&&e.uniform1i(t,0)}this.bindCommonUniformsMain(e,this.programEntry,this.canvas.width,this.canvas.height),e.drawArrays(e.TRIANGLES,0,3)}render(e,r){if(this.isOffscreen||this.isPaused||this.isHiddenByViewport||this.isReducedMotion||this.isContextLost||this.isDestroyed||!this.gl||!this.programEntry)return;let t=performance.now(),i=this.lastRenderNow?t-this.lastRenderNow:16.67;this.lastRenderNow=t;let s=Math.max(.001,Math.min(i*.001,.05));this.lastDeltaSec=s,this.currentSpeed+=(this.targetSpeed-this.currentSpeed)*U(7.5,s),this.elapsedSec+=s*this.currentSpeed;let a=!1;if(this.needsResize&&(this.needsResize=!1,a=!0),this.dynamicRes&&this.dynamicRes.recordFrame(i,t)&&(a=!0),a&&this.applyCanvasSize(),this.mouseActive+=(this.targetMouseActive-this.mouseActive)*U(7,s),this.mouseActive<.001&&this.targetMouseActive===0&&(this.mouseActive=0),this.targetMouseActive>.5){let n=this.mouse[0],u=this.mouse[1],c=U(13,s);this.mouse[0]+=(this.targetMouse[0]-this.mouse[0])*c,this.mouse[1]+=(this.targetMouse[1]-this.mouse[1])*c,this.mouseVel[0]=Math.max(-8,Math.min(8,(this.mouse[0]-n)/s)),this.mouseVel[1]=Math.max(-8,Math.min(8,(this.mouse[1]-u)/s))}else this.mouseVel[0]=0,this.mouseVel[1]=0;if(this.trackScroll){let n=this.scroll;this.scroll+=(this.targetScroll-this.scroll)*U(9.5,s),this.scrollVel=Math.max(-6,Math.min(6,(this.scroll-n)/s))}this.drawMainThreadFrame()}syncDprBounds(){let{minDpr:e,maxDpr:r}=this.resolveDprBounds(),i=this.options.dynamicResolution??!0?e:r;this.isOffscreen&&this.worker?this.worker.postMessage({type:"dprBounds",minDpr:i,maxDpr:r}):this.dynamicRes&&this.dynamicRes.setBounds(i,r)&&(this.isReducedMotion&&!this.isPaused&&!this.isHiddenByViewport?(this.needsResize=!1,this.applyCanvasSize(),this.drawMainThreadFrame()):this.needsResize=!0)}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 r=this.options.quality;this.options={...this.options,...e};let t=this.seedUniformsFromOptions(e,!1);if((e.quality!==void 0&&e.quality!==r||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()),typeof e.trackScroll=="boolean"&&e.trackScroll!==this.trackScroll&&(this.trackScroll=e.trackScroll,this.syncScrollListener()),typeof e.respectReducedMotion=="boolean"){this.respectReducedMotion=e.respectReducedMotion;let i=this.reducedMotionQuery?.matches??!1;this.applyReducedMotionState(this.respectReducedMotion&&i)}this.isOffscreen&&this.worker?Object.keys(t).length>0&&this.worker.postMessage({type:"uniformsBatch",uniforms:t}):this.isReducedMotion&&(this.needsResize&&(this.needsResize=!1,this.applyCanvasSize()),this.drawMainThreadFrame())}applyReducedMotionState(e){this.isReducedMotion!==e&&(this.isReducedMotion=e,this.lastRenderNow=0,this.isOffscreen&&this.worker?this.worker.postMessage({type:"reducedMotion",value:e}):e&&(this.needsResize&&(this.needsResize=!1,this.applyCanvasSize()),this.drawMainThreadFrame()))}getLocalPointerCoords(e){let r=this.container.getBoundingClientRect();if(r.width<=0||r.height<=0||e.clientX<r.left||e.clientX>r.right||e.clientY<r.top||e.clientY>r.bottom)return null;let t=(e.clientX-r.left)/r.width,i=1-(e.clientY-r.top)/r.height;return[t,i]}syncPointerListener(){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(r=>{let t=r[0];if(!t)return;let i=Math.max(1,Math.floor(t.contentRect.width)),s=Math.max(1,Math.floor(t.contentRect.height));i===this.width&&s===this.height||(this.width=i,this.height=s,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(r=>{let t=r[0]?.isIntersecting??!0;this.isHiddenByViewport=!t,t||this.handlePointerLeave(),this.isOffscreen&&this.worker?this.worker.postMessage({type:t&&!this.isPaused?"resume":"pause"}):t||(this.lastRenderNow=0)},{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.syncPointerListener(),this.syncScrollListener()}setUniform(e,r){this.isDestroyed||(this.customUniforms.set(e,r),e==="uSpeed"&&typeof r=="number"&&(this.targetSpeed=r),this.isOffscreen&&this.worker?this.worker.postMessage({type:"uniform",name:e,value:typeof r=="number"?r:Array.from(r)}):this.isReducedMotion&&this.drawMainThreadFrame())}setColor(e,r){let t=l(r,"#ffffff"),i=v.hexToVec3Into(t,v.scratchVec3);this.setUniform(e,[i[0],i[1],i[2]])}pause(){this.isPaused||this.isDestroyed||(this.isPaused=!0,this.lastRenderNow=0,this.handlePointerLeave(),this.isOffscreen&&this.worker&&this.worker.postMessage({type:"pause"}))}resume(){!this.isPaused||this.isDestroyed||(this.isPaused=!1,this.lastRenderNow=0,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.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.gl&&(this.destroyPingPongMain(),this.vbo&&this.gl.deleteBuffer(this.vbo),this.vao&&this.gl.deleteVertexArray(this.vao),g.disposeContext(this.gl),this.gl.getExtension("WEBGL_lose_context")?.loseContext(),this.gl=null),this.markContextReleased(),v.releaseVec2(this.mouse),v.releaseVec2(this.targetMouse),v.releaseVec2(this.mouseVel),this.customUniforms.clear(),this.canvas.remove())}};w._activeContexts=0;var M=w;var _=class{constructor(){this.plugins=new Map;this.activeByElement=new WeakMap;this.activeSet=new Set;this.visibilityObserver=null;this.visibilityCallbacks=new WeakMap;this.removeTicker=null}ensureObserver(){return typeof window>"u"||typeof IntersectionObserver>"u"?null:(this.visibilityObserver||(this.visibilityObserver=new IntersectionObserver(e=>{for(let r=0;r<e.length;r++){let t=e[r],i=this.visibilityCallbacks.get(t.target);i&&i.forEach(s=>s(t.isIntersecting))}},{rootMargin:"50px"})),this.visibilityObserver)}ensureTicker(){this.removeTicker||(this.removeTicker=B.add((e,r)=>{this.activeSet.forEach(t=>{if(!(!t.visible||t.faulted||!t.instance.update))try{t.instance.update(e,r)}catch(i){t.faulted=!0,console.error(`[FluxFX] Runtime error in "${t.name}" (auto-paused):`,i)}})}))}stopTickerIfEmpty(){this.activeSet.size===0&&this.removeTicker&&(this.removeTicker(),this.removeTicker=null)}register(e){return this.plugins.set(e.name,e),this}has(e){return this.plugins.has(e)}getStats(){let e=0;this.activeSet.forEach(t=>{t.visible&&e++});let r=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;return{mounted:this.activeSet.size,visible:e,activeLoops:B.isRunning?1:0,registered:this.plugins.size,webglContexts:M.activeContexts,reducedMotion:r}}apply(e,r,t={}){let i=this.plugins.get(r);if(!i)return console.warn(`[FluxFX] Effect "${r}" is not registered.`),()=>{};let s=this.activeByElement.get(e);s||(s=new Map,this.activeByElement.set(e,s));let a=s.get(r);a&&a.destroy();let n;try{n=i.mount(e,t)}catch(h){return console.error(`[FluxFX] Failed to mount "${r}":`,h),()=>{}}let u=t.pauseWhenHidden??!0,c=null,d=!1,f={el:e,name:r,plugin:i,instance:n,visible:!0,faulted:!1,destroy:()=>{if(!d){d=!0,c?.(),this.activeSet.delete(f),s?.delete(r);try{f.instance.destroy()}catch(h){console.error(`[FluxFX] Cleanup error in "${r}":`,h)}this.stopTickerIfEmpty()}}};if(u){let h=this.ensureObserver();if(h){let m=this.visibilityCallbacks.get(e);m||(m=new Set,this.visibilityCallbacks.set(e,m),h.observe(e));let p=b=>{f.visible=b,b?f.instance.resume?.():f.instance.pause?.()};m.add(p),c=()=>{m?.delete(p),m&&m.size===0&&(h.unobserve(e),this.visibilityCallbacks.delete(e))}}}return s.set(r,f),this.activeSet.add(f),f.instance.update&&this.ensureTicker(),f.destroy}update(e,r,t={}){let s=this.activeByElement.get(e)?.get(r);if(!s)return!1;if(s.instance.setOptions)try{return s.instance.setOptions(t),!0}catch(a){return console.error(`[FluxFX] Hot-update error in "${r}":`,a),!1}try{return s.instance.destroy(),s.instance=s.plugin.mount(e,t),s.faulted=!1,s.visible||s.instance.pause?.(),s.instance.update&&this.ensureTicker(),!0}catch(a){return s.faulted=!0,console.error(`[FluxFX] Fallback remount error in "${r}":`,a),!1}}scan(e=document){if(typeof document>"u")return;e.querySelectorAll("[data-fx]").forEach(t=>{let i=t.getAttribute("data-fx");if(!i)return;let s=i.trim().split(/\s+/).filter(Boolean),a=this.parseDatasetOptions(t),n=this.activeByElement.get(t);s.forEach(u=>{n?.has(u)||this.apply(t,u,a)})})}init(e){typeof document>"u"||(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>this.scan(e??document),{once:!0}):this.scan(e??document))}destroyAll(){let e=Array.from(this.activeSet);for(let r=0;r<e.length;r++)e[r].destroy()}parseDatasetOptions(e){let r={};for(let[t,i]of Object.entries(e.dataset)){if(!t.startsWith("fx")||t==="fx"||i===void 0)continue;let s=t.slice(2),a=s.charAt(0).toLowerCase()+s.slice(1);i==="true"?r[a]=!0:i==="false"?r[a]=!1:i!==""&&!Number.isNaN(Number(i))?r[a]=Number(i):r[a]=i}return r}},O=new _;var Te=`#version 300 es
|
|
859
|
+
`,ye=null;function Te(){if(typeof window>"u"||typeof Worker>"u"||typeof OffscreenCanvas>"u"||typeof HTMLCanvasElement>"u"||!("transferControlToOffscreen"in HTMLCanvasElement.prototype))return!1;let s=typeof navigator<"u"?navigator.userAgent:"";return!(/iP(ad|hone|od)/i.test(s)||/^((?!chrome|android).)*safari/i.test(s))}function Ve(){if(!ye){let s=new Blob([Rt],{type:"application/javascript"});ye=URL.createObjectURL(s)}return new Worker(ye)}var He=oe;var ie={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}},Et=new Float32Array([-1,-1,3,-1,-1,3]),St=12;function Ge(){if(typeof navigator>"u")return!1;let s=navigator.userAgent||"";return/Safari/i.test(s)&&!/Chrome|Chromium|Edg|CriOS|FxiOS|OPR/i.test(s)}function We(){if(typeof navigator>"u")return 8;let s=navigator.userAgent||"",e=/Mobi|Android|iPhone|iPad|iPod/i.test(s);return Ge()||e?6:8}function ae(){return typeof performance<"u"?performance.now():Date.now()}var Me=30,Ce=60,re=1800;function de(s,e){return 1-Math.exp(-s*e)}var B=class B{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=k.acquireVec2(.5,.5);this.targetMouse=k.acquireVec2(.5,.5);this.mouseVel=k.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=Me;this.activeFps=Ce;this.protectionTier=W.tier;this.isSurvivalSuspended=!1;this.unsubscribeGuard=null;this.isBudgetSuspended=!1;this.lastActiveAt=ae();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,o]=i;this.inspectSurfaceFromTarget(t.target,!0),this.isPointerInside=!0,this.targetMouseActive=1,this.mouseDown=1,this.boostInteraction(re),this.isOffscreen&&this.worker?(this.worker.postMessage({type:"mouseEnter",x:r,y:o}),this.worker.postMessage({type:"mouseDown",down:!0})):(this.mouse[0]=r,this.mouse[1]=o,this.targetMouse[0]=r,this.targetMouse[1]=o,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,o]=i;this.inspectSurfaceFromTarget(t.target),this.boostInteraction(re),this.targetMouseActive=1,this.isOffscreen&&this.worker?this.worker.postMessage({type:"mouse",x:r,y:o}):(this.targetMouse[0]=r,this.targetMouse[1]=o)};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&&F.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(re),this.protectionTier>=3&&this.applyProtectionState(),this.lastActiveAt=ae(),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(re),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(re),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,B.instances.add(this);let i=t.quality??"medium",r=ie[i]??ie.medium;this.baseFeedbackMaxDim=t.feedbackMaxDim??r.fboMaxDim;let o=this.resolveTierConfig();this.ambientFps=o.ambientFps,this.activeFps=o.activeFps,this.feedbackMaxDim=o.feedbackMaxDim,this.isSurvivalSuspended=o.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,d=t.offscreen??!0;this.seedUniformsFromOptions(t,!0);let f=typeof window<"u"&&window.innerHeight||0,h=typeof window<"u"&&window.innerWidth||0,m=(t.pauseWhenHidden??!0)&&f>0&&(l.bottom<-50||l.top>f+50||l.right<-50||l.left>h+50);m&&(this.isHiddenByViewport=!0),B.ensureContextBudget(this,m)?d&&Te()?this.initOffscreenMode(t,a,c,u):this.initMainThreadMode(t,a,c,u):(this.isBudgetSuspended=!0,this.applyBudgetFallbackStyle()),this.bindObservers(t.pauseWhenHidden??!0),this.unsubscribeGuard=W.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,We());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(o=>{o===e||o.isDestroyed||o.isBudgetSuspended||!o.countedContext||(o.isHiddenByViewport||o.isPaused?(!i||o.lastActiveAt<i.lastActiveAt)&&(i=o):t&&!o.isPointerInside&&o.mouseDown===0&&(!r||o.lastActiveAt<r.lastActiveAt)&&(r=o))}),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=re){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:Me,activeFps:Ce,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:Me,activeFps:Ce,feedbackMaxDim:e,suspended:!1}}resolveDprBounds(){let e=this.options.quality??"medium",t=ie[e]??ie.medium,i=typeof window<"u"&&window.devicePixelRatio||1,r=i>=1.5,o=this.options.maxDpr??Math.min(i,t.max),n=r?t.retinaMin:t.min,l=this.options.minDpr??Math.min(n,o);if(this.protectionTier===1){let a=Math.max(.65,Number((o*.75).toFixed(2)));return{minDpr:Math.min(l,a),maxDpr:a}}if(this.protectionTier>=2){let a=Math.max(.55,Math.min(l,Number((o*.6).toFixed(2))));return{minDpr:a,maxDpr:a}}return{minDpr:l,maxDpr:o}}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,B._activeContexts++,B._activeContexts>St&&console.warn(`[FluxFX] ${B._activeContexts} active WebGL contexts detected. Browsers typically cap contexts around 8\u201316; consider limiting simultaneous WebGL backgrounds.`))}markContextReleased(){this.countedContext&&(this.countedContext=!1,B._activeContexts=Math.max(0,B._activeContexts-1))}uniformVec3Css(e,t,i=1){let r=this.customUniforms.get(e),o=t[0],n=t[1],l=t[2];return r&&typeof r!="number"&&r.length>=3&&(o=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(${o}, ${n}, ${l}, ${i})`:`rgb(${o}, ${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,o=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%, ${o}, 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(),F.disposeContext(t),e||this.canvas.remove();else{this.destroyPingPongMain(),this.destroyMainTextures(),this.vbo&&t.deleteBuffer(this.vbo),this.vao&&t.deleteVertexArray(this.vao),F.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 o=this.canvas.cloneNode(!1);this.canvas.replaceWith(o),this.canvas=o}else this.canvas.remove();!B.recycleMainContext(r,t)&&!Ge()&&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||!B.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(),o=this.options.dynamicResolution??!0,n=this.options.offscreen??!0;return this.isBudgetSuspended=!1,this.isContextLost=!1,this.lastActiveAt=ae(),n&&Te()?this.initOffscreenMode(this.options,i,r,o):this.initMainThreadMode(this.options,i,r,o),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 o=performance.now();this.boostInteraction(420);let n=l=>{if(this.isDestroyed){this.themeTweenRaf=0;return}let a=Math.min(1,(l-o)/t),c=a<.5?2*a*a:1-Math.pow(-2*a+2,2)/2,u=(m,v)=>[m[0]+(v[0]-m[0])*c,m[1]+(v[1]-m[1])*c,m[2]+(v[2]-m[2])*c],d=u(i[0],r[0]),f=u(i[1],r[1]),h=u(i[2],r[2]);this.activePaletteRgb=[d,f,h],this.pushUniformBatch({uColor1:d,uColor2:f,uColor3:h}),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 o=Oe(i,this.container);if(!o){this.isSurfaceAdapted&&(this.isSurfaceAdapted=!1,this.lastSurfaceKey="",this.startPaletteTween(this.basePaletteRgb,220));return}let n=`${Math.round(o[0]*255)},${Math.round(o[1]*255)},${Math.round(o[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=_e(l,[o[0],o[1],o[2]]);this.isSurfaceAdapted=!0,this.startPaletteTween(a,220)}parseColorList(e){if(!e)return[];let t=Array.isArray(e)?e:String(e).split(",").map(o=>o.trim()).filter(Boolean);if(t.length===0)return[];let i=D(t[0],"#6366f1"),r=[];for(let o=0;o<t.length;o++){let n=D(t[o],i),l=k.hexToVec3Into(n,k.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],o=Array.isArray(r)?r[0]:r;if(typeof o=="string"&&o.trim()){let n=D(o,"#6366f1"),l=k.hexToVec3Into(n,k.scratchVec3);t.push([l[0],l[1],l[2]])}}return t}detectDarkTheme(e){return e==="dark"?!0:e==="light"?!1:Ue(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?ue(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,o=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 d=Math.min(1,(u-l)/a),f=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;this.currentTheme=r+(t-r)*f;let h=(b,x)=>[b[0]+(x[0]-b[0])*f,b[1]+(x[1]-b[1])*f,b[2]+(x[2]-b[2])*f],m=h(o[0],n[0]),v=h(o[1],n[1]),g=h(o[2],n[2]);this.activePaletteRgb=[m,v,g],this.pushUniformBatch({uTheme:this.currentTheme,uColor1:m,uColor2:v,uColor3:g}),d<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=ue(this.scrollStopsRgb,this.resolvedDarkTheme),r=i.length-1,o=t*r,n=Math.min(r-1,Math.floor(o)),l=o-n,a=i[n],c=i[n+1],u=i[Math.min(i.length-1,n+2)]??a,d=[a[0]+(c[0]-a[0])*l,a[1]+(c[1]-a[1])*l,a[2]+(c[2]-a[2])*l],f=[c[0]+(u[0]-c[0])*l,c[1]+(u[1]-c[1])*l,c[2]+(u[2]-c[2])*l],h=this.basePaletteRgb[2]??u;this.activePaletteRgb=[d,f,h],this.pushUniformBatch({uColor1:d,uColor2:f,uColor3:h})}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 o=this.detectDarkTheme(this.themeMode);if(this.resolvedDarkTheme=o,t&&(this.currentTheme=o?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(o);if(a.length>0)if(this.basePaletteRgb=a,this.rawBasePaletteRgb.length===0&&(this.rawBasePaletteRgb=a),!t&&o!==r)this.startThemeTransition(o);else{let[c,u,d]=this.toTriplet(a);this.activePaletteRgb=[c,u,d],this.customUniforms.set("uColor1",c),this.customUniforms.set("uColor2",u),this.customUniforms.set("uColor3",d),i.uColor1=c,i.uColor2=u,i.uColor3=d,t||(this.currentTheme=o?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 o=this.canvas.cloneNode(!1);this.canvas.replaceWith(o),this.canvas=o,this.initMainThreadMode(e,t,i,r)}initOffscreenMode(e,t,i,r){try{let o=Ve(),n=this.canvas.transferControlToOffscreen();this.worker=o,this.isOffscreen=!0,this.markContextActive(),o.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&&W.recordGpuFrame(this.reportedFrameTimeMs,c,performance.now())}else a.data?.type==="needTextures"&&this.reuploadLoadedTextures()},o.onerror=()=>{this.fallbackToMainThread(e,t,i,r)};let l={};this.customUniforms.forEach((a,c)=>{l[c]=typeof a=="number"?a:Array.from(a)}),o.postMessage({type:"init",canvas:n,width:this.width,height:this.height,minDpr:t,maxDpr:i,dynamicRes:r,reducedMotion:this.isReducedMotion,vertexShader:e.vertexShader??He,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)),o=Math.max(i,r);if(o>this.feedbackMaxDim){let n=this.feedbackMaxDim/o;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,o=e.UNSIGNED_BYTE;this.feedbackFloat&&(e.getExtension("EXT_color_buffer_float")||e.getExtension("EXT_color_buffer_half_float"))&&(r=e.RGBA16F,o=e.HALF_FLOAT);let l=(c,u)=>{let d=[];for(let f=0;f<2;f++){let h=e.createTexture(),m=e.createFramebuffer();if(!h||!m)return h&&e.deleteTexture(h),m&&e.deleteFramebuffer(m),d.forEach(v=>{e.deleteFramebuffer(v.fbo),e.deleteTexture(v.tex)}),null;if(e.bindTexture(e.TEXTURE_2D,h),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texImage2D(e.TEXTURE_2D,0,c,this.fboW,this.fboH,0,e.RGBA,u,null),e.bindFramebuffer(e.FRAMEBUFFER,m),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,h,0),e.checkFramebufferStatus(e.FRAMEBUFFER)!==e.FRAMEBUFFER_COMPLETE)return e.deleteFramebuffer(m),e.deleteTexture(h),d.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),d.push({fbo:m,tex:h})}return e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindTexture(e.TEXTURE_2D,null),[d[0],d[1]]},a=l(r,o);!a&&r!==e.RGBA8&&(r=e.RGBA8,o=e.UNSIGNED_BYTE,a=l(r,o)),this.fboFormat=r,this.fboType=o,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,o=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,o,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??oe;this.programEntry=F.getOrCreateProgram(e,this.options.fragmentShader,t),this.options.feedbackShader?this.feedbackProgramEntry=F.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,Et,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 o=null,n=B.acquireRecycledMainContext();if(n?(n.canvas.style.background="",this.canvas.replaceWith(n.canvas),this.canvas=n.canvas,o=n.gl):o=this.canvas.getContext("webgl2",{alpha:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance",preserveDrawingBuffer:!1}),!o){console.warn("[FluxFX] WebGL2 is not supported on this device."),this.isBudgetSuspended=!0,this.applyBudgetFallbackStyle();return}this.gl=o,this.markContextActive(),this.canvas.addEventListener("webglcontextlost",this.handleContextLost,!1),this.canvas.addEventListener("webglcontextrestored",this.handleContextRestored,!1),this.dynamicRes=new ce({minScale:r?t:i,maxScale:i}),this.initMainThreadPipeline(o),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 o=F.getUniformLocation(e,t,"uTime");o&&e.uniform1f(o,this.elapsedSec);let n=F.getUniformLocation(e,t,"uDelta");n&&e.uniform1f(n,this.lastDeltaSec);let l=F.getUniformLocation(e,t,"uResolution");l&&e.uniform2f(l,i,r);let a=F.getUniformLocation(e,t,"uCanvasResolution");a&&e.uniform2f(a,this.canvas.width,this.canvas.height);let c=F.getUniformLocation(e,t,"uDpr");c&&this.dynamicRes&&e.uniform1f(c,this.dynamicRes.scale);let u=F.getUniformLocation(e,t,"uMouse");u&&e.uniform2f(u,this.mouse[0],this.mouse[1]);let d=F.getUniformLocation(e,t,"uMouseVel");d&&e.uniform2f(d,this.mouseVel[0],this.mouseVel[1]);let f=F.getUniformLocation(e,t,"uMouseDown");f&&e.uniform1f(f,this.mouseDown);let h=F.getUniformLocation(e,t,"uMouseActive");h&&e.uniform1f(h,this.mouseActive);let m=F.getUniformLocation(e,t,"uScroll");m&&e.uniform1f(m,this.scroll);let v=F.getUniformLocation(e,t,"uScrollVel");v&&e.uniform1f(v,this.scrollVel),this.customUniforms.forEach((g,b)=>{let x=F.getUniformLocation(e,t,b);x&&(b==="uSpeed"?e.uniform1f(x,this.currentSpeed):typeof g=="number"?e.uniform1f(x,g):g.length===2?e.uniform2f(x,g[0],g[1]):g.length===3?e.uniform3f(x,g[0],g[1],g[2]):g.length===4&&e.uniform4f(x,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=F.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=F.getUniformLocation(e,this.programEntry,"uFeedback");t&&e.uniform1i(t,0);let i=F.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&&W.recordGpuFrame(a,n,i);let u=Math.max(.001,Math.min(c*.001,.05));if(this.lastDeltaSec=u,this.currentSpeed+=(this.targetSpeed-this.currentSpeed)*de(7.5,u),this.elapsedSec+=u*this.currentSpeed,this.needsResize&&(this.needsResize=!1,this.applyCanvasSize()),this.mouseActive+=(this.targetMouseActive-this.mouseActive)*de(7,u),this.mouseActive<.001&&this.targetMouseActive===0&&(this.mouseActive=0),this.targetMouseActive>.5){let d=this.mouse[0],f=this.mouse[1],h=de(13,u);this.mouse[0]+=(this.targetMouse[0]-this.mouse[0])*h,this.mouse[1]+=(this.targetMouse[1]-this.mouse[1])*h,this.mouseVel[0]=Math.max(-8,Math.min(8,(this.mouse[0]-d)/u)),this.mouseVel[1]=Math.max(-8,Math.min(8,(this.mouse[1]-f)/u))}else this.mouseVel[0]=0,this.mouseVel[1]=0;if(this.trackScroll){let d=this.scroll;this.scroll+=(this.targetScroll-this.scroll)*de(9.5,u),this.scrollVel=Math.max(-6,Math.min(6,(this.scroll-d)/u))}this.drawMainThreadFrame(),this.prevFrameDrew=!0}applyProtectionState(){if(this.isDestroyed||this.isBudgetSuspended)return;let e=this.resolveTierConfig(),{minDpr:t,maxDpr:i}=this.resolveDprBounds(),o=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:o,maxDpr:i,feedbackMaxDim:this.feedbackMaxDim,ambientFps:this.ambientFps,activeFps:this.activeFps,suspended:this.isSurvivalSuspended}):((this.dynamicRes?.setBounds(o,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 o=this.shouldPreserveBg()?1:Number(this.customUniforms.get("uTransparentBg")??0);this.customUniforms.set("uTransparentBg",o),i.uTransparentBg=o}if(this.boostInteraction(1200),e.quality!==void 0&&e.quality!==t){let r=ie[e.quality]??ie.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;B.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)),o=Math.max(1,Math.floor(i.contentRect.height));r===this.width&&o===this.height||(this.width=r,this.height=o,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=ae(),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=D(t,"#ffffff"),r=k.hexToVec3Into(i,k.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=ae(),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),B.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(),k.releaseVec2(this.mouse),k.releaseVec2(this.targetMouse),k.releaseVec2(this.mouseVel),this.customUniforms.clear(),this.textureUrls.clear(),this.textureUnits.clear(),this.loadedImages.clear(),this.textureLoadTokens.clear(),B.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 o=F.getUniformLocation(e,t,r);o&&(e.activeTexture(e.TEXTURE0+i.unit),e.bindTexture(e.TEXTURE_2D,i.tex),e.uniform1i(o,i.unit))})}uploadImageTexture(e,t,i,r){if(this.isDestroyed)return;let o=this.textureUnits.get(e);o===void 0&&(o=this.nextTextureUnit++,this.textureUnits.set(e,o));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:o,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+o),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:o,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):"",o=this.textureUrls.get(t)??"";if(!r){o?this.clearTextureSlot(t):this.customUniforms.set(`${t}Ready`,0);continue}if(r===o)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}}};B._activeContexts=0,B._maxContexts=We(),B.instances=new Set,B.recycledMainContexts=[];var G=B;var fe=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||N.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 o=n=>{e.visible=n,e.instance&&(n&&!N.isHidden?e.instance.resume?.():e.instance.pause?.(),this.syncTickerState())};r.add(o),e.unobserve=()=>{r?.delete(o),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(o=>o(i.isIntersecting))}},{rootMargin:"50px"})),this.visibilityObserver)}ensureVisibilitySub(){this.removeVisibilitySub||(this.removeVisibilitySub=N.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=N.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(o){r.faulted=!0,console.error(`[FluxFX] Runtime error in "${r.name}" (auto-paused):`,o);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){G.setMaxActiveContexts(e)}getStats(){let e=0,t=0,i=!1,r=N.isHidden;this.activeSet.forEach(u=>{if(!u.instance){t++;return}u.visible&&e++;let d=u.instance.isIdle?.()??!1;r||!u.visible||u.faulted||d?t++:!u.instance.isWebGL&&u.instance.isIdle&&(i=!0)});let o=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,n=G.getRenderStats(),l=N.fps,a=N.frameTimeMs;!r&&n.activeRendering>0&&!i?(l=n.fps,a=n.frameTimeMs):r&&(l=0,a=0);let c=W.getSnapshot();return{mounted:this.activeSet.size,visible:e,pausedEffects:t,activeLoops:N.isRunning?1:0,registered:this.plugins.size,webglContexts:G.activeContexts,activeContexts:G.activeContexts,maxWebGLContexts:G.maxActiveContexts,suspendedContexts:G.suspendedContexts,fps:l,frameTimeMs:a,reducedMotion:o,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 o=this.activeByElement.get(e);o||(o=new Map,this.activeByElement.set(e,o));let n=o.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),o?.delete(t),this.cleanupEmptyEngine())}};return this.isDeviceAllowed(a.options)&&!this.mountEntryInstance(a)?(o?.delete(t),()=>{}):(o.set(t,a),this.activeSet.add(a),this.ensureVisibilitySub(),this.syncResizeWatcher(),this.syncTickerState(),a.destroy)}update(e,t,i={}){let o=this.activeByElement.get(e)?.get(t);if(!o)return!1;o.options={...o.options,...i};let n=o.options;if(this.syncResizeWatcher(),!this.isDeviceAllowed(n))return this.unmountEntryInstance(o),this.syncTickerState(),!0;if(!o.instance){let a=this.mountEntryInstance(o);return this.syncTickerState(),a}if(o.instance.setOptions)try{return o.instance.setOptions(n),this.syncTickerState(),!0}catch(a){return console.error(`[FluxFX] Hot-update error in "${t}":`,a),!1}try{return o.instance.destroy(),o.instance=o.plugin.mount(e,n),o.faulted=!1,this.bindWake(o),(!o.visible||N.isHidden)&&o.instance.pause?.(),this.syncTickerState(),!0}catch(a){return o.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 o=r.trim().split(/\s+/).filter(Boolean),n=this.parseDatasetOptions(i),l=this.activeByElement.get(i);o.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[o,n]of Object.entries(e.dataset)){if(!o.startsWith("fx")||o==="fx"||n===void 0)continue;let l=o.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(d=>d.trim()).filter(Boolean):c!==""&&!Number.isNaN(Number(c))?t[a]=Number(c):t[a]=c}return t}},he=new fe;function Lt(s){if(s==null)return!1;let e=String(s).trim().toLowerCase();if(!e)return!1;if(e==="transparent"||e==="none")return!0;let t=e.match(/^rgba?\(\s*[\d.]+\s*,\s*[\d.]+\s*,\s*[\d.]+(?:\s*,\s*([\d.]+))?\s*\)$/);return t&&t[1]!==void 0?parseFloat(t[1])<=.001:!1}function Xe(s){let e=s.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,o=parseInt(t.slice(4,6),16)/255;return .2126*i+.7152*r+.0722*o>.45}function ze(s,e){if(Array.isArray(s.colors)&&s.colors.length>0){let o=s.colors.filter(Boolean);if(o.length===1){let c=D(o[0],e[0]);return[c,c,c]}if(o.length===2){let c=D(o[0],e[0]),u=D(o[1],e[1]);return[c,u,u]}let n=D(o[0],e[0]),l=D(o[1]??n,e[1]),a=D(o[2]??l,e[2]);return[n,l,a]}if(typeof s.colors=="string"){let o=s.colors.split(",").map(n=>n.trim()).filter(Boolean);if(o.length===1){let n=D(o[0],e[0]);return[n,n,n]}if(o.length===2){let n=D(o[0],e[0]),l=D(o[1],e[1]);return[n,l,l]}if(o.length>2)return[D(o[0],e[0]),D(o[1],e[1]),D(o[2],e[2])]}if(s.color1===void 0&&s.color2===void 0&&s.color3===void 0)return e;let t=D(s.color1,e[0]),i=s.color2!==void 0?D(s.color2,t):t,r=s.color3!==void 0?D(s.color3,i):i;return[t,i,r]}function I(s,e){let t=Lt(s.bgColor),i=!t&&s.bgColor!==void 0&&String(s.bgColor).trim()!=="",r=i?D(s.bgColor,e):e,o=k.hexToVec3Into(r,k.scratchVec3);return{uBgColor:[o[0],o[1],o[2]],uHasBgColor:i?1:0,uTransparentBg:t?1:0,bgHex:r,hasBgColor:i,transparentBg:t}}function Ft(s){return s==="high"?.65:s==="low"?.35:.5}function O(s){return{name:s.name,mount(e,t){let i=t.quality??"medium",r=new G(e,{fragmentShader:s.fragmentShader,vertexShader:s.vertexShader,feedbackShader:s.feedbackShader,feedbackScale:s.feedbackShader?Ft(i):void 0,feedbackFloat:s.feedbackShader?s.feedbackFloat??!0:void 0,feedbackMaxDim:typeof t.feedbackMaxDim=="number"?t.feedbackMaxDim:void 0,speed:typeof t.speed=="number"?t.speed:1,quality:i,colors:ze(t,s.defaultColors),uniforms:s.resolveUniforms?s.resolveUniforms(t):void 0,textures:s.resolveTextures?s.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(o,n){r.render(o,n)},setOptions(o){r.updateOptions({speed:typeof o.speed=="number"?o.speed:1,quality:o.quality,colors:ze(o,s.defaultColors),uniforms:s.resolveUniforms?s.resolveUniforms(o):void 0,textures:s.resolveTextures?s.resolveTextures(o):void 0,theme:o.theme,lightColors:o.lightColors,darkColors:o.darkColors,scrollColors:o.scrollColors,trackScroll:o.trackScroll,layer:o.layer,preserveBg:o.preserveBg,adaptToSurface:o.adaptToSurface,overlayOpacity:o.overlayOpacity,interactive:o.interactive!==!1,dynamicResolution:o.dynamicResolution,minDpr:o.minDpr,maxDpr:o.maxDpr,feedbackMaxDim:typeof o.feedbackMaxDim=="number"?o.feedbackMaxDim:void 0,respectReducedMotion:o.respectReducedMotion})},isIdle(){return r.isIdle},onWake(o){r.onWake(o)},pause(){r.pause()},resume(){r.resume()},destroy(){r.destroy()}}}}}var kt=`#version 300 es
|
|
681
860
|
precision highp float;
|
|
682
861
|
|
|
683
862
|
in vec2 vUv;
|
|
@@ -687,6 +866,12 @@ uniform float uTime;
|
|
|
687
866
|
uniform vec2 uResolution;
|
|
688
867
|
uniform vec2 uMouse;
|
|
689
868
|
uniform float uMouseActive;
|
|
869
|
+
uniform float uMouseDown;
|
|
870
|
+
uniform vec3 uBgColor;
|
|
871
|
+
uniform float uHasBgColor;
|
|
872
|
+
uniform float uTransparentBg;
|
|
873
|
+
uniform float uTheme;
|
|
874
|
+
uniform float uQuality;
|
|
690
875
|
uniform vec3 uColor1;
|
|
691
876
|
uniform vec3 uColor2;
|
|
692
877
|
uniform vec3 uColor3;
|
|
@@ -698,7 +883,7 @@ float hash(vec2 p) {
|
|
|
698
883
|
float noise(vec2 p) {
|
|
699
884
|
vec2 i = floor(p);
|
|
700
885
|
vec2 f = fract(p);
|
|
701
|
-
vec2 u = f * f * (
|
|
886
|
+
vec2 u = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);
|
|
702
887
|
return mix(
|
|
703
888
|
mix(hash(i + vec2(0.0, 0.0)), hash(i + vec2(1.0, 0.0)), u.x),
|
|
704
889
|
mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), u.x),
|
|
@@ -709,13 +894,18 @@ float noise(vec2 p) {
|
|
|
709
894
|
float fbm(vec2 p) {
|
|
710
895
|
float value = 0.0;
|
|
711
896
|
float amp = 0.5;
|
|
897
|
+
float norm = 0.0;
|
|
712
898
|
mat2 rot = mat2(0.8, 0.6, -0.6, 0.8);
|
|
713
|
-
|
|
899
|
+
// Keep >= 3 octaves even on low quality so aurora curves stay silky smooth
|
|
900
|
+
int octaves = uQuality < 0.25 ? 3 : (uQuality < 0.75 ? 4 : 5);
|
|
901
|
+
for (int i = 0; i < 5; i++) {
|
|
902
|
+
if (i >= octaves) break;
|
|
714
903
|
value += amp * noise(p);
|
|
904
|
+
norm += amp;
|
|
715
905
|
p = rot * p * 2.02;
|
|
716
906
|
amp *= 0.5;
|
|
717
907
|
}
|
|
718
|
-
return value;
|
|
908
|
+
return value / max(norm, 0.001);
|
|
719
909
|
}
|
|
720
910
|
|
|
721
911
|
void main() {
|
|
@@ -724,28 +914,66 @@ void main() {
|
|
|
724
914
|
vec2 p = (uv - 0.5) * vec2(aspect, 1.0);
|
|
725
915
|
|
|
726
916
|
vec2 m = (uMouse - 0.5) * vec2(aspect, 1.0);
|
|
727
|
-
|
|
728
|
-
|
|
917
|
+
vec2 diff = p - m;
|
|
918
|
+
float mouseDist = length(diff);
|
|
919
|
+
vec2 pushDir = mouseDist > 0.0005 ? diff / mouseDist : vec2(0.0);
|
|
920
|
+
float mouseInfluence = exp(-mouseDist * 2.1) * uMouseActive;
|
|
921
|
+
p += pushDir * mouseInfluence * (0.16 + 0.08 * uMouseDown);
|
|
922
|
+
|
|
923
|
+
float t = uTime * 0.28;
|
|
924
|
+
|
|
925
|
+
// Two-stage smooth domain warp for organic northern-lights waves
|
|
926
|
+
vec2 q = vec2(
|
|
927
|
+
fbm(p * 1.15 + vec2(t * 0.55, -t * 0.30)),
|
|
928
|
+
fbm(p * 1.15 + vec2(-t * 0.40, t * 0.35) + vec2(4.2, 1.8))
|
|
929
|
+
);
|
|
930
|
+
float f = fbm(p * 1.45 + 1.15 * q + vec2(t * 0.22, -t * 0.14));
|
|
729
931
|
|
|
730
|
-
|
|
932
|
+
// Sweeping gaussian aurora curtains (smooth flowing veils, zero repeating stripe grid)
|
|
933
|
+
float d1 = abs(p.y + 0.10 - (f - 0.5) * 0.85 - 0.18 * sin(p.x * 1.55 + t * 0.85));
|
|
934
|
+
float d2 = abs(p.y - 0.14 + (q.x - 0.5) * 0.78 - 0.20 * cos(p.x * 1.35 - t * 0.72));
|
|
935
|
+
float d3 = abs((p.y * 0.85 - p.x * 0.26) - (q.y - 0.5) * 0.72 + 0.14 * sin(p.x * 2.0 + t * 1.05));
|
|
731
936
|
|
|
732
|
-
|
|
733
|
-
float
|
|
937
|
+
float band1 = exp(-d1 * d1 * 6.2);
|
|
938
|
+
float band2 = exp(-d2 * d2 * 7.2) * smoothstep(0.14, 0.86, f);
|
|
939
|
+
float band3 = exp(-d3 * d3 * 8.8) * smoothstep(0.18, 0.88, q.x);
|
|
734
940
|
|
|
735
|
-
|
|
736
|
-
float
|
|
941
|
+
// Subtle vertical curtain shimmer rays
|
|
942
|
+
float ray = smoothstep(0.28, 0.84, fbm(vec2(p.x * 3.6 + q.x * 1.3, p.y * 0.85 - t * 0.55)));
|
|
943
|
+
float w1 = clamp(band1 * (0.68 + 0.52 * ray) + mouseInfluence * 0.16, 0.0, 1.0);
|
|
944
|
+
float w2 = clamp(band2 * (0.68 + 0.48 * ray), 0.0, 1.0);
|
|
945
|
+
float w3 = clamp(band3 * (0.58 + 0.52 * ray), 0.0, 1.0);
|
|
737
946
|
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
947
|
+
// Unified weighted palette blend prevents muddy color overlap
|
|
948
|
+
float totalW = w1 + w2 + w3;
|
|
949
|
+
vec3 ribbonCol = (uColor1 * w1 + uColor2 * w2 + uColor3 * w3) / max(totalW, 0.001);
|
|
950
|
+
float coreGlow = clamp((band1 * band2 + band2 * band3) * 1.25, 0.0, 1.0);
|
|
951
|
+
ribbonCol = mix(ribbonCol, mix(ribbonCol, vec3(1.0), 0.38), coreGlow * 0.5);
|
|
742
952
|
|
|
743
|
-
float
|
|
744
|
-
float grain = (hash(gl_FragCoord.xy + fract(uTime)) - 0.5) * 0.
|
|
745
|
-
col = col * vig + grain;
|
|
953
|
+
float intensity = clamp(max(w1, max(w2, w3)) * 0.78 + totalW * 0.18, 0.0, 1.0);
|
|
954
|
+
float grain = (hash(gl_FragCoord.xy + fract(uTime * 0.25)) - 0.5) * 0.012;
|
|
746
955
|
|
|
747
|
-
|
|
748
|
-
|
|
956
|
+
if (uTransparentBg > 0.5) {
|
|
957
|
+
vec3 premult = clamp(ribbonCol + vec3(grain), 0.0, 1.0);
|
|
958
|
+
fragColor = vec4(premult * intensity, intensity);
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
float bgLum = dot(uBgColor, vec3(0.2126, 0.7152, 0.0722));
|
|
963
|
+
float darkAmt = uHasBgColor > 0.5 ? smoothstep(0.55, 0.25, bgLum) : clamp(uTheme, 0.0, 1.0);
|
|
964
|
+
vec3 baseDark = uHasBgColor > 0.5 ? uBgColor : vec3(0.028, 0.038, 0.085);
|
|
965
|
+
vec3 baseLight = uHasBgColor > 0.5 ? uBgColor : vec3(0.968, 0.965, 0.955);
|
|
966
|
+
|
|
967
|
+
vec3 darkCol = mix(baseDark, clamp(baseDark * 0.35 + ribbonCol * 1.1, 0.0, 1.0), intensity);
|
|
968
|
+
float darkVig = 1.0 - dot(uv - 0.5, uv - 0.5) * 0.26;
|
|
969
|
+
darkCol = clamp(darkCol * darkVig + grain, 0.0, 1.0);
|
|
970
|
+
|
|
971
|
+
vec3 lightCol = mix(baseLight, ribbonCol, intensity * 0.65);
|
|
972
|
+
float lightVig = 1.0 - dot(uv - 0.5, uv - 0.5) * 0.06;
|
|
973
|
+
lightCol = clamp(lightCol * lightVig + grain * 0.45, 0.0, 1.0);
|
|
974
|
+
|
|
975
|
+
fragColor = vec4(mix(lightCol, darkCol, darkAmt), 1.0);
|
|
976
|
+
}`,Ne=O({name:"aurora",fragmentShader:kt,defaultColors:["#4f46e5","#06b6d4","#ec4899"],resolveUniforms(s){let e=I(s,"#080a17");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg}}});var Dt=`#version 300 es
|
|
749
977
|
precision highp float;
|
|
750
978
|
|
|
751
979
|
in vec2 vUv;
|
|
@@ -755,12 +983,19 @@ uniform float uTime;
|
|
|
755
983
|
uniform vec2 uResolution;
|
|
756
984
|
uniform vec2 uMouse;
|
|
757
985
|
uniform float uMouseActive;
|
|
986
|
+
uniform vec3 uBgColor;
|
|
987
|
+
uniform float uHasBgColor;
|
|
988
|
+
uniform float uTransparentBg;
|
|
989
|
+
uniform float uTheme;
|
|
990
|
+
uniform float uQuality;
|
|
758
991
|
uniform vec3 uColor1;
|
|
759
992
|
uniform vec3 uColor2;
|
|
760
993
|
uniform vec3 uColor3;
|
|
761
994
|
|
|
762
995
|
float field(vec2 p, float t) {
|
|
763
|
-
|
|
996
|
+
int iters = uQuality < 0.25 ? 3 : (uQuality < 0.75 ? 4 : 5);
|
|
997
|
+
for (int i = 1; i <= 5; i++) {
|
|
998
|
+
if (i > iters) break;
|
|
764
999
|
float fi = float(i);
|
|
765
1000
|
p.x += 0.35 / fi * sin(fi * 2.2 * p.y + t + 0.4 * fi);
|
|
766
1001
|
p.y += 0.35 / fi * cos(fi * 2.2 * p.x + t * 0.9 + 0.3 * fi);
|
|
@@ -792,13 +1027,34 @@ void main() {
|
|
|
792
1027
|
float spec = pow(max(dot(normal, halfVec), 0.0), 28.0);
|
|
793
1028
|
float fresnel = pow(1.0 - max(dot(normal, viewDir), 0.0), 3.0);
|
|
794
1029
|
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
1030
|
+
if (uTransparentBg > 0.5) {
|
|
1031
|
+
vec3 ridgeBase = mix(uColor1, uColor2, smoothstep(0.15, 0.9, h));
|
|
1032
|
+
vec3 metalCol = ridgeBase * (0.55 + 0.65 * diff);
|
|
1033
|
+
metalCol += mix(vec3(0.95), uColor3, 0.35) * spec * 1.15;
|
|
1034
|
+
metalCol += uColor3 * fresnel * 0.5;
|
|
1035
|
+
metalCol = clamp(metalCol, 0.0, 1.0);
|
|
1036
|
+
float alpha = clamp(smoothstep(0.2, 0.88, h) * 0.78 + spec * 0.9 + fresnel * 0.45, 0.0, 1.0);
|
|
1037
|
+
fragColor = vec4(metalCol * alpha, alpha);
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
799
1040
|
|
|
800
|
-
|
|
801
|
-
|
|
1041
|
+
float darkAmt = clamp(uTheme, 0.0, 1.0);
|
|
1042
|
+
|
|
1043
|
+
vec3 darkBase = uHasBgColor > 0.5 ? uBgColor : uColor1 * 0.25;
|
|
1044
|
+
vec3 baseD = mix(darkBase, uColor2 * 0.75, h);
|
|
1045
|
+
vec3 darkCol = baseD * (0.45 + 0.75 * diff);
|
|
1046
|
+
darkCol += mix(vec3(0.95), uColor3, 0.35) * spec * 1.1;
|
|
1047
|
+
darkCol += uColor3 * fresnel * 0.45;
|
|
1048
|
+
|
|
1049
|
+
vec3 lightBase = uHasBgColor > 0.5 ? uBgColor : mix(vec3(0.92, 0.935, 0.96), uColor1, 0.16);
|
|
1050
|
+
vec3 baseL = mix(lightBase, mix(vec3(0.76, 0.80, 0.88), uColor2, 0.42), h);
|
|
1051
|
+
vec3 lightCol = baseL * (0.78 + 0.30 * diff);
|
|
1052
|
+
lightCol += mix(vec3(1.0), uColor3, 0.28) * spec * 0.85;
|
|
1053
|
+
lightCol = mix(lightCol, uColor3, fresnel * 0.24);
|
|
1054
|
+
lightCol = clamp(lightCol, 0.0, 1.0);
|
|
1055
|
+
|
|
1056
|
+
fragColor = vec4(mix(lightCol, darkCol, darkAmt), 1.0);
|
|
1057
|
+
}`,Qe=O({name:"liquid-metal",fragmentShader:Dt,defaultColors:["#18181b","#94a3b8","#38bdf8"],resolveUniforms(s){let e=I(s,"#0f172a");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg}}});var Pt=`#version 300 es
|
|
802
1058
|
precision highp float;
|
|
803
1059
|
|
|
804
1060
|
in vec2 vUv;
|
|
@@ -859,7 +1115,6 @@ void main() {
|
|
|
859
1115
|
vel *= velDecay;
|
|
860
1116
|
dye *= dyeDecay;
|
|
861
1117
|
|
|
862
|
-
// Subtle autonomous emitter (uTime is already smoothly speed-integrated)
|
|
863
1118
|
float t = uTime * 0.55;
|
|
864
1119
|
vec2 autoPos = vec2(
|
|
865
1120
|
0.5 + 0.28 * cos(t * 0.9) * sin(t * 0.4),
|
|
@@ -900,7 +1155,7 @@ void main() {
|
|
|
900
1155
|
dye = clamp(dye, vec2(0.0), vec2(1.0));
|
|
901
1156
|
|
|
902
1157
|
fragColor = vec4(encodedVel, dye);
|
|
903
|
-
}`,
|
|
1158
|
+
}`,At=`#version 300 es
|
|
904
1159
|
precision highp float;
|
|
905
1160
|
|
|
906
1161
|
in vec2 vUv;
|
|
@@ -910,7 +1165,9 @@ uniform sampler2D uFeedback;
|
|
|
910
1165
|
uniform float uTime;
|
|
911
1166
|
uniform vec2 uResolution;
|
|
912
1167
|
uniform vec3 uBgColor;
|
|
1168
|
+
uniform float uHasBgColor;
|
|
913
1169
|
uniform float uTransparentBg;
|
|
1170
|
+
uniform float uTheme;
|
|
914
1171
|
uniform vec3 uColor1;
|
|
915
1172
|
uniform vec3 uColor2;
|
|
916
1173
|
uniform vec3 uColor3;
|
|
@@ -920,7 +1177,6 @@ float hash(vec2 p) {
|
|
|
920
1177
|
}
|
|
921
1178
|
|
|
922
1179
|
void main() {
|
|
923
|
-
// Sample gradients using actual FBO texture resolution (eliminates Retina specular banding)
|
|
924
1180
|
vec2 fboTexel = 1.0 / max(vec2(textureSize(uFeedback, 0)), vec2(1.0));
|
|
925
1181
|
vec4 state = texture(uFeedback, vUv);
|
|
926
1182
|
|
|
@@ -943,38 +1199,44 @@ void main() {
|
|
|
943
1199
|
float m2 = smoothstep(0.06, 0.85, dyeB) * 0.88;
|
|
944
1200
|
float m3 = smoothstep(0.18, 0.95, dyeA * dyeB * 1.6 + flowEnergy * density * 0.65) * 0.75;
|
|
945
1201
|
|
|
946
|
-
|
|
947
|
-
|
|
1202
|
+
float darkAmt = clamp(uTheme, 0.0, 1.0);
|
|
1203
|
+
float grain = (hash(gl_FragCoord.xy + fract(uTime)) - 0.5) * 0.015;
|
|
1204
|
+
|
|
1205
|
+
vec3 baseDark = uHasBgColor > 0.5
|
|
948
1206
|
? uBgColor
|
|
949
1207
|
: (vec3(0.025, 0.03, 0.065) + uColor1 * 0.04);
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
1208
|
+
vec3 darkCol = baseDark;
|
|
1209
|
+
darkCol = mix(darkCol, uColor1, m1);
|
|
1210
|
+
darkCol = mix(darkCol, uColor2, m2);
|
|
1211
|
+
darkCol += uColor3 * m3;
|
|
1212
|
+
darkCol += mix(vec3(1.0), uColor3, 0.4) * spec * 0.55;
|
|
1213
|
+
float darkVig = 1.0 - dot(vUv - 0.5, vUv - 0.5) * 0.65;
|
|
1214
|
+
darkCol = max(darkCol * darkVig + grain, vec3(0.0));
|
|
1215
|
+
|
|
1216
|
+
vec3 baseLight = uHasBgColor > 0.5 ? uBgColor : vec3(0.96, 0.953, 0.935);
|
|
1217
|
+
vec3 lightCol = baseLight;
|
|
1218
|
+
lightCol = mix(lightCol, uColor1, m1 * 0.58);
|
|
1219
|
+
lightCol = mix(lightCol, uColor2, m2 * 0.54);
|
|
1220
|
+
lightCol = mix(lightCol, uColor3, m3 * 0.50);
|
|
1221
|
+
lightCol += vec3(0.28) * spec * 0.42;
|
|
1222
|
+
float lightVig = 1.0 - dot(vUv - 0.5, vUv - 0.5) * 0.12;
|
|
1223
|
+
lightCol = clamp(lightCol * lightVig + grain * 0.5, 0.0, 1.0);
|
|
1224
|
+
|
|
1225
|
+
vec3 opaqueCol = mix(lightCol, darkCol, darkAmt);
|
|
1226
|
+
|
|
1227
|
+
float wSum = m1 + m2 + m3 + 0.0001;
|
|
1228
|
+
vec3 dyeCol = (uColor1 * m1 + uColor2 * m2 + uColor3 * m3) / wSum;
|
|
1229
|
+
dyeCol += mix(vec3(1.0), uColor3, 0.4) * spec * 0.48;
|
|
967
1230
|
dyeCol = clamp(dyeCol + vec3(grain), 0.0, 1.0);
|
|
968
1231
|
|
|
969
1232
|
float alpha = clamp(max(max(m1, m2), max(m3, spec * 0.55)), 0.0, 1.0);
|
|
970
1233
|
|
|
971
1234
|
if (uTransparentBg > 0.5) {
|
|
972
|
-
// Premultiplied alpha for standard canvas alpha blending
|
|
973
1235
|
fragColor = vec4(dyeCol * alpha, alpha);
|
|
974
1236
|
} else {
|
|
975
1237
|
fragColor = vec4(opaqueCol, 1.0);
|
|
976
1238
|
}
|
|
977
|
-
}`,
|
|
1239
|
+
}`,qe=O({name:"fluid",fragmentShader:At,feedbackShader:Pt,feedbackFloat:!0,defaultColors:["#6366f1","#06b6d4","#f43f5e"],resolveUniforms(s){let e=I(s,"#060810");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg,uDissipation:typeof s.dissipation=="number"?s.dissipation:.975,uRadius:typeof s.radius=="number"?s.radius:.0045,uSwirl:typeof s.swirl=="number"?s.swirl:1.4}}});var Bt=`#version 300 es
|
|
978
1240
|
precision highp float;
|
|
979
1241
|
|
|
980
1242
|
in vec2 vUv;
|
|
@@ -1015,25 +1277,21 @@ void main() {
|
|
|
1015
1277
|
vec2 vD = decodeVel(d);
|
|
1016
1278
|
vec2 vU = decodeVel(u);
|
|
1017
1279
|
|
|
1018
|
-
// Vorticity confinement for wispy ink tendrils in still water
|
|
1019
1280
|
float vorticity = (vR.y - vL.y) - (vU.x - vD.x);
|
|
1020
1281
|
vec2 grad = vec2(abs(vU.y) - abs(vD.y), abs(vR.x) - abs(vL.x));
|
|
1021
1282
|
vec2 perp = normalize(grad + vec2(0.0001));
|
|
1022
1283
|
vel += vec2(perp.y, -perp.x) * vorticity * uCurl * dt * 1.65;
|
|
1023
1284
|
|
|
1024
|
-
// Advect velocity & ink pigments backward along flow
|
|
1025
1285
|
vec2 backUv = clamp(vUv - vel * dt * 0.48 * clamp(uSpeed, 0.25, 3.0), texel, 1.0 - texel);
|
|
1026
1286
|
vec4 adv = texture(uPrevFrame, backUv);
|
|
1027
1287
|
vec2 advVel = decodeVel(adv);
|
|
1028
1288
|
|
|
1029
|
-
// Water viscosity: velocity damps faster than suspended ink pigments
|
|
1030
1289
|
float visc = pow(clamp(uDissipation * 0.985, 0.88, 0.992), dt * 60.0);
|
|
1031
1290
|
float inkHold = pow(clamp(uDissipation + 0.006, 0.92, 0.998), dt * 60.0);
|
|
1032
1291
|
|
|
1033
1292
|
vel = mix(advVel, (vL + vR + vD + vU) * 0.25, 0.07) * visc;
|
|
1034
1293
|
vec2 ink = mix(adv.ba, (l.ba + r.ba + d.ba + u.ba) * 0.25, 0.035) * inkHold;
|
|
1035
1294
|
|
|
1036
|
-
// Gentle ambient ink drift so canvas feels alive before pointer interaction
|
|
1037
1295
|
float t = uTime * 0.42;
|
|
1038
1296
|
vec2 driftPos = vec2(
|
|
1039
1297
|
0.5 + 0.25 * sin(t * 0.85),
|
|
@@ -1046,7 +1304,6 @@ void main() {
|
|
|
1046
1304
|
ink.x += driftSplat * (0.45 + 0.45 * sin(t * 1.2)) * dt * 0.85;
|
|
1047
1305
|
ink.y += driftSplat * (0.45 + 0.45 * cos(t * 0.9)) * dt * 0.75;
|
|
1048
1306
|
|
|
1049
|
-
// Pointer ink injection (strictly scoped to active container)
|
|
1050
1307
|
if (uMouseActive > 0.01) {
|
|
1051
1308
|
vec2 deltaP = (vUv - uMouse) * vec2(aspect, 1.0);
|
|
1052
1309
|
float dist2 = dot(deltaP, deltaP);
|
|
@@ -1062,7 +1319,6 @@ void main() {
|
|
|
1062
1319
|
ink.y += deposit * (0.35 + 0.65 * (1.0 - wave));
|
|
1063
1320
|
}
|
|
1064
1321
|
|
|
1065
|
-
// Press & hold drops a concentrated ink bloom
|
|
1066
1322
|
if (uMouseDown > 0.5) {
|
|
1067
1323
|
vec2 outward = normalize(deltaP + vec2(0.0001));
|
|
1068
1324
|
float bloom = exp(-dist2 / max(uRadius * 2.4, 0.003));
|
|
@@ -1076,7 +1332,7 @@ void main() {
|
|
|
1076
1332
|
vec2 encVel = clamp(vel * 0.5 + 0.5, vec2(0.02), vec2(0.98));
|
|
1077
1333
|
|
|
1078
1334
|
fragColor = vec4(encVel, ink);
|
|
1079
|
-
}`,
|
|
1335
|
+
}`,Ut=`#version 300 es
|
|
1080
1336
|
precision highp float;
|
|
1081
1337
|
|
|
1082
1338
|
in vec2 vUv;
|
|
@@ -1085,6 +1341,10 @@ out vec4 fragColor;
|
|
|
1085
1341
|
uniform sampler2D uFeedback;
|
|
1086
1342
|
uniform float uTime;
|
|
1087
1343
|
uniform vec2 uResolution;
|
|
1344
|
+
uniform vec3 uBgColor;
|
|
1345
|
+
uniform float uHasBgColor;
|
|
1346
|
+
uniform float uTransparentBg;
|
|
1347
|
+
uniform float uTheme;
|
|
1088
1348
|
uniform vec3 uColor1;
|
|
1089
1349
|
uniform vec3 uColor2;
|
|
1090
1350
|
uniform vec3 uColor3;
|
|
@@ -1100,7 +1360,6 @@ void main() {
|
|
|
1100
1360
|
float ink1 = fbo.b;
|
|
1101
1361
|
float ink2 = fbo.a;
|
|
1102
1362
|
|
|
1103
|
-
// Subtle refractive distortion along ink pigment gradient
|
|
1104
1363
|
float hC = ink1 * 0.7 + ink2 * 0.55;
|
|
1105
1364
|
float hL = dot(texture(uFeedback, vUv - vec2(fboTexel.x * 2.0, 0.0)).ba, vec2(0.7, 0.55));
|
|
1106
1365
|
float hR = dot(texture(uFeedback, vUv + vec2(fboTexel.x * 2.0, 0.0)).ba, vec2(0.7, 0.55));
|
|
@@ -1114,30 +1373,51 @@ void main() {
|
|
|
1114
1373
|
float p1 = mix(ink1, refFbo.b, 0.45);
|
|
1115
1374
|
float p2 = mix(ink2, refFbo.a, 0.45);
|
|
1116
1375
|
|
|
1117
|
-
// Water backdrop + Beer-Lambert style pigment absorption
|
|
1118
|
-
vec3 waterBase = vec3(0.025, 0.03, 0.06) + uColor1 * 0.035;
|
|
1119
1376
|
float absorb1 = smoothstep(0.02, 0.82, p1);
|
|
1120
1377
|
float absorb2 = smoothstep(0.04, 0.86, p2);
|
|
1121
|
-
|
|
1122
|
-
vec3 col = waterBase;
|
|
1123
|
-
col = mix(col, uColor1, absorb1 * 0.92);
|
|
1124
|
-
col = mix(col, uColor2, absorb2 * 0.86);
|
|
1125
|
-
|
|
1126
|
-
// Rich filament veins where pigments fold and overlap
|
|
1127
1378
|
float filament = smoothstep(0.22, 0.92, p1 * p2 * 1.7 + length(grad) * 2.2);
|
|
1128
|
-
col = mix(col, uColor3, filament * 0.68);
|
|
1129
1379
|
|
|
1130
|
-
// Soft water surface sheen along pigment ridges
|
|
1131
1380
|
vec3 n = normalize(vec3((hL - hR) * 2.8, (hD - hU) * 2.8, 1.0));
|
|
1132
1381
|
float rim = pow(1.0 - max(n.z, 0.0), 2.2) * smoothstep(0.05, 0.65, hC);
|
|
1133
|
-
col += mix(vec3(0.9), uColor3, 0.45) * rim * 0.35;
|
|
1134
|
-
|
|
1135
|
-
float vig = 1.0 - dot(vUv - 0.5, vUv - 0.5) * 0.62;
|
|
1136
1382
|
float grain = (hash(gl_FragCoord.xy + fract(uTime)) - 0.5) * 0.015;
|
|
1137
|
-
col = max(col * vig + grain, vec3(0.0));
|
|
1138
1383
|
|
|
1139
|
-
|
|
1140
|
-
|
|
1384
|
+
if (uTransparentBg > 0.5) {
|
|
1385
|
+
float a1 = absorb1 * 0.92;
|
|
1386
|
+
float a2 = absorb2 * 0.86;
|
|
1387
|
+
float a3 = filament * 0.68;
|
|
1388
|
+
float wSum = a1 + a2 + a3 + 0.0001;
|
|
1389
|
+
vec3 inkCol = (uColor1 * a1 + uColor2 * a2 + uColor3 * a3) / wSum;
|
|
1390
|
+
inkCol += mix(vec3(0.9), uColor3, 0.45) * rim * 0.35;
|
|
1391
|
+
inkCol = clamp(inkCol + vec3(grain), 0.0, 1.0);
|
|
1392
|
+
float alpha = clamp(max(max(a1, a2), max(a3, rim * 0.35)), 0.0, 1.0);
|
|
1393
|
+
fragColor = vec4(inkCol * alpha, alpha);
|
|
1394
|
+
return;
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
float darkAmt = clamp(uTheme, 0.0, 1.0);
|
|
1398
|
+
|
|
1399
|
+
vec3 waterDark = uHasBgColor > 0.5
|
|
1400
|
+
? uBgColor
|
|
1401
|
+
: (vec3(0.025, 0.03, 0.06) + uColor1 * 0.035);
|
|
1402
|
+
vec3 darkCol = waterDark;
|
|
1403
|
+
darkCol = mix(darkCol, uColor1, absorb1 * 0.92);
|
|
1404
|
+
darkCol = mix(darkCol, uColor2, absorb2 * 0.86);
|
|
1405
|
+
darkCol = mix(darkCol, uColor3, filament * 0.68);
|
|
1406
|
+
darkCol += mix(vec3(0.9), uColor3, 0.45) * rim * 0.35;
|
|
1407
|
+
float darkVig = 1.0 - dot(vUv - 0.5, vUv - 0.5) * 0.62;
|
|
1408
|
+
darkCol = max(darkCol * darkVig + grain, vec3(0.0));
|
|
1409
|
+
|
|
1410
|
+
vec3 waterLight = uHasBgColor > 0.5 ? uBgColor : vec3(0.965, 0.955, 0.935);
|
|
1411
|
+
vec3 lightCol = waterLight;
|
|
1412
|
+
lightCol = mix(lightCol, uColor1 * 0.82, absorb1 * 0.68);
|
|
1413
|
+
lightCol = mix(lightCol, uColor2 * 0.86, absorb2 * 0.62);
|
|
1414
|
+
lightCol = mix(lightCol, uColor3 * 0.90, filament * 0.55);
|
|
1415
|
+
lightCol += vec3(0.14) * rim * 0.25;
|
|
1416
|
+
float lightVig = 1.0 - dot(vUv - 0.5, vUv - 0.5) * 0.12;
|
|
1417
|
+
lightCol = clamp(lightCol * lightVig + grain * 0.5, 0.0, 1.0);
|
|
1418
|
+
|
|
1419
|
+
fragColor = vec4(mix(lightCol, darkCol, darkAmt), 1.0);
|
|
1420
|
+
}`,$e=O({name:"ink",fragmentShader:Ut,feedbackShader:Bt,feedbackFloat:!0,defaultColors:["#1e1b4b","#0284c7","#e11d48"],resolveUniforms(s){let e=I(s,"#060810");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg,uDissipation:typeof s.dissipation=="number"?s.dissipation:.982,uRadius:typeof s.radius=="number"?s.radius:.004,uCurl:typeof s.curl=="number"?s.curl:1.75}}});var It=`#version 300 es
|
|
1141
1421
|
precision highp float;
|
|
1142
1422
|
|
|
1143
1423
|
in vec2 vUv;
|
|
@@ -1178,18 +1458,15 @@ void main() {
|
|
|
1178
1458
|
vec2 vD = decodeVel(d);
|
|
1179
1459
|
vec2 vU = decodeVel(u);
|
|
1180
1460
|
|
|
1181
|
-
// Vorticity confinement for wispy curling ink tendrils
|
|
1182
1461
|
float curl = (vR.y - vL.y) - (vU.x - vD.x);
|
|
1183
1462
|
vec2 grad = vec2(abs(vU.y) - abs(vD.y), abs(vR.x) - abs(vL.x));
|
|
1184
1463
|
vec2 swirlDir = normalize(grad + vec2(0.0001));
|
|
1185
1464
|
vel += vec2(swirlDir.y, -swirlDir.x) * curl * uCurl * dt * 1.5;
|
|
1186
1465
|
|
|
1187
|
-
// Semi-Lagrangian advection along flow
|
|
1188
1466
|
vec2 backUv = clamp(vUv - vel * dt * 0.52 * clamp(uSpeed, 0.25, 3.0), texel, 1.0 - texel);
|
|
1189
1467
|
vec4 adv = texture(uPrevFrame, backUv);
|
|
1190
1468
|
vec2 advVel = decodeVel(adv);
|
|
1191
1469
|
|
|
1192
|
-
// Soft pressure-like neighbor smoothing keeps incompressible swirls silky
|
|
1193
1470
|
vec2 avgVel = (vL + vR + vD + vU) * 0.25;
|
|
1194
1471
|
vec2 avgInk = (l.ba + r.ba + d.ba + u.ba) * 0.25;
|
|
1195
1472
|
|
|
@@ -1199,7 +1476,6 @@ void main() {
|
|
|
1199
1476
|
vel = mix(advVel, avgVel, 0.09) * velDecay;
|
|
1200
1477
|
vec2 ink = mix(adv.ba, avgInk, 0.032) * inkDecay;
|
|
1201
1478
|
|
|
1202
|
-
// Autonomous curving ink plumes (gives live video-like motion on load)
|
|
1203
1479
|
float t = uTime * 0.45;
|
|
1204
1480
|
for (int i = 0; i < 3; i++) {
|
|
1205
1481
|
float fi = float(i);
|
|
@@ -1219,7 +1495,6 @@ void main() {
|
|
|
1219
1495
|
ink.y += splat * (1.0 - pulse * 0.65) * dt * 0.75;
|
|
1220
1496
|
}
|
|
1221
1497
|
|
|
1222
|
-
// Interactive cursor stroke & click/hold ink bloom (strictly inside container)
|
|
1223
1498
|
if (uMouseActive > 0.01) {
|
|
1224
1499
|
vec2 diff = (vUv - uMouse) * vec2(aspect, 1.0);
|
|
1225
1500
|
float distSq = dot(diff, diff);
|
|
@@ -1248,7 +1523,7 @@ void main() {
|
|
|
1248
1523
|
vec2 encVel = clamp(vel * 0.5 + 0.5, vec2(0.02), vec2(0.98));
|
|
1249
1524
|
|
|
1250
1525
|
fragColor = vec4(encVel, ink);
|
|
1251
|
-
}`,
|
|
1526
|
+
}`,Ot=`#version 300 es
|
|
1252
1527
|
precision highp float;
|
|
1253
1528
|
|
|
1254
1529
|
in vec2 vUv;
|
|
@@ -1258,8 +1533,11 @@ uniform sampler2D uFeedback;
|
|
|
1258
1533
|
uniform float uTime;
|
|
1259
1534
|
uniform vec2 uResolution;
|
|
1260
1535
|
uniform vec3 uBgColor;
|
|
1536
|
+
uniform float uHasBgColor;
|
|
1537
|
+
uniform float uHasExplicitLightMode;
|
|
1261
1538
|
uniform float uTransparentBg;
|
|
1262
1539
|
uniform float uLightMode;
|
|
1540
|
+
uniform float uTheme;
|
|
1263
1541
|
uniform float uAbsorptionGain;
|
|
1264
1542
|
uniform vec3 uColor1;
|
|
1265
1543
|
uniform vec3 uColor2;
|
|
@@ -1278,7 +1556,6 @@ void main() {
|
|
|
1278
1556
|
float pA = fbo.b;
|
|
1279
1557
|
float pB = fbo.a;
|
|
1280
1558
|
|
|
1281
|
-
// Fluid surface relief normal from pigment density gradient
|
|
1282
1559
|
float hC = pA * 0.72 + pB * 0.58;
|
|
1283
1560
|
float hL = dot(texture(uFeedback, vUv - vec2(fboTexel.x * 2.0, 0.0)).ba, vec2(0.72, 0.58));
|
|
1284
1561
|
float hR = dot(texture(uFeedback, vUv + vec2(fboTexel.x * 2.0, 0.0)).ba, vec2(0.72, 0.58));
|
|
@@ -1290,38 +1567,595 @@ void main() {
|
|
|
1290
1567
|
float diffuse = clamp(dot(normal, lightDir), 0.0, 1.0);
|
|
1291
1568
|
float rimSheen = pow(clamp(dot(normal, normalize(vec3(0.4, 0.6, 0.7))), 0.0, 1.0), 8.0);
|
|
1292
1569
|
|
|
1293
|
-
// Combine 3 palette tones across dual pigment channels
|
|
1294
1570
|
vec3 tintMix = normalize(uColor1 * pA + uColor2 * pB + uColor3 * (pA * pB * 1.8) + vec3(0.0001));
|
|
1295
1571
|
float totalInk = (pA + pB * 0.85) * uAbsorptionGain;
|
|
1296
1572
|
|
|
1297
|
-
|
|
1573
|
+
float darkAmt = clamp(uTheme, 0.0, 1.0);
|
|
1574
|
+
float effectiveLightMode = uHasExplicitLightMode > 0.5
|
|
1575
|
+
? clamp(uLightMode, 0.0, 1.0)
|
|
1576
|
+
: (1.0 - darkAmt);
|
|
1577
|
+
vec3 effectiveBg = uHasBgColor > 0.5
|
|
1578
|
+
? uBgColor
|
|
1579
|
+
: mix(vec3(0.96, 0.953, 0.933), vec3(0.032, 0.04, 0.075), darkAmt);
|
|
1580
|
+
|
|
1298
1581
|
vec3 transmittance = exp(-tintMix * totalInk * 1.35);
|
|
1299
1582
|
float inkMask = clamp(1.0 - exp(-hC * 1.5), 0.0, 1.0);
|
|
1300
|
-
vec3 lightCol =
|
|
1583
|
+
vec3 lightCol = effectiveBg * transmittance;
|
|
1301
1584
|
lightCol *= mix(1.0, 0.90 + 0.16 * diffuse, inkMask * 0.72);
|
|
1302
1585
|
lightCol += vec3(0.025) * rimSheen * inkMask * (1.0 - inkMask * 0.45);
|
|
1303
1586
|
|
|
1304
|
-
// Dark water: Luminous bioluminescent plumes on solid bg
|
|
1305
1587
|
vec3 luminous = (vec3(1.0) - exp(-tintMix * totalInk * 1.25)) * (0.86 + 0.24 * diffuse);
|
|
1306
|
-
vec3 darkCol =
|
|
1588
|
+
vec3 darkCol = effectiveBg + luminous + luminous * rimSheen * 0.12;
|
|
1307
1589
|
|
|
1308
|
-
vec3 opaqueCol = mix(darkCol, lightCol,
|
|
1590
|
+
vec3 opaqueCol = mix(darkCol, lightCol, effectiveLightMode);
|
|
1309
1591
|
|
|
1310
|
-
// Subtle vignette + fine organic grain on solid bg
|
|
1311
1592
|
vec2 centered = vUv - 0.5;
|
|
1312
|
-
float vignetteStrength = mix(0.36, 0.085,
|
|
1593
|
+
float vignetteStrength = mix(0.36, 0.085, effectiveLightMode);
|
|
1313
1594
|
opaqueCol *= (1.0 - dot(centered, centered) * vignetteStrength);
|
|
1314
1595
|
float grain = (hash12(vUv * 900.0 + fract(uTime * 0.05)) - 0.5) * 0.011;
|
|
1315
1596
|
opaqueCol = clamp(opaqueCol + grain, 0.0, 1.0);
|
|
1316
1597
|
|
|
1317
|
-
// Transparent backdrop mode: only render pigment/ink with alpha over page/body bg
|
|
1318
1598
|
float inkAlpha = clamp(1.0 - exp(-totalInk * 1.35), 0.0, 1.0);
|
|
1319
1599
|
vec3 inkRgb = clamp(tintMix * (0.82 + 0.28 * diffuse) + vec3(0.04) * rimSheen, 0.0, 1.0);
|
|
1320
1600
|
|
|
1321
1601
|
if (uTransparentBg > 0.5) {
|
|
1322
|
-
// Premultiplied alpha works cleanly with standard canvas alpha blending
|
|
1323
1602
|
fragColor = vec4(inkRgb * inkAlpha, inkAlpha);
|
|
1324
1603
|
} else {
|
|
1325
1604
|
fragColor = vec4(opaqueCol, 1.0);
|
|
1326
1605
|
}
|
|
1327
|
-
}`,
|
|
1606
|
+
}`,Ke=O({name:"aetheria",fragmentShader:Ot,feedbackShader:It,feedbackFloat:!0,defaultColors:["#1e3a5f","#2d3748","#0284c7"],resolveUniforms(s){let e=I(s,"#f5f3ee"),t=typeof s.lightMode=="number"||typeof s.lightMode=="boolean"||e.hasBgColor,i=Xe(e.bgHex)?1:0,r=typeof s.lightMode=="number"?s.lightMode:typeof s.lightMode=="boolean"?s.lightMode?1:0:i;return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uHasExplicitLightMode:t?1:0,uTransparentBg:e.uTransparentBg,uLightMode:r,uAbsorptionGain:typeof s.absorptionGain=="number"?s.absorptionGain:1.45,uDissipation:typeof s.dissipation=="number"?s.dissipation:.978,uRadius:typeof s.radius=="number"?s.radius:.0032,uCurl:typeof s.curl=="number"?s.curl:1.85}}});var _t=`#version 300 es
|
|
1607
|
+
precision highp float;
|
|
1608
|
+
|
|
1609
|
+
in vec2 vUv;
|
|
1610
|
+
out vec4 fragColor;
|
|
1611
|
+
|
|
1612
|
+
uniform float uTime;
|
|
1613
|
+
uniform vec2 uResolution;
|
|
1614
|
+
uniform vec2 uMouse;
|
|
1615
|
+
uniform float uMouseActive;
|
|
1616
|
+
uniform float uMouseDown;
|
|
1617
|
+
uniform float uScroll;
|
|
1618
|
+
uniform vec3 uBgColor;
|
|
1619
|
+
uniform float uHasBgColor;
|
|
1620
|
+
uniform float uTransparentBg;
|
|
1621
|
+
uniform float uTheme;
|
|
1622
|
+
uniform float uQuality;
|
|
1623
|
+
uniform vec3 uColor1;
|
|
1624
|
+
uniform vec3 uColor2;
|
|
1625
|
+
uniform vec3 uColor3;
|
|
1626
|
+
uniform float uShape;
|
|
1627
|
+
uniform float uDepth;
|
|
1628
|
+
uniform float uGloss;
|
|
1629
|
+
uniform float uDistortion;
|
|
1630
|
+
|
|
1631
|
+
mat2 rot2(float a) {
|
|
1632
|
+
float c = cos(a);
|
|
1633
|
+
float s = sin(a);
|
|
1634
|
+
return mat2(c, -s, s, c);
|
|
1635
|
+
}
|
|
1636
|
+
|
|
1637
|
+
float smin(float a, float b, float k) {
|
|
1638
|
+
float h = clamp(0.5 + 0.5 * (b - a) / max(k, 0.0001), 0.0, 1.0);
|
|
1639
|
+
return mix(b, a, h) - k * h * (1.0 - h);
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
float sdSphere(vec3 p, float r) {
|
|
1643
|
+
return length(p) - r;
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
float sdTorus(vec3 p, vec2 t) {
|
|
1647
|
+
vec2 q = vec2(length(p.xz) - t.x, p.y);
|
|
1648
|
+
return length(q) - t.y;
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
float sdOctahedron(vec3 p, float s) {
|
|
1652
|
+
p = abs(p);
|
|
1653
|
+
float m = p.x + p.y + p.z - s;
|
|
1654
|
+
vec3 q;
|
|
1655
|
+
if (3.0 * p.x < m) q = p.xyz;
|
|
1656
|
+
else if (3.0 * p.y < m) q = p.yzx;
|
|
1657
|
+
else if (3.0 * p.z < m) q = p.zxy;
|
|
1658
|
+
else return m * 0.57735027;
|
|
1659
|
+
float k = clamp(0.5 * (q.z - q.y + s), 0.0, s);
|
|
1660
|
+
return length(vec3(q.x, q.y - s + k, q.z - k));
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1663
|
+
float mapScene(vec3 p, float t) {
|
|
1664
|
+
vec3 q = p;
|
|
1665
|
+
float twist = uDistortion * (0.65 + 0.35 * sin(t * 0.7));
|
|
1666
|
+
q.xz *= rot2(t * 0.42 + q.y * twist + uScroll * 1.5);
|
|
1667
|
+
q.yz *= rot2(t * 0.31);
|
|
1668
|
+
|
|
1669
|
+
float dMain;
|
|
1670
|
+
if (uShape < 0.5) {
|
|
1671
|
+
// Prism: faceted crystal + smooth-blended core sphere
|
|
1672
|
+
float oct = sdOctahedron(q, 0.76) - 0.05;
|
|
1673
|
+
float core = sdSphere(q, 0.48);
|
|
1674
|
+
dMain = smin(oct, core, 0.18);
|
|
1675
|
+
} else if (uShape < 1.5) {
|
|
1676
|
+
// Torus: twisted orbital ring + inner core
|
|
1677
|
+
float tor = sdTorus(q, vec2(0.62, 0.23));
|
|
1678
|
+
float core = sdSphere(q * 1.15, 0.34);
|
|
1679
|
+
dMain = smin(tor, core, 0.24);
|
|
1680
|
+
} else {
|
|
1681
|
+
// Orb: breathing sculpted sphere
|
|
1682
|
+
float disp = sin(q.x * 4.2 + t * 1.4) * sin(q.y * 4.2 - t * 1.1) * sin(q.z * 4.2 + t * 0.9);
|
|
1683
|
+
dMain = sdSphere(q, 0.62) + disp * (0.04 + uDistortion * 0.12);
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
// Orbiting 3D satellites smoothly fusing into the main form
|
|
1687
|
+
vec3 orb1 = vec3(cos(t * 0.95) * 0.72, sin(t * 1.2) * 0.36, sin(t * 0.95) * 0.72);
|
|
1688
|
+
vec3 orb2 = vec3(sin(t * 0.75 + 2.1) * 0.68, cos(t * 1.05) * 0.42, cos(t * 0.75 + 2.1) * 0.68);
|
|
1689
|
+
float dOrbs = smin(sdSphere(p - orb1, 0.17), sdSphere(p - orb2, 0.14), 0.25);
|
|
1690
|
+
|
|
1691
|
+
float d = smin(dMain, dOrbs, 0.28);
|
|
1692
|
+
|
|
1693
|
+
if (uDistortion > 0.01 && uShape < 1.5) {
|
|
1694
|
+
float ripple = sin(q.x * 5.0 + t * 1.5) * sin(q.y * 5.0 - t * 1.2) * sin(q.z * 5.0 + t);
|
|
1695
|
+
d += ripple * uDistortion * 0.055;
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
return d;
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1701
|
+
vec3 calcNormal(vec3 p, float t) {
|
|
1702
|
+
vec2 e = vec2(0.0025, -0.0025);
|
|
1703
|
+
return normalize(
|
|
1704
|
+
e.xyy * mapScene(p + e.xyy, t) +
|
|
1705
|
+
e.yyx * mapScene(p + e.yyx, t) +
|
|
1706
|
+
e.yxy * mapScene(p + e.yxy, t) +
|
|
1707
|
+
e.xxx * mapScene(p + e.xxx, t)
|
|
1708
|
+
);
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
float calcAO(vec3 pos, vec3 nor, float t) {
|
|
1712
|
+
int taps = uQuality < 0.25 ? 2 : (uQuality < 0.75 ? 3 : 4);
|
|
1713
|
+
float occ = 0.0;
|
|
1714
|
+
float sca = 1.0;
|
|
1715
|
+
for (int i = 0; i < 4; i++) {
|
|
1716
|
+
if (i >= taps) break;
|
|
1717
|
+
float h = 0.025 + 0.11 * float(i) / 3.0;
|
|
1718
|
+
float d = mapScene(pos + h * nor, t);
|
|
1719
|
+
occ += (h - d) * sca;
|
|
1720
|
+
sca *= 0.88;
|
|
1721
|
+
}
|
|
1722
|
+
return clamp(1.0 - 2.2 * occ, 0.0, 1.0);
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1725
|
+
void main() {
|
|
1726
|
+
float aspect = uResolution.x / max(uResolution.y, 1.0);
|
|
1727
|
+
vec2 uv = (vUv - 0.5) * vec2(aspect, 1.0) * 2.0;
|
|
1728
|
+
|
|
1729
|
+
float t = uTime * 0.85;
|
|
1730
|
+
float camDist = 2.75 / clamp(uDepth, 0.45, 2.2);
|
|
1731
|
+
camDist -= uMouseDown * 0.22;
|
|
1732
|
+
|
|
1733
|
+
// Interactive 3D camera orbit from pointer position
|
|
1734
|
+
vec2 mOffset = (uMouse - 0.5) * 1.55 * uMouseActive;
|
|
1735
|
+
vec3 ro = vec3(0.0, 0.08 * sin(t * 0.4), camDist);
|
|
1736
|
+
ro.xz *= rot2(-mOffset.x + sin(t * 0.22) * 0.18);
|
|
1737
|
+
ro.yz *= rot2(mOffset.y * 0.65);
|
|
1738
|
+
|
|
1739
|
+
vec3 ta = vec3(0.0, 0.0, 0.0);
|
|
1740
|
+
vec3 ww = normalize(ta - ro);
|
|
1741
|
+
vec3 uu = normalize(cross(ww, vec3(0.0, 1.0, 0.0)));
|
|
1742
|
+
vec3 vv = cross(uu, ww);
|
|
1743
|
+
vec3 rd = normalize(uv.x * uu + uv.y * vv + 1.55 * ww);
|
|
1744
|
+
|
|
1745
|
+
int maxSteps = uQuality < 0.25 ? 32 : (uQuality < 0.75 ? 48 : 72);
|
|
1746
|
+
float maxDist = 7.0;
|
|
1747
|
+
float dTotal = 0.0;
|
|
1748
|
+
float minDist = 1e5;
|
|
1749
|
+
bool hit = false;
|
|
1750
|
+
|
|
1751
|
+
for (int i = 0; i < 72; i++) {
|
|
1752
|
+
if (i >= maxSteps) break;
|
|
1753
|
+
vec3 p = ro + rd * dTotal;
|
|
1754
|
+
float d = mapScene(p, t);
|
|
1755
|
+
minDist = min(minDist, max(d, 0.0));
|
|
1756
|
+
if (d < 0.0018) {
|
|
1757
|
+
hit = true;
|
|
1758
|
+
break;
|
|
1759
|
+
}
|
|
1760
|
+
if (dTotal > maxDist) break;
|
|
1761
|
+
dTotal += d * 0.85;
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
float darkAmt = clamp(uTheme, 0.0, 1.0);
|
|
1765
|
+
vec3 baseDark = uHasBgColor > 0.5 ? uBgColor : vec3(0.03, 0.04, 0.085);
|
|
1766
|
+
vec3 baseLight = uHasBgColor > 0.5 ? uBgColor : vec3(0.955, 0.95, 0.935);
|
|
1767
|
+
vec3 bgCol = mix(baseLight, baseDark, darkAmt);
|
|
1768
|
+
|
|
1769
|
+
// Volumetric aura around the 3D object
|
|
1770
|
+
float aura = exp(-minDist * 4.5);
|
|
1771
|
+
vec3 auraCol = mix(uColor1, uColor2, 0.5 + 0.5 * sin(uv.x + uv.y + t * 0.5));
|
|
1772
|
+
auraCol = mix(auraCol, uColor3, aura * 0.45);
|
|
1773
|
+
|
|
1774
|
+
if (!hit) {
|
|
1775
|
+
if (uTransparentBg > 0.5) {
|
|
1776
|
+
float alpha = clamp(aura * 0.52, 0.0, 1.0);
|
|
1777
|
+
fragColor = vec4(auraCol * alpha, alpha);
|
|
1778
|
+
return;
|
|
1779
|
+
}
|
|
1780
|
+
vec3 sky = bgCol + auraCol * aura * mix(0.18, 0.36, darkAmt);
|
|
1781
|
+
float vig = 1.0 - dot(vUv - 0.5, vUv - 0.5) * mix(0.14, 0.65, darkAmt);
|
|
1782
|
+
fragColor = vec4(clamp(sky * vig, 0.0, 1.0), 1.0);
|
|
1783
|
+
return;
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
vec3 pos = ro + rd * dTotal;
|
|
1787
|
+
vec3 nor = calcNormal(pos, t);
|
|
1788
|
+
float ao = calcAO(pos, nor, t);
|
|
1789
|
+
vec3 viewDir = -rd;
|
|
1790
|
+
|
|
1791
|
+
// 3-point 3D studio lighting
|
|
1792
|
+
vec3 keyDir = normalize(vec3(0.65, 0.8, 0.6));
|
|
1793
|
+
vec3 fillDir = normalize(vec3(-0.75, -0.35, 0.45));
|
|
1794
|
+
vec3 rimDir = normalize(vec3(-0.2, 0.5, -0.85));
|
|
1795
|
+
|
|
1796
|
+
float keyDiff = max(dot(nor, keyDir), 0.0);
|
|
1797
|
+
float fillDiff = max(dot(nor, fillDir), 0.0);
|
|
1798
|
+
float rimDiff = max(dot(nor, rimDir), 0.0);
|
|
1799
|
+
|
|
1800
|
+
vec3 halfKey = normalize(keyDir + viewDir);
|
|
1801
|
+
vec3 halfRim = normalize(rimDir + viewDir);
|
|
1802
|
+
float glossPow = mix(14.0, 64.0, clamp(uGloss * 0.6, 0.0, 1.0));
|
|
1803
|
+
float specKey = pow(max(dot(nor, halfKey), 0.0), glossPow) * uGloss;
|
|
1804
|
+
float specRim = pow(max(dot(nor, halfRim), 0.0), glossPow * 0.7) * uGloss;
|
|
1805
|
+
|
|
1806
|
+
float fresnel = pow(1.0 - max(dot(nor, viewDir), 0.0), 3.0);
|
|
1807
|
+
float irid = 0.5 + 0.5 * sin(dot(nor, viewDir) * 5.5 + pos.y * 2.5 + t * 0.8);
|
|
1808
|
+
|
|
1809
|
+
vec3 baseAlbedo = mix(uColor1, uColor2, 0.5 + 0.5 * nor.y);
|
|
1810
|
+
baseAlbedo = mix(baseAlbedo, uColor3, fresnel * 0.65 + irid * 0.25);
|
|
1811
|
+
|
|
1812
|
+
vec3 litCol = baseAlbedo * (0.24 + keyDiff * 0.78 + fillDiff * 0.32) * ao;
|
|
1813
|
+
litCol += mix(vec3(1.0), uColor3, 0.35) * specKey * 0.95;
|
|
1814
|
+
litCol += uColor2 * rimDiff * 0.42 + uColor3 * specRim * 0.45;
|
|
1815
|
+
litCol += mix(uColor2, uColor3, irid) * fresnel * 0.55;
|
|
1816
|
+
|
|
1817
|
+
// Depth fog blend for smooth silhouette edges
|
|
1818
|
+
float fog = smoothstep(1.2, 5.2, dTotal);
|
|
1819
|
+
if (uTransparentBg > 0.5) {
|
|
1820
|
+
vec3 col = clamp(mix(litCol, auraCol, fog * 0.35), 0.0, 1.0);
|
|
1821
|
+
float alpha = clamp(0.96 - fog * 0.25 + fresnel * 0.15, 0.0, 1.0);
|
|
1822
|
+
fragColor = vec4(col * alpha, alpha);
|
|
1823
|
+
return;
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
vec3 finalCol = mix(litCol, bgCol + auraCol * 0.25, fog * 0.45);
|
|
1827
|
+
float vig = 1.0 - dot(vUv - 0.5, vUv - 0.5) * mix(0.12, 0.55, darkAmt);
|
|
1828
|
+
fragColor = vec4(clamp(finalCol * vig, 0.0, 1.0), 1.0);
|
|
1829
|
+
}`;function Vt(s){if(typeof s=="number")return s;let e=String(s??"prism").trim().toLowerCase();return e==="torus"?1:e==="orb"||e==="sphere"?2:0}var Ye=O({name:"prism-3d",fragmentShader:_t,defaultColors:["#6366f1","#06b6d4","#f472b6"],resolveUniforms(s){let e=I(s,"#070a16");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg,uShape:Vt(s.shape),uDepth:typeof s.depth=="number"?s.depth:1,uGloss:typeof s.gloss=="number"?s.gloss:1,uDistortion:typeof s.distortion=="number"?s.distortion:.35}}});var Ht=`#version 300 es
|
|
1830
|
+
precision highp float;
|
|
1831
|
+
|
|
1832
|
+
in vec2 vUv;
|
|
1833
|
+
out vec4 fragColor;
|
|
1834
|
+
|
|
1835
|
+
uniform sampler2D uPrevFrame;
|
|
1836
|
+
uniform float uTime;
|
|
1837
|
+
uniform float uDelta;
|
|
1838
|
+
uniform vec2 uResolution;
|
|
1839
|
+
uniform vec2 uMouse;
|
|
1840
|
+
uniform vec2 uMouseVel;
|
|
1841
|
+
uniform float uMouseDown;
|
|
1842
|
+
uniform float uMouseActive;
|
|
1843
|
+
uniform float uSpeed;
|
|
1844
|
+
uniform float uDissipation;
|
|
1845
|
+
uniform float uRadius;
|
|
1846
|
+
uniform float uAmbient;
|
|
1847
|
+
uniform float uClickReveal;
|
|
1848
|
+
|
|
1849
|
+
float hash21(vec2 p) {
|
|
1850
|
+
p = fract(p * vec2(123.34, 456.21));
|
|
1851
|
+
p += dot(p, p + 45.32);
|
|
1852
|
+
return fract(p.x * p.y);
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
float valueNoise(vec2 p) {
|
|
1856
|
+
vec2 i = floor(p);
|
|
1857
|
+
vec2 f = fract(p);
|
|
1858
|
+
vec2 u = f * f * (3.0 - 2.0 * f);
|
|
1859
|
+
float a = hash21(i);
|
|
1860
|
+
float b = hash21(i + vec2(1.0, 0.0));
|
|
1861
|
+
float c = hash21(i + vec2(0.0, 1.0));
|
|
1862
|
+
float d = hash21(i + vec2(1.0, 1.0));
|
|
1863
|
+
return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1866
|
+
float sdSegment(vec2 p, vec2 a, vec2 b) {
|
|
1867
|
+
vec2 pa = p - a;
|
|
1868
|
+
vec2 ba = b - a;
|
|
1869
|
+
float h = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-6), 0.0, 1.0);
|
|
1870
|
+
return length(pa - ba * h);
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1873
|
+
void main() {
|
|
1874
|
+
vec2 texel = 1.0 / max(uResolution, vec2(1.0));
|
|
1875
|
+
float dt = clamp(uDelta, 0.004, 0.033);
|
|
1876
|
+
float aspect = uResolution.x / max(uResolution.y, 1.0);
|
|
1877
|
+
float speed = clamp(uSpeed, 0.25, 3.0);
|
|
1878
|
+
|
|
1879
|
+
vec4 c = texture(uPrevFrame, vUv);
|
|
1880
|
+
vec4 l = texture(uPrevFrame, vUv - vec2(texel.x, 0.0));
|
|
1881
|
+
vec4 r = texture(uPrevFrame, vUv + vec2(texel.x, 0.0));
|
|
1882
|
+
vec4 d = texture(uPrevFrame, vUv - vec2(0.0, texel.y));
|
|
1883
|
+
vec4 u = texture(uPrevFrame, vUv + vec2(0.0, texel.y));
|
|
1884
|
+
|
|
1885
|
+
float blurMask = (l.r + r.r + d.r + u.r) * 0.25;
|
|
1886
|
+
float hold = pow(clamp(uDissipation, 0.85, 0.9995), dt * 60.0 * speed);
|
|
1887
|
+
|
|
1888
|
+
float n = valueNoise(vUv * 14.0 + vec2(uTime * 0.25, -uTime * 0.18));
|
|
1889
|
+
float prevMask = mix(c.r, blurMask, 0.14) * hold;
|
|
1890
|
+
if (uDissipation < 0.9985) {
|
|
1891
|
+
prevMask = max(0.0, prevMask - dt * 0.015 * (1.0 + (1.0 - n) * 0.6));
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
float brushVal = 0.0;
|
|
1895
|
+
vec2 p = vUv * vec2(aspect, 1.0);
|
|
1896
|
+
float baseRad = clamp(uRadius, 0.02, 0.65);
|
|
1897
|
+
|
|
1898
|
+
if (uMouseActive > 0.01) {
|
|
1899
|
+
vec2 curM = uMouse * vec2(aspect, 1.0);
|
|
1900
|
+
vec2 prevM = clamp(uMouse - uMouseVel * dt, vec2(0.0), vec2(1.0)) * vec2(aspect, 1.0);
|
|
1901
|
+
float dist = sdSegment(p, prevM, curM);
|
|
1902
|
+
|
|
1903
|
+
float velBoost = 1.0 + min(length(uMouseVel) * 0.12, 0.45);
|
|
1904
|
+
float clickBoost = (uClickReveal > 0.5 && uMouseDown > 0.5) ? 1.5 : 1.0;
|
|
1905
|
+
float rad = baseRad * velBoost * clickBoost;
|
|
1906
|
+
|
|
1907
|
+
float organicDist = dist + (n - 0.5) * rad * 0.28;
|
|
1908
|
+
float stroke = 1.0 - smoothstep(rad * 0.24, rad, organicDist);
|
|
1909
|
+
brushVal = max(brushVal, stroke * clamp(uMouseActive, 0.0, 1.0));
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
if (uAmbient > 0.5 && uMouseActive < 0.25) {
|
|
1913
|
+
float t = uTime * 0.55 * speed;
|
|
1914
|
+
vec2 ambCenter = vec2(
|
|
1915
|
+
0.5 + 0.13 * sin(t) + 0.04 * cos(t * 2.1),
|
|
1916
|
+
0.54 + 0.11 * cos(t * 0.82)
|
|
1917
|
+
) * vec2(aspect, 1.0);
|
|
1918
|
+
float ambDist = length(p - ambCenter);
|
|
1919
|
+
float ambRad = baseRad * 0.88;
|
|
1920
|
+
float ambStroke = 1.0 - smoothstep(ambRad * 0.25, ambRad, ambDist + (n - 0.5) * ambRad * 0.28);
|
|
1921
|
+
brushVal = max(brushVal, ambStroke * 0.82 * (1.0 - smoothstep(0.0, 0.25, uMouseActive)));
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
float nextMask = clamp(max(prevMask, brushVal), 0.0, 1.0);
|
|
1925
|
+
float freshEdge = clamp(mix(c.g * 0.88, brushVal, 0.45), 0.0, 1.0);
|
|
1926
|
+
|
|
1927
|
+
fragColor = vec4(nextMask, freshEdge, 0.0, 1.0);
|
|
1928
|
+
}`,Wt=`#version 300 es
|
|
1929
|
+
precision highp float;
|
|
1930
|
+
|
|
1931
|
+
in vec2 vUv;
|
|
1932
|
+
out vec4 fragColor;
|
|
1933
|
+
|
|
1934
|
+
uniform sampler2D uFeedback;
|
|
1935
|
+
uniform sampler2D uBaseTex;
|
|
1936
|
+
uniform sampler2D uRevealTex;
|
|
1937
|
+
uniform vec2 uBaseTexSize;
|
|
1938
|
+
uniform vec2 uRevealTexSize;
|
|
1939
|
+
uniform float uBaseTexReady;
|
|
1940
|
+
uniform float uRevealTexReady;
|
|
1941
|
+
|
|
1942
|
+
uniform float uTime;
|
|
1943
|
+
uniform vec2 uResolution;
|
|
1944
|
+
uniform vec3 uBgColor;
|
|
1945
|
+
uniform float uHasBgColor;
|
|
1946
|
+
uniform float uTransparentBg;
|
|
1947
|
+
uniform vec3 uColor1;
|
|
1948
|
+
uniform vec3 uColor2;
|
|
1949
|
+
|
|
1950
|
+
uniform float uFit;
|
|
1951
|
+
uniform vec2 uPosition;
|
|
1952
|
+
uniform float uSoftness;
|
|
1953
|
+
uniform float uEdgeNoise;
|
|
1954
|
+
uniform float uEdgeGlow;
|
|
1955
|
+
|
|
1956
|
+
float hash21(vec2 p) {
|
|
1957
|
+
p = fract(p * vec2(127.1, 311.7));
|
|
1958
|
+
p += dot(p, p + 34.23);
|
|
1959
|
+
return fract(p.x * p.y);
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1962
|
+
float valueNoise(vec2 p) {
|
|
1963
|
+
vec2 i = floor(p);
|
|
1964
|
+
vec2 f = fract(p);
|
|
1965
|
+
vec2 u = f * f * (3.0 - 2.0 * f);
|
|
1966
|
+
return mix(
|
|
1967
|
+
mix(hash21(i), hash21(i + vec2(1.0, 0.0)), u.x),
|
|
1968
|
+
mix(hash21(i + vec2(0.0, 1.0)), hash21(i + vec2(1.0, 1.0)), u.x),
|
|
1969
|
+
u.y
|
|
1970
|
+
);
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
float fbm(vec2 p) {
|
|
1974
|
+
float v = 0.0;
|
|
1975
|
+
float a = 0.5;
|
|
1976
|
+
mat2 rot = mat2(0.8, 0.6, -0.6, 0.8);
|
|
1977
|
+
for (int i = 0; i < 4; i++) {
|
|
1978
|
+
v += a * valueNoise(p);
|
|
1979
|
+
p = rot * p * 2.07 + vec2(17.1, 31.7);
|
|
1980
|
+
a *= 0.5;
|
|
1981
|
+
}
|
|
1982
|
+
return v;
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
vec2 computeFitUv(vec2 uv, vec2 res, vec2 texSize, float fitMode, vec2 align) {
|
|
1986
|
+
float canvasAspect = res.x / max(res.y, 1.0);
|
|
1987
|
+
float texAspect = texSize.x / max(texSize.y, 1.0);
|
|
1988
|
+
float r = canvasAspect / max(texAspect, 0.0001);
|
|
1989
|
+
|
|
1990
|
+
vec2 scale = vec2(1.0);
|
|
1991
|
+
if (fitMode < 0.5) {
|
|
1992
|
+
// cover
|
|
1993
|
+
if (r > 1.0) {
|
|
1994
|
+
scale = vec2(1.0, 1.0 / r);
|
|
1995
|
+
} else {
|
|
1996
|
+
scale = vec2(r, 1.0);
|
|
1997
|
+
}
|
|
1998
|
+
} else {
|
|
1999
|
+
// contain
|
|
2000
|
+
if (r > 1.0) {
|
|
2001
|
+
scale = vec2(r, 1.0);
|
|
2002
|
+
} else {
|
|
2003
|
+
scale = vec2(1.0, 1.0 / r);
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
return (uv - align) * scale + align;
|
|
2008
|
+
}
|
|
2009
|
+
|
|
2010
|
+
void main() {
|
|
2011
|
+
if (uBaseTexReady < 0.5) {
|
|
2012
|
+
if (uHasBgColor > 0.5 && uTransparentBg < 0.5) {
|
|
2013
|
+
fragColor = vec4(uBgColor, 1.0);
|
|
2014
|
+
} else {
|
|
2015
|
+
fragColor = vec4(0.0);
|
|
2016
|
+
}
|
|
2017
|
+
return;
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
vec2 baseUv = computeFitUv(vUv, uResolution, max(uBaseTexSize, vec2(1.0)), uFit, uPosition);
|
|
2021
|
+
bool inBase = baseUv.x >= 0.0 && baseUv.x <= 1.0 && baseUv.y >= 0.0 && baseUv.y <= 1.0;
|
|
2022
|
+
|
|
2023
|
+
if (!inBase) {
|
|
2024
|
+
if (uHasBgColor > 0.5 && uTransparentBg < 0.5) {
|
|
2025
|
+
fragColor = vec4(uBgColor, 1.0);
|
|
2026
|
+
} else {
|
|
2027
|
+
fragColor = vec4(0.0);
|
|
2028
|
+
}
|
|
2029
|
+
return;
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
vec2 baseSampleUv = vec2(baseUv.x, 1.0 - baseUv.y);
|
|
2033
|
+
vec4 baseCol = texture(uBaseTex, baseSampleUv);
|
|
2034
|
+
|
|
2035
|
+
if (uRevealTexReady < 0.5) {
|
|
2036
|
+
if (uHasBgColor > 0.5 && uTransparentBg < 0.5) {
|
|
2037
|
+
fragColor = vec4(mix(uBgColor, baseCol.rgb, baseCol.a), 1.0);
|
|
2038
|
+
} else {
|
|
2039
|
+
fragColor = vec4(baseCol.rgb * baseCol.a, baseCol.a);
|
|
2040
|
+
}
|
|
2041
|
+
return;
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
vec2 fboTexel = 1.0 / max(vec2(textureSize(uFeedback, 0)), vec2(1.0));
|
|
2045
|
+
float m = texture(uFeedback, vUv).r;
|
|
2046
|
+
float mL = texture(uFeedback, vUv - vec2(fboTexel.x * 2.0, 0.0)).r;
|
|
2047
|
+
float mR = texture(uFeedback, vUv + vec2(fboTexel.x * 2.0, 0.0)).r;
|
|
2048
|
+
float mD = texture(uFeedback, vUv - vec2(0.0, fboTexel.y * 2.0)).r;
|
|
2049
|
+
float mU = texture(uFeedback, vUv + vec2(0.0, fboTexel.y * 2.0)).r;
|
|
2050
|
+
vec2 grad = vec2(mR - mL, mU - mD);
|
|
2051
|
+
|
|
2052
|
+
float aspect = uResolution.x / max(uResolution.y, 1.0);
|
|
2053
|
+
vec2 noiseCoord = vUv * vec2(aspect, 1.0) * 16.0;
|
|
2054
|
+
float nMacro = fbm(noiseCoord + vec2(uTime * 0.08, -uTime * 0.06));
|
|
2055
|
+
float nGrain = hash21(floor(vUv * uResolution * 0.55) + fract(uTime * 0.25));
|
|
2056
|
+
float dissolveNoise = mix(nMacro, nGrain, 0.24);
|
|
2057
|
+
|
|
2058
|
+
// Zero noise outside touched mask (m=0) or inside solid core (m=1)
|
|
2059
|
+
float edgeEnvelope = sin(clamp(m, 0.0, 1.0) * 3.14159265);
|
|
2060
|
+
float perturbed = m + (dissolveNoise - 0.5) * clamp(uEdgeNoise, 0.0, 0.9) * edgeEnvelope;
|
|
2061
|
+
float soft = clamp(uSoftness, 0.015, 0.49);
|
|
2062
|
+
float revealMask = smoothstep(0.5 - soft, 0.5 + soft, perturbed) * smoothstep(0.0, 0.02, m);
|
|
2063
|
+
|
|
2064
|
+
vec2 revUv = computeFitUv(vUv, uResolution, max(uRevealTexSize, vec2(1.0)), uFit, uPosition);
|
|
2065
|
+
vec2 revSampleUv = clamp(vec2(revUv.x, 1.0 - revUv.y) + grad * 0.0045 * edgeEnvelope, 0.0, 1.0);
|
|
2066
|
+
vec4 revCol = texture(uRevealTex, revSampleUv);
|
|
2067
|
+
|
|
2068
|
+
vec3 col = mix(baseCol.rgb, revCol.rgb, revealMask);
|
|
2069
|
+
float outAlpha = mix(baseCol.a, revCol.a, revealMask);
|
|
2070
|
+
|
|
2071
|
+
float edgeBand = 4.0 * revealMask * (1.0 - revealMask);
|
|
2072
|
+
vec3 shimmer = mix(uColor1, uColor2, 0.5 + 0.5 * nMacro);
|
|
2073
|
+
col = clamp(col + shimmer * edgeBand * clamp(uEdgeGlow, 0.0, 1.5) * 0.5, 0.0, 1.0);
|
|
2074
|
+
|
|
2075
|
+
if (uHasBgColor > 0.5 && uTransparentBg < 0.5) {
|
|
2076
|
+
fragColor = vec4(mix(uBgColor, col, outAlpha), 1.0);
|
|
2077
|
+
return;
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
fragColor = vec4(col * outAlpha, outAlpha);
|
|
2081
|
+
}`;function Gt(s){return String(s??"cover").trim().toLowerCase()==="contain"?1:0}function zt(s){let e=String(s??"center").trim().toLowerCase();return e==="bottom"?[.5,0]:e==="top"?[.5,1]:[.5,.5]}function je(s){return typeof s=="string"?s.trim():""}function Je(s,e){if(typeof s=="boolean")return s?1:0;if(typeof s=="string"){let t=s.trim().toLowerCase();if(t==="true")return 1;if(t==="false")return 0}return typeof s=="number"?s>.5?1:0:e?1:0}var Ze=O({name:"brush-reveal",fragmentShader:Wt,feedbackShader:Ht,feedbackFloat:!0,defaultColors:["#ff6b2b","#ffd166","#ffffff"],resolveTextures(s){return{uBaseTex:je(s.baseImage??s.image),uRevealTex:je(s.revealImage)}},resolveUniforms(s){let e=I(s,"#000000");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg,uRadius:typeof s.radius=="number"?s.radius:.13,uSoftness:typeof s.softness=="number"?s.softness:.22,uEdgeNoise:typeof s.edgeNoise=="number"?s.edgeNoise:.38,uEdgeGlow:typeof s.edgeGlow=="number"?s.edgeGlow:.24,uDissipation:typeof s.dissipation=="number"?s.dissipation:.985,uFit:Gt(s.fit),uPosition:zt(s.position),uAmbient:Je(s.ambient,!1),uClickReveal:Je(s.clickReveal,!0)}}});var Xt=`#version 300 es
|
|
2082
|
+
precision highp float;
|
|
2083
|
+
|
|
2084
|
+
in vec2 vUv;
|
|
2085
|
+
out vec4 fragColor;
|
|
2086
|
+
|
|
2087
|
+
uniform float uTime;
|
|
2088
|
+
uniform vec2 uResolution;
|
|
2089
|
+
uniform vec2 uMouse;
|
|
2090
|
+
uniform float uMouseActive;
|
|
2091
|
+
uniform float uScroll;
|
|
2092
|
+
uniform vec3 uBgColor;
|
|
2093
|
+
uniform float uHasBgColor;
|
|
2094
|
+
uniform float uTransparentBg;
|
|
2095
|
+
uniform float uTheme;
|
|
2096
|
+
uniform vec3 uColor1;
|
|
2097
|
+
uniform vec3 uColor2;
|
|
2098
|
+
uniform vec3 uColor3;
|
|
2099
|
+
uniform float uSpotRadius;
|
|
2100
|
+
uniform float uSpotIntensity;
|
|
2101
|
+
uniform vec2 uSpotPosition;
|
|
2102
|
+
|
|
2103
|
+
float hash21(vec2 p) {
|
|
2104
|
+
p = fract(p * vec2(127.1, 311.7));
|
|
2105
|
+
p += dot(p, p + 34.23);
|
|
2106
|
+
return fract(p.x * p.y);
|
|
2107
|
+
}
|
|
2108
|
+
|
|
2109
|
+
void main() {
|
|
2110
|
+
float aspect = uResolution.x / max(uResolution.y, 1.0);
|
|
2111
|
+
float darkAmt = clamp(uTheme, 0.0, 1.0);
|
|
2112
|
+
|
|
2113
|
+
// Base cyclorama studio tone: uses bgColor if set, otherwise uColor1 tinted studio backdrop
|
|
2114
|
+
vec3 defaultDark = mix(vec3(0.055, 0.06, 0.075), uColor1, 0.35);
|
|
2115
|
+
vec3 defaultLight = mix(vec3(0.945, 0.935, 0.92), uColor1, 0.65);
|
|
2116
|
+
vec3 baseCol = uHasBgColor > 0.5 ? uBgColor : mix(defaultLight, defaultDark, darkAmt);
|
|
2117
|
+
|
|
2118
|
+
// Smooth cursor-reactive studio spotlight tracking (returns to uSpotPosition when pointer leaves)
|
|
2119
|
+
vec2 baseOrigin = clamp(uSpotPosition + vec2(0.0, -uScroll * 0.04), vec2(0.08), vec2(0.92));
|
|
2120
|
+
vec2 spotOrigin = mix(baseOrigin, clamp(uMouse, vec2(0.05), vec2(0.95)), clamp(uMouseActive, 0.0, 1.0));
|
|
2121
|
+
|
|
2122
|
+
vec2 delta = (vUv - spotOrigin) * vec2(aspect, 1.0);
|
|
2123
|
+
float dist = length(delta);
|
|
2124
|
+
|
|
2125
|
+
float rad = clamp(uSpotRadius, 0.18, 1.45);
|
|
2126
|
+
float coreGlow = exp(-(dist * dist) / (rad * rad * 0.42));
|
|
2127
|
+
float wideHalo = exp(-(dist * dist) / (rad * rad * 1.65));
|
|
2128
|
+
|
|
2129
|
+
// Subtle vertical studio floor gradient & overhead rim wash
|
|
2130
|
+
float floorGrad = smoothstep(0.0, 0.36, vUv.y);
|
|
2131
|
+
float topWash = smoothstep(0.35, 1.0, vUv.y) * 0.12;
|
|
2132
|
+
float breathe = 0.96 + 0.04 * sin(uTime * 0.75);
|
|
2133
|
+
|
|
2134
|
+
vec3 spotColor = mix(uColor2, uColor3, coreGlow * 0.65);
|
|
2135
|
+
float intensity = clamp(uSpotIntensity, 0.0, 2.5) * breathe;
|
|
2136
|
+
|
|
2137
|
+
vec3 col = baseCol;
|
|
2138
|
+
col = mix(col, spotColor, wideHalo * 0.42 * intensity);
|
|
2139
|
+
col += spotColor * coreGlow * mix(0.28, 0.52, darkAmt) * intensity;
|
|
2140
|
+
col += uColor2 * topWash * intensity * 0.35;
|
|
2141
|
+
|
|
2142
|
+
// Soft studio cyclorama floor shadow near bottom
|
|
2143
|
+
col *= mix(0.84, 1.0, floorGrad);
|
|
2144
|
+
|
|
2145
|
+
// Subtle edge vignette for depth
|
|
2146
|
+
vec2 vigUv = vUv - 0.5;
|
|
2147
|
+
float vig = 1.0 - dot(vigUv, vigUv) * mix(0.16, 0.48, darkAmt);
|
|
2148
|
+
col *= vig;
|
|
2149
|
+
|
|
2150
|
+
// Fine dithering grain to eliminate 8-bit gradient banding
|
|
2151
|
+
float grain = (hash21(gl_FragCoord.xy + fract(uTime * 0.17)) - 0.5) * 0.014;
|
|
2152
|
+
col = clamp(col + vec3(grain), 0.0, 1.0);
|
|
2153
|
+
|
|
2154
|
+
if (uTransparentBg > 0.5) {
|
|
2155
|
+
float alpha = clamp((wideHalo * 0.45 + coreGlow * 0.55) * intensity, 0.0, 1.0);
|
|
2156
|
+
fragColor = vec4(spotColor * alpha, alpha);
|
|
2157
|
+
return;
|
|
2158
|
+
}
|
|
2159
|
+
|
|
2160
|
+
fragColor = vec4(col, 1.0);
|
|
2161
|
+
}`;function Nt(s){if(Array.isArray(s)&&s.length>=2){let t=Number(s[0]),i=Number(s[1]);if(!Number.isNaN(t)&&!Number.isNaN(i))return[t,i]}let e=String(s??"center").trim().toLowerCase();return e==="left"?[.34,.52]:e==="right"?[.66,.52]:[.5,.52]}var et=O({name:"spotlight",fragmentShader:Xt,defaultColors:["#14161a","#4b5563","#f8fafc"],resolveUniforms(s){let e=I(s,"#121316");return{uBgColor:e.uBgColor,uHasBgColor:e.uHasBgColor,uTransparentBg:e.uTransparentBg,uSpotRadius:typeof s.spotRadius=="number"?s.spotRadius:.62,uSpotIntensity:typeof s.spotIntensity=="number"?s.spotIntensity:1,uSpotPosition:Nt(s.spotPosition)}}});var tt={name:"tilt-3d",mount(s,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,o=e.glare!==!1,n=e.respectReducedMotion??!0,l=s.style.transform,a=s.style.position,c=s.style.overflow,u=s.style.willChange,d=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(prefers-reduced-motion: reduce)"):null,f=n&&(d?.matches??!1);f||(s.style.willChange="transform");let h=null;o&&(getComputedStyle(s).position==="static"&&(s.style.position="relative"),s.style.overflow="hidden",h=document.createElement("div"),Object.assign(h.style,{position:"absolute",inset:"0",pointerEvents:"none",borderRadius:"inherit",opacity:"0",transition:"opacity 0.25s ease",zIndex:"2"}),s.appendChild(h));let m=0,v=0,g=1,b=0,x=0,y=1,T=50,R=50,E=!1,S=!1,M=null,L=null,U=!0,_=()=>{U=!0},ee=()=>{let p=s.getBoundingClientRect();L={left:p.left,top:p.top,width:p.width,height:p.height},U=!1},q=p=>{let C=n&&p.matches;f!==C&&(f=C,f?(m=0,v=0,g=1,b=0,x=0,y=1,E=!1,h&&(h.style.opacity="0"),s.style.transform=l,s.style.willChange=u):(s.style.willChange="transform",U=!0),M?.())},$=()=>{U=!0},K=p=>{if(S||f||((U||!L)&&ee(),!L||L.width<=0||L.height<=0))return;let C=(p.clientX-L.left)/L.width,w=(p.clientY-L.top)/L.height;m=(.5-w)*t*2,v=(C-.5)*t*2,g=i,T=C*100,R=w*100,E=!0,h&&(h.style.opacity="1"),M?.()},Y=()=>{f||(m=0,v=0,g=1,h&&(h.style.opacity="0"),(Math.abs(b)>.01||Math.abs(x)>.01||Math.abs(y-1)>.001)&&(E=!0,S||M?.()))},j=null;return typeof ResizeObserver<"u"&&(j=new ResizeObserver(_),j.observe(s)),d&&typeof d.addEventListener=="function"&&d.addEventListener("change",q),s.addEventListener("pointerenter",$,{passive:!0}),s.addEventListener("pointermove",K,{passive:!0}),s.addEventListener("pointerleave",Y,{passive:!0}),window.addEventListener("resize",_,{passive:!0}),window.addEventListener("scroll",_,{passive:!0,capture:!0}),{update(p,C){if(!E||S||f)return;let w=1-Math.exp(-12*C);if(b+=(m-b)*w,x+=(v-x)*w,y+=(g-y)*w,h&&(h.style.background=`radial-gradient(circle at ${T.toFixed(1)}% ${R.toFixed(1)}%, rgba(255,255,255,0.22), transparent 60%)`),Math.abs(m-b)<.02&&Math.abs(v-x)<.02&&Math.abs(g-y)<.001){b=m,x=v,y=g,E=!1,s.style.transform=g===1&&m===0&&v===0?l:`perspective(${r}px) rotateX(${b.toFixed(2)}deg) rotateY(${x.toFixed(2)}deg) scale3d(${y.toFixed(3)}, ${y.toFixed(3)}, 1)`;return}s.style.transform=`perspective(${r}px) rotateX(${b.toFixed(2)}deg) rotateY(${x.toFixed(2)}deg) scale3d(${y.toFixed(3)}, ${y.toFixed(3)}, 1)`},isIdle(){return!E||S||f},onWake(p){M=p},pause(){S=!0},resume(){S=!1,U=!0,E&&!f&&M?.()},destroy(){M=null,E=!1,L=null,j?.disconnect(),j=null,d&&typeof d.removeEventListener=="function"&&d.removeEventListener("change",q),s.removeEventListener("pointerenter",$),s.removeEventListener("pointermove",K),s.removeEventListener("pointerleave",Y),window.removeEventListener("resize",_),window.removeEventListener("scroll",_,!0),h?.remove(),s.style.transform=l,s.style.position=a,s.style.overflow=c,s.style.willChange=u}}}};var it={name:"magnetic",mount(s,e){let t=typeof e.strength=="number"?e.strength:.35,i=e.respectReducedMotion??!0,r=s.style.transform,o=s.style.willChange,n=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(prefers-reduced-motion: reduce)"):null,l=i&&(n?.matches??!1);l||(s.style.willChange="transform");let a=0,c=0,u=0,d=0,f=!1,h=!1,m=null,v=null,g=!0,b=()=>{g=!0},x=()=>{let M=s.getBoundingClientRect();v={left:M.left-u,top:M.top-d,width:M.width,height:M.height},g=!1},y=M=>{let L=i&&M.matches;l!==L&&(l=L,l?(a=0,c=0,u=0,d=0,f=!1,s.style.transform=r,s.style.willChange=o):(s.style.willChange="transform",g=!0),m?.())},T=()=>{g=!0},R=M=>{if(h||l||((g||!v)&&x(),!v||v.width<=0||v.height<=0))return;let L=v.left+v.width*.5,U=v.top+v.height*.5;a=(M.clientX-L)*t,c=(M.clientY-U)*t,f=!0,m?.()},E=()=>{l||(a=0,c=0,(Math.abs(u)>.01||Math.abs(d)>.01)&&(f=!0,h||m?.()))},S=null;return typeof ResizeObserver<"u"&&(S=new ResizeObserver(b),S.observe(s)),n&&typeof n.addEventListener=="function"&&n.addEventListener("change",y),s.addEventListener("pointerenter",T,{passive:!0}),s.addEventListener("pointermove",R,{passive:!0}),s.addEventListener("pointerleave",E,{passive:!0}),window.addEventListener("resize",b,{passive:!0}),window.addEventListener("scroll",b,{passive:!0,capture:!0}),{update(M,L){if(!f||h||l)return;let U=1-Math.exp(-10*L);if(u+=(a-u)*U,d+=(c-d)*U,Math.abs(a-u)<.05&&Math.abs(c-d)<.05){u=a,d=c,f=!1,s.style.transform=a===0&&c===0?r:`translate3d(${u.toFixed(2)}px, ${d.toFixed(2)}px, 0)`;return}s.style.transform=`translate3d(${u.toFixed(2)}px, ${d.toFixed(2)}px, 0)`},isIdle(){return!f||h||l},onWake(M){m=M},pause(){h=!0},resume(){h=!1,g=!0,f&&!l&&m?.()},destroy(){m=null,f=!1,v=null,S?.disconnect(),S=null,n&&typeof n.removeEventListener=="function"&&n.removeEventListener("change",y),s.removeEventListener("pointerenter",T),s.removeEventListener("pointermove",R),s.removeEventListener("pointerleave",E),window.removeEventListener("resize",b),window.removeEventListener("scroll",b,!0),s.style.transform=r,s.style.willChange=o}}}};function Q(s,e,t){return Math.min(t,Math.max(e,s))}function Z(s,e){return typeof s=="number"&&!Number.isNaN(s)?s:e}function we(s,e){if(typeof s=="boolean")return s;if(typeof s=="string"){let t=s.trim().toLowerCase();if(t==="true")return!0;if(t==="false")return!1}return e}function Qt(s){return s===!1?0:s===!0||s===void 0?18:typeof s=="number"&&!Number.isNaN(s)?s:18}function rt(s,e){let t=Math.round(Z(s.activeIndex,0));return{activeIndex:e>0?Q(t,0,e-1):0,focused:we(s.focused,!1),wrap:we(s.wrap,!0),clickToFocus:we(s.clickToFocus,!0),spread:Z(s.spread,25),depthScale:Q(Z(s.depthScale,.22),.05,.45),curve:Z(s.curve,10),parallax:Qt(s.parallax),focusOffsetX:Z(s.focusOffsetX,-15),focusScale:Q(Z(s.focusScale,1.07),.8,1.4),perspective:Z(s.perspective,1100),respectReducedMotion:s.respectReducedMotion??!0,onChange:typeof s.onChange=="function"?s.onChange:void 0}}function st(s){let e=Array.from(s.querySelectorAll("[data-fx-slide]"));return e.length>0?e:Array.from(s.children).filter(t=>t instanceof HTMLElement&&!t.hasAttribute("data-fluxfx-canvas"))}function me(s,e,t,i){let r=s-e;if(i&&t>2){let o=t/2;for(;r>o;)r-=t;for(;r<-o;)r+=t}return r}var ot={name:"depth-carousel",mount(s,e){let t=s.style.position,i=s.style.perspective,r=s.style.transformStyle;typeof window<"u"&&getComputedStyle(s).position==="static"&&(s.style.position="relative");let o=st(s),n=new Map,l=()=>{o=st(s);for(let p of o)n.has(p)||n.set(p,{el:p,transform:p.style.transform,opacity:p.style.opacity,zIndex:p.style.zIndex,filter:p.style.filter,pointerEvents:p.style.pointerEvents,willChange:p.style.willChange})};l();let a=rt(e,o.length);s.style.perspective=`${a.perspective}px`,s.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),d=a.activeIndex,f=a.activeIndex,h=a.focused?1:0,m=a.focused?1:0,v=0,g=0,b=0,x=0,y=!0,T=!1,R=null,E=null,S=null,M=!1,L=(p=!1)=>{(p||u)&&(d=f,h=m,v=b,g=x);let C=o.length;if(C!==0)for(let w=0;w<C;w++){let A=o[w],X=me(w,d,C,a.wrap),V=Math.abs(X),J=X*a.spread,se=Math.max(.45,1-V*a.depthScale),pe=-V*160,at=Q(-X*a.curve,-32,32),Ee=V>2.35?0:Math.max(.18,1-V*.32),ve=V<.5,nt=ve?a.focusOffsetX:J*1.45,lt=ve?a.focusScale:se*.85,ct=ve?1:0,ut=J+(nt-J)*h,dt=se+(lt-se)*h,ft=pe*(1-h*.5),ht=at*(1-h),Se=Ee+(ct-Ee)*h,Le=Math.max(.25,1-V*.25),mt=v*a.parallax*Le,pt=g*(a.parallax*.55)*Le,vt=Math.max(1,20-Math.round(V*4)),Fe=V>1.2&&h<.5?Math.min(2.5,(V-1.2)*1.5):0;u||(A.style.willChange="transform, opacity"),A.style.zIndex=String(vt),A.style.opacity=Se.toFixed(3),A.style.pointerEvents=Se<.08?"none":"auto",A.style.filter=Fe>.1?`blur(${Fe.toFixed(2)}px)`:"",A.style.transform=`translate3d(calc(${ut.toFixed(2)}% + ${mt.toFixed(2)}px), ${pt.toFixed(2)}px, ${ft.toFixed(1)}px) rotateY(${ht.toFixed(2)}deg) scale(${dt.toFixed(4)})`;let ke=w===Math.round(f)?"true":"false";A.getAttribute("data-fx-active")!==ke&&A.setAttribute("data-fx-active",ke)}},U=()=>{let p=Q(Math.round(f),0,Math.max(0,o.length-1)),C=o[p]??null;a.onChange?.({index:p,focused:m>.5,element:C}),s.dispatchEvent(new CustomEvent("fluxfx:change",{bubbles:!0,detail:{index:p,focused:m>.5,element:C}}))},_=(p,C)=>{let w=o.length;if(w===0)return;let A=p;a.wrap?A=(p%w+w)%w:A=Q(p,0,w-1);let X=f,V=m;if(a.wrap&&w>2){let J=me(A,d,w,!0);f=d+J,f=A}else f=A;typeof C=="boolean"&&(m=C?1:0),(f!==X||m!==V)&&U(),y=!0,u?(L(!0),y=!1):T||R?.()},ee=p=>{if(T||u)return;let C=s.getBoundingClientRect();C.width<=0||C.height<=0||(b=Q(((p.clientX-C.left)/C.width-.5)*2,-1,1),x=Q(((p.clientY-C.top)/C.height-.5)*2,-1,1),E!==null&&S===p.pointerId&&Math.abs(p.clientX-E)>22&&(M=!0),y=!0,R?.())},q=()=>{u||(b=0,x=0,y=!0,T||R?.())},$=p=>{T||p.button!==0||(E=p.clientX,S=p.pointerId,M=!1)},K=p=>{if(E===null||S!==p.pointerId)return;let C=p.clientX-E;if(E=null,S=null,Math.abs(C)>48&&m<.5){let w=C<0?1:-1;_(f+w)}},Y=p=>{if(T)return;if(M){M=!1;return}let C=p.target;if(C){if(C.closest("[data-fx-prev]")){_(f-1,!1);return}if(C.closest("[data-fx-next]")){_(f+1,!1);return}for(let w=0;w<o.length;w++)if(o[w]===C||o[w].contains(C)){w!==Math.round(f)?_(w,!1):a.clickToFocus&&_(w,m<.5);return}}},j=p=>{u=a.respectReducedMotion&&p.matches,u&&(L(!0),y=!1),R?.()};return c&&typeof c.addEventListener=="function"&&c.addEventListener("change",j),s.addEventListener("pointermove",ee,{passive:!0}),s.addEventListener("pointerleave",q,{passive:!0}),s.addEventListener("pointerdown",$,{passive:!0}),window.addEventListener("pointerup",K,{passive:!0}),s.addEventListener("click",Y),L(!0),y=!1,{update(p,C){if(!y||T||u)return;let w=Math.min(C,.05),A=1-Math.exp(-10.5*w),X=1-Math.exp(-8*w),V=me(f,d,o.length,a.wrap);d+=V*A,a.wrap&&o.length>0&&(d=(d%o.length+o.length)%o.length),h+=(m-h)*A,v+=(b-v)*X,g+=(x-g)*X,L(!1);let J=Math.abs(me(f,d,o.length,a.wrap))<.002,se=Math.abs(m-h)<.003,pe=Math.abs(b-v)<.003&&Math.abs(x-g)<.003;J&&se&&pe&&(L(!0),y=!1)},setOptions(p){l();let C=a;a=rt(p,o.length),a.perspective!==C.perspective&&(s.style.perspective=`${a.perspective}px`);let w=p.focused!==void 0?a.focused:m>.5,A=p.activeIndex!==void 0?a.activeIndex:f,X=Math.round(A)!==Math.round(f)||w!==m>.5;f=A,m=w?1:0,X&&U(),y=!0,u?(L(!0),y=!1):T||R?.()},isIdle(){return!y||T||u},onWake(p){R=p},pause(){T=!0},resume(){T=!1,y&&!u&&R?.()},destroy(){R=null,y=!1,c&&typeof c.removeEventListener=="function"&&c.removeEventListener("change",j),s.removeEventListener("pointermove",ee),s.removeEventListener("pointerleave",q),s.removeEventListener("pointerdown",$),window.removeEventListener("pointerup",K),s.removeEventListener("click",Y),n.forEach(p=>{p.el.style.transform=p.transform,p.el.style.opacity=p.opacity,p.el.style.zIndex=p.zIndex,p.el.style.filter=p.filter,p.el.style.pointerEvents=p.pointerEvents,p.el.style.willChange=p.willChange,p.el.removeAttribute("data-fx-active")}),n.clear(),s.style.position=t,s.style.perspective=i,s.style.transformStyle=r}}}};he.register(Ne).register(Qe).register(qe).register($e).register(Ke).register(Ye).register(Ze).register(et).register(tt).register(it).register(ot);var Re=he;typeof window<"u"&&(window.FluxFX=he);function H(s,e={},t=!1){let i=(0,P.useRef)(null),r=Array.isArray(s)?s.join(" "):s,o=JSON.stringify(e),n=(0,P.useRef)(o);n.current=o;let l=(0,P.useRef)(!1),a=(0,P.useRef)(null);return(0,P.useEffect)(()=>{if(t||typeof window>"u")return;let c=i.current;if(!c||!r.trim())return;let u=n.current,d=JSON.parse(u),h=r.trim().split(/\s+/).map(m=>Re.apply(c,m,d));return l.current=!0,a.current=u,()=>{l.current=!1,a.current=null,h.forEach(m=>m())}},[r,t]),(0,P.useEffect)(()=>{if(!l.current||t||typeof window>"u"||a.current===o)return;let c=i.current;if(!c||!r.trim())return;let u=JSON.parse(o);r.trim().split(/\s+/).forEach(f=>{Re.update(c,f,u)}),a.current=o},[o,r,t]),i}function z(s){let{device:e,minWidth:t,maxWidth:i,disableOnMobile:r,disableOnDesktop:o,mobileBreakpoint:n,...l}=s;return{deviceOpts:{device:e,minWidth:t,maxWidth:i,disableOnMobile:r,disableOnDesktop:o,mobileBreakpoint:n},domRest:l}}function qt({as:s="section",speed:e=1,quality:t="medium",colors:i=["#4f46e5","#06b6d4","#ec4899"],bgColor:r,theme:o,lightColors:n,darkColors:l,scrollColors:a,trackScroll:c,layer:u,preserveBg:d,adaptToSurface:f,overlayOpacity:h,interactive:m=!0,respectReducedMotion:v=!0,disabled:g=!1,children:b,...x}){let{deviceOpts:y,domRest:T}=z(x),R=H("aurora",{speed:e,quality:t,colors:i,bgColor:r,theme:o,lightColors:n,darkColors:l,scrollColors:a,trackScroll:c,layer:u,preserveBg:d,adaptToSurface:f,overlayOpacity:h,interactive:m,respectReducedMotion:v,...y},g);return P.default.createElement(s,{ref:R,...T},b)}function $t({as:s="section",speed:e=1,quality:t="medium",colors:i=["#0f172a","#94a3b8","#38bdf8"],bgColor:r,theme:o,lightColors:n,darkColors:l,scrollColors:a,trackScroll:c,layer:u,preserveBg:d,adaptToSurface:f,overlayOpacity:h,interactive:m=!0,respectReducedMotion:v=!0,disabled:g=!1,children:b,...x}){let{deviceOpts:y,domRest:T}=z(x),R=H("liquid-metal",{speed:e,quality:t,colors:i,bgColor:r,theme:o,lightColors:n,darkColors:l,scrollColors:a,trackScroll:c,layer:u,preserveBg:d,adaptToSurface:f,overlayOpacity:h,interactive:m,respectReducedMotion:v,...y},g);return P.default.createElement(s,{ref:R,...T},b)}function Kt({as:s="section",speed:e=1,quality:t="medium",colors:i=["#6366f1","#06b6d4","#f43f5e"],bgColor:r,theme:o,lightColors:n,darkColors:l,scrollColors:a,trackScroll:c,layer:u,preserveBg:d,adaptToSurface:f,overlayOpacity:h,dissipation:m=.975,radius:v=.0045,swirl:g=1.4,interactive:b=!0,respectReducedMotion:x=!0,disabled:y=!1,children:T,...R}){let{deviceOpts:E,domRest:S}=z(R),M=H("fluid",{speed:e,quality:t,colors:i,bgColor:r,theme:o,lightColors:n,darkColors:l,scrollColors:a,trackScroll:c,layer:u,preserveBg:d,adaptToSurface:f,overlayOpacity:h,dissipation:m,radius:v,swirl:g,interactive:b,respectReducedMotion:x,...E},y);return P.default.createElement(s,{ref:M,...S},T)}function Yt({as:s="div",maxTilt:e=12,scale:t=1.03,perspective:i=900,glare:r=!0,respectReducedMotion:o=!0,disabled:n=!1,children:l,...a}){let{deviceOpts:c,domRest:u}=z(a),d=H("tilt-3d",{maxTilt:e,scale:t,perspective:i,glare:r,respectReducedMotion:o,...c},n);return P.default.createElement(s,{ref:d,...u},l)}function jt({as:s="div",strength:e=.35,respectReducedMotion:t=!0,disabled:i=!1,style:r,children:o,...n}){let{deviceOpts:l,domRest:a}=z(n),c=H("magnetic",{strength:e,respectReducedMotion:t,...l},i);return P.default.createElement(s,{ref:c,style:{display:"inline-block",...r},...a},o)}function Jt({as:s="section",speed:e=1,quality:t="medium",colors:i=["#1e1b4b","#0284c7","#e11d48"],bgColor:r,theme:o,lightColors:n,darkColors:l,scrollColors:a,trackScroll:c,layer:u,preserveBg:d,adaptToSurface:f,overlayOpacity:h,dissipation:m=.982,radius:v=.004,curl:g=1.75,interactive:b=!0,respectReducedMotion:x=!0,disabled:y=!1,children:T,...R}){let{deviceOpts:E,domRest:S}=z(R),M=H("ink",{speed:e,quality:t,colors:i,bgColor:r,theme:o,lightColors:n,darkColors:l,scrollColors:a,trackScroll:c,layer:u,preserveBg:d,adaptToSurface:f,overlayOpacity:h,dissipation:m,radius:v,curl:g,interactive:b,respectReducedMotion:x,...E},y);return P.default.createElement(s,{ref:M,...S},T)}function Zt({as:s="section",speed:e=1,quality:t="medium",colors:i=["#1e3a5f","#2d3748","#0284c7"],bgColor:r,theme:o,lightColors:n,darkColors:l,scrollColors:a,trackScroll:c,layer:u,preserveBg:d,adaptToSurface:f,overlayOpacity:h,lightMode:m,absorptionGain:v=1.45,dissipation:g=.978,radius:b=.0032,curl:x=1.85,interactive:y=!0,respectReducedMotion:T=!0,disabled:R=!1,children:E,...S}){let{deviceOpts:M,domRest:L}=z(S),U=H("aetheria",{speed:e,quality:t,colors:i,bgColor:r,theme:o,lightColors:n,darkColors:l,scrollColors:a,trackScroll:c,layer:u,preserveBg:d,adaptToSurface:f,overlayOpacity:h,lightMode:m,absorptionGain:v,dissipation:g,radius:b,curl:x,interactive:y,respectReducedMotion:T,...M},R);return P.default.createElement(s,{ref:U,...L},E)}function ei({as:s="section",speed:e=1,quality:t="medium",colors:i=["#6366f1","#06b6d4","#f472b6"],bgColor:r,theme:o,lightColors:n,darkColors:l,scrollColors:a,trackScroll:c,layer:u,preserveBg:d,adaptToSurface:f,overlayOpacity:h,shape:m="prism",depth:v=1,gloss:g=1,distortion:b=.35,interactive:x=!0,respectReducedMotion:y=!0,disabled:T=!1,children:R,...E}){let{deviceOpts:S,domRest:M}=z(E),L=H("prism-3d",{speed:e,quality:t,colors:i,bgColor:r,theme:o,lightColors:n,darkColors:l,scrollColors:a,trackScroll:c,layer:u,preserveBg:d,adaptToSurface:f,overlayOpacity:h,shape:m,depth:v,gloss:g,distortion:b,interactive:x,respectReducedMotion:y,...S},T);return P.default.createElement(s,{ref:L,...M},R)}function ti({as:s="section",baseImage:e,revealImage:t,speed:i=1,quality:r="medium",colors:o=["#ff6b2b","#ffd166","#ffffff"],bgColor:n="transparent",theme:l,lightColors:a,darkColors:c,scrollColors:u,trackScroll:d,layer:f,preserveBg:h,adaptToSurface:m,overlayOpacity:v,radius:g=.13,softness:b=.22,edgeNoise:x=.38,edgeGlow:y=.24,dissipation:T=.985,fit:R="cover",position:E="center",ambient:S=!1,clickReveal:M=!0,interactive:L=!0,respectReducedMotion:U=!0,disabled:_=!1,children:ee,...q}){let{deviceOpts:$,domRest:K}=z(q),Y=H("brush-reveal",{baseImage:e,revealImage:t,speed:i,quality:r,colors:o,bgColor:n,theme:l,lightColors:a,darkColors:c,scrollColors:u,trackScroll:d,layer:f,preserveBg:h,adaptToSurface:m,overlayOpacity:v,radius:g,softness:b,edgeNoise:x,edgeGlow:y,dissipation:T,fit:R,position:E,ambient:S,clickReveal:M,interactive:L,respectReducedMotion:U,...$},_);return P.default.createElement(s,{ref:Y,...K},ee)}function ii({as:s="section",speed:e=1,quality:t="medium",colors:i=["#14161a","#4b5563","#f8fafc"],bgColor:r,theme:o,lightColors:n,darkColors:l,scrollColors:a,trackScroll:c,layer:u,preserveBg:d,adaptToSurface:f,overlayOpacity:h,spotRadius:m=.62,spotIntensity:v=1,spotPosition:g="center",interactive:b=!0,respectReducedMotion:x=!0,disabled:y=!1,children:T,...R}){let{deviceOpts:E,domRest:S}=z(R),M=H("spotlight",{speed:e,quality:t,colors:i,bgColor:r,theme:o,lightColors:n,darkColors:l,scrollColors:a,trackScroll:c,layer:u,preserveBg:d,adaptToSurface:f,overlayOpacity:h,spotRadius:m,spotIntensity:v,spotPosition:g,interactive:b,respectReducedMotion:x,...E},y);return P.default.createElement(s,{ref:M,...S},T)}function ri({as:s="div",activeIndex:e=0,focused:t=!1,wrap:i=!0,clickToFocus:r=!0,spread:o=25,depthScale:n=.22,curve:l=10,parallax:a=18,focusOffsetX:c=-15,focusScale:u=1.07,perspective:d=1100,respectReducedMotion:f=!0,disabled:h=!1,onSlideChange:m,children:v,...g}){let{deviceOpts:b,domRest:x}=z(g),y=(0,P.useRef)(m);y.current=m;let T=H("depth-carousel",{activeIndex:e,focused:t,wrap:i,clickToFocus:r,spread:o,depthScale:n,curve:l,parallax:a,focusOffsetX:c,focusScale:u,perspective:d,respectReducedMotion:f,...b},h);return(0,P.useEffect)(()=>{let R=T.current;if(!R)return;let E=S=>{let M=S;y.current?.(M.detail)};return R.addEventListener("fluxfx:change",E),()=>R.removeEventListener("fluxfx:change",E)},[T]),P.default.createElement(s,{ref:T,...x},v)}0&&(module.exports={Aetheria,Aurora,BrushReveal,DepthCarousel,Fluid,Ink,LiquidMetal,Magnetic,Prism3D,Spotlight,TiltCard,useFX});
|