asciify-engine 4.23.0 → 4.24.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 (87) hide show
  1. package/README.md +7 -0
  2. package/dist/core.cjs +1 -1
  3. package/dist/core.js +1 -1
  4. package/dist/field.cjs +1 -1
  5. package/dist/field.js +1 -1
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/kit/chunk-2CF4PX6U.js +1 -0
  9. package/dist/kit/chunk-2NVKPXPL.js +1 -0
  10. package/dist/kit/chunk-3473NPIN.js +1 -0
  11. package/dist/kit/chunk-3A5LID2G.js +1 -0
  12. package/dist/kit/chunk-3PCKMO6I.js +1 -0
  13. package/dist/kit/chunk-4HWMQCAM.js +1 -0
  14. package/dist/kit/chunk-4OT66HSZ.js +1 -0
  15. package/dist/kit/chunk-4QHFEMFS.js +1 -0
  16. package/dist/kit/chunk-4ZQFDFEH.js +1 -0
  17. package/dist/kit/chunk-5BEBNKYM.js +1 -0
  18. package/dist/kit/chunk-5I4IZTL5.js +1 -0
  19. package/dist/kit/chunk-5QE6UMXN.js +1 -0
  20. package/dist/kit/chunk-5Z2EJAUV.js +1 -0
  21. package/dist/kit/chunk-73M2OESE.js +1 -0
  22. package/dist/kit/chunk-7ABNWOW4.js +1 -0
  23. package/dist/kit/chunk-AIM3J2US.js +1 -0
  24. package/dist/kit/chunk-BN7HL52Z.js +1 -0
  25. package/dist/kit/chunk-BNVRKD3V.js +1 -0
  26. package/dist/kit/chunk-BQZCLGCY.js +1 -0
  27. package/dist/kit/chunk-BR6ZNJZW.js +1 -0
  28. package/dist/kit/chunk-BTD6EFAW.js +1 -0
  29. package/dist/kit/chunk-C3C7AYKL.js +1 -0
  30. package/dist/kit/chunk-C4KZYCPF.js +1 -0
  31. package/dist/kit/chunk-DFOWXOZR.js +1 -0
  32. package/dist/kit/chunk-DZ5XGHTJ.js +1 -0
  33. package/dist/kit/chunk-E3TUOX2A.js +1 -0
  34. package/dist/kit/chunk-ENTDGT2V.js +1 -0
  35. package/dist/kit/chunk-FR3ZJNOY.js +1 -0
  36. package/dist/kit/chunk-FUI5AVIF.js +1 -0
  37. package/dist/kit/chunk-G57QACJG.js +1 -0
  38. package/dist/kit/chunk-H2UZBVKE.js +1 -0
  39. package/dist/kit/chunk-HTUGMGVA.js +1 -0
  40. package/dist/kit/chunk-I4QVLLRQ.js +1 -0
  41. package/dist/kit/chunk-IPVN22ZM.js +1 -0
  42. package/dist/kit/chunk-IQTGJRDX.js +1 -0
  43. package/dist/kit/chunk-IUKSHYED.js +1 -0
  44. package/dist/kit/chunk-J2YZBT3N.js +1 -0
  45. package/dist/kit/chunk-K563CCOL.js +1 -0
  46. package/dist/kit/chunk-KWTF6Q5W.js +1 -0
  47. package/dist/kit/chunk-MGVPLQ3Z.js +1 -0
  48. package/dist/kit/chunk-MIZ2DUHU.js +1 -0
  49. package/dist/kit/chunk-MQJQIDO5.js +1 -0
  50. package/dist/kit/chunk-NURPDP3Y.js +1 -0
  51. package/dist/kit/chunk-O7SGY4YJ.js +1 -0
  52. package/dist/kit/chunk-OWEZV7TQ.js +1 -0
  53. package/dist/kit/chunk-PCIAA2LL.js +1 -0
  54. package/dist/kit/chunk-PFKYKAIP.js +1 -0
  55. package/dist/kit/chunk-PIU2BMFU.js +1 -0
  56. package/dist/kit/chunk-QALCXKU6.js +1 -0
  57. package/dist/kit/chunk-QRCXXS5Z.js +1 -0
  58. package/dist/kit/chunk-RFLIFKZ4.js +1 -0
  59. package/dist/kit/chunk-ROR6MG3K.js +1 -0
  60. package/dist/kit/chunk-S62H7ZIU.js +1 -0
  61. package/dist/kit/chunk-S7RZP2MT.js +1 -0
  62. package/dist/kit/chunk-SARCZMLN.js +1 -0
  63. package/dist/kit/chunk-SNCXU7KF.js +1 -0
  64. package/dist/kit/chunk-T3GWGPST.js +1 -0
  65. package/dist/kit/chunk-TTGMK4EA.js +1 -0
  66. package/dist/kit/chunk-UML6XQAR.js +1 -0
  67. package/dist/kit/chunk-UO7RB7RC.js +1 -0
  68. package/dist/kit/chunk-VC2ZQG63.js +1 -0
  69. package/dist/kit/chunk-VVW7LZT2.js +1 -0
  70. package/dist/kit/chunk-W2STAN6V.js +1 -0
  71. package/dist/kit/chunk-WJLZM3DR.js +1 -0
  72. package/dist/kit/chunk-XANKANGR.js +1 -0
  73. package/dist/kit/chunk-XB4DKPGL.js +1 -0
  74. package/dist/kit/chunk-XDKKCIIL.js +1 -0
  75. package/dist/kit/chunk-XM56OTYT.js +1 -0
  76. package/dist/kit/chunk-XPXMCXYI.js +1 -0
  77. package/dist/kit/chunk-YBRP6BFW.js +1 -0
  78. package/dist/kit/chunk-YCWMOTYH.js +1 -0
  79. package/dist/kit/chunk-ZCHGV2CV.js +1 -0
  80. package/dist/kit/chunk-ZRJVOUWH.js +1 -0
  81. package/dist/kit.cjs +1 -1
  82. package/dist/kit.js +1 -1
  83. package/dist/studio.cjs +1 -1
  84. package/dist/studio.js +1 -1
  85. package/package.json +2 -2
  86. package/skills/asciify-engine/SKILL.md +3 -3
  87. package/skills/asciify-engine/references/performance.md +30 -0
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!==i.adaptive,y=0,w=0,b=0,k=0,S=o.maxCells;const A=matchMedia("(prefers-reduced-motion: reduce)"),E=e.source instanceof HTMLVideoElement?e.source:null,F=()=>{l||h||!m||document.hidden||(h=requestAnimationFrame(C))},T=()=>!d&&!A.matches&&m&&!document.hidden,P=()=>{E&&(E.loop=!0,T()?E.play().catch(()=>{d=!0,c=!0,F()}):E.pause()),p=0,c=!0,F()};function C(t){if(h=0,l||!m||document.hidden)return;const g=T();g&&(u+=p?Math.min(.1,(t-p)/1e3):0),p=t;const A=ut(a),P=g&&(e.animated||A),C=E?.getVideoPlaybackQuality?.().totalVideoFrames??-1,I=!E||C<0||C!==x;if(c||o.active||P&&(I||A)&&t-M>=1e3/Math.max(1,Math.min(60,i.fps??60))-.5){const h=performance.now();try{e.animated&&!E&&o.invalidate();const[t,l]=J(s,r,a);f=n.update(u,a.motion.type,a.motion.speed),o.render(e.frame(E?.currentTime??u),u,t,l,f);const c=performance.now()-h;if(i.onFrame?.(E?.currentTime??u,c),w=w?.9*w+.1*c:c,++y>20&&v&&(P||o.active)){const t=1e3/Math.max(1,Math.min(60,i.fps??60));b=w>1.1*t?b+1:0,k=w<.5*t?k+1:0,b>=20&&o.maxCells>3e3?(o.setBudget(Math.max(3e3,.8*o.maxCells)),i.onQualityChange?.(o.maxCells),b=0,w=0):k>=30&&o.maxCells<S&&(o.setBudget(Math.min(S,1.25*o.maxCells)),i.onQualityChange?.(o.maxCells),k=0,w=0)}}catch(t){d=!0,i.onError?.(t instanceof Error?t:new Error(String(t)))}c=!1,M=t,x=C}g&&(P||o.active)?F():P||o.active||o.maxCells>=S||(o.setBudget(S),i.onQualityChange?.(o.maxCells),b=k=w=y=0,0)||(c=!0,F())}const I=e=>{if(!T())return;const i=t.getBoundingClientRect();o.pointer((e.clientX-i.left)/i.width,(e.clientY-i.top)/i.height,e.timeStamp),F()},R=()=>{o.leave(),F()},O=t=>{"touch"===t.pointerType&&R()},L=new IntersectionObserver(([t])=>{m=t.isIntersecting,P()});L.observe(t),t.addEventListener("pointermove",I),t.addEventListener("pointerup",O),t.addEventListener("pointerleave",R),t.addEventListener("pointercancel",R),document.addEventListener("visibilitychange",P),A.addEventListener("change",P);const D=()=>{l||(l=!0,cancelAnimationFrame(h),L.disconnect(),t.removeEventListener("pointermove",I),t.removeEventListener("pointerup",O),t.removeEventListener("pointerleave",R),t.removeEventListener("pointercancel",R),document.removeEventListener("visibilitychange",P),A.removeEventListener("change",P),i.signal?.removeEventListener("abort",D),o.destroy(),e.destroy())};if(i.signal?.addEventListener("abort",D,{once:!0}),i.signal?.aborted)throw D(),new DOMException("Cancelled","AbortError");return P(),{canvas:t,media:e,update(t){a=K(a,t),o.configure(a),c=!0,F()},resize(t,e,i){void 0!==i&&o.setPixelRatio(i),s=Math.max(2,t),r=Math.max(2,e),c=!0,F()},pause(t=!0){d=t,P()},async seek(t){u=Math.max(0,t),await e.seek(u),o.invalidate(),c=!0,F()},redraw(){o.invalidate(),c=!0,F()},get time(){return E?.currentTime??u},get settings(){return V(a)},get motionTime(){return f},get paused(){return d||A.matches},setAdaptive(t){v=t,y=b=w=0},setBudget(t){o.setBudget(t),S=o.maxCells,b=k=w=y=0,i.onQualityChange?.(o.maxCells),c=!0,F()},get pixelRatio(){return o.pixelRatio},get maxCells(){return o.maxCells},get capabilities(){return o.capabilities},destroy:D}}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=[{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