asciify-engine 4.16.0 → 4.18.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.
package/dist/core.js CHANGED
@@ -1 +1 @@
1
- var t={standard:{label:"Classic ASCII",chars:" .:-=+*#%@"},asciify:{label:"Asciify",chars:" .:-=+YCIFSA#@"},minimal:{label:"Minimal",chars:" .:+"},detailed:{label:"Detailed",chars:" .,:;itLf1CG80@"},letters:{label:"Letters",chars:" .liLTYCFSAWM"},technical:{label:"Technical",chars:" ._:;+/>=][{}*$#@"},blocks:{label:"Tonal blocks",chars:" ░▒▓█"},braille:{label:"Braille",chars:" ⠁⠃⠇⡇⣇⣧⣷⣿"}},e={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"}},n={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"},o={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"}}},r=[{value:"none",mode:"none",group:"Still",label:"Off",description:"Keep the image still. Hover stays available."},{value:"caustics",mode:"caustics",group:"Light and texture",label:"Caustics",description:"Soft ribbons of light travel across a stationary character grid."},{value:"current",mode:"current",group:"Flow and depth",label:"Slow Current",description:"A gentle flow through the image, with steady edges."},{value:"reform",mode:"reform",group:"Rebuild",label:"Reveal & Reform",description:"Disperse, gather, then hold the complete image."},{value:"sheen",mode:"sheen",group:"Light and texture",label:"Sheen",description:"A broad diagonal light sweep; characters stay anchored."},{value:"tidal",mode:"tidal",group:"Flow and depth",label:"Tidal Rings",description:"Concentric currents travel outward, with protected edges."},{value:"grain",mode:"grain",group:"Light and texture",label:"Living Grain",description:"Slow, individually phased tonal changes on a stationary grid."},{value:"parallax",mode:"parallax",group:"Flow and depth",label:"Parallax",description:"A shallow, continuous drift through the image, with the edges held in place."},{value:"weave",mode:"weave",group:"Flow and depth",label:"Woven Flow",description:"Interlaced bands move in opposing directions, like a flexible printed fabric."},{value:"print",mode:"print",group:"Rebuild",label:"Print Shift",description:"Staggered rows lift, soften and register back into the image."},{value:"trace",mode:"trace",group:"Light and texture",label:"Contour Light",description:"Light follows the source image’s tonal contours; every character stays anchored."},{value:"relight",mode:"relight",group:"Light and texture",label:"Relight",description:"A slow orbit of light models the image’s midtones, while the character grid stays fixed."},{value:"shimmer",mode:"shimmer",group:"Light and texture",label:"Shimmer",description:"Small highlights glint at different moments. Shadows stay quiet and the image stays in place."},{value:"breeze",mode:"breeze",group:"Flow and depth",label:"Breeze",description:"A traveling bend gently sways the image, like a print suspended in moving air."},{value:"unfold",mode:"unfold",group:"Rebuild",label:"Unfold",description:"Narrow panels turn, soften and return to a complete image, with a readable hold between cycles."}];var a=t=>Math.max(0,Math.min(1,t)),i=(t,e,n)=>{const o=a((n-t)/(e-t));return o*o*(3-2*o)},s=(t,e)=>{const n=(.06711056*t+.00583715*e)%1*52.9829189;return n-Math.floor(n)};function c(t,e,n,o,r,c=.5){if(r[0]=r[1]=r[2]=0,r[3]=1,"none"===t)return r;const l=o*Math.PI/6,h=i(0,.12,Math.min(e,1-e,n,1-n));if("caustics"===t){const t=Math.sin(9*e+5*n+l)+Math.sin(8*n-3*e-l),o=Math.pow(Math.max(0,1-.72*Math.abs(t)),3);r[2]=(.22*o-.045)*h}else if("current"===t)r[0]=Math.sin(9*n+l)*Math.cos(7*e-l)*10*h,r[1]=Math.cos(8*e+l)*Math.sin(6*n-l)*7*h;else if("sheen"===t)r[2]=.2*Math.pow(.5+.5*Math.cos(5*e+3*n-l),8)-.025;else if("tidal"===t){const t=e-.5,o=n-.5,a=Math.hypot(t,o),i=Math.sin(22*a-l)*h;r[0]=t*i*9,r[1]=o*i*9,r[2]=.035*i}else if("grain"===t){const t=s(Math.floor(160*e),Math.floor(100*n))*Math.PI*2;r[2]=.07*Math.sin(l+t)}else if("parallax"===t){const t=.45+.55*Math.max(0,1-1.4*Math.hypot(e-.5,n-.5));r[0]=12*Math.sin(l)*t*h,r[1]=6*(Math.cos(l)-1)*t*h}else if("weave"===t)r[0]=Math.sin(n*Math.PI*6+l)*Math.sin(l)*8*h,r[1]=Math.sin(e*Math.PI*6-l)*Math.sin(l)*6*h;else if("print"===t){const t=Math.floor(24*n),e=((o+3*s(t,3))%12+12)%12,a=i(1,2.5,e)*(1-i(3.5,5,e));r[0]=Math.sin(2.4*t)*a*9*h,r[1]=5*-a*h,r[2]=.22*-a,r[3]=1-.45*a}else if("trace"===t){const t=.5+.5*Math.cos(l);r[2]=.22*Math.pow(Math.max(0,1-Math.abs(a(c)-t)/.16),3)-.015}else if("relight"===t){const t=n-.5,o=1.3*((e-.5)*Math.cos(l)+t*Math.sin(l));r[2]=.3*o*(.25+3*a(c)*(1-a(c)))*h}else if("shimmer"===t){const t=s(Math.floor(160*e),Math.floor(100*n))*Math.PI*2,o=Math.pow(.5+.5*Math.cos(l+t),10);r[2]=.28*(o-.1762)*i(.35,.9,c)}else if("breeze"===t){const t=Math.sin(l-4*n),o=.35+.65*(1-n);r[0]=10*t*o*h,r[1]=2.5*Math.sin(2*l-4*n+3*e)*o*h,r[2]=.035*Math.cos(l-4*n)*h}else if("unfold"===t){const t=Math.floor(12*e),n=12*e-t-.5,a=((o-.11*t)%12+12)%12,s=i(1,3,a)*(1-i(5,7,a));r[0]=-n*s*24*h,r[1]=Math.sin(1.7*t)*s*3*h,r[2]=.12*-s,r[3]=1-.65*s}else if("reform"===t){const t=(o%12+12)%12,a=s(Math.floor(160*e),Math.floor(100*n)),c=.65*e+.2*n+.15*a+.08*Math.sin(8*e-5*n),d=i(1.8+1.2*c,3.8+1.2*c,t)*(1-i(5+1.7*c,7.2+1.7*c,t));r[0]=Math.sin(9*n+l)*d*(1-d)*24*h,r[1]=-d*(1-d)*(8+12*a)*h,r[2]=.45*-d,r[3]=1-.9*d}return r}function l(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 h(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 d(t,e,n,o,r,a){if((a?1-t/255:t/255)<.12)return" ";const i=[...e];return i[(o*r+n)%i.length]}var f=[[0,8,2,10],[12,4,14,6],[3,11,1,9],[15,7,13,5]];function m(t,e,n,o){if(o<=0)return t;const r=(f[n%4][e%4]/16-.5)*o*128;return Math.max(0,Math.min(255,t+r))}var u=new Array(256),g=new Array(256);for(let t=0;t<256;t++)u[t]=`rgb(${t},${t},${t})`,g[t]=`rgb(0,${t},0)`;function p(t,e,n,o,r,a=!1){switch(e){case"fullcolor":return`rgb(${t.r},${t.g},${t.b})`;case"matrix":return g[.299*t.r+.587*t.g+.114*t.b|0];case"accent":return`rgb(${n},${o},${r})`;default:{const e=.299*t.r+.587*t.g+.114*t.b|0;return u[e]}}}var M=[0,0,0];function v(t,e,n,o,r,a=!1){switch(e){case"fullcolor":M[0]=t.r,M[1]=t.g,M[2]=t.b;break;case"matrix":{const e=.299*t.r+.587*t.g+.114*t.b|0;M[0]=0,M[1]=e,M[2]=0;break}case"accent":M[0]=n,M[1]=o,M[2]=r;break;default:{const e=.299*t.r+.587*t.g+.114*t.b|0;M[0]=e,M[1]=e,M[2]=e;break}}return M}function w(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 y(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=w(t);if(e&&e.a>.1)return e}e=e.parentElement}return null}function x(t){if(t){const e=y(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=y(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 b(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 S(t){return t*t*(3-2*t)}var E={scale:1,offsetX:0,offsetY:0,glow:0,colorBlend:0,proximity:0};function C(t,e,n,o,r,a,i,s,c="spotlight",l=.5,h="circle",d=[],f=1){const m=(t-n)*Math.max(1,f),u=(e-o)*Math.max(1,1/f),g=.08+.35*l+.04*a;let p,M;if("box"===h){const t=Math.abs(m),e=Math.abs(u);p=Math.max(t,e),M=g}else p=Math.sqrt(m*m+u*u),M=g;if(p>=M&&("trail"!==c||0===d.length))return E.scale=1,E.offsetX=0,E.offsetY=0,E.glow=0,E.colorBlend=0,E.proximity=0,E;const v=S(Math.max(0,1-p/M))*r;let w=1,y=0,x=0,b=0,C=0;switch(c){case"spotlight":{w=1+v*a*1.8;const t=Math.atan2(u,m),e=v*v*a*.6;y=Math.cos(t)*e*i,x=Math.sin(t)*e*s,b=v*a*.4,C=v*v*a*.25;break}case"magnify":w=1+v*a*.85,b=v*a*.15;break;case"repel":{w=1;const t=Math.atan2(u,m),e=v*v*a*1.8;y=Math.cos(t)*e*i,x=Math.sin(t)*e*s;break}case"glow":b=v*a*.8,C=v*a*.4;break;case"colorShift":w=1,b=v*a*.12,C=v*a;break;case"attract":{const t=Math.atan2(u,m),e=v*v*a*1;y=(.45*-Math.cos(t)-1.6*Math.sin(t))*e*i,x=(.45*-Math.sin(t)+1.6*Math.cos(t))*e*s,b=v*a*.3;break}case"shatter":{const t=Math.atan2(u,m),e=.5*Math.sin(43.7*m+29.3*u),n=v*a*1.4*(.7+.3*e);y=Math.cos(t+e)*n*i,x=Math.sin(t+e)*n*s,w=Math.max(.1,1-v*a*.6),b=v*a*.25;break}case"trail":{let n=v,o=-u*v,r=m*v;for(const a of d){const i=(t-a.x)*Math.max(1,f),s=(e-a.y)*Math.max(1,1/f),c=Math.hypot(i,s)/g;if(c>=1)continue;const l=S(1-c)*a.intensity;n=Math.max(n,l),o+=(.35*a.vx-2*s)*l*.35,r+=(.35*a.vy+2*i)*l*.35}y=Math.tanh(2*o)*a*i*3,x=Math.tanh(2*r)*a*s*3,C=n*a*.65,b=n*a*.35,w=1+n*a*.08,E.proximity=n;break}case"glitchText":w=1,b=v*a*.5,C=v*a*.6}return E.scale=w,E.offsetX=y,E.offsetY=x,E.glow=b,E.colorBlend=C,"trail"!==c&&(E.proximity=v),E}function T(t,e,{continuous:n=!1,interactive:o=!1}={}){const r=t.parentElement??t;let a=null,i=0,s=!1,c=!0,l=!0,h=-1/0;const d=window.matchMedia("(prefers-reduced-motion: reduce)"),f=()=>{l=!0,s||!c||document.hidden||i||(i=requestAnimationFrame(m))},m=t=>{if(i=0,s||!c||document.hidden)return;const o=!d.matches&&(n||t-h<1500);(l||o)&&(e(t,d.matches?null:a),l=!1),o&&(i=requestAnimationFrame(m))},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,r=(e.clientY-n.top)/n.height;a=o>=0&&o<=1&&r>=0&&r<=1?{x:o,y:r}:null,h=performance.now(),f()},g=()=>{a=null,h=performance.now(),f()},p=()=>{document.hidden&&i?(cancelAnimationFrame(i),i=0):f()},M="undefined"==typeof IntersectionObserver?null:new IntersectionObserver(([t])=>{c=t.isIntersecting,c?f():i&&(cancelAnimationFrame(i),i=0)});return M?.observe(t),o&&(r.addEventListener("pointermove",u),r.addEventListener("pointerleave",g)),document.addEventListener("visibilitychange",p),d.addEventListener("change",f),f(),{wake:f,stop:()=>{s=!0,cancelAnimationFrame(i),M?.disconnect(),r.removeEventListener("pointermove",u),r.removeEventListener("pointerleave",g),document.removeEventListener("visibilitychange",p),d.removeEventListener("change",f)}}}var A=null,F=null;function L(t,e){if(!A||!F){const n=l(t,e);A=n.canvas,F=n.ctx}return A.width!==t&&(A.width=t),A.height!==e&&(A.height=e),F}var I=new Map,R=new Map,k=new WeakMap;function H(t){const e=Intl.Segmenter;return e?Array.from(new e(void 0,{granularity:"grapheme"}).segment(t),({segment:t})=>t):[...t]}function W(t){let e=I.get(t);return e||(e=H(t),I.set(t,e)),e}function $(t){return H(t)}function P(t,e,n){const o=n?1-t/255:t/255,r=Math.floor(o*(e.length-1));return e[Math.max(0,Math.min(e.length-1,r))]??" "}function j(t,e,n,o){const r=`${t}\0${e?1:0}\0${n}\0${o}`;let a=R.get(r);if(!a){const i=W(t);a=new Array(256);for(let t=0;t<256;t++)a[t]=P(h(t,n,o),i,e);R.set(r,a)}return a}function z(){I.clear(),R.clear(),J=new WeakMap,Z=new WeakMap,Q=new WeakMap,A=null,F=null}function O(t,e){return"auto"!==t?t:!x(e)}function q(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 B(t){const e=t||"auto";if("auto"!==e)return q(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=q(t.getPropertyValue(e).trim());if(n)return n}const e=q(getComputedStyle(document.body).accentColor??"");if(e)return e}return x("undefined"!=typeof document?document.body:null)?"faf9f7":"0d0d0d"}function V(t,e,n){return Math.max(e,Math.min(n,t))}function D(t,e,n){if(!t)return{x:0,y:0,width:e,height:n};const o=t.unit??"percent",r=!1!==t.preserveAspect,a=t=>void 0===t?void 0:"percent"===o?t*e:t,i=t=>void 0===t?void 0:"percent"===o?t*n:t,s=V(a(t.left)??0,0,e-1),c=V(a(t.right)??0,0,e-s-1),l=V(i(t.top)??0,0,n-1),h=V(i(t.bottom)??0,0,n-l-1),d=void 0!==t.left||void 0!==t.right||void 0!==t.top||void 0!==t.bottom,f=Math.max(1,e-s-c),m=Math.max(1,n-l-h),u=d?f:a(t.width),g=d?m:i(t.height);let p=u??e,M=g??n;if(r&&!d){const t=p/e,o=M/n,r=Math.min(t,o),a=void 0===u?o:void 0===g?t:r;p=e*a,M=n*a}p=V(p,1,d?f:e),M=V(M,1,d?m:n);const v=t.anchor??"center",w=a(t.x),y=i(t.y),x=d?s:0,b=d?l:0,S=d?f:e,E=d?m:n,C=v.endsWith("left")||"left"===v?0:v.endsWith("right")||"right"===v?S-p:(S-p)/2,T=v.startsWith("top")||"top"===v?0:v.startsWith("bottom")||"bottom"===v?E-M:(E-M)/2;return{x:V(w??x+C,0,Math.max(0,e-p)),y:V(y??b+T,0,Math.max(0,n-M)),width:p,height:M}}function N(t,e,n,o){const r=t instanceof HTMLVideoElement?t.videoWidth:t.width,a=t instanceof HTMLVideoElement?t.videoHeight:t.height;if(0===r||0===a)return{frame:[],cols:0,rows:0};const i=e.charAspect,s=e.fontSize*e.charSpacing,c=e.fontSize/i*e.charSpacing,l=n||r,f=o||a,u=Math.floor(l/s),g=Math.floor(f/c);if(u<=0||g<=0)return{frame:[],cols:0,rows:0};const p=D(e.sourceCrop,r,a),M=Math.max(1,Math.min(Math.floor(2048/u),Math.floor(p.width/u))),v=Math.max(1,Math.min(Math.floor(2048/g),Math.floor(p.height/g))),w=u*M,y=g*v,x=L(w,y),S=x.globalCompositeOperation;x.globalCompositeOperation="copy";try{x.drawImage(t,p.x,p.y,p.width,p.height,0,0,w,y)}finally{x.globalCompositeOperation=S}const E=x.getImageData(0,0,w,y).data,C=e.chromaKey,T=null!=C&&!1!==C,A=!0===C,F="blue-screen"===C;let I=null,R=0;!T||A||F||(I=b(C),R=(e.chromaKeyTolerance??60)**2);let k=0,H=255;if(e.normalize){let t=255,e=0;for(let n=0;n<E.length;n+=4){if(T){const t=E[n],e=E[n+1],o=E[n+2];let r=!1;if(A)r=e>1.4*t&&e>1.4*o&&e>80;else if(F)r=o>1.4*t&&o>1.4*e&&o>80;else if(null!==I){const n=t-I.r,a=e-I.g,i=o-I.b;r=n*n+a*a+i*i<=R}if(r)continue}const o=.299*E[n]+.587*E[n+1]+.114*E[n+2];o<t&&(t=o),o>e&&(e=o)}k=t,H=e>t?e-t:255}const $=[],z=O(e.invert),q=T&&e.charset.replace(/ /g,"")||e.charset,B=W(q),V=e.customText?null:j(q,z,e.brightness,e.contrast),N=M*v;for(let t=0;t<g;t++){const n=[];for(let o=0;o<u;o++){let r=0,a=0,i=0,s=0,c=0;for(let e=0;e<v;e++){const n=(t*v+e)*w;for(let t=0;t<M;t++){const e=4*(n+o*M+t),l=E[e],h=E[e+1],d=E[e+2],f=E[e+3];if(T){let t=!1;if(A)t=h>1.4*l&&h>1.4*d&&h>80;else if(F)t=d>1.4*l&&d>1.4*h&&d>80;else if(null!==I){const e=l-I.r,n=h-I.g,o=d-I.b;t=e*e+n*n+o*o<=R}if(t){c++;continue}}r+=l,a+=h,i+=d,s+=f}}if(T&&c>N/2){n.push({char:" ",r:0,g:0,b:0,a:0});continue}const l=N-c,f=l>0?r/l:0,g=l>0?a/l:0,p=l>0?i/l:0,y=l>0?s/l:0,x=.299*f+.587*g+.114*p,b=e.normalize?(x-k)/H*255:x,S=h(b,e.brightness,e.contrast),C=e.ditherStrength>0?m(S,o,t,e.ditherStrength):S,L=e.customText?d(C,e.customText,o,t,u,z):e.ditherStrength>0?P(C,B,z):V[Math.max(0,Math.min(255,0|b))];n.push({char:L,r:f,g:g,b:p,a:y,lum:C})}$.push(n)}return{frame:$,cols:u,rows:g}}function U(t,e,n,o){const r=t instanceof HTMLVideoElement?t.videoWidth:t.width,a=t instanceof HTMLVideoElement?t.videoHeight:t.height;if(0===r||0===a)return{rows:[],cols:0,rowCount:0};const i=e.charAspect,s=e.fontSize*e.charSpacing,c=e.fontSize/i*e.charSpacing,l=n||r,d=o||a,f=Math.floor(l/s),u=Math.floor(d/c);if(f<=0||u<=0)return{rows:[],cols:0,rowCount:0};const g=f,p=u,M=L(g,p),v=D(e.sourceCrop,r,a),w=M.globalCompositeOperation;M.globalCompositeOperation="copy";try{M.drawImage(t,v.x,v.y,v.width,v.height,0,0,g,p)}finally{M.globalCompositeOperation=w}const y=M.getImageData(0,0,g,p).data,x=e.chromaKey,S=null!=x&&!1!==x,E=!0===x,C="blue-screen"===x;let T=null,A=0;!S||E||C||(T=b(x),A=(e.chromaKeyTolerance??60)**2);let F=0,I=255;if(e.normalize){let t=255,e=0;for(let n=0;n<y.length;n+=4){if(S){const t=y[n],e=y[n+1],o=y[n+2];let r=!1;if(E)r=e>1.4*t&&e>1.4*o&&e>80;else if(C)r=o>1.4*t&&o>1.4*e&&o>80;else if(null!==T){const n=t-T.r,a=e-T.g,i=o-T.b;r=n*n+a*a+i*i<=A}if(r)continue}const o=.299*y[n]+.587*y[n+1]+.114*y[n+2];o<t&&(t=o),o>e&&(e=o)}F=t,I=e>t?e-t:255}const R=O(e.invert),k=S&&e.charset.replace(/ /g,"")||e.charset,H=W(k),$=e.customText?null:j(k,R,e.brightness,e.contrast),z=e.customText?W(e.customText):null,q="fullcolor"===e.colorMode?new Uint8ClampedArray(f*u*4):void 0,B=[];for(let t=0;t<u;t++){let n="";for(let o=0;o<f;o++){const r=4*(t*g+o),a=r,i=y[r],s=y[r+1],c=y[r+2],l=y[r+3];if(S){let t=!1;if(E)t=s>1.4*i&&s>1.4*c&&s>80;else if(C)t=c>1.4*i&&c>1.4*s&&c>80;else if(null!==T){const e=i-T.r,n=s-T.g,o=c-T.b;t=e*e+n*n+o*o<=A}if(t){n+=" ",q&&(q[a]=0,q[a+1]=0,q[a+2]=0,q[a+3]=0);continue}}q&&(q[a]=i,q[a+1]=s,q[a+2]=c,q[a+3]=l);const d=.299*i+.587*s+.114*c,u=e.normalize?(d-F)/I*255:d,p=e.ditherStrength>0||z?h(u,e.brightness,e.contrast):u,M=e.ditherStrength>0?m(p,o,t,e.ditherStrength):p;if(z){n+=(R?1-M/255:M/255)<.12?" ":z[(t*f+o)%z.length]}else e.ditherStrength<=0?n+=$[Math.max(0,Math.min(255,0|u))]:n+=P(M,H,R)}B.push(n)}return{rows:B,cols:f,rowCount:u,colors:q}}function K(t,e,n,o,r){if(0===e.rows.length)return;const a=t.canvas,i=Boolean(n.chromaKey)||e.rows.some(t=>t.includes(" "));i||(k.delete(t),t.clearRect(0,0,o,r),t.fillStyle=x(a)?"#0a0a0a":"#faf9f7",t.fillRect(0,0,o,r));const s=B(n.accentColor),c=parseInt(s.substring(0,2),16),l=parseInt(s.substring(2,4),16),h=parseInt(s.substring(4,6),16),d=o/e.cols,f=r/e.rowCount,m=.9*Math.min(d/.55,f),u=e.colors;if("fullcolor"===n.colorMode&&u){k.delete(t),t.clearRect(0,0,o,r),t.font=`${m}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 r=$(e.rows[o]);let a=0;for(;a<e.cols;){for(;a<e.cols&&" "===r[a];)a++;if(a>=e.cols)break;const i=a,s=4*(o*e.cols+a),c=240&u[s],l=240&u[s+1],h=240&u[s+2];for(a++;a<e.cols&&" "!==r[a];){const t=4*(o*e.cols+a);if((240&u[t])!==c||(240&u[t+1])!==l||(240&u[t+2])!==h)break;a++}const m=`rgb(${c},${l},${h})`;m!==n&&(t.fillStyle=m,n=m),t.fillText(r.slice(i,a).join(""),i*d+.5*d,o*f+.5*f)}}return void(t.globalAlpha=1)}t.font=`${m}px "JetBrains Mono", monospace`,t.textAlign="left",t.textBaseline="middle";const g="matrix"===n.colorMode?"rgb(0,255,0)":"grayscale"===n.colorMode?x(a)?"rgb(230,230,230)":"rgb(24,24,24)":`rgb(${c},${l},${h})`;t.fillStyle=g,t.globalAlpha=1;const p=k.get(t),M=i&&p&&p.cols===e.cols&&p.rowCount===e.rowCount&&p.canvasWidth===o&&p.canvasHeight===r&&p.fillStyle===g;M||t.clearRect(0,0,o,r);for(let n=0;n<e.rows.length;n++){const r=e.rows[n];M&&p.rows[n]===r||(M&&t.clearRect(0,n*f,o,f+1),0!==r.trim().length&&t.fillText(r,.5*d,n*f+.5*f))}k.set(t,{rows:e.rows.slice(),cols:e.cols,rowCount:e.rowCount,canvasWidth:o,canvasHeight:r,fillStyle:g}),t.globalAlpha=1}async function Y(t,e,n,o,r=12,a=10,i,s=0){const c=Math.min(t.duration-s,a),l=Math.ceil(c*r),h=[];let d=0,f=0;for(let a=0;a<l;a++){const m=s+a/r;if(m>s+c)break;t.currentTime=m,await new Promise(e=>{const n=()=>{t.removeEventListener("seeked",n),e()};t.addEventListener("seeked",n)});const u=N(t,e,n,o);h.push(u.frame),d=u.cols,f=u.rows,i?.((a+1)/l)}return{frames:h,cols:d,rows:f,fps:r}}async function G(t,e,n,o,r=12,a=10,i,s=0){const c=Math.min(t.duration-s,a),l=Math.ceil(c*r),h=[];let d=0,f=0;for(let a=0;a<l;a++){const m=s+a/r;if(m>s+c)break;t.currentTime=m,await new Promise(e=>{const n=()=>{t.removeEventListener("seeked",n),e()};t.addEventListener("seeked",n)});const u=U(t,e,n,o);h.push(u),d=u.cols,f=u.rowCount,i?.((a+1)/l)}return{frames:h,cols:d,rows:f,fps:r}}async function X(t,e,n,o,r){const{parseGIF:a,decompressFrames:i}=await import("gifuct-js"),s=a(t),c=i(s,!0);if(0===c.length)return{frames:[],cols:0,rows:0,fps:10};const l=c[0].dims.width,h=c[0].dims.height,d=s.lsd?.width||l,f=s.lsd?.height||h,m=document.createElement("canvas");m.width=d,m.height=f;const u=m.getContext("2d"),g=document.createElement("canvas");g.width=d,g.height=f;const p=g.getContext("2d"),M=document.createElement("canvas"),v=M.getContext("2d"),w=[];let y=0,x=0,b=0;for(const t of c)b+=t.delay||100;const S=b/c.length,E=Math.round(Math.min(30,Math.max(5,1e3/S))),C=Math.min(c.length,300);for(let t=0;t<C;t++){const a=c[t],{dims:i,patch:s,disposalType:l}=a;3===l&&(p.clearRect(0,0,d,f),p.drawImage(m,0,0)),M.width!==i.width&&(M.width=i.width),M.height!==i.height&&(M.height=i.height);const h=new ImageData(new Uint8ClampedArray(s.buffer),i.width,i.height);v.putImageData(h,0,0),u.drawImage(M,i.left||0,i.top||0);const b=N(m,e,n,o);w.push(b.frame),y=b.cols,x=b.rows,2===l?u.clearRect(i.left||0,i.top||0,i.width,i.height):3===l&&(u.clearRect(0,0,d,f),u.drawImage(g,0,0)),r?.((t+1)/C)}return{frames:w,cols:y,rows:x,fps:E}}async function _(t,e,n,o,r){const{parseGIF:a,decompressFrames:i}=await import("gifuct-js"),s=a(t),c=i(s,!0);if(0===c.length)return{frames:[],cols:0,rows:0,fps:10};const l=c[0].dims.width,h=c[0].dims.height,d=s.lsd?.width||l,f=s.lsd?.height||h,m=document.createElement("canvas");m.width=d,m.height=f;const u=m.getContext("2d"),g=document.createElement("canvas");g.width=d,g.height=f;const p=g.getContext("2d"),M=document.createElement("canvas"),v=M.getContext("2d"),w=[];let y=0,x=0,b=0;for(const t of c)b+=t.delay||100;const S=b/c.length,E=Math.round(Math.min(30,Math.max(5,1e3/S))),C=Math.min(c.length,300);for(let t=0;t<C;t++){const a=c[t],{dims:i,patch:s,disposalType:l}=a;3===l&&(p.clearRect(0,0,d,f),p.drawImage(m,0,0)),M.width!==i.width&&(M.width=i.width),M.height!==i.height&&(M.height=i.height);const h=new ImageData(new Uint8ClampedArray(s.buffer),i.width,i.height);v.putImageData(h,0,0),u.drawImage(M,i.left||0,i.top||0);const b=U(m,e,n,o);w.push(b),y=b.cols,x=b.rowCount,2===l?u.clearRect(i.left||0,i.top||0,i.width,i.height):3===l&&(u.clearRect(0,0,d,f),u.drawImage(g,0,0)),r?.((t+1)/C)}return{frames:w,cols:y,rows:x,fps:E}}var J=new WeakMap,Q=new WeakMap,Z=new WeakMap;function tt(t,e,n,o,r,a=0,i){if(!e.length||!e[0].length||o<=0||r<=0)return;let s=null;if(n.hoverStrength>0){let e=J.get(t);e||(e={x:.5,y:.5,intensity:0,time:-1,emittedAt:-1,points:[]},J.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 r=t.intensity<.003,a=t.x,i=t.y;if(e){r&&(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&&!r&&n-t.emittedAt>=24&&Math.hypot(t.x-a,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-a)/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 J.delete(t);if("none"!==n.animationStyle||n.charsetFrames?.length||n.hoverStrength<=0)return Z.delete(t),void et(t,e,n,o,r,a,s);const c=Q.get(t);if(c?.frame!==e)return Q.set(t,{frame:e,since:performance.now()}),Z.delete(t),void et(t,e,n,o,r,a,s);if(performance.now()-c.since<100)return void et(t,e,n,o,r,a,s);const l=t.getTransform();if(l.b||l.c||l.a<=0||l.d<=0)return void et(t,e,n,o,r,a,s);if(!s||(s.intensity??0)<.003)return void et(t,e,n,o,r,a,null);const h=x(t.canvas),d={...n,accentColor:"#"+B(n.accentColor)},f=JSON.stringify([d,o,r,l.a,l.d,h,void 0!==document.fonts?document.fonts.status:"loaded"]);let m=Z.get(t);if(!m||m.frame!==e||m.key!==f){const n=m?.canvas??document.createElement("canvas");n.width=Math.ceil(o*l.a),n.height=Math.ceil(r*l.d);const a=n.getContext("2d");a.setTransform(l.a,0,0,l.d,0,0),et(a,e,d,o,r,0,null,void 0,h),m={frame:e,key:f,canvas:n},Z.set(t,m)}if(t.clearRect(0,0,o,r),t.drawImage(m.canvas,0,0,o,r),!s||(s.intensity??0)<.003)return;const u=e.length,g=e[0].length,p=.08+.35*n.hoverRadius+.04*n.hoverStrength,M="trail"===n.hoverEffect?[s,...s.trail??[]]:[s];let v=1,w=1,y=0,b=0;for(const t of M)v=Math.min(v,t.x-p),y=Math.max(y,t.x+p),w=Math.min(w,t.y-p),b=Math.max(b,t.y+p);if("glitchText"===n.hoverEffect){const t=n.hoverText,e=Math.max(1,...(Array.isArray(t)?t:[t]).map(t=>t.length));v=Math.min(v,s.x-e/g),y=Math.max(y,s.x+e/g)}const S=Math.ceil(5+4*n.hoverStrength),E={x:Math.max(0,Math.floor(v*g)-S),y:Math.max(0,Math.floor(w*u)-S),right:Math.min(g,Math.ceil(y*g)+S),bottom:Math.min(u,Math.ceil(b*u)+S)};t.save(),t.beginPath(),t.rect(E.x*o/g,E.y*r/u,(E.right-E.x)*o/g,(E.bottom-E.y)*r/u),t.clip(),et(t,e,d,o,r,a,s,E,h),t.restore()}function et(t,e,n,o,a,i=0,s,l,h){const d=e.length;if(0===d)return;const f=e[0].length;t.clearRect(0,0,o,a);let m=!1;const u=Math.max(1,d>>2),g=Math.max(1,f>>2);t:for(let t=0;t<d;t+=u){const n=e[t];for(let t=0;t<f;t+=g)if(n[t].a<200){m=!0;break t}}const M=t.canvas,w=h??x(M);m||(t.fillStyle=w?"#0a0a0a":"#faf9f7",t.fillRect(0,0,o,a));const y=o/f,b=a/d,S=s?.intensity??1,E=!!(s&&n.hoverStrength>0&&S>.005),T="#"+(q(n.hoverColor||"#ffffff")??"ffffff"),A=parseInt(T.slice(1,3),16),F=parseInt(T.slice(3,5),16),L=parseInt(T.slice(5,7),16),I=B(n.accentColor),R=parseInt(I.substring(0,2),16),k=parseInt(I.substring(2,4),16),H=parseInt(I.substring(4,6),16),$=n.hoverRadius;let j=0,z=f,V=0,D=d,N=0,U=0;if(E&&s){N=s.x,U=s.y;const t=.08+.35*$+.04*n.hoverStrength;j=Math.max(0,Math.floor((N-t)*f)-1),z=Math.min(f,Math.ceil((N+t)*f)+1),V=Math.max(0,Math.floor((U-t)*d)-1),D=Math.min(d,Math.ceil((U+t)*d)+1)}if(E&&"trail"===n.hoverEffect)for(const t of s?.trail??[]){const e=.08+.35*$+.04*n.hoverStrength;j=Math.min(j,Math.max(0,Math.floor((t.x-e)*f)-1)),z=Math.max(z,Math.min(f,Math.ceil((t.x+e)*f)+1)),V=Math.min(V,Math.max(0,Math.floor((t.y-e)*d)-1)),D=Math.max(D,Math.min(d,Math.ceil((t.y+e)*d)+1))}const K=n.animationStyle,Y=n.animationSpeed,G=(X=K,r.find(t=>t.value===X||t.mode===X)?.mode??"none");var X;const _="none"===G,J=[0,0,0,1],Q=n.hoverStrength,Z=n.hoverEffect,tt=$,et=n.hoverShape||"circle",nt=O(n.invert,M),ot=n.colorMode,rt=2*Math.PI,at=1/f,it=1/d;let st="",ct=-1;if("dots"===n.renderMode){const r=.5*Math.min(y,b)*n.dotSizeRatio;for(let n=l?.y??0;n<(l?.bottom??d);n++){const h=e[n];for(let e=l?.x??0;e<(l?.right??f);e++){const l=h[e];if(l.a<10)continue;const m=.00392156863*(.299*l.r+.587*l.g+.114*l.b),u=nt?1-m:m;if(u<.02)continue;_||c(G,e/f,n/d,i*Y,J,(.299*l.r+.587*l.g+.114*l.b)/255);const g=Math.max(0,Math.min(1,(1+J[2])*J[3]));let M=1,w=0,x=0,T=0,I=0;if(E&&e>=j&&e<=z&&n>=V&&n<=D){const t=C(e*at,n*it,N,U,S,Q,y,b,Z,tt,et,s?.trail,o/a);M=t.scale,w=t.offsetX,x=t.offsetY,T=t.glow,I=t.colorBlend}const W=r*u*g*M;if(W<.3)continue;const $=e*y+.5*y+w+J[0],P=n*b+.5*b+x+J[1];let O;if(I>0){const t=v(l,ot,R,k,H,nt);O=`rgb(${Math.min(255,t[0]+(A-t[0])*I|0)},${Math.min(255,t[1]+(F-t[1])*I|0)},${Math.min(255,t[2]+(L-t[2])*I|0)})`}else O=p(l,ot,R,k,H,nt);const q=Math.min(1,.00392156863*l.a*g*(1+T));if(q!==ct&&(t.globalAlpha=q,ct=q),O!==st&&(t.fillStyle=O,st=O),W<=3){const e=2*W;t.fillRect($-W,P-W,e,e)}else t.beginPath(),t.arc($,P,W,0,rt),t.fill()}}}else{const r=.55,h=.9*Math.min(y/r,b);{const e=/\p{Extended_Pictographic}/u.test(n.customText||n.charset);t.font=e?`${h}px "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twemoji Mozilla", sans-serif`:`${h}px "JetBrains Mono", monospace`,t.textAlign="center",t.textBaseline="middle"}const m=n.charsetFrames,u=!!m?.length,g=u?m[Math.floor(Math.max(0,i)*(n.charsetFps??2))%m.length]:n.charset,M=t.getTransform();if(!E&&_&&!u&&"accent"===ot&&!l&&n.hoverStrength<=0&&!/\p{Extended_Pictographic}/u.test(n.customText||n.charset)&&"letterSpacing"in t&&/^[\x20-\x7e]*$/.test(n.customText||n.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=y-o+"px",t.fillStyle=`rgb(${R},${k},${H})`,t.globalAlpha=1,t.textAlign="left";for(let n=0;n<d;n++){const r=e[n];let a="";for(let t=0;t<f;t++){const e=r[t];a+=e.a<10?" ":e.char}0!==a.trim().length&&t.fillText(a,.5*(y-o),n*b+.5*b)}return t.letterSpacing=n,t.textAlign="center",void(t.globalAlpha=1)}const w="glitchText"===Z&&E,x="!@#$%^&*<>{}[]|/\\~`0123456789",T=x.length;let I="",O=0,q=0,B=0,K=0,X=0,rt=0;if(w){const t=n.hoverText??"ASCIIFY";if(q=Math.round(N*f),B=Math.round(U*d),Array.isArray(t)){const e=t.filter(t=>t.length>0);0===e.length&&e.push("ASCIIFY");I=e[((7*Math.floor(q/Math.max(1,Math.ceil(f/5)))+13*Math.floor(B/Math.max(1,Math.ceil(d/3))))%e.length+e.length)%e.length]}else I=t||"ASCIIFY";O=I.length,K=Math.max(3,Math.min(12,Math.round(d*$*.6)));const e=Math.floor(K/2);X=Math.max(0,B-e),X+K>d&&(X=Math.max(0,d-K)),rt=q-Math.floor(O/2)}for(let n=l?.y??0;n<(l?.bottom??d);n++){const r=e[n];for(let h=l?.x??0;h<(l?.right??f);h++){const l=r[h];if(l.a<10)continue;let m=u&&null!=l.lum?P(l.lum,W(g),nt):l.char;if(" "===m)continue;_||c(G,h/f,n/d,i*Y,J,(.299*l.r+.587*l.g+.114*l.b)/255);const $=Math.max(0,Math.min(1,(1+J[2])*J[3]));if($<.05)continue;let lt=1,ht=0,dt=0,ft=0,mt=0;if(E&&!w&&h>=j&&h<=z&&n>=V&&n<=D){const t=C(h*at,n*it,N,U,S,Q,y,b,Z,tt,et,s?.trail,o/a);if(lt=t.scale,ht=t.offsetX,dt=t.offsetY,ft=t.glow,mt=t.colorBlend,"trail"===Z&&t.proximity>0){const o=Math.max(0,Math.min(f-1,Math.round(h-t.offsetX/y))),r=e[Math.max(0,Math.min(d-1,Math.round(n-t.offsetY/b)))][o],a=r.lum??.299*r.r+.587*r.g+.114*r.b;m=P(Math.min(255,a+t.proximity*Q*65),W(g),nt)}}if(w&&n>=X&&n<X+K){const t=h-rt;if(t>=0&&t<O){const e=I[t],o=Math.abs(n-B)/Math.max(1,.5*K),r=Math.abs(h-q)/Math.max(1,O),a=Math.max(o,r),s=Math.max(0,Math.min(1,1-.9*a)),c=43758.5453*Math.sin(127.1*h+311.7*n+43758.5453*Math.floor(12*i));m=Math.abs(c-Math.floor(c))<s?e:x[Math.abs(Math.floor(97*c))%T],ft=.3+.7*s,mt=.3+.65*s}}const ut=h*y+.5*y+ht+J[0],gt=n*b+.5*b+dt+J[1];let pt;if(mt>0){const t=v(l,ot,R,k,H,nt);pt=`rgb(${Math.min(255,t[0]+(A-t[0])*mt|0)},${Math.min(255,t[1]+(F-t[1])*mt|0)},${Math.min(255,t[2]+(L-t[2])*mt|0)})`}else pt=p(l,ot,R,k,H,nt);const Mt=Math.min(1,.00392156863*l.a*$*(1+ft));Mt!==ct&&(t.globalAlpha=Mt,ct=Mt),pt!==st&&(t.fillStyle=pt,st=pt),1!==lt?(t.translate(ut,gt),t.scale(lt,lt),t.fillText(m,0,0),t.setTransform(M)):t.fillText(m,ut,gt)}}}t.globalAlpha=1}function nt(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 ot(t){return Math.max(0,Math.min(1,t))}function rt(t){return"string"==typeof t?document.querySelector(t):t instanceof HTMLElement?t:null}function at(t){return"ascii"===t.renderMode&&"none"===t.animationStyle&&t.hoverStrength<=0&&!t.charsetFrames?.length}function it(t,e={}){const n=ot(t),o=ot(n*(void 0===e.speed?1:Math.max(.001,e.speed)));return ot(e.ease?e.ease(o):o)}function st(t,e,n={}){if(!Number.isFinite(t.duration)||t.duration<=0)return;const o=n.from??0,r=n.to??t.duration,a=Math.max(o,Math.min(r,t.duration)),i=it(e,n),s=o+(a-o)*i;t.currentTime=Math.min(Math.max(o,s),Math.max(o,a-.04)),n.onUpdate?.(i,t)}function ct(t,e){return Math.abs(t.currentTime-e)<1/240?lt(t):new Promise(n=>{const o=()=>{t.removeEventListener("seeked",o),n()};t.addEventListener("seeked",o,{once:!0});const r=t.fastSeek;r?r.call(t,e):t.currentTime=e})}function lt(t){const e=t.requestVideoFrameCallback;return new Promise(e?n=>{let o=!1;const r=()=>{o||(o=!0,n())};e.call(t,r),window.setTimeout(r,32)}:t=>requestAnimationFrame(()=>t()))}function ht(t,e={}){const n=rt(e.trigger)??t;t.pause();const o=e.gsap,r=e.ScrollTrigger??o?.ScrollTrigger;if(o&&r?.create){o.registerPlugin?.(r);const a=r.create({trigger:n,start:e.start??"top bottom",end:e.end??"bottom top",scrub:e.scrub??!0,onUpdate:n=>st(t,n.progress,e)});return()=>a.kill?.()}return function(t,e,n){let o=0;const r=()=>{o=0;const r=e.getBoundingClientRect(),a=window.innerHeight||document.documentElement.clientHeight,i=r.height+a,s=i>0?ot((a-r.top)/i):0;st(t,s,n)},a=()=>{o||(o=requestAnimationFrame(r))};return window.addEventListener("scroll",a,{passive:!0}),window.addEventListener("resize",a),a(),()=>{window.removeEventListener("scroll",a),window.removeEventListener("resize",a),o&&cancelAnimationFrame(o)}}(t,n,e)}function dt(t,e,n){const o=e.gsap,r=e.ScrollTrigger??o?.ScrollTrigger;if(o&&r?.create){o.registerPlugin?.(r);const a=r.create({trigger:t,start:e.start??"top bottom",end:e.end??"bottom top",scrub:e.scrub??!0,onUpdate:t=>n(t.progress)});return()=>a.kill?.()}return function(t,e){let n=0;const o=()=>{n=0;const o=t.getBoundingClientRect(),r=window.innerHeight||document.documentElement.clientHeight,a=o.height+r,i=a>0?ot((r-o.top)/a):0;e(i)},r=()=>{n||(n=requestAnimationFrame(o))};return window.addEventListener("scroll",r,{passive:!0}),window.addEventListener("resize",r),r(),()=>{window.removeEventListener("scroll",r),window.removeEventListener("resize",r),n&&cancelAnimationFrame(n)}}(t,n)}function ft(t,e,n){if(!t||!e||!n.sourceCrop)return{w:t,h:e};const o=D(n.sourceCrop,t,e);return{w:Math.max(1,Math.round(o.width)),h:Math.max(1,Math.round(o.height))}}function mt(t,e,n,o){const r=o.chromaKey;if(null==r||!1===r)return!1;if(!0===r)return e>1.4*t&&e>1.4*n&&e>80;if("blue-screen"===r)return n>1.4*t&&n>1.4*e&&n>80;const a=b(r),i=(o.chromaKeyTolerance??60)**2,s=t-a.r,c=e-a.g,l=n-a.b;return s*s+c*c+l*l<=i}function ut(t,e,n){if(!e.chromaKey||!e.sourceCrop||"off"===e.chromaKeyTrimMode)return e;const o=t instanceof HTMLVideoElement?t.videoWidth:t.width,r=t instanceof HTMLVideoElement?t.videoHeight:t.height;if(!o||!r)return e;const a=D(e.sourceCrop,o,r),i=Math.min(360,Math.max(1,Math.round(a.width))),s=Math.max(1,Math.round(i*(a.height/a.width))),{ctx:c}=l(i,s);c.drawImage(t,a.x,a.y,a.width,a.height,0,0,i,s);const h=c.getImageData(0,0,i,s).data,d=Math.max(0,Math.min(255,e.chromaKeyTrimLuminanceThreshold??0));let f=i,m=s,u=-1,g=-1;for(let t=0;t<s;t++)for(let n=0;n<i;n++){const o=4*(t*i+n),r=h[o+3],a=h[o],s=h[o+1],c=h[o+2];r<=8||.2126*a+.7152*s+.0722*c<=d||mt(a,s,c,e)||(n<f&&(f=n),t<m&&(m=t),n>u&&(u=n),t>g&&(g=t))}if(u<f||g<m)return e;const p=Math.max(0,Math.min(.25,e.chromaKeyTrimPadding??.002)),M=Math.round(i*p),v=Math.round(s*p);f=Math.max(0,f-M),m=Math.max(0,m-v),u=Math.min(i-1,u+M),g=Math.min(s-1,g+v);const w=function(t,e,n,o,r){const a=r&&Number.isFinite(r)&&r>0?r:null;if(!a)return t;const i=e.x,s=e.y,c=e.x+e.width,l=e.y+e.height,h=Math.max(i,t.left),d=Math.max(s,t.top),f=Math.min(c,n-t.right),m=Math.min(l,o-t.bottom),u=Math.max(1,f-h),g=Math.max(1,m-d),p=h+u/2,M=d+g/2;let v=u,w=g;v/w<a?v=w*a:w=v/a;v>e.width&&(v=e.width,w=Math.max(g,Math.min(e.height,v/a)));w>e.height&&(w=e.height,v=Math.max(u,Math.min(e.width,w*a)));let y=p-v/2,x=M-w/2;return y=Math.max(i,Math.min(c-v,y)),x=Math.max(s,Math.min(l-w,x)),{left:y,top:x,right:n-(y+v),bottom:o-(x+w)}}({left:a.x+f/i*a.width,top:a.y+m/s*a.height,right:o-(a.x+(u+1)/i*a.width),bottom:r-(a.y+(g+1)/s*a.height)},{x:a.x,y:a.y,width:a.width,height:a.height},o,r,n);return{...e,sourceCrop:{unit:"pixel",...w,preserveAspect:!1}}}function gt(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 pt(t,e,n,o,r){if(!e.chromaKey||!e.sourceCrop||"range"!==e.chromaKeyTrimMode)return e;const a=t.currentTime,i=function(t,e,n,o){const r=!0===o?{}:o||{},a=Math.max(0,r.from??e),i=r.to??n??(Number.isFinite(t.duration)?t.duration:a),s=Math.max(a,i-.04),c=Math.max(0,s-a),l=c>.1?[a,a+.25*c,a+.5*c,a+.75*c,s]:[a];return Array.from(new Set(l.map(t=>Math.max(0,Number(t.toFixed(3))))))}(t,n,o,r);let s=null;for(const n of i){await ct(t,n),await lt(t);const o=gt(ut(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 ct(t,a),await lt(t),s?{...e,sourceCrop:{unit:"pixel",...s,preserveAspect:!0}}:e}function Mt(t,e,n=2048){return vt({sourceWidth:t,sourceHeight:e,maxRenderDimension:n})}function vt({sourceWidth:t,sourceHeight:e,cssWidth:n=0,cssHeight:o=0,maxRenderDimension:r=2048}){const a=Math.max(1,t),i=Math.max(1,e),s=a/i,c=Math.max(1,r),l=Math.min(1,c/Math.max(a,i)),h=Math.max(a,i)*l,d=Math.max(0,n,o),f=Math.min(c,Math.max(h,d));return s>=1?{renderW:Math.round(f),renderH:Math.round(f/s)}:{renderW:Math.round(f*s),renderH:Math.round(f)}}function wt(t,e,n,o){if(void 0===t)return;if("number"==typeof t)return t;const r=t.trim();if(r.endsWith("%")){const t=Number.parseFloat(r)/100;return Number.isFinite(t)?e*t:void 0}if(r.endsWith("px")){const t=Number.parseFloat(r);return Number.isFinite(t)?t:void 0}if(r.endsWith("vw")){const t=Number.parseFloat(r)/100;return Number.isFinite(t)?n*t:void 0}if(r.endsWith("vh")){const t=Number.parseFloat(r)/100;return Number.isFinite(t)?o*t:void 0}}function yt(t,e,n,o,r,a=2048,i={}){const{width:s,height:c}=e.getBoundingClientRect();if(!s||!c)return{renderW:0,renderH:0,dpr:1};const l="undefined"!=typeof window?window.innerWidth:s,h="undefined"!=typeof window?window.innerHeight:c,d=wt(i.width,s,l,h)??s,f=wt(i.height,c,l,h)??c,m=function(t,e,n,o,r){const a=t=>{const n=wt(t,e,o,r);return n&&n>0?n:0},i=t=>{const e=wt(t,n,o,r);return e&&e>0?e:0};return void 0===t?{x:0,y:0}:"number"==typeof t||"string"==typeof t?{x:a(t),y:i(t)}:{x:a(t.x),y:i(t.y)}}(i.bleed,s,c,l,h),u=d+2*m.x,g=f+2*m.y,{cssW:p,cssH:M}=function(t,e,n,o="contain"){if("fill"===o)return{cssW:t,cssH:e};let r=t,a=r/n;const i="cover"===o,s=a>e;return(i&&!s||!i&&s)&&(a=e,r=a*n),"scale-down"===o&&(r=Math.min(r,t),a=Math.min(a,e)),{cssW:Math.round(r),cssH:Math.round(a)}}(u,g,n,i.objectFit??"contain"),v="undefined"!=typeof window&&window.devicePixelRatio||1;let w,y;o&&r?({renderW:w,renderH:y}=vt({sourceWidth:o,sourceHeight:r,cssWidth:p,cssHeight:M,maxRenderDimension:a})):(w=p,y=M);const x=8e6,b=w*v*y*v>x?Math.sqrt(x/(w*y)):v;return t.width=Math.round(w*b),t.height=Math.round(y*b),t.style.width=`${p}px`,t.style.height=`${M}px`,{renderW:w,renderH:y,dpr:b}}async function xt(t,e,{fontSize:o,artStyle:r="classic",options:a={}}={}){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=nt(r),c=o??a.fontSize??10,l={...n,...s,artStyle:r,...a,fontSize:c},h=e.getContext("2d");if(!h)throw new Error("Could not get 2d context from canvas");const{w:d,h:f}=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:m,renderH:u}=Mt(d,f),g="undefined"!=typeof window&&window.devicePixelRatio||1,p=8e6,M=m*g*u*g>p?Math.sqrt(p/(m*u)):g;e.width===Math.round(m*M)&&e.height===Math.round(u*M)||(e.width=Math.round(m*M),e.height=Math.round(u*M));const{frame:v}=N(i,l,m,u),w=(t,e)=>{h.save(),h.setTransform(M,0,0,M,0,0),tt(h,v,l,m,u,t/1e3,e),h.restore()};w(0,null);return T(e,w,{continuous:"none"!==l.animationStyle||!!l.charsetFrames?.length,interactive:l.hoverStrength>0}).stop}async function bt(t,e,{fontSize:o,artStyle:r="classic",options:a={}}={}){const i="string"==typeof t?await fetch(t).then(t=>t.arrayBuffer()):t,s=o??a.fontSize??10;let c={...n,...nt(r),artStyle:r,...a,fontSize:s};const l=e.getContext("2d");if(!l)throw new Error("Could not get 2d context from canvas");const{frames:h,fps:d}=await X(i,c,e.width,e.height);if(!h.length)throw new Error("asciifyGif: the GIF contains no renderable frames.");const f=performance.now();let m=-1;return T(e,(t,n)=>{const o=Math.floor((t-f)*d/1e3)%h.length;o===m&&!n&&c.hoverStrength<=0&&"none"===c.animationStyle&&!c.charsetFrames?.length||(tt(l,h[o],c,e.width,e.height,(t-f)/1e3,n),m=o)},{continuous:!0,interactive:c.hoverStrength>0}).stop}async function St(t,e,{fontSize:o,artStyle:r="classic",options:a={},fitTo:i,objectFit:s,objectPosition:c,scale:l,width:h,height:d,bleed:f,preExtract:m=!1,fps:u,maxRenderDimension:g=2048,trim:p,scroll:M,maxCachedFrames:v=90,onReady:w,onFrame:y}={}){const x=p?.start??0,b=p?.end,S=o??a.fontSize??10;let E={...n,...nt(r),artStyle:r,...a,fontSize:S};const C=e.getContext("2d");if(!C)throw new Error("asciifyVideo: could not get 2d context from canvas.");const A="string"==typeof i?document.querySelector(i):i instanceof HTMLElement?i:null,F={objectFit:s,objectPosition:c,scale:l,width:h,height:d,bleed:f},L=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")}}(e,F),I=t=>()=>{t(),L()};if(m){let n;"string"==typeof t?(n=document.createElement("video"),n.crossOrigin="anonymous",n.src=t,n.readyState<2&&await new Promise((e,o)=>{n.onloadeddata=()=>e(),n.onerror=()=>o(new Error(`asciifyVideo: failed to load "${t}"`))})):n=t,E=await pt(n,E,x,b,M);const o=ft(n.videoWidth,n.videoHeight,E);A&&yt(e,A,o.w/o.h,o.w,o.h,g,F);const{renderW:r,renderH:a}=Mt(o.w,o.h,g),i="undefined"!=typeof window&&window.devicePixelRatio||1,s=8e6,c=r*i*a*i>s?Math.sqrt(s/(r*a)):i;e.width===Math.round(r*c)&&e.height===Math.round(a*c)||(e.width=Math.round(r*c),e.height=Math.round(a*c));const l=void 0!==b?b-x:10,h=u??(M?18:void 0);if(at(E)){const{frames:t,fps:o}=await G(n,E,r,a,h,l,void 0,x),i=e=>{const n=t[e];n&&(C.save(),C.setTransform(c,0,0,c,0,0),K(C,n,E,r,a),C.restore(),y?.())};if(M){let o=!1,r=-1;const a=!0===M?{}:M,s=dt(rt(a.trigger)??A??e,a,e=>{const s=it(e,a),c=Math.max(0,Math.min(t.length-1,Math.round(s*(t.length-1))));c!==r&&(r=c,i(c),o||(o=!0,w?.(n)),a.onUpdate?.(s,n))});return i(0),o=!0,w?.(n),I(s)}let s,d=!1,f=0,m=performance.now(),u=!0;const g=1e3/o,p=e=>{d||(e-m>=g&&(i(f),f=(f+1)%t.length,m=e,u&&(u=!1,w?.(n))),s=requestAnimationFrame(p))};return s=requestAnimationFrame(p),I(()=>{d=!0,cancelAnimationFrame(s)})}const{frames:d,fps:f}=await Y(n,E,r,a,h,l,void 0,x);if(!d.length)throw new Error("asciifyVideo: no frames were decoded.");let m=0;const p=performance.now(),v=T(e,(t,e)=>{M||(m=Math.floor((t-p)*f/1e3)%d.length),C.save(),C.setTransform(c,0,0,c,0,0),tt(C,d[m],E,r,a,(t-p)/1e3,e),C.restore(),y?.()},{continuous:!M||"none"!==E.animationStyle||!!E.charsetFrames?.length,interactive:E.hoverStrength>0});let S;if(M){const t=!0===M?{}:M;S=dt(rt(t.trigger)??A??e,t,e=>{m=Math.max(0,Math.min(d.length-1,Math.round(it(e,t)*(d.length-1)))),v.wake(),t.onUpdate?.(e,n)})}return w?.(n),I(()=>{v.stop(),S?.()})}let R,k=!1;"string"==typeof t?(R=document.createElement("video"),R.crossOrigin="anonymous",R.src=t,R.muted=!0,R.loop=!0,R.playsInline=!0,R.setAttribute("playsinline",""),Object.assign(R.style,{position:"fixed",top:"0",left:"0",width:"1px",height:"1px",opacity:"0",pointerEvents:"none",zIndex:"-1"}),document.body.appendChild(R),k=!0,await new Promise((e,n)=>{R.onloadedmetadata=()=>e(),R.onerror=()=>n(new Error(`asciifyVideo: failed to load "${t}"`))}),await R.play().catch(()=>{})):(R=t,R.readyState<HTMLMediaElement.HAVE_METADATA&&await new Promise((t,e)=>{const n=()=>{R.removeEventListener("loadedmetadata",o),R.removeEventListener("error",r)},o=()=>{n(),t()},r=()=>{n(),e(new Error("asciifyVideo: provided video element failed to load metadata."))};R.addEventListener("loadedmetadata",o),R.addEventListener("error",r),R.load()}),R.paused&&await R.play().catch(()=>{})),x>0&&(R.currentTime=x,await new Promise(t=>{const e=()=>{R.removeEventListener("seeked",e),t()};R.addEventListener("seeked",e)}),await lt(R));let H=null;(x>0||void 0!==b)&&(H=()=>{(void 0!==b&&R.currentTime>=b||x>0&&R.currentTime<x)&&(R.currentTime=x)},R.addEventListener("timeupdate",H)),E=await pt(R,E,x,b,M);let W=null;const $=ft(R.videoWidth,R.videoHeight,E);let{renderW:P,renderH:j}=Mt($.w,$.h,g);const z=t=>"frame"===E.chromaKeyTrimMode?ut(t,E,P/j):E;if(A){const t=$.w/$.h,n=$.w,o=$.h,r=yt(e,A,t,n,o,g,F);P=r.renderW,j=r.renderH;const a=e.getContext("2d");a&&a.setTransform(r.dpr,0,0,r.dpr,0,0),W=new ResizeObserver(()=>{const r=yt(e,A,t,n,o,g,F);P=r.renderW,j=r.renderH;const a=e.getContext("2d");a&&a.setTransform(r.dpr,0,0,r.dpr,0,0)}),W.observe(A)}else{const t="undefined"!=typeof window&&window.devicePixelRatio||1,n=8e6,o=P*t*j*t>n?Math.sqrt(n/(P*j)):t;e.width===Math.round(P*o)&&e.height===Math.round(j*o)||(e.width=Math.round(P*o),e.height=Math.round(j*o)),C.setTransform(o,0,0,o,0,0)}let O=!0,q=null;const B=M&&!m,V=u&&u>0?1e3/u:0;let D=0;const X=!B&&at(E);if(B&&"ascii"===E.renderMode&&"none"===E.animationStyle&&E.hoverStrength<=0&&!E.charsetFrames?.length){const t=!0===M?{}:M,n=rt(t.trigger)??A??e,o=t.from??x,r=t.to??b??R.duration,a=Math.max(o,Math.min(r,R.duration)),i=Math.max(.001,a-o),s=Math.min(60,Math.max(12,u??30)),c=Math.max(2,Math.ceil(i*s)+1),l=new Array(c),h=[],d=Math.max(2,Math.min(c,Math.floor(v))),f=()=>{for(;h.length>d;){const t=h.findIndex(t=>t!==g&&Math.abs(t-g)>2),e=t>=0?t:0,n=h.splice(e,1)[0];void 0!==n&&(l[n]=void 0)}},m=t=>{const e=h.indexOf(t);e>=0&&h.splice(e,1),h.push(t),f()};let g=0,p=0,S=-1,T=0,F=!1,L=!1,$=!1;const O=new Set,B=document.createElement("video");B.muted=!0,B.playsInline=!0,B.preload="auto",B.crossOrigin=R.crossOrigin||"anonymous",B.src=R.currentSrc||R.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",r)},o=()=>{n(),t()},r=()=>{n(),e(new Error("asciifyVideo: cache video failed to load metadata."))};B.addEventListener("loadedmetadata",o),B.addEventListener("error",r),B.load()}),B.pause(),R.paused&&await R.play().catch(()=>{});const N=t=>o+i*t/Math.max(1,c-1),Y=t=>Math.max(0,Math.min(c-1,Math.round(t*(c-1)))),G=z(R),X=U(R,G,P,j);X.rows.length>0&&(l[0]=X,m(0),K(C,X,G,P,j),$=!0,w?.(R),y?.());const _=t=>{if(l[t])return t;for(let e=1;e<c;e++){const n=t-e,o=t+e;if(n>=0&&l[n])return n;if(o<c&&l[o])return o}return-1},J=()=>{if(!l[g])return g;for(const t of O)if(!l[t])return t;for(let t=1;t<c;t++){const e=g-t,n=g+t;if(e>=0&&!l[e])return e;if(n<c&&!l[n])return n}return-1},Q=t=>{t<0||t>=c||l[t]||(O.add(t),Z())},Z=async()=>{if(F||L)return;const t=J();if(!(t<0)){O.delete(t),L=!0;try{if(await ct(B,N(t)),!F){const e=z(B),n=U(B,e,P,j);n.rows.length>0&&(l[t]=n,m(t))}}finally{L=!1,F||requestAnimationFrame(()=>{Z()})}}},tt=()=>{if(F)return;const t=_(g);if(t>=0&&t!==S){const e=l[t];e&&(K(C,e,E,P,j),S=t,$||($=!0,w?.(R)),y?.())}else if(t<0||S<0){const t=performance.now();if(V<=0||t-D>=V){const e=z(R),n=U(R,e,P,j);n.rows.length>0&&(K(C,n,e,P,j),D=t,$||($=!0,w?.(R)),y?.())}}Q(g),T=requestAnimationFrame(tt)};return q=dt(n,t,e=>{const n=function(t,e,n={}){if(!Number.isFinite(t.duration)||t.duration<=0)return null;const o=n.from??0,r=n.to??t.duration,a=Math.max(o,Math.min(r,t.duration)),i=it(e,n),s=o+(a-o)*i;return{progress:i,time:Math.min(Math.max(o,s),Math.max(o,a-.04))}}(R,e,{...t,from:o,to:a});p=n?.progress??ot(e),g=Y(p),Q(g),Q(g-1),Q(g+1),Q(g-2),Q(g+2),Q(g-3),Q(g+3),t.onUpdate?.(p,R)}),Q(0),Q(1),T=requestAnimationFrame(tt),I(()=>{F=!0,cancelAnimationFrame(T),q?.(),W?.disconnect(),O.clear(),h.length=0,l.fill(void 0),B.pause(),B.src="",B.removeAttribute("src"),B.load(),B.isConnected&&B.remove(),H&&R.removeEventListener("timeupdate",H),k&&(R.pause(),R.src="",R.removeAttribute("src"),R.load(),R.isConnected&&R.remove())})}if(B){const t=!0===M?{}:M;q=ht(R,{...t,trigger:t.trigger??A??e,from:t.from??x,to:t.to??b})}let _=-1,J=0,Q=-1,Z=0;const et="function"==typeof R.requestVideoFrameCallback,st=()=>{Z=R.requestVideoFrameCallback(()=>{J++,st()})};et&&st();let mt=0,gt=0,vt=null;const wt=T(e,(t,n)=>{if(R.readyState<2||0===e.width||0===e.height)return;if(V>0&&t-D<V&&!n)return;if(x>0&&R.currentTime<x)return;if(void 0!==b&&R.currentTime>=b)return;const o=(et?J!==Q:R.currentTime!==_)||mt!==P||gt!==j;if(o||!(E.hoverStrength<=0)||"none"!==E.animationStyle||E.charsetFrames?.length){if(X){const t=z(R),e=U(R,t,P,j);K(C,e,t,P,j)}else!o&&vt||(vt=N(R,z(R),P,j).frame),tt(C,vt,E,P,j,t/1e3,n);_=R.currentTime,Q=J,mt=P,gt=j,D=t,O&&(O=!1,w?.(R)),y?.()}},{continuous:!0,interactive:E.hoverStrength>0});return I(()=>{wt.stop(),Z&&R.cancelVideoFrameCallback(Z),q?.(),W?.disconnect(),H&&R.removeEventListener("timeupdate",H),k&&(R.pause(),R.src="",R.removeAttribute("src"),R.load(),R.isConnected&&R.remove())})}function Et(t,e,n){return St(t,e,n)}function Ct(t,e={},o,r){const a={...n,...e},{frame:i,cols:s}=N(t,a,o,r);if(!i.length||0===s)return"";const c=[];for(const t of i)c.push(t.map(t=>t.char).join(""));return c.join("\n")}function Tt(t,e={},o,r){const a={...n,...e},{frame:i,cols:s}=N(t,a,o,r);if(!i.length||0===s)return"";const c=[];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}`;c.push(e)}return c.join("\n")}function At(t,e,n,o="#505050",r=100){if(!t||e<=0||n<=0)return[];const a=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:a.r,g:a.g,b:a.b,a:r})))}var Ft=new WeakMap;function Lt(t,e,o,r,a={},i){const{fontSize:s=10,lineHeight:c=1.6,color:l="#505050",opacity:h=100,hoverEffect:d="spotlight",hoverStrength:f=.85,hoverRadius:m=.18,hoverColor:u="#d4ff00"}=a,g=Math.max(1,Math.floor(e/s)),p=Math.max(1,Math.floor(o/(s*c))),M=JSON.stringify([r,g,p,l,h]);let v=Ft.get(t);v&&v.key===M||(v={key:M,frame:At(r,g,p,l,h)},Ft.set(t,v));tt(t,v.frame,{...n,fontSize:s,hoverEffect:d,hoverStrength:f,hoverRadius:m,hoverColor:u},e,o,0,i??null)}function It(t,{format:e="png",quality:n=.92,scale:o=1}={}){return new Promise((r,a)=>{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 a(new Error("captureSnapshot: could not get 2d context"));n.drawImage(t,0,0,e.width,e.height),i=e}i.toBlob(t=>t?r(t):a(new Error("captureSnapshot: toBlob returned null")),`image/${e}`,n)})}async function Rt(t,e={}){const{filename:n="asciify-snapshot",format:o="png",...r}=e,a=await It(t,{format:o,...r}),i="jpeg"===o?"jpg":o,s=document.createElement("a");s.href=URL.createObjectURL(a),s.download=`${n}.${i}`,s.click(),setTimeout(()=>URL.revokeObjectURL(s.href),1e4)}async function kt(t,{fontSize:e=10,style:o="classic",options:r={},liveOptions:a,mirror:i=!0,constraints:s={facingMode:"user"},dpr:c}={}){if(!navigator.mediaDevices?.getUserMedia)throw new Error("asciifyWebcam: getUserMedia is not supported in this browser.");const l=nt(o),h=await navigator.mediaDevices.getUserMedia({video:s}),d=document.createElement("video");d.srcObject=h,d.muted=!0,d.playsInline=!0,await new Promise((t,e)=>{d.onloadedmetadata=()=>t(),d.onerror=()=>e(new Error("asciifyWebcam: video stream failed to load.")),d.play().catch(e)});const f={...n,...l,...r,fontSize:e},m=t.getContext("2d");if(!m)throw new Error("asciifyWebcam: could not get 2d context from canvas.");const u=c??("undefined"!=typeof window?window.devicePixelRatio:1)??1;1!==u&&m.scale(u,u);let g=null;const p=e=>{const n=t.getBoundingClientRect();g={x:(e.clientX-n.left)/n.width,y:(e.clientY-n.top)/n.height}},M=()=>{g=null};f.hoverStrength>0&&(t.addEventListener("mousemove",p),t.addEventListener("mouseleave",M));let v,w=!1;const y=performance.now(),x=e=>{if(!w){if(d.readyState>=d.HAVE_CURRENT_DATA){const n=t.width/u,o=t.height/u,r=(e-y)/1e3,s=a?{...f,...a()}:f;s.hoverStrength>0?(t.addEventListener("mousemove",p),t.addEventListener("mouseleave",M)):(t.removeEventListener("mousemove",p),t.removeEventListener("mouseleave",M));const{frame:c}=N(d,s,n,o),l=g&&i?{x:1-g.x,y:g.y}:g;i?(m.save(),m.scale(-1,1),m.translate(-n,0),tt(m,c,s,n,o,r,l),m.restore()):tt(m,c,s,n,o,r,l)}v=requestAnimationFrame(x)}};return v=requestAnimationFrame(x),()=>{w=!0,cancelAnimationFrame(v),t.removeEventListener("mousemove",p),t.removeEventListener("mouseleave",M),h.getTracks().forEach(t=>t.stop()),d.srcObject=null}}var Ht={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]},Wt=[127,65,65,65,65,65,127];function $t(t){return Ht[t]??Ht[t.toUpperCase()]??Wt}function Pt(t,e={}){if(!t)return"";const{char:n="█",scale:o=1}=e,r=[...n][0]??"█",a=Math.max(1,Math.floor(o)),i=7*a,s=a,c=Array.from({length:i},()=>"");for(let e=0;e<t.length;e++){const n=$t(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?r:" ").repeat(a);for(let e=0;e<a;e++)c[t*a+e]+=o}if(e<t.length-1)for(let t=0;t<i;t++)c[t]+=" ".repeat(s)}return c.join("\n")}function jt(t,e,n={}){const{color:o="#d4ff00",bgColor:r,fontSize:a=10}=n,i=Pt(e,n);if(!i)return;const s=i.split("\n"),c=Math.max(...s.map(t=>[...t].length));t.width=Math.ceil(c*a*.6),t.height=Math.ceil(s.length*a);const l=t.getContext("2d");r&&"transparent"!==r?(l.fillStyle=r,l.fillRect(0,0,t.width,t.height)):l.clearRect(0,0,t.width,t.height),l.fillStyle=o,l.font=`${a}px monospace`,l.textBaseline="top",s.forEach((t,e)=>l.fillText(t,0,e*a))}var zt=["ascii","blocks","braille","dots","lines","cross","diagonal","diamond","mixed","pixel","mosaic","lego","voxel","disco","dither","hex","led","cmyk","stipple","engraving","crosshatch","woodblock","risograph","pointillism"];export{t as CHARACTER_SETS,n as DEFAULT_OPTIONS,o as HOVER_PRESETS,e as PALETTE_THEMES,zt as STUDIO_STYLES,Ct as asciiText,Tt as asciiTextAnsi,xt as asciify,bt as asciifyGif,Et as asciifyLiveVideo,Pt as asciifyText,St as asciifyVideo,kt as asciifyWebcam,At as buildTextFrame,It as captureSnapshot,z as clearAsciifyCaches,vt as computeCanvasRenderSize,ht as createVideoScrollScrub,X as gifToAsciiFrames,_ as gifToAsciiTextFrames,N as imageToAsciiFrame,U as imageToAsciiTextFrame,tt as renderFrameToCanvas,Lt as renderTextBackground,K as renderTextFrameToCanvas,jt as renderTextToCanvas,Rt as snapshotAndDownload,Y as videoToAsciiFrames,G as videoToAsciiTextFrames};//# sourceMappingURL=core.js.map
1
+ 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={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"}},n={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"},o={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"}}},r=[{value:"none",mode:"none",group:"Still",label:"Off",description:"Keep the image still. Hover stays available."},{value:"caustics",mode:"caustics",group:"Light and texture",label:"Caustics",description:"Soft ribbons of light travel across a stationary character grid."},{value:"current",mode:"current",group:"Flow and depth",label:"Slow Current",description:"A gentle flow through the image, with steady edges."},{value:"reform",mode:"reform",group:"Rebuild",label:"Reveal & Reform",description:"Disperse, gather, then hold the complete image."},{value:"sheen",mode:"sheen",group:"Light and texture",label:"Sheen",description:"A broad diagonal light sweep; characters stay anchored."},{value:"tidal",mode:"tidal",group:"Flow and depth",label:"Tidal Rings",description:"Concentric currents travel outward, with protected edges."},{value:"grain",mode:"grain",group:"Light and texture",label:"Living Grain",description:"Slow, individually phased tonal changes on a stationary grid."},{value:"parallax",mode:"parallax",group:"Flow and depth",label:"Parallax",description:"A shallow, continuous drift through the image, with the edges held in place."},{value:"weave",mode:"weave",group:"Flow and depth",label:"Woven Flow",description:"Interlaced bands move in opposing directions, like a flexible printed fabric."},{value:"print",mode:"print",group:"Rebuild",label:"Print Shift",description:"Staggered rows lift, soften and register back into the image."},{value:"trace",mode:"trace",group:"Light and texture",label:"Contour Light",description:"Light follows the source image’s tonal contours; every character stays anchored."},{value:"relight",mode:"relight",group:"Light and texture",label:"Relight",description:"A slow orbit of light models the image’s midtones, while the character grid stays fixed."},{value:"shimmer",mode:"shimmer",group:"Light and texture",label:"Shimmer",description:"Small highlights glint at different moments. Shadows stay quiet and the image stays in place."},{value:"breeze",mode:"breeze",group:"Flow and depth",label:"Breeze",description:"A traveling bend gently sways the image, like a print suspended in moving air."},{value:"unfold",mode:"unfold",group:"Rebuild",label:"Unfold",description:"Narrow panels turn, soften and return to a complete image, with a readable hold between cycles."}];var a=t=>Math.max(0,Math.min(1,t)),i=(t,e,n)=>{const o=a((n-t)/(e-t));return o*o*(3-2*o)},s=(t,e)=>{const n=(.06711056*t+.00583715*e)%1*52.9829189;return n-Math.floor(n)};function c(t,e,n,o,r,c=.5){if(r[0]=r[1]=r[2]=0,r[3]=1,"none"===t)return r;const l=o*Math.PI/6,h=i(0,.12,Math.min(e,1-e,n,1-n));if("caustics"===t){const t=Math.sin(9*e+5*n+l)+Math.sin(8*n-3*e-l),o=Math.pow(Math.max(0,1-.72*Math.abs(t)),3);r[2]=(.22*o-.045)*h}else if("current"===t)r[0]=Math.sin(9*n+l)*Math.cos(7*e-l)*10*h,r[1]=Math.cos(8*e+l)*Math.sin(6*n-l)*7*h;else if("sheen"===t)r[2]=.2*Math.pow(.5+.5*Math.cos(5*e+3*n-l),8)-.025;else if("tidal"===t){const t=e-.5,o=n-.5,a=Math.hypot(t,o),i=Math.sin(22*a-l)*h;r[0]=t*i*9,r[1]=o*i*9,r[2]=.035*i}else if("grain"===t){const t=s(Math.floor(160*e),Math.floor(100*n))*Math.PI*2;r[2]=.07*Math.sin(l+t)}else if("parallax"===t){const t=.45+.55*Math.max(0,1-1.4*Math.hypot(e-.5,n-.5));r[0]=12*Math.sin(l)*t*h,r[1]=6*(Math.cos(l)-1)*t*h}else if("weave"===t)r[0]=Math.sin(n*Math.PI*6+l)*Math.sin(l)*8*h,r[1]=Math.sin(e*Math.PI*6-l)*Math.sin(l)*6*h;else if("print"===t){const t=Math.floor(24*n),e=((o+3*s(t,3))%12+12)%12,a=i(1,2.5,e)*(1-i(3.5,5,e));r[0]=Math.sin(2.4*t)*a*9*h,r[1]=5*-a*h,r[2]=.22*-a,r[3]=1-.45*a}else if("trace"===t){const t=.5+.5*Math.cos(l);r[2]=.22*Math.pow(Math.max(0,1-Math.abs(a(c)-t)/.16),3)-.015}else if("relight"===t){const t=n-.5,o=1.3*((e-.5)*Math.cos(l)+t*Math.sin(l));r[2]=.3*o*(.25+3*a(c)*(1-a(c)))*h}else if("shimmer"===t){const t=s(Math.floor(160*e),Math.floor(100*n))*Math.PI*2,o=Math.pow(.5+.5*Math.cos(l+t),10);r[2]=.28*(o-.1762)*i(.35,.9,c)}else if("breeze"===t){const t=Math.sin(l-4*n),o=.35+.65*(1-n);r[0]=10*t*o*h,r[1]=2.5*Math.sin(2*l-4*n+3*e)*o*h,r[2]=.035*Math.cos(l-4*n)*h}else if("unfold"===t){const t=Math.floor(12*e),n=12*e-t-.5,a=((o-.11*t)%12+12)%12,s=i(1,3,a)*(1-i(5,7,a));r[0]=-n*s*24*h,r[1]=Math.sin(1.7*t)*s*3*h,r[2]=.12*-s,r[3]=1-.65*s}else if("reform"===t){const t=(o%12+12)%12,a=s(Math.floor(160*e),Math.floor(100*n)),c=.65*e+.2*n+.15*a+.08*Math.sin(8*e-5*n),d=i(1.8+1.2*c,3.8+1.2*c,t)*(1-i(5+1.7*c,7.2+1.7*c,t));r[0]=Math.sin(9*n+l)*d*(1-d)*24*h,r[1]=-d*(1-d)*(8+12*a)*h,r[2]=.45*-d,r[3]=1-.9*d}return r}function l(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 h(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 d(t,e,n,o,r,a){if((a?1-t/255:t/255)<.12)return" ";const i=[...e];return i[(o*r+n)%i.length]}var f=[[0,8,2,10],[12,4,14,6],[3,11,1,9],[15,7,13,5]];function m(t,e,n,o){if(o<=0)return t;const r=(f[n%4][e%4]/16-.5)*o*128;return Math.max(0,Math.min(255,t+r))}var u=new Array(256),g=new Array(256);for(let t=0;t<256;t++)u[t]=`rgb(${t},${t},${t})`,g[t]=`rgb(0,${t},0)`;function p(t,e,n,o,r,a=!1){switch(e){case"fullcolor":return`rgb(${t.r},${t.g},${t.b})`;case"matrix":return g[.299*t.r+.587*t.g+.114*t.b|0];case"accent":return`rgb(${n},${o},${r})`;default:{const e=.299*t.r+.587*t.g+.114*t.b|0;return u[e]}}}var M=[0,0,0];function v(t,e,n,o,r,a=!1){switch(e){case"fullcolor":M[0]=t.r,M[1]=t.g,M[2]=t.b;break;case"matrix":{const e=.299*t.r+.587*t.g+.114*t.b|0;M[0]=0,M[1]=e,M[2]=0;break}case"accent":M[0]=n,M[1]=o,M[2]=r;break;default:{const e=.299*t.r+.587*t.g+.114*t.b|0;M[0]=e,M[1]=e,M[2]=e;break}}return M}function w(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 y(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=w(t);if(e&&e.a>.1)return e}e=e.parentElement}return null}function x(t){if(t){const e=y(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=y(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 b(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 S(t){return t*t*(3-2*t)}var E={scale:1,offsetX:0,offsetY:0,glow:0,colorBlend:0,proximity:0};function C(t,e,n,o,r,a,i,s,c="spotlight",l=.5,h="circle",d=[],f=1){const m=(t-n)*Math.max(1,f),u=(e-o)*Math.max(1,1/f),g=.08+.35*l+.04*a;let p,M;if("box"===h){const t=Math.abs(m),e=Math.abs(u);p=Math.max(t,e),M=g}else p=Math.sqrt(m*m+u*u),M=g;if(p>=M&&("trail"!==c||0===d.length))return E.scale=1,E.offsetX=0,E.offsetY=0,E.glow=0,E.colorBlend=0,E.proximity=0,E;const v=S(Math.max(0,1-p/M))*r;let w=1,y=0,x=0,b=0,C=0;switch(c){case"spotlight":{w=1+v*a*1.8;const t=Math.atan2(u,m),e=v*v*a*.6;y=Math.cos(t)*e*i,x=Math.sin(t)*e*s,b=v*a*.4,C=v*v*a*.25;break}case"magnify":w=1+v*a*.85,b=v*a*.15;break;case"repel":{w=1;const t=Math.atan2(u,m),e=v*v*a*1.8;y=Math.cos(t)*e*i,x=Math.sin(t)*e*s;break}case"glow":b=v*a*.8,C=v*a*.4;break;case"colorShift":w=1,b=v*a*.12,C=v*a;break;case"attract":{const t=Math.atan2(u,m),e=v*v*a*1;y=(.45*-Math.cos(t)-1.6*Math.sin(t))*e*i,x=(.45*-Math.sin(t)+1.6*Math.cos(t))*e*s,b=v*a*.3;break}case"shatter":{const t=Math.atan2(u,m),e=.5*Math.sin(43.7*m+29.3*u),n=v*a*1.4*(.7+.3*e);y=Math.cos(t+e)*n*i,x=Math.sin(t+e)*n*s,w=Math.max(.1,1-v*a*.6),b=v*a*.25;break}case"trail":{let n=v,o=-u*v,r=m*v;for(const a of d){const i=(t-a.x)*Math.max(1,f),s=(e-a.y)*Math.max(1,1/f),c=Math.hypot(i,s)/g;if(c>=1)continue;const l=S(1-c)*a.intensity;n=Math.max(n,l),o+=(.35*a.vx-2*s)*l*.35,r+=(.35*a.vy+2*i)*l*.35}y=Math.tanh(2*o)*a*i*3,x=Math.tanh(2*r)*a*s*3,C=n*a*.65,b=n*a*.35,w=1+n*a*.08,E.proximity=n;break}case"glitchText":w=1,b=v*a*.5,C=v*a*.6}return E.scale=w,E.offsetX=y,E.offsetY=x,E.glow=b,E.colorBlend=C,"trail"!==c&&(E.proximity=v),E}function T(t,e,{continuous:n=!1,interactive:o=!1}={}){const r=t.parentElement??t;let a=null,i=0,s=!1,c=!0,l=!0,h=-1/0;const d=window.matchMedia("(prefers-reduced-motion: reduce)"),f=()=>{l=!0,s||!c||document.hidden||i||(i=requestAnimationFrame(m))},m=t=>{if(i=0,s||!c||document.hidden)return;const o=!d.matches&&(n||t-h<1500);(l||o)&&(e(t,d.matches?null:a),l=!1),o&&(i=requestAnimationFrame(m))},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,r=(e.clientY-n.top)/n.height;a=o>=0&&o<=1&&r>=0&&r<=1?{x:o,y:r}:null,h=performance.now(),f()},g=()=>{a=null,h=performance.now(),f()},p=()=>{document.hidden&&i?(cancelAnimationFrame(i),i=0):f()},M="undefined"==typeof IntersectionObserver?null:new IntersectionObserver(([t])=>{c=t.isIntersecting,c?f():i&&(cancelAnimationFrame(i),i=0)});return M?.observe(t),o&&(r.addEventListener("pointermove",u),r.addEventListener("pointerleave",g)),document.addEventListener("visibilitychange",p),d.addEventListener("change",f),f(),{wake:f,stop:()=>{s=!0,cancelAnimationFrame(i),M?.disconnect(),r.removeEventListener("pointermove",u),r.removeEventListener("pointerleave",g),document.removeEventListener("visibilitychange",p),d.removeEventListener("change",f)}}}var A=null,F=null;function L(t,e){if(!A||!F){const n=l(t,e);A=n.canvas,F=n.ctx}return A.width!==t&&(A.width=t),A.height!==e&&(A.height=e),F}var I=new Map,R=new Map,k=new WeakMap;function H(t){const e=Intl.Segmenter;return e?Array.from(new e(void 0,{granularity:"grapheme"}).segment(t),({segment:t})=>t):[...t]}function W(t){let e=I.get(t);return e||(e=H(t),I.set(t,e)),e}function $(t){return H(t)}function P(t,e,n){const o=n?1-t/255:t/255,r=Math.floor(o*(e.length-1));return e[Math.max(0,Math.min(e.length-1,r))]??" "}function j(t,e,n,o){const r=`${t}\0${e?1:0}\0${n}\0${o}`;let a=R.get(r);if(!a){const i=W(t);a=new Array(256);for(let t=0;t<256;t++)a[t]=P(h(t,n,o),i,e);R.set(r,a)}return a}function z(){I.clear(),R.clear(),J=new WeakMap,Z=new WeakMap,Q=new WeakMap,A=null,F=null}function O(t,e){return"auto"!==t?t:!x(e)}function q(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 B(t){const e=t||"auto";if("auto"!==e)return q(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=q(t.getPropertyValue(e).trim());if(n)return n}const e=q(getComputedStyle(document.body).accentColor??"");if(e)return e}return x("undefined"!=typeof document?document.body:null)?"faf9f7":"0d0d0d"}function V(t,e,n){return Math.max(e,Math.min(n,t))}function D(t,e,n){if(!t)return{x:0,y:0,width:e,height:n};const o=t.unit??"percent",r=!1!==t.preserveAspect,a=t=>void 0===t?void 0:"percent"===o?t*e:t,i=t=>void 0===t?void 0:"percent"===o?t*n:t,s=V(a(t.left)??0,0,e-1),c=V(a(t.right)??0,0,e-s-1),l=V(i(t.top)??0,0,n-1),h=V(i(t.bottom)??0,0,n-l-1),d=void 0!==t.left||void 0!==t.right||void 0!==t.top||void 0!==t.bottom,f=Math.max(1,e-s-c),m=Math.max(1,n-l-h),u=d?f:a(t.width),g=d?m:i(t.height);let p=u??e,M=g??n;if(r&&!d){const t=p/e,o=M/n,r=Math.min(t,o),a=void 0===u?o:void 0===g?t:r;p=e*a,M=n*a}p=V(p,1,d?f:e),M=V(M,1,d?m:n);const v=t.anchor??"center",w=a(t.x),y=i(t.y),x=d?s:0,b=d?l:0,S=d?f:e,E=d?m:n,C=v.endsWith("left")||"left"===v?0:v.endsWith("right")||"right"===v?S-p:(S-p)/2,T=v.startsWith("top")||"top"===v?0:v.startsWith("bottom")||"bottom"===v?E-M:(E-M)/2;return{x:V(w??x+C,0,Math.max(0,e-p)),y:V(y??b+T,0,Math.max(0,n-M)),width:p,height:M}}function N(t,e,n,o){const r=t instanceof HTMLVideoElement?t.videoWidth:t.width,a=t instanceof HTMLVideoElement?t.videoHeight:t.height;if(0===r||0===a)return{frame:[],cols:0,rows:0};const i=e.charAspect,s=e.fontSize*e.charSpacing,c=e.fontSize/i*e.charSpacing,l=n||r,f=o||a,u=Math.floor(l/s),g=Math.floor(f/c);if(u<=0||g<=0)return{frame:[],cols:0,rows:0};const p=D(e.sourceCrop,r,a),M=Math.max(1,Math.min(Math.floor(2048/u),Math.floor(p.width/u))),v=Math.max(1,Math.min(Math.floor(2048/g),Math.floor(p.height/g))),w=u*M,y=g*v,x=L(w,y),S=x.globalCompositeOperation;x.globalCompositeOperation="copy";try{x.drawImage(t,p.x,p.y,p.width,p.height,0,0,w,y)}finally{x.globalCompositeOperation=S}const E=x.getImageData(0,0,w,y).data,C=e.chromaKey,T=null!=C&&!1!==C,A=!0===C,F="blue-screen"===C;let I=null,R=0;!T||A||F||(I=b(C),R=(e.chromaKeyTolerance??60)**2);let k=0,H=255;if(e.normalize){let t=255,e=0;for(let n=0;n<E.length;n+=4){if(T){const t=E[n],e=E[n+1],o=E[n+2];let r=!1;if(A)r=e>1.4*t&&e>1.4*o&&e>80;else if(F)r=o>1.4*t&&o>1.4*e&&o>80;else if(null!==I){const n=t-I.r,a=e-I.g,i=o-I.b;r=n*n+a*a+i*i<=R}if(r)continue}const o=.299*E[n]+.587*E[n+1]+.114*E[n+2];o<t&&(t=o),o>e&&(e=o)}k=t,H=e>t?e-t:255}const $=[],z=O(e.invert),q=T&&e.charset.replace(/ /g,"")||e.charset,B=W(q),V=e.customText?null:j(q,z,e.brightness,e.contrast),N=M*v;for(let t=0;t<g;t++){const n=[];for(let o=0;o<u;o++){let r=0,a=0,i=0,s=0,c=0;for(let e=0;e<v;e++){const n=(t*v+e)*w;for(let t=0;t<M;t++){const e=4*(n+o*M+t),l=E[e],h=E[e+1],d=E[e+2],f=E[e+3];if(T){let t=!1;if(A)t=h>1.4*l&&h>1.4*d&&h>80;else if(F)t=d>1.4*l&&d>1.4*h&&d>80;else if(null!==I){const e=l-I.r,n=h-I.g,o=d-I.b;t=e*e+n*n+o*o<=R}if(t){c++;continue}}r+=l,a+=h,i+=d,s+=f}}if(T&&c>N/2){n.push({char:" ",r:0,g:0,b:0,a:0});continue}const l=N-c,f=l>0?r/l:0,g=l>0?a/l:0,p=l>0?i/l:0,y=l>0?s/l:0,x=.299*f+.587*g+.114*p,b=e.normalize?(x-k)/H*255:x,S=h(b,e.brightness,e.contrast),C=e.ditherStrength>0?m(S,o,t,e.ditherStrength):S,L=e.customText?d(C,e.customText,o,t,u,z):e.ditherStrength>0?P(C,B,z):V[Math.max(0,Math.min(255,0|b))];n.push({char:L,r:f,g:g,b:p,a:y,lum:C})}$.push(n)}return{frame:$,cols:u,rows:g}}function U(t,e,n,o){const r=t instanceof HTMLVideoElement?t.videoWidth:t.width,a=t instanceof HTMLVideoElement?t.videoHeight:t.height;if(0===r||0===a)return{rows:[],cols:0,rowCount:0};const i=e.charAspect,s=e.fontSize*e.charSpacing,c=e.fontSize/i*e.charSpacing,l=n||r,d=o||a,f=Math.floor(l/s),u=Math.floor(d/c);if(f<=0||u<=0)return{rows:[],cols:0,rowCount:0};const g=f,p=u,M=L(g,p),v=D(e.sourceCrop,r,a),w=M.globalCompositeOperation;M.globalCompositeOperation="copy";try{M.drawImage(t,v.x,v.y,v.width,v.height,0,0,g,p)}finally{M.globalCompositeOperation=w}const y=M.getImageData(0,0,g,p).data,x=e.chromaKey,S=null!=x&&!1!==x,E=!0===x,C="blue-screen"===x;let T=null,A=0;!S||E||C||(T=b(x),A=(e.chromaKeyTolerance??60)**2);let F=0,I=255;if(e.normalize){let t=255,e=0;for(let n=0;n<y.length;n+=4){if(S){const t=y[n],e=y[n+1],o=y[n+2];let r=!1;if(E)r=e>1.4*t&&e>1.4*o&&e>80;else if(C)r=o>1.4*t&&o>1.4*e&&o>80;else if(null!==T){const n=t-T.r,a=e-T.g,i=o-T.b;r=n*n+a*a+i*i<=A}if(r)continue}const o=.299*y[n]+.587*y[n+1]+.114*y[n+2];o<t&&(t=o),o>e&&(e=o)}F=t,I=e>t?e-t:255}const R=O(e.invert),k=S&&e.charset.replace(/ /g,"")||e.charset,H=W(k),$=e.customText?null:j(k,R,e.brightness,e.contrast),z=e.customText?W(e.customText):null,q="fullcolor"===e.colorMode?new Uint8ClampedArray(f*u*4):void 0,B=[];for(let t=0;t<u;t++){let n="";for(let o=0;o<f;o++){const r=4*(t*g+o),a=r,i=y[r],s=y[r+1],c=y[r+2],l=y[r+3];if(S){let t=!1;if(E)t=s>1.4*i&&s>1.4*c&&s>80;else if(C)t=c>1.4*i&&c>1.4*s&&c>80;else if(null!==T){const e=i-T.r,n=s-T.g,o=c-T.b;t=e*e+n*n+o*o<=A}if(t){n+=" ",q&&(q[a]=0,q[a+1]=0,q[a+2]=0,q[a+3]=0);continue}}q&&(q[a]=i,q[a+1]=s,q[a+2]=c,q[a+3]=l);const d=.299*i+.587*s+.114*c,u=e.normalize?(d-F)/I*255:d,p=e.ditherStrength>0||z?h(u,e.brightness,e.contrast):u,M=e.ditherStrength>0?m(p,o,t,e.ditherStrength):p;if(z){n+=(R?1-M/255:M/255)<.12?" ":z[(t*f+o)%z.length]}else e.ditherStrength<=0?n+=$[Math.max(0,Math.min(255,0|u))]:n+=P(M,H,R)}B.push(n)}return{rows:B,cols:f,rowCount:u,colors:q}}function K(t,e,n,o,r){if(0===e.rows.length)return;const a=t.canvas,i=Boolean(n.chromaKey)||e.rows.some(t=>t.includes(" "));i||(k.delete(t),t.clearRect(0,0,o,r),t.fillStyle=x(a)?"#0a0a0a":"#faf9f7",t.fillRect(0,0,o,r));const s=B(n.accentColor),c=parseInt(s.substring(0,2),16),l=parseInt(s.substring(2,4),16),h=parseInt(s.substring(4,6),16),d=o/e.cols,f=r/e.rowCount,m=.9*Math.min(d/.55,f),u=e.colors;if("fullcolor"===n.colorMode&&u){k.delete(t),t.clearRect(0,0,o,r),t.font=`${m}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 r=$(e.rows[o]);let a=0;for(;a<e.cols;){for(;a<e.cols&&" "===r[a];)a++;if(a>=e.cols)break;const i=a,s=4*(o*e.cols+a),c=240&u[s],l=240&u[s+1],h=240&u[s+2];for(a++;a<e.cols&&" "!==r[a];){const t=4*(o*e.cols+a);if((240&u[t])!==c||(240&u[t+1])!==l||(240&u[t+2])!==h)break;a++}const m=`rgb(${c},${l},${h})`;m!==n&&(t.fillStyle=m,n=m),t.fillText(r.slice(i,a).join(""),i*d+.5*d,o*f+.5*f)}}return void(t.globalAlpha=1)}t.font=`${m}px "JetBrains Mono", monospace`,t.textAlign="left",t.textBaseline="middle";const g="matrix"===n.colorMode?"rgb(0,255,0)":"grayscale"===n.colorMode?x(a)?"rgb(230,230,230)":"rgb(24,24,24)":`rgb(${c},${l},${h})`;t.fillStyle=g,t.globalAlpha=1;const p=k.get(t),M=i&&p&&p.cols===e.cols&&p.rowCount===e.rowCount&&p.canvasWidth===o&&p.canvasHeight===r&&p.fillStyle===g;M||t.clearRect(0,0,o,r);for(let n=0;n<e.rows.length;n++){const r=e.rows[n];M&&p.rows[n]===r||(M&&t.clearRect(0,n*f,o,f+1),0!==r.trim().length&&t.fillText(r,.5*d,n*f+.5*f))}k.set(t,{rows:e.rows.slice(),cols:e.cols,rowCount:e.rowCount,canvasWidth:o,canvasHeight:r,fillStyle:g}),t.globalAlpha=1}async function Y(t,e,n,o,r=12,a=10,i,s=0){const c=Math.min(t.duration-s,a),l=Math.ceil(c*r),h=[];let d=0,f=0;for(let a=0;a<l;a++){const m=s+a/r;if(m>s+c)break;t.currentTime=m,await new Promise(e=>{const n=()=>{t.removeEventListener("seeked",n),e()};t.addEventListener("seeked",n)});const u=N(t,e,n,o);h.push(u.frame),d=u.cols,f=u.rows,i?.((a+1)/l)}return{frames:h,cols:d,rows:f,fps:r}}async function X(t,e,n,o,r=12,a=10,i,s=0){const c=Math.min(t.duration-s,a),l=Math.ceil(c*r),h=[];let d=0,f=0;for(let a=0;a<l;a++){const m=s+a/r;if(m>s+c)break;t.currentTime=m,await new Promise(e=>{const n=()=>{t.removeEventListener("seeked",n),e()};t.addEventListener("seeked",n)});const u=U(t,e,n,o);h.push(u),d=u.cols,f=u.rowCount,i?.((a+1)/l)}return{frames:h,cols:d,rows:f,fps:r}}async function G(t,e,n,o,r){const{parseGIF:a,decompressFrames:i}=await import("gifuct-js"),s=a(t),c=i(s,!0);if(0===c.length)return{frames:[],cols:0,rows:0,fps:10};const l=c[0].dims.width,h=c[0].dims.height,d=s.lsd?.width||l,f=s.lsd?.height||h,m=document.createElement("canvas");m.width=d,m.height=f;const u=m.getContext("2d"),g=document.createElement("canvas");g.width=d,g.height=f;const p=g.getContext("2d"),M=document.createElement("canvas"),v=M.getContext("2d"),w=[];let y=0,x=0,b=0;for(const t of c)b+=t.delay||100;const S=b/c.length,E=Math.round(Math.min(30,Math.max(5,1e3/S))),C=Math.min(c.length,300);for(let t=0;t<C;t++){const a=c[t],{dims:i,patch:s,disposalType:l}=a;3===l&&(p.clearRect(0,0,d,f),p.drawImage(m,0,0)),M.width!==i.width&&(M.width=i.width),M.height!==i.height&&(M.height=i.height);const h=new ImageData(new Uint8ClampedArray(s.buffer),i.width,i.height);v.putImageData(h,0,0),u.drawImage(M,i.left||0,i.top||0);const b=N(m,e,n,o);w.push(b.frame),y=b.cols,x=b.rows,2===l?u.clearRect(i.left||0,i.top||0,i.width,i.height):3===l&&(u.clearRect(0,0,d,f),u.drawImage(g,0,0)),r?.((t+1)/C)}return{frames:w,cols:y,rows:x,fps:E}}async function _(t,e,n,o,r){const{parseGIF:a,decompressFrames:i}=await import("gifuct-js"),s=a(t),c=i(s,!0);if(0===c.length)return{frames:[],cols:0,rows:0,fps:10};const l=c[0].dims.width,h=c[0].dims.height,d=s.lsd?.width||l,f=s.lsd?.height||h,m=document.createElement("canvas");m.width=d,m.height=f;const u=m.getContext("2d"),g=document.createElement("canvas");g.width=d,g.height=f;const p=g.getContext("2d"),M=document.createElement("canvas"),v=M.getContext("2d"),w=[];let y=0,x=0,b=0;for(const t of c)b+=t.delay||100;const S=b/c.length,E=Math.round(Math.min(30,Math.max(5,1e3/S))),C=Math.min(c.length,300);for(let t=0;t<C;t++){const a=c[t],{dims:i,patch:s,disposalType:l}=a;3===l&&(p.clearRect(0,0,d,f),p.drawImage(m,0,0)),M.width!==i.width&&(M.width=i.width),M.height!==i.height&&(M.height=i.height);const h=new ImageData(new Uint8ClampedArray(s.buffer),i.width,i.height);v.putImageData(h,0,0),u.drawImage(M,i.left||0,i.top||0);const b=U(m,e,n,o);w.push(b),y=b.cols,x=b.rowCount,2===l?u.clearRect(i.left||0,i.top||0,i.width,i.height):3===l&&(u.clearRect(0,0,d,f),u.drawImage(g,0,0)),r?.((t+1)/C)}return{frames:w,cols:y,rows:x,fps:E}}var J=new WeakMap,Q=new WeakMap,Z=new WeakMap;function tt(t,e,n,o,r,a=0,i){if(!e.length||!e[0].length||o<=0||r<=0)return;let s=null;if(n.hoverStrength>0){let e=J.get(t);e||(e={x:.5,y:.5,intensity:0,time:-1,emittedAt:-1,points:[]},J.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 r=t.intensity<.003,a=t.x,i=t.y;if(e){r&&(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&&!r&&n-t.emittedAt>=24&&Math.hypot(t.x-a,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-a)/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 J.delete(t);if("none"!==n.animationStyle||n.charsetFrames?.length||n.hoverStrength<=0)return Z.delete(t),void et(t,e,n,o,r,a,s);const c=Q.get(t);if(c?.frame!==e)return Q.set(t,{frame:e,since:performance.now()}),Z.delete(t),void et(t,e,n,o,r,a,s);if(performance.now()-c.since<100)return void et(t,e,n,o,r,a,s);const l=t.getTransform();if(l.b||l.c||l.a<=0||l.d<=0)return void et(t,e,n,o,r,a,s);if(!s||(s.intensity??0)<.003)return void et(t,e,n,o,r,a,null);const h=x(t.canvas),d={...n,accentColor:"#"+B(n.accentColor)},f=JSON.stringify([d,o,r,l.a,l.d,h,void 0!==document.fonts?document.fonts.status:"loaded"]);let m=Z.get(t);if(!m||m.frame!==e||m.key!==f){const n=m?.canvas??document.createElement("canvas");n.width=Math.ceil(o*l.a),n.height=Math.ceil(r*l.d);const a=n.getContext("2d");a.setTransform(l.a,0,0,l.d,0,0),et(a,e,d,o,r,0,null,void 0,h),m={frame:e,key:f,canvas:n},Z.set(t,m)}if(t.clearRect(0,0,o,r),t.drawImage(m.canvas,0,0,o,r),!s||(s.intensity??0)<.003)return;const u=e.length,g=e[0].length,p=.08+.35*n.hoverRadius+.04*n.hoverStrength,M="trail"===n.hoverEffect?[s,...s.trail??[]]:[s];let v=1,w=1,y=0,b=0;for(const t of M)v=Math.min(v,t.x-p),y=Math.max(y,t.x+p),w=Math.min(w,t.y-p),b=Math.max(b,t.y+p);if("glitchText"===n.hoverEffect){const t=n.hoverText,e=Math.max(1,...(Array.isArray(t)?t:[t]).map(t=>t.length));v=Math.min(v,s.x-e/g),y=Math.max(y,s.x+e/g)}const S=Math.ceil(5+4*n.hoverStrength),E={x:Math.max(0,Math.floor(v*g)-S),y:Math.max(0,Math.floor(w*u)-S),right:Math.min(g,Math.ceil(y*g)+S),bottom:Math.min(u,Math.ceil(b*u)+S)};t.save(),t.beginPath(),t.rect(E.x*o/g,E.y*r/u,(E.right-E.x)*o/g,(E.bottom-E.y)*r/u),t.clip(),et(t,e,d,o,r,a,s,E,h),t.restore()}function et(t,e,n,o,a,i=0,s,l,h){const d=e.length;if(0===d)return;const f=e[0].length;t.clearRect(0,0,o,a);let m=!1;const u=Math.max(1,d>>2),g=Math.max(1,f>>2);t:for(let t=0;t<d;t+=u){const n=e[t];for(let t=0;t<f;t+=g)if(n[t].a<200){m=!0;break t}}const M=t.canvas,w=h??x(M);m||(t.fillStyle=w?"#0a0a0a":"#faf9f7",t.fillRect(0,0,o,a));const y=o/f,b=a/d,S=s?.intensity??1,E=!!(s&&n.hoverStrength>0&&S>.005),T="#"+(q(n.hoverColor||"#ffffff")??"ffffff"),A=parseInt(T.slice(1,3),16),F=parseInt(T.slice(3,5),16),L=parseInt(T.slice(5,7),16),I=B(n.accentColor),R=parseInt(I.substring(0,2),16),k=parseInt(I.substring(2,4),16),H=parseInt(I.substring(4,6),16),$=n.hoverRadius;let j=0,z=f,V=0,D=d,N=0,U=0;if(E&&s){N=s.x,U=s.y;const t=.08+.35*$+.04*n.hoverStrength;j=Math.max(0,Math.floor((N-t)*f)-1),z=Math.min(f,Math.ceil((N+t)*f)+1),V=Math.max(0,Math.floor((U-t)*d)-1),D=Math.min(d,Math.ceil((U+t)*d)+1)}if(E&&"trail"===n.hoverEffect)for(const t of s?.trail??[]){const e=.08+.35*$+.04*n.hoverStrength;j=Math.min(j,Math.max(0,Math.floor((t.x-e)*f)-1)),z=Math.max(z,Math.min(f,Math.ceil((t.x+e)*f)+1)),V=Math.min(V,Math.max(0,Math.floor((t.y-e)*d)-1)),D=Math.max(D,Math.min(d,Math.ceil((t.y+e)*d)+1))}const K=n.animationStyle,Y=n.animationSpeed,X=(G=K,r.find(t=>t.value===G||t.mode===G)?.mode??"none");var G;const _="none"===X,J=[0,0,0,1],Q=n.hoverStrength,Z=n.hoverEffect,tt=$,et=n.hoverShape||"circle",nt=O(n.invert,M),ot=n.colorMode,rt=2*Math.PI,at=1/f,it=1/d;let st="",ct=-1;if("dots"===n.renderMode){const r=.5*Math.min(y,b)*n.dotSizeRatio;for(let n=l?.y??0;n<(l?.bottom??d);n++){const h=e[n];for(let e=l?.x??0;e<(l?.right??f);e++){const l=h[e];if(l.a<10)continue;const m=.00392156863*(.299*l.r+.587*l.g+.114*l.b),u=nt?1-m:m;if(u<.02)continue;_||c(X,e/f,n/d,i*Y,J,(.299*l.r+.587*l.g+.114*l.b)/255);const g=Math.max(0,Math.min(1,(1+J[2])*J[3]));let M=1,w=0,x=0,T=0,I=0;if(E&&e>=j&&e<=z&&n>=V&&n<=D){const t=C(e*at,n*it,N,U,S,Q,y,b,Z,tt,et,s?.trail,o/a);M=t.scale,w=t.offsetX,x=t.offsetY,T=t.glow,I=t.colorBlend}const W=r*u*g*M;if(W<.3)continue;const $=e*y+.5*y+w+J[0],P=n*b+.5*b+x+J[1];let O;if(I>0){const t=v(l,ot,R,k,H,nt);O=`rgb(${Math.min(255,t[0]+(A-t[0])*I|0)},${Math.min(255,t[1]+(F-t[1])*I|0)},${Math.min(255,t[2]+(L-t[2])*I|0)})`}else O=p(l,ot,R,k,H,nt);const q=Math.min(1,.00392156863*l.a*g*(1+T));if(q!==ct&&(t.globalAlpha=q,ct=q),O!==st&&(t.fillStyle=O,st=O),W<=3){const e=2*W;t.fillRect($-W,P-W,e,e)}else t.beginPath(),t.arc($,P,W,0,rt),t.fill()}}}else{const r=.55,h=.9*Math.min(y/r,b);{const e=/\p{Extended_Pictographic}/u.test(n.customText||n.charset);t.font=e?`${h}px "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twemoji Mozilla", sans-serif`:`${h}px "JetBrains Mono", monospace`,t.textAlign="center",t.textBaseline="middle"}const m=n.charsetFrames,u=!!m?.length,g=u?m[Math.floor(Math.max(0,i)*(n.charsetFps??2))%m.length]:n.charset,M=t.getTransform();if(!E&&_&&!u&&"accent"===ot&&!l&&n.hoverStrength<=0&&!/\p{Extended_Pictographic}/u.test(n.customText||n.charset)&&"letterSpacing"in t&&/^[\x20-\x7e]*$/.test(n.customText||n.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=y-o+"px",t.fillStyle=`rgb(${R},${k},${H})`,t.globalAlpha=1,t.textAlign="left";for(let n=0;n<d;n++){const r=e[n];let a="";for(let t=0;t<f;t++){const e=r[t];a+=e.a<10?" ":e.char}0!==a.trim().length&&t.fillText(a,.5*(y-o),n*b+.5*b)}return t.letterSpacing=n,t.textAlign="center",void(t.globalAlpha=1)}const w="glitchText"===Z&&E,x="!@#$%^&*<>{}[]|/\\~`0123456789",T=x.length;let I="",O=0,q=0,B=0,K=0,G=0,rt=0;if(w){const t=n.hoverText??"ASCIIFY";if(q=Math.round(N*f),B=Math.round(U*d),Array.isArray(t)){const e=t.filter(t=>t.length>0);0===e.length&&e.push("ASCIIFY");I=e[((7*Math.floor(q/Math.max(1,Math.ceil(f/5)))+13*Math.floor(B/Math.max(1,Math.ceil(d/3))))%e.length+e.length)%e.length]}else I=t||"ASCIIFY";O=I.length,K=Math.max(3,Math.min(12,Math.round(d*$*.6)));const e=Math.floor(K/2);G=Math.max(0,B-e),G+K>d&&(G=Math.max(0,d-K)),rt=q-Math.floor(O/2)}for(let n=l?.y??0;n<(l?.bottom??d);n++){const r=e[n];for(let h=l?.x??0;h<(l?.right??f);h++){const l=r[h];if(l.a<10)continue;let m=u&&null!=l.lum?P(l.lum,W(g),nt):l.char;if(" "===m)continue;_||c(X,h/f,n/d,i*Y,J,(.299*l.r+.587*l.g+.114*l.b)/255);const $=Math.max(0,Math.min(1,(1+J[2])*J[3]));if($<.05)continue;let lt=1,ht=0,dt=0,ft=0,mt=0;if(E&&!w&&h>=j&&h<=z&&n>=V&&n<=D){const t=C(h*at,n*it,N,U,S,Q,y,b,Z,tt,et,s?.trail,o/a);if(lt=t.scale,ht=t.offsetX,dt=t.offsetY,ft=t.glow,mt=t.colorBlend,"trail"===Z&&t.proximity>0){const o=Math.max(0,Math.min(f-1,Math.round(h-t.offsetX/y))),r=e[Math.max(0,Math.min(d-1,Math.round(n-t.offsetY/b)))][o],a=r.lum??.299*r.r+.587*r.g+.114*r.b;m=P(Math.min(255,a+t.proximity*Q*65),W(g),nt)}}if(w&&n>=G&&n<G+K){const t=h-rt;if(t>=0&&t<O){const e=I[t],o=Math.abs(n-B)/Math.max(1,.5*K),r=Math.abs(h-q)/Math.max(1,O),a=Math.max(o,r),s=Math.max(0,Math.min(1,1-.9*a)),c=43758.5453*Math.sin(127.1*h+311.7*n+43758.5453*Math.floor(12*i));m=Math.abs(c-Math.floor(c))<s?e:x[Math.abs(Math.floor(97*c))%T],ft=.3+.7*s,mt=.3+.65*s}}const ut=h*y+.5*y+ht+J[0],gt=n*b+.5*b+dt+J[1];let pt;if(mt>0){const t=v(l,ot,R,k,H,nt);pt=`rgb(${Math.min(255,t[0]+(A-t[0])*mt|0)},${Math.min(255,t[1]+(F-t[1])*mt|0)},${Math.min(255,t[2]+(L-t[2])*mt|0)})`}else pt=p(l,ot,R,k,H,nt);const Mt=Math.min(1,.00392156863*l.a*$*(1+ft));Mt!==ct&&(t.globalAlpha=Mt,ct=Mt),pt!==st&&(t.fillStyle=pt,st=pt),1!==lt?(t.translate(ut,gt),t.scale(lt,lt),t.fillText(m,0,0),t.setTransform(M)):t.fillText(m,ut,gt)}}}t.globalAlpha=1}function nt(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 ot(t){return Math.max(0,Math.min(1,t))}function rt(t){return"string"==typeof t?document.querySelector(t):t instanceof HTMLElement?t:null}function at(t){return"ascii"===t.renderMode&&"none"===t.animationStyle&&t.hoverStrength<=0&&!t.charsetFrames?.length}function it(t,e={}){const n=ot(t),o=ot(n*(void 0===e.speed?1:Math.max(.001,e.speed)));return ot(e.ease?e.ease(o):o)}function st(t,e,n={}){if(!Number.isFinite(t.duration)||t.duration<=0)return;const o=n.from??0,r=n.to??t.duration,a=Math.max(o,Math.min(r,t.duration)),i=it(e,n),s=o+(a-o)*i;t.currentTime=Math.min(Math.max(o,s),Math.max(o,a-.04)),n.onUpdate?.(i,t)}function ct(t,e){return Math.abs(t.currentTime-e)<1/240?lt(t):new Promise(n=>{const o=()=>{t.removeEventListener("seeked",o),n()};t.addEventListener("seeked",o,{once:!0});const r=t.fastSeek;r?r.call(t,e):t.currentTime=e})}function lt(t){const e=t.requestVideoFrameCallback;return new Promise(e?n=>{let o=!1;const r=()=>{o||(o=!0,n())};e.call(t,r),window.setTimeout(r,32)}:t=>requestAnimationFrame(()=>t()))}function ht(t,e={}){const n=rt(e.trigger)??t;t.pause();const o=e.gsap,r=e.ScrollTrigger??o?.ScrollTrigger;if(o&&r?.create){o.registerPlugin?.(r);const a=r.create({trigger:n,start:e.start??"top bottom",end:e.end??"bottom top",scrub:e.scrub??!0,onUpdate:n=>st(t,n.progress,e)});return()=>a.kill?.()}return function(t,e,n){let o=0;const r=()=>{o=0;const r=e.getBoundingClientRect(),a=window.innerHeight||document.documentElement.clientHeight,i=r.height+a,s=i>0?ot((a-r.top)/i):0;st(t,s,n)},a=()=>{o||(o=requestAnimationFrame(r))};return window.addEventListener("scroll",a,{passive:!0}),window.addEventListener("resize",a),a(),()=>{window.removeEventListener("scroll",a),window.removeEventListener("resize",a),o&&cancelAnimationFrame(o)}}(t,n,e)}function dt(t,e,n){const o=e.gsap,r=e.ScrollTrigger??o?.ScrollTrigger;if(o&&r?.create){o.registerPlugin?.(r);const a=r.create({trigger:t,start:e.start??"top bottom",end:e.end??"bottom top",scrub:e.scrub??!0,onUpdate:t=>n(t.progress)});return()=>a.kill?.()}return function(t,e){let n=0;const o=()=>{n=0;const o=t.getBoundingClientRect(),r=window.innerHeight||document.documentElement.clientHeight,a=o.height+r,i=a>0?ot((r-o.top)/a):0;e(i)},r=()=>{n||(n=requestAnimationFrame(o))};return window.addEventListener("scroll",r,{passive:!0}),window.addEventListener("resize",r),r(),()=>{window.removeEventListener("scroll",r),window.removeEventListener("resize",r),n&&cancelAnimationFrame(n)}}(t,n)}function ft(t,e,n){if(!t||!e||!n.sourceCrop)return{w:t,h:e};const o=D(n.sourceCrop,t,e);return{w:Math.max(1,Math.round(o.width)),h:Math.max(1,Math.round(o.height))}}function mt(t,e,n,o){const r=o.chromaKey;if(null==r||!1===r)return!1;if(!0===r)return e>1.4*t&&e>1.4*n&&e>80;if("blue-screen"===r)return n>1.4*t&&n>1.4*e&&n>80;const a=b(r),i=(o.chromaKeyTolerance??60)**2,s=t-a.r,c=e-a.g,l=n-a.b;return s*s+c*c+l*l<=i}function ut(t,e,n){if(!e.chromaKey||!e.sourceCrop||"off"===e.chromaKeyTrimMode)return e;const o=t instanceof HTMLVideoElement?t.videoWidth:t.width,r=t instanceof HTMLVideoElement?t.videoHeight:t.height;if(!o||!r)return e;const a=D(e.sourceCrop,o,r),i=Math.min(360,Math.max(1,Math.round(a.width))),s=Math.max(1,Math.round(i*(a.height/a.width))),{ctx:c}=l(i,s);c.drawImage(t,a.x,a.y,a.width,a.height,0,0,i,s);const h=c.getImageData(0,0,i,s).data,d=Math.max(0,Math.min(255,e.chromaKeyTrimLuminanceThreshold??0));let f=i,m=s,u=-1,g=-1;for(let t=0;t<s;t++)for(let n=0;n<i;n++){const o=4*(t*i+n),r=h[o+3],a=h[o],s=h[o+1],c=h[o+2];r<=8||.2126*a+.7152*s+.0722*c<=d||mt(a,s,c,e)||(n<f&&(f=n),t<m&&(m=t),n>u&&(u=n),t>g&&(g=t))}if(u<f||g<m)return e;const p=Math.max(0,Math.min(.25,e.chromaKeyTrimPadding??.002)),M=Math.round(i*p),v=Math.round(s*p);f=Math.max(0,f-M),m=Math.max(0,m-v),u=Math.min(i-1,u+M),g=Math.min(s-1,g+v);const w=function(t,e,n,o,r){const a=r&&Number.isFinite(r)&&r>0?r:null;if(!a)return t;const i=e.x,s=e.y,c=e.x+e.width,l=e.y+e.height,h=Math.max(i,t.left),d=Math.max(s,t.top),f=Math.min(c,n-t.right),m=Math.min(l,o-t.bottom),u=Math.max(1,f-h),g=Math.max(1,m-d),p=h+u/2,M=d+g/2;let v=u,w=g;v/w<a?v=w*a:w=v/a;v>e.width&&(v=e.width,w=Math.max(g,Math.min(e.height,v/a)));w>e.height&&(w=e.height,v=Math.max(u,Math.min(e.width,w*a)));let y=p-v/2,x=M-w/2;return y=Math.max(i,Math.min(c-v,y)),x=Math.max(s,Math.min(l-w,x)),{left:y,top:x,right:n-(y+v),bottom:o-(x+w)}}({left:a.x+f/i*a.width,top:a.y+m/s*a.height,right:o-(a.x+(u+1)/i*a.width),bottom:r-(a.y+(g+1)/s*a.height)},{x:a.x,y:a.y,width:a.width,height:a.height},o,r,n);return{...e,sourceCrop:{unit:"pixel",...w,preserveAspect:!1}}}function gt(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 pt(t,e,n,o,r){if(!e.chromaKey||!e.sourceCrop||"range"!==e.chromaKeyTrimMode)return e;const a=t.currentTime,i=function(t,e,n,o){const r=!0===o?{}:o||{},a=Math.max(0,r.from??e),i=r.to??n??(Number.isFinite(t.duration)?t.duration:a),s=Math.max(a,i-.04),c=Math.max(0,s-a),l=c>.1?[a,a+.25*c,a+.5*c,a+.75*c,s]:[a];return Array.from(new Set(l.map(t=>Math.max(0,Number(t.toFixed(3))))))}(t,n,o,r);let s=null;for(const n of i){await ct(t,n),await lt(t);const o=gt(ut(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 ct(t,a),await lt(t),s?{...e,sourceCrop:{unit:"pixel",...s,preserveAspect:!0}}:e}function Mt(t,e,n=2048){return vt({sourceWidth:t,sourceHeight:e,maxRenderDimension:n})}function vt({sourceWidth:t,sourceHeight:e,cssWidth:n=0,cssHeight:o=0,maxRenderDimension:r=2048}){const a=Math.max(1,t),i=Math.max(1,e),s=a/i,c=Math.max(1,r),l=Math.min(1,c/Math.max(a,i)),h=Math.max(a,i)*l,d=Math.max(0,n,o),f=Math.min(c,Math.max(h,d));return s>=1?{renderW:Math.round(f),renderH:Math.round(f/s)}:{renderW:Math.round(f*s),renderH:Math.round(f)}}function wt(t,e,n,o){if(void 0===t)return;if("number"==typeof t)return t;const r=t.trim();if(r.endsWith("%")){const t=Number.parseFloat(r)/100;return Number.isFinite(t)?e*t:void 0}if(r.endsWith("px")){const t=Number.parseFloat(r);return Number.isFinite(t)?t:void 0}if(r.endsWith("vw")){const t=Number.parseFloat(r)/100;return Number.isFinite(t)?n*t:void 0}if(r.endsWith("vh")){const t=Number.parseFloat(r)/100;return Number.isFinite(t)?o*t:void 0}}function yt(t,e,n,o,r,a=2048,i={}){const{width:s,height:c}=e.getBoundingClientRect();if(!s||!c)return{renderW:0,renderH:0,dpr:1};const l="undefined"!=typeof window?window.innerWidth:s,h="undefined"!=typeof window?window.innerHeight:c,d=wt(i.width,s,l,h)??s,f=wt(i.height,c,l,h)??c,m=function(t,e,n,o,r){const a=t=>{const n=wt(t,e,o,r);return n&&n>0?n:0},i=t=>{const e=wt(t,n,o,r);return e&&e>0?e:0};return void 0===t?{x:0,y:0}:"number"==typeof t||"string"==typeof t?{x:a(t),y:i(t)}:{x:a(t.x),y:i(t.y)}}(i.bleed,s,c,l,h),u=d+2*m.x,g=f+2*m.y,{cssW:p,cssH:M}=function(t,e,n,o="contain"){if("fill"===o)return{cssW:t,cssH:e};let r=t,a=r/n;const i="cover"===o,s=a>e;return(i&&!s||!i&&s)&&(a=e,r=a*n),"scale-down"===o&&(r=Math.min(r,t),a=Math.min(a,e)),{cssW:Math.round(r),cssH:Math.round(a)}}(u,g,n,i.objectFit??"contain"),v="undefined"!=typeof window&&window.devicePixelRatio||1;let w,y;o&&r?({renderW:w,renderH:y}=vt({sourceWidth:o,sourceHeight:r,cssWidth:p,cssHeight:M,maxRenderDimension:a})):(w=p,y=M);const x=8e6,b=w*v*y*v>x?Math.sqrt(x/(w*y)):v;return t.width=Math.round(w*b),t.height=Math.round(y*b),t.style.width=`${p}px`,t.style.height=`${M}px`,{renderW:w,renderH:y,dpr:b}}async function xt(t,e,{fontSize:o,artStyle:r="classic",options:a={}}={}){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=nt(r),c=o??a.fontSize??10,l={...n,...s,artStyle:r,...a,fontSize:c},h=e.getContext("2d");if(!h)throw new Error("Could not get 2d context from canvas");const{w:d,h:f}=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:m,renderH:u}=Mt(d,f),g="undefined"!=typeof window&&window.devicePixelRatio||1,p=8e6,M=m*g*u*g>p?Math.sqrt(p/(m*u)):g;e.width===Math.round(m*M)&&e.height===Math.round(u*M)||(e.width=Math.round(m*M),e.height=Math.round(u*M));const{frame:v}=N(i,l,m,u),w=(t,e)=>{h.save(),h.setTransform(M,0,0,M,0,0),tt(h,v,l,m,u,t/1e3,e),h.restore()};w(0,null);return T(e,w,{continuous:"none"!==l.animationStyle||!!l.charsetFrames?.length,interactive:l.hoverStrength>0}).stop}async function bt(t,e,{fontSize:o,artStyle:r="classic",options:a={}}={}){const i="string"==typeof t?await fetch(t).then(t=>t.arrayBuffer()):t,s=o??a.fontSize??10;let c={...n,...nt(r),artStyle:r,...a,fontSize:s};const l=e.getContext("2d");if(!l)throw new Error("Could not get 2d context from canvas");const{frames:h,fps:d}=await G(i,c,e.width,e.height);if(!h.length)throw new Error("asciifyGif: the GIF contains no renderable frames.");const f=performance.now();let m=-1;return T(e,(t,n)=>{const o=Math.floor((t-f)*d/1e3)%h.length;o===m&&!n&&c.hoverStrength<=0&&"none"===c.animationStyle&&!c.charsetFrames?.length||(tt(l,h[o],c,e.width,e.height,(t-f)/1e3,n),m=o)},{continuous:!0,interactive:c.hoverStrength>0}).stop}async function St(t,e,{fontSize:o,artStyle:r="classic",options:a={},fitTo:i,objectFit:s,objectPosition:c,scale:l,width:h,height:d,bleed:f,preExtract:m=!1,fps:u,maxRenderDimension:g=2048,trim:p,scroll:M,maxCachedFrames:v=90,onReady:w,onFrame:y}={}){const x=p?.start??0,b=p?.end,S=o??a.fontSize??10;let E={...n,...nt(r),artStyle:r,...a,fontSize:S};const C=e.getContext("2d");if(!C)throw new Error("asciifyVideo: could not get 2d context from canvas.");const A="string"==typeof i?document.querySelector(i):i instanceof HTMLElement?i:null,F={objectFit:s,objectPosition:c,scale:l,width:h,height:d,bleed:f},L=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")}}(e,F),I=t=>()=>{t(),L()};if(m){let n;"string"==typeof t?(n=document.createElement("video"),n.crossOrigin="anonymous",n.src=t,n.readyState<2&&await new Promise((e,o)=>{n.onloadeddata=()=>e(),n.onerror=()=>o(new Error(`asciifyVideo: failed to load "${t}"`))})):n=t,E=await pt(n,E,x,b,M);const o=ft(n.videoWidth,n.videoHeight,E);A&&yt(e,A,o.w/o.h,o.w,o.h,g,F);const{renderW:r,renderH:a}=Mt(o.w,o.h,g),i="undefined"!=typeof window&&window.devicePixelRatio||1,s=8e6,c=r*i*a*i>s?Math.sqrt(s/(r*a)):i;e.width===Math.round(r*c)&&e.height===Math.round(a*c)||(e.width=Math.round(r*c),e.height=Math.round(a*c));const l=void 0!==b?b-x:10,h=u??(M?18:void 0);if(at(E)){const{frames:t,fps:o}=await X(n,E,r,a,h,l,void 0,x),i=e=>{const n=t[e];n&&(C.save(),C.setTransform(c,0,0,c,0,0),K(C,n,E,r,a),C.restore(),y?.())};if(M){let o=!1,r=-1;const a=!0===M?{}:M,s=dt(rt(a.trigger)??A??e,a,e=>{const s=it(e,a),c=Math.max(0,Math.min(t.length-1,Math.round(s*(t.length-1))));c!==r&&(r=c,i(c),o||(o=!0,w?.(n)),a.onUpdate?.(s,n))});return i(0),o=!0,w?.(n),I(s)}let s,d=!1,f=0,m=performance.now(),u=!0;const g=1e3/o,p=e=>{d||(e-m>=g&&(i(f),f=(f+1)%t.length,m=e,u&&(u=!1,w?.(n))),s=requestAnimationFrame(p))};return s=requestAnimationFrame(p),I(()=>{d=!0,cancelAnimationFrame(s)})}const{frames:d,fps:f}=await Y(n,E,r,a,h,l,void 0,x);if(!d.length)throw new Error("asciifyVideo: no frames were decoded.");let m=0;const p=performance.now(),v=T(e,(t,e)=>{M||(m=Math.floor((t-p)*f/1e3)%d.length),C.save(),C.setTransform(c,0,0,c,0,0),tt(C,d[m],E,r,a,(t-p)/1e3,e),C.restore(),y?.()},{continuous:!M||"none"!==E.animationStyle||!!E.charsetFrames?.length,interactive:E.hoverStrength>0});let S;if(M){const t=!0===M?{}:M;S=dt(rt(t.trigger)??A??e,t,e=>{m=Math.max(0,Math.min(d.length-1,Math.round(it(e,t)*(d.length-1)))),v.wake(),t.onUpdate?.(e,n)})}return w?.(n),I(()=>{v.stop(),S?.()})}let R,k=!1;"string"==typeof t?(R=document.createElement("video"),R.crossOrigin="anonymous",R.src=t,R.muted=!0,R.loop=!0,R.playsInline=!0,R.setAttribute("playsinline",""),Object.assign(R.style,{position:"fixed",top:"0",left:"0",width:"1px",height:"1px",opacity:"0",pointerEvents:"none",zIndex:"-1"}),document.body.appendChild(R),k=!0,await new Promise((e,n)=>{R.onloadedmetadata=()=>e(),R.onerror=()=>n(new Error(`asciifyVideo: failed to load "${t}"`))}),await R.play().catch(()=>{})):(R=t,R.readyState<HTMLMediaElement.HAVE_METADATA&&await new Promise((t,e)=>{const n=()=>{R.removeEventListener("loadedmetadata",o),R.removeEventListener("error",r)},o=()=>{n(),t()},r=()=>{n(),e(new Error("asciifyVideo: provided video element failed to load metadata."))};R.addEventListener("loadedmetadata",o),R.addEventListener("error",r),R.load()}),R.paused&&await R.play().catch(()=>{})),x>0&&(R.currentTime=x,await new Promise(t=>{const e=()=>{R.removeEventListener("seeked",e),t()};R.addEventListener("seeked",e)}),await lt(R));let H=null;(x>0||void 0!==b)&&(H=()=>{(void 0!==b&&R.currentTime>=b||x>0&&R.currentTime<x)&&(R.currentTime=x)},R.addEventListener("timeupdate",H)),E=await pt(R,E,x,b,M);let W=null;const $=ft(R.videoWidth,R.videoHeight,E);let{renderW:P,renderH:j}=Mt($.w,$.h,g);const z=t=>"frame"===E.chromaKeyTrimMode?ut(t,E,P/j):E;if(A){const t=$.w/$.h,n=$.w,o=$.h,r=yt(e,A,t,n,o,g,F);P=r.renderW,j=r.renderH;const a=e.getContext("2d");a&&a.setTransform(r.dpr,0,0,r.dpr,0,0),W=new ResizeObserver(()=>{const r=yt(e,A,t,n,o,g,F);P=r.renderW,j=r.renderH;const a=e.getContext("2d");a&&a.setTransform(r.dpr,0,0,r.dpr,0,0)}),W.observe(A)}else{const t="undefined"!=typeof window&&window.devicePixelRatio||1,n=8e6,o=P*t*j*t>n?Math.sqrt(n/(P*j)):t;e.width===Math.round(P*o)&&e.height===Math.round(j*o)||(e.width=Math.round(P*o),e.height=Math.round(j*o)),C.setTransform(o,0,0,o,0,0)}let O=!0,q=null;const B=M&&!m,V=u&&u>0?1e3/u:0;let D=0;const G=!B&&at(E);if(B&&"ascii"===E.renderMode&&"none"===E.animationStyle&&E.hoverStrength<=0&&!E.charsetFrames?.length){const t=!0===M?{}:M,n=rt(t.trigger)??A??e,o=t.from??x,r=t.to??b??R.duration,a=Math.max(o,Math.min(r,R.duration)),i=Math.max(.001,a-o),s=Math.min(60,Math.max(12,u??30)),c=Math.max(2,Math.ceil(i*s)+1),l=new Array(c),h=[],d=Math.max(2,Math.min(c,Math.floor(v))),f=()=>{for(;h.length>d;){const t=h.findIndex(t=>t!==g&&Math.abs(t-g)>2),e=t>=0?t:0,n=h.splice(e,1)[0];void 0!==n&&(l[n]=void 0)}},m=t=>{const e=h.indexOf(t);e>=0&&h.splice(e,1),h.push(t),f()};let g=0,p=0,S=-1,T=0,F=!1,L=!1,$=!1;const O=new Set,B=document.createElement("video");B.muted=!0,B.playsInline=!0,B.preload="auto",B.crossOrigin=R.crossOrigin||"anonymous",B.src=R.currentSrc||R.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",r)},o=()=>{n(),t()},r=()=>{n(),e(new Error("asciifyVideo: cache video failed to load metadata."))};B.addEventListener("loadedmetadata",o),B.addEventListener("error",r),B.load()}),B.pause(),R.paused&&await R.play().catch(()=>{});const N=t=>o+i*t/Math.max(1,c-1),Y=t=>Math.max(0,Math.min(c-1,Math.round(t*(c-1)))),X=z(R),G=U(R,X,P,j);G.rows.length>0&&(l[0]=G,m(0),K(C,G,X,P,j),$=!0,w?.(R),y?.());const _=t=>{if(l[t])return t;for(let e=1;e<c;e++){const n=t-e,o=t+e;if(n>=0&&l[n])return n;if(o<c&&l[o])return o}return-1},J=()=>{if(!l[g])return g;for(const t of O)if(!l[t])return t;for(let t=1;t<c;t++){const e=g-t,n=g+t;if(e>=0&&!l[e])return e;if(n<c&&!l[n])return n}return-1},Q=t=>{t<0||t>=c||l[t]||(O.add(t),Z())},Z=async()=>{if(F||L)return;const t=J();if(!(t<0)){O.delete(t),L=!0;try{if(await ct(B,N(t)),!F){const e=z(B),n=U(B,e,P,j);n.rows.length>0&&(l[t]=n,m(t))}}finally{L=!1,F||requestAnimationFrame(()=>{Z()})}}},tt=()=>{if(F)return;const t=_(g);if(t>=0&&t!==S){const e=l[t];e&&(K(C,e,E,P,j),S=t,$||($=!0,w?.(R)),y?.())}else if(t<0||S<0){const t=performance.now();if(V<=0||t-D>=V){const e=z(R),n=U(R,e,P,j);n.rows.length>0&&(K(C,n,e,P,j),D=t,$||($=!0,w?.(R)),y?.())}}Q(g),T=requestAnimationFrame(tt)};return q=dt(n,t,e=>{const n=function(t,e,n={}){if(!Number.isFinite(t.duration)||t.duration<=0)return null;const o=n.from??0,r=n.to??t.duration,a=Math.max(o,Math.min(r,t.duration)),i=it(e,n),s=o+(a-o)*i;return{progress:i,time:Math.min(Math.max(o,s),Math.max(o,a-.04))}}(R,e,{...t,from:o,to:a});p=n?.progress??ot(e),g=Y(p),Q(g),Q(g-1),Q(g+1),Q(g-2),Q(g+2),Q(g-3),Q(g+3),t.onUpdate?.(p,R)}),Q(0),Q(1),T=requestAnimationFrame(tt),I(()=>{F=!0,cancelAnimationFrame(T),q?.(),W?.disconnect(),O.clear(),h.length=0,l.fill(void 0),B.pause(),B.src="",B.removeAttribute("src"),B.load(),B.isConnected&&B.remove(),H&&R.removeEventListener("timeupdate",H),k&&(R.pause(),R.src="",R.removeAttribute("src"),R.load(),R.isConnected&&R.remove())})}if(B){const t=!0===M?{}:M;q=ht(R,{...t,trigger:t.trigger??A??e,from:t.from??x,to:t.to??b})}let _=-1,J=0,Q=-1,Z=0;const et="function"==typeof R.requestVideoFrameCallback,st=()=>{Z=R.requestVideoFrameCallback(()=>{J++,st()})};et&&st();let mt=0,gt=0,vt=null;const wt=T(e,(t,n)=>{if(R.readyState<2||0===e.width||0===e.height)return;if(V>0&&t-D<V&&!n)return;if(x>0&&R.currentTime<x)return;if(void 0!==b&&R.currentTime>=b)return;const o=(et?J!==Q:R.currentTime!==_)||mt!==P||gt!==j;if(o||!(E.hoverStrength<=0)||"none"!==E.animationStyle||E.charsetFrames?.length){if(G){const t=z(R),e=U(R,t,P,j);K(C,e,t,P,j)}else!o&&vt||(vt=N(R,z(R),P,j).frame),tt(C,vt,E,P,j,t/1e3,n);_=R.currentTime,Q=J,mt=P,gt=j,D=t,O&&(O=!1,w?.(R)),y?.()}},{continuous:!0,interactive:E.hoverStrength>0});return I(()=>{wt.stop(),Z&&R.cancelVideoFrameCallback(Z),q?.(),W?.disconnect(),H&&R.removeEventListener("timeupdate",H),k&&(R.pause(),R.src="",R.removeAttribute("src"),R.load(),R.isConnected&&R.remove())})}function Et(t,e,n){return St(t,e,n)}function Ct(t,e={},o,r){const a={...n,...e},{frame:i,cols:s}=N(t,a,o,r);if(!i.length||0===s)return"";const c=[];for(const t of i)c.push(t.map(t=>t.char).join(""));return c.join("\n")}function Tt(t,e={},o,r){const a={...n,...e},{frame:i,cols:s}=N(t,a,o,r);if(!i.length||0===s)return"";const c=[];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}`;c.push(e)}return c.join("\n")}function At(t,e,n,o="#505050",r=100){if(!t||e<=0||n<=0)return[];const a=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:a.r,g:a.g,b:a.b,a:r})))}var Ft=new WeakMap;function Lt(t,e,o,r,a={},i){const{fontSize:s=10,lineHeight:c=1.6,color:l="#505050",opacity:h=100,hoverEffect:d="spotlight",hoverStrength:f=.85,hoverRadius:m=.18,hoverColor:u="#d4ff00"}=a,g=Math.max(1,Math.floor(e/s)),p=Math.max(1,Math.floor(o/(s*c))),M=JSON.stringify([r,g,p,l,h]);let v=Ft.get(t);v&&v.key===M||(v={key:M,frame:At(r,g,p,l,h)},Ft.set(t,v));tt(t,v.frame,{...n,fontSize:s,hoverEffect:d,hoverStrength:f,hoverRadius:m,hoverColor:u},e,o,0,i??null)}function It(t,{format:e="png",quality:n=.92,scale:o=1}={}){return new Promise((r,a)=>{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 a(new Error("captureSnapshot: could not get 2d context"));n.drawImage(t,0,0,e.width,e.height),i=e}i.toBlob(t=>t?r(t):a(new Error("captureSnapshot: toBlob returned null")),`image/${e}`,n)})}async function Rt(t,e={}){const{filename:n="asciify-snapshot",format:o="png",...r}=e,a=await It(t,{format:o,...r}),i="jpeg"===o?"jpg":o,s=document.createElement("a");s.href=URL.createObjectURL(a),s.download=`${n}.${i}`,s.click(),setTimeout(()=>URL.revokeObjectURL(s.href),1e4)}async function kt(t,{fontSize:e=10,style:o="classic",options:r={},liveOptions:a,mirror:i=!0,constraints:s={facingMode:"user"},dpr:c}={}){if(!navigator.mediaDevices?.getUserMedia)throw new Error("asciifyWebcam: getUserMedia is not supported in this browser.");const l=nt(o),h=await navigator.mediaDevices.getUserMedia({video:s}),d=document.createElement("video");d.srcObject=h,d.muted=!0,d.playsInline=!0,await new Promise((t,e)=>{d.onloadedmetadata=()=>t(),d.onerror=()=>e(new Error("asciifyWebcam: video stream failed to load.")),d.play().catch(e)});const f={...n,...l,...r,fontSize:e},m=t.getContext("2d");if(!m)throw new Error("asciifyWebcam: could not get 2d context from canvas.");const u=c??("undefined"!=typeof window?window.devicePixelRatio:1)??1;1!==u&&m.scale(u,u);let g=null;const p=e=>{const n=t.getBoundingClientRect();g={x:(e.clientX-n.left)/n.width,y:(e.clientY-n.top)/n.height}},M=()=>{g=null};f.hoverStrength>0&&(t.addEventListener("mousemove",p),t.addEventListener("mouseleave",M));let v,w=!1;const y=performance.now(),x=e=>{if(!w){if(d.readyState>=d.HAVE_CURRENT_DATA){const n=t.width/u,o=t.height/u,r=(e-y)/1e3,s=a?{...f,...a()}:f;s.hoverStrength>0?(t.addEventListener("mousemove",p),t.addEventListener("mouseleave",M)):(t.removeEventListener("mousemove",p),t.removeEventListener("mouseleave",M));const{frame:c}=N(d,s,n,o),l=g&&i?{x:1-g.x,y:g.y}:g;i?(m.save(),m.scale(-1,1),m.translate(-n,0),tt(m,c,s,n,o,r,l),m.restore()):tt(m,c,s,n,o,r,l)}v=requestAnimationFrame(x)}};return v=requestAnimationFrame(x),()=>{w=!0,cancelAnimationFrame(v),t.removeEventListener("mousemove",p),t.removeEventListener("mouseleave",M),h.getTracks().forEach(t=>t.stop()),d.srcObject=null}}var Ht={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]},Wt=[127,65,65,65,65,65,127];function $t(t){return Ht[t]??Ht[t.toUpperCase()]??Wt}function Pt(t,e={}){if(!t)return"";const{char:n="█",scale:o=1}=e,r=[...n][0]??"█",a=Math.max(1,Math.floor(o)),i=7*a,s=a,c=Array.from({length:i},()=>"");for(let e=0;e<t.length;e++){const n=$t(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?r:" ").repeat(a);for(let e=0;e<a;e++)c[t*a+e]+=o}if(e<t.length-1)for(let t=0;t<i;t++)c[t]+=" ".repeat(s)}return c.join("\n")}function jt(t,e,n={}){const{color:o="#d4ff00",bgColor:r,fontSize:a=10}=n,i=Pt(e,n);if(!i)return;const s=i.split("\n"),c=Math.max(...s.map(t=>[...t].length));t.width=Math.ceil(c*a*.6),t.height=Math.ceil(s.length*a);const l=t.getContext("2d");r&&"transparent"!==r?(l.fillStyle=r,l.fillRect(0,0,t.width,t.height)):l.clearRect(0,0,t.width,t.height),l.fillStyle=o,l.font=`${a}px monospace`,l.textBaseline="top",s.forEach((t,e)=>l.fillText(t,0,e*a))}var zt=["ascii","blocks","braille","dots","lines","cross","diagonal","diamond","mixed","pixel","mosaic","lego","voxel","disco","dither","hex","led","cmyk","stipple","engraving","crosshatch","woodblock","risograph","pointillism"];export{t as CHARACTER_SETS,n as DEFAULT_OPTIONS,o as HOVER_PRESETS,e as PALETTE_THEMES,zt as STUDIO_STYLES,Ct as asciiText,Tt as asciiTextAnsi,xt as asciify,bt as asciifyGif,Et as asciifyLiveVideo,Pt as asciifyText,St as asciifyVideo,kt as asciifyWebcam,At as buildTextFrame,It as captureSnapshot,z as clearAsciifyCaches,vt as computeCanvasRenderSize,ht as createVideoScrollScrub,G as gifToAsciiFrames,_ as gifToAsciiTextFrames,N as imageToAsciiFrame,U as imageToAsciiTextFrame,tt as renderFrameToCanvas,Lt as renderTextBackground,K as renderTextFrameToCanvas,jt as renderTextToCanvas,Rt as snapshotAndDownload,Y as videoToAsciiFrames,X as videoToAsciiTextFrames};//# sourceMappingURL=core.js.map
package/dist/field.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var e=e=>e?"\nconst float VSCALE=6.;\nvec4 decodeFluid(vec4 t){return vec4((t.xy*2.-1.)*VSCALE,t.z,t.w);}\nvec4 encodeFluid(vec4 v){return vec4(clamp(v.xy/VSCALE*.5+.5,0.,1.),clamp(v.z,0.,1.),1.);}":"\nvec4 decodeFluid(vec4 t){return t;}\nvec4 encodeFluid(vec4 v){return vec4(v.xyz,1.);}",t="#version 300 es\nprecision highp float;\nprecision highp sampler2D;\nuniform vec2 uTexel;\nout vec4 outColor;\nvec2 here(){return gl_FragCoord.xy*uTexel;}\n",n=t+"\nuniform sampler2D uVelocity;\nuniform vec2 uFrom, uTo, uForce;\nuniform float uAspect, uRadius;\nfloat segment(vec2 p,vec2 a,vec2 b){vec2 pa=p-a,ba=b-a;float h=clamp(dot(pa,ba)/max(dot(ba,ba),1e-8),0.,1.);return length(pa-ba*h);}\nvoid main(){\n vec2 uv=here(),scale=vec2(uAspect,1.);\n float d=segment(uv*scale,uFrom*scale,uTo*scale);\n outColor=vec4(texture(uVelocity,uv).xy+uForce*exp(-d*d/(uRadius*uRadius)),0.,1.);\n}",r=t+"\nuniform sampler2D uVelocity;\nvoid main(){\n vec2 uv=here();\n float l=texture(uVelocity,uv-vec2(uTexel.x,0.)).y,r=texture(uVelocity,uv+vec2(uTexel.x,0.)).y;\n float t=texture(uVelocity,uv+vec2(0.,uTexel.y)).x,b=texture(uVelocity,uv-vec2(0.,uTexel.y)).x;\n outColor=vec4(.5*(r-l-t+b),0.,0.,1.);\n}",i=t+"\nuniform sampler2D uVelocity, uCurl;\nuniform float uStrength, uDt;\nvoid main(){\n vec2 uv=here();\n float l=texture(uCurl,uv-vec2(uTexel.x,0.)).x,r=texture(uCurl,uv+vec2(uTexel.x,0.)).x;\n float t=texture(uCurl,uv+vec2(0.,uTexel.y)).x,b=texture(uCurl,uv-vec2(0.,uTexel.y)).x,c=texture(uCurl,uv).x;\n vec2 force=.5*vec2(abs(t)-abs(b),abs(r)-abs(l));\n force=force/(length(force)+1e-4)*uStrength*c;\n force.y=-force.y;\n outColor=vec4(clamp(texture(uVelocity,uv).xy+force*uDt,-1000.,1000.),0.,1.);\n}",o=t+"\nuniform sampler2D uVelocity;\nvoid main(){\n vec2 uv=here(),c=texture(uVelocity,uv).xy;\n float l=texture(uVelocity,uv-vec2(uTexel.x,0.)).x,r=texture(uVelocity,uv+vec2(uTexel.x,0.)).x;\n float t=texture(uVelocity,uv+vec2(0.,uTexel.y)).y,b=texture(uVelocity,uv-vec2(0.,uTexel.y)).y;\n if(uv.x-uTexel.x<0.)l=-c.x;\n if(uv.x+uTexel.x>1.)r=-c.x;\n if(uv.y+uTexel.y>1.)t=-c.y;\n if(uv.y-uTexel.y<0.)b=-c.y;\n outColor=vec4(.5*(r-l+t-b),0.,0.,1.);\n}",a=t+"\nuniform sampler2D uSource;\nuniform float uAmount;\nvoid main(){outColor=vec4(texture(uSource,here()).x*uAmount,0.,0.,1.);}",l=t+"\nuniform sampler2D uPressure, uDivergence;\nvoid main(){\n vec2 uv=here();\n float l=texture(uPressure,uv-vec2(uTexel.x,0.)).x,r=texture(uPressure,uv+vec2(uTexel.x,0.)).x;\n float t=texture(uPressure,uv+vec2(0.,uTexel.y)).x,b=texture(uPressure,uv-vec2(0.,uTexel.y)).x;\n outColor=vec4((l+r+b+t-texture(uDivergence,uv).x)*.25,0.,0.,1.);\n}",u=t+"\nuniform sampler2D uPressure, uVelocity;\nvoid main(){\n vec2 uv=here();\n float l=texture(uPressure,uv-vec2(uTexel.x,0.)).x,r=texture(uPressure,uv+vec2(uTexel.x,0.)).x;\n float t=texture(uPressure,uv+vec2(0.,uTexel.y)).x,b=texture(uPressure,uv-vec2(0.,uTexel.y)).x;\n outColor=vec4(texture(uVelocity,uv).xy-vec2(r-l,t-b),0.,1.);\n}",s=t+"\nuniform sampler2D uVelocity;\nuniform float uDt, uDissipation;\nvoid main(){\n vec2 uv=here();\n vec2 back=uv-uDt*texture(uVelocity,uv).xy*uTexel;\n outColor=vec4(texture(uVelocity,back).xy/(1.+uDissipation*uDt),0.,1.);\n}";var c=class{constructor(e,t){this.previous=null,this.peak=0,this.width=e,this.height=t;const n=e*t;this.pixels=new Uint8Array(4*n),this.signal=new Float32Array(n),this.offsetX=new Float32Array(n),this.offsetY=new Float32Array(n),this.driftX=new Float32Array(n),this.driftY=new Float32Array(n),this.u=new Float32Array(n),this.v=new Float32Array(n),this.ink=new Float32Array(n),this.a=new Float32Array(n),this.b=new Float32Array(n),this.c=new Float32Array(n),this.pressure=new Float32Array(n),this.pressureNext=new Float32Array(n),this.divergence=new Float32Array(n),this.curl=new Float32Array(n)}get active(){return this.peak>2e-4}clear(){for(const e of[this.u,this.v,this.ink,this.a,this.b,this.c,this.pressure,this.pressureNext,this.divergence,this.curl,this.signal,this.pixels,this.offsetX,this.offsetY,this.driftX,this.driftY])e.fill(0);this.previous=null,this.peak=0}leave(){this.previous=null}move(e,t,n,r=performance.now()){if(!Number.isFinite(e+t+n+r))return;e=Math.max(0,Math.min(1,e)),t=Math.max(0,Math.min(1,t)),n=Math.max(.1,Math.min(1,n));const i=this.previous;if(this.previous={x:e,y:t,time:r},!i)return;const o=(e-i.x)*(this.width-1),a=(t-i.y)*(this.height-1),l=Math.hypot(o,a);if(l<.001)return;const u=Math.min(this.width,this.height),s=r>i.time?Math.max(1/240,(r-i.time)/1e3):1/60,c=Math.min(12,l/u/s),f=1-Math.exp(-c/2.2),h=u*(.022+.075*n)*(.65+.95*f),d=Math.min(128,Math.max(1,Math.ceil(l/(.4*h)))),m=l/h*(.32+.22*f)/d,v=o/l,p=a/l,g=-p,x=v,E=l*(2+18*f)/d;for(let n=0;n<d;n++){const r=(n+.5)/d,o=(i.x+(e-i.x)*r)*(this.width-1),a=(i.y+(t-i.y)*r)*(this.height-1),l=Math.max(1,Math.floor(o-3*h)),u=Math.min(this.width-2,Math.ceil(o+3*h)),s=Math.max(1,Math.floor(a-3*h)),c=Math.min(this.height-2,Math.ceil(a+3*h));for(let e=s;e<=c;e++)for(let t=l;t<=u;t++){const n=((t-o)*v+(e-a)*p)/h,r=((t-o)*g+(e-a)*x)/h,i=Math.exp(-n*n*.65-r*r*1.7),l=e*this.width+t;this.ink[l]=1-(1-this.ink[l])*Math.exp(-i*m);const u=1-r*r*.55,s=n*r*.7;this.u[l]=Math.max(-80,Math.min(80,this.u[l]+(v*u+g*s)*i*E)),this.v[l]=Math.max(-80,Math.min(80,this.v[l]+(p*u+x*s)*i*E))}}this.peak=1}read(e,t,n){const r=0|(t=Math.max(.5,Math.min(this.width-1.5,t))),i=0|(n=Math.max(.5,Math.min(this.height-1.5,n))),o=t-r,a=n-i,l=i*this.width+r;return(e[l]*(1-o)+e[l+1]*o)*(1-a)+(e[l+this.width]*(1-o)+e[l+this.width+1]*o)*a}sample(e,t){return this.read(this.signal,e*(this.width-1),t*(this.height-1))}displacement(e,t,n){n[0]=this.read(this.offsetX,e*(this.width-1),t*(this.height-1)),n[1]=this.read(this.offsetY,e*(this.width-1),t*(this.height-1))}step(e){if(!this.active||!Number.isFinite(e))return;let t=Math.max(0,Math.min(.05,e));const n=this.width,r=this.height;for(;t>1e-7;){const e=Math.min(1/60,t);t-=e;const i=Math.exp(-1.9*e),o=Math.exp(-3.2*e);for(let t=1;t<r-1;t++)for(let a=1;a<n-1;a++){const l=t*n+a,u=Math.max(.5,Math.min(n-1.5,a-this.u[l]*e)),s=Math.max(.5,Math.min(r-1.5,t-this.v[l]*e)),c=0|u,f=0|s,h=u-c,d=s-f,m=f*n+c,v=(1-h)*(1-d),p=h*(1-d),g=(1-h)*d,x=h*d;this.a[l]=(this.u[m]*v+this.u[m+1]*p+this.u[m+n]*g+this.u[m+n+1]*x)*i,this.b[l]=(this.v[m]*v+this.v[m+1]*p+this.v[m+n]*g+this.v[m+n+1]*x)*i,this.c[l]=(this.ink[m]*v+this.ink[m+1]*p+this.ink[m+n]*g+this.ink[m+n+1]*x)*o}[this.u,this.a]=[this.a,this.u],[this.v,this.b]=[this.b,this.v],[this.ink,this.c]=[this.c,this.ink];for(let e=1;e<r-1;e++)for(let t=1;t<n-1;t++){const r=e*n+t;this.curl[r]=.5*(this.v[r+1]-this.v[r-1]-this.u[r+n]+this.u[r-n])}for(let t=1;t<r-1;t++)for(let r=1;r<n-1;r++){const i=t*n+r,o=Math.abs(this.curl[i+1])-Math.abs(this.curl[i-1]),a=Math.abs(this.curl[i+n])-Math.abs(this.curl[i-n]),l=Math.hypot(o,a)+1e-4,u=this.curl[i]*e*10,s=Math.hypot(this.u[i],this.v[i]);this.u[i]+=a/l*u,this.v[i]-=o/l*u;const c=Math.min(1,s/(Math.hypot(this.u[i],this.v[i])+1e-6));this.u[i]*=c,this.v[i]*=c,this.divergence[i]=-.5*(this.u[i+1]-this.u[i-1]+this.v[i+n]-this.v[i-n])}this.pressure.fill(0);for(let e=0;e<4;e++){for(let e=1;e<r-1;e++)for(let t=1;t<n-1;t++){const r=e*n+t;this.pressureNext[r]=.25*(this.divergence[r]+this.pressure[r-1]+this.pressure[r+1]+this.pressure[r-n]+this.pressure[r+n])}[this.pressure,this.pressureNext]=[this.pressureNext,this.pressure]}let a=0;for(let t=1;t<r-1;t++)for(let r=1;r<n-1;r++){const i=t*n+r;this.u[i]=Math.max(-80,Math.min(80,this.u[i]-.5*(this.pressure[i+1]-this.pressure[i-1]))),this.v[i]=Math.max(-80,Math.min(80,this.v[i]-.5*(this.pressure[i+n]-this.pressure[i-n]))),this.driftX[i]+=(3.6*this.u[i]-58*this.offsetX[i]-12*this.driftX[i])*e,this.driftY[i]+=(3.6*this.v[i]-58*this.offsetY[i]-12*this.driftY[i])*e,this.offsetX[i]=Math.max(-2,Math.min(2,this.offsetX[i]+this.driftX[i]*e)),this.offsetY[i]=Math.max(-2,Math.min(2,this.offsetY[i]+this.driftY[i]*e)),this.signal[i]=1-Math.exp(.06*-Math.hypot(this.u[i],this.v[i])-.16*this.ink[i]),a=Math.max(a,this.signal[i])}this.peak=a}if(this.active)for(let e=0;e<this.ink.length;e++){const t=Math.round(65535*Math.min(1,this.signal[e]));this.pixels[4*e]=t>>>8,this.pixels[4*e+1]=255&t,this.pixels[4*e+2]=Math.round(128+63.5*this.offsetX[e]),this.pixels[4*e+3]=Math.round(128+63.5*this.offsetY[e])}else this.clear()}},f={radius:.13,strength:.5,trail:.45,follow:12},h={strength:.55,radius:.45},d={radius:.075,force:1,dissipation:1.6,refraction:.03,glow:.55,resolution:128,curl:24},m={charset:" .,:-=+*#%@",cellSize:12,cellAspect:1,cellFit:"pixel",font:'ui-monospace, "SF Mono", Menlo, Consolas, monospace',fontWeight:500,glyphScale:.8,mark:"glyph",dotScale:.9,color:"ink",ink:"#f3ba32",highlight:"auto",background:"transparent",brightness:0,contrast:1,gamma:1,invert:!1,levels:"auto",blend:"auto",saturation:1.1,shade:.5,backdrop:0,fit:"cover",focus:{x:.5,y:.5},vignette:0,drift:0,scene:"flow",scale:1,clear:!1,speed:1,hover:"fluid",fluid:d,lantern:f,trail:h,maxPixelRatio:2,respectReducedMotion:!0},v=(e,t,n,r)=>"number"==typeof e&&Number.isFinite(e)?Math.min(n,Math.max(t,e)):r,p=(e,t)=>"string"==typeof e&&/^#([\da-f]{3}|[\da-f]{6})$/i.test(e.trim())?e.trim().toLowerCase():t;function g(e){const t=Intl.Segmenter;return(t?Array.from(new t(void 0,{granularity:"grapheme"}).segment(e),e=>e.segment):Array.from(e)).filter(e=>"\n"!==e&&"\r"!==e&&"\t"!==e).slice(0,256)}function x(e={},t=m){const n="string"==typeof e.charset&&g(e.charset).length>=2?e.charset:t.charset,r=t.fluid||d,i=void 0===e.fluid?t.fluid:e.fluid,o=!1!==i&&(()=>{const e=!0!==i&&i?{...r,...i}:r;return{radius:v(e.radius,.005,.5,d.radius),force:v(e.force,0,8,d.force),dissipation:v(e.dissipation,.05,20,d.dissipation),refraction:v(e.refraction,0,.5,d.refraction),glow:v(e.glow,0,2,d.glow),resolution:Math.round(v(e.resolution,16,512,d.resolution)),curl:v(e.curl,0,80,d.curl)}})(),a="none"===e.scene||"flow"===e.scene||"orb"===e.scene||"drift"===e.scene?e.scene:t.scene,l=!!e.clear&&"object"==typeof e.clear&&("element"in e.clear||"nodeType"in e.clear),u=void 0===e.clear||l?t.clear:e.clear,s=!!u&&{x:v(u.x,-.5,1.5,.25),y:v(u.y,-.5,1.5,.3),width:v(u.width,0,2,.5),height:v(u.height,0,2,.4),feather:v(u.feather,.005,1,.12),shape:"rect"===u.shape?"rect":"ellipse"};return{charset:n,cellSize:v(e.cellSize,3,96,t.cellSize),cellAspect:v(e.cellAspect,.3,2,t.cellAspect),cellFit:"fill"===e.cellFit||"pixel"===e.cellFit?e.cellFit:t.cellFit,font:"string"==typeof e.font&&e.font.trim()?e.font:t.font,fontWeight:Math.round(v(e.fontWeight,100,900,t.fontWeight)),glyphScale:v(e.glyphScale,.3,1.6,t.glyphScale),mark:"dot"===e.mark||"glyph"===e.mark?e.mark:t.mark,dotScale:v(e.dotScale,.1,1.4,t.dotScale),color:"source"===e.color||"ink"===e.color?e.color:t.color,ink:p(e.ink,t.ink),highlight:"auto"===e.highlight?"auto":p(e.highlight,t.highlight),background:"transparent"===e.background?"transparent":p(e.background,t.background),brightness:v(e.brightness,-1,1,t.brightness),contrast:v(e.contrast,0,4,t.contrast),gamma:v(e.gamma,.2,5,t.gamma),invert:"boolean"==typeof e.invert?e.invert:t.invert,levels:"none"===e.levels||"auto"===e.levels?e.levels:t.levels,blend:"auto"===e.blend||"coarse"===e.blend||"on"===e.blend||"off"===e.blend?e.blend:t.blend,saturation:v(e.saturation,0,3,t.saturation),shade:v(e.shade,0,1,t.shade),backdrop:v(e.backdrop,0,1,t.backdrop),fit:"contain"===e.fit||"cover"===e.fit?e.fit:t.fit,focus:{x:v(e.focus?.x,0,1,t.focus.x),y:v(e.focus?.y,0,1,t.focus.y)},vignette:v(e.vignette,0,1,t.vignette),drift:v(e.drift,0,2,t.drift),scene:a,scale:v(e.scale,.2,6,t.scale),clear:s,speed:v(e.speed,0,5,t.speed),hover:"fluid"===e.hover||"lantern"===e.hover||"trail"===e.hover||"none"===e.hover?e.hover:t.hover,fluid:o,lantern:{radius:v(e.lantern?.radius,.02,.6,t.lantern.radius),strength:v(e.lantern?.strength,0,1.5,t.lantern.strength),trail:v(e.lantern?.trail,0,3,t.lantern.trail),follow:v(e.lantern?.follow,1,60,t.lantern.follow)},trail:{strength:v(e.trail?.strength,0,1,t.trail.strength),radius:v(e.trail?.radius,.1,1,t.trail.radius)},maxPixelRatio:v(e.maxPixelRatio,.5,4,t.maxPixelRatio),respectReducedMotion:"boolean"==typeof e.respectReducedMotion?e.respectReducedMotion:t.respectReducedMotion}}function E(e,t,n,r,i,o={x:.5,y:.5}){if(!(e>0&&t>0&&n>0&&r>0))return{scale:[1,1],offset:[0,0]};const a=e/t,l=n/r,u=l>a,s="cover"===i?u?[a/l,1]:[1,l/a]:u?[1,l/a]:[a/l,1];return{scale:s,offset:"cover"===i?[(1-s[0])*o.x,(1-s[1])*o.y]:[.5*(1-s[0]),.5*(1-s[1])]}}function T(e,t,n,r){const i=Math.max(2,Math.round(e*n)),o=Math.max(2,Math.round(i*t)),a=Math.min(16,Math.max(1,r)),l=Math.ceil(r/a);return{width:o,height:i,columns:a,rows:l,atlasWidth:a*o,atlasHeight:l*i}}function y(e){const t=e.replace("#",""),n=3===t.length?t.split("").map(e=>e+e).join(""):t,r=Number.parseInt(n,16);return Number.isFinite(r)&&6===n.length?[(r>>16&255)/255,(r>>8&255)/255,(255&r)/255]:[0,0,0]}function b(e){const t=new Uint32Array(256);let n=0;for(let r=0;r+3<e.length;r+=4)e[r+3]<8||(t[Math.round(.2126*e[r]+.7152*e[r+1]+.0722*e[r+2])]++,n++);if(!n)return[0,1];const r=e=>{let r=0;for(let i=0;i<256;i++)if(r+=t[i],r>=n*e)return i/255;return 1},i=r(.02),o=r(.98);return o-i<.08?[0,1]:[i,o]}var w=e=>"fluid"!==e.hover||e.fluid?e.hover:"none";function M(e,t,n=24,r=.12,i="ellipse"){return e.width>0&&e.height>0&&{x:(t.left-n-e.left)/e.width,y:(t.top-n-e.top)/e.height,width:(t.width+2*n)/e.width,height:(t.height+2*n)/e.height,feather:r,shape:i}}var R,F=/\.(mp4|webm|mov|m4v|ogv)(\?|#|$)/i,A=/swiftshader|llvmpipe|softpipe|software|basic render/i;function L(){if(R)return R;if("undefined"==typeof document||void 0===globalThis.WebGL2RenderingContext)return R="none";try{const e=document.createElement("canvas").getContext("webgl2");if(!e)return R="none";const t=e.getExtension("WEBGL_debug_renderer_info"),n=String(e.getParameter(t?t.UNMASKED_RENDERER_WEBGL:e.RENDERER)??"");return e.getExtension("WEBGL_lose_context")?.loseContext(),R=A.test(n)?"software":"gpu"}catch{return R="none"}}exports.DEFAULT_FIELD_FLUID=d,exports.DEFAULT_FIELD_LANTERN=f,exports.DEFAULT_FIELD_SETTINGS=m,exports.DEFAULT_FIELD_TRAIL=h,exports.FIELD_HOVERS=[{value:"fluid",label:"Fluid",description:"An ink-in-water wake that bends the image and swirls the characters."},{value:"lantern",label:"Lantern",description:"A soft light follows the pointer and lifts the characters it passes, without distortion."},{value:"trail",label:"Trail",description:"The Asciify Trail: in the wake, sparse characters fill in and dense ones open up, then settle. No distortion."},{value:"none",label:"Off",description:"The field stays still under the pointer."}],exports.activeFieldHover=w,exports.fieldCellLayout=T,exports.fieldClearFromRects=M,exports.fieldGlyphs=g,exports.fieldLevels=b,exports.fieldSourceRect=E,exports.glyphFieldTier=L,exports.isGlyphFieldSupported=function(e={}){const t=L();return"gpu"===t||"software"===t&&!!e.allowSoftware},exports.mountGlyphField=function(t,f={}){const h=e=>"undefined"!=typeof HTMLElement&&e instanceof HTMLElement,d=e=>{const t=e.clear;return h(t)?{element:{element:t},rest:{...e,clear:void 0}}:t&&"object"==typeof t&&h(t.element)?{element:t,rest:{...e,clear:void 0}}:{element:null,rest:e}};let m=d(f).element,v=x(d(f).rest);const p=f.onError,R=t.getContext("webgl2",{alpha:!0,antialias:!1,depth:!1,stencil:!1,premultipliedAlpha:!0,powerPreference:"high-performance"});if(!R)throw new Error("WebGL2 is not available for the glyph field.");const A=R;t.setAttribute("role","img"),t.setAttribute("aria-label",f.label??"ASCII artwork"),t.dataset.renderer="glyph-field";let L=!1;const _=A.getExtension("KHR_parallel_shader_compile");let S,D,k=null,C=null,U=null,P=null,B=[],I=[],X=null,N=!1,V=null,G=null;const H=[];let z=0,O=0,W=1,Y=0,q=T(v.cellSize,v.cellAspect,1,2),$=2,j=0,K=0,J=0,Q=null,Z=!1,ee=null,te=0,ne=0,re=0,ie=null,oe=0,ae=!0,le=0,ue=[0,1],se=-1/0,ce=0,fe=0,he=0,de=!0,me=!1,ve=!1,pe=!1,ge=!1,xe=!0,Ee=null,Te=null,ye=1/60,be=0,we=0,Me=[];const Re=new Float32Array(16),Fe=()=>{if(!m)return;const{element:e,padding:n=32,feather:r=.16,shape:i="rect"}=m,o=M(t.getBoundingClientRect(),e.getBoundingClientRect(),n,r,i),a=v.clear;JSON.stringify(a)!==JSON.stringify(o)&&(v={...v,clear:o},de=!0)},Ae={target:null,at:null,strength:0,trail:[]},Le=new Float32Array(36);let _e=null,Se=null,De=!1;const ke=()=>{if(!z||!O)return null;const e=z/O,t=Math.round(e>=1?128:128*e),n=Math.round(e>=1?128/e:128);return _e&&_e.width===t&&_e.height===n||(_e=new c(t,n),Se||(Se=Oe(A.LINEAR)),A.bindTexture(A.TEXTURE_2D,Se),A.texImage2D(A.TEXTURE_2D,0,A.RGBA8,t,n,0,A.RGBA,A.UNSIGNED_BYTE,_e.pixels),De=!0),_e};let Ce=0;const Ue="function"==typeof matchMedia?matchMedia("(prefers-reduced-motion: reduce)"):null,Pe=()=>v.respectReducedMotion&&!!Ue?.matches;let Be;const Ie=new Promise(e=>{Be=e});let Xe=!0;const Ne=e=>p?.(e instanceof Error?e:new Error(String(e))),Ve=(e,t)=>{const n=A.createShader(e);return H.push(n),A.shaderSource(n,t),A.compileShader(n),n},Ge=e=>{G??(G=Ve(A.VERTEX_SHADER,"#version 300 es\nvoid main(){vec2 p=vec2((gl_VertexID<<1)&2,gl_VertexID&2);gl_Position=vec4(p*2.-1.,0.,1.);}"));const t=A.createProgram(),n=Ve(A.FRAGMENT_SHADER,e);return A.attachShader(t,G),A.attachShader(t,n),A.linkProgram(t),{program:t,locations:null,fragment:n}},He=(e,t=!1)=>{if(e.locations)return!0;const{program:n,fragment:r}=e;if(!t&&_&&!A.getProgramParameter(n,_.COMPLETION_STATUS_KHR))return!1;if(!A.getProgramParameter(n,A.LINK_STATUS)){if(A.isContextLost())return!1;throw new Error(A.getShaderInfoLog(r)||A.getProgramInfoLog(n)||"Glyph field program failed to link.")}const i={};for(let e=A.getProgramParameter(n,A.ACTIVE_UNIFORMS)-1;e>=0;e--){const t=A.getActiveUniform(n,e).name.replace(/\[0\]$/,"");i[t]=A.getUniformLocation(n,t)}return e.locations=i,!0},ze=(e=!1)=>!!k&&!!C&&He(k,e)&&He(C,e),Oe=e=>{const t=A.createTexture();return A.bindTexture(A.TEXTURE_2D,t),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_MIN_FILTER,e),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_MAG_FILTER,e===A.LINEAR_MIPMAP_LINEAR?A.LINEAR:e),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_WRAP_S,A.CLAMP_TO_EDGE),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_WRAP_T,A.CLAMP_TO_EDGE),t},We=()=>{P&&(A.deleteTexture(P.ink),A.deleteTexture(P.under),A.deleteFramebuffer(P.buffer),P=null)},Ye=()=>function(e,t,n,r,i,o,a){if("fill"!==e||!(i>0&&o>0))return[a.width,a.height];const l=t*r,u=l*n;return[i/Math.max(1,Math.floor(i/u+1e-6)),o/Math.max(1,Math.floor(o/l+1e-6))]}(v.cellFit,v.cellSize,v.cellAspect,W,z,O,q),qe=()=>!!v.fluid&&"fluid"===w(v),$e=()=>{X?.release(),N=!1,B.forEach(e=>A.deleteTexture(e)),I.forEach(e=>A.deleteFramebuffer(e)),B=[],I=[]};function je(){U&&A.deleteProgram(U.program),U=Ge((t=>`#version 300 es\nprecision highp float;\nprecision highp sampler2D;\nuniform sampler2D uPrevious;\nuniform vec2 uSize;\nuniform float uAspect, uDt, uDecay, uEnergyDecay, uRadius, uSplat;\nuniform vec2 uFrom, uTo, uForce;\nout vec4 outColor;\n${e(t)}\nfloat segment(vec2 p,vec2 a,vec2 b){vec2 pa=p-a,ba=b-a;float h=clamp(dot(pa,ba)/max(dot(ba,ba),1e-8),0.,1.);return length(pa-ba*h);}\nvoid main(){\n vec2 uv=gl_FragCoord.xy/uSize;\n vec4 here=decodeFluid(texture(uPrevious,uv));\n vec4 state=decodeFluid(texture(uPrevious,uv-uDt*here.xy*vec2(1./uAspect,1.)));\n state.xy*=exp(-uDt*uDecay);\n state.z*=exp(-uDt*uEnergyDecay);\n if(uSplat>.5){\n vec2 scale=vec2(uAspect,1.);\n float d=segment(uv*scale,uFrom*scale,uTo*scale);\n float g=exp(-d*d/(uRadius*uRadius));\n state.xy+=uForce*g;\n state.z=min(1.,state.z+g*min(1.,length(uForce)*.5+.08));\n }\n float speed=length(state.xy);\n if(speed>5.)state.xy*=5./speed;\n outColor=encodeFluid(state);\n}`)(L)),X?.dispose(),X=L?null:function(e,t,c){const f={splat:t(n),curl:t(r),vorticity:t(i),divergence:t(o),fade:t(a),pressure:t(l),gradient:t(u),advect:t(s)},h=Object.values(f);let d=0,m=0,v=[],p=[],g=null,x=null;const E=t=>{const n=e.createTexture();e.bindTexture(e.TEXTURE_2D,n),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texImage2D(e.TEXTURE_2D,0,e.RGBA16F,d,m,0,e.RGBA,e.HALF_FLOAT,null);const r=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,n,0),e.checkFramebufferStatus(e.FRAMEBUFFER)!==e.FRAMEBUFFER_COMPLETE?(e.deleteFramebuffer(r),e.deleteTexture(n),null):(e.viewport(0,0,d,m),e.clearColor(0,0,0,1),e.clear(e.COLOR_BUFFER_BIT),{texture:n,buffer:r})},T=t=>{t&&(e.deleteTexture(t.texture),e.deleteFramebuffer(t.buffer))},y=()=>{[...v,...p,g,x].forEach(T),v=[],p=[],g=x=null},b=(t,n)=>{const r=t.locations;return e.useProgram(t.program),e.bindFramebuffer(e.FRAMEBUFFER,n.buffer),e.uniform2f(r.uTexel,1/d,1/m),r},w=(t,n,r,i)=>{e.activeTexture(e.TEXTURE0+r),e.bindTexture(e.TEXTURE_2D,i),e.uniform1i(t[n],r)},M=()=>e.drawArrays(e.TRIANGLES,0,3),R=e=>{const t=e[0];e[0]=e[1],e[1]=t};return{resize(t,n){y(),d=t,m=n;const r=[E(e.LINEAR),E(e.LINEAR),E(e.NEAREST),E(e.NEAREST),E(e.NEAREST),E(e.NEAREST)];return e.bindFramebuffer(e.FRAMEBUFFER,null),r.some(e=>!e)?(r.forEach(T),!1):(v=[r[0],r[1]],p=[r[2],r[3]],g=r[4],x=r[5],!0)},ready:()=>h.every(c),step(t,n){if(!v.length||!g||!x)return;let r;e.viewport(0,0,d,m),t&&(r=b(f.splat,v[1]),w(r,"uVelocity",0,v[0].texture),e.uniform2f(r.uFrom,t.from[0],t.from[1]),e.uniform2f(r.uTo,t.to[0],t.to[1]),e.uniform2f(r.uForce,t.force[0],t.force[1]),e.uniform1f(r.uAspect,n.aspect),e.uniform1f(r.uRadius,n.radius),M(),R(v)),n.curl>0&&(r=b(f.curl,x),w(r,"uVelocity",0,v[0].texture),M(),r=b(f.vorticity,v[1]),w(r,"uVelocity",0,v[0].texture),w(r,"uCurl",1,x.texture),e.uniform1f(r.uStrength,n.curl),e.uniform1f(r.uDt,n.dt),M(),R(v)),r=b(f.divergence,g),w(r,"uVelocity",0,v[0].texture),M(),r=b(f.fade,p[1]),w(r,"uSource",0,p[0].texture),e.uniform1f(r.uAmount,.8),M(),R(p);for(let e=0;e<20;e++)r=b(f.pressure,p[1]),w(r,"uPressure",0,p[0].texture),w(r,"uDivergence",1,g.texture),M(),R(p);r=b(f.gradient,v[1]),w(r,"uPressure",0,p[0].texture),w(r,"uVelocity",1,v[0].texture),M(),R(v),r=b(f.advect,v[1]),w(r,"uVelocity",0,v[0].texture),e.uniform1f(r.uDt,n.dt),e.uniform1f(r.uDissipation,n.dissipation),M(),R(v),e.bindFramebuffer(e.FRAMEBUFFER,null)},get velocity(){return v[0]?.texture??null},get size(){return[d,m]},release:y,dispose(){y(),h.forEach(({program:t})=>e.deleteProgram(t))}}}(A,Ge,e=>He(e))}const Ke=()=>{$e();const e=v.fluid;if(!(e&&qe()&&z&&O))return;U||je();const t=e.resolution,n=z/O;if(j=n>=1?t:Math.max(8,Math.round(t*n)),K=n>=1?Math.max(8,Math.round(t/n)):t,N=!!X&&X.resize(j,K),N)return void(J=0);const r=()=>{$e();for(let e=0;e<2;e++){const e=Oe(A.LINEAR);A.texImage2D(A.TEXTURE_2D,0,L?A.RGBA8:A.RGBA16F,j,K,0,A.RGBA,L?A.UNSIGNED_BYTE:A.HALF_FLOAT,null);const t=A.createFramebuffer();A.bindFramebuffer(A.FRAMEBUFFER,t),A.framebufferTexture2D(A.FRAMEBUFFER,A.COLOR_ATTACHMENT0,A.TEXTURE_2D,e,0),B.push(e),I.push(t)}return A.checkFramebufferStatus(A.FRAMEBUFFER)===A.FRAMEBUFFER_COMPLETE};if(!r()){if(L)throw new Error("The glyph field could not allocate its fluid buffers.");L=!0,Je(),je(),r()}for(const e of I)A.bindFramebuffer(A.FRAMEBUFFER,e),A.viewport(0,0,j,K),A.clearColor(L?.5:0,L?.5:0,0,1),A.clear(A.COLOR_BUFFER_BIT);A.bindFramebuffer(A.FRAMEBUFFER,null),J=0};function Je(){k&&A.deleteProgram(k.program),C&&A.deleteProgram(C.program),We(),k=Ge((t=>`#version 300 es\nprecision highp float;\nprecision highp sampler2D;\nuniform sampler2D uSource, uFluid;\nuniform vec2 uResolution, uCell;\nuniform float uCount, uBlend;\nconst float BAYER[16]=float[16](0.,8.,2.,10.,12.,4.,14.,6.,3.,11.,1.,9.,15.,7.,13.,5.);\nuniform vec4 uSourceMap;\nuniform int uScene;\nuniform vec3 uInk, uHighlight;\nuniform vec4 uBackground;\nuniform float uBrightness, uContrast, uGamma, uInvert, uVignette, uSourceColor;\nuniform float uRefraction, uGlow, uTime, uDrift, uFluidOn, uLod, uSaturation, uBackdrop, uShade, uHighlightAuto, uFluidMode;\nuniform vec2 uFluidTexel;\nuniform int uHoverMode;\nuniform vec3 uLight;\nuniform vec3 uTrail[12];\nuniform float uLightRadius, uLightGain, uClock, uFlicker, uTrailAmount;\nuniform sampler2D uTrailMap;\nuniform vec2 uLevels;\nuniform int uMark;\nuniform float uScale, uClearFeather, uClearShape;\nuniform vec4 uClear;\nuniform vec4 uPulse[4];\nlayout(location=0) out vec4 outInk;\nlayout(location=1) out vec4 outUnder;\n${e(t)}\nfloat hash(vec2 p){p=fract(p*vec2(123.34,456.21));p+=dot(p,p+45.32);return fract(p.x*p.y);}\nfloat noise(vec2 p){vec2 i=floor(p),f=fract(p),u=f*f*(3.-2.*f);\n return mix(mix(hash(i),hash(i+vec2(1,0)),u.x),mix(hash(i+vec2(0,1)),hash(i+vec2(1,1)),u.x),u.y);}\nfloat fbm(vec2 p){float v=0.,a=.5;for(int i=0;i<5;i++){v+=a*noise(p);p=p*2.03+vec2(1.7,9.2);a*=.5;}return v;}\nvec3 generated(vec2 uv,float aspect){\n vec2 p=(uv-.5)*vec2(aspect,1.)*uScale;\n if(uScene==1){\n float t=uTime*.08;\n vec2 q=vec2(fbm(p*1.6+t),fbm(p*1.6-t+3.1));\n return vec3(smoothstep(.28,.86,fbm(p*1.8+q*1.6+vec2(t*.6,-t*.4))));\n }\n if(uScene==2){\n float r=.36,d=length(p),a=uTime*.25;\n vec3 l=normalize(vec3(cos(a)*.8,.55,sin(a)*.6+.6));\n if(d<r){\n vec3 n=normalize(vec3(p.x,-p.y,sqrt(r*r-d*d)));\n float diffuse=max(dot(n,l),0.),rim=pow(1.-n.z,2.5);\n float lon=atan(n.x,n.z)+uTime*.35,lat=asin(clamp(n.y,-1.,1.));\n float bands=.5+.25*sin(lat*14.)+.25*sin(lon*6.);\n return vec3(clamp(diffuse*.85+rim*.5+bands*.12,0.,1.));\n }\n return vec3(exp(-pow((d-r)*9.,2.))*.35);\n }\n if(uScene==4){\n // Drift: a few broad lobes that wander slowly. Built for halftone, where large soft shapes read best.\n float t=uTime*.045;\n vec2 q=p*1.15;\n vec2 w=vec2(fbm(q*.7+vec2(t,-t*.7)),fbm(q*.7+vec2(4.3-t*.8,t+1.7)));\n float n=fbm(q+w*1.3+vec2(t*.4,t*.25));\n return vec3(smoothstep(.36,.74,n));\n }\n return vec3(0.);\n}\nvoid main(){\n vec2 cell=floor(gl_FragCoord.xy);\n vec2 uv=(cell+.5)*uCell/uResolution;\n float aspect=uResolution.x/uResolution.y;\n vec4 fluid=vec4(0.);\n // lift: signed tone change. The solver's flow brightens one side of each eddy and opens the other into gaps.\n float lift=0.,wake=0.,bend=1.,swirl=0.,speed=0.;\n if(uFluidOn>.5){\n vec4 raw=texture(uFluid,vec2(uv.x,1.-uv.y));\n if(uFluidMode>.5){\n vec2 v=raw.xy*uFluidTexel*vec2(aspect,1.);\n fluid=vec4(v,0.,1.);\n swirl=clamp(dot(v,vec2(.4,.65))*uGlow*.32,-.65,.65);\n speed=clamp(length(v)*uGlow*.055,0.,.38);\n bend=.4;\n } else {\n fluid=decodeFluid(raw);\n wake=clamp(fluid.z*uGlow,0.,1.);\n lift=wake*.55;\n }\n }\n vec2 drift=uDrift*.006*vec2(sin(uv.y*5.3+uTime*.6),cos(uv.x*4.1-uTime*.5));\n vec2 sampleAt=uv-vec2(fluid.x/aspect,-fluid.y)*uRefraction*bend+drift;\n vec3 rgb,glow=vec3(0.);\n if(uScene==0){\n vec2 s=sampleAt*uSourceMap.xy+uSourceMap.zw;\n bool inside=!(s.x<0.||s.y<0.||s.x>1.||s.y>1.);\n rgb=inside?textureLod(uSource,s,uLod).rgb:vec3(0.);\n if(uBackdrop>0.){\n vec2 b=(uv-vec2(fluid.x/aspect,-fluid.y)*uRefraction*bend*.5)*uSourceMap.xy+uSourceMap.zw;\n glow=(b.x<0.||b.y<0.||b.x>1.||b.y>1.)?vec3(0.):textureLod(uSource,b,uLod+3.).rgb*uBackdrop;\n }\n } else rgb=generated(sampleAt,aspect);\n float tone=dot(rgb,vec3(.2126,.7152,.0722));\n tone=clamp((tone-uLevels.x)/max(uLevels.y-uLevels.x,.01),0.,1.);\n tone=clamp((tone-.5)*uContrast+.5+uBrightness,0.,1.);\n tone=pow(tone,1./uGamma);\n if(uInvert>.5)tone=1.-tone;\n float flick=0.,trailFold=0.;\n if(uHoverMode==2){\n // Lantern: a soft light and its fading tail lift the characters they pass. Nothing moves the image.\n vec2 ap=vec2(aspect,1.),d=(uv-uLight.xy)*ap;\n float r2=uLightRadius*uLightRadius,glowL=uLight.z*exp(-dot(d,d)/r2);\n for(int i=0;i<12;i++){vec2 e=(uv-uTrail[i].xy)*ap;glowL+=uTrail[i].z*exp(-dot(e,e)/(r2*.55));}\n glowL=min(glowL,1.);\n float grain=fract(sin(dot(cell,vec2(12.9898,78.233)))*43758.5453);\n lift=glowL*uLightGain*(.7+.6*grain);\n wake=glowL*.4;\n // A few letters at the light's rim step up the ramp and back, as if being retyped.\n flick=uFlicker*step(.9,fract(grain*13.7+floor(uClock*7.+grain*5.)*.37))*glowL*(1.-glowL)*4.;\n }\n if(uHoverMode==3){\n // Trail: the studio's ink field, as a 16-bit density. Sparse marks fill in, dense marks open up.\n vec4 ink=texture(uTrailMap,uv);\n float density=(ink.r*65280.+ink.g*255.)/65535.*uTrailAmount;\n float t=clamp(density/.38,0.,1.);\n trailFold=t*t*(3.-2.*t);\n }\n if(uFluidMode>.5&&uHoverMode==1){\n // Dark ground: any motion lights the characters. Lit ground: the flow lights one side of each eddy and opens the other.\n // A little cell-to-cell grain keeps the lit area a shimmer of letters rather than a solid block.\n float grain=fract(sin(dot(cell,vec2(12.9898,78.233)))*43758.5453);\n lift=mix(abs(swirl)*.5+speed,swirl+speed*.35,smoothstep(.12,.55,tone))*(.65+.7*grain);\n wake=clamp(lift*1.6,0.,1.);\n }\n tone=clamp(tone+lift,0.,1.);\n tone+=(1.-2.*tone)*trailFold;\n // Pulses: rings sent by the interface (field.pulse()), e.g. on a save or a notification.\n for(int i=0;i<4;i++){\n if(uPulse[i].w<=0.)continue;\n float dist=length((uv-uPulse[i].xy)*vec2(aspect,1.)),front=uPulse[i].z*.95;\n float ring=exp(-pow((dist-front)/.1,2.))*uPulse[i].w*exp(-uPulse[i].z*.85);\n tone=clamp(tone+ring*.85,0.,1.);\n }\n tone*=1.-uVignette*smoothstep(.35,1.05,length((uv-.5)*vec2(min(aspect,1.8),1.)*2.));\n if(uClear.z>0.){\n // Clear zone: the field fades out around content so text above it stays readable.\n vec2 half_=uClear.zw*.5*vec2(aspect,1.),q=(uv-uClear.xy-uClear.zw*.5)*vec2(aspect,1.);\n float dz;\n if(uClearShape>.5){vec2 e=abs(q)-half_;dz=length(max(e,0.))+min(max(e.x,e.y),0.);}\n else dz=(length(q/max(half_,vec2(1e-4)))-1.)*min(half_.x,half_.y);\n tone*=smoothstep(0.,uClearFeather,dz);\n }\n // Blend: a shade between two characters takes the upper one in the share of cells a 4x4 Bayer pattern gives it.\n float level=tone*(uCount-1.),upper=fract(level)>=.5?1.:0.;\n if(uBlend>.5&&tone>.02&&tone<.98){\n ivec2 q=ivec2(mod(gl_FragCoord.xy,4.));\n upper=fract(level)>(BAYER[q.y*4+q.x]+.5)/16.?1.:0.;\n }\n float index=min(uCount-1.,floor(level)+upper+(flick>.5&&tone>.02?1.:0.));\n vec3 hue=rgb/max(max(rgb.r,rgb.g),max(rgb.b,.03));\n hue=mix(vec3(dot(hue,vec3(.2126,.7152,.0722))),hue,uSaturation);\n vec3 ink=mix(uInk*mix(1.,.3+.7*tone,uShade),clamp(hue*(.38+.62*tone),0.,1.),uSourceColor);\n vec3 lifted=uHighlightAuto>.5?ink/max(max(ink.r,ink.g),max(ink.b,.06)):uHighlight;\n ink=mix(ink,lifted,wake*.7);\n float underAlpha=max(uBackground.a,min(1.,max(glow.r,max(glow.g,glow.b))));\n vec3 under=min(uBackground.rgb*uBackground.a+glow,vec3(underAlpha));\n // Halftone keeps the tone for the dot size; glyphs keep their atlas index, exact in 8 bits.\n outInk=vec4(ink,uMark==1?(tone>.003?tone:0.):index/255.);\n outUnder=vec4(under,underAlpha);\n}`)(L)),C=Ge("#version 300 es\nprecision highp float;\nprecision highp sampler2D;\nuniform sampler2D uAtlas, uCells, uUnder;\nuniform vec2 uResolution, uCell, uPitch;\nuniform float uColumns, uDotScale;\nuniform int uMark;\nout vec4 outColor;\nvoid main(){\n vec2 frag=vec2(gl_FragCoord.x,uResolution.y-gl_FragCoord.y);\n // The pitch is the atlas cell, or a fractional one under cellFit 'fill', where each glyph sits centred in its stretched cell.\n vec2 cell=floor(frag/uPitch);\n vec4 ink=texelFetch(uCells,ivec2(cell),0),under=texelFetch(uUnder,ivec2(cell),0);\n vec2 local=frag-cell*uPitch;\n float coverage;\n if(uMark==1){\n // Halftone: dot area follows tone, so midtones read true; edges are antialiased to one device pixel.\n float r=sqrt(ink.a)*min(uPitch.x,uPitch.y)*.5*uDotScale;\n coverage=ink.a>.003?clamp(r-length(local-uPitch*.5)+.5,0.,1.):0.;\n } else {\n float index=floor(ink.a*255.+.5);\n ivec2 tile=ivec2(int(mod(index,uColumns)),int(floor(index/uColumns)));\n vec2 texel=floor(local-floor((uPitch-uCell)*.5));\n coverage=all(greaterThanEqual(texel,vec2(0.)))&&all(lessThan(texel,uCell))?texelFetch(uAtlas,tile*ivec2(uCell)+ivec2(texel),0).a:0.;\n }\n outColor=vec4(ink.rgb*coverage+under.rgb*(1.-coverage),coverage+under.a*(1.-coverage));\n}"),_||ze(!0)}const Qe=()=>`${v.fontWeight} ${Math.max(1,q.height*v.glyphScale)}px ${v.font}`,Ze=()=>{const e=g(v.charset);$=e.length,q=T(v.cellSize,v.cellAspect,W,$),Y=W;const t=document.createElement("canvas");t.width=q.atlasWidth,t.height=q.atlasHeight;const n=t.getContext("2d");n.fillStyle="#fff",n.textAlign="center",n.textBaseline="alphabetic",n.font=Qe();const r=n.measureText("M"),i=r.actualBoundingBoxAscent||q.height*v.glyphScale*.7,o=r.actualBoundingBoxDescent||0,a=(q.height+i-o)/2;e.forEach((e,t)=>{const r=t%q.columns*q.width+q.width/2,i=Math.floor(t/q.columns)*q.height+a,o=n.measureText(e).width;n.save(),n.beginPath(),n.rect(r-q.width/2,i-a,q.width,q.height),n.clip(),n.translate(r,i),o>.96*q.width&&n.scale(.96*q.width/o,1),n.fillText(e,0,0),n.restore()}),A.bindTexture(A.TEXTURE_2D,S),A.pixelStorei(A.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),A.texImage2D(A.TEXTURE_2D,0,A.RGBA8,A.RGBA,A.UNSIGNED_BYTE,t),t.width=t.height=1,de=!0},et="undefined"==typeof document?void 0:document.fonts,tt=()=>{if(!et?.load)return;const e=Qe();et.load(e,g(v.charset).join("")).then(()=>{me||ve||Qe()!==e||(Ze(),yt())},()=>{})},nt=e=>e.trim().replace(/^["']|["']$/g,"").toLowerCase(),rt=e=>{const t=e.fontfaces??[],n=v.font.split(",").map(nt);t.some(e=>n.includes(nt(e.family)))&&tt()},it=()=>{if(ue=[0,1],Q&&"none"!==v.levels)try{const e=document.createElement("canvas");e.width=e.height=64;const t=e.getContext("2d",{willReadFrequently:!0});Q===ie&&(t.imageSmoothingQuality="medium"),t.drawImage(Q,0,0,64,64),ue=b(t.getImageData(0,0,64,64).data)}catch{ue=[0,1]}},ot=()=>{if(!Q)return;const e=performance.now();Q instanceof HTMLVideoElement&&!(e-se>1500)||(it(),se=e),A.bindTexture(A.TEXTURE_2D,D),A.pixelStorei(A.UNPACK_FLIP_Y_WEBGL,!1),A.pixelStorei(A.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);try{A.texImage2D(A.TEXTURE_2D,0,A.RGBA8,A.RGBA,A.UNSIGNED_BYTE,Q),A.generateMipmap(A.TEXTURE_2D)}catch(e){Ne(e)}},at=()=>{L=!A.getExtension("EXT_color_buffer_float")&&!A.getExtension("EXT_color_buffer_half_float"),Je(),V=A.createVertexArray(),S=Oe(A.NEAREST),D=Oe(A.LINEAR_MIPMAP_LINEAR),A.bindTexture(A.TEXTURE_2D,D),A.texImage2D(A.TEXTURE_2D,0,A.RGBA8,1,1,0,A.RGBA,A.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),A.generateMipmap(A.TEXTURE_2D),z=O=0,Y=0,lt(),tt(),Q&&ot()};function lt(){const e=t.clientWidth||t.clientHeight?{width:t.clientWidth,height:t.clientHeight}:t.getBoundingClientRect(),n=Math.min(globalThis.devicePixelRatio||1,v.maxPixelRatio),r=Math.max(1,Math.round(e.width*n)),i=Math.max(1,Math.round(e.height*n));if(r===z&&i===O&&n===W)return!1;const o=!z||Math.abs(r/i-z/O)>.01;return W=n,z=r,O=i,t.width=z,t.height=O,Y!==W&&Ze(),(o||qe()&&!B.length&&!N)&&Ke(),de=!0,!0}let ut=null,st=[0,0,0],ct=[1,1,1],ft=[0,0,0,0],ht=E(1,1,1,1,"cover"),dt=null,mt=0,vt=0,pt=0,gt=0;const xt=()=>{ut!==v&&(ut=v,st=y(v.ink),ct=y("auto"===v.highlight?"#ffffff":v.highlight),ft="transparent"===v.background?[0,0,0,0]:[...y(v.background),1]),dt===v&&mt===z&&vt===O&&pt===te&&gt===ne||(dt=v,mt=z,vt=O,pt=te,gt=ne,ht=E(z,O,te||1,ne||1,v.fit,v.focus));const e=v.fluid,t=Q&&oe?q.height/O*oe*ht.scale[1]:1,n=(()=>{const[e,t]=Ye(),n=Math.ceil(z/e-1e-4),r=Math.ceil(O/t-1e-4);if(P&&P.columns===n&&P.rows===r)return P;We();const i=()=>{const e=Oe(A.NEAREST);return A.texStorage2D(A.TEXTURE_2D,1,L?A.RGBA8:A.RGBA16F,n,r),e},o=i(),a=i(),l=A.createFramebuffer();return A.bindFramebuffer(A.FRAMEBUFFER,l),A.framebufferTexture2D(A.FRAMEBUFFER,A.COLOR_ATTACHMENT0,A.TEXTURE_2D,o,0),A.framebufferTexture2D(A.FRAMEBUFFER,A.COLOR_ATTACHMENT1,A.TEXTURE_2D,a,0),A.drawBuffers([A.COLOR_ATTACHMENT0,A.COLOR_ATTACHMENT1]),P={ink:o,under:a,buffer:l,columns:n,rows:r}})(),r=k.locations,i=C.locations,o=w(v),a=!Pe();A.bindFramebuffer(A.FRAMEBUFFER,n.buffer),A.viewport(0,0,n.columns,n.rows),A.useProgram(k.program),A.activeTexture(A.TEXTURE0),A.bindTexture(A.TEXTURE_2D,D),A.uniform1i(r.uSource,0),A.activeTexture(A.TEXTURE2),A.bindTexture(A.TEXTURE_2D,(N?X?.velocity:B[J])??D),A.uniform1i(r.uFluid,2),A.activeTexture(A.TEXTURE3),A.bindTexture(A.TEXTURE_2D,Se??D),A.uniform1i(r.uTrailMap,3),A.uniform1f(r.uFluidMode,N?1:0),A.uniform1i(r.uHoverMode,"fluid"===o?1:"lantern"===o?2:"trail"===o&&De?3:0),A.uniform1f(r.uTrailAmount,v.trail.strength),A.uniform3f(r.uLight,Ae.at?.[0]??-1,Ae.at?.[1]??-1,"lantern"===o?Ae.strength:0),A.uniform3fv(r.uTrail,Le),A.uniform1f(r.uLightRadius,v.lantern.radius),A.uniform1f(r.uLightGain,v.lantern.strength),A.uniform1f(r.uClock,performance.now()/1e3),A.uniform1f(r.uFlicker,a?1:0),A.uniform2f(r.uFluidTexel,1/Math.max(1,j),1/Math.max(1,K)),A.uniform2f(r.uResolution,z,O);const[l,u]=Ye();A.uniform2f(r.uCell,l,u),A.uniform1f(r.uCount,$),A.uniform1f(r.uBlend,"on"===v.blend||$<=9&&("coarse"===v.blend||"auto"===v.blend&&Z)?1:0),A.uniform4f(r.uSourceMap,ht.scale[0],ht.scale[1],ht.offset[0],ht.offset[1]),A.uniform1i(r.uScene,Q?0:"flow"===v.scene?1:"orb"===v.scene?2:"drift"===v.scene?4:3),A.uniform1i(r.uMark,"dot"===v.mark?1:0),A.uniform1f(r.uScale,v.scale);const s=v.clear;A.uniform4f(r.uClear,s?s.x:0,s?s.y:0,s?s.width:0,s?s.height:0),A.uniform1f(r.uClearFeather,s?s.feather:.1),A.uniform1f(r.uClearShape,s&&"rect"===s.shape?1:0);const c=performance.now();Re.fill(0);for(let e=0;e<Me.length;e++){const t=Me[e],n=4*e;Re[n]=t.x,Re[n+1]=t.y,Re[n+2]=(c-t.born)/1e3,Re[n+3]=t.strength}A.uniform4fv(r.uPulse,Re),A.uniform3fv(r.uInk,st),A.uniform3fv(r.uHighlight,ct),A.uniform1f(r.uHighlightAuto,"auto"===v.highlight?1:0),A.uniform4fv(r.uBackground,ft),A.uniform1f(r.uBrightness,v.brightness),A.uniform1f(r.uContrast,v.contrast),A.uniform1f(r.uGamma,v.gamma),A.uniform1f(r.uInvert,v.invert?1:0),A.uniform1f(r.uVignette,v.vignette),A.uniform1f(r.uSourceColor,"source"===v.color?1:0),A.uniform1f(r.uRefraction,e?e.refraction*(a?1:.25):0),A.uniform1f(r.uGlow,e?e.glow:0),A.uniform1f(r.uTime,he),A.uniform1f(r.uDrift,a?v.drift:0),A.uniform1f(r.uFluidOn,e&&"fluid"===o&&(B.length||N)?1:0),A.uniform1f(r.uLod,Math.max(0,Math.log2(Math.max(1,t))-.5)),A.uniform1f(r.uSaturation,v.saturation),A.uniform1f(r.uShade,v.shade),A.uniform1f(r.uBackdrop,Q?v.backdrop:0),A.uniform2f(r.uLevels,Q&&"auto"===v.levels?ue[0]:0,Q&&"auto"===v.levels?ue[1]:1),A.bindVertexArray(V),A.drawArrays(A.TRIANGLES,0,3),A.bindFramebuffer(A.FRAMEBUFFER,null),A.viewport(0,0,z,O),A.useProgram(C.program),A.activeTexture(A.TEXTURE1),A.bindTexture(A.TEXTURE_2D,S),A.uniform1i(i.uAtlas,1),A.activeTexture(A.TEXTURE4),A.bindTexture(A.TEXTURE_2D,n.ink),A.uniform1i(i.uCells,4),A.activeTexture(A.TEXTURE5),A.bindTexture(A.TEXTURE_2D,n.under),A.uniform1i(i.uUnder,5),A.uniform2f(i.uResolution,z,O),A.uniform2f(i.uCell,q.width,q.height),A.uniform2f(i.uPitch,l,u),A.uniform1f(i.uColumns,q.columns),A.uniform1f(i.uDotScale,v.dotScale),A.uniform1i(i.uMark,"dot"===v.mark?1:0),A.drawArrays(A.TRIANGLES,0,3)},Et=()=>!me&&!ve&&!pe&&(xe||Xe)&&!("undefined"!=typeof document&&document.hidden),Tt=e=>{if(ce=0,!Et())return;const t=(e-fe)/1e3,n=Math.min(1/30,Math.max(1/480,t));fe=e,ye=.9*ye+.1*Math.min(t,.25),be=ye>1/24?be+1:0;try{be>45&&we<2&&(be=0,we++,1===we&&W>1?(v={...v,maxPixelRatio:1},lt()):we=2);const t=ze(),r=!(ge||we>=2&&!(Q instanceof HTMLVideoElement)||(!(Q instanceof HTMLVideoElement)||Q.paused||Q.ended)&&(Pe()||!(!Q&&"none"!==v.scene||v.drift>0)));r&&(he+=n*v.speed),Q instanceof HTMLVideoElement&&Q.readyState>=2&&ae&&(ae=!("requestVideoFrameCallback"in Q),ot(),de=!0);const i=w(v);let o="fluid"===i&&(null!==Te||e<Ce);if(o?((e,t)=>{const n=v.fluid;if(!n||!I.length&&!N)return;if(N?!X?.ready():!U||!He(U))return;const r=z/O,i=Te;if(Te=null,N&&X){const o=5200*n.force*(Pe()?.35:1);return i&&(Ce=t+1e3*Math.min(9,6/Math.max(.3,n.dissipation))),void X.step(i?{from:i.from,to:i.to,force:[(i.to[0]-i.from[0])*o,(i.to[1]-i.from[1])*o]}:null,{dt:Math.min(e,1/60),radius:1.1*n.radius,curl:n.curl,dissipation:n.dissipation,aspect:r})}let o=0,a=0;if(i){const e=(Pe()?1:3)*n.force;o=(i.to[0]-i.from[0])*r*e*4,a=(i.to[1]-i.from[1])*e*4,Ce=t+7/Math.min(n.dissipation,1.1*n.dissipation)*1e3}const l=U.locations;A.bindFramebuffer(A.FRAMEBUFFER,I[1-J]),A.viewport(0,0,j,K),A.useProgram(U.program),A.activeTexture(A.TEXTURE0),A.bindTexture(A.TEXTURE_2D,B[J]),A.uniform1i(l.uPrevious,0),A.uniform2f(l.uSize,j,K),A.uniform1f(l.uAspect,r),A.uniform1f(l.uDt,e),A.uniform1f(l.uDecay,n.dissipation),A.uniform1f(l.uEnergyDecay,1.1*n.dissipation),A.uniform1f(l.uRadius,n.radius),A.uniform1f(l.uSplat,i?1:0),A.uniform2f(l.uFrom,i?.from[0]??0,i?.from[1]??0),A.uniform2f(l.uTo,i?.to[0]??0,i?.to[1]??0),A.uniform2f(l.uForce,o,a),A.drawArrays(A.TRIANGLES,0,3),J=1-J})(n,e):Te=null,"lantern"===i&&(o=((e,t)=>{const n=v.lantern,r=Ae.target;if(r){const i=Ae.at;if(i)if(Pe())i[0]=r[0],i[1]=r[1];else{const t=1-Math.exp(-n.follow*e);i[0]+=(r[0]-i[0])*t,i[1]+=(r[1]-i[1])*t}else Ae.at=[r[0],r[1]];const o=Ae.at,a=Ae.trail[Ae.trail.length-1];n.trail>0&&(!a||t-a.born>28&&Math.hypot(o[0]-a.x,o[1]-a.y)>.004)&&(Ae.trail.push({x:o[0],y:o[1],born:t}),Ae.trail.length>12&&Ae.trail.shift())}Ae.strength+=((r?1:0)-Ae.strength)*(1-Math.exp(-e*(r?9:5)));const i=Ae.trail;for(let e=i.length-1;e>=0;e--)n.trail>0&&t-i[e].born<4e3*n.trail||i.splice(e,1);Le.fill(0);for(let e=0;e<i.length;e++){const r=i[e];Le[3*e]=r.x,Le[3*e+1]=r.y,Le[3*e+2]=.55*Math.exp(-(t-r.born)/1e3/Math.max(.01,n.trail))}return Ae.strength>.003||i.length>0})(n,e)||o),"trail"===i){const e=!!_e?.active;o=(e=>{const t=ke();return!(!t||!t.active||(t.step(e),A.bindTexture(A.TEXTURE_2D,Se),A.texSubImage2D(A.TEXTURE_2D,0,0,0,t.width,t.height,A.RGBA,A.UNSIGNED_BYTE,t.pixels),De=!0,0))})(n)||o,e&&!_e?.active&&(de=!0)}if(Me.length){for(let t=Me.length-1;t>=0;t--)e-Me[t].born>=2400&&Me.splice(t,1);o=!0,Me.length||(de=!0)}t&&(r||o||de)&&(xt(),de=!1,!Xe||re&&!Q||(Xe=!1,Be())),(r||o||Te||!t)&&(ce=requestAnimationFrame(Tt))}catch(e){pe=!0,Ne(e)}};function yt(){!ce&&Et()&&(fe=performance.now(),ce=requestAnimationFrame(Tt))}const bt=(e,n)=>{const r=t.getBoundingClientRect();if(!r.width||!r.height)return null;const i=(e-r.left)/r.width,o=(n-r.top)/r.height;return i<-.05||i>1.05||o<-.05||o>1.05?null:[i,1-o]},wt=e=>{const t=w(v);if("none"===t||ge)return Ee=null,void(Ae.target=null);if("lantern"===t)return Ae.target=e?[e[0],1-e[1]]:null,Ee=null,void yt();if("trail"===t){const t=ke();if(!t)return;return e?t.move(e[0],1-e[1],v.trail.radius,performance.now()):t.leave(),Ee=null,void yt()}e?(Ee&&(Te=Te?{from:Te.from,to:e}:{from:Ee,to:e}),Ee=e,yt()):Ee=null},Mt=e=>wt(bt(e.clientX,e.clientY)),Rt=()=>{Ee=null,_e?.leave(),Ae.target&&(Ae.target=null,yt())},Ft=f.interactionTarget??window;Ft.addEventListener("pointermove",Mt,{passive:!0}),Ft.addEventListener("pointerdown",Mt,{passive:!0}),document.addEventListener("pointerleave",Rt),Ft!==window&&Ft.addEventListener("pointerleave",Rt);const At="function"==typeof ResizeObserver?new ResizeObserver(()=>{const e=lt();Fe(),(e||de)&&yt()}):null;At?.observe(t),m&&At?.observe(m.element);const Lt="function"==typeof IntersectionObserver?new IntersectionObserver(([e])=>{xe=e.isIntersecting,xe&&(de=!0,yt())},{rootMargin:"120px"}):null;Lt?.observe(t);const _t=()=>{document.hidden||(de=!0,yt())};document.addEventListener("visibilitychange",_t);const St=()=>{de=!0,yt()};Ue?.addEventListener?.("change",St),et?.addEventListener?.("loadingdone",rt);const Dt=e=>{e.preventDefault(),ve=!0,ce&&cancelAnimationFrame(ce),ce=0},kt=()=>{ve=!1,H.length=0,G=null,k=C=U=null,P=null,B=[],I=[],X=null,N=!1,Se=null,_e=null,De=!1;try{at(),de=!0,yt()}catch(e){Ne(e)}};t.addEventListener("webglcontextlost",Dt),t.addEventListener("webglcontextrestored",kt);const Ct=()=>{ee&&(ee.pause(),ee.removeAttribute("src"),ee.load(),ee=null),le&&Q instanceof HTMLVideoElement&&"cancelVideoFrameCallback"in Q&&Q.cancelVideoFrameCallback(le),le=0},Ut=()=>{ie?.close(),ie=null},Pt=async e=>{const t=await createImageBitmap(e,{premultiplyAlpha:"none"}),n=[t.width,t.height],r=function(e,t,n,r,i,o,a=8){if(!(n>=16&&r>=16&&e>0&&t>0&&i>0))return 1;const l=a/i/("cover"===o?Math.min(e/n,t/r):Math.max(e/n,t/r));return l>.5?1:2**-Math.floor(Math.log2(1/l))}(t.width,t.height,z,O,q.height,v.fit);if(1===r)return{element:t,owned:!0,natural:n};try{return{element:await createImageBitmap(t,{resizeWidth:Math.max(1,Math.round(t.width*r)),resizeHeight:Math.max(1,Math.round(t.height*r)),resizeQuality:"medium",premultiplyAlpha:"none"}),owned:!0,natural:n}}finally{t.close()}},Bt=e=>new Promise((t,n)=>{const r=new Image;r.crossOrigin="anonymous",r.decoding="async",r.onload=()=>t({element:r,owned:!1}),r.onerror=()=>n(new Error("The glyph field could not load this image.")),r.src=e}),It=async e=>{const t=++re;if(!e)return Ct(),Ut(),Q=null,te=ne=oe=0,Z=!1,de=!0,void yt();try{const n=await(async e=>{if("string"!=typeof e)return e instanceof HTMLImageElement&&!e.complete?e.decode().then(()=>({element:e,owned:!1})):e instanceof HTMLVideoElement&&e.readyState<2?new Promise((t,n)=>{e.addEventListener("loadeddata",()=>t({element:e,owned:!1}),{once:!0}),e.addEventListener("error",()=>n(new Error("The glyph field could not load this video.")),{once:!0})}):{element:e,owned:!1};if(F.test(e))return new Promise((t,n)=>{const r=document.createElement("video");r.crossOrigin="anonymous",r.muted=!0,r.loop=!0,r.playsInline=!0,r.preload="auto",r.addEventListener("loadeddata",()=>{r.play().catch(()=>{}),t({element:r,owned:!0})},{once:!0}),r.addEventListener("error",()=>n(new Error("The glyph field could not load this video.")),{once:!0}),r.src=e});if("function"!=typeof createImageBitmap||"function"!=typeof fetch)return Bt(e);let t;try{t=await(await fetch(e).then(e=>{if(!e.ok)throw new Error("The glyph field could not load this image.");return e})).blob()}catch(t){if(t instanceof Error&&t.message.startsWith("The glyph field"))throw t;return Bt(e)}if(!/svg/i.test(t.type))try{return await Pt(t)}catch{}const n=URL.createObjectURL(t);try{return await Bt(n)}finally{URL.revokeObjectURL(n)}})(e),{element:r,owned:i}=n;if(me||t!==re)return void(i&&r instanceof HTMLVideoElement?(r.pause(),r.removeAttribute("src"),r.load()):i&&r.close());Ct(),Ut(),ee=i&&r instanceof HTMLVideoElement?r:null,!i||r instanceof HTMLVideoElement||(ie=r),Q=r,Z="string"==typeof e||e instanceof HTMLImageElement||e instanceof HTMLVideoElement,oe=r instanceof HTMLVideoElement?r.videoHeight:r instanceof HTMLImageElement?r.naturalHeight:r.height,te=n.natural?.[0]??(r instanceof HTMLVideoElement?r.videoWidth:r instanceof HTMLImageElement?r.naturalWidth:r.width),ne=n.natural?.[1]??oe,ae=!0,r instanceof HTMLVideoElement&&(e=>{const t=e;if(!t.requestVideoFrameCallback)return;const n=()=>{me||Q!==e||(ae=!0,yt(),le=t.requestVideoFrameCallback(n))};le=t.requestVideoFrameCallback(n)})(r),ve||ot(),de=!0,yt()}catch(e){Xe&&t===re&&(Xe=!1,Be()),Ne(e)}};at(),Fe();const Xt=f.source??null;return Xt?(re=1,It(Xt)):yt(),{canvas:t,ready:Ie,get settings(){return v},update(e){const n=v,{element:r,rest:i}=d(e);"clear"in e&&(m&&m.element!==r?.element&&At?.unobserve(m.element),m=r,r&&At?.observe(r.element)),v=x(r?{...i,clear:v.clear}:i,v),Fe(),e.label&&t.setAttribute("aria-label",e.label),v.maxPixelRatio!==n.maxPixelRatio&&lt(),v.charset===n.charset&&v.cellSize===n.cellSize&&v.cellAspect===n.cellAspect&&v.font===n.font&&v.fontWeight===n.fontWeight&&v.glyphScale===n.glyphScale||(Ze(),tt()),v.levels!==n.levels&&it();((!!n.fluid&&"fluid"===w(n))!==qe()||v.fluid&&n.fluid&&v.fluid.resolution!==n.fluid.resolution)&&Ke(),"source"in e&&It(e.source??null),de=!0,yt()},setSource:It,pointer(e,n=0){if(null===e)return void wt(null);const r=t.getBoundingClientRect();wt(bt(r.left+e,r.top+n))},redraw(){if(!(me||ve||pe)&&z)try{ze(!0)&&xt()}catch(e){pe=!0,Ne(e)}},pulse(e={}){if(me||Pe())return;const n=t.getBoundingClientRect();if(!n.width||!n.height)return;let r=e.x??n.width/2,i=e.y??n.height/2;if(e.element){const t=e.element.getBoundingClientRect();r=t.left+t.width/2-n.left,i=t.top+t.height/2-n.top}const o=Math.max(0,Math.min(2,e.strength??1));Me=[...Me,{x:r/n.width,y:i/n.height,born:performance.now(),strength:o}].slice(-4),yt()},play(){ge=!1,Q instanceof HTMLVideoElement&&Q.play().catch(()=>{}),de=!0,yt()},pause(){ge=!0,Q instanceof HTMLVideoElement&&Q.pause()},resize(){lt()&&yt()},destroy(){if(!me&&(me=!0,ce&&cancelAnimationFrame(ce),Ft.removeEventListener("pointermove",Mt),Ft.removeEventListener("pointerdown",Mt),document.removeEventListener("pointerleave",Rt),Ft.removeEventListener("pointerleave",Rt),document.removeEventListener("visibilitychange",_t),Ue?.removeEventListener?.("change",St),et?.removeEventListener?.("loadingdone",rt),t.removeEventListener("webglcontextlost",Dt),t.removeEventListener("webglcontextrestored",kt),At?.disconnect(),Lt?.disconnect(),Ct(),Ut(),Q=null,!ve)){$e(),We(),A.deleteTexture(S),A.deleteTexture(D);for(const e of[k,C,U])e&&A.deleteProgram(e.program);X?.dispose(),Se&&A.deleteTexture(Se),H.forEach(e=>A.deleteShader(e)),V&&A.deleteVertexArray(V)}}}},exports.normalizeFieldSettings=x;//# sourceMappingURL=field.cjs.map
1
+ "use strict";var e=e=>e?"\nconst float VSCALE=6.;\nvec4 decodeFluid(vec4 t){return vec4((t.xy*2.-1.)*VSCALE,t.z,t.w);}\nvec4 encodeFluid(vec4 v){return vec4(clamp(v.xy/VSCALE*.5+.5,0.,1.),clamp(v.z,0.,1.),1.);}":"\nvec4 decodeFluid(vec4 t){return t;}\nvec4 encodeFluid(vec4 v){return vec4(v.xyz,1.);}",t="#version 300 es\nprecision highp float;\nprecision highp sampler2D;\nuniform vec2 uTexel;\nout vec4 outColor;\nvec2 here(){return gl_FragCoord.xy*uTexel;}\n",n=t+"\nuniform sampler2D uVelocity;\nuniform vec2 uFrom, uTo, uForce;\nuniform float uAspect, uRadius;\nfloat segment(vec2 p,vec2 a,vec2 b){vec2 pa=p-a,ba=b-a;float h=clamp(dot(pa,ba)/max(dot(ba,ba),1e-8),0.,1.);return length(pa-ba*h);}\nvoid main(){\n vec2 uv=here(),scale=vec2(uAspect,1.);\n float d=segment(uv*scale,uFrom*scale,uTo*scale);\n outColor=vec4(texture(uVelocity,uv).xy+uForce*exp(-d*d/(uRadius*uRadius)),0.,1.);\n}",r=t+"\nuniform sampler2D uVelocity;\nvoid main(){\n vec2 uv=here();\n float l=texture(uVelocity,uv-vec2(uTexel.x,0.)).y,r=texture(uVelocity,uv+vec2(uTexel.x,0.)).y;\n float t=texture(uVelocity,uv+vec2(0.,uTexel.y)).x,b=texture(uVelocity,uv-vec2(0.,uTexel.y)).x;\n outColor=vec4(.5*(r-l-t+b),0.,0.,1.);\n}",i=t+"\nuniform sampler2D uVelocity, uCurl;\nuniform float uStrength, uDt;\nvoid main(){\n vec2 uv=here();\n float l=texture(uCurl,uv-vec2(uTexel.x,0.)).x,r=texture(uCurl,uv+vec2(uTexel.x,0.)).x;\n float t=texture(uCurl,uv+vec2(0.,uTexel.y)).x,b=texture(uCurl,uv-vec2(0.,uTexel.y)).x,c=texture(uCurl,uv).x;\n vec2 force=.5*vec2(abs(t)-abs(b),abs(r)-abs(l));\n force=force/(length(force)+1e-4)*uStrength*c;\n force.y=-force.y;\n outColor=vec4(clamp(texture(uVelocity,uv).xy+force*uDt,-1000.,1000.),0.,1.);\n}",o=t+"\nuniform sampler2D uVelocity;\nvoid main(){\n vec2 uv=here(),c=texture(uVelocity,uv).xy;\n float l=texture(uVelocity,uv-vec2(uTexel.x,0.)).x,r=texture(uVelocity,uv+vec2(uTexel.x,0.)).x;\n float t=texture(uVelocity,uv+vec2(0.,uTexel.y)).y,b=texture(uVelocity,uv-vec2(0.,uTexel.y)).y;\n if(uv.x-uTexel.x<0.)l=-c.x;\n if(uv.x+uTexel.x>1.)r=-c.x;\n if(uv.y+uTexel.y>1.)t=-c.y;\n if(uv.y-uTexel.y<0.)b=-c.y;\n outColor=vec4(.5*(r-l+t-b),0.,0.,1.);\n}",a=t+"\nuniform sampler2D uSource;\nuniform float uAmount;\nvoid main(){outColor=vec4(texture(uSource,here()).x*uAmount,0.,0.,1.);}",l=t+"\nuniform sampler2D uPressure, uDivergence;\nvoid main(){\n vec2 uv=here();\n float l=texture(uPressure,uv-vec2(uTexel.x,0.)).x,r=texture(uPressure,uv+vec2(uTexel.x,0.)).x;\n float t=texture(uPressure,uv+vec2(0.,uTexel.y)).x,b=texture(uPressure,uv-vec2(0.,uTexel.y)).x;\n outColor=vec4((l+r+b+t-texture(uDivergence,uv).x)*.25,0.,0.,1.);\n}",u=t+"\nuniform sampler2D uPressure, uVelocity;\nvoid main(){\n vec2 uv=here();\n float l=texture(uPressure,uv-vec2(uTexel.x,0.)).x,r=texture(uPressure,uv+vec2(uTexel.x,0.)).x;\n float t=texture(uPressure,uv+vec2(0.,uTexel.y)).x,b=texture(uPressure,uv-vec2(0.,uTexel.y)).x;\n outColor=vec4(texture(uVelocity,uv).xy-vec2(r-l,t-b),0.,1.);\n}",s=t+"\nuniform sampler2D uVelocity;\nuniform float uDt, uDissipation;\nvoid main(){\n vec2 uv=here();\n vec2 back=uv-uDt*texture(uVelocity,uv).xy*uTexel;\n outColor=vec4(texture(uVelocity,back).xy/(1.+uDissipation*uDt),0.,1.);\n}";var c=class{constructor(e,t){this.previous=null,this.peak=0,this.width=e,this.height=t;const n=e*t;this.pixels=new Uint8Array(4*n),this.signal=new Float32Array(n),this.offsetX=new Float32Array(n),this.offsetY=new Float32Array(n),this.driftX=new Float32Array(n),this.driftY=new Float32Array(n),this.u=new Float32Array(n),this.v=new Float32Array(n),this.ink=new Float32Array(n),this.a=new Float32Array(n),this.b=new Float32Array(n),this.c=new Float32Array(n),this.pressure=new Float32Array(n),this.pressureNext=new Float32Array(n),this.divergence=new Float32Array(n),this.curl=new Float32Array(n)}get active(){return this.peak>2e-4}clear(){for(const e of[this.u,this.v,this.ink,this.a,this.b,this.c,this.pressure,this.pressureNext,this.divergence,this.curl,this.signal,this.pixels,this.offsetX,this.offsetY,this.driftX,this.driftY])e.fill(0);this.previous=null,this.peak=0}leave(){this.previous=null}move(e,t,n,r=performance.now()){if(!Number.isFinite(e+t+n+r))return;e=Math.max(0,Math.min(1,e)),t=Math.max(0,Math.min(1,t)),n=Math.max(.1,Math.min(1,n));const i=this.previous;if(this.previous={x:e,y:t,time:r},!i)return;const o=(e-i.x)*(this.width-1),a=(t-i.y)*(this.height-1),l=Math.hypot(o,a);if(l<.001)return;const u=Math.min(this.width,this.height),s=r>i.time?Math.max(1/240,(r-i.time)/1e3):1/60,c=Math.min(12,l/u/s),h=1-Math.exp(-c/2.2),f=u*(.022+.075*n)*(.65+.95*h),d=Math.min(128,Math.max(1,Math.ceil(l/(.4*f)))),m=l/f*(.32+.22*h)/d,v=o/l,g=a/l,p=-g,x=v,E=l*(2+18*h)/d;for(let n=0;n<d;n++){const r=(n+.5)/d,o=(i.x+(e-i.x)*r)*(this.width-1),a=(i.y+(t-i.y)*r)*(this.height-1),l=Math.max(1,Math.floor(o-3*f)),u=Math.min(this.width-2,Math.ceil(o+3*f)),s=Math.max(1,Math.floor(a-3*f)),c=Math.min(this.height-2,Math.ceil(a+3*f));for(let e=s;e<=c;e++)for(let t=l;t<=u;t++){const n=((t-o)*v+(e-a)*g)/f,r=((t-o)*p+(e-a)*x)/f,i=Math.exp(-n*n*.65-r*r*1.7),l=e*this.width+t;this.ink[l]=1-(1-this.ink[l])*Math.exp(-i*m);const u=1-r*r*.55,s=n*r*.7;this.u[l]=Math.max(-80,Math.min(80,this.u[l]+(v*u+p*s)*i*E)),this.v[l]=Math.max(-80,Math.min(80,this.v[l]+(g*u+x*s)*i*E))}}this.peak=1}read(e,t,n){const r=0|(t=Math.max(.5,Math.min(this.width-1.5,t))),i=0|(n=Math.max(.5,Math.min(this.height-1.5,n))),o=t-r,a=n-i,l=i*this.width+r;return(e[l]*(1-o)+e[l+1]*o)*(1-a)+(e[l+this.width]*(1-o)+e[l+this.width+1]*o)*a}sample(e,t){return this.read(this.signal,e*(this.width-1),t*(this.height-1))}displacement(e,t,n){n[0]=this.read(this.offsetX,e*(this.width-1),t*(this.height-1)),n[1]=this.read(this.offsetY,e*(this.width-1),t*(this.height-1))}step(e){if(!this.active||!Number.isFinite(e))return;let t=Math.max(0,Math.min(.05,e));const n=this.width,r=this.height;for(;t>1e-7;){const e=Math.min(1/60,t);t-=e;const i=Math.exp(-1.9*e),o=Math.exp(-3.2*e);for(let t=1;t<r-1;t++)for(let a=1;a<n-1;a++){const l=t*n+a,u=Math.max(.5,Math.min(n-1.5,a-this.u[l]*e)),s=Math.max(.5,Math.min(r-1.5,t-this.v[l]*e)),c=0|u,h=0|s,f=u-c,d=s-h,m=h*n+c,v=(1-f)*(1-d),g=f*(1-d),p=(1-f)*d,x=f*d;this.a[l]=(this.u[m]*v+this.u[m+1]*g+this.u[m+n]*p+this.u[m+n+1]*x)*i,this.b[l]=(this.v[m]*v+this.v[m+1]*g+this.v[m+n]*p+this.v[m+n+1]*x)*i,this.c[l]=(this.ink[m]*v+this.ink[m+1]*g+this.ink[m+n]*p+this.ink[m+n+1]*x)*o}[this.u,this.a]=[this.a,this.u],[this.v,this.b]=[this.b,this.v],[this.ink,this.c]=[this.c,this.ink];for(let e=1;e<r-1;e++)for(let t=1;t<n-1;t++){const r=e*n+t;this.curl[r]=.5*(this.v[r+1]-this.v[r-1]-this.u[r+n]+this.u[r-n])}for(let t=1;t<r-1;t++)for(let r=1;r<n-1;r++){const i=t*n+r,o=Math.abs(this.curl[i+1])-Math.abs(this.curl[i-1]),a=Math.abs(this.curl[i+n])-Math.abs(this.curl[i-n]),l=Math.hypot(o,a)+1e-4,u=this.curl[i]*e*10,s=Math.hypot(this.u[i],this.v[i]);this.u[i]+=a/l*u,this.v[i]-=o/l*u;const c=Math.min(1,s/(Math.hypot(this.u[i],this.v[i])+1e-6));this.u[i]*=c,this.v[i]*=c,this.divergence[i]=-.5*(this.u[i+1]-this.u[i-1]+this.v[i+n]-this.v[i-n])}this.pressure.fill(0);for(let e=0;e<4;e++){for(let e=1;e<r-1;e++)for(let t=1;t<n-1;t++){const r=e*n+t;this.pressureNext[r]=.25*(this.divergence[r]+this.pressure[r-1]+this.pressure[r+1]+this.pressure[r-n]+this.pressure[r+n])}[this.pressure,this.pressureNext]=[this.pressureNext,this.pressure]}let a=0;for(let t=1;t<r-1;t++)for(let r=1;r<n-1;r++){const i=t*n+r;this.u[i]=Math.max(-80,Math.min(80,this.u[i]-.5*(this.pressure[i+1]-this.pressure[i-1]))),this.v[i]=Math.max(-80,Math.min(80,this.v[i]-.5*(this.pressure[i+n]-this.pressure[i-n]))),this.driftX[i]+=(3.6*this.u[i]-58*this.offsetX[i]-12*this.driftX[i])*e,this.driftY[i]+=(3.6*this.v[i]-58*this.offsetY[i]-12*this.driftY[i])*e,this.offsetX[i]=Math.max(-2,Math.min(2,this.offsetX[i]+this.driftX[i]*e)),this.offsetY[i]=Math.max(-2,Math.min(2,this.offsetY[i]+this.driftY[i]*e)),this.signal[i]=1-Math.exp(.06*-Math.hypot(this.u[i],this.v[i])-.16*this.ink[i]),a=Math.max(a,this.signal[i])}this.peak=a}if(this.active)for(let e=0;e<this.ink.length;e++){const t=Math.round(65535*Math.min(1,this.signal[e]));this.pixels[4*e]=t>>>8,this.pixels[4*e+1]=255&t,this.pixels[4*e+2]=Math.round(128+63.5*this.offsetX[e]),this.pixels[4*e+3]=Math.round(128+63.5*this.offsetY[e])}else this.clear()}},h=["glyph","dot","pixel","mosaic","lego","voxel","disco","dither","hex","led","cmyk","stipple","engraving","crosshatch","woodblock","risograph","pointillism"],f={radius:.13,strength:.5,trail:.45,follow:12},d={strength:.55,radius:.45},m={radius:.075,force:1,dissipation:1.6,refraction:.03,glow:.55,resolution:128,curl:24},v={charset:" .,:-=+*#%@",cellSize:12,cellAspect:1,cellFit:"pixel",font:'ui-monospace, "SF Mono", Menlo, Consolas, monospace',fontWeight:500,glyphScale:.8,mark:"glyph",dotScale:.9,color:"ink",ink:"#f3ba32",highlight:"auto",background:"transparent",brightness:0,contrast:1,gamma:1,invert:!1,levels:"auto",blend:"auto",saturation:1.1,shade:.5,backdrop:0,fit:"cover",focus:{x:.5,y:.5},vignette:0,drift:0,scene:"flow",scale:1,clear:!1,speed:1,hover:"fluid",fluid:m,lantern:f,trail:d,maxPixelRatio:2,respectReducedMotion:!0},g=(e,t,n,r)=>"number"==typeof e&&Number.isFinite(e)?Math.min(n,Math.max(t,e)):r,p=(e,t)=>"string"==typeof e&&/^#([\da-f]{3}|[\da-f]{6})$/i.test(e.trim())?e.trim().toLowerCase():t;function x(e){const t=Intl.Segmenter;return(t?Array.from(new t(void 0,{granularity:"grapheme"}).segment(e),e=>e.segment):Array.from(e)).filter(e=>"\n"!==e&&"\r"!==e&&"\t"!==e).slice(0,256)}function E(e={},t=v){const n="string"==typeof e.charset&&x(e.charset).length>=2?e.charset:t.charset,r=t.fluid||m,i=void 0===e.fluid?t.fluid:e.fluid,o=!1!==i&&(()=>{const e=!0!==i&&i?{...r,...i}:r;return{radius:g(e.radius,.005,.5,m.radius),force:g(e.force,0,8,m.force),dissipation:g(e.dissipation,.05,20,m.dissipation),refraction:g(e.refraction,0,.5,m.refraction),glow:g(e.glow,0,2,m.glow),resolution:Math.round(g(e.resolution,16,512,m.resolution)),curl:g(e.curl,0,80,m.curl)}})(),a="none"===e.scene||"flow"===e.scene||"orb"===e.scene||"drift"===e.scene||"swell"===e.scene?e.scene:t.scene,l=!!e.clear&&"object"==typeof e.clear&&("element"in e.clear||"nodeType"in e.clear),u=void 0===e.clear||l?t.clear:e.clear,s=!!u&&{x:g(u.x,-.5,1.5,.25),y:g(u.y,-.5,1.5,.3),width:g(u.width,0,2,.5),height:g(u.height,0,2,.4),feather:g(u.feather,.005,1,.12),shape:"rect"===u.shape?"rect":"ellipse"};return{charset:n,cellSize:g(e.cellSize,3,96,t.cellSize),cellAspect:g(e.cellAspect,.3,2,t.cellAspect),cellFit:"fill"===e.cellFit||"pixel"===e.cellFit?e.cellFit:t.cellFit,font:"string"==typeof e.font&&e.font.trim()?e.font:t.font,fontWeight:Math.round(g(e.fontWeight,100,900,t.fontWeight)),glyphScale:g(e.glyphScale,.3,1.6,t.glyphScale),mark:h.includes(e.mark)?e.mark:t.mark,dotScale:g(e.dotScale,.1,1.4,t.dotScale),color:"source"===e.color||"ink"===e.color?e.color:t.color,ink:p(e.ink,t.ink),highlight:"auto"===e.highlight?"auto":p(e.highlight,t.highlight),background:"transparent"===e.background?"transparent":p(e.background,t.background),brightness:g(e.brightness,-1,1,t.brightness),contrast:g(e.contrast,0,4,t.contrast),gamma:g(e.gamma,.2,5,t.gamma),invert:"boolean"==typeof e.invert?e.invert:t.invert,levels:"none"===e.levels||"auto"===e.levels?e.levels:t.levels,blend:"auto"===e.blend||"coarse"===e.blend||"on"===e.blend||"off"===e.blend?e.blend:t.blend,saturation:g(e.saturation,0,3,t.saturation),shade:g(e.shade,0,1,t.shade),backdrop:g(e.backdrop,0,1,t.backdrop),fit:"contain"===e.fit||"cover"===e.fit?e.fit:t.fit,focus:{x:g(e.focus?.x,0,1,t.focus.x),y:g(e.focus?.y,0,1,t.focus.y)},vignette:g(e.vignette,0,1,t.vignette),drift:g(e.drift,0,2,t.drift),scene:a,scale:g(e.scale,.2,6,t.scale),clear:s,speed:g(e.speed,0,5,t.speed),hover:"fluid"===e.hover||"lantern"===e.hover||"trail"===e.hover||"none"===e.hover?e.hover:t.hover,fluid:o,lantern:{radius:g(e.lantern?.radius,.02,.6,t.lantern.radius),strength:g(e.lantern?.strength,0,1.5,t.lantern.strength),trail:g(e.lantern?.trail,0,3,t.lantern.trail),follow:g(e.lantern?.follow,1,60,t.lantern.follow)},trail:{strength:g(e.trail?.strength,0,1,t.trail.strength),radius:g(e.trail?.radius,.1,1,t.trail.radius)},maxPixelRatio:g(e.maxPixelRatio,.5,4,t.maxPixelRatio),respectReducedMotion:"boolean"==typeof e.respectReducedMotion?e.respectReducedMotion:t.respectReducedMotion}}function y(e,t,n,r,i,o={x:.5,y:.5}){if(!(e>0&&t>0&&n>0&&r>0))return{scale:[1,1],offset:[0,0]};const a=e/t,l=n/r,u=l>a,s="cover"===i?u?[a/l,1]:[1,l/a]:u?[1,l/a]:[a/l,1];return{scale:s,offset:"cover"===i?[(1-s[0])*o.x,(1-s[1])*o.y]:[.5*(1-s[0]),.5*(1-s[1])]}}function b(e,t,n,r){const i=Math.max(2,Math.round(e*n)),o=Math.max(2,Math.round(i*t)),a=Math.min(16,Math.max(1,r)),l=Math.ceil(r/a);return{width:o,height:i,columns:a,rows:l,atlasWidth:a*o,atlasHeight:l*i}}function T(e){const t=e.replace("#",""),n=3===t.length?t.split("").map(e=>e+e).join(""):t,r=Number.parseInt(n,16);return Number.isFinite(r)&&6===n.length?[(r>>16&255)/255,(r>>8&255)/255,(255&r)/255]:[0,0,0]}function w(e){const t=new Uint32Array(256);let n=0;for(let r=0;r+3<e.length;r+=4)e[r+3]<8||(t[Math.round(.2126*e[r]+.7152*e[r+1]+.0722*e[r+2])]++,n++);if(!n)return[0,1];const r=e=>{let r=0;for(let i=0;i<256;i++)if(r+=t[i],r>=n*e)return i/255;return 1},i=r(.02),o=r(.98);return o-i<.08?[0,1]:[i,o]}var M=e=>"fluid"!==e.hover||e.fluid?e.hover:"none";function R(e,t,n=24,r=.12,i="ellipse"){return e.width>0&&e.height>0&&{x:(t.left-n-e.left)/e.width,y:(t.top-n-e.top)/e.height,width:(t.width+2*n)/e.width,height:(t.height+2*n)/e.height,feather:r,shape:i}}var F,A=/\.(mp4|webm|mov|m4v|ogv)(\?|#|$)/i,k=/swiftshader|llvmpipe|softpipe|software|basic render/i;function L(){if(F)return F;if("undefined"==typeof document||void 0===globalThis.WebGL2RenderingContext)return F="none";try{const e=document.createElement("canvas").getContext("webgl2");if(!e)return F="none";const t=e.getExtension("WEBGL_debug_renderer_info"),n=String(e.getParameter(t?t.UNMASKED_RENDERER_WEBGL:e.RENDERER)??"");return e.getExtension("WEBGL_lose_context")?.loseContext(),F=k.test(n)?"software":"gpu"}catch{return F="none"}}exports.DEFAULT_FIELD_FLUID=m,exports.DEFAULT_FIELD_LANTERN=f,exports.DEFAULT_FIELD_SETTINGS=v,exports.DEFAULT_FIELD_TRAIL=d,exports.FIELD_HOVERS=[{value:"fluid",label:"Fluid",description:"An ink-in-water wake that bends the image and swirls the characters."},{value:"lantern",label:"Lantern",description:"A soft light follows the pointer and lifts the characters it passes, without distortion."},{value:"trail",label:"Trail",description:"The Asciify Trail: in the wake, sparse characters fill in and dense ones open up, then settle. No distortion."},{value:"none",label:"Off",description:"The field stays still under the pointer."}],exports.FIELD_MARKS=h,exports.activeFieldHover=M,exports.fieldCellLayout=b,exports.fieldClearFromRects=R,exports.fieldGlyphs=x,exports.fieldLevels=w,exports.fieldSourceRect=y,exports.glyphFieldTier=L,exports.isGlyphFieldSupported=function(e={}){const t=L();return"gpu"===t||"software"===t&&!!e.allowSoftware},exports.mountGlyphField=function(t,f={}){const d=e=>"undefined"!=typeof HTMLElement&&e instanceof HTMLElement,m=e=>{const t=e.clear;return d(t)?{element:{element:t},rest:{...e,clear:void 0}}:t&&"object"==typeof t&&d(t.element)?{element:t,rest:{...e,clear:void 0}}:{element:null,rest:e}};let v=m(f).element,g=E(m(f).rest);const p=f.onError,F=t.getContext("webgl2",{alpha:!0,antialias:!1,depth:!1,stencil:!1,premultipliedAlpha:!0,powerPreference:"high-performance"});if(!F)throw new Error("WebGL2 is not available for the glyph field.");const k=F;t.setAttribute("role","img"),t.setAttribute("aria-label",f.label??"ASCII artwork"),t.dataset.renderer="glyph-field";let L=!1;const D=k.getExtension("KHR_parallel_shader_compile");let S,_,C=null,P=null,U=null,I=null,B=[],X=[],N=null,G=!1,H=null,V=null;const O=[];let z=0,q=0,W=1,Y=0,j=b(g.cellSize,g.cellAspect,1,2),K=2,$=0,J=0,Q=0,Z=null,ee=!1,te=null,ne=0,re=0,ie=0,oe=null,ae=0,le=!0,ue=0,se=[0,1],ce=-1/0,he=0,fe=0,de=0,me=!0,ve=!1,ge=!1,pe=!1,xe=!1,Ee=!0,ye=null,be=null,Te=1/60,we=0,Me=0,Re=[];const Fe=new Float32Array(16),Ae=()=>{if(!v)return;const{element:e,padding:n=32,feather:r=.16,shape:i="rect"}=v,o=R(t.getBoundingClientRect(),e.getBoundingClientRect(),n,r,i),a=g.clear;JSON.stringify(a)!==JSON.stringify(o)&&(g={...g,clear:o},me=!0)},ke={target:null,at:null,strength:0,trail:[]},Le=new Float32Array(36);let De=null,Se=null,_e=!1;const Ce=()=>{if(!z||!q)return null;const e=z/q,t=Math.round(e>=1?128:128*e),n=Math.round(e>=1?128/e:128);return De&&De.width===t&&De.height===n||(De=new c(t,n),Se||(Se=qe(k.LINEAR)),k.bindTexture(k.TEXTURE_2D,Se),k.texImage2D(k.TEXTURE_2D,0,k.RGBA8,t,n,0,k.RGBA,k.UNSIGNED_BYTE,De.pixels),_e=!0),De};let Pe=0;const Ue="function"==typeof matchMedia?matchMedia("(prefers-reduced-motion: reduce)"):null,Ie=()=>g.respectReducedMotion&&!!Ue?.matches;let Be;const Xe=new Promise(e=>{Be=e});let Ne=!0;const Ge=e=>p?.(e instanceof Error?e:new Error(String(e))),He=(e,t)=>{const n=k.createShader(e);return O.push(n),k.shaderSource(n,t),k.compileShader(n),n},Ve=e=>{V??(V=He(k.VERTEX_SHADER,"#version 300 es\nvoid main(){vec2 p=vec2((gl_VertexID<<1)&2,gl_VertexID&2);gl_Position=vec4(p*2.-1.,0.,1.);}"));const t=k.createProgram(),n=He(k.FRAGMENT_SHADER,e);return k.attachShader(t,V),k.attachShader(t,n),k.linkProgram(t),{program:t,locations:null,fragment:n}},Oe=(e,t=!1)=>{if(e.locations)return!0;const{program:n,fragment:r}=e;if(!t&&D&&!k.getProgramParameter(n,D.COMPLETION_STATUS_KHR))return!1;if(!k.getProgramParameter(n,k.LINK_STATUS)){if(k.isContextLost())return!1;throw new Error(k.getShaderInfoLog(r)||k.getProgramInfoLog(n)||"Glyph field program failed to link.")}const i={};for(let e=k.getProgramParameter(n,k.ACTIVE_UNIFORMS)-1;e>=0;e--){const t=k.getActiveUniform(n,e).name.replace(/\[0\]$/,"");i[t]=k.getUniformLocation(n,t)}return e.locations=i,!0},ze=(e=!1)=>!!C&&!!P&&Oe(C,e)&&Oe(P,e),qe=e=>{const t=k.createTexture();return k.bindTexture(k.TEXTURE_2D,t),k.texParameteri(k.TEXTURE_2D,k.TEXTURE_MIN_FILTER,e),k.texParameteri(k.TEXTURE_2D,k.TEXTURE_MAG_FILTER,e===k.LINEAR_MIPMAP_LINEAR?k.LINEAR:e),k.texParameteri(k.TEXTURE_2D,k.TEXTURE_WRAP_S,k.CLAMP_TO_EDGE),k.texParameteri(k.TEXTURE_2D,k.TEXTURE_WRAP_T,k.CLAMP_TO_EDGE),t},We=()=>{I&&(k.deleteTexture(I.ink),k.deleteTexture(I.under),k.deleteFramebuffer(I.buffer),I=null)},Ye=()=>function(e,t,n,r,i,o,a){if("fill"!==e||!(i>0&&o>0))return[a.width,a.height];const l=t*r,u=l*n;return[i/Math.max(1,Math.floor(i/u+1e-6)),o/Math.max(1,Math.floor(o/l+1e-6))]}(g.cellFit,g.cellSize,g.cellAspect,W,z,q,j),je=()=>!!g.fluid&&"fluid"===M(g),Ke=()=>{N?.release(),G=!1,B.forEach(e=>k.deleteTexture(e)),X.forEach(e=>k.deleteFramebuffer(e)),B=[],X=[]};function $e(){U&&k.deleteProgram(U.program),U=Ve((t=>`#version 300 es\nprecision highp float;\nprecision highp sampler2D;\nuniform sampler2D uPrevious;\nuniform vec2 uSize;\nuniform float uAspect, uDt, uDecay, uEnergyDecay, uRadius, uSplat;\nuniform vec2 uFrom, uTo, uForce;\nout vec4 outColor;\n${e(t)}\nfloat segment(vec2 p,vec2 a,vec2 b){vec2 pa=p-a,ba=b-a;float h=clamp(dot(pa,ba)/max(dot(ba,ba),1e-8),0.,1.);return length(pa-ba*h);}\nvoid main(){\n vec2 uv=gl_FragCoord.xy/uSize;\n vec4 here=decodeFluid(texture(uPrevious,uv));\n vec4 state=decodeFluid(texture(uPrevious,uv-uDt*here.xy*vec2(1./uAspect,1.)));\n state.xy*=exp(-uDt*uDecay);\n state.z*=exp(-uDt*uEnergyDecay);\n if(uSplat>.5){\n vec2 scale=vec2(uAspect,1.);\n float d=segment(uv*scale,uFrom*scale,uTo*scale);\n float g=exp(-d*d/(uRadius*uRadius));\n state.xy+=uForce*g;\n state.z=min(1.,state.z+g*min(1.,length(uForce)*.5+.08));\n }\n float speed=length(state.xy);\n if(speed>5.)state.xy*=5./speed;\n outColor=encodeFluid(state);\n}`)(L)),N?.dispose(),N=L?null:function(e,t,c){const h={splat:t(n),curl:t(r),vorticity:t(i),divergence:t(o),fade:t(a),pressure:t(l),gradient:t(u),advect:t(s)},f=Object.values(h);let d=0,m=0,v=[],g=[],p=null,x=null;const E=t=>{const n=e.createTexture();e.bindTexture(e.TEXTURE_2D,n),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texImage2D(e.TEXTURE_2D,0,e.RGBA16F,d,m,0,e.RGBA,e.HALF_FLOAT,null);const r=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,n,0),e.checkFramebufferStatus(e.FRAMEBUFFER)!==e.FRAMEBUFFER_COMPLETE?(e.deleteFramebuffer(r),e.deleteTexture(n),null):(e.viewport(0,0,d,m),e.clearColor(0,0,0,1),e.clear(e.COLOR_BUFFER_BIT),{texture:n,buffer:r})},y=t=>{t&&(e.deleteTexture(t.texture),e.deleteFramebuffer(t.buffer))},b=()=>{[...v,...g,p,x].forEach(y),v=[],g=[],p=x=null},T=(t,n)=>{const r=t.locations;return e.useProgram(t.program),e.bindFramebuffer(e.FRAMEBUFFER,n.buffer),e.uniform2f(r.uTexel,1/d,1/m),r},w=(t,n,r,i)=>{e.activeTexture(e.TEXTURE0+r),e.bindTexture(e.TEXTURE_2D,i),e.uniform1i(t[n],r)},M=()=>e.drawArrays(e.TRIANGLES,0,3),R=e=>{const t=e[0];e[0]=e[1],e[1]=t};return{resize(t,n){b(),d=t,m=n;const r=[E(e.LINEAR),E(e.LINEAR),E(e.NEAREST),E(e.NEAREST),E(e.NEAREST),E(e.NEAREST)];return e.bindFramebuffer(e.FRAMEBUFFER,null),r.some(e=>!e)?(r.forEach(y),!1):(v=[r[0],r[1]],g=[r[2],r[3]],p=r[4],x=r[5],!0)},ready:()=>f.every(c),step(t,n){if(!v.length||!p||!x)return;let r;e.viewport(0,0,d,m),t&&(r=T(h.splat,v[1]),w(r,"uVelocity",0,v[0].texture),e.uniform2f(r.uFrom,t.from[0],t.from[1]),e.uniform2f(r.uTo,t.to[0],t.to[1]),e.uniform2f(r.uForce,t.force[0],t.force[1]),e.uniform1f(r.uAspect,n.aspect),e.uniform1f(r.uRadius,n.radius),M(),R(v)),n.curl>0&&(r=T(h.curl,x),w(r,"uVelocity",0,v[0].texture),M(),r=T(h.vorticity,v[1]),w(r,"uVelocity",0,v[0].texture),w(r,"uCurl",1,x.texture),e.uniform1f(r.uStrength,n.curl),e.uniform1f(r.uDt,n.dt),M(),R(v)),r=T(h.divergence,p),w(r,"uVelocity",0,v[0].texture),M(),r=T(h.fade,g[1]),w(r,"uSource",0,g[0].texture),e.uniform1f(r.uAmount,.8),M(),R(g);for(let e=0;e<20;e++)r=T(h.pressure,g[1]),w(r,"uPressure",0,g[0].texture),w(r,"uDivergence",1,p.texture),M(),R(g);r=T(h.gradient,v[1]),w(r,"uPressure",0,g[0].texture),w(r,"uVelocity",1,v[0].texture),M(),R(v),r=T(h.advect,v[1]),w(r,"uVelocity",0,v[0].texture),e.uniform1f(r.uDt,n.dt),e.uniform1f(r.uDissipation,n.dissipation),M(),R(v),e.bindFramebuffer(e.FRAMEBUFFER,null)},get velocity(){return v[0]?.texture??null},get size(){return[d,m]},release:b,dispose(){b(),f.forEach(({program:t})=>e.deleteProgram(t))}}}(k,Ve,e=>Oe(e))}const Je=()=>{Ke();const e=g.fluid;if(!(e&&je()&&z&&q))return;U||$e();const t=e.resolution,n=z/q;if($=n>=1?t:Math.max(8,Math.round(t*n)),J=n>=1?Math.max(8,Math.round(t/n)):t,G=!!N&&N.resize($,J),G)return void(Q=0);const r=()=>{Ke();for(let e=0;e<2;e++){const e=qe(k.LINEAR);k.texImage2D(k.TEXTURE_2D,0,L?k.RGBA8:k.RGBA16F,$,J,0,k.RGBA,L?k.UNSIGNED_BYTE:k.HALF_FLOAT,null);const t=k.createFramebuffer();k.bindFramebuffer(k.FRAMEBUFFER,t),k.framebufferTexture2D(k.FRAMEBUFFER,k.COLOR_ATTACHMENT0,k.TEXTURE_2D,e,0),B.push(e),X.push(t)}return k.checkFramebufferStatus(k.FRAMEBUFFER)===k.FRAMEBUFFER_COMPLETE};if(!r()){if(L)throw new Error("The glyph field could not allocate its fluid buffers.");L=!0,Qe(),$e(),r()}for(const e of X)k.bindFramebuffer(k.FRAMEBUFFER,e),k.viewport(0,0,$,J),k.clearColor(L?.5:0,L?.5:0,0,1),k.clear(k.COLOR_BUFFER_BIT);k.bindFramebuffer(k.FRAMEBUFFER,null),Q=0};function Qe(){C&&k.deleteProgram(C.program),P&&k.deleteProgram(P.program),We(),C=Ve((t=>`#version 300 es\nprecision highp float;\nprecision highp sampler2D;\nuniform sampler2D uSource, uFluid;\nuniform vec2 uResolution, uCell;\nuniform float uCount, uBlend;\nconst float BAYER[16]=float[16](0.,8.,2.,10.,12.,4.,14.,6.,3.,11.,1.,9.,15.,7.,13.,5.);\nuniform vec4 uSourceMap;\nuniform int uScene;\nuniform vec3 uInk, uHighlight;\nuniform vec4 uBackground;\nuniform float uBrightness, uContrast, uGamma, uInvert, uVignette, uSourceColor;\nuniform float uRefraction, uGlow, uTime, uDrift, uFluidOn, uLod, uSaturation, uBackdrop, uShade, uHighlightAuto, uFluidMode;\nuniform vec2 uFluidTexel;\nuniform int uHoverMode;\nuniform vec3 uLight;\nuniform vec3 uTrail[12];\nuniform float uLightRadius, uLightGain, uClock, uFlicker, uTrailAmount;\nuniform sampler2D uTrailMap;\nuniform vec2 uLevels;\nuniform int uMark;\nuniform float uScale, uClearFeather, uClearShape;\nuniform vec4 uClear;\nuniform vec4 uPulse[4];\nlayout(location=0) out vec4 outInk;\nlayout(location=1) out vec4 outUnder;\n${e(t)}\nfloat hash(vec2 p){p=fract(p*vec2(123.34,456.21));p+=dot(p,p+45.32);return fract(p.x*p.y);}\nfloat noise(vec2 p){vec2 i=floor(p),f=fract(p),u=f*f*(3.-2.*f);\n return mix(mix(hash(i),hash(i+vec2(1,0)),u.x),mix(hash(i+vec2(0,1)),hash(i+vec2(1,1)),u.x),u.y);}\nfloat fbm(vec2 p){float v=0.,a=.5;for(int i=0;i<5;i++){v+=a*noise(p);p=p*2.03+vec2(1.7,9.2);a*=.5;}return v;}\nvec3 generated(vec2 uv,float aspect){\n vec2 p=(uv-.5)*vec2(aspect,1.)*uScale;\n if(uScene==1){\n float t=uTime*.08;\n vec2 q=vec2(fbm(p*1.6+t),fbm(p*1.6-t+3.1));\n return vec3(smoothstep(.28,.86,fbm(p*1.8+q*1.6+vec2(t*.6,-t*.4))));\n }\n if(uScene==2){\n float r=.36,d=length(p),a=uTime*.25;\n vec3 l=normalize(vec3(cos(a)*.8,.55,sin(a)*.6+.6));\n if(d<r){\n vec3 n=normalize(vec3(p.x,-p.y,sqrt(r*r-d*d)));\n float diffuse=max(dot(n,l),0.),rim=pow(1.-n.z,2.5);\n float lon=atan(n.x,n.z)+uTime*.35,lat=asin(clamp(n.y,-1.,1.));\n float bands=.5+.25*sin(lat*14.)+.25*sin(lon*6.);\n return vec3(clamp(diffuse*.85+rim*.5+bands*.12,0.,1.));\n }\n return vec3(exp(-pow((d-r)*9.,2.))*.35);\n }\n if(uScene==4){\n // Drift: a few broad lobes that wander slowly. Built for halftone, where large soft shapes read best.\n float t=uTime*.045;\n vec2 q=p*1.15;\n vec2 w=vec2(fbm(q*.7+vec2(t,-t*.7)),fbm(q*.7+vec2(4.3-t*.8,t+1.7)));\n float n=fbm(q+w*1.3+vec2(t*.4,t*.25));\n return vec3(smoothstep(.36,.74,n));\n }\n if(uScene==5){\n // Swell: three crossing swells, the second bent by the first, so crests roll diagonally instead of pooling.\n float t=uTime;\n float s=sin((dot(p,vec2(.94,.33))/.95-t/9.)*6.2831853);\n float c=sin((dot(p,vec2(.6,-.8))/.58-t/13.)*6.2831853+s*.9);\n float k=sin((dot(p,vec2(-.29,.96))/.36+t/17.)*6.2831853);\n return vec3(smoothstep(.3,.9,.5+.5*(s*.5+c*.35+k*.15)));\n }\n return vec3(0.);\n}\nvoid main(){\n vec2 cell=floor(gl_FragCoord.xy);\n vec2 uv=(cell+.5)*uCell/uResolution;\n float aspect=uResolution.x/uResolution.y;\n vec4 fluid=vec4(0.);\n // lift: signed tone change. The solver's flow brightens one side of each eddy and opens the other into gaps.\n float lift=0.,wake=0.,bend=1.,swirl=0.,speed=0.;\n if(uFluidOn>.5){\n vec4 raw=texture(uFluid,vec2(uv.x,1.-uv.y));\n if(uFluidMode>.5){\n vec2 v=raw.xy*uFluidTexel*vec2(aspect,1.);\n fluid=vec4(v,0.,1.);\n swirl=clamp(dot(v,vec2(.4,.65))*uGlow*.32,-.65,.65);\n speed=clamp(length(v)*uGlow*.055,0.,.38);\n bend=.4;\n } else {\n fluid=decodeFluid(raw);\n wake=clamp(fluid.z*uGlow,0.,1.);\n lift=wake*.55;\n }\n }\n vec2 drift=uDrift*.006*vec2(sin(uv.y*5.3+uTime*.6),cos(uv.x*4.1-uTime*.5));\n vec2 sampleAt=uv-vec2(fluid.x/aspect,-fluid.y)*uRefraction*bend+drift;\n vec3 rgb,glow=vec3(0.);\n if(uScene==0){\n vec2 s=sampleAt*uSourceMap.xy+uSourceMap.zw;\n bool inside=!(s.x<0.||s.y<0.||s.x>1.||s.y>1.);\n rgb=inside?textureLod(uSource,s,uLod).rgb:vec3(0.);\n if(uBackdrop>0.){\n vec2 b=(uv-vec2(fluid.x/aspect,-fluid.y)*uRefraction*bend*.5)*uSourceMap.xy+uSourceMap.zw;\n glow=(b.x<0.||b.y<0.||b.x>1.||b.y>1.)?vec3(0.):textureLod(uSource,b,uLod+3.).rgb*uBackdrop;\n }\n } else rgb=generated(sampleAt,aspect);\n float tone=dot(rgb,vec3(.2126,.7152,.0722));\n tone=clamp((tone-uLevels.x)/max(uLevels.y-uLevels.x,.01),0.,1.);\n tone=clamp((tone-.5)*uContrast+.5+uBrightness,0.,1.);\n tone=pow(tone,1./uGamma);\n if(uInvert>.5)tone=1.-tone;\n float flick=0.,trailFold=0.;\n if(uHoverMode==2){\n // Lantern: a soft light and its fading tail lift the characters they pass. Nothing moves the image.\n vec2 ap=vec2(aspect,1.),d=(uv-uLight.xy)*ap;\n float r2=uLightRadius*uLightRadius,glowL=uLight.z*exp(-dot(d,d)/r2);\n for(int i=0;i<12;i++){vec2 e=(uv-uTrail[i].xy)*ap;glowL+=uTrail[i].z*exp(-dot(e,e)/(r2*.55));}\n glowL=min(glowL,1.);\n float grain=fract(sin(dot(cell,vec2(12.9898,78.233)))*43758.5453);\n lift=glowL*uLightGain*(.7+.6*grain);\n wake=glowL*.4;\n // A few letters at the light's rim step up the ramp and back, as if being retyped.\n flick=uFlicker*step(.9,fract(grain*13.7+floor(uClock*7.+grain*5.)*.37))*glowL*(1.-glowL)*4.;\n }\n if(uHoverMode==3){\n // Trail: the studio's ink field, as a 16-bit density. Sparse marks fill in, dense marks open up.\n vec4 ink=texture(uTrailMap,uv);\n float density=(ink.r*65280.+ink.g*255.)/65535.*uTrailAmount;\n float t=clamp(density/.38,0.,1.);\n trailFold=t*t*(3.-2.*t);\n }\n if(uFluidMode>.5&&uHoverMode==1){\n // Dark ground: any motion lights the characters. Lit ground: the flow lights one side of each eddy and opens the other.\n // A little cell-to-cell grain keeps the lit area a shimmer of letters rather than a solid block.\n float grain=fract(sin(dot(cell,vec2(12.9898,78.233)))*43758.5453);\n lift=mix(abs(swirl)*.5+speed,swirl+speed*.35,smoothstep(.12,.55,tone))*(.65+.7*grain);\n wake=clamp(lift*1.6,0.,1.);\n }\n tone=clamp(tone+lift,0.,1.);\n tone+=(1.-2.*tone)*trailFold;\n // Pulses: rings sent by the interface (field.pulse()), e.g. on a save or a notification.\n for(int i=0;i<4;i++){\n if(uPulse[i].w<=0.)continue;\n float dist=length((uv-uPulse[i].xy)*vec2(aspect,1.)),front=uPulse[i].z*.95;\n float ring=exp(-pow((dist-front)/.1,2.))*uPulse[i].w*exp(-uPulse[i].z*.85);\n tone=clamp(tone+ring*.85,0.,1.);\n }\n tone*=1.-uVignette*smoothstep(.35,1.05,length((uv-.5)*vec2(min(aspect,1.8),1.)*2.));\n if(uClear.z>0.){\n // Clear zone: the field fades out around content so text above it stays readable.\n vec2 half_=uClear.zw*.5*vec2(aspect,1.),q=(uv-uClear.xy-uClear.zw*.5)*vec2(aspect,1.);\n float dz;\n if(uClearShape>.5){vec2 e=abs(q)-half_;dz=length(max(e,0.))+min(max(e.x,e.y),0.);}\n else dz=(length(q/max(half_,vec2(1e-4)))-1.)*min(half_.x,half_.y);\n tone*=smoothstep(0.,uClearFeather,dz);\n }\n // Blend: a shade between two characters takes the upper one in the share of cells a 4x4 Bayer pattern gives it.\n float level=tone*(uCount-1.),upper=fract(level)>=.5?1.:0.;\n if(uBlend>.5&&tone>.02&&tone<.98){\n ivec2 q=ivec2(mod(gl_FragCoord.xy,4.));\n upper=fract(level)>(BAYER[q.y*4+q.x]+.5)/16.?1.:0.;\n }\n float index=min(uCount-1.,floor(level)+upper+(flick>.5&&tone>.02?1.:0.));\n vec3 hue=rgb/max(max(rgb.r,rgb.g),max(rgb.b,.03));\n hue=mix(vec3(dot(hue,vec3(.2126,.7152,.0722))),hue,uSaturation);\n vec3 ink=mix(uInk*mix(1.,.3+.7*tone,uShade),clamp(hue*(.38+.62*tone),0.,1.),uSourceColor);\n vec3 lifted=uHighlightAuto>.5?ink/max(max(ink.r,ink.g),max(ink.b,.06)):uHighlight;\n ink=mix(ink,lifted,wake*.7);\n float underAlpha=max(uBackground.a,min(1.,max(glow.r,max(glow.g,glow.b))));\n vec3 under=min(uBackground.rgb*uBackground.a+glow,vec3(underAlpha));\n // Glyphs keep their atlas index, exact in 8 bits; the other marks keep the tone, and empty where the charset is blank.\n outInk=vec4(ink,uMark==0?index/255.:uMark==1?(tone>.003?tone:0.):index>0.?max(tone,1./255.):0.);\n outUnder=vec4(under,underAlpha);\n}`)(L)),P=Ve("#version 300 es\nprecision highp float;\nprecision highp sampler2D;\nuniform sampler2D uAtlas, uCells, uUnder;\nuniform vec2 uResolution, uCell, uPitch;\nuniform float uColumns, uDotScale, uSourceColor;\nuniform int uMark;\nout vec4 outColor;\nconst float BAYER[16]=float[16](0.,8.,2.,10.,12.,4.,14.,6.,3.,11.,1.,9.,15.,7.,13.,5.);\n// The Studio's print defaults: screen angle -35deg, roughness .35, seed 7, registration .2 and its coral second ink.\nconst vec2 DIR=vec2(.81915,-.57358);\nconst float ROUGH=.35,SEED=7.;\nconst vec3 SECOND=vec3(.925,.404,.322);\nfloat hash(vec2 p){p=fract(p*vec2(123.34,456.21));p+=dot(p,p+45.32);return fract(p.x*p.y);}\n// Coverage of a signed distance given in device pixels.\nfloat cover(float d){return clamp(.5-d,0.,1.);}\nfloat box(vec2 p,vec2 lo,vec2 hi){vec2 a=clamp(p-lo,0.,1.)*clamp(hi-p,0.,1.);return a.x*a.y;}\nfloat disc(vec2 p,vec2 c,float r){return r>.05?cover(length(p-c)-r):0.;}\nfloat ellipse(vec2 p,vec2 c,vec2 r,float a){vec2 d=p-c;d=vec2(cos(a)*d.x+sin(a)*d.y,-sin(a)*d.x+cos(a)*d.y);float k=length(d/r);return cover((k-1.)*min(r.x,r.y));}\n// World-anchored parallel cuts across direction d: period and width in cell heights, so lines run on from cell to cell.\nfloat cuts(vec2 w,vec2 d,float period,float width,float px){\n if(width<=0.)return 0.;\n float proj=dot(vec2(-d.y,d.x),w);\n return cover((abs(fract(proj/period+.5)-.5)*period-width*.5)*px);\n}\n// Lays an ink over what is already down, multiplying where they overlap, as transparent inks do on paper.\nvoid lay(inout vec3 rgb,inout float a,vec3 c,float k){\n float next=a+k*(1.-a);\n rgb=next>0.?(rgb*a*(1.-k)+mix(c,rgb*c,a)*k)/next:c;\n a=next;\n}\nvoid main(){\n vec2 frag=vec2(gl_FragCoord.x,uResolution.y-gl_FragCoord.y);\n // The pitch is the atlas cell, or a fractional one under cellFit 'fill', where each glyph sits centred in its stretched cell.\n vec2 cell=floor(frag/uPitch);\n vec4 ink=texelFetch(uCells,ivec2(cell),0),under=texelFetch(uUnder,ivec2(cell),0);\n vec2 local=frag-cell*uPitch;\n float coverage;\n vec3 rgb=ink.rgb;\n if(uMark==0){\n float index=floor(ink.a*255.+.5);\n ivec2 tile=ivec2(int(mod(index,uColumns)),int(floor(index/uColumns)));\n vec2 texel=floor(local-floor((uPitch-uCell)*.5));\n coverage=all(greaterThanEqual(texel,vec2(0.)))&&all(lessThan(texel,uCell))?texelFetch(uAtlas,tile*ivec2(uCell)+ivec2(texel),0).a:0.;\n } else if(uMark==1){\n // Halftone: dot area follows tone, so midtones read true; edges are antialiased to one device pixel.\n float r=sqrt(ink.a)*min(uPitch.x,uPitch.y)*.5*uDotScale;\n coverage=ink.a>.003?clamp(r-length(local-uPitch*.5)+.5,0.,1.):0.;\n } else if(ink.a<=0.){\n coverage=0.;\n } else {\n float tone=ink.a,side=min(uPitch.x,uPitch.y);\n vec2 q=local/uPitch,c=uPitch*.5,p=local+.5;\n // Tiles fade with the tone in one ink, as the Studio's do; in source colour the colour already carries it.\n float fade=uSourceColor>.5?1.:tone,gap=max(.5,uPitch.x*.06),grain=hash(cell+SEED);\n vec2 w=(cell+q)*uPitch/uPitch.y;\n if(uMark==2)coverage=fade;\n else if(uMark==3)coverage=box(p,vec2(0.),uPitch-gap)*fade;\n else if(uMark==4){\n // Lego: a gapped brick, lit from above, with a raised stud ringed by its shadow.\n coverage=box(p,vec2(0.),uPitch-gap)*fade;\n rgb*=1.06-.14*q.y;\n float r=side*.28,d=length(local-c)-r,lit=clamp(dot(c-local,vec2(.6,.8))/r,-1.,1.);\n rgb=mix(rgb,mix(rgb,vec3(1.),.2+.12*lit),cover(d));\n rgb=mix(rgb,rgb*.72,cover(abs(d)-max(.5,side*.04)));\n } else if(uMark==5){\n // Voxel: an isometric cube; top, left and right faces at full, .72 and .42 strength.\n float h=.5*abs(q.x-.5);\n coverage=cover(-min(q.y-h,1.-h-q.y)*uPitch.y)*cover(-min(q.x,1.-q.x)*uPitch.x);\n coverage*=mix(q.x<.5?.72:.42,1.,cover((q.y-(.5-h))*uPitch.y))*fade;\n } else if(uMark==6){\n // Disco: a gapped mirror tile, its upper facet catching light and its lower in shade.\n coverage=box(p,vec2(0.),uPitch-gap)*fade;\n rgb=q.y<.35?mix(rgb,vec3(1.),.1+grain*.25):q.y>.65?rgb*.75:rgb;\n } else if(uMark==7){\n // Dither: an ordered 4x4 Bayer screen at about five dots a cell, lit where the cell's tone passes the threshold.\n ivec2 b=ivec2(mod(floor(frag/max(1.,floor(side/5.))),4.));\n coverage=tone>(BAYER[b.y*4+b.x]+.5)/16.?1.:0.;\n } else if(uMark==8){\n // Hex: a flat-topped hexagon filling the cell.\n vec2 h=abs((local-c)/(uPitch*.49));\n coverage=cover(max(h.y-.866,h.x*.866+h.y*.5-.866)*side*.49)*fade;\n } else if(uMark==9){\n // LED: a round lamp with a soft halo and a specular glint, separated by an unlit matrix.\n float r=side*.39,d=length(local-c);\n coverage=max(cover(d-r),.3*exp(-pow(max(0.,d-r)/(side*.12),2.)))*fade;\n rgb=mix(rgb,vec3(1.),.35*disc(local,uPitch*vec2(.43,.4),side*.11));\n } else if(uMark==10){\n // CMYK: the cell's hue separated into offset cyan, magenta and yellow dots, each sized by its share of the tone. The\n // key screen carries the neutral share in the ink's own lightness, since a light ink on a dark page has no black.\n float top=max(rgb.r,max(rgb.g,rgb.b)),low=min(rgb.r,min(rgb.g,rgb.b));\n vec3 cmy=(top-rgb)/max(top,.001);\n float a=0.;vec3 col=vec3(1.);\n lay(col,a,vec3(top),disc(local,c,side*.48*sqrt(tone*low/max(top,.001))));\n lay(col,a,vec3(0.,1.,1.),disc(local,uPitch*vec2(.36,.36),side*.48*sqrt(tone*cmy.x)));\n lay(col,a,vec3(1.,0.,1.),disc(local,uPitch*vec2(.64,.36),side*.48*sqrt(tone*cmy.y)));\n lay(col,a,vec3(1.,1.,0.),disc(local,uPitch*vec2(.5,.66),side*.48*sqrt(tone*cmy.z)));\n rgb=col;coverage=a;\n } else if(uMark==11||uMark==16){\n // Stipple and pointillism: four jittered marks a cell, their size following the tone.\n coverage=0.;vec3 col=rgb;\n for(int m=0;m<4;m++){\n vec2 o=vec2(float(m%2),float(m/2));\n float j=hash(cell*2.+o+SEED),jy=hash(cell+o*11.+SEED+1.);\n vec2 at=((o+.5)/2.+(vec2(j,jy)-.5)*ROUGH*.28)*uPitch;\n float r=min(min(min(at.x,uPitch.x-at.x),min(at.y,uPitch.y-at.y)),side*min(.245,.21*sqrt(tone)*(1.-ROUGH*j*.35)));\n float k=uMark==11?disc(local,at,r):ellipse(local,at,vec2(r,r*.64),j*3.14159);\n if(uMark==16&&k>coverage)col=uSourceColor>.5?clamp(rgb+(j-.5)*ROUGH*.25*vec3(1.,-.4,-1.),0.,1.):rgb*(1.+(j-.5)*ROUGH*.5);\n coverage=max(coverage,k);\n }\n rgb=col;\n } else if(uMark==12||uMark==13){\n // Engraving and crosshatch: parallel cuts whose weight follows the tone; crossings join only in the darker tones.\n float cv=tone*(1.-ROUGH*grain*.3),px=uPitch.y;\n coverage=cuts(w,DIR,.5,min(.47,.36*cv),px);\n if(uMark==13){\n coverage=max(coverage,cuts(w,vec2(-DIR.y,DIR.x),.5,min(.47,.36*max(0.,cv*1.5-.3)),px)*step(.2,cv));\n coverage=max(coverage,cuts(w,normalize(DIR+vec2(-DIR.y,DIR.x)),.5,min(.47,.36*max(0.,cv*2.-1.2)),px)*step(.6,cv));\n }\n } else if(uMark==14){\n // Woodblock: broad carved bands in five stepped weights, their edges wavering along the grain.\n float cv=ceil(tone*(1.-ROUGH*grain*.3)*5.)/5.,width=min(.94,.72*cv);\n float proj=dot(vec2(-DIR.y,DIR.x),w),line=floor(proj+.5),along=dot(DIR,w);\n float cut=sin(along*5.3+line*1.9+SEED)*.5+sin(along*13.1+line)*.25;\n coverage=cover((abs(proj-line)-width*.5*(1.+ROUGH*cut*.5))*uPitch.y);\n } else if(uMark==15){\n // Risograph: two offset screens, the main ink and the coral second ink, misregistered along the screen angle.\n float split=uSourceColor>.5?clamp(.5+(rgb.r-rgb.b)*.5,0.,1.):.5,r=side*min(.48,.44*sqrt(tone));\n float a=0.;vec3 col=rgb;\n lay(col,a,rgb,disc(local,c,r*sqrt(.35+(1.-split)*.65)));\n lay(col,a,SECOND,disc(local,c+DIR*.2*.38*side,r*sqrt(.3+split*.7)*(1.-ROUGH*hash(cell+SEED+13.)*.3)));\n rgb=col;coverage=a;\n } else coverage=0.;\n }\n outColor=vec4(rgb*coverage+under.rgb*(1.-coverage),coverage+under.a*(1.-coverage));\n}"),D||ze(!0)}const Ze=()=>`${g.fontWeight} ${Math.max(1,j.height*g.glyphScale)}px ${g.font}`,et=()=>{const e=x(g.charset);K=e.length,j=b(g.cellSize,g.cellAspect,W,K),Y=W;const t=document.createElement("canvas");t.width=j.atlasWidth,t.height=j.atlasHeight;const n=t.getContext("2d");n.fillStyle="#fff",n.textAlign="center",n.textBaseline="alphabetic",n.font=Ze();const r=n.measureText("M"),i=r.actualBoundingBoxAscent||j.height*g.glyphScale*.7,o=r.actualBoundingBoxDescent||0,a=(j.height+i-o)/2;e.forEach((e,t)=>{const r=t%j.columns*j.width+j.width/2,i=Math.floor(t/j.columns)*j.height+a,o=n.measureText(e).width;n.save(),n.beginPath(),n.rect(r-j.width/2,i-a,j.width,j.height),n.clip(),n.translate(r,i),o>.96*j.width&&n.scale(.96*j.width/o,1),n.fillText(e,0,0),n.restore()}),k.bindTexture(k.TEXTURE_2D,S),k.pixelStorei(k.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),k.texImage2D(k.TEXTURE_2D,0,k.RGBA8,k.RGBA,k.UNSIGNED_BYTE,t),t.width=t.height=1,me=!0},tt="undefined"==typeof document?void 0:document.fonts,nt=()=>{if(!tt?.load)return;const e=Ze();tt.load(e,x(g.charset).join("")).then(()=>{ve||ge||Ze()!==e||(et(),Tt())},()=>{})},rt=e=>e.trim().replace(/^["']|["']$/g,"").toLowerCase(),it=e=>{const t=e.fontfaces??[],n=g.font.split(",").map(rt);t.some(e=>n.includes(rt(e.family)))&&nt()},ot=()=>{if(se=[0,1],Z&&"none"!==g.levels)try{const e=document.createElement("canvas");e.width=e.height=64;const t=e.getContext("2d",{willReadFrequently:!0});Z===oe&&(t.imageSmoothingQuality="medium"),t.drawImage(Z,0,0,64,64),se=w(t.getImageData(0,0,64,64).data)}catch{se=[0,1]}},at=()=>{if(!Z)return;const e=performance.now();Z instanceof HTMLVideoElement&&!(e-ce>1500)||(ot(),ce=e),k.bindTexture(k.TEXTURE_2D,_),k.pixelStorei(k.UNPACK_FLIP_Y_WEBGL,!1),k.pixelStorei(k.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);try{k.texImage2D(k.TEXTURE_2D,0,k.RGBA8,k.RGBA,k.UNSIGNED_BYTE,Z),k.generateMipmap(k.TEXTURE_2D)}catch(e){Ge(e)}},lt=()=>{L=!k.getExtension("EXT_color_buffer_float")&&!k.getExtension("EXT_color_buffer_half_float"),Qe(),H=k.createVertexArray(),S=qe(k.NEAREST),_=qe(k.LINEAR_MIPMAP_LINEAR),k.bindTexture(k.TEXTURE_2D,_),k.texImage2D(k.TEXTURE_2D,0,k.RGBA8,1,1,0,k.RGBA,k.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),k.generateMipmap(k.TEXTURE_2D),z=q=0,Y=0,ut(),nt(),Z&&at()};function ut(){const e=t.clientWidth||t.clientHeight?{width:t.clientWidth,height:t.clientHeight}:t.getBoundingClientRect(),n=Math.min(globalThis.devicePixelRatio||1,g.maxPixelRatio),r=Math.max(1,Math.round(e.width*n)),i=Math.max(1,Math.round(e.height*n));if(r===z&&i===q&&n===W)return!1;const o=!z||Math.abs(r/i-z/q)>.01;return W=n,z=r,q=i,t.width=z,t.height=q,Y!==W&&et(),(o||je()&&!B.length&&!G)&&Je(),me=!0,!0}let st=null,ct=[0,0,0],ht=[1,1,1],ft=[0,0,0,0],dt=y(1,1,1,1,"cover"),mt=null,vt=0,gt=0,pt=0,xt=0;const Et=()=>{st!==g&&(st=g,ct=T(g.ink),ht=T("auto"===g.highlight?"#ffffff":g.highlight),ft="transparent"===g.background?[0,0,0,0]:[...T(g.background),1]),mt===g&&vt===z&&gt===q&&pt===ne&&xt===re||(mt=g,vt=z,gt=q,pt=ne,xt=re,dt=y(z,q,ne||1,re||1,g.fit,g.focus));const e=g.fluid,t=Z&&ae?j.height/q*ae*dt.scale[1]:1,n=(()=>{const[e,t]=Ye(),n=Math.ceil(z/e-1e-4),r=Math.ceil(q/t-1e-4);if(I&&I.columns===n&&I.rows===r)return I;We();const i=()=>{const e=qe(k.NEAREST);return k.texStorage2D(k.TEXTURE_2D,1,L?k.RGBA8:k.RGBA16F,n,r),e},o=i(),a=i(),l=k.createFramebuffer();return k.bindFramebuffer(k.FRAMEBUFFER,l),k.framebufferTexture2D(k.FRAMEBUFFER,k.COLOR_ATTACHMENT0,k.TEXTURE_2D,o,0),k.framebufferTexture2D(k.FRAMEBUFFER,k.COLOR_ATTACHMENT1,k.TEXTURE_2D,a,0),k.drawBuffers([k.COLOR_ATTACHMENT0,k.COLOR_ATTACHMENT1]),I={ink:o,under:a,buffer:l,columns:n,rows:r}})(),r=C.locations,i=P.locations,o=M(g),a=!Ie();k.bindFramebuffer(k.FRAMEBUFFER,n.buffer),k.viewport(0,0,n.columns,n.rows),k.useProgram(C.program),k.activeTexture(k.TEXTURE0),k.bindTexture(k.TEXTURE_2D,_),k.uniform1i(r.uSource,0),k.activeTexture(k.TEXTURE2),k.bindTexture(k.TEXTURE_2D,(G?N?.velocity:B[Q])??_),k.uniform1i(r.uFluid,2),k.activeTexture(k.TEXTURE3),k.bindTexture(k.TEXTURE_2D,Se??_),k.uniform1i(r.uTrailMap,3),k.uniform1f(r.uFluidMode,G?1:0),k.uniform1i(r.uHoverMode,"fluid"===o?1:"lantern"===o?2:"trail"===o&&_e?3:0),k.uniform1f(r.uTrailAmount,g.trail.strength),k.uniform3f(r.uLight,ke.at?.[0]??-1,ke.at?.[1]??-1,"lantern"===o?ke.strength:0),k.uniform3fv(r.uTrail,Le),k.uniform1f(r.uLightRadius,g.lantern.radius),k.uniform1f(r.uLightGain,g.lantern.strength),k.uniform1f(r.uClock,performance.now()/1e3),k.uniform1f(r.uFlicker,a?1:0),k.uniform2f(r.uFluidTexel,1/Math.max(1,$),1/Math.max(1,J)),k.uniform2f(r.uResolution,z,q);const[l,u]=Ye();k.uniform2f(r.uCell,l,u),k.uniform1f(r.uCount,K),k.uniform1f(r.uBlend,"on"===g.blend||K<=9&&("coarse"===g.blend||"auto"===g.blend&&ee)?1:0),k.uniform4f(r.uSourceMap,dt.scale[0],dt.scale[1],dt.offset[0],dt.offset[1]),k.uniform1i(r.uScene,Z?0:"flow"===g.scene?1:"orb"===g.scene?2:"drift"===g.scene?4:"swell"===g.scene?5:3),k.uniform1i(r.uMark,h.indexOf(g.mark)),k.uniform1f(r.uScale,g.scale);const s=g.clear;k.uniform4f(r.uClear,s?s.x:0,s?s.y:0,s?s.width:0,s?s.height:0),k.uniform1f(r.uClearFeather,s?s.feather:.1),k.uniform1f(r.uClearShape,s&&"rect"===s.shape?1:0);const c=performance.now();Fe.fill(0);for(let e=0;e<Re.length;e++){const t=Re[e],n=4*e;Fe[n]=t.x,Fe[n+1]=t.y,Fe[n+2]=(c-t.born)/1e3,Fe[n+3]=t.strength}k.uniform4fv(r.uPulse,Fe),k.uniform3fv(r.uInk,ct),k.uniform3fv(r.uHighlight,ht),k.uniform1f(r.uHighlightAuto,"auto"===g.highlight?1:0),k.uniform4fv(r.uBackground,ft),k.uniform1f(r.uBrightness,g.brightness),k.uniform1f(r.uContrast,g.contrast),k.uniform1f(r.uGamma,g.gamma),k.uniform1f(r.uInvert,g.invert?1:0),k.uniform1f(r.uVignette,g.vignette),k.uniform1f(r.uSourceColor,"source"===g.color?1:0),k.uniform1f(r.uRefraction,e?e.refraction*(a?1:.25):0),k.uniform1f(r.uGlow,e?e.glow:0),k.uniform1f(r.uTime,de),k.uniform1f(r.uDrift,a?g.drift:0),k.uniform1f(r.uFluidOn,e&&"fluid"===o&&(B.length||G)?1:0),k.uniform1f(r.uLod,Math.max(0,Math.log2(Math.max(1,t))-.5)),k.uniform1f(r.uSaturation,g.saturation),k.uniform1f(r.uShade,g.shade),k.uniform1f(r.uBackdrop,Z?g.backdrop:0),k.uniform2f(r.uLevels,Z&&"auto"===g.levels?se[0]:0,Z&&"auto"===g.levels?se[1]:1),k.bindVertexArray(H),k.drawArrays(k.TRIANGLES,0,3),k.bindFramebuffer(k.FRAMEBUFFER,null),k.viewport(0,0,z,q),k.useProgram(P.program),k.activeTexture(k.TEXTURE1),k.bindTexture(k.TEXTURE_2D,S),k.uniform1i(i.uAtlas,1),k.activeTexture(k.TEXTURE4),k.bindTexture(k.TEXTURE_2D,n.ink),k.uniform1i(i.uCells,4),k.activeTexture(k.TEXTURE5),k.bindTexture(k.TEXTURE_2D,n.under),k.uniform1i(i.uUnder,5),k.uniform2f(i.uResolution,z,q),k.uniform2f(i.uCell,j.width,j.height),k.uniform2f(i.uPitch,l,u),k.uniform1f(i.uColumns,j.columns),k.uniform1f(i.uDotScale,g.dotScale),k.uniform1i(i.uMark,h.indexOf(g.mark)),k.uniform1f(i.uSourceColor,"source"===g.color?1:0),k.drawArrays(k.TRIANGLES,0,3)},yt=()=>!ve&&!ge&&!pe&&(Ee||Ne)&&!("undefined"!=typeof document&&document.hidden),bt=e=>{if(he=0,!yt())return;const t=(e-fe)/1e3,n=Math.min(1/30,Math.max(1/480,t));fe=e,Te=.9*Te+.1*Math.min(t,.25),we=Te>1/24?we+1:0;try{we>45&&Me<2&&(we=0,Me++,1===Me&&W>1?(g={...g,maxPixelRatio:1},ut()):Me=2);const t=ze(),r=!(xe||Me>=2&&!(Z instanceof HTMLVideoElement)||(!(Z instanceof HTMLVideoElement)||Z.paused||Z.ended)&&(Ie()||!(!Z&&"none"!==g.scene||g.drift>0)));r&&(de+=n*g.speed),Z instanceof HTMLVideoElement&&Z.readyState>=2&&le&&(le=!("requestVideoFrameCallback"in Z),at(),me=!0);const i=M(g);let o="fluid"===i&&(null!==be||e<Pe);if(o?((e,t)=>{const n=g.fluid;if(!n||!X.length&&!G)return;if(G?!N?.ready():!U||!Oe(U))return;const r=z/q,i=be;if(be=null,G&&N){const o=5200*n.force*(Ie()?.35:1);return i&&(Pe=t+1e3*Math.min(9,6/Math.max(.3,n.dissipation))),void N.step(i?{from:i.from,to:i.to,force:[(i.to[0]-i.from[0])*o,(i.to[1]-i.from[1])*o]}:null,{dt:Math.min(e,1/60),radius:1.1*n.radius,curl:n.curl,dissipation:n.dissipation,aspect:r})}let o=0,a=0;if(i){const e=(Ie()?1:3)*n.force;o=(i.to[0]-i.from[0])*r*e*4,a=(i.to[1]-i.from[1])*e*4,Pe=t+7/Math.min(n.dissipation,1.1*n.dissipation)*1e3}const l=U.locations;k.bindFramebuffer(k.FRAMEBUFFER,X[1-Q]),k.viewport(0,0,$,J),k.useProgram(U.program),k.activeTexture(k.TEXTURE0),k.bindTexture(k.TEXTURE_2D,B[Q]),k.uniform1i(l.uPrevious,0),k.uniform2f(l.uSize,$,J),k.uniform1f(l.uAspect,r),k.uniform1f(l.uDt,e),k.uniform1f(l.uDecay,n.dissipation),k.uniform1f(l.uEnergyDecay,1.1*n.dissipation),k.uniform1f(l.uRadius,n.radius),k.uniform1f(l.uSplat,i?1:0),k.uniform2f(l.uFrom,i?.from[0]??0,i?.from[1]??0),k.uniform2f(l.uTo,i?.to[0]??0,i?.to[1]??0),k.uniform2f(l.uForce,o,a),k.drawArrays(k.TRIANGLES,0,3),Q=1-Q})(n,e):be=null,"lantern"===i&&(o=((e,t)=>{const n=g.lantern,r=ke.target;if(r){const i=ke.at;if(i)if(Ie())i[0]=r[0],i[1]=r[1];else{const t=1-Math.exp(-n.follow*e);i[0]+=(r[0]-i[0])*t,i[1]+=(r[1]-i[1])*t}else ke.at=[r[0],r[1]];const o=ke.at,a=ke.trail[ke.trail.length-1];n.trail>0&&(!a||t-a.born>28&&Math.hypot(o[0]-a.x,o[1]-a.y)>.004)&&(ke.trail.push({x:o[0],y:o[1],born:t}),ke.trail.length>12&&ke.trail.shift())}ke.strength+=((r?1:0)-ke.strength)*(1-Math.exp(-e*(r?9:5)));const i=ke.trail;for(let e=i.length-1;e>=0;e--)n.trail>0&&t-i[e].born<4e3*n.trail||i.splice(e,1);Le.fill(0);for(let e=0;e<i.length;e++){const r=i[e];Le[3*e]=r.x,Le[3*e+1]=r.y,Le[3*e+2]=.55*Math.exp(-(t-r.born)/1e3/Math.max(.01,n.trail))}return ke.strength>.003||i.length>0})(n,e)||o),"trail"===i){const e=!!De?.active;o=(e=>{const t=Ce();return!(!t||!t.active||(t.step(e),k.bindTexture(k.TEXTURE_2D,Se),k.texSubImage2D(k.TEXTURE_2D,0,0,0,t.width,t.height,k.RGBA,k.UNSIGNED_BYTE,t.pixels),_e=!0,0))})(n)||o,e&&!De?.active&&(me=!0)}if(Re.length){for(let t=Re.length-1;t>=0;t--)e-Re[t].born>=2400&&Re.splice(t,1);o=!0,Re.length||(me=!0)}t&&(r||o||me)&&(Et(),me=!1,!Ne||ie&&!Z||(Ne=!1,Be())),(r||o||be||!t)&&(he=requestAnimationFrame(bt))}catch(e){pe=!0,Ge(e)}};function Tt(){!he&&yt()&&(fe=performance.now(),he=requestAnimationFrame(bt))}const wt=(e,n)=>{const r=t.getBoundingClientRect();if(!r.width||!r.height)return null;const i=(e-r.left)/r.width,o=(n-r.top)/r.height;return i<-.05||i>1.05||o<-.05||o>1.05?null:[i,1-o]},Mt=e=>{const t=M(g);if("none"===t||xe)return ye=null,void(ke.target=null);if("lantern"===t)return ke.target=e?[e[0],1-e[1]]:null,ye=null,void Tt();if("trail"===t){const t=Ce();if(!t)return;return e?t.move(e[0],1-e[1],g.trail.radius,performance.now()):t.leave(),ye=null,void Tt()}e?(ye&&(be=be?{from:be.from,to:e}:{from:ye,to:e}),ye=e,Tt()):ye=null},Rt=e=>Mt(wt(e.clientX,e.clientY)),Ft=()=>{ye=null,De?.leave(),ke.target&&(ke.target=null,Tt())},At=f.interactionTarget??window;At.addEventListener("pointermove",Rt,{passive:!0}),At.addEventListener("pointerdown",Rt,{passive:!0}),document.addEventListener("pointerleave",Ft),At!==window&&At.addEventListener("pointerleave",Ft);const kt="function"==typeof ResizeObserver?new ResizeObserver(()=>{const e=ut();Ae(),(e||me)&&Tt()}):null;kt?.observe(t),v&&kt?.observe(v.element);const Lt="function"==typeof IntersectionObserver?new IntersectionObserver(([e])=>{Ee=e.isIntersecting,Ee&&(me=!0,Tt())},{rootMargin:"120px"}):null;Lt?.observe(t);const Dt=()=>{document.hidden||(me=!0,Tt())};document.addEventListener("visibilitychange",Dt);const St=()=>{me=!0,Tt()};Ue?.addEventListener?.("change",St),tt?.addEventListener?.("loadingdone",it);const _t=e=>{e.preventDefault(),ge=!0,he&&cancelAnimationFrame(he),he=0},Ct=()=>{ge=!1,O.length=0,V=null,C=P=U=null,I=null,B=[],X=[],N=null,G=!1,Se=null,De=null,_e=!1;try{lt(),me=!0,Tt()}catch(e){Ge(e)}};t.addEventListener("webglcontextlost",_t),t.addEventListener("webglcontextrestored",Ct);const Pt=()=>{te&&(te.pause(),te.removeAttribute("src"),te.load(),te=null),ue&&Z instanceof HTMLVideoElement&&"cancelVideoFrameCallback"in Z&&Z.cancelVideoFrameCallback(ue),ue=0},Ut=()=>{oe?.close(),oe=null},It=async e=>{const t=await createImageBitmap(e,{premultiplyAlpha:"none"}),n=[t.width,t.height],r=function(e,t,n,r,i,o,a=8){if(!(n>=16&&r>=16&&e>0&&t>0&&i>0))return 1;const l=a/i/("cover"===o?Math.min(e/n,t/r):Math.max(e/n,t/r));return l>.5?1:2**-Math.floor(Math.log2(1/l))}(t.width,t.height,z,q,j.height,g.fit);if(1===r)return{element:t,owned:!0,natural:n};try{return{element:await createImageBitmap(t,{resizeWidth:Math.max(1,Math.round(t.width*r)),resizeHeight:Math.max(1,Math.round(t.height*r)),resizeQuality:"medium",premultiplyAlpha:"none"}),owned:!0,natural:n}}finally{t.close()}},Bt=e=>new Promise((t,n)=>{const r=new Image;r.crossOrigin="anonymous",r.decoding="async",r.onload=()=>t({element:r,owned:!1}),r.onerror=()=>n(new Error("The glyph field could not load this image.")),r.src=e}),Xt=async e=>{const t=++ie;if(!e)return Pt(),Ut(),Z=null,ne=re=ae=0,ee=!1,me=!0,void Tt();try{const n=await(async e=>{if("string"!=typeof e)return e instanceof HTMLImageElement&&!e.complete?e.decode().then(()=>({element:e,owned:!1})):e instanceof HTMLVideoElement&&e.readyState<2?new Promise((t,n)=>{e.addEventListener("loadeddata",()=>t({element:e,owned:!1}),{once:!0}),e.addEventListener("error",()=>n(new Error("The glyph field could not load this video.")),{once:!0})}):{element:e,owned:!1};if(A.test(e))return new Promise((t,n)=>{const r=document.createElement("video");r.crossOrigin="anonymous",r.muted=!0,r.loop=!0,r.playsInline=!0,r.preload="auto",r.addEventListener("loadeddata",()=>{r.play().catch(()=>{}),t({element:r,owned:!0})},{once:!0}),r.addEventListener("error",()=>n(new Error("The glyph field could not load this video.")),{once:!0}),r.src=e});if("function"!=typeof createImageBitmap||"function"!=typeof fetch)return Bt(e);let t;try{t=await(await fetch(e).then(e=>{if(!e.ok)throw new Error("The glyph field could not load this image.");return e})).blob()}catch(t){if(t instanceof Error&&t.message.startsWith("The glyph field"))throw t;return Bt(e)}if(!/svg/i.test(t.type))try{return await It(t)}catch{}const n=URL.createObjectURL(t);try{return await Bt(n)}finally{URL.revokeObjectURL(n)}})(e),{element:r,owned:i}=n;if(ve||t!==ie)return void(i&&r instanceof HTMLVideoElement?(r.pause(),r.removeAttribute("src"),r.load()):i&&r.close());Pt(),Ut(),te=i&&r instanceof HTMLVideoElement?r:null,!i||r instanceof HTMLVideoElement||(oe=r),Z=r,ee="string"==typeof e||e instanceof HTMLImageElement||e instanceof HTMLVideoElement,ae=r instanceof HTMLVideoElement?r.videoHeight:r instanceof HTMLImageElement?r.naturalHeight:r.height,ne=n.natural?.[0]??(r instanceof HTMLVideoElement?r.videoWidth:r instanceof HTMLImageElement?r.naturalWidth:r.width),re=n.natural?.[1]??ae,le=!0,r instanceof HTMLVideoElement&&(e=>{const t=e;if(!t.requestVideoFrameCallback)return;const n=()=>{ve||Z!==e||(le=!0,Tt(),ue=t.requestVideoFrameCallback(n))};ue=t.requestVideoFrameCallback(n)})(r),ge||at(),me=!0,Tt()}catch(e){Ne&&t===ie&&(Ne=!1,Be()),Ge(e)}};lt(),Ae();const Nt=f.source??null;return Nt?(ie=1,Xt(Nt)):Tt(),{canvas:t,ready:Xe,get settings(){return g},update(e){const n=g,{element:r,rest:i}=m(e);"clear"in e&&(v&&v.element!==r?.element&&kt?.unobserve(v.element),v=r,r&&kt?.observe(r.element)),g=E(r?{...i,clear:g.clear}:i,g),Ae(),e.label&&t.setAttribute("aria-label",e.label),g.maxPixelRatio!==n.maxPixelRatio&&ut(),g.charset===n.charset&&g.cellSize===n.cellSize&&g.cellAspect===n.cellAspect&&g.font===n.font&&g.fontWeight===n.fontWeight&&g.glyphScale===n.glyphScale||(et(),nt()),g.levels!==n.levels&&ot();((!!n.fluid&&"fluid"===M(n))!==je()||g.fluid&&n.fluid&&g.fluid.resolution!==n.fluid.resolution)&&Je(),"source"in e&&Xt(e.source??null),me=!0,Tt()},setSource:Xt,pointer(e,n=0){if(null===e)return void Mt(null);const r=t.getBoundingClientRect();Mt(wt(r.left+e,r.top+n))},redraw(){if(!(ve||ge||pe)&&z)try{ze(!0)&&Et()}catch(e){pe=!0,Ge(e)}},pulse(e={}){if(ve||Ie())return;const n=t.getBoundingClientRect();if(!n.width||!n.height)return;let r=e.x??n.width/2,i=e.y??n.height/2;if(e.element){const t=e.element.getBoundingClientRect();r=t.left+t.width/2-n.left,i=t.top+t.height/2-n.top}const o=Math.max(0,Math.min(2,e.strength??1));Re=[...Re,{x:r/n.width,y:i/n.height,born:performance.now(),strength:o}].slice(-4),Tt()},play(){xe=!1,Z instanceof HTMLVideoElement&&Z.play().catch(()=>{}),me=!0,Tt()},pause(){xe=!0,Z instanceof HTMLVideoElement&&Z.pause()},resize(){ut()&&Tt()},destroy(){if(!ve&&(ve=!0,he&&cancelAnimationFrame(he),At.removeEventListener("pointermove",Rt),At.removeEventListener("pointerdown",Rt),document.removeEventListener("pointerleave",Ft),At.removeEventListener("pointerleave",Ft),document.removeEventListener("visibilitychange",Dt),Ue?.removeEventListener?.("change",St),tt?.removeEventListener?.("loadingdone",it),t.removeEventListener("webglcontextlost",_t),t.removeEventListener("webglcontextrestored",Ct),kt?.disconnect(),Lt?.disconnect(),Pt(),Ut(),Z=null,!ge)){Ke(),We(),k.deleteTexture(S),k.deleteTexture(_);for(const e of[C,P,U])e&&k.deleteProgram(e.program);N?.dispose(),Se&&k.deleteTexture(Se),O.forEach(e=>k.deleteShader(e)),H&&k.deleteVertexArray(H)}}}},exports.normalizeFieldSettings=E;//# sourceMappingURL=field.cjs.map