asciify-engine 4.24.0 → 4.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/CHANGELOG.md +325 -0
  2. package/README.md +71 -718
  3. package/dist/core.cjs +1 -1
  4. package/dist/core.js +1 -1
  5. package/dist/field.cjs +1 -1
  6. package/dist/field.d.cts +132 -272
  7. package/dist/field.d.ts +132 -272
  8. package/dist/field.js +1 -1
  9. package/dist/glyph-field-C2fQIlnq.d.cts +292 -0
  10. package/dist/glyph-field-DRC-7uVf.d.ts +292 -0
  11. package/dist/hover.cjs +1 -1
  12. package/dist/hover.js +1 -1
  13. package/dist/index.cjs +1 -1
  14. package/dist/index.js +1 -1
  15. package/dist/kit/chunk-2FH6GGV6.js +1 -0
  16. package/dist/kit/chunk-2GAV4OAK.js +1 -0
  17. package/dist/kit/{chunk-C4KZYCPF.js → chunk-2LBQ7QJT.js} +1 -1
  18. package/dist/kit/{chunk-BN7HL52Z.js → chunk-3LJ5C3U3.js} +1 -1
  19. package/dist/kit/{chunk-NURPDP3Y.js → chunk-3MHEDZLZ.js} +1 -1
  20. package/dist/kit/{chunk-BR6ZNJZW.js → chunk-3OD5BMF5.js} +1 -1
  21. package/dist/kit/{chunk-C3C7AYKL.js → chunk-3VEMKDBW.js} +1 -1
  22. package/dist/kit/{chunk-PFKYKAIP.js → chunk-42KMN727.js} +1 -1
  23. package/dist/kit/{chunk-2CF4PX6U.js → chunk-6G5MPND3.js} +1 -1
  24. package/dist/kit/{chunk-QALCXKU6.js → chunk-6WU247CB.js} +1 -1
  25. package/dist/kit/{chunk-YBRP6BFW.js → chunk-776H2BJ7.js} +1 -1
  26. package/dist/kit/chunk-7DXSG526.js +1 -0
  27. package/dist/kit/{chunk-H2UZBVKE.js → chunk-7M2FFUZ3.js} +1 -1
  28. package/dist/kit/{chunk-5BEBNKYM.js → chunk-7NVKRDKE.js} +1 -1
  29. package/dist/kit/{chunk-XB4DKPGL.js → chunk-AIGAJMNN.js} +1 -1
  30. package/dist/kit/{chunk-O7SGY4YJ.js → chunk-B3TY6UXJ.js} +1 -1
  31. package/dist/kit/{chunk-XDKKCIIL.js → chunk-BFBG3VHI.js} +1 -1
  32. package/dist/kit/{chunk-3A5LID2G.js → chunk-CG6SGQMY.js} +1 -1
  33. package/dist/kit/{chunk-T3GWGPST.js → chunk-CGSWUO67.js} +1 -1
  34. package/dist/kit/{chunk-DFOWXOZR.js → chunk-DAJSBX6H.js} +1 -1
  35. package/dist/kit/{chunk-IUKSHYED.js → chunk-DCLJHSWM.js} +1 -1
  36. package/dist/kit/{chunk-W2STAN6V.js → chunk-DMRPBFLW.js} +1 -1
  37. package/dist/kit/{chunk-XANKANGR.js → chunk-E3FPFANJ.js} +1 -1
  38. package/dist/kit/{chunk-VC2ZQG63.js → chunk-EKYEA7Z4.js} +1 -1
  39. package/dist/kit/{chunk-IQTGJRDX.js → chunk-F6F2C3RH.js} +1 -1
  40. package/dist/kit/chunk-FEAFQY7O.js +1 -0
  41. package/dist/kit/{chunk-FUI5AVIF.js → chunk-FHN3PPSI.js} +1 -1
  42. package/dist/kit/{chunk-QRCXXS5Z.js → chunk-FPCCX4FM.js} +1 -1
  43. package/dist/kit/{chunk-TTGMK4EA.js → chunk-FWODCYYJ.js} +1 -1
  44. package/dist/kit/{chunk-AIM3J2US.js → chunk-GBNV3GXG.js} +1 -1
  45. package/dist/kit/chunk-GF72XM4C.js +1 -0
  46. package/dist/kit/{chunk-SARCZMLN.js → chunk-GKR3ROYR.js} +1 -1
  47. package/dist/kit/{chunk-ROR6MG3K.js → chunk-H5KHXZWR.js} +1 -1
  48. package/dist/kit/{chunk-PCIAA2LL.js → chunk-I5R2347P.js} +1 -1
  49. package/dist/kit/{chunk-4QHFEMFS.js → chunk-IBNDCKEX.js} +1 -1
  50. package/dist/kit/{chunk-J2YZBT3N.js → chunk-ILXVBO7M.js} +1 -1
  51. package/dist/kit/{chunk-S62H7ZIU.js → chunk-JELJEEJO.js} +1 -1
  52. package/dist/kit/{chunk-2NVKPXPL.js → chunk-K6JX64AS.js} +1 -1
  53. package/dist/kit/{chunk-3473NPIN.js → chunk-KCEYRIU4.js} +1 -1
  54. package/dist/kit/{chunk-HTUGMGVA.js → chunk-KDROJANO.js} +1 -1
  55. package/dist/kit/{chunk-5QE6UMXN.js → chunk-KEE55QSD.js} +1 -1
  56. package/dist/kit/{chunk-MIZ2DUHU.js → chunk-KFXMLIVF.js} +1 -1
  57. package/dist/kit/{chunk-G57QACJG.js → chunk-KLRF3S7O.js} +1 -1
  58. package/dist/kit/{chunk-ENTDGT2V.js → chunk-KXI3T72F.js} +1 -1
  59. package/dist/kit/{chunk-4ZQFDFEH.js → chunk-KY5KCIZE.js} +1 -1
  60. package/dist/kit/{chunk-4OT66HSZ.js → chunk-LE53AVKR.js} +1 -1
  61. package/dist/kit/{chunk-WJLZM3DR.js → chunk-LVCGC3SO.js} +1 -1
  62. package/dist/kit/chunk-M5VVLYI2.js +1 -0
  63. package/dist/kit/{chunk-7ABNWOW4.js → chunk-MJJSZS23.js} +1 -1
  64. package/dist/kit/{chunk-VVW7LZT2.js → chunk-MZFK765W.js} +1 -1
  65. package/dist/kit/{chunk-5I4IZTL5.js → chunk-NF4WVWAC.js} +1 -1
  66. package/dist/kit/{chunk-PIU2BMFU.js → chunk-NW4U2YRE.js} +1 -1
  67. package/dist/kit/{chunk-5Z2EJAUV.js → chunk-ORSI57T2.js} +1 -1
  68. package/dist/kit/{chunk-UML6XQAR.js → chunk-QSTDYL35.js} +1 -1
  69. package/dist/kit/{chunk-K563CCOL.js → chunk-QVICL57J.js} +1 -1
  70. package/dist/kit/{chunk-MQJQIDO5.js → chunk-RXOPJJC4.js} +1 -1
  71. package/dist/kit/{chunk-SNCXU7KF.js → chunk-SDSW7422.js} +1 -1
  72. package/dist/kit/{chunk-DZ5XGHTJ.js → chunk-TRDA73HN.js} +1 -1
  73. package/dist/kit/{chunk-KWTF6Q5W.js → chunk-UOYBFLGJ.js} +1 -1
  74. package/dist/kit/chunk-UVLKCAKH.js +1 -0
  75. package/dist/kit/{chunk-YCWMOTYH.js → chunk-VBWG7HQA.js} +1 -1
  76. package/dist/kit/{chunk-FR3ZJNOY.js → chunk-VIUEAEBX.js} +1 -1
  77. package/dist/kit/{chunk-ZRJVOUWH.js → chunk-VV2KP7ZW.js} +1 -1
  78. package/dist/kit/chunk-VX2AD3M7.js +1 -0
  79. package/dist/kit/{chunk-RFLIFKZ4.js → chunk-W4U5CK6L.js} +1 -1
  80. package/dist/kit/{chunk-I4QVLLRQ.js → chunk-WI2AF2KE.js} +1 -1
  81. package/dist/kit/{chunk-MGVPLQ3Z.js → chunk-XUCYFWC3.js} +1 -1
  82. package/dist/kit/{chunk-BNVRKD3V.js → chunk-Z2FRNFMB.js} +1 -1
  83. package/dist/kit/{chunk-BQZCLGCY.js → chunk-Z3KD6CLE.js} +1 -1
  84. package/dist/kit/{chunk-E3TUOX2A.js → chunk-ZCXNGJGB.js} +1 -1
  85. package/dist/kit/{chunk-IPVN22ZM.js → chunk-ZWZZMU5P.js} +1 -1
  86. package/dist/kit.cjs +1 -1
  87. package/dist/kit.d.cts +4 -2
  88. package/dist/kit.d.ts +4 -2
  89. package/dist/kit.js +1 -1
  90. package/dist/studio-worker.js +1 -0
  91. package/dist/studio.cjs +1 -1
  92. package/dist/studio.js +1 -1
  93. package/package.json +3 -1
  94. package/skills/asciify-engine/SKILL.md +2 -2
  95. package/skills/asciify-engine/references/applying-asciify.md +1 -1
  96. package/skills/asciify-engine/references/kit.md +2 -2
  97. package/skills/asciify-engine/references/performance.md +6 -3
  98. package/dist/kit/chunk-3PCKMO6I.js +0 -1
  99. package/dist/kit/chunk-4HWMQCAM.js +0 -1
  100. package/dist/kit/chunk-73M2OESE.js +0 -1
  101. package/dist/kit/chunk-BTD6EFAW.js +0 -1
  102. package/dist/kit/chunk-OWEZV7TQ.js +0 -1
  103. package/dist/kit/chunk-S7RZP2MT.js +0 -1
  104. package/dist/kit/chunk-UO7RB7RC.js +0 -1
  105. package/dist/kit/chunk-XM56OTYT.js +0 -1
