asciify-engine 4.24.0 → 4.26.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 (105) hide show
  1. package/CHANGELOG.md +325 -0
  2. package/README.md +71 -718
  3. package/dist/core.cjs +1 -1
  4. package/dist/core.js +1 -1
  5. package/dist/field.cjs +1 -1
  6. package/dist/field.d.cts +132 -272
  7. package/dist/field.d.ts +132 -272
  8. package/dist/field.js +1 -1
  9. package/dist/glyph-field-C2fQIlnq.d.cts +292 -0
  10. package/dist/glyph-field-DRC-7uVf.d.ts +292 -0
  11. package/dist/hover.cjs +1 -1
  12. package/dist/hover.js +1 -1
  13. package/dist/index.cjs +1 -1
  14. package/dist/index.js +1 -1
  15. package/dist/kit/chunk-2FH6GGV6.js +1 -0
  16. package/dist/kit/chunk-2GAV4OAK.js +1 -0
  17. package/dist/kit/{chunk-C4KZYCPF.js → chunk-2LBQ7QJT.js} +1 -1
  18. package/dist/kit/{chunk-BN7HL52Z.js → chunk-3LJ5C3U3.js} +1 -1
  19. package/dist/kit/{chunk-NURPDP3Y.js → chunk-3MHEDZLZ.js} +1 -1
  20. package/dist/kit/{chunk-BR6ZNJZW.js → chunk-3OD5BMF5.js} +1 -1
  21. package/dist/kit/{chunk-C3C7AYKL.js → chunk-3VEMKDBW.js} +1 -1
  22. package/dist/kit/{chunk-PFKYKAIP.js → chunk-42KMN727.js} +1 -1
  23. package/dist/kit/{chunk-2CF4PX6U.js → chunk-6G5MPND3.js} +1 -1
  24. package/dist/kit/{chunk-QALCXKU6.js → chunk-6WU247CB.js} +1 -1
  25. package/dist/kit/{chunk-YBRP6BFW.js → chunk-776H2BJ7.js} +1 -1
  26. package/dist/kit/chunk-7DXSG526.js +1 -0
  27. package/dist/kit/{chunk-H2UZBVKE.js → chunk-7M2FFUZ3.js} +1 -1
  28. package/dist/kit/{chunk-5BEBNKYM.js → chunk-7NVKRDKE.js} +1 -1
  29. package/dist/kit/{chunk-XB4DKPGL.js → chunk-AIGAJMNN.js} +1 -1
  30. package/dist/kit/{chunk-O7SGY4YJ.js → chunk-B3TY6UXJ.js} +1 -1
  31. package/dist/kit/{chunk-XDKKCIIL.js → chunk-BFBG3VHI.js} +1 -1
  32. package/dist/kit/{chunk-3A5LID2G.js → chunk-CG6SGQMY.js} +1 -1
  33. package/dist/kit/{chunk-T3GWGPST.js → chunk-CGSWUO67.js} +1 -1
  34. package/dist/kit/{chunk-DFOWXOZR.js → chunk-DAJSBX6H.js} +1 -1
  35. package/dist/kit/{chunk-IUKSHYED.js → chunk-DCLJHSWM.js} +1 -1
  36. package/dist/kit/{chunk-W2STAN6V.js → chunk-DMRPBFLW.js} +1 -1
  37. package/dist/kit/{chunk-XANKANGR.js → chunk-E3FPFANJ.js} +1 -1
  38. package/dist/kit/{chunk-VC2ZQG63.js → chunk-EKYEA7Z4.js} +1 -1
  39. package/dist/kit/{chunk-IQTGJRDX.js → chunk-F6F2C3RH.js} +1 -1
  40. package/dist/kit/chunk-FEAFQY7O.js +1 -0
  41. package/dist/kit/{chunk-FUI5AVIF.js → chunk-FHN3PPSI.js} +1 -1
  42. package/dist/kit/{chunk-QRCXXS5Z.js → chunk-FPCCX4FM.js} +1 -1
  43. package/dist/kit/{chunk-TTGMK4EA.js → chunk-FWODCYYJ.js} +1 -1
  44. package/dist/kit/{chunk-AIM3J2US.js → chunk-GBNV3GXG.js} +1 -1
  45. package/dist/kit/chunk-GF72XM4C.js +1 -0
  46. package/dist/kit/{chunk-SARCZMLN.js → chunk-GKR3ROYR.js} +1 -1
  47. package/dist/kit/{chunk-ROR6MG3K.js → chunk-H5KHXZWR.js} +1 -1
  48. package/dist/kit/{chunk-PCIAA2LL.js → chunk-I5R2347P.js} +1 -1
  49. package/dist/kit/{chunk-4QHFEMFS.js → chunk-IBNDCKEX.js} +1 -1
  50. package/dist/kit/{chunk-J2YZBT3N.js → chunk-ILXVBO7M.js} +1 -1
  51. package/dist/kit/{chunk-S62H7ZIU.js → chunk-JELJEEJO.js} +1 -1
  52. package/dist/kit/{chunk-2NVKPXPL.js → chunk-K6JX64AS.js} +1 -1
  53. package/dist/kit/{chunk-3473NPIN.js → chunk-KCEYRIU4.js} +1 -1
  54. package/dist/kit/{chunk-HTUGMGVA.js → chunk-KDROJANO.js} +1 -1
  55. package/dist/kit/{chunk-5QE6UMXN.js → chunk-KEE55QSD.js} +1 -1
  56. package/dist/kit/{chunk-MIZ2DUHU.js → chunk-KFXMLIVF.js} +1 -1
  57. package/dist/kit/{chunk-G57QACJG.js → chunk-KLRF3S7O.js} +1 -1
  58. package/dist/kit/{chunk-ENTDGT2V.js → chunk-KXI3T72F.js} +1 -1
  59. package/dist/kit/{chunk-4ZQFDFEH.js → chunk-KY5KCIZE.js} +1 -1
  60. package/dist/kit/{chunk-4OT66HSZ.js → chunk-LE53AVKR.js} +1 -1
  61. package/dist/kit/{chunk-WJLZM3DR.js → chunk-LVCGC3SO.js} +1 -1
  62. package/dist/kit/chunk-M5VVLYI2.js +1 -0
  63. package/dist/kit/{chunk-7ABNWOW4.js → chunk-MJJSZS23.js} +1 -1
  64. package/dist/kit/{chunk-VVW7LZT2.js → chunk-MZFK765W.js} +1 -1
  65. package/dist/kit/{chunk-5I4IZTL5.js → chunk-NF4WVWAC.js} +1 -1
  66. package/dist/kit/{chunk-PIU2BMFU.js → chunk-NW4U2YRE.js} +1 -1
  67. package/dist/kit/{chunk-5Z2EJAUV.js → chunk-ORSI57T2.js} +1 -1
  68. package/dist/kit/{chunk-UML6XQAR.js → chunk-QSTDYL35.js} +1 -1
  69. package/dist/kit/{chunk-K563CCOL.js → chunk-QVICL57J.js} +1 -1
  70. package/dist/kit/{chunk-MQJQIDO5.js → chunk-RXOPJJC4.js} +1 -1
  71. package/dist/kit/{chunk-SNCXU7KF.js → chunk-SDSW7422.js} +1 -1
  72. package/dist/kit/{chunk-DZ5XGHTJ.js → chunk-TRDA73HN.js} +1 -1
  73. package/dist/kit/{chunk-KWTF6Q5W.js → chunk-UOYBFLGJ.js} +1 -1
  74. package/dist/kit/chunk-UVLKCAKH.js +1 -0
  75. package/dist/kit/{chunk-YCWMOTYH.js → chunk-VBWG7HQA.js} +1 -1
  76. package/dist/kit/{chunk-FR3ZJNOY.js → chunk-VIUEAEBX.js} +1 -1
  77. package/dist/kit/{chunk-ZRJVOUWH.js → chunk-VV2KP7ZW.js} +1 -1
  78. package/dist/kit/chunk-VX2AD3M7.js +1 -0
  79. package/dist/kit/{chunk-RFLIFKZ4.js → chunk-W4U5CK6L.js} +1 -1
  80. package/dist/kit/{chunk-I4QVLLRQ.js → chunk-WI2AF2KE.js} +1 -1
  81. package/dist/kit/{chunk-MGVPLQ3Z.js → chunk-XUCYFWC3.js} +1 -1
  82. package/dist/kit/{chunk-BNVRKD3V.js → chunk-Z2FRNFMB.js} +1 -1
  83. package/dist/kit/{chunk-BQZCLGCY.js → chunk-Z3KD6CLE.js} +1 -1
  84. package/dist/kit/{chunk-E3TUOX2A.js → chunk-ZCXNGJGB.js} +1 -1
  85. package/dist/kit/{chunk-IPVN22ZM.js → chunk-ZWZZMU5P.js} +1 -1
  86. package/dist/kit.cjs +1 -1
  87. package/dist/kit.d.cts +4 -2
  88. package/dist/kit.d.ts +4 -2
  89. package/dist/kit.js +1 -1
  90. package/dist/studio-worker.js +1 -0
  91. package/dist/studio.cjs +1 -1
  92. package/dist/studio.js +1 -1
  93. package/package.json +3 -1
  94. package/skills/asciify-engine/SKILL.md +2 -2
  95. package/skills/asciify-engine/references/applying-asciify.md +1 -1
  96. package/skills/asciify-engine/references/kit.md +2 -2
  97. package/skills/asciify-engine/references/performance.md +6 -3
  98. package/dist/kit/chunk-3PCKMO6I.js +0 -1
  99. package/dist/kit/chunk-4HWMQCAM.js +0 -1
  100. package/dist/kit/chunk-73M2OESE.js +0 -1
  101. package/dist/kit/chunk-BTD6EFAW.js +0 -1
  102. package/dist/kit/chunk-OWEZV7TQ.js +0 -1
  103. package/dist/kit/chunk-S7RZP2MT.js +0 -1
  104. package/dist/kit/chunk-UO7RB7RC.js +0 -1
  105. package/dist/kit/chunk-XM56OTYT.js +0 -1
