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