package/dist/core.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t={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:" ⠁⠃⠇⡇⣇⣧⣷⣿"}},e={fontSize:7,charSpacing:1,brightness:0,contrast:0,charset:t.standard.chars,colorMode:"grayscale",accentColor:"#d4ff00",invert:!1,renderMode:"ascii",animationStyle:"none",animationSpeed:1,dotSizeRatio:.8,ditherStrength:0,charAspect:.55,normalize:!1,hoverStrength:0,hoverRadius:.2,hoverEffect:"spotlight",hoverColor:"#ffffff",hoverShape:"circle",hoverText:"ASCIIFY",artStyle:"classic",fineDither:!1,customText:"",chromaKey:null,chromaKeyTolerance:60,chromaKeyTrimPadding:.002,chromaKeyTrimLuminanceThreshold:0,chromaKeyTrimMode:"range"},n={caustics:"sheen",grain:"shimmer",trace:"relight",tidal:"current",weave:"current",breeze:"current",reform:"develop",print:"develop",unfold:"develop"},o=[{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."}];var a=t=>Math.max(0,Math.min(1,t)),r=(t,e,n)=>{const o=a((n-t)/(e-t));return o*o*(3-2*o)},i=(t,e)=>{const n=(.06711056*t+.00583715*e)%1*52.9829189;return n-Math.floor(n)};function s(t){const e=Math.floor(t),n=Math.max(0,Math.min(1,(t-e-.2)/.6));return e+n*n*(3-2*n)}function h(t,e,n,o,a){if(!(a<1))for(let r=0;r<2;r++){for(let r=0;r<o;r++){let o=0;const i=r*n;for(let e=-a;e<=a;e++)o+=t[i+Math.max(0,Math.min(n-1,e))];for(let r=0;r<n;r++)e[i+r]=o/(2*a+1),o+=t[i+Math.min(n-1,r+a+1)]-t[i+Math.max(0,r-a)]}for(let r=0;r<n;r++){let i=0;for(let t=-a;t<=a;t++)i+=e[Math.max(0,Math.min(o-1,t))*n+r];for(let s=0;s<o;s++)t[s*n+r]=i/(2*a+1),i+=e[Math.min(o-1,s+a+1)*n+r]-e[Math.max(0,s-a)*n+r]}}}var c=new Float32Array(0);var l=t=>Math.max(0,Math.min(1,t)),f=(t,e,n)=>{const o=l((n-t)/(e-t));return o*o*(3-2*o)};function m(t,e,n=256){let o=0;for(let e=0;e<t.length;e++)t[e]>o&&(o=t[e]);if(o<=0)return 0;const a=new Uint32Array(n);for(let e=0;e<t.length;e++)a[Math.min(n-1,Math.floor(Math.max(0,t[e])/o*n))]++;let r=0;const i=t.length*e;for(let t=0;t<n;t++)if(r+=a[t],r>=i)return(t+1)/n*o;return o}var d=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}},u=null;function M(t,e,n,o,a){const r=2*a+1;for(let i=0;i<o;i++){const o=i*n;let s=0;for(let e=-a;e<=a;e++)s+=t[o+Math.max(0,Math.min(n-1,e))];for(let i=0;i<n;i++)e[o+i]=s/r,s+=t[o+Math.min(n-1,i+a+1)]-t[o+Math.max(0,i-a)]}for(let i=0;i<n;i++){let s=0;for(let t=-a;t<=a;t++)s+=e[Math.max(0,Math.min(o-1,t))*n+i];for(let h=0;h<o;h++)t[h*n+i]=s/r,s+=e[Math.min(o-1,h+a+1)*n+i]-e[Math.max(0,h-a)*n+i]}}function g(t,e,n,o,a,r,i){const s=n*o,h=i.take(),c=i.take(e),l=i.take(t),f=i.take(),m=i.take();for(let n=0;n<s;n++)f[n]=e[n]*e[n],m[n]=e[n]*t[n];M(c,h,n,o,a),M(l,h,n,o,a),M(f,h,n,o,a),M(m,h,n,o,a);for(let t=0;t<s;t++){const e=(m[t]-c[t]*l[t])/(f[t]-c[t]*c[t]+r);f[t]=e,m[t]=l[t]-e*c[t]}M(f,h,n,o,a),M(m,h,n,o,a);for(let n=0;n<s;n++)t[n]=f[n]*e[n]+m[n]}function p(t,e,n,o,a,r=2){for(let i=0;i<r;i++){for(let r=0;r<o;r++)for(let o=0;o<n;o++){const i=r*n+o;let s=t[i];o>0&&(s=Math.max(s,Math.min(e[i],t[i-1]*a))),r>0&&(s=Math.max(s,Math.min(e[i],t[i-n]*a),o>0?Math.min(e[i],t[i-n-1]*a):0,o<n-1?Math.min(e[i],t[i-n+1]*a):0)),t[i]=s}for(let r=o-1;r>=0;r--)for(let i=n-1;i>=0;i--){const s=r*n+i;let h=t[s];i<n-1&&(h=Math.max(h,Math.min(e[s],t[s+1]*a))),r<o-1&&(h=Math.max(h,Math.min(e[s],t[s+n]*a),i>0?Math.min(e[s],t[s+n-1]*a):0,i<n-1?Math.min(e[s],t[s+n+1]*a):0)),t[s]=h}}}function x(t,e,n,o,a){for(let r=0;r<o;r++)for(let o=0;o<n;o++){let i=1;for(let e=Math.max(0,o-a);e<=Math.min(n-1,o+a);e++)i=Math.min(i,t[r*n+e]);e[r*n+o]=i}for(let r=0;r<o;r++)for(let i=0;i<n;i++){let s=1;for(let t=Math.max(0,r-a);t<=Math.min(o-1,r+a);t++)s=Math.min(s,e[t*n+i]);t[r*n+i]=s}}function v(t,e,n,o,a){const r=n*o,i=Math.min(n,o),s=a.take(),d=a.take(),u=a.take(),v=a.take(),w=a.take();for(let n=0;n<r;n++){const o=t[4*n+3]/255;w[n]=o,s[n]=e[4*n]/255*o,d[n]=e[4*n+1]/255*o,u[n]=e[4*n+2]/255*o,v[n]=(.299*t[4*n]+.587*t[4*n+1]+.114*t[4*n+2])/255*o}const y=a.take(),b=(t,e)=>{const r=a.take(t);return h(r,y,n,o,e),r},S=Math.max(2,Math.round(.04*i)),E=Math.max(S+2,Math.round(.12*i)),k=Math.max(2,Math.round(.05*i)),T=b(v,1),A=b(v,S),C=b(v,E),F=a.take(),I=a.take(),L=a.take(),R=a.take(),H=a.take();for(let t=0;t<o;t++)for(let e=0;e<n;e++){const a=t*n+e;F[a]=Math.abs(v[a]-T[a]),I[a]=Math.abs(T[a]-A[a]),L[a]=Math.abs(A[a]-C[a]),R[a]=Math.abs(v[t*n+Math.min(n-1,e+1)]-v[t*n+Math.max(0,e-1)]),H[a]=Math.abs(v[Math.min(o-1,t+1)*n+e]-v[Math.max(0,t-1)*n+e])}h(F,y,n,o,k),h(I,y,n,o,k),h(L,y,n,o,k),h(R,y,n,o,2),h(H,y,n,o,2);const W=Math.max(.01,m(F,.9)+m(I,.9)),j=b(s,1),$=b(d,1),P=b(u,1),O=a.take(),z=a.take(),q=a.take();let D=0;for(let t=0;t<r;t++){const e=j[t],n=$[t],o=P[t],a=Math.max(e,n,o),r=a-Math.min(e,n,o);q[t]=a,z[t]=a>.001?r/a:0,D+=r;let i=0;r>1e-4&&(i=a===e?((n-o)/r+6)%6:a===n?(o-e)/r+2:(e-n)/r+4),O[t]=60*i}const U=f(.02,.07,D/r),V=Math.max(2,Math.round(.06*o)),B=new Float32Array(o);for(let t=0;t<o;t++){let e=0;for(let o=0;o<n;o++)e+=F[t*n+o]+I[t*n+o];B[t]=e/n}let N=.5,K=0;for(let t=Math.max(V,Math.round(.12*o));t<=Math.min(o-V,Math.round(.88*o));t++){let e=0,a=0,r=0,i=0;for(let o=0;o<n;o++){let r=0,i=0,s=0,h=0,c=0,l=0;for(let e=1;e<=V;e++){const a=(t-e)*n+o,f=(t+e-1)*n+o;r+=j[a],i+=$[a],s+=P[a],h+=j[f],c+=$[f],l+=P[f]}const f=(Math.abs(r-h)+Math.abs(i-c)+Math.abs(s-l))/V;e+=f,a+=f>.12?1:0}const s=Math.max(2,Math.round(.15*o)),h=Math.max(0,t-s),c=Math.min(o,t+s);for(let e=h;e<t;e++)r+=B[e];for(let e=t;e<c;e++)i+=B[e];r/=t-h,i/=c-t;const l=f(-.05,.3,(i-r)/(i+r+1e-4)),m=f(.08,.35,e/n)*(a/n)*l;m>K&&(K=m,N=t/o)}const Y=f(.15,.45,K),_=a.take(),G=a.take(),X=a.take();for(let t=0;t<r;t++)_[t]=Math.min(s[t],d[t],u[t]);x(_,y,n,o,1),h(_,y,n,o,S);for(let t=0;t<r;t++)G[t]=I[t]+L[t];let J=0,Q=0,Z=0;for(let t=0;t<r;t++)J+=j[t],Q+=$[t],Z+=P[t];J/=r,Q/=r,Z/=r;const tt=b(j,S),et=b($,S),nt=b(P,S),ot=b(j,E),at=b($,E),rt=b(P,E);for(let t=0;t<r;t++){const e=Math.hypot(tt[t]-J,et[t]-Q,nt[t]-Z),n=Math.hypot(tt[t]-ot[t],et[t]-at[t],nt[t]-rt[t]);X[t]=(e+1.5*n)*(.4+.6*z[t]*U+.4*(1-U))}const it=a.take(),st=a.take(),ht=a.take(),ct=a.take(),lt=a.take(),ft=a.take(),mt=a.take(),dt=a.take(),ut=a.take(),Mt=a.take();for(let t=0;t<o;t++)for(let e=0;e<n;e++)Mt[t*n+e]=Math.abs(v[Math.min(o-1,t+1)*n+e]-v[Math.max(0,t-1)*n+e]);h(Mt,y,n,o,1);for(let t=0;t<o;t++)for(let e=0;e<n;e++){const a=t*n+e,r=(t+.5)/o,i=O[a],s=z[a]*U,h=q[a],c=F[a]+I[a],l=f(175,200,i)*(1-f(250,275,i))*f(.08,.25,s),m=(1-f(45,65,i)+f(290,330,i))*f(.2,.45,s)*f(.3,.55,h),d=(1-f(.15,.35,s))*f(.45,.7,h)*Y,u=(1-f(.08,.2,h))*Y,M=Y>.3?1-f(N,N+.1,r):1-f(.4,.8,r),g=1-f(.02,.06,c),p=1-f(.03,.09,c);st[a]=Math.max(l*g,.7*u*(1-f(.008,.025,c)),m*p*.9)*M,ht[a]=Math.max(st[a],d*g*M),it[a]=0===t?st[a]:0,ct[a]=f(150,172,i)*(1-f(232,250,i))*f(.25,.45,s),mt[a]=f(1.3,2.2,(R[a]+.004)/(H[a]+.004))*f(.35,.55,T[a])*(1-f(.1,.18,z[a]*U))*f(.025,.07,c)*f(.025,.045,Mt[a]);const x=1-f(.18,.4,s),v=f(.55,.8,h)*f(.05,.12,c);lt[a]=Math.max(ct[a],.85*x,.8*v)}p(it,st,n,o,.995,1),p(it,ht,n,o,.8,1);let gt=0;for(let t=0;t<r;t++)gt+=it[t];const pt=gt>.04*r&&Y>.3;if(pt)for(let t=0;t<o;t++)for(let e=0;e<n;e++)ct[t*n+e]*=f(N,N+.05,(t+.5)/o);if(pt){const t=a.take(),e=a.take(),i=a.take();for(let e=0;e<r;e++)t[e]=.299*tt[e]+.587*et[e]+.114*nt[e];for(let t=0;t<o;t++)for(let a=0;a<n;a++)e[t*n+a]=T[Math.min(o-1,t+1)*n+a]-T[Math.max(0,t-1)*n+a];const s=new Uint8Array(r);for(let t=1;t<o-1;t++)for(let a=0;a<n;a++){const r=Math.abs(e[t*n+a]);let i=r>.03;for(let s=-3;s<=3&&i;s++)s&&t+s>=0&&t+s<o&&Math.abs(e[(t+s)*n+a])>r&&(i=!1);s[t*n+a]=i?1:0}const c=(e,n,o,a=!0)=>{const r=tt[n]+et[n]+nt[n]+.05,i=tt[o]+et[o]+nt[o]+.05,s=Math.abs(tt[n]/r-tt[o]/i)+Math.abs(et[n]/r-et[o]/i)+Math.abs(nt[n]/r-nt[o]/i),h=Math.min(Math.abs(O[n]-O[o]),360-Math.abs(O[n]-O[o])),c=Math.max(1-f(.1,.25,s),(1-f(15,35,h))*f(.15,.3,Math.min(z[n],z[o]))),l=Math.max(f(2,3,(H[n]+.004)/(R[n]+.004))*f(.015,.04,F[n]+I[n])*f(.4,.55,F[n]/(F[n]+I[n]+1e-4)),1-f(.12,.25,t[n]));return c*(a?l:1)*(1-f(.82*t[o]+.02,1.02*t[o]+.05,t[n]))};let l=0,m=0;for(let t=Math.max(3,Math.round(o*Math.max(.25,N)));t<Math.round(.88*o);t++){let e=0;for(let o=0;o<n;o++)(s[(t-1)*n+o]||s[t*n+o]||s[(t+1)*n+o])&&e++;if(e<.5*n)continue;let a=0;for(let e=t+1;e<Math.min(o,2*t);e++)for(let o=0;o<n;o++)a+=c(t,e*n+o,(2*t-e)*n+o);a>m&&(m=a,l=t)}const d=f(.05,.1,m/r);if(d>0)for(let t=l+1;t<Math.min(o,2*l);t++)for(let e=0;e<n;e++){const o=t*n+e;dt[o]=c(l,o,(2*l-t)*n+e)*d,ut[o]=c(l,o,(2*l-t)*n+e,!1)*d,i[o]=dt[o]}h(i,y,n,o,1);for(let t=0;t<r;t++)dt[t]=Math.max(dt[t],i[t]),ct[t]=Math.max(ct[t],dt[t])}const xt=b(ct,E);for(let t=0;t<r;t++)ct[t]*=f(.15,.35,xt[t]);const vt=b(ct,S);for(let t=0;t<r;t++){ct[t]*=1-.8*st[t];const e=Math.min(Math.abs(O[t]-200),360-Math.abs(O[t]-200));ft[t]=f(.28,.45,z[t]*U)*f(55,80,e)*(1-f(.3,.6,ut[t]))}const wt=b(ft,S);for(let t=0;t<r;t++)ft[t]=Math.max(ft[t]*(1-(1-f(.15,.3,wt[t]))*f(.55,.7,q[t])*f(.5,.65,z[t])),1-w[t]),lt[t]=Math.min(Math.max(lt[t],.9*ut[t]),Math.max(ct[t],f(.25,.6,vt[t])))*(1-it[t])*(1-ft[t]);p(ct,lt,n,o,.97);const yt=a.take(mt),bt=Math.max(2,Math.round(.12*o));for(let t=0;t<n;t++){let e=0;for(let a=-bt;a<=bt;a++)e+=mt[Math.max(0,Math.min(o-1,a))*n+t];for(let a=0;a<o;a++)yt[a*n+t]=e/(2*bt+1),e+=mt[Math.min(o-1,a+bt+1)*n+t]-mt[Math.max(0,a-bt)*n+t]}h(yt,y,n,o,1);for(let t=0;t<r;t++)mt[t]=f(.2,.45,yt[t])*f(.2,.5,mt[t]+.5*yt[t])*(1-it[t]);g(it,v,n,o,Math.max(2,Math.round(.04*i)),.002,a),g(ct,v,n,o,Math.max(2,Math.round(.04*i)),.002,a),g(mt,v,n,o,Math.max(2,Math.round(.03*i)),.002,a),h(ft,y,n,o,1);for(let t=0;t<r;t++)it[t]=f(.3,.7,it[t])*w[t],mt[t]=f(.3,.7,mt[t])*w[t]*(1-it[t]),ct[t]=f(.3,.7,ct[t])*(1-it[t])*(1-mt[t])*(1-f(.15,.4,ft[t]));x(it,y,n,o,2),x(ct,y,n,o,2),x(mt,y,n,o,1),h(it,y,n,o,1),h(ct,y,n,o,1),h(mt,y,n,o,1);const St=1/Math.max(.02,m(X,.97)),Et=1/Math.max(.01,m(G,.9)),kt=m(_,.97),Tt=m(_,.1),At=f(.06,.25,kt-Tt),Ct=a.take();for(let t=0;t<o;t++)for(let e=0;e<n;e++){const a=t*n+e,r=(e+.5)/n,i=(t+.5)/o,s=Math.max(it[a],ct[a]),h=F[a]+I[a]+L[a],c=.6*l(((F[a]+.6*I[a])/(h+.004)-.25)/.55)+.4*l((F[a]+I[a])/W),m=f(.04,.35,h/W)*(1-s),d=.55*l((_[a]-Tt)/Math.max(.05,kt-Tt))+.25*(1-l(G[a]*Et))+.2*l(2*(P[a]-j[a])+.3)*U,u=At*f(.12,.35,A[a])*(.4+.6*Y),M=Y*(i<N?.45:.45+.55*f(0,1,(i-N)/Math.max(.15,1-N)))+(1-Y)*(.5+.4*(i-.5)),g=F[a]/(F[a]+I[a]+1e-4),p=f(.2,.7,(F[a]+I[a])/W)*(.35+.65*Y)*(1-s),x=1-l(1.5*Math.hypot(1.2*(r-.5),i-.52)),v=l(X[a]*St)*(.55+.45*x),w=.3*m,y=.25*u,b=.12+.45*Y,S=.12*p,E=.35*(1-.4*Y)*(1-s);Ct[a]=(w*c+y*(1-d)+b*M+S*l(1.6-1.6*g)+E*v+.04)/(w+y+b+S+E+.08)*(1-.85*it[a])*(1-.45*ct[a]*(1-Y))}const Ft=function(t,e,n){const o=e*n,a={width:e,height:n,subject:new Float32Array(o),depth:new Float32Array(o),key:"none"},{subject:r,depth:i}=a;let s=0;for(let e=0;e<o;e++)t[4*e+3]<250&&s++;const l=e=>(.2126*t[4*e]+.7152*t[4*e+1]+.0722*t[4*e+2])/255;let f="none",m=0;if(s>.01*o)f="alpha";else{let t=0,o=0,a=0;const r=Math.max(1,Math.round(.03*Math.min(e,n)));for(let i=0;i<n;i++)for(let s=0;s<e;s++){if(s>=r&&i>=r&&s<e-r&&i<n-r)continue;const h=l(i*e+s);t+=h,o+=h*h,a++}m=t/Math.max(1,a),Math.sqrt(Math.max(0,o/Math.max(1,a)-m*m))<.07&&(f="ground")}for(let e=0;e<o;e++){const n=t[4*e+3]/255,o=l(e);let a=1;if("alpha"===f)a=n;else if("ground"===f){const t=Math.max(0,Math.min(1,(Math.abs(o-m)-.035)/.12));a=t*t*(3-2*t)}r[e]=1*a,i[e]=o*n}a.key=f,c.length<o&&(c=new Float32Array(o));const d=c;return h(r,d,e,n,Math.max(1,Math.round(.02*Math.min(e,n)))),h(i,d,e,n,Math.max(1,Math.round(.035*Math.min(e,n)))),a}(t,n,o);if("none"!==Ft.key)for(let t=0;t<r;t++)Ct[t]=.7*Ft.subject[t]+.3*Ct[t];return h(Ct,y,n,o,Math.max(1,Math.round(.03*i))),function(t,e,n,o,a,r,i,s,h){const c=a*r,l=h.take(),f=t=>(M(t,l,a,r,i),t),m=(t,e)=>{const n=h.take();for(let o=0;o<c;o++)n[o]=t[o]*e[o];return f(n)},d=f(h.take(e)),u=f(h.take(n)),g=f(h.take(o)),p=f(h.take(t)),x=m(e,e),v=m(e,n),w=m(e,o),y=m(n,n),b=m(n,o),S=m(o,o),E=m(e,t),k=m(n,t),T=m(o,t),A=h.take(),C=h.take(),F=h.take(),I=h.take();for(let t=0;t<c;t++){const e=E[t]-d[t]*p[t],n=k[t]-u[t]*p[t],o=T[t]-g[t]*p[t],a=x[t]-d[t]*d[t]+s,r=v[t]-d[t]*u[t],i=w[t]-d[t]*g[t],h=y[t]-u[t]*u[t]+s,c=b[t]-u[t]*g[t],l=S[t]-g[t]*g[t]+s,f=h*l-c*c,m=i*c-r*l,M=r*c-i*h,L=a*l-i*i,R=r*i-a*c,H=a*h-r*r,W=a*f+r*m+i*M,j=Math.abs(W)>1e-12?1/W:0;A[t]=(f*e+m*n+M*o)*j,C[t]=(m*e+L*n+R*o)*j,F[t]=(M*e+R*n+H*o)*j,I[t]=p[t]-A[t]*d[t]-C[t]*u[t]-F[t]*g[t]}f(A),f(C),f(F),f(I);for(let a=0;a<c;a++)t[a]=A[a]*e[a]+C[a]*n[a]+F[a]*o[a]+I[a]}(Ct,j,$,P,n,o,Math.max(2,Math.round(.07*i)),.004,a),{depth:Ct,water:ct,sky:it,falls:mt}}function w(t,e,n,o,a,r,i){if(e===r&&n===i)return t[a*r+o];const s=Math.max(0,Math.min(e-1,(o+.5)*e/r-.5)),h=Math.max(0,Math.min(n-1,(a+.5)*n/i-.5)),c=Math.min(e-2,Math.floor(s)),l=Math.min(n-2,Math.floor(h)),f=s-c,m=h-l;if(c<0||l<0)return t[Math.round(h)*e+Math.round(s)];const d=l*e+c,u=d+e;return(t[d]*(1-f)+t[d+1]*f)*(1-m)+(t[u]*(1-f)+t[u+1]*f)*m}var y=new WeakMap;function b(t){const e=y.get(t);if(e)return e;const n=t.length,o=t[0]?.length??0,a=new Uint8ClampedArray(o*n*4);for(let e=0;e<n;e++)for(let n=0;n<o;n++){const r=t[e][n],i=4*(e*o+n);a[i]=r.r,a[i+1]=r.g,a[i+2]=r.b,a[i+3]=r.a}const r=function(t,e,n,o,a=t){const r=e*n,i=o?.length===11*r?o:new Float32Array(11*r);if(!r)return i;const s=Math.min(e,n),c=new Float32Array(r),f=new Float32Array(r),M=new Float32Array(r),g=new Float32Array(r),p=new Float32Array(r),x=new Float32Array(r);for(let e=0;e<r;e++){const n=t[4*e+3]/255;c[e]=(.299*t[4*e]+.587*t[4*e+1]+.114*t[4*e+2])/255*n}f.set(c),h(f,x,e,n,Math.max(1,Math.round(.012*s))),M.set(c),h(M,x,e,n,Math.max(1,Math.round(.03*s)));for(let t=0;t<r;t++){g[t]=Math.abs(c[t]-f[t]);const e=Math.max(0,c[t]-.55)/.45;p[t]=e*e}h(g,x,e,n,Math.max(1,Math.round(.02*s)));const y=1/Math.max(.02,m(g,.95));h(p,x,e,n,Math.max(1,Math.round(.05*s)));const b=1/Math.max(.03,m(p,.98)),S=Math.max(1,Math.ceil(Math.sqrt(r/12e3))),E=Math.max(1,Math.floor(e/S)),k=Math.max(1,Math.floor(n/S)),T=E*k;let A=t,C=a;if(S>1){const n=new Uint8ClampedArray(4*T),o=a===t?n:new Uint8ClampedArray(4*T);for(let r=0;r<k;r++)for(let i=0;i<E;i++){const s=[0,0,0,0,0,0,0];for(let h=r*S;h<(r+1)*S;h++)for(let r=i*S;r<(i+1)*S;r++){const i=4*(h*e+r);for(let e=0;e<4;e++)s[e]+=t[i+e];if(o!==n)for(let t=0;t<3;t++)s[4+t]+=a[i+t]}const h=4*(r*E+i),c=S*S;for(let t=0;t<4;t++)n[h+t]=s[t]/c;if(o!==n){for(let t=0;t<3;t++)o[h+t]=s[4+t]/c;o[h+3]=n[h+3]}}A=n,C=o}u?.n!==T&&(u=new d(T)),u.reset();const{depth:F,water:I,sky:L,falls:R}=v(A,C,E,k,u),H=m(F,.03),W=m(F,.97),j=Math.max(.05,W-H);let $=0,P=0,O=0;const z=new Float32Array(r);for(let t=0;t<n;t++)for(let o=0;o<e;o++){const a=t*e+o,r=11*a,s=l((w(F,E,k,o,t,e,n)-H)/j);i[r+1]=s,i[r+8]=l(w(I,E,k,o,t,e,n)),i[r+9]=l(w(L,E,k,o,t,e,n)),i[r+10]=l(w(R,E,k,o,t,e,n));const h=s*s*s*(.25+c[a]);$+=(o+.5)/e*h,P+=(t+.5)/n*h,O+=h,z[a]=Math.hypot(M[t*e+Math.min(e-1,o+1)]-M[t*e+Math.max(0,o-1)],M[Math.min(n-1,t+1)*e+o]-M[Math.max(0,t-1)*e+o])}$=O>0?Math.max(.3,Math.min(.7,$/O)):.5,P=O>0?Math.max(.3,Math.min(.7,P/O)):.5;const q=1/Math.max(.004,m(z,.97));for(let t=0;t<n;t++)for(let o=0;o<e;o++){const a=t*e+o,r=11*a,s=(M[t*e+Math.min(e-1,o+1)]-M[t*e+Math.max(0,o-1)])*q,h=(M[Math.min(n-1,t+1)*e+o]-M[Math.max(0,t-1)*e+o])*q;i[r]=M[a],i[r+2]=Math.min(1,p[a]*b),i[r+3]=Math.min(1,g[a]*y),i[r+4]=Math.max(-1,Math.min(1,-s)),i[r+5]=Math.max(-1,Math.min(1,-h)),i[r+6]=$,i[r+7]=P}return i}(a,o,n);return y.set(t,r),r}function S(t,e){const n=document.createElement("canvas");n.width=t,n.height=e;const o=n.getContext("2d",{willReadFrequently:!0});return{canvas:n,ctx:o}}function E(t,e,n){let o=t+255*e;return o=259*(255*n+255)/(255*(259-255*n))*(o-128)+128,Math.max(0,Math.min(255,o))}function k(t,e,n,o,a,r){if((r?1-t/255:t/255)<.12)return" ";const i=[...e];return i[(o*a+n)%i.length]}var T=[[0,8,2,10],[12,4,14,6],[3,11,1,9],[15,7,13,5]];function A(t,e,n,o){if(o<=0)return t;const a=(T[n%4][e%4]/16-.5)*o*128;return Math.max(0,Math.min(255,t+a))}var C=new Array(256),F=new Array(256);for(let t=0;t<256;t++)C[t]=`rgb(${t},${t},${t})`,F[t]=`rgb(0,${t},0)`;function I(t,e,n,o,a,r=!1){switch(e){case"fullcolor":return`rgb(${t.r},${t.g},${t.b})`;case"matrix":return F[.299*t.r+.587*t.g+.114*t.b|0];case"accent":return`rgb(${n},${o},${a})`;default:{const e=.299*t.r+.587*t.g+.114*t.b|0;return C[e]}}}var L=[0,0,0];function R(t,e,n,o,a,r=!1){switch(e){case"fullcolor":L[0]=t.r,L[1]=t.g,L[2]=t.b;break;case"matrix":{const e=.299*t.r+.587*t.g+.114*t.b|0;L[0]=0,L[1]=e,L[2]=0;break}case"accent":L[0]=n,L[1]=o,L[2]=a;break;default:{const e=.299*t.r+.587*t.g+.114*t.b|0;L[0]=e,L[1]=e,L[2]=e;break}}return L}function H(t){const e=t.match(/rgba?\(\s*(\d+)\s*[,\s]\s*(\d+)\s*[,\s]\s*(\d+)(?:\s*[,/]\s*([\d.]+))?\s*\)/);return e?{r:+e[1],g:+e[2],b:+e[3],a:void 0!==e[4]?+e[4]:1}:null}function W(t){let e=t;for(;e&&e!==document.documentElement.parentElement;){const t=getComputedStyle(e).backgroundColor;if(t&&"transparent"!==t&&"rgba(0, 0, 0, 0)"!==t){const e=H(t);if(e&&e.a>.1)return e}e=e.parentElement}return null}function j(t){if(t){const e=W(t);if(e){return(.299*e.r+.587*e.g+.114*e.b)/255<.4}}if("undefined"!=typeof document){const t=document.documentElement,e=(t.getAttribute("data-theme")||"").toLowerCase();if("dark"===e)return!0;if("light"===e)return!1;if(t.classList.contains("dark"))return!0;if(document.body){const t=W(document.body);if(t){return(.299*t.r+.587*t.g+.114*t.b)/255<.4}}}return"undefined"!=typeof window&&window.matchMedia("(prefers-color-scheme: dark)").matches}function $(t){if("string"!=typeof t)return t;const e=document.createElement("canvas");e.width=1,e.height=1;const n=e.getContext("2d");n.fillStyle=t,n.fillRect(0,0,1,1);const o=n.getImageData(0,0,1,1).data;return{r:o[0],g:o[1],b:o[2]}}function P(t){return t*t*(3-2*t)}var O={scale:1,offsetX:0,offsetY:0,glow:0,colorBlend:0,proximity:0};function z(t,e,n,o,a,r,i,s,h="spotlight",c=.5,l="circle",f=[],m=1){const d=(t-n)*Math.max(1,m),u=(e-o)*Math.max(1,1/m),M=.08+.35*c+.04*r;let g,p;if("box"===l){const t=Math.abs(d),e=Math.abs(u);g=Math.max(t,e),p=M}else g=Math.sqrt(d*d+u*u),p=M;if(g>=p&&("trail"!==h||0===f.length))return O.scale=1,O.offsetX=0,O.offsetY=0,O.glow=0,O.colorBlend=0,O.proximity=0,O;const x=P(Math.max(0,1-g/p))*a;let v=1,w=0,y=0,b=0,S=0;switch(h){case"spotlight":{v=1+x*r*1.8;const t=Math.atan2(u,d),e=x*x*r*.6;w=Math.cos(t)*e*i,y=Math.sin(t)*e*s,b=x*r*.4,S=x*x*r*.25;break}case"magnify":v=1+x*r*.85,b=x*r*.15;break;case"repel":{v=1;const t=Math.atan2(u,d),e=x*x*r*1.8;w=Math.cos(t)*e*i,y=Math.sin(t)*e*s;break}case"glow":b=x*r*.8,S=x*r*.4;break;case"colorShift":v=1,b=x*r*.12,S=x*r;break;case"attract":{const t=Math.atan2(u,d),e=x*x*r*1;w=(.45*-Math.cos(t)-1.6*Math.sin(t))*e*i,y=(.45*-Math.sin(t)+1.6*Math.cos(t))*e*s,b=x*r*.3;break}case"shatter":{const t=Math.atan2(u,d),e=.5*Math.sin(43.7*d+29.3*u),n=x*r*1.4*(.7+.3*e);w=Math.cos(t+e)*n*i,y=Math.sin(t+e)*n*s,v=Math.max(.1,1-x*r*.6),b=x*r*.25;break}case"trail":{let n=x,o=-u*x,a=d*x;for(const r of f){const i=(t-r.x)*Math.max(1,m),s=(e-r.y)*Math.max(1,1/m),h=Math.hypot(i,s)/M;if(h>=1)continue;const c=P(1-h)*r.intensity;n=Math.max(n,c),o+=(.35*r.vx-2*s)*c*.35,a+=(.35*r.vy+2*i)*c*.35}w=Math.tanh(2*o)*r*i*3,y=Math.tanh(2*a)*r*s*3,S=n*r*.65,b=n*r*.35,v=1+n*r*.08,O.proximity=n;break}case"glitchText":v=1,b=x*r*.5,S=x*r*.6}return O.scale=v,O.offsetX=w,O.offsetY=y,O.glow=b,O.colorBlend=S,"trail"!==h&&(O.proximity=x),O}function q(t,e,{continuous:n=!1,interactive:o=!1}={}){const a=t.parentElement??t;let r=null,i=0,s=!1,h=!0,c=!0,l=-1/0;const f=window.matchMedia("(prefers-reduced-motion: reduce)"),m=()=>{c=!0,s||!h||document.hidden||i||(i=requestAnimationFrame(d))},d=t=>{if(i=0,s||!h||document.hidden)return;const o=!f.matches&&(n||t-l<1500);(c||o)&&(e(t,f.matches?null:r),c=!1),o&&(i=requestAnimationFrame(d))},u=e=>{if("touch"===e.pointerType)return;const n=t.getBoundingClientRect();if(!n.width||!n.height)return;const o=(e.clientX-n.left)/n.width,a=(e.clientY-n.top)/n.height;r=o>=0&&o<=1&&a>=0&&a<=1?{x:o,y:a}:null,l=performance.now(),m()},M=()=>{r=null,l=performance.now(),m()},g=()=>{document.hidden&&i?(cancelAnimationFrame(i),i=0):m()},p="undefined"==typeof IntersectionObserver?null:new IntersectionObserver(([t])=>{h=t.isIntersecting,h?m():i&&(cancelAnimationFrame(i),i=0)});return p?.observe(t),o&&(a.addEventListener("pointermove",u),a.addEventListener("pointerleave",M)),document.addEventListener("visibilitychange",g),f.addEventListener("change",m),m(),{wake:m,stop:()=>{s=!0,cancelAnimationFrame(i),p?.disconnect(),a.removeEventListener("pointermove",u),a.removeEventListener("pointerleave",M),document.removeEventListener("visibilitychange",g),f.removeEventListener("change",m)}}}var D=null,U=null;function V(t,e){if(!D||!U){const n=S(t,e);D=n.canvas,U=n.ctx}return D.width!==t&&(D.width=t),D.height!==e&&(D.height=e),U}var B=new Map,N=new Map,K=new WeakMap;function Y(t){const e=Intl.Segmenter;return e?Array.from(new e(void 0,{granularity:"grapheme"}).segment(t),({segment:t})=>t):[...t]}function _(t){let e=B.get(t);return e||(e=Y(t),B.set(t,e)),e}function G(t){return Y(t)}function X(t,e,n){const o=n?1-t/255:t/255,a=Math.floor(o*(e.length-1));return e[Math.max(0,Math.min(e.length-1,a))]??" "}function J(t,e,n,o){const a=`${t}\0${e?1:0}\0${n}\0${o}`;let r=N.get(a);if(!r){const i=_(t);r=new Array(256);for(let t=0;t<256;t++)r[t]=X(E(t,n,o),i,e);N.set(a,r)}return r}function Q(t,e){return"auto"!==t?t:!j(e)}function Z(t){const e=t.match(/^#([0-9a-fA-F]{3,6})$/);if(e){let t=e[1];if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6===t.length)return t}const n=t.match(/rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/);return n?[n[1],n[2],n[3]].map(t=>parseInt(t).toString(16).padStart(2,"0")).join(""):null}function tt(t){const e=t||"auto";if("auto"!==e)return Z(e)??"ffffff";if("undefined"!=typeof document){const t=getComputedStyle(document.documentElement);for(const e of["--accent-color","--color-accent","--accent","--color-primary","--primary","--brand-color"]){const n=Z(t.getPropertyValue(e).trim());if(n)return n}const e=Z(getComputedStyle(document.body).accentColor??"");if(e)return e}return j("undefined"!=typeof document?document.body:null)?"faf9f7":"0d0d0d"}function et(t,e,n){return Math.max(e,Math.min(n,t))}function nt(t,e,n){if(!t)return{x:0,y:0,width:e,height:n};const o=t.unit??"percent",a=!1!==t.preserveAspect,r=t=>void 0===t?void 0:"percent"===o?t*e:t,i=t=>void 0===t?void 0:"percent"===o?t*n:t,s=et(r(t.left)??0,0,e-1),h=et(r(t.right)??0,0,e-s-1),c=et(i(t.top)??0,0,n-1),l=et(i(t.bottom)??0,0,n-c-1),f=void 0!==t.left||void 0!==t.right||void 0!==t.top||void 0!==t.bottom,m=Math.max(1,e-s-h),d=Math.max(1,n-c-l),u=f?m:r(t.width),M=f?d:i(t.height);let g=u??e,p=M??n;if(a&&!f){const t=g/e,o=p/n,a=Math.min(t,o),r=void 0===u?o:void 0===M?t:a;g=e*r,p=n*r}g=et(g,1,f?m:e),p=et(p,1,f?d:n);const x=t.anchor??"center",v=r(t.x),w=i(t.y),y=f?s:0,b=f?c:0,S=f?m:e,E=f?d:n,k=x.endsWith("left")||"left"===x?0:x.endsWith("right")||"right"===x?S-g:(S-g)/2,T=x.startsWith("top")||"top"===x?0:x.startsWith("bottom")||"bottom"===x?E-p:(E-p)/2;return{x:et(v??y+k,0,Math.max(0,e-g)),y:et(w??b+T,0,Math.max(0,n-p)),width:g,height:p}}function ot(t,e,n,o){const a=t instanceof HTMLVideoElement?t.videoWidth:t.width,r=t instanceof HTMLVideoElement?t.videoHeight:t.height;if(0===a||0===r)return{frame:[],cols:0,rows:0};const i=e.charAspect,s=e.fontSize*e.charSpacing,h=e.fontSize/i*e.charSpacing,c=n||a,l=o||r,f=Math.floor(c/s),m=Math.floor(l/h);if(f<=0||m<=0)return{frame:[],cols:0,rows:0};const d=nt(e.sourceCrop,a,r),u=Math.max(1,Math.min(Math.floor(2048/f),Math.floor(d.width/f))),M=Math.max(1,Math.min(Math.floor(2048/m),Math.floor(d.height/m))),g=f*u,p=m*M,x=V(g,p),v=x.globalCompositeOperation;x.globalCompositeOperation="copy";try{x.drawImage(t,d.x,d.y,d.width,d.height,0,0,g,p)}finally{x.globalCompositeOperation=v}const w=x.getImageData(0,0,g,p).data,y=e.chromaKey,b=null!=y&&!1!==y,S=!0===y,T="blue-screen"===y;let C=null,F=0;!b||S||T||(C=$(y),F=(e.chromaKeyTolerance??60)**2);let I=0,L=255;if(e.normalize){let t=255,e=0;for(let n=0;n<w.length;n+=4){if(b){const t=w[n],e=w[n+1],o=w[n+2];let a=!1;if(S)a=e>1.4*t&&e>1.4*o&&e>80;else if(T)a=o>1.4*t&&o>1.4*e&&o>80;else if(null!==C){const n=t-C.r,r=e-C.g,i=o-C.b;a=n*n+r*r+i*i<=F}if(a)continue}const o=.299*w[n]+.587*w[n+1]+.114*w[n+2];o<t&&(t=o),o>e&&(e=o)}I=t,L=e>t?e-t:255}const R=[],H=Q(e.invert),W=b&&e.charset.replace(/ /g,"")||e.charset,j=_(W),P=e.customText?null:J(W,H,e.brightness,e.contrast),O=u*M;for(let t=0;t<m;t++){const n=[];for(let o=0;o<f;o++){let a=0,r=0,i=0,s=0,h=0;for(let e=0;e<M;e++){const n=(t*M+e)*g;for(let t=0;t<u;t++){const e=4*(n+o*u+t),c=w[e],l=w[e+1],f=w[e+2],m=w[e+3];if(b){let t=!1;if(S)t=l>1.4*c&&l>1.4*f&&l>80;else if(T)t=f>1.4*c&&f>1.4*l&&f>80;else if(null!==C){const e=c-C.r,n=l-C.g,o=f-C.b;t=e*e+n*n+o*o<=F}if(t){h++;continue}}a+=c,r+=l,i+=f,s+=m}}if(b&&h>O/2){n.push({char:" ",r:0,g:0,b:0,a:0});continue}const c=O-h,l=c>0?a/c:0,m=c>0?r/c:0,d=c>0?i/c:0,p=c>0?s/c:0,x=.299*l+.587*m+.114*d,v=e.normalize?(x-I)/L*255:x,y=E(v,e.brightness,e.contrast),R=e.ditherStrength>0?A(y,o,t,e.ditherStrength):y,W=e.customText?k(R,e.customText,o,t,f,H):e.ditherStrength>0?X(R,j,H):P[Math.max(0,Math.min(255,0|v))];n.push({char:W,r:l,g:m,b:d,a:p,lum:R})}R.push(n)}return{frame:R,cols:f,rows:m}}function at(t,e,n,o){const a=t instanceof HTMLVideoElement?t.videoWidth:t.width,r=t instanceof HTMLVideoElement?t.videoHeight:t.height;if(0===a||0===r)return{rows:[],cols:0,rowCount:0};const i=e.charAspect,s=e.fontSize*e.charSpacing,h=e.fontSize/i*e.charSpacing,c=n||a,l=o||r,f=Math.floor(c/s),m=Math.floor(l/h);if(f<=0||m<=0)return{rows:[],cols:0,rowCount:0};const d=f,u=m,M=V(d,u),g=nt(e.sourceCrop,a,r),p=M.globalCompositeOperation;M.globalCompositeOperation="copy";try{M.drawImage(t,g.x,g.y,g.width,g.height,0,0,d,u)}finally{M.globalCompositeOperation=p}const x=M.getImageData(0,0,d,u).data,v=e.chromaKey,w=null!=v&&!1!==v,y=!0===v,b="blue-screen"===v;let S=null,k=0;!w||y||b||(S=$(v),k=(e.chromaKeyTolerance??60)**2);let T=0,C=255;if(e.normalize){let t=255,e=0;for(let n=0;n<x.length;n+=4){if(w){const t=x[n],e=x[n+1],o=x[n+2];let a=!1;if(y)a=e>1.4*t&&e>1.4*o&&e>80;else if(b)a=o>1.4*t&&o>1.4*e&&o>80;else if(null!==S){const n=t-S.r,r=e-S.g,i=o-S.b;a=n*n+r*r+i*i<=k}if(a)continue}const o=.299*x[n]+.587*x[n+1]+.114*x[n+2];o<t&&(t=o),o>e&&(e=o)}T=t,C=e>t?e-t:255}const F=Q(e.invert),I=w&&e.charset.replace(/ /g,"")||e.charset,L=_(I),R=e.customText?null:J(I,F,e.brightness,e.contrast),H=e.customText?_(e.customText):null,W="fullcolor"===e.colorMode?new Uint8ClampedArray(f*m*4):void 0,j=[];for(let t=0;t<m;t++){let n="";for(let o=0;o<f;o++){const a=4*(t*d+o),r=a,i=x[a],s=x[a+1],h=x[a+2],c=x[a+3];if(w){let t=!1;if(y)t=s>1.4*i&&s>1.4*h&&s>80;else if(b)t=h>1.4*i&&h>1.4*s&&h>80;else if(null!==S){const e=i-S.r,n=s-S.g,o=h-S.b;t=e*e+n*n+o*o<=k}if(t){n+=" ",W&&(W[r]=0,W[r+1]=0,W[r+2]=0,W[r+3]=0);continue}}W&&(W[r]=i,W[r+1]=s,W[r+2]=h,W[r+3]=c);const l=.299*i+.587*s+.114*h,m=e.normalize?(l-T)/C*255:l,u=e.ditherStrength>0||H?E(m,e.brightness,e.contrast):m,M=e.ditherStrength>0?A(u,o,t,e.ditherStrength):u;if(H){n+=(F?1-M/255:M/255)<.12?" ":H[(t*f+o)%H.length]}else e.ditherStrength<=0?n+=R[Math.max(0,Math.min(255,0|m))]:n+=X(M,L,F)}j.push(n)}return{rows:j,cols:f,rowCount:m,colors:W}}function rt(t,e,n,o,a){if(0===e.rows.length)return;const r=t.canvas,i=Boolean(n.chromaKey)||e.rows.some(t=>t.includes(" "));i||(K.delete(t),t.clearRect(0,0,o,a),t.fillStyle=j(r)?"#0a0a0a":"#faf9f7",t.fillRect(0,0,o,a));const s=tt(n.accentColor),h=parseInt(s.substring(0,2),16),c=parseInt(s.substring(2,4),16),l=parseInt(s.substring(4,6),16),f=o/e.cols,m=a/e.rowCount,d=.9*Math.min(f/.55,m),u=e.colors;if("fullcolor"===n.colorMode&&u){K.delete(t),t.clearRect(0,0,o,a),t.font=`${d}px "JetBrains Mono", monospace`,t.textAlign="left",t.textBaseline="middle",t.globalAlpha=1;let n="";for(let o=0;o<e.rows.length;o++){const a=G(e.rows[o]);let r=0;for(;r<e.cols;){for(;r<e.cols&&" "===a[r];)r++;if(r>=e.cols)break;const i=r,s=4*(o*e.cols+r),h=240&u[s],c=240&u[s+1],l=240&u[s+2];for(r++;r<e.cols&&" "!==a[r];){const t=4*(o*e.cols+r);if((240&u[t])!==h||(240&u[t+1])!==c||(240&u[t+2])!==l)break;r++}const d=`rgb(${h},${c},${l})`;d!==n&&(t.fillStyle=d,n=d),t.fillText(a.slice(i,r).join(""),i*f+.5*f,o*m+.5*m)}}return void(t.globalAlpha=1)}t.font=`${d}px "JetBrains Mono", monospace`,t.textAlign="left",t.textBaseline="middle";const M="matrix"===n.colorMode?"rgb(0,255,0)":"grayscale"===n.colorMode?j(r)?"rgb(230,230,230)":"rgb(24,24,24)":`rgb(${h},${c},${l})`;t.fillStyle=M,t.globalAlpha=1;const g=K.get(t),p=i&&g&&g.cols===e.cols&&g.rowCount===e.rowCount&&g.canvasWidth===o&&g.canvasHeight===a&&g.fillStyle===M;p||t.clearRect(0,0,o,a);for(let n=0;n<e.rows.length;n++){const a=e.rows[n];p&&g.rows[n]===a||(p&&t.clearRect(0,n*m,o,m+1),0!==a.trim().length&&t.fillText(a,.5*f,n*m+.5*m))}K.set(t,{rows:e.rows.slice(),cols:e.cols,rowCount:e.rowCount,canvasWidth:o,canvasHeight:a,fillStyle:M}),t.globalAlpha=1}async function it(t,e,n,o,a=12,r=10,i,s=0){const h=Math.min(t.duration-s,r),c=Math.ceil(h*a),l=[];let f=0,m=0;for(let r=0;r<c;r++){const d=s+r/a;if(d>s+h)break;t.currentTime=d,await new Promise(e=>{const n=()=>{t.removeEventListener("seeked",n),e()};t.addEventListener("seeked",n)});const u=ot(t,e,n,o);l.push(u.frame),f=u.cols,m=u.rows,i?.((r+1)/c)}return{frames:l,cols:f,rows:m,fps:a}}async function st(t,e,n,o,a=12,r=10,i,s=0){const h=Math.min(t.duration-s,r),c=Math.ceil(h*a),l=[];let f=0,m=0;for(let r=0;r<c;r++){const d=s+r/a;if(d>s+h)break;t.currentTime=d,await new Promise(e=>{const n=()=>{t.removeEventListener("seeked",n),e()};t.addEventListener("seeked",n)});const u=at(t,e,n,o);l.push(u),f=u.cols,m=u.rowCount,i?.((r+1)/c)}return{frames:l,cols:f,rows:m,fps:a}}async function ht(t,e,n,o,a){const{parseGIF:r,decompressFrames:i}=await import("gifuct-js"),s=r(t),h=i(s,!0);if(0===h.length)return{frames:[],cols:0,rows:0,fps:10};const c=h[0].dims.width,l=h[0].dims.height,f=s.lsd?.width||c,m=s.lsd?.height||l,d=document.createElement("canvas");d.width=f,d.height=m;const u=d.getContext("2d"),M=document.createElement("canvas");M.width=f,M.height=m;const g=M.getContext("2d"),p=document.createElement("canvas"),x=p.getContext("2d"),v=[];let w=0,y=0,b=0;for(const t of h)b+=t.delay||100;const S=b/h.length,E=Math.round(Math.min(30,Math.max(5,1e3/S))),k=Math.min(h.length,300);for(let t=0;t<k;t++){const r=h[t],{dims:i,patch:s,disposalType:c}=r;3===c&&(g.clearRect(0,0,f,m),g.drawImage(d,0,0)),p.width!==i.width&&(p.width=i.width),p.height!==i.height&&(p.height=i.height);const l=new ImageData(new Uint8ClampedArray(s.buffer),i.width,i.height);x.putImageData(l,0,0),u.drawImage(p,i.left||0,i.top||0);const b=ot(d,e,n,o);v.push(b.frame),w=b.cols,y=b.rows,2===c?u.clearRect(i.left||0,i.top||0,i.width,i.height):3===c&&(u.clearRect(0,0,f,m),u.drawImage(M,0,0)),a?.((t+1)/k)}return{frames:v,cols:w,rows:y,fps:E}}var ct=new WeakMap,lt=new WeakMap,ft=new WeakMap;function mt(t,e,n,o,a,r=0,i){if(!e.length||!e[0].length||o<=0||a<=0)return;let s=null;if(n.hoverStrength>0){let e=ct.get(t);e||(e={x:.5,y:.5,intensity:0,time:-1,emittedAt:-1,points:[]},ct.set(t,e)),s=function(t,e,n){const o=t.time<0?1/60:Math.max(0,Math.min(.1,(n-t.time)/1e3));t.time=n;const a=t.intensity<.003,r=t.x,i=t.y;if(e){a&&(t.x=e.x,t.y=e.y);const n=1-Math.exp(-o/.055);t.x+=(e.x-t.x)*n,t.y+=(e.y-t.y)*n}t.intensity+=((e?.intensity??(e?1:0))-t.intensity)*(1-Math.exp(-o/(e?.09:.18)));const s=Math.exp(-o/.22);for(const e of t.points)e.intensity*=s;for(;t.points.length&&t.points[0].intensity<.01;)t.points.shift();return e&&!a&&n-t.emittedAt>=24&&Math.hypot(t.x-r,t.y-i)>5e-4&&(t.points.push({x:t.x,y:t.y,intensity:t.intensity,vx:Math.max(-1,Math.min(1,(t.x-r)/Math.max(o,.001))),vy:Math.max(-1,Math.min(1,(t.y-i)/Math.max(o,.001)))}),t.points.length>12&&t.points.shift(),t.emittedAt=n),!e&&t.intensity<.003&&!t.points.length?(t.intensity=0,null):{x:t.x,y:t.y,intensity:t.intensity,trail:t.points}}(e,i??null,performance.now())}else ct.delete(t);if("none"!==n.animationStyle||n.charsetFrames?.length||n.hoverStrength<=0)return ft.delete(t),void dt(t,e,n,o,a,r,s);const h=lt.get(t);if(h?.frame!==e)return lt.set(t,{frame:e,since:performance.now()}),ft.delete(t),void dt(t,e,n,o,a,r,s);if(performance.now()-h.since<100)return void dt(t,e,n,o,a,r,s);const c=t.getTransform();if(c.b||c.c||c.a<=0||c.d<=0)return void dt(t,e,n,o,a,r,s);if(!s||(s.intensity??0)<.003)return void dt(t,e,n,o,a,r,null);const l=j(t.canvas),f={...n,accentColor:"#"+tt(n.accentColor)},m=JSON.stringify([f,o,a,c.a,c.d,l,void 0!==document.fonts?document.fonts.status:"loaded"]);let d=ft.get(t);if(!d||d.frame!==e||d.key!==m){const n=d?.canvas??document.createElement("canvas");n.width=Math.ceil(o*c.a),n.height=Math.ceil(a*c.d);const r=n.getContext("2d");r.setTransform(c.a,0,0,c.d,0,0),dt(r,e,f,o,a,0,null,void 0,l),d={frame:e,key:m,canvas:n},ft.set(t,d)}if(t.clearRect(0,0,o,a),t.drawImage(d.canvas,0,0,o,a),!s||(s.intensity??0)<.003)return;const u=e.length,M=e[0].length,g=.08+.35*n.hoverRadius+.04*n.hoverStrength,p="trail"===n.hoverEffect?[s,...s.trail??[]]:[s];let x=1,v=1,w=0,y=0;for(const t of p)x=Math.min(x,t.x-g),w=Math.max(w,t.x+g),v=Math.min(v,t.y-g),y=Math.max(y,t.y+g);if("glitchText"===n.hoverEffect){const t=n.hoverText,e=Math.max(1,...(Array.isArray(t)?t:[t]).map(t=>t.length));x=Math.min(x,s.x-e/M),w=Math.max(w,s.x+e/M)}const b=Math.ceil(5+4*n.hoverStrength),S={x:Math.max(0,Math.floor(x*M)-b),y:Math.max(0,Math.floor(v*u)-b),right:Math.min(M,Math.ceil(w*M)+b),bottom:Math.min(u,Math.ceil(y*u)+b)};t.save(),t.beginPath(),t.rect(S.x*o/M,S.y*a/u,(S.right-S.x)*o/M,(S.bottom-S.y)*a/u),t.clip(),dt(t,e,f,o,a,r,s,S,l),t.restore()}function dt(t,e,h,c,l,f=0,m,d,u){const M=e.length;if(0===M)return;const g=e[0].length;t.clearRect(0,0,c,l);let p=!1;const x=Math.max(1,M>>2),v=Math.max(1,g>>2);t:for(let t=0;t<M;t+=x){const n=e[t];for(let t=0;t<g;t+=v)if(n[t].a<200){p=!0;break t}}const w=t.canvas,y=u??j(w);p||(t.fillStyle=y?"#0a0a0a":"#faf9f7",t.fillRect(0,0,c,l));const S=c/g,E=l/M,k=m?.intensity??1,T=!!(m&&h.hoverStrength>0&&k>.005),A="#"+(Z(h.hoverColor||"#ffffff")??"ffffff"),C=parseInt(A.slice(1,3),16),F=parseInt(A.slice(3,5),16),L=parseInt(A.slice(5,7),16),H=tt(h.accentColor),W=parseInt(H.substring(0,2),16),$=parseInt(H.substring(2,4),16),P=parseInt(H.substring(4,6),16),O=h.hoverRadius;let q=0,D=g,U=0,V=M,B=0,N=0;if(T&&m){B=m.x,N=m.y;const t=.08+.35*O+.04*h.hoverStrength;q=Math.max(0,Math.floor((B-t)*g)-1),D=Math.min(g,Math.ceil((B+t)*g)+1),U=Math.max(0,Math.floor((N-t)*M)-1),V=Math.min(M,Math.ceil((N+t)*M)+1)}if(T&&"trail"===h.hoverEffect)for(const t of m?.trail??[]){const e=.08+.35*O+.04*h.hoverStrength;q=Math.min(q,Math.max(0,Math.floor((t.x-e)*g)-1)),D=Math.max(D,Math.min(g,Math.ceil((t.x+e)*g)+1)),U=Math.min(U,Math.max(0,Math.floor((t.y-e)*M)-1)),V=Math.max(V,Math.min(M,Math.ceil((t.y+e)*M)+1))}const K=h.animationStyle,Y=h.animationSpeed,G=function(t){const e=t&&Object.prototype.hasOwnProperty.call(n,t)?n[t]:t;return o.find(t=>t.value===e||t.mode===e)?.mode??"none"}(K),J="none"===G,et=[0,0,0,1],nt=J?void 0:b(e),ot=[0,0],at="relight"===(it=G)||"sheen"===it||"glow"===it||"shimmer"===it||"mist"===it,rt={char:" ",r:0,g:0,b:0,a:0};var it;const st=(t,n,o,h)=>{!function(t,e,n,o,s,h=.5,c,l=0){if(s[0]=s[1]=s[2]=0,s[3]=1,"none"===t)return s;h=a(h);const f=c?c[l]:h,m=c?c[l+1]:.5+.5*a(1-2*Math.hypot(e-.5,n-.55)),d=c?c[l+2]:r(.55,1,h)**2,u=c?c[l+3]:.5,M=c?c[l+4]:0,g=c?c[l+5]:0,p=o*Math.PI/6,x=(o%12+12)%12,v=r(0,.12,Math.min(e,1-e,n,1-n));if("relight"===t){const t=p+.6,o=Math.cos(t),a=Math.sin(t),i=Math.max(-1,Math.min(1,M*o+g*a))+.35*(o*(e-.5)+a*(n-.5));s[2]=.2*i*(.3+.7*r(.04,.3,f)*(1-.6*r(.82,1,h)))}else if("sheen"===t){const t=1.9*r(0,8,x)-.35,o=(.75*e+.45*n)/1.2+.05*(.75*M+.45*g),a=Math.exp(-(((o-t)/.12)**2));s[2]=a*r(.3,.8,f)*(1-.5*r(.9,1,h))*.45}else if("glow"===t){const t=.5-.5*Math.cos(p),e=1-.8*t;s[2]=.2*r(e-.3,e+.02,d)*Math.sqrt(d)*(1-.65*h)+.05*t*r(.6,.95,h)}else if("shimmer"===t){const t=i(Math.floor(160*e),Math.floor(100*n))*Math.PI*2,o=Math.pow(.5+.5*Math.cos(2*p+t),28);s[2]=o*r(.5,.88,h)*(.35+.65*r(.1,.55,u))*.42}else if("parallax"===t){const t=m-.45;s[0]=16*t*Math.sin(p)*v,s[1]=7*t*Math.sin(2*p)*v}else if("push"===t){const t=.045*(.5-.5*Math.cos(p))*(.7+.6*m)*960,o=c?c[l+6]:.5,a=c?c[l+7]:.5;s[0]=(e-o)*t,s[1]=(n-a)*t}else if("focus"===t){const t=Math.sin(p),e=t*t*r(.35,.85,t>=0?1-m:m);s[2]=(f-h)*e*.75}else if("mist"===t){const t=Math.pow(1-m,1.5)*(1-.6*u),o=.5*Math.sin(4.1*e-p+.9*Math.sin(3.3*n+p))+.3*Math.sin(7.3*e+2.1*n-2*p+1.1*Math.sin(2.7*e-5.1*n+p))+.2*Math.sin(5.7*n-1.9*e+p);s[2]=r(-.3,.9,o)*t*.16*(1-.55*h)}else if("current"===t){const t=c?.[l+8]??0,o=c?.[l+9]??0,a=c?.[l+10]??0,f=r(0,.06,Math.min(e,1-e,n,1-n)),d=c?0:(1-.4*u)*(1-.8*m)*v,M=t=>14*n-t+1.5*Math.sin(3*e+t),g=t=>16*n+2*e-t,x=t=>29*n-3*e-2*t,w=t=>1.7*e+2.3*n-t,y=t=>26*n+1.5*Math.sin(40*e)-2*t;s[0]=7*(Math.sin(M(p))-Math.sin(M(0))+.43*(Math.sin(5*e-3*n+p)-Math.sin(5*e-3*n)))*d+(3.5*(Math.sin(g(p))-Math.sin(g(0)))+1.5*(Math.sin(x(p))-Math.sin(x(0))))*t*f+5*(Math.sin(w(p))-Math.sin(w(0)))*o*f,s[1]=2*(Math.sin(11*e+p)-Math.sin(11*e))*d+.8*(Math.cos(g(p))-Math.cos(g(0)))*t*f+12*(Math.sin(y(p))-Math.sin(y(0)))*a*f;const b=Math.pow(.5+.5*Math.cos(2*p+9*e-4*n+6.2831853*i(Math.floor(160*e),Math.floor(100*n))),24)-Math.pow(.5+.5*Math.cos(9*e-4*n+6.2831853*i(Math.floor(160*e),Math.floor(100*n))),24);s[2]=.03*(Math.cos(M(p))-Math.cos(M(0)))*d+(b*r(.5,.85,h)*.3+.025*(Math.cos(g(p))-Math.cos(g(0))))*t*f+.08*(Math.cos(y(p))-Math.cos(y(0)))*a*f}else if("develop"===t){const t=r(7,8.5,x),o=a((x-8.5)/3.5),c=x<8.5?1-t:r(0,1,(1.45*o-(1-h)+.06*(i(Math.floor(160*e),Math.floor(100*n))-.5))/.3);s[2]=.3*-(1-c),s[3]=1-.9*(1-c)}}(G,t/g,n/M,f*Y,et,(.299*o.r+.587*o.g+.114*o.b)/255,nt,11*(n*g+t));let c=o;(et[0]||et[1])&&(!function(t,e,n,o,a,r){r[0]=s(Math.max(0,Math.min(o-1,e-t[0]/960*o))),r[1]=s(Math.max(0,Math.min(a-1,n-t[1]/960*a)))}(et,t,n,g,M,ot),c=e[Math.round(ot[1])][Math.round(ot[0])]);const l=255*et[2];return Math.abs(l)<.5&&1===et[3]?c:(rt.r=Math.max(0,Math.min(255,c.r+l)),rt.g=Math.max(0,Math.min(255,c.g+l)),rt.b=Math.max(0,Math.min(255,c.b+l)),rt.a=c.a*et[3],rt.char=c.char,rt.lum=c.lum,null!=c.lum&&(rt.lum=Math.max(0,Math.min(255,c.lum+l*(at?.45:1))),h&&Math.abs(l)>2&&(rt.char=X(rt.lum,h,mt))),rt)},ht=h.hoverStrength,ct=h.hoverEffect,lt=O,ft=h.hoverShape||"circle",mt=Q(h.invert,w),dt=h.colorMode,ut=2*Math.PI,Mt=1/g,gt=1/M;let pt="",xt=-1;if("dots"===h.renderMode){const n=.5*Math.min(S,E)*h.dotSizeRatio;for(let o=d?.y??0;o<(d?.bottom??M);o++){const a=e[o];for(let e=d?.x??0;e<(d?.right??g);e++){const r=J?a[e]:st(e,o,a[e]);if(r.a<10)continue;const i=.00392156863*(.299*r.r+.587*r.g+.114*r.b),s=mt?1-i:i;if(s<.02)continue;let h=1,f=0,d=0,u=0,M=0;if(T&&e>=q&&e<=D&&o>=U&&o<=V){const t=z(e*Mt,o*gt,B,N,k,ht,S,E,ct,lt,ft,m?.trail,c/l);h=t.scale,f=t.offsetX,d=t.offsetY,u=t.glow,M=t.colorBlend}const g=n*s*h;if(g<.3)continue;const p=e*S+.5*S+f,x=o*E+.5*E+d;let v;if(M>0){const t=R(r,dt,W,$,P,mt);v=`rgb(${Math.min(255,t[0]+(C-t[0])*M|0)},${Math.min(255,t[1]+(F-t[1])*M|0)},${Math.min(255,t[2]+(L-t[2])*M|0)})`}else v=I(r,dt,W,$,P,mt);const w=Math.min(1,.00392156863*r.a*(1+u));if(w!==xt&&(t.globalAlpha=w,xt=w),v!==pt&&(t.fillStyle=v,pt=v),g<=3){const e=2*g;t.fillRect(p-g,x-g,e,e)}else t.beginPath(),t.arc(p,x,g,0,ut),t.fill()}}}else{const n=.55,o=.9*Math.min(S/n,E);{const e=/\p{Extended_Pictographic}/u.test(h.customText||h.charset);t.font=e?`${o}px "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twemoji Mozilla", sans-serif`:`${o}px "JetBrains Mono", monospace`,t.textAlign="center",t.textBaseline="middle"}const a=h.charsetFrames,r=!!a?.length,i=r?a[Math.floor(Math.max(0,f)*(h.charsetFps??2))%a.length]:h.charset,s=t.getTransform();if(!T&&J&&!r&&"accent"===dt&&!d&&h.hoverStrength<=0&&!/\p{Extended_Pictographic}/u.test(h.customText||h.charset)&&"letterSpacing"in t&&/^[\x20-\x7e]*$/.test(h.customText||h.charset)&&e.every(t=>t.every(t=>t.a<10||255===t.a&&1===t.char.length&&/^[\x20-\x7e]$/.test(t.char)))){const n=t.letterSpacing;t.letterSpacing="0px";const o=t.measureText("M").width;t.letterSpacing=S-o+"px",t.fillStyle=`rgb(${W},${$},${P})`,t.globalAlpha=1,t.textAlign="left";for(let n=0;n<M;n++){const a=e[n];let r="";for(let t=0;t<g;t++){const e=a[t];r+=e.a<10?" ":e.char}0!==r.trim().length&&t.fillText(r,.5*(S-o),n*E+.5*E)}return t.letterSpacing=n,t.textAlign="center",void(t.globalAlpha=1)}const u="glitchText"===ct&&T,p="!@#$%^&*<>{}[]|/\\~`0123456789",x=p.length;let v="",w=0,y=0,b=0,A=0,H=0,j=0;if(u){const t=h.hoverText??"ASCIIFY";if(y=Math.round(B*g),b=Math.round(N*M),Array.isArray(t)){const e=t.filter(t=>t.length>0);0===e.length&&e.push("ASCIIFY");v=e[((7*Math.floor(y/Math.max(1,Math.ceil(g/5)))+13*Math.floor(b/Math.max(1,Math.ceil(M/3))))%e.length+e.length)%e.length]}else v=t||"ASCIIFY";w=v.length,A=Math.max(3,Math.min(12,Math.round(M*O*.6)));const e=Math.floor(A/2);H=Math.max(0,b-e),H+A>M&&(H=Math.max(0,M-A)),j=y-Math.floor(w/2)}for(let n=d?.y??0;n<(d?.bottom??M);n++){const o=e[n];for(let a=d?.x??0;a<(d?.right??g);a++){const d=J?o[a]:st(a,n,o[a],h.customText?void 0:_(i));if(d.a<10)continue;let O=r&&null!=d.lum?X(d.lum,_(i),mt):d.char;if(" "===O)continue;let K=1,Y=0,G=0,Q=0,Z=0;if(T&&!u&&a>=q&&a<=D&&n>=U&&n<=V){const t=z(a*Mt,n*gt,B,N,k,ht,S,E,ct,lt,ft,m?.trail,c/l);if(K=t.scale,Y=t.offsetX,G=t.offsetY,Q=t.glow,Z=t.colorBlend,"trail"===ct&&t.proximity>0){const o=Math.max(0,Math.min(g-1,Math.round(a-t.offsetX/S))),r=Math.max(0,Math.min(M-1,Math.round(n-t.offsetY/E))),s=e[r][o],h=s.lum??.299*s.r+.587*s.g+.114*s.b;O=X(Math.min(255,h+t.proximity*ht*65),_(i),mt)}}if(u&&n>=H&&n<H+A){const t=a-j;if(t>=0&&t<w){const e=v[t],o=Math.abs(n-b)/Math.max(1,.5*A),r=Math.abs(a-y)/Math.max(1,w),i=Math.max(o,r),s=Math.max(0,Math.min(1,1-.9*i)),h=43758.5453*Math.sin(127.1*a+311.7*n+43758.5453*Math.floor(12*f));O=Math.abs(h-Math.floor(h))<s?e:p[Math.abs(Math.floor(97*h))%x],Q=.3+.7*s,Z=.3+.65*s}}const tt=a*S+.5*S+Y,et=n*E+.5*E+G;let nt;if(Z>0){const t=R(d,dt,W,$,P,mt);nt=`rgb(${Math.min(255,t[0]+(C-t[0])*Z|0)},${Math.min(255,t[1]+(F-t[1])*Z|0)},${Math.min(255,t[2]+(L-t[2])*Z|0)})`}else nt=I(d,dt,W,$,P,mt);const ot=Math.min(1,.00392156863*d.a*(1+Q));ot!==xt&&(t.globalAlpha=ot,xt=ot),nt!==pt&&(t.fillStyle=nt,pt=nt),1!==K?(t.translate(tt,et),t.scale(K,K),t.fillText(O,0,0),t.setTransform(s)):t.fillText(O,tt,et)}}}t.globalAlpha=1}function ut(t="classic"){if("classic"!==t)throw new RangeError(`Art preset "${String(t)}" was removed in 4.1. Use a StudioStyle with asciify-engine/studio, or supply options.charset directly.`);return{artStyle:"classic"}}function Mt(t){return Math.max(0,Math.min(1,t))}function gt(t){return"string"==typeof t?document.querySelector(t):t instanceof HTMLElement?t:null}function pt(t){return"ascii"===t.renderMode&&"none"===t.animationStyle&&t.hoverStrength<=0&&!t.charsetFrames?.length}function xt(t,e={}){const n=Mt(t),o=Mt(n*(void 0===e.speed?1:Math.max(.001,e.speed)));return Mt(e.ease?e.ease(o):o)}function vt(t,e,n={}){if(!Number.isFinite(t.duration)||t.duration<=0)return;const o=n.from??0,a=n.to??t.duration,r=Math.max(o,Math.min(a,t.duration)),i=xt(e,n),s=o+(r-o)*i;t.currentTime=Math.min(Math.max(o,s),Math.max(o,r-.04)),n.onUpdate?.(i,t)}function wt(t,e){return Math.abs(t.currentTime-e)<1/240?yt(t):new Promise(n=>{const o=()=>{t.removeEventListener("seeked",o),n()};t.addEventListener("seeked",o,{once:!0});const a=t.fastSeek;a?a.call(t,e):t.currentTime=e})}function yt(t){const e=t.requestVideoFrameCallback;return new Promise(e?n=>{let o=!1;const a=()=>{o||(o=!0,n())};e.call(t,a),window.setTimeout(a,32)}:t=>requestAnimationFrame(()=>t()))}function bt(t,e={}){const n=gt(e.trigger)??t;t.pause();const o=e.gsap,a=e.ScrollTrigger??o?.ScrollTrigger;if(o&&a?.create){o.registerPlugin?.(a);const r=a.create({trigger:n,start:e.start??"top bottom",end:e.end??"bottom top",scrub:e.scrub??!0,onUpdate:n=>vt(t,n.progress,e)});return()=>r.kill?.()}return function(t,e,n){let o=0;const a=()=>{o=0;const a=e.getBoundingClientRect(),r=window.innerHeight||document.documentElement.clientHeight,i=a.height+r,s=i>0?Mt((r-a.top)/i):0;vt(t,s,n)},r=()=>{o||(o=requestAnimationFrame(a))};return window.addEventListener("scroll",r,{passive:!0}),window.addEventListener("resize",r),r(),()=>{window.removeEventListener("scroll",r),window.removeEventListener("resize",r),o&&cancelAnimationFrame(o)}}(t,n,e)}function St(t,e,n){const o=e.gsap,a=e.ScrollTrigger??o?.ScrollTrigger;if(o&&a?.create){o.registerPlugin?.(a);const r=a.create({trigger:t,start:e.start??"top bottom",end:e.end??"bottom top",scrub:e.scrub??!0,onUpdate:t=>n(t.progress)});return()=>r.kill?.()}return function(t,e){let n=0;const o=()=>{n=0;const o=t.getBoundingClientRect(),a=window.innerHeight||document.documentElement.clientHeight,r=o.height+a,i=r>0?Mt((a-o.top)/r):0;e(i)},a=()=>{n||(n=requestAnimationFrame(o))};return window.addEventListener("scroll",a,{passive:!0}),window.addEventListener("resize",a),a(),()=>{window.removeEventListener("scroll",a),window.removeEventListener("resize",a),n&&cancelAnimationFrame(n)}}(t,n)}function Et(t,e,n){if(!t||!e||!n.sourceCrop)return{w:t,h:e};const o=nt(n.sourceCrop,t,e);return{w:Math.max(1,Math.round(o.width)),h:Math.max(1,Math.round(o.height))}}function kt(t,e,n,o){const a=o.chromaKey;if(null==a||!1===a)return!1;if(!0===a)return e>1.4*t&&e>1.4*n&&e>80;if("blue-screen"===a)return n>1.4*t&&n>1.4*e&&n>80;const r=$(a),i=(o.chromaKeyTolerance??60)**2,s=t-r.r,h=e-r.g,c=n-r.b;return s*s+h*h+c*c<=i}function Tt(t,e,n){if(!e.chromaKey||!e.sourceCrop||"off"===e.chromaKeyTrimMode)return e;const o=t instanceof HTMLVideoElement?t.videoWidth:t.width,a=t instanceof HTMLVideoElement?t.videoHeight:t.height;if(!o||!a)return e;const r=nt(e.sourceCrop,o,a),i=Math.min(360,Math.max(1,Math.round(r.width))),s=Math.max(1,Math.round(i*(r.height/r.width))),{ctx:h}=S(i,s);h.drawImage(t,r.x,r.y,r.width,r.height,0,0,i,s);const c=h.getImageData(0,0,i,s).data,l=Math.max(0,Math.min(255,e.chromaKeyTrimLuminanceThreshold??0));let f=i,m=s,d=-1,u=-1;for(let t=0;t<s;t++)for(let n=0;n<i;n++){const o=4*(t*i+n),a=c[o+3],r=c[o],s=c[o+1],h=c[o+2];a<=8||.2126*r+.7152*s+.0722*h<=l||kt(r,s,h,e)||(n<f&&(f=n),t<m&&(m=t),n>d&&(d=n),t>u&&(u=t))}if(d<f||u<m)return e;const M=Math.max(0,Math.min(.25,e.chromaKeyTrimPadding??.002)),g=Math.round(i*M),p=Math.round(s*M);f=Math.max(0,f-g),m=Math.max(0,m-p),d=Math.min(i-1,d+g),u=Math.min(s-1,u+p);const x=function(t,e,n,o,a){const r=a&&Number.isFinite(a)&&a>0?a:null;if(!r)return t;const i=e.x,s=e.y,h=e.x+e.width,c=e.y+e.height,l=Math.max(i,t.left),f=Math.max(s,t.top),m=Math.min(h,n-t.right),d=Math.min(c,o-t.bottom),u=Math.max(1,m-l),M=Math.max(1,d-f),g=l+u/2,p=f+M/2;let x=u,v=M;x/v<r?x=v*r:v=x/r;x>e.width&&(x=e.width,v=Math.max(M,Math.min(e.height,x/r)));v>e.height&&(v=e.height,x=Math.max(u,Math.min(e.width,v*r)));let w=g-x/2,y=p-v/2;return w=Math.max(i,Math.min(h-x,w)),y=Math.max(s,Math.min(c-v,y)),{left:w,top:y,right:n-(w+x),bottom:o-(y+v)}}({left:r.x+f/i*r.width,top:r.y+m/s*r.height,right:o-(r.x+(d+1)/i*r.width),bottom:a-(r.y+(u+1)/s*r.height)},{x:r.x,y:r.y,width:r.width,height:r.height},o,a,n);return{...e,sourceCrop:{unit:"pixel",...x,preserveAspect:!1}}}function At(t){const e=t.sourceCrop;return e&&"pixel"===e.unit?void 0===e.left||void 0===e.top||void 0===e.right||void 0===e.bottom?null:{left:e.left,top:e.top,right:e.right,bottom:e.bottom}:null}async function Ct(t,e,n,o,a){if(!e.chromaKey||!e.sourceCrop||"range"!==e.chromaKeyTrimMode)return e;const r=t.currentTime,i=function(t,e,n,o){const a=!0===o?{}:o||{},r=Math.max(0,a.from??e),i=a.to??n??(Number.isFinite(t.duration)?t.duration:r),s=Math.max(r,i-.04),h=Math.max(0,s-r),c=h>.1?[r,r+.25*h,r+.5*h,r+.75*h,s]:[r];return Array.from(new Set(c.map(t=>Math.max(0,Number(t.toFixed(3))))))}(t,n,o,a);let s=null;for(const n of i){await wt(t,n),await yt(t);const o=At(Tt(t,e));o&&(s=s?{left:Math.min(s.left,o.left),top:Math.min(s.top,o.top),right:Math.min(s.right,o.right),bottom:Math.min(s.bottom,o.bottom)}:o)}return await wt(t,r),await yt(t),s?{...e,sourceCrop:{unit:"pixel",...s,preserveAspect:!0}}:e}function Ft(t,e,n=2048){return It({sourceWidth:t,sourceHeight:e,maxRenderDimension:n})}function It({sourceWidth:t,sourceHeight:e,cssWidth:n=0,cssHeight:o=0,maxRenderDimension:a=2048}){const r=Math.max(1,t),i=Math.max(1,e),s=r/i,h=Math.max(1,a),c=Math.min(1,h/Math.max(r,i)),l=Math.max(r,i)*c,f=Math.max(0,n,o),m=Math.min(h,Math.max(l,f));return s>=1?{renderW:Math.round(m),renderH:Math.round(m/s)}:{renderW:Math.round(m*s),renderH:Math.round(m)}}function Lt(t,e,n,o){if(void 0===t)return;if("number"==typeof t)return t;const a=t.trim();if(a.endsWith("%")){const t=Number.parseFloat(a)/100;return Number.isFinite(t)?e*t:void 0}if(a.endsWith("px")){const t=Number.parseFloat(a);return Number.isFinite(t)?t:void 0}if(a.endsWith("vw")){const t=Number.parseFloat(a)/100;return Number.isFinite(t)?n*t:void 0}if(a.endsWith("vh")){const t=Number.parseFloat(a)/100;return Number.isFinite(t)?o*t:void 0}}function Rt(t,e,n,o,a,r=2048,i={}){const{width:s,height:h}=e.getBoundingClientRect();if(!s||!h)return{renderW:0,renderH:0,dpr:1};const c="undefined"!=typeof window?window.innerWidth:s,l="undefined"!=typeof window?window.innerHeight:h,f=Lt(i.width,s,c,l)??s,m=Lt(i.height,h,c,l)??h,d=function(t,e,n,o,a){const r=t=>{const n=Lt(t,e,o,a);return n&&n>0?n:0},i=t=>{const e=Lt(t,n,o,a);return e&&e>0?e:0};return void 0===t?{x:0,y:0}:"number"==typeof t||"string"==typeof t?{x:r(t),y:i(t)}:{x:r(t.x),y:i(t.y)}}(i.bleed,s,h,c,l),u=f+2*d.x,M=m+2*d.y,{cssW:g,cssH:p}=function(t,e,n,o="contain"){if("fill"===o)return{cssW:t,cssH:e};let a=t,r=a/n;const i="cover"===o,s=r>e;return(i&&!s||!i&&s)&&(r=e,a=r*n),"scale-down"===o&&(a=Math.min(a,t),r=Math.min(r,e)),{cssW:Math.round(a),cssH:Math.round(r)}}(u,M,n,i.objectFit??"contain"),x="undefined"!=typeof window&&window.devicePixelRatio||1;let v,w;o&&a?({renderW:v,renderH:w}=It({sourceWidth:o,sourceHeight:a,cssWidth:g,cssHeight:p,maxRenderDimension:r})):(v=g,w=p);const y=8e6,b=v*x*w*x>y?Math.sqrt(y/(v*w)):x;return t.width=Math.round(v*b),t.height=Math.round(w*b),t.style.width=`${g}px`,t.style.height=`${p}px`,{renderW:v,renderH:w,dpr:b}}async function Ht(t,n,{fontSize:o,artStyle:a="classic",options:r={},fitTo:i,objectFit:s,objectPosition:h,scale:c,width:l,height:f,bleed:m,preExtract:d=!1,fps:u,maxRenderDimension:M=2048,trim:g,scroll:p,maxCachedFrames:x=90,onReady:v,onFrame:w}={}){const y=g?.start??0,b=g?.end,S=o??r.fontSize??10;let E={...e,...ut(a),artStyle:a,...r,fontSize:S};const k=n.getContext("2d");if(!k)throw new Error("asciifyVideo: could not get 2d context from canvas.");const T="string"==typeof i?document.querySelector(i):i instanceof HTMLElement?i:null,A={objectFit:s,objectPosition:h,scale:c,width:l,height:f,bleed:m},C=function(t,e){var n;if(!function(t){return void 0!==t.objectFit||void 0!==t.objectPosition||void 0!==t.scale||void 0!==t.width||void 0!==t.height||void 0!==t.bleed}(e))return()=>{};const o={width:t.style.width,height:t.style.height,objectFit:t.style.objectFit,objectPosition:t.style.objectPosition,maxWidth:t.style.maxWidth,maxHeight:t.style.maxHeight,transformOrigin:t.style.transformOrigin,scale:t.style.getPropertyValue("scale")};if(e.objectFit&&(t.style.objectFit=e.objectFit),e.objectPosition&&(t.style.objectPosition=e.objectPosition,t.style.transformOrigin=e.objectPosition),void 0===e.scale&&void 0===e.bleed||(t.style.maxWidth="none",t.style.maxHeight="none"),void 0!==e.scale){const o=Number.isFinite(e.scale)&&e.scale>0?e.scale:1;t.style.setProperty("scale",String(o)),(n=t.style).transformOrigin||(n.transformOrigin=e.objectPosition??"center center")}return()=>{t.style.width=o.width,t.style.height=o.height,t.style.objectFit=o.objectFit,t.style.objectPosition=o.objectPosition,t.style.maxWidth=o.maxWidth,t.style.maxHeight=o.maxHeight,t.style.transformOrigin=o.transformOrigin,o.scale?t.style.setProperty("scale",o.scale):t.style.removeProperty("scale")}}(n,A),F=t=>()=>{t(),C()};if(d){let e;"string"==typeof t?(e=document.createElement("video"),e.crossOrigin="anonymous",e.src=t,e.readyState<2&&await new Promise((n,o)=>{e.onloadeddata=()=>n(),e.onerror=()=>o(new Error(`asciifyVideo: failed to load "${t}"`))})):e=t,E=await Ct(e,E,y,b,p);const o=Et(e.videoWidth,e.videoHeight,E);T&&Rt(n,T,o.w/o.h,o.w,o.h,M,A);const{renderW:a,renderH:r}=Ft(o.w,o.h,M),i="undefined"!=typeof window&&window.devicePixelRatio||1,s=8e6,h=a*i*r*i>s?Math.sqrt(s/(a*r)):i;n.width===Math.round(a*h)&&n.height===Math.round(r*h)||(n.width=Math.round(a*h),n.height=Math.round(r*h));const c=void 0!==b?b-y:10,l=u??(p?18:void 0);if(pt(E)){const{frames:t,fps:o}=await st(e,E,a,r,l,c,void 0,y),i=e=>{const n=t[e];n&&(k.save(),k.setTransform(h,0,0,h,0,0),rt(k,n,E,a,r),k.restore(),w?.())};if(p){let o=!1,a=-1;const r=!0===p?{}:p,s=St(gt(r.trigger)??T??n,r,n=>{const s=xt(n,r),h=Math.max(0,Math.min(t.length-1,Math.round(s*(t.length-1))));h!==a&&(a=h,i(h),o||(o=!0,v?.(e)),r.onUpdate?.(s,e))});return i(0),o=!0,v?.(e),F(s)}let s=!1,f=0,m=0,d=performance.now(),u=!0,M=!0;const g=1e3/o,x=n=>{f=0,s||!u&&!M||(n-d>=g&&(i(m),m=(m+1)%t.length,d=n,M&&(M=!1,v?.(e))),f=requestAnimationFrame(x))},b="function"==typeof IntersectionObserver?new IntersectionObserver(([t])=>{u=t.isIntersecting,!u||f||s||(f=requestAnimationFrame(x))}):null;return b?.observe(n),f=requestAnimationFrame(x),F(()=>{s=!0,cancelAnimationFrame(f),b?.disconnect()})}const{frames:f,fps:m}=await it(e,E,a,r,l,c,void 0,y);if(!f.length)throw new Error("asciifyVideo: no frames were decoded.");let d=0;const g=performance.now(),x=q(n,(t,e)=>{p||(d=Math.floor((t-g)*m/1e3)%f.length),k.save(),k.setTransform(h,0,0,h,0,0),mt(k,f[d],E,a,r,(t-g)/1e3,e),k.restore(),w?.()},{continuous:!p||"none"!==E.animationStyle||!!E.charsetFrames?.length,interactive:E.hoverStrength>0});let S;if(p){const t=!0===p?{}:p;S=St(gt(t.trigger)??T??n,t,n=>{d=Math.max(0,Math.min(f.length-1,Math.round(xt(n,t)*(f.length-1)))),x.wake(),t.onUpdate?.(n,e)})}return v?.(e),F(()=>{x.stop(),S?.()})}let I,L=!1;"string"==typeof t?(I=document.createElement("video"),I.crossOrigin="anonymous",I.src=t,I.muted=!0,I.loop=!0,I.playsInline=!0,I.setAttribute("playsinline",""),Object.assign(I.style,{position:"fixed",top:"0",left:"0",width:"1px",height:"1px",opacity:"0",pointerEvents:"none",zIndex:"-1"}),document.body.appendChild(I),L=!0,await new Promise((e,n)=>{I.onloadedmetadata=()=>e(),I.onerror=()=>n(new Error(`asciifyVideo: failed to load "${t}"`))}),await I.play().catch(()=>{})):(I=t,I.readyState<HTMLMediaElement.HAVE_METADATA&&await new Promise((t,e)=>{const n=()=>{I.removeEventListener("loadedmetadata",o),I.removeEventListener("error",a)},o=()=>{n(),t()},a=()=>{n(),e(new Error("asciifyVideo: provided video element failed to load metadata."))};I.addEventListener("loadedmetadata",o),I.addEventListener("error",a),I.load()}),I.paused&&await I.play().catch(()=>{})),y>0&&(I.currentTime=y,await new Promise(t=>{const e=()=>{I.removeEventListener("seeked",e),t()};I.addEventListener("seeked",e)}),await yt(I));let R=null;(y>0||void 0!==b)&&(R=()=>{(void 0!==b&&I.currentTime>=b||y>0&&I.currentTime<y)&&(I.currentTime=y)},I.addEventListener("timeupdate",R)),E=await Ct(I,E,y,b,p);let H=null;const W=Et(I.videoWidth,I.videoHeight,E);let{renderW:j,renderH:$}=Ft(W.w,W.h,M);const P=t=>"frame"===E.chromaKeyTrimMode?Tt(t,E,j/$):E;if(T){const t=W.w/W.h,e=W.w,o=W.h,a=Rt(n,T,t,e,o,M,A);j=a.renderW,$=a.renderH;const r=n.getContext("2d");r&&r.setTransform(a.dpr,0,0,a.dpr,0,0),H=new ResizeObserver(()=>{const a=Rt(n,T,t,e,o,M,A);j=a.renderW,$=a.renderH;const r=n.getContext("2d");r&&r.setTransform(a.dpr,0,0,a.dpr,0,0)}),H.observe(T)}else{const t="undefined"!=typeof window&&window.devicePixelRatio||1,e=8e6,o=j*t*$*t>e?Math.sqrt(e/(j*$)):t;n.width===Math.round(j*o)&&n.height===Math.round($*o)||(n.width=Math.round(j*o),n.height=Math.round($*o)),k.setTransform(o,0,0,o,0,0)}let O=!0,z=null;const D=p&&!d,U=u&&u>0?1e3/u:0;let V=0;const B=!D&&pt(E);if(D&&"ascii"===E.renderMode&&"none"===E.animationStyle&&E.hoverStrength<=0&&!E.charsetFrames?.length){const t=!0===p?{}:p,e=gt(t.trigger)??T??n,o=t.from??y,a=t.to??b??I.duration,r=Math.max(o,Math.min(a,I.duration)),i=Math.max(.001,r-o),s=Math.min(60,Math.max(12,u??30)),h=Math.max(2,Math.ceil(i*s)+1),c=new Array(h),l=[],f=Math.max(2,Math.min(h,Math.floor(x))),m=()=>{for(;l.length>f;){const t=l.findIndex(t=>t!==M&&Math.abs(t-M)>2),e=t>=0?t:0,n=l.splice(e,1)[0];void 0!==n&&(c[n]=void 0)}},d=t=>{const e=l.indexOf(t);e>=0&&l.splice(e,1),l.push(t),m()};let M=0,g=0,S=-1,A=0,C=!0,W=!1,O=!1,q=!1;const D=new Set,B=document.createElement("video");B.muted=!0,B.playsInline=!0,B.preload="auto",B.crossOrigin=I.crossOrigin||"anonymous",B.src=I.currentSrc||I.src,Object.assign(B.style,{position:"fixed",top:"0",left:"0",width:"1px",height:"1px",opacity:"0",pointerEvents:"none",zIndex:"-1"}),document.body.appendChild(B),B.readyState<HTMLMediaElement.HAVE_METADATA&&await new Promise((t,e)=>{const n=()=>{B.removeEventListener("loadedmetadata",o),B.removeEventListener("error",a)},o=()=>{n(),t()},a=()=>{n(),e(new Error("asciifyVideo: cache video failed to load metadata."))};B.addEventListener("loadedmetadata",o),B.addEventListener("error",a),B.load()}),B.pause(),I.paused&&await I.play().catch(()=>{});const N=t=>o+i*t/Math.max(1,h-1),K=t=>Math.max(0,Math.min(h-1,Math.round(t*(h-1)))),Y=P(I),_=at(I,Y,j,$);_.rows.length>0&&(c[0]=_,d(0),rt(k,_,Y,j,$),q=!0,v?.(I),w?.());const G=t=>{if(c[t])return t;for(let e=1;e<h;e++){const n=t-e,o=t+e;if(n>=0&&c[n])return n;if(o<h&&c[o])return o}return-1},X=()=>{if(!c[M])return M;for(const t of D)if(!c[t])return t;for(let t=1;t<h;t++){const e=M-t,n=M+t;if(e>=0&&!c[e])return e;if(n<h&&!c[n])return n}return-1},J=t=>{t<0||t>=h||c[t]||(D.add(t),Q())},Q=async()=>{if(W||O)return;const t=X();if(!(t<0)){D.delete(t),O=!0;try{if(await wt(B,N(t)),!W){const e=P(B),n=at(B,e,j,$);n.rows.length>0&&(c[t]=n,d(t))}}finally{O=!1,W||requestAnimationFrame(()=>{Q()})}}},Z=()=>{if(A=0,W||!C&&q)return;const t=G(M);if(t>=0&&t!==S){const e=c[t];e&&(rt(k,e,E,j,$),S=t,q||(q=!0,v?.(I)),w?.())}else if(t<0||S<0){const t=performance.now();if(U<=0||t-V>=U){const e=P(I),n=at(I,e,j,$);n.rows.length>0&&(rt(k,n,e,j,$),V=t,q||(q=!0,v?.(I)),w?.())}}J(M),A=requestAnimationFrame(Z)};z=St(e,t,e=>{const n=function(t,e,n={}){if(!Number.isFinite(t.duration)||t.duration<=0)return null;const o=n.from??0,a=n.to??t.duration,r=Math.max(o,Math.min(a,t.duration)),i=xt(e,n),s=o+(r-o)*i;return{progress:i,time:Math.min(Math.max(o,s),Math.max(o,r-.04))}}(I,e,{...t,from:o,to:r});g=n?.progress??Mt(e),M=K(g),J(M),J(M-1),J(M+1),J(M-2),J(M+2),J(M-3),J(M+3),t.onUpdate?.(g,I)}),J(0),J(1);const tt="function"==typeof IntersectionObserver?new IntersectionObserver(([t])=>{C=t.isIntersecting,!C||A||W||(A=requestAnimationFrame(Z))}):null;return tt?.observe(n),A=requestAnimationFrame(Z),F(()=>{W=!0,cancelAnimationFrame(A),tt?.disconnect(),z?.(),H?.disconnect(),D.clear(),l.length=0,c.fill(void 0),B.pause(),B.src="",B.removeAttribute("src"),B.load(),B.isConnected&&B.remove(),R&&I.removeEventListener("timeupdate",R),L&&(I.pause(),I.src="",I.removeAttribute("src"),I.load(),I.isConnected&&I.remove())})}if(D){const t=!0===p?{}:p;z=bt(I,{...t,trigger:t.trigger??T??n,from:t.from??y,to:t.to??b})}let N=-1,K=0,Y=-1,_=0;const G="function"==typeof I.requestVideoFrameCallback,X=()=>{_=I.requestVideoFrameCallback(()=>{K++,X()})};G&&X();let J=0,Q=0,Z=null;const tt=q(n,(t,e)=>{if(I.readyState<2||0===n.width||0===n.height)return;if(U>0&&t-V<U&&!e)return;if(y>0&&I.currentTime<y)return;if(void 0!==b&&I.currentTime>=b)return;const o=(G?K!==Y:I.currentTime!==N)||J!==j||Q!==$;if(o||!(E.hoverStrength<=0)||"none"!==E.animationStyle||E.charsetFrames?.length){if(B){const t=P(I),e=at(I,t,j,$);rt(k,e,t,j,$)}else!o&&Z||(Z=ot(I,P(I),j,$).frame),mt(k,Z,E,j,$,t/1e3,e);N=I.currentTime,Y=K,J=j,Q=$,V=t,O&&(O=!1,v?.(I)),w?.()}},{continuous:!0,interactive:E.hoverStrength>0});return F(()=>{tt.stop(),_&&I.cancelVideoFrameCallback(_),z?.(),H?.disconnect(),R&&I.removeEventListener("timeupdate",R),L&&(I.pause(),I.src="",I.removeAttribute("src"),I.load(),I.isConnected&&I.remove())})}function Wt(t,e,n,o="#505050",a=100){if(!t||e<=0||n<=0)return[];const r=function(t){const e=t.match(/^#([0-9a-f]{3,8})$/i)?.[1];if(e){const t=e.length<=4?e.split("").map(t=>parseInt(t+t,16)):[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)];return{r:t[0],g:t[1],b:t[2]}}const n=t.match(/rgba?\(\s*(\d+)[,\s]+(\d+)[,\s]+(\d+)/i);return n?{r:+n[1],g:+n[2],b:+n[3]}:null}(o)??{r:80,g:80,b:80},i=t,s=i.length;return Array.from({length:n},(t,n)=>Array.from({length:e},(t,o)=>({char:i[(n*e+o)%s],r:r.r,g:r.g,b:r.b,a:a})))}var jt=new WeakMap;function $t(t,{format:e="png",quality:n=.92,scale:o=1}={}){return new Promise((a,r)=>{let i=t;if(1!==o){const e=document.createElement("canvas");e.width=Math.round(t.width*o),e.height=Math.round(t.height*o);const n=e.getContext("2d");if(!n)return void r(new Error("captureSnapshot: could not get 2d context"));n.drawImage(t,0,0,e.width,e.height),i=e}i.toBlob(t=>t?a(t):r(new Error("captureSnapshot: toBlob returned null")),`image/${e}`,n)})}var Pt={A:[28,54,99,127,99,99,99],B:[126,99,99,126,99,99,126],C:[62,99,96,96,96,99,62],D:[124,102,99,99,99,102,124],E:[127,96,96,124,96,96,127],F:[127,96,96,124,96,96,96],G:[62,99,96,111,99,99,62],H:[99,99,99,127,99,99,99],I:[127,8,8,8,8,8,127],J:[63,6,6,6,102,102,60],K:[99,102,108,120,108,102,99],L:[96,96,96,96,96,96,127],M:[99,119,107,107,99,99,99],N:[99,115,107,103,99,99,99],O:[62,99,99,99,99,99,62],P:[126,99,99,126,96,96,96],Q:[62,99,99,99,107,102,61],R:[126,99,99,126,108,102,99],S:[62,99,96,62,3,99,62],T:[127,8,8,8,8,8,8],U:[99,99,99,99,99,99,62],V:[99,99,99,99,54,28,8],W:[99,99,99,107,107,54,20],X:[99,54,28,8,28,54,99],Y:[99,99,54,28,8,8,8],Z:[127,3,6,12,24,48,127],a:[0,0,60,3,62,99,61],b:[96,96,124,99,99,99,124],c:[0,0,62,96,96,96,62],d:[3,3,31,99,99,99,31],e:[0,0,62,99,127,96,62],f:[30,48,48,126,48,48,48],g:[0,0,63,99,63,3,62],h:[96,96,124,99,99,99,99],i:[8,0,24,8,8,8,28],j:[4,0,12,4,4,36,24],k:[96,96,102,108,120,108,102],l:[24,8,8,8,8,8,28],m:[0,0,92,107,107,99,99],n:[0,0,94,99,99,99,99],o:[0,0,62,99,99,99,62],p:[0,0,126,99,126,96,96],q:[0,0,63,99,63,3,3],r:[0,0,94,99,96,96,96],s:[0,0,62,96,62,3,124],t:[48,48,126,48,48,48,30],u:[0,0,99,99,99,103,59],v:[0,0,99,99,54,28,8],w:[0,0,99,99,107,54,20],x:[0,0,99,54,28,54,99],y:[0,0,99,99,63,3,62],z:[0,0,127,6,12,24,127],0:[62,99,103,107,115,99,62],1:[8,24,56,8,8,8,62],2:[62,99,3,6,24,48,127],3:[62,99,3,30,3,99,62],4:[6,14,22,38,127,6,6],5:[127,96,126,3,3,99,62],6:[62,99,96,126,99,99,62],7:[127,3,6,12,24,24,24],8:[62,99,99,62,99,99,62],9:[62,99,99,63,3,99,62]," ":[0,0,0,0,0,0,0],"!":[24,24,24,24,24,0,24],"?":[62,99,3,14,8,0,8],".":[0,0,0,0,0,24,24],",":[0,0,0,0,0,24,48],";":[0,24,24,0,24,24,48],":":[0,24,24,0,24,24,0],"-":[0,0,0,62,0,0,0],_:[0,0,0,0,0,0,127],"'":[24,24,32,0,0,0,0],'"':[54,54,36,0,0,0,0],"`":[24,8,0,0,0,0,0],")":[24,12,6,6,6,12,24],"(":[12,24,48,48,48,24,12],"[":[60,48,48,48,48,48,60],"]":[30,6,6,6,6,6,30],"{":[14,24,24,48,24,24,14],"}":[56,12,12,6,12,12,56],"/":[3,6,12,24,48,96,0],"\\":[96,48,24,12,6,3,0],"|":[8,8,8,8,8,8,8],"+":[0,8,8,62,8,8,0],"=":[0,0,62,0,62,0,0],"*":[0,42,28,127,28,42,0],"#":[36,36,127,36,127,36,36],"@":[62,99,111,107,111,96,62],"&":[24,36,24,60,74,68,58],"%":[99,38,4,8,16,50,99],$:[8,62,72,62,9,62,8],"^":[8,20,34,0,0,0,0],"~":[0,0,50,76,0,0,0],"<":[6,12,24,48,24,12,6],">":[48,24,12,6,12,24,48]},Ot=[127,65,65,65,65,65,127];function zt(t){return Pt[t]??Pt[t.toUpperCase()]??Ot}function qt(t,e={}){if(!t)return"";const{char:n="█",scale:o=1}=e,a=[...n][0]??"█",r=Math.max(1,Math.floor(o)),i=7*r,s=r,h=Array.from({length:i},()=>"");for(let e=0;e<t.length;e++){const n=zt(t[e]);for(let t=0;t<7;t++){const e=n[t];let o="";for(let t=6;t>=0;t--)o+=(e>>t&1?a:" ").repeat(r);for(let e=0;e<r;e++)h[t*r+e]+=o}if(e<t.length-1)for(let t=0;t<i;t++)h[t]+=" ".repeat(s)}return h.join("\n")}var Dt=["ascii","blocks","braille","dots","lines","cross","diagonal","diamond","mixed","pixel","mosaic","lego","voxel","disco","dither","hex","led","cmyk","stipple","engraving","crosshatch","woodblock","risograph","pointillism"];exports.CHARACTER_SETS=t,exports.DEFAULT_OPTIONS=e,exports.HOVER_PRESETS={none:{label:"Off",options:{hoverStrength:0,hoverEffect:"spotlight",hoverRadius:.2,hoverColor:"#ffffff"}},subtle:{label:"Subtle",options:{hoverStrength:.25,hoverEffect:"glow",hoverRadius:.12,hoverColor:"#ffffff"}},flashlight:{label:"Flashlight",options:{hoverStrength:.6,hoverEffect:"spotlight",hoverRadius:.15,hoverColor:"#fffbe6"}},magnifier:{label:"Magnifier",options:{hoverStrength:.7,hoverEffect:"magnify",hoverRadius:.12,hoverColor:"#ffffff"}},forceField:{label:"Force Field",options:{hoverStrength:.7,hoverEffect:"repel",hoverRadius:.15,hoverColor:"#a0e8ff"}},neon:{label:"Neon",options:{hoverStrength:.6,hoverEffect:"colorShift",hoverRadius:.15,hoverColor:"#d946ef"}},fire:{label:"Fire",options:{hoverStrength:.7,hoverEffect:"spotlight",hoverRadius:.15,hoverColor:"#ff6b2b"}},ice:{label:"Ice",options:{hoverStrength:.5,hoverEffect:"glow",hoverRadius:.15,hoverColor:"#60d5f7"}},gravity:{label:"Gravity",options:{hoverStrength:.7,hoverEffect:"attract",hoverRadius:.18,hoverColor:"#a5d6ff"}},shatter:{label:"Shatter",options:{hoverStrength:.8,hoverEffect:"shatter",hoverRadius:.14,hoverColor:"#ff6090"}},ghost:{label:"Fluid trail",options:{hoverStrength:.55,hoverEffect:"trail",hoverRadius:.2,hoverColor:"#b39ddb"}},glitchReveal:{label:"Glitch Reveal",options:{hoverStrength:.8,hoverEffect:"glitchText",hoverRadius:.18,hoverColor:"#a3e635"}}},exports.PALETTE_THEMES={dracula:{name:"Dracula",accent:"#bd93f9",bg:"#282a36",fg:"#f8f8f2"},monokai:{name:"Monokai",accent:"#a6e22e",bg:"#272822",fg:"#f8f8f2"},nord:{name:"Nord",accent:"#88c0d0",bg:"#2e3440",fg:"#eceff4"},catppuccin:{name:"Catppuccin",accent:"#cba6f7",bg:"#1e1e2e",fg:"#cdd6f4"},solarized:{name:"Solarized",accent:"#268bd2",bg:"#002b36",fg:"#839496"},gruvbox:{name:"Gruvbox",accent:"#b8bb26",bg:"#282828",fg:"#ebdbb2"}},exports.STUDIO_STYLES=Dt,exports.asciiText=function(t,n={},o,a){const r={...e,...n},{frame:i,cols:s}=ot(t,r,o,a);if(!i.length||0===s)return"";const h=[];for(const t of i)h.push(t.map(t=>t.char).join(""));return h.join("\n")},exports.asciiTextAnsi=function(t,n={},o,a){const r={...e,...n},{frame:i,cols:s}=ot(t,r,o,a);if(!i.length||0===s)return"";const h=[];for(const t of i){let e="";for(const n of t)" "===n.char||n.a<10?e+=" ":e+=`[38;2;${n.r};${n.g};${n.b}m${n.char}`;h.push(e)}return h.join("\n")},exports.asciify=async function(t,n,{fontSize:o,artStyle:a="classic",options:r={}}={}){let i;if("string"==typeof t){const e=new Image;e.crossOrigin="anonymous",await new Promise((n,o)=>{e.onload=()=>n(),e.onerror=()=>o(new Error(`Failed to load image: ${t}`)),e.src=t}),i=e}else t instanceof HTMLImageElement&&!t.complete?(await new Promise((e,n)=>{t.onload=()=>e(),t.onerror=()=>n(new Error("Image failed to load"))}),i=t):i=t;const s=ut(a),h=o??r.fontSize??10,c={...e,...s,artStyle:a,...r,fontSize:h},l=n.getContext("2d");if(!l)throw new Error("Could not get 2d context from canvas");const{w:f,h:m}=function(t){return t instanceof HTMLVideoElement?{w:t.videoWidth,h:t.videoHeight}:t instanceof HTMLImageElement?{w:t.naturalWidth||t.width,h:t.naturalHeight||t.height}:{w:t.width,h:t.height}}(i),{renderW:d,renderH:u}=Ft(f,m),M="undefined"!=typeof window&&window.devicePixelRatio||1,g=8e6,p=d*M*u*M>g?Math.sqrt(g/(d*u)):M;n.width===Math.round(d*p)&&n.height===Math.round(u*p)||(n.width=Math.round(d*p),n.height=Math.round(u*p));const{frame:x}=ot(i,c,d,u),v=(t,e)=>{l.save(),l.setTransform(p,0,0,p,0,0),mt(l,x,c,d,u,t/1e3,e),l.restore()};return v(0,null),q(n,v,{continuous:"none"!==c.animationStyle||!!c.charsetFrames?.length,interactive:c.hoverStrength>0}).stop},exports.asciifyGif=async function(t,n,{fontSize:o,artStyle:a="classic",options:r={}}={}){const i="string"==typeof t?await fetch(t).then(t=>t.arrayBuffer()):t,s=o??r.fontSize??10;let h={...e,...ut(a),artStyle:a,...r,fontSize:s};const c=n.getContext("2d");if(!c)throw new Error("Could not get 2d context from canvas");const{frames:l,fps:f}=await ht(i,h,n.width,n.height);if(!l.length)throw new Error("asciifyGif: the GIF contains no renderable frames.");const m=performance.now();let d=-1;return q(n,(t,e)=>{const o=Math.floor((t-m)*f/1e3)%l.length;o===d&&!e&&h.hoverStrength<=0&&"none"===h.animationStyle&&!h.charsetFrames?.length||(mt(c,l[o],h,n.width,n.height,(t-m)/1e3,e),d=o)},{continuous:!0,interactive:h.hoverStrength>0}).stop},exports.asciifyLiveVideo=function(t,e,n){return Ht(t,e,n)},exports.asciifyText=qt,exports.asciifyVideo=Ht,exports.asciifyWebcam=async function(t,{fontSize:n=10,style:o="classic",options:a={},liveOptions:r,mirror:i=!0,constraints:s={facingMode:"user"},dpr:h}={}){if(!navigator.mediaDevices?.getUserMedia)throw new Error("asciifyWebcam: getUserMedia is not supported in this browser.");const c=ut(o),l=await navigator.mediaDevices.getUserMedia({video:s}),f=document.createElement("video");f.srcObject=l,f.muted=!0,f.playsInline=!0,await new Promise((t,e)=>{f.onloadedmetadata=()=>t(),f.onerror=()=>e(new Error("asciifyWebcam: video stream failed to load.")),f.play().catch(e)});const m={...e,...c,...a,fontSize:n},d=t.getContext("2d");if(!d)throw new Error("asciifyWebcam: could not get 2d context from canvas.");const u=h??("undefined"!=typeof window?window.devicePixelRatio:1)??1;1!==u&&d.scale(u,u);let M=null;const g=e=>{const n=t.getBoundingClientRect();M={x:(e.clientX-n.left)/n.width,y:(e.clientY-n.top)/n.height}},p=()=>{M=null};m.hoverStrength>0&&(t.addEventListener("mousemove",g),t.addEventListener("mouseleave",p));let x,v=!1;const w=performance.now(),y=e=>{if(!v){if(f.readyState>=f.HAVE_CURRENT_DATA){const n=t.width/u,o=t.height/u,a=(e-w)/1e3,s=r?{...m,...r()}:m;s.hoverStrength>0?(t.addEventListener("mousemove",g),t.addEventListener("mouseleave",p)):(t.removeEventListener("mousemove",g),t.removeEventListener("mouseleave",p));const{frame:h}=ot(f,s,n,o),c=M&&i?{x:1-M.x,y:M.y}:M;i?(d.save(),d.scale(-1,1),d.translate(-n,0),mt(d,h,s,n,o,a,c),d.restore()):mt(d,h,s,n,o,a,c)}x=requestAnimationFrame(y)}};return x=requestAnimationFrame(y),()=>{v=!0,cancelAnimationFrame(x),t.removeEventListener("mousemove",g),t.removeEventListener("mouseleave",p),l.getTracks().forEach(t=>t.stop()),f.srcObject=null}},exports.buildTextFrame=Wt,exports.captureSnapshot=$t,exports.clearAsciifyCaches=function(){B.clear(),N.clear(),ct=new WeakMap,ft=new WeakMap,lt=new WeakMap,D=null,U=null},exports.computeCanvasRenderSize=It,exports.createVideoScrollScrub=bt,exports.gifToAsciiFrames=ht,exports.gifToAsciiTextFrames=async function(t,e,n,o,a){const{parseGIF:r,decompressFrames:i}=await import("gifuct-js"),s=r(t),h=i(s,!0);if(0===h.length)return{frames:[],cols:0,rows:0,fps:10};const c=h[0].dims.width,l=h[0].dims.height,f=s.lsd?.width||c,m=s.lsd?.height||l,d=document.createElement("canvas");d.width=f,d.height=m;const u=d.getContext("2d"),M=document.createElement("canvas");M.width=f,M.height=m;const g=M.getContext("2d"),p=document.createElement("canvas"),x=p.getContext("2d"),v=[];let w=0,y=0,b=0;for(const t of h)b+=t.delay||100;const S=b/h.length,E=Math.round(Math.min(30,Math.max(5,1e3/S))),k=Math.min(h.length,300);for(let t=0;t<k;t++){const r=h[t],{dims:i,patch:s,disposalType:c}=r;3===c&&(g.clearRect(0,0,f,m),g.drawImage(d,0,0)),p.width!==i.width&&(p.width=i.width),p.height!==i.height&&(p.height=i.height);const l=new ImageData(new Uint8ClampedArray(s.buffer),i.width,i.height);x.putImageData(l,0,0),u.drawImage(p,i.left||0,i.top||0);const b=at(d,e,n,o);v.push(b),w=b.cols,y=b.rowCount,2===c?u.clearRect(i.left||0,i.top||0,i.width,i.height):3===c&&(u.clearRect(0,0,f,m),u.drawImage(M,0,0)),a?.((t+1)/k)}return{frames:v,cols:w,rows:y,fps:E}},exports.imageToAsciiFrame=ot,exports.imageToAsciiTextFrame=at,exports.renderFrameToCanvas=mt,exports.renderTextBackground=function(t,n,o,a,r={},i){const{fontSize:s=10,lineHeight:h=1.6,color:c="#505050",opacity:l=100,hoverEffect:f="spotlight",hoverStrength:m=.85,hoverRadius:d=.18,hoverColor:u="#d4ff00"}=r,M=Math.max(1,Math.floor(n/s)),g=Math.max(1,Math.floor(o/(s*h))),p=JSON.stringify([a,M,g,c,l]);let x=jt.get(t);x&&x.key===p||(x={key:p,frame:Wt(a,M,g,c,l)},jt.set(t,x)),mt(t,x.frame,{...e,fontSize:s,hoverEffect:f,hoverStrength:m,hoverRadius:d,hoverColor:u},n,o,0,i??null)},exports.renderTextFrameToCanvas=rt,exports.renderTextToCanvas=function(t,e,n={}){const{color:o="#d4ff00",bgColor:a,fontSize:r=10}=n,i=qt(e,n);if(!i)return;const s=i.split("\n"),h=Math.max(...s.map(t=>[...t].length));t.width=Math.ceil(h*r*.6),t.height=Math.ceil(s.length*r);const c=t.getContext("2d");a&&"transparent"!==a?(c.fillStyle=a,c.fillRect(0,0,t.width,t.height)):c.clearRect(0,0,t.width,t.height),c.fillStyle=o,c.font=`${r}px monospace`,c.textBaseline="top",s.forEach((t,e)=>c.fillText(t,0,e*r))},exports.snapshotAndDownload=async function(t,e={}){const{filename:n="asciify-snapshot",format:o="png",...a}=e,r=await $t(t,{format:o,...a}),i="jpeg"===o?"jpg":o,s=document.createElement("a");s.href=URL.createObjectURL(r),s.download=`${n}.${i}`,s.click(),setTimeout(()=>URL.revokeObjectURL(s.href),1e4)},exports.videoToAsciiFrames=it,exports.videoToAsciiTextFrames=st;//# sourceMappingURL=core.cjs.map
1
+ "use strict";var t={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:" ⠁⠃⠇⡇⣇⣧⣷⣿"}},e={fontSize:7,charSpacing:1,brightness:0,contrast:0,charset:t.standard.chars,colorMode:"grayscale",accentColor:"#d4ff00",invert:!1,renderMode:"ascii",animationStyle:"none",animationSpeed:1,dotSizeRatio:.8,ditherStrength:0,charAspect:.55,normalize:!1,hoverStrength:0,hoverRadius:.2,hoverEffect:"spotlight",hoverColor:"#ffffff",hoverShape:"circle",hoverText:"ASCIIFY",artStyle:"classic",fineDither:!1,customText:"",chromaKey:null,chromaKeyTolerance:60,chromaKeyTrimPadding:.002,chromaKeyTrimLuminanceThreshold:0,chromaKeyTrimMode:"range"},n={caustics:"sheen",grain:"shimmer",trace:"relight",tidal:"current",weave:"current",breeze:"current",reform:"develop",print:"develop",unfold:"develop"},o=[{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."}];var a=t=>Math.max(0,Math.min(1,t)),r=(t,e,n)=>{const o=a((n-t)/(e-t));return o*o*(3-2*o)},i=(t,e)=>{const n=(.06711056*t+.00583715*e)%1*52.9829189;return n-Math.floor(n)};function s(t){const e=Math.floor(t),n=Math.max(0,Math.min(1,(t-e-.2)/.6));return e+n*n*(3-2*n)}function h(t,e,n,o,a){if(!(a<1))for(let r=0;r<2;r++){for(let r=0;r<o;r++){let o=0;const i=r*n;for(let e=-a;e<=a;e++)o+=t[i+Math.max(0,Math.min(n-1,e))];for(let r=0;r<n;r++)e[i+r]=o/(2*a+1),o+=t[i+Math.min(n-1,r+a+1)]-t[i+Math.max(0,r-a)]}for(let r=0;r<n;r++){let i=0;for(let t=-a;t<=a;t++)i+=e[Math.max(0,Math.min(o-1,t))*n+r];for(let s=0;s<o;s++)t[s*n+r]=i/(2*a+1),i+=e[Math.min(o-1,s+a+1)*n+r]-e[Math.max(0,s-a)*n+r]}}}var c=new Float32Array(0);var l=t=>Math.max(0,Math.min(1,t)),f=(t,e,n)=>{const o=l((n-t)/(e-t));return o*o*(3-2*o)};function m(t,e,n=256){let o=0;for(let e=0;e<t.length;e++)t[e]>o&&(o=t[e]);if(o<=0)return 0;const a=new Uint32Array(n);for(let e=0;e<t.length;e++)a[Math.min(n-1,Math.floor(Math.max(0,t[e])/o*n))]++;let r=0;const i=t.length*e;for(let t=0;t<n;t++)if(r+=a[t],r>=i)return(t+1)/n*o;return o}var d=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}},u=null;function M(t,e,n,o,a){const r=2*a+1;for(let i=0;i<o;i++){const o=i*n;let s=0;for(let e=-a;e<=a;e++)s+=t[o+Math.max(0,Math.min(n-1,e))];for(let i=0;i<n;i++)e[o+i]=s/r,s+=t[o+Math.min(n-1,i+a+1)]-t[o+Math.max(0,i-a)]}for(let i=0;i<n;i++){let s=0;for(let t=-a;t<=a;t++)s+=e[Math.max(0,Math.min(o-1,t))*n+i];for(let h=0;h<o;h++)t[h*n+i]=s/r,s+=e[Math.min(o-1,h+a+1)*n+i]-e[Math.max(0,h-a)*n+i]}}function g(t,e,n,o,a,r,i){const s=n*o,h=i.take(),c=i.take(e),l=i.take(t),f=i.take(),m=i.take();for(let n=0;n<s;n++)f[n]=e[n]*e[n],m[n]=e[n]*t[n];M(c,h,n,o,a),M(l,h,n,o,a),M(f,h,n,o,a),M(m,h,n,o,a);for(let t=0;t<s;t++){const e=(m[t]-c[t]*l[t])/(f[t]-c[t]*c[t]+r);f[t]=e,m[t]=l[t]-e*c[t]}M(f,h,n,o,a),M(m,h,n,o,a);for(let n=0;n<s;n++)t[n]=f[n]*e[n]+m[n]}function p(t,e,n,o,a,r=2){for(let i=0;i<r;i++){for(let r=0;r<o;r++)for(let o=0;o<n;o++){const i=r*n+o;let s=t[i];o>0&&(s=Math.max(s,Math.min(e[i],t[i-1]*a))),r>0&&(s=Math.max(s,Math.min(e[i],t[i-n]*a),o>0?Math.min(e[i],t[i-n-1]*a):0,o<n-1?Math.min(e[i],t[i-n+1]*a):0)),t[i]=s}for(let r=o-1;r>=0;r--)for(let i=n-1;i>=0;i--){const s=r*n+i;let h=t[s];i<n-1&&(h=Math.max(h,Math.min(e[s],t[s+1]*a))),r<o-1&&(h=Math.max(h,Math.min(e[s],t[s+n]*a),i>0?Math.min(e[s],t[s+n-1]*a):0,i<n-1?Math.min(e[s],t[s+n+1]*a):0)),t[s]=h}}}function x(t,e,n,o,a){for(let r=0;r<o;r++)for(let o=0;o<n;o++){let i=1;for(let e=Math.max(0,o-a);e<=Math.min(n-1,o+a);e++)i=Math.min(i,t[r*n+e]);e[r*n+o]=i}for(let r=0;r<o;r++)for(let i=0;i<n;i++){let s=1;for(let t=Math.max(0,r-a);t<=Math.min(o-1,r+a);t++)s=Math.min(s,e[t*n+i]);t[r*n+i]=s}}function v(t,e,n,o,a){const r=n*o,i=Math.min(n,o),s=a.take(),d=a.take(),u=a.take(),v=a.take(),w=a.take();for(let n=0;n<r;n++){const o=t[4*n+3]/255;w[n]=o,s[n]=e[4*n]/255*o,d[n]=e[4*n+1]/255*o,u[n]=e[4*n+2]/255*o,v[n]=(.299*t[4*n]+.587*t[4*n+1]+.114*t[4*n+2])/255*o}const y=a.take(),b=(t,e)=>{const r=a.take(t);return h(r,y,n,o,e),r},S=Math.max(2,Math.round(.04*i)),E=Math.max(S+2,Math.round(.12*i)),T=Math.max(2,Math.round(.05*i)),k=b(v,1),A=b(v,S),C=b(v,E),F=a.take(),I=a.take(),L=a.take(),R=a.take(),H=a.take();for(let t=0;t<o;t++)for(let e=0;e<n;e++){const a=t*n+e;F[a]=Math.abs(v[a]-k[a]),I[a]=Math.abs(k[a]-A[a]),L[a]=Math.abs(A[a]-C[a]),R[a]=Math.abs(v[t*n+Math.min(n-1,e+1)]-v[t*n+Math.max(0,e-1)]),H[a]=Math.abs(v[Math.min(o-1,t+1)*n+e]-v[Math.max(0,t-1)*n+e])}h(F,y,n,o,T),h(I,y,n,o,T),h(L,y,n,o,T),h(R,y,n,o,2),h(H,y,n,o,2);const W=Math.max(.01,m(F,.9)+m(I,.9)),j=b(s,1),P=b(d,1),$=b(u,1),O=a.take(),z=a.take(),q=a.take();let D=0;for(let t=0;t<r;t++){const e=j[t],n=P[t],o=$[t],a=Math.max(e,n,o),r=a-Math.min(e,n,o);q[t]=a,z[t]=a>.001?r/a:0,D+=r;let i=0;r>1e-4&&(i=a===e?((n-o)/r+6)%6:a===n?(o-e)/r+2:(e-n)/r+4),O[t]=60*i}const U=f(.02,.07,D/r),V=Math.max(2,Math.round(.06*o)),B=new Float32Array(o);for(let t=0;t<o;t++){let e=0;for(let o=0;o<n;o++)e+=F[t*n+o]+I[t*n+o];B[t]=e/n}let N=.5,K=0;for(let t=Math.max(V,Math.round(.12*o));t<=Math.min(o-V,Math.round(.88*o));t++){let e=0,a=0,r=0,i=0;for(let o=0;o<n;o++){let r=0,i=0,s=0,h=0,c=0,l=0;for(let e=1;e<=V;e++){const a=(t-e)*n+o,f=(t+e-1)*n+o;r+=j[a],i+=P[a],s+=$[a],h+=j[f],c+=P[f],l+=$[f]}const f=(Math.abs(r-h)+Math.abs(i-c)+Math.abs(s-l))/V;e+=f,a+=f>.12?1:0}const s=Math.max(2,Math.round(.15*o)),h=Math.max(0,t-s),c=Math.min(o,t+s);for(let e=h;e<t;e++)r+=B[e];for(let e=t;e<c;e++)i+=B[e];r/=t-h,i/=c-t;const l=f(-.05,.3,(i-r)/(i+r+1e-4)),m=f(.08,.35,e/n)*(a/n)*l;m>K&&(K=m,N=t/o)}const Y=f(.15,.45,K),_=a.take(),G=a.take(),X=a.take();for(let t=0;t<r;t++)_[t]=Math.min(s[t],d[t],u[t]);x(_,y,n,o,1),h(_,y,n,o,S);for(let t=0;t<r;t++)G[t]=I[t]+L[t];let J=0,Q=0,Z=0;for(let t=0;t<r;t++)J+=j[t],Q+=P[t],Z+=$[t];J/=r,Q/=r,Z/=r;const tt=b(j,S),et=b(P,S),nt=b($,S),ot=b(j,E),at=b(P,E),rt=b($,E);for(let t=0;t<r;t++){const e=Math.hypot(tt[t]-J,et[t]-Q,nt[t]-Z),n=Math.hypot(tt[t]-ot[t],et[t]-at[t],nt[t]-rt[t]);X[t]=(e+1.5*n)*(.4+.6*z[t]*U+.4*(1-U))}const it=a.take(),st=a.take(),ht=a.take(),ct=a.take(),lt=a.take(),ft=a.take(),mt=a.take(),dt=a.take(),ut=a.take(),Mt=a.take();for(let t=0;t<o;t++)for(let e=0;e<n;e++)Mt[t*n+e]=Math.abs(v[Math.min(o-1,t+1)*n+e]-v[Math.max(0,t-1)*n+e]);h(Mt,y,n,o,1);for(let t=0;t<o;t++)for(let e=0;e<n;e++){const a=t*n+e,r=(t+.5)/o,i=O[a],s=z[a]*U,h=q[a],c=F[a]+I[a],l=f(175,200,i)*(1-f(250,275,i))*f(.08,.25,s),m=(1-f(45,65,i)+f(290,330,i))*f(.2,.45,s)*f(.3,.55,h),d=(1-f(.15,.35,s))*f(.45,.7,h)*Y,u=(1-f(.08,.2,h))*Y,M=Y>.3?1-f(N,N+.1,r):1-f(.4,.8,r),g=1-f(.02,.06,c),p=1-f(.03,.09,c);st[a]=Math.max(l*g,.7*u*(1-f(.008,.025,c)),m*p*.9)*M,ht[a]=Math.max(st[a],d*g*M),it[a]=0===t?st[a]:0,ct[a]=f(150,172,i)*(1-f(232,250,i))*f(.25,.45,s),mt[a]=f(1.3,2.2,(R[a]+.004)/(H[a]+.004))*f(.35,.55,k[a])*(1-f(.1,.18,z[a]*U))*f(.025,.07,c)*f(.025,.045,Mt[a]);const x=1-f(.18,.4,s),v=f(.55,.8,h)*f(.05,.12,c);lt[a]=Math.max(ct[a],.85*x,.8*v)}p(it,st,n,o,.995,1),p(it,ht,n,o,.8,1);let gt=0;for(let t=0;t<r;t++)gt+=it[t];const pt=gt>.04*r&&Y>.3;if(pt)for(let t=0;t<o;t++)for(let e=0;e<n;e++)ct[t*n+e]*=f(N,N+.05,(t+.5)/o);if(pt){const t=a.take(),e=a.take(),i=a.take();for(let e=0;e<r;e++)t[e]=.299*tt[e]+.587*et[e]+.114*nt[e];for(let t=0;t<o;t++)for(let a=0;a<n;a++)e[t*n+a]=k[Math.min(o-1,t+1)*n+a]-k[Math.max(0,t-1)*n+a];const s=new Uint8Array(r);for(let t=1;t<o-1;t++)for(let a=0;a<n;a++){const r=Math.abs(e[t*n+a]);let i=r>.03;for(let s=-3;s<=3&&i;s++)s&&t+s>=0&&t+s<o&&Math.abs(e[(t+s)*n+a])>r&&(i=!1);s[t*n+a]=i?1:0}const c=(e,n,o,a=!0)=>{const r=tt[n]+et[n]+nt[n]+.05,i=tt[o]+et[o]+nt[o]+.05,s=Math.abs(tt[n]/r-tt[o]/i)+Math.abs(et[n]/r-et[o]/i)+Math.abs(nt[n]/r-nt[o]/i),h=Math.min(Math.abs(O[n]-O[o]),360-Math.abs(O[n]-O[o])),c=Math.max(1-f(.1,.25,s),(1-f(15,35,h))*f(.15,.3,Math.min(z[n],z[o]))),l=Math.max(f(2,3,(H[n]+.004)/(R[n]+.004))*f(.015,.04,F[n]+I[n])*f(.4,.55,F[n]/(F[n]+I[n]+1e-4)),1-f(.12,.25,t[n]));return c*(a?l:1)*(1-f(.82*t[o]+.02,1.02*t[o]+.05,t[n]))};let l=0,m=0;for(let t=Math.max(3,Math.round(o*Math.max(.25,N)));t<Math.round(.88*o);t++){let e=0;for(let o=0;o<n;o++)(s[(t-1)*n+o]||s[t*n+o]||s[(t+1)*n+o])&&e++;if(e<.5*n)continue;let a=0;for(let e=t+1;e<Math.min(o,2*t);e++)for(let o=0;o<n;o++)a+=c(t,e*n+o,(2*t-e)*n+o);a>m&&(m=a,l=t)}const d=f(.05,.1,m/r);if(d>0)for(let t=l+1;t<Math.min(o,2*l);t++)for(let e=0;e<n;e++){const o=t*n+e;dt[o]=c(l,o,(2*l-t)*n+e)*d,ut[o]=c(l,o,(2*l-t)*n+e,!1)*d,i[o]=dt[o]}h(i,y,n,o,1);for(let t=0;t<r;t++)dt[t]=Math.max(dt[t],i[t]),ct[t]=Math.max(ct[t],dt[t])}const xt=b(ct,E);for(let t=0;t<r;t++)ct[t]*=f(.15,.35,xt[t]);const vt=b(ct,S);for(let t=0;t<r;t++){ct[t]*=1-.8*st[t];const e=Math.min(Math.abs(O[t]-200),360-Math.abs(O[t]-200));ft[t]=f(.28,.45,z[t]*U)*f(55,80,e)*(1-f(.3,.6,ut[t]))}const wt=b(ft,S);for(let t=0;t<r;t++)ft[t]=Math.max(ft[t]*(1-(1-f(.15,.3,wt[t]))*f(.55,.7,q[t])*f(.5,.65,z[t])),1-w[t]),lt[t]=Math.min(Math.max(lt[t],.9*ut[t]),Math.max(ct[t],f(.25,.6,vt[t])))*(1-it[t])*(1-ft[t]);p(ct,lt,n,o,.97);const yt=a.take(mt),bt=Math.max(2,Math.round(.12*o));for(let t=0;t<n;t++){let e=0;for(let a=-bt;a<=bt;a++)e+=mt[Math.max(0,Math.min(o-1,a))*n+t];for(let a=0;a<o;a++)yt[a*n+t]=e/(2*bt+1),e+=mt[Math.min(o-1,a+bt+1)*n+t]-mt[Math.max(0,a-bt)*n+t]}h(yt,y,n,o,1);for(let t=0;t<r;t++)mt[t]=f(.2,.45,yt[t])*f(.2,.5,mt[t]+.5*yt[t])*(1-it[t]);g(it,v,n,o,Math.max(2,Math.round(.04*i)),.002,a),g(ct,v,n,o,Math.max(2,Math.round(.04*i)),.002,a),g(mt,v,n,o,Math.max(2,Math.round(.03*i)),.002,a),h(ft,y,n,o,1);for(let t=0;t<r;t++)it[t]=f(.3,.7,it[t])*w[t],mt[t]=f(.3,.7,mt[t])*w[t]*(1-it[t]),ct[t]=f(.3,.7,ct[t])*(1-it[t])*(1-mt[t])*(1-f(.15,.4,ft[t]));x(it,y,n,o,2),x(ct,y,n,o,2),x(mt,y,n,o,1),h(it,y,n,o,1),h(ct,y,n,o,1),h(mt,y,n,o,1);const St=1/Math.max(.02,m(X,.97)),Et=1/Math.max(.01,m(G,.9)),Tt=m(_,.97),kt=m(_,.1),At=f(.06,.25,Tt-kt),Ct=a.take();for(let t=0;t<o;t++)for(let e=0;e<n;e++){const a=t*n+e,r=(e+.5)/n,i=(t+.5)/o,s=Math.max(it[a],ct[a]),h=F[a]+I[a]+L[a],c=.6*l(((F[a]+.6*I[a])/(h+.004)-.25)/.55)+.4*l((F[a]+I[a])/W),m=f(.04,.35,h/W)*(1-s),d=.55*l((_[a]-kt)/Math.max(.05,Tt-kt))+.25*(1-l(G[a]*Et))+.2*l(2*($[a]-j[a])+.3)*U,u=At*f(.12,.35,A[a])*(.4+.6*Y),M=Y*(i<N?.45:.45+.55*f(0,1,(i-N)/Math.max(.15,1-N)))+(1-Y)*(.5+.4*(i-.5)),g=F[a]/(F[a]+I[a]+1e-4),p=f(.2,.7,(F[a]+I[a])/W)*(.35+.65*Y)*(1-s),x=1-l(1.5*Math.hypot(1.2*(r-.5),i-.52)),v=l(X[a]*St)*(.55+.45*x),w=.3*m,y=.25*u,b=.12+.45*Y,S=.12*p,E=.35*(1-.4*Y)*(1-s);Ct[a]=(w*c+y*(1-d)+b*M+S*l(1.6-1.6*g)+E*v+.04)/(w+y+b+S+E+.08)*(1-.85*it[a])*(1-.45*ct[a]*(1-Y))}const Ft=function(t,e,n){const o=e*n,a={width:e,height:n,subject:new Float32Array(o),depth:new Float32Array(o),key:"none"},{subject:r,depth:i}=a;let s=0;for(let e=0;e<o;e++)t[4*e+3]<250&&s++;const l=e=>(.2126*t[4*e]+.7152*t[4*e+1]+.0722*t[4*e+2])/255;let f="none",m=0;if(s>.01*o)f="alpha";else{let t=0,o=0,a=0;const r=Math.max(1,Math.round(.03*Math.min(e,n)));for(let i=0;i<n;i++)for(let s=0;s<e;s++){if(s>=r&&i>=r&&s<e-r&&i<n-r)continue;const h=l(i*e+s);t+=h,o+=h*h,a++}m=t/Math.max(1,a),Math.sqrt(Math.max(0,o/Math.max(1,a)-m*m))<.07&&(f="ground")}for(let e=0;e<o;e++){const n=t[4*e+3]/255,o=l(e);let a=1;if("alpha"===f)a=n;else if("ground"===f){const t=Math.max(0,Math.min(1,(Math.abs(o-m)-.035)/.12));a=t*t*(3-2*t)}r[e]=1*a,i[e]=o*n}a.key=f,c.length<o&&(c=new Float32Array(o));const d=c;return h(r,d,e,n,Math.max(1,Math.round(.02*Math.min(e,n)))),h(i,d,e,n,Math.max(1,Math.round(.035*Math.min(e,n)))),a}(t,n,o);if("none"!==Ft.key)for(let t=0;t<r;t++)Ct[t]=.7*Ft.subject[t]+.3*Ct[t];return h(Ct,y,n,o,Math.max(1,Math.round(.03*i))),function(t,e,n,o,a,r,i,s,h){const c=a*r,l=h.take(),f=t=>(M(t,l,a,r,i),t),m=(t,e)=>{const n=h.take();for(let o=0;o<c;o++)n[o]=t[o]*e[o];return f(n)},d=f(h.take(e)),u=f(h.take(n)),g=f(h.take(o)),p=f(h.take(t)),x=m(e,e),v=m(e,n),w=m(e,o),y=m(n,n),b=m(n,o),S=m(o,o),E=m(e,t),T=m(n,t),k=m(o,t),A=h.take(),C=h.take(),F=h.take(),I=h.take();for(let t=0;t<c;t++){const e=E[t]-d[t]*p[t],n=T[t]-u[t]*p[t],o=k[t]-g[t]*p[t],a=x[t]-d[t]*d[t]+s,r=v[t]-d[t]*u[t],i=w[t]-d[t]*g[t],h=y[t]-u[t]*u[t]+s,c=b[t]-u[t]*g[t],l=S[t]-g[t]*g[t]+s,f=h*l-c*c,m=i*c-r*l,M=r*c-i*h,L=a*l-i*i,R=r*i-a*c,H=a*h-r*r,W=a*f+r*m+i*M,j=Math.abs(W)>1e-12?1/W:0;A[t]=(f*e+m*n+M*o)*j,C[t]=(m*e+L*n+R*o)*j,F[t]=(M*e+R*n+H*o)*j,I[t]=p[t]-A[t]*d[t]-C[t]*u[t]-F[t]*g[t]}f(A),f(C),f(F),f(I);for(let a=0;a<c;a++)t[a]=A[a]*e[a]+C[a]*n[a]+F[a]*o[a]+I[a]}(Ct,j,P,$,n,o,Math.max(2,Math.round(.07*i)),.004,a),{depth:Ct,water:ct,sky:it,falls:mt}}function w(t,e,n,o,a,r,i){if(e===r&&n===i)return t[a*r+o];const s=Math.max(0,Math.min(e-1,(o+.5)*e/r-.5)),h=Math.max(0,Math.min(n-1,(a+.5)*n/i-.5)),c=Math.min(e-2,Math.floor(s)),l=Math.min(n-2,Math.floor(h)),f=s-c,m=h-l;if(c<0||l<0)return t[Math.round(h)*e+Math.round(s)];const d=l*e+c,u=d+e;return(t[d]*(1-f)+t[d+1]*f)*(1-m)+(t[u]*(1-f)+t[u+1]*f)*m}var y=new WeakMap;function b(t){const e=y.get(t);if(e)return e;const n=t.length,o=t[0]?.length??0,a=new Uint8ClampedArray(o*n*4);for(let e=0;e<n;e++)for(let n=0;n<o;n++){const r=t[e][n],i=4*(e*o+n);a[i]=r.r,a[i+1]=r.g,a[i+2]=r.b,a[i+3]=r.a}const r=function(t,e,n,o,a=t){const r=e*n,i=o?.length===11*r?o:new Float32Array(11*r);if(!r)return i;const s=Math.min(e,n),c=new Float32Array(r),f=new Float32Array(r),M=new Float32Array(r),g=new Float32Array(r),p=new Float32Array(r),x=new Float32Array(r);for(let e=0;e<r;e++){const n=t[4*e+3]/255;c[e]=(.299*t[4*e]+.587*t[4*e+1]+.114*t[4*e+2])/255*n}f.set(c),h(f,x,e,n,Math.max(1,Math.round(.012*s))),M.set(c),h(M,x,e,n,Math.max(1,Math.round(.03*s)));for(let t=0;t<r;t++){g[t]=Math.abs(c[t]-f[t]);const e=Math.max(0,c[t]-.55)/.45;p[t]=e*e}h(g,x,e,n,Math.max(1,Math.round(.02*s)));const y=1/Math.max(.02,m(g,.95));h(p,x,e,n,Math.max(1,Math.round(.05*s)));const b=1/Math.max(.03,m(p,.98)),S=Math.max(1,Math.ceil(Math.sqrt(r/12e3))),E=Math.max(1,Math.floor(e/S)),T=Math.max(1,Math.floor(n/S)),k=E*T;let A=t,C=a;if(S>1){const n=new Uint8ClampedArray(4*k),o=a===t?n:new Uint8ClampedArray(4*k);for(let r=0;r<T;r++)for(let i=0;i<E;i++){const s=[0,0,0,0,0,0,0];for(let h=r*S;h<(r+1)*S;h++)for(let r=i*S;r<(i+1)*S;r++){const i=4*(h*e+r);for(let e=0;e<4;e++)s[e]+=t[i+e];if(o!==n)for(let t=0;t<3;t++)s[4+t]+=a[i+t]}const h=4*(r*E+i),c=S*S;for(let t=0;t<4;t++)n[h+t]=s[t]/c;if(o!==n){for(let t=0;t<3;t++)o[h+t]=s[4+t]/c;o[h+3]=n[h+3]}}A=n,C=o}u?.n!==k&&(u=new d(k)),u.reset();const{depth:F,water:I,sky:L,falls:R}=v(A,C,E,T,u),H=m(F,.03),W=m(F,.97),j=Math.max(.05,W-H);let P=0,$=0,O=0;const z=new Float32Array(r);for(let t=0;t<n;t++)for(let o=0;o<e;o++){const a=t*e+o,r=11*a,s=l((w(F,E,T,o,t,e,n)-H)/j);i[r+1]=s,i[r+8]=l(w(I,E,T,o,t,e,n)),i[r+9]=l(w(L,E,T,o,t,e,n)),i[r+10]=l(w(R,E,T,o,t,e,n));const h=s*s*s*(.25+c[a]);P+=(o+.5)/e*h,$+=(t+.5)/n*h,O+=h,z[a]=Math.hypot(M[t*e+Math.min(e-1,o+1)]-M[t*e+Math.max(0,o-1)],M[Math.min(n-1,t+1)*e+o]-M[Math.max(0,t-1)*e+o])}P=O>0?Math.max(.3,Math.min(.7,P/O)):.5,$=O>0?Math.max(.3,Math.min(.7,$/O)):.5;const q=1/Math.max(.004,m(z,.97));for(let t=0;t<n;t++)for(let o=0;o<e;o++){const a=t*e+o,r=11*a,s=(M[t*e+Math.min(e-1,o+1)]-M[t*e+Math.max(0,o-1)])*q,h=(M[Math.min(n-1,t+1)*e+o]-M[Math.max(0,t-1)*e+o])*q;i[r]=M[a],i[r+2]=Math.min(1,p[a]*b),i[r+3]=Math.min(1,g[a]*y),i[r+4]=Math.max(-1,Math.min(1,-s)),i[r+5]=Math.max(-1,Math.min(1,-h)),i[r+6]=P,i[r+7]=$}return i}(a,o,n);return y.set(t,r),r}function S(t,e){const n=document.createElement("canvas");n.width=t,n.height=e;const o=n.getContext("2d",{willReadFrequently:!0});return{canvas:n,ctx:o}}function E(t,e,n){let o=t+255*e;return o=259*(255*n+255)/(255*(259-255*n))*(o-128)+128,Math.max(0,Math.min(255,o))}function T(t,e,n,o,a,r){if((r?1-t/255:t/255)<.12)return" ";const i=[...e];return i[(o*a+n)%i.length]}var k=[[0,8,2,10],[12,4,14,6],[3,11,1,9],[15,7,13,5]];function A(t,e,n,o){if(o<=0)return t;const a=(k[n%4][e%4]/16-.5)*o*128;return Math.max(0,Math.min(255,t+a))}var C=new Array(256),F=new Array(256);for(let t=0;t<256;t++)C[t]=`rgb(${t},${t},${t})`,F[t]=`rgb(0,${t},0)`;function I(t,e,n,o,a,r=!1){switch(e){case"fullcolor":return`rgb(${t.r},${t.g},${t.b})`;case"matrix":return F[.299*t.r+.587*t.g+.114*t.b|0];case"accent":return`rgb(${n},${o},${a})`;default:{const e=.299*t.r+.587*t.g+.114*t.b|0;return C[e]}}}var L=[0,0,0];function R(t,e,n,o,a,r=!1){switch(e){case"fullcolor":L[0]=t.r,L[1]=t.g,L[2]=t.b;break;case"matrix":{const e=.299*t.r+.587*t.g+.114*t.b|0;L[0]=0,L[1]=e,L[2]=0;break}case"accent":L[0]=n,L[1]=o,L[2]=a;break;default:{const e=.299*t.r+.587*t.g+.114*t.b|0;L[0]=e,L[1]=e,L[2]=e;break}}return L}function H(t){const e=t.match(/rgba?\(\s*(\d+)\s*[,\s]\s*(\d+)\s*[,\s]\s*(\d+)(?:\s*[,/]\s*([\d.]+))?\s*\)/);return e?{r:+e[1],g:+e[2],b:+e[3],a:void 0!==e[4]?+e[4]:1}:null}function W(t){let e=t;for(;e&&e!==document.documentElement.parentElement;){const t=getComputedStyle(e).backgroundColor;if(t&&"transparent"!==t&&"rgba(0, 0, 0, 0)"!==t){const e=H(t);if(e&&e.a>.1)return e}e=e.parentElement}return null}function j(t){if(t){const e=W(t);if(e){return(.299*e.r+.587*e.g+.114*e.b)/255<.4}}if("undefined"!=typeof document){const t=document.documentElement,e=(t.getAttribute("data-theme")||"").toLowerCase();if("dark"===e)return!0;if("light"===e)return!1;if(t.classList.contains("dark"))return!0;if(document.body){const t=W(document.body);if(t){return(.299*t.r+.587*t.g+.114*t.b)/255<.4}}}return"undefined"!=typeof window&&window.matchMedia("(prefers-color-scheme: dark)").matches}function P(t){if("string"!=typeof t)return t;const e=document.createElement("canvas");e.width=1,e.height=1;const n=e.getContext("2d");n.fillStyle=t,n.fillRect(0,0,1,1);const o=n.getImageData(0,0,1,1).data;return{r:o[0],g:o[1],b:o[2]}}function $(t){return t*t*(3-2*t)}var O={scale:1,offsetX:0,offsetY:0,glow:0,colorBlend:0,proximity:0};function z(t,e,n,o,a,r,i,s,h="spotlight",c=.5,l="circle",f=[],m=1){const d=(t-n)*Math.max(1,m),u=(e-o)*Math.max(1,1/m),M=.08+.35*c+.04*r;let g,p;if("box"===l){const t=Math.abs(d),e=Math.abs(u);g=Math.max(t,e),p=M}else g=Math.sqrt(d*d+u*u),p=M;if(g>=p&&("trail"!==h||0===f.length))return O.scale=1,O.offsetX=0,O.offsetY=0,O.glow=0,O.colorBlend=0,O.proximity=0,O;const x=$(Math.max(0,1-g/p))*a;let v=1,w=0,y=0,b=0,S=0;switch(h){case"spotlight":{v=1+x*r*1.8;const t=Math.atan2(u,d),e=x*x*r*.6;w=Math.cos(t)*e*i,y=Math.sin(t)*e*s,b=x*r*.4,S=x*x*r*.25;break}case"magnify":v=1+x*r*.85,b=x*r*.15;break;case"repel":{v=1;const t=Math.atan2(u,d),e=x*x*r*1.8;w=Math.cos(t)*e*i,y=Math.sin(t)*e*s;break}case"glow":b=x*r*.8,S=x*r*.4;break;case"colorShift":v=1,b=x*r*.12,S=x*r;break;case"attract":{const t=Math.atan2(u,d),e=x*x*r*1;w=(.45*-Math.cos(t)-1.6*Math.sin(t))*e*i,y=(.45*-Math.sin(t)+1.6*Math.cos(t))*e*s,b=x*r*.3;break}case"shatter":{const t=Math.atan2(u,d),e=.5*Math.sin(43.7*d+29.3*u),n=x*r*1.4*(.7+.3*e);w=Math.cos(t+e)*n*i,y=Math.sin(t+e)*n*s,v=Math.max(.1,1-x*r*.6),b=x*r*.25;break}case"trail":{let n=x,o=-u*x,a=d*x;for(const r of f){const i=(t-r.x)*Math.max(1,m),s=(e-r.y)*Math.max(1,1/m),h=Math.hypot(i,s)/M;if(h>=1)continue;const c=$(1-h)*r.intensity;n=Math.max(n,c),o+=(.35*r.vx-2*s)*c*.35,a+=(.35*r.vy+2*i)*c*.35}w=Math.tanh(2*o)*r*i*3,y=Math.tanh(2*a)*r*s*3,S=n*r*.65,b=n*r*.35,v=1+n*r*.08,O.proximity=n;break}case"glitchText":v=1,b=x*r*.5,S=x*r*.6}return O.scale=v,O.offsetX=w,O.offsetY=y,O.glow=b,O.colorBlend=S,"trail"!==h&&(O.proximity=x),O}function q(t,e,{continuous:n=!1,interactive:o=!1}={}){const a=t.parentElement??t;let r=null,i=0,s=!1,h=!0,c=!0,l=-1/0;const f=window.matchMedia("(prefers-reduced-motion: reduce)"),m=()=>{c=!0,s||!h||document.hidden||i||(i=requestAnimationFrame(d))},d=t=>{if(i=0,s||!h||document.hidden)return;const o=!f.matches&&(n||t-l<1500);(c||o)&&(e(t,f.matches?null:r),c=!1),o&&(i=requestAnimationFrame(d))},u=e=>{if("touch"===e.pointerType)return;const n=t.getBoundingClientRect();if(!n.width||!n.height)return;const o=(e.clientX-n.left)/n.width,a=(e.clientY-n.top)/n.height;r=o>=0&&o<=1&&a>=0&&a<=1?{x:o,y:a}:null,l=performance.now(),m()},M=()=>{r=null,l=performance.now(),m()},g=()=>{document.hidden&&i?(cancelAnimationFrame(i),i=0):m()},p="undefined"==typeof IntersectionObserver?null:new IntersectionObserver(([t])=>{h=t.isIntersecting,h?m():i&&(cancelAnimationFrame(i),i=0)});return p?.observe(t),o&&(a.addEventListener("pointermove",u),a.addEventListener("pointerleave",M)),document.addEventListener("visibilitychange",g),f.addEventListener("change",m),m(),{wake:m,stop:()=>{s=!0,cancelAnimationFrame(i),p?.disconnect(),a.removeEventListener("pointermove",u),a.removeEventListener("pointerleave",M),document.removeEventListener("visibilitychange",g),f.removeEventListener("change",m)}}}var D=null,U=null;function V(t,e){if(!D||!U){const n=S(t,e);D=n.canvas,U=n.ctx}return D.width!==t&&(D.width=t),D.height!==e&&(D.height=e),U}var B=new Map,N=new Map,K=new WeakMap;function Y(t){const e=Intl.Segmenter;return e?Array.from(new e(void 0,{granularity:"grapheme"}).segment(t),({segment:t})=>t):[...t]}function _(t){let e=B.get(t);return e||(e=Y(t),B.set(t,e)),e}function G(t){return Y(t)}function X(t,e,n){const o=n?1-t/255:t/255,a=Math.floor(o*(e.length-1));return e[Math.max(0,Math.min(e.length-1,a))]??" "}function J(t,e,n,o){const a=`${t}\0${e?1:0}\0${n}\0${o}`;let r=N.get(a);if(!r){const i=_(t);r=new Array(256);for(let t=0;t<256;t++)r[t]=X(E(t,n,o),i,e);N.set(a,r)}return r}function Q(t,e){return"auto"!==t?t:!j(e)}function Z(t){const e=t.match(/^#([0-9a-fA-F]{3,6})$/);if(e){let t=e[1];if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6===t.length)return t}const n=t.match(/rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/);return n?[n[1],n[2],n[3]].map(t=>parseInt(t).toString(16).padStart(2,"0")).join(""):null}function tt(t){const e=t||"auto";if("auto"!==e)return Z(e)??"ffffff";if("undefined"!=typeof document){const t=getComputedStyle(document.documentElement);for(const e of["--accent-color","--color-accent","--accent","--color-primary","--primary","--brand-color"]){const n=Z(t.getPropertyValue(e).trim());if(n)return n}const e=Z(getComputedStyle(document.body).accentColor??"");if(e)return e}return j("undefined"!=typeof document?document.body:null)?"faf9f7":"0d0d0d"}function et(t,e,n){return Math.max(e,Math.min(n,t))}function nt(t,e,n){if(!t)return{x:0,y:0,width:e,height:n};const o=t.unit??"percent",a=!1!==t.preserveAspect,r=t=>void 0===t?void 0:"percent"===o?t*e:t,i=t=>void 0===t?void 0:"percent"===o?t*n:t,s=et(r(t.left)??0,0,e-1),h=et(r(t.right)??0,0,e-s-1),c=et(i(t.top)??0,0,n-1),l=et(i(t.bottom)??0,0,n-c-1),f=void 0!==t.left||void 0!==t.right||void 0!==t.top||void 0!==t.bottom,m=Math.max(1,e-s-h),d=Math.max(1,n-c-l),u=f?m:r(t.width),M=f?d:i(t.height);let g=u??e,p=M??n;if(a&&!f){const t=g/e,o=p/n,a=Math.min(t,o),r=void 0===u?o:void 0===M?t:a;g=e*r,p=n*r}g=et(g,1,f?m:e),p=et(p,1,f?d:n);const x=t.anchor??"center",v=r(t.x),w=i(t.y),y=f?s:0,b=f?c:0,S=f?m:e,E=f?d:n,T=x.endsWith("left")||"left"===x?0:x.endsWith("right")||"right"===x?S-g:(S-g)/2,k=x.startsWith("top")||"top"===x?0:x.startsWith("bottom")||"bottom"===x?E-p:(E-p)/2;return{x:et(v??y+T,0,Math.max(0,e-g)),y:et(w??b+k,0,Math.max(0,n-p)),width:g,height:p}}function ot(t,e,n,o){const a=t instanceof HTMLVideoElement?t.videoWidth:t.width,r=t instanceof HTMLVideoElement?t.videoHeight:t.height;if(0===a||0===r)return{frame:[],cols:0,rows:0};const i=e.charAspect,s=e.fontSize*e.charSpacing,h=e.fontSize/i*e.charSpacing,c=n||a,l=o||r,f=Math.floor(c/s),m=Math.floor(l/h);if(f<=0||m<=0)return{frame:[],cols:0,rows:0};const d=nt(e.sourceCrop,a,r),u=Math.max(1,Math.min(Math.floor(2048/f),Math.floor(d.width/f))),M=Math.max(1,Math.min(Math.floor(2048/m),Math.floor(d.height/m))),g=f*u,p=m*M,x=V(g,p),v=x.globalCompositeOperation;x.globalCompositeOperation="copy";try{x.drawImage(t,d.x,d.y,d.width,d.height,0,0,g,p)}finally{x.globalCompositeOperation=v}const w=x.getImageData(0,0,g,p).data,y=e.chromaKey,b=null!=y&&!1!==y,S=!0===y,k="blue-screen"===y;let C=null,F=0;!b||S||k||(C=P(y),F=(e.chromaKeyTolerance??60)**2);let I=0,L=255;if(e.normalize){let t=255,e=0;for(let n=0;n<w.length;n+=4){if(b){const t=w[n],e=w[n+1],o=w[n+2];let a=!1;if(S)a=e>1.4*t&&e>1.4*o&&e>80;else if(k)a=o>1.4*t&&o>1.4*e&&o>80;else if(null!==C){const n=t-C.r,r=e-C.g,i=o-C.b;a=n*n+r*r+i*i<=F}if(a)continue}const o=.299*w[n]+.587*w[n+1]+.114*w[n+2];o<t&&(t=o),o>e&&(e=o)}I=t,L=e>t?e-t:255}const R=[],H=Q(e.invert),W=b&&e.charset.replace(/ /g,"")||e.charset,j=_(W),$=e.customText?null:J(W,H,e.brightness,e.contrast),O=u*M;for(let t=0;t<m;t++){const n=[];for(let o=0;o<f;o++){let a=0,r=0,i=0,s=0,h=0;for(let e=0;e<M;e++){const n=(t*M+e)*g;for(let t=0;t<u;t++){const e=4*(n+o*u+t),c=w[e],l=w[e+1],f=w[e+2],m=w[e+3];if(b){let t=!1;if(S)t=l>1.4*c&&l>1.4*f&&l>80;else if(k)t=f>1.4*c&&f>1.4*l&&f>80;else if(null!==C){const e=c-C.r,n=l-C.g,o=f-C.b;t=e*e+n*n+o*o<=F}if(t){h++;continue}}a+=c,r+=l,i+=f,s+=m}}if(b&&h>O/2){n.push({char:" ",r:0,g:0,b:0,a:0});continue}const c=O-h,l=c>0?a/c:0,m=c>0?r/c:0,d=c>0?i/c:0,p=c>0?s/c:0,x=.299*l+.587*m+.114*d,v=e.normalize?(x-I)/L*255:x,y=E(v,e.brightness,e.contrast),R=e.ditherStrength>0?A(y,o,t,e.ditherStrength):y,W=e.customText?T(R,e.customText,o,t,f,H):e.ditherStrength>0?X(R,j,H):$[Math.max(0,Math.min(255,0|v))];n.push({char:W,r:l,g:m,b:d,a:p,lum:R})}R.push(n)}return{frame:R,cols:f,rows:m}}function at(t,e,n,o){const a=t instanceof HTMLVideoElement?t.videoWidth:t.width,r=t instanceof HTMLVideoElement?t.videoHeight:t.height;if(0===a||0===r)return{rows:[],cols:0,rowCount:0};const i=e.charAspect,s=e.fontSize*e.charSpacing,h=e.fontSize/i*e.charSpacing,c=n||a,l=o||r,f=Math.floor(c/s),m=Math.floor(l/h);if(f<=0||m<=0)return{rows:[],cols:0,rowCount:0};const d=f,u=m,M=V(d,u),g=nt(e.sourceCrop,a,r),p=M.globalCompositeOperation;M.globalCompositeOperation="copy";try{M.drawImage(t,g.x,g.y,g.width,g.height,0,0,d,u)}finally{M.globalCompositeOperation=p}const x=M.getImageData(0,0,d,u).data,v=e.chromaKey,w=null!=v&&!1!==v,y=!0===v,b="blue-screen"===v;let S=null,T=0;!w||y||b||(S=P(v),T=(e.chromaKeyTolerance??60)**2);let k=0,C=255;if(e.normalize){let t=255,e=0;for(let n=0;n<x.length;n+=4){if(w){const t=x[n],e=x[n+1],o=x[n+2];let a=!1;if(y)a=e>1.4*t&&e>1.4*o&&e>80;else if(b)a=o>1.4*t&&o>1.4*e&&o>80;else if(null!==S){const n=t-S.r,r=e-S.g,i=o-S.b;a=n*n+r*r+i*i<=T}if(a)continue}const o=.299*x[n]+.587*x[n+1]+.114*x[n+2];o<t&&(t=o),o>e&&(e=o)}k=t,C=e>t?e-t:255}const F=Q(e.invert),I=w&&e.charset.replace(/ /g,"")||e.charset,L=_(I),R=e.customText?null:J(I,F,e.brightness,e.contrast),H=e.customText?_(e.customText):null,W="fullcolor"===e.colorMode?new Uint8ClampedArray(f*m*4):void 0,j=[];for(let t=0;t<m;t++){let n="";for(let o=0;o<f;o++){const a=4*(t*d+o),r=a,i=x[a],s=x[a+1],h=x[a+2],c=x[a+3];if(w){let t=!1;if(y)t=s>1.4*i&&s>1.4*h&&s>80;else if(b)t=h>1.4*i&&h>1.4*s&&h>80;else if(null!==S){const e=i-S.r,n=s-S.g,o=h-S.b;t=e*e+n*n+o*o<=T}if(t){n+=" ",W&&(W[r]=0,W[r+1]=0,W[r+2]=0,W[r+3]=0);continue}}W&&(W[r]=i,W[r+1]=s,W[r+2]=h,W[r+3]=c);const l=.299*i+.587*s+.114*h,m=e.normalize?(l-k)/C*255:l,u=e.ditherStrength>0||H?E(m,e.brightness,e.contrast):m,M=e.ditherStrength>0?A(u,o,t,e.ditherStrength):u;if(H){n+=(F?1-M/255:M/255)<.12?" ":H[(t*f+o)%H.length]}else e.ditherStrength<=0?n+=R[Math.max(0,Math.min(255,0|m))]:n+=X(M,L,F)}j.push(n)}return{rows:j,cols:f,rowCount:m,colors:W}}function rt(t,e,n,o,a){if(0===e.rows.length)return;const r=t.canvas,i=Boolean(n.chromaKey)||e.rows.some(t=>t.includes(" "));i||(K.delete(t),t.clearRect(0,0,o,a),t.fillStyle=j(r)?"#0a0a0a":"#faf9f7",t.fillRect(0,0,o,a));const s=tt(n.accentColor),h=parseInt(s.substring(0,2),16),c=parseInt(s.substring(2,4),16),l=parseInt(s.substring(4,6),16),f=o/e.cols,m=a/e.rowCount,d=.9*Math.min(f/.55,m),u=e.colors;if("fullcolor"===n.colorMode&&u){K.delete(t),t.clearRect(0,0,o,a),t.font=`${d}px "JetBrains Mono", monospace`,t.textAlign="left",t.textBaseline="middle",t.globalAlpha=1;let n="";for(let o=0;o<e.rows.length;o++){const a=G(e.rows[o]);let r=0;for(;r<e.cols;){for(;r<e.cols&&" "===a[r];)r++;if(r>=e.cols)break;const i=r,s=4*(o*e.cols+r),h=240&u[s],c=240&u[s+1],l=240&u[s+2];for(r++;r<e.cols&&" "!==a[r];){const t=4*(o*e.cols+r);if((240&u[t])!==h||(240&u[t+1])!==c||(240&u[t+2])!==l)break;r++}const d=`rgb(${h},${c},${l})`;d!==n&&(t.fillStyle=d,n=d),t.fillText(a.slice(i,r).join(""),i*f+.5*f,o*m+.5*m)}}return void(t.globalAlpha=1)}t.font=`${d}px "JetBrains Mono", monospace`,t.textAlign="left",t.textBaseline="middle";const M="matrix"===n.colorMode?"rgb(0,255,0)":"grayscale"===n.colorMode?j(r)?"rgb(230,230,230)":"rgb(24,24,24)":`rgb(${h},${c},${l})`;t.fillStyle=M,t.globalAlpha=1;const g=K.get(t),p=i&&g&&g.cols===e.cols&&g.rowCount===e.rowCount&&g.canvasWidth===o&&g.canvasHeight===a&&g.fillStyle===M;p||t.clearRect(0,0,o,a);for(let n=0;n<e.rows.length;n++){const a=e.rows[n];p&&g.rows[n]===a||(p&&t.clearRect(0,n*m,o,m+1),0!==a.trim().length&&t.fillText(a,.5*f,n*m+.5*m))}K.set(t,{rows:e.rows.slice(),cols:e.cols,rowCount:e.rowCount,canvasWidth:o,canvasHeight:a,fillStyle:M}),t.globalAlpha=1}async function it(t,e,n,o,a=12,r=10,i,s=0){const h=Math.min(t.duration-s,r),c=Math.ceil(h*a),l=[];let f=0,m=0;for(let r=0;r<c;r++){const d=s+r/a;if(d>s+h)break;t.currentTime=d,await new Promise(e=>{const n=()=>{t.removeEventListener("seeked",n),e()};t.addEventListener("seeked",n)});const u=ot(t,e,n,o);l.push(u.frame),f=u.cols,m=u.rows,i?.((r+1)/c)}return{frames:l,cols:f,rows:m,fps:a}}async function st(t,e,n,o,a=12,r=10,i,s=0){const h=Math.min(t.duration-s,r),c=Math.ceil(h*a),l=[];let f=0,m=0;for(let r=0;r<c;r++){const d=s+r/a;if(d>s+h)break;t.currentTime=d,await new Promise(e=>{const n=()=>{t.removeEventListener("seeked",n),e()};t.addEventListener("seeked",n)});const u=at(t,e,n,o);l.push(u),f=u.cols,m=u.rowCount,i?.((r+1)/c)}return{frames:l,cols:f,rows:m,fps:a}}async function ht(t,e,n,o,a){const{parseGIF:r,decompressFrames:i}=await import("gifuct-js"),s=r(t),h=i(s,!0);if(0===h.length)return{frames:[],cols:0,rows:0,fps:10};const c=h[0].dims.width,l=h[0].dims.height,f=s.lsd?.width||c,m=s.lsd?.height||l,d=document.createElement("canvas");d.width=f,d.height=m;const u=d.getContext("2d"),M=document.createElement("canvas");M.width=f,M.height=m;const g=M.getContext("2d"),p=document.createElement("canvas"),x=p.getContext("2d"),v=[];let w=0,y=0,b=0;for(const t of h)b+=t.delay||100;const S=b/h.length,E=Math.round(Math.min(30,Math.max(5,1e3/S))),T=Math.min(h.length,300);let k=performance.now();for(let t=0;t<T;t++){performance.now()-k>8&&(await new Promise(t=>setTimeout(t,0)),k=performance.now());const r=h[t],{dims:i,patch:s,disposalType:c}=r;3===c&&(g.clearRect(0,0,f,m),g.drawImage(d,0,0)),p.width!==i.width&&(p.width=i.width),p.height!==i.height&&(p.height=i.height);const l=new ImageData(new Uint8ClampedArray(s.buffer),i.width,i.height);x.putImageData(l,0,0),u.drawImage(p,i.left||0,i.top||0);const b=ot(d,e,n,o);v.push(b.frame),w=b.cols,y=b.rows,2===c?u.clearRect(i.left||0,i.top||0,i.width,i.height):3===c&&(u.clearRect(0,0,f,m),u.drawImage(M,0,0)),a?.((t+1)/T)}return{frames:v,cols:w,rows:y,fps:E}}var ct=new WeakMap,lt=new WeakMap,ft=new WeakMap;function mt(t,e,n,o,a,r=0,i){if(!e.length||!e[0].length||o<=0||a<=0)return;let s=null;if(n.hoverStrength>0){let e=ct.get(t);e||(e={x:.5,y:.5,intensity:0,time:-1,emittedAt:-1,points:[]},ct.set(t,e)),s=function(t,e,n){const o=t.time<0?1/60:Math.max(0,Math.min(.1,(n-t.time)/1e3));t.time=n;const a=t.intensity<.003,r=t.x,i=t.y;if(e){a&&(t.x=e.x,t.y=e.y);const n=1-Math.exp(-o/.055);t.x+=(e.x-t.x)*n,t.y+=(e.y-t.y)*n}t.intensity+=((e?.intensity??(e?1:0))-t.intensity)*(1-Math.exp(-o/(e?.09:.18)));const s=Math.exp(-o/.22);for(const e of t.points)e.intensity*=s;for(;t.points.length&&t.points[0].intensity<.01;)t.points.shift();return e&&!a&&n-t.emittedAt>=24&&Math.hypot(t.x-r,t.y-i)>5e-4&&(t.points.push({x:t.x,y:t.y,intensity:t.intensity,vx:Math.max(-1,Math.min(1,(t.x-r)/Math.max(o,.001))),vy:Math.max(-1,Math.min(1,(t.y-i)/Math.max(o,.001)))}),t.points.length>12&&t.points.shift(),t.emittedAt=n),!e&&t.intensity<.003&&!t.points.length?(t.intensity=0,null):{x:t.x,y:t.y,intensity:t.intensity,trail:t.points}}(e,i??null,performance.now())}else ct.delete(t);if("none"!==n.animationStyle||n.charsetFrames?.length||n.hoverStrength<=0)return ft.delete(t),void dt(t,e,n,o,a,r,s);const h=lt.get(t);if(h?.frame!==e)return lt.set(t,{frame:e,since:performance.now()}),ft.delete(t),void dt(t,e,n,o,a,r,s);if(performance.now()-h.since<100)return void dt(t,e,n,o,a,r,s);const c=t.getTransform();if(c.b||c.c||c.a<=0||c.d<=0)return void dt(t,e,n,o,a,r,s);if(!s||(s.intensity??0)<.003)return void dt(t,e,n,o,a,r,null);const l=j(t.canvas),f={...n,accentColor:"#"+tt(n.accentColor)},m=JSON.stringify([f,o,a,c.a,c.d,l,void 0!==document.fonts?document.fonts.status:"loaded"]);let d=ft.get(t);if(!d||d.frame!==e||d.key!==m){const n=d?.canvas??document.createElement("canvas");n.width=Math.ceil(o*c.a),n.height=Math.ceil(a*c.d);const r=n.getContext("2d");r.setTransform(c.a,0,0,c.d,0,0),dt(r,e,f,o,a,0,null,void 0,l),d={frame:e,key:m,canvas:n},ft.set(t,d)}if(t.clearRect(0,0,o,a),t.drawImage(d.canvas,0,0,o,a),!s||(s.intensity??0)<.003)return;const u=e.length,M=e[0].length,g=.08+.35*n.hoverRadius+.04*n.hoverStrength,p="trail"===n.hoverEffect?[s,...s.trail??[]]:[s];let x=1,v=1,w=0,y=0;for(const t of p)x=Math.min(x,t.x-g),w=Math.max(w,t.x+g),v=Math.min(v,t.y-g),y=Math.max(y,t.y+g);if("glitchText"===n.hoverEffect){const t=n.hoverText,e=Math.max(1,...(Array.isArray(t)?t:[t]).map(t=>t.length));x=Math.min(x,s.x-e/M),w=Math.max(w,s.x+e/M)}const b=Math.ceil(5+4*n.hoverStrength),S={x:Math.max(0,Math.floor(x*M)-b),y:Math.max(0,Math.floor(v*u)-b),right:Math.min(M,Math.ceil(w*M)+b),bottom:Math.min(u,Math.ceil(y*u)+b)};t.save(),t.beginPath(),t.rect(S.x*o/M,S.y*a/u,(S.right-S.x)*o/M,(S.bottom-S.y)*a/u),t.clip(),dt(t,e,f,o,a,r,s,S,l),t.restore()}function dt(t,e,h,c,l,f=0,m,d,u){const M=e.length;if(0===M)return;const g=e[0].length;t.clearRect(0,0,c,l);let p=!1;const x=Math.max(1,M>>2),v=Math.max(1,g>>2);t:for(let t=0;t<M;t+=x){const n=e[t];for(let t=0;t<g;t+=v)if(n[t].a<200){p=!0;break t}}const w=t.canvas,y=u??j(w);p||(t.fillStyle=y?"#0a0a0a":"#faf9f7",t.fillRect(0,0,c,l));const S=c/g,E=l/M,T=m?.intensity??1,k=!!(m&&h.hoverStrength>0&&T>.005),A="#"+(Z(h.hoverColor||"#ffffff")??"ffffff"),C=parseInt(A.slice(1,3),16),F=parseInt(A.slice(3,5),16),L=parseInt(A.slice(5,7),16),H=tt(h.accentColor),W=parseInt(H.substring(0,2),16),P=parseInt(H.substring(2,4),16),$=parseInt(H.substring(4,6),16),O=h.hoverRadius;let q=0,D=g,U=0,V=M,B=0,N=0;if(k&&m){B=m.x,N=m.y;const t=.08+.35*O+.04*h.hoverStrength;q=Math.max(0,Math.floor((B-t)*g)-1),D=Math.min(g,Math.ceil((B+t)*g)+1),U=Math.max(0,Math.floor((N-t)*M)-1),V=Math.min(M,Math.ceil((N+t)*M)+1)}if(k&&"trail"===h.hoverEffect)for(const t of m?.trail??[]){const e=.08+.35*O+.04*h.hoverStrength;q=Math.min(q,Math.max(0,Math.floor((t.x-e)*g)-1)),D=Math.max(D,Math.min(g,Math.ceil((t.x+e)*g)+1)),U=Math.min(U,Math.max(0,Math.floor((t.y-e)*M)-1)),V=Math.max(V,Math.min(M,Math.ceil((t.y+e)*M)+1))}const K=h.animationStyle,Y=h.animationSpeed,G=function(t){const e=t&&Object.prototype.hasOwnProperty.call(n,t)?n[t]:t;return o.find(t=>t.value===e||t.mode===e)?.mode??"none"}(K),J="none"===G,et=[0,0,0,1],nt=J?void 0:b(e),ot=[0,0],at="relight"===(it=G)||"sheen"===it||"glow"===it||"shimmer"===it||"mist"===it,rt={char:" ",r:0,g:0,b:0,a:0};var it;const st=(t,n,o,h)=>{!function(t,e,n,o,s,h=.5,c,l=0){if(s[0]=s[1]=s[2]=0,s[3]=1,"none"===t)return s;h=a(h);const f=c?c[l]:h,m=c?c[l+1]:.5+.5*a(1-2*Math.hypot(e-.5,n-.55)),d=c?c[l+2]:r(.55,1,h)**2,u=c?c[l+3]:.5,M=c?c[l+4]:0,g=c?c[l+5]:0,p=o*Math.PI/6,x=(o%12+12)%12,v=r(0,.12,Math.min(e,1-e,n,1-n));if("relight"===t){const t=p+.6,o=Math.cos(t),a=Math.sin(t),i=Math.max(-1,Math.min(1,M*o+g*a))+.35*(o*(e-.5)+a*(n-.5));s[2]=.2*i*(.3+.7*r(.04,.3,f)*(1-.6*r(.82,1,h)))}else if("sheen"===t){const t=1.9*r(0,8,x)-.35,o=(.75*e+.45*n)/1.2+.05*(.75*M+.45*g),a=Math.exp(-(((o-t)/.12)**2));s[2]=a*r(.3,.8,f)*(1-.5*r(.9,1,h))*.45}else if("glow"===t){const t=.5-.5*Math.cos(p),e=1-.8*t;s[2]=.2*r(e-.3,e+.02,d)*Math.sqrt(d)*(1-.65*h)+.05*t*r(.6,.95,h)}else if("shimmer"===t){const t=i(Math.floor(160*e),Math.floor(100*n))*Math.PI*2,o=Math.pow(.5+.5*Math.cos(2*p+t),28);s[2]=o*r(.5,.88,h)*(.35+.65*r(.1,.55,u))*.42}else if("parallax"===t){const t=m-.45;s[0]=16*t*Math.sin(p)*v,s[1]=7*t*Math.sin(2*p)*v}else if("push"===t){const t=.045*(.5-.5*Math.cos(p))*(.7+.6*m)*960,o=c?c[l+6]:.5,a=c?c[l+7]:.5;s[0]=(e-o)*t,s[1]=(n-a)*t}else if("focus"===t){const t=Math.sin(p),e=t*t*r(.35,.85,t>=0?1-m:m);s[2]=(f-h)*e*.75}else if("mist"===t){const t=Math.pow(1-m,1.5)*(1-.6*u),o=.5*Math.sin(4.1*e-p+.9*Math.sin(3.3*n+p))+.3*Math.sin(7.3*e+2.1*n-2*p+1.1*Math.sin(2.7*e-5.1*n+p))+.2*Math.sin(5.7*n-1.9*e+p);s[2]=r(-.3,.9,o)*t*.16*(1-.55*h)}else if("current"===t){const t=c?.[l+8]??0,o=c?.[l+9]??0,a=c?.[l+10]??0,f=r(0,.06,Math.min(e,1-e,n,1-n)),d=c?0:(1-.4*u)*(1-.8*m)*v,M=t=>14*n-t+1.5*Math.sin(3*e+t),g=t=>16*n+2*e-t,x=t=>29*n-3*e-2*t,w=t=>1.7*e+2.3*n-t,y=t=>26*n+1.5*Math.sin(40*e)-2*t;s[0]=7*(Math.sin(M(p))-Math.sin(M(0))+.43*(Math.sin(5*e-3*n+p)-Math.sin(5*e-3*n)))*d+(3.5*(Math.sin(g(p))-Math.sin(g(0)))+1.5*(Math.sin(x(p))-Math.sin(x(0))))*t*f+5*(Math.sin(w(p))-Math.sin(w(0)))*o*f,s[1]=2*(Math.sin(11*e+p)-Math.sin(11*e))*d+.8*(Math.cos(g(p))-Math.cos(g(0)))*t*f+12*(Math.sin(y(p))-Math.sin(y(0)))*a*f;const b=Math.pow(.5+.5*Math.cos(2*p+9*e-4*n+6.2831853*i(Math.floor(160*e),Math.floor(100*n))),24)-Math.pow(.5+.5*Math.cos(9*e-4*n+6.2831853*i(Math.floor(160*e),Math.floor(100*n))),24);s[2]=.03*(Math.cos(M(p))-Math.cos(M(0)))*d+(b*r(.5,.85,h)*.3+.025*(Math.cos(g(p))-Math.cos(g(0))))*t*f+.08*(Math.cos(y(p))-Math.cos(y(0)))*a*f}else if("develop"===t){const t=r(7,8.5,x),o=a((x-8.5)/3.5),c=x<8.5?1-t:r(0,1,(1.45*o-(1-h)+.06*(i(Math.floor(160*e),Math.floor(100*n))-.5))/.3);s[2]=.3*-(1-c),s[3]=1-.9*(1-c)}}(G,t/g,n/M,f*Y,et,(.299*o.r+.587*o.g+.114*o.b)/255,nt,11*(n*g+t));let c=o;(et[0]||et[1])&&(!function(t,e,n,o,a,r){r[0]=s(Math.max(0,Math.min(o-1,e-t[0]/960*o))),r[1]=s(Math.max(0,Math.min(a-1,n-t[1]/960*a)))}(et,t,n,g,M,ot),c=e[Math.round(ot[1])][Math.round(ot[0])]);const l=255*et[2];return Math.abs(l)<.5&&1===et[3]?c:(rt.r=Math.max(0,Math.min(255,c.r+l)),rt.g=Math.max(0,Math.min(255,c.g+l)),rt.b=Math.max(0,Math.min(255,c.b+l)),rt.a=c.a*et[3],rt.char=c.char,rt.lum=c.lum,null!=c.lum&&(rt.lum=Math.max(0,Math.min(255,c.lum+l*(at?.45:1))),h&&Math.abs(l)>2&&(rt.char=X(rt.lum,h,mt))),rt)},ht=h.hoverStrength,ct=h.hoverEffect,lt=O,ft=h.hoverShape||"circle",mt=Q(h.invert,w),dt=h.colorMode,ut=2*Math.PI,Mt=1/g,gt=1/M;let pt="",xt=-1;if("dots"===h.renderMode){const n=.5*Math.min(S,E)*h.dotSizeRatio;for(let o=d?.y??0;o<(d?.bottom??M);o++){const a=e[o];for(let e=d?.x??0;e<(d?.right??g);e++){const r=J?a[e]:st(e,o,a[e]);if(r.a<10)continue;const i=.00392156863*(.299*r.r+.587*r.g+.114*r.b),s=mt?1-i:i;if(s<.02)continue;let h=1,f=0,d=0,u=0,M=0;if(k&&e>=q&&e<=D&&o>=U&&o<=V){const t=z(e*Mt,o*gt,B,N,T,ht,S,E,ct,lt,ft,m?.trail,c/l);h=t.scale,f=t.offsetX,d=t.offsetY,u=t.glow,M=t.colorBlend}const g=n*s*h;if(g<.3)continue;const p=e*S+.5*S+f,x=o*E+.5*E+d;let v;if(M>0){const t=R(r,dt,W,P,$,mt);v=`rgb(${Math.min(255,t[0]+(C-t[0])*M|0)},${Math.min(255,t[1]+(F-t[1])*M|0)},${Math.min(255,t[2]+(L-t[2])*M|0)})`}else v=I(r,dt,W,P,$,mt);const w=Math.min(1,.00392156863*r.a*(1+u));if(w!==xt&&(t.globalAlpha=w,xt=w),v!==pt&&(t.fillStyle=v,pt=v),g<=3){const e=2*g;t.fillRect(p-g,x-g,e,e)}else t.beginPath(),t.arc(p,x,g,0,ut),t.fill()}}}else{const n=.55,o=.9*Math.min(S/n,E);{const e=/\p{Extended_Pictographic}/u.test(h.customText||h.charset);t.font=e?`${o}px "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twemoji Mozilla", sans-serif`:`${o}px "JetBrains Mono", monospace`,t.textAlign="center",t.textBaseline="middle"}const a=h.charsetFrames,r=!!a?.length,i=r?a[Math.floor(Math.max(0,f)*(h.charsetFps??2))%a.length]:h.charset,s=t.getTransform();if(!k&&J&&!r&&"accent"===dt&&!d&&h.hoverStrength<=0&&!/\p{Extended_Pictographic}/u.test(h.customText||h.charset)&&"letterSpacing"in t&&/^[\x20-\x7e]*$/.test(h.customText||h.charset)&&e.every(t=>t.every(t=>t.a<10||255===t.a&&1===t.char.length&&/^[\x20-\x7e]$/.test(t.char)))){const n=t.letterSpacing;t.letterSpacing="0px";const o=t.measureText("M").width;t.letterSpacing=S-o+"px",t.fillStyle=`rgb(${W},${P},${$})`,t.globalAlpha=1,t.textAlign="left";for(let n=0;n<M;n++){const a=e[n];let r="";for(let t=0;t<g;t++){const e=a[t];r+=e.a<10?" ":e.char}0!==r.trim().length&&t.fillText(r,.5*(S-o),n*E+.5*E)}return t.letterSpacing=n,t.textAlign="center",void(t.globalAlpha=1)}const u="glitchText"===ct&&k,p="!@#$%^&*<>{}[]|/\\~`0123456789",x=p.length;let v="",w=0,y=0,b=0,A=0,H=0,j=0;if(u){const t=h.hoverText??"ASCIIFY";if(y=Math.round(B*g),b=Math.round(N*M),Array.isArray(t)){const e=t.filter(t=>t.length>0);0===e.length&&e.push("ASCIIFY");v=e[((7*Math.floor(y/Math.max(1,Math.ceil(g/5)))+13*Math.floor(b/Math.max(1,Math.ceil(M/3))))%e.length+e.length)%e.length]}else v=t||"ASCIIFY";w=v.length,A=Math.max(3,Math.min(12,Math.round(M*O*.6)));const e=Math.floor(A/2);H=Math.max(0,b-e),H+A>M&&(H=Math.max(0,M-A)),j=y-Math.floor(w/2)}for(let n=d?.y??0;n<(d?.bottom??M);n++){const o=e[n];for(let a=d?.x??0;a<(d?.right??g);a++){const d=J?o[a]:st(a,n,o[a],h.customText?void 0:_(i));if(d.a<10)continue;let O=r&&null!=d.lum?X(d.lum,_(i),mt):d.char;if(" "===O)continue;let K=1,Y=0,G=0,Q=0,Z=0;if(k&&!u&&a>=q&&a<=D&&n>=U&&n<=V){const t=z(a*Mt,n*gt,B,N,T,ht,S,E,ct,lt,ft,m?.trail,c/l);if(K=t.scale,Y=t.offsetX,G=t.offsetY,Q=t.glow,Z=t.colorBlend,"trail"===ct&&t.proximity>0){const o=Math.max(0,Math.min(g-1,Math.round(a-t.offsetX/S))),r=Math.max(0,Math.min(M-1,Math.round(n-t.offsetY/E))),s=e[r][o],h=s.lum??.299*s.r+.587*s.g+.114*s.b;O=X(Math.min(255,h+t.proximity*ht*65),_(i),mt)}}if(u&&n>=H&&n<H+A){const t=a-j;if(t>=0&&t<w){const e=v[t],o=Math.abs(n-b)/Math.max(1,.5*A),r=Math.abs(a-y)/Math.max(1,w),i=Math.max(o,r),s=Math.max(0,Math.min(1,1-.9*i)),h=43758.5453*Math.sin(127.1*a+311.7*n+43758.5453*Math.floor(12*f));O=Math.abs(h-Math.floor(h))<s?e:p[Math.abs(Math.floor(97*h))%x],Q=.3+.7*s,Z=.3+.65*s}}const tt=a*S+.5*S+Y,et=n*E+.5*E+G;let nt;if(Z>0){const t=R(d,dt,W,P,$,mt);nt=`rgb(${Math.min(255,t[0]+(C-t[0])*Z|0)},${Math.min(255,t[1]+(F-t[1])*Z|0)},${Math.min(255,t[2]+(L-t[2])*Z|0)})`}else nt=I(d,dt,W,P,$,mt);const ot=Math.min(1,.00392156863*d.a*(1+Q));ot!==xt&&(t.globalAlpha=ot,xt=ot),nt!==pt&&(t.fillStyle=nt,pt=nt),1!==K?(t.translate(tt,et),t.scale(K,K),t.fillText(O,0,0),t.setTransform(s)):t.fillText(O,tt,et)}}}t.globalAlpha=1}function ut(t="classic"){if("classic"!==t)throw new RangeError(`Art preset "${String(t)}" was removed in 4.1. Use a StudioStyle with asciify-engine/studio, or supply options.charset directly.`);return{artStyle:"classic"}}function Mt(t){return Math.max(0,Math.min(1,t))}function gt(t){return"string"==typeof t?document.querySelector(t):t instanceof HTMLElement?t:null}function pt(t){return"ascii"===t.renderMode&&"none"===t.animationStyle&&t.hoverStrength<=0&&!t.charsetFrames?.length}function xt(t,e={}){const n=Mt(t),o=Mt(n*(void 0===e.speed?1:Math.max(.001,e.speed)));return Mt(e.ease?e.ease(o):o)}function vt(t,e,n={}){if(!Number.isFinite(t.duration)||t.duration<=0)return;const o=n.from??0,a=n.to??t.duration,r=Math.max(o,Math.min(a,t.duration)),i=xt(e,n),s=o+(r-o)*i;t.currentTime=Math.min(Math.max(o,s),Math.max(o,r-.04)),n.onUpdate?.(i,t)}function wt(t,e){return Math.abs(t.currentTime-e)<1/240?yt(t):new Promise(n=>{const o=()=>{t.removeEventListener("seeked",o),n()};t.addEventListener("seeked",o,{once:!0});const a=t.fastSeek;a?a.call(t,e):t.currentTime=e})}function yt(t){const e=t.requestVideoFrameCallback;return new Promise(e?n=>{let o=!1;const a=()=>{o||(o=!0,n())};e.call(t,a),window.setTimeout(a,32)}:t=>requestAnimationFrame(()=>t()))}function bt(t,e={}){const n=gt(e.trigger)??t;t.pause();const o=e.gsap,a=e.ScrollTrigger??o?.ScrollTrigger;if(o&&a?.create){o.registerPlugin?.(a);const r=a.create({trigger:n,start:e.start??"top bottom",end:e.end??"bottom top",scrub:e.scrub??!0,onUpdate:n=>vt(t,n.progress,e)});return()=>r.kill?.()}return function(t,e,n){let o=0;const a=()=>{o=0;const a=e.getBoundingClientRect(),r=window.innerHeight||document.documentElement.clientHeight,i=a.height+r,s=i>0?Mt((r-a.top)/i):0;vt(t,s,n)},r=()=>{o||(o=requestAnimationFrame(a))};return window.addEventListener("scroll",r,{passive:!0}),window.addEventListener("resize",r),r(),()=>{window.removeEventListener("scroll",r),window.removeEventListener("resize",r),o&&cancelAnimationFrame(o)}}(t,n,e)}function St(t,e,n){const o=e.gsap,a=e.ScrollTrigger??o?.ScrollTrigger;if(o&&a?.create){o.registerPlugin?.(a);const r=a.create({trigger:t,start:e.start??"top bottom",end:e.end??"bottom top",scrub:e.scrub??!0,onUpdate:t=>n(t.progress)});return()=>r.kill?.()}return function(t,e){let n=0;const o=()=>{n=0;const o=t.getBoundingClientRect(),a=window.innerHeight||document.documentElement.clientHeight,r=o.height+a,i=r>0?Mt((a-o.top)/r):0;e(i)},a=()=>{n||(n=requestAnimationFrame(o))};return window.addEventListener("scroll",a,{passive:!0}),window.addEventListener("resize",a),a(),()=>{window.removeEventListener("scroll",a),window.removeEventListener("resize",a),n&&cancelAnimationFrame(n)}}(t,n)}function Et(t,e,n){if(!t||!e||!n.sourceCrop)return{w:t,h:e};const o=nt(n.sourceCrop,t,e);return{w:Math.max(1,Math.round(o.width)),h:Math.max(1,Math.round(o.height))}}function Tt(t,e,n,o){const a=o.chromaKey;if(null==a||!1===a)return!1;if(!0===a)return e>1.4*t&&e>1.4*n&&e>80;if("blue-screen"===a)return n>1.4*t&&n>1.4*e&&n>80;const r=P(a),i=(o.chromaKeyTolerance??60)**2,s=t-r.r,h=e-r.g,c=n-r.b;return s*s+h*h+c*c<=i}function kt(t,e,n){if(!e.chromaKey||!e.sourceCrop||"off"===e.chromaKeyTrimMode)return e;const o=t instanceof HTMLVideoElement?t.videoWidth:t.width,a=t instanceof HTMLVideoElement?t.videoHeight:t.height;if(!o||!a)return e;const r=nt(e.sourceCrop,o,a),i=Math.min(360,Math.max(1,Math.round(r.width))),s=Math.max(1,Math.round(i*(r.height/r.width))),{ctx:h}=S(i,s);h.drawImage(t,r.x,r.y,r.width,r.height,0,0,i,s);const c=h.getImageData(0,0,i,s).data,l=Math.max(0,Math.min(255,e.chromaKeyTrimLuminanceThreshold??0));let f=i,m=s,d=-1,u=-1;for(let t=0;t<s;t++)for(let n=0;n<i;n++){const o=4*(t*i+n),a=c[o+3],r=c[o],s=c[o+1],h=c[o+2];a<=8||.2126*r+.7152*s+.0722*h<=l||Tt(r,s,h,e)||(n<f&&(f=n),t<m&&(m=t),n>d&&(d=n),t>u&&(u=t))}if(d<f||u<m)return e;const M=Math.max(0,Math.min(.25,e.chromaKeyTrimPadding??.002)),g=Math.round(i*M),p=Math.round(s*M);f=Math.max(0,f-g),m=Math.max(0,m-p),d=Math.min(i-1,d+g),u=Math.min(s-1,u+p);const x=function(t,e,n,o,a){const r=a&&Number.isFinite(a)&&a>0?a:null;if(!r)return t;const i=e.x,s=e.y,h=e.x+e.width,c=e.y+e.height,l=Math.max(i,t.left),f=Math.max(s,t.top),m=Math.min(h,n-t.right),d=Math.min(c,o-t.bottom),u=Math.max(1,m-l),M=Math.max(1,d-f),g=l+u/2,p=f+M/2;let x=u,v=M;x/v<r?x=v*r:v=x/r;x>e.width&&(x=e.width,v=Math.max(M,Math.min(e.height,x/r)));v>e.height&&(v=e.height,x=Math.max(u,Math.min(e.width,v*r)));let w=g-x/2,y=p-v/2;return w=Math.max(i,Math.min(h-x,w)),y=Math.max(s,Math.min(c-v,y)),{left:w,top:y,right:n-(w+x),bottom:o-(y+v)}}({left:r.x+f/i*r.width,top:r.y+m/s*r.height,right:o-(r.x+(d+1)/i*r.width),bottom:a-(r.y+(u+1)/s*r.height)},{x:r.x,y:r.y,width:r.width,height:r.height},o,a,n);return{...e,sourceCrop:{unit:"pixel",...x,preserveAspect:!1}}}function At(t){const e=t.sourceCrop;return e&&"pixel"===e.unit?void 0===e.left||void 0===e.top||void 0===e.right||void 0===e.bottom?null:{left:e.left,top:e.top,right:e.right,bottom:e.bottom}:null}async function Ct(t,e,n,o,a){if(!e.chromaKey||!e.sourceCrop||"range"!==e.chromaKeyTrimMode)return e;const r=t.currentTime,i=function(t,e,n,o){const a=!0===o?{}:o||{},r=Math.max(0,a.from??e),i=a.to??n??(Number.isFinite(t.duration)?t.duration:r),s=Math.max(r,i-.04),h=Math.max(0,s-r),c=h>.1?[r,r+.25*h,r+.5*h,r+.75*h,s]:[r];return Array.from(new Set(c.map(t=>Math.max(0,Number(t.toFixed(3))))))}(t,n,o,a);let s=null;for(const n of i){await wt(t,n),await yt(t);const o=At(kt(t,e));o&&(s=s?{left:Math.min(s.left,o.left),top:Math.min(s.top,o.top),right:Math.min(s.right,o.right),bottom:Math.min(s.bottom,o.bottom)}:o)}return await wt(t,r),await yt(t),s?{...e,sourceCrop:{unit:"pixel",...s,preserveAspect:!0}}:e}function Ft(t,e,n=2048){return It({sourceWidth:t,sourceHeight:e,maxRenderDimension:n})}function It({sourceWidth:t,sourceHeight:e,cssWidth:n=0,cssHeight:o=0,maxRenderDimension:a=2048}){const r=Math.max(1,t),i=Math.max(1,e),s=r/i,h=Math.max(1,a),c=Math.min(1,h/Math.max(r,i)),l=Math.max(r,i)*c,f=Math.max(0,n,o),m=Math.min(h,Math.max(l,f));return s>=1?{renderW:Math.round(m),renderH:Math.round(m/s)}:{renderW:Math.round(m*s),renderH:Math.round(m)}}function Lt(t,e,n,o){if(void 0===t)return;if("number"==typeof t)return t;const a=t.trim();if(a.endsWith("%")){const t=Number.parseFloat(a)/100;return Number.isFinite(t)?e*t:void 0}if(a.endsWith("px")){const t=Number.parseFloat(a);return Number.isFinite(t)?t:void 0}if(a.endsWith("vw")){const t=Number.parseFloat(a)/100;return Number.isFinite(t)?n*t:void 0}if(a.endsWith("vh")){const t=Number.parseFloat(a)/100;return Number.isFinite(t)?o*t:void 0}}function Rt(t,e,n,o,a,r=2048,i={}){const{width:s,height:h}=e.getBoundingClientRect();if(!s||!h)return{renderW:0,renderH:0,dpr:1};const c="undefined"!=typeof window?window.innerWidth:s,l="undefined"!=typeof window?window.innerHeight:h,f=Lt(i.width,s,c,l)??s,m=Lt(i.height,h,c,l)??h,d=function(t,e,n,o,a){const r=t=>{const n=Lt(t,e,o,a);return n&&n>0?n:0},i=t=>{const e=Lt(t,n,o,a);return e&&e>0?e:0};return void 0===t?{x:0,y:0}:"number"==typeof t||"string"==typeof t?{x:r(t),y:i(t)}:{x:r(t.x),y:i(t.y)}}(i.bleed,s,h,c,l),u=f+2*d.x,M=m+2*d.y,{cssW:g,cssH:p}=function(t,e,n,o="contain"){if("fill"===o)return{cssW:t,cssH:e};let a=t,r=a/n;const i="cover"===o,s=r>e;return(i&&!s||!i&&s)&&(r=e,a=r*n),"scale-down"===o&&(a=Math.min(a,t),r=Math.min(r,e)),{cssW:Math.round(a),cssH:Math.round(r)}}(u,M,n,i.objectFit??"contain"),x="undefined"!=typeof window&&window.devicePixelRatio||1;let v,w;o&&a?({renderW:v,renderH:w}=It({sourceWidth:o,sourceHeight:a,cssWidth:g,cssHeight:p,maxRenderDimension:r})):(v=g,w=p);const y=8e6,b=v*x*w*x>y?Math.sqrt(y/(v*w)):x;return t.width=Math.round(v*b),t.height=Math.round(w*b),t.style.width=`${g}px`,t.style.height=`${p}px`,{renderW:v,renderH:w,dpr:b}}async function Ht(t,n,{fontSize:o,artStyle:a="classic",options:r={},fitTo:i,objectFit:s,objectPosition:h,scale:c,width:l,height:f,bleed:m,preExtract:d=!1,fps:u,maxRenderDimension:M=2048,trim:g,scroll:p,maxCachedFrames:x=90,onReady:v,onFrame:w}={}){const y=g?.start??0,b=g?.end,S=o??r.fontSize??10;let E={...e,...ut(a),artStyle:a,...r,fontSize:S};const T=n.getContext("2d");if(!T)throw new Error("asciifyVideo: could not get 2d context from canvas.");const k="string"==typeof i?document.querySelector(i):i instanceof HTMLElement?i:null,A={objectFit:s,objectPosition:h,scale:c,width:l,height:f,bleed:m},C=function(t,e){var n;if(!function(t){return void 0!==t.objectFit||void 0!==t.objectPosition||void 0!==t.scale||void 0!==t.width||void 0!==t.height||void 0!==t.bleed}(e))return()=>{};const o={width:t.style.width,height:t.style.height,objectFit:t.style.objectFit,objectPosition:t.style.objectPosition,maxWidth:t.style.maxWidth,maxHeight:t.style.maxHeight,transformOrigin:t.style.transformOrigin,scale:t.style.getPropertyValue("scale")};if(e.objectFit&&(t.style.objectFit=e.objectFit),e.objectPosition&&(t.style.objectPosition=e.objectPosition,t.style.transformOrigin=e.objectPosition),void 0===e.scale&&void 0===e.bleed||(t.style.maxWidth="none",t.style.maxHeight="none"),void 0!==e.scale){const o=Number.isFinite(e.scale)&&e.scale>0?e.scale:1;t.style.setProperty("scale",String(o)),(n=t.style).transformOrigin||(n.transformOrigin=e.objectPosition??"center center")}return()=>{t.style.width=o.width,t.style.height=o.height,t.style.objectFit=o.objectFit,t.style.objectPosition=o.objectPosition,t.style.maxWidth=o.maxWidth,t.style.maxHeight=o.maxHeight,t.style.transformOrigin=o.transformOrigin,o.scale?t.style.setProperty("scale",o.scale):t.style.removeProperty("scale")}}(n,A),F=t=>()=>{t(),C()};if(d){let e;"string"==typeof t?(e=document.createElement("video"),e.crossOrigin="anonymous",e.src=t,e.readyState<2&&await new Promise((n,o)=>{e.onloadeddata=()=>n(),e.onerror=()=>o(new Error(`asciifyVideo: failed to load "${t}"`))})):e=t,E=await Ct(e,E,y,b,p);const o=Et(e.videoWidth,e.videoHeight,E);k&&Rt(n,k,o.w/o.h,o.w,o.h,M,A);const{renderW:a,renderH:r}=Ft(o.w,o.h,M),i="undefined"!=typeof window&&window.devicePixelRatio||1,s=8e6,h=a*i*r*i>s?Math.sqrt(s/(a*r)):i;n.width===Math.round(a*h)&&n.height===Math.round(r*h)||(n.width=Math.round(a*h),n.height=Math.round(r*h));const c=void 0!==b?b-y:10,l=u??(p?18:void 0);if(pt(E)){const{frames:t,fps:o}=await st(e,E,a,r,l,c,void 0,y),i=e=>{const n=t[e];n&&(T.save(),T.setTransform(h,0,0,h,0,0),rt(T,n,E,a,r),T.restore(),w?.())};if(p){let o=!1,a=-1;const r=!0===p?{}:p,s=St(gt(r.trigger)??k??n,r,n=>{const s=xt(n,r),h=Math.max(0,Math.min(t.length-1,Math.round(s*(t.length-1))));h!==a&&(a=h,i(h),o||(o=!0,v?.(e)),r.onUpdate?.(s,e))});return i(0),o=!0,v?.(e),F(s)}let s=!1,f=0,m=0,d=performance.now(),u=!0,M=!0;const g=1e3/o,x=n=>{f=0,s||!u&&!M||(n-d>=g&&(i(m),m=(m+1)%t.length,d=n,M&&(M=!1,v?.(e))),f=requestAnimationFrame(x))},b="function"==typeof IntersectionObserver?new IntersectionObserver(([t])=>{u=t.isIntersecting,!u||f||s||(f=requestAnimationFrame(x))}):null;return b?.observe(n),f=requestAnimationFrame(x),F(()=>{s=!0,cancelAnimationFrame(f),b?.disconnect()})}const{frames:f,fps:m}=await it(e,E,a,r,l,c,void 0,y);if(!f.length)throw new Error("asciifyVideo: no frames were decoded.");let d=0;const g=performance.now(),x=q(n,(t,e)=>{p||(d=Math.floor((t-g)*m/1e3)%f.length),T.save(),T.setTransform(h,0,0,h,0,0),mt(T,f[d],E,a,r,(t-g)/1e3,e),T.restore(),w?.()},{continuous:!p||"none"!==E.animationStyle||!!E.charsetFrames?.length,interactive:E.hoverStrength>0});let S;if(p){const t=!0===p?{}:p;S=St(gt(t.trigger)??k??n,t,n=>{d=Math.max(0,Math.min(f.length-1,Math.round(xt(n,t)*(f.length-1)))),x.wake(),t.onUpdate?.(n,e)})}return v?.(e),F(()=>{x.stop(),S?.()})}let I,L=!1;"string"==typeof t?(I=document.createElement("video"),I.crossOrigin="anonymous",I.src=t,I.muted=!0,I.loop=!0,I.playsInline=!0,I.setAttribute("playsinline",""),Object.assign(I.style,{position:"fixed",top:"0",left:"0",width:"1px",height:"1px",opacity:"0",pointerEvents:"none",zIndex:"-1"}),document.body.appendChild(I),L=!0,await new Promise((e,n)=>{I.onloadedmetadata=()=>e(),I.onerror=()=>n(new Error(`asciifyVideo: failed to load "${t}"`))}),await I.play().catch(()=>{})):(I=t,I.readyState<HTMLMediaElement.HAVE_METADATA&&await new Promise((t,e)=>{const n=()=>{I.removeEventListener("loadedmetadata",o),I.removeEventListener("error",a)},o=()=>{n(),t()},a=()=>{n(),e(new Error("asciifyVideo: provided video element failed to load metadata."))};I.addEventListener("loadedmetadata",o),I.addEventListener("error",a),I.load()}),I.paused&&await I.play().catch(()=>{})),y>0&&(I.currentTime=y,await new Promise(t=>{const e=()=>{I.removeEventListener("seeked",e),t()};I.addEventListener("seeked",e)}),await yt(I));let R=null;(y>0||void 0!==b)&&(R=()=>{(void 0!==b&&I.currentTime>=b||y>0&&I.currentTime<y)&&(I.currentTime=y)},I.addEventListener("timeupdate",R)),E=await Ct(I,E,y,b,p);let H=null;const W=Et(I.videoWidth,I.videoHeight,E);let{renderW:j,renderH:P}=Ft(W.w,W.h,M);const $=t=>"frame"===E.chromaKeyTrimMode?kt(t,E,j/P):E;if(k){const t=W.w/W.h,e=W.w,o=W.h,a=Rt(n,k,t,e,o,M,A);j=a.renderW,P=a.renderH;const r=n.getContext("2d");r&&r.setTransform(a.dpr,0,0,a.dpr,0,0),H=new ResizeObserver(()=>{const a=Rt(n,k,t,e,o,M,A);j=a.renderW,P=a.renderH;const r=n.getContext("2d");r&&r.setTransform(a.dpr,0,0,a.dpr,0,0)}),H.observe(k)}else{const t="undefined"!=typeof window&&window.devicePixelRatio||1,e=8e6,o=j*t*P*t>e?Math.sqrt(e/(j*P)):t;n.width===Math.round(j*o)&&n.height===Math.round(P*o)||(n.width=Math.round(j*o),n.height=Math.round(P*o)),T.setTransform(o,0,0,o,0,0)}let O=!0,z=null;const D=p&&!d,U=u&&u>0?1e3/u:0;let V=0;const B=!D&&pt(E);if(D&&"ascii"===E.renderMode&&"none"===E.animationStyle&&E.hoverStrength<=0&&!E.charsetFrames?.length){const t=!0===p?{}:p,e=gt(t.trigger)??k??n,o=t.from??y,a=t.to??b??I.duration,r=Math.max(o,Math.min(a,I.duration)),i=Math.max(.001,r-o),s=Math.min(60,Math.max(12,u??30)),h=Math.max(2,Math.ceil(i*s)+1),c=new Array(h),l=[],f=Math.max(2,Math.min(h,Math.floor(x))),m=()=>{for(;l.length>f;){const t=l.findIndex(t=>t!==M&&Math.abs(t-M)>2),e=t>=0?t:0,n=l.splice(e,1)[0];void 0!==n&&(c[n]=void 0)}},d=t=>{const e=l.indexOf(t);e>=0&&l.splice(e,1),l.push(t),m()};let M=0,g=0,S=-1,A=0,C=!0,W=!1,O=!1,q=!1;const D=new Set,B=document.createElement("video");B.muted=!0,B.playsInline=!0,B.preload="auto",B.crossOrigin=I.crossOrigin||"anonymous",B.src=I.currentSrc||I.src,Object.assign(B.style,{position:"fixed",top:"0",left:"0",width:"1px",height:"1px",opacity:"0",pointerEvents:"none",zIndex:"-1"}),document.body.appendChild(B),B.readyState<HTMLMediaElement.HAVE_METADATA&&await new Promise((t,e)=>{const n=()=>{B.removeEventListener("loadedmetadata",o),B.removeEventListener("error",a)},o=()=>{n(),t()},a=()=>{n(),e(new Error("asciifyVideo: cache video failed to load metadata."))};B.addEventListener("loadedmetadata",o),B.addEventListener("error",a),B.load()}),B.pause(),I.paused&&await I.play().catch(()=>{});const N=t=>o+i*t/Math.max(1,h-1),K=t=>Math.max(0,Math.min(h-1,Math.round(t*(h-1)))),Y=$(I),_=at(I,Y,j,P);_.rows.length>0&&(c[0]=_,d(0),rt(T,_,Y,j,P),q=!0,v?.(I),w?.());const G=t=>{if(c[t])return t;for(let e=1;e<h;e++){const n=t-e,o=t+e;if(n>=0&&c[n])return n;if(o<h&&c[o])return o}return-1},X=()=>{if(!c[M])return M;for(const t of D)if(!c[t])return t;for(let t=1;t<h;t++){const e=M-t,n=M+t;if(e>=0&&!c[e])return e;if(n<h&&!c[n])return n}return-1},J=t=>{t<0||t>=h||c[t]||(D.add(t),Q())},Q=async()=>{if(W||O)return;const t=X();if(!(t<0)){D.delete(t),O=!0;try{if(await wt(B,N(t)),!W){const e=$(B),n=at(B,e,j,P);n.rows.length>0&&(c[t]=n,d(t))}}finally{O=!1,W||requestAnimationFrame(()=>{Q()})}}},Z=()=>{if(A=0,W||!C&&q)return;const t=G(M);if(t>=0&&t!==S){const e=c[t];e&&(rt(T,e,E,j,P),S=t,q||(q=!0,v?.(I)),w?.())}else if(t<0||S<0){const t=performance.now();if(U<=0||t-V>=U){const e=$(I),n=at(I,e,j,P);n.rows.length>0&&(rt(T,n,e,j,P),V=t,q||(q=!0,v?.(I)),w?.())}}J(M),A=requestAnimationFrame(Z)};z=St(e,t,e=>{const n=function(t,e,n={}){if(!Number.isFinite(t.duration)||t.duration<=0)return null;const o=n.from??0,a=n.to??t.duration,r=Math.max(o,Math.min(a,t.duration)),i=xt(e,n),s=o+(r-o)*i;return{progress:i,time:Math.min(Math.max(o,s),Math.max(o,r-.04))}}(I,e,{...t,from:o,to:r});g=n?.progress??Mt(e),M=K(g),J(M),J(M-1),J(M+1),J(M-2),J(M+2),J(M-3),J(M+3),t.onUpdate?.(g,I)}),J(0),J(1);const tt="function"==typeof IntersectionObserver?new IntersectionObserver(([t])=>{C=t.isIntersecting,!C||A||W||(A=requestAnimationFrame(Z))}):null;return tt?.observe(n),A=requestAnimationFrame(Z),F(()=>{W=!0,cancelAnimationFrame(A),tt?.disconnect(),z?.(),H?.disconnect(),D.clear(),l.length=0,c.fill(void 0),B.pause(),B.src="",B.removeAttribute("src"),B.load(),B.isConnected&&B.remove(),R&&I.removeEventListener("timeupdate",R),L&&(I.pause(),I.src="",I.removeAttribute("src"),I.load(),I.isConnected&&I.remove())})}if(D){const t=!0===p?{}:p;z=bt(I,{...t,trigger:t.trigger??k??n,from:t.from??y,to:t.to??b})}let N=-1,K=0,Y=-1,_=0;const G="function"==typeof I.requestVideoFrameCallback,X=()=>{_=I.requestVideoFrameCallback(()=>{K++,X()})};G&&X();let J=0,Q=0,Z=null;const tt=q(n,(t,e)=>{if(I.readyState<2||0===n.width||0===n.height)return;if(U>0&&t-V<U&&!e)return;if(y>0&&I.currentTime<y)return;if(void 0!==b&&I.currentTime>=b)return;const o=(G?K!==Y:I.currentTime!==N)||J!==j||Q!==P;if(o||!(E.hoverStrength<=0)||"none"!==E.animationStyle||E.charsetFrames?.length){if(B){const t=$(I),e=at(I,t,j,P);rt(T,e,t,j,P)}else!o&&Z||(Z=ot(I,$(I),j,P).frame),mt(T,Z,E,j,P,t/1e3,e);N=I.currentTime,Y=K,J=j,Q=P,V=t,O&&(O=!1,v?.(I)),w?.()}},{continuous:!0,interactive:E.hoverStrength>0});return F(()=>{tt.stop(),_&&I.cancelVideoFrameCallback(_),z?.(),H?.disconnect(),R&&I.removeEventListener("timeupdate",R),L&&(I.pause(),I.src="",I.removeAttribute("src"),I.load(),I.isConnected&&I.remove())})}function Wt(t,e,n,o="#505050",a=100){if(!t||e<=0||n<=0)return[];const r=function(t){const e=t.match(/^#([0-9a-f]{3,8})$/i)?.[1];if(e){const t=e.length<=4?e.split("").map(t=>parseInt(t+t,16)):[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)];return{r:t[0],g:t[1],b:t[2]}}const n=t.match(/rgba?\(\s*(\d+)[,\s]+(\d+)[,\s]+(\d+)/i);return n?{r:+n[1],g:+n[2],b:+n[3]}:null}(o)??{r:80,g:80,b:80},i=t,s=i.length;return Array.from({length:n},(t,n)=>Array.from({length:e},(t,o)=>({char:i[(n*e+o)%s],r:r.r,g:r.g,b:r.b,a:a})))}var jt=new WeakMap;function Pt(t,{format:e="png",quality:n=.92,scale:o=1}={}){return new Promise((a,r)=>{let i=t;if(1!==o){const e=document.createElement("canvas");e.width=Math.round(t.width*o),e.height=Math.round(t.height*o);const n=e.getContext("2d");if(!n)return void r(new Error("captureSnapshot: could not get 2d context"));n.drawImage(t,0,0,e.width,e.height),i=e}i.toBlob(t=>t?a(t):r(new Error("captureSnapshot: toBlob returned null")),`image/${e}`,n)})}var $t={A:[28,54,99,127,99,99,99],B:[126,99,99,126,99,99,126],C:[62,99,96,96,96,99,62],D:[124,102,99,99,99,102,124],E:[127,96,96,124,96,96,127],F:[127,96,96,124,96,96,96],G:[62,99,96,111,99,99,62],H:[99,99,99,127,99,99,99],I:[127,8,8,8,8,8,127],J:[63,6,6,6,102,102,60],K:[99,102,108,120,108,102,99],L:[96,96,96,96,96,96,127],M:[99,119,107,107,99,99,99],N:[99,115,107,103,99,99,99],O:[62,99,99,99,99,99,62],P:[126,99,99,126,96,96,96],Q:[62,99,99,99,107,102,61],R:[126,99,99,126,108,102,99],S:[62,99,96,62,3,99,62],T:[127,8,8,8,8,8,8],U:[99,99,99,99,99,99,62],V:[99,99,99,99,54,28,8],W:[99,99,99,107,107,54,20],X:[99,54,28,8,28,54,99],Y:[99,99,54,28,8,8,8],Z:[127,3,6,12,24,48,127],a:[0,0,60,3,62,99,61],b:[96,96,124,99,99,99,124],c:[0,0,62,96,96,96,62],d:[3,3,31,99,99,99,31],e:[0,0,62,99,127,96,62],f:[30,48,48,126,48,48,48],g:[0,0,63,99,63,3,62],h:[96,96,124,99,99,99,99],i:[8,0,24,8,8,8,28],j:[4,0,12,4,4,36,24],k:[96,96,102,108,120,108,102],l:[24,8,8,8,8,8,28],m:[0,0,92,107,107,99,99],n:[0,0,94,99,99,99,99],o:[0,0,62,99,99,99,62],p:[0,0,126,99,126,96,96],q:[0,0,63,99,63,3,3],r:[0,0,94,99,96,96,96],s:[0,0,62,96,62,3,124],t:[48,48,126,48,48,48,30],u:[0,0,99,99,99,103,59],v:[0,0,99,99,54,28,8],w:[0,0,99,99,107,54,20],x:[0,0,99,54,28,54,99],y:[0,0,99,99,63,3,62],z:[0,0,127,6,12,24,127],0:[62,99,103,107,115,99,62],1:[8,24,56,8,8,8,62],2:[62,99,3,6,24,48,127],3:[62,99,3,30,3,99,62],4:[6,14,22,38,127,6,6],5:[127,96,126,3,3,99,62],6:[62,99,96,126,99,99,62],7:[127,3,6,12,24,24,24],8:[62,99,99,62,99,99,62],9:[62,99,99,63,3,99,62]," ":[0,0,0,0,0,0,0],"!":[24,24,24,24,24,0,24],"?":[62,99,3,14,8,0,8],".":[0,0,0,0,0,24,24],",":[0,0,0,0,0,24,48],";":[0,24,24,0,24,24,48],":":[0,24,24,0,24,24,0],"-":[0,0,0,62,0,0,0],_:[0,0,0,0,0,0,127],"'":[24,24,32,0,0,0,0],'"':[54,54,36,0,0,0,0],"`":[24,8,0,0,0,0,0],")":[24,12,6,6,6,12,24],"(":[12,24,48,48,48,24,12],"[":[60,48,48,48,48,48,60],"]":[30,6,6,6,6,6,30],"{":[14,24,24,48,24,24,14],"}":[56,12,12,6,12,12,56],"/":[3,6,12,24,48,96,0],"\\":[96,48,24,12,6,3,0],"|":[8,8,8,8,8,8,8],"+":[0,8,8,62,8,8,0],"=":[0,0,62,0,62,0,0],"*":[0,42,28,127,28,42,0],"#":[36,36,127,36,127,36,36],"@":[62,99,111,107,111,96,62],"&":[24,36,24,60,74,68,58],"%":[99,38,4,8,16,50,99],$:[8,62,72,62,9,62,8],"^":[8,20,34,0,0,0,0],"~":[0,0,50,76,0,0,0],"<":[6,12,24,48,24,12,6],">":[48,24,12,6,12,24,48]},Ot=[127,65,65,65,65,65,127];function zt(t){return $t[t]??$t[t.toUpperCase()]??Ot}function qt(t,e={}){if(!t)return"";const{char:n="█",scale:o=1}=e,a=[...n][0]??"█",r=Math.max(1,Math.floor(o)),i=7*r,s=r,h=Array.from({length:i},()=>"");for(let e=0;e<t.length;e++){const n=zt(t[e]);for(let t=0;t<7;t++){const e=n[t];let o="";for(let t=6;t>=0;t--)o+=(e>>t&1?a:" ").repeat(r);for(let e=0;e<r;e++)h[t*r+e]+=o}if(e<t.length-1)for(let t=0;t<i;t++)h[t]+=" ".repeat(s)}return h.join("\n")}var Dt=["ascii","blocks","braille","dots","lines","cross","diagonal","diamond","mixed","pixel","mosaic","lego","voxel","disco","dither","hex","led","cmyk","stipple","engraving","crosshatch","woodblock","risograph","pointillism"];exports.CHARACTER_SETS=t,exports.DEFAULT_OPTIONS=e,exports.HOVER_PRESETS={none:{label:"Off",options:{hoverStrength:0,hoverEffect:"spotlight",hoverRadius:.2,hoverColor:"#ffffff"}},subtle:{label:"Subtle",options:{hoverStrength:.25,hoverEffect:"glow",hoverRadius:.12,hoverColor:"#ffffff"}},flashlight:{label:"Flashlight",options:{hoverStrength:.6,hoverEffect:"spotlight",hoverRadius:.15,hoverColor:"#fffbe6"}},magnifier:{label:"Magnifier",options:{hoverStrength:.7,hoverEffect:"magnify",hoverRadius:.12,hoverColor:"#ffffff"}},forceField:{label:"Force Field",options:{hoverStrength:.7,hoverEffect:"repel",hoverRadius:.15,hoverColor:"#a0e8ff"}},neon:{label:"Neon",options:{hoverStrength:.6,hoverEffect:"colorShift",hoverRadius:.15,hoverColor:"#d946ef"}},fire:{label:"Fire",options:{hoverStrength:.7,hoverEffect:"spotlight",hoverRadius:.15,hoverColor:"#ff6b2b"}},ice:{label:"Ice",options:{hoverStrength:.5,hoverEffect:"glow",hoverRadius:.15,hoverColor:"#60d5f7"}},gravity:{label:"Gravity",options:{hoverStrength:.7,hoverEffect:"attract",hoverRadius:.18,hoverColor:"#a5d6ff"}},shatter:{label:"Shatter",options:{hoverStrength:.8,hoverEffect:"shatter",hoverRadius:.14,hoverColor:"#ff6090"}},ghost:{label:"Fluid trail",options:{hoverStrength:.55,hoverEffect:"trail",hoverRadius:.2,hoverColor:"#b39ddb"}},glitchReveal:{label:"Glitch Reveal",options:{hoverStrength:.8,hoverEffect:"glitchText",hoverRadius:.18,hoverColor:"#a3e635"}}},exports.PALETTE_THEMES={dracula:{name:"Dracula",accent:"#bd93f9",bg:"#282a36",fg:"#f8f8f2"},monokai:{name:"Monokai",accent:"#a6e22e",bg:"#272822",fg:"#f8f8f2"},nord:{name:"Nord",accent:"#88c0d0",bg:"#2e3440",fg:"#eceff4"},catppuccin:{name:"Catppuccin",accent:"#cba6f7",bg:"#1e1e2e",fg:"#cdd6f4"},solarized:{name:"Solarized",accent:"#268bd2",bg:"#002b36",fg:"#839496"},gruvbox:{name:"Gruvbox",accent:"#b8bb26",bg:"#282828",fg:"#ebdbb2"}},exports.STUDIO_STYLES=Dt,exports.asciiText=function(t,n={},o,a){const r={...e,...n},{frame:i,cols:s}=ot(t,r,o,a);if(!i.length||0===s)return"";const h=[];for(const t of i)h.push(t.map(t=>t.char).join(""));return h.join("\n")},exports.asciiTextAnsi=function(t,n={},o,a){const r={...e,...n},{frame:i,cols:s}=ot(t,r,o,a);if(!i.length||0===s)return"";const h=[];for(const t of i){let e="";for(const n of t)" "===n.char||n.a<10?e+=" ":e+=`[38;2;${n.r};${n.g};${n.b}m${n.char}`;h.push(e)}return h.join("\n")},exports.asciify=async function(t,n,{fontSize:o,artStyle:a="classic",options:r={}}={}){let i;if("string"==typeof t){const e=new Image;e.crossOrigin="anonymous",await new Promise((n,o)=>{e.onload=()=>n(),e.onerror=()=>o(new Error(`Failed to load image: ${t}`)),e.src=t}),i=e}else t instanceof HTMLImageElement&&!t.complete?(await new Promise((e,n)=>{t.onload=()=>e(),t.onerror=()=>n(new Error("Image failed to load"))}),i=t):i=t;const s=ut(a),h=o??r.fontSize??10,c={...e,...s,artStyle:a,...r,fontSize:h},l=n.getContext("2d");if(!l)throw new Error("Could not get 2d context from canvas");const{w:f,h:m}=function(t){return t instanceof HTMLVideoElement?{w:t.videoWidth,h:t.videoHeight}:t instanceof HTMLImageElement?{w:t.naturalWidth||t.width,h:t.naturalHeight||t.height}:{w:t.width,h:t.height}}(i),{renderW:d,renderH:u}=Ft(f,m),M="undefined"!=typeof window&&window.devicePixelRatio||1,g=8e6,p=d*M*u*M>g?Math.sqrt(g/(d*u)):M;n.width===Math.round(d*p)&&n.height===Math.round(u*p)||(n.width=Math.round(d*p),n.height=Math.round(u*p));const{frame:x}=ot(i,c,d,u),v=(t,e)=>{l.save(),l.setTransform(p,0,0,p,0,0),mt(l,x,c,d,u,t/1e3,e),l.restore()};return v(0,null),q(n,v,{continuous:"none"!==c.animationStyle||!!c.charsetFrames?.length,interactive:c.hoverStrength>0}).stop},exports.asciifyGif=async function(t,n,{fontSize:o,artStyle:a="classic",options:r={}}={}){const i="string"==typeof t?await fetch(t).then(t=>t.arrayBuffer()):t,s=o??r.fontSize??10;let h={...e,...ut(a),artStyle:a,...r,fontSize:s};const c=n.getContext("2d");if(!c)throw new Error("Could not get 2d context from canvas");const{frames:l,fps:f}=await ht(i,h,n.width,n.height);if(!l.length)throw new Error("asciifyGif: the GIF contains no renderable frames.");const m=performance.now();let d=-1;return q(n,(t,e)=>{const o=Math.floor((t-m)*f/1e3)%l.length;o===d&&!e&&h.hoverStrength<=0&&"none"===h.animationStyle&&!h.charsetFrames?.length||(mt(c,l[o],h,n.width,n.height,(t-m)/1e3,e),d=o)},{continuous:!0,interactive:h.hoverStrength>0}).stop},exports.asciifyLiveVideo=function(t,e,n){return Ht(t,e,n)},exports.asciifyText=qt,exports.asciifyVideo=Ht,exports.asciifyWebcam=async function(t,{fontSize:n=10,style:o="classic",options:a={},liveOptions:r,mirror:i=!0,constraints:s={facingMode:"user"},dpr:h}={}){if(!navigator.mediaDevices?.getUserMedia)throw new Error("asciifyWebcam: getUserMedia is not supported in this browser.");const c=ut(o),l=await navigator.mediaDevices.getUserMedia({video:s}),f=document.createElement("video");f.srcObject=l,f.muted=!0,f.playsInline=!0,await new Promise((t,e)=>{f.onloadedmetadata=()=>t(),f.onerror=()=>e(new Error("asciifyWebcam: video stream failed to load.")),f.play().catch(e)});const m={...e,...c,...a,fontSize:n},d=t.getContext("2d");if(!d)throw new Error("asciifyWebcam: could not get 2d context from canvas.");const u=h??("undefined"!=typeof window?window.devicePixelRatio:1)??1;1!==u&&d.scale(u,u);let M=null;const g=e=>{const n=t.getBoundingClientRect();M={x:(e.clientX-n.left)/n.width,y:(e.clientY-n.top)/n.height}},p=()=>{M=null};m.hoverStrength>0&&(t.addEventListener("mousemove",g),t.addEventListener("mouseleave",p));let x,v=!1;const w=performance.now(),y=e=>{if(!v){if(f.readyState>=f.HAVE_CURRENT_DATA){const n=t.width/u,o=t.height/u,a=(e-w)/1e3,s=r?{...m,...r()}:m;s.hoverStrength>0?(t.addEventListener("mousemove",g),t.addEventListener("mouseleave",p)):(t.removeEventListener("mousemove",g),t.removeEventListener("mouseleave",p));const{frame:h}=ot(f,s,n,o),c=M&&i?{x:1-M.x,y:M.y}:M;i?(d.save(),d.scale(-1,1),d.translate(-n,0),mt(d,h,s,n,o,a,c),d.restore()):mt(d,h,s,n,o,a,c)}x=requestAnimationFrame(y)}};return x=requestAnimationFrame(y),()=>{v=!0,cancelAnimationFrame(x),t.removeEventListener("mousemove",g),t.removeEventListener("mouseleave",p),l.getTracks().forEach(t=>t.stop()),f.srcObject=null}},exports.buildTextFrame=Wt,exports.captureSnapshot=Pt,exports.clearAsciifyCaches=function(){B.clear(),N.clear(),ct=new WeakMap,ft=new WeakMap,lt=new WeakMap,D=null,U=null},exports.computeCanvasRenderSize=It,exports.createVideoScrollScrub=bt,exports.gifToAsciiFrames=ht,exports.gifToAsciiTextFrames=async function(t,e,n,o,a){const{parseGIF:r,decompressFrames:i}=await import("gifuct-js"),s=r(t),h=i(s,!0);if(0===h.length)return{frames:[],cols:0,rows:0,fps:10};const c=h[0].dims.width,l=h[0].dims.height,f=s.lsd?.width||c,m=s.lsd?.height||l,d=document.createElement("canvas");d.width=f,d.height=m;const u=d.getContext("2d"),M=document.createElement("canvas");M.width=f,M.height=m;const g=M.getContext("2d"),p=document.createElement("canvas"),x=p.getContext("2d"),v=[];let w=0,y=0,b=0;for(const t of h)b+=t.delay||100;const S=b/h.length,E=Math.round(Math.min(30,Math.max(5,1e3/S))),T=Math.min(h.length,300);let k=performance.now();for(let t=0;t<T;t++){performance.now()-k>8&&(await new Promise(t=>setTimeout(t,0)),k=performance.now());const r=h[t],{dims:i,patch:s,disposalType:c}=r;3===c&&(g.clearRect(0,0,f,m),g.drawImage(d,0,0)),p.width!==i.width&&(p.width=i.width),p.height!==i.height&&(p.height=i.height);const l=new ImageData(new Uint8ClampedArray(s.buffer),i.width,i.height);x.putImageData(l,0,0),u.drawImage(p,i.left||0,i.top||0);const b=at(d,e,n,o);v.push(b),w=b.cols,y=b.rowCount,2===c?u.clearRect(i.left||0,i.top||0,i.width,i.height):3===c&&(u.clearRect(0,0,f,m),u.drawImage(M,0,0)),a?.((t+1)/T)}return{frames:v,cols:w,rows:y,fps:E}},exports.imageToAsciiFrame=ot,exports.imageToAsciiTextFrame=at,exports.renderFrameToCanvas=mt,exports.renderTextBackground=function(t,n,o,a,r={},i){const{fontSize:s=10,lineHeight:h=1.6,color:c="#505050",opacity:l=100,hoverEffect:f="spotlight",hoverStrength:m=.85,hoverRadius:d=.18,hoverColor:u="#d4ff00"}=r,M=Math.max(1,Math.floor(n/s)),g=Math.max(1,Math.floor(o/(s*h))),p=JSON.stringify([a,M,g,c,l]);let x=jt.get(t);x&&x.key===p||(x={key:p,frame:Wt(a,M,g,c,l)},jt.set(t,x)),mt(t,x.frame,{...e,fontSize:s,hoverEffect:f,hoverStrength:m,hoverRadius:d,hoverColor:u},n,o,0,i??null)},exports.renderTextFrameToCanvas=rt,exports.renderTextToCanvas=function(t,e,n={}){const{color:o="#d4ff00",bgColor:a,fontSize:r=10}=n,i=qt(e,n);if(!i)return;const s=i.split("\n"),h=Math.max(...s.map(t=>[...t].length));t.width=Math.ceil(h*r*.6),t.height=Math.ceil(s.length*r);const c=t.getContext("2d");a&&"transparent"!==a?(c.fillStyle=a,c.fillRect(0,0,t.width,t.height)):c.clearRect(0,0,t.width,t.height),c.fillStyle=o,c.font=`${r}px monospace`,c.textBaseline="top",s.forEach((t,e)=>c.fillText(t,0,e*r))},exports.snapshotAndDownload=async function(t,e={}){const{filename:n="asciify-snapshot",format:o="png",...a}=e,r=await Pt(t,{format:o,...a}),i="jpeg"===o?"jpg":o,s=document.createElement("a");s.href=URL.createObjectURL(r),s.download=`${n}.${i}`,s.click(),setTimeout(()=>URL.revokeObjectURL(s.href),1e4)},exports.videoToAsciiFrames=it,exports.videoToAsciiTextFrames=st;//# sourceMappingURL=core.cjs.map