package/dist/studio.js CHANGED
@@ -1 +1 @@
1
- var t=[{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."}],e={rake:"silk"},i={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}},a={effect:"trail",strength:.55,radius:.2,decay:.5,scope:"all",edgeSafe:!1};function s(i){if("string"==typeof i)return i in e?e[i]:t.some(t=>t.value===i)?i:void 0}var r=[{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."}],o=t=>"subject"===t||"outside"===t?t:"all";function n(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 o=r*i;for(let e=-s;e<=s;e++)a+=t[o+Math.max(0,Math.min(i-1,e))];for(let r=0;r<i;r++)e[o+r]=a/(2*s+1),a+=t[o+Math.min(i-1,r+s+1)]-t[o+Math.max(0,r-s)]}for(let r=0;r<i;r++){let o=0;for(let t=-s;t<=s;t++)o+=e[Math.max(0,Math.min(a-1,t))*i+r];for(let n=0;n<a;n++)t[n*i+r]=o/(2*s+1),o+=e[Math.min(a-1,n+s+1)*i+r]-e[Math.max(0,n-s)*i+r]}}}var h=new Float32Array(0);function l(t,e,i,a,s){const r=e*i,o=s&&s.width===e&&s.height===i?s:{width:e,height:i,subject:new Float32Array(r),depth:new Float32Array(r),key:"none"},{subject:l,depth:c}=o;let m=0;for(let e=0;e<r;e++)t[4*e+3]<250&&m++;const d=e=>(.2126*t[4*e]+.7152*t[4*e+1]+.0722*t[4*e+2])/255;let u="none",f=0;if(m>.01*r)u="alpha";else if(a)u="mask";else{let t=0,a=0,s=0;const r=Math.max(1,Math.round(.03*Math.min(e,i)));for(let o=0;o<i;o++)for(let n=0;n<e;n++){if(n>=r&&o>=r&&n<e-r&&o<i-r)continue;const h=d(o*e+n);t+=h,a+=h*h,s++}f=t/Math.max(1,s);Math.sqrt(Math.max(0,a/Math.max(1,s)-f*f))<.07&&(u="ground")}for(let e=0;e<r;e++){const i=t[4*e+3]/255,s=d(e);let r=1;if("alpha"===u)r=i;else if("ground"===u){const t=Math.max(0,Math.min(1,(Math.abs(s-f)-.035)/.12));r=t*t*(3-2*t)}l[e]=r*(a?Math.max(0,Math.min(1,a[e])):1),c[e]=s*i}o.key=u,h.length<r&&(h=new Float32Array(r));const p=h;return n(l,p,e,i,Math.max(1,Math.round(.02*Math.min(e,i)))),n(c,p,e,i,Math.max(1,Math.round(.035*Math.min(e,i)))),o}function c(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"},d=[{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 u(t){const e=t&&Object.prototype.hasOwnProperty.call(m,t)?m[t]:t;return d.find(t=>t.value===e||t.mode===e)?.mode??"none"}var f=t=>Math.max(0,Math.min(1,t)),p=(t,e,i)=>{const a=f((i-t)/(e-t));return a*a*(3-2*a)},g=(t,e)=>{const i=(.06711056*t+.00583715*e)%1*52.9829189;return i-Math.floor(i)},M=class{constructor(){this.last=null,this.mode="none",this.phase=0}update(t,e,i=1){const a=u(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 x(t,e,i,a,s,r=.5,o,n=0){if(s[0]=s[1]=s[2]=0,s[3]=1,"none"===t)return s;r=f(r);const h=o?o[n]:r,l=o?o[n+1]:.5+.5*f(1-2*Math.hypot(e-.5,i-.55)),c=o?o[n+2]:p(.55,1,r)**2,m=o?o[n+3]:.5,d=o?o[n+4]:0,u=o?o[n+5]:0,M=a*Math.PI/6,x=(a%12+12)%12,v=p(0,.12,Math.min(e,1-e,i,1-i));if("relight"===t){const t=M+.6,a=Math.cos(t),o=Math.sin(t),n=Math.max(-1,Math.min(1,d*a+u*o))+.35*(a*(e-.5)+o*(i-.5));s[2]=.2*n*(.3+.7*p(.04,.3,h)*(1-.6*p(.82,1,r)))}else if("sheen"===t){const t=1.9*p(0,8,x)-.35,a=(.75*e+.45*i)/1.2+.05*(.75*d+.45*u),o=Math.exp(-(((a-t)/.12)**2));s[2]=o*p(.3,.8,h)*(1-.5*p(.9,1,r))*.45}else if("glow"===t){const t=.5-.5*Math.cos(M),e=1-.8*t;s[2]=.2*p(e-.3,e+.02,c)*Math.sqrt(c)*(1-.65*r)+.05*t*p(.6,.95,r)}else if("shimmer"===t){const t=g(Math.floor(160*e),Math.floor(100*i))*Math.PI*2,a=Math.pow(.5+.5*Math.cos(2*M+t),28);s[2]=a*p(.5,.88,r)*(.35+.65*p(.1,.55,m))*.42}else if("parallax"===t){const t=l-.45;s[0]=16*t*Math.sin(M)*v,s[1]=7*t*Math.sin(2*M)*v}else if("push"===t){const t=.045*(.5-.5*Math.cos(M))*(.7+.6*l)*960,a=o?o[n+6]:.5,r=o?o[n+7]:.5;s[0]=(e-a)*t,s[1]=(i-r)*t}else if("focus"===t){const t=Math.sin(M),e=t*t*p(.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-M+.9*Math.sin(3.3*i+M))+.3*Math.sin(7.3*e+2.1*i-2*M+1.1*Math.sin(2.7*e-5.1*i+M))+.2*Math.sin(5.7*i-1.9*e+M);s[2]=p(-.3,.9,a)*t*.16*(1-.55*r)}else if("current"===t){const t=o?.[n+8]??0,a=o?.[n+9]??0,h=o?.[n+10]??0,c=p(0,.06,Math.min(e,1-e,i,1-i)),d=o?0:(1-.4*m)*(1-.8*l)*v,u=t=>14*i-t+1.5*Math.sin(3*e+t),f=t=>16*i+2*e-t,x=t=>29*i-3*e-2*t,y=t=>1.7*e+2.3*i-t,w=t=>26*i+1.5*Math.sin(40*e)-2*t;s[0]=7*(Math.sin(u(M))-Math.sin(u(0))+.43*(Math.sin(5*e-3*i+M)-Math.sin(5*e-3*i)))*d+(3.5*(Math.sin(f(M))-Math.sin(f(0)))+1.5*(Math.sin(x(M))-Math.sin(x(0))))*t*c+5*(Math.sin(y(M))-Math.sin(y(0)))*a*c,s[1]=2*(Math.sin(11*e+M)-Math.sin(11*e))*d+.8*(Math.cos(f(M))-Math.cos(f(0)))*t*c+12*(Math.sin(w(M))-Math.sin(w(0)))*h*c;const b=Math.pow(.5+.5*Math.cos(2*M+9*e-4*i+6.2831853*g(Math.floor(160*e),Math.floor(100*i))),24)-Math.pow(.5+.5*Math.cos(9*e-4*i+6.2831853*g(Math.floor(160*e),Math.floor(100*i))),24);s[2]=.03*(Math.cos(u(M))-Math.cos(u(0)))*d+(b*p(.5,.85,r)*.3+.025*(Math.cos(f(M))-Math.cos(f(0))))*t*c+.08*(Math.cos(w(M))-Math.cos(w(0)))*h*c}else if("develop"===t){const t=p(7,8.5,x),a=f((x-8.5)/3.5),o=x<8.5?1-t:p(0,1,(1.45*a-(1-r)+.06*(g(Math.floor(160*e),Math.floor(100*i))-.5))/.3);s[2]=.3*-(1-o),s[3]=1-.9*(1-o)}return s}function v(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 y(t,e,i,a,s,r){return r[0]=v(Math.max(0,Math.min(a-1,e-t[0]/960*a))),r[1]=v(Math.max(0,Math.min(s-1,i-t[1]/960*s))),r}function w(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]=f(1+(t[3]-1)*i),t}var b=["rgb","red","green","blue"],k=t=>Math.max(0,Math.min(1,t));function A(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*k(i[0]))/255;!e.has(t)&&e.size>=16||e.set(t,k(i[1]))}return[...e].sort((t,e)=>t[0]-e[0])}function S(t){const e=t&&"object"==typeof t?t:{};return Object.fromEntries(b.map(t=>[t,A(e[t])]))}function E(t){const e=A(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 o=2*a[t]+a[t-1],n=a[t]+2*a[t-1];r[t]=(o+n)/(o/e+n/i)}const o=new Uint8Array(256);let n=0;for(let t=0;t<256;t++){const s=t/255;for(;n<i-2&&s>e[n+1][0];)n++;const h=a[n],l=(s-e[n][0])/h,c=l*l,m=c*l,d=(2*m-3*c+1)*e[n][1]+(m-2*c+l)*h*r[n]+(-2*m+3*c)*e[n+1][1]+(m-c)*h*r[n+1];o[t]=Math.round(255*k(d))}return o}function F(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 o=Math.floor(a),n=Math.floor(s),h=a-o,l=s-n,c=4*(n*e+o);if(0===h&&0===l){for(let e=0;e<4;e++)r[e]=t[c+e];return}const m=4*(n*e+Math.min(e-1,o+1)),d=4*(Math.min(i-1,n+1)*e+o),u=4*(Math.min(i-1,n+1)*e+Math.min(e-1,o+1)),f=(1-h)*(1-l)*t[c+3],p=h*(1-l)*t[m+3],g=(1-h)*l*t[d+3],M=h*l*t[u+3],x=f+p+g+M;for(let e=0;e<3;e++)r[e]=x?(t[c+e]*f+t[m+e]*p+t[d+e]*g+t[u+e]*M)/x:0;r[3]=x}function P(t,e,i,a,s,r){if(a>=0&&a<=e-1&&s>=0&&s<=i-1)return F(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 o=Math.floor(a),n=Math.floor(s),h=a-o,l=s-n;for(let a=0;a<=1;a++)for(let s=0;s<=1;s++){const c=o+s,m=n+a;if(c<0||c>=e||m<0||m>=i)continue;const d=4*(m*e+c),u=(s?h:1-h)*(a?l:1-l)*t[d+3];r[0]+=t[d]*u,r[1]+=t[d+1]*u,r[2]+=t[d+2]*u,r[3]+=u}r[3]&&(r[0]/=r[3],r[1]/=r[3],r[2]/=r[3])}var C=[{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}],T=8,I=(t,e,i,a)=>"number"==typeof t&&Number.isFinite(t)?Math.max(i,Math.min(a,t)):e;function R(t){if(!Array.isArray(t))return[];const e=[];for(const i of t.slice(0,64))if(i&&"object"==typeof i&&C.some(t=>t.value===i.type)&&(e.push({type:i.type,enabled:!1!==i.enabled,amount:I(i.amount,.35,-1,1),x:I(i.x,.5,0,1),y:I(i.y,.5,0,1),radius:I(i.radius,.55,.05,2),angle:I(i.angle,0,-180,180),frequency:I(i.frequency,5,1,24)}),8===e.length))break;return e}var N=2*Math.PI,L=(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},O=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=R(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 o=(s+.5)/e,n=(a+.5)/i;for(let e=this.warps.length-1;e>=0;e--){const i=this.warps[e],a=(o-i.x)*t/i.radius,s=(n-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 d=a,u=s;if("twirl"===i.type||"zigzag"===i.type){const t="twirl"===i.type?-m*N*c:.65*m*(2/Math.PI*Math.asin(Math.sin(l*N*i.frequency)))*c,e=Math.cos(t),r=Math.sin(t);d=a*e-s*r,u=a*r+s*e}else if("pinch"===i.type){const t=Math.exp(2*m*c);d=a*t,u=s*t}else if("sphere"===i.type&&l>0){const t=1+m*c*(2*Math.asin(l)/Math.PI/l-1);d=a*t,u=s*t}else if("ripple"===i.type&&l>0){const t=1+.12*m*Math.sin(l*N*i.frequency)*c/l;d=a*t,u=s*t}else if("shear"===i.type){const t=-a*i.sin+s*i.cos;d-=m*t*.9*c*i.cos,u-=m*t*.9*c*i.sin}else if("smudge"===i.type)d-=.65*m*c*i.cos,u-=.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),o=m>0?r/Math.PI:Math.cos(t*Math.PI)*(e+1)/2,n=m>0?2*l-1:Math.sin(t*Math.PI)*(e+1)/2,h=o*i.cos-n*i.sin,f=o*i.sin+n*i.cos;d+=(h-a)*Math.abs(m)*c,u+=(f-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=(L(t,e)-.5)*m*.5*c,o=(L(e+71,t-31)-.5)*m*.5*c;d+=r*i.cos-o*i.sin,u+=r*i.sin+o*i.cos}o=i.x+d*i.radius/t,n=i.y+u*i.radius/r}const h=2*(a*e+s);this.coordinates[h]=o*e-.5,this.coordinates[h+1]=n*i-.5}this.geometry=s}this.output.length!==t.length&&(this.output=new Uint8ClampedArray(t.length));const r=t===this.output?t.slice():t,o="transparent"===this.edge?P:F;for(let a=0,s=0;a<t.length;a+=4,s+=2){o(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=""}},D=["stipple","engraving","crosshatch","woodblock","risograph","pointillism"],j=[{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."}];function X(t){return D.includes(t)}var U={density:1,weight:1,angle:-35,roughness:.35,invert:!1,secondaryInk:"#ec6752",registration:.2,seed:7};function q(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)):U[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:U.secondaryInk,registration:i("registration",0,1),seed:Math.round(i("seed",0,65535))}}var z=["ascii","blocks","braille","dots","lines","cross","diagonal","diamond","mixed","pixel","mosaic","lego","voxel","disco","dither","hex","led","cmyk",...D],Y=["none","bayer2","bayer4","bayer8","bayer16","floyd-steinberg","atkinson","stucki","sierra","sierra-lite","burkes","jarvis","halftone","lines","noise","vertical-lines","diagonal-lines","radial","blue-noise"],B=["source-over","multiply","screen","overlay","soft-light","hard-light","color-dodge","color-burn","hue","saturation","color","luminosity"],W={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"]},G={version:1,aspectRatio:"original",style:"ascii",cellSize:6,charset:" .:-=+*#%@",colorMode:"accent",ink:"#e6e3da",print:{...U},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}},H=t=>t&&"object"==typeof t&&!Array.isArray(t)?t:{},V=(t,e,i,a)=>"number"==typeof t&&Number.isFinite(t)?Math.min(a,Math.max(i,t)):e,Q=(t,e)=>"string"==typeof t&&/^#[\da-f]{6}$/i.test(t)?t:e,J=(t,e,i)=>e.includes(t)?t:i;function K(t={}){const e=H(t),r=G;if(void 0!==e.version&&1!==e.version)throw new Error("Unsupported studio settings version. Update asciify-engine.");const n=H(e.crop),h=H(e.backdrop),l=H(e.color),c=H(e.dither),m=H(e.mask),f=H(e.effects),p=H(e.motion),g=H(e.hover),M={...r.effects};for(const t of["bloom","characterBloom","grain","dust","scanlines","crt","prism","rgbSplit","sharpen","vignette","glitch","pixelate","halftone"])M[t]=V(f[t],0,0,1);M.blur=V(f.blur,0,0,24),M.blurType=J(f.blurType,["gaussian","directional","radial","progressive"],r.effects.blurType),M.angle=V(f.angle,0,-180,180),M.focus=V(f.focus,.5,0,1);let x=2048;return{version:1,aspectRatio:J(e.aspectRatio,["original","16:9","9:16","1:1","4:3","3:4","21:9"],"original"),style:J(e.style,z,r.style),cellSize:V(e.cellSize,r.cellSize,X(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(""):r.charset,colorMode:J(e.colorMode,["accent","source","gray"],r.colorMode),ink:Q(e.ink,r.ink),print:q(e.print),warps:R(e.warps),warpEdge:J(e.warpEdge,["clamp","transparent"],"clamp"),crop:{x:V(n.x,.5,0,1),y:V(n.y,.5,0,1),zoom:V(n.zoom,1,1,5),rotation:90*Math.round(V(n.rotation,0,-360,360)/90)},backdrop:{mode:J(h.mode,["solid","transparent","source","blurred","gradient"],r.backdrop.mode),color:Q(h.color,r.backdrop.color),color2:Q(h.color2,r.backdrop.color2),blur:V(h.blur,12,0,32),opacity:V(h.opacity,1,0,1)},color:{brightness:V(l.brightness,0,-1,1),contrast:V(l.contrast,1,0,3),saturation:V(l.saturation,1,0,3),grayscale:V(l.grayscale,0,0,1),tint:Q(l.tint,r.color.tint),amount:V(l.amount,0,0,1),blend:J(l.blend,B,r.color.blend),blackPoint:V(l.blackPoint,0,0,.99),whitePoint:Math.max(V(l.blackPoint,0,0,.99)+1/255,V(l.whitePoint,1,1/255,1)),gamma:V(l.gamma,1,.25,4),shadows:V(l.shadows,0,-1,1),highlights:V(l.highlights,0,-1,1),curves:S(l.curves),denoise:V(l.denoise,0,0,1),levels:"none"===l.levels?"none":"auto"},dither:{algorithm:J(c.algorithm,Y,"none"),palette:"string"==typeof c.palette&&Object.prototype.hasOwnProperty.call(W,c.palette)?c.palette:"mono",colors:Array.isArray(c.colors)&&c.colors.length>=2?c.colors.slice(0,32).map(t=>Q(t,"#000000")):[...r.dither.colors],amount:V(c.amount,1,0,2),scale:Math.round(V(c.scale,2,1,12)),threshold:V(c.threshold,.5,0,1),motion:J(c.motion,["none","drift","shimmer"],"none"),speed:V(c.speed,1,.1,3),direction:V(c.direction,45,-180,180),colorSpace:J(c.colorSpace,["rgb","luminance"],"rgb")},mask:{enabled:!0===m.enabled,invert:!0===m.invert,shapes:Array.isArray(m.shapes)?m.shapes.slice(0,64).map(t=>{const e=H(t),i=J(e.kind,["rectangle","ellipse","brush"],"rectangle"),a="brush"===i&&Array.isArray(e.points)?e.points.slice(0,x).map(t=>Array.isArray(t)?[Math.round(1e4*V(t[0],0,0,1))/1e4,Math.round(1e4*V(t[1],0,0,1))/1e4]:[0,0]):[];return x-=a.length,{kind:i,x:V(e.x,0,0,1),y:V(e.y,0,0,1),width:V(e.width,.5,0,1),height:V(e.height,.5,0,1),size:V(e.size,.05,.005,.5),points:a}}):[]},lights:Array.isArray(e.lights)?e.lights.slice(0,4).map(t=>{const e=H(t);return{x:V(e.x,.5,0,1),y:V(e.y,.5,0,1),radius:V(e.radius,.3,.02,1),intensity:V(e.intensity,.5,0,1),color:Q(e.color,"#ffffff")}}):[],effects:M,motion:{type:J("string"==typeof p.type?u(p.type):p.type,d.map(t=>t.mode),"none"),speed:V(p.speed,1,.1,3),amount:V(p.amount,1,0,2)},hover:{effect:s(g.effect)??a.effect,strength:V(g.strength,i.strength.default,i.strength.min,i.strength.max),radius:V(g.radius,i.radius.default,i.radius.min,i.radius.max),edgeSafe:!0===g.edgeSafe,..."all"!==o(g.scope)&&{scope:o(g.scope)},....5!==V(g.decay,.5,0,1)&&{decay:V(g.decay,.5,0,1)}}}}function Z(t){return JSON.stringify(K(t))}function $(t){if(t.length>1e5)throw new Error("Settings exceed 100 KB.");return K(JSON.parse(t))}function _(t,e,i,a,s){const r=Math.abs(s.rotation/90)%2==1,o=r?e:t,n=r?t:e,h=Math.max(i/o,a/n)*s.zoom;return{width:o*h,height:n*h,x:(i-o*h)*s.x,y:(a-n*h)*s.y,scale:h,rotated:r}}function tt(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 et(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}),K(i)}function it(t,e,i,a=12e3,s=1){const r=Math.max(2,Number.isFinite(t)?t:960),o=Math.max(2,Number.isFinite(e)?e:540),n=Math.max(1,Math.floor(Number.isFinite(a)?a:12e3)),h=Math.max(.01,Number.isFinite(s)?s:1),l=X(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*o/(n*l))/h));for(;Math.ceil(r/(c*h))*Math.ceil(o/(c*h*l))>n;)c++;const m="dither"===i.style?i.dither.scale:i.cellSize,d=Math.max(c,m)*h;return{cell:d,rowHeight:d*l,columns:Math.ceil(r/d),rows:Math.ceil(o/(d*l)),minimum:c,limited:m<c}}var at=[["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:K(a)}));function st(t){const e=at.find(e=>e.id===t);if(!e)throw new Error("Unknown studio look.");return K(e.settings)}function rt(t,e=Math.random){const i=at.filter(e=>e.settings.style!==t.style||e.settings.ink!==t.ink),a=st(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=K(t).mask,a}function ot(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 o=[0,.25+.2*s,.5,.75+.2*r,1],n=o.slice(1).map((t,e)=>4*(t-o[e])),h=[n[0],...n.slice(1).map((t,e)=>2*t*n[e]/(t+n[e])),n[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)),n=4*s-r,c=n*n,m=c*n,d=(2*m-3*c+1)*o[r]+(m-2*c+n)*h[r]/4+(-2*m+3*c)*o[r+1]+(m-c)*h[r+1]/4;l[t]=Math.round(255*Math.max(0,Math.min(1,d)))}return l}(t),i=t.curves;if(!e&&(!i||Object.values(i).every(t=>t.every(([t,e])=>t===e))))return null;const a=E(i?.rgb),s=[i?.red,i?.green,i?.blue].map(E),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 nt=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 o=4*(s*e+r);if(!a[o+3])continue;const n=a[o],h=a[o+1],l=a[o+2];let c=0,m=0,d=0,u=0;for(let t=-1;t<=1;t++){const o=s+t;if(!(o<0||o>=i))for(let i=-1;i<=1;i++){const s=r+i;if(s<0||s>=e)continue;const f=4*(o*e+s);if(!a[f+3])continue;const p=Math.max(Math.abs(a[f]-n),Math.abs(a[f+1]-h),Math.abs(a[f+2]-l)),g=this.weights[p]*(0===i?1:.6)*(0===t?1:.6)*a[f+3];c+=a[f]*g,m+=a[f+1]*g,d+=a[f+2]*g,u+=g}}t[o]=n+(c/u-n)*this.amount,t[o+1]=h+(m/u-h)*this.amount,t[o+2]=l+(d/u-l)*this.amount}}},ht=2*Math.PI,lt=t=>Math.max(0,Math.min(1,t)),ct=.1,mt=t=>Math.max(-.1,Math.min(1.1,t)),dt=Float32Array.from({length:2048},(t,e)=>Math.sin(e/2048*ht)),ut=t=>dt[2047&Math.floor(t*(2048/ht))];function ft(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 pt(t){const e=q(t),{density:i,weight:a,angle:s,roughness:r,invert:o,secondaryInk:n,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)]),d=new Float32Array(6);function u(t,e,i,s,o,n,h,c,u=!1){if(h<=0)return;const[f,p]=m[c],g=-p,M=f,x=g*(e+.5)+M*(i+.5),v=.5*(Math.abs(g)+Math.abs(M)),y=u?1:.5,w=Math.ceil((x-v)/y),b=Math.floor((x+v)/y),k=Math.min(.94*y,.72*y*h*a);t.lineWidth=n*k,t.beginPath();for(let a=w;a<=b;a++){const h=a*y-x,c=.5+g*h,m=.5+M*h;let v=-2,w=2;if(Math.abs(f)>1e-8){const t=-c/f,e=(1-c)/f;v=Math.max(v,Math.min(t,e)),w=Math.min(w,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)),w=Math.min(w,Math.max(t,e))}else if(m<0||m>1)continue;if(!(w<=v))if(u&&(v-=ct,w+=ct),u){for(let t=0;t<6;t++){const s=v+(w-v)*t/5,r=f*(e+c+f*s)+p*(i+m+p*s);d[t]=.5*ut(5.3*r+1.9*a+l)+.25*ut(13.1*r+a)}for(let e=0;e<2;e++)for(let i=0;i<6;i++){const a=v+(w-v)*(e?5-i:i)/5,h=d[e?5-i:i],l=.5*k*(1+r*h*.5)*(e?-1:1),u=s+mt(c+f*a+g*l)*n,x=o+mt(m+p*a+M*l)*n;e||i?t.lineTo(u,x):t.moveTo(u,x)}t.closePath()}else t.moveTo(s+(c+f*v)*n,o+(m+p*v)*n),t.lineTo(s+(c+f*w)*n,o+(m+p*w)*n)}u?t.fill():t.stroke()}return{settings:e,paint(t,e,s,c,d,f,p,g,M,x,v,y,w){const b=lt((o?1-g:g)*i);if(b<=0||t.globalAlpha<=0)return;t.fillStyle=M,t.strokeStyle=M;const k=ft(s,c,l);if("engraving"===e||"crosshatch"===e||"woodblock"===e){const i=b*(1-r*k*.3);"woodblock"===e?u(t,s,c,d,f,p,Math.ceil(5*i)/5,0,!0):(u(t,s,c,d,f,p,i,0),"crosshatch"===e&&(u(t,s,c,d,f,p,Math.max(0,1.5*i-.3),1),u(t,s,c,d,f,p,Math.max(0,2*i-1.2),2)))}else if("risograph"===e){const e="source"===w?lt(.5+(x-y)/510):.5,i=.38*h*p,o=p*Math.min(.48,.44*Math.sqrt(b)*a);t.beginPath(),t.arc(d+.5*p,f+.5*p,o*Math.sqrt(.35+.65*(1-e)),0,ht),t.fill(),t.globalCompositeOperation="multiply",t.fillStyle=n;const u=1-r*ft(s,c,l+13)*.3;t.beginPath(),t.arc(d+.5*p+i*m[0][0],f+.5*p+i*m[0][1],o*Math.sqrt(.3+.7*e)*u,0,ht),t.fill(),t.globalCompositeOperation="source-over"}else{"stipple"===e&&t.beginPath();for(let i=0;i<4;i++){const o=ft(2*s+i%2,2*c+(i>>1),l),n=ft(s,c,l+11*i+1),h=d+((i%2+.5)/2+(o-.5)*r*.28)*p,m=f+((.5+(i>>1))/2+(n-.5)*r*.28)*p,u=Math.min(h-d,d+p-h,m-f,f+p-m,p*Math.min(.245,.21*a*Math.sqrt(b)*(1-r*o*.35)));if("stipple"===e)t.moveTo(h+u,m),t.arc(h,m,u,0,ht);else{const e=(o-.5)*r*64;t.fillStyle="source"===w?`rgb(${Math.round(x+e)},${Math.round(v-.4*e)},${Math.round(y-e)})`:"gray"===w?`rgb(${Math.round(x+e)},${Math.round(x+e)},${Math.round(x+e)})`:M,t.beginPath(),t.ellipse(h,m,u,.64*u,o*Math.PI,0,ht),t.fill()}}"stipple"===e&&t.fill()}}}}var gt=new Set(["none","floyd-steinberg","atkinson","stucki","sierra","sierra-lite","burkes","jarvis"]);function Mt(t){return"dither"===t.style&&("shimmer"===t.dither.motion||"drift"===t.dither.motion&&t.dither.amount>0&&!gt.has(t.dither.algorithm))}function xt(t){return"none"!==t.motion.type&&(t.motion.amount??1)>0}function vt(t){return xt(t)||Mt(t)||t.effects.grain>0||t.effects.dust>0||t.effects.glitch>0}var yt=11,wt=t=>Math.max(0,Math.min(1,t)),bt=(t,e,i)=>{const a=wt((i-t)/(e-t));return a*a*(3-2*a)};function kt(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 o=t.length*e;for(let t=0;t<i;t++)if(r+=s[t],r>=o)return(t+1)/i*a;return a}var At=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}},St=null;function Et(t,e,i,a,s){const r=2*s+1;for(let o=0;o<a;o++){const a=o*i;let n=0;for(let e=-s;e<=s;e++)n+=t[a+Math.max(0,Math.min(i-1,e))];for(let o=0;o<i;o++)e[a+o]=n/r,n+=t[a+Math.min(i-1,o+s+1)]-t[a+Math.max(0,o-s)]}for(let o=0;o<i;o++){let n=0;for(let t=-s;t<=s;t++)n+=e[Math.max(0,Math.min(a-1,t))*i+o];for(let h=0;h<a;h++)t[h*i+o]=n/r,n+=e[Math.min(a-1,h+s+1)*i+o]-e[Math.max(0,h-s)*i+o]}}function Ft(t,e,i,a,s,r,o){const n=i*a,h=o.take(),l=o.take(e),c=o.take(t),m=o.take(),d=o.take();for(let i=0;i<n;i++)m[i]=e[i]*e[i],d[i]=e[i]*t[i];Et(l,h,i,a,s),Et(c,h,i,a,s),Et(m,h,i,a,s),Et(d,h,i,a,s);for(let t=0;t<n;t++){const e=(d[t]-l[t]*c[t])/(m[t]-l[t]*l[t]+r);m[t]=e,d[t]=c[t]-e*l[t]}Et(m,h,i,a,s),Et(d,h,i,a,s);for(let i=0;i<n;i++)t[i]=m[i]*e[i]+d[i]}function Pt(t,e,i,a,s,r=2){for(let o=0;o<r;o++){for(let r=0;r<a;r++)for(let a=0;a<i;a++){const o=r*i+a;let n=t[o];a>0&&(n=Math.max(n,Math.min(e[o],t[o-1]*s))),r>0&&(n=Math.max(n,Math.min(e[o],t[o-i]*s),a>0?Math.min(e[o],t[o-i-1]*s):0,a<i-1?Math.min(e[o],t[o-i+1]*s):0)),t[o]=n}for(let r=a-1;r>=0;r--)for(let o=i-1;o>=0;o--){const n=r*i+o;let h=t[n];o<i-1&&(h=Math.max(h,Math.min(e[n],t[n+1]*s))),r<a-1&&(h=Math.max(h,Math.min(e[n],t[n+i]*s),o>0?Math.min(e[n],t[n+i-1]*s):0,o<i-1?Math.min(e[n],t[n+i+1]*s):0)),t[n]=h}}}function Ct(t,e,i,a,s){for(let r=0;r<a;r++)for(let a=0;a<i;a++){let o=1;for(let e=Math.max(0,a-s);e<=Math.min(i-1,a+s);e++)o=Math.min(o,t[r*i+e]);e[r*i+a]=o}for(let r=0;r<a;r++)for(let o=0;o<i;o++){let n=1;for(let t=Math.max(0,r-s);t<=Math.min(a-1,r+s);t++)n=Math.min(n,e[t*i+o]);t[r*i+o]=n}}function Tt(t,e,i,a,s){const r=i*a,o=Math.min(i,a),h=s.take(),c=s.take(),m=s.take(),d=s.take(),u=s.take();for(let i=0;i<r;i++){const a=t[4*i+3]/255;u[i]=a,h[i]=e[4*i]/255*a,c[i]=e[4*i+1]/255*a,m[i]=e[4*i+2]/255*a,d[i]=(.299*t[4*i]+.587*t[4*i+1]+.114*t[4*i+2])/255*a}const f=s.take(),p=(t,e)=>{const r=s.take(t);return n(r,f,i,a,e),r},g=Math.max(2,Math.round(.04*o)),M=Math.max(g+2,Math.round(.12*o)),x=Math.max(2,Math.round(.05*o)),v=p(d,1),y=p(d,g),w=p(d,M),b=s.take(),k=s.take(),A=s.take(),S=s.take(),E=s.take();for(let t=0;t<a;t++)for(let e=0;e<i;e++){const s=t*i+e;b[s]=Math.abs(d[s]-v[s]),k[s]=Math.abs(v[s]-y[s]),A[s]=Math.abs(y[s]-w[s]),S[s]=Math.abs(d[t*i+Math.min(i-1,e+1)]-d[t*i+Math.max(0,e-1)]),E[s]=Math.abs(d[Math.min(a-1,t+1)*i+e]-d[Math.max(0,t-1)*i+e])}n(b,f,i,a,x),n(k,f,i,a,x),n(A,f,i,a,x),n(S,f,i,a,2),n(E,f,i,a,2);const F=Math.max(.01,kt(b,.9)+kt(k,.9)),P=p(h,1),C=p(c,1),T=p(m,1),I=s.take(),R=s.take(),N=s.take();let L=0;for(let t=0;t<r;t++){const e=P[t],i=C[t],a=T[t],s=Math.max(e,i,a),r=s-Math.min(e,i,a);N[t]=s,R[t]=s>.001?r/s:0,L+=r;let o=0;r>1e-4&&(o=s===e?((i-a)/r+6)%6:s===i?(a-e)/r+2:(e-i)/r+4),I[t]=60*o}const O=bt(.02,.07,L/r),D=Math.max(2,Math.round(.06*a)),j=new Float32Array(a);for(let t=0;t<a;t++){let e=0;for(let a=0;a<i;a++)e+=b[t*i+a]+k[t*i+a];j[t]=e/i}let X=.5,U=0;for(let t=Math.max(D,Math.round(.12*a));t<=Math.min(a-D,Math.round(.88*a));t++){let e=0,s=0,r=0,o=0;for(let a=0;a<i;a++){let r=0,o=0,n=0,h=0,l=0,c=0;for(let e=1;e<=D;e++){const s=(t-e)*i+a,m=(t+e-1)*i+a;r+=P[s],o+=C[s],n+=T[s],h+=P[m],l+=C[m],c+=T[m]}const m=(Math.abs(r-h)+Math.abs(o-l)+Math.abs(n-c))/D;e+=m,s+=m>.12?1:0}const n=Math.max(2,Math.round(.15*a)),h=Math.max(0,t-n),l=Math.min(a,t+n);for(let e=h;e<t;e++)r+=j[e];for(let e=t;e<l;e++)o+=j[e];r/=t-h,o/=l-t;const c=bt(-.05,.3,(o-r)/(o+r+1e-4)),m=bt(.08,.35,e/i)*(s/i)*c;m>U&&(U=m,X=t/a)}const q=bt(.15,.45,U),z=s.take(),Y=s.take(),B=s.take();for(let t=0;t<r;t++)z[t]=Math.min(h[t],c[t],m[t]);Ct(z,f,i,a,1),n(z,f,i,a,g);for(let t=0;t<r;t++)Y[t]=k[t]+A[t];let W=0,G=0,H=0;for(let t=0;t<r;t++)W+=P[t],G+=C[t],H+=T[t];W/=r,G/=r,H/=r;const V=p(P,g),Q=p(C,g),J=p(T,g),K=p(P,M),Z=p(C,M),$=p(T,M);for(let t=0;t<r;t++){const e=Math.hypot(V[t]-W,Q[t]-G,J[t]-H),i=Math.hypot(V[t]-K[t],Q[t]-Z[t],J[t]-$[t]);B[t]=(e+1.5*i)*(.4+.6*R[t]*O+.4*(1-O))}const _=s.take(),tt=s.take(),et=s.take(),it=s.take(),at=s.take(),st=s.take(),rt=s.take(),ot=s.take(),nt=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(d[Math.min(a-1,t+1)*i+e]-d[Math.max(0,t-1)*i+e]);n(ht,f,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,o=I[s],n=R[s]*O,h=N[s],l=b[s]+k[s],c=bt(175,200,o)*(1-bt(250,275,o))*bt(.08,.25,n),m=(1-bt(45,65,o)+bt(290,330,o))*bt(.2,.45,n)*bt(.3,.55,h),d=(1-bt(.15,.35,n))*bt(.45,.7,h)*q,u=(1-bt(.08,.2,h))*q,f=q>.3?1-bt(X,X+.1,r):1-bt(.4,.8,r),p=1-bt(.02,.06,l),g=1-bt(.03,.09,l);tt[s]=Math.max(c*p,.7*u*(1-bt(.008,.025,l)),m*g*.9)*f,et[s]=Math.max(tt[s],d*p*f),_[s]=0===t?tt[s]:0,it[s]=bt(150,172,o)*(1-bt(232,250,o))*bt(.25,.45,n),rt[s]=bt(1.3,2.2,(S[s]+.004)/(E[s]+.004))*bt(.35,.55,v[s])*(1-bt(.1,.18,R[s]*O))*bt(.025,.07,l)*bt(.025,.045,ht[s]);const M=1-bt(.18,.4,n),x=bt(.55,.8,h)*bt(.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&&q>.3;if(ct)for(let t=0;t<a;t++)for(let e=0;e<i;e++)it[t*i+e]*=bt(X,X+.05,(t+.5)/a);if(ct){const t=s.take(),e=s.take(),o=s.take();for(let e=0;e<r;e++)t[e]=.299*V[e]+.587*Q[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 h=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 o=r>.03;for(let n=-3;n<=3&&o;n++)n&&t+n>=0&&t+n<a&&Math.abs(e[(t+n)*i+s])>r&&(o=!1);h[t*i+s]=o?1:0}const l=(e,i,a,s=!0)=>{const r=V[i]+Q[i]+J[i]+.05,o=V[a]+Q[a]+J[a]+.05,n=Math.abs(V[i]/r-V[a]/o)+Math.abs(Q[i]/r-Q[a]/o)+Math.abs(J[i]/r-J[a]/o),h=Math.min(Math.abs(I[i]-I[a]),360-Math.abs(I[i]-I[a])),l=Math.max(1-bt(.1,.25,n),(1-bt(15,35,h))*bt(.15,.3,Math.min(R[i],R[a]))),c=Math.max(bt(2,3,(E[i]+.004)/(S[i]+.004))*bt(.015,.04,b[i]+k[i])*bt(.4,.55,b[i]/(b[i]+k[i]+1e-4)),1-bt(.12,.25,t[i]));return l*(s?c:1)*(1-bt(.82*t[a]+.02,1.02*t[a]+.05,t[i]))};let c=0,m=0;for(let t=Math.max(3,Math.round(a*Math.max(.25,X)));t<Math.round(.88*a);t++){let e=0;for(let a=0;a<i;a++)(h[(t-1)*i+a]||h[t*i+a]||h[(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+=l(t,e*i+a,(2*t-e)*i+a);s>m&&(m=s,c=t)}const d=bt(.05,.1,m/r);if(d>0)for(let t=c+1;t<Math.min(a,2*c);t++)for(let e=0;e<i;e++){const a=t*i+e;ot[a]=l(c,a,(2*c-t)*i+e)*d,nt[a]=l(c,a,(2*c-t)*i+e,!1)*d,o[a]=ot[a]}n(o,f,i,a,1);for(let t=0;t<r;t++)ot[t]=Math.max(ot[t],o[t]),it[t]=Math.max(it[t],ot[t])}const mt=p(it,M);for(let t=0;t<r;t++)it[t]*=bt(.15,.35,mt[t]);const dt=p(it,g);for(let t=0;t<r;t++){it[t]*=1-.8*tt[t];const e=Math.min(Math.abs(I[t]-200),360-Math.abs(I[t]-200));st[t]=bt(.28,.45,R[t]*O)*bt(55,80,e)*(1-bt(.3,.6,nt[t]))}const ut=p(st,g);for(let t=0;t<r;t++)st[t]=Math.max(st[t]*(1-(1-bt(.15,.3,ut[t]))*bt(.55,.7,N[t])*bt(.5,.65,R[t])),1-u[t]),at[t]=Math.min(Math.max(at[t],.9*nt[t]),Math.max(it[t],bt(.25,.6,dt[t])))*(1-_[t])*(1-st[t]);Pt(it,at,i,a,.97);const ft=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++)ft[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]}n(ft,f,i,a,1);for(let t=0;t<r;t++)rt[t]=bt(.2,.45,ft[t])*bt(.2,.5,rt[t]+.5*ft[t])*(1-_[t]);Ft(_,d,i,a,Math.max(2,Math.round(.04*o)),.002,s),Ft(it,d,i,a,Math.max(2,Math.round(.04*o)),.002,s),Ft(rt,d,i,a,Math.max(2,Math.round(.03*o)),.002,s),n(st,f,i,a,1);for(let t=0;t<r;t++)_[t]=bt(.3,.7,_[t])*u[t],rt[t]=bt(.3,.7,rt[t])*u[t]*(1-_[t]),it[t]=bt(.3,.7,it[t])*(1-_[t])*(1-rt[t])*(1-bt(.15,.4,st[t]));Ct(_,f,i,a,2),Ct(it,f,i,a,2),Ct(rt,f,i,a,1),n(_,f,i,a,1),n(it,f,i,a,1),n(rt,f,i,a,1);const gt=1/Math.max(.02,kt(B,.97)),Mt=1/Math.max(.01,kt(Y,.9)),xt=kt(z,.97),vt=kt(z,.1),yt=bt(.06,.25,xt-vt),At=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,o=(t+.5)/a,n=Math.max(_[s],it[s]),h=b[s]+k[s]+A[s],l=.6*wt(((b[s]+.6*k[s])/(h+.004)-.25)/.55)+.4*wt((b[s]+k[s])/F),c=bt(.04,.35,h/F)*(1-n),m=.55*wt((z[s]-vt)/Math.max(.05,xt-vt))+.25*(1-wt(Y[s]*Mt))+.2*wt(2*(T[s]-P[s])+.3)*O,d=yt*bt(.12,.35,y[s])*(.4+.6*q),u=q*(o<X?.45:.45+.55*bt(0,1,(o-X)/Math.max(.15,1-X)))+(1-q)*(.5+.4*(o-.5)),f=b[s]/(b[s]+k[s]+1e-4),p=bt(.2,.7,(b[s]+k[s])/F)*(.35+.65*q)*(1-n),g=1-wt(1.5*Math.hypot(1.2*(r-.5),o-.52)),M=wt(B[s]*gt)*(.55+.45*g),x=.3*c,v=.25*d,w=.12+.45*q,S=.12*p,E=.35*(1-.4*q)*(1-n);At[s]=(x*l+v*(1-m)+w*u+S*wt(1.6-1.6*f)+E*M+.04)/(x+v+w+S+E+.08)*(1-.85*_[s])*(1-.45*it[s]*(1-q))}const St=l(t,i,a);if("none"!==St.key)for(let t=0;t<r;t++)At[t]=.7*St.subject[t]+.3*At[t];return n(At,f,i,a,Math.max(1,Math.round(.03*o))),function(t,e,i,a,s,r,o,n,h){const l=s*r,c=h.take(),m=t=>(Et(t,c,s,r,o),t),d=(t,e)=>{const i=h.take();for(let a=0;a<l;a++)i[a]=t[a]*e[a];return m(i)},u=m(h.take(e)),f=m(h.take(i)),p=m(h.take(a)),g=m(h.take(t)),M=d(e,e),x=d(e,i),v=d(e,a),y=d(i,i),w=d(i,a),b=d(a,a),k=d(e,t),A=d(i,t),S=d(a,t),E=h.take(),F=h.take(),P=h.take(),C=h.take();for(let t=0;t<l;t++){const e=k[t]-u[t]*g[t],i=A[t]-f[t]*g[t],a=S[t]-p[t]*g[t],s=M[t]-u[t]*u[t]+n,r=x[t]-u[t]*f[t],o=v[t]-u[t]*p[t],h=y[t]-f[t]*f[t]+n,l=w[t]-f[t]*p[t],c=b[t]-p[t]*p[t]+n,m=h*c-l*l,d=o*l-r*c,T=r*l-o*h,I=s*c-o*o,R=r*o-s*l,N=s*h-r*r,L=s*m+r*d+o*T,O=Math.abs(L)>1e-12?1/L:0;E[t]=(m*e+d*i+T*a)*O,F[t]=(d*e+I*i+R*a)*O,P[t]=(T*e+R*i+N*a)*O,C[t]=g[t]-E[t]*u[t]-F[t]*f[t]-P[t]*p[t]}m(E),m(F),m(P),m(C);for(let s=0;s<l;s++)t[s]=E[s]*e[s]+F[s]*i[s]+P[s]*a[s]+C[s]}(At,P,C,T,i,a,Math.max(2,Math.round(.07*o)),.004,s),{depth:At,water:it,sky:_,falls:rt}}function It(t,e,i,a,s,r,o){if(e===r&&i===o)return t[s*r+a];const n=Math.max(0,Math.min(e-1,(a+.5)*e/r-.5)),h=Math.max(0,Math.min(i-1,(s+.5)*i/o-.5)),l=Math.min(e-2,Math.floor(n)),c=Math.min(i-2,Math.floor(h)),m=n-l,d=h-c;if(l<0||c<0)return t[Math.round(h)*e+Math.round(n)];const u=c*e+l,f=u+e;return(t[u]*(1-m)+t[u+1]*m)*(1-d)+(t[f]*(1-m)+t[f+1]*m)*d}var Rt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Nt="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",Lt=new Uint16Array(4096);for(let t=0;t<Lt.length;t++)Lt[t]=Rt.indexOf(Nt[2*t])<<6|Rt.indexOf(Nt[2*t+1]);var Ot=(t,e)=>{const i=43758.5453*Math.sin(127.1*t+311.7*e);return i-Math.floor(i)};var Dt=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))])),jt={"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]]},Xt=t=>[parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16)];function Ut(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 qt=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 o=this.width/this.height,n=Math.hypot((t-r.x)*Math.max(1,o),(e-r.y)*Math.max(1,1/o));if(n<1e-4||this.clock-this.lastRing<1/24)return;const h=n/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],o=.17*i,n=this.rings[t+3]*(1-Math.exp(20*-i))*Math.exp(2.5*-i),h=o+1.8*r,l=this.rings[t],c=this.rings[t+1],m=Math.max(0,Math.floor((l-h/a)*(this.width-1))),d=Math.min(this.width-1,Math.ceil((l+h/a)*(this.width-1))),u=Math.max(0,Math.floor((c-h/s)*(this.height-1))),f=Math.min(this.height-1,Math.ceil((c+h/s)*(this.height-1)));for(let t=u;t<=f;t++)for(let e=m;e<=d;e++){const i=(Math.hypot((e/(this.width-1)-l)*a,(t/(this.height-1)-c)*s)-o)/r;Math.abs(i)>1.8||(this.values[t*this.width+e]+=n*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?Ut(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),o=Math.floor(s),n=a-r,h=s-o,l=o*this.width+r,c=l+this.width;i[0]=i[1]=0,i[2]=3*((this.values[l]*(1-n)+this.values[l+1]*n)*(1-h)+(this.values[c]*(1-n)+this.values[c+1]*n)*h)}},zt=t=>["dissolve","silk","vortex","magnetic","scatter","etch","elastic","lens","smudge"].includes(t),Yt=t=>"elastic"===t||"scatter"===t,Bt={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]=Ut(a/(t-1),i/(e-1),t/e);this.clear()}get active(){return this.peak>2e-4}setMode(t){if(Yt(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,o=Math.floor(s),n=Math.floor(r),h=s-o,l=r-n,c=h*h*(3-2*h),m=l*l*(3-2*l),d=((e(o,n)*(1-c)+e(o+1,n)*c)*(1-m)+(e(o,n+1)*(1-c)+e(o+1,n+1)*c)*m)*Math.PI*4,u=2*(i*this.width+a);t[u]=.7*Math.cos(d),t[u+1]=.7*Math.sin(d)}}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,o=Math.max(1,s/r),n=Math.max(1,r/s),h=a?(t-a.x)*o:0,l=a?(e-a.y)*n: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)),d=Math.min(128,Math.max(1,Math.ceil(c/(.45*m)))),u=c?h/c:1,f=c?l/c:0,p=a||"lens"!==this.mode?Math.min(1,c/(m*d)*2.2):.32;for(let i=0;i<d;i++){const h=(i+.5)/d,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/o)*(s-1))),M=Math.min(s-1,Math.ceil((l+2.5*m/o)*(s-1))),x=Math.max(0,Math.floor((c-2.5*m/n)*(r-1))),v=Math.min(r-1,Math.ceil((c+2.5*m/n)*(r-1)));for(let t=x;t<=v;t++)for(let e=g;e<=M;e++){const i=(e/(s-1)-l)*o/m,a=(t/(r-1)-c)*n/m,h=Math.exp(1.5*-(i*i+a*a)),d=t*s+e;if("dissolve"===this.mode||"etch"===this.mode)this.ink[d]=Math.max(this.ink[d],h);else if("elastic"===this.mode)this.springX[d]=Math.max(-24,Math.min(24,this.springX[d]+u*h*p*12)),this.springY[d]=Math.max(-24,Math.min(24,this.springY[d]+f*h*p*12));else if("scatter"===this.mode){const t=this.scatterDirections;this.springX[d]=Math.max(-24,Math.min(24,this.springX[d]+(.6*i+t[2*d])*h*p*7)),this.springY[d]=Math.max(-24,Math.min(24,this.springY[d]+(.6*a+t[2*d+1])*h*p*7))}else if("lens"===this.mode)this.targetX[d]=Math.max(-.65,Math.min(.65,this.targetX[d]+i*h*p*1.6)),this.targetY[d]=Math.max(-.65,Math.min(.65,this.targetY[d]+a*h*p*1.6));else if("smudge"===this.mode)this.targetX[d]=Math.max(-1,Math.min(1,this.targetX[d]+u*h*p*1.3)),this.targetY[d]=Math.max(-1,Math.min(1,this.targetY[d]+f*h*p*1.3));else{const t=(-i*f+a*u)*h*2.8,e="magnetic"===this.mode?-i*h*2.5:"silk"===this.mode?u*t:-a*h*2.5,s="magnetic"===this.mode?-a*h*2.5:"silk"===this.mode?f*t:i*h*2.5;this.targetX[d]=Math.max(-1,Math.min(1,this.targetX[d]+e*p)),this.targetY[d]=Math.max(-1,Math.min(1,this.targetY[d]+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 o=0;const[n,h]="scatter"===this.mode?Bt.scatter:Bt.elastic,l=Math.sqrt(n-h*h),c=Math.exp(-h*e),m=Math.cos(l*e),d=Math.sin(l*e)/l;for(let t=0;t<this.ink.length;t++)if("etch"===this.mode)this.ink[t]*=s,o=Math.max(o,this.ink[t]);else if("dissolve"===this.mode){this.ink[t]*=s,o=Math.max(o,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(Yt(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)*d))),this.offsetY[t]=Math.max(-1,Math.min(1,c*(i*m+(s+h*i)*d))),this.springX[t]=c*(a*m-(h*a+n*e)*d),this.springY[t]=c*(s*m-(h*s+n*i)*d),o=Math.max(o,.05*Math.abs(this.springX[t]),.05*Math.abs(this.springY[t]))}else if("lens"===this.mode||"smudge"===this.mode){const e=1-r,o=a/(a-i)*(s-e);this.offsetX[t]=this.offsetX[t]*e+this.targetX[t]*o,this.offsetY[t]=this.offsetY[t]*e+this.targetY[t]*o,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;o=Math.max(o,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=o,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),o=Math.floor(s),n=a-r,h=s-o,l=o*this.width+r,c=l+this.width,m=t=>(t[l]*(1-n)+t[l+1]*n)*(1-h)+(t[c]*(1-n)+t[c+1]*n)*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?Ut(t,e,this.width/this.height):1)*.08,i[1]=m(this.offsetY)*(this.edgeSafe?Ut(t,e,this.width/this.height):1)*.08,i[2]="dissolve"===this.mode?6*-m(this.ink):0}},Gt=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 o=.015+r.age*(.15+.22*r.radius),n=.009+.014*r.radius,h=(Math.hypot((t-r.x)*i,(e-r.y)*a)-o)/n,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]),o=4*s;this.pixels[o]=r>>>8,this.pixels[o+1]=255&r}this.echoPeak=a,this.active||(this.echo.fill(0),this.pixels.fill(0))}},Ht=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),o=(e-s.y)*(this.height-1),n=Math.hypot(r,o);if(n<.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,n/h/l),m=1-Math.exp(-c/2.2),d=h*(.022+.075*i)*(.65+.95*m),u=Math.min(128,Math.max(1,Math.ceil(n/(.4*d)))),f=n/d*(.32+.22*m)/u,p=r/n,g=o/n,M=-g,x=p,v=n*(2+18*m)/u;for(let i=0;i<u;i++){const a=(i+.5)/u,r=(s.x+(t-s.x)*a)*(this.width-1),o=(s.y+(e-s.y)*a)*(this.height-1),n=Math.max(1,Math.floor(r-3*d)),h=Math.min(this.width-2,Math.ceil(r+3*d)),l=Math.max(1,Math.floor(o-3*d)),c=Math.min(this.height-2,Math.ceil(o+3*d));for(let t=l;t<=c;t++)for(let e=n;e<=h;e++){const i=((e-r)*p+(t-o)*g)/d,a=((e-r)*M+(t-o)*x)/d,s=Math.exp(-i*i*.65-a*a*1.7),n=t*this.width+e;this.ink[n]=1-(1-this.ink[n])*Math.exp(-s*f);const h=1-a*a*.55,l=i*a*.7;this.u[n]=Math.max(-80,Math.min(80,this.u[n]+(p*h+M*l)*s*v)),this.v[n]=Math.max(-80,Math.min(80,this.v[n]+(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,o=i-s,n=s*this.width+a;return(t[n]*(1-r)+t[n+1]*r)*(1-o)+(t[n+this.width]*(1-r)+t[n+this.width+1]*r)*o}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 o=1;o<i-1;o++){const n=e*i+o,h=Math.max(.5,Math.min(i-1.5,o-this.u[n]*t)),l=Math.max(.5,Math.min(a-1.5,e-this.v[n]*t)),c=0|h,m=0|l,d=h-c,u=l-m,f=m*i+c,p=(1-d)*(1-u),g=d*(1-u),M=(1-d)*u,x=d*u;this.a[n]=(this.u[f]*p+this.u[f+1]*g+this.u[f+i]*M+this.u[f+i+1]*x)*s,this.b[n]=(this.v[f]*p+this.v[f+1]*g+this.v[f+i]*M+this.v[f+i+1]*x)*s,this.c[n]=(this.ink[f]*p+this.ink[f+1]*g+this.ink[f+i]*M+this.ink[f+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]),o=Math.abs(this.curl[s+i])-Math.abs(this.curl[s-i]),n=Math.hypot(r,o)+1e-4,h=this.curl[s]*t*10,l=Math.hypot(this.u[s],this.v[s]);this.u[s]+=o/n*h,this.v[s]-=r/n*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 o=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]),o=Math.max(o,this.signal[s])}this.peak=o}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 Vt=["loupe","repel","tilt","reveal","haze","bleed"],Qt=t=>Vt.includes(t),Jt=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}},Kt=t=>t*t*(3-2*t),Zt=(t,e)=>{const i=43758.5453*Math.sin(127.1*t+311.7*e);return i-Math.floor(i)};function $t(t,e){const i=Math.floor(t),a=Math.floor(e),s=Kt(t-i),r=Kt(e-a),o=Zt(i,a),n=Zt(i+1,a),h=Zt(i,a+1);return(o+(n-o)*s)*(1-r)+(h+(Zt(i+1,a+1)-h)*s)*r}var _t=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 Jt,this.y=new Jt,this.tx=new Jt,this.ty=new Jt,this.presence=new Jt,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*$t(.09*e,.045*t)+.15*Zt(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,o=this.width,n=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,d=t+(i-t)*m,u=e+(a-e)*m,f=Math.max(0,Math.floor((d-2*h/this.sx)*(o-1))),p=Math.min(o-1,Math.ceil((d+2*h/this.sx)*(o-1))),g=Math.max(0,Math.floor((u-2*h/this.sy)*(n-1))),M=Math.min(n-1,Math.ceil((u+2*h/this.sy)*(n-1)));for(let t=g;t<=M;t++)for(let e=f;e<=p;e++){const i=(e/(o-1)-d)*this.sx/h,a=(t/(n-1)-u)*this.sy/h,l=t*o+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,o=this.width,n=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,d=Math.exp(-(i?.15:.9)*e/h);let u=0;for(let t=0;t<h;t++){u=0;for(let t=1;t<n-1;t++)for(let e=1;e<o-1;e++){const i=t*o+e,n=a[i],h=r[i],f=Math.min(h,r[i-1])*(a[i-1]-n)+Math.min(h,r[i+1])*(a[i+1]-n)+Math.min(h,r[i-o])*(a[i-o]-n)+Math.min(h,r[i+o])*(a[i+o]-n),p=Math.max(0,(n+f*Math.min(.24,c*l))*d-m*l);s[i]=p,p>u&&(u=p)}a.set(s)}this.inkPeak=u}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,o=Math.max(0,Math.min(a-1.001,t*(a-1))),n=Math.max(0,Math.min(s-1.001,e*(s-1))),h=Math.floor(o),l=Math.floor(n),c=o-h,m=n-l,d=l*a+h,u=d+a,f=(r[d]*(1-c)+r[d+1]*c)*(1-m)+(r[u]*(1-c)+r[u+1]*c)*m;return void(i[2]=1-Math.exp(2.4*-f))}if("tilt"===s){const a=this.guide?function(t,e,i,a){const s=t[e],r=t.width,o=t.height,n=Math.max(0,Math.min(r-1.001,i*(r-1))),h=Math.max(0,Math.min(o-1.001,a*(o-1))),l=Math.floor(n),c=Math.floor(h),m=n-l,d=h-c,u=c*r+l,f=Math.min(o-1,c+1)*r+l,p=l+1<r?1:0;return(s[u]*(1-m)+s[u+p]*m)*(1-d)+(s[f]*(1-m)+s[f+p]*m)*d}(this.guide,"depth",t,e):.6,s=.2+.8*a,r=this.edgeSafe?Ut(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,o=(t-this.x.value)*this.sx,n=(e-this.y.value)*this.sy,h=(o*o+n*n)/(r*r);if("reveal"===s)return void(i[2]=Math.exp(2.4*-h)*a);if(h>9)return;const l=this.edgeSafe?Ut(t,e,this.sx/this.sy):1;let c=0,m=0;if("loupe"===s){const t=Math.exp(-h*h)*a*.5;c=o*t,m=n*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(o*o+n*n));c=o/s*Math.min(e,s+.5*r*a),m=n/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=n/r+.45,h=Math.exp(-o*o/(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,d=t*this.sx*9,u=e*this.sy*9+2.3*l;c=.06*($t(d,u)-.5)*h,m=.026*($t(d+17.3,1.3*u+.7*l)-.5)*h,i[2]=.35*($t(1.7*d+5,1.7*u)-.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 o=0;o<t;o++){const n=4*(r*t+o);if(s?this.sample(o/(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[n]=t>>>8,i[n+1]=255&t,i[n+2]=128,i[n+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[n]=t>>>8,i[n+1]=255&t,i[n+2]=e>>>8,i[n+3]=255&e}}}},te=(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 ee(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 ie=t=>["trail","contour","etch","ripple","bleed","haze"].includes(t),ae=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]=Ut(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 Ht(this.columns,this.rows),this.contour=new Gt(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:zt(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:s(t)??"none";e!==this.mode&&(this.clear(),this.mode=e,this.refraction.mode=e,zt(e)&&this.afterimage.setMode(e),"ripple"!==e||this.ripple||(this.ripple=new qt(this.columns,this.rows)),Qt(e)&&(this.cursor??(this.cursor=new _t(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:zt(e)?this.afterimage.pixels:this.waterPixels,this.refraction.strength=te(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=te(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(zt(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,o=Math.hypot(s,r);if(o<1e-5)return;const n=.035+.1*this.radius,h=3*n,l=Math.min(192,Math.max(1,Math.ceil(o/(.5*n)))),c=95*Math.min(o,1)/l;for(let i=0;i<l;i++){const s=(i+.5)/l,r=a.x+(t-a.x)*s,o=a.y+(e-a.y)*s,m=Math.max(1,Math.floor((r-h/this.xScale)*(this.columns-1))),d=Math.min(this.columns-2,Math.ceil((r+h/this.xScale)*(this.columns-1))),u=Math.max(1,Math.floor((o-h/this.yScale)*(this.rows-1))),f=Math.min(this.rows-2,Math.ceil((o+h/this.yScale)*(this.rows-1)));for(let t=u;t<=f;t++)for(let e=m;e<=d;e++){const i=(e/(this.columns-1)-r)*this.xScale,a=(t/(this.rows-1)-o)*this.yScale,s=Math.exp(-(i*i+a*a)/(n*n))*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(zt(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 o=0;for(let t=1;t<this.rows-1;t++)for(let a=1;a<this.columns-1;a++){const n=t*this.columns+a,h=this.heights[n],l=this.heights[n-1]+this.heights[n+1]+this.heights[n-this.columns]+this.heights[n+this.columns]-4*h,c=Math.min(a,t,this.columns-1-a,this.rows-1-t),m=c<5?.88+.024*c:1,d=(this.velocity[n]+(l*i*i-8*h)*e)*s*m;this.velocity[n]=d,this.next[n]=(h+d*e)*m*r,o=Math.max(o,Math.abs(this.next[n]),.1*Math.abs(d))}this.heights.set(this.next),this.energy=o,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,o=Math.tanh(s)*(this.refraction.edgeSafe?this.edgeMask[i]:1),n=Math.tanh(r)*(this.refraction.edgeSafe?this.edgeMask[i]:1);this.normals[2*i]=o,this.normals[2*i+1]=n;const h=Math.round(32767*o+32768),l=Math.round(32767*n+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(zt(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),o=Math.floor(s),n=a-r,h=s-o,l=2*(o*this.columns+r),c=l+2*this.columns;for(let t=0;t<2;t++)i[t]=.08*((this.normals[l+t]*(1-n)+this.normals[l+2+t]*n)*(1-h)+(this.normals[c+t]*(1-n)+this.normals[c+2+t]*n)*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,o,n]=i.focus,h=(t-s)*Math.max(1,a)/n,l=(e-r)*Math.max(1,1/a)/n;return"light"===i.mode?Math.exp(-3*(h*h+l*l))*o:"scan"===i.mode?(1.3*Math.exp(-h*h*110)-.3*Math.exp(-h*h*12))*Math.exp(-l*l*1.8)*o:0}(t,e,this.refraction,this.xScale/this.yScale):0}};function se(t){return"videoWidth"in t?[t.videoWidth,t.videoHeight]:"naturalWidth"in t?[t.naturalWidth,t.naturalHeight]:[t.width,t.height]}var re=(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}},oe=(t,e,i)=>{t.width===e&&t.height===i||(t.width=e,t.height=i)},ne={blocks:" ░▒▓█",braille:" ⠁⠃⠇⡇⣇⣧⣷⣿",lines:" -═╪╬",cross:" ·+xX#",diagonal:" /╱╳",diamond:" ·◇◈◆",mixed:" .:+/◇#@"},he=.32,le=.9;function ce(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<he&&(s=Math.max(0,Math.min(1-he,(s+r)/2-.16)),r=s+he),[s,r]}function me(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 o=((.299*t[i]+.587*t[i+1]+.114*t[i+2])/255-e)/a;o<=.06||(s+=Math.min(1,o),r++)}if(!r)return le;const o=Math.min(.99,Math.max(.01,s/r));return Math.min(le,Math.max(.6,Math.log(.5)/Math.log(o)))}function de(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 ue(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()}}function fe(t,e={},i={}){const a=t.getContext("2d");if(!a)throw new Error("Canvas is already owned by another renderer.");const s=re(),r=re(!0),o=re(),h=re(),m=re(),d=re(),u=re(),f=re(),p=re(),g=re();let M,v=0,b=0,k=1,A=le,S=null,E=null,P=null,C="",T=K(e),I=0,R="",N="",L="",D=new Uint8ClampedArray(0),j=new Uint8ClampedArray(0),U=new Uint8ClampedArray(0),q=null,z="",Y=0,B=0,G=0,H=null,V="",Q=new ae,J=null,Z=new Float32Array(0);const $=re(!0),tt=re(),et=re();let at=0;const st=[0,0,0],rt=[0,0,0,1],ht=[0,0],lt=[0,0,0,0];let ct=ot(T.color),mt=pt(T.print);const dt=new nt(T.color.denoise),ut=new O(T.warps,T.warpEdge),ft=Math.max(64,Math.min(4096,Number.isFinite(i.maxDimension)?i.maxDimension:960)),gt=Math.max(256,Math.min(1048576,Number.isFinite(i.maxCells)?i.maxCells:12e3));let vt=gt,bt=Math.max(.1,Math.min(8,i.pixelRatio??1));return{canvas:t,render:function(e,i=0,O=960,K=540,ot=i*T.motion.speed){if(Number.isFinite(i)||(i=0),!Number.isFinite(O)||!Number.isFinite(K)||O<1||K<1)throw new Error("Render dimensions must be positive finite numbers.");const[nt,pt]=se(e);if(!nt||!pt)return;const gt=Math.min(1,ft/Math.max(O,K)),Et=Math.max(2,Math.round(O*gt)),Ft=Math.max(2,Math.round(K*gt));oe(t,Et,Ft),oe(s.canvas,Et,Ft),oe(o.canvas,Et,Ft),oe(h.canvas,Et,Ft),oe(m.canvas,Et,Ft),at!==Et/Ft&&(at=Et/Ft,Q=new ae(at),Q.setGuide(J)),Q.configure(T.hover.effect,T.hover.strength,T.hover.radius,T.hover.edgeSafe,T.hover.decay),Q.step(Math.max(0,Math.min(.05,i-G))),G=i;const Pt="currentTime"in e?e.getVideoPlaybackQuality?.().totalVideoFrames??e.currentTime:0,Ct=[I,Et,Ft,Pt].join(":"),Rt="dither"===T.style,Nt=it(Et,Ft,T,vt,bt),Ut=Nt.cell,qt=Nt.rowHeight,zt=Nt.columns,Yt=Nt.rows;if(R!==Ct||H!==e||Y!==zt||B!==Yt){H=e,R=Ct,z="",N="",L="",Y=zt,B=Yt,s.ctx.clearRect(0,0,Et,Ft),s.ctx.save();const t=_(nt,pt,Et,Ft,T.crop);s.ctx.translate(t.x+t.width/2,t.y+t.height/2),s.ctx.rotate(T.crop.rotation*Math.PI/180),s.ctx.drawImage(e,-nt*t.scale/2,-pt*t.scale/2,nt*t.scale,pt*t.scale),s.ctx.restore(),oe(r.canvas,Y,B),r.ctx.clearRect(0,0,Y,B),r.ctx.drawImage(s.canvas,0,0,Y,B),D=r.ctx.getImageData(0,0,Y,B).data,dt.apply(D,Y,B),j.length!==D.length&&(j=new Uint8ClampedArray(D.length)),j.set(D);const i=T.color;for(let t=0;t<D.length;t+=4){const e=.299*D[t]+.587*D[t+1]+.114*D[t+2];for(let a=0;a<3;a++){const s=e+(D[t+a]-e)*i.saturation;D[t+a]=((s*(1-i.grayscale)+e*i.grayscale)/255-.5)*i.contrast*255+127.5+255*i.brightness}}if(ct&&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]])}(D,ct),D=ut.apply(D,Y,B,Et/Ft),"none"!==T.color.levels){const[t,i]=ce(D),a=me(D,t,i),s=S===e&&"currentTime"in e?.15:1;S=e,b+=(t-b)*s,k+=(i-k)*s,A+=(a-A)*s}const a=T.hover,o=a.scope??"all";if("none"===a.effect||"all"===o&&"tilt"!==a.effect)J=null;else{let t=null;if(T.mask.enabled&&T.mask.shapes.length){oe($.canvas,Y,B),$.ctx.clearRect(0,0,Y,B),ue($.ctx,Y,B,T.mask.shapes);const e=$.ctx.getImageData(0,0,Y,B).data;t=new Float32Array(Y*B);for(let i=0;i<t.length;i++)t[i]=T.mask.invert?1-e[4*i+3]/255:e[4*i+3]/255}J=l(D,Y,B,t,J),Z.length!==Y*B&&(Z=new Float32Array(Y*B));for(let t=0;t<Z.length;t++)Z[t]=c(o,J.subject[t],J.key);if("reveal"===a.effect){oe(tt.canvas,Y,B);const t=new ImageData(Y,B);for(let e=0;e<Z.length;e++)t.data[4*e+3]=255*Z[e];tt.ctx.putImageData(t,0,0)}}Q.setGuide(J)}const Bt=xt(T),Wt=Mt(T),Gt=!Q.active&&!Bt&&!Wt,Ht=[Ct,Y,B,Ut,qt,bt,Q.signature].join(":"),Vt=Q.engaged,Qt=Q.effect;if(!Gt||L!==Ht){o.ctx.clearRect(0,0,Et,Ft),o.ctx.globalAlpha=1,o.ctx.globalCompositeOperation="source-over";const t=ot,e=Bt?T.motion.type:"none",a=T.motion.amount??1,l="relight"===(Jt=e)||"sheen"===Jt||"glow"===Jt||"shimmer"===Jt||"mist"===Jt;if("none"!==e&&z!==R&&(q=function(t,e,i,a,s=t){const r=e*i,o=a?.length===r*yt?a:new Float32Array(r*yt);if(!r)return o;const h=Math.min(e,i),l=new Float32Array(r),c=new Float32Array(r),m=new Float32Array(r),d=new Float32Array(r),u=new Float32Array(r),f=new Float32Array(r);for(let e=0;e<r;e++){const i=t[4*e+3]/255;l[e]=(.299*t[4*e]+.587*t[4*e+1]+.114*t[4*e+2])/255*i}c.set(l),n(c,f,e,i,Math.max(1,Math.round(.012*h))),m.set(l),n(m,f,e,i,Math.max(1,Math.round(.03*h)));for(let t=0;t<r;t++){d[t]=Math.abs(l[t]-c[t]);const e=Math.max(0,l[t]-.55)/.45;u[t]=e*e}n(d,f,e,i,Math.max(1,Math.round(.02*h)));const p=1/Math.max(.02,kt(d,.95));n(u,f,e,i,Math.max(1,Math.round(.05*h)));const g=1/Math.max(.03,kt(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 w=t,b=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 o=0;o<x;o++){const n=[0,0,0,0,0,0,0];for(let h=r*M;h<(r+1)*M;h++)for(let r=o*M;r<(o+1)*M;r++){const o=4*(h*e+r);for(let e=0;e<4;e++)n[e]+=t[o+e];if(a!==i)for(let t=0;t<3;t++)n[4+t]+=s[o+t]}const h=4*(r*x+o),l=M*M;for(let t=0;t<4;t++)i[h+t]=n[t]/l;if(a!==i){for(let t=0;t<3;t++)a[h+t]=n[4+t]/l;a[h+3]=i[h+3]}}w=i,b=a}St?.n!==y&&(St=new At(y)),St.reset();const{depth:k,water:A,sky:S,falls:E}=Tt(w,b,x,v,St),F=kt(k,.03),P=kt(k,.97),C=Math.max(.05,P-F);let T=0,I=0,R=0;const N=new Float32Array(r);for(let t=0;t<i;t++)for(let a=0;a<e;a++){const s=t*e+a,r=s*yt,n=wt((It(k,x,v,a,t,e,i)-F)/C);o[r+1]=n,o[r+8]=wt(It(A,x,v,a,t,e,i)),o[r+9]=wt(It(S,x,v,a,t,e,i)),o[r+10]=wt(It(E,x,v,a,t,e,i));const h=n*n*n*(.25+l[s]);T+=(a+.5)/e*h,I+=(t+.5)/i*h,R+=h,N[s]=Math.hypot(m[t*e+Math.min(e-1,a+1)]-m[t*e+Math.max(0,a-1)],m[Math.min(i-1,t+1)*e+a]-m[Math.max(0,t-1)*e+a])}T=R>0?Math.max(.3,Math.min(.7,T/R)):.5,I=R>0?Math.max(.3,Math.min(.7,I/R)):.5;const L=1/Math.max(.004,kt(N,.97));for(let t=0;t<i;t++)for(let a=0;a<e;a++){const s=t*e+a,r=s*yt,n=(m[t*e+Math.min(e-1,a+1)]-m[t*e+Math.max(0,a-1)])*L,h=(m[Math.min(i-1,t+1)*e+a]-m[Math.max(0,t-1)*e+a])*L;o[r]=m[s],o[r+2]=Math.min(1,u[s]*g),o[r+3]=Math.min(1,d[s]*p),o[r+4]=Math.max(-1,Math.min(1,-n)),o[r+5]=Math.max(-1,Math.min(1,-h)),o[r+6]=T,o[r+7]=I}return o}(j,Y,B,q),z=R),Rt){const s=Gt;if(!s||N!==Ct){U.length!==D.length&&(U=new Uint8ClampedArray(D.length));const o=U;if(o.set(D),Vt||"none"!==e)for(let i=0;i<B;i++)for(let s=0;s<Y;s++){const r=s/Y,n=i/B;let h=s,l=i,c=0,m=0,d=1;if(Vt){Q.sample(r,n,st);const t=J?Z[i*Y+s]:1;h-=st[0]*t*Y,l-=st[1]*t*B,"reveal"===Qt?d=1-.72*Math.min(1,st[2]*t):"repel"===Qt?d=1+Math.max(-1,st[2])*t:c=st[2]/3*t}const u=4*(i*Y+s);x(e,r,n,t,rt,(.299*D[u]+.587*D[u+1]+.114*D[u+2])/255,q??void 0,(i*Y+s)*yt),w(rt,a),(rt[0]||rt[1])&&(y(rt,h,l,Y,B,ht),h=ht[0],l=ht[1]),m=rt[2],d*=rt[3];const f=4*(i*Y+s);F(D,Y,B,h,l,lt);for(let t=0;t<3;t++){let e=ee(Qt,lt[t]/255,c)+m;o[f+t]=255*e}o[f+3]=lt[3]*d}!function(t,e,i,a,s=0){const{algorithm:r,amount:o,threshold:n}=a,h="blue-noise"===r,l=r.startsWith("bayer")?Number(r.slice(5)):0,c=Dt.get(l),m=l-1,d="luminance"===a.colorSpace,u=("custom"===a.palette?a.colors:W[a.palette]??W.mono).map(Xt),f=jt[r],p=f?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,w=u.map(t=>.299*t[0]+.587*t[1]+.114*t[2]),b="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?(Lt[64*(a-v&63)+(s-x&63)]+.5)/Lt.length:0;c?A=c[(a-v&m)*l+(s-x&m)]:"noise"===r?A=Ot(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 E=128*(A*o+b+(.5-n)),F=t[M]+E+(p?.[k]??0),P=t[M+1]+E+(p?.[k+1]??0),C=t[M+2]+E+(p?.[k+2]??0);let T=0,I=0,R=0;if(u.length){let t=1/0,e=1/0,i=0,a=0;const s=.299*F+.587*P+.114*C;for(let r=0;r<u.length;r++){const o=u[r],n=d?(s-w[r])**2:(F-o[0])**2*.299+(P-o[1])**2*.587+(C-o[2])**2*.114;n<t?(h&&(e=t,a=i,i=r),t=n,[T,I,R]=o):h&&n<e&&(e=n,a=r)}if(h&&o>0&&Number.isFinite(e)){const t=u[a],e=t[0]-T,r=t[1]-I,n=t[2]-R,h=w[a]-w[i],l=d?h*h:e*e*.299+r*r*.587+n*n*.114,c=d?(s-w[i])*h:(F-T)*e*.299+(P-I)*r*.587+(C-R)*n*.114;S<(l?Math.max(0,Math.min(1,c/l*o)):0)&&([T,I,R]=t)}}else if(h){const t=Math.max(0,Math.min(1,.5+(S-.5)*o));T=51*Math.floor(F/51+1-t),I=51*Math.floor(P/51+1-t),R=51*Math.floor(C/51+1-t)}else T=51*Math.round(F/51),I=51*Math.round(P/51),R=51*Math.round(C/51);if(t[M]=T,t[M+1]=I,t[M+2]=R,p&&f){p[k]=p[k+1]=p[k+2]=0;for(const[t,r,n]of f){const h=s+t;if(h<0||h>=e||a+r>=i)continue;const l=3*((a+r)%3*e+h);p[l]+=(F-T)*n*o,p[l+1]+=(P-I)*n*o,p[l+2]+=(C-R)*n*o}}}}(o,Y,B,T.dither,i),r.ctx.putImageData(new ImageData(o,Y,B),0,0),N=s?Ct:""}o.ctx.imageSmoothingEnabled=!1,o.ctx.drawImage(r.canvas,0,0,Et,Ft)}else{const i=Array.from(ne[T.style]??T.charset),s=o.ctx,r=Xt(T.ink),n="ripple"===Qt||"etch"===Qt,h=n&&.299*r[0]+.587*r[1]+.114*r[2]<90?[214,214,214]:r,c="ascii"===T.style||!!ne[T.style],m=X(T.style)?T.style:null,d=Math.max(3,Math.round(.92*qt)),f=Math.ceil(Ut+4),p=Math.ceil(qt+4),M=[i.join(""),d,f,p,T.ink,T.colorMode].join(":");if(c&&M!==V){V=M,oe(u.canvas,f*i.length,p),u.ctx.clearRect(0,0,u.canvas.width,p),u.ctx.font=`${d}px monospace`,u.ctx.textBaseline="middle",u.ctx.textAlign="center",u.ctx.fillStyle="accent"===T.colorMode?T.ink:"#ffffff",i.forEach((t,e)=>u.ctx.fillText(t,e*f+f/2,p/2)),E=null,C="";try{const t=u.ctx.getImageData(0,0,u.canvas.width,u.canvas.height).data;E=i.map((e,i)=>{let a=0;for(let e=0;e<u.canvas.height;e++)for(let s=i*f;s<(i+1)*f&&s<u.canvas.width;s++)a+=t[4*(e*u.canvas.width+s)+3];return a})}catch{E=null}}const S=c&&"none"!==T.color.levels;if(S&&E){const t=V+":"+A.toFixed(2);t!==C&&(C=t,P=de(E,A))}const I=Math.max(.001,k-b);if("lego"===T.style&&v!==Ut){v=Ut,oe(g.canvas,Math.ceil(Ut),Math.ceil(qt));const t=g.ctx;t.clearRect(0,0,g.canvas.width,g.canvas.height),t.fillStyle="rgba(255,255,255,.2)",t.strokeStyle="rgba(0,0,0,.25)",t.lineWidth=Math.max(.5,.6*bt),t.beginPath(),t.arc(Ut/2,qt/2,.28*Ut,0,2*Math.PI),t.fill(),t.stroke()}s.font=`${d}px monospace`,s.textBaseline="middle",s.textAlign="center";for(let o=0;o<B;o++)for(let d=0;d<Y;d++){let M=d,v=o,k=0,E=0;if(Vt){Q.sample(d/Y,o/B,st);const t=J?Z[o*Y+d]:1;M=Math.max(0,Math.min(Y-1,d-st[0]*t*Y)),v=Math.max(0,Math.min(B-1,o-st[1]*t*B)),"reveal"===Qt?E=.72*Math.min(1,st[2]*t):"repel"===Qt?E=-Math.max(-1,st[2])*t:k=st[2]/3*t}if("none"!==e){const i=4*(o*Y+d);x(e,d/Y,o/B,t,rt,(.299*D[i]+.587*D[i+1]+.114*D[i+2])/255,q??void 0,(o*Y+d)*yt),w(rt,a),(rt[0]||rt[1])&&(y(rt,M,v,Y,B,ht),M=ht[0],v=ht[1])}F(D,Y,B,M,v,lt);let C=0;if(n&&k>.012&&(lt[3]?lt[3]>250&&.299*lt[0]+.587*lt[1]+.114*lt[2]<30:"outside"===T.hover.scope)){const t=Math.min(1,(k-.012)/.12);C=t*t*(3-2*t)}if(!lt[3]){if(!(C||k>.03)||"outside"!==T.hover.scope||!ie(Qt))continue;lt[0]=h[0],lt[1]=h[1],lt[2]=h[2],lt[3]=C?255:Math.min(255,640*k)}const R=lt[0],N=lt[1],L=lt[2],O=(.299*R+.587*N+.114*L)/255;let j=S?Math.max(0,Math.min(1,(O-b)/I)):O;j=ee(Qt,j,k,!!m&&mt.settings.invert);const X=d*Ut,U=o*qt;let z=1,W=j;if("none"!==e){const t=rt[2]/(S?Math.max(.5,I):1);j=Math.max(0,Math.min(1,j+t)),W=Math.max(0,Math.min(1,W+t*(l?.45:1)))}else W=j;C&&(j=W=Math.max(j,.1+.45*C)),z=("none"!==e?rt[3]:1)*lt[3]/255*(1-E)*(C?.3+.45*C:1),c||m||"accent"!==T.colorMode||"cmyk"===T.style?S&&"accent"===T.colorMode&&(z*=.32+.68*Math.pow(j,A)):z*=j,s.globalAlpha=z;const G=255*(j-O),H="source"===T.colorMode?`rgb(${R+G},${N+G},${L+G})`:"gray"===T.colorMode?`rgb(${Math.round(255*j)},${Math.round(255*j)},${Math.round(255*j)})`:T.ink;if(s.fillStyle=H,m)mt.paint(s,m,d,o,X,U,Ut,j,H,"gray"===T.colorMode?255*j:R+G,"gray"===T.colorMode?255*j:N+G,"gray"===T.colorMode?255*j:L+G,T.colorMode);else if(c){const t=S&&P?P[Math.round(255*W)]:Math.max(0,Math.min(i.length-1,Math.round(W*(i.length-1))));"accent"===T.colorMode?s.drawImage(u.canvas,t*f,0,f,p,Math.round(X+(Ut-f)/2),Math.round(U+(qt-p)/2),f,p):s.fillText(i[t],X+Ut/2,U+qt/2)}else if("dots"===T.style)s.beginPath(),s.arc(X+Ut/2,U+qt/2,.48*Ut*Math.sqrt(j),0,2*Math.PI),s.fill();else if("led"===T.style)s.beginPath(),s.arc(X+Ut/2,U+qt/2,.39*Ut,0,2*Math.PI),s.fill(),s.globalAlpha=.35*z,s.fillStyle="#ffffff",s.beginPath(),s.arc(X+.43*Ut,U+.4*qt,.11*Ut,0,2*Math.PI),s.fill();else if("hex"===T.style){const t=X+Ut/2,e=U+qt/2;s.beginPath();for(let i=0;i<6;i++){const a=Math.PI/3*i,r=t+Math.cos(a)*Ut*.49,o=e+Math.sin(a)*qt*.49;0===i?s.moveTo(r,o):s.lineTo(r,o)}s.closePath(),s.fill()}else if("cmyk"===T.style){s.fillStyle="#ffffff",s.fillRect(X,U,Ut,qt);const t=(t,e)=>Math.max(0,Math.min(255,"source"===T.colorMode?t+G:"gray"===T.colorMode?255*j:e*j)),e=t(R,r[0]),i=t(N,r[1]),a=t(L,r[2]),o=1-Math.max(e,i,a)/255,n=Math.max(.001,1-o),h=[["#00ffff",(1-e/255-o)/n,.36,.36],["#ff00ff",(1-i/255-o)/n,.64,.36],["#ffff00",(1-a/255-o)/n,.5,.66],["#000000",o,.5,.5]];s.globalCompositeOperation="multiply";for(const[t,e,i,a]of h)s.fillStyle=t,s.beginPath(),s.arc(X+Ut*i,U+qt*a,.48*Ut*Math.sqrt(Math.max(0,e)),0,2*Math.PI),s.fill();s.globalCompositeOperation="source-over"}else if("voxel"===T.style){const t=X+Ut/2,e=U+qt/2;s.beginPath(),s.moveTo(t,U),s.lineTo(X+Ut,U+.25*qt),s.lineTo(t,e),s.lineTo(X,U+.25*qt),s.closePath(),s.fill(),s.globalAlpha=.72*z,s.beginPath(),s.moveTo(X,U+.25*qt),s.lineTo(t,e),s.lineTo(t,U+qt),s.lineTo(X,U+.75*qt),s.closePath(),s.fill(),s.globalAlpha=.42*z,s.beginPath(),s.moveTo(t,e),s.lineTo(X+Ut,U+.25*qt),s.lineTo(X+Ut,U+.75*qt),s.lineTo(t,U+qt),s.closePath(),s.fill()}else{const t="pixel"===T.style?0:Math.max(.5,.06*Ut);s.fillRect(X,U,Ut-t,qt-t),"lego"===T.style&&s.drawImage(g.canvas,X,U),"disco"===T.style&&(s.fillStyle=`rgba(255,255,255,${.1+.25*Ot(d,o)})`,s.fillRect(X,U,Ut-t,.35*qt),s.fillStyle="rgba(0,0,0,.25)",s.fillRect(X,U+.65*qt,Ut-t,.35*qt-t))}}}o.ctx.globalAlpha=1,(T.color.amount||T.lights.length)&&(oe(f.canvas,Et,Ft),f.ctx.clearRect(0,0,Et,Ft),f.ctx.drawImage(o.canvas,0,0)),T.color.amount&&(o.ctx.save(),o.ctx.globalCompositeOperation=T.color.blend,o.ctx.globalAlpha=T.color.amount,o.ctx.fillStyle=T.color.tint,o.ctx.fillRect(0,0,Et,Ft),o.ctx.restore());for(const t of T.lights){const e=t.radius*Math.max(Et,Ft),i=o.ctx.createRadialGradient(t.x*Et,t.y*Ft,0,t.x*Et,t.y*Ft,e);i.addColorStop(0,t.color),i.addColorStop(1,"transparent"),o.ctx.save(),o.ctx.globalCompositeOperation="screen",o.ctx.globalAlpha=t.intensity,o.ctx.fillStyle=i,o.ctx.fillRect(0,0,Et,Ft),o.ctx.restore()}(T.color.amount||T.lights.length)&&(o.ctx.globalCompositeOperation="destination-in",o.ctx.drawImage(f.canvas,0,0),o.ctx.globalCompositeOperation="source-over"),T.mask.enabled&&T.mask.shapes.length&&(ue(m.ctx,Et,Ft,T.mask.shapes),o.ctx.globalCompositeOperation=T.mask.invert?"destination-out":"destination-in",o.ctx.drawImage(m.canvas,0,0),o.ctx.globalCompositeOperation="source-over");const c=h.ctx;c.clearRect(0,0,Et,Ft),c.globalAlpha=T.backdrop.opacity;const M=T.backdrop;if("solid"===M.mode&&(c.fillStyle=M.color,c.fillRect(0,0,Et,Ft)),"gradient"===M.mode){const t=c.createLinearGradient(0,0,Et,Ft);t.addColorStop(0,M.color),t.addColorStop(1,M.color2),c.fillStyle=t,c.fillRect(0,0,Et,Ft)}if("source"===M.mode&&c.drawImage(s.canvas,0,0),"blurred"===M.mode){const t=Math.max(1,M.blur);oe(d.canvas,Math.max(2,Math.round(Et/t)),Math.max(2,Math.round(Ft/t))),d.ctx.drawImage(s.canvas,0,0,d.canvas.width,d.canvas.height),c.imageSmoothingEnabled=!0,c.drawImage(d.canvas,0,0,Et,Ft)}c.globalAlpha=1,T.effects.characterBloom>0&&(oe(p.canvas,Math.max(2,Math.round(Et/3)),Math.max(2,Math.round(Ft/3))),p.ctx.clearRect(0,0,p.canvas.width,p.canvas.height),p.ctx.drawImage(o.canvas,0,0,p.canvas.width,p.canvas.height),c.save(),c.globalAlpha=.8*T.effects.characterBloom,c.globalCompositeOperation="screen",c.filter=`blur(${1+4*T.effects.characterBloom}px)`,c.drawImage(p.canvas,0,0,Et,Ft),c.restore());const S=Q.spotlight;if(S&&S[2]>.002){oe(et.canvas,Et,Ft);const t=et.ctx,e=S[3]*Math.min(Et,Ft)*1.6;t.globalCompositeOperation="source-over",t.clearRect(0,0,Et,Ft),t.drawImage(s.canvas,0,0),t.globalCompositeOperation="destination-in";const i=t.createRadialGradient(S[0]*Et,S[1]*Ft,0,S[0]*Et,S[1]*Ft,e),a=Math.min(1,S[2]*T.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,Et,Ft),J&&"all"!==(T.hover.scope??"all")&&(t.imageSmoothingEnabled=!0,t.drawImage(tt.canvas,0,0,Et,Ft)),t.globalCompositeOperation="source-over",c.drawImage(et.canvas,0,0)}c.drawImage(o.canvas,0,0),L=Gt?Ht:""}var Jt;const Kt=Object.entries(T.effects).some(([t,e])=>!["angle","focus","blurType","characterBloom"].includes(t)&&"number"==typeof e&&e>0);a.clearRect(0,0,Et,Ft),Kt?(void 0===M&&(M=function(){const t=document.createElement("canvas"),e=t.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,antialias:!1,preserveDrawingBuffer:!0});if(!e)return null;const i=[],a=(t,a)=>{const s=e.createShader(t);if(i.push(s),e.shaderSource(s,a),e.compileShader(s),!e.getShaderParameter(s,e.COMPILE_STATUS))throw new Error(e.getShaderInfoLog(s)||"Finish shader failed");return s},s=e.createProgram();if(e.attachShader(s,a(e.VERTEX_SHADER,"attribute vec2 p;varying vec2 uv;void main(){uv=(p+1.)*.5;gl_Position=vec4(p,0.,1.);}")),e.attachShader(s,a(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(s),!e.getProgramParameter(s,e.LINK_STATUS))throw new Error("Finish link failed");e.useProgram(s);const r=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),e.STATIC_DRAW);const o=e.getAttribLocation(s,"p");e.enableVertexAttribArray(o),e.vertexAttribPointer(o,2,e.FLOAT,!1,0,0);const n=e.createTexture();e.bindTexture(e.TEXTURE_2D,n),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);const h=["t","bloom","grain","dust","scanlines","crt","prism","rgbSplit","sharpen","vignette","glitch","pixelate","blur","blurMode","angle","focus","halftone"],l=Object.fromEntries(h.map(t=>[t,e.getUniformLocation(s,t)])),c=e.getUniformLocation(s,"size");return{canvas:t,render(i,a,r,o=1){t.width===i.width&&t.height===i.height||(t.width=i.width,t.height=i.height,e.viewport(0,0,t.width,t.height)),e.useProgram(s),e.bindTexture(e.TEXTURE_2D,n),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,i),e.uniform2f(c,t.width/o,t.height/o);for(const t of h)e.uniform1f(l[t],"t"===t?r:"blurMode"===t?["gaussian","directional","radial","progressive"].indexOf(a.blurType):"angle"===t?a.angle*Math.PI/180:a[t]??0);return e.drawArrays(e.TRIANGLE_STRIP,0,4),t},destroy(){e.deleteTexture(n),e.deleteBuffer(r),e.deleteProgram(s),i.forEach(t=>e.deleteShader(t)),t.width=t.height=1,e.getExtension("WEBGL_lose_context")?.loseContext()}}}()),M?a.drawImage(M.render(h.canvas,T.effects,i,bt),0,0):a.drawImage(h.canvas,0,0),t.dataset.studioFinish=M?"gpu":"unavailable"):(a.drawImage(h.canvas,0,0),t.dataset.studioFinish="none")},setPixelRatio(t){bt=Math.max(.1,Math.min(8,Number.isFinite(t)?t:1))},get pixelRatio(){return bt},setBudget(t){vt=Math.max(256,Math.min(gt,Number.isFinite(t)?Math.round(t):gt))},get maxCells(){return vt},configure(t){T=K(t),ct=ot(T.color),mt=pt(T.print),dt.configure(T.color.denoise),ut.configure(T.warps,T.warpEdge),I++},pointer:(t,e,i)=>{Q.configure(T.hover.effect,T.hover.strength,T.hover.radius,T.hover.edgeSafe,T.hover.decay),Q.move(t,e,i)},leave(){Q.leave()},get active(){return Q.active},get settings(){return K(T)},get capabilities(){return{gpuFinish:null!==M}},invalidate(){R=""},destroy(){M?.destroy(),ut.clear(),dt.configure(0);for(const t of[s,r,o,h,m,d,u,f,p,g,$,tt,et])t.canvas.width=t.canvas.height=1;H=null,D=new Uint8ClampedArray(0),U=new Uint8ClampedArray(0),q=null,z=""}}}function pe(t,e,i){return new Promise((a,s)=>{const r=()=>{l(),a()},o=()=>{l(),s(new Error("Unable to load this media. Check its format and cross-origin permissions."))},n=()=>{l(),s(new DOMException("Cancelled","AbortError"))},h=setTimeout(o,2e4),l=()=>{clearTimeout(h),t.removeEventListener(e,r),t.removeEventListener("error",o),i?.removeEventListener("abort",n)};t.addEventListener(e,r,{once:!0}),t.addEventListener("error",o,{once:!0}),i?.addEventListener("abort",n,{once:!0}),i?.aborted&&n()})}async function ge(t,e){if("string"==typeof t&&t.startsWith("blob:")){const i=await fetch(t,{signal:e}),a=await i.blob();return ge(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,o=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 n=s(o),h=n.lsd.width,l=n.lsd.height;if(h*l>4e6)throw new Error("GIF is too large. Use a smaller GIF or an MP4.");const c=n.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(n,!0);if(m.length*h*l*4>128e6)throw new Error("GIF exceeds the 128 MB decoded budget. Use MP4 for long animations.");const d=document.createElement("canvas");d.width=h,d.height=l;const u=d.getContext("2d"),f=document.createElement("canvas"),p=f.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&&(u.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&&u.clearRect(e.dims.left,e.dims.top,e.dims.width,e.dims.height),3===e?.disposalType&&x&&u.putImageData(x,0,0);const i=m[t];x=3===i.disposalType?u.getImageData(0,0,h,l):null,f.width=i.dims.width,f.height=i.dims.height,p.putImageData(new ImageData(new Uint8ClampedArray(i.patch),f.width,f.height),0,0),u.drawImage(f,i.dims.left,i.dims.top)}return M=a,d};return v(0),{source:d,width:h,height:l,duration:g,animated:!0,seek:async()=>{},frame:v,destroy(){d.width=f.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,o=s?document.createElement("video"):new Image;o.crossOrigin="anonymous",o instanceof HTMLVideoElement&&(o.muted=!0,o.playsInline=!0,o.preload="auto");const n=()=>{o instanceof HTMLVideoElement?(o.pause(),o.removeAttribute("src"),o.load()):o.src="",i&&URL.revokeObjectURL(r)};try{const t=pe(o,s?"loadeddata":"load",e);o.src=r,await t;const i=o instanceof HTMLVideoElement?o.videoWidth:o.naturalWidth,a=o instanceof HTMLVideoElement?o.videoHeight:o.naturalHeight;return{source:o,width:i,height:a,duration:o instanceof HTMLVideoElement?o.duration:0,animated:s,async seek(t,e){if(!(o instanceof HTMLVideoElement))return;if(!Number.isFinite(o.duration)||o.duration<=0)throw new Error("Video duration is unavailable.");const i=Math.max(0,Math.min(o.duration-.001,t%o.duration));if(Math.abs(o.currentTime-i)<.001&&o.readyState>=2)return;const a=pe(o,"seeked",e);o.currentTime=i,await a},frame:()=>o,destroy:n}}catch(t){throw n(),t}}var Me=t=>{if(t?.aborted)throw new DOMException("Export cancelled","AbortError")};async function xe(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 o=Math.max(1,Math.min(60,Math.round(e.fps??24))),n=e.duration??5;if(!Number.isFinite(n)||n<=0||n>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||n*o>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&&o>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(Me(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.");Me(a);const o=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 Me(a),e.onProgress?.(1),o}const d=Math.ceil(n*o);if("gif"===i){const i=await import("gifenc"),{GIFEncoder:h,quantize:l,applyPalette:m}="function"==typeof i.GIFEncoder?i:i.default,u=h(),f=c.getContext("2d");for(let i=0;i<d;i++){Me(a);const h=i/o;if(await t(c,h,s,r,a),Me(a),"unavailable"===c.dataset.studioFinish)throw new Error("Optical effects need WebGL. Disable these effects or export in a supported browser.");const p=f.getImageData(0,0,s,r).data,g=l(p,256),M=m(p,g);u.writeFrame(M,s,r,{palette:g,delay:10*(Math.round(100*Math.min((i+1)/o,n))-Math.round(100*i/o)),repeat:0}),e.onProgress?.((i+1)/d*.98),await new Promise(t=>setTimeout(t,0))}return Me(a),u.finish(),e.onProgress?.(1),new Blob([new Uint8Array(u.bytes())],{type:"image/gif"})}const{Output:u,Mp4OutputFormat:f,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 u({format:"mp4"===i?new f({fastStart:"in-memory"}):new p,target:new g});c.width=s,c.height=r,m=()=>y.cancel();const w=new M(c,{codec:v,bitrate:Math.max(5e5,Math.round(s*r*o*.15))});y.addVideoTrack(w,{frameRate:o}),c.width=s,c.height=r,await y.start();for(let i=0;i<d;i++){Me(a);const h=i/o;if(await t(c,h,s,r,a),Me(a),"unavailable"===c.dataset.studioFinish)throw new Error("Optical effects need WebGL. Disable these effects or export in a supported browser.");await w.add(h,Math.min(1/o,n-h)),e.onProgress?.((i+1)/d*.98),i%4==0&&await new Promise(t=>setTimeout(t,0))}return w.close(),Me(a),await y.finalize(),Me(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}}async function ve(t,e,i){let a;const s=K(e),r="png"!==i.format&&"jpeg"!==i.format;try{return await xe(async(e,o,n,h,l,c)=>{a??(a=fe(e,s,{maxDimension:4096,maxCells:i.maxCells??12e3,pixelRatio:n/(i.referenceWidth??Math.min(n,960))})),r&&a.invalidate(),a.render(await t.frame(o,l),o,n,h,c)},i)}finally{a?.destroy()}}async function ye(t,e,i={}){const a=await ge(e,i.signal);try{return we(t,a,i)}catch(t){throw a.destroy(),t}}function we(t,e,i={}){let a=K(i.settings),s=i.width??e.width,r=i.height??e.height;const o=fe(t,a,i),n=new M;let h=0,l=!1,c=!0,m=!1,d=!0,u=0,f=0,p=0,g=0,x=-1,v=!1,y=!1!==i.adaptive,w=0,b=0,k=0,A=0,S=o.maxCells;const E=matchMedia("(prefers-reduced-motion: reduce)"),F=e.source instanceof HTMLVideoElement?e.source:null,P=()=>{l||h||!d||document.hidden||(h=requestAnimationFrame(I))},C=()=>!m&&!E.matches&&d&&!document.hidden,T=()=>{F&&(F.loop=!0,C()?F.play().catch(()=>{m=!0,c=!0,P()}):F.pause()),p=0,c=!0,P()};function I(t){if(h=0,l||!d||document.hidden)return;const M=C();M&&(u+=p?Math.min(.1,(t-p)/1e3):0),p=t;const E=vt(a),T=M&&(e.animated||E),I=F?.getVideoPlaybackQuality?.().totalVideoFrames??-1,R=!F||I<0||I!==x,N=1e3/Math.max(1,Math.min(60,i.fps??60))-.5;if(c||(o.active?t-g>=Math.max(N,2*b):v)||T&&(R||E)&&t-g>=N){const h=performance.now();try{e.animated&&!F&&o.invalidate();const[t,l]=tt(s,r,a);f=n.update(u,a.motion.type,a.motion.speed),o.render(e.frame(F?.currentTime??u),u,t,l,f);const c=performance.now()-h;if(i.onFrame?.(F?.currentTime??u,c),b=b?.9*b+.1*c:c,++w>20&&y&&(T||o.active)){const t=1e3/Math.max(1,Math.min(60,i.fps??60));k=b>1.1*t?k+1:0,A=b<.5*t?A+1:0,k>=20&&o.maxCells>3e3?(o.setBudget(Math.max(3e3,.8*o.maxCells)),i.onQualityChange?.(o.maxCells),k=0,b=0):A>=30&&o.maxCells<S&&(o.setBudget(Math.min(S,1.25*o.maxCells)),i.onQualityChange?.(o.maxCells),A=0,b=0)}}catch(t){m=!0,i.onError?.(t instanceof Error?t:new Error(String(t)))}c=!1,g=t,v=o.active,x=I}M&&(T||o.active)?P():T||o.active||o.maxCells>=S||(o.setBudget(S),i.onQualityChange?.(o.maxCells),k=A=b=w=0,0)||(c=!0,P())}const R=e=>{if(!C())return;const i=t.getBoundingClientRect();o.pointer((e.clientX-i.left)/i.width,(e.clientY-i.top)/i.height,e.timeStamp),P()},N=()=>{o.leave(),P()},L=t=>{"touch"===t.pointerType&&N()},O=new IntersectionObserver(([t])=>{d=t.isIntersecting,T()});O.observe(t),t.addEventListener("pointermove",R),t.addEventListener("pointerup",L),t.addEventListener("pointerleave",N),t.addEventListener("pointercancel",N),document.addEventListener("visibilitychange",T),E.addEventListener("change",T);const D=()=>{l||(l=!0,cancelAnimationFrame(h),O.disconnect(),t.removeEventListener("pointermove",R),t.removeEventListener("pointerup",L),t.removeEventListener("pointerleave",N),t.removeEventListener("pointercancel",N),document.removeEventListener("visibilitychange",T),E.removeEventListener("change",T),i.signal?.removeEventListener("abort",D),o.destroy(),e.destroy())};if(i.signal?.addEventListener("abort",D,{once:!0}),i.signal?.aborted)throw D(),new DOMException("Cancelled","AbortError");return T(),{canvas:t,media:e,update(t){a=et(a,t),o.configure(a),c=!0,P()},resize(t,e,i){void 0!==i&&o.setPixelRatio(i),s=Math.max(2,t),r=Math.max(2,e),c=!0,P()},pause(t=!0){m=t,T()},async seek(t){u=Math.max(0,t),await e.seek(u),o.invalidate(),c=!0,P()},redraw(){o.invalidate(),c=!0,P()},get time(){return F?.currentTime??u},get settings(){return K(a)},get motionTime(){return f},get paused(){return m||E.matches},setAdaptive(t){y=t,w=k=b=0},setBudget(t){o.setBudget(t),S=o.maxCells,k=A=b=w=0,i.onQualityChange?.(o.maxCells),c=!0,P()},get pixelRatio(){return o.pixelRatio},get maxCells(){return o.maxCells},get capabilities(){return o.capabilities},destroy:D}}var be={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")},ke=Object.keys(be);async function Ae(t,e="Standard",i="#ffffff",a="#080808"){if(!Object.prototype.hasOwnProperty.call(be,e))throw new Error("Unknown text font.");const{default:s}=await import("figlet/browser"),r=await be[e]();s.parseFont(e,r.default),s.defaults({fetchFontIfMissing:!1});const o=s.textSync(t.slice(0,120),{font:e}),n=o.split("\n"),h=Math.max(1,...n.map(t=>t.length)),l=Math.max(1,n.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 d=m.getContext("2d");return null!==a&&(d.fillStyle=a,d.fillRect(0,0,m.width,m.height)),d.fillStyle=i,d.font=15*c+"px monospace",d.textBaseline="top",n.forEach((t,e)=>d.fillText(t,16,16+15*e*c)),{canvas:m,ascii:o}}var Se={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:" ⠁⠃⠇⡇⣇⣧⣷⣿"}},Ee=Se,Fe=8,Pe=t=>t&&"object"==typeof t&&!Array.isArray(t)?t:{},Ce=(t,e,i,a)=>"number"==typeof t&&Number.isFinite(t)?Math.max(i,Math.min(a,t)):e,Te=(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 Ie(t={}){const e=Pe(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(Ce(e.width,1280,2,4096)),height:Math.round(Ce(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=Pe(t),s=Pe(i.placement),r=Pe(i.settings),o=Pe(r.backdrop),n=Te(i.id,"Layer id"),h=Te(i.source,"Source key");if(a.has(n))throw new Error(`Duplicate layer id: ${n}`);return a.add(n),{id:n,source:h,name:"string"==typeof i.name?i.name.slice(0,80):`Layer ${e+1}`,visible:!1!==i.visible,opacity:Ce(i.opacity,1,0,1),blend:B.includes(i.blend)?i.blend:"source-over",placement:{x:Ce(s.x,.5,-1,2),y:Ce(s.y,.5,-1,2),width:Ce(s.width,1,.01,2),height:Ce(s.height,1,.01,2),rotation:Ce(s.rotation,0,-180,180),flipX:!0===s.flipX,flipY:!0===s.flipY},settings:K({...r,backdrop:{mode:"transparent",...o}})}})}}function Re(t,e,i){if(!t.layers.some(t=>t.id===e))throw new Error(`Unknown layer: ${e}`);return Ie({...t,layers:t.layers.map(t=>t.id!==e?t:{...t,...i,id:e,placement:{...t.placement,...i.placement},settings:et(t.settings,i.settings??{})})})}var Ne=t=>JSON.stringify(Ie(t));function Le(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 Ie(e)}function Oe(t,e,i,a,s){const r=t.placement,o=r.rotation*Math.PI/180,n=Math.cos(o),h=Math.sin(o),l=(e-r.x)*a,c=(i-r.y)*s,m=(l*n+c*h)/(r.width*a),d=(-l*h+c*n)/(r.height*s);return[.5+m*(r.flipX?-1:1),.5+d*(r.flipY?-1:1)]}function De(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)),o=(s*i.width*t.width+r*i.height*t.height)/2,n=(r*i.width*t.width+s*i.height*t.height)/2;return i.x*t.width+o>0&&i.x*t.width-o<t.width&&i.y*t.height+n>0&&i.y*t.height-n<t.height})}function je(t,e=24e3,i=4194304,a=t.width,s=t.height){const r=De(t),o=Math.round(Ce(e,24e3,2048,1048576)),n=Ce(i,4194304,65536,16777216),h=r.map(t=>t.placement.width*t.placement.height),l=h.reduce((t,e)=>t+e,0),c=o-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)}}),d=m.reduce((t,e)=>t+e.width*e.height,0);let u=0,f=0;return r.map((t,e)=>{const i=e===r.length-1?o-u:256+Math.floor(c*h[e]/l);u+=i;const a=m[e],s=e===r.length-1?n-f:4+Math.floor((n-4*r.length)*a.width*a.height/Math.max(1,d));f+=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 Xe(t,e={},i={}){const a=t.getContext("2d");if(!a)throw new Error("Project canvas is already owned by another renderer.");let s=Ie(e),r=!0,o=!1,n=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)),d=[];const u=new Map,f=()=>{if(o)throw new Error("Project renderer has been destroyed.")};return{canvas:t,render(e,o=0,p=s.width,g=s.height,M={}){if(f(),!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 w={...s,width:v,height:y},b=De(w);for(const t of b)if(!e.has(t.source))throw new Error(`Missing project source: ${t.source}`);const k=new Set(b.map(t=>t.id));for(const[t,e]of u)k.has(t)||(e.renderer.destroy(),u.delete(t),r=!0);d=je(w,c,i.maxRasterPixels,v,y);for(let t=0;t<b.length;t++){const i=b[t],a=d[t],s=e.get(i.source);if(!s)throw new Error(`Missing project source: ${i.source}`);let h=u.get(i.id);const c=n.get(i.id);h?h.signature!==c&&(h.renderer.configure(i.settings),h.signature=c,h.dirty=!0):(h={renderer:fe(document.createElement("canvas"),i.settings,{maxDimension:4096,maxCells:l}),signature:c,dirty:!0,geometry:""},u.set(i.id,h));const f=m*a.width/(p*i.placement.width),g=`${a.width}:${a.height}:${a.maxCells}:${f}`;h.geometry!==g&&(h.renderer.setBudget(a.maxCells),h.renderer.setPixelRatio(f),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||vt(i.settings)){const t=Object.prototype.hasOwnProperty.call(M,i.id)?M[i.id]:void 0;h.renderer.render(s,o,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 b){const e=u.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){f(),s=Ie(t),n=new Map(s.layers.map(t=>[t.id,JSON.stringify(t.settings)])),(()=>{const t=new Set(De(s).map(t=>t.id));for(const[e,i]of u)t.has(e)||(i.renderer.destroy(),u.delete(e))})(),r=!0},pointer(e,i,a){if(o||!Number.isFinite(e)||!Number.isFinite(i))return;if(e<0||e>1||i<0||i>1){for(const t of u.values())t.renderer.leave();return}let r=!1;for(const o of De({...s,width:t.width,height:t.height}).reverse()){const n=u.get(o.id);if(!n)continue;const[h,l]=Oe(o,e,i,t.width,t.height);(!r||"all"===s.pointerMode)&&h>=0&&h<=1&&l>=0&&l<=1&&"none"!==o.settings.hover.effect&&o.settings.hover.strength>0?(n.renderer.pointer(h,l,a),r=!0):n.renderer.leave()}},leave(){for(const t of u.values())t.renderer.leave()},invalidate(t){f();for(const e of s.layers)if(void 0===t||t===e.source){const t=u.get(e.id);t&&(t.renderer.invalidate(),t.dirty=!0)}r=!0},setBudget(t){f(),c=Math.max(2048,Math.min(l,Number.isFinite(t)?Math.round(t):l)),r=!0},setPixelRatio(t){f(),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 d.map(t=>({...t}))},get active(){return[...u.values()].some(t=>t.renderer.active)},destroy(){if(!o){o=!0;for(const t of u.values())t.renderer.destroy();u.clear(),t.width=t.height=1}}}}function Ue(t,e){for(const i of t.layers)if(!e.has(i.source))throw new Error(`Missing project source: ${i.source}`)}async function qe(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.");Ue(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 ge(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 Ae(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}}async function ze(t,e,i,a={}){const s=Ie(e),r=await qe(s,i,a.signal);try{return Ye(t,s,r,a)}catch(t){for(const t of new Set(r.values()))t.destroy();throw t}}function Ye(t,e,i,a={}){if((i=new Map(i)).size>8)throw new Error("A project supports up to 8 media bindings.");let s=Ie(e);if(Ue(s,i),a.signal?.aborted)throw new DOMException("Cancelled","AbortError");const r=Xe(t,s,a),o=matchMedia("(prefers-reduced-motion: reduce)"),n=[...new Set(i.values())],h=n.filter(t=>t.source instanceof HTMLVideoElement).map(t=>t.source),l=new Map;let c,m={},d=0,u=0,f=0,p=0,g=!0,x=!1,v=!0,y=!1,w=!1!==a.adaptive,b=0,k=0,A=0,S=0,E=s.width,F=s.height,P=0,C=!1,T=r.maxCells;const I=new WeakSet,R=Math.max(1,Math.min(60,Number.isFinite(a.fps)?a.fps:60)),N=()=>!y&&!x&&!C&&!o.matches&&v&&!document.hidden,L=()=>{y||p||!v||document.hidden||(p=requestAnimationFrame(X))},O=()=>new Set(De({...s,width:E,height:F}).map(t=>i.get(t.source).source)),D=()=>{const t=O();for(const e of h)e.loop=!0,N()&&t.has(e)?e.paused&&!I.has(e)&&(I.add(e),e.play().then(()=>{I.delete(e),N()&&O().has(e)||e.pause()}).catch(t=>{I.delete(e),y||(x=!0,D(),a.onError?.(t instanceof Error?t:new Error(String(t))),g=!0,L())})):e.pause()},j=()=>{u=0,g=!0,D(),L()};function X(t){if(p=0,y||!v||document.hidden)return;const e=N();e&&(d+=u?Math.min(.1,(t-u)/1e3):0),u=t;const o=De({...s,width:E,height:F}),n=o.some(t=>i.get(t.source).animated||vt(t.settings));if(g||e&&r.active||e&&n&&t-f>=1e3/R-.5){const s=performance.now();try{const t=new Map,h=new Set(o.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(d))}m={};for(const t of o){let e=l.get(t.id);e||(e=new M,l.set(t.id,e)),m[t.id]=e.update(d,t.settings.motion.type,t.settings.motion.speed)}r.render(t,d,E,F,m);const c=performance.now()-s;if(a.onFrame?.(d,c),k=k?.9*k+.1*c:c,++b>20&&w&&e&&(n||r.active)){const t=1e3/R;A=k>1.1*t?A+1:0,S=k<.5*t?S+1:0,A>=20&&r.maxCells>2048?(r.setBudget(Math.max(2048,.8*r.maxCells)),a.onQualityChange?.(r.maxCells),k=A=0,g=!0):S>=30&&r.maxCells<T&&(r.setBudget(Math.min(T,1.25*r.maxCells)),a.onQualityChange?.(r.maxCells),k=S=0,g=!0)}}catch(t){x=!0,D(),a.onError?.(t instanceof Error?t:new Error(String(t)))}g=!1,f=t}e&&(n||r.active)?L():!n&&!r.active&&r.maxCells<T&&(r.setBudget(T),a.onQualityChange?.(r.maxCells),b=A=S=k=0,g=!0,L())}const U=e=>{if(!N())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),L())},q=()=>{r.leave(),L()},z=new IntersectionObserver(([t])=>{v=t.isIntersecting,j()});z.observe(t),t.addEventListener("pointermove",U),t.addEventListener("pointerleave",q),t.addEventListener("pointercancel",q),document.addEventListener("visibilitychange",j),o.addEventListener("change",j);const Y=()=>{if(!y){y=!0,P++,c?.abort(),cancelAnimationFrame(p),p=0,z.disconnect(),t.removeEventListener("pointermove",U),t.removeEventListener("pointerleave",q),t.removeEventListener("pointercancel",q),document.removeEventListener("visibilitychange",j),o.removeEventListener("change",j),a.signal?.removeEventListener("abort",Y),r.destroy();for(const t of n)t.destroy();l.clear()}};a.signal?.addEventListener("abort",Y,{once:!0});const B=()=>{if(y)throw new Error("Project player has been destroyed.")},W=t=>{B();const e=Ie(t);Ue(e,i),E===s.width&&F===s.height&&(E=e.width,F=e.height),s=e,r.configure(s);for(const t of l.keys())s.layers.some(e=>e.id===t)||l.delete(t);j()};return j(),{canvas:t,get project(){return Ie(s)},get time(){return d},get motionTimes(){return{...m}},get paused(){return x||o.matches},get maxCells(){return r.maxCells},get pixelRatio(){return r.pixelRatio},get quality(){return r.quality},update:W,updateLayer:(t,e)=>W(Re(s,t,e)),resize(t,e,i){if(B(),!Number.isFinite(t)||!Number.isFinite(e)||t<2||e<2)throw new Error("Project dimensions must be positive finite numbers.");E=t,F=e,void 0!==i&&r.setPixelRatio(i),j()},pause(t=!0){B(),x=t,j()},async seek(t){if(B(),!Number.isFinite(t)||t<0)throw new Error("Project time must be finite and non-negative.");const e=++P;c?.abort(),c=new AbortController;const i=c.signal;C=!0,D();try{if(await Promise.all(n.map(e=>e.seek(t,i))),y||e!==P)return;d=t,l.clear(),r.invalidate()}finally{y||e!==P||(C=!1,j())}},redraw(){B(),r.invalidate(),g=!0,L()},setBudget(t){B(),r.setBudget(t),T=r.maxCells,b=A=S=k=0,a.onQualityChange?.(r.maxCells),g=!0,L()},setAdaptive(t){w=t,b=A=S=k=0},destroy:Y}}async function Be(t,e,i){const a=Ie(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 o,n;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 xe(async(t,e,h,l,m)=>{n??(n=await qe(a,r,m)),o??(o=Xe(t,a,{maxDimension:4096,maxCells:i.maxCells??24e3,maxRasterPixels:i.maxRasterPixels,pixelRatio:h/(i.referenceWidth??Math.min(h,960))}));const d=new Set(De({...a,width:h,height:l}).map(t=>t.source)),u=new Map;await Promise.all([...d].map(async t=>{const i=n.get(t);await i.seek(e,m),u.set(t,i.frame(e)),i.animated&&o.invalidate(t)})),o.render(u,e,h,l,c?s:{})},{...i,signal:h.signal})}finally{if(h.abort(),i.signal?.removeEventListener("abort",l),o?.destroy(),n)for(const t of new Set(n.values()))t.destroy()}}var We=[{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}}];export{B as BLEND_MODES,Se as CHARACTER_SETS,a as DEFAULT_HOVER,U as DEFAULT_STUDIO_PRINT,G as DEFAULT_STUDIO_SETTINGS,e as DEPRECATED_STUDIO_HOVERS,m as DEPRECATED_STUDIO_MOTIONS,Y as DITHER_ALGORITHMS,i as HOVER_CONTROLS,r as HOVER_SCOPES,Fe as MAX_STUDIO_LAYERS,T as MAX_STUDIO_WARPS,We as STUDIO_ANIMATION_PRESETS,Ee as STUDIO_CHARACTER_SETS,b as STUDIO_CURVE_CHANNELS,t as STUDIO_HOVERS,at as STUDIO_LOOKS,d as STUDIO_MOTIONS,W as STUDIO_PALETTES,j as STUDIO_PRINT_STYLES,D as STUDIO_PRINT_STYLE_IDS,z as STUDIO_STYLES,ke as STUDIO_TEXT_FONTS,C as STUDIO_WARPS,E as createStudioCurveLookup,Xe as createStudioProjectRenderer,fe as createStudioRenderer,Ae as createStudioText,ve as exportStudio,Be as exportStudioProject,de as inkIndexLookup,X as isStudioPrintStyle,ge as loadStudioMedia,ye as mountStudio,we as mountStudioMedia,ze as mountStudioProject,Ye as mountStudioProjectMedia,A as normalizeStudioCurve,S as normalizeStudioCurves,q as normalizeStudioPrint,Ie as normalizeStudioProject,K as normalizeStudioSettings,R as normalizeStudioWarps,Le as parseStudioProject,$ as parseStudioSettings,s as resolveHover,rt as restyleStudio,Ne as serializeStudioProject,Z as serializeStudioSettings,_ as studioCrop,tt as studioDimensions,it as studioGrid,Oe as studioLayerPoint,ce as studioLevels,st as studioLook,je as studioProjectBudget,se as studioSourceSize,me as studioToneGamma,Re as updateStudioProjectLayer,et as updateStudioSettings,De as visibleStudioLayers};//# sourceMappingURL=studio.js.map
1
+ var t=[{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."}],e={rake:"silk"},i={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}},a={effect:"trail",strength:.55,radius:.2,decay:.5,scope:"all",edgeSafe:!1};function s(i){if("string"==typeof i)return i in e?e[i]:t.some(t=>t.value===i)?i:void 0}var r=[{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."}],o=t=>"subject"===t||"outside"===t?t:"all";function n(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 o=r*i;for(let e=-s;e<=s;e++)a+=t[o+Math.max(0,Math.min(i-1,e))];for(let r=0;r<i;r++)e[o+r]=a/(2*s+1),a+=t[o+Math.min(i-1,r+s+1)]-t[o+Math.max(0,r-s)]}for(let r=0;r<i;r++){let o=0;for(let t=-s;t<=s;t++)o+=e[Math.max(0,Math.min(a-1,t))*i+r];for(let n=0;n<a;n++)t[n*i+r]=o/(2*s+1),o+=e[Math.min(a-1,n+s+1)*i+r]-e[Math.max(0,n-s)*i+r]}}}var h=new Float32Array(0);function l(t,e,i,a,s){const r=e*i,o=s&&s.width===e&&s.height===i?s:{width:e,height:i,subject:new Float32Array(r),depth:new Float32Array(r),key:"none"},{subject:l,depth:c}=o;let m=0;for(let e=0;e<r;e++)t[4*e+3]<250&&m++;const d=e=>(.2126*t[4*e]+.7152*t[4*e+1]+.0722*t[4*e+2])/255;let f="none",u=0;if(m>.01*r)f="alpha";else if(a)f="mask";else{let t=0,a=0,s=0;const r=Math.max(1,Math.round(.03*Math.min(e,i)));for(let o=0;o<i;o++)for(let n=0;n<e;n++){if(n>=r&&o>=r&&n<e-r&&o<i-r)continue;const h=d(o*e+n);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&&(f="ground")}for(let e=0;e<r;e++){const i=t[4*e+3]/255,s=d(e);let r=1;if("alpha"===f)r=i;else if("ground"===f){const t=Math.max(0,Math.min(1,(Math.abs(s-u)-.035)/.12));r=t*t*(3-2*t)}l[e]=r*(a?Math.max(0,Math.min(1,a[e])):1),c[e]=s*i}o.key=f,h.length<r&&(h=new Float32Array(r));const p=h;return n(l,p,e,i,Math.max(1,Math.round(.02*Math.min(e,i)))),n(c,p,e,i,Math.max(1,Math.round(.035*Math.min(e,i)))),o}function c(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"},d=[{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 f(t){const e=t&&Object.prototype.hasOwnProperty.call(m,t)?m[t]:t;return d.find(t=>t.value===e||t.mode===e)?.mode??"none"}var u=t=>Math.max(0,Math.min(1,t)),p=(t,e,i)=>{const a=u((i-t)/(e-t));return a*a*(3-2*a)},g=(t,e)=>{const i=(.06711056*t+.00583715*e)%1*52.9829189;return i-Math.floor(i)},M=class{constructor(){this.last=null,this.mode="none",this.phase=0}update(t,e,i=1){const a=f(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 x(t,e,i,a,s,r=.5,o,n=0){if(s[0]=s[1]=s[2]=0,s[3]=1,"none"===t)return s;r=u(r);const h=o?o[n]:r,l=o?o[n+1]:.5+.5*u(1-2*Math.hypot(e-.5,i-.55)),c=o?o[n+2]:p(.55,1,r)**2,m=o?o[n+3]:.5,d=o?o[n+4]:0,f=o?o[n+5]:0,M=a*Math.PI/6,x=(a%12+12)%12,v=p(0,.12,Math.min(e,1-e,i,1-i));if("relight"===t){const t=M+.6,a=Math.cos(t),o=Math.sin(t),n=Math.max(-1,Math.min(1,d*a+f*o))+.35*(a*(e-.5)+o*(i-.5));s[2]=.2*n*(.3+.7*p(.04,.3,h)*(1-.6*p(.82,1,r)))}else if("sheen"===t){const t=1.9*p(0,8,x)-.35,a=(.75*e+.45*i)/1.2+.05*(.75*d+.45*f),o=Math.exp(-(((a-t)/.12)**2));s[2]=o*p(.3,.8,h)*(1-.5*p(.9,1,r))*.45}else if("glow"===t){const t=.5-.5*Math.cos(M),e=1-.8*t;s[2]=.2*p(e-.3,e+.02,c)*Math.sqrt(c)*(1-.65*r)+.05*t*p(.6,.95,r)}else if("shimmer"===t){const t=g(Math.floor(160*e),Math.floor(100*i))*Math.PI*2,a=Math.pow(.5+.5*Math.cos(2*M+t),28);s[2]=a*p(.5,.88,r)*(.35+.65*p(.1,.55,m))*.42}else if("parallax"===t){const t=l-.45;s[0]=16*t*Math.sin(M)*v,s[1]=7*t*Math.sin(2*M)*v}else if("push"===t){const t=.045*(.5-.5*Math.cos(M))*(.7+.6*l)*960,a=o?o[n+6]:.5,r=o?o[n+7]:.5;s[0]=(e-a)*t,s[1]=(i-r)*t}else if("focus"===t){const t=Math.sin(M),e=t*t*p(.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-M+.9*Math.sin(3.3*i+M))+.3*Math.sin(7.3*e+2.1*i-2*M+1.1*Math.sin(2.7*e-5.1*i+M))+.2*Math.sin(5.7*i-1.9*e+M);s[2]=p(-.3,.9,a)*t*.16*(1-.55*r)}else if("current"===t){const t=o?.[n+8]??0,a=o?.[n+9]??0,h=o?.[n+10]??0,c=p(0,.06,Math.min(e,1-e,i,1-i)),d=o?0:(1-.4*m)*(1-.8*l)*v,f=t=>14*i-t+1.5*Math.sin(3*e+t),u=t=>16*i+2*e-t,x=t=>29*i-3*e-2*t,y=t=>1.7*e+2.3*i-t,w=t=>26*i+1.5*Math.sin(40*e)-2*t;s[0]=7*(Math.sin(f(M))-Math.sin(f(0))+.43*(Math.sin(5*e-3*i+M)-Math.sin(5*e-3*i)))*d+(3.5*(Math.sin(u(M))-Math.sin(u(0)))+1.5*(Math.sin(x(M))-Math.sin(x(0))))*t*c+5*(Math.sin(y(M))-Math.sin(y(0)))*a*c,s[1]=2*(Math.sin(11*e+M)-Math.sin(11*e))*d+.8*(Math.cos(u(M))-Math.cos(u(0)))*t*c+12*(Math.sin(w(M))-Math.sin(w(0)))*h*c;const b=Math.pow(.5+.5*Math.cos(2*M+9*e-4*i+6.2831853*g(Math.floor(160*e),Math.floor(100*i))),24)-Math.pow(.5+.5*Math.cos(9*e-4*i+6.2831853*g(Math.floor(160*e),Math.floor(100*i))),24);s[2]=.03*(Math.cos(f(M))-Math.cos(f(0)))*d+(b*p(.5,.85,r)*.3+.025*(Math.cos(u(M))-Math.cos(u(0))))*t*c+.08*(Math.cos(w(M))-Math.cos(w(0)))*h*c}else if("develop"===t){const t=p(7,8.5,x),a=u((x-8.5)/3.5),o=x<8.5?1-t:p(0,1,(1.45*a-(1-r)+.06*(g(Math.floor(160*e),Math.floor(100*i))-.5))/.3);s[2]=.3*-(1-o),s[3]=1-.9*(1-o)}return s}function v(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 y(t,e,i,a,s,r){return r[0]=v(Math.max(0,Math.min(a-1,e-t[0]/960*a))),r[1]=v(Math.max(0,Math.min(s-1,i-t[1]/960*s))),r}function w(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]=u(1+(t[3]-1)*i),t}var b=["rgb","red","green","blue"],k=t=>Math.max(0,Math.min(1,t));function A(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*k(i[0]))/255;!e.has(t)&&e.size>=16||e.set(t,k(i[1]))}return[...e].sort((t,e)=>t[0]-e[0])}function S(t){const e=t&&"object"==typeof t?t:{};return Object.fromEntries(b.map(t=>[t,A(e[t])]))}function E(t){const e=A(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 o=2*a[t]+a[t-1],n=a[t]+2*a[t-1];r[t]=(o+n)/(o/e+n/i)}const o=new Uint8Array(256);let n=0;for(let t=0;t<256;t++){const s=t/255;for(;n<i-2&&s>e[n+1][0];)n++;const h=a[n],l=(s-e[n][0])/h,c=l*l,m=c*l,d=(2*m-3*c+1)*e[n][1]+(m-2*c+l)*h*r[n]+(-2*m+3*c)*e[n+1][1]+(m-c)*h*r[n+1];o[t]=Math.round(255*k(d))}return o}function F(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 o=Math.floor(a),n=Math.floor(s),h=a-o,l=s-n,c=4*(n*e+o);if(0===h&&0===l){for(let e=0;e<4;e++)r[e]=t[c+e];return}const m=4*(n*e+Math.min(e-1,o+1)),d=4*(Math.min(i-1,n+1)*e+o),f=4*(Math.min(i-1,n+1)*e+Math.min(e-1,o+1)),u=(1-h)*(1-l)*t[c+3],p=h*(1-l)*t[m+3],g=(1-h)*l*t[d+3],M=h*l*t[f+3],x=u+p+g+M;for(let e=0;e<3;e++)r[e]=x?(t[c+e]*u+t[m+e]*p+t[d+e]*g+t[f+e]*M)/x:0;r[3]=x}function C(t,e,i,a,s,r){if(a>=0&&a<=e-1&&s>=0&&s<=i-1)return F(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 o=Math.floor(a),n=Math.floor(s),h=a-o,l=s-n;for(let a=0;a<=1;a++)for(let s=0;s<=1;s++){const c=o+s,m=n+a;if(c<0||c>=e||m<0||m>=i)continue;const d=4*(m*e+c),f=(s?h:1-h)*(a?l:1-l)*t[d+3];r[0]+=t[d]*f,r[1]+=t[d+1]*f,r[2]+=t[d+2]*f,r[3]+=f}r[3]&&(r[0]/=r[3],r[1]/=r[3],r[2]/=r[3])}var P=[{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}],T=8,I=(t,e,i,a)=>"number"==typeof t&&Number.isFinite(t)?Math.max(i,Math.min(a,t)):e;function R(t){if(!Array.isArray(t))return[];const e=[];for(const i of t.slice(0,64))if(i&&"object"==typeof i&&P.some(t=>t.value===i.type)&&(e.push({type:i.type,enabled:!1!==i.enabled,amount:I(i.amount,.35,-1,1),x:I(i.x,.5,0,1),y:I(i.y,.5,0,1),radius:I(i.radius,.55,.05,2),angle:I(i.angle,0,-180,180),frequency:I(i.frequency,5,1,24)}),8===e.length))break;return e}var N=2*Math.PI,O=(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},L=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=R(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 o=(s+.5)/e,n=(a+.5)/i;for(let e=this.warps.length-1;e>=0;e--){const i=this.warps[e],a=(o-i.x)*t/i.radius,s=(n-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 d=a,f=s;if("twirl"===i.type||"zigzag"===i.type){const t="twirl"===i.type?-m*N*c:.65*m*(2/Math.PI*Math.asin(Math.sin(l*N*i.frequency)))*c,e=Math.cos(t),r=Math.sin(t);d=a*e-s*r,f=a*r+s*e}else if("pinch"===i.type){const t=Math.exp(2*m*c);d=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);d=a*t,f=s*t}else if("ripple"===i.type&&l>0){const t=1+.12*m*Math.sin(l*N*i.frequency)*c/l;d=a*t,f=s*t}else if("shear"===i.type){const t=-a*i.sin+s*i.cos;d-=m*t*.9*c*i.cos,f-=m*t*.9*c*i.sin}else if("smudge"===i.type)d-=.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),o=m>0?r/Math.PI:Math.cos(t*Math.PI)*(e+1)/2,n=m>0?2*l-1:Math.sin(t*Math.PI)*(e+1)/2,h=o*i.cos-n*i.sin,u=o*i.sin+n*i.cos;d+=(h-a)*Math.abs(m)*c,f+=(u-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=(O(t,e)-.5)*m*.5*c,o=(O(e+71,t-31)-.5)*m*.5*c;d+=r*i.cos-o*i.sin,f+=r*i.sin+o*i.cos}o=i.x+d*i.radius/t,n=i.y+f*i.radius/r}const h=2*(a*e+s);this.coordinates[h]=o*e-.5,this.coordinates[h+1]=n*i-.5}this.geometry=s}this.output.length!==t.length&&(this.output=new Uint8ClampedArray(t.length));const r=t===this.output?t.slice():t,o="transparent"===this.edge?C:F;for(let a=0,s=0;a<t.length;a+=4,s+=2){o(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=""}},D=["stipple","engraving","crosshatch","woodblock","risograph","pointillism"],j=[{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."}];function q(t){return D.includes(t)}var U={density:1,weight:1,angle:-35,roughness:.35,invert:!1,secondaryInk:"#ec6752",registration:.2,seed:7};function X(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)):U[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:U.secondaryInk,registration:i("registration",0,1),seed:Math.round(i("seed",0,65535))}}var z=["ascii","blocks","braille","dots","lines","cross","diagonal","diamond","mixed","pixel","mosaic","lego","voxel","disco","dither","hex","led","cmyk",...D],B=["none","bayer2","bayer4","bayer8","bayer16","floyd-steinberg","atkinson","stucki","sierra","sierra-lite","burkes","jarvis","halftone","lines","noise","vertical-lines","diagonal-lines","radial","blue-noise"],Y=["source-over","multiply","screen","overlay","soft-light","hard-light","color-dodge","color-burn","hue","saturation","color","luminosity"],W={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"]},G={version:1,aspectRatio:"original",style:"ascii",cellSize:6,charset:" .:-=+*#%@",colorMode:"accent",ink:"#e6e3da",print:{...U},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}},H=t=>t&&"object"==typeof t&&!Array.isArray(t)?t:{},V=(t,e,i,a)=>"number"==typeof t&&Number.isFinite(t)?Math.min(a,Math.max(i,t)):e,Q=(t,e)=>"string"==typeof t&&/^#[\da-f]{6}$/i.test(t)?t:e,J=(t,e,i)=>e.includes(t)?t:i;function K(t={}){const e=H(t),r=G;if(void 0!==e.version&&1!==e.version)throw new Error("Unsupported studio settings version. Update asciify-engine.");const n=H(e.crop),h=H(e.backdrop),l=H(e.color),c=H(e.dither),m=H(e.mask),u=H(e.effects),p=H(e.motion),g=H(e.hover),M={...r.effects};for(const t of["bloom","characterBloom","grain","dust","scanlines","crt","prism","rgbSplit","sharpen","vignette","glitch","pixelate","halftone"])M[t]=V(u[t],0,0,1);M.blur=V(u.blur,0,0,24),M.blurType=J(u.blurType,["gaussian","directional","radial","progressive"],r.effects.blurType),M.angle=V(u.angle,0,-180,180),M.focus=V(u.focus,.5,0,1);let x=2048;return{version:1,aspectRatio:J(e.aspectRatio,["original","16:9","9:16","1:1","4:3","3:4","21:9"],"original"),style:J(e.style,z,r.style),cellSize:V(e.cellSize,r.cellSize,q(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(""):r.charset,colorMode:J(e.colorMode,["accent","source","gray"],r.colorMode),ink:Q(e.ink,r.ink),print:X(e.print),warps:R(e.warps),warpEdge:J(e.warpEdge,["clamp","transparent"],"clamp"),crop:{x:V(n.x,.5,0,1),y:V(n.y,.5,0,1),zoom:V(n.zoom,1,1,5),rotation:90*Math.round(V(n.rotation,0,-360,360)/90)},backdrop:{mode:J(h.mode,["solid","transparent","source","blurred","gradient"],r.backdrop.mode),color:Q(h.color,r.backdrop.color),color2:Q(h.color2,r.backdrop.color2),blur:V(h.blur,12,0,32),opacity:V(h.opacity,1,0,1)},color:{brightness:V(l.brightness,0,-1,1),contrast:V(l.contrast,1,0,3),saturation:V(l.saturation,1,0,3),grayscale:V(l.grayscale,0,0,1),tint:Q(l.tint,r.color.tint),amount:V(l.amount,0,0,1),blend:J(l.blend,Y,r.color.blend),blackPoint:V(l.blackPoint,0,0,.99),whitePoint:Math.max(V(l.blackPoint,0,0,.99)+1/255,V(l.whitePoint,1,1/255,1)),gamma:V(l.gamma,1,.25,4),shadows:V(l.shadows,0,-1,1),highlights:V(l.highlights,0,-1,1),curves:S(l.curves),denoise:V(l.denoise,0,0,1),levels:"none"===l.levels?"none":"auto"},dither:{algorithm:J(c.algorithm,B,"none"),palette:"string"==typeof c.palette&&Object.prototype.hasOwnProperty.call(W,c.palette)?c.palette:"mono",colors:Array.isArray(c.colors)&&c.colors.length>=2?c.colors.slice(0,32).map(t=>Q(t,"#000000")):[...r.dither.colors],amount:V(c.amount,1,0,2),scale:Math.round(V(c.scale,2,1,12)),threshold:V(c.threshold,.5,0,1),motion:J(c.motion,["none","drift","shimmer"],"none"),speed:V(c.speed,1,.1,3),direction:V(c.direction,45,-180,180),colorSpace:J(c.colorSpace,["rgb","luminance"],"rgb")},mask:{enabled:!0===m.enabled,invert:!0===m.invert,shapes:Array.isArray(m.shapes)?m.shapes.slice(0,64).map(t=>{const e=H(t),i=J(e.kind,["rectangle","ellipse","brush"],"rectangle"),a="brush"===i&&Array.isArray(e.points)?e.points.slice(0,x).map(t=>Array.isArray(t)?[Math.round(1e4*V(t[0],0,0,1))/1e4,Math.round(1e4*V(t[1],0,0,1))/1e4]:[0,0]):[];return x-=a.length,{kind:i,x:V(e.x,0,0,1),y:V(e.y,0,0,1),width:V(e.width,.5,0,1),height:V(e.height,.5,0,1),size:V(e.size,.05,.005,.5),points:a}}):[]},lights:Array.isArray(e.lights)?e.lights.slice(0,4).map(t=>{const e=H(t);return{x:V(e.x,.5,0,1),y:V(e.y,.5,0,1),radius:V(e.radius,.3,.02,1),intensity:V(e.intensity,.5,0,1),color:Q(e.color,"#ffffff")}}):[],effects:M,motion:{type:J("string"==typeof p.type?f(p.type):p.type,d.map(t=>t.mode),"none"),speed:V(p.speed,1,.1,3),amount:V(p.amount,1,0,2)},hover:{effect:s(g.effect)??a.effect,strength:V(g.strength,i.strength.default,i.strength.min,i.strength.max),radius:V(g.radius,i.radius.default,i.radius.min,i.radius.max),edgeSafe:!0===g.edgeSafe,..."all"!==o(g.scope)&&{scope:o(g.scope)},....5!==V(g.decay,.5,0,1)&&{decay:V(g.decay,.5,0,1)}}}}function Z(t){return JSON.stringify(K(t))}function $(t){if(t.length>1e5)throw new Error("Settings exceed 100 KB.");return K(JSON.parse(t))}function _(t,e,i,a,s){const r=Math.abs(s.rotation/90)%2==1,o=r?e:t,n=r?t:e,h=Math.max(i/o,a/n)*s.zoom;return{width:o*h,height:n*h,x:(i-o*h)*s.x,y:(a-n*h)*s.y,scale:h,rotated:r}}function tt(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 et(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}),K(i)}function it(t,e,i,a=12e3,s=1){const r=Math.max(2,Number.isFinite(t)?t:960),o=Math.max(2,Number.isFinite(e)?e:540),n=Math.max(1,Math.floor(Number.isFinite(a)?a:12e3)),h=Math.max(.01,Number.isFinite(s)?s:1),l=q(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*o/(n*l))/h));for(;Math.ceil(r/(c*h))*Math.ceil(o/(c*h*l))>n;)c++;const m="dither"===i.style?i.dither.scale:i.cellSize,d=Math.max(c,m)*h;return{cell:d,rowHeight:d*l,columns:Math.ceil(r/d),rows:Math.ceil(o/(d*l)),minimum:c,limited:m<c}}var at=[["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:K(a)}));function st(t){const e=at.find(e=>e.id===t);if(!e)throw new Error("Unknown studio look.");return K(e.settings)}function rt(t,e=Math.random){const i=at.filter(e=>e.settings.style!==t.style||e.settings.ink!==t.ink),a=st(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=K(t).mask,a}function ot(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 o=[0,.25+.2*s,.5,.75+.2*r,1],n=o.slice(1).map((t,e)=>4*(t-o[e])),h=[n[0],...n.slice(1).map((t,e)=>2*t*n[e]/(t+n[e])),n[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)),n=4*s-r,c=n*n,m=c*n,d=(2*m-3*c+1)*o[r]+(m-2*c+n)*h[r]/4+(-2*m+3*c)*o[r+1]+(m-c)*h[r+1]/4;l[t]=Math.round(255*Math.max(0,Math.min(1,d)))}return l}(t),i=t.curves;if(!e&&(!i||Object.values(i).every(t=>t.every(([t,e])=>t===e))))return null;const a=E(i?.rgb),s=[i?.red,i?.green,i?.blue].map(E),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 nt=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 o=4*(s*e+r);if(!a[o+3])continue;const n=a[o],h=a[o+1],l=a[o+2];let c=0,m=0,d=0,f=0;for(let t=-1;t<=1;t++){const o=s+t;if(!(o<0||o>=i))for(let i=-1;i<=1;i++){const s=r+i;if(s<0||s>=e)continue;const u=4*(o*e+s);if(!a[u+3])continue;const p=Math.max(Math.abs(a[u]-n),Math.abs(a[u+1]-h),Math.abs(a[u+2]-l)),g=this.weights[p]*(0===i?1:.6)*(0===t?1:.6)*a[u+3];c+=a[u]*g,m+=a[u+1]*g,d+=a[u+2]*g,f+=g}}t[o]=n+(c/f-n)*this.amount,t[o+1]=h+(m/f-h)*this.amount,t[o+2]=l+(d/f-l)*this.amount}}},ht=2*Math.PI,lt=t=>Math.max(0,Math.min(1,t)),ct=.1,mt=t=>Math.max(-.1,Math.min(1.1,t)),dt=Float32Array.from({length:2048},(t,e)=>Math.sin(e/2048*ht)),ft=t=>dt[2047&Math.floor(t*(2048/ht))];function ut(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 pt(t){const e=X(t),{density:i,weight:a,angle:s,roughness:r,invert:o,secondaryInk:n,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)]),d=new Float32Array(6);function f(t,e,i,s,o,n,h,c,f=!1){if(h<=0)return;const[u,p]=m[c],g=-p,M=u,x=g*(e+.5)+M*(i+.5),v=.5*(Math.abs(g)+Math.abs(M)),y=f?1:.5,w=Math.ceil((x-v)/y),b=Math.floor((x+v)/y),k=Math.min(.94*y,.72*y*h*a);t.lineWidth=n*k,t.beginPath();for(let a=w;a<=b;a++){const h=a*y-x,c=.5+g*h,m=.5+M*h;let v=-2,w=2;if(Math.abs(u)>1e-8){const t=-c/u,e=(1-c)/u;v=Math.max(v,Math.min(t,e)),w=Math.min(w,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)),w=Math.min(w,Math.max(t,e))}else if(m<0||m>1)continue;if(!(w<=v))if(f&&(v-=ct,w+=ct),f){for(let t=0;t<6;t++){const s=v+(w-v)*t/5,r=u*(e+c+u*s)+p*(i+m+p*s);d[t]=.5*ft(5.3*r+1.9*a+l)+.25*ft(13.1*r+a)}for(let e=0;e<2;e++)for(let i=0;i<6;i++){const a=v+(w-v)*(e?5-i:i)/5,h=d[e?5-i:i],l=.5*k*(1+r*h*.5)*(e?-1:1),f=s+mt(c+u*a+g*l)*n,x=o+mt(m+p*a+M*l)*n;e||i?t.lineTo(f,x):t.moveTo(f,x)}t.closePath()}else t.moveTo(s+(c+u*v)*n,o+(m+p*v)*n),t.lineTo(s+(c+u*w)*n,o+(m+p*w)*n)}f?t.fill():t.stroke()}return{settings:e,paint(t,e,s,c,d,u,p,g,M,x,v,y,w){const b=lt((o?1-g:g)*i);if(b<=0||t.globalAlpha<=0)return;t.fillStyle=M,t.strokeStyle=M;const k=ut(s,c,l);if("engraving"===e||"crosshatch"===e||"woodblock"===e){const i=b*(1-r*k*.3);"woodblock"===e?f(t,s,c,d,u,p,Math.ceil(5*i)/5,0,!0):(f(t,s,c,d,u,p,i,0),"crosshatch"===e&&(f(t,s,c,d,u,p,Math.max(0,1.5*i-.3),1),f(t,s,c,d,u,p,Math.max(0,2*i-1.2),2)))}else if("risograph"===e){const e="source"===w?lt(.5+(x-y)/510):.5,i=.38*h*p,o=p*Math.min(.48,.44*Math.sqrt(b)*a);t.beginPath(),t.arc(d+.5*p,u+.5*p,o*Math.sqrt(.35+.65*(1-e)),0,ht),t.fill(),t.globalCompositeOperation="multiply",t.fillStyle=n;const f=1-r*ut(s,c,l+13)*.3;t.beginPath(),t.arc(d+.5*p+i*m[0][0],u+.5*p+i*m[0][1],o*Math.sqrt(.3+.7*e)*f,0,ht),t.fill(),t.globalCompositeOperation="source-over"}else{const i=t.fillEllipse;"stipple"===e&&t.beginPath();for(let o=0;o<4;o++){const n=ut(2*s+o%2,2*c+(o>>1),l),h=ut(s,c,l+11*o+1),m=d+((o%2+.5)/2+(n-.5)*r*.28)*p,f=u+((.5+(o>>1))/2+(h-.5)*r*.28)*p,g=Math.min(m-d,d+p-m,f-u,u+p-f,p*Math.min(.245,.21*a*Math.sqrt(b)*(1-r*n*.35)));if("stipple"===e)t.moveTo(m+g,f),t.arc(m,f,g,0,ht);else{const e=(n-.5)*r*64;if(i&&"accent"!==w){const t=Math.round(x+e);i(m,f,g,.64*g,n*Math.PI,t,"source"===w?Math.round(v-.4*e):t,"source"===w?Math.round(y-e):t);continue}t.fillStyle="source"===w?`rgb(${Math.round(x+e)},${Math.round(v-.4*e)},${Math.round(y-e)})`:"gray"===w?`rgb(${Math.round(x+e)},${Math.round(x+e)},${Math.round(x+e)})`:M,t.beginPath(),t.ellipse(m,f,g,.64*g,n*Math.PI,0,ht),t.fill()}}"stipple"===e&&t.fill()}}}}var gt=new Set(["none","floyd-steinberg","atkinson","stucki","sierra","sierra-lite","burkes","jarvis"]);function Mt(t){return"dither"===t.style&&("shimmer"===t.dither.motion||"drift"===t.dither.motion&&t.dither.amount>0&&!gt.has(t.dither.algorithm))}function xt(t){return"none"!==t.motion.type&&(t.motion.amount??1)>0}function vt(t){return xt(t)||Mt(t)||t.effects.grain>0||t.effects.dust>0||t.effects.glitch>0}var yt=11,wt=t=>Math.max(0,Math.min(1,t)),bt=(t,e,i)=>{const a=wt((i-t)/(e-t));return a*a*(3-2*a)};function kt(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 o=t.length*e;for(let t=0;t<i;t++)if(r+=s[t],r>=o)return(t+1)/i*a;return a}var At=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}},St=null;function Et(t,e,i,a,s){const r=2*s+1;for(let o=0;o<a;o++){const a=o*i;let n=0;for(let e=-s;e<=s;e++)n+=t[a+Math.max(0,Math.min(i-1,e))];for(let o=0;o<i;o++)e[a+o]=n/r,n+=t[a+Math.min(i-1,o+s+1)]-t[a+Math.max(0,o-s)]}for(let o=0;o<i;o++){let n=0;for(let t=-s;t<=s;t++)n+=e[Math.max(0,Math.min(a-1,t))*i+o];for(let h=0;h<a;h++)t[h*i+o]=n/r,n+=e[Math.min(a-1,h+s+1)*i+o]-e[Math.max(0,h-s)*i+o]}}function Ft(t,e,i,a,s,r,o){const n=i*a,h=o.take(),l=o.take(e),c=o.take(t),m=o.take(),d=o.take();for(let i=0;i<n;i++)m[i]=e[i]*e[i],d[i]=e[i]*t[i];Et(l,h,i,a,s),Et(c,h,i,a,s),Et(m,h,i,a,s),Et(d,h,i,a,s);for(let t=0;t<n;t++){const e=(d[t]-l[t]*c[t])/(m[t]-l[t]*l[t]+r);m[t]=e,d[t]=c[t]-e*l[t]}Et(m,h,i,a,s),Et(d,h,i,a,s);for(let i=0;i<n;i++)t[i]=m[i]*e[i]+d[i]}function Ct(t,e,i,a,s,r=2){for(let o=0;o<r;o++){for(let r=0;r<a;r++)for(let a=0;a<i;a++){const o=r*i+a;let n=t[o];a>0&&(n=Math.max(n,Math.min(e[o],t[o-1]*s))),r>0&&(n=Math.max(n,Math.min(e[o],t[o-i]*s),a>0?Math.min(e[o],t[o-i-1]*s):0,a<i-1?Math.min(e[o],t[o-i+1]*s):0)),t[o]=n}for(let r=a-1;r>=0;r--)for(let o=i-1;o>=0;o--){const n=r*i+o;let h=t[n];o<i-1&&(h=Math.max(h,Math.min(e[n],t[n+1]*s))),r<a-1&&(h=Math.max(h,Math.min(e[n],t[n+i]*s),o>0?Math.min(e[n],t[n+i-1]*s):0,o<i-1?Math.min(e[n],t[n+i+1]*s):0)),t[n]=h}}}function Pt(t,e,i,a,s){for(let r=0;r<a;r++)for(let a=0;a<i;a++){let o=1;for(let e=Math.max(0,a-s);e<=Math.min(i-1,a+s);e++)o=Math.min(o,t[r*i+e]);e[r*i+a]=o}for(let r=0;r<a;r++)for(let o=0;o<i;o++){let n=1;for(let t=Math.max(0,r-s);t<=Math.min(a-1,r+s);t++)n=Math.min(n,e[t*i+o]);t[r*i+o]=n}}function Tt(t,e,i,a,s){const r=i*a,o=Math.min(i,a),h=s.take(),c=s.take(),m=s.take(),d=s.take(),f=s.take();for(let i=0;i<r;i++){const a=t[4*i+3]/255;f[i]=a,h[i]=e[4*i]/255*a,c[i]=e[4*i+1]/255*a,m[i]=e[4*i+2]/255*a,d[i]=(.299*t[4*i]+.587*t[4*i+1]+.114*t[4*i+2])/255*a}const u=s.take(),p=(t,e)=>{const r=s.take(t);return n(r,u,i,a,e),r},g=Math.max(2,Math.round(.04*o)),M=Math.max(g+2,Math.round(.12*o)),x=Math.max(2,Math.round(.05*o)),v=p(d,1),y=p(d,g),w=p(d,M),b=s.take(),k=s.take(),A=s.take(),S=s.take(),E=s.take();for(let t=0;t<a;t++)for(let e=0;e<i;e++){const s=t*i+e;b[s]=Math.abs(d[s]-v[s]),k[s]=Math.abs(v[s]-y[s]),A[s]=Math.abs(y[s]-w[s]),S[s]=Math.abs(d[t*i+Math.min(i-1,e+1)]-d[t*i+Math.max(0,e-1)]),E[s]=Math.abs(d[Math.min(a-1,t+1)*i+e]-d[Math.max(0,t-1)*i+e])}n(b,u,i,a,x),n(k,u,i,a,x),n(A,u,i,a,x),n(S,u,i,a,2),n(E,u,i,a,2);const F=Math.max(.01,kt(b,.9)+kt(k,.9)),C=p(h,1),P=p(c,1),T=p(m,1),I=s.take(),R=s.take(),N=s.take();let O=0;for(let t=0;t<r;t++){const e=C[t],i=P[t],a=T[t],s=Math.max(e,i,a),r=s-Math.min(e,i,a);N[t]=s,R[t]=s>.001?r/s:0,O+=r;let o=0;r>1e-4&&(o=s===e?((i-a)/r+6)%6:s===i?(a-e)/r+2:(e-i)/r+4),I[t]=60*o}const L=bt(.02,.07,O/r),D=Math.max(2,Math.round(.06*a)),j=new Float32Array(a);for(let t=0;t<a;t++){let e=0;for(let a=0;a<i;a++)e+=b[t*i+a]+k[t*i+a];j[t]=e/i}let q=.5,U=0;for(let t=Math.max(D,Math.round(.12*a));t<=Math.min(a-D,Math.round(.88*a));t++){let e=0,s=0,r=0,o=0;for(let a=0;a<i;a++){let r=0,o=0,n=0,h=0,l=0,c=0;for(let e=1;e<=D;e++){const s=(t-e)*i+a,m=(t+e-1)*i+a;r+=C[s],o+=P[s],n+=T[s],h+=C[m],l+=P[m],c+=T[m]}const m=(Math.abs(r-h)+Math.abs(o-l)+Math.abs(n-c))/D;e+=m,s+=m>.12?1:0}const n=Math.max(2,Math.round(.15*a)),h=Math.max(0,t-n),l=Math.min(a,t+n);for(let e=h;e<t;e++)r+=j[e];for(let e=t;e<l;e++)o+=j[e];r/=t-h,o/=l-t;const c=bt(-.05,.3,(o-r)/(o+r+1e-4)),m=bt(.08,.35,e/i)*(s/i)*c;m>U&&(U=m,q=t/a)}const X=bt(.15,.45,U),z=s.take(),B=s.take(),Y=s.take();for(let t=0;t<r;t++)z[t]=Math.min(h[t],c[t],m[t]);Pt(z,u,i,a,1),n(z,u,i,a,g);for(let t=0;t<r;t++)B[t]=k[t]+A[t];let W=0,G=0,H=0;for(let t=0;t<r;t++)W+=C[t],G+=P[t],H+=T[t];W/=r,G/=r,H/=r;const V=p(C,g),Q=p(P,g),J=p(T,g),K=p(C,M),Z=p(P,M),$=p(T,M);for(let t=0;t<r;t++){const e=Math.hypot(V[t]-W,Q[t]-G,J[t]-H),i=Math.hypot(V[t]-K[t],Q[t]-Z[t],J[t]-$[t]);Y[t]=(e+1.5*i)*(.4+.6*R[t]*L+.4*(1-L))}const _=s.take(),tt=s.take(),et=s.take(),it=s.take(),at=s.take(),st=s.take(),rt=s.take(),ot=s.take(),nt=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(d[Math.min(a-1,t+1)*i+e]-d[Math.max(0,t-1)*i+e]);n(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,o=I[s],n=R[s]*L,h=N[s],l=b[s]+k[s],c=bt(175,200,o)*(1-bt(250,275,o))*bt(.08,.25,n),m=(1-bt(45,65,o)+bt(290,330,o))*bt(.2,.45,n)*bt(.3,.55,h),d=(1-bt(.15,.35,n))*bt(.45,.7,h)*X,f=(1-bt(.08,.2,h))*X,u=X>.3?1-bt(q,q+.1,r):1-bt(.4,.8,r),p=1-bt(.02,.06,l),g=1-bt(.03,.09,l);tt[s]=Math.max(c*p,.7*f*(1-bt(.008,.025,l)),m*g*.9)*u,et[s]=Math.max(tt[s],d*p*u),_[s]=0===t?tt[s]:0,it[s]=bt(150,172,o)*(1-bt(232,250,o))*bt(.25,.45,n),rt[s]=bt(1.3,2.2,(S[s]+.004)/(E[s]+.004))*bt(.35,.55,v[s])*(1-bt(.1,.18,R[s]*L))*bt(.025,.07,l)*bt(.025,.045,ht[s]);const M=1-bt(.18,.4,n),x=bt(.55,.8,h)*bt(.05,.12,l);at[s]=Math.max(it[s],.85*M,.8*x)}Ct(_,tt,i,a,.995,1),Ct(_,et,i,a,.8,1);let lt=0;for(let t=0;t<r;t++)lt+=_[t];const ct=lt>.04*r&&X>.3;if(ct)for(let t=0;t<a;t++)for(let e=0;e<i;e++)it[t*i+e]*=bt(q,q+.05,(t+.5)/a);if(ct){const t=s.take(),e=s.take(),o=s.take();for(let e=0;e<r;e++)t[e]=.299*V[e]+.587*Q[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 h=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 o=r>.03;for(let n=-3;n<=3&&o;n++)n&&t+n>=0&&t+n<a&&Math.abs(e[(t+n)*i+s])>r&&(o=!1);h[t*i+s]=o?1:0}const l=(e,i,a,s=!0)=>{const r=V[i]+Q[i]+J[i]+.05,o=V[a]+Q[a]+J[a]+.05,n=Math.abs(V[i]/r-V[a]/o)+Math.abs(Q[i]/r-Q[a]/o)+Math.abs(J[i]/r-J[a]/o),h=Math.min(Math.abs(I[i]-I[a]),360-Math.abs(I[i]-I[a])),l=Math.max(1-bt(.1,.25,n),(1-bt(15,35,h))*bt(.15,.3,Math.min(R[i],R[a]))),c=Math.max(bt(2,3,(E[i]+.004)/(S[i]+.004))*bt(.015,.04,b[i]+k[i])*bt(.4,.55,b[i]/(b[i]+k[i]+1e-4)),1-bt(.12,.25,t[i]));return l*(s?c:1)*(1-bt(.82*t[a]+.02,1.02*t[a]+.05,t[i]))};let c=0,m=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++)(h[(t-1)*i+a]||h[t*i+a]||h[(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+=l(t,e*i+a,(2*t-e)*i+a);s>m&&(m=s,c=t)}const d=bt(.05,.1,m/r);if(d>0)for(let t=c+1;t<Math.min(a,2*c);t++)for(let e=0;e<i;e++){const a=t*i+e;ot[a]=l(c,a,(2*c-t)*i+e)*d,nt[a]=l(c,a,(2*c-t)*i+e,!1)*d,o[a]=ot[a]}n(o,u,i,a,1);for(let t=0;t<r;t++)ot[t]=Math.max(ot[t],o[t]),it[t]=Math.max(it[t],ot[t])}const mt=p(it,M);for(let t=0;t<r;t++)it[t]*=bt(.15,.35,mt[t]);const dt=p(it,g);for(let t=0;t<r;t++){it[t]*=1-.8*tt[t];const e=Math.min(Math.abs(I[t]-200),360-Math.abs(I[t]-200));st[t]=bt(.28,.45,R[t]*L)*bt(55,80,e)*(1-bt(.3,.6,nt[t]))}const ft=p(st,g);for(let t=0;t<r;t++)st[t]=Math.max(st[t]*(1-(1-bt(.15,.3,ft[t]))*bt(.55,.7,N[t])*bt(.5,.65,R[t])),1-f[t]),at[t]=Math.min(Math.max(at[t],.9*nt[t]),Math.max(it[t],bt(.25,.6,dt[t])))*(1-_[t])*(1-st[t]);Ct(it,at,i,a,.97);const ut=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++)ut[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]}n(ut,u,i,a,1);for(let t=0;t<r;t++)rt[t]=bt(.2,.45,ut[t])*bt(.2,.5,rt[t]+.5*ut[t])*(1-_[t]);Ft(_,d,i,a,Math.max(2,Math.round(.04*o)),.002,s),Ft(it,d,i,a,Math.max(2,Math.round(.04*o)),.002,s),Ft(rt,d,i,a,Math.max(2,Math.round(.03*o)),.002,s),n(st,u,i,a,1);for(let t=0;t<r;t++)_[t]=bt(.3,.7,_[t])*f[t],rt[t]=bt(.3,.7,rt[t])*f[t]*(1-_[t]),it[t]=bt(.3,.7,it[t])*(1-_[t])*(1-rt[t])*(1-bt(.15,.4,st[t]));Pt(_,u,i,a,2),Pt(it,u,i,a,2),Pt(rt,u,i,a,1),n(_,u,i,a,1),n(it,u,i,a,1),n(rt,u,i,a,1);const gt=1/Math.max(.02,kt(Y,.97)),Mt=1/Math.max(.01,kt(B,.9)),xt=kt(z,.97),vt=kt(z,.1),yt=bt(.06,.25,xt-vt),At=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,o=(t+.5)/a,n=Math.max(_[s],it[s]),h=b[s]+k[s]+A[s],l=.6*wt(((b[s]+.6*k[s])/(h+.004)-.25)/.55)+.4*wt((b[s]+k[s])/F),c=bt(.04,.35,h/F)*(1-n),m=.55*wt((z[s]-vt)/Math.max(.05,xt-vt))+.25*(1-wt(B[s]*Mt))+.2*wt(2*(T[s]-C[s])+.3)*L,d=yt*bt(.12,.35,y[s])*(.4+.6*X),f=X*(o<q?.45:.45+.55*bt(0,1,(o-q)/Math.max(.15,1-q)))+(1-X)*(.5+.4*(o-.5)),u=b[s]/(b[s]+k[s]+1e-4),p=bt(.2,.7,(b[s]+k[s])/F)*(.35+.65*X)*(1-n),g=1-wt(1.5*Math.hypot(1.2*(r-.5),o-.52)),M=wt(Y[s]*gt)*(.55+.45*g),x=.3*c,v=.25*d,w=.12+.45*X,S=.12*p,E=.35*(1-.4*X)*(1-n);At[s]=(x*l+v*(1-m)+w*f+S*wt(1.6-1.6*u)+E*M+.04)/(x+v+w+S+E+.08)*(1-.85*_[s])*(1-.45*it[s]*(1-X))}const St=l(t,i,a);if("none"!==St.key)for(let t=0;t<r;t++)At[t]=.7*St.subject[t]+.3*At[t];return n(At,u,i,a,Math.max(1,Math.round(.03*o))),function(t,e,i,a,s,r,o,n,h){const l=s*r,c=h.take(),m=t=>(Et(t,c,s,r,o),t),d=(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)),u=m(h.take(i)),p=m(h.take(a)),g=m(h.take(t)),M=d(e,e),x=d(e,i),v=d(e,a),y=d(i,i),w=d(i,a),b=d(a,a),k=d(e,t),A=d(i,t),S=d(a,t),E=h.take(),F=h.take(),C=h.take(),P=h.take();for(let t=0;t<l;t++){const e=k[t]-f[t]*g[t],i=A[t]-u[t]*g[t],a=S[t]-p[t]*g[t],s=M[t]-f[t]*f[t]+n,r=x[t]-f[t]*u[t],o=v[t]-f[t]*p[t],h=y[t]-u[t]*u[t]+n,l=w[t]-u[t]*p[t],c=b[t]-p[t]*p[t]+n,m=h*c-l*l,d=o*l-r*c,T=r*l-o*h,I=s*c-o*o,R=r*o-s*l,N=s*h-r*r,O=s*m+r*d+o*T,L=Math.abs(O)>1e-12?1/O:0;E[t]=(m*e+d*i+T*a)*L,F[t]=(d*e+I*i+R*a)*L,C[t]=(T*e+R*i+N*a)*L,P[t]=g[t]-E[t]*f[t]-F[t]*u[t]-C[t]*p[t]}m(E),m(F),m(C),m(P);for(let s=0;s<l;s++)t[s]=E[s]*e[s]+F[s]*i[s]+C[s]*a[s]+P[s]}(At,C,P,T,i,a,Math.max(2,Math.round(.07*o)),.004,s),{depth:At,water:it,sky:_,falls:rt}}function It(t,e,i,a,s,r,o){if(e===r&&i===o)return t[s*r+a];const n=Math.max(0,Math.min(e-1,(a+.5)*e/r-.5)),h=Math.max(0,Math.min(i-1,(s+.5)*i/o-.5)),l=Math.min(e-2,Math.floor(n)),c=Math.min(i-2,Math.floor(h)),m=n-l,d=h-c;if(l<0||c<0)return t[Math.round(h)*e+Math.round(n)];const f=c*e+l,u=f+e;return(t[f]*(1-m)+t[f+1]*m)*(1-d)+(t[u]*(1-m)+t[u+1]*m)*d}var Rt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Nt="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",Ot=new Uint16Array(4096);for(let t=0;t<Ot.length;t++)Ot[t]=Rt.indexOf(Nt[2*t])<<6|Rt.indexOf(Nt[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 Dt=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))])),jt={"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]]},qt=t=>[parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16)];function Ut(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 Xt=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 o=this.width/this.height,n=Math.hypot((t-r.x)*Math.max(1,o),(e-r.y)*Math.max(1,1/o));if(n<1e-4||this.clock-this.lastRing<1/24)return;const h=n/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],o=.17*i,n=this.rings[t+3]*(1-Math.exp(20*-i))*Math.exp(2.5*-i),h=o+1.8*r,l=this.rings[t],c=this.rings[t+1],m=Math.max(0,Math.floor((l-h/a)*(this.width-1))),d=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))),u=Math.min(this.height-1,Math.ceil((c+h/s)*(this.height-1)));for(let t=f;t<=u;t++)for(let e=m;e<=d;e++){const i=(Math.hypot((e/(this.width-1)-l)*a,(t/(this.height-1)-c)*s)-o)/r;Math.abs(i)>1.8||(this.values[t*this.width+e]+=n*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?Ut(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),o=Math.floor(s),n=a-r,h=s-o,l=o*this.width+r,c=l+this.width;i[0]=i[1]=0,i[2]=3*((this.values[l]*(1-n)+this.values[l+1]*n)*(1-h)+(this.values[c]*(1-n)+this.values[c+1]*n)*h)}},zt=t=>["dissolve","silk","vortex","magnetic","scatter","etch","elastic","lens","smudge"].includes(t),Bt=t=>"elastic"===t||"scatter"===t,Yt={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]=Ut(a/(t-1),i/(e-1),t/e);this.clear()}get active(){return this.peak>2e-4}setMode(t){if(Bt(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,o=Math.floor(s),n=Math.floor(r),h=s-o,l=r-n,c=h*h*(3-2*h),m=l*l*(3-2*l),d=((e(o,n)*(1-c)+e(o+1,n)*c)*(1-m)+(e(o,n+1)*(1-c)+e(o+1,n+1)*c)*m)*Math.PI*4,f=2*(i*this.width+a);t[f]=.7*Math.cos(d),t[f+1]=.7*Math.sin(d)}}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,o=Math.max(1,s/r),n=Math.max(1,r/s),h=a?(t-a.x)*o:0,l=a?(e-a.y)*n: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)),d=Math.min(128,Math.max(1,Math.ceil(c/(.45*m)))),f=c?h/c:1,u=c?l/c:0,p=a||"lens"!==this.mode?Math.min(1,c/(m*d)*2.2):.32;for(let i=0;i<d;i++){const h=(i+.5)/d,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/o)*(s-1))),M=Math.min(s-1,Math.ceil((l+2.5*m/o)*(s-1))),x=Math.max(0,Math.floor((c-2.5*m/n)*(r-1))),v=Math.min(r-1,Math.ceil((c+2.5*m/n)*(r-1)));for(let t=x;t<=v;t++)for(let e=g;e<=M;e++){const i=(e/(s-1)-l)*o/m,a=(t/(r-1)-c)*n/m,h=Math.exp(1.5*-(i*i+a*a)),d=t*s+e;if("dissolve"===this.mode||"etch"===this.mode)this.ink[d]=Math.max(this.ink[d],h);else if("elastic"===this.mode)this.springX[d]=Math.max(-24,Math.min(24,this.springX[d]+f*h*p*12)),this.springY[d]=Math.max(-24,Math.min(24,this.springY[d]+u*h*p*12));else if("scatter"===this.mode){const t=this.scatterDirections;this.springX[d]=Math.max(-24,Math.min(24,this.springX[d]+(.6*i+t[2*d])*h*p*7)),this.springY[d]=Math.max(-24,Math.min(24,this.springY[d]+(.6*a+t[2*d+1])*h*p*7))}else if("lens"===this.mode)this.targetX[d]=Math.max(-.65,Math.min(.65,this.targetX[d]+i*h*p*1.6)),this.targetY[d]=Math.max(-.65,Math.min(.65,this.targetY[d]+a*h*p*1.6));else if("smudge"===this.mode)this.targetX[d]=Math.max(-1,Math.min(1,this.targetX[d]+f*h*p*1.3)),this.targetY[d]=Math.max(-1,Math.min(1,this.targetY[d]+u*h*p*1.3));else{const t=(-i*u+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?u*t:i*h*2.5;this.targetX[d]=Math.max(-1,Math.min(1,this.targetX[d]+e*p)),this.targetY[d]=Math.max(-1,Math.min(1,this.targetY[d]+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 o=0;const[n,h]="scatter"===this.mode?Yt.scatter:Yt.elastic,l=Math.sqrt(n-h*h),c=Math.exp(-h*e),m=Math.cos(l*e),d=Math.sin(l*e)/l;for(let t=0;t<this.ink.length;t++)if("etch"===this.mode)this.ink[t]*=s,o=Math.max(o,this.ink[t]);else if("dissolve"===this.mode){this.ink[t]*=s,o=Math.max(o,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(Bt(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)*d))),this.offsetY[t]=Math.max(-1,Math.min(1,c*(i*m+(s+h*i)*d))),this.springX[t]=c*(a*m-(h*a+n*e)*d),this.springY[t]=c*(s*m-(h*s+n*i)*d),o=Math.max(o,.05*Math.abs(this.springX[t]),.05*Math.abs(this.springY[t]))}else if("lens"===this.mode||"smudge"===this.mode){const e=1-r,o=a/(a-i)*(s-e);this.offsetX[t]=this.offsetX[t]*e+this.targetX[t]*o,this.offsetY[t]=this.offsetY[t]*e+this.targetY[t]*o,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;o=Math.max(o,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=o,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),o=Math.floor(s),n=a-r,h=s-o,l=o*this.width+r,c=l+this.width,m=t=>(t[l]*(1-n)+t[l+1]*n)*(1-h)+(t[c]*(1-n)+t[c+1]*n)*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?Ut(t,e,this.width/this.height):1)*.08,i[1]=m(this.offsetY)*(this.edgeSafe?Ut(t,e,this.width/this.height):1)*.08,i[2]="dissolve"===this.mode?6*-m(this.ink):0}},Gt=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 o=.015+r.age*(.15+.22*r.radius),n=.009+.014*r.radius,h=(Math.hypot((t-r.x)*i,(e-r.y)*a)-o)/n,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]),o=4*s;this.pixels[o]=r>>>8,this.pixels[o+1]=255&r}this.echoPeak=a,this.active||(this.echo.fill(0),this.pixels.fill(0))}},Ht=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),o=(e-s.y)*(this.height-1),n=Math.hypot(r,o);if(n<.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,n/h/l),m=1-Math.exp(-c/2.2),d=h*(.022+.075*i)*(.65+.95*m),f=Math.min(128,Math.max(1,Math.ceil(n/(.4*d)))),u=n/d*(.32+.22*m)/f,p=r/n,g=o/n,M=-g,x=p,v=n*(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),o=(s.y+(e-s.y)*a)*(this.height-1),n=Math.max(1,Math.floor(r-3*d)),h=Math.min(this.width-2,Math.ceil(r+3*d)),l=Math.max(1,Math.floor(o-3*d)),c=Math.min(this.height-2,Math.ceil(o+3*d));for(let t=l;t<=c;t++)for(let e=n;e<=h;e++){const i=((e-r)*p+(t-o)*g)/d,a=((e-r)*M+(t-o)*x)/d,s=Math.exp(-i*i*.65-a*a*1.7),n=t*this.width+e;this.ink[n]=1-(1-this.ink[n])*Math.exp(-s*u);const h=1-a*a*.55,l=i*a*.7;this.u[n]=Math.max(-80,Math.min(80,this.u[n]+(p*h+M*l)*s*v)),this.v[n]=Math.max(-80,Math.min(80,this.v[n]+(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,o=i-s,n=s*this.width+a;return(t[n]*(1-r)+t[n+1]*r)*(1-o)+(t[n+this.width]*(1-r)+t[n+this.width+1]*r)*o}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 o=1;o<i-1;o++){const n=e*i+o,h=Math.max(.5,Math.min(i-1.5,o-this.u[n]*t)),l=Math.max(.5,Math.min(a-1.5,e-this.v[n]*t)),c=0|h,m=0|l,d=h-c,f=l-m,u=m*i+c,p=(1-d)*(1-f),g=d*(1-f),M=(1-d)*f,x=d*f;this.a[n]=(this.u[u]*p+this.u[u+1]*g+this.u[u+i]*M+this.u[u+i+1]*x)*s,this.b[n]=(this.v[u]*p+this.v[u+1]*g+this.v[u+i]*M+this.v[u+i+1]*x)*s,this.c[n]=(this.ink[u]*p+this.ink[u+1]*g+this.ink[u+i]*M+this.ink[u+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]),o=Math.abs(this.curl[s+i])-Math.abs(this.curl[s-i]),n=Math.hypot(r,o)+1e-4,h=this.curl[s]*t*10,l=Math.hypot(this.u[s],this.v[s]);this.u[s]+=o/n*h,this.v[s]-=r/n*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 o=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]),o=Math.max(o,this.signal[s])}this.peak=o}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 Vt=["loupe","repel","tilt","reveal","haze","bleed"],Qt=t=>Vt.includes(t),Jt=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}},Kt=t=>t*t*(3-2*t),Zt=(t,e)=>{const i=43758.5453*Math.sin(127.1*t+311.7*e);return i-Math.floor(i)};function $t(t,e){const i=Math.floor(t),a=Math.floor(e),s=Kt(t-i),r=Kt(e-a),o=Zt(i,a),n=Zt(i+1,a),h=Zt(i,a+1);return(o+(n-o)*s)*(1-r)+(h+(Zt(i+1,a+1)-h)*s)*r}var _t=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 Jt,this.y=new Jt,this.tx=new Jt,this.ty=new Jt,this.presence=new Jt,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*$t(.09*e,.045*t)+.15*Zt(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,o=this.width,n=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,d=t+(i-t)*m,f=e+(a-e)*m,u=Math.max(0,Math.floor((d-2*h/this.sx)*(o-1))),p=Math.min(o-1,Math.ceil((d+2*h/this.sx)*(o-1))),g=Math.max(0,Math.floor((f-2*h/this.sy)*(n-1))),M=Math.min(n-1,Math.ceil((f+2*h/this.sy)*(n-1)));for(let t=g;t<=M;t++)for(let e=u;e<=p;e++){const i=(e/(o-1)-d)*this.sx/h,a=(t/(n-1)-f)*this.sy/h,l=t*o+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,o=this.width,n=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,d=Math.exp(-(i?.15:.9)*e/h);let f=0;for(let t=0;t<h;t++){f=0;for(let t=1;t<n-1;t++)for(let e=1;e<o-1;e++){const i=t*o+e,n=a[i],h=r[i],u=Math.min(h,r[i-1])*(a[i-1]-n)+Math.min(h,r[i+1])*(a[i+1]-n)+Math.min(h,r[i-o])*(a[i-o]-n)+Math.min(h,r[i+o])*(a[i+o]-n),p=Math.max(0,(n+u*Math.min(.24,c*l))*d-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,o=Math.max(0,Math.min(a-1.001,t*(a-1))),n=Math.max(0,Math.min(s-1.001,e*(s-1))),h=Math.floor(o),l=Math.floor(n),c=o-h,m=n-l,d=l*a+h,f=d+a,u=(r[d]*(1-c)+r[d+1]*c)*(1-m)+(r[f]*(1-c)+r[f+1]*c)*m;return void(i[2]=1-Math.exp(2.4*-u))}if("tilt"===s){const a=this.guide?function(t,e,i,a){const s=t[e],r=t.width,o=t.height,n=Math.max(0,Math.min(r-1.001,i*(r-1))),h=Math.max(0,Math.min(o-1.001,a*(o-1))),l=Math.floor(n),c=Math.floor(h),m=n-l,d=h-c,f=c*r+l,u=Math.min(o-1,c+1)*r+l,p=l+1<r?1:0;return(s[f]*(1-m)+s[f+p]*m)*(1-d)+(s[u]*(1-m)+s[u+p]*m)*d}(this.guide,"depth",t,e):.6,s=.2+.8*a,r=this.edgeSafe?Ut(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,o=(t-this.x.value)*this.sx,n=(e-this.y.value)*this.sy,h=(o*o+n*n)/(r*r);if("reveal"===s)return void(i[2]=Math.exp(2.4*-h)*a);if(h>9)return;const l=this.edgeSafe?Ut(t,e,this.sx/this.sy):1;let c=0,m=0;if("loupe"===s){const t=Math.exp(-h*h)*a*.5;c=o*t,m=n*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(o*o+n*n));c=o/s*Math.min(e,s+.5*r*a),m=n/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=n/r+.45,h=Math.exp(-o*o/(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,d=t*this.sx*9,f=e*this.sy*9+2.3*l;c=.06*($t(d,f)-.5)*h,m=.026*($t(d+17.3,1.3*f+.7*l)-.5)*h,i[2]=.35*($t(1.7*d+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 o=0;o<t;o++){const n=4*(r*t+o);if(s?this.sample(o/(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[n]=t>>>8,i[n+1]=255&t,i[n+2]=128,i[n+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[n]=t>>>8,i[n+1]=255&t,i[n+2]=e>>>8,i[n+3]=255&e}}}},te=(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 ee(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 ie=t=>["trail","contour","etch","ripple","bleed","haze"].includes(t),ae=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]=Ut(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 Ht(this.columns,this.rows),this.contour=new Gt(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:zt(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:s(t)??"none";e!==this.mode&&(this.clear(),this.mode=e,this.refraction.mode=e,zt(e)&&this.afterimage.setMode(e),"ripple"!==e||this.ripple||(this.ripple=new Xt(this.columns,this.rows)),Qt(e)&&(this.cursor??(this.cursor=new _t(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:zt(e)?this.afterimage.pixels:this.waterPixels,this.refraction.strength=te(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=te(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(zt(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,o=Math.hypot(s,r);if(o<1e-5)return;const n=.035+.1*this.radius,h=3*n,l=Math.min(192,Math.max(1,Math.ceil(o/(.5*n)))),c=95*Math.min(o,1)/l;for(let i=0;i<l;i++){const s=(i+.5)/l,r=a.x+(t-a.x)*s,o=a.y+(e-a.y)*s,m=Math.max(1,Math.floor((r-h/this.xScale)*(this.columns-1))),d=Math.min(this.columns-2,Math.ceil((r+h/this.xScale)*(this.columns-1))),f=Math.max(1,Math.floor((o-h/this.yScale)*(this.rows-1))),u=Math.min(this.rows-2,Math.ceil((o+h/this.yScale)*(this.rows-1)));for(let t=f;t<=u;t++)for(let e=m;e<=d;e++){const i=(e/(this.columns-1)-r)*this.xScale,a=(t/(this.rows-1)-o)*this.yScale,s=Math.exp(-(i*i+a*a)/(n*n))*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(zt(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 o=0;for(let t=1;t<this.rows-1;t++)for(let a=1;a<this.columns-1;a++){const n=t*this.columns+a,h=this.heights[n],l=this.heights[n-1]+this.heights[n+1]+this.heights[n-this.columns]+this.heights[n+this.columns]-4*h,c=Math.min(a,t,this.columns-1-a,this.rows-1-t),m=c<5?.88+.024*c:1,d=(this.velocity[n]+(l*i*i-8*h)*e)*s*m;this.velocity[n]=d,this.next[n]=(h+d*e)*m*r,o=Math.max(o,Math.abs(this.next[n]),.1*Math.abs(d))}this.heights.set(this.next),this.energy=o,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,o=Math.tanh(s)*(this.refraction.edgeSafe?this.edgeMask[i]:1),n=Math.tanh(r)*(this.refraction.edgeSafe?this.edgeMask[i]:1);this.normals[2*i]=o,this.normals[2*i+1]=n;const h=Math.round(32767*o+32768),l=Math.round(32767*n+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(zt(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),o=Math.floor(s),n=a-r,h=s-o,l=2*(o*this.columns+r),c=l+2*this.columns;for(let t=0;t<2;t++)i[t]=.08*((this.normals[l+t]*(1-n)+this.normals[l+2+t]*n)*(1-h)+(this.normals[c+t]*(1-n)+this.normals[c+2+t]*n)*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,o,n]=i.focus,h=(t-s)*Math.max(1,a)/n,l=(e-r)*Math.max(1,1/a)/n;return"light"===i.mode?Math.exp(-3*(h*h+l*l))*o:"scan"===i.mode?(1.3*Math.exp(-h*h*110)-.3*Math.exp(-h*h*12))*Math.exp(-l*l*1.8)*o:0}(t,e,this.refraction,this.xScale/this.yScale):0}};function se(t){return"videoWidth"in t?[t.videoWidth,t.videoHeight]:"naturalWidth"in t?[t.naturalWidth,t.naturalHeight]:[t.width,t.height]}var re=(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}},oe=(t,e,i)=>{t.width===e&&t.height===i||(t.width=e,t.height=i)},ne={blocks:" ░▒▓█",braille:" ⠁⠃⠇⡇⣇⣧⣷⣿",lines:" -═╪╬",cross:" ·+xX#",diagonal:" /╱╳",diamond:" ·◇◈◆",mixed:" .:+/◇#@"},he=.32,le=.9;function ce(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<he&&(s=Math.max(0,Math.min(1-he,(s+r)/2-.16)),r=s+he),[s,r]}function me(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 o=((.299*t[i]+.587*t[i+1]+.114*t[i+2])/255-e)/a;o<=.06||(s+=Math.min(1,o),r++)}if(!r)return le;const o=Math.min(.99,Math.max(.01,s/r));return Math.min(le,Math.max(.6,Math.log(.5)/Math.log(o)))}function de(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 fe(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 ue=new WeakMap,pe=t=>Math.max(64,Math.min(4096,Number.isFinite(t)?t:960));function ge(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 Me(t,e,i,a,s){const[r,o]=se(e);t.clearRect(0,0,i,a),t.save();const n=_(r,o,i,a,s);t.translate(n.x+n.width/2,n.y+n.height/2),t.rotate(s.rotation*Math.PI/180),t.drawImage(e,-r*n.scale/2,-o*n.scale/2,r*n.scale,o*n.scale),t.restore()}function xe(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 o=s(),h=s(!0),m=s(),d=s(),f=s(),u=s(),p=s(),g=s(),M=s(),v=s();let b,k,A=0,S=0,E=1,C=le,P=null,T=null,I=null,R="",N=K(e),O=0,D="",j="",U="",X=new Uint8ClampedArray(0),z=new Uint8ClampedArray(0),B=new Uint8ClampedArray(0),Y=null,G="",H=0,V=0,Q=0,J=null,Z="",$=new ae,_=null,tt=new Float32Array(0);const et=s(!0),at=s(),st=s();let rt=0;const ht=[0,0,0],lt=[0,0,0,1],ct=[0,0],mt=[0,0,0,0];let dt=ot(N.color),ft=pt(N.print);const ut=new nt(N.color.denoise),gt=new L(N.warps,N.warpEdge),vt=pe(i.maxDimension),bt=Math.max(256,Math.min(1048576,Number.isFinite(i.maxCells)?i.maxCells:12e3));let Et=bt,Ft=Math.max(.1,Math.min(8,i.pixelRatio??1));const Ct=(t,e,i)=>{$.configure(N.hover.effect,N.hover.strength,N.hover.radius,N.hover.edgeSafe,N.hover.decay),$.move(t,e,i)};function Pt(t,e=0,i=960,a=540,s=e*N.motion.speed){Rt(t,e,i,a,s,!0)}function Rt(e,i,s,L,K,ot){if(Number.isFinite(i)||(i=0),!Number.isFinite(s)||!Number.isFinite(L)||s<1||L<1)throw new Error("Render dimensions must be positive finite numbers.");const[nt,pt]=se(e);if(!nt||!pt)return;const[bt,Ct]=ge(vt,s,L);oe(t,bt,Ct),oe(o.canvas,bt,Ct),oe(m.canvas,bt,Ct),oe(d.canvas,bt,Ct),oe(f.canvas,bt,Ct),rt!==bt/Ct&&(rt=bt/Ct,$=new ae(rt),$.setGuide(_)),$.configure(N.hover.effect,N.hover.strength,N.hover.radius,N.hover.edgeSafe,N.hover.decay),$.step(Math.max(0,Math.min(.05,i-Q))),Q=i;const Pt=a.media(e),Rt=[O,bt,Ct,Pt.time].join(":"),Nt="dither"===N.style,Ut=it(bt,Ct,N,Et,Ft),Xt=Ut.cell,zt=Ut.rowHeight,Bt=Ut.columns,Yt=Ut.rows;if(D!==Rt||J!==Pt.key||H!==Bt||V!==Yt){J=Pt.key,D=Rt,G="",j="",U="",H=Bt,V=Yt,a.scene?a.scene(o.ctx,bt,Ct):Me(o.ctx,e,bt,Ct,N.crop),oe(h.canvas,H,V),h.ctx.clearRect(0,0,H,V),h.ctx.drawImage(o.canvas,0,0,H,V),X=h.ctx.getImageData(0,0,H,V).data,ut.apply(X,H,V),z.length!==X.length&&(z=new Uint8ClampedArray(X.length)),z.set(X);const t=N.color;for(let e=0;e<X.length;e+=4){const i=.299*X[e]+.587*X[e+1]+.114*X[e+2];for(let a=0;a<3;a++){const s=i+(X[e+a]-i)*t.saturation;X[e+a]=((s*(1-t.grayscale)+i*t.grayscale)/255-.5)*t.contrast*255+127.5+255*t.brightness}}if(dt&&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]])}(X,dt),X=gt.apply(X,H,V,bt/Ct),"none"!==N.color.levels){const[t,e]=ce(X),i=me(X,t,e),a=P===Pt.key&&Pt.video?.15:1;P=Pt.key,S+=(t-S)*a,E+=(e-E)*a,C+=(i-C)*a}const i=N.hover,s=i.scope??"all";if("none"===i.effect||"all"===s&&"tilt"!==i.effect)_=null;else{let t=null;if(N.mask.enabled&&N.mask.shapes.length){oe(et.canvas,H,V),et.ctx.clearRect(0,0,H,V),fe(et.ctx,H,V,N.mask.shapes);const e=et.ctx.getImageData(0,0,H,V).data;t=new Float32Array(H*V);for(let i=0;i<t.length;i++)t[i]=N.mask.invert?1-e[4*i+3]/255:e[4*i+3]/255}_=l(X,H,V,t,_),tt.length!==H*V&&(tt=new Float32Array(H*V));for(let t=0;t<tt.length;t++)tt[t]=c(s,_.subject[t],_.key);if("reveal"===i.effect){oe(at.canvas,H,V);const t=new ImageData(H,V);for(let e=0;e<tt.length;e++)t.data[4*e+3]=255*tt[e];at.ctx.putImageData(t,0,0)}}$.setGuide(_)}if(!ot)return void(U=j="");const Wt=xt(N),Gt=Mt(N),Ht=!$.active&&!Wt&&!Gt,Vt=[Rt,H,V,Xt,zt,Ft,$.signature].join(":"),Qt=$.engaged,Jt=$.effect;if(!Ht||U!==Vt){m.ctx.clearRect(0,0,bt,Ct),m.ctx.globalAlpha=1,m.ctx.globalCompositeOperation="source-over";const t=K,e=Wt?N.motion.type:"none",s=N.motion.amount??1,r="relight"===(Kt=e)||"sheen"===Kt||"glow"===Kt||"shimmer"===Kt||"mist"===Kt;"none"!==e&&G!==D&&(Y=function(t,e,i,a,s=t){const r=e*i,o=a?.length===r*yt?a:new Float32Array(r*yt);if(!r)return o;const h=Math.min(e,i),l=new Float32Array(r),c=new Float32Array(r),m=new Float32Array(r),d=new Float32Array(r),f=new Float32Array(r),u=new Float32Array(r);for(let e=0;e<r;e++){const i=t[4*e+3]/255;l[e]=(.299*t[4*e]+.587*t[4*e+1]+.114*t[4*e+2])/255*i}c.set(l),n(c,u,e,i,Math.max(1,Math.round(.012*h))),m.set(l),n(m,u,e,i,Math.max(1,Math.round(.03*h)));for(let t=0;t<r;t++){d[t]=Math.abs(l[t]-c[t]);const e=Math.max(0,l[t]-.55)/.45;f[t]=e*e}n(d,u,e,i,Math.max(1,Math.round(.02*h)));const p=1/Math.max(.02,kt(d,.95));n(f,u,e,i,Math.max(1,Math.round(.05*h)));const g=1/Math.max(.03,kt(f,.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 w=t,b=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 o=0;o<x;o++){const n=[0,0,0,0,0,0,0];for(let h=r*M;h<(r+1)*M;h++)for(let r=o*M;r<(o+1)*M;r++){const o=4*(h*e+r);for(let e=0;e<4;e++)n[e]+=t[o+e];if(a!==i)for(let t=0;t<3;t++)n[4+t]+=s[o+t]}const h=4*(r*x+o),l=M*M;for(let t=0;t<4;t++)i[h+t]=n[t]/l;if(a!==i){for(let t=0;t<3;t++)a[h+t]=n[4+t]/l;a[h+3]=i[h+3]}}w=i,b=a}St?.n!==y&&(St=new At(y)),St.reset();const{depth:k,water:A,sky:S,falls:E}=Tt(w,b,x,v,St),F=kt(k,.03),C=kt(k,.97),P=Math.max(.05,C-F);let T=0,I=0,R=0;const N=new Float32Array(r);for(let t=0;t<i;t++)for(let a=0;a<e;a++){const s=t*e+a,r=s*yt,n=wt((It(k,x,v,a,t,e,i)-F)/P);o[r+1]=n,o[r+8]=wt(It(A,x,v,a,t,e,i)),o[r+9]=wt(It(S,x,v,a,t,e,i)),o[r+10]=wt(It(E,x,v,a,t,e,i));const h=n*n*n*(.25+l[s]);T+=(a+.5)/e*h,I+=(t+.5)/i*h,R+=h,N[s]=Math.hypot(m[t*e+Math.min(e-1,a+1)]-m[t*e+Math.max(0,a-1)],m[Math.min(i-1,t+1)*e+a]-m[Math.max(0,t-1)*e+a])}T=R>0?Math.max(.3,Math.min(.7,T/R)):.5,I=R>0?Math.max(.3,Math.min(.7,I/R)):.5;const O=1/Math.max(.004,kt(N,.97));for(let t=0;t<i;t++)for(let a=0;a<e;a++){const s=t*e+a,r=s*yt,n=(m[t*e+Math.min(e-1,a+1)]-m[t*e+Math.max(0,a-1)])*O,h=(m[Math.min(i-1,t+1)*e+a]-m[Math.max(0,t-1)*e+a])*O;o[r]=m[s],o[r+2]=Math.min(1,f[s]*g),o[r+3]=Math.min(1,d[s]*p),o[r+4]=Math.max(-1,Math.min(1,-n)),o[r+5]=Math.max(-1,Math.min(1,-h)),o[r+6]=T,o[r+7]=I}return o}(z,H,V,Y),G=D);let l=null;if(Nt){const a=Ht;if(!a||j!==Rt){B.length!==X.length&&(B=new Uint8ClampedArray(X.length));const r=B;if(r.set(X),Qt||"none"!==e)for(let i=0;i<V;i++)for(let a=0;a<H;a++){const o=a/H,n=i/V;let h=a,l=i,c=0,m=0,d=1;if(Qt){$.sample(o,n,ht);const t=_?tt[i*H+a]:1;h-=ht[0]*t*H,l-=ht[1]*t*V,"reveal"===Jt?d=1-.72*Math.min(1,ht[2]*t):"repel"===Jt?d=1+Math.max(-1,ht[2])*t:c=ht[2]/3*t}const f=4*(i*H+a);x(e,o,n,t,lt,(.299*X[f]+.587*X[f+1]+.114*X[f+2])/255,Y??void 0,(i*H+a)*yt),w(lt,s),(lt[0]||lt[1])&&(y(lt,h,l,H,V,ct),h=ct[0],l=ct[1]),m=lt[2],d*=lt[3];const u=4*(i*H+a);F(X,H,V,h,l,mt);for(let t=0;t<3;t++){let e=ee(Jt,mt[t]/255,c)+m;r[u+t]=255*e}r[u+3]=mt[3]*d}!function(t,e,i,a,s=0){const{algorithm:r,amount:o,threshold:n}=a,h="blue-noise"===r,l=r.startsWith("bayer")?Number(r.slice(5)):0,c=Dt.get(l),m=l-1,d="luminance"===a.colorSpace,f=("custom"===a.palette?a.colors:W[a.palette]??W.mono).map(qt),u=jt[r],p=u?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,w=f.map(t=>.299*t[0]+.587*t[1]+.114*t[2]),b="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 E=128*(A*o+b+(.5-n)),F=t[M]+E+(p?.[k]??0),C=t[M+1]+E+(p?.[k+1]??0),P=t[M+2]+E+(p?.[k+2]??0);let T=0,I=0,R=0;if(f.length){let t=1/0,e=1/0,i=0,a=0;const s=.299*F+.587*C+.114*P;for(let r=0;r<f.length;r++){const o=f[r],n=d?(s-w[r])**2:(F-o[0])**2*.299+(C-o[1])**2*.587+(P-o[2])**2*.114;n<t?(h&&(e=t,a=i,i=r),t=n,[T,I,R]=o):h&&n<e&&(e=n,a=r)}if(h&&o>0&&Number.isFinite(e)){const t=f[a],e=t[0]-T,r=t[1]-I,n=t[2]-R,h=w[a]-w[i],l=d?h*h:e*e*.299+r*r*.587+n*n*.114,c=d?(s-w[i])*h:(F-T)*e*.299+(C-I)*r*.587+(P-R)*n*.114;S<(l?Math.max(0,Math.min(1,c/l*o)):0)&&([T,I,R]=t)}}else if(h){const t=Math.max(0,Math.min(1,.5+(S-.5)*o));T=51*Math.floor(F/51+1-t),I=51*Math.floor(C/51+1-t),R=51*Math.floor(P/51+1-t)}else T=51*Math.round(F/51),I=51*Math.round(C/51),R=51*Math.round(P/51);if(t[M]=T,t[M+1]=I,t[M+2]=R,p&&u){p[k]=p[k+1]=p[k+2]=0;for(const[t,r,n]of u){const h=s+t;if(h<0||h>=e||a+r>=i)continue;const l=3*((a+r)%3*e+h);p[l]+=(F-T)*n*o,p[l+1]+=(C-I)*n*o,p[l+2]+=(P-R)*n*o}}}}(r,H,V,N.dither,i),h.ctx.putImageData(new ImageData(r,H,V),0,0),j=a?Rt:""}m.ctx.imageSmoothingEnabled=!1,m.ctx.drawImage(h.canvas,0,0,bt,Ct)}else{const i="pointillism"===N.style;i&&a.marks&&void 0===k&&(k=a.marks()),l=i&&k?.begin(bt,Ct)?k:null;const o=Array.from(ne[N.style]??N.charset),n=l?.ctx??m.ctx,h=qt(N.ink),c="ripple"===Jt||"etch"===Jt,d=c&&.299*h[0]+.587*h[1]+.114*h[2]<90?[214,214,214]:h,f="ascii"===N.style||!!ne[N.style],u=q(N.style)?N.style:null,g=Math.max(3,Math.round(.92*zt)),M=Math.ceil(Xt+4),b=Math.ceil(zt+4),P=[o.join(""),g,M,b,N.ink,N.colorMode].join(":");if(f&&P!==Z){Z=P,oe(p.canvas,M*o.length,b),p.ctx.clearRect(0,0,p.canvas.width,b),p.ctx.font=`${g}px monospace`,p.ctx.textBaseline="middle",p.ctx.textAlign="center",p.ctx.fillStyle="accent"===N.colorMode?N.ink:"#ffffff",o.forEach((t,e)=>p.ctx.fillText(t,e*M+M/2,b/2)),T=null,R="";try{const t=p.ctx.getImageData(0,0,p.canvas.width,p.canvas.height).data;T=o.map((e,i)=>{let a=0;for(let e=0;e<p.canvas.height;e++)for(let s=i*M;s<(i+1)*M&&s<p.canvas.width;s++)a+=t[4*(e*p.canvas.width+s)+3];return a})}catch{T=null}}const O=f&&"none"!==N.color.levels;if(O&&T){const t=Z+":"+C.toFixed(2);t!==R&&(R=t,I=de(T,C))}const L=Math.max(.001,E-S);if("lego"===N.style&&A!==Xt){A=Xt,oe(v.canvas,Math.ceil(Xt),Math.ceil(zt));const t=v.ctx;t.clearRect(0,0,v.canvas.width,v.canvas.height),t.fillStyle="rgba(255,255,255,.2)",t.strokeStyle="rgba(0,0,0,.25)",t.lineWidth=Math.max(.5,.6*Ft),t.beginPath(),t.arc(Xt/2,zt/2,.28*Xt,0,2*Math.PI),t.fill(),t.stroke()}n.font=`${g}px monospace`,n.textBaseline="middle",n.textAlign="center";for(let i=0;i<V;i++)for(let a=0;a<H;a++){let m=a,g=i,k=0,A=0;if(Qt){$.sample(a/H,i/V,ht);const t=_?tt[i*H+a]:1;m=Math.max(0,Math.min(H-1,a-ht[0]*t*H)),g=Math.max(0,Math.min(V-1,i-ht[1]*t*V)),"reveal"===Jt?A=.72*Math.min(1,ht[2]*t):"repel"===Jt?A=-Math.max(-1,ht[2])*t:k=ht[2]/3*t}if("none"!==e){const r=4*(i*H+a);x(e,a/H,i/V,t,lt,(.299*X[r]+.587*X[r+1]+.114*X[r+2])/255,Y??void 0,(i*H+a)*yt),w(lt,s),(lt[0]||lt[1])&&(y(lt,m,g,H,V,ct),m=ct[0],g=ct[1])}F(X,H,V,m,g,mt);let E=0;if(c&&k>.012&&(mt[3]?mt[3]>250&&.299*mt[0]+.587*mt[1]+.114*mt[2]<30:"outside"===N.hover.scope)){const t=Math.min(1,(k-.012)/.12);E=t*t*(3-2*t)}if(!mt[3]){if(!(E||k>.03)||"outside"!==N.hover.scope||!ie(Jt))continue;mt[0]=d[0],mt[1]=d[1],mt[2]=d[2],mt[3]=E?255:Math.min(255,640*k)}const P=mt[0],R=mt[1],D=mt[2],j=(.299*P+.587*R+.114*D)/255;let q=O?Math.max(0,Math.min(1,(j-S)/L)):j;q=ee(Jt,q,k,!!u&&ft.settings.invert);const U=a*Xt,z=i*zt;let B=1,W=q;if("none"!==e){const t=lt[2]/(O?Math.max(.5,L):1);q=Math.max(0,Math.min(1,q+t)),W=Math.max(0,Math.min(1,W+t*(r?.45:1)))}else W=q;E&&(q=W=Math.max(q,.1+.45*E)),B=("none"!==e?lt[3]:1)*mt[3]/255*(1-A)*(E?.3+.45*E:1),f||u||"accent"!==N.colorMode||"cmyk"===N.style?O&&"accent"===N.colorMode&&(B*=.32+.68*Math.pow(q,C)):B*=q,n.globalAlpha=B;const G=255*(q-j),Q=l&&"accent"!==N.colorMode?N.ink:"source"===N.colorMode?`rgb(${P+G},${R+G},${D+G})`:"gray"===N.colorMode?`rgb(${Math.round(255*q)},${Math.round(255*q)},${Math.round(255*q)})`:N.ink;if(n.fillStyle=Q,u)ft.paint(n,u,a,i,U,z,Xt,q,Q,"gray"===N.colorMode?255*q:P+G,"gray"===N.colorMode?255*q:R+G,"gray"===N.colorMode?255*q:D+G,N.colorMode);else if(f){const t=O&&I?I[Math.round(255*W)]:Math.max(0,Math.min(o.length-1,Math.round(W*(o.length-1))));if("accent"===N.colorMode?0===T?.[t]:" "===o[t])continue;"accent"===N.colorMode?n.drawImage(p.canvas,t*M,0,M,b,Math.round(U+(Xt-M)/2),Math.round(z+(zt-b)/2),M,b):n.fillText(o[t],U+Xt/2,z+zt/2)}else if("dots"===N.style)n.beginPath(),n.arc(U+Xt/2,z+zt/2,.48*Xt*Math.sqrt(q),0,2*Math.PI),n.fill();else if("led"===N.style)n.beginPath(),n.arc(U+Xt/2,z+zt/2,.39*Xt,0,2*Math.PI),n.fill(),n.globalAlpha=.35*B,n.fillStyle="#ffffff",n.beginPath(),n.arc(U+.43*Xt,z+.4*zt,.11*Xt,0,2*Math.PI),n.fill();else if("hex"===N.style){const t=U+Xt/2,e=z+zt/2;n.beginPath();for(let i=0;i<6;i++){const a=Math.PI/3*i,s=t+Math.cos(a)*Xt*.49,r=e+Math.sin(a)*zt*.49;0===i?n.moveTo(s,r):n.lineTo(s,r)}n.closePath(),n.fill()}else if("cmyk"===N.style){n.fillStyle="#ffffff",n.fillRect(U,z,Xt,zt);const t=(t,e)=>Math.max(0,Math.min(255,"source"===N.colorMode?t+G:"gray"===N.colorMode?255*q:e*q)),e=t(P,h[0]),i=t(R,h[1]),a=t(D,h[2]),s=1-Math.max(e,i,a)/255,r=Math.max(.001,1-s),o=[["#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]];n.globalCompositeOperation="multiply";for(const[t,e,i,a]of o)e>0&&(n.fillStyle=t,n.beginPath(),n.arc(U+Xt*i,z+zt*a,.48*Xt*Math.sqrt(Math.max(0,e)),0,2*Math.PI),n.fill());n.globalCompositeOperation="source-over"}else if("voxel"===N.style){const t=U+Xt/2,e=z+zt/2;n.beginPath(),n.moveTo(t,z),n.lineTo(U+Xt,z+.25*zt),n.lineTo(t,e),n.lineTo(U,z+.25*zt),n.closePath(),n.fill(),n.globalAlpha=.72*B,n.beginPath(),n.moveTo(U,z+.25*zt),n.lineTo(t,e),n.lineTo(t,z+zt),n.lineTo(U,z+.75*zt),n.closePath(),n.fill(),n.globalAlpha=.42*B,n.beginPath(),n.moveTo(t,e),n.lineTo(U+Xt,z+.25*zt),n.lineTo(U+Xt,z+.75*zt),n.lineTo(t,z+zt),n.closePath(),n.fill()}else{const t="pixel"===N.style?0:Math.max(.5,.06*Xt);n.fillRect(U,z,Xt-t,zt-t),"lego"===N.style&&n.drawImage(v.canvas,U,z),"disco"===N.style&&(n.fillStyle=`rgba(255,255,255,${.1+.25*Lt(a,i)})`,n.fillRect(U,z,Xt-t,.35*zt),n.fillStyle="rgba(0,0,0,.25)",n.fillRect(U,z+.65*zt,Xt-t,.35*zt-t))}}}if(m.ctx.globalAlpha=1,l){const t=l.finish();t&&m.ctx.drawImage(t,0,0)}(N.color.amount||N.lights.length)&&(oe(g.canvas,bt,Ct),g.ctx.clearRect(0,0,bt,Ct),g.ctx.drawImage(m.canvas,0,0)),N.color.amount&&(m.ctx.save(),m.ctx.globalCompositeOperation=N.color.blend,m.ctx.globalAlpha=N.color.amount,m.ctx.fillStyle=N.color.tint,m.ctx.fillRect(0,0,bt,Ct),m.ctx.restore());for(const t of N.lights){const e=t.radius*Math.max(bt,Ct),i=m.ctx.createRadialGradient(t.x*bt,t.y*Ct,0,t.x*bt,t.y*Ct,e);i.addColorStop(0,t.color),i.addColorStop(1,"transparent"),m.ctx.save(),m.ctx.globalCompositeOperation="screen",m.ctx.globalAlpha=t.intensity,m.ctx.fillStyle=i,m.ctx.fillRect(0,0,bt,Ct),m.ctx.restore()}(N.color.amount||N.lights.length)&&(m.ctx.globalCompositeOperation="destination-in",m.ctx.drawImage(g.canvas,0,0),m.ctx.globalCompositeOperation="source-over"),N.mask.enabled&&N.mask.shapes.length&&(fe(f.ctx,bt,Ct,N.mask.shapes),m.ctx.globalCompositeOperation=N.mask.invert?"destination-out":"destination-in",m.ctx.drawImage(f.canvas,0,0),m.ctx.globalCompositeOperation="source-over");const c=d.ctx;c.clearRect(0,0,bt,Ct),c.globalAlpha=N.backdrop.opacity;const b=N.backdrop;if("solid"===b.mode&&(c.fillStyle=b.color,c.fillRect(0,0,bt,Ct)),"gradient"===b.mode){const t=c.createLinearGradient(0,0,bt,Ct);t.addColorStop(0,b.color),t.addColorStop(1,b.color2),c.fillStyle=t,c.fillRect(0,0,bt,Ct)}if("source"===b.mode&&c.drawImage(o.canvas,0,0),"blurred"===b.mode){const t=Math.max(1,b.blur);oe(u.canvas,Math.max(2,Math.round(bt/t)),Math.max(2,Math.round(Ct/t))),u.ctx.drawImage(o.canvas,0,0,u.canvas.width,u.canvas.height),c.imageSmoothingEnabled=!0,c.drawImage(u.canvas,0,0,bt,Ct)}c.globalAlpha=1,N.effects.characterBloom>0&&(oe(M.canvas,Math.max(2,Math.round(bt/3)),Math.max(2,Math.round(Ct/3))),M.ctx.clearRect(0,0,M.canvas.width,M.canvas.height),M.ctx.drawImage(m.canvas,0,0,M.canvas.width,M.canvas.height),c.save(),c.globalAlpha=.8*N.effects.characterBloom,c.globalCompositeOperation="screen",c.filter=`blur(${1+4*N.effects.characterBloom}px)`,c.drawImage(M.canvas,0,0,bt,Ct),c.restore());const P=$.spotlight;if(P&&P[2]>.002){oe(st.canvas,bt,Ct);const t=st.ctx,e=P[3]*Math.min(bt,Ct)*1.6;t.globalCompositeOperation="source-over",t.clearRect(0,0,bt,Ct),t.drawImage(o.canvas,0,0),t.globalCompositeOperation="destination-in";const i=t.createRadialGradient(P[0]*bt,P[1]*Ct,0,P[0]*bt,P[1]*Ct,e),a=Math.min(1,P[2]*N.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,Ct),_&&"all"!==(N.hover.scope??"all")&&(t.imageSmoothingEnabled=!0,t.drawImage(at.canvas,0,0,bt,Ct)),t.globalCompositeOperation="source-over",c.drawImage(st.canvas,0,0)}c.drawImage(m.canvas,0,0),U=Ht?Vt:""}var Kt;const Zt=Object.entries(N.effects).some(([t,e])=>!["angle","focus","blurType","characterBloom"].includes(t)&&"number"==typeof e&&e>0);r.clearRect(0,0,bt,Ct),Zt?(void 0===b&&(b=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 o=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,o),i.bufferData(i.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),i.STATIC_DRAW);const n=i.getAttribLocation(r,"p");i.enableVertexAttribArray(n),i.vertexAttribPointer(n,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,o=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/o,e.height/o);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(o),i.deleteProgram(r),a.forEach(t=>i.deleteShader(t)),e.width=e.height=1,i.getExtension("WEBGL_lose_context")?.loseContext()}}}(a.finishCanvas)),b?r.drawImage(b.render(d.canvas,N.effects,i,Ft),0,0):r.drawImage(d.canvas,0,0),a.finished(b?"gpu":"unavailable")):(r.drawImage(d.canvas,0,0),a.finished("none"))}const Nt={canvas:t,render:Pt,setPixelRatio(t){Ft=Math.max(.1,Math.min(8,Number.isFinite(t)?t:1))},get pixelRatio(){return Ft},setBudget(t){Et=Math.max(256,Math.min(bt,Number.isFinite(t)?Math.round(t):bt))},get maxCells(){return Et},configure(t){N=K(t),dt=ot(N.color),ft=pt(N.print),ut.configure(N.color.denoise),gt.configure(N.warps,N.warpEdge),O++},pointer:Ct,leave(){$.leave()},get active(){return $.active},get settings(){return K(N)},get capabilities(){return{gpuFinish:null!==b}},invalidate(){D=""},destroy(){b?.destroy(),k?.destroy(),k=void 0,gt.clear(),ut.configure(0);for(const t of[o,h,m,d,f,u,p,g,M,v,et,at,st])t.canvas.width=t.canvas.height=1;J=null,X=new Uint8ClampedArray(0),B=new Uint8ClampedArray(0),Y=null,G=""}};return ue.set(Nt,Rt),Nt}(t,e,i,(t=>({surface:re,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 ve(t,e,i){return new Promise((a,s)=>{const r=()=>{l(),a()},o=()=>{l(),s(new Error("Unable to load this media. Check its format and cross-origin permissions."))},n=()=>{l(),s(new DOMException("Cancelled","AbortError"))},h=setTimeout(o,2e4),l=()=>{clearTimeout(h),t.removeEventListener(e,r),t.removeEventListener("error",o),i?.removeEventListener("abort",n)};t.addEventListener(e,r,{once:!0}),t.addEventListener("error",o,{once:!0}),i?.addEventListener("abort",n,{once:!0}),i?.aborted&&n()})}async function ye(t,e){if("string"==typeof t&&t.startsWith("blob:")){const i=await fetch(t,{signal:e}),a=await i.blob();return ye(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,o=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 n=s(o),h=n.lsd.width,l=n.lsd.height;if(h*l>4e6)throw new Error("GIF is too large. Use a smaller GIF or an MP4.");const c=n.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(n,!0);if(m.length*h*l*4>128e6)throw new Error("GIF exceeds the 128 MB decoded budget. Use MP4 for long animations.");const d=document.createElement("canvas");d.width=h,d.height=l;const f=d.getContext("2d"),u=document.createElement("canvas"),p=u.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,u.width=i.dims.width,u.height=i.dims.height,p.putImageData(new ImageData(new Uint8ClampedArray(i.patch),u.width,u.height),0,0),f.drawImage(u,i.dims.left,i.dims.top)}return M=a,d};return v(0),{source:d,width:h,height:l,duration:g,animated:!0,seek:async()=>{},frame:v,destroy(){d.width=u.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,o=s?document.createElement("video"):new Image;o.crossOrigin="anonymous",o instanceof HTMLVideoElement&&(o.muted=!0,o.playsInline=!0,o.preload="auto");const n=()=>{o instanceof HTMLVideoElement?(o.pause(),o.removeAttribute("src"),o.load()):o.src="",i&&URL.revokeObjectURL(r)};try{const t=ve(o,s?"loadeddata":"load",e);o.src=r,await t;const i=o instanceof HTMLVideoElement?o.videoWidth:o.naturalWidth,a=o instanceof HTMLVideoElement?o.videoHeight:o.naturalHeight;return{source:o,width:i,height:a,duration:o instanceof HTMLVideoElement?o.duration:0,animated:s,async seek(t,e){if(!(o instanceof HTMLVideoElement))return;if(!Number.isFinite(o.duration)||o.duration<=0)throw new Error("Video duration is unavailable.");const i=Math.max(0,Math.min(o.duration-.001,t%o.duration));if(Math.abs(o.currentTime-i)<.001&&o.readyState>=2)return;const a=ve(o,"seeked",e);o.currentTime=i,await a},frame:()=>o,destroy:n}}catch(t){throw n(),t}}var we=t=>{if(t?.aborted)throw new DOMException("Export cancelled","AbortError")};async function be(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 o=Math.max(1,Math.min(60,Math.round(e.fps??24))),n=e.duration??5;if(!Number.isFinite(n)||n<=0||n>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||n*o>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&&o>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(we(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.");we(a);const o=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 we(a),e.onProgress?.(1),o}const d=Math.ceil(n*o);if("gif"===i){const i=await import("gifenc"),{GIFEncoder:h,quantize:l,applyPalette:m}="function"==typeof i.GIFEncoder?i:i.default,f=h(),u=c.getContext("2d");for(let i=0;i<d;i++){we(a);const h=i/o;if(await t(c,h,s,r,a),we(a),"unavailable"===c.dataset.studioFinish)throw new Error("Optical effects need WebGL. Disable these effects or export in a supported browser.");const p=u.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)/o,n))-Math.round(100*i/o)),repeat:0}),e.onProgress?.((i+1)/d*.98),await new Promise(t=>setTimeout(t,0))}return we(a),f.finish(),e.onProgress?.(1),new Blob([new Uint8Array(f.bytes())],{type:"image/gif"})}const{Output:f,Mp4OutputFormat:u,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 u({fastStart:"in-memory"}):new p,target:new g});c.width=s,c.height=r,m=()=>y.cancel();const w=new M(c,{codec:v,bitrate:Math.max(5e5,Math.round(s*r*o*.15))});y.addVideoTrack(w,{frameRate:o}),c.width=s,c.height=r,await y.start();for(let i=0;i<d;i++){we(a);const h=i/o;if(await t(c,h,s,r,a),we(a),"unavailable"===c.dataset.studioFinish)throw new Error("Optical effects need WebGL. Disable these effects or export in a supported browser.");await w.add(h,Math.min(1/o,n-h)),e.onProgress?.((i+1)/d*.98),i%4==0&&await new Promise(t=>setTimeout(t,0))}return w.close(),we(a),await y.finalize(),we(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}}async function ke(t,e,i){let a;const s=K(e),r="png"!==i.format&&"jpeg"!==i.format;try{return await be(async(e,o,n,h,l,c)=>{a??(a=xe(e,s,{maxDimension:4096,maxCells:i.maxCells??12e3,pixelRatio:n/(i.referenceWidth??Math.min(n,960))})),r&&a.invalidate(),a.render(await t.frame(o,l),o,n,h,c)},i)}finally{a?.destroy()}}var Ae=null,Se=()=>Ae??(Ae=import("./studio-worker.js").then(({default:t})=>t?URL.createObjectURL(new Blob([t],{type:"text/javascript"})):null,()=>null)),Ee=null;function Fe(){if(null!==Ee)return Ee;try{Ee="function"==typeof Worker&&"function"==typeof OffscreenCanvas&&"function"==typeof createImageBitmap&&"transferToImageBitmap"in OffscreenCanvas.prototype&&!!new OffscreenCanvas(1,1).getContext("2d")}catch{Ee=!1}return Ee}var Ce=new WeakSet;function Pe(t,e,i,a,s={width:960,height:540}){let r=null;const o=pe(i.maxDimension),[n,h]=ge(o,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(n*h);let d=n*h;const f=[],u=[];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,w=!1,b=!1,k=0,A=null,S=!1,E=!1,F="none",C=JSON.stringify(K(e).crop),P=null,T=null,I="",R=!0,N=new WeakMap,O=0,L=[],D=null;const j=t=>{if(!w){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=>{b?a.error(new Error(t)):(W(),a.unavailable())};let U=[];const X=()=>{let t=!1;for(;L.length&&void 0!==L[0].reply;){const e=L.shift();e.reply&&(U.push(e),t=!0)}for(;U.length>2;)U.shift().reply.bitmap.close();t&&a.ready()},z=t=>{const e=t.worker=new Worker(r);e.onmessage=t=>{const e=t.data;if(w)return void("frame"===e.type&&e.bitmap.close());if("ready"===e.type)return;"error"===e.type&&q(e.message);const i=L.find(t=>t.seq===e.seq);i?(i.reply="frame"===e.type?e:null,"frame"===e.type&&p&&u.push(e.cost)>=3&&function(t){const e=p;p=null;const i=Math.min(m,c(d),Math.max(f.length,Math.ceil(t/7)))-f.length;for(let t=0;t<i;t++){const i=B();i.post(Y);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())}(u.sort((t,e)=>t-e)[1]),X()):"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=[]},B=()=>{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&&z(t),t},Y={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--)B().post(Y);Se().then(t=>{w||(t?(r=t,f.forEach(z)):q("The Studio worker could not load."))});function W(){if(!w){w=!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[...L,...U])t.reply?.bitmap.close();L=[],U=[],P&&(P.width=P.height=1),P=T=null,N=new WeakMap}}return{get turns(){return f.length},get busy(){return L.length>=v()},get drawing(){return L.length>0||U.length>0},show:()=>{const e=U.shift();return!!e?.reply&&(S=e.reply.active||U.some(t=>t.reply.active),F=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||(D=t.getContext("2d"))),y?y.transferFromImageBitmap(i):(D?.clearRect(0,0,t.width,t.height),D?.drawImage(i,0,0),i.close()),t.dataset.studioFinish=F,b=!0,a.frame(e.time,e.reply.cost),!0);var i},render(t,e,i,a,s,r){if(w||L.length>=v())return!1;const[n,h]=se(t);if(!n||!h)return!1;const[l,u]=ge(o,i,a);for(d=l*u;f.length>c(d);){const t=f.pop();t.worker?.terminate();for(const[,e]of t.waiting)for(const t of e)t.close?.();for(const e of L)e.lane===t&&void 0===e.reply&&(e.reply=null);X()}const g=++k,M=f[g%f.length];L.push({seq:g,time:e,input:E,lane:M}),E=!1;const x=(t=>{let e=N.get(t);return void 0===e&&N.set(t,e=++O),e})(t),y=()=>{if(!w){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}})}},b=[x,r.video?r.time:0,l,u,C].join(":");if(!R&&b===I)return A?A.then(y):y(),!0;R=!1,I=b;const S=()=>{if(w)throw new DOMException("Cancelled","AbortError");return P||(P=document.createElement("canvas"),T=P.getContext("2d")),P.width!==l&&(P.width=l),P.height!==u&&(P.height=u),Me(T,t,l,u,JSON.parse(C)),Promise.all(Array.from({length:f.length+(p?m-f.length:0)},()=>createImageBitmap(P)))},F=t instanceof HTMLImageElement&&!Ce.has(t)?t.decode().catch(()=>{}).then(()=>{Ce.add(t)}):null,D=(A??Promise.resolve()).then(()=>F?F.then(S):S()).then(t=>{if(w){for(const e of t)e.close();return}const e={type:"source",scene:t[0],width:n,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=L.find(t=>t.seq===g);e&&(e.reply=null,X()),R=!0,w||q(t instanceof Error?t.message:String(t))});return A=D,D.then(()=>{A===D&&(A=null)}),!0},pointer(t,e,i){E=!0,j({type:"pointer",x:t,y:e,time:i})},leave(){E=!0,j({type:"leave"})},configure(t){C=JSON.stringify(K(t).crop),j({type:"configure",settings:t})},setBudget(t){M=Math.max(256,Math.min(g,Number.isFinite(t)?Math.round(t):g)),j({type:"budget",cells:t})},get maxCells(){return M},setPixelRatio(t){x=Math.max(.1,Math.min(8,Number.isFinite(t)?t:1)),j({type:"ratio",ratio:t})},get pixelRatio(){return x},get active(){return S||E||L.some(t=>t.input)||U.some(t=>t.input||t.reply.active)},get capabilities(){return{gpuFinish:"unavailable"!==F}},invalidate(){R=!0,j({type:"invalidate"})},destroy:W}}async function Te(t,e,i={}){Fe()&&Se();const a=await ye(e,i.signal);try{return Ie(t,a,i)}catch(t){throw a.destroy(),t}}function Ie(t,e,i={}){let a,s=K(i.settings),r=i.width??e.width,o=i.height??e.height,n=null;const h=()=>xe(t,s,i);if(Fe())try{a=n=Pe(t,s,i,{frame:function(t,r){if(m)return;i.onFrame?.(t,r),V(r/(n?.turns??1),N()&&(e.animated||vt(s))),w=a.active,b||w||d||n?.drawing?R():P()&&(d=!0,R())},ready:()=>R(),unavailable(){const t=a.maxCells,e=a.pixelRatio;n=null,a=h(),a.setBudget(t),a.setPixelRatio(e),d=!0,R()},error:Q},{width:r,height:o})}catch{n=null,a=h()}else a=h();const l=new M;let c=0,m=!1,d=!0,f=!1,u=!0,p=0,g=0,x=0,v=0,y=-1,w=!1,b=!1,k=!1!==i.adaptive,A=0,S=0,E=0,F=0,C=a.maxCells;const P=()=>!(a.maxCells>=C)&&(a.setBudget(C),i.onQualityChange?.(a.maxCells),E=F=S=A=0,!0),T=matchMedia("(prefers-reduced-motion: reduce)"),I=e.source instanceof HTMLVideoElement?e.source:null,R=()=>{m||c||!u||document.hidden||(c=requestAnimationFrame(L))},N=()=>!f&&!T.matches&&u&&!document.hidden,O=()=>{I&&(I.loop=!0,N()?I.play().catch(()=>{f=!0,d=!0,R()}):I.pause()),x=0,d=!0,R()};function L(t){if(c=0,m||!u||document.hidden)return;n?.show()&&n.drawing&&R();const h=N();h&&(p+=x?Math.min(.1,(t-x)/1e3):0),x=t;const f=vt(s),M=h&&(e.animated||f),k=I?.getVideoPlaybackQuality?.().totalVideoFrames??-1,A=!I||k<0||k!==y,E=1e3/Math.max(1,Math.min(60,i.fps??60))-.5,F=d||(a.active?n||t-v>=Math.max(E,2*S):w)||M&&(A||f)&&t-v>=E;if(n&&function(t){const e=t-D;if(D=t,j++,e<3||e>100)return;q+=e,8===++U&&(B=Math.min(B,q/8),q=U=0);if(X+=e,++z<30)return;const i=X/z;X=z=0,i>1.25*B?(H&&(G=Math.min(64,2*G)),Y=Math.min(4,Y+1),W=G,H=!1):Y>1&&i<1.1*B&&--W<=0?(Y--,H=!0):H&&(H=!1,G=Math.max(1,G/2))}(t),F&&n&&!d&&j%Y)b=!0;else if(F&&n)if(n.busy)b=!0;else{e.animated&&!I&&n.invalidate();const[i,a]=tt(r,o,s);g=l.update(p,s.motion.type,s.motion.speed);const h=I?.currentTime??p;(n.render(e.frame(h),h,i,a,g,{video:!!I,time:k})||d)&&(d=!1,v=t,b=!1,y=k)}else if(F){const n=performance.now();try{e.animated&&!I&&a.invalidate();const[t,h]=tt(r,o,s);g=l.update(p,s.motion.type,s.motion.speed),a.render(e.frame(I?.currentTime??p),p,t,h,g);const c=performance.now()-n;i.onFrame?.(I?.currentTime??p,c),V(c,M)}catch(t){Q(t)}d=!1,v=t,w=a.active,y=k}h&&(M||a.active||b)?R():M||a.active||n?.drawing||!P()||(d=!0,R())}let D=0,j=0,q=0,U=0,X=0,z=0,B=1/0,Y=1,W=0,G=1,H=!1;function V(t,e){if(S=S?.9*S+.1*t:t,++A>20&&k&&(e||a.active)){const t=1e3/Math.max(1,Math.min(60,i.fps??60));E=S>1.1*t?E+1:0,F=S<.5*t?F+1:0,E>=20&&a.maxCells>3e3?(a.setBudget(Math.max(3e3,.8*a.maxCells)),i.onQualityChange?.(a.maxCells),E=0,S=0):F>=30&&a.maxCells<C&&(a.setBudget(Math.min(C,1.25*a.maxCells)),i.onQualityChange?.(a.maxCells),F=0,S=0)}}function Q(t){f=!0,i.onError?.(t instanceof Error?t:new Error(String(t)))}const J=e=>{if(!N())return;const i=t.getBoundingClientRect();a.pointer((e.clientX-i.left)/i.width,(e.clientY-i.top)/i.height,e.timeStamp),R()},Z=()=>{a.leave(),R()},$=t=>{"touch"===t.pointerType&&Z()},_=new IntersectionObserver(([t])=>{u=t.isIntersecting,O()});_.observe(t),t.addEventListener("pointermove",J),t.addEventListener("pointerup",$),t.addEventListener("pointerleave",Z),t.addEventListener("pointercancel",Z),document.addEventListener("visibilitychange",O),T.addEventListener("change",O);const it=()=>{m||(m=!0,cancelAnimationFrame(c),_.disconnect(),t.removeEventListener("pointermove",J),t.removeEventListener("pointerup",$),t.removeEventListener("pointerleave",Z),t.removeEventListener("pointercancel",Z),document.removeEventListener("visibilitychange",O),T.removeEventListener("change",O),i.signal?.removeEventListener("abort",it),a.destroy(),e.destroy())};if(i.signal?.addEventListener("abort",it,{once:!0}),i.signal?.aborted)throw it(),new DOMException("Cancelled","AbortError");return O(),{canvas:t,media:e,update(t){s=et(s,t),a.configure(s),d=!0,R()},resize(t,e,i){void 0!==i&&a.setPixelRatio(i),r=Math.max(2,t),o=Math.max(2,e),d=!0,R()},pause(t=!0){f=t,O()},async seek(t){p=Math.max(0,t),await e.seek(p),a.invalidate(),d=!0,R()},redraw(){a.invalidate(),d=!0,R()},get time(){return I?.currentTime??p},get settings(){return K(s)},get motionTime(){return g},get paused(){return f||T.matches},setAdaptive(t){k=t,A=E=S=0},setBudget(t){a.setBudget(t),C=a.maxCells,E=F=S=A=0,i.onQualityChange?.(a.maxCells),d=!0,R()},get pixelRatio(){return a.pixelRatio},get maxCells(){return a.maxCells},get capabilities(){return a.capabilities},destroy:it}}var Re={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")},Ne=Object.keys(Re);async function Oe(t,e="Standard",i="#ffffff",a="#080808"){if(!Object.prototype.hasOwnProperty.call(Re,e))throw new Error("Unknown text font.");const{default:s}=await import("figlet/browser"),r=await Re[e]();s.parseFont(e,r.default),s.defaults({fetchFontIfMissing:!1});const o=s.textSync(t.slice(0,120),{font:e}),n=o.split("\n"),h=Math.max(1,...n.map(t=>t.length)),l=Math.max(1,n.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 d=m.getContext("2d");return null!==a&&(d.fillStyle=a,d.fillRect(0,0,m.width,m.height)),d.fillStyle=i,d.font=15*c+"px monospace",d.textBaseline="top",n.forEach((t,e)=>d.fillText(t,16,16+15*e*c)),{canvas:m,ascii:o}}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:" ⠁⠃⠇⡇⣇⣧⣷⣿"}},De=Le,je=8,qe=t=>t&&"object"==typeof t&&!Array.isArray(t)?t:{},Ue=(t,e,i,a)=>"number"==typeof t&&Number.isFinite(t)?Math.max(i,Math.min(a,t)):e,Xe=(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 ze(t={}){const e=qe(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(Ue(e.width,1280,2,4096)),height:Math.round(Ue(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=qe(t),s=qe(i.placement),r=qe(i.settings),o=qe(r.backdrop),n=Xe(i.id,"Layer id"),h=Xe(i.source,"Source key");if(a.has(n))throw new Error(`Duplicate layer id: ${n}`);return a.add(n),{id:n,source:h,name:"string"==typeof i.name?i.name.slice(0,80):`Layer ${e+1}`,visible:!1!==i.visible,opacity:Ue(i.opacity,1,0,1),blend:Y.includes(i.blend)?i.blend:"source-over",placement:{x:Ue(s.x,.5,-1,2),y:Ue(s.y,.5,-1,2),width:Ue(s.width,1,.01,2),height:Ue(s.height,1,.01,2),rotation:Ue(s.rotation,0,-180,180),flipX:!0===s.flipX,flipY:!0===s.flipY},settings:K({...r,backdrop:{mode:"transparent",...o}})}})}}function Be(t,e,i){if(!t.layers.some(t=>t.id===e))throw new Error(`Unknown layer: ${e}`);return ze({...t,layers:t.layers.map(t=>t.id!==e?t:{...t,...i,id:e,placement:{...t.placement,...i.placement},settings:et(t.settings,i.settings??{})})})}var Ye=t=>JSON.stringify(ze(t));function We(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 ze(e)}function Ge(t,e,i,a,s){const r=t.placement,o=r.rotation*Math.PI/180,n=Math.cos(o),h=Math.sin(o),l=(e-r.x)*a,c=(i-r.y)*s,m=(l*n+c*h)/(r.width*a),d=(-l*h+c*n)/(r.height*s);return[.5+m*(r.flipX?-1:1),.5+d*(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)),o=(s*i.width*t.width+r*i.height*t.height)/2,n=(r*i.width*t.width+s*i.height*t.height)/2;return i.x*t.width+o>0&&i.x*t.width-o<t.width&&i.y*t.height+n>0&&i.y*t.height-n<t.height})}function Ve(t,e=24e3,i=4194304,a=t.width,s=t.height){const r=He(t),o=Math.round(Ue(e,24e3,2048,1048576)),n=Ue(i,4194304,65536,16777216),h=r.map(t=>t.placement.width*t.placement.height),l=h.reduce((t,e)=>t+e,0),c=o-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)}}),d=m.reduce((t,e)=>t+e.width*e.height,0);let f=0,u=0;return r.map((t,e)=>{const i=e===r.length-1?o-f:256+Math.floor(c*h[e]/l);f+=i;const a=m[e],s=e===r.length-1?n-u:4+Math.floor((n-4*r.length)*a.width*a.height/Math.max(1,d));u+=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 Qe(t,e={},i={}){const a=t.getContext("2d");if(!a)throw new Error("Project canvas is already owned by another renderer.");let s=ze(e),r=!0,o=!1,n=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)),d=[];const f=new Map,u=()=>{if(o)throw new Error("Project renderer has been destroyed.")};return{canvas:t,render(e,o=0,p=s.width,g=s.height,M={}){if(u(),!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 w={...s,width:v,height:y},b=He(w);for(const t of b)if(!e.has(t.source))throw new Error(`Missing project source: ${t.source}`);const k=new Set(b.map(t=>t.id));for(const[t,e]of f)k.has(t)||(e.renderer.destroy(),f.delete(t),r=!0);d=Ve(w,c,i.maxRasterPixels,v,y);for(let t=0;t<b.length;t++){const i=b[t],a=d[t],s=e.get(i.source);if(!s)throw new Error(`Missing project source: ${i.source}`);let h=f.get(i.id);const c=n.get(i.id);h?h.signature!==c&&(h.renderer.configure(i.settings),h.signature=c,h.dirty=!0):(h={renderer:xe(document.createElement("canvas"),i.settings,{maxDimension:4096,maxCells:l}),signature:c,dirty:!0,geometry:""},f.set(i.id,h));const u=m*a.width/(p*i.placement.width),g=`${a.width}:${a.height}:${a.maxCells}:${u}`;h.geometry!==g&&(h.renderer.setBudget(a.maxCells),h.renderer.setPixelRatio(u),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||vt(i.settings)){const t=Object.prototype.hasOwnProperty.call(M,i.id)?M[i.id]:void 0;h.renderer.render(s,o,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 b){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){u(),s=ze(t),n=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(o||!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 o of He({...s,width:t.width,height:t.height}).reverse()){const n=f.get(o.id);if(!n)continue;const[h,l]=Ge(o,e,i,t.width,t.height);(!r||"all"===s.pointerMode)&&h>=0&&h<=1&&l>=0&&l<=1&&"none"!==o.settings.hover.effect&&o.settings.hover.strength>0?(n.renderer.pointer(h,l,a),r=!0):n.renderer.leave()}},leave(){for(const t of f.values())t.renderer.leave()},invalidate(t){u();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){u(),c=Math.max(2048,Math.min(l,Number.isFinite(t)?Math.round(t):l)),r=!0},setPixelRatio(t){u(),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 d.map(t=>({...t}))},get active(){return[...f.values()].some(t=>t.renderer.active)},destroy(){if(!o){o=!0;for(const t of f.values())t.renderer.destroy();f.clear(),t.width=t.height=1}}}}function Je(t,e){for(const i of t.layers)if(!e.has(i.source))throw new Error(`Missing project source: ${i.source}`)}async function Ke(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.");Je(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 ye(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}}async function Ze(t,e,i,a={}){const s=ze(e),r=await Ke(s,i,a.signal);try{return $e(t,s,r,a)}catch(t){for(const t of new Set(r.values()))t.destroy();throw t}}function $e(t,e,i,a={}){if((i=new Map(i)).size>8)throw new Error("A project supports up to 8 media bindings.");let s=ze(e);if(Je(s,i),a.signal?.aborted)throw new DOMException("Cancelled","AbortError");const r=Qe(t,s,a),o=matchMedia("(prefers-reduced-motion: reduce)"),n=[...new Set(i.values())],h=n.filter(t=>t.source instanceof HTMLVideoElement).map(t=>t.source),l=new Map;let c,m={},d=0,f=0,u=0,p=0,g=!0,x=!1,v=!0,y=!1,w=!1!==a.adaptive,b=0,k=0,A=0,S=0,E=s.width,F=s.height,C=0,P=!1,T=r.maxCells;const I=new WeakSet,R=Math.max(1,Math.min(60,Number.isFinite(a.fps)?a.fps:60)),N=()=>!y&&!x&&!P&&!o.matches&&v&&!document.hidden,O=()=>{y||p||!v||document.hidden||(p=requestAnimationFrame(q))},L=()=>new Set(He({...s,width:E,height:F}).map(t=>i.get(t.source).source)),D=()=>{const t=L();for(const e of h)e.loop=!0,N()&&t.has(e)?e.paused&&!I.has(e)&&(I.add(e),e.play().then(()=>{I.delete(e),N()&&L().has(e)||e.pause()}).catch(t=>{I.delete(e),y||(x=!0,D(),a.onError?.(t instanceof Error?t:new Error(String(t))),g=!0,O())})):e.pause()},j=()=>{f=0,g=!0,D(),O()};function q(t){if(p=0,y||!v||document.hidden)return;const e=N();e&&(d+=f?Math.min(.1,(t-f)/1e3):0),f=t;const o=He({...s,width:E,height:F}),n=o.some(t=>i.get(t.source).animated||vt(t.settings));if(g||e&&r.active||e&&n&&t-u>=1e3/R-.5){const s=performance.now();try{const t=new Map,h=new Set(o.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(d))}m={};for(const t of o){let e=l.get(t.id);e||(e=new M,l.set(t.id,e)),m[t.id]=e.update(d,t.settings.motion.type,t.settings.motion.speed)}r.render(t,d,E,F,m);const c=performance.now()-s;if(a.onFrame?.(d,c),k=k?.9*k+.1*c:c,++b>20&&w&&e&&(n||r.active)){const t=1e3/R;A=k>1.1*t?A+1:0,S=k<.5*t?S+1:0,A>=20&&r.maxCells>2048?(r.setBudget(Math.max(2048,.8*r.maxCells)),a.onQualityChange?.(r.maxCells),k=A=0,g=!0):S>=30&&r.maxCells<T&&(r.setBudget(Math.min(T,1.25*r.maxCells)),a.onQualityChange?.(r.maxCells),k=S=0,g=!0)}}catch(t){x=!0,D(),a.onError?.(t instanceof Error?t:new Error(String(t)))}g=!1,u=t}e&&(n||r.active)?O():!n&&!r.active&&r.maxCells<T&&(r.setBudget(T),a.onQualityChange?.(r.maxCells),b=A=S=k=0,g=!0,O())}const U=e=>{if(!N())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),O())},X=()=>{r.leave(),O()},z=new IntersectionObserver(([t])=>{v=t.isIntersecting,j()});z.observe(t),t.addEventListener("pointermove",U),t.addEventListener("pointerleave",X),t.addEventListener("pointercancel",X),document.addEventListener("visibilitychange",j),o.addEventListener("change",j);const B=()=>{if(!y){y=!0,C++,c?.abort(),cancelAnimationFrame(p),p=0,z.disconnect(),t.removeEventListener("pointermove",U),t.removeEventListener("pointerleave",X),t.removeEventListener("pointercancel",X),document.removeEventListener("visibilitychange",j),o.removeEventListener("change",j),a.signal?.removeEventListener("abort",B),r.destroy();for(const t of n)t.destroy();l.clear()}};a.signal?.addEventListener("abort",B,{once:!0});const Y=()=>{if(y)throw new Error("Project player has been destroyed.")},W=t=>{Y();const e=ze(t);Je(e,i),E===s.width&&F===s.height&&(E=e.width,F=e.height),s=e,r.configure(s);for(const t of l.keys())s.layers.some(e=>e.id===t)||l.delete(t);j()};return j(),{canvas:t,get project(){return ze(s)},get time(){return d},get motionTimes(){return{...m}},get paused(){return x||o.matches},get maxCells(){return r.maxCells},get pixelRatio(){return r.pixelRatio},get quality(){return r.quality},update:W,updateLayer:(t,e)=>W(Be(s,t,e)),resize(t,e,i){if(Y(),!Number.isFinite(t)||!Number.isFinite(e)||t<2||e<2)throw new Error("Project dimensions must be positive finite numbers.");E=t,F=e,void 0!==i&&r.setPixelRatio(i),j()},pause(t=!0){Y(),x=t,j()},async seek(t){if(Y(),!Number.isFinite(t)||t<0)throw new Error("Project time must be finite and non-negative.");const e=++C;c?.abort(),c=new AbortController;const i=c.signal;P=!0,D();try{if(await Promise.all(n.map(e=>e.seek(t,i))),y||e!==C)return;d=t,l.clear(),r.invalidate()}finally{y||e!==C||(P=!1,j())}},redraw(){Y(),r.invalidate(),g=!0,O()},setBudget(t){Y(),r.setBudget(t),T=r.maxCells,b=A=S=k=0,a.onQualityChange?.(r.maxCells),g=!0,O()},setAdaptive(t){w=t,b=A=S=k=0},destroy:B}}async function _e(t,e,i){const a=ze(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 o,n;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 be(async(t,e,h,l,m)=>{n??(n=await Ke(a,r,m)),o??(o=Qe(t,a,{maxDimension:4096,maxCells:i.maxCells??24e3,maxRasterPixels:i.maxRasterPixels,pixelRatio:h/(i.referenceWidth??Math.min(h,960))}));const d=new Set(He({...a,width:h,height:l}).map(t=>t.source)),f=new Map;await Promise.all([...d].map(async t=>{const i=n.get(t);await i.seek(e,m),f.set(t,i.frame(e)),i.animated&&o.invalidate(t)})),o.render(f,e,h,l,c?s:{})},{...i,signal:h.signal})}finally{if(h.abort(),i.signal?.removeEventListener("abort",l),o?.destroy(),n)for(const t of new Set(n.values()))t.destroy()}}var ti=[{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}}];export{Y as BLEND_MODES,Le as CHARACTER_SETS,a as DEFAULT_HOVER,U as DEFAULT_STUDIO_PRINT,G as DEFAULT_STUDIO_SETTINGS,e as DEPRECATED_STUDIO_HOVERS,m as DEPRECATED_STUDIO_MOTIONS,B as DITHER_ALGORITHMS,i as HOVER_CONTROLS,r as HOVER_SCOPES,je as MAX_STUDIO_LAYERS,T as MAX_STUDIO_WARPS,ti as STUDIO_ANIMATION_PRESETS,De as STUDIO_CHARACTER_SETS,b as STUDIO_CURVE_CHANNELS,t as STUDIO_HOVERS,at as STUDIO_LOOKS,d as STUDIO_MOTIONS,W as STUDIO_PALETTES,j as STUDIO_PRINT_STYLES,D as STUDIO_PRINT_STYLE_IDS,z as STUDIO_STYLES,Ne as STUDIO_TEXT_FONTS,P as STUDIO_WARPS,E as createStudioCurveLookup,Qe as createStudioProjectRenderer,xe as createStudioRenderer,Oe as createStudioText,ke as exportStudio,_e as exportStudioProject,de as inkIndexLookup,q as isStudioPrintStyle,ye as loadStudioMedia,Te as mountStudio,Ie as mountStudioMedia,Ze as mountStudioProject,$e as mountStudioProjectMedia,A as normalizeStudioCurve,S as normalizeStudioCurves,X as normalizeStudioPrint,ze as normalizeStudioProject,K as normalizeStudioSettings,R as normalizeStudioWarps,We as parseStudioProject,$ as parseStudioSettings,s as resolveHover,rt as restyleStudio,Ye as serializeStudioProject,Z as serializeStudioSettings,_ as studioCrop,tt as studioDimensions,it as studioGrid,Ge as studioLayerPoint,ce as studioLevels,st as studioLook,Ve as studioProjectBudget,se as studioSourceSize,me as studioToneGamma,Be as updateStudioProjectLayer,et as updateStudioSettings,He as visibleStudioLayers};//# sourceMappingURL=studio.js.map