@occluze/umber 0.2.1 → 0.3.0
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/LICENSE.md +21 -0
- package/README.md +78 -48
- package/dist/chunks/badge.js +2 -0
- package/dist/chunks/basis.js +2 -0
- package/dist/chunks/basis_transcoder.js +2 -0
- package/dist/chunks/basis_transcoder.wasm +0 -0
- package/dist/chunks/capture.js +2 -2
- package/dist/chunks/covers.js +2 -2
- package/dist/chunks/curves.js +2 -0
- package/dist/chunks/flip.js +2 -2
- package/dist/chunks/fx.js +2 -102
- package/dist/chunks/gl.js +2 -180
- package/dist/chunks/glsl.js +2 -239
- package/dist/chunks/inspect.js +2 -6
- package/dist/chunks/instances.js +2 -93
- package/dist/chunks/layers.js +2 -21
- package/dist/chunks/licence.js +2 -2
- package/dist/chunks/morph.js +2 -2
- package/dist/chunks/patch.js +2 -0
- package/dist/chunks/prepared.js +2 -0
- package/dist/chunks/profiler.js +2 -0
- package/dist/chunks/restore.js +2 -2
- package/dist/chunks/shapes.js +2 -2
- package/dist/chunks/sim.js +2 -22
- package/dist/chunks/text.js +2 -52
- package/dist/chunks/video.js +2 -2
- package/dist/chunks/views.js +2 -2
- package/dist/chunks/vocabulary.js +2 -0
- package/dist/chunks/warm.js +2 -2
- package/dist/frameworks/astro.mjs +2 -0
- package/dist/frameworks/react.mjs +2 -0
- package/dist/frameworks/svelte.mjs +2 -0
- package/dist/frameworks/vue.mjs +2 -0
- package/dist/modules/debug.js +2 -36
- package/dist/modules/debug.mjs +2 -36
- package/dist/modules/handoff.js +2 -2
- package/dist/modules/handoff.mjs +2 -2
- package/dist/modules/input.js +2 -2
- package/dist/modules/input.mjs +2 -2
- package/dist/modules/router-swap.js +2 -13
- package/dist/modules/router.js +2 -2
- package/dist/modules/router.mjs +2 -2
- package/dist/modules/scroll-more.js +2 -0
- package/dist/modules/scroll-touch.js +2 -0
- package/dist/modules/scroll.js +2 -2
- package/dist/modules/scroll.mjs +2 -2
- package/dist/modules/scrollfx.js +2 -0
- package/dist/modules/scrollfx.mjs +2 -0
- package/dist/modules/scrub.js +2 -8
- package/dist/modules/scrub.mjs +2 -8
- package/dist/modules/three.js +2 -0
- package/dist/modules/three.mjs +2 -0
- package/dist/node/assets.mjs +9 -0
- package/dist/node/astro.mjs +47 -0
- package/dist/node/cli.mjs +109 -0
- package/dist/node/shared-3Q24RNIF.mjs +602 -0
- package/dist/node/shared-4FIU6DYP.mjs +200 -0
- package/dist/node/vite.mjs +10 -0
- package/dist/umber.css +2 -2
- package/dist/umber.js +2 -2
- package/dist/umber.mjs +2 -2
- package/docs/AI-quick.md +116 -54
- package/docs/AI.md +1275 -805
- package/docs/npm.md +37 -26
- package/package.json +181 -12
- package/types/assets.d.ts +87 -0
- package/types/astro.d.ts +43 -0
- package/types/debug.d.ts +17 -16
- package/types/esm.d.ts +12 -12
- package/types/global.d.ts +17 -0
- package/types/handoff.d.ts +26 -25
- package/types/input.d.ts +63 -55
- package/types/loop.d.ts +75 -0
- package/types/module.d.ts +108 -0
- package/types/react.d.ts +15 -0
- package/types/router.d.ts +87 -45
- package/types/scroll.d.ts +96 -38
- package/types/scrollfx.d.ts +80 -0
- package/types/scrub.d.ts +33 -32
- package/types/svelte.d.ts +16 -0
- package/types/three.d.ts +226 -0
- package/types/umber.d.ts +633 -357
- package/types/vite.d.ts +33 -0
- package/types/vue.d.ts +14 -0
package/dist/chunks/fx.js
CHANGED
|
@@ -1,102 +1,2 @@
|
|
|
1
|
-
/*! Umber v0.
|
|
2
|
-
var ce={info(){},warn:(o,...e)=>console.warn("[umber]",o,...e),once:(o,...e)=>console.warn("[umber]",o,...e),error:(o,...e)=>console.error("[umber]",o,...e)},p=ce;function V(o){o&&(p=o)}var he,pe,me,de,ge,ve,be,xe,B,k,Ee;function q(o){o&&({attr:he,config:pe,describe:me,findGL:de,findMedia:ge,markMedia:ve,unmarkMedia:be,needsLive:xe,say:B,tell:k,createEmitter:Ee}=o)}var D=["float","half","u8"];function ye(o,e){if(e==="u8")return{type:e,internal:o.RGBA8,pixel:o.UNSIGNED_BYTE,filter:o.LINEAR};if(!o.getExtension("EXT_color_buffer_float")&&(e==="float"||!o.getExtension("EXT_color_buffer_half_float")))return null;let r=e==="float",s={type:e,internal:r?o.RGBA32F:o.RGBA16F,pixel:r?o.FLOAT:o.HALF_FLOAT,filter:!r||o.getExtension("OES_texture_float_linear")?o.LINEAR:o.NEAREST},i=new y(o,{width:4,height:4,type:e,msaa:0,attachments:1},s,0),n=i.complete;return i.dispose(),n?s:null}function j(o,e,t,r=!1){for(let s=D.indexOf(e);s<D.length;s++){let i=D[s];t.has(i)||t.set(i,ye(o,i));let n=t.get(i);if(n)return i!==e&&!r&&p.once(`render targets: "${e}" can't be rendered to on this GPU; they use "${i}" instead (values above 1 clip and soft gradients may band). Ask for type: "${i}" to skip this message.`),n}return t.get("u8")}var y=class{constructor(e,t,r,s){this.gl=e;this.spec=t;this.format=r;this.samples=s;this.textures=[];this.msaa=null;this.db=[];this.freed=0;let{width:i,height:n,attachments:a}=t;this.key=O(t,r.type,s);let u=[];for(let l=0;l<a;l++)u.push(e.COLOR_ATTACHMENT0+l);let f=e.getParameter(e.FRAMEBUFFER_BINDING);this.fb=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this.fb);for(let l=0;l<a;l++){let c=e.createTexture();e.bindTexture(e.TEXTURE_2D,c),e.texStorage2D(e.TEXTURE_2D,1,r.internal,i,n),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,r.filter),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,r.filter),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.framebufferTexture2D(e.FRAMEBUFFER,u[l],e.TEXTURE_2D,c,0),this.textures.push(c)}if(a>1&&e.drawBuffers(u),this.complete=e.checkFramebufferStatus(e.FRAMEBUFFER)===e.FRAMEBUFFER_COMPLETE,s){this.msaa=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this.msaa);for(let l=0;l<a;l++){let c=e.createRenderbuffer();e.bindRenderbuffer(e.RENDERBUFFER,c),e.renderbufferStorageMultisample(e.RENDERBUFFER,s,r.internal,i,n),e.framebufferRenderbuffer(e.FRAMEBUFFER,u[l],e.RENDERBUFFER,c),this.db.push(c)}a>1&&e.drawBuffers(u),this.complete&&=e.checkFramebufferStatus(e.FRAMEBUFFER)===e.FRAMEBUFFER_COMPLETE,e.bindRenderbuffer(e.RENDERBUFFER,null)}e.bindFramebuffer(e.FRAMEBUFFER,f)}get draw(){return this.msaa||this.fb}get bytes(){let{width:e,height:t,attachments:r}=this.spec,s=this.format.type==="float"?16:this.format.type==="half"?8:4;return e*t*s*r*(1+this.samples)}resolve(){let e=this.gl;if(!this.msaa)return;let{width:t,height:r,attachments:s}=this.spec;e.bindFramebuffer(e.READ_FRAMEBUFFER,this.msaa),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,this.fb);let i=[];for(let n=0;n<s;n++){for(let a=0;a<s;a++)i[a]=a===n?e.COLOR_ATTACHMENT0+n:e.NONE;e.readBuffer(e.COLOR_ATTACHMENT0+n),s>1&&e.drawBuffers(i),e.blitFramebuffer(0,0,t,r,0,0,t,r,e.COLOR_BUFFER_BIT,e.NEAREST),i[n]=e.COLOR_ATTACHMENT0+n}if(s>1){for(let n=0;n<s;n++)i[n]=e.COLOR_ATTACHMENT0+n;e.drawBuffers(i)}e.invalidateFramebuffer(e.READ_FRAMEBUFFER,i.length?i:[e.COLOR_ATTACHMENT0]),e.bindFramebuffer(e.READ_FRAMEBUFFER,null),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,null)}dispose(){let e=this.gl;for(let t of this.textures)e.deleteTexture(t);for(let t of this.db)e.deleteRenderbuffer(t);e.deleteFramebuffer(this.fb),this.msaa&&e.deleteFramebuffer(this.msaa),this.textures.length=0,this.db.length=0}},O=(o,e,t)=>`${o.width}x${o.height}|${e}|${t}|${o.attachments}`;var N=5e3,F=class{constructor(e){this.gl=e;this.free=new Map;this.live=new Set;this.formats=new Map;this._a=new Set;this.dead=!1;this.timer=0;this.grew=null;this.peak=0;this.Ma=()=>{this.timer=0;let e=performance.now(),t=!1;for(let[r,s]of this.free){for(let i=s.length-1;i>=0;i--)e-s[i].freed>=N-1?s.splice(i,1)[0].dispose():t=!0;s.length||this.free.delete(r)}this.fell(),t&&(this.timer=setTimeout(this.Ma,N))}}acquire(e){let t=this.gl,r=j(t,e.type,this.formats,e.quiet),s=e.msaa>0&&!this._a.has(r.type)?Math.min(e.msaa,t.getParameter(t.MAX_SAMPLES)||0):0,i=O(e,r.type,s),n=this.free.get(i)?.pop(),a=!n;return n||(n=new y(t,e,r,s),!n.complete&&s&&(n.dispose(),this._a.add(r.type),p.once(`render targets: this GPU refuses ${s}x MSAA for "${r.type}" targets; they draw without it (edges stair-step). Ask for msaa: 0 to skip this message.`),n=new y(t,e,r,0))),this.live.add(n),a&&this.grew?.(),n}release(e){if(!e||!this.live.delete(e)||this.dead)return;e.freed=performance.now();let t=this.free.get(e.key);t?t.push(e):this.free.set(e.key,[e]),this.timer||=setTimeout(this.Ma,N)}get bytes(){let e=0;for(let t of this.live)e+=t.bytes;for(let t of this.free.values())for(let r of t)e+=r.bytes;return e}trim(){let e=0;for(let t of this.free.values())for(let r of t)e+=r.bytes,r.dispose();return this.free.clear(),this.fell(),e}fell(){this.peak=Math.min(this.peak,this.bytes)}lost(){this.dead=!0,this.free.clear(),this.fell(),this.formats.clear(),this._a.clear()}restored(){this.dead=!1;let e=new Map,t=[...this.live];this.live.clear();for(let r of t)e.set(r,this.acquire(r.spec));return e}dispose(){this.timer&&clearTimeout(this.timer),this.timer=0;for(let e of this.live)e.dispose();for(let e of this.free.values())for(let t of e)t.dispose();this.live.clear(),this.free.clear()}};var Y="uniformMatrix2fv,uniformMatrix3fv,uniformMatrix4fv,,,,,,,,,uniformMatrix2x3fv,uniformMatrix2x4fv,uniformMatrix3x2fv,uniformMatrix3x4fv,uniformMatrix4x2fv,uniformMatrix4x3fv".split(","),S=class{constructor(e,t,r,s="program"){this.gl=e;this.vertex=t;this.fragment=r;this.label=s;this.uniforms=new Map;this.samplers=[];this.state="pending";this.error=null;this.shaders=[];this.Ka=globalThis.occluzeCapture?.version==1?null:e.getExtension("KHR_parallel_shader_compile");let i=K(e,e.VERTEX_SHADER,t),n=K(e,e.FRAGMENT_SHADER,r),a=e.createProgram();e.attachShader(a,i),e.attachShader(a,n),e.bindAttribLocation(a,0,"aPosition"),e.linkProgram(a),this.program=a,this.shaders=[i,n],this.Ka||this.finalize()}ready(){return this.state!=="pending"?this.state==="ok":this.Ka&&!this.gl.getProgramParameter(this.program,this.Ka.COMPLETION_STATUS_KHR)?!1:(this.finalize(),this.state==="ok")}get failed(){return this.state==="failed"}finalize(){let e=this.gl,t=this.program;if(!e.getProgramParameter(t,e.LINK_STATUS)){let[s,i]=this.shaders;this.error=Q(e,s,"vertex",this.vertex,this.label)||Q(e,i,"fragment",this.fragment,this.label)||["link",this.label,e.getProgramInfoLog(t)||"",""],this.Pa(),e.deleteProgram(t),this.state="failed";return}this.Pa();let r=e.getProgramParameter(t,e.ACTIVE_UNIFORMS);for(let s=0;s<r;s++){let i=e.getActiveUniform(t,s);if(!i)continue;let n=i.name.replace(/\[0\]$/,""),a=e.getUniformLocation(t,i.name);a&&(this.uniforms.set(n,{loc:a,type:i.type,size:i.size}),(i.type===e.SAMPLER_2D||i.type===e.UNSIGNED_INT_SAMPLER_2D)&&this.samplers.push(n))}this.state="ok"}Pa(){for(let e of this.shaders)this.gl.deleteShader(e);this.shaders=[]}set(e,t){let r=this.state==="ok"?this.uniforms.get(e):void 0;if(!r||t==null)return;let s=this.gl,i=r.type;if(typeof t=="number"){if(r.last===t)return;r.last=t,i===s.FLOAT?s.uniform1f(r.loc,t):i===s.UNSIGNED_INT?s.uniform1ui(r.loc,t):s.uniform1i(r.loc,t);return}let n=t,a=r.last;if(a?.length===n.length){let u=n.length;for(;u--&&a[u]===n[u];);if(u<0)return}else a=r.last=[];for(let u=0;u<n.length;u++)a[u]=n[u];i===s.FLOAT_VEC2?s.uniform2fv(r.loc,n):i===s.FLOAT_VEC3?s.uniform3fv(r.loc,n,0,Math.min(n.length,r.size*3)):i===s.FLOAT_VEC4?s.uniform4fv(r.loc,n):Y[i-s.FLOAT_MAT2]?s[Y[i-s.FLOAT_MAT2]](r.loc,!1,n):i===s.FLOAT?s.uniform1fv(r.loc,n):s[`uniform${n.length/r.size}${i===s.UNSIGNED_INT||i>=s.UNSIGNED_INT_VEC2?"u":""}iv`]?.(r.loc,n)}dispose(){this.Pa(),this.state!=="failed"&&this.gl.deleteProgram(this.program)}};function K(o,e,t){let r=o.createShader(e);return o.shaderSource(r,t),o.compileShader(r),r}function Q(o,e,t,r,s){return e&&!o.getShaderParameter(e,o.COMPILE_STATUS)?[t,s,o.getShaderInfoLog(e)||"",r]:null}var R={};function J(o){let e=new Set,t=r=>{let s=R[r];if(!(e.has(r)||s.defined.test(o))){for(let i of s.needs||[])t(i);e.add(r)}};for(let r in R)R[r].used.test(o)&&t(r);return[...e].map(r=>R[r].code).join(`
|
|
3
|
-
|
|
4
|
-
`)}var Re=new Set(["uViewport","uSurface","uRect","uSize","uTime","uScrollVelocity","uMouse","uProgress","uAlpha","uRadius","uRadiusKy","uDpr","uImage","uImageSize","uFit","uFitPosition","uGlyphIndex","uGlyphData","uPlaneMatrix","uCanvas","uBleed","uUmberClips","uUmberClipXf","uUmberClipBox","uUmberClipRadius","uUmberClipPoly","uUmberClipPolyInfo"]);function Te(o){if(typeof o=="number"||typeof o=="boolean")return"float";if(Array.isArray(o)||ArrayBuffer.isView(o)){let e=o.length;return e===2?"vec2":e===3?"vec3":e===4?"vec4":e===9?"mat3":e===16?"mat4":null}return typeof o=="string"?"sampler2D":o&&typeof o=="object"?"highp sampler2D":null}function G(o,e){let t=s=>s.charAt(0).toUpperCase()+s.slice(1),r=s=>s.split(/[-_\s]+/).map(t).join("");return`u${r(o)}${r(e)}`}function Z(o,e){let t=[];for(let r in o){if(Re.has(r)||new RegExp(`uniform\\s+\\w+\\s+${r}\\b`).test(e))continue;let s=Te(o[r]);s&&t.push(`uniform ${s} ${r};`)}return t.join(`
|
|
5
|
-
`)}var T=null,ee=(o,e)=>o.replace(/var\(\s*(--[\w-]+)\s*(?:,((?:[^()]|\([^()]*\))*))?\)/g,(t,r,s="")=>getComputedStyle(e).getPropertyValue(r).trim()||ee(s,e));function M(o,e){let t=ee(o,e).trim().replace(/currentcolor/gi,getComputedStyle(e).color);return typeof CSS>"u"||t.includes("var(")||!CSS.supports("color",t)?o.includes("var(")?(B("var",[o],e),new Float32Array(4)):null:(T||=document.createElement("canvas").getContext("2d",{willReadFrequently:!0}),T?(T.clearRect(0,0,1,1),T.fillStyle=t,T.fillRect(0,0,1,1),Float32Array.from(T.getImageData(0,0,1,1).data,r=>r/255)):null)}var we=`#version 300 es
|
|
6
|
-
out vec2 vUv;
|
|
7
|
-
void main(){
|
|
8
|
-
vUv=vec2(gl_VertexID&1,gl_VertexID>>1)*2.0;
|
|
9
|
-
gl_Position=vec4(vUv*2.0-1.0,0.0,1.0);
|
|
10
|
-
}
|
|
11
|
-
`,_e=`#version 300 es
|
|
12
|
-
precision highp float;
|
|
13
|
-
in vec2 vUv;
|
|
14
|
-
layout(location=0)out vec4 outColor;
|
|
15
|
-
uniform vec2 uSize;
|
|
16
|
-
uniform float uTime;
|
|
17
|
-
`,Ae=`void main(){
|
|
18
|
-
vec4 c=color(vUv);
|
|
19
|
-
outColor=vec4(c.rgb*c.a,c.a);
|
|
20
|
-
}
|
|
21
|
-
`,_=o=>o&&typeof o=="object"&&"value"in o&&!("texture"in o)?o.value:o;function P(o){for(let e in o){let t=_(o[e]);t&&typeof t=="object"&&"texture"in t&&(t.byPass=!0)}}var Fe=64,Se=[0,0,0,0];function Me(o,e){let t={};for(let s in e){let i=_(e[s]);t[s]=typeof i=="string"?Se:i}let r=/\bvoid\s+main\s*\(/.test(o);return _e+Z(t,o)+`
|
|
22
|
-
`+o+(r?"":Ae)}var L=class{constructor(e){this.gl=e;this.cache=new Map;this.size=new Float32Array(2);this.colors=new Map}program(e,t){let r=Me(e,t);if(this.cache.has(r))return this.cache.get(r);let s=new S(this.gl,we,r,"target pass");return s.state==="pending"&&!s.ready()&&s.finalize(),s.failed&&(k("glsl",s.error,p.error),s=null),this.cache.set(r,s),s}draw(e,t,r,s,i,n=!1){let a=this.gl;a.viewport(0,0,t,r),a.disable(a.SCISSOR_TEST),n?(a.enable(a.BLEND),a.blendFunc(a.ONE,a.ONE_MINUS_SRC_ALPHA)):a.disable(a.BLEND),a.useProgram(e.program),this.size[0]=t,this.size[1]=r,e.set("uSize",this.size),e.set("uTime",i);let u=0;for(let f in s){let l=_(s[f]);l&&typeof l=="object"&&"texture"in l?(a.activeTexture(a.TEXTURE0+u),a.bindTexture(a.TEXTURE_2D,l.texture),e.set(f,u++)):e.set(f,typeof l=="boolean"?Number(l):typeof l=="string"?this.color(l):l)}a.activeTexture(a.TEXTURE0),a.bindVertexArray(null),a.drawArrays(a.TRIANGLES,0,3)}color(e){let t=this.colors.get(e);return t===void 0&&(this.colors.size>=Fe&&this.colors.clear(),this.colors.set(e,t=M(e,document.documentElement))),t}lost(){this.cache.clear()}dispose(){for(let e of this.cache.values())e?.dispose();this.cache.clear()}};var Le=32,U=class{constructor(e){this.fx=e;this.of=new WeakMap;this.known=new WeakSet;this.held=new Map;this.list=[];this.yb=[];this.current=null;this.frame=0;this.depth=e=>{let t=0;for(let r=this.groupOf(e);r;r=this.groupOf(r))t++;return t};this.inner=(e,t)=>this.depth(t)-this.depth(e);this.members=()=>{let e=this.fx.stage,t=this.current;for(let r of this.yb)if(!(r.group!==t||r.morphHidden||r.vt||r.hush)){if(r._mods.frames)r._mods.frames.pick(r);else if(r.kind==="video"){if(!e.video?.upload(r))continue;e.renderer.reset()}if(!(r.kind!=="shader"&&r.kind!=="group"&&!(r.texture?.ready||r.prev?.ready)||!r.program||!r.grid)&&!(r.kind==="group"&&!r.texture)){if(!r.program.ready()){r.program.failed?e.programs.failed(r,e.planes):e.forced=Math.max(e.forced,2);continue}e.renderer.drawPlane(r,!0),r.lastRect.set(r.rect),r.lastXf.set(r.drawXf),r.lastOpacity=r.opacity,r.readyFrame===-1&&r.status==="loading"&&(r.readyFrame=this.frame)}}};this.Ma=(e,t)=>{e.seen===this.frame&&!t.destroyed||(this.fx.pool.release(e.b),e.b=null,e.chain?.release(),t.destroyed&&this.held.delete(t))}}groupOf(e){let t=this.of.get(e);if(t===void 0||t?.destroyed){let r=e.el.parentElement?.closest('[data-gl="group"]');t=r&&this.fx.stage.plane(r)||null,this.of.set(e,t)}return t}moved(){this.of=new WeakMap}draw(e,t){let r=this.list;r.length=0;for(let i of e)i.group=null,i.kind==="group"&&(r.push(i),this.known.has(i)||(this.known.add(i),this.of=new WeakMap));this.frame=t,this.yb=e;let s=!1;return r.length&&(s=this._b(e)),this.held.size&&this.held.forEach(this.Ma),s}_b(e){let t=this.list;t.length>1&&t.sort(this.inner);for(let s of e){let i=this.groupOf(s);if(!(!i||!t.includes(i))){if(s.kind==="layer"||s.backdrop){p.once('data-gl="group": three.js layers and planes that read uBackdrop draw on the canvas, not in their group.');continue}s.group=i}}let r=!1;for(let s of t){if(!s.program?.ready()||!s.grid){if(s.program?.failed){for(let i of e)i.group===s&&(i.group=null);this.fx.stage.programs.failed(s,this.fx.stage.planes)}else this.fx.stage.forced=Math.max(this.fx.stage.forced,2);continue}this.render(s),r=!0}return r}render(e){let t=this.fx.stage,r=t.viewport.width,s=t.viewport.height,i=t.canvas.width/r,n=e.rect,a=Le+e.bleed,u=Math.min(n[2],r+2*a),f=Math.min(n[3],s+2*a),l=Math.min(Math.max(-a-n[0],0),n[2]-u),c=Math.min(Math.max(-a-n[1],0),n[3]-f),h=this.held.get(e);if(!h){let E={texture:null,ready:!0,width:0,height:0,refs:0,bytes:0,dispose(){}};this.held.set(e,h={b:null,tex:E,chain:null,key:"",x:l,y:c,seen:0,trail:{until:0,mine:-1}})}h.seen=this.frame;let m=Math.max(1,Math.round(u*i)),g=Math.max(1,Math.round(f*i));(!h.b||h.b.spec.width!==m||h.b.spec.height!==g)&&(this.fx.pool.release(h.b),h.b=this.fx.pool.acquire({width:m,height:g,type:"u8",msaa:0,attachments:1})),this.current=e,this.fx.into(h.b,n[0]+l,n[1]+c,u,f,this.members,!1);let b=h.b,x=h.chain=this.fx.chainFor(e.el,h.chain,!1);if(x?.ok){let E=x.values;E.uScrollShift[0]=(l-h.x)/u,E.uScrollShift[1]=(c-h.y)/f,this.fx.setValues(E,n[0]+l,n[1]+c,u,f),b=x.run(h.b,!1,m,g)||h.b,this.fx.stage.gl.bindFramebuffer(this.fx.stage.gl.FRAMEBUFFER,null),t.renderer.reset(),x.feedback&&this.fx.awake(h.trail)}h.x=l,h.y=c;let v=h.tex;v.texture=b.textures[0],v.width=u,v.height=f,e.texture=v,e.fit=3,e.fitPosition[0]=l,e.fitPosition[1]=c}lost(e){this.held.forEach(t=>{t.b&&e.delete(t.b),t.chain?.forget(e)}),this.held.clear()}restored(){for(let e of this.fx.stage.planes)e.kind==="group"&&(e.textureState="ready")}dispose(){this.held.forEach(e=>e.chain?.release()),this.held.clear()}};var se=1500,z=["normal","add","screen","multiply"],Pe=/\b(sampleImage|sampleRaw|fxaa)\s*\(/,ie=(o,e)=>new RegExp(`\\b${e}\\s*\\(`).test(o)&&!new RegExp(`\\b(void|float|vec[234])\\s+${e}\\s*\\(`).test(o),X={test:o=>ie(o,"previous")},Ue=/\btoneMap\s*\(/,Ce=/\b(?:float|int|bool|void|vec[234]|mat[234])\s+(\w+)\s*[(=;]/g,Ie={blend:"normal",opacity:1,scale:1},Be=(o="")=>[...o.matchAll(Ce)].map(e=>e[1]);function ke(o){let e=[],t=[],r=[],s=!0;for(let i of o){let n=Be(i.def.fragment?.head);(s||i.def.fragment?.uv||Pe.test(i.code)||t[0].options.scale!==i.options.scale||n.some(a=>r.includes(a)))&&(e.push(t=[]),r=[]),t.push(i),r.push(...n),s=X.test(i.code)}return e}var De=`uniform sampler2D uImage;
|
|
23
|
-
void main() { outColor = texture(uImage, vUv); }`,Oe=`uniform sampler2D uImage;
|
|
24
|
-
uniform vec2 uViewport;
|
|
25
|
-
uniform vec4 uRect;
|
|
26
|
-
uniform vec2 uMouse;
|
|
27
|
-
uniform vec2 uCanvas;
|
|
28
|
-
uniform float uScrollVelocity;
|
|
29
|
-
uniform float uProgress;
|
|
30
|
-
uniform float uDpr;
|
|
31
|
-
#define PI 3.141592653589793
|
|
32
|
-
vec4 umberStraight(vec4 c){return vec4(c.rgb/max(c.a,1e-5),c.a);}
|
|
33
|
-
vec4 sampleRaw(vec2 uv){return texture(uImage,umberY(uv));}
|
|
34
|
-
vec4 sampleImage(vec2 uv){return umberStraight(sampleRaw(uv));}
|
|
35
|
-
`,te={previous:`uniform sampler2D uPrevious;
|
|
36
|
-
uniform vec2 uScrollShift;
|
|
37
|
-
vec4 previous(vec2 uv){
|
|
38
|
-
uv+=uScrollShift;
|
|
39
|
-
if(uv.x<0.0||uv.y<0.0||uv.x>1.0||uv.y>1.0)return vec4(0.0);
|
|
40
|
-
return umberStraight(texture(uPrevious,umberY(uv)));
|
|
41
|
-
}`,toneMap:`vec3 toneMap(vec3 c){
|
|
42
|
-
c=max(c,0.0);
|
|
43
|
-
return c*(1.0+c/16.0)/(1.0+c);
|
|
44
|
-
}`,screenPx:"vec2 screenPx(){return uRect.xy+umberY(vUv)*uRect.zw;}",screenUv:"vec2 screenUv(){return(uRect.xy+umberY(vUv)*uRect.zw)/uViewport;}",fxaa:`float umberLuma(vec4 c){return dot(c.rgb,vec3(0.299,0.587,0.114));}
|
|
45
|
-
vec4 fxaa(vec2 uv){
|
|
46
|
-
vec2 px=1.0/vec2(textureSize(uImage,0));
|
|
47
|
-
vec4 m=sampleRaw(uv);
|
|
48
|
-
float n=umberLuma(sampleRaw(uv-vec2(0.0,px.y)));
|
|
49
|
-
float s=umberLuma(sampleRaw(uv+vec2(0.0,px.y)));
|
|
50
|
-
float w=umberLuma(sampleRaw(uv-vec2(px.x,0.0)));
|
|
51
|
-
float e=umberLuma(sampleRaw(uv+vec2(px.x,0.0)));
|
|
52
|
-
float l=umberLuma(m);
|
|
53
|
-
float hi=max(max(max(n,s),max(w,e)),l);
|
|
54
|
-
float lo=min(min(min(n,s),min(w,e)),l);
|
|
55
|
-
if(hi-lo<max(0.03,hi*0.12))return umberStraight(m);
|
|
56
|
-
vec2 d=vec2(s-n,w-e);
|
|
57
|
-
d=d/max(length(d),1e-5)*px;
|
|
58
|
-
vec4 a=sampleRaw(uv+d*0.5)+sampleRaw(uv-d*0.5);
|
|
59
|
-
vec4 b=sampleRaw(uv+d*1.5)+sampleRaw(uv-d*1.5);
|
|
60
|
-
return umberStraight((m*2.0+a*2.0+b)/7.0);
|
|
61
|
-
}`},Ne=`vec4 umberMix(vec4 b,vec4 c,float mode,float o){
|
|
62
|
-
vec3 m=mode<0.5?c.rgb:mode<1.5?b.rgb+c.rgb:mode<2.5?b.rgb+c.rgb-b.rgb*c.rgb:b.rgb*c.rgb;
|
|
63
|
-
return mix(b,vec4(m,c.a),o);
|
|
64
|
-
}`;function Ge(o,e){let t=o.map(u=>u.code).join(`
|
|
65
|
-
`),r=`vec2 umberY(vec2 v) { return ${e?"vec2(v.x, 1.0 - v.y)":"v"}; }
|
|
66
|
-
`+Oe;for(let u in te)ie(t,u)&&(r+=te[u]);let s="",i=!1;o.forEach((u,f)=>{let l=u.def.fragment||{},c=Math.max(0,z.indexOf(u.options.blend)),h=c>0||u.options.opacity!==1;i||=h,s+=` // ${u.name}
|
|
67
|
-
{
|
|
68
|
-
`,h&&(s+=` vec4 umberBase = ${f||!l.uv?"color":"sampleImage(umberUv)"};
|
|
69
|
-
`),l.color&&(s+=` {
|
|
70
|
-
${l.color}
|
|
71
|
-
}
|
|
72
|
-
`),l.alpha&&(s+=` float alpha = 1.0;
|
|
73
|
-
{
|
|
74
|
-
${l.alpha}
|
|
75
|
-
}
|
|
76
|
-
color.a *= alpha;
|
|
77
|
-
`),h&&(s+=` color = umberMix(umberBase, color, ${c}.0, ${G(u.name,"opacity")});
|
|
78
|
-
`),s+=` }
|
|
79
|
-
`,f||(s+=` uv = umberUv;
|
|
80
|
-
`)});let n=o.map(u=>u.def.fragment?.head?`// ${u.name}
|
|
81
|
-
${u.def.fragment.head}`:"").join(`
|
|
82
|
-
`),a=J(t+n);return`${r}${i?Ne:""}
|
|
83
|
-
${a}
|
|
84
|
-
${n}
|
|
85
|
-
void main() {
|
|
86
|
-
vec2 umberUv = umberY(vUv);
|
|
87
|
-
vec2 uv = umberUv;
|
|
88
|
-
{
|
|
89
|
-
${o[0].def.fragment?.uv||""}
|
|
90
|
-
}
|
|
91
|
-
vec4 color = sampleImage(uv);
|
|
92
|
-
${s}
|
|
93
|
-
float a = clamp(color.a, 0.0, 1.0);
|
|
94
|
-
outColor = vec4(color.rgb * a, a);
|
|
95
|
-
}
|
|
96
|
-
`}var re=o=>Math.max(1,Math.round(o)),A=class{constructor(e,t,r,s=document.documentElement){this.host=e;this.runs=[];this.values={uImage:{texture:null},uPrevious:{texture:null},uScrollShift:new Float32Array(2),uViewport:new Float32Array(2),uRect:new Float32Array(4),uMouse:new Float32Array(2),uCanvas:new Float32Array(2),uScrollVelocity:0,uProgress:0,uDpr:1};this.list="";this.size=0;this.el=null;this.glsl=!1;this.gen=0;this.pa=[];this.pairs=new Map;this.ab=0;this.Na={uImage:{texture:null}};this.w=0;this.h=0;let i=t.map(n=>n.code).join(`
|
|
97
|
-
`);this.mouse=/\buMouse\b/.test(i),this.type=Ue.test(i)?"half":"u8",this.feedback=X.test(i);for(let n of ke(t)){let a={};for(let l of n){for(let c in l.def.uniforms||{})a[c]=l.def.uniforms[c];for(let c in l.options){let h=l.options[c];(typeof h=="number"||typeof h=="boolean"||typeof h=="string"||Array.isArray(h))&&(a[G(l.name,c)]=typeof h=="boolean"?+h:h)}}for(let l in a){let c=_(a[l]);if(typeof c!="string")continue;let h=M(c,s);h?a[l]=h:delete a[l]}P(a);let u=Ge(n,r);Object.assign(a,this.values);let f=e.passes.program(u,a);this.runs.push({steps:n,scale:Math.min(1,Math.max(.25,+n[0].options.scale||1)),feedback:X.test(n.map(l=>l.code).join()),program:f,values:a})}}get ok(){return this.runs.length>0&&this.runs.every(e=>e.program)}vc(e,t,r){for(let i of this.pa)if(i!==r&&i.spec.width===e&&i.spec.height===t)return i;let s=this.host.pool.acquire({width:e,height:t,type:this.type,msaa:0,attachments:1,quiet:!0});return this.pa.push(s),s}run(e,t,r,s){let i=this.host.gl,{width:n,height:a}=e.spec;(n!==this.w||a!==this.h)&&this.release(),this.w=n,this.h=a,this.ab^=1;let u=e,f=this.runs.length;for(let l=0;l<f;l++){let c=this.runs[l],h=t&&l===f-1&&c.scale===1&&!c.feedback,m=h?r:re(n*c.scale),g=h?s:re(a*c.scale),b=null;if(c.feedback){let v=this.pairs.get(c);if(!v){let E={width:m,height:g,type:this.type,msaa:0,attachments:1,quiet:!0};this.pairs.set(c,v=[this.host.pool.acquire(E),this.host.pool.acquire(E)]);for(let fe of v)i.bindFramebuffer(i.FRAMEBUFFER,fe.fb),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT)}b=v[this.ab],this.values.uPrevious.texture=v[this.ab^1].textures[0]}else h||(b=this.vc(m,g,u));i.bindFramebuffer(i.FRAMEBUFFER,b?b.fb:null),this.values.uImage.texture=u.textures[0];let x=c.values;if(x.uScrollVelocity=this.values.uScrollVelocity,x.uProgress=this.values.uProgress,x.uDpr=this.values.uDpr,this.host.passes.draw(c.program,m,g,c.values,this.host.time,h),!b)return null;u=b}return t?(this.copy===void 0&&(this.copy=this.host.passes.program(De,this.Na)),i.bindFramebuffer(i.FRAMEBUFFER,null),this.Na.uImage.texture=u.textures[0],this.copy&&this.host.passes.draw(this.copy,r,s,this.Na,this.host.time,!0),null):u}forget(e){for(let t of this.pa)e.delete(t);for(let t of this.pairs.values())for(let r of t)e.delete(r);this.pa.length=0,this.pairs.clear(),this.w=this.h=0}release(){for(let e of this.pa)this.host.pool.release(e);for(let e of this.pairs.values())for(let t of e)this.host.pool.release(t);this.pa.length=0,this.pairs.clear()}};function ne(o,e,t,r){let s=[];for(let i of o){let n=t.get(i);if(!n){p.once(`data-gl-pass: no effect "${i}" (yet). Define it with gl.effect("${i}", {...}); until then the passes run without it.`);continue}let a=r(e,`data-gl-${i}`,{...Ie,...n.options||{}});z.includes(a.blend)||(p.once(`data-gl-${i}-blend="${a.blend}": the blends are ${z.join(", ")}; it is "normal". Other modes: write them in the effect's color slot.`),a.blend="normal"),n.vertex?.main&&p.once(`data-gl-pass: "${i}" moves vertices; a pass is one flat surface, so its vertex code is left out.`),s.push({name:i,def:n,options:a,code:Object.values(n.fragment||{}).join(`
|
|
98
|
-
`)})}return s}var oe=3e3,$=0,d=1,C=2,ae=3,le=`uniform float uProgress;
|
|
99
|
-
vec4 prev(vec2 uv){return texture(uPrev,vec2(uv.x,1.0-uv.y));}
|
|
100
|
-
vec4 next(vec2 uv){return texture(uNext,vec2(uv.x,1.0-uv.y));}
|
|
101
|
-
`,ze=`void main(){outColor=leave(vec2(vUv.x,1.0-vUv.y));}
|
|
102
|
-
`,I=class{constructor(e,t,r){this.fx=e;this.state=$;this.prev=null;this.next=null;this.progress={value:0};this.program=null;this.start=0;this.until=0;this.from="";this.away=!1;this.count=0;this.off=[];this.said=!1;let s=e.stage;if(this.swaps=/\bnext\s*\(/.test(t),this.glsl=(this.swaps?le:le.replace(/vec4 next.*\n/,""))+t+ze,this.uniforms={...r.uniforms,uPrev:{texture:null},uNext:{texture:null},uProgress:this.progress},this.swaps||delete this.uniforms.uNext,this.duration=Math.max(0,+(r.duration??1)||0),this.ease=s.ease(r.ease??"umber"),/\bvec4\s+leave\s*\(/.test(t)?this.program=e.passes.program(this.glsl,this.uniforms):p.warn("gl.leave(glsl): define `vec4 leave(vec2 uv)` (prev(uv) is the old page, next(uv) the new one, uProgress 0 -> 1)."),r.links!==!1){let i=f=>{let l=f.target?.closest?.("a[href]"),c=f;f.type==="click"&&c.detail||l&&l.origin===location.origin&&(l.pathname!==location.pathname||l.search!==location.search)&&!l.target&&!l.hasAttribute("download")&&!c.metaKey&&!c.ctrlKey&&!c.shiftKey&&!c.button&&(this.from=location.href,this.away=l.pathname!==location.pathname,this.arm(oe))},n=()=>{this.from="",this.arm(oe)},a=f=>{let l=f;this.state===d&&this.until!==1/0&&l.oldURL.split("#")[0]===l.newURL.split("#")[0]&&this.stop()},u=()=>this.state===d&&this.until!==1/0&&this.stop();addEventListener("pointerdown",i,!0),addEventListener("click",i,!0),addEventListener("pointercancel",u,!0),addEventListener("popstate",n),addEventListener("hashchange",a),this.off.push(()=>removeEventListener("pointerdown",i,!0),()=>removeEventListener("click",i,!0),()=>removeEventListener("pointercancel",u,!0),()=>removeEventListener("popstate",n),()=>removeEventListener("hashchange",a))}}arm(e=0){let t=this.fx.stage;t.reducedMotion||t.lost||this.state>d||e&&this.state===d&&this.until===1/0||(this.until=e?performance.now()+e:1/0,e&&setTimeout(()=>this.state===d&&performance.now()>=this.until&&this.stop(),e+50),this.state!==d&&(this.state=d,this.count=t.visibleList.length,t.markDirty()),!e&&!this.prev&&!t.inactive&&t.renderer.draw(t.host.ticker.frame))}swap(){this.state===d&&(this.until!==1/0&&location.href===this.from&&!(this.away&&this.left())||(this.state=C,this.fx.stage.changing||this.play()))}left(){let e=this.fx.stage;for(let t of e.visibleList)if(t.destroyed&&!e.plane(t.el))return!0;return!1}play(){this.state!==d&&this.state!==C||this.state===d&&this.until!==1/0||(this.state=ae,this.start=this.fx.stage.now,this.fx.stage.markDirty())}frame(){let e=this.fx.stage,t=e.gl,r=e.visibleList.length;if(this.state===d)if(e.changing&&r<this.count)this.state=C;else{if(performance.now()>this.until)return this.stop();this.count=r,this.copy(this.prev=this.qb(this.prev)),this.list=this.fx.passList;return}if(this.state<C)return;if(!this.prev)return this.stop();this.list!==this.fx.passList&&!this.said&&(this.said=!0,p.warn(`gl.leave(): data-gl-pass changed with the page ("${this.list}" -> "${this.fx.passList}"), so the old page leaves under the new passes. Keep the same data-gl-pass on both pages (on <html>, which routers leave alone).`));let s=0;if(this.state===ae){if(s=this.duration>0?Math.min(1,(e.now-this.start)/(this.duration*1e3)):1,s>=1)return this.stop();e.markDirty()}this.progress.value=this.ease(s),this.uniforms.uPrev.texture=this.prev.textures[0],this.swaps&&(this.next=this.qb(this.next),this.copy(this.next),this.uniforms.uNext.texture=this.next.textures[0]);let i=this.program||=this.fx.passes.program(this.glsl,this.uniforms);i&&(this.fx.passes.draw(i,e.canvas.width,e.canvas.height,this.uniforms,e.time,!this.swaps),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA)),e.renderer.reset()}qb(e){let t=this.fx,{width:r,height:s}=t.stage.canvas,i=t.on?t.scene.spec.type:"u8";return e&&e.spec.width===r&&e.spec.height===s&&e.spec.type===i?e:(t.pool.release(e),t.pool.acquire({width:r,height:s,type:i,msaa:0,attachments:1,quiet:!0}))}copy(e){let t=this.fx.stage,r=t.gl;r.bindTexture(r.TEXTURE_2D,e.textures[0]),r.copyTexSubImage2D(r.TEXTURE_2D,0,0,0,0,0,e.spec.width,e.spec.height),t.renderer.reset()}stop(){let e=this.state;this.state=$,this.fx.pool.release(this.prev),this.fx.pool.release(this.next),this.prev=this.next=null,e>d&&this.fx.stage.markDirty();let t=this.after;t&&this.fx.setLeave(t)}lost(e){e.delete(this.prev),e.delete(this.next),this.state=$,this.prev=this.next=this.program=null}dispose(){this.after=void 0,this.stop(),this.off.forEach(e=>e()),this.off=[]}};var ue=["u8","half","float"],Xe=5e3,$e=32,H=class{constructor(e,t,r){this.fx=e;this.b=t;this.spec=r;this.version=0;this.redo=null}get texture(){return this.textures[0]||null}get textures(){return this.b&&!this.fx.stage.lost?this.b.textures:[]}get framebuffer(){return this.b&&!this.fx.stage.lost?this.b.fb:null}get width(){return this.spec.width}get height(){return this.spec.height}get type(){return this.b?this.b.format.type:this.spec.type}get msaa(){return this.b?this.b.samples:0}draw(e,t={}){return(this.redo=()=>this.b&&this.fx.pass(this.b,e,t))(),this}clear(){return this.redo=null,this.fx.clear(this.b),this}resize(e,t){if(e=w(e,this.fx.stage.gl),t=w(t,this.fx.stage.gl),!this.b||e===this.spec.width&&t===this.spec.height)return this;let r=this.b;return this.spec={...this.spec,width:e,height:t},this.b=this.fx.pool.acquire(this.spec),this.fx.pool.release(r),this.version++,this.fx.clear(this.b),this.redo?.(),this}release(){this.fx.pool.release(this.b),this.b=this.redo=null,this.fx.targets.delete(this),this.fx.stage.markDirty()}};function He(o,e){for(let t of o.runs)for(let r of t.steps)if(e.get(r.name)!==r.def)return!1;return!0}var We=(o,e)=>JSON.stringify(o.runs.flatMap(t=>t.steps.map(r=>r.options)))===JSON.stringify(e.map(t=>t.options));function w(o,e){return Math.max(1,Math.min(Math.round(+o||1),e.getParameter(e.MAX_TEXTURE_SIZE)||4096))}var W=class{constructor(e,t={}){this.stage=e;this.helpers=t;this.targets=new Set;this.back=null;this.nb=0;this.groups=new U(this);this.scene=null;this.keepScene=0;this.page=null;this.bare=null;this.on=!1;this.sx=0;this.sy=0;this.trail={until:0,mine:-1};this.pointer=null;this.gen=0;this.uc=null;this.loadSim=()=>import(new URL("./sim.js",import.meta.url).href);this.heavy=!1;this.leave=null;this.options=(e,t,r)=>this.stage.readOptions(e,t,r);this.was=new Float32Array(4);this.Cc=new Float32Array(2);this.pool=new F(e.gl),this.passes=new L(e.gl);let r=e.invalidate;e.invalidate=s=>{this.gen++,this.passes.colors.clear(),r.call(e,s)},Object.defineProperty(e.stats,"targetMB",{enumerable:!0,get:()=>Math.round(this.pool.bytes/2**20)}),this.pool.grew=()=>{let s=i=>Math.round(i/1048576);this.pool.bytes>this.pool.peak&&(this.pool.peak=this.pool.bytes,e.media.evictFar()),!(this.heavy||this.pool.bytes<=e.textureBudget)&&(this.heavy=!0,p.warn(`render targets hold ${s(this.pool.bytes)} MB on the GPU (gl.info.targetMB), past this device's ${s(e.textureBudget)} MB image budget. Make them smaller: sim sizes, data-gl-<effect>-scale on passes, fewer groups, gl.target() sizes.`))},e.subsystems.push(this),e.cleanups.push(()=>this.dispose()),e.markDirty()}get gl(){return this.stage.gl}get time(){return this.stage.time}chainFor(e,t,r){let s=e.getAttribute("data-gl-pass")||"",i=this.stage,n=i.registry.effects,a=!!i.programs.glsl,u=null;if(t&&t.list===s&&t.size===n.size&&t.el===e&&t.glsl===a&&He(t,n)&&(t.gen===this.gen||(t.gen=this.gen,We(t,u=this.steps(s,e)))))return t;if(t?.release(),!s.trim())return null;Object.assign(R,this.helpers);let f=new A(this,u||this.steps(s,e),r,e);return f.list=s,f.size=n.size,f.el=e,f.glsl=a,f.gen=this.gen,f.mouse&&!this.pointer&&(addEventListener("pointermove",this.pointer=()=>this.stage.markDirty(),{passive:!0}),i.cleanups.push(()=>removeEventListener("pointermove",this.pointer))),f}steps(e,t){return ne(e.trim().split(/\s+/),t,this.stage.registry.effects,this.options)}setValues(e,t,r,s,i){let n=this.stage;e.uViewport[0]=n.viewport.width,e.uViewport[1]=n.viewport.height,e.uRect[0]=t,e.uRect[1]=r,e.uRect[2]=s,e.uRect[3]=i,e.uCanvas[0]=n.canvas.width,e.uCanvas[1]=n.canvas.height,e.uDpr=n.canvas.width/n.viewport.width,e.uScrollVelocity=n.velocity,e.uMouse[0]=(n.pointer.x-t)/s,e.uMouse[1]=(n.pointer.y-r)/i}pre(e){let t=this.stage,r=t.gl,s=t.canvas.width,i=t.canvas.height,n=t.host.ticker.frame.frame;this.back&&this.nb<n-1&&(this.pool.release(this.back),this.back=null),this.groups.draw(e,n)&&(r.viewport(0,0,s,i),r.enable(r.BLEND),r.blendFunc(r.ONE,r.ONE_MINUS_SRC_ALPHA));let a=document.body,u=this.page=this.chainFor(a?.hasAttribute("data-gl-pass")?a:document.documentElement,this.page,!0);this.on=!!u?.ok||this.keepScene>0;let f=this.scene;if(!this.on){f&&this.pool.release(f),this.scene=null;return}let l=u?.ok?u.type:"u8";(!f||f.spec.width!==s||f.spec.height!==i||f.spec.type!==l)&&(this.pool.release(f),f=this.scene=this.pool.acquire({width:s,height:i,type:l,msaa:0,attachments:1,quiet:!0})),r.bindFramebuffer(r.FRAMEBUFFER,null),r.clear(r.COLOR_BUFFER_BIT),r.bindFramebuffer(r.FRAMEBUFFER,f.fb)}get passList(){return this.page?.ok?this.page.list:""}bind(){this.on&&this.stage.gl.bindFramebuffer(this.stage.gl.FRAMEBUFFER,this.scene.fb)}post(){if(!this.on)return;this.on=!1;let e=this.stage,t=e.viewport.width,r=e.viewport.height,s=this.page?.ok?this.page:this.bare||=new A(this,[],!0),i=s.values;i.uScrollShift[0]=(e.scrollX-this.sx)/t,i.uScrollShift[1]=(e.scrollY-this.sy)/r,this.sx=e.scrollX,this.sy=e.scrollY,this.setValues(i,0,0,t,r),s.run(this.scene,!0,e.canvas.width,e.canvas.height),e.gl.bindFramebuffer(e.gl.FRAMEBUFFER,null),e.renderer.reset(),s.feedback&&this.awake(this.trail)}awake(e){let t=this.stage,r=t.host.ticker.frame.frame,s=performance.now();r!==e.mine&&(e.until=s+se),s<e.until&&(t.forced=Math.max(t.forced,2),e.mine=r+1)}target(e={}){let t=this.stage;return e.type&&!ue.includes(e.type)&&p.warn(`gl.target({ type: "${e.type}" }): the types are "u8", "half" and "float"; it is "half".`),this.make({width:w(e.width??t.canvas.width,t.gl),height:w(e.height??t.canvas.height,t.gl),type:e.type&&ue.includes(e.type)?e.type:"half",quiet:!e.type,msaa:Math.max(0,e.msaa|0),attachments:Math.min(4,Math.max(1,e.attachments|0||1))})}sims(){return this.uc||=this.stage.chunk(this.loadSim,"sim","sims stay still and uFlow reads nothing.",e=>e.sims(this))}sim(e){return this.sims().then(t=>t&&t.sim(e))}flow(e){return this.sims().then(t=>t&&t.flow(e))}setLeave(e){if(this.leave&&(this.leave.state>d||this.leave.state&&this.stage.changing))return void(this.leave.after=e);this.leave?.dispose(),this.leave=e[0]?new I(this,e[0],e[1]||{}):null}make(e){let t=new H(this,this.pool.acquire(e),e);return this.targets.add(t),this.clear(t.b),t}async snapshot(e){let t=this.stage,r=typeof e=="string"?document.querySelector(e):e instanceof Element?e:e?.el,s=r?t.plane(r):null;if(!s||s.kind==="layer")return p.warn(`gl.snapshot(): ${typeof e=="string"?`"${e}"`:"this element"} has no GL plane to copy (a [data-gl] image, video, text or shader; three.js layers render their own).`,r),null;if(!await this.whenReady(s))return p.warn("gl.snapshot(): the plane did not draw within 5 s (still loading, an error, or 0 px); nothing was copied.",r),null;let i=t.canvas.width/t.viewport.width,n=s.rect,a=this.make({width:w(n[2]*i,t.gl),height:w(n[3]*i,t.gl),type:"u8",msaa:s.level?4:0,attachments:1}),u=()=>{a.b&&!s.destroyed&&this.into(a.b,n[0],n[1],n[2],n[3],()=>t.renderer.drawPlane(s,!0))};return u(),a.redo=()=>void this.whenReady(s).then(f=>f&&u()),a}whenReady(e){let t=this.stage,r=performance.now();return t.lost||t.loadMedia(e),new Promise(s=>{let i=()=>{if(e.destroyed||e.status==="error"||t.destroyed||performance.now()-r>Xe)return s(!1);let n=e.kind==="shader"||!!e.texture?.ready;if(!t.lost&&n&&e.program?.ready()&&e.grid&&e.rect[2]>0&&e.rect[3]>0)return s(!0);setTimeout(i,30)};i()})}into(e,t,r,s,i,n,a=!0){let u=this.stage,f=u.gl;if(u.lost)return;let l=u.renderer.surface,c=u.renderer.qa,h=this.was,m=this.Cc;h.set(l),m.set(c),f.bindFramebuffer(f.FRAMEBUFFER,e.draw),f.viewport(0,0,e.spec.width,e.spec.height),f.disable(f.SCISSOR_TEST),f.clearColor(0,0,0,0),f.clear(f.COLOR_BUFFER_BIT),f.enable(f.BLEND),f.blendFunc(f.ONE,f.ONE_MINUS_SRC_ALPHA),l[0]=t,l[1]=r+i,l[2]=s,l[3]=-i,c[0]=e.spec.width,c[1]=e.spec.height,f.activeTexture(f.TEXTURE0),u.renderer.reset();try{n()}finally{l.set(h),c.set(m),this.done(e,a)}}pass(e,t,r){let s=this.stage;if(s.lost)return!1;let i=this.passes.program(t,r);return i?(P(r),s.gl.bindFramebuffer(s.gl.FRAMEBUFFER,e.draw),this.passes.draw(i,e.spec.width,e.spec.height,r,s.time),this.done(e),!0):!1}clear(e){let t=this.stage.gl;!e||this.stage.lost||(t.bindFramebuffer(t.FRAMEBUFFER,e.draw),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),this.done(e))}done(e,t=!0){e.resolve(),this.stage.gl.bindFramebuffer(this.stage.gl.FRAMEBUFFER,null),this.stage.renderer.reset(),t&&this.stage.markDirty()}copy(e){let t=this.stage,r=t.gl,s=t.canvas.width,i=t.canvas.height,n=this.back;this.nb=t.host.ticker.frame.frame;let a=this.on?this.scene.spec.type:"u8";(!n||n.spec.width!==s||n.spec.height!==i||n.spec.type!==a)&&(this.pool.release(n),n=this.back=this.pool.acquire({width:s,height:i,type:a,msaa:0,attachments:1,quiet:!0}));let u=s/t.viewport.width,f=e.rect,l=($e+e.bleed)*u,c=Math.max(0,Math.floor(f[0]*u-l)),h=Math.min(s,Math.ceil((f[0]+f[2])*u+l)),m=Math.max(0,Math.floor(i-(f[1]+f[3])*u-l)),g=Math.min(i,Math.ceil(i-f[1]*u+l));return h>c&&g>m&&(r.bindTexture(r.TEXTURE_2D,n.textures[0]),r.copyTexSubImage2D(r.TEXTURE_2D,0,c,m,c,m,h-c,g-m)),e.backdrop.texture=n.textures[0],!0}lost(){let e=this.pool.live;this.back&&e.delete(this.back),this.scene&&e.delete(this.scene),this.groups.lost(e),this.page?.forget(e),this.bare?.forget(e),this.back=this.scene=this.page=this.bare=null,this.on=!1,this.leave?.lost(e),this.pool.lost(),this.passes.lost()}restored(){this.groups.restored();let e=this.pool.restored();for(let r of this.targets)r.b=r.b&&e.get(r.b)||null,r.version++,this.clear(r.b),r.redo?.();let t=this.leave?.after;t&&this.setLeave(t)}dispose(){this.groups.dispose(),this.leave?.dispose(),this.pool.dispose(),this.passes.dispose(),this.targets.clear(),this.back=this.scene=this.page=this.bare=null}};function At(o,e={},t){V(o.host.log),q(o.host.lib);let r=o.fx=new W(o,e);return t&&o.remake(new Set(o.planes.filter(s=>s.backdrop&&s.status==="error"))),r}export{W as Fx,H as Target,At as fx};
|
|
1
|
+
/*! Umber v0.3.0 | (c) Ravi Klaassens | UNLICENSED */
|
|
2
|
+
var e=()=>{};var t=()=>Promise.reject(new Error("no words"));var s={configure:e,debug:!1,warnings:!1,info:e,warn:e,error:e,report:e,words:t},r=s;function i(e){r=e}var a=["float","half","u8"],n={float:16,half:8,u8:4};function l(e){return{type:"u8",internal:e.RGBA8,pixel:e.UNSIGNED_BYTE,filter:e.LINEAR}}function h(e,t){if(t==="u8")return l(e);if(!e.getExtension("EXT_color_buffer_float")&&(t==="float"||!e.getExtension("EXT_color_buffer_half_float")))return null;let s=t==="float",r={type:t,internal:s?e.RGBA32F:e.RGBA16F,pixel:s?e.FLOAT:e.HALF_FLOAT,filter:!s||e.getExtension("OES_texture_float_linear")?e.LINEAR:e.NEAREST},i=new u(e,{width:4,height:4,type:t,msaa:0,attachments:1},r,0),a=i.complete;return i.dispose(),a?r:null}function o(e,t,s,i=!1){for(let n of a.slice(a.indexOf(t))){s.has(n)||s.set(n,h(e,n));let a=s.get(n);if(a)return n!==t&&!i&&r.warn(`render targets: "${t}" can't be rendered to on this GPU; they use "${n}" instead (values above 1 clip and soft gradients may band). Ask for type: "${n}" to skip this message.`),a}return l(e)}var u=class{constructor(e,t,s,r){this.gl=e;this.spec=t;this.format=s;this.samples=r;this.textures=[];this.msaa=null;this.Bc=[];this.freed=0;let{width:i,height:a,attachments:n}=t;this.key=f(t,s.type,r);let l=[];for(let t=0;t<n;t++)l.push(e.COLOR_ATTACHMENT0+t);let h=e.getParameter(e.FRAMEBUFFER_BINDING);this.fb=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this.fb);for(let t=0;t<n;t++){let r=e.createTexture();e.bindTexture(e.TEXTURE_2D,r),e.texStorage2D(e.TEXTURE_2D,1,s.internal,i,a),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,s.filter),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,s.filter),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.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+t,e.TEXTURE_2D,r,0),this.textures.push(r)}if(n>1&&e.drawBuffers(l),this.complete=e.checkFramebufferStatus(e.FRAMEBUFFER)===e.FRAMEBUFFER_COMPLETE,r){this.msaa=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this.msaa);for(let t=0;t<n;t++){let n=e.createRenderbuffer();e.bindRenderbuffer(e.RENDERBUFFER,n),e.renderbufferStorageMultisample(e.RENDERBUFFER,r,s.internal,i,a),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+t,e.RENDERBUFFER,n),this.Bc.push(n)}n>1&&e.drawBuffers(l),this.complete&&=e.checkFramebufferStatus(e.FRAMEBUFFER)===e.FRAMEBUFFER_COMPLETE,e.bindRenderbuffer(e.RENDERBUFFER,null)}e.bindFramebuffer(e.FRAMEBUFFER,h)}get texture(){return this.textures[0]??null}get draw(){return this.msaa??this.fb}get bytes(){let{width:e,height:t,attachments:s}=this.spec;return e*t*n[this.format.type]*s*(1+this.samples)}resolve(){let e=this.gl;if(!this.msaa)return;let{width:t,height:s,attachments:r}=this.spec;e.bindFramebuffer(e.READ_FRAMEBUFFER,this.msaa),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,this.fb);let i=[];for(let a=0;a<r;a++){for(let t=0;t<r;t++)i[t]=t===a?e.COLOR_ATTACHMENT0+a:e.NONE;e.readBuffer(e.COLOR_ATTACHMENT0+a),r>1&&e.drawBuffers(i),e.blitFramebuffer(0,0,t,s,0,0,t,s,e.COLOR_BUFFER_BIT,e.NEAREST),i[a]=e.COLOR_ATTACHMENT0+a}if(r>1){for(let t=0;t<r;t++)i[t]=e.COLOR_ATTACHMENT0+t;e.drawBuffers(i)}e.invalidateFramebuffer(e.READ_FRAMEBUFFER,i.length?i:[e.COLOR_ATTACHMENT0]),e.bindFramebuffer(e.READ_FRAMEBUFFER,null),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,null)}dispose(){let e=this.gl;for(let t of this.textures)e.deleteTexture(t);for(let t of this.Bc)e.deleteRenderbuffer(t);e.deleteFramebuffer(this.fb),this.msaa&&e.deleteFramebuffer(this.msaa),this.textures.length=0,this.Bc.length=0}},f=(e,t,s)=>`${e.width}x${e.height}|${t}|${s}|${e.attachments}`;var c=5e3,p=class{constructor(e){this.gl=e;this.free=new Map;this.live=new Set;this.formats=new Map;this.rc=new Set;this.dead=!1;this.grew=null;this.Td=null;this.Hb=0;this.jb=()=>{this.timer=void 0;let e=performance.now(),t=!1;for(let[s,r]of this.free){for(let s=r.length-1;s>=0;s--){let i=r[s];i&&(e-i.freed>=c-1?(r.splice(s,1),i.dispose()):t=!0)}r.length||this.free.delete(s)}this.fell(),t&&(this.timer=setTimeout(this.jb,c))}}acquire(e){let t=this.gl,s=o(t,e.type,this.formats,e.quiet),i=e.msaa>0&&!this.rc.has(s.type)?Math.min(e.msaa,t.getParameter(t.MAX_SAMPLES)??0):0,a=f(e,s.type,i),n=this.free.get(a)?.pop(),l=!n;return n||(n=new u(t,e,s,i),!n.complete&&i&&(n.dispose(),this.rc.add(s.type),r.warn(`render targets: this GPU refuses ${i}x MSAA for "${s.type}" targets; they draw without it (edges stair-step). Ask for msaa: 0 to skip this message.`),n=new u(t,e,s,0))),this.live.add(n),l&&this.grew?.(),n}release(e){if(!e||!this.live.delete(e)||this.dead)return;e.freed=performance.now();let t=this.free.get(e.key);t?t.push(e):this.free.set(e.key,[e]),this.timer??=setTimeout(this.jb,c)}get bytes(){let e=0;for(let t of this.live)e+=t.bytes;for(let t of this.free.values())for(let s of t)e+=s.bytes;return e}trim(){let e=0;for(let t of this.free.values())for(let s of t)e+=s.bytes,s.dispose();return this.free.clear(),this.fell(),e}fell(){this.Hb=Math.min(this.Hb,this.bytes),this.Td?.()}lost(){this.dead=!0,this.free.clear(),this.fell(),this.formats.clear(),this.rc.clear()}restored(){this.dead=!1;let e=new Map,t=[...this.live];this.live.clear();for(let s of t)e.set(s,this.acquire(s.spec));return e}dispose(){this.timer&&clearTimeout(this.timer),this.timer=void 0;for(let e of this.live)e.dispose();for(let e of this.free.values())for(let t of e)t.dispose();this.live.clear(),this.free.clear()}};function g(e){return typeof e=="number"?new Float32Array(e):new Float32Array(e)}var m=(e,t)=>e[t]??NaN;var d=e=>e,v=["uniformMatrix2fv","uniformMatrix3fv","uniformMatrix4fv",void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,"uniformMatrix2x3fv","uniformMatrix2x4fv","uniformMatrix3x2fv","uniformMatrix3x4fv","uniformMatrix4x2fv","uniformMatrix4x3fv"],b=["uniform1iv","uniform2iv","uniform3iv","uniform4iv"],x=["uniform1uiv","uniform2uiv","uniform3uiv","uniform4uiv"];function y(e,t,s){return(t===e.UNSIGNED_INT||t>=e.UNSIGNED_INT_VEC2&&t<=e.UNSIGNED_INT_VEC4?x:b)[s-1]}var E=class{constructor(e,t,s,r="program"){this.gl=e;this.vertex=t;this.fragment=s;this.uniforms=new Map;this.state="pending";this.started=!1;this.error=null;this.shaders=[];this.options=typeof r=="string"?{label:r}:r;let i=globalThis.occluzeCapture;this.Eb=i?.version===1?null:e.getExtension("KHR_parallel_shader_compile");let a=d(e.createProgram());if(!a)throw new Error("the WebGL context is lost");this.program=a,this.options.lazy||this.start()}start(){if(this.started)return;this.started=!0;let e=this.gl,t=this.program,s,r;try{s=T(e,e.VERTEX_SHADER,this.vertex),r=T(e,e.FRAGMENT_SHADER,this.fragment)}catch{this.state="failed";return}e.attachShader(t,s),e.attachShader(t,r),e.bindAttribLocation(t,0,"aPosition");for(let[s,r]of this.options.attributes??[])e.bindAttribLocation(t,r,s);e.linkProgram(t),this.shaders=[s,r],this.Eb||this.Yb()}ready(){return this.state!=="pending"?this.state==="ok":this.compiled()?(this.Yb(),this.state==="ok"):!1}compiled(){return this.start(),this.state!=="pending"?!0:!this.Eb||!!this.gl.getProgramParameter(this.program,this.Eb.COMPLETION_STATUS_KHR)}get failed(){return this.state==="failed"}Yb(){if(this.start(),this.state!=="pending")return;let e=this.gl,t=this.program;if(!e.getProgramParameter(t,e.LINK_STATUS)){this.error=this.yg(),this.Vb(),e.deleteProgram(t),this.state="failed";return}this.Vb();let s=e.getProgramParameter(t,e.ACTIVE_UNIFORMS);for(let r=0;r<s;r++){let s=e.getActiveUniform(t,r);if(!s)continue;let i=s.name.replace(/\[0\]$/,""),a=e.getUniformLocation(t,s.name);a&&this.uniforms.set(i,{location:a,type:s.type,size:s.size})}this.state="ok"}yg(){let e=this.gl,[t,s]=this.shaders,r=A(e,t);if(r!==null)return["vertex",this.options.label,r,this.vertex];let i=A(e,s);return i!==null?["fragment",this.options.label,i,this.fragment]:["link",this.options.label,e.getProgramInfoLog(this.program)??"",""]}Vb(){for(let e of this.shaders)this.gl.deleteShader(e);this.shaders=[]}set(e,t){let s=this.state==="ok"?this.uniforms.get(e):void 0;!s||t==null||(typeof t=="number"?w(this.gl,s,t):F(this.gl,s,t))}dispose(){this.Vb(),this.state!=="failed"&&this.gl.deleteProgram(this.program)}};function w(e,t,s){if(t.last===s)return;t.last=s;let{type:r,location:i}=t;r===e.FLOAT?e.uniform1f(i,s):r===e.UNSIGNED_INT?e.uniform1ui(i,s):e.uniform1i(i,s)}function R(e,t){let s=e.last;if(s?.length===t.length){let e=t.length;for(;e--&&s[e]===t[e];);if(e<0)return!1}else s=[],e.last=s;for(let e=0;e<t.length;e++)s[e]=m(t,e);return!0}function F(e,t,s){if(!R(t,s))return;let{type:r,location:i}=t,a=v[r-e.FLOAT_MAT2];if(r===e.FLOAT_VEC2)e.uniform2fv(i,s);else if(r===e.FLOAT_VEC3)e.uniform3fv(i,s,0,Math.min(s.length,t.size*3));else if(r===e.FLOAT_VEC4)e.uniform4fv(i,s);else if(a)e[a](i,!1,s);else if(r===e.FLOAT)e.uniform1fv(i,s);else{let a=y(e,r,s.length/t.size);a&&e[a](i,s)}}function T(e,t,s){let r=d(e.createShader(t));if(!r)throw new Error("the WebGL context is lost");return e.shaderSource(r,s),e.compileShader(r),r}function A(e,t){return t&&!e.getShaderParameter(t,e.COMPILE_STATUS)?e.getShaderInfoLog(t)??"":null}var M={};function _(e,t=M){let s=new Map,r=i=>{let a=t[i];if(!(!a||s.has(i)||a.defined.test(e))){for(let e of a.needs??[])r(e);s.set(i,a)}};for(let[s,i]of Object.entries(t))i.used.test(e)&&r(s);return[...s.values()].map(e=>e.code).join(`\n\n`)}var U=new Set(["uViewport","uSurface","uRect","uSize","uTime","uScrollVelocity","uMouse","uProgress","uAlpha","uRadius","uRadiusKy","uDpr","uImage","uImageSize","uFit","uFitPosition","uGlyphIndex","uGlyphData","uUmberTextLayout","uUmberTextColor","uUmberCurves","uUmberBands","uUmberGlyphs","uPlaneMatrix","uCanvas","uBleed","uUmberClips","uUmberClipXf","uUmberClipBox","uUmberClipRadius","uUmberClipPoly","uUmberClipPolyInfo","uUmberHdr"]);function S(e){if(typeof e=="number"||typeof e=="boolean")return"float";if(Array.isArray(e)||ArrayBuffer.isView(e)){let t=e.length;return t===2?"vec2":t===3?"vec3":t===4?"vec4":t===9?"mat3":t===16?"mat4":null}return typeof e=="string"?"sampler2D":e&&typeof e=="object"?"highp sampler2D":null}function k(e,t){let s=e=>e.charAt(0).toUpperCase()+e.slice(1),r=e=>e.split(/[-_\s]+/).map(s).join("");return`u${r(e)}${r(t)}`}var B=/\/\*[\s\S]*?\*\/|\/\/[^\n]*/g;function L(e){let t=e.replace(/\\n/g,`\n`).replace(B," ");return e=>new RegExp(`\\buniform\\b[^;]*\\b${e}\\b`).test(t)}function N(e,t){let s=[],r=L(t);for(let t in e){if(U.has(t)||r(t))continue;let i=S(e[t]);i&&s.push(`uniform ${i} ${t};`)}return s.join(`\n`)}var O=null,C=(e,t)=>e.replace(/var\(\s*(--[\w-]+)\s*(?:,((?:[^()]|\([^()]*\))*))?\)/g,(e,s,r)=>getComputedStyle(t).getPropertyValue(s).trim()||C(r??"",t));function D(e,t,s){let r=C(e,t).trim().replace(/currentcolor/gi,getComputedStyle(t).color);return typeof CSS>"u"||r.includes("var(")||!CSS.supports("color",r)?e.includes("var(")?(s("var",[e],t),new Float32Array(4)):null:(O??=document.createElement("canvas").getContext("2d",{willReadFrequently:!0}),O?(O.clearRect(0,0,1,1),O.fillStyle=r,O.fillRect(0,0,1,1),Float32Array.from(O.getImageData(0,0,1,1).data,e=>e/255)):null)}var I=`#version 300 es\nout vec2 vUv;\nvoid main(){\nvUv=vec2(gl_VertexID&1,gl_VertexID>>1)*2.0;\ngl_Position=vec4(vUv*2.0-1.0,0.0,1.0);\n}\n`,P=`#version 300 es\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\nin vec2 vUv;\nlayout(location=0)out vec4 outColor;\nuniform vec2 uSize;\nuniform float uTime;\nuniform float uUmberHdr;\n`,H=`void main(){\nvec4 c=color(vUv);\noutColor=vec4((uUmberHdr>0.5?c.rgb:clamp(c.rgb,0.0,1.0))*c.a,c.a);\n}\n`;function $(e){return typeof e=="object"&&e!==null&&"value"in e&&!("texture"in e)?e.value:e}function X(e){return typeof e=="object"&&e!==null&&"texture"in e}function z(e){for(let t in e){let s=$(e[t]);X(s)&&(s.Rb=!0)}}var V=64,j=[0,0,0,0];function G(e,t){let s={};for(let e in t){let r=$(t[e]);s[e]=typeof r=="string"?j:r}let r=/\bvoid\s+main\s*\(/.test(e);return P+N(s,e)+`\n`+e+(r?"":H)}var q=32,Y=class{constructor(e,t,s){this.gl=e;this.lib=t;this.clock=s;this.cache=new Map;this.drawn=new Map;this.size=new Float32Array(2);this.colors=new Map}program(e,t,s=!1,r=!0){let i=G(e,t),a=s?this.drawn:this.cache,n=a.get(i);if(n===void 0&&(n=new E(this.gl,I,i,"target pass")),n&&(r||n.failed)&&!this.finish(n)&&(n=null),a.delete(i),a.set(i,n),s&&a.size>q){for(let[e,t]of a){a.delete(e),t?.dispose();break}this.lib.say("targetDraws",[q])}return n}finish(e){return e.state==="pending"&&e.Yb(),e.failed?(e.error&&this.lib.tell("glsl",e.error,r.error),e.error=null,!1):!0}draw(e,t,s){let r=this.gl;r.viewport(0,0,t.width,t.height),r.disable(r.SCISSOR_TEST),t.over?(r.enable(r.BLEND),r.blendFunc(r.ONE,r.ONE_MINUS_SRC_ALPHA)):r.disable(r.BLEND),r.useProgram(e.program),this.size[0]=t.width,this.size[1]=t.height,e.set("uSize",this.size),e.set("uTime",this.clock.time),e.set("uUmberHdr",t.type==="half"||t.type==="float"?1:0);let i=0;for(let t in s){let a=$(s[t]);X(a)?(r.activeTexture(r.TEXTURE0+i),r.bindTexture(r.TEXTURE_2D,a.texture),e.set(t,i),i++):e.set(t,this.uniformValue(a))}r.activeTexture(r.TEXTURE0),r.bindVertexArray(null),r.drawArrays(r.TRIANGLES,0,3)}uniformValue(e){return typeof e=="boolean"?Number(e):typeof e=="string"?this.color(e):e}color(e){let t=this.colors.get(e);return t===void 0&&(this.colors.size>=V&&this.colors.clear(),t=D(e,document.documentElement,this.lib.say),this.colors.set(e,t)),t}lost(){this.cache.clear(),this.drawn.clear()}dispose(){for(let e of this.cache.values())e?.dispose();for(let e of this.drawn.values())e?.dispose();this.lost()}};var W=32;function Q(e,t){return{buffers:null,texture:{texture:null,ready:!0,width:0,height:0,refs:0,bytes:0,dispose(){}},chain:null,key:"",x:e,y:t,seen:0,trail:{until:0,mine:-1}}}var K=(e,t)=>e.group!==t||e.morphHidden||e.viewTransition||e.hush;function J(e){return e.kind==="group"?!e.texture||!e.program||!e.grid:e.kind!=="shader"&&e.texture?.ready!==!0&&e.prev?.ready!==!0||!e.program||!e.grid}var Z=class{constructor(e){this.fx=e;this.of=new WeakMap;this.known=new WeakSet;this.held=new Map;this.at=g(4);this.Ob=[0,0];this.list=[];this.gd=[];this.current=null;this.frame=0;this.depth=e=>{let t=0;for(let s=this.dc(e);s;s=this.dc(s))t++;return t};this.inner=(e,t)=>this.depth(t)-this.depth(e);this.members=()=>{let e=this.fx.stage,t=this.current;for(let s of this.gd)if(!K(s,t)&&!(!this.prepare(s)||J(s)||!s.program)){if(!s.program.ready()){s.program.failed?e.gpu.programs.failed(s,e.planes.all):e.scheduler.oa(2);continue}e.gpu.renderer.Ia(s,!0),s._z.set(s.rect),s._D.set(s._c),s._y=s.opacity,s.drawnIn(this.frame)}};this.jb=(e,t)=>{e.seen===this.frame&&!t.destroyed||(this.fx.pool.release(e.buffers),e.buffers=null,e.chain?.release(),t.destroyed&&this.held.delete(t))}}dc(e){let t=this.of.get(e);if(t===void 0||t?.destroyed){let s=e.el.parentElement?.closest("[data-umber~=group]");t=s?this.fx.stage.planes.of(s)??null:null,this.of.set(e,t)}return t}moved(){this.of=new WeakMap}draw(e,t){let s=this.list;s.length=0;for(let t of e)t.group=null,t.kind==="group"&&(s.push(t),this.known.has(t)||(this.known.add(t),this.of=new WeakMap));this.frame=t,this.gd=e;let r=!1;return s.length&&(r=this.Tf(e)),this.held.size&&this.held.forEach(this.jb),r}Tf(e){let t=this.list;t.length>1&&t.sort(this.inner);for(let s of e){let e=this.dc(s);if(!(!e||!t.includes(e))){if(s.kind==="layer"||s.backdrop){this.fx.stage.env.lib.say("groupDraw",[]);continue}s.group=e}}let s=!1;for(let r of t){if(!r.program?.ready()||!r.grid){r.program?.failed?this.Wh(r,e):this.fx.stage.scheduler.oa(2);continue}this.render(r),s=!0}return s}Wh(e,t){for(let s of t)s.group===e&&(s.group=null);this.fx.stage.gpu.programs.failed(e,this.fx.stage.planes.all)}render(e){let t=this.fx.stage,s=t.canvasHost.viewport.width,r=t.canvasHost.viewport.height,i=t.gpu.canvas.width/s,a=e.rect,n=W+e.bleed,l=Math.min(a[2],s+2*n),h=Math.min(a[3],r+2*n),o=Math.min(Math.max(-n-a[0],0),a[2]-l),u=Math.min(Math.max(-n-a[1],0),a[3]-h),f=this.held.get(e);f||(f=Q(o,u),this.held.set(e,f)),f.seen=this.frame;let c=this.vf(f,Math.max(1,Math.round(l*i)),Math.max(1,Math.round(h*i)));this.current=e;let p=this.at;p[0]=a[0]+o,p[1]=a[1]+u,p[2]=l,p[3]=h,this.fx.into(c,p,this.members,!1),this.Ob[0]=(o-f.x)/l,this.Ob[1]=(u-f.y)/h;let g=this.xh(e,f,c);f.x=o,f.y=u;let m=f.texture;m.texture=g.texture,m.width=l,m.height=h,e.texture=m,e.fit=3,e._g[0]=o,e._g[1]=u}vf(e,t,s){return(e.buffers?.spec.width!==t||e.buffers.spec.height!==s)&&(this.fx.pool.release(e.buffers),e.buffers=this.fx.pool.acquire({width:t,height:s,type:"u8",msaa:0,attachments:1})),e.buffers}xh(e,t,s){let r=this.fx.Yc(e.el,t.chain,!1);if(t.chain=r,!r?.ok)return s;let i=this.at,a=r.values;a.uScrollShift[0]=this.Ob[0],a.uScrollShift[1]=this.Ob[1],this.fx.Qd(a,i);let n=r.run(s,!1,s.spec.width,s.spec.height)??s,l=this.fx.stage;return l.gpu.gl.bindFramebuffer(l.gpu.gl.FRAMEBUFFER,null),l.gpu.renderer.reset(),r.feedback&&this.fx.awake(t.trail),n}prepare(e){if(e.modules.frames)e.modules.frames.pick(e);else if(e.kind==="video"){if(!this.fx.stage.chunks.video?.upload(e))return!1;this.fx.stage.gpu.renderer.reset()}return!0}lost(e){this.held.forEach(t=>{t.buffers&&e.delete(t.buffers),t.chain?.forget(e)}),this.held.clear()}restored(){for(let e of this.fx.stage.planes.all)e.kind==="group"&&(e.textureState="ready")}dispose(){this.held.forEach(e=>e.chain?.release()),this.held.clear()}};var ee=1500,te=["normal","add","screen","multiply"],se=/\b(sampleImage|sampleRaw|fxaa)\s*\(/,re=(e,t)=>new RegExp(`\\b${t}\\s*\\(`).test(e)&&!new RegExp(`\\b(void|float|vec[234])\\s+${t}\\s*\\(`).test(e),ie={test:e=>re(e,"previous")},ae=/\btoneMap\s*\(/,ne=/\b(?:float|int|bool|void|vec[234]|mat[234])\s+(\w+)\s*[(=;]/g,le={blend:"normal",opacity:1,scale:1},he=(e="")=>[...e.matchAll(ne)].flatMap(([,e])=>e??[]);function oe(e){let t=[],s=[],r=[],i=!0;for(let a of e){let e=he(a.def.fragment?.head);(i||a.def.fragment?.uv||se.test(a.code)||s[0]?.options.scale!==a.options.scale||e.some(e=>r.includes(e)))&&(s=[],t.push(s),r=[]),s.push(a),r.push(...e),i=ie.test(a.code)}return t}var ue=`uniform sampler2D uImage;\nvoid main() { outColor = texture(uImage, vUv); }`,fe=`uniform highp sampler2D uImage;\nuniform vec2 uViewport;\nuniform vec4 uRect;\nuniform vec2 uMouse;\nuniform vec2 uCanvas;\nuniform float uScrollVelocity;\nuniform float uProgress;\nuniform float uDpr;\n#define PI 3.141592653589793\nvec4 umberStraight(vec4 c){return vec4(c.rgb/max(c.a,1e-5),c.a);}\nvec4 sampleRaw(vec2 uv){return texture(uImage,umberY(uv));}\nvec4 sampleImage(vec2 uv){return umberStraight(sampleRaw(uv));}\n`,ce={previous:`uniform highp sampler2D uPrevious;\nuniform vec2 uScrollShift;\nvec4 previous(vec2 uv){\nuv+=uScrollShift;\nif(uv.x<0.0||uv.y<0.0||uv.x>1.0||uv.y>1.0)return vec4(0.0);\nreturn umberStraight(texture(uPrevious,umberY(uv)));\n}`,toneMap:`vec3 toneMap(vec3 c){\nc=max(c,0.0);\nreturn c*(1.0+c/16.0)/(1.0+c);\n}`,screenPx:"vec2 screenPx(){return uRect.xy+umberY(vUv)*uRect.zw;}",screenUv:"vec2 screenUv(){return(uRect.xy+umberY(vUv)*uRect.zw)/uViewport;}",fxaa:`float umberLuma(vec4 c){return dot(c.rgb,vec3(0.299,0.587,0.114));}\nvec4 fxaa(vec2 uv){\nvec2 px=1.0/vec2(textureSize(uImage,0));\nvec4 m=sampleRaw(uv);\nfloat n=umberLuma(sampleRaw(uv-vec2(0.0,px.y)));\nfloat s=umberLuma(sampleRaw(uv+vec2(0.0,px.y)));\nfloat w=umberLuma(sampleRaw(uv-vec2(px.x,0.0)));\nfloat e=umberLuma(sampleRaw(uv+vec2(px.x,0.0)));\nfloat l=umberLuma(m);\nfloat hi=max(max(max(n,s),max(w,e)),l);\nfloat lo=min(min(min(n,s),min(w,e)),l);\nif(hi-lo<max(0.03,hi*0.12))return umberStraight(m);\nvec2 d=vec2(s-n,w-e);\nd=d/max(length(d),1e-5)*px;\nvec4 a=sampleRaw(uv+d*0.5)+sampleRaw(uv-d*0.5);\nvec4 b=sampleRaw(uv+d*1.5)+sampleRaw(uv-d*1.5);\nreturn umberStraight((m*2.0+a*2.0+b)/7.0);\n}`},pe=`vec4 umberMix(vec4 b,vec4 c,float mode,float o){\nvec3 m=mode<0.5?c.rgb:mode<1.5?b.rgb+c.rgb:mode<2.5?b.rgb+c.rgb-b.rgb*c.rgb:b.rgb*c.rgb;\nvec4 p=mix(vec4(b.rgb*b.a,b.a),vec4(m*c.a,c.a),o);\nreturn vec4(p.rgb/max(p.a,1e-5),p.a);\n}`,ge=e=>Math.max(0,te.indexOf(e.options.blend)),me=e=>ge(e)>0||e.options.opacity!==1;function de(e,t){let s=e.def.fragment??{},r=me(e),i=` // ${e.name}\n {\n`;return r&&(i+=` vec4 umberBase = ${t||!s.uv?"color":"sampleImage(umberUv)"};\n`),s.color&&(i+=` {\n${s.color}\n }\n`),s.alpha&&(i+=` float alpha = 1.0;\n {\n${s.alpha}\n }\n color.a *= alpha;\n`),r&&(i+=` color = umberMix(umberBase, color, ${ge(e)}.0, ${k(e.name,"opacity")});\n`),i+=` }\n`,t||(i+=` uv = umberUv;\n`),i}function ve(e,t,s){let r=e.map(e=>e.code).join(`\n`),i=`vec2 umberY(vec2 v) { return ${t?"vec2(v.x, 1.0 - v.y)":"v"}; }\n`+fe;for(let[e,t]of Object.entries(ce))re(r,e)&&(i+=t);let a=e.map(de).join(""),n=e.map(e=>e.def.fragment?.head?`// ${e.name}\n${e.def.fragment.head}`:"").join(`\n`);return`${i}${e.some(me)?pe:""}\n${_(r+n,s)}\n${n}\nvoid main() {\n vec2 umberUv = umberY(vUv);\n vec2 uv = umberUv;\n {\n${e[0]?.def.fragment?.uv??""}\n }\n vec4 color = sampleImage(uv);\n${a}\n float a = clamp(color.a, 0.0, 1.0);\n outColor = vec4((uUmberHdr > 0.5 ? color.rgb : clamp(color.rgb, 0.0, 1.0)) * a, a);\n}\n`}function be(e,t,s){let r=xe(e),i={};for(let e in r){let a=$(r[e]);if(typeof a!="string"){i[e]=r[e];continue}let n=D(a,t,s);n&&(i[e]=n)}return i}function xe(e){let t={};for(let s of e){let e=s.def.uniforms??{};for(let s in e)t[s]=e[s];for(let e in s.options){let r=s.options[e];(typeof r=="number"||typeof r=="boolean"||typeof r=="string"||Array.isArray(r))&&(t[k(s.name,e)]=typeof r=="boolean"?Number(r):r)}}return t}var ye=e=>Math.max(1,Math.round(e)),Ee=class{constructor(e,t,s,r=document.documentElement){this.host=e;this.runs=[];this.values={uImage:{texture:null},uPrevious:{texture:null},uScrollShift:new Float32Array(2),uViewport:new Float32Array(2),uRect:new Float32Array(4),uMouse:new Float32Array(2),uCanvas:new Float32Array(2),uScrollVelocity:0,uProgress:0,uDpr:1};this.list="";this.size=0;this.el=null;this.glsl=!1;this.gen=0;this.Ta=[];this.pairs=new Map;this.Fb=0;this.Tb={uImage:{texture:null}};this.kc=0;this.jc=0;let i=t.map(e=>e.code).join(`\n`);this.mouse=/\buMouse\b/.test(i),this.type=ae.test(i)?"half":"u8",this.feedback=ie.test(i);for(let i of oe(t)){let t=be(i,r,e.say);z(t);let a=ve(i,s,e.helpers);Object.assign(t,this.values);let n=e.passes.program(a,t,!1,!1);this.runs.push({steps:i,scale:Math.min(1,Math.max(.25,Number(i[0]?.options.scale)||1)),feedback:ie.test(i.map(e=>e.code).join()),program:n,values:t})}}get ok(){return this.runs.length>0&&this.runs.every(e=>e.program&&!e.program.failed)}Qh(e,t,s){for(let r of this.Ta)if(r!==s&&r.spec.width===e&&r.spec.height===t)return r;let r=this.host.pool.acquire({width:e,height:t,type:this.type,msaa:0,attachments:1,quiet:!0});return this.Ta.push(r),r}Yg(e,t,s){let r=this.pairs.get(e);if(r)return r;let i=this.host.gl,a={width:t,height:s,type:this.type,msaa:0,attachments:1,quiet:!0};r=[this.host.pool.acquire(a),this.host.pool.acquire(a)],this.pairs.set(e,r);for(let e of r)i.bindFramebuffer(i.FRAMEBUFFER,e.fb),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT);return r}run(e,t,s,r){let{width:i,height:a}=e.spec;(i!==this.kc||a!==this.jc)&&this.release(),this.kc=i,this.jc=a,this.Fb=this.Fb?0:1;let n=e,l=this.runs.length;for(let e=0,h=this.runs[0];h;h=this.runs[++e]){let o=t&&e===l-1&&h.scale===1&&!h.feedback,u=o?s:ye(i*h.scale),f=o?r:ye(a*h.scale),c=o?null:this.zh(h,u,f,n),p={width:u,height:f,over:o,type:c?.format.type};if(!this.Yf(h,n,c,p)||!c)return null;n=c}return t?(this.Hf(n,s,r),null):n}zh(e,t,s,r){if(!e.feedback)return this.Qh(t,s,r);let i=this.Yg(e,t,s);return this.values.uPrevious.texture=(this.Fb?i[0]:i[1]).texture,this.Fb?i[1]:i[0]}Yf(e,t,s,r){let i=this.host.gl;i.bindFramebuffer(i.FRAMEBUFFER,s?s.fb:null),this.values.uImage.texture=t.texture;let a=e.values;return a.uScrollVelocity=this.values.uScrollVelocity,a.uProgress=this.values.uProgress,a.uDpr=this.values.uDpr,!e.program||!this.host.passes.finish(e.program)?!1:(this.host.passes.draw(e.program,r,e.values),!0)}Hf(e,t,s){let r=this.host.gl;this.copy===void 0&&(this.copy=this.host.passes.program(ue,this.Tb)),r.bindFramebuffer(r.FRAMEBUFFER,null),this.Tb.uImage.texture=e.texture,this.copy&&this.host.passes.draw(this.copy,{width:t,height:s,over:!0},this.Tb)}forget(e){for(let t of this.Ta)e.delete(t);for(let t of this.pairs.values())for(let s of t)e.delete(s);this.Ta.length=0,this.pairs.clear(),this.kc=0,this.jc=0}release(){for(let e of this.Ta)this.host.pool.release(e);for(let e of this.pairs.values())for(let t of e)this.host.pool.release(t);this.Ta.length=0,this.pairs.clear()}};function we(e,t,{effects:s,read:r,say:i}){let a=[];for(let n of e){let e=s.get(n);if(!e){i("passEffect",[n]);continue}let l=r(t,`data-umber-${n}`,{...le,...e.options}),h=typeof l.blend=="string"&&te.includes(l.blend)?l.blend:"normal";h!==l.blend&&i("passBlend",[n,String(l.blend),te]),e.vertex?.main&&i("passVertex",[n]),a.push({name:n,def:e,options:Object.assign(l,{blend:h}),code:Object.values(e.fragment??{}).join(`\n`)})}return a}var Re=`uniform float uProgress;\nvec4 prev(vec2 uv){return texture(uPrev,vec2(uv.x,1.0-uv.y));}\nvec4 next(vec2 uv){return texture(uNext,vec2(uv.x,1.0-uv.y));}\n`,Fe=`void main(){outColor=leave(vec2(vUv.x,1.0-vUv.y));}\n`;function Te(e,t){return e.origin===location.origin&&(e.pathname!==location.pathname||e.search!==location.search)&&!e.target&&!e.hasAttribute("download")&&!t.metaKey&&!t.ctrlKey&&!t.shiftKey&&!t.button}var Ae=class{constructor(e,t,s){this.fx=e;this.state=0;this.prev=null;this.next=null;this.progress={value:0};this.program=null;this.start=0;this.until=0;this.from="";this.away=!1;this.count=0;this.off=[];this.said=!1;let r=e.stage;this.swaps=/\bnext\s*\(/.test(t),this.glsl=(this.swaps?Re:Re.replace(/vec4 next.*\n/,""))+t+Fe,this.uniforms={...s.uniforms,uPrev:{texture:null},uNext:{texture:null},uProgress:this.progress},this.swaps||delete this.uniforms.uNext;let i=s.duration??1;this.duration=Number.isNaN(i)?0:Math.max(0,i),this.ease=r.env.kit.ease(s.ease??"umber"),/\bvec4\s+leave\s*\(/.test(t)?this.program=e.passes.program(this.glsl,this.uniforms):r.env.lib.say("leaveGlsl",[]),s.links!==!1&&this.zg()}zg(){let e=e=>{let t=e.target instanceof Element?e.target.closest("a[href]"):null,s=e;e.type==="click"&&s.detail||t&&Te(t,s)&&(this.from=location.href,this.away=t.pathname!==location.pathname,this.Qb(3e3))},t=()=>{this.from="",this.Qb(3e3)},s=e=>{let t=e;this.Qc()&&t.oldURL.split("#")[0]===t.newURL.split("#")[0]&&this.stop()},r=()=>{this.Qc()&&this.stop()};addEventListener("pointerdown",e,!0),addEventListener("click",e,!0),addEventListener("pointercancel",r,!0),addEventListener("popstate",t),addEventListener("hashchange",s),this.off.push(()=>{removeEventListener("pointerdown",e,!0)},()=>{removeEventListener("click",e,!0)},()=>{removeEventListener("pointercancel",r,!0)},()=>{removeEventListener("popstate",t)},()=>{removeEventListener("hashchange",s)})}Qc(){return this.state===1&&this.until!==1/0}Qb(e=0){let t=this.fx.stage;t.env.reducedMotion||t.gpu.context.gone||this.state>1||e&&this.state===1&&this.until===1/0||(this.until=e?performance.now()+e:1/0,e&&setTimeout(()=>{this.state===1&&performance.now()>=this.until&&this.stop()},e+50),this.state!==1&&(this.state=1,this.count=t.planes.visible.length,t.scheduler.markDirty()),!e&&!this.prev&&!t.scheduler.inactive&&t.gpu.renderer.draw(t.env.host.ticker.frame))}swap(){this.state===1&&(this.until!==1/0&&location.href===this.from&&!(this.away&&this.left())||(this.state=2,this.fx.stage.scheduler.changing||this.play()))}left(){let e=this.fx.stage.planes;for(let t of e.visible)if(t.destroyed&&!e.of(t.el))return!0;return!1}play(){this.state!==1&&this.state!==2||this.state===1&&this.until!==1/0||(this.state=3,this.start=this.fx.stage.env.now,this.fx.stage.scheduler.markDirty())}frame(){let e=this.fx.stage,t=e.planes.visible.length;if(this.state===1)if(e.scheduler.changing&&t<this.count)this.state=2;else{this.Gf(t);return}if(this.state<2)return;if(!this.prev){this.stop();return}this.list!==this.fx.xc&&!this.said&&(this.said=!0,e.env.lib.say("leavePasses",[String(this.list),this.fx.xc]));let s=this.Lf();if(s>=1){this.stop();return}this.Wf(this.prev,s)}Gf(e){if(performance.now()>this.until){this.stop();return}this.count=e,this.prev=this.Xc(this.prev),this.copy(this.prev),this.list=this.fx.xc}Lf(){if(this.state!==3)return 0;let e=this.fx.stage,t=this.duration>0?Math.min(1,(e.env.now-this.start)/(this.duration*1e3)):1;return t<1&&e.scheduler.markDirty(),t}Wf(e,t){let s=this.fx.stage,r=s.gpu.gl;this.progress.value=this.ease(t),this.uniforms.uPrev.texture=e.texture,this.swaps&&(this.next=this.Xc(this.next),this.copy(this.next),this.uniforms.uNext.texture=this.next.texture),this.program??=this.fx.passes.program(this.glsl,this.uniforms);let i=this.program;if(i){let e=s.gpu.canvas;this.fx.passes.draw(i,{width:e.width,height:e.height,over:!this.swaps},this.uniforms),r.enable(r.BLEND),r.blendFunc(r.ONE,r.ONE_MINUS_SRC_ALPHA)}s.gpu.renderer.reset()}Xc(e){let t=this.fx,{width:s,height:r}=t.stage.gpu.canvas,i=t.on&&t.scene?t.scene.spec.type:"u8";return e?.spec.width===s&&e.spec.height===r&&e.spec.type===i?e:(t.pool.release(e),t.pool.acquire({width:s,height:r,type:i,msaa:0,attachments:1,quiet:!0}))}copy(e){let t=this.fx.stage.gpu,s=t.gl;s.bindTexture(s.TEXTURE_2D,e.texture),s.copyTexSubImage2D(s.TEXTURE_2D,0,0,0,0,0,e.spec.width,e.spec.height),t.renderer.reset()}stop(){let e=this.state;this.state=0,this.fx.pool.release(this.prev),this.fx.pool.release(this.next),this.prev=null,this.next=null,e>1&&this.fx.stage.scheduler.markDirty();let t=this.after;t&&this.fx.setLeave(t)}lost(e){this.prev&&e.delete(this.prev),this.next&&e.delete(this.next),this.state=0,this.prev=null,this.next=null,this.program=null}dispose(){this.after=void 0,this.stop(),this.off.forEach(e=>{e()}),this.off=[]}};var Me=["u8","half","float"],_e=5e3,Ue=32,Se=class{constructor(e,t,s){this.fx=e;this.b=t;this.spec=s;this.version=0;this.Ba=null}get texture(){return this.textures[0]??null}get textures(){return this.b&&!this.fx.stage.gpu.context.gone?this.b.textures:[]}get framebuffer(){return this.b&&!this.fx.stage.gpu.context.gone?this.b.fb:null}get width(){return this.spec.width}get height(){return this.spec.height}get type(){return this.b?this.b.format.type:this.spec.type}get msaa(){return this.b?this.b.samples:0}draw(e,t={}){return this.Ba=()=>{this.b&&this.fx.pass(this.b,e,t)},this.Ba(),this}clear(){return this.Ba=null,this.fx.clear(this.b),this}resize(e,t){if(e=Ne(e,this.fx.stage.gpu.gl),t=Ne(t,this.fx.stage.gpu.gl),!this.b||e===this.spec.width&&t===this.spec.height)return this;let s=this.b;return this.spec={...this.spec,width:e,height:t},this.b=this.fx.pool.acquire(this.spec),this.fx.pool.release(s),this.version++,this.fx.clear(this.b),this.Ba?.(),this}release(){this.fx.pool.release(this.b),this.b=null,this.Ba=null,this.fx.targets.delete(this),this.fx.stage.scheduler.markDirty()}};function ke(e,t){for(let s of e.runs)for(let e of s.steps)if(t.get(e.name)!==e.def)return!1;return!0}function Be(e){return typeof e=="string"?document.querySelector(e):e instanceof Element?e:e?.el??null}var Le=(e,t)=>JSON.stringify(e.runs.flatMap(e=>e.steps.map(e=>e.options)))===JSON.stringify(t.map(e=>e.options));function Ne(e,t){let s=t.getParameter(t.MAX_TEXTURE_SIZE)??4096;return Math.max(1,Math.min(Math.round(e||1),s))}var Oe=class{constructor(e,t={}){this.stage=e;this.helpers=t;this.targets=new Set;this.back=null;this.Rc=0;this.groups=new Z(this);this.scene=null;this.pd=0;this.page=null;this.bare=null;this.on=!1;this.sx=0;this.sy=0;this.trail={until:0,mine:-1};this.pointer=null;this.gen=0;this.Ih=null;this.loadSim=()=>import(new URL("./sim.js",import.meta.url).href);this.heavy=!1;this.leave=null;this.options=(e,t,s)=>this.stage.env.lib.config(e,t,s);this.was=new Float32Array(4);this.whole=g(4);this.oi=new Float32Array(2);this.pool=new p(e.gpu.gl),this.passes=new Y(e.gpu.gl,e.env.lib,this);let s=()=>{this.gen++,this.passes.colors.clear()};e.env.onInvalidate.add(s),e.env.cleanups.push(()=>e.env.onInvalidate.delete(s));let r=()=>{e.env.stats.targetMB=Math.round(this.pool.bytes/2**20)};r(),this.pool.Td=r,this.pool.grew=()=>{r();let t=e=>Math.round(e/2**20);this.pool.bytes>this.pool.Hb&&(this.pool.Hb=this.pool.bytes,e.gpu.media.Wb()),!(this.heavy||!(e.gpu.tier.textureBudget>0)||this.pool.bytes<=e.gpu.tier.textureBudget)&&(this.heavy=!0,e.env.lib.say("targetBudget",[t(this.pool.bytes),t(e.gpu.tier.textureBudget)]))},e.gpu.subsystems.push(this),e.env.cleanups.push(()=>{this.dispose()}),e.scheduler.markDirty()}get gl(){return this.stage.gpu.gl}get time(){return this.stage.env.frame.time}get say(){return this.stage.env.lib.say}Yc(e,t,s){let r=e.getAttribute("data-umber-pass")??"",i=this.stage,a=i.env.registry.effects,n=!!i.gpu.programs.glsl,l=null;if(t?.list===r&&t.size===a.size&&t.el===e&&t.glsl===n&&ke(t,a)&&(t.gen===this.gen||(t.gen=this.gen,l=this.steps(r,e),Le(t,l))))return t;if(t?.release(),!r.trim())return null;let h=new Ee(this,l??this.steps(r,e),s,e);if(h.list=r,h.size=a.size,h.el=e,h.glsl=n,h.gen=this.gen,h.mouse&&!this.pointer){let e=()=>{this.stage.scheduler.markDirty()};this.pointer=e,addEventListener("pointermove",e,{passive:!0}),i.env.cleanups.push(()=>{removeEventListener("pointermove",e)})}return h}steps(e,t){return we(e.trim().split(/\s+/),t,{effects:this.stage.env.registry.effects,read:this.options,say:this.stage.env.lib.say})}Qd(e,t){let s=this.stage,r=t[0],i=t[1],a=t[2],n=t[3];e.uViewport[0]=s.canvasHost.viewport.width,e.uViewport[1]=s.canvasHost.viewport.height,e.uRect[0]=r,e.uRect[1]=i,e.uRect[2]=a,e.uRect[3]=n,e.uCanvas[0]=s.gpu.canvas.width,e.uCanvas[1]=s.gpu.canvas.height,e.uDpr=s.gpu.canvas.width/s.canvasHost.viewport.width,e.uScrollVelocity=s.env.frame.velocity,e.uMouse[0]=(s.env.frame.pointer.x-r)/a,e.uMouse[1]=(s.env.frame.pointer.y-i)/n}pre(e){let t=this.stage,s=t.gpu.gl,r=t.gpu.canvas.width,i=t.gpu.canvas.height,a=t.env.host.ticker.frame.frame;this.back&&this.Rc<a-1&&(this.pool.release(this.back),this.back=null),this.groups.draw(e,a)&&(s.viewport(0,0,r,i),s.enable(s.BLEND),s.blendFunc(s.ONE,s.ONE_MINUS_SRC_ALPHA));let n=document.body,l=this.Yc(n?.hasAttribute("data-umber-pass")?n:document.documentElement,this.page,!0);this.page=l,this.on=!!l?.ok||this.pd>0;let h=this.scene,o=this.stage.gpu.renderer;if(o.Aa=0,!this.on){h&&this.pool.release(h),this.scene=null;return}let u=l?.ok?l.type:"u8";(h?.spec.width!==r||h.spec.height!==i||h.spec.type!==u)&&(this.pool.release(h),h=this.pool.acquire({width:r,height:i,type:u,msaa:0,attachments:1,quiet:!0}),this.scene=h),o.Aa=h.format.type==="u8"?0:1,s.bindFramebuffer(s.FRAMEBUFFER,null),s.clear(s.COLOR_BUFFER_BIT),s.bindFramebuffer(s.FRAMEBUFFER,h.fb)}get xc(){return this.page?.ok?this.page.list:""}get passing(){return!!this.page?.ok||this.pd>0}bind(){this.on&&this.scene&&this.stage.gpu.gl.bindFramebuffer(this.stage.gpu.gl.FRAMEBUFFER,this.scene.fb)}post(){let e=this.scene;if(!this.on||!e)return;this.on=!1;let t=this.stage,s=t.canvasHost.viewport.width,r=t.canvasHost.viewport.height,i=this.page?.ok?this.page:this.mf(),a=i.values;a.uScrollShift[0]=(t.env.frame.scrollX-this.sx)/s,a.uScrollShift[1]=(t.env.frame.scrollY-this.sy)/r,this.sx=t.env.frame.scrollX,this.sy=t.env.frame.scrollY;let n=this.whole;n[2]=s,n[3]=r,this.Qd(a,n),i.run(e,!0,t.gpu.canvas.width,t.gpu.canvas.height),t.gpu.gl.bindFramebuffer(t.gpu.gl.FRAMEBUFFER,null),t.gpu.renderer.reset(),i.feedback&&this.awake(this.trail)}mf(){return this.bare??=new Ee(this,[],!0),this.bare}awake(e){let t=this.stage,s=t.env.host.ticker.frame.frame,r=performance.now();s!==e.mine&&(e.until=r+ee),r<e.until&&(t.scheduler.oa(2),e.mine=s+1)}target(e={}){let t=this.stage;return e.type&&!Me.includes(e.type)&&t.env.lib.say("targetType",[e.type]),this.make({width:Ne(e.width??t.gpu.canvas.width,t.gpu.gl),height:Ne(e.height??t.gpu.canvas.height,t.gpu.gl),type:e.type&&Me.includes(e.type)?e.type:"half",quiet:!e.type,msaa:Math.max(0,(e.msaa??0)|0),attachments:Math.min(4,Math.max(1,(e.attachments??1)|0))})}sims(){return this.Ih??=this.stage.chunks.load({load:this.loadSim,file:"sim",dom:"sims stay still and uFlow reads nothing.",made:e=>e.sims(this)})}sim(e){return this.sims().then(t=>t?t.sim(e):null)}flow(e){return this.sims().then(t=>t?t.flow(e):null)}setLeave(e){if(this.leave&&(this.leave.state>1||this.leave.state&&this.stage.scheduler.changing)){this.leave.after=e;return}this.leave?.dispose(),this.leave=e[0]?new Ae(this,e[0],e[1]??{}):null}make(e){let t=new Se(this,this.pool.acquire(e),e);return this.targets.add(t),this.clear(t.b),t}async snapshot(e){let t=this.stage,s=Be(e),r=s?t.planes.of(s):void 0;if(!r||r.kind==="layer")return t.env.lib.say("snapshotNone",[typeof e=="string"?e:null],s),null;if(!await this.Nc(r))return t.env.lib.say("snapshotLate",[],s),null;let i=t.gpu.canvas.width/t.canvasHost.viewport.width,a=r.rect,n=this.make({width:Ne(a[2]*i,t.gpu.gl),height:Ne(a[3]*i,t.gpu.gl),type:"u8",msaa:r.level?4:0,attachments:1}),l=()=>{n.b&&!r.destroyed&&this.into(n.b,a,()=>{t.gpu.renderer.Ia(r,!0)})};return l(),n.Ba=()=>{this.Nc(r).then(e=>{e&&l()})},n}Nc(e){let t=this.stage,s=performance.now();return t.gpu.context.gone||t.factory.load(e),new Promise(r=>{let i=()=>{if(e.destroyed||e.status==="error"||t.env.destroyed||performance.now()-s>_e){r(!1);return}let a=e.kind==="shader"||!!e.texture?.ready;if(!t.gpu.context.gone&&a&&e.program?.ready()&&e.grid&&e.rect[2]>0&&e.rect[3]>0){r(!0);return}setTimeout(i,30)};i()})}into(e,t,s,r=!0){let i=this.stage,a=t[0],n=t[1],l=t[2],h=t[3],o=i.gpu.gl;if(i.gpu.context.gone)return;let u=i.gpu.renderer.surface,f=i.gpu.renderer.Ha,c=this.was,p=this.oi;c.set(u),p.set(f);let g=i.gpu.renderer.Aa;i.gpu.renderer.Aa=e.format.type==="u8"?0:1,o.bindFramebuffer(o.FRAMEBUFFER,e.draw),o.viewport(0,0,e.spec.width,e.spec.height),o.disable(o.SCISSOR_TEST),o.clearColor(0,0,0,0),o.clear(o.COLOR_BUFFER_BIT),o.enable(o.BLEND),o.blendFunc(o.ONE,o.ONE_MINUS_SRC_ALPHA),u[0]=a,u[1]=n+h,u[2]=l,u[3]=-h,f[0]=e.spec.width,f[1]=e.spec.height,o.activeTexture(o.TEXTURE0),i.gpu.renderer.reset();try{s()}finally{u.set(c),f.set(p),i.gpu.renderer.Aa=g,this.done(e,r)}}pass(e,t,s){let r=this.stage;if(r.gpu.context.gone)return!1;let i=this.passes.program(t,s,!0);if(!i)return!1;z(s);let a=e.msaa?null:this.Jf(e,s);return r.gpu.gl.bindFramebuffer(r.gpu.gl.FRAMEBUFFER,e.draw),this.passes.draw(i,e.spec,a?.uniforms??s),this.pool.release(a?.buffers??null),this.done(e),!0}Jf(e,t){let s=this.stage.gpu.gl,r=null;for(let i in t){let a=$(t[i])?.texture,n=a?e.textures.indexOf(a):-1;if(n<0)continue;r??={uniforms:{...t},buffers:this.pool.acquire({...e.spec,type:e.format.type,msaa:0,quiet:!0})};let l=r.buffers.textures[n]??null;s.bindFramebuffer(s.READ_FRAMEBUFFER,e.fb),s.readBuffer(s.COLOR_ATTACHMENT0+n),s.bindTexture(s.TEXTURE_2D,l),s.copyTexSubImage2D(s.TEXTURE_2D,0,0,0,0,0,e.spec.width,e.spec.height),r.uniforms[i]={texture:l}}return r&&s.readBuffer(s.COLOR_ATTACHMENT0),r}clear(e){let t=this.stage.gpu.gl;!e||this.stage.gpu.context.gone||(t.bindFramebuffer(t.FRAMEBUFFER,e.draw),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),this.done(e))}done(e,t=!0){e.resolve(),this.stage.gpu.gl.bindFramebuffer(this.stage.gpu.gl.FRAMEBUFFER,null),this.stage.gpu.renderer.reset(),t&&this.stage.scheduler.markDirty()}copy(e){let t=e.backdrop;if(!t)return!1;let s=this.stage,r=s.gpu.gl,i=s.gpu.canvas.width,a=s.gpu.canvas.height,n=this.back;this.Rc=s.env.host.ticker.frame.frame;let l=this.on&&this.scene?this.scene.spec.type:"u8";(n?.spec.width!==i||n.spec.height!==a||n.spec.type!==l)&&(this.pool.release(n),n=this.pool.acquire({width:i,height:a,type:l,msaa:0,attachments:1,quiet:!0}),this.back=n);let h=i/s.canvasHost.viewport.width,o=e.rect,u=(Ue+e.bleed)*h,f=Math.max(0,Math.floor(o[0]*h-u)),c=Math.min(i,Math.ceil((o[0]+o[2])*h+u)),p=Math.max(0,Math.floor(a-(o[1]+o[3])*h-u)),g=Math.min(a,Math.ceil(a-o[1]*h+u));return c>f&&g>p&&(r.bindTexture(r.TEXTURE_2D,n.texture),r.copyTexSubImage2D(r.TEXTURE_2D,0,f,p,f,p,c-f,g-p)),t.texture=n.texture,!0}lost(){let e=this.pool.live;this.back&&e.delete(this.back),this.scene&&e.delete(this.scene),this.groups.lost(e),this.page?.forget(e),this.bare?.forget(e),this.back=null,this.scene=null,this.page=null,this.bare=null,this.on=!1,this.leave?.lost(e),this.pool.lost(),this.passes.lost()}restored(){this.groups.restored();let e=this.pool.restored();for(let t of this.targets)t.b=t.b?e.get(t.b)??null:null,t.version++,this.clear(t.b),t.Ba?.();let t=this.leave?.after;t&&this.setLeave(t)}dispose(){this.groups.dispose(),this.leave?.dispose(),this.pool.dispose(),this.passes.dispose(),this.targets.clear(),this.back=null,this.scene=null,this.page=null,this.bare=null}};function Ce(e,t={},s){i(e.env.host.log);let r=new Oe(e,t);return e.chunks.fx=r,s&&e.chunks.pa(new Set(e.planes.all.filter(e=>e.backdrop&&e.status==="error"))),r}export{Oe as Fx,Se as Target,Ce as fx};
|