asciify-engine 4.28.0 → 4.29.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.
@@ -1 +1 @@
1
- var t='"use strict";(()=>{function De(n,t,e,r,i,a){r=Math.max(0,Math.min(t-1,r)),i=Math.max(0,Math.min(e-1,i));let o=Math.floor(r),l=Math.floor(i),s=r-o,h=i-l,f=(l*t+o)*4;if(s===0&&h===0){for(let S=0;S<4;S++)a[S]=n[f+S];return}let u=(l*t+Math.min(t-1,o+1))*4,m=(Math.min(e-1,l+1)*t+o)*4,d=(Math.min(e-1,l+1)*t+Math.min(t-1,o+1))*4,c=(1-s)*(1-h)*n[f+3],b=s*(1-h)*n[u+3],g=(1-s)*h*n[m+3],y=s*h*n[d+3],x=c+b+g+y;for(let S=0;S<3;S++)a[S]=x?(n[f+S]*c+n[u+S]*b+n[m+S]*g+n[d+S]*y)/x:0;a[3]=x}function _r(n,t,e,r,i,a){if(r>=0&&r<=t-1&&i>=0&&i<=e-1)return De(n,t,e,r,i,a);if(a[0]=a[1]=a[2]=a[3]=0,r<=-1||r>=t||i<=-1||i>=e)return;let o=Math.floor(r),l=Math.floor(i),s=r-o,h=i-l;for(let f=0;f<=1;f++)for(let u=0;u<=1;u++){let m=o+u,d=l+f;if(m<0||m>=t||d<0||d>=e)continue;let c=(d*t+m)*4,b=(u?s:1-s)*(f?h:1-h)*n[c+3];a[0]+=n[c]*b,a[1]+=n[c+1]*b,a[2]+=n[c+2]*b,a[3]+=b}a[3]&&(a[0]/=a[3],a[1]/=a[3],a[2]/=a[3])}var zi=`#version 300 es\nlayout(location=1) in vec4 shape;\nlayout(location=2) in float angle;\nlayout(location=3) in vec4 color;\nlayout(location=4) in float path;\nuniform vec2 size;\n// Rim vertices per quadrant in this draw: a fan of 4 * slots triangles per ellipse, of which only the\n// quadrant\'s own segment count are not empty.\nuniform int slots;\nout vec4 ink;\nconst float W = 0.70710678118;\nvec2 turn(vec2 v, vec2 axis) { return vec2(v.x * axis.x - v.y * axis.y, v.x * axis.y + v.y * axis.x); }\n// Skia\'s Wang\'s formula for a conic at a quarter-pixel tolerance, rounded up to a power of two: how many line segments\n// the GPU canvas tessellates the curve into.\nfloat segments(vec2 p0, vec2 p1, vec2 p2) {\n vec2 center = (min(min(p0, p1), p2) + max(max(p0, p1), p2)) * 0.5;\n p0 -= center; p1 -= center; p2 -= center;\n float maxLength = sqrt(max(max(dot(p0, p0), dot(p1, p1)), dot(p2, p2)));\n vec2 dp = -2.0 * W * p1 + p0 + p2;\n float dw = abs(-2.0 * W + 2.0);\n float numer = length(dp) * 4.0 + max(0.0, maxLength * 4.0 - 1.0) * dw;\n float n = sqrt(max(numer / (4.0 * min(W, 1.0)), 0.0));\n return exp2(ceil(log2(max(1.0, ceil(n)))));\n}\nvoid main() {\n int triangle = gl_VertexID / 3, corner = gl_VertexID % 3;\n vec2 radii = shape.zw;\n vec2 axis = vec2(cos(angle), sin(angle));\n vec2 unit = vec2(0.0);\n if (corner != 0) {\n int k = triangle + corner - 1, quadrant = k / slots;\n // The quadrant\'s own conic, in the frame\'s pixels, decides its segment count.\n vec2 a0 = vec2(1.0, 0.0), a1 = vec2(1.0, 1.0), a2 = vec2(0.0, 1.0);\n if (quadrant == 1) { a0 = vec2(0.0, 1.0); a1 = vec2(-1.0, 1.0); a2 = vec2(-1.0, 0.0); }\n else if (quadrant == 2) { a0 = vec2(-1.0, 0.0); a1 = vec2(-1.0, -1.0); a2 = vec2(0.0, -1.0); }\n else if (quadrant == 3) { a0 = vec2(0.0, -1.0); a1 = vec2(1.0, -1.0); a2 = vec2(1.0, 0.0); }\n float n = min(float(slots), segments(turn(a0 * radii, axis), turn(a1 * radii, axis), turn(a2 * radii, axis)));\n float t = quadrant > 3 ? 0.0 : floor(float(k - quadrant * slots) * n / float(slots)) / n;\n float a = (1.0 - t) * (1.0 - t), b = 2.0 * W * t * (1.0 - t), c = t * t;\n unit = quadrant > 3 ? vec2(1.0, 0.0) : (a0 * a + a1 * b + a2 * c) / (a + b + c);\n }\n vec2 p = shape.xy + turn(unit * radii, axis);\n ink = vec4(color.rgb * color.a, color.a);\n // Drawn upside down and flipped back when resolved: the canvas\'s multisample pattern is the GPU\'s, top-left origin.\n // Each fill is one path: a later path is nearer, and a path\'s own shapes overlap on equal depth, so a sample covered\n // twice by one path is blended once, as a single filled path is.\n gl_Position = vec4(p / size * 2.0 - 1.0, 1.0 - path * exp2(-23.0), 1.0);\n}`,qi=`#version 300 es\nprecision highp float;\nin vec4 ink;\nout vec4 outColor;\nvoid main() { outColor = ink; }`,Gi=`#version 300 es\nlayout(location=1) in vec4 shape;\nlayout(location=3) in vec4 color;\nlayout(location=4) in float path;\nuniform vec2 size;\nout vec4 ink;\nflat out vec3 disc;\nvoid main() {\n int corner = gl_VertexID;\n vec2 c = vec2(corner == 1 || corner == 2 || corner == 4 ? 1.0 : 0.0, corner == 2 || corner == 4 || corner == 5 ? 1.0 : 0.0);\n float reach = shape.z + 1.0;\n vec2 p = mix(floor(shape.xy - reach), ceil(shape.xy + reach), c);\n ink = vec4(color.rgb * color.a, color.a);\n disc = shape.xyz;\n gl_Position = vec4(p / size * 2.0 - 1.0, 1.0 - path * exp2(-23.0), 1.0);\n}`,Bi=`#version 300 es\nprecision highp float;\nin vec4 ink;\nflat in vec3 disc;\nout vec4 outColor;\nvoid main() {\n float r = disc.z, d = distance(gl_FragCoord.xy, disc.xy);\n float coverage = clamp(d < r ? 0.5 - (d * d - r * r) / (2.0 * max(d, 1e-6)) : r + 0.5 - d, 0.0, 1.0);\n if (coverage <= 0.0) discard;\n outColor = ink * coverage;\n}`;var $e="dot-fill";function Jr(){if(typeof OffscreenCanvas!="function")return null;let n=new OffscreenCanvas(300,150),t=n.getContext("webgl2",{alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1});if(!t)return null;let e=(L,z)=>{let O=t.createShader(L);if(t.shaderSource(O,z),t.compileShader(O),!t.getShaderParameter(O,t.COMPILE_STATUS))throw new Error(t.getShaderInfoLog(O)||"Dot shader failed");return O},r=(L,z)=>{let O=t.createProgram();return t.attachShader(O,e(t.VERTEX_SHADER,L)),t.attachShader(O,e(t.FRAGMENT_SHADER,z)),t.linkProgram(O),t.getProgramParameter(O,t.LINK_STATUS)?O:null},i,a;try{i=r(zi,qi),a=r(Gi,Bi)}catch{return null}if(!i||!a)return null;let o=t.getUniformLocation(i,"size"),l=t.getUniformLocation(i,"slots"),s=t.getUniformLocation(a,"size"),h=!1,f=!1,u=new Float64Array(6*4096),m=new Float64Array(9*1024),d=[],c=0,b=0,g=0,y=0,x=null,S=t.createVertexArray();t.bindVertexArray(S);let A=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,A);let k=40;t.enableVertexAttribArray(1),t.vertexAttribPointer(1,4,t.FLOAT,!1,k,0),t.vertexAttribDivisor(1,1),t.enableVertexAttribArray(2),t.vertexAttribPointer(2,1,t.FLOAT,!1,k,16),t.vertexAttribDivisor(2,1),t.enableVertexAttribArray(3),t.vertexAttribPointer(3,4,t.FLOAT,!1,k,20),t.vertexAttribDivisor(3,1),t.enableVertexAttribArray(4),t.vertexAttribPointer(4,1,t.FLOAT,!1,k,36),t.vertexAttribDivisor(4,1),t.bindVertexArray(null);let U=Math.min(4,t.getParameter(t.MAX_SAMPLES)),Y=t.createFramebuffer(),I=t.createRenderbuffer(),P=t.createRenderbuffer(),M=0,X=0,H=t.createFramebuffer(),K=t.createRenderbuffer(),v=new Float32Array(10*4096),R=0,G=1,q=1,C=0,E=new Float64Array(40),w=0,F=1,B=0,Z=0,et=0,N=1,tt="#000000",dt=new Map,lt=new OffscreenCanvas(1,1).getContext("2d"),St=L=>Math.max(0,Math.min(255,Number(L)))/255,Et=L=>{let z=dt.get(L);if(z)return z;let O=/^rgb\\(([-+.\\deE]+),([-+.\\deE]+),([-+.\\deE]+)\\)$/.exec(L),rt=O?null:/^#([\\da-f]{2})([\\da-f]{2})([\\da-f]{2})$/i.exec(L);if(O&&O.slice(1).every(J=>Number.isFinite(Number(J))))z=[St(O[1]),St(O[2]),St(O[3]),1];else if(rt)z=[parseInt(rt[1],16)/255,parseInt(rt[2],16)/255,parseInt(rt[3],16)/255,1];else{if(lt.fillStyle="#010203",lt.fillStyle=L,lt.fillStyle==="#010203"&&!/^(#010203|rgb\\(1,2,3\\))$/i.test(L.replace(/\\s/g,"")))return null;lt.clearRect(0,0,1,1),lt.fillRect(0,0,1,1);let[J,pt,Mt,Dt]=lt.getImageData(0,0,1,1).data;z=[J/255,pt/255,Mt/255,Dt/255]}return dt.size>=4096&&dt.clear(),dt.set(L,z),z},Lt=(L,z,O,rt,J)=>{if(w*5+5>E.length){let Mt=new Float64Array(E.length*2);Mt.set(E),E=Mt}let pt=w++*5;E[pt]=L,E[pt+1]=z,E[pt+2]=O,E[pt+3]=rt,E[pt+4]=J},Tt=!0,yt=0,ee=(L,z,O,rt,J,pt)=>{if((R+1)*6>u.length){let Dt=new Float64Array(u.length*2);Dt.set(u),u=Dt}let Mt=R++*6;u[Mt]=L,u[Mt+1]=z,u[Mt+2]=O,u[Mt+3]=rt,u[Mt+4]=J,u[Mt+5]=pt},ct=(L,z,O,rt,J,pt,Mt,Dt,Bt,ut)=>{if((R+1)*10>v.length){let zt=new Float32Array(v.length*2);zt.set(v),v=zt}let gt=R++*10;O>yt&&(yt=O),rt>yt&&(yt=rt),v[gt]=L,v[gt+1]=z,v[gt+2]=O,v[gt+3]=rt,v[gt+4]=J,v[gt+5]=pt,v[gt+6]=Mt,v[gt+7]=Dt,v[gt+8]=Bt,v[gt+9]=ut},Qt=(L,z,O,rt,J,pt,Mt,Dt,Bt)=>{if((L+1)*9>m.length){let gt=new Float64Array(m.length*2);gt.set(m),m=gt}let ut=L*9;m[ut]=z,m[ut+1]=O,m[ut+2]=rt,m[ut+3]=J,m[ut+4]=F,m[ut+5]=Mt,m[ut+6]=Dt,m[ut+7]=Bt,!pt&&d[d.length-1]!==tt&&d.push(tt),m[ut+8]=pt?-1:d.length-1},de={get globalAlpha(){return F},set globalAlpha(L){L>=0&&L<=1&&(F=L)},get fillStyle(){return tt},set fillStyle(L){if(typeof L!="string"||L===tt)return;tt=L;let z=Et(L);z&&([B,Z,et,N]=z)},strokeStyle:"#000000",globalCompositeOperation:"source-over",font:"",textBaseline:"alphabetic",textAlign:"start",beginPath(){w=0},moveTo(){},closePath(){},arc(L,z,O){Lt(L,z,O,O,0)},ellipse(L,z,O,rt,J){Lt(L,z,O,rt,J)},fill(){let L=F*N;if(L<=0)return;let z=++C,O=!1;for(let rt=0;rt<w;rt++){let J=rt*5;E[J+2]>0&&E[J+3]>0&&(Tt?ee(E[J],E[J+1],E[J+2],E[J+3],E[J+4],z):ct(E[J],E[J+1],E[J+2],E[J+3],E[J+4],B,Z,et,L,z),O=!0)}O&&(w===1&&E[2]===E[3]&&E[4]===0&&E[2]>=1?h=!0:f=!0,Tt&&Qt(z,L,B,Z,et,tt===$e,b,g,y))},fillColor(L,z,O){tt=$e,b=L,g=z,y=O,B=Math.max(0,Math.min(255,L))/255,Z=Math.max(0,Math.min(255,z))/255,et=Math.max(0,Math.min(255,O))/255,N=1},fillEllipse(L,z,O,rt,J,pt,Mt,Dt){if(F<=0)return;let Bt=++C;if(!(O>0&&rt>0))return;f=!0;let ut=Math.max(0,Math.min(255,pt))/255,gt=Math.max(0,Math.min(255,Mt))/255,zt=Math.max(0,Math.min(255,Dt))/255;if(!Tt)return ct(L,z,O,rt,J,ut,gt,zt,F,Bt);ee(L,z,O,rt,J,Bt),Qt(Bt,F,ut,gt,zt,!0,pt,Mt,Dt)}},kt=()=>{x||(x=new OffscreenCanvas(G,q).getContext("2d"));let L=x;if(!L)return null;L.canvas.width!==G||L.canvas.height!==q?(L.canvas.width=G,L.canvas.height=q):L.clearRect(0,0,G,q);for(let z=0;z<R;){let O=u[z*6+5],rt=O*9;L.globalAlpha=m[rt+4],L.fillStyle=m[rt+8]<0?`rgb(${m[rt+5]},${m[rt+6]},${m[rt+7]})`:d[m[rt+8]],L.beginPath();let J=z+1<R&&u[(z+1)*6+5]===O;for(;z<R&&u[z*6+5]===O;z++){let pt=z*6,Mt=u[pt],Dt=u[pt+1],Bt=u[pt+2],ut=u[pt+3],gt=u[pt+4];J&&L.moveTo(Mt+Bt,Dt),Bt===ut&&gt===0?L.arc(Mt,Dt,Bt,0,Math.PI*2):L.ellipse(Mt,Dt,Bt,ut,gt,0,Math.PI*2)}L.fill()}return L.globalAlpha=1,L.canvas};return{ctx:de,begin(L,z,O=!0){return t.isContextLost()?!1:c>0?(c--,!1):(Tt=O,yt=0,G=L,q=z,R=0,d=[],h=f=!1,w=0,C=0,F=1,tt="#000000",B=Z=et=0,N=1,!0)},finish(){if(h&&f&&Tt)return c=30,kt();if(t.isContextLost())return null;if(n.width!==G&&(n.width=G),n.height!==q&&(n.height=q),(M!==G||X!==q)&&(M=G,X=q,t.bindRenderbuffer(t.RENDERBUFFER,I),t.renderbufferStorageMultisample(t.RENDERBUFFER,U,t.RGBA8,G,q),t.bindRenderbuffer(t.RENDERBUFFER,P),t.renderbufferStorageMultisample(t.RENDERBUFFER,U,t.DEPTH_COMPONENT24,G,q),t.bindFramebuffer(t.FRAMEBUFFER,Y),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.RENDERBUFFER,I),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.RENDERBUFFER,P),t.bindRenderbuffer(t.RENDERBUFFER,K),t.renderbufferStorage(t.RENDERBUFFER,t.RGBA8,G,q),t.bindFramebuffer(t.FRAMEBUFFER,H),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.RENDERBUFFER,K)),t.bindFramebuffer(t.FRAMEBUFFER,Y),t.viewport(0,0,G,q),t.clearColor(0,0,0,0),t.clearDepth(1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT),R){if(R*10>v.length&&(v=new Float32Array(Math.max(v.length*2,R*10))),Tt)for(let L=0;L<R;L++){let z=L*6,O=u[z+5],rt=O*9,J=L*10,pt=u[z+2],Mt=u[z+3];pt>yt&&(yt=pt),Mt>yt&&(yt=Mt),v[J]=u[z],v[J+1]=u[z+1],v[J+2]=pt,v[J+3]=Mt,v[J+4]=u[z+4],v[J+5]=m[rt+1],v[J+6]=m[rt+2],v[J+7]=m[rt+3],v[J+8]=m[rt],v[J+9]=O}if(t.enable(t.DEPTH_TEST),t.depthFunc(t.LESS),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.bindVertexArray(S),t.bindBuffer(t.ARRAY_BUFFER,A),t.bufferData(t.ARRAY_BUFFER,v.subarray(0,R*10),t.STREAM_DRAW),h&&!f)t.useProgram(a),t.uniform2f(s,G,q),t.drawArraysInstanced(t.TRIANGLES,0,6,R);else{let L=Math.sqrt(Math.max(0,2*yt-.207)),z=Math.min(64,2**Math.ceil(Math.log2(Math.max(1,Math.ceil(L)))));t.useProgram(i),t.uniform2f(o,G,q),t.uniform1i(l,z),t.drawArraysInstanced(t.TRIANGLES,0,z*4*3,R)}t.bindVertexArray(null)}return t.bindFramebuffer(t.READ_FRAMEBUFFER,Y),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,H),t.blitFramebuffer(0,0,G,q,0,0,G,q,t.COLOR_BUFFER_BIT,t.NEAREST),t.bindFramebuffer(t.READ_FRAMEBUFFER,H),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),t.blitFramebuffer(0,0,G,q,0,q,G,0,t.COLOR_BUFFER_BIT,t.NEAREST),t.bindFramebuffer(t.FRAMEBUFFER,null),n},destroy(){x&&(x.canvas.width=x.canvas.height=1),t.deleteProgram(i),t.deleteProgram(a),t.deleteRenderbuffer(I),t.deleteRenderbuffer(P),t.deleteRenderbuffer(K),t.deleteFramebuffer(Y),t.deleteFramebuffer(H),t.getExtension("WEBGL_lose_context")?.loseContext(),n.width=n.height=1}}}var Xi=["rgb","red","green","blue"],Rr=n=>Math.max(0,Math.min(1,n));function Zr(n){let t=new Map([[0,0],[1,1]]);if(Array.isArray(n))for(let e of n.slice(0,64)){if(!Array.isArray(e)||e.length<2||typeof e[0]!="number"||!Number.isFinite(e[0])||typeof e[1]!="number"||!Number.isFinite(e[1]))continue;let r=Math.round(Rr(e[0])*255)/255;!t.has(r)&&t.size>=16||t.set(r,Rr(e[1]))}return[...t].sort((e,r)=>e[0]-r[0])}function Qr(n){let t=n&&typeof n=="object"?n:{};return Object.fromEntries(Xi.map(e=>[e,Zr(t[e])]))}function Tr(n){let t=Zr(n),e=t.length,r=t.slice(1).map((s,h)=>s[0]-t[h][0]),i=t.slice(1).map((s,h)=>(s[1]-t[h][1])/r[h]),a=new Float64Array(e);a[0]=i[0],a[e-1]=i[e-2];for(let s=1;s<e-1;s++){let h=i[s-1],f=i[s];if(h*f<=0)continue;let u=2*r[s]+r[s-1],m=r[s]+2*r[s-1];a[s]=(u+m)/(u/h+m/f)}let o=new Uint8Array(256),l=0;for(let s=0;s<256;s++){let h=s/255;for(;l<e-2&&h>t[l+1][0];)l++;let f=r[l],u=(h-t[l][0])/f,m=u*u,d=m*u,c=(2*d-3*m+1)*t[l][1]+(d-2*m+u)*f*a[l]+(-2*d+3*m)*t[l+1][1]+(d-m)*f*a[l+1];o[s]=Math.round(Rr(c)*255)}return o}function Cr(n){let t=Yi(n),e=n.curves;if(!t&&(!e||Object.values(e).every(o=>o.every(([l,s])=>l===s))))return null;let r=Tr(e?.rgb),i=[e?.red,e?.green,e?.blue].map(Tr),a=new Uint8Array(768);for(let o=0;o<256;o++)for(let l=0;l<3;l++)a[l*256+o]=i[l][r[t?t[o]:o]];return a}function $r(n,t){for(let e=0;e<n.length;e+=4)n[e+3]&&(n[e]=t[n[e]],n[e+1]=t[256+n[e+1]],n[e+2]=t[512+n[e+2]])}function Yi(n){let t=n.blackPoint??0,e=n.whitePoint??1,r=n.gamma??1,i=n.shadows??0,a=n.highlights??0;if(t===0&&e===1&&r===1&&i===0&&a===0)return null;let o=[0,.25+i*.2,.5,.75+a*.2,1],l=o.slice(1).map((f,u)=>(f-o[u])*4),s=[l[0],...l.slice(1).map((f,u)=>2*f*l[u]/(f+l[u])),l[3]],h=new Uint8Array(256);for(let f=0;f<256;f++){let u=Math.pow(Math.max(0,Math.min(1,(f/255-t)/(e-t))),1/r),m=Math.min(3,Math.floor(u*4)),d=u*4-m,c=d*d,b=c*d,g=(2*b-3*c+1)*o[m]+(b-2*c+d)*s[m]/4+(-2*b+3*c)*o[m+1]+(b-c)*s[m+1]/4;h[f]=Math.round(Math.max(0,Math.min(1,g))*255)}return h}var tr=class{constructor(t=0){this.amount=0;this.weights=new Float32Array(256);this.source=new Uint8ClampedArray(0);this.configure(t)}configure(t=0){let e=Math.max(0,Math.min(1,Number.isFinite(t)?t:0));if(e===this.amount)return;if(this.amount=e,e===0){this.source=new Uint8ClampedArray(0);return}let r=8+e*24;for(let i=0;i<256;i++)this.weights[i]=Math.exp(-i*i/(2*r*r))}apply(t,e,r){if(!this.amount)return;if(!Number.isInteger(e)||!Number.isInteger(r)||e<1||r<1||e*r*4!==t.length)throw new Error("Denoise dimensions do not match the source.");this.source.length!==t.length&&(this.source=new Uint8ClampedArray(t.length));let i=this.source;i.set(t);for(let a=0;a<r;a++)for(let o=0;o<e;o++){let l=(a*e+o)*4;if(!i[l+3])continue;let s=i[l],h=i[l+1],f=i[l+2],u=0,m=0,d=0,c=0;for(let b=-1;b<=1;b++){let g=a+b;if(!(g<0||g>=r))for(let y=-1;y<=1;y++){let x=o+y;if(x<0||x>=e)continue;let S=(g*e+x)*4;if(!i[S+3])continue;let A=Math.max(Math.abs(i[S]-s),Math.abs(i[S+1]-h),Math.abs(i[S+2]-f)),k=this.weights[A]*(y===0?1:.6)*(b===0?1:.6)*i[S+3];u+=i[S]*k,m+=i[S+1]*k,d+=i[S+2]*k,c+=k}}t[l]=s+(u/c-s)*this.amount,t[l+1]=h+(m/c-h)*this.amount,t[l+2]=f+(d/c-f)*this.amount}}};var Wi=[{value:"twirl",label:"Twirl",description:"Rotate the center into a smooth spiral; the outer boundary stays fixed.",direction:!1,frequency:!1},{value:"pinch",label:"Pinch",description:"Contract the center, or expand it with negative strength.",direction:!1,frequency:!1},{value:"sphere",label:"Spherize",description:"Magnify a rounded lens through the source; negative strength recedes.",direction:!1,frequency:!1},{value:"ripple",label:"Ripple",description:"Bend the image through concentric, soft-edged waves.",direction:!1,frequency:!0},{value:"zigzag",label:"Zigzag",description:"Alternate the twist in sharp, concentric bands.",direction:!1,frequency:!0},{value:"shear",label:"Shear",description:"Slant a region along an adjustable direction.",direction:!0,frequency:!1},{value:"smudge",label:"Smudge",description:"Draw a soft region of the source along one direction.",direction:!0,frequency:!1},{value:"polar",label:"Polar",description:"Unwrap a region into polar coordinates; negative strength wraps it.",direction:!0,frequency:!1},{value:"fragment",label:"Fragment",description:"Offset small source tiles into a stable fractured texture.",direction:!0,frequency:!0}],ji=8,Ue=(n,t,e,r)=>typeof n=="number"&&Number.isFinite(n)?Math.max(e,Math.min(r,n)):t;function Pr(n){if(!Array.isArray(n))return[];let t=[];for(let e of n.slice(0,64))if(!(!e||typeof e!="object"||!Wi.some(r=>r.value===e.type))&&(t.push({type:e.type,enabled:e.enabled!==!1,amount:Ue(e.amount,.35,-1,1),x:Ue(e.x,.5,0,1),y:Ue(e.y,.5,0,1),radius:Ue(e.radius,.55,.05,2),angle:Ue(e.angle,0,-180,180),frequency:Ue(e.frequency,5,1,24)}),t.length===ji))break;return t}var Ir=Math.PI*2,ti=(n,t)=>{let e=Math.imul(n,374761393)^Math.imul(t,668265263);return e=Math.imul(e^e>>>13,1274126177),((e^e>>>16)>>>0)/4294967296},er=class{constructor(t=[],e="clamp"){this.warps=[];this.signature="";this.geometry="";this.coordinates=new Float32Array(0);this.output=new Uint8ClampedArray(0);this.sampled=[0,0,0,0];this.edge="clamp";this.configure(t,e)}configure(t=[],e="clamp"){let r=Pr(t).filter(a=>a.enabled&&a.amount!==0),i=JSON.stringify(r);this.edge=e==="transparent"?"transparent":"clamp",i!==this.signature&&(this.signature=i,this.geometry="",this.warps=r.map(a=>({...a,cos:Math.cos(a.angle*Math.PI/180),sin:Math.sin(a.angle*Math.PI/180)})),r.length||this.clear())}get active(){return this.warps.length>0}apply(t,e,r,i=e/r){if(!this.active)return t;if(!Number.isInteger(e)||!Number.isInteger(r)||e<1||r<1||e*r*4!==t.length||!Number.isFinite(i)||i<=0)throw new Error("Warp dimensions do not match the source.");let a=`${e}:${r}:${i}`;if(a!==this.geometry){this.coordinates.length!==e*r*2&&(this.coordinates=new Float32Array(e*r*2));let s=Math.max(1,i),h=Math.max(1,1/i);for(let f=0;f<r;f++)for(let u=0;u<e;u++){let m=(u+.5)/e,d=(f+.5)/r;for(let b=this.warps.length-1;b>=0;b--){let g=this.warps[b],y=(m-g.x)*s/g.radius,x=(d-g.y)*h/g.radius,S=y*y+x*x;if(S>=1)continue;let A=Math.sqrt(S),k=(1-S)*(1-S),U=g.amount,Y=y,I=x;if(g.type==="twirl"||g.type==="zigzag"){let P=g.type==="twirl"?-U*Ir*k:U*.65*(2/Math.PI*Math.asin(Math.sin(A*Ir*g.frequency)))*k,M=Math.cos(P),X=Math.sin(P);Y=y*M-x*X,I=y*X+x*M}else if(g.type==="pinch"){let P=Math.exp(U*2*k);Y=y*P,I=x*P}else if(g.type==="sphere"&&A>0){let P=Math.asin(A)*2/Math.PI,M=1+U*k*(P/A-1);Y=y*M,I=x*M}else if(g.type==="ripple"&&A>0){let P=1+U*.12*Math.sin(A*Ir*g.frequency)*k/A;Y=y*P,I=x*P}else if(g.type==="shear"){let P=-y*g.sin+x*g.cos;Y-=U*P*.9*k*g.cos,I-=U*P*.9*k*g.sin}else if(g.type==="smudge")Y-=U*.65*k*g.cos,I-=U*.65*k*g.sin;else if(g.type==="polar"){let P=y*g.cos+x*g.sin,M=-y*g.sin+x*g.cos,X=Math.atan2(M,P),H=U>0?X/Math.PI:Math.cos(P*Math.PI)*(M+1)/2,K=U>0?A*2-1:Math.sin(P*Math.PI)*(M+1)/2,v=H*g.cos-K*g.sin,R=H*g.sin+K*g.cos;Y+=(v-y)*Math.abs(U)*k,I+=(R-x)*Math.abs(U)*k}else if(g.type==="fragment"){let P=Math.floor((y*g.cos+x*g.sin)*g.frequency),M=Math.floor((-y*g.sin+x*g.cos)*g.frequency),X=(ti(P,M)-.5)*U*.5*k,H=(ti(M+71,P-31)-.5)*U*.5*k;Y+=X*g.cos-H*g.sin,I+=X*g.sin+H*g.cos}m=g.x+Y*g.radius/s,d=g.y+I*g.radius/h}let c=(f*e+u)*2;this.coordinates[c]=m*e-.5,this.coordinates[c+1]=d*r-.5}this.geometry=a}this.output.length!==t.length&&(this.output=new Uint8ClampedArray(t.length));let o=t===this.output?t.slice():t,l=this.edge==="transparent"?_r:De;for(let s=0,h=0;s<t.length;s+=4,h+=2){l(o,e,r,this.coordinates[h],this.coordinates[h+1],this.sampled);for(let f=0;f<4;f++)this.output[s+f]=this.sampled[f]}return this.output}clear(){this.coordinates=new Float32Array(0),this.output=new Uint8ClampedArray(0),this.geometry=""}};var Lr=["stipple","engraving","crosshatch","woodblock","risograph","pointillism"];function We(n){return Lr.includes(n)}var rr={density:1,weight:1,angle:-35,roughness:.35,invert:!1,secondaryInk:"#ec6752",registration:.2,seed:7};function ir(n){let t=n&&typeof n=="object"&&!Array.isArray(n)?n:{},e=(r,i,a)=>{let o=t[r];return typeof o=="number"&&Number.isFinite(o)?Math.max(i,Math.min(a,o)):rr[r]};return{density:e("density",0,2),weight:e("weight",.25,2),angle:e("angle",-180,180),roughness:e("roughness",0,1),invert:t.invert===!0,secondaryInk:typeof t.secondaryInk=="string"&&/^#[\\da-f]{6}$/i.test(t.secondaryInk)?t.secondaryInk:rr.secondaryInk,registration:e("registration",0,1),seed:Math.round(e("seed",0,65535))}}var He=Math.PI*2,ei=n=>Math.max(0,Math.min(1,n)),ar=.1,ri=n=>Math.max(-ar,Math.min(1+ar,n)),Ki=Float32Array.from({length:2048},(n,t)=>Math.sin(t/2048*He)),ii=n=>Ki[Math.floor(n*(2048/He))&2047];function nr(n,t,e){let r=Math.imul(n,374761393)^Math.imul(t,668265263)^Math.imul(e,1442695041);return r=Math.imul(r^r>>>13,1274126177),((r^r>>>16)>>>0)/4294967296}function Dr(n){let t=ir(n),{density:e,weight:r,angle:i,roughness:a,invert:o,secondaryInk:l,registration:s,seed:h}=t,f=i*Math.PI/180,m=[f,f+Math.PI/2,f+Math.PI/4].map(b=>[Math.cos(b),Math.sin(b)]),d=new Float32Array(6);function c(b,g,y,x,S,A,k,U,Y=!1){if(k<=0)return;let[I,P]=m[U],M=-P,X=I,H=M*(g+.5)+X*(y+.5),K=(Math.abs(M)+Math.abs(X))*.5,v=Y?1:.5,R=Math.ceil((H-K)/v),G=Math.floor((H+K)/v),q=Math.min(v*.94,v*.72*k*r);b.lineWidth=A*q,b.beginPath();for(let C=R;C<=G;C++){let E=C*v-H,w=.5+M*E,F=.5+X*E,B=-2,Z=2;if(Math.abs(I)>1e-8){let et=-w/I,N=(1-w)/I;B=Math.max(B,Math.min(et,N)),Z=Math.min(Z,Math.max(et,N))}else if(w<0||w>1)continue;if(Math.abs(P)>1e-8){let et=-F/P,N=(1-F)/P;B=Math.max(B,Math.min(et,N)),Z=Math.min(Z,Math.max(et,N))}else if(F<0||F>1)continue;if(!(Z<=B))if(Y&&(B-=ar,Z+=ar),!Y)b.moveTo(x+(w+I*B)*A,S+(F+P*B)*A),b.lineTo(x+(w+I*Z)*A,S+(F+P*Z)*A);else{for(let et=0;et<6;et++){let N=B+(Z-B)*et/5,tt=I*(g+w+I*N)+P*(y+F+P*N);d[et]=ii(tt*5.3+C*1.9+h)*.5+ii(tt*13.1+C)*.25}for(let et=0;et<2;et++)for(let N=0;N<6;N++){let tt=B+(Z-B)*(et?5-N:N)/5,dt=d[et?5-N:N],lt=q*.5*(1+a*dt*.5)*(et?-1:1),St=x+ri(w+I*tt+M*lt)*A,Et=S+ri(F+P*tt+X*lt)*A;!et&&!N?b.moveTo(St,Et):b.lineTo(St,Et)}b.closePath()}}Y?b.fill():b.stroke()}return{settings:t,paint(b,g,y,x,S,A,k,U,Y,I,P,M,X){let H=ei((o?1-U:U)*e);if(H<=0||b.globalAlpha<=0)return;b.fillStyle=Y,b.strokeStyle=Y;let K=nr(y,x,h);if(g==="engraving"||g==="crosshatch"||g==="woodblock"){let v=H*(1-a*K*.3);g==="woodblock"?c(b,y,x,S,A,k,Math.ceil(v*5)/5,0,!0):(c(b,y,x,S,A,k,v,0),g==="crosshatch"&&(c(b,y,x,S,A,k,Math.max(0,v*1.5-.3),1),c(b,y,x,S,A,k,Math.max(0,v*2-1.2),2)))}else if(g==="risograph"){let v=X==="source"?ei(.5+(I-M)/510):.5,R=s*.38*k,G=k*Math.min(.48,.44*Math.sqrt(H)*r);b.beginPath(),b.arc(S+k*.5,A+k*.5,G*Math.sqrt(.35+(1-v)*.65),0,He),b.fill(),b.globalCompositeOperation="multiply",b.fillStyle=l;let q=1-a*nr(y,x,h+13)*.3;b.beginPath(),b.arc(S+k*.5+R*m[0][0],A+k*.5+R*m[0][1],G*Math.sqrt(.3+v*.7)*q,0,He),b.fill(),b.globalCompositeOperation="source-over"}else{let v=b.fillEllipse;g==="stipple"&&b.beginPath();for(let R=0;R<4;R++){let G=nr(y*2+R%2,x*2+(R>>1),h),q=nr(y,x,h+R*11+1),C=S+((R%2+.5)/2+(G-.5)*a*.28)*k,E=A+(((R>>1)+.5)/2+(q-.5)*a*.28)*k,w=Math.min(C-S,S+k-C,E-A,A+k-E,k*Math.min(.245,.21*r*Math.sqrt(H)*(1-a*G*.35)));if(g==="stipple")b.moveTo(C+w,E),b.arc(C,E,w,0,He);else{let F=(G-.5)*a*64;if(v&&X!=="accent"){let B=Math.round(I+F);v(C,E,w,w*.64,G*Math.PI,B,X==="source"?Math.round(P-F*.4):B,X==="source"?Math.round(M-F):B);continue}X==="source"?b.fillStyle=`rgb(${Math.round(I+F)},${Math.round(P-F*.4)},${Math.round(M-F)})`:X==="gray"?b.fillStyle=`rgb(${Math.round(I+F)},${Math.round(I+F)},${Math.round(I+F)})`:b.fillStyle=Y,b.beginPath(),b.ellipse(C,E,w,w*.64,G*Math.PI,0,He),b.fill()}}g==="stipple"&&b.fill()}}}}var Vi=new Set(["none","floyd-steinberg","atkinson","stucki","sierra","sierra-lite","burkes","jarvis"]);function ni(n){return n.style==="dither"&&(n.dither.motion==="shimmer"||n.dither.motion==="drift"&&n.dither.amount>0&&!Vi.has(n.dither.algorithm))}function ai(n){return n.motion.type!=="none"&&(n.motion.amount??1)>0}var oi={caustics:"sheen",grain:"shimmer",trace:"relight",tidal:"current",weave:"current",breeze:"current",reform:"develop",print:"develop",unfold:"develop"},Ur=[{value:"none",mode:"none",group:"Still",label:"Off",description:"Keep the image still. Hover stays available."},{value:"relight",mode:"relight",group:"Light",label:"Relight",description:"A key light circles the subject and models its own relief, like moving a lamp around a sculpture."},{value:"sheen",mode:"sheen",group:"Light",label:"Specular sweep",description:"One slow pass of light glances across the highlights and follows their form, then rests."},{value:"glow",mode:"glow",group:"Light",label:"Highlight bloom",description:"The brightest areas breathe a soft halo into their surroundings. Shadows stay deep."},{value:"shimmer",mode:"shimmer",group:"Light",label:"Glints",description:"Sparse glints on bright fine detail, like light on water, metal or an eye. Everything else holds still."},{value:"parallax",mode:"parallax",group:"Depth",label:"Parallax",description:"A slow camera drift: the subject moves against its background, read from the photo\\u2019s own depth cues."},{value:"push",mode:"push",group:"Depth",label:"Slow push",description:"A gentle push toward the subject and back, with nearer areas moving slightly more."},{value:"focus",mode:"focus",group:"Depth",label:"Focus pull",description:"Focus racks from the subject to the background and back; the characters soften out of focus."},{value:"mist",mode:"mist",group:"Atmosphere",label:"Mist",description:"Soft mist drifts through the distance and plain areas, leaving the subject clear."},{value:"current",mode:"current",group:"Atmosphere",label:"Drift",description:"Water swells and glints, falls stream down, sky and clouds drift slowly, like a cinemagraph. Subjects and buildings hold still."},{value:"develop",mode:"develop",group:"Reveal",label:"Develop",description:"The image holds, fades, then develops back in from its highlights to its shadows, like a print in the tray."}];function li(n){let t=n&&Object.prototype.hasOwnProperty.call(oi,n)?oi[n]:n;return Ur.find(e=>e.value===t||e.mode===t)?.mode??"none"}var je=n=>Math.max(0,Math.min(1,n)),Yt=(n,t,e)=>{let r=je((e-n)/(t-n));return r*r*(3-2*r)},or=(n,t)=>{let e=52.9829189*((n*.06711056+t*.00583715)%1);return e-Math.floor(e)};function Hr(n,t,e,r,i,a=.5,o,l=0){if(i[0]=i[1]=i[2]=0,i[3]=1,n==="none")return i;a=je(a);let s=o?o[l]:a,h=o?o[l+1]:.5+.5*je(1-Math.hypot(t-.5,e-.55)*2),f=o?o[l+2]:Yt(.55,1,a)**2,u=o?o[l+3]:.5,m=o?o[l+4]:0,d=o?o[l+5]:0,c=r*Math.PI/6,b=(r%12+12)%12,g=Yt(0,.12,Math.min(t,1-t,e,1-e));if(n==="relight"){let y=c+.6,x=Math.cos(y),S=Math.sin(y),A=Math.max(-1,Math.min(1,m*x+d*S))+(x*(t-.5)+S*(e-.5))*.35;i[2]=A*.2*(.3+.7*Yt(.04,.3,s)*(1-.6*Yt(.82,1,a)))}else if(n==="sheen"){let y=-.35+1.9*Yt(0,8,b),x=(t*.75+e*.45)/1.2+(m*.75+d*.45)*.05,S=Math.exp(-(((x-y)/.12)**2));i[2]=S*Yt(.3,.8,s)*(1-.5*Yt(.9,1,a))*.45}else if(n==="glow"){let y=.5-.5*Math.cos(c),x=1-.8*y;i[2]=.2*Yt(x-.3,x+.02,f)*Math.sqrt(f)*(1-.65*a)+.05*y*Yt(.6,.95,a)}else if(n==="shimmer"){let y=or(Math.floor(t*160),Math.floor(e*100))*Math.PI*2,x=Math.pow(.5+.5*Math.cos(c*2+y),28);i[2]=x*Yt(.5,.88,a)*(.35+.65*Yt(.1,.55,u))*.42}else if(n==="parallax"){let y=h-.45;i[0]=y*16*Math.sin(c)*g,i[1]=y*7*Math.sin(c*2)*g}else if(n==="push"){let y=.045*(.5-.5*Math.cos(c))*(.7+.6*h)*960,x=o?o[l+6]:.5,S=o?o[l+7]:.5;i[0]=(t-x)*y,i[1]=(e-S)*y}else if(n==="focus"){let y=Math.sin(c),x=y*y*Yt(.35,.85,y>=0?1-h:h);i[2]=(s-a)*x*.75}else if(n==="mist"){let y=Math.pow(1-h,1.5)*(1-.6*u),x=Math.sin(t*4.1-c+Math.sin(e*3.3+c)*.9)*.5+Math.sin(t*7.3+e*2.1-c*2+Math.sin(t*2.7-e*5.1+c)*1.1)*.3+Math.sin(e*5.7-t*1.9+c)*.2;i[2]=Yt(-.3,.9,x)*y*.16*(1-.55*a)}else if(n==="current"){let y=o?.[l+8]??0,x=o?.[l+9]??0,S=o?.[l+10]??0,A=Yt(0,.06,Math.min(t,1-t,e,1-e)),k=o?0:(1-.4*u)*(1-.8*h)*g,U=H=>e*14-H+Math.sin(t*3+H)*1.5,Y=H=>e*16+t*2-H,I=H=>e*29-t*3-H*2,P=H=>t*1.7+e*2.3-H,M=H=>e*26+Math.sin(t*40)*1.5-H*2;i[0]=(Math.sin(U(c))-Math.sin(U(0))+(Math.sin(t*5-e*3+c)-Math.sin(t*5-e*3))*.43)*7*k+((Math.sin(Y(c))-Math.sin(Y(0)))*3.5+(Math.sin(I(c))-Math.sin(I(0)))*1.5)*y*A+(Math.sin(P(c))-Math.sin(P(0)))*5*x*A,i[1]=(Math.sin(t*11+c)-Math.sin(t*11))*2*k+(Math.cos(Y(c))-Math.cos(Y(0)))*.8*y*A+(Math.sin(M(c))-Math.sin(M(0)))*12*S*A;let X=Math.pow(.5+.5*Math.cos(c*2+t*9-e*4+or(Math.floor(t*160),Math.floor(e*100))*6.2831853),24)-Math.pow(.5+.5*Math.cos(t*9-e*4+or(Math.floor(t*160),Math.floor(e*100))*6.2831853),24);i[2]=(Math.cos(U(c))-Math.cos(U(0)))*.03*k+(X*Yt(.5,.85,a)*.3+(Math.cos(Y(c))-Math.cos(Y(0)))*.025)*y*A+(Math.cos(M(c))-Math.cos(M(0)))*.08*S*A}else if(n==="develop"){let y=Yt(7,8.5,b),x=je((b-8.5)/3.5),S=b<8.5?1-y:Yt(0,1,(x*1.45-(1-a)+(or(Math.floor(t*160),Math.floor(e*100))-.5)*.06)/.3);i[2]=-(1-S)*.3,i[3]=1-(1-S)*.9}return i}var hi=n=>n==="relight"||n==="sheen"||n==="glow"||n==="shimmer"||n==="mist";function si(n){let t=Math.floor(n),e=Math.max(0,Math.min(1,(n-t-.2)/.6));return t+e*e*(3-2*e)}function Or(n,t,e,r,i,a){return a[0]=si(Math.max(0,Math.min(r-1,t-n[0]/960*r))),a[1]=si(Math.max(0,Math.min(i-1,e-n[1]/960*i))),a}function Nr(n,t){let e=Math.max(0,Math.min(2,Number.isFinite(t)?t:1));return n[0]*=e,n[1]*=e,n[2]*=e,n[3]=je(1+(n[3]-1)*e),n}var qr=n=>n==="subject"||n==="outside"?n:"all";function Pt(n,t,e,r,i){if(!(i<1))for(let a=0;a<2;a++){for(let o=0;o<r;o++){let l=0,s=o*e;for(let h=-i;h<=i;h++)l+=n[s+Math.max(0,Math.min(e-1,h))];for(let h=0;h<e;h++)t[s+h]=l/(i*2+1),l+=n[s+Math.min(e-1,h+i+1)]-n[s+Math.max(0,h-i)]}for(let o=0;o<e;o++){let l=0;for(let s=-i;s<=i;s++)l+=t[Math.max(0,Math.min(r-1,s))*e+o];for(let s=0;s<r;s++)n[s*e+o]=l/(i*2+1),l+=t[Math.min(r-1,s+i+1)*e+o]-t[Math.max(0,s-i)*e+o]}}}var zr=new Float32Array(0);function sr(n,t,e,r,i){let a=t*e,o=i&&i.width===t&&i.height===e?i:{width:t,height:e,subject:new Float32Array(a),depth:new Float32Array(a),key:"none"},{subject:l,depth:s}=o,h=0;for(let c=0;c<a;c++)n[c*4+3]<250&&h++;let f=c=>(n[c*4]*.2126+n[c*4+1]*.7152+n[c*4+2]*.0722)/255,u="none",m=0;if(h>a*.01)u="alpha";else if(r)u="mask";else{let c=0,b=0,g=0,y=Math.max(1,Math.round(Math.min(t,e)*.03));for(let S=0;S<e;S++)for(let A=0;A<t;A++){if(A>=y&&S>=y&&A<t-y&&S<e-y)continue;let k=f(S*t+A);c+=k,b+=k*k,g++}m=c/Math.max(1,g),Math.sqrt(Math.max(0,b/Math.max(1,g)-m*m))<.07&&(u="ground")}for(let c=0;c<a;c++){let b=n[c*4+3]/255,g=f(c),y=1;if(u==="alpha")y=b;else if(u==="ground"){let x=Math.max(0,Math.min(1,(Math.abs(g-m)-.035)/.12));y=x*x*(3-2*x)}l[c]=y*(r?Math.max(0,Math.min(1,r[c])):1),s[c]=g*b}o.key=u,zr.length<a&&(zr=new Float32Array(a));let d=zr;return Pt(l,d,t,e,Math.max(1,Math.round(Math.min(t,e)*.02))),Pt(s,d,t,e,Math.max(1,Math.round(Math.min(t,e)*.035))),o}function ci(n,t,e="ground"){return e==="none"?1:n==="subject"?t:n==="outside"?1-t:1}function ui(n,t,e,r){let i=n[t],a=n.width,o=n.height,l=Math.max(0,Math.min(a-1.001,e*(a-1))),s=Math.max(0,Math.min(o-1.001,r*(o-1))),h=Math.floor(l),f=Math.floor(s),u=l-h,m=s-f,d=f*a+h,c=Math.min(o-1,f+1)*a+h,b=h+1<a?1:0;return(i[d]*(1-u)+i[d+b]*u)*(1-m)+(i[c]*(1-u)+i[c+b]*u)*m}var we=11,Zt=n=>Math.max(0,Math.min(1,n)),j=(n,t,e)=>{let r=Zt((e-n)/(t-n));return r*r*(3-2*r)};function ne(n,t,e=256){let r=0;for(let l=0;l<n.length;l++)n[l]>r&&(r=n[l]);if(r<=0)return 0;let i=new Uint32Array(e);for(let l=0;l<n.length;l++)i[Math.min(e-1,Math.floor(Math.max(0,n[l])/r*e))]++;let a=0,o=n.length*t;for(let l=0;l<e;l++)if(a+=i[l],a>=o)return(l+1)/e*r;return r}var _i=12e3,Xr=class{constructor(t){this.n=t;this.arrays=[];this.next=0}take(t){this.next===this.arrays.length&&this.arrays.push(new Float32Array(this.n));let e=this.arrays[this.next++];return t?e.set(t):e.fill(0),e}reset(){this.next=0}},lr=null;function Ji(n,t,e,r,i,a,o,l,s){let h=i*a,f=s.take(),u=v=>(Ae(v,f,i,a,o),v),m=(v,R)=>{let G=s.take();for(let q=0;q<h;q++)G[q]=v[q]*R[q];return u(G)},d=u(s.take(t)),c=u(s.take(e)),b=u(s.take(r)),g=u(s.take(n)),y=m(t,t),x=m(t,e),S=m(t,r),A=m(e,e),k=m(e,r),U=m(r,r),Y=m(t,n),I=m(e,n),P=m(r,n),M=s.take(),X=s.take(),H=s.take(),K=s.take();for(let v=0;v<h;v++){let R=Y[v]-d[v]*g[v],G=I[v]-c[v]*g[v],q=P[v]-b[v]*g[v],C=y[v]-d[v]*d[v]+l,E=x[v]-d[v]*c[v],w=S[v]-d[v]*b[v],F=A[v]-c[v]*c[v]+l,B=k[v]-c[v]*b[v],Z=U[v]-b[v]*b[v]+l,et=F*Z-B*B,N=w*B-E*Z,tt=E*B-w*F,dt=C*Z-w*w,lt=E*w-C*B,St=C*F-E*E,Et=C*et+E*N+w*tt,Lt=Math.abs(Et)>1e-12?1/Et:0;M[v]=(et*R+N*G+tt*q)*Lt,X[v]=(N*R+dt*G+lt*q)*Lt,H[v]=(tt*R+lt*G+St*q)*Lt,K[v]=g[v]-M[v]*d[v]-X[v]*c[v]-H[v]*b[v]}u(M),u(X),u(H),u(K);for(let v=0;v<h;v++)n[v]=M[v]*t[v]+X[v]*e[v]+H[v]*r[v]+K[v]}function Ae(n,t,e,r,i){let a=i*2+1;for(let o=0;o<r;o++){let l=o*e,s=0;for(let h=-i;h<=i;h++)s+=n[l+Math.max(0,Math.min(e-1,h))];for(let h=0;h<e;h++)t[l+h]=s/a,s+=n[l+Math.min(e-1,h+i+1)]-n[l+Math.max(0,h-i)]}for(let o=0;o<e;o++){let l=0;for(let s=-i;s<=i;s++)l+=t[Math.max(0,Math.min(r-1,s))*e+o];for(let s=0;s<r;s++)n[s*e+o]=l/a,l+=t[Math.min(r-1,s+i+1)*e+o]-t[Math.max(0,s-i)*e+o]}}function Gr(n,t,e,r,i,a,o){let l=e*r,s=o.take(),h=o.take(t),f=o.take(n),u=o.take(),m=o.take();for(let d=0;d<l;d++)u[d]=t[d]*t[d],m[d]=t[d]*n[d];Ae(h,s,e,r,i),Ae(f,s,e,r,i),Ae(u,s,e,r,i),Ae(m,s,e,r,i);for(let d=0;d<l;d++){let c=(m[d]-h[d]*f[d])/(u[d]-h[d]*h[d]+a);u[d]=c,m[d]=f[d]-c*h[d]}Ae(u,s,e,r,i),Ae(m,s,e,r,i);for(let d=0;d<l;d++)n[d]=u[d]*t[d]+m[d]}function Br(n,t,e,r,i,a=2){for(let o=0;o<a;o++){for(let l=0;l<r;l++)for(let s=0;s<e;s++){let h=l*e+s,f=n[h];s>0&&(f=Math.max(f,Math.min(t[h],n[h-1]*i))),l>0&&(f=Math.max(f,Math.min(t[h],n[h-e]*i),s>0?Math.min(t[h],n[h-e-1]*i):0,s<e-1?Math.min(t[h],n[h-e+1]*i):0)),n[h]=f}for(let l=r-1;l>=0;l--)for(let s=e-1;s>=0;s--){let h=l*e+s,f=n[h];s<e-1&&(f=Math.max(f,Math.min(t[h],n[h+1]*i))),l<r-1&&(f=Math.max(f,Math.min(t[h],n[h+e]*i),s>0?Math.min(t[h],n[h+e-1]*i):0,s<e-1?Math.min(t[h],n[h+e+1]*i):0)),n[h]=f}}}function hr(n,t,e,r,i){for(let a=0;a<r;a++)for(let o=0;o<e;o++){let l=1;for(let s=Math.max(0,o-i);s<=Math.min(e-1,o+i);s++)l=Math.min(l,n[a*e+s]);t[a*e+o]=l}for(let a=0;a<r;a++)for(let o=0;o<e;o++){let l=1;for(let s=Math.max(0,a-i);s<=Math.min(r-1,a+i);s++)l=Math.min(l,t[s*e+o]);n[a*e+o]=l}}function Zi(n,t,e,r,i){let a=e*r,o=Math.min(e,r),l=i.take(),s=i.take(),h=i.take(),f=i.take(),u=i.take();for(let p=0;p<a;p++){let W=n[p*4+3]/255;u[p]=W,l[p]=t[p*4]/255*W,s[p]=t[p*4+1]/255*W,h[p]=t[p*4+2]/255*W,f[p]=(n[p*4]*.299+n[p*4+1]*.587+n[p*4+2]*.114)/255*W}let m=i.take(),d=(p,W)=>{let T=i.take(p);return Pt(T,m,e,r,W),T},c=Math.max(2,Math.round(o*.04)),b=Math.max(c+2,Math.round(o*.12)),g=Math.max(2,Math.round(o*.05)),y=d(f,1),x=d(f,c),S=d(f,b),A=i.take(),k=i.take(),U=i.take(),Y=i.take(),I=i.take();for(let p=0;p<r;p++)for(let W=0;W<e;W++){let T=p*e+W;A[T]=Math.abs(f[T]-y[T]),k[T]=Math.abs(y[T]-x[T]),U[T]=Math.abs(x[T]-S[T]),Y[T]=Math.abs(f[p*e+Math.min(e-1,W+1)]-f[p*e+Math.max(0,W-1)]),I[T]=Math.abs(f[Math.min(r-1,p+1)*e+W]-f[Math.max(0,p-1)*e+W])}Pt(A,m,e,r,g),Pt(k,m,e,r,g),Pt(U,m,e,r,g),Pt(Y,m,e,r,2),Pt(I,m,e,r,2);let P=Math.max(.01,ne(A,.9)+ne(k,.9)),M=d(l,1),X=d(s,1),H=d(h,1),K=i.take(),v=i.take(),R=i.take(),G=0;for(let p=0;p<a;p++){let W=M[p],T=X[p],Q=H[p],V=Math.max(W,T,Q),At=Math.min(W,T,Q),Rt=V-At;R[p]=V,v[p]=V>.001?Rt/V:0,G+=Rt;let Ht=0;Rt>1e-4&&(Ht=V===W?((T-Q)/Rt+6)%6:V===T?(Q-W)/Rt+2:(W-T)/Rt+4),K[p]=Ht*60}let q=j(.02,.07,G/a),C=Math.max(2,Math.round(r*.06)),E=new Float32Array(r);for(let p=0;p<r;p++){let W=0;for(let T=0;T<e;T++)W+=A[p*e+T]+k[p*e+T];E[p]=W/e}let w=.5,F=0;for(let p=Math.max(C,Math.round(r*.12));p<=Math.min(r-C,Math.round(r*.88));p++){let W=0,T=0,Q=0,V=0;for(let nt=0;nt<e;nt++){let xt=0,bt=0,Vt=0,Nt=0,wt=0,Wt=0;for(let mt=1;mt<=C;mt++){let ot=(p-mt)*e+nt,Ut=(p+mt-1)*e+nt;xt+=M[ot],bt+=X[ot],Vt+=H[ot],Nt+=M[Ut],wt+=X[Ut],Wt+=H[Ut]}let Ft=(Math.abs(xt-Nt)+Math.abs(bt-wt)+Math.abs(Vt-Wt))/C;W+=Ft,T+=Ft>.12?1:0}let At=Math.max(2,Math.round(r*.15)),Rt=Math.max(0,p-At),Ht=Math.min(r,p+At);for(let nt=Rt;nt<p;nt++)Q+=E[nt];for(let nt=p;nt<Ht;nt++)V+=E[nt];Q/=p-Rt,V/=Ht-p;let _=j(-.05,.3,(V-Q)/(V+Q+1e-4)),$=j(.08,.35,W/e)*(T/e)*_;$>F&&(F=$,w=p/r)}let B=j(.15,.45,F),Z=i.take(),et=i.take(),N=i.take();for(let p=0;p<a;p++)Z[p]=Math.min(l[p],s[p],h[p]);hr(Z,m,e,r,1),Pt(Z,m,e,r,c);for(let p=0;p<a;p++)et[p]=k[p]+U[p];let tt=0,dt=0,lt=0;for(let p=0;p<a;p++)tt+=M[p],dt+=X[p],lt+=H[p];tt/=a,dt/=a,lt/=a;let St=d(M,c),Et=d(X,c),Lt=d(H,c),Tt=d(M,b),yt=d(X,b),ee=d(H,b);for(let p=0;p<a;p++){let W=Math.hypot(St[p]-tt,Et[p]-dt,Lt[p]-lt),T=Math.hypot(St[p]-Tt[p],Et[p]-yt[p],Lt[p]-ee[p]);N[p]=(W+T*1.5)*(.4+.6*v[p]*q+.4*(1-q))}let ct=i.take(),Qt=i.take(),de=i.take(),kt=i.take(),L=i.take(),z=i.take(),O=i.take(),rt=i.take(),J=i.take(),pt=i.take();for(let p=0;p<r;p++)for(let W=0;W<e;W++)pt[p*e+W]=Math.abs(f[Math.min(r-1,p+1)*e+W]-f[Math.max(0,p-1)*e+W]);Pt(pt,m,e,r,1);for(let p=0;p<r;p++)for(let W=0;W<e;W++){let T=p*e+W,Q=(p+.5)/r,V=K[T],At=v[T]*q,Rt=R[T],Ht=A[T]+k[T],_=j(175,200,V)*(1-j(250,275,V))*j(.08,.25,At),$=(1-j(45,65,V)+j(290,330,V))*j(.2,.45,At)*j(.3,.55,Rt),nt=(1-j(.15,.35,At))*j(.45,.7,Rt)*B,xt=(1-j(.08,.2,Rt))*B,bt=B>.3?1-j(w,w+.1,Q):1-j(.4,.8,Q),Vt=1-j(.02,.06,Ht),Nt=1-j(.03,.09,Ht);Qt[T]=Math.max(_*Vt,xt*.7*(1-j(.008,.025,Ht)),$*Nt*.9)*bt,de[T]=Math.max(Qt[T],nt*Vt*bt),ct[T]=p===0?Qt[T]:0,kt[T]=j(150,172,V)*(1-j(232,250,V))*j(.25,.45,At),O[T]=j(1.3,2.2,(Y[T]+.004)/(I[T]+.004))*j(.35,.55,y[T])*(1-j(.1,.18,v[T]*q))*j(.025,.07,Ht)*j(.025,.045,pt[T]);let wt=1-j(.18,.4,At),Wt=j(.55,.8,Rt)*j(.05,.12,Ht);L[T]=Math.max(kt[T],wt*.85,Wt*.8)}Br(ct,Qt,e,r,.995,1),Br(ct,de,e,r,.8,1);let Mt=0;for(let p=0;p<a;p++)Mt+=ct[p];let Dt=Mt>a*.04&&B>.3;if(Dt)for(let p=0;p<r;p++)for(let W=0;W<e;W++)kt[p*e+W]*=j(w,w+.05,(p+.5)/r);if(Dt){let p=i.take(),W=i.take(),T=i.take();for(let _=0;_<a;_++)p[_]=St[_]*.299+Et[_]*.587+Lt[_]*.114;for(let _=0;_<r;_++)for(let $=0;$<e;$++)W[_*e+$]=y[Math.min(r-1,_+1)*e+$]-y[Math.max(0,_-1)*e+$];let Q=new Uint8Array(a);for(let _=1;_<r-1;_++)for(let $=0;$<e;$++){let nt=Math.abs(W[_*e+$]),xt=nt>.03;for(let bt=-3;bt<=3&&xt;bt++)bt&&_+bt>=0&&_+bt<r&&Math.abs(W[(_+bt)*e+$])>nt&&(xt=!1);Q[_*e+$]=xt?1:0}let V=(_,$,nt,xt=!0)=>{let bt=St[$]+Et[$]+Lt[$]+.05,Vt=St[nt]+Et[nt]+Lt[nt]+.05,Nt=Math.abs(St[$]/bt-St[nt]/Vt)+Math.abs(Et[$]/bt-Et[nt]/Vt)+Math.abs(Lt[$]/bt-Lt[nt]/Vt),wt=Math.min(Math.abs(K[$]-K[nt]),360-Math.abs(K[$]-K[nt])),Wt=Math.max(1-j(.1,.25,Nt),(1-j(15,35,wt))*j(.15,.3,Math.min(v[$],v[nt]))),Ft=Math.max(j(2,3,(I[$]+.004)/(Y[$]+.004))*j(.015,.04,A[$]+k[$])*j(.4,.55,A[$]/(A[$]+k[$]+1e-4)),1-j(.12,.25,p[$]));return Wt*(xt?Ft:1)*(1-j(p[nt]*.82+.02,p[nt]*1.02+.05,p[$]))},At=0,Rt=0;for(let _=Math.max(3,Math.round(r*Math.max(.25,w)));_<Math.round(r*.88);_++){let $=0;for(let xt=0;xt<e;xt++)(Q[(_-1)*e+xt]||Q[_*e+xt]||Q[(_+1)*e+xt])&&$++;if($<e*.5)continue;let nt=0;for(let xt=_+1;xt<Math.min(r,2*_);xt++)for(let bt=0;bt<e;bt++)nt+=V(_,xt*e+bt,(2*_-xt)*e+bt);nt>Rt&&(Rt=nt,At=_)}let Ht=j(.05,.1,Rt/a);if(Ht>0)for(let _=At+1;_<Math.min(r,2*At);_++)for(let $=0;$<e;$++){let nt=_*e+$;rt[nt]=V(At,nt,(2*At-_)*e+$)*Ht,J[nt]=V(At,nt,(2*At-_)*e+$,!1)*Ht,T[nt]=rt[nt]}Pt(T,m,e,r,1);for(let _=0;_<a;_++)rt[_]=Math.max(rt[_],T[_]),kt[_]=Math.max(kt[_],rt[_])}let Bt=d(kt,b);for(let p=0;p<a;p++)kt[p]*=j(.15,.35,Bt[p]);let ut=d(kt,c);for(let p=0;p<a;p++){kt[p]*=1-Qt[p]*.8;let W=Math.min(Math.abs(K[p]-200),360-Math.abs(K[p]-200));z[p]=j(.28,.45,v[p]*q)*j(55,80,W)*(1-j(.3,.6,J[p]))}let gt=d(z,c);for(let p=0;p<a;p++)z[p]=Math.max(z[p]*(1-(1-j(.15,.3,gt[p]))*j(.55,.7,R[p])*j(.5,.65,v[p])),1-u[p]),L[p]=Math.min(Math.max(L[p],J[p]*.9),Math.max(kt[p],j(.25,.6,ut[p])))*(1-ct[p])*(1-z[p]);Br(kt,L,e,r,.97);let zt=i.take(O),re=Math.max(2,Math.round(r*.12));for(let p=0;p<e;p++){let W=0;for(let T=-re;T<=re;T++)W+=O[Math.max(0,Math.min(r-1,T))*e+p];for(let T=0;T<r;T++)zt[T*e+p]=W/(re*2+1),W+=O[Math.min(r-1,T+re+1)*e+p]-O[Math.max(0,T-re)*e+p]}Pt(zt,m,e,r,1);for(let p=0;p<a;p++)O[p]=j(.2,.45,zt[p])*j(.2,.5,O[p]+zt[p]*.5)*(1-ct[p]);Gr(ct,f,e,r,Math.max(2,Math.round(o*.04)),.002,i),Gr(kt,f,e,r,Math.max(2,Math.round(o*.04)),.002,i),Gr(O,f,e,r,Math.max(2,Math.round(o*.03)),.002,i),Pt(z,m,e,r,1);for(let p=0;p<a;p++)ct[p]=j(.3,.7,ct[p])*u[p],O[p]=j(.3,.7,O[p])*u[p]*(1-ct[p]),kt[p]=j(.3,.7,kt[p])*(1-ct[p])*(1-O[p])*(1-j(.15,.4,z[p]));hr(ct,m,e,r,2),hr(kt,m,e,r,2),hr(O,m,e,r,1),Pt(ct,m,e,r,1),Pt(kt,m,e,r,1),Pt(O,m,e,r,1);let Ne=1/Math.max(.02,ne(N,.97)),wr=1/Math.max(.01,ne(et,.9)),Ze=ne(Z,.97),ze=ne(Z,.1),ht=j(.06,.25,Ze-ze),it=i.take();for(let p=0;p<r;p++)for(let W=0;W<e;W++){let T=p*e+W,Q=(W+.5)/e,V=(p+.5)/r,At=Math.max(ct[T],kt[T]),Rt=A[T]+k[T]+U[T],Ht=Zt(((A[T]+k[T]*.6)/(Rt+.004)-.25)/.55)*.6+Zt((A[T]+k[T])/P)*.4,_=j(.04,.35,Rt/P)*(1-At),$=Zt((Z[T]-ze)/Math.max(.05,Ze-ze))*.55+(1-Zt(et[T]*wr))*.25+Zt((H[T]-M[T])*2+.3)*.2*q,nt=ht*j(.12,.35,x[T])*(.4+.6*B),xt=V<w?.45:.45+.55*j(0,1,(V-w)/Math.max(.15,1-w)),bt=B*xt+(1-B)*(.5+(V-.5)*.4),Vt=A[T]/(A[T]+k[T]+1e-4),Nt=j(.2,.7,(A[T]+k[T])/P)*(.35+.65*B)*(1-At),wt=1-Zt(Math.hypot((Q-.5)*1.2,V-.52)*1.5),Wt=Zt(N[T]*Ne)*(.55+.45*wt),Ft=.3*_,mt=.25*nt,ot=.12+.45*B,Ut=.12*Nt,ie=.35*(1-.4*B)*(1-At);it[T]=(Ft*Ht+mt*(1-$)+ot*bt+Ut*Zt(1.6-Vt*1.6)+ie*Wt+.08*.5)/(Ft+mt+ot+Ut+ie+.08)*(1-.85*ct[T])*(1-.45*kt[T]*(1-B))}let ce=sr(n,e,r);if(ce.key!=="none")for(let p=0;p<a;p++)it[p]=ce.subject[p]*.7+it[p]*.3;return Pt(it,m,e,r,Math.max(1,Math.round(o*.03))),Ji(it,M,X,H,e,r,Math.max(2,Math.round(o*.07)),.004,i),{depth:it,water:kt,sky:ct,falls:O}}function cr(n,t,e,r,i,a,o){if(t===a&&e===o)return n[i*a+r];let l=Math.max(0,Math.min(t-1,(r+.5)*t/a-.5)),s=Math.max(0,Math.min(e-1,(i+.5)*e/o-.5)),h=Math.min(t-2,Math.floor(l)),f=Math.min(e-2,Math.floor(s)),u=l-h,m=s-f;if(h<0||f<0)return n[Math.round(s)*t+Math.round(l)];let d=f*t+h,c=d+t;return(n[d]*(1-u)+n[d+1]*u)*(1-m)+(n[c]*(1-u)+n[c+1]*u)*m}function mi(n,t,e,r,i=n){let a=t*e,o=r?.length===a*we?r:new Float32Array(a*we);if(!a)return o;let l=Math.min(t,e),s=new Float32Array(a),h=new Float32Array(a),f=new Float32Array(a),u=new Float32Array(a),m=new Float32Array(a),d=new Float32Array(a);for(let C=0;C<a;C++){let E=n[C*4+3]/255;s[C]=(n[C*4]*.299+n[C*4+1]*.587+n[C*4+2]*.114)/255*E}h.set(s),Pt(h,d,t,e,Math.max(1,Math.round(l*.012))),f.set(s),Pt(f,d,t,e,Math.max(1,Math.round(l*.03)));for(let C=0;C<a;C++){u[C]=Math.abs(s[C]-h[C]);let E=Math.max(0,s[C]-.55)/.45;m[C]=E*E}Pt(u,d,t,e,Math.max(1,Math.round(l*.02)));let c=1/Math.max(.02,ne(u,.95));Pt(m,d,t,e,Math.max(1,Math.round(l*.05)));let b=1/Math.max(.03,ne(m,.98)),g=Math.max(1,Math.ceil(Math.sqrt(a/_i))),y=Math.max(1,Math.floor(t/g)),x=Math.max(1,Math.floor(e/g)),S=y*x,A=n,k=i;if(g>1){let C=new Uint8ClampedArray(S*4),E=i===n?C:new Uint8ClampedArray(S*4);for(let w=0;w<x;w++)for(let F=0;F<y;F++){let B=[0,0,0,0,0,0,0];for(let N=w*g;N<(w+1)*g;N++)for(let tt=F*g;tt<(F+1)*g;tt++){let dt=(N*t+tt)*4;for(let lt=0;lt<4;lt++)B[lt]+=n[dt+lt];if(E!==C)for(let lt=0;lt<3;lt++)B[4+lt]+=i[dt+lt]}let Z=(w*y+F)*4,et=g*g;for(let N=0;N<4;N++)C[Z+N]=B[N]/et;if(E!==C){for(let N=0;N<3;N++)E[Z+N]=B[4+N]/et;E[Z+3]=C[Z+3]}}A=C,k=E}lr?.n!==S&&(lr=new Xr(S)),lr.reset();let{depth:U,water:Y,sky:I,falls:P}=Zi(A,k,y,x,lr),M=ne(U,.03),X=ne(U,.97),H=Math.max(.05,X-M),K=0,v=0,R=0,G=new Float32Array(a);for(let C=0;C<e;C++)for(let E=0;E<t;E++){let w=C*t+E,F=w*we,B=Zt((cr(U,y,x,E,C,t,e)-M)/H);o[F+1]=B,o[F+8]=Zt(cr(Y,y,x,E,C,t,e)),o[F+9]=Zt(cr(I,y,x,E,C,t,e)),o[F+10]=Zt(cr(P,y,x,E,C,t,e));let Z=B*B*B*(.25+s[w]);K+=(E+.5)/t*Z,v+=(C+.5)/e*Z,R+=Z,G[w]=Math.hypot(f[C*t+Math.min(t-1,E+1)]-f[C*t+Math.max(0,E-1)],f[Math.min(e-1,C+1)*t+E]-f[Math.max(0,C-1)*t+E])}K=R>0?Math.max(.3,Math.min(.7,K/R)):.5,v=R>0?Math.max(.3,Math.min(.7,v/R)):.5;let q=1/Math.max(.004,ne(G,.97));for(let C=0;C<e;C++)for(let E=0;E<t;E++){let w=C*t+E,F=w*we,B=(f[C*t+Math.min(t-1,E+1)]-f[C*t+Math.max(0,E-1)])*q,Z=(f[Math.min(e-1,C+1)*t+E]-f[Math.max(0,C-1)*t+E])*q;o[F]=f[w],o[F+2]=Math.min(1,m[w]*b),o[F+3]=Math.min(1,u[w]*c),o[F+4]=Math.max(-1,Math.min(1,-B)),o[F+5]=Math.max(-1,Math.min(1,-Z)),o[F+6]=K,o[F+7]=v}return o}var Qi=[{value:"none",label:"Off",group:"Still",description:"Keep the artwork still under the pointer."},{value:"trail",label:"Trail",group:"Change characters",description:"A fluid wake changes character density and settles behind your cursor."},{value:"dissolve",label:"Dissolve",group:"Change characters",description:"Erase a soft path through the characters; the image gradually reforms."},{value:"contour",label:"Contour",group:"Change characters",description:"Fine tonal rings trace your path without moving the grid."},{value:"etch",label:"Emboss",group:"Change characters",description:"Press a light-and-shadow impression into the characters; the grid stays fixed."},{value:"ripple",label:"Ripple rings",group:"Change characters",description:"Expanding light-and-shadow rings follow your stroke. Faster movement excites stronger rings; the grid stays still."},{value:"bleed",label:"Ink bleed",group:"Change characters",description:"Ink wells up where the cursor rests, spreads along the paper grain, then dries back."},{value:"water",label:"Water",group:"Move the image",description:"Soft ripples refract the image and settle after your stroke."},{value:"silk",label:"Silk",group:"Move the image",description:"Directional folds follow the movement of your hand."},{value:"vortex",label:"Vortex",group:"Move the image",description:"A swirling wake curls through the image."},{value:"magnetic",label:"Magnetic Pull",group:"Move the image",description:"The image gathers toward your stroke, then relaxes."},{value:"scatter",label:"Scatter",group:"Move the image",description:"Characters scatter in soft drifts from your stroke, then spring back into place."},{value:"elastic",label:"Elastic",group:"Move the image",description:"Push the image with your stroke; it recoils past its rest once, then settles."},{value:"lens",label:"Lens wake",group:"Move the image",description:"A soft magnifying wake brings details closer, then relaxes back into focus."},{value:"smudge",label:"Smudge",group:"Move the image",description:"Drag the image in the direction of your stroke; a smooth, lingering pull settles without a bounce."},{value:"loupe",label:"Loupe",group:"Follow the cursor",description:"A glass loupe glides after the cursor and magnifies what it covers, easing through a soft rim."},{value:"reveal",label:"Reveal",group:"Follow the cursor",description:"A soft spotlight shows the original photograph through the characters."},{value:"repel",label:"Repel",group:"Follow the cursor",description:"Characters part around the cursor and spring back with one soft rebound when it leaves."},{value:"tilt",label:"Tilt",group:"Follow the cursor",description:"The image leans toward the cursor; bright areas sit nearer and move more, like a parallax card."},{value:"haze",label:"Heat haze",group:"Follow the cursor",description:"A rising shimmer bends the characters above the cursor, livelier while you move."}],fi={rake:"silk"},Fe={radius:{label:"Hover size",min:.1,max:1,step:.05,default:.2},strength:{label:"Hover strength",min:0,max:1,step:.05,default:.55},decay:{label:"Linger",min:0,max:1,step:.05,default:.5}},di={effect:"trail",strength:.55,radius:.2,decay:.5,scope:"all",edgeSafe:!1};function ur(n){if(typeof n=="string")return n in fi?fi[n]:Qi.some(t=>t.value===n)?n:void 0}var $i=["ascii","blocks","braille","dots","lines","cross","diagonal","diamond","mixed","pixel","mosaic","lego","voxel","disco","dither","hex","led","cmyk",...Lr],tn=["none","bayer2","bayer4","bayer8","bayer16","floyd-steinberg","atkinson","stucki","sierra","sierra-lite","burkes","jarvis","halftone","lines","noise","vertical-lines","diagonal-lines","radial","blue-noise"],en=["source-over","multiply","screen","overlay","soft-light","hard-light","color-dodge","color-burn","hue","saturation","color","luminosity"],mr={original:[],gray4:["#000000","#555555","#aaaaaa","#ffffff"],gray8:["#000000","#242424","#494949","#6d6d6d","#929292","#b6b6b6","#dbdbdb","#ffffff"],rgb8:["#000000","#ff0000","#00ff00","#0000ff","#ffff00","#ff00ff","#00ffff","#ffffff"],cyberpunk:["#08081a","#3c1670","#ed299a","#29dfef","#fff7bf"],pastel:["#393448","#a5b4d4","#9ed9c6","#e7aac1","#f5e8be"],mono:["#080808","#f2f2e8"],asciify:["#080808","#625b38","#a19558","#e8b900"],gameboy:["#0f380f","#306230","#8bac0f","#9bbc0f"],cga:["#000000","#55ffff","#ff55ff","#ffffff"],pico8:["#000000","#1d2b53","#7e2553","#008751","#ab5236","#5f574f","#c2c3c7","#fff1e8","#ff004d","#ffa300","#ffec27","#00e436","#29adff","#83769c","#ff77a8","#ffccaa"],c64:["#000000","#ffffff","#880000","#aaffee","#cc44cc","#00cc55","#0000aa","#eeee77","#dd8855","#664400","#ff7777","#333333","#777777","#aaff66","#0088ff","#bbbbbb"],amber:["#100b00","#5f3b00","#c98014","#ffd17c"],ice:["#081b29","#25586e","#69a6b3","#d9ece7"],risograph:["#f4ebd0","#f2594b","#2853a5","#29232e"],sepia:["#201b17","#6b5039","#b49868","#f6e6c5"],nord:["#2e3440","#4c566a","#88c0d0","#eceff4"],dusk:["#211b35","#654271","#c3788c","#f5c9a3"],forest:["#101f1b","#355747","#87a16f","#e4e3ba"],ocean:["#071b33","#17577f","#3fa7a4","#d9efde"],newsprint:["#191919","#666666","#aaaaaa","#eee9df"],custom:["#0b0b0a","#e6e3da"]},rn={version:1,aspectRatio:"original",style:"ascii",cellSize:6,charset:" .:-=+*#%@",colorMode:"accent",ink:"#e6e3da",print:{...rr},crop:{x:.5,y:.5,zoom:1,rotation:0},warps:[],warpEdge:"clamp",backdrop:{mode:"solid",color:"#080808",color2:"#1d1d1b",blur:12,opacity:1},color:{brightness:0,contrast:1,saturation:1,grayscale:0,tint:"#e6e3da",amount:0,blend:"source-over",blackPoint:0,whitePoint:1,gamma:1,shadows:0,highlights:0,curves:{rgb:[[0,0],[1,1]],red:[[0,0],[1,1]],green:[[0,0],[1,1]],blue:[[0,0],[1,1]]},denoise:0,levels:"auto"},dither:{algorithm:"none",palette:"mono",colors:["#080808","#e6e3da"],amount:1,scale:2,threshold:.5,motion:"none",speed:1,direction:45,colorSpace:"rgb"},mask:{enabled:!1,invert:!1,shapes:[]},lights:[],effects:{bloom:0,characterBloom:0,grain:0,dust:0,scanlines:0,crt:0,prism:0,rgbSplit:0,sharpen:0,vignette:0,glitch:0,pixelate:0,blur:0,blurType:"gaussian",angle:0,focus:.5,halftone:0},motion:{type:"none",speed:1,amount:1},hover:{effect:"trail",strength:.55,radius:.2,edgeSafe:!1}},ae=n=>n&&typeof n=="object"&&!Array.isArray(n)?n:{},at=(n,t,e,r)=>typeof n=="number"&&Number.isFinite(n)?Math.min(r,Math.max(e,n)):t,Oe=(n,t)=>typeof n=="string"&&/^#[\\da-f]{6}$/i.test(n)?n:t,te=(n,t,e)=>t.includes(n)?n:e;function fr(n={}){let t=ae(n),e=rn;if(t.version!==void 0&&t.version!==1)throw new Error("Unsupported studio settings version. Update asciify-engine.");let r=ae(t.crop),i=ae(t.backdrop),a=ae(t.color),o=ae(t.dither),l=ae(t.mask),s=ae(t.effects),h=ae(t.motion),f=ae(t.hover),u={...e.effects};for(let d of["bloom","characterBloom","grain","dust","scanlines","crt","prism","rgbSplit","sharpen","vignette","glitch","pixelate","halftone"])u[d]=at(s[d],0,0,1);u.blur=at(s.blur,0,0,24),u.blurType=te(s.blurType,["gaussian","directional","radial","progressive"],e.effects.blurType),u.angle=at(s.angle,0,-180,180),u.focus=at(s.focus,.5,0,1);let m=2048;return{version:1,aspectRatio:te(t.aspectRatio,["original","16:9","9:16","1:1","4:3","3:4","21:9"],"original"),style:te(t.style,$i,e.style),cellSize:at(t.cellSize,e.cellSize,We(String(t.style))||["pixel","mosaic","lego","voxel","disco","dots","hex","led","cmyk"].includes(String(t.style))?1:3,60),charset:typeof t.charset=="string"&&t.charset.length?Array.from(t.charset).slice(0,128).join(""):e.charset,colorMode:te(t.colorMode,["accent","source","gray"],e.colorMode),ink:Oe(t.ink,e.ink),print:ir(t.print),warps:Pr(t.warps),warpEdge:te(t.warpEdge,["clamp","transparent"],"clamp"),crop:{x:at(r.x,.5,0,1),y:at(r.y,.5,0,1),zoom:at(r.zoom,1,1,5),rotation:Math.round(at(r.rotation,0,-360,360)/90)*90},backdrop:{mode:te(i.mode,["solid","transparent","source","blurred","gradient"],e.backdrop.mode),color:Oe(i.color,e.backdrop.color),color2:Oe(i.color2,e.backdrop.color2),blur:at(i.blur,12,0,32),opacity:at(i.opacity,1,0,1)},color:{brightness:at(a.brightness,0,-1,1),contrast:at(a.contrast,1,0,3),saturation:at(a.saturation,1,0,3),grayscale:at(a.grayscale,0,0,1),tint:Oe(a.tint,e.color.tint),amount:at(a.amount,0,0,1),blend:te(a.blend,en,e.color.blend),blackPoint:at(a.blackPoint,0,0,.99),whitePoint:Math.max(at(a.blackPoint,0,0,.99)+1/255,at(a.whitePoint,1,1/255,1)),gamma:at(a.gamma,1,.25,4),shadows:at(a.shadows,0,-1,1),highlights:at(a.highlights,0,-1,1),curves:Qr(a.curves),denoise:at(a.denoise,0,0,1),levels:a.levels==="none"?"none":"auto"},dither:{algorithm:te(o.algorithm,tn,"none"),palette:typeof o.palette=="string"&&Object.prototype.hasOwnProperty.call(mr,o.palette)?o.palette:"mono",colors:Array.isArray(o.colors)&&o.colors.length>=2?o.colors.slice(0,32).map(d=>Oe(d,"#000000")):[...e.dither.colors],amount:at(o.amount,1,0,2),scale:Math.round(at(o.scale,2,1,12)),threshold:at(o.threshold,.5,0,1),motion:te(o.motion,["none","drift","shimmer"],"none"),speed:at(o.speed,1,.1,3),direction:at(o.direction,45,-180,180),colorSpace:te(o.colorSpace,["rgb","luminance"],"rgb")},mask:{enabled:l.enabled===!0,invert:l.invert===!0,shapes:Array.isArray(l.shapes)?l.shapes.slice(0,64).map(d=>{let c=ae(d),b=te(c.kind,["rectangle","ellipse","brush"],"rectangle"),g=b==="brush"&&Array.isArray(c.points)?c.points.slice(0,m).map(y=>Array.isArray(y)?[Math.round(at(y[0],0,0,1)*1e4)/1e4,Math.round(at(y[1],0,0,1)*1e4)/1e4]:[0,0]):[];return m-=g.length,{kind:b,x:at(c.x,0,0,1),y:at(c.y,0,0,1),width:at(c.width,.5,0,1),height:at(c.height,.5,0,1),size:at(c.size,.05,.005,.5),points:g}}):[]},lights:Array.isArray(t.lights)?t.lights.slice(0,4).map(d=>{let c=ae(d);return{x:at(c.x,.5,0,1),y:at(c.y,.5,0,1),radius:at(c.radius,.3,.02,1),intensity:at(c.intensity,.5,0,1),color:Oe(c.color,"#ffffff")}}):[],effects:u,motion:{type:te(typeof h.type=="string"?li(h.type):h.type,Ur.map(d=>d.mode),"none"),speed:at(h.speed,1,.1,3),amount:at(h.amount,1,0,2)},hover:{effect:ur(f.effect)??di.effect,strength:at(f.strength,Fe.strength.default,Fe.strength.min,Fe.strength.max),radius:at(f.radius,Fe.radius.default,Fe.radius.min,Fe.radius.max),edgeSafe:f.edgeSafe===!0,...qr(f.scope)!=="all"&&{scope:qr(f.scope)},...at(f.decay,.5,0,1)!==.5&&{decay:at(f.decay,.5,0,1)}}}}function pi(n,t,e,r,i){let a=Math.abs(i.rotation/90)%2===1,o=a?t:n,l=a?n:t,s=Math.max(e/o,r/l)*i.zoom;return{width:o*s,height:l*s,x:(e-o*s)*i.x,y:(r-l*s)*i.y,scale:s,rotated:a}}function gi(n,t,e,r=12e3,i=1){let a=Math.max(2,Number.isFinite(n)?n:960),o=Math.max(2,Number.isFinite(t)?t:540),l=Math.max(1,Math.floor(Number.isFinite(r)?r:12e3)),s=Math.max(.01,Number.isFinite(i)?i:1),h=We(e.style)||["dither","pixel","mosaic","lego","voxel","disco","dots","hex","led","cmyk"].includes(e.style)?1:1.65,f=Math.max(1,Math.ceil(Math.sqrt(a*o/(l*h))/s));for(;Math.ceil(a/(f*s))*Math.ceil(o/(f*s*h))>l;)f++;let u=e.style==="dither"?e.dither.scale:e.cellSize,m=Math.max(f,u)*s;return{cell:m,rowHeight:m*h,columns:Math.ceil(a/m),rows:Math.ceil(o/(m*h)),minimum:f,limited:u<f}}var bi="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Mi="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",Ke=new Uint16Array(4096);for(let n=0;n<Ke.length;n++)Ke[n]=bi.indexOf(Mi[n*2])<<6|bi.indexOf(Mi[n*2+1]);var Wr=(n,t)=>{let e=Math.sin(n*127.1+t*311.7)*43758.5453;return e-Math.floor(e)};function nn(n,t,e){let r=0;for(let i=1;i<e;i*=2){let a=(Math.floor(n/i)%2+2)%2,o=(Math.floor(t/i)%2+2)%2;r=r*4+[[0,2],[3,1]][o][a]}return(r+.5)/(e*e)-.5}var an=new Map([2,4,8,16].map(n=>[n,Float64Array.from({length:n*n},(t,e)=>nn(e%n,Math.floor(e/n),n))])),on={"floyd-steinberg":[[1,0,7/16],[-1,1,3/16],[0,1,5/16],[1,1,1/16]],atkinson:[[1,0,.125],[2,0,.125],[-1,1,.125],[0,1,.125],[1,1,.125],[0,2,.125]],stucki:[[1,0,8/42],[2,0,4/42],[-2,1,2/42],[-1,1,4/42],[0,1,8/42],[1,1,4/42],[2,1,2/42],[-2,2,1/42],[-1,2,2/42],[0,2,4/42],[1,2,2/42],[2,2,1/42]],sierra:[[1,0,5/32],[2,0,3/32],[-2,1,2/32],[-1,1,4/32],[0,1,5/32],[1,1,4/32],[2,1,2/32],[-1,2,2/32],[0,2,3/32],[1,2,2/32]],"sierra-lite":[[1,0,.5],[-1,1,.25],[0,1,.25]],burkes:[[1,0,8/32],[2,0,4/32],[-2,1,2/32],[-1,1,4/32],[0,1,8/32],[1,1,4/32],[2,1,2/32]],jarvis:[[1,0,7/48],[2,0,5/48],[-2,1,3/48],[-1,1,5/48],[0,1,7/48],[1,1,5/48],[2,1,3/48],[-2,2,1/48],[-1,2,3/48],[0,2,5/48],[1,2,3/48],[2,2,1/48]]},jr=n=>[parseInt(n.slice(1,3),16),parseInt(n.slice(3,5),16),parseInt(n.slice(5,7),16)];function vi(n,t,e,r,i=0){let{algorithm:a,amount:o,threshold:l}=r,s=a==="blue-noise",h=a.startsWith("bayer")?Number(a.slice(5)):0,f=an.get(h),u=h-1,m=r.colorSpace==="luminance",c=(r.palette==="custom"?r.colors:mr[r.palette]??mr.mono).map(jr),b=on[a],g=b?new Float32Array(t*3*3):null,y=r.motion==="drift"?i*r.speed*3:0,x=(r.direction??45)*Math.PI/180,S=Math.round(Math.cos(x)*y),A=Math.round(Math.sin(x)*y),k=(I,P)=>(I%P+P)%P,U=c.map(I=>I[0]*.299+I[1]*.587+I[2]*.114),Y=r.motion==="shimmer"?Math.sin(i*r.speed*2)*.15:0;for(let I=0;I<e;I++)for(let P=0;P<t;P++){let M=(I*t+P)*4,X=(I%3*t+P)*3;if(n[M+3]===0){g&&(g[X]=g[X+1]=g[X+2]=0);continue}let H=0,K=s?(Ke[(I-A&63)*64+(P-S&63)]+.5)/Ke.length:0;f?H=f[(I-A&u)*h+(P-S&u)]:a==="noise"?H=Wr(P-S,I-A)-.5:a==="lines"?H=k(I-A,4)/3-.5:a==="vertical-lines"?H=k(P-S,4)/3-.5:a==="diagonal-lines"?H=k(P-S+I-A,4)/3-.5:a==="radial"?H=k(Math.hypot(P-t/2,I-e/2)-y,6)/6-.5:a==="halftone"&&(H=Math.hypot(k(P-S,6)-2.5,k(I-A,6)-2.5)/3.54-.5);let v=(H*o+Y+(.5-l))*128,R=n[M]+v+(g?.[X]??0),G=n[M+1]+v+(g?.[X+1]??0),q=n[M+2]+v+(g?.[X+2]??0),C=0,E=0,w=0;if(c.length){let F=1/0,B=1/0,Z=0,et=0,N=R*.299+G*.587+q*.114;for(let tt=0;tt<c.length;tt++){let dt=c[tt],lt=m?(N-U[tt])**2:(R-dt[0])**2*.299+(G-dt[1])**2*.587+(q-dt[2])**2*.114;lt<F?(s&&(B=F,et=Z,Z=tt),F=lt,[C,E,w]=dt):s&&lt<B&&(B=lt,et=tt)}if(s&&o>0&&Number.isFinite(B)){let tt=c[et],dt=tt[0]-C,lt=tt[1]-E,St=tt[2]-w,Et=U[et]-U[Z],Lt=m?Et*Et:dt*dt*.299+lt*lt*.587+St*St*.114,Tt=m?(N-U[Z])*Et:(R-C)*dt*.299+(G-E)*lt*.587+(q-w)*St*.114,yt=Lt?Math.max(0,Math.min(1,Tt/Lt*o)):0;K<yt&&([C,E,w]=tt)}}else if(s){let F=Math.max(0,Math.min(1,.5+(K-.5)*o));C=Math.floor(R/51+1-F)*51,E=Math.floor(G/51+1-F)*51,w=Math.floor(q/51+1-F)*51}else C=Math.round(R/51)*51,E=Math.round(G/51)*51,w=Math.round(q/51)*51;if(n[M]=C,n[M+1]=E,n[M+2]=w,g&&b){g[X]=g[X+1]=g[X+2]=0;for(let[F,B,Z]of b){let et=P+F;if(et<0||et>=t||I+B>=e)continue;let N=((I+B)%3*t+et)*3;g[N]+=(R-C)*Z*o,g[N+1]+=(G-E)*Z*o,g[N+2]+=(q-w)*Z*o}}}}function yi(n=()=>document.createElement("canvas")){let t=n(),e=t.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,antialias:!1,preserveDrawingBuffer:!0});if(!e)return null;let r=[],i=(m,d)=>{let c=e.createShader(m);if(r.push(c),e.shaderSource(c,d),e.compileShader(c),!e.getShaderParameter(c,e.COMPILE_STATUS))throw new Error(e.getShaderInfoLog(c)||"Finish shader failed");return c},a=e.createProgram();if(e.attachShader(a,i(e.VERTEX_SHADER,"attribute vec2 p;varying vec2 uv;void main(){uv=(p+1.)*.5;gl_Position=vec4(p,0.,1.);}")),e.attachShader(a,i(e.FRAGMENT_SHADER,`precision mediump float;varying vec2 uv;uniform sampler2D src;uniform vec2 size;uniform float t,bloom,grain,dust,scanlines,crt,prism,vignette,glitch,pixelate,blur,blurMode,angle,focus,halftone,rgbSplit,sharpen;\n float hash(vec2 p){return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453);}\n vec4 sampleAt(vec2 p){if(min(min(p.x,p.y),min(1.-p.x,1.-p.y))<0.)return vec4(0.);return texture2D(src,vec2(p.x,1.-p.y));}\n void main(){vec2 q=uv,c=q-.5;q=c*(1.+dot(c,c)*crt*.25)+.5;\n if(glitch>0.)q.x+=(hash(vec2(floor(q.y*35.),floor(t*5.)))-.5)*.07*glitch*step(.82,hash(vec2(floor(q.y*35.),floor(t*5.)+3.)));\n if(pixelate>0.){vec2 grid=size/(1.+pixelate*20.);q=(floor(q*grid)+.5)/grid;}\n vec4 base=sampleAt(q);float edge=smoothstep(.12,.65,length(c));\n vec2 shift=vec2((prism*3.*edge+rgbSplit*8.)/size.x,prism*edge/size.y);\n if(prism>0.||rgbSplit>0.)base.rgb=vec3(sampleAt(q+shift).r,base.g,sampleAt(q-shift).b);\n vec2 dir=vec2(cos(angle),sin(angle))/size;float amount=blur;\n if(blurMode>1.5&&blurMode<2.5){dir=normalize(c+vec2(.0001))/size;amount*=length(c)*2.;}\n if(blurMode>2.5)amount*=smoothstep(.05,.5,abs(q.y-focus));\n vec4 blurred=base;\n if(amount>0.){blurred=base*.2;for(int i=1;i<=4;i++){float f=float(i)*amount*.35;vec2 off=dir*f;if(blurMode<.5)off=vec2(cos(float(i)*1.57),sin(float(i)*1.57))*amount/size;blurred+=sampleAt(q+off)*.1+sampleAt(q-off)*.1;}}\n vec3 light=vec3(0.);\n // Bloom: a wide golden-angle disc of soft-kneed highlights, screened on, so light spills like halation instead of ghosting glyphs.\n if(bloom>0.){float total=0.;for(int i=0;i<16;i++){float f=float(i);vec2 o=vec2(cos(f*2.39996),sin(f*2.39996))*(2.+f*1.6)/size;vec3 s=sampleAt(q+o).rgb;float w=1./(1.+f*.18);light+=s*smoothstep(.35,.9,max(s.r,max(s.g,s.b)))*w;total+=w;}light*=bloom*3.2/total;}\n vec3 col=1.-(1.-blurred.rgb)*(1.-min(light,vec3(1.)));\n if(sharpen>0.){vec2 px=1./size;vec3 near=sampleAt(q+vec2(px.x,0.)).rgb+sampleAt(q-vec2(px.x,0.)).rgb+sampleAt(q+vec2(0.,px.y)).rgb+sampleAt(q-vec2(0.,px.y)).rgb;col+=(base.rgb*4.-near)*sharpen*.5;}\ncol*=1.-scanlines*.4*(.5+.5*cos(q.y*size.y*3.14159));\n col*=1.-vignette*smoothstep(.15,.72,length(c));\n // Film grain: soft triangular noise, strongest in the midtones, quiet in deep shadow and paper-white highlights.\n float luma=dot(col,vec3(.299,.587,.114));vec2 g=floor(q*size/1.25)+floor(t*24.)*vec2(7.,13.);\n col+=(hash(g)+hash(g+31.7)-1.)*grain*.17*(.2+3.2*luma*(1.-luma));\n if(dust>0.)col+=step(1.-dust*.002,hash(floor(q*size*.25)+floor(t*2.)))*.4;\n if(halftone>0.)col*=mix(1.,smoothstep(.1,.65,length(fract(q*size/6.)-.5)),halftone);\n gl_FragColor=vec4(clamp(col,0.,1.),blurred.a);}`)),e.linkProgram(a),!e.getProgramParameter(a,e.LINK_STATUS))throw new Error("Finish link failed");e.useProgram(a);let o=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,o),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),e.STATIC_DRAW);let l=e.getAttribLocation(a,"p");e.enableVertexAttribArray(l),e.vertexAttribPointer(l,2,e.FLOAT,!1,0,0);let s=e.createTexture();e.bindTexture(e.TEXTURE_2D,s),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);let h=["t","bloom","grain","dust","scanlines","crt","prism","rgbSplit","sharpen","vignette","glitch","pixelate","blur","blurMode","angle","focus","halftone"],f=Object.fromEntries(h.map(m=>[m,e.getUniformLocation(a,m)])),u=e.getUniformLocation(a,"size");return{canvas:t,render(m,d,c,b=1){(t.width!==m.width||t.height!==m.height)&&(t.width=m.width,t.height=m.height,e.viewport(0,0,t.width,t.height)),e.useProgram(a),e.bindTexture(e.TEXTURE_2D,s),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,m),e.uniform2f(u,t.width/b,t.height/b);for(let g of h)e.uniform1f(f[g],g==="t"?c:g==="blurMode"?["gaussian","directional","radial","progressive"].indexOf(d.blurType):g==="angle"?d.angle*Math.PI/180:d[g]??0);return e.drawArrays(e.TRIANGLE_STRIP,0,4),t},destroy(){e.deleteTexture(s),e.deleteBuffer(o),e.deleteProgram(a),r.forEach(m=>e.deleteShader(m)),t.width=t.height=1,e.getExtension("WEBGL_lose_context")?.loseContext()}}}function oe(n,t,e){let r=Math.min(n*Math.max(1,e),(1-n)*Math.max(1,e),t*Math.max(1,1/e),(1-t)*Math.max(1,1/e)),i=Math.max(0,Math.min(1,(r-.035)/.105));return i*i*i*(i*(i*6-15)+10)}var dr=class{constructor(t,e){this.edgeSafe=!1;this.rings=new Float64Array(40);this.slot=0;this.clock=0;this.lastRing=-1;this.previous=null;this.alive=!1;this.width=t,this.height=e,this.pixels=new Uint8Array(t*e*4),this.values=new Float32Array(t*e),this.clear()}get active(){return this.alive}clear(){this.rings.fill(0),this.values.fill(0),this.pixels.fill(0);for(let t=0;t<this.pixels.length;t+=4)this.pixels[t]=128;this.previous=null,this.alive=!1,this.slot=0,this.lastRing=-1,this.clock=0}leave(){this.previous=null}move(t,e,r,i){if(!Number.isFinite(t+e+r))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e));let a=Number.isFinite(i)?i/1e3:this.clock,o=this.previous;if(this.previous={x:t,y:e,time:a},!o)return;let l=this.width/this.height,s=Math.hypot((t-o.x)*Math.max(1,l),(e-o.y)*Math.max(1,1/l));if(s<1e-4||this.clock-this.lastRing<1/24)return;let h=s/Math.max(1/240,Math.min(.1,a-o.time||1/60)),f=this.slot*5;this.slot=(this.slot+1)%8,this.rings[f]=t,this.rings[f+1]=e,this.rings[f+2]=0,this.rings[f+3]=Math.min(.9,.26+h*.2),this.rings[f+4]=.035+Math.max(.1,Math.min(1,r))*.13,this.alive=!0,this.lastRing=this.clock}step(t){if(!Number.isFinite(t)||t<=0)return;let e=Math.min(.05,t);if(this.clock+=e,!this.alive)return;this.values.fill(0),this.alive=!1;let r=this.width/this.height,i=Math.max(1,r),a=Math.max(1,1/r);for(let o=0;o<this.rings.length;o+=5){if(!this.rings[o+3])continue;let l=this.rings[o+2]+=e;if(l>2.8){this.rings[o+3]=0;continue}this.alive=!0;let s=this.rings[o+4],h=l*.17,f=this.rings[o+3]*(1-Math.exp(-l*20))*Math.exp(-l*2.5),u=h+s*1.8,m=this.rings[o],d=this.rings[o+1],c=Math.max(0,Math.floor((m-u/i)*(this.width-1))),b=Math.min(this.width-1,Math.ceil((m+u/i)*(this.width-1))),g=Math.max(0,Math.floor((d-u/a)*(this.height-1))),y=Math.min(this.height-1,Math.ceil((d+u/a)*(this.height-1)));for(let x=g;x<=y;x++)for(let S=c;S<=b;S++){let k=(Math.hypot((S/(this.width-1)-m)*i,(x/(this.height-1)-d)*a)-h)/s;Math.abs(k)>1.8||(this.values[x*this.width+S]+=f*Math.cos(k*Math.PI*2)*Math.exp(-k*k*2.5))}}for(let o=0;o<this.height;o++)for(let l=0;l<this.width;l++){let s=o*this.width+l,h=this.values[s]=Math.max(-1,Math.min(1,this.values[s]))*(this.edgeSafe?oe(l/(this.width-1),o/(this.height-1),r):1),f=Math.round(h*32767+32768);this.pixels[s*4]=f>>>8,this.pixels[s*4+1]=f&255}}sample(t,e,r){let i=Math.max(0,Math.min(this.width-1.001,t*(this.width-1))),a=Math.max(0,Math.min(this.height-1.001,e*(this.height-1))),o=Math.floor(i),l=Math.floor(a),s=i-o,h=a-l,f=l*this.width+o,u=f+this.width;r[0]=r[1]=0,r[2]=((this.values[f]*(1-s)+this.values[f+1]*s)*(1-h)+(this.values[u]*(1-s)+this.values[u+1]*s)*h)*3}};var Ee=n=>["dissolve","silk","vortex","magnetic","scatter","etch","elastic","lens","smudge"].includes(n),xi=n=>n==="elastic"||n==="scatter",Si={elastic:[150,4.2],scatter:[90,3.6]},pr=class{constructor(t,e){this.edgeSafe=!1;this.previous=null;this.peak=0;this.scatterDirections=null;this.springX=null;this.springY=null;this.mode="dissolve";this.width=t,this.height=e;let r=t*e;this.pixels=new Uint8Array(r*4),this.ink=new Float32Array(r),this.targetX=new Float32Array(r),this.targetY=new Float32Array(r),this.offsetX=new Float32Array(r),this.offsetY=new Float32Array(r),this.edge=new Float32Array(r);for(let i=0;i<e;i++)for(let a=0;a<t;a++)this.edge[i*t+a]=oe(a/(t-1),i/(e-1),t/e);this.clear()}get active(){return this.peak>2e-4}setMode(t){if(xi(t)&&!this.springX&&(this.springX=new Float32Array(this.ink.length),this.springY=new Float32Array(this.ink.length)),t==="scatter"&&!this.scatterDirections){let e=this.scatterDirections=new Float64Array(this.width*this.height*2),r=(i,a)=>{let o=Math.sin(i*127.1+a*311.7)*43758.5453;return o-Math.floor(o)};for(let i=0;i<this.height;i++)for(let a=0;a<this.width;a++){let o=a*.09,l=i*.09,s=Math.floor(o),h=Math.floor(l),f=o-s,u=l-h,m=f*f*(3-2*f),d=u*u*(3-2*u),b=((r(s,h)*(1-m)+r(s+1,h)*m)*(1-d)+(r(s,h+1)*(1-m)+r(s+1,h+1)*m)*d)*Math.PI*4,g=(i*this.width+a)*2;e[g]=Math.cos(b)*.7,e[g+1]=Math.sin(b)*.7}}t!==this.mode&&(this.mode=t,this.clear())}clear(){for(let t of[this.ink,this.targetX,this.targetY,this.offsetX,this.offsetY,this.pixels])t.fill(0);if(this.previous=null,this.peak=0,this.springX?.fill(0),this.springY?.fill(0),this.mode!=="dissolve")for(let t=0;t<this.pixels.length;t+=4)this.pixels[t]=this.pixels[t+2]=128}leave(){this.previous=null}move(t,e,r){if(!Number.isFinite(t+e+r))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e));let i=this.previous;this.previous={x:t,y:e};let a=this.width,o=this.height,l=Math.max(1,a/o),s=Math.max(1,o/a),h=i?(t-i.x)*l:0,f=i?(e-i.y)*s:0,u=Math.hypot(h,f);if(!i&&this.mode!=="dissolve"&&this.mode!=="etch"&&this.mode!=="lens"||i&&u<1e-4)return;let m=.035+Math.max(.1,Math.min(1,r))*.11,d=Math.min(128,Math.max(1,Math.ceil(u/(m*.45)))),c=u?h/u:1,b=u?f/u:0,g=!i&&this.mode==="lens"?.32:Math.min(1,u/(m*d)*2.2);for(let y=0;y<d;y++){let x=(y+.5)/d,S=i?i.x+(t-i.x)*x:t,A=i?i.y+(e-i.y)*x:e,k=Math.max(0,Math.floor((S-m*2.5/l)*(a-1))),U=Math.min(a-1,Math.ceil((S+m*2.5/l)*(a-1))),Y=Math.max(0,Math.floor((A-m*2.5/s)*(o-1))),I=Math.min(o-1,Math.ceil((A+m*2.5/s)*(o-1)));for(let P=Y;P<=I;P++)for(let M=k;M<=U;M++){let X=(M/(a-1)-S)*l/m,H=(P/(o-1)-A)*s/m,K=Math.exp(-(X*X+H*H)*1.5),v=P*a+M;if(this.mode==="dissolve"||this.mode==="etch")this.ink[v]=Math.max(this.ink[v],K);else if(this.mode==="elastic")this.springX[v]=Math.max(-24,Math.min(24,this.springX[v]+c*K*g*12)),this.springY[v]=Math.max(-24,Math.min(24,this.springY[v]+b*K*g*12));else if(this.mode==="scatter"){let R=this.scatterDirections;this.springX[v]=Math.max(-24,Math.min(24,this.springX[v]+(X*.6+R[v*2])*K*g*7)),this.springY[v]=Math.max(-24,Math.min(24,this.springY[v]+(H*.6+R[v*2+1])*K*g*7))}else if(this.mode==="lens")this.targetX[v]=Math.max(-.65,Math.min(.65,this.targetX[v]+X*K*g*1.6)),this.targetY[v]=Math.max(-.65,Math.min(.65,this.targetY[v]+H*K*g*1.6));else if(this.mode==="smudge")this.targetX[v]=Math.max(-1,Math.min(1,this.targetX[v]+c*K*g*1.3)),this.targetY[v]=Math.max(-1,Math.min(1,this.targetY[v]+b*K*g*1.3));else{let R=(-X*b+H*c)*K*2.8,G=this.mode==="magnetic"?-X*K*2.5:this.mode==="silk"?c*R:-H*K*2.5,q=this.mode==="magnetic"?-H*K*2.5:this.mode==="silk"?b*R:X*K*2.5;this.targetX[v]=Math.max(-1,Math.min(1,this.targetX[v]+G*g)),this.targetY[v]=Math.max(-1,Math.min(1,this.targetY[v]+q*g))}}}this.peak=1}step(t){if(!this.active||!Number.isFinite(t))return;let e=Math.max(0,Math.min(.05,t)),r=this.mode==="dissolve"?2.15:this.mode==="smudge"?2.4:3.2,i=this.mode==="lens"?16:22,a=Math.exp(-r*e),o=1-Math.exp(-i*e),l=0,[s,h]=this.mode==="scatter"?Si.scatter:Si.elastic,f=Math.sqrt(s-h*h),u=Math.exp(-h*e),m=Math.cos(f*e),d=Math.sin(f*e)/f;for(let c=0;c<this.ink.length;c++)if(this.mode==="etch")this.ink[c]*=a,l=Math.max(l,this.ink[c]);else if(this.mode==="dissolve"){this.ink[c]*=a,l=Math.max(l,this.ink[c]);let b=Math.round(this.ink[c]*65535);this.pixels[c*4]=b>>>8,this.pixels[c*4+1]=b&255}else{if(xi(this.mode)){let y=this.offsetX[c],x=this.offsetY[c],S=this.springX[c],A=this.springY[c];this.offsetX[c]=Math.max(-1,Math.min(1,u*(y*m+(S+h*y)*d))),this.offsetY[c]=Math.max(-1,Math.min(1,u*(x*m+(A+h*x)*d))),this.springX[c]=u*(S*m-(h*S+s*y)*d),this.springY[c]=u*(A*m-(h*A+s*x)*d),l=Math.max(l,Math.abs(this.springX[c])*.05,Math.abs(this.springY[c])*.05)}else if(this.mode==="lens"||this.mode==="smudge"){let y=1-o,x=i/(i-r)*(a-y);this.offsetX[c]=this.offsetX[c]*y+this.targetX[c]*x,this.offsetY[c]=this.offsetY[c]*y+this.targetY[c]*x,this.targetX[c]*=a,this.targetY[c]*=a}else this.targetX[c]*=a,this.targetY[c]*=a,this.offsetX[c]+=(this.targetX[c]-this.offsetX[c])*o,this.offsetY[c]+=(this.targetY[c]-this.offsetY[c])*o;l=Math.max(l,Math.abs(this.offsetX[c]),Math.abs(this.offsetY[c]),Math.abs(this.targetX[c]),Math.abs(this.targetY[c]));let b=Math.round(this.offsetX[c]*(this.edgeSafe?this.edge[c]:1)*32767+32768),g=Math.round(this.offsetY[c]*(this.edgeSafe?this.edge[c]:1)*32767+32768);this.pixels[c*4]=b>>>8,this.pixels[c*4+1]=b&255,this.pixels[c*4+2]=g>>>8,this.pixels[c*4+3]=g&255}if(this.mode==="etch")for(let c=0;c<this.height;c++)for(let b=0;b<this.width;b++){let g=c*this.width+b,y=(this.ink[c*this.width+Math.max(0,b-1)]-this.ink[c*this.width+Math.min(this.width-1,b+1)]+this.ink[Math.max(0,c-1)*this.width+b]-this.ink[Math.min(this.height-1,c+1)*this.width+b])*3;this.offsetX[g]=Math.max(-1,Math.min(1,y))*(this.edgeSafe?this.edge[g]:1);let x=Math.round(this.offsetX[g]*32767+32768);this.pixels[g*4]=x>>>8,this.pixels[g*4+1]=x&255}this.peak=l,this.active||this.clear()}sample(t,e,r){let i=Math.max(0,Math.min(this.width-1.001,t*(this.width-1))),a=Math.max(0,Math.min(this.height-1.001,e*(this.height-1))),o=Math.floor(i),l=Math.floor(a),s=i-o,h=a-l,f=l*this.width+o,u=f+this.width,m=d=>(d[f]*(1-s)+d[f+1]*s)*(1-h)+(d[u]*(1-s)+d[u+1]*s)*h;if(this.mode==="etch"){r[0]=r[1]=0,r[2]=m(this.offsetX)*3;return}r[0]=m(this.offsetX)*(this.edgeSafe?oe(t,e,this.width/this.height):1)*.08,r[1]=m(this.offsetY)*(this.edgeSafe?oe(t,e,this.width/this.height):1)*.08,r[2]=this.mode==="dissolve"?-m(this.ink)*6:0}};var gr=class{constructor(t,e){this.rings=[];this.previous=null;this.elapsed=1;this.echoPeak=0;this.width=t,this.height=e,this.pixels=new Uint8Array(t*e*4),this.echo=new Float32Array(t*e)}get active(){return this.rings.length>0||this.echoPeak>2e-4}clear(){this.rings=[],this.previous=null,this.elapsed=1,this.pixels.fill(0),this.echo.fill(0),this.echoPeak=0}leave(){this.previous=null}move(t,e,r){let i=Math.max(1,this.width/this.height),a=Math.max(1,this.height/this.width);this.previous&&(Math.hypot((t-this.previous.x)*i,(e-this.previous.y)*a)<.065||this.elapsed<.3)||this.rings.length!==4&&(this.previous={x:t,y:e},this.elapsed=0,this.rings.push({x:t,y:e,age:0,radius:r}))}ringSample(t,e){let r=Math.max(1,this.width/this.height),i=Math.max(1,this.height/this.width),a=0;for(let o of this.rings){let l=.015+o.age*(.15+o.radius*.22),s=.009+o.radius*.014,h=(Math.hypot((t-o.x)*r,(e-o.y)*i)-l)/s,f=Math.sin(Math.min(1,o.age/.07)*Math.PI/2)*Math.max(0,1-o.age/1.35)**2;a=Math.max(a,Math.exp(-h*h)*f)}return a}sample(t,e){let r=Math.max(0,Math.min(this.width-1,Math.round(t*(this.width-1)))),i=Math.max(0,Math.min(this.height-1,Math.round(e*(this.height-1))));return Math.max(this.ringSample(t,e),this.echo[i*this.width+r])}step(t){if(!Number.isFinite(t))return;let e=Math.max(0,Math.min(.05,t));this.elapsed+=e;for(let a of this.rings)a.age+=e;if(this.rings=this.rings.filter(a=>a.age<1.35),!this.active){this.pixels.fill(0);return}let r=Math.exp(-5.5*e),i=0;for(let a=0;a<this.height;a++)for(let o=0;o<this.width;o++){let l=a*this.width+o;this.echo[l]=Math.max(this.ringSample(o/(this.width-1),a/(this.height-1)),this.echo[l]*r),i=Math.max(i,this.echo[l]);let s=Math.round(this.echo[l]*65535),h=l*4;this.pixels[h]=s>>>8,this.pixels[h+1]=s&255}this.echoPeak=i,this.active||(this.echo.fill(0),this.pixels.fill(0))}};var br=class{constructor(t,e){this.previous=null;this.peak=0;this.width=t,this.height=e;let r=t*e;this.pixels=new Uint8Array(r*4),this.signal=new Float32Array(r),this.offsetX=new Float32Array(r),this.offsetY=new Float32Array(r),this.driftX=new Float32Array(r),this.driftY=new Float32Array(r),this.u=new Float32Array(r),this.v=new Float32Array(r),this.ink=new Float32Array(r),this.a=new Float32Array(r),this.b=new Float32Array(r),this.c=new Float32Array(r),this.pressure=new Float32Array(r),this.pressureNext=new Float32Array(r),this.divergence=new Float32Array(r),this.curl=new Float32Array(r)}get active(){return this.peak>2e-4}clear(){for(let t of[this.u,this.v,this.ink,this.a,this.b,this.c,this.pressure,this.pressureNext,this.divergence,this.curl,this.signal,this.pixels,this.offsetX,this.offsetY,this.driftX,this.driftY])t.fill(0);this.previous=null,this.peak=0}leave(){this.previous=null}move(t,e,r,i=performance.now()){if(!Number.isFinite(t+e+r+i))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e)),r=Math.max(.1,Math.min(1,r));let a=this.previous;if(this.previous={x:t,y:e,time:i},!a)return;let o=(t-a.x)*(this.width-1),l=(e-a.y)*(this.height-1),s=Math.hypot(o,l);if(s<.001)return;let h=Math.min(this.width,this.height),f=i>a.time?Math.max(1/240,(i-a.time)/1e3):1/60,u=Math.min(12,s/h/f),m=1-Math.exp(-u/2.2),d=h*(.022+r*.075)*(.65+m*.95),c=Math.min(128,Math.max(1,Math.ceil(s/(d*.4)))),b=s/d*(.32+m*.22)/c,g=o/s,y=l/s,x=-y,S=g,A=s*(2+m*18)/c;for(let k=0;k<c;k++){let U=(k+.5)/c,Y=(a.x+(t-a.x)*U)*(this.width-1),I=(a.y+(e-a.y)*U)*(this.height-1),P=Math.max(1,Math.floor(Y-d*3)),M=Math.min(this.width-2,Math.ceil(Y+d*3)),X=Math.max(1,Math.floor(I-d*3)),H=Math.min(this.height-2,Math.ceil(I+d*3));for(let K=X;K<=H;K++)for(let v=P;v<=M;v++){let R=((v-Y)*g+(K-I)*y)/d,G=((v-Y)*x+(K-I)*S)/d,q=Math.exp(-R*R*.65-G*G*1.7),C=K*this.width+v;this.ink[C]=1-(1-this.ink[C])*Math.exp(-q*b);let E=1-G*G*.55,w=R*G*.7;this.u[C]=Math.max(-80,Math.min(80,this.u[C]+(g*E+x*w)*q*A)),this.v[C]=Math.max(-80,Math.min(80,this.v[C]+(y*E+S*w)*q*A))}}this.peak=1}read(t,e,r){e=Math.max(.5,Math.min(this.width-1.5,e)),r=Math.max(.5,Math.min(this.height-1.5,r));let i=e|0,a=r|0,o=e-i,l=r-a,s=a*this.width+i;return(t[s]*(1-o)+t[s+1]*o)*(1-l)+(t[s+this.width]*(1-o)+t[s+this.width+1]*o)*l}sample(t,e){return this.read(this.signal,t*(this.width-1),e*(this.height-1))}displacement(t,e,r){r[0]=this.read(this.offsetX,t*(this.width-1),e*(this.height-1)),r[1]=this.read(this.offsetY,t*(this.width-1),e*(this.height-1))}step(t){if(!this.active||!Number.isFinite(t))return;let e=Math.max(0,Math.min(.05,t)),r=this.width,i=this.height;for(;e>1e-7;){let a=Math.min(.016666666666666666,e);e-=a;let o=Math.exp(-1.9*a),l=Math.exp(-3.2*a);for(let h=1;h<i-1;h++)for(let f=1;f<r-1;f++){let u=h*r+f,m=Math.max(.5,Math.min(r-1.5,f-this.u[u]*a)),d=Math.max(.5,Math.min(i-1.5,h-this.v[u]*a)),c=m|0,b=d|0,g=m-c,y=d-b,x=b*r+c,S=(1-g)*(1-y),A=g*(1-y),k=(1-g)*y,U=g*y;this.a[u]=(this.u[x]*S+this.u[x+1]*A+this.u[x+r]*k+this.u[x+r+1]*U)*o,this.b[u]=(this.v[x]*S+this.v[x+1]*A+this.v[x+r]*k+this.v[x+r+1]*U)*o,this.c[u]=(this.ink[x]*S+this.ink[x+1]*A+this.ink[x+r]*k+this.ink[x+r+1]*U)*l}[this.u,this.a]=[this.a,this.u],[this.v,this.b]=[this.b,this.v],[this.ink,this.c]=[this.c,this.ink];for(let h=1;h<i-1;h++)for(let f=1;f<r-1;f++){let u=h*r+f;this.curl[u]=(this.v[u+1]-this.v[u-1]-this.u[u+r]+this.u[u-r])*.5}for(let h=1;h<i-1;h++)for(let f=1;f<r-1;f++){let u=h*r+f,m=Math.abs(this.curl[u+1])-Math.abs(this.curl[u-1]),d=Math.abs(this.curl[u+r])-Math.abs(this.curl[u-r]),c=Math.hypot(m,d)+1e-4,b=this.curl[u]*a*10,g=Math.hypot(this.u[u],this.v[u]);this.u[u]+=d/c*b,this.v[u]-=m/c*b;let y=Math.min(1,g/(Math.hypot(this.u[u],this.v[u])+1e-6));this.u[u]*=y,this.v[u]*=y,this.divergence[u]=-.5*(this.u[u+1]-this.u[u-1]+this.v[u+r]-this.v[u-r])}this.pressure.fill(0);for(let h=0;h<4;h++){for(let f=1;f<i-1;f++)for(let u=1;u<r-1;u++){let m=f*r+u;this.pressureNext[m]=(this.divergence[m]+this.pressure[m-1]+this.pressure[m+1]+this.pressure[m-r]+this.pressure[m+r])*.25}[this.pressure,this.pressureNext]=[this.pressureNext,this.pressure]}let s=0;for(let h=1;h<i-1;h++)for(let f=1;f<r-1;f++){let u=h*r+f;this.u[u]=Math.max(-80,Math.min(80,this.u[u]-(this.pressure[u+1]-this.pressure[u-1])*.5)),this.v[u]=Math.max(-80,Math.min(80,this.v[u]-(this.pressure[u+r]-this.pressure[u-r])*.5)),this.driftX[u]+=(this.u[u]*3.6-58*this.offsetX[u]-12*this.driftX[u])*a,this.driftY[u]+=(this.v[u]*3.6-58*this.offsetY[u]-12*this.driftY[u])*a,this.offsetX[u]=Math.max(-2,Math.min(2,this.offsetX[u]+this.driftX[u]*a)),this.offsetY[u]=Math.max(-2,Math.min(2,this.offsetY[u]+this.driftY[u]*a)),this.signal[u]=1-Math.exp(-Math.hypot(this.u[u],this.v[u])*.06-this.ink[u]*.16),s=Math.max(s,this.signal[u])}this.peak=s}if(!this.active){this.clear();return}for(let a=0;a<this.ink.length;a++){let o=Math.round(Math.min(1,this.signal[a])*65535);this.pixels[a*4]=o>>>8,this.pixels[a*4+1]=o&255,this.pixels[a*4+2]=Math.round(128+this.offsetX[a]*63.5),this.pixels[a*4+3]=Math.round(128+this.offsetY[a]*63.5)}}};function ki(n,t){let e=Math.max(0,Math.min(1,t/.38)),r=e*e*(3-2*e);return n+(1-2*n)*r}var sn=["loupe","repel","tilt","reveal","haze","bleed"],he=n=>sn.includes(n),Re=class{constructor(){this.value=0;this.velocity=0}step(t,e,r,i){let a=2*Math.sqrt(r)*i;for(let o=e;o>1e-6;o-=1/480){let l=Math.min(.0020833333333333333,o);this.velocity+=((t-this.value)*r-this.velocity*a)*l,this.value+=this.velocity*l}}resting(t){return Math.abs(this.value-t)<.0015&&Math.abs(this.velocity)<.01}set(t){this.value=t,this.velocity=0}},Ai=n=>n*n*(3-2*n),Ve=(n,t)=>{let e=Math.sin(n*127.1+t*311.7)*43758.5453;return e-Math.floor(e)};function Mr(n,t){let e=Math.floor(n),r=Math.floor(t),i=Ai(n-e),a=Ai(t-r),o=Ve(e,r),l=Ve(e+1,r),s=Ve(e,r+1),h=Ve(e+1,r+1);return(o+(l-o)*i)*(1-a)+(s+(h-s)*i)*a}var vr=class{constructor(t,e){this.edgeSafe=!1;this.settle=1;this.focus=[.5,.5,0,.2];this.guide=null;this.mode="loupe";this.radius=.35;this.x=new Re;this.y=new Re;this.tx=new Re;this.ty=new Re;this.presence=new Re;this.target=null;this.speed=0;this.clock=0;this.inkPeak=0;this.ink=null;this.next=null;this.fiber=null;this.sampled=[0,0,0];this.width=t,this.height=e,this.pixels=new Uint8Array(t*e*4),this.sx=Math.max(1,t/e),this.sy=Math.max(1,e/t),this.clear()}setMode(t){if(t!==this.mode&&(this.mode=t,this.clear(),t==="bleed"&&!this.ink)){let e=this.width*this.height;this.ink=new Float32Array(e),this.next=new Float32Array(e),this.fiber=new Float32Array(e);for(let r=0;r<this.height;r++)for(let i=0;i<this.width;i++)this.fiber[r*this.width+i]=.35+.5*Mr(i*.09,r*.045)+.15*Ve(i,r)}}setRadius(t){this.radius=Math.max(.1,Math.min(1,t))}get reach(){return(.05+this.radius*.25)*(this.mode==="loupe"?1-this.speed*.14:1)}get engaged(){return this.presence.value>.002||this.inkPeak>.002||Math.abs(this.tx.value)+Math.abs(this.ty.value)>4e-4}get active(){let t=this.target?1:0;return!this.presence.resting(t)||!!this.target&&(!this.x.resting(this.target.x)||!this.y.resting(this.target.y))||!this.tx.resting(this.tiltGoal(0))||!this.ty.resting(this.tiltGoal(1))||this.speed>.01||this.mode==="haze"&&this.presence.value>.002||this.inkPeak>.002}tiltGoal(t){return this.target&&this.mode==="tilt"?((t?this.target.y:this.target.x)-.5)*2:0}clear(){for(let t of[this.x,this.y,this.tx,this.ty,this.presence])t.set(0);this.x.set(.5),this.y.set(.5),this.target=null,this.speed=0,this.inkPeak=0,this.ink?.fill(0),this.next?.fill(0),this.encode()}move(t,e,r){if(!Number.isFinite(t+e))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e));let i=Number.isFinite(r)?r/1e3:this.clock,a=this.target;if(!a&&this.presence.value<.05&&(this.x.set(t),this.y.set(e)),a){let o=Math.hypot((t-a.x)*this.sx,(e-a.y)*this.sy),l=o/Math.max(1/240,Math.min(.1,i-a.time||1/60));this.speed=Math.max(this.speed,Math.min(1,l/1.6)),this.mode==="bleed"&&this.deposit(a.x,a.y,t,e,Math.min(1,o*9))}else this.mode==="bleed"&&this.deposit(t,e,t,e,.5);this.target={x:t,y:e,time:i}}leave(){this.target=null}deposit(t,e,r,i,a){let o=this.ink,l=this.width,s=this.height,h=this.reach*.55,f=Math.hypot((r-t)*this.sx,(i-e)*this.sy),u=Math.min(48,Math.max(1,Math.ceil(f/(h*.5))));for(let m=0;m<u;m++){let d=(m+.5)/u,c=t+(r-t)*d,b=e+(i-e)*d,g=Math.max(0,Math.floor((c-h*2/this.sx)*(l-1))),y=Math.min(l-1,Math.ceil((c+h*2/this.sx)*(l-1))),x=Math.max(0,Math.floor((b-h*2/this.sy)*(s-1))),S=Math.min(s-1,Math.ceil((b+h*2/this.sy)*(s-1)));for(let A=x;A<=S;A++)for(let k=g;k<=y;k++){let U=(k/(l-1)-c)*this.sx/h,Y=(A/(s-1)-b)*this.sy/h,I=A*l+k;o[I]=Math.min(1.4,o[I]+Math.exp(-(U*U+Y*Y)*1.8)*a/u*1.6)}}this.inkPeak=Math.max(this.inkPeak,.01)}step(t){if(!Number.isFinite(t)||t<=0)return;let e=Math.min(.05,t),r=e*this.settle;this.clock+=e;let i=this.target,a=this.mode;if(i?this.presence.step(1,e,190,1):this.presence.step(0,r,a==="repel"?120:70,a==="repel"?.42:1),i){let o=a==="tilt"?60:a==="haze"?90:240,l=a==="loupe"||a==="repel"?.72:.9;this.x.step(i.x,e,o,l),this.y.step(i.y,e,o,l)}this.tx.step(this.tiltGoal(0),i?e:r,45,.78),this.ty.step(this.tiltGoal(1),i?e:r,45,.78),this.speed*=Math.exp(-e*7),a==="bleed"&&this.spread(e,r,!!i),!this.engaged&&!this.active&&(this.presence.set(0),this.tx.set(0),this.ty.set(0)),this.focus[0]=this.x.value,this.focus[1]=this.y.value,this.focus[2]=Math.max(0,Math.min(1,this.presence.value)),this.focus[3]=this.reach,this.encode()}spread(t,e,r){let i=this.ink,a=this.next,o=this.fiber,l=this.width,s=this.height;r&&this.target&&this.deposit(this.x.value,this.y.value,this.x.value,this.y.value,t*.9);let h=Math.max(1,Math.ceil(t/(1/240))),f=t/h,u=26*(.4+this.radius),m=(r?.02:.1)*e/t,d=Math.exp(-(r?.15:.9)*e/h),c=0;for(let b=0;b<h;b++){c=0;for(let g=1;g<s-1;g++)for(let y=1;y<l-1;y++){let x=g*l+y,S=i[x],A=o[x],k=Math.min(A,o[x-1])*(i[x-1]-S)+Math.min(A,o[x+1])*(i[x+1]-S)+Math.min(A,o[x-l])*(i[x-l]-S)+Math.min(A,o[x+l])*(i[x+l]-S),U=Math.max(0,(S+k*Math.min(.24,u*f))*d-m*f);a[x]=U,U>c&&(c=U)}i.set(a)}this.inkPeak=c}sample(t,e,r){r[0]=r[1]=r[2]=0;let i=this.presence.value,a=this.mode;if(a==="bleed"){if(this.inkPeak<=.002)return;let d=this.width,c=this.height,b=this.ink,g=Math.max(0,Math.min(d-1.001,t*(d-1))),y=Math.max(0,Math.min(c-1.001,e*(c-1))),x=Math.floor(g),S=Math.floor(y),A=g-x,k=y-S,U=S*d+x,Y=U+d,I=(b[U]*(1-A)+b[U+1]*A)*(1-k)+(b[Y]*(1-A)+b[Y+1]*A)*k;r[2]=1-Math.exp(-I*2.4);return}if(a==="tilt"){let c=.2+.8*(this.guide?ui(this.guide,"depth",t,e):.6),b=this.edgeSafe?oe(t,e,this.sx/this.sy):1;r[0]=this.tx.value*.024*c*b/this.sx,r[1]=this.ty.value*.024*c*b/this.sy;return}if(i<=.001)return;let o=this.reach,l=(t-this.x.value)*this.sx,s=(e-this.y.value)*this.sy,h=(l*l+s*s)/(o*o);if(a==="reveal"){r[2]=Math.exp(-h*2.4)*i;return}if(h>9)return;let f=this.edgeSafe?oe(t,e,this.sx/this.sy):1,u=0,m=0;if(a==="loupe"){let d=Math.exp(-h*h)*i*.5;u=l*d,m=s*d;let c=Math.sqrt(h)-1;r[2]=Math.exp(-c*c/.018)*i*.55}else if(a==="repel"){let d=Math.sqrt(h),c=o*.5*Math.exp(-h/1.7)*i,b=Math.max(1e-6,Math.sqrt(l*l+s*s));u=l/b*Math.min(c,b+o*.5*i),m=s/b*Math.min(c,b+o*.5*i);let g=Math.max(0,Math.min(1,(d-.3)/.32));r[2]=-(1-g*g*(3-2*g))*i}else if(a==="haze"){let d=s/o+.45,c=Math.exp(-(l*l/(o*o))-d*d/2.6)*i*(.35+.65*Math.min(1,this.speed*1.4+.25));if(c<.002)return;let b=this.clock,g=t*this.sx*9,y=e*this.sy*9+b*2.3,x=Mr(g,y)-.5,S=Mr(g+17.3,y*1.3+b*.7)-.5;u=x*.06*c,m=S*.026*c,r[2]=(Mr(g*1.7+5,y*1.7)-.5)*.35*c}r[0]=u*f/this.sx,r[1]=m*f/this.sy}encode(){let t=this.width,e=this.height,r=this.pixels,i=this.sampled,a=this.engaged;for(let o=0;o<e;o++)for(let l=0;l<t;l++){let s=(o*t+l)*4;if(a?this.sample(l/(t-1),o/(e-1),i):i[0]=i[1]=i[2]=0,this.mode==="bleed"){let h=Math.round(Math.max(-1,Math.min(1,i[2]))*32767+32768);r[s]=h>>>8,r[s+1]=h&255,r[s+2]=128,r[s+3]=0}else{this.mode==="repel"&&(i[0]*=.3,i[1]*=.3);let h=Math.round(Math.max(-1,Math.min(1,i[0]/.16))*32767+32768),f=Math.round(Math.max(-1,Math.min(1,i[1]/.16))*32767+32768);r[s]=h>>>8,r[s+1]=h&255,r[s+2]=f>>>8,r[s+3]=f&255}}}};var ln=.2,hn=.6,cn=3,un=7,wi=(n,t)=>n==="water"?30*t/.55:n==="silk"?28*t:n==="vortex"?38*t:["magnetic","scatter","elastic","lens","smudge"].includes(n)?32*t:["loupe","repel","tilt","haze"].includes(n)?.16*t/.55:0,mn=(n=.5)=>Math.pow(2,(.5-(Number.isFinite(n)?Math.max(0,Math.min(1,n)):.5))*2.4);function Kr(n,t,e,r=!1){if(!e)return t;let i=a=>Math.max(0,Math.min(1,a));switch(n){case"trail":case"contour":return ki(t,e);case"etch":case"ripple":return i(t+e*.35);case"dissolve":{let a=Math.max(0,1+e);return r?1-(1-t)*a:t*a}case"bleed":return i(t+e*(r?-.6:.6));case"loupe":return i(t+e*.3);case"haze":return i(t+e*.5);default:return t}}var Fi=n=>["trail","contour","etch","ripple","bleed","haze"].includes(n),_e=class{constructor(t=1){this.ripple=null;this.cursor=null;this.settle=1;this.mode="water";this.amount=.55;this.radius=.2;this.lensX=.5;this.lensY=.5;this.lensStrength=0;this.previous=null;this.energy=0;this.pending=!1;this.remainder=0;this.quiet=0;this.guide=null;t=Math.max(.25,Math.min(4,t)),this.columns=Math.round(t>=1?128:128*t),this.rows=Math.round(t>=1?128/t:128),this.xScale=Math.max(1,t),this.yScale=Math.max(1,1/t),this.heights=new Float32Array(this.columns*this.rows),this.velocity=new Float32Array(this.heights.length),this.next=new Float32Array(this.heights.length),this.normals=new Float32Array(this.heights.length*2),this.edgeMask=new Float32Array(this.heights.length);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.edgeMask[e*this.columns+r]=oe(r/(this.columns-1),e/(this.rows-1),t);this.refraction={width:this.columns,height:this.rows,pixels:new Uint8Array(this.heights.length*4),strength:30,mode:"water",focus:[.5,.5,0,.2]},this.waterPixels=this.refraction.pixels,this.trail=new br(this.columns,this.rows),this.contour=new gr(this.columns,this.rows),this.afterimage=new pr(this.columns,this.rows),this.clear()}get invertsDensity(){return this.mode==="trail"}get densityTrail(){return["trail","contour","dissolve","etch","ripple","bleed"].includes(this.mode)}get hasRefraction(){return this.active||this.lensStrength>15e-5}get effect(){return this.mode}get engaged(){return he(this.mode)?this.cursor.engaged:this.active}get spotlight(){return this.mode==="reveal"&&this.cursor?this.cursor.focus:null}get signature(){return he(this.mode)&&this.cursor.engaged?this.cursor.focus.map(t=>t.toFixed(4)).join(","):""}setGuide(t){this.cursor&&(this.cursor.guide=t),this.guide=t}get active(){return he(this.mode)?this.cursor.active:this.mode==="ripple"?this.ripple?.active??!1:Ee(this.mode)?this.afterimage.active:this.mode==="contour"?this.contour.active:this.mode==="trail"?this.trail.active:this.pending||this.energy>15e-5}setMode(t){let e=t==="light"||t==="scan"?t:ur(t)??"none";e!==this.mode&&(this.clear(),this.mode=e,this.refraction.mode=e,Ee(e)&&this.afterimage.setMode(e),e==="ripple"&&!this.ripple&&(this.ripple=new dr(this.columns,this.rows)),he(e)&&(this.cursor??(this.cursor=new vr(this.columns,this.rows)),this.cursor.guide=this.guide,this.cursor.setMode(e)),this.refraction.pixels=he(e)?this.cursor.pixels:e==="ripple"?this.ripple.pixels:e==="trail"?this.trail.pixels:e==="contour"?this.contour.pixels:Ee(e)?this.afterimage.pixels:this.waterPixels,this.refraction.strength=wi(e,this.amount),this.refraction.relative=he(e))}configure(t,e=.55,r=.2,i=!1,a=.5){this.setMode(t),this.settle=mn(a),this.refraction.edgeSafe=i,this.afterimage.edgeSafe=i,this.ripple&&(this.ripple.edgeSafe=i),this.amount=Number.isFinite(e)?Math.max(0,Math.min(1,e)):.55,this.radius=Number.isFinite(r)?Math.max(.1,Math.min(1,r)):.2,this.cursor&&(this.cursor.edgeSafe=i,this.cursor.settle=this.settle,this.cursor.setRadius(this.radius)),this.refraction.strength=wi(this.mode,this.amount),this.refraction.focus[2]=this.densityTrail?this.amount:this.lensStrength*this.amount,this.refraction.focus[3]=this.radius,(this.mode==="reveal"||this.mode==="repel")&&this.syncSpot()}syncSpot(){let t=this.cursor.focus;this.refraction.focus=[t[0],t[1],t[2]*(this.mode==="repel"?Math.min(1,this.amount/.55):this.amount),t[3]]}move(t,e,r){if(this.mode==="none"||this.amount===0||!Number.isFinite(t+e))return;if(t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e)),he(this.mode)){this.cursor.move(t,e,r);return}if(this.mode==="ripple"){this.ripple.move(t,e,this.radius,r);return}if(Ee(this.mode)){this.afterimage.move(t,e,this.radius);return}if(this.mode==="contour"){this.contour.move(t,e,this.radius);return}if(this.mode==="trail"){this.trail.move(t,e,this.radius,r);return}if(this.mode!=="water"){!this.previous&&this.lensStrength<.001&&(this.lensX=t,this.lensY=e),this.previous={x:t,y:e},this.pending=!0;return}if(!this.previous){this.previous={x:t,y:e};return}let i=this.previous;this.previous={x:t,y:e};let a=(t-i.x)*this.xScale,o=(e-i.y)*this.yScale,l=Math.hypot(a,o);if(l<1e-5)return;let s=.035+this.radius*.1,h=s*3,f=Math.min(192,Math.max(1,Math.ceil(l/(s*.5)))),u=Math.min(l,1)*95/f;for(let m=0;m<f;m++){let d=(m+.5)/f,c=i.x+(t-i.x)*d,b=i.y+(e-i.y)*d,g=Math.max(1,Math.floor((c-h/this.xScale)*(this.columns-1))),y=Math.min(this.columns-2,Math.ceil((c+h/this.xScale)*(this.columns-1))),x=Math.max(1,Math.floor((b-h/this.yScale)*(this.rows-1))),S=Math.min(this.rows-2,Math.ceil((b+h/this.yScale)*(this.rows-1)));for(let A=x;A<=S;A++)for(let k=g;k<=y;k++){let U=(k/(this.columns-1)-c)*this.xScale,Y=(A/(this.rows-1)-b)*this.yScale,I=Math.exp(-(U*U+Y*Y)/(s*s))*u,P=A*this.columns+k;this.velocity[P]=Math.max(-12,this.velocity[P]-I)}}this.pending=!0,this.quiet=0}leave(){this.cursor?.leave(),this.ripple?.leave(),this.afterimage.leave(),this.contour.leave(),this.trail.leave(),this.previous=null,this.mode!=="water"&&this.lensStrength&&(this.pending=!0)}clear(){this.trail.clear(),this.contour.clear(),this.afterimage.clear(),this.ripple?.clear(),this.cursor?.clear(),this.heights.fill(0),this.velocity.fill(0),this.next.fill(0),this.normals.fill(0),this.refraction.focus[2]=0,this.previous=null,this.lensStrength=0,this.energy=0,this.pending=!1,this.remainder=0,this.quiet=0;for(let t=0;t<this.waterPixels.length;t+=4)this.waterPixels[t]=this.waterPixels[t+2]=128,this.waterPixels[t+1]=this.waterPixels[t+3]=0}step(t){if(!this.active||!Number.isFinite(t))return;if(he(this.mode)){this.cursor.step(t),(this.mode==="reveal"||this.mode==="repel")&&this.syncSpot();return}if(t*=this.settle,this.mode==="ripple"){this.ripple.step(t);return}if(Ee(this.mode)){this.afterimage.step(t);return}if(this.mode==="contour"){this.contour.step(t);return}if(this.mode==="trail"){this.trail.step(t);return}if(this.mode!=="water"){this.stepLight(Math.max(0,Math.min(.05,t)));return}this.remainder+=Math.max(0,Math.min(.05,t));let e=1/120,r=Math.min(this.columns,this.rows)*.3;for(;this.remainder+1e-8>=e;){this.remainder-=e,this.quiet+=e;let a=Math.max(0,Math.min(1,(this.quiet-ln)/hn)),o=a*a*(3-2*a),l=Math.exp(-(3.8+o*cn)*e),s=Math.exp(-o*un*e),h=0;for(let f=1;f<this.rows-1;f++)for(let u=1;u<this.columns-1;u++){let m=f*this.columns+u,d=this.heights[m],c=this.heights[m-1]+this.heights[m+1]+this.heights[m-this.columns]+this.heights[m+this.columns]-4*d,b=Math.min(u,f,this.columns-1-u,this.rows-1-f),g=b<5?.88+b*.024:1,y=(this.velocity[m]+(c*r*r-d*8)*e)*l*g;this.velocity[m]=y,this.next[m]=(d+y*e)*g*s,h=Math.max(h,Math.abs(this.next[m]),Math.abs(y)*.1)}this.heights.set(this.next),this.energy=h,this.pending=!1}if(!this.active){this.clear();return}let i=Math.min(this.columns,this.rows)*.18;for(let a=0;a<this.rows;a++)for(let o=0;o<this.columns;o++){let l=a*this.columns+o,s=(this.heights[a*this.columns+Math.max(0,o-1)]-this.heights[a*this.columns+Math.min(this.columns-1,o+1)])*i,h=(this.heights[Math.max(0,a-1)*this.columns+o]-this.heights[Math.min(this.rows-1,a+1)*this.columns+o])*i,f=Math.tanh(s)*(this.refraction.edgeSafe?this.edgeMask[l]:1),u=Math.tanh(h)*(this.refraction.edgeSafe?this.edgeMask[l]:1);this.normals[l*2]=f,this.normals[l*2+1]=u;let m=Math.round(f*32767+32768),d=Math.round(u*32767+32768);this.refraction.pixels[l*4]=m>>>8,this.refraction.pixels[l*4+1]=m&255,this.refraction.pixels[l*4+2]=d>>>8,this.refraction.pixels[l*4+3]=d&255}}stepLight(t){let e=this.previous,r=1-Math.exp(-30*t),i=1-Math.exp(-12*t);if(e&&(this.lensX+=(e.x-this.lensX)*r,this.lensY+=(e.y-this.lensY)*r),this.lensStrength+=((e?1:0)-this.lensStrength)*i,this.energy=Math.max(e?Math.abs(e.x-this.lensX)+Math.abs(e.y-this.lensY):0,Math.abs((e?1:0)-this.lensStrength)),this.pending=!1,!e&&!this.active){this.clear();return}this.refraction.focus=[this.lensX,this.lensY,this.lensStrength*this.amount,this.radius]}sample(t,e,r){if(he(this.mode)){this.cursor.sample(t,e,r),r[0]*=this.amount/.55,r[1]*=this.amount/.55,r[2]*=this.mode==="reveal"||this.mode==="repel"?Math.min(1,this.amount/.55):this.amount*3;return}if(this.mode==="ripple"){this.ripple.sample(t,e,r),r[2]*=this.amount;return}if(Ee(this.mode)){this.afterimage.sample(t,e,r),r[0]*=this.amount,r[1]*=this.amount,r[2]*=this.amount;return}if(this.mode==="contour"){r[0]=r[1]=0,r[2]=this.contour.sample(t,e)*this.amount*3;return}if(this.mode==="trail"){r[0]=r[1]=0,r[2]=this.trail.sample(t,e)*this.amount*3;return}let i=Math.max(0,Math.min(this.columns-1.001,t*(this.columns-1))),a=Math.max(0,Math.min(this.rows-1.001,e*(this.rows-1))),o=Math.floor(i),l=Math.floor(a),s=i-o,h=a-l,f=(l*this.columns+o)*2,u=f+this.columns*2;for(let m=0;m<2;m++)r[m]=((this.normals[f+m]*(1-s)+this.normals[f+2+m]*s)*(1-h)+(this.normals[u+m]*(1-s)+this.normals[u+2+m]*s)*h)*.08;r[0]*=this.amount/.55,r[1]*=this.amount/.55,r[2]=this.mode==="light"||this.mode==="scan"?fn(t,e,this.refraction,this.xScale/this.yScale):0}};function fn(n,t,e,r){let[i,a,o,l]=e.focus,s=(n-i)*Math.max(1,r)/l,h=(t-a)*Math.max(1,1/r)/l;return e.mode==="light"?Math.exp(-3*(s*s+h*h))*o:e.mode==="scan"?(Math.exp(-s*s*110)*1.3-Math.exp(-s*s*12)*.3)*Math.exp(-h*h*1.8)*o:0}function Ti(n){return"videoWidth"in n?[n.videoWidth,n.videoHeight]:"naturalWidth"in n?[n.naturalWidth,n.naturalHeight]:[n.width,n.height]}var jt=(n,t,e)=>{(n.width!==t||n.height!==e)&&(n.width=t,n.height=e)},Ei={blocks:" \\u2591\\u2592\\u2593\\u2588",braille:" \\u2801\\u2803\\u2807\\u2847\\u28C7\\u28E7\\u28F7\\u28FF",lines:" -\\u2550\\u256A\\u256C",cross:" \\xB7+xX#",diagonal:" /\\u2571\\u2573",diamond:" \\xB7\\u25C7\\u25C8\\u25C6",mixed:" .:+/\\u25C7#@"},dn=new Set(["pointillism","stipple","led","dots"]),pn=.01,gn=.99,yr=.32,bn=.07,Mn=.6,xr=.9;function vn(n){let t=new Uint32Array(256),e=0;for(let o=0;o<n.length;o+=4)n[o+3]<8||(t[Math.min(255,n[o]*.299+n[o+1]*.587+n[o+2]*.114|0)]++,e++);if(!e)return[0,1];let r=o=>{let l=0,s=o*e;for(let h=0;h<256;h++)if((l+=t[h])>=s)return h/255;return 1},i=r(pn),a=r(gn);return a-i<yr&&(i=Math.max(0,Math.min(1-yr,(i+a)/2-yr/2)),a=i+yr),[i,a]}function yn(n,t,e){let r=Math.max(.001,e-t),i=0,a=0;for(let l=0;l<n.length;l+=4){if(n[l+3]<8)continue;let s=((n[l]*.299+n[l+1]*.587+n[l+2]*.114)/255-t)/r;s<=.06||(i+=Math.min(1,s),a++)}if(!a)return xr;let o=Math.min(.99,Math.max(.01,i/a));return Math.min(xr,Math.max(Mn,Math.log(.5)/Math.log(o)))}function xn(n,t=xr){let e=Math.min(...n),r=Math.max(...n);if(!(r-e>1e-4))return null;let i=n.map(o=>(o-e)/(r-e)),a=new Uint8Array(256);for(let o=0;o<256;o++){if(o/255<bn){a[o]=i.indexOf(0);continue}let l=Math.pow(o/255,t),s=0;for(let h=1;h<i.length;h++)Math.abs(i[h]-l)<Math.abs(i[s]-l)&&(s=h);a[o]=s}return a}function Ri(n,t,e,r){n.clearRect(0,0,t,e),n.fillStyle="#fff",n.strokeStyle="#fff",n.lineCap="round",n.lineJoin="round";for(let i of r){if(n.beginPath(),i.kind==="ellipse")n.ellipse((i.x+i.width/2)*t,(i.y+i.height/2)*e,i.width*t/2,i.height*e/2,0,0,Math.PI*2);else if(i.kind==="rectangle")n.rect(i.x*t,i.y*e,i.width*t,i.height*e);else{if(n.lineWidth=(i.size??.05)*t,i.points?.length===1){n.arc(i.points[0][0]*t,i.points[0][1]*e,n.lineWidth/2,0,Math.PI*2),n.fill();continue}i.points?.forEach(([a,o],l)=>l?n.lineTo(a*t,o*e):n.moveTo(a*t,o*e)),n.stroke();continue}n.fill()}}var Ci=new WeakMap;function Ii(n,t,e,r,i,a){Ci.get(n)?.(t,e,r,i,a,!1)}var Sn=n=>Math.max(64,Math.min(4096,Number.isFinite(n)?n:960));function kn(n,t,e){let r=Math.min(1,n/Math.max(t,e));return[Math.max(2,Math.round(t*r)),Math.max(2,Math.round(e*r))]}function An(n,t,e,r,i){let[a,o]=Ti(t);n.clearRect(0,0,e,r),n.save();let l=pi(a,o,e,r,i);n.translate(l.x+l.width/2,l.y+l.height/2),n.rotate(i.rotation*Math.PI/180),n.drawImage(t,-a*l.scale/2,-o*l.scale/2,a*l.scale,o*l.scale),n.restore()}function Pi(n,t,e,r){let i=r.surface,a=n.getContext("2d");if(!a)throw new Error("Canvas is already owned by another renderer.");let o=i(),l=i(!0),s=i(),h=i(),f=i(),u=i(),m=i(),d=i(),c=i(),b=i(),g=0,y=0,x=1,S=xr,A=null,k=null,U=null,Y="",I,P,M=fr(t),X=0,H="",K="",v="",R=new Uint8ClampedArray(0),G=new Uint8ClampedArray(0),q=new Uint8ClampedArray(0),C=null,E="",w=0,F=0,B=0,Z=null,et="",N=new _e,tt=null,dt=new Float32Array(0),lt=i(!0),St=i(),Et=i(),Lt=0,Tt=[0,0,0],yt=[0,0,0,1],ee=[0,0],ct=[0,0,0,0],Qt=Cr(M.color),de=Dr(M.print),kt=new tr(M.color.denoise),L=new er(M.warps,M.warpEdge),z=Sn(e.maxDimension),O=Math.max(256,Math.min(1048576,Number.isFinite(e.maxCells)?e.maxCells:12e3)),rt=O,J=Math.max(.1,Math.min(8,e.pixelRatio??1)),pt=(ut,gt,zt)=>{N.configure(M.hover.effect,M.hover.strength,M.hover.radius,M.hover.edgeSafe,M.hover.decay),N.move(ut,gt,zt)};function Mt(ut,gt=0,zt=960,re=540,Ne=gt*M.motion.speed){Dt(ut,gt,zt,re,Ne,!0)}function Dt(ut,gt,zt,re,Ne,wr){if(Number.isFinite(gt)||(gt=0),!Number.isFinite(zt)||!Number.isFinite(re)||zt<1||re<1)throw new Error("Render dimensions must be positive finite numbers.");let[Ze,ze]=Ti(ut);if(!Ze||!ze)return;let[ht,it]=kn(z,zt,re);jt(n,ht,it),jt(o.canvas,ht,it),jt(s.canvas,ht,it),jt(h.canvas,ht,it),jt(f.canvas,ht,it),Lt!==ht/it&&(Lt=ht/it,N=new _e(Lt),N.setGuide(tt)),N.configure(M.hover.effect,M.hover.strength,M.hover.radius,M.hover.edgeSafe,M.hover.decay),N.step(Math.max(0,Math.min(.05,gt-B))),B=gt;let ce=r.media(ut),p=[X,ht,it,ce.time].join(":"),W=M.style==="dither",T=gi(ht,it,M,rt,J),Q=T.cell,V=T.rowHeight,At=T.columns,Rt=T.rows;if(H!==p||Z!==ce.key||w!==At||F!==Rt){Z=ce.key,H=p,E="",K="",v="",w=At,F=Rt,r.scene?r.scene(o.ctx,ht,it):An(o.ctx,ut,ht,it,M.crop),jt(l.canvas,w,F),l.ctx.clearRect(0,0,w,F),l.ctx.drawImage(o.canvas,0,0,w,F),R=l.ctx.getImageData(0,0,w,F).data,kt.apply(R,w,F),G.length!==R.length&&(G=new Uint8ClampedArray(R.length)),G.set(R);let Nt=M.color;for(let Ft=0;Ft<R.length;Ft+=4){let mt=R[Ft]*.299+R[Ft+1]*.587+R[Ft+2]*.114;for(let ot=0;ot<3;ot++){let Ut=mt+(R[Ft+ot]-mt)*Nt.saturation;R[Ft+ot]=((Ut*(1-Nt.grayscale)+mt*Nt.grayscale)/255-.5)*Nt.contrast*255+127.5+Nt.brightness*255}}if(Qt&&$r(R,Qt),R=L.apply(R,w,F,ht/it),M.color.levels!=="none"){let[Ft,mt]=vn(R),ot=yn(R,Ft,mt),Ut=A===ce.key&&ce.video?.15:1;A=ce.key,y+=(Ft-y)*Ut,x+=(mt-x)*Ut,S+=(ot-S)*Ut}let wt=M.hover,Wt=wt.scope??"all";if(wt.effect!=="none"&&(Wt!=="all"||wt.effect==="tilt")){let Ft=null;if(M.mask.enabled&&M.mask.shapes.length){jt(lt.canvas,w,F),lt.ctx.clearRect(0,0,w,F),Ri(lt.ctx,w,F,M.mask.shapes);let mt=lt.ctx.getImageData(0,0,w,F).data;Ft=new Float32Array(w*F);for(let ot=0;ot<Ft.length;ot++)Ft[ot]=M.mask.invert?1-mt[ot*4+3]/255:mt[ot*4+3]/255}tt=sr(R,w,F,Ft,tt),dt.length!==w*F&&(dt=new Float32Array(w*F));for(let mt=0;mt<dt.length;mt++)dt[mt]=ci(Wt,tt.subject[mt],tt.key);if(wt.effect==="reveal"){jt(St.canvas,w,F);let mt=new ImageData(w,F);for(let ot=0;ot<dt.length;ot++)mt.data[ot*4+3]=dt[ot]*255;St.ctx.putImageData(mt,0,0)}}else tt=null;N.setGuide(tt)}if(!wr){v=K="";return}let Ht=ai(M),_=ni(M),$=!N.active&&!Ht&&!_,nt=[p,w,F,Q,V,J,N.signature].join(":"),xt=N.engaged,bt=N.effect;if(!$||v!==nt){s.ctx.clearRect(0,0,ht,it),s.ctx.globalAlpha=1,s.ctx.globalCompositeOperation="source-over";let Nt=Ne,wt=Ht?M.motion.type:"none",Wt=M.motion.amount??1,Ft=hi(wt);wt!=="none"&&E!==H&&(C=mi(G,w,F,C),E=H);let mt=null;if(W){let ft=$;if(!ft||K!==p){q.length!==R.length&&(q=new Uint8ClampedArray(R.length));let qt=q;if(qt.set(R),xt||wt!=="none")for(let D=0;D<F;D++)for(let Gt=0;Gt<w;Gt++){let ue=Gt/w,Te=D/F,me=Gt,fe=D,Ce=0,_t=0,$t=1;if(xt){N.sample(ue,Te,Tt);let Jt=tt?dt[D*w+Gt]:1;me-=Tt[0]*Jt*w,fe-=Tt[1]*Jt*F,bt==="reveal"?$t=1-.72*Math.min(1,Tt[2]*Jt):bt==="repel"?$t=1+Math.max(-1,Tt[2])*Jt:Ce=Tt[2]/3*Jt}let Ie=(D*w+Gt)*4;Hr(wt,ue,Te,Nt,yt,(R[Ie]*.299+R[Ie+1]*.587+R[Ie+2]*.114)/255,C??void 0,(D*w+Gt)*we),Nr(yt,Wt),(yt[0]||yt[1])&&(Or(yt,me,fe,w,F,ee),me=ee[0],fe=ee[1]),_t=yt[2],$t*=yt[3];let pe=(D*w+Gt)*4;De(R,w,F,me,fe,ct);for(let Jt=0;Jt<3;Jt++){let vt=ct[Jt]/255,Xt=Kr(bt,vt,Ce)+_t;qt[pe+Jt]=Xt*255}qt[pe+3]=ct[3]*$t}vi(qt,w,F,M.dither,gt),l.ctx.putImageData(new ImageData(qt,w,F),0,0),K=ft?p:""}s.ctx.imageSmoothingEnabled=!1,s.ctx.drawImage(l.canvas,0,0,ht,it)}else{let ft=dn.has(M.style);ft&&r.marks&&P===void 0&&(P=r.marks()),mt=ft&&P?.begin(ht,it,M.style==="led"||M.style==="dots")?P:null;let qt=Array.from(Ei[M.style]??M.charset),D=mt?.ctx??s.ctx,Gt=jr(M.ink),ue=bt==="ripple"||bt==="etch",Te=ue&&Gt[0]*.299+Gt[1]*.587+Gt[2]*.114<90?[214,214,214]:Gt,me=M.style==="ascii"||!!Ei[M.style],fe=We(M.style)?M.style:null,Ce=Math.max(3,Math.round(V*.92)),_t=Math.ceil(Q+4),$t=Math.ceil(V+4),Ie=[qt.join(""),Ce,_t,$t,M.ink,M.colorMode].join(":");if(me&&Ie!==et){et=Ie,jt(m.canvas,_t*qt.length,$t),m.ctx.clearRect(0,0,m.canvas.width,$t),m.ctx.font=`${Ce}px monospace`,m.ctx.textBaseline="middle",m.ctx.textAlign="center",m.ctx.fillStyle=M.colorMode==="accent"?M.ink:"#ffffff",qt.forEach((vt,Xt)=>m.ctx.fillText(vt,Xt*_t+_t/2,$t/2)),k=null,Y="";try{let vt=m.ctx.getImageData(0,0,m.canvas.width,m.canvas.height).data;k=qt.map((Xt,ve)=>{let ye=0;for(let se=0;se<m.canvas.height;se++)for(let ge=ve*_t;ge<(ve+1)*_t&&ge<m.canvas.width;ge++)ye+=vt[(se*m.canvas.width+ge)*4+3];return ye})}catch{k=null}}let pe=me&&M.color.levels!=="none";if(pe&&k){let vt=et+":"+S.toFixed(2);vt!==Y&&(Y=vt,U=xn(k,S))}let Jt=Math.max(.001,x-y);if(M.style==="lego"&&g!==Q){g=Q,jt(b.canvas,Math.ceil(Q),Math.ceil(V));let vt=b.ctx;vt.clearRect(0,0,b.canvas.width,b.canvas.height),vt.fillStyle="rgba(255,255,255,.2)",vt.strokeStyle="rgba(0,0,0,.25)",vt.lineWidth=Math.max(.5,J*.6),vt.beginPath(),vt.arc(Q/2,V/2,Q*.28,0,Math.PI*2),vt.fill(),vt.stroke()}D.font=`${Ce}px monospace`,D.textBaseline="middle",D.textAlign="center";for(let vt=0;vt<F;vt++)for(let Xt=0;Xt<w;Xt++){let ve=Xt,ye=vt,se=0,ge=0;if(xt){N.sample(Xt/w,vt/F,Tt);let st=tt?dt[vt*w+Xt]:1;ve=Math.max(0,Math.min(w-1,Xt-Tt[0]*st*w)),ye=Math.max(0,Math.min(F-1,vt-Tt[1]*st*F)),bt==="reveal"?ge=Math.min(1,Tt[2]*st)*.72:bt==="repel"?ge=-Math.max(-1,Tt[2])*st:se=Tt[2]/3*st}if(wt!=="none"){let st=(vt*w+Xt)*4;Hr(wt,Xt/w,vt/F,Nt,yt,(R[st]*.299+R[st+1]*.587+R[st+2]*.114)/255,C??void 0,(vt*w+Xt)*we),Nr(yt,Wt),(yt[0]||yt[1])&&(Or(yt,ve,ye,w,F,ee),ve=ee[0],ye=ee[1])}De(R,w,F,ve,ye,ct);let xe=0;if(ue&&se>.012&&(ct[3]?ct[3]>250&&ct[0]*.299+ct[1]*.587+ct[2]*.114<30:M.hover.scope==="outside")){let st=Math.min(1,(se-.012)/.12);xe=st*st*(3-2*st)}if(!ct[3]){if(!((xe||se>.03)&&M.hover.scope==="outside"&&Fi(bt)))continue;ct[0]=Te[0],ct[1]=Te[1],ct[2]=Te[2],ct[3]=xe?255:Math.min(255,se*640)}let qe=ct[0],Ge=ct[1],Be=ct[2],Fr=(qe*.299+Ge*.587+Be*.114)/255,It=pe?Math.max(0,Math.min(1,(Fr-y)/Jt)):Fr;It=Kr(bt,It,se,!!fe&&de.settings.invert);let Ot=Xt*Q,Ct=vt*V,Se=1,Pe=It;if(wt!=="none"){let st=yt[2]/(pe?Math.max(.5,Jt):1);It=Math.max(0,Math.min(1,It+st)),Pe=Math.max(0,Math.min(1,Pe+st*(Ft?.45:1)))}else Pe=It;xe&&(It=Pe=Math.max(It,.1+xe*.45)),Se=(wt!=="none"?yt[3]:1)*ct[3]/255*(1-ge)*(xe?.3+xe*.45:1),!me&&!fe&&M.colorMode==="accent"&&M.style!=="cmyk"?Se*=It:pe&&M.colorMode==="accent"&&(Se*=.32+.68*Math.pow(It,S)),D.globalAlpha=Se;let le=(It-Fr)*255,Xe;if(mt&&M.colorMode!=="accent"&&M.style==="pointillism")Xe=M.ink;else if(mt&&M.colorMode!=="accent"){if(M.colorMode==="source")mt.ctx.fillColor(qe+le,Ge+le,Be+le);else{let st=Math.round(It*255);mt.ctx.fillColor(st,st,st)}Xe=$e}else Xe=M.colorMode==="source"?`rgb(${qe+le},${Ge+le},${Be+le})`:M.colorMode==="gray"?`rgb(${Math.round(It*255)},${Math.round(It*255)},${Math.round(It*255)})`:M.ink;if(D.fillStyle=Xe,fe)de.paint(D,fe,Xt,vt,Ot,Ct,Q,It,Xe,M.colorMode==="gray"?It*255:qe+le,M.colorMode==="gray"?It*255:Ge+le,M.colorMode==="gray"?It*255:Be+le,M.colorMode);else if(me){let st=pe&&U?U[Math.round(Pe*255)]:Math.max(0,Math.min(qt.length-1,Math.round(Pe*(qt.length-1))));if(M.colorMode==="accent"?k?.[st]===0:qt[st]===" ")continue;M.colorMode==="accent"?D.drawImage(m.canvas,st*_t,0,_t,$t,Math.round(Ot+(Q-_t)/2),Math.round(Ct+(V-$t)/2),_t,$t):D.fillText(qt[st],Ot+Q/2,Ct+V/2)}else if(M.style==="dots")D.beginPath(),D.arc(Ot+Q/2,Ct+V/2,Q*.48*Math.sqrt(It),0,Math.PI*2),D.fill();else if(M.style==="led")D.beginPath(),D.arc(Ot+Q/2,Ct+V/2,Q*.39,0,Math.PI*2),D.fill(),D.globalAlpha=Se*.35,D.fillStyle="#ffffff",D.beginPath(),D.arc(Ot+Q*.43,Ct+V*.4,Q*.11,0,Math.PI*2),D.fill();else if(M.style==="hex"){let st=Ot+Q/2,be=Ct+V/2;D.beginPath();for(let ke=0;ke<6;ke++){let Ye=Math.PI/3*ke,Me=st+Math.cos(Ye)*Q*.49,Le=be+Math.sin(Ye)*V*.49;ke===0?D.moveTo(Me,Le):D.lineTo(Me,Le)}D.closePath(),D.fill()}else if(M.style==="cmyk"){D.fillStyle="#ffffff",D.fillRect(Ot,Ct,Q,V);let st=(Er,Qe)=>Math.max(0,Math.min(255,M.colorMode==="source"?Er+le:M.colorMode==="gray"?It*255:Qe*It)),be=st(qe,Gt[0]),ke=st(Ge,Gt[1]),Ye=st(Be,Gt[2]),Me=1-Math.max(be,ke,Ye)/255,Le=Math.max(.001,1-Me),Hi=[["#00ffff",(1-be/255-Me)/Le,.36,.36],["#ff00ff",(1-ke/255-Me)/Le,.64,.36],["#ffff00",(1-Ye/255-Me)/Le,.5,.66],["#000000",Me,.5,.5]];D.globalCompositeOperation="multiply";for(let[Er,Qe,Oi,Ni]of Hi)Qe>0&&(D.fillStyle=Er,D.beginPath(),D.arc(Ot+Q*Oi,Ct+V*Ni,Q*.48*Math.sqrt(Math.max(0,Qe)),0,Math.PI*2),D.fill());D.globalCompositeOperation="source-over"}else if(M.style==="voxel"){let st=Ot+Q/2,be=Ct+V/2;D.beginPath(),D.moveTo(st,Ct),D.lineTo(Ot+Q,Ct+V*.25),D.lineTo(st,be),D.lineTo(Ot,Ct+V*.25),D.closePath(),D.fill(),D.globalAlpha=Se*.72,D.beginPath(),D.moveTo(Ot,Ct+V*.25),D.lineTo(st,be),D.lineTo(st,Ct+V),D.lineTo(Ot,Ct+V*.75),D.closePath(),D.fill(),D.globalAlpha=Se*.42,D.beginPath(),D.moveTo(st,be),D.lineTo(Ot+Q,Ct+V*.25),D.lineTo(Ot+Q,Ct+V*.75),D.lineTo(st,Ct+V),D.closePath(),D.fill()}else{let st=M.style==="pixel"?0:Math.max(.5,Q*.06);D.fillRect(Ot,Ct,Q-st,V-st),M.style==="lego"&&D.drawImage(b.canvas,Ot,Ct),M.style==="disco"&&(D.fillStyle=`rgba(255,255,255,${.1+Wr(Xt,vt)*.25})`,D.fillRect(Ot,Ct,Q-st,V*.35),D.fillStyle="rgba(0,0,0,.25)",D.fillRect(Ot,Ct+V*.65,Q-st,V*.35-st))}}}if(s.ctx.globalAlpha=1,mt){let ft=mt.finish();ft&&s.ctx.drawImage(ft,0,0)}(M.color.amount||M.lights.length)&&(jt(d.canvas,ht,it),d.ctx.clearRect(0,0,ht,it),d.ctx.drawImage(s.canvas,0,0)),M.color.amount&&(s.ctx.save(),s.ctx.globalCompositeOperation=M.color.blend,s.ctx.globalAlpha=M.color.amount,s.ctx.fillStyle=M.color.tint,s.ctx.fillRect(0,0,ht,it),s.ctx.restore());for(let ft of M.lights){let qt=ft.radius*Math.max(ht,it),D=s.ctx.createRadialGradient(ft.x*ht,ft.y*it,0,ft.x*ht,ft.y*it,qt);D.addColorStop(0,ft.color),D.addColorStop(1,"transparent"),s.ctx.save(),s.ctx.globalCompositeOperation="screen",s.ctx.globalAlpha=ft.intensity,s.ctx.fillStyle=D,s.ctx.fillRect(0,0,ht,it),s.ctx.restore()}(M.color.amount||M.lights.length)&&(s.ctx.globalCompositeOperation="destination-in",s.ctx.drawImage(d.canvas,0,0),s.ctx.globalCompositeOperation="source-over"),M.mask.enabled&&M.mask.shapes.length&&(Ri(f.ctx,ht,it,M.mask.shapes),s.ctx.globalCompositeOperation=M.mask.invert?"destination-out":"destination-in",s.ctx.drawImage(f.canvas,0,0),s.ctx.globalCompositeOperation="source-over");let ot=h.ctx;ot.clearRect(0,0,ht,it),ot.globalAlpha=M.backdrop.opacity;let Ut=M.backdrop;if(Ut.mode==="solid"&&(ot.fillStyle=Ut.color,ot.fillRect(0,0,ht,it)),Ut.mode==="gradient"){let ft=ot.createLinearGradient(0,0,ht,it);ft.addColorStop(0,Ut.color),ft.addColorStop(1,Ut.color2),ot.fillStyle=ft,ot.fillRect(0,0,ht,it)}if(Ut.mode==="source"&&ot.drawImage(o.canvas,0,0),Ut.mode==="blurred"){let ft=Math.max(1,Ut.blur);jt(u.canvas,Math.max(2,Math.round(ht/ft)),Math.max(2,Math.round(it/ft))),u.ctx.drawImage(o.canvas,0,0,u.canvas.width,u.canvas.height),ot.imageSmoothingEnabled=!0,ot.drawImage(u.canvas,0,0,ht,it)}ot.globalAlpha=1,M.effects.characterBloom>0&&(jt(c.canvas,Math.max(2,Math.round(ht/3)),Math.max(2,Math.round(it/3))),c.ctx.clearRect(0,0,c.canvas.width,c.canvas.height),c.ctx.drawImage(s.canvas,0,0,c.canvas.width,c.canvas.height),ot.save(),ot.globalAlpha=M.effects.characterBloom*.8,ot.globalCompositeOperation="screen",ot.filter=`blur(${1+M.effects.characterBloom*4}px)`,ot.drawImage(c.canvas,0,0,ht,it),ot.restore());let ie=N.spotlight;if(ie&&ie[2]>.002){jt(Et.canvas,ht,it);let ft=Et.ctx,qt=ie[3]*Math.min(ht,it)*1.6;ft.globalCompositeOperation="source-over",ft.clearRect(0,0,ht,it),ft.drawImage(o.canvas,0,0),ft.globalCompositeOperation="destination-in";let D=ft.createRadialGradient(ie[0]*ht,ie[1]*it,0,ie[0]*ht,ie[1]*it,qt),Gt=Math.min(1,ie[2]*M.hover.strength/.55);for(let ue of[0,.2,.4,.6,.8,1])D.addColorStop(ue,`rgba(0,0,0,${Gt*Math.exp(-2.4*(ue*1.6)**2)*(1-ue)})`);ft.fillStyle=D,ft.fillRect(0,0,ht,it),tt&&(M.hover.scope??"all")!=="all"&&(ft.imageSmoothingEnabled=!0,ft.drawImage(St.canvas,0,0,ht,it)),ft.globalCompositeOperation="source-over",ot.drawImage(Et.canvas,0,0)}ot.drawImage(s.canvas,0,0),v=$?nt:""}let Vt=Object.entries(M.effects).some(([Nt,wt])=>!["angle","focus","blurType","characterBloom"].includes(Nt)&&typeof wt=="number"&&wt>0);a.clearRect(0,0,ht,it),Vt?(I===void 0&&(I=yi(r.finishCanvas)),I?a.drawImage(I.render(h.canvas,M.effects,gt,J),0,0):a.drawImage(h.canvas,0,0),r.finished(I?"gpu":"unavailable")):(a.drawImage(h.canvas,0,0),r.finished("none"))}let Bt={canvas:n,render:Mt,setPixelRatio(ut){J=Math.max(.1,Math.min(8,Number.isFinite(ut)?ut:1))},get pixelRatio(){return J},setBudget(ut){rt=Math.max(256,Math.min(O,Number.isFinite(ut)?Math.round(ut):O))},get maxCells(){return rt},configure(ut){M=fr(ut),Qt=Cr(M.color),de=Dr(M.print),kt.configure(M.color.denoise),L.configure(M.warps,M.warpEdge),X++},pointer:pt,leave(){N.leave()},get active(){return N.active},get settings(){return fr(M)},get capabilities(){return{gpuFinish:I!==null}},invalidate(){H=""},destroy(){I?.destroy(),P?.destroy(),P=void 0,L.clear(),kt.configure(0);for(let ut of[o,l,s,h,f,u,m,d,c,b,lt,St,Et])ut.canvas.width=ut.canvas.height=1;Z=null,R=new Uint8ClampedArray(0),q=new Uint8ClampedArray(0),C=null,E=""}};return Ci.set(Bt,Dt),Bt}var Li=self,Vr=()=>new OffscreenCanvas(300,150),wn=()=>{let n=Vr(),t=n.getContext("2d");if(!t)throw new Error("Canvas 2D is unavailable.");return{canvas:n,ctx:t}},Kt=null,Sr=null,Ar=null,Je=null,Di={video:!1,time:0,key:0},Ui="none",kr=(n,t=[])=>Li.postMessage(n,t),Fn={surface:wn,media:()=>Di,scene(n,t,e){n.clearRect(0,0,t,e),Ar&&n.drawImage(Ar,0,0)},finishCanvas:()=>Vr(),marks:Jr,finished(n){Ui=n}};Li.onmessage=n=>{let t=n.data;try{switch(t.type){case"init":Sr=Vr(),Kt=Pi(Sr,t.settings,t.limits,Fn),t.pixelRatio!==void 0&&Kt.setPixelRatio(t.pixelRatio),t.budget!==void 0&&Kt.setBudget(t.budget);break;case"source":Ar?.close(),Ar=t.scene,Je={width:t.width,height:t.height},Di={video:t.video,time:t.time,key:t.key};break;case"pointer":Kt?.pointer(t.x,t.y,t.time);break;case"leave":Kt?.leave();break;case"configure":Kt?.configure(t.settings);break;case"budget":Kt?.setBudget(t.cells);break;case"ratio":Kt?.setPixelRatio(t.ratio);break;case"invalidate":Kt?.invalidate();break;case"advance":Kt&&Je&&Ii(Kt,Je,t.time,t.width,t.height,t.motionTime);break;case"render":{if(!Kt||!Sr||!Je){kr({type:"skip",seq:t.seq});break}let e=performance.now();Kt.render(Je,t.time,t.width,t.height,t.motionTime);let r=performance.now()-e,i=Sr.transferToImageBitmap();kr({type:"frame",seq:t.seq,bitmap:i,cost:r,active:Kt.active,finish:Ui},[i]);break}}}catch(e){kr({type:"error",seq:t.type==="render"||t.type==="advance"?t.seq:-1,message:e instanceof Error?e.message:String(e)})}};kr({type:"ready"});})();\n';export{t as default};
1
+ var t='"use strict";(()=>{function De(i,t,e,r,n,a){r=Math.max(0,Math.min(t-1,r)),n=Math.max(0,Math.min(e-1,n));let o=Math.floor(r),l=Math.floor(n),s=r-o,h=n-l,f=(l*t+o)*4;if(s===0&&h===0){for(let S=0;S<4;S++)a[S]=i[f+S];return}let u=(l*t+Math.min(t-1,o+1))*4,m=(Math.min(e-1,l+1)*t+o)*4,d=(Math.min(e-1,l+1)*t+Math.min(t-1,o+1))*4,c=(1-s)*(1-h)*i[f+3],b=s*(1-h)*i[u+3],g=(1-s)*h*i[m+3],y=s*h*i[d+3],x=c+b+g+y;for(let S=0;S<3;S++)a[S]=x?(i[f+S]*c+i[u+S]*b+i[m+S]*g+i[d+S]*y)/x:0;a[3]=x}function _r(i,t,e,r,n,a){if(r>=0&&r<=t-1&&n>=0&&n<=e-1)return De(i,t,e,r,n,a);if(a[0]=a[1]=a[2]=a[3]=0,r<=-1||r>=t||n<=-1||n>=e)return;let o=Math.floor(r),l=Math.floor(n),s=r-o,h=n-l;for(let f=0;f<=1;f++)for(let u=0;u<=1;u++){let m=o+u,d=l+f;if(m<0||m>=t||d<0||d>=e)continue;let c=(d*t+m)*4,b=(u?s:1-s)*(f?h:1-h)*i[c+3];a[0]+=i[c]*b,a[1]+=i[c+1]*b,a[2]+=i[c+2]*b,a[3]+=b}a[3]&&(a[0]/=a[3],a[1]/=a[3],a[2]/=a[3])}var qn=`#version 300 es\nlayout(location=1) in vec4 shape;\nlayout(location=2) in float angle;\nlayout(location=3) in vec4 color;\nlayout(location=4) in float path;\nuniform vec2 size;\n// Rim vertices per quadrant in this draw: a fan of 4 * slots triangles per ellipse, of which only the\n// quadrant\'s own segment count are not empty.\nuniform int slots;\nout vec4 ink;\nconst float W = 0.70710678118;\nvec2 turn(vec2 v, vec2 axis) { return vec2(v.x * axis.x - v.y * axis.y, v.x * axis.y + v.y * axis.x); }\n// Skia\'s Wang\'s formula for a conic at a quarter-pixel tolerance, rounded up to a power of two: how many line segments\n// the GPU canvas tessellates the curve into.\nfloat segments(vec2 p0, vec2 p1, vec2 p2) {\n vec2 center = (min(min(p0, p1), p2) + max(max(p0, p1), p2)) * 0.5;\n p0 -= center; p1 -= center; p2 -= center;\n float maxLength = sqrt(max(max(dot(p0, p0), dot(p1, p1)), dot(p2, p2)));\n vec2 dp = -2.0 * W * p1 + p0 + p2;\n float dw = abs(-2.0 * W + 2.0);\n float numer = length(dp) * 4.0 + max(0.0, maxLength * 4.0 - 1.0) * dw;\n float n = sqrt(max(numer / (4.0 * min(W, 1.0)), 0.0));\n return exp2(ceil(log2(max(1.0, ceil(n)))));\n}\nvoid main() {\n int triangle = gl_VertexID / 3, corner = gl_VertexID % 3;\n vec2 radii = shape.zw;\n vec2 axis = vec2(cos(angle), sin(angle));\n vec2 unit = vec2(0.0);\n if (corner != 0) {\n int k = triangle + corner - 1, quadrant = k / slots;\n // The quadrant\'s own conic, in the frame\'s pixels, decides its segment count.\n vec2 a0 = vec2(1.0, 0.0), a1 = vec2(1.0, 1.0), a2 = vec2(0.0, 1.0);\n if (quadrant == 1) { a0 = vec2(0.0, 1.0); a1 = vec2(-1.0, 1.0); a2 = vec2(-1.0, 0.0); }\n else if (quadrant == 2) { a0 = vec2(-1.0, 0.0); a1 = vec2(-1.0, -1.0); a2 = vec2(0.0, -1.0); }\n else if (quadrant == 3) { a0 = vec2(0.0, -1.0); a1 = vec2(1.0, -1.0); a2 = vec2(1.0, 0.0); }\n float n = min(float(slots), segments(turn(a0 * radii, axis), turn(a1 * radii, axis), turn(a2 * radii, axis)));\n float t = quadrant > 3 ? 0.0 : floor(float(k - quadrant * slots) * n / float(slots)) / n;\n float a = (1.0 - t) * (1.0 - t), b = 2.0 * W * t * (1.0 - t), c = t * t;\n unit = quadrant > 3 ? vec2(1.0, 0.0) : (a0 * a + a1 * b + a2 * c) / (a + b + c);\n }\n vec2 p = shape.xy + turn(unit * radii, axis);\n ink = vec4(color.rgb * color.a, color.a);\n // Drawn upside down and flipped back when resolved: the canvas\'s multisample pattern is the GPU\'s, top-left origin.\n // Each fill is one path: a later path is nearer, and a path\'s own shapes overlap on equal depth, so a sample covered\n // twice by one path is blended once, as a single filled path is.\n gl_Position = vec4(p / size * 2.0 - 1.0, 1.0 - path * exp2(-23.0), 1.0);\n}`,Gn=`#version 300 es\nprecision highp float;\nin vec4 ink;\nout vec4 outColor;\nvoid main() { outColor = ink; }`,Bn=`#version 300 es\nlayout(location=1) in vec4 shape;\nlayout(location=3) in vec4 color;\nlayout(location=4) in float path;\nuniform vec2 size;\nout vec4 ink;\nflat out vec3 disc;\nvoid main() {\n int corner = gl_VertexID;\n vec2 c = vec2(corner == 1 || corner == 2 || corner == 4 ? 1.0 : 0.0, corner == 2 || corner == 4 || corner == 5 ? 1.0 : 0.0);\n float reach = shape.z + 1.0;\n vec2 p = mix(floor(shape.xy - reach), ceil(shape.xy + reach), c);\n ink = vec4(color.rgb * color.a, color.a);\n disc = shape.xyz;\n gl_Position = vec4(p / size * 2.0 - 1.0, 1.0 - path * exp2(-23.0), 1.0);\n}`,Xn=`#version 300 es\nprecision highp float;\nin vec4 ink;\nflat in vec3 disc;\nout vec4 outColor;\nvoid main() {\n float r = disc.z, d = distance(gl_FragCoord.xy, disc.xy);\n float coverage = clamp(d < r ? 0.5 - (d * d - r * r) / (2.0 * max(d, 1e-6)) : r + 0.5 - d, 0.0, 1.0);\n if (coverage <= 0.0) discard;\n outColor = ink * coverage;\n}`;var $e="dot-fill";function Jr(){if(typeof OffscreenCanvas!="function")return null;let i=new OffscreenCanvas(300,150),t=i.getContext("webgl2",{alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1});if(!t)return null;let e=(L,z)=>{let O=t.createShader(L);if(t.shaderSource(O,z),t.compileShader(O),!t.getShaderParameter(O,t.COMPILE_STATUS))throw new Error(t.getShaderInfoLog(O)||"Dot shader failed");return O},r=(L,z)=>{let O=t.createProgram();return t.attachShader(O,e(t.VERTEX_SHADER,L)),t.attachShader(O,e(t.FRAGMENT_SHADER,z)),t.linkProgram(O),t.getProgramParameter(O,t.LINK_STATUS)?O:null},n,a;try{n=r(qn,Gn),a=r(Bn,Xn)}catch{return null}if(!n||!a)return null;let o=t.getUniformLocation(n,"size"),l=t.getUniformLocation(n,"slots"),s=t.getUniformLocation(a,"size"),h=!1,f=!1,u=new Float64Array(6*4096),m=new Float64Array(9*1024),d=[],c=0,b=0,g=0,y=0,x=null,S=t.createVertexArray();t.bindVertexArray(S);let A=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,A);let k=40;t.enableVertexAttribArray(1),t.vertexAttribPointer(1,4,t.FLOAT,!1,k,0),t.vertexAttribDivisor(1,1),t.enableVertexAttribArray(2),t.vertexAttribPointer(2,1,t.FLOAT,!1,k,16),t.vertexAttribDivisor(2,1),t.enableVertexAttribArray(3),t.vertexAttribPointer(3,4,t.FLOAT,!1,k,20),t.vertexAttribDivisor(3,1),t.enableVertexAttribArray(4),t.vertexAttribPointer(4,1,t.FLOAT,!1,k,36),t.vertexAttribDivisor(4,1),t.bindVertexArray(null);let U=Math.min(4,t.getParameter(t.MAX_SAMPLES)),Y=t.createFramebuffer(),I=t.createRenderbuffer(),P=t.createRenderbuffer(),M=0,X=0,H=t.createFramebuffer(),K=t.createRenderbuffer(),v=new Float32Array(10*4096),R=0,G=1,q=1,C=0,E=new Float64Array(40),w=0,F=1,B=0,Z=0,et=0,N=1,tt="#000000",dt=new Map,lt=new OffscreenCanvas(1,1).getContext("2d"),St=L=>Math.max(0,Math.min(255,Number(L)))/255,Et=L=>{let z=dt.get(L);if(z)return z;let O=/^rgb\\(([-+.\\deE]+),([-+.\\deE]+),([-+.\\deE]+)\\)$/.exec(L),rt=O?null:/^#([\\da-f]{2})([\\da-f]{2})([\\da-f]{2})$/i.exec(L);if(O&&O.slice(1).every(J=>Number.isFinite(Number(J))))z=[St(O[1]),St(O[2]),St(O[3]),1];else if(rt)z=[parseInt(rt[1],16)/255,parseInt(rt[2],16)/255,parseInt(rt[3],16)/255,1];else{if(lt.fillStyle="#010203",lt.fillStyle=L,lt.fillStyle==="#010203"&&!/^(#010203|rgb\\(1,2,3\\))$/i.test(L.replace(/\\s/g,"")))return null;lt.clearRect(0,0,1,1),lt.fillRect(0,0,1,1);let[J,pt,Mt,Dt]=lt.getImageData(0,0,1,1).data;z=[J/255,pt/255,Mt/255,Dt/255]}return dt.size>=4096&&dt.clear(),dt.set(L,z),z},Lt=(L,z,O,rt,J)=>{if(w*5+5>E.length){let Mt=new Float64Array(E.length*2);Mt.set(E),E=Mt}let pt=w++*5;E[pt]=L,E[pt+1]=z,E[pt+2]=O,E[pt+3]=rt,E[pt+4]=J},Tt=!0,yt=0,ee=(L,z,O,rt,J,pt)=>{if((R+1)*6>u.length){let Dt=new Float64Array(u.length*2);Dt.set(u),u=Dt}let Mt=R++*6;u[Mt]=L,u[Mt+1]=z,u[Mt+2]=O,u[Mt+3]=rt,u[Mt+4]=J,u[Mt+5]=pt},ct=(L,z,O,rt,J,pt,Mt,Dt,Bt,ut)=>{if((R+1)*10>v.length){let zt=new Float32Array(v.length*2);zt.set(v),v=zt}let gt=R++*10;O>yt&&(yt=O),rt>yt&&(yt=rt),v[gt]=L,v[gt+1]=z,v[gt+2]=O,v[gt+3]=rt,v[gt+4]=J,v[gt+5]=pt,v[gt+6]=Mt,v[gt+7]=Dt,v[gt+8]=Bt,v[gt+9]=ut},Qt=(L,z,O,rt,J,pt,Mt,Dt,Bt)=>{if((L+1)*9>m.length){let gt=new Float64Array(m.length*2);gt.set(m),m=gt}let ut=L*9;m[ut]=z,m[ut+1]=O,m[ut+2]=rt,m[ut+3]=J,m[ut+4]=F,m[ut+5]=Mt,m[ut+6]=Dt,m[ut+7]=Bt,!pt&&d[d.length-1]!==tt&&d.push(tt),m[ut+8]=pt?-1:d.length-1},de={get globalAlpha(){return F},set globalAlpha(L){L>=0&&L<=1&&(F=L)},get fillStyle(){return tt},set fillStyle(L){if(typeof L!="string"||L===tt)return;tt=L;let z=Et(L);z&&([B,Z,et,N]=z)},strokeStyle:"#000000",globalCompositeOperation:"source-over",font:"",textBaseline:"alphabetic",textAlign:"start",beginPath(){w=0},moveTo(){},closePath(){},arc(L,z,O){Lt(L,z,O,O,0)},ellipse(L,z,O,rt,J){Lt(L,z,O,rt,J)},fill(){let L=F*N;if(L<=0)return;let z=++C,O=!1;for(let rt=0;rt<w;rt++){let J=rt*5;E[J+2]>0&&E[J+3]>0&&(Tt?ee(E[J],E[J+1],E[J+2],E[J+3],E[J+4],z):ct(E[J],E[J+1],E[J+2],E[J+3],E[J+4],B,Z,et,L,z),O=!0)}O&&(w===1&&E[2]===E[3]&&E[4]===0&&E[2]>=1?h=!0:f=!0,Tt&&Qt(z,L,B,Z,et,tt===$e,b,g,y))},fillColor(L,z,O){tt=$e,b=L,g=z,y=O,B=Math.max(0,Math.min(255,L))/255,Z=Math.max(0,Math.min(255,z))/255,et=Math.max(0,Math.min(255,O))/255,N=1},fillEllipse(L,z,O,rt,J,pt,Mt,Dt){if(F<=0)return;let Bt=++C;if(!(O>0&&rt>0))return;f=!0;let ut=Math.max(0,Math.min(255,pt))/255,gt=Math.max(0,Math.min(255,Mt))/255,zt=Math.max(0,Math.min(255,Dt))/255;if(!Tt)return ct(L,z,O,rt,J,ut,gt,zt,F,Bt);ee(L,z,O,rt,J,Bt),Qt(Bt,F,ut,gt,zt,!0,pt,Mt,Dt)}},kt=()=>{x||(x=new OffscreenCanvas(G,q).getContext("2d"));let L=x;if(!L)return null;L.canvas.width!==G||L.canvas.height!==q?(L.canvas.width=G,L.canvas.height=q):L.clearRect(0,0,G,q);for(let z=0;z<R;){let O=u[z*6+5],rt=O*9;L.globalAlpha=m[rt+4],L.fillStyle=m[rt+8]<0?`rgb(${m[rt+5]},${m[rt+6]},${m[rt+7]})`:d[m[rt+8]],L.beginPath();let J=z+1<R&&u[(z+1)*6+5]===O;for(;z<R&&u[z*6+5]===O;z++){let pt=z*6,Mt=u[pt],Dt=u[pt+1],Bt=u[pt+2],ut=u[pt+3],gt=u[pt+4];J&&L.moveTo(Mt+Bt,Dt),Bt===ut&&gt===0?L.arc(Mt,Dt,Bt,0,Math.PI*2):L.ellipse(Mt,Dt,Bt,ut,gt,0,Math.PI*2)}L.fill()}return L.globalAlpha=1,L.canvas};return{ctx:de,begin(L,z,O=!0){return t.isContextLost()?!1:c>0?(c--,!1):(Tt=O,yt=0,G=L,q=z,R=0,d=[],h=f=!1,w=0,C=0,F=1,tt="#000000",B=Z=et=0,N=1,!0)},finish(){if(h&&f&&Tt)return c=30,kt();if(t.isContextLost())return null;if(i.width!==G&&(i.width=G),i.height!==q&&(i.height=q),(M!==G||X!==q)&&(M=G,X=q,t.bindRenderbuffer(t.RENDERBUFFER,I),t.renderbufferStorageMultisample(t.RENDERBUFFER,U,t.RGBA8,G,q),t.bindRenderbuffer(t.RENDERBUFFER,P),t.renderbufferStorageMultisample(t.RENDERBUFFER,U,t.DEPTH_COMPONENT24,G,q),t.bindFramebuffer(t.FRAMEBUFFER,Y),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.RENDERBUFFER,I),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.RENDERBUFFER,P),t.bindRenderbuffer(t.RENDERBUFFER,K),t.renderbufferStorage(t.RENDERBUFFER,t.RGBA8,G,q),t.bindFramebuffer(t.FRAMEBUFFER,H),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.RENDERBUFFER,K)),t.bindFramebuffer(t.FRAMEBUFFER,Y),t.viewport(0,0,G,q),t.clearColor(0,0,0,0),t.clearDepth(1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT),R){if(R*10>v.length&&(v=new Float32Array(Math.max(v.length*2,R*10))),Tt)for(let L=0;L<R;L++){let z=L*6,O=u[z+5],rt=O*9,J=L*10,pt=u[z+2],Mt=u[z+3];pt>yt&&(yt=pt),Mt>yt&&(yt=Mt),v[J]=u[z],v[J+1]=u[z+1],v[J+2]=pt,v[J+3]=Mt,v[J+4]=u[z+4],v[J+5]=m[rt+1],v[J+6]=m[rt+2],v[J+7]=m[rt+3],v[J+8]=m[rt],v[J+9]=O}if(t.enable(t.DEPTH_TEST),t.depthFunc(t.LESS),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.bindVertexArray(S),t.bindBuffer(t.ARRAY_BUFFER,A),t.bufferData(t.ARRAY_BUFFER,v.subarray(0,R*10),t.STREAM_DRAW),h&&!f)t.useProgram(a),t.uniform2f(s,G,q),t.drawArraysInstanced(t.TRIANGLES,0,6,R);else{let L=Math.sqrt(Math.max(0,2*yt-.207)),z=Math.min(64,2**Math.ceil(Math.log2(Math.max(1,Math.ceil(L)))));t.useProgram(n),t.uniform2f(o,G,q),t.uniform1i(l,z),t.drawArraysInstanced(t.TRIANGLES,0,z*4*3,R)}t.bindVertexArray(null)}return t.bindFramebuffer(t.READ_FRAMEBUFFER,Y),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,H),t.blitFramebuffer(0,0,G,q,0,0,G,q,t.COLOR_BUFFER_BIT,t.NEAREST),t.bindFramebuffer(t.READ_FRAMEBUFFER,H),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),t.blitFramebuffer(0,0,G,q,0,q,G,0,t.COLOR_BUFFER_BIT,t.NEAREST),t.bindFramebuffer(t.FRAMEBUFFER,null),i},destroy(){x&&(x.canvas.width=x.canvas.height=1),t.deleteProgram(n),t.deleteProgram(a),t.deleteRenderbuffer(I),t.deleteRenderbuffer(P),t.deleteRenderbuffer(K),t.deleteFramebuffer(Y),t.deleteFramebuffer(H),t.getExtension("WEBGL_lose_context")?.loseContext(),i.width=i.height=1}}}var Yn=["rgb","red","green","blue"],Rr=i=>Math.max(0,Math.min(1,i));function Zr(i){let t=new Map([[0,0],[1,1]]);if(Array.isArray(i))for(let e of i.slice(0,64)){if(!Array.isArray(e)||e.length<2||typeof e[0]!="number"||!Number.isFinite(e[0])||typeof e[1]!="number"||!Number.isFinite(e[1]))continue;let r=Math.round(Rr(e[0])*255)/255;!t.has(r)&&t.size>=16||t.set(r,Rr(e[1]))}return[...t].sort((e,r)=>e[0]-r[0])}function Qr(i){let t=i&&typeof i=="object"?i:{};return Object.fromEntries(Yn.map(e=>[e,Zr(t[e])]))}function Tr(i){let t=Zr(i),e=t.length,r=t.slice(1).map((s,h)=>s[0]-t[h][0]),n=t.slice(1).map((s,h)=>(s[1]-t[h][1])/r[h]),a=new Float64Array(e);a[0]=n[0],a[e-1]=n[e-2];for(let s=1;s<e-1;s++){let h=n[s-1],f=n[s];if(h*f<=0)continue;let u=2*r[s]+r[s-1],m=r[s]+2*r[s-1];a[s]=(u+m)/(u/h+m/f)}let o=new Uint8Array(256),l=0;for(let s=0;s<256;s++){let h=s/255;for(;l<e-2&&h>t[l+1][0];)l++;let f=r[l],u=(h-t[l][0])/f,m=u*u,d=m*u,c=(2*d-3*m+1)*t[l][1]+(d-2*m+u)*f*a[l]+(-2*d+3*m)*t[l+1][1]+(d-m)*f*a[l+1];o[s]=Math.round(Rr(c)*255)}return o}function Cr(i){let t=Wn(i),e=i.curves;if(!t&&(!e||Object.values(e).every(o=>o.every(([l,s])=>l===s))))return null;let r=Tr(e?.rgb),n=[e?.red,e?.green,e?.blue].map(Tr),a=new Uint8Array(768);for(let o=0;o<256;o++)for(let l=0;l<3;l++)a[l*256+o]=n[l][r[t?t[o]:o]];return a}function $r(i,t){for(let e=0;e<i.length;e+=4)i[e+3]&&(i[e]=t[i[e]],i[e+1]=t[256+i[e+1]],i[e+2]=t[512+i[e+2]])}function Wn(i){let t=i.blackPoint??0,e=i.whitePoint??1,r=i.gamma??1,n=i.shadows??0,a=i.highlights??0;if(t===0&&e===1&&r===1&&n===0&&a===0)return null;let o=[0,.25+n*.2,.5,.75+a*.2,1],l=o.slice(1).map((f,u)=>(f-o[u])*4),s=[l[0],...l.slice(1).map((f,u)=>2*f*l[u]/(f+l[u])),l[3]],h=new Uint8Array(256);for(let f=0;f<256;f++){let u=Math.pow(Math.max(0,Math.min(1,(f/255-t)/(e-t))),1/r),m=Math.min(3,Math.floor(u*4)),d=u*4-m,c=d*d,b=c*d,g=(2*b-3*c+1)*o[m]+(b-2*c+d)*s[m]/4+(-2*b+3*c)*o[m+1]+(b-c)*s[m+1]/4;h[f]=Math.round(Math.max(0,Math.min(1,g))*255)}return h}var tr=class{constructor(t=0){this.amount=0;this.weights=new Float32Array(256);this.source=new Uint8ClampedArray(0);this.configure(t)}configure(t=0){let e=Math.max(0,Math.min(1,Number.isFinite(t)?t:0));if(e===this.amount)return;if(this.amount=e,e===0){this.source=new Uint8ClampedArray(0);return}let r=8+e*24;for(let n=0;n<256;n++)this.weights[n]=Math.exp(-n*n/(2*r*r))}apply(t,e,r){if(!this.amount)return;if(!Number.isInteger(e)||!Number.isInteger(r)||e<1||r<1||e*r*4!==t.length)throw new Error("Denoise dimensions do not match the source.");this.source.length!==t.length&&(this.source=new Uint8ClampedArray(t.length));let n=this.source;n.set(t);for(let a=0;a<r;a++)for(let o=0;o<e;o++){let l=(a*e+o)*4;if(!n[l+3])continue;let s=n[l],h=n[l+1],f=n[l+2],u=0,m=0,d=0,c=0;for(let b=-1;b<=1;b++){let g=a+b;if(!(g<0||g>=r))for(let y=-1;y<=1;y++){let x=o+y;if(x<0||x>=e)continue;let S=(g*e+x)*4;if(!n[S+3])continue;let A=Math.max(Math.abs(n[S]-s),Math.abs(n[S+1]-h),Math.abs(n[S+2]-f)),k=this.weights[A]*(y===0?1:.6)*(b===0?1:.6)*n[S+3];u+=n[S]*k,m+=n[S+1]*k,d+=n[S+2]*k,c+=k}}t[l]=s+(u/c-s)*this.amount,t[l+1]=h+(m/c-h)*this.amount,t[l+2]=f+(d/c-f)*this.amount}}};var jn=[{value:"twirl",label:"Twirl",description:"Rotate the center into a smooth spiral; the outer boundary stays fixed.",direction:!1,frequency:!1},{value:"pinch",label:"Pinch",description:"Contract the center, or expand it with negative strength.",direction:!1,frequency:!1},{value:"sphere",label:"Spherize",description:"Magnify a rounded lens through the source; negative strength recedes.",direction:!1,frequency:!1},{value:"ripple",label:"Ripple",description:"Bend the image through concentric, soft-edged waves.",direction:!1,frequency:!0},{value:"zigzag",label:"Zigzag",description:"Alternate the twist in sharp, concentric bands.",direction:!1,frequency:!0},{value:"shear",label:"Shear",description:"Slant a region along an adjustable direction.",direction:!0,frequency:!1},{value:"smudge",label:"Smudge",description:"Draw a soft region of the source along one direction.",direction:!0,frequency:!1},{value:"polar",label:"Polar",description:"Unwrap a region into polar coordinates; negative strength wraps it.",direction:!0,frequency:!1},{value:"fragment",label:"Fragment",description:"Offset small source tiles into a stable fractured texture.",direction:!0,frequency:!0}],Kn=8,Ue=(i,t,e,r)=>typeof i=="number"&&Number.isFinite(i)?Math.max(e,Math.min(r,i)):t;function Pr(i){if(!Array.isArray(i))return[];let t=[];for(let e of i.slice(0,64))if(!(!e||typeof e!="object"||!jn.some(r=>r.value===e.type))&&(t.push({type:e.type,enabled:e.enabled!==!1,amount:Ue(e.amount,.35,-1,1),x:Ue(e.x,.5,0,1),y:Ue(e.y,.5,0,1),radius:Ue(e.radius,.55,.05,2),angle:Ue(e.angle,0,-180,180),frequency:Ue(e.frequency,5,1,24)}),t.length===Kn))break;return t}var Ir=Math.PI*2,tn=(i,t)=>{let e=Math.imul(i,374761393)^Math.imul(t,668265263);return e=Math.imul(e^e>>>13,1274126177),((e^e>>>16)>>>0)/4294967296},er=class{constructor(t=[],e="clamp"){this.warps=[];this.signature="";this.geometry="";this.coordinates=new Float32Array(0);this.output=new Uint8ClampedArray(0);this.sampled=[0,0,0,0];this.edge="clamp";this.configure(t,e)}configure(t=[],e="clamp"){let r=Pr(t).filter(a=>a.enabled&&a.amount!==0),n=JSON.stringify(r);this.edge=e==="transparent"?"transparent":"clamp",n!==this.signature&&(this.signature=n,this.geometry="",this.warps=r.map(a=>({...a,cos:Math.cos(a.angle*Math.PI/180),sin:Math.sin(a.angle*Math.PI/180)})),r.length||this.clear())}get active(){return this.warps.length>0}apply(t,e,r,n=e/r){if(!this.active)return t;if(!Number.isInteger(e)||!Number.isInteger(r)||e<1||r<1||e*r*4!==t.length||!Number.isFinite(n)||n<=0)throw new Error("Warp dimensions do not match the source.");let a=`${e}:${r}:${n}`;if(a!==this.geometry){this.coordinates.length!==e*r*2&&(this.coordinates=new Float32Array(e*r*2));let s=Math.max(1,n),h=Math.max(1,1/n);for(let f=0;f<r;f++)for(let u=0;u<e;u++){let m=(u+.5)/e,d=(f+.5)/r;for(let b=this.warps.length-1;b>=0;b--){let g=this.warps[b],y=(m-g.x)*s/g.radius,x=(d-g.y)*h/g.radius,S=y*y+x*x;if(S>=1)continue;let A=Math.sqrt(S),k=(1-S)*(1-S),U=g.amount,Y=y,I=x;if(g.type==="twirl"||g.type==="zigzag"){let P=g.type==="twirl"?-U*Ir*k:U*.65*(2/Math.PI*Math.asin(Math.sin(A*Ir*g.frequency)))*k,M=Math.cos(P),X=Math.sin(P);Y=y*M-x*X,I=y*X+x*M}else if(g.type==="pinch"){let P=Math.exp(U*2*k);Y=y*P,I=x*P}else if(g.type==="sphere"&&A>0){let P=Math.asin(A)*2/Math.PI,M=1+U*k*(P/A-1);Y=y*M,I=x*M}else if(g.type==="ripple"&&A>0){let P=1+U*.12*Math.sin(A*Ir*g.frequency)*k/A;Y=y*P,I=x*P}else if(g.type==="shear"){let P=-y*g.sin+x*g.cos;Y-=U*P*.9*k*g.cos,I-=U*P*.9*k*g.sin}else if(g.type==="smudge")Y-=U*.65*k*g.cos,I-=U*.65*k*g.sin;else if(g.type==="polar"){let P=y*g.cos+x*g.sin,M=-y*g.sin+x*g.cos,X=Math.atan2(M,P),H=U>0?X/Math.PI:Math.cos(P*Math.PI)*(M+1)/2,K=U>0?A*2-1:Math.sin(P*Math.PI)*(M+1)/2,v=H*g.cos-K*g.sin,R=H*g.sin+K*g.cos;Y+=(v-y)*Math.abs(U)*k,I+=(R-x)*Math.abs(U)*k}else if(g.type==="fragment"){let P=Math.floor((y*g.cos+x*g.sin)*g.frequency),M=Math.floor((-y*g.sin+x*g.cos)*g.frequency),X=(tn(P,M)-.5)*U*.5*k,H=(tn(M+71,P-31)-.5)*U*.5*k;Y+=X*g.cos-H*g.sin,I+=X*g.sin+H*g.cos}m=g.x+Y*g.radius/s,d=g.y+I*g.radius/h}let c=(f*e+u)*2;this.coordinates[c]=m*e-.5,this.coordinates[c+1]=d*r-.5}this.geometry=a}this.output.length!==t.length&&(this.output=new Uint8ClampedArray(t.length));let o=t===this.output?t.slice():t,l=this.edge==="transparent"?_r:De;for(let s=0,h=0;s<t.length;s+=4,h+=2){l(o,e,r,this.coordinates[h],this.coordinates[h+1],this.sampled);for(let f=0;f<4;f++)this.output[s+f]=this.sampled[f]}return this.output}clear(){this.coordinates=new Float32Array(0),this.output=new Uint8ClampedArray(0),this.geometry=""}};var Lr=["stipple","engraving","crosshatch","woodblock","risograph","pointillism"];function We(i){return Lr.includes(i)}var rr={density:1,weight:1,angle:-35,roughness:.35,invert:!1,secondaryInk:"#ec6752",registration:.2,seed:7};function nr(i){let t=i&&typeof i=="object"&&!Array.isArray(i)?i:{},e=(r,n,a)=>{let o=t[r];return typeof o=="number"&&Number.isFinite(o)?Math.max(n,Math.min(a,o)):rr[r]};return{density:e("density",0,2),weight:e("weight",.25,2),angle:e("angle",-180,180),roughness:e("roughness",0,1),invert:t.invert===!0,secondaryInk:typeof t.secondaryInk=="string"&&/^#[\\da-f]{6}$/i.test(t.secondaryInk)?t.secondaryInk:rr.secondaryInk,registration:e("registration",0,1),seed:Math.round(e("seed",0,65535))}}var He=Math.PI*2,en=i=>Math.max(0,Math.min(1,i)),ar=.1,rn=i=>Math.max(-ar,Math.min(1+ar,i)),Vn=Float32Array.from({length:2048},(i,t)=>Math.sin(t/2048*He)),nn=i=>Vn[Math.floor(i*(2048/He))&2047];function ir(i,t,e){let r=Math.imul(i,374761393)^Math.imul(t,668265263)^Math.imul(e,1442695041);return r=Math.imul(r^r>>>13,1274126177),((r^r>>>16)>>>0)/4294967296}function Dr(i){let t=nr(i),{density:e,weight:r,angle:n,roughness:a,invert:o,secondaryInk:l,registration:s,seed:h}=t,f=n*Math.PI/180,m=[f,f+Math.PI/2,f+Math.PI/4].map(b=>[Math.cos(b),Math.sin(b)]),d=new Float32Array(6);function c(b,g,y,x,S,A,k,U,Y=!1){if(k<=0)return;let[I,P]=m[U],M=-P,X=I,H=M*(g+.5)+X*(y+.5),K=(Math.abs(M)+Math.abs(X))*.5,v=Y?1:.5,R=Math.ceil((H-K)/v),G=Math.floor((H+K)/v),q=Math.min(v*.94,v*.72*k*r);b.lineWidth=A*q,b.beginPath();for(let C=R;C<=G;C++){let E=C*v-H,w=.5+M*E,F=.5+X*E,B=-2,Z=2;if(Math.abs(I)>1e-8){let et=-w/I,N=(1-w)/I;B=Math.max(B,Math.min(et,N)),Z=Math.min(Z,Math.max(et,N))}else if(w<0||w>1)continue;if(Math.abs(P)>1e-8){let et=-F/P,N=(1-F)/P;B=Math.max(B,Math.min(et,N)),Z=Math.min(Z,Math.max(et,N))}else if(F<0||F>1)continue;if(!(Z<=B))if(Y&&(B-=ar,Z+=ar),!Y)b.moveTo(x+(w+I*B)*A,S+(F+P*B)*A),b.lineTo(x+(w+I*Z)*A,S+(F+P*Z)*A);else{for(let et=0;et<6;et++){let N=B+(Z-B)*et/5,tt=I*(g+w+I*N)+P*(y+F+P*N);d[et]=nn(tt*5.3+C*1.9+h)*.5+nn(tt*13.1+C)*.25}for(let et=0;et<2;et++)for(let N=0;N<6;N++){let tt=B+(Z-B)*(et?5-N:N)/5,dt=d[et?5-N:N],lt=q*.5*(1+a*dt*.5)*(et?-1:1),St=x+rn(w+I*tt+M*lt)*A,Et=S+rn(F+P*tt+X*lt)*A;!et&&!N?b.moveTo(St,Et):b.lineTo(St,Et)}b.closePath()}}Y?b.fill():b.stroke()}return{settings:t,paint(b,g,y,x,S,A,k,U,Y,I,P,M,X){let H=en((o?1-U:U)*e);if(H<=0||b.globalAlpha<=0)return;b.fillStyle=Y,b.strokeStyle=Y;let K=ir(y,x,h);if(g==="engraving"||g==="crosshatch"||g==="woodblock"){let v=H*(1-a*K*.3);g==="woodblock"?c(b,y,x,S,A,k,Math.ceil(v*5)/5,0,!0):(c(b,y,x,S,A,k,v,0),g==="crosshatch"&&(c(b,y,x,S,A,k,Math.max(0,v*1.5-.3),1),c(b,y,x,S,A,k,Math.max(0,v*2-1.2),2)))}else if(g==="risograph"){let v=X==="source"?en(.5+(I-M)/510):.5,R=s*.38*k,G=k*Math.min(.48,.44*Math.sqrt(H)*r);b.beginPath(),b.arc(S+k*.5,A+k*.5,G*Math.sqrt(.35+(1-v)*.65),0,He),b.fill(),b.globalCompositeOperation="multiply",b.fillStyle=l;let q=1-a*ir(y,x,h+13)*.3;b.beginPath(),b.arc(S+k*.5+R*m[0][0],A+k*.5+R*m[0][1],G*Math.sqrt(.3+v*.7)*q,0,He),b.fill(),b.globalCompositeOperation="source-over"}else{let v=b.fillEllipse;g==="stipple"&&b.beginPath();for(let R=0;R<4;R++){let G=ir(y*2+R%2,x*2+(R>>1),h),q=ir(y,x,h+R*11+1),C=S+((R%2+.5)/2+(G-.5)*a*.28)*k,E=A+(((R>>1)+.5)/2+(q-.5)*a*.28)*k,w=Math.min(C-S,S+k-C,E-A,A+k-E,k*Math.min(.245,.21*r*Math.sqrt(H)*(1-a*G*.35)));if(g==="stipple")b.moveTo(C+w,E),b.arc(C,E,w,0,He);else{let F=(G-.5)*a*64;if(v&&X!=="accent"){let B=Math.round(I+F);v(C,E,w,w*.64,G*Math.PI,B,X==="source"?Math.round(P-F*.4):B,X==="source"?Math.round(M-F):B);continue}X==="source"?b.fillStyle=`rgb(${Math.round(I+F)},${Math.round(P-F*.4)},${Math.round(M-F)})`:X==="gray"?b.fillStyle=`rgb(${Math.round(I+F)},${Math.round(I+F)},${Math.round(I+F)})`:b.fillStyle=Y,b.beginPath(),b.ellipse(C,E,w,w*.64,G*Math.PI,0,He),b.fill()}}g==="stipple"&&b.fill()}}}}var _n=new Set(["none","floyd-steinberg","atkinson","stucki","sierra","sierra-lite","burkes","jarvis"]);function an(i){return i.style==="dither"&&(i.dither.motion==="shimmer"||i.dither.motion==="drift"&&i.dither.amount>0&&!_n.has(i.dither.algorithm))}function on(i){return i.motion.type!=="none"&&(i.motion.amount??1)>0}var sn={caustics:"sheen",grain:"shimmer",trace:"relight",tidal:"current",weave:"current",breeze:"current",reform:"develop",print:"develop",unfold:"develop"},Ur=[{value:"none",mode:"none",group:"Still",label:"Off",description:"Keep the image still. Hover stays available."},{value:"relight",mode:"relight",group:"Light",label:"Relight",description:"A key light circles the subject and models its own relief, like moving a lamp around a sculpture."},{value:"sheen",mode:"sheen",group:"Light",label:"Specular sweep",description:"One slow pass of light glances across the highlights and follows their form, then rests."},{value:"glow",mode:"glow",group:"Light",label:"Highlight bloom",description:"The brightest areas breathe a soft halo into their surroundings. Shadows stay deep."},{value:"shimmer",mode:"shimmer",group:"Light",label:"Glints",description:"Sparse glints on bright fine detail, like light on water, metal or an eye. Everything else holds still."},{value:"parallax",mode:"parallax",group:"Depth",label:"Parallax",description:"A slow camera drift: the subject moves against its background, read from the photo\\u2019s own depth cues."},{value:"push",mode:"push",group:"Depth",label:"Slow push",description:"A gentle push toward the subject and back, with nearer areas moving slightly more."},{value:"focus",mode:"focus",group:"Depth",label:"Focus pull",description:"Focus racks from the subject to the background and back; the characters soften out of focus."},{value:"mist",mode:"mist",group:"Atmosphere",label:"Mist",description:"Soft mist drifts through the distance and plain areas, leaving the subject clear."},{value:"current",mode:"current",group:"Atmosphere",label:"Drift",description:"Water swells and glints, falls stream down, sky and clouds drift slowly, like a cinemagraph. Subjects and buildings hold still."},{value:"develop",mode:"develop",group:"Reveal",label:"Develop",description:"The image holds, fades, then develops back in from its highlights to its shadows, like a print in the tray."}];function hn(i){let t=i&&Object.prototype.hasOwnProperty.call(sn,i)?sn[i]:i;return Ur.find(e=>e.value===t||e.mode===t)?.mode??"none"}var je=i=>Math.max(0,Math.min(1,i)),Yt=(i,t,e)=>{let r=je((e-i)/(t-i));return r*r*(3-2*r)},or=(i,t)=>{let e=52.9829189*((i*.06711056+t*.00583715)%1);return e-Math.floor(e)};function Hr(i,t,e,r,n,a=.5,o,l=0){if(n[0]=n[1]=n[2]=0,n[3]=1,i==="none")return n;a=je(a);let s=o?o[l]:a,h=o?o[l+1]:.5+.5*je(1-Math.hypot(t-.5,e-.55)*2),f=o?o[l+2]:Yt(.55,1,a)**2,u=o?o[l+3]:.5,m=o?o[l+4]:0,d=o?o[l+5]:0,c=r*Math.PI/6,b=(r%12+12)%12,g=Yt(0,.12,Math.min(t,1-t,e,1-e));if(i==="relight"){let y=c+.6,x=Math.cos(y),S=Math.sin(y),A=Math.max(-1,Math.min(1,m*x+d*S))+(x*(t-.5)+S*(e-.5))*.35;n[2]=A*.2*(.3+.7*Yt(.04,.3,s)*(1-.6*Yt(.82,1,a)))}else if(i==="sheen"){let y=-.35+1.9*Yt(0,8,b),x=(t*.75+e*.45)/1.2+(m*.75+d*.45)*.05,S=Math.exp(-(((x-y)/.12)**2));n[2]=S*Yt(.3,.8,s)*(1-.5*Yt(.9,1,a))*.45}else if(i==="glow"){let y=.5-.5*Math.cos(c),x=1-.8*y;n[2]=.2*Yt(x-.3,x+.02,f)*Math.sqrt(f)*(1-.65*a)+.05*y*Yt(.6,.95,a)}else if(i==="shimmer"){let y=or(Math.floor(t*160),Math.floor(e*100))*Math.PI*2,x=Math.pow(.5+.5*Math.cos(c*2+y),28);n[2]=x*Yt(.5,.88,a)*(.35+.65*Yt(.1,.55,u))*.42}else if(i==="parallax"){let y=h-.45;n[0]=y*16*Math.sin(c)*g,n[1]=y*7*Math.sin(c*2)*g}else if(i==="push"){let y=.045*(.5-.5*Math.cos(c))*(.7+.6*h)*960,x=o?o[l+6]:.5,S=o?o[l+7]:.5;n[0]=(t-x)*y,n[1]=(e-S)*y}else if(i==="focus"){let y=Math.sin(c),x=y*y*Yt(.35,.85,y>=0?1-h:h);n[2]=(s-a)*x*.75}else if(i==="mist"){let y=Math.pow(1-h,1.5)*(1-.6*u),x=Math.sin(t*4.1-c+Math.sin(e*3.3+c)*.9)*.5+Math.sin(t*7.3+e*2.1-c*2+Math.sin(t*2.7-e*5.1+c)*1.1)*.3+Math.sin(e*5.7-t*1.9+c)*.2;n[2]=Yt(-.3,.9,x)*y*.16*(1-.55*a)}else if(i==="current"){let y=o?.[l+8]??0,x=o?.[l+9]??0,S=o?.[l+10]??0,A=Yt(0,.06,Math.min(t,1-t,e,1-e)),k=o?0:(1-.4*u)*(1-.8*h)*g,U=H=>e*14-H+Math.sin(t*3+H)*1.5,Y=H=>e*16+t*2-H,I=H=>e*29-t*3-H*2,P=H=>t*1.7+e*2.3-H,M=H=>e*26+Math.sin(t*40)*1.5-H*2;n[0]=(Math.sin(U(c))-Math.sin(U(0))+(Math.sin(t*5-e*3+c)-Math.sin(t*5-e*3))*.43)*7*k+((Math.sin(Y(c))-Math.sin(Y(0)))*3.5+(Math.sin(I(c))-Math.sin(I(0)))*1.5)*y*A+(Math.sin(P(c))-Math.sin(P(0)))*5*x*A,n[1]=(Math.sin(t*11+c)-Math.sin(t*11))*2*k+(Math.cos(Y(c))-Math.cos(Y(0)))*.8*y*A+(Math.sin(M(c))-Math.sin(M(0)))*12*S*A;let X=Math.pow(.5+.5*Math.cos(c*2+t*9-e*4+or(Math.floor(t*160),Math.floor(e*100))*6.2831853),24)-Math.pow(.5+.5*Math.cos(t*9-e*4+or(Math.floor(t*160),Math.floor(e*100))*6.2831853),24);n[2]=(Math.cos(U(c))-Math.cos(U(0)))*.03*k+(X*Yt(.5,.85,a)*.3+(Math.cos(Y(c))-Math.cos(Y(0)))*.025)*y*A+(Math.cos(M(c))-Math.cos(M(0)))*.08*S*A}else if(i==="develop"){let y=Yt(7,8.5,b),x=je((b-8.5)/3.5),S=b<8.5?1-y:Yt(0,1,(x*1.45-(1-a)+(or(Math.floor(t*160),Math.floor(e*100))-.5)*.06)/.3);n[2]=-(1-S)*.3,n[3]=1-(1-S)*.9}return n}var cn=i=>i==="relight"||i==="sheen"||i==="glow"||i==="shimmer"||i==="mist";function ln(i){let t=Math.floor(i),e=Math.max(0,Math.min(1,(i-t-.2)/.6));return t+e*e*(3-2*e)}function Or(i,t,e,r,n,a){return a[0]=ln(Math.max(0,Math.min(r-1,t-i[0]/960*r))),a[1]=ln(Math.max(0,Math.min(n-1,e-i[1]/960*n))),a}function Nr(i,t){let e=Math.max(0,Math.min(2,Number.isFinite(t)?t:1));return i[0]*=e,i[1]*=e,i[2]*=e,i[3]=je(1+(i[3]-1)*e),i}var qr=i=>i==="subject"||i==="outside"?i:"all";function Pt(i,t,e,r,n){if(!(n<1))for(let a=0;a<2;a++){for(let o=0;o<r;o++){let l=0,s=o*e;for(let h=-n;h<=n;h++)l+=i[s+Math.max(0,Math.min(e-1,h))];for(let h=0;h<e;h++)t[s+h]=l/(n*2+1),l+=i[s+Math.min(e-1,h+n+1)]-i[s+Math.max(0,h-n)]}for(let o=0;o<e;o++){let l=0;for(let s=-n;s<=n;s++)l+=t[Math.max(0,Math.min(r-1,s))*e+o];for(let s=0;s<r;s++)i[s*e+o]=l/(n*2+1),l+=t[Math.min(r-1,s+n+1)*e+o]-t[Math.max(0,s-n)*e+o]}}}var zr=new Float32Array(0);function sr(i,t,e,r,n){let a=t*e,o=n&&n.width===t&&n.height===e?n:{width:t,height:e,subject:new Float32Array(a),depth:new Float32Array(a),key:"none"},{subject:l,depth:s}=o,h=0;for(let c=0;c<a;c++)i[c*4+3]<250&&h++;let f=c=>(i[c*4]*.2126+i[c*4+1]*.7152+i[c*4+2]*.0722)/255,u="none",m=0;if(h>a*.01)u="alpha";else if(r)u="mask";else{let c=0,b=0,g=0,y=Math.max(1,Math.round(Math.min(t,e)*.03));for(let S=0;S<e;S++)for(let A=0;A<t;A++){if(A>=y&&S>=y&&A<t-y&&S<e-y)continue;let k=f(S*t+A);c+=k,b+=k*k,g++}m=c/Math.max(1,g),Math.sqrt(Math.max(0,b/Math.max(1,g)-m*m))<.07&&(u="ground")}for(let c=0;c<a;c++){let b=i[c*4+3]/255,g=f(c),y=1;if(u==="alpha")y=b;else if(u==="ground"){let x=Math.max(0,Math.min(1,(Math.abs(g-m)-.035)/.12));y=x*x*(3-2*x)}l[c]=y*(r?Math.max(0,Math.min(1,r[c])):1),s[c]=g*b}o.key=u,zr.length<a&&(zr=new Float32Array(a));let d=zr;return Pt(l,d,t,e,Math.max(1,Math.round(Math.min(t,e)*.02))),Pt(s,d,t,e,Math.max(1,Math.round(Math.min(t,e)*.035))),o}function un(i,t,e="ground"){return e==="none"?1:i==="subject"?t:i==="outside"?1-t:1}function mn(i,t,e,r){let n=i[t],a=i.width,o=i.height,l=Math.max(0,Math.min(a-1.001,e*(a-1))),s=Math.max(0,Math.min(o-1.001,r*(o-1))),h=Math.floor(l),f=Math.floor(s),u=l-h,m=s-f,d=f*a+h,c=Math.min(o-1,f+1)*a+h,b=h+1<a?1:0;return(n[d]*(1-u)+n[d+b]*u)*(1-m)+(n[c]*(1-u)+n[c+b]*u)*m}var we=11,Zt=i=>Math.max(0,Math.min(1,i)),j=(i,t,e)=>{let r=Zt((e-i)/(t-i));return r*r*(3-2*r)};function ie(i,t,e=256){let r=0;for(let l=0;l<i.length;l++)i[l]>r&&(r=i[l]);if(r<=0)return 0;let n=new Uint32Array(e);for(let l=0;l<i.length;l++)n[Math.min(e-1,Math.floor(Math.max(0,i[l])/r*e))]++;let a=0,o=i.length*t;for(let l=0;l<e;l++)if(a+=n[l],a>=o)return(l+1)/e*r;return r}var Jn=12e3,Xr=class{constructor(t){this.n=t;this.arrays=[];this.next=0}take(t){this.next===this.arrays.length&&this.arrays.push(new Float32Array(this.n));let e=this.arrays[this.next++];return t?e.set(t):e.fill(0),e}reset(){this.next=0}},lr=null;function Zn(i,t,e,r,n,a,o,l,s){let h=n*a,f=s.take(),u=v=>(Ae(v,f,n,a,o),v),m=(v,R)=>{let G=s.take();for(let q=0;q<h;q++)G[q]=v[q]*R[q];return u(G)},d=u(s.take(t)),c=u(s.take(e)),b=u(s.take(r)),g=u(s.take(i)),y=m(t,t),x=m(t,e),S=m(t,r),A=m(e,e),k=m(e,r),U=m(r,r),Y=m(t,i),I=m(e,i),P=m(r,i),M=s.take(),X=s.take(),H=s.take(),K=s.take();for(let v=0;v<h;v++){let R=Y[v]-d[v]*g[v],G=I[v]-c[v]*g[v],q=P[v]-b[v]*g[v],C=y[v]-d[v]*d[v]+l,E=x[v]-d[v]*c[v],w=S[v]-d[v]*b[v],F=A[v]-c[v]*c[v]+l,B=k[v]-c[v]*b[v],Z=U[v]-b[v]*b[v]+l,et=F*Z-B*B,N=w*B-E*Z,tt=E*B-w*F,dt=C*Z-w*w,lt=E*w-C*B,St=C*F-E*E,Et=C*et+E*N+w*tt,Lt=Math.abs(Et)>1e-12?1/Et:0;M[v]=(et*R+N*G+tt*q)*Lt,X[v]=(N*R+dt*G+lt*q)*Lt,H[v]=(tt*R+lt*G+St*q)*Lt,K[v]=g[v]-M[v]*d[v]-X[v]*c[v]-H[v]*b[v]}u(M),u(X),u(H),u(K);for(let v=0;v<h;v++)i[v]=M[v]*t[v]+X[v]*e[v]+H[v]*r[v]+K[v]}function Ae(i,t,e,r,n){let a=n*2+1;for(let o=0;o<r;o++){let l=o*e,s=0;for(let h=-n;h<=n;h++)s+=i[l+Math.max(0,Math.min(e-1,h))];for(let h=0;h<e;h++)t[l+h]=s/a,s+=i[l+Math.min(e-1,h+n+1)]-i[l+Math.max(0,h-n)]}for(let o=0;o<e;o++){let l=0;for(let s=-n;s<=n;s++)l+=t[Math.max(0,Math.min(r-1,s))*e+o];for(let s=0;s<r;s++)i[s*e+o]=l/a,l+=t[Math.min(r-1,s+n+1)*e+o]-t[Math.max(0,s-n)*e+o]}}function Gr(i,t,e,r,n,a,o){let l=e*r,s=o.take(),h=o.take(t),f=o.take(i),u=o.take(),m=o.take();for(let d=0;d<l;d++)u[d]=t[d]*t[d],m[d]=t[d]*i[d];Ae(h,s,e,r,n),Ae(f,s,e,r,n),Ae(u,s,e,r,n),Ae(m,s,e,r,n);for(let d=0;d<l;d++){let c=(m[d]-h[d]*f[d])/(u[d]-h[d]*h[d]+a);u[d]=c,m[d]=f[d]-c*h[d]}Ae(u,s,e,r,n),Ae(m,s,e,r,n);for(let d=0;d<l;d++)i[d]=u[d]*t[d]+m[d]}function Br(i,t,e,r,n,a=2){for(let o=0;o<a;o++){for(let l=0;l<r;l++)for(let s=0;s<e;s++){let h=l*e+s,f=i[h];s>0&&(f=Math.max(f,Math.min(t[h],i[h-1]*n))),l>0&&(f=Math.max(f,Math.min(t[h],i[h-e]*n),s>0?Math.min(t[h],i[h-e-1]*n):0,s<e-1?Math.min(t[h],i[h-e+1]*n):0)),i[h]=f}for(let l=r-1;l>=0;l--)for(let s=e-1;s>=0;s--){let h=l*e+s,f=i[h];s<e-1&&(f=Math.max(f,Math.min(t[h],i[h+1]*n))),l<r-1&&(f=Math.max(f,Math.min(t[h],i[h+e]*n),s>0?Math.min(t[h],i[h+e-1]*n):0,s<e-1?Math.min(t[h],i[h+e+1]*n):0)),i[h]=f}}}function hr(i,t,e,r,n){for(let a=0;a<r;a++)for(let o=0;o<e;o++){let l=1;for(let s=Math.max(0,o-n);s<=Math.min(e-1,o+n);s++)l=Math.min(l,i[a*e+s]);t[a*e+o]=l}for(let a=0;a<r;a++)for(let o=0;o<e;o++){let l=1;for(let s=Math.max(0,a-n);s<=Math.min(r-1,a+n);s++)l=Math.min(l,t[s*e+o]);i[a*e+o]=l}}function Qn(i,t,e,r,n){let a=e*r,o=Math.min(e,r),l=n.take(),s=n.take(),h=n.take(),f=n.take(),u=n.take();for(let p=0;p<a;p++){let W=i[p*4+3]/255;u[p]=W,l[p]=t[p*4]/255*W,s[p]=t[p*4+1]/255*W,h[p]=t[p*4+2]/255*W,f[p]=(i[p*4]*.299+i[p*4+1]*.587+i[p*4+2]*.114)/255*W}let m=n.take(),d=(p,W)=>{let T=n.take(p);return Pt(T,m,e,r,W),T},c=Math.max(2,Math.round(o*.04)),b=Math.max(c+2,Math.round(o*.12)),g=Math.max(2,Math.round(o*.05)),y=d(f,1),x=d(f,c),S=d(f,b),A=n.take(),k=n.take(),U=n.take(),Y=n.take(),I=n.take();for(let p=0;p<r;p++)for(let W=0;W<e;W++){let T=p*e+W;A[T]=Math.abs(f[T]-y[T]),k[T]=Math.abs(y[T]-x[T]),U[T]=Math.abs(x[T]-S[T]),Y[T]=Math.abs(f[p*e+Math.min(e-1,W+1)]-f[p*e+Math.max(0,W-1)]),I[T]=Math.abs(f[Math.min(r-1,p+1)*e+W]-f[Math.max(0,p-1)*e+W])}Pt(A,m,e,r,g),Pt(k,m,e,r,g),Pt(U,m,e,r,g),Pt(Y,m,e,r,2),Pt(I,m,e,r,2);let P=Math.max(.01,ie(A,.9)+ie(k,.9)),M=d(l,1),X=d(s,1),H=d(h,1),K=n.take(),v=n.take(),R=n.take(),G=0;for(let p=0;p<a;p++){let W=M[p],T=X[p],Q=H[p],V=Math.max(W,T,Q),At=Math.min(W,T,Q),Rt=V-At;R[p]=V,v[p]=V>.001?Rt/V:0,G+=Rt;let Ht=0;Rt>1e-4&&(Ht=V===W?((T-Q)/Rt+6)%6:V===T?(Q-W)/Rt+2:(W-T)/Rt+4),K[p]=Ht*60}let q=j(.02,.07,G/a),C=Math.max(2,Math.round(r*.06)),E=new Float32Array(r);for(let p=0;p<r;p++){let W=0;for(let T=0;T<e;T++)W+=A[p*e+T]+k[p*e+T];E[p]=W/e}let w=.5,F=0;for(let p=Math.max(C,Math.round(r*.12));p<=Math.min(r-C,Math.round(r*.88));p++){let W=0,T=0,Q=0,V=0;for(let it=0;it<e;it++){let xt=0,bt=0,Vt=0,Nt=0,wt=0,Wt=0;for(let mt=1;mt<=C;mt++){let ot=(p-mt)*e+it,Ut=(p+mt-1)*e+it;xt+=M[ot],bt+=X[ot],Vt+=H[ot],Nt+=M[Ut],wt+=X[Ut],Wt+=H[Ut]}let Ft=(Math.abs(xt-Nt)+Math.abs(bt-wt)+Math.abs(Vt-Wt))/C;W+=Ft,T+=Ft>.12?1:0}let At=Math.max(2,Math.round(r*.15)),Rt=Math.max(0,p-At),Ht=Math.min(r,p+At);for(let it=Rt;it<p;it++)Q+=E[it];for(let it=p;it<Ht;it++)V+=E[it];Q/=p-Rt,V/=Ht-p;let _=j(-.05,.3,(V-Q)/(V+Q+1e-4)),$=j(.08,.35,W/e)*(T/e)*_;$>F&&(F=$,w=p/r)}let B=j(.15,.45,F),Z=n.take(),et=n.take(),N=n.take();for(let p=0;p<a;p++)Z[p]=Math.min(l[p],s[p],h[p]);hr(Z,m,e,r,1),Pt(Z,m,e,r,c);for(let p=0;p<a;p++)et[p]=k[p]+U[p];let tt=0,dt=0,lt=0;for(let p=0;p<a;p++)tt+=M[p],dt+=X[p],lt+=H[p];tt/=a,dt/=a,lt/=a;let St=d(M,c),Et=d(X,c),Lt=d(H,c),Tt=d(M,b),yt=d(X,b),ee=d(H,b);for(let p=0;p<a;p++){let W=Math.hypot(St[p]-tt,Et[p]-dt,Lt[p]-lt),T=Math.hypot(St[p]-Tt[p],Et[p]-yt[p],Lt[p]-ee[p]);N[p]=(W+T*1.5)*(.4+.6*v[p]*q+.4*(1-q))}let ct=n.take(),Qt=n.take(),de=n.take(),kt=n.take(),L=n.take(),z=n.take(),O=n.take(),rt=n.take(),J=n.take(),pt=n.take();for(let p=0;p<r;p++)for(let W=0;W<e;W++)pt[p*e+W]=Math.abs(f[Math.min(r-1,p+1)*e+W]-f[Math.max(0,p-1)*e+W]);Pt(pt,m,e,r,1);for(let p=0;p<r;p++)for(let W=0;W<e;W++){let T=p*e+W,Q=(p+.5)/r,V=K[T],At=v[T]*q,Rt=R[T],Ht=A[T]+k[T],_=j(175,200,V)*(1-j(250,275,V))*j(.08,.25,At),$=(1-j(45,65,V)+j(290,330,V))*j(.2,.45,At)*j(.3,.55,Rt),it=(1-j(.15,.35,At))*j(.45,.7,Rt)*B,xt=(1-j(.08,.2,Rt))*B,bt=B>.3?1-j(w,w+.1,Q):1-j(.4,.8,Q),Vt=1-j(.02,.06,Ht),Nt=1-j(.03,.09,Ht);Qt[T]=Math.max(_*Vt,xt*.7*(1-j(.008,.025,Ht)),$*Nt*.9)*bt,de[T]=Math.max(Qt[T],it*Vt*bt),ct[T]=p===0?Qt[T]:0,kt[T]=j(150,172,V)*(1-j(232,250,V))*j(.25,.45,At),O[T]=j(1.3,2.2,(Y[T]+.004)/(I[T]+.004))*j(.35,.55,y[T])*(1-j(.1,.18,v[T]*q))*j(.025,.07,Ht)*j(.025,.045,pt[T]);let wt=1-j(.18,.4,At),Wt=j(.55,.8,Rt)*j(.05,.12,Ht);L[T]=Math.max(kt[T],wt*.85,Wt*.8)}Br(ct,Qt,e,r,.995,1),Br(ct,de,e,r,.8,1);let Mt=0;for(let p=0;p<a;p++)Mt+=ct[p];let Dt=Mt>a*.04&&B>.3;if(Dt)for(let p=0;p<r;p++)for(let W=0;W<e;W++)kt[p*e+W]*=j(w,w+.05,(p+.5)/r);if(Dt){let p=n.take(),W=n.take(),T=n.take();for(let _=0;_<a;_++)p[_]=St[_]*.299+Et[_]*.587+Lt[_]*.114;for(let _=0;_<r;_++)for(let $=0;$<e;$++)W[_*e+$]=y[Math.min(r-1,_+1)*e+$]-y[Math.max(0,_-1)*e+$];let Q=new Uint8Array(a);for(let _=1;_<r-1;_++)for(let $=0;$<e;$++){let it=Math.abs(W[_*e+$]),xt=it>.03;for(let bt=-3;bt<=3&&xt;bt++)bt&&_+bt>=0&&_+bt<r&&Math.abs(W[(_+bt)*e+$])>it&&(xt=!1);Q[_*e+$]=xt?1:0}let V=(_,$,it,xt=!0)=>{let bt=St[$]+Et[$]+Lt[$]+.05,Vt=St[it]+Et[it]+Lt[it]+.05,Nt=Math.abs(St[$]/bt-St[it]/Vt)+Math.abs(Et[$]/bt-Et[it]/Vt)+Math.abs(Lt[$]/bt-Lt[it]/Vt),wt=Math.min(Math.abs(K[$]-K[it]),360-Math.abs(K[$]-K[it])),Wt=Math.max(1-j(.1,.25,Nt),(1-j(15,35,wt))*j(.15,.3,Math.min(v[$],v[it]))),Ft=Math.max(j(2,3,(I[$]+.004)/(Y[$]+.004))*j(.015,.04,A[$]+k[$])*j(.4,.55,A[$]/(A[$]+k[$]+1e-4)),1-j(.12,.25,p[$]));return Wt*(xt?Ft:1)*(1-j(p[it]*.82+.02,p[it]*1.02+.05,p[$]))},At=0,Rt=0;for(let _=Math.max(3,Math.round(r*Math.max(.25,w)));_<Math.round(r*.88);_++){let $=0;for(let xt=0;xt<e;xt++)(Q[(_-1)*e+xt]||Q[_*e+xt]||Q[(_+1)*e+xt])&&$++;if($<e*.5)continue;let it=0;for(let xt=_+1;xt<Math.min(r,2*_);xt++)for(let bt=0;bt<e;bt++)it+=V(_,xt*e+bt,(2*_-xt)*e+bt);it>Rt&&(Rt=it,At=_)}let Ht=j(.05,.1,Rt/a);if(Ht>0)for(let _=At+1;_<Math.min(r,2*At);_++)for(let $=0;$<e;$++){let it=_*e+$;rt[it]=V(At,it,(2*At-_)*e+$)*Ht,J[it]=V(At,it,(2*At-_)*e+$,!1)*Ht,T[it]=rt[it]}Pt(T,m,e,r,1);for(let _=0;_<a;_++)rt[_]=Math.max(rt[_],T[_]),kt[_]=Math.max(kt[_],rt[_])}let Bt=d(kt,b);for(let p=0;p<a;p++)kt[p]*=j(.15,.35,Bt[p]);let ut=d(kt,c);for(let p=0;p<a;p++){kt[p]*=1-Qt[p]*.8;let W=Math.min(Math.abs(K[p]-200),360-Math.abs(K[p]-200));z[p]=j(.28,.45,v[p]*q)*j(55,80,W)*(1-j(.3,.6,J[p]))}let gt=d(z,c);for(let p=0;p<a;p++)z[p]=Math.max(z[p]*(1-(1-j(.15,.3,gt[p]))*j(.55,.7,R[p])*j(.5,.65,v[p])),1-u[p]),L[p]=Math.min(Math.max(L[p],J[p]*.9),Math.max(kt[p],j(.25,.6,ut[p])))*(1-ct[p])*(1-z[p]);Br(kt,L,e,r,.97);let zt=n.take(O),re=Math.max(2,Math.round(r*.12));for(let p=0;p<e;p++){let W=0;for(let T=-re;T<=re;T++)W+=O[Math.max(0,Math.min(r-1,T))*e+p];for(let T=0;T<r;T++)zt[T*e+p]=W/(re*2+1),W+=O[Math.min(r-1,T+re+1)*e+p]-O[Math.max(0,T-re)*e+p]}Pt(zt,m,e,r,1);for(let p=0;p<a;p++)O[p]=j(.2,.45,zt[p])*j(.2,.5,O[p]+zt[p]*.5)*(1-ct[p]);Gr(ct,f,e,r,Math.max(2,Math.round(o*.04)),.002,n),Gr(kt,f,e,r,Math.max(2,Math.round(o*.04)),.002,n),Gr(O,f,e,r,Math.max(2,Math.round(o*.03)),.002,n),Pt(z,m,e,r,1);for(let p=0;p<a;p++)ct[p]=j(.3,.7,ct[p])*u[p],O[p]=j(.3,.7,O[p])*u[p]*(1-ct[p]),kt[p]=j(.3,.7,kt[p])*(1-ct[p])*(1-O[p])*(1-j(.15,.4,z[p]));hr(ct,m,e,r,2),hr(kt,m,e,r,2),hr(O,m,e,r,1),Pt(ct,m,e,r,1),Pt(kt,m,e,r,1),Pt(O,m,e,r,1);let Ne=1/Math.max(.02,ie(N,.97)),wr=1/Math.max(.01,ie(et,.9)),Ze=ie(Z,.97),ze=ie(Z,.1),ht=j(.06,.25,Ze-ze),nt=n.take();for(let p=0;p<r;p++)for(let W=0;W<e;W++){let T=p*e+W,Q=(W+.5)/e,V=(p+.5)/r,At=Math.max(ct[T],kt[T]),Rt=A[T]+k[T]+U[T],Ht=Zt(((A[T]+k[T]*.6)/(Rt+.004)-.25)/.55)*.6+Zt((A[T]+k[T])/P)*.4,_=j(.04,.35,Rt/P)*(1-At),$=Zt((Z[T]-ze)/Math.max(.05,Ze-ze))*.55+(1-Zt(et[T]*wr))*.25+Zt((H[T]-M[T])*2+.3)*.2*q,it=ht*j(.12,.35,x[T])*(.4+.6*B),xt=V<w?.45:.45+.55*j(0,1,(V-w)/Math.max(.15,1-w)),bt=B*xt+(1-B)*(.5+(V-.5)*.4),Vt=A[T]/(A[T]+k[T]+1e-4),Nt=j(.2,.7,(A[T]+k[T])/P)*(.35+.65*B)*(1-At),wt=1-Zt(Math.hypot((Q-.5)*1.2,V-.52)*1.5),Wt=Zt(N[T]*Ne)*(.55+.45*wt),Ft=.3*_,mt=.25*it,ot=.12+.45*B,Ut=.12*Nt,ne=.35*(1-.4*B)*(1-At);nt[T]=(Ft*Ht+mt*(1-$)+ot*bt+Ut*Zt(1.6-Vt*1.6)+ne*Wt+.08*.5)/(Ft+mt+ot+Ut+ne+.08)*(1-.85*ct[T])*(1-.45*kt[T]*(1-B))}let ce=sr(i,e,r);if(ce.key!=="none")for(let p=0;p<a;p++)nt[p]=ce.subject[p]*.7+nt[p]*.3;return Pt(nt,m,e,r,Math.max(1,Math.round(o*.03))),Zn(nt,M,X,H,e,r,Math.max(2,Math.round(o*.07)),.004,n),{depth:nt,water:kt,sky:ct,falls:O}}function cr(i,t,e,r,n,a,o){if(t===a&&e===o)return i[n*a+r];let l=Math.max(0,Math.min(t-1,(r+.5)*t/a-.5)),s=Math.max(0,Math.min(e-1,(n+.5)*e/o-.5)),h=Math.min(t-2,Math.floor(l)),f=Math.min(e-2,Math.floor(s)),u=l-h,m=s-f;if(h<0||f<0)return i[Math.round(s)*t+Math.round(l)];let d=f*t+h,c=d+t;return(i[d]*(1-u)+i[d+1]*u)*(1-m)+(i[c]*(1-u)+i[c+1]*u)*m}function fn(i,t,e,r,n=i){let a=t*e,o=r?.length===a*we?r:new Float32Array(a*we);if(!a)return o;let l=Math.min(t,e),s=new Float32Array(a),h=new Float32Array(a),f=new Float32Array(a),u=new Float32Array(a),m=new Float32Array(a),d=new Float32Array(a);for(let C=0;C<a;C++){let E=i[C*4+3]/255;s[C]=(i[C*4]*.299+i[C*4+1]*.587+i[C*4+2]*.114)/255*E}h.set(s),Pt(h,d,t,e,Math.max(1,Math.round(l*.012))),f.set(s),Pt(f,d,t,e,Math.max(1,Math.round(l*.03)));for(let C=0;C<a;C++){u[C]=Math.abs(s[C]-h[C]);let E=Math.max(0,s[C]-.55)/.45;m[C]=E*E}Pt(u,d,t,e,Math.max(1,Math.round(l*.02)));let c=1/Math.max(.02,ie(u,.95));Pt(m,d,t,e,Math.max(1,Math.round(l*.05)));let b=1/Math.max(.03,ie(m,.98)),g=Math.max(1,Math.ceil(Math.sqrt(a/Jn))),y=Math.max(1,Math.floor(t/g)),x=Math.max(1,Math.floor(e/g)),S=y*x,A=i,k=n;if(g>1){let C=new Uint8ClampedArray(S*4),E=n===i?C:new Uint8ClampedArray(S*4);for(let w=0;w<x;w++)for(let F=0;F<y;F++){let B=[0,0,0,0,0,0,0];for(let N=w*g;N<(w+1)*g;N++)for(let tt=F*g;tt<(F+1)*g;tt++){let dt=(N*t+tt)*4;for(let lt=0;lt<4;lt++)B[lt]+=i[dt+lt];if(E!==C)for(let lt=0;lt<3;lt++)B[4+lt]+=n[dt+lt]}let Z=(w*y+F)*4,et=g*g;for(let N=0;N<4;N++)C[Z+N]=B[N]/et;if(E!==C){for(let N=0;N<3;N++)E[Z+N]=B[4+N]/et;E[Z+3]=C[Z+3]}}A=C,k=E}lr?.n!==S&&(lr=new Xr(S)),lr.reset();let{depth:U,water:Y,sky:I,falls:P}=Qn(A,k,y,x,lr),M=ie(U,.03),X=ie(U,.97),H=Math.max(.05,X-M),K=0,v=0,R=0,G=new Float32Array(a);for(let C=0;C<e;C++)for(let E=0;E<t;E++){let w=C*t+E,F=w*we,B=Zt((cr(U,y,x,E,C,t,e)-M)/H);o[F+1]=B,o[F+8]=Zt(cr(Y,y,x,E,C,t,e)),o[F+9]=Zt(cr(I,y,x,E,C,t,e)),o[F+10]=Zt(cr(P,y,x,E,C,t,e));let Z=B*B*B*(.25+s[w]);K+=(E+.5)/t*Z,v+=(C+.5)/e*Z,R+=Z,G[w]=Math.hypot(f[C*t+Math.min(t-1,E+1)]-f[C*t+Math.max(0,E-1)],f[Math.min(e-1,C+1)*t+E]-f[Math.max(0,C-1)*t+E])}K=R>0?Math.max(.3,Math.min(.7,K/R)):.5,v=R>0?Math.max(.3,Math.min(.7,v/R)):.5;let q=1/Math.max(.004,ie(G,.97));for(let C=0;C<e;C++)for(let E=0;E<t;E++){let w=C*t+E,F=w*we,B=(f[C*t+Math.min(t-1,E+1)]-f[C*t+Math.max(0,E-1)])*q,Z=(f[Math.min(e-1,C+1)*t+E]-f[Math.max(0,C-1)*t+E])*q;o[F]=f[w],o[F+2]=Math.min(1,m[w]*b),o[F+3]=Math.min(1,u[w]*c),o[F+4]=Math.max(-1,Math.min(1,-B)),o[F+5]=Math.max(-1,Math.min(1,-Z)),o[F+6]=K,o[F+7]=v}return o}var $n=[{value:"none",label:"Off",group:"Still",description:"Keep the artwork still under the pointer."},{value:"trail",label:"Trail",group:"Change characters",description:"A fluid wake changes character density and settles behind your cursor."},{value:"dissolve",label:"Dissolve",group:"Change characters",description:"Erase a soft path through the characters; the image gradually reforms."},{value:"contour",label:"Contour",group:"Change characters",description:"Fine tonal rings trace your path without moving the grid."},{value:"etch",label:"Emboss",group:"Change characters",description:"Press a light-and-shadow impression into the characters; the grid stays fixed."},{value:"ripple",label:"Ripple rings",group:"Change characters",description:"Expanding light-and-shadow rings follow your stroke. Faster movement excites stronger rings; the grid stays still."},{value:"bleed",label:"Ink bleed",group:"Change characters",description:"Ink wells up where the cursor rests, spreads along the paper grain, then dries back."},{value:"water",label:"Water",group:"Move the image",description:"Soft ripples refract the image and settle after your stroke."},{value:"silk",label:"Silk",group:"Move the image",description:"Directional folds follow the movement of your hand."},{value:"vortex",label:"Vortex",group:"Move the image",description:"A swirling wake curls through the image."},{value:"magnetic",label:"Magnetic Pull",group:"Move the image",description:"The image gathers toward your stroke, then relaxes."},{value:"scatter",label:"Scatter",group:"Move the image",description:"Characters scatter in soft drifts from your stroke, then spring back into place."},{value:"elastic",label:"Elastic",group:"Move the image",description:"Push the image with your stroke; it recoils past its rest once, then settles."},{value:"lens",label:"Lens wake",group:"Move the image",description:"A soft magnifying wake brings details closer, then relaxes back into focus."},{value:"smudge",label:"Smudge",group:"Move the image",description:"Drag the image in the direction of your stroke; a smooth, lingering pull settles without a bounce."},{value:"loupe",label:"Loupe",group:"Follow the cursor",description:"A glass loupe glides after the cursor and magnifies what it covers, easing through a soft rim."},{value:"reveal",label:"Reveal",group:"Follow the cursor",description:"A soft spotlight shows the original photograph through the characters."},{value:"repel",label:"Repel",group:"Follow the cursor",description:"Characters part around the cursor and spring back with one soft rebound when it leaves."},{value:"tilt",label:"Tilt",group:"Follow the cursor",description:"The image leans toward the cursor; bright areas sit nearer and move more, like a parallax card."},{value:"haze",label:"Heat haze",group:"Follow the cursor",description:"A rising shimmer bends the characters above the cursor, livelier while you move."}],dn={rake:"silk"},Fe={radius:{label:"Hover size",min:.1,max:1,step:.05,default:.2},strength:{label:"Hover strength",min:0,max:1,step:.05,default:.55},decay:{label:"Linger",min:0,max:1,step:.05,default:.5}},pn={effect:"trail",strength:.55,radius:.2,decay:.5,scope:"all",edgeSafe:!1};function ur(i){if(typeof i=="string")return i in dn?dn[i]:$n.some(t=>t.value===i)?i:void 0}var ti=["ascii","blocks","braille","dots","lines","cross","diagonal","diamond","mixed","pixel","mosaic","lego","voxel","disco","dither","hex","led","cmyk",...Lr],ei=["none","bayer2","bayer4","bayer8","bayer16","floyd-steinberg","atkinson","stucki","sierra","sierra-lite","burkes","jarvis","halftone","lines","noise","vertical-lines","diagonal-lines","radial","blue-noise"],ri=["source-over","multiply","screen","overlay","soft-light","hard-light","color-dodge","color-burn","hue","saturation","color","luminosity"],mr={original:[],gray4:["#000000","#555555","#aaaaaa","#ffffff"],gray8:["#000000","#242424","#494949","#6d6d6d","#929292","#b6b6b6","#dbdbdb","#ffffff"],rgb8:["#000000","#ff0000","#00ff00","#0000ff","#ffff00","#ff00ff","#00ffff","#ffffff"],cyberpunk:["#08081a","#3c1670","#ed299a","#29dfef","#fff7bf"],pastel:["#393448","#a5b4d4","#9ed9c6","#e7aac1","#f5e8be"],mono:["#080808","#f2f2e8"],asciify:["#080808","#625b38","#a19558","#e8b900"],gameboy:["#0f380f","#306230","#8bac0f","#9bbc0f"],cga:["#000000","#55ffff","#ff55ff","#ffffff"],pico8:["#000000","#1d2b53","#7e2553","#008751","#ab5236","#5f574f","#c2c3c7","#fff1e8","#ff004d","#ffa300","#ffec27","#00e436","#29adff","#83769c","#ff77a8","#ffccaa"],c64:["#000000","#ffffff","#880000","#aaffee","#cc44cc","#00cc55","#0000aa","#eeee77","#dd8855","#664400","#ff7777","#333333","#777777","#aaff66","#0088ff","#bbbbbb"],amber:["#100b00","#5f3b00","#c98014","#ffd17c"],ice:["#081b29","#25586e","#69a6b3","#d9ece7"],risograph:["#f4ebd0","#f2594b","#2853a5","#29232e"],sepia:["#201b17","#6b5039","#b49868","#f6e6c5"],nord:["#2e3440","#4c566a","#88c0d0","#eceff4"],dusk:["#211b35","#654271","#c3788c","#f5c9a3"],forest:["#101f1b","#355747","#87a16f","#e4e3ba"],ocean:["#071b33","#17577f","#3fa7a4","#d9efde"],newsprint:["#191919","#666666","#aaaaaa","#eee9df"],custom:["#0b0b0a","#e6e3da"]},ni={version:1,aspectRatio:"original",style:"ascii",cellSize:6,charset:" .:-=+*#%@",colorMode:"accent",ink:"#e6e3da",print:{...rr},crop:{x:.5,y:.5,zoom:1,rotation:0},warps:[],warpEdge:"clamp",backdrop:{mode:"solid",color:"#080808",color2:"#1d1d1b",blur:12,opacity:1},color:{brightness:0,contrast:1,saturation:1,grayscale:0,tint:"#e6e3da",amount:0,blend:"source-over",blackPoint:0,whitePoint:1,gamma:1,shadows:0,highlights:0,curves:{rgb:[[0,0],[1,1]],red:[[0,0],[1,1]],green:[[0,0],[1,1]],blue:[[0,0],[1,1]]},denoise:0,levels:"auto"},dither:{algorithm:"none",palette:"mono",colors:["#080808","#e6e3da"],amount:1,scale:2,threshold:.5,motion:"none",speed:1,direction:45,colorSpace:"rgb"},mask:{enabled:!1,invert:!1,shapes:[]},lights:[],effects:{bloom:0,characterBloom:0,grain:0,dust:0,scanlines:0,crt:0,prism:0,rgbSplit:0,sharpen:0,vignette:0,glitch:0,pixelate:0,blur:0,blurType:"gaussian",angle:0,focus:.5,halftone:0},motion:{type:"none",speed:1,amount:1},hover:{effect:"trail",strength:.55,radius:.2,edgeSafe:!1}},ae=i=>i&&typeof i=="object"&&!Array.isArray(i)?i:{},at=(i,t,e,r)=>typeof i=="number"&&Number.isFinite(i)?Math.min(r,Math.max(e,i)):t,Oe=(i,t)=>typeof i=="string"&&/^#[\\da-f]{6}$/i.test(i)?i:t,te=(i,t,e)=>t.includes(i)?i:e;function fr(i={}){let t=ae(i),e=ni;if(t.version!==void 0&&t.version!==1)throw new Error("Unsupported studio settings version. Update asciify-engine.");let r=ae(t.crop),n=ae(t.backdrop),a=ae(t.color),o=ae(t.dither),l=ae(t.mask),s=ae(t.effects),h=ae(t.motion),f=ae(t.hover),u={...e.effects};for(let d of["bloom","characterBloom","grain","dust","scanlines","crt","prism","rgbSplit","sharpen","vignette","glitch","pixelate","halftone"])u[d]=at(s[d],0,0,1);u.blur=at(s.blur,0,0,24),u.blurType=te(s.blurType,["gaussian","directional","radial","progressive"],e.effects.blurType),u.angle=at(s.angle,0,-180,180),u.focus=at(s.focus,.5,0,1);let m=2048;return{version:1,aspectRatio:te(t.aspectRatio,["original","16:9","9:16","1:1","4:3","3:4","21:9"],"original"),style:te(t.style,ti,e.style),cellSize:at(t.cellSize,e.cellSize,We(String(t.style))||["pixel","mosaic","lego","voxel","disco","dots","hex","led","cmyk"].includes(String(t.style))?1:3,60),charset:typeof t.charset=="string"&&t.charset.length?Array.from(t.charset).slice(0,128).join(""):e.charset,colorMode:te(t.colorMode,["accent","source","gray"],e.colorMode),ink:Oe(t.ink,e.ink),print:nr(t.print),warps:Pr(t.warps),warpEdge:te(t.warpEdge,["clamp","transparent"],"clamp"),crop:{x:at(r.x,.5,0,1),y:at(r.y,.5,0,1),zoom:at(r.zoom,1,1,5),rotation:Math.round(at(r.rotation,0,-360,360)/90)*90},backdrop:{mode:te(n.mode,["solid","transparent","source","blurred","gradient"],e.backdrop.mode),color:Oe(n.color,e.backdrop.color),color2:Oe(n.color2,e.backdrop.color2),blur:at(n.blur,12,0,32),opacity:at(n.opacity,1,0,1)},color:{brightness:at(a.brightness,0,-1,1),contrast:at(a.contrast,1,0,3),saturation:at(a.saturation,1,0,3),grayscale:at(a.grayscale,0,0,1),tint:Oe(a.tint,e.color.tint),amount:at(a.amount,0,0,1),blend:te(a.blend,ri,e.color.blend),blackPoint:at(a.blackPoint,0,0,.99),whitePoint:Math.max(at(a.blackPoint,0,0,.99)+1/255,at(a.whitePoint,1,1/255,1)),gamma:at(a.gamma,1,.25,4),shadows:at(a.shadows,0,-1,1),highlights:at(a.highlights,0,-1,1),curves:Qr(a.curves),denoise:at(a.denoise,0,0,1),levels:a.levels==="none"?"none":"auto"},dither:{algorithm:te(o.algorithm,ei,"none"),palette:typeof o.palette=="string"&&Object.prototype.hasOwnProperty.call(mr,o.palette)?o.palette:"mono",colors:Array.isArray(o.colors)&&o.colors.length>=2?o.colors.slice(0,32).map(d=>Oe(d,"#000000")):[...e.dither.colors],amount:at(o.amount,1,0,2),scale:Math.round(at(o.scale,2,1,12)),threshold:at(o.threshold,.5,0,1),motion:te(o.motion,["none","drift","shimmer"],"none"),speed:at(o.speed,1,.1,3),direction:at(o.direction,45,-180,180),colorSpace:te(o.colorSpace,["rgb","luminance"],"rgb")},mask:{enabled:l.enabled===!0,invert:l.invert===!0,shapes:Array.isArray(l.shapes)?l.shapes.slice(0,64).map(d=>{let c=ae(d),b=te(c.kind,["rectangle","ellipse","brush"],"rectangle"),g=b==="brush"&&Array.isArray(c.points)?c.points.slice(0,m).map(y=>Array.isArray(y)?[Math.round(at(y[0],0,0,1)*1e4)/1e4,Math.round(at(y[1],0,0,1)*1e4)/1e4]:[0,0]):[];return m-=g.length,{kind:b,x:at(c.x,0,0,1),y:at(c.y,0,0,1),width:at(c.width,.5,0,1),height:at(c.height,.5,0,1),size:at(c.size,.05,.005,.5),points:g}}):[]},lights:Array.isArray(t.lights)?t.lights.slice(0,4).map(d=>{let c=ae(d);return{x:at(c.x,.5,0,1),y:at(c.y,.5,0,1),radius:at(c.radius,.3,.02,1),intensity:at(c.intensity,.5,0,1),color:Oe(c.color,"#ffffff")}}):[],effects:u,motion:{type:te(typeof h.type=="string"?hn(h.type):h.type,Ur.map(d=>d.mode),"none"),speed:at(h.speed,1,.1,3),amount:at(h.amount,1,0,2)},hover:{effect:ur(f.effect)??pn.effect,strength:at(f.strength,Fe.strength.default,Fe.strength.min,Fe.strength.max),radius:at(f.radius,Fe.radius.default,Fe.radius.min,Fe.radius.max),edgeSafe:f.edgeSafe===!0,...qr(f.scope)!=="all"&&{scope:qr(f.scope)},...at(f.decay,.5,0,1)!==.5&&{decay:at(f.decay,.5,0,1)}}}}function gn(i,t,e,r,n){let a=Math.abs(n.rotation/90)%2===1,o=a?t:i,l=a?i:t,s=Math.max(e/o,r/l)*n.zoom;return{width:o*s,height:l*s,x:(e-o*s)*n.x,y:(r-l*s)*n.y,scale:s,rotated:a}}function bn(i,t,e,r=12e3,n=1){let a=Math.max(2,Number.isFinite(i)?i:960),o=Math.max(2,Number.isFinite(t)?t:540),l=Math.max(1,Math.floor(Number.isFinite(r)?r:12e3)),s=Math.max(.01,Number.isFinite(n)?n:1),h=We(e.style)||["dither","pixel","mosaic","lego","voxel","disco","dots","hex","led","cmyk"].includes(e.style)?1:1.65,f=Math.max(1,Math.ceil(Math.sqrt(a*o/(l*h))/s));for(;Math.ceil(a/(f*s))*Math.ceil(o/(f*s*h))>l;)f++;let u=e.style==="dither"?e.dither.scale:e.cellSize,m=Math.max(f,u)*s;return{cell:m,rowHeight:m*h,columns:Math.ceil(a/m),rows:Math.ceil(o/(m*h)),minimum:f,limited:u<f}}var Mn="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",vn="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",Ke=new Uint16Array(4096);for(let i=0;i<Ke.length;i++)Ke[i]=Mn.indexOf(vn[i*2])<<6|Mn.indexOf(vn[i*2+1]);var Wr=(i,t)=>{let e=Math.sin(i*127.1+t*311.7)*43758.5453;return e-Math.floor(e)};function ii(i,t,e){let r=0;for(let n=1;n<e;n*=2){let a=(Math.floor(i/n)%2+2)%2,o=(Math.floor(t/n)%2+2)%2;r=r*4+[[0,2],[3,1]][o][a]}return(r+.5)/(e*e)-.5}var ai=new Map([2,4,8,16].map(i=>[i,Float64Array.from({length:i*i},(t,e)=>ii(e%i,Math.floor(e/i),i))])),oi={"floyd-steinberg":[[1,0,7/16],[-1,1,3/16],[0,1,5/16],[1,1,1/16]],atkinson:[[1,0,.125],[2,0,.125],[-1,1,.125],[0,1,.125],[1,1,.125],[0,2,.125]],stucki:[[1,0,8/42],[2,0,4/42],[-2,1,2/42],[-1,1,4/42],[0,1,8/42],[1,1,4/42],[2,1,2/42],[-2,2,1/42],[-1,2,2/42],[0,2,4/42],[1,2,2/42],[2,2,1/42]],sierra:[[1,0,5/32],[2,0,3/32],[-2,1,2/32],[-1,1,4/32],[0,1,5/32],[1,1,4/32],[2,1,2/32],[-1,2,2/32],[0,2,3/32],[1,2,2/32]],"sierra-lite":[[1,0,.5],[-1,1,.25],[0,1,.25]],burkes:[[1,0,8/32],[2,0,4/32],[-2,1,2/32],[-1,1,4/32],[0,1,8/32],[1,1,4/32],[2,1,2/32]],jarvis:[[1,0,7/48],[2,0,5/48],[-2,1,3/48],[-1,1,5/48],[0,1,7/48],[1,1,5/48],[2,1,3/48],[-2,2,1/48],[-1,2,3/48],[0,2,5/48],[1,2,3/48],[2,2,1/48]]},jr=i=>[parseInt(i.slice(1,3),16),parseInt(i.slice(3,5),16),parseInt(i.slice(5,7),16)];function yn(i,t,e,r,n=0){let{algorithm:a,amount:o,threshold:l}=r,s=a==="blue-noise",h=a.startsWith("bayer")?Number(a.slice(5)):0,f=ai.get(h),u=h-1,m=r.colorSpace==="luminance",c=(r.palette==="custom"?r.colors:mr[r.palette]??mr.mono).map(jr),b=oi[a],g=b?new Float32Array(t*3*3):null,y=r.motion==="drift"?n*r.speed*3:0,x=(r.direction??45)*Math.PI/180,S=Math.round(Math.cos(x)*y),A=Math.round(Math.sin(x)*y),k=(I,P)=>(I%P+P)%P,U=c.map(I=>I[0]*.299+I[1]*.587+I[2]*.114),Y=r.motion==="shimmer"?Math.sin(n*r.speed*2)*.15:0;for(let I=0;I<e;I++)for(let P=0;P<t;P++){let M=(I*t+P)*4,X=(I%3*t+P)*3;if(i[M+3]===0){g&&(g[X]=g[X+1]=g[X+2]=0);continue}let H=0,K=s?(Ke[(I-A&63)*64+(P-S&63)]+.5)/Ke.length:0;f?H=f[(I-A&u)*h+(P-S&u)]:a==="noise"?H=Wr(P-S,I-A)-.5:a==="lines"?H=k(I-A,4)/3-.5:a==="vertical-lines"?H=k(P-S,4)/3-.5:a==="diagonal-lines"?H=k(P-S+I-A,4)/3-.5:a==="radial"?H=k(Math.hypot(P-t/2,I-e/2)-y,6)/6-.5:a==="halftone"&&(H=Math.hypot(k(P-S,6)-2.5,k(I-A,6)-2.5)/3.54-.5);let v=(H*o+Y+(.5-l))*128,R=i[M]+v+(g?.[X]??0),G=i[M+1]+v+(g?.[X+1]??0),q=i[M+2]+v+(g?.[X+2]??0),C=0,E=0,w=0;if(c.length){let F=1/0,B=1/0,Z=0,et=0,N=R*.299+G*.587+q*.114;for(let tt=0;tt<c.length;tt++){let dt=c[tt],lt=m?(N-U[tt])**2:(R-dt[0])**2*.299+(G-dt[1])**2*.587+(q-dt[2])**2*.114;lt<F?(s&&(B=F,et=Z,Z=tt),F=lt,[C,E,w]=dt):s&&lt<B&&(B=lt,et=tt)}if(s&&o>0&&Number.isFinite(B)){let tt=c[et],dt=tt[0]-C,lt=tt[1]-E,St=tt[2]-w,Et=U[et]-U[Z],Lt=m?Et*Et:dt*dt*.299+lt*lt*.587+St*St*.114,Tt=m?(N-U[Z])*Et:(R-C)*dt*.299+(G-E)*lt*.587+(q-w)*St*.114,yt=Lt?Math.max(0,Math.min(1,Tt/Lt*o)):0;K<yt&&([C,E,w]=tt)}}else if(s){let F=Math.max(0,Math.min(1,.5+(K-.5)*o));C=Math.floor(R/51+1-F)*51,E=Math.floor(G/51+1-F)*51,w=Math.floor(q/51+1-F)*51}else C=Math.round(R/51)*51,E=Math.round(G/51)*51,w=Math.round(q/51)*51;if(i[M]=C,i[M+1]=E,i[M+2]=w,g&&b){g[X]=g[X+1]=g[X+2]=0;for(let[F,B,Z]of b){let et=P+F;if(et<0||et>=t||I+B>=e)continue;let N=((I+B)%3*t+et)*3;g[N]+=(R-C)*Z*o,g[N+1]+=(G-E)*Z*o,g[N+2]+=(q-w)*Z*o}}}}function xn(i=()=>document.createElement("canvas")){let t=i(),e=t.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,antialias:!1,preserveDrawingBuffer:!0});if(!e)return null;let r=[],n=(m,d)=>{let c=e.createShader(m);if(r.push(c),e.shaderSource(c,d),e.compileShader(c),!e.getShaderParameter(c,e.COMPILE_STATUS))throw new Error(e.getShaderInfoLog(c)||"Finish shader failed");return c},a=e.createProgram();if(e.attachShader(a,n(e.VERTEX_SHADER,"attribute vec2 p;varying vec2 uv;void main(){uv=(p+1.)*.5;gl_Position=vec4(p,0.,1.);}")),e.attachShader(a,n(e.FRAGMENT_SHADER,`precision mediump float;varying vec2 uv;uniform sampler2D src;uniform vec2 size;uniform float t,bloom,grain,dust,scanlines,crt,prism,vignette,glitch,pixelate,blur,blurMode,angle,focus,halftone,rgbSplit,sharpen;\n float hash(vec2 p){return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453);}\n vec4 sampleAt(vec2 p){if(min(min(p.x,p.y),min(1.-p.x,1.-p.y))<0.)return vec4(0.);return texture2D(src,vec2(p.x,1.-p.y));}\n void main(){vec2 q=uv,c=q-.5;q=c*(1.+dot(c,c)*crt*.25)+.5;\n if(glitch>0.)q.x+=(hash(vec2(floor(q.y*35.),floor(t*5.)))-.5)*.07*glitch*step(.82,hash(vec2(floor(q.y*35.),floor(t*5.)+3.)));\n if(pixelate>0.){vec2 grid=size/(1.+pixelate*20.);q=(floor(q*grid)+.5)/grid;}\n vec4 base=sampleAt(q);float edge=smoothstep(.12,.65,length(c));\n vec2 shift=vec2((prism*3.*edge+rgbSplit*8.)/size.x,prism*edge/size.y);\n if(prism>0.||rgbSplit>0.)base.rgb=vec3(sampleAt(q+shift).r,base.g,sampleAt(q-shift).b);\n vec2 dir=vec2(cos(angle),sin(angle))/size;float amount=blur;\n if(blurMode>1.5&&blurMode<2.5){dir=normalize(c+vec2(.0001))/size;amount*=length(c)*2.;}\n if(blurMode>2.5)amount*=smoothstep(.05,.5,abs(q.y-focus));\n vec4 blurred=base;\n if(amount>0.){blurred=base*.2;for(int i=1;i<=4;i++){float f=float(i)*amount*.35;vec2 off=dir*f;if(blurMode<.5)off=vec2(cos(float(i)*1.57),sin(float(i)*1.57))*amount/size;blurred+=sampleAt(q+off)*.1+sampleAt(q-off)*.1;}}\n vec3 light=vec3(0.);\n // Bloom: a wide golden-angle disc of soft-kneed highlights, screened on, so light spills like halation instead of ghosting glyphs.\n if(bloom>0.){float total=0.;for(int i=0;i<16;i++){float f=float(i);vec2 o=vec2(cos(f*2.39996),sin(f*2.39996))*(2.+f*1.6)/size;vec3 s=sampleAt(q+o).rgb;float w=1./(1.+f*.18);light+=s*smoothstep(.35,.9,max(s.r,max(s.g,s.b)))*w;total+=w;}light*=bloom*3.2/total;}\n vec3 col=1.-(1.-blurred.rgb)*(1.-min(light,vec3(1.)));\n if(sharpen>0.){vec2 px=1./size;vec3 near=sampleAt(q+vec2(px.x,0.)).rgb+sampleAt(q-vec2(px.x,0.)).rgb+sampleAt(q+vec2(0.,px.y)).rgb+sampleAt(q-vec2(0.,px.y)).rgb;col+=(base.rgb*4.-near)*sharpen*.5;}\ncol*=1.-scanlines*.4*(.5+.5*cos(q.y*size.y*3.14159));\n col*=1.-vignette*smoothstep(.15,.72,length(c));\n // Film grain: soft triangular noise, strongest in the midtones, quiet in deep shadow and paper-white highlights.\n float luma=dot(col,vec3(.299,.587,.114));vec2 g=floor(q*size/1.25)+floor(t*24.)*vec2(7.,13.);\n col+=(hash(g)+hash(g+31.7)-1.)*grain*.17*(.2+3.2*luma*(1.-luma));\n if(dust>0.)col+=step(1.-dust*.002,hash(floor(q*size*.25)+floor(t*2.)))*.4;\n if(halftone>0.)col*=mix(1.,smoothstep(.1,.65,length(fract(q*size/6.)-.5)),halftone);\n gl_FragColor=vec4(clamp(col,0.,1.),blurred.a);}`)),e.linkProgram(a),!e.getProgramParameter(a,e.LINK_STATUS))throw new Error("Finish link failed");e.useProgram(a);let o=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,o),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),e.STATIC_DRAW);let l=e.getAttribLocation(a,"p");e.enableVertexAttribArray(l),e.vertexAttribPointer(l,2,e.FLOAT,!1,0,0);let s=e.createTexture();e.bindTexture(e.TEXTURE_2D,s),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);let h=["t","bloom","grain","dust","scanlines","crt","prism","rgbSplit","sharpen","vignette","glitch","pixelate","blur","blurMode","angle","focus","halftone"],f=Object.fromEntries(h.map(m=>[m,e.getUniformLocation(a,m)])),u=e.getUniformLocation(a,"size");return{canvas:t,render(m,d,c,b=1){(t.width!==m.width||t.height!==m.height)&&(t.width=m.width,t.height=m.height,e.viewport(0,0,t.width,t.height)),e.useProgram(a),e.bindTexture(e.TEXTURE_2D,s),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,m),e.uniform2f(u,t.width/b,t.height/b);for(let g of h)e.uniform1f(f[g],g==="t"?c:g==="blurMode"?["gaussian","directional","radial","progressive"].indexOf(d.blurType):g==="angle"?d.angle*Math.PI/180:d[g]??0);return e.drawArrays(e.TRIANGLE_STRIP,0,4),t},destroy(){e.deleteTexture(s),e.deleteBuffer(o),e.deleteProgram(a),r.forEach(m=>e.deleteShader(m)),t.width=t.height=1,e.getExtension("WEBGL_lose_context")?.loseContext()}}}function oe(i,t,e){let r=Math.min(i*Math.max(1,e),(1-i)*Math.max(1,e),t*Math.max(1,1/e),(1-t)*Math.max(1,1/e)),n=Math.max(0,Math.min(1,(r-.035)/.105));return n*n*n*(n*(n*6-15)+10)}var dr=class{constructor(t,e){this.edgeSafe=!1;this.rings=new Float64Array(40);this.slot=0;this.clock=0;this.lastRing=-1;this.previous=null;this.alive=!1;this.width=t,this.height=e,this.pixels=new Uint8Array(t*e*4),this.values=new Float32Array(t*e),this.clear()}get active(){return this.alive}clear(){this.rings.fill(0),this.values.fill(0),this.pixels.fill(0);for(let t=0;t<this.pixels.length;t+=4)this.pixels[t]=128;this.previous=null,this.alive=!1,this.slot=0,this.lastRing=-1,this.clock=0}leave(){this.previous=null}move(t,e,r,n){if(!Number.isFinite(t+e+r))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e));let a=Number.isFinite(n)?n/1e3:this.clock,o=this.previous;if(this.previous={x:t,y:e,time:a},!o)return;let l=this.width/this.height,s=Math.hypot((t-o.x)*Math.max(1,l),(e-o.y)*Math.max(1,1/l));if(s<1e-4||this.clock-this.lastRing<1/24)return;let h=s/Math.max(1/240,Math.min(.1,a-o.time||1/60)),f=this.slot*5;this.slot=(this.slot+1)%8,this.rings[f]=t,this.rings[f+1]=e,this.rings[f+2]=0,this.rings[f+3]=Math.min(.9,.26+h*.2),this.rings[f+4]=.035+Math.max(.1,Math.min(1,r))*.13,this.alive=!0,this.lastRing=this.clock}step(t){if(!Number.isFinite(t)||t<=0)return;let e=Math.min(.05,t);if(this.clock+=e,!this.alive)return;this.values.fill(0),this.alive=!1;let r=this.width/this.height,n=Math.max(1,r),a=Math.max(1,1/r);for(let o=0;o<this.rings.length;o+=5){if(!this.rings[o+3])continue;let l=this.rings[o+2]+=e;if(l>2.8){this.rings[o+3]=0;continue}this.alive=!0;let s=this.rings[o+4],h=l*.17,f=this.rings[o+3]*(1-Math.exp(-l*20))*Math.exp(-l*2.5),u=h+s*1.8,m=this.rings[o],d=this.rings[o+1],c=Math.max(0,Math.floor((m-u/n)*(this.width-1))),b=Math.min(this.width-1,Math.ceil((m+u/n)*(this.width-1))),g=Math.max(0,Math.floor((d-u/a)*(this.height-1))),y=Math.min(this.height-1,Math.ceil((d+u/a)*(this.height-1)));for(let x=g;x<=y;x++)for(let S=c;S<=b;S++){let k=(Math.hypot((S/(this.width-1)-m)*n,(x/(this.height-1)-d)*a)-h)/s;Math.abs(k)>1.8||(this.values[x*this.width+S]+=f*Math.cos(k*Math.PI*2)*Math.exp(-k*k*2.5))}}for(let o=0;o<this.height;o++)for(let l=0;l<this.width;l++){let s=o*this.width+l,h=this.values[s]=Math.max(-1,Math.min(1,this.values[s]))*(this.edgeSafe?oe(l/(this.width-1),o/(this.height-1),r):1),f=Math.round(h*32767+32768);this.pixels[s*4]=f>>>8,this.pixels[s*4+1]=f&255}}sample(t,e,r){let n=Math.max(0,Math.min(this.width-1.001,t*(this.width-1))),a=Math.max(0,Math.min(this.height-1.001,e*(this.height-1))),o=Math.floor(n),l=Math.floor(a),s=n-o,h=a-l,f=l*this.width+o,u=f+this.width;r[0]=r[1]=0,r[2]=((this.values[f]*(1-s)+this.values[f+1]*s)*(1-h)+(this.values[u]*(1-s)+this.values[u+1]*s)*h)*3}};var Ee=i=>["dissolve","silk","vortex","magnetic","scatter","etch","elastic","lens","smudge"].includes(i),Sn=i=>i==="elastic"||i==="scatter",kn={elastic:[150,4.2],scatter:[90,3.6]},pr=class{constructor(t,e){this.edgeSafe=!1;this.previous=null;this.peak=0;this.scatterDirections=null;this.springX=null;this.springY=null;this.mode="dissolve";this.width=t,this.height=e;let r=t*e;this.pixels=new Uint8Array(r*4),this.ink=new Float32Array(r),this.targetX=new Float32Array(r),this.targetY=new Float32Array(r),this.offsetX=new Float32Array(r),this.offsetY=new Float32Array(r),this.edge=new Float32Array(r);for(let n=0;n<e;n++)for(let a=0;a<t;a++)this.edge[n*t+a]=oe(a/(t-1),n/(e-1),t/e);this.clear()}get active(){return this.peak>2e-4}setMode(t){if(Sn(t)&&!this.springX&&(this.springX=new Float32Array(this.ink.length),this.springY=new Float32Array(this.ink.length)),t==="scatter"&&!this.scatterDirections){let e=this.scatterDirections=new Float64Array(this.width*this.height*2),r=(n,a)=>{let o=Math.sin(n*127.1+a*311.7)*43758.5453;return o-Math.floor(o)};for(let n=0;n<this.height;n++)for(let a=0;a<this.width;a++){let o=a*.09,l=n*.09,s=Math.floor(o),h=Math.floor(l),f=o-s,u=l-h,m=f*f*(3-2*f),d=u*u*(3-2*u),b=((r(s,h)*(1-m)+r(s+1,h)*m)*(1-d)+(r(s,h+1)*(1-m)+r(s+1,h+1)*m)*d)*Math.PI*4,g=(n*this.width+a)*2;e[g]=Math.cos(b)*.7,e[g+1]=Math.sin(b)*.7}}t!==this.mode&&(this.mode=t,this.clear())}clear(){for(let t of[this.ink,this.targetX,this.targetY,this.offsetX,this.offsetY,this.pixels])t.fill(0);if(this.previous=null,this.peak=0,this.springX?.fill(0),this.springY?.fill(0),this.mode!=="dissolve")for(let t=0;t<this.pixels.length;t+=4)this.pixels[t]=this.pixels[t+2]=128}leave(){this.previous=null}move(t,e,r){if(!Number.isFinite(t+e+r))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e));let n=this.previous;this.previous={x:t,y:e};let a=this.width,o=this.height,l=Math.max(1,a/o),s=Math.max(1,o/a),h=n?(t-n.x)*l:0,f=n?(e-n.y)*s:0,u=Math.hypot(h,f);if(!n&&this.mode!=="dissolve"&&this.mode!=="etch"&&this.mode!=="lens"||n&&u<1e-4)return;let m=.035+Math.max(.1,Math.min(1,r))*.11,d=Math.min(128,Math.max(1,Math.ceil(u/(m*.45)))),c=u?h/u:1,b=u?f/u:0,g=!n&&this.mode==="lens"?.32:Math.min(1,u/(m*d)*2.2);for(let y=0;y<d;y++){let x=(y+.5)/d,S=n?n.x+(t-n.x)*x:t,A=n?n.y+(e-n.y)*x:e,k=Math.max(0,Math.floor((S-m*2.5/l)*(a-1))),U=Math.min(a-1,Math.ceil((S+m*2.5/l)*(a-1))),Y=Math.max(0,Math.floor((A-m*2.5/s)*(o-1))),I=Math.min(o-1,Math.ceil((A+m*2.5/s)*(o-1)));for(let P=Y;P<=I;P++)for(let M=k;M<=U;M++){let X=(M/(a-1)-S)*l/m,H=(P/(o-1)-A)*s/m,K=Math.exp(-(X*X+H*H)*1.5),v=P*a+M;if(this.mode==="dissolve"||this.mode==="etch")this.ink[v]=Math.max(this.ink[v],K);else if(this.mode==="elastic")this.springX[v]=Math.max(-24,Math.min(24,this.springX[v]+c*K*g*12)),this.springY[v]=Math.max(-24,Math.min(24,this.springY[v]+b*K*g*12));else if(this.mode==="scatter"){let R=this.scatterDirections;this.springX[v]=Math.max(-24,Math.min(24,this.springX[v]+(X*.6+R[v*2])*K*g*7)),this.springY[v]=Math.max(-24,Math.min(24,this.springY[v]+(H*.6+R[v*2+1])*K*g*7))}else if(this.mode==="lens")this.targetX[v]=Math.max(-.65,Math.min(.65,this.targetX[v]+X*K*g*1.6)),this.targetY[v]=Math.max(-.65,Math.min(.65,this.targetY[v]+H*K*g*1.6));else if(this.mode==="smudge")this.targetX[v]=Math.max(-1,Math.min(1,this.targetX[v]+c*K*g*1.3)),this.targetY[v]=Math.max(-1,Math.min(1,this.targetY[v]+b*K*g*1.3));else{let R=(-X*b+H*c)*K*2.8,G=this.mode==="magnetic"?-X*K*2.5:this.mode==="silk"?c*R:-H*K*2.5,q=this.mode==="magnetic"?-H*K*2.5:this.mode==="silk"?b*R:X*K*2.5;this.targetX[v]=Math.max(-1,Math.min(1,this.targetX[v]+G*g)),this.targetY[v]=Math.max(-1,Math.min(1,this.targetY[v]+q*g))}}}this.peak=1}step(t){if(!this.active||!Number.isFinite(t))return;let e=Math.max(0,Math.min(.05,t)),r=this.mode==="dissolve"?2.15:this.mode==="smudge"?2.4:3.2,n=this.mode==="lens"?16:22,a=Math.exp(-r*e),o=1-Math.exp(-n*e),l=0,[s,h]=this.mode==="scatter"?kn.scatter:kn.elastic,f=Math.sqrt(s-h*h),u=Math.exp(-h*e),m=Math.cos(f*e),d=Math.sin(f*e)/f;for(let c=0;c<this.ink.length;c++)if(this.mode==="etch")this.ink[c]*=a,l=Math.max(l,this.ink[c]);else if(this.mode==="dissolve"){this.ink[c]*=a,l=Math.max(l,this.ink[c]);let b=Math.round(this.ink[c]*65535);this.pixels[c*4]=b>>>8,this.pixels[c*4+1]=b&255}else{if(Sn(this.mode)){let y=this.offsetX[c],x=this.offsetY[c],S=this.springX[c],A=this.springY[c];this.offsetX[c]=Math.max(-1,Math.min(1,u*(y*m+(S+h*y)*d))),this.offsetY[c]=Math.max(-1,Math.min(1,u*(x*m+(A+h*x)*d))),this.springX[c]=u*(S*m-(h*S+s*y)*d),this.springY[c]=u*(A*m-(h*A+s*x)*d),l=Math.max(l,Math.abs(this.springX[c])*.05,Math.abs(this.springY[c])*.05)}else if(this.mode==="lens"||this.mode==="smudge"){let y=1-o,x=n/(n-r)*(a-y);this.offsetX[c]=this.offsetX[c]*y+this.targetX[c]*x,this.offsetY[c]=this.offsetY[c]*y+this.targetY[c]*x,this.targetX[c]*=a,this.targetY[c]*=a}else this.targetX[c]*=a,this.targetY[c]*=a,this.offsetX[c]+=(this.targetX[c]-this.offsetX[c])*o,this.offsetY[c]+=(this.targetY[c]-this.offsetY[c])*o;l=Math.max(l,Math.abs(this.offsetX[c]),Math.abs(this.offsetY[c]),Math.abs(this.targetX[c]),Math.abs(this.targetY[c]));let b=Math.round(this.offsetX[c]*(this.edgeSafe?this.edge[c]:1)*32767+32768),g=Math.round(this.offsetY[c]*(this.edgeSafe?this.edge[c]:1)*32767+32768);this.pixels[c*4]=b>>>8,this.pixels[c*4+1]=b&255,this.pixels[c*4+2]=g>>>8,this.pixels[c*4+3]=g&255}if(this.mode==="etch")for(let c=0;c<this.height;c++)for(let b=0;b<this.width;b++){let g=c*this.width+b,y=(this.ink[c*this.width+Math.max(0,b-1)]-this.ink[c*this.width+Math.min(this.width-1,b+1)]+this.ink[Math.max(0,c-1)*this.width+b]-this.ink[Math.min(this.height-1,c+1)*this.width+b])*3;this.offsetX[g]=Math.max(-1,Math.min(1,y))*(this.edgeSafe?this.edge[g]:1);let x=Math.round(this.offsetX[g]*32767+32768);this.pixels[g*4]=x>>>8,this.pixels[g*4+1]=x&255}this.peak=l,this.active||this.clear()}sample(t,e,r){let n=Math.max(0,Math.min(this.width-1.001,t*(this.width-1))),a=Math.max(0,Math.min(this.height-1.001,e*(this.height-1))),o=Math.floor(n),l=Math.floor(a),s=n-o,h=a-l,f=l*this.width+o,u=f+this.width,m=d=>(d[f]*(1-s)+d[f+1]*s)*(1-h)+(d[u]*(1-s)+d[u+1]*s)*h;if(this.mode==="etch"){r[0]=r[1]=0,r[2]=m(this.offsetX)*3;return}r[0]=m(this.offsetX)*(this.edgeSafe?oe(t,e,this.width/this.height):1)*.08,r[1]=m(this.offsetY)*(this.edgeSafe?oe(t,e,this.width/this.height):1)*.08,r[2]=this.mode==="dissolve"?-m(this.ink)*6:0}};var gr=class{constructor(t,e){this.rings=[];this.previous=null;this.elapsed=1;this.echoPeak=0;this.width=t,this.height=e,this.pixels=new Uint8Array(t*e*4),this.echo=new Float32Array(t*e)}get active(){return this.rings.length>0||this.echoPeak>2e-4}clear(){this.rings=[],this.previous=null,this.elapsed=1,this.pixels.fill(0),this.echo.fill(0),this.echoPeak=0}leave(){this.previous=null}move(t,e,r){let n=Math.max(1,this.width/this.height),a=Math.max(1,this.height/this.width);this.previous&&(Math.hypot((t-this.previous.x)*n,(e-this.previous.y)*a)<.065||this.elapsed<.3)||this.rings.length!==4&&(this.previous={x:t,y:e},this.elapsed=0,this.rings.push({x:t,y:e,age:0,radius:r}))}ringSample(t,e){let r=Math.max(1,this.width/this.height),n=Math.max(1,this.height/this.width),a=0;for(let o of this.rings){let l=.015+o.age*(.15+o.radius*.22),s=.009+o.radius*.014,h=(Math.hypot((t-o.x)*r,(e-o.y)*n)-l)/s,f=Math.sin(Math.min(1,o.age/.07)*Math.PI/2)*Math.max(0,1-o.age/1.35)**2;a=Math.max(a,Math.exp(-h*h)*f)}return a}sample(t,e){let r=Math.max(0,Math.min(this.width-1,Math.round(t*(this.width-1)))),n=Math.max(0,Math.min(this.height-1,Math.round(e*(this.height-1))));return Math.max(this.ringSample(t,e),this.echo[n*this.width+r])}step(t){if(!Number.isFinite(t))return;let e=Math.max(0,Math.min(.05,t));this.elapsed+=e;for(let a of this.rings)a.age+=e;if(this.rings=this.rings.filter(a=>a.age<1.35),!this.active){this.pixels.fill(0);return}let r=Math.exp(-5.5*e),n=0;for(let a=0;a<this.height;a++)for(let o=0;o<this.width;o++){let l=a*this.width+o;this.echo[l]=Math.max(this.ringSample(o/(this.width-1),a/(this.height-1)),this.echo[l]*r),n=Math.max(n,this.echo[l]);let s=Math.round(this.echo[l]*65535),h=l*4;this.pixels[h]=s>>>8,this.pixels[h+1]=s&255}this.echoPeak=n,this.active||(this.echo.fill(0),this.pixels.fill(0))}};var br=class{constructor(t,e,r){this.previous=null;this.peak=0;this.width=t,this.height=e,this.span=r??Math.min(t,e);let n=t*e;this.pixels=new Uint8Array(n*4),this.signal=new Float32Array(n),this.offsetX=new Float32Array(n),this.offsetY=new Float32Array(n),this.driftX=new Float32Array(n),this.driftY=new Float32Array(n),this.u=new Float32Array(n),this.v=new Float32Array(n),this.ink=new Float32Array(n),this.a=new Float32Array(n),this.b=new Float32Array(n),this.c=new Float32Array(n),this.pressure=new Float32Array(n),this.pressureNext=new Float32Array(n),this.divergence=new Float32Array(n),this.curl=new Float32Array(n)}get active(){return this.peak>2e-4}clear(){for(let t of[this.u,this.v,this.ink,this.a,this.b,this.c,this.pressure,this.pressureNext,this.divergence,this.curl,this.signal,this.pixels,this.offsetX,this.offsetY,this.driftX,this.driftY])t.fill(0);this.previous=null,this.peak=0}leave(){this.previous=null}move(t,e,r,n=performance.now()){if(!Number.isFinite(t+e+r+n))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e)),r=Math.max(.1,Math.min(1,r));let a=this.previous;if(this.previous={x:t,y:e,time:n},!a)return;let o=(t-a.x)*(this.width-1),l=(e-a.y)*(this.height-1),s=Math.hypot(o,l);if(s<.001)return;let h=this.span,f=n>a.time?Math.max(1/240,(n-a.time)/1e3):1/60,u=Math.min(12,s/h/f),m=1-Math.exp(-u/2.2),d=h*(.022+r*.075)*(.65+m*.95),c=Math.min(128,Math.max(1,Math.ceil(s/(d*.4)))),b=s/d*(.32+m*.22)/c,g=o/s,y=l/s,x=-y,S=g,A=s*(2+m*18)/c;for(let k=0;k<c;k++){let U=(k+.5)/c,Y=(a.x+(t-a.x)*U)*(this.width-1),I=(a.y+(e-a.y)*U)*(this.height-1),P=Math.max(1,Math.floor(Y-d*3)),M=Math.min(this.width-2,Math.ceil(Y+d*3)),X=Math.max(1,Math.floor(I-d*3)),H=Math.min(this.height-2,Math.ceil(I+d*3));for(let K=X;K<=H;K++)for(let v=P;v<=M;v++){let R=((v-Y)*g+(K-I)*y)/d,G=((v-Y)*x+(K-I)*S)/d,q=Math.exp(-R*R*.65-G*G*1.7),C=K*this.width+v;this.ink[C]=1-(1-this.ink[C])*Math.exp(-q*b);let E=1-G*G*.55,w=R*G*.7;this.u[C]=Math.max(-80,Math.min(80,this.u[C]+(g*E+x*w)*q*A)),this.v[C]=Math.max(-80,Math.min(80,this.v[C]+(y*E+S*w)*q*A))}}this.peak=1}read(t,e,r){e=Math.max(.5,Math.min(this.width-1.5,e)),r=Math.max(.5,Math.min(this.height-1.5,r));let n=e|0,a=r|0,o=e-n,l=r-a,s=a*this.width+n;return(t[s]*(1-o)+t[s+1]*o)*(1-l)+(t[s+this.width]*(1-o)+t[s+this.width+1]*o)*l}sample(t,e){return this.read(this.signal,t*(this.width-1),e*(this.height-1))}displacement(t,e,r){r[0]=this.read(this.offsetX,t*(this.width-1),e*(this.height-1)),r[1]=this.read(this.offsetY,t*(this.width-1),e*(this.height-1))}step(t){if(!this.active||!Number.isFinite(t))return;let e=Math.max(0,Math.min(.05,t)),r=this.width,n=this.height;for(;e>1e-7;){let a=Math.min(.016666666666666666,e);e-=a;let o=Math.exp(-1.9*a),l=Math.exp(-3.2*a);for(let h=1;h<n-1;h++)for(let f=1;f<r-1;f++){let u=h*r+f,m=Math.max(.5,Math.min(r-1.5,f-this.u[u]*a)),d=Math.max(.5,Math.min(n-1.5,h-this.v[u]*a)),c=m|0,b=d|0,g=m-c,y=d-b,x=b*r+c,S=(1-g)*(1-y),A=g*(1-y),k=(1-g)*y,U=g*y;this.a[u]=(this.u[x]*S+this.u[x+1]*A+this.u[x+r]*k+this.u[x+r+1]*U)*o,this.b[u]=(this.v[x]*S+this.v[x+1]*A+this.v[x+r]*k+this.v[x+r+1]*U)*o,this.c[u]=(this.ink[x]*S+this.ink[x+1]*A+this.ink[x+r]*k+this.ink[x+r+1]*U)*l}[this.u,this.a]=[this.a,this.u],[this.v,this.b]=[this.b,this.v],[this.ink,this.c]=[this.c,this.ink];for(let h=1;h<n-1;h++)for(let f=1;f<r-1;f++){let u=h*r+f;this.curl[u]=(this.v[u+1]-this.v[u-1]-this.u[u+r]+this.u[u-r])*.5}for(let h=1;h<n-1;h++)for(let f=1;f<r-1;f++){let u=h*r+f,m=Math.abs(this.curl[u+1])-Math.abs(this.curl[u-1]),d=Math.abs(this.curl[u+r])-Math.abs(this.curl[u-r]),c=Math.hypot(m,d)+1e-4,b=this.curl[u]*a*10,g=Math.hypot(this.u[u],this.v[u]);this.u[u]+=d/c*b,this.v[u]-=m/c*b;let y=Math.min(1,g/(Math.hypot(this.u[u],this.v[u])+1e-6));this.u[u]*=y,this.v[u]*=y,this.divergence[u]=-.5*(this.u[u+1]-this.u[u-1]+this.v[u+r]-this.v[u-r])}this.pressure.fill(0);for(let h=0;h<4;h++){for(let f=1;f<n-1;f++)for(let u=1;u<r-1;u++){let m=f*r+u;this.pressureNext[m]=(this.divergence[m]+this.pressure[m-1]+this.pressure[m+1]+this.pressure[m-r]+this.pressure[m+r])*.25}[this.pressure,this.pressureNext]=[this.pressureNext,this.pressure]}let s=0;for(let h=1;h<n-1;h++)for(let f=1;f<r-1;f++){let u=h*r+f;this.u[u]=Math.max(-80,Math.min(80,this.u[u]-(this.pressure[u+1]-this.pressure[u-1])*.5)),this.v[u]=Math.max(-80,Math.min(80,this.v[u]-(this.pressure[u+r]-this.pressure[u-r])*.5)),this.driftX[u]+=(this.u[u]*3.6-58*this.offsetX[u]-12*this.driftX[u])*a,this.driftY[u]+=(this.v[u]*3.6-58*this.offsetY[u]-12*this.driftY[u])*a,this.offsetX[u]=Math.max(-2,Math.min(2,this.offsetX[u]+this.driftX[u]*a)),this.offsetY[u]=Math.max(-2,Math.min(2,this.offsetY[u]+this.driftY[u]*a)),this.signal[u]=1-Math.exp(-Math.hypot(this.u[u],this.v[u])*.06-this.ink[u]*.16),s=Math.max(s,this.signal[u])}this.peak=s}if(!this.active){this.clear();return}for(let a=0;a<this.ink.length;a++){let o=Math.round(Math.min(1,this.signal[a])*65535);this.pixels[a*4]=o>>>8,this.pixels[a*4+1]=o&255,this.pixels[a*4+2]=Math.round(128+this.offsetX[a]*63.5),this.pixels[a*4+3]=Math.round(128+this.offsetY[a]*63.5)}}};function An(i,t){let e=Math.max(0,Math.min(1,t/.38)),r=e*e*(3-2*e);return i+(1-2*i)*r}var si=["loupe","repel","tilt","reveal","haze","bleed"],he=i=>si.includes(i),Re=class{constructor(){this.value=0;this.velocity=0}step(t,e,r,n){let a=2*Math.sqrt(r)*n;for(let o=e;o>1e-6;o-=1/480){let l=Math.min(.0020833333333333333,o);this.velocity+=((t-this.value)*r-this.velocity*a)*l,this.value+=this.velocity*l}}resting(t){return Math.abs(this.value-t)<.0015&&Math.abs(this.velocity)<.01}set(t){this.value=t,this.velocity=0}},wn=i=>i*i*(3-2*i),Ve=(i,t)=>{let e=Math.sin(i*127.1+t*311.7)*43758.5453;return e-Math.floor(e)};function Mr(i,t){let e=Math.floor(i),r=Math.floor(t),n=wn(i-e),a=wn(t-r),o=Ve(e,r),l=Ve(e+1,r),s=Ve(e,r+1),h=Ve(e+1,r+1);return(o+(l-o)*n)*(1-a)+(s+(h-s)*n)*a}var vr=class{constructor(t,e){this.edgeSafe=!1;this.settle=1;this.focus=[.5,.5,0,.2];this.guide=null;this.mode="loupe";this.radius=.35;this.x=new Re;this.y=new Re;this.tx=new Re;this.ty=new Re;this.presence=new Re;this.target=null;this.speed=0;this.clock=0;this.inkPeak=0;this.ink=null;this.next=null;this.fiber=null;this.sampled=[0,0,0];this.width=t,this.height=e,this.pixels=new Uint8Array(t*e*4),this.sx=Math.max(1,t/e),this.sy=Math.max(1,e/t),this.clear()}setMode(t){if(t!==this.mode&&(this.mode=t,this.clear(),t==="bleed"&&!this.ink)){let e=this.width*this.height;this.ink=new Float32Array(e),this.next=new Float32Array(e),this.fiber=new Float32Array(e);for(let r=0;r<this.height;r++)for(let n=0;n<this.width;n++)this.fiber[r*this.width+n]=.35+.5*Mr(n*.09,r*.045)+.15*Ve(n,r)}}setRadius(t){this.radius=Math.max(.1,Math.min(1,t))}get reach(){return(.05+this.radius*.25)*(this.mode==="loupe"?1-this.speed*.14:1)}get engaged(){return this.presence.value>.002||this.inkPeak>.002||Math.abs(this.tx.value)+Math.abs(this.ty.value)>4e-4}get active(){let t=this.target?1:0;return!this.presence.resting(t)||!!this.target&&(!this.x.resting(this.target.x)||!this.y.resting(this.target.y))||!this.tx.resting(this.tiltGoal(0))||!this.ty.resting(this.tiltGoal(1))||this.speed>.01||this.mode==="haze"&&this.presence.value>.002||this.inkPeak>.002}tiltGoal(t){return this.target&&this.mode==="tilt"?((t?this.target.y:this.target.x)-.5)*2:0}clear(){for(let t of[this.x,this.y,this.tx,this.ty,this.presence])t.set(0);this.x.set(.5),this.y.set(.5),this.target=null,this.speed=0,this.inkPeak=0,this.ink?.fill(0),this.next?.fill(0),this.encode()}move(t,e,r){if(!Number.isFinite(t+e))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e));let n=Number.isFinite(r)?r/1e3:this.clock,a=this.target;if(!a&&this.presence.value<.05&&(this.x.set(t),this.y.set(e)),a){let o=Math.hypot((t-a.x)*this.sx,(e-a.y)*this.sy),l=o/Math.max(1/240,Math.min(.1,n-a.time||1/60));this.speed=Math.max(this.speed,Math.min(1,l/1.6)),this.mode==="bleed"&&this.deposit(a.x,a.y,t,e,Math.min(1,o*9))}else this.mode==="bleed"&&this.deposit(t,e,t,e,.5);this.target={x:t,y:e,time:n}}leave(){this.target=null}deposit(t,e,r,n,a){let o=this.ink,l=this.width,s=this.height,h=this.reach*.55,f=Math.hypot((r-t)*this.sx,(n-e)*this.sy),u=Math.min(48,Math.max(1,Math.ceil(f/(h*.5))));for(let m=0;m<u;m++){let d=(m+.5)/u,c=t+(r-t)*d,b=e+(n-e)*d,g=Math.max(0,Math.floor((c-h*2/this.sx)*(l-1))),y=Math.min(l-1,Math.ceil((c+h*2/this.sx)*(l-1))),x=Math.max(0,Math.floor((b-h*2/this.sy)*(s-1))),S=Math.min(s-1,Math.ceil((b+h*2/this.sy)*(s-1)));for(let A=x;A<=S;A++)for(let k=g;k<=y;k++){let U=(k/(l-1)-c)*this.sx/h,Y=(A/(s-1)-b)*this.sy/h,I=A*l+k;o[I]=Math.min(1.4,o[I]+Math.exp(-(U*U+Y*Y)*1.8)*a/u*1.6)}}this.inkPeak=Math.max(this.inkPeak,.01)}step(t){if(!Number.isFinite(t)||t<=0)return;let e=Math.min(.05,t),r=e*this.settle;this.clock+=e;let n=this.target,a=this.mode;if(n?this.presence.step(1,e,190,1):this.presence.step(0,r,a==="repel"?120:70,a==="repel"?.42:1),n){let o=a==="tilt"?60:a==="haze"?90:240,l=a==="loupe"||a==="repel"?.72:.9;this.x.step(n.x,e,o,l),this.y.step(n.y,e,o,l)}this.tx.step(this.tiltGoal(0),n?e:r,45,.78),this.ty.step(this.tiltGoal(1),n?e:r,45,.78),this.speed*=Math.exp(-e*7),a==="bleed"&&this.spread(e,r,!!n),!this.engaged&&!this.active&&(this.presence.set(0),this.tx.set(0),this.ty.set(0)),this.focus[0]=this.x.value,this.focus[1]=this.y.value,this.focus[2]=Math.max(0,Math.min(1,this.presence.value)),this.focus[3]=this.reach,this.encode()}spread(t,e,r){let n=this.ink,a=this.next,o=this.fiber,l=this.width,s=this.height;r&&this.target&&this.deposit(this.x.value,this.y.value,this.x.value,this.y.value,t*.9);let h=Math.max(1,Math.ceil(t/(1/240))),f=t/h,u=26*(.4+this.radius),m=(r?.02:.1)*e/t,d=Math.exp(-(r?.15:.9)*e/h),c=0;for(let b=0;b<h;b++){c=0;for(let g=1;g<s-1;g++)for(let y=1;y<l-1;y++){let x=g*l+y,S=n[x],A=o[x],k=Math.min(A,o[x-1])*(n[x-1]-S)+Math.min(A,o[x+1])*(n[x+1]-S)+Math.min(A,o[x-l])*(n[x-l]-S)+Math.min(A,o[x+l])*(n[x+l]-S),U=Math.max(0,(S+k*Math.min(.24,u*f))*d-m*f);a[x]=U,U>c&&(c=U)}n.set(a)}this.inkPeak=c}sample(t,e,r){r[0]=r[1]=r[2]=0;let n=this.presence.value,a=this.mode;if(a==="bleed"){if(this.inkPeak<=.002)return;let d=this.width,c=this.height,b=this.ink,g=Math.max(0,Math.min(d-1.001,t*(d-1))),y=Math.max(0,Math.min(c-1.001,e*(c-1))),x=Math.floor(g),S=Math.floor(y),A=g-x,k=y-S,U=S*d+x,Y=U+d,I=(b[U]*(1-A)+b[U+1]*A)*(1-k)+(b[Y]*(1-A)+b[Y+1]*A)*k;r[2]=1-Math.exp(-I*2.4);return}if(a==="tilt"){let c=.2+.8*(this.guide?mn(this.guide,"depth",t,e):.6),b=this.edgeSafe?oe(t,e,this.sx/this.sy):1;r[0]=this.tx.value*.024*c*b/this.sx,r[1]=this.ty.value*.024*c*b/this.sy;return}if(n<=.001)return;let o=this.reach,l=(t-this.x.value)*this.sx,s=(e-this.y.value)*this.sy,h=(l*l+s*s)/(o*o);if(a==="reveal"){r[2]=Math.exp(-h*2.4)*n;return}if(h>9)return;let f=this.edgeSafe?oe(t,e,this.sx/this.sy):1,u=0,m=0;if(a==="loupe"){let d=Math.exp(-h*h)*n*.5;u=l*d,m=s*d;let c=Math.sqrt(h)-1;r[2]=Math.exp(-c*c/.018)*n*.55}else if(a==="repel"){let d=Math.sqrt(h),c=o*.5*Math.exp(-h/1.7)*n,b=Math.max(1e-6,Math.sqrt(l*l+s*s));u=l/b*Math.min(c,b+o*.5*n),m=s/b*Math.min(c,b+o*.5*n);let g=Math.max(0,Math.min(1,(d-.3)/.32));r[2]=-(1-g*g*(3-2*g))*n}else if(a==="haze"){let d=s/o+.45,c=Math.exp(-(l*l/(o*o))-d*d/2.6)*n*(.35+.65*Math.min(1,this.speed*1.4+.25));if(c<.002)return;let b=this.clock,g=t*this.sx*9,y=e*this.sy*9+b*2.3,x=Mr(g,y)-.5,S=Mr(g+17.3,y*1.3+b*.7)-.5;u=x*.06*c,m=S*.026*c,r[2]=(Mr(g*1.7+5,y*1.7)-.5)*.35*c}r[0]=u*f/this.sx,r[1]=m*f/this.sy}encode(){let t=this.width,e=this.height,r=this.pixels,n=this.sampled,a=this.engaged;for(let o=0;o<e;o++)for(let l=0;l<t;l++){let s=(o*t+l)*4;if(a?this.sample(l/(t-1),o/(e-1),n):n[0]=n[1]=n[2]=0,this.mode==="bleed"){let h=Math.round(Math.max(-1,Math.min(1,n[2]))*32767+32768);r[s]=h>>>8,r[s+1]=h&255,r[s+2]=128,r[s+3]=0}else{this.mode==="repel"&&(n[0]*=.3,n[1]*=.3);let h=Math.round(Math.max(-1,Math.min(1,n[0]/.16))*32767+32768),f=Math.round(Math.max(-1,Math.min(1,n[1]/.16))*32767+32768);r[s]=h>>>8,r[s+1]=h&255,r[s+2]=f>>>8,r[s+3]=f&255}}}};var li=.2,hi=.6,ci=3,ui=7,Fn=(i,t)=>i==="water"?30*t/.55:i==="silk"?28*t:i==="vortex"?38*t:["magnetic","scatter","elastic","lens","smudge"].includes(i)?32*t:["loupe","repel","tilt","haze"].includes(i)?.16*t/.55:0,mi=(i=.5)=>Math.pow(2,(.5-(Number.isFinite(i)?Math.max(0,Math.min(1,i)):.5))*2.4);function Kr(i,t,e,r=!1){if(!e)return t;let n=a=>Math.max(0,Math.min(1,a));switch(i){case"trail":case"contour":return An(t,e);case"etch":case"ripple":return n(t+e*.35);case"dissolve":{let a=Math.max(0,1+e);return r?1-(1-t)*a:t*a}case"bleed":return n(t+e*(r?-.6:.6));case"loupe":return n(t+e*.3);case"haze":return n(t+e*.5);default:return t}}var En=i=>["trail","contour","etch","ripple","bleed","haze"].includes(i),_e=class{constructor(t=1){this.ripple=null;this.cursor=null;this.settle=1;this.mode="water";this.amount=.55;this.radius=.2;this.lensX=.5;this.lensY=.5;this.lensStrength=0;this.previous=null;this.energy=0;this.pending=!1;this.remainder=0;this.quiet=0;this.guide=null;t=Math.max(.25,Math.min(4,t)),this.columns=Math.round(t>=1?128:128*t),this.rows=Math.round(t>=1?128/t:128),this.xScale=Math.max(1,t),this.yScale=Math.max(1,1/t),this.heights=new Float32Array(this.columns*this.rows),this.velocity=new Float32Array(this.heights.length),this.next=new Float32Array(this.heights.length),this.normals=new Float32Array(this.heights.length*2),this.edgeMask=new Float32Array(this.heights.length);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.edgeMask[e*this.columns+r]=oe(r/(this.columns-1),e/(this.rows-1),t);this.refraction={width:this.columns,height:this.rows,pixels:new Uint8Array(this.heights.length*4),strength:30,mode:"water",focus:[.5,.5,0,.2]},this.waterPixels=this.refraction.pixels,this.trail=new br(this.columns,this.rows),this.contour=new gr(this.columns,this.rows),this.afterimage=new pr(this.columns,this.rows),this.clear()}get invertsDensity(){return this.mode==="trail"}get densityTrail(){return["trail","contour","dissolve","etch","ripple","bleed"].includes(this.mode)}get hasRefraction(){return this.active||this.lensStrength>15e-5}get effect(){return this.mode}get engaged(){return he(this.mode)?this.cursor.engaged:this.active}get spotlight(){return this.mode==="reveal"&&this.cursor?this.cursor.focus:null}get signature(){return he(this.mode)&&this.cursor.engaged?this.cursor.focus.map(t=>t.toFixed(4)).join(","):""}setGuide(t){this.cursor&&(this.cursor.guide=t),this.guide=t}get active(){return he(this.mode)?this.cursor.active:this.mode==="ripple"?this.ripple?.active??!1:Ee(this.mode)?this.afterimage.active:this.mode==="contour"?this.contour.active:this.mode==="trail"?this.trail.active:this.pending||this.energy>15e-5}setMode(t){let e=t==="light"||t==="scan"?t:ur(t)??"none";e!==this.mode&&(this.clear(),this.mode=e,this.refraction.mode=e,Ee(e)&&this.afterimage.setMode(e),e==="ripple"&&!this.ripple&&(this.ripple=new dr(this.columns,this.rows)),he(e)&&(this.cursor??(this.cursor=new vr(this.columns,this.rows)),this.cursor.guide=this.guide,this.cursor.setMode(e)),this.refraction.pixels=he(e)?this.cursor.pixels:e==="ripple"?this.ripple.pixels:e==="trail"?this.trail.pixels:e==="contour"?this.contour.pixels:Ee(e)?this.afterimage.pixels:this.waterPixels,this.refraction.strength=Fn(e,this.amount),this.refraction.relative=he(e))}configure(t,e=.55,r=.2,n=!1,a=.5){this.setMode(t),this.settle=mi(a),this.refraction.edgeSafe=n,this.afterimage.edgeSafe=n,this.ripple&&(this.ripple.edgeSafe=n),this.amount=Number.isFinite(e)?Math.max(0,Math.min(1,e)):.55,this.radius=Number.isFinite(r)?Math.max(.1,Math.min(1,r)):.2,this.cursor&&(this.cursor.edgeSafe=n,this.cursor.settle=this.settle,this.cursor.setRadius(this.radius)),this.refraction.strength=Fn(this.mode,this.amount),this.refraction.focus[2]=this.densityTrail?this.amount:this.lensStrength*this.amount,this.refraction.focus[3]=this.radius,(this.mode==="reveal"||this.mode==="repel")&&this.syncSpot()}syncSpot(){let t=this.cursor.focus;this.refraction.focus=[t[0],t[1],t[2]*(this.mode==="repel"?Math.min(1,this.amount/.55):this.amount),t[3]]}move(t,e,r){if(this.mode==="none"||this.amount===0||!Number.isFinite(t+e))return;if(t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e)),he(this.mode)){this.cursor.move(t,e,r);return}if(this.mode==="ripple"){this.ripple.move(t,e,this.radius,r);return}if(Ee(this.mode)){this.afterimage.move(t,e,this.radius);return}if(this.mode==="contour"){this.contour.move(t,e,this.radius);return}if(this.mode==="trail"){this.trail.move(t,e,this.radius,r);return}if(this.mode!=="water"){!this.previous&&this.lensStrength<.001&&(this.lensX=t,this.lensY=e),this.previous={x:t,y:e},this.pending=!0;return}if(!this.previous){this.previous={x:t,y:e};return}let n=this.previous;this.previous={x:t,y:e};let a=(t-n.x)*this.xScale,o=(e-n.y)*this.yScale,l=Math.hypot(a,o);if(l<1e-5)return;let s=.035+this.radius*.1,h=s*3,f=Math.min(192,Math.max(1,Math.ceil(l/(s*.5)))),u=Math.min(l,1)*95/f;for(let m=0;m<f;m++){let d=(m+.5)/f,c=n.x+(t-n.x)*d,b=n.y+(e-n.y)*d,g=Math.max(1,Math.floor((c-h/this.xScale)*(this.columns-1))),y=Math.min(this.columns-2,Math.ceil((c+h/this.xScale)*(this.columns-1))),x=Math.max(1,Math.floor((b-h/this.yScale)*(this.rows-1))),S=Math.min(this.rows-2,Math.ceil((b+h/this.yScale)*(this.rows-1)));for(let A=x;A<=S;A++)for(let k=g;k<=y;k++){let U=(k/(this.columns-1)-c)*this.xScale,Y=(A/(this.rows-1)-b)*this.yScale,I=Math.exp(-(U*U+Y*Y)/(s*s))*u,P=A*this.columns+k;this.velocity[P]=Math.max(-12,this.velocity[P]-I)}}this.pending=!0,this.quiet=0}leave(){this.cursor?.leave(),this.ripple?.leave(),this.afterimage.leave(),this.contour.leave(),this.trail.leave(),this.previous=null,this.mode!=="water"&&this.lensStrength&&(this.pending=!0)}clear(){this.trail.clear(),this.contour.clear(),this.afterimage.clear(),this.ripple?.clear(),this.cursor?.clear(),this.heights.fill(0),this.velocity.fill(0),this.next.fill(0),this.normals.fill(0),this.refraction.focus[2]=0,this.previous=null,this.lensStrength=0,this.energy=0,this.pending=!1,this.remainder=0,this.quiet=0;for(let t=0;t<this.waterPixels.length;t+=4)this.waterPixels[t]=this.waterPixels[t+2]=128,this.waterPixels[t+1]=this.waterPixels[t+3]=0}step(t){if(!this.active||!Number.isFinite(t))return;if(he(this.mode)){this.cursor.step(t),(this.mode==="reveal"||this.mode==="repel")&&this.syncSpot();return}if(t*=this.settle,this.mode==="ripple"){this.ripple.step(t);return}if(Ee(this.mode)){this.afterimage.step(t);return}if(this.mode==="contour"){this.contour.step(t);return}if(this.mode==="trail"){this.trail.step(t);return}if(this.mode!=="water"){this.stepLight(Math.max(0,Math.min(.05,t)));return}this.remainder+=Math.max(0,Math.min(.05,t));let e=1/120,r=Math.min(this.columns,this.rows)*.3;for(;this.remainder+1e-8>=e;){this.remainder-=e,this.quiet+=e;let a=Math.max(0,Math.min(1,(this.quiet-li)/hi)),o=a*a*(3-2*a),l=Math.exp(-(3.8+o*ci)*e),s=Math.exp(-o*ui*e),h=0;for(let f=1;f<this.rows-1;f++)for(let u=1;u<this.columns-1;u++){let m=f*this.columns+u,d=this.heights[m],c=this.heights[m-1]+this.heights[m+1]+this.heights[m-this.columns]+this.heights[m+this.columns]-4*d,b=Math.min(u,f,this.columns-1-u,this.rows-1-f),g=b<5?.88+b*.024:1,y=(this.velocity[m]+(c*r*r-d*8)*e)*l*g;this.velocity[m]=y,this.next[m]=(d+y*e)*g*s,h=Math.max(h,Math.abs(this.next[m]),Math.abs(y)*.1)}this.heights.set(this.next),this.energy=h,this.pending=!1}if(!this.active){this.clear();return}let n=Math.min(this.columns,this.rows)*.18;for(let a=0;a<this.rows;a++)for(let o=0;o<this.columns;o++){let l=a*this.columns+o,s=(this.heights[a*this.columns+Math.max(0,o-1)]-this.heights[a*this.columns+Math.min(this.columns-1,o+1)])*n,h=(this.heights[Math.max(0,a-1)*this.columns+o]-this.heights[Math.min(this.rows-1,a+1)*this.columns+o])*n,f=Math.tanh(s)*(this.refraction.edgeSafe?this.edgeMask[l]:1),u=Math.tanh(h)*(this.refraction.edgeSafe?this.edgeMask[l]:1);this.normals[l*2]=f,this.normals[l*2+1]=u;let m=Math.round(f*32767+32768),d=Math.round(u*32767+32768);this.refraction.pixels[l*4]=m>>>8,this.refraction.pixels[l*4+1]=m&255,this.refraction.pixels[l*4+2]=d>>>8,this.refraction.pixels[l*4+3]=d&255}}stepLight(t){let e=this.previous,r=1-Math.exp(-30*t),n=1-Math.exp(-12*t);if(e&&(this.lensX+=(e.x-this.lensX)*r,this.lensY+=(e.y-this.lensY)*r),this.lensStrength+=((e?1:0)-this.lensStrength)*n,this.energy=Math.max(e?Math.abs(e.x-this.lensX)+Math.abs(e.y-this.lensY):0,Math.abs((e?1:0)-this.lensStrength)),this.pending=!1,!e&&!this.active){this.clear();return}this.refraction.focus=[this.lensX,this.lensY,this.lensStrength*this.amount,this.radius]}sample(t,e,r){if(he(this.mode)){this.cursor.sample(t,e,r),r[0]*=this.amount/.55,r[1]*=this.amount/.55,r[2]*=this.mode==="reveal"||this.mode==="repel"?Math.min(1,this.amount/.55):this.amount*3;return}if(this.mode==="ripple"){this.ripple.sample(t,e,r),r[2]*=this.amount;return}if(Ee(this.mode)){this.afterimage.sample(t,e,r),r[0]*=this.amount,r[1]*=this.amount,r[2]*=this.amount;return}if(this.mode==="contour"){r[0]=r[1]=0,r[2]=this.contour.sample(t,e)*this.amount*3;return}if(this.mode==="trail"){r[0]=r[1]=0,r[2]=this.trail.sample(t,e)*this.amount*3;return}let n=Math.max(0,Math.min(this.columns-1.001,t*(this.columns-1))),a=Math.max(0,Math.min(this.rows-1.001,e*(this.rows-1))),o=Math.floor(n),l=Math.floor(a),s=n-o,h=a-l,f=(l*this.columns+o)*2,u=f+this.columns*2;for(let m=0;m<2;m++)r[m]=((this.normals[f+m]*(1-s)+this.normals[f+2+m]*s)*(1-h)+(this.normals[u+m]*(1-s)+this.normals[u+2+m]*s)*h)*.08;r[0]*=this.amount/.55,r[1]*=this.amount/.55,r[2]=this.mode==="light"||this.mode==="scan"?fi(t,e,this.refraction,this.xScale/this.yScale):0}};function fi(i,t,e,r){let[n,a,o,l]=e.focus,s=(i-n)*Math.max(1,r)/l,h=(t-a)*Math.max(1,1/r)/l;return e.mode==="light"?Math.exp(-3*(s*s+h*h))*o:e.mode==="scan"?(Math.exp(-s*s*110)*1.3-Math.exp(-s*s*12)*.3)*Math.exp(-h*h*1.8)*o:0}function Cn(i){return"videoWidth"in i?[i.videoWidth,i.videoHeight]:"naturalWidth"in i?[i.naturalWidth,i.naturalHeight]:[i.width,i.height]}var jt=(i,t,e)=>{(i.width!==t||i.height!==e)&&(i.width=t,i.height=e)},Rn={blocks:" \\u2591\\u2592\\u2593\\u2588",braille:" \\u2801\\u2803\\u2807\\u2847\\u28C7\\u28E7\\u28F7\\u28FF",lines:" -\\u2550\\u256A\\u256C",cross:" \\xB7+xX#",diagonal:" /\\u2571\\u2573",diamond:" \\xB7\\u25C7\\u25C8\\u25C6",mixed:" .:+/\\u25C7#@"},di=new Set(["pointillism","stipple","led","dots"]),pi=.01,gi=.99,yr=.32,bi=.07,Mi=.6,xr=.9;function vi(i){let t=new Uint32Array(256),e=0;for(let o=0;o<i.length;o+=4)i[o+3]<8||(t[Math.min(255,i[o]*.299+i[o+1]*.587+i[o+2]*.114|0)]++,e++);if(!e)return[0,1];let r=o=>{let l=0,s=o*e;for(let h=0;h<256;h++)if((l+=t[h])>=s)return h/255;return 1},n=r(pi),a=r(gi);return a-n<yr&&(n=Math.max(0,Math.min(1-yr,(n+a)/2-yr/2)),a=n+yr),[n,a]}function yi(i,t,e){let r=Math.max(.001,e-t),n=0,a=0;for(let l=0;l<i.length;l+=4){if(i[l+3]<8)continue;let s=((i[l]*.299+i[l+1]*.587+i[l+2]*.114)/255-t)/r;s<=.06||(n+=Math.min(1,s),a++)}if(!a)return xr;let o=Math.min(.99,Math.max(.01,n/a));return Math.min(xr,Math.max(Mi,Math.log(.5)/Math.log(o)))}function xi(i,t=xr){let e=Math.min(...i),r=Math.max(...i);if(!(r-e>1e-4))return null;let n=i.map(o=>(o-e)/(r-e)),a=new Uint8Array(256);for(let o=0;o<256;o++){if(o/255<bi){a[o]=n.indexOf(0);continue}let l=Math.pow(o/255,t),s=0;for(let h=1;h<n.length;h++)Math.abs(n[h]-l)<Math.abs(n[s]-l)&&(s=h);a[o]=s}return a}function Tn(i,t,e,r){i.clearRect(0,0,t,e),i.fillStyle="#fff",i.strokeStyle="#fff",i.lineCap="round",i.lineJoin="round";for(let n of r){if(i.beginPath(),n.kind==="ellipse")i.ellipse((n.x+n.width/2)*t,(n.y+n.height/2)*e,n.width*t/2,n.height*e/2,0,0,Math.PI*2);else if(n.kind==="rectangle")i.rect(n.x*t,n.y*e,n.width*t,n.height*e);else{if(i.lineWidth=(n.size??.05)*t,n.points?.length===1){i.arc(n.points[0][0]*t,n.points[0][1]*e,i.lineWidth/2,0,Math.PI*2),i.fill();continue}n.points?.forEach(([a,o],l)=>l?i.lineTo(a*t,o*e):i.moveTo(a*t,o*e)),i.stroke();continue}i.fill()}}var In=new WeakMap;function Pn(i,t,e,r,n,a){In.get(i)?.(t,e,r,n,a,!1)}var Si=i=>Math.max(64,Math.min(4096,Number.isFinite(i)?i:960));function ki(i,t,e){let r=Math.min(1,i/Math.max(t,e));return[Math.max(2,Math.round(t*r)),Math.max(2,Math.round(e*r))]}function Ai(i,t,e,r,n){let[a,o]=Cn(t);i.clearRect(0,0,e,r),i.save();let l=gn(a,o,e,r,n);i.translate(l.x+l.width/2,l.y+l.height/2),i.rotate(n.rotation*Math.PI/180),i.drawImage(t,-a*l.scale/2,-o*l.scale/2,a*l.scale,o*l.scale),i.restore()}function Ln(i,t,e,r){let n=r.surface,a=i.getContext("2d");if(!a)throw new Error("Canvas is already owned by another renderer.");let o=n(),l=n(!0),s=n(),h=n(),f=n(),u=n(),m=n(),d=n(),c=n(),b=n(),g=0,y=0,x=1,S=xr,A=null,k=null,U=null,Y="",I,P,M=fr(t),X=0,H="",K="",v="",R=new Uint8ClampedArray(0),G=new Uint8ClampedArray(0),q=new Uint8ClampedArray(0),C=null,E="",w=0,F=0,B=0,Z=null,et="",N=new _e,tt=null,dt=new Float32Array(0),lt=n(!0),St=n(),Et=n(),Lt=0,Tt=[0,0,0],yt=[0,0,0,1],ee=[0,0],ct=[0,0,0,0],Qt=Cr(M.color),de=Dr(M.print),kt=new tr(M.color.denoise),L=new er(M.warps,M.warpEdge),z=Si(e.maxDimension),O=Math.max(256,Math.min(1048576,Number.isFinite(e.maxCells)?e.maxCells:12e3)),rt=O,J=Math.max(.1,Math.min(8,e.pixelRatio??1)),pt=(ut,gt,zt)=>{N.configure(M.hover.effect,M.hover.strength,M.hover.radius,M.hover.edgeSafe,M.hover.decay),N.move(ut,gt,zt)};function Mt(ut,gt=0,zt=960,re=540,Ne=gt*M.motion.speed){Dt(ut,gt,zt,re,Ne,!0)}function Dt(ut,gt,zt,re,Ne,wr){if(Number.isFinite(gt)||(gt=0),!Number.isFinite(zt)||!Number.isFinite(re)||zt<1||re<1)throw new Error("Render dimensions must be positive finite numbers.");let[Ze,ze]=Cn(ut);if(!Ze||!ze)return;let[ht,nt]=ki(z,zt,re);jt(i,ht,nt),jt(o.canvas,ht,nt),jt(s.canvas,ht,nt),jt(h.canvas,ht,nt),jt(f.canvas,ht,nt),Lt!==ht/nt&&(Lt=ht/nt,N=new _e(Lt),N.setGuide(tt)),N.configure(M.hover.effect,M.hover.strength,M.hover.radius,M.hover.edgeSafe,M.hover.decay),N.step(Math.max(0,Math.min(.05,gt-B))),B=gt;let ce=r.media(ut),p=[X,ht,nt,ce.time].join(":"),W=M.style==="dither",T=bn(ht,nt,M,rt,J),Q=T.cell,V=T.rowHeight,At=T.columns,Rt=T.rows;if(H!==p||Z!==ce.key||w!==At||F!==Rt){Z=ce.key,H=p,E="",K="",v="",w=At,F=Rt,r.scene?r.scene(o.ctx,ht,nt):Ai(o.ctx,ut,ht,nt,M.crop),jt(l.canvas,w,F),l.ctx.clearRect(0,0,w,F),l.ctx.drawImage(o.canvas,0,0,w,F),R=l.ctx.getImageData(0,0,w,F).data,kt.apply(R,w,F),G.length!==R.length&&(G=new Uint8ClampedArray(R.length)),G.set(R);let Nt=M.color;for(let Ft=0;Ft<R.length;Ft+=4){let mt=R[Ft]*.299+R[Ft+1]*.587+R[Ft+2]*.114;for(let ot=0;ot<3;ot++){let Ut=mt+(R[Ft+ot]-mt)*Nt.saturation;R[Ft+ot]=((Ut*(1-Nt.grayscale)+mt*Nt.grayscale)/255-.5)*Nt.contrast*255+127.5+Nt.brightness*255}}if(Qt&&$r(R,Qt),R=L.apply(R,w,F,ht/nt),M.color.levels!=="none"){let[Ft,mt]=vi(R),ot=yi(R,Ft,mt),Ut=A===ce.key&&ce.video?.15:1;A=ce.key,y+=(Ft-y)*Ut,x+=(mt-x)*Ut,S+=(ot-S)*Ut}let wt=M.hover,Wt=wt.scope??"all";if(wt.effect!=="none"&&(Wt!=="all"||wt.effect==="tilt")){let Ft=null;if(M.mask.enabled&&M.mask.shapes.length){jt(lt.canvas,w,F),lt.ctx.clearRect(0,0,w,F),Tn(lt.ctx,w,F,M.mask.shapes);let mt=lt.ctx.getImageData(0,0,w,F).data;Ft=new Float32Array(w*F);for(let ot=0;ot<Ft.length;ot++)Ft[ot]=M.mask.invert?1-mt[ot*4+3]/255:mt[ot*4+3]/255}tt=sr(R,w,F,Ft,tt),dt.length!==w*F&&(dt=new Float32Array(w*F));for(let mt=0;mt<dt.length;mt++)dt[mt]=un(Wt,tt.subject[mt],tt.key);if(wt.effect==="reveal"){jt(St.canvas,w,F);let mt=new ImageData(w,F);for(let ot=0;ot<dt.length;ot++)mt.data[ot*4+3]=dt[ot]*255;St.ctx.putImageData(mt,0,0)}}else tt=null;N.setGuide(tt)}if(!wr){v=K="";return}let Ht=on(M),_=an(M),$=!N.active&&!Ht&&!_,it=[p,w,F,Q,V,J,N.signature].join(":"),xt=N.engaged,bt=N.effect;if(!$||v!==it){s.ctx.clearRect(0,0,ht,nt),s.ctx.globalAlpha=1,s.ctx.globalCompositeOperation="source-over";let Nt=Ne,wt=Ht?M.motion.type:"none",Wt=M.motion.amount??1,Ft=cn(wt);wt!=="none"&&E!==H&&(C=fn(G,w,F,C),E=H);let mt=null;if(W){let ft=$;if(!ft||K!==p){q.length!==R.length&&(q=new Uint8ClampedArray(R.length));let qt=q;if(qt.set(R),xt||wt!=="none")for(let D=0;D<F;D++)for(let Gt=0;Gt<w;Gt++){let ue=Gt/w,Te=D/F,me=Gt,fe=D,Ce=0,_t=0,$t=1;if(xt){N.sample(ue,Te,Tt);let Jt=tt?dt[D*w+Gt]:1;me-=Tt[0]*Jt*w,fe-=Tt[1]*Jt*F,bt==="reveal"?$t=1-.72*Math.min(1,Tt[2]*Jt):bt==="repel"?$t=1+Math.max(-1,Tt[2])*Jt:Ce=Tt[2]/3*Jt}let Ie=(D*w+Gt)*4;Hr(wt,ue,Te,Nt,yt,(R[Ie]*.299+R[Ie+1]*.587+R[Ie+2]*.114)/255,C??void 0,(D*w+Gt)*we),Nr(yt,Wt),(yt[0]||yt[1])&&(Or(yt,me,fe,w,F,ee),me=ee[0],fe=ee[1]),_t=yt[2],$t*=yt[3];let pe=(D*w+Gt)*4;De(R,w,F,me,fe,ct);for(let Jt=0;Jt<3;Jt++){let vt=ct[Jt]/255,Xt=Kr(bt,vt,Ce)+_t;qt[pe+Jt]=Xt*255}qt[pe+3]=ct[3]*$t}yn(qt,w,F,M.dither,gt),l.ctx.putImageData(new ImageData(qt,w,F),0,0),K=ft?p:""}s.ctx.imageSmoothingEnabled=!1,s.ctx.drawImage(l.canvas,0,0,ht,nt)}else{let ft=di.has(M.style);ft&&r.marks&&P===void 0&&(P=r.marks()),mt=ft&&P?.begin(ht,nt,M.style==="led"||M.style==="dots")?P:null;let qt=Array.from(Rn[M.style]??M.charset),D=mt?.ctx??s.ctx,Gt=jr(M.ink),ue=bt==="ripple"||bt==="etch",Te=ue&&Gt[0]*.299+Gt[1]*.587+Gt[2]*.114<90?[214,214,214]:Gt,me=M.style==="ascii"||!!Rn[M.style],fe=We(M.style)?M.style:null,Ce=Math.max(3,Math.round(V*.92)),_t=Math.ceil(Q+4),$t=Math.ceil(V+4),Ie=[qt.join(""),Ce,_t,$t,M.ink,M.colorMode].join(":");if(me&&Ie!==et){et=Ie,jt(m.canvas,_t*qt.length,$t),m.ctx.clearRect(0,0,m.canvas.width,$t),m.ctx.font=`${Ce}px monospace`,m.ctx.textBaseline="middle",m.ctx.textAlign="center",m.ctx.fillStyle=M.colorMode==="accent"?M.ink:"#ffffff",qt.forEach((vt,Xt)=>m.ctx.fillText(vt,Xt*_t+_t/2,$t/2)),k=null,Y="";try{let vt=m.ctx.getImageData(0,0,m.canvas.width,m.canvas.height).data;k=qt.map((Xt,ve)=>{let ye=0;for(let se=0;se<m.canvas.height;se++)for(let ge=ve*_t;ge<(ve+1)*_t&&ge<m.canvas.width;ge++)ye+=vt[(se*m.canvas.width+ge)*4+3];return ye})}catch{k=null}}let pe=me&&M.color.levels!=="none";if(pe&&k){let vt=et+":"+S.toFixed(2);vt!==Y&&(Y=vt,U=xi(k,S))}let Jt=Math.max(.001,x-y);if(M.style==="lego"&&g!==Q){g=Q,jt(b.canvas,Math.ceil(Q),Math.ceil(V));let vt=b.ctx;vt.clearRect(0,0,b.canvas.width,b.canvas.height),vt.fillStyle="rgba(255,255,255,.2)",vt.strokeStyle="rgba(0,0,0,.25)",vt.lineWidth=Math.max(.5,J*.6),vt.beginPath(),vt.arc(Q/2,V/2,Q*.28,0,Math.PI*2),vt.fill(),vt.stroke()}D.font=`${Ce}px monospace`,D.textBaseline="middle",D.textAlign="center";for(let vt=0;vt<F;vt++)for(let Xt=0;Xt<w;Xt++){let ve=Xt,ye=vt,se=0,ge=0;if(xt){N.sample(Xt/w,vt/F,Tt);let st=tt?dt[vt*w+Xt]:1;ve=Math.max(0,Math.min(w-1,Xt-Tt[0]*st*w)),ye=Math.max(0,Math.min(F-1,vt-Tt[1]*st*F)),bt==="reveal"?ge=Math.min(1,Tt[2]*st)*.72:bt==="repel"?ge=-Math.max(-1,Tt[2])*st:se=Tt[2]/3*st}if(wt!=="none"){let st=(vt*w+Xt)*4;Hr(wt,Xt/w,vt/F,Nt,yt,(R[st]*.299+R[st+1]*.587+R[st+2]*.114)/255,C??void 0,(vt*w+Xt)*we),Nr(yt,Wt),(yt[0]||yt[1])&&(Or(yt,ve,ye,w,F,ee),ve=ee[0],ye=ee[1])}De(R,w,F,ve,ye,ct);let xe=0;if(ue&&se>.012&&(ct[3]?ct[3]>250&&ct[0]*.299+ct[1]*.587+ct[2]*.114<30:M.hover.scope==="outside")){let st=Math.min(1,(se-.012)/.12);xe=st*st*(3-2*st)}if(!ct[3]){if(!((xe||se>.03)&&M.hover.scope==="outside"&&En(bt)))continue;ct[0]=Te[0],ct[1]=Te[1],ct[2]=Te[2],ct[3]=xe?255:Math.min(255,se*640)}let qe=ct[0],Ge=ct[1],Be=ct[2],Fr=(qe*.299+Ge*.587+Be*.114)/255,It=pe?Math.max(0,Math.min(1,(Fr-y)/Jt)):Fr;It=Kr(bt,It,se,!!fe&&de.settings.invert);let Ot=Xt*Q,Ct=vt*V,Se=1,Pe=It;if(wt!=="none"){let st=yt[2]/(pe?Math.max(.5,Jt):1);It=Math.max(0,Math.min(1,It+st)),Pe=Math.max(0,Math.min(1,Pe+st*(Ft?.45:1)))}else Pe=It;xe&&(It=Pe=Math.max(It,.1+xe*.45)),Se=(wt!=="none"?yt[3]:1)*ct[3]/255*(1-ge)*(xe?.3+xe*.45:1),!me&&!fe&&M.colorMode==="accent"&&M.style!=="cmyk"?Se*=It:pe&&M.colorMode==="accent"&&(Se*=.32+.68*Math.pow(It,S)),D.globalAlpha=Se;let le=(It-Fr)*255,Xe;if(mt&&M.colorMode!=="accent"&&M.style==="pointillism")Xe=M.ink;else if(mt&&M.colorMode!=="accent"){if(M.colorMode==="source")mt.ctx.fillColor(qe+le,Ge+le,Be+le);else{let st=Math.round(It*255);mt.ctx.fillColor(st,st,st)}Xe=$e}else Xe=M.colorMode==="source"?`rgb(${qe+le},${Ge+le},${Be+le})`:M.colorMode==="gray"?`rgb(${Math.round(It*255)},${Math.round(It*255)},${Math.round(It*255)})`:M.ink;if(D.fillStyle=Xe,fe)de.paint(D,fe,Xt,vt,Ot,Ct,Q,It,Xe,M.colorMode==="gray"?It*255:qe+le,M.colorMode==="gray"?It*255:Ge+le,M.colorMode==="gray"?It*255:Be+le,M.colorMode);else if(me){let st=pe&&U?U[Math.round(Pe*255)]:Math.max(0,Math.min(qt.length-1,Math.round(Pe*(qt.length-1))));if(M.colorMode==="accent"?k?.[st]===0:qt[st]===" ")continue;M.colorMode==="accent"?D.drawImage(m.canvas,st*_t,0,_t,$t,Math.round(Ot+(Q-_t)/2),Math.round(Ct+(V-$t)/2),_t,$t):D.fillText(qt[st],Ot+Q/2,Ct+V/2)}else if(M.style==="dots")D.beginPath(),D.arc(Ot+Q/2,Ct+V/2,Q*.48*Math.sqrt(It),0,Math.PI*2),D.fill();else if(M.style==="led")D.beginPath(),D.arc(Ot+Q/2,Ct+V/2,Q*.39,0,Math.PI*2),D.fill(),D.globalAlpha=Se*.35,D.fillStyle="#ffffff",D.beginPath(),D.arc(Ot+Q*.43,Ct+V*.4,Q*.11,0,Math.PI*2),D.fill();else if(M.style==="hex"){let st=Ot+Q/2,be=Ct+V/2;D.beginPath();for(let ke=0;ke<6;ke++){let Ye=Math.PI/3*ke,Me=st+Math.cos(Ye)*Q*.49,Le=be+Math.sin(Ye)*V*.49;ke===0?D.moveTo(Me,Le):D.lineTo(Me,Le)}D.closePath(),D.fill()}else if(M.style==="cmyk"){D.fillStyle="#ffffff",D.fillRect(Ot,Ct,Q,V);let st=(Er,Qe)=>Math.max(0,Math.min(255,M.colorMode==="source"?Er+le:M.colorMode==="gray"?It*255:Qe*It)),be=st(qe,Gt[0]),ke=st(Ge,Gt[1]),Ye=st(Be,Gt[2]),Me=1-Math.max(be,ke,Ye)/255,Le=Math.max(.001,1-Me),On=[["#00ffff",(1-be/255-Me)/Le,.36,.36],["#ff00ff",(1-ke/255-Me)/Le,.64,.36],["#ffff00",(1-Ye/255-Me)/Le,.5,.66],["#000000",Me,.5,.5]];D.globalCompositeOperation="multiply";for(let[Er,Qe,Nn,zn]of On)Qe>0&&(D.fillStyle=Er,D.beginPath(),D.arc(Ot+Q*Nn,Ct+V*zn,Q*.48*Math.sqrt(Math.max(0,Qe)),0,Math.PI*2),D.fill());D.globalCompositeOperation="source-over"}else if(M.style==="voxel"){let st=Ot+Q/2,be=Ct+V/2;D.beginPath(),D.moveTo(st,Ct),D.lineTo(Ot+Q,Ct+V*.25),D.lineTo(st,be),D.lineTo(Ot,Ct+V*.25),D.closePath(),D.fill(),D.globalAlpha=Se*.72,D.beginPath(),D.moveTo(Ot,Ct+V*.25),D.lineTo(st,be),D.lineTo(st,Ct+V),D.lineTo(Ot,Ct+V*.75),D.closePath(),D.fill(),D.globalAlpha=Se*.42,D.beginPath(),D.moveTo(st,be),D.lineTo(Ot+Q,Ct+V*.25),D.lineTo(Ot+Q,Ct+V*.75),D.lineTo(st,Ct+V),D.closePath(),D.fill()}else{let st=M.style==="pixel"?0:Math.max(.5,Q*.06);D.fillRect(Ot,Ct,Q-st,V-st),M.style==="lego"&&D.drawImage(b.canvas,Ot,Ct),M.style==="disco"&&(D.fillStyle=`rgba(255,255,255,${.1+Wr(Xt,vt)*.25})`,D.fillRect(Ot,Ct,Q-st,V*.35),D.fillStyle="rgba(0,0,0,.25)",D.fillRect(Ot,Ct+V*.65,Q-st,V*.35-st))}}}if(s.ctx.globalAlpha=1,mt){let ft=mt.finish();ft&&s.ctx.drawImage(ft,0,0)}(M.color.amount||M.lights.length)&&(jt(d.canvas,ht,nt),d.ctx.clearRect(0,0,ht,nt),d.ctx.drawImage(s.canvas,0,0)),M.color.amount&&(s.ctx.save(),s.ctx.globalCompositeOperation=M.color.blend,s.ctx.globalAlpha=M.color.amount,s.ctx.fillStyle=M.color.tint,s.ctx.fillRect(0,0,ht,nt),s.ctx.restore());for(let ft of M.lights){let qt=ft.radius*Math.max(ht,nt),D=s.ctx.createRadialGradient(ft.x*ht,ft.y*nt,0,ft.x*ht,ft.y*nt,qt);D.addColorStop(0,ft.color),D.addColorStop(1,"transparent"),s.ctx.save(),s.ctx.globalCompositeOperation="screen",s.ctx.globalAlpha=ft.intensity,s.ctx.fillStyle=D,s.ctx.fillRect(0,0,ht,nt),s.ctx.restore()}(M.color.amount||M.lights.length)&&(s.ctx.globalCompositeOperation="destination-in",s.ctx.drawImage(d.canvas,0,0),s.ctx.globalCompositeOperation="source-over"),M.mask.enabled&&M.mask.shapes.length&&(Tn(f.ctx,ht,nt,M.mask.shapes),s.ctx.globalCompositeOperation=M.mask.invert?"destination-out":"destination-in",s.ctx.drawImage(f.canvas,0,0),s.ctx.globalCompositeOperation="source-over");let ot=h.ctx;ot.clearRect(0,0,ht,nt),ot.globalAlpha=M.backdrop.opacity;let Ut=M.backdrop;if(Ut.mode==="solid"&&(ot.fillStyle=Ut.color,ot.fillRect(0,0,ht,nt)),Ut.mode==="gradient"){let ft=ot.createLinearGradient(0,0,ht,nt);ft.addColorStop(0,Ut.color),ft.addColorStop(1,Ut.color2),ot.fillStyle=ft,ot.fillRect(0,0,ht,nt)}if(Ut.mode==="source"&&ot.drawImage(o.canvas,0,0),Ut.mode==="blurred"){let ft=Math.max(1,Ut.blur);jt(u.canvas,Math.max(2,Math.round(ht/ft)),Math.max(2,Math.round(nt/ft))),u.ctx.drawImage(o.canvas,0,0,u.canvas.width,u.canvas.height),ot.imageSmoothingEnabled=!0,ot.drawImage(u.canvas,0,0,ht,nt)}ot.globalAlpha=1,M.effects.characterBloom>0&&(jt(c.canvas,Math.max(2,Math.round(ht/3)),Math.max(2,Math.round(nt/3))),c.ctx.clearRect(0,0,c.canvas.width,c.canvas.height),c.ctx.drawImage(s.canvas,0,0,c.canvas.width,c.canvas.height),ot.save(),ot.globalAlpha=M.effects.characterBloom*.8,ot.globalCompositeOperation="screen",ot.filter=`blur(${1+M.effects.characterBloom*4}px)`,ot.drawImage(c.canvas,0,0,ht,nt),ot.restore());let ne=N.spotlight;if(ne&&ne[2]>.002){jt(Et.canvas,ht,nt);let ft=Et.ctx,qt=ne[3]*Math.min(ht,nt)*1.6;ft.globalCompositeOperation="source-over",ft.clearRect(0,0,ht,nt),ft.drawImage(o.canvas,0,0),ft.globalCompositeOperation="destination-in";let D=ft.createRadialGradient(ne[0]*ht,ne[1]*nt,0,ne[0]*ht,ne[1]*nt,qt),Gt=Math.min(1,ne[2]*M.hover.strength/.55);for(let ue of[0,.2,.4,.6,.8,1])D.addColorStop(ue,`rgba(0,0,0,${Gt*Math.exp(-2.4*(ue*1.6)**2)*(1-ue)})`);ft.fillStyle=D,ft.fillRect(0,0,ht,nt),tt&&(M.hover.scope??"all")!=="all"&&(ft.imageSmoothingEnabled=!0,ft.drawImage(St.canvas,0,0,ht,nt)),ft.globalCompositeOperation="source-over",ot.drawImage(Et.canvas,0,0)}ot.drawImage(s.canvas,0,0),v=$?it:""}let Vt=Object.entries(M.effects).some(([Nt,wt])=>!["angle","focus","blurType","characterBloom"].includes(Nt)&&typeof wt=="number"&&wt>0);a.clearRect(0,0,ht,nt),Vt?(I===void 0&&(I=xn(r.finishCanvas)),I?a.drawImage(I.render(h.canvas,M.effects,gt,J),0,0):a.drawImage(h.canvas,0,0),r.finished(I?"gpu":"unavailable")):(a.drawImage(h.canvas,0,0),r.finished("none"))}let Bt={canvas:i,render:Mt,setPixelRatio(ut){J=Math.max(.1,Math.min(8,Number.isFinite(ut)?ut:1))},get pixelRatio(){return J},setBudget(ut){rt=Math.max(256,Math.min(O,Number.isFinite(ut)?Math.round(ut):O))},get maxCells(){return rt},configure(ut){M=fr(ut),Qt=Cr(M.color),de=Dr(M.print),kt.configure(M.color.denoise),L.configure(M.warps,M.warpEdge),X++},pointer:pt,leave(){N.leave()},get active(){return N.active},get settings(){return fr(M)},get capabilities(){return{gpuFinish:I!==null}},invalidate(){H=""},destroy(){I?.destroy(),P?.destroy(),P=void 0,L.clear(),kt.configure(0);for(let ut of[o,l,s,h,f,u,m,d,c,b,lt,St,Et])ut.canvas.width=ut.canvas.height=1;Z=null,R=new Uint8ClampedArray(0),q=new Uint8ClampedArray(0),C=null,E=""}};return In.set(Bt,Dt),Bt}var Dn=self,Vr=()=>new OffscreenCanvas(300,150),wi=()=>{let i=Vr(),t=i.getContext("2d");if(!t)throw new Error("Canvas 2D is unavailable.");return{canvas:i,ctx:t}},Kt=null,Sr=null,Ar=null,Je=null,Un={video:!1,time:0,key:0},Hn="none",kr=(i,t=[])=>Dn.postMessage(i,t),Fi={surface:wi,media:()=>Un,scene(i,t,e){i.clearRect(0,0,t,e),Ar&&i.drawImage(Ar,0,0)},finishCanvas:()=>Vr(),marks:Jr,finished(i){Hn=i}};Dn.onmessage=i=>{let t=i.data;try{switch(t.type){case"init":Sr=Vr(),Kt=Ln(Sr,t.settings,t.limits,Fi),t.pixelRatio!==void 0&&Kt.setPixelRatio(t.pixelRatio),t.budget!==void 0&&Kt.setBudget(t.budget);break;case"source":Ar?.close(),Ar=t.scene,Je={width:t.width,height:t.height},Un={video:t.video,time:t.time,key:t.key};break;case"pointer":Kt?.pointer(t.x,t.y,t.time);break;case"leave":Kt?.leave();break;case"configure":Kt?.configure(t.settings);break;case"budget":Kt?.setBudget(t.cells);break;case"ratio":Kt?.setPixelRatio(t.ratio);break;case"invalidate":Kt?.invalidate();break;case"advance":Kt&&Je&&Pn(Kt,Je,t.time,t.width,t.height,t.motionTime);break;case"render":{if(!Kt||!Sr||!Je){kr({type:"skip",seq:t.seq});break}let e=performance.now();Kt.render(Je,t.time,t.width,t.height,t.motionTime);let r=performance.now()-e,n=Sr.transferToImageBitmap();kr({type:"frame",seq:t.seq,bitmap:n,cost:r,active:Kt.active,finish:Hn},[n]);break}}}catch(e){kr({type:"error",seq:t.type==="render"||t.type==="advance"?t.seq:-1,message:e instanceof Error?e.message:String(e)})}};kr({type:"ready"});})();\n';export{t as default};