asciify-engine 1.0.9 → 1.0.11
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/embed.js +1 -1
- package/dist/index.cjs +67 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.js +67 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/embed.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){'use strict';function et(
|
|
1
|
+
(function(){'use strict';function et(t){let l=atob(t),e=new Uint8Array(l.length);for(let a=0;a<l.length;a++)e[a]=l.charCodeAt(a);return e}function dt(t){return Array.isArray(t)?t.map(et):[et(t)]}function Mt(t,l,e,a){let r=t[0],n=1+(e*a+l)*r;if(r===3){let f=Math.round(.299*t[n]+.587*t[n+1]+.114*t[n+2]);return {r:t[n],g:t[n+1],b:t[n+2],a:255,l:f}}if(r===4){let f=Math.round(.299*t[n]+.587*t[n+1]+.114*t[n+2]);return {r:t[n],g:t[n+1],b:t[n+2],a:t[n+3],l:f}}return r===1?{r:t[n],g:t[n],b:t[n],l:t[n],a:255}:{r:t[n],g:t[n],b:t[n],l:t[n],a:t[n+1]}}function gt(t){return t*t*(3-2*t)}function bt(t,l){if(t==="fullcolor")return (e,a,r)=>`rgb(${e},${a},${r})`;if(t==="matrix")return (e,a,r)=>`rgb(0,${Math.floor(.299*e+.587*a+.114*r)},0)`;if(t==="accent"){let e=l.replace("#",""),a=parseInt(e.substring(0,2),16),r=parseInt(e.substring(2,4),16),n=parseInt(e.substring(4,6),16);return (f,y,i)=>{let s=(.299*f+.587*y+.114*i)/255;return `rgb(${Math.floor(a*s)},${Math.floor(r*s)},${Math.floor(n*s)})`}}return (e,a,r)=>{let n=Math.floor(.299*e+.587*a+.114*r);return `rgb(${n},${n},${n})`}}function pt(t,l,e,a,r,n,f){let y=l,i=f*y;switch(t){case "wave":{let s=Math.sin(e/r*Math.PI*4+i*3)*.5+.5,o=Math.sin(a/n*Math.PI*3+i*2)*.5+.5;return .3+.7*(s*.6+o*.4)}case "pulse":{let s=r/2,o=n/2,d=Math.sqrt((e-s)**2+(a-o)**2),h=Math.sqrt(s*s+o*o);return .2+.8*(Math.sin(d/h*Math.PI*6-i*4)*.5+.5)}case "rain":return .1+.9*(Math.sin(a/n*Math.PI*8-i*5+e*.3)*.5+.5)*(Math.sin(e/r*Math.PI*2+i)*.3+.7);case "breathe":return Math.max(.1,Math.min(1,Math.sin(i*2)*.3+.7+Math.sin((e+a)*.1+i)*.1));case "sparkle":{let s=Math.sin(e*127.1+a*311.7+Math.floor(i*8)*43758.5453)*43758.5453,o=s-Math.floor(s);return o>.7?1:.15+o*.4}case "glitch":{let s=Math.floor(a/(n*.05)),o=Math.sin(s*43.23+Math.floor(i*6)*17.89)*43758.5453;if(o-Math.floor(o)>.85){let h=Math.sin(i*30+s)*.5+.5;return h<.3?0:h}return 1}case "spiral":{let s=r/2,o=n/2,d=e-s,h=a-o,M=Math.atan2(h,d),I=Math.sqrt(d*d+h*h),F=Math.sqrt(s*s+o*o);return .15+.85*(Math.sin(M*3+I/F*Math.PI*8-i*3)*.5+.5)}case "typewriter":{let s=r*n,o=a*r+e,d=i*.5%1,h=d*s*1.3,M=o-h;return M>0?0:Math.min(1,Math.max(0,1+M/(s*.15)))}case "scatter":{let s=r/2,o=n/2,d=e-s,h=a-o,M=Math.sqrt(d*d+h*h)/Math.sqrt(s*s+o*o),I=Math.sin(i*1.5)*.5+.5;return M>I?Math.max(0,1-(M-I)*3):.7+.3*Math.sin(M*10-i*2)}default:return 1}}function at(t,l,e){let a=document.getElementById(t);if(!a){console.error(`Asciify: canvas #${t} not found`);return}let r=a.getContext("2d"),{r:n,c:f,w:y,h:i}=e,s=e.fps??10,o=e.cs??" .:-=+*#%@",d=e.cm??"grayscale",h=e.ac??"#ffffff",M=e.as??"none",I=e.sp??1,F=e.inv??false,m=e.hs??0,st=e.hr??.3,P=e.he??"spotlight",k=e.hc??"#ffffff",ot=e.dr??.7,it=e.dots??false,z=e.anim??false,ct=parseInt(k.slice(1,3),16)||255,lt=parseInt(k.slice(3,5),16)||255,ht=parseInt(k.slice(5,7),16)||255,$=y/f,E=i/n,K=dt(l),mt=bt(d,h),R=m>0,Q=M!=="none"||z,H=-1,U=-1,A=0,J=.5,W=.5,D=0,V=0;R&&(a.addEventListener("mousemove",S=>{let w=a.getBoundingClientRect();H=(S.clientX-w.left)/w.width,U=(S.clientY-w.top)/w.height;}),a.addEventListener("mouseleave",()=>{H=-1,U=-1;}));function N(S){let w=S/1e3;z&&S-V>=1e3/s&&(D=(D+1)%K.length,V=S);let ut=K[D];r.clearRect(0,0,y,i),r.fillStyle="#0a0a0a",r.fillRect(0,0,y,i),R&&(H>=0?(J+=(H-J)*.1,W+=(U-W)*.1,A+=(1-A)*.12):(A*=.96,A<.003&&(A=0)));for(let q=0;q<n;q++)for(let C=0;C<f;C++){let v=Mt(ut,C,q,f);if(v.a<10)continue;let X=pt(M,I,C,q,f,n,w);if(X<.05)continue;let O=1,Y=0,G=0,L=0,x=0;if(R&&A>.003){let u=C/f,g=q/n,b=u-J,p=g-W,tt=Math.sqrt(b*b+p*p),nt=.08+st*.35+m*.04;if(tt<nt){let ft=1-tt/nt,c=gt(ft)*A,T=Math.atan2(p,b);if(P==="spotlight"){O=1+c*m*1.8;let B=c*c*m*.6;Y=Math.cos(T)*B*$,G=Math.sin(T)*B*E,L=c*m*.4,x=c*c*m*.25;}else if(P==="magnify")O=1+c*m*2.5,L=c*m*.15;else if(P==="repel"){O=1+c*m*.3;let B=c*c*m*1.2;Y=Math.cos(T)*B*$,G=Math.sin(T)*B*E;}else P==="glow"?(L=c*m*.8,x=c*m*.4):P==="colorShift"&&(O=1+c*m*.4,L=c*m*.2,x=c*m*.7);}}let Z=C*$+$/2+Y,_=q*E+E/2+G,j=mt(v.r,v.g,v.b);if(x>0){let u=j.match(/rgb\((\d+),(\d+),(\d+)\)/);if(u){let g=+u[1],b=+u[2],p=+u[3];j=`rgb(${Math.min(255,Math.round(g+(ct-g)*x))},${Math.min(255,Math.round(b+(lt-b)*x))},${Math.min(255,Math.round(p+(ht-p)*x))})`;}}if(r.globalAlpha=Math.min(1,v.a/255*X*(1+L)),r.fillStyle=j,it){let u=v.l/255;if(F&&(u=1-u),u<.02)continue;let g=Math.min($,E)*.5*ot*u*X*O;if(g<.3)continue;r.beginPath(),r.arc(Z,_,g,0,Math.PI*2),r.fill();}else {let u=v.l/255;F&&(u=1-u);let g=Math.floor(u*(o.length-1)),b=o[Math.max(0,Math.min(o.length-1,g))];if(b===" ")continue;let p=Math.min($/.55,E)*.9*O;r.font=`${p}px "JetBrains Mono",monospace`,r.textAlign="center",r.textBaseline="middle",r.fillText(b,Z,_);}}r.globalAlpha=1,(Q||R)&&requestAnimationFrame(N);}Q||R?requestAnimationFrame(N):N(0);}window.Asciify=at;function rt(){document.querySelectorAll('canvas[id^="ar-"]').forEach(t=>{let l=t.id,e=document.getElementById(`${l}-d`),a=t.getAttribute("data-asciify-opts");if(!(!e||!a))try{let r=JSON.parse(a),n=JSON.parse(e.textContent||"");at(l,n,r);}catch(r){console.error("Asciify: failed to parse embed data for #"+l,r);}});}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",rt):rt();})();
|
package/dist/index.cjs
CHANGED
|
@@ -722,7 +722,7 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
|
|
|
722
722
|
function serializeFrame(frame, fullColor) {
|
|
723
723
|
const rows = frame.length;
|
|
724
724
|
const cols = rows > 0 ? frame[0].length : 0;
|
|
725
|
-
const stride = fullColor ?
|
|
725
|
+
const stride = fullColor ? 3 : 1;
|
|
726
726
|
const buf = new Uint8Array(1 + rows * cols * stride);
|
|
727
727
|
buf[0] = stride;
|
|
728
728
|
let i = 1;
|
|
@@ -733,10 +733,8 @@ function serializeFrame(frame, fullColor) {
|
|
|
733
733
|
buf[i++] = cell.r;
|
|
734
734
|
buf[i++] = cell.g;
|
|
735
735
|
buf[i++] = cell.b;
|
|
736
|
-
buf[i++] = cell.a;
|
|
737
736
|
} else {
|
|
738
737
|
buf[i++] = Math.round(0.299 * cell.r + 0.587 * cell.g + 0.114 * cell.b);
|
|
739
|
-
buf[i++] = cell.a;
|
|
740
738
|
}
|
|
741
739
|
}
|
|
742
740
|
}
|
|
@@ -834,7 +832,7 @@ async function asciifyVideo(source, canvas, { fontSize = 10, style = "classic",
|
|
|
834
832
|
cancelAnimationFrame(animId);
|
|
835
833
|
};
|
|
836
834
|
}
|
|
837
|
-
var EMBED_CDN_VERSION = "1.0.
|
|
835
|
+
var EMBED_CDN_VERSION = "1.0.11";
|
|
838
836
|
function buildEmbedOpts(options, rows, cols, width, height, fps, animated) {
|
|
839
837
|
const o = {
|
|
840
838
|
r: rows,
|
|
@@ -1001,6 +999,70 @@ function renderWaveBackground(ctx, width, height, time, mousePos = { x: 0.5, y:
|
|
|
1001
999
|
}
|
|
1002
1000
|
}
|
|
1003
1001
|
}
|
|
1002
|
+
function mountWaveBackground(target, options = {}) {
|
|
1003
|
+
const { opacity = 0.2, className, zIndex = 0, ...renderOpts } = options;
|
|
1004
|
+
const container = typeof target === "string" ? document.querySelector(target) : target;
|
|
1005
|
+
if (!container) {
|
|
1006
|
+
console.warn("[asciify] mountWaveBackground: target not found", target);
|
|
1007
|
+
return { destroy: () => {
|
|
1008
|
+
} };
|
|
1009
|
+
}
|
|
1010
|
+
const prevPosition = container.style.position;
|
|
1011
|
+
if (getComputedStyle(container).position === "static") {
|
|
1012
|
+
container.style.position = "relative";
|
|
1013
|
+
}
|
|
1014
|
+
const canvas = document.createElement("canvas");
|
|
1015
|
+
canvas.style.cssText = [
|
|
1016
|
+
"position:absolute",
|
|
1017
|
+
"inset:0",
|
|
1018
|
+
"width:100%",
|
|
1019
|
+
"height:100%",
|
|
1020
|
+
`opacity:${opacity}`,
|
|
1021
|
+
"pointer-events:none",
|
|
1022
|
+
`z-index:${zIndex}`
|
|
1023
|
+
].join(";");
|
|
1024
|
+
if (className) canvas.className = className;
|
|
1025
|
+
container.prepend(canvas);
|
|
1026
|
+
const ctx = canvas.getContext("2d");
|
|
1027
|
+
const dpr = window.devicePixelRatio || 1;
|
|
1028
|
+
const mouse = { x: 0.5, y: 0.5 };
|
|
1029
|
+
const smoothMouse = { x: 0.5, y: 0.5 };
|
|
1030
|
+
const resize = () => {
|
|
1031
|
+
const r = container.getBoundingClientRect();
|
|
1032
|
+
canvas.width = r.width * dpr;
|
|
1033
|
+
canvas.height = r.height * dpr;
|
|
1034
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
1035
|
+
};
|
|
1036
|
+
resize();
|
|
1037
|
+
const onMouseMove = (e) => {
|
|
1038
|
+
const r = container.getBoundingClientRect();
|
|
1039
|
+
mouse.x = (e.clientX - r.left) / r.width;
|
|
1040
|
+
mouse.y = (e.clientY - r.top) / r.height;
|
|
1041
|
+
};
|
|
1042
|
+
const ro = new ResizeObserver(resize);
|
|
1043
|
+
ro.observe(container);
|
|
1044
|
+
window.addEventListener("mousemove", onMouseMove);
|
|
1045
|
+
let time = 0;
|
|
1046
|
+
let raf = 0;
|
|
1047
|
+
const tick = () => {
|
|
1048
|
+
smoothMouse.x += (mouse.x - smoothMouse.x) * 0.07;
|
|
1049
|
+
smoothMouse.y += (mouse.y - smoothMouse.y) * 0.07;
|
|
1050
|
+
const r = container.getBoundingClientRect();
|
|
1051
|
+
renderWaveBackground(ctx, r.width, r.height, time, smoothMouse, renderOpts);
|
|
1052
|
+
time += 0.016;
|
|
1053
|
+
raf = requestAnimationFrame(tick);
|
|
1054
|
+
};
|
|
1055
|
+
raf = requestAnimationFrame(tick);
|
|
1056
|
+
return {
|
|
1057
|
+
destroy: () => {
|
|
1058
|
+
cancelAnimationFrame(raf);
|
|
1059
|
+
ro.disconnect();
|
|
1060
|
+
window.removeEventListener("mousemove", onMouseMove);
|
|
1061
|
+
canvas.remove();
|
|
1062
|
+
container.style.position = prevPosition;
|
|
1063
|
+
}
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1004
1066
|
|
|
1005
1067
|
// src/webgl-engine.ts
|
|
1006
1068
|
var VERT_SRC = (
|
|
@@ -1461,6 +1523,7 @@ exports.generateAnimatedEmbedCode = generateAnimatedEmbedCode;
|
|
|
1461
1523
|
exports.generateEmbedCode = generateEmbedCode;
|
|
1462
1524
|
exports.gifToAsciiFrames = gifToAsciiFrames;
|
|
1463
1525
|
exports.imageToAsciiFrame = imageToAsciiFrame;
|
|
1526
|
+
exports.mountWaveBackground = mountWaveBackground;
|
|
1464
1527
|
exports.renderFrameToCanvas = renderFrameToCanvas;
|
|
1465
1528
|
exports.renderWaveBackground = renderWaveBackground;
|
|
1466
1529
|
exports.tryCreateWebGLRenderer = tryCreateWebGLRenderer;
|