UNPKG

sixel

Version:

Sixel image format for node and browser.

3 lines 31.9 kB
/*! For license information please see encode.esm.js.LICENSE.txt */ var e={277:e=>{var t,r,n;e.exports=UPNG={},UPNG.toRGBA8=function(e){var t=e.width,r=e.height;if(null==e.tabs.acTL)return[UPNG.toRGBA8.decodeImage(e.data,t,r,e).buffer];var n=[];null==e.frames[0].data&&(e.frames[0].data=e.data);for(var i=t*r*4,a=new Uint8Array(i),o=new Uint8Array(i),f=new Uint8Array(i),s=0;s<e.frames.length;s++){var l=e.frames[s],u=l.rect.x,c=l.rect.y,h=l.rect.width,d=l.rect.height,g=UPNG.toRGBA8.decodeImage(l.data,h,d,e);if(0!=s)for(var U=0;U<i;U++)f[U]=a[U];if(0==l.blend?UPNG._copyTile(g,h,d,a,t,r,u,c,0):1==l.blend&&UPNG._copyTile(g,h,d,a,t,r,u,c,1),n.push(a.buffer.slice(0)),0==l.dispose);else if(1==l.dispose)UPNG._copyTile(o,h,d,a,t,r,u,c,0);else if(2==l.dispose)for(U=0;U<i;U++)a[U]=f[U]}return n},UPNG.toRGBA8.decodeImage=function(e,t,r,n){var i=t*r,a=UPNG.decode._getBPP(n),o=Math.ceil(t*a/8),f=new Uint8Array(4*i),s=new Uint32Array(f.buffer),l=n.ctype,u=n.depth,c=UPNG._bin.readUshort;if(Date.now(),6==l){var h=i<<2;if(8==u)for(var d=0;d<h;d+=4)f[d]=e[d],f[d+1]=e[d+1],f[d+2]=e[d+2],f[d+3]=e[d+3];if(16==u)for(d=0;d<h;d++)f[d]=e[d<<1]}else if(2==l){var g=n.tabs.tRNS;if(null==g){if(8==u)for(d=0;d<i;d++){var U=3*d;s[d]=255<<24|e[U+2]<<16|e[U+1]<<8|e[U]}if(16==u)for(d=0;d<i;d++)U=6*d,s[d]=255<<24|e[U+4]<<16|e[U+2]<<8|e[U]}else{var p=g[0],v=g[1],N=g[2];if(8==u)for(d=0;d<i;d++){var w=d<<2;U=3*d,s[d]=255<<24|e[U+2]<<16|e[U+1]<<8|e[U],e[U]==p&&e[U+1]==v&&e[U+2]==N&&(f[w+3]=0)}if(16==u)for(d=0;d<i;d++)w=d<<2,U=6*d,s[d]=255<<24|e[U+4]<<16|e[U+2]<<8|e[U],c(e,U)==p&&c(e,U+2)==v&&c(e,U+4)==N&&(f[w+3]=0)}}else if(3==l){var P=n.tabs.PLTE,b=n.tabs.tRNS,G=b?b.length:0;if(1==u)for(var y=0;y<r;y++){var m=y*o,A=y*t;for(d=0;d<t;d++){w=A+d<<2;var _=3*(I=e[m+(d>>3)]>>7-((7&d)<<0)&1);f[w]=P[_],f[w+1]=P[_+1],f[w+2]=P[_+2],f[w+3]=I<G?b[I]:255}}if(2==u)for(y=0;y<r;y++)for(m=y*o,A=y*t,d=0;d<t;d++)w=A+d<<2,_=3*(I=e[m+(d>>2)]>>6-((3&d)<<1)&3),f[w]=P[_],f[w+1]=P[_+1],f[w+2]=P[_+2],f[w+3]=I<G?b[I]:255;if(4==u)for(y=0;y<r;y++)for(m=y*o,A=y*t,d=0;d<t;d++)w=A+d<<2,_=3*(I=e[m+(d>>1)]>>4-((1&d)<<2)&15),f[w]=P[_],f[w+1]=P[_+1],f[w+2]=P[_+2],f[w+3]=I<G?b[I]:255;if(8==u)for(d=0;d<i;d++){var I;w=d<<2,_=3*(I=e[d]),f[w]=P[_],f[w+1]=P[_+1],f[w+2]=P[_+2],f[w+3]=I<G?b[I]:255}}else if(4==l){if(8==u)for(d=0;d<i;d++){w=d<<2;var x=e[T=d<<1];f[w]=x,f[w+1]=x,f[w+2]=x,f[w+3]=e[T+1]}if(16==u)for(d=0;d<i;d++){var T;w=d<<2,x=e[T=d<<2],f[w]=x,f[w+1]=x,f[w+2]=x,f[w+3]=e[T+2]}}else if(0==l)for(p=n.tabs.tRNS?n.tabs.tRNS:-1,y=0;y<r;y++){var M=y*o,H=y*t;if(1==u)for(var R=0;R<t;R++){var q=(x=255*(e[M+(R>>>3)]>>>7-(7&R)&1))==255*p?0:255;s[H+R]=q<<24|x<<16|x<<8|x}else if(2==u)for(R=0;R<t;R++)q=(x=85*(e[M+(R>>>2)]>>>6-((3&R)<<1)&3))==85*p?0:255,s[H+R]=q<<24|x<<16|x<<8|x;else if(4==u)for(R=0;R<t;R++)q=(x=17*(e[M+(R>>>1)]>>>4-((1&R)<<2)&15))==17*p?0:255,s[H+R]=q<<24|x<<16|x<<8|x;else if(8==u)for(R=0;R<t;R++)q=(x=e[M+R])==p?0:255,s[H+R]=q<<24|x<<16|x<<8|x;else if(16==u)for(R=0;R<t;R++)x=e[M+(R<<1)],q=c(e,M+(R<<d))==p?0:255,s[H+R]=q<<24|x<<16|x<<8|x}return f},UPNG.decode=function(e){for(var t,r=new Uint8Array(e),n=8,i=UPNG._bin,a=i.readUshort,o=i.readUint,f={tabs:{},frames:[]},s=new Uint8Array(r.length),l=0,u=0,c=[137,80,78,71,13,10,26,10],h=0;h<8;h++)if(r[h]!=c[h])throw"The input is not a PNG file!";for(;n<r.length;){var d=i.readUint(r,n);n+=4;var g=i.readASCII(r,n,4);if(n+=4,"IHDR"==g)UPNG.decode._IHDR(r,n,f);else if("CgBI"==g)f.tabs[g]=r.slice(n,n+4);else if("IDAT"==g){for(h=0;h<d;h++)s[l+h]=r[n+h];l+=d}else if("acTL"==g)f.tabs[g]={num_frames:o(r,n),num_plays:o(r,n+4)},t=new Uint8Array(r.length);else if("fcTL"==g){var U;0!=u&&((U=f.frames[f.frames.length-1]).data=UPNG.decode._decompress(f,t.slice(0,u),U.rect.width,U.rect.height),u=0);var p={x:o(r,n+12),y:o(r,n+16),width:o(r,n+4),height:o(r,n+8)},v=a(r,n+22);v=a(r,n+20)/(0==v?100:v);var N={rect:p,delay:Math.round(1e3*v),dispose:r[n+24],blend:r[n+25]};f.frames.push(N)}else if("fdAT"==g){for(h=0;h<d-4;h++)t[u+h]=r[n+h+4];u+=d-4}else if("pHYs"==g)f.tabs[g]=[i.readUint(r,n),i.readUint(r,n+4),r[n+8]];else if("cHRM"==g)for(f.tabs[g]=[],h=0;h<8;h++)f.tabs[g].push(i.readUint(r,n+4*h));else if("tEXt"==g||"zTXt"==g){null==f.tabs[g]&&(f.tabs[g]={});var w=i.nextZero(r,n),P=i.readASCII(r,n,w-n),b=n+d-w-1;if("tEXt"==g)m=i.readASCII(r,w+1,b);else{var G=UPNG.decode._inflate(r.slice(w+2,w+2+b));m=i.readUTF8(G,0,G.length)}f.tabs[g][P]=m}else if("iTXt"==g){null==f.tabs[g]&&(f.tabs[g]={}),w=0;var y=n;w=i.nextZero(r,y),P=i.readASCII(r,y,w-y);var m,A=r[y=w+1];r[y+1],y+=2,w=i.nextZero(r,y),i.readASCII(r,y,w-y),y=w+1,w=i.nextZero(r,y),i.readUTF8(r,y,w-y),b=d-((y=w+1)-n),0==A?m=i.readUTF8(r,y,b):(G=UPNG.decode._inflate(r.slice(y,y+b)),m=i.readUTF8(G,0,G.length)),f.tabs[g][P]=m}else if("PLTE"==g)f.tabs[g]=i.readBytes(r,n,d);else if("hIST"==g){var _=f.tabs.PLTE.length/3;for(f.tabs[g]=[],h=0;h<_;h++)f.tabs[g].push(a(r,n+2*h))}else if("tRNS"==g)3==f.ctype?f.tabs[g]=i.readBytes(r,n,d):0==f.ctype?f.tabs[g]=a(r,n):2==f.ctype&&(f.tabs[g]=[a(r,n),a(r,n+2),a(r,n+4)]);else if("gAMA"==g)f.tabs[g]=i.readUint(r,n)/1e5;else if("sRGB"==g)f.tabs[g]=r[n];else if("bKGD"==g)0==f.ctype||4==f.ctype?f.tabs[g]=[a(r,n)]:2==f.ctype||6==f.ctype?f.tabs[g]=[a(r,n),a(r,n+2),a(r,n+4)]:3==f.ctype&&(f.tabs[g]=r[n]);else if("IEND"==g)break;n+=d,i.readUint(r,n),n+=4}return 0!=u&&((U=f.frames[f.frames.length-1]).data=UPNG.decode._decompress(f,t.slice(0,u),U.rect.width,U.rect.height),u=0),f.data=UPNG.decode._decompress(f,s,f.width,f.height),delete f.compress,delete f.interlace,delete f.filter,f},UPNG.decode._decompress=function(e,t,r,n){Date.now();var i=UPNG.decode._getBPP(e),a=Math.ceil(r*i/8),o=new Uint8Array((a+1+e.interlace)*n);return t=e.tabs.CgBI?UPNG.inflateRaw(t,o):UPNG.decode._inflate(t,o),Date.now(),0==e.interlace?t=UPNG.decode._filterZero(t,e,0,r,n):1==e.interlace&&(t=UPNG.decode._readInterlace(t,e)),t},UPNG.decode._inflate=function(e,t){return UPNG.inflateRaw(new Uint8Array(e.buffer,2,e.length-6),t)},UPNG.inflateRaw=((n={}).H={},n.H.N=function(e,t){var r,i,a=Uint8Array,o=0,f=0,s=0,l=0,u=0,c=0,h=0,d=0,g=0;if(3==e[0]&&0==e[1])return t||new a(0);var U=n.H,p=U.b,v=U.e,N=U.R,w=U.n,P=U.A,b=U.Z,G=U.m,y=null==t;for(y&&(t=new a(e.length>>>2<<3));0==o;)if(o=p(e,g,1),f=p(e,g+1,2),g+=3,0!=f){if(y&&(t=n.H.W(t,d+(1<<17))),1==f&&(r=G.J,i=G.h,c=511,h=31),2==f){s=v(e,g,5)+257,l=v(e,g+5,5)+1,u=v(e,g+10,4)+4,g+=14;for(var m=1,A=0;A<38;A+=2)G.Q[A]=0,G.Q[A+1]=0;for(A=0;A<u;A++){var _=v(e,g+3*A,3);G.Q[1+(G.X[A]<<1)]=_,_>m&&(m=_)}g+=3*u,w(G.Q,m),P(G.Q,m,G.u),r=G.w,i=G.d,g=N(G.u,(1<<m)-1,s+l,e,g,G.v);var I=U.V(G.v,0,s,G.C);c=(1<<I)-1;var x=U.V(G.v,s,l,G.D);h=(1<<x)-1,w(G.C,I),P(G.C,I,r),w(G.D,x),P(G.D,x,i)}for(;;){var T=r[b(e,g)&c];g+=15&T;var M=T>>>4;if(M>>>8==0)t[d++]=M;else{if(256==M)break;var H=d+M-254;if(M>264){var R=G.q[M-257];H=d+(R>>>3)+v(e,g,7&R),g+=7&R}var q=i[b(e,g)&h];g+=15&q;var z=q>>>4,D=G.c[z],E=(D>>>4)+p(e,g,15&D);for(g+=15&D;d<H;)t[d]=t[d++-E],t[d]=t[d++-E],t[d]=t[d++-E],t[d]=t[d++-E];d=H}}}else{0!=(7&g)&&(g+=8-(7&g));var S=4+(g>>>3),B=e[S-4]|e[S-3]<<8;y&&(t=n.H.W(t,d+B)),t.set(new a(e.buffer,e.byteOffset+S,B),d),g=S+B<<3,d+=B}return t.length==d?t:t.slice(0,d)},n.H.W=function(e,t){var r=e.length;if(t<=r)return e;var n=new Uint8Array(r<<1);return n.set(e,0),n},n.H.R=function(e,t,r,i,a,o){for(var f=n.H.e,s=n.H.Z,l=0;l<r;){var u=e[s(i,a)&t];a+=15&u;var c=u>>>4;if(c<=15)o[l]=c,l++;else{var h=0,d=0;16==c?(d=3+f(i,a,2),a+=2,h=o[l-1]):17==c?(d=3+f(i,a,3),a+=3):18==c&&(d=11+f(i,a,7),a+=7);for(var g=l+d;l<g;)o[l]=h,l++}}return a},n.H.V=function(e,t,r,n){for(var i=0,a=0,o=n.length>>>1;a<r;){var f=e[a+t];n[a<<1]=0,n[1+(a<<1)]=f,f>i&&(i=f),a++}for(;a<o;)n[a<<1]=0,n[1+(a<<1)]=0,a++;return i},n.H.n=function(e,t){for(var r,i,a,o,f=n.H.m,s=e.length,l=f.j,u=0;u<=t;u++)l[u]=0;for(u=1;u<s;u+=2)l[e[u]]++;var c=f.K;for(r=0,l[0]=0,i=1;i<=t;i++)r=r+l[i-1]<<1,c[i]=r;for(a=0;a<s;a+=2)0!=(o=e[a+1])&&(e[a]=c[o],c[o]++)},n.H.A=function(e,t,r){for(var i=e.length,a=n.H.m.r,o=0;o<i;o+=2)if(0!=e[o+1])for(var f=o>>1,s=e[o+1],l=f<<4|s,u=t-s,c=e[o]<<u,h=c+(1<<u);c!=h;)r[a[c]>>>15-t]=l,c++},n.H.l=function(e,t){for(var r=n.H.m.r,i=15-t,a=0;a<e.length;a+=2){var o=e[a]<<t-e[a+1];e[a]=r[o]>>>i}},n.H.M=function(e,t,r){r<<=7&t;var n=t>>>3;e[n]|=r,e[n+1]|=r>>>8},n.H.I=function(e,t,r){r<<=7&t;var n=t>>>3;e[n]|=r,e[n+1]|=r>>>8,e[n+2]|=r>>>16},n.H.e=function(e,t,r){return(e[t>>>3]|e[1+(t>>>3)]<<8)>>>(7&t)&(1<<r)-1},n.H.b=function(e,t,r){return(e[t>>>3]|e[1+(t>>>3)]<<8|e[2+(t>>>3)]<<16)>>>(7&t)&(1<<r)-1},n.H.Z=function(e,t){return(e[t>>>3]|e[1+(t>>>3)]<<8|e[2+(t>>>3)]<<16)>>>(7&t)},n.H.i=function(e,t){return(e[t>>>3]|e[1+(t>>>3)]<<8|e[2+(t>>>3)]<<16|e[3+(t>>>3)]<<24)>>>(7&t)},n.H.m=(t=Uint16Array,r=Uint32Array,{K:new t(16),j:new t(16),X:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],S:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],T:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],q:new t(32),p:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],z:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],c:new r(32),J:new t(512),_:[],h:new t(32),$:[],w:new t(32768),C:[],v:[],d:new t(32768),D:[],u:new t(512),Q:[],r:new t(32768),s:new r(286),Y:new r(30),a:new r(19),t:new r(15e3),k:new t(65536),g:new t(32768)}),function(){for(var e=n.H.m,t=0;t<32768;t++){var r=t;r=(4278255360&(r=(4042322160&(r=(3435973836&(r=(2863311530&r)>>>1|(1431655765&r)<<1))>>>2|(858993459&r)<<2))>>>4|(252645135&r)<<4))>>>8|(16711935&r)<<8,e.r[t]=(r>>>16|r<<16)>>>17}function i(e,t,r){for(;0!=t--;)e.push(0,r)}for(t=0;t<32;t++)e.q[t]=e.S[t]<<3|e.T[t],e.c[t]=e.p[t]<<4|e.z[t];i(e._,144,8),i(e._,112,9),i(e._,24,7),i(e._,8,8),n.H.n(e._,9),n.H.A(e._,9,e.J),n.H.l(e._,9),i(e.$,32,5),n.H.n(e.$,5),n.H.A(e.$,5,e.h),n.H.l(e.$,5),i(e.Q,19,0),i(e.C,286,0),i(e.D,30,0),i(e.v,320,0)}(),n.H.N),UPNG.decode._readInterlace=function(e,t){for(var r=t.width,n=t.height,i=UPNG.decode._getBPP(t),a=i>>3,o=Math.ceil(r*i/8),f=new Uint8Array(n*o),s=0,l=[0,0,4,0,2,0,1],u=[0,4,0,2,0,1,0],c=[8,8,8,4,4,2,2],h=[8,8,4,4,2,2,1],d=0;d<7;){for(var g=c[d],U=h[d],p=0,v=0,N=l[d];N<n;)N+=g,v++;for(var w=u[d];w<r;)w+=U,p++;var P=Math.ceil(p*i/8);UPNG.decode._filterZero(e,t,s,p,v);for(var b=0,G=l[d];G<n;){for(var y=u[d],m=s+b*P<<3;y<r;){var A;if(1==i&&(A=(A=e[m>>3])>>7-(7&m)&1,f[G*o+(y>>3)]|=A<<7-((7&y)<<0)),2==i&&(A=(A=e[m>>3])>>6-(7&m)&3,f[G*o+(y>>2)]|=A<<6-((3&y)<<1)),4==i&&(A=(A=e[m>>3])>>4-(7&m)&15,f[G*o+(y>>1)]|=A<<4-((1&y)<<2)),i>=8)for(var _=G*o+y*a,I=0;I<a;I++)f[_+I]=e[(m>>3)+I];m+=i,y+=U}b++,G+=g}p*v!=0&&(s+=v*(1+P)),d+=1}return f},UPNG.decode._getBPP=function(e){return[1,null,3,1,2,null,4][e.ctype]*e.depth},UPNG.decode._filterZero=function(e,t,r,n,i){var a=UPNG.decode._getBPP(t),o=Math.ceil(n*a/8),f=UPNG.decode._paeth;a=Math.ceil(a/8);var s=0,l=1,u=e[r],c=0;if(u>1&&(e[r]=[0,0,1][u-2]),3==u)for(c=a;c<o;c++)e[c+1]=e[c+1]+(e[c+1-a]>>>1)&255;for(var h=0;h<i;h++)if(c=0,0==(u=e[(l=(s=r+h*o)+h+1)-1]))for(;c<o;c++)e[s+c]=e[l+c];else if(1==u){for(;c<a;c++)e[s+c]=e[l+c];for(;c<o;c++)e[s+c]=e[l+c]+e[s+c-a]}else if(2==u)for(;c<o;c++)e[s+c]=e[l+c]+e[s+c-o];else if(3==u){for(;c<a;c++)e[s+c]=e[l+c]+(e[s+c-o]>>>1);for(;c<o;c++)e[s+c]=e[l+c]+(e[s+c-o]+e[s+c-a]>>>1)}else{for(;c<a;c++)e[s+c]=e[l+c]+f(0,e[s+c-o],0);for(;c<o;c++)e[s+c]=e[l+c]+f(e[s+c-a],e[s+c-o],e[s+c-a-o])}return e},UPNG.decode._paeth=function(e,t,r){var n=e+t-r,i=n-e,a=n-t,o=n-r;return i*i<=a*a&&i*i<=o*o?e:a*a<=o*o?t:r},UPNG.decode._IHDR=function(e,t,r){var n=UPNG._bin;r.width=n.readUint(e,t),t+=4,r.height=n.readUint(e,t),t+=4,r.depth=e[t],t++,r.ctype=e[t],t++,r.compress=e[t],t++,r.filter=e[t],t++,r.interlace=e[t],t++},UPNG._bin={nextZero:function(e,t){for(;0!=e[t];)t++;return t},readUshort:function(e,t){return e[t]<<8|e[t+1]},writeUshort:function(e,t,r){e[t]=r>>8&255,e[t+1]=255&r},readUint:function(e,t){return 16777216*e[t]+(e[t+1]<<16|e[t+2]<<8|e[t+3])},writeUint:function(e,t,r){e[t]=r>>24&255,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=255&r},readASCII:function(e,t,r){for(var n="",i=0;i<r;i++)n+=String.fromCharCode(e[t+i]);return n},writeASCII:function(e,t,r){for(var n=0;n<r.length;n++)e[t+n]=r.charCodeAt(n)},readBytes:function(e,t,r){for(var n=[],i=0;i<r;i++)n.push(e[t+i]);return n},pad:function(e){return e.length<2?"0"+e:e},readUTF8:function(e,t,r){for(var n,i="",a=0;a<r;a++)i+="%"+UPNG._bin.pad(e[t+a].toString(16));try{n=decodeURIComponent(i)}catch(n){return UPNG._bin.readASCII(e,t,r)}return n}},UPNG._copyTile=function(e,t,r,n,i,a,o,f,s){for(var l=Math.min(t,i),u=Math.min(r,a),c=0,h=0,d=0;d<u;d++)for(var g=0;g<l;g++)if(o>=0&&f>=0?(c=d*t+g<<2,h=(f+d)*i+o+g<<2):(c=(-f+d)*t-o+g<<2,h=d*i+g<<2),0==s)n[h]=e[c],n[h+1]=e[c+1],n[h+2]=e[c+2],n[h+3]=e[c+3];else if(1==s){var U=e[c+3]*(1/255),p=e[c]*U,v=e[c+1]*U,N=e[c+2]*U,w=n[h+3]*(1/255),P=n[h]*w,b=n[h+1]*w,G=n[h+2]*w,y=1-U,m=U+w*y,A=0==m?0:1/m;n[h+3]=255*m,n[h+0]=(p+P*y)*A,n[h+1]=(v+b*y)*A,n[h+2]=(N+G*y)*A}else if(2==s)U=e[c+3],p=e[c],v=e[c+1],N=e[c+2],w=n[h+3],P=n[h],b=n[h+1],G=n[h+2],U==w&&p==P&&v==b&&N==G?(n[h]=0,n[h+1]=0,n[h+2]=0,n[h+3]=0):(n[h]=p,n[h+1]=v,n[h+2]=N,n[h+3]=U);else if(3==s){if(U=e[c+3],p=e[c],v=e[c+1],N=e[c+2],w=n[h+3],P=n[h],b=n[h+1],G=n[h+2],U==w&&p==P&&v==b&&N==G)continue;if(U<220&&w>20)return!1}return!0},UPNG.encode=function(e,t,r,n,i,a,o){null==n&&(n=0),null==o&&(o=!1);var f=UPNG.encode.compress(e,t,r,n,[!1,!1,!1,0,o]);return UPNG.encode.compressPNG(f,-1),UPNG.encode._main(f,t,r,i,a)},UPNG.encodeLL=function(e,t,r,n,i,a,o,f){for(var s={ctype:0+(1==n?0:2)+(0==i?0:4),depth:a,frames:[]},l=(Date.now(),(n+i)*a),u=l*t,c=0;c<e.length;c++)s.frames.push({rect:{x:0,y:0,width:t,height:r},img:new Uint8Array(e[c]),blend:0,dispose:1,bpp:Math.ceil(l/8),bpl:Math.ceil(u/8)});return UPNG.encode.compressPNG(s,0,!0),UPNG.encode._main(s,t,r,o,f)},UPNG.encode._main=function(e,t,r,n,i){null==i&&(i={});var a=UPNG.crc.crc,o=UPNG._bin.writeUint,f=UPNG._bin.writeUshort,s=UPNG._bin.writeASCII,l=8,u=e.frames.length>1,c=!1,h=33+(u?20:0);if(null!=i.sRGB&&(h+=13),null!=i.pHYs&&(h+=21),3==e.ctype){for(var d=e.plte.length,g=0;g<d;g++)e.plte[g]>>>24!=255&&(c=!0);h+=8+3*d+4+(c?8+1*d+4:0)}for(var U=0;U<e.frames.length;U++)u&&(h+=38),h+=(m=e.frames[U]).cimg.length+12,0!=U&&(h+=4);h+=12;var p=new Uint8Array(h),v=[137,80,78,71,13,10,26,10];for(g=0;g<8;g++)p[g]=v[g];if(o(p,l,13),s(p,l+=4,"IHDR"),o(p,l+=4,t),o(p,l+=4,r),p[l+=4]=e.depth,p[++l]=e.ctype,p[++l]=0,p[++l]=0,p[++l]=0,o(p,++l,a(p,l-17,17)),l+=4,null!=i.sRGB&&(o(p,l,1),s(p,l+=4,"sRGB"),p[l+=4]=i.sRGB,o(p,++l,a(p,l-5,5)),l+=4),null!=i.pHYs&&(o(p,l,9),s(p,l+=4,"pHYs"),o(p,l+=4,i.pHYs[0]),o(p,l+=4,i.pHYs[1]),p[l+=4]=i.pHYs[2],o(p,++l,a(p,l-13,13)),l+=4),u&&(o(p,l,8),s(p,l+=4,"acTL"),o(p,l+=4,e.frames.length),o(p,l+=4,null!=i.loop?i.loop:0),o(p,l+=4,a(p,l-12,12)),l+=4),3==e.ctype){for(o(p,l,3*(d=e.plte.length)),s(p,l+=4,"PLTE"),l+=4,g=0;g<d;g++){var N=3*g,w=e.plte[g],P=255&w,b=w>>>8&255,G=w>>>16&255;p[l+N+0]=P,p[l+N+1]=b,p[l+N+2]=G}if(o(p,l+=3*d,a(p,l-3*d-4,3*d+4)),l+=4,c){for(o(p,l,d),s(p,l+=4,"tRNS"),l+=4,g=0;g<d;g++)p[l+g]=e.plte[g]>>>24&255;o(p,l+=d,a(p,l-d-4,d+4)),l+=4}}var y=0;for(U=0;U<e.frames.length;U++){var m=e.frames[U];u&&(o(p,l,26),s(p,l+=4,"fcTL"),o(p,l+=4,y++),o(p,l+=4,m.rect.width),o(p,l+=4,m.rect.height),o(p,l+=4,m.rect.x),o(p,l+=4,m.rect.y),f(p,l+=4,n[U]),f(p,l+=2,1e3),p[l+=2]=m.dispose,p[++l]=m.blend,o(p,++l,a(p,l-30,30)),l+=4);var A=m.cimg;o(p,l,(d=A.length)+(0==U?0:4));var _=l+=4;s(p,l,0==U?"IDAT":"fdAT"),l+=4,0!=U&&(o(p,l,y++),l+=4),p.set(A,l),o(p,l+=d,a(p,_,l-_)),l+=4}return o(p,l,0),s(p,l+=4,"IEND"),o(p,l+=4,a(p,l-4,4)),l+=4,p.buffer},UPNG.encode.compressPNG=function(e,t,r){for(var n=0;n<e.frames.length;n++){var i=e.frames[n],a=(i.rect.width,i.rect.height),o=new Uint8Array(a*i.bpl+a);i.cimg=UPNG.encode._filterZero(i.img,a,i.bpp,i.bpl,o,t,r)}},UPNG.encode.compress=function(e,t,r,n,i){for(var a=i[0],o=i[1],f=i[2],s=i[3],l=i[4],u=6,c=8,h=255,d=0;d<e.length;d++)for(var g=new Uint8Array(e[d]),U=g.length,p=0;p<U;p+=4)h&=g[p+3];var v=255!=h,N=UPNG.encode.framize(e,t,r,a,o,f),w={},P=[],b=[];if(0!=n){var G=[];for(p=0;p<N.length;p++)G.push(N[p].img.buffer);var y=UPNG.encode.concatRGBA(G),m=UPNG.quantize(y,n);console.log(m);var A=0,_=new Uint8Array(m.abuf);for(p=0;p<N.length;p++){var I=(X=N[p].img).length;for(b.push(new Uint8Array(m.inds.buffer,A>>2,I>>2)),d=0;d<I;d+=4)X[d]=_[A+d],X[d+1]=_[A+d+1],X[d+2]=_[A+d+2],X[d+3]=_[A+d+3];A+=I}for(p=0;p<m.plte.length;p++)P.push(m.plte[p].est.rgba)}else for(d=0;d<N.length;d++){var x=N[d],T=new Uint32Array(x.img.buffer),M=x.rect.width,H=(U=T.length,new Uint8Array(U));for(b.push(H),p=0;p<U;p++){var R=T[p];if(0!=p&&R==T[p-1])H[p]=H[p-1];else if(p>M&&R==T[p-M])H[p]=H[p-M];else{var q=w[R];if(null==q&&(w[R]=q=P.length,P.push(R),P.length>=300))break;H[p]=q}}}var z=P.length;for(z<=256&&0==l&&(c=z<=2?1:z<=4?2:z<=16?4:8,c=Math.max(c,s)),d=0;d<N.length;d++){(x=N[d]).rect.x,x.rect.y,M=x.rect.width;var D=x.rect.height,E=x.img,S=(new Uint32Array(E.buffer),4*M),B=4;if(z<=256&&0==l){S=Math.ceil(c*M/8);for(var C=new Uint8Array(S*D),L=b[d],$=0;$<D;$++){p=$*S;var Z=$*M;if(8==c)for(var j=0;j<M;j++)C[p+j]=L[Z+j];else if(4==c)for(j=0;j<M;j++)C[p+(j>>1)]|=L[Z+j]<<4-4*(1&j);else if(2==c)for(j=0;j<M;j++)C[p+(j>>2)]|=L[Z+j]<<6-2*(3&j);else if(1==c)for(j=0;j<M;j++)C[p+(j>>3)]|=L[Z+j]<<7-1*(7&j)}E=C,u=3,B=1}else if(0==v&&1==N.length){C=new Uint8Array(M*D*3);var F=M*D;for(p=0;p<F;p++){var X,O=4*p;C[X=3*p]=E[O],C[X+1]=E[O+1],C[X+2]=E[O+2]}E=C,u=2,B=3,S=3*M}x.img=E,x.bpl=S,x.bpp=B}return{ctype:u,depth:c,plte:P,frames:N}},UPNG.encode.framize=function(e,t,r,n,i,a){for(var o=[],f=0;f<e.length;f++){var s,l=new Uint8Array(e[f]),u=new Uint32Array(l.buffer),c=0,h=0,d=t,g=r,U=n?1:0;if(0!=f){for(var p=a||n||1==f||0!=o[f-2].dispose?1:2,v=0,N=1e9,w=0;w<p;w++){for(var P=new Uint8Array(e[f-1-w]),b=new Uint32Array(e[f-1-w]),G=t,y=r,m=-1,A=-1,_=0;_<r;_++)for(var I=0;I<t;I++)u[z=_*t+I]!=b[z]&&(I<G&&(G=I),I>m&&(m=I),_<y&&(y=_),_>A&&(A=_));-1==m&&(G=y=m=A=0),i&&(1==(1&G)&&G--,1==(1&y)&&y--);var x=(m-G+1)*(A-y+1);x<N&&(N=x,v=w,c=G,h=y,d=m-G+1,g=A-y+1)}P=new Uint8Array(e[f-1-v]),1==v&&(o[f-1].dispose=2),s=new Uint8Array(d*g*4),UPNG._copyTile(P,t,r,s,d,g,-c,-h,0),1==(U=UPNG._copyTile(l,t,r,s,d,g,-c,-h,3)?1:0)?UPNG.encode._prepareDiff(l,t,r,s,{x:c,y:h,width:d,height:g}):UPNG._copyTile(l,t,r,s,d,g,-c,-h,0)}else s=l.slice(0);o.push({rect:{x:c,y:h,width:d,height:g},img:s,blend:U,dispose:0})}if(n)for(f=0;f<o.length;f++)if(1!=(D=o[f]).blend){var T=D.rect,M=o[f-1].rect,H=Math.min(T.x,M.x),R=Math.min(T.y,M.y),q={x:H,y:R,width:Math.max(T.x+T.width,M.x+M.width)-H,height:Math.max(T.y+T.height,M.y+M.height)-R};o[f-1].dispose=1,f-1!=0&&UPNG.encode._updateFrame(e,t,r,o,f-1,q,i),UPNG.encode._updateFrame(e,t,r,o,f,q,i)}if(1!=e.length)for(var z=0;z<o.length;z++){var D;(D=o[z]).rect.width,D.rect.height}return o},UPNG.encode._updateFrame=function(e,t,r,n,i,a,o){for(var f=Uint8Array,s=Uint32Array,l=new f(e[i-1]),u=new s(e[i-1]),c=i+1<e.length?new f(e[i+1]):null,h=new f(e[i]),d=new s(h.buffer),g=t,U=r,p=-1,v=-1,N=0;N<a.height;N++)for(var w=0;w<a.width;w++){var P=a.x+w,b=a.y+N,G=b*t+P,y=d[G];0==y||0==n[i-1].dispose&&u[G]==y&&(null==c||0!=c[4*G+3])||(P<g&&(g=P),P>p&&(p=P),b<U&&(U=b),b>v&&(v=b))}-1==p&&(g=U=p=v=0),o&&(1==(1&g)&&g--,1==(1&U)&&U--),a={x:g,y:U,width:p-g+1,height:v-U+1};var m=n[i];m.rect=a,m.blend=1,m.img=new Uint8Array(a.width*a.height*4),0==n[i-1].dispose?(UPNG._copyTile(l,t,r,m.img,a.width,a.height,-a.x,-a.y,0),UPNG.encode._prepareDiff(h,t,r,m.img,a)):UPNG._copyTile(h,t,r,m.img,a.width,a.height,-a.x,-a.y,0)},UPNG.encode._prepareDiff=function(e,t,r,n,i){UPNG._copyTile(e,t,r,n,i.width,i.height,-i.x,-i.y,2)},UPNG.encode._filterZero=function(e,t,r,n,i,a,o){var f,s=[],l=[0,1,2,3,4];-1!=a?l=[a]:(t*n>5e5||1==r)&&(l=[0]),o&&(f={level:0});for(var u=i.length>1e7&&null!=UZIP?UZIP:pako,c=(Date.now(),0);c<l.length;c++){for(var h=0;h<t;h++)UPNG.encode._filterLine(i,e,h,n,r,l[c]);s.push(u.deflate(i,f))}var d,g=1e9;for(c=0;c<s.length;c++)s[c].length<g&&(d=c,g=s[c].length);return s[d]},UPNG.encode._filterLine=function(e,t,r,n,i,a){var o=r*n,f=o+r,s=UPNG.decode._paeth;if(e[f]=a,f++,0==a)if(n<500)for(var l=0;l<n;l++)e[f+l]=t[o+l];else e.set(new Uint8Array(t.buffer,o,n),f);else if(1==a){for(l=0;l<i;l++)e[f+l]=t[o+l];for(l=i;l<n;l++)e[f+l]=t[o+l]-t[o+l-i]+256&255}else if(0==r){for(l=0;l<i;l++)e[f+l]=t[o+l];if(2==a)for(l=i;l<n;l++)e[f+l]=t[o+l];if(3==a)for(l=i;l<n;l++)e[f+l]=t[o+l]-(t[o+l-i]>>1)+256&255;if(4==a)for(l=i;l<n;l++)e[f+l]=t[o+l]-s(t[o+l-i],0,0)+256&255}else{if(2==a)for(l=0;l<n;l++)e[f+l]=t[o+l]+256-t[o+l-n]&255;if(3==a){for(l=0;l<i;l++)e[f+l]=t[o+l]+256-(t[o+l-n]>>1)&255;for(l=i;l<n;l++)e[f+l]=t[o+l]+256-(t[o+l-n]+t[o+l-i]>>1)&255}if(4==a){for(l=0;l<i;l++)e[f+l]=t[o+l]+256-s(0,t[o+l-n],0)&255;for(l=i;l<n;l++)e[f+l]=t[o+l]+256-s(t[o+l-i],t[o+l-n],t[o+l-i-n])&255}}},UPNG.crc={table:function(){for(var e=new Uint32Array(256),t=0;t<256;t++){for(var r=t,n=0;n<8;n++)1&r?r=3988292384^r>>>1:r>>>=1;e[t]=r}return e}(),update:function(e,t,r,n){for(var i=0;i<n;i++)e=UPNG.crc.table[255&(e^t[r+i])]^e>>>8;return e},crc:function(e,t,r){return 4294967295^UPNG.crc.update(4294967295,e,t,r)}},UPNG.quantize=function(e,t){var r,n=new Uint8Array(e),i=n.slice(0),a=new Uint32Array(i.buffer),o=UPNG.quantize.getKDtree(i,t),f=o[0],s=o[1],l=UPNG.quantize.planeDst,u=n,c=a,h=u.length,d=new Uint8Array(n.length>>2);if(n.length<2e7)for(var g=0;g<h;g+=4){var U=u[g]*(1/255),p=u[g+1]*(1/255),v=u[g+2]*(1/255),N=u[g+3]*(1/255);r=UPNG.quantize.getNearest(f,U,p,v,N),d[g>>2]=r.ind,c[g>>2]=r.est.rgba}else for(g=0;g<h;g+=4){for(U=u[g]*(1/255),p=u[g+1]*(1/255),v=u[g+2]*(1/255),N=u[g+3]*(1/255),r=f;r.left;)r=l(r.est,U,p,v,N)<=0?r.left:r.right;d[g>>2]=r.ind,c[g>>2]=r.est.rgba}return{abuf:i.buffer,inds:d,plte:s}},UPNG.quantize.getKDtree=function(e,t,r){null==r&&(r=1e-4);var n=new Uint32Array(e.buffer),i={i0:0,i1:e.length,bst:null,est:null,tdst:0,left:null,right:null};i.bst=UPNG.quantize.stats(e,i.i0,i.i1),i.est=UPNG.quantize.estats(i.bst);for(var a=[i];a.length<t;){for(var o=0,f=0,s=0;s<a.length;s++)a[s].est.L>o&&(o=a[s].est.L,f=s);if(o<r)break;var l=a[f],u=UPNG.quantize.splitPixels(e,n,l.i0,l.i1,l.est.e,l.est.eMq255);if(l.i0>=u||l.i1<=u)l.est.L=0;else{var c={i0:l.i0,i1:u,bst:null,est:null,tdst:0,left:null,right:null};c.bst=UPNG.quantize.stats(e,c.i0,c.i1),c.est=UPNG.quantize.estats(c.bst);var h={i0:u,i1:l.i1,bst:null,est:null,tdst:0,left:null,right:null};for(h.bst={R:[],m:[],N:l.bst.N-c.bst.N},s=0;s<16;s++)h.bst.R[s]=l.bst.R[s]-c.bst.R[s];for(s=0;s<4;s++)h.bst.m[s]=l.bst.m[s]-c.bst.m[s];h.est=UPNG.quantize.estats(h.bst),l.left=c,l.right=h,a[f]=c,a.push(h)}}for(a.sort((function(e,t){return t.bst.N-e.bst.N})),s=0;s<a.length;s++)a[s].ind=s;return[i,a]},UPNG.quantize.getNearest=function(e,t,r,n,i){if(null==e.left)return e.tdst=UPNG.quantize.dist(e.est.q,t,r,n,i),e;var a=UPNG.quantize.planeDst(e.est,t,r,n,i),o=e.left,f=e.right;a>0&&(o=e.right,f=e.left);var s=UPNG.quantize.getNearest(o,t,r,n,i);if(s.tdst<=a*a)return s;var l=UPNG.quantize.getNearest(f,t,r,n,i);return l.tdst<s.tdst?l:s},UPNG.quantize.planeDst=function(e,t,r,n,i){var a=e.e;return a[0]*t+a[1]*r+a[2]*n+a[3]*i-e.eMq},UPNG.quantize.dist=function(e,t,r,n,i){var a=t-e[0],o=r-e[1],f=n-e[2],s=i-e[3];return a*a+o*o+f*f+s*s},UPNG.quantize.splitPixels=function(e,t,r,n,i,a){var o=UPNG.quantize.vecDot;for(n-=4;r<n;){for(;o(e,r,i)<=a;)r+=4;for(;o(e,n,i)>a;)n-=4;if(r>=n)break;var f=t[r>>2];t[r>>2]=t[n>>2],t[n>>2]=f,r+=4,n-=4}for(;o(e,r,i)>a;)r-=4;return r+4},UPNG.quantize.vecDot=function(e,t,r){return e[t]*r[0]+e[t+1]*r[1]+e[t+2]*r[2]+e[t+3]*r[3]},UPNG.quantize.stats=function(e,t,r){for(var n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],i=[0,0,0,0],a=r-t>>2,o=t;o<r;o+=4){var f=e[o]*(1/255),s=e[o+1]*(1/255),l=e[o+2]*(1/255),u=e[o+3]*(1/255);i[0]+=f,i[1]+=s,i[2]+=l,i[3]+=u,n[0]+=f*f,n[1]+=f*s,n[2]+=f*l,n[3]+=f*u,n[5]+=s*s,n[6]+=s*l,n[7]+=s*u,n[10]+=l*l,n[11]+=l*u,n[15]+=u*u}return n[4]=n[1],n[8]=n[2],n[9]=n[6],n[12]=n[3],n[13]=n[7],n[14]=n[11],{R:n,m:i,N:a}},UPNG.quantize.estats=function(e){var t=e.R,r=e.m,n=e.N,i=r[0],a=r[1],o=r[2],f=r[3],s=0==n?0:1/n,l=[t[0]-i*i*s,t[1]-i*a*s,t[2]-i*o*s,t[3]-i*f*s,t[4]-a*i*s,t[5]-a*a*s,t[6]-a*o*s,t[7]-a*f*s,t[8]-o*i*s,t[9]-o*a*s,t[10]-o*o*s,t[11]-o*f*s,t[12]-f*i*s,t[13]-f*a*s,t[14]-f*o*s,t[15]-f*f*s],u=l,c=UPNG.M4,h=[.5,.5,.5,.5],d=0,g=0;if(0!=n)for(var U=0;U<16&&(h=c.multVec(u,h),g=Math.sqrt(c.dot(h,h)),h=c.sml(1/g,h),!(0!=U&&Math.abs(g-d)<1e-9));U++)d=g;var p=[i*s,a*s,o*s,f*s];return{Cov:l,q:p,e:h,L:d,eMq255:c.dot(c.sml(255,p),h),eMq:c.dot(h,p),rgba:(Math.round(255*p[3])<<24|Math.round(255*p[2])<<16|Math.round(255*p[1])<<8|Math.round(255*p[0])<<0)>>>0}},UPNG.M4={multVec:function(e,t){return[e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],e[4]*t[0]+e[5]*t[1]+e[6]*t[2]+e[7]*t[3],e[8]*t[0]+e[9]*t[1]+e[10]*t[2]+e[11]*t[3],e[12]*t[0]+e[13]*t[1]+e[14]*t[2]+e[15]*t[3]]},dot:function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]},sml:function(e,t){return[e*t[0],e*t[1],e*t[2],e*t[3]]}},UPNG.encode.concatRGBA=function(e){for(var t=0,r=0;r<e.length;r++)t+=e[r].byteLength;var n=new Uint8Array(t),i=0;for(r=0;r<e.length;r++){for(var a=new Uint8Array(e[r]),o=a.length,f=0;f<o;f+=4){var s=a[f],l=a[f+1],u=a[f+2],c=a[f+3];0==c&&(s=l=u=0),n[i+f]=s,n[i+f+1]=l,n[i+f+2]=u,n[i+f+3]=c}i+=o}return n.buffer}}},t={};function r(n){var i=t[n];if(void 0!==i)return i.exports;var a=t[n]={exports:{}};return e[n](a,a.exports,r),a.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var n={};(()=>{function e(e){return 255&e}function t(e){return e>>>8&255}function i(e){return e>>>16&255}function a(e){return e>>>24&255}function o(e,t,r,n=255){return((255&n)<<24|(255&r)<<16|(255&t)<<8|255&e)>>>0}function f(e){return[255&e,e>>8&255,e>>16&255,e>>>24]}function s(r,n){const a=e(r),o=t(r),f=i(r);let s=Number.MAX_SAFE_INTEGER,l=-1;for(let e=0;e<n.length;++e){const t=a-n[e][0],r=o-n[e][1],i=f-n[e][2],u=t*t+r*r+i*i;if(!u)return e;u<s&&(s=u,l=e)}return l}function l(e,t,r){return(4278190080|Math.round(r/100*255)<<16|Math.round(t/100*255)<<8|Math.round(e/100*255))>>>0}r.d(n,{uO:()=>N,xq:()=>h,Zl:()=>u,Aj:()=>c,gp:()=>f,n2:()=>y,Dz:()=>v,Xz:()=>b,m1:()=>o}),255===new Uint8Array(new Uint32Array([4278190080]).buffer)[0]&&console.warn("BE platform detected. This version of node-sixel works only on LE properly.");const u=new Uint32Array([l(0,0,0),l(20,20,80),l(80,13,13),l(20,80,20),l(80,20,80),l(20,80,80),l(80,80,20),l(53,53,53),l(26,26,26),l(33,33,60),l(60,26,26),l(33,60,33),l(60,33,60),l(33,60,60),l(60,60,33),l(80,80,80)]),c=new Uint32Array([l(0,0,0),l(13,13,13),l(26,26,26),l(40,40,40),l(6,6,6),l(20,20,20),l(33,33,33),l(46,46,46),l(0,0,0),l(13,13,13),l(26,26,26),l(40,40,40),l(6,6,6),l(20,20,20),l(33,33,33),l(46,46,46)]),h=(()=>{const e=[o(0,0,0),o(205,0,0),o(0,205,0),o(205,205,0),o(0,0,238),o(205,0,205),o(0,250,205),o(229,229,229),o(127,127,127),o(255,0,0),o(0,255,0),o(255,255,0),o(92,92,255),o(255,0,255),o(0,255,255),o(255,255,255)],t=[0,95,135,175,215,255];for(let r=0;r<6;++r)for(let n=0;n<6;++n)for(let i=0;i<6;++i)e.push(o(t[r],t[n],t[i]));for(let t=8;t<=238;t+=10)e.push(o(t,t,t));return new Uint32Array(e)})(),d=(o(0,0,0,255),o(255,255,255,255),r(277).quantize);function g(e){return e>=255?255:e<0?0:e}function U(r,n,a,o){return((65280|g(i(r)+o))<<8|g(t(r)+a))<<8|g(e(r)+n)}class p{constructor(e,t=14,r=42){this.palette=e,this._boxes={},this._boxes2={};const n=t*t*3,i=r*r*3;for(let e=0;e<4096;++e){const t=e>>8,r=e>>4&15,a=15&e;this._nearestPoints(e,8+(t<<4),8+(r<<4),8+(a<<4),n,i)}}_nearestPoints(e,t,r,n,i,a){let o=Number.MAX_SAFE_INTEGER,f=-1;const s=[],l=[];for(let e=0;e<this.palette.length;++e){const u=this.palette[e],c=this._distance(t,r,n,u[0],u[1],u[2]);c<o&&(o=c,f=e),c<i?s.push(e):c<a&&l.push(e)}0===s.length&&s.push(f),this._boxes[e]=s,this._boxes2[e]=l}_distance(e,t,r,n,i,a){const o=e-n,f=t-i,s=r-a;return o*o+f*f+s*s}nearest(r){const n=e(r),a=t(r),o=i(r),f=n>>4<<8|a>>4<<4|o>>4,s=this._boxes[f];let l=Number.MAX_SAFE_INTEGER,u=-1;for(let e=0;e<s.length;++e){const t=this.palette[s[e]],r=this._distance(n,a,o,t[0],t[1],t[2]);if(!r)return s[e];r<l&&(l=r,u=s[e])}if(this._distance(n,a,o,8+(240&n),8+(240&a),8+(240&o))>192){const e=this._boxes2[f];for(let t=0;t<e.length;++t){const r=this.palette[e[t]],i=this._distance(n,a,o,r[0],r[1],r[2]);i<l&&(l=i,u=e[t])}}return u}}function v(e=0){return`P0;${e};q`}const N="\\";function w(e,t){const r=String.fromCharCode(e+63);return t>3?"!"+t+r:3===t?r+r+r:2===t?r+r:r}function P(e,t,r,n,i,o){const f=new Int8Array(o.length+1),l=new Uint8Array(o.length+1),u=new Uint16Array(o.length+1),c=new Int16Array(o.length+1);f.fill(-1),u.fill(1),c.fill(-1);const h=[],d=[];let g=0,U=0;for(let p=0;p<n;++p){const v=t+p;let N=0;l.fill(0,0,h.length);for(let t=0;t<r;++t){const r=e[v+N];r!==g&&(g=r,U=a(r)&&i.get(r)||0,void 0===U&&(U=s(r,o)+1,i.set(r,U)),-1===c[U]&&(d.push([]),p&&(f[h.length]=0,u[h.length]=p),c[U]=h.length,h.push(U))),l[c[U]]|=1<<t,N+=n}for(let e=0;e<h.length;++e)l[e]===f[e]?u[e]++:(~f[e]&&d[e].push(w(f[e],u[e])),f[e]=l[e],u[e]=1)}for(let e=0;e<h.length;++e)f[e]&&d[e].push(w(f[e],u[e]));const p=[];for(let e=0;e<h.length;++e)h[e]&&p.push("#"+(h[e]-1)+d[e].join("")+"$");return p.join("")}function b(e,t,r,n,i=!0){if(!e.length||!t||!r)return"";if(t*r*4!==e.length)throw new Error("wrong geometry of data");if(!n||!n.length)throw new Error("palette must not be empty");const s=[0],l=[];for(let e=0;e<n.length;++e){let t=n[e];if("number"==typeof t){if(!a(t))continue;t=o(...f(t))}else t=o(...t);~s.indexOf(t)||(s.push(t),l.push(f(t).slice(0,-1)))}const u=[];i&&u.push(`"1;1;${t};${r}`);for(let[e,[t,r,n]]of l.entries())u.push(`#${e};2;${Math.round(t/255*100)};${Math.round(r/255*100)};${Math.round(n/255*100)}`);const c=new Map(s.map(((e,t)=>[e,t]))),h=[],d=new Uint32Array(e.buffer);for(let e=0;e<r;e+=6)h.push(P(d,e*t,r-e>=6?6:r-e,t,c,l));return u.push(h.join("-\n")),u.join("")}function G(e,t,r,n,i,a,o,f){i.fill(-1),a.fill(0),o.fill(1),f.fill(-1);const s=[],l=[];for(let u=0;u<n;++u){const c=t+u;let h=0;a.fill(0,0,s.length);for(let t=0;t<r;++t){const r=e[c+h]+1;-1===f[r]&&(l.push([]),u&&(i[s.length]=0,o[s.length]=u),f[r]=s.length,s.push(r)),a[f[r]]|=1<<t,h+=n}for(let e=0;e<s.length;++e)a[e]===i[e]?o[e]++:(~i[e]&&l[e].push(w(i[e],o[e])),i[e]=a[e],o[e]=1)}for(let e=0;e<s.length;++e)i[e]&&l[e].push(w(i[e],o[e]));const u=[];for(let e=0;e<s.length;++e)s[e]&&u.push("#"+(s[e]-1)+l[e].join("")+"$");return u.join("")}function y(r,n,s,l=256,u=0){const{indices:c,palette:h}=function(r,n,a){const o=new Uint32Array(r.buffer),s=d.getKDtree(r.slice(),a)[1],l=s.map((e=>f(e.est.rgba))),u=new p(l),c=new Uint16Array(o.length),h=o.length;for(let r=0;r<h;++r){const a=o[r],f=e(a),l=t(a),h=i(a),d=u.nearest(a);c[r]=d;const g=s[d].est.rgba;let p=f-e(g)>>2,v=l-t(g)>>2,N=h-i(g)>>2;o[r+1]=U(o[r+1],p,v,N),o[r+n]=U(o[r+n],p,v,N),p>>=1,v>>=1,N>>=1,o[r+n-1]=U(o[r+n-1],p,v,N),o[r+n+1]=U(o[r+n+1],p,v,N)}return{indices:c,palette:s.map((e=>e.est.rgba))}}(r,n,l),g=function(e,t,r,n,i=!0){if(!e.length||!t||!r)return"";if(t*r!==e.length)throw new Error("wrong geometry of data");if(!n||!n.length)throw new Error("palette must not be empty");const s=[0],l=[];for(let e=0;e<n.length;++e){let t=n[e];if("number"==typeof t){if(!a(t))continue;t=o(...f(t))}else t=o(...t);~s.indexOf(t)||(s.push(t),l.push(f(t).slice(0,-1)))}const u=[];i&&u.push(`"1;1;${t};${r}`);for(let[e,[t,r,n]]of l.entries())u.push(`#${e};2;${Math.round(t/255*100)};${Math.round(r/255*100)};${Math.round(n/255*100)}`);const c=new Int8Array(l.length+1),h=new Uint8Array(l.length+1),d=new Uint16Array(l.length+1),g=new Int16Array(l.length+1),U=[];for(let n=0;n<r;n+=6)U.push(G(e,n*t,r-n>=6?6:r-n,t,c,h,d,g));return u.push(U.join("-\n")),u.join("")}(c,n,s,h);return[v(u),g,N].join("")}})();var i=n.uO,a=n.xq,o=n.Zl,f=n.Aj,s=n.gp,l=n.n2,u=n.Dz,c=n.Xz,h=n.m1;export{i as FINALIZER,a as PALETTE_ANSI_256,o as PALETTE_VT340_COLOR,f as PALETTE_VT340_GREY,s as fromRGBA8888,l as image2sixel,u as introducer,c as sixelEncode,h as toRGBA8888}; //# sourceMappingURL=encode.esm.js.map