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.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";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=t=>"subject"===t||"outside"===t?t:"all";function o(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 n=new Float32Array(0);function h(t,e,i,a,s){const r=e*i,h=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}=h;let d=0;for(let e=0;e<r;e++)t[4*e+3]<250&&d++;const m=e=>(.2126*t[4*e]+.7152*t[4*e+1]+.0722*t[4*e+2])/255;let u="none",f=0;if(d>.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=m(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=m(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}h.key=u,n.length<r&&(n=new Float32Array(r));const p=n;return o(l,p,e,i,Math.max(1,Math.round(.02*Math.min(e,i)))),o(c,p,e,i,Math.max(1,Math.round(.035*Math.min(e,i)))),h}function l(t,e,i="ground"){return"none"===i?1:"subject"===t?e:"outside"===t?1-e:1}var c={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 m(t){const e=t&&Object.prototype.hasOwnProperty.call(c,t)?c[t]:t;return d.find(t=>t.value===e||t.mode===e)?.mode??"none"}var u=t=>Math.max(0,Math.min(1,t)),f=(t,e,i)=>{const a=u((i-t)/(e-t));return a*a*(3-2*a)},p=(t,e)=>{const i=(.06711056*t+.00583715*e)%1*52.9829189;return i-Math.floor(i)},g=class{constructor(){this.last=null,this.mode="none",this.phase=0}update(t,e,i=1){const a=m(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 M(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]:f(.55,1,r)**2,d=o?o[n+3]:.5,m=o?o[n+4]:0,g=o?o[n+5]:0,M=a*Math.PI/6,x=(a%12+12)%12,v=f(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,m*a+g*o))+.35*(a*(e-.5)+o*(i-.5));s[2]=.2*n*(.3+.7*f(.04,.3,h)*(1-.6*f(.82,1,r)))}else if("sheen"===t){const t=1.9*f(0,8,x)-.35,a=(.75*e+.45*i)/1.2+.05*(.75*m+.45*g),o=Math.exp(-(((a-t)/.12)**2));s[2]=o*f(.3,.8,h)*(1-.5*f(.9,1,r))*.45}else if("glow"===t){const t=.5-.5*Math.cos(M),e=1-.8*t;s[2]=.2*f(e-.3,e+.02,c)*Math.sqrt(c)*(1-.65*r)+.05*t*f(.6,.95,r)}else if("shimmer"===t){const t=p(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*f(.5,.88,r)*(.35+.65*f(.1,.55,d))*.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*f(.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*d),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]=f(-.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=f(0,.06,Math.min(e,1-e,i,1-i)),m=o?0:(1-.4*d)*(1-.8*l)*v,u=t=>14*i-t+1.5*Math.sin(3*e+t),g=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)))*m+(3.5*(Math.sin(g(M))-Math.sin(g(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))*m+.8*(Math.cos(g(M))-Math.cos(g(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*p(Math.floor(160*e),Math.floor(100*i))),24)-Math.pow(.5+.5*Math.cos(9*e-4*i+6.2831853*p(Math.floor(160*e),Math.floor(100*i))),24);s[2]=.03*(Math.cos(u(M))-Math.cos(u(0)))*m+(b*f(.5,.85,r)*.3+.025*(Math.cos(g(M))-Math.cos(g(0))))*t*c+.08*(Math.cos(w(M))-Math.cos(w(0)))*h*c}else if("develop"===t){const t=f(7,8.5,x),a=u((x-8.5)/3.5),o=x<8.5?1-t:f(0,1,(1.45*a-(1-r)+.06*(p(Math.floor(160*e),Math.floor(100*i))-.5))/.3);s[2]=.3*-(1-o),s[3]=1-.9*(1-o)}return s}function x(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 v(t,e,i,a,s,r){return r[0]=x(Math.max(0,Math.min(a-1,e-t[0]/960*a))),r[1]=x(Math.max(0,Math.min(s-1,i-t[1]/960*s))),r}function y(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 w=["rgb","red","green","blue"],b=t=>Math.max(0,Math.min(1,t));function k(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*b(i[0]))/255;!e.has(t)&&e.size>=16||e.set(t,b(i[1]))}return[...e].sort((t,e)=>t[0]-e[0])}function S(t){const e=t&&"object"==typeof t?t:{};return Object.fromEntries(w.map(t=>[t,k(e[t])]))}function A(t){const e=k(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,d=c*l,m=(2*d-3*c+1)*e[n][1]+(d-2*c+l)*h*r[n]+(-2*d+3*c)*e[n+1][1]+(d-c)*h*r[n+1];o[t]=Math.round(255*b(m))}return o}function E(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 d=4*(n*e+Math.min(e-1,o+1)),m=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[d+3],g=(1-h)*l*t[m+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[d+e]*p+t[m+e]*g+t[u+e]*M)/x:0;r[3]=x}function F(t,e,i,a,s,r){if(a>=0&&a<=e-1&&s>=0&&s<=i-1)return E(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,d=n+a;if(c<0||c>=e||d<0||d>=i)continue;const m=4*(d*e+c),u=(s?h:1-h)*(a?l:1-l)*t[m+3];r[0]+=t[m]*u,r[1]+=t[m+1]*u,r[2]+=t[m+2]*u,r[3]+=u}r[3]&&(r[0]/=r[3],r[1]/=r[3],r[2]/=r[3])}var T=[{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}],P=(t,e,i,a)=>"number"==typeof t&&Number.isFinite(t)?Math.max(i,Math.min(a,t)):e;function C(t){if(!Array.isArray(t))return[];const e=[];for(const i of t.slice(0,64))if(i&&"object"==typeof i&&T.some(t=>t.value===i.type)&&(e.push({type:i.type,enabled:!1!==i.enabled,amount:P(i.amount,.35,-1,1),x:P(i.x,.5,0,1),y:P(i.y,.5,0,1),radius:P(i.radius,.55,.05,2),angle:P(i.angle,0,-180,180),frequency:P(i.frequency,5,1,24)}),8===e.length))break;return e}var I=2*Math.PI,R=(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=C(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),d=i.amount;let m=a,u=s;if("twirl"===i.type||"zigzag"===i.type){const t="twirl"===i.type?-d*I*c:.65*d*(2/Math.PI*Math.asin(Math.sin(l*I*i.frequency)))*c,e=Math.cos(t),r=Math.sin(t);m=a*e-s*r,u=a*r+s*e}else if("pinch"===i.type){const t=Math.exp(2*d*c);m=a*t,u=s*t}else if("sphere"===i.type&&l>0){const t=1+d*c*(2*Math.asin(l)/Math.PI/l-1);m=a*t,u=s*t}else if("ripple"===i.type&&l>0){const t=1+.12*d*Math.sin(l*I*i.frequency)*c/l;m=a*t,u=s*t}else if("shear"===i.type){const t=-a*i.sin+s*i.cos;m-=d*t*.9*c*i.cos,u-=d*t*.9*c*i.sin}else if("smudge"===i.type)m-=.65*d*c*i.cos,u-=.65*d*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=d>0?r/Math.PI:Math.cos(t*Math.PI)*(e+1)/2,n=d>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;m+=(h-a)*Math.abs(d)*c,u+=(f-s)*Math.abs(d)*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=(R(t,e)-.5)*d*.5*c,o=(R(e+71,t-31)-.5)*d*.5*c;m+=r*i.cos-o*i.sin,u+=r*i.sin+o*i.cos}o=i.x+m*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?F:E;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=""}},L=["stipple","engraving","crosshatch","woodblock","risograph","pointillism"];function D(t){return L.includes(t)}var N={density:1,weight:1,angle:-35,roughness:.35,invert:!1,secondaryInk:"#ec6752",registration:.2,seed:7};function U(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)):N[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:N.secondaryInk,registration:i("registration",0,1),seed:Math.round(i("seed",0,65535))}}var j=["ascii","blocks","braille","dots","lines","cross","diagonal","diamond","mixed","pixel","mosaic","lego","voxel","disco","dither","hex","led","cmyk",...L],X=["none","bayer2","bayer4","bayer8","bayer16","floyd-steinberg","atkinson","stucki","sierra","sierra-lite","burkes","jarvis","halftone","lines","noise","vertical-lines","diagonal-lines","radial","blue-noise"],z=["source-over","multiply","screen","overlay","soft-light","hard-light","color-dodge","color-burn","hue","saturation","color","luminosity"],q={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"]},Y={version:1,aspectRatio:"original",style:"ascii",cellSize:6,charset:" .:-=+*#%@",colorMode:"accent",ink:"#e6e3da",print:{...N},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}},B=t=>t&&"object"==typeof t&&!Array.isArray(t)?t:{},W=(t,e,i,a)=>"number"==typeof t&&Number.isFinite(t)?Math.min(a,Math.max(i,t)):e,G=(t,e)=>"string"==typeof t&&/^#[\da-f]{6}$/i.test(t)?t:e,H=(t,e,i)=>e.includes(t)?t:i;function V(t={}){const e=B(t),o=Y;if(void 0!==e.version&&1!==e.version)throw new Error("Unsupported studio settings version. Update asciify-engine.");const n=B(e.crop),h=B(e.backdrop),l=B(e.color),c=B(e.dither),u=B(e.mask),f=B(e.effects),p=B(e.motion),g=B(e.hover),M={...o.effects};for(const t of["bloom","characterBloom","grain","dust","scanlines","crt","prism","rgbSplit","sharpen","vignette","glitch","pixelate","halftone"])M[t]=W(f[t],0,0,1);M.blur=W(f.blur,0,0,24),M.blurType=H(f.blurType,["gaussian","directional","radial","progressive"],o.effects.blurType),M.angle=W(f.angle,0,-180,180),M.focus=W(f.focus,.5,0,1);let x=2048;return{version:1,aspectRatio:H(e.aspectRatio,["original","16:9","9:16","1:1","4:3","3:4","21:9"],"original"),style:H(e.style,j,o.style),cellSize:W(e.cellSize,o.cellSize,D(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(""):o.charset,colorMode:H(e.colorMode,["accent","source","gray"],o.colorMode),ink:G(e.ink,o.ink),print:U(e.print),warps:C(e.warps),warpEdge:H(e.warpEdge,["clamp","transparent"],"clamp"),crop:{x:W(n.x,.5,0,1),y:W(n.y,.5,0,1),zoom:W(n.zoom,1,1,5),rotation:90*Math.round(W(n.rotation,0,-360,360)/90)},backdrop:{mode:H(h.mode,["solid","transparent","source","blurred","gradient"],o.backdrop.mode),color:G(h.color,o.backdrop.color),color2:G(h.color2,o.backdrop.color2),blur:W(h.blur,12,0,32),opacity:W(h.opacity,1,0,1)},color:{brightness:W(l.brightness,0,-1,1),contrast:W(l.contrast,1,0,3),saturation:W(l.saturation,1,0,3),grayscale:W(l.grayscale,0,0,1),tint:G(l.tint,o.color.tint),amount:W(l.amount,0,0,1),blend:H(l.blend,z,o.color.blend),blackPoint:W(l.blackPoint,0,0,.99),whitePoint:Math.max(W(l.blackPoint,0,0,.99)+1/255,W(l.whitePoint,1,1/255,1)),gamma:W(l.gamma,1,.25,4),shadows:W(l.shadows,0,-1,1),highlights:W(l.highlights,0,-1,1),curves:S(l.curves),denoise:W(l.denoise,0,0,1),levels:"none"===l.levels?"none":"auto"},dither:{algorithm:H(c.algorithm,X,"none"),palette:"string"==typeof c.palette&&Object.prototype.hasOwnProperty.call(q,c.palette)?c.palette:"mono",colors:Array.isArray(c.colors)&&c.colors.length>=2?c.colors.slice(0,32).map(t=>G(t,"#000000")):[...o.dither.colors],amount:W(c.amount,1,0,2),scale:Math.round(W(c.scale,2,1,12)),threshold:W(c.threshold,.5,0,1),motion:H(c.motion,["none","drift","shimmer"],"none"),speed:W(c.speed,1,.1,3),direction:W(c.direction,45,-180,180),colorSpace:H(c.colorSpace,["rgb","luminance"],"rgb")},mask:{enabled:!0===u.enabled,invert:!0===u.invert,shapes:Array.isArray(u.shapes)?u.shapes.slice(0,64).map(t=>{const e=B(t),i=H(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*W(t[0],0,0,1))/1e4,Math.round(1e4*W(t[1],0,0,1))/1e4]:[0,0]):[];return x-=a.length,{kind:i,x:W(e.x,0,0,1),y:W(e.y,0,0,1),width:W(e.width,.5,0,1),height:W(e.height,.5,0,1),size:W(e.size,.05,.005,.5),points:a}}):[]},lights:Array.isArray(e.lights)?e.lights.slice(0,4).map(t=>{const e=B(t);return{x:W(e.x,.5,0,1),y:W(e.y,.5,0,1),radius:W(e.radius,.3,.02,1),intensity:W(e.intensity,.5,0,1),color:G(e.color,"#ffffff")}}):[],effects:M,motion:{type:H("string"==typeof p.type?m(p.type):p.type,d.map(t=>t.mode),"none"),speed:W(p.speed,1,.1,3),amount:W(p.amount,1,0,2)},hover:{effect:s(g.effect)??a.effect,strength:W(g.strength,i.strength.default,i.strength.min,i.strength.max),radius:W(g.radius,i.radius.default,i.radius.min,i.radius.max),edgeSafe:!0===g.edgeSafe,..."all"!==r(g.scope)&&{scope:r(g.scope)},....5!==W(g.decay,.5,0,1)&&{decay:W(g.decay,.5,0,1)}}}}function Q(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 J(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 K(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}),V(i)}function Z(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=D(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 d="dither"===i.style?i.dither.scale:i.cellSize,m=Math.max(c,d)*h;return{cell:m,rowHeight:m*l,columns:Math.ceil(r/m),rows:Math.ceil(o/(m*l)),minimum:c,limited:d<c}}var _=[["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:V(a)}));function $(t){const e=_.find(e=>e.id===t);if(!e)throw new Error("Unknown studio look.");return V(e.settings)}function tt(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,d=c*n,m=(2*d-3*c+1)*o[r]+(d-2*c+n)*h[r]/4+(-2*d+3*c)*o[r+1]+(d-c)*h[r+1]/4;l[t]=Math.round(255*Math.max(0,Math.min(1,m)))}return l}(t),i=t.curves;if(!e&&(!i||Object.values(i).every(t=>t.every(([t,e])=>t===e))))return null;const a=A(i?.rgb),s=[i?.red,i?.green,i?.blue].map(A),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 et=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,d=0,m=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,d+=a[f+1]*g,m+=a[f+2]*g,u+=g}}t[o]=n+(c/u-n)*this.amount,t[o+1]=h+(d/u-h)*this.amount,t[o+2]=l+(m/u-l)*this.amount}}},it=2*Math.PI,at=t=>Math.max(0,Math.min(1,t)),st=.1,rt=t=>Math.max(-.1,Math.min(1.1,t)),ot=Float32Array.from({length:2048},(t,e)=>Math.sin(e/2048*it)),nt=t=>ot[2047&Math.floor(t*(2048/it))];function ht(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 lt(t){const e=U(t),{density:i,weight:a,angle:s,roughness:r,invert:o,secondaryInk:n,registration:h,seed:l}=e,c=s*Math.PI/180,d=[c,c+Math.PI/2,c+Math.PI/4].map(t=>[Math.cos(t),Math.sin(t)]),m=new Float32Array(6);function u(t,e,i,s,o,n,h,c,u=!1){if(h<=0)return;const[f,p]=d[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,d=.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=-d/p,e=(1-d)/p;v=Math.max(v,Math.min(t,e)),w=Math.min(w,Math.max(t,e))}else if(d<0||d>1)continue;if(!(w<=v))if(u&&(v-=st,w+=st),u){for(let t=0;t<6;t++){const s=v+(w-v)*t/5,r=f*(e+c+f*s)+p*(i+d+p*s);m[t]=.5*nt(5.3*r+1.9*a+l)+.25*nt(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=m[e?5-i:i],l=.5*k*(1+r*h*.5)*(e?-1:1),u=s+rt(c+f*a+g*l)*n,x=o+rt(d+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+(d+p*v)*n),t.lineTo(s+(c+f*w)*n,o+(d+p*w)*n)}u?t.fill():t.stroke()}return{settings:e,paint(t,e,s,c,m,f,p,g,M,x,v,y,w){const b=at((o?1-g:g)*i);if(b<=0||t.globalAlpha<=0)return;t.fillStyle=M,t.strokeStyle=M;const k=ht(s,c,l);if("engraving"===e||"crosshatch"===e||"woodblock"===e){const i=b*(1-r*k*.3);"woodblock"===e?u(t,s,c,m,f,p,Math.ceil(5*i)/5,0,!0):(u(t,s,c,m,f,p,i,0),"crosshatch"===e&&(u(t,s,c,m,f,p,Math.max(0,1.5*i-.3),1),u(t,s,c,m,f,p,Math.max(0,2*i-1.2),2)))}else if("risograph"===e){const e="source"===w?at(.5+(x-y)/510):.5,i=.38*h*p,o=p*Math.min(.48,.44*Math.sqrt(b)*a);t.beginPath(),t.arc(m+.5*p,f+.5*p,o*Math.sqrt(.35+.65*(1-e)),0,it),t.fill(),t.globalCompositeOperation="multiply",t.fillStyle=n;const u=1-r*ht(s,c,l+13)*.3;t.beginPath(),t.arc(m+.5*p+i*d[0][0],f+.5*p+i*d[0][1],o*Math.sqrt(.3+.7*e)*u,0,it),t.fill(),t.globalCompositeOperation="source-over"}else{"stipple"===e&&t.beginPath();for(let i=0;i<4;i++){const o=ht(2*s+i%2,2*c+(i>>1),l),n=ht(s,c,l+11*i+1),h=m+((i%2+.5)/2+(o-.5)*r*.28)*p,d=f+((.5+(i>>1))/2+(n-.5)*r*.28)*p,u=Math.min(h-m,m+p-h,d-f,f+p-d,p*Math.min(.245,.21*a*Math.sqrt(b)*(1-r*o*.35)));if("stipple"===e)t.moveTo(h+u,d),t.arc(h,d,u,0,it);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,d,u,.64*u,o*Math.PI,0,it),t.fill()}}"stipple"===e&&t.fill()}}}}var ct=new Set(["none","floyd-steinberg","atkinson","stucki","sierra","sierra-lite","burkes","jarvis"]);function dt(t){return"dither"===t.style&&("shimmer"===t.dither.motion||"drift"===t.dither.motion&&t.dither.amount>0&&!ct.has(t.dither.algorithm))}function mt(t){return"none"!==t.motion.type&&(t.motion.amount??1)>0}function ut(t){return mt(t)||dt(t)||t.effects.grain>0||t.effects.dust>0||t.effects.glitch>0}var ft=11,pt=t=>Math.max(0,Math.min(1,t)),gt=(t,e,i)=>{const a=pt((i-t)/(e-t));return a*a*(3-2*a)};function Mt(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 xt=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}},vt=null;function yt(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 wt(t,e,i,a,s,r,o){const n=i*a,h=o.take(),l=o.take(e),c=o.take(t),d=o.take(),m=o.take();for(let i=0;i<n;i++)d[i]=e[i]*e[i],m[i]=e[i]*t[i];yt(l,h,i,a,s),yt(c,h,i,a,s),yt(d,h,i,a,s),yt(m,h,i,a,s);for(let t=0;t<n;t++){const e=(m[t]-l[t]*c[t])/(d[t]-l[t]*l[t]+r);d[t]=e,m[t]=c[t]-e*l[t]}yt(d,h,i,a,s),yt(m,h,i,a,s);for(let i=0;i<n;i++)t[i]=d[i]*e[i]+m[i]}function bt(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 kt(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 St(t,e,i,a,s){const r=i*a,n=Math.min(i,a),l=s.take(),c=s.take(),d=s.take(),m=s.take(),u=s.take();for(let i=0;i<r;i++){const a=t[4*i+3]/255;u[i]=a,l[i]=e[4*i]/255*a,c[i]=e[4*i+1]/255*a,d[i]=e[4*i+2]/255*a,m[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 o(r,f,i,a,e),r},g=Math.max(2,Math.round(.04*n)),M=Math.max(g+2,Math.round(.12*n)),x=Math.max(2,Math.round(.05*n)),v=p(m,1),y=p(m,g),w=p(m,M),b=s.take(),k=s.take(),S=s.take(),A=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(m[s]-v[s]),k[s]=Math.abs(v[s]-y[s]),S[s]=Math.abs(y[s]-w[s]),A[s]=Math.abs(m[t*i+Math.min(i-1,e+1)]-m[t*i+Math.max(0,e-1)]),E[s]=Math.abs(m[Math.min(a-1,t+1)*i+e]-m[Math.max(0,t-1)*i+e])}o(b,f,i,a,x),o(k,f,i,a,x),o(S,f,i,a,x),o(A,f,i,a,2),o(E,f,i,a,2);const F=Math.max(.01,Mt(b,.9)+Mt(k,.9)),T=p(l,1),P=p(c,1),C=p(d,1),I=s.take(),R=s.take(),O=s.take();let L=0;for(let t=0;t<r;t++){const e=T[t],i=P[t],a=C[t],s=Math.max(e,i,a),r=s-Math.min(e,i,a);O[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 D=gt(.02,.07,L/r),N=Math.max(2,Math.round(.06*a)),U=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];U[t]=e/i}let j=.5,X=0;for(let t=Math.max(N,Math.round(.12*a));t<=Math.min(a-N,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<=N;e++){const s=(t-e)*i+a,d=(t+e-1)*i+a;r+=T[s],o+=P[s],n+=C[s],h+=T[d],l+=P[d],c+=C[d]}const d=(Math.abs(r-h)+Math.abs(o-l)+Math.abs(n-c))/N;e+=d,s+=d>.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+=U[e];for(let e=t;e<l;e++)o+=U[e];r/=t-h,o/=l-t;const c=gt(-.05,.3,(o-r)/(o+r+1e-4)),d=gt(.08,.35,e/i)*(s/i)*c;d>X&&(X=d,j=t/a)}const z=gt(.15,.45,X),q=s.take(),Y=s.take(),B=s.take();for(let t=0;t<r;t++)q[t]=Math.min(l[t],c[t],d[t]);kt(q,f,i,a,1),o(q,f,i,a,g);for(let t=0;t<r;t++)Y[t]=k[t]+S[t];let W=0,G=0,H=0;for(let t=0;t<r;t++)W+=T[t],G+=P[t],H+=C[t];W/=r,G/=r,H/=r;const V=p(T,g),Q=p(P,g),J=p(C,g),K=p(T,M),Z=p(P,M),_=p(C,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]*D+.4*(1-D))}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(m[Math.min(a-1,t+1)*i+e]-m[Math.max(0,t-1)*i+e]);o(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]*D,h=O[s],l=b[s]+k[s],c=gt(175,200,o)*(1-gt(250,275,o))*gt(.08,.25,n),d=(1-gt(45,65,o)+gt(290,330,o))*gt(.2,.45,n)*gt(.3,.55,h),m=(1-gt(.15,.35,n))*gt(.45,.7,h)*z,u=(1-gt(.08,.2,h))*z,f=z>.3?1-gt(j,j+.1,r):1-gt(.4,.8,r),p=1-gt(.02,.06,l),g=1-gt(.03,.09,l);tt[s]=Math.max(c*p,.7*u*(1-gt(.008,.025,l)),d*g*.9)*f,et[s]=Math.max(tt[s],m*p*f),$[s]=0===t?tt[s]:0,it[s]=gt(150,172,o)*(1-gt(232,250,o))*gt(.25,.45,n),rt[s]=gt(1.3,2.2,(A[s]+.004)/(E[s]+.004))*gt(.35,.55,v[s])*(1-gt(.1,.18,R[s]*D))*gt(.025,.07,l)*gt(.025,.045,ht[s]);const M=1-gt(.18,.4,n),x=gt(.55,.8,h)*gt(.05,.12,l);at[s]=Math.max(it[s],.85*M,.8*x)}bt($,tt,i,a,.995,1),bt($,et,i,a,.8,1);let lt=0;for(let t=0;t<r;t++)lt+=$[t];const ct=lt>.04*r&&z>.3;if(ct)for(let t=0;t<a;t++)for(let e=0;e<i;e++)it[t*i+e]*=gt(j,j+.05,(t+.5)/a);if(ct){const t=s.take(),e=s.take(),n=s.take();for(let e=0;e<r;e++)t[e]=.299*V[e]+.587*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-gt(.1,.25,n),(1-gt(15,35,h))*gt(.15,.3,Math.min(R[i],R[a]))),c=Math.max(gt(2,3,(E[i]+.004)/(A[i]+.004))*gt(.015,.04,b[i]+k[i])*gt(.4,.55,b[i]/(b[i]+k[i]+1e-4)),1-gt(.12,.25,t[i]));return l*(s?c:1)*(1-gt(.82*t[a]+.02,1.02*t[a]+.05,t[i]))};let c=0,d=0;for(let t=Math.max(3,Math.round(a*Math.max(.25,j)));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>d&&(d=s,c=t)}const m=gt(.05,.1,d/r);if(m>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)*m,nt[a]=l(c,a,(2*c-t)*i+e,!1)*m,n[a]=ot[a]}o(n,f,i,a,1);for(let t=0;t<r;t++)ot[t]=Math.max(ot[t],n[t]),it[t]=Math.max(it[t],ot[t])}const dt=p(it,M);for(let t=0;t<r;t++)it[t]*=gt(.15,.35,dt[t]);const mt=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]=gt(.28,.45,R[t]*D)*gt(55,80,e)*(1-gt(.3,.6,nt[t]))}const ut=p(st,g);for(let t=0;t<r;t++)st[t]=Math.max(st[t]*(1-(1-gt(.15,.3,ut[t]))*gt(.55,.7,O[t])*gt(.5,.65,R[t])),1-u[t]),at[t]=Math.min(Math.max(at[t],.9*nt[t]),Math.max(it[t],gt(.25,.6,mt[t])))*(1-$[t])*(1-st[t]);bt(it,at,i,a,.97);const ft=s.take(rt),xt=Math.max(2,Math.round(.12*a));for(let t=0;t<i;t++){let e=0;for(let s=-xt;s<=xt;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*xt+1),e+=rt[Math.min(a-1,s+xt+1)*i+t]-rt[Math.max(0,s-xt)*i+t]}o(ft,f,i,a,1);for(let t=0;t<r;t++)rt[t]=gt(.2,.45,ft[t])*gt(.2,.5,rt[t]+.5*ft[t])*(1-$[t]);wt($,m,i,a,Math.max(2,Math.round(.04*n)),.002,s),wt(it,m,i,a,Math.max(2,Math.round(.04*n)),.002,s),wt(rt,m,i,a,Math.max(2,Math.round(.03*n)),.002,s),o(st,f,i,a,1);for(let t=0;t<r;t++)$[t]=gt(.3,.7,$[t])*u[t],rt[t]=gt(.3,.7,rt[t])*u[t]*(1-$[t]),it[t]=gt(.3,.7,it[t])*(1-$[t])*(1-rt[t])*(1-gt(.15,.4,st[t]));kt($,f,i,a,2),kt(it,f,i,a,2),kt(rt,f,i,a,1),o($,f,i,a,1),o(it,f,i,a,1),o(rt,f,i,a,1);const vt=1/Math.max(.02,Mt(B,.97)),St=1/Math.max(.01,Mt(Y,.9)),At=Mt(q,.97),Et=Mt(q,.1),Ft=gt(.06,.25,At-Et),Tt=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]+S[s],l=.6*pt(((b[s]+.6*k[s])/(h+.004)-.25)/.55)+.4*pt((b[s]+k[s])/F),c=gt(.04,.35,h/F)*(1-n),d=.55*pt((q[s]-Et)/Math.max(.05,At-Et))+.25*(1-pt(Y[s]*St))+.2*pt(2*(C[s]-T[s])+.3)*D,m=Ft*gt(.12,.35,y[s])*(.4+.6*z),u=z*(o<j?.45:.45+.55*gt(0,1,(o-j)/Math.max(.15,1-j)))+(1-z)*(.5+.4*(o-.5)),f=b[s]/(b[s]+k[s]+1e-4),p=gt(.2,.7,(b[s]+k[s])/F)*(.35+.65*z)*(1-n),g=1-pt(1.5*Math.hypot(1.2*(r-.5),o-.52)),M=pt(B[s]*vt)*(.55+.45*g),x=.3*c,v=.25*m,w=.12+.45*z,A=.12*p,E=.35*(1-.4*z)*(1-n);Tt[s]=(x*l+v*(1-d)+w*u+A*pt(1.6-1.6*f)+E*M+.04)/(x+v+w+A+E+.08)*(1-.85*$[s])*(1-.45*it[s]*(1-z))}const Pt=h(t,i,a);if("none"!==Pt.key)for(let t=0;t<r;t++)Tt[t]=.7*Pt.subject[t]+.3*Tt[t];return o(Tt,f,i,a,Math.max(1,Math.round(.03*n))),function(t,e,i,a,s,r,o,n,h){const l=s*r,c=h.take(),d=t=>(yt(t,c,s,r,o),t),m=(t,e)=>{const i=h.take();for(let a=0;a<l;a++)i[a]=t[a]*e[a];return d(i)},u=d(h.take(e)),f=d(h.take(i)),p=d(h.take(a)),g=d(h.take(t)),M=m(e,e),x=m(e,i),v=m(e,a),y=m(i,i),w=m(i,a),b=m(a,a),k=m(e,t),S=m(i,t),A=m(a,t),E=h.take(),F=h.take(),T=h.take(),P=h.take();for(let t=0;t<l;t++){const e=k[t]-u[t]*g[t],i=S[t]-f[t]*g[t],a=A[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,d=h*c-l*l,m=o*l-r*c,C=r*l-o*h,I=s*c-o*o,R=r*o-s*l,O=s*h-r*r,L=s*d+r*m+o*C,D=Math.abs(L)>1e-12?1/L:0;E[t]=(d*e+m*i+C*a)*D,F[t]=(m*e+I*i+R*a)*D,T[t]=(C*e+R*i+O*a)*D,P[t]=g[t]-E[t]*u[t]-F[t]*f[t]-T[t]*p[t]}d(E),d(F),d(T),d(P);for(let s=0;s<l;s++)t[s]=E[s]*e[s]+F[s]*i[s]+T[s]*a[s]+P[s]}(Tt,T,P,C,i,a,Math.max(2,Math.round(.07*n)),.004,s),{depth:Tt,water:it,sky:$,falls:rt}}function At(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)),d=n-l,m=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-d)+t[u+1]*d)*(1-m)+(t[f]*(1-d)+t[f+1]*d)*m}var Et="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Ft="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",Tt=new Uint16Array(4096);for(let t=0;t<Tt.length;t++)Tt[t]=Et.indexOf(Ft[2*t])<<6|Et.indexOf(Ft[2*t+1]);var Pt=(t,e)=>{const i=43758.5453*Math.sin(127.1*t+311.7*e);return i-Math.floor(i)};var Ct=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))])),It={"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]]},Rt=t=>[parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16)];function Ot(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 Lt=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],d=Math.max(0,Math.floor((l-h/a)*(this.width-1))),m=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=d;e<=m;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?Ot(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)}},Dt=t=>["dissolve","silk","vortex","magnetic","scatter","etch","elastic","lens","smudge"].includes(t),Nt=t=>"elastic"===t||"scatter"===t,Ut={elastic:[150,4.2],scatter:[90,3.6]},jt=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]=Ot(a/(t-1),i/(e-1),t/e);this.clear()}get active(){return this.peak>2e-4}setMode(t){if(Nt(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),d=l*l*(3-2*l),m=((e(o,n)*(1-c)+e(o+1,n)*c)*(1-d)+(e(o,n+1)*(1-c)+e(o+1,n+1)*c)*d)*Math.PI*4,u=2*(i*this.width+a);t[u]=.7*Math.cos(m),t[u+1]=.7*Math.sin(m)}}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 d=.035+.11*Math.max(.1,Math.min(1,i)),m=Math.min(128,Math.max(1,Math.ceil(c/(.45*d)))),u=c?h/c:1,f=c?l/c:0,p=a||"lens"!==this.mode?Math.min(1,c/(d*m)*2.2):.32;for(let i=0;i<m;i++){const h=(i+.5)/m,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*d/o)*(s-1))),M=Math.min(s-1,Math.ceil((l+2.5*d/o)*(s-1))),x=Math.max(0,Math.floor((c-2.5*d/n)*(r-1))),v=Math.min(r-1,Math.ceil((c+2.5*d/n)*(r-1)));for(let t=x;t<=v;t++)for(let e=g;e<=M;e++){const i=(e/(s-1)-l)*o/d,a=(t/(r-1)-c)*n/d,h=Math.exp(1.5*-(i*i+a*a)),m=t*s+e;if("dissolve"===this.mode||"etch"===this.mode)this.ink[m]=Math.max(this.ink[m],h);else if("elastic"===this.mode)this.springX[m]=Math.max(-24,Math.min(24,this.springX[m]+u*h*p*12)),this.springY[m]=Math.max(-24,Math.min(24,this.springY[m]+f*h*p*12));else if("scatter"===this.mode){const t=this.scatterDirections;this.springX[m]=Math.max(-24,Math.min(24,this.springX[m]+(.6*i+t[2*m])*h*p*7)),this.springY[m]=Math.max(-24,Math.min(24,this.springY[m]+(.6*a+t[2*m+1])*h*p*7))}else if("lens"===this.mode)this.targetX[m]=Math.max(-.65,Math.min(.65,this.targetX[m]+i*h*p*1.6)),this.targetY[m]=Math.max(-.65,Math.min(.65,this.targetY[m]+a*h*p*1.6));else if("smudge"===this.mode)this.targetX[m]=Math.max(-1,Math.min(1,this.targetX[m]+u*h*p*1.3)),this.targetY[m]=Math.max(-1,Math.min(1,this.targetY[m]+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[m]=Math.max(-1,Math.min(1,this.targetX[m]+e*p)),this.targetY[m]=Math.max(-1,Math.min(1,this.targetY[m]+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?Ut.scatter:Ut.elastic,l=Math.sqrt(n-h*h),c=Math.exp(-h*e),d=Math.cos(l*e),m=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(Nt(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*d+(a+h*e)*m))),this.offsetY[t]=Math.max(-1,Math.min(1,c*(i*d+(s+h*i)*m))),this.springX[t]=c*(a*d-(h*a+n*e)*m),this.springY[t]=c*(s*d-(h*s+n*i)*m),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,d=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*d(this.offsetX));i[0]=d(this.offsetX)*(this.edgeSafe?Ot(t,e,this.width/this.height):1)*.08,i[1]=d(this.offsetY)*(this.edgeSafe?Ot(t,e,this.width/this.height):1)*.08,i[2]="dissolve"===this.mode?6*-d(this.ink):0}},Xt=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))}},zt=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),d=1-Math.exp(-c/2.2),m=h*(.022+.075*i)*(.65+.95*d),u=Math.min(128,Math.max(1,Math.ceil(n/(.4*m)))),f=n/m*(.32+.22*d)/u,p=r/n,g=o/n,M=-g,x=p,v=n*(2+18*d)/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*m)),h=Math.min(this.width-2,Math.ceil(r+3*m)),l=Math.max(1,Math.floor(o-3*m)),c=Math.min(this.height-2,Math.ceil(o+3*m));for(let t=l;t<=c;t++)for(let e=n;e<=h;e++){const i=((e-r)*p+(t-o)*g)/m,a=((e-r)*M+(t-o)*x)/m,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,d=0|l,m=h-c,u=l-d,f=d*i+c,p=(1-m)*(1-u),g=m*(1-u),M=(1-m)*u,x=m*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 qt=["loupe","repel","tilt","reveal","haze","bleed"],Yt=t=>qt.includes(t),Bt=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}},Wt=t=>t*t*(3-2*t),Gt=(t,e)=>{const i=43758.5453*Math.sin(127.1*t+311.7*e);return i-Math.floor(i)};function Ht(t,e){const i=Math.floor(t),a=Math.floor(e),s=Wt(t-i),r=Wt(e-a),o=Gt(i,a),n=Gt(i+1,a),h=Gt(i,a+1);return(o+(n-o)*s)*(1-r)+(h+(Gt(i+1,a+1)-h)*s)*r}var Vt=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 Bt,this.y=new Bt,this.tx=new Bt,this.ty=new Bt,this.presence=new Bt,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*Ht(.09*e,.045*t)+.15*Gt(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 d=(l+.5)/c,m=t+(i-t)*d,u=e+(a-e)*d,f=Math.max(0,Math.floor((m-2*h/this.sx)*(o-1))),p=Math.min(o-1,Math.ceil((m+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)-m)*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),d=(i?.02:.1)*e/t,m=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))*m-d*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,d=n-l,m=l*a+h,u=m+a,f=(r[m]*(1-c)+r[m+1]*c)*(1-d)+(r[u]*(1-c)+r[u+1]*c)*d;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),d=n-l,m=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-d)+s[u+p]*d)*(1-m)+(s[f]*(1-d)+s[f+p]*d)*m}(this.guide,"depth",t,e):.6,s=.2+.8*a,r=this.edgeSafe?Ot(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?Ot(t,e,this.sx/this.sy):1;let c=0,d=0;if("loupe"===s){const t=Math.exp(-h*h)*a*.5;c=o*t,d=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),d=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,m=t*this.sx*9,u=e*this.sy*9+2.3*l;c=.06*(Ht(m,u)-.5)*h,d=.026*(Ht(m+17.3,1.3*u+.7*l)-.5)*h,i[2]=.35*(Ht(1.7*m+5,1.7*u)-.5)*h}i[0]=c*l/this.sx,i[1]=d*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}}}},Qt=(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 Jt(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 Kt=t=>["trail","contour","etch","ripple","bleed","haze"].includes(t),Zt=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]=Ot(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 zt(this.columns,this.rows),this.contour=new Xt(this.columns,this.rows),this.afterimage=new jt(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 Yt(this.mode)?this.cursor.engaged:this.active}get spotlight(){return"reveal"===this.mode&&this.cursor?this.cursor.focus:null}get signature(){return Yt(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 Yt(this.mode)?this.cursor.active:"ripple"===this.mode?this.ripple?.active??!1:Dt(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,Dt(e)&&this.afterimage.setMode(e),"ripple"!==e||this.ripple||(this.ripple=new Lt(this.columns,this.rows)),Yt(e)&&(this.cursor??(this.cursor=new Vt(this.columns,this.rows)),this.cursor.guide=this.guide,this.cursor.setMode(e)),this.refraction.pixels=Yt(e)?this.cursor.pixels:"ripple"===e?this.ripple.pixels:"trail"===e?this.trail.pixels:"contour"===e?this.contour.pixels:Dt(e)?this.afterimage.pixels:this.waterPixels,this.refraction.strength=Qt(e,this.amount),this.refraction.relative=Yt(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=Qt(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)),Yt(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(Dt(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,d=Math.max(1,Math.floor((r-h/this.xScale)*(this.columns-1))),m=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=d;e<=m;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(Yt(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(Dt(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),d=c<5?.88+.024*c:1,m=(this.velocity[n]+(l*i*i-8*h)*e)*s*d;this.velocity[n]=m,this.next[n]=(h+m*e)*d*r,o=Math.max(o,Math.abs(this.next[n]),.1*Math.abs(m))}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(Yt(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(Dt(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 _t(t){return"videoWidth"in t?[t.videoWidth,t.videoHeight]:"naturalWidth"in t?[t.naturalWidth,t.naturalHeight]:[t.width,t.height]}var $t=(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}},te=(t,e,i)=>{t.width===e&&t.height===i||(t.width=e,t.height=i)},ee={blocks:" ░▒▓█",braille:" ⠁⠃⠇⡇⣇⣧⣷⣿",lines:" -═╪╬",cross:" ·+xX#",diagonal:" /╱╳",diamond:" ·◇◈◆",mixed:" .:+/◇#@"},ie=.32,ae=.9;function se(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<ie&&(s=Math.max(0,Math.min(1-ie,(s+r)/2-.16)),r=s+ie),[s,r]}function re(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 ae;const o=Math.min(.99,Math.max(.01,s/r));return Math.min(ae,Math.max(.6,Math.log(.5)/Math.log(o)))}function oe(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 ne(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 he(t,e={},i={}){const a=t.getContext("2d");if(!a)throw new Error("Canvas is already owned by another renderer.");const s=$t(),r=$t(!0),n=$t(),c=$t(),d=$t(),m=$t(),u=$t(),f=$t(),p=$t(),g=$t();let x,w=0,b=0,k=1,S=ae,A=null,F=null,T=null,P="",C=V(e),I=0,R="",L="",N="",U=new Uint8ClampedArray(0),j=new Uint8ClampedArray(0),X=new Uint8ClampedArray(0),z=null,Y="",B=0,W=0,G=0,H=null,J="",K=new Zt,_=null,$=new Float32Array(0);const it=$t(!0),at=$t(),st=$t();let rt=0;const ot=[0,0,0],nt=[0,0,0,1],ht=[0,0],ct=[0,0,0,0];let ut=tt(C.color),gt=lt(C.print);const yt=new et(C.color.denoise),wt=new O(C.warps,C.warpEdge),bt=Math.max(64,Math.min(4096,Number.isFinite(i.maxDimension)?i.maxDimension:960)),kt=Math.max(256,Math.min(1048576,Number.isFinite(i.maxCells)?i.maxCells:12e3));let Et=kt,Ft=Math.max(.1,Math.min(8,i.pixelRatio??1));return{canvas:t,render:function(e,i=0,O=960,V=540,tt=i*C.motion.speed){if(Number.isFinite(i)||(i=0),!Number.isFinite(O)||!Number.isFinite(V)||O<1||V<1)throw new Error("Render dimensions must be positive finite numbers.");const[et,lt]=_t(e);if(!et||!lt)return;const kt=Math.min(1,bt/Math.max(O,V)),Ot=Math.max(2,Math.round(O*kt)),Lt=Math.max(2,Math.round(V*kt));te(t,Ot,Lt),te(s.canvas,Ot,Lt),te(n.canvas,Ot,Lt),te(c.canvas,Ot,Lt),te(d.canvas,Ot,Lt),rt!==Ot/Lt&&(rt=Ot/Lt,K=new Zt(rt),K.setGuide(_)),K.configure(C.hover.effect,C.hover.strength,C.hover.radius,C.hover.edgeSafe,C.hover.decay),K.step(Math.max(0,Math.min(.05,i-G))),G=i;const Dt="currentTime"in e?e.getVideoPlaybackQuality?.().totalVideoFrames??e.currentTime:0,Nt=[I,Ot,Lt,Dt].join(":"),Ut="dither"===C.style,jt=Z(Ot,Lt,C,Et,Ft),Xt=jt.cell,zt=jt.rowHeight,qt=jt.columns,Yt=jt.rows;if(R!==Nt||H!==e||B!==qt||W!==Yt){H=e,R=Nt,Y="",L="",N="",B=qt,W=Yt,s.ctx.clearRect(0,0,Ot,Lt),s.ctx.save();const t=Q(et,lt,Ot,Lt,C.crop);s.ctx.translate(t.x+t.width/2,t.y+t.height/2),s.ctx.rotate(C.crop.rotation*Math.PI/180),s.ctx.drawImage(e,-et*t.scale/2,-lt*t.scale/2,et*t.scale,lt*t.scale),s.ctx.restore(),te(r.canvas,B,W),r.ctx.clearRect(0,0,B,W),r.ctx.drawImage(s.canvas,0,0,B,W),U=r.ctx.getImageData(0,0,B,W).data,yt.apply(U,B,W),j.length!==U.length&&(j=new Uint8ClampedArray(U.length)),j.set(U);const i=C.color;for(let t=0;t<U.length;t+=4){const e=.299*U[t]+.587*U[t+1]+.114*U[t+2];for(let a=0;a<3;a++){const s=e+(U[t+a]-e)*i.saturation;U[t+a]=((s*(1-i.grayscale)+e*i.grayscale)/255-.5)*i.contrast*255+127.5+255*i.brightness}}if(ut&&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]])}(U,ut),U=wt.apply(U,B,W,Ot/Lt),"none"!==C.color.levels){const[t,i]=se(U),a=re(U,t,i),s=A===e&&"currentTime"in e?.15:1;A=e,b+=(t-b)*s,k+=(i-k)*s,S+=(a-S)*s}const a=C.hover,o=a.scope??"all";if("none"===a.effect||"all"===o&&"tilt"!==a.effect)_=null;else{let t=null;if(C.mask.enabled&&C.mask.shapes.length){te(it.canvas,B,W),it.ctx.clearRect(0,0,B,W),ne(it.ctx,B,W,C.mask.shapes);const e=it.ctx.getImageData(0,0,B,W).data;t=new Float32Array(B*W);for(let i=0;i<t.length;i++)t[i]=C.mask.invert?1-e[4*i+3]/255:e[4*i+3]/255}_=h(U,B,W,t,_),$.length!==B*W&&($=new Float32Array(B*W));for(let t=0;t<$.length;t++)$[t]=l(o,_.subject[t],_.key);if("reveal"===a.effect){te(at.canvas,B,W);const t=new ImageData(B,W);for(let e=0;e<$.length;e++)t.data[4*e+3]=255*$[e];at.ctx.putImageData(t,0,0)}}K.setGuide(_)}const Bt=mt(C),Wt=dt(C),Gt=!K.active&&!Bt&&!Wt,Ht=[Nt,B,W,Xt,zt,Ft,K.signature].join(":"),Vt=K.engaged,Qt=K.effect;if(!Gt||N!==Ht){n.ctx.clearRect(0,0,Ot,Lt),n.ctx.globalAlpha=1,n.ctx.globalCompositeOperation="source-over";const t=tt,e=Bt?C.motion.type:"none",a=C.motion.amount??1,h="relight"===($t=e)||"sheen"===$t||"glow"===$t||"shimmer"===$t||"mist"===$t;if("none"!==e&&Y!==R&&(z=function(t,e,i,a,s=t){const r=e*i,n=a?.length===r*ft?a:new Float32Array(r*ft);if(!r)return n;const h=Math.min(e,i),l=new Float32Array(r),c=new Float32Array(r),d=new Float32Array(r),m=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),o(c,f,e,i,Math.max(1,Math.round(.012*h))),d.set(l),o(d,f,e,i,Math.max(1,Math.round(.03*h)));for(let t=0;t<r;t++){m[t]=Math.abs(l[t]-c[t]);const e=Math.max(0,l[t]-.55)/.45;u[t]=e*e}o(m,f,e,i,Math.max(1,Math.round(.02*h)));const p=1/Math.max(.02,Mt(m,.95));o(u,f,e,i,Math.max(1,Math.round(.05*h)));const g=1/Math.max(.03,Mt(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}vt?.n!==y&&(vt=new xt(y)),vt.reset();const{depth:k,water:S,sky:A,falls:E}=St(w,b,x,v,vt),F=Mt(k,.03),T=Mt(k,.97),P=Math.max(.05,T-F);let C=0,I=0,R=0;const O=new Float32Array(r);for(let t=0;t<i;t++)for(let a=0;a<e;a++){const s=t*e+a,r=s*ft,o=pt((At(k,x,v,a,t,e,i)-F)/P);n[r+1]=o,n[r+8]=pt(At(S,x,v,a,t,e,i)),n[r+9]=pt(At(A,x,v,a,t,e,i)),n[r+10]=pt(At(E,x,v,a,t,e,i));const h=o*o*o*(.25+l[s]);C+=(a+.5)/e*h,I+=(t+.5)/i*h,R+=h,O[s]=Math.hypot(d[t*e+Math.min(e-1,a+1)]-d[t*e+Math.max(0,a-1)],d[Math.min(i-1,t+1)*e+a]-d[Math.max(0,t-1)*e+a])}C=R>0?Math.max(.3,Math.min(.7,C/R)):.5,I=R>0?Math.max(.3,Math.min(.7,I/R)):.5;const L=1/Math.max(.004,Mt(O,.97));for(let t=0;t<i;t++)for(let a=0;a<e;a++){const s=t*e+a,r=s*ft,o=(d[t*e+Math.min(e-1,a+1)]-d[t*e+Math.max(0,a-1)])*L,h=(d[Math.min(i-1,t+1)*e+a]-d[Math.max(0,t-1)*e+a])*L;n[r]=d[s],n[r+2]=Math.min(1,u[s]*g),n[r+3]=Math.min(1,m[s]*p),n[r+4]=Math.max(-1,Math.min(1,-o)),n[r+5]=Math.max(-1,Math.min(1,-h)),n[r+6]=C,n[r+7]=I}return n}(j,B,W,z),Y=R),Ut){const s=Gt;if(!s||L!==Nt){X.length!==U.length&&(X=new Uint8ClampedArray(U.length));const o=X;if(o.set(U),Vt||"none"!==e)for(let i=0;i<W;i++)for(let s=0;s<B;s++){const r=s/B,n=i/W;let h=s,l=i,c=0,d=0,m=1;if(Vt){K.sample(r,n,ot);const t=_?$[i*B+s]:1;h-=ot[0]*t*B,l-=ot[1]*t*W,"reveal"===Qt?m=1-.72*Math.min(1,ot[2]*t):"repel"===Qt?m=1+Math.max(-1,ot[2])*t:c=ot[2]/3*t}const u=4*(i*B+s);M(e,r,n,t,nt,(.299*U[u]+.587*U[u+1]+.114*U[u+2])/255,z??void 0,(i*B+s)*ft),y(nt,a),(nt[0]||nt[1])&&(v(nt,h,l,B,W,ht),h=ht[0],l=ht[1]),d=nt[2],m*=nt[3];const f=4*(i*B+s);E(U,B,W,h,l,ct);for(let t=0;t<3;t++){let e=Jt(Qt,ct[t]/255,c)+d;o[f+t]=255*e}o[f+3]=ct[3]*m}!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=Ct.get(l),d=l-1,m="luminance"===a.colorSpace,u=("custom"===a.palette?a.colors:q[a.palette]??q.mono).map(Rt),f=It[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 S=0;const A=h?(Tt[64*(a-v&63)+(s-x&63)]+.5)/Tt.length:0;c?S=c[(a-v&d)*l+(s-x&d)]:"noise"===r?S=Pt(s-x,a-v)-.5:"lines"===r?S=y(a-v,4)/3-.5:"vertical-lines"===r?S=y(s-x,4)/3-.5:"diagonal-lines"===r?S=y(s-x+a-v,4)/3-.5:"radial"===r?S=y(Math.hypot(s-e/2,a-i/2)-g,6)/6-.5:"halftone"===r&&(S=Math.hypot(y(s-x,6)-2.5,y(a-v,6)-2.5)/3.54-.5);const E=128*(S*o+b+(.5-n)),F=t[M]+E+(p?.[k]??0),T=t[M+1]+E+(p?.[k+1]??0),P=t[M+2]+E+(p?.[k+2]??0);let C=0,I=0,R=0;if(u.length){let t=1/0,e=1/0,i=0,a=0;const s=.299*F+.587*T+.114*P;for(let r=0;r<u.length;r++){const o=u[r],n=m?(s-w[r])**2:(F-o[0])**2*.299+(T-o[1])**2*.587+(P-o[2])**2*.114;n<t?(h&&(e=t,a=i,i=r),t=n,[C,I,R]=o):h&&n<e&&(e=n,a=r)}if(h&&o>0&&Number.isFinite(e)){const t=u[a],e=t[0]-C,r=t[1]-I,n=t[2]-R,h=w[a]-w[i],l=m?h*h:e*e*.299+r*r*.587+n*n*.114,c=m?(s-w[i])*h:(F-C)*e*.299+(T-I)*r*.587+(P-R)*n*.114;A<(l?Math.max(0,Math.min(1,c/l*o)):0)&&([C,I,R]=t)}}else if(h){const t=Math.max(0,Math.min(1,.5+(A-.5)*o));C=51*Math.floor(F/51+1-t),I=51*Math.floor(T/51+1-t),R=51*Math.floor(P/51+1-t)}else C=51*Math.round(F/51),I=51*Math.round(T/51),R=51*Math.round(P/51);if(t[M]=C,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-C)*n*o,p[l+1]+=(T-I)*n*o,p[l+2]+=(P-R)*n*o}}}}(o,B,W,C.dither,i),r.ctx.putImageData(new ImageData(o,B,W),0,0),L=s?Nt:""}n.ctx.imageSmoothingEnabled=!1,n.ctx.drawImage(r.canvas,0,0,Ot,Lt)}else{const i=Array.from(ee[C.style]??C.charset),s=n.ctx,r=Rt(C.ink),o="ripple"===Qt||"etch"===Qt,l=o&&.299*r[0]+.587*r[1]+.114*r[2]<90?[214,214,214]:r,c="ascii"===C.style||!!ee[C.style],d=D(C.style)?C.style:null,m=Math.max(3,Math.round(.92*zt)),f=Math.ceil(Xt+4),p=Math.ceil(zt+4),x=[i.join(""),m,f,p,C.ink,C.colorMode].join(":");if(c&&x!==J){J=x,te(u.canvas,f*i.length,p),u.ctx.clearRect(0,0,u.canvas.width,p),u.ctx.font=`${m}px monospace`,u.ctx.textBaseline="middle",u.ctx.textAlign="center",u.ctx.fillStyle="accent"===C.colorMode?C.ink:"#ffffff",i.forEach((t,e)=>u.ctx.fillText(t,e*f+f/2,p/2)),F=null,P="";try{const t=u.ctx.getImageData(0,0,u.canvas.width,u.canvas.height).data;F=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{F=null}}const A=c&&"none"!==C.color.levels;if(A&&F){const t=J+":"+S.toFixed(2);t!==P&&(P=t,T=oe(F,S))}const I=Math.max(.001,k-b);if("lego"===C.style&&w!==Xt){w=Xt,te(g.canvas,Math.ceil(Xt),Math.ceil(zt));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*Ft),t.beginPath(),t.arc(Xt/2,zt/2,.28*Xt,0,2*Math.PI),t.fill(),t.stroke()}s.font=`${m}px monospace`,s.textBaseline="middle",s.textAlign="center";for(let n=0;n<W;n++)for(let m=0;m<B;m++){let x=m,w=n,k=0,F=0;if(Vt){K.sample(m/B,n/W,ot);const t=_?$[n*B+m]:1;x=Math.max(0,Math.min(B-1,m-ot[0]*t*B)),w=Math.max(0,Math.min(W-1,n-ot[1]*t*W)),"reveal"===Qt?F=.72*Math.min(1,ot[2]*t):"repel"===Qt?F=-Math.max(-1,ot[2])*t:k=ot[2]/3*t}if("none"!==e){const i=4*(n*B+m);M(e,m/B,n/W,t,nt,(.299*U[i]+.587*U[i+1]+.114*U[i+2])/255,z??void 0,(n*B+m)*ft),y(nt,a),(nt[0]||nt[1])&&(v(nt,x,w,B,W,ht),x=ht[0],w=ht[1])}E(U,B,W,x,w,ct);let P=0;if(o&&k>.012&&(ct[3]?ct[3]>250&&.299*ct[0]+.587*ct[1]+.114*ct[2]<30:"outside"===C.hover.scope)){const t=Math.min(1,(k-.012)/.12);P=t*t*(3-2*t)}if(!ct[3]){if(!(P||k>.03)||"outside"!==C.hover.scope||!Kt(Qt))continue;ct[0]=l[0],ct[1]=l[1],ct[2]=l[2],ct[3]=P?255:Math.min(255,640*k)}const R=ct[0],O=ct[1],L=ct[2],D=(.299*R+.587*O+.114*L)/255;let N=A?Math.max(0,Math.min(1,(D-b)/I)):D;N=Jt(Qt,N,k,!!d&&gt.settings.invert);const j=m*Xt,X=n*zt;let q=1,Y=N;if("none"!==e){const t=nt[2]/(A?Math.max(.5,I):1);N=Math.max(0,Math.min(1,N+t)),Y=Math.max(0,Math.min(1,Y+t*(h?.45:1)))}else Y=N;P&&(N=Y=Math.max(N,.1+.45*P)),q=("none"!==e?nt[3]:1)*ct[3]/255*(1-F)*(P?.3+.45*P:1),c||d||"accent"!==C.colorMode||"cmyk"===C.style?A&&"accent"===C.colorMode&&(q*=.32+.68*Math.pow(N,S)):q*=N,s.globalAlpha=q;const G=255*(N-D),H="source"===C.colorMode?`rgb(${R+G},${O+G},${L+G})`:"gray"===C.colorMode?`rgb(${Math.round(255*N)},${Math.round(255*N)},${Math.round(255*N)})`:C.ink;if(s.fillStyle=H,d)gt.paint(s,d,m,n,j,X,Xt,N,H,"gray"===C.colorMode?255*N:R+G,"gray"===C.colorMode?255*N:O+G,"gray"===C.colorMode?255*N:L+G,C.colorMode);else if(c){const t=A&&T?T[Math.round(255*Y)]:Math.max(0,Math.min(i.length-1,Math.round(Y*(i.length-1))));"accent"===C.colorMode?s.drawImage(u.canvas,t*f,0,f,p,Math.round(j+(Xt-f)/2),Math.round(X+(zt-p)/2),f,p):s.fillText(i[t],j+Xt/2,X+zt/2)}else if("dots"===C.style)s.beginPath(),s.arc(j+Xt/2,X+zt/2,.48*Xt*Math.sqrt(N),0,2*Math.PI),s.fill();else if("led"===C.style)s.beginPath(),s.arc(j+Xt/2,X+zt/2,.39*Xt,0,2*Math.PI),s.fill(),s.globalAlpha=.35*q,s.fillStyle="#ffffff",s.beginPath(),s.arc(j+.43*Xt,X+.4*zt,.11*Xt,0,2*Math.PI),s.fill();else if("hex"===C.style){const t=j+Xt/2,e=X+zt/2;s.beginPath();for(let i=0;i<6;i++){const a=Math.PI/3*i,r=t+Math.cos(a)*Xt*.49,o=e+Math.sin(a)*zt*.49;0===i?s.moveTo(r,o):s.lineTo(r,o)}s.closePath(),s.fill()}else if("cmyk"===C.style){s.fillStyle="#ffffff",s.fillRect(j,X,Xt,zt);const t=(t,e)=>Math.max(0,Math.min(255,"source"===C.colorMode?t+G:"gray"===C.colorMode?255*N:e*N)),e=t(R,r[0]),i=t(O,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(j+Xt*i,X+zt*a,.48*Xt*Math.sqrt(Math.max(0,e)),0,2*Math.PI),s.fill();s.globalCompositeOperation="source-over"}else if("voxel"===C.style){const t=j+Xt/2,e=X+zt/2;s.beginPath(),s.moveTo(t,X),s.lineTo(j+Xt,X+.25*zt),s.lineTo(t,e),s.lineTo(j,X+.25*zt),s.closePath(),s.fill(),s.globalAlpha=.72*q,s.beginPath(),s.moveTo(j,X+.25*zt),s.lineTo(t,e),s.lineTo(t,X+zt),s.lineTo(j,X+.75*zt),s.closePath(),s.fill(),s.globalAlpha=.42*q,s.beginPath(),s.moveTo(t,e),s.lineTo(j+Xt,X+.25*zt),s.lineTo(j+Xt,X+.75*zt),s.lineTo(t,X+zt),s.closePath(),s.fill()}else{const t="pixel"===C.style?0:Math.max(.5,.06*Xt);s.fillRect(j,X,Xt-t,zt-t),"lego"===C.style&&s.drawImage(g.canvas,j,X),"disco"===C.style&&(s.fillStyle=`rgba(255,255,255,${.1+.25*Pt(m,n)})`,s.fillRect(j,X,Xt-t,.35*zt),s.fillStyle="rgba(0,0,0,.25)",s.fillRect(j,X+.65*zt,Xt-t,.35*zt-t))}}}n.ctx.globalAlpha=1,(C.color.amount||C.lights.length)&&(te(f.canvas,Ot,Lt),f.ctx.clearRect(0,0,Ot,Lt),f.ctx.drawImage(n.canvas,0,0)),C.color.amount&&(n.ctx.save(),n.ctx.globalCompositeOperation=C.color.blend,n.ctx.globalAlpha=C.color.amount,n.ctx.fillStyle=C.color.tint,n.ctx.fillRect(0,0,Ot,Lt),n.ctx.restore());for(const t of C.lights){const e=t.radius*Math.max(Ot,Lt),i=n.ctx.createRadialGradient(t.x*Ot,t.y*Lt,0,t.x*Ot,t.y*Lt,e);i.addColorStop(0,t.color),i.addColorStop(1,"transparent"),n.ctx.save(),n.ctx.globalCompositeOperation="screen",n.ctx.globalAlpha=t.intensity,n.ctx.fillStyle=i,n.ctx.fillRect(0,0,Ot,Lt),n.ctx.restore()}(C.color.amount||C.lights.length)&&(n.ctx.globalCompositeOperation="destination-in",n.ctx.drawImage(f.canvas,0,0),n.ctx.globalCompositeOperation="source-over"),C.mask.enabled&&C.mask.shapes.length&&(ne(d.ctx,Ot,Lt,C.mask.shapes),n.ctx.globalCompositeOperation=C.mask.invert?"destination-out":"destination-in",n.ctx.drawImage(d.canvas,0,0),n.ctx.globalCompositeOperation="source-over");const l=c.ctx;l.clearRect(0,0,Ot,Lt),l.globalAlpha=C.backdrop.opacity;const x=C.backdrop;if("solid"===x.mode&&(l.fillStyle=x.color,l.fillRect(0,0,Ot,Lt)),"gradient"===x.mode){const t=l.createLinearGradient(0,0,Ot,Lt);t.addColorStop(0,x.color),t.addColorStop(1,x.color2),l.fillStyle=t,l.fillRect(0,0,Ot,Lt)}if("source"===x.mode&&l.drawImage(s.canvas,0,0),"blurred"===x.mode){const t=Math.max(1,x.blur);te(m.canvas,Math.max(2,Math.round(Ot/t)),Math.max(2,Math.round(Lt/t))),m.ctx.drawImage(s.canvas,0,0,m.canvas.width,m.canvas.height),l.imageSmoothingEnabled=!0,l.drawImage(m.canvas,0,0,Ot,Lt)}l.globalAlpha=1,C.effects.characterBloom>0&&(te(p.canvas,Math.max(2,Math.round(Ot/3)),Math.max(2,Math.round(Lt/3))),p.ctx.clearRect(0,0,p.canvas.width,p.canvas.height),p.ctx.drawImage(n.canvas,0,0,p.canvas.width,p.canvas.height),l.save(),l.globalAlpha=.8*C.effects.characterBloom,l.globalCompositeOperation="screen",l.filter=`blur(${1+4*C.effects.characterBloom}px)`,l.drawImage(p.canvas,0,0,Ot,Lt),l.restore());const A=K.spotlight;if(A&&A[2]>.002){te(st.canvas,Ot,Lt);const t=st.ctx,e=A[3]*Math.min(Ot,Lt)*1.6;t.globalCompositeOperation="source-over",t.clearRect(0,0,Ot,Lt),t.drawImage(s.canvas,0,0),t.globalCompositeOperation="destination-in";const i=t.createRadialGradient(A[0]*Ot,A[1]*Lt,0,A[0]*Ot,A[1]*Lt,e),a=Math.min(1,A[2]*C.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,Ot,Lt),_&&"all"!==(C.hover.scope??"all")&&(t.imageSmoothingEnabled=!0,t.drawImage(at.canvas,0,0,Ot,Lt)),t.globalCompositeOperation="source-over",l.drawImage(st.canvas,0,0)}l.drawImage(n.canvas,0,0),N=Gt?Ht:""}var $t;const ie=Object.entries(C.effects).some(([t,e])=>!["angle","focus","blurType","characterBloom"].includes(t)&&"number"==typeof e&&e>0);a.clearRect(0,0,Ot,Lt),ie?(void 0===x&&(x=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()}}}()),x?a.drawImage(x.render(c.canvas,C.effects,i,Ft),0,0):a.drawImage(c.canvas,0,0),t.dataset.studioFinish=x?"gpu":"unavailable"):(a.drawImage(c.canvas,0,0),t.dataset.studioFinish="none")},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(kt,Number.isFinite(t)?Math.round(t):kt))},get maxCells(){return Et},configure(t){C=V(t),ut=tt(C.color),gt=lt(C.print),yt.configure(C.color.denoise),wt.configure(C.warps,C.warpEdge),I++},pointer:(t,e,i)=>{K.configure(C.hover.effect,C.hover.strength,C.hover.radius,C.hover.edgeSafe,C.hover.decay),K.move(t,e,i)},leave(){K.leave()},get active(){return K.active},get settings(){return V(C)},get capabilities(){return{gpuFinish:null!==x}},invalidate(){R=""},destroy(){x?.destroy(),wt.clear(),yt.configure(0);for(const t of[s,r,n,c,d,m,u,f,p,g,it,at,st])t.canvas.width=t.canvas.height=1;H=null,U=new Uint8ClampedArray(0),X=new Uint8ClampedArray(0),z=null,Y=""}}}function le(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 ce(t,e){if("string"==typeof t&&t.startsWith("blob:")){const i=await fetch(t,{signal:e}),a=await i.blob();return ce(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 d=r(n,!0);if(d.length*h*l*4>128e6)throw new Error("GIF exceeds the 128 MB decoded budget. Use MP4 for long animations.");const m=document.createElement("canvas");m.width=h,m.height=l;const u=m.getContext("2d"),f=document.createElement("canvas"),p=f.getContext("2d"),g=d.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<d.length-1&&(i+=Math.max(20,d[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=d[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=d[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,m};return v(0),{source:m,width:h,height:l,duration:g,animated:!0,seek:async()=>{},frame:v,destroy(){m.width=f.width=1,d.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=le(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=le(o,"seeked",e);o.currentTime=i,await a},frame:()=>o,destroy:n}}catch(t){throw n(),t}}var de=t=>{if(t?.aborted)throw new DOMException("Export cancelled","AbortError")};async function me(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 d;try{if(de(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.");de(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 de(a),e.onProgress?.(1),o}const m=Math.ceil(n*o);if("gif"===i){const i=await import("gifenc"),{GIFEncoder:h,quantize:l,applyPalette:d}="function"==typeof i.GIFEncoder?i:i.default,u=h(),f=c.getContext("2d");for(let i=0;i<m;i++){de(a);const h=i/o;if(await t(c,h,s,r,a),de(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=d(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)/m*.98),await new Promise(t=>setTimeout(t,0))}return de(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,d=()=>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<m;i++){de(a);const h=i/o;if(await t(c,h,s,r,a),de(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)/m*.98),i%4==0&&await new Promise(t=>setTimeout(t,0))}return w.close(),de(a),await y.finalize(),de(a),d=void 0,e.onProgress?.(1),new Blob([y.target.buffer],{type:"mp4"===i?"video/mp4":"video/webm"})}catch(t){throw await(d?.().catch(()=>{})),t}finally{c.width=c.height=1}}function ue(t,e,i={}){let a=V(i.settings),s=i.width??e.width,r=i.height??e.height;const o=he(t,a,i),n=new g;let h=0,l=!1,c=!0,d=!1,m=!0,u=0,f=0,p=0,M=0,x=-1,v=!1,y=!1!==i.adaptive,w=0,b=0,k=0,S=0,A=o.maxCells;const E=matchMedia("(prefers-reduced-motion: reduce)"),F=e.source instanceof HTMLVideoElement?e.source:null,T=()=>{l||h||!m||document.hidden||(h=requestAnimationFrame(I))},P=()=>!d&&!E.matches&&m&&!document.hidden,C=()=>{F&&(F.loop=!0,P()?F.play().catch(()=>{d=!0,c=!0,T()}):F.pause()),p=0,c=!0,T()};function I(t){if(h=0,l||!m||document.hidden)return;const g=P();g&&(u+=p?Math.min(.1,(t-p)/1e3):0),p=t;const E=ut(a),C=g&&(e.animated||E),I=F?.getVideoPlaybackQuality?.().totalVideoFrames??-1,R=!F||I<0||I!==x,O=1e3/Math.max(1,Math.min(60,i.fps??60))-.5;if(c||(o.active?t-M>=Math.max(O,2*b):v)||C&&(R||E)&&t-M>=O){const h=performance.now();try{e.animated&&!F&&o.invalidate();const[t,l]=J(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&&(C||o.active)){const t=1e3/Math.max(1,Math.min(60,i.fps??60));k=b>1.1*t?k+1:0,S=b<.5*t?S+1:0,k>=20&&o.maxCells>3e3?(o.setBudget(Math.max(3e3,.8*o.maxCells)),i.onQualityChange?.(o.maxCells),k=0,b=0):S>=30&&o.maxCells<A&&(o.setBudget(Math.min(A,1.25*o.maxCells)),i.onQualityChange?.(o.maxCells),S=0,b=0)}}catch(t){d=!0,i.onError?.(t instanceof Error?t:new Error(String(t)))}c=!1,M=t,v=o.active,x=I}g&&(C||o.active)?T():C||o.active||o.maxCells>=A||(o.setBudget(A),i.onQualityChange?.(o.maxCells),k=S=b=w=0,0)||(c=!0,T())}const R=e=>{if(!P())return;const i=t.getBoundingClientRect();o.pointer((e.clientX-i.left)/i.width,(e.clientY-i.top)/i.height,e.timeStamp),T()},O=()=>{o.leave(),T()},L=t=>{"touch"===t.pointerType&&O()},D=new IntersectionObserver(([t])=>{m=t.isIntersecting,C()});D.observe(t),t.addEventListener("pointermove",R),t.addEventListener("pointerup",L),t.addEventListener("pointerleave",O),t.addEventListener("pointercancel",O),document.addEventListener("visibilitychange",C),E.addEventListener("change",C);const N=()=>{l||(l=!0,cancelAnimationFrame(h),D.disconnect(),t.removeEventListener("pointermove",R),t.removeEventListener("pointerup",L),t.removeEventListener("pointerleave",O),t.removeEventListener("pointercancel",O),document.removeEventListener("visibilitychange",C),E.removeEventListener("change",C),i.signal?.removeEventListener("abort",N),o.destroy(),e.destroy())};if(i.signal?.addEventListener("abort",N,{once:!0}),i.signal?.aborted)throw N(),new DOMException("Cancelled","AbortError");return C(),{canvas:t,media:e,update(t){a=K(a,t),o.configure(a),c=!0,T()},resize(t,e,i){void 0!==i&&o.setPixelRatio(i),s=Math.max(2,t),r=Math.max(2,e),c=!0,T()},pause(t=!0){d=t,C()},async seek(t){u=Math.max(0,t),await e.seek(u),o.invalidate(),c=!0,T()},redraw(){o.invalidate(),c=!0,T()},get time(){return F?.currentTime??u},get settings(){return V(a)},get motionTime(){return f},get paused(){return d||E.matches},setAdaptive(t){y=t,w=k=b=0},setBudget(t){o.setBudget(t),A=o.maxCells,k=S=b=w=0,i.onQualityChange?.(o.maxCells),c=!0,T()},get pixelRatio(){return o.pixelRatio},get maxCells(){return o.maxCells},get capabilities(){return o.capabilities},destroy:N}}var fe={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")},pe=Object.keys(fe);async function ge(t,e="Standard",i="#ffffff",a="#080808"){if(!Object.prototype.hasOwnProperty.call(fe,e))throw new Error("Unknown text font.");const{default:s}=await import("figlet/browser"),r=await fe[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)),d=document.createElement("canvas");d.width=Math.ceil(9*h*c+32),d.height=Math.ceil(15*l*c+32);const m=d.getContext("2d");return null!==a&&(m.fillStyle=a,m.fillRect(0,0,d.width,d.height)),m.fillStyle=i,m.font=15*c+"px monospace",m.textBaseline="top",n.forEach((t,e)=>m.fillText(t,16,16+15*e*c)),{canvas:d,ascii:o}}var Me={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:" ⠁⠃⠇⡇⣇⣧⣷⣿"}},xe=Me,ve=t=>t&&"object"==typeof t&&!Array.isArray(t)?t:{},ye=(t,e,i,a)=>"number"==typeof t&&Number.isFinite(t)?Math.max(i,Math.min(a,t)):e,we=(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 be(t={}){const e=ve(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(ye(e.width,1280,2,4096)),height:Math.round(ye(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=ve(t),s=ve(i.placement),r=ve(i.settings),o=ve(r.backdrop),n=we(i.id,"Layer id"),h=we(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:ye(i.opacity,1,0,1),blend:z.includes(i.blend)?i.blend:"source-over",placement:{x:ye(s.x,.5,-1,2),y:ye(s.y,.5,-1,2),width:ye(s.width,1,.01,2),height:ye(s.height,1,.01,2),rotation:ye(s.rotation,0,-180,180),flipX:!0===s.flipX,flipY:!0===s.flipY},settings:V({...r,backdrop:{mode:"transparent",...o}})}})}}function ke(t,e,i){if(!t.layers.some(t=>t.id===e))throw new Error(`Unknown layer: ${e}`);return be({...t,layers:t.layers.map(t=>t.id!==e?t:{...t,...i,id:e,placement:{...t.placement,...i.placement},settings:K(t.settings,i.settings??{})})})}function Se(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,d=(l*n+c*h)/(r.width*a),m=(-l*h+c*n)/(r.height*s);return[.5+d*(r.flipX?-1:1),.5+m*(r.flipY?-1:1)]}function Ae(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 Ee(t,e=24e3,i=4194304,a=t.width,s=t.height){const r=Ae(t),o=Math.round(ye(e,24e3,2048,1048576)),n=ye(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,d=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)}}),m=d.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=d[e],s=e===r.length-1?n-f:4+Math.floor((n-4*r.length)*a.width*a.height/Math.max(1,m));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 Fe(t,e={},i={}){const a=t.getContext("2d");if(!a)throw new Error("Project canvas is already owned by another renderer.");let s=be(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,d=Math.max(.1,Math.min(8,Number.isFinite(i.pixelRatio)?i.pixelRatio:1)),m=[];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=Ae(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);m=Ee(w,c,i.maxRasterPixels,v,y);for(let t=0;t<b.length;t++){const i=b[t],a=m[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:he(document.createElement("canvas"),i.settings,{maxDimension:4096,maxCells:l}),signature:c,dirty:!0,geometry:""},u.set(i.id,h));const f=d*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||ut(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 S="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?S="unavailable":"unavailable"!==S&&"gpu"===e.renderer.canvas.dataset.studioFinish&&(S="gpu")}return a.globalAlpha=1,a.globalCompositeOperation="source-over",t.dataset.studioFinish=S,r=!1,!0},configure(t){f(),s=be(t),n=new Map(s.layers.map(t=>[t.id,JSON.stringify(t.settings)])),(()=>{const t=new Set(Ae(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 Ae({...s,width:t.width,height:t.height}).reverse()){const n=u.get(o.id);if(!n)continue;const[h,l]=Se(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(),d=Math.max(.1,Math.min(8,Number.isFinite(t)?t:1)),r=!0},get maxCells(){return c},get pixelRatio(){return d},get quality(){return m.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 Te(t,e){for(const i of t.layers)if(!e.has(i.source))throw new Error(`Missing project source: ${i.source}`)}async function Pe(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.");Te(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 ce(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 ge(i.text,i.font,i.ink??"#ffffff",null);s.set(t,{source:a,width:a.width,height:a.height,duration:0,animated:!1,frame:()=>a,seek:async()=>{},destroy:()=>{a.width=a.height=1}})}}}if(i?.aborted)throw new DOMException("Cancelled","AbortError");return s}catch(t){for(const t of s.values())t.destroy();throw t}}function Ce(t,e,i,a={}){if((i=new Map(i)).size>8)throw new Error("A project supports up to 8 media bindings.");let s=be(e);if(Te(s,i),a.signal?.aborted)throw new DOMException("Cancelled","AbortError");const r=Fe(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,d={},m=0,u=0,f=0,p=0,M=!0,x=!1,v=!0,y=!1,w=!1!==a.adaptive,b=0,k=0,S=0,A=0,E=s.width,F=s.height,T=0,P=!1,C=r.maxCells;const I=new WeakSet,R=Math.max(1,Math.min(60,Number.isFinite(a.fps)?a.fps:60)),O=()=>!y&&!x&&!P&&!o.matches&&v&&!document.hidden,L=()=>{y||p||!v||document.hidden||(p=requestAnimationFrame(j))},D=()=>new Set(Ae({...s,width:E,height:F}).map(t=>i.get(t.source).source)),N=()=>{const t=D();for(const e of h)e.loop=!0,O()&&t.has(e)?e.paused&&!I.has(e)&&(I.add(e),e.play().then(()=>{I.delete(e),O()&&D().has(e)||e.pause()}).catch(t=>{I.delete(e),y||(x=!0,N(),a.onError?.(t instanceof Error?t:new Error(String(t))),M=!0,L())})):e.pause()},U=()=>{u=0,M=!0,N(),L()};function j(t){if(p=0,y||!v||document.hidden)return;const e=O();e&&(m+=u?Math.min(.1,(t-u)/1e3):0),u=t;const o=Ae({...s,width:E,height:F}),n=o.some(t=>i.get(t.source).animated||ut(t.settings));if(M||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(m))}d={};for(const t of o){let e=l.get(t.id);e||(e=new g,l.set(t.id,e)),d[t.id]=e.update(m,t.settings.motion.type,t.settings.motion.speed)}r.render(t,m,E,F,d);const c=performance.now()-s;if(a.onFrame?.(m,c),k=k?.9*k+.1*c:c,++b>20&&w&&e&&(n||r.active)){const t=1e3/R;S=k>1.1*t?S+1:0,A=k<.5*t?A+1:0,S>=20&&r.maxCells>2048?(r.setBudget(Math.max(2048,.8*r.maxCells)),a.onQualityChange?.(r.maxCells),k=S=0,M=!0):A>=30&&r.maxCells<C&&(r.setBudget(Math.min(C,1.25*r.maxCells)),a.onQualityChange?.(r.maxCells),k=A=0,M=!0)}}catch(t){x=!0,N(),a.onError?.(t instanceof Error?t:new Error(String(t)))}M=!1,f=t}e&&(n||r.active)?L():!n&&!r.active&&r.maxCells<C&&(r.setBudget(C),a.onQualityChange?.(r.maxCells),b=S=A=k=0,M=!0,L())}const X=e=>{if(!O())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())},z=()=>{r.leave(),L()},q=new IntersectionObserver(([t])=>{v=t.isIntersecting,U()});q.observe(t),t.addEventListener("pointermove",X),t.addEventListener("pointerleave",z),t.addEventListener("pointercancel",z),document.addEventListener("visibilitychange",U),o.addEventListener("change",U);const Y=()=>{if(!y){y=!0,T++,c?.abort(),cancelAnimationFrame(p),p=0,q.disconnect(),t.removeEventListener("pointermove",X),t.removeEventListener("pointerleave",z),t.removeEventListener("pointercancel",z),document.removeEventListener("visibilitychange",U),o.removeEventListener("change",U),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=be(t);Te(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);U()};return U(),{canvas:t,get project(){return be(s)},get time(){return m},get motionTimes(){return{...d}},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(ke(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),U()},pause(t=!0){B(),x=t,U()},async seek(t){if(B(),!Number.isFinite(t)||t<0)throw new Error("Project time must be finite and non-negative.");const e=++T;c?.abort(),c=new AbortController;const i=c.signal;P=!0,N();try{if(await Promise.all(n.map(e=>e.seek(t,i))),y||e!==T)return;m=t,l.clear(),r.invalidate()}finally{y||e!==T||(P=!1,U())}},redraw(){B(),r.invalidate(),M=!0,L()},setBudget(t){B(),r.setBudget(t),C=r.maxCells,b=S=A=k=0,a.onQualityChange?.(r.maxCells),M=!0,L()},setAdaptive(t){w=t,b=S=A=k=0},destroy:Y}}exports.BLEND_MODES=z,exports.CHARACTER_SETS=Me,exports.DEFAULT_HOVER=a,exports.DEFAULT_STUDIO_PRINT=N,exports.DEFAULT_STUDIO_SETTINGS=Y,exports.DEPRECATED_STUDIO_HOVERS=e,exports.DEPRECATED_STUDIO_MOTIONS=c,exports.DITHER_ALGORITHMS=X,exports.HOVER_CONTROLS=i,exports.HOVER_SCOPES=[{value:"all",label:"Everywhere",description:"The hover acts on the whole artwork."},{value:"subject",label:"Subject",description:"The hover stays on the subject and fades softly at its edge."},{value:"outside",label:"Around",description:"The hover acts only on the ground around the subject."}],exports.MAX_STUDIO_LAYERS=8,exports.MAX_STUDIO_WARPS=8,exports.STUDIO_ANIMATION_PRESETS=[{id:"quiet-light",label:"Quiet light",description:"A key light circles the subject’s own relief, with a soft magnifying wake.",motion:{type:"relight",speed:.6,amount:.8},hover:{effect:"lens",radius:.45,strength:.5}},{id:"living-paper",label:"Memory",description:"A slow push toward the subject; the image leans toward your cursor.",motion:{type:"push",speed:.5,amount:.8},hover:{effect:"tilt",radius:.5,strength:.45}},{id:"silver-grain",label:"Silver light",description:"Sparse glints on bright detail, with a fluid character trail.",motion:{type:"shimmer",speed:.6,amount:.9},hover:{effect:"trail",radius:.35,strength:.55}},{id:"ripple-study",label:"Still water",description:"Smooth water and sky drift like a cinemagraph; your stroke sends out rings.",motion:{type:"current",speed:.6,amount:.8},hover:{effect:"ripple",radius:.45,strength:.7}},{id:"unfolding-print",label:"Darkroom",description:"The print develops from its highlights; your cursor dissolves a soft path.",motion:{type:"develop",speed:.7,amount:1},hover:{effect:"dissolve",radius:.35,strength:.55}},{id:"silk-flow",label:"Morning mist",description:"Mist drifts through the distance; directional folds follow your hand.",motion:{type:"mist",speed:.6,amount:1},hover:{effect:"silk",radius:.4,strength:.5}},{id:"depth-study",label:"Depth study",description:"A slow parallax drift from the photo’s own depth, with a loupe under your cursor.",motion:{type:"parallax",speed:.6,amount:.9},hover:{effect:"loupe",radius:.35,strength:.55}}],exports.STUDIO_CHARACTER_SETS=xe,exports.STUDIO_CURVE_CHANNELS=w,exports.STUDIO_HOVERS=t,exports.STUDIO_LOOKS=_,exports.STUDIO_MOTIONS=d,exports.STUDIO_PALETTES=q,exports.STUDIO_PRINT_STYLES=[{value:"stipple",label:"Stipple",description:"Scattered ink dots shape the image through their size."},{value:"engraving",label:"Engraving",description:"Continuous parallel cuts change weight with the image."},{value:"crosshatch",label:"Crosshatch",description:"Crossing layers of fine lines build the tonal range."},{value:"woodblock",label:"Woodblock",description:"Broad carved bands with irregular edges and stepped tones."},{value:"risograph",label:"Risograph",description:"Two offset ink screens with adjustable registration."},{value:"pointillism",label:"Pointillism",description:"Small pigment strokes mix source colors into the image."}],exports.STUDIO_PRINT_STYLE_IDS=L,exports.STUDIO_STYLES=j,exports.STUDIO_TEXT_FONTS=pe,exports.STUDIO_WARPS=T,exports.createStudioCurveLookup=A,exports.createStudioProjectRenderer=Fe,exports.createStudioRenderer=he,exports.createStudioText=ge,exports.exportStudio=async function(t,e,i){let a;const s=V(e),r="png"!==i.format&&"jpeg"!==i.format;try{return await me(async(e,o,n,h,l,c)=>{a??(a=he(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()}},exports.exportStudioProject=async function(t,e,i){const a=be(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 me(async(t,e,h,l,d)=>{n??(n=await Pe(a,r,d)),o??(o=Fe(t,a,{maxDimension:4096,maxCells:i.maxCells??24e3,maxRasterPixels:i.maxRasterPixels,pixelRatio:h/(i.referenceWidth??Math.min(h,960))}));const m=new Set(Ae({...a,width:h,height:l}).map(t=>t.source)),u=new Map;await Promise.all([...m].map(async t=>{const i=n.get(t);await i.seek(e,d),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()}},exports.inkIndexLookup=oe,exports.isStudioPrintStyle=D,exports.loadStudioMedia=ce,exports.mountStudio=async function(t,e,i={}){const a=await ce(e,i.signal);try{return ue(t,a,i)}catch(t){throw a.destroy(),t}},exports.mountStudioMedia=ue,exports.mountStudioProject=async function(t,e,i,a={}){const s=be(e),r=await Pe(s,i,a.signal);try{return Ce(t,s,r,a)}catch(t){for(const t of new Set(r.values()))t.destroy();throw t}},exports.mountStudioProjectMedia=Ce,exports.normalizeStudioCurve=k,exports.normalizeStudioCurves=S,exports.normalizeStudioPrint=U,exports.normalizeStudioProject=be,exports.normalizeStudioSettings=V,exports.normalizeStudioWarps=C,exports.parseStudioProject=function(t){if(t.length>1e6)throw new Error("Project exceeds the 1 MB settings limit.");const e=JSON.parse(t);if("asciify-project"!==e?.kind||1!==e.version||!Array.isArray(e.layers))throw new Error("This is not an Asciify layered project.");return be(e)},exports.parseStudioSettings=function(t){if(t.length>1e5)throw new Error("Settings exceed 100 KB.");return V(JSON.parse(t))},exports.resolveHover=s,exports.restyleStudio=function(t,e=Math.random){const i=_.filter(e=>e.settings.style!==t.style||e.settings.ink!==t.ink),a=$(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=V(t).mask,a},exports.serializeStudioProject=t=>JSON.stringify(be(t)),exports.serializeStudioSettings=function(t){return JSON.stringify(V(t))},exports.studioCrop=Q,exports.studioDimensions=J,exports.studioGrid=Z,exports.studioLayerPoint=Se,exports.studioLevels=se,exports.studioLook=$,exports.studioProjectBudget=Ee,exports.studioSourceSize=_t,exports.studioToneGamma=re,exports.updateStudioProjectLayer=ke,exports.updateStudioSettings=K,exports.visibleStudioLayers=Ae;//# sourceMappingURL=studio.cjs.map
1
+ "use strict";var t,e=Object.defineProperty,i=Object.getOwnPropertyNames,a=(t,e)=>function(){return t&&(e=(0,t[i(t)[0]])(t=0)),e},s=a({"worker-source:/Users/ayangabryl/asciify-recovery/work/engine/src/studio/render-worker.ts"(){t='"use strict";(()=>{function Ce(n,t,e,r,i,a){r=Math.max(0,Math.min(t-1,r)),i=Math.max(0,Math.min(e-1,i));let o=Math.floor(r),l=Math.floor(i),s=r-o,h=i-l,m=(l*t+o)*4;if(s===0&&h===0){for(let S=0;S<4;S++)a[S]=n[m+S];return}let u=(l*t+Math.min(t-1,o+1))*4,f=(Math.min(e-1,l+1)*t+o)*4,p=(Math.min(e-1,l+1)*t+Math.min(t-1,o+1))*4,c=(1-s)*(1-h)*n[m+3],b=s*(1-h)*n[u+3],g=(1-s)*h*n[f+3],M=s*h*n[p+3],v=c+b+g+M;for(let S=0;S<3;S++)a[S]=v?(n[m+S]*c+n[u+S]*b+n[f+S]*g+n[p+S]*M)/v:0;a[3]=v}function Vr(n,t,e,r,i,a){if(r>=0&&r<=t-1&&i>=0&&i<=e-1)return Ce(n,t,e,r,i,a);if(a[0]=a[1]=a[2]=a[3]=0,r<=-1||r>=t||i<=-1||i>=e)return;let o=Math.floor(r),l=Math.floor(i),s=r-o,h=i-l;for(let m=0;m<=1;m++)for(let u=0;u<=1;u++){let f=o+u,p=l+m;if(f<0||f>=t||p<0||p>=e)continue;let c=(p*t+f)*4,b=(u?s:1-s)*(m?h:1-h)*n[c+3];a[0]+=n[c]*b,a[1]+=n[c+1]*b,a[2]+=n[c+2]*b,a[3]+=b}a[3]&&(a[0]/=a[3],a[1]/=a[3],a[2]/=a[3])}var Ni=["rgb","red","green","blue"],Fr=n=>Math.max(0,Math.min(1,n));function _r(n){let t=new Map([[0,0],[1,1]]);if(Array.isArray(n))for(let e of n.slice(0,64)){if(!Array.isArray(e)||e.length<2||typeof e[0]!="number"||!Number.isFinite(e[0])||typeof e[1]!="number"||!Number.isFinite(e[1]))continue;let r=Math.round(Fr(e[0])*255)/255;!t.has(r)&&t.size>=16||t.set(r,Fr(e[1]))}return[...t].sort((e,r)=>e[0]-r[0])}function Jr(n){let t=n&&typeof n=="object"?n:{};return Object.fromEntries(Ni.map(e=>[e,_r(t[e])]))}function Er(n){let t=_r(n),e=t.length,r=t.slice(1).map((s,h)=>s[0]-t[h][0]),i=t.slice(1).map((s,h)=>(s[1]-t[h][1])/r[h]),a=new Float64Array(e);a[0]=i[0],a[e-1]=i[e-2];for(let s=1;s<e-1;s++){let h=i[s-1],m=i[s];if(h*m<=0)continue;let u=2*r[s]+r[s-1],f=r[s]+2*r[s-1];a[s]=(u+f)/(u/h+f/m)}let o=new Uint8Array(256),l=0;for(let s=0;s<256;s++){let h=s/255;for(;l<e-2&&h>t[l+1][0];)l++;let m=r[l],u=(h-t[l][0])/m,f=u*u,p=f*u,c=(2*p-3*f+1)*t[l][1]+(p-2*f+u)*m*a[l]+(-2*p+3*f)*t[l+1][1]+(p-f)*m*a[l+1];o[s]=Math.round(Fr(c)*255)}return o}function Rr(n){let t=qi(n),e=n.curves;if(!t&&(!e||Object.values(e).every(o=>o.every(([l,s])=>l===s))))return null;let r=Er(e?.rgb),i=[e?.red,e?.green,e?.blue].map(Er),a=new Uint8Array(768);for(let o=0;o<256;o++)for(let l=0;l<3;l++)a[l*256+o]=i[l][r[t?t[o]:o]];return a}function Zr(n,t){for(let e=0;e<n.length;e+=4)n[e+3]&&(n[e]=t[n[e]],n[e+1]=t[256+n[e+1]],n[e+2]=t[512+n[e+2]])}function qi(n){let t=n.blackPoint??0,e=n.whitePoint??1,r=n.gamma??1,i=n.shadows??0,a=n.highlights??0;if(t===0&&e===1&&r===1&&i===0&&a===0)return null;let o=[0,.25+i*.2,.5,.75+a*.2,1],l=o.slice(1).map((m,u)=>(m-o[u])*4),s=[l[0],...l.slice(1).map((m,u)=>2*m*l[u]/(m+l[u])),l[3]],h=new Uint8Array(256);for(let m=0;m<256;m++){let u=Math.pow(Math.max(0,Math.min(1,(m/255-t)/(e-t))),1/r),f=Math.min(3,Math.floor(u*4)),p=u*4-f,c=p*p,b=c*p,g=(2*b-3*c+1)*o[f]+(b-2*c+p)*s[f]/4+(-2*b+3*c)*o[f+1]+(b-c)*s[f+1]/4;h[m]=Math.round(Math.max(0,Math.min(1,g))*255)}return h}var Qe=class{constructor(t=0){this.amount=0;this.weights=new Float32Array(256);this.source=new Uint8ClampedArray(0);this.configure(t)}configure(t=0){let e=Math.max(0,Math.min(1,Number.isFinite(t)?t:0));if(e===this.amount)return;if(this.amount=e,e===0){this.source=new Uint8ClampedArray(0);return}let r=8+e*24;for(let i=0;i<256;i++)this.weights[i]=Math.exp(-i*i/(2*r*r))}apply(t,e,r){if(!this.amount)return;if(!Number.isInteger(e)||!Number.isInteger(r)||e<1||r<1||e*r*4!==t.length)throw new Error("Denoise dimensions do not match the source.");this.source.length!==t.length&&(this.source=new Uint8ClampedArray(t.length));let i=this.source;i.set(t);for(let a=0;a<r;a++)for(let o=0;o<e;o++){let l=(a*e+o)*4;if(!i[l+3])continue;let s=i[l],h=i[l+1],m=i[l+2],u=0,f=0,p=0,c=0;for(let b=-1;b<=1;b++){let g=a+b;if(!(g<0||g>=r))for(let M=-1;M<=1;M++){let v=o+M;if(v<0||v>=e)continue;let S=(g*e+v)*4;if(!i[S+3])continue;let k=Math.max(Math.abs(i[S]-s),Math.abs(i[S+1]-h),Math.abs(i[S+2]-m)),A=this.weights[k]*(M===0?1:.6)*(b===0?1:.6)*i[S+3];u+=i[S]*A,f+=i[S+1]*A,p+=i[S+2]*A,c+=A}}t[l]=s+(u/c-s)*this.amount,t[l+1]=h+(f/c-h)*this.amount,t[l+2]=m+(p/c-m)*this.amount}}};var zi=[{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}],Bi=8,Ie=(n,t,e,r)=>typeof n=="number"&&Number.isFinite(n)?Math.max(e,Math.min(r,n)):t;function Cr(n){if(!Array.isArray(n))return[];let t=[];for(let e of n.slice(0,64))if(!(!e||typeof e!="object"||!zi.some(r=>r.value===e.type))&&(t.push({type:e.type,enabled:e.enabled!==!1,amount:Ie(e.amount,.35,-1,1),x:Ie(e.x,.5,0,1),y:Ie(e.y,.5,0,1),radius:Ie(e.radius,.55,.05,2),angle:Ie(e.angle,0,-180,180),frequency:Ie(e.frequency,5,1,24)}),t.length===Bi))break;return t}var Tr=Math.PI*2,Qr=(n,t)=>{let e=Math.imul(n,374761393)^Math.imul(t,668265263);return e=Math.imul(e^e>>>13,1274126177),((e^e>>>16)>>>0)/4294967296},$e=class{constructor(t=[],e="clamp"){this.warps=[];this.signature="";this.geometry="";this.coordinates=new Float32Array(0);this.output=new Uint8ClampedArray(0);this.sampled=[0,0,0,0];this.edge="clamp";this.configure(t,e)}configure(t=[],e="clamp"){let r=Cr(t).filter(a=>a.enabled&&a.amount!==0),i=JSON.stringify(r);this.edge=e==="transparent"?"transparent":"clamp",i!==this.signature&&(this.signature=i,this.geometry="",this.warps=r.map(a=>({...a,cos:Math.cos(a.angle*Math.PI/180),sin:Math.sin(a.angle*Math.PI/180)})),r.length||this.clear())}get active(){return this.warps.length>0}apply(t,e,r,i=e/r){if(!this.active)return t;if(!Number.isInteger(e)||!Number.isInteger(r)||e<1||r<1||e*r*4!==t.length||!Number.isFinite(i)||i<=0)throw new Error("Warp dimensions do not match the source.");let a=`${e}:${r}:${i}`;if(a!==this.geometry){this.coordinates.length!==e*r*2&&(this.coordinates=new Float32Array(e*r*2));let s=Math.max(1,i),h=Math.max(1,1/i);for(let m=0;m<r;m++)for(let u=0;u<e;u++){let f=(u+.5)/e,p=(m+.5)/r;for(let b=this.warps.length-1;b>=0;b--){let g=this.warps[b],M=(f-g.x)*s/g.radius,v=(p-g.y)*h/g.radius,S=M*M+v*v;if(S>=1)continue;let k=Math.sqrt(S),A=(1-S)*(1-S),H=g.amount,N=M,C=v;if(g.type==="twirl"||g.type==="zigzag"){let I=g.type==="twirl"?-H*Tr*A:H*.65*(2/Math.PI*Math.asin(Math.sin(k*Tr*g.frequency)))*A,y=Math.cos(I),z=Math.sin(I);N=M*y-v*z,C=M*z+v*y}else if(g.type==="pinch"){let I=Math.exp(H*2*A);N=M*I,C=v*I}else if(g.type==="sphere"&&k>0){let I=Math.asin(k)*2/Math.PI,y=1+H*A*(I/k-1);N=M*y,C=v*y}else if(g.type==="ripple"&&k>0){let I=1+H*.12*Math.sin(k*Tr*g.frequency)*A/k;N=M*I,C=v*I}else if(g.type==="shear"){let I=-M*g.sin+v*g.cos;N-=H*I*.9*A*g.cos,C-=H*I*.9*A*g.sin}else if(g.type==="smudge")N-=H*.65*A*g.cos,C-=H*.65*A*g.sin;else if(g.type==="polar"){let I=M*g.cos+v*g.sin,y=-M*g.sin+v*g.cos,z=Math.atan2(y,I),q=H>0?z/Math.PI:Math.cos(I*Math.PI)*(y+1)/2,Y=H>0?k*2-1:Math.sin(I*Math.PI)*(y+1)/2,x=q*g.cos-Y*g.sin,D=q*g.sin+Y*g.cos;N+=(x-M)*Math.abs(H)*A,C+=(D-v)*Math.abs(H)*A}else if(g.type==="fragment"){let I=Math.floor((M*g.cos+v*g.sin)*g.frequency),y=Math.floor((-M*g.sin+v*g.cos)*g.frequency),z=(Qr(I,y)-.5)*H*.5*A,q=(Qr(y+71,I-31)-.5)*H*.5*A;N+=z*g.cos-q*g.sin,C+=z*g.sin+q*g.cos}f=g.x+N*g.radius/s,p=g.y+C*g.radius/h}let c=(m*e+u)*2;this.coordinates[c]=f*e-.5,this.coordinates[c+1]=p*r-.5}this.geometry=a}this.output.length!==t.length&&(this.output=new Uint8ClampedArray(t.length));let o=t===this.output?t.slice():t,l=this.edge==="transparent"?Vr:Ce;for(let s=0,h=0;s<t.length;s+=4,h+=2){l(o,e,r,this.coordinates[h],this.coordinates[h+1],this.sampled);for(let m=0;m<4;m++)this.output[s+m]=this.sampled[m]}return this.output}clear(){this.coordinates=new Float32Array(0),this.output=new Uint8ClampedArray(0),this.geometry=""}};var Ir=["stipple","engraving","crosshatch","woodblock","risograph","pointillism"];function qe(n){return Ir.includes(n)}var tr={density:1,weight:1,angle:-35,roughness:.35,invert:!1,secondaryInk:"#ec6752",registration:.2,seed:7};function er(n){let t=n&&typeof n=="object"&&!Array.isArray(n)?n:{},e=(r,i,a)=>{let o=t[r];return typeof o=="number"&&Number.isFinite(o)?Math.max(i,Math.min(a,o)):tr[r]};return{density:e("density",0,2),weight:e("weight",.25,2),angle:e("angle",-180,180),roughness:e("roughness",0,1),invert:t.invert===!0,secondaryInk:typeof t.secondaryInk=="string"&&/^#[\\da-f]{6}$/i.test(t.secondaryInk)?t.secondaryInk:tr.secondaryInk,registration:e("registration",0,1),seed:Math.round(e("seed",0,65535))}}var Pe=Math.PI*2,$r=n=>Math.max(0,Math.min(1,n)),ir=.1,ti=n=>Math.max(-ir,Math.min(1+ir,n)),Gi=Float32Array.from({length:2048},(n,t)=>Math.sin(t/2048*Pe)),ei=n=>Gi[Math.floor(n*(2048/Pe))&2047];function rr(n,t,e){let r=Math.imul(n,374761393)^Math.imul(t,668265263)^Math.imul(e,1442695041);return r=Math.imul(r^r>>>13,1274126177),((r^r>>>16)>>>0)/4294967296}function Pr(n){let t=er(n),{density:e,weight:r,angle:i,roughness:a,invert:o,secondaryInk:l,registration:s,seed:h}=t,m=i*Math.PI/180,f=[m,m+Math.PI/2,m+Math.PI/4].map(b=>[Math.cos(b),Math.sin(b)]),p=new Float32Array(6);function c(b,g,M,v,S,k,A,H,N=!1){if(A<=0)return;let[C,I]=f[H],y=-I,z=C,q=y*(g+.5)+z*(M+.5),Y=(Math.abs(y)+Math.abs(z))*.5,x=N?1:.5,D=Math.ceil((q-Y)/x),V=Math.floor((q+Y)/x),Z=Math.min(x*.94,x*.72*A*r);b.lineWidth=k*Z,b.beginPath();for(let T=D;T<=V;T++){let O=T*x-q,w=.5+y*O,F=.5+z*O,W=-2,P=2;if(Math.abs(C)>1e-8){let U=-w/C,E=(1-w)/C;W=Math.max(W,Math.min(U,E)),P=Math.min(P,Math.max(U,E))}else if(w<0||w>1)continue;if(Math.abs(I)>1e-8){let U=-F/I,E=(1-F)/I;W=Math.max(W,Math.min(U,E)),P=Math.min(P,Math.max(U,E))}else if(F<0||F>1)continue;if(!(P<=W))if(N&&(W-=ir,P+=ir),!N)b.moveTo(v+(w+C*W)*k,S+(F+I*W)*k),b.lineTo(v+(w+C*P)*k,S+(F+I*P)*k);else{for(let U=0;U<6;U++){let E=W+(P-W)*U/5,B=C*(g+w+C*E)+I*(M+F+I*E);p[U]=ei(B*5.3+T*1.9+h)*.5+ei(B*13.1+T)*.25}for(let U=0;U<2;U++)for(let E=0;E<6;E++){let B=W+(P-W)*(U?5-E:E)/5,nt=p[U?5-E:E],Q=Z*.5*(1+a*nt*.5)*(U?-1:1),ct=v+ti(w+C*B+y*Q)*k,ft=S+ti(F+I*B+z*Q)*k;!U&&!E?b.moveTo(ct,ft):b.lineTo(ct,ft)}b.closePath()}}N?b.fill():b.stroke()}return{settings:t,paint(b,g,M,v,S,k,A,H,N,C,I,y,z){let q=$r((o?1-H:H)*e);if(q<=0||b.globalAlpha<=0)return;b.fillStyle=N,b.strokeStyle=N;let Y=rr(M,v,h);if(g==="engraving"||g==="crosshatch"||g==="woodblock"){let x=q*(1-a*Y*.3);g==="woodblock"?c(b,M,v,S,k,A,Math.ceil(x*5)/5,0,!0):(c(b,M,v,S,k,A,x,0),g==="crosshatch"&&(c(b,M,v,S,k,A,Math.max(0,x*1.5-.3),1),c(b,M,v,S,k,A,Math.max(0,x*2-1.2),2)))}else if(g==="risograph"){let x=z==="source"?$r(.5+(C-y)/510):.5,D=s*.38*A,V=A*Math.min(.48,.44*Math.sqrt(q)*r);b.beginPath(),b.arc(S+A*.5,k+A*.5,V*Math.sqrt(.35+(1-x)*.65),0,Pe),b.fill(),b.globalCompositeOperation="multiply",b.fillStyle=l;let Z=1-a*rr(M,v,h+13)*.3;b.beginPath(),b.arc(S+A*.5+D*f[0][0],k+A*.5+D*f[0][1],V*Math.sqrt(.3+x*.7)*Z,0,Pe),b.fill(),b.globalCompositeOperation="source-over"}else{let x=b.fillEllipse;g==="stipple"&&b.beginPath();for(let D=0;D<4;D++){let V=rr(M*2+D%2,v*2+(D>>1),h),Z=rr(M,v,h+D*11+1),T=S+((D%2+.5)/2+(V-.5)*a*.28)*A,O=k+(((D>>1)+.5)/2+(Z-.5)*a*.28)*A,w=Math.min(T-S,S+A-T,O-k,k+A-O,A*Math.min(.245,.21*r*Math.sqrt(q)*(1-a*V*.35)));if(g==="stipple")b.moveTo(T+w,O),b.arc(T,O,w,0,Pe);else{let F=(V-.5)*a*64;if(x&&z!=="accent"){let W=Math.round(C+F);x(T,O,w,w*.64,V*Math.PI,W,z==="source"?Math.round(I-F*.4):W,z==="source"?Math.round(y-F):W);continue}z==="source"?b.fillStyle=`rgb(${Math.round(C+F)},${Math.round(I-F*.4)},${Math.round(y-F)})`:z==="gray"?b.fillStyle=`rgb(${Math.round(C+F)},${Math.round(C+F)},${Math.round(C+F)})`:b.fillStyle=N,b.beginPath(),b.ellipse(T,O,w,w*.64,V*Math.PI,0,Pe),b.fill()}}g==="stipple"&&b.fill()}}}}var Xi=new Set(["none","floyd-steinberg","atkinson","stucki","sierra","sierra-lite","burkes","jarvis"]);function ri(n){return n.style==="dither"&&(n.dither.motion==="shimmer"||n.dither.motion==="drift"&&n.dither.amount>0&&!Xi.has(n.dither.algorithm))}function ii(n){return n.motion.type!=="none"&&(n.motion.amount??1)>0}var ni={caustics:"sheen",grain:"shimmer",trace:"relight",tidal:"current",weave:"current",breeze:"current",reform:"develop",print:"develop",unfold:"develop"},Dr=[{value:"none",mode:"none",group:"Still",label:"Off",description:"Keep the image still. Hover stays available."},{value:"relight",mode:"relight",group:"Light",label:"Relight",description:"A key light circles the subject and models its own relief, like moving a lamp around a sculpture."},{value:"sheen",mode:"sheen",group:"Light",label:"Specular sweep",description:"One slow pass of light glances across the highlights and follows their form, then rests."},{value:"glow",mode:"glow",group:"Light",label:"Highlight bloom",description:"The brightest areas breathe a soft halo into their surroundings. Shadows stay deep."},{value:"shimmer",mode:"shimmer",group:"Light",label:"Glints",description:"Sparse glints on bright fine detail, like light on water, metal or an eye. Everything else holds still."},{value:"parallax",mode:"parallax",group:"Depth",label:"Parallax",description:"A slow camera drift: the subject moves against its background, read from the photo\\u2019s own depth cues."},{value:"push",mode:"push",group:"Depth",label:"Slow push",description:"A gentle push toward the subject and back, with nearer areas moving slightly more."},{value:"focus",mode:"focus",group:"Depth",label:"Focus pull",description:"Focus racks from the subject to the background and back; the characters soften out of focus."},{value:"mist",mode:"mist",group:"Atmosphere",label:"Mist",description:"Soft mist drifts through the distance and plain areas, leaving the subject clear."},{value:"current",mode:"current",group:"Atmosphere",label:"Drift",description:"Water swells and glints, falls stream down, sky and clouds drift slowly, like a cinemagraph. Subjects and buildings hold still."},{value:"develop",mode:"develop",group:"Reveal",label:"Develop",description:"The image holds, fades, then develops back in from its highlights to its shadows, like a print in the tray."}];function oi(n){let t=n&&Object.prototype.hasOwnProperty.call(ni,n)?ni[n]:n;return Dr.find(e=>e.value===t||e.mode===t)?.mode??"none"}var ze=n=>Math.max(0,Math.min(1,n)),Lt=(n,t,e)=>{let r=ze((e-n)/(t-n));return r*r*(3-2*r)},nr=(n,t)=>{let e=52.9829189*((n*.06711056+t*.00583715)%1);return e-Math.floor(e)};function Lr(n,t,e,r,i,a=.5,o,l=0){if(i[0]=i[1]=i[2]=0,i[3]=1,n==="none")return i;a=ze(a);let s=o?o[l]:a,h=o?o[l+1]:.5+.5*ze(1-Math.hypot(t-.5,e-.55)*2),m=o?o[l+2]:Lt(.55,1,a)**2,u=o?o[l+3]:.5,f=o?o[l+4]:0,p=o?o[l+5]:0,c=r*Math.PI/6,b=(r%12+12)%12,g=Lt(0,.12,Math.min(t,1-t,e,1-e));if(n==="relight"){let M=c+.6,v=Math.cos(M),S=Math.sin(M),k=Math.max(-1,Math.min(1,f*v+p*S))+(v*(t-.5)+S*(e-.5))*.35;i[2]=k*.2*(.3+.7*Lt(.04,.3,s)*(1-.6*Lt(.82,1,a)))}else if(n==="sheen"){let M=-.35+1.9*Lt(0,8,b),v=(t*.75+e*.45)/1.2+(f*.75+p*.45)*.05,S=Math.exp(-(((v-M)/.12)**2));i[2]=S*Lt(.3,.8,s)*(1-.5*Lt(.9,1,a))*.45}else if(n==="glow"){let M=.5-.5*Math.cos(c),v=1-.8*M;i[2]=.2*Lt(v-.3,v+.02,m)*Math.sqrt(m)*(1-.65*a)+.05*M*Lt(.6,.95,a)}else if(n==="shimmer"){let M=nr(Math.floor(t*160),Math.floor(e*100))*Math.PI*2,v=Math.pow(.5+.5*Math.cos(c*2+M),28);i[2]=v*Lt(.5,.88,a)*(.35+.65*Lt(.1,.55,u))*.42}else if(n==="parallax"){let M=h-.45;i[0]=M*16*Math.sin(c)*g,i[1]=M*7*Math.sin(c*2)*g}else if(n==="push"){let M=.045*(.5-.5*Math.cos(c))*(.7+.6*h)*960,v=o?o[l+6]:.5,S=o?o[l+7]:.5;i[0]=(t-v)*M,i[1]=(e-S)*M}else if(n==="focus"){let M=Math.sin(c),v=M*M*Lt(.35,.85,M>=0?1-h:h);i[2]=(s-a)*v*.75}else if(n==="mist"){let M=Math.pow(1-h,1.5)*(1-.6*u),v=Math.sin(t*4.1-c+Math.sin(e*3.3+c)*.9)*.5+Math.sin(t*7.3+e*2.1-c*2+Math.sin(t*2.7-e*5.1+c)*1.1)*.3+Math.sin(e*5.7-t*1.9+c)*.2;i[2]=Lt(-.3,.9,v)*M*.16*(1-.55*a)}else if(n==="current"){let M=o?.[l+8]??0,v=o?.[l+9]??0,S=o?.[l+10]??0,k=Lt(0,.06,Math.min(t,1-t,e,1-e)),A=o?0:(1-.4*u)*(1-.8*h)*g,H=q=>e*14-q+Math.sin(t*3+q)*1.5,N=q=>e*16+t*2-q,C=q=>e*29-t*3-q*2,I=q=>t*1.7+e*2.3-q,y=q=>e*26+Math.sin(t*40)*1.5-q*2;i[0]=(Math.sin(H(c))-Math.sin(H(0))+(Math.sin(t*5-e*3+c)-Math.sin(t*5-e*3))*.43)*7*A+((Math.sin(N(c))-Math.sin(N(0)))*3.5+(Math.sin(C(c))-Math.sin(C(0)))*1.5)*M*k+(Math.sin(I(c))-Math.sin(I(0)))*5*v*k,i[1]=(Math.sin(t*11+c)-Math.sin(t*11))*2*A+(Math.cos(N(c))-Math.cos(N(0)))*.8*M*k+(Math.sin(y(c))-Math.sin(y(0)))*12*S*k;let z=Math.pow(.5+.5*Math.cos(c*2+t*9-e*4+nr(Math.floor(t*160),Math.floor(e*100))*6.2831853),24)-Math.pow(.5+.5*Math.cos(t*9-e*4+nr(Math.floor(t*160),Math.floor(e*100))*6.2831853),24);i[2]=(Math.cos(H(c))-Math.cos(H(0)))*.03*A+(z*Lt(.5,.85,a)*.3+(Math.cos(N(c))-Math.cos(N(0)))*.025)*M*k+(Math.cos(y(c))-Math.cos(y(0)))*.08*S*k}else if(n==="develop"){let M=Lt(7,8.5,b),v=ze((b-8.5)/3.5),S=b<8.5?1-M:Lt(0,1,(v*1.45-(1-a)+(nr(Math.floor(t*160),Math.floor(e*100))-.5)*.06)/.3);i[2]=-(1-S)*.3,i[3]=1-(1-S)*.9}return i}var si=n=>n==="relight"||n==="sheen"||n==="glow"||n==="shimmer"||n==="mist";function ai(n){let t=Math.floor(n),e=Math.max(0,Math.min(1,(n-t-.2)/.6));return t+e*e*(3-2*e)}function Ur(n,t,e,r,i,a){return a[0]=ai(Math.max(0,Math.min(r-1,t-n[0]/960*r))),a[1]=ai(Math.max(0,Math.min(i-1,e-n[1]/960*i))),a}function Hr(n,t){let e=Math.max(0,Math.min(2,Number.isFinite(t)?t:1));return n[0]*=e,n[1]*=e,n[2]*=e,n[3]=ze(1+(n[3]-1)*e),n}var Nr=n=>n==="subject"||n==="outside"?n:"all";function xt(n,t,e,r,i){if(!(i<1))for(let a=0;a<2;a++){for(let o=0;o<r;o++){let l=0,s=o*e;for(let h=-i;h<=i;h++)l+=n[s+Math.max(0,Math.min(e-1,h))];for(let h=0;h<e;h++)t[s+h]=l/(i*2+1),l+=n[s+Math.min(e-1,h+i+1)]-n[s+Math.max(0,h-i)]}for(let o=0;o<e;o++){let l=0;for(let s=-i;s<=i;s++)l+=t[Math.max(0,Math.min(r-1,s))*e+o];for(let s=0;s<r;s++)n[s*e+o]=l/(i*2+1),l+=t[Math.min(r-1,s+i+1)*e+o]-t[Math.max(0,s-i)*e+o]}}}var Or=new Float32Array(0);function ar(n,t,e,r,i){let a=t*e,o=i&&i.width===t&&i.height===e?i:{width:t,height:e,subject:new Float32Array(a),depth:new Float32Array(a),key:"none"},{subject:l,depth:s}=o,h=0;for(let c=0;c<a;c++)n[c*4+3]<250&&h++;let m=c=>(n[c*4]*.2126+n[c*4+1]*.7152+n[c*4+2]*.0722)/255,u="none",f=0;if(h>a*.01)u="alpha";else if(r)u="mask";else{let c=0,b=0,g=0,M=Math.max(1,Math.round(Math.min(t,e)*.03));for(let S=0;S<e;S++)for(let k=0;k<t;k++){if(k>=M&&S>=M&&k<t-M&&S<e-M)continue;let A=m(S*t+k);c+=A,b+=A*A,g++}f=c/Math.max(1,g),Math.sqrt(Math.max(0,b/Math.max(1,g)-f*f))<.07&&(u="ground")}for(let c=0;c<a;c++){let b=n[c*4+3]/255,g=m(c),M=1;if(u==="alpha")M=b;else if(u==="ground"){let v=Math.max(0,Math.min(1,(Math.abs(g-f)-.035)/.12));M=v*v*(3-2*v)}l[c]=M*(r?Math.max(0,Math.min(1,r[c])):1),s[c]=g*b}o.key=u,Or.length<a&&(Or=new Float32Array(a));let p=Or;return xt(l,p,t,e,Math.max(1,Math.round(Math.min(t,e)*.02))),xt(s,p,t,e,Math.max(1,Math.round(Math.min(t,e)*.035))),o}function li(n,t,e="ground"){return e==="none"?1:n==="subject"?t:n==="outside"?1-t:1}function hi(n,t,e,r){let i=n[t],a=n.width,o=n.height,l=Math.max(0,Math.min(a-1.001,e*(a-1))),s=Math.max(0,Math.min(o-1.001,r*(o-1))),h=Math.floor(l),m=Math.floor(s),u=l-h,f=s-m,p=m*a+h,c=Math.min(o-1,m+1)*a+h,b=h+1<a?1:0;return(i[p]*(1-u)+i[p+b]*u)*(1-f)+(i[c]*(1-u)+i[c+b]*u)*f}var ve=11,Gt=n=>Math.max(0,Math.min(1,n)),X=(n,t,e)=>{let r=Gt((e-n)/(t-n));return r*r*(3-2*r)};function Vt(n,t,e=256){let r=0;for(let l=0;l<n.length;l++)n[l]>r&&(r=n[l]);if(r<=0)return 0;let i=new Uint32Array(e);for(let l=0;l<n.length;l++)i[Math.min(e-1,Math.floor(Math.max(0,n[l])/r*e))]++;let a=0,o=n.length*t;for(let l=0;l<e;l++)if(a+=i[l],a>=o)return(l+1)/e*r;return r}var Yi=12e3,Br=class{constructor(t){this.n=t;this.arrays=[];this.next=0}take(t){this.next===this.arrays.length&&this.arrays.push(new Float32Array(this.n));let e=this.arrays[this.next++];return t?e.set(t):e.fill(0),e}reset(){this.next=0}},or=null;function Wi(n,t,e,r,i,a,o,l,s){let h=i*a,m=s.take(),u=x=>(ye(x,m,i,a,o),x),f=(x,D)=>{let V=s.take();for(let Z=0;Z<h;Z++)V[Z]=x[Z]*D[Z];return u(V)},p=u(s.take(t)),c=u(s.take(e)),b=u(s.take(r)),g=u(s.take(n)),M=f(t,t),v=f(t,e),S=f(t,r),k=f(e,e),A=f(e,r),H=f(r,r),N=f(t,n),C=f(e,n),I=f(r,n),y=s.take(),z=s.take(),q=s.take(),Y=s.take();for(let x=0;x<h;x++){let D=N[x]-p[x]*g[x],V=C[x]-c[x]*g[x],Z=I[x]-b[x]*g[x],T=M[x]-p[x]*p[x]+l,O=v[x]-p[x]*c[x],w=S[x]-p[x]*b[x],F=k[x]-c[x]*c[x]+l,W=A[x]-c[x]*b[x],P=H[x]-b[x]*b[x]+l,U=F*P-W*W,E=w*W-O*P,B=O*W-w*F,nt=T*P-w*w,Q=O*w-T*W,ct=T*F-O*O,ft=T*U+O*E+w*B,At=Math.abs(ft)>1e-12?1/ft:0;y[x]=(U*D+E*V+B*Z)*At,z[x]=(E*D+nt*V+Q*Z)*At,q[x]=(B*D+Q*V+ct*Z)*At,Y[x]=g[x]-y[x]*p[x]-z[x]*c[x]-q[x]*b[x]}u(y),u(z),u(q),u(Y);for(let x=0;x<h;x++)n[x]=y[x]*t[x]+z[x]*e[x]+q[x]*r[x]+Y[x]}function ye(n,t,e,r,i){let a=i*2+1;for(let o=0;o<r;o++){let l=o*e,s=0;for(let h=-i;h<=i;h++)s+=n[l+Math.max(0,Math.min(e-1,h))];for(let h=0;h<e;h++)t[l+h]=s/a,s+=n[l+Math.min(e-1,h+i+1)]-n[l+Math.max(0,h-i)]}for(let o=0;o<e;o++){let l=0;for(let s=-i;s<=i;s++)l+=t[Math.max(0,Math.min(r-1,s))*e+o];for(let s=0;s<r;s++)n[s*e+o]=l/a,l+=t[Math.min(r-1,s+i+1)*e+o]-t[Math.max(0,s-i)*e+o]}}function qr(n,t,e,r,i,a,o){let l=e*r,s=o.take(),h=o.take(t),m=o.take(n),u=o.take(),f=o.take();for(let p=0;p<l;p++)u[p]=t[p]*t[p],f[p]=t[p]*n[p];ye(h,s,e,r,i),ye(m,s,e,r,i),ye(u,s,e,r,i),ye(f,s,e,r,i);for(let p=0;p<l;p++){let c=(f[p]-h[p]*m[p])/(u[p]-h[p]*h[p]+a);u[p]=c,f[p]=m[p]-c*h[p]}ye(u,s,e,r,i),ye(f,s,e,r,i);for(let p=0;p<l;p++)n[p]=u[p]*t[p]+f[p]}function zr(n,t,e,r,i,a=2){for(let o=0;o<a;o++){for(let l=0;l<r;l++)for(let s=0;s<e;s++){let h=l*e+s,m=n[h];s>0&&(m=Math.max(m,Math.min(t[h],n[h-1]*i))),l>0&&(m=Math.max(m,Math.min(t[h],n[h-e]*i),s>0?Math.min(t[h],n[h-e-1]*i):0,s<e-1?Math.min(t[h],n[h-e+1]*i):0)),n[h]=m}for(let l=r-1;l>=0;l--)for(let s=e-1;s>=0;s--){let h=l*e+s,m=n[h];s<e-1&&(m=Math.max(m,Math.min(t[h],n[h+1]*i))),l<r-1&&(m=Math.max(m,Math.min(t[h],n[h+e]*i),s>0?Math.min(t[h],n[h+e-1]*i):0,s<e-1?Math.min(t[h],n[h+e+1]*i):0)),n[h]=m}}}function sr(n,t,e,r,i){for(let a=0;a<r;a++)for(let o=0;o<e;o++){let l=1;for(let s=Math.max(0,o-i);s<=Math.min(e-1,o+i);s++)l=Math.min(l,n[a*e+s]);t[a*e+o]=l}for(let a=0;a<r;a++)for(let o=0;o<e;o++){let l=1;for(let s=Math.max(0,a-i);s<=Math.min(r-1,a+i);s++)l=Math.min(l,t[s*e+o]);n[a*e+o]=l}}function ji(n,t,e,r,i){let a=e*r,o=Math.min(e,r),l=i.take(),s=i.take(),h=i.take(),m=i.take(),u=i.take();for(let d=0;d<a;d++){let G=n[d*4+3]/255;u[d]=G,l[d]=t[d*4]/255*G,s[d]=t[d*4+1]/255*G,h[d]=t[d*4+2]/255*G,m[d]=(n[d*4]*.299+n[d*4+1]*.587+n[d*4+2]*.114)/255*G}let f=i.take(),p=(d,G)=>{let R=i.take(d);return xt(R,f,e,r,G),R},c=Math.max(2,Math.round(o*.04)),b=Math.max(c+2,Math.round(o*.12)),g=Math.max(2,Math.round(o*.05)),M=p(m,1),v=p(m,c),S=p(m,b),k=i.take(),A=i.take(),H=i.take(),N=i.take(),C=i.take();for(let d=0;d<r;d++)for(let G=0;G<e;G++){let R=d*e+G;k[R]=Math.abs(m[R]-M[R]),A[R]=Math.abs(M[R]-v[R]),H[R]=Math.abs(v[R]-S[R]),N[R]=Math.abs(m[d*e+Math.min(e-1,G+1)]-m[d*e+Math.max(0,G-1)]),C[R]=Math.abs(m[Math.min(r-1,d+1)*e+G]-m[Math.max(0,d-1)*e+G])}xt(k,f,e,r,g),xt(A,f,e,r,g),xt(H,f,e,r,g),xt(N,f,e,r,2),xt(C,f,e,r,2);let I=Math.max(.01,Vt(k,.9)+Vt(A,.9)),y=p(l,1),z=p(s,1),q=p(h,1),Y=i.take(),x=i.take(),D=i.take(),V=0;for(let d=0;d<a;d++){let G=y[d],R=z[d],_=q[d],j=Math.max(G,R,_),pt=Math.min(G,R,_),Mt=j-pt;D[d]=j,x[d]=j>.001?Mt/j:0,V+=Mt;let Ft=0;Mt>1e-4&&(Ft=j===G?((R-_)/Mt+6)%6:j===R?(_-G)/Mt+2:(G-R)/Mt+4),Y[d]=Ft*60}let Z=X(.02,.07,V/a),T=Math.max(2,Math.round(r*.06)),O=new Float32Array(r);for(let d=0;d<r;d++){let G=0;for(let R=0;R<e;R++)G+=k[d*e+R]+A[d*e+R];O[d]=G/e}let w=.5,F=0;for(let d=Math.max(T,Math.round(r*.12));d<=Math.min(r-T,Math.round(r*.88));d++){let G=0,R=0,_=0,j=0;for(let tt=0;tt<e;tt++){let dt=0,lt=0,qt=0,Rt=0,gt=0,Ut=0;for(let ht=1;ht<=T;ht++){let rt=(d-ht)*e+tt,St=(d+ht-1)*e+tt;dt+=y[rt],lt+=z[rt],qt+=q[rt],Rt+=y[St],gt+=z[St],Ut+=q[St]}let bt=(Math.abs(dt-Rt)+Math.abs(lt-gt)+Math.abs(qt-Ut))/T;G+=bt,R+=bt>.12?1:0}let pt=Math.max(2,Math.round(r*.15)),Mt=Math.max(0,d-pt),Ft=Math.min(r,d+pt);for(let tt=Mt;tt<d;tt++)_+=O[tt];for(let tt=d;tt<Ft;tt++)j+=O[tt];_/=d-Mt,j/=Ft-d;let K=X(-.05,.3,(j-_)/(j+_+1e-4)),J=X(.08,.35,G/e)*(R/e)*K;J>F&&(F=J,w=d/r)}let W=X(.15,.45,F),P=i.take(),U=i.take(),E=i.take();for(let d=0;d<a;d++)P[d]=Math.min(l[d],s[d],h[d]);sr(P,f,e,r,1),xt(P,f,e,r,c);for(let d=0;d<a;d++)U[d]=A[d]+H[d];let B=0,nt=0,Q=0;for(let d=0;d<a;d++)B+=y[d],nt+=z[d],Q+=q[d];B/=a,nt/=a,Q/=a;let ct=p(y,c),ft=p(z,c),At=p(q,c),Tt=p(y,b),mt=p(z,b),se=p(q,b);for(let d=0;d<a;d++){let G=Math.hypot(ct[d]-B,ft[d]-nt,At[d]-Q),R=Math.hypot(ct[d]-Tt[d],ft[d]-mt[d],At[d]-se[d]);E[d]=(G+R*1.5)*(.4+.6*x[d]*Z+.4*(1-Z))}let ot=i.take(),te=i.take(),Ae=i.take(),yt=i.take(),le=i.take(),ee=i.take(),Ct=i.take(),re=i.take(),Zt=i.take(),Le=i.take();for(let d=0;d<r;d++)for(let G=0;G<e;G++)Le[d*e+G]=Math.abs(m[Math.min(r-1,d+1)*e+G]-m[Math.max(0,d-1)*e+G]);xt(Le,f,e,r,1);for(let d=0;d<r;d++)for(let G=0;G<e;G++){let R=d*e+G,_=(d+.5)/r,j=Y[R],pt=x[R]*Z,Mt=D[R],Ft=k[R]+A[R],K=X(175,200,j)*(1-X(250,275,j))*X(.08,.25,pt),J=(1-X(45,65,j)+X(290,330,j))*X(.2,.45,pt)*X(.3,.55,Mt),tt=(1-X(.15,.35,pt))*X(.45,.7,Mt)*W,dt=(1-X(.08,.2,Mt))*W,lt=W>.3?1-X(w,w+.1,_):1-X(.4,.8,_),qt=1-X(.02,.06,Ft),Rt=1-X(.03,.09,Ft);te[R]=Math.max(K*qt,dt*.7*(1-X(.008,.025,Ft)),J*Rt*.9)*lt,Ae[R]=Math.max(te[R],tt*qt*lt),ot[R]=d===0?te[R]:0,yt[R]=X(150,172,j)*(1-X(232,250,j))*X(.25,.45,pt),Ct[R]=X(1.3,2.2,(N[R]+.004)/(C[R]+.004))*X(.35,.55,M[R])*(1-X(.1,.18,x[R]*Z))*X(.025,.07,Ft)*X(.025,.045,Le[R]);let gt=1-X(.18,.4,pt),Ut=X(.55,.8,Mt)*X(.05,.12,Ft);le[R]=Math.max(yt[R],gt*.85,Ut*.8)}zr(ot,te,e,r,.995,1),zr(ot,Ae,e,r,.8,1);let We=0;for(let d=0;d<a;d++)We+=ot[d];let Ue=We>a*.04&&W>.3;if(Ue)for(let d=0;d<r;d++)for(let G=0;G<e;G++)yt[d*e+G]*=X(w,w+.05,(d+.5)/r);if(Ue){let d=i.take(),G=i.take(),R=i.take();for(let K=0;K<a;K++)d[K]=ct[K]*.299+ft[K]*.587+At[K]*.114;for(let K=0;K<r;K++)for(let J=0;J<e;J++)G[K*e+J]=M[Math.min(r-1,K+1)*e+J]-M[Math.max(0,K-1)*e+J];let _=new Uint8Array(a);for(let K=1;K<r-1;K++)for(let J=0;J<e;J++){let tt=Math.abs(G[K*e+J]),dt=tt>.03;for(let lt=-3;lt<=3&&dt;lt++)lt&&K+lt>=0&&K+lt<r&&Math.abs(G[(K+lt)*e+J])>tt&&(dt=!1);_[K*e+J]=dt?1:0}let j=(K,J,tt,dt=!0)=>{let lt=ct[J]+ft[J]+At[J]+.05,qt=ct[tt]+ft[tt]+At[tt]+.05,Rt=Math.abs(ct[J]/lt-ct[tt]/qt)+Math.abs(ft[J]/lt-ft[tt]/qt)+Math.abs(At[J]/lt-At[tt]/qt),gt=Math.min(Math.abs(Y[J]-Y[tt]),360-Math.abs(Y[J]-Y[tt])),Ut=Math.max(1-X(.1,.25,Rt),(1-X(15,35,gt))*X(.15,.3,Math.min(x[J],x[tt]))),bt=Math.max(X(2,3,(C[J]+.004)/(N[J]+.004))*X(.015,.04,k[J]+A[J])*X(.4,.55,k[J]/(k[J]+A[J]+1e-4)),1-X(.12,.25,d[J]));return Ut*(dt?bt:1)*(1-X(d[tt]*.82+.02,d[tt]*1.02+.05,d[J]))},pt=0,Mt=0;for(let K=Math.max(3,Math.round(r*Math.max(.25,w)));K<Math.round(r*.88);K++){let J=0;for(let dt=0;dt<e;dt++)(_[(K-1)*e+dt]||_[K*e+dt]||_[(K+1)*e+dt])&&J++;if(J<e*.5)continue;let tt=0;for(let dt=K+1;dt<Math.min(r,2*K);dt++)for(let lt=0;lt<e;lt++)tt+=j(K,dt*e+lt,(2*K-dt)*e+lt);tt>Mt&&(Mt=tt,pt=K)}let Ft=X(.05,.1,Mt/a);if(Ft>0)for(let K=pt+1;K<Math.min(r,2*pt);K++)for(let J=0;J<e;J++){let tt=K*e+J;re[tt]=j(pt,tt,(2*pt-K)*e+J)*Ft,Zt[tt]=j(pt,tt,(2*pt-K)*e+J,!1)*Ft,R[tt]=re[tt]}xt(R,f,e,r,1);for(let K=0;K<a;K++)re[K]=Math.max(re[K],R[K]),yt[K]=Math.max(yt[K],re[K])}let je=p(yt,b);for(let d=0;d<a;d++)yt[d]*=X(.15,.35,je[d]);let wt=p(yt,c);for(let d=0;d<a;d++){yt[d]*=1-te[d]*.8;let G=Math.min(Math.abs(Y[d]-200),360-Math.abs(Y[d]-200));ee[d]=X(.28,.45,x[d]*Z)*X(55,80,G)*(1-X(.3,.6,Zt[d]))}let Nt=p(ee,c);for(let d=0;d<a;d++)ee[d]=Math.max(ee[d]*(1-(1-X(.15,.3,Nt[d]))*X(.55,.7,D[d])*X(.5,.65,x[d])),1-u[d]),le[d]=Math.min(Math.max(le[d],Zt[d]*.9),Math.max(yt[d],X(.25,.6,wt[d])))*(1-ot[d])*(1-ee[d]);zr(yt,le,e,r,.97);let Xt=i.take(Ct),jt=Math.max(2,Math.round(r*.12));for(let d=0;d<e;d++){let G=0;for(let R=-jt;R<=jt;R++)G+=Ct[Math.max(0,Math.min(r-1,R))*e+d];for(let R=0;R<r;R++)Xt[R*e+d]=G/(jt*2+1),G+=Ct[Math.min(r-1,R+jt+1)*e+d]-Ct[Math.max(0,R-jt)*e+d]}xt(Xt,f,e,r,1);for(let d=0;d<a;d++)Ct[d]=X(.2,.45,Xt[d])*X(.2,.5,Ct[d]+Xt[d]*.5)*(1-ot[d]);qr(ot,m,e,r,Math.max(2,Math.round(o*.04)),.002,i),qr(yt,m,e,r,Math.max(2,Math.round(o*.04)),.002,i),qr(Ct,m,e,r,Math.max(2,Math.round(o*.03)),.002,i),xt(ee,f,e,r,1);for(let d=0;d<a;d++)ot[d]=X(.3,.7,ot[d])*u[d],Ct[d]=X(.3,.7,Ct[d])*u[d]*(1-ot[d]),yt[d]=X(.3,.7,yt[d])*(1-ot[d])*(1-Ct[d])*(1-X(.15,.4,ee[d]));sr(ot,f,e,r,2),sr(yt,f,e,r,2),sr(Ct,f,e,r,1),xt(ot,f,e,r,1),xt(yt,f,e,r,1),xt(Ct,f,e,r,1);let He=1/Math.max(.02,Vt(E,.97)),kr=1/Math.max(.01,Vt(U,.9)),Ke=Vt(P,.97),Oe=Vt(P,.1),it=X(.06,.25,Ke-Oe),$=i.take();for(let d=0;d<r;d++)for(let G=0;G<e;G++){let R=d*e+G,_=(G+.5)/e,j=(d+.5)/r,pt=Math.max(ot[R],yt[R]),Mt=k[R]+A[R]+H[R],Ft=Gt(((k[R]+A[R]*.6)/(Mt+.004)-.25)/.55)*.6+Gt((k[R]+A[R])/I)*.4,K=X(.04,.35,Mt/I)*(1-pt),J=Gt((P[R]-Oe)/Math.max(.05,Ke-Oe))*.55+(1-Gt(U[R]*kr))*.25+Gt((q[R]-y[R])*2+.3)*.2*Z,tt=it*X(.12,.35,v[R])*(.4+.6*W),dt=j<w?.45:.45+.55*X(0,1,(j-w)/Math.max(.15,1-w)),lt=W*dt+(1-W)*(.5+(j-.5)*.4),qt=k[R]/(k[R]+A[R]+1e-4),Rt=X(.2,.7,(k[R]+A[R])/I)*(.35+.65*W)*(1-pt),gt=1-Gt(Math.hypot((_-.5)*1.2,j-.52)*1.5),Ut=Gt(E[R]*He)*(.55+.45*gt),bt=.3*K,ht=.25*tt,rt=.12+.45*W,St=.12*Rt,Kt=.35*(1-.4*W)*(1-pt);$[R]=(bt*Ft+ht*(1-J)+rt*lt+St*Gt(1.6-qt*1.6)+Kt*Ut+.08*.5)/(bt+ht+rt+St+Kt+.08)*(1-.85*ot[R])*(1-.45*yt[R]*(1-W))}let ie=ar(n,e,r);if(ie.key!=="none")for(let d=0;d<a;d++)$[d]=ie.subject[d]*.7+$[d]*.3;return xt($,f,e,r,Math.max(1,Math.round(o*.03))),Wi($,y,z,q,e,r,Math.max(2,Math.round(o*.07)),.004,i),{depth:$,water:yt,sky:ot,falls:Ct}}function lr(n,t,e,r,i,a,o){if(t===a&&e===o)return n[i*a+r];let l=Math.max(0,Math.min(t-1,(r+.5)*t/a-.5)),s=Math.max(0,Math.min(e-1,(i+.5)*e/o-.5)),h=Math.min(t-2,Math.floor(l)),m=Math.min(e-2,Math.floor(s)),u=l-h,f=s-m;if(h<0||m<0)return n[Math.round(s)*t+Math.round(l)];let p=m*t+h,c=p+t;return(n[p]*(1-u)+n[p+1]*u)*(1-f)+(n[c]*(1-u)+n[c+1]*u)*f}function ci(n,t,e,r,i=n){let a=t*e,o=r?.length===a*ve?r:new Float32Array(a*ve);if(!a)return o;let l=Math.min(t,e),s=new Float32Array(a),h=new Float32Array(a),m=new Float32Array(a),u=new Float32Array(a),f=new Float32Array(a),p=new Float32Array(a);for(let T=0;T<a;T++){let O=n[T*4+3]/255;s[T]=(n[T*4]*.299+n[T*4+1]*.587+n[T*4+2]*.114)/255*O}h.set(s),xt(h,p,t,e,Math.max(1,Math.round(l*.012))),m.set(s),xt(m,p,t,e,Math.max(1,Math.round(l*.03)));for(let T=0;T<a;T++){u[T]=Math.abs(s[T]-h[T]);let O=Math.max(0,s[T]-.55)/.45;f[T]=O*O}xt(u,p,t,e,Math.max(1,Math.round(l*.02)));let c=1/Math.max(.02,Vt(u,.95));xt(f,p,t,e,Math.max(1,Math.round(l*.05)));let b=1/Math.max(.03,Vt(f,.98)),g=Math.max(1,Math.ceil(Math.sqrt(a/Yi))),M=Math.max(1,Math.floor(t/g)),v=Math.max(1,Math.floor(e/g)),S=M*v,k=n,A=i;if(g>1){let T=new Uint8ClampedArray(S*4),O=i===n?T:new Uint8ClampedArray(S*4);for(let w=0;w<v;w++)for(let F=0;F<M;F++){let W=[0,0,0,0,0,0,0];for(let E=w*g;E<(w+1)*g;E++)for(let B=F*g;B<(F+1)*g;B++){let nt=(E*t+B)*4;for(let Q=0;Q<4;Q++)W[Q]+=n[nt+Q];if(O!==T)for(let Q=0;Q<3;Q++)W[4+Q]+=i[nt+Q]}let P=(w*M+F)*4,U=g*g;for(let E=0;E<4;E++)T[P+E]=W[E]/U;if(O!==T){for(let E=0;E<3;E++)O[P+E]=W[4+E]/U;O[P+3]=T[P+3]}}k=T,A=O}or?.n!==S&&(or=new Br(S)),or.reset();let{depth:H,water:N,sky:C,falls:I}=ji(k,A,M,v,or),y=Vt(H,.03),z=Vt(H,.97),q=Math.max(.05,z-y),Y=0,x=0,D=0,V=new Float32Array(a);for(let T=0;T<e;T++)for(let O=0;O<t;O++){let w=T*t+O,F=w*ve,W=Gt((lr(H,M,v,O,T,t,e)-y)/q);o[F+1]=W,o[F+8]=Gt(lr(N,M,v,O,T,t,e)),o[F+9]=Gt(lr(C,M,v,O,T,t,e)),o[F+10]=Gt(lr(I,M,v,O,T,t,e));let P=W*W*W*(.25+s[w]);Y+=(O+.5)/t*P,x+=(T+.5)/e*P,D+=P,V[w]=Math.hypot(m[T*t+Math.min(t-1,O+1)]-m[T*t+Math.max(0,O-1)],m[Math.min(e-1,T+1)*t+O]-m[Math.max(0,T-1)*t+O])}Y=D>0?Math.max(.3,Math.min(.7,Y/D)):.5,x=D>0?Math.max(.3,Math.min(.7,x/D)):.5;let Z=1/Math.max(.004,Vt(V,.97));for(let T=0;T<e;T++)for(let O=0;O<t;O++){let w=T*t+O,F=w*ve,W=(m[T*t+Math.min(t-1,O+1)]-m[T*t+Math.max(0,O-1)])*Z,P=(m[Math.min(e-1,T+1)*t+O]-m[Math.max(0,T-1)*t+O])*Z;o[F]=m[w],o[F+2]=Math.min(1,f[w]*b),o[F+3]=Math.min(1,u[w]*c),o[F+4]=Math.max(-1,Math.min(1,-W)),o[F+5]=Math.max(-1,Math.min(1,-P)),o[F+6]=Y,o[F+7]=x}return o}var Ki=[{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."}],ui={rake:"silk"},xe={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}},mi={effect:"trail",strength:.55,radius:.2,decay:.5,scope:"all",edgeSafe:!1};function hr(n){if(typeof n=="string")return n in ui?ui[n]:Ki.some(t=>t.value===n)?n:void 0}var Vi=["ascii","blocks","braille","dots","lines","cross","diagonal","diamond","mixed","pixel","mosaic","lego","voxel","disco","dither","hex","led","cmyk",...Ir],_i=["none","bayer2","bayer4","bayer8","bayer16","floyd-steinberg","atkinson","stucki","sierra","sierra-lite","burkes","jarvis","halftone","lines","noise","vertical-lines","diagonal-lines","radial","blue-noise"],Ji=["source-over","multiply","screen","overlay","soft-light","hard-light","color-dodge","color-burn","hue","saturation","color","luminosity"],cr={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"]},Zi={version:1,aspectRatio:"original",style:"ascii",cellSize:6,charset:" .:-=+*#%@",colorMode:"accent",ink:"#e6e3da",print:{...tr},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}},_t=n=>n&&typeof n=="object"&&!Array.isArray(n)?n:{},et=(n,t,e,r)=>typeof n=="number"&&Number.isFinite(n)?Math.min(r,Math.max(e,n)):t,De=(n,t)=>typeof n=="string"&&/^#[\\da-f]{6}$/i.test(n)?n:t,Wt=(n,t,e)=>t.includes(n)?n:e;function ur(n={}){let t=_t(n),e=Zi;if(t.version!==void 0&&t.version!==1)throw new Error("Unsupported studio settings version. Update asciify-engine.");let r=_t(t.crop),i=_t(t.backdrop),a=_t(t.color),o=_t(t.dither),l=_t(t.mask),s=_t(t.effects),h=_t(t.motion),m=_t(t.hover),u={...e.effects};for(let p of["bloom","characterBloom","grain","dust","scanlines","crt","prism","rgbSplit","sharpen","vignette","glitch","pixelate","halftone"])u[p]=et(s[p],0,0,1);u.blur=et(s.blur,0,0,24),u.blurType=Wt(s.blurType,["gaussian","directional","radial","progressive"],e.effects.blurType),u.angle=et(s.angle,0,-180,180),u.focus=et(s.focus,.5,0,1);let f=2048;return{version:1,aspectRatio:Wt(t.aspectRatio,["original","16:9","9:16","1:1","4:3","3:4","21:9"],"original"),style:Wt(t.style,Vi,e.style),cellSize:et(t.cellSize,e.cellSize,qe(String(t.style))||["pixel","mosaic","lego","voxel","disco","dots","hex","led","cmyk"].includes(String(t.style))?1:3,60),charset:typeof t.charset=="string"&&t.charset.length?Array.from(t.charset).slice(0,128).join(""):e.charset,colorMode:Wt(t.colorMode,["accent","source","gray"],e.colorMode),ink:De(t.ink,e.ink),print:er(t.print),warps:Cr(t.warps),warpEdge:Wt(t.warpEdge,["clamp","transparent"],"clamp"),crop:{x:et(r.x,.5,0,1),y:et(r.y,.5,0,1),zoom:et(r.zoom,1,1,5),rotation:Math.round(et(r.rotation,0,-360,360)/90)*90},backdrop:{mode:Wt(i.mode,["solid","transparent","source","blurred","gradient"],e.backdrop.mode),color:De(i.color,e.backdrop.color),color2:De(i.color2,e.backdrop.color2),blur:et(i.blur,12,0,32),opacity:et(i.opacity,1,0,1)},color:{brightness:et(a.brightness,0,-1,1),contrast:et(a.contrast,1,0,3),saturation:et(a.saturation,1,0,3),grayscale:et(a.grayscale,0,0,1),tint:De(a.tint,e.color.tint),amount:et(a.amount,0,0,1),blend:Wt(a.blend,Ji,e.color.blend),blackPoint:et(a.blackPoint,0,0,.99),whitePoint:Math.max(et(a.blackPoint,0,0,.99)+1/255,et(a.whitePoint,1,1/255,1)),gamma:et(a.gamma,1,.25,4),shadows:et(a.shadows,0,-1,1),highlights:et(a.highlights,0,-1,1),curves:Jr(a.curves),denoise:et(a.denoise,0,0,1),levels:a.levels==="none"?"none":"auto"},dither:{algorithm:Wt(o.algorithm,_i,"none"),palette:typeof o.palette=="string"&&Object.prototype.hasOwnProperty.call(cr,o.palette)?o.palette:"mono",colors:Array.isArray(o.colors)&&o.colors.length>=2?o.colors.slice(0,32).map(p=>De(p,"#000000")):[...e.dither.colors],amount:et(o.amount,1,0,2),scale:Math.round(et(o.scale,2,1,12)),threshold:et(o.threshold,.5,0,1),motion:Wt(o.motion,["none","drift","shimmer"],"none"),speed:et(o.speed,1,.1,3),direction:et(o.direction,45,-180,180),colorSpace:Wt(o.colorSpace,["rgb","luminance"],"rgb")},mask:{enabled:l.enabled===!0,invert:l.invert===!0,shapes:Array.isArray(l.shapes)?l.shapes.slice(0,64).map(p=>{let c=_t(p),b=Wt(c.kind,["rectangle","ellipse","brush"],"rectangle"),g=b==="brush"&&Array.isArray(c.points)?c.points.slice(0,f).map(M=>Array.isArray(M)?[Math.round(et(M[0],0,0,1)*1e4)/1e4,Math.round(et(M[1],0,0,1)*1e4)/1e4]:[0,0]):[];return f-=g.length,{kind:b,x:et(c.x,0,0,1),y:et(c.y,0,0,1),width:et(c.width,.5,0,1),height:et(c.height,.5,0,1),size:et(c.size,.05,.005,.5),points:g}}):[]},lights:Array.isArray(t.lights)?t.lights.slice(0,4).map(p=>{let c=_t(p);return{x:et(c.x,.5,0,1),y:et(c.y,.5,0,1),radius:et(c.radius,.3,.02,1),intensity:et(c.intensity,.5,0,1),color:De(c.color,"#ffffff")}}):[],effects:u,motion:{type:Wt(typeof h.type=="string"?oi(h.type):h.type,Dr.map(p=>p.mode),"none"),speed:et(h.speed,1,.1,3),amount:et(h.amount,1,0,2)},hover:{effect:hr(m.effect)??mi.effect,strength:et(m.strength,xe.strength.default,xe.strength.min,xe.strength.max),radius:et(m.radius,xe.radius.default,xe.radius.min,xe.radius.max),edgeSafe:m.edgeSafe===!0,...Nr(m.scope)!=="all"&&{scope:Nr(m.scope)},...et(m.decay,.5,0,1)!==.5&&{decay:et(m.decay,.5,0,1)}}}}function fi(n,t,e,r,i){let a=Math.abs(i.rotation/90)%2===1,o=a?t:n,l=a?n:t,s=Math.max(e/o,r/l)*i.zoom;return{width:o*s,height:l*s,x:(e-o*s)*i.x,y:(r-l*s)*i.y,scale:s,rotated:a}}function di(n,t,e,r=12e3,i=1){let a=Math.max(2,Number.isFinite(n)?n:960),o=Math.max(2,Number.isFinite(t)?t:540),l=Math.max(1,Math.floor(Number.isFinite(r)?r:12e3)),s=Math.max(.01,Number.isFinite(i)?i:1),h=qe(e.style)||["dither","pixel","mosaic","lego","voxel","disco","dots","hex","led","cmyk"].includes(e.style)?1:1.65,m=Math.max(1,Math.ceil(Math.sqrt(a*o/(l*h))/s));for(;Math.ceil(a/(m*s))*Math.ceil(o/(m*s*h))>l;)m++;let u=e.style==="dither"?e.dither.scale:e.cellSize,f=Math.max(m,u)*s;return{cell:f,rowHeight:f*h,columns:Math.ceil(a/f),rows:Math.ceil(o/(f*h)),minimum:m,limited:u<m}}var pi="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",gi="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",Be=new Uint16Array(4096);for(let n=0;n<Be.length;n++)Be[n]=pi.indexOf(gi[n*2])<<6|pi.indexOf(gi[n*2+1]);var Xr=(n,t)=>{let e=Math.sin(n*127.1+t*311.7)*43758.5453;return e-Math.floor(e)};function Qi(n,t,e){let r=0;for(let i=1;i<e;i*=2){let a=(Math.floor(n/i)%2+2)%2,o=(Math.floor(t/i)%2+2)%2;r=r*4+[[0,2],[3,1]][o][a]}return(r+.5)/(e*e)-.5}var $i=new Map([2,4,8,16].map(n=>[n,Float64Array.from({length:n*n},(t,e)=>Qi(e%n,Math.floor(e/n),n))])),tn={"floyd-steinberg":[[1,0,7/16],[-1,1,3/16],[0,1,5/16],[1,1,1/16]],atkinson:[[1,0,.125],[2,0,.125],[-1,1,.125],[0,1,.125],[1,1,.125],[0,2,.125]],stucki:[[1,0,8/42],[2,0,4/42],[-2,1,2/42],[-1,1,4/42],[0,1,8/42],[1,1,4/42],[2,1,2/42],[-2,2,1/42],[-1,2,2/42],[0,2,4/42],[1,2,2/42],[2,2,1/42]],sierra:[[1,0,5/32],[2,0,3/32],[-2,1,2/32],[-1,1,4/32],[0,1,5/32],[1,1,4/32],[2,1,2/32],[-1,2,2/32],[0,2,3/32],[1,2,2/32]],"sierra-lite":[[1,0,.5],[-1,1,.25],[0,1,.25]],burkes:[[1,0,8/32],[2,0,4/32],[-2,1,2/32],[-1,1,4/32],[0,1,8/32],[1,1,4/32],[2,1,2/32]],jarvis:[[1,0,7/48],[2,0,5/48],[-2,1,3/48],[-1,1,5/48],[0,1,7/48],[1,1,5/48],[2,1,3/48],[-2,2,1/48],[-1,2,3/48],[0,2,5/48],[1,2,3/48],[2,2,1/48]]},Yr=n=>[parseInt(n.slice(1,3),16),parseInt(n.slice(3,5),16),parseInt(n.slice(5,7),16)];function bi(n,t,e,r,i=0){let{algorithm:a,amount:o,threshold:l}=r,s=a==="blue-noise",h=a.startsWith("bayer")?Number(a.slice(5)):0,m=$i.get(h),u=h-1,f=r.colorSpace==="luminance",c=(r.palette==="custom"?r.colors:cr[r.palette]??cr.mono).map(Yr),b=tn[a],g=b?new Float32Array(t*3*3):null,M=r.motion==="drift"?i*r.speed*3:0,v=(r.direction??45)*Math.PI/180,S=Math.round(Math.cos(v)*M),k=Math.round(Math.sin(v)*M),A=(C,I)=>(C%I+I)%I,H=c.map(C=>C[0]*.299+C[1]*.587+C[2]*.114),N=r.motion==="shimmer"?Math.sin(i*r.speed*2)*.15:0;for(let C=0;C<e;C++)for(let I=0;I<t;I++){let y=(C*t+I)*4,z=(C%3*t+I)*3;if(n[y+3]===0){g&&(g[z]=g[z+1]=g[z+2]=0);continue}let q=0,Y=s?(Be[(C-k&63)*64+(I-S&63)]+.5)/Be.length:0;m?q=m[(C-k&u)*h+(I-S&u)]:a==="noise"?q=Xr(I-S,C-k)-.5:a==="lines"?q=A(C-k,4)/3-.5:a==="vertical-lines"?q=A(I-S,4)/3-.5:a==="diagonal-lines"?q=A(I-S+C-k,4)/3-.5:a==="radial"?q=A(Math.hypot(I-t/2,C-e/2)-M,6)/6-.5:a==="halftone"&&(q=Math.hypot(A(I-S,6)-2.5,A(C-k,6)-2.5)/3.54-.5);let x=(q*o+N+(.5-l))*128,D=n[y]+x+(g?.[z]??0),V=n[y+1]+x+(g?.[z+1]??0),Z=n[y+2]+x+(g?.[z+2]??0),T=0,O=0,w=0;if(c.length){let F=1/0,W=1/0,P=0,U=0,E=D*.299+V*.587+Z*.114;for(let B=0;B<c.length;B++){let nt=c[B],Q=f?(E-H[B])**2:(D-nt[0])**2*.299+(V-nt[1])**2*.587+(Z-nt[2])**2*.114;Q<F?(s&&(W=F,U=P,P=B),F=Q,[T,O,w]=nt):s&&Q<W&&(W=Q,U=B)}if(s&&o>0&&Number.isFinite(W)){let B=c[U],nt=B[0]-T,Q=B[1]-O,ct=B[2]-w,ft=H[U]-H[P],At=f?ft*ft:nt*nt*.299+Q*Q*.587+ct*ct*.114,Tt=f?(E-H[P])*ft:(D-T)*nt*.299+(V-O)*Q*.587+(Z-w)*ct*.114,mt=At?Math.max(0,Math.min(1,Tt/At*o)):0;Y<mt&&([T,O,w]=B)}}else if(s){let F=Math.max(0,Math.min(1,.5+(Y-.5)*o));T=Math.floor(D/51+1-F)*51,O=Math.floor(V/51+1-F)*51,w=Math.floor(Z/51+1-F)*51}else T=Math.round(D/51)*51,O=Math.round(V/51)*51,w=Math.round(Z/51)*51;if(n[y]=T,n[y+1]=O,n[y+2]=w,g&&b){g[z]=g[z+1]=g[z+2]=0;for(let[F,W,P]of b){let U=I+F;if(U<0||U>=t||C+W>=e)continue;let E=((C+W)%3*t+U)*3;g[E]+=(D-T)*P*o,g[E+1]+=(V-O)*P*o,g[E+2]+=(Z-w)*P*o}}}}function Mi(n=()=>document.createElement("canvas")){let t=n(),e=t.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,antialias:!1,preserveDrawingBuffer:!0});if(!e)return null;let r=[],i=(f,p)=>{let c=e.createShader(f);if(r.push(c),e.shaderSource(c,p),e.compileShader(c),!e.getShaderParameter(c,e.COMPILE_STATUS))throw new Error(e.getShaderInfoLog(c)||"Finish shader failed");return c},a=e.createProgram();if(e.attachShader(a,i(e.VERTEX_SHADER,"attribute vec2 p;varying vec2 uv;void main(){uv=(p+1.)*.5;gl_Position=vec4(p,0.,1.);}")),e.attachShader(a,i(e.FRAGMENT_SHADER,`precision mediump float;varying vec2 uv;uniform sampler2D src;uniform vec2 size;uniform float t,bloom,grain,dust,scanlines,crt,prism,vignette,glitch,pixelate,blur,blurMode,angle,focus,halftone,rgbSplit,sharpen;\n float hash(vec2 p){return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453);}\n vec4 sampleAt(vec2 p){if(min(min(p.x,p.y),min(1.-p.x,1.-p.y))<0.)return vec4(0.);return texture2D(src,vec2(p.x,1.-p.y));}\n void main(){vec2 q=uv,c=q-.5;q=c*(1.+dot(c,c)*crt*.25)+.5;\n if(glitch>0.)q.x+=(hash(vec2(floor(q.y*35.),floor(t*5.)))-.5)*.07*glitch*step(.82,hash(vec2(floor(q.y*35.),floor(t*5.)+3.)));\n if(pixelate>0.){vec2 grid=size/(1.+pixelate*20.);q=(floor(q*grid)+.5)/grid;}\n vec4 base=sampleAt(q);float edge=smoothstep(.12,.65,length(c));\n vec2 shift=vec2((prism*3.*edge+rgbSplit*8.)/size.x,prism*edge/size.y);\n if(prism>0.||rgbSplit>0.)base.rgb=vec3(sampleAt(q+shift).r,base.g,sampleAt(q-shift).b);\n vec2 dir=vec2(cos(angle),sin(angle))/size;float amount=blur;\n if(blurMode>1.5&&blurMode<2.5){dir=normalize(c+vec2(.0001))/size;amount*=length(c)*2.;}\n if(blurMode>2.5)amount*=smoothstep(.05,.5,abs(q.y-focus));\n vec4 blurred=base;\n if(amount>0.){blurred=base*.2;for(int i=1;i<=4;i++){float f=float(i)*amount*.35;vec2 off=dir*f;if(blurMode<.5)off=vec2(cos(float(i)*1.57),sin(float(i)*1.57))*amount/size;blurred+=sampleAt(q+off)*.1+sampleAt(q-off)*.1;}}\n vec3 light=vec3(0.);\n // Bloom: a wide golden-angle disc of soft-kneed highlights, screened on, so light spills like halation instead of ghosting glyphs.\n if(bloom>0.){float total=0.;for(int i=0;i<16;i++){float f=float(i);vec2 o=vec2(cos(f*2.39996),sin(f*2.39996))*(2.+f*1.6)/size;vec3 s=sampleAt(q+o).rgb;float w=1./(1.+f*.18);light+=s*smoothstep(.35,.9,max(s.r,max(s.g,s.b)))*w;total+=w;}light*=bloom*3.2/total;}\n vec3 col=1.-(1.-blurred.rgb)*(1.-min(light,vec3(1.)));\n if(sharpen>0.){vec2 px=1./size;vec3 near=sampleAt(q+vec2(px.x,0.)).rgb+sampleAt(q-vec2(px.x,0.)).rgb+sampleAt(q+vec2(0.,px.y)).rgb+sampleAt(q-vec2(0.,px.y)).rgb;col+=(base.rgb*4.-near)*sharpen*.5;}\ncol*=1.-scanlines*.4*(.5+.5*cos(q.y*size.y*3.14159));\n col*=1.-vignette*smoothstep(.15,.72,length(c));\n // Film grain: soft triangular noise, strongest in the midtones, quiet in deep shadow and paper-white highlights.\n float luma=dot(col,vec3(.299,.587,.114));vec2 g=floor(q*size/1.25)+floor(t*24.)*vec2(7.,13.);\n col+=(hash(g)+hash(g+31.7)-1.)*grain*.17*(.2+3.2*luma*(1.-luma));\n if(dust>0.)col+=step(1.-dust*.002,hash(floor(q*size*.25)+floor(t*2.)))*.4;\n if(halftone>0.)col*=mix(1.,smoothstep(.1,.65,length(fract(q*size/6.)-.5)),halftone);\n gl_FragColor=vec4(clamp(col,0.,1.),blurred.a);}`)),e.linkProgram(a),!e.getProgramParameter(a,e.LINK_STATUS))throw new Error("Finish link failed");e.useProgram(a);let o=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,o),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),e.STATIC_DRAW);let l=e.getAttribLocation(a,"p");e.enableVertexAttribArray(l),e.vertexAttribPointer(l,2,e.FLOAT,!1,0,0);let s=e.createTexture();e.bindTexture(e.TEXTURE_2D,s),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE);let h=["t","bloom","grain","dust","scanlines","crt","prism","rgbSplit","sharpen","vignette","glitch","pixelate","blur","blurMode","angle","focus","halftone"],m=Object.fromEntries(h.map(f=>[f,e.getUniformLocation(a,f)])),u=e.getUniformLocation(a,"size");return{canvas:t,render(f,p,c,b=1){(t.width!==f.width||t.height!==f.height)&&(t.width=f.width,t.height=f.height,e.viewport(0,0,t.width,t.height)),e.useProgram(a),e.bindTexture(e.TEXTURE_2D,s),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,f),e.uniform2f(u,t.width/b,t.height/b);for(let g of h)e.uniform1f(m[g],g==="t"?c:g==="blurMode"?["gaussian","directional","radial","progressive"].indexOf(p.blurType):g==="angle"?p.angle*Math.PI/180:p[g]??0);return e.drawArrays(e.TRIANGLE_STRIP,0,4),t},destroy(){e.deleteTexture(s),e.deleteBuffer(o),e.deleteProgram(a),r.forEach(f=>e.deleteShader(f)),t.width=t.height=1,e.getExtension("WEBGL_lose_context")?.loseContext()}}}function Jt(n,t,e){let r=Math.min(n*Math.max(1,e),(1-n)*Math.max(1,e),t*Math.max(1,1/e),(1-t)*Math.max(1,1/e)),i=Math.max(0,Math.min(1,(r-.035)/.105));return i*i*i*(i*(i*6-15)+10)}var mr=class{constructor(t,e){this.edgeSafe=!1;this.rings=new Float64Array(40);this.slot=0;this.clock=0;this.lastRing=-1;this.previous=null;this.alive=!1;this.width=t,this.height=e,this.pixels=new Uint8Array(t*e*4),this.values=new Float32Array(t*e),this.clear()}get active(){return this.alive}clear(){this.rings.fill(0),this.values.fill(0),this.pixels.fill(0);for(let t=0;t<this.pixels.length;t+=4)this.pixels[t]=128;this.previous=null,this.alive=!1,this.slot=0,this.lastRing=-1,this.clock=0}leave(){this.previous=null}move(t,e,r,i){if(!Number.isFinite(t+e+r))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e));let a=Number.isFinite(i)?i/1e3:this.clock,o=this.previous;if(this.previous={x:t,y:e,time:a},!o)return;let l=this.width/this.height,s=Math.hypot((t-o.x)*Math.max(1,l),(e-o.y)*Math.max(1,1/l));if(s<1e-4||this.clock-this.lastRing<1/24)return;let h=s/Math.max(1/240,Math.min(.1,a-o.time||1/60)),m=this.slot*5;this.slot=(this.slot+1)%8,this.rings[m]=t,this.rings[m+1]=e,this.rings[m+2]=0,this.rings[m+3]=Math.min(.9,.26+h*.2),this.rings[m+4]=.035+Math.max(.1,Math.min(1,r))*.13,this.alive=!0,this.lastRing=this.clock}step(t){if(!Number.isFinite(t)||t<=0)return;let e=Math.min(.05,t);if(this.clock+=e,!this.alive)return;this.values.fill(0),this.alive=!1;let r=this.width/this.height,i=Math.max(1,r),a=Math.max(1,1/r);for(let o=0;o<this.rings.length;o+=5){if(!this.rings[o+3])continue;let l=this.rings[o+2]+=e;if(l>2.8){this.rings[o+3]=0;continue}this.alive=!0;let s=this.rings[o+4],h=l*.17,m=this.rings[o+3]*(1-Math.exp(-l*20))*Math.exp(-l*2.5),u=h+s*1.8,f=this.rings[o],p=this.rings[o+1],c=Math.max(0,Math.floor((f-u/i)*(this.width-1))),b=Math.min(this.width-1,Math.ceil((f+u/i)*(this.width-1))),g=Math.max(0,Math.floor((p-u/a)*(this.height-1))),M=Math.min(this.height-1,Math.ceil((p+u/a)*(this.height-1)));for(let v=g;v<=M;v++)for(let S=c;S<=b;S++){let A=(Math.hypot((S/(this.width-1)-f)*i,(v/(this.height-1)-p)*a)-h)/s;Math.abs(A)>1.8||(this.values[v*this.width+S]+=m*Math.cos(A*Math.PI*2)*Math.exp(-A*A*2.5))}}for(let o=0;o<this.height;o++)for(let l=0;l<this.width;l++){let s=o*this.width+l,h=this.values[s]=Math.max(-1,Math.min(1,this.values[s]))*(this.edgeSafe?Jt(l/(this.width-1),o/(this.height-1),r):1),m=Math.round(h*32767+32768);this.pixels[s*4]=m>>>8,this.pixels[s*4+1]=m&255}}sample(t,e,r){let i=Math.max(0,Math.min(this.width-1.001,t*(this.width-1))),a=Math.max(0,Math.min(this.height-1.001,e*(this.height-1))),o=Math.floor(i),l=Math.floor(a),s=i-o,h=a-l,m=l*this.width+o,u=m+this.width;r[0]=r[1]=0,r[2]=((this.values[m]*(1-s)+this.values[m+1]*s)*(1-h)+(this.values[u]*(1-s)+this.values[u+1]*s)*h)*3}};var Se=n=>["dissolve","silk","vortex","magnetic","scatter","etch","elastic","lens","smudge"].includes(n),yi=n=>n==="elastic"||n==="scatter",vi={elastic:[150,4.2],scatter:[90,3.6]},fr=class{constructor(t,e){this.edgeSafe=!1;this.previous=null;this.peak=0;this.scatterDirections=null;this.springX=null;this.springY=null;this.mode="dissolve";this.width=t,this.height=e;let r=t*e;this.pixels=new Uint8Array(r*4),this.ink=new Float32Array(r),this.targetX=new Float32Array(r),this.targetY=new Float32Array(r),this.offsetX=new Float32Array(r),this.offsetY=new Float32Array(r),this.edge=new Float32Array(r);for(let i=0;i<e;i++)for(let a=0;a<t;a++)this.edge[i*t+a]=Jt(a/(t-1),i/(e-1),t/e);this.clear()}get active(){return this.peak>2e-4}setMode(t){if(yi(t)&&!this.springX&&(this.springX=new Float32Array(this.ink.length),this.springY=new Float32Array(this.ink.length)),t==="scatter"&&!this.scatterDirections){let e=this.scatterDirections=new Float64Array(this.width*this.height*2),r=(i,a)=>{let o=Math.sin(i*127.1+a*311.7)*43758.5453;return o-Math.floor(o)};for(let i=0;i<this.height;i++)for(let a=0;a<this.width;a++){let o=a*.09,l=i*.09,s=Math.floor(o),h=Math.floor(l),m=o-s,u=l-h,f=m*m*(3-2*m),p=u*u*(3-2*u),b=((r(s,h)*(1-f)+r(s+1,h)*f)*(1-p)+(r(s,h+1)*(1-f)+r(s+1,h+1)*f)*p)*Math.PI*4,g=(i*this.width+a)*2;e[g]=Math.cos(b)*.7,e[g+1]=Math.sin(b)*.7}}t!==this.mode&&(this.mode=t,this.clear())}clear(){for(let t of[this.ink,this.targetX,this.targetY,this.offsetX,this.offsetY,this.pixels])t.fill(0);if(this.previous=null,this.peak=0,this.springX?.fill(0),this.springY?.fill(0),this.mode!=="dissolve")for(let t=0;t<this.pixels.length;t+=4)this.pixels[t]=this.pixels[t+2]=128}leave(){this.previous=null}move(t,e,r){if(!Number.isFinite(t+e+r))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e));let i=this.previous;this.previous={x:t,y:e};let a=this.width,o=this.height,l=Math.max(1,a/o),s=Math.max(1,o/a),h=i?(t-i.x)*l:0,m=i?(e-i.y)*s:0,u=Math.hypot(h,m);if(!i&&this.mode!=="dissolve"&&this.mode!=="etch"&&this.mode!=="lens"||i&&u<1e-4)return;let f=.035+Math.max(.1,Math.min(1,r))*.11,p=Math.min(128,Math.max(1,Math.ceil(u/(f*.45)))),c=u?h/u:1,b=u?m/u:0,g=!i&&this.mode==="lens"?.32:Math.min(1,u/(f*p)*2.2);for(let M=0;M<p;M++){let v=(M+.5)/p,S=i?i.x+(t-i.x)*v:t,k=i?i.y+(e-i.y)*v:e,A=Math.max(0,Math.floor((S-f*2.5/l)*(a-1))),H=Math.min(a-1,Math.ceil((S+f*2.5/l)*(a-1))),N=Math.max(0,Math.floor((k-f*2.5/s)*(o-1))),C=Math.min(o-1,Math.ceil((k+f*2.5/s)*(o-1)));for(let I=N;I<=C;I++)for(let y=A;y<=H;y++){let z=(y/(a-1)-S)*l/f,q=(I/(o-1)-k)*s/f,Y=Math.exp(-(z*z+q*q)*1.5),x=I*a+y;if(this.mode==="dissolve"||this.mode==="etch")this.ink[x]=Math.max(this.ink[x],Y);else if(this.mode==="elastic")this.springX[x]=Math.max(-24,Math.min(24,this.springX[x]+c*Y*g*12)),this.springY[x]=Math.max(-24,Math.min(24,this.springY[x]+b*Y*g*12));else if(this.mode==="scatter"){let D=this.scatterDirections;this.springX[x]=Math.max(-24,Math.min(24,this.springX[x]+(z*.6+D[x*2])*Y*g*7)),this.springY[x]=Math.max(-24,Math.min(24,this.springY[x]+(q*.6+D[x*2+1])*Y*g*7))}else if(this.mode==="lens")this.targetX[x]=Math.max(-.65,Math.min(.65,this.targetX[x]+z*Y*g*1.6)),this.targetY[x]=Math.max(-.65,Math.min(.65,this.targetY[x]+q*Y*g*1.6));else if(this.mode==="smudge")this.targetX[x]=Math.max(-1,Math.min(1,this.targetX[x]+c*Y*g*1.3)),this.targetY[x]=Math.max(-1,Math.min(1,this.targetY[x]+b*Y*g*1.3));else{let D=(-z*b+q*c)*Y*2.8,V=this.mode==="magnetic"?-z*Y*2.5:this.mode==="silk"?c*D:-q*Y*2.5,Z=this.mode==="magnetic"?-q*Y*2.5:this.mode==="silk"?b*D:z*Y*2.5;this.targetX[x]=Math.max(-1,Math.min(1,this.targetX[x]+V*g)),this.targetY[x]=Math.max(-1,Math.min(1,this.targetY[x]+Z*g))}}}this.peak=1}step(t){if(!this.active||!Number.isFinite(t))return;let e=Math.max(0,Math.min(.05,t)),r=this.mode==="dissolve"?2.15:this.mode==="smudge"?2.4:3.2,i=this.mode==="lens"?16:22,a=Math.exp(-r*e),o=1-Math.exp(-i*e),l=0,[s,h]=this.mode==="scatter"?vi.scatter:vi.elastic,m=Math.sqrt(s-h*h),u=Math.exp(-h*e),f=Math.cos(m*e),p=Math.sin(m*e)/m;for(let c=0;c<this.ink.length;c++)if(this.mode==="etch")this.ink[c]*=a,l=Math.max(l,this.ink[c]);else if(this.mode==="dissolve"){this.ink[c]*=a,l=Math.max(l,this.ink[c]);let b=Math.round(this.ink[c]*65535);this.pixels[c*4]=b>>>8,this.pixels[c*4+1]=b&255}else{if(yi(this.mode)){let M=this.offsetX[c],v=this.offsetY[c],S=this.springX[c],k=this.springY[c];this.offsetX[c]=Math.max(-1,Math.min(1,u*(M*f+(S+h*M)*p))),this.offsetY[c]=Math.max(-1,Math.min(1,u*(v*f+(k+h*v)*p))),this.springX[c]=u*(S*f-(h*S+s*M)*p),this.springY[c]=u*(k*f-(h*k+s*v)*p),l=Math.max(l,Math.abs(this.springX[c])*.05,Math.abs(this.springY[c])*.05)}else if(this.mode==="lens"||this.mode==="smudge"){let M=1-o,v=i/(i-r)*(a-M);this.offsetX[c]=this.offsetX[c]*M+this.targetX[c]*v,this.offsetY[c]=this.offsetY[c]*M+this.targetY[c]*v,this.targetX[c]*=a,this.targetY[c]*=a}else this.targetX[c]*=a,this.targetY[c]*=a,this.offsetX[c]+=(this.targetX[c]-this.offsetX[c])*o,this.offsetY[c]+=(this.targetY[c]-this.offsetY[c])*o;l=Math.max(l,Math.abs(this.offsetX[c]),Math.abs(this.offsetY[c]),Math.abs(this.targetX[c]),Math.abs(this.targetY[c]));let b=Math.round(this.offsetX[c]*(this.edgeSafe?this.edge[c]:1)*32767+32768),g=Math.round(this.offsetY[c]*(this.edgeSafe?this.edge[c]:1)*32767+32768);this.pixels[c*4]=b>>>8,this.pixels[c*4+1]=b&255,this.pixels[c*4+2]=g>>>8,this.pixels[c*4+3]=g&255}if(this.mode==="etch")for(let c=0;c<this.height;c++)for(let b=0;b<this.width;b++){let g=c*this.width+b,M=(this.ink[c*this.width+Math.max(0,b-1)]-this.ink[c*this.width+Math.min(this.width-1,b+1)]+this.ink[Math.max(0,c-1)*this.width+b]-this.ink[Math.min(this.height-1,c+1)*this.width+b])*3;this.offsetX[g]=Math.max(-1,Math.min(1,M))*(this.edgeSafe?this.edge[g]:1);let v=Math.round(this.offsetX[g]*32767+32768);this.pixels[g*4]=v>>>8,this.pixels[g*4+1]=v&255}this.peak=l,this.active||this.clear()}sample(t,e,r){let i=Math.max(0,Math.min(this.width-1.001,t*(this.width-1))),a=Math.max(0,Math.min(this.height-1.001,e*(this.height-1))),o=Math.floor(i),l=Math.floor(a),s=i-o,h=a-l,m=l*this.width+o,u=m+this.width,f=p=>(p[m]*(1-s)+p[m+1]*s)*(1-h)+(p[u]*(1-s)+p[u+1]*s)*h;if(this.mode==="etch"){r[0]=r[1]=0,r[2]=f(this.offsetX)*3;return}r[0]=f(this.offsetX)*(this.edgeSafe?Jt(t,e,this.width/this.height):1)*.08,r[1]=f(this.offsetY)*(this.edgeSafe?Jt(t,e,this.width/this.height):1)*.08,r[2]=this.mode==="dissolve"?-f(this.ink)*6:0}};var dr=class{constructor(t,e){this.rings=[];this.previous=null;this.elapsed=1;this.echoPeak=0;this.width=t,this.height=e,this.pixels=new Uint8Array(t*e*4),this.echo=new Float32Array(t*e)}get active(){return this.rings.length>0||this.echoPeak>2e-4}clear(){this.rings=[],this.previous=null,this.elapsed=1,this.pixels.fill(0),this.echo.fill(0),this.echoPeak=0}leave(){this.previous=null}move(t,e,r){let i=Math.max(1,this.width/this.height),a=Math.max(1,this.height/this.width);this.previous&&(Math.hypot((t-this.previous.x)*i,(e-this.previous.y)*a)<.065||this.elapsed<.3)||this.rings.length!==4&&(this.previous={x:t,y:e},this.elapsed=0,this.rings.push({x:t,y:e,age:0,radius:r}))}ringSample(t,e){let r=Math.max(1,this.width/this.height),i=Math.max(1,this.height/this.width),a=0;for(let o of this.rings){let l=.015+o.age*(.15+o.radius*.22),s=.009+o.radius*.014,h=(Math.hypot((t-o.x)*r,(e-o.y)*i)-l)/s,m=Math.sin(Math.min(1,o.age/.07)*Math.PI/2)*Math.max(0,1-o.age/1.35)**2;a=Math.max(a,Math.exp(-h*h)*m)}return a}sample(t,e){let r=Math.max(0,Math.min(this.width-1,Math.round(t*(this.width-1)))),i=Math.max(0,Math.min(this.height-1,Math.round(e*(this.height-1))));return Math.max(this.ringSample(t,e),this.echo[i*this.width+r])}step(t){if(!Number.isFinite(t))return;let e=Math.max(0,Math.min(.05,t));this.elapsed+=e;for(let a of this.rings)a.age+=e;if(this.rings=this.rings.filter(a=>a.age<1.35),!this.active){this.pixels.fill(0);return}let r=Math.exp(-5.5*e),i=0;for(let a=0;a<this.height;a++)for(let o=0;o<this.width;o++){let l=a*this.width+o;this.echo[l]=Math.max(this.ringSample(o/(this.width-1),a/(this.height-1)),this.echo[l]*r),i=Math.max(i,this.echo[l]);let s=Math.round(this.echo[l]*65535),h=l*4;this.pixels[h]=s>>>8,this.pixels[h+1]=s&255}this.echoPeak=i,this.active||(this.echo.fill(0),this.pixels.fill(0))}};var pr=class{constructor(t,e){this.previous=null;this.peak=0;this.width=t,this.height=e;let r=t*e;this.pixels=new Uint8Array(r*4),this.signal=new Float32Array(r),this.offsetX=new Float32Array(r),this.offsetY=new Float32Array(r),this.driftX=new Float32Array(r),this.driftY=new Float32Array(r),this.u=new Float32Array(r),this.v=new Float32Array(r),this.ink=new Float32Array(r),this.a=new Float32Array(r),this.b=new Float32Array(r),this.c=new Float32Array(r),this.pressure=new Float32Array(r),this.pressureNext=new Float32Array(r),this.divergence=new Float32Array(r),this.curl=new Float32Array(r)}get active(){return this.peak>2e-4}clear(){for(let t of[this.u,this.v,this.ink,this.a,this.b,this.c,this.pressure,this.pressureNext,this.divergence,this.curl,this.signal,this.pixels,this.offsetX,this.offsetY,this.driftX,this.driftY])t.fill(0);this.previous=null,this.peak=0}leave(){this.previous=null}move(t,e,r,i=performance.now()){if(!Number.isFinite(t+e+r+i))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e)),r=Math.max(.1,Math.min(1,r));let a=this.previous;if(this.previous={x:t,y:e,time:i},!a)return;let o=(t-a.x)*(this.width-1),l=(e-a.y)*(this.height-1),s=Math.hypot(o,l);if(s<.001)return;let h=Math.min(this.width,this.height),m=i>a.time?Math.max(1/240,(i-a.time)/1e3):1/60,u=Math.min(12,s/h/m),f=1-Math.exp(-u/2.2),p=h*(.022+r*.075)*(.65+f*.95),c=Math.min(128,Math.max(1,Math.ceil(s/(p*.4)))),b=s/p*(.32+f*.22)/c,g=o/s,M=l/s,v=-M,S=g,k=s*(2+f*18)/c;for(let A=0;A<c;A++){let H=(A+.5)/c,N=(a.x+(t-a.x)*H)*(this.width-1),C=(a.y+(e-a.y)*H)*(this.height-1),I=Math.max(1,Math.floor(N-p*3)),y=Math.min(this.width-2,Math.ceil(N+p*3)),z=Math.max(1,Math.floor(C-p*3)),q=Math.min(this.height-2,Math.ceil(C+p*3));for(let Y=z;Y<=q;Y++)for(let x=I;x<=y;x++){let D=((x-N)*g+(Y-C)*M)/p,V=((x-N)*v+(Y-C)*S)/p,Z=Math.exp(-D*D*.65-V*V*1.7),T=Y*this.width+x;this.ink[T]=1-(1-this.ink[T])*Math.exp(-Z*b);let O=1-V*V*.55,w=D*V*.7;this.u[T]=Math.max(-80,Math.min(80,this.u[T]+(g*O+v*w)*Z*k)),this.v[T]=Math.max(-80,Math.min(80,this.v[T]+(M*O+S*w)*Z*k))}}this.peak=1}read(t,e,r){e=Math.max(.5,Math.min(this.width-1.5,e)),r=Math.max(.5,Math.min(this.height-1.5,r));let i=e|0,a=r|0,o=e-i,l=r-a,s=a*this.width+i;return(t[s]*(1-o)+t[s+1]*o)*(1-l)+(t[s+this.width]*(1-o)+t[s+this.width+1]*o)*l}sample(t,e){return this.read(this.signal,t*(this.width-1),e*(this.height-1))}displacement(t,e,r){r[0]=this.read(this.offsetX,t*(this.width-1),e*(this.height-1)),r[1]=this.read(this.offsetY,t*(this.width-1),e*(this.height-1))}step(t){if(!this.active||!Number.isFinite(t))return;let e=Math.max(0,Math.min(.05,t)),r=this.width,i=this.height;for(;e>1e-7;){let a=Math.min(.016666666666666666,e);e-=a;let o=Math.exp(-1.9*a),l=Math.exp(-3.2*a);for(let h=1;h<i-1;h++)for(let m=1;m<r-1;m++){let u=h*r+m,f=Math.max(.5,Math.min(r-1.5,m-this.u[u]*a)),p=Math.max(.5,Math.min(i-1.5,h-this.v[u]*a)),c=f|0,b=p|0,g=f-c,M=p-b,v=b*r+c,S=(1-g)*(1-M),k=g*(1-M),A=(1-g)*M,H=g*M;this.a[u]=(this.u[v]*S+this.u[v+1]*k+this.u[v+r]*A+this.u[v+r+1]*H)*o,this.b[u]=(this.v[v]*S+this.v[v+1]*k+this.v[v+r]*A+this.v[v+r+1]*H)*o,this.c[u]=(this.ink[v]*S+this.ink[v+1]*k+this.ink[v+r]*A+this.ink[v+r+1]*H)*l}[this.u,this.a]=[this.a,this.u],[this.v,this.b]=[this.b,this.v],[this.ink,this.c]=[this.c,this.ink];for(let h=1;h<i-1;h++)for(let m=1;m<r-1;m++){let u=h*r+m;this.curl[u]=(this.v[u+1]-this.v[u-1]-this.u[u+r]+this.u[u-r])*.5}for(let h=1;h<i-1;h++)for(let m=1;m<r-1;m++){let u=h*r+m,f=Math.abs(this.curl[u+1])-Math.abs(this.curl[u-1]),p=Math.abs(this.curl[u+r])-Math.abs(this.curl[u-r]),c=Math.hypot(f,p)+1e-4,b=this.curl[u]*a*10,g=Math.hypot(this.u[u],this.v[u]);this.u[u]+=p/c*b,this.v[u]-=f/c*b;let M=Math.min(1,g/(Math.hypot(this.u[u],this.v[u])+1e-6));this.u[u]*=M,this.v[u]*=M,this.divergence[u]=-.5*(this.u[u+1]-this.u[u-1]+this.v[u+r]-this.v[u-r])}this.pressure.fill(0);for(let h=0;h<4;h++){for(let m=1;m<i-1;m++)for(let u=1;u<r-1;u++){let f=m*r+u;this.pressureNext[f]=(this.divergence[f]+this.pressure[f-1]+this.pressure[f+1]+this.pressure[f-r]+this.pressure[f+r])*.25}[this.pressure,this.pressureNext]=[this.pressureNext,this.pressure]}let s=0;for(let h=1;h<i-1;h++)for(let m=1;m<r-1;m++){let u=h*r+m;this.u[u]=Math.max(-80,Math.min(80,this.u[u]-(this.pressure[u+1]-this.pressure[u-1])*.5)),this.v[u]=Math.max(-80,Math.min(80,this.v[u]-(this.pressure[u+r]-this.pressure[u-r])*.5)),this.driftX[u]+=(this.u[u]*3.6-58*this.offsetX[u]-12*this.driftX[u])*a,this.driftY[u]+=(this.v[u]*3.6-58*this.offsetY[u]-12*this.driftY[u])*a,this.offsetX[u]=Math.max(-2,Math.min(2,this.offsetX[u]+this.driftX[u]*a)),this.offsetY[u]=Math.max(-2,Math.min(2,this.offsetY[u]+this.driftY[u]*a)),this.signal[u]=1-Math.exp(-Math.hypot(this.u[u],this.v[u])*.06-this.ink[u]*.16),s=Math.max(s,this.signal[u])}this.peak=s}if(!this.active){this.clear();return}for(let a=0;a<this.ink.length;a++){let o=Math.round(Math.min(1,this.signal[a])*65535);this.pixels[a*4]=o>>>8,this.pixels[a*4+1]=o&255,this.pixels[a*4+2]=Math.round(128+this.offsetX[a]*63.5),this.pixels[a*4+3]=Math.round(128+this.offsetY[a]*63.5)}}};function xi(n,t){let e=Math.max(0,Math.min(1,t/.38)),r=e*e*(3-2*e);return n+(1-2*n)*r}var en=["loupe","repel","tilt","reveal","haze","bleed"],$t=n=>en.includes(n),ke=class{constructor(){this.value=0;this.velocity=0}step(t,e,r,i){let a=2*Math.sqrt(r)*i;for(let o=e;o>1e-6;o-=1/480){let l=Math.min(.0020833333333333333,o);this.velocity+=((t-this.value)*r-this.velocity*a)*l,this.value+=this.velocity*l}}resting(t){return Math.abs(this.value-t)<.0015&&Math.abs(this.velocity)<.01}set(t){this.value=t,this.velocity=0}},Si=n=>n*n*(3-2*n),Ge=(n,t)=>{let e=Math.sin(n*127.1+t*311.7)*43758.5453;return e-Math.floor(e)};function gr(n,t){let e=Math.floor(n),r=Math.floor(t),i=Si(n-e),a=Si(t-r),o=Ge(e,r),l=Ge(e+1,r),s=Ge(e,r+1),h=Ge(e+1,r+1);return(o+(l-o)*i)*(1-a)+(s+(h-s)*i)*a}var br=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 ke;this.y=new ke;this.tx=new ke;this.ty=new ke;this.presence=new ke;this.target=null;this.speed=0;this.clock=0;this.inkPeak=0;this.ink=null;this.next=null;this.fiber=null;this.sampled=[0,0,0];this.width=t,this.height=e,this.pixels=new Uint8Array(t*e*4),this.sx=Math.max(1,t/e),this.sy=Math.max(1,e/t),this.clear()}setMode(t){if(t!==this.mode&&(this.mode=t,this.clear(),t==="bleed"&&!this.ink)){let e=this.width*this.height;this.ink=new Float32Array(e),this.next=new Float32Array(e),this.fiber=new Float32Array(e);for(let r=0;r<this.height;r++)for(let i=0;i<this.width;i++)this.fiber[r*this.width+i]=.35+.5*gr(i*.09,r*.045)+.15*Ge(i,r)}}setRadius(t){this.radius=Math.max(.1,Math.min(1,t))}get reach(){return(.05+this.radius*.25)*(this.mode==="loupe"?1-this.speed*.14:1)}get engaged(){return this.presence.value>.002||this.inkPeak>.002||Math.abs(this.tx.value)+Math.abs(this.ty.value)>4e-4}get active(){let t=this.target?1:0;return!this.presence.resting(t)||!!this.target&&(!this.x.resting(this.target.x)||!this.y.resting(this.target.y))||!this.tx.resting(this.tiltGoal(0))||!this.ty.resting(this.tiltGoal(1))||this.speed>.01||this.mode==="haze"&&this.presence.value>.002||this.inkPeak>.002}tiltGoal(t){return this.target&&this.mode==="tilt"?((t?this.target.y:this.target.x)-.5)*2:0}clear(){for(let t of[this.x,this.y,this.tx,this.ty,this.presence])t.set(0);this.x.set(.5),this.y.set(.5),this.target=null,this.speed=0,this.inkPeak=0,this.ink?.fill(0),this.next?.fill(0),this.encode()}move(t,e,r){if(!Number.isFinite(t+e))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e));let i=Number.isFinite(r)?r/1e3:this.clock,a=this.target;if(!a&&this.presence.value<.05&&(this.x.set(t),this.y.set(e)),a){let o=Math.hypot((t-a.x)*this.sx,(e-a.y)*this.sy),l=o/Math.max(1/240,Math.min(.1,i-a.time||1/60));this.speed=Math.max(this.speed,Math.min(1,l/1.6)),this.mode==="bleed"&&this.deposit(a.x,a.y,t,e,Math.min(1,o*9))}else this.mode==="bleed"&&this.deposit(t,e,t,e,.5);this.target={x:t,y:e,time:i}}leave(){this.target=null}deposit(t,e,r,i,a){let o=this.ink,l=this.width,s=this.height,h=this.reach*.55,m=Math.hypot((r-t)*this.sx,(i-e)*this.sy),u=Math.min(48,Math.max(1,Math.ceil(m/(h*.5))));for(let f=0;f<u;f++){let p=(f+.5)/u,c=t+(r-t)*p,b=e+(i-e)*p,g=Math.max(0,Math.floor((c-h*2/this.sx)*(l-1))),M=Math.min(l-1,Math.ceil((c+h*2/this.sx)*(l-1))),v=Math.max(0,Math.floor((b-h*2/this.sy)*(s-1))),S=Math.min(s-1,Math.ceil((b+h*2/this.sy)*(s-1)));for(let k=v;k<=S;k++)for(let A=g;A<=M;A++){let H=(A/(l-1)-c)*this.sx/h,N=(k/(s-1)-b)*this.sy/h,C=k*l+A;o[C]=Math.min(1.4,o[C]+Math.exp(-(H*H+N*N)*1.8)*a/u*1.6)}}this.inkPeak=Math.max(this.inkPeak,.01)}step(t){if(!Number.isFinite(t)||t<=0)return;let e=Math.min(.05,t),r=e*this.settle;this.clock+=e;let i=this.target,a=this.mode;if(i?this.presence.step(1,e,190,1):this.presence.step(0,r,a==="repel"?120:70,a==="repel"?.42:1),i){let o=a==="tilt"?60:a==="haze"?90:240,l=a==="loupe"||a==="repel"?.72:.9;this.x.step(i.x,e,o,l),this.y.step(i.y,e,o,l)}this.tx.step(this.tiltGoal(0),i?e:r,45,.78),this.ty.step(this.tiltGoal(1),i?e:r,45,.78),this.speed*=Math.exp(-e*7),a==="bleed"&&this.spread(e,r,!!i),!this.engaged&&!this.active&&(this.presence.set(0),this.tx.set(0),this.ty.set(0)),this.focus[0]=this.x.value,this.focus[1]=this.y.value,this.focus[2]=Math.max(0,Math.min(1,this.presence.value)),this.focus[3]=this.reach,this.encode()}spread(t,e,r){let i=this.ink,a=this.next,o=this.fiber,l=this.width,s=this.height;r&&this.target&&this.deposit(this.x.value,this.y.value,this.x.value,this.y.value,t*.9);let h=Math.max(1,Math.ceil(t/(1/240))),m=t/h,u=26*(.4+this.radius),f=(r?.02:.1)*e/t,p=Math.exp(-(r?.15:.9)*e/h),c=0;for(let b=0;b<h;b++){c=0;for(let g=1;g<s-1;g++)for(let M=1;M<l-1;M++){let v=g*l+M,S=i[v],k=o[v],A=Math.min(k,o[v-1])*(i[v-1]-S)+Math.min(k,o[v+1])*(i[v+1]-S)+Math.min(k,o[v-l])*(i[v-l]-S)+Math.min(k,o[v+l])*(i[v+l]-S),H=Math.max(0,(S+A*Math.min(.24,u*m))*p-f*m);a[v]=H,H>c&&(c=H)}i.set(a)}this.inkPeak=c}sample(t,e,r){r[0]=r[1]=r[2]=0;let i=this.presence.value,a=this.mode;if(a==="bleed"){if(this.inkPeak<=.002)return;let p=this.width,c=this.height,b=this.ink,g=Math.max(0,Math.min(p-1.001,t*(p-1))),M=Math.max(0,Math.min(c-1.001,e*(c-1))),v=Math.floor(g),S=Math.floor(M),k=g-v,A=M-S,H=S*p+v,N=H+p,C=(b[H]*(1-k)+b[H+1]*k)*(1-A)+(b[N]*(1-k)+b[N+1]*k)*A;r[2]=1-Math.exp(-C*2.4);return}if(a==="tilt"){let c=.2+.8*(this.guide?hi(this.guide,"depth",t,e):.6),b=this.edgeSafe?Jt(t,e,this.sx/this.sy):1;r[0]=this.tx.value*.024*c*b/this.sx,r[1]=this.ty.value*.024*c*b/this.sy;return}if(i<=.001)return;let o=this.reach,l=(t-this.x.value)*this.sx,s=(e-this.y.value)*this.sy,h=(l*l+s*s)/(o*o);if(a==="reveal"){r[2]=Math.exp(-h*2.4)*i;return}if(h>9)return;let m=this.edgeSafe?Jt(t,e,this.sx/this.sy):1,u=0,f=0;if(a==="loupe"){let p=Math.exp(-h*h)*i*.5;u=l*p,f=s*p;let c=Math.sqrt(h)-1;r[2]=Math.exp(-c*c/.018)*i*.55}else if(a==="repel"){let p=Math.sqrt(h),c=o*.5*Math.exp(-h/1.7)*i,b=Math.max(1e-6,Math.sqrt(l*l+s*s));u=l/b*Math.min(c,b+o*.5*i),f=s/b*Math.min(c,b+o*.5*i);let g=Math.max(0,Math.min(1,(p-.3)/.32));r[2]=-(1-g*g*(3-2*g))*i}else if(a==="haze"){let p=s/o+.45,c=Math.exp(-(l*l/(o*o))-p*p/2.6)*i*(.35+.65*Math.min(1,this.speed*1.4+.25));if(c<.002)return;let b=this.clock,g=t*this.sx*9,M=e*this.sy*9+b*2.3,v=gr(g,M)-.5,S=gr(g+17.3,M*1.3+b*.7)-.5;u=v*.06*c,f=S*.026*c,r[2]=(gr(g*1.7+5,M*1.7)-.5)*.35*c}r[0]=u*m/this.sx,r[1]=f*m/this.sy}encode(){let t=this.width,e=this.height,r=this.pixels,i=this.sampled,a=this.engaged;for(let o=0;o<e;o++)for(let l=0;l<t;l++){let s=(o*t+l)*4;if(a?this.sample(l/(t-1),o/(e-1),i):i[0]=i[1]=i[2]=0,this.mode==="bleed"){let h=Math.round(Math.max(-1,Math.min(1,i[2]))*32767+32768);r[s]=h>>>8,r[s+1]=h&255,r[s+2]=128,r[s+3]=0}else{this.mode==="repel"&&(i[0]*=.3,i[1]*=.3);let h=Math.round(Math.max(-1,Math.min(1,i[0]/.16))*32767+32768),m=Math.round(Math.max(-1,Math.min(1,i[1]/.16))*32767+32768);r[s]=h>>>8,r[s+1]=h&255,r[s+2]=m>>>8,r[s+3]=m&255}}}};var rn=.2,nn=.6,an=3,on=7,ki=(n,t)=>n==="water"?30*t/.55:n==="silk"?28*t:n==="vortex"?38*t:["magnetic","scatter","elastic","lens","smudge"].includes(n)?32*t:["loupe","repel","tilt","haze"].includes(n)?.16*t/.55:0,sn=(n=.5)=>Math.pow(2,(.5-(Number.isFinite(n)?Math.max(0,Math.min(1,n)):.5))*2.4);function Wr(n,t,e,r=!1){if(!e)return t;let i=a=>Math.max(0,Math.min(1,a));switch(n){case"trail":case"contour":return xi(t,e);case"etch":case"ripple":return i(t+e*.35);case"dissolve":{let a=Math.max(0,1+e);return r?1-(1-t)*a:t*a}case"bleed":return i(t+e*(r?-.6:.6));case"loupe":return i(t+e*.3);case"haze":return i(t+e*.5);default:return t}}var Ai=n=>["trail","contour","etch","ripple","bleed","haze"].includes(n),Xe=class{constructor(t=1){this.ripple=null;this.cursor=null;this.settle=1;this.mode="water";this.amount=.55;this.radius=.2;this.lensX=.5;this.lensY=.5;this.lensStrength=0;this.previous=null;this.energy=0;this.pending=!1;this.remainder=0;this.quiet=0;this.guide=null;t=Math.max(.25,Math.min(4,t)),this.columns=Math.round(t>=1?128:128*t),this.rows=Math.round(t>=1?128/t:128),this.xScale=Math.max(1,t),this.yScale=Math.max(1,1/t),this.heights=new Float32Array(this.columns*this.rows),this.velocity=new Float32Array(this.heights.length),this.next=new Float32Array(this.heights.length),this.normals=new Float32Array(this.heights.length*2),this.edgeMask=new Float32Array(this.heights.length);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.edgeMask[e*this.columns+r]=Jt(r/(this.columns-1),e/(this.rows-1),t);this.refraction={width:this.columns,height:this.rows,pixels:new Uint8Array(this.heights.length*4),strength:30,mode:"water",focus:[.5,.5,0,.2]},this.waterPixels=this.refraction.pixels,this.trail=new pr(this.columns,this.rows),this.contour=new dr(this.columns,this.rows),this.afterimage=new fr(this.columns,this.rows),this.clear()}get invertsDensity(){return this.mode==="trail"}get densityTrail(){return["trail","contour","dissolve","etch","ripple","bleed"].includes(this.mode)}get hasRefraction(){return this.active||this.lensStrength>15e-5}get effect(){return this.mode}get engaged(){return $t(this.mode)?this.cursor.engaged:this.active}get spotlight(){return this.mode==="reveal"&&this.cursor?this.cursor.focus:null}get signature(){return $t(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 $t(this.mode)?this.cursor.active:this.mode==="ripple"?this.ripple?.active??!1:Se(this.mode)?this.afterimage.active:this.mode==="contour"?this.contour.active:this.mode==="trail"?this.trail.active:this.pending||this.energy>15e-5}setMode(t){let e=t==="light"||t==="scan"?t:hr(t)??"none";e!==this.mode&&(this.clear(),this.mode=e,this.refraction.mode=e,Se(e)&&this.afterimage.setMode(e),e==="ripple"&&!this.ripple&&(this.ripple=new mr(this.columns,this.rows)),$t(e)&&(this.cursor??(this.cursor=new br(this.columns,this.rows)),this.cursor.guide=this.guide,this.cursor.setMode(e)),this.refraction.pixels=$t(e)?this.cursor.pixels:e==="ripple"?this.ripple.pixels:e==="trail"?this.trail.pixels:e==="contour"?this.contour.pixels:Se(e)?this.afterimage.pixels:this.waterPixels,this.refraction.strength=ki(e,this.amount),this.refraction.relative=$t(e))}configure(t,e=.55,r=.2,i=!1,a=.5){this.setMode(t),this.settle=sn(a),this.refraction.edgeSafe=i,this.afterimage.edgeSafe=i,this.ripple&&(this.ripple.edgeSafe=i),this.amount=Number.isFinite(e)?Math.max(0,Math.min(1,e)):.55,this.radius=Number.isFinite(r)?Math.max(.1,Math.min(1,r)):.2,this.cursor&&(this.cursor.edgeSafe=i,this.cursor.settle=this.settle,this.cursor.setRadius(this.radius)),this.refraction.strength=ki(this.mode,this.amount),this.refraction.focus[2]=this.densityTrail?this.amount:this.lensStrength*this.amount,this.refraction.focus[3]=this.radius,(this.mode==="reveal"||this.mode==="repel")&&this.syncSpot()}syncSpot(){let t=this.cursor.focus;this.refraction.focus=[t[0],t[1],t[2]*(this.mode==="repel"?Math.min(1,this.amount/.55):this.amount),t[3]]}move(t,e,r){if(this.mode==="none"||this.amount===0||!Number.isFinite(t+e))return;if(t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e)),$t(this.mode)){this.cursor.move(t,e,r);return}if(this.mode==="ripple"){this.ripple.move(t,e,this.radius,r);return}if(Se(this.mode)){this.afterimage.move(t,e,this.radius);return}if(this.mode==="contour"){this.contour.move(t,e,this.radius);return}if(this.mode==="trail"){this.trail.move(t,e,this.radius,r);return}if(this.mode!=="water"){!this.previous&&this.lensStrength<.001&&(this.lensX=t,this.lensY=e),this.previous={x:t,y:e},this.pending=!0;return}if(!this.previous){this.previous={x:t,y:e};return}let i=this.previous;this.previous={x:t,y:e};let a=(t-i.x)*this.xScale,o=(e-i.y)*this.yScale,l=Math.hypot(a,o);if(l<1e-5)return;let s=.035+this.radius*.1,h=s*3,m=Math.min(192,Math.max(1,Math.ceil(l/(s*.5)))),u=Math.min(l,1)*95/m;for(let f=0;f<m;f++){let p=(f+.5)/m,c=i.x+(t-i.x)*p,b=i.y+(e-i.y)*p,g=Math.max(1,Math.floor((c-h/this.xScale)*(this.columns-1))),M=Math.min(this.columns-2,Math.ceil((c+h/this.xScale)*(this.columns-1))),v=Math.max(1,Math.floor((b-h/this.yScale)*(this.rows-1))),S=Math.min(this.rows-2,Math.ceil((b+h/this.yScale)*(this.rows-1)));for(let k=v;k<=S;k++)for(let A=g;A<=M;A++){let H=(A/(this.columns-1)-c)*this.xScale,N=(k/(this.rows-1)-b)*this.yScale,C=Math.exp(-(H*H+N*N)/(s*s))*u,I=k*this.columns+A;this.velocity[I]=Math.max(-12,this.velocity[I]-C)}}this.pending=!0,this.quiet=0}leave(){this.cursor?.leave(),this.ripple?.leave(),this.afterimage.leave(),this.contour.leave(),this.trail.leave(),this.previous=null,this.mode!=="water"&&this.lensStrength&&(this.pending=!0)}clear(){this.trail.clear(),this.contour.clear(),this.afterimage.clear(),this.ripple?.clear(),this.cursor?.clear(),this.heights.fill(0),this.velocity.fill(0),this.next.fill(0),this.normals.fill(0),this.refraction.focus[2]=0,this.previous=null,this.lensStrength=0,this.energy=0,this.pending=!1,this.remainder=0,this.quiet=0;for(let t=0;t<this.waterPixels.length;t+=4)this.waterPixels[t]=this.waterPixels[t+2]=128,this.waterPixels[t+1]=this.waterPixels[t+3]=0}step(t){if(!this.active||!Number.isFinite(t))return;if($t(this.mode)){this.cursor.step(t),(this.mode==="reveal"||this.mode==="repel")&&this.syncSpot();return}if(t*=this.settle,this.mode==="ripple"){this.ripple.step(t);return}if(Se(this.mode)){this.afterimage.step(t);return}if(this.mode==="contour"){this.contour.step(t);return}if(this.mode==="trail"){this.trail.step(t);return}if(this.mode!=="water"){this.stepLight(Math.max(0,Math.min(.05,t)));return}this.remainder+=Math.max(0,Math.min(.05,t));let e=1/120,r=Math.min(this.columns,this.rows)*.3;for(;this.remainder+1e-8>=e;){this.remainder-=e,this.quiet+=e;let a=Math.max(0,Math.min(1,(this.quiet-rn)/nn)),o=a*a*(3-2*a),l=Math.exp(-(3.8+o*an)*e),s=Math.exp(-o*on*e),h=0;for(let m=1;m<this.rows-1;m++)for(let u=1;u<this.columns-1;u++){let f=m*this.columns+u,p=this.heights[f],c=this.heights[f-1]+this.heights[f+1]+this.heights[f-this.columns]+this.heights[f+this.columns]-4*p,b=Math.min(u,m,this.columns-1-u,this.rows-1-m),g=b<5?.88+b*.024:1,M=(this.velocity[f]+(c*r*r-p*8)*e)*l*g;this.velocity[f]=M,this.next[f]=(p+M*e)*g*s,h=Math.max(h,Math.abs(this.next[f]),Math.abs(M)*.1)}this.heights.set(this.next),this.energy=h,this.pending=!1}if(!this.active){this.clear();return}let i=Math.min(this.columns,this.rows)*.18;for(let a=0;a<this.rows;a++)for(let o=0;o<this.columns;o++){let l=a*this.columns+o,s=(this.heights[a*this.columns+Math.max(0,o-1)]-this.heights[a*this.columns+Math.min(this.columns-1,o+1)])*i,h=(this.heights[Math.max(0,a-1)*this.columns+o]-this.heights[Math.min(this.rows-1,a+1)*this.columns+o])*i,m=Math.tanh(s)*(this.refraction.edgeSafe?this.edgeMask[l]:1),u=Math.tanh(h)*(this.refraction.edgeSafe?this.edgeMask[l]:1);this.normals[l*2]=m,this.normals[l*2+1]=u;let f=Math.round(m*32767+32768),p=Math.round(u*32767+32768);this.refraction.pixels[l*4]=f>>>8,this.refraction.pixels[l*4+1]=f&255,this.refraction.pixels[l*4+2]=p>>>8,this.refraction.pixels[l*4+3]=p&255}}stepLight(t){let e=this.previous,r=1-Math.exp(-30*t),i=1-Math.exp(-12*t);if(e&&(this.lensX+=(e.x-this.lensX)*r,this.lensY+=(e.y-this.lensY)*r),this.lensStrength+=((e?1:0)-this.lensStrength)*i,this.energy=Math.max(e?Math.abs(e.x-this.lensX)+Math.abs(e.y-this.lensY):0,Math.abs((e?1:0)-this.lensStrength)),this.pending=!1,!e&&!this.active){this.clear();return}this.refraction.focus=[this.lensX,this.lensY,this.lensStrength*this.amount,this.radius]}sample(t,e,r){if($t(this.mode)){this.cursor.sample(t,e,r),r[0]*=this.amount/.55,r[1]*=this.amount/.55,r[2]*=this.mode==="reveal"||this.mode==="repel"?Math.min(1,this.amount/.55):this.amount*3;return}if(this.mode==="ripple"){this.ripple.sample(t,e,r),r[2]*=this.amount;return}if(Se(this.mode)){this.afterimage.sample(t,e,r),r[0]*=this.amount,r[1]*=this.amount,r[2]*=this.amount;return}if(this.mode==="contour"){r[0]=r[1]=0,r[2]=this.contour.sample(t,e)*this.amount*3;return}if(this.mode==="trail"){r[0]=r[1]=0,r[2]=this.trail.sample(t,e)*this.amount*3;return}let i=Math.max(0,Math.min(this.columns-1.001,t*(this.columns-1))),a=Math.max(0,Math.min(this.rows-1.001,e*(this.rows-1))),o=Math.floor(i),l=Math.floor(a),s=i-o,h=a-l,m=(l*this.columns+o)*2,u=m+this.columns*2;for(let f=0;f<2;f++)r[f]=((this.normals[m+f]*(1-s)+this.normals[m+2+f]*s)*(1-h)+(this.normals[u+f]*(1-s)+this.normals[u+2+f]*s)*h)*.08;r[0]*=this.amount/.55,r[1]*=this.amount/.55,r[2]=this.mode==="light"||this.mode==="scan"?ln(t,e,this.refraction,this.xScale/this.yScale):0}};function ln(n,t,e,r){let[i,a,o,l]=e.focus,s=(n-i)*Math.max(1,r)/l,h=(t-a)*Math.max(1,1/r)/l;return e.mode==="light"?Math.exp(-3*(s*s+h*h))*o:e.mode==="scan"?(Math.exp(-s*s*110)*1.3-Math.exp(-s*s*12)*.3)*Math.exp(-h*h*1.8)*o:0}function Ei(n){return"videoWidth"in n?[n.videoWidth,n.videoHeight]:"naturalWidth"in n?[n.naturalWidth,n.naturalHeight]:[n.width,n.height]}var Ht=(n,t,e)=>{(n.width!==t||n.height!==e)&&(n.width=t,n.height=e)},wi={blocks:" \\u2591\\u2592\\u2593\\u2588",braille:" \\u2801\\u2803\\u2807\\u2847\\u28C7\\u28E7\\u28F7\\u28FF",lines:" -\\u2550\\u256A\\u256C",cross:" \\xB7+xX#",diagonal:" /\\u2571\\u2573",diamond:" \\xB7\\u25C7\\u25C8\\u25C6",mixed:" .:+/\\u25C7#@"},hn=.01,cn=.99,Mr=.32,un=.07,mn=.6,yr=.9;function fn(n){let t=new Uint32Array(256),e=0;for(let o=0;o<n.length;o+=4)n[o+3]<8||(t[Math.min(255,n[o]*.299+n[o+1]*.587+n[o+2]*.114|0)]++,e++);if(!e)return[0,1];let r=o=>{let l=0,s=o*e;for(let h=0;h<256;h++)if((l+=t[h])>=s)return h/255;return 1},i=r(hn),a=r(cn);return a-i<Mr&&(i=Math.max(0,Math.min(1-Mr,(i+a)/2-Mr/2)),a=i+Mr),[i,a]}function dn(n,t,e){let r=Math.max(.001,e-t),i=0,a=0;for(let l=0;l<n.length;l+=4){if(n[l+3]<8)continue;let s=((n[l]*.299+n[l+1]*.587+n[l+2]*.114)/255-t)/r;s<=.06||(i+=Math.min(1,s),a++)}if(!a)return yr;let o=Math.min(.99,Math.max(.01,i/a));return Math.min(yr,Math.max(mn,Math.log(.5)/Math.log(o)))}function pn(n,t=yr){let e=Math.min(...n),r=Math.max(...n);if(!(r-e>1e-4))return null;let i=n.map(o=>(o-e)/(r-e)),a=new Uint8Array(256);for(let o=0;o<256;o++){if(o/255<un){a[o]=i.indexOf(0);continue}let l=Math.pow(o/255,t),s=0;for(let h=1;h<i.length;h++)Math.abs(i[h]-l)<Math.abs(i[s]-l)&&(s=h);a[o]=s}return a}function Fi(n,t,e,r){n.clearRect(0,0,t,e),n.fillStyle="#fff",n.strokeStyle="#fff",n.lineCap="round",n.lineJoin="round";for(let i of r){if(n.beginPath(),i.kind==="ellipse")n.ellipse((i.x+i.width/2)*t,(i.y+i.height/2)*e,i.width*t/2,i.height*e/2,0,0,Math.PI*2);else if(i.kind==="rectangle")n.rect(i.x*t,i.y*e,i.width*t,i.height*e);else{if(n.lineWidth=(i.size??.05)*t,i.points?.length===1){n.arc(i.points[0][0]*t,i.points[0][1]*e,n.lineWidth/2,0,Math.PI*2),n.fill();continue}i.points?.forEach(([a,o],l)=>l?n.lineTo(a*t,o*e):n.moveTo(a*t,o*e)),n.stroke();continue}n.fill()}}var Ri=new WeakMap;function Ti(n,t,e,r,i,a){Ri.get(n)?.(t,e,r,i,a,!1)}var gn=n=>Math.max(64,Math.min(4096,Number.isFinite(n)?n:960));function bn(n,t,e){let r=Math.min(1,n/Math.max(t,e));return[Math.max(2,Math.round(t*r)),Math.max(2,Math.round(e*r))]}function Mn(n,t,e,r,i){let[a,o]=Ei(t);n.clearRect(0,0,e,r),n.save();let l=fi(a,o,e,r,i);n.translate(l.x+l.width/2,l.y+l.height/2),n.rotate(i.rotation*Math.PI/180),n.drawImage(t,-a*l.scale/2,-o*l.scale/2,a*l.scale,o*l.scale),n.restore()}function Ci(n,t,e,r){let i=r.surface,a=n.getContext("2d");if(!a)throw new Error("Canvas is already owned by another renderer.");let o=i(),l=i(!0),s=i(),h=i(),m=i(),u=i(),f=i(),p=i(),c=i(),b=i(),g=0,M=0,v=1,S=yr,k=null,A=null,H=null,N="",C,I,y=ur(t),z=0,q="",Y="",x="",D=new Uint8ClampedArray(0),V=new Uint8ClampedArray(0),Z=new Uint8ClampedArray(0),T=null,O="",w=0,F=0,W=0,P=null,U="",E=new Xe,B=null,nt=new Float32Array(0),Q=i(!0),ct=i(),ft=i(),At=0,Tt=[0,0,0],mt=[0,0,0,1],se=[0,0],ot=[0,0,0,0],te=Rr(y.color),Ae=Pr(y.print),yt=new Qe(y.color.denoise),le=new $e(y.warps,y.warpEdge),ee=gn(e.maxDimension),Ct=Math.max(256,Math.min(1048576,Number.isFinite(e.maxCells)?e.maxCells:12e3)),re=Ct,Zt=Math.max(.1,Math.min(8,e.pixelRatio??1)),Le=(wt,Nt,Xt)=>{E.configure(y.hover.effect,y.hover.strength,y.hover.radius,y.hover.edgeSafe,y.hover.decay),E.move(wt,Nt,Xt)};function We(wt,Nt=0,Xt=960,jt=540,He=Nt*y.motion.speed){Ue(wt,Nt,Xt,jt,He,!0)}function Ue(wt,Nt,Xt,jt,He,kr){if(Number.isFinite(Nt)||(Nt=0),!Number.isFinite(Xt)||!Number.isFinite(jt)||Xt<1||jt<1)throw new Error("Render dimensions must be positive finite numbers.");let[Ke,Oe]=Ei(wt);if(!Ke||!Oe)return;let[it,$]=bn(ee,Xt,jt);Ht(n,it,$),Ht(o.canvas,it,$),Ht(s.canvas,it,$),Ht(h.canvas,it,$),Ht(m.canvas,it,$),At!==it/$&&(At=it/$,E=new Xe(At),E.setGuide(B)),E.configure(y.hover.effect,y.hover.strength,y.hover.radius,y.hover.edgeSafe,y.hover.decay),E.step(Math.max(0,Math.min(.05,Nt-W))),W=Nt;let ie=r.media(wt),d=[z,it,$,ie.time].join(":"),G=y.style==="dither",R=di(it,$,y,re,Zt),_=R.cell,j=R.rowHeight,pt=R.columns,Mt=R.rows;if(q!==d||P!==ie.key||w!==pt||F!==Mt){P=ie.key,q=d,O="",Y="",x="",w=pt,F=Mt,r.scene?r.scene(o.ctx,it,$):Mn(o.ctx,wt,it,$,y.crop),Ht(l.canvas,w,F),l.ctx.clearRect(0,0,w,F),l.ctx.drawImage(o.canvas,0,0,w,F),D=l.ctx.getImageData(0,0,w,F).data,yt.apply(D,w,F),V.length!==D.length&&(V=new Uint8ClampedArray(D.length)),V.set(D);let Rt=y.color;for(let bt=0;bt<D.length;bt+=4){let ht=D[bt]*.299+D[bt+1]*.587+D[bt+2]*.114;for(let rt=0;rt<3;rt++){let St=ht+(D[bt+rt]-ht)*Rt.saturation;D[bt+rt]=((St*(1-Rt.grayscale)+ht*Rt.grayscale)/255-.5)*Rt.contrast*255+127.5+Rt.brightness*255}}if(te&&Zr(D,te),D=le.apply(D,w,F,it/$),y.color.levels!=="none"){let[bt,ht]=fn(D),rt=dn(D,bt,ht),St=k===ie.key&&ie.video?.15:1;k=ie.key,M+=(bt-M)*St,v+=(ht-v)*St,S+=(rt-S)*St}let gt=y.hover,Ut=gt.scope??"all";if(gt.effect!=="none"&&(Ut!=="all"||gt.effect==="tilt")){let bt=null;if(y.mask.enabled&&y.mask.shapes.length){Ht(Q.canvas,w,F),Q.ctx.clearRect(0,0,w,F),Fi(Q.ctx,w,F,y.mask.shapes);let ht=Q.ctx.getImageData(0,0,w,F).data;bt=new Float32Array(w*F);for(let rt=0;rt<bt.length;rt++)bt[rt]=y.mask.invert?1-ht[rt*4+3]/255:ht[rt*4+3]/255}B=ar(D,w,F,bt,B),nt.length!==w*F&&(nt=new Float32Array(w*F));for(let ht=0;ht<nt.length;ht++)nt[ht]=li(Ut,B.subject[ht],B.key);if(gt.effect==="reveal"){Ht(ct.canvas,w,F);let ht=new ImageData(w,F);for(let rt=0;rt<nt.length;rt++)ht.data[rt*4+3]=nt[rt]*255;ct.ctx.putImageData(ht,0,0)}}else B=null;E.setGuide(B)}if(!kr){x=Y="";return}let Ft=ii(y),K=ri(y),J=!E.active&&!Ft&&!K,tt=[d,w,F,_,j,Zt,E.signature].join(":"),dt=E.engaged,lt=E.effect;if(!J||x!==tt){s.ctx.clearRect(0,0,it,$),s.ctx.globalAlpha=1,s.ctx.globalCompositeOperation="source-over";let Rt=He,gt=Ft?y.motion.type:"none",Ut=y.motion.amount??1,bt=si(gt);gt!=="none"&&O!==q&&(T=ci(V,w,F,T),O=q);let ht=null;if(G){let st=J;if(!st||Y!==d){Z.length!==D.length&&(Z=new Uint8ClampedArray(D.length));let It=Z;if(It.set(D),dt||gt!=="none")for(let L=0;L<F;L++)for(let Pt=0;Pt<w;Pt++){let ne=Pt/w,we=L/F,ae=Pt,oe=L,Fe=0,zt=0,Yt=1;if(dt){E.sample(ne,we,Tt);let Bt=B?nt[L*w+Pt]:1;ae-=Tt[0]*Bt*w,oe-=Tt[1]*Bt*F,lt==="reveal"?Yt=1-.72*Math.min(1,Tt[2]*Bt):lt==="repel"?Yt=1+Math.max(-1,Tt[2])*Bt:Fe=Tt[2]/3*Bt}let Ee=(L*w+Pt)*4;Lr(gt,ne,we,Rt,mt,(D[Ee]*.299+D[Ee+1]*.587+D[Ee+2]*.114)/255,T??void 0,(L*w+Pt)*ve),Hr(mt,Ut),(mt[0]||mt[1])&&(Ur(mt,ae,oe,w,F,se),ae=se[0],oe=se[1]),zt=mt[2],Yt*=mt[3];let he=(L*w+Pt)*4;Ce(D,w,F,ae,oe,ot);for(let Bt=0;Bt<3;Bt++){let ut=ot[Bt]/255,Dt=Wr(lt,ut,Fe)+zt;It[he+Bt]=Dt*255}It[he+3]=ot[3]*Yt}bi(It,w,F,y.dither,Nt),l.ctx.putImageData(new ImageData(It,w,F),0,0),Y=st?d:""}s.ctx.imageSmoothingEnabled=!1,s.ctx.drawImage(l.canvas,0,0,it,$)}else{let st=y.style==="pointillism";st&&r.marks&&I===void 0&&(I=r.marks()),ht=st&&I?.begin(it,$)?I:null;let It=Array.from(wi[y.style]??y.charset),L=ht?.ctx??s.ctx,Pt=Yr(y.ink),ne=lt==="ripple"||lt==="etch",we=ne&&Pt[0]*.299+Pt[1]*.587+Pt[2]*.114<90?[214,214,214]:Pt,ae=y.style==="ascii"||!!wi[y.style],oe=qe(y.style)?y.style:null,Fe=Math.max(3,Math.round(j*.92)),zt=Math.ceil(_+4),Yt=Math.ceil(j+4),Ee=[It.join(""),Fe,zt,Yt,y.ink,y.colorMode].join(":");if(ae&&Ee!==U){U=Ee,Ht(f.canvas,zt*It.length,Yt),f.ctx.clearRect(0,0,f.canvas.width,Yt),f.ctx.font=`${Fe}px monospace`,f.ctx.textBaseline="middle",f.ctx.textAlign="center",f.ctx.fillStyle=y.colorMode==="accent"?y.ink:"#ffffff",It.forEach((ut,Dt)=>f.ctx.fillText(ut,Dt*zt+zt/2,Yt/2)),A=null,N="";try{let ut=f.ctx.getImageData(0,0,f.canvas.width,f.canvas.height).data;A=It.map((Dt,fe)=>{let de=0;for(let Qt=0;Qt<f.canvas.height;Qt++)for(let ce=fe*zt;ce<(fe+1)*zt&&ce<f.canvas.width;ce++)de+=ut[(Qt*f.canvas.width+ce)*4+3];return de})}catch{A=null}}let he=ae&&y.color.levels!=="none";if(he&&A){let ut=U+":"+S.toFixed(2);ut!==N&&(N=ut,H=pn(A,S))}let Bt=Math.max(.001,v-M);if(y.style==="lego"&&g!==_){g=_,Ht(b.canvas,Math.ceil(_),Math.ceil(j));let ut=b.ctx;ut.clearRect(0,0,b.canvas.width,b.canvas.height),ut.fillStyle="rgba(255,255,255,.2)",ut.strokeStyle="rgba(0,0,0,.25)",ut.lineWidth=Math.max(.5,Zt*.6),ut.beginPath(),ut.arc(_/2,j/2,_*.28,0,Math.PI*2),ut.fill(),ut.stroke()}L.font=`${Fe}px monospace`,L.textBaseline="middle",L.textAlign="center";for(let ut=0;ut<F;ut++)for(let Dt=0;Dt<w;Dt++){let fe=Dt,de=ut,Qt=0,ce=0;if(dt){E.sample(Dt/w,ut/F,Tt);let at=B?nt[ut*w+Dt]:1;fe=Math.max(0,Math.min(w-1,Dt-Tt[0]*at*w)),de=Math.max(0,Math.min(F-1,ut-Tt[1]*at*F)),lt==="reveal"?ce=Math.min(1,Tt[2]*at)*.72:lt==="repel"?ce=-Math.max(-1,Tt[2])*at:Qt=Tt[2]/3*at}if(gt!=="none"){let at=(ut*w+Dt)*4;Lr(gt,Dt/w,ut/F,Rt,mt,(D[at]*.299+D[at+1]*.587+D[at+2]*.114)/255,T??void 0,(ut*w+Dt)*ve),Hr(mt,Ut),(mt[0]||mt[1])&&(Ur(mt,fe,de,w,F,se),fe=se[0],de=se[1])}Ce(D,w,F,fe,de,ot);let pe=0;if(ne&&Qt>.012&&(ot[3]?ot[3]>250&&ot[0]*.299+ot[1]*.587+ot[2]*.114<30:y.hover.scope==="outside")){let at=Math.min(1,(Qt-.012)/.12);pe=at*at*(3-2*at)}if(!ot[3]){if(!((pe||Qt>.03)&&y.hover.scope==="outside"&&Ai(lt)))continue;ot[0]=we[0],ot[1]=we[1],ot[2]=we[2],ot[3]=pe?255:Math.min(255,Qt*640)}let Ve=ot[0],_e=ot[1],Je=ot[2],Ar=(Ve*.299+_e*.587+Je*.114)/255,kt=he?Math.max(0,Math.min(1,(Ar-M)/Bt)):Ar;kt=Wr(lt,kt,Qt,!!oe&&Ae.settings.invert);let Et=Dt*_,vt=ut*j,ge=1,Re=kt;if(gt!=="none"){let at=mt[2]/(he?Math.max(.5,Bt):1);kt=Math.max(0,Math.min(1,kt+at)),Re=Math.max(0,Math.min(1,Re+at*(bt?.45:1)))}else Re=kt;pe&&(kt=Re=Math.max(kt,.1+pe*.45)),ge=(gt!=="none"?mt[3]:1)*ot[3]/255*(1-ce)*(pe?.3+pe*.45:1),!ae&&!oe&&y.colorMode==="accent"&&y.style!=="cmyk"?ge*=kt:he&&y.colorMode==="accent"&&(ge*=.32+.68*Math.pow(kt,S)),L.globalAlpha=ge;let be=(kt-Ar)*255,Kr=ht&&y.colorMode!=="accent"?y.ink:y.colorMode==="source"?`rgb(${Ve+be},${_e+be},${Je+be})`:y.colorMode==="gray"?`rgb(${Math.round(kt*255)},${Math.round(kt*255)},${Math.round(kt*255)})`:y.ink;if(L.fillStyle=Kr,oe)Ae.paint(L,oe,Dt,ut,Et,vt,_,kt,Kr,y.colorMode==="gray"?kt*255:Ve+be,y.colorMode==="gray"?kt*255:_e+be,y.colorMode==="gray"?kt*255:Je+be,y.colorMode);else if(ae){let at=he&&H?H[Math.round(Re*255)]:Math.max(0,Math.min(It.length-1,Math.round(Re*(It.length-1))));if(y.colorMode==="accent"?A?.[at]===0:It[at]===" ")continue;y.colorMode==="accent"?L.drawImage(f.canvas,at*zt,0,zt,Yt,Math.round(Et+(_-zt)/2),Math.round(vt+(j-Yt)/2),zt,Yt):L.fillText(It[at],Et+_/2,vt+j/2)}else if(y.style==="dots")L.beginPath(),L.arc(Et+_/2,vt+j/2,_*.48*Math.sqrt(kt),0,Math.PI*2),L.fill();else if(y.style==="led")L.beginPath(),L.arc(Et+_/2,vt+j/2,_*.39,0,Math.PI*2),L.fill(),L.globalAlpha=ge*.35,L.fillStyle="#ffffff",L.beginPath(),L.arc(Et+_*.43,vt+j*.4,_*.11,0,Math.PI*2),L.fill();else if(y.style==="hex"){let at=Et+_/2,ue=vt+j/2;L.beginPath();for(let Me=0;Me<6;Me++){let Ne=Math.PI/3*Me,me=at+Math.cos(Ne)*_*.49,Te=ue+Math.sin(Ne)*j*.49;Me===0?L.moveTo(me,Te):L.lineTo(me,Te)}L.closePath(),L.fill()}else if(y.style==="cmyk"){L.fillStyle="#ffffff",L.fillRect(Et,vt,_,j);let at=(wr,Ze)=>Math.max(0,Math.min(255,y.colorMode==="source"?wr+be:y.colorMode==="gray"?kt*255:Ze*kt)),ue=at(Ve,Pt[0]),Me=at(_e,Pt[1]),Ne=at(Je,Pt[2]),me=1-Math.max(ue,Me,Ne)/255,Te=Math.max(.001,1-me),Ui=[["#00ffff",(1-ue/255-me)/Te,.36,.36],["#ff00ff",(1-Me/255-me)/Te,.64,.36],["#ffff00",(1-Ne/255-me)/Te,.5,.66],["#000000",me,.5,.5]];L.globalCompositeOperation="multiply";for(let[wr,Ze,Hi,Oi]of Ui)Ze>0&&(L.fillStyle=wr,L.beginPath(),L.arc(Et+_*Hi,vt+j*Oi,_*.48*Math.sqrt(Math.max(0,Ze)),0,Math.PI*2),L.fill());L.globalCompositeOperation="source-over"}else if(y.style==="voxel"){let at=Et+_/2,ue=vt+j/2;L.beginPath(),L.moveTo(at,vt),L.lineTo(Et+_,vt+j*.25),L.lineTo(at,ue),L.lineTo(Et,vt+j*.25),L.closePath(),L.fill(),L.globalAlpha=ge*.72,L.beginPath(),L.moveTo(Et,vt+j*.25),L.lineTo(at,ue),L.lineTo(at,vt+j),L.lineTo(Et,vt+j*.75),L.closePath(),L.fill(),L.globalAlpha=ge*.42,L.beginPath(),L.moveTo(at,ue),L.lineTo(Et+_,vt+j*.25),L.lineTo(Et+_,vt+j*.75),L.lineTo(at,vt+j),L.closePath(),L.fill()}else{let at=y.style==="pixel"?0:Math.max(.5,_*.06);L.fillRect(Et,vt,_-at,j-at),y.style==="lego"&&L.drawImage(b.canvas,Et,vt),y.style==="disco"&&(L.fillStyle=`rgba(255,255,255,${.1+Xr(Dt,ut)*.25})`,L.fillRect(Et,vt,_-at,j*.35),L.fillStyle="rgba(0,0,0,.25)",L.fillRect(Et,vt+j*.65,_-at,j*.35-at))}}}if(s.ctx.globalAlpha=1,ht){let st=ht.finish();st&&s.ctx.drawImage(st,0,0)}(y.color.amount||y.lights.length)&&(Ht(p.canvas,it,$),p.ctx.clearRect(0,0,it,$),p.ctx.drawImage(s.canvas,0,0)),y.color.amount&&(s.ctx.save(),s.ctx.globalCompositeOperation=y.color.blend,s.ctx.globalAlpha=y.color.amount,s.ctx.fillStyle=y.color.tint,s.ctx.fillRect(0,0,it,$),s.ctx.restore());for(let st of y.lights){let It=st.radius*Math.max(it,$),L=s.ctx.createRadialGradient(st.x*it,st.y*$,0,st.x*it,st.y*$,It);L.addColorStop(0,st.color),L.addColorStop(1,"transparent"),s.ctx.save(),s.ctx.globalCompositeOperation="screen",s.ctx.globalAlpha=st.intensity,s.ctx.fillStyle=L,s.ctx.fillRect(0,0,it,$),s.ctx.restore()}(y.color.amount||y.lights.length)&&(s.ctx.globalCompositeOperation="destination-in",s.ctx.drawImage(p.canvas,0,0),s.ctx.globalCompositeOperation="source-over"),y.mask.enabled&&y.mask.shapes.length&&(Fi(m.ctx,it,$,y.mask.shapes),s.ctx.globalCompositeOperation=y.mask.invert?"destination-out":"destination-in",s.ctx.drawImage(m.canvas,0,0),s.ctx.globalCompositeOperation="source-over");let rt=h.ctx;rt.clearRect(0,0,it,$),rt.globalAlpha=y.backdrop.opacity;let St=y.backdrop;if(St.mode==="solid"&&(rt.fillStyle=St.color,rt.fillRect(0,0,it,$)),St.mode==="gradient"){let st=rt.createLinearGradient(0,0,it,$);st.addColorStop(0,St.color),st.addColorStop(1,St.color2),rt.fillStyle=st,rt.fillRect(0,0,it,$)}if(St.mode==="source"&&rt.drawImage(o.canvas,0,0),St.mode==="blurred"){let st=Math.max(1,St.blur);Ht(u.canvas,Math.max(2,Math.round(it/st)),Math.max(2,Math.round($/st))),u.ctx.drawImage(o.canvas,0,0,u.canvas.width,u.canvas.height),rt.imageSmoothingEnabled=!0,rt.drawImage(u.canvas,0,0,it,$)}rt.globalAlpha=1,y.effects.characterBloom>0&&(Ht(c.canvas,Math.max(2,Math.round(it/3)),Math.max(2,Math.round($/3))),c.ctx.clearRect(0,0,c.canvas.width,c.canvas.height),c.ctx.drawImage(s.canvas,0,0,c.canvas.width,c.canvas.height),rt.save(),rt.globalAlpha=y.effects.characterBloom*.8,rt.globalCompositeOperation="screen",rt.filter=`blur(${1+y.effects.characterBloom*4}px)`,rt.drawImage(c.canvas,0,0,it,$),rt.restore());let Kt=E.spotlight;if(Kt&&Kt[2]>.002){Ht(ft.canvas,it,$);let st=ft.ctx,It=Kt[3]*Math.min(it,$)*1.6;st.globalCompositeOperation="source-over",st.clearRect(0,0,it,$),st.drawImage(o.canvas,0,0),st.globalCompositeOperation="destination-in";let L=st.createRadialGradient(Kt[0]*it,Kt[1]*$,0,Kt[0]*it,Kt[1]*$,It),Pt=Math.min(1,Kt[2]*y.hover.strength/.55);for(let ne of[0,.2,.4,.6,.8,1])L.addColorStop(ne,`rgba(0,0,0,${Pt*Math.exp(-2.4*(ne*1.6)**2)*(1-ne)})`);st.fillStyle=L,st.fillRect(0,0,it,$),B&&(y.hover.scope??"all")!=="all"&&(st.imageSmoothingEnabled=!0,st.drawImage(ct.canvas,0,0,it,$)),st.globalCompositeOperation="source-over",rt.drawImage(ft.canvas,0,0)}rt.drawImage(s.canvas,0,0),x=J?tt:""}let qt=Object.entries(y.effects).some(([Rt,gt])=>!["angle","focus","blurType","characterBloom"].includes(Rt)&&typeof gt=="number"&&gt>0);a.clearRect(0,0,it,$),qt?(C===void 0&&(C=Mi(r.finishCanvas)),C?a.drawImage(C.render(h.canvas,y.effects,Nt,Zt),0,0):a.drawImage(h.canvas,0,0),r.finished(C?"gpu":"unavailable")):(a.drawImage(h.canvas,0,0),r.finished("none"))}let je={canvas:n,render:We,setPixelRatio(wt){Zt=Math.max(.1,Math.min(8,Number.isFinite(wt)?wt:1))},get pixelRatio(){return Zt},setBudget(wt){re=Math.max(256,Math.min(Ct,Number.isFinite(wt)?Math.round(wt):Ct))},get maxCells(){return re},configure(wt){y=ur(wt),te=Rr(y.color),Ae=Pr(y.print),yt.configure(y.color.denoise),le.configure(y.warps,y.warpEdge),z++},pointer:Le,leave(){E.leave()},get active(){return E.active},get settings(){return ur(y)},get capabilities(){return{gpuFinish:C!==null}},invalidate(){q=""},destroy(){C?.destroy(),I?.destroy(),I=void 0,le.clear(),yt.configure(0);for(let wt of[o,l,s,h,m,u,f,p,c,b,Q,ct,ft])wt.canvas.width=wt.canvas.height=1;P=null,D=new Uint8ClampedArray(0),Z=new Uint8ClampedArray(0),T=null,O=""}};return Ri.set(je,Ue),je}var yn=`#version 300 es\nlayout(location=1) in vec4 shape;\nlayout(location=2) in float angle;\nlayout(location=3) in vec4 color;\nlayout(location=4) in float path;\nuniform vec2 size;\n// Rim vertices per quadrant in this draw: a fan of 4 * slots triangles per ellipse, of which only the\n// quadrant\'s own segment count are not empty.\nuniform int slots;\nout vec4 ink;\nconst float W = 0.70710678118;\nvec2 turn(vec2 v, vec2 axis) { return vec2(v.x * axis.x - v.y * axis.y, v.x * axis.y + v.y * axis.x); }\n// Skia\'s Wang\'s formula for a conic at a quarter-pixel tolerance, rounded up to a power of two: how many line segments\n// the GPU canvas tessellates the curve into.\nfloat segments(vec2 p0, vec2 p1, vec2 p2) {\n vec2 center = (min(min(p0, p1), p2) + max(max(p0, p1), p2)) * 0.5;\n p0 -= center; p1 -= center; p2 -= center;\n float maxLength = sqrt(max(max(dot(p0, p0), dot(p1, p1)), dot(p2, p2)));\n vec2 dp = -2.0 * W * p1 + p0 + p2;\n float dw = abs(-2.0 * W + 2.0);\n float numer = length(dp) * 4.0 + max(0.0, maxLength * 4.0 - 1.0) * dw;\n float n = sqrt(max(numer / (4.0 * min(W, 1.0)), 0.0));\n return exp2(ceil(log2(max(1.0, ceil(n)))));\n}\nvoid main() {\n int triangle = gl_VertexID / 3, corner = gl_VertexID % 3;\n vec2 radii = shape.zw;\n vec2 axis = vec2(cos(angle), sin(angle));\n vec2 unit = vec2(0.0);\n if (corner != 0) {\n int k = triangle + corner - 1, quadrant = k / slots;\n // The quadrant\'s own conic, in the frame\'s pixels, decides its segment count.\n vec2 a0 = vec2(1.0, 0.0), a1 = vec2(1.0, 1.0), a2 = vec2(0.0, 1.0);\n if (quadrant == 1) { a0 = vec2(0.0, 1.0); a1 = vec2(-1.0, 1.0); a2 = vec2(-1.0, 0.0); }\n else if (quadrant == 2) { a0 = vec2(-1.0, 0.0); a1 = vec2(-1.0, -1.0); a2 = vec2(0.0, -1.0); }\n else if (quadrant == 3) { a0 = vec2(0.0, -1.0); a1 = vec2(1.0, -1.0); a2 = vec2(1.0, 0.0); }\n float n = min(float(slots), segments(turn(a0 * radii, axis), turn(a1 * radii, axis), turn(a2 * radii, axis)));\n float t = quadrant > 3 ? 0.0 : floor(float(k - quadrant * slots) * n / float(slots)) / n;\n float a = (1.0 - t) * (1.0 - t), b = 2.0 * W * t * (1.0 - t), c = t * t;\n unit = quadrant > 3 ? vec2(1.0, 0.0) : (a0 * a + a1 * b + a2 * c) / (a + b + c);\n }\n vec2 p = shape.xy + turn(unit * radii, axis);\n ink = vec4(color.rgb * color.a, color.a);\n // Drawn upside down and flipped back when resolved: the canvas\'s multisample pattern is the GPU\'s, top-left origin.\n // Each fill is one path: a later path is nearer, and a path\'s own shapes overlap on equal depth, so a sample covered\n // twice by one path is blended once, as a single filled path is.\n gl_Position = vec4(p / size * 2.0 - 1.0, 1.0 - path * exp2(-23.0), 1.0);\n}`,vn=`#version 300 es\nprecision highp float;\nin vec4 ink;\nout vec4 outColor;\nvoid main() { outColor = ink; }`;function Ii(){if(typeof OffscreenCanvas!="function")return null;let n=new OffscreenCanvas(300,150),t=n.getContext("webgl2",{alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1});if(!t)return null;let e=(P,U)=>{let E=t.createShader(P);if(t.shaderSource(E,U),t.compileShader(E),!t.getShaderParameter(E,t.COMPILE_STATUS))throw new Error(t.getShaderInfoLog(E)||"Dot shader failed");return E},r=t.createProgram();try{if(t.attachShader(r,e(t.VERTEX_SHADER,yn)),t.attachShader(r,e(t.FRAGMENT_SHADER,vn)),t.linkProgram(r),!t.getProgramParameter(r,t.LINK_STATUS))return null}catch{return null}let i=t.getUniformLocation(r,"size"),a=t.getUniformLocation(r,"slots"),o=t.createVertexArray();t.bindVertexArray(o);let l=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,l);let s=40;t.enableVertexAttribArray(1),t.vertexAttribPointer(1,4,t.FLOAT,!1,s,0),t.vertexAttribDivisor(1,1),t.enableVertexAttribArray(2),t.vertexAttribPointer(2,1,t.FLOAT,!1,s,16),t.vertexAttribDivisor(2,1),t.enableVertexAttribArray(3),t.vertexAttribPointer(3,4,t.FLOAT,!1,s,20),t.vertexAttribDivisor(3,1),t.enableVertexAttribArray(4),t.vertexAttribPointer(4,1,t.FLOAT,!1,s,36),t.vertexAttribDivisor(4,1),t.bindVertexArray(null);let h=Math.min(4,t.getParameter(t.MAX_SAMPLES)),m=t.createFramebuffer(),u=t.createRenderbuffer(),f=t.createRenderbuffer(),p=0,c=0,b=t.createFramebuffer(),g=t.createRenderbuffer(),M=new Float32Array(10*4096),v=0,S=1,k=1,A=0,H=0,N=new Float32Array(40),C=0,I=1,y=0,z=0,q=0,Y=1,x="#000000",D=new Map,V=new OffscreenCanvas(1,1).getContext("2d"),Z=P=>Math.max(0,Math.min(255,Number(P)))/255,T=P=>{let U=D.get(P);if(U)return U;let E=/^rgb\\(([-+.\\deE]+),([-+.\\deE]+),([-+.\\deE]+)\\)$/.exec(P),B=E?null:/^#([\\da-f]{2})([\\da-f]{2})([\\da-f]{2})$/i.exec(P);if(E&&E.slice(1).every(nt=>Number.isFinite(Number(nt))))U=[Z(E[1]),Z(E[2]),Z(E[3]),1];else if(B)U=[parseInt(B[1],16)/255,parseInt(B[2],16)/255,parseInt(B[3],16)/255,1];else{if(V.fillStyle="#010203",V.fillStyle=P,V.fillStyle==="#010203"&&!/^(#010203|rgb\\(1,2,3\\))$/i.test(P.replace(/\\s/g,"")))return null;V.clearRect(0,0,1,1),V.fillRect(0,0,1,1);let[nt,Q,ct,ft]=V.getImageData(0,0,1,1).data;U=[nt/255,Q/255,ct/255,ft/255]}return D.size>=4096&&D.clear(),D.set(P,U),U},O=(P,U,E,B,nt)=>{if(C*5+5>N.length){let ct=new Float32Array(N.length*2);ct.set(N),N=ct}let Q=C++*5;N[Q]=P,N[Q+1]=U,N[Q+2]=E,N[Q+3]=B,N[Q+4]=nt},w=P=>{if((v+P)*10>M.length){let U=new Float32Array(Math.max(M.length*2,(v+P)*10));U.set(M),M=U}},F=(P,U,E,B,nt,Q,ct,ft,At,Tt)=>{if(!(E>0&&B>0))return;let mt=v++*10;E>A&&(A=E),B>A&&(A=B),M[mt]=P,M[mt+1]=U,M[mt+2]=E,M[mt+3]=B,M[mt+4]=nt,M[mt+5]=Q,M[mt+6]=ct,M[mt+7]=ft,M[mt+8]=At,M[mt+9]=Tt};return{ctx:{get globalAlpha(){return I},set globalAlpha(P){P>=0&&P<=1&&(I=P)},get fillStyle(){return x},set fillStyle(P){if(typeof P!="string"||P===x)return;x=P;let U=T(P);U&&([y,z,q,Y]=U)},strokeStyle:"#000000",globalCompositeOperation:"source-over",font:"",textBaseline:"alphabetic",textAlign:"start",beginPath(){C=0},moveTo(){},closePath(){},arc(P,U,E){O(P,U,E,E,0)},ellipse(P,U,E,B,nt){O(P,U,E,B,nt)},fill(){let P=I*Y;if(P<=0)return;w(C);let U=++H;for(let E=0;E<C;E++){let B=E*5;F(N[B],N[B+1],N[B+2],N[B+3],N[B+4],y,z,q,P,U)}},fillEllipse(P,U,E,B,nt,Q,ct,ft){I<=0||(w(1),F(P,U,E,B,nt,Math.max(0,Math.min(255,Q))/255,Math.max(0,Math.min(255,ct))/255,Math.max(0,Math.min(255,ft))/255,I,++H))}},begin(P,U){return t.isContextLost()?!1:(S=P,k=U,v=0,C=0,A=0,H=0,I=1,x="#000000",y=z=q=0,Y=1,!0)},finish(){if(t.isContextLost())return null;if(n.width!==S&&(n.width=S),n.height!==k&&(n.height=k),(p!==S||c!==k)&&(p=S,c=k,t.bindRenderbuffer(t.RENDERBUFFER,u),t.renderbufferStorageMultisample(t.RENDERBUFFER,h,t.RGBA8,S,k),t.bindRenderbuffer(t.RENDERBUFFER,f),t.renderbufferStorageMultisample(t.RENDERBUFFER,h,t.DEPTH_COMPONENT24,S,k),t.bindFramebuffer(t.FRAMEBUFFER,m),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.RENDERBUFFER,u),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.RENDERBUFFER,f),t.bindRenderbuffer(t.RENDERBUFFER,g),t.renderbufferStorage(t.RENDERBUFFER,t.RGBA8,S,k),t.bindFramebuffer(t.FRAMEBUFFER,b),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.RENDERBUFFER,g)),t.bindFramebuffer(t.FRAMEBUFFER,m),t.viewport(0,0,S,k),t.clearColor(0,0,0,0),t.clearDepth(1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT),v){t.useProgram(r),t.uniform2f(i,S,k);let P=Math.sqrt(Math.max(0,2*A-.207)),U=Math.min(64,2**Math.ceil(Math.log2(Math.max(1,Math.ceil(P)))));t.uniform1i(a,U),t.enable(t.DEPTH_TEST),t.depthFunc(t.LESS),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.bindVertexArray(o),t.bindBuffer(t.ARRAY_BUFFER,l),t.bufferData(t.ARRAY_BUFFER,M.subarray(0,v*10),t.STREAM_DRAW),t.drawArraysInstanced(t.TRIANGLES,0,U*4*3,v),t.bindVertexArray(null)}return t.bindFramebuffer(t.READ_FRAMEBUFFER,m),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,b),t.blitFramebuffer(0,0,S,k,0,0,S,k,t.COLOR_BUFFER_BIT,t.NEAREST),t.bindFramebuffer(t.READ_FRAMEBUFFER,b),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),t.blitFramebuffer(0,0,S,k,0,k,S,0,t.COLOR_BUFFER_BIT,t.NEAREST),t.bindFramebuffer(t.FRAMEBUFFER,null),n},destroy(){t.deleteRenderbuffer(u),t.deleteRenderbuffer(f),t.deleteRenderbuffer(g),t.deleteFramebuffer(m),t.deleteFramebuffer(b),t.getExtension("WEBGL_lose_context")?.loseContext(),n.width=n.height=1}}}var Pi=self,jr=()=>new OffscreenCanvas(300,150),xn=()=>{let n=jr(),t=n.getContext("2d");if(!t)throw new Error("Canvas 2D is unavailable.");return{canvas:n,ctx:t}},Ot=null,vr=null,Sr=null,Ye=null,Di={video:!1,time:0,key:0},Li="none",xr=(n,t=[])=>Pi.postMessage(n,t),Sn={surface:xn,media:()=>Di,scene(n,t,e){n.clearRect(0,0,t,e),Sr&&n.drawImage(Sr,0,0)},finishCanvas:()=>jr(),marks:Ii,finished(n){Li=n}};Pi.onmessage=n=>{let t=n.data;try{switch(t.type){case"init":vr=jr(),Ot=Ci(vr,t.settings,t.limits,Sn),t.pixelRatio!==void 0&&Ot.setPixelRatio(t.pixelRatio),t.budget!==void 0&&Ot.setBudget(t.budget);break;case"source":Sr?.close(),Sr=t.scene,Ye={width:t.width,height:t.height},Di={video:t.video,time:t.time,key:t.key};break;case"pointer":Ot?.pointer(t.x,t.y,t.time);break;case"leave":Ot?.leave();break;case"configure":Ot?.configure(t.settings);break;case"budget":Ot?.setBudget(t.cells);break;case"ratio":Ot?.setPixelRatio(t.ratio);break;case"invalidate":Ot?.invalidate();break;case"advance":Ot&&Ye&&Ti(Ot,Ye,t.time,t.width,t.height,t.motionTime);break;case"render":{if(!Ot||!vr||!Ye){xr({type:"skip",seq:t.seq});break}let e=performance.now();Ot.render(Ye,t.time,t.width,t.height,t.motionTime);let r=performance.now()-e,i=vr.transferToImageBitmap();xr({type:"frame",seq:t.seq,bitmap:i,cost:r,active:Ot.active,finish:Li},[i]);break}}}catch(e){xr({type:"error",seq:t.type==="render"||t.type==="advance"?t.seq:-1,message:e instanceof Error?e.message:String(e)})}};xr({type:"ready"});})();\n'}}),r={};((t,i)=>{for(var a in i)e(t,a,{get:i[a],enumerable:!0})})(r,{default:()=>t});var n=a({"src/studio/worker-source.ts"(){s()}}),o=[{value:"none",label:"Off",group:"Still",description:"Keep the artwork still under the pointer."},{value:"trail",label:"Trail",group:"Change characters",description:"A fluid wake changes character density and settles behind your cursor."},{value:"dissolve",label:"Dissolve",group:"Change characters",description:"Erase a soft path through the characters; the image gradually reforms."},{value:"contour",label:"Contour",group:"Change characters",description:"Fine tonal rings trace your path without moving the grid."},{value:"etch",label:"Emboss",group:"Change characters",description:"Press a light-and-shadow impression into the characters; the grid stays fixed."},{value:"ripple",label:"Ripple rings",group:"Change characters",description:"Expanding light-and-shadow rings follow your stroke. Faster movement excites stronger rings; the grid stays still."},{value:"bleed",label:"Ink bleed",group:"Change characters",description:"Ink wells up where the cursor rests, spreads along the paper grain, then dries back."},{value:"water",label:"Water",group:"Move the image",description:"Soft ripples refract the image and settle after your stroke."},{value:"silk",label:"Silk",group:"Move the image",description:"Directional folds follow the movement of your hand."},{value:"vortex",label:"Vortex",group:"Move the image",description:"A swirling wake curls through the image."},{value:"magnetic",label:"Magnetic Pull",group:"Move the image",description:"The image gathers toward your stroke, then relaxes."},{value:"scatter",label:"Scatter",group:"Move the image",description:"Characters scatter in soft drifts from your stroke, then spring back into place."},{value:"elastic",label:"Elastic",group:"Move the image",description:"Push the image with your stroke; it recoils past its rest once, then settles."},{value:"lens",label:"Lens wake",group:"Move the image",description:"A soft magnifying wake brings details closer, then relaxes back into focus."},{value:"smudge",label:"Smudge",group:"Move the image",description:"Drag the image in the direction of your stroke; a smooth, lingering pull settles without a bounce."},{value:"loupe",label:"Loupe",group:"Follow the cursor",description:"A glass loupe glides after the cursor and magnifies what it covers, easing through a soft rim."},{value:"reveal",label:"Reveal",group:"Follow the cursor",description:"A soft spotlight shows the original photograph through the characters."},{value:"repel",label:"Repel",group:"Follow the cursor",description:"Characters part around the cursor and spring back with one soft rebound when it leaves."},{value:"tilt",label:"Tilt",group:"Follow the cursor",description:"The image leans toward the cursor; bright areas sit nearer and move more, like a parallax card."},{value:"haze",label:"Heat haze",group:"Follow the cursor",description:"A rising shimmer bends the characters above the cursor, livelier while you move."}],h={rake:"silk"},l={radius:{label:"Hover size",min:.1,max:1,step:.05,default:.2},strength:{label:"Hover strength",min:0,max:1,step:.05,default:.55},decay:{label:"Linger",min:0,max:1,step:.05,default:.5}},c={effect:"trail",strength:.55,radius:.2,decay:.5,scope:"all",edgeSafe:!1};function m(t){if("string"==typeof t)return t in h?h[t]:o.some(e=>e.value===t)?t:void 0}var u=t=>"subject"===t||"outside"===t?t:"all";function f(t,e,i,a,s){if(!(s<1))for(let r=0;r<2;r++){for(let r=0;r<a;r++){let a=0;const n=r*i;for(let e=-s;e<=s;e++)a+=t[n+Math.max(0,Math.min(i-1,e))];for(let r=0;r<i;r++)e[n+r]=a/(2*s+1),a+=t[n+Math.min(i-1,r+s+1)]-t[n+Math.max(0,r-s)]}for(let r=0;r<i;r++){let n=0;for(let t=-s;t<=s;t++)n+=e[Math.max(0,Math.min(a-1,t))*i+r];for(let o=0;o<a;o++)t[o*i+r]=n/(2*s+1),n+=e[Math.min(a-1,o+s+1)*i+r]-e[Math.max(0,o-s)*i+r]}}}var d=new Float32Array(0);function p(t,e,i,a,s){const r=e*i,n=s&&s.width===e&&s.height===i?s:{width:e,height:i,subject:new Float32Array(r),depth:new Float32Array(r),key:"none"},{subject:o,depth:h}=n;let l=0;for(let e=0;e<r;e++)t[4*e+3]<250&&l++;const c=e=>(.2126*t[4*e]+.7152*t[4*e+1]+.0722*t[4*e+2])/255;let m="none",u=0;if(l>.01*r)m="alpha";else if(a)m="mask";else{let t=0,a=0,s=0;const r=Math.max(1,Math.round(.03*Math.min(e,i)));for(let n=0;n<i;n++)for(let o=0;o<e;o++){if(o>=r&&n>=r&&o<e-r&&n<i-r)continue;const h=c(n*e+o);t+=h,a+=h*h,s++}u=t/Math.max(1,s);Math.sqrt(Math.max(0,a/Math.max(1,s)-u*u))<.07&&(m="ground")}for(let e=0;e<r;e++){const i=t[4*e+3]/255,s=c(e);let r=1;if("alpha"===m)r=i;else if("ground"===m){const t=Math.max(0,Math.min(1,(Math.abs(s-u)-.035)/.12));r=t*t*(3-2*t)}o[e]=r*(a?Math.max(0,Math.min(1,a[e])):1),h[e]=s*i}n.key=m,d.length<r&&(d=new Float32Array(r));const p=d;return f(o,p,e,i,Math.max(1,Math.round(.02*Math.min(e,i)))),f(h,p,e,i,Math.max(1,Math.round(.035*Math.min(e,i)))),n}function g(t,e,i="ground"){return"none"===i?1:"subject"===t?e:"outside"===t?1-e:1}var M={caustics:"sheen",grain:"shimmer",trace:"relight",tidal:"current",weave:"current",breeze:"current",reform:"develop",print:"develop",unfold:"develop"},x=[{value:"none",mode:"none",group:"Still",label:"Off",description:"Keep the image still. Hover stays available."},{value:"relight",mode:"relight",group:"Light",label:"Relight",description:"A key light circles the subject and models its own relief, like moving a lamp around a sculpture."},{value:"sheen",mode:"sheen",group:"Light",label:"Specular sweep",description:"One slow pass of light glances across the highlights and follows their form, then rests."},{value:"glow",mode:"glow",group:"Light",label:"Highlight bloom",description:"The brightest areas breathe a soft halo into their surroundings. Shadows stay deep."},{value:"shimmer",mode:"shimmer",group:"Light",label:"Glints",description:"Sparse glints on bright fine detail, like light on water, metal or an eye. Everything else holds still."},{value:"parallax",mode:"parallax",group:"Depth",label:"Parallax",description:"A slow camera drift: the subject moves against its background, read from the photo’s own depth cues."},{value:"push",mode:"push",group:"Depth",label:"Slow push",description:"A gentle push toward the subject and back, with nearer areas moving slightly more."},{value:"focus",mode:"focus",group:"Depth",label:"Focus pull",description:"Focus racks from the subject to the background and back; the characters soften out of focus."},{value:"mist",mode:"mist",group:"Atmosphere",label:"Mist",description:"Soft mist drifts through the distance and plain areas, leaving the subject clear."},{value:"current",mode:"current",group:"Atmosphere",label:"Drift",description:"Water swells and glints, falls stream down, sky and clouds drift slowly, like a cinemagraph. Subjects and buildings hold still."},{value:"develop",mode:"develop",group:"Reveal",label:"Develop",description:"The image holds, fades, then develops back in from its highlights to its shadows, like a print in the tray."}];function v(t){const e=t&&Object.prototype.hasOwnProperty.call(M,t)?M[t]:t;return x.find(t=>t.value===e||t.mode===e)?.mode??"none"}var y=t=>Math.max(0,Math.min(1,t)),b=(t,e,i)=>{const a=y((i-t)/(e-t));return a*a*(3-2*a)},w=(t,e)=>{const i=(.06711056*t+.00583715*e)%1*52.9829189;return i-Math.floor(i)},k=class{constructor(){this.last=null,this.mode="none",this.phase=0}update(t,e,i=1){const a=v(e);return Number.isFinite(t)?((a!==this.mode||null!==this.last&&t<this.last)&&(this.mode=a,this.phase=0,this.last=t),null!==this.last&&(this.phase+=Math.max(0,t-this.last)*Math.max(.1,Math.min(3,Number.isFinite(i)?i:1))),this.last=t,this.phase):this.phase}};function A(t,e,i,a,s,r=.5,n,o=0){if(s[0]=s[1]=s[2]=0,s[3]=1,"none"===t)return s;r=y(r);const h=n?n[o]:r,l=n?n[o+1]:.5+.5*y(1-2*Math.hypot(e-.5,i-.55)),c=n?n[o+2]:b(.55,1,r)**2,m=n?n[o+3]:.5,u=n?n[o+4]:0,f=n?n[o+5]:0,d=a*Math.PI/6,p=(a%12+12)%12,g=b(0,.12,Math.min(e,1-e,i,1-i));if("relight"===t){const t=d+.6,a=Math.cos(t),n=Math.sin(t),o=Math.max(-1,Math.min(1,u*a+f*n))+.35*(a*(e-.5)+n*(i-.5));s[2]=.2*o*(.3+.7*b(.04,.3,h)*(1-.6*b(.82,1,r)))}else if("sheen"===t){const t=1.9*b(0,8,p)-.35,a=(.75*e+.45*i)/1.2+.05*(.75*u+.45*f),n=Math.exp(-(((a-t)/.12)**2));s[2]=n*b(.3,.8,h)*(1-.5*b(.9,1,r))*.45}else if("glow"===t){const t=.5-.5*Math.cos(d),e=1-.8*t;s[2]=.2*b(e-.3,e+.02,c)*Math.sqrt(c)*(1-.65*r)+.05*t*b(.6,.95,r)}else if("shimmer"===t){const t=w(Math.floor(160*e),Math.floor(100*i))*Math.PI*2,a=Math.pow(.5+.5*Math.cos(2*d+t),28);s[2]=a*b(.5,.88,r)*(.35+.65*b(.1,.55,m))*.42}else if("parallax"===t){const t=l-.45;s[0]=16*t*Math.sin(d)*g,s[1]=7*t*Math.sin(2*d)*g}else if("push"===t){const t=.045*(.5-.5*Math.cos(d))*(.7+.6*l)*960,a=n?n[o+6]:.5,r=n?n[o+7]:.5;s[0]=(e-a)*t,s[1]=(i-r)*t}else if("focus"===t){const t=Math.sin(d),e=t*t*b(.35,.85,t>=0?1-l:l);s[2]=(h-r)*e*.75}else if("mist"===t){const t=Math.pow(1-l,1.5)*(1-.6*m),a=.5*Math.sin(4.1*e-d+.9*Math.sin(3.3*i+d))+.3*Math.sin(7.3*e+2.1*i-2*d+1.1*Math.sin(2.7*e-5.1*i+d))+.2*Math.sin(5.7*i-1.9*e+d);s[2]=b(-.3,.9,a)*t*.16*(1-.55*r)}else if("current"===t){const t=n?.[o+8]??0,a=n?.[o+9]??0,h=n?.[o+10]??0,c=b(0,.06,Math.min(e,1-e,i,1-i)),u=n?0:(1-.4*m)*(1-.8*l)*g,f=t=>14*i-t+1.5*Math.sin(3*e+t),p=t=>16*i+2*e-t,M=t=>29*i-3*e-2*t,x=t=>1.7*e+2.3*i-t,v=t=>26*i+1.5*Math.sin(40*e)-2*t;s[0]=7*(Math.sin(f(d))-Math.sin(f(0))+.43*(Math.sin(5*e-3*i+d)-Math.sin(5*e-3*i)))*u+(3.5*(Math.sin(p(d))-Math.sin(p(0)))+1.5*(Math.sin(M(d))-Math.sin(M(0))))*t*c+5*(Math.sin(x(d))-Math.sin(x(0)))*a*c,s[1]=2*(Math.sin(11*e+d)-Math.sin(11*e))*u+.8*(Math.cos(p(d))-Math.cos(p(0)))*t*c+12*(Math.sin(v(d))-Math.sin(v(0)))*h*c;const y=Math.pow(.5+.5*Math.cos(2*d+9*e-4*i+6.2831853*w(Math.floor(160*e),Math.floor(100*i))),24)-Math.pow(.5+.5*Math.cos(9*e-4*i+6.2831853*w(Math.floor(160*e),Math.floor(100*i))),24);s[2]=.03*(Math.cos(f(d))-Math.cos(f(0)))*u+(y*b(.5,.85,r)*.3+.025*(Math.cos(p(d))-Math.cos(p(0))))*t*c+.08*(Math.cos(v(d))-Math.cos(v(0)))*h*c}else if("develop"===t){const t=b(7,8.5,p),a=y((p-8.5)/3.5),n=p<8.5?1-t:b(0,1,(1.45*a-(1-r)+.06*(w(Math.floor(160*e),Math.floor(100*i))-.5))/.3);s[2]=.3*-(1-n),s[3]=1-.9*(1-n)}return s}function S(t){const e=Math.floor(t),i=Math.max(0,Math.min(1,(t-e-.2)/.6));return e+i*i*(3-2*i)}function F(t,e,i,a,s,r){return r[0]=S(Math.max(0,Math.min(a-1,e-t[0]/960*a))),r[1]=S(Math.max(0,Math.min(s-1,i-t[1]/960*s))),r}function E(t,e){const i=Math.max(0,Math.min(2,Number.isFinite(e)?e:1));return t[0]*=i,t[1]*=i,t[2]*=i,t[3]=y(1+(t[3]-1)*i),t}var R=["rgb","red","green","blue"],P=t=>Math.max(0,Math.min(1,t));function T(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*P(i[0]))/255;!e.has(t)&&e.size>=16||e.set(t,P(i[1]))}return[...e].sort((t,e)=>t[0]-e[0])}function I(t){const e=t&&"object"==typeof t?t:{};return Object.fromEntries(R.map(t=>[t,T(e[t])]))}function C(t){const e=T(t),i=e.length,a=e.slice(1).map((t,i)=>t[0]-e[i][0]),s=e.slice(1).map((t,i)=>(t[1]-e[i][1])/a[i]),r=new Float64Array(i);r[0]=s[0],r[i-1]=s[i-2];for(let t=1;t<i-1;t++){const e=s[t-1],i=s[t];if(e*i<=0)continue;const n=2*a[t]+a[t-1],o=a[t]+2*a[t-1];r[t]=(n+o)/(n/e+o/i)}const n=new Uint8Array(256);let o=0;for(let t=0;t<256;t++){const s=t/255;for(;o<i-2&&s>e[o+1][0];)o++;const h=a[o],l=(s-e[o][0])/h,c=l*l,m=c*l,u=(2*m-3*c+1)*e[o][1]+(m-2*c+l)*h*r[o]+(-2*m+3*c)*e[o+1][1]+(m-c)*h*r[o+1];n[t]=Math.round(255*P(u))}return n}function D(t,e,i,a,s,r){a=Math.max(0,Math.min(e-1,a)),s=Math.max(0,Math.min(i-1,s));const n=Math.floor(a),o=Math.floor(s),h=a-n,l=s-o,c=4*(o*e+n);if(0===h&&0===l){for(let e=0;e<4;e++)r[e]=t[c+e];return}const m=4*(o*e+Math.min(e-1,n+1)),u=4*(Math.min(i-1,o+1)*e+n),f=4*(Math.min(i-1,o+1)*e+Math.min(e-1,n+1)),d=(1-h)*(1-l)*t[c+3],p=h*(1-l)*t[m+3],g=(1-h)*l*t[u+3],M=h*l*t[f+3],x=d+p+g+M;for(let e=0;e<3;e++)r[e]=x?(t[c+e]*d+t[m+e]*p+t[u+e]*g+t[f+e]*M)/x:0;r[3]=x}function N(t,e,i,a,s,r){if(a>=0&&a<=e-1&&s>=0&&s<=i-1)return D(t,e,i,a,s,r);if(r[0]=r[1]=r[2]=r[3]=0,a<=-1||a>=e||s<=-1||s>=i)return;const n=Math.floor(a),o=Math.floor(s),h=a-n,l=s-o;for(let a=0;a<=1;a++)for(let s=0;s<=1;s++){const c=n+s,m=o+a;if(c<0||c>=e||m<0||m>=i)continue;const u=4*(m*e+c),f=(s?h:1-h)*(a?l:1-l)*t[u+3];r[0]+=t[u]*f,r[1]+=t[u+1]*f,r[2]+=t[u+2]*f,r[3]+=f}r[3]&&(r[0]/=r[3],r[1]/=r[3],r[2]/=r[3])}var O=[{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}],U=(t,e,i,a)=>"number"==typeof t&&Number.isFinite(t)?Math.max(i,Math.min(a,t)):e;function L(t){if(!Array.isArray(t))return[];const e=[];for(const i of t.slice(0,64))if(i&&"object"==typeof i&&O.some(t=>t.value===i.type)&&(e.push({type:i.type,enabled:!1!==i.enabled,amount:U(i.amount,.35,-1,1),x:U(i.x,.5,0,1),y:U(i.y,.5,0,1),radius:U(i.radius,.55,.05,2),angle:U(i.angle,0,-180,180),frequency:U(i.frequency,5,1,24)}),8===e.length))break;return e}var q=2*Math.PI,X=(t,e)=>{let i=Math.imul(t,374761393)^Math.imul(e,668265263);return i=Math.imul(i^i>>>13,1274126177),((i^i>>>16)>>>0)/4294967296},B=class{constructor(t=[],e="clamp"){this.warps=[],this.signature="",this.geometry="",this.coordinates=new Float32Array(0),this.output=new Uint8ClampedArray(0),this.sampled=[0,0,0,0],this.edge="clamp",this.configure(t,e)}configure(t=[],e="clamp"){const i=L(t).filter(t=>t.enabled&&0!==t.amount),a=JSON.stringify(i);this.edge="transparent"===e?"transparent":"clamp",a!==this.signature&&(this.signature=a,this.geometry="",this.warps=i.map(t=>({...t,cos:Math.cos(t.angle*Math.PI/180),sin:Math.sin(t.angle*Math.PI/180)})),i.length||this.clear())}get active(){return this.warps.length>0}apply(t,e,i,a=e/i){if(!this.active)return t;if(!Number.isInteger(e)||!Number.isInteger(i)||e<1||i<1||e*i*4!==t.length||!Number.isFinite(a)||a<=0)throw new Error("Warp dimensions do not match the source.");const s=`${e}:${i}:${a}`;if(s!==this.geometry){this.coordinates.length!==e*i*2&&(this.coordinates=new Float32Array(e*i*2));const t=Math.max(1,a),r=Math.max(1,1/a);for(let a=0;a<i;a++)for(let s=0;s<e;s++){let n=(s+.5)/e,o=(a+.5)/i;for(let e=this.warps.length-1;e>=0;e--){const i=this.warps[e],a=(n-i.x)*t/i.radius,s=(o-i.y)*r/i.radius,h=a*a+s*s;if(h>=1)continue;const l=Math.sqrt(h),c=(1-h)*(1-h),m=i.amount;let u=a,f=s;if("twirl"===i.type||"zigzag"===i.type){const t="twirl"===i.type?-m*q*c:.65*m*(2/Math.PI*Math.asin(Math.sin(l*q*i.frequency)))*c,e=Math.cos(t),r=Math.sin(t);u=a*e-s*r,f=a*r+s*e}else if("pinch"===i.type){const t=Math.exp(2*m*c);u=a*t,f=s*t}else if("sphere"===i.type&&l>0){const t=1+m*c*(2*Math.asin(l)/Math.PI/l-1);u=a*t,f=s*t}else if("ripple"===i.type&&l>0){const t=1+.12*m*Math.sin(l*q*i.frequency)*c/l;u=a*t,f=s*t}else if("shear"===i.type){const t=-a*i.sin+s*i.cos;u-=m*t*.9*c*i.cos,f-=m*t*.9*c*i.sin}else if("smudge"===i.type)u-=.65*m*c*i.cos,f-=.65*m*c*i.sin;else if("polar"===i.type){const t=a*i.cos+s*i.sin,e=-a*i.sin+s*i.cos,r=Math.atan2(e,t),n=m>0?r/Math.PI:Math.cos(t*Math.PI)*(e+1)/2,o=m>0?2*l-1:Math.sin(t*Math.PI)*(e+1)/2,h=n*i.cos-o*i.sin,d=n*i.sin+o*i.cos;u+=(h-a)*Math.abs(m)*c,f+=(d-s)*Math.abs(m)*c}else if("fragment"===i.type){const t=Math.floor((a*i.cos+s*i.sin)*i.frequency),e=Math.floor((-a*i.sin+s*i.cos)*i.frequency),r=(X(t,e)-.5)*m*.5*c,n=(X(e+71,t-31)-.5)*m*.5*c;u+=r*i.cos-n*i.sin,f+=r*i.sin+n*i.cos}n=i.x+u*i.radius/t,o=i.y+f*i.radius/r}const h=2*(a*e+s);this.coordinates[h]=n*e-.5,this.coordinates[h+1]=o*i-.5}this.geometry=s}this.output.length!==t.length&&(this.output=new Uint8ClampedArray(t.length));const r=t===this.output?t.slice():t,n="transparent"===this.edge?N:D;for(let a=0,s=0;a<t.length;a+=4,s+=2){n(r,e,i,this.coordinates[s],this.coordinates[s+1],this.sampled);for(let t=0;t<4;t++)this.output[a+t]=this.sampled[t]}return this.output}clear(){this.coordinates=new Float32Array(0),this.output=new Uint8ClampedArray(0),this.geometry=""}},z=["stipple","engraving","crosshatch","woodblock","risograph","pointillism"];function Y(t){return z.includes(t)}var j={density:1,weight:1,angle:-35,roughness:.35,invert:!1,secondaryInk:"#ec6752",registration:.2,seed:7};function W(t){const e=t&&"object"==typeof t&&!Array.isArray(t)?t:{},i=(t,i,a)=>{const s=e[t];return"number"==typeof s&&Number.isFinite(s)?Math.max(i,Math.min(a,s)):j[t]};return{density:i("density",0,2),weight:i("weight",.25,2),angle:i("angle",-180,180),roughness:i("roughness",0,1),invert:!0===e.invert,secondaryInk:"string"==typeof e.secondaryInk&&/^#[\da-f]{6}$/i.test(e.secondaryInk)?e.secondaryInk:j.secondaryInk,registration:i("registration",0,1),seed:Math.round(i("seed",0,65535))}}var H=["ascii","blocks","braille","dots","lines","cross","diagonal","diamond","mixed","pixel","mosaic","lego","voxel","disco","dither","hex","led","cmyk",...z],G=["none","bayer2","bayer4","bayer8","bayer16","floyd-steinberg","atkinson","stucki","sierra","sierra-lite","burkes","jarvis","halftone","lines","noise","vertical-lines","diagonal-lines","radial","blue-noise"],V=["source-over","multiply","screen","overlay","soft-light","hard-light","color-dodge","color-burn","hue","saturation","color","luminosity"],K={original:[],gray4:["#000000","#555555","#aaaaaa","#ffffff"],gray8:["#000000","#242424","#494949","#6d6d6d","#929292","#b6b6b6","#dbdbdb","#ffffff"],rgb8:["#000000","#ff0000","#00ff00","#0000ff","#ffff00","#ff00ff","#00ffff","#ffffff"],cyberpunk:["#08081a","#3c1670","#ed299a","#29dfef","#fff7bf"],pastel:["#393448","#a5b4d4","#9ed9c6","#e7aac1","#f5e8be"],mono:["#080808","#f2f2e8"],asciify:["#080808","#625b38","#a19558","#e8b900"],gameboy:["#0f380f","#306230","#8bac0f","#9bbc0f"],cga:["#000000","#55ffff","#ff55ff","#ffffff"],pico8:["#000000","#1d2b53","#7e2553","#008751","#ab5236","#5f574f","#c2c3c7","#fff1e8","#ff004d","#ffa300","#ffec27","#00e436","#29adff","#83769c","#ff77a8","#ffccaa"],c64:["#000000","#ffffff","#880000","#aaffee","#cc44cc","#00cc55","#0000aa","#eeee77","#dd8855","#664400","#ff7777","#333333","#777777","#aaff66","#0088ff","#bbbbbb"],amber:["#100b00","#5f3b00","#c98014","#ffd17c"],ice:["#081b29","#25586e","#69a6b3","#d9ece7"],risograph:["#f4ebd0","#f2594b","#2853a5","#29232e"],sepia:["#201b17","#6b5039","#b49868","#f6e6c5"],nord:["#2e3440","#4c566a","#88c0d0","#eceff4"],dusk:["#211b35","#654271","#c3788c","#f5c9a3"],forest:["#101f1b","#355747","#87a16f","#e4e3ba"],ocean:["#071b33","#17577f","#3fa7a4","#d9efde"],newsprint:["#191919","#666666","#aaaaaa","#eee9df"],custom:["#0b0b0a","#e6e3da"]},J={version:1,aspectRatio:"original",style:"ascii",cellSize:6,charset:" .:-=+*#%@",colorMode:"accent",ink:"#e6e3da",print:{...j},crop:{x:.5,y:.5,zoom:1,rotation:0},warps:[],warpEdge:"clamp",backdrop:{mode:"solid",color:"#080808",color2:"#1d1d1b",blur:12,opacity:1},color:{brightness:0,contrast:1,saturation:1,grayscale:0,tint:"#e6e3da",amount:0,blend:"source-over",blackPoint:0,whitePoint:1,gamma:1,shadows:0,highlights:0,curves:{rgb:[[0,0],[1,1]],red:[[0,0],[1,1]],green:[[0,0],[1,1]],blue:[[0,0],[1,1]]},denoise:0,levels:"auto"},dither:{algorithm:"none",palette:"mono",colors:["#080808","#e6e3da"],amount:1,scale:2,threshold:.5,motion:"none",speed:1,direction:45,colorSpace:"rgb"},mask:{enabled:!1,invert:!1,shapes:[]},lights:[],effects:{bloom:0,characterBloom:0,grain:0,dust:0,scanlines:0,crt:0,prism:0,rgbSplit:0,sharpen:0,vignette:0,glitch:0,pixelate:0,blur:0,blurType:"gaussian",angle:0,focus:.5,halftone:0},motion:{type:"none",speed:1,amount:1},hover:{effect:"trail",strength:.55,radius:.2,edgeSafe:!1}},Q=t=>t&&"object"==typeof t&&!Array.isArray(t)?t:{},Z=(t,e,i,a)=>"number"==typeof t&&Number.isFinite(t)?Math.min(a,Math.max(i,t)):e,_=(t,e)=>"string"==typeof t&&/^#[\da-f]{6}$/i.test(t)?t:e,$=(t,e,i)=>e.includes(t)?t:i;function tt(t={}){const e=Q(t),i=J;if(void 0!==e.version&&1!==e.version)throw new Error("Unsupported studio settings version. Update asciify-engine.");const a=Q(e.crop),s=Q(e.backdrop),r=Q(e.color),n=Q(e.dither),o=Q(e.mask),h=Q(e.effects),f=Q(e.motion),d=Q(e.hover),p={...i.effects};for(const t of["bloom","characterBloom","grain","dust","scanlines","crt","prism","rgbSplit","sharpen","vignette","glitch","pixelate","halftone"])p[t]=Z(h[t],0,0,1);p.blur=Z(h.blur,0,0,24),p.blurType=$(h.blurType,["gaussian","directional","radial","progressive"],i.effects.blurType),p.angle=Z(h.angle,0,-180,180),p.focus=Z(h.focus,.5,0,1);let g=2048;return{version:1,aspectRatio:$(e.aspectRatio,["original","16:9","9:16","1:1","4:3","3:4","21:9"],"original"),style:$(e.style,H,i.style),cellSize:Z(e.cellSize,i.cellSize,Y(String(e.style))||["pixel","mosaic","lego","voxel","disco","dots","hex","led","cmyk"].includes(String(e.style))?1:3,60),charset:"string"==typeof e.charset&&e.charset.length?Array.from(e.charset).slice(0,128).join(""):i.charset,colorMode:$(e.colorMode,["accent","source","gray"],i.colorMode),ink:_(e.ink,i.ink),print:W(e.print),warps:L(e.warps),warpEdge:$(e.warpEdge,["clamp","transparent"],"clamp"),crop:{x:Z(a.x,.5,0,1),y:Z(a.y,.5,0,1),zoom:Z(a.zoom,1,1,5),rotation:90*Math.round(Z(a.rotation,0,-360,360)/90)},backdrop:{mode:$(s.mode,["solid","transparent","source","blurred","gradient"],i.backdrop.mode),color:_(s.color,i.backdrop.color),color2:_(s.color2,i.backdrop.color2),blur:Z(s.blur,12,0,32),opacity:Z(s.opacity,1,0,1)},color:{brightness:Z(r.brightness,0,-1,1),contrast:Z(r.contrast,1,0,3),saturation:Z(r.saturation,1,0,3),grayscale:Z(r.grayscale,0,0,1),tint:_(r.tint,i.color.tint),amount:Z(r.amount,0,0,1),blend:$(r.blend,V,i.color.blend),blackPoint:Z(r.blackPoint,0,0,.99),whitePoint:Math.max(Z(r.blackPoint,0,0,.99)+1/255,Z(r.whitePoint,1,1/255,1)),gamma:Z(r.gamma,1,.25,4),shadows:Z(r.shadows,0,-1,1),highlights:Z(r.highlights,0,-1,1),curves:I(r.curves),denoise:Z(r.denoise,0,0,1),levels:"none"===r.levels?"none":"auto"},dither:{algorithm:$(n.algorithm,G,"none"),palette:"string"==typeof n.palette&&Object.prototype.hasOwnProperty.call(K,n.palette)?n.palette:"mono",colors:Array.isArray(n.colors)&&n.colors.length>=2?n.colors.slice(0,32).map(t=>_(t,"#000000")):[...i.dither.colors],amount:Z(n.amount,1,0,2),scale:Math.round(Z(n.scale,2,1,12)),threshold:Z(n.threshold,.5,0,1),motion:$(n.motion,["none","drift","shimmer"],"none"),speed:Z(n.speed,1,.1,3),direction:Z(n.direction,45,-180,180),colorSpace:$(n.colorSpace,["rgb","luminance"],"rgb")},mask:{enabled:!0===o.enabled,invert:!0===o.invert,shapes:Array.isArray(o.shapes)?o.shapes.slice(0,64).map(t=>{const e=Q(t),i=$(e.kind,["rectangle","ellipse","brush"],"rectangle"),a="brush"===i&&Array.isArray(e.points)?e.points.slice(0,g).map(t=>Array.isArray(t)?[Math.round(1e4*Z(t[0],0,0,1))/1e4,Math.round(1e4*Z(t[1],0,0,1))/1e4]:[0,0]):[];return g-=a.length,{kind:i,x:Z(e.x,0,0,1),y:Z(e.y,0,0,1),width:Z(e.width,.5,0,1),height:Z(e.height,.5,0,1),size:Z(e.size,.05,.005,.5),points:a}}):[]},lights:Array.isArray(e.lights)?e.lights.slice(0,4).map(t=>{const e=Q(t);return{x:Z(e.x,.5,0,1),y:Z(e.y,.5,0,1),radius:Z(e.radius,.3,.02,1),intensity:Z(e.intensity,.5,0,1),color:_(e.color,"#ffffff")}}):[],effects:p,motion:{type:$("string"==typeof f.type?v(f.type):f.type,x.map(t=>t.mode),"none"),speed:Z(f.speed,1,.1,3),amount:Z(f.amount,1,0,2)},hover:{effect:m(d.effect)??c.effect,strength:Z(d.strength,l.strength.default,l.strength.min,l.strength.max),radius:Z(d.radius,l.radius.default,l.radius.min,l.radius.max),edgeSafe:!0===d.edgeSafe,..."all"!==u(d.scope)&&{scope:u(d.scope)},....5!==Z(d.decay,.5,0,1)&&{decay:Z(d.decay,.5,0,1)}}}}function et(t,e,i,a,s){const r=Math.abs(s.rotation/90)%2==1,n=r?e:t,o=r?t:e,h=Math.max(i/n,a/o)*s.zoom;return{width:n*h,height:o*h,x:(i-n*h)*s.x,y:(a-o*h)*s.y,scale:h,rotated:r}}function it(t,e,i){if(Math.abs(i.crop.rotation/90)%2==1&&([t,e]=[e,t]),"original"===i.aspectRatio)return[t,e];const[a,s]=i.aspectRatio.split(":").map(Number);return t/e>a/s?[Math.round(e*a/s),e]:[t,Math.round(t*s/a)]}function at(t,e){const i={...t,...e};for(const a of["crop","backdrop","color","dither","mask","effects","motion","hover","print"])e[a]&&Object.assign(i,{[a]:{...t[a],...e[a]}});return e.color?.curves&&(i.color.curves={...t.color.curves,...e.color.curves}),tt(i)}function st(t,e,i,a=12e3,s=1){const r=Math.max(2,Number.isFinite(t)?t:960),n=Math.max(2,Number.isFinite(e)?e:540),o=Math.max(1,Math.floor(Number.isFinite(a)?a:12e3)),h=Math.max(.01,Number.isFinite(s)?s:1),l=Y(i.style)||["dither","pixel","mosaic","lego","voxel","disco","dots","hex","led","cmyk"].includes(i.style)?1:1.65;let c=Math.max(1,Math.ceil(Math.sqrt(r*n/(o*l))/h));for(;Math.ceil(r/(c*h))*Math.ceil(n/(c*h*l))>o;)c++;const m="dither"===i.style?i.dither.scale:i.cellSize,u=Math.max(c,m)*h;return{cell:u,rowHeight:u*l,columns:Math.ceil(r/u),rows:Math.ceil(n/(u*l)),minimum:c,limited:m<c}}var rt=[["ascii","Signature ASCII","Clean characters in paper white on near black.",{cellSize:4,ink:"#ece9e0",backdrop:{mode:"solid",color:"#0b0b0a"},color:{contrast:1.25,gamma:1.25},effects:{characterBloom:.12}}],["print","Newsprint","Fine diffusion in soft black on warm paper.",{style:"dither",cellSize:6,ink:"#1d1c19",backdrop:{mode:"solid",color:"#efece4"},dither:{algorithm:"floyd-steinberg",palette:"custom",colors:["#efece4","#1d1c19"],scale:2}}],["handheld","Pocket camera","Four-tone ordered dither in graphite.",{style:"dither",cellSize:6,ink:"#dedbd2",backdrop:{mode:"solid",color:"#121211"},dither:{algorithm:"bayer4",palette:"custom",colors:["#121211","#3e3d39","#8a8880","#dedbd2"],scale:2}}],["riso","Two inks","Muted blue and coral on warm paper.",{style:"dither",cellSize:6,ink:"#3d5068",backdrop:{mode:"solid",color:"#f0ece3"},dither:{algorithm:"atkinson",palette:"custom",colors:["#f0ece3","#c27461","#3d5068"],scale:2}}],["night","Night signal","Graphite characters with a faint optical fringe.",{cellSize:4,ink:"#cdc9be",backdrop:{mode:"solid",color:"#0b0b0a"},color:{contrast:1.2,gamma:1.2},effects:{prism:.2,scanlines:.08,vignette:.3,bloom:.12}}],["terminal","Phosphor","Soft sage glyphs with a faint glow.",{cellSize:5,ink:"#a4c9b3",backdrop:{mode:"solid",color:"#0a0d0b"},effects:{bloom:.16,scanlines:.12,crt:.06}}],["mosaic","Mosaic study","Separated tiles in quiet source color.",{style:"mosaic",ink:"#e6e3da",cellSize:9,colorMode:"source",backdrop:{mode:"solid",color:"#0b0b0a"},color:{saturation:.55,contrast:1.05}}],["bricks","Brickwork","Studded cells in softened color.",{style:"lego",ink:"#e6e3da",cellSize:12,colorMode:"source",backdrop:{mode:"solid",color:"#0b0b0a"},color:{saturation:.55}}],["voxel","Little volumes","Three-face isometric tiles in muted color.",{style:"voxel",ink:"#e6e3da",cellSize:12,colorMode:"source",backdrop:{mode:"solid",color:"#0b0b0a"},color:{saturation:.5}}],["disco","Mirror room","Faceted tiles under one soft light.",{style:"disco",ink:"#e6e3da",cellSize:11,colorMode:"source",backdrop:{mode:"solid",color:"#0b0b0a"},color:{saturation:.5},lights:[{x:.35,y:.25,radius:.28,intensity:.28,color:"#f4efe4"}]}],["wallpaper","Wallpaper","Living ASCII over a softened source.",{cellSize:5,backdrop:{mode:"blurred",color:"#0b0b0a",blur:18,opacity:.4},ink:"#e6e3da",motion:{type:"relight",speed:.35,amount:.8}}],["blueprint","Blueprint","Fine linework in pale blue on deep navy.",{style:"lines",cellSize:6,ink:"#b3c9d8",backdrop:{mode:"solid",color:"#0e1b28"}}]].map(([t,e,i,a])=>({id:t,name:e,description:i,settings:tt(a)}));function nt(t){const e=rt.find(e=>e.id===t);if(!e)throw new Error("Unknown studio look.");return tt(e.settings)}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 n=[0,.25+.2*s,.5,.75+.2*r,1],o=n.slice(1).map((t,e)=>4*(t-n[e])),h=[o[0],...o.slice(1).map((t,e)=>2*t*o[e]/(t+o[e])),o[3]],l=new Uint8Array(256);for(let t=0;t<256;t++){const s=Math.pow(Math.max(0,Math.min(1,(t/255-e)/(i-e))),1/a),r=Math.min(3,Math.floor(4*s)),o=4*s-r,c=o*o,m=c*o,u=(2*m-3*c+1)*n[r]+(m-2*c+o)*h[r]/4+(-2*m+3*c)*n[r+1]+(m-c)*h[r+1]/4;l[t]=Math.round(255*Math.max(0,Math.min(1,u)))}return l}(t),i=t.curves;if(!e&&(!i||Object.values(i).every(t=>t.every(([t,e])=>t===e))))return null;const a=C(i?.rgb),s=[i?.red,i?.green,i?.blue].map(C),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 ht=class{constructor(t=0){this.amount=0,this.weights=new Float32Array(256),this.source=new Uint8ClampedArray(0),this.configure(t)}configure(t=0){const e=Math.max(0,Math.min(1,Number.isFinite(t)?t:0));if(e===this.amount)return;if(this.amount=e,0===e)return void(this.source=new Uint8ClampedArray(0));const i=8+24*e;for(let t=0;t<256;t++)this.weights[t]=Math.exp(-t*t/(2*i*i))}apply(t,e,i){if(!this.amount)return;if(!Number.isInteger(e)||!Number.isInteger(i)||e<1||i<1||e*i*4!==t.length)throw new Error("Denoise dimensions do not match the source.");this.source.length!==t.length&&(this.source=new Uint8ClampedArray(t.length));const a=this.source;a.set(t);for(let s=0;s<i;s++)for(let r=0;r<e;r++){const n=4*(s*e+r);if(!a[n+3])continue;const o=a[n],h=a[n+1],l=a[n+2];let c=0,m=0,u=0,f=0;for(let t=-1;t<=1;t++){const n=s+t;if(!(n<0||n>=i))for(let i=-1;i<=1;i++){const s=r+i;if(s<0||s>=e)continue;const d=4*(n*e+s);if(!a[d+3])continue;const p=Math.max(Math.abs(a[d]-o),Math.abs(a[d+1]-h),Math.abs(a[d+2]-l)),g=this.weights[p]*(0===i?1:.6)*(0===t?1:.6)*a[d+3];c+=a[d]*g,m+=a[d+1]*g,u+=a[d+2]*g,f+=g}}t[n]=o+(c/f-o)*this.amount,t[n+1]=h+(m/f-h)*this.amount,t[n+2]=l+(u/f-l)*this.amount}}},lt=2*Math.PI,ct=t=>Math.max(0,Math.min(1,t)),mt=.1,ut=t=>Math.max(-.1,Math.min(1.1,t)),ft=Float32Array.from({length:2048},(t,e)=>Math.sin(e/2048*lt)),dt=t=>ft[2047&Math.floor(t*(2048/lt))];function pt(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 gt(t){const e=W(t),{density:i,weight:a,angle:s,roughness:r,invert:n,secondaryInk:o,registration:h,seed:l}=e,c=s*Math.PI/180,m=[c,c+Math.PI/2,c+Math.PI/4].map(t=>[Math.cos(t),Math.sin(t)]),u=new Float32Array(6);function f(t,e,i,s,n,o,h,c,f=!1){if(h<=0)return;const[d,p]=m[c],g=-p,M=d,x=g*(e+.5)+M*(i+.5),v=.5*(Math.abs(g)+Math.abs(M)),y=f?1:.5,b=Math.ceil((x-v)/y),w=Math.floor((x+v)/y),k=Math.min(.94*y,.72*y*h*a);t.lineWidth=o*k,t.beginPath();for(let a=b;a<=w;a++){const h=a*y-x,c=.5+g*h,m=.5+M*h;let v=-2,b=2;if(Math.abs(d)>1e-8){const t=-c/d,e=(1-c)/d;v=Math.max(v,Math.min(t,e)),b=Math.min(b,Math.max(t,e))}else if(c<0||c>1)continue;if(Math.abs(p)>1e-8){const t=-m/p,e=(1-m)/p;v=Math.max(v,Math.min(t,e)),b=Math.min(b,Math.max(t,e))}else if(m<0||m>1)continue;if(!(b<=v))if(f&&(v-=mt,b+=mt),f){for(let t=0;t<6;t++){const s=v+(b-v)*t/5,r=d*(e+c+d*s)+p*(i+m+p*s);u[t]=.5*dt(5.3*r+1.9*a+l)+.25*dt(13.1*r+a)}for(let e=0;e<2;e++)for(let i=0;i<6;i++){const a=v+(b-v)*(e?5-i:i)/5,h=u[e?5-i:i],l=.5*k*(1+r*h*.5)*(e?-1:1),f=s+ut(c+d*a+g*l)*o,x=n+ut(m+p*a+M*l)*o;e||i?t.lineTo(f,x):t.moveTo(f,x)}t.closePath()}else t.moveTo(s+(c+d*v)*o,n+(m+p*v)*o),t.lineTo(s+(c+d*b)*o,n+(m+p*b)*o)}f?t.fill():t.stroke()}return{settings:e,paint(t,e,s,c,u,d,p,g,M,x,v,y,b){const w=ct((n?1-g:g)*i);if(w<=0||t.globalAlpha<=0)return;t.fillStyle=M,t.strokeStyle=M;const k=pt(s,c,l);if("engraving"===e||"crosshatch"===e||"woodblock"===e){const i=w*(1-r*k*.3);"woodblock"===e?f(t,s,c,u,d,p,Math.ceil(5*i)/5,0,!0):(f(t,s,c,u,d,p,i,0),"crosshatch"===e&&(f(t,s,c,u,d,p,Math.max(0,1.5*i-.3),1),f(t,s,c,u,d,p,Math.max(0,2*i-1.2),2)))}else if("risograph"===e){const e="source"===b?ct(.5+(x-y)/510):.5,i=.38*h*p,n=p*Math.min(.48,.44*Math.sqrt(w)*a);t.beginPath(),t.arc(u+.5*p,d+.5*p,n*Math.sqrt(.35+.65*(1-e)),0,lt),t.fill(),t.globalCompositeOperation="multiply",t.fillStyle=o;const f=1-r*pt(s,c,l+13)*.3;t.beginPath(),t.arc(u+.5*p+i*m[0][0],d+.5*p+i*m[0][1],n*Math.sqrt(.3+.7*e)*f,0,lt),t.fill(),t.globalCompositeOperation="source-over"}else{const i=t.fillEllipse;"stipple"===e&&t.beginPath();for(let n=0;n<4;n++){const o=pt(2*s+n%2,2*c+(n>>1),l),h=pt(s,c,l+11*n+1),m=u+((n%2+.5)/2+(o-.5)*r*.28)*p,f=d+((.5+(n>>1))/2+(h-.5)*r*.28)*p,g=Math.min(m-u,u+p-m,f-d,d+p-f,p*Math.min(.245,.21*a*Math.sqrt(w)*(1-r*o*.35)));if("stipple"===e)t.moveTo(m+g,f),t.arc(m,f,g,0,lt);else{const e=(o-.5)*r*64;if(i&&"accent"!==b){const t=Math.round(x+e);i(m,f,g,.64*g,o*Math.PI,t,"source"===b?Math.round(v-.4*e):t,"source"===b?Math.round(y-e):t);continue}t.fillStyle="source"===b?`rgb(${Math.round(x+e)},${Math.round(v-.4*e)},${Math.round(y-e)})`:"gray"===b?`rgb(${Math.round(x+e)},${Math.round(x+e)},${Math.round(x+e)})`:M,t.beginPath(),t.ellipse(m,f,g,.64*g,o*Math.PI,0,lt),t.fill()}}"stipple"===e&&t.fill()}}}}var Mt=new Set(["none","floyd-steinberg","atkinson","stucki","sierra","sierra-lite","burkes","jarvis"]);function xt(t){return"dither"===t.style&&("shimmer"===t.dither.motion||"drift"===t.dither.motion&&t.dither.amount>0&&!Mt.has(t.dither.algorithm))}function vt(t){return"none"!==t.motion.type&&(t.motion.amount??1)>0}function yt(t){return vt(t)||xt(t)||t.effects.grain>0||t.effects.dust>0||t.effects.glitch>0}var bt=11,wt=t=>Math.max(0,Math.min(1,t)),kt=(t,e,i)=>{const a=wt((i-t)/(e-t));return a*a*(3-2*a)};function At(t,e,i=256){let a=0;for(let e=0;e<t.length;e++)t[e]>a&&(a=t[e]);if(a<=0)return 0;const s=new Uint32Array(i);for(let e=0;e<t.length;e++)s[Math.min(i-1,Math.floor(Math.max(0,t[e])/a*i))]++;let r=0;const n=t.length*e;for(let t=0;t<i;t++)if(r+=s[t],r>=n)return(t+1)/i*a;return a}var St=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}},Ft=null;function Et(t,e,i,a,s){const r=2*s+1;for(let n=0;n<a;n++){const a=n*i;let o=0;for(let e=-s;e<=s;e++)o+=t[a+Math.max(0,Math.min(i-1,e))];for(let n=0;n<i;n++)e[a+n]=o/r,o+=t[a+Math.min(i-1,n+s+1)]-t[a+Math.max(0,n-s)]}for(let n=0;n<i;n++){let o=0;for(let t=-s;t<=s;t++)o+=e[Math.max(0,Math.min(a-1,t))*i+n];for(let h=0;h<a;h++)t[h*i+n]=o/r,o+=e[Math.min(a-1,h+s+1)*i+n]-e[Math.max(0,h-s)*i+n]}}function Rt(t,e,i,a,s,r,n){const o=i*a,h=n.take(),l=n.take(e),c=n.take(t),m=n.take(),u=n.take();for(let i=0;i<o;i++)m[i]=e[i]*e[i],u[i]=e[i]*t[i];Et(l,h,i,a,s),Et(c,h,i,a,s),Et(m,h,i,a,s),Et(u,h,i,a,s);for(let t=0;t<o;t++){const e=(u[t]-l[t]*c[t])/(m[t]-l[t]*l[t]+r);m[t]=e,u[t]=c[t]-e*l[t]}Et(m,h,i,a,s),Et(u,h,i,a,s);for(let i=0;i<o;i++)t[i]=m[i]*e[i]+u[i]}function Pt(t,e,i,a,s,r=2){for(let n=0;n<r;n++){for(let r=0;r<a;r++)for(let a=0;a<i;a++){const n=r*i+a;let o=t[n];a>0&&(o=Math.max(o,Math.min(e[n],t[n-1]*s))),r>0&&(o=Math.max(o,Math.min(e[n],t[n-i]*s),a>0?Math.min(e[n],t[n-i-1]*s):0,a<i-1?Math.min(e[n],t[n-i+1]*s):0)),t[n]=o}for(let r=a-1;r>=0;r--)for(let n=i-1;n>=0;n--){const o=r*i+n;let h=t[o];n<i-1&&(h=Math.max(h,Math.min(e[o],t[o+1]*s))),r<a-1&&(h=Math.max(h,Math.min(e[o],t[o+i]*s),n>0?Math.min(e[o],t[o+i-1]*s):0,n<i-1?Math.min(e[o],t[o+i+1]*s):0)),t[o]=h}}}function Tt(t,e,i,a,s){for(let r=0;r<a;r++)for(let a=0;a<i;a++){let n=1;for(let e=Math.max(0,a-s);e<=Math.min(i-1,a+s);e++)n=Math.min(n,t[r*i+e]);e[r*i+a]=n}for(let r=0;r<a;r++)for(let n=0;n<i;n++){let o=1;for(let t=Math.max(0,r-s);t<=Math.min(a-1,r+s);t++)o=Math.min(o,e[t*i+n]);t[r*i+n]=o}}function It(t,e,i,a,s){const r=i*a,n=Math.min(i,a),o=s.take(),h=s.take(),l=s.take(),c=s.take(),m=s.take();for(let i=0;i<r;i++){const a=t[4*i+3]/255;m[i]=a,o[i]=e[4*i]/255*a,h[i]=e[4*i+1]/255*a,l[i]=e[4*i+2]/255*a,c[i]=(.299*t[4*i]+.587*t[4*i+1]+.114*t[4*i+2])/255*a}const u=s.take(),d=(t,e)=>{const r=s.take(t);return f(r,u,i,a,e),r},g=Math.max(2,Math.round(.04*n)),M=Math.max(g+2,Math.round(.12*n)),x=Math.max(2,Math.round(.05*n)),v=d(c,1),y=d(c,g),b=d(c,M),w=s.take(),k=s.take(),A=s.take(),S=s.take(),F=s.take();for(let t=0;t<a;t++)for(let e=0;e<i;e++){const s=t*i+e;w[s]=Math.abs(c[s]-v[s]),k[s]=Math.abs(v[s]-y[s]),A[s]=Math.abs(y[s]-b[s]),S[s]=Math.abs(c[t*i+Math.min(i-1,e+1)]-c[t*i+Math.max(0,e-1)]),F[s]=Math.abs(c[Math.min(a-1,t+1)*i+e]-c[Math.max(0,t-1)*i+e])}f(w,u,i,a,x),f(k,u,i,a,x),f(A,u,i,a,x),f(S,u,i,a,2),f(F,u,i,a,2);const E=Math.max(.01,At(w,.9)+At(k,.9)),R=d(o,1),P=d(h,1),T=d(l,1),I=s.take(),C=s.take(),D=s.take();let N=0;for(let t=0;t<r;t++){const e=R[t],i=P[t],a=T[t],s=Math.max(e,i,a),r=s-Math.min(e,i,a);D[t]=s,C[t]=s>.001?r/s:0,N+=r;let n=0;r>1e-4&&(n=s===e?((i-a)/r+6)%6:s===i?(a-e)/r+2:(e-i)/r+4),I[t]=60*n}const O=kt(.02,.07,N/r),U=Math.max(2,Math.round(.06*a)),L=new Float32Array(a);for(let t=0;t<a;t++){let e=0;for(let a=0;a<i;a++)e+=w[t*i+a]+k[t*i+a];L[t]=e/i}let q=.5,X=0;for(let t=Math.max(U,Math.round(.12*a));t<=Math.min(a-U,Math.round(.88*a));t++){let e=0,s=0,r=0,n=0;for(let a=0;a<i;a++){let r=0,n=0,o=0,h=0,l=0,c=0;for(let e=1;e<=U;e++){const s=(t-e)*i+a,m=(t+e-1)*i+a;r+=R[s],n+=P[s],o+=T[s],h+=R[m],l+=P[m],c+=T[m]}const m=(Math.abs(r-h)+Math.abs(n-l)+Math.abs(o-c))/U;e+=m,s+=m>.12?1:0}const o=Math.max(2,Math.round(.15*a)),h=Math.max(0,t-o),l=Math.min(a,t+o);for(let e=h;e<t;e++)r+=L[e];for(let e=t;e<l;e++)n+=L[e];r/=t-h,n/=l-t;const c=kt(-.05,.3,(n-r)/(n+r+1e-4)),m=kt(.08,.35,e/i)*(s/i)*c;m>X&&(X=m,q=t/a)}const B=kt(.15,.45,X),z=s.take(),Y=s.take(),j=s.take();for(let t=0;t<r;t++)z[t]=Math.min(o[t],h[t],l[t]);Tt(z,u,i,a,1),f(z,u,i,a,g);for(let t=0;t<r;t++)Y[t]=k[t]+A[t];let W=0,H=0,G=0;for(let t=0;t<r;t++)W+=R[t],H+=P[t],G+=T[t];W/=r,H/=r,G/=r;const V=d(R,g),K=d(P,g),J=d(T,g),Q=d(R,M),Z=d(P,M),_=d(T,M);for(let t=0;t<r;t++){const e=Math.hypot(V[t]-W,K[t]-H,J[t]-G),i=Math.hypot(V[t]-Q[t],K[t]-Z[t],J[t]-_[t]);j[t]=(e+1.5*i)*(.4+.6*C[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(),nt=s.take(),ot=s.take(),ht=s.take();for(let t=0;t<a;t++)for(let e=0;e<i;e++)ht[t*i+e]=Math.abs(c[Math.min(a-1,t+1)*i+e]-c[Math.max(0,t-1)*i+e]);f(ht,u,i,a,1);for(let t=0;t<a;t++)for(let e=0;e<i;e++){const s=t*i+e,r=(t+.5)/a,n=I[s],o=C[s]*O,h=D[s],l=w[s]+k[s],c=kt(175,200,n)*(1-kt(250,275,n))*kt(.08,.25,o),m=(1-kt(45,65,n)+kt(290,330,n))*kt(.2,.45,o)*kt(.3,.55,h),u=(1-kt(.15,.35,o))*kt(.45,.7,h)*B,f=(1-kt(.08,.2,h))*B,d=B>.3?1-kt(q,q+.1,r):1-kt(.4,.8,r),p=1-kt(.02,.06,l),g=1-kt(.03,.09,l);tt[s]=Math.max(c*p,.7*f*(1-kt(.008,.025,l)),m*g*.9)*d,et[s]=Math.max(tt[s],u*p*d),$[s]=0===t?tt[s]:0,it[s]=kt(150,172,n)*(1-kt(232,250,n))*kt(.25,.45,o),rt[s]=kt(1.3,2.2,(S[s]+.004)/(F[s]+.004))*kt(.35,.55,v[s])*(1-kt(.1,.18,C[s]*O))*kt(.025,.07,l)*kt(.025,.045,ht[s]);const M=1-kt(.18,.4,o),x=kt(.55,.8,h)*kt(.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&&B>.3;if(ct)for(let t=0;t<a;t++)for(let e=0;e<i;e++)it[t*i+e]*=kt(q,q+.05,(t+.5)/a);if(ct){const t=s.take(),e=s.take(),n=s.take();for(let e=0;e<r;e++)t[e]=.299*V[e]+.587*K[e]+.114*J[e];for(let t=0;t<a;t++)for(let s=0;s<i;s++)e[t*i+s]=v[Math.min(a-1,t+1)*i+s]-v[Math.max(0,t-1)*i+s];const o=new Uint8Array(r);for(let t=1;t<a-1;t++)for(let s=0;s<i;s++){const r=Math.abs(e[t*i+s]);let n=r>.03;for(let o=-3;o<=3&&n;o++)o&&t+o>=0&&t+o<a&&Math.abs(e[(t+o)*i+s])>r&&(n=!1);o[t*i+s]=n?1:0}const h=(e,i,a,s=!0)=>{const r=V[i]+K[i]+J[i]+.05,n=V[a]+K[a]+J[a]+.05,o=Math.abs(V[i]/r-V[a]/n)+Math.abs(K[i]/r-K[a]/n)+Math.abs(J[i]/r-J[a]/n),h=Math.min(Math.abs(I[i]-I[a]),360-Math.abs(I[i]-I[a])),l=Math.max(1-kt(.1,.25,o),(1-kt(15,35,h))*kt(.15,.3,Math.min(C[i],C[a]))),c=Math.max(kt(2,3,(F[i]+.004)/(S[i]+.004))*kt(.015,.04,w[i]+k[i])*kt(.4,.55,w[i]/(w[i]+k[i]+1e-4)),1-kt(.12,.25,t[i]));return l*(s?c:1)*(1-kt(.82*t[a]+.02,1.02*t[a]+.05,t[i]))};let l=0,c=0;for(let t=Math.max(3,Math.round(a*Math.max(.25,q)));t<Math.round(.88*a);t++){let e=0;for(let a=0;a<i;a++)(o[(t-1)*i+a]||o[t*i+a]||o[(t+1)*i+a])&&e++;if(e<.5*i)continue;let s=0;for(let e=t+1;e<Math.min(a,2*t);e++)for(let a=0;a<i;a++)s+=h(t,e*i+a,(2*t-e)*i+a);s>c&&(c=s,l=t)}const m=kt(.05,.1,c/r);if(m>0)for(let t=l+1;t<Math.min(a,2*l);t++)for(let e=0;e<i;e++){const a=t*i+e;nt[a]=h(l,a,(2*l-t)*i+e)*m,ot[a]=h(l,a,(2*l-t)*i+e,!1)*m,n[a]=nt[a]}f(n,u,i,a,1);for(let t=0;t<r;t++)nt[t]=Math.max(nt[t],n[t]),it[t]=Math.max(it[t],nt[t])}const mt=d(it,M);for(let t=0;t<r;t++)it[t]*=kt(.15,.35,mt[t]);const ut=d(it,g);for(let t=0;t<r;t++){it[t]*=1-.8*tt[t];const e=Math.min(Math.abs(I[t]-200),360-Math.abs(I[t]-200));st[t]=kt(.28,.45,C[t]*O)*kt(55,80,e)*(1-kt(.3,.6,ot[t]))}const ft=d(st,g);for(let t=0;t<r;t++)st[t]=Math.max(st[t]*(1-(1-kt(.15,.3,ft[t]))*kt(.55,.7,D[t])*kt(.5,.65,C[t])),1-m[t]),at[t]=Math.min(Math.max(at[t],.9*ot[t]),Math.max(it[t],kt(.25,.6,ut[t])))*(1-$[t])*(1-st[t]);Pt(it,at,i,a,.97);const dt=s.take(rt),pt=Math.max(2,Math.round(.12*a));for(let t=0;t<i;t++){let e=0;for(let s=-pt;s<=pt;s++)e+=rt[Math.max(0,Math.min(a-1,s))*i+t];for(let s=0;s<a;s++)dt[s*i+t]=e/(2*pt+1),e+=rt[Math.min(a-1,s+pt+1)*i+t]-rt[Math.max(0,s-pt)*i+t]}f(dt,u,i,a,1);for(let t=0;t<r;t++)rt[t]=kt(.2,.45,dt[t])*kt(.2,.5,rt[t]+.5*dt[t])*(1-$[t]);Rt($,c,i,a,Math.max(2,Math.round(.04*n)),.002,s),Rt(it,c,i,a,Math.max(2,Math.round(.04*n)),.002,s),Rt(rt,c,i,a,Math.max(2,Math.round(.03*n)),.002,s),f(st,u,i,a,1);for(let t=0;t<r;t++)$[t]=kt(.3,.7,$[t])*m[t],rt[t]=kt(.3,.7,rt[t])*m[t]*(1-$[t]),it[t]=kt(.3,.7,it[t])*(1-$[t])*(1-rt[t])*(1-kt(.15,.4,st[t]));Tt($,u,i,a,2),Tt(it,u,i,a,2),Tt(rt,u,i,a,1),f($,u,i,a,1),f(it,u,i,a,1),f(rt,u,i,a,1);const gt=1/Math.max(.02,At(j,.97)),Mt=1/Math.max(.01,At(Y,.9)),xt=At(z,.97),vt=At(z,.1),yt=kt(.06,.25,xt-vt),bt=s.take();for(let t=0;t<a;t++)for(let e=0;e<i;e++){const s=t*i+e,r=(e+.5)/i,n=(t+.5)/a,o=Math.max($[s],it[s]),h=w[s]+k[s]+A[s],l=.6*wt(((w[s]+.6*k[s])/(h+.004)-.25)/.55)+.4*wt((w[s]+k[s])/E),c=kt(.04,.35,h/E)*(1-o),m=.55*wt((z[s]-vt)/Math.max(.05,xt-vt))+.25*(1-wt(Y[s]*Mt))+.2*wt(2*(T[s]-R[s])+.3)*O,u=yt*kt(.12,.35,y[s])*(.4+.6*B),f=B*(n<q?.45:.45+.55*kt(0,1,(n-q)/Math.max(.15,1-q)))+(1-B)*(.5+.4*(n-.5)),d=w[s]/(w[s]+k[s]+1e-4),p=kt(.2,.7,(w[s]+k[s])/E)*(.35+.65*B)*(1-o),g=1-wt(1.5*Math.hypot(1.2*(r-.5),n-.52)),M=wt(j[s]*gt)*(.55+.45*g),x=.3*c,v=.25*u,b=.12+.45*B,S=.12*p,F=.35*(1-.4*B)*(1-o);bt[s]=(x*l+v*(1-m)+b*f+S*wt(1.6-1.6*d)+F*M+.04)/(x+v+b+S+F+.08)*(1-.85*$[s])*(1-.45*it[s]*(1-B))}const St=p(t,i,a);if("none"!==St.key)for(let t=0;t<r;t++)bt[t]=.7*St.subject[t]+.3*bt[t];return f(bt,u,i,a,Math.max(1,Math.round(.03*n))),function(t,e,i,a,s,r,n,o,h){const l=s*r,c=h.take(),m=t=>(Et(t,c,s,r,n),t),u=(t,e)=>{const i=h.take();for(let a=0;a<l;a++)i[a]=t[a]*e[a];return m(i)},f=m(h.take(e)),d=m(h.take(i)),p=m(h.take(a)),g=m(h.take(t)),M=u(e,e),x=u(e,i),v=u(e,a),y=u(i,i),b=u(i,a),w=u(a,a),k=u(e,t),A=u(i,t),S=u(a,t),F=h.take(),E=h.take(),R=h.take(),P=h.take();for(let t=0;t<l;t++){const e=k[t]-f[t]*g[t],i=A[t]-d[t]*g[t],a=S[t]-p[t]*g[t],s=M[t]-f[t]*f[t]+o,r=x[t]-f[t]*d[t],n=v[t]-f[t]*p[t],h=y[t]-d[t]*d[t]+o,l=b[t]-d[t]*p[t],c=w[t]-p[t]*p[t]+o,m=h*c-l*l,u=n*l-r*c,T=r*l-n*h,I=s*c-n*n,C=r*n-s*l,D=s*h-r*r,N=s*m+r*u+n*T,O=Math.abs(N)>1e-12?1/N:0;F[t]=(m*e+u*i+T*a)*O,E[t]=(u*e+I*i+C*a)*O,R[t]=(T*e+C*i+D*a)*O,P[t]=g[t]-F[t]*f[t]-E[t]*d[t]-R[t]*p[t]}m(F),m(E),m(R),m(P);for(let s=0;s<l;s++)t[s]=F[s]*e[s]+E[s]*i[s]+R[s]*a[s]+P[s]}(bt,R,P,T,i,a,Math.max(2,Math.round(.07*n)),.004,s),{depth:bt,water:it,sky:$,falls:rt}}function Ct(t,e,i,a,s,r,n){if(e===r&&i===n)return t[s*r+a];const o=Math.max(0,Math.min(e-1,(a+.5)*e/r-.5)),h=Math.max(0,Math.min(i-1,(s+.5)*i/n-.5)),l=Math.min(e-2,Math.floor(o)),c=Math.min(i-2,Math.floor(h)),m=o-l,u=h-c;if(l<0||c<0)return t[Math.round(h)*e+Math.round(o)];const f=c*e+l,d=f+e;return(t[f]*(1-m)+t[f+1]*m)*(1-u)+(t[d]*(1-m)+t[d+1]*m)*u}var Dt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Nt="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",Ot=new Uint16Array(4096);for(let t=0;t<Ot.length;t++)Ot[t]=Dt.indexOf(Nt[2*t])<<6|Dt.indexOf(Nt[2*t+1]);var Ut=(t,e)=>{const i=43758.5453*Math.sin(127.1*t+311.7*e);return i-Math.floor(i)};var Lt=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))])),qt={"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 Bt(t,e,i){const a=Math.min(t*Math.max(1,i),(1-t)*Math.max(1,i),e*Math.max(1,1/i),(1-e)*Math.max(1,1/i)),s=Math.max(0,Math.min(1,(a-.035)/.105));return s*s*s*(s*(6*s-15)+10)}var zt=class{constructor(t,e){this.edgeSafe=!1,this.rings=new Float64Array(40),this.slot=0,this.clock=0,this.lastRing=-1,this.previous=null,this.alive=!1,this.width=t,this.height=e,this.pixels=new Uint8Array(t*e*4),this.values=new Float32Array(t*e),this.clear()}get active(){return this.alive}clear(){this.rings.fill(0),this.values.fill(0),this.pixels.fill(0);for(let t=0;t<this.pixels.length;t+=4)this.pixels[t]=128;this.previous=null,this.alive=!1,this.slot=0,this.lastRing=-1,this.clock=0}leave(){this.previous=null}move(t,e,i,a){if(!Number.isFinite(t+e+i))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e));const s=Number.isFinite(a)?a/1e3:this.clock,r=this.previous;if(this.previous={x:t,y:e,time:s},!r)return;const n=this.width/this.height,o=Math.hypot((t-r.x)*Math.max(1,n),(e-r.y)*Math.max(1,1/n));if(o<1e-4||this.clock-this.lastRing<1/24)return;const h=o/Math.max(1/240,Math.min(.1,s-r.time||1/60)),l=5*this.slot;this.slot=(this.slot+1)%8,this.rings[l]=t,this.rings[l+1]=e,this.rings[l+2]=0,this.rings[l+3]=Math.min(.9,.26+.2*h),this.rings[l+4]=.035+.13*Math.max(.1,Math.min(1,i)),this.alive=!0,this.lastRing=this.clock}step(t){if(!Number.isFinite(t)||t<=0)return;const e=Math.min(.05,t);if(this.clock+=e,!this.alive)return;this.values.fill(0),this.alive=!1;const i=this.width/this.height,a=Math.max(1,i),s=Math.max(1,1/i);for(let t=0;t<this.rings.length;t+=5){if(!this.rings[t+3])continue;const i=this.rings[t+2]+=e;if(i>2.8){this.rings[t+3]=0;continue}this.alive=!0;const r=this.rings[t+4],n=.17*i,o=this.rings[t+3]*(1-Math.exp(20*-i))*Math.exp(2.5*-i),h=n+1.8*r,l=this.rings[t],c=this.rings[t+1],m=Math.max(0,Math.floor((l-h/a)*(this.width-1))),u=Math.min(this.width-1,Math.ceil((l+h/a)*(this.width-1))),f=Math.max(0,Math.floor((c-h/s)*(this.height-1))),d=Math.min(this.height-1,Math.ceil((c+h/s)*(this.height-1)));for(let t=f;t<=d;t++)for(let e=m;e<=u;e++){const i=(Math.hypot((e/(this.width-1)-l)*a,(t/(this.height-1)-c)*s)-n)/r;Math.abs(i)>1.8||(this.values[t*this.width+e]+=o*Math.cos(i*Math.PI*2)*Math.exp(-i*i*2.5))}}for(let t=0;t<this.height;t++)for(let e=0;e<this.width;e++){const a=t*this.width+e,s=this.values[a]=Math.max(-1,Math.min(1,this.values[a]))*(this.edgeSafe?Bt(e/(this.width-1),t/(this.height-1),i):1),r=Math.round(32767*s+32768);this.pixels[4*a]=r>>>8,this.pixels[4*a+1]=255&r}}sample(t,e,i){const a=Math.max(0,Math.min(this.width-1.001,t*(this.width-1))),s=Math.max(0,Math.min(this.height-1.001,e*(this.height-1))),r=Math.floor(a),n=Math.floor(s),o=a-r,h=s-n,l=n*this.width+r,c=l+this.width;i[0]=i[1]=0,i[2]=3*((this.values[l]*(1-o)+this.values[l+1]*o)*(1-h)+(this.values[c]*(1-o)+this.values[c+1]*o)*h)}},Yt=t=>["dissolve","silk","vortex","magnetic","scatter","etch","elastic","lens","smudge"].includes(t),jt=t=>"elastic"===t||"scatter"===t,Wt={elastic:[150,4.2],scatter:[90,3.6]},Ht=class{constructor(t,e){this.edgeSafe=!1,this.previous=null,this.peak=0,this.scatterDirections=null,this.springX=null,this.springY=null,this.mode="dissolve",this.width=t,this.height=e;const i=t*e;this.pixels=new Uint8Array(4*i),this.ink=new Float32Array(i),this.targetX=new Float32Array(i),this.targetY=new Float32Array(i),this.offsetX=new Float32Array(i),this.offsetY=new Float32Array(i),this.edge=new Float32Array(i);for(let i=0;i<e;i++)for(let a=0;a<t;a++)this.edge[i*t+a]=Bt(a/(t-1),i/(e-1),t/e);this.clear()}get active(){return this.peak>2e-4}setMode(t){if(jt(t)&&!this.springX&&(this.springX=new Float32Array(this.ink.length),this.springY=new Float32Array(this.ink.length)),"scatter"===t&&!this.scatterDirections){const t=this.scatterDirections=new Float64Array(this.width*this.height*2),e=(t,e)=>{const i=43758.5453*Math.sin(127.1*t+311.7*e);return i-Math.floor(i)};for(let i=0;i<this.height;i++)for(let a=0;a<this.width;a++){const s=.09*a,r=.09*i,n=Math.floor(s),o=Math.floor(r),h=s-n,l=r-o,c=h*h*(3-2*h),m=l*l*(3-2*l),u=((e(n,o)*(1-c)+e(n+1,o)*c)*(1-m)+(e(n,o+1)*(1-c)+e(n+1,o+1)*c)*m)*Math.PI*4,f=2*(i*this.width+a);t[f]=.7*Math.cos(u),t[f+1]=.7*Math.sin(u)}}t!==this.mode&&(this.mode=t,this.clear())}clear(){for(const t of[this.ink,this.targetX,this.targetY,this.offsetX,this.offsetY,this.pixels])t.fill(0);if(this.previous=null,this.peak=0,this.springX?.fill(0),this.springY?.fill(0),"dissolve"!==this.mode)for(let t=0;t<this.pixels.length;t+=4)this.pixels[t]=this.pixels[t+2]=128}leave(){this.previous=null}move(t,e,i){if(!Number.isFinite(t+e+i))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e));const a=this.previous;this.previous={x:t,y:e};const s=this.width,r=this.height,n=Math.max(1,s/r),o=Math.max(1,r/s),h=a?(t-a.x)*n:0,l=a?(e-a.y)*o:0,c=Math.hypot(h,l);if(!a&&"dissolve"!==this.mode&&"etch"!==this.mode&&"lens"!==this.mode)return;if(a&&c<1e-4)return;const m=.035+.11*Math.max(.1,Math.min(1,i)),u=Math.min(128,Math.max(1,Math.ceil(c/(.45*m)))),f=c?h/c:1,d=c?l/c:0,p=a||"lens"!==this.mode?Math.min(1,c/(m*u)*2.2):.32;for(let i=0;i<u;i++){const h=(i+.5)/u,l=a?a.x+(t-a.x)*h:t,c=a?a.y+(e-a.y)*h:e,g=Math.max(0,Math.floor((l-2.5*m/n)*(s-1))),M=Math.min(s-1,Math.ceil((l+2.5*m/n)*(s-1))),x=Math.max(0,Math.floor((c-2.5*m/o)*(r-1))),v=Math.min(r-1,Math.ceil((c+2.5*m/o)*(r-1)));for(let t=x;t<=v;t++)for(let e=g;e<=M;e++){const i=(e/(s-1)-l)*n/m,a=(t/(r-1)-c)*o/m,h=Math.exp(1.5*-(i*i+a*a)),u=t*s+e;if("dissolve"===this.mode||"etch"===this.mode)this.ink[u]=Math.max(this.ink[u],h);else if("elastic"===this.mode)this.springX[u]=Math.max(-24,Math.min(24,this.springX[u]+f*h*p*12)),this.springY[u]=Math.max(-24,Math.min(24,this.springY[u]+d*h*p*12));else if("scatter"===this.mode){const t=this.scatterDirections;this.springX[u]=Math.max(-24,Math.min(24,this.springX[u]+(.6*i+t[2*u])*h*p*7)),this.springY[u]=Math.max(-24,Math.min(24,this.springY[u]+(.6*a+t[2*u+1])*h*p*7))}else if("lens"===this.mode)this.targetX[u]=Math.max(-.65,Math.min(.65,this.targetX[u]+i*h*p*1.6)),this.targetY[u]=Math.max(-.65,Math.min(.65,this.targetY[u]+a*h*p*1.6));else if("smudge"===this.mode)this.targetX[u]=Math.max(-1,Math.min(1,this.targetX[u]+f*h*p*1.3)),this.targetY[u]=Math.max(-1,Math.min(1,this.targetY[u]+d*h*p*1.3));else{const t=(-i*d+a*f)*h*2.8,e="magnetic"===this.mode?-i*h*2.5:"silk"===this.mode?f*t:-a*h*2.5,s="magnetic"===this.mode?-a*h*2.5:"silk"===this.mode?d*t:i*h*2.5;this.targetX[u]=Math.max(-1,Math.min(1,this.targetX[u]+e*p)),this.targetY[u]=Math.max(-1,Math.min(1,this.targetY[u]+s*p))}}}this.peak=1}step(t){if(!this.active||!Number.isFinite(t))return;const e=Math.max(0,Math.min(.05,t)),i="dissolve"===this.mode?2.15:"smudge"===this.mode?2.4:3.2,a="lens"===this.mode?16:22,s=Math.exp(-i*e),r=1-Math.exp(-a*e);let n=0;const[o,h]="scatter"===this.mode?Wt.scatter:Wt.elastic,l=Math.sqrt(o-h*h),c=Math.exp(-h*e),m=Math.cos(l*e),u=Math.sin(l*e)/l;for(let t=0;t<this.ink.length;t++)if("etch"===this.mode)this.ink[t]*=s,n=Math.max(n,this.ink[t]);else if("dissolve"===this.mode){this.ink[t]*=s,n=Math.max(n,this.ink[t]);const e=Math.round(65535*this.ink[t]);this.pixels[4*t]=e>>>8,this.pixels[4*t+1]=255&e}else{if(jt(this.mode)){const e=this.offsetX[t],i=this.offsetY[t],a=this.springX[t],s=this.springY[t];this.offsetX[t]=Math.max(-1,Math.min(1,c*(e*m+(a+h*e)*u))),this.offsetY[t]=Math.max(-1,Math.min(1,c*(i*m+(s+h*i)*u))),this.springX[t]=c*(a*m-(h*a+o*e)*u),this.springY[t]=c*(s*m-(h*s+o*i)*u),n=Math.max(n,.05*Math.abs(this.springX[t]),.05*Math.abs(this.springY[t]))}else if("lens"===this.mode||"smudge"===this.mode){const e=1-r,n=a/(a-i)*(s-e);this.offsetX[t]=this.offsetX[t]*e+this.targetX[t]*n,this.offsetY[t]=this.offsetY[t]*e+this.targetY[t]*n,this.targetX[t]*=s,this.targetY[t]*=s}else this.targetX[t]*=s,this.targetY[t]*=s,this.offsetX[t]+=(this.targetX[t]-this.offsetX[t])*r,this.offsetY[t]+=(this.targetY[t]-this.offsetY[t])*r;n=Math.max(n,Math.abs(this.offsetX[t]),Math.abs(this.offsetY[t]),Math.abs(this.targetX[t]),Math.abs(this.targetY[t]));const e=Math.round(this.offsetX[t]*(this.edgeSafe?this.edge[t]:1)*32767+32768),l=Math.round(this.offsetY[t]*(this.edgeSafe?this.edge[t]:1)*32767+32768);this.pixels[4*t]=e>>>8,this.pixels[4*t+1]=255&e,this.pixels[4*t+2]=l>>>8,this.pixels[4*t+3]=255&l}if("etch"===this.mode)for(let t=0;t<this.height;t++)for(let e=0;e<this.width;e++){const i=t*this.width+e,a=3*(this.ink[t*this.width+Math.max(0,e-1)]-this.ink[t*this.width+Math.min(this.width-1,e+1)]+this.ink[Math.max(0,t-1)*this.width+e]-this.ink[Math.min(this.height-1,t+1)*this.width+e]);this.offsetX[i]=Math.max(-1,Math.min(1,a))*(this.edgeSafe?this.edge[i]:1);const s=Math.round(32767*this.offsetX[i]+32768);this.pixels[4*i]=s>>>8,this.pixels[4*i+1]=255&s}this.peak=n,this.active||this.clear()}sample(t,e,i){const a=Math.max(0,Math.min(this.width-1.001,t*(this.width-1))),s=Math.max(0,Math.min(this.height-1.001,e*(this.height-1))),r=Math.floor(a),n=Math.floor(s),o=a-r,h=s-n,l=n*this.width+r,c=l+this.width,m=t=>(t[l]*(1-o)+t[l+1]*o)*(1-h)+(t[c]*(1-o)+t[c+1]*o)*h;if("etch"===this.mode)return i[0]=i[1]=0,void(i[2]=3*m(this.offsetX));i[0]=m(this.offsetX)*(this.edgeSafe?Bt(t,e,this.width/this.height):1)*.08,i[1]=m(this.offsetY)*(this.edgeSafe?Bt(t,e,this.width/this.height):1)*.08,i[2]="dissolve"===this.mode?6*-m(this.ink):0}},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 n=.015+r.age*(.15+.22*r.radius),o=.009+.014*r.radius,h=(Math.hypot((t-r.x)*i,(e-r.y)*a)-n)/o,l=Math.sin(Math.min(1,r.age/.07)*Math.PI/2)*Math.max(0,1-r.age/1.35)**2;s=Math.max(s,Math.exp(-h*h)*l)}return s}sample(t,e){const i=Math.max(0,Math.min(this.width-1,Math.round(t*(this.width-1)))),a=Math.max(0,Math.min(this.height-1,Math.round(e*(this.height-1))));return Math.max(this.ringSample(t,e),this.echo[a*this.width+i])}step(t){if(!Number.isFinite(t))return;const e=Math.max(0,Math.min(.05,t));this.elapsed+=e;for(const t of this.rings)t.age+=e;if(this.rings=this.rings.filter(t=>t.age<1.35),!this.active)return void this.pixels.fill(0);const i=Math.exp(-5.5*e);let a=0;for(let t=0;t<this.height;t++)for(let e=0;e<this.width;e++){const s=t*this.width+e;this.echo[s]=Math.max(this.ringSample(e/(this.width-1),t/(this.height-1)),this.echo[s]*i),a=Math.max(a,this.echo[s]);const r=Math.round(65535*this.echo[s]),n=4*s;this.pixels[n]=r>>>8,this.pixels[n+1]=255&r}this.echoPeak=a,this.active||(this.echo.fill(0),this.pixels.fill(0))}},Vt=class{constructor(t,e){this.previous=null,this.peak=0,this.width=t,this.height=e;const i=t*e;this.pixels=new Uint8Array(4*i),this.signal=new Float32Array(i),this.offsetX=new Float32Array(i),this.offsetY=new Float32Array(i),this.driftX=new Float32Array(i),this.driftY=new Float32Array(i),this.u=new Float32Array(i),this.v=new Float32Array(i),this.ink=new Float32Array(i),this.a=new Float32Array(i),this.b=new Float32Array(i),this.c=new Float32Array(i),this.pressure=new Float32Array(i),this.pressureNext=new Float32Array(i),this.divergence=new Float32Array(i),this.curl=new Float32Array(i)}get active(){return this.peak>2e-4}clear(){for(const t of[this.u,this.v,this.ink,this.a,this.b,this.c,this.pressure,this.pressureNext,this.divergence,this.curl,this.signal,this.pixels,this.offsetX,this.offsetY,this.driftX,this.driftY])t.fill(0);this.previous=null,this.peak=0}leave(){this.previous=null}move(t,e,i,a=performance.now()){if(!Number.isFinite(t+e+i+a))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e)),i=Math.max(.1,Math.min(1,i));const s=this.previous;if(this.previous={x:t,y:e,time:a},!s)return;const r=(t-s.x)*(this.width-1),n=(e-s.y)*(this.height-1),o=Math.hypot(r,n);if(o<.001)return;const h=Math.min(this.width,this.height),l=a>s.time?Math.max(1/240,(a-s.time)/1e3):1/60,c=Math.min(12,o/h/l),m=1-Math.exp(-c/2.2),u=h*(.022+.075*i)*(.65+.95*m),f=Math.min(128,Math.max(1,Math.ceil(o/(.4*u)))),d=o/u*(.32+.22*m)/f,p=r/o,g=n/o,M=-g,x=p,v=o*(2+18*m)/f;for(let i=0;i<f;i++){const a=(i+.5)/f,r=(s.x+(t-s.x)*a)*(this.width-1),n=(s.y+(e-s.y)*a)*(this.height-1),o=Math.max(1,Math.floor(r-3*u)),h=Math.min(this.width-2,Math.ceil(r+3*u)),l=Math.max(1,Math.floor(n-3*u)),c=Math.min(this.height-2,Math.ceil(n+3*u));for(let t=l;t<=c;t++)for(let e=o;e<=h;e++){const i=((e-r)*p+(t-n)*g)/u,a=((e-r)*M+(t-n)*x)/u,s=Math.exp(-i*i*.65-a*a*1.7),o=t*this.width+e;this.ink[o]=1-(1-this.ink[o])*Math.exp(-s*d);const h=1-a*a*.55,l=i*a*.7;this.u[o]=Math.max(-80,Math.min(80,this.u[o]+(p*h+M*l)*s*v)),this.v[o]=Math.max(-80,Math.min(80,this.v[o]+(g*h+x*l)*s*v))}}this.peak=1}read(t,e,i){const a=0|(e=Math.max(.5,Math.min(this.width-1.5,e))),s=0|(i=Math.max(.5,Math.min(this.height-1.5,i))),r=e-a,n=i-s,o=s*this.width+a;return(t[o]*(1-r)+t[o+1]*r)*(1-n)+(t[o+this.width]*(1-r)+t[o+this.width+1]*r)*n}sample(t,e){return this.read(this.signal,t*(this.width-1),e*(this.height-1))}displacement(t,e,i){i[0]=this.read(this.offsetX,t*(this.width-1),e*(this.height-1)),i[1]=this.read(this.offsetY,t*(this.width-1),e*(this.height-1))}step(t){if(!this.active||!Number.isFinite(t))return;let e=Math.max(0,Math.min(.05,t));const i=this.width,a=this.height;for(;e>1e-7;){const t=Math.min(1/60,e);e-=t;const s=Math.exp(-1.9*t),r=Math.exp(-3.2*t);for(let e=1;e<a-1;e++)for(let n=1;n<i-1;n++){const o=e*i+n,h=Math.max(.5,Math.min(i-1.5,n-this.u[o]*t)),l=Math.max(.5,Math.min(a-1.5,e-this.v[o]*t)),c=0|h,m=0|l,u=h-c,f=l-m,d=m*i+c,p=(1-u)*(1-f),g=u*(1-f),M=(1-u)*f,x=u*f;this.a[o]=(this.u[d]*p+this.u[d+1]*g+this.u[d+i]*M+this.u[d+i+1]*x)*s,this.b[o]=(this.v[d]*p+this.v[d+1]*g+this.v[d+i]*M+this.v[d+i+1]*x)*s,this.c[o]=(this.ink[d]*p+this.ink[d+1]*g+this.ink[d+i]*M+this.ink[d+i+1]*x)*r}[this.u,this.a]=[this.a,this.u],[this.v,this.b]=[this.b,this.v],[this.ink,this.c]=[this.c,this.ink];for(let t=1;t<a-1;t++)for(let e=1;e<i-1;e++){const a=t*i+e;this.curl[a]=.5*(this.v[a+1]-this.v[a-1]-this.u[a+i]+this.u[a-i])}for(let e=1;e<a-1;e++)for(let a=1;a<i-1;a++){const s=e*i+a,r=Math.abs(this.curl[s+1])-Math.abs(this.curl[s-1]),n=Math.abs(this.curl[s+i])-Math.abs(this.curl[s-i]),o=Math.hypot(r,n)+1e-4,h=this.curl[s]*t*10,l=Math.hypot(this.u[s],this.v[s]);this.u[s]+=n/o*h,this.v[s]-=r/o*h;const c=Math.min(1,l/(Math.hypot(this.u[s],this.v[s])+1e-6));this.u[s]*=c,this.v[s]*=c,this.divergence[s]=-.5*(this.u[s+1]-this.u[s-1]+this.v[s+i]-this.v[s-i])}this.pressure.fill(0);for(let t=0;t<4;t++){for(let t=1;t<a-1;t++)for(let e=1;e<i-1;e++){const a=t*i+e;this.pressureNext[a]=.25*(this.divergence[a]+this.pressure[a-1]+this.pressure[a+1]+this.pressure[a-i]+this.pressure[a+i])}[this.pressure,this.pressureNext]=[this.pressureNext,this.pressure]}let n=0;for(let e=1;e<a-1;e++)for(let a=1;a<i-1;a++){const s=e*i+a;this.u[s]=Math.max(-80,Math.min(80,this.u[s]-.5*(this.pressure[s+1]-this.pressure[s-1]))),this.v[s]=Math.max(-80,Math.min(80,this.v[s]-.5*(this.pressure[s+i]-this.pressure[s-i]))),this.driftX[s]+=(3.6*this.u[s]-58*this.offsetX[s]-12*this.driftX[s])*t,this.driftY[s]+=(3.6*this.v[s]-58*this.offsetY[s]-12*this.driftY[s])*t,this.offsetX[s]=Math.max(-2,Math.min(2,this.offsetX[s]+this.driftX[s]*t)),this.offsetY[s]=Math.max(-2,Math.min(2,this.offsetY[s]+this.driftY[s]*t)),this.signal[s]=1-Math.exp(.06*-Math.hypot(this.u[s],this.v[s])-.16*this.ink[s]),n=Math.max(n,this.signal[s])}this.peak=n}if(this.active)for(let t=0;t<this.ink.length;t++){const e=Math.round(65535*Math.min(1,this.signal[t]));this.pixels[4*t]=e>>>8,this.pixels[4*t+1]=255&e,this.pixels[4*t+2]=Math.round(128+63.5*this.offsetX[t]),this.pixels[4*t+3]=Math.round(128+63.5*this.offsetY[t])}else this.clear()}};var Kt=["loupe","repel","tilt","reveal","haze","bleed"],Jt=t=>Kt.includes(t),Qt=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}},Zt=t=>t*t*(3-2*t),_t=(t,e)=>{const i=43758.5453*Math.sin(127.1*t+311.7*e);return i-Math.floor(i)};function $t(t,e){const i=Math.floor(t),a=Math.floor(e),s=Zt(t-i),r=Zt(e-a),n=_t(i,a),o=_t(i+1,a),h=_t(i,a+1);return(n+(o-n)*s)*(1-r)+(h+(_t(i+1,a+1)-h)*s)*r}var te=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 Qt,this.y=new Qt,this.tx=new Qt,this.ty=new Qt,this.presence=new Qt,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*_t(e,t)}}setRadius(t){this.radius=Math.max(.1,Math.min(1,t))}get reach(){return(.05+.25*this.radius)*("loupe"===this.mode?1-.14*this.speed:1)}get engaged(){return this.presence.value>.002||this.inkPeak>.002||Math.abs(this.tx.value)+Math.abs(this.ty.value)>4e-4}get active(){const t=this.target?1:0;return!this.presence.resting(t)||!!this.target&&(!this.x.resting(this.target.x)||!this.y.resting(this.target.y))||!this.tx.resting(this.tiltGoal(0))||!this.ty.resting(this.tiltGoal(1))||this.speed>.01||"haze"===this.mode&&this.presence.value>.002||this.inkPeak>.002}tiltGoal(t){return this.target&&"tilt"===this.mode?2*((t?this.target.y:this.target.x)-.5):0}clear(){for(const t of[this.x,this.y,this.tx,this.ty,this.presence])t.set(0);this.x.set(.5),this.y.set(.5),this.target=null,this.speed=0,this.inkPeak=0,this.ink?.fill(0),this.next?.fill(0),this.encode()}move(t,e,i){if(!Number.isFinite(t+e))return;t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e));const a=Number.isFinite(i)?i/1e3:this.clock,s=this.target;if(!s&&this.presence.value<.05&&(this.x.set(t),this.y.set(e)),s){const i=Math.hypot((t-s.x)*this.sx,(e-s.y)*this.sy),r=i/Math.max(1/240,Math.min(.1,a-s.time||1/60));this.speed=Math.max(this.speed,Math.min(1,r/1.6)),"bleed"===this.mode&&this.deposit(s.x,s.y,t,e,Math.min(1,9*i))}else"bleed"===this.mode&&this.deposit(t,e,t,e,.5);this.target={x:t,y:e,time:a}}leave(){this.target=null}deposit(t,e,i,a,s){const r=this.ink,n=this.width,o=this.height,h=.55*this.reach,l=Math.hypot((i-t)*this.sx,(a-e)*this.sy),c=Math.min(48,Math.max(1,Math.ceil(l/(.5*h))));for(let l=0;l<c;l++){const m=(l+.5)/c,u=t+(i-t)*m,f=e+(a-e)*m,d=Math.max(0,Math.floor((u-2*h/this.sx)*(n-1))),p=Math.min(n-1,Math.ceil((u+2*h/this.sx)*(n-1))),g=Math.max(0,Math.floor((f-2*h/this.sy)*(o-1))),M=Math.min(o-1,Math.ceil((f+2*h/this.sy)*(o-1)));for(let t=g;t<=M;t++)for(let e=d;e<=p;e++){const i=(e/(n-1)-u)*this.sx/h,a=(t/(o-1)-f)*this.sy/h,l=t*n+e;r[l]=Math.min(1.4,r[l]+Math.exp(1.8*-(i*i+a*a))*s/c*1.6)}}this.inkPeak=Math.max(this.inkPeak,.01)}step(t){if(!Number.isFinite(t)||t<=0)return;const e=Math.min(.05,t),i=e*this.settle;this.clock+=e;const a=this.target,s=this.mode;if(a?this.presence.step(1,e,190,1):this.presence.step(0,i,"repel"===s?120:70,"repel"===s?.42:1),a){const t="tilt"===s?60:"haze"===s?90:240,i="loupe"===s||"repel"===s?.72:.9;this.x.step(a.x,e,t,i),this.y.step(a.y,e,t,i)}this.tx.step(this.tiltGoal(0),a?e:i,45,.78),this.ty.step(this.tiltGoal(1),a?e:i,45,.78),this.speed*=Math.exp(7*-e),"bleed"===s&&this.spread(e,i,!!a),this.engaged||this.active||(this.presence.set(0),this.tx.set(0),this.ty.set(0)),this.focus[0]=this.x.value,this.focus[1]=this.y.value,this.focus[2]=Math.max(0,Math.min(1,this.presence.value)),this.focus[3]=this.reach,this.encode()}spread(t,e,i){const a=this.ink,s=this.next,r=this.fiber,n=this.width,o=this.height;i&&this.target&&this.deposit(this.x.value,this.y.value,this.x.value,this.y.value,.9*t);const h=Math.max(1,Math.ceil(t/(1/240))),l=t/h,c=26*(.4+this.radius),m=(i?.02:.1)*e/t,u=Math.exp(-(i?.15:.9)*e/h);let f=0;for(let t=0;t<h;t++){f=0;for(let t=1;t<o-1;t++)for(let e=1;e<n-1;e++){const i=t*n+e,o=a[i],h=r[i],d=Math.min(h,r[i-1])*(a[i-1]-o)+Math.min(h,r[i+1])*(a[i+1]-o)+Math.min(h,r[i-n])*(a[i-n]-o)+Math.min(h,r[i+n])*(a[i+n]-o),p=Math.max(0,(o+d*Math.min(.24,c*l))*u-m*l);s[i]=p,p>f&&(f=p)}a.set(s)}this.inkPeak=f}sample(t,e,i){i[0]=i[1]=i[2]=0;const a=this.presence.value,s=this.mode;if("bleed"===s){if(this.inkPeak<=.002)return;const a=this.width,s=this.height,r=this.ink,n=Math.max(0,Math.min(a-1.001,t*(a-1))),o=Math.max(0,Math.min(s-1.001,e*(s-1))),h=Math.floor(n),l=Math.floor(o),c=n-h,m=o-l,u=l*a+h,f=u+a,d=(r[u]*(1-c)+r[u+1]*c)*(1-m)+(r[f]*(1-c)+r[f+1]*c)*m;return void(i[2]=1-Math.exp(2.4*-d))}if("tilt"===s){const a=this.guide?function(t,e,i,a){const s=t[e],r=t.width,n=t.height,o=Math.max(0,Math.min(r-1.001,i*(r-1))),h=Math.max(0,Math.min(n-1.001,a*(n-1))),l=Math.floor(o),c=Math.floor(h),m=o-l,u=h-c,f=c*r+l,d=Math.min(n-1,c+1)*r+l,p=l+1<r?1:0;return(s[f]*(1-m)+s[f+p]*m)*(1-u)+(s[d]*(1-m)+s[d+p]*m)*u}(this.guide,"depth",t,e):.6,s=.2+.8*a,r=this.edgeSafe?Bt(t,e,this.sx/this.sy):1;return i[0]=.024*this.tx.value*s*r/this.sx,void(i[1]=.024*this.ty.value*s*r/this.sy)}if(a<=.001)return;const r=this.reach,n=(t-this.x.value)*this.sx,o=(e-this.y.value)*this.sy,h=(n*n+o*o)/(r*r);if("reveal"===s)return void(i[2]=Math.exp(2.4*-h)*a);if(h>9)return;const l=this.edgeSafe?Bt(t,e,this.sx/this.sy):1;let c=0,m=0;if("loupe"===s){const t=Math.exp(-h*h)*a*.5;c=n*t,m=o*t;const e=Math.sqrt(h)-1;i[2]=Math.exp(-e*e/.018)*a*.55}else if("repel"===s){const t=Math.sqrt(h),e=.5*r*Math.exp(-h/1.7)*a,s=Math.max(1e-6,Math.sqrt(n*n+o*o));c=n/s*Math.min(e,s+.5*r*a),m=o/s*Math.min(e,s+.5*r*a);const l=Math.max(0,Math.min(1,(t-.3)/.32));i[2]=-(1-l*l*(3-2*l))*a}else if("haze"===s){const s=o/r+.45,h=Math.exp(-n*n/(r*r)-s*s/2.6)*a*(.35+.65*Math.min(1,1.4*this.speed+.25));if(h<.002)return;const l=this.clock,u=t*this.sx*9,f=e*this.sy*9+2.3*l;c=.06*($t(u,f)-.5)*h,m=.026*($t(u+17.3,1.3*f+.7*l)-.5)*h,i[2]=.35*($t(1.7*u+5,1.7*f)-.5)*h}i[0]=c*l/this.sx,i[1]=m*l/this.sy}encode(){const t=this.width,e=this.height,i=this.pixels,a=this.sampled,s=this.engaged;for(let r=0;r<e;r++)for(let n=0;n<t;n++){const o=4*(r*t+n);if(s?this.sample(n/(t-1),r/(e-1),a):a[0]=a[1]=a[2]=0,"bleed"===this.mode){const t=Math.round(32767*Math.max(-1,Math.min(1,a[2]))+32768);i[o]=t>>>8,i[o+1]=255&t,i[o+2]=128,i[o+3]=0}else{"repel"===this.mode&&(a[0]*=.3,a[1]*=.3);const t=Math.round(32767*Math.max(-1,Math.min(1,a[0]/.16))+32768),e=Math.round(32767*Math.max(-1,Math.min(1,a[1]/.16))+32768);i[o]=t>>>8,i[o+1]=255&t,i[o+2]=e>>>8,i[o+3]=255&e}}}},ee=(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 ie(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 ae=t=>["trail","contour","etch","ripple","bleed","haze"].includes(t),se=class{constructor(t=1){this.ripple=null,this.cursor=null,this.settle=1,this.mode="water",this.amount=.55,this.radius=.2,this.lensX=.5,this.lensY=.5,this.lensStrength=0,this.previous=null,this.energy=0,this.pending=!1,this.remainder=0,this.quiet=0,this.guide=null,t=Math.max(.25,Math.min(4,t)),this.columns=Math.round(t>=1?128:128*t),this.rows=Math.round(t>=1?128/t:128),this.xScale=Math.max(1,t),this.yScale=Math.max(1,1/t),this.heights=new Float32Array(this.columns*this.rows),this.velocity=new Float32Array(this.heights.length),this.next=new Float32Array(this.heights.length),this.normals=new Float32Array(2*this.heights.length),this.edgeMask=new Float32Array(this.heights.length);for(let e=0;e<this.rows;e++)for(let i=0;i<this.columns;i++)this.edgeMask[e*this.columns+i]=Bt(i/(this.columns-1),e/(this.rows-1),t);this.refraction={width:this.columns,height:this.rows,pixels:new Uint8Array(4*this.heights.length),strength:30,mode:"water",focus:[.5,.5,0,.2]},this.waterPixels=this.refraction.pixels,this.trail=new Vt(this.columns,this.rows),this.contour=new Gt(this.columns,this.rows),this.afterimage=new Ht(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 Jt(this.mode)?this.cursor.engaged:this.active}get spotlight(){return"reveal"===this.mode&&this.cursor?this.cursor.focus:null}get signature(){return Jt(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 Jt(this.mode)?this.cursor.active:"ripple"===this.mode?this.ripple?.active??!1:Yt(this.mode)?this.afterimage.active:"contour"===this.mode?this.contour.active:"trail"===this.mode?this.trail.active:this.pending||this.energy>15e-5}setMode(t){const e="light"===t||"scan"===t?t:m(t)??"none";e!==this.mode&&(this.clear(),this.mode=e,this.refraction.mode=e,Yt(e)&&this.afterimage.setMode(e),"ripple"!==e||this.ripple||(this.ripple=new zt(this.columns,this.rows)),Jt(e)&&(this.cursor??(this.cursor=new te(this.columns,this.rows)),this.cursor.guide=this.guide,this.cursor.setMode(e)),this.refraction.pixels=Jt(e)?this.cursor.pixels:"ripple"===e?this.ripple.pixels:"trail"===e?this.trail.pixels:"contour"===e?this.contour.pixels:Yt(e)?this.afterimage.pixels:this.waterPixels,this.refraction.strength=ee(e,this.amount),this.refraction.relative=Jt(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=ee(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)),Jt(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(Yt(this.mode))return void this.afterimage.move(t,e,this.radius);if("contour"===this.mode)return void this.contour.move(t,e,this.radius);if("trail"===this.mode)return void this.trail.move(t,e,this.radius,i);if("water"!==this.mode)return!this.previous&&this.lensStrength<.001&&(this.lensX=t,this.lensY=e),this.previous={x:t,y:e},void(this.pending=!0);if(!this.previous)return void(this.previous={x:t,y:e});const a=this.previous;this.previous={x:t,y:e};const s=(t-a.x)*this.xScale,r=(e-a.y)*this.yScale,n=Math.hypot(s,r);if(n<1e-5)return;const o=.035+.1*this.radius,h=3*o,l=Math.min(192,Math.max(1,Math.ceil(n/(.5*o)))),c=95*Math.min(n,1)/l;for(let i=0;i<l;i++){const s=(i+.5)/l,r=a.x+(t-a.x)*s,n=a.y+(e-a.y)*s,m=Math.max(1,Math.floor((r-h/this.xScale)*(this.columns-1))),u=Math.min(this.columns-2,Math.ceil((r+h/this.xScale)*(this.columns-1))),f=Math.max(1,Math.floor((n-h/this.yScale)*(this.rows-1))),d=Math.min(this.rows-2,Math.ceil((n+h/this.yScale)*(this.rows-1)));for(let t=f;t<=d;t++)for(let e=m;e<=u;e++){const i=(e/(this.columns-1)-r)*this.xScale,a=(t/(this.rows-1)-n)*this.yScale,s=Math.exp(-(i*i+a*a)/(o*o))*c,h=t*this.columns+e;this.velocity[h]=Math.max(-12,this.velocity[h]-s)}}this.pending=!0,this.quiet=0}leave(){this.cursor?.leave(),this.ripple?.leave(),this.afterimage.leave(),this.contour.leave(),this.trail.leave(),this.previous=null,"water"!==this.mode&&this.lensStrength&&(this.pending=!0)}clear(){this.trail.clear(),this.contour.clear(),this.afterimage.clear(),this.ripple?.clear(),this.cursor?.clear(),this.heights.fill(0),this.velocity.fill(0),this.next.fill(0),this.normals.fill(0),this.refraction.focus[2]=0,this.previous=null,this.lensStrength=0,this.energy=0,this.pending=!1,this.remainder=0,this.quiet=0;for(let t=0;t<this.waterPixels.length;t+=4)this.waterPixels[t]=this.waterPixels[t+2]=128,this.waterPixels[t+1]=this.waterPixels[t+3]=0}step(t){if(!this.active||!Number.isFinite(t))return;if(Jt(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(Yt(this.mode))return void this.afterimage.step(t);if("contour"===this.mode)return void this.contour.step(t);if("trail"===this.mode)return void this.trail.step(t);if("water"!==this.mode)return void this.stepLight(Math.max(0,Math.min(.05,t)));this.remainder+=Math.max(0,Math.min(.05,t));const e=1/120,i=.3*Math.min(this.columns,this.rows);for(;this.remainder+1e-8>=e;){this.remainder-=e,this.quiet+=e;const t=Math.max(0,Math.min(1,(this.quiet-.2)/.6)),a=t*t*(3-2*t),s=Math.exp(-(3.8+3*a)*e),r=Math.exp(7*-a*e);let n=0;for(let t=1;t<this.rows-1;t++)for(let a=1;a<this.columns-1;a++){const o=t*this.columns+a,h=this.heights[o],l=this.heights[o-1]+this.heights[o+1]+this.heights[o-this.columns]+this.heights[o+this.columns]-4*h,c=Math.min(a,t,this.columns-1-a,this.rows-1-t),m=c<5?.88+.024*c:1,u=(this.velocity[o]+(l*i*i-8*h)*e)*s*m;this.velocity[o]=u,this.next[o]=(h+u*e)*m*r,n=Math.max(n,Math.abs(this.next[o]),.1*Math.abs(u))}this.heights.set(this.next),this.energy=n,this.pending=!1}if(!this.active)return void this.clear();const a=.18*Math.min(this.columns,this.rows);for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++){const i=t*this.columns+e,s=(this.heights[t*this.columns+Math.max(0,e-1)]-this.heights[t*this.columns+Math.min(this.columns-1,e+1)])*a,r=(this.heights[Math.max(0,t-1)*this.columns+e]-this.heights[Math.min(this.rows-1,t+1)*this.columns+e])*a,n=Math.tanh(s)*(this.refraction.edgeSafe?this.edgeMask[i]:1),o=Math.tanh(r)*(this.refraction.edgeSafe?this.edgeMask[i]:1);this.normals[2*i]=n,this.normals[2*i+1]=o;const h=Math.round(32767*n+32768),l=Math.round(32767*o+32768);this.refraction.pixels[4*i]=h>>>8,this.refraction.pixels[4*i+1]=255&h,this.refraction.pixels[4*i+2]=l>>>8,this.refraction.pixels[4*i+3]=255&l}}stepLight(t){const e=this.previous,i=1-Math.exp(-30*t),a=1-Math.exp(-12*t);e&&(this.lensX+=(e.x-this.lensX)*i,this.lensY+=(e.y-this.lensY)*i),this.lensStrength+=((e?1:0)-this.lensStrength)*a,this.energy=Math.max(e?Math.abs(e.x-this.lensX)+Math.abs(e.y-this.lensY):0,Math.abs((e?1:0)-this.lensStrength)),this.pending=!1,e||this.active?this.refraction.focus=[this.lensX,this.lensY,this.lensStrength*this.amount,this.radius]:this.clear()}sample(t,e,i){if(Jt(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(Yt(this.mode))return this.afterimage.sample(t,e,i),i[0]*=this.amount,i[1]*=this.amount,void(i[2]*=this.amount);if("contour"===this.mode)return i[0]=i[1]=0,void(i[2]=this.contour.sample(t,e)*this.amount*3);if("trail"===this.mode)return i[0]=i[1]=0,void(i[2]=this.trail.sample(t,e)*this.amount*3);const a=Math.max(0,Math.min(this.columns-1.001,t*(this.columns-1))),s=Math.max(0,Math.min(this.rows-1.001,e*(this.rows-1))),r=Math.floor(a),n=Math.floor(s),o=a-r,h=s-n,l=2*(n*this.columns+r),c=l+2*this.columns;for(let t=0;t<2;t++)i[t]=.08*((this.normals[l+t]*(1-o)+this.normals[l+2+t]*o)*(1-h)+(this.normals[c+t]*(1-o)+this.normals[c+2+t]*o)*h);i[0]*=this.amount/.55,i[1]*=this.amount/.55,i[2]="light"===this.mode||"scan"===this.mode?function(t,e,i,a){const[s,r,n,o]=i.focus,h=(t-s)*Math.max(1,a)/o,l=(e-r)*Math.max(1,1/a)/o;return"light"===i.mode?Math.exp(-3*(h*h+l*l))*n:"scan"===i.mode?(1.3*Math.exp(-h*h*110)-.3*Math.exp(-h*h*12))*Math.exp(-l*l*1.8)*n:0}(t,e,this.refraction,this.xScale/this.yScale):0}};function re(t){return"videoWidth"in t?[t.videoWidth,t.videoHeight]:"naturalWidth"in t?[t.naturalWidth,t.naturalHeight]:[t.width,t.height]}var ne=(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)},he={blocks:" ░▒▓█",braille:" ⠁⠃⠇⡇⣇⣧⣷⣿",lines:" -═╪╬",cross:" ·+xX#",diagonal:" /╱╳",diamond:" ·◇◈◆",mixed:" .:+/◇#@"},le=.32,ce=.9;function me(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<le&&(s=Math.max(0,Math.min(1-le,(s+r)/2-.16)),r=s+le),[s,r]}function ue(t,e,i){const a=Math.max(.001,i-e);let s=0,r=0;for(let i=0;i<t.length;i+=4){if(t[i+3]<8)continue;const n=((.299*t[i]+.587*t[i+1]+.114*t[i+2])/255-e)/a;n<=.06||(s+=Math.min(1,n),r++)}if(!r)return ce;const n=Math.min(.99,Math.max(.01,s/r));return Math.min(ce,Math.max(.6,Math.log(.5)/Math.log(n)))}function fe(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 de(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 pe=new WeakMap,ge=t=>Math.max(64,Math.min(4096,Number.isFinite(t)?t:960));function Me(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 xe(t,e,i,a,s){const[r,n]=re(e);t.clearRect(0,0,i,a),t.save();const o=et(r,n,i,a,s);t.translate(o.x+o.width/2,o.y+o.height/2),t.rotate(s.rotation*Math.PI/180),t.drawImage(e,-r*o.scale/2,-n*o.scale/2,r*o.scale,n*o.scale),t.restore()}function ve(t,e={},i={}){return function(t,e,i,a){const s=a.surface,r=t.getContext("2d");if(!r)throw new Error("Canvas is already owned by another renderer.");const n=s(),o=s(!0),h=s(),l=s(),c=s(),m=s(),u=s(),d=s(),M=s(),x=s();let v,y,b=0,w=0,k=1,S=ce,R=null,P=null,T=null,I="",C=tt(e),N=0,O="",U="",L="",q=new Uint8ClampedArray(0),X=new Uint8ClampedArray(0),z=new Uint8ClampedArray(0),j=null,W="",H=0,G=0,V=0,J=null,Q="",Z=new se,_=null,$=new Float32Array(0);const et=s(!0),it=s(),at=s();let rt=0;const nt=[0,0,0],lt=[0,0,0,1],ct=[0,0],mt=[0,0,0,0];let ut=ot(C.color),ft=gt(C.print);const dt=new ht(C.color.denoise),pt=new B(C.warps,C.warpEdge),Mt=ge(i.maxDimension),yt=Math.max(256,Math.min(1048576,Number.isFinite(i.maxCells)?i.maxCells:12e3));let kt=yt,Et=Math.max(.1,Math.min(8,i.pixelRatio??1));const Rt=(t,e,i)=>{Z.configure(C.hover.effect,C.hover.strength,C.hover.radius,C.hover.edgeSafe,C.hover.decay),Z.move(t,e,i)};function Pt(t,e=0,i=960,a=540,s=e*C.motion.speed){Tt(t,e,i,a,s,!0)}function Tt(e,i,s,B,tt,ot){if(Number.isFinite(i)||(i=0),!Number.isFinite(s)||!Number.isFinite(B)||s<1||B<1)throw new Error("Render dimensions must be positive finite numbers.");const[ht,gt]=re(e);if(!ht||!gt)return;const[yt,Rt]=Me(Mt,s,B);oe(t,yt,Rt),oe(n.canvas,yt,Rt),oe(h.canvas,yt,Rt),oe(l.canvas,yt,Rt),oe(c.canvas,yt,Rt),rt!==yt/Rt&&(rt=yt/Rt,Z=new se(rt),Z.setGuide(_)),Z.configure(C.hover.effect,C.hover.strength,C.hover.radius,C.hover.edgeSafe,C.hover.decay),Z.step(Math.max(0,Math.min(.05,i-V))),V=i;const Pt=a.media(e),Tt=[N,yt,Rt,Pt.time].join(":"),Dt="dither"===C.style,Nt=st(yt,Rt,C,kt,Et),Bt=Nt.cell,zt=Nt.rowHeight,Yt=Nt.columns,jt=Nt.rows;if(O!==Tt||J!==Pt.key||H!==Yt||G!==jt){J=Pt.key,O=Tt,W="",U="",L="",H=Yt,G=jt,a.scene?a.scene(n.ctx,yt,Rt):xe(n.ctx,e,yt,Rt,C.crop),oe(o.canvas,H,G),o.ctx.clearRect(0,0,H,G),o.ctx.drawImage(n.canvas,0,0,H,G),q=o.ctx.getImageData(0,0,H,G).data,dt.apply(q,H,G),X.length!==q.length&&(X=new Uint8ClampedArray(q.length)),X.set(q);const t=C.color;for(let e=0;e<q.length;e+=4){const i=.299*q[e]+.587*q[e+1]+.114*q[e+2];for(let a=0;a<3;a++){const s=i+(q[e+a]-i)*t.saturation;q[e+a]=((s*(1-t.grayscale)+i*t.grayscale)/255-.5)*t.contrast*255+127.5+255*t.brightness}}if(ut&&function(t,e){for(let i=0;i<t.length;i+=4)t[i+3]&&(t[i]=e[t[i]],t[i+1]=e[256+t[i+1]],t[i+2]=e[512+t[i+2]])}(q,ut),q=pt.apply(q,H,G,yt/Rt),"none"!==C.color.levels){const[t,e]=me(q),i=ue(q,t,e),a=R===Pt.key&&Pt.video?.15:1;R=Pt.key,w+=(t-w)*a,k+=(e-k)*a,S+=(i-S)*a}const i=C.hover,s=i.scope??"all";if("none"===i.effect||"all"===s&&"tilt"!==i.effect)_=null;else{let t=null;if(C.mask.enabled&&C.mask.shapes.length){oe(et.canvas,H,G),et.ctx.clearRect(0,0,H,G),de(et.ctx,H,G,C.mask.shapes);const e=et.ctx.getImageData(0,0,H,G).data;t=new Float32Array(H*G);for(let i=0;i<t.length;i++)t[i]=C.mask.invert?1-e[4*i+3]/255:e[4*i+3]/255}_=p(q,H,G,t,_),$.length!==H*G&&($=new Float32Array(H*G));for(let t=0;t<$.length;t++)$[t]=g(s,_.subject[t],_.key);if("reveal"===i.effect){oe(it.canvas,H,G);const t=new ImageData(H,G);for(let e=0;e<$.length;e++)t.data[4*e+3]=255*$[e];it.ctx.putImageData(t,0,0)}}Z.setGuide(_)}if(!ot)return void(L=U="");const Wt=vt(C),Ht=xt(C),Gt=!Z.active&&!Wt&&!Ht,Vt=[Tt,H,G,Bt,zt,Et,Z.signature].join(":"),Kt=Z.engaged,Jt=Z.effect;if(!Gt||L!==Vt){h.ctx.clearRect(0,0,yt,Rt),h.ctx.globalAlpha=1,h.ctx.globalCompositeOperation="source-over";const t=tt,e=Wt?C.motion.type:"none",s=C.motion.amount??1,r="relight"===(Qt=e)||"sheen"===Qt||"glow"===Qt||"shimmer"===Qt||"mist"===Qt;"none"!==e&&W!==O&&(j=function(t,e,i,a,s=t){const r=e*i,n=a?.length===r*bt?a:new Float32Array(r*bt);if(!r)return n;const o=Math.min(e,i),h=new Float32Array(r),l=new Float32Array(r),c=new Float32Array(r),m=new Float32Array(r),u=new Float32Array(r),d=new Float32Array(r);for(let e=0;e<r;e++){const i=t[4*e+3]/255;h[e]=(.299*t[4*e]+.587*t[4*e+1]+.114*t[4*e+2])/255*i}l.set(h),f(l,d,e,i,Math.max(1,Math.round(.012*o))),c.set(h),f(c,d,e,i,Math.max(1,Math.round(.03*o)));for(let t=0;t<r;t++){m[t]=Math.abs(h[t]-l[t]);const e=Math.max(0,h[t]-.55)/.45;u[t]=e*e}f(m,d,e,i,Math.max(1,Math.round(.02*o)));const p=1/Math.max(.02,At(m,.95));f(u,d,e,i,Math.max(1,Math.round(.05*o)));const g=1/Math.max(.03,At(u,.98)),M=Math.max(1,Math.ceil(Math.sqrt(r/12e3))),x=Math.max(1,Math.floor(e/M)),v=Math.max(1,Math.floor(i/M)),y=x*v;let b=t,w=s;if(M>1){const i=new Uint8ClampedArray(4*y),a=s===t?i:new Uint8ClampedArray(4*y);for(let r=0;r<v;r++)for(let n=0;n<x;n++){const o=[0,0,0,0,0,0,0];for(let h=r*M;h<(r+1)*M;h++)for(let r=n*M;r<(n+1)*M;r++){const n=4*(h*e+r);for(let e=0;e<4;e++)o[e]+=t[n+e];if(a!==i)for(let t=0;t<3;t++)o[4+t]+=s[n+t]}const h=4*(r*x+n),l=M*M;for(let t=0;t<4;t++)i[h+t]=o[t]/l;if(a!==i){for(let t=0;t<3;t++)a[h+t]=o[4+t]/l;a[h+3]=i[h+3]}}b=i,w=a}Ft?.n!==y&&(Ft=new St(y)),Ft.reset();const{depth:k,water:A,sky:S,falls:F}=It(b,w,x,v,Ft),E=At(k,.03),R=At(k,.97),P=Math.max(.05,R-E);let T=0,I=0,C=0;const D=new Float32Array(r);for(let t=0;t<i;t++)for(let a=0;a<e;a++){const s=t*e+a,r=s*bt,o=wt((Ct(k,x,v,a,t,e,i)-E)/P);n[r+1]=o,n[r+8]=wt(Ct(A,x,v,a,t,e,i)),n[r+9]=wt(Ct(S,x,v,a,t,e,i)),n[r+10]=wt(Ct(F,x,v,a,t,e,i));const l=o*o*o*(.25+h[s]);T+=(a+.5)/e*l,I+=(t+.5)/i*l,C+=l,D[s]=Math.hypot(c[t*e+Math.min(e-1,a+1)]-c[t*e+Math.max(0,a-1)],c[Math.min(i-1,t+1)*e+a]-c[Math.max(0,t-1)*e+a])}T=C>0?Math.max(.3,Math.min(.7,T/C)):.5,I=C>0?Math.max(.3,Math.min(.7,I/C)):.5;const N=1/Math.max(.004,At(D,.97));for(let t=0;t<i;t++)for(let a=0;a<e;a++){const s=t*e+a,r=s*bt,o=(c[t*e+Math.min(e-1,a+1)]-c[t*e+Math.max(0,a-1)])*N,h=(c[Math.min(i-1,t+1)*e+a]-c[Math.max(0,t-1)*e+a])*N;n[r]=c[s],n[r+2]=Math.min(1,u[s]*g),n[r+3]=Math.min(1,m[s]*p),n[r+4]=Math.max(-1,Math.min(1,-o)),n[r+5]=Math.max(-1,Math.min(1,-h)),n[r+6]=T,n[r+7]=I}return n}(X,H,G,j),W=O);let p=null;if(Dt){const a=Gt;if(!a||U!==Tt){z.length!==q.length&&(z=new Uint8ClampedArray(q.length));const r=z;if(r.set(q),Kt||"none"!==e)for(let i=0;i<G;i++)for(let a=0;a<H;a++){const n=a/H,o=i/G;let h=a,l=i,c=0,m=0,u=1;if(Kt){Z.sample(n,o,nt);const t=_?$[i*H+a]:1;h-=nt[0]*t*H,l-=nt[1]*t*G,"reveal"===Jt?u=1-.72*Math.min(1,nt[2]*t):"repel"===Jt?u=1+Math.max(-1,nt[2])*t:c=nt[2]/3*t}const f=4*(i*H+a);A(e,n,o,t,lt,(.299*q[f]+.587*q[f+1]+.114*q[f+2])/255,j??void 0,(i*H+a)*bt),E(lt,s),(lt[0]||lt[1])&&(F(lt,h,l,H,G,ct),h=ct[0],l=ct[1]),m=lt[2],u*=lt[3];const d=4*(i*H+a);D(q,H,G,h,l,mt);for(let t=0;t<3;t++){let e=ie(Jt,mt[t]/255,c)+m;r[d+t]=255*e}r[d+3]=mt[3]*u}!function(t,e,i,a,s=0){const{algorithm:r,amount:n,threshold:o}=a,h="blue-noise"===r,l=r.startsWith("bayer")?Number(r.slice(5)):0,c=Lt.get(l),m=l-1,u="luminance"===a.colorSpace,f=("custom"===a.palette?a.colors:K[a.palette]??K.mono).map(Xt),d=qt[r],p=d?new Float32Array(3*e*3):null,g="drift"===a.motion?s*a.speed*3:0,M=(a.direction??45)*Math.PI/180,x=Math.round(Math.cos(M)*g),v=Math.round(Math.sin(M)*g),y=(t,e)=>(t%e+e)%e,b=f.map(t=>.299*t[0]+.587*t[1]+.114*t[2]),w="shimmer"===a.motion?.15*Math.sin(s*a.speed*2):0;for(let a=0;a<i;a++)for(let s=0;s<e;s++){const M=4*(a*e+s),k=3*(a%3*e+s);if(0===t[M+3]){p&&(p[k]=p[k+1]=p[k+2]=0);continue}let A=0;const S=h?(Ot[64*(a-v&63)+(s-x&63)]+.5)/Ot.length:0;c?A=c[(a-v&m)*l+(s-x&m)]:"noise"===r?A=Ut(s-x,a-v)-.5:"lines"===r?A=y(a-v,4)/3-.5:"vertical-lines"===r?A=y(s-x,4)/3-.5:"diagonal-lines"===r?A=y(s-x+a-v,4)/3-.5:"radial"===r?A=y(Math.hypot(s-e/2,a-i/2)-g,6)/6-.5:"halftone"===r&&(A=Math.hypot(y(s-x,6)-2.5,y(a-v,6)-2.5)/3.54-.5);const F=128*(A*n+w+(.5-o)),E=t[M]+F+(p?.[k]??0),R=t[M+1]+F+(p?.[k+1]??0),P=t[M+2]+F+(p?.[k+2]??0);let T=0,I=0,C=0;if(f.length){let t=1/0,e=1/0,i=0,a=0;const s=.299*E+.587*R+.114*P;for(let r=0;r<f.length;r++){const n=f[r],o=u?(s-b[r])**2:(E-n[0])**2*.299+(R-n[1])**2*.587+(P-n[2])**2*.114;o<t?(h&&(e=t,a=i,i=r),t=o,[T,I,C]=n):h&&o<e&&(e=o,a=r)}if(h&&n>0&&Number.isFinite(e)){const t=f[a],e=t[0]-T,r=t[1]-I,o=t[2]-C,h=b[a]-b[i],l=u?h*h:e*e*.299+r*r*.587+o*o*.114,c=u?(s-b[i])*h:(E-T)*e*.299+(R-I)*r*.587+(P-C)*o*.114;S<(l?Math.max(0,Math.min(1,c/l*n)):0)&&([T,I,C]=t)}}else if(h){const t=Math.max(0,Math.min(1,.5+(S-.5)*n));T=51*Math.floor(E/51+1-t),I=51*Math.floor(R/51+1-t),C=51*Math.floor(P/51+1-t)}else T=51*Math.round(E/51),I=51*Math.round(R/51),C=51*Math.round(P/51);if(t[M]=T,t[M+1]=I,t[M+2]=C,p&&d){p[k]=p[k+1]=p[k+2]=0;for(const[t,r,o]of d){const h=s+t;if(h<0||h>=e||a+r>=i)continue;const l=3*((a+r)%3*e+h);p[l]+=(E-T)*o*n,p[l+1]+=(R-I)*o*n,p[l+2]+=(P-C)*o*n}}}}(r,H,G,C.dither,i),o.ctx.putImageData(new ImageData(r,H,G),0,0),U=a?Tt:""}h.ctx.imageSmoothingEnabled=!1,h.ctx.drawImage(o.canvas,0,0,yt,Rt)}else{const i="pointillism"===C.style;i&&a.marks&&void 0===y&&(y=a.marks()),p=i&&y?.begin(yt,Rt)?y:null;const n=Array.from(he[C.style]??C.charset),o=p?.ctx??h.ctx,l=Xt(C.ink),c="ripple"===Jt||"etch"===Jt,m=c&&.299*l[0]+.587*l[1]+.114*l[2]<90?[214,214,214]:l,f="ascii"===C.style||!!he[C.style],d=Y(C.style)?C.style:null,g=Math.max(3,Math.round(.92*zt)),M=Math.ceil(Bt+4),v=Math.ceil(zt+4),R=[n.join(""),g,M,v,C.ink,C.colorMode].join(":");if(f&&R!==Q){Q=R,oe(u.canvas,M*n.length,v),u.ctx.clearRect(0,0,u.canvas.width,v),u.ctx.font=`${g}px monospace`,u.ctx.textBaseline="middle",u.ctx.textAlign="center",u.ctx.fillStyle="accent"===C.colorMode?C.ink:"#ffffff",n.forEach((t,e)=>u.ctx.fillText(t,e*M+M/2,v/2)),P=null,I="";try{const t=u.ctx.getImageData(0,0,u.canvas.width,u.canvas.height).data;P=n.map((e,i)=>{let a=0;for(let e=0;e<u.canvas.height;e++)for(let s=i*M;s<(i+1)*M&&s<u.canvas.width;s++)a+=t[4*(e*u.canvas.width+s)+3];return a})}catch{P=null}}const N=f&&"none"!==C.color.levels;if(N&&P){const t=Q+":"+S.toFixed(2);t!==I&&(I=t,T=fe(P,S))}const O=Math.max(.001,k-w);if("lego"===C.style&&b!==Bt){b=Bt,oe(x.canvas,Math.ceil(Bt),Math.ceil(zt));const t=x.ctx;t.clearRect(0,0,x.canvas.width,x.canvas.height),t.fillStyle="rgba(255,255,255,.2)",t.strokeStyle="rgba(0,0,0,.25)",t.lineWidth=Math.max(.5,.6*Et),t.beginPath(),t.arc(Bt/2,zt/2,.28*Bt,0,2*Math.PI),t.fill(),t.stroke()}o.font=`${g}px monospace`,o.textBaseline="middle",o.textAlign="center";for(let i=0;i<G;i++)for(let a=0;a<H;a++){let h=a,g=i,y=0,b=0;if(Kt){Z.sample(a/H,i/G,nt);const t=_?$[i*H+a]:1;h=Math.max(0,Math.min(H-1,a-nt[0]*t*H)),g=Math.max(0,Math.min(G-1,i-nt[1]*t*G)),"reveal"===Jt?b=.72*Math.min(1,nt[2]*t):"repel"===Jt?b=-Math.max(-1,nt[2])*t:y=nt[2]/3*t}if("none"!==e){const r=4*(i*H+a);A(e,a/H,i/G,t,lt,(.299*q[r]+.587*q[r+1]+.114*q[r+2])/255,j??void 0,(i*H+a)*bt),E(lt,s),(lt[0]||lt[1])&&(F(lt,h,g,H,G,ct),h=ct[0],g=ct[1])}D(q,H,G,h,g,mt);let k=0;if(c&&y>.012&&(mt[3]?mt[3]>250&&.299*mt[0]+.587*mt[1]+.114*mt[2]<30:"outside"===C.hover.scope)){const t=Math.min(1,(y-.012)/.12);k=t*t*(3-2*t)}if(!mt[3]){if(!(k||y>.03)||"outside"!==C.hover.scope||!ae(Jt))continue;mt[0]=m[0],mt[1]=m[1],mt[2]=m[2],mt[3]=k?255:Math.min(255,640*y)}const R=mt[0],I=mt[1],U=mt[2],L=(.299*R+.587*I+.114*U)/255;let X=N?Math.max(0,Math.min(1,(L-w)/O)):L;X=ie(Jt,X,y,!!d&&ft.settings.invert);const B=a*Bt,z=i*zt;let Y=1,W=X;if("none"!==e){const t=lt[2]/(N?Math.max(.5,O):1);X=Math.max(0,Math.min(1,X+t)),W=Math.max(0,Math.min(1,W+t*(r?.45:1)))}else W=X;k&&(X=W=Math.max(X,.1+.45*k)),Y=("none"!==e?lt[3]:1)*mt[3]/255*(1-b)*(k?.3+.45*k:1),f||d||"accent"!==C.colorMode||"cmyk"===C.style?N&&"accent"===C.colorMode&&(Y*=.32+.68*Math.pow(X,S)):Y*=X,o.globalAlpha=Y;const V=255*(X-L),K=p&&"accent"!==C.colorMode?C.ink:"source"===C.colorMode?`rgb(${R+V},${I+V},${U+V})`:"gray"===C.colorMode?`rgb(${Math.round(255*X)},${Math.round(255*X)},${Math.round(255*X)})`:C.ink;if(o.fillStyle=K,d)ft.paint(o,d,a,i,B,z,Bt,X,K,"gray"===C.colorMode?255*X:R+V,"gray"===C.colorMode?255*X:I+V,"gray"===C.colorMode?255*X:U+V,C.colorMode);else if(f){const t=N&&T?T[Math.round(255*W)]:Math.max(0,Math.min(n.length-1,Math.round(W*(n.length-1))));if("accent"===C.colorMode?0===P?.[t]:" "===n[t])continue;"accent"===C.colorMode?o.drawImage(u.canvas,t*M,0,M,v,Math.round(B+(Bt-M)/2),Math.round(z+(zt-v)/2),M,v):o.fillText(n[t],B+Bt/2,z+zt/2)}else if("dots"===C.style)o.beginPath(),o.arc(B+Bt/2,z+zt/2,.48*Bt*Math.sqrt(X),0,2*Math.PI),o.fill();else if("led"===C.style)o.beginPath(),o.arc(B+Bt/2,z+zt/2,.39*Bt,0,2*Math.PI),o.fill(),o.globalAlpha=.35*Y,o.fillStyle="#ffffff",o.beginPath(),o.arc(B+.43*Bt,z+.4*zt,.11*Bt,0,2*Math.PI),o.fill();else if("hex"===C.style){const t=B+Bt/2,e=z+zt/2;o.beginPath();for(let i=0;i<6;i++){const a=Math.PI/3*i,s=t+Math.cos(a)*Bt*.49,r=e+Math.sin(a)*zt*.49;0===i?o.moveTo(s,r):o.lineTo(s,r)}o.closePath(),o.fill()}else if("cmyk"===C.style){o.fillStyle="#ffffff",o.fillRect(B,z,Bt,zt);const t=(t,e)=>Math.max(0,Math.min(255,"source"===C.colorMode?t+V:"gray"===C.colorMode?255*X:e*X)),e=t(R,l[0]),i=t(I,l[1]),a=t(U,l[2]),s=1-Math.max(e,i,a)/255,r=Math.max(.001,1-s),n=[["#00ffff",(1-e/255-s)/r,.36,.36],["#ff00ff",(1-i/255-s)/r,.64,.36],["#ffff00",(1-a/255-s)/r,.5,.66],["#000000",s,.5,.5]];o.globalCompositeOperation="multiply";for(const[t,e,i,a]of n)e>0&&(o.fillStyle=t,o.beginPath(),o.arc(B+Bt*i,z+zt*a,.48*Bt*Math.sqrt(Math.max(0,e)),0,2*Math.PI),o.fill());o.globalCompositeOperation="source-over"}else if("voxel"===C.style){const t=B+Bt/2,e=z+zt/2;o.beginPath(),o.moveTo(t,z),o.lineTo(B+Bt,z+.25*zt),o.lineTo(t,e),o.lineTo(B,z+.25*zt),o.closePath(),o.fill(),o.globalAlpha=.72*Y,o.beginPath(),o.moveTo(B,z+.25*zt),o.lineTo(t,e),o.lineTo(t,z+zt),o.lineTo(B,z+.75*zt),o.closePath(),o.fill(),o.globalAlpha=.42*Y,o.beginPath(),o.moveTo(t,e),o.lineTo(B+Bt,z+.25*zt),o.lineTo(B+Bt,z+.75*zt),o.lineTo(t,z+zt),o.closePath(),o.fill()}else{const t="pixel"===C.style?0:Math.max(.5,.06*Bt);o.fillRect(B,z,Bt-t,zt-t),"lego"===C.style&&o.drawImage(x.canvas,B,z),"disco"===C.style&&(o.fillStyle=`rgba(255,255,255,${.1+.25*Ut(a,i)})`,o.fillRect(B,z,Bt-t,.35*zt),o.fillStyle="rgba(0,0,0,.25)",o.fillRect(B,z+.65*zt,Bt-t,.35*zt-t))}}}if(h.ctx.globalAlpha=1,p){const t=p.finish();t&&h.ctx.drawImage(t,0,0)}(C.color.amount||C.lights.length)&&(oe(d.canvas,yt,Rt),d.ctx.clearRect(0,0,yt,Rt),d.ctx.drawImage(h.canvas,0,0)),C.color.amount&&(h.ctx.save(),h.ctx.globalCompositeOperation=C.color.blend,h.ctx.globalAlpha=C.color.amount,h.ctx.fillStyle=C.color.tint,h.ctx.fillRect(0,0,yt,Rt),h.ctx.restore());for(const t of C.lights){const e=t.radius*Math.max(yt,Rt),i=h.ctx.createRadialGradient(t.x*yt,t.y*Rt,0,t.x*yt,t.y*Rt,e);i.addColorStop(0,t.color),i.addColorStop(1,"transparent"),h.ctx.save(),h.ctx.globalCompositeOperation="screen",h.ctx.globalAlpha=t.intensity,h.ctx.fillStyle=i,h.ctx.fillRect(0,0,yt,Rt),h.ctx.restore()}(C.color.amount||C.lights.length)&&(h.ctx.globalCompositeOperation="destination-in",h.ctx.drawImage(d.canvas,0,0),h.ctx.globalCompositeOperation="source-over"),C.mask.enabled&&C.mask.shapes.length&&(de(c.ctx,yt,Rt,C.mask.shapes),h.ctx.globalCompositeOperation=C.mask.invert?"destination-out":"destination-in",h.ctx.drawImage(c.canvas,0,0),h.ctx.globalCompositeOperation="source-over");const g=l.ctx;g.clearRect(0,0,yt,Rt),g.globalAlpha=C.backdrop.opacity;const v=C.backdrop;if("solid"===v.mode&&(g.fillStyle=v.color,g.fillRect(0,0,yt,Rt)),"gradient"===v.mode){const t=g.createLinearGradient(0,0,yt,Rt);t.addColorStop(0,v.color),t.addColorStop(1,v.color2),g.fillStyle=t,g.fillRect(0,0,yt,Rt)}if("source"===v.mode&&g.drawImage(n.canvas,0,0),"blurred"===v.mode){const t=Math.max(1,v.blur);oe(m.canvas,Math.max(2,Math.round(yt/t)),Math.max(2,Math.round(Rt/t))),m.ctx.drawImage(n.canvas,0,0,m.canvas.width,m.canvas.height),g.imageSmoothingEnabled=!0,g.drawImage(m.canvas,0,0,yt,Rt)}g.globalAlpha=1,C.effects.characterBloom>0&&(oe(M.canvas,Math.max(2,Math.round(yt/3)),Math.max(2,Math.round(Rt/3))),M.ctx.clearRect(0,0,M.canvas.width,M.canvas.height),M.ctx.drawImage(h.canvas,0,0,M.canvas.width,M.canvas.height),g.save(),g.globalAlpha=.8*C.effects.characterBloom,g.globalCompositeOperation="screen",g.filter=`blur(${1+4*C.effects.characterBloom}px)`,g.drawImage(M.canvas,0,0,yt,Rt),g.restore());const R=Z.spotlight;if(R&&R[2]>.002){oe(at.canvas,yt,Rt);const t=at.ctx,e=R[3]*Math.min(yt,Rt)*1.6;t.globalCompositeOperation="source-over",t.clearRect(0,0,yt,Rt),t.drawImage(n.canvas,0,0),t.globalCompositeOperation="destination-in";const i=t.createRadialGradient(R[0]*yt,R[1]*Rt,0,R[0]*yt,R[1]*Rt,e),a=Math.min(1,R[2]*C.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,yt,Rt),_&&"all"!==(C.hover.scope??"all")&&(t.imageSmoothingEnabled=!0,t.drawImage(it.canvas,0,0,yt,Rt)),t.globalCompositeOperation="source-over",g.drawImage(at.canvas,0,0)}g.drawImage(h.canvas,0,0),L=Gt?Vt:""}var Qt;const Zt=Object.entries(C.effects).some(([t,e])=>!["angle","focus","blurType","characterBloom"].includes(t)&&"number"==typeof e&&e>0);r.clearRect(0,0,yt,Rt),Zt?(void 0===v&&(v=function(t=()=>document.createElement("canvas")){const e=t(),i=e.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,antialias:!1,preserveDrawingBuffer:!0});if(!i)return null;const a=[],s=(t,e)=>{const s=i.createShader(t);if(a.push(s),i.shaderSource(s,e),i.compileShader(s),!i.getShaderParameter(s,i.COMPILE_STATUS))throw new Error(i.getShaderInfoLog(s)||"Finish shader failed");return s},r=i.createProgram();if(i.attachShader(r,s(i.VERTEX_SHADER,"attribute vec2 p;varying vec2 uv;void main(){uv=(p+1.)*.5;gl_Position=vec4(p,0.,1.);}")),i.attachShader(r,s(i.FRAGMENT_SHADER,"precision mediump float;varying vec2 uv;uniform sampler2D src;uniform vec2 size;uniform float t,bloom,grain,dust,scanlines,crt,prism,vignette,glitch,pixelate,blur,blurMode,angle,focus,halftone,rgbSplit,sharpen;\n float hash(vec2 p){return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453);}\n vec4 sampleAt(vec2 p){if(min(min(p.x,p.y),min(1.-p.x,1.-p.y))<0.)return vec4(0.);return texture2D(src,vec2(p.x,1.-p.y));}\n void main(){vec2 q=uv,c=q-.5;q=c*(1.+dot(c,c)*crt*.25)+.5;\n if(glitch>0.)q.x+=(hash(vec2(floor(q.y*35.),floor(t*5.)))-.5)*.07*glitch*step(.82,hash(vec2(floor(q.y*35.),floor(t*5.)+3.)));\n if(pixelate>0.){vec2 grid=size/(1.+pixelate*20.);q=(floor(q*grid)+.5)/grid;}\n vec4 base=sampleAt(q);float edge=smoothstep(.12,.65,length(c));\n vec2 shift=vec2((prism*3.*edge+rgbSplit*8.)/size.x,prism*edge/size.y);\n if(prism>0.||rgbSplit>0.)base.rgb=vec3(sampleAt(q+shift).r,base.g,sampleAt(q-shift).b);\n vec2 dir=vec2(cos(angle),sin(angle))/size;float amount=blur;\n if(blurMode>1.5&&blurMode<2.5){dir=normalize(c+vec2(.0001))/size;amount*=length(c)*2.;}\n if(blurMode>2.5)amount*=smoothstep(.05,.5,abs(q.y-focus));\n vec4 blurred=base;\n if(amount>0.){blurred=base*.2;for(int i=1;i<=4;i++){float f=float(i)*amount*.35;vec2 off=dir*f;if(blurMode<.5)off=vec2(cos(float(i)*1.57),sin(float(i)*1.57))*amount/size;blurred+=sampleAt(q+off)*.1+sampleAt(q-off)*.1;}}\n vec3 light=vec3(0.);\n // Bloom: a wide golden-angle disc of soft-kneed highlights, screened on, so light spills like halation instead of ghosting glyphs.\n if(bloom>0.){float total=0.;for(int i=0;i<16;i++){float f=float(i);vec2 o=vec2(cos(f*2.39996),sin(f*2.39996))*(2.+f*1.6)/size;vec3 s=sampleAt(q+o).rgb;float w=1./(1.+f*.18);light+=s*smoothstep(.35,.9,max(s.r,max(s.g,s.b)))*w;total+=w;}light*=bloom*3.2/total;}\n vec3 col=1.-(1.-blurred.rgb)*(1.-min(light,vec3(1.)));\n if(sharpen>0.){vec2 px=1./size;vec3 near=sampleAt(q+vec2(px.x,0.)).rgb+sampleAt(q-vec2(px.x,0.)).rgb+sampleAt(q+vec2(0.,px.y)).rgb+sampleAt(q-vec2(0.,px.y)).rgb;col+=(base.rgb*4.-near)*sharpen*.5;}\ncol*=1.-scanlines*.4*(.5+.5*cos(q.y*size.y*3.14159));\n col*=1.-vignette*smoothstep(.15,.72,length(c));\n // Film grain: soft triangular noise, strongest in the midtones, quiet in deep shadow and paper-white highlights.\n float luma=dot(col,vec3(.299,.587,.114));vec2 g=floor(q*size/1.25)+floor(t*24.)*vec2(7.,13.);\n col+=(hash(g)+hash(g+31.7)-1.)*grain*.17*(.2+3.2*luma*(1.-luma));\n if(dust>0.)col+=step(1.-dust*.002,hash(floor(q*size*.25)+floor(t*2.)))*.4;\n if(halftone>0.)col*=mix(1.,smoothstep(.1,.65,length(fract(q*size/6.)-.5)),halftone);\n gl_FragColor=vec4(clamp(col,0.,1.),blurred.a);}")),i.linkProgram(r),!i.getProgramParameter(r,i.LINK_STATUS))throw new Error("Finish link failed");i.useProgram(r);const n=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,n),i.bufferData(i.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),i.STATIC_DRAW);const o=i.getAttribLocation(r,"p");i.enableVertexAttribArray(o),i.vertexAttribPointer(o,2,i.FLOAT,!1,0,0);const h=i.createTexture();i.bindTexture(i.TEXTURE_2D,h),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE);const l=["t","bloom","grain","dust","scanlines","crt","prism","rgbSplit","sharpen","vignette","glitch","pixelate","blur","blurMode","angle","focus","halftone"],c=Object.fromEntries(l.map(t=>[t,i.getUniformLocation(r,t)])),m=i.getUniformLocation(r,"size");return{canvas:e,render(t,a,s,n=1){e.width===t.width&&e.height===t.height||(e.width=t.width,e.height=t.height,i.viewport(0,0,e.width,e.height)),i.useProgram(r),i.bindTexture(i.TEXTURE_2D,h),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t),i.uniform2f(m,e.width/n,e.height/n);for(const t of l)i.uniform1f(c[t],"t"===t?s:"blurMode"===t?["gaussian","directional","radial","progressive"].indexOf(a.blurType):"angle"===t?a.angle*Math.PI/180:a[t]??0);return i.drawArrays(i.TRIANGLE_STRIP,0,4),e},destroy(){i.deleteTexture(h),i.deleteBuffer(n),i.deleteProgram(r),a.forEach(t=>i.deleteShader(t)),e.width=e.height=1,i.getExtension("WEBGL_lose_context")?.loseContext()}}}(a.finishCanvas)),v?r.drawImage(v.render(l.canvas,C.effects,i,Et),0,0):r.drawImage(l.canvas,0,0),a.finished(v?"gpu":"unavailable")):(r.drawImage(l.canvas,0,0),a.finished("none"))}const Dt={canvas:t,render:Pt,setPixelRatio(t){Et=Math.max(.1,Math.min(8,Number.isFinite(t)?t:1))},get pixelRatio(){return Et},setBudget(t){kt=Math.max(256,Math.min(yt,Number.isFinite(t)?Math.round(t):yt))},get maxCells(){return kt},configure(t){C=tt(t),ut=ot(C.color),ft=gt(C.print),dt.configure(C.color.denoise),pt.configure(C.warps,C.warpEdge),N++},pointer:Rt,leave(){Z.leave()},get active(){return Z.active},get settings(){return tt(C)},get capabilities(){return{gpuFinish:null!==v}},invalidate(){O=""},destroy(){v?.destroy(),y?.destroy(),y=void 0,pt.clear(),dt.configure(0);for(const t of[n,o,h,l,c,m,u,d,M,x,et,it,at])t.canvas.width=t.canvas.height=1;J=null,q=new Uint8ClampedArray(0),z=new Uint8ClampedArray(0),j=null,W=""}};return pe.set(Dt,Tt),Dt}(t,e,i,(t=>({surface:ne,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 ye(t,e,i){return new Promise((a,s)=>{const r=()=>{l(),a()},n=()=>{l(),s(new Error("Unable to load this media. Check its format and cross-origin permissions."))},o=()=>{l(),s(new DOMException("Cancelled","AbortError"))},h=setTimeout(n,2e4),l=()=>{clearTimeout(h),t.removeEventListener(e,r),t.removeEventListener("error",n),i?.removeEventListener("abort",o)};t.addEventListener(e,r,{once:!0}),t.addEventListener("error",n,{once:!0}),i?.addEventListener("abort",o,{once:!0}),i?.aborted&&o()})}async function be(t,e){if("string"==typeof t&&t.startsWith("blob:")){const i=await fetch(t,{signal:e}),a=await i.blob();return be(new File([a],"Imported media",{type:a.type}),e)}const i="string"!=typeof t,a=i?t.name:t;if(i?"image/gif"===t.type:/\.gif(?:[?#]|$)/i.test(a)){const a=await import("gifuct-js"),{parseGIF:s,decompressFrames:r}="function"==typeof a.parseGIF?a:a.default,n=i?await t.arrayBuffer():await fetch(t,{signal:e}).then(t=>{if(!t.ok)throw new Error("GIF download failed.");return t.arrayBuffer()});if(e?.aborted)throw new DOMException("Cancelled","AbortError");const o=s(n),h=o.lsd.width,l=o.lsd.height;if(h*l>4e6)throw new Error("GIF is too large. Use a smaller GIF or an MP4.");const c=o.frames.filter(t=>"image"in t).length;if(!c||c*h*l*4>128e6)throw new Error("GIF exceeds the decoded memory budget. Use MP4 for long animations.");const m=r(o,!0);if(m.length*h*l*4>128e6)throw new Error("GIF exceeds the 128 MB decoded budget. Use MP4 for long animations.");const u=document.createElement("canvas");u.width=h,u.height=l;const f=u.getContext("2d"),d=document.createElement("canvas"),p=d.getContext("2d"),g=m.reduce((t,e)=>t+Math.max(20,e.delay),0)/1e3;let M=-1,x=null;const v=t=>{const e=(t%g+g)%g*1e3;let i=0,a=0;for(;a<m.length-1&&(i+=Math.max(20,m[a].delay),!(e<i));a++);a<M&&(f.clearRect(0,0,h,l),M=-1,x=null);for(let t=M+1;t<=a;t++){const e=m[t-1];2===e?.disposalType&&f.clearRect(e.dims.left,e.dims.top,e.dims.width,e.dims.height),3===e?.disposalType&&x&&f.putImageData(x,0,0);const i=m[t];x=3===i.disposalType?f.getImageData(0,0,h,l):null,d.width=i.dims.width,d.height=i.dims.height,p.putImageData(new ImageData(new Uint8ClampedArray(i.patch),d.width,d.height),0,0),f.drawImage(d,i.dims.left,i.dims.top)}return M=a,u};return v(0),{source:u,width:h,height:l,duration:g,animated:!0,seek:async()=>{},frame:v,destroy(){u.width=d.width=1,m.length=0,x=null}}}const s=i?t.type.startsWith("video/"):/\.(mp4|webm|mov)(?:[?#]|$)/i.test(a),r=i?URL.createObjectURL(t):t,n=s?document.createElement("video"):new Image;n.crossOrigin="anonymous",n instanceof HTMLVideoElement&&(n.muted=!0,n.playsInline=!0,n.preload="auto");const o=()=>{n instanceof HTMLVideoElement?(n.pause(),n.removeAttribute("src"),n.load()):n.src="",i&&URL.revokeObjectURL(r)};try{const t=ye(n,s?"loadeddata":"load",e);n.src=r,await t;const i=n instanceof HTMLVideoElement?n.videoWidth:n.naturalWidth,a=n instanceof HTMLVideoElement?n.videoHeight:n.naturalHeight;return{source:n,width:i,height:a,duration:n instanceof HTMLVideoElement?n.duration:0,animated:s,async seek(t,e){if(!(n instanceof HTMLVideoElement))return;if(!Number.isFinite(n.duration)||n.duration<=0)throw new Error("Video duration is unavailable.");const i=Math.max(0,Math.min(n.duration-.001,t%n.duration));if(Math.abs(n.currentTime-i)<.001&&n.readyState>=2)return;const a=ye(n,"seeked",e);n.currentTime=i,await a},frame:()=>n,destroy:o}}catch(t){throw o(),t}}var we=t=>{if(t?.aborted)throw new DOMException("Export cancelled","AbortError")};async function ke(t,e){const{format:i,signal:a}=e,s=Math.round(e.width),r=Math.round(e.height);if(!Number.isFinite(s)||!Number.isFinite(r)||s<2||r<2||s>4096||r>4096||s*r>16777216)throw new Error("Choose export dimensions between 2 and 4096 pixels.");if(!["png","jpeg","mp4","webm","gif"].includes(i))throw new Error("Unknown export format.");if(void 0!==e.fps&&!Number.isFinite(e.fps))throw new Error("Frames per second must be finite.");const n=Math.max(1,Math.min(60,Math.round(e.fps??24))),o=e.duration??5;if(!Number.isFinite(o)||o<=0||o>60)throw new Error("Choose a duration from 0 to 60 seconds.");const h="png"===i||"jpeg"===i,l=e.time??0;if(!Number.isFinite(l)||l<0)throw new Error("Image time must be a finite non-negative number.");if(void 0!==e.motionTime&&(!Number.isFinite(e.motionTime)||e.motionTime<0))throw new Error("Motion time must be a finite non-negative number.");if(!h&&s*r>8294400)throw new Error("Video exports support up to 3840 × 2160 pixels.");if("gif"===i&&(s*r>921600||o*n>600))throw new Error("GIF export supports up to 1280 × 720 and 600 frames. Use MP4 for larger exports.");if(void 0!==e.referenceWidth&&(!Number.isFinite(e.referenceWidth)||e.referenceWidth<1))throw new Error("Reference width must be a positive number.");if("gif"===i&&n>30)throw new Error("GIF exports support up to 30 fps. Choose MP4 or WebM for higher frame rates.");const c=document.createElement("canvas");let m;try{if(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 n=await new Promise((t,a)=>c.toBlob(e=>e?t(e):a(new Error("Image export failed.")),"png"===i?"image/png":"image/jpeg",e.quality??.92));return we(a),e.onProgress?.(1),n}const u=Math.ceil(o*n);if("gif"===i){const i=await import("gifenc"),{GIFEncoder:h,quantize:l,applyPalette:m}="function"==typeof i.GIFEncoder?i:i.default,f=h(),d=c.getContext("2d");for(let i=0;i<u;i++){we(a);const h=i/n;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=d.getImageData(0,0,s,r).data,g=l(p,256),M=m(p,g);f.writeFrame(M,s,r,{palette:g,delay:10*(Math.round(100*Math.min((i+1)/n,o))-Math.round(100*i/n)),repeat:0}),e.onProgress?.((i+1)/u*.98),await new Promise(t=>setTimeout(t,0))}return we(a),f.finish(),e.onProgress?.(1),new Blob([new Uint8Array(f.bytes())],{type:"image/gif"})}const{Output:f,Mp4OutputFormat:d,WebMOutputFormat:p,BufferTarget:g,CanvasSource:M,canEncodeVideo:x}=await import("mediabunny"),v="mp4"===i?"avc":"vp9";if(!await x(v,{width:s,height:r}))throw new Error(`${i.toUpperCase()} encoding is unavailable in this browser. Try another format or a current browser with WebCodecs.`);const y=new f({format:"mp4"===i?new d({fastStart:"in-memory"}):new p,target:new g});c.width=s,c.height=r,m=()=>y.cancel();const b=new M(c,{codec:v,bitrate:Math.max(5e5,Math.round(s*r*n*.15))});y.addVideoTrack(b,{frameRate:n}),c.width=s,c.height=r,await y.start();for(let i=0;i<u;i++){we(a);const h=i/n;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 b.add(h,Math.min(1/n,o-h)),e.onProgress?.((i+1)/u*.98),i%4==0&&await new Promise(t=>setTimeout(t,0))}return b.close(),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}}var Ae=null,Se=()=>Ae??(Ae=Promise.resolve().then(()=>(n(),r)).then(({default:t})=>t?URL.createObjectURL(new Blob([t],{type:"text/javascript"})):null,()=>null)),Fe=null;function Ee(){if(null!==Fe)return Fe;try{Fe="function"==typeof Worker&&"function"==typeof OffscreenCanvas&&"function"==typeof createImageBitmap&&"transferToImageBitmap"in OffscreenCanvas.prototype&&!!new OffscreenCanvas(1,1).getContext("2d")}catch{Fe=!1}return Fe}var Re=new WeakSet;function Pe(t,e,i,a,s={width:960,height:540}){let r=null;const n=ge(i.maxDimension),[o,h]=Me(n,Math.max(2,s.width),Math.max(2,s.height)),l=navigator.hardwareConcurrency??2,c=t=>Math.max(1,Math.min(l>=8?3:l>=4?2:1,Math.floor(6e6/t))),m=c(o*h);let u=o*h;const f=[],d=[];let p=m>Math.min(2,m)?[]:null;const g=Math.max(256,Math.min(1048576,Number.isFinite(i.maxCells)?i.maxCells:12e3));let M=g,x=Math.max(.1,Math.min(8,i.pixelRatio??1));const v=()=>2*f.length;let y,b=!1,w=!1,k=0,A=null,S=!1,F=!1,E="none",R=JSON.stringify(tt(e).crop),P=null,T=null,I="",C=!0,D=new WeakMap,N=0,O=[],U=null;const L=t=>{if(!b){for(const e of f)e.post(t);if(p?.push({message:t}),p&&p.length>4096){for(const{spares:t}of p)t?.forEach(t=>t.close());p=null}}},q=t=>{w?a.error(new Error(t)):(W(),a.unavailable())};let X=[];const B=()=>{let t=!1;for(;O.length&&void 0!==O[0].reply;){const e=O.shift();e.reply&&(X.push(e),t=!0)}for(;X.length>2;)X.shift().reply.bitmap.close();t&&a.ready()},z=t=>{const e=t.worker=new Worker(r);e.onmessage=t=>{const e=t.data;if(b)return void("frame"===e.type&&e.bitmap.close());if("ready"===e.type)return;"error"===e.type&&q(e.message);const i=O.find(t=>t.seq===e.seq);i?(i.reply="frame"===e.type?e:null,"frame"===e.type&&p&&d.push(e.cost)>=3&&function(t){const e=p;p=null;const i=Math.min(m,c(u),Math.max(f.length,Math.ceil(t/7)))-f.length;for(let t=0;t<i;t++){const i=Y();i.post(j);for(const{message:a,spares:s}of e)if("source"===a.type){const e=s[t];i.post({...a,scene:e},[e])}else i.post("render"===a.type?{...a,type:"advance"}:a)}for(const{spares:t}of e)t?.slice(Math.max(0,i)).forEach(t=>t.close())}(d.sort((t,e)=>t-e)[1]),B()):"frame"===e.type&&e.bitmap.close()},e.onerror=t=>{t.preventDefault?.(),q(t.message||"The Studio worker failed.")};for(const[i,a]of t.waiting)e.postMessage(i,a);t.waiting=[]},Y=()=>{const t={worker:null,waiting:[],post(e,i=[]){t.worker?t.worker.postMessage(e,i):t.waiting.push([e,i])}};return f.push(t),r&&z(t),t},j={type:"init",settings:e,limits:{maxDimension:i.maxDimension,maxCells:i.maxCells},pixelRatio:x,budget:M};for(let t=Math.min(2,m);t>0;t--)Y().post(j);Se().then(t=>{b||(t?(r=t,f.forEach(z)):q("The Studio worker could not load."))});function W(){if(!b){b=!0;for(const t of f)t.worker?.terminate();for(const{spares:t}of p??[])t?.forEach(t=>t.close());for(const t of f)for(const[,e]of t.waiting)for(const t of e)t.close?.();p=null;for(const t of[...O,...X])t.reply?.bitmap.close();O=[],X=[],P&&(P.width=P.height=1),P=T=null,D=new WeakMap}}return{get turns(){return f.length},get busy(){return O.length>=v()},get drawing(){return O.length>0||X.length>0},show:()=>{const e=X.shift();return!!e?.reply&&(S=e.reply.active||X.some(t=>t.reply.active),E=e.reply.finish,i=e.reply.bitmap,t.width!==i.width&&(t.width=i.width),t.height!==i.height&&(t.height=i.height),void 0===y&&(y=t.getContext("bitmaprenderer"),y||(U=t.getContext("2d"))),y?y.transferFromImageBitmap(i):(U?.clearRect(0,0,t.width,t.height),U?.drawImage(i,0,0),i.close()),t.dataset.studioFinish=E,w=!0,a.frame(e.time,e.reply.cost),!0);var i},render(t,e,i,a,s,r){if(b||O.length>=v())return!1;const[o,h]=re(t);if(!o||!h)return!1;const[l,d]=Me(n,i,a);for(u=l*d;f.length>c(u);){const t=f.pop();t.worker?.terminate();for(const[,e]of t.waiting)for(const t of e)t.close?.();for(const e of O)e.lane===t&&void 0===e.reply&&(e.reply=null);B()}const g=++k,M=f[g%f.length];O.push({seq:g,time:e,input:F,lane:M}),F=!1;const x=(t=>{let e=D.get(t);return void 0===e&&D.set(t,e=++N),e})(t),y=()=>{if(!b){for(const t of f)t.post({type:t===M?"render":"advance",seq:g,time:e,width:i,height:a,motionTime:s});p?.push({message:{type:"advance",seq:g,time:e,width:i,height:a,motionTime:s}})}},w=[x,r.video?r.time:0,l,d,R].join(":");if(!C&&w===I)return A?A.then(y):y(),!0;C=!1,I=w;const S=()=>{if(b)throw new DOMException("Cancelled","AbortError");return P||(P=document.createElement("canvas"),T=P.getContext("2d")),P.width!==l&&(P.width=l),P.height!==d&&(P.height=d),xe(T,t,l,d,JSON.parse(R)),Promise.all(Array.from({length:f.length+(p?m-f.length:0)},()=>createImageBitmap(P)))},E=t instanceof HTMLImageElement&&!Re.has(t)?t.decode().catch(()=>{}).then(()=>{Re.add(t)}):null,U=(A??Promise.resolve()).then(()=>E?E.then(S):S()).then(t=>{if(b){for(const e of t)e.close();return}const e={type:"source",scene:t[0],width:o,height:h,video:r.video,time:r.time,key:x};f.forEach((i,a)=>i.post({...e,scene:t[a]},[t[a]])),p?p.push({message:e,spares:t.slice(f.length)}):t.slice(f.length).forEach(t=>t.close()),y()},t=>{const e=O.find(t=>t.seq===g);e&&(e.reply=null,B()),C=!0,b||q(t instanceof Error?t.message:String(t))});return A=U,U.then(()=>{A===U&&(A=null)}),!0},pointer(t,e,i){F=!0,L({type:"pointer",x:t,y:e,time:i})},leave(){F=!0,L({type:"leave"})},configure(t){R=JSON.stringify(tt(t).crop),L({type:"configure",settings:t})},setBudget(t){M=Math.max(256,Math.min(g,Number.isFinite(t)?Math.round(t):g)),L({type:"budget",cells:t})},get maxCells(){return M},setPixelRatio(t){x=Math.max(.1,Math.min(8,Number.isFinite(t)?t:1)),L({type:"ratio",ratio:t})},get pixelRatio(){return x},get active(){return S||F||O.some(t=>t.input)||X.some(t=>t.input||t.reply.active)},get capabilities(){return{gpuFinish:"unavailable"!==E}},invalidate(){C=!0,L({type:"invalidate"})},destroy:W}}function Te(t,e,i={}){let a,s=tt(i.settings),r=i.width??e.width,n=i.height??e.height,o=null;const h=()=>ve(t,s,i);if(Ee())try{a=o=Pe(t,s,i,{frame:function(t,r){if(m)return;i.onFrame?.(t,r),V(r/(o?.turns??1),D()&&(e.animated||yt(s))),y=a.active,b||y||u||o?.drawing?C():P()&&(u=!0,C())},ready:()=>C(),unavailable(){const t=a.maxCells,e=a.pixelRatio;o=null,a=h(),a.setBudget(t),a.setPixelRatio(e),u=!0,C()},error:K},{width:r,height:n})}catch{o=null,a=h()}else a=h();const l=new k;let c=0,m=!1,u=!0,f=!1,d=!0,p=0,g=0,M=0,x=0,v=-1,y=!1,b=!1,w=!1!==i.adaptive,A=0,S=0,F=0,E=0,R=a.maxCells;const P=()=>!(a.maxCells>=R)&&(a.setBudget(R),i.onQualityChange?.(a.maxCells),F=E=S=A=0,!0),T=matchMedia("(prefers-reduced-motion: reduce)"),I=e.source instanceof HTMLVideoElement?e.source:null,C=()=>{m||c||!d||document.hidden||(c=requestAnimationFrame(O))},D=()=>!f&&!T.matches&&d&&!document.hidden,N=()=>{I&&(I.loop=!0,D()?I.play().catch(()=>{f=!0,u=!0,C()}):I.pause()),M=0,u=!0,C()};function O(t){if(c=0,m||!d||document.hidden)return;o?.show()&&o.drawing&&C();const h=D();h&&(p+=M?Math.min(.1,(t-M)/1e3):0),M=t;const f=yt(s),w=h&&(e.animated||f),k=I?.getVideoPlaybackQuality?.().totalVideoFrames??-1,A=!I||k<0||k!==v,F=1e3/Math.max(1,Math.min(60,i.fps??60))-.5,E=u||(a.active?o||t-x>=Math.max(F,2*S):y)||w&&(A||f)&&t-x>=F;if(o&&function(t){const e=t-U;if(U=t,L++,e<3||e>100)return;q+=e,8===++X&&(Y=Math.min(Y,q/8),q=X=0);if(B+=e,++z<30)return;const i=B/z;B=z=0,i>1.25*Y?(G&&(H=Math.min(64,2*H)),j=Math.min(4,j+1),W=H,G=!1):j>1&&i<1.1*Y&&--W<=0?(j--,G=!0):G&&(G=!1,H=Math.max(1,H/2))}(t),E&&o&&!u&&L%j)b=!0;else if(E&&o)if(o.busy)b=!0;else{e.animated&&!I&&o.invalidate();const[i,a]=it(r,n,s);g=l.update(p,s.motion.type,s.motion.speed);const h=I?.currentTime??p;(o.render(e.frame(h),h,i,a,g,{video:!!I,time:k})||u)&&(u=!1,x=t,b=!1,v=k)}else if(E){const o=performance.now();try{e.animated&&!I&&a.invalidate();const[t,h]=it(r,n,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()-o;i.onFrame?.(I?.currentTime??p,c),V(c,w)}catch(t){K(t)}u=!1,x=t,y=a.active,v=k}h&&(w||a.active||b)?C():w||a.active||o?.drawing||!P()||(u=!0,C())}let U=0,L=0,q=0,X=0,B=0,z=0,Y=1/0,j=1,W=0,H=1,G=!1;function V(t,e){if(S=S?.9*S+.1*t:t,++A>20&&w&&(e||a.active)){const t=1e3/Math.max(1,Math.min(60,i.fps??60));F=S>1.1*t?F+1:0,E=S<.5*t?E+1:0,F>=20&&a.maxCells>3e3?(a.setBudget(Math.max(3e3,.8*a.maxCells)),i.onQualityChange?.(a.maxCells),F=0,S=0):E>=30&&a.maxCells<R&&(a.setBudget(Math.min(R,1.25*a.maxCells)),i.onQualityChange?.(a.maxCells),E=0,S=0)}}function K(t){f=!0,i.onError?.(t instanceof Error?t:new Error(String(t)))}const J=e=>{if(!D())return;const i=t.getBoundingClientRect();a.pointer((e.clientX-i.left)/i.width,(e.clientY-i.top)/i.height,e.timeStamp),C()},Q=()=>{a.leave(),C()},Z=t=>{"touch"===t.pointerType&&Q()},_=new IntersectionObserver(([t])=>{d=t.isIntersecting,N()});_.observe(t),t.addEventListener("pointermove",J),t.addEventListener("pointerup",Z),t.addEventListener("pointerleave",Q),t.addEventListener("pointercancel",Q),document.addEventListener("visibilitychange",N),T.addEventListener("change",N);const $=()=>{m||(m=!0,cancelAnimationFrame(c),_.disconnect(),t.removeEventListener("pointermove",J),t.removeEventListener("pointerup",Z),t.removeEventListener("pointerleave",Q),t.removeEventListener("pointercancel",Q),document.removeEventListener("visibilitychange",N),T.removeEventListener("change",N),i.signal?.removeEventListener("abort",$),a.destroy(),e.destroy())};if(i.signal?.addEventListener("abort",$,{once:!0}),i.signal?.aborted)throw $(),new DOMException("Cancelled","AbortError");return N(),{canvas:t,media:e,update(t){s=at(s,t),a.configure(s),u=!0,C()},resize(t,e,i){void 0!==i&&a.setPixelRatio(i),r=Math.max(2,t),n=Math.max(2,e),u=!0,C()},pause(t=!0){f=t,N()},async seek(t){p=Math.max(0,t),await e.seek(p),a.invalidate(),u=!0,C()},redraw(){a.invalidate(),u=!0,C()},get time(){return I?.currentTime??p},get settings(){return tt(s)},get motionTime(){return g},get paused(){return f||T.matches},setAdaptive(t){w=t,A=F=S=0},setBudget(t){a.setBudget(t),R=a.maxCells,F=E=S=A=0,i.onQualityChange?.(a.maxCells),u=!0,C()},get pixelRatio(){return a.pixelRatio},get maxCells(){return a.maxCells},get capabilities(){return a.capabilities},destroy:$}}var Ie={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")},Ce=Object.keys(Ie);async function De(t,e="Standard",i="#ffffff",a="#080808"){if(!Object.prototype.hasOwnProperty.call(Ie,e))throw new Error("Unknown text font.");const{default:s}=await import("figlet/browser"),r=await Ie[e]();s.parseFont(e,r.default),s.defaults({fetchFontIfMissing:!1});const n=s.textSync(t.slice(0,120),{font:e}),o=n.split("\n"),h=Math.max(1,...o.map(t=>t.length)),l=Math.max(1,o.length),c=Math.min(1,2048/(9*h)),m=document.createElement("canvas");m.width=Math.ceil(9*h*c+32),m.height=Math.ceil(15*l*c+32);const u=m.getContext("2d");return null!==a&&(u.fillStyle=a,u.fillRect(0,0,m.width,m.height)),u.fillStyle=i,u.font=15*c+"px monospace",u.textBaseline="top",o.forEach((t,e)=>u.fillText(t,16,16+15*e*c)),{canvas:m,ascii:n}}var Ne={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:" ⠁⠃⠇⡇⣇⣧⣷⣿"}},Oe=Ne,Ue=t=>t&&"object"==typeof t&&!Array.isArray(t)?t:{},Le=(t,e,i,a)=>"number"==typeof t&&Number.isFinite(t)?Math.max(i,Math.min(a,t)):e,qe=(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 Xe(t={}){const e=Ue(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(Le(e.width,1280,2,4096)),height:Math.round(Le(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=Ue(t),s=Ue(i.placement),r=Ue(i.settings),n=Ue(r.backdrop),o=qe(i.id,"Layer id"),h=qe(i.source,"Source key");if(a.has(o))throw new Error(`Duplicate layer id: ${o}`);return a.add(o),{id:o,source:h,name:"string"==typeof i.name?i.name.slice(0,80):`Layer ${e+1}`,visible:!1!==i.visible,opacity:Le(i.opacity,1,0,1),blend:V.includes(i.blend)?i.blend:"source-over",placement:{x:Le(s.x,.5,-1,2),y:Le(s.y,.5,-1,2),width:Le(s.width,1,.01,2),height:Le(s.height,1,.01,2),rotation:Le(s.rotation,0,-180,180),flipX:!0===s.flipX,flipY:!0===s.flipY},settings:tt({...r,backdrop:{mode:"transparent",...n}})}})}}function Be(t,e,i){if(!t.layers.some(t=>t.id===e))throw new Error(`Unknown layer: ${e}`);return Xe({...t,layers:t.layers.map(t=>t.id!==e?t:{...t,...i,id:e,placement:{...t.placement,...i.placement},settings:at(t.settings,i.settings??{})})})}function ze(t,e,i,a,s){const r=t.placement,n=r.rotation*Math.PI/180,o=Math.cos(n),h=Math.sin(n),l=(e-r.x)*a,c=(i-r.y)*s,m=(l*o+c*h)/(r.width*a),u=(-l*h+c*o)/(r.height*s);return[.5+m*(r.flipX?-1:1),.5+u*(r.flipY?-1:1)]}function Ye(t){return t.layers.filter(e=>{if(!e.visible||e.opacity<=0)return!1;const i=e.placement,a=i.rotation*Math.PI/180,s=Math.abs(Math.cos(a)),r=Math.abs(Math.sin(a)),n=(s*i.width*t.width+r*i.height*t.height)/2,o=(r*i.width*t.width+s*i.height*t.height)/2;return i.x*t.width+n>0&&i.x*t.width-n<t.width&&i.y*t.height+o>0&&i.y*t.height-o<t.height})}function je(t,e=24e3,i=4194304,a=t.width,s=t.height){const r=Ye(t),n=Math.round(Le(e,24e3,2048,1048576)),o=Le(i,4194304,65536,16777216),h=r.map(t=>t.placement.width*t.placement.height),l=h.reduce((t,e)=>t+e,0),c=n-256*r.length,m=r.map(t=>{const e=a*t.placement.width,i=s*t.placement.height,r=Math.min(1,4096/Math.max(e,i));return{width:Math.max(2,e*r),height:Math.max(2,i*r)}}),u=m.reduce((t,e)=>t+e.width*e.height,0);let f=0,d=0;return r.map((t,e)=>{const i=e===r.length-1?n-f:256+Math.floor(c*h[e]/l);f+=i;const a=m[e],s=e===r.length-1?o-d:4+Math.floor((o-4*r.length)*a.width*a.height/Math.max(1,u));d+=s;const p=Math.min(1,Math.sqrt(s/(a.width*a.height)));let g=Math.max(2,Math.floor(a.width*p)),M=Math.max(2,Math.floor(a.height*p));return g*M>s&&(g>=M?g=Math.max(2,Math.floor(s/M)):M=Math.max(2,Math.floor(s/g))),{id:t.id,maxCells:i,width:g,height:M}})}function We(t,e={},i={}){const a=t.getContext("2d");if(!a)throw new Error("Project canvas is already owned by another renderer.");let s=Xe(e),r=!0,n=!1,o=new Map(s.layers.map(t=>[t.id,JSON.stringify(t.settings)]));const h=Math.max(64,Math.min(4096,Number.isFinite(i.maxDimension)?i.maxDimension:960)),l=Math.max(2048,Math.min(1048576,Number.isFinite(i.maxCells)?i.maxCells:24e3));let c=l,m=Math.max(.1,Math.min(8,Number.isFinite(i.pixelRatio)?i.pixelRatio:1)),u=[];const f=new Map,d=()=>{if(n)throw new Error("Project renderer has been destroyed.")};return{canvas:t,render(e,n=0,p=s.width,g=s.height,M={}){if(d(),!Number.isFinite(p)||!Number.isFinite(g)||p<2||g<2)throw new Error("Project dimensions must be positive finite numbers.");const x=Math.min(1,h/Math.max(p,g)),v=Math.max(2,Math.round(p*x)),y=Math.max(2,Math.round(g*x));t.width===v&&t.height===y||(t.width=v,t.height=y,r=!0);const b={...s,width:v,height:y},w=Ye(b);for(const t of w)if(!e.has(t.source))throw new Error(`Missing project source: ${t.source}`);const k=new Set(w.map(t=>t.id));for(const[t,e]of f)k.has(t)||(e.renderer.destroy(),f.delete(t),r=!0);u=je(b,c,i.maxRasterPixels,v,y);for(let t=0;t<w.length;t++){const i=w[t],a=u[t],s=e.get(i.source);if(!s)throw new Error(`Missing project source: ${i.source}`);let h=f.get(i.id);const c=o.get(i.id);h?h.signature!==c&&(h.renderer.configure(i.settings),h.signature=c,h.dirty=!0):(h={renderer:ve(document.createElement("canvas"),i.settings,{maxDimension:4096,maxCells:l}),signature:c,dirty:!0,geometry:""},f.set(i.id,h));const d=m*a.width/(p*i.placement.width),g=`${a.width}:${a.height}:${a.maxCells}:${d}`;h.geometry!==g&&(h.renderer.setBudget(a.maxCells),h.renderer.setPixelRatio(d),h.geometry=g,h.dirty=!0);const x="currentTime"in s?s.getVideoPlaybackQuality?.().totalVideoFrames??s.currentTime:0;if(h.dirty||h.source!==s||h.stamp!==x||h.renderer.active||yt(i.settings)){const t=Object.prototype.hasOwnProperty.call(M,i.id)?M[i.id]:void 0;h.renderer.render(s,n,a.width,a.height,t),h.dirty=!1,h.source=s,h.stamp=x,r=!0}}if(!r)return!1;a.clearRect(0,0,v,y),a.globalCompositeOperation="source-over",a.globalAlpha=1,null!==s.background&&(a.fillStyle=s.background,a.fillRect(0,0,v,y));let A="none";for(const t of w){const e=f.get(t.id),i=t.placement;a.save(),a.globalAlpha=t.opacity,a.globalCompositeOperation=t.blend;try{a.translate(i.x*v,i.y*y),a.rotate(i.rotation*Math.PI/180),a.scale(i.flipX?-1:1,i.flipY?-1:1),a.drawImage(e.renderer.canvas,-i.width*v/2,-i.height*y/2,i.width*v,i.height*y)}finally{a.restore()}"unavailable"===e.renderer.canvas.dataset.studioFinish?A="unavailable":"unavailable"!==A&&"gpu"===e.renderer.canvas.dataset.studioFinish&&(A="gpu")}return a.globalAlpha=1,a.globalCompositeOperation="source-over",t.dataset.studioFinish=A,r=!1,!0},configure(t){d(),s=Xe(t),o=new Map(s.layers.map(t=>[t.id,JSON.stringify(t.settings)])),(()=>{const t=new Set(Ye(s).map(t=>t.id));for(const[e,i]of f)t.has(e)||(i.renderer.destroy(),f.delete(e))})(),r=!0},pointer(e,i,a){if(n||!Number.isFinite(e)||!Number.isFinite(i))return;if(e<0||e>1||i<0||i>1){for(const t of f.values())t.renderer.leave();return}let r=!1;for(const n of Ye({...s,width:t.width,height:t.height}).reverse()){const o=f.get(n.id);if(!o)continue;const[h,l]=ze(n,e,i,t.width,t.height);(!r||"all"===s.pointerMode)&&h>=0&&h<=1&&l>=0&&l<=1&&"none"!==n.settings.hover.effect&&n.settings.hover.strength>0?(o.renderer.pointer(h,l,a),r=!0):o.renderer.leave()}},leave(){for(const t of f.values())t.renderer.leave()},invalidate(t){d();for(const e of s.layers)if(void 0===t||t===e.source){const t=f.get(e.id);t&&(t.renderer.invalidate(),t.dirty=!0)}r=!0},setBudget(t){d(),c=Math.max(2048,Math.min(l,Number.isFinite(t)?Math.round(t):l)),r=!0},setPixelRatio(t){d(),m=Math.max(.1,Math.min(8,Number.isFinite(t)?t:1)),r=!0},get maxCells(){return c},get pixelRatio(){return m},get quality(){return u.map(t=>({...t}))},get active(){return[...f.values()].some(t=>t.renderer.active)},destroy(){if(!n){n=!0;for(const t of f.values())t.renderer.destroy();f.clear(),t.width=t.height=1}}}}function He(t,e){for(const i of t.layers)if(!e.has(i.source))throw new Error(`Missing project source: ${i.source}`)}async function Ge(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.");He(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 be(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 De(i.text,i.font,i.ink??"#ffffff",null);s.set(t,{source:a,width:a.width,height:a.height,duration:0,animated:!1,frame:()=>a,seek:async()=>{},destroy:()=>{a.width=a.height=1}})}}}if(i?.aborted)throw new DOMException("Cancelled","AbortError");return s}catch(t){for(const t of s.values())t.destroy();throw t}}function Ve(t,e,i,a={}){if((i=new Map(i)).size>8)throw new Error("A project supports up to 8 media bindings.");let s=Xe(e);if(He(s,i),a.signal?.aborted)throw new DOMException("Cancelled","AbortError");const r=We(t,s,a),n=matchMedia("(prefers-reduced-motion: reduce)"),o=[...new Set(i.values())],h=o.filter(t=>t.source instanceof HTMLVideoElement).map(t=>t.source),l=new Map;let c,m={},u=0,f=0,d=0,p=0,g=!0,M=!1,x=!0,v=!1,y=!1!==a.adaptive,b=0,w=0,A=0,S=0,F=s.width,E=s.height,R=0,P=!1,T=r.maxCells;const I=new WeakSet,C=Math.max(1,Math.min(60,Number.isFinite(a.fps)?a.fps:60)),D=()=>!v&&!M&&!P&&!n.matches&&x&&!document.hidden,N=()=>{v||p||!x||document.hidden||(p=requestAnimationFrame(q))},O=()=>new Set(Ye({...s,width:F,height:E}).map(t=>i.get(t.source).source)),U=()=>{const t=O();for(const e of h)e.loop=!0,D()&&t.has(e)?e.paused&&!I.has(e)&&(I.add(e),e.play().then(()=>{I.delete(e),D()&&O().has(e)||e.pause()}).catch(t=>{I.delete(e),v||(M=!0,U(),a.onError?.(t instanceof Error?t:new Error(String(t))),g=!0,N())})):e.pause()},L=()=>{f=0,g=!0,U(),N()};function q(t){if(p=0,v||!x||document.hidden)return;const e=D();e&&(u+=f?Math.min(.1,(t-f)/1e3):0),f=t;const n=Ye({...s,width:F,height:E}),o=n.some(t=>i.get(t.source).animated||yt(t.settings));if(g||e&&r.active||e&&o&&t-d>=1e3/C-.5){const s=performance.now();try{const t=new Map,h=new Set(n.map(t=>t.source));for(const a of h){const s=i.get(a);!s.animated||s.source instanceof HTMLVideoElement||!e||r.invalidate(a),t.set(a,s.frame(u))}m={};for(const t of n){let e=l.get(t.id);e||(e=new k,l.set(t.id,e)),m[t.id]=e.update(u,t.settings.motion.type,t.settings.motion.speed)}r.render(t,u,F,E,m);const c=performance.now()-s;if(a.onFrame?.(u,c),w=w?.9*w+.1*c:c,++b>20&&y&&e&&(o||r.active)){const t=1e3/C;A=w>1.1*t?A+1:0,S=w<.5*t?S+1:0,A>=20&&r.maxCells>2048?(r.setBudget(Math.max(2048,.8*r.maxCells)),a.onQualityChange?.(r.maxCells),w=A=0,g=!0):S>=30&&r.maxCells<T&&(r.setBudget(Math.min(T,1.25*r.maxCells)),a.onQualityChange?.(r.maxCells),w=S=0,g=!0)}}catch(t){M=!0,U(),a.onError?.(t instanceof Error?t:new Error(String(t)))}g=!1,d=t}e&&(o||r.active)?N():!o&&!r.active&&r.maxCells<T&&(r.setBudget(T),a.onQualityChange?.(r.maxCells),b=A=S=w=0,g=!0,N())}const X=e=>{if(!D())return;const i=t.getBoundingClientRect();i.width&&i.height&&(r.pointer((e.clientX-i.left)/i.width,(e.clientY-i.top)/i.height,e.timeStamp),N())},B=()=>{r.leave(),N()},z=new IntersectionObserver(([t])=>{x=t.isIntersecting,L()});z.observe(t),t.addEventListener("pointermove",X),t.addEventListener("pointerleave",B),t.addEventListener("pointercancel",B),document.addEventListener("visibilitychange",L),n.addEventListener("change",L);const Y=()=>{if(!v){v=!0,R++,c?.abort(),cancelAnimationFrame(p),p=0,z.disconnect(),t.removeEventListener("pointermove",X),t.removeEventListener("pointerleave",B),t.removeEventListener("pointercancel",B),document.removeEventListener("visibilitychange",L),n.removeEventListener("change",L),a.signal?.removeEventListener("abort",Y),r.destroy();for(const t of o)t.destroy();l.clear()}};a.signal?.addEventListener("abort",Y,{once:!0});const j=()=>{if(v)throw new Error("Project player has been destroyed.")},W=t=>{j();const e=Xe(t);He(e,i),F===s.width&&E===s.height&&(F=e.width,E=e.height),s=e,r.configure(s);for(const t of l.keys())s.layers.some(e=>e.id===t)||l.delete(t);L()};return L(),{canvas:t,get project(){return Xe(s)},get time(){return u},get motionTimes(){return{...m}},get paused(){return M||n.matches},get maxCells(){return r.maxCells},get pixelRatio(){return r.pixelRatio},get quality(){return r.quality},update:W,updateLayer:(t,e)=>W(Be(s,t,e)),resize(t,e,i){if(j(),!Number.isFinite(t)||!Number.isFinite(e)||t<2||e<2)throw new Error("Project dimensions must be positive finite numbers.");F=t,E=e,void 0!==i&&r.setPixelRatio(i),L()},pause(t=!0){j(),M=t,L()},async seek(t){if(j(),!Number.isFinite(t)||t<0)throw new Error("Project time must be finite and non-negative.");const e=++R;c?.abort(),c=new AbortController;const i=c.signal;P=!0,U();try{if(await Promise.all(o.map(e=>e.seek(t,i))),v||e!==R)return;u=t,l.clear(),r.invalidate()}finally{v||e!==R||(P=!1,L())}},redraw(){j(),r.invalidate(),g=!0,N()},setBudget(t){j(),r.setBudget(t),T=r.maxCells,b=A=S=w=0,a.onQualityChange?.(r.maxCells),g=!0,N()},setAdaptive(t){y=t,b=A=S=w=0},destroy:Y}}exports.BLEND_MODES=V,exports.CHARACTER_SETS=Ne,exports.DEFAULT_HOVER=c,exports.DEFAULT_STUDIO_PRINT=j,exports.DEFAULT_STUDIO_SETTINGS=J,exports.DEPRECATED_STUDIO_HOVERS=h,exports.DEPRECATED_STUDIO_MOTIONS=M,exports.DITHER_ALGORITHMS=G,exports.HOVER_CONTROLS=l,exports.HOVER_SCOPES=[{value:"all",label:"Everywhere",description:"The hover acts on the whole artwork."},{value:"subject",label:"Subject",description:"The hover stays on the subject and fades softly at its edge."},{value:"outside",label:"Around",description:"The hover acts only on the ground around the subject."}],exports.MAX_STUDIO_LAYERS=8,exports.MAX_STUDIO_WARPS=8,exports.STUDIO_ANIMATION_PRESETS=[{id:"quiet-light",label:"Quiet light",description:"A key light circles the subject’s own relief, with a soft magnifying wake.",motion:{type:"relight",speed:.6,amount:.8},hover:{effect:"lens",radius:.45,strength:.5}},{id:"living-paper",label:"Memory",description:"A slow push toward the subject; the image leans toward your cursor.",motion:{type:"push",speed:.5,amount:.8},hover:{effect:"tilt",radius:.5,strength:.45}},{id:"silver-grain",label:"Silver light",description:"Sparse glints on bright detail, with a fluid character trail.",motion:{type:"shimmer",speed:.6,amount:.9},hover:{effect:"trail",radius:.35,strength:.55}},{id:"ripple-study",label:"Still water",description:"Smooth water and sky drift like a cinemagraph; your stroke sends out rings.",motion:{type:"current",speed:.6,amount:.8},hover:{effect:"ripple",radius:.45,strength:.7}},{id:"unfolding-print",label:"Darkroom",description:"The print develops from its highlights; your cursor dissolves a soft path.",motion:{type:"develop",speed:.7,amount:1},hover:{effect:"dissolve",radius:.35,strength:.55}},{id:"silk-flow",label:"Morning mist",description:"Mist drifts through the distance; directional folds follow your hand.",motion:{type:"mist",speed:.6,amount:1},hover:{effect:"silk",radius:.4,strength:.5}},{id:"depth-study",label:"Depth study",description:"A slow parallax drift from the photo’s own depth, with a loupe under your cursor.",motion:{type:"parallax",speed:.6,amount:.9},hover:{effect:"loupe",radius:.35,strength:.55}}],exports.STUDIO_CHARACTER_SETS=Oe,exports.STUDIO_CURVE_CHANNELS=R,exports.STUDIO_HOVERS=o,exports.STUDIO_LOOKS=rt,exports.STUDIO_MOTIONS=x,exports.STUDIO_PALETTES=K,exports.STUDIO_PRINT_STYLES=[{value:"stipple",label:"Stipple",description:"Scattered ink dots shape the image through their size."},{value:"engraving",label:"Engraving",description:"Continuous parallel cuts change weight with the image."},{value:"crosshatch",label:"Crosshatch",description:"Crossing layers of fine lines build the tonal range."},{value:"woodblock",label:"Woodblock",description:"Broad carved bands with irregular edges and stepped tones."},{value:"risograph",label:"Risograph",description:"Two offset ink screens with adjustable registration."},{value:"pointillism",label:"Pointillism",description:"Small pigment strokes mix source colors into the image."}],exports.STUDIO_PRINT_STYLE_IDS=z,exports.STUDIO_STYLES=H,exports.STUDIO_TEXT_FONTS=Ce,exports.STUDIO_WARPS=O,exports.createStudioCurveLookup=C,exports.createStudioProjectRenderer=We,exports.createStudioRenderer=ve,exports.createStudioText=De,exports.exportStudio=async function(t,e,i){let a;const s=tt(e),r="png"!==i.format&&"jpeg"!==i.format;try{return await ke(async(e,n,o,h,l,c)=>{a??(a=ve(e,s,{maxDimension:4096,maxCells:i.maxCells??12e3,pixelRatio:o/(i.referenceWidth??Math.min(o,960))})),r&&a.invalidate(),a.render(await t.frame(n,l),n,o,h,c)},i)}finally{a?.destroy()}},exports.exportStudioProject=async function(t,e,i){const a=Xe(t),s={...i.motionTimes};if(Object.values(s).some(t=>!Number.isFinite(t)||t<0))throw new Error("Layer motion times must be finite non-negative numbers.");const r=Object.fromEntries(Object.entries(e).map(([t,e])=>[t,e&&"object"==typeof e&&"text"in e&&"string"==typeof e.text?{...e}:e]));let n,o;const h=new AbortController,l=()=>h.abort();i.signal?.aborted?l():i.signal?.addEventListener("abort",l,{once:!0});const c="png"===i.format||"jpeg"===i.format;try{return await ke(async(t,e,h,l,m)=>{o??(o=await Ge(a,r,m)),n??(n=We(t,a,{maxDimension:4096,maxCells:i.maxCells??24e3,maxRasterPixels:i.maxRasterPixels,pixelRatio:h/(i.referenceWidth??Math.min(h,960))}));const u=new Set(Ye({...a,width:h,height:l}).map(t=>t.source)),f=new Map;await Promise.all([...u].map(async t=>{const i=o.get(t);await i.seek(e,m),f.set(t,i.frame(e)),i.animated&&n.invalidate(t)})),n.render(f,e,h,l,c?s:{})},{...i,signal:h.signal})}finally{if(h.abort(),i.signal?.removeEventListener("abort",l),n?.destroy(),o)for(const t of new Set(o.values()))t.destroy()}},exports.inkIndexLookup=fe,exports.isStudioPrintStyle=Y,exports.loadStudioMedia=be,exports.mountStudio=async function(t,e,i={}){Ee()&&Se();const a=await be(e,i.signal);try{return Te(t,a,i)}catch(t){throw a.destroy(),t}},exports.mountStudioMedia=Te,exports.mountStudioProject=async function(t,e,i,a={}){const s=Xe(e),r=await Ge(s,i,a.signal);try{return Ve(t,s,r,a)}catch(t){for(const t of new Set(r.values()))t.destroy();throw t}},exports.mountStudioProjectMedia=Ve,exports.normalizeStudioCurve=T,exports.normalizeStudioCurves=I,exports.normalizeStudioPrint=W,exports.normalizeStudioProject=Xe,exports.normalizeStudioSettings=tt,exports.normalizeStudioWarps=L,exports.parseStudioProject=function(t){if(t.length>1e6)throw new Error("Project exceeds the 1 MB settings limit.");const e=JSON.parse(t);if("asciify-project"!==e?.kind||1!==e.version||!Array.isArray(e.layers))throw new Error("This is not an Asciify layered project.");return Xe(e)},exports.parseStudioSettings=function(t){if(t.length>1e5)throw new Error("Settings exceed 100 KB.");return tt(JSON.parse(t))},exports.resolveHover=m,exports.restyleStudio=function(t,e=Math.random){const i=rt.filter(e=>e.settings.style!==t.style||e.settings.ink!==t.ink),a=nt(i[Math.min(i.length-1,Math.max(0,Math.floor(e()*i.length)))].id);return a.aspectRatio=t.aspectRatio,a.crop={...t.crop},a.mask=tt(t).mask,a},exports.serializeStudioProject=t=>JSON.stringify(Xe(t)),exports.serializeStudioSettings=function(t){return JSON.stringify(tt(t))},exports.studioCrop=et,exports.studioDimensions=it,exports.studioGrid=st,exports.studioLayerPoint=ze,exports.studioLevels=me,exports.studioLook=nt,exports.studioProjectBudget=je,exports.studioSourceSize=re,exports.studioToneGamma=ue,exports.updateStudioProjectLayer=Be,exports.updateStudioSettings=at,exports.visibleStudioLayers=Ye;//# sourceMappingURL=studio.cjs.map