asciify-engine 4.28.0 → 4.30.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.
Files changed (110) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/THIRD_PARTY.md +3 -0
  3. package/dist/field.cjs +1 -1
  4. package/dist/field.d.cts +1 -1
  5. package/dist/field.d.ts +1 -1
  6. package/dist/field.js +1 -1
  7. package/dist/{glyph-field-DRC-7uVf.d.ts → glyph-field-BCwGhohg.d.ts} +11 -0
  8. package/dist/{glyph-field-C2fQIlnq.d.cts → glyph-field-DKWHAMml.d.cts} +11 -0
  9. package/dist/hover.cjs +1 -1
  10. package/dist/hover.js +1 -1
  11. package/dist/kit/{chunk-4NV5APSJ.js → chunk-2NACMWVV.js} +1 -1
  12. package/dist/kit/{chunk-F6F2C3RH.js → chunk-2UOPVMN3.js} +1 -1
  13. package/dist/kit/{chunk-DMRPBFLW.js → chunk-3H3DJI3M.js} +1 -1
  14. package/dist/kit/{chunk-7M2FFUZ3.js → chunk-4G5LJNMB.js} +1 -1
  15. package/dist/kit/{chunk-G4ZSMTFN.js → chunk-4NR7QENR.js} +1 -1
  16. package/dist/kit/{chunk-GKR3ROYR.js → chunk-5Q634WWI.js} +1 -1
  17. package/dist/kit/{chunk-KY5KCIZE.js → chunk-64NSPD2R.js} +1 -1
  18. package/dist/kit/{chunk-2FH6GGV6.js → chunk-6G2ZVIBS.js} +1 -1
  19. package/dist/kit/{chunk-3MHEDZLZ.js → chunk-6NDTKY3V.js} +1 -1
  20. package/dist/kit/{chunk-GBNV3GXG.js → chunk-7QH33RJJ.js} +1 -1
  21. package/dist/kit/{chunk-BFBG3VHI.js → chunk-7TXDNPL3.js} +1 -1
  22. package/dist/kit/{chunk-3OD5BMF5.js → chunk-AAV5QNHU.js} +1 -1
  23. package/dist/kit/chunk-AU33Y2SZ.js +1 -0
  24. package/dist/kit/{chunk-KCEYRIU4.js → chunk-BGPEFFKK.js} +1 -1
  25. package/dist/kit/{chunk-KDROJANO.js → chunk-BJJUDT26.js} +1 -1
  26. package/dist/kit/{chunk-2LBQ7QJT.js → chunk-BO4CPM26.js} +1 -1
  27. package/dist/kit/chunk-BQ53B2HP.js +1 -0
  28. package/dist/kit/chunk-BV6AOHFU.js +1 -0
  29. package/dist/kit/{chunk-QVICL57J.js → chunk-CH64MY3U.js} +1 -1
  30. package/dist/kit/{chunk-LVCGC3SO.js → chunk-CMGMCRAD.js} +1 -1
  31. package/dist/kit/{chunk-4U72YE65.js → chunk-CZL5WMU6.js} +1 -1
  32. package/dist/kit/{chunk-PB5E3D4E.js → chunk-DKRZSP5K.js} +1 -1
  33. package/dist/kit/{chunk-KFXMLIVF.js → chunk-E427W6P5.js} +1 -1
  34. package/dist/kit/{chunk-RXOPJJC4.js → chunk-EH4S6T7U.js} +1 -1
  35. package/dist/kit/chunk-F4IO3HWD.js +1 -0
  36. package/dist/kit/{chunk-K6JX64AS.js → chunk-FU4WW3PU.js} +1 -1
  37. package/dist/kit/{chunk-TRDA73HN.js → chunk-G3FVDS2A.js} +1 -1
  38. package/dist/kit/{chunk-FHN3PPSI.js → chunk-G7GQSPMC.js} +1 -1
  39. package/dist/kit/chunk-GI5BNKBL.js +1 -0
  40. package/dist/kit/{chunk-KEE55QSD.js → chunk-GJANKSX6.js} +1 -1
  41. package/dist/kit/{chunk-Z2FRNFMB.js → chunk-HENGH3DE.js} +1 -1
  42. package/dist/kit/chunk-I377LEZA.js +1 -0
  43. package/dist/kit/chunk-IFZDWKIX.js +1 -0
  44. package/dist/kit/{chunk-WDS7VM2E.js → chunk-J7Y2KBXK.js} +1 -1
  45. package/dist/kit/{chunk-KXI3T72F.js → chunk-JF3WEYIE.js} +1 -1
  46. package/dist/kit/{chunk-3VEMKDBW.js → chunk-LTRVMY3D.js} +1 -1
  47. package/dist/kit/{chunk-EKYEA7Z4.js → chunk-M5JJSIWI.js} +1 -1
  48. package/dist/kit/{chunk-ILXVBO7M.js → chunk-MT23DCGU.js} +1 -1
  49. package/dist/kit/{chunk-NF4WVWAC.js → chunk-MWUPCAET.js} +1 -1
  50. package/dist/kit/{chunk-FPCCX4FM.js → chunk-MYAZOXMF.js} +1 -1
  51. package/dist/kit/{chunk-3YSK7V26.js → chunk-N7J4UAWY.js} +1 -1
  52. package/dist/kit/{chunk-YSN7EHSH.js → chunk-NP7UG7DS.js} +1 -1
  53. package/dist/kit/{chunk-ZCXNGJGB.js → chunk-NQ4PFWOG.js} +1 -1
  54. package/dist/kit/chunk-NS6HYTQZ.js +1 -0
  55. package/dist/kit/chunk-NSKX2OFA.js +1 -0
  56. package/dist/kit/{chunk-WI2AF2KE.js → chunk-OOVUQEXT.js} +1 -1
  57. package/dist/kit/{chunk-W4U5CK6L.js → chunk-P5MVACML.js} +1 -1
  58. package/dist/kit/chunk-PZKQUZQK.js +1 -0
  59. package/dist/kit/{chunk-CGSWUO67.js → chunk-R3ALZFUQ.js} +1 -1
  60. package/dist/kit/{chunk-7DXSG526.js → chunk-RGV7VRYC.js} +1 -1
  61. package/dist/kit/chunk-SBAUVRBY.js +1 -0
  62. package/dist/kit/chunk-SQNULNT3.js +1 -0
  63. package/dist/kit/{chunk-HYVTFKWX.js → chunk-TJHSBZBF.js} +1 -1
  64. package/dist/kit/{chunk-FWODCYYJ.js → chunk-UHLNVM63.js} +1 -1
  65. package/dist/kit/{chunk-UOYBFLGJ.js → chunk-UT6MJP5B.js} +1 -1
  66. package/dist/kit/{chunk-QSTDYL35.js → chunk-UWX7VIXT.js} +1 -1
  67. package/dist/kit/{chunk-6WU247CB.js → chunk-UXDJSGED.js} +1 -1
  68. package/dist/kit/{chunk-Z3KD6CLE.js → chunk-UXJRBOSR.js} +1 -1
  69. package/dist/kit/{chunk-KLRF3S7O.js → chunk-V42Q4L2G.js} +1 -1
  70. package/dist/kit/chunk-V6KL3IA7.js +1 -0
  71. package/dist/kit/{chunk-776H2BJ7.js → chunk-VENDLTH4.js} +1 -1
  72. package/dist/kit/{chunk-ZWZZMU5P.js → chunk-VQ4KIRBW.js} +1 -1
  73. package/dist/kit/{chunk-OZFSNW5N.js → chunk-WPWCFCEZ.js} +1 -1
  74. package/dist/kit/{chunk-H5KHXZWR.js → chunk-WRBLIULG.js} +1 -1
  75. package/dist/kit/{chunk-SDSW7422.js → chunk-WSWIOD2C.js} +1 -1
  76. package/dist/kit/{chunk-NW4U2YRE.js → chunk-X6GAMLEH.js} +1 -1
  77. package/dist/kit/chunk-X7AUCVMH.js +1 -0
  78. package/dist/kit/{chunk-B3TY6UXJ.js → chunk-XDX6WLED.js} +1 -1
  79. package/dist/kit/{chunk-42KMN727.js → chunk-XVA7UGUQ.js} +1 -1
  80. package/dist/kit/chunk-XXHIFJ5Z.js +1 -0
  81. package/dist/kit/{chunk-3LJ5C3U3.js → chunk-XZO4VH2Z.js} +1 -1
  82. package/dist/kit/{chunk-6G5MPND3.js → chunk-Y2SDQ6EC.js} +1 -1
  83. package/dist/kit/{chunk-CG6SGQMY.js → chunk-ZGCKUXYP.js} +1 -1
  84. package/dist/kit/{chunk-E3FPFANJ.js → chunk-ZNZAO7JA.js} +1 -1
  85. package/dist/kit/{chunk-XUCYFWC3.js → chunk-ZTCSVEHT.js} +1 -1
  86. package/dist/kit.cjs +1 -1
  87. package/dist/kit.d.cts +182 -7
  88. package/dist/kit.d.ts +182 -7
  89. package/dist/kit.js +1 -1
  90. package/dist/studio-worker.js +1 -1
  91. package/dist/studio.cjs +1 -1
  92. package/dist/studio.js +1 -1
  93. package/package.json +1 -1
  94. package/skills/asciify-engine/SKILL.md +4 -4
  95. package/skills/asciify-engine/references/applying-asciify.md +18 -2
  96. package/skills/asciify-engine/references/components.md +81 -0
  97. package/skills/asciify-engine/references/glyph-field.md +2 -0
  98. package/skills/asciify-engine/references/kit.md +132 -3
  99. package/skills/asciify-engine/references/scenario-prompts.md +10 -1
  100. package/dist/kit/chunk-2GAV4OAK.js +0 -1
  101. package/dist/kit/chunk-2MLFWO4U.js +0 -1
  102. package/dist/kit/chunk-AIGAJMNN.js +0 -1
  103. package/dist/kit/chunk-GF72XM4C.js +0 -1
  104. package/dist/kit/chunk-I5R2347P.js +0 -1
  105. package/dist/kit/chunk-M5VVLYI2.js +0 -1
  106. package/dist/kit/chunk-ORSI57T2.js +0 -1
  107. package/dist/kit/chunk-PGFBIU7R.js +0 -1
  108. package/dist/kit/chunk-UVLKCAKH.js +0 -1
  109. package/dist/kit/chunk-VBWG7HQA.js +0 -1
  110. package/dist/kit/chunk-VV2KP7ZW.js +0 -1
package/dist/studio.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t,e=Object.defineProperty,i=Object.getOwnPropertyNames,a=(t,e)=>function(){return t&&(e=(0,t[i(t)[0]])(t=0)),e},s=a({"worker-source:/Users/ayangabryl/asciify-recovery/work/engine/src/studio/render-worker.ts"(){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'}}),r={};((t,i)=>{for(var a in i)e(t,a,{get:i[a],enumerable:!0})})(r,{default:()=>t});var n=a({"src/studio/worker-source.ts"(){s()}}),o=[{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."}],h={rake:"silk"},l={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}},c={effect:"trail",strength:.55,radius:.2,decay:.5,scope:"all",edgeSafe:!1};function m(t){if("string"==typeof t)return t in h?h[t]:o.some(e=>e.value===t)?t:void 0}var u=t=>"subject"===t||"outside"===t?t:"all";function f(t,e,i,a,s){if(!(s<1))for(let r=0;r<2;r++){for(let r=0;r<a;r++){let a=0;const n=r*i;for(let e=-s;e<=s;e++)a+=t[n+Math.max(0,Math.min(i-1,e))];for(let r=0;r<i;r++)e[n+r]=a/(2*s+1),a+=t[n+Math.min(i-1,r+s+1)]-t[n+Math.max(0,r-s)]}for(let r=0;r<i;r++){let n=0;for(let t=-s;t<=s;t++)n+=e[Math.max(0,Math.min(a-1,t))*i+r];for(let o=0;o<a;o++)t[o*i+r]=n/(2*s+1),n+=e[Math.min(a-1,o+s+1)*i+r]-e[Math.max(0,o-s)*i+r]}}}var d=new Float32Array(0);function p(t,e,i,a,s){const r=e*i,n=s&&s.width===e&&s.height===i?s:{width:e,height:i,subject:new Float32Array(r),depth:new Float32Array(r),key:"none"},{subject:o,depth:h}=n;let l=0;for(let e=0;e<r;e++)t[4*e+3]<250&&l++;const c=e=>(.2126*t[4*e]+.7152*t[4*e+1]+.0722*t[4*e+2])/255;let m="none",u=0;if(l>.01*r)m="alpha";else if(a)m="mask";else{let t=0,a=0,s=0;const r=Math.max(1,Math.round(.03*Math.min(e,i)));for(let n=0;n<i;n++)for(let o=0;o<e;o++){if(o>=r&&n>=r&&o<e-r&&n<i-r)continue;const h=c(n*e+o);t+=h,a+=h*h,s++}u=t/Math.max(1,s);Math.sqrt(Math.max(0,a/Math.max(1,s)-u*u))<.07&&(m="ground")}for(let e=0;e<r;e++){const i=t[4*e+3]/255,s=c(e);let r=1;if("alpha"===m)r=i;else if("ground"===m){const t=Math.max(0,Math.min(1,(Math.abs(s-u)-.035)/.12));r=t*t*(3-2*t)}o[e]=r*(a?Math.max(0,Math.min(1,a[e])):1),h[e]=s*i}n.key=m,d.length<r&&(d=new Float32Array(r));const p=d;return f(o,p,e,i,Math.max(1,Math.round(.02*Math.min(e,i)))),f(h,p,e,i,Math.max(1,Math.round(.035*Math.min(e,i)))),n}function g(t,e,i="ground"){return"none"===i?1:"subject"===t?e:"outside"===t?1-e:1}var M={caustics:"sheen",grain:"shimmer",trace:"relight",tidal:"current",weave:"current",breeze:"current",reform:"develop",print:"develop",unfold:"develop"},x=[{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’s 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 v(t){const e=t&&Object.prototype.hasOwnProperty.call(M,t)?M[t]:t;return x.find(t=>t.value===e||t.mode===e)?.mode??"none"}var y=t=>Math.max(0,Math.min(1,t)),b=(t,e,i)=>{const a=y((i-t)/(e-t));return a*a*(3-2*a)},w=(t,e)=>{const i=(.06711056*t+.00583715*e)%1*52.9829189;return i-Math.floor(i)},k=class{constructor(){this.last=null,this.mode="none",this.phase=0}update(t,e,i=1){const a=v(e);return Number.isFinite(t)?((a!==this.mode||null!==this.last&&t<this.last)&&(this.mode=a,this.phase=0,this.last=t),null!==this.last&&(this.phase+=Math.max(0,t-this.last)*Math.max(.1,Math.min(3,Number.isFinite(i)?i:1))),this.last=t,this.phase):this.phase}};function A(t,e,i,a,s,r=.5,n,o=0){if(s[0]=s[1]=s[2]=0,s[3]=1,"none"===t)return s;r=y(r);const h=n?n[o]:r,l=n?n[o+1]:.5+.5*y(1-2*Math.hypot(e-.5,i-.55)),c=n?n[o+2]:b(.55,1,r)**2,m=n?n[o+3]:.5,u=n?n[o+4]:0,f=n?n[o+5]:0,d=a*Math.PI/6,p=(a%12+12)%12,g=b(0,.12,Math.min(e,1-e,i,1-i));if("relight"===t){const t=d+.6,a=Math.cos(t),n=Math.sin(t),o=Math.max(-1,Math.min(1,u*a+f*n))+.35*(a*(e-.5)+n*(i-.5));s[2]=.2*o*(.3+.7*b(.04,.3,h)*(1-.6*b(.82,1,r)))}else if("sheen"===t){const t=1.9*b(0,8,p)-.35,a=(.75*e+.45*i)/1.2+.05*(.75*u+.45*f),n=Math.exp(-(((a-t)/.12)**2));s[2]=n*b(.3,.8,h)*(1-.5*b(.9,1,r))*.45}else if("glow"===t){const t=.5-.5*Math.cos(d),e=1-.8*t;s[2]=.2*b(e-.3,e+.02,c)*Math.sqrt(c)*(1-.65*r)+.05*t*b(.6,.95,r)}else if("shimmer"===t){const t=w(Math.floor(160*e),Math.floor(100*i))*Math.PI*2,a=Math.pow(.5+.5*Math.cos(2*d+t),28);s[2]=a*b(.5,.88,r)*(.35+.65*b(.1,.55,m))*.42}else if("parallax"===t){const t=l-.45;s[0]=16*t*Math.sin(d)*g,s[1]=7*t*Math.sin(2*d)*g}else if("push"===t){const t=.045*(.5-.5*Math.cos(d))*(.7+.6*l)*960,a=n?n[o+6]:.5,r=n?n[o+7]:.5;s[0]=(e-a)*t,s[1]=(i-r)*t}else if("focus"===t){const t=Math.sin(d),e=t*t*b(.35,.85,t>=0?1-l:l);s[2]=(h-r)*e*.75}else if("mist"===t){const t=Math.pow(1-l,1.5)*(1-.6*m),a=.5*Math.sin(4.1*e-d+.9*Math.sin(3.3*i+d))+.3*Math.sin(7.3*e+2.1*i-2*d+1.1*Math.sin(2.7*e-5.1*i+d))+.2*Math.sin(5.7*i-1.9*e+d);s[2]=b(-.3,.9,a)*t*.16*(1-.55*r)}else if("current"===t){const t=n?.[o+8]??0,a=n?.[o+9]??0,h=n?.[o+10]??0,c=b(0,.06,Math.min(e,1-e,i,1-i)),u=n?0:(1-.4*m)*(1-.8*l)*g,f=t=>14*i-t+1.5*Math.sin(3*e+t),p=t=>16*i+2*e-t,M=t=>29*i-3*e-2*t,x=t=>1.7*e+2.3*i-t,v=t=>26*i+1.5*Math.sin(40*e)-2*t;s[0]=7*(Math.sin(f(d))-Math.sin(f(0))+.43*(Math.sin(5*e-3*i+d)-Math.sin(5*e-3*i)))*u+(3.5*(Math.sin(p(d))-Math.sin(p(0)))+1.5*(Math.sin(M(d))-Math.sin(M(0))))*t*c+5*(Math.sin(x(d))-Math.sin(x(0)))*a*c,s[1]=2*(Math.sin(11*e+d)-Math.sin(11*e))*u+.8*(Math.cos(p(d))-Math.cos(p(0)))*t*c+12*(Math.sin(v(d))-Math.sin(v(0)))*h*c;const y=Math.pow(.5+.5*Math.cos(2*d+9*e-4*i+6.2831853*w(Math.floor(160*e),Math.floor(100*i))),24)-Math.pow(.5+.5*Math.cos(9*e-4*i+6.2831853*w(Math.floor(160*e),Math.floor(100*i))),24);s[2]=.03*(Math.cos(f(d))-Math.cos(f(0)))*u+(y*b(.5,.85,r)*.3+.025*(Math.cos(p(d))-Math.cos(p(0))))*t*c+.08*(Math.cos(v(d))-Math.cos(v(0)))*h*c}else if("develop"===t){const t=b(7,8.5,p),a=y((p-8.5)/3.5),n=p<8.5?1-t:b(0,1,(1.45*a-(1-r)+.06*(w(Math.floor(160*e),Math.floor(100*i))-.5))/.3);s[2]=.3*-(1-n),s[3]=1-.9*(1-n)}return s}function S(t){const e=Math.floor(t),i=Math.max(0,Math.min(1,(t-e-.2)/.6));return e+i*i*(3-2*i)}function F(t,e,i,a,s,r){return r[0]=S(Math.max(0,Math.min(a-1,e-t[0]/960*a))),r[1]=S(Math.max(0,Math.min(s-1,i-t[1]/960*s))),r}function E(t,e){const i=Math.max(0,Math.min(2,Number.isFinite(e)?e:1));return t[0]*=i,t[1]*=i,t[2]*=i,t[3]=y(1+(t[3]-1)*i),t}var R=["rgb","red","green","blue"],T=t=>Math.max(0,Math.min(1,t));function P(t){const e=new Map([[0,0],[1,1]]);if(Array.isArray(t))for(const i of t.slice(0,64)){if(!Array.isArray(i)||i.length<2||"number"!=typeof i[0]||!Number.isFinite(i[0])||"number"!=typeof i[1]||!Number.isFinite(i[1]))continue;const t=Math.round(255*T(i[0]))/255;!e.has(t)&&e.size>=16||e.set(t,T(i[1]))}return[...e].sort((t,e)=>t[0]-e[0])}function C(t){const e=t&&"object"==typeof t?t:{};return Object.fromEntries(R.map(t=>[t,P(e[t])]))}function I(t){const e=P(t),i=e.length,a=e.slice(1).map((t,i)=>t[0]-e[i][0]),s=e.slice(1).map((t,i)=>(t[1]-e[i][1])/a[i]),r=new Float64Array(i);r[0]=s[0],r[i-1]=s[i-2];for(let t=1;t<i-1;t++){const e=s[t-1],i=s[t];if(e*i<=0)continue;const n=2*a[t]+a[t-1],o=a[t]+2*a[t-1];r[t]=(n+o)/(n/e+o/i)}const n=new Uint8Array(256);let o=0;for(let t=0;t<256;t++){const s=t/255;for(;o<i-2&&s>e[o+1][0];)o++;const h=a[o],l=(s-e[o][0])/h,c=l*l,m=c*l,u=(2*m-3*c+1)*e[o][1]+(m-2*c+l)*h*r[o]+(-2*m+3*c)*e[o+1][1]+(m-c)*h*r[o+1];n[t]=Math.round(255*T(u))}return n}function D(t,e,i,a,s,r){a=Math.max(0,Math.min(e-1,a)),s=Math.max(0,Math.min(i-1,s));const n=Math.floor(a),o=Math.floor(s),h=a-n,l=s-o,c=4*(o*e+n);if(0===h&&0===l){for(let e=0;e<4;e++)r[e]=t[c+e];return}const m=4*(o*e+Math.min(e-1,n+1)),u=4*(Math.min(i-1,o+1)*e+n),f=4*(Math.min(i-1,o+1)*e+Math.min(e-1,n+1)),d=(1-h)*(1-l)*t[c+3],p=h*(1-l)*t[m+3],g=(1-h)*l*t[u+3],M=h*l*t[f+3],x=d+p+g+M;for(let e=0;e<3;e++)r[e]=x?(t[c+e]*d+t[m+e]*p+t[u+e]*g+t[f+e]*M)/x:0;r[3]=x}function N(t,e,i,a,s,r){if(a>=0&&a<=e-1&&s>=0&&s<=i-1)return D(t,e,i,a,s,r);if(r[0]=r[1]=r[2]=r[3]=0,a<=-1||a>=e||s<=-1||s>=i)return;const n=Math.floor(a),o=Math.floor(s),h=a-n,l=s-o;for(let a=0;a<=1;a++)for(let s=0;s<=1;s++){const c=n+s,m=o+a;if(c<0||c>=e||m<0||m>=i)continue;const u=4*(m*e+c),f=(s?h:1-h)*(a?l:1-l)*t[u+3];r[0]+=t[u]*f,r[1]+=t[u+1]*f,r[2]+=t[u+2]*f,r[3]+=f}r[3]&&(r[0]/=r[3],r[1]/=r[3],r[2]/=r[3])}var U=[{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}],O=(t,e,i,a)=>"number"==typeof t&&Number.isFinite(t)?Math.max(i,Math.min(a,t)):e;function L(t){if(!Array.isArray(t))return[];const e=[];for(const i of t.slice(0,64))if(i&&"object"==typeof i&&U.some(t=>t.value===i.type)&&(e.push({type:i.type,enabled:!1!==i.enabled,amount:O(i.amount,.35,-1,1),x:O(i.x,.5,0,1),y:O(i.y,.5,0,1),radius:O(i.radius,.55,.05,2),angle:O(i.angle,0,-180,180),frequency:O(i.frequency,5,1,24)}),8===e.length))break;return e}var q=2*Math.PI,X=(t,e)=>{let i=Math.imul(t,374761393)^Math.imul(e,668265263);return i=Math.imul(i^i>>>13,1274126177),((i^i>>>16)>>>0)/4294967296},z=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"){const i=L(t).filter(t=>t.enabled&&0!==t.amount),a=JSON.stringify(i);this.edge="transparent"===e?"transparent":"clamp",a!==this.signature&&(this.signature=a,this.geometry="",this.warps=i.map(t=>({...t,cos:Math.cos(t.angle*Math.PI/180),sin:Math.sin(t.angle*Math.PI/180)})),i.length||this.clear())}get active(){return this.warps.length>0}apply(t,e,i,a=e/i){if(!this.active)return t;if(!Number.isInteger(e)||!Number.isInteger(i)||e<1||i<1||e*i*4!==t.length||!Number.isFinite(a)||a<=0)throw new Error("Warp dimensions do not match the source.");const s=`${e}:${i}:${a}`;if(s!==this.geometry){this.coordinates.length!==e*i*2&&(this.coordinates=new Float32Array(e*i*2));const t=Math.max(1,a),r=Math.max(1,1/a);for(let a=0;a<i;a++)for(let s=0;s<e;s++){let n=(s+.5)/e,o=(a+.5)/i;for(let e=this.warps.length-1;e>=0;e--){const i=this.warps[e],a=(n-i.x)*t/i.radius,s=(o-i.y)*r/i.radius,h=a*a+s*s;if(h>=1)continue;const l=Math.sqrt(h),c=(1-h)*(1-h),m=i.amount;let u=a,f=s;if("twirl"===i.type||"zigzag"===i.type){const t="twirl"===i.type?-m*q*c:.65*m*(2/Math.PI*Math.asin(Math.sin(l*q*i.frequency)))*c,e=Math.cos(t),r=Math.sin(t);u=a*e-s*r,f=a*r+s*e}else if("pinch"===i.type){const t=Math.exp(2*m*c);u=a*t,f=s*t}else if("sphere"===i.type&&l>0){const t=1+m*c*(2*Math.asin(l)/Math.PI/l-1);u=a*t,f=s*t}else if("ripple"===i.type&&l>0){const t=1+.12*m*Math.sin(l*q*i.frequency)*c/l;u=a*t,f=s*t}else if("shear"===i.type){const t=-a*i.sin+s*i.cos;u-=m*t*.9*c*i.cos,f-=m*t*.9*c*i.sin}else if("smudge"===i.type)u-=.65*m*c*i.cos,f-=.65*m*c*i.sin;else if("polar"===i.type){const t=a*i.cos+s*i.sin,e=-a*i.sin+s*i.cos,r=Math.atan2(e,t),n=m>0?r/Math.PI:Math.cos(t*Math.PI)*(e+1)/2,o=m>0?2*l-1:Math.sin(t*Math.PI)*(e+1)/2,h=n*i.cos-o*i.sin,d=n*i.sin+o*i.cos;u+=(h-a)*Math.abs(m)*c,f+=(d-s)*Math.abs(m)*c}else if("fragment"===i.type){const t=Math.floor((a*i.cos+s*i.sin)*i.frequency),e=Math.floor((-a*i.sin+s*i.cos)*i.frequency),r=(X(t,e)-.5)*m*.5*c,n=(X(e+71,t-31)-.5)*m*.5*c;u+=r*i.cos-n*i.sin,f+=r*i.sin+n*i.cos}n=i.x+u*i.radius/t,o=i.y+f*i.radius/r}const h=2*(a*e+s);this.coordinates[h]=n*e-.5,this.coordinates[h+1]=o*i-.5}this.geometry=s}this.output.length!==t.length&&(this.output=new Uint8ClampedArray(t.length));const r=t===this.output?t.slice():t,n="transparent"===this.edge?N:D;for(let a=0,s=0;a<t.length;a+=4,s+=2){n(r,e,i,this.coordinates[s],this.coordinates[s+1],this.sampled);for(let t=0;t<4;t++)this.output[a+t]=this.sampled[t]}return this.output}clear(){this.coordinates=new Float32Array(0),this.output=new Uint8ClampedArray(0),this.geometry=""}},B=["stipple","engraving","crosshatch","woodblock","risograph","pointillism"];function Y(t){return B.includes(t)}var j={density:1,weight:1,angle:-35,roughness:.35,invert:!1,secondaryInk:"#ec6752",registration:.2,seed:7};function G(t){const e=t&&"object"==typeof t&&!Array.isArray(t)?t:{},i=(t,i,a)=>{const s=e[t];return"number"==typeof s&&Number.isFinite(s)?Math.max(i,Math.min(a,s)):j[t]};return{density:i("density",0,2),weight:i("weight",.25,2),angle:i("angle",-180,180),roughness:i("roughness",0,1),invert:!0===e.invert,secondaryInk:"string"==typeof e.secondaryInk&&/^#[\da-f]{6}$/i.test(e.secondaryInk)?e.secondaryInk:j.secondaryInk,registration:i("registration",0,1),seed:Math.round(i("seed",0,65535))}}var H=["ascii","blocks","braille","dots","lines","cross","diagonal","diamond","mixed","pixel","mosaic","lego","voxel","disco","dither","hex","led","cmyk",...B],W=["none","bayer2","bayer4","bayer8","bayer16","floyd-steinberg","atkinson","stucki","sierra","sierra-lite","burkes","jarvis","halftone","lines","noise","vertical-lines","diagonal-lines","radial","blue-noise"],V=["source-over","multiply","screen","overlay","soft-light","hard-light","color-dodge","color-burn","hue","saturation","color","luminosity"],K={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"]},J={version:1,aspectRatio:"original",style:"ascii",cellSize:6,charset:" .:-=+*#%@",colorMode:"accent",ink:"#e6e3da",print:{...j},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}},Q=t=>t&&"object"==typeof t&&!Array.isArray(t)?t:{},Z=(t,e,i,a)=>"number"==typeof t&&Number.isFinite(t)?Math.min(a,Math.max(i,t)):e,_=(t,e)=>"string"==typeof t&&/^#[\da-f]{6}$/i.test(t)?t:e,$=(t,e,i)=>e.includes(t)?t:i;function tt(t={}){const e=Q(t),i=J;if(void 0!==e.version&&1!==e.version)throw new Error("Unsupported studio settings version. Update asciify-engine.");const a=Q(e.crop),s=Q(e.backdrop),r=Q(e.color),n=Q(e.dither),o=Q(e.mask),h=Q(e.effects),f=Q(e.motion),d=Q(e.hover),p={...i.effects};for(const t of["bloom","characterBloom","grain","dust","scanlines","crt","prism","rgbSplit","sharpen","vignette","glitch","pixelate","halftone"])p[t]=Z(h[t],0,0,1);p.blur=Z(h.blur,0,0,24),p.blurType=$(h.blurType,["gaussian","directional","radial","progressive"],i.effects.blurType),p.angle=Z(h.angle,0,-180,180),p.focus=Z(h.focus,.5,0,1);let g=2048;return{version:1,aspectRatio:$(e.aspectRatio,["original","16:9","9:16","1:1","4:3","3:4","21:9"],"original"),style:$(e.style,H,i.style),cellSize:Z(e.cellSize,i.cellSize,Y(String(e.style))||["pixel","mosaic","lego","voxel","disco","dots","hex","led","cmyk"].includes(String(e.style))?1:3,60),charset:"string"==typeof e.charset&&e.charset.length?Array.from(e.charset).slice(0,128).join(""):i.charset,colorMode:$(e.colorMode,["accent","source","gray"],i.colorMode),ink:_(e.ink,i.ink),print:G(e.print),warps:L(e.warps),warpEdge:$(e.warpEdge,["clamp","transparent"],"clamp"),crop:{x:Z(a.x,.5,0,1),y:Z(a.y,.5,0,1),zoom:Z(a.zoom,1,1,5),rotation:90*Math.round(Z(a.rotation,0,-360,360)/90)},backdrop:{mode:$(s.mode,["solid","transparent","source","blurred","gradient"],i.backdrop.mode),color:_(s.color,i.backdrop.color),color2:_(s.color2,i.backdrop.color2),blur:Z(s.blur,12,0,32),opacity:Z(s.opacity,1,0,1)},color:{brightness:Z(r.brightness,0,-1,1),contrast:Z(r.contrast,1,0,3),saturation:Z(r.saturation,1,0,3),grayscale:Z(r.grayscale,0,0,1),tint:_(r.tint,i.color.tint),amount:Z(r.amount,0,0,1),blend:$(r.blend,V,i.color.blend),blackPoint:Z(r.blackPoint,0,0,.99),whitePoint:Math.max(Z(r.blackPoint,0,0,.99)+1/255,Z(r.whitePoint,1,1/255,1)),gamma:Z(r.gamma,1,.25,4),shadows:Z(r.shadows,0,-1,1),highlights:Z(r.highlights,0,-1,1),curves:C(r.curves),denoise:Z(r.denoise,0,0,1),levels:"none"===r.levels?"none":"auto"},dither:{algorithm:$(n.algorithm,W,"none"),palette:"string"==typeof n.palette&&Object.prototype.hasOwnProperty.call(K,n.palette)?n.palette:"mono",colors:Array.isArray(n.colors)&&n.colors.length>=2?n.colors.slice(0,32).map(t=>_(t,"#000000")):[...i.dither.colors],amount:Z(n.amount,1,0,2),scale:Math.round(Z(n.scale,2,1,12)),threshold:Z(n.threshold,.5,0,1),motion:$(n.motion,["none","drift","shimmer"],"none"),speed:Z(n.speed,1,.1,3),direction:Z(n.direction,45,-180,180),colorSpace:$(n.colorSpace,["rgb","luminance"],"rgb")},mask:{enabled:!0===o.enabled,invert:!0===o.invert,shapes:Array.isArray(o.shapes)?o.shapes.slice(0,64).map(t=>{const e=Q(t),i=$(e.kind,["rectangle","ellipse","brush"],"rectangle"),a="brush"===i&&Array.isArray(e.points)?e.points.slice(0,g).map(t=>Array.isArray(t)?[Math.round(1e4*Z(t[0],0,0,1))/1e4,Math.round(1e4*Z(t[1],0,0,1))/1e4]:[0,0]):[];return g-=a.length,{kind:i,x:Z(e.x,0,0,1),y:Z(e.y,0,0,1),width:Z(e.width,.5,0,1),height:Z(e.height,.5,0,1),size:Z(e.size,.05,.005,.5),points:a}}):[]},lights:Array.isArray(e.lights)?e.lights.slice(0,4).map(t=>{const e=Q(t);return{x:Z(e.x,.5,0,1),y:Z(e.y,.5,0,1),radius:Z(e.radius,.3,.02,1),intensity:Z(e.intensity,.5,0,1),color:_(e.color,"#ffffff")}}):[],effects:p,motion:{type:$("string"==typeof f.type?v(f.type):f.type,x.map(t=>t.mode),"none"),speed:Z(f.speed,1,.1,3),amount:Z(f.amount,1,0,2)},hover:{effect:m(d.effect)??c.effect,strength:Z(d.strength,l.strength.default,l.strength.min,l.strength.max),radius:Z(d.radius,l.radius.default,l.radius.min,l.radius.max),edgeSafe:!0===d.edgeSafe,..."all"!==u(d.scope)&&{scope:u(d.scope)},....5!==Z(d.decay,.5,0,1)&&{decay:Z(d.decay,.5,0,1)}}}}function et(t,e,i,a,s){const r=Math.abs(s.rotation/90)%2==1,n=r?e:t,o=r?t:e,h=Math.max(i/n,a/o)*s.zoom;return{width:n*h,height:o*h,x:(i-n*h)*s.x,y:(a-o*h)*s.y,scale:h,rotated:r}}function it(t,e,i){if(Math.abs(i.crop.rotation/90)%2==1&&([t,e]=[e,t]),"original"===i.aspectRatio)return[t,e];const[a,s]=i.aspectRatio.split(":").map(Number);return t/e>a/s?[Math.round(e*a/s),e]:[t,Math.round(t*s/a)]}function at(t,e){const i={...t,...e};for(const a of["crop","backdrop","color","dither","mask","effects","motion","hover","print"])e[a]&&Object.assign(i,{[a]:{...t[a],...e[a]}});return e.color?.curves&&(i.color.curves={...t.color.curves,...e.color.curves}),tt(i)}function st(t,e,i,a=12e3,s=1){const r=Math.max(2,Number.isFinite(t)?t:960),n=Math.max(2,Number.isFinite(e)?e:540),o=Math.max(1,Math.floor(Number.isFinite(a)?a:12e3)),h=Math.max(.01,Number.isFinite(s)?s:1),l=Y(i.style)||["dither","pixel","mosaic","lego","voxel","disco","dots","hex","led","cmyk"].includes(i.style)?1:1.65;let c=Math.max(1,Math.ceil(Math.sqrt(r*n/(o*l))/h));for(;Math.ceil(r/(c*h))*Math.ceil(n/(c*h*l))>o;)c++;const m="dither"===i.style?i.dither.scale:i.cellSize,u=Math.max(c,m)*h;return{cell:u,rowHeight:u*l,columns:Math.ceil(r/u),rows:Math.ceil(n/(u*l)),minimum:c,limited:m<c}}var rt=[["ascii","Signature ASCII","Clean characters in paper white on near black.",{cellSize:4,ink:"#ece9e0",backdrop:{mode:"solid",color:"#0b0b0a"},color:{contrast:1.25,gamma:1.25},effects:{characterBloom:.12}}],["print","Newsprint","Fine diffusion in soft black on warm paper.",{style:"dither",cellSize:6,ink:"#1d1c19",backdrop:{mode:"solid",color:"#efece4"},dither:{algorithm:"floyd-steinberg",palette:"custom",colors:["#efece4","#1d1c19"],scale:2}}],["handheld","Pocket camera","Four-tone ordered dither in graphite.",{style:"dither",cellSize:6,ink:"#dedbd2",backdrop:{mode:"solid",color:"#121211"},dither:{algorithm:"bayer4",palette:"custom",colors:["#121211","#3e3d39","#8a8880","#dedbd2"],scale:2}}],["riso","Two inks","Muted blue and coral on warm paper.",{style:"dither",cellSize:6,ink:"#3d5068",backdrop:{mode:"solid",color:"#f0ece3"},dither:{algorithm:"atkinson",palette:"custom",colors:["#f0ece3","#c27461","#3d5068"],scale:2}}],["night","Night signal","Graphite characters with a faint optical fringe.",{cellSize:4,ink:"#cdc9be",backdrop:{mode:"solid",color:"#0b0b0a"},color:{contrast:1.2,gamma:1.2},effects:{prism:.2,scanlines:.08,vignette:.3,bloom:.12}}],["terminal","Phosphor","Soft sage glyphs with a faint glow.",{cellSize:5,ink:"#a4c9b3",backdrop:{mode:"solid",color:"#0a0d0b"},effects:{bloom:.16,scanlines:.12,crt:.06}}],["mosaic","Mosaic study","Separated tiles in quiet source color.",{style:"mosaic",ink:"#e6e3da",cellSize:9,colorMode:"source",backdrop:{mode:"solid",color:"#0b0b0a"},color:{saturation:.55,contrast:1.05}}],["bricks","Brickwork","Studded cells in softened color.",{style:"lego",ink:"#e6e3da",cellSize:12,colorMode:"source",backdrop:{mode:"solid",color:"#0b0b0a"},color:{saturation:.55}}],["voxel","Little volumes","Three-face isometric tiles in muted color.",{style:"voxel",ink:"#e6e3da",cellSize:12,colorMode:"source",backdrop:{mode:"solid",color:"#0b0b0a"},color:{saturation:.5}}],["disco","Mirror room","Faceted tiles under one soft light.",{style:"disco",ink:"#e6e3da",cellSize:11,colorMode:"source",backdrop:{mode:"solid",color:"#0b0b0a"},color:{saturation:.5},lights:[{x:.35,y:.25,radius:.28,intensity:.28,color:"#f4efe4"}]}],["wallpaper","Wallpaper","Living ASCII over a softened source.",{cellSize:5,backdrop:{mode:"blurred",color:"#0b0b0a",blur:18,opacity:.4},ink:"#e6e3da",motion:{type:"relight",speed:.35,amount:.8}}],["blueprint","Blueprint","Fine linework in pale blue on deep navy.",{style:"lines",cellSize:6,ink:"#b3c9d8",backdrop:{mode:"solid",color:"#0e1b28"}}]].map(([t,e,i,a])=>({id:t,name:e,description:i,settings:tt(a)}));function nt(t){const e=rt.find(e=>e.id===t);if(!e)throw new Error("Unknown studio look.");return tt(e.settings)}var ot="dot-fill";function ht(t){const e=function(t){const e=t.blackPoint??0,i=t.whitePoint??1,a=t.gamma??1,s=t.shadows??0,r=t.highlights??0;if(0===e&&1===i&&1===a&&0===s&&0===r)return null;const n=[0,.25+.2*s,.5,.75+.2*r,1],o=n.slice(1).map((t,e)=>4*(t-n[e])),h=[o[0],...o.slice(1).map((t,e)=>2*t*o[e]/(t+o[e])),o[3]],l=new Uint8Array(256);for(let t=0;t<256;t++){const s=Math.pow(Math.max(0,Math.min(1,(t/255-e)/(i-e))),1/a),r=Math.min(3,Math.floor(4*s)),o=4*s-r,c=o*o,m=c*o,u=(2*m-3*c+1)*n[r]+(m-2*c+o)*h[r]/4+(-2*m+3*c)*n[r+1]+(m-c)*h[r+1]/4;l[t]=Math.round(255*Math.max(0,Math.min(1,u)))}return l}(t),i=t.curves;if(!e&&(!i||Object.values(i).every(t=>t.every(([t,e])=>t===e))))return null;const a=I(i?.rgb),s=[i?.red,i?.green,i?.blue].map(I),r=new Uint8Array(768);for(let t=0;t<256;t++)for(let i=0;i<3;i++)r[256*i+t]=s[i][a[e?e[t]:t]];return r}var lt=class{constructor(t=0){this.amount=0,this.weights=new Float32Array(256),this.source=new Uint8ClampedArray(0),this.configure(t)}configure(t=0){const e=Math.max(0,Math.min(1,Number.isFinite(t)?t:0));if(e===this.amount)return;if(this.amount=e,0===e)return void(this.source=new Uint8ClampedArray(0));const i=8+24*e;for(let t=0;t<256;t++)this.weights[t]=Math.exp(-t*t/(2*i*i))}apply(t,e,i){if(!this.amount)return;if(!Number.isInteger(e)||!Number.isInteger(i)||e<1||i<1||e*i*4!==t.length)throw new Error("Denoise dimensions do not match the source.");this.source.length!==t.length&&(this.source=new Uint8ClampedArray(t.length));const a=this.source;a.set(t);for(let s=0;s<i;s++)for(let r=0;r<e;r++){const n=4*(s*e+r);if(!a[n+3])continue;const o=a[n],h=a[n+1],l=a[n+2];let c=0,m=0,u=0,f=0;for(let t=-1;t<=1;t++){const n=s+t;if(!(n<0||n>=i))for(let i=-1;i<=1;i++){const s=r+i;if(s<0||s>=e)continue;const d=4*(n*e+s);if(!a[d+3])continue;const p=Math.max(Math.abs(a[d]-o),Math.abs(a[d+1]-h),Math.abs(a[d+2]-l)),g=this.weights[p]*(0===i?1:.6)*(0===t?1:.6)*a[d+3];c+=a[d]*g,m+=a[d+1]*g,u+=a[d+2]*g,f+=g}}t[n]=o+(c/f-o)*this.amount,t[n+1]=h+(m/f-h)*this.amount,t[n+2]=l+(u/f-l)*this.amount}}},ct=2*Math.PI,mt=t=>Math.max(0,Math.min(1,t)),ut=.1,ft=t=>Math.max(-.1,Math.min(1.1,t)),dt=Float32Array.from({length:2048},(t,e)=>Math.sin(e/2048*ct)),pt=t=>dt[2047&Math.floor(t*(2048/ct))];function gt(t,e,i){let a=Math.imul(t,374761393)^Math.imul(e,668265263)^Math.imul(i,1442695041);return a=Math.imul(a^a>>>13,1274126177),((a^a>>>16)>>>0)/4294967296}function Mt(t){const e=G(t),{density:i,weight:a,angle:s,roughness:r,invert:n,secondaryInk:o,registration:h,seed:l}=e,c=s*Math.PI/180,m=[c,c+Math.PI/2,c+Math.PI/4].map(t=>[Math.cos(t),Math.sin(t)]),u=new Float32Array(6);function f(t,e,i,s,n,o,h,c,f=!1){if(h<=0)return;const[d,p]=m[c],g=-p,M=d,x=g*(e+.5)+M*(i+.5),v=.5*(Math.abs(g)+Math.abs(M)),y=f?1:.5,b=Math.ceil((x-v)/y),w=Math.floor((x+v)/y),k=Math.min(.94*y,.72*y*h*a);t.lineWidth=o*k,t.beginPath();for(let a=b;a<=w;a++){const h=a*y-x,c=.5+g*h,m=.5+M*h;let v=-2,b=2;if(Math.abs(d)>1e-8){const t=-c/d,e=(1-c)/d;v=Math.max(v,Math.min(t,e)),b=Math.min(b,Math.max(t,e))}else if(c<0||c>1)continue;if(Math.abs(p)>1e-8){const t=-m/p,e=(1-m)/p;v=Math.max(v,Math.min(t,e)),b=Math.min(b,Math.max(t,e))}else if(m<0||m>1)continue;if(!(b<=v))if(f&&(v-=ut,b+=ut),f){for(let t=0;t<6;t++){const s=v+(b-v)*t/5,r=d*(e+c+d*s)+p*(i+m+p*s);u[t]=.5*pt(5.3*r+1.9*a+l)+.25*pt(13.1*r+a)}for(let e=0;e<2;e++)for(let i=0;i<6;i++){const a=v+(b-v)*(e?5-i:i)/5,h=u[e?5-i:i],l=.5*k*(1+r*h*.5)*(e?-1:1),f=s+ft(c+d*a+g*l)*o,x=n+ft(m+p*a+M*l)*o;e||i?t.lineTo(f,x):t.moveTo(f,x)}t.closePath()}else t.moveTo(s+(c+d*v)*o,n+(m+p*v)*o),t.lineTo(s+(c+d*b)*o,n+(m+p*b)*o)}f?t.fill():t.stroke()}return{settings:e,paint(t,e,s,c,u,d,p,g,M,x,v,y,b){const w=mt((n?1-g:g)*i);if(w<=0||t.globalAlpha<=0)return;t.fillStyle=M,t.strokeStyle=M;const k=gt(s,c,l);if("engraving"===e||"crosshatch"===e||"woodblock"===e){const i=w*(1-r*k*.3);"woodblock"===e?f(t,s,c,u,d,p,Math.ceil(5*i)/5,0,!0):(f(t,s,c,u,d,p,i,0),"crosshatch"===e&&(f(t,s,c,u,d,p,Math.max(0,1.5*i-.3),1),f(t,s,c,u,d,p,Math.max(0,2*i-1.2),2)))}else if("risograph"===e){const e="source"===b?mt(.5+(x-y)/510):.5,i=.38*h*p,n=p*Math.min(.48,.44*Math.sqrt(w)*a);t.beginPath(),t.arc(u+.5*p,d+.5*p,n*Math.sqrt(.35+.65*(1-e)),0,ct),t.fill(),t.globalCompositeOperation="multiply",t.fillStyle=o;const f=1-r*gt(s,c,l+13)*.3;t.beginPath(),t.arc(u+.5*p+i*m[0][0],d+.5*p+i*m[0][1],n*Math.sqrt(.3+.7*e)*f,0,ct),t.fill(),t.globalCompositeOperation="source-over"}else{const i=t.fillEllipse;"stipple"===e&&t.beginPath();for(let n=0;n<4;n++){const o=gt(2*s+n%2,2*c+(n>>1),l),h=gt(s,c,l+11*n+1),m=u+((n%2+.5)/2+(o-.5)*r*.28)*p,f=d+((.5+(n>>1))/2+(h-.5)*r*.28)*p,g=Math.min(m-u,u+p-m,f-d,d+p-f,p*Math.min(.245,.21*a*Math.sqrt(w)*(1-r*o*.35)));if("stipple"===e)t.moveTo(m+g,f),t.arc(m,f,g,0,ct);else{const e=(o-.5)*r*64;if(i&&"accent"!==b){const t=Math.round(x+e);i(m,f,g,.64*g,o*Math.PI,t,"source"===b?Math.round(v-.4*e):t,"source"===b?Math.round(y-e):t);continue}t.fillStyle="source"===b?`rgb(${Math.round(x+e)},${Math.round(v-.4*e)},${Math.round(y-e)})`:"gray"===b?`rgb(${Math.round(x+e)},${Math.round(x+e)},${Math.round(x+e)})`:M,t.beginPath(),t.ellipse(m,f,g,.64*g,o*Math.PI,0,ct),t.fill()}}"stipple"===e&&t.fill()}}}}var xt=new Set(["none","floyd-steinberg","atkinson","stucki","sierra","sierra-lite","burkes","jarvis"]);function vt(t){return"dither"===t.style&&("shimmer"===t.dither.motion||"drift"===t.dither.motion&&t.dither.amount>0&&!xt.has(t.dither.algorithm))}function yt(t){return"none"!==t.motion.type&&(t.motion.amount??1)>0}function bt(t){return yt(t)||vt(t)||t.effects.grain>0||t.effects.dust>0||t.effects.glitch>0}var wt=11,kt=t=>Math.max(0,Math.min(1,t)),At=(t,e,i)=>{const a=kt((i-t)/(e-t));return a*a*(3-2*a)};function St(t,e,i=256){let a=0;for(let e=0;e<t.length;e++)t[e]>a&&(a=t[e]);if(a<=0)return 0;const s=new Uint32Array(i);for(let e=0;e<t.length;e++)s[Math.min(i-1,Math.floor(Math.max(0,t[e])/a*i))]++;let r=0;const n=t.length*e;for(let t=0;t<i;t++)if(r+=s[t],r>=n)return(t+1)/i*a;return a}var Ft=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));const e=this.arrays[this.next++];return t?e.set(t):e.fill(0),e}reset(){this.next=0}},Et=null;function Rt(t,e,i,a,s){const r=2*s+1;for(let n=0;n<a;n++){const a=n*i;let o=0;for(let e=-s;e<=s;e++)o+=t[a+Math.max(0,Math.min(i-1,e))];for(let n=0;n<i;n++)e[a+n]=o/r,o+=t[a+Math.min(i-1,n+s+1)]-t[a+Math.max(0,n-s)]}for(let n=0;n<i;n++){let o=0;for(let t=-s;t<=s;t++)o+=e[Math.max(0,Math.min(a-1,t))*i+n];for(let h=0;h<a;h++)t[h*i+n]=o/r,o+=e[Math.min(a-1,h+s+1)*i+n]-e[Math.max(0,h-s)*i+n]}}function Tt(t,e,i,a,s,r,n){const o=i*a,h=n.take(),l=n.take(e),c=n.take(t),m=n.take(),u=n.take();for(let i=0;i<o;i++)m[i]=e[i]*e[i],u[i]=e[i]*t[i];Rt(l,h,i,a,s),Rt(c,h,i,a,s),Rt(m,h,i,a,s),Rt(u,h,i,a,s);for(let t=0;t<o;t++){const e=(u[t]-l[t]*c[t])/(m[t]-l[t]*l[t]+r);m[t]=e,u[t]=c[t]-e*l[t]}Rt(m,h,i,a,s),Rt(u,h,i,a,s);for(let i=0;i<o;i++)t[i]=m[i]*e[i]+u[i]}function Pt(t,e,i,a,s,r=2){for(let n=0;n<r;n++){for(let r=0;r<a;r++)for(let a=0;a<i;a++){const n=r*i+a;let o=t[n];a>0&&(o=Math.max(o,Math.min(e[n],t[n-1]*s))),r>0&&(o=Math.max(o,Math.min(e[n],t[n-i]*s),a>0?Math.min(e[n],t[n-i-1]*s):0,a<i-1?Math.min(e[n],t[n-i+1]*s):0)),t[n]=o}for(let r=a-1;r>=0;r--)for(let n=i-1;n>=0;n--){const o=r*i+n;let h=t[o];n<i-1&&(h=Math.max(h,Math.min(e[o],t[o+1]*s))),r<a-1&&(h=Math.max(h,Math.min(e[o],t[o+i]*s),n>0?Math.min(e[o],t[o+i-1]*s):0,n<i-1?Math.min(e[o],t[o+i+1]*s):0)),t[o]=h}}}function Ct(t,e,i,a,s){for(let r=0;r<a;r++)for(let a=0;a<i;a++){let n=1;for(let e=Math.max(0,a-s);e<=Math.min(i-1,a+s);e++)n=Math.min(n,t[r*i+e]);e[r*i+a]=n}for(let r=0;r<a;r++)for(let n=0;n<i;n++){let o=1;for(let t=Math.max(0,r-s);t<=Math.min(a-1,r+s);t++)o=Math.min(o,e[t*i+n]);t[r*i+n]=o}}function It(t,e,i,a,s){const r=i*a,n=Math.min(i,a),o=s.take(),h=s.take(),l=s.take(),c=s.take(),m=s.take();for(let i=0;i<r;i++){const a=t[4*i+3]/255;m[i]=a,o[i]=e[4*i]/255*a,h[i]=e[4*i+1]/255*a,l[i]=e[4*i+2]/255*a,c[i]=(.299*t[4*i]+.587*t[4*i+1]+.114*t[4*i+2])/255*a}const u=s.take(),d=(t,e)=>{const r=s.take(t);return f(r,u,i,a,e),r},g=Math.max(2,Math.round(.04*n)),M=Math.max(g+2,Math.round(.12*n)),x=Math.max(2,Math.round(.05*n)),v=d(c,1),y=d(c,g),b=d(c,M),w=s.take(),k=s.take(),A=s.take(),S=s.take(),F=s.take();for(let t=0;t<a;t++)for(let e=0;e<i;e++){const s=t*i+e;w[s]=Math.abs(c[s]-v[s]),k[s]=Math.abs(v[s]-y[s]),A[s]=Math.abs(y[s]-b[s]),S[s]=Math.abs(c[t*i+Math.min(i-1,e+1)]-c[t*i+Math.max(0,e-1)]),F[s]=Math.abs(c[Math.min(a-1,t+1)*i+e]-c[Math.max(0,t-1)*i+e])}f(w,u,i,a,x),f(k,u,i,a,x),f(A,u,i,a,x),f(S,u,i,a,2),f(F,u,i,a,2);const E=Math.max(.01,St(w,.9)+St(k,.9)),R=d(o,1),T=d(h,1),P=d(l,1),C=s.take(),I=s.take(),D=s.take();let N=0;for(let t=0;t<r;t++){const e=R[t],i=T[t],a=P[t],s=Math.max(e,i,a),r=s-Math.min(e,i,a);D[t]=s,I[t]=s>.001?r/s:0,N+=r;let n=0;r>1e-4&&(n=s===e?((i-a)/r+6)%6:s===i?(a-e)/r+2:(e-i)/r+4),C[t]=60*n}const U=At(.02,.07,N/r),O=Math.max(2,Math.round(.06*a)),L=new Float32Array(a);for(let t=0;t<a;t++){let e=0;for(let a=0;a<i;a++)e+=w[t*i+a]+k[t*i+a];L[t]=e/i}let q=.5,X=0;for(let t=Math.max(O,Math.round(.12*a));t<=Math.min(a-O,Math.round(.88*a));t++){let e=0,s=0,r=0,n=0;for(let a=0;a<i;a++){let r=0,n=0,o=0,h=0,l=0,c=0;for(let e=1;e<=O;e++){const s=(t-e)*i+a,m=(t+e-1)*i+a;r+=R[s],n+=T[s],o+=P[s],h+=R[m],l+=T[m],c+=P[m]}const m=(Math.abs(r-h)+Math.abs(n-l)+Math.abs(o-c))/O;e+=m,s+=m>.12?1:0}const o=Math.max(2,Math.round(.15*a)),h=Math.max(0,t-o),l=Math.min(a,t+o);for(let e=h;e<t;e++)r+=L[e];for(let e=t;e<l;e++)n+=L[e];r/=t-h,n/=l-t;const c=At(-.05,.3,(n-r)/(n+r+1e-4)),m=At(.08,.35,e/i)*(s/i)*c;m>X&&(X=m,q=t/a)}const z=At(.15,.45,X),B=s.take(),Y=s.take(),j=s.take();for(let t=0;t<r;t++)B[t]=Math.min(o[t],h[t],l[t]);Ct(B,u,i,a,1),f(B,u,i,a,g);for(let t=0;t<r;t++)Y[t]=k[t]+A[t];let G=0,H=0,W=0;for(let t=0;t<r;t++)G+=R[t],H+=T[t],W+=P[t];G/=r,H/=r,W/=r;const V=d(R,g),K=d(T,g),J=d(P,g),Q=d(R,M),Z=d(T,M),_=d(P,M);for(let t=0;t<r;t++){const e=Math.hypot(V[t]-G,K[t]-H,J[t]-W),i=Math.hypot(V[t]-Q[t],K[t]-Z[t],J[t]-_[t]);j[t]=(e+1.5*i)*(.4+.6*I[t]*U+.4*(1-U))}const $=s.take(),tt=s.take(),et=s.take(),it=s.take(),at=s.take(),st=s.take(),rt=s.take(),nt=s.take(),ot=s.take(),ht=s.take();for(let t=0;t<a;t++)for(let e=0;e<i;e++)ht[t*i+e]=Math.abs(c[Math.min(a-1,t+1)*i+e]-c[Math.max(0,t-1)*i+e]);f(ht,u,i,a,1);for(let t=0;t<a;t++)for(let e=0;e<i;e++){const s=t*i+e,r=(t+.5)/a,n=C[s],o=I[s]*U,h=D[s],l=w[s]+k[s],c=At(175,200,n)*(1-At(250,275,n))*At(.08,.25,o),m=(1-At(45,65,n)+At(290,330,n))*At(.2,.45,o)*At(.3,.55,h),u=(1-At(.15,.35,o))*At(.45,.7,h)*z,f=(1-At(.08,.2,h))*z,d=z>.3?1-At(q,q+.1,r):1-At(.4,.8,r),p=1-At(.02,.06,l),g=1-At(.03,.09,l);tt[s]=Math.max(c*p,.7*f*(1-At(.008,.025,l)),m*g*.9)*d,et[s]=Math.max(tt[s],u*p*d),$[s]=0===t?tt[s]:0,it[s]=At(150,172,n)*(1-At(232,250,n))*At(.25,.45,o),rt[s]=At(1.3,2.2,(S[s]+.004)/(F[s]+.004))*At(.35,.55,v[s])*(1-At(.1,.18,I[s]*U))*At(.025,.07,l)*At(.025,.045,ht[s]);const M=1-At(.18,.4,o),x=At(.55,.8,h)*At(.05,.12,l);at[s]=Math.max(it[s],.85*M,.8*x)}Pt($,tt,i,a,.995,1),Pt($,et,i,a,.8,1);let lt=0;for(let t=0;t<r;t++)lt+=$[t];const ct=lt>.04*r&&z>.3;if(ct)for(let t=0;t<a;t++)for(let e=0;e<i;e++)it[t*i+e]*=At(q,q+.05,(t+.5)/a);if(ct){const t=s.take(),e=s.take(),n=s.take();for(let e=0;e<r;e++)t[e]=.299*V[e]+.587*K[e]+.114*J[e];for(let t=0;t<a;t++)for(let s=0;s<i;s++)e[t*i+s]=v[Math.min(a-1,t+1)*i+s]-v[Math.max(0,t-1)*i+s];const o=new Uint8Array(r);for(let t=1;t<a-1;t++)for(let s=0;s<i;s++){const r=Math.abs(e[t*i+s]);let n=r>.03;for(let o=-3;o<=3&&n;o++)o&&t+o>=0&&t+o<a&&Math.abs(e[(t+o)*i+s])>r&&(n=!1);o[t*i+s]=n?1:0}const h=(e,i,a,s=!0)=>{const r=V[i]+K[i]+J[i]+.05,n=V[a]+K[a]+J[a]+.05,o=Math.abs(V[i]/r-V[a]/n)+Math.abs(K[i]/r-K[a]/n)+Math.abs(J[i]/r-J[a]/n),h=Math.min(Math.abs(C[i]-C[a]),360-Math.abs(C[i]-C[a])),l=Math.max(1-At(.1,.25,o),(1-At(15,35,h))*At(.15,.3,Math.min(I[i],I[a]))),c=Math.max(At(2,3,(F[i]+.004)/(S[i]+.004))*At(.015,.04,w[i]+k[i])*At(.4,.55,w[i]/(w[i]+k[i]+1e-4)),1-At(.12,.25,t[i]));return l*(s?c:1)*(1-At(.82*t[a]+.02,1.02*t[a]+.05,t[i]))};let l=0,c=0;for(let t=Math.max(3,Math.round(a*Math.max(.25,q)));t<Math.round(.88*a);t++){let e=0;for(let a=0;a<i;a++)(o[(t-1)*i+a]||o[t*i+a]||o[(t+1)*i+a])&&e++;if(e<.5*i)continue;let s=0;for(let e=t+1;e<Math.min(a,2*t);e++)for(let a=0;a<i;a++)s+=h(t,e*i+a,(2*t-e)*i+a);s>c&&(c=s,l=t)}const m=At(.05,.1,c/r);if(m>0)for(let t=l+1;t<Math.min(a,2*l);t++)for(let e=0;e<i;e++){const a=t*i+e;nt[a]=h(l,a,(2*l-t)*i+e)*m,ot[a]=h(l,a,(2*l-t)*i+e,!1)*m,n[a]=nt[a]}f(n,u,i,a,1);for(let t=0;t<r;t++)nt[t]=Math.max(nt[t],n[t]),it[t]=Math.max(it[t],nt[t])}const mt=d(it,M);for(let t=0;t<r;t++)it[t]*=At(.15,.35,mt[t]);const ut=d(it,g);for(let t=0;t<r;t++){it[t]*=1-.8*tt[t];const e=Math.min(Math.abs(C[t]-200),360-Math.abs(C[t]-200));st[t]=At(.28,.45,I[t]*U)*At(55,80,e)*(1-At(.3,.6,ot[t]))}const ft=d(st,g);for(let t=0;t<r;t++)st[t]=Math.max(st[t]*(1-(1-At(.15,.3,ft[t]))*At(.55,.7,D[t])*At(.5,.65,I[t])),1-m[t]),at[t]=Math.min(Math.max(at[t],.9*ot[t]),Math.max(it[t],At(.25,.6,ut[t])))*(1-$[t])*(1-st[t]);Pt(it,at,i,a,.97);const dt=s.take(rt),pt=Math.max(2,Math.round(.12*a));for(let t=0;t<i;t++){let e=0;for(let s=-pt;s<=pt;s++)e+=rt[Math.max(0,Math.min(a-1,s))*i+t];for(let s=0;s<a;s++)dt[s*i+t]=e/(2*pt+1),e+=rt[Math.min(a-1,s+pt+1)*i+t]-rt[Math.max(0,s-pt)*i+t]}f(dt,u,i,a,1);for(let t=0;t<r;t++)rt[t]=At(.2,.45,dt[t])*At(.2,.5,rt[t]+.5*dt[t])*(1-$[t]);Tt($,c,i,a,Math.max(2,Math.round(.04*n)),.002,s),Tt(it,c,i,a,Math.max(2,Math.round(.04*n)),.002,s),Tt(rt,c,i,a,Math.max(2,Math.round(.03*n)),.002,s),f(st,u,i,a,1);for(let t=0;t<r;t++)$[t]=At(.3,.7,$[t])*m[t],rt[t]=At(.3,.7,rt[t])*m[t]*(1-$[t]),it[t]=At(.3,.7,it[t])*(1-$[t])*(1-rt[t])*(1-At(.15,.4,st[t]));Ct($,u,i,a,2),Ct(it,u,i,a,2),Ct(rt,u,i,a,1),f($,u,i,a,1),f(it,u,i,a,1),f(rt,u,i,a,1);const gt=1/Math.max(.02,St(j,.97)),Mt=1/Math.max(.01,St(Y,.9)),xt=St(B,.97),vt=St(B,.1),yt=At(.06,.25,xt-vt),bt=s.take();for(let t=0;t<a;t++)for(let e=0;e<i;e++){const s=t*i+e,r=(e+.5)/i,n=(t+.5)/a,o=Math.max($[s],it[s]),h=w[s]+k[s]+A[s],l=.6*kt(((w[s]+.6*k[s])/(h+.004)-.25)/.55)+.4*kt((w[s]+k[s])/E),c=At(.04,.35,h/E)*(1-o),m=.55*kt((B[s]-vt)/Math.max(.05,xt-vt))+.25*(1-kt(Y[s]*Mt))+.2*kt(2*(P[s]-R[s])+.3)*U,u=yt*At(.12,.35,y[s])*(.4+.6*z),f=z*(n<q?.45:.45+.55*At(0,1,(n-q)/Math.max(.15,1-q)))+(1-z)*(.5+.4*(n-.5)),d=w[s]/(w[s]+k[s]+1e-4),p=At(.2,.7,(w[s]+k[s])/E)*(.35+.65*z)*(1-o),g=1-kt(1.5*Math.hypot(1.2*(r-.5),n-.52)),M=kt(j[s]*gt)*(.55+.45*g),x=.3*c,v=.25*u,b=.12+.45*z,S=.12*p,F=.35*(1-.4*z)*(1-o);bt[s]=(x*l+v*(1-m)+b*f+S*kt(1.6-1.6*d)+F*M+.04)/(x+v+b+S+F+.08)*(1-.85*$[s])*(1-.45*it[s]*(1-z))}const wt=p(t,i,a);if("none"!==wt.key)for(let t=0;t<r;t++)bt[t]=.7*wt.subject[t]+.3*bt[t];return f(bt,u,i,a,Math.max(1,Math.round(.03*n))),function(t,e,i,a,s,r,n,o,h){const l=s*r,c=h.take(),m=t=>(Rt(t,c,s,r,n),t),u=(t,e)=>{const i=h.take();for(let a=0;a<l;a++)i[a]=t[a]*e[a];return m(i)},f=m(h.take(e)),d=m(h.take(i)),p=m(h.take(a)),g=m(h.take(t)),M=u(e,e),x=u(e,i),v=u(e,a),y=u(i,i),b=u(i,a),w=u(a,a),k=u(e,t),A=u(i,t),S=u(a,t),F=h.take(),E=h.take(),R=h.take(),T=h.take();for(let t=0;t<l;t++){const e=k[t]-f[t]*g[t],i=A[t]-d[t]*g[t],a=S[t]-p[t]*g[t],s=M[t]-f[t]*f[t]+o,r=x[t]-f[t]*d[t],n=v[t]-f[t]*p[t],h=y[t]-d[t]*d[t]+o,l=b[t]-d[t]*p[t],c=w[t]-p[t]*p[t]+o,m=h*c-l*l,u=n*l-r*c,P=r*l-n*h,C=s*c-n*n,I=r*n-s*l,D=s*h-r*r,N=s*m+r*u+n*P,U=Math.abs(N)>1e-12?1/N:0;F[t]=(m*e+u*i+P*a)*U,E[t]=(u*e+C*i+I*a)*U,R[t]=(P*e+I*i+D*a)*U,T[t]=g[t]-F[t]*f[t]-E[t]*d[t]-R[t]*p[t]}m(F),m(E),m(R),m(T);for(let s=0;s<l;s++)t[s]=F[s]*e[s]+E[s]*i[s]+R[s]*a[s]+T[s]}(bt,R,T,P,i,a,Math.max(2,Math.round(.07*n)),.004,s),{depth:bt,water:it,sky:$,falls:rt}}function Dt(t,e,i,a,s,r,n){if(e===r&&i===n)return t[s*r+a];const o=Math.max(0,Math.min(e-1,(a+.5)*e/r-.5)),h=Math.max(0,Math.min(i-1,(s+.5)*i/n-.5)),l=Math.min(e-2,Math.floor(o)),c=Math.min(i-2,Math.floor(h)),m=o-l,u=h-c;if(l<0||c<0)return t[Math.round(h)*e+Math.round(o)];const f=c*e+l,d=f+e;return(t[f]*(1-m)+t[f+1]*m)*(1-u)+(t[d]*(1-m)+t[d+1]*m)*u}var Nt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Ut="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",Ot=new Uint16Array(4096);for(let t=0;t<Ot.length;t++)Ot[t]=Nt.indexOf(Ut[2*t])<<6|Nt.indexOf(Ut[2*t+1]);var Lt=(t,e)=>{const i=43758.5453*Math.sin(127.1*t+311.7*e);return i-Math.floor(i)};var qt=new Map([2,4,8,16].map(t=>[t,Float64Array.from({length:t*t},(e,i)=>function(t,e,i){let a=0;for(let s=1;s<i;s*=2){const i=(Math.floor(t/s)%2+2)%2;a=4*a+[[0,2],[3,1]][(Math.floor(e/s)%2+2)%2][i]}return(a+.5)/(i*i)-.5}(i%t,Math.floor(i/t),t))])),Xt={"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,.25],[2,0,4/32],[-2,1,2/32],[-1,1,4/32],[0,1,.25],[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]]},zt=t=>[parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16)];function Bt(t,e,i){const a=Math.min(t*Math.max(1,i),(1-t)*Math.max(1,i),e*Math.max(1,1/i),(1-e)*Math.max(1,1/i)),s=Math.max(0,Math.min(1,(a-.035)/.105));return s*s*s*(s*(6*s-15)+10)}var Yt=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,i,a){if(!Number.isFinite(t+e+i))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e));const s=Number.isFinite(a)?a/1e3:this.clock,r=this.previous;if(this.previous={x:t,y:e,time:s},!r)return;const n=this.width/this.height,o=Math.hypot((t-r.x)*Math.max(1,n),(e-r.y)*Math.max(1,1/n));if(o<1e-4||this.clock-this.lastRing<1/24)return;const h=o/Math.max(1/240,Math.min(.1,s-r.time||1/60)),l=5*this.slot;this.slot=(this.slot+1)%8,this.rings[l]=t,this.rings[l+1]=e,this.rings[l+2]=0,this.rings[l+3]=Math.min(.9,.26+.2*h),this.rings[l+4]=.035+.13*Math.max(.1,Math.min(1,i)),this.alive=!0,this.lastRing=this.clock}step(t){if(!Number.isFinite(t)||t<=0)return;const e=Math.min(.05,t);if(this.clock+=e,!this.alive)return;this.values.fill(0),this.alive=!1;const i=this.width/this.height,a=Math.max(1,i),s=Math.max(1,1/i);for(let t=0;t<this.rings.length;t+=5){if(!this.rings[t+3])continue;const i=this.rings[t+2]+=e;if(i>2.8){this.rings[t+3]=0;continue}this.alive=!0;const r=this.rings[t+4],n=.17*i,o=this.rings[t+3]*(1-Math.exp(20*-i))*Math.exp(2.5*-i),h=n+1.8*r,l=this.rings[t],c=this.rings[t+1],m=Math.max(0,Math.floor((l-h/a)*(this.width-1))),u=Math.min(this.width-1,Math.ceil((l+h/a)*(this.width-1))),f=Math.max(0,Math.floor((c-h/s)*(this.height-1))),d=Math.min(this.height-1,Math.ceil((c+h/s)*(this.height-1)));for(let t=f;t<=d;t++)for(let e=m;e<=u;e++){const i=(Math.hypot((e/(this.width-1)-l)*a,(t/(this.height-1)-c)*s)-n)/r;Math.abs(i)>1.8||(this.values[t*this.width+e]+=o*Math.cos(i*Math.PI*2)*Math.exp(-i*i*2.5))}}for(let t=0;t<this.height;t++)for(let e=0;e<this.width;e++){const a=t*this.width+e,s=this.values[a]=Math.max(-1,Math.min(1,this.values[a]))*(this.edgeSafe?Bt(e/(this.width-1),t/(this.height-1),i):1),r=Math.round(32767*s+32768);this.pixels[4*a]=r>>>8,this.pixels[4*a+1]=255&r}}sample(t,e,i){const a=Math.max(0,Math.min(this.width-1.001,t*(this.width-1))),s=Math.max(0,Math.min(this.height-1.001,e*(this.height-1))),r=Math.floor(a),n=Math.floor(s),o=a-r,h=s-n,l=n*this.width+r,c=l+this.width;i[0]=i[1]=0,i[2]=3*((this.values[l]*(1-o)+this.values[l+1]*o)*(1-h)+(this.values[c]*(1-o)+this.values[c+1]*o)*h)}},jt=t=>["dissolve","silk","vortex","magnetic","scatter","etch","elastic","lens","smudge"].includes(t),Gt=t=>"elastic"===t||"scatter"===t,Ht={elastic:[150,4.2],scatter:[90,3.6]},Wt=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;const i=t*e;this.pixels=new Uint8Array(4*i),this.ink=new Float32Array(i),this.targetX=new Float32Array(i),this.targetY=new Float32Array(i),this.offsetX=new Float32Array(i),this.offsetY=new Float32Array(i),this.edge=new Float32Array(i);for(let i=0;i<e;i++)for(let a=0;a<t;a++)this.edge[i*t+a]=Bt(a/(t-1),i/(e-1),t/e);this.clear()}get active(){return this.peak>2e-4}setMode(t){if(Gt(t)&&!this.springX&&(this.springX=new Float32Array(this.ink.length),this.springY=new Float32Array(this.ink.length)),"scatter"===t&&!this.scatterDirections){const t=this.scatterDirections=new Float64Array(this.width*this.height*2),e=(t,e)=>{const i=43758.5453*Math.sin(127.1*t+311.7*e);return i-Math.floor(i)};for(let i=0;i<this.height;i++)for(let a=0;a<this.width;a++){const s=.09*a,r=.09*i,n=Math.floor(s),o=Math.floor(r),h=s-n,l=r-o,c=h*h*(3-2*h),m=l*l*(3-2*l),u=((e(n,o)*(1-c)+e(n+1,o)*c)*(1-m)+(e(n,o+1)*(1-c)+e(n+1,o+1)*c)*m)*Math.PI*4,f=2*(i*this.width+a);t[f]=.7*Math.cos(u),t[f+1]=.7*Math.sin(u)}}t!==this.mode&&(this.mode=t,this.clear())}clear(){for(const 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),"dissolve"!==this.mode)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,i){if(!Number.isFinite(t+e+i))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e));const a=this.previous;this.previous={x:t,y:e};const s=this.width,r=this.height,n=Math.max(1,s/r),o=Math.max(1,r/s),h=a?(t-a.x)*n:0,l=a?(e-a.y)*o:0,c=Math.hypot(h,l);if(!a&&"dissolve"!==this.mode&&"etch"!==this.mode&&"lens"!==this.mode)return;if(a&&c<1e-4)return;const m=.035+.11*Math.max(.1,Math.min(1,i)),u=Math.min(128,Math.max(1,Math.ceil(c/(.45*m)))),f=c?h/c:1,d=c?l/c:0,p=a||"lens"!==this.mode?Math.min(1,c/(m*u)*2.2):.32;for(let i=0;i<u;i++){const h=(i+.5)/u,l=a?a.x+(t-a.x)*h:t,c=a?a.y+(e-a.y)*h:e,g=Math.max(0,Math.floor((l-2.5*m/n)*(s-1))),M=Math.min(s-1,Math.ceil((l+2.5*m/n)*(s-1))),x=Math.max(0,Math.floor((c-2.5*m/o)*(r-1))),v=Math.min(r-1,Math.ceil((c+2.5*m/o)*(r-1)));for(let t=x;t<=v;t++)for(let e=g;e<=M;e++){const i=(e/(s-1)-l)*n/m,a=(t/(r-1)-c)*o/m,h=Math.exp(1.5*-(i*i+a*a)),u=t*s+e;if("dissolve"===this.mode||"etch"===this.mode)this.ink[u]=Math.max(this.ink[u],h);else if("elastic"===this.mode)this.springX[u]=Math.max(-24,Math.min(24,this.springX[u]+f*h*p*12)),this.springY[u]=Math.max(-24,Math.min(24,this.springY[u]+d*h*p*12));else if("scatter"===this.mode){const t=this.scatterDirections;this.springX[u]=Math.max(-24,Math.min(24,this.springX[u]+(.6*i+t[2*u])*h*p*7)),this.springY[u]=Math.max(-24,Math.min(24,this.springY[u]+(.6*a+t[2*u+1])*h*p*7))}else if("lens"===this.mode)this.targetX[u]=Math.max(-.65,Math.min(.65,this.targetX[u]+i*h*p*1.6)),this.targetY[u]=Math.max(-.65,Math.min(.65,this.targetY[u]+a*h*p*1.6));else if("smudge"===this.mode)this.targetX[u]=Math.max(-1,Math.min(1,this.targetX[u]+f*h*p*1.3)),this.targetY[u]=Math.max(-1,Math.min(1,this.targetY[u]+d*h*p*1.3));else{const t=(-i*d+a*f)*h*2.8,e="magnetic"===this.mode?-i*h*2.5:"silk"===this.mode?f*t:-a*h*2.5,s="magnetic"===this.mode?-a*h*2.5:"silk"===this.mode?d*t:i*h*2.5;this.targetX[u]=Math.max(-1,Math.min(1,this.targetX[u]+e*p)),this.targetY[u]=Math.max(-1,Math.min(1,this.targetY[u]+s*p))}}}this.peak=1}step(t){if(!this.active||!Number.isFinite(t))return;const e=Math.max(0,Math.min(.05,t)),i="dissolve"===this.mode?2.15:"smudge"===this.mode?2.4:3.2,a="lens"===this.mode?16:22,s=Math.exp(-i*e),r=1-Math.exp(-a*e);let n=0;const[o,h]="scatter"===this.mode?Ht.scatter:Ht.elastic,l=Math.sqrt(o-h*h),c=Math.exp(-h*e),m=Math.cos(l*e),u=Math.sin(l*e)/l;for(let t=0;t<this.ink.length;t++)if("etch"===this.mode)this.ink[t]*=s,n=Math.max(n,this.ink[t]);else if("dissolve"===this.mode){this.ink[t]*=s,n=Math.max(n,this.ink[t]);const e=Math.round(65535*this.ink[t]);this.pixels[4*t]=e>>>8,this.pixels[4*t+1]=255&e}else{if(Gt(this.mode)){const e=this.offsetX[t],i=this.offsetY[t],a=this.springX[t],s=this.springY[t];this.offsetX[t]=Math.max(-1,Math.min(1,c*(e*m+(a+h*e)*u))),this.offsetY[t]=Math.max(-1,Math.min(1,c*(i*m+(s+h*i)*u))),this.springX[t]=c*(a*m-(h*a+o*e)*u),this.springY[t]=c*(s*m-(h*s+o*i)*u),n=Math.max(n,.05*Math.abs(this.springX[t]),.05*Math.abs(this.springY[t]))}else if("lens"===this.mode||"smudge"===this.mode){const e=1-r,n=a/(a-i)*(s-e);this.offsetX[t]=this.offsetX[t]*e+this.targetX[t]*n,this.offsetY[t]=this.offsetY[t]*e+this.targetY[t]*n,this.targetX[t]*=s,this.targetY[t]*=s}else this.targetX[t]*=s,this.targetY[t]*=s,this.offsetX[t]+=(this.targetX[t]-this.offsetX[t])*r,this.offsetY[t]+=(this.targetY[t]-this.offsetY[t])*r;n=Math.max(n,Math.abs(this.offsetX[t]),Math.abs(this.offsetY[t]),Math.abs(this.targetX[t]),Math.abs(this.targetY[t]));const e=Math.round(this.offsetX[t]*(this.edgeSafe?this.edge[t]:1)*32767+32768),l=Math.round(this.offsetY[t]*(this.edgeSafe?this.edge[t]:1)*32767+32768);this.pixels[4*t]=e>>>8,this.pixels[4*t+1]=255&e,this.pixels[4*t+2]=l>>>8,this.pixels[4*t+3]=255&l}if("etch"===this.mode)for(let t=0;t<this.height;t++)for(let e=0;e<this.width;e++){const i=t*this.width+e,a=3*(this.ink[t*this.width+Math.max(0,e-1)]-this.ink[t*this.width+Math.min(this.width-1,e+1)]+this.ink[Math.max(0,t-1)*this.width+e]-this.ink[Math.min(this.height-1,t+1)*this.width+e]);this.offsetX[i]=Math.max(-1,Math.min(1,a))*(this.edgeSafe?this.edge[i]:1);const s=Math.round(32767*this.offsetX[i]+32768);this.pixels[4*i]=s>>>8,this.pixels[4*i+1]=255&s}this.peak=n,this.active||this.clear()}sample(t,e,i){const a=Math.max(0,Math.min(this.width-1.001,t*(this.width-1))),s=Math.max(0,Math.min(this.height-1.001,e*(this.height-1))),r=Math.floor(a),n=Math.floor(s),o=a-r,h=s-n,l=n*this.width+r,c=l+this.width,m=t=>(t[l]*(1-o)+t[l+1]*o)*(1-h)+(t[c]*(1-o)+t[c+1]*o)*h;if("etch"===this.mode)return i[0]=i[1]=0,void(i[2]=3*m(this.offsetX));i[0]=m(this.offsetX)*(this.edgeSafe?Bt(t,e,this.width/this.height):1)*.08,i[1]=m(this.offsetY)*(this.edgeSafe?Bt(t,e,this.width/this.height):1)*.08,i[2]="dissolve"===this.mode?6*-m(this.ink):0}},Vt=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,i){const a=Math.max(1,this.width/this.height),s=Math.max(1,this.height/this.width);this.previous&&(Math.hypot((t-this.previous.x)*a,(e-this.previous.y)*s)<.065||this.elapsed<.3)||4!==this.rings.length&&(this.previous={x:t,y:e},this.elapsed=0,this.rings.push({x:t,y:e,age:0,radius:i}))}ringSample(t,e){const i=Math.max(1,this.width/this.height),a=Math.max(1,this.height/this.width);let s=0;for(const r of this.rings){const n=.015+r.age*(.15+.22*r.radius),o=.009+.014*r.radius,h=(Math.hypot((t-r.x)*i,(e-r.y)*a)-n)/o,l=Math.sin(Math.min(1,r.age/.07)*Math.PI/2)*Math.max(0,1-r.age/1.35)**2;s=Math.max(s,Math.exp(-h*h)*l)}return s}sample(t,e){const i=Math.max(0,Math.min(this.width-1,Math.round(t*(this.width-1)))),a=Math.max(0,Math.min(this.height-1,Math.round(e*(this.height-1))));return Math.max(this.ringSample(t,e),this.echo[a*this.width+i])}step(t){if(!Number.isFinite(t))return;const e=Math.max(0,Math.min(.05,t));this.elapsed+=e;for(const t of this.rings)t.age+=e;if(this.rings=this.rings.filter(t=>t.age<1.35),!this.active)return void this.pixels.fill(0);const i=Math.exp(-5.5*e);let a=0;for(let t=0;t<this.height;t++)for(let e=0;e<this.width;e++){const s=t*this.width+e;this.echo[s]=Math.max(this.ringSample(e/(this.width-1),t/(this.height-1)),this.echo[s]*i),a=Math.max(a,this.echo[s]);const r=Math.round(65535*this.echo[s]),n=4*s;this.pixels[n]=r>>>8,this.pixels[n+1]=255&r}this.echoPeak=a,this.active||(this.echo.fill(0),this.pixels.fill(0))}},Kt=class{constructor(t,e){this.previous=null,this.peak=0,this.width=t,this.height=e;const i=t*e;this.pixels=new Uint8Array(4*i),this.signal=new Float32Array(i),this.offsetX=new Float32Array(i),this.offsetY=new Float32Array(i),this.driftX=new Float32Array(i),this.driftY=new Float32Array(i),this.u=new Float32Array(i),this.v=new Float32Array(i),this.ink=new Float32Array(i),this.a=new Float32Array(i),this.b=new Float32Array(i),this.c=new Float32Array(i),this.pressure=new Float32Array(i),this.pressureNext=new Float32Array(i),this.divergence=new Float32Array(i),this.curl=new Float32Array(i)}get active(){return this.peak>2e-4}clear(){for(const 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,i,a=performance.now()){if(!Number.isFinite(t+e+i+a))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e)),i=Math.max(.1,Math.min(1,i));const s=this.previous;if(this.previous={x:t,y:e,time:a},!s)return;const r=(t-s.x)*(this.width-1),n=(e-s.y)*(this.height-1),o=Math.hypot(r,n);if(o<.001)return;const h=Math.min(this.width,this.height),l=a>s.time?Math.max(1/240,(a-s.time)/1e3):1/60,c=Math.min(12,o/h/l),m=1-Math.exp(-c/2.2),u=h*(.022+.075*i)*(.65+.95*m),f=Math.min(128,Math.max(1,Math.ceil(o/(.4*u)))),d=o/u*(.32+.22*m)/f,p=r/o,g=n/o,M=-g,x=p,v=o*(2+18*m)/f;for(let i=0;i<f;i++){const a=(i+.5)/f,r=(s.x+(t-s.x)*a)*(this.width-1),n=(s.y+(e-s.y)*a)*(this.height-1),o=Math.max(1,Math.floor(r-3*u)),h=Math.min(this.width-2,Math.ceil(r+3*u)),l=Math.max(1,Math.floor(n-3*u)),c=Math.min(this.height-2,Math.ceil(n+3*u));for(let t=l;t<=c;t++)for(let e=o;e<=h;e++){const i=((e-r)*p+(t-n)*g)/u,a=((e-r)*M+(t-n)*x)/u,s=Math.exp(-i*i*.65-a*a*1.7),o=t*this.width+e;this.ink[o]=1-(1-this.ink[o])*Math.exp(-s*d);const h=1-a*a*.55,l=i*a*.7;this.u[o]=Math.max(-80,Math.min(80,this.u[o]+(p*h+M*l)*s*v)),this.v[o]=Math.max(-80,Math.min(80,this.v[o]+(g*h+x*l)*s*v))}}this.peak=1}read(t,e,i){const a=0|(e=Math.max(.5,Math.min(this.width-1.5,e))),s=0|(i=Math.max(.5,Math.min(this.height-1.5,i))),r=e-a,n=i-s,o=s*this.width+a;return(t[o]*(1-r)+t[o+1]*r)*(1-n)+(t[o+this.width]*(1-r)+t[o+this.width+1]*r)*n}sample(t,e){return this.read(this.signal,t*(this.width-1),e*(this.height-1))}displacement(t,e,i){i[0]=this.read(this.offsetX,t*(this.width-1),e*(this.height-1)),i[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));const i=this.width,a=this.height;for(;e>1e-7;){const t=Math.min(1/60,e);e-=t;const s=Math.exp(-1.9*t),r=Math.exp(-3.2*t);for(let e=1;e<a-1;e++)for(let n=1;n<i-1;n++){const o=e*i+n,h=Math.max(.5,Math.min(i-1.5,n-this.u[o]*t)),l=Math.max(.5,Math.min(a-1.5,e-this.v[o]*t)),c=0|h,m=0|l,u=h-c,f=l-m,d=m*i+c,p=(1-u)*(1-f),g=u*(1-f),M=(1-u)*f,x=u*f;this.a[o]=(this.u[d]*p+this.u[d+1]*g+this.u[d+i]*M+this.u[d+i+1]*x)*s,this.b[o]=(this.v[d]*p+this.v[d+1]*g+this.v[d+i]*M+this.v[d+i+1]*x)*s,this.c[o]=(this.ink[d]*p+this.ink[d+1]*g+this.ink[d+i]*M+this.ink[d+i+1]*x)*r}[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 t=1;t<a-1;t++)for(let e=1;e<i-1;e++){const a=t*i+e;this.curl[a]=.5*(this.v[a+1]-this.v[a-1]-this.u[a+i]+this.u[a-i])}for(let e=1;e<a-1;e++)for(let a=1;a<i-1;a++){const s=e*i+a,r=Math.abs(this.curl[s+1])-Math.abs(this.curl[s-1]),n=Math.abs(this.curl[s+i])-Math.abs(this.curl[s-i]),o=Math.hypot(r,n)+1e-4,h=this.curl[s]*t*10,l=Math.hypot(this.u[s],this.v[s]);this.u[s]+=n/o*h,this.v[s]-=r/o*h;const c=Math.min(1,l/(Math.hypot(this.u[s],this.v[s])+1e-6));this.u[s]*=c,this.v[s]*=c,this.divergence[s]=-.5*(this.u[s+1]-this.u[s-1]+this.v[s+i]-this.v[s-i])}this.pressure.fill(0);for(let t=0;t<4;t++){for(let t=1;t<a-1;t++)for(let e=1;e<i-1;e++){const a=t*i+e;this.pressureNext[a]=.25*(this.divergence[a]+this.pressure[a-1]+this.pressure[a+1]+this.pressure[a-i]+this.pressure[a+i])}[this.pressure,this.pressureNext]=[this.pressureNext,this.pressure]}let n=0;for(let e=1;e<a-1;e++)for(let a=1;a<i-1;a++){const s=e*i+a;this.u[s]=Math.max(-80,Math.min(80,this.u[s]-.5*(this.pressure[s+1]-this.pressure[s-1]))),this.v[s]=Math.max(-80,Math.min(80,this.v[s]-.5*(this.pressure[s+i]-this.pressure[s-i]))),this.driftX[s]+=(3.6*this.u[s]-58*this.offsetX[s]-12*this.driftX[s])*t,this.driftY[s]+=(3.6*this.v[s]-58*this.offsetY[s]-12*this.driftY[s])*t,this.offsetX[s]=Math.max(-2,Math.min(2,this.offsetX[s]+this.driftX[s]*t)),this.offsetY[s]=Math.max(-2,Math.min(2,this.offsetY[s]+this.driftY[s]*t)),this.signal[s]=1-Math.exp(.06*-Math.hypot(this.u[s],this.v[s])-.16*this.ink[s]),n=Math.max(n,this.signal[s])}this.peak=n}if(this.active)for(let t=0;t<this.ink.length;t++){const e=Math.round(65535*Math.min(1,this.signal[t]));this.pixels[4*t]=e>>>8,this.pixels[4*t+1]=255&e,this.pixels[4*t+2]=Math.round(128+63.5*this.offsetX[t]),this.pixels[4*t+3]=Math.round(128+63.5*this.offsetY[t])}else this.clear()}};var Jt=["loupe","repel","tilt","reveal","haze","bleed"],Qt=t=>Jt.includes(t),Zt=class{constructor(){this.value=0,this.velocity=0}step(t,e,i,a){const s=2*Math.sqrt(i)*a;for(let a=e;a>1e-6;a-=1/480){const e=Math.min(1/480,a);this.velocity+=((t-this.value)*i-this.velocity*s)*e,this.value+=this.velocity*e}}resting(t){return Math.abs(this.value-t)<.0015&&Math.abs(this.velocity)<.01}set(t){this.value=t,this.velocity=0}},_t=t=>t*t*(3-2*t),$t=(t,e)=>{const i=43758.5453*Math.sin(127.1*t+311.7*e);return i-Math.floor(i)};function te(t,e){const i=Math.floor(t),a=Math.floor(e),s=_t(t-i),r=_t(e-a),n=$t(i,a),o=$t(i+1,a),h=$t(i,a+1);return(n+(o-n)*s)*(1-r)+(h+($t(i+1,a+1)-h)*s)*r}var ee=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 Zt,this.y=new Zt,this.tx=new Zt,this.ty=new Zt,this.presence=new Zt,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(),"bleed"===t&&!this.ink)){const t=this.width*this.height;this.ink=new Float32Array(t),this.next=new Float32Array(t),this.fiber=new Float32Array(t);for(let t=0;t<this.height;t++)for(let e=0;e<this.width;e++)this.fiber[t*this.width+e]=.35+.5*te(.09*e,.045*t)+.15*$t(e,t)}}setRadius(t){this.radius=Math.max(.1,Math.min(1,t))}get reach(){return(.05+.25*this.radius)*("loupe"===this.mode?1-.14*this.speed: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(){const 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||"haze"===this.mode&&this.presence.value>.002||this.inkPeak>.002}tiltGoal(t){return this.target&&"tilt"===this.mode?2*((t?this.target.y:this.target.x)-.5):0}clear(){for(const 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,i){if(!Number.isFinite(t+e))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e));const a=Number.isFinite(i)?i/1e3:this.clock,s=this.target;if(!s&&this.presence.value<.05&&(this.x.set(t),this.y.set(e)),s){const i=Math.hypot((t-s.x)*this.sx,(e-s.y)*this.sy),r=i/Math.max(1/240,Math.min(.1,a-s.time||1/60));this.speed=Math.max(this.speed,Math.min(1,r/1.6)),"bleed"===this.mode&&this.deposit(s.x,s.y,t,e,Math.min(1,9*i))}else"bleed"===this.mode&&this.deposit(t,e,t,e,.5);this.target={x:t,y:e,time:a}}leave(){this.target=null}deposit(t,e,i,a,s){const r=this.ink,n=this.width,o=this.height,h=.55*this.reach,l=Math.hypot((i-t)*this.sx,(a-e)*this.sy),c=Math.min(48,Math.max(1,Math.ceil(l/(.5*h))));for(let l=0;l<c;l++){const m=(l+.5)/c,u=t+(i-t)*m,f=e+(a-e)*m,d=Math.max(0,Math.floor((u-2*h/this.sx)*(n-1))),p=Math.min(n-1,Math.ceil((u+2*h/this.sx)*(n-1))),g=Math.max(0,Math.floor((f-2*h/this.sy)*(o-1))),M=Math.min(o-1,Math.ceil((f+2*h/this.sy)*(o-1)));for(let t=g;t<=M;t++)for(let e=d;e<=p;e++){const i=(e/(n-1)-u)*this.sx/h,a=(t/(o-1)-f)*this.sy/h,l=t*n+e;r[l]=Math.min(1.4,r[l]+Math.exp(1.8*-(i*i+a*a))*s/c*1.6)}}this.inkPeak=Math.max(this.inkPeak,.01)}step(t){if(!Number.isFinite(t)||t<=0)return;const e=Math.min(.05,t),i=e*this.settle;this.clock+=e;const a=this.target,s=this.mode;if(a?this.presence.step(1,e,190,1):this.presence.step(0,i,"repel"===s?120:70,"repel"===s?.42:1),a){const t="tilt"===s?60:"haze"===s?90:240,i="loupe"===s||"repel"===s?.72:.9;this.x.step(a.x,e,t,i),this.y.step(a.y,e,t,i)}this.tx.step(this.tiltGoal(0),a?e:i,45,.78),this.ty.step(this.tiltGoal(1),a?e:i,45,.78),this.speed*=Math.exp(7*-e),"bleed"===s&&this.spread(e,i,!!a),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,i){const a=this.ink,s=this.next,r=this.fiber,n=this.width,o=this.height;i&&this.target&&this.deposit(this.x.value,this.y.value,this.x.value,this.y.value,.9*t);const h=Math.max(1,Math.ceil(t/(1/240))),l=t/h,c=26*(.4+this.radius),m=(i?.02:.1)*e/t,u=Math.exp(-(i?.15:.9)*e/h);let f=0;for(let t=0;t<h;t++){f=0;for(let t=1;t<o-1;t++)for(let e=1;e<n-1;e++){const i=t*n+e,o=a[i],h=r[i],d=Math.min(h,r[i-1])*(a[i-1]-o)+Math.min(h,r[i+1])*(a[i+1]-o)+Math.min(h,r[i-n])*(a[i-n]-o)+Math.min(h,r[i+n])*(a[i+n]-o),p=Math.max(0,(o+d*Math.min(.24,c*l))*u-m*l);s[i]=p,p>f&&(f=p)}a.set(s)}this.inkPeak=f}sample(t,e,i){i[0]=i[1]=i[2]=0;const a=this.presence.value,s=this.mode;if("bleed"===s){if(this.inkPeak<=.002)return;const a=this.width,s=this.height,r=this.ink,n=Math.max(0,Math.min(a-1.001,t*(a-1))),o=Math.max(0,Math.min(s-1.001,e*(s-1))),h=Math.floor(n),l=Math.floor(o),c=n-h,m=o-l,u=l*a+h,f=u+a,d=(r[u]*(1-c)+r[u+1]*c)*(1-m)+(r[f]*(1-c)+r[f+1]*c)*m;return void(i[2]=1-Math.exp(2.4*-d))}if("tilt"===s){const a=this.guide?function(t,e,i,a){const s=t[e],r=t.width,n=t.height,o=Math.max(0,Math.min(r-1.001,i*(r-1))),h=Math.max(0,Math.min(n-1.001,a*(n-1))),l=Math.floor(o),c=Math.floor(h),m=o-l,u=h-c,f=c*r+l,d=Math.min(n-1,c+1)*r+l,p=l+1<r?1:0;return(s[f]*(1-m)+s[f+p]*m)*(1-u)+(s[d]*(1-m)+s[d+p]*m)*u}(this.guide,"depth",t,e):.6,s=.2+.8*a,r=this.edgeSafe?Bt(t,e,this.sx/this.sy):1;return i[0]=.024*this.tx.value*s*r/this.sx,void(i[1]=.024*this.ty.value*s*r/this.sy)}if(a<=.001)return;const r=this.reach,n=(t-this.x.value)*this.sx,o=(e-this.y.value)*this.sy,h=(n*n+o*o)/(r*r);if("reveal"===s)return void(i[2]=Math.exp(2.4*-h)*a);if(h>9)return;const l=this.edgeSafe?Bt(t,e,this.sx/this.sy):1;let c=0,m=0;if("loupe"===s){const t=Math.exp(-h*h)*a*.5;c=n*t,m=o*t;const e=Math.sqrt(h)-1;i[2]=Math.exp(-e*e/.018)*a*.55}else if("repel"===s){const t=Math.sqrt(h),e=.5*r*Math.exp(-h/1.7)*a,s=Math.max(1e-6,Math.sqrt(n*n+o*o));c=n/s*Math.min(e,s+.5*r*a),m=o/s*Math.min(e,s+.5*r*a);const l=Math.max(0,Math.min(1,(t-.3)/.32));i[2]=-(1-l*l*(3-2*l))*a}else if("haze"===s){const s=o/r+.45,h=Math.exp(-n*n/(r*r)-s*s/2.6)*a*(.35+.65*Math.min(1,1.4*this.speed+.25));if(h<.002)return;const l=this.clock,u=t*this.sx*9,f=e*this.sy*9+2.3*l;c=.06*(te(u,f)-.5)*h,m=.026*(te(u+17.3,1.3*f+.7*l)-.5)*h,i[2]=.35*(te(1.7*u+5,1.7*f)-.5)*h}i[0]=c*l/this.sx,i[1]=m*l/this.sy}encode(){const t=this.width,e=this.height,i=this.pixels,a=this.sampled,s=this.engaged;for(let r=0;r<e;r++)for(let n=0;n<t;n++){const o=4*(r*t+n);if(s?this.sample(n/(t-1),r/(e-1),a):a[0]=a[1]=a[2]=0,"bleed"===this.mode){const t=Math.round(32767*Math.max(-1,Math.min(1,a[2]))+32768);i[o]=t>>>8,i[o+1]=255&t,i[o+2]=128,i[o+3]=0}else{"repel"===this.mode&&(a[0]*=.3,a[1]*=.3);const t=Math.round(32767*Math.max(-1,Math.min(1,a[0]/.16))+32768),e=Math.round(32767*Math.max(-1,Math.min(1,a[1]/.16))+32768);i[o]=t>>>8,i[o+1]=255&t,i[o+2]=e>>>8,i[o+3]=255&e}}}},ie=(t,e)=>"water"===t?30*e/.55:"silk"===t?28*e:"vortex"===t?38*e:["magnetic","scatter","elastic","lens","smudge"].includes(t)?32*e:["loupe","repel","tilt","haze"].includes(t)?.16*e/.55:0;function ae(t,e,i,a=!1){if(!i)return e;const s=t=>Math.max(0,Math.min(1,t));switch(t){case"trail":case"contour":return function(t,e){const i=Math.max(0,Math.min(1,e/.38));return t+i*i*(3-2*i)*(1-2*t)}(e,i);case"etch":case"ripple":return s(e+.35*i);case"dissolve":{const t=Math.max(0,1+i);return a?1-(1-e)*t:e*t}case"bleed":return s(e+i*(a?-.6:.6));case"loupe":return s(e+.3*i);case"haze":return s(e+.5*i);default:return e}}var se=t=>["trail","contour","etch","ripple","bleed","haze"].includes(t),re=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(2*this.heights.length),this.edgeMask=new Float32Array(this.heights.length);for(let e=0;e<this.rows;e++)for(let i=0;i<this.columns;i++)this.edgeMask[e*this.columns+i]=Bt(i/(this.columns-1),e/(this.rows-1),t);this.refraction={width:this.columns,height:this.rows,pixels:new Uint8Array(4*this.heights.length),strength:30,mode:"water",focus:[.5,.5,0,.2]},this.waterPixels=this.refraction.pixels,this.trail=new Kt(this.columns,this.rows),this.contour=new Vt(this.columns,this.rows),this.afterimage=new Wt(this.columns,this.rows),this.clear()}get invertsDensity(){return"trail"===this.mode}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 Qt(this.mode)?this.cursor.engaged:this.active}get spotlight(){return"reveal"===this.mode&&this.cursor?this.cursor.focus:null}get signature(){return Qt(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 Qt(this.mode)?this.cursor.active:"ripple"===this.mode?this.ripple?.active??!1:jt(this.mode)?this.afterimage.active:"contour"===this.mode?this.contour.active:"trail"===this.mode?this.trail.active:this.pending||this.energy>15e-5}setMode(t){const e="light"===t||"scan"===t?t:m(t)??"none";e!==this.mode&&(this.clear(),this.mode=e,this.refraction.mode=e,jt(e)&&this.afterimage.setMode(e),"ripple"!==e||this.ripple||(this.ripple=new Yt(this.columns,this.rows)),Qt(e)&&(this.cursor??(this.cursor=new ee(this.columns,this.rows)),this.cursor.guide=this.guide,this.cursor.setMode(e)),this.refraction.pixels=Qt(e)?this.cursor.pixels:"ripple"===e?this.ripple.pixels:"trail"===e?this.trail.pixels:"contour"===e?this.contour.pixels:jt(e)?this.afterimage.pixels:this.waterPixels,this.refraction.strength=ie(e,this.amount),this.refraction.relative=Qt(e))}configure(t,e=.55,i=.2,a=!1,s=.5){this.setMode(t),this.settle=((t=.5)=>Math.pow(2,2.4*(.5-(Number.isFinite(t)?Math.max(0,Math.min(1,t)):.5))))(s),this.refraction.edgeSafe=a,this.afterimage.edgeSafe=a,this.ripple&&(this.ripple.edgeSafe=a),this.amount=Number.isFinite(e)?Math.max(0,Math.min(1,e)):.55,this.radius=Number.isFinite(i)?Math.max(.1,Math.min(1,i)):.2,this.cursor&&(this.cursor.edgeSafe=a,this.cursor.settle=this.settle,this.cursor.setRadius(this.radius)),this.refraction.strength=ie(this.mode,this.amount),this.refraction.focus[2]=this.densityTrail?this.amount:this.lensStrength*this.amount,this.refraction.focus[3]=this.radius,"reveal"!==this.mode&&"repel"!==this.mode||this.syncSpot()}syncSpot(){const t=this.cursor.focus;this.refraction.focus=[t[0],t[1],t[2]*("repel"===this.mode?Math.min(1,this.amount/.55):this.amount),t[3]]}move(t,e,i){if("none"===this.mode||0===this.amount)return;if(!Number.isFinite(t+e))return;if(t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e)),Qt(this.mode))return void this.cursor.move(t,e,i);if("ripple"===this.mode)return void this.ripple.move(t,e,this.radius,i);if(jt(this.mode))return void this.afterimage.move(t,e,this.radius);if("contour"===this.mode)return void this.contour.move(t,e,this.radius);if("trail"===this.mode)return void this.trail.move(t,e,this.radius,i);if("water"!==this.mode)return!this.previous&&this.lensStrength<.001&&(this.lensX=t,this.lensY=e),this.previous={x:t,y:e},void(this.pending=!0);if(!this.previous)return void(this.previous={x:t,y:e});const a=this.previous;this.previous={x:t,y:e};const s=(t-a.x)*this.xScale,r=(e-a.y)*this.yScale,n=Math.hypot(s,r);if(n<1e-5)return;const o=.035+.1*this.radius,h=3*o,l=Math.min(192,Math.max(1,Math.ceil(n/(.5*o)))),c=95*Math.min(n,1)/l;for(let i=0;i<l;i++){const s=(i+.5)/l,r=a.x+(t-a.x)*s,n=a.y+(e-a.y)*s,m=Math.max(1,Math.floor((r-h/this.xScale)*(this.columns-1))),u=Math.min(this.columns-2,Math.ceil((r+h/this.xScale)*(this.columns-1))),f=Math.max(1,Math.floor((n-h/this.yScale)*(this.rows-1))),d=Math.min(this.rows-2,Math.ceil((n+h/this.yScale)*(this.rows-1)));for(let t=f;t<=d;t++)for(let e=m;e<=u;e++){const i=(e/(this.columns-1)-r)*this.xScale,a=(t/(this.rows-1)-n)*this.yScale,s=Math.exp(-(i*i+a*a)/(o*o))*c,h=t*this.columns+e;this.velocity[h]=Math.max(-12,this.velocity[h]-s)}}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,"water"!==this.mode&&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(Qt(this.mode))return this.cursor.step(t),void("reveal"!==this.mode&&"repel"!==this.mode||this.syncSpot());if(t*=this.settle,"ripple"===this.mode)return void this.ripple.step(t);if(jt(this.mode))return void this.afterimage.step(t);if("contour"===this.mode)return void this.contour.step(t);if("trail"===this.mode)return void this.trail.step(t);if("water"!==this.mode)return void this.stepLight(Math.max(0,Math.min(.05,t)));this.remainder+=Math.max(0,Math.min(.05,t));const e=1/120,i=.3*Math.min(this.columns,this.rows);for(;this.remainder+1e-8>=e;){this.remainder-=e,this.quiet+=e;const t=Math.max(0,Math.min(1,(this.quiet-.2)/.6)),a=t*t*(3-2*t),s=Math.exp(-(3.8+3*a)*e),r=Math.exp(7*-a*e);let n=0;for(let t=1;t<this.rows-1;t++)for(let a=1;a<this.columns-1;a++){const o=t*this.columns+a,h=this.heights[o],l=this.heights[o-1]+this.heights[o+1]+this.heights[o-this.columns]+this.heights[o+this.columns]-4*h,c=Math.min(a,t,this.columns-1-a,this.rows-1-t),m=c<5?.88+.024*c:1,u=(this.velocity[o]+(l*i*i-8*h)*e)*s*m;this.velocity[o]=u,this.next[o]=(h+u*e)*m*r,n=Math.max(n,Math.abs(this.next[o]),.1*Math.abs(u))}this.heights.set(this.next),this.energy=n,this.pending=!1}if(!this.active)return void this.clear();const a=.18*Math.min(this.columns,this.rows);for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++){const i=t*this.columns+e,s=(this.heights[t*this.columns+Math.max(0,e-1)]-this.heights[t*this.columns+Math.min(this.columns-1,e+1)])*a,r=(this.heights[Math.max(0,t-1)*this.columns+e]-this.heights[Math.min(this.rows-1,t+1)*this.columns+e])*a,n=Math.tanh(s)*(this.refraction.edgeSafe?this.edgeMask[i]:1),o=Math.tanh(r)*(this.refraction.edgeSafe?this.edgeMask[i]:1);this.normals[2*i]=n,this.normals[2*i+1]=o;const h=Math.round(32767*n+32768),l=Math.round(32767*o+32768);this.refraction.pixels[4*i]=h>>>8,this.refraction.pixels[4*i+1]=255&h,this.refraction.pixels[4*i+2]=l>>>8,this.refraction.pixels[4*i+3]=255&l}}stepLight(t){const e=this.previous,i=1-Math.exp(-30*t),a=1-Math.exp(-12*t);e&&(this.lensX+=(e.x-this.lensX)*i,this.lensY+=(e.y-this.lensY)*i),this.lensStrength+=((e?1:0)-this.lensStrength)*a,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.refraction.focus=[this.lensX,this.lensY,this.lensStrength*this.amount,this.radius]:this.clear()}sample(t,e,i){if(Qt(this.mode))return this.cursor.sample(t,e,i),i[0]*=this.amount/.55,i[1]*=this.amount/.55,void(i[2]*="reveal"===this.mode||"repel"===this.mode?Math.min(1,this.amount/.55):3*this.amount);if("ripple"===this.mode)return this.ripple.sample(t,e,i),void(i[2]*=this.amount);if(jt(this.mode))return this.afterimage.sample(t,e,i),i[0]*=this.amount,i[1]*=this.amount,void(i[2]*=this.amount);if("contour"===this.mode)return i[0]=i[1]=0,void(i[2]=this.contour.sample(t,e)*this.amount*3);if("trail"===this.mode)return i[0]=i[1]=0,void(i[2]=this.trail.sample(t,e)*this.amount*3);const a=Math.max(0,Math.min(this.columns-1.001,t*(this.columns-1))),s=Math.max(0,Math.min(this.rows-1.001,e*(this.rows-1))),r=Math.floor(a),n=Math.floor(s),o=a-r,h=s-n,l=2*(n*this.columns+r),c=l+2*this.columns;for(let t=0;t<2;t++)i[t]=.08*((this.normals[l+t]*(1-o)+this.normals[l+2+t]*o)*(1-h)+(this.normals[c+t]*(1-o)+this.normals[c+2+t]*o)*h);i[0]*=this.amount/.55,i[1]*=this.amount/.55,i[2]="light"===this.mode||"scan"===this.mode?function(t,e,i,a){const[s,r,n,o]=i.focus,h=(t-s)*Math.max(1,a)/o,l=(e-r)*Math.max(1,1/a)/o;return"light"===i.mode?Math.exp(-3*(h*h+l*l))*n:"scan"===i.mode?(1.3*Math.exp(-h*h*110)-.3*Math.exp(-h*h*12))*Math.exp(-l*l*1.8)*n:0}(t,e,this.refraction,this.xScale/this.yScale):0}};function ne(t){return"videoWidth"in t?[t.videoWidth,t.videoHeight]:"naturalWidth"in t?[t.naturalWidth,t.naturalHeight]:[t.width,t.height]}var oe=(t=!1)=>{const e=document.createElement("canvas"),i=e.getContext("2d",{willReadFrequently:t});if(!i)throw new Error("Canvas 2D is unavailable.");return{canvas:e,ctx:i}},he=(t,e,i)=>{t.width===e&&t.height===i||(t.width=e,t.height=i)},le={blocks:" ░▒▓█",braille:" ⠁⠃⠇⡇⣇⣧⣷⣿",lines:" -═╪╬",cross:" ·+xX#",diagonal:" /╱╳",diamond:" ·◇◈◆",mixed:" .:+/◇#@"},ce=new Set(["pointillism","stipple","led","dots"]),me=.32,ue=.9;function fe(t){const e=new Uint32Array(256);let i=0;for(let a=0;a<t.length;a+=4)t[a+3]<8||(e[Math.min(255,.299*t[a]+.587*t[a+1]+.114*t[a+2]|0)]++,i++);if(!i)return[0,1];const a=t=>{let a=0;const s=t*i;for(let t=0;t<256;t++)if((a+=e[t])>=s)return t/255;return 1};let s=a(.01),r=a(.99);return r-s<me&&(s=Math.max(0,Math.min(1-me,(s+r)/2-.16)),r=s+me),[s,r]}function de(t,e,i){const a=Math.max(.001,i-e);let s=0,r=0;for(let i=0;i<t.length;i+=4){if(t[i+3]<8)continue;const n=((.299*t[i]+.587*t[i+1]+.114*t[i+2])/255-e)/a;n<=.06||(s+=Math.min(1,n),r++)}if(!r)return ue;const n=Math.min(.99,Math.max(.01,s/r));return Math.min(ue,Math.max(.6,Math.log(.5)/Math.log(n)))}function pe(t,e=.9){const i=Math.min(...t),a=Math.max(...t);if(!(a-i>1e-4))return null;const s=t.map(t=>(t-i)/(a-i)),r=new Uint8Array(256);for(let t=0;t<256;t++){if(t/255<.07){r[t]=s.indexOf(0);continue}const i=Math.pow(t/255,e);let a=0;for(let t=1;t<s.length;t++)Math.abs(s[t]-i)<Math.abs(s[a]-i)&&(a=t);r[t]=a}return r}function ge(t,e,i,a){t.clearRect(0,0,e,i),t.fillStyle="#fff",t.strokeStyle="#fff",t.lineCap="round",t.lineJoin="round";for(const s of a){if(t.beginPath(),"ellipse"===s.kind)t.ellipse((s.x+s.width/2)*e,(s.y+s.height/2)*i,s.width*e/2,s.height*i/2,0,0,2*Math.PI);else{if("rectangle"!==s.kind){if(t.lineWidth=(s.size??.05)*e,1===s.points?.length){t.arc(s.points[0][0]*e,s.points[0][1]*i,t.lineWidth/2,0,2*Math.PI),t.fill();continue}s.points?.forEach(([a,s],r)=>r?t.lineTo(a*e,s*i):t.moveTo(a*e,s*i)),t.stroke();continue}t.rect(s.x*e,s.y*i,s.width*e,s.height*i)}t.fill()}}var Me=new WeakMap,xe=t=>Math.max(64,Math.min(4096,Number.isFinite(t)?t:960));function ve(t,e,i){const a=Math.min(1,t/Math.max(e,i));return[Math.max(2,Math.round(e*a)),Math.max(2,Math.round(i*a))]}function ye(t,e,i,a,s){const[r,n]=ne(e);t.clearRect(0,0,i,a),t.save();const o=et(r,n,i,a,s);t.translate(o.x+o.width/2,o.y+o.height/2),t.rotate(s.rotation*Math.PI/180),t.drawImage(e,-r*o.scale/2,-n*o.scale/2,r*o.scale,n*o.scale),t.restore()}function be(t,e={},i={}){return function(t,e,i,a){const s=a.surface,r=t.getContext("2d");if(!r)throw new Error("Canvas is already owned by another renderer.");const n=s(),o=s(!0),h=s(),l=s(),c=s(),m=s(),u=s(),d=s(),M=s(),x=s();let v,y,b=0,w=0,k=1,S=ue,R=null,T=null,P=null,C="",I=tt(e),N=0,U="",O="",L="",q=new Uint8ClampedArray(0),X=new Uint8ClampedArray(0),B=new Uint8ClampedArray(0),j=null,G="",H=0,W=0,V=0,J=null,Q="",Z=new re,_=null,$=new Float32Array(0);const et=s(!0),it=s(),at=s();let rt=0;const nt=[0,0,0],ct=[0,0,0,1],mt=[0,0],ut=[0,0,0,0];let ft=ht(I.color),dt=Mt(I.print);const pt=new lt(I.color.denoise),gt=new z(I.warps,I.warpEdge),xt=xe(i.maxDimension),bt=Math.max(256,Math.min(1048576,Number.isFinite(i.maxCells)?i.maxCells:12e3));let At=bt,Rt=Math.max(.1,Math.min(8,i.pixelRatio??1));const Tt=(t,e,i)=>{Z.configure(I.hover.effect,I.hover.strength,I.hover.radius,I.hover.edgeSafe,I.hover.decay),Z.move(t,e,i)};function Pt(t,e=0,i=960,a=540,s=e*I.motion.speed){Ct(t,e,i,a,s,!0)}function Ct(e,i,s,z,tt,ht){if(Number.isFinite(i)||(i=0),!Number.isFinite(s)||!Number.isFinite(z)||s<1||z<1)throw new Error("Render dimensions must be positive finite numbers.");const[lt,Mt]=ne(e);if(!lt||!Mt)return;const[bt,Tt]=ve(xt,s,z);he(t,bt,Tt),he(n.canvas,bt,Tt),he(h.canvas,bt,Tt),he(l.canvas,bt,Tt),he(c.canvas,bt,Tt),rt!==bt/Tt&&(rt=bt/Tt,Z=new re(rt),Z.setGuide(_)),Z.configure(I.hover.effect,I.hover.strength,I.hover.radius,I.hover.edgeSafe,I.hover.decay),Z.step(Math.max(0,Math.min(.05,i-V))),V=i;const Pt=a.media(e),Ct=[N,bt,Tt,Pt.time].join(":"),Nt="dither"===I.style,Ut=st(bt,Tt,I,At,Rt),Bt=Ut.cell,Yt=Ut.rowHeight,jt=Ut.columns,Gt=Ut.rows;if(U!==Ct||J!==Pt.key||H!==jt||W!==Gt){J=Pt.key,U=Ct,G="",O="",L="",H=jt,W=Gt,a.scene?a.scene(n.ctx,bt,Tt):ye(n.ctx,e,bt,Tt,I.crop),he(o.canvas,H,W),o.ctx.clearRect(0,0,H,W),o.ctx.drawImage(n.canvas,0,0,H,W),q=o.ctx.getImageData(0,0,H,W).data,pt.apply(q,H,W),X.length!==q.length&&(X=new Uint8ClampedArray(q.length)),X.set(q);const t=I.color;for(let e=0;e<q.length;e+=4){const i=.299*q[e]+.587*q[e+1]+.114*q[e+2];for(let a=0;a<3;a++){const s=i+(q[e+a]-i)*t.saturation;q[e+a]=((s*(1-t.grayscale)+i*t.grayscale)/255-.5)*t.contrast*255+127.5+255*t.brightness}}if(ft&&function(t,e){for(let i=0;i<t.length;i+=4)t[i+3]&&(t[i]=e[t[i]],t[i+1]=e[256+t[i+1]],t[i+2]=e[512+t[i+2]])}(q,ft),q=gt.apply(q,H,W,bt/Tt),"none"!==I.color.levels){const[t,e]=fe(q),i=de(q,t,e),a=R===Pt.key&&Pt.video?.15:1;R=Pt.key,w+=(t-w)*a,k+=(e-k)*a,S+=(i-S)*a}const i=I.hover,s=i.scope??"all";if("none"===i.effect||"all"===s&&"tilt"!==i.effect)_=null;else{let t=null;if(I.mask.enabled&&I.mask.shapes.length){he(et.canvas,H,W),et.ctx.clearRect(0,0,H,W),ge(et.ctx,H,W,I.mask.shapes);const e=et.ctx.getImageData(0,0,H,W).data;t=new Float32Array(H*W);for(let i=0;i<t.length;i++)t[i]=I.mask.invert?1-e[4*i+3]/255:e[4*i+3]/255}_=p(q,H,W,t,_),$.length!==H*W&&($=new Float32Array(H*W));for(let t=0;t<$.length;t++)$[t]=g(s,_.subject[t],_.key);if("reveal"===i.effect){he(it.canvas,H,W);const t=new ImageData(H,W);for(let e=0;e<$.length;e++)t.data[4*e+3]=255*$[e];it.ctx.putImageData(t,0,0)}}Z.setGuide(_)}if(!ht)return void(L=O="");const Ht=yt(I),Wt=vt(I),Vt=!Z.active&&!Ht&&!Wt,Kt=[Ct,H,W,Bt,Yt,Rt,Z.signature].join(":"),Jt=Z.engaged,Qt=Z.effect;if(!Vt||L!==Kt){h.ctx.clearRect(0,0,bt,Tt),h.ctx.globalAlpha=1,h.ctx.globalCompositeOperation="source-over";const t=tt,e=Ht?I.motion.type:"none",s=I.motion.amount??1,r="relight"===(Zt=e)||"sheen"===Zt||"glow"===Zt||"shimmer"===Zt||"mist"===Zt;"none"!==e&&G!==U&&(j=function(t,e,i,a,s=t){const r=e*i,n=a?.length===r*wt?a:new Float32Array(r*wt);if(!r)return n;const o=Math.min(e,i),h=new Float32Array(r),l=new Float32Array(r),c=new Float32Array(r),m=new Float32Array(r),u=new Float32Array(r),d=new Float32Array(r);for(let e=0;e<r;e++){const i=t[4*e+3]/255;h[e]=(.299*t[4*e]+.587*t[4*e+1]+.114*t[4*e+2])/255*i}l.set(h),f(l,d,e,i,Math.max(1,Math.round(.012*o))),c.set(h),f(c,d,e,i,Math.max(1,Math.round(.03*o)));for(let t=0;t<r;t++){m[t]=Math.abs(h[t]-l[t]);const e=Math.max(0,h[t]-.55)/.45;u[t]=e*e}f(m,d,e,i,Math.max(1,Math.round(.02*o)));const p=1/Math.max(.02,St(m,.95));f(u,d,e,i,Math.max(1,Math.round(.05*o)));const g=1/Math.max(.03,St(u,.98)),M=Math.max(1,Math.ceil(Math.sqrt(r/12e3))),x=Math.max(1,Math.floor(e/M)),v=Math.max(1,Math.floor(i/M)),y=x*v;let b=t,w=s;if(M>1){const i=new Uint8ClampedArray(4*y),a=s===t?i:new Uint8ClampedArray(4*y);for(let r=0;r<v;r++)for(let n=0;n<x;n++){const o=[0,0,0,0,0,0,0];for(let h=r*M;h<(r+1)*M;h++)for(let r=n*M;r<(n+1)*M;r++){const n=4*(h*e+r);for(let e=0;e<4;e++)o[e]+=t[n+e];if(a!==i)for(let t=0;t<3;t++)o[4+t]+=s[n+t]}const h=4*(r*x+n),l=M*M;for(let t=0;t<4;t++)i[h+t]=o[t]/l;if(a!==i){for(let t=0;t<3;t++)a[h+t]=o[4+t]/l;a[h+3]=i[h+3]}}b=i,w=a}Et?.n!==y&&(Et=new Ft(y)),Et.reset();const{depth:k,water:A,sky:S,falls:F}=It(b,w,x,v,Et),E=St(k,.03),R=St(k,.97),T=Math.max(.05,R-E);let P=0,C=0,I=0;const D=new Float32Array(r);for(let t=0;t<i;t++)for(let a=0;a<e;a++){const s=t*e+a,r=s*wt,o=kt((Dt(k,x,v,a,t,e,i)-E)/T);n[r+1]=o,n[r+8]=kt(Dt(A,x,v,a,t,e,i)),n[r+9]=kt(Dt(S,x,v,a,t,e,i)),n[r+10]=kt(Dt(F,x,v,a,t,e,i));const l=o*o*o*(.25+h[s]);P+=(a+.5)/e*l,C+=(t+.5)/i*l,I+=l,D[s]=Math.hypot(c[t*e+Math.min(e-1,a+1)]-c[t*e+Math.max(0,a-1)],c[Math.min(i-1,t+1)*e+a]-c[Math.max(0,t-1)*e+a])}P=I>0?Math.max(.3,Math.min(.7,P/I)):.5,C=I>0?Math.max(.3,Math.min(.7,C/I)):.5;const N=1/Math.max(.004,St(D,.97));for(let t=0;t<i;t++)for(let a=0;a<e;a++){const s=t*e+a,r=s*wt,o=(c[t*e+Math.min(e-1,a+1)]-c[t*e+Math.max(0,a-1)])*N,h=(c[Math.min(i-1,t+1)*e+a]-c[Math.max(0,t-1)*e+a])*N;n[r]=c[s],n[r+2]=Math.min(1,u[s]*g),n[r+3]=Math.min(1,m[s]*p),n[r+4]=Math.max(-1,Math.min(1,-o)),n[r+5]=Math.max(-1,Math.min(1,-h)),n[r+6]=P,n[r+7]=C}return n}(X,H,W,j),G=U);let p=null;if(Nt){const a=Vt;if(!a||O!==Ct){B.length!==q.length&&(B=new Uint8ClampedArray(q.length));const r=B;if(r.set(q),Jt||"none"!==e)for(let i=0;i<W;i++)for(let a=0;a<H;a++){const n=a/H,o=i/W;let h=a,l=i,c=0,m=0,u=1;if(Jt){Z.sample(n,o,nt);const t=_?$[i*H+a]:1;h-=nt[0]*t*H,l-=nt[1]*t*W,"reveal"===Qt?u=1-.72*Math.min(1,nt[2]*t):"repel"===Qt?u=1+Math.max(-1,nt[2])*t:c=nt[2]/3*t}const f=4*(i*H+a);A(e,n,o,t,ct,(.299*q[f]+.587*q[f+1]+.114*q[f+2])/255,j??void 0,(i*H+a)*wt),E(ct,s),(ct[0]||ct[1])&&(F(ct,h,l,H,W,mt),h=mt[0],l=mt[1]),m=ct[2],u*=ct[3];const d=4*(i*H+a);D(q,H,W,h,l,ut);for(let t=0;t<3;t++){let e=ae(Qt,ut[t]/255,c)+m;r[d+t]=255*e}r[d+3]=ut[3]*u}!function(t,e,i,a,s=0){const{algorithm:r,amount:n,threshold:o}=a,h="blue-noise"===r,l=r.startsWith("bayer")?Number(r.slice(5)):0,c=qt.get(l),m=l-1,u="luminance"===a.colorSpace,f=("custom"===a.palette?a.colors:K[a.palette]??K.mono).map(zt),d=Xt[r],p=d?new Float32Array(3*e*3):null,g="drift"===a.motion?s*a.speed*3:0,M=(a.direction??45)*Math.PI/180,x=Math.round(Math.cos(M)*g),v=Math.round(Math.sin(M)*g),y=(t,e)=>(t%e+e)%e,b=f.map(t=>.299*t[0]+.587*t[1]+.114*t[2]),w="shimmer"===a.motion?.15*Math.sin(s*a.speed*2):0;for(let a=0;a<i;a++)for(let s=0;s<e;s++){const M=4*(a*e+s),k=3*(a%3*e+s);if(0===t[M+3]){p&&(p[k]=p[k+1]=p[k+2]=0);continue}let A=0;const S=h?(Ot[64*(a-v&63)+(s-x&63)]+.5)/Ot.length:0;c?A=c[(a-v&m)*l+(s-x&m)]:"noise"===r?A=Lt(s-x,a-v)-.5:"lines"===r?A=y(a-v,4)/3-.5:"vertical-lines"===r?A=y(s-x,4)/3-.5:"diagonal-lines"===r?A=y(s-x+a-v,4)/3-.5:"radial"===r?A=y(Math.hypot(s-e/2,a-i/2)-g,6)/6-.5:"halftone"===r&&(A=Math.hypot(y(s-x,6)-2.5,y(a-v,6)-2.5)/3.54-.5);const F=128*(A*n+w+(.5-o)),E=t[M]+F+(p?.[k]??0),R=t[M+1]+F+(p?.[k+1]??0),T=t[M+2]+F+(p?.[k+2]??0);let P=0,C=0,I=0;if(f.length){let t=1/0,e=1/0,i=0,a=0;const s=.299*E+.587*R+.114*T;for(let r=0;r<f.length;r++){const n=f[r],o=u?(s-b[r])**2:(E-n[0])**2*.299+(R-n[1])**2*.587+(T-n[2])**2*.114;o<t?(h&&(e=t,a=i,i=r),t=o,[P,C,I]=n):h&&o<e&&(e=o,a=r)}if(h&&n>0&&Number.isFinite(e)){const t=f[a],e=t[0]-P,r=t[1]-C,o=t[2]-I,h=b[a]-b[i],l=u?h*h:e*e*.299+r*r*.587+o*o*.114,c=u?(s-b[i])*h:(E-P)*e*.299+(R-C)*r*.587+(T-I)*o*.114;S<(l?Math.max(0,Math.min(1,c/l*n)):0)&&([P,C,I]=t)}}else if(h){const t=Math.max(0,Math.min(1,.5+(S-.5)*n));P=51*Math.floor(E/51+1-t),C=51*Math.floor(R/51+1-t),I=51*Math.floor(T/51+1-t)}else P=51*Math.round(E/51),C=51*Math.round(R/51),I=51*Math.round(T/51);if(t[M]=P,t[M+1]=C,t[M+2]=I,p&&d){p[k]=p[k+1]=p[k+2]=0;for(const[t,r,o]of d){const h=s+t;if(h<0||h>=e||a+r>=i)continue;const l=3*((a+r)%3*e+h);p[l]+=(E-P)*o*n,p[l+1]+=(R-C)*o*n,p[l+2]+=(T-I)*o*n}}}}(r,H,W,I.dither,i),o.ctx.putImageData(new ImageData(r,H,W),0,0),O=a?Ct:""}h.ctx.imageSmoothingEnabled=!1,h.ctx.drawImage(o.canvas,0,0,bt,Tt)}else{const i=ce.has(I.style);i&&a.marks&&void 0===y&&(y=a.marks()),p=i&&y?.begin(bt,Tt,"led"===I.style||"dots"===I.style)?y:null;const n=Array.from(le[I.style]??I.charset),o=p?.ctx??h.ctx,l=zt(I.ink),c="ripple"===Qt||"etch"===Qt,m=c&&.299*l[0]+.587*l[1]+.114*l[2]<90?[214,214,214]:l,f="ascii"===I.style||!!le[I.style],d=Y(I.style)?I.style:null,g=Math.max(3,Math.round(.92*Yt)),M=Math.ceil(Bt+4),v=Math.ceil(Yt+4),R=[n.join(""),g,M,v,I.ink,I.colorMode].join(":");if(f&&R!==Q){Q=R,he(u.canvas,M*n.length,v),u.ctx.clearRect(0,0,u.canvas.width,v),u.ctx.font=`${g}px monospace`,u.ctx.textBaseline="middle",u.ctx.textAlign="center",u.ctx.fillStyle="accent"===I.colorMode?I.ink:"#ffffff",n.forEach((t,e)=>u.ctx.fillText(t,e*M+M/2,v/2)),T=null,C="";try{const t=u.ctx.getImageData(0,0,u.canvas.width,u.canvas.height).data;T=n.map((e,i)=>{let a=0;for(let e=0;e<u.canvas.height;e++)for(let s=i*M;s<(i+1)*M&&s<u.canvas.width;s++)a+=t[4*(e*u.canvas.width+s)+3];return a})}catch{T=null}}const N=f&&"none"!==I.color.levels;if(N&&T){const t=Q+":"+S.toFixed(2);t!==C&&(C=t,P=pe(T,S))}const U=Math.max(.001,k-w);if("lego"===I.style&&b!==Bt){b=Bt,he(x.canvas,Math.ceil(Bt),Math.ceil(Yt));const t=x.ctx;t.clearRect(0,0,x.canvas.width,x.canvas.height),t.fillStyle="rgba(255,255,255,.2)",t.strokeStyle="rgba(0,0,0,.25)",t.lineWidth=Math.max(.5,.6*Rt),t.beginPath(),t.arc(Bt/2,Yt/2,.28*Bt,0,2*Math.PI),t.fill(),t.stroke()}o.font=`${g}px monospace`,o.textBaseline="middle",o.textAlign="center";for(let i=0;i<W;i++)for(let a=0;a<H;a++){let h=a,g=i,y=0,b=0;if(Jt){Z.sample(a/H,i/W,nt);const t=_?$[i*H+a]:1;h=Math.max(0,Math.min(H-1,a-nt[0]*t*H)),g=Math.max(0,Math.min(W-1,i-nt[1]*t*W)),"reveal"===Qt?b=.72*Math.min(1,nt[2]*t):"repel"===Qt?b=-Math.max(-1,nt[2])*t:y=nt[2]/3*t}if("none"!==e){const r=4*(i*H+a);A(e,a/H,i/W,t,ct,(.299*q[r]+.587*q[r+1]+.114*q[r+2])/255,j??void 0,(i*H+a)*wt),E(ct,s),(ct[0]||ct[1])&&(F(ct,h,g,H,W,mt),h=mt[0],g=mt[1])}D(q,H,W,h,g,ut);let k=0;if(c&&y>.012&&(ut[3]?ut[3]>250&&.299*ut[0]+.587*ut[1]+.114*ut[2]<30:"outside"===I.hover.scope)){const t=Math.min(1,(y-.012)/.12);k=t*t*(3-2*t)}if(!ut[3]){if(!(k||y>.03)||"outside"!==I.hover.scope||!se(Qt))continue;ut[0]=m[0],ut[1]=m[1],ut[2]=m[2],ut[3]=k?255:Math.min(255,640*y)}const R=ut[0],C=ut[1],O=ut[2],L=(.299*R+.587*C+.114*O)/255;let X=N?Math.max(0,Math.min(1,(L-w)/U)):L;X=ae(Qt,X,y,!!d&&dt.settings.invert);const z=a*Bt,B=i*Yt;let Y=1,G=X;if("none"!==e){const t=ct[2]/(N?Math.max(.5,U):1);X=Math.max(0,Math.min(1,X+t)),G=Math.max(0,Math.min(1,G+t*(r?.45:1)))}else G=X;k&&(X=G=Math.max(X,.1+.45*k)),Y=("none"!==e?ct[3]:1)*ut[3]/255*(1-b)*(k?.3+.45*k:1),f||d||"accent"!==I.colorMode||"cmyk"===I.style?N&&"accent"===I.colorMode&&(Y*=.32+.68*Math.pow(X,S)):Y*=X,o.globalAlpha=Y;const V=255*(X-L);let K;if(p&&"accent"!==I.colorMode&&"pointillism"===I.style)K=I.ink;else if(p&&"accent"!==I.colorMode){if("source"===I.colorMode)p.ctx.fillColor(R+V,C+V,O+V);else{const t=Math.round(255*X);p.ctx.fillColor(t,t,t)}K=ot}else K="source"===I.colorMode?`rgb(${R+V},${C+V},${O+V})`:"gray"===I.colorMode?`rgb(${Math.round(255*X)},${Math.round(255*X)},${Math.round(255*X)})`:I.ink;if(o.fillStyle=K,d)dt.paint(o,d,a,i,z,B,Bt,X,K,"gray"===I.colorMode?255*X:R+V,"gray"===I.colorMode?255*X:C+V,"gray"===I.colorMode?255*X:O+V,I.colorMode);else if(f){const t=N&&P?P[Math.round(255*G)]:Math.max(0,Math.min(n.length-1,Math.round(G*(n.length-1))));if("accent"===I.colorMode?0===T?.[t]:" "===n[t])continue;"accent"===I.colorMode?o.drawImage(u.canvas,t*M,0,M,v,Math.round(z+(Bt-M)/2),Math.round(B+(Yt-v)/2),M,v):o.fillText(n[t],z+Bt/2,B+Yt/2)}else if("dots"===I.style)o.beginPath(),o.arc(z+Bt/2,B+Yt/2,.48*Bt*Math.sqrt(X),0,2*Math.PI),o.fill();else if("led"===I.style)o.beginPath(),o.arc(z+Bt/2,B+Yt/2,.39*Bt,0,2*Math.PI),o.fill(),o.globalAlpha=.35*Y,o.fillStyle="#ffffff",o.beginPath(),o.arc(z+.43*Bt,B+.4*Yt,.11*Bt,0,2*Math.PI),o.fill();else if("hex"===I.style){const t=z+Bt/2,e=B+Yt/2;o.beginPath();for(let i=0;i<6;i++){const a=Math.PI/3*i,s=t+Math.cos(a)*Bt*.49,r=e+Math.sin(a)*Yt*.49;0===i?o.moveTo(s,r):o.lineTo(s,r)}o.closePath(),o.fill()}else if("cmyk"===I.style){o.fillStyle="#ffffff",o.fillRect(z,B,Bt,Yt);const t=(t,e)=>Math.max(0,Math.min(255,"source"===I.colorMode?t+V:"gray"===I.colorMode?255*X:e*X)),e=t(R,l[0]),i=t(C,l[1]),a=t(O,l[2]),s=1-Math.max(e,i,a)/255,r=Math.max(.001,1-s),n=[["#00ffff",(1-e/255-s)/r,.36,.36],["#ff00ff",(1-i/255-s)/r,.64,.36],["#ffff00",(1-a/255-s)/r,.5,.66],["#000000",s,.5,.5]];o.globalCompositeOperation="multiply";for(const[t,e,i,a]of n)e>0&&(o.fillStyle=t,o.beginPath(),o.arc(z+Bt*i,B+Yt*a,.48*Bt*Math.sqrt(Math.max(0,e)),0,2*Math.PI),o.fill());o.globalCompositeOperation="source-over"}else if("voxel"===I.style){const t=z+Bt/2,e=B+Yt/2;o.beginPath(),o.moveTo(t,B),o.lineTo(z+Bt,B+.25*Yt),o.lineTo(t,e),o.lineTo(z,B+.25*Yt),o.closePath(),o.fill(),o.globalAlpha=.72*Y,o.beginPath(),o.moveTo(z,B+.25*Yt),o.lineTo(t,e),o.lineTo(t,B+Yt),o.lineTo(z,B+.75*Yt),o.closePath(),o.fill(),o.globalAlpha=.42*Y,o.beginPath(),o.moveTo(t,e),o.lineTo(z+Bt,B+.25*Yt),o.lineTo(z+Bt,B+.75*Yt),o.lineTo(t,B+Yt),o.closePath(),o.fill()}else{const t="pixel"===I.style?0:Math.max(.5,.06*Bt);o.fillRect(z,B,Bt-t,Yt-t),"lego"===I.style&&o.drawImage(x.canvas,z,B),"disco"===I.style&&(o.fillStyle=`rgba(255,255,255,${.1+.25*Lt(a,i)})`,o.fillRect(z,B,Bt-t,.35*Yt),o.fillStyle="rgba(0,0,0,.25)",o.fillRect(z,B+.65*Yt,Bt-t,.35*Yt-t))}}}if(h.ctx.globalAlpha=1,p){const t=p.finish();t&&h.ctx.drawImage(t,0,0)}(I.color.amount||I.lights.length)&&(he(d.canvas,bt,Tt),d.ctx.clearRect(0,0,bt,Tt),d.ctx.drawImage(h.canvas,0,0)),I.color.amount&&(h.ctx.save(),h.ctx.globalCompositeOperation=I.color.blend,h.ctx.globalAlpha=I.color.amount,h.ctx.fillStyle=I.color.tint,h.ctx.fillRect(0,0,bt,Tt),h.ctx.restore());for(const t of I.lights){const e=t.radius*Math.max(bt,Tt),i=h.ctx.createRadialGradient(t.x*bt,t.y*Tt,0,t.x*bt,t.y*Tt,e);i.addColorStop(0,t.color),i.addColorStop(1,"transparent"),h.ctx.save(),h.ctx.globalCompositeOperation="screen",h.ctx.globalAlpha=t.intensity,h.ctx.fillStyle=i,h.ctx.fillRect(0,0,bt,Tt),h.ctx.restore()}(I.color.amount||I.lights.length)&&(h.ctx.globalCompositeOperation="destination-in",h.ctx.drawImage(d.canvas,0,0),h.ctx.globalCompositeOperation="source-over"),I.mask.enabled&&I.mask.shapes.length&&(ge(c.ctx,bt,Tt,I.mask.shapes),h.ctx.globalCompositeOperation=I.mask.invert?"destination-out":"destination-in",h.ctx.drawImage(c.canvas,0,0),h.ctx.globalCompositeOperation="source-over");const g=l.ctx;g.clearRect(0,0,bt,Tt),g.globalAlpha=I.backdrop.opacity;const v=I.backdrop;if("solid"===v.mode&&(g.fillStyle=v.color,g.fillRect(0,0,bt,Tt)),"gradient"===v.mode){const t=g.createLinearGradient(0,0,bt,Tt);t.addColorStop(0,v.color),t.addColorStop(1,v.color2),g.fillStyle=t,g.fillRect(0,0,bt,Tt)}if("source"===v.mode&&g.drawImage(n.canvas,0,0),"blurred"===v.mode){const t=Math.max(1,v.blur);he(m.canvas,Math.max(2,Math.round(bt/t)),Math.max(2,Math.round(Tt/t))),m.ctx.drawImage(n.canvas,0,0,m.canvas.width,m.canvas.height),g.imageSmoothingEnabled=!0,g.drawImage(m.canvas,0,0,bt,Tt)}g.globalAlpha=1,I.effects.characterBloom>0&&(he(M.canvas,Math.max(2,Math.round(bt/3)),Math.max(2,Math.round(Tt/3))),M.ctx.clearRect(0,0,M.canvas.width,M.canvas.height),M.ctx.drawImage(h.canvas,0,0,M.canvas.width,M.canvas.height),g.save(),g.globalAlpha=.8*I.effects.characterBloom,g.globalCompositeOperation="screen",g.filter=`blur(${1+4*I.effects.characterBloom}px)`,g.drawImage(M.canvas,0,0,bt,Tt),g.restore());const R=Z.spotlight;if(R&&R[2]>.002){he(at.canvas,bt,Tt);const t=at.ctx,e=R[3]*Math.min(bt,Tt)*1.6;t.globalCompositeOperation="source-over",t.clearRect(0,0,bt,Tt),t.drawImage(n.canvas,0,0),t.globalCompositeOperation="destination-in";const i=t.createRadialGradient(R[0]*bt,R[1]*Tt,0,R[0]*bt,R[1]*Tt,e),a=Math.min(1,R[2]*I.hover.strength/.55);for(const t of[0,.2,.4,.6,.8,1])i.addColorStop(t,`rgba(0,0,0,${a*Math.exp(-2.4*(1.6*t)**2)*(1-t)})`);t.fillStyle=i,t.fillRect(0,0,bt,Tt),_&&"all"!==(I.hover.scope??"all")&&(t.imageSmoothingEnabled=!0,t.drawImage(it.canvas,0,0,bt,Tt)),t.globalCompositeOperation="source-over",g.drawImage(at.canvas,0,0)}g.drawImage(h.canvas,0,0),L=Vt?Kt:""}var Zt;const _t=Object.entries(I.effects).some(([t,e])=>!["angle","focus","blurType","characterBloom"].includes(t)&&"number"==typeof e&&e>0);r.clearRect(0,0,bt,Tt),_t?(void 0===v&&(v=function(t=()=>document.createElement("canvas")){const e=t(),i=e.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,antialias:!1,preserveDrawingBuffer:!0});if(!i)return null;const a=[],s=(t,e)=>{const s=i.createShader(t);if(a.push(s),i.shaderSource(s,e),i.compileShader(s),!i.getShaderParameter(s,i.COMPILE_STATUS))throw new Error(i.getShaderInfoLog(s)||"Finish shader failed");return s},r=i.createProgram();if(i.attachShader(r,s(i.VERTEX_SHADER,"attribute vec2 p;varying vec2 uv;void main(){uv=(p+1.)*.5;gl_Position=vec4(p,0.,1.);}")),i.attachShader(r,s(i.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);}")),i.linkProgram(r),!i.getProgramParameter(r,i.LINK_STATUS))throw new Error("Finish link failed");i.useProgram(r);const n=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,n),i.bufferData(i.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),i.STATIC_DRAW);const o=i.getAttribLocation(r,"p");i.enableVertexAttribArray(o),i.vertexAttribPointer(o,2,i.FLOAT,!1,0,0);const h=i.createTexture();i.bindTexture(i.TEXTURE_2D,h),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE);const l=["t","bloom","grain","dust","scanlines","crt","prism","rgbSplit","sharpen","vignette","glitch","pixelate","blur","blurMode","angle","focus","halftone"],c=Object.fromEntries(l.map(t=>[t,i.getUniformLocation(r,t)])),m=i.getUniformLocation(r,"size");return{canvas:e,render(t,a,s,n=1){e.width===t.width&&e.height===t.height||(e.width=t.width,e.height=t.height,i.viewport(0,0,e.width,e.height)),i.useProgram(r),i.bindTexture(i.TEXTURE_2D,h),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t),i.uniform2f(m,e.width/n,e.height/n);for(const t of l)i.uniform1f(c[t],"t"===t?s:"blurMode"===t?["gaussian","directional","radial","progressive"].indexOf(a.blurType):"angle"===t?a.angle*Math.PI/180:a[t]??0);return i.drawArrays(i.TRIANGLE_STRIP,0,4),e},destroy(){i.deleteTexture(h),i.deleteBuffer(n),i.deleteProgram(r),a.forEach(t=>i.deleteShader(t)),e.width=e.height=1,i.getExtension("WEBGL_lose_context")?.loseContext()}}}(a.finishCanvas)),v?r.drawImage(v.render(l.canvas,I.effects,i,Rt),0,0):r.drawImage(l.canvas,0,0),a.finished(v?"gpu":"unavailable")):(r.drawImage(l.canvas,0,0),a.finished("none"))}const Nt={canvas:t,render:Pt,setPixelRatio(t){Rt=Math.max(.1,Math.min(8,Number.isFinite(t)?t:1))},get pixelRatio(){return Rt},setBudget(t){At=Math.max(256,Math.min(bt,Number.isFinite(t)?Math.round(t):bt))},get maxCells(){return At},configure(t){I=tt(t),ft=ht(I.color),dt=Mt(I.print),pt.configure(I.color.denoise),gt.configure(I.warps,I.warpEdge),N++},pointer:Tt,leave(){Z.leave()},get active(){return Z.active},get settings(){return tt(I)},get capabilities(){return{gpuFinish:null!==v}},invalidate(){U=""},destroy(){v?.destroy(),y?.destroy(),y=void 0,gt.clear(),pt.configure(0);for(const t of[n,o,h,l,c,m,u,d,M,x,et,it,at])t.canvas.width=t.canvas.height=1;J=null,q=new Uint8ClampedArray(0),B=new Uint8ClampedArray(0),j=null,G=""}};return Me.set(Nt,Ct),Nt}(t,e,i,(t=>({surface:oe,media:t=>"currentTime"in t?{video:!0,time:t.getVideoPlaybackQuality?.().totalVideoFrames??t.currentTime,key:t}:{video:!1,time:0,key:t},finished(e){t.dataset.studioFinish=e}}))(t))}function we(t,e,i){return new Promise((a,s)=>{const r=()=>{l(),a()},n=()=>{l(),s(new Error("Unable to load this media. Check its format and cross-origin permissions."))},o=()=>{l(),s(new DOMException("Cancelled","AbortError"))},h=setTimeout(n,2e4),l=()=>{clearTimeout(h),t.removeEventListener(e,r),t.removeEventListener("error",n),i?.removeEventListener("abort",o)};t.addEventListener(e,r,{once:!0}),t.addEventListener("error",n,{once:!0}),i?.addEventListener("abort",o,{once:!0}),i?.aborted&&o()})}async function ke(t,e){if("string"==typeof t&&t.startsWith("blob:")){const i=await fetch(t,{signal:e}),a=await i.blob();return ke(new File([a],"Imported media",{type:a.type}),e)}const i="string"!=typeof t,a=i?t.name:t;if(i?"image/gif"===t.type:/\.gif(?:[?#]|$)/i.test(a)){const a=await import("gifuct-js"),{parseGIF:s,decompressFrames:r}="function"==typeof a.parseGIF?a:a.default,n=i?await t.arrayBuffer():await fetch(t,{signal:e}).then(t=>{if(!t.ok)throw new Error("GIF download failed.");return t.arrayBuffer()});if(e?.aborted)throw new DOMException("Cancelled","AbortError");const o=s(n),h=o.lsd.width,l=o.lsd.height;if(h*l>4e6)throw new Error("GIF is too large. Use a smaller GIF or an MP4.");const c=o.frames.filter(t=>"image"in t).length;if(!c||c*h*l*4>128e6)throw new Error("GIF exceeds the decoded memory budget. Use MP4 for long animations.");const m=r(o,!0);if(m.length*h*l*4>128e6)throw new Error("GIF exceeds the 128 MB decoded budget. Use MP4 for long animations.");const u=document.createElement("canvas");u.width=h,u.height=l;const f=u.getContext("2d"),d=document.createElement("canvas"),p=d.getContext("2d"),g=m.reduce((t,e)=>t+Math.max(20,e.delay),0)/1e3;let M=-1,x=null;const v=t=>{const e=(t%g+g)%g*1e3;let i=0,a=0;for(;a<m.length-1&&(i+=Math.max(20,m[a].delay),!(e<i));a++);a<M&&(f.clearRect(0,0,h,l),M=-1,x=null);for(let t=M+1;t<=a;t++){const e=m[t-1];2===e?.disposalType&&f.clearRect(e.dims.left,e.dims.top,e.dims.width,e.dims.height),3===e?.disposalType&&x&&f.putImageData(x,0,0);const i=m[t];x=3===i.disposalType?f.getImageData(0,0,h,l):null,d.width=i.dims.width,d.height=i.dims.height,p.putImageData(new ImageData(new Uint8ClampedArray(i.patch),d.width,d.height),0,0),f.drawImage(d,i.dims.left,i.dims.top)}return M=a,u};return v(0),{source:u,width:h,height:l,duration:g,animated:!0,seek:async()=>{},frame:v,destroy(){u.width=d.width=1,m.length=0,x=null}}}const s=i?t.type.startsWith("video/"):/\.(mp4|webm|mov)(?:[?#]|$)/i.test(a),r=i?URL.createObjectURL(t):t,n=s?document.createElement("video"):new Image;n.crossOrigin="anonymous",n instanceof HTMLVideoElement&&(n.muted=!0,n.playsInline=!0,n.preload="auto");const o=()=>{n instanceof HTMLVideoElement?(n.pause(),n.removeAttribute("src"),n.load()):n.src="",i&&URL.revokeObjectURL(r)};try{const t=we(n,s?"loadeddata":"load",e);n.src=r,await t;const i=n instanceof HTMLVideoElement?n.videoWidth:n.naturalWidth,a=n instanceof HTMLVideoElement?n.videoHeight:n.naturalHeight;return{source:n,width:i,height:a,duration:n instanceof HTMLVideoElement?n.duration:0,animated:s,async seek(t,e){if(!(n instanceof HTMLVideoElement))return;if(!Number.isFinite(n.duration)||n.duration<=0)throw new Error("Video duration is unavailable.");const i=Math.max(0,Math.min(n.duration-.001,t%n.duration));if(Math.abs(n.currentTime-i)<.001&&n.readyState>=2)return;const a=we(n,"seeked",e);n.currentTime=i,await a},frame:()=>n,destroy:o}}catch(t){throw o(),t}}var Ae=t=>{if(t?.aborted)throw new DOMException("Export cancelled","AbortError")};async function Se(t,e){const{format:i,signal:a}=e,s=Math.round(e.width),r=Math.round(e.height);if(!Number.isFinite(s)||!Number.isFinite(r)||s<2||r<2||s>4096||r>4096||s*r>16777216)throw new Error("Choose export dimensions between 2 and 4096 pixels.");if(!["png","jpeg","mp4","webm","gif"].includes(i))throw new Error("Unknown export format.");if(void 0!==e.fps&&!Number.isFinite(e.fps))throw new Error("Frames per second must be finite.");const n=Math.max(1,Math.min(60,Math.round(e.fps??24))),o=e.duration??5;if(!Number.isFinite(o)||o<=0||o>60)throw new Error("Choose a duration from 0 to 60 seconds.");const h="png"===i||"jpeg"===i,l=e.time??0;if(!Number.isFinite(l)||l<0)throw new Error("Image time must be a finite non-negative number.");if(void 0!==e.motionTime&&(!Number.isFinite(e.motionTime)||e.motionTime<0))throw new Error("Motion time must be a finite non-negative number.");if(!h&&s*r>8294400)throw new Error("Video exports support up to 3840 × 2160 pixels.");if("gif"===i&&(s*r>921600||o*n>600))throw new Error("GIF export supports up to 1280 × 720 and 600 frames. Use MP4 for larger exports.");if(void 0!==e.referenceWidth&&(!Number.isFinite(e.referenceWidth)||e.referenceWidth<1))throw new Error("Reference width must be a positive number.");if("gif"===i&&n>30)throw new Error("GIF exports support up to 30 fps. Choose MP4 or WebM for higher frame rates.");const c=document.createElement("canvas");let m;try{if(Ae(a),e.onProgress?.(0),h){if(await t(c,l,s,r,a,e.motionTime),"unavailable"===c.dataset.studioFinish)throw new Error("Optical effects need WebGL. Disable these effects or export in a supported browser.");Ae(a);const n=await new Promise((t,a)=>c.toBlob(e=>e?t(e):a(new Error("Image export failed.")),"png"===i?"image/png":"image/jpeg",e.quality??.92));return Ae(a),e.onProgress?.(1),n}const u=Math.ceil(o*n);if("gif"===i){const i=await import("gifenc"),{GIFEncoder:h,quantize:l,applyPalette:m}="function"==typeof i.GIFEncoder?i:i.default,f=h(),d=c.getContext("2d");for(let i=0;i<u;i++){Ae(a);const h=i/n;if(await t(c,h,s,r,a),Ae(a),"unavailable"===c.dataset.studioFinish)throw new Error("Optical effects need WebGL. Disable these effects or export in a supported browser.");const p=d.getImageData(0,0,s,r).data,g=l(p,256),M=m(p,g);f.writeFrame(M,s,r,{palette:g,delay:10*(Math.round(100*Math.min((i+1)/n,o))-Math.round(100*i/n)),repeat:0}),e.onProgress?.((i+1)/u*.98),await new Promise(t=>setTimeout(t,0))}return Ae(a),f.finish(),e.onProgress?.(1),new Blob([new Uint8Array(f.bytes())],{type:"image/gif"})}const{Output:f,Mp4OutputFormat:d,WebMOutputFormat:p,BufferTarget:g,CanvasSource:M,canEncodeVideo:x}=await import("mediabunny"),v="mp4"===i?"avc":"vp9";if(!await x(v,{width:s,height:r}))throw new Error(`${i.toUpperCase()} encoding is unavailable in this browser. Try another format or a current browser with WebCodecs.`);const y=new f({format:"mp4"===i?new d({fastStart:"in-memory"}):new p,target:new g});c.width=s,c.height=r,m=()=>y.cancel();const b=new M(c,{codec:v,bitrate:Math.max(5e5,Math.round(s*r*n*.15))});y.addVideoTrack(b,{frameRate:n}),c.width=s,c.height=r,await y.start();for(let i=0;i<u;i++){Ae(a);const h=i/n;if(await t(c,h,s,r,a),Ae(a),"unavailable"===c.dataset.studioFinish)throw new Error("Optical effects need WebGL. Disable these effects or export in a supported browser.");await b.add(h,Math.min(1/n,o-h)),e.onProgress?.((i+1)/u*.98),i%4==0&&await new Promise(t=>setTimeout(t,0))}return b.close(),Ae(a),await y.finalize(),Ae(a),m=void 0,e.onProgress?.(1),new Blob([y.target.buffer],{type:"mp4"===i?"video/mp4":"video/webm"})}catch(t){throw await(m?.().catch(()=>{})),t}finally{c.width=c.height=1}}var Fe=class{constructor(){this.stride=1,this.period=1/0,this.last=0,this.short=0,this.shortCount=0,this.lateRun=0,this.grace=0,this.probeAt=0,this.delay=500,this.probing=-1}tick(t,e,i){const a=this.last?t-this.last:0;if(this.last=t,a<3||a>100)return this.lateRun=0,this.stride;if(this.short+=a,8===++this.shortCount&&(this.period=Math.min(this.period,this.short/8),this.short=this.shortCount=0),!Number.isFinite(this.period))return this.stride;const s=e||a>1.25*this.period;return this.grace>0?(this.grace--,this.lateRun=0):this.lateRun=s?this.lateRun+1:0,this.probing>=0&&t-this.probing>=500&&(this.probing=-1,this.delay=500),this.lateRun>=8&&i>.4*this.period&&this.stride<4?(this.probing>=0&&(this.delay=Math.min(1e3,2*this.delay)),this.probing=-1,this.stride++,this.lateRun=0,this.grace=8,this.probeAt=t+this.delay):this.stride>1&&t>=this.probeAt&&(this.stride=1,this.lateRun=0,this.grace=8,this.probing=t,this.probeAt=t+this.delay),this.stride}reset(){this.stride=1,this.lateRun=this.grace=0,this.delay=500,this.probing=-1,this.last=0}},Ee=null,Re=()=>Ee??(Ee=Promise.resolve().then(()=>(n(),r)).then(({default:t})=>t?URL.createObjectURL(new Blob([t],{type:"text/javascript"})):null,()=>null)),Te=null;function Pe(){if(null!==Te)return Te;try{Te="function"==typeof Worker&&"function"==typeof OffscreenCanvas&&"function"==typeof createImageBitmap&&"transferToImageBitmap"in OffscreenCanvas.prototype&&!!new OffscreenCanvas(1,1).getContext("2d")}catch{Te=!1}return Te}var Ce=new WeakSet;function Ie(t,e,i,a,s={width:960,height:540}){let r=null;const n=xe(i.maxDimension),[o,h]=ve(n,Math.max(2,s.width),Math.max(2,s.height)),l=navigator.hardwareConcurrency??2,c=t=>Math.max(1,Math.min(l>=8?3:l>=4?2:1,Math.floor(6e6/t))),m=c(o*h);let u=o*h;const f=[],d=[];let p=m>Math.min(2,m)?[]:null;const g=Math.max(256,Math.min(1048576,Number.isFinite(i.maxCells)?i.maxCells:12e3));let M=g,x=Math.max(.1,Math.min(8,i.pixelRatio??1));const v=()=>2*f.length;let y,b=!1,w=!1,k=0,A=null,S=!1,F=!1,E="none",R=JSON.stringify(tt(e).crop),T=null,P=null,C="",I=!0,D=new WeakMap,N=0,U=[],O=null;const L=t=>{if(!b){for(const e of f)e.post(t);if(p?.push({message:t}),p&&p.length>4096){for(const{spares:t}of p)t?.forEach(t=>t.close());p=null}}},q=t=>{w?a.error(new Error(t)):(G(),a.unavailable())};let X=[];const z=()=>{let t=!1;for(;U.length&&void 0!==U[0].reply;){const e=U.shift();e.reply&&(X.push(e),t=!0)}for(;X.length>2;)X.shift().reply.bitmap.close();t&&a.ready()},B=t=>{const e=t.worker=new Worker(r);e.onmessage=t=>{const e=t.data;if(b)return void("frame"===e.type&&e.bitmap.close());if("ready"===e.type)return;"error"===e.type&&q(e.message);const i=U.find(t=>t.seq===e.seq);i?(i.reply="frame"===e.type?e:null,"frame"===e.type&&p&&d.push(e.cost)>=3&&function(t){const e=p;p=null;const i=Math.min(m,c(u),Math.max(f.length,Math.ceil(t/7)))-f.length;for(let t=0;t<i;t++){const i=Y();i.post(j);for(const{message:a,spares:s}of e)if("source"===a.type){const e=s[t];i.post({...a,scene:e},[e])}else i.post("render"===a.type?{...a,type:"advance"}:a)}for(const{spares:t}of e)t?.slice(Math.max(0,i)).forEach(t=>t.close())}(d.sort((t,e)=>t-e)[1]),z()):"frame"===e.type&&e.bitmap.close()},e.onerror=t=>{t.preventDefault?.(),q(t.message||"The Studio worker failed.")};for(const[i,a]of t.waiting)e.postMessage(i,a);t.waiting=[]},Y=()=>{const t={worker:null,waiting:[],post(e,i=[]){t.worker?t.worker.postMessage(e,i):t.waiting.push([e,i])}};return f.push(t),r&&B(t),t},j={type:"init",settings:e,limits:{maxDimension:i.maxDimension,maxCells:i.maxCells},pixelRatio:x,budget:M};for(let t=Math.min(2,m);t>0;t--)Y().post(j);Re().then(t=>{b||(t?(r=t,f.forEach(B)):q("The Studio worker could not load."))});function G(){if(!b){b=!0;for(const t of f)t.worker?.terminate();for(const{spares:t}of p??[])t?.forEach(t=>t.close());for(const t of f)for(const[,e]of t.waiting)for(const t of e)t.close?.();p=null;for(const t of[...U,...X])t.reply?.bitmap.close();U=[],X=[],T&&(T.width=T.height=1),T=P=null,D=new WeakMap}}return{get turns(){return f.length},get busy(){return U.length>=v()},get drawing(){return U.length>0||X.length>0},show:()=>{const e=X.shift();return!!e?.reply&&(S=e.reply.active||X.some(t=>t.reply.active),E=e.reply.finish,i=e.reply.bitmap,t.width!==i.width&&(t.width=i.width),t.height!==i.height&&(t.height=i.height),void 0===y&&(y=t.getContext("bitmaprenderer"),y||(O=t.getContext("2d"))),y?y.transferFromImageBitmap(i):(O?.clearRect(0,0,t.width,t.height),O?.drawImage(i,0,0),i.close()),t.dataset.studioFinish=E,w=!0,a.frame(e.time,e.reply.cost),!0);var i},render(t,e,i,a,s,r){if(b||U.length>=v())return!1;const[o,h]=ne(t);if(!o||!h)return!1;const[l,d]=ve(n,i,a);for(u=l*d;f.length>c(u);){const t=f.pop();t.worker?.terminate();for(const[,e]of t.waiting)for(const t of e)t.close?.();for(const e of U)e.lane===t&&void 0===e.reply&&(e.reply=null);z()}const g=++k,M=f[g%f.length];U.push({seq:g,time:e,input:F,lane:M}),F=!1;const x=(t=>{let e=D.get(t);return void 0===e&&D.set(t,e=++N),e})(t),y=()=>{if(!b){for(const t of f)t.post({type:t===M?"render":"advance",seq:g,time:e,width:i,height:a,motionTime:s});p?.push({message:{type:"advance",seq:g,time:e,width:i,height:a,motionTime:s}})}},w=[x,r.video?r.time:0,l,d,R].join(":");if(!I&&w===C)return A?A.then(y):y(),!0;I=!1,C=w;const S=()=>{if(b)throw new DOMException("Cancelled","AbortError");return T||(T=document.createElement("canvas"),P=T.getContext("2d")),T.width!==l&&(T.width=l),T.height!==d&&(T.height=d),ye(P,t,l,d,JSON.parse(R)),Promise.all(Array.from({length:f.length+(p?m-f.length:0)},()=>createImageBitmap(T)))},E=t instanceof HTMLImageElement&&!Ce.has(t)?t.decode().catch(()=>{}).then(()=>{Ce.add(t)}):null,O=(A??Promise.resolve()).then(()=>E?E.then(S):S()).then(t=>{if(b){for(const e of t)e.close();return}const e={type:"source",scene:t[0],width:o,height:h,video:r.video,time:r.time,key:x};f.forEach((i,a)=>i.post({...e,scene:t[a]},[t[a]])),p?p.push({message:e,spares:t.slice(f.length)}):t.slice(f.length).forEach(t=>t.close()),y()},t=>{const e=U.find(t=>t.seq===g);e&&(e.reply=null,z()),I=!0,b||q(t instanceof Error?t.message:String(t))});return A=O,O.then(()=>{A===O&&(A=null)}),!0},pointer(t,e,i){F=!0,L({type:"pointer",x:t,y:e,time:i})},leave(){F=!0,L({type:"leave"})},configure(t){R=JSON.stringify(tt(t).crop),L({type:"configure",settings:t})},setBudget(t){M=Math.max(256,Math.min(g,Number.isFinite(t)?Math.round(t):g)),L({type:"budget",cells:t})},get maxCells(){return M},setPixelRatio(t){x=Math.max(.1,Math.min(8,Number.isFinite(t)?t:1)),L({type:"ratio",ratio:t})},get pixelRatio(){return x},get active(){return S||F||U.some(t=>t.input)||X.some(t=>t.input||t.reply.active)},get capabilities(){return{gpuFinish:"unavailable"!==E}},invalidate(){I=!0,L({type:"invalidate"})},destroy:G}}function De(t,e,i={}){let a,s=tt(i.settings),r=i.width??e.width,n=i.height??e.height,o=null;const h=()=>be(t,s,i);if(Pe())try{a=o=Ie(t,s,i,{frame:function(t,r){if(m)return;i.onFrame?.(t,r),q(r/(o?.turns??1),D()&&(e.animated||bt(s))),y=a.active,b||y||u||o?.drawing?I():T()&&(u=!0,I())},ready:()=>I(),unavailable(){const t=a.maxCells,e=a.pixelRatio;o=null,a=h(),a.setBudget(t),a.setPixelRatio(e),u=!0,I()},error:X},{width:r,height:n})}catch{o=null,a=h()}else a=h();const l=new k;let c=0,m=!1,u=!0,f=!1,d=!0,p=0,g=0,M=0,x=0,v=-1,y=!1,b=!1,w=!1!==i.adaptive,A=0,S=0,F=0,E=0,R=a.maxCells;const T=()=>!(a.maxCells>=R)&&(a.setBudget(R),i.onQualityChange?.(a.maxCells),F=E=S=A=0,!0),P=matchMedia("(prefers-reduced-motion: reduce)"),C=e.source instanceof HTMLVideoElement?e.source:null,I=()=>{m||c||!d||document.hidden||(c=requestAnimationFrame(U))},D=()=>!f&&!P.matches&&d&&!document.hidden,N=()=>{C&&(C.loop=!0,D()?C.play().catch(()=>{f=!0,u=!0,I()}):C.pause()),M=0,u=!0,I()};function U(t){if(c=0,m||!d||document.hidden)return;const h=o?.show()??!1;h&&o.drawing&&I();const f=D();f&&(p+=M?Math.min(.1,(t-M)/1e3):0),M=t;const w=bt(s),k=f&&(e.animated||w),A=C?.getVideoPlaybackQuality?.().totalVideoFrames??-1,F=!C||A<0||A!==v,E=1e3/Math.max(1,Math.min(60,i.fps??60))-.5,R=u||(a.active?o||t-x>=Math.max(E,2*S):y)||k&&(F||w)&&t-x>=E;if(o&&(O.tick(t,a.active&&1===O.stride&&!h&&o.drawing,S),L++),R&&o&&!u&&L%O.stride)b=!0;else if(R&&o)if(o.busy)b=!0;else{e.animated&&!C&&o.invalidate();const[i,a]=it(r,n,s);g=l.update(p,s.motion.type,s.motion.speed);const h=C?.currentTime??p;(o.render(e.frame(h),h,i,a,g,{video:!!C,time:A})||u)&&(u=!1,x=t,b=!1,v=A)}else if(R){const o=performance.now();try{e.animated&&!C&&a.invalidate();const[t,h]=it(r,n,s);g=l.update(p,s.motion.type,s.motion.speed),a.render(e.frame(C?.currentTime??p),p,t,h,g);const c=performance.now()-o;i.onFrame?.(C?.currentTime??p,c),q(c,k)}catch(t){X(t)}u=!1,x=t,y=a.active,v=A}f&&(k||a.active||b)?I():k||a.active||o?.drawing||!T()||(u=!0,I())}const O=new Fe;let L=0;function q(t,e){if(S=S?.9*S+.1*t:t,++A>20&&w&&(e||a.active)){const t=1e3/Math.max(1,Math.min(60,i.fps??60));F=S>1.1*t?F+1:0,E=S<.5*t?E+1:0,F>=20&&a.maxCells>3e3?(a.setBudget(Math.max(3e3,.8*a.maxCells)),i.onQualityChange?.(a.maxCells),F=0,S=0):E>=30&&a.maxCells<R&&(a.setBudget(Math.min(R,1.25*a.maxCells)),i.onQualityChange?.(a.maxCells),E=0,S=0)}}function X(t){f=!0,i.onError?.(t instanceof Error?t:new Error(String(t)))}const z=e=>{if(!D())return;a.active||O.reset();const i=t.getBoundingClientRect();a.pointer((e.clientX-i.left)/i.width,(e.clientY-i.top)/i.height,e.timeStamp),I()},B=()=>{a.leave(),I()},Y=t=>{"touch"===t.pointerType&&B()},j=new IntersectionObserver(([t])=>{d=t.isIntersecting,N()});j.observe(t),t.addEventListener("pointermove",z),t.addEventListener("pointerup",Y),t.addEventListener("pointerleave",B),t.addEventListener("pointercancel",B),document.addEventListener("visibilitychange",N),P.addEventListener("change",N);const G=()=>{m||(m=!0,cancelAnimationFrame(c),j.disconnect(),t.removeEventListener("pointermove",z),t.removeEventListener("pointerup",Y),t.removeEventListener("pointerleave",B),t.removeEventListener("pointercancel",B),document.removeEventListener("visibilitychange",N),P.removeEventListener("change",N),i.signal?.removeEventListener("abort",G),a.destroy(),e.destroy())};if(i.signal?.addEventListener("abort",G,{once:!0}),i.signal?.aborted)throw G(),new DOMException("Cancelled","AbortError");return N(),{canvas:t,media:e,update(t){s=at(s,t),a.configure(s),u=!0,I()},resize(t,e,i){void 0!==i&&a.setPixelRatio(i),r=Math.max(2,t),n=Math.max(2,e),u=!0,I()},pause(t=!0){f=t,N()},async seek(t){p=Math.max(0,t),await e.seek(p),a.invalidate(),u=!0,I()},redraw(){a.invalidate(),u=!0,I()},get time(){return C?.currentTime??p},get settings(){return tt(s)},get motionTime(){return g},get paused(){return f||P.matches},setAdaptive(t){w=t,A=F=S=0},setBudget(t){a.setBudget(t),R=a.maxCells,F=E=S=A=0,i.onQualityChange?.(a.maxCells),u=!0,I()},get pixelRatio(){return a.pixelRatio},get maxCells(){return a.maxCells},get capabilities(){return a.capabilities},destroy:G}}var Ne={Standard:()=>import("figlet/fonts/Standard"),Slant:()=>import("figlet/fonts/Slant"),Small:()=>import("figlet/fonts/Small"),Big:()=>import("figlet/fonts/Big"),Banner:()=>import("figlet/fonts/Banner"),Block:()=>import("figlet/fonts/Block"),Bubble:()=>import("figlet/fonts/Bubble"),Digital:()=>import("figlet/fonts/Digital"),Doom:()=>import("figlet/fonts/Doom"),Lean:()=>import("figlet/fonts/Lean"),Mini:()=>import("figlet/fonts/Mini"),Script:()=>import("figlet/fonts/Script"),Shadow:()=>import("figlet/fonts/Shadow"),Speed:()=>import("figlet/fonts/Speed"),Starwars:()=>import("figlet/fonts/Star Wars"),Stop:()=>import("figlet/fonts/Stop"),Straight:()=>import("figlet/fonts/Straight"),Thin:()=>import("figlet/fonts/Thin"),ThreeD:()=>import("figlet/fonts/3-D"),Univers:()=>import("figlet/fonts/Univers"),Wavy:()=>import("figlet/fonts/Wavy")},Ue=Object.keys(Ne);async function Oe(t,e="Standard",i="#ffffff",a="#080808"){if(!Object.prototype.hasOwnProperty.call(Ne,e))throw new Error("Unknown text font.");const{default:s}=await import("figlet/browser"),r=await Ne[e]();s.parseFont(e,r.default),s.defaults({fetchFontIfMissing:!1});const n=s.textSync(t.slice(0,120),{font:e}),o=n.split("\n"),h=Math.max(1,...o.map(t=>t.length)),l=Math.max(1,o.length),c=Math.min(1,2048/(9*h)),m=document.createElement("canvas");m.width=Math.ceil(9*h*c+32),m.height=Math.ceil(15*l*c+32);const u=m.getContext("2d");return null!==a&&(u.fillStyle=a,u.fillRect(0,0,m.width,m.height)),u.fillStyle=i,u.font=15*c+"px monospace",u.textBaseline="top",o.forEach((t,e)=>u.fillText(t,16,16+15*e*c)),{canvas:m,ascii:n}}var Le={standard:{label:"Classic ASCII",chars:" .:-=+*#%@"},asciify:{label:"Asciify",chars:" .:-=+YCIFSA#@"},minimal:{label:"Minimal",chars:" .:+"},detailed:{label:"Detailed",chars:" .,:;-~=+*xX#%@"},letters:{label:"Letters",chars:" .liLTYCFSAWM"},technical:{label:"Technical",chars:" ._:;+/>=][{}*$#@"},blocks:{label:"Tonal blocks",chars:" ░▒▓█"},braille:{label:"Braille",chars:" ⠁⠃⠇⡇⣇⣧⣷⣿"}},qe=Le,Xe=t=>t&&"object"==typeof t&&!Array.isArray(t)?t:{},ze=(t,e,i,a)=>"number"==typeof t&&Number.isFinite(t)?Math.max(i,Math.min(a,t)):e,Be=(t,e)=>{if("string"!=typeof t||!/^[a-zA-Z0-9][a-zA-Z0-9:_-]{0,63}$/.test(t))throw new Error(`${e} must be 1–64 letters, numbers, colons, dashes or underscores, starting with a letter or number.`);return t};function Ye(t={}){const e=Xe(t);if(void 0!==e.kind&&"asciify-project"!==e.kind||void 0!==e.version&&1!==e.version)throw new Error("Unsupported Studio project. Update asciify-engine.");if(void 0!==e.layers&&!Array.isArray(e.layers))throw new Error("Project layers must be an array.");const i=Array.isArray(e.layers)?e.layers:[];if(i.length>8)throw new Error("A project supports up to 8 layers.");const a=new Set;return{kind:"asciify-project",version:1,width:Math.round(ze(e.width,1280,2,4096)),height:Math.round(ze(e.height,720,2,4096)),background:null===e.background?null:"string"==typeof e.background&&/^#[a-f\d]{6}$/i.test(e.background)?e.background:"#0c1711",pointerMode:"all"===e.pointerMode?"all":"top",layers:i.map((t,e)=>{const i=Xe(t),s=Xe(i.placement),r=Xe(i.settings),n=Xe(r.backdrop),o=Be(i.id,"Layer id"),h=Be(i.source,"Source key");if(a.has(o))throw new Error(`Duplicate layer id: ${o}`);return a.add(o),{id:o,source:h,name:"string"==typeof i.name?i.name.slice(0,80):`Layer ${e+1}`,visible:!1!==i.visible,opacity:ze(i.opacity,1,0,1),blend:V.includes(i.blend)?i.blend:"source-over",placement:{x:ze(s.x,.5,-1,2),y:ze(s.y,.5,-1,2),width:ze(s.width,1,.01,2),height:ze(s.height,1,.01,2),rotation:ze(s.rotation,0,-180,180),flipX:!0===s.flipX,flipY:!0===s.flipY},settings:tt({...r,backdrop:{mode:"transparent",...n}})}})}}function je(t,e,i){if(!t.layers.some(t=>t.id===e))throw new Error(`Unknown layer: ${e}`);return Ye({...t,layers:t.layers.map(t=>t.id!==e?t:{...t,...i,id:e,placement:{...t.placement,...i.placement},settings:at(t.settings,i.settings??{})})})}function Ge(t,e,i,a,s){const r=t.placement,n=r.rotation*Math.PI/180,o=Math.cos(n),h=Math.sin(n),l=(e-r.x)*a,c=(i-r.y)*s,m=(l*o+c*h)/(r.width*a),u=(-l*h+c*o)/(r.height*s);return[.5+m*(r.flipX?-1:1),.5+u*(r.flipY?-1:1)]}function He(t){return t.layers.filter(e=>{if(!e.visible||e.opacity<=0)return!1;const i=e.placement,a=i.rotation*Math.PI/180,s=Math.abs(Math.cos(a)),r=Math.abs(Math.sin(a)),n=(s*i.width*t.width+r*i.height*t.height)/2,o=(r*i.width*t.width+s*i.height*t.height)/2;return i.x*t.width+n>0&&i.x*t.width-n<t.width&&i.y*t.height+o>0&&i.y*t.height-o<t.height})}function We(t,e=24e3,i=4194304,a=t.width,s=t.height){const r=He(t),n=Math.round(ze(e,24e3,2048,1048576)),o=ze(i,4194304,65536,16777216),h=r.map(t=>t.placement.width*t.placement.height),l=h.reduce((t,e)=>t+e,0),c=n-256*r.length,m=r.map(t=>{const e=a*t.placement.width,i=s*t.placement.height,r=Math.min(1,4096/Math.max(e,i));return{width:Math.max(2,e*r),height:Math.max(2,i*r)}}),u=m.reduce((t,e)=>t+e.width*e.height,0);let f=0,d=0;return r.map((t,e)=>{const i=e===r.length-1?n-f:256+Math.floor(c*h[e]/l);f+=i;const a=m[e],s=e===r.length-1?o-d:4+Math.floor((o-4*r.length)*a.width*a.height/Math.max(1,u));d+=s;const p=Math.min(1,Math.sqrt(s/(a.width*a.height)));let g=Math.max(2,Math.floor(a.width*p)),M=Math.max(2,Math.floor(a.height*p));return g*M>s&&(g>=M?g=Math.max(2,Math.floor(s/M)):M=Math.max(2,Math.floor(s/g))),{id:t.id,maxCells:i,width:g,height:M}})}function Ve(t,e={},i={}){const a=t.getContext("2d");if(!a)throw new Error("Project canvas is already owned by another renderer.");let s=Ye(e),r=!0,n=!1,o=new Map(s.layers.map(t=>[t.id,JSON.stringify(t.settings)]));const h=Math.max(64,Math.min(4096,Number.isFinite(i.maxDimension)?i.maxDimension:960)),l=Math.max(2048,Math.min(1048576,Number.isFinite(i.maxCells)?i.maxCells:24e3));let c=l,m=Math.max(.1,Math.min(8,Number.isFinite(i.pixelRatio)?i.pixelRatio:1)),u=[];const f=new Map,d=()=>{if(n)throw new Error("Project renderer has been destroyed.")};return{canvas:t,render(e,n=0,p=s.width,g=s.height,M={}){if(d(),!Number.isFinite(p)||!Number.isFinite(g)||p<2||g<2)throw new Error("Project dimensions must be positive finite numbers.");const x=Math.min(1,h/Math.max(p,g)),v=Math.max(2,Math.round(p*x)),y=Math.max(2,Math.round(g*x));t.width===v&&t.height===y||(t.width=v,t.height=y,r=!0);const b={...s,width:v,height:y},w=He(b);for(const t of w)if(!e.has(t.source))throw new Error(`Missing project source: ${t.source}`);const k=new Set(w.map(t=>t.id));for(const[t,e]of f)k.has(t)||(e.renderer.destroy(),f.delete(t),r=!0);u=We(b,c,i.maxRasterPixels,v,y);for(let t=0;t<w.length;t++){const i=w[t],a=u[t],s=e.get(i.source);if(!s)throw new Error(`Missing project source: ${i.source}`);let h=f.get(i.id);const c=o.get(i.id);h?h.signature!==c&&(h.renderer.configure(i.settings),h.signature=c,h.dirty=!0):(h={renderer:be(document.createElement("canvas"),i.settings,{maxDimension:4096,maxCells:l}),signature:c,dirty:!0,geometry:""},f.set(i.id,h));const d=m*a.width/(p*i.placement.width),g=`${a.width}:${a.height}:${a.maxCells}:${d}`;h.geometry!==g&&(h.renderer.setBudget(a.maxCells),h.renderer.setPixelRatio(d),h.geometry=g,h.dirty=!0);const x="currentTime"in s?s.getVideoPlaybackQuality?.().totalVideoFrames??s.currentTime:0;if(h.dirty||h.source!==s||h.stamp!==x||h.renderer.active||bt(i.settings)){const t=Object.prototype.hasOwnProperty.call(M,i.id)?M[i.id]:void 0;h.renderer.render(s,n,a.width,a.height,t),h.dirty=!1,h.source=s,h.stamp=x,r=!0}}if(!r)return!1;a.clearRect(0,0,v,y),a.globalCompositeOperation="source-over",a.globalAlpha=1,null!==s.background&&(a.fillStyle=s.background,a.fillRect(0,0,v,y));let A="none";for(const t of w){const e=f.get(t.id),i=t.placement;a.save(),a.globalAlpha=t.opacity,a.globalCompositeOperation=t.blend;try{a.translate(i.x*v,i.y*y),a.rotate(i.rotation*Math.PI/180),a.scale(i.flipX?-1:1,i.flipY?-1:1),a.drawImage(e.renderer.canvas,-i.width*v/2,-i.height*y/2,i.width*v,i.height*y)}finally{a.restore()}"unavailable"===e.renderer.canvas.dataset.studioFinish?A="unavailable":"unavailable"!==A&&"gpu"===e.renderer.canvas.dataset.studioFinish&&(A="gpu")}return a.globalAlpha=1,a.globalCompositeOperation="source-over",t.dataset.studioFinish=A,r=!1,!0},configure(t){d(),s=Ye(t),o=new Map(s.layers.map(t=>[t.id,JSON.stringify(t.settings)])),(()=>{const t=new Set(He(s).map(t=>t.id));for(const[e,i]of f)t.has(e)||(i.renderer.destroy(),f.delete(e))})(),r=!0},pointer(e,i,a){if(n||!Number.isFinite(e)||!Number.isFinite(i))return;if(e<0||e>1||i<0||i>1){for(const t of f.values())t.renderer.leave();return}let r=!1;for(const n of He({...s,width:t.width,height:t.height}).reverse()){const o=f.get(n.id);if(!o)continue;const[h,l]=Ge(n,e,i,t.width,t.height);(!r||"all"===s.pointerMode)&&h>=0&&h<=1&&l>=0&&l<=1&&"none"!==n.settings.hover.effect&&n.settings.hover.strength>0?(o.renderer.pointer(h,l,a),r=!0):o.renderer.leave()}},leave(){for(const t of f.values())t.renderer.leave()},invalidate(t){d();for(const e of s.layers)if(void 0===t||t===e.source){const t=f.get(e.id);t&&(t.renderer.invalidate(),t.dirty=!0)}r=!0},setBudget(t){d(),c=Math.max(2048,Math.min(l,Number.isFinite(t)?Math.round(t):l)),r=!0},setPixelRatio(t){d(),m=Math.max(.1,Math.min(8,Number.isFinite(t)?t:1)),r=!0},get maxCells(){return c},get pixelRatio(){return m},get quality(){return u.map(t=>({...t}))},get active(){return[...f.values()].some(t=>t.renderer.active)},destroy(){if(!n){n=!0;for(const t of f.values())t.renderer.destroy();f.clear(),t.width=t.height=1}}}}function Ke(t,e){for(const i of t.layers)if(!e.has(i.source))throw new Error(`Missing project source: ${i.source}`)}async function Je(t,e,i){const a=Object.entries(e),s=new Map;if(a.length>8)throw new Error("A project supports up to 8 media bindings.");Ke(t,new Map(a));try{for(const[t,e]of a){if(i?.aborted)throw new DOMException("Cancelled","AbortError");if("string"==typeof e||"undefined"!=typeof File&&e instanceof File)s.set(t,await ke(e,i));else{if(!e||"object"!=typeof e||!("text"in e)||"string"!=typeof e.text)throw new Error(`Invalid project source: ${t}`);{const i=e,{canvas:a}=await Oe(i.text,i.font,i.ink??"#ffffff",null);s.set(t,{source:a,width:a.width,height:a.height,duration:0,animated:!1,frame:()=>a,seek:async()=>{},destroy:()=>{a.width=a.height=1}})}}}if(i?.aborted)throw new DOMException("Cancelled","AbortError");return s}catch(t){for(const t of s.values())t.destroy();throw t}}function Qe(t,e,i,a={}){if((i=new Map(i)).size>8)throw new Error("A project supports up to 8 media bindings.");let s=Ye(e);if(Ke(s,i),a.signal?.aborted)throw new DOMException("Cancelled","AbortError");const r=Ve(t,s,a),n=matchMedia("(prefers-reduced-motion: reduce)"),o=[...new Set(i.values())],h=o.filter(t=>t.source instanceof HTMLVideoElement).map(t=>t.source),l=new Map;let c,m={},u=0,f=0,d=0,p=0,g=!0,M=!1,x=!0,v=!1,y=!1!==a.adaptive,b=0,w=0,A=0,S=0,F=s.width,E=s.height,R=0,T=!1,P=r.maxCells;const C=new WeakSet,I=Math.max(1,Math.min(60,Number.isFinite(a.fps)?a.fps:60)),D=()=>!v&&!M&&!T&&!n.matches&&x&&!document.hidden,N=()=>{v||p||!x||document.hidden||(p=requestAnimationFrame(q))},U=()=>new Set(He({...s,width:F,height:E}).map(t=>i.get(t.source).source)),O=()=>{const t=U();for(const e of h)e.loop=!0,D()&&t.has(e)?e.paused&&!C.has(e)&&(C.add(e),e.play().then(()=>{C.delete(e),D()&&U().has(e)||e.pause()}).catch(t=>{C.delete(e),v||(M=!0,O(),a.onError?.(t instanceof Error?t:new Error(String(t))),g=!0,N())})):e.pause()},L=()=>{f=0,g=!0,O(),N()};function q(t){if(p=0,v||!x||document.hidden)return;const e=D();e&&(u+=f?Math.min(.1,(t-f)/1e3):0),f=t;const n=He({...s,width:F,height:E}),o=n.some(t=>i.get(t.source).animated||bt(t.settings));if(g||e&&r.active||e&&o&&t-d>=1e3/I-.5){const s=performance.now();try{const t=new Map,h=new Set(n.map(t=>t.source));for(const a of h){const s=i.get(a);!s.animated||s.source instanceof HTMLVideoElement||!e||r.invalidate(a),t.set(a,s.frame(u))}m={};for(const t of n){let e=l.get(t.id);e||(e=new k,l.set(t.id,e)),m[t.id]=e.update(u,t.settings.motion.type,t.settings.motion.speed)}r.render(t,u,F,E,m);const c=performance.now()-s;if(a.onFrame?.(u,c),w=w?.9*w+.1*c:c,++b>20&&y&&e&&(o||r.active)){const t=1e3/I;A=w>1.1*t?A+1:0,S=w<.5*t?S+1:0,A>=20&&r.maxCells>2048?(r.setBudget(Math.max(2048,.8*r.maxCells)),a.onQualityChange?.(r.maxCells),w=A=0,g=!0):S>=30&&r.maxCells<P&&(r.setBudget(Math.min(P,1.25*r.maxCells)),a.onQualityChange?.(r.maxCells),w=S=0,g=!0)}}catch(t){M=!0,O(),a.onError?.(t instanceof Error?t:new Error(String(t)))}g=!1,d=t}e&&(o||r.active)?N():!o&&!r.active&&r.maxCells<P&&(r.setBudget(P),a.onQualityChange?.(r.maxCells),b=A=S=w=0,g=!0,N())}const X=e=>{if(!D())return;const i=t.getBoundingClientRect();i.width&&i.height&&(r.pointer((e.clientX-i.left)/i.width,(e.clientY-i.top)/i.height,e.timeStamp),N())},z=()=>{r.leave(),N()},B=new IntersectionObserver(([t])=>{x=t.isIntersecting,L()});B.observe(t),t.addEventListener("pointermove",X),t.addEventListener("pointerleave",z),t.addEventListener("pointercancel",z),document.addEventListener("visibilitychange",L),n.addEventListener("change",L);const Y=()=>{if(!v){v=!0,R++,c?.abort(),cancelAnimationFrame(p),p=0,B.disconnect(),t.removeEventListener("pointermove",X),t.removeEventListener("pointerleave",z),t.removeEventListener("pointercancel",z),document.removeEventListener("visibilitychange",L),n.removeEventListener("change",L),a.signal?.removeEventListener("abort",Y),r.destroy();for(const t of o)t.destroy();l.clear()}};a.signal?.addEventListener("abort",Y,{once:!0});const j=()=>{if(v)throw new Error("Project player has been destroyed.")},G=t=>{j();const e=Ye(t);Ke(e,i),F===s.width&&E===s.height&&(F=e.width,E=e.height),s=e,r.configure(s);for(const t of l.keys())s.layers.some(e=>e.id===t)||l.delete(t);L()};return L(),{canvas:t,get project(){return Ye(s)},get time(){return u},get motionTimes(){return{...m}},get paused(){return M||n.matches},get maxCells(){return r.maxCells},get pixelRatio(){return r.pixelRatio},get quality(){return r.quality},update:G,updateLayer:(t,e)=>G(je(s,t,e)),resize(t,e,i){if(j(),!Number.isFinite(t)||!Number.isFinite(e)||t<2||e<2)throw new Error("Project dimensions must be positive finite numbers.");F=t,E=e,void 0!==i&&r.setPixelRatio(i),L()},pause(t=!0){j(),M=t,L()},async seek(t){if(j(),!Number.isFinite(t)||t<0)throw new Error("Project time must be finite and non-negative.");const e=++R;c?.abort(),c=new AbortController;const i=c.signal;T=!0,O();try{if(await Promise.all(o.map(e=>e.seek(t,i))),v||e!==R)return;u=t,l.clear(),r.invalidate()}finally{v||e!==R||(T=!1,L())}},redraw(){j(),r.invalidate(),g=!0,N()},setBudget(t){j(),r.setBudget(t),P=r.maxCells,b=A=S=w=0,a.onQualityChange?.(r.maxCells),g=!0,N()},setAdaptive(t){y=t,b=A=S=w=0},destroy:Y}}exports.BLEND_MODES=V,exports.CHARACTER_SETS=Le,exports.DEFAULT_HOVER=c,exports.DEFAULT_STUDIO_PRINT=j,exports.DEFAULT_STUDIO_SETTINGS=J,exports.DEPRECATED_STUDIO_HOVERS=h,exports.DEPRECATED_STUDIO_MOTIONS=M,exports.DITHER_ALGORITHMS=W,exports.HOVER_CONTROLS=l,exports.HOVER_SCOPES=[{value:"all",label:"Everywhere",description:"The hover acts on the whole artwork."},{value:"subject",label:"Subject",description:"The hover stays on the subject and fades softly at its edge."},{value:"outside",label:"Around",description:"The hover acts only on the ground around the subject."}],exports.MAX_STUDIO_LAYERS=8,exports.MAX_STUDIO_WARPS=8,exports.STUDIO_ANIMATION_PRESETS=[{id:"quiet-light",label:"Quiet light",description:"A key light circles the subject’s own relief, with a soft magnifying wake.",motion:{type:"relight",speed:.6,amount:.8},hover:{effect:"lens",radius:.45,strength:.5}},{id:"living-paper",label:"Memory",description:"A slow push toward the subject; the image leans toward your cursor.",motion:{type:"push",speed:.5,amount:.8},hover:{effect:"tilt",radius:.5,strength:.45}},{id:"silver-grain",label:"Silver light",description:"Sparse glints on bright detail, with a fluid character trail.",motion:{type:"shimmer",speed:.6,amount:.9},hover:{effect:"trail",radius:.35,strength:.55}},{id:"ripple-study",label:"Still water",description:"Smooth water and sky drift like a cinemagraph; your stroke sends out rings.",motion:{type:"current",speed:.6,amount:.8},hover:{effect:"ripple",radius:.45,strength:.7}},{id:"unfolding-print",label:"Darkroom",description:"The print develops from its highlights; your cursor dissolves a soft path.",motion:{type:"develop",speed:.7,amount:1},hover:{effect:"dissolve",radius:.35,strength:.55}},{id:"silk-flow",label:"Morning mist",description:"Mist drifts through the distance; directional folds follow your hand.",motion:{type:"mist",speed:.6,amount:1},hover:{effect:"silk",radius:.4,strength:.5}},{id:"depth-study",label:"Depth study",description:"A slow parallax drift from the photo’s own depth, with a loupe under your cursor.",motion:{type:"parallax",speed:.6,amount:.9},hover:{effect:"loupe",radius:.35,strength:.55}}],exports.STUDIO_CHARACTER_SETS=qe,exports.STUDIO_CURVE_CHANNELS=R,exports.STUDIO_HOVERS=o,exports.STUDIO_LOOKS=rt,exports.STUDIO_MOTIONS=x,exports.STUDIO_PALETTES=K,exports.STUDIO_PRINT_STYLES=[{value:"stipple",label:"Stipple",description:"Scattered ink dots shape the image through their size."},{value:"engraving",label:"Engraving",description:"Continuous parallel cuts change weight with the image."},{value:"crosshatch",label:"Crosshatch",description:"Crossing layers of fine lines build the tonal range."},{value:"woodblock",label:"Woodblock",description:"Broad carved bands with irregular edges and stepped tones."},{value:"risograph",label:"Risograph",description:"Two offset ink screens with adjustable registration."},{value:"pointillism",label:"Pointillism",description:"Small pigment strokes mix source colors into the image."}],exports.STUDIO_PRINT_STYLE_IDS=B,exports.STUDIO_STYLES=H,exports.STUDIO_TEXT_FONTS=Ue,exports.STUDIO_WARPS=U,exports.createStudioCurveLookup=I,exports.createStudioProjectRenderer=Ve,exports.createStudioRenderer=be,exports.createStudioText=Oe,exports.exportStudio=async function(t,e,i){let a;const s=tt(e),r="png"!==i.format&&"jpeg"!==i.format;try{return await Se(async(e,n,o,h,l,c)=>{a??(a=be(e,s,{maxDimension:4096,maxCells:i.maxCells??12e3,pixelRatio:o/(i.referenceWidth??Math.min(o,960))})),r&&a.invalidate(),a.render(await t.frame(n,l),n,o,h,c)},i)}finally{a?.destroy()}},exports.exportStudioProject=async function(t,e,i){const a=Ye(t),s={...i.motionTimes};if(Object.values(s).some(t=>!Number.isFinite(t)||t<0))throw new Error("Layer motion times must be finite non-negative numbers.");const r=Object.fromEntries(Object.entries(e).map(([t,e])=>[t,e&&"object"==typeof e&&"text"in e&&"string"==typeof e.text?{...e}:e]));let n,o;const h=new AbortController,l=()=>h.abort();i.signal?.aborted?l():i.signal?.addEventListener("abort",l,{once:!0});const c="png"===i.format||"jpeg"===i.format;try{return await Se(async(t,e,h,l,m)=>{o??(o=await Je(a,r,m)),n??(n=Ve(t,a,{maxDimension:4096,maxCells:i.maxCells??24e3,maxRasterPixels:i.maxRasterPixels,pixelRatio:h/(i.referenceWidth??Math.min(h,960))}));const u=new Set(He({...a,width:h,height:l}).map(t=>t.source)),f=new Map;await Promise.all([...u].map(async t=>{const i=o.get(t);await i.seek(e,m),f.set(t,i.frame(e)),i.animated&&n.invalidate(t)})),n.render(f,e,h,l,c?s:{})},{...i,signal:h.signal})}finally{if(h.abort(),i.signal?.removeEventListener("abort",l),n?.destroy(),o)for(const t of new Set(o.values()))t.destroy()}},exports.inkIndexLookup=pe,exports.isStudioPrintStyle=Y,exports.loadStudioMedia=ke,exports.mountStudio=async function(t,e,i={}){Pe()&&Re();const a=await ke(e,i.signal);try{return De(t,a,i)}catch(t){throw a.destroy(),t}},exports.mountStudioMedia=De,exports.mountStudioProject=async function(t,e,i,a={}){const s=Ye(e),r=await Je(s,i,a.signal);try{return Qe(t,s,r,a)}catch(t){for(const t of new Set(r.values()))t.destroy();throw t}},exports.mountStudioProjectMedia=Qe,exports.normalizeStudioCurve=P,exports.normalizeStudioCurves=C,exports.normalizeStudioPrint=G,exports.normalizeStudioProject=Ye,exports.normalizeStudioSettings=tt,exports.normalizeStudioWarps=L,exports.parseStudioProject=function(t){if(t.length>1e6)throw new Error("Project exceeds the 1 MB settings limit.");const e=JSON.parse(t);if("asciify-project"!==e?.kind||1!==e.version||!Array.isArray(e.layers))throw new Error("This is not an Asciify layered project.");return Ye(e)},exports.parseStudioSettings=function(t){if(t.length>1e5)throw new Error("Settings exceed 100 KB.");return tt(JSON.parse(t))},exports.resolveHover=m,exports.restyleStudio=function(t,e=Math.random){const i=rt.filter(e=>e.settings.style!==t.style||e.settings.ink!==t.ink),a=nt(i[Math.min(i.length-1,Math.max(0,Math.floor(e()*i.length)))].id);return a.aspectRatio=t.aspectRatio,a.crop={...t.crop},a.mask=tt(t).mask,a},exports.serializeStudioProject=t=>JSON.stringify(Ye(t)),exports.serializeStudioSettings=function(t){return JSON.stringify(tt(t))},exports.studioCrop=et,exports.studioDimensions=it,exports.studioGrid=st,exports.studioLayerPoint=Ge,exports.studioLevels=fe,exports.studioLook=nt,exports.studioProjectBudget=We,exports.studioSourceSize=ne,exports.studioToneGamma=de,exports.updateStudioProjectLayer=je,exports.updateStudioSettings=at,exports.visibleStudioLayers=He;//# sourceMappingURL=studio.cjs.map
1
+ "use strict";var t,e=Object.defineProperty,i=Object.getOwnPropertyNames,a=(t,e)=>function(){return t&&(e=(0,t[i(t)[0]])(t=0)),e},s=a({"worker-source:/Users/ayangabryl/asciify-recovery/work/engine/src/studio/render-worker.ts"(){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'}}),r={};((t,i)=>{for(var a in i)e(t,a,{get:i[a],enumerable:!0})})(r,{default:()=>t});var n=a({"src/studio/worker-source.ts"(){s()}}),o=[{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."}],h={rake:"silk"},l={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}},c={effect:"trail",strength:.55,radius:.2,decay:.5,scope:"all",edgeSafe:!1};function m(t){if("string"==typeof t)return t in h?h[t]:o.some(e=>e.value===t)?t:void 0}var u=t=>"subject"===t||"outside"===t?t:"all";function f(t,e,i,a,s){if(!(s<1))for(let r=0;r<2;r++){for(let r=0;r<a;r++){let a=0;const n=r*i;for(let e=-s;e<=s;e++)a+=t[n+Math.max(0,Math.min(i-1,e))];for(let r=0;r<i;r++)e[n+r]=a/(2*s+1),a+=t[n+Math.min(i-1,r+s+1)]-t[n+Math.max(0,r-s)]}for(let r=0;r<i;r++){let n=0;for(let t=-s;t<=s;t++)n+=e[Math.max(0,Math.min(a-1,t))*i+r];for(let o=0;o<a;o++)t[o*i+r]=n/(2*s+1),n+=e[Math.min(a-1,o+s+1)*i+r]-e[Math.max(0,o-s)*i+r]}}}var d=new Float32Array(0);function p(t,e,i,a,s){const r=e*i,n=s&&s.width===e&&s.height===i?s:{width:e,height:i,subject:new Float32Array(r),depth:new Float32Array(r),key:"none"},{subject:o,depth:h}=n;let l=0;for(let e=0;e<r;e++)t[4*e+3]<250&&l++;const c=e=>(.2126*t[4*e]+.7152*t[4*e+1]+.0722*t[4*e+2])/255;let m="none",u=0;if(l>.01*r)m="alpha";else if(a)m="mask";else{let t=0,a=0,s=0;const r=Math.max(1,Math.round(.03*Math.min(e,i)));for(let n=0;n<i;n++)for(let o=0;o<e;o++){if(o>=r&&n>=r&&o<e-r&&n<i-r)continue;const h=c(n*e+o);t+=h,a+=h*h,s++}u=t/Math.max(1,s);Math.sqrt(Math.max(0,a/Math.max(1,s)-u*u))<.07&&(m="ground")}for(let e=0;e<r;e++){const i=t[4*e+3]/255,s=c(e);let r=1;if("alpha"===m)r=i;else if("ground"===m){const t=Math.max(0,Math.min(1,(Math.abs(s-u)-.035)/.12));r=t*t*(3-2*t)}o[e]=r*(a?Math.max(0,Math.min(1,a[e])):1),h[e]=s*i}n.key=m,d.length<r&&(d=new Float32Array(r));const p=d;return f(o,p,e,i,Math.max(1,Math.round(.02*Math.min(e,i)))),f(h,p,e,i,Math.max(1,Math.round(.035*Math.min(e,i)))),n}function g(t,e,i="ground"){return"none"===i?1:"subject"===t?e:"outside"===t?1-e:1}var M={caustics:"sheen",grain:"shimmer",trace:"relight",tidal:"current",weave:"current",breeze:"current",reform:"develop",print:"develop",unfold:"develop"},x=[{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’s 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 v(t){const e=t&&Object.prototype.hasOwnProperty.call(M,t)?M[t]:t;return x.find(t=>t.value===e||t.mode===e)?.mode??"none"}var y=t=>Math.max(0,Math.min(1,t)),b=(t,e,i)=>{const a=y((i-t)/(e-t));return a*a*(3-2*a)},w=(t,e)=>{const i=(.06711056*t+.00583715*e)%1*52.9829189;return i-Math.floor(i)},k=class{constructor(){this.last=null,this.mode="none",this.phase=0}update(t,e,i=1){const a=v(e);return Number.isFinite(t)?((a!==this.mode||null!==this.last&&t<this.last)&&(this.mode=a,this.phase=0,this.last=t),null!==this.last&&(this.phase+=Math.max(0,t-this.last)*Math.max(.1,Math.min(3,Number.isFinite(i)?i:1))),this.last=t,this.phase):this.phase}};function A(t,e,i,a,s,r=.5,n,o=0){if(s[0]=s[1]=s[2]=0,s[3]=1,"none"===t)return s;r=y(r);const h=n?n[o]:r,l=n?n[o+1]:.5+.5*y(1-2*Math.hypot(e-.5,i-.55)),c=n?n[o+2]:b(.55,1,r)**2,m=n?n[o+3]:.5,u=n?n[o+4]:0,f=n?n[o+5]:0,d=a*Math.PI/6,p=(a%12+12)%12,g=b(0,.12,Math.min(e,1-e,i,1-i));if("relight"===t){const t=d+.6,a=Math.cos(t),n=Math.sin(t),o=Math.max(-1,Math.min(1,u*a+f*n))+.35*(a*(e-.5)+n*(i-.5));s[2]=.2*o*(.3+.7*b(.04,.3,h)*(1-.6*b(.82,1,r)))}else if("sheen"===t){const t=1.9*b(0,8,p)-.35,a=(.75*e+.45*i)/1.2+.05*(.75*u+.45*f),n=Math.exp(-(((a-t)/.12)**2));s[2]=n*b(.3,.8,h)*(1-.5*b(.9,1,r))*.45}else if("glow"===t){const t=.5-.5*Math.cos(d),e=1-.8*t;s[2]=.2*b(e-.3,e+.02,c)*Math.sqrt(c)*(1-.65*r)+.05*t*b(.6,.95,r)}else if("shimmer"===t){const t=w(Math.floor(160*e),Math.floor(100*i))*Math.PI*2,a=Math.pow(.5+.5*Math.cos(2*d+t),28);s[2]=a*b(.5,.88,r)*(.35+.65*b(.1,.55,m))*.42}else if("parallax"===t){const t=l-.45;s[0]=16*t*Math.sin(d)*g,s[1]=7*t*Math.sin(2*d)*g}else if("push"===t){const t=.045*(.5-.5*Math.cos(d))*(.7+.6*l)*960,a=n?n[o+6]:.5,r=n?n[o+7]:.5;s[0]=(e-a)*t,s[1]=(i-r)*t}else if("focus"===t){const t=Math.sin(d),e=t*t*b(.35,.85,t>=0?1-l:l);s[2]=(h-r)*e*.75}else if("mist"===t){const t=Math.pow(1-l,1.5)*(1-.6*m),a=.5*Math.sin(4.1*e-d+.9*Math.sin(3.3*i+d))+.3*Math.sin(7.3*e+2.1*i-2*d+1.1*Math.sin(2.7*e-5.1*i+d))+.2*Math.sin(5.7*i-1.9*e+d);s[2]=b(-.3,.9,a)*t*.16*(1-.55*r)}else if("current"===t){const t=n?.[o+8]??0,a=n?.[o+9]??0,h=n?.[o+10]??0,c=b(0,.06,Math.min(e,1-e,i,1-i)),u=n?0:(1-.4*m)*(1-.8*l)*g,f=t=>14*i-t+1.5*Math.sin(3*e+t),p=t=>16*i+2*e-t,M=t=>29*i-3*e-2*t,x=t=>1.7*e+2.3*i-t,v=t=>26*i+1.5*Math.sin(40*e)-2*t;s[0]=7*(Math.sin(f(d))-Math.sin(f(0))+.43*(Math.sin(5*e-3*i+d)-Math.sin(5*e-3*i)))*u+(3.5*(Math.sin(p(d))-Math.sin(p(0)))+1.5*(Math.sin(M(d))-Math.sin(M(0))))*t*c+5*(Math.sin(x(d))-Math.sin(x(0)))*a*c,s[1]=2*(Math.sin(11*e+d)-Math.sin(11*e))*u+.8*(Math.cos(p(d))-Math.cos(p(0)))*t*c+12*(Math.sin(v(d))-Math.sin(v(0)))*h*c;const y=Math.pow(.5+.5*Math.cos(2*d+9*e-4*i+6.2831853*w(Math.floor(160*e),Math.floor(100*i))),24)-Math.pow(.5+.5*Math.cos(9*e-4*i+6.2831853*w(Math.floor(160*e),Math.floor(100*i))),24);s[2]=.03*(Math.cos(f(d))-Math.cos(f(0)))*u+(y*b(.5,.85,r)*.3+.025*(Math.cos(p(d))-Math.cos(p(0))))*t*c+.08*(Math.cos(v(d))-Math.cos(v(0)))*h*c}else if("develop"===t){const t=b(7,8.5,p),a=y((p-8.5)/3.5),n=p<8.5?1-t:b(0,1,(1.45*a-(1-r)+.06*(w(Math.floor(160*e),Math.floor(100*i))-.5))/.3);s[2]=.3*-(1-n),s[3]=1-.9*(1-n)}return s}function S(t){const e=Math.floor(t),i=Math.max(0,Math.min(1,(t-e-.2)/.6));return e+i*i*(3-2*i)}function F(t,e,i,a,s,r){return r[0]=S(Math.max(0,Math.min(a-1,e-t[0]/960*a))),r[1]=S(Math.max(0,Math.min(s-1,i-t[1]/960*s))),r}function E(t,e){const i=Math.max(0,Math.min(2,Number.isFinite(e)?e:1));return t[0]*=i,t[1]*=i,t[2]*=i,t[3]=y(1+(t[3]-1)*i),t}var R=["rgb","red","green","blue"],T=t=>Math.max(0,Math.min(1,t));function P(t){const e=new Map([[0,0],[1,1]]);if(Array.isArray(t))for(const i of t.slice(0,64)){if(!Array.isArray(i)||i.length<2||"number"!=typeof i[0]||!Number.isFinite(i[0])||"number"!=typeof i[1]||!Number.isFinite(i[1]))continue;const t=Math.round(255*T(i[0]))/255;!e.has(t)&&e.size>=16||e.set(t,T(i[1]))}return[...e].sort((t,e)=>t[0]-e[0])}function C(t){const e=t&&"object"==typeof t?t:{};return Object.fromEntries(R.map(t=>[t,P(e[t])]))}function I(t){const e=P(t),i=e.length,a=e.slice(1).map((t,i)=>t[0]-e[i][0]),s=e.slice(1).map((t,i)=>(t[1]-e[i][1])/a[i]),r=new Float64Array(i);r[0]=s[0],r[i-1]=s[i-2];for(let t=1;t<i-1;t++){const e=s[t-1],i=s[t];if(e*i<=0)continue;const n=2*a[t]+a[t-1],o=a[t]+2*a[t-1];r[t]=(n+o)/(n/e+o/i)}const n=new Uint8Array(256);let o=0;for(let t=0;t<256;t++){const s=t/255;for(;o<i-2&&s>e[o+1][0];)o++;const h=a[o],l=(s-e[o][0])/h,c=l*l,m=c*l,u=(2*m-3*c+1)*e[o][1]+(m-2*c+l)*h*r[o]+(-2*m+3*c)*e[o+1][1]+(m-c)*h*r[o+1];n[t]=Math.round(255*T(u))}return n}function D(t,e,i,a,s,r){a=Math.max(0,Math.min(e-1,a)),s=Math.max(0,Math.min(i-1,s));const n=Math.floor(a),o=Math.floor(s),h=a-n,l=s-o,c=4*(o*e+n);if(0===h&&0===l){for(let e=0;e<4;e++)r[e]=t[c+e];return}const m=4*(o*e+Math.min(e-1,n+1)),u=4*(Math.min(i-1,o+1)*e+n),f=4*(Math.min(i-1,o+1)*e+Math.min(e-1,n+1)),d=(1-h)*(1-l)*t[c+3],p=h*(1-l)*t[m+3],g=(1-h)*l*t[u+3],M=h*l*t[f+3],x=d+p+g+M;for(let e=0;e<3;e++)r[e]=x?(t[c+e]*d+t[m+e]*p+t[u+e]*g+t[f+e]*M)/x:0;r[3]=x}function N(t,e,i,a,s,r){if(a>=0&&a<=e-1&&s>=0&&s<=i-1)return D(t,e,i,a,s,r);if(r[0]=r[1]=r[2]=r[3]=0,a<=-1||a>=e||s<=-1||s>=i)return;const n=Math.floor(a),o=Math.floor(s),h=a-n,l=s-o;for(let a=0;a<=1;a++)for(let s=0;s<=1;s++){const c=n+s,m=o+a;if(c<0||c>=e||m<0||m>=i)continue;const u=4*(m*e+c),f=(s?h:1-h)*(a?l:1-l)*t[u+3];r[0]+=t[u]*f,r[1]+=t[u+1]*f,r[2]+=t[u+2]*f,r[3]+=f}r[3]&&(r[0]/=r[3],r[1]/=r[3],r[2]/=r[3])}var U=[{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}],O=(t,e,i,a)=>"number"==typeof t&&Number.isFinite(t)?Math.max(i,Math.min(a,t)):e;function L(t){if(!Array.isArray(t))return[];const e=[];for(const i of t.slice(0,64))if(i&&"object"==typeof i&&U.some(t=>t.value===i.type)&&(e.push({type:i.type,enabled:!1!==i.enabled,amount:O(i.amount,.35,-1,1),x:O(i.x,.5,0,1),y:O(i.y,.5,0,1),radius:O(i.radius,.55,.05,2),angle:O(i.angle,0,-180,180),frequency:O(i.frequency,5,1,24)}),8===e.length))break;return e}var q=2*Math.PI,X=(t,e)=>{let i=Math.imul(t,374761393)^Math.imul(e,668265263);return i=Math.imul(i^i>>>13,1274126177),((i^i>>>16)>>>0)/4294967296},z=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"){const i=L(t).filter(t=>t.enabled&&0!==t.amount),a=JSON.stringify(i);this.edge="transparent"===e?"transparent":"clamp",a!==this.signature&&(this.signature=a,this.geometry="",this.warps=i.map(t=>({...t,cos:Math.cos(t.angle*Math.PI/180),sin:Math.sin(t.angle*Math.PI/180)})),i.length||this.clear())}get active(){return this.warps.length>0}apply(t,e,i,a=e/i){if(!this.active)return t;if(!Number.isInteger(e)||!Number.isInteger(i)||e<1||i<1||e*i*4!==t.length||!Number.isFinite(a)||a<=0)throw new Error("Warp dimensions do not match the source.");const s=`${e}:${i}:${a}`;if(s!==this.geometry){this.coordinates.length!==e*i*2&&(this.coordinates=new Float32Array(e*i*2));const t=Math.max(1,a),r=Math.max(1,1/a);for(let a=0;a<i;a++)for(let s=0;s<e;s++){let n=(s+.5)/e,o=(a+.5)/i;for(let e=this.warps.length-1;e>=0;e--){const i=this.warps[e],a=(n-i.x)*t/i.radius,s=(o-i.y)*r/i.radius,h=a*a+s*s;if(h>=1)continue;const l=Math.sqrt(h),c=(1-h)*(1-h),m=i.amount;let u=a,f=s;if("twirl"===i.type||"zigzag"===i.type){const t="twirl"===i.type?-m*q*c:.65*m*(2/Math.PI*Math.asin(Math.sin(l*q*i.frequency)))*c,e=Math.cos(t),r=Math.sin(t);u=a*e-s*r,f=a*r+s*e}else if("pinch"===i.type){const t=Math.exp(2*m*c);u=a*t,f=s*t}else if("sphere"===i.type&&l>0){const t=1+m*c*(2*Math.asin(l)/Math.PI/l-1);u=a*t,f=s*t}else if("ripple"===i.type&&l>0){const t=1+.12*m*Math.sin(l*q*i.frequency)*c/l;u=a*t,f=s*t}else if("shear"===i.type){const t=-a*i.sin+s*i.cos;u-=m*t*.9*c*i.cos,f-=m*t*.9*c*i.sin}else if("smudge"===i.type)u-=.65*m*c*i.cos,f-=.65*m*c*i.sin;else if("polar"===i.type){const t=a*i.cos+s*i.sin,e=-a*i.sin+s*i.cos,r=Math.atan2(e,t),n=m>0?r/Math.PI:Math.cos(t*Math.PI)*(e+1)/2,o=m>0?2*l-1:Math.sin(t*Math.PI)*(e+1)/2,h=n*i.cos-o*i.sin,d=n*i.sin+o*i.cos;u+=(h-a)*Math.abs(m)*c,f+=(d-s)*Math.abs(m)*c}else if("fragment"===i.type){const t=Math.floor((a*i.cos+s*i.sin)*i.frequency),e=Math.floor((-a*i.sin+s*i.cos)*i.frequency),r=(X(t,e)-.5)*m*.5*c,n=(X(e+71,t-31)-.5)*m*.5*c;u+=r*i.cos-n*i.sin,f+=r*i.sin+n*i.cos}n=i.x+u*i.radius/t,o=i.y+f*i.radius/r}const h=2*(a*e+s);this.coordinates[h]=n*e-.5,this.coordinates[h+1]=o*i-.5}this.geometry=s}this.output.length!==t.length&&(this.output=new Uint8ClampedArray(t.length));const r=t===this.output?t.slice():t,n="transparent"===this.edge?N:D;for(let a=0,s=0;a<t.length;a+=4,s+=2){n(r,e,i,this.coordinates[s],this.coordinates[s+1],this.sampled);for(let t=0;t<4;t++)this.output[a+t]=this.sampled[t]}return this.output}clear(){this.coordinates=new Float32Array(0),this.output=new Uint8ClampedArray(0),this.geometry=""}},B=["stipple","engraving","crosshatch","woodblock","risograph","pointillism"];function Y(t){return B.includes(t)}var j={density:1,weight:1,angle:-35,roughness:.35,invert:!1,secondaryInk:"#ec6752",registration:.2,seed:7};function G(t){const e=t&&"object"==typeof t&&!Array.isArray(t)?t:{},i=(t,i,a)=>{const s=e[t];return"number"==typeof s&&Number.isFinite(s)?Math.max(i,Math.min(a,s)):j[t]};return{density:i("density",0,2),weight:i("weight",.25,2),angle:i("angle",-180,180),roughness:i("roughness",0,1),invert:!0===e.invert,secondaryInk:"string"==typeof e.secondaryInk&&/^#[\da-f]{6}$/i.test(e.secondaryInk)?e.secondaryInk:j.secondaryInk,registration:i("registration",0,1),seed:Math.round(i("seed",0,65535))}}var H=["ascii","blocks","braille","dots","lines","cross","diagonal","diamond","mixed","pixel","mosaic","lego","voxel","disco","dither","hex","led","cmyk",...B],W=["none","bayer2","bayer4","bayer8","bayer16","floyd-steinberg","atkinson","stucki","sierra","sierra-lite","burkes","jarvis","halftone","lines","noise","vertical-lines","diagonal-lines","radial","blue-noise"],V=["source-over","multiply","screen","overlay","soft-light","hard-light","color-dodge","color-burn","hue","saturation","color","luminosity"],K={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"]},J={version:1,aspectRatio:"original",style:"ascii",cellSize:6,charset:" .:-=+*#%@",colorMode:"accent",ink:"#e6e3da",print:{...j},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}},Q=t=>t&&"object"==typeof t&&!Array.isArray(t)?t:{},Z=(t,e,i,a)=>"number"==typeof t&&Number.isFinite(t)?Math.min(a,Math.max(i,t)):e,_=(t,e)=>"string"==typeof t&&/^#[\da-f]{6}$/i.test(t)?t:e,$=(t,e,i)=>e.includes(t)?t:i;function tt(t={}){const e=Q(t),i=J;if(void 0!==e.version&&1!==e.version)throw new Error("Unsupported studio settings version. Update asciify-engine.");const a=Q(e.crop),s=Q(e.backdrop),r=Q(e.color),n=Q(e.dither),o=Q(e.mask),h=Q(e.effects),f=Q(e.motion),d=Q(e.hover),p={...i.effects};for(const t of["bloom","characterBloom","grain","dust","scanlines","crt","prism","rgbSplit","sharpen","vignette","glitch","pixelate","halftone"])p[t]=Z(h[t],0,0,1);p.blur=Z(h.blur,0,0,24),p.blurType=$(h.blurType,["gaussian","directional","radial","progressive"],i.effects.blurType),p.angle=Z(h.angle,0,-180,180),p.focus=Z(h.focus,.5,0,1);let g=2048;return{version:1,aspectRatio:$(e.aspectRatio,["original","16:9","9:16","1:1","4:3","3:4","21:9"],"original"),style:$(e.style,H,i.style),cellSize:Z(e.cellSize,i.cellSize,Y(String(e.style))||["pixel","mosaic","lego","voxel","disco","dots","hex","led","cmyk"].includes(String(e.style))?1:3,60),charset:"string"==typeof e.charset&&e.charset.length?Array.from(e.charset).slice(0,128).join(""):i.charset,colorMode:$(e.colorMode,["accent","source","gray"],i.colorMode),ink:_(e.ink,i.ink),print:G(e.print),warps:L(e.warps),warpEdge:$(e.warpEdge,["clamp","transparent"],"clamp"),crop:{x:Z(a.x,.5,0,1),y:Z(a.y,.5,0,1),zoom:Z(a.zoom,1,1,5),rotation:90*Math.round(Z(a.rotation,0,-360,360)/90)},backdrop:{mode:$(s.mode,["solid","transparent","source","blurred","gradient"],i.backdrop.mode),color:_(s.color,i.backdrop.color),color2:_(s.color2,i.backdrop.color2),blur:Z(s.blur,12,0,32),opacity:Z(s.opacity,1,0,1)},color:{brightness:Z(r.brightness,0,-1,1),contrast:Z(r.contrast,1,0,3),saturation:Z(r.saturation,1,0,3),grayscale:Z(r.grayscale,0,0,1),tint:_(r.tint,i.color.tint),amount:Z(r.amount,0,0,1),blend:$(r.blend,V,i.color.blend),blackPoint:Z(r.blackPoint,0,0,.99),whitePoint:Math.max(Z(r.blackPoint,0,0,.99)+1/255,Z(r.whitePoint,1,1/255,1)),gamma:Z(r.gamma,1,.25,4),shadows:Z(r.shadows,0,-1,1),highlights:Z(r.highlights,0,-1,1),curves:C(r.curves),denoise:Z(r.denoise,0,0,1),levels:"none"===r.levels?"none":"auto"},dither:{algorithm:$(n.algorithm,W,"none"),palette:"string"==typeof n.palette&&Object.prototype.hasOwnProperty.call(K,n.palette)?n.palette:"mono",colors:Array.isArray(n.colors)&&n.colors.length>=2?n.colors.slice(0,32).map(t=>_(t,"#000000")):[...i.dither.colors],amount:Z(n.amount,1,0,2),scale:Math.round(Z(n.scale,2,1,12)),threshold:Z(n.threshold,.5,0,1),motion:$(n.motion,["none","drift","shimmer"],"none"),speed:Z(n.speed,1,.1,3),direction:Z(n.direction,45,-180,180),colorSpace:$(n.colorSpace,["rgb","luminance"],"rgb")},mask:{enabled:!0===o.enabled,invert:!0===o.invert,shapes:Array.isArray(o.shapes)?o.shapes.slice(0,64).map(t=>{const e=Q(t),i=$(e.kind,["rectangle","ellipse","brush"],"rectangle"),a="brush"===i&&Array.isArray(e.points)?e.points.slice(0,g).map(t=>Array.isArray(t)?[Math.round(1e4*Z(t[0],0,0,1))/1e4,Math.round(1e4*Z(t[1],0,0,1))/1e4]:[0,0]):[];return g-=a.length,{kind:i,x:Z(e.x,0,0,1),y:Z(e.y,0,0,1),width:Z(e.width,.5,0,1),height:Z(e.height,.5,0,1),size:Z(e.size,.05,.005,.5),points:a}}):[]},lights:Array.isArray(e.lights)?e.lights.slice(0,4).map(t=>{const e=Q(t);return{x:Z(e.x,.5,0,1),y:Z(e.y,.5,0,1),radius:Z(e.radius,.3,.02,1),intensity:Z(e.intensity,.5,0,1),color:_(e.color,"#ffffff")}}):[],effects:p,motion:{type:$("string"==typeof f.type?v(f.type):f.type,x.map(t=>t.mode),"none"),speed:Z(f.speed,1,.1,3),amount:Z(f.amount,1,0,2)},hover:{effect:m(d.effect)??c.effect,strength:Z(d.strength,l.strength.default,l.strength.min,l.strength.max),radius:Z(d.radius,l.radius.default,l.radius.min,l.radius.max),edgeSafe:!0===d.edgeSafe,..."all"!==u(d.scope)&&{scope:u(d.scope)},....5!==Z(d.decay,.5,0,1)&&{decay:Z(d.decay,.5,0,1)}}}}function et(t,e,i,a,s){const r=Math.abs(s.rotation/90)%2==1,n=r?e:t,o=r?t:e,h=Math.max(i/n,a/o)*s.zoom;return{width:n*h,height:o*h,x:(i-n*h)*s.x,y:(a-o*h)*s.y,scale:h,rotated:r}}function it(t,e,i){if(Math.abs(i.crop.rotation/90)%2==1&&([t,e]=[e,t]),"original"===i.aspectRatio)return[t,e];const[a,s]=i.aspectRatio.split(":").map(Number);return t/e>a/s?[Math.round(e*a/s),e]:[t,Math.round(t*s/a)]}function at(t,e){const i={...t,...e};for(const a of["crop","backdrop","color","dither","mask","effects","motion","hover","print"])e[a]&&Object.assign(i,{[a]:{...t[a],...e[a]}});return e.color?.curves&&(i.color.curves={...t.color.curves,...e.color.curves}),tt(i)}function st(t,e,i,a=12e3,s=1){const r=Math.max(2,Number.isFinite(t)?t:960),n=Math.max(2,Number.isFinite(e)?e:540),o=Math.max(1,Math.floor(Number.isFinite(a)?a:12e3)),h=Math.max(.01,Number.isFinite(s)?s:1),l=Y(i.style)||["dither","pixel","mosaic","lego","voxel","disco","dots","hex","led","cmyk"].includes(i.style)?1:1.65;let c=Math.max(1,Math.ceil(Math.sqrt(r*n/(o*l))/h));for(;Math.ceil(r/(c*h))*Math.ceil(n/(c*h*l))>o;)c++;const m="dither"===i.style?i.dither.scale:i.cellSize,u=Math.max(c,m)*h;return{cell:u,rowHeight:u*l,columns:Math.ceil(r/u),rows:Math.ceil(n/(u*l)),minimum:c,limited:m<c}}var rt=[["ascii","Signature ASCII","Clean characters in paper white on near black.",{cellSize:4,ink:"#ece9e0",backdrop:{mode:"solid",color:"#0b0b0a"},color:{contrast:1.25,gamma:1.25},effects:{characterBloom:.12}}],["print","Newsprint","Fine diffusion in soft black on warm paper.",{style:"dither",cellSize:6,ink:"#1d1c19",backdrop:{mode:"solid",color:"#efece4"},dither:{algorithm:"floyd-steinberg",palette:"custom",colors:["#efece4","#1d1c19"],scale:2}}],["handheld","Pocket camera","Four-tone ordered dither in graphite.",{style:"dither",cellSize:6,ink:"#dedbd2",backdrop:{mode:"solid",color:"#121211"},dither:{algorithm:"bayer4",palette:"custom",colors:["#121211","#3e3d39","#8a8880","#dedbd2"],scale:2}}],["riso","Two inks","Muted blue and coral on warm paper.",{style:"dither",cellSize:6,ink:"#3d5068",backdrop:{mode:"solid",color:"#f0ece3"},dither:{algorithm:"atkinson",palette:"custom",colors:["#f0ece3","#c27461","#3d5068"],scale:2}}],["night","Night signal","Graphite characters with a faint optical fringe.",{cellSize:4,ink:"#cdc9be",backdrop:{mode:"solid",color:"#0b0b0a"},color:{contrast:1.2,gamma:1.2},effects:{prism:.2,scanlines:.08,vignette:.3,bloom:.12}}],["terminal","Phosphor","Soft sage glyphs with a faint glow.",{cellSize:5,ink:"#a4c9b3",backdrop:{mode:"solid",color:"#0a0d0b"},effects:{bloom:.16,scanlines:.12,crt:.06}}],["mosaic","Mosaic study","Separated tiles in quiet source color.",{style:"mosaic",ink:"#e6e3da",cellSize:9,colorMode:"source",backdrop:{mode:"solid",color:"#0b0b0a"},color:{saturation:.55,contrast:1.05}}],["bricks","Brickwork","Studded cells in softened color.",{style:"lego",ink:"#e6e3da",cellSize:12,colorMode:"source",backdrop:{mode:"solid",color:"#0b0b0a"},color:{saturation:.55}}],["voxel","Little volumes","Three-face isometric tiles in muted color.",{style:"voxel",ink:"#e6e3da",cellSize:12,colorMode:"source",backdrop:{mode:"solid",color:"#0b0b0a"},color:{saturation:.5}}],["disco","Mirror room","Faceted tiles under one soft light.",{style:"disco",ink:"#e6e3da",cellSize:11,colorMode:"source",backdrop:{mode:"solid",color:"#0b0b0a"},color:{saturation:.5},lights:[{x:.35,y:.25,radius:.28,intensity:.28,color:"#f4efe4"}]}],["wallpaper","Wallpaper","Living ASCII over a softened source.",{cellSize:5,backdrop:{mode:"blurred",color:"#0b0b0a",blur:18,opacity:.4},ink:"#e6e3da",motion:{type:"relight",speed:.35,amount:.8}}],["blueprint","Blueprint","Fine linework in pale blue on deep navy.",{style:"lines",cellSize:6,ink:"#b3c9d8",backdrop:{mode:"solid",color:"#0e1b28"}}]].map(([t,e,i,a])=>({id:t,name:e,description:i,settings:tt(a)}));function nt(t){const e=rt.find(e=>e.id===t);if(!e)throw new Error("Unknown studio look.");return tt(e.settings)}var ot="dot-fill";function ht(t){const e=function(t){const e=t.blackPoint??0,i=t.whitePoint??1,a=t.gamma??1,s=t.shadows??0,r=t.highlights??0;if(0===e&&1===i&&1===a&&0===s&&0===r)return null;const n=[0,.25+.2*s,.5,.75+.2*r,1],o=n.slice(1).map((t,e)=>4*(t-n[e])),h=[o[0],...o.slice(1).map((t,e)=>2*t*o[e]/(t+o[e])),o[3]],l=new Uint8Array(256);for(let t=0;t<256;t++){const s=Math.pow(Math.max(0,Math.min(1,(t/255-e)/(i-e))),1/a),r=Math.min(3,Math.floor(4*s)),o=4*s-r,c=o*o,m=c*o,u=(2*m-3*c+1)*n[r]+(m-2*c+o)*h[r]/4+(-2*m+3*c)*n[r+1]+(m-c)*h[r+1]/4;l[t]=Math.round(255*Math.max(0,Math.min(1,u)))}return l}(t),i=t.curves;if(!e&&(!i||Object.values(i).every(t=>t.every(([t,e])=>t===e))))return null;const a=I(i?.rgb),s=[i?.red,i?.green,i?.blue].map(I),r=new Uint8Array(768);for(let t=0;t<256;t++)for(let i=0;i<3;i++)r[256*i+t]=s[i][a[e?e[t]:t]];return r}var lt=class{constructor(t=0){this.amount=0,this.weights=new Float32Array(256),this.source=new Uint8ClampedArray(0),this.configure(t)}configure(t=0){const e=Math.max(0,Math.min(1,Number.isFinite(t)?t:0));if(e===this.amount)return;if(this.amount=e,0===e)return void(this.source=new Uint8ClampedArray(0));const i=8+24*e;for(let t=0;t<256;t++)this.weights[t]=Math.exp(-t*t/(2*i*i))}apply(t,e,i){if(!this.amount)return;if(!Number.isInteger(e)||!Number.isInteger(i)||e<1||i<1||e*i*4!==t.length)throw new Error("Denoise dimensions do not match the source.");this.source.length!==t.length&&(this.source=new Uint8ClampedArray(t.length));const a=this.source;a.set(t);for(let s=0;s<i;s++)for(let r=0;r<e;r++){const n=4*(s*e+r);if(!a[n+3])continue;const o=a[n],h=a[n+1],l=a[n+2];let c=0,m=0,u=0,f=0;for(let t=-1;t<=1;t++){const n=s+t;if(!(n<0||n>=i))for(let i=-1;i<=1;i++){const s=r+i;if(s<0||s>=e)continue;const d=4*(n*e+s);if(!a[d+3])continue;const p=Math.max(Math.abs(a[d]-o),Math.abs(a[d+1]-h),Math.abs(a[d+2]-l)),g=this.weights[p]*(0===i?1:.6)*(0===t?1:.6)*a[d+3];c+=a[d]*g,m+=a[d+1]*g,u+=a[d+2]*g,f+=g}}t[n]=o+(c/f-o)*this.amount,t[n+1]=h+(m/f-h)*this.amount,t[n+2]=l+(u/f-l)*this.amount}}},ct=2*Math.PI,mt=t=>Math.max(0,Math.min(1,t)),ut=.1,ft=t=>Math.max(-.1,Math.min(1.1,t)),dt=Float32Array.from({length:2048},(t,e)=>Math.sin(e/2048*ct)),pt=t=>dt[2047&Math.floor(t*(2048/ct))];function gt(t,e,i){let a=Math.imul(t,374761393)^Math.imul(e,668265263)^Math.imul(i,1442695041);return a=Math.imul(a^a>>>13,1274126177),((a^a>>>16)>>>0)/4294967296}function Mt(t){const e=G(t),{density:i,weight:a,angle:s,roughness:r,invert:n,secondaryInk:o,registration:h,seed:l}=e,c=s*Math.PI/180,m=[c,c+Math.PI/2,c+Math.PI/4].map(t=>[Math.cos(t),Math.sin(t)]),u=new Float32Array(6);function f(t,e,i,s,n,o,h,c,f=!1){if(h<=0)return;const[d,p]=m[c],g=-p,M=d,x=g*(e+.5)+M*(i+.5),v=.5*(Math.abs(g)+Math.abs(M)),y=f?1:.5,b=Math.ceil((x-v)/y),w=Math.floor((x+v)/y),k=Math.min(.94*y,.72*y*h*a);t.lineWidth=o*k,t.beginPath();for(let a=b;a<=w;a++){const h=a*y-x,c=.5+g*h,m=.5+M*h;let v=-2,b=2;if(Math.abs(d)>1e-8){const t=-c/d,e=(1-c)/d;v=Math.max(v,Math.min(t,e)),b=Math.min(b,Math.max(t,e))}else if(c<0||c>1)continue;if(Math.abs(p)>1e-8){const t=-m/p,e=(1-m)/p;v=Math.max(v,Math.min(t,e)),b=Math.min(b,Math.max(t,e))}else if(m<0||m>1)continue;if(!(b<=v))if(f&&(v-=ut,b+=ut),f){for(let t=0;t<6;t++){const s=v+(b-v)*t/5,r=d*(e+c+d*s)+p*(i+m+p*s);u[t]=.5*pt(5.3*r+1.9*a+l)+.25*pt(13.1*r+a)}for(let e=0;e<2;e++)for(let i=0;i<6;i++){const a=v+(b-v)*(e?5-i:i)/5,h=u[e?5-i:i],l=.5*k*(1+r*h*.5)*(e?-1:1),f=s+ft(c+d*a+g*l)*o,x=n+ft(m+p*a+M*l)*o;e||i?t.lineTo(f,x):t.moveTo(f,x)}t.closePath()}else t.moveTo(s+(c+d*v)*o,n+(m+p*v)*o),t.lineTo(s+(c+d*b)*o,n+(m+p*b)*o)}f?t.fill():t.stroke()}return{settings:e,paint(t,e,s,c,u,d,p,g,M,x,v,y,b){const w=mt((n?1-g:g)*i);if(w<=0||t.globalAlpha<=0)return;t.fillStyle=M,t.strokeStyle=M;const k=gt(s,c,l);if("engraving"===e||"crosshatch"===e||"woodblock"===e){const i=w*(1-r*k*.3);"woodblock"===e?f(t,s,c,u,d,p,Math.ceil(5*i)/5,0,!0):(f(t,s,c,u,d,p,i,0),"crosshatch"===e&&(f(t,s,c,u,d,p,Math.max(0,1.5*i-.3),1),f(t,s,c,u,d,p,Math.max(0,2*i-1.2),2)))}else if("risograph"===e){const e="source"===b?mt(.5+(x-y)/510):.5,i=.38*h*p,n=p*Math.min(.48,.44*Math.sqrt(w)*a);t.beginPath(),t.arc(u+.5*p,d+.5*p,n*Math.sqrt(.35+.65*(1-e)),0,ct),t.fill(),t.globalCompositeOperation="multiply",t.fillStyle=o;const f=1-r*gt(s,c,l+13)*.3;t.beginPath(),t.arc(u+.5*p+i*m[0][0],d+.5*p+i*m[0][1],n*Math.sqrt(.3+.7*e)*f,0,ct),t.fill(),t.globalCompositeOperation="source-over"}else{const i=t.fillEllipse;"stipple"===e&&t.beginPath();for(let n=0;n<4;n++){const o=gt(2*s+n%2,2*c+(n>>1),l),h=gt(s,c,l+11*n+1),m=u+((n%2+.5)/2+(o-.5)*r*.28)*p,f=d+((.5+(n>>1))/2+(h-.5)*r*.28)*p,g=Math.min(m-u,u+p-m,f-d,d+p-f,p*Math.min(.245,.21*a*Math.sqrt(w)*(1-r*o*.35)));if("stipple"===e)t.moveTo(m+g,f),t.arc(m,f,g,0,ct);else{const e=(o-.5)*r*64;if(i&&"accent"!==b){const t=Math.round(x+e);i(m,f,g,.64*g,o*Math.PI,t,"source"===b?Math.round(v-.4*e):t,"source"===b?Math.round(y-e):t);continue}t.fillStyle="source"===b?`rgb(${Math.round(x+e)},${Math.round(v-.4*e)},${Math.round(y-e)})`:"gray"===b?`rgb(${Math.round(x+e)},${Math.round(x+e)},${Math.round(x+e)})`:M,t.beginPath(),t.ellipse(m,f,g,.64*g,o*Math.PI,0,ct),t.fill()}}"stipple"===e&&t.fill()}}}}var xt=new Set(["none","floyd-steinberg","atkinson","stucki","sierra","sierra-lite","burkes","jarvis"]);function vt(t){return"dither"===t.style&&("shimmer"===t.dither.motion||"drift"===t.dither.motion&&t.dither.amount>0&&!xt.has(t.dither.algorithm))}function yt(t){return"none"!==t.motion.type&&(t.motion.amount??1)>0}function bt(t){return yt(t)||vt(t)||t.effects.grain>0||t.effects.dust>0||t.effects.glitch>0}var wt=11,kt=t=>Math.max(0,Math.min(1,t)),At=(t,e,i)=>{const a=kt((i-t)/(e-t));return a*a*(3-2*a)};function St(t,e,i=256){let a=0;for(let e=0;e<t.length;e++)t[e]>a&&(a=t[e]);if(a<=0)return 0;const s=new Uint32Array(i);for(let e=0;e<t.length;e++)s[Math.min(i-1,Math.floor(Math.max(0,t[e])/a*i))]++;let r=0;const n=t.length*e;for(let t=0;t<i;t++)if(r+=s[t],r>=n)return(t+1)/i*a;return a}var Ft=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));const e=this.arrays[this.next++];return t?e.set(t):e.fill(0),e}reset(){this.next=0}},Et=null;function Rt(t,e,i,a,s){const r=2*s+1;for(let n=0;n<a;n++){const a=n*i;let o=0;for(let e=-s;e<=s;e++)o+=t[a+Math.max(0,Math.min(i-1,e))];for(let n=0;n<i;n++)e[a+n]=o/r,o+=t[a+Math.min(i-1,n+s+1)]-t[a+Math.max(0,n-s)]}for(let n=0;n<i;n++){let o=0;for(let t=-s;t<=s;t++)o+=e[Math.max(0,Math.min(a-1,t))*i+n];for(let h=0;h<a;h++)t[h*i+n]=o/r,o+=e[Math.min(a-1,h+s+1)*i+n]-e[Math.max(0,h-s)*i+n]}}function Tt(t,e,i,a,s,r,n){const o=i*a,h=n.take(),l=n.take(e),c=n.take(t),m=n.take(),u=n.take();for(let i=0;i<o;i++)m[i]=e[i]*e[i],u[i]=e[i]*t[i];Rt(l,h,i,a,s),Rt(c,h,i,a,s),Rt(m,h,i,a,s),Rt(u,h,i,a,s);for(let t=0;t<o;t++){const e=(u[t]-l[t]*c[t])/(m[t]-l[t]*l[t]+r);m[t]=e,u[t]=c[t]-e*l[t]}Rt(m,h,i,a,s),Rt(u,h,i,a,s);for(let i=0;i<o;i++)t[i]=m[i]*e[i]+u[i]}function Pt(t,e,i,a,s,r=2){for(let n=0;n<r;n++){for(let r=0;r<a;r++)for(let a=0;a<i;a++){const n=r*i+a;let o=t[n];a>0&&(o=Math.max(o,Math.min(e[n],t[n-1]*s))),r>0&&(o=Math.max(o,Math.min(e[n],t[n-i]*s),a>0?Math.min(e[n],t[n-i-1]*s):0,a<i-1?Math.min(e[n],t[n-i+1]*s):0)),t[n]=o}for(let r=a-1;r>=0;r--)for(let n=i-1;n>=0;n--){const o=r*i+n;let h=t[o];n<i-1&&(h=Math.max(h,Math.min(e[o],t[o+1]*s))),r<a-1&&(h=Math.max(h,Math.min(e[o],t[o+i]*s),n>0?Math.min(e[o],t[o+i-1]*s):0,n<i-1?Math.min(e[o],t[o+i+1]*s):0)),t[o]=h}}}function Ct(t,e,i,a,s){for(let r=0;r<a;r++)for(let a=0;a<i;a++){let n=1;for(let e=Math.max(0,a-s);e<=Math.min(i-1,a+s);e++)n=Math.min(n,t[r*i+e]);e[r*i+a]=n}for(let r=0;r<a;r++)for(let n=0;n<i;n++){let o=1;for(let t=Math.max(0,r-s);t<=Math.min(a-1,r+s);t++)o=Math.min(o,e[t*i+n]);t[r*i+n]=o}}function It(t,e,i,a,s){const r=i*a,n=Math.min(i,a),o=s.take(),h=s.take(),l=s.take(),c=s.take(),m=s.take();for(let i=0;i<r;i++){const a=t[4*i+3]/255;m[i]=a,o[i]=e[4*i]/255*a,h[i]=e[4*i+1]/255*a,l[i]=e[4*i+2]/255*a,c[i]=(.299*t[4*i]+.587*t[4*i+1]+.114*t[4*i+2])/255*a}const u=s.take(),d=(t,e)=>{const r=s.take(t);return f(r,u,i,a,e),r},g=Math.max(2,Math.round(.04*n)),M=Math.max(g+2,Math.round(.12*n)),x=Math.max(2,Math.round(.05*n)),v=d(c,1),y=d(c,g),b=d(c,M),w=s.take(),k=s.take(),A=s.take(),S=s.take(),F=s.take();for(let t=0;t<a;t++)for(let e=0;e<i;e++){const s=t*i+e;w[s]=Math.abs(c[s]-v[s]),k[s]=Math.abs(v[s]-y[s]),A[s]=Math.abs(y[s]-b[s]),S[s]=Math.abs(c[t*i+Math.min(i-1,e+1)]-c[t*i+Math.max(0,e-1)]),F[s]=Math.abs(c[Math.min(a-1,t+1)*i+e]-c[Math.max(0,t-1)*i+e])}f(w,u,i,a,x),f(k,u,i,a,x),f(A,u,i,a,x),f(S,u,i,a,2),f(F,u,i,a,2);const E=Math.max(.01,St(w,.9)+St(k,.9)),R=d(o,1),T=d(h,1),P=d(l,1),C=s.take(),I=s.take(),D=s.take();let N=0;for(let t=0;t<r;t++){const e=R[t],i=T[t],a=P[t],s=Math.max(e,i,a),r=s-Math.min(e,i,a);D[t]=s,I[t]=s>.001?r/s:0,N+=r;let n=0;r>1e-4&&(n=s===e?((i-a)/r+6)%6:s===i?(a-e)/r+2:(e-i)/r+4),C[t]=60*n}const U=At(.02,.07,N/r),O=Math.max(2,Math.round(.06*a)),L=new Float32Array(a);for(let t=0;t<a;t++){let e=0;for(let a=0;a<i;a++)e+=w[t*i+a]+k[t*i+a];L[t]=e/i}let q=.5,X=0;for(let t=Math.max(O,Math.round(.12*a));t<=Math.min(a-O,Math.round(.88*a));t++){let e=0,s=0,r=0,n=0;for(let a=0;a<i;a++){let r=0,n=0,o=0,h=0,l=0,c=0;for(let e=1;e<=O;e++){const s=(t-e)*i+a,m=(t+e-1)*i+a;r+=R[s],n+=T[s],o+=P[s],h+=R[m],l+=T[m],c+=P[m]}const m=(Math.abs(r-h)+Math.abs(n-l)+Math.abs(o-c))/O;e+=m,s+=m>.12?1:0}const o=Math.max(2,Math.round(.15*a)),h=Math.max(0,t-o),l=Math.min(a,t+o);for(let e=h;e<t;e++)r+=L[e];for(let e=t;e<l;e++)n+=L[e];r/=t-h,n/=l-t;const c=At(-.05,.3,(n-r)/(n+r+1e-4)),m=At(.08,.35,e/i)*(s/i)*c;m>X&&(X=m,q=t/a)}const z=At(.15,.45,X),B=s.take(),Y=s.take(),j=s.take();for(let t=0;t<r;t++)B[t]=Math.min(o[t],h[t],l[t]);Ct(B,u,i,a,1),f(B,u,i,a,g);for(let t=0;t<r;t++)Y[t]=k[t]+A[t];let G=0,H=0,W=0;for(let t=0;t<r;t++)G+=R[t],H+=T[t],W+=P[t];G/=r,H/=r,W/=r;const V=d(R,g),K=d(T,g),J=d(P,g),Q=d(R,M),Z=d(T,M),_=d(P,M);for(let t=0;t<r;t++){const e=Math.hypot(V[t]-G,K[t]-H,J[t]-W),i=Math.hypot(V[t]-Q[t],K[t]-Z[t],J[t]-_[t]);j[t]=(e+1.5*i)*(.4+.6*I[t]*U+.4*(1-U))}const $=s.take(),tt=s.take(),et=s.take(),it=s.take(),at=s.take(),st=s.take(),rt=s.take(),nt=s.take(),ot=s.take(),ht=s.take();for(let t=0;t<a;t++)for(let e=0;e<i;e++)ht[t*i+e]=Math.abs(c[Math.min(a-1,t+1)*i+e]-c[Math.max(0,t-1)*i+e]);f(ht,u,i,a,1);for(let t=0;t<a;t++)for(let e=0;e<i;e++){const s=t*i+e,r=(t+.5)/a,n=C[s],o=I[s]*U,h=D[s],l=w[s]+k[s],c=At(175,200,n)*(1-At(250,275,n))*At(.08,.25,o),m=(1-At(45,65,n)+At(290,330,n))*At(.2,.45,o)*At(.3,.55,h),u=(1-At(.15,.35,o))*At(.45,.7,h)*z,f=(1-At(.08,.2,h))*z,d=z>.3?1-At(q,q+.1,r):1-At(.4,.8,r),p=1-At(.02,.06,l),g=1-At(.03,.09,l);tt[s]=Math.max(c*p,.7*f*(1-At(.008,.025,l)),m*g*.9)*d,et[s]=Math.max(tt[s],u*p*d),$[s]=0===t?tt[s]:0,it[s]=At(150,172,n)*(1-At(232,250,n))*At(.25,.45,o),rt[s]=At(1.3,2.2,(S[s]+.004)/(F[s]+.004))*At(.35,.55,v[s])*(1-At(.1,.18,I[s]*U))*At(.025,.07,l)*At(.025,.045,ht[s]);const M=1-At(.18,.4,o),x=At(.55,.8,h)*At(.05,.12,l);at[s]=Math.max(it[s],.85*M,.8*x)}Pt($,tt,i,a,.995,1),Pt($,et,i,a,.8,1);let lt=0;for(let t=0;t<r;t++)lt+=$[t];const ct=lt>.04*r&&z>.3;if(ct)for(let t=0;t<a;t++)for(let e=0;e<i;e++)it[t*i+e]*=At(q,q+.05,(t+.5)/a);if(ct){const t=s.take(),e=s.take(),n=s.take();for(let e=0;e<r;e++)t[e]=.299*V[e]+.587*K[e]+.114*J[e];for(let t=0;t<a;t++)for(let s=0;s<i;s++)e[t*i+s]=v[Math.min(a-1,t+1)*i+s]-v[Math.max(0,t-1)*i+s];const o=new Uint8Array(r);for(let t=1;t<a-1;t++)for(let s=0;s<i;s++){const r=Math.abs(e[t*i+s]);let n=r>.03;for(let o=-3;o<=3&&n;o++)o&&t+o>=0&&t+o<a&&Math.abs(e[(t+o)*i+s])>r&&(n=!1);o[t*i+s]=n?1:0}const h=(e,i,a,s=!0)=>{const r=V[i]+K[i]+J[i]+.05,n=V[a]+K[a]+J[a]+.05,o=Math.abs(V[i]/r-V[a]/n)+Math.abs(K[i]/r-K[a]/n)+Math.abs(J[i]/r-J[a]/n),h=Math.min(Math.abs(C[i]-C[a]),360-Math.abs(C[i]-C[a])),l=Math.max(1-At(.1,.25,o),(1-At(15,35,h))*At(.15,.3,Math.min(I[i],I[a]))),c=Math.max(At(2,3,(F[i]+.004)/(S[i]+.004))*At(.015,.04,w[i]+k[i])*At(.4,.55,w[i]/(w[i]+k[i]+1e-4)),1-At(.12,.25,t[i]));return l*(s?c:1)*(1-At(.82*t[a]+.02,1.02*t[a]+.05,t[i]))};let l=0,c=0;for(let t=Math.max(3,Math.round(a*Math.max(.25,q)));t<Math.round(.88*a);t++){let e=0;for(let a=0;a<i;a++)(o[(t-1)*i+a]||o[t*i+a]||o[(t+1)*i+a])&&e++;if(e<.5*i)continue;let s=0;for(let e=t+1;e<Math.min(a,2*t);e++)for(let a=0;a<i;a++)s+=h(t,e*i+a,(2*t-e)*i+a);s>c&&(c=s,l=t)}const m=At(.05,.1,c/r);if(m>0)for(let t=l+1;t<Math.min(a,2*l);t++)for(let e=0;e<i;e++){const a=t*i+e;nt[a]=h(l,a,(2*l-t)*i+e)*m,ot[a]=h(l,a,(2*l-t)*i+e,!1)*m,n[a]=nt[a]}f(n,u,i,a,1);for(let t=0;t<r;t++)nt[t]=Math.max(nt[t],n[t]),it[t]=Math.max(it[t],nt[t])}const mt=d(it,M);for(let t=0;t<r;t++)it[t]*=At(.15,.35,mt[t]);const ut=d(it,g);for(let t=0;t<r;t++){it[t]*=1-.8*tt[t];const e=Math.min(Math.abs(C[t]-200),360-Math.abs(C[t]-200));st[t]=At(.28,.45,I[t]*U)*At(55,80,e)*(1-At(.3,.6,ot[t]))}const ft=d(st,g);for(let t=0;t<r;t++)st[t]=Math.max(st[t]*(1-(1-At(.15,.3,ft[t]))*At(.55,.7,D[t])*At(.5,.65,I[t])),1-m[t]),at[t]=Math.min(Math.max(at[t],.9*ot[t]),Math.max(it[t],At(.25,.6,ut[t])))*(1-$[t])*(1-st[t]);Pt(it,at,i,a,.97);const dt=s.take(rt),pt=Math.max(2,Math.round(.12*a));for(let t=0;t<i;t++){let e=0;for(let s=-pt;s<=pt;s++)e+=rt[Math.max(0,Math.min(a-1,s))*i+t];for(let s=0;s<a;s++)dt[s*i+t]=e/(2*pt+1),e+=rt[Math.min(a-1,s+pt+1)*i+t]-rt[Math.max(0,s-pt)*i+t]}f(dt,u,i,a,1);for(let t=0;t<r;t++)rt[t]=At(.2,.45,dt[t])*At(.2,.5,rt[t]+.5*dt[t])*(1-$[t]);Tt($,c,i,a,Math.max(2,Math.round(.04*n)),.002,s),Tt(it,c,i,a,Math.max(2,Math.round(.04*n)),.002,s),Tt(rt,c,i,a,Math.max(2,Math.round(.03*n)),.002,s),f(st,u,i,a,1);for(let t=0;t<r;t++)$[t]=At(.3,.7,$[t])*m[t],rt[t]=At(.3,.7,rt[t])*m[t]*(1-$[t]),it[t]=At(.3,.7,it[t])*(1-$[t])*(1-rt[t])*(1-At(.15,.4,st[t]));Ct($,u,i,a,2),Ct(it,u,i,a,2),Ct(rt,u,i,a,1),f($,u,i,a,1),f(it,u,i,a,1),f(rt,u,i,a,1);const gt=1/Math.max(.02,St(j,.97)),Mt=1/Math.max(.01,St(Y,.9)),xt=St(B,.97),vt=St(B,.1),yt=At(.06,.25,xt-vt),bt=s.take();for(let t=0;t<a;t++)for(let e=0;e<i;e++){const s=t*i+e,r=(e+.5)/i,n=(t+.5)/a,o=Math.max($[s],it[s]),h=w[s]+k[s]+A[s],l=.6*kt(((w[s]+.6*k[s])/(h+.004)-.25)/.55)+.4*kt((w[s]+k[s])/E),c=At(.04,.35,h/E)*(1-o),m=.55*kt((B[s]-vt)/Math.max(.05,xt-vt))+.25*(1-kt(Y[s]*Mt))+.2*kt(2*(P[s]-R[s])+.3)*U,u=yt*At(.12,.35,y[s])*(.4+.6*z),f=z*(n<q?.45:.45+.55*At(0,1,(n-q)/Math.max(.15,1-q)))+(1-z)*(.5+.4*(n-.5)),d=w[s]/(w[s]+k[s]+1e-4),p=At(.2,.7,(w[s]+k[s])/E)*(.35+.65*z)*(1-o),g=1-kt(1.5*Math.hypot(1.2*(r-.5),n-.52)),M=kt(j[s]*gt)*(.55+.45*g),x=.3*c,v=.25*u,b=.12+.45*z,S=.12*p,F=.35*(1-.4*z)*(1-o);bt[s]=(x*l+v*(1-m)+b*f+S*kt(1.6-1.6*d)+F*M+.04)/(x+v+b+S+F+.08)*(1-.85*$[s])*(1-.45*it[s]*(1-z))}const wt=p(t,i,a);if("none"!==wt.key)for(let t=0;t<r;t++)bt[t]=.7*wt.subject[t]+.3*bt[t];return f(bt,u,i,a,Math.max(1,Math.round(.03*n))),function(t,e,i,a,s,r,n,o,h){const l=s*r,c=h.take(),m=t=>(Rt(t,c,s,r,n),t),u=(t,e)=>{const i=h.take();for(let a=0;a<l;a++)i[a]=t[a]*e[a];return m(i)},f=m(h.take(e)),d=m(h.take(i)),p=m(h.take(a)),g=m(h.take(t)),M=u(e,e),x=u(e,i),v=u(e,a),y=u(i,i),b=u(i,a),w=u(a,a),k=u(e,t),A=u(i,t),S=u(a,t),F=h.take(),E=h.take(),R=h.take(),T=h.take();for(let t=0;t<l;t++){const e=k[t]-f[t]*g[t],i=A[t]-d[t]*g[t],a=S[t]-p[t]*g[t],s=M[t]-f[t]*f[t]+o,r=x[t]-f[t]*d[t],n=v[t]-f[t]*p[t],h=y[t]-d[t]*d[t]+o,l=b[t]-d[t]*p[t],c=w[t]-p[t]*p[t]+o,m=h*c-l*l,u=n*l-r*c,P=r*l-n*h,C=s*c-n*n,I=r*n-s*l,D=s*h-r*r,N=s*m+r*u+n*P,U=Math.abs(N)>1e-12?1/N:0;F[t]=(m*e+u*i+P*a)*U,E[t]=(u*e+C*i+I*a)*U,R[t]=(P*e+I*i+D*a)*U,T[t]=g[t]-F[t]*f[t]-E[t]*d[t]-R[t]*p[t]}m(F),m(E),m(R),m(T);for(let s=0;s<l;s++)t[s]=F[s]*e[s]+E[s]*i[s]+R[s]*a[s]+T[s]}(bt,R,T,P,i,a,Math.max(2,Math.round(.07*n)),.004,s),{depth:bt,water:it,sky:$,falls:rt}}function Dt(t,e,i,a,s,r,n){if(e===r&&i===n)return t[s*r+a];const o=Math.max(0,Math.min(e-1,(a+.5)*e/r-.5)),h=Math.max(0,Math.min(i-1,(s+.5)*i/n-.5)),l=Math.min(e-2,Math.floor(o)),c=Math.min(i-2,Math.floor(h)),m=o-l,u=h-c;if(l<0||c<0)return t[Math.round(h)*e+Math.round(o)];const f=c*e+l,d=f+e;return(t[f]*(1-m)+t[f+1]*m)*(1-u)+(t[d]*(1-m)+t[d+1]*m)*u}var Nt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Ut="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",Ot=new Uint16Array(4096);for(let t=0;t<Ot.length;t++)Ot[t]=Nt.indexOf(Ut[2*t])<<6|Nt.indexOf(Ut[2*t+1]);var Lt=(t,e)=>{const i=43758.5453*Math.sin(127.1*t+311.7*e);return i-Math.floor(i)};var qt=new Map([2,4,8,16].map(t=>[t,Float64Array.from({length:t*t},(e,i)=>function(t,e,i){let a=0;for(let s=1;s<i;s*=2){const i=(Math.floor(t/s)%2+2)%2;a=4*a+[[0,2],[3,1]][(Math.floor(e/s)%2+2)%2][i]}return(a+.5)/(i*i)-.5}(i%t,Math.floor(i/t),t))])),Xt={"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,.25],[2,0,4/32],[-2,1,2/32],[-1,1,4/32],[0,1,.25],[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]]},zt=t=>[parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16)];function Bt(t,e,i){const a=Math.min(t*Math.max(1,i),(1-t)*Math.max(1,i),e*Math.max(1,1/i),(1-e)*Math.max(1,1/i)),s=Math.max(0,Math.min(1,(a-.035)/.105));return s*s*s*(s*(6*s-15)+10)}var Yt=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,i,a){if(!Number.isFinite(t+e+i))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e));const s=Number.isFinite(a)?a/1e3:this.clock,r=this.previous;if(this.previous={x:t,y:e,time:s},!r)return;const n=this.width/this.height,o=Math.hypot((t-r.x)*Math.max(1,n),(e-r.y)*Math.max(1,1/n));if(o<1e-4||this.clock-this.lastRing<1/24)return;const h=o/Math.max(1/240,Math.min(.1,s-r.time||1/60)),l=5*this.slot;this.slot=(this.slot+1)%8,this.rings[l]=t,this.rings[l+1]=e,this.rings[l+2]=0,this.rings[l+3]=Math.min(.9,.26+.2*h),this.rings[l+4]=.035+.13*Math.max(.1,Math.min(1,i)),this.alive=!0,this.lastRing=this.clock}step(t){if(!Number.isFinite(t)||t<=0)return;const e=Math.min(.05,t);if(this.clock+=e,!this.alive)return;this.values.fill(0),this.alive=!1;const i=this.width/this.height,a=Math.max(1,i),s=Math.max(1,1/i);for(let t=0;t<this.rings.length;t+=5){if(!this.rings[t+3])continue;const i=this.rings[t+2]+=e;if(i>2.8){this.rings[t+3]=0;continue}this.alive=!0;const r=this.rings[t+4],n=.17*i,o=this.rings[t+3]*(1-Math.exp(20*-i))*Math.exp(2.5*-i),h=n+1.8*r,l=this.rings[t],c=this.rings[t+1],m=Math.max(0,Math.floor((l-h/a)*(this.width-1))),u=Math.min(this.width-1,Math.ceil((l+h/a)*(this.width-1))),f=Math.max(0,Math.floor((c-h/s)*(this.height-1))),d=Math.min(this.height-1,Math.ceil((c+h/s)*(this.height-1)));for(let t=f;t<=d;t++)for(let e=m;e<=u;e++){const i=(Math.hypot((e/(this.width-1)-l)*a,(t/(this.height-1)-c)*s)-n)/r;Math.abs(i)>1.8||(this.values[t*this.width+e]+=o*Math.cos(i*Math.PI*2)*Math.exp(-i*i*2.5))}}for(let t=0;t<this.height;t++)for(let e=0;e<this.width;e++){const a=t*this.width+e,s=this.values[a]=Math.max(-1,Math.min(1,this.values[a]))*(this.edgeSafe?Bt(e/(this.width-1),t/(this.height-1),i):1),r=Math.round(32767*s+32768);this.pixels[4*a]=r>>>8,this.pixels[4*a+1]=255&r}}sample(t,e,i){const a=Math.max(0,Math.min(this.width-1.001,t*(this.width-1))),s=Math.max(0,Math.min(this.height-1.001,e*(this.height-1))),r=Math.floor(a),n=Math.floor(s),o=a-r,h=s-n,l=n*this.width+r,c=l+this.width;i[0]=i[1]=0,i[2]=3*((this.values[l]*(1-o)+this.values[l+1]*o)*(1-h)+(this.values[c]*(1-o)+this.values[c+1]*o)*h)}},jt=t=>["dissolve","silk","vortex","magnetic","scatter","etch","elastic","lens","smudge"].includes(t),Gt=t=>"elastic"===t||"scatter"===t,Ht={elastic:[150,4.2],scatter:[90,3.6]},Wt=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;const i=t*e;this.pixels=new Uint8Array(4*i),this.ink=new Float32Array(i),this.targetX=new Float32Array(i),this.targetY=new Float32Array(i),this.offsetX=new Float32Array(i),this.offsetY=new Float32Array(i),this.edge=new Float32Array(i);for(let i=0;i<e;i++)for(let a=0;a<t;a++)this.edge[i*t+a]=Bt(a/(t-1),i/(e-1),t/e);this.clear()}get active(){return this.peak>2e-4}setMode(t){if(Gt(t)&&!this.springX&&(this.springX=new Float32Array(this.ink.length),this.springY=new Float32Array(this.ink.length)),"scatter"===t&&!this.scatterDirections){const t=this.scatterDirections=new Float64Array(this.width*this.height*2),e=(t,e)=>{const i=43758.5453*Math.sin(127.1*t+311.7*e);return i-Math.floor(i)};for(let i=0;i<this.height;i++)for(let a=0;a<this.width;a++){const s=.09*a,r=.09*i,n=Math.floor(s),o=Math.floor(r),h=s-n,l=r-o,c=h*h*(3-2*h),m=l*l*(3-2*l),u=((e(n,o)*(1-c)+e(n+1,o)*c)*(1-m)+(e(n,o+1)*(1-c)+e(n+1,o+1)*c)*m)*Math.PI*4,f=2*(i*this.width+a);t[f]=.7*Math.cos(u),t[f+1]=.7*Math.sin(u)}}t!==this.mode&&(this.mode=t,this.clear())}clear(){for(const 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),"dissolve"!==this.mode)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,i){if(!Number.isFinite(t+e+i))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e));const a=this.previous;this.previous={x:t,y:e};const s=this.width,r=this.height,n=Math.max(1,s/r),o=Math.max(1,r/s),h=a?(t-a.x)*n:0,l=a?(e-a.y)*o:0,c=Math.hypot(h,l);if(!a&&"dissolve"!==this.mode&&"etch"!==this.mode&&"lens"!==this.mode)return;if(a&&c<1e-4)return;const m=.035+.11*Math.max(.1,Math.min(1,i)),u=Math.min(128,Math.max(1,Math.ceil(c/(.45*m)))),f=c?h/c:1,d=c?l/c:0,p=a||"lens"!==this.mode?Math.min(1,c/(m*u)*2.2):.32;for(let i=0;i<u;i++){const h=(i+.5)/u,l=a?a.x+(t-a.x)*h:t,c=a?a.y+(e-a.y)*h:e,g=Math.max(0,Math.floor((l-2.5*m/n)*(s-1))),M=Math.min(s-1,Math.ceil((l+2.5*m/n)*(s-1))),x=Math.max(0,Math.floor((c-2.5*m/o)*(r-1))),v=Math.min(r-1,Math.ceil((c+2.5*m/o)*(r-1)));for(let t=x;t<=v;t++)for(let e=g;e<=M;e++){const i=(e/(s-1)-l)*n/m,a=(t/(r-1)-c)*o/m,h=Math.exp(1.5*-(i*i+a*a)),u=t*s+e;if("dissolve"===this.mode||"etch"===this.mode)this.ink[u]=Math.max(this.ink[u],h);else if("elastic"===this.mode)this.springX[u]=Math.max(-24,Math.min(24,this.springX[u]+f*h*p*12)),this.springY[u]=Math.max(-24,Math.min(24,this.springY[u]+d*h*p*12));else if("scatter"===this.mode){const t=this.scatterDirections;this.springX[u]=Math.max(-24,Math.min(24,this.springX[u]+(.6*i+t[2*u])*h*p*7)),this.springY[u]=Math.max(-24,Math.min(24,this.springY[u]+(.6*a+t[2*u+1])*h*p*7))}else if("lens"===this.mode)this.targetX[u]=Math.max(-.65,Math.min(.65,this.targetX[u]+i*h*p*1.6)),this.targetY[u]=Math.max(-.65,Math.min(.65,this.targetY[u]+a*h*p*1.6));else if("smudge"===this.mode)this.targetX[u]=Math.max(-1,Math.min(1,this.targetX[u]+f*h*p*1.3)),this.targetY[u]=Math.max(-1,Math.min(1,this.targetY[u]+d*h*p*1.3));else{const t=(-i*d+a*f)*h*2.8,e="magnetic"===this.mode?-i*h*2.5:"silk"===this.mode?f*t:-a*h*2.5,s="magnetic"===this.mode?-a*h*2.5:"silk"===this.mode?d*t:i*h*2.5;this.targetX[u]=Math.max(-1,Math.min(1,this.targetX[u]+e*p)),this.targetY[u]=Math.max(-1,Math.min(1,this.targetY[u]+s*p))}}}this.peak=1}step(t){if(!this.active||!Number.isFinite(t))return;const e=Math.max(0,Math.min(.05,t)),i="dissolve"===this.mode?2.15:"smudge"===this.mode?2.4:3.2,a="lens"===this.mode?16:22,s=Math.exp(-i*e),r=1-Math.exp(-a*e);let n=0;const[o,h]="scatter"===this.mode?Ht.scatter:Ht.elastic,l=Math.sqrt(o-h*h),c=Math.exp(-h*e),m=Math.cos(l*e),u=Math.sin(l*e)/l;for(let t=0;t<this.ink.length;t++)if("etch"===this.mode)this.ink[t]*=s,n=Math.max(n,this.ink[t]);else if("dissolve"===this.mode){this.ink[t]*=s,n=Math.max(n,this.ink[t]);const e=Math.round(65535*this.ink[t]);this.pixels[4*t]=e>>>8,this.pixels[4*t+1]=255&e}else{if(Gt(this.mode)){const e=this.offsetX[t],i=this.offsetY[t],a=this.springX[t],s=this.springY[t];this.offsetX[t]=Math.max(-1,Math.min(1,c*(e*m+(a+h*e)*u))),this.offsetY[t]=Math.max(-1,Math.min(1,c*(i*m+(s+h*i)*u))),this.springX[t]=c*(a*m-(h*a+o*e)*u),this.springY[t]=c*(s*m-(h*s+o*i)*u),n=Math.max(n,.05*Math.abs(this.springX[t]),.05*Math.abs(this.springY[t]))}else if("lens"===this.mode||"smudge"===this.mode){const e=1-r,n=a/(a-i)*(s-e);this.offsetX[t]=this.offsetX[t]*e+this.targetX[t]*n,this.offsetY[t]=this.offsetY[t]*e+this.targetY[t]*n,this.targetX[t]*=s,this.targetY[t]*=s}else this.targetX[t]*=s,this.targetY[t]*=s,this.offsetX[t]+=(this.targetX[t]-this.offsetX[t])*r,this.offsetY[t]+=(this.targetY[t]-this.offsetY[t])*r;n=Math.max(n,Math.abs(this.offsetX[t]),Math.abs(this.offsetY[t]),Math.abs(this.targetX[t]),Math.abs(this.targetY[t]));const e=Math.round(this.offsetX[t]*(this.edgeSafe?this.edge[t]:1)*32767+32768),l=Math.round(this.offsetY[t]*(this.edgeSafe?this.edge[t]:1)*32767+32768);this.pixels[4*t]=e>>>8,this.pixels[4*t+1]=255&e,this.pixels[4*t+2]=l>>>8,this.pixels[4*t+3]=255&l}if("etch"===this.mode)for(let t=0;t<this.height;t++)for(let e=0;e<this.width;e++){const i=t*this.width+e,a=3*(this.ink[t*this.width+Math.max(0,e-1)]-this.ink[t*this.width+Math.min(this.width-1,e+1)]+this.ink[Math.max(0,t-1)*this.width+e]-this.ink[Math.min(this.height-1,t+1)*this.width+e]);this.offsetX[i]=Math.max(-1,Math.min(1,a))*(this.edgeSafe?this.edge[i]:1);const s=Math.round(32767*this.offsetX[i]+32768);this.pixels[4*i]=s>>>8,this.pixels[4*i+1]=255&s}this.peak=n,this.active||this.clear()}sample(t,e,i){const a=Math.max(0,Math.min(this.width-1.001,t*(this.width-1))),s=Math.max(0,Math.min(this.height-1.001,e*(this.height-1))),r=Math.floor(a),n=Math.floor(s),o=a-r,h=s-n,l=n*this.width+r,c=l+this.width,m=t=>(t[l]*(1-o)+t[l+1]*o)*(1-h)+(t[c]*(1-o)+t[c+1]*o)*h;if("etch"===this.mode)return i[0]=i[1]=0,void(i[2]=3*m(this.offsetX));i[0]=m(this.offsetX)*(this.edgeSafe?Bt(t,e,this.width/this.height):1)*.08,i[1]=m(this.offsetY)*(this.edgeSafe?Bt(t,e,this.width/this.height):1)*.08,i[2]="dissolve"===this.mode?6*-m(this.ink):0}},Vt=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,i){const a=Math.max(1,this.width/this.height),s=Math.max(1,this.height/this.width);this.previous&&(Math.hypot((t-this.previous.x)*a,(e-this.previous.y)*s)<.065||this.elapsed<.3)||4!==this.rings.length&&(this.previous={x:t,y:e},this.elapsed=0,this.rings.push({x:t,y:e,age:0,radius:i}))}ringSample(t,e){const i=Math.max(1,this.width/this.height),a=Math.max(1,this.height/this.width);let s=0;for(const r of this.rings){const n=.015+r.age*(.15+.22*r.radius),o=.009+.014*r.radius,h=(Math.hypot((t-r.x)*i,(e-r.y)*a)-n)/o,l=Math.sin(Math.min(1,r.age/.07)*Math.PI/2)*Math.max(0,1-r.age/1.35)**2;s=Math.max(s,Math.exp(-h*h)*l)}return s}sample(t,e){const i=Math.max(0,Math.min(this.width-1,Math.round(t*(this.width-1)))),a=Math.max(0,Math.min(this.height-1,Math.round(e*(this.height-1))));return Math.max(this.ringSample(t,e),this.echo[a*this.width+i])}step(t){if(!Number.isFinite(t))return;const e=Math.max(0,Math.min(.05,t));this.elapsed+=e;for(const t of this.rings)t.age+=e;if(this.rings=this.rings.filter(t=>t.age<1.35),!this.active)return void this.pixels.fill(0);const i=Math.exp(-5.5*e);let a=0;for(let t=0;t<this.height;t++)for(let e=0;e<this.width;e++){const s=t*this.width+e;this.echo[s]=Math.max(this.ringSample(e/(this.width-1),t/(this.height-1)),this.echo[s]*i),a=Math.max(a,this.echo[s]);const r=Math.round(65535*this.echo[s]),n=4*s;this.pixels[n]=r>>>8,this.pixels[n+1]=255&r}this.echoPeak=a,this.active||(this.echo.fill(0),this.pixels.fill(0))}},Kt=class{constructor(t,e,i){this.previous=null,this.peak=0,this.width=t,this.height=e,this.span=i??Math.min(t,e);const a=t*e;this.pixels=new Uint8Array(4*a),this.signal=new Float32Array(a),this.offsetX=new Float32Array(a),this.offsetY=new Float32Array(a),this.driftX=new Float32Array(a),this.driftY=new Float32Array(a),this.u=new Float32Array(a),this.v=new Float32Array(a),this.ink=new Float32Array(a),this.a=new Float32Array(a),this.b=new Float32Array(a),this.c=new Float32Array(a),this.pressure=new Float32Array(a),this.pressureNext=new Float32Array(a),this.divergence=new Float32Array(a),this.curl=new Float32Array(a)}get active(){return this.peak>2e-4}clear(){for(const 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,i,a=performance.now()){if(!Number.isFinite(t+e+i+a))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e)),i=Math.max(.1,Math.min(1,i));const s=this.previous;if(this.previous={x:t,y:e,time:a},!s)return;const r=(t-s.x)*(this.width-1),n=(e-s.y)*(this.height-1),o=Math.hypot(r,n);if(o<.001)return;const h=this.span,l=a>s.time?Math.max(1/240,(a-s.time)/1e3):1/60,c=Math.min(12,o/h/l),m=1-Math.exp(-c/2.2),u=h*(.022+.075*i)*(.65+.95*m),f=Math.min(128,Math.max(1,Math.ceil(o/(.4*u)))),d=o/u*(.32+.22*m)/f,p=r/o,g=n/o,M=-g,x=p,v=o*(2+18*m)/f;for(let i=0;i<f;i++){const a=(i+.5)/f,r=(s.x+(t-s.x)*a)*(this.width-1),n=(s.y+(e-s.y)*a)*(this.height-1),o=Math.max(1,Math.floor(r-3*u)),h=Math.min(this.width-2,Math.ceil(r+3*u)),l=Math.max(1,Math.floor(n-3*u)),c=Math.min(this.height-2,Math.ceil(n+3*u));for(let t=l;t<=c;t++)for(let e=o;e<=h;e++){const i=((e-r)*p+(t-n)*g)/u,a=((e-r)*M+(t-n)*x)/u,s=Math.exp(-i*i*.65-a*a*1.7),o=t*this.width+e;this.ink[o]=1-(1-this.ink[o])*Math.exp(-s*d);const h=1-a*a*.55,l=i*a*.7;this.u[o]=Math.max(-80,Math.min(80,this.u[o]+(p*h+M*l)*s*v)),this.v[o]=Math.max(-80,Math.min(80,this.v[o]+(g*h+x*l)*s*v))}}this.peak=1}read(t,e,i){const a=0|(e=Math.max(.5,Math.min(this.width-1.5,e))),s=0|(i=Math.max(.5,Math.min(this.height-1.5,i))),r=e-a,n=i-s,o=s*this.width+a;return(t[o]*(1-r)+t[o+1]*r)*(1-n)+(t[o+this.width]*(1-r)+t[o+this.width+1]*r)*n}sample(t,e){return this.read(this.signal,t*(this.width-1),e*(this.height-1))}displacement(t,e,i){i[0]=this.read(this.offsetX,t*(this.width-1),e*(this.height-1)),i[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));const i=this.width,a=this.height;for(;e>1e-7;){const t=Math.min(1/60,e);e-=t;const s=Math.exp(-1.9*t),r=Math.exp(-3.2*t);for(let e=1;e<a-1;e++)for(let n=1;n<i-1;n++){const o=e*i+n,h=Math.max(.5,Math.min(i-1.5,n-this.u[o]*t)),l=Math.max(.5,Math.min(a-1.5,e-this.v[o]*t)),c=0|h,m=0|l,u=h-c,f=l-m,d=m*i+c,p=(1-u)*(1-f),g=u*(1-f),M=(1-u)*f,x=u*f;this.a[o]=(this.u[d]*p+this.u[d+1]*g+this.u[d+i]*M+this.u[d+i+1]*x)*s,this.b[o]=(this.v[d]*p+this.v[d+1]*g+this.v[d+i]*M+this.v[d+i+1]*x)*s,this.c[o]=(this.ink[d]*p+this.ink[d+1]*g+this.ink[d+i]*M+this.ink[d+i+1]*x)*r}[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 t=1;t<a-1;t++)for(let e=1;e<i-1;e++){const a=t*i+e;this.curl[a]=.5*(this.v[a+1]-this.v[a-1]-this.u[a+i]+this.u[a-i])}for(let e=1;e<a-1;e++)for(let a=1;a<i-1;a++){const s=e*i+a,r=Math.abs(this.curl[s+1])-Math.abs(this.curl[s-1]),n=Math.abs(this.curl[s+i])-Math.abs(this.curl[s-i]),o=Math.hypot(r,n)+1e-4,h=this.curl[s]*t*10,l=Math.hypot(this.u[s],this.v[s]);this.u[s]+=n/o*h,this.v[s]-=r/o*h;const c=Math.min(1,l/(Math.hypot(this.u[s],this.v[s])+1e-6));this.u[s]*=c,this.v[s]*=c,this.divergence[s]=-.5*(this.u[s+1]-this.u[s-1]+this.v[s+i]-this.v[s-i])}this.pressure.fill(0);for(let t=0;t<4;t++){for(let t=1;t<a-1;t++)for(let e=1;e<i-1;e++){const a=t*i+e;this.pressureNext[a]=.25*(this.divergence[a]+this.pressure[a-1]+this.pressure[a+1]+this.pressure[a-i]+this.pressure[a+i])}[this.pressure,this.pressureNext]=[this.pressureNext,this.pressure]}let n=0;for(let e=1;e<a-1;e++)for(let a=1;a<i-1;a++){const s=e*i+a;this.u[s]=Math.max(-80,Math.min(80,this.u[s]-.5*(this.pressure[s+1]-this.pressure[s-1]))),this.v[s]=Math.max(-80,Math.min(80,this.v[s]-.5*(this.pressure[s+i]-this.pressure[s-i]))),this.driftX[s]+=(3.6*this.u[s]-58*this.offsetX[s]-12*this.driftX[s])*t,this.driftY[s]+=(3.6*this.v[s]-58*this.offsetY[s]-12*this.driftY[s])*t,this.offsetX[s]=Math.max(-2,Math.min(2,this.offsetX[s]+this.driftX[s]*t)),this.offsetY[s]=Math.max(-2,Math.min(2,this.offsetY[s]+this.driftY[s]*t)),this.signal[s]=1-Math.exp(.06*-Math.hypot(this.u[s],this.v[s])-.16*this.ink[s]),n=Math.max(n,this.signal[s])}this.peak=n}if(this.active)for(let t=0;t<this.ink.length;t++){const e=Math.round(65535*Math.min(1,this.signal[t]));this.pixels[4*t]=e>>>8,this.pixels[4*t+1]=255&e,this.pixels[4*t+2]=Math.round(128+63.5*this.offsetX[t]),this.pixels[4*t+3]=Math.round(128+63.5*this.offsetY[t])}else this.clear()}};var Jt=["loupe","repel","tilt","reveal","haze","bleed"],Qt=t=>Jt.includes(t),Zt=class{constructor(){this.value=0,this.velocity=0}step(t,e,i,a){const s=2*Math.sqrt(i)*a;for(let a=e;a>1e-6;a-=1/480){const e=Math.min(1/480,a);this.velocity+=((t-this.value)*i-this.velocity*s)*e,this.value+=this.velocity*e}}resting(t){return Math.abs(this.value-t)<.0015&&Math.abs(this.velocity)<.01}set(t){this.value=t,this.velocity=0}},_t=t=>t*t*(3-2*t),$t=(t,e)=>{const i=43758.5453*Math.sin(127.1*t+311.7*e);return i-Math.floor(i)};function te(t,e){const i=Math.floor(t),a=Math.floor(e),s=_t(t-i),r=_t(e-a),n=$t(i,a),o=$t(i+1,a),h=$t(i,a+1);return(n+(o-n)*s)*(1-r)+(h+($t(i+1,a+1)-h)*s)*r}var ee=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 Zt,this.y=new Zt,this.tx=new Zt,this.ty=new Zt,this.presence=new Zt,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(),"bleed"===t&&!this.ink)){const t=this.width*this.height;this.ink=new Float32Array(t),this.next=new Float32Array(t),this.fiber=new Float32Array(t);for(let t=0;t<this.height;t++)for(let e=0;e<this.width;e++)this.fiber[t*this.width+e]=.35+.5*te(.09*e,.045*t)+.15*$t(e,t)}}setRadius(t){this.radius=Math.max(.1,Math.min(1,t))}get reach(){return(.05+.25*this.radius)*("loupe"===this.mode?1-.14*this.speed: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(){const 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||"haze"===this.mode&&this.presence.value>.002||this.inkPeak>.002}tiltGoal(t){return this.target&&"tilt"===this.mode?2*((t?this.target.y:this.target.x)-.5):0}clear(){for(const 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,i){if(!Number.isFinite(t+e))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e));const a=Number.isFinite(i)?i/1e3:this.clock,s=this.target;if(!s&&this.presence.value<.05&&(this.x.set(t),this.y.set(e)),s){const i=Math.hypot((t-s.x)*this.sx,(e-s.y)*this.sy),r=i/Math.max(1/240,Math.min(.1,a-s.time||1/60));this.speed=Math.max(this.speed,Math.min(1,r/1.6)),"bleed"===this.mode&&this.deposit(s.x,s.y,t,e,Math.min(1,9*i))}else"bleed"===this.mode&&this.deposit(t,e,t,e,.5);this.target={x:t,y:e,time:a}}leave(){this.target=null}deposit(t,e,i,a,s){const r=this.ink,n=this.width,o=this.height,h=.55*this.reach,l=Math.hypot((i-t)*this.sx,(a-e)*this.sy),c=Math.min(48,Math.max(1,Math.ceil(l/(.5*h))));for(let l=0;l<c;l++){const m=(l+.5)/c,u=t+(i-t)*m,f=e+(a-e)*m,d=Math.max(0,Math.floor((u-2*h/this.sx)*(n-1))),p=Math.min(n-1,Math.ceil((u+2*h/this.sx)*(n-1))),g=Math.max(0,Math.floor((f-2*h/this.sy)*(o-1))),M=Math.min(o-1,Math.ceil((f+2*h/this.sy)*(o-1)));for(let t=g;t<=M;t++)for(let e=d;e<=p;e++){const i=(e/(n-1)-u)*this.sx/h,a=(t/(o-1)-f)*this.sy/h,l=t*n+e;r[l]=Math.min(1.4,r[l]+Math.exp(1.8*-(i*i+a*a))*s/c*1.6)}}this.inkPeak=Math.max(this.inkPeak,.01)}step(t){if(!Number.isFinite(t)||t<=0)return;const e=Math.min(.05,t),i=e*this.settle;this.clock+=e;const a=this.target,s=this.mode;if(a?this.presence.step(1,e,190,1):this.presence.step(0,i,"repel"===s?120:70,"repel"===s?.42:1),a){const t="tilt"===s?60:"haze"===s?90:240,i="loupe"===s||"repel"===s?.72:.9;this.x.step(a.x,e,t,i),this.y.step(a.y,e,t,i)}this.tx.step(this.tiltGoal(0),a?e:i,45,.78),this.ty.step(this.tiltGoal(1),a?e:i,45,.78),this.speed*=Math.exp(7*-e),"bleed"===s&&this.spread(e,i,!!a),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,i){const a=this.ink,s=this.next,r=this.fiber,n=this.width,o=this.height;i&&this.target&&this.deposit(this.x.value,this.y.value,this.x.value,this.y.value,.9*t);const h=Math.max(1,Math.ceil(t/(1/240))),l=t/h,c=26*(.4+this.radius),m=(i?.02:.1)*e/t,u=Math.exp(-(i?.15:.9)*e/h);let f=0;for(let t=0;t<h;t++){f=0;for(let t=1;t<o-1;t++)for(let e=1;e<n-1;e++){const i=t*n+e,o=a[i],h=r[i],d=Math.min(h,r[i-1])*(a[i-1]-o)+Math.min(h,r[i+1])*(a[i+1]-o)+Math.min(h,r[i-n])*(a[i-n]-o)+Math.min(h,r[i+n])*(a[i+n]-o),p=Math.max(0,(o+d*Math.min(.24,c*l))*u-m*l);s[i]=p,p>f&&(f=p)}a.set(s)}this.inkPeak=f}sample(t,e,i){i[0]=i[1]=i[2]=0;const a=this.presence.value,s=this.mode;if("bleed"===s){if(this.inkPeak<=.002)return;const a=this.width,s=this.height,r=this.ink,n=Math.max(0,Math.min(a-1.001,t*(a-1))),o=Math.max(0,Math.min(s-1.001,e*(s-1))),h=Math.floor(n),l=Math.floor(o),c=n-h,m=o-l,u=l*a+h,f=u+a,d=(r[u]*(1-c)+r[u+1]*c)*(1-m)+(r[f]*(1-c)+r[f+1]*c)*m;return void(i[2]=1-Math.exp(2.4*-d))}if("tilt"===s){const a=this.guide?function(t,e,i,a){const s=t[e],r=t.width,n=t.height,o=Math.max(0,Math.min(r-1.001,i*(r-1))),h=Math.max(0,Math.min(n-1.001,a*(n-1))),l=Math.floor(o),c=Math.floor(h),m=o-l,u=h-c,f=c*r+l,d=Math.min(n-1,c+1)*r+l,p=l+1<r?1:0;return(s[f]*(1-m)+s[f+p]*m)*(1-u)+(s[d]*(1-m)+s[d+p]*m)*u}(this.guide,"depth",t,e):.6,s=.2+.8*a,r=this.edgeSafe?Bt(t,e,this.sx/this.sy):1;return i[0]=.024*this.tx.value*s*r/this.sx,void(i[1]=.024*this.ty.value*s*r/this.sy)}if(a<=.001)return;const r=this.reach,n=(t-this.x.value)*this.sx,o=(e-this.y.value)*this.sy,h=(n*n+o*o)/(r*r);if("reveal"===s)return void(i[2]=Math.exp(2.4*-h)*a);if(h>9)return;const l=this.edgeSafe?Bt(t,e,this.sx/this.sy):1;let c=0,m=0;if("loupe"===s){const t=Math.exp(-h*h)*a*.5;c=n*t,m=o*t;const e=Math.sqrt(h)-1;i[2]=Math.exp(-e*e/.018)*a*.55}else if("repel"===s){const t=Math.sqrt(h),e=.5*r*Math.exp(-h/1.7)*a,s=Math.max(1e-6,Math.sqrt(n*n+o*o));c=n/s*Math.min(e,s+.5*r*a),m=o/s*Math.min(e,s+.5*r*a);const l=Math.max(0,Math.min(1,(t-.3)/.32));i[2]=-(1-l*l*(3-2*l))*a}else if("haze"===s){const s=o/r+.45,h=Math.exp(-n*n/(r*r)-s*s/2.6)*a*(.35+.65*Math.min(1,1.4*this.speed+.25));if(h<.002)return;const l=this.clock,u=t*this.sx*9,f=e*this.sy*9+2.3*l;c=.06*(te(u,f)-.5)*h,m=.026*(te(u+17.3,1.3*f+.7*l)-.5)*h,i[2]=.35*(te(1.7*u+5,1.7*f)-.5)*h}i[0]=c*l/this.sx,i[1]=m*l/this.sy}encode(){const t=this.width,e=this.height,i=this.pixels,a=this.sampled,s=this.engaged;for(let r=0;r<e;r++)for(let n=0;n<t;n++){const o=4*(r*t+n);if(s?this.sample(n/(t-1),r/(e-1),a):a[0]=a[1]=a[2]=0,"bleed"===this.mode){const t=Math.round(32767*Math.max(-1,Math.min(1,a[2]))+32768);i[o]=t>>>8,i[o+1]=255&t,i[o+2]=128,i[o+3]=0}else{"repel"===this.mode&&(a[0]*=.3,a[1]*=.3);const t=Math.round(32767*Math.max(-1,Math.min(1,a[0]/.16))+32768),e=Math.round(32767*Math.max(-1,Math.min(1,a[1]/.16))+32768);i[o]=t>>>8,i[o+1]=255&t,i[o+2]=e>>>8,i[o+3]=255&e}}}},ie=(t,e)=>"water"===t?30*e/.55:"silk"===t?28*e:"vortex"===t?38*e:["magnetic","scatter","elastic","lens","smudge"].includes(t)?32*e:["loupe","repel","tilt","haze"].includes(t)?.16*e/.55:0;function ae(t,e,i,a=!1){if(!i)return e;const s=t=>Math.max(0,Math.min(1,t));switch(t){case"trail":case"contour":return function(t,e){const i=Math.max(0,Math.min(1,e/.38));return t+i*i*(3-2*i)*(1-2*t)}(e,i);case"etch":case"ripple":return s(e+.35*i);case"dissolve":{const t=Math.max(0,1+i);return a?1-(1-e)*t:e*t}case"bleed":return s(e+i*(a?-.6:.6));case"loupe":return s(e+.3*i);case"haze":return s(e+.5*i);default:return e}}var se=t=>["trail","contour","etch","ripple","bleed","haze"].includes(t),re=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(2*this.heights.length),this.edgeMask=new Float32Array(this.heights.length);for(let e=0;e<this.rows;e++)for(let i=0;i<this.columns;i++)this.edgeMask[e*this.columns+i]=Bt(i/(this.columns-1),e/(this.rows-1),t);this.refraction={width:this.columns,height:this.rows,pixels:new Uint8Array(4*this.heights.length),strength:30,mode:"water",focus:[.5,.5,0,.2]},this.waterPixels=this.refraction.pixels,this.trail=new Kt(this.columns,this.rows),this.contour=new Vt(this.columns,this.rows),this.afterimage=new Wt(this.columns,this.rows),this.clear()}get invertsDensity(){return"trail"===this.mode}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 Qt(this.mode)?this.cursor.engaged:this.active}get spotlight(){return"reveal"===this.mode&&this.cursor?this.cursor.focus:null}get signature(){return Qt(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 Qt(this.mode)?this.cursor.active:"ripple"===this.mode?this.ripple?.active??!1:jt(this.mode)?this.afterimage.active:"contour"===this.mode?this.contour.active:"trail"===this.mode?this.trail.active:this.pending||this.energy>15e-5}setMode(t){const e="light"===t||"scan"===t?t:m(t)??"none";e!==this.mode&&(this.clear(),this.mode=e,this.refraction.mode=e,jt(e)&&this.afterimage.setMode(e),"ripple"!==e||this.ripple||(this.ripple=new Yt(this.columns,this.rows)),Qt(e)&&(this.cursor??(this.cursor=new ee(this.columns,this.rows)),this.cursor.guide=this.guide,this.cursor.setMode(e)),this.refraction.pixels=Qt(e)?this.cursor.pixels:"ripple"===e?this.ripple.pixels:"trail"===e?this.trail.pixels:"contour"===e?this.contour.pixels:jt(e)?this.afterimage.pixels:this.waterPixels,this.refraction.strength=ie(e,this.amount),this.refraction.relative=Qt(e))}configure(t,e=.55,i=.2,a=!1,s=.5){this.setMode(t),this.settle=((t=.5)=>Math.pow(2,2.4*(.5-(Number.isFinite(t)?Math.max(0,Math.min(1,t)):.5))))(s),this.refraction.edgeSafe=a,this.afterimage.edgeSafe=a,this.ripple&&(this.ripple.edgeSafe=a),this.amount=Number.isFinite(e)?Math.max(0,Math.min(1,e)):.55,this.radius=Number.isFinite(i)?Math.max(.1,Math.min(1,i)):.2,this.cursor&&(this.cursor.edgeSafe=a,this.cursor.settle=this.settle,this.cursor.setRadius(this.radius)),this.refraction.strength=ie(this.mode,this.amount),this.refraction.focus[2]=this.densityTrail?this.amount:this.lensStrength*this.amount,this.refraction.focus[3]=this.radius,"reveal"!==this.mode&&"repel"!==this.mode||this.syncSpot()}syncSpot(){const t=this.cursor.focus;this.refraction.focus=[t[0],t[1],t[2]*("repel"===this.mode?Math.min(1,this.amount/.55):this.amount),t[3]]}move(t,e,i){if("none"===this.mode||0===this.amount)return;if(!Number.isFinite(t+e))return;if(t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e)),Qt(this.mode))return void this.cursor.move(t,e,i);if("ripple"===this.mode)return void this.ripple.move(t,e,this.radius,i);if(jt(this.mode))return void this.afterimage.move(t,e,this.radius);if("contour"===this.mode)return void this.contour.move(t,e,this.radius);if("trail"===this.mode)return void this.trail.move(t,e,this.radius,i);if("water"!==this.mode)return!this.previous&&this.lensStrength<.001&&(this.lensX=t,this.lensY=e),this.previous={x:t,y:e},void(this.pending=!0);if(!this.previous)return void(this.previous={x:t,y:e});const a=this.previous;this.previous={x:t,y:e};const s=(t-a.x)*this.xScale,r=(e-a.y)*this.yScale,n=Math.hypot(s,r);if(n<1e-5)return;const o=.035+.1*this.radius,h=3*o,l=Math.min(192,Math.max(1,Math.ceil(n/(.5*o)))),c=95*Math.min(n,1)/l;for(let i=0;i<l;i++){const s=(i+.5)/l,r=a.x+(t-a.x)*s,n=a.y+(e-a.y)*s,m=Math.max(1,Math.floor((r-h/this.xScale)*(this.columns-1))),u=Math.min(this.columns-2,Math.ceil((r+h/this.xScale)*(this.columns-1))),f=Math.max(1,Math.floor((n-h/this.yScale)*(this.rows-1))),d=Math.min(this.rows-2,Math.ceil((n+h/this.yScale)*(this.rows-1)));for(let t=f;t<=d;t++)for(let e=m;e<=u;e++){const i=(e/(this.columns-1)-r)*this.xScale,a=(t/(this.rows-1)-n)*this.yScale,s=Math.exp(-(i*i+a*a)/(o*o))*c,h=t*this.columns+e;this.velocity[h]=Math.max(-12,this.velocity[h]-s)}}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,"water"!==this.mode&&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(Qt(this.mode))return this.cursor.step(t),void("reveal"!==this.mode&&"repel"!==this.mode||this.syncSpot());if(t*=this.settle,"ripple"===this.mode)return void this.ripple.step(t);if(jt(this.mode))return void this.afterimage.step(t);if("contour"===this.mode)return void this.contour.step(t);if("trail"===this.mode)return void this.trail.step(t);if("water"!==this.mode)return void this.stepLight(Math.max(0,Math.min(.05,t)));this.remainder+=Math.max(0,Math.min(.05,t));const e=1/120,i=.3*Math.min(this.columns,this.rows);for(;this.remainder+1e-8>=e;){this.remainder-=e,this.quiet+=e;const t=Math.max(0,Math.min(1,(this.quiet-.2)/.6)),a=t*t*(3-2*t),s=Math.exp(-(3.8+3*a)*e),r=Math.exp(7*-a*e);let n=0;for(let t=1;t<this.rows-1;t++)for(let a=1;a<this.columns-1;a++){const o=t*this.columns+a,h=this.heights[o],l=this.heights[o-1]+this.heights[o+1]+this.heights[o-this.columns]+this.heights[o+this.columns]-4*h,c=Math.min(a,t,this.columns-1-a,this.rows-1-t),m=c<5?.88+.024*c:1,u=(this.velocity[o]+(l*i*i-8*h)*e)*s*m;this.velocity[o]=u,this.next[o]=(h+u*e)*m*r,n=Math.max(n,Math.abs(this.next[o]),.1*Math.abs(u))}this.heights.set(this.next),this.energy=n,this.pending=!1}if(!this.active)return void this.clear();const a=.18*Math.min(this.columns,this.rows);for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++){const i=t*this.columns+e,s=(this.heights[t*this.columns+Math.max(0,e-1)]-this.heights[t*this.columns+Math.min(this.columns-1,e+1)])*a,r=(this.heights[Math.max(0,t-1)*this.columns+e]-this.heights[Math.min(this.rows-1,t+1)*this.columns+e])*a,n=Math.tanh(s)*(this.refraction.edgeSafe?this.edgeMask[i]:1),o=Math.tanh(r)*(this.refraction.edgeSafe?this.edgeMask[i]:1);this.normals[2*i]=n,this.normals[2*i+1]=o;const h=Math.round(32767*n+32768),l=Math.round(32767*o+32768);this.refraction.pixels[4*i]=h>>>8,this.refraction.pixels[4*i+1]=255&h,this.refraction.pixels[4*i+2]=l>>>8,this.refraction.pixels[4*i+3]=255&l}}stepLight(t){const e=this.previous,i=1-Math.exp(-30*t),a=1-Math.exp(-12*t);e&&(this.lensX+=(e.x-this.lensX)*i,this.lensY+=(e.y-this.lensY)*i),this.lensStrength+=((e?1:0)-this.lensStrength)*a,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.refraction.focus=[this.lensX,this.lensY,this.lensStrength*this.amount,this.radius]:this.clear()}sample(t,e,i){if(Qt(this.mode))return this.cursor.sample(t,e,i),i[0]*=this.amount/.55,i[1]*=this.amount/.55,void(i[2]*="reveal"===this.mode||"repel"===this.mode?Math.min(1,this.amount/.55):3*this.amount);if("ripple"===this.mode)return this.ripple.sample(t,e,i),void(i[2]*=this.amount);if(jt(this.mode))return this.afterimage.sample(t,e,i),i[0]*=this.amount,i[1]*=this.amount,void(i[2]*=this.amount);if("contour"===this.mode)return i[0]=i[1]=0,void(i[2]=this.contour.sample(t,e)*this.amount*3);if("trail"===this.mode)return i[0]=i[1]=0,void(i[2]=this.trail.sample(t,e)*this.amount*3);const a=Math.max(0,Math.min(this.columns-1.001,t*(this.columns-1))),s=Math.max(0,Math.min(this.rows-1.001,e*(this.rows-1))),r=Math.floor(a),n=Math.floor(s),o=a-r,h=s-n,l=2*(n*this.columns+r),c=l+2*this.columns;for(let t=0;t<2;t++)i[t]=.08*((this.normals[l+t]*(1-o)+this.normals[l+2+t]*o)*(1-h)+(this.normals[c+t]*(1-o)+this.normals[c+2+t]*o)*h);i[0]*=this.amount/.55,i[1]*=this.amount/.55,i[2]="light"===this.mode||"scan"===this.mode?function(t,e,i,a){const[s,r,n,o]=i.focus,h=(t-s)*Math.max(1,a)/o,l=(e-r)*Math.max(1,1/a)/o;return"light"===i.mode?Math.exp(-3*(h*h+l*l))*n:"scan"===i.mode?(1.3*Math.exp(-h*h*110)-.3*Math.exp(-h*h*12))*Math.exp(-l*l*1.8)*n:0}(t,e,this.refraction,this.xScale/this.yScale):0}};function ne(t){return"videoWidth"in t?[t.videoWidth,t.videoHeight]:"naturalWidth"in t?[t.naturalWidth,t.naturalHeight]:[t.width,t.height]}var oe=(t=!1)=>{const e=document.createElement("canvas"),i=e.getContext("2d",{willReadFrequently:t});if(!i)throw new Error("Canvas 2D is unavailable.");return{canvas:e,ctx:i}},he=(t,e,i)=>{t.width===e&&t.height===i||(t.width=e,t.height=i)},le={blocks:" ░▒▓█",braille:" ⠁⠃⠇⡇⣇⣧⣷⣿",lines:" -═╪╬",cross:" ·+xX#",diagonal:" /╱╳",diamond:" ·◇◈◆",mixed:" .:+/◇#@"},ce=new Set(["pointillism","stipple","led","dots"]),me=.32,ue=.9;function fe(t){const e=new Uint32Array(256);let i=0;for(let a=0;a<t.length;a+=4)t[a+3]<8||(e[Math.min(255,.299*t[a]+.587*t[a+1]+.114*t[a+2]|0)]++,i++);if(!i)return[0,1];const a=t=>{let a=0;const s=t*i;for(let t=0;t<256;t++)if((a+=e[t])>=s)return t/255;return 1};let s=a(.01),r=a(.99);return r-s<me&&(s=Math.max(0,Math.min(1-me,(s+r)/2-.16)),r=s+me),[s,r]}function de(t,e,i){const a=Math.max(.001,i-e);let s=0,r=0;for(let i=0;i<t.length;i+=4){if(t[i+3]<8)continue;const n=((.299*t[i]+.587*t[i+1]+.114*t[i+2])/255-e)/a;n<=.06||(s+=Math.min(1,n),r++)}if(!r)return ue;const n=Math.min(.99,Math.max(.01,s/r));return Math.min(ue,Math.max(.6,Math.log(.5)/Math.log(n)))}function pe(t,e=.9){const i=Math.min(...t),a=Math.max(...t);if(!(a-i>1e-4))return null;const s=t.map(t=>(t-i)/(a-i)),r=new Uint8Array(256);for(let t=0;t<256;t++){if(t/255<.07){r[t]=s.indexOf(0);continue}const i=Math.pow(t/255,e);let a=0;for(let t=1;t<s.length;t++)Math.abs(s[t]-i)<Math.abs(s[a]-i)&&(a=t);r[t]=a}return r}function ge(t,e,i,a){t.clearRect(0,0,e,i),t.fillStyle="#fff",t.strokeStyle="#fff",t.lineCap="round",t.lineJoin="round";for(const s of a){if(t.beginPath(),"ellipse"===s.kind)t.ellipse((s.x+s.width/2)*e,(s.y+s.height/2)*i,s.width*e/2,s.height*i/2,0,0,2*Math.PI);else{if("rectangle"!==s.kind){if(t.lineWidth=(s.size??.05)*e,1===s.points?.length){t.arc(s.points[0][0]*e,s.points[0][1]*i,t.lineWidth/2,0,2*Math.PI),t.fill();continue}s.points?.forEach(([a,s],r)=>r?t.lineTo(a*e,s*i):t.moveTo(a*e,s*i)),t.stroke();continue}t.rect(s.x*e,s.y*i,s.width*e,s.height*i)}t.fill()}}var Me=new WeakMap,xe=t=>Math.max(64,Math.min(4096,Number.isFinite(t)?t:960));function ve(t,e,i){const a=Math.min(1,t/Math.max(e,i));return[Math.max(2,Math.round(e*a)),Math.max(2,Math.round(i*a))]}function ye(t,e,i,a,s){const[r,n]=ne(e);t.clearRect(0,0,i,a),t.save();const o=et(r,n,i,a,s);t.translate(o.x+o.width/2,o.y+o.height/2),t.rotate(s.rotation*Math.PI/180),t.drawImage(e,-r*o.scale/2,-n*o.scale/2,r*o.scale,n*o.scale),t.restore()}function be(t,e={},i={}){return function(t,e,i,a){const s=a.surface,r=t.getContext("2d");if(!r)throw new Error("Canvas is already owned by another renderer.");const n=s(),o=s(!0),h=s(),l=s(),c=s(),m=s(),u=s(),d=s(),M=s(),x=s();let v,y,b=0,w=0,k=1,S=ue,R=null,T=null,P=null,C="",I=tt(e),N=0,U="",O="",L="",q=new Uint8ClampedArray(0),X=new Uint8ClampedArray(0),B=new Uint8ClampedArray(0),j=null,G="",H=0,W=0,V=0,J=null,Q="",Z=new re,_=null,$=new Float32Array(0);const et=s(!0),it=s(),at=s();let rt=0;const nt=[0,0,0],ct=[0,0,0,1],mt=[0,0],ut=[0,0,0,0];let ft=ht(I.color),dt=Mt(I.print);const pt=new lt(I.color.denoise),gt=new z(I.warps,I.warpEdge),xt=xe(i.maxDimension),bt=Math.max(256,Math.min(1048576,Number.isFinite(i.maxCells)?i.maxCells:12e3));let At=bt,Rt=Math.max(.1,Math.min(8,i.pixelRatio??1));const Tt=(t,e,i)=>{Z.configure(I.hover.effect,I.hover.strength,I.hover.radius,I.hover.edgeSafe,I.hover.decay),Z.move(t,e,i)};function Pt(t,e=0,i=960,a=540,s=e*I.motion.speed){Ct(t,e,i,a,s,!0)}function Ct(e,i,s,z,tt,ht){if(Number.isFinite(i)||(i=0),!Number.isFinite(s)||!Number.isFinite(z)||s<1||z<1)throw new Error("Render dimensions must be positive finite numbers.");const[lt,Mt]=ne(e);if(!lt||!Mt)return;const[bt,Tt]=ve(xt,s,z);he(t,bt,Tt),he(n.canvas,bt,Tt),he(h.canvas,bt,Tt),he(l.canvas,bt,Tt),he(c.canvas,bt,Tt),rt!==bt/Tt&&(rt=bt/Tt,Z=new re(rt),Z.setGuide(_)),Z.configure(I.hover.effect,I.hover.strength,I.hover.radius,I.hover.edgeSafe,I.hover.decay),Z.step(Math.max(0,Math.min(.05,i-V))),V=i;const Pt=a.media(e),Ct=[N,bt,Tt,Pt.time].join(":"),Nt="dither"===I.style,Ut=st(bt,Tt,I,At,Rt),Bt=Ut.cell,Yt=Ut.rowHeight,jt=Ut.columns,Gt=Ut.rows;if(U!==Ct||J!==Pt.key||H!==jt||W!==Gt){J=Pt.key,U=Ct,G="",O="",L="",H=jt,W=Gt,a.scene?a.scene(n.ctx,bt,Tt):ye(n.ctx,e,bt,Tt,I.crop),he(o.canvas,H,W),o.ctx.clearRect(0,0,H,W),o.ctx.drawImage(n.canvas,0,0,H,W),q=o.ctx.getImageData(0,0,H,W).data,pt.apply(q,H,W),X.length!==q.length&&(X=new Uint8ClampedArray(q.length)),X.set(q);const t=I.color;for(let e=0;e<q.length;e+=4){const i=.299*q[e]+.587*q[e+1]+.114*q[e+2];for(let a=0;a<3;a++){const s=i+(q[e+a]-i)*t.saturation;q[e+a]=((s*(1-t.grayscale)+i*t.grayscale)/255-.5)*t.contrast*255+127.5+255*t.brightness}}if(ft&&function(t,e){for(let i=0;i<t.length;i+=4)t[i+3]&&(t[i]=e[t[i]],t[i+1]=e[256+t[i+1]],t[i+2]=e[512+t[i+2]])}(q,ft),q=gt.apply(q,H,W,bt/Tt),"none"!==I.color.levels){const[t,e]=fe(q),i=de(q,t,e),a=R===Pt.key&&Pt.video?.15:1;R=Pt.key,w+=(t-w)*a,k+=(e-k)*a,S+=(i-S)*a}const i=I.hover,s=i.scope??"all";if("none"===i.effect||"all"===s&&"tilt"!==i.effect)_=null;else{let t=null;if(I.mask.enabled&&I.mask.shapes.length){he(et.canvas,H,W),et.ctx.clearRect(0,0,H,W),ge(et.ctx,H,W,I.mask.shapes);const e=et.ctx.getImageData(0,0,H,W).data;t=new Float32Array(H*W);for(let i=0;i<t.length;i++)t[i]=I.mask.invert?1-e[4*i+3]/255:e[4*i+3]/255}_=p(q,H,W,t,_),$.length!==H*W&&($=new Float32Array(H*W));for(let t=0;t<$.length;t++)$[t]=g(s,_.subject[t],_.key);if("reveal"===i.effect){he(it.canvas,H,W);const t=new ImageData(H,W);for(let e=0;e<$.length;e++)t.data[4*e+3]=255*$[e];it.ctx.putImageData(t,0,0)}}Z.setGuide(_)}if(!ht)return void(L=O="");const Ht=yt(I),Wt=vt(I),Vt=!Z.active&&!Ht&&!Wt,Kt=[Ct,H,W,Bt,Yt,Rt,Z.signature].join(":"),Jt=Z.engaged,Qt=Z.effect;if(!Vt||L!==Kt){h.ctx.clearRect(0,0,bt,Tt),h.ctx.globalAlpha=1,h.ctx.globalCompositeOperation="source-over";const t=tt,e=Ht?I.motion.type:"none",s=I.motion.amount??1,r="relight"===(Zt=e)||"sheen"===Zt||"glow"===Zt||"shimmer"===Zt||"mist"===Zt;"none"!==e&&G!==U&&(j=function(t,e,i,a,s=t){const r=e*i,n=a?.length===r*wt?a:new Float32Array(r*wt);if(!r)return n;const o=Math.min(e,i),h=new Float32Array(r),l=new Float32Array(r),c=new Float32Array(r),m=new Float32Array(r),u=new Float32Array(r),d=new Float32Array(r);for(let e=0;e<r;e++){const i=t[4*e+3]/255;h[e]=(.299*t[4*e]+.587*t[4*e+1]+.114*t[4*e+2])/255*i}l.set(h),f(l,d,e,i,Math.max(1,Math.round(.012*o))),c.set(h),f(c,d,e,i,Math.max(1,Math.round(.03*o)));for(let t=0;t<r;t++){m[t]=Math.abs(h[t]-l[t]);const e=Math.max(0,h[t]-.55)/.45;u[t]=e*e}f(m,d,e,i,Math.max(1,Math.round(.02*o)));const p=1/Math.max(.02,St(m,.95));f(u,d,e,i,Math.max(1,Math.round(.05*o)));const g=1/Math.max(.03,St(u,.98)),M=Math.max(1,Math.ceil(Math.sqrt(r/12e3))),x=Math.max(1,Math.floor(e/M)),v=Math.max(1,Math.floor(i/M)),y=x*v;let b=t,w=s;if(M>1){const i=new Uint8ClampedArray(4*y),a=s===t?i:new Uint8ClampedArray(4*y);for(let r=0;r<v;r++)for(let n=0;n<x;n++){const o=[0,0,0,0,0,0,0];for(let h=r*M;h<(r+1)*M;h++)for(let r=n*M;r<(n+1)*M;r++){const n=4*(h*e+r);for(let e=0;e<4;e++)o[e]+=t[n+e];if(a!==i)for(let t=0;t<3;t++)o[4+t]+=s[n+t]}const h=4*(r*x+n),l=M*M;for(let t=0;t<4;t++)i[h+t]=o[t]/l;if(a!==i){for(let t=0;t<3;t++)a[h+t]=o[4+t]/l;a[h+3]=i[h+3]}}b=i,w=a}Et?.n!==y&&(Et=new Ft(y)),Et.reset();const{depth:k,water:A,sky:S,falls:F}=It(b,w,x,v,Et),E=St(k,.03),R=St(k,.97),T=Math.max(.05,R-E);let P=0,C=0,I=0;const D=new Float32Array(r);for(let t=0;t<i;t++)for(let a=0;a<e;a++){const s=t*e+a,r=s*wt,o=kt((Dt(k,x,v,a,t,e,i)-E)/T);n[r+1]=o,n[r+8]=kt(Dt(A,x,v,a,t,e,i)),n[r+9]=kt(Dt(S,x,v,a,t,e,i)),n[r+10]=kt(Dt(F,x,v,a,t,e,i));const l=o*o*o*(.25+h[s]);P+=(a+.5)/e*l,C+=(t+.5)/i*l,I+=l,D[s]=Math.hypot(c[t*e+Math.min(e-1,a+1)]-c[t*e+Math.max(0,a-1)],c[Math.min(i-1,t+1)*e+a]-c[Math.max(0,t-1)*e+a])}P=I>0?Math.max(.3,Math.min(.7,P/I)):.5,C=I>0?Math.max(.3,Math.min(.7,C/I)):.5;const N=1/Math.max(.004,St(D,.97));for(let t=0;t<i;t++)for(let a=0;a<e;a++){const s=t*e+a,r=s*wt,o=(c[t*e+Math.min(e-1,a+1)]-c[t*e+Math.max(0,a-1)])*N,h=(c[Math.min(i-1,t+1)*e+a]-c[Math.max(0,t-1)*e+a])*N;n[r]=c[s],n[r+2]=Math.min(1,u[s]*g),n[r+3]=Math.min(1,m[s]*p),n[r+4]=Math.max(-1,Math.min(1,-o)),n[r+5]=Math.max(-1,Math.min(1,-h)),n[r+6]=P,n[r+7]=C}return n}(X,H,W,j),G=U);let p=null;if(Nt){const a=Vt;if(!a||O!==Ct){B.length!==q.length&&(B=new Uint8ClampedArray(q.length));const r=B;if(r.set(q),Jt||"none"!==e)for(let i=0;i<W;i++)for(let a=0;a<H;a++){const n=a/H,o=i/W;let h=a,l=i,c=0,m=0,u=1;if(Jt){Z.sample(n,o,nt);const t=_?$[i*H+a]:1;h-=nt[0]*t*H,l-=nt[1]*t*W,"reveal"===Qt?u=1-.72*Math.min(1,nt[2]*t):"repel"===Qt?u=1+Math.max(-1,nt[2])*t:c=nt[2]/3*t}const f=4*(i*H+a);A(e,n,o,t,ct,(.299*q[f]+.587*q[f+1]+.114*q[f+2])/255,j??void 0,(i*H+a)*wt),E(ct,s),(ct[0]||ct[1])&&(F(ct,h,l,H,W,mt),h=mt[0],l=mt[1]),m=ct[2],u*=ct[3];const d=4*(i*H+a);D(q,H,W,h,l,ut);for(let t=0;t<3;t++){let e=ae(Qt,ut[t]/255,c)+m;r[d+t]=255*e}r[d+3]=ut[3]*u}!function(t,e,i,a,s=0){const{algorithm:r,amount:n,threshold:o}=a,h="blue-noise"===r,l=r.startsWith("bayer")?Number(r.slice(5)):0,c=qt.get(l),m=l-1,u="luminance"===a.colorSpace,f=("custom"===a.palette?a.colors:K[a.palette]??K.mono).map(zt),d=Xt[r],p=d?new Float32Array(3*e*3):null,g="drift"===a.motion?s*a.speed*3:0,M=(a.direction??45)*Math.PI/180,x=Math.round(Math.cos(M)*g),v=Math.round(Math.sin(M)*g),y=(t,e)=>(t%e+e)%e,b=f.map(t=>.299*t[0]+.587*t[1]+.114*t[2]),w="shimmer"===a.motion?.15*Math.sin(s*a.speed*2):0;for(let a=0;a<i;a++)for(let s=0;s<e;s++){const M=4*(a*e+s),k=3*(a%3*e+s);if(0===t[M+3]){p&&(p[k]=p[k+1]=p[k+2]=0);continue}let A=0;const S=h?(Ot[64*(a-v&63)+(s-x&63)]+.5)/Ot.length:0;c?A=c[(a-v&m)*l+(s-x&m)]:"noise"===r?A=Lt(s-x,a-v)-.5:"lines"===r?A=y(a-v,4)/3-.5:"vertical-lines"===r?A=y(s-x,4)/3-.5:"diagonal-lines"===r?A=y(s-x+a-v,4)/3-.5:"radial"===r?A=y(Math.hypot(s-e/2,a-i/2)-g,6)/6-.5:"halftone"===r&&(A=Math.hypot(y(s-x,6)-2.5,y(a-v,6)-2.5)/3.54-.5);const F=128*(A*n+w+(.5-o)),E=t[M]+F+(p?.[k]??0),R=t[M+1]+F+(p?.[k+1]??0),T=t[M+2]+F+(p?.[k+2]??0);let P=0,C=0,I=0;if(f.length){let t=1/0,e=1/0,i=0,a=0;const s=.299*E+.587*R+.114*T;for(let r=0;r<f.length;r++){const n=f[r],o=u?(s-b[r])**2:(E-n[0])**2*.299+(R-n[1])**2*.587+(T-n[2])**2*.114;o<t?(h&&(e=t,a=i,i=r),t=o,[P,C,I]=n):h&&o<e&&(e=o,a=r)}if(h&&n>0&&Number.isFinite(e)){const t=f[a],e=t[0]-P,r=t[1]-C,o=t[2]-I,h=b[a]-b[i],l=u?h*h:e*e*.299+r*r*.587+o*o*.114,c=u?(s-b[i])*h:(E-P)*e*.299+(R-C)*r*.587+(T-I)*o*.114;S<(l?Math.max(0,Math.min(1,c/l*n)):0)&&([P,C,I]=t)}}else if(h){const t=Math.max(0,Math.min(1,.5+(S-.5)*n));P=51*Math.floor(E/51+1-t),C=51*Math.floor(R/51+1-t),I=51*Math.floor(T/51+1-t)}else P=51*Math.round(E/51),C=51*Math.round(R/51),I=51*Math.round(T/51);if(t[M]=P,t[M+1]=C,t[M+2]=I,p&&d){p[k]=p[k+1]=p[k+2]=0;for(const[t,r,o]of d){const h=s+t;if(h<0||h>=e||a+r>=i)continue;const l=3*((a+r)%3*e+h);p[l]+=(E-P)*o*n,p[l+1]+=(R-C)*o*n,p[l+2]+=(T-I)*o*n}}}}(r,H,W,I.dither,i),o.ctx.putImageData(new ImageData(r,H,W),0,0),O=a?Ct:""}h.ctx.imageSmoothingEnabled=!1,h.ctx.drawImage(o.canvas,0,0,bt,Tt)}else{const i=ce.has(I.style);i&&a.marks&&void 0===y&&(y=a.marks()),p=i&&y?.begin(bt,Tt,"led"===I.style||"dots"===I.style)?y:null;const n=Array.from(le[I.style]??I.charset),o=p?.ctx??h.ctx,l=zt(I.ink),c="ripple"===Qt||"etch"===Qt,m=c&&.299*l[0]+.587*l[1]+.114*l[2]<90?[214,214,214]:l,f="ascii"===I.style||!!le[I.style],d=Y(I.style)?I.style:null,g=Math.max(3,Math.round(.92*Yt)),M=Math.ceil(Bt+4),v=Math.ceil(Yt+4),R=[n.join(""),g,M,v,I.ink,I.colorMode].join(":");if(f&&R!==Q){Q=R,he(u.canvas,M*n.length,v),u.ctx.clearRect(0,0,u.canvas.width,v),u.ctx.font=`${g}px monospace`,u.ctx.textBaseline="middle",u.ctx.textAlign="center",u.ctx.fillStyle="accent"===I.colorMode?I.ink:"#ffffff",n.forEach((t,e)=>u.ctx.fillText(t,e*M+M/2,v/2)),T=null,C="";try{const t=u.ctx.getImageData(0,0,u.canvas.width,u.canvas.height).data;T=n.map((e,i)=>{let a=0;for(let e=0;e<u.canvas.height;e++)for(let s=i*M;s<(i+1)*M&&s<u.canvas.width;s++)a+=t[4*(e*u.canvas.width+s)+3];return a})}catch{T=null}}const N=f&&"none"!==I.color.levels;if(N&&T){const t=Q+":"+S.toFixed(2);t!==C&&(C=t,P=pe(T,S))}const U=Math.max(.001,k-w);if("lego"===I.style&&b!==Bt){b=Bt,he(x.canvas,Math.ceil(Bt),Math.ceil(Yt));const t=x.ctx;t.clearRect(0,0,x.canvas.width,x.canvas.height),t.fillStyle="rgba(255,255,255,.2)",t.strokeStyle="rgba(0,0,0,.25)",t.lineWidth=Math.max(.5,.6*Rt),t.beginPath(),t.arc(Bt/2,Yt/2,.28*Bt,0,2*Math.PI),t.fill(),t.stroke()}o.font=`${g}px monospace`,o.textBaseline="middle",o.textAlign="center";for(let i=0;i<W;i++)for(let a=0;a<H;a++){let h=a,g=i,y=0,b=0;if(Jt){Z.sample(a/H,i/W,nt);const t=_?$[i*H+a]:1;h=Math.max(0,Math.min(H-1,a-nt[0]*t*H)),g=Math.max(0,Math.min(W-1,i-nt[1]*t*W)),"reveal"===Qt?b=.72*Math.min(1,nt[2]*t):"repel"===Qt?b=-Math.max(-1,nt[2])*t:y=nt[2]/3*t}if("none"!==e){const r=4*(i*H+a);A(e,a/H,i/W,t,ct,(.299*q[r]+.587*q[r+1]+.114*q[r+2])/255,j??void 0,(i*H+a)*wt),E(ct,s),(ct[0]||ct[1])&&(F(ct,h,g,H,W,mt),h=mt[0],g=mt[1])}D(q,H,W,h,g,ut);let k=0;if(c&&y>.012&&(ut[3]?ut[3]>250&&.299*ut[0]+.587*ut[1]+.114*ut[2]<30:"outside"===I.hover.scope)){const t=Math.min(1,(y-.012)/.12);k=t*t*(3-2*t)}if(!ut[3]){if(!(k||y>.03)||"outside"!==I.hover.scope||!se(Qt))continue;ut[0]=m[0],ut[1]=m[1],ut[2]=m[2],ut[3]=k?255:Math.min(255,640*y)}const R=ut[0],C=ut[1],O=ut[2],L=(.299*R+.587*C+.114*O)/255;let X=N?Math.max(0,Math.min(1,(L-w)/U)):L;X=ae(Qt,X,y,!!d&&dt.settings.invert);const z=a*Bt,B=i*Yt;let Y=1,G=X;if("none"!==e){const t=ct[2]/(N?Math.max(.5,U):1);X=Math.max(0,Math.min(1,X+t)),G=Math.max(0,Math.min(1,G+t*(r?.45:1)))}else G=X;k&&(X=G=Math.max(X,.1+.45*k)),Y=("none"!==e?ct[3]:1)*ut[3]/255*(1-b)*(k?.3+.45*k:1),f||d||"accent"!==I.colorMode||"cmyk"===I.style?N&&"accent"===I.colorMode&&(Y*=.32+.68*Math.pow(X,S)):Y*=X,o.globalAlpha=Y;const V=255*(X-L);let K;if(p&&"accent"!==I.colorMode&&"pointillism"===I.style)K=I.ink;else if(p&&"accent"!==I.colorMode){if("source"===I.colorMode)p.ctx.fillColor(R+V,C+V,O+V);else{const t=Math.round(255*X);p.ctx.fillColor(t,t,t)}K=ot}else K="source"===I.colorMode?`rgb(${R+V},${C+V},${O+V})`:"gray"===I.colorMode?`rgb(${Math.round(255*X)},${Math.round(255*X)},${Math.round(255*X)})`:I.ink;if(o.fillStyle=K,d)dt.paint(o,d,a,i,z,B,Bt,X,K,"gray"===I.colorMode?255*X:R+V,"gray"===I.colorMode?255*X:C+V,"gray"===I.colorMode?255*X:O+V,I.colorMode);else if(f){const t=N&&P?P[Math.round(255*G)]:Math.max(0,Math.min(n.length-1,Math.round(G*(n.length-1))));if("accent"===I.colorMode?0===T?.[t]:" "===n[t])continue;"accent"===I.colorMode?o.drawImage(u.canvas,t*M,0,M,v,Math.round(z+(Bt-M)/2),Math.round(B+(Yt-v)/2),M,v):o.fillText(n[t],z+Bt/2,B+Yt/2)}else if("dots"===I.style)o.beginPath(),o.arc(z+Bt/2,B+Yt/2,.48*Bt*Math.sqrt(X),0,2*Math.PI),o.fill();else if("led"===I.style)o.beginPath(),o.arc(z+Bt/2,B+Yt/2,.39*Bt,0,2*Math.PI),o.fill(),o.globalAlpha=.35*Y,o.fillStyle="#ffffff",o.beginPath(),o.arc(z+.43*Bt,B+.4*Yt,.11*Bt,0,2*Math.PI),o.fill();else if("hex"===I.style){const t=z+Bt/2,e=B+Yt/2;o.beginPath();for(let i=0;i<6;i++){const a=Math.PI/3*i,s=t+Math.cos(a)*Bt*.49,r=e+Math.sin(a)*Yt*.49;0===i?o.moveTo(s,r):o.lineTo(s,r)}o.closePath(),o.fill()}else if("cmyk"===I.style){o.fillStyle="#ffffff",o.fillRect(z,B,Bt,Yt);const t=(t,e)=>Math.max(0,Math.min(255,"source"===I.colorMode?t+V:"gray"===I.colorMode?255*X:e*X)),e=t(R,l[0]),i=t(C,l[1]),a=t(O,l[2]),s=1-Math.max(e,i,a)/255,r=Math.max(.001,1-s),n=[["#00ffff",(1-e/255-s)/r,.36,.36],["#ff00ff",(1-i/255-s)/r,.64,.36],["#ffff00",(1-a/255-s)/r,.5,.66],["#000000",s,.5,.5]];o.globalCompositeOperation="multiply";for(const[t,e,i,a]of n)e>0&&(o.fillStyle=t,o.beginPath(),o.arc(z+Bt*i,B+Yt*a,.48*Bt*Math.sqrt(Math.max(0,e)),0,2*Math.PI),o.fill());o.globalCompositeOperation="source-over"}else if("voxel"===I.style){const t=z+Bt/2,e=B+Yt/2;o.beginPath(),o.moveTo(t,B),o.lineTo(z+Bt,B+.25*Yt),o.lineTo(t,e),o.lineTo(z,B+.25*Yt),o.closePath(),o.fill(),o.globalAlpha=.72*Y,o.beginPath(),o.moveTo(z,B+.25*Yt),o.lineTo(t,e),o.lineTo(t,B+Yt),o.lineTo(z,B+.75*Yt),o.closePath(),o.fill(),o.globalAlpha=.42*Y,o.beginPath(),o.moveTo(t,e),o.lineTo(z+Bt,B+.25*Yt),o.lineTo(z+Bt,B+.75*Yt),o.lineTo(t,B+Yt),o.closePath(),o.fill()}else{const t="pixel"===I.style?0:Math.max(.5,.06*Bt);o.fillRect(z,B,Bt-t,Yt-t),"lego"===I.style&&o.drawImage(x.canvas,z,B),"disco"===I.style&&(o.fillStyle=`rgba(255,255,255,${.1+.25*Lt(a,i)})`,o.fillRect(z,B,Bt-t,.35*Yt),o.fillStyle="rgba(0,0,0,.25)",o.fillRect(z,B+.65*Yt,Bt-t,.35*Yt-t))}}}if(h.ctx.globalAlpha=1,p){const t=p.finish();t&&h.ctx.drawImage(t,0,0)}(I.color.amount||I.lights.length)&&(he(d.canvas,bt,Tt),d.ctx.clearRect(0,0,bt,Tt),d.ctx.drawImage(h.canvas,0,0)),I.color.amount&&(h.ctx.save(),h.ctx.globalCompositeOperation=I.color.blend,h.ctx.globalAlpha=I.color.amount,h.ctx.fillStyle=I.color.tint,h.ctx.fillRect(0,0,bt,Tt),h.ctx.restore());for(const t of I.lights){const e=t.radius*Math.max(bt,Tt),i=h.ctx.createRadialGradient(t.x*bt,t.y*Tt,0,t.x*bt,t.y*Tt,e);i.addColorStop(0,t.color),i.addColorStop(1,"transparent"),h.ctx.save(),h.ctx.globalCompositeOperation="screen",h.ctx.globalAlpha=t.intensity,h.ctx.fillStyle=i,h.ctx.fillRect(0,0,bt,Tt),h.ctx.restore()}(I.color.amount||I.lights.length)&&(h.ctx.globalCompositeOperation="destination-in",h.ctx.drawImage(d.canvas,0,0),h.ctx.globalCompositeOperation="source-over"),I.mask.enabled&&I.mask.shapes.length&&(ge(c.ctx,bt,Tt,I.mask.shapes),h.ctx.globalCompositeOperation=I.mask.invert?"destination-out":"destination-in",h.ctx.drawImage(c.canvas,0,0),h.ctx.globalCompositeOperation="source-over");const g=l.ctx;g.clearRect(0,0,bt,Tt),g.globalAlpha=I.backdrop.opacity;const v=I.backdrop;if("solid"===v.mode&&(g.fillStyle=v.color,g.fillRect(0,0,bt,Tt)),"gradient"===v.mode){const t=g.createLinearGradient(0,0,bt,Tt);t.addColorStop(0,v.color),t.addColorStop(1,v.color2),g.fillStyle=t,g.fillRect(0,0,bt,Tt)}if("source"===v.mode&&g.drawImage(n.canvas,0,0),"blurred"===v.mode){const t=Math.max(1,v.blur);he(m.canvas,Math.max(2,Math.round(bt/t)),Math.max(2,Math.round(Tt/t))),m.ctx.drawImage(n.canvas,0,0,m.canvas.width,m.canvas.height),g.imageSmoothingEnabled=!0,g.drawImage(m.canvas,0,0,bt,Tt)}g.globalAlpha=1,I.effects.characterBloom>0&&(he(M.canvas,Math.max(2,Math.round(bt/3)),Math.max(2,Math.round(Tt/3))),M.ctx.clearRect(0,0,M.canvas.width,M.canvas.height),M.ctx.drawImage(h.canvas,0,0,M.canvas.width,M.canvas.height),g.save(),g.globalAlpha=.8*I.effects.characterBloom,g.globalCompositeOperation="screen",g.filter=`blur(${1+4*I.effects.characterBloom}px)`,g.drawImage(M.canvas,0,0,bt,Tt),g.restore());const R=Z.spotlight;if(R&&R[2]>.002){he(at.canvas,bt,Tt);const t=at.ctx,e=R[3]*Math.min(bt,Tt)*1.6;t.globalCompositeOperation="source-over",t.clearRect(0,0,bt,Tt),t.drawImage(n.canvas,0,0),t.globalCompositeOperation="destination-in";const i=t.createRadialGradient(R[0]*bt,R[1]*Tt,0,R[0]*bt,R[1]*Tt,e),a=Math.min(1,R[2]*I.hover.strength/.55);for(const t of[0,.2,.4,.6,.8,1])i.addColorStop(t,`rgba(0,0,0,${a*Math.exp(-2.4*(1.6*t)**2)*(1-t)})`);t.fillStyle=i,t.fillRect(0,0,bt,Tt),_&&"all"!==(I.hover.scope??"all")&&(t.imageSmoothingEnabled=!0,t.drawImage(it.canvas,0,0,bt,Tt)),t.globalCompositeOperation="source-over",g.drawImage(at.canvas,0,0)}g.drawImage(h.canvas,0,0),L=Vt?Kt:""}var Zt;const _t=Object.entries(I.effects).some(([t,e])=>!["angle","focus","blurType","characterBloom"].includes(t)&&"number"==typeof e&&e>0);r.clearRect(0,0,bt,Tt),_t?(void 0===v&&(v=function(t=()=>document.createElement("canvas")){const e=t(),i=e.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,antialias:!1,preserveDrawingBuffer:!0});if(!i)return null;const a=[],s=(t,e)=>{const s=i.createShader(t);if(a.push(s),i.shaderSource(s,e),i.compileShader(s),!i.getShaderParameter(s,i.COMPILE_STATUS))throw new Error(i.getShaderInfoLog(s)||"Finish shader failed");return s},r=i.createProgram();if(i.attachShader(r,s(i.VERTEX_SHADER,"attribute vec2 p;varying vec2 uv;void main(){uv=(p+1.)*.5;gl_Position=vec4(p,0.,1.);}")),i.attachShader(r,s(i.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);}")),i.linkProgram(r),!i.getProgramParameter(r,i.LINK_STATUS))throw new Error("Finish link failed");i.useProgram(r);const n=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,n),i.bufferData(i.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),i.STATIC_DRAW);const o=i.getAttribLocation(r,"p");i.enableVertexAttribArray(o),i.vertexAttribPointer(o,2,i.FLOAT,!1,0,0);const h=i.createTexture();i.bindTexture(i.TEXTURE_2D,h),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE);const l=["t","bloom","grain","dust","scanlines","crt","prism","rgbSplit","sharpen","vignette","glitch","pixelate","blur","blurMode","angle","focus","halftone"],c=Object.fromEntries(l.map(t=>[t,i.getUniformLocation(r,t)])),m=i.getUniformLocation(r,"size");return{canvas:e,render(t,a,s,n=1){e.width===t.width&&e.height===t.height||(e.width=t.width,e.height=t.height,i.viewport(0,0,e.width,e.height)),i.useProgram(r),i.bindTexture(i.TEXTURE_2D,h),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t),i.uniform2f(m,e.width/n,e.height/n);for(const t of l)i.uniform1f(c[t],"t"===t?s:"blurMode"===t?["gaussian","directional","radial","progressive"].indexOf(a.blurType):"angle"===t?a.angle*Math.PI/180:a[t]??0);return i.drawArrays(i.TRIANGLE_STRIP,0,4),e},destroy(){i.deleteTexture(h),i.deleteBuffer(n),i.deleteProgram(r),a.forEach(t=>i.deleteShader(t)),e.width=e.height=1,i.getExtension("WEBGL_lose_context")?.loseContext()}}}(a.finishCanvas)),v?r.drawImage(v.render(l.canvas,I.effects,i,Rt),0,0):r.drawImage(l.canvas,0,0),a.finished(v?"gpu":"unavailable")):(r.drawImage(l.canvas,0,0),a.finished("none"))}const Nt={canvas:t,render:Pt,setPixelRatio(t){Rt=Math.max(.1,Math.min(8,Number.isFinite(t)?t:1))},get pixelRatio(){return Rt},setBudget(t){At=Math.max(256,Math.min(bt,Number.isFinite(t)?Math.round(t):bt))},get maxCells(){return At},configure(t){I=tt(t),ft=ht(I.color),dt=Mt(I.print),pt.configure(I.color.denoise),gt.configure(I.warps,I.warpEdge),N++},pointer:Tt,leave(){Z.leave()},get active(){return Z.active},get settings(){return tt(I)},get capabilities(){return{gpuFinish:null!==v}},invalidate(){U=""},destroy(){v?.destroy(),y?.destroy(),y=void 0,gt.clear(),pt.configure(0);for(const t of[n,o,h,l,c,m,u,d,M,x,et,it,at])t.canvas.width=t.canvas.height=1;J=null,q=new Uint8ClampedArray(0),B=new Uint8ClampedArray(0),j=null,G=""}};return Me.set(Nt,Ct),Nt}(t,e,i,(t=>({surface:oe,media:t=>"currentTime"in t?{video:!0,time:t.getVideoPlaybackQuality?.().totalVideoFrames??t.currentTime,key:t}:{video:!1,time:0,key:t},finished(e){t.dataset.studioFinish=e}}))(t))}function we(t,e,i){return new Promise((a,s)=>{const r=()=>{l(),a()},n=()=>{l(),s(new Error("Unable to load this media. Check its format and cross-origin permissions."))},o=()=>{l(),s(new DOMException("Cancelled","AbortError"))},h=setTimeout(n,2e4),l=()=>{clearTimeout(h),t.removeEventListener(e,r),t.removeEventListener("error",n),i?.removeEventListener("abort",o)};t.addEventListener(e,r,{once:!0}),t.addEventListener("error",n,{once:!0}),i?.addEventListener("abort",o,{once:!0}),i?.aborted&&o()})}async function ke(t,e){if("string"==typeof t&&t.startsWith("blob:")){const i=await fetch(t,{signal:e}),a=await i.blob();return ke(new File([a],"Imported media",{type:a.type}),e)}const i="string"!=typeof t,a=i?t.name:t;if(i?"image/gif"===t.type:/\.gif(?:[?#]|$)/i.test(a)){const a=await import("gifuct-js"),{parseGIF:s,decompressFrames:r}="function"==typeof a.parseGIF?a:a.default,n=i?await t.arrayBuffer():await fetch(t,{signal:e}).then(t=>{if(!t.ok)throw new Error("GIF download failed.");return t.arrayBuffer()});if(e?.aborted)throw new DOMException("Cancelled","AbortError");const o=s(n),h=o.lsd.width,l=o.lsd.height;if(h*l>4e6)throw new Error("GIF is too large. Use a smaller GIF or an MP4.");const c=o.frames.filter(t=>"image"in t).length;if(!c||c*h*l*4>128e6)throw new Error("GIF exceeds the decoded memory budget. Use MP4 for long animations.");const m=r(o,!0);if(m.length*h*l*4>128e6)throw new Error("GIF exceeds the 128 MB decoded budget. Use MP4 for long animations.");const u=document.createElement("canvas");u.width=h,u.height=l;const f=u.getContext("2d"),d=document.createElement("canvas"),p=d.getContext("2d"),g=m.reduce((t,e)=>t+Math.max(20,e.delay),0)/1e3;let M=-1,x=null;const v=t=>{const e=(t%g+g)%g*1e3;let i=0,a=0;for(;a<m.length-1&&(i+=Math.max(20,m[a].delay),!(e<i));a++);a<M&&(f.clearRect(0,0,h,l),M=-1,x=null);for(let t=M+1;t<=a;t++){const e=m[t-1];2===e?.disposalType&&f.clearRect(e.dims.left,e.dims.top,e.dims.width,e.dims.height),3===e?.disposalType&&x&&f.putImageData(x,0,0);const i=m[t];x=3===i.disposalType?f.getImageData(0,0,h,l):null,d.width=i.dims.width,d.height=i.dims.height,p.putImageData(new ImageData(new Uint8ClampedArray(i.patch),d.width,d.height),0,0),f.drawImage(d,i.dims.left,i.dims.top)}return M=a,u};return v(0),{source:u,width:h,height:l,duration:g,animated:!0,seek:async()=>{},frame:v,destroy(){u.width=d.width=1,m.length=0,x=null}}}const s=i?t.type.startsWith("video/"):/\.(mp4|webm|mov)(?:[?#]|$)/i.test(a),r=i?URL.createObjectURL(t):t,n=s?document.createElement("video"):new Image;n.crossOrigin="anonymous",n instanceof HTMLVideoElement&&(n.muted=!0,n.playsInline=!0,n.preload="auto");const o=()=>{n instanceof HTMLVideoElement?(n.pause(),n.removeAttribute("src"),n.load()):n.src="",i&&URL.revokeObjectURL(r)};try{const t=we(n,s?"loadeddata":"load",e);n.src=r,await t;const i=n instanceof HTMLVideoElement?n.videoWidth:n.naturalWidth,a=n instanceof HTMLVideoElement?n.videoHeight:n.naturalHeight;return{source:n,width:i,height:a,duration:n instanceof HTMLVideoElement?n.duration:0,animated:s,async seek(t,e){if(!(n instanceof HTMLVideoElement))return;if(!Number.isFinite(n.duration)||n.duration<=0)throw new Error("Video duration is unavailable.");const i=Math.max(0,Math.min(n.duration-.001,t%n.duration));if(Math.abs(n.currentTime-i)<.001&&n.readyState>=2)return;const a=we(n,"seeked",e);n.currentTime=i,await a},frame:()=>n,destroy:o}}catch(t){throw o(),t}}var Ae=t=>{if(t?.aborted)throw new DOMException("Export cancelled","AbortError")};async function Se(t,e){const{format:i,signal:a}=e,s=Math.round(e.width),r=Math.round(e.height);if(!Number.isFinite(s)||!Number.isFinite(r)||s<2||r<2||s>4096||r>4096||s*r>16777216)throw new Error("Choose export dimensions between 2 and 4096 pixels.");if(!["png","jpeg","mp4","webm","gif"].includes(i))throw new Error("Unknown export format.");if(void 0!==e.fps&&!Number.isFinite(e.fps))throw new Error("Frames per second must be finite.");const n=Math.max(1,Math.min(60,Math.round(e.fps??24))),o=e.duration??5;if(!Number.isFinite(o)||o<=0||o>60)throw new Error("Choose a duration from 0 to 60 seconds.");const h="png"===i||"jpeg"===i,l=e.time??0;if(!Number.isFinite(l)||l<0)throw new Error("Image time must be a finite non-negative number.");if(void 0!==e.motionTime&&(!Number.isFinite(e.motionTime)||e.motionTime<0))throw new Error("Motion time must be a finite non-negative number.");if(!h&&s*r>8294400)throw new Error("Video exports support up to 3840 × 2160 pixels.");if("gif"===i&&(s*r>921600||o*n>600))throw new Error("GIF export supports up to 1280 × 720 and 600 frames. Use MP4 for larger exports.");if(void 0!==e.referenceWidth&&(!Number.isFinite(e.referenceWidth)||e.referenceWidth<1))throw new Error("Reference width must be a positive number.");if("gif"===i&&n>30)throw new Error("GIF exports support up to 30 fps. Choose MP4 or WebM for higher frame rates.");const c=document.createElement("canvas");let m;try{if(Ae(a),e.onProgress?.(0),h){if(await t(c,l,s,r,a,e.motionTime),"unavailable"===c.dataset.studioFinish)throw new Error("Optical effects need WebGL. Disable these effects or export in a supported browser.");Ae(a);const n=await new Promise((t,a)=>c.toBlob(e=>e?t(e):a(new Error("Image export failed.")),"png"===i?"image/png":"image/jpeg",e.quality??.92));return Ae(a),e.onProgress?.(1),n}const u=Math.ceil(o*n);if("gif"===i){const i=await import("gifenc"),{GIFEncoder:h,quantize:l,applyPalette:m}="function"==typeof i.GIFEncoder?i:i.default,f=h(),d=c.getContext("2d");for(let i=0;i<u;i++){Ae(a);const h=i/n;if(await t(c,h,s,r,a),Ae(a),"unavailable"===c.dataset.studioFinish)throw new Error("Optical effects need WebGL. Disable these effects or export in a supported browser.");const p=d.getImageData(0,0,s,r).data,g=l(p,256),M=m(p,g);f.writeFrame(M,s,r,{palette:g,delay:10*(Math.round(100*Math.min((i+1)/n,o))-Math.round(100*i/n)),repeat:0}),e.onProgress?.((i+1)/u*.98),await new Promise(t=>setTimeout(t,0))}return Ae(a),f.finish(),e.onProgress?.(1),new Blob([new Uint8Array(f.bytes())],{type:"image/gif"})}const{Output:f,Mp4OutputFormat:d,WebMOutputFormat:p,BufferTarget:g,CanvasSource:M,canEncodeVideo:x}=await import("mediabunny"),v="mp4"===i?"avc":"vp9";if(!await x(v,{width:s,height:r}))throw new Error(`${i.toUpperCase()} encoding is unavailable in this browser. Try another format or a current browser with WebCodecs.`);const y=new f({format:"mp4"===i?new d({fastStart:"in-memory"}):new p,target:new g});c.width=s,c.height=r,m=()=>y.cancel();const b=new M(c,{codec:v,bitrate:Math.max(5e5,Math.round(s*r*n*.15))});y.addVideoTrack(b,{frameRate:n}),c.width=s,c.height=r,await y.start();for(let i=0;i<u;i++){Ae(a);const h=i/n;if(await t(c,h,s,r,a),Ae(a),"unavailable"===c.dataset.studioFinish)throw new Error("Optical effects need WebGL. Disable these effects or export in a supported browser.");await b.add(h,Math.min(1/n,o-h)),e.onProgress?.((i+1)/u*.98),i%4==0&&await new Promise(t=>setTimeout(t,0))}return b.close(),Ae(a),await y.finalize(),Ae(a),m=void 0,e.onProgress?.(1),new Blob([y.target.buffer],{type:"mp4"===i?"video/mp4":"video/webm"})}catch(t){throw await(m?.().catch(()=>{})),t}finally{c.width=c.height=1}}var Fe=class{constructor(){this.stride=1,this.period=1/0,this.last=0,this.short=0,this.shortCount=0,this.lateRun=0,this.grace=0,this.probeAt=0,this.delay=500,this.probing=-1}tick(t,e,i){const a=this.last?t-this.last:0;if(this.last=t,a<3||a>100)return this.lateRun=0,this.stride;if(this.short+=a,8===++this.shortCount&&(this.period=Math.min(this.period,this.short/8),this.short=this.shortCount=0),!Number.isFinite(this.period))return this.stride;const s=e||a>1.25*this.period;return this.grace>0?(this.grace--,this.lateRun=0):this.lateRun=s?this.lateRun+1:0,this.probing>=0&&t-this.probing>=500&&(this.probing=-1,this.delay=500),this.lateRun>=8&&i>.4*this.period&&this.stride<4?(this.probing>=0&&(this.delay=Math.min(1e3,2*this.delay)),this.probing=-1,this.stride++,this.lateRun=0,this.grace=8,this.probeAt=t+this.delay):this.stride>1&&t>=this.probeAt&&(this.stride=1,this.lateRun=0,this.grace=8,this.probing=t,this.probeAt=t+this.delay),this.stride}reset(){this.stride=1,this.lateRun=this.grace=0,this.delay=500,this.probing=-1,this.last=0}},Ee=null,Re=()=>Ee??(Ee=Promise.resolve().then(()=>(n(),r)).then(({default:t})=>t?URL.createObjectURL(new Blob([t],{type:"text/javascript"})):null,()=>null)),Te=null;function Pe(){if(null!==Te)return Te;try{Te="function"==typeof Worker&&"function"==typeof OffscreenCanvas&&"function"==typeof createImageBitmap&&"transferToImageBitmap"in OffscreenCanvas.prototype&&!!new OffscreenCanvas(1,1).getContext("2d")}catch{Te=!1}return Te}var Ce=new WeakSet;function Ie(t,e,i,a,s={width:960,height:540}){let r=null;const n=xe(i.maxDimension),[o,h]=ve(n,Math.max(2,s.width),Math.max(2,s.height)),l=navigator.hardwareConcurrency??2,c=t=>Math.max(1,Math.min(l>=8?3:l>=4?2:1,Math.floor(6e6/t))),m=c(o*h);let u=o*h;const f=[],d=[];let p=m>Math.min(2,m)?[]:null;const g=Math.max(256,Math.min(1048576,Number.isFinite(i.maxCells)?i.maxCells:12e3));let M=g,x=Math.max(.1,Math.min(8,i.pixelRatio??1));const v=()=>2*f.length;let y,b=!1,w=!1,k=0,A=null,S=!1,F=!1,E="none",R=JSON.stringify(tt(e).crop),T=null,P=null,C="",I=!0,D=new WeakMap,N=0,U=[],O=null;const L=t=>{if(!b){for(const e of f)e.post(t);if(p?.push({message:t}),p&&p.length>4096){for(const{spares:t}of p)t?.forEach(t=>t.close());p=null}}},q=t=>{w?a.error(new Error(t)):(G(),a.unavailable())};let X=[];const z=()=>{let t=!1;for(;U.length&&void 0!==U[0].reply;){const e=U.shift();e.reply&&(X.push(e),t=!0)}for(;X.length>2;)X.shift().reply.bitmap.close();t&&a.ready()},B=t=>{const e=t.worker=new Worker(r);e.onmessage=t=>{const e=t.data;if(b)return void("frame"===e.type&&e.bitmap.close());if("ready"===e.type)return;"error"===e.type&&q(e.message);const i=U.find(t=>t.seq===e.seq);i?(i.reply="frame"===e.type?e:null,"frame"===e.type&&p&&d.push(e.cost)>=3&&function(t){const e=p;p=null;const i=Math.min(m,c(u),Math.max(f.length,Math.ceil(t/7)))-f.length;for(let t=0;t<i;t++){const i=Y();i.post(j);for(const{message:a,spares:s}of e)if("source"===a.type){const e=s[t];i.post({...a,scene:e},[e])}else i.post("render"===a.type?{...a,type:"advance"}:a)}for(const{spares:t}of e)t?.slice(Math.max(0,i)).forEach(t=>t.close())}(d.sort((t,e)=>t-e)[1]),z()):"frame"===e.type&&e.bitmap.close()},e.onerror=t=>{t.preventDefault?.(),q(t.message||"The Studio worker failed.")};for(const[i,a]of t.waiting)e.postMessage(i,a);t.waiting=[]},Y=()=>{const t={worker:null,waiting:[],post(e,i=[]){t.worker?t.worker.postMessage(e,i):t.waiting.push([e,i])}};return f.push(t),r&&B(t),t},j={type:"init",settings:e,limits:{maxDimension:i.maxDimension,maxCells:i.maxCells},pixelRatio:x,budget:M};for(let t=Math.min(2,m);t>0;t--)Y().post(j);Re().then(t=>{b||(t?(r=t,f.forEach(B)):q("The Studio worker could not load."))});function G(){if(!b){b=!0;for(const t of f)t.worker?.terminate();for(const{spares:t}of p??[])t?.forEach(t=>t.close());for(const t of f)for(const[,e]of t.waiting)for(const t of e)t.close?.();p=null;for(const t of[...U,...X])t.reply?.bitmap.close();U=[],X=[],T&&(T.width=T.height=1),T=P=null,D=new WeakMap}}return{get turns(){return f.length},get busy(){return U.length>=v()},get drawing(){return U.length>0||X.length>0},show:()=>{const e=X.shift();return!!e?.reply&&(S=e.reply.active||X.some(t=>t.reply.active),E=e.reply.finish,i=e.reply.bitmap,t.width!==i.width&&(t.width=i.width),t.height!==i.height&&(t.height=i.height),void 0===y&&(y=t.getContext("bitmaprenderer"),y||(O=t.getContext("2d"))),y?y.transferFromImageBitmap(i):(O?.clearRect(0,0,t.width,t.height),O?.drawImage(i,0,0),i.close()),t.dataset.studioFinish=E,w=!0,a.frame(e.time,e.reply.cost),!0);var i},render(t,e,i,a,s,r){if(b||U.length>=v())return!1;const[o,h]=ne(t);if(!o||!h)return!1;const[l,d]=ve(n,i,a);for(u=l*d;f.length>c(u);){const t=f.pop();t.worker?.terminate();for(const[,e]of t.waiting)for(const t of e)t.close?.();for(const e of U)e.lane===t&&void 0===e.reply&&(e.reply=null);z()}const g=++k,M=f[g%f.length];U.push({seq:g,time:e,input:F,lane:M}),F=!1;const x=(t=>{let e=D.get(t);return void 0===e&&D.set(t,e=++N),e})(t),y=()=>{if(!b){for(const t of f)t.post({type:t===M?"render":"advance",seq:g,time:e,width:i,height:a,motionTime:s});p?.push({message:{type:"advance",seq:g,time:e,width:i,height:a,motionTime:s}})}},w=[x,r.video?r.time:0,l,d,R].join(":");if(!I&&w===C)return A?A.then(y):y(),!0;I=!1,C=w;const S=()=>{if(b)throw new DOMException("Cancelled","AbortError");return T||(T=document.createElement("canvas"),P=T.getContext("2d")),T.width!==l&&(T.width=l),T.height!==d&&(T.height=d),ye(P,t,l,d,JSON.parse(R)),Promise.all(Array.from({length:f.length+(p?m-f.length:0)},()=>createImageBitmap(T)))},E=t instanceof HTMLImageElement&&!Ce.has(t)?t.decode().catch(()=>{}).then(()=>{Ce.add(t)}):null,O=(A??Promise.resolve()).then(()=>E?E.then(S):S()).then(t=>{if(b){for(const e of t)e.close();return}const e={type:"source",scene:t[0],width:o,height:h,video:r.video,time:r.time,key:x};f.forEach((i,a)=>i.post({...e,scene:t[a]},[t[a]])),p?p.push({message:e,spares:t.slice(f.length)}):t.slice(f.length).forEach(t=>t.close()),y()},t=>{const e=U.find(t=>t.seq===g);e&&(e.reply=null,z()),I=!0,b||q(t instanceof Error?t.message:String(t))});return A=O,O.then(()=>{A===O&&(A=null)}),!0},pointer(t,e,i){F=!0,L({type:"pointer",x:t,y:e,time:i})},leave(){F=!0,L({type:"leave"})},configure(t){R=JSON.stringify(tt(t).crop),L({type:"configure",settings:t})},setBudget(t){M=Math.max(256,Math.min(g,Number.isFinite(t)?Math.round(t):g)),L({type:"budget",cells:t})},get maxCells(){return M},setPixelRatio(t){x=Math.max(.1,Math.min(8,Number.isFinite(t)?t:1)),L({type:"ratio",ratio:t})},get pixelRatio(){return x},get active(){return S||F||U.some(t=>t.input)||X.some(t=>t.input||t.reply.active)},get capabilities(){return{gpuFinish:"unavailable"!==E}},invalidate(){I=!0,L({type:"invalidate"})},destroy:G}}function De(t,e,i={}){let a,s=tt(i.settings),r=i.width??e.width,n=i.height??e.height,o=null;const h=()=>be(t,s,i);if(Pe())try{a=o=Ie(t,s,i,{frame:function(t,r){if(m)return;i.onFrame?.(t,r),q(r/(o?.turns??1),D()&&(e.animated||bt(s))),y=a.active,b||y||u||o?.drawing?I():T()&&(u=!0,I())},ready:()=>I(),unavailable(){const t=a.maxCells,e=a.pixelRatio;o=null,a=h(),a.setBudget(t),a.setPixelRatio(e),u=!0,I()},error:X},{width:r,height:n})}catch{o=null,a=h()}else a=h();const l=new k;let c=0,m=!1,u=!0,f=!1,d=!0,p=0,g=0,M=0,x=0,v=-1,y=!1,b=!1,w=!1!==i.adaptive,A=0,S=0,F=0,E=0,R=a.maxCells;const T=()=>!(a.maxCells>=R)&&(a.setBudget(R),i.onQualityChange?.(a.maxCells),F=E=S=A=0,!0),P=matchMedia("(prefers-reduced-motion: reduce)"),C=e.source instanceof HTMLVideoElement?e.source:null,I=()=>{m||c||!d||document.hidden||(c=requestAnimationFrame(U))},D=()=>!f&&!P.matches&&d&&!document.hidden,N=()=>{C&&(C.loop=!0,D()?C.play().catch(()=>{f=!0,u=!0,I()}):C.pause()),M=0,u=!0,I()};function U(t){if(c=0,m||!d||document.hidden)return;const h=o?.show()??!1;h&&o.drawing&&I();const f=D();f&&(p+=M?Math.min(.1,(t-M)/1e3):0),M=t;const w=bt(s),k=f&&(e.animated||w),A=C?.getVideoPlaybackQuality?.().totalVideoFrames??-1,F=!C||A<0||A!==v,E=1e3/Math.max(1,Math.min(60,i.fps??60))-.5,R=u||(a.active?o||t-x>=Math.max(E,2*S):y)||k&&(F||w)&&t-x>=E;if(o&&(O.tick(t,a.active&&1===O.stride&&!h&&o.drawing,S),L++),R&&o&&!u&&L%O.stride)b=!0;else if(R&&o)if(o.busy)b=!0;else{e.animated&&!C&&o.invalidate();const[i,a]=it(r,n,s);g=l.update(p,s.motion.type,s.motion.speed);const h=C?.currentTime??p;(o.render(e.frame(h),h,i,a,g,{video:!!C,time:A})||u)&&(u=!1,x=t,b=!1,v=A)}else if(R){const o=performance.now();try{e.animated&&!C&&a.invalidate();const[t,h]=it(r,n,s);g=l.update(p,s.motion.type,s.motion.speed),a.render(e.frame(C?.currentTime??p),p,t,h,g);const c=performance.now()-o;i.onFrame?.(C?.currentTime??p,c),q(c,k)}catch(t){X(t)}u=!1,x=t,y=a.active,v=A}f&&(k||a.active||b)?I():k||a.active||o?.drawing||!T()||(u=!0,I())}const O=new Fe;let L=0;function q(t,e){if(S=S?.9*S+.1*t:t,++A>20&&w&&(e||a.active)){const t=1e3/Math.max(1,Math.min(60,i.fps??60));F=S>1.1*t?F+1:0,E=S<.5*t?E+1:0,F>=20&&a.maxCells>3e3?(a.setBudget(Math.max(3e3,.8*a.maxCells)),i.onQualityChange?.(a.maxCells),F=0,S=0):E>=30&&a.maxCells<R&&(a.setBudget(Math.min(R,1.25*a.maxCells)),i.onQualityChange?.(a.maxCells),E=0,S=0)}}function X(t){f=!0,i.onError?.(t instanceof Error?t:new Error(String(t)))}const z=e=>{if(!D())return;a.active||O.reset();const i=t.getBoundingClientRect();a.pointer((e.clientX-i.left)/i.width,(e.clientY-i.top)/i.height,e.timeStamp),I()},B=()=>{a.leave(),I()},Y=t=>{"touch"===t.pointerType&&B()},j=new IntersectionObserver(([t])=>{d=t.isIntersecting,N()});j.observe(t),t.addEventListener("pointermove",z),t.addEventListener("pointerup",Y),t.addEventListener("pointerleave",B),t.addEventListener("pointercancel",B),document.addEventListener("visibilitychange",N),P.addEventListener("change",N);const G=()=>{m||(m=!0,cancelAnimationFrame(c),j.disconnect(),t.removeEventListener("pointermove",z),t.removeEventListener("pointerup",Y),t.removeEventListener("pointerleave",B),t.removeEventListener("pointercancel",B),document.removeEventListener("visibilitychange",N),P.removeEventListener("change",N),i.signal?.removeEventListener("abort",G),a.destroy(),e.destroy())};if(i.signal?.addEventListener("abort",G,{once:!0}),i.signal?.aborted)throw G(),new DOMException("Cancelled","AbortError");return N(),{canvas:t,media:e,update(t){s=at(s,t),a.configure(s),u=!0,I()},resize(t,e,i){void 0!==i&&a.setPixelRatio(i),r=Math.max(2,t),n=Math.max(2,e),u=!0,I()},pause(t=!0){f=t,N()},async seek(t){p=Math.max(0,t),await e.seek(p),a.invalidate(),u=!0,I()},redraw(){a.invalidate(),u=!0,I()},get time(){return C?.currentTime??p},get settings(){return tt(s)},get motionTime(){return g},get paused(){return f||P.matches},setAdaptive(t){w=t,A=F=S=0},setBudget(t){a.setBudget(t),R=a.maxCells,F=E=S=A=0,i.onQualityChange?.(a.maxCells),u=!0,I()},get pixelRatio(){return a.pixelRatio},get maxCells(){return a.maxCells},get capabilities(){return a.capabilities},destroy:G}}var Ne={Standard:()=>import("figlet/fonts/Standard"),Slant:()=>import("figlet/fonts/Slant"),Small:()=>import("figlet/fonts/Small"),Big:()=>import("figlet/fonts/Big"),Banner:()=>import("figlet/fonts/Banner"),Block:()=>import("figlet/fonts/Block"),Bubble:()=>import("figlet/fonts/Bubble"),Digital:()=>import("figlet/fonts/Digital"),Doom:()=>import("figlet/fonts/Doom"),Lean:()=>import("figlet/fonts/Lean"),Mini:()=>import("figlet/fonts/Mini"),Script:()=>import("figlet/fonts/Script"),Shadow:()=>import("figlet/fonts/Shadow"),Speed:()=>import("figlet/fonts/Speed"),Starwars:()=>import("figlet/fonts/Star Wars"),Stop:()=>import("figlet/fonts/Stop"),Straight:()=>import("figlet/fonts/Straight"),Thin:()=>import("figlet/fonts/Thin"),ThreeD:()=>import("figlet/fonts/3-D"),Univers:()=>import("figlet/fonts/Univers"),Wavy:()=>import("figlet/fonts/Wavy")},Ue=Object.keys(Ne);async function Oe(t,e="Standard",i="#ffffff",a="#080808"){if(!Object.prototype.hasOwnProperty.call(Ne,e))throw new Error("Unknown text font.");const{default:s}=await import("figlet/browser"),r=await Ne[e]();s.parseFont(e,r.default),s.defaults({fetchFontIfMissing:!1});const n=s.textSync(t.slice(0,120),{font:e}),o=n.split("\n"),h=Math.max(1,...o.map(t=>t.length)),l=Math.max(1,o.length),c=Math.min(1,2048/(9*h)),m=document.createElement("canvas");m.width=Math.ceil(9*h*c+32),m.height=Math.ceil(15*l*c+32);const u=m.getContext("2d");return null!==a&&(u.fillStyle=a,u.fillRect(0,0,m.width,m.height)),u.fillStyle=i,u.font=15*c+"px monospace",u.textBaseline="top",o.forEach((t,e)=>u.fillText(t,16,16+15*e*c)),{canvas:m,ascii:n}}var Le={standard:{label:"Classic ASCII",chars:" .:-=+*#%@"},asciify:{label:"Asciify",chars:" .:-=+YCIFSA#@"},minimal:{label:"Minimal",chars:" .:+"},detailed:{label:"Detailed",chars:" .,:;-~=+*xX#%@"},letters:{label:"Letters",chars:" .liLTYCFSAWM"},technical:{label:"Technical",chars:" ._:;+/>=][{}*$#@"},blocks:{label:"Tonal blocks",chars:" ░▒▓█"},braille:{label:"Braille",chars:" ⠁⠃⠇⡇⣇⣧⣷⣿"}},qe=Le,Xe=t=>t&&"object"==typeof t&&!Array.isArray(t)?t:{},ze=(t,e,i,a)=>"number"==typeof t&&Number.isFinite(t)?Math.max(i,Math.min(a,t)):e,Be=(t,e)=>{if("string"!=typeof t||!/^[a-zA-Z0-9][a-zA-Z0-9:_-]{0,63}$/.test(t))throw new Error(`${e} must be 1–64 letters, numbers, colons, dashes or underscores, starting with a letter or number.`);return t};function Ye(t={}){const e=Xe(t);if(void 0!==e.kind&&"asciify-project"!==e.kind||void 0!==e.version&&1!==e.version)throw new Error("Unsupported Studio project. Update asciify-engine.");if(void 0!==e.layers&&!Array.isArray(e.layers))throw new Error("Project layers must be an array.");const i=Array.isArray(e.layers)?e.layers:[];if(i.length>8)throw new Error("A project supports up to 8 layers.");const a=new Set;return{kind:"asciify-project",version:1,width:Math.round(ze(e.width,1280,2,4096)),height:Math.round(ze(e.height,720,2,4096)),background:null===e.background?null:"string"==typeof e.background&&/^#[a-f\d]{6}$/i.test(e.background)?e.background:"#0c1711",pointerMode:"all"===e.pointerMode?"all":"top",layers:i.map((t,e)=>{const i=Xe(t),s=Xe(i.placement),r=Xe(i.settings),n=Xe(r.backdrop),o=Be(i.id,"Layer id"),h=Be(i.source,"Source key");if(a.has(o))throw new Error(`Duplicate layer id: ${o}`);return a.add(o),{id:o,source:h,name:"string"==typeof i.name?i.name.slice(0,80):`Layer ${e+1}`,visible:!1!==i.visible,opacity:ze(i.opacity,1,0,1),blend:V.includes(i.blend)?i.blend:"source-over",placement:{x:ze(s.x,.5,-1,2),y:ze(s.y,.5,-1,2),width:ze(s.width,1,.01,2),height:ze(s.height,1,.01,2),rotation:ze(s.rotation,0,-180,180),flipX:!0===s.flipX,flipY:!0===s.flipY},settings:tt({...r,backdrop:{mode:"transparent",...n}})}})}}function je(t,e,i){if(!t.layers.some(t=>t.id===e))throw new Error(`Unknown layer: ${e}`);return Ye({...t,layers:t.layers.map(t=>t.id!==e?t:{...t,...i,id:e,placement:{...t.placement,...i.placement},settings:at(t.settings,i.settings??{})})})}function Ge(t,e,i,a,s){const r=t.placement,n=r.rotation*Math.PI/180,o=Math.cos(n),h=Math.sin(n),l=(e-r.x)*a,c=(i-r.y)*s,m=(l*o+c*h)/(r.width*a),u=(-l*h+c*o)/(r.height*s);return[.5+m*(r.flipX?-1:1),.5+u*(r.flipY?-1:1)]}function He(t){return t.layers.filter(e=>{if(!e.visible||e.opacity<=0)return!1;const i=e.placement,a=i.rotation*Math.PI/180,s=Math.abs(Math.cos(a)),r=Math.abs(Math.sin(a)),n=(s*i.width*t.width+r*i.height*t.height)/2,o=(r*i.width*t.width+s*i.height*t.height)/2;return i.x*t.width+n>0&&i.x*t.width-n<t.width&&i.y*t.height+o>0&&i.y*t.height-o<t.height})}function We(t,e=24e3,i=4194304,a=t.width,s=t.height){const r=He(t),n=Math.round(ze(e,24e3,2048,1048576)),o=ze(i,4194304,65536,16777216),h=r.map(t=>t.placement.width*t.placement.height),l=h.reduce((t,e)=>t+e,0),c=n-256*r.length,m=r.map(t=>{const e=a*t.placement.width,i=s*t.placement.height,r=Math.min(1,4096/Math.max(e,i));return{width:Math.max(2,e*r),height:Math.max(2,i*r)}}),u=m.reduce((t,e)=>t+e.width*e.height,0);let f=0,d=0;return r.map((t,e)=>{const i=e===r.length-1?n-f:256+Math.floor(c*h[e]/l);f+=i;const a=m[e],s=e===r.length-1?o-d:4+Math.floor((o-4*r.length)*a.width*a.height/Math.max(1,u));d+=s;const p=Math.min(1,Math.sqrt(s/(a.width*a.height)));let g=Math.max(2,Math.floor(a.width*p)),M=Math.max(2,Math.floor(a.height*p));return g*M>s&&(g>=M?g=Math.max(2,Math.floor(s/M)):M=Math.max(2,Math.floor(s/g))),{id:t.id,maxCells:i,width:g,height:M}})}function Ve(t,e={},i={}){const a=t.getContext("2d");if(!a)throw new Error("Project canvas is already owned by another renderer.");let s=Ye(e),r=!0,n=!1,o=new Map(s.layers.map(t=>[t.id,JSON.stringify(t.settings)]));const h=Math.max(64,Math.min(4096,Number.isFinite(i.maxDimension)?i.maxDimension:960)),l=Math.max(2048,Math.min(1048576,Number.isFinite(i.maxCells)?i.maxCells:24e3));let c=l,m=Math.max(.1,Math.min(8,Number.isFinite(i.pixelRatio)?i.pixelRatio:1)),u=[];const f=new Map,d=()=>{if(n)throw new Error("Project renderer has been destroyed.")};return{canvas:t,render(e,n=0,p=s.width,g=s.height,M={}){if(d(),!Number.isFinite(p)||!Number.isFinite(g)||p<2||g<2)throw new Error("Project dimensions must be positive finite numbers.");const x=Math.min(1,h/Math.max(p,g)),v=Math.max(2,Math.round(p*x)),y=Math.max(2,Math.round(g*x));t.width===v&&t.height===y||(t.width=v,t.height=y,r=!0);const b={...s,width:v,height:y},w=He(b);for(const t of w)if(!e.has(t.source))throw new Error(`Missing project source: ${t.source}`);const k=new Set(w.map(t=>t.id));for(const[t,e]of f)k.has(t)||(e.renderer.destroy(),f.delete(t),r=!0);u=We(b,c,i.maxRasterPixels,v,y);for(let t=0;t<w.length;t++){const i=w[t],a=u[t],s=e.get(i.source);if(!s)throw new Error(`Missing project source: ${i.source}`);let h=f.get(i.id);const c=o.get(i.id);h?h.signature!==c&&(h.renderer.configure(i.settings),h.signature=c,h.dirty=!0):(h={renderer:be(document.createElement("canvas"),i.settings,{maxDimension:4096,maxCells:l}),signature:c,dirty:!0,geometry:""},f.set(i.id,h));const d=m*a.width/(p*i.placement.width),g=`${a.width}:${a.height}:${a.maxCells}:${d}`;h.geometry!==g&&(h.renderer.setBudget(a.maxCells),h.renderer.setPixelRatio(d),h.geometry=g,h.dirty=!0);const x="currentTime"in s?s.getVideoPlaybackQuality?.().totalVideoFrames??s.currentTime:0;if(h.dirty||h.source!==s||h.stamp!==x||h.renderer.active||bt(i.settings)){const t=Object.prototype.hasOwnProperty.call(M,i.id)?M[i.id]:void 0;h.renderer.render(s,n,a.width,a.height,t),h.dirty=!1,h.source=s,h.stamp=x,r=!0}}if(!r)return!1;a.clearRect(0,0,v,y),a.globalCompositeOperation="source-over",a.globalAlpha=1,null!==s.background&&(a.fillStyle=s.background,a.fillRect(0,0,v,y));let A="none";for(const t of w){const e=f.get(t.id),i=t.placement;a.save(),a.globalAlpha=t.opacity,a.globalCompositeOperation=t.blend;try{a.translate(i.x*v,i.y*y),a.rotate(i.rotation*Math.PI/180),a.scale(i.flipX?-1:1,i.flipY?-1:1),a.drawImage(e.renderer.canvas,-i.width*v/2,-i.height*y/2,i.width*v,i.height*y)}finally{a.restore()}"unavailable"===e.renderer.canvas.dataset.studioFinish?A="unavailable":"unavailable"!==A&&"gpu"===e.renderer.canvas.dataset.studioFinish&&(A="gpu")}return a.globalAlpha=1,a.globalCompositeOperation="source-over",t.dataset.studioFinish=A,r=!1,!0},configure(t){d(),s=Ye(t),o=new Map(s.layers.map(t=>[t.id,JSON.stringify(t.settings)])),(()=>{const t=new Set(He(s).map(t=>t.id));for(const[e,i]of f)t.has(e)||(i.renderer.destroy(),f.delete(e))})(),r=!0},pointer(e,i,a){if(n||!Number.isFinite(e)||!Number.isFinite(i))return;if(e<0||e>1||i<0||i>1){for(const t of f.values())t.renderer.leave();return}let r=!1;for(const n of He({...s,width:t.width,height:t.height}).reverse()){const o=f.get(n.id);if(!o)continue;const[h,l]=Ge(n,e,i,t.width,t.height);(!r||"all"===s.pointerMode)&&h>=0&&h<=1&&l>=0&&l<=1&&"none"!==n.settings.hover.effect&&n.settings.hover.strength>0?(o.renderer.pointer(h,l,a),r=!0):o.renderer.leave()}},leave(){for(const t of f.values())t.renderer.leave()},invalidate(t){d();for(const e of s.layers)if(void 0===t||t===e.source){const t=f.get(e.id);t&&(t.renderer.invalidate(),t.dirty=!0)}r=!0},setBudget(t){d(),c=Math.max(2048,Math.min(l,Number.isFinite(t)?Math.round(t):l)),r=!0},setPixelRatio(t){d(),m=Math.max(.1,Math.min(8,Number.isFinite(t)?t:1)),r=!0},get maxCells(){return c},get pixelRatio(){return m},get quality(){return u.map(t=>({...t}))},get active(){return[...f.values()].some(t=>t.renderer.active)},destroy(){if(!n){n=!0;for(const t of f.values())t.renderer.destroy();f.clear(),t.width=t.height=1}}}}function Ke(t,e){for(const i of t.layers)if(!e.has(i.source))throw new Error(`Missing project source: ${i.source}`)}async function Je(t,e,i){const a=Object.entries(e),s=new Map;if(a.length>8)throw new Error("A project supports up to 8 media bindings.");Ke(t,new Map(a));try{for(const[t,e]of a){if(i?.aborted)throw new DOMException("Cancelled","AbortError");if("string"==typeof e||"undefined"!=typeof File&&e instanceof File)s.set(t,await ke(e,i));else{if(!e||"object"!=typeof e||!("text"in e)||"string"!=typeof e.text)throw new Error(`Invalid project source: ${t}`);{const i=e,{canvas:a}=await Oe(i.text,i.font,i.ink??"#ffffff",null);s.set(t,{source:a,width:a.width,height:a.height,duration:0,animated:!1,frame:()=>a,seek:async()=>{},destroy:()=>{a.width=a.height=1}})}}}if(i?.aborted)throw new DOMException("Cancelled","AbortError");return s}catch(t){for(const t of s.values())t.destroy();throw t}}function Qe(t,e,i,a={}){if((i=new Map(i)).size>8)throw new Error("A project supports up to 8 media bindings.");let s=Ye(e);if(Ke(s,i),a.signal?.aborted)throw new DOMException("Cancelled","AbortError");const r=Ve(t,s,a),n=matchMedia("(prefers-reduced-motion: reduce)"),o=[...new Set(i.values())],h=o.filter(t=>t.source instanceof HTMLVideoElement).map(t=>t.source),l=new Map;let c,m={},u=0,f=0,d=0,p=0,g=!0,M=!1,x=!0,v=!1,y=!1!==a.adaptive,b=0,w=0,A=0,S=0,F=s.width,E=s.height,R=0,T=!1,P=r.maxCells;const C=new WeakSet,I=Math.max(1,Math.min(60,Number.isFinite(a.fps)?a.fps:60)),D=()=>!v&&!M&&!T&&!n.matches&&x&&!document.hidden,N=()=>{v||p||!x||document.hidden||(p=requestAnimationFrame(q))},U=()=>new Set(He({...s,width:F,height:E}).map(t=>i.get(t.source).source)),O=()=>{const t=U();for(const e of h)e.loop=!0,D()&&t.has(e)?e.paused&&!C.has(e)&&(C.add(e),e.play().then(()=>{C.delete(e),D()&&U().has(e)||e.pause()}).catch(t=>{C.delete(e),v||(M=!0,O(),a.onError?.(t instanceof Error?t:new Error(String(t))),g=!0,N())})):e.pause()},L=()=>{f=0,g=!0,O(),N()};function q(t){if(p=0,v||!x||document.hidden)return;const e=D();e&&(u+=f?Math.min(.1,(t-f)/1e3):0),f=t;const n=He({...s,width:F,height:E}),o=n.some(t=>i.get(t.source).animated||bt(t.settings));if(g||e&&r.active||e&&o&&t-d>=1e3/I-.5){const s=performance.now();try{const t=new Map,h=new Set(n.map(t=>t.source));for(const a of h){const s=i.get(a);!s.animated||s.source instanceof HTMLVideoElement||!e||r.invalidate(a),t.set(a,s.frame(u))}m={};for(const t of n){let e=l.get(t.id);e||(e=new k,l.set(t.id,e)),m[t.id]=e.update(u,t.settings.motion.type,t.settings.motion.speed)}r.render(t,u,F,E,m);const c=performance.now()-s;if(a.onFrame?.(u,c),w=w?.9*w+.1*c:c,++b>20&&y&&e&&(o||r.active)){const t=1e3/I;A=w>1.1*t?A+1:0,S=w<.5*t?S+1:0,A>=20&&r.maxCells>2048?(r.setBudget(Math.max(2048,.8*r.maxCells)),a.onQualityChange?.(r.maxCells),w=A=0,g=!0):S>=30&&r.maxCells<P&&(r.setBudget(Math.min(P,1.25*r.maxCells)),a.onQualityChange?.(r.maxCells),w=S=0,g=!0)}}catch(t){M=!0,O(),a.onError?.(t instanceof Error?t:new Error(String(t)))}g=!1,d=t}e&&(o||r.active)?N():!o&&!r.active&&r.maxCells<P&&(r.setBudget(P),a.onQualityChange?.(r.maxCells),b=A=S=w=0,g=!0,N())}const X=e=>{if(!D())return;const i=t.getBoundingClientRect();i.width&&i.height&&(r.pointer((e.clientX-i.left)/i.width,(e.clientY-i.top)/i.height,e.timeStamp),N())},z=()=>{r.leave(),N()},B=new IntersectionObserver(([t])=>{x=t.isIntersecting,L()});B.observe(t),t.addEventListener("pointermove",X),t.addEventListener("pointerleave",z),t.addEventListener("pointercancel",z),document.addEventListener("visibilitychange",L),n.addEventListener("change",L);const Y=()=>{if(!v){v=!0,R++,c?.abort(),cancelAnimationFrame(p),p=0,B.disconnect(),t.removeEventListener("pointermove",X),t.removeEventListener("pointerleave",z),t.removeEventListener("pointercancel",z),document.removeEventListener("visibilitychange",L),n.removeEventListener("change",L),a.signal?.removeEventListener("abort",Y),r.destroy();for(const t of o)t.destroy();l.clear()}};a.signal?.addEventListener("abort",Y,{once:!0});const j=()=>{if(v)throw new Error("Project player has been destroyed.")},G=t=>{j();const e=Ye(t);Ke(e,i),F===s.width&&E===s.height&&(F=e.width,E=e.height),s=e,r.configure(s);for(const t of l.keys())s.layers.some(e=>e.id===t)||l.delete(t);L()};return L(),{canvas:t,get project(){return Ye(s)},get time(){return u},get motionTimes(){return{...m}},get paused(){return M||n.matches},get maxCells(){return r.maxCells},get pixelRatio(){return r.pixelRatio},get quality(){return r.quality},update:G,updateLayer:(t,e)=>G(je(s,t,e)),resize(t,e,i){if(j(),!Number.isFinite(t)||!Number.isFinite(e)||t<2||e<2)throw new Error("Project dimensions must be positive finite numbers.");F=t,E=e,void 0!==i&&r.setPixelRatio(i),L()},pause(t=!0){j(),M=t,L()},async seek(t){if(j(),!Number.isFinite(t)||t<0)throw new Error("Project time must be finite and non-negative.");const e=++R;c?.abort(),c=new AbortController;const i=c.signal;T=!0,O();try{if(await Promise.all(o.map(e=>e.seek(t,i))),v||e!==R)return;u=t,l.clear(),r.invalidate()}finally{v||e!==R||(T=!1,L())}},redraw(){j(),r.invalidate(),g=!0,N()},setBudget(t){j(),r.setBudget(t),P=r.maxCells,b=A=S=w=0,a.onQualityChange?.(r.maxCells),g=!0,N()},setAdaptive(t){y=t,b=A=S=w=0},destroy:Y}}exports.BLEND_MODES=V,exports.CHARACTER_SETS=Le,exports.DEFAULT_HOVER=c,exports.DEFAULT_STUDIO_PRINT=j,exports.DEFAULT_STUDIO_SETTINGS=J,exports.DEPRECATED_STUDIO_HOVERS=h,exports.DEPRECATED_STUDIO_MOTIONS=M,exports.DITHER_ALGORITHMS=W,exports.HOVER_CONTROLS=l,exports.HOVER_SCOPES=[{value:"all",label:"Everywhere",description:"The hover acts on the whole artwork."},{value:"subject",label:"Subject",description:"The hover stays on the subject and fades softly at its edge."},{value:"outside",label:"Around",description:"The hover acts only on the ground around the subject."}],exports.MAX_STUDIO_LAYERS=8,exports.MAX_STUDIO_WARPS=8,exports.STUDIO_ANIMATION_PRESETS=[{id:"quiet-light",label:"Quiet light",description:"A key light circles the subject’s own relief, with a soft magnifying wake.",motion:{type:"relight",speed:.6,amount:.8},hover:{effect:"lens",radius:.45,strength:.5}},{id:"living-paper",label:"Memory",description:"A slow push toward the subject; the image leans toward your cursor.",motion:{type:"push",speed:.5,amount:.8},hover:{effect:"tilt",radius:.5,strength:.45}},{id:"silver-grain",label:"Silver light",description:"Sparse glints on bright detail, with a fluid character trail.",motion:{type:"shimmer",speed:.6,amount:.9},hover:{effect:"trail",radius:.35,strength:.55}},{id:"ripple-study",label:"Still water",description:"Smooth water and sky drift like a cinemagraph; your stroke sends out rings.",motion:{type:"current",speed:.6,amount:.8},hover:{effect:"ripple",radius:.45,strength:.7}},{id:"unfolding-print",label:"Darkroom",description:"The print develops from its highlights; your cursor dissolves a soft path.",motion:{type:"develop",speed:.7,amount:1},hover:{effect:"dissolve",radius:.35,strength:.55}},{id:"silk-flow",label:"Morning mist",description:"Mist drifts through the distance; directional folds follow your hand.",motion:{type:"mist",speed:.6,amount:1},hover:{effect:"silk",radius:.4,strength:.5}},{id:"depth-study",label:"Depth study",description:"A slow parallax drift from the photo’s own depth, with a loupe under your cursor.",motion:{type:"parallax",speed:.6,amount:.9},hover:{effect:"loupe",radius:.35,strength:.55}}],exports.STUDIO_CHARACTER_SETS=qe,exports.STUDIO_CURVE_CHANNELS=R,exports.STUDIO_HOVERS=o,exports.STUDIO_LOOKS=rt,exports.STUDIO_MOTIONS=x,exports.STUDIO_PALETTES=K,exports.STUDIO_PRINT_STYLES=[{value:"stipple",label:"Stipple",description:"Scattered ink dots shape the image through their size."},{value:"engraving",label:"Engraving",description:"Continuous parallel cuts change weight with the image."},{value:"crosshatch",label:"Crosshatch",description:"Crossing layers of fine lines build the tonal range."},{value:"woodblock",label:"Woodblock",description:"Broad carved bands with irregular edges and stepped tones."},{value:"risograph",label:"Risograph",description:"Two offset ink screens with adjustable registration."},{value:"pointillism",label:"Pointillism",description:"Small pigment strokes mix source colors into the image."}],exports.STUDIO_PRINT_STYLE_IDS=B,exports.STUDIO_STYLES=H,exports.STUDIO_TEXT_FONTS=Ue,exports.STUDIO_WARPS=U,exports.createStudioCurveLookup=I,exports.createStudioProjectRenderer=Ve,exports.createStudioRenderer=be,exports.createStudioText=Oe,exports.exportStudio=async function(t,e,i){let a;const s=tt(e),r="png"!==i.format&&"jpeg"!==i.format;try{return await Se(async(e,n,o,h,l,c)=>{a??(a=be(e,s,{maxDimension:4096,maxCells:i.maxCells??12e3,pixelRatio:o/(i.referenceWidth??Math.min(o,960))})),r&&a.invalidate(),a.render(await t.frame(n,l),n,o,h,c)},i)}finally{a?.destroy()}},exports.exportStudioProject=async function(t,e,i){const a=Ye(t),s={...i.motionTimes};if(Object.values(s).some(t=>!Number.isFinite(t)||t<0))throw new Error("Layer motion times must be finite non-negative numbers.");const r=Object.fromEntries(Object.entries(e).map(([t,e])=>[t,e&&"object"==typeof e&&"text"in e&&"string"==typeof e.text?{...e}:e]));let n,o;const h=new AbortController,l=()=>h.abort();i.signal?.aborted?l():i.signal?.addEventListener("abort",l,{once:!0});const c="png"===i.format||"jpeg"===i.format;try{return await Se(async(t,e,h,l,m)=>{o??(o=await Je(a,r,m)),n??(n=Ve(t,a,{maxDimension:4096,maxCells:i.maxCells??24e3,maxRasterPixels:i.maxRasterPixels,pixelRatio:h/(i.referenceWidth??Math.min(h,960))}));const u=new Set(He({...a,width:h,height:l}).map(t=>t.source)),f=new Map;await Promise.all([...u].map(async t=>{const i=o.get(t);await i.seek(e,m),f.set(t,i.frame(e)),i.animated&&n.invalidate(t)})),n.render(f,e,h,l,c?s:{})},{...i,signal:h.signal})}finally{if(h.abort(),i.signal?.removeEventListener("abort",l),n?.destroy(),o)for(const t of new Set(o.values()))t.destroy()}},exports.inkIndexLookup=pe,exports.isStudioPrintStyle=Y,exports.loadStudioMedia=ke,exports.mountStudio=async function(t,e,i={}){Pe()&&Re();const a=await ke(e,i.signal);try{return De(t,a,i)}catch(t){throw a.destroy(),t}},exports.mountStudioMedia=De,exports.mountStudioProject=async function(t,e,i,a={}){const s=Ye(e),r=await Je(s,i,a.signal);try{return Qe(t,s,r,a)}catch(t){for(const t of new Set(r.values()))t.destroy();throw t}},exports.mountStudioProjectMedia=Qe,exports.normalizeStudioCurve=P,exports.normalizeStudioCurves=C,exports.normalizeStudioPrint=G,exports.normalizeStudioProject=Ye,exports.normalizeStudioSettings=tt,exports.normalizeStudioWarps=L,exports.parseStudioProject=function(t){if(t.length>1e6)throw new Error("Project exceeds the 1 MB settings limit.");const e=JSON.parse(t);if("asciify-project"!==e?.kind||1!==e.version||!Array.isArray(e.layers))throw new Error("This is not an Asciify layered project.");return Ye(e)},exports.parseStudioSettings=function(t){if(t.length>1e5)throw new Error("Settings exceed 100 KB.");return tt(JSON.parse(t))},exports.resolveHover=m,exports.restyleStudio=function(t,e=Math.random){const i=rt.filter(e=>e.settings.style!==t.style||e.settings.ink!==t.ink),a=nt(i[Math.min(i.length-1,Math.max(0,Math.floor(e()*i.length)))].id);return a.aspectRatio=t.aspectRatio,a.crop={...t.crop},a.mask=tt(t).mask,a},exports.serializeStudioProject=t=>JSON.stringify(Ye(t)),exports.serializeStudioSettings=function(t){return JSON.stringify(tt(t))},exports.studioCrop=et,exports.studioDimensions=it,exports.studioGrid=st,exports.studioLayerPoint=Ge,exports.studioLevels=fe,exports.studioLook=nt,exports.studioProjectBudget=We,exports.studioSourceSize=ne,exports.studioToneGamma=de,exports.updateStudioProjectLayer=je,exports.updateStudioSettings=at,exports.visibleStudioLayers=He;//# sourceMappingURL=studio.cjs.map