@kecan0406/ttheme 1.2.13 → 1.2.14

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/bin/ttheme.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import{createRequire as BM}from"node:module";var HM=Object.create;var{getPrototypeOf:FM,defineProperty:Hp,getOwnPropertyNames:CM}=Object;var LM=Object.prototype.hasOwnProperty;function jM(t){return this[t]}var _M,GM,Ll=(t,e,n)=>{var r=t!=null&&typeof t==="object";if(r){var i=e?_M??=new WeakMap:GM??=new WeakMap,s=i.get(t);if(s)return s}n=t!=null?HM(FM(t)):{};let o=e||!t||!t.__esModule?Hp(n,"default",{value:t,enumerable:!0}):n;for(let a of CM(t))if(!LM.call(o,a))Hp(o,a,{get:jM.bind(t,a),enumerable:!0});if(r)i.set(t,o);return o};var $t=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var zt=BM(import.meta.url);var ql=$t((v3,ig)=>{var aO=zt("util"),rg=zt("stream"),We=ig.exports=function(){rg.call(this),this._buffers=[],this._buffered=0,this._reads=[],this._paused=!1,this._encoding="utf8",this.writable=!0};aO.inherits(We,rg);We.prototype.read=function(t,e){this._reads.push({length:Math.abs(t),allowLess:t<0,func:e}),process.nextTick(function(){if(this._process(),this._paused&&this._reads&&this._reads.length>0)this._paused=!1,this.emit("drain")}.bind(this))};We.prototype.write=function(t,e){if(!this.writable)return this.emit("error",Error("Stream not writable")),!1;let n;if(Buffer.isBuffer(t))n=t;else n=Buffer.from(t,e||this._encoding);if(this._buffers.push(n),this._buffered+=n.length,this._process(),this._reads&&this._reads.length===0)this._paused=!0;return this.writable&&!this._paused};We.prototype.end=function(t,e){if(t)this.write(t,e);if(this.writable=!1,!this._buffers)return;if(this._buffers.length===0)this._end();else this._buffers.push(null),this._process()};We.prototype.destroySoon=We.prototype.end;We.prototype._end=function(){if(this._reads.length>0)this.emit("error",Error("Unexpected end of input"));this.destroy()};We.prototype.destroy=function(){if(!this._buffers)return;this.writable=!1,this._reads=null,this._buffers=null,this.emit("close")};We.prototype._processReadAllowingLess=function(t){this._reads.shift();let e=this._buffers[0];if(e.length>t.length)this._buffered-=t.length,this._buffers[0]=e.slice(t.length),t.func.call(this,e.slice(0,t.length));else this._buffered-=e.length,this._buffers.shift(),t.func.call(this,e)};We.prototype._processRead=function(t){this._reads.shift();let e=0,n=0,r=Buffer.alloc(t.length);while(e<t.length){let i=this._buffers[n++],s=Math.min(i.length,t.length-e);if(i.copy(r,e,0,s),e+=s,s!==i.length)this._buffers[--n]=i.slice(s)}if(n>0)this._buffers.splice(0,n);this._buffered-=t.length,t.func.call(this,r)};We.prototype._process=function(){try{while(this._buffered>0&&this._reads&&this._reads.length>0){let t=this._reads[0];if(t.allowLess)this._processReadAllowingLess(t);else if(this._buffered>=t.length)this._processRead(t);else break}if(this._buffers&&!this.writable)this._end()}catch(t){this.emit("error",t)}}});var Yl=$t((cO)=>{var rr=[{x:[0],y:[0]},{x:[4],y:[0]},{x:[0,4],y:[4]},{x:[2,6],y:[0,4]},{x:[0,2,4,6],y:[2,6]},{x:[1,3,5,7],y:[0,2,4,6]},{x:[0,1,2,3,4,5,6,7],y:[1,3,5,7]}];cO.getImagePasses=function(t,e){let n=[],r=t%8,i=e%8,s=(t-r)/8,o=(e-i)/8;for(let a=0;a<rr.length;a++){let c=rr[a],u=s*c.x.length,l=o*c.y.length;for(let f=0;f<c.x.length;f++)if(c.x[f]<r)u++;else break;for(let f=0;f<c.y.length;f++)if(c.y[f]<i)l++;else break;if(u>0&&l>0)n.push({width:u,height:l,index:a})}return n};cO.getInterlaceIterator=function(t){return function(e,n,r){let i=e%rr[r].x.length,s=(e-i)/rr[r].x.length*8+rr[r].x[i],o=n%rr[r].y.length,a=(n-o)/rr[r].y.length*8+rr[r].y[o];return s*4+a*t*4}}});var Jl=$t((S3,sg)=>{sg.exports=function(e,n,r){let i=e+n-r,s=Math.abs(i-e),o=Math.abs(i-n),a=Math.abs(i-r);if(s<=o&&s<=a)return e;if(o<=a)return n;return r}});var Vl=$t((M3,ag)=>{var fO=Yl(),dO=Jl();function og(t,e,n){let r=t*e;if(n!==8)r=Math.ceil(r/(8/n));return r}var ns=ag.exports=function(t,e){let{width:n,height:r,interlace:i,bpp:s,depth:o}=t;if(this.read=e.read,this.write=e.write,this.complete=e.complete,this._imageIndex=0,this._images=[],i){let a=fO.getImagePasses(n,r);for(let c=0;c<a.length;c++)this._images.push({byteWidth:og(a[c].width,s,o),height:a[c].height,lineIndex:0})}else this._images.push({byteWidth:og(n,s,o),height:r,lineIndex:0});if(o===8)this._xComparison=s;else if(o===16)this._xComparison=s*2;else this._xComparison=1};ns.prototype.start=function(){this.read(this._images[this._imageIndex].byteWidth+1,this._reverseFilterLine.bind(this))};ns.prototype._unFilterType1=function(t,e,n){let r=this._xComparison,i=r-1;for(let s=0;s<n;s++){let o=t[1+s],a=s>i?e[s-r]:0;e[s]=o+a}};ns.prototype._unFilterType2=function(t,e,n){let r=this._lastLine;for(let i=0;i<n;i++){let s=t[1+i],o=r?r[i]:0;e[i]=s+o}};ns.prototype._unFilterType3=function(t,e,n){let r=this._xComparison,i=r-1,s=this._lastLine;for(let o=0;o<n;o++){let a=t[1+o],c=s?s[o]:0,u=o>i?e[o-r]:0,l=Math.floor((u+c)/2);e[o]=a+l}};ns.prototype._unFilterType4=function(t,e,n){let r=this._xComparison,i=r-1,s=this._lastLine;for(let o=0;o<n;o++){let a=t[1+o],c=s?s[o]:0,u=o>i?e[o-r]:0,l=o>i&&s?s[o-r]:0,f=dO(u,c,l);e[o]=a+f}};ns.prototype._reverseFilterLine=function(t){let e=t[0],n,r=this._images[this._imageIndex],i=r.byteWidth;if(e===0)n=t.slice(1,i+1);else switch(n=Buffer.alloc(i),e){case 1:this._unFilterType1(t,n,i);break;case 2:this._unFilterType2(t,n,i);break;case 3:this._unFilterType3(t,n,i);break;case 4:this._unFilterType4(t,n,i);break;default:throw Error("Unrecognised filter type - "+e)}if(this.write(n),r.lineIndex++,r.lineIndex>=r.height)this._lastLine=null,this._imageIndex++,r=this._images[this._imageIndex];else this._lastLine=n;if(r)this.read(r.byteWidth+1,this._reverseFilterLine.bind(this));else this._lastLine=null,this.complete()}});var lg=$t((O3,ug)=>{var hO=zt("util"),cg=ql(),mO=Vl(),pO=ug.exports=function(t){cg.call(this);let e=[],n=this;this._filter=new mO(t,{read:this.read.bind(this),write:function(r){e.push(r)},complete:function(){n.emit("complete",Buffer.concat(e))}}),this._filter.start()};hO.inherits(pO,cg)});var rs=$t((x3,fg)=>{fg.exports={PNG_SIGNATURE:[137,80,78,71,13,10,26,10],TYPE_IHDR:1229472850,TYPE_IEND:1229278788,TYPE_IDAT:1229209940,TYPE_PLTE:1347179589,TYPE_tRNS:1951551059,TYPE_gAMA:1732332865,COLORTYPE_GRAYSCALE:0,COLORTYPE_PALETTE:1,COLORTYPE_COLOR:2,COLORTYPE_ALPHA:4,COLORTYPE_PALETTE_COLOR:3,COLORTYPE_COLOR_ALPHA:6,COLORTYPE_TO_BPP_MAP:{0:1,2:3,3:1,4:2,6:4},GAMMA_DIVISION:1e5}});var Xl=$t((I3,dg)=>{var Zl=[];(function(){for(let t=0;t<256;t++){let e=t;for(let n=0;n<8;n++)if(e&1)e=3988292384^e>>>1;else e=e>>>1;Zl[t]=e}})();var Ql=dg.exports=function(){this._crc=-1};Ql.prototype.write=function(t){for(let e=0;e<t.length;e++)this._crc=Zl[(this._crc^t[e])&255]^this._crc>>>8;return!0};Ql.prototype.crc32=function(){return this._crc^-1};Ql.crc32=function(t){let e=-1;for(let n=0;n<t.length;n++)e=Zl[(e^t[n])&255]^e>>>8;return e^-1}});var tf=$t((R3,hg)=>{var Nt=rs(),gO=Xl(),Pt=hg.exports=function(t,e){this._options=t,t.checkCRC=t.checkCRC!==!1,this._hasIHDR=!1,this._hasIEND=!1,this._emittedHeadersFinished=!1,this._palette=[],this._colorType=0,this._chunks={},this._chunks[Nt.TYPE_IHDR]=this._handleIHDR.bind(this),this._chunks[Nt.TYPE_IEND]=this._handleIEND.bind(this),this._chunks[Nt.TYPE_IDAT]=this._handleIDAT.bind(this),this._chunks[Nt.TYPE_PLTE]=this._handlePLTE.bind(this),this._chunks[Nt.TYPE_tRNS]=this._handleTRNS.bind(this),this._chunks[Nt.TYPE_gAMA]=this._handleGAMA.bind(this),this.read=e.read,this.error=e.error,this.metadata=e.metadata,this.gamma=e.gamma,this.transColor=e.transColor,this.palette=e.palette,this.parsed=e.parsed,this.inflateData=e.inflateData,this.finished=e.finished,this.simpleTransparency=e.simpleTransparency,this.headersFinished=e.headersFinished||function(){}};Pt.prototype.start=function(){this.read(Nt.PNG_SIGNATURE.length,this._parseSignature.bind(this))};Pt.prototype._parseSignature=function(t){let e=Nt.PNG_SIGNATURE;for(let n=0;n<e.length;n++)if(t[n]!==e[n]){this.error(Error("Invalid file signature"));return}this.read(8,this._parseChunkBegin.bind(this))};Pt.prototype._parseChunkBegin=function(t){let e=t.readUInt32BE(0),n=t.readUInt32BE(4),r="";for(let s=4;s<8;s++)r+=String.fromCharCode(t[s]);let i=Boolean(t[4]&32);if(!this._hasIHDR&&n!==Nt.TYPE_IHDR){this.error(Error("Expected IHDR on beggining"));return}if(this._crc=new gO,this._crc.write(Buffer.from(r)),this._chunks[n])return this._chunks[n](e);if(!i){this.error(Error("Unsupported critical chunk type "+r));return}this.read(e+4,this._skipChunk.bind(this))};Pt.prototype._skipChunk=function(){this.read(8,this._parseChunkBegin.bind(this))};Pt.prototype._handleChunkEnd=function(){this.read(4,this._parseChunkEnd.bind(this))};Pt.prototype._parseChunkEnd=function(t){let e=t.readInt32BE(0),n=this._crc.crc32();if(this._options.checkCRC&&n!==e){this.error(Error("Crc error - "+e+" - "+n));return}if(!this._hasIEND)this.read(8,this._parseChunkBegin.bind(this))};Pt.prototype._handleIHDR=function(t){this.read(t,this._parseIHDR.bind(this))};Pt.prototype._parseIHDR=function(t){this._crc.write(t);let e=t.readUInt32BE(0),n=t.readUInt32BE(4),r=t[8],i=t[9],s=t[10],o=t[11],a=t[12];if(r!==8&&r!==4&&r!==2&&r!==1&&r!==16){this.error(Error("Unsupported bit depth "+r));return}if(!(i in Nt.COLORTYPE_TO_BPP_MAP)){this.error(Error("Unsupported color type"));return}if(s!==0){this.error(Error("Unsupported compression method"));return}if(o!==0){this.error(Error("Unsupported filter method"));return}if(a!==0&&a!==1){this.error(Error("Unsupported interlace method"));return}this._colorType=i;let c=Nt.COLORTYPE_TO_BPP_MAP[this._colorType];this._hasIHDR=!0,this.metadata({width:e,height:n,depth:r,interlace:Boolean(a),palette:Boolean(i&Nt.COLORTYPE_PALETTE),color:Boolean(i&Nt.COLORTYPE_COLOR),alpha:Boolean(i&Nt.COLORTYPE_ALPHA),bpp:c,colorType:i}),this._handleChunkEnd()};Pt.prototype._handlePLTE=function(t){this.read(t,this._parsePLTE.bind(this))};Pt.prototype._parsePLTE=function(t){this._crc.write(t);let e=Math.floor(t.length/3);for(let n=0;n<e;n++)this._palette.push([t[n*3],t[n*3+1],t[n*3+2],255]);this.palette(this._palette),this._handleChunkEnd()};Pt.prototype._handleTRNS=function(t){this.simpleTransparency(),this.read(t,this._parseTRNS.bind(this))};Pt.prototype._parseTRNS=function(t){if(this._crc.write(t),this._colorType===Nt.COLORTYPE_PALETTE_COLOR){if(this._palette.length===0){this.error(Error("Transparency chunk must be after palette"));return}if(t.length>this._palette.length){this.error(Error("More transparent colors than palette size"));return}for(let e=0;e<t.length;e++)this._palette[e][3]=t[e];this.palette(this._palette)}if(this._colorType===Nt.COLORTYPE_GRAYSCALE)this.transColor([t.readUInt16BE(0)]);if(this._colorType===Nt.COLORTYPE_COLOR)this.transColor([t.readUInt16BE(0),t.readUInt16BE(2),t.readUInt16BE(4)]);this._handleChunkEnd()};Pt.prototype._handleGAMA=function(t){this.read(t,this._parseGAMA.bind(this))};Pt.prototype._parseGAMA=function(t){this._crc.write(t),this.gamma(t.readUInt32BE(0)/Nt.GAMMA_DIVISION),this._handleChunkEnd()};Pt.prototype._handleIDAT=function(t){if(!this._emittedHeadersFinished)this._emittedHeadersFinished=!0,this.headersFinished();this.read(-t,this._parseIDAT.bind(this,t))};Pt.prototype._parseIDAT=function(t,e){if(this._crc.write(e),this._colorType===Nt.COLORTYPE_PALETTE_COLOR&&this._palette.length===0)throw Error("Expected palette not found");this.inflateData(e);let n=t-e.length;if(n>0)this._handleIDAT(n);else this._handleChunkEnd()};Pt.prototype._handleIEND=function(t){this.read(t,this._parseIEND.bind(this))};Pt.prototype._parseIEND=function(t){if(this._crc.write(t),this._hasIEND=!0,this._handleChunkEnd(),this.finished)this.finished()}});var ef=$t((vO)=>{var mg=Yl(),bO=[function(){},function(t,e,n,r){if(r===e.length)throw Error("Ran out of data");let i=e[r];t[n]=i,t[n+1]=i,t[n+2]=i,t[n+3]=255},function(t,e,n,r){if(r+1>=e.length)throw Error("Ran out of data");let i=e[r];t[n]=i,t[n+1]=i,t[n+2]=i,t[n+3]=e[r+1]},function(t,e,n,r){if(r+2>=e.length)throw Error("Ran out of data");t[n]=e[r],t[n+1]=e[r+1],t[n+2]=e[r+2],t[n+3]=255},function(t,e,n,r){if(r+3>=e.length)throw Error("Ran out of data");t[n]=e[r],t[n+1]=e[r+1],t[n+2]=e[r+2],t[n+3]=e[r+3]}],wO=[function(){},function(t,e,n,r){let i=e[0];t[n]=i,t[n+1]=i,t[n+2]=i,t[n+3]=r},function(t,e,n){let r=e[0];t[n]=r,t[n+1]=r,t[n+2]=r,t[n+3]=e[1]},function(t,e,n,r){t[n]=e[0],t[n+1]=e[1],t[n+2]=e[2],t[n+3]=r},function(t,e,n){t[n]=e[0],t[n+1]=e[1],t[n+2]=e[2],t[n+3]=e[3]}];function $O(t,e){let n=[],r=0;function i(){if(r===t.length)throw Error("Ran out of data");let s=t[r];r++;let o,a,c,u,l,f,d,h;switch(e){default:throw Error("unrecognised depth");case 16:d=t[r],r++,n.push((s<<8)+d);break;case 4:d=s&15,h=s>>4,n.push(h,d);break;case 2:l=s&3,f=s>>2&3,d=s>>4&3,h=s>>6&3,n.push(h,d,f,l);break;case 1:o=s&1,a=s>>1&1,c=s>>2&1,u=s>>3&1,l=s>>4&1,f=s>>5&1,d=s>>6&1,h=s>>7&1,n.push(h,d,f,l,u,c,a,o);break}}return{get:function(s){while(n.length<s)i();let o=n.slice(0,s);return n=n.slice(s),o},resetAfterLine:function(){n.length=0},end:function(){if(r!==t.length)throw Error("extra data found")}}}function kO(t,e,n,r,i,s){let{width:o,height:a,index:c}=t;for(let u=0;u<a;u++)for(let l=0;l<o;l++){let f=n(l,u,c);bO[r](e,i,f,s),s+=r}return s}function yO(t,e,n,r,i,s){let{width:o,height:a,index:c}=t;for(let u=0;u<a;u++){for(let l=0;l<o;l++){let f=i.get(r),d=n(l,u,c);wO[r](e,f,d,s)}i.resetAfterLine()}}vO.dataToBitMap=function(t,e){let{width:n,height:r,depth:i,bpp:s,interlace:o}=e,a;if(i!==8)a=$O(t,i);let c;if(i<=8)c=Buffer.alloc(n*r*4);else c=new Uint16Array(n*r*4);let u=Math.pow(2,i)-1,l=0,f,d;if(o)f=mg.getImagePasses(n,r),d=mg.getInterlaceIterator(n,r);else{let h=0;d=function(){let m=h;return h+=4,m},f=[{width:n,height:r}]}for(let h=0;h<f.length;h++)if(i===8)l=kO(f[h],c,d,s,t,l);else yO(f[h],c,d,s,a,u);if(i===8){if(l!==t.length)throw Error("extra data found")}else a.end();return c}});var nf=$t((T3,pg)=>{function SO(t,e,n,r,i){let s=0;for(let o=0;o<r;o++)for(let a=0;a<n;a++){let c=i[t[s]];if(!c)throw Error("index "+t[s]+" not in palette");for(let u=0;u<4;u++)e[s+u]=c[u];s+=4}}function MO(t,e,n,r,i){let s=0;for(let o=0;o<r;o++)for(let a=0;a<n;a++){let c=!1;if(i.length===1){if(i[0]===t[s])c=!0}else if(i[0]===t[s]&&i[1]===t[s+1]&&i[2]===t[s+2])c=!0;if(c)for(let u=0;u<4;u++)e[s+u]=0;s+=4}}function OO(t,e,n,r,i){let s=255,o=Math.pow(2,i)-1,a=0;for(let c=0;c<r;c++)for(let u=0;u<n;u++){for(let l=0;l<4;l++)e[a+l]=Math.floor(t[a+l]*s/o+0.5);a+=4}}pg.exports=function(t,e,n=!1){let{depth:r,width:i,height:s,colorType:o,transColor:a,palette:c}=e,u=t;if(o===3)SO(t,u,i,s,c);else{if(a)MO(t,u,i,s,a);if(r!==8&&!n){if(r===16)u=Buffer.alloc(i*s*4);OO(t,u,i,s,r)}}return u}});var wg=$t((A3,bg)=>{var xO=zt("util"),rf=zt("zlib"),gg=ql(),IO=lg(),RO=tf(),NO=ef(),TO=nf(),cn=bg.exports=function(t){gg.call(this),this._parser=new RO(t,{read:this.read.bind(this),error:this._handleError.bind(this),metadata:this._handleMetaData.bind(this),gamma:this.emit.bind(this,"gamma"),palette:this._handlePalette.bind(this),transColor:this._handleTransColor.bind(this),finished:this._finished.bind(this),inflateData:this._inflateData.bind(this),simpleTransparency:this._simpleTransparency.bind(this),headersFinished:this._headersFinished.bind(this)}),this._options=t,this.writable=!0,this._parser.start()};xO.inherits(cn,gg);cn.prototype._handleError=function(t){if(this.emit("error",t),this.writable=!1,this.destroy(),this._inflate&&this._inflate.destroy)this._inflate.destroy();if(this._filter)this._filter.destroy(),this._filter.on("error",function(){});this.errord=!0};cn.prototype._inflateData=function(t){if(!this._inflate)if(this._bitmapInfo.interlace)this._inflate=rf.createInflate(),this._inflate.on("error",this.emit.bind(this,"error")),this._filter.on("complete",this._complete.bind(this)),this._inflate.pipe(this._filter);else{let n=((this._bitmapInfo.width*this._bitmapInfo.bpp*this._bitmapInfo.depth+7>>3)+1)*this._bitmapInfo.height,r=Math.max(n,rf.Z_MIN_CHUNK);this._inflate=rf.createInflate({chunkSize:r});let i=n,s=this.emit.bind(this,"error");this._inflate.on("error",function(a){if(!i)return;s(a)}),this._filter.on("complete",this._complete.bind(this));let o=this._filter.write.bind(this._filter);this._inflate.on("data",function(a){if(!i)return;if(a.length>i)a=a.slice(0,i);i-=a.length,o(a)}),this._inflate.on("end",this._filter.end.bind(this._filter))}this._inflate.write(t)};cn.prototype._handleMetaData=function(t){this._metaData=t,this._bitmapInfo=Object.create(t),this._filter=new IO(this._bitmapInfo)};cn.prototype._handleTransColor=function(t){this._bitmapInfo.transColor=t};cn.prototype._handlePalette=function(t){this._bitmapInfo.palette=t};cn.prototype._simpleTransparency=function(){this._metaData.alpha=!0};cn.prototype._headersFinished=function(){this.emit("metadata",this._metaData)};cn.prototype._finished=function(){if(this.errord)return;if(!this._inflate)this.emit("error","No Inflate block");else this._inflate.end()};cn.prototype._complete=function(t){if(this.errord)return;let e;try{let n=NO.dataToBitMap(t,this._bitmapInfo);e=TO(n,this._bitmapInfo,this._options.skipRescale),n=null}catch(n){this._handleError(n);return}this.emit("parsed",e)}});var kg=$t((P3,$g)=>{var Pe=rs();$g.exports=function(t,e,n,r){let i=[Pe.COLORTYPE_COLOR_ALPHA,Pe.COLORTYPE_ALPHA].indexOf(r.colorType)!==-1;if(r.colorType===r.inputColorType){let m=function(){let $=new ArrayBuffer(2);return new DataView($).setInt16(0,256,!0),new Int16Array($)[0]!==256}();if(r.bitDepth===8||r.bitDepth===16&&m)return t}let s=r.bitDepth!==16?t:new Uint16Array(t.buffer),o=255,a=Pe.COLORTYPE_TO_BPP_MAP[r.inputColorType];if(a===4&&!r.inputHasAlpha)a=3;let c=Pe.COLORTYPE_TO_BPP_MAP[r.colorType];if(r.bitDepth===16)o=65535,c*=2;let u=Buffer.alloc(e*n*c),l=0,f=0,d=r.bgColor||{};if(d.red===void 0)d.red=o;if(d.green===void 0)d.green=o;if(d.blue===void 0)d.blue=o;function h(){let m,$,g,b=o;switch(r.inputColorType){case Pe.COLORTYPE_COLOR_ALPHA:b=s[l+3],m=s[l],$=s[l+1],g=s[l+2];break;case Pe.COLORTYPE_COLOR:m=s[l],$=s[l+1],g=s[l+2];break;case Pe.COLORTYPE_ALPHA:b=s[l+1],m=s[l],$=m,g=m;break;case Pe.COLORTYPE_GRAYSCALE:m=s[l],$=m,g=m;break;default:throw Error("input color type:"+r.inputColorType+" is not supported at present")}if(r.inputHasAlpha){if(!i)b/=o,m=Math.min(Math.max(Math.round((1-b)*d.red+b*m),0),o),$=Math.min(Math.max(Math.round((1-b)*d.green+b*$),0),o),g=Math.min(Math.max(Math.round((1-b)*d.blue+b*g),0),o)}return{red:m,green:$,blue:g,alpha:b}}for(let m=0;m<n;m++)for(let $=0;$<e;$++){let g=h(s,l);switch(r.colorType){case Pe.COLORTYPE_COLOR_ALPHA:case Pe.COLORTYPE_COLOR:if(r.bitDepth===8){if(u[f]=g.red,u[f+1]=g.green,u[f+2]=g.blue,i)u[f+3]=g.alpha}else if(u.writeUInt16BE(g.red,f),u.writeUInt16BE(g.green,f+2),u.writeUInt16BE(g.blue,f+4),i)u.writeUInt16BE(g.alpha,f+6);break;case Pe.COLORTYPE_ALPHA:case Pe.COLORTYPE_GRAYSCALE:{let b=(g.red+g.green+g.blue)/3;if(r.bitDepth===8){if(u[f]=b,i)u[f+1]=g.alpha}else if(u.writeUInt16BE(b,f),i)u.writeUInt16BE(g.alpha,f+2);break}default:throw Error("unrecognised color Type "+r.colorType)}l+=a,f+=c}return u}});var Eg=$t((H3,vg)=>{var yg=Jl();function AO(t,e,n,r,i){for(let s=0;s<n;s++)r[i+s]=t[e+s]}function PO(t,e,n){let r=0,i=e+n;for(let s=e;s<i;s++)r+=Math.abs(t[s]);return r}function HO(t,e,n,r,i,s){for(let o=0;o<n;o++){let a=o>=s?t[e+o-s]:0,c=t[e+o]-a;r[i+o]=c}}function FO(t,e,n,r){let i=0;for(let s=0;s<n;s++){let o=s>=r?t[e+s-r]:0,a=t[e+s]-o;i+=Math.abs(a)}return i}function CO(t,e,n,r,i){for(let s=0;s<n;s++){let o=e>0?t[e+s-n]:0,a=t[e+s]-o;r[i+s]=a}}function LO(t,e,n){let r=0,i=e+n;for(let s=e;s<i;s++){let o=e>0?t[s-n]:0,a=t[s]-o;r+=Math.abs(a)}return r}function jO(t,e,n,r,i,s){for(let o=0;o<n;o++){let a=o>=s?t[e+o-s]:0,c=e>0?t[e+o-n]:0,u=t[e+o]-(a+c>>1);r[i+o]=u}}function _O(t,e,n,r){let i=0;for(let s=0;s<n;s++){let o=s>=r?t[e+s-r]:0,a=e>0?t[e+s-n]:0,c=t[e+s]-(o+a>>1);i+=Math.abs(c)}return i}function GO(t,e,n,r,i,s){for(let o=0;o<n;o++){let a=o>=s?t[e+o-s]:0,c=e>0?t[e+o-n]:0,u=e>0&&o>=s?t[e+o-(n+s)]:0,l=t[e+o]-yg(a,c,u);r[i+o]=l}}function BO(t,e,n,r){let i=0;for(let s=0;s<n;s++){let o=s>=r?t[e+s-r]:0,a=e>0?t[e+s-n]:0,c=e>0&&s>=r?t[e+s-(n+r)]:0,u=t[e+s]-yg(o,a,c);i+=Math.abs(u)}return i}var UO={0:AO,1:HO,2:CO,3:jO,4:GO},WO={0:PO,1:FO,2:LO,3:_O,4:BO};vg.exports=function(t,e,n,r,i){let s;if(!("filterType"in r)||r.filterType===-1)s=[0,1,2,3,4];else if(typeof r.filterType==="number")s=[r.filterType];else throw Error("unrecognised filter types");if(r.bitDepth===16)i*=2;let o=e*i,a=0,c=0,u=Buffer.alloc((o+1)*n),l=s[0];for(let f=0;f<n;f++){if(s.length>1){let d=1/0;for(let h=0;h<s.length;h++){let m=WO[s[h]](t,c,o,i);if(m<d)l=s[h],d=m}}u[a]=l,a++,UO[l](t,c,o,u,a,i),a+=o,c+=o}return u}});var sf=$t((F3,Sg)=>{var Dt=rs(),KO=Xl(),zO=kg(),DO=Eg(),qO=zt("zlib"),ir=Sg.exports=function(t){if(this._options=t,t.deflateChunkSize=t.deflateChunkSize||32768,t.deflateLevel=t.deflateLevel!=null?t.deflateLevel:9,t.deflateStrategy=t.deflateStrategy!=null?t.deflateStrategy:3,t.inputHasAlpha=t.inputHasAlpha!=null?t.inputHasAlpha:!0,t.deflateFactory=t.deflateFactory||qO.createDeflate,t.bitDepth=t.bitDepth||8,t.colorType=typeof t.colorType==="number"?t.colorType:Dt.COLORTYPE_COLOR_ALPHA,t.inputColorType=typeof t.inputColorType==="number"?t.inputColorType:Dt.COLORTYPE_COLOR_ALPHA,[Dt.COLORTYPE_GRAYSCALE,Dt.COLORTYPE_COLOR,Dt.COLORTYPE_COLOR_ALPHA,Dt.COLORTYPE_ALPHA].indexOf(t.colorType)===-1)throw Error("option color type:"+t.colorType+" is not supported at present");if([Dt.COLORTYPE_GRAYSCALE,Dt.COLORTYPE_COLOR,Dt.COLORTYPE_COLOR_ALPHA,Dt.COLORTYPE_ALPHA].indexOf(t.inputColorType)===-1)throw Error("option input color type:"+t.inputColorType+" is not supported at present");if(t.bitDepth!==8&&t.bitDepth!==16)throw Error("option bit depth:"+t.bitDepth+" is not supported at present")};ir.prototype.getDeflateOptions=function(){return{chunkSize:this._options.deflateChunkSize,level:this._options.deflateLevel,strategy:this._options.deflateStrategy}};ir.prototype.createDeflate=function(){return this._options.deflateFactory(this.getDeflateOptions())};ir.prototype.filterData=function(t,e,n){let r=zO(t,e,n,this._options),i=Dt.COLORTYPE_TO_BPP_MAP[this._options.colorType];return DO(r,e,n,this._options,i)};ir.prototype._packChunk=function(t,e){let n=e?e.length:0,r=Buffer.alloc(n+12);if(r.writeUInt32BE(n,0),r.writeUInt32BE(t,4),e)e.copy(r,8);return r.writeInt32BE(KO.crc32(r.slice(4,r.length-4)),r.length-4),r};ir.prototype.packGAMA=function(t){let e=Buffer.alloc(4);return e.writeUInt32BE(Math.floor(t*Dt.GAMMA_DIVISION),0),this._packChunk(Dt.TYPE_gAMA,e)};ir.prototype.packIHDR=function(t,e){let n=Buffer.alloc(13);return n.writeUInt32BE(t,0),n.writeUInt32BE(e,4),n[8]=this._options.bitDepth,n[9]=this._options.colorType,n[10]=0,n[11]=0,n[12]=0,this._packChunk(Dt.TYPE_IHDR,n)};ir.prototype.packIDAT=function(t){return this._packChunk(Dt.TYPE_IDAT,t)};ir.prototype.packIEND=function(){return this._packChunk(Dt.TYPE_IEND,null)}});var Ig=$t((C3,xg)=>{var YO=zt("util"),Mg=zt("stream"),JO=rs(),VO=sf(),Og=xg.exports=function(t){Mg.call(this);let e=t||{};this._packer=new VO(e),this._deflate=this._packer.createDeflate(),this.readable=!0};YO.inherits(Og,Mg);Og.prototype.pack=function(t,e,n,r){if(this.emit("data",Buffer.from(JO.PNG_SIGNATURE)),this.emit("data",this._packer.packIHDR(e,n)),r)this.emit("data",this._packer.packGAMA(r));let i=this._packer.filterData(t,e,n);this._deflate.on("error",this.emit.bind(this,"error")),this._deflate.on("data",function(s){this.emit("data",this._packer.packIDAT(s))}.bind(this)),this._deflate.on("end",function(){this.emit("data",this._packer.packIEND()),this.emit("end")}.bind(this)),this._deflate.end(i)}});var Hg=$t((ho,Pg)=>{var Rg=zt("assert").ok,is=zt("zlib"),ZO=zt("util"),Ng=zt("buffer").kMaxLength;function ti(t){if(!(this instanceof ti))return new ti(t);if(t&&t.chunkSize<is.Z_MIN_CHUNK)t.chunkSize=is.Z_MIN_CHUNK;if(is.Inflate.call(this,t),this._offset=this._offset===void 0?this._outOffset:this._offset,this._buffer=this._buffer||this._outBuffer,t&&t.maxLength!=null)this._maxLength=t.maxLength}function QO(t){return new ti(t)}function Tg(t,e){if(e)process.nextTick(e);if(!t._handle)return;t._handle.close(),t._handle=null}ti.prototype._processChunk=function(t,e,n){if(typeof n==="function")return is.Inflate._processChunk.call(this,t,e,n);let r=this,i=t&&t.length,s=this._chunkSize-this._offset,o=this._maxLength,a=0,c=[],u=0,l;this.on("error",function(m){l=m});function f(m,$){if(r._hadError)return;let g=s-$;if(Rg(g>=0,"have should not go down"),g>0){let b=r._buffer.slice(r._offset,r._offset+g);if(r._offset+=g,b.length>o)b=b.slice(0,o);if(c.push(b),u+=b.length,o-=b.length,o===0)return!1}if($===0||r._offset>=r._chunkSize)s=r._chunkSize,r._offset=0,r._buffer=Buffer.allocUnsafe(r._chunkSize);if($===0)return a+=i-m,i=m,!0;return!1}Rg(this._handle,"zlib binding closed");let d;do d=this._handle.writeSync(e,t,a,i,this._buffer,this._offset,s),d=d||this._writeState;while(!this._hadError&&f(d[0],d[1]));if(this._hadError)throw l;if(u>=Ng)throw Tg(this),RangeError("Cannot create final Buffer. It would be larger than 0x"+Ng.toString(16)+" bytes");let h=Buffer.concat(c,u);return Tg(this),h};ZO.inherits(ti,is.Inflate);function XO(t,e){if(typeof e==="string")e=Buffer.from(e);if(!(e instanceof Buffer))throw TypeError("Not a string or buffer");let n=t._finishFlushFlag;if(n==null)n=is.Z_FINISH;return t._processChunk(e,n)}function Ag(t,e){return XO(new ti(e),t)}Pg.exports=ho=Ag;ho.Inflate=ti;ho.createInflate=QO;ho.inflateSync=Ag});var of=$t((L3,Cg)=>{var Fg=Cg.exports=function(t){this._buffer=t,this._reads=[]};Fg.prototype.read=function(t,e){this._reads.push({length:Math.abs(t),allowLess:t<0,func:e})};Fg.prototype.process=function(){while(this._reads.length>0&&this._buffer.length){let t=this._reads[0];if(this._buffer.length&&(this._buffer.length>=t.length||t.allowLess)){this._reads.shift();let e=this._buffer;this._buffer=e.slice(t.length),t.func.call(this,e.slice(0,t.length))}else break}if(this._reads.length>0)throw Error("There are some read requests waitng on finished stream");if(this._buffer.length>0)throw Error("unrecognised content at end of stream")}});var Lg=$t((nx)=>{var tx=of(),ex=Vl();nx.process=function(t,e){let n=[],r=new tx(t);return new ex(e,{read:r.read.bind(r),write:function(s){n.push(s)},complete:function(){}}).start(),r.process(),Buffer.concat(n)}});var Bg=$t((_3,Gg)=>{var jg=!0,_g=zt("zlib"),ix=Hg();if(!_g.deflateSync)jg=!1;var sx=of(),ox=Lg(),ax=tf(),cx=ef(),ux=nf();Gg.exports=function(t,e){if(!jg)throw Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");let n;function r(S){n=S}let i;function s(S){i=S}function o(S){i.transColor=S}function a(S){i.palette=S}function c(){i.alpha=!0}let u;function l(S){u=S}let f=[];function d(S){f.push(S)}let h=new sx(t);if(new ax(e,{read:h.read.bind(h),error:r,metadata:s,gamma:l,palette:a,transColor:o,inflateData:d,simpleTransparency:c}).start(),h.process(),n)throw n;let $=Buffer.concat(f);f.length=0;let g;if(i.interlace)g=_g.inflateSync($);else{let x=((i.width*i.bpp*i.depth+7>>3)+1)*i.height;g=ix($,{chunkSize:x,maxLength:x})}if($=null,!g||!g.length)throw Error("bad png - invalid inflate data response");let b=ox.process(g,i);$=null;let y=cx.dataToBitMap(b,i);b=null;let E=ux(y,i,e.skipRescale);return i.data=E,i.gamma=u||0,i}});var zg=$t((G3,Kg)=>{var Ug=!0,Wg=zt("zlib");if(!Wg.deflateSync)Ug=!1;var lx=rs(),fx=sf();Kg.exports=function(t,e){if(!Ug)throw Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");let r=new fx(e||{}),i=[];if(i.push(Buffer.from(lx.PNG_SIGNATURE)),i.push(r.packIHDR(t.width,t.height)),t.gamma)i.push(r.packGAMA(t.gamma));let s=r.filterData(t.data,t.width,t.height),o=Wg.deflateSync(s,r.getDeflateOptions());if(s=null,!o||!o.length)throw Error("bad png - invalid compressed data response");return i.push(r.packIDAT(o)),i.push(r.packIEND()),Buffer.concat(i)}});var Dg=$t((mx)=>{var dx=Bg(),hx=zg();mx.read=function(t,e){return dx(t,e||{})};mx.write=function(t,e){return hx(t,e)}});var Yg=$t((yx)=>{var bx=zt("util"),qg=zt("stream"),wx=wg(),$x=Ig(),kx=Dg(),Zt=yx.PNG=function(t){if(qg.call(this),t=t||{},this.width=t.width|0,this.height=t.height|0,this.data=this.width>0&&this.height>0?Buffer.alloc(4*this.width*this.height):null,t.fill&&this.data)this.data.fill(0);this.gamma=0,this.readable=this.writable=!0,this._parser=new wx(t),this._parser.on("error",this.emit.bind(this,"error")),this._parser.on("close",this._handleClose.bind(this)),this._parser.on("metadata",this._metadata.bind(this)),this._parser.on("gamma",this._gamma.bind(this)),this._parser.on("parsed",function(e){this.data=e,this.emit("parsed",e)}.bind(this)),this._packer=new $x(t),this._packer.on("data",this.emit.bind(this,"data")),this._packer.on("end",this.emit.bind(this,"end")),this._parser.on("close",this._handleClose.bind(this)),this._packer.on("error",this.emit.bind(this,"error"))};bx.inherits(Zt,qg);Zt.sync=kx;Zt.prototype.pack=function(){if(!this.data||!this.data.length)return this.emit("error","No data provided"),this;return process.nextTick(function(){this._packer.pack(this.data,this.width,this.height,this.gamma)}.bind(this)),this};Zt.prototype.parse=function(t,e){if(e){let n,r;n=function(i){this.removeListener("error",r),this.data=i,e(null,this)}.bind(this),r=function(i){this.removeListener("parsed",n),e(i,null)}.bind(this),this.once("parsed",n),this.once("error",r)}return this.end(t),this};Zt.prototype.write=function(t){return this._parser.write(t),!0};Zt.prototype.end=function(t){this._parser.end(t)};Zt.prototype._metadata=function(t){this.width=t.width,this.height=t.height,this.emit("metadata",t)};Zt.prototype._gamma=function(t){this.gamma=t};Zt.prototype._handleClose=function(){if(!this._parser.writable&&!this._packer.readable)this.emit("close")};Zt.bitblt=function(t,e,n,r,i,s,o,a){if(n|=0,r|=0,i|=0,s|=0,o|=0,a|=0,n>t.width||r>t.height||n+i>t.width||r+s>t.height)throw Error("bitblt reading outside image");if(o>e.width||a>e.height||o+i>e.width||a+s>e.height)throw Error("bitblt writing outside image");for(let c=0;c<s;c++)t.data.copy(e.data,(a+c)*e.width+o<<2,(r+c)*t.width+n<<2,(r+c)*t.width+n+i<<2)};Zt.prototype.bitblt=function(t,e,n,r,i,s,o){return Zt.bitblt(this,t,e,n,r,i,s,o),this};Zt.adjustGamma=function(t){if(t.gamma){for(let e=0;e<t.height;e++)for(let n=0;n<t.width;n++){let r=t.width*e+n<<2;for(let i=0;i<3;i++){let s=t.data[r+i]/255;s=Math.pow(s,0.45454545454545453/t.gamma),t.data[r+i]=Math.round(s*255)}}t.gamma=0}};Zt.prototype.adjustGamma=function(){Zt.adjustGamma(this)}});var yd=$t((t5,j0)=>{var kd={to(t,e){if(!e)return`\x1B[${t+1}G`;return`\x1B[${e+1};${t+1}H`},move(t,e){let n="";if(t<0)n+=`\x1B[${-t}D`;else if(t>0)n+=`\x1B[${t}C`;if(e<0)n+=`\x1B[${-e}A`;else if(e>0)n+=`\x1B[${e}B`;return n},up:(t=1)=>`\x1B[${t}A`,down:(t=1)=>`\x1B[${t}B`,forward:(t=1)=>`\x1B[${t}C`,backward:(t=1)=>`\x1B[${t}D`,nextLine:(t=1)=>"\x1B[E".repeat(t),prevLine:(t=1)=>"\x1B[F".repeat(t),left:"\x1B[G",hide:"\x1B[?25l",show:"\x1B[?25h",save:"\x1B7",restore:"\x1B8"},wR={up:(t=1)=>"\x1B[S".repeat(t),down:(t=1)=>"\x1B[T".repeat(t)},$R={screen:"\x1B[2J",up:(t=1)=>"\x1B[1J".repeat(t),down:(t=1)=>"\x1B[J".repeat(t),line:"\x1B[2K",lineEnd:"\x1B[K",lineStart:"\x1B[1K",lines(t){let e="";for(let n=0;n<t;n++)e+=this.line+(n<t-1?kd.up():"");if(t)e+=kd.left;return e}};j0.exports={cursor:kd,scroll:wR,erase:$R,beep:"\x07"}});import{spawnSync as i3}from"node:child_process";import{isMainThread as s3}from"node:worker_threads";import{parseArgs as VL}from"node:util";var It={name:"@kecan0406/ttheme",version:"1.2.13",type:"module",bin:{ttheme:"bin/ttheme.js"},files:["bin","dist/manifest.json","shell","!shell/check.zsh"],description:"Character terminal palettes for Ghostty, kitty, Alacritty, WezTerm, iTerm2, Windows Terminal, Warp and Konsole",license:"MIT",author:"kecan0406",repository:{type:"git",url:"git+https://github.com/kecan0406/ttheme.git"},homepage:"https://github.com/kecan0406/ttheme#readme",bugs:"https://github.com/kecan0406/ttheme/issues",keywords:["terminal","theme","ghostty","kitty","alacritty","wezterm","iterm2","konsole"],devDependencies:{"@biomejs/biome":"^2.3.0","@clack/prompts":"^1.7.0","@jsquash/jpeg":"^1.6.0","@material/material-color-utilities":"^0.4.0","@types/bun":"^1.3.0","@types/pngjs":"6.0.5","@xterm/headless":"6.0.0","fast-string-width":"^3.0.2",pngjs:"7.0.0","smol-toml":"^1.9.0",typescript:"^5.8.2"},engines:{bun:">=1.3",node:">=20.11"}};import{existsSync as _C,readFileSync as GC}from"node:fs";var Fp=(()=>{let t=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return(e)=>{let n=0;t.lastIndex=0;while(t.test(e))n+=1;return e.length-n}})(),Cp=(t)=>{return t===12288||t>=65281&&t<=65376||t>=65504&&t<=65510},Lp=(t)=>{return t===8987||t===9001||t>=12272&&t<=12287||t>=12289&&t<=12350||t>=12441&&t<=12543||t>=12549&&t<=12591||t>=12593&&t<=12686||t>=12688&&t<=12771||t>=12783&&t<=12830||t>=12832&&t<=12871||t>=12880&&t<=19903||t>=65040&&t<=65049||t>=65072&&t<=65106||t>=65108&&t<=65126||t>=65128&&t<=65131||t>=127488&&t<=127490||t>=127504&&t<=127547||t>=127552&&t<=127560||t>=131072&&t<=196605||t>=196608&&t<=262141};var WM=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,KM=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,jp=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,zM=/\t{1,1000}/y,_p=/[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu,DM=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,qM=/\p{M}+/gu,YM={limit:1/0,ellipsis:""},Gp=(t,e={},n={})=>{let r=e.limit??1/0,i=e.ellipsis??"",s=e?.ellipsisWidth??(i?Gp(i,YM,n).width:0),o=0,a=n.controlWidth??0,c=n.tabWidth??8,u=n.emojiWidth??2,l=2,f=n.regularWidth??1,d=n.wideWidth??2,h=[[DM,f],[WM,0],[KM,a],[zM,c],[_p,u],[jp,d]],m=0,$=0,g=t.length,b=0,y=!1,E=g,S=Math.max(0,r-s),x=0,R=0,N=0,F=0;t:while(!0){if(R>x||$>=g&&$>m){let _=t.slice(x,R)||t.slice(m,$);b=0;for(let B of _.replaceAll(qM,"")){let tt=B.codePointAt(0)||0;if(Cp(tt))F=2;else if(Lp(tt))F=d;else F=f;if(N+F>S)E=Math.min(E,Math.max(x,m)+b);if(N+F>r){y=!0;break t}b+=B.length,N+=F}x=R=0}if($>=g)break t;for(let _=0,B=h.length;_<B;_++){let[tt,W]=h[_];if(tt.lastIndex=$,tt.test(t)){if(b=tt===jp?Fp(t.slice($,tt.lastIndex)):tt===_p?1:tt.lastIndex-$,F=b*W,N+F>S)E=Math.min(E,$+Math.floor((S-N)/W));if(N+F>r){y=!0;break t}N+=F,x=m,R=$,$=m=tt.lastIndex;continue t}}$+=1}return{width:y?S:N,index:y?E:g,truncated:y,ellipsed:y&&r>=s}},Bp=Gp;var JM={limit:1/0,ellipsis:"",ellipsisWidth:0},VM=(t,e={})=>{return Bp(t,JM,e).width},X=VM;function jl(t){let e=t.replace("#","");return[e.slice(0,2),e.slice(2,4),e.slice(4,6)].map((n)=>Number.parseInt(n,16)).join(";")}function Be(t){return`\x1B[38;2;${jl(t)}m`}function Ga(t,e){return`\x1B[48;2;${jl(t)};38;2;${jl(e)}m`}function Up(t,e="\x1B[39m"){return`${t.map((n)=>`${Be(n)}■`).join(" ")}${e}`}var At="\x1B[0m",at="\x1B[1m",A="\x1B[2m",ge="\x1B[22m",Zi="\x1B[32m",Vt="\x1B[33m",Ba="\x1B[36m",xn=["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"],uo="⧉";function Ua(t,e){return e?`\x1B]8;;${e}\x1B\\${t}\x1B]8;;\x1B\\`:t}function _l(t,e){if(t[e]!=="\x1B")return 0;if(t[e+1]==="]"){let r=t.indexOf("\x07",e+2),i=t.indexOf("\x1B\\",e+2),s=r!==-1&&(i===-1||r<i)?r+1:i!==-1?i+2:0;return s?s-e:0}if(t[e+1]!=="[")return 0;let n=e+2;while(n<t.length&&!/[@-~]/.test(t[n]))n++;return n<t.length?n-e+1:0}function Gl(t,e){let n="",r=0,i=0;while(i<t.length){let s=_l(t,i);if(s>0){n+=t.slice(i,i+s),i+=s;continue}let o=String.fromCodePoint(t.codePointAt(i)),a=X(o);if(r+a>e)break;n+=o,r+=a,i+=o.length}return{head:n,used:r}}function ot(t,e,n=!0){if(e<=0)return"";let r=X(t);if(r<=e)return n?t+" ".repeat(e-r):t;let{head:i,used:s}=Gl(t,e-1);return`${i}${t.includes("\x1B")?"\x1B[0m":""}…${n?" ".repeat(e-1-s):""}`}function Wp(t,e){let{head:n,used:r}=Gl(t,e);return`${n}${t.includes("\x1B")?At:""}${" ".repeat(e-r)}`}function Gt(t,e,n){let r=n-X(e)-1;return r<=0?ot(t,n):`${ot(t,r)} ${e}`}function bt(t,e){let n=[],r="";for(let i of t.split(/\s+/).filter(Boolean)){let s=r?`${r} ${i}`:i;if(X(s)<=e){r=s;continue}if(r)n.push(r);while(X(i)>e){let{head:o}=Gl(i,e),a=Math.max(o.lastIndexOf("/")+1,o.lastIndexOf("#")),c=a>0?a:o.length;n.push(i.slice(0,c)),i=i.slice(c)}r=i}if(r)n.push(r);return n}import{existsSync as g0,readFileSync as dd}from"node:fs";import{join as b0}from"node:path";var ZM=/^#[0-9a-f]{6}$/;function oe(t){return ZM.test(t)}function rt(t){let e=Number.parseInt(t.slice(1),16);return[e>>16&255,e>>8&255,e&255]}function Bt(t,e,n){let r=rt(t),i=rt(e);return`#${r.map((s,o)=>Math.round(s+((i[o]??0)-s)*n).toString(16).padStart(2,"0")).join("")}`}function vt(t){let[e,n,r]=rt(t).map((i)=>{let s=i/255;return s<=0.03928?s/12.92:((s+0.055)/1.055)**2.4});return 0.2126*e+0.7152*n+0.0722*r}function wt(t,e){let n=vt(t),r=vt(e);return(Math.max(n,r)+0.05)/(Math.min(n,r)+0.05)}function Wa(t,e){return Math.round(wt(t,e)*100)/100}function QM(t){let e=t/255;return e<=0.04045?e/12.92:((e+0.055)/1.055)**2.4}function St(t){let[e,n,r]=rt(t).map(QM),i=Math.cbrt(0.4122214708*e+0.5363325363*n+0.0514459929*r),s=Math.cbrt(0.2119034982*e+0.6806995451*n+0.1073969566*r),o=Math.cbrt(0.0883024619*e+0.2817188376*n+0.6299787005*r),a=1.9779984951*i-2.428592205*s+0.4505937099*o,c=0.0259040371*i+0.7827717662*s-0.808675766*o;return{l:0.2104542553*i+0.793617785*s-0.0040720468*o,c:Math.hypot(a,c),h:(Math.atan2(c,a)*180/Math.PI+360)%360}}var tr=7,Kp=3,Bl=0.15,zp=1.6,Wl=[1,2,3,4,5,6,9,10,11,12,13,14],Dp=[7,15],er=[1,2,3,4,5,6],be={1:{name:"red",center:19,width:25},2:{name:"green",center:132,width:35},3:{name:"yellow",center:88,width:35},4:{name:"blue",center:250,width:60},5:{name:"magenta",center:329,width:40},6:{name:"cyan",center:197,width:60}},fo=0.03,Ue=25,Qi=15,Xi=0.08;function In(t,e){let n=t.ansi[e];if(n===void 0)throw Error(`${t.name}: missing ANSI ${e}`);return n}function Ul(t,e,n){let r=t.background;return e.flatMap((i)=>{let s=In(t,i);return wt(s,r)<n?[`ANSI ${i} ${s} on ${r} is ${Wa(s,r)}:1, needs ${n}:1`]:[]})}function qp(t,e){return Math.min(...e.map((n)=>wt(In(t,n),t.background)))}var Yp=[{rule:"foreground",label:"foreground on background",unit:"ratio",min:tr,measure:({foreground:t,background:e})=>wt(t,e),check:({foreground:t,background:e})=>wt(t,e)<tr?[`foreground ${t} on ${e} is ${Wa(t,e)}:1, needs ${tr}:1`]:[]},{rule:"accents",label:"weakest accent on background",unit:"ratio",min:Kp,measure:(t)=>qp(t,Wl),check:(t)=>Ul(t,Wl,Kp)},{rule:"ansi0-dark",label:"ansi0 luminance",unit:"luminance",max:Bl,measure:(t)=>vt(In(t,0)),check:(t)=>{let e=In(t,0);return vt(e)>Bl?[`ANSI 0 ${e} has luminance ${vt(e).toFixed(3)}, needs <= ${Bl}`]:[]}},{rule:"light-ansi",label:"ansi7 and ansi15 on background",unit:"ratio",min:tr,measure:(t)=>qp(t,Dp),check:(t)=>Ul(t,Dp,tr)},{rule:"ansi8-visible",label:"ansi8 on background",unit:"ratio",min:zp,measure:(t)=>wt(In(t,8),t.background),check:(t)=>Ul(t,[8],zp)},{rule:"selection",label:"foreground on selection",unit:"ratio",min:tr,measure:({foreground:t,selectionBackground:e})=>e===void 0?Number.NaN:wt(t,e),check:({foreground:t,selectionBackground:e})=>e!==void 0&&wt(t,e)<tr?[`foreground ${t} on selection ${e} is ${Wa(t,e)}:1, needs ${tr}:1`]:[]}];function Ae(t,e){let n=Math.abs(t-e)%360;return Math.min(n,360-n)}var sn=(t)=>t>8?t-8:t;function ts(t){let e=t.signatureSlots.filter((n)=>n.startsWith("ansi")).map((n)=>Number(n.slice(4)));return new Set(e.flatMap((n)=>er.includes(sn(n))?[n,n>8?n-8:n+8]:[n]))}function lo(t,e){let n=St(In(t,e));return n.c<fo?void 0:n}function nr(t){let e=ts(t);return Wl.flatMap((n)=>{let r=lo(t,n),i=be[sn(n)];if(r===void 0||i===void 0||e.has(n))return[];let s=Ae(r.h,i.center)-i.width;return s>0?[{slot:n,hue:r.h,over:s}]:[]})}function Rn(t){let e=new Set(t.signatureSlots);return er.flatMap((n)=>{let r=lo(t,n),i=lo(t,n+8);if(r===void 0||i===void 0||e.has(`ansi${n}`)&&e.has(`ansi${n+8}`))return[];return[{normal:n,gap:Ae(r.h,i.h)}]})}function Nn(t){let e=ts(t);return[0,8].flatMap((n)=>er.flatMap((r)=>er.filter((i)=>i>r).flatMap((i)=>{let[s,o]=[n+r,n+i],a=lo(t,s),c=lo(t,o);if(a===void 0||c===void 0||e.has(s)&&e.has(o))return[];return Ae(a.h,c.h)<Qi&&Math.abs(a.l-c.l)<Xi?[[s,o]]:[]})))}var XM=[{rule:"ansi-role",label:"accent hue outside its ANSI role",unit:"degrees",max:0,measure:(t)=>Math.max(0,...nr(t).map((e)=>e.over)),check:(t)=>nr(t).map(({slot:e,hue:n,over:r})=>{let i=be[sn(e)];return`ANSI ${e} ${In(t,e)} has hue ${n.toFixed(0)}°, ${r.toFixed(0)}° outside ${i.name} (${i.center}±${i.width}°)`})},{rule:"bright-follows",label:"widest normal to bright hue gap",unit:"degrees",max:Ue,measure:(t)=>Math.max(0,...Rn(t).map((e)=>e.gap)),check:(t)=>Rn(t).filter((e)=>e.gap>Ue).map(({normal:e,gap:n})=>`ANSI ${e+8} is ${n.toFixed(0)}° from ANSI ${e}, needs <= ${Ue}°`)},{rule:"distinct",label:"accent pairs that read as one color",unit:"pairs",max:0,measure:(t)=>Nn(t).length,check:(t)=>Nn(t).map(([e,n])=>`ANSI ${e} ${In(t,e)} and ANSI ${n} ${In(t,n)} are within ${Qi}° hue and ${Xi} lightness`)}],Ka=[...Yp,...XM],Kl=Ka.map((t)=>t.rule),we=Ka.map(({rule:t,label:e,unit:n,min:r,max:i})=>({rule:t,label:e,unit:n,...r===void 0?{}:{min:r},...i===void 0?{}:{max:i}}));function on(t){return Ka.map((e)=>Math.round(e.measure(t)*1000)/1000)}function Jp(t,e){return t.filter((n)=>!e.waive.includes(n.rule)).flatMap((n)=>n.check(e).map((r)=>({theme:e.name,rule:n.rule,detail:r})))}function Qr(t){return Jp(Ka,t)}function Vp(t){return Jp(Yp,t)}function Zp(t){return t.flatMap(Qr)}import{chmodSync as tO,copyFileSync as eO,existsSync as es,mkdirSync as nO,readFileSync as zl,realpathSync as rO,renameSync as Xp,rmSync as Qp,statSync as iO,writeFileSync as tg}from"node:fs";import{dirname as sO}from"node:path";function eg(t){return`${t}.ttheme.bak`}var oO=/^(?:#|--) ttheme begin$|path = "ttheme-|^DefaultProfile=ttheme-/m;function Dl(t){let e=eg(t);if(es(t)&&!es(e)&&!oO.test(zl(t,"utf8")))eO(t,e)}function P(t,e){let n=es(t)?rO(t):t;nO(sO(n),{recursive:!0});let r=`${n}.ttheme-${process.pid}`;if(tg(r,e),es(n))tO(r,iO(n).mode&4095);Xp(r,n)}function Xr(t,e,n){if(tg(t,n),t!==e)Xp(t,e)}function an(t,e){if((es(t)?zl(t,"utf8"):void 0)===e)return!1;return Dl(t),P(t,e),!0}function ng(t,e){let n=eg(t),r=es(n)?zl(n,"utf8"):void 0;if(e===""&&r===void 0)return Qp(t,{force:!0}),"removed";if(P(t,e),r===void 0||r===e)return Qp(n,{force:!0}),"restored";return"kept backup"}import{createHash as fw}from"node:crypto";import{copyFileSync as e2,existsSync as Hf,mkdirSync as n2,readdirSync as r2,readFileSync as ms,renameSync as dw,rmSync as hs,statSync as i2}from"node:fs";import{basename as hw,isAbsolute as s2,join as D}from"node:path";import{createHash as xI}from"node:crypto";import{existsSync as II,readdirSync as RI,readFileSync as NI,rmSync as TI,statSync as AI,utimesSync as PI}from"node:fs";import{join as fs}from"node:path";import{readdirSync as Hx,rmSync as Fx,statSync as Cx}from"node:fs";import{setDefaultAutoSelectFamilyAttemptTimeout as Lx}from"node:net";import{homedir as jx}from"node:os";import{join as wo}from"node:path";import{setTimeout as _x}from"node:timers/promises";var Qg=Ll(Yg(),1);import{constants as Mx,deflateSync as Ox,inflateSync as xx}from"node:zlib";import{inflateRawSync as Ex}from"node:zlib";var vx=(()=>{var t=import.meta.url;return function(e={}){var n=e,r,i,s=new Promise((p,w)=>{r=p,i=w});let a=globalThis.ServiceWorkerGlobalScope!==void 0&&typeof self<"u"&&globalThis.caches&&globalThis.caches.default!==void 0,c=typeof process==="object"&&process.release&&process.release.name==="node";if(a||c){if(!globalThis.ImageData)globalThis.ImageData=class{constructor(w,k,v){this.data=w,this.width=k,this.height=v}};if(import.meta.url===void 0)import.meta.url="https://localhost";if(typeof self<"u"&&self.location===void 0)self.location={href:""}}var u=Object.assign({},n),l=[],f="./this.program",d=(p,w)=>{throw w},h=typeof window=="object",m=typeof importScripts=="function",$=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string",g="";function b(p){if(n.locateFile)return n.locateFile(p,g);return g+p}var y,E,S;if(h||m){if(m)g=self.location.href;else if(typeof document<"u"&&document.currentScript)g=document.currentScript.src;if(t)g=t;if(g.startsWith("blob:"))g="";else g=g.substr(0,g.replace(/[?#].*/,"").lastIndexOf("/")+1);{if(y=(p)=>{var w=new XMLHttpRequest;return w.open("GET",p,!1),w.send(null),w.responseText},m)S=(p)=>{var w=new XMLHttpRequest;return w.open("GET",p,!1),w.responseType="arraybuffer",w.send(null),new Uint8Array(w.response)};E=(p,w,k)=>{var v=new XMLHttpRequest;v.open("GET",p,!0),v.responseType="arraybuffer",v.onload=()=>{if(v.status==200||v.status==0&&v.response){w(v.response);return}k()},v.onerror=k,v.send(null)}}}var x=n.print||console.log.bind(console),R=n.printErr||console.error.bind(console);if(Object.assign(n,u),u=null,n.arguments)l=n.arguments;if(n.thisProgram)f=n.thisProgram;if(n.quit)d=n.quit;var N;if(n.wasmBinary)N=n.wasmBinary;var F,_=!1,B,tt,W,Q,U,yt,et,Xn,en;function nn(){var p=F.buffer;n.HEAP8=tt=new Int8Array(p),n.HEAP16=Q=new Int16Array(p),n.HEAPU8=W=new Uint8Array(p),n.HEAPU16=U=new Uint16Array(p),n.HEAP32=yt=new Int32Array(p),n.HEAPU32=et=new Uint32Array(p),n.HEAPF32=Xn=new Float32Array(p),n.HEAPF64=en=new Float64Array(p)}var rn=[],Ca=[],Dr=[],El=!1;function Sl(){if(n.preRun){if(typeof n.preRun=="function")n.preRun=[n.preRun];while(n.preRun.length)zE(n.preRun.shift())}xl(rn)}function Ml(){El=!0,xl(Ca)}function KE(){if(n.postRun){if(typeof n.postRun=="function")n.postRun=[n.postRun];while(n.postRun.length)qE(n.postRun.shift())}xl(Dr)}function zE(p){rn.unshift(p)}function DE(p){Ca.unshift(p)}function qE(p){Dr.unshift(p)}var qr=0,Ol=null,ao=null;function YE(p){qr++,n.monitorRunDependencies?.(qr)}function JE(p){if(qr--,n.monitorRunDependencies?.(qr),qr==0){if(Ol!==null)clearInterval(Ol),Ol=null;if(ao){var w=ao;ao=null,w()}}}function mp(p){n.onAbort?.(p),p="Aborted("+p+")",R(p),_=!0,B=1,p+=". Build with -sASSERTIONS for more info.";var w=new WebAssembly.RuntimeError(p);throw i(w),w}var VE="data:application/octet-stream;base64,",pp=(p)=>p.startsWith(VE),Yr;if(n.locateFile){if(Yr="mozjpeg_dec.wasm",!pp(Yr))Yr=b(Yr)}else Yr=new URL("mozjpeg_dec.wasm",import.meta.url).href;function gp(p){if(p==Yr&&N)return new Uint8Array(N);if(S)return S(p);throw"both async and sync fetching of the wasm failed"}function ZE(p){if(!N&&(h||m)){if(typeof fetch=="function")return fetch(p,{credentials:"same-origin"}).then((w)=>{if(!w.ok)throw`failed to load wasm binary file at '${p}'`;return w.arrayBuffer()}).catch(()=>gp(p))}return Promise.resolve().then(()=>gp(p))}function bp(p,w,k){return ZE(p).then((v)=>WebAssembly.instantiate(v,w)).then(k,(v)=>{R(`failed to asynchronously prepare wasm: ${v}`),mp(v)})}function QE(p,w,k,v){if(!p&&typeof WebAssembly.instantiateStreaming=="function"&&!pp(w)&&typeof fetch=="function")return fetch(w,{credentials:"same-origin"}).then((O)=>{var I=WebAssembly.instantiateStreaming(O,k);return I.then(v,function(C){return R(`wasm streaming compile failed: ${C}`),R("falling back to ArrayBuffer instantiation"),bp(w,k,v)})});return bp(w,k,v)}function XE(){var p={a:EM};function w(v,O){return Yt=v.exports,F=Yt.A,nn(),Mp=Yt.F,DE(Yt.B),JE("wasm-instantiate"),Yt}YE("wasm-instantiate");function k(v){w(v.instance)}if(n.instantiateWasm)try{return n.instantiateWasm(p,w)}catch(v){R(`Module.instantiateWasm callback failed with error: ${v}`),i(v)}return QE(N,Yr,p,k).catch(i),{}}function tS(p){this.name="ExitStatus",this.message=`Program terminated with exit(${p})`,this.status=p}var xl=(p)=>{while(p.length>0)p.shift()(n)},eS=n.noExitRuntime||!0;class wp{constructor(p){this.excPtr=p,this.ptr=p-24}set_type(p){et[this.ptr+4>>2]=p}get_type(){return et[this.ptr+4>>2]}set_destructor(p){et[this.ptr+8>>2]=p}get_destructor(){return et[this.ptr+8>>2]}set_caught(p){p=p?1:0,tt[this.ptr+12]=p}get_caught(){return tt[this.ptr+12]!=0}set_rethrown(p){p=p?1:0,tt[this.ptr+13]=p}get_rethrown(){return tt[this.ptr+13]!=0}init(p,w){this.set_adjusted_ptr(0),this.set_type(p),this.set_destructor(w)}set_adjusted_ptr(p){et[this.ptr+16>>2]=p}get_adjusted_ptr(){return et[this.ptr+16>>2]}get_exception_ptr(){var p=Ap(this.get_type());if(p)return et[this.excPtr>>2];var w=this.get_adjusted_ptr();if(w!==0)return w;return this.excPtr}}var $p=0,nS=0,rS=(p,w,k)=>{var v=new wp(p);throw v.init(w,k),$p=p,nS++,$p},iS=(p,w,k,v,O)=>{},sS=()=>{var p=Array(256);for(var w=0;w<256;++w)p[w]=String.fromCharCode(w);kp=p},kp,Ge=(p)=>{var w="",k=p;while(W[k])w+=kp[W[k++]];return w},qi={},Jr={},La={},yp,pe=(p)=>{throw new yp(p)},vp,Ep=(p)=>{throw new vp(p)},oS=(p,w,k)=>{p.forEach(function(T){La[T]=w});function v(T){var G=k(T);if(G.length!==p.length)Ep("Mismatched type converter count");for(var V=0;V<p.length;++V)Sn(p[V],G[V])}var O=Array(w.length),I=[],C=0;if(w.forEach((T,G)=>{if(Jr.hasOwnProperty(T))O[G]=Jr[T];else{if(I.push(T),!qi.hasOwnProperty(T))qi[T]=[];qi[T].push(()=>{if(O[G]=Jr[T],++C,C===I.length)v(O)})}}),I.length===0)v(O)};function aS(p,w,k={}){var v=w.name;if(!p)pe(`type "${v}" must have a positive integer typeid pointer`);if(Jr.hasOwnProperty(p))if(k.ignoreDuplicateRegistrations)return;else pe(`Cannot register type '${v}' twice`);if(Jr[p]=w,delete La[p],qi.hasOwnProperty(p)){var O=qi[p];delete qi[p],O.forEach((I)=>I())}}function Sn(p,w,k={}){if(!("argPackAdvance"in w))throw TypeError("registerType registeredInstance requires argPackAdvance");return aS(p,w,k)}var Vr=8,cS=(p,w,k,v)=>{w=Ge(w),Sn(p,{name:w,fromWireType:function(O){return!!O},toWireType:function(O,I){return I?k:v},argPackAdvance:Vr,readValueFromPointer:function(O){return this.fromWireType(W[O])},destructorFunction:null})},Il=[],Mn=[],Rl=(p)=>{if(p>9&&--Mn[p+1]===0)Mn[p]=void 0,Il.push(p)},uS=()=>Mn.length/2-5-Il.length,lS=()=>{Mn.push(0,1,void 0,1,null,1,!0,1,!1,1),n.count_emval_handles=uS},Zr={toValue:(p)=>{if(!p)pe("Cannot use deleted val. handle = "+p);return Mn[p]},toHandle:(p)=>{switch(p){case void 0:return 2;case null:return 4;case!0:return 6;case!1:return 8;default:{let w=Il.pop()||Mn.length;return Mn[w]=p,Mn[w+1]=1,w}}}};function Nl(p){return this.fromWireType(et[p>>2])}var fS={name:"emscripten::val",fromWireType:(p)=>{var w=Zr.toValue(p);return Rl(p),w},toWireType:(p,w)=>Zr.toHandle(w),argPackAdvance:Vr,readValueFromPointer:Nl,destructorFunction:null},dS=(p)=>Sn(p,fS),hS=(p,w)=>{switch(w){case 4:return function(k){return this.fromWireType(Xn[k>>2])};case 8:return function(k){return this.fromWireType(en[k>>3])};default:throw TypeError(`invalid float width (${w}): ${p}`)}},mS=(p,w,k)=>{w=Ge(w),Sn(p,{name:w,fromWireType:(v)=>v,toWireType:(v,O)=>O,argPackAdvance:Vr,readValueFromPointer:hS(w,k),destructorFunction:null})},Tl=(p,w)=>Object.defineProperty(w,"name",{value:p}),Sp=(p)=>{while(p.length){var w=p.pop(),k=p.pop();k(w)}};function pS(p){for(var w=1;w<p.length;++w)if(p[w]!==null&&p[w].destructorFunction===void 0)return!0;return!1}function gS(p,w,k,v,O,I){var C=w.length;if(C<2)pe("argTypes array size mismatch! Must at least get return value and 'this' types!");var T=w[1]!==null&&k!==null,G=pS(w),V=w[0].name!=="void",ht=C-2,xt=Array(ht),Jt=[],Te=[],Yi=function(...Fl){if(Fl.length!==ht)pe(`function ${p} called with ${Fl.length} arguments, expected ${ht}`);Te.length=0;var Cl;if(Jt.length=T?2:1,Jt[0]=O,T)Cl=w[1].toWireType(Te,this),Jt[1]=Cl;for(var Ji=0;Ji<ht;++Ji)xt[Ji]=w[Ji+2].toWireType(Te,Fl[Ji]),Jt.push(xt[Ji]);var NM=v(...Jt);function TM(AM){if(G)Sp(Te);else for(var Vi=T?1:2;Vi<w.length;Vi++){var PM=Vi===1?Cl:xt[Vi-2];if(w[Vi].destructorFunction!==null)w[Vi].destructorFunction(PM)}if(V)return w[0].fromWireType(AM)}return TM(NM)};return Tl(p,Yi)}var bS=(p,w,k)=>{if(p[w].overloadTable===void 0){var v=p[w];p[w]=function(...O){if(!p[w].overloadTable.hasOwnProperty(O.length))pe(`Function '${k}' called with an invalid number of arguments (${O.length}) - expects one of (${p[w].overloadTable})!`);return p[w].overloadTable[O.length].apply(this,O)},p[w].overloadTable=[],p[w].overloadTable[v.argCount]=v}},wS=(p,w,k)=>{if(n.hasOwnProperty(p)){if(k===void 0||n[p].overloadTable!==void 0&&n[p].overloadTable[k]!==void 0)pe(`Cannot register public name '${p}' twice`);if(bS(n,p,p),n.hasOwnProperty(k))pe(`Cannot register multiple overloads of a function with the same number of arguments (${k})!`);n[p].overloadTable[k]=w}else if(n[p]=w,k!==void 0)n[p].numArguments=k},$S=(p,w)=>{var k=[];for(var v=0;v<p;v++)k.push(et[w+v*4>>2]);return k},kS=(p,w,k)=>{if(!n.hasOwnProperty(p))Ep("Replacing nonexistent public symbol");if(n[p].overloadTable!==void 0&&k!==void 0)n[p].overloadTable[k]=w;else n[p]=w,n[p].argCount=k},yS=(p,w,k)=>{p=p.replace(/p/g,"i");var v=n["dynCall_"+p];return v(w,...k)},ja=[],Mp,Op=(p)=>{var w=ja[p];if(!w){if(p>=ja.length)ja.length=p+1;ja[p]=w=Mp.get(p)}return w},vS=(p,w,k=[])=>{if(p.includes("j"))return yS(p,w,k);var v=Op(w)(...k);return v},ES=(p,w)=>(...k)=>vS(p,w,k),SS=(p,w)=>{p=Ge(p);function k(){if(p.includes("j"))return ES(p,w);return Op(w)}var v=k();if(typeof v!="function")pe(`unknown function pointer with signature ${p}: ${w}`);return v},MS=(p,w)=>{var k=Tl(w,function(v){this.name=w,this.message=v;var O=Error(v).stack;if(O!==void 0)this.stack=this.toString()+`
3
- `+O.replace(/^Error(:[^\n]*)?\n/,"")});return k.prototype=Object.create(p.prototype),k.prototype.constructor=k,k.prototype.toString=function(){if(this.message===void 0)return this.name;else return`${this.name}: ${this.message}`},k},xp,Ip=(p)=>{var w=Tp(p),k=Ge(w);return On(w),k},OS=(p,w)=>{var k=[],v={};function O(I){if(v[I])return;if(Jr[I])return;if(La[I]){La[I].forEach(O);return}k.push(I),v[I]=!0}throw w.forEach(O),new xp(`${p}: `+k.map(Ip).join([", "]))},xS=(p)=>{p=p.trim();let w=p.indexOf("(");if(w!==-1)return p.substr(0,w);else return p},IS=(p,w,k,v,O,I,C)=>{var T=$S(w,k);p=Ge(p),p=xS(p),O=SS(v,O),wS(p,function(){OS(`Cannot call ${p} due to unbound types`,T)},w-1),oS([],T,(G)=>{var V=[G[0],null].concat(G.slice(1));return kS(p,gS(p,V,null,O,I,C),w-1),[]})},RS=(p,w,k)=>{switch(w){case 1:return k?(v)=>tt[v]:(v)=>W[v];case 2:return k?(v)=>Q[v>>1]:(v)=>U[v>>1];case 4:return k?(v)=>yt[v>>2]:(v)=>et[v>>2];default:throw TypeError(`invalid integer width (${w}): ${p}`)}},NS=(p,w,k,v,O)=>{if(w=Ge(w),O===-1)O=4294967295;var I=(ht)=>ht;if(v===0){var C=32-8*k;I=(ht)=>ht<<C>>>C}var T=w.includes("unsigned"),G=(ht,xt)=>{},V;if(T)V=function(ht,xt){return G(xt,this.name),xt>>>0};else V=function(ht,xt){return G(xt,this.name),xt};Sn(p,{name:w,fromWireType:I,toWireType:V,argPackAdvance:Vr,readValueFromPointer:RS(w,k,v!==0),destructorFunction:null})},TS=(p,w,k)=>{var v=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],O=v[w];function I(C){var T=et[C>>2],G=et[C+4>>2];return new O(tt.buffer,G,T)}k=Ge(k),Sn(p,{name:k,fromWireType:I,argPackAdvance:Vr,readValueFromPointer:I},{ignoreDuplicateRegistrations:!0})},AS=(p,w,k,v)=>{if(!(v>0))return 0;var O=k,I=k+v-1;for(var C=0;C<p.length;++C){var T=p.charCodeAt(C);if(T>=55296&&T<=57343){var G=p.charCodeAt(++C);T=65536+((T&1023)<<10)|G&1023}if(T<=127){if(k>=I)break;w[k++]=T}else if(T<=2047){if(k+1>=I)break;w[k++]=192|T>>6,w[k++]=128|T&63}else if(T<=65535){if(k+2>=I)break;w[k++]=224|T>>12,w[k++]=128|T>>6&63,w[k++]=128|T&63}else{if(k+3>=I)break;w[k++]=240|T>>18,w[k++]=128|T>>12&63,w[k++]=128|T>>6&63,w[k++]=128|T&63}}return w[k]=0,k-O},PS=(p,w,k)=>AS(p,W,w,k),HS=(p)=>{var w=0;for(var k=0;k<p.length;++k){var v=p.charCodeAt(k);if(v<=127)w++;else if(v<=2047)w+=2;else if(v>=55296&&v<=57343)w+=4,++k;else w+=3}return w},Rp=(p,w,k)=>{var v=w+k,O="";while(!(w>=v)){var I=p[w++];if(!I)return O;if(!(I&128)){O+=String.fromCharCode(I);continue}var C=p[w++]&63;if((I&224)==192){O+=String.fromCharCode((I&31)<<6|C);continue}var T=p[w++]&63;if((I&240)==224)I=(I&15)<<12|C<<6|T;else I=(I&7)<<18|C<<12|T<<6|p[w++]&63;if(I<65536)O+=String.fromCharCode(I);else{var G=I-65536;O+=String.fromCharCode(55296|G>>10,56320|G&1023)}}return O},FS=(p,w)=>p?Rp(W,p,w):"",CS=(p,w)=>{w=Ge(w);var k=w==="std::string";Sn(p,{name:w,fromWireType(v){var O=et[v>>2],I=v+4,C;if(k){var T=I;for(var G=0;G<=O;++G){var V=I+G;if(G==O||W[V]==0){var ht=V-T,xt=FS(T,ht);if(C===void 0)C=xt;else C+=String.fromCharCode(0),C+=xt;T=V+1}}}else{var Jt=Array(O);for(var G=0;G<O;++G)Jt[G]=String.fromCharCode(W[I+G]);C=Jt.join("")}return On(v),C},toWireType(v,O){if(O instanceof ArrayBuffer)O=new Uint8Array(O);var I,C=typeof O=="string";if(!(C||O instanceof Uint8Array||O instanceof Uint8ClampedArray||O instanceof Int8Array))pe("Cannot pass non-string to std::string");if(k&&C)I=HS(O);else I=O.length;var T=Hl(4+I+1),G=T+4;if(et[T>>2]=I,k&&C)PS(O,G,I+1);else if(C)for(var V=0;V<I;++V){var ht=O.charCodeAt(V);if(ht>255)On(G),pe("String has UTF-16 code units that do not fit in 8 bits");W[G+V]=ht}else for(var V=0;V<I;++V)W[G+V]=O[V];if(v!==null)v.push(On,T);return T},argPackAdvance:Vr,readValueFromPointer:Nl,destructorFunction(v){On(v)}})},LS=(p,w)=>{var k="";for(var v=0;!(v>=w/2);++v){var O=Q[p+v*2>>1];if(O==0)break;k+=String.fromCharCode(O)}return k},jS=(p,w,k)=>{if(k??=2147483647,k<2)return 0;k-=2;var v=w,O=k<p.length*2?k/2:p.length;for(var I=0;I<O;++I){var C=p.charCodeAt(I);Q[w>>1]=C,w+=2}return Q[w>>1]=0,w-v},_S=(p)=>p.length*2,GS=(p,w)=>{var k=0,v="";while(!(k>=w/4)){var O=yt[p+k*4>>2];if(O==0)break;if(++k,O>=65536){var I=O-65536;v+=String.fromCharCode(55296|I>>10,56320|I&1023)}else v+=String.fromCharCode(O)}return v},BS=(p,w,k)=>{if(k??=2147483647,k<4)return 0;var v=w,O=v+k-4;for(var I=0;I<p.length;++I){var C=p.charCodeAt(I);if(C>=55296&&C<=57343){var T=p.charCodeAt(++I);C=65536+((C&1023)<<10)|T&1023}if(yt[w>>2]=C,w+=4,w+4>O)break}return yt[w>>2]=0,w-v},US=(p)=>{var w=0;for(var k=0;k<p.length;++k){var v=p.charCodeAt(k);if(v>=55296&&v<=57343)++k;w+=4}return w},WS=(p,w,k)=>{k=Ge(k);var v,O,I,C;if(w===2)v=LS,O=jS,C=_S,I=(T)=>U[T>>1];else if(w===4)v=GS,O=BS,C=US,I=(T)=>et[T>>2];Sn(p,{name:k,fromWireType:(T)=>{var G=et[T>>2],V,ht=T+4;for(var xt=0;xt<=G;++xt){var Jt=T+4+xt*w;if(xt==G||I(Jt)==0){var Te=Jt-ht,Yi=v(ht,Te);if(V===void 0)V=Yi;else V+=String.fromCharCode(0),V+=Yi;ht=Jt+w}}return On(T),V},toWireType:(T,G)=>{if(typeof G!="string")pe(`Cannot pass non-string to C++ string type ${k}`);var V=C(G),ht=Hl(4+V+w);if(et[ht>>2]=V/w,O(G,ht+4,V+w),T!==null)T.push(On,ht);return ht},argPackAdvance:Vr,readValueFromPointer:Nl,destructorFunction(T){On(T)}})},KS=(p,w)=>{w=Ge(w),Sn(p,{isVoid:!0,name:w,argPackAdvance:0,fromWireType:()=>{return},toWireType:(k,v)=>{return}})},zS=(p,w,k)=>W.copyWithin(p,w,w+k),Al=[],DS=(p,w,k,v)=>{return p=Al[p],w=Zr.toValue(w),p(null,w,k,v)},qS={},YS=(p)=>{var w=qS[p];if(w===void 0)return Ge(p);return w},Np=()=>{if(typeof globalThis=="object")return globalThis;function p(w){w.$$$embind_global$$$=w;var k=typeof $$$embind_global$$$=="object"&&w.$$$embind_global$$$==w;if(!k)delete w.$$$embind_global$$$;return k}if(typeof $$$embind_global$$$=="object")return $$$embind_global$$$;if(typeof global=="object"&&p(global))$$$embind_global$$$=global;else if(typeof self=="object"&&p(self))$$$embind_global$$$=self;if(typeof $$$embind_global$$$=="object")return $$$embind_global$$$;throw Error("unable to get global object.")},JS=(p)=>{if(p===0)return Zr.toHandle(Np());else return p=YS(p),Zr.toHandle(Np()[p])},VS=(p)=>{var w=Al.length;return Al.push(p),w},ZS=(p,w)=>{var k=Jr[p];if(k===void 0)pe(`${w} has unknown type ${Ip(p)}`);return k},QS=(p,w)=>{var k=Array(p);for(var v=0;v<p;++v)k[v]=ZS(et[w+v*4>>2],"parameter "+v);return k},XS=Reflect.construct,tM=(p,w,k)=>{var v=[],O=p.toWireType(v,k);if(v.length)et[w>>2]=Zr.toHandle(v);return O},eM=(p,w,k)=>{var v=QS(p,w),O=v.shift();p--;var I=Array(p),C=(G,V,ht,xt)=>{var Jt=0;for(var Te=0;Te<p;++Te)I[Te]=v[Te].readValueFromPointer(xt+Jt),Jt+=v[Te].argPackAdvance;var Yi=k===1?XS(V,I):V.apply(G,I);return tM(O,ht,Yi)},T=`methodCaller<(${v.map((G)=>G.name).join(", ")}) => ${O.name}>`;return VS(Tl(T,C))},nM=(p)=>{if(p>9)Mn[p+1]+=1},rM=(p)=>{var w=Zr.toValue(p);Sp(w),Rl(p)},iM=()=>{mp("")},sM=()=>2147483648,oM=(p)=>{var w=F.buffer,k=(p-w.byteLength+65535)/65536;try{return F.grow(k),nn(),1}catch(v){}},aM=(p)=>{var w=W.length;p>>>=0;var k=sM();if(p>k)return!1;var v=(G,V)=>G+(V-G%V)%V;for(var O=1;O<=4;O*=2){var I=w*(1+0.2/O);I=Math.min(I,p+100663296);var C=Math.min(k,v(Math.max(p,I),65536)),T=oM(C);if(T)return!0}return!1},Pl={},cM=()=>f||"./this.program",co=()=>{if(!co.strings){var p=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",w={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:p,_:cM()};for(var k in Pl)if(Pl[k]===void 0)delete w[k];else w[k]=Pl[k];var v=[];for(var k in w)v.push(`${k}=${w[k]}`);co.strings=v}return co.strings},uM=(p,w)=>{for(var k=0;k<p.length;++k)tt[w++]=p.charCodeAt(k);tt[w]=0},lM=(p,w)=>{var k=0;return co().forEach((v,O)=>{var I=w+k;et[p+O*4>>2]=I,uM(v,I),k+=v.length+1}),0},fM=(p,w)=>{var k=co();et[p>>2]=k.length;var v=0;return k.forEach((O)=>v+=O.length+1),et[w>>2]=v,0},dM=0,hM=()=>eS||dM>0,mM=(p)=>{if(B=p,!hM())n.onExit?.(p),_=!0;d(p,new tS(p))},pM=(p,w)=>{B=p,mM(p)},gM=pM,bM=(p)=>52,wM=(p,w)=>w+2097152>>>0<4194305-!!p?(p>>>0)+w*4294967296:NaN;function $M(p,w,k,v,O){var I=wM(w,k);return 70}var kM=[null,[],[]],yM=(p,w)=>{var k=kM[p];if(w===0||w===10)(p===1?x:R)(Rp(k,0)),k.length=0;else k.push(w)},vM=(p,w,k,v)=>{var O=0;for(var I=0;I<k;I++){var C=et[w>>2],T=et[w+4>>2];w+=8;for(var G=0;G<T;G++)yM(p,W[C+G]);O+=T}return et[v>>2]=O,0};sS(),yp=n.BindingError=class extends Error{constructor(w){super(w);this.name="BindingError"}},vp=n.InternalError=class extends Error{constructor(w){super(w);this.name="InternalError"}},lS(),xp=n.UnboundTypeError=MS(Error,"UnboundTypeError");var EM={o:rS,q:iS,m:cS,l:dS,j:mS,f:IS,b:NS,a:TS,e:CS,c:WS,n:KS,v:zS,i:DS,d:Rl,k:JS,h:eM,y:nM,g:rM,r:iM,s:aM,t:lM,u:fM,z:gM,w:bM,p:$M,x:vM},Yt=XE(),SM=()=>(SM=Yt.B)(),Tp=(p)=>(Tp=Yt.C)(p),Hl=(p)=>(Hl=Yt.D)(p),On=(p)=>(On=Yt.E)(p),MM=(p)=>(MM=Yt._emscripten_stack_restore)(p),OM=(p)=>(OM=Yt._emscripten_stack_alloc)(p),xM=()=>(xM=Yt.emscripten_stack_get_current)(),IM=(p)=>(IM=Yt.__cxa_increment_exception_refcount)(p),Ap=(p)=>(Ap=Yt.G)(p),RM=n.dynCall_jiji=(p,w,k,v,O)=>(RM=n.dynCall_jiji=Yt.H)(p,w,k,v,O),_a;ao=function p(){if(!_a)Pp();if(!_a)ao=p};function Pp(){if(qr>0)return;if(Sl(),qr>0)return;function p(){if(_a)return;if(_a=!0,n.calledRun=!0,_)return;if(Ml(),r(n),n.onRuntimeInitialized)n.onRuntimeInitialized();KE()}if(n.setStatus)n.setStatus("Running..."),setTimeout(function(){setTimeout(function(){n.setStatus("")},1),p()},1);else p()}if(n.preInit){if(typeof n.preInit=="function")n.preInit=[n.preInit];while(n.preInit.length>0)n.preInit.pop()()}return Pp(),s}})(),Jg=vx;function cf(t){if(t[0]!==255||t[1]!==216)return null;let e=2;while(e+9<t.length){if(t[e]!==255){e++;continue}let n=t[e+1];if(n===255){e++;continue}let r=t[e+2]<<8|t[e+3];if(n>=192&&n<=207&&n!==196&&n!==200&&n!==204)return{height:t[e+5]<<8|t[e+6],width:t[e+7]<<8|t[e+8]};e+=2+r}return null}var af;function Sx(){if(af)return af;let t=new WebAssembly.Module(Ex(Buffer.from("7L0NnFzHVSd6q+5H3+7bPdMjjeyRZmTf7ohFITZWgpFN4mBdEX3Y8leI15jfy+6a3UC8Mwp4ZEWYRdaMY9kICESA2TWsCXrBb+2wNugtejwvmBcFDBFgFgXMRkkMEYtJzBLA720A78PY+/+fU3X73u4eSVYMC1mUePre+rqnTp06derUqXOCb7rzPSYIAvN/m9nbzFKA/8zSbeHSEn/sEhLiJf4Lbov0x0pOY2nJJWu2q+NK4S1gzgH8C25LfFH3gNwIWUgIlw4smQOuzn40vZ/to0rEmihnmIxsNsM6BwS+A/wWHkMpZH/MrDPfZL4paOLvPw8i/P0X8vwu9OqbzDcHIf5+S9DA33dLyu2Bxd9/GUzh77yUXAgM/u6W3PcEMf5+q9T6Nsm9I0jxd1Fa2BNk+HunlN8bJPj7Xvm7T0p+u6TfFbTw9zuktX8VBOFvm48ba2y7ZdqTQTu0q1bbaHI6MGEzNUFs19h2aLKgzUEwYXBB0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6Xl1+80Glnns9OFtPvHvh9iC5x946fvyTDx4/jgG8a1dqbCzZn93XCbnIrtJgdngXqZnsggpVgei8WolZ/BpwBO2LeMC74JfjPYc9Om8Egj8C+HvOnAR+hERoE+GPTQp/DuALvEPojkHws8GNxM6StrgOz4/heTXcx2ntBvcJVZXWYsx3A9hESPL2Za46vfRZkv8+xNuG94Nw/fr9LriUfr8XblC/PwCX1O+PwJX0+9NwZf3+LFxWv78EN6Tf34TL6fcAiOSwfo/jfUy/z8f7Af3ehvcB/b60Xfqa3le1V9cT76XsZN3C9dxEEy7q2Vc+p7LHrH/3I+wjeF4L98eKYDo7c4Xd4A9k+5zi3wWY9y8S+GMa/roK/GLZgNURdJ5Pt0va9KO8qa/+xNVX18P9KdwNcDdyOuc4BVea0Ziv8yy3S/xPVsX/FNxNcJ/W8Jfr/KisN+N5CxxGgroV7jNwf6YS1/xYmZHxJbIACoKO4tt3uUrcj2f0CvhdCXfXEhx7owAsIp/5sYfQHnoG3lf9Bw==","base64"))),e={noInitialRun:!0,print:()=>{return},printErr:()=>{return},instantiateWasm:(n,r)=>{let i=new WebAssembly.Instance(t,n);return r(i),i.exports}};if(Jg(e),typeof e.decode!=="function")throw Error("the JPEG decoder did not start");return af=e,e}function Vg(t,e){let n=cf(t);if(n&&n.width*n.height>e)throw Error(`${n.width}×${n.height} is over ${e/1e6} megapixels`);let r=null;try{r=Sx().decode(t,!0)}catch{r=null}if(!r)throw Error("not a JPEG image this decoder can read");return{width:r.width,height:r.height,data:new Uint8Array(r.data.buffer,r.data.byteOffset,r.data.length)}}var ss=[137,80,78,71,13,10,26,10],Xg=13,tb=3;function ei(t){return t.length>=ss.length&&ss.every((e,n)=>t[n]===e)}var eb={0:1,2:3,4:2,6:4};function Ix(t){if(t.length<33||!ei(t))return;let e=Buffer.from(t.buffer,t.byteOffset,t.byteLength),n=e.readUInt32BE(16),r=e.readUInt32BE(20),i=e[25];if(e[24]!==8||e[28]!==0||eb[i]===void 0)return;let s=[];for(let o=8;o+12<=e.length;){let a=e.readUInt32BE(o),c=e.toString("latin1",o+4,o+8);if(c==="IDAT")s.push(e.subarray(o+8,o+8+a));else if(c==="tRNS"||c==="IEND"){if(c==="tRNS"&&i!==4&&i!==6)return;break}o+=12+a}return s.length>0?{width:n,height:r,type:i,idat:s}:void 0}function Rx(t,e,n,r){let i=new Uint8Array(e);for(let s=0;s<n;s++){let o=s*(e+1),a=t[o],c=o+1,u=s>0?t:i,l=s>0?c-e-1:0;if(a===1)for(let f=r;f<e;f++)t[c+f]=t[c+f]+t[c+f-r];else if(a===2)for(let f=0;f<e;f++)t[c+f]=t[c+f]+u[l+f];else if(a===3){for(let f=0;f<r;f++)t[c+f]=t[c+f]+(u[l+f]>>1);for(let f=r;f<e;f++)t[c+f]=t[c+f]+(t[c+f-r]+u[l+f]>>1)}else if(a===4){for(let f=0;f<r;f++)t[c+f]=t[c+f]+u[l+f];for(let f=r;f<e;f++){let d=t[c+f-r],h=u[l+f],m=u[l+f-r],$=Math.abs(h-m),g=Math.abs(d-m),b=Math.abs(d+h-2*m);t[c+f]=t[c+f]+($<=g&&$<=b?d:g<=b?h:m)}}else if(a!==0)throw Error(`bad PNG filter ${a}`)}}function Nx(t){let{width:e,height:n,type:r}=t,i=eb[r],s=e*i,o=xx(Buffer.concat(t.idat),{chunkSize:Math.min(268435456,Math.max(65536,n*(s+1)))});if(o.length<n*(s+1))throw Error("truncated PNG");Rx(o,s,n,i);let a=new Uint8Array(e*n*4);for(let c=0;c<n;c++){let u=c*(s+1)+1,l=c*e*4;if(r===6)a.set(o.subarray(u,u+s),l);else if(r===2)for(let f=0,d=u,h=l;f<e;f++,d+=3,h+=4)a[h]=o[d],a[h+1]=o[d+1],a[h+2]=o[d+2],a[h+3]=255;else if(r===0)for(let f=0,d=l;f<e;f++,d+=4){let h=o[u+f];a[d]=h,a[d+1]=h,a[d+2]=h,a[d+3]=255}else for(let f=0,d=u,h=l;f<e;f++,d+=2,h+=4){let m=o[d];a[h]=m,a[h+1]=m,a[h+2]=m,a[h+3]=o[d+1]}}return{width:e,height:n,data:a}}function Ht(t){let e=Ix(t);if(e)return Nx(e);let n=Qg.PNG.sync.read(Buffer.from(t));return{width:n.width,height:n.height,data:new Uint8Array(n.data)}}function or(t,e){if(ei(t)){let n=un(t);if(n&&n.width*n.height>e)throw Error(`${n.width}×${n.height} is over ${e/1e6} megapixels`);return Ht(t)}if(t[0]===255&&t[1]===216)return Vg(t,e);throw Error("not a PNG or JPEG image")}function nb(t,e){let{width:n,height:r,at:i}=e,s=Math.max(0,i.x),o=Math.max(0,i.y),a=Math.min(n,i.x+i.w),c=Math.min(r,i.y+i.h);if(a<=s||c<=o)return;let u={x:s,y:o,w:a-s,h:c-o};if(i.w===t.width&&i.h===t.height)return{part:t,box:u,dx:s-i.x,dy:o-i.y};let l={x:(s-i.x)*t.width/i.w,y:(o-i.y)*t.height/i.h,w:u.w*t.width/i.w,h:u.h*t.height/i.h};return{part:mo(t,l,u.w,u.h),box:u,dx:0,dy:0}}function rb(t,e){let n=new Uint8Array(e.width*e.height*4),r=nb(t,e);if(r){let{part:i,box:s,dx:o,dy:a}=r;for(let c=0;c<s.h;c++){let u=((c+a)*i.width+o)*4;n.set(i.data.subarray(u,u+s.w*4),((s.y+c)*e.width+s.x)*4)}}return{width:e.width,height:e.height,data:n}}function ar(t,e,n,r={width:t.width,height:t.height,at:{x:0,y:0,w:t.width,h:t.height}}){let i=rt(e),{width:s,height:o}=r,a=new Uint8Array(s*o*3);for(let h=0;h<s*3;h+=3)a.set(i,h);for(let h=1;h<o;h++)a.copyWithin(h*s*3,0,s*3);let c=nb(t,r);if(!c)return{width:s,height:o,data:a};let{part:u,box:l,dx:f,dy:d}=c;for(let h=0;h<l.h;h++)for(let m=0;m<l.w;m++){let $=((h+d)*u.width+m+f)*4,g=((l.y+h)*s+l.x+m)*3,b=u.data[$+3]/255*n;for(let y=0;y<3;y++)a[g+y]=Math.round(i[y]*(1-b)+u.data[$+y]*b)}return{width:s,height:o,data:a}}function Zg(t,e){for(let n=0;n+e.length<=t.length;n++){let r=!0;for(let i=0;i<e.length&&r;i++)r=t[n+i]===e.charCodeAt(i);if(r)return n}return-1}function un(t){if(t.length<33||!ei(t))return null;let e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=e.getUint32(16),r=e.getUint32(20);if(t[25]===4||t[25]===6)return{width:n,height:r,alpha:!0};let i=Zg(t,"IDAT");return{width:n,height:r,alpha:Zg(i===-1?t:t.subarray(0,i),"tRNS")!==-1}}function ib(t,e=Xg){let{width:n,height:r,data:i}=t,s=(l)=>{for(let f=l*n*4+3,d=f+n*4;f<d;f+=4)if(i[f]>=e)return!0;return!1},o=0;while(o<r&&!s(o))o++;if(o===r)return null;let a=r-1;while(!s(a))a--;let c=n,u=-1;for(let l=o;l<=a;l++){let f=l*n*4+3;for(let d=0;d<c;d++)if(i[f+d*4]>=e){c=d;break}for(let d=n-1;d>u;d--)if(i[f+d*4]>=e){u=d;break}}return{x:c,y:o,w:u-c+1,h:a-o+1}}function Tn(t,e={x:0,y:0,w:t.width,h:t.height}){let n=0;for(let r=e.y;r<e.y+e.h;r++)for(let i=e.x;i<e.x+e.w;i++)if((t.data[(r*t.width+i)*4+3]??0)<Xg)n++;return Math.round(n*100/(e.w*e.h))}function sb(t,e,n){let r=Math.min(e/t.width,n/t.height),i=Math.max(1,Math.round(t.width*r)),s=Math.max(1,Math.round(t.height*r)),o=mo(t,{x:0,y:0,w:t.width,h:t.height},i,s),a=new Uint8Array(e*n*4),c=Math.floor((e-i)/2),u=Math.floor((n-s)/2);for(let l=0;l<s;l++)a.set(o.data.subarray(l*i*4,(l+1)*i*4),((u+l)*e+c)*4);return{width:e,height:n,data:a}}function Tx(t){let e=Math.abs(t);if(e<1)return(7*e*e*e-12*e*e+5.333333333333333)/6;if(e<2)return(-2.3333333333333335*e*e*e+12*e*e-20*e+10.666666666666666)/6;return 0}function uf(t,e,n,r){if(n===r&&Number.isInteger(e)&&e>=0&&e+r<=t)return{first:Int32Array.from({length:r},(l,f)=>e+f),size:1,weights:new Float32Array(r).fill(1)};let i=n/r,s=Math.max(1,i),o=2*s,a=Math.min(t,Math.ceil(2*o)+2),c=new Int32Array(r),u=new Float32Array(r*a);for(let l=0;l<r;l++){let f=e+(l+0.5)*i,d=Math.floor(f-o-0.5),h=Math.max(0,Math.min(t-a,d));c[l]=h;let m=0;for(let $=d;$<=Math.ceil(f+o-0.5);$++){let g=Tx(($+0.5-f)/s),b=l*a+Math.min(t-1,Math.max(0,$))-h;u[b]=(u[b]??0)+g,m+=g}for(let $=l*a;$<(l+1)*a;$++)u[$]=(u[$]??0)/m}return{first:c,size:a,weights:u}}function ob(t,e,n,r,i,s,o){let a=uf(t,e.y,e.h,r),c=n*i,u=a.size+1,l=Array.from({length:u},()=>new Float32Array(c)),f=new Int32Array(u).fill(-1),d=new Float32Array(c),h=[],m=[];for(let $=0;$<r;$++){h.length=0,m.length=0;let g=a.first[$];for(let y=0;y<a.size;y++){let E=a.weights[$*a.size+y];if(E===0)continue;let S=g+y,x=S%u,R=l[x];if(f[x]!==S)s(S,R),f[x]=S;h.push(R),m.push(E)}let b=0;while(b<h.length){let y=h[b],E=m[b];if(h.length-b>=4){let S=h[b+1],x=h[b+2],R=h[b+3],N=m[b+1],F=m[b+2],_=m[b+3];if(b===0)for(let B=0;B<c;B++)d[B]=y[B]*E+S[B]*N+x[B]*F+R[B]*_;else for(let B=0;B<c;B++)d[B]=d[B]+(y[B]*E+S[B]*N+x[B]*F+R[B]*_);b+=4}else{if(b===0)for(let S=0;S<c;S++)d[S]=y[S]*E;else for(let S=0;S<c;S++)d[S]=d[S]+y[S]*E;b+=1}}if(h.length===0)d.fill(0);o($,d)}}function ab(t,e,n,r,i){let s=0,o=n;while(s<o){let c=s+o>>1;if(t[c]+e-1<r)s=c+1;else o=c}let a=s;o=n;while(s<o){let c=s+o>>1;if(t[c]<=i)s=c+1;else o=c}return[a,s]}function mo(t,e,n,r){let i=uf(t.width,e.x,e.w,n),s=t.data,o=t.width,a=new Float32Array(o*4),c=new Uint8Array(n*r*4);return ob(t.height,e,n,r,4,(u,l)=>{let f=u*o*4,d=o,h=-1;for(let g=0,b=0;g<o*4;g+=4,b++){let y=s[f+g+3];if(y===0){a[g]=0,a[g+1]=0,a[g+2]=0,a[g+3]=0;continue}if(b<d)d=b;h=b,a[g]=s[f+g]*y,a[g+1]=s[f+g+1]*y,a[g+2]=s[f+g+2]*y,a[g+3]=y}if(l.fill(0),h<0)return;let[m,$]=ab(i.first,i.size,n,d,h);for(let g=m;g<$;g++){let b=i.first[g]*4,y=g*i.size,E=0,S=0,x=0,R=0;for(let N=0;N<i.size;N++){let F=i.weights[y+N],_=b+N*4;E+=a[_]*F,S+=a[_+1]*F,x+=a[_+2]*F,R+=a[_+3]*F}l[g*4]=E,l[g*4+1]=S,l[g*4+2]=x,l[g*4+3]=R}},(u,l)=>{let f=u*n*4;for(let d=0;d<n;d++){let h=d*4,m=l[h+3];if(m<=0)continue;let $=l[h]/m;c[f+h]=($<0?0:$>255?255:$)+0.5,$=l[h+1]/m,c[f+h+1]=($<0?0:$>255?255:$)+0.5,$=l[h+2]/m,c[f+h+2]=($<0?0:$>255?255:$)+0.5,c[f+h+3]=(m>255?255:m)+0.5}}),{width:n,height:r,data:c}}function cb(t,e,n,r){let i=uf(t.width,e.x,e.w,n),s=t.data,o=t.width,a=new Float32Array(n*r);return ob(t.height,e,n,r,1,(c,u)=>{let l=c*o,f=o,d=-1;for(let $=0;$<o;$++)if(s[l+$]!==0){if($<f)f=$;d=$}if(u.fill(0),d<0)return;let[h,m]=ab(i.first,i.size,n,f,d);for(let $=h;$<m;$++){let g=l+i.first[$],b=$*i.size,y=0;for(let E=0;E<i.size;E++)y+=s[g+E]*i.weights[b+E];u[$]=y}},(c,u)=>{a.set(u,c*n)}),{width:n,height:r,data:a}}function po(t,e){if(e<=0)return t;let n=Math.max(1,Math.ceil(e*3)),r=Array.from({length:2*n+1},(l,f)=>Math.exp(-((f-n)**2)/(2*e*e))),i=r.reduce((l,f)=>l+f,0),{width:s,height:o,data:a}=t,c=new Float32Array(s*o);for(let l=0;l<o;l++){let f=l*s;for(let d=0;d<s;d++){let h=0;for(let m=-n;m<=n;m++)h+=(a[f+Math.min(s-1,Math.max(0,d+m))]??0)*(r[m+n]??0);c[f+d]=h/i}}let u=new Float32Array(s*o);for(let l=0;l<o;l++){let f=l*s;for(let d=-n;d<=n;d++){let h=(r[d+n]??0)/i,m=Math.min(o-1,Math.max(0,l+d))*s;for(let $=0;$<s;$++)u[f+$]=(u[f+$]??0)+(c[m+$]??0)*h}}return{width:s,height:o,data:u}}function go(t){let e=new Uint8Array(t.data.length);for(let n=0;n<e.length;n++){let r=t.data[n];e[n]=(r<0?0:r>255?255:r)+0.5}return{width:t.width,height:t.height,data:e}}function ni(t){let e=new Uint8Array(t.width*t.height);for(let n=0;n<e.length;n++)e[n]=t.data[n*4+3]??0;return{width:t.width,height:t.height,data:e}}var Ax=Array.from({length:256},(t,e)=>{let n=e;for(let r=0;r<8;r++)n=n&1?3988292384^n>>>1:n>>>1;return n>>>0});function Px(t){let e=4294967295;for(let n of t)e=(Ax[(e^n)&255]??0)^e>>>8;return(e^4294967295)>>>0}function sr(t,e){let n=Buffer.alloc(12+e.length);return n.writeUInt32BE(e.length,0),n.write(t,4,"latin1"),n.set(e,8),n.writeUInt32BE(Px(n.subarray(4,8+e.length)),8+e.length),n}function ub(t,e,n){let r=new Uint8Array(n*(e+1));r.set(t.subarray(0,e),1);for(let i=1;i<n;i++){let s=i*(e+1),o=i*e,a=o-e;r[s]=2;for(let c=0;c<e;c++)r[s+1+c]=t[o+c]-t[a+c]}return r}function lb(t){return Ox(t,{level:1,strategy:Mx.Z_RLE})}function fb(t,e,n){let r=Buffer.alloc(13);return r.writeUInt32BE(t.width,0),r.writeUInt32BE(t.height,4),r[8]=8,r[9]=e,Buffer.concat([Buffer.from(ss),sr("IHDR",r),...n,sr("IDAT",lb(ub(t.data,t.width,t.height))),sr("IEND",new Uint8Array)])}function db(t){let[e,n,r]=rt(t),i=new Uint8Array(768);for(let s=0;s<256;s++)i.set([e,n,r],s*3);return sr("PLTE",i)}function hb(t,e,n,r,i){let s=Buffer.alloc(13);return s.writeUInt32BE(t,0),s.writeUInt32BE(e,4),s[8]=8,s[9]=n,Buffer.concat([Buffer.from(ss),sr("IHDR",s),sr("IDAT",lb(ub(i,t*r,e))),sr("IEND",new Uint8Array)])}function cr(t){return hb(t.width,t.height,2,3,t.data)}function ln(t){return hb(t.width,t.height,6,4,t.data)}function ri(t,e){return fb(t,tb,[db(e),sr("tRNS",Uint8Array.from({length:256},(n,r)=>r))])}function lf(t){return fb(t,0,[])}function za(t,e){if(!ei(t)||t[25]!==tb)return;let n=Buffer.from(t.buffer,t.byteOffset,t.byteLength),r=[Buffer.from(ss)],i=ss.length;while(i+8<=n.length){let s=i+12+n.readUInt32BE(i);r.push(n.toString("latin1",i+4,i+8)==="PLTE"?db(e):n.subarray(i,s)),i=s}return Buffer.concat(r)}var ur=100,$e=25000000,Gx=536870912,os=["safe","questionable","explicit"],ii=["nudity","underwear"],mf=["comic","monochrome","sketch","chibi"],vb=["off","5","10","25","50","100"],Eb=["off","720","1080","1440","1800","2560"],Sb={nudity:new Set(["nude","naked","topless","bottomless","nipples","naked_towel","undressing"]),underwear:new Set(["underwear","panties","pantsu","bra","lingerie","pantyshot"])},Bx={comic:new Set(["comic","4koma"]),monochrome:new Set(["monochrome","greyscale"]),sketch:new Set(["sketch","lineart","line_art"]),chibi:new Set(["chibi"])},Ux=/^(?:rating|score|width|height|filetype|dimension):/,bo={safe:"s",questionable:"q",explicit:"e"},Mb=8191,Wx=20000,Kx=5000,mb=3000,pb=8,zx=8,Dx=8000,qx=3000,Ob=60000,gb=3,Yx=3,Jx="https://static.zerochan.net",xb="https://s1.zerochan.net",pf=`ttheme/${It.version} (+${It.homepage})`,Vx=["orig","tile","thumb","cut"],Ib=new Map,Zx=mI(process.env.TTHEME_FIND_HOSTS),Qx=hI(process.env.TTHEME_FIND_CUTOUTS);Lx(qx);var Xx=["artist","character","copyright"];function bb(t){try{return Hx(t)}catch{return[]}}function as(t){return t.startsWith("//")?`https:${t}`:t}function fr(t){return(/\.([a-z0-9]+)(?:\?.*)?$/i.exec(t)?.[1]??"").toLowerCase()}function $o(t){let e=t.trim();if(!e)return[];let n=JSON.parse(e);if(Array.isArray(n))return n;let r=n.posts;return Array.isArray(r)?r:[]}function tI(t){let e=t.trim(),r=(e?JSON.parse(e):{}).tags??{};return new Map(Object.entries(r).map(([i,s])=>[i,String(s)]))}function df(t,e,n){let r=as(String(t??""));return{file:r,width:Number(e)||0,height:Number(n)||0,ext:fr(r)}}function An(t){return String(t??"").split(/\s+/).filter(Boolean)}function hf(t){let e=typeof t==="number"?new Date(t*1000):typeof t==="string"?new Date(t):void 0;return e&&!Number.isNaN(e.getTime())?e.toISOString().slice(0,10):void 0}function Rb(t,e){let n=as(String(e.preview??""));if(!e.file||!n||!Number(t.id))return[];let r=Number(t.width??t.image_width)||0,i=Number(t.height??t.image_height)||0;return[{id:Number(t.id),width:r,height:i,file:e.file,preview:n,ext:e.ext,owner:String(e.owner??""),score:Number(t.score)||0,rating:String(t.rating??""),md5:String(e.md5??""),source:String(t.source??""),tags:An(e.tags),named:e.named,...hf(t.created_at)?{posted:hf(t.created_at)}:{},solo:e.solo,family:Number(t.parent_id)||(t.has_children===!0?Number(t.id):0),smaller:e.versions.filter((s)=>s.file&&s.width>0&&s.height>0&&s.width*s.height<r*i)}]}function eI(t){let e=tI(t);return $o(t).flatMap((n)=>{let r=as(String(n.file_url??"")),i=String(n.tags??""),s=(o)=>An(i).filter((a)=>e.get(a)===o);return Rb(n,{preview:n.preview_url,file:r,ext:String(n.file_ext||fr(r)).toLowerCase(),owner:n.author,md5:n.md5,tags:i,named:{artist:s("artist"),character:s("character"),copyright:s("copyright")},solo:void 0,versions:[df(n.jpeg_url,n.jpeg_width,n.jpeg_height),df(n.sample_url,n.sample_width,n.sample_height)]})})}function nI(t){return $o(t).flatMap((e)=>{let n=as(String(e.file_url??"")),r=String(e.tag_string??""),i=e.media_asset??{};return Rb(e,{preview:i.variants?.find((s)=>s.type==="360x360")?.url??e.preview_file_url,file:n,ext:String(e.file_ext||fr(n)).toLowerCase(),owner:"",md5:e.md5,tags:r,named:{artist:An(e.tag_string_artist),character:An(e.tag_string_character),copyright:An(e.tag_string_copyright)},solo:r.split(/\s+/).includes("solo"),versions:(i.variants??[]).map((s)=>df(s.url,s.width,s.height)).filter((s)=>s.ext==="jpg"||s.ext==="png").sort((s,o)=>o.width*o.height-s.width*s.height)})})}function Nb(t){return t.toLowerCase().replace(/\s+/g,"_")}function rI(t){return(Array.isArray(t)?t:[]).map((e)=>Nb(String(e)))}function iI(t){return String(t??"").replace(/[^0-9a-z]+/gi,".").replace(/^\.+|\.+$/g,"")||"zerochan"}function sI(t){let e=t.trim(),n=e?JSON.parse(e):{};return(Array.isArray(n.items)?n.items:n.id?[n]:[]).flatMap((i)=>{let s=Number(i.id);if(!s)return[];let o=rI(i.tags),a=as(String(i.full??""));return[{id:s,width:Number(i.width)||0,height:Number(i.height)||0,file:a,ext:fr(a),preview:`${xb}/${iI(i.tag??i.primary)}.600.${s}.jpg`,owner:"",score:0,rating:o.some((c)=>Sb.nudity.has(c))?"q":"g",md5:String(i.md5??i.hash??""),source:String(i.source??""),tags:o,named:{artist:[],character:[],copyright:[]},solo:o.includes("solo"),family:0,smaller:[]}]})}var oI={mangaka:"artist",studio:"artist",character:"character",series:"copyright",game:"copyright"};function wb(t){return t.replace(/&(?:#(\d+)|amp|quot|apos|lt|gt);/g,(e,n)=>n?String.fromCharCode(Number(n)):{"&amp;":"&","&quot;":'"',"&apos;":"'","&lt;":"<","&gt;":">"}[e]??e)}function aI(t){let e={artist:[],character:[],copyright:[]};for(let[,r,i]of t.matchAll(/<li class="([a-z]+)[^"]*"[^>]*\bdata-tag="([^"]*)"/g)){let s=oI[r],o=Nb(wb(i));if(s&&!e[s].includes(o))e[s].push(o)}let n=hf(/"datePublished":\s*"([^"]+)"/.exec(t)?.[1]);return{named:e,source:"",owner:wb(/\buploader = \{\s*name: '([^']*)'/.exec(t)?.[1]??""),...n?{posted:n}:{}}}function cI(t){return Number(/Zerochan has ([\d,]+) /.exec(t)?.[1]?.replace(/,/g,"")??0)}function uI(t){return $o(t).flatMap((e)=>{let n=String(e.value??"");return n?[{value:n,count:Number(e.post_count)||0}]:[]})}function lI(t){return $o(t).flatMap((e)=>{let n=String(e.name??"");return n?[{value:n,count:Number(e.count)||0}]:[]})}function fI(t){return Number(/count="(\d+)"/.exec(t)?.[1]??0)}function dI(t){let n=(t.trim()?JSON.parse(t):{}).counts?.posts;return n===null?Number.NaN:Number(n)||0}function hI(t){let e=new Map;for(let n of(t??"").split(/\s+/).filter(Boolean)){let r=n.indexOf("=");if(r>0)e.set(n.slice(0,r),n.slice(r+1).split(",").filter(Boolean))}return e}function mI(t){let e=new Map;for(let n of(t??"").split(/[\s,]+/).filter(Boolean)){let r=n.indexOf("="),i=n.slice(0,r);try{let s=new URL(n.slice(r+1));if(i&&s.protocol==="https:")e.set(i,s.origin)}catch{}}return e}function Da(t,e,n,r){let i=(t??"").split(/\s+/);if(r!==void 0&&i.includes(r))return[];let s=e.filter((o)=>i.includes(o));return s.length>0?s:[...n]}function si(t){return Da(t,os,["safe"])}function cs(t){return Da(t,ii,ii,"none")}function qa(t){return Da(t,mf,[],"none")}function ko(t){let e=Y.map((n)=>n.name);return Da(t,e,e)}function gf(t,e,n){return{score:Number(t)||0,size:Number(e)||0,png:n==="on"}}function yo(t){return[...new Set((t??"").toLowerCase().split(/[\s,]+/).map((e)=>e.replace(/^-+/,"")).filter(Boolean))]}function bf(t,e,n){return{safe:new Set(t),questionable:new Set(e),explicit:new Set(n)}}function wf(t){let e=Zx.get(t.key),n=Qx.get(t.key);return{...t,origin:e??t.origin,moved:e!==void 0&&e!==t.origin,cutouts:n??t.cutouts,vouched:t.vouched&&n===void 0}}function Tb(t){return t.length<2?t.join(""):t.map((e)=>`~${e}`).join(" ")}function Ab(t){return t>0?[`width:>=${t}`,`height:>=${t}`]:[]}function $b(t){let e=wf(t),n=(r)=>new URLSearchParams({api_version:"2",include_tags:"1",...r});return{...e,scored:!0,narrow:({score:r,size:i})=>[...r>0?[`score:>=${r}`]:[],...Ab(i)],cutouts:Tb(e.cutouts),ratings:bf([bo.safe],[bo.questionable],[bo.explicit]),rate:(r)=>{let[i]=r;if(r.length===1&&i)return`rating:${bo[i]}`;let s=os.filter((a)=>!r.includes(a)),[o]=s;return s.length===1&&o?`-rating:${bo[o]}`:""},best:"order:score",tagBudget:Number.POSITIVE_INFINITY,ors:!0,postsUrl:(r,i)=>`${e.origin}/post.json?${n({limit:String(ur),page:String(i+1),tags:r})}`,countUrl:(r)=>`${e.origin}/post.xml?${new URLSearchParams({limit:"1",tags:r})}`,postUrl:(r)=>`${e.origin}/post.json?${n({tags:`id:${r}`})}`,pageUrl:(r)=>`${e.origin}/post/show/${r}`,parse:eI,count:fI,uploadedBy:(r)=>`user:${r}`}}function pI(t){let e=wf(t),n=bf(["g"],["s","q"],["e"]);return{...e,scored:!0,narrow:({score:r,size:i,png:s})=>[...r>0?[`score:>=${r}`]:[],...Ab(i),...s?["filetype:png"]:[]],cutouts:Tb(e.cutouts),ratings:n,rate:(r)=>r.length===os.length?"":`rating:${r.flatMap((i)=>[...n[i]]).join(",")}`,best:"order:score",tagBudget:2,ors:!0,postsUrl:(r,i)=>`${e.origin}/posts.json?${new URLSearchParams({limit:String(ur),page:String(i+1),tags:r})}`,countUrl:(r)=>`${e.origin}/counts/posts.json?${new URLSearchParams({tags:r})}`,postUrl:(r)=>`${e.origin}/posts.json?${new URLSearchParams({limit:"1",tags:`id:${r}`})}`,pageUrl:(r)=>`${e.origin}/posts/${r}`,parse:nI,count:dI,uploadedBy:(r)=>`user:${r}`}}function ff(t){return t.split(/\s+/).filter((e)=>e&&!/^(?:order|dimension):/.test(e)).map((e)=>e.split("_").map(encodeURIComponent).join("+")).join(",")}function kb(t){let e=t.split(/\s+/),n=e.find((r)=>r.startsWith("dimension:"))?.slice(10);return{s:e.includes("order:fav")?"fav":"id",...n?{d:n}:{}}}function gI(t){let e=wf(t);return{...e,scored:!1,narrow:({size:n})=>n>=1800?["dimension:huge"]:n>0?["dimension:large"]:[],cutouts:e.cutouts[0]??"",ratings:bf(["g"],["q"],["e"]),rate:()=>"",best:"order:fav",tagBudget:3,ors:!1,missing:404,postsUrl:(n,r)=>`${e.origin}/${ff(n)}?${new URLSearchParams({json:"",l:String(ur),p:String(r+1),...kb(n)})}`,countUrl:(n)=>`${e.origin}/${ff(n)}?${new URLSearchParams({xml:"",l:"1"})}`,postUrl:(n)=>`${e.origin}/${n}?json=`,pageUrl:(n)=>`${e.origin}/${n}`,parse:sI,count:cI,credits:aI,counts:(n)=>ff(n).split(",").length===1&&!("d"in kb(n)),guesses:(n)=>(n.tags.includes("transparent_background")?["png","jpg"]:["jpg","png"]).map((r)=>n.preview.replace(xb,Jx).replace(/\.600\.(\d+)\.jpg$/,`.full.$1.${r}`))}}function bI(t){let e=yb(`https://${t}`);return Y.find((n)=>yb(n.origin)===e)}function $f(t){return t.split(/\s+/).filter((e)=>e&&!Ux.test(e)).length}function Ya(t,e){let n=t.trim();if(/^\d+$/.test(n))return{site:e,id:Number(n)};let r=/^([\w.]+):(\d+)$/.exec(n);if(r){let a=Y.find((c)=>c.key===r[1]||c.name===r[1]);return a&&{site:a,id:Number(r[2])}}let i;try{i=new URL(n)}catch{return}let s=bI(i.host),o=Number(i.searchParams.get("id")??i.pathname.split("/").filter(Boolean).at(-1));return s&&o>0?{site:s,id:o}:void 0}var Y=[pI({key:"danbooru",name:"danbooru",origin:"https://shima.donmai.us",cutouts:["transparent_background"],vouched:!1,ansi:2}),$b({key:"konachan",name:"konachan",origin:"https://konachan.net",cutouts:["transparent","vector"],vouched:!1,ansi:6}),$b({key:"yande",name:"yande.re",origin:"https://yande.re",cutouts:["transparent_png"],vouched:!0,ansi:5}),gI({key:"zerochan",name:"zerochan",origin:"https://www.zerochan.net",cutouts:["transparent_background"],vouched:!1,ansi:3})],Qt=Y.find((t)=>t.key==="danbooru"),dr=134217728;function ke(t,e){let n=Y.indexOf(t);return(n===-1?Y.length:n)*dr+e}function yb(t){let e;try{e=new URL(t).hostname}catch{return""}return e.split(".").slice(-2).join(".")}function oi(t,e,n=e){return e.mirror&&n===e?{site:Qt,url:e.mirror.file}:{site:t,url:n.file}}function Ja(t,e){return e.mirror?{site:Qt,url:e.mirror.preview}:{site:t,url:e.preview}}function Va(t,e=ii){return t.tags.filter((n)=>e.some((r)=>Sb[r].has(n)))}function Pb(t,e){return t.tags.filter((n)=>e.some((r)=>Bx[r].has(n)))}function Za(t,e,n=["safe"]){return n.some((r)=>t.ratings[r].has(e.rating))}function Hb(t,e){return t.rate(["safe"])===""?void 0:os.find((n)=>t.ratings[n].has(e.rating))}function fn(t){return[t,...t.smaller].find((e)=>e.width*e.height<=$e)}function Fb(t){let e=new Map;for(let[n,r]of[...t].sort(([i],[s])=>i<s?-1:1)){if(r==="")continue;e.set(r,[...e.get(r)??[],n])}return e}function hr(){return wo(process.env.XDG_CACHE_HOME??wo(jx(),".cache"),"ttheme")}function Ke(t){return wo(hr(),t.key)}function Cb(t=Gx,e=hr()){let n=[],r=0;for(let i of bb(e))for(let s of Vx){let o=wo(e,i,s);for(let a of bb(o)){let c=wo(o,a);try{let{size:u,mtimeMs:l}=Cx(c);n.push({path:c,size:u,at:l}),r+=u}catch{}}}n.sort((i,s)=>i.at-s.at);for(let i of n){if(r<=t)return;try{Fx(i.path,{force:!0}),r-=i.size}catch{}}}function wI(t,e){if(t!==null&&/^\s*\d+\s*$/.test(t))return Number(t)*1000;let n=t===null?Number.NaN:Date.parse(t);return Number.isNaN(n)?Ob:Math.max(0,n-e)}function Pn(t){return Ib.get(t.key)??0}function $I(t){for(let e=t;e instanceof Error;e=e.cause)if(e.code==="ECONNRESET")return!0;return!1}function kI(t){return(t.headers.get("server")??"").startsWith("cloudflare")&&t.headers.get("cf-mitigated")==="challenge"}function yI(t,e){let n=new URL(e,t);if(!n.search)n.search=new URL(t).search;return n.href}async function lr(t,e,n,r={},i=Wx){let s=e;for(let o=1,a=0;;o++){let c=Pn(t)-Date.now();if(c>0)await _x(c,void 0,{signal:n});let u;try{u=await fetch(s,{headers:{"User-Agent":pf,Referer:`${t.origin}/`,...r},redirect:"manual",signal:i?AbortSignal.any([n,AbortSignal.timeout(i)]):n})}catch(f){if(o<gb&&!n.aborted&&$I(f))continue;throw f}let l=u.headers.get("location");if(l&&u.status>=300&&u.status<400&&a<Yx){await u.body?.cancel(),s=yI(s,l),a++,o--;continue}if(u.status===429&&o<gb){await u.body?.cancel();let f=wI(u.headers.get("retry-after"),Date.now());if(f>Ob)throw Error(`${t.name} asks to wait ${Math.ceil(f/1000)}s`);Ib.set(t.key,Math.max(Pn(t),Date.now()+f));continue}if(!u.ok)throw await u.body?.cancel(),Object.assign(Error(kI(u)?`${t.name} is behind a Cloudflare challenge`:`${t.name} answered ${u.status}`),{status:u.status});return u}}async function Qa(t,e,n){try{return await(await lr(t,e,n)).text()}catch(r){if(t.missing!==void 0&&r.status===t.missing)return"";throw r}}async function Lb(t,e,n,r){return t.parse(await Qa(t,t.postsUrl(e,n),r))}async function kf(t,e,n){return t.count(await Qa(t,t.countUrl(e),n))}async function us(t,e,n){let[r]=t.parse(await Qa(t,t.postUrl(e),n));return r}async function Xa(t,e,n){return t.credits?.(await Qa(t,t.pageUrl(e),n))}var vI=/^https?:\/\/(?:i\.pximg\.net|i\d*\.pixiv\.net|img\d*\.pixiv\.net)\/\S*\/(\d+)(?:_p\d+)?(?:_\w+)?\.\w+(?:[?#]\S*)?$/i,EI=/^https?:\/\/(?:www\.)?pixiv\.net\/member_illust\.php\?\S*\billust_id=(\d+)/i;function vo(t){let e=vI.exec(t)?.[1]??EI.exec(t)?.[1];return e?`https://www.pixiv.net/artworks/${e}`:t}function tc(t,e){return t.credits!==void 0&&e.named.artist.length===0}function Eo(t,e){for(let n of Xx){let r=e.named?.[n]??[];if(t.named[n].length===0&&r.length>0)t.named[n]=r}if(t.source||=e.source??"",t.owner||=e.owner??"",!t.posted&&e.posted)t.posted=e.posted}function SI(t){let e=new URLSearchParams({limit:String(2*ur),only:"md5,tag_string,tag_string_artist,tag_string_character,tag_string_copyright,source,file_url",tags:`md5:${t.join(",")}`});return`${Qt.origin}/posts.json?${e}`}function MI(t){return new Map($o(t).flatMap((e)=>{let n=String(e.md5??"");return n?[[n,{tags:An(e.tag_string),named:{artist:An(e.tag_string_artist),character:An(e.tag_string_character),copyright:An(e.tag_string_copyright)},source:String(e.source??""),file:as(String(e.file_url??""))}]]:[]}))}function ec(t,e){for(let n of t){let r=e.get(n.md5);if(!r)continue;if(n.tags=[...new Set([...n.tags,...r.tags])],Eo(n,r),n.solo=r.tags.includes("solo"),r.file.includes("/original/")){if(n.mirror={file:r.file,preview:r.file.replace("/original/","/360x360/").replace(/\.[a-z0-9]+$/i,".jpg")},!n.file)n.file=r.file,n.ext=fr(r.file)}}}async function nc(t,e){let n=new Map;if(Pn(Qt)>Date.now())return n;for(let r=0;r<t.length;r+=ur){let i=await(await lr(Qt,SI(t.slice(r,r+ur)),e,{},Kx)).text();for(let[s,o]of MI(i))n.set(s,o)}return n}async function So(t,e,n){if(e.file||!t.guesses)return;for(let r of t.guesses(e))try{let i=await lr(t,r,n,{Range:`bytes=0-${Mb}`}),s=un(new Uint8Array(await i.arrayBuffer()));return e.file=r,e.ext=fr(r),s}catch(i){if(n.aborted||i.status!==404)throw i}throw Error(`${t.name} keeps no png or jpg of ${e.id}`)}async function jb(t,e){if(Pn(Qt)<=Date.now())try{let i=new URLSearchParams({"search[query]":t,"search[type]":"tag_query",limit:String(pb)}),s=`${Qt.origin}/autocomplete.json?${i}`;return uI(await(await lr(Qt,s,e,{},mb)).text())}catch(i){if(e.aborted)throw i}let n=Y.find((i)=>i.key==="yande"),r=new URLSearchParams({name:t,order:"count",limit:String(pb)});return lI(await(await lr(n,`${n.origin}/tag.json?${r}`,e,{},mb)).text())}function OI(t){try{return(JSON.parse(t).related_tags??[]).flatMap(({tag:n})=>n?.name?[{value:n.name,count:Number(n.post_count)||0}]:[])}catch{return[]}}async function _b(t,e){if(Pn(Qt)>Date.now())return[];let n=new URLSearchParams({"search[query]":t,"search[category]":"character",limit:String(zx)});return OI(await(await lr(Qt,`${Qt.origin}/related_tag.json?${n}`,e,{},Dx)).text())}function Gb(t,e){return e.slice(0,t.ors?t.tagBudget:1)}async function Bb(t,e,n){let r=await lr(t,e,n,{Range:`bytes=0-${Mb}`});return un(new Uint8Array(await r.arrayBuffer()))}async function rc(t,e,n,r){let i=await lr(t,e,n,{},0),s=Number(i.headers.get("content-length"))||0,o=i.body?.getReader();if(!o)return new Uint8Array(await i.arrayBuffer());let a=[],c=0;for(;;){let{done:f,value:d}=await o.read();if(f)break;a.push(d),c+=d.length,r?.(c,s)}let u=new Uint8Array(c),l=0;for(let f of a)u.set(f,l),l+=f.length;return u}var HI=12,FI=/^[0-9a-f]{40}$/;function ls(){return fs(hr(),"drawn")}function Ub(t){return xI("sha1").update(JSON.stringify(t)).digest("hex")}function Wb(t){return II(fs(ls(),t))}function Kb(t){let e=fs(ls(),t);try{let n=NI(e),r=n.readUInt32BE(0),i=JSON.parse(n.toString("utf8",4,4+r)),s=n.subarray(4+r,4+r+i.figure),o=n.subarray(4+r+i.figure,4+r+i.figure+i.picture);if(s.length!==i.figure||o.length!==i.picture)return;let a=new Date;return PI(e,a,a),{stem:i.stem,fill:i.fill,...i.peak?{peak:i.peak}:{},figure:s,picture:o}}catch{return}}function yf(t,e){let n=Buffer.from(JSON.stringify({stem:e.stem,fill:e.fill,...e.peak?{peak:e.peak}:{},figure:e.figure.length,picture:e.picture.length})),r=Buffer.alloc(4);r.writeUInt32BE(n.length),P(fs(ls(),t),Buffer.concat([r,n,e.figure,e.picture])),CI()}function CI(){let t=RI(ls()).filter((e)=>FI.test(e)).flatMap((e)=>{try{return[{name:e,at:AI(fs(ls(),e)).mtimeMs}]}catch{return[]}}).sort((e,n)=>n.at-e.at);for(let{name:e}of t.slice(HI))TI(fs(ls(),e),{force:!0})}import{readdirSync as WI,readFileSync as Xb}from"node:fs";import{basename as KI,join as tw}from"node:path";/*!
2
+ import{createRequire as w2}from"node:module";var d2=Object.create;var{getPrototypeOf:f2,defineProperty:Rg,getOwnPropertyNames:h2}=Object;var m2=Object.prototype.hasOwnProperty;function p2(t){return this[t]}var g2,b2,bd=(t,e,n)=>{var r=t!=null&&typeof t==="object";if(r){var i=e?g2??=new WeakMap:b2??=new WeakMap,o=i.get(t);if(o)return o}n=t!=null?d2(f2(t)):{};let s=e||!t||!t.__esModule?Rg(n,"default",{value:t,enumerable:!0}):n;for(let a of h2(t))if(!m2.call(s,a))Rg(s,a,{get:p2.bind(t,a),enumerable:!0});if(r)i.set(t,s);return s};var St=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Yt=w2(import.meta.url);var xd=St((u4,Xg)=>{var j2=Yt("util"),Qg=Yt("stream"),Je=Xg.exports=function(){Qg.call(this),this._buffers=[],this._buffered=0,this._reads=[],this._paused=!1,this._encoding="utf8",this.writable=!0};j2.inherits(Je,Qg);Je.prototype.read=function(t,e){this._reads.push({length:Math.abs(t),allowLess:t<0,func:e}),process.nextTick(function(){if(this._process(),this._paused&&this._reads&&this._reads.length>0)this._paused=!1,this.emit("drain")}.bind(this))};Je.prototype.write=function(t,e){if(!this.writable)return this.emit("error",Error("Stream not writable")),!1;let n;if(Buffer.isBuffer(t))n=t;else n=Buffer.from(t,e||this._encoding);if(this._buffers.push(n),this._buffered+=n.length,this._process(),this._reads&&this._reads.length===0)this._paused=!0;return this.writable&&!this._paused};Je.prototype.end=function(t,e){if(t)this.write(t,e);if(this.writable=!1,!this._buffers)return;if(this._buffers.length===0)this._end();else this._buffers.push(null),this._process()};Je.prototype.destroySoon=Je.prototype.end;Je.prototype._end=function(){if(this._reads.length>0)this.emit("error",Error("Unexpected end of input"));this.destroy()};Je.prototype.destroy=function(){if(!this._buffers)return;this.writable=!1,this._reads=null,this._buffers=null,this.emit("close")};Je.prototype._processReadAllowingLess=function(t){this._reads.shift();let e=this._buffers[0];if(e.length>t.length)this._buffered-=t.length,this._buffers[0]=e.slice(t.length),t.func.call(this,e.slice(0,t.length));else this._buffered-=e.length,this._buffers.shift(),t.func.call(this,e)};Je.prototype._processRead=function(t){this._reads.shift();let e=0,n=0,r=Buffer.alloc(t.length);while(e<t.length){let i=this._buffers[n++],o=Math.min(i.length,t.length-e);if(i.copy(r,e,0,o),e+=o,o!==i.length)this._buffers[--n]=i.slice(o)}if(n>0)this._buffers.splice(0,n);this._buffered-=t.length,t.func.call(this,r)};Je.prototype._process=function(){try{while(this._buffered>0&&this._reads&&this._reads.length>0){let t=this._reads[0];if(t.allowLess)this._processReadAllowingLess(t);else if(this._buffered>=t.length)this._processRead(t);else break}if(this._buffers&&!this.writable)this._end()}catch(t){this.emit("error",t)}}});var Od=St((_2)=>{var gr=[{x:[0],y:[0]},{x:[4],y:[0]},{x:[0,4],y:[4]},{x:[2,6],y:[0,4]},{x:[0,2,4,6],y:[2,6]},{x:[1,3,5,7],y:[0,2,4,6]},{x:[0,1,2,3,4,5,6,7],y:[1,3,5,7]}];_2.getImagePasses=function(t,e){let n=[],r=t%8,i=e%8,o=(t-r)/8,s=(e-i)/8;for(let a=0;a<gr.length;a++){let c=gr[a],u=o*c.x.length,l=s*c.y.length;for(let d=0;d<c.x.length;d++)if(c.x[d]<r)u++;else break;for(let d=0;d<c.y.length;d++)if(c.y[d]<i)l++;else break;if(u>0&&l>0)n.push({width:u,height:l,index:a})}return n};_2.getInterlaceIterator=function(t){return function(e,n,r){let i=e%gr[r].x.length,o=(e-i)/gr[r].x.length*8+gr[r].x[i],s=n%gr[r].y.length,a=(n-s)/gr[r].y.length*8+gr[r].y[s];return o*4+a*t*4}}});var Id=St((d4,tb)=>{tb.exports=function(e,n,r){let i=e+n-r,o=Math.abs(i-e),s=Math.abs(i-n),a=Math.abs(i-r);if(o<=s&&o<=a)return e;if(s<=a)return n;return r}});var Rd=St((f4,nb)=>{var U2=Od(),W2=Id();function eb(t,e,n){let r=t*e;if(n!==8)r=Math.ceil(r/(8/n));return r}var go=nb.exports=function(t,e){let{width:n,height:r,interlace:i,bpp:o,depth:s}=t;if(this.read=e.read,this.write=e.write,this.complete=e.complete,this._imageIndex=0,this._images=[],i){let a=U2.getImagePasses(n,r);for(let c=0;c<a.length;c++)this._images.push({byteWidth:eb(a[c].width,o,s),height:a[c].height,lineIndex:0})}else this._images.push({byteWidth:eb(n,o,s),height:r,lineIndex:0});if(s===8)this._xComparison=o;else if(s===16)this._xComparison=o*2;else this._xComparison=1};go.prototype.start=function(){this.read(this._images[this._imageIndex].byteWidth+1,this._reverseFilterLine.bind(this))};go.prototype._unFilterType1=function(t,e,n){let r=this._xComparison,i=r-1;for(let o=0;o<n;o++){let s=t[1+o],a=o>i?e[o-r]:0;e[o]=s+a}};go.prototype._unFilterType2=function(t,e,n){let r=this._lastLine;for(let i=0;i<n;i++){let o=t[1+i],s=r?r[i]:0;e[i]=o+s}};go.prototype._unFilterType3=function(t,e,n){let r=this._xComparison,i=r-1,o=this._lastLine;for(let s=0;s<n;s++){let a=t[1+s],c=o?o[s]:0,u=s>i?e[s-r]:0,l=Math.floor((u+c)/2);e[s]=a+l}};go.prototype._unFilterType4=function(t,e,n){let r=this._xComparison,i=r-1,o=this._lastLine;for(let s=0;s<n;s++){let a=t[1+s],c=o?o[s]:0,u=s>i?e[s-r]:0,l=s>i&&o?o[s-r]:0,d=W2(u,c,l);e[s]=a+d}};go.prototype._reverseFilterLine=function(t){let e=t[0],n,r=this._images[this._imageIndex],i=r.byteWidth;if(e===0)n=t.slice(1,i+1);else switch(n=Buffer.alloc(i),e){case 1:this._unFilterType1(t,n,i);break;case 2:this._unFilterType2(t,n,i);break;case 3:this._unFilterType3(t,n,i);break;case 4:this._unFilterType4(t,n,i);break;default:throw Error("Unrecognised filter type - "+e)}if(this.write(n),r.lineIndex++,r.lineIndex>=r.height)this._lastLine=null,this._imageIndex++,r=this._images[this._imageIndex];else this._lastLine=n;if(r)this.read(r.byteWidth+1,this._reverseFilterLine.bind(this));else this._lastLine=null,this.complete()}});var ob=St((h4,ib)=>{var K2=Yt("util"),rb=xd(),z2=Rd(),D2=ib.exports=function(t){rb.call(this);let e=[],n=this;this._filter=new z2(t,{read:this.read.bind(this),write:function(r){e.push(r)},complete:function(){n.emit("complete",Buffer.concat(e))}}),this._filter.start()};K2.inherits(D2,rb)});var bo=St((m4,sb)=>{sb.exports={PNG_SIGNATURE:[137,80,78,71,13,10,26,10],TYPE_IHDR:1229472850,TYPE_IEND:1229278788,TYPE_IDAT:1229209940,TYPE_PLTE:1347179589,TYPE_tRNS:1951551059,TYPE_gAMA:1732332865,COLORTYPE_GRAYSCALE:0,COLORTYPE_PALETTE:1,COLORTYPE_COLOR:2,COLORTYPE_ALPHA:4,COLORTYPE_PALETTE_COLOR:3,COLORTYPE_COLOR_ALPHA:6,COLORTYPE_TO_BPP_MAP:{0:1,2:3,3:1,4:2,6:4},GAMMA_DIVISION:1e5}});var Ad=St((p4,ab)=>{var Pd=[];(function(){for(let t=0;t<256;t++){let e=t;for(let n=0;n<8;n++)if(e&1)e=3988292384^e>>>1;else e=e>>>1;Pd[t]=e}})();var Nd=ab.exports=function(){this._crc=-1};Nd.prototype.write=function(t){for(let e=0;e<t.length;e++)this._crc=Pd[(this._crc^t[e])&255]^this._crc>>>8;return!0};Nd.prototype.crc32=function(){return this._crc^-1};Nd.crc32=function(t){let e=-1;for(let n=0;n<t.length;n++)e=Pd[(e^t[n])&255]^e>>>8;return e^-1}});var Td=St((g4,cb)=>{var Ht=bo(),q2=Ad(),Ft=cb.exports=function(t,e){this._options=t,t.checkCRC=t.checkCRC!==!1,this._hasIHDR=!1,this._hasIEND=!1,this._emittedHeadersFinished=!1,this._palette=[],this._colorType=0,this._chunks={},this._chunks[Ht.TYPE_IHDR]=this._handleIHDR.bind(this),this._chunks[Ht.TYPE_IEND]=this._handleIEND.bind(this),this._chunks[Ht.TYPE_IDAT]=this._handleIDAT.bind(this),this._chunks[Ht.TYPE_PLTE]=this._handlePLTE.bind(this),this._chunks[Ht.TYPE_tRNS]=this._handleTRNS.bind(this),this._chunks[Ht.TYPE_gAMA]=this._handleGAMA.bind(this),this.read=e.read,this.error=e.error,this.metadata=e.metadata,this.gamma=e.gamma,this.transColor=e.transColor,this.palette=e.palette,this.parsed=e.parsed,this.inflateData=e.inflateData,this.finished=e.finished,this.simpleTransparency=e.simpleTransparency,this.headersFinished=e.headersFinished||function(){}};Ft.prototype.start=function(){this.read(Ht.PNG_SIGNATURE.length,this._parseSignature.bind(this))};Ft.prototype._parseSignature=function(t){let e=Ht.PNG_SIGNATURE;for(let n=0;n<e.length;n++)if(t[n]!==e[n]){this.error(Error("Invalid file signature"));return}this.read(8,this._parseChunkBegin.bind(this))};Ft.prototype._parseChunkBegin=function(t){let e=t.readUInt32BE(0),n=t.readUInt32BE(4),r="";for(let o=4;o<8;o++)r+=String.fromCharCode(t[o]);let i=Boolean(t[4]&32);if(!this._hasIHDR&&n!==Ht.TYPE_IHDR){this.error(Error("Expected IHDR on beggining"));return}if(this._crc=new q2,this._crc.write(Buffer.from(r)),this._chunks[n])return this._chunks[n](e);if(!i){this.error(Error("Unsupported critical chunk type "+r));return}this.read(e+4,this._skipChunk.bind(this))};Ft.prototype._skipChunk=function(){this.read(8,this._parseChunkBegin.bind(this))};Ft.prototype._handleChunkEnd=function(){this.read(4,this._parseChunkEnd.bind(this))};Ft.prototype._parseChunkEnd=function(t){let e=t.readInt32BE(0),n=this._crc.crc32();if(this._options.checkCRC&&n!==e){this.error(Error("Crc error - "+e+" - "+n));return}if(!this._hasIEND)this.read(8,this._parseChunkBegin.bind(this))};Ft.prototype._handleIHDR=function(t){this.read(t,this._parseIHDR.bind(this))};Ft.prototype._parseIHDR=function(t){this._crc.write(t);let e=t.readUInt32BE(0),n=t.readUInt32BE(4),r=t[8],i=t[9],o=t[10],s=t[11],a=t[12];if(r!==8&&r!==4&&r!==2&&r!==1&&r!==16){this.error(Error("Unsupported bit depth "+r));return}if(!(i in Ht.COLORTYPE_TO_BPP_MAP)){this.error(Error("Unsupported color type"));return}if(o!==0){this.error(Error("Unsupported compression method"));return}if(s!==0){this.error(Error("Unsupported filter method"));return}if(a!==0&&a!==1){this.error(Error("Unsupported interlace method"));return}this._colorType=i;let c=Ht.COLORTYPE_TO_BPP_MAP[this._colorType];this._hasIHDR=!0,this.metadata({width:e,height:n,depth:r,interlace:Boolean(a),palette:Boolean(i&Ht.COLORTYPE_PALETTE),color:Boolean(i&Ht.COLORTYPE_COLOR),alpha:Boolean(i&Ht.COLORTYPE_ALPHA),bpp:c,colorType:i}),this._handleChunkEnd()};Ft.prototype._handlePLTE=function(t){this.read(t,this._parsePLTE.bind(this))};Ft.prototype._parsePLTE=function(t){this._crc.write(t);let e=Math.floor(t.length/3);for(let n=0;n<e;n++)this._palette.push([t[n*3],t[n*3+1],t[n*3+2],255]);this.palette(this._palette),this._handleChunkEnd()};Ft.prototype._handleTRNS=function(t){this.simpleTransparency(),this.read(t,this._parseTRNS.bind(this))};Ft.prototype._parseTRNS=function(t){if(this._crc.write(t),this._colorType===Ht.COLORTYPE_PALETTE_COLOR){if(this._palette.length===0){this.error(Error("Transparency chunk must be after palette"));return}if(t.length>this._palette.length){this.error(Error("More transparent colors than palette size"));return}for(let e=0;e<t.length;e++)this._palette[e][3]=t[e];this.palette(this._palette)}if(this._colorType===Ht.COLORTYPE_GRAYSCALE)this.transColor([t.readUInt16BE(0)]);if(this._colorType===Ht.COLORTYPE_COLOR)this.transColor([t.readUInt16BE(0),t.readUInt16BE(2),t.readUInt16BE(4)]);this._handleChunkEnd()};Ft.prototype._handleGAMA=function(t){this.read(t,this._parseGAMA.bind(this))};Ft.prototype._parseGAMA=function(t){this._crc.write(t),this.gamma(t.readUInt32BE(0)/Ht.GAMMA_DIVISION),this._handleChunkEnd()};Ft.prototype._handleIDAT=function(t){if(!this._emittedHeadersFinished)this._emittedHeadersFinished=!0,this.headersFinished();this.read(-t,this._parseIDAT.bind(this,t))};Ft.prototype._parseIDAT=function(t,e){if(this._crc.write(e),this._colorType===Ht.COLORTYPE_PALETTE_COLOR&&this._palette.length===0)throw Error("Expected palette not found");this.inflateData(e);let n=t-e.length;if(n>0)this._handleIDAT(n);else this._handleChunkEnd()};Ft.prototype._handleIEND=function(t){this.read(t,this._parseIEND.bind(this))};Ft.prototype._parseIEND=function(t){if(this._crc.write(t),this._hasIEND=!0,this._handleChunkEnd(),this.finished)this.finished()}});var Hd=St((X2)=>{var ub=Od(),Y2=[function(){},function(t,e,n,r){if(r===e.length)throw Error("Ran out of data");let i=e[r];t[n]=i,t[n+1]=i,t[n+2]=i,t[n+3]=255},function(t,e,n,r){if(r+1>=e.length)throw Error("Ran out of data");let i=e[r];t[n]=i,t[n+1]=i,t[n+2]=i,t[n+3]=e[r+1]},function(t,e,n,r){if(r+2>=e.length)throw Error("Ran out of data");t[n]=e[r],t[n+1]=e[r+1],t[n+2]=e[r+2],t[n+3]=255},function(t,e,n,r){if(r+3>=e.length)throw Error("Ran out of data");t[n]=e[r],t[n+1]=e[r+1],t[n+2]=e[r+2],t[n+3]=e[r+3]}],J2=[function(){},function(t,e,n,r){let i=e[0];t[n]=i,t[n+1]=i,t[n+2]=i,t[n+3]=r},function(t,e,n){let r=e[0];t[n]=r,t[n+1]=r,t[n+2]=r,t[n+3]=e[1]},function(t,e,n,r){t[n]=e[0],t[n+1]=e[1],t[n+2]=e[2],t[n+3]=r},function(t,e,n){t[n]=e[0],t[n+1]=e[1],t[n+2]=e[2],t[n+3]=e[3]}];function V2(t,e){let n=[],r=0;function i(){if(r===t.length)throw Error("Ran out of data");let o=t[r];r++;let s,a,c,u,l,d,f,h;switch(e){default:throw Error("unrecognised depth");case 16:f=t[r],r++,n.push((o<<8)+f);break;case 4:f=o&15,h=o>>4,n.push(h,f);break;case 2:l=o&3,d=o>>2&3,f=o>>4&3,h=o>>6&3,n.push(h,f,d,l);break;case 1:s=o&1,a=o>>1&1,c=o>>2&1,u=o>>3&1,l=o>>4&1,d=o>>5&1,f=o>>6&1,h=o>>7&1,n.push(h,f,d,l,u,c,a,s);break}}return{get:function(o){while(n.length<o)i();let s=n.slice(0,o);return n=n.slice(o),s},resetAfterLine:function(){n.length=0},end:function(){if(r!==t.length)throw Error("extra data found")}}}function Z2(t,e,n,r,i,o){let{width:s,height:a,index:c}=t;for(let u=0;u<a;u++)for(let l=0;l<s;l++){let d=n(l,u,c);Y2[r](e,i,d,o),o+=r}return o}function Q2(t,e,n,r,i,o){let{width:s,height:a,index:c}=t;for(let u=0;u<a;u++){for(let l=0;l<s;l++){let d=i.get(r),f=n(l,u,c);J2[r](e,d,f,o)}i.resetAfterLine()}}X2.dataToBitMap=function(t,e){let{width:n,height:r,depth:i,bpp:o,interlace:s}=e,a;if(i!==8)a=V2(t,i);let c;if(i<=8)c=Buffer.alloc(n*r*4);else c=new Uint16Array(n*r*4);let u=Math.pow(2,i)-1,l=0,d,f;if(s)d=ub.getImagePasses(n,r),f=ub.getInterlaceIterator(n,r);else{let h=0;f=function(){let m=h;return h+=4,m},d=[{width:n,height:r}]}for(let h=0;h<d.length;h++)if(i===8)l=Z2(d[h],c,f,o,t,l);else Q2(d[h],c,f,o,a,u);if(i===8){if(l!==t.length)throw Error("extra data found")}else a.end();return c}});var Cd=St((w4,lb)=>{function eO(t,e,n,r,i){let o=0;for(let s=0;s<r;s++)for(let a=0;a<n;a++){let c=i[t[o]];if(!c)throw Error("index "+t[o]+" not in palette");for(let u=0;u<4;u++)e[o+u]=c[u];o+=4}}function nO(t,e,n,r,i){let o=0;for(let s=0;s<r;s++)for(let a=0;a<n;a++){let c=!1;if(i.length===1){if(i[0]===t[o])c=!0}else if(i[0]===t[o]&&i[1]===t[o+1]&&i[2]===t[o+2])c=!0;if(c)for(let u=0;u<4;u++)e[o+u]=0;o+=4}}function rO(t,e,n,r,i){let o=255,s=Math.pow(2,i)-1,a=0;for(let c=0;c<r;c++)for(let u=0;u<n;u++){for(let l=0;l<4;l++)e[a+l]=Math.floor(t[a+l]*o/s+0.5);a+=4}}lb.exports=function(t,e,n=!1){let{depth:r,width:i,height:o,colorType:s,transColor:a,palette:c}=e,u=t;if(s===3)eO(t,u,i,o,c);else{if(a)nO(t,u,i,o,a);if(r!==8&&!n){if(r===16)u=Buffer.alloc(i*o*4);rO(t,u,i,o,r)}}return u}});var hb=St(($4,fb)=>{var iO=Yt("util"),Ld=Yt("zlib"),db=xd(),oO=ob(),sO=Td(),aO=Hd(),cO=Cd(),wn=fb.exports=function(t){db.call(this),this._parser=new sO(t,{read:this.read.bind(this),error:this._handleError.bind(this),metadata:this._handleMetaData.bind(this),gamma:this.emit.bind(this,"gamma"),palette:this._handlePalette.bind(this),transColor:this._handleTransColor.bind(this),finished:this._finished.bind(this),inflateData:this._inflateData.bind(this),simpleTransparency:this._simpleTransparency.bind(this),headersFinished:this._headersFinished.bind(this)}),this._options=t,this.writable=!0,this._parser.start()};iO.inherits(wn,db);wn.prototype._handleError=function(t){if(this.emit("error",t),this.writable=!1,this.destroy(),this._inflate&&this._inflate.destroy)this._inflate.destroy();if(this._filter)this._filter.destroy(),this._filter.on("error",function(){});this.errord=!0};wn.prototype._inflateData=function(t){if(!this._inflate)if(this._bitmapInfo.interlace)this._inflate=Ld.createInflate(),this._inflate.on("error",this.emit.bind(this,"error")),this._filter.on("complete",this._complete.bind(this)),this._inflate.pipe(this._filter);else{let n=((this._bitmapInfo.width*this._bitmapInfo.bpp*this._bitmapInfo.depth+7>>3)+1)*this._bitmapInfo.height,r=Math.max(n,Ld.Z_MIN_CHUNK);this._inflate=Ld.createInflate({chunkSize:r});let i=n,o=this.emit.bind(this,"error");this._inflate.on("error",function(a){if(!i)return;o(a)}),this._filter.on("complete",this._complete.bind(this));let s=this._filter.write.bind(this._filter);this._inflate.on("data",function(a){if(!i)return;if(a.length>i)a=a.slice(0,i);i-=a.length,s(a)}),this._inflate.on("end",this._filter.end.bind(this._filter))}this._inflate.write(t)};wn.prototype._handleMetaData=function(t){this._metaData=t,this._bitmapInfo=Object.create(t),this._filter=new oO(this._bitmapInfo)};wn.prototype._handleTransColor=function(t){this._bitmapInfo.transColor=t};wn.prototype._handlePalette=function(t){this._bitmapInfo.palette=t};wn.prototype._simpleTransparency=function(){this._metaData.alpha=!0};wn.prototype._headersFinished=function(){this.emit("metadata",this._metaData)};wn.prototype._finished=function(){if(this.errord)return;if(!this._inflate)this.emit("error","No Inflate block");else this._inflate.end()};wn.prototype._complete=function(t){if(this.errord)return;let e;try{let n=aO.dataToBitMap(t,this._bitmapInfo);e=cO(n,this._bitmapInfo,this._options.skipRescale),n=null}catch(n){this._handleError(n);return}this.emit("parsed",e)}});var pb=St((k4,mb)=>{var Fe=bo();mb.exports=function(t,e,n,r){let i=[Fe.COLORTYPE_COLOR_ALPHA,Fe.COLORTYPE_ALPHA].indexOf(r.colorType)!==-1;if(r.colorType===r.inputColorType){let m=function(){let g=new ArrayBuffer(2);return new DataView(g).setInt16(0,256,!0),new Int16Array(g)[0]!==256}();if(r.bitDepth===8||r.bitDepth===16&&m)return t}let o=r.bitDepth!==16?t:new Uint16Array(t.buffer),s=255,a=Fe.COLORTYPE_TO_BPP_MAP[r.inputColorType];if(a===4&&!r.inputHasAlpha)a=3;let c=Fe.COLORTYPE_TO_BPP_MAP[r.colorType];if(r.bitDepth===16)s=65535,c*=2;let u=Buffer.alloc(e*n*c),l=0,d=0,f=r.bgColor||{};if(f.red===void 0)f.red=s;if(f.green===void 0)f.green=s;if(f.blue===void 0)f.blue=s;function h(){let m,g,b,w=s;switch(r.inputColorType){case Fe.COLORTYPE_COLOR_ALPHA:w=o[l+3],m=o[l],g=o[l+1],b=o[l+2];break;case Fe.COLORTYPE_COLOR:m=o[l],g=o[l+1],b=o[l+2];break;case Fe.COLORTYPE_ALPHA:w=o[l+1],m=o[l],g=m,b=m;break;case Fe.COLORTYPE_GRAYSCALE:m=o[l],g=m,b=m;break;default:throw Error("input color type:"+r.inputColorType+" is not supported at present")}if(r.inputHasAlpha){if(!i)w/=s,m=Math.min(Math.max(Math.round((1-w)*f.red+w*m),0),s),g=Math.min(Math.max(Math.round((1-w)*f.green+w*g),0),s),b=Math.min(Math.max(Math.round((1-w)*f.blue+w*b),0),s)}return{red:m,green:g,blue:b,alpha:w}}for(let m=0;m<n;m++)for(let g=0;g<e;g++){let b=h(o,l);switch(r.colorType){case Fe.COLORTYPE_COLOR_ALPHA:case Fe.COLORTYPE_COLOR:if(r.bitDepth===8){if(u[d]=b.red,u[d+1]=b.green,u[d+2]=b.blue,i)u[d+3]=b.alpha}else if(u.writeUInt16BE(b.red,d),u.writeUInt16BE(b.green,d+2),u.writeUInt16BE(b.blue,d+4),i)u.writeUInt16BE(b.alpha,d+6);break;case Fe.COLORTYPE_ALPHA:case Fe.COLORTYPE_GRAYSCALE:{let w=(b.red+b.green+b.blue)/3;if(r.bitDepth===8){if(u[d]=w,i)u[d+1]=b.alpha}else if(u.writeUInt16BE(w,d),i)u.writeUInt16BE(b.alpha,d+2);break}default:throw Error("unrecognised color Type "+r.colorType)}l+=a,d+=c}return u}});var wb=St((y4,bb)=>{var gb=Id();function uO(t,e,n,r,i){for(let o=0;o<n;o++)r[i+o]=t[e+o]}function lO(t,e,n){let r=0,i=e+n;for(let o=e;o<i;o++)r+=Math.abs(t[o]);return r}function dO(t,e,n,r,i,o){for(let s=0;s<n;s++){let a=s>=o?t[e+s-o]:0,c=t[e+s]-a;r[i+s]=c}}function fO(t,e,n,r){let i=0;for(let o=0;o<n;o++){let s=o>=r?t[e+o-r]:0,a=t[e+o]-s;i+=Math.abs(a)}return i}function hO(t,e,n,r,i){for(let o=0;o<n;o++){let s=e>0?t[e+o-n]:0,a=t[e+o]-s;r[i+o]=a}}function mO(t,e,n){let r=0,i=e+n;for(let o=e;o<i;o++){let s=e>0?t[o-n]:0,a=t[o]-s;r+=Math.abs(a)}return r}function pO(t,e,n,r,i,o){for(let s=0;s<n;s++){let a=s>=o?t[e+s-o]:0,c=e>0?t[e+s-n]:0,u=t[e+s]-(a+c>>1);r[i+s]=u}}function gO(t,e,n,r){let i=0;for(let o=0;o<n;o++){let s=o>=r?t[e+o-r]:0,a=e>0?t[e+o-n]:0,c=t[e+o]-(s+a>>1);i+=Math.abs(c)}return i}function bO(t,e,n,r,i,o){for(let s=0;s<n;s++){let a=s>=o?t[e+s-o]:0,c=e>0?t[e+s-n]:0,u=e>0&&s>=o?t[e+s-(n+o)]:0,l=t[e+s]-gb(a,c,u);r[i+s]=l}}function wO(t,e,n,r){let i=0;for(let o=0;o<n;o++){let s=o>=r?t[e+o-r]:0,a=e>0?t[e+o-n]:0,c=e>0&&o>=r?t[e+o-(n+r)]:0,u=t[e+o]-gb(s,a,c);i+=Math.abs(u)}return i}var $O={0:uO,1:dO,2:hO,3:pO,4:bO},kO={0:lO,1:fO,2:mO,3:gO,4:wO};bb.exports=function(t,e,n,r,i){let o;if(!("filterType"in r)||r.filterType===-1)o=[0,1,2,3,4];else if(typeof r.filterType==="number")o=[r.filterType];else throw Error("unrecognised filter types");if(r.bitDepth===16)i*=2;let s=e*i,a=0,c=0,u=Buffer.alloc((s+1)*n),l=o[0];for(let d=0;d<n;d++){if(o.length>1){let f=1/0;for(let h=0;h<o.length;h++){let m=kO[o[h]](t,c,s,i);if(m<f)l=o[h],f=m}}u[a]=l,a++,$O[l](t,c,s,u,a,i),a+=s,c+=s}return u}});var Fd=St((v4,$b)=>{var Jt=bo(),yO=Ad(),vO=pb(),SO=wb(),EO=Yt("zlib"),br=$b.exports=function(t){if(this._options=t,t.deflateChunkSize=t.deflateChunkSize||32768,t.deflateLevel=t.deflateLevel!=null?t.deflateLevel:9,t.deflateStrategy=t.deflateStrategy!=null?t.deflateStrategy:3,t.inputHasAlpha=t.inputHasAlpha!=null?t.inputHasAlpha:!0,t.deflateFactory=t.deflateFactory||EO.createDeflate,t.bitDepth=t.bitDepth||8,t.colorType=typeof t.colorType==="number"?t.colorType:Jt.COLORTYPE_COLOR_ALPHA,t.inputColorType=typeof t.inputColorType==="number"?t.inputColorType:Jt.COLORTYPE_COLOR_ALPHA,[Jt.COLORTYPE_GRAYSCALE,Jt.COLORTYPE_COLOR,Jt.COLORTYPE_COLOR_ALPHA,Jt.COLORTYPE_ALPHA].indexOf(t.colorType)===-1)throw Error("option color type:"+t.colorType+" is not supported at present");if([Jt.COLORTYPE_GRAYSCALE,Jt.COLORTYPE_COLOR,Jt.COLORTYPE_COLOR_ALPHA,Jt.COLORTYPE_ALPHA].indexOf(t.inputColorType)===-1)throw Error("option input color type:"+t.inputColorType+" is not supported at present");if(t.bitDepth!==8&&t.bitDepth!==16)throw Error("option bit depth:"+t.bitDepth+" is not supported at present")};br.prototype.getDeflateOptions=function(){return{chunkSize:this._options.deflateChunkSize,level:this._options.deflateLevel,strategy:this._options.deflateStrategy}};br.prototype.createDeflate=function(){return this._options.deflateFactory(this.getDeflateOptions())};br.prototype.filterData=function(t,e,n){let r=vO(t,e,n,this._options),i=Jt.COLORTYPE_TO_BPP_MAP[this._options.colorType];return SO(r,e,n,this._options,i)};br.prototype._packChunk=function(t,e){let n=e?e.length:0,r=Buffer.alloc(n+12);if(r.writeUInt32BE(n,0),r.writeUInt32BE(t,4),e)e.copy(r,8);return r.writeInt32BE(yO.crc32(r.slice(4,r.length-4)),r.length-4),r};br.prototype.packGAMA=function(t){let e=Buffer.alloc(4);return e.writeUInt32BE(Math.floor(t*Jt.GAMMA_DIVISION),0),this._packChunk(Jt.TYPE_gAMA,e)};br.prototype.packIHDR=function(t,e){let n=Buffer.alloc(13);return n.writeUInt32BE(t,0),n.writeUInt32BE(e,4),n[8]=this._options.bitDepth,n[9]=this._options.colorType,n[10]=0,n[11]=0,n[12]=0,this._packChunk(Jt.TYPE_IHDR,n)};br.prototype.packIDAT=function(t){return this._packChunk(Jt.TYPE_IDAT,t)};br.prototype.packIEND=function(){return this._packChunk(Jt.TYPE_IEND,null)}});var Sb=St((S4,vb)=>{var MO=Yt("util"),kb=Yt("stream"),xO=bo(),OO=Fd(),yb=vb.exports=function(t){kb.call(this);let e=t||{};this._packer=new OO(e),this._deflate=this._packer.createDeflate(),this.readable=!0};MO.inherits(yb,kb);yb.prototype.pack=function(t,e,n,r){if(this.emit("data",Buffer.from(xO.PNG_SIGNATURE)),this.emit("data",this._packer.packIHDR(e,n)),r)this.emit("data",this._packer.packGAMA(r));let i=this._packer.filterData(t,e,n);this._deflate.on("error",this.emit.bind(this,"error")),this._deflate.on("data",function(o){this.emit("data",this._packer.packIDAT(o))}.bind(this)),this._deflate.on("end",function(){this.emit("data",this._packer.packIEND()),this.emit("end")}.bind(this)),this._deflate.end(i)}});var Rb=St((Ns,Ib)=>{var Eb=Yt("assert").ok,wo=Yt("zlib"),IO=Yt("util"),Mb=Yt("buffer").kMaxLength;function di(t){if(!(this instanceof di))return new di(t);if(t&&t.chunkSize<wo.Z_MIN_CHUNK)t.chunkSize=wo.Z_MIN_CHUNK;if(wo.Inflate.call(this,t),this._offset=this._offset===void 0?this._outOffset:this._offset,this._buffer=this._buffer||this._outBuffer,t&&t.maxLength!=null)this._maxLength=t.maxLength}function RO(t){return new di(t)}function xb(t,e){if(e)process.nextTick(e);if(!t._handle)return;t._handle.close(),t._handle=null}di.prototype._processChunk=function(t,e,n){if(typeof n==="function")return wo.Inflate._processChunk.call(this,t,e,n);let r=this,i=t&&t.length,o=this._chunkSize-this._offset,s=this._maxLength,a=0,c=[],u=0,l;this.on("error",function(m){l=m});function d(m,g){if(r._hadError)return;let b=o-g;if(Eb(b>=0,"have should not go down"),b>0){let w=r._buffer.slice(r._offset,r._offset+b);if(r._offset+=b,w.length>s)w=w.slice(0,s);if(c.push(w),u+=w.length,s-=w.length,s===0)return!1}if(g===0||r._offset>=r._chunkSize)o=r._chunkSize,r._offset=0,r._buffer=Buffer.allocUnsafe(r._chunkSize);if(g===0)return a+=i-m,i=m,!0;return!1}Eb(this._handle,"zlib binding closed");let f;do f=this._handle.writeSync(e,t,a,i,this._buffer,this._offset,o),f=f||this._writeState;while(!this._hadError&&d(f[0],f[1]));if(this._hadError)throw l;if(u>=Mb)throw xb(this),RangeError("Cannot create final Buffer. It would be larger than 0x"+Mb.toString(16)+" bytes");let h=Buffer.concat(c,u);return xb(this),h};IO.inherits(di,wo.Inflate);function PO(t,e){if(typeof e==="string")e=Buffer.from(e);if(!(e instanceof Buffer))throw TypeError("Not a string or buffer");let n=t._finishFlushFlag;if(n==null)n=wo.Z_FINISH;return t._processChunk(e,n)}function Ob(t,e){return PO(new di(e),t)}Ib.exports=Ns=Ob;Ns.Inflate=di;Ns.createInflate=RO;Ns.inflateSync=Ob});var jd=St((E4,Nb)=>{var Pb=Nb.exports=function(t){this._buffer=t,this._reads=[]};Pb.prototype.read=function(t,e){this._reads.push({length:Math.abs(t),allowLess:t<0,func:e})};Pb.prototype.process=function(){while(this._reads.length>0&&this._buffer.length){let t=this._reads[0];if(this._buffer.length&&(this._buffer.length>=t.length||t.allowLess)){this._reads.shift();let e=this._buffer;this._buffer=e.slice(t.length),t.func.call(this,e.slice(0,t.length))}else break}if(this._reads.length>0)throw Error("There are some read requests waitng on finished stream");if(this._buffer.length>0)throw Error("unrecognised content at end of stream")}});var Ab=St((TO)=>{var NO=jd(),AO=Rd();TO.process=function(t,e){let n=[],r=new NO(t);return new AO(e,{read:r.read.bind(r),write:function(o){n.push(o)},complete:function(){}}).start(),r.process(),Buffer.concat(n)}});var Lb=St((x4,Cb)=>{var Tb=!0,Hb=Yt("zlib"),CO=Rb();if(!Hb.deflateSync)Tb=!1;var LO=jd(),FO=Ab(),jO=Td(),_O=Hd(),BO=Cd();Cb.exports=function(t,e){if(!Tb)throw Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");let n;function r(S){n=S}let i;function o(S){i=S}function s(S){i.transColor=S}function a(S){i.palette=S}function c(){i.alpha=!0}let u;function l(S){u=S}let d=[];function f(S){d.push(S)}let h=new LO(t);if(new jO(e,{read:h.read.bind(h),error:r,metadata:o,gamma:l,palette:a,transColor:s,inflateData:f,simpleTransparency:c}).start(),h.process(),n)throw n;let g=Buffer.concat(d);d.length=0;let b;if(i.interlace)b=Hb.inflateSync(g);else{let M=((i.width*i.bpp*i.depth+7>>3)+1)*i.height;b=CO(g,{chunkSize:M,maxLength:M})}if(g=null,!b||!b.length)throw Error("bad png - invalid inflate data response");let w=FO.process(b,i);g=null;let k=_O.dataToBitMap(w,i);w=null;let v=BO(k,i,e.skipRescale);return i.data=v,i.gamma=u||0,i}});var Bb=St((O4,_b)=>{var Fb=!0,jb=Yt("zlib");if(!jb.deflateSync)Fb=!1;var GO=bo(),UO=Fd();_b.exports=function(t,e){if(!Fb)throw Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");let r=new UO(e||{}),i=[];if(i.push(Buffer.from(GO.PNG_SIGNATURE)),i.push(r.packIHDR(t.width,t.height)),t.gamma)i.push(r.packGAMA(t.gamma));let o=r.filterData(t.data,t.width,t.height),s=jb.deflateSync(o,r.getDeflateOptions());if(o=null,!s||!s.length)throw Error("bad png - invalid compressed data response");return i.push(r.packIDAT(s)),i.push(r.packIEND()),Buffer.concat(i)}});var Gb=St((zO)=>{var WO=Lb(),KO=Bb();zO.read=function(t,e){return WO(t,e||{})};zO.write=function(t,e){return KO(t,e)}});var Wb=St((QO)=>{var YO=Yt("util"),Ub=Yt("stream"),JO=hb(),VO=Sb(),ZO=Gb(),re=QO.PNG=function(t){if(Ub.call(this),t=t||{},this.width=t.width|0,this.height=t.height|0,this.data=this.width>0&&this.height>0?Buffer.alloc(4*this.width*this.height):null,t.fill&&this.data)this.data.fill(0);this.gamma=0,this.readable=this.writable=!0,this._parser=new JO(t),this._parser.on("error",this.emit.bind(this,"error")),this._parser.on("close",this._handleClose.bind(this)),this._parser.on("metadata",this._metadata.bind(this)),this._parser.on("gamma",this._gamma.bind(this)),this._parser.on("parsed",function(e){this.data=e,this.emit("parsed",e)}.bind(this)),this._packer=new VO(t),this._packer.on("data",this.emit.bind(this,"data")),this._packer.on("end",this.emit.bind(this,"end")),this._parser.on("close",this._handleClose.bind(this)),this._packer.on("error",this.emit.bind(this,"error"))};YO.inherits(re,Ub);re.sync=ZO;re.prototype.pack=function(){if(!this.data||!this.data.length)return this.emit("error","No data provided"),this;return process.nextTick(function(){this._packer.pack(this.data,this.width,this.height,this.gamma)}.bind(this)),this};re.prototype.parse=function(t,e){if(e){let n,r;n=function(i){this.removeListener("error",r),this.data=i,e(null,this)}.bind(this),r=function(i){this.removeListener("parsed",n),e(i,null)}.bind(this),this.once("parsed",n),this.once("error",r)}return this.end(t),this};re.prototype.write=function(t){return this._parser.write(t),!0};re.prototype.end=function(t){this._parser.end(t)};re.prototype._metadata=function(t){this.width=t.width,this.height=t.height,this.emit("metadata",t)};re.prototype._gamma=function(t){this.gamma=t};re.prototype._handleClose=function(){if(!this._parser.writable&&!this._packer.readable)this.emit("close")};re.bitblt=function(t,e,n,r,i,o,s,a){if(n|=0,r|=0,i|=0,o|=0,s|=0,a|=0,n>t.width||r>t.height||n+i>t.width||r+o>t.height)throw Error("bitblt reading outside image");if(s>e.width||a>e.height||s+i>e.width||a+o>e.height)throw Error("bitblt writing outside image");for(let c=0;c<o;c++)t.data.copy(e.data,(a+c)*e.width+s<<2,(r+c)*t.width+n<<2,(r+c)*t.width+n+i<<2)};re.prototype.bitblt=function(t,e,n,r,i,o,s){return re.bitblt(this,t,e,n,r,i,o,s),this};re.adjustGamma=function(t){if(t.gamma){for(let e=0;e<t.height;e++)for(let n=0;n<t.width;n++){let r=t.width*e+n<<2;for(let i=0;i<3;i++){let o=t.data[r+i]/255;o=Math.pow(o,0.45454545454545453/t.gamma),t.data[r+i]=Math.round(o*255)}}t.gamma=0}};re.prototype.adjustGamma=function(){re.adjustGamma(this)}});var eh=St((G6,F$)=>{var th={to(t,e){if(!e)return`\x1B[${t+1}G`;return`\x1B[${e+1};${t+1}H`},move(t,e){let n="";if(t<0)n+=`\x1B[${-t}D`;else if(t>0)n+=`\x1B[${t}C`;if(e<0)n+=`\x1B[${-e}A`;else if(e>0)n+=`\x1B[${e}B`;return n},up:(t=1)=>`\x1B[${t}A`,down:(t=1)=>`\x1B[${t}B`,forward:(t=1)=>`\x1B[${t}C`,backward:(t=1)=>`\x1B[${t}D`,nextLine:(t=1)=>"\x1B[E".repeat(t),prevLine:(t=1)=>"\x1B[F".repeat(t),left:"\x1B[G",hide:"\x1B[?25l",show:"\x1B[?25h",save:"\x1B7",restore:"\x1B8"},YP={up:(t=1)=>"\x1B[S".repeat(t),down:(t=1)=>"\x1B[T".repeat(t)},JP={screen:"\x1B[2J",up:(t=1)=>"\x1B[1J".repeat(t),down:(t=1)=>"\x1B[J".repeat(t),line:"\x1B[2K",lineEnd:"\x1B[K",lineStart:"\x1B[1K",lines(t){let e="";for(let n=0;n<t;n++)e+=this.line+(n<t-1?th.up():"");if(t)e+=th.left;return e}};F$.exports={cursor:th,scroll:YP,erase:JP,beep:"\x07"}});import{spawnSync as z5}from"node:child_process";import{isMainThread as D5}from"node:worker_threads";import{parseArgs as F5}from"node:util";var At={name:"@kecan0406/ttheme",version:"1.2.14",type:"module",bin:{ttheme:"bin/ttheme.js"},files:["bin","dist/manifest.json","shell","!shell/check.zsh"],description:"Character terminal palettes for Ghostty, kitty, Alacritty, WezTerm, iTerm2, Windows Terminal, Warp and Konsole",license:"MIT",author:"kecan0406",repository:{type:"git",url:"git+https://github.com/kecan0406/ttheme.git"},homepage:"https://github.com/kecan0406/ttheme#readme",bugs:"https://github.com/kecan0406/ttheme/issues",keywords:["terminal","theme","ghostty","kitty","alacritty","wezterm","iterm2","konsole"],devDependencies:{"@biomejs/biome":"^2.3.0","@clack/prompts":"^1.7.0","@jsquash/jpeg":"^1.6.0","@material/material-color-utilities":"^0.4.0","@types/bun":"^1.3.0","@types/pngjs":"6.0.5","@xterm/headless":"6.0.0","fast-string-width":"^3.0.2",pngjs:"7.0.0","smol-toml":"^1.9.0",typescript:"^5.8.2"},engines:{bun:">=1.3",node:">=20.11"}};import{existsSync as P8,readFileSync as N8}from"node:fs";var Pg=(()=>{let t=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return(e)=>{let n=0;t.lastIndex=0;while(t.test(e))n+=1;return e.length-n}})(),Ng=(t)=>{return t===12288||t>=65281&&t<=65376||t>=65504&&t<=65510},Ag=(t)=>{return t===8987||t===9001||t>=12272&&t<=12287||t>=12289&&t<=12350||t>=12441&&t<=12543||t>=12549&&t<=12591||t>=12593&&t<=12686||t>=12688&&t<=12771||t>=12783&&t<=12830||t>=12832&&t<=12871||t>=12880&&t<=19903||t>=65040&&t<=65049||t>=65072&&t<=65106||t>=65108&&t<=65126||t>=65128&&t<=65131||t>=127488&&t<=127490||t>=127504&&t<=127547||t>=127552&&t<=127560||t>=131072&&t<=196605||t>=196608&&t<=262141};var k2=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,y2=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,Tg=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,v2=/\t{1,1000}/y,Hg=/[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu,S2=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,E2=/\p{M}+/gu,M2={limit:1/0,ellipsis:""},Cg=(t,e={},n={})=>{let r=e.limit??1/0,i=e.ellipsis??"",o=e?.ellipsisWidth??(i?Cg(i,M2,n).width:0),s=0,a=n.controlWidth??0,c=n.tabWidth??8,u=n.emojiWidth??2,l=2,d=n.regularWidth??1,f=n.wideWidth??2,h=[[S2,d],[k2,0],[y2,a],[v2,c],[Hg,u],[Tg,f]],m=0,g=0,b=t.length,w=0,k=!1,v=b,S=Math.max(0,r-o),M=0,I=0,O=0,H=0;t:while(!0){if(I>M||g>=b&&g>m){let N=t.slice(M,I)||t.slice(m,g);w=0;for(let L of N.replaceAll(E2,"")){let K=L.codePointAt(0)||0;if(Ng(K))H=2;else if(Ag(K))H=f;else H=d;if(O+H>S)v=Math.min(v,Math.max(M,m)+w);if(O+H>r){k=!0;break t}w+=L.length,O+=H}M=I=0}if(g>=b)break t;for(let N=0,L=h.length;N<L;N++){let[K,B]=h[N];if(K.lastIndex=g,K.test(t)){if(w=K===Tg?Pg(t.slice(g,K.lastIndex)):K===Hg?1:K.lastIndex-g,H=w*B,O+H>S)v=Math.min(v,g+Math.floor((S-O)/B));if(O+H>r){k=!0;break t}O+=H,M=m,I=g,g=m=K.lastIndex;continue t}}g+=1}return{width:k?S:O,index:k?v:b,truncated:k,ellipsed:k&&r>=o}},Lg=Cg;var x2={limit:1/0,ellipsis:"",ellipsisWidth:0},O2=(t,e={})=>{return Lg(t,x2,e).width},_=O2;function wd(t){let e=t.replace("#","");return[e.slice(0,2),e.slice(2,4),e.slice(4,6)].map((n)=>Number.parseInt(n,16)).join(";")}function qe(t){return`\x1B[38;2;${wd(t)}m`}function mc(t,e){return`\x1B[48;2;${wd(t)};38;2;${wd(e)}m`}function Fg(t,e="\x1B[39m"){return`${t.map((n)=>`${qe(n)}■`).join(" ")}${e}`}var Lt="\x1B[0m",ct="\x1B[1m",C="\x1B[2m",$e="\x1B[22m",lo="\x1B[32m",ne="\x1B[33m",pc="\x1B[36m",jn=["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"],Is="⧉";function gc(t,e){return e?`\x1B]8;;${e}\x1B\\${t}\x1B]8;;\x1B\\`:t}function Rs(t,e){if(t[e]!=="\x1B")return 0;if(t[e+1]==="]"){let r=t.indexOf("\x07",e+2),i=t.indexOf("\x1B\\",e+2),o=r!==-1&&(i===-1||r<i)?r+1:i!==-1?i+2:0;return o?o-e:0}if(t[e+1]!=="[")return 0;let n=e+2;while(n<t.length&&!/[@-~]/.test(t[n]))n++;return n<t.length?n-e+1:0}function $d(t,e){let n="",r=0,i=0;while(i<t.length){let o=Rs(t,i);if(o>0){n+=t.slice(i,i+o),i+=o;continue}let s=String.fromCodePoint(t.codePointAt(i)),a=_(s);if(r+a>e)break;n+=s,r+=a,i+=s.length}return{head:n,used:r}}function rt(t,e,n=!0){if(e<=0)return"";let r=_(t);if(r<=e)return n?t+" ".repeat(e-r):t;let{head:i,used:o}=$d(t,e-1);return`${i}${t.includes("\x1B")?"\x1B[0m":""}…${n?" ".repeat(e-1-o):""}`}function jg(t,e){let{head:n,used:r}=$d(t,e);return`${n}${t.includes("\x1B")?Lt:""}${" ".repeat(e-r)}`}function yt(t,e,n){let r=n-_(e)-1;return r<=0?rt(t,n):`${rt(t,r)} ${e}`}function bt(t,e){let n=[],r="";for(let i of t.split(/\s+/).filter(Boolean)){let o=r?`${r} ${i}`:i;if(_(o)<=e){r=o;continue}if(r)n.push(r);while(_(i)>e){let{head:s}=$d(i,e),a=Math.max(s.lastIndexOf("/")+1,s.lastIndexOf("#")),c=a>0?a:s.length;n.push(i.slice(0,c)),i=i.slice(c)}r=i}if(r)n.push(r);return n}import{existsSync as d$,readFileSync as zf}from"node:fs";import{join as f$}from"node:path";var I2=/^#[0-9a-f]{6}$/;function le(t){return I2.test(t)}function et(t){let e=Number.parseInt(t.slice(1),16);return[e>>16&255,e>>8&255,e&255]}function pt(t,e,n){let r=et(t),i=et(e);return`#${r.map((o,s)=>Math.round(o+((i[s]??0)-o)*n).toString(16).padStart(2,"0")).join("")}`}function vt(t){let[e,n,r]=et(t).map((i)=>{let o=i/255;return o<=0.03928?o/12.92:((o+0.055)/1.055)**2.4});return 0.2126*e+0.7152*n+0.0722*r}function wt(t,e){let n=vt(t),r=vt(e);return(Math.max(n,r)+0.05)/(Math.min(n,r)+0.05)}function bc(t,e){return Math.round(wt(t,e)*100)/100}function R2(t){let e=t/255;return e<=0.04045?e/12.92:((e+0.055)/1.055)**2.4}function Et(t){let[e,n,r]=et(t).map(R2),i=Math.cbrt(0.4122214708*e+0.5363325363*n+0.0514459929*r),o=Math.cbrt(0.2119034982*e+0.6806995451*n+0.1073969566*r),s=Math.cbrt(0.0883024619*e+0.2817188376*n+0.6299787005*r),a=1.9779984951*i-2.428592205*o+0.4505937099*s,c=0.0259040371*i+0.7827717662*o-0.808675766*s;return{l:0.2104542553*i+0.793617785*o-0.0040720468*s,c:Math.hypot(a,c),h:(Math.atan2(c,a)*180/Math.PI+360)%360}}var hr=7,_g=3,kd=0.15,Bg=1.6,vd=[1,2,3,4,5,6,9,10,11,12,13,14],Gg=[7,15],mr=[1,2,3,4,5,6],ke={1:{name:"red",center:19,width:25},2:{name:"green",center:132,width:35},3:{name:"yellow",center:88,width:35},4:{name:"blue",center:250,width:60},5:{name:"magenta",center:329,width:40},6:{name:"cyan",center:197,width:60}},ui=0.03,Ye=25,fo=15,ho=0.08;function _n(t,e){let n=t.ansi[e];if(n===void 0)throw Error(`${t.name}: missing ANSI ${e}`);return n}function yd(t,e,n){let r=t.background;return e.flatMap((i)=>{let o=_n(t,i);return wt(o,r)<n?[`ANSI ${i} ${o} on ${r} is ${bc(o,r)}:1, needs ${n}:1`]:[]})}function Ug(t,e){return Math.min(...e.map((n)=>wt(_n(t,n),t.background)))}var Wg=[{rule:"foreground",label:"foreground on background",unit:"ratio",min:hr,measure:({foreground:t,background:e})=>wt(t,e),check:({foreground:t,background:e})=>wt(t,e)<hr?[`foreground ${t} on ${e} is ${bc(t,e)}:1, needs ${hr}:1`]:[]},{rule:"accents",label:"weakest accent on background",unit:"ratio",min:_g,measure:(t)=>Ug(t,vd),check:(t)=>yd(t,vd,_g)},{rule:"ansi0-dark",label:"ansi0 luminance",unit:"luminance",max:kd,measure:(t)=>vt(_n(t,0)),check:(t)=>{let e=_n(t,0);return vt(e)>kd?[`ANSI 0 ${e} has luminance ${vt(e).toFixed(3)}, needs <= ${kd}`]:[]}},{rule:"light-ansi",label:"ansi7 and ansi15 on background",unit:"ratio",min:hr,measure:(t)=>Ug(t,Gg),check:(t)=>yd(t,Gg,hr)},{rule:"ansi8-visible",label:"ansi8 on background",unit:"ratio",min:Bg,measure:(t)=>wt(_n(t,8),t.background),check:(t)=>yd(t,[8],Bg)},{rule:"selection",label:"foreground on selection",unit:"ratio",min:hr,measure:({foreground:t,selectionBackground:e})=>e===void 0?Number.NaN:wt(t,e),check:({foreground:t,selectionBackground:e})=>e!==void 0&&wt(t,e)<hr?[`foreground ${t} on selection ${e} is ${bc(t,e)}:1, needs ${hr}:1`]:[]}];function ye(t,e){let n=Math.abs(t-e)%360;return Math.min(n,360-n)}var pn=(t)=>t>8?t-8:t;function mo(t){let e=t.signatureSlots.filter((n)=>n.startsWith("ansi")).map((n)=>Number(n.slice(4)));return new Set(e.flatMap((n)=>mr.includes(pn(n))?[n,n>8?n-8:n+8]:[n]))}function Ps(t,e){let n=Et(_n(t,e));return n.c<ui?void 0:n}function pr(t){let e=mo(t);return vd.flatMap((n)=>{let r=Ps(t,n),i=ke[pn(n)];if(r===void 0||i===void 0||e.has(n))return[];let o=ye(r.h,i.center)-i.width;return o>0?[{slot:n,hue:r.h,over:o}]:[]})}function Bn(t){let e=new Set(t.signatureSlots);return mr.flatMap((n)=>{let r=Ps(t,n),i=Ps(t,n+8);if(r===void 0||i===void 0||e.has(`ansi${n}`)&&e.has(`ansi${n+8}`))return[];return[{normal:n,gap:ye(r.h,i.h)}]})}function Gn(t){let e=mo(t);return[0,8].flatMap((n)=>mr.flatMap((r)=>mr.filter((i)=>i>r).flatMap((i)=>{let[o,s]=[n+r,n+i],a=Ps(t,o),c=Ps(t,s);if(a===void 0||c===void 0||e.has(o)&&e.has(s))return[];return ye(a.h,c.h)<fo&&Math.abs(a.l-c.l)<ho?[[o,s]]:[]})))}var P2=[{rule:"ansi-role",label:"accent hue outside its ANSI role",unit:"degrees",max:0,measure:(t)=>Math.max(0,...pr(t).map((e)=>e.over)),check:(t)=>pr(t).map(({slot:e,hue:n,over:r})=>{let i=ke[pn(e)];return`ANSI ${e} ${_n(t,e)} has hue ${n.toFixed(0)}°, ${r.toFixed(0)}° outside ${i.name} (${i.center}±${i.width}°)`})},{rule:"bright-follows",label:"widest normal to bright hue gap",unit:"degrees",max:Ye,measure:(t)=>Math.max(0,...Bn(t).map((e)=>e.gap)),check:(t)=>Bn(t).filter((e)=>e.gap>Ye).map(({normal:e,gap:n})=>`ANSI ${e+8} is ${n.toFixed(0)}° from ANSI ${e}, needs <= ${Ye}°`)},{rule:"distinct",label:"accent pairs that read as one color",unit:"pairs",max:0,measure:(t)=>Gn(t).length,check:(t)=>Gn(t).map(([e,n])=>`ANSI ${e} ${_n(t,e)} and ANSI ${n} ${_n(t,n)} are within ${fo}° hue and ${ho} lightness`)}],wc=[...Wg,...P2],Sd=wc.map((t)=>t.rule),ve=wc.map(({rule:t,label:e,unit:n,min:r,max:i})=>({rule:t,label:e,unit:n,...r===void 0?{}:{min:r},...i===void 0?{}:{max:i}}));function gn(t){return wc.map((e)=>Math.round(e.measure(t)*1000)/1000)}function Kg(t,e){return t.filter((n)=>!e.waive.includes(n.rule)).flatMap((n)=>n.check(e).map((r)=>({theme:e.name,rule:n.rule,detail:r})))}function Un(t){return Kg(wc,t)}function zg(t){return Kg(Wg,t)}function Dg(t){return t.flatMap(Un)}import{chmodSync as N2,copyFileSync as A2,existsSync as po,mkdirSync as T2,readFileSync as Ed,realpathSync as H2,renameSync as Yg,rmSync as qg,statSync as C2,writeFileSync as Jg}from"node:fs";import{dirname as L2}from"node:path";function Vg(t){return`${t}.ttheme.bak`}var F2=/^(?:#|--) ttheme begin$|path = "ttheme-|^DefaultProfile=ttheme-/m;function Md(t){let e=Vg(t);if(po(t)&&!po(e)&&!F2.test(Ed(t,"utf8")))A2(t,e)}function F(t,e){let n=po(t)?H2(t):t;T2(L2(n),{recursive:!0});let r=`${n}.ttheme-${process.pid}`;if(Jg(r,e),po(n))N2(r,C2(n).mode&4095);Yg(r,n)}function li(t,e,n){if(Jg(t,n),t!==e)Yg(t,e)}function bn(t,e){if((po(t)?Ed(t,"utf8"):void 0)===e)return!1;return Md(t),F(t,e),!0}function Zg(t,e){let n=Vg(t),r=po(n)?Ed(n,"utf8"):void 0;if(e===""&&r===void 0)return qg(t,{force:!0}),"removed";if(F(t,e),r===void 0||r===e)return qg(n,{force:!0}),"restored";return"kept backup"}import{createHash as a0}from"node:crypto";import{copyFileSync as AR,existsSync as hf,mkdirSync as TR,readdirSync as HR,readFileSync as Io,renameSync as c0,rmSync as Oo,statSync as CR}from"node:fs";import{basename as u0,isAbsolute as LR,join as Y}from"node:path";import{createHash as iR}from"node:crypto";import{existsSync as oR,readdirSync as sR,readFileSync as aR,rmSync as cR,statSync as uR,utimesSync as lR}from"node:fs";import{join as Mo}from"node:path";import{readdirSync as dI,rmSync as fI,statSync as hI}from"node:fs";import{setDefaultAutoSelectFamilyAttemptTimeout as mI}from"node:net";import{homedir as pI}from"node:os";import{join as Ls}from"node:path";import{setTimeout as gI}from"node:timers/promises";var qb=bd(Wb(),1);import{constants as nI,deflateSync as rI,inflateSync as iI}from"node:zlib";import{inflateRawSync as tI}from"node:zlib";var XO=(()=>{var t=import.meta.url;return function(e={}){var n=e,r,i,o=new Promise((p,$)=>{r=p,i=$});let a=globalThis.ServiceWorkerGlobalScope!==void 0&&typeof self<"u"&&globalThis.caches&&globalThis.caches.default!==void 0,c=typeof process==="object"&&process.release&&process.release.name==="node";if(a||c){if(!globalThis.ImageData)globalThis.ImageData=class{constructor($,y,E){this.data=$,this.width=y,this.height=E}};if(import.meta.url===void 0)import.meta.url="https://localhost";if(typeof self<"u"&&self.location===void 0)self.location={href:""}}var u=Object.assign({},n),l=[],d="./this.program",f=(p,$)=>{throw $},h=typeof window=="object",m=typeof importScripts=="function",g=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string",b="";function w(p){if(n.locateFile)return n.locateFile(p,b);return b+p}var k,v,S;if(h||m){if(m)b=self.location.href;else if(typeof document<"u"&&document.currentScript)b=document.currentScript.src;if(t)b=t;if(b.startsWith("blob:"))b="";else b=b.substr(0,b.replace(/[?#].*/,"").lastIndexOf("/")+1);{if(k=(p)=>{var $=new XMLHttpRequest;return $.open("GET",p,!1),$.send(null),$.responseText},m)S=(p)=>{var $=new XMLHttpRequest;return $.open("GET",p,!1),$.responseType="arraybuffer",$.send(null),new Uint8Array($.response)};v=(p,$,y)=>{var E=new XMLHttpRequest;E.open("GET",p,!0),E.responseType="arraybuffer",E.onload=()=>{if(E.status==200||E.status==0&&E.response){$(E.response);return}y()},E.onerror=y,E.send(null)}}}var M=n.print||console.log.bind(console),I=n.printErr||console.error.bind(console);if(Object.assign(n,u),u=null,n.arguments)l=n.arguments;if(n.thisProgram)d=n.thisProgram;if(n.quit)f=n.quit;var O;if(n.wasmBinary)O=n.wasmBinary;var H,N=!1,L,K,B,X,z,Mt,tt,fr,fn;function hn(){var p=H.buffer;n.HEAP8=K=new Int8Array(p),n.HEAP16=X=new Int16Array(p),n.HEAPU8=B=new Uint8Array(p),n.HEAPU16=z=new Uint16Array(p),n.HEAP32=Mt=new Int32Array(p),n.HEAPU32=tt=new Uint32Array(p),n.HEAPF32=fr=new Float32Array(p),n.HEAPF64=fn=new Float64Array(p)}var mn=[],lc=[],ri=[],rd=!1;function id(){if(n.preRun){if(typeof n.preRun=="function")n.preRun=[n.preRun];while(n.preRun.length)vM(n.preRun.shift())}ad(mn)}function od(){rd=!0,ad(lc)}function yM(){if(n.postRun){if(typeof n.postRun=="function")n.postRun=[n.postRun];while(n.postRun.length)EM(n.postRun.shift())}ad(ri)}function vM(p){mn.unshift(p)}function SM(p){lc.unshift(p)}function EM(p){ri.unshift(p)}var ii=0,sd=null,xs=null;function MM(p){ii++,n.monitorRunDependencies?.(ii)}function xM(p){if(ii--,n.monitorRunDependencies?.(ii),ii==0){if(sd!==null)clearInterval(sd),sd=null;if(xs){var $=xs;xs=null,$()}}}function ug(p){n.onAbort?.(p),p="Aborted("+p+")",I(p),N=!0,L=1,p+=". Build with -sASSERTIONS for more info.";var $=new WebAssembly.RuntimeError(p);throw i($),$}var OM="data:application/octet-stream;base64,",lg=(p)=>p.startsWith(OM),oi;if(n.locateFile){if(oi="mozjpeg_dec.wasm",!lg(oi))oi=w(oi)}else oi=new URL("mozjpeg_dec.wasm",import.meta.url).href;function dg(p){if(p==oi&&O)return new Uint8Array(O);if(S)return S(p);throw"both async and sync fetching of the wasm failed"}function IM(p){if(!O&&(h||m)){if(typeof fetch=="function")return fetch(p,{credentials:"same-origin"}).then(($)=>{if(!$.ok)throw`failed to load wasm binary file at '${p}'`;return $.arrayBuffer()}).catch(()=>dg(p))}return Promise.resolve().then(()=>dg(p))}function fg(p,$,y){return IM(p).then((E)=>WebAssembly.instantiate(E,$)).then(y,(E)=>{I(`failed to asynchronously prepare wasm: ${E}`),ug(E)})}function RM(p,$,y,E){if(!p&&typeof WebAssembly.instantiateStreaming=="function"&&!lg($)&&typeof fetch=="function")return fetch($,{credentials:"same-origin"}).then((R)=>{var P=WebAssembly.instantiateStreaming(R,y);return P.then(E,function(G){return I(`wasm streaming compile failed: ${G}`),I("falling back to ArrayBuffer instantiation"),fg($,y,E)})});return fg($,y,E)}function PM(){var p={a:t2};function $(E,R){return te=E.exports,H=te.A,hn(),kg=te.F,SM(te.B),xM("wasm-instantiate"),te}MM("wasm-instantiate");function y(E){$(E.instance)}if(n.instantiateWasm)try{return n.instantiateWasm(p,$)}catch(E){I(`Module.instantiateWasm callback failed with error: ${E}`),i(E)}return RM(O,oi,p,y).catch(i),{}}function NM(p){this.name="ExitStatus",this.message=`Program terminated with exit(${p})`,this.status=p}var ad=(p)=>{while(p.length>0)p.shift()(n)},AM=n.noExitRuntime||!0;class hg{constructor(p){this.excPtr=p,this.ptr=p-24}set_type(p){tt[this.ptr+4>>2]=p}get_type(){return tt[this.ptr+4>>2]}set_destructor(p){tt[this.ptr+8>>2]=p}get_destructor(){return tt[this.ptr+8>>2]}set_caught(p){p=p?1:0,K[this.ptr+12]=p}get_caught(){return K[this.ptr+12]!=0}set_rethrown(p){p=p?1:0,K[this.ptr+13]=p}get_rethrown(){return K[this.ptr+13]!=0}init(p,$){this.set_adjusted_ptr(0),this.set_type(p),this.set_destructor($)}set_adjusted_ptr(p){tt[this.ptr+16>>2]=p}get_adjusted_ptr(){return tt[this.ptr+16>>2]}get_exception_ptr(){var p=Og(this.get_type());if(p)return tt[this.excPtr>>2];var $=this.get_adjusted_ptr();if($!==0)return $;return this.excPtr}}var mg=0,TM=0,HM=(p,$,y)=>{var E=new hg(p);throw E.init($,y),mg=p,TM++,mg},CM=(p,$,y,E,R)=>{},LM=()=>{var p=Array(256);for(var $=0;$<256;++$)p[$]=String.fromCharCode($);pg=p},pg,De=(p)=>{var $="",y=p;while(B[y])$+=pg[B[y++]];return $},so={},si={},dc={},gg,we=(p)=>{throw new gg(p)},bg,wg=(p)=>{throw new bg(p)},FM=(p,$,y)=>{p.forEach(function(T){dc[T]=$});function E(T){var U=y(T);if(U.length!==p.length)wg("Mismatched type converter count");for(var Z=0;Z<p.length;++Z)Cn(p[Z],U[Z])}var R=Array($.length),P=[],G=0;if($.forEach((T,U)=>{if(si.hasOwnProperty(T))R[U]=si[T];else{if(P.push(T),!so.hasOwnProperty(T))so[T]=[];so[T].push(()=>{if(R[U]=si[T],++G,G===P.length)E(R)})}}),P.length===0)E(R)};function jM(p,$,y={}){var E=$.name;if(!p)we(`type "${E}" must have a positive integer typeid pointer`);if(si.hasOwnProperty(p))if(y.ignoreDuplicateRegistrations)return;else we(`Cannot register type '${E}' twice`);if(si[p]=$,delete dc[p],so.hasOwnProperty(p)){var R=so[p];delete so[p],R.forEach((P)=>P())}}function Cn(p,$,y={}){if(!("argPackAdvance"in $))throw TypeError("registerType registeredInstance requires argPackAdvance");return jM(p,$,y)}var ai=8,_M=(p,$,y,E)=>{$=De($),Cn(p,{name:$,fromWireType:function(R){return!!R},toWireType:function(R,P){return P?y:E},argPackAdvance:ai,readValueFromPointer:function(R){return this.fromWireType(B[R])},destructorFunction:null})},cd=[],Ln=[],ud=(p)=>{if(p>9&&--Ln[p+1]===0)Ln[p]=void 0,cd.push(p)},BM=()=>Ln.length/2-5-cd.length,GM=()=>{Ln.push(0,1,void 0,1,null,1,!0,1,!1,1),n.count_emval_handles=BM},ci={toValue:(p)=>{if(!p)we("Cannot use deleted val. handle = "+p);return Ln[p]},toHandle:(p)=>{switch(p){case void 0:return 2;case null:return 4;case!0:return 6;case!1:return 8;default:{let $=cd.pop()||Ln.length;return Ln[$]=p,Ln[$+1]=1,$}}}};function ld(p){return this.fromWireType(tt[p>>2])}var UM={name:"emscripten::val",fromWireType:(p)=>{var $=ci.toValue(p);return ud(p),$},toWireType:(p,$)=>ci.toHandle($),argPackAdvance:ai,readValueFromPointer:ld,destructorFunction:null},WM=(p)=>Cn(p,UM),KM=(p,$)=>{switch($){case 4:return function(y){return this.fromWireType(fr[y>>2])};case 8:return function(y){return this.fromWireType(fn[y>>3])};default:throw TypeError(`invalid float width (${$}): ${p}`)}},zM=(p,$,y)=>{$=De($),Cn(p,{name:$,fromWireType:(E)=>E,toWireType:(E,R)=>R,argPackAdvance:ai,readValueFromPointer:KM($,y),destructorFunction:null})},dd=(p,$)=>Object.defineProperty($,"name",{value:p}),$g=(p)=>{while(p.length){var $=p.pop(),y=p.pop();y($)}};function DM(p){for(var $=1;$<p.length;++$)if(p[$]!==null&&p[$].destructorFunction===void 0)return!0;return!1}function qM(p,$,y,E,R,P){var G=$.length;if(G<2)we("argTypes array size mismatch! Must at least get return value and 'this' types!");var T=$[1]!==null&&y!==null,U=DM($),Z=$[0].name!=="void",mt=G-2,Nt=Array(mt),ee=[],Le=[],ao=function(...pd){if(pd.length!==mt)we(`function ${p} called with ${pd.length} arguments, expected ${mt}`);Le.length=0;var gd;if(ee.length=T?2:1,ee[0]=R,T)gd=$[1].toWireType(Le,this),ee[1]=gd;for(var co=0;co<mt;++co)Nt[co]=$[co+2].toWireType(Le,pd[co]),ee.push(Nt[co]);var a2=E(...ee);function c2(u2){if(U)$g(Le);else for(var uo=T?1:2;uo<$.length;uo++){var l2=uo===1?gd:Nt[uo-2];if($[uo].destructorFunction!==null)$[uo].destructorFunction(l2)}if(Z)return $[0].fromWireType(u2)}return c2(a2)};return dd(p,ao)}var YM=(p,$,y)=>{if(p[$].overloadTable===void 0){var E=p[$];p[$]=function(...R){if(!p[$].overloadTable.hasOwnProperty(R.length))we(`Function '${y}' called with an invalid number of arguments (${R.length}) - expects one of (${p[$].overloadTable})!`);return p[$].overloadTable[R.length].apply(this,R)},p[$].overloadTable=[],p[$].overloadTable[E.argCount]=E}},JM=(p,$,y)=>{if(n.hasOwnProperty(p)){if(y===void 0||n[p].overloadTable!==void 0&&n[p].overloadTable[y]!==void 0)we(`Cannot register public name '${p}' twice`);if(YM(n,p,p),n.hasOwnProperty(y))we(`Cannot register multiple overloads of a function with the same number of arguments (${y})!`);n[p].overloadTable[y]=$}else if(n[p]=$,y!==void 0)n[p].numArguments=y},VM=(p,$)=>{var y=[];for(var E=0;E<p;E++)y.push(tt[$+E*4>>2]);return y},ZM=(p,$,y)=>{if(!n.hasOwnProperty(p))wg("Replacing nonexistent public symbol");if(n[p].overloadTable!==void 0&&y!==void 0)n[p].overloadTable[y]=$;else n[p]=$,n[p].argCount=y},QM=(p,$,y)=>{p=p.replace(/p/g,"i");var E=n["dynCall_"+p];return E($,...y)},fc=[],kg,yg=(p)=>{var $=fc[p];if(!$){if(p>=fc.length)fc.length=p+1;fc[p]=$=kg.get(p)}return $},XM=(p,$,y=[])=>{if(p.includes("j"))return QM(p,$,y);var E=yg($)(...y);return E},tx=(p,$)=>(...y)=>XM(p,$,y),ex=(p,$)=>{p=De(p);function y(){if(p.includes("j"))return tx(p,$);return yg($)}var E=y();if(typeof E!="function")we(`unknown function pointer with signature ${p}: ${$}`);return E},nx=(p,$)=>{var y=dd($,function(E){this.name=$,this.message=E;var R=Error(E).stack;if(R!==void 0)this.stack=this.toString()+`
3
+ `+R.replace(/^Error(:[^\n]*)?\n/,"")});return y.prototype=Object.create(p.prototype),y.prototype.constructor=y,y.prototype.toString=function(){if(this.message===void 0)return this.name;else return`${this.name}: ${this.message}`},y},vg,Sg=(p)=>{var $=xg(p),y=De($);return Fn($),y},rx=(p,$)=>{var y=[],E={};function R(P){if(E[P])return;if(si[P])return;if(dc[P]){dc[P].forEach(R);return}y.push(P),E[P]=!0}throw $.forEach(R),new vg(`${p}: `+y.map(Sg).join([", "]))},ix=(p)=>{p=p.trim();let $=p.indexOf("(");if($!==-1)return p.substr(0,$);else return p},ox=(p,$,y,E,R,P,G)=>{var T=VM($,y);p=De(p),p=ix(p),R=ex(E,R),JM(p,function(){rx(`Cannot call ${p} due to unbound types`,T)},$-1),FM([],T,(U)=>{var Z=[U[0],null].concat(U.slice(1));return ZM(p,qM(p,Z,null,R,P,G),$-1),[]})},sx=(p,$,y)=>{switch($){case 1:return y?(E)=>K[E]:(E)=>B[E];case 2:return y?(E)=>X[E>>1]:(E)=>z[E>>1];case 4:return y?(E)=>Mt[E>>2]:(E)=>tt[E>>2];default:throw TypeError(`invalid integer width (${$}): ${p}`)}},ax=(p,$,y,E,R)=>{if($=De($),R===-1)R=4294967295;var P=(mt)=>mt;if(E===0){var G=32-8*y;P=(mt)=>mt<<G>>>G}var T=$.includes("unsigned"),U=(mt,Nt)=>{},Z;if(T)Z=function(mt,Nt){return U(Nt,this.name),Nt>>>0};else Z=function(mt,Nt){return U(Nt,this.name),Nt};Cn(p,{name:$,fromWireType:P,toWireType:Z,argPackAdvance:ai,readValueFromPointer:sx($,y,E!==0),destructorFunction:null})},cx=(p,$,y)=>{var E=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],R=E[$];function P(G){var T=tt[G>>2],U=tt[G+4>>2];return new R(K.buffer,U,T)}y=De(y),Cn(p,{name:y,fromWireType:P,argPackAdvance:ai,readValueFromPointer:P},{ignoreDuplicateRegistrations:!0})},ux=(p,$,y,E)=>{if(!(E>0))return 0;var R=y,P=y+E-1;for(var G=0;G<p.length;++G){var T=p.charCodeAt(G);if(T>=55296&&T<=57343){var U=p.charCodeAt(++G);T=65536+((T&1023)<<10)|U&1023}if(T<=127){if(y>=P)break;$[y++]=T}else if(T<=2047){if(y+1>=P)break;$[y++]=192|T>>6,$[y++]=128|T&63}else if(T<=65535){if(y+2>=P)break;$[y++]=224|T>>12,$[y++]=128|T>>6&63,$[y++]=128|T&63}else{if(y+3>=P)break;$[y++]=240|T>>18,$[y++]=128|T>>12&63,$[y++]=128|T>>6&63,$[y++]=128|T&63}}return $[y]=0,y-R},lx=(p,$,y)=>ux(p,B,$,y),dx=(p)=>{var $=0;for(var y=0;y<p.length;++y){var E=p.charCodeAt(y);if(E<=127)$++;else if(E<=2047)$+=2;else if(E>=55296&&E<=57343)$+=4,++y;else $+=3}return $},Eg=(p,$,y)=>{var E=$+y,R="";while(!($>=E)){var P=p[$++];if(!P)return R;if(!(P&128)){R+=String.fromCharCode(P);continue}var G=p[$++]&63;if((P&224)==192){R+=String.fromCharCode((P&31)<<6|G);continue}var T=p[$++]&63;if((P&240)==224)P=(P&15)<<12|G<<6|T;else P=(P&7)<<18|G<<12|T<<6|p[$++]&63;if(P<65536)R+=String.fromCharCode(P);else{var U=P-65536;R+=String.fromCharCode(55296|U>>10,56320|U&1023)}}return R},fx=(p,$)=>p?Eg(B,p,$):"",hx=(p,$)=>{$=De($);var y=$==="std::string";Cn(p,{name:$,fromWireType(E){var R=tt[E>>2],P=E+4,G;if(y){var T=P;for(var U=0;U<=R;++U){var Z=P+U;if(U==R||B[Z]==0){var mt=Z-T,Nt=fx(T,mt);if(G===void 0)G=Nt;else G+=String.fromCharCode(0),G+=Nt;T=Z+1}}}else{var ee=Array(R);for(var U=0;U<R;++U)ee[U]=String.fromCharCode(B[P+U]);G=ee.join("")}return Fn(E),G},toWireType(E,R){if(R instanceof ArrayBuffer)R=new Uint8Array(R);var P,G=typeof R=="string";if(!(G||R instanceof Uint8Array||R instanceof Uint8ClampedArray||R instanceof Int8Array))we("Cannot pass non-string to std::string");if(y&&G)P=dx(R);else P=R.length;var T=md(4+P+1),U=T+4;if(tt[T>>2]=P,y&&G)lx(R,U,P+1);else if(G)for(var Z=0;Z<P;++Z){var mt=R.charCodeAt(Z);if(mt>255)Fn(U),we("String has UTF-16 code units that do not fit in 8 bits");B[U+Z]=mt}else for(var Z=0;Z<P;++Z)B[U+Z]=R[Z];if(E!==null)E.push(Fn,T);return T},argPackAdvance:ai,readValueFromPointer:ld,destructorFunction(E){Fn(E)}})},mx=(p,$)=>{var y="";for(var E=0;!(E>=$/2);++E){var R=X[p+E*2>>1];if(R==0)break;y+=String.fromCharCode(R)}return y},px=(p,$,y)=>{if(y??=2147483647,y<2)return 0;y-=2;var E=$,R=y<p.length*2?y/2:p.length;for(var P=0;P<R;++P){var G=p.charCodeAt(P);X[$>>1]=G,$+=2}return X[$>>1]=0,$-E},gx=(p)=>p.length*2,bx=(p,$)=>{var y=0,E="";while(!(y>=$/4)){var R=Mt[p+y*4>>2];if(R==0)break;if(++y,R>=65536){var P=R-65536;E+=String.fromCharCode(55296|P>>10,56320|P&1023)}else E+=String.fromCharCode(R)}return E},wx=(p,$,y)=>{if(y??=2147483647,y<4)return 0;var E=$,R=E+y-4;for(var P=0;P<p.length;++P){var G=p.charCodeAt(P);if(G>=55296&&G<=57343){var T=p.charCodeAt(++P);G=65536+((G&1023)<<10)|T&1023}if(Mt[$>>2]=G,$+=4,$+4>R)break}return Mt[$>>2]=0,$-E},$x=(p)=>{var $=0;for(var y=0;y<p.length;++y){var E=p.charCodeAt(y);if(E>=55296&&E<=57343)++y;$+=4}return $},kx=(p,$,y)=>{y=De(y);var E,R,P,G;if($===2)E=mx,R=px,G=gx,P=(T)=>z[T>>1];else if($===4)E=bx,R=wx,G=$x,P=(T)=>tt[T>>2];Cn(p,{name:y,fromWireType:(T)=>{var U=tt[T>>2],Z,mt=T+4;for(var Nt=0;Nt<=U;++Nt){var ee=T+4+Nt*$;if(Nt==U||P(ee)==0){var Le=ee-mt,ao=E(mt,Le);if(Z===void 0)Z=ao;else Z+=String.fromCharCode(0),Z+=ao;mt=ee+$}}return Fn(T),Z},toWireType:(T,U)=>{if(typeof U!="string")we(`Cannot pass non-string to C++ string type ${y}`);var Z=G(U),mt=md(4+Z+$);if(tt[mt>>2]=Z/$,R(U,mt+4,Z+$),T!==null)T.push(Fn,mt);return mt},argPackAdvance:ai,readValueFromPointer:ld,destructorFunction(T){Fn(T)}})},yx=(p,$)=>{$=De($),Cn(p,{isVoid:!0,name:$,argPackAdvance:0,fromWireType:()=>{return},toWireType:(y,E)=>{return}})},vx=(p,$,y)=>B.copyWithin(p,$,$+y),fd=[],Sx=(p,$,y,E)=>{return p=fd[p],$=ci.toValue($),p(null,$,y,E)},Ex={},Mx=(p)=>{var $=Ex[p];if($===void 0)return De(p);return $},Mg=()=>{if(typeof globalThis=="object")return globalThis;function p($){$.$$$embind_global$$$=$;var y=typeof $$$embind_global$$$=="object"&&$.$$$embind_global$$$==$;if(!y)delete $.$$$embind_global$$$;return y}if(typeof $$$embind_global$$$=="object")return $$$embind_global$$$;if(typeof global=="object"&&p(global))$$$embind_global$$$=global;else if(typeof self=="object"&&p(self))$$$embind_global$$$=self;if(typeof $$$embind_global$$$=="object")return $$$embind_global$$$;throw Error("unable to get global object.")},xx=(p)=>{if(p===0)return ci.toHandle(Mg());else return p=Mx(p),ci.toHandle(Mg()[p])},Ox=(p)=>{var $=fd.length;return fd.push(p),$},Ix=(p,$)=>{var y=si[p];if(y===void 0)we(`${$} has unknown type ${Sg(p)}`);return y},Rx=(p,$)=>{var y=Array(p);for(var E=0;E<p;++E)y[E]=Ix(tt[$+E*4>>2],"parameter "+E);return y},Px=Reflect.construct,Nx=(p,$,y)=>{var E=[],R=p.toWireType(E,y);if(E.length)tt[$>>2]=ci.toHandle(E);return R},Ax=(p,$,y)=>{var E=Rx(p,$),R=E.shift();p--;var P=Array(p),G=(U,Z,mt,Nt)=>{var ee=0;for(var Le=0;Le<p;++Le)P[Le]=E[Le].readValueFromPointer(Nt+ee),ee+=E[Le].argPackAdvance;var ao=y===1?Px(Z,P):Z.apply(U,P);return Nx(R,mt,ao)},T=`methodCaller<(${E.map((U)=>U.name).join(", ")}) => ${R.name}>`;return Ox(dd(T,G))},Tx=(p)=>{if(p>9)Ln[p+1]+=1},Hx=(p)=>{var $=ci.toValue(p);$g($),ud(p)},Cx=()=>{ug("")},Lx=()=>2147483648,Fx=(p)=>{var $=H.buffer,y=(p-$.byteLength+65535)/65536;try{return H.grow(y),hn(),1}catch(E){}},jx=(p)=>{var $=B.length;p>>>=0;var y=Lx();if(p>y)return!1;var E=(U,Z)=>U+(Z-U%Z)%Z;for(var R=1;R<=4;R*=2){var P=$*(1+0.2/R);P=Math.min(P,p+100663296);var G=Math.min(y,E(Math.max(p,P),65536)),T=Fx(G);if(T)return!0}return!1},hd={},_x=()=>d||"./this.program",Os=()=>{if(!Os.strings){var p=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",$={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:p,_:_x()};for(var y in hd)if(hd[y]===void 0)delete $[y];else $[y]=hd[y];var E=[];for(var y in $)E.push(`${y}=${$[y]}`);Os.strings=E}return Os.strings},Bx=(p,$)=>{for(var y=0;y<p.length;++y)K[$++]=p.charCodeAt(y);K[$]=0},Gx=(p,$)=>{var y=0;return Os().forEach((E,R)=>{var P=$+y;tt[p+R*4>>2]=P,Bx(E,P),y+=E.length+1}),0},Ux=(p,$)=>{var y=Os();tt[p>>2]=y.length;var E=0;return y.forEach((R)=>E+=R.length+1),tt[$>>2]=E,0},Wx=0,Kx=()=>AM||Wx>0,zx=(p)=>{if(L=p,!Kx())n.onExit?.(p),N=!0;f(p,new NM(p))},Dx=(p,$)=>{L=p,zx(p)},qx=Dx,Yx=(p)=>52,Jx=(p,$)=>$+2097152>>>0<4194305-!!p?(p>>>0)+$*4294967296:NaN;function Vx(p,$,y,E,R){var P=Jx($,y);return 70}var Zx=[null,[],[]],Qx=(p,$)=>{var y=Zx[p];if($===0||$===10)(p===1?M:I)(Eg(y,0)),y.length=0;else y.push($)},Xx=(p,$,y,E)=>{var R=0;for(var P=0;P<y;P++){var G=tt[$>>2],T=tt[$+4>>2];$+=8;for(var U=0;U<T;U++)Qx(p,B[G+U]);R+=T}return tt[E>>2]=R,0};LM(),gg=n.BindingError=class extends Error{constructor($){super($);this.name="BindingError"}},bg=n.InternalError=class extends Error{constructor($){super($);this.name="InternalError"}},GM(),vg=n.UnboundTypeError=nx(Error,"UnboundTypeError");var t2={o:HM,q:CM,m:_M,l:WM,j:zM,f:ox,b:ax,a:cx,e:hx,c:kx,n:yx,v:vx,i:Sx,d:ud,k:xx,h:Ax,y:Tx,g:Hx,r:Cx,s:jx,t:Gx,u:Ux,z:qx,w:Yx,p:Vx,x:Xx},te=PM(),e2=()=>(e2=te.B)(),xg=(p)=>(xg=te.C)(p),md=(p)=>(md=te.D)(p),Fn=(p)=>(Fn=te.E)(p),n2=(p)=>(n2=te._emscripten_stack_restore)(p),r2=(p)=>(r2=te._emscripten_stack_alloc)(p),i2=()=>(i2=te.emscripten_stack_get_current)(),o2=(p)=>(o2=te.__cxa_increment_exception_refcount)(p),Og=(p)=>(Og=te.G)(p),s2=n.dynCall_jiji=(p,$,y,E,R)=>(s2=n.dynCall_jiji=te.H)(p,$,y,E,R),hc;xs=function p(){if(!hc)Ig();if(!hc)xs=p};function Ig(){if(ii>0)return;if(id(),ii>0)return;function p(){if(hc)return;if(hc=!0,n.calledRun=!0,N)return;if(od(),r(n),n.onRuntimeInitialized)n.onRuntimeInitialized();yM()}if(n.setStatus)n.setStatus("Running..."),setTimeout(function(){setTimeout(function(){n.setStatus("")},1),p()},1);else p()}if(n.preInit){if(typeof n.preInit=="function")n.preInit=[n.preInit];while(n.preInit.length>0)n.preInit.pop()()}return Ig(),o}})(),Kb=XO;function Bd(t){if(t[0]!==255||t[1]!==216)return null;let e=2;while(e+9<t.length){if(t[e]!==255){e++;continue}let n=t[e+1];if(n===255){e++;continue}let r=t[e+2]<<8|t[e+3];if(n>=192&&n<=207&&n!==196&&n!==200&&n!==204)return{height:t[e+5]<<8|t[e+6],width:t[e+7]<<8|t[e+8]};e+=2+r}return null}var _d;function eI(){if(_d)return _d;let t=new WebAssembly.Module(tI(Buffer.from("7L0NnFzHVSd6q+5H3+7bPdMjjeyRZmTf7ohFITZWgpFN4mBdEX3Y8leI15jfy+6a3UC8Mwp4ZEWYRdaMY9kICESA2TWsCXrBb+2wNugtejwvmBcFDBFgFgXMRkkMEYtJzBLA720A78PY+/+fU3X73u4eSVYMC1mUePre+rqnTp06derUqXOCb7rzPSYIAvN/m9nbzFKA/8zSbeHSEn/sEhLiJf4Lbov0x0pOY2nJJWu2q+NK4S1gzgH8C25LfFH3gNwIWUgIlw4smQOuzn40vZ/to0rEmihnmIxsNsM6BwS+A/wWHkMpZH/MrDPfZL4paOLvPw8i/P0X8vwu9OqbzDcHIf5+S9DA33dLyu2Bxd9/GUzh77yUXAgM/u6W3PcEMf5+q9T6Nsm9I0jxd1Fa2BNk+HunlN8bJPj7Xvm7T0p+u6TfFbTw9zuktX8VBOFvm48ba2y7ZdqTQTu0q1bbaHI6MGEzNUFs19h2aLKgzUEwYXBB0IyTLJu8cGZtkjRNapoma6+L4ybygixLYvkXNKLqvzhuxPwvCPE/aSfBoBo8mFZrYiJIU8lp2ixFUgflo47FP9O1BhUT/otG/jUaaDF2HwRCEpOgcfwXon7D3GEewv/ihjHvs8vLNunYJVMc/1yU4SfIGhtSU9jAbA3ebL4uOGbM24KLzbagb7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2Za46vfRZkv8+xNuG94Nw/fr9LriUfr8XblC/PwCX1O+PwJX0+9NwZf3+LFxWv78EN6Tf34TL6fcAiOSwfo/jfUy/z8f7Af3ehvcB/b60Xfqa3le1V9cT76XsZN3C9dxEEy7q2Vc+p7LHrH/3I+wjeF4L98eKYDo7c4Xd4A9k+5zi3wWY9y8S+GMa/roK/GLZgNURdJ5Pt0va9KO8qa/+xNVX18P9KdwNcDdyOuc4BVea0Ziv8yy3S/xPVsX/FNxNcJ/W8Jfr/KisN+N5CxxGgroV7jNwf6YS1/xYmZHxJbIACoKO4tt3uUrcj2f0CvhdCXfXEhx7owAsIp/5sYfQHnoG3lf9Bw==","base64"))),e={noInitialRun:!0,print:()=>{return},printErr:()=>{return},instantiateWasm:(n,r)=>{let i=new WebAssembly.Instance(t,n);return r(i),i.exports}};if(Kb(e),typeof e.decode!=="function")throw Error("the JPEG decoder did not start");return _d=e,e}function zb(t,e){let n=Bd(t);if(n&&n.width*n.height>e)throw Error(`${n.width}×${n.height} is over ${e/1e6} megapixels`);let r=null;try{r=eI().decode(t,!0)}catch{r=null}if(!r)throw Error("not a JPEG image this decoder can read");return{width:r.width,height:r.height,data:new Uint8Array(r.data.buffer,r.data.byteOffset,r.data.length)}}var $o=[137,80,78,71,13,10,26,10],Yb=13,Jb=3;function fi(t){return t.length>=$o.length&&$o.every((e,n)=>t[n]===e)}var Vb={0:1,2:3,4:2,6:4};function oI(t){if(t.length<33||!fi(t))return;let e=Buffer.from(t.buffer,t.byteOffset,t.byteLength),n=e.readUInt32BE(16),r=e.readUInt32BE(20),i=e[25];if(e[24]!==8||e[28]!==0||Vb[i]===void 0)return;let o=[];for(let s=8;s+12<=e.length;){let a=e.readUInt32BE(s),c=e.toString("latin1",s+4,s+8);if(c==="IDAT")o.push(e.subarray(s+8,s+8+a));else if(c==="tRNS"||c==="IEND"){if(c==="tRNS"&&i!==4&&i!==6)return;break}s+=12+a}return o.length>0?{width:n,height:r,type:i,idat:o}:void 0}function sI(t,e,n,r){let i=new Uint8Array(e);for(let o=0;o<n;o++){let s=o*(e+1),a=t[s],c=s+1,u=o>0?t:i,l=o>0?c-e-1:0;if(a===1)for(let d=r;d<e;d++)t[c+d]=t[c+d]+t[c+d-r];else if(a===2)for(let d=0;d<e;d++)t[c+d]=t[c+d]+u[l+d];else if(a===3){for(let d=0;d<r;d++)t[c+d]=t[c+d]+(u[l+d]>>1);for(let d=r;d<e;d++)t[c+d]=t[c+d]+(t[c+d-r]+u[l+d]>>1)}else if(a===4){for(let d=0;d<r;d++)t[c+d]=t[c+d]+u[l+d];for(let d=r;d<e;d++){let f=t[c+d-r],h=u[l+d],m=u[l+d-r],g=Math.abs(h-m),b=Math.abs(f-m),w=Math.abs(f+h-2*m);t[c+d]=t[c+d]+(g<=b&&g<=w?f:b<=w?h:m)}}else if(a!==0)throw Error(`bad PNG filter ${a}`)}}function aI(t){let{width:e,height:n,type:r}=t,i=Vb[r],o=e*i,s=iI(Buffer.concat(t.idat),{chunkSize:Math.min(268435456,Math.max(65536,n*(o+1)))});if(s.length<n*(o+1))throw Error("truncated PNG");sI(s,o,n,i);let a=new Uint8Array(e*n*4);for(let c=0;c<n;c++){let u=c*(o+1)+1,l=c*e*4;if(r===6)a.set(s.subarray(u,u+o),l);else if(r===2)for(let d=0,f=u,h=l;d<e;d++,f+=3,h+=4)a[h]=s[f],a[h+1]=s[f+1],a[h+2]=s[f+2],a[h+3]=255;else if(r===0)for(let d=0,f=l;d<e;d++,f+=4){let h=s[u+d];a[f]=h,a[f+1]=h,a[f+2]=h,a[f+3]=255}else for(let d=0,f=u,h=l;d<e;d++,f+=2,h+=4){let m=s[f];a[h]=m,a[h+1]=m,a[h+2]=m,a[h+3]=s[f+1]}}return{width:e,height:n,data:a}}function jt(t){let e=oI(t);if(e)return aI(e);let n=qb.PNG.sync.read(Buffer.from(t));return{width:n.width,height:n.height,data:new Uint8Array(n.data)}}function $r(t,e){if(fi(t)){let n=$n(t);if(n&&n.width*n.height>e)throw Error(`${n.width}×${n.height} is over ${e/1e6} megapixels`);return jt(t)}if(t[0]===255&&t[1]===216)return zb(t,e);throw Error("not a PNG or JPEG image")}function Zb(t,e){let{width:n,height:r,at:i}=e,o=Math.max(0,i.x),s=Math.max(0,i.y),a=Math.min(n,i.x+i.w),c=Math.min(r,i.y+i.h);if(a<=o||c<=s)return;let u={x:o,y:s,w:a-o,h:c-s};if(i.w===t.width&&i.h===t.height)return{part:t,box:u,dx:o-i.x,dy:s-i.y};let l={x:(o-i.x)*t.width/i.w,y:(s-i.y)*t.height/i.h,w:u.w*t.width/i.w,h:u.h*t.height/i.h};return{part:As(t,l,u.w,u.h),box:u,dx:0,dy:0}}function Qb(t,e){let n=new Uint8Array(e.width*e.height*4),r=Zb(t,e);if(r){let{part:i,box:o,dx:s,dy:a}=r;for(let c=0;c<o.h;c++){let u=((c+a)*i.width+s)*4;n.set(i.data.subarray(u,u+o.w*4),((o.y+c)*e.width+o.x)*4)}}return{width:e.width,height:e.height,data:n}}function kr(t,e,n,r={width:t.width,height:t.height,at:{x:0,y:0,w:t.width,h:t.height}}){let i=et(e),{width:o,height:s}=r,a=new Uint8Array(o*s*3);for(let h=0;h<o*3;h+=3)a.set(i,h);for(let h=1;h<s;h++)a.copyWithin(h*o*3,0,o*3);let c=Zb(t,r);if(!c)return{width:o,height:s,data:a};let{part:u,box:l,dx:d,dy:f}=c;for(let h=0;h<l.h;h++)for(let m=0;m<l.w;m++){let g=((h+f)*u.width+m+d)*4,b=((l.y+h)*o+l.x+m)*3,w=u.data[g+3]/255*n;for(let k=0;k<3;k++)a[b+k]=Math.round(i[k]*(1-w)+u.data[g+k]*w)}return{width:o,height:s,data:a}}function Db(t,e){for(let n=0;n+e.length<=t.length;n++){let r=!0;for(let i=0;i<e.length&&r;i++)r=t[n+i]===e.charCodeAt(i);if(r)return n}return-1}function $n(t){if(t.length<33||!fi(t))return null;let e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=e.getUint32(16),r=e.getUint32(20);if(t[25]===4||t[25]===6)return{width:n,height:r,alpha:!0};let i=Db(t,"IDAT");return{width:n,height:r,alpha:Db(i===-1?t:t.subarray(0,i),"tRNS")!==-1}}function Xb(t,e=Yb){let{width:n,height:r,data:i}=t,o=(l)=>{for(let d=l*n*4+3,f=d+n*4;d<f;d+=4)if(i[d]>=e)return!0;return!1},s=0;while(s<r&&!o(s))s++;if(s===r)return null;let a=r-1;while(!o(a))a--;let c=n,u=-1;for(let l=s;l<=a;l++){let d=l*n*4+3;for(let f=0;f<c;f++)if(i[d+f*4]>=e){c=f;break}for(let f=n-1;f>u;f--)if(i[d+f*4]>=e){u=f;break}}return{x:c,y:s,w:u-c+1,h:a-s+1}}function Wn(t,e={x:0,y:0,w:t.width,h:t.height}){let n=0;for(let r=e.y;r<e.y+e.h;r++)for(let i=e.x;i<e.x+e.w;i++)if((t.data[(r*t.width+i)*4+3]??0)<Yb)n++;return Math.round(n*100/(e.w*e.h))}function tw(t,e,n){let r=Math.min(e/t.width,n/t.height),i=Math.max(1,Math.round(t.width*r)),o=Math.max(1,Math.round(t.height*r)),s=As(t,{x:0,y:0,w:t.width,h:t.height},i,o),a=new Uint8Array(e*n*4),c=Math.floor((e-i)/2),u=Math.floor((n-o)/2);for(let l=0;l<o;l++)a.set(s.data.subarray(l*i*4,(l+1)*i*4),((u+l)*e+c)*4);return{width:e,height:n,data:a}}function cI(t){let e=Math.abs(t);if(e<1)return(7*e*e*e-12*e*e+5.333333333333333)/6;if(e<2)return(-2.3333333333333335*e*e*e+12*e*e-20*e+10.666666666666666)/6;return 0}function Gd(t,e,n,r){if(n===r&&Number.isInteger(e)&&e>=0&&e+r<=t)return{first:Int32Array.from({length:r},(l,d)=>e+d),size:1,weights:new Float32Array(r).fill(1)};let i=n/r,o=Math.max(1,i),s=2*o,a=Math.min(t,Math.ceil(2*s)+2),c=new Int32Array(r),u=new Float32Array(r*a);for(let l=0;l<r;l++){let d=e+(l+0.5)*i,f=Math.floor(d-s-0.5),h=Math.max(0,Math.min(t-a,f));c[l]=h;let m=0;for(let g=f;g<=Math.ceil(d+s-0.5);g++){let b=cI((g+0.5-d)/o),w=l*a+Math.min(t-1,Math.max(0,g))-h;u[w]=(u[w]??0)+b,m+=b}for(let g=l*a;g<(l+1)*a;g++)u[g]=(u[g]??0)/m}return{first:c,size:a,weights:u}}function ew(t,e,n,r,i,o,s){let a=Gd(t,e.y,e.h,r),c=n*i,u=a.size+1,l=Array.from({length:u},()=>new Float32Array(c)),d=new Int32Array(u).fill(-1),f=new Float32Array(c),h=[],m=[];for(let g=0;g<r;g++){h.length=0,m.length=0;let b=a.first[g];for(let k=0;k<a.size;k++){let v=a.weights[g*a.size+k];if(v===0)continue;let S=b+k,M=S%u,I=l[M];if(d[M]!==S)o(S,I),d[M]=S;h.push(I),m.push(v)}let w=0;while(w<h.length){let k=h[w],v=m[w];if(h.length-w>=4){let S=h[w+1],M=h[w+2],I=h[w+3],O=m[w+1],H=m[w+2],N=m[w+3];if(w===0)for(let L=0;L<c;L++)f[L]=k[L]*v+S[L]*O+M[L]*H+I[L]*N;else for(let L=0;L<c;L++)f[L]=f[L]+(k[L]*v+S[L]*O+M[L]*H+I[L]*N);w+=4}else{if(w===0)for(let S=0;S<c;S++)f[S]=k[S]*v;else for(let S=0;S<c;S++)f[S]=f[S]+k[S]*v;w+=1}}if(h.length===0)f.fill(0);s(g,f)}}function nw(t,e,n,r,i){let o=0,s=n;while(o<s){let c=o+s>>1;if(t[c]+e-1<r)o=c+1;else s=c}let a=o;s=n;while(o<s){let c=o+s>>1;if(t[c]<=i)o=c+1;else s=c}return[a,o]}function As(t,e,n,r){let i=Gd(t.width,e.x,e.w,n),o=t.data,s=t.width,a=new Float32Array(s*4),c=new Uint8Array(n*r*4);return ew(t.height,e,n,r,4,(u,l)=>{let d=u*s*4,f=s,h=-1;for(let b=0,w=0;b<s*4;b+=4,w++){let k=o[d+b+3];if(k===0){a[b]=0,a[b+1]=0,a[b+2]=0,a[b+3]=0;continue}if(w<f)f=w;h=w,a[b]=o[d+b]*k,a[b+1]=o[d+b+1]*k,a[b+2]=o[d+b+2]*k,a[b+3]=k}if(l.fill(0),h<0)return;let[m,g]=nw(i.first,i.size,n,f,h);for(let b=m;b<g;b++){let w=i.first[b]*4,k=b*i.size,v=0,S=0,M=0,I=0;for(let O=0;O<i.size;O++){let H=i.weights[k+O],N=w+O*4;v+=a[N]*H,S+=a[N+1]*H,M+=a[N+2]*H,I+=a[N+3]*H}l[b*4]=v,l[b*4+1]=S,l[b*4+2]=M,l[b*4+3]=I}},(u,l)=>{let d=u*n*4;for(let f=0;f<n;f++){let h=f*4,m=l[h+3];if(m<=0)continue;let g=l[h]/m;c[d+h]=(g<0?0:g>255?255:g)+0.5,g=l[h+1]/m,c[d+h+1]=(g<0?0:g>255?255:g)+0.5,g=l[h+2]/m,c[d+h+2]=(g<0?0:g>255?255:g)+0.5,c[d+h+3]=(m>255?255:m)+0.5}}),{width:n,height:r,data:c}}function rw(t,e,n,r){let i=Gd(t.width,e.x,e.w,n),o=t.data,s=t.width,a=new Float32Array(n*r);return ew(t.height,e,n,r,1,(c,u)=>{let l=c*s,d=s,f=-1;for(let g=0;g<s;g++)if(o[l+g]!==0){if(g<d)d=g;f=g}if(u.fill(0),f<0)return;let[h,m]=nw(i.first,i.size,n,d,f);for(let g=h;g<m;g++){let b=l+i.first[g],w=g*i.size,k=0;for(let v=0;v<i.size;v++)k+=o[b+v]*i.weights[w+v];u[g]=k}},(c,u)=>{a.set(u,c*n)}),{width:n,height:r,data:a}}function Ts(t,e){if(e<=0)return t;let n=Math.max(1,Math.ceil(e*3)),r=Array.from({length:2*n+1},(l,d)=>Math.exp(-((d-n)**2)/(2*e*e))),i=r.reduce((l,d)=>l+d,0),{width:o,height:s,data:a}=t,c=new Float32Array(o*s);for(let l=0;l<s;l++){let d=l*o;for(let f=0;f<o;f++){let h=0;for(let m=-n;m<=n;m++)h+=(a[d+Math.min(o-1,Math.max(0,f+m))]??0)*(r[m+n]??0);c[d+f]=h/i}}let u=new Float32Array(o*s);for(let l=0;l<s;l++){let d=l*o;for(let f=-n;f<=n;f++){let h=(r[f+n]??0)/i,m=Math.min(s-1,Math.max(0,l+f))*o;for(let g=0;g<o;g++)u[d+g]=(u[d+g]??0)+(c[m+g]??0)*h}}return{width:o,height:s,data:u}}function Hs(t){let e=new Uint8Array(t.data.length);for(let n=0;n<e.length;n++){let r=t.data[n];e[n]=(r<0?0:r>255?255:r)+0.5}return{width:t.width,height:t.height,data:e}}function hi(t){let e=new Uint8Array(t.width*t.height);for(let n=0;n<e.length;n++)e[n]=t.data[n*4+3]??0;return{width:t.width,height:t.height,data:e}}var uI=Array.from({length:256},(t,e)=>{let n=e;for(let r=0;r<8;r++)n=n&1?3988292384^n>>>1:n>>>1;return n>>>0});function lI(t){let e=4294967295;for(let n of t)e=(uI[(e^n)&255]??0)^e>>>8;return(e^4294967295)>>>0}function wr(t,e){let n=Buffer.alloc(12+e.length);return n.writeUInt32BE(e.length,0),n.write(t,4,"latin1"),n.set(e,8),n.writeUInt32BE(lI(n.subarray(4,8+e.length)),8+e.length),n}function iw(t,e,n){let r=new Uint8Array(n*(e+1));r.set(t.subarray(0,e),1);for(let i=1;i<n;i++){let o=i*(e+1),s=i*e,a=s-e;r[o]=2;for(let c=0;c<e;c++)r[o+1+c]=t[s+c]-t[a+c]}return r}function ow(t){return rI(t,{level:1,strategy:nI.Z_RLE})}function sw(t,e,n){let r=Buffer.alloc(13);return r.writeUInt32BE(t.width,0),r.writeUInt32BE(t.height,4),r[8]=8,r[9]=e,Buffer.concat([Buffer.from($o),wr("IHDR",r),...n,wr("IDAT",ow(iw(t.data,t.width,t.height))),wr("IEND",new Uint8Array)])}function aw(t){let[e,n,r]=et(t),i=new Uint8Array(768);for(let o=0;o<256;o++)i.set([e,n,r],o*3);return wr("PLTE",i)}function cw(t,e,n,r,i){let o=Buffer.alloc(13);return o.writeUInt32BE(t,0),o.writeUInt32BE(e,4),o[8]=8,o[9]=n,Buffer.concat([Buffer.from($o),wr("IHDR",o),wr("IDAT",ow(iw(i,t*r,e))),wr("IEND",new Uint8Array)])}function yr(t){return cw(t.width,t.height,2,3,t.data)}function je(t){return cw(t.width,t.height,6,4,t.data)}function mi(t,e){return sw(t,Jb,[aw(e),wr("tRNS",Uint8Array.from({length:256},(n,r)=>r))])}function Ud(t){return sw(t,0,[])}function $c(t,e){if(!fi(t)||t[25]!==Jb)return;let n=Buffer.from(t.buffer,t.byteOffset,t.byteLength),r=[Buffer.from($o)],i=$o.length;while(i+8<=n.length){let o=i+12+n.readUInt32BE(i);r.push(n.toString("latin1",i+4,i+8)==="PLTE"?aw(e):n.subarray(i,o)),i=o}return Buffer.concat(r)}var vr=100,Se=25000000,bI=536870912,ko=["safe","questionable","explicit"],pi=["nudity","underwear"],Dd=["comic","monochrome","sketch","chibi"],bw=["off","5","10","25","50","100"],ww=["off","720","1080","1440","1800","2560"],$w={nudity:new Set(["nude","naked","topless","bottomless","nipples","naked_towel","undressing"]),underwear:new Set(["underwear","panties","pantsu","bra","lingerie","pantyshot"])},wI={comic:new Set(["comic","4koma"]),monochrome:new Set(["monochrome","greyscale"]),sketch:new Set(["sketch","lineart","line_art"]),chibi:new Set(["chibi"])},$I=/^(?:rating|score|width|height|filetype|dimension):/,Cs={safe:"s",questionable:"q",explicit:"e"},kw=8191,kI=20000,yI=5000,uw=3000,lw=8,vI=8,SI=8000,EI=3000,yw=60000,dw=3,MI=3,xI="https://static.zerochan.net",vw="https://s1.zerochan.net",qd=`ttheme/${At.version} (+${At.homepage})`,OI=["orig","tile","thumb","cut"],Sw=new Map,II=zI(process.env.TTHEME_FIND_HOSTS),RI=KI(process.env.TTHEME_FIND_CUTOUTS);mI(EI);var PI=["artist","character","copyright"];function fw(t){try{return dI(t)}catch{return[]}}function yo(t){return t.startsWith("//")?`https:${t}`:t}function Er(t){return(/\.([a-z0-9]+)(?:\?.*)?$/i.exec(t)?.[1]??"").toLowerCase()}function Fs(t){let e=t.trim();if(!e)return[];let n=JSON.parse(e);if(Array.isArray(n))return n;let r=n.posts;return Array.isArray(r)?r:[]}function NI(t){let e=t.trim(),r=(e?JSON.parse(e):{}).tags??{};return new Map(Object.entries(r).map(([i,o])=>[i,String(o)]))}function Kd(t,e,n){let r=yo(String(t??""));return{file:r,width:Number(e)||0,height:Number(n)||0,ext:Er(r)}}function Kn(t){return String(t??"").split(/\s+/).filter(Boolean)}function zd(t){let e=typeof t==="number"?new Date(t*1000):typeof t==="string"?new Date(t):void 0;return e&&!Number.isNaN(e.getTime())?e.toISOString().slice(0,10):void 0}function Ew(t,e){let n=yo(String(e.preview??""));if(!e.file||!n||!Number(t.id))return[];let r=Number(t.width??t.image_width)||0,i=Number(t.height??t.image_height)||0;return[{id:Number(t.id),width:r,height:i,file:e.file,preview:n,ext:e.ext,owner:String(e.owner??""),score:Number(t.score)||0,rating:String(t.rating??""),md5:String(e.md5??""),source:String(t.source??""),tags:Kn(e.tags),named:e.named,...zd(t.created_at)?{posted:zd(t.created_at)}:{},solo:e.solo,family:Number(t.parent_id)||(t.has_children===!0?Number(t.id):0),smaller:e.versions.filter((o)=>o.file&&o.width>0&&o.height>0&&o.width*o.height<r*i)}]}function AI(t){let e=NI(t);return Fs(t).flatMap((n)=>{let r=yo(String(n.file_url??"")),i=String(n.tags??""),o=(s)=>Kn(i).filter((a)=>e.get(a)===s);return Ew(n,{preview:n.preview_url,file:r,ext:String(n.file_ext||Er(r)).toLowerCase(),owner:n.author,md5:n.md5,tags:i,named:{artist:o("artist"),character:o("character"),copyright:o("copyright")},solo:void 0,versions:[Kd(n.jpeg_url,n.jpeg_width,n.jpeg_height),Kd(n.sample_url,n.sample_width,n.sample_height)]})})}function TI(t){return Fs(t).flatMap((e)=>{let n=yo(String(e.file_url??"")),r=String(e.tag_string??""),i=e.media_asset??{};return Ew(e,{preview:i.variants?.find((o)=>o.type==="360x360")?.url??e.preview_file_url,file:n,ext:String(e.file_ext||Er(n)).toLowerCase(),owner:"",md5:e.md5,tags:r,named:{artist:Kn(e.tag_string_artist),character:Kn(e.tag_string_character),copyright:Kn(e.tag_string_copyright)},solo:r.split(/\s+/).includes("solo"),versions:(i.variants??[]).map((o)=>Kd(o.url,o.width,o.height)).filter((o)=>o.ext==="jpg"||o.ext==="png").sort((o,s)=>s.width*s.height-o.width*o.height)})})}function Mw(t){return t.toLowerCase().replace(/\s+/g,"_")}function HI(t){return(Array.isArray(t)?t:[]).map((e)=>Mw(String(e)))}function CI(t){return String(t??"").replace(/[^0-9a-z]+/gi,".").replace(/^\.+|\.+$/g,"")||"zerochan"}function LI(t){let e=t.trim(),n=e?JSON.parse(e):{};return(Array.isArray(n.items)?n.items:n.id?[n]:[]).flatMap((i)=>{let o=Number(i.id);if(!o)return[];let s=HI(i.tags),a=yo(String(i.full??""));return[{id:o,width:Number(i.width)||0,height:Number(i.height)||0,file:a,ext:Er(a),preview:`${vw}/${CI(i.tag??i.primary)}.600.${o}.jpg`,owner:"",score:0,rating:s.some((c)=>$w.nudity.has(c))?"q":"g",md5:String(i.md5??i.hash??""),source:String(i.source??""),tags:s,named:{artist:[],character:[],copyright:[]},solo:s.includes("solo"),family:0,smaller:[]}]})}var FI={mangaka:"artist",studio:"artist",character:"character",series:"copyright",game:"copyright"};function hw(t){return t.replace(/&(?:#(\d+)|amp|quot|apos|lt|gt);/g,(e,n)=>n?String.fromCharCode(Number(n)):{"&amp;":"&","&quot;":'"',"&apos;":"'","&lt;":"<","&gt;":">"}[e]??e)}function jI(t){let e={artist:[],character:[],copyright:[]};for(let[,r,i]of t.matchAll(/<li class="([a-z]+)[^"]*"[^>]*\bdata-tag="([^"]*)"/g)){let o=FI[r],s=Mw(hw(i));if(o&&!e[o].includes(s))e[o].push(s)}let n=zd(/"datePublished":\s*"([^"]+)"/.exec(t)?.[1]);return{named:e,source:"",owner:hw(/\buploader = \{\s*name: '([^']*)'/.exec(t)?.[1]??""),...n?{posted:n}:{}}}function _I(t){return Number(/Zerochan has ([\d,]+) /.exec(t)?.[1]?.replace(/,/g,"")??0)}function BI(t){return Fs(t).flatMap((e)=>{let n=String(e.value??"");return n?[{value:n,count:Number(e.post_count)||0}]:[]})}function GI(t){return Fs(t).flatMap((e)=>{let n=String(e.name??"");return n?[{value:n,count:Number(e.count)||0}]:[]})}function UI(t){return Number(/count="(\d+)"/.exec(t)?.[1]??0)}function WI(t){let n=(t.trim()?JSON.parse(t):{}).counts?.posts;return n===null?Number.NaN:Number(n)||0}function KI(t){let e=new Map;for(let n of(t??"").split(/\s+/).filter(Boolean)){let r=n.indexOf("=");if(r>0)e.set(n.slice(0,r),n.slice(r+1).split(",").filter(Boolean))}return e}function zI(t){let e=new Map;for(let n of(t??"").split(/[\s,]+/).filter(Boolean)){let r=n.indexOf("="),i=n.slice(0,r);try{let o=new URL(n.slice(r+1));if(i&&o.protocol==="https:")e.set(i,o.origin)}catch{}}return e}function kc(t,e,n,r){let i=(t??"").split(/\s+/);if(r!==void 0&&i.includes(r))return[];let o=e.filter((s)=>i.includes(s));return o.length>0?o:[...n]}function gi(t){return kc(t,ko,["safe"])}function vo(t){return kc(t,pi,pi,"none")}function yc(t){return kc(t,Dd,[],"none")}function js(t){let e=J.map((n)=>n.name);return kc(t,e,e)}function Yd(t,e,n){return{score:Number(t)||0,size:Number(e)||0,png:n==="on"}}function _s(t){return[...new Set((t??"").toLowerCase().split(/[\s,]+/).map((e)=>e.replace(/^-+/,"")).filter(Boolean))]}function Jd(t,e,n){return{safe:new Set(t),questionable:new Set(e),explicit:new Set(n)}}function Vd(t){let e=II.get(t.key),n=RI.get(t.key);return{...t,origin:e??t.origin,moved:e!==void 0&&e!==t.origin,cutouts:n??t.cutouts,vouched:t.vouched&&n===void 0}}function xw(t){return t.length<2?t.join(""):t.map((e)=>`~${e}`).join(" ")}function Ow(t){return t>0?[`width:>=${t}`,`height:>=${t}`]:[]}function mw(t){let e=Vd(t),n=(r)=>new URLSearchParams({api_version:"2",include_tags:"1",...r});return{...e,scored:!0,narrow:({score:r,size:i})=>[...r>0?[`score:>=${r}`]:[],...Ow(i)],cutouts:xw(e.cutouts),ratings:Jd([Cs.safe],[Cs.questionable],[Cs.explicit]),rate:(r)=>{let[i]=r;if(r.length===1&&i)return`rating:${Cs[i]}`;let o=ko.filter((a)=>!r.includes(a)),[s]=o;return o.length===1&&s?`-rating:${Cs[s]}`:""},best:"order:score",tagBudget:Number.POSITIVE_INFINITY,ors:!0,postsUrl:(r,i)=>`${e.origin}/post.json?${n({limit:String(vr),page:String(i+1),tags:r})}`,countUrl:(r)=>`${e.origin}/post.xml?${new URLSearchParams({limit:"1",tags:r})}`,postUrl:(r)=>`${e.origin}/post.json?${n({tags:`id:${r}`})}`,pageUrl:(r)=>`${e.origin}/post/show/${r}`,parse:AI,count:UI,uploadedBy:(r)=>`user:${r}`}}function DI(t){let e=Vd(t),n=Jd(["g"],["s","q"],["e"]);return{...e,scored:!0,narrow:({score:r,size:i,png:o})=>[...r>0?[`score:>=${r}`]:[],...Ow(i),...o?["filetype:png"]:[]],cutouts:xw(e.cutouts),ratings:n,rate:(r)=>r.length===ko.length?"":`rating:${r.flatMap((i)=>[...n[i]]).join(",")}`,best:"order:score",tagBudget:2,ors:!0,postsUrl:(r,i)=>`${e.origin}/posts.json?${new URLSearchParams({limit:String(vr),page:String(i+1),tags:r})}`,countUrl:(r)=>`${e.origin}/counts/posts.json?${new URLSearchParams({tags:r})}`,postUrl:(r)=>`${e.origin}/posts.json?${new URLSearchParams({limit:"1",tags:`id:${r}`})}`,pageUrl:(r)=>`${e.origin}/posts/${r}`,parse:TI,count:WI,uploadedBy:(r)=>`user:${r}`}}function Wd(t){return t.split(/\s+/).filter((e)=>e&&!/^(?:order|dimension):/.test(e)).map((e)=>e.split("_").map(encodeURIComponent).join("+")).join(",")}function pw(t){let e=t.split(/\s+/),n=e.find((r)=>r.startsWith("dimension:"))?.slice(10);return{s:e.includes("order:fav")?"fav":"id",...n?{d:n}:{}}}function qI(t){let e=Vd(t);return{...e,scored:!1,narrow:({size:n})=>n>=1800?["dimension:huge"]:n>0?["dimension:large"]:[],cutouts:e.cutouts[0]??"",ratings:Jd(["g"],["q"],["e"]),rate:()=>"",best:"order:fav",tagBudget:3,ors:!1,missing:404,postsUrl:(n,r)=>`${e.origin}/${Wd(n)}?${new URLSearchParams({json:"",l:String(vr),p:String(r+1),...pw(n)})}`,countUrl:(n)=>`${e.origin}/${Wd(n)}?${new URLSearchParams({xml:"",l:"1"})}`,postUrl:(n)=>`${e.origin}/${n}?json=`,pageUrl:(n)=>`${e.origin}/${n}`,parse:LI,count:_I,credits:jI,counts:(n)=>Wd(n).split(",").length===1&&!("d"in pw(n)),guesses:(n)=>(n.tags.includes("transparent_background")?["png","jpg"]:["jpg","png"]).map((r)=>n.preview.replace(vw,xI).replace(/\.600\.(\d+)\.jpg$/,`.full.$1.${r}`))}}function YI(t){let e=gw(`https://${t}`);return J.find((n)=>gw(n.origin)===e)}function Zd(t){return t.split(/\s+/).filter((e)=>e&&!$I.test(e)).length}function vc(t,e){let n=t.trim();if(/^\d+$/.test(n))return{site:e,id:Number(n)};let r=/^([\w.]+):(\d+)$/.exec(n);if(r){let a=J.find((c)=>c.key===r[1]||c.name===r[1]);return a&&{site:a,id:Number(r[2])}}let i;try{i=new URL(n)}catch{return}let o=YI(i.host),s=Number(i.searchParams.get("id")??i.pathname.split("/").filter(Boolean).at(-1));return o&&s>0?{site:o,id:s}:void 0}var J=[DI({key:"danbooru",name:"danbooru",origin:"https://shima.donmai.us",cutouts:["transparent_background"],vouched:!1,ansi:2}),mw({key:"konachan",name:"konachan",origin:"https://konachan.net",cutouts:["transparent","vector"],vouched:!1,ansi:6}),mw({key:"yande",name:"yande.re",origin:"https://yande.re",cutouts:["transparent_png"],vouched:!0,ansi:5}),qI({key:"zerochan",name:"zerochan",origin:"https://www.zerochan.net",cutouts:["transparent_background"],vouched:!1,ansi:3})],ie=J.find((t)=>t.key==="danbooru"),Mr=134217728;function Ee(t,e){let n=J.indexOf(t);return(n===-1?J.length:n)*Mr+e}function gw(t){let e;try{e=new URL(t).hostname}catch{return""}return e.split(".").slice(-2).join(".")}function bi(t,e,n=e){return e.mirror&&n===e?{site:ie,url:e.mirror.file}:{site:t,url:n.file}}function Sc(t,e){return e.mirror?{site:ie,url:e.mirror.preview}:{site:t,url:e.preview}}function Ec(t,e=pi){return t.tags.filter((n)=>e.some((r)=>$w[r].has(n)))}function Iw(t,e){return t.tags.filter((n)=>e.some((r)=>wI[r].has(n)))}function Mc(t,e,n=["safe"]){return n.some((r)=>t.ratings[r].has(e.rating))}function Rw(t,e){return t.rate(["safe"])===""?void 0:ko.find((n)=>t.ratings[n].has(e.rating))}function kn(t){return[t,...t.smaller].find((e)=>e.width*e.height<=Se)}function Pw(t){let e=new Map;for(let[n,r]of[...t].sort(([i],[o])=>i<o?-1:1)){if(r==="")continue;e.set(r,[...e.get(r)??[],n])}return e}function xr(){return Ls(process.env.XDG_CACHE_HOME??Ls(pI(),".cache"),"ttheme")}function Ve(t){return Ls(xr(),t.key)}function Nw(t=bI,e=xr()){let n=[],r=0;for(let i of fw(e))for(let o of OI){let s=Ls(e,i,o);for(let a of fw(s)){let c=Ls(s,a);try{let{size:u,mtimeMs:l}=hI(c);n.push({path:c,size:u,at:l}),r+=u}catch{}}}n.sort((i,o)=>i.at-o.at);for(let i of n){if(r<=t)return;try{fI(i.path,{force:!0}),r-=i.size}catch{}}}function JI(t,e){if(t!==null&&/^\s*\d+\s*$/.test(t))return Number(t)*1000;let n=t===null?Number.NaN:Date.parse(t);return Number.isNaN(n)?yw:Math.max(0,n-e)}function zn(t){return Sw.get(t.key)??0}function VI(t){for(let e=t;e instanceof Error;e=e.cause)if(e.code==="ECONNRESET")return!0;return!1}function ZI(t){return(t.headers.get("server")??"").startsWith("cloudflare")&&t.headers.get("cf-mitigated")==="challenge"}function QI(t,e){let n=new URL(e,t);if(!n.search)n.search=new URL(t).search;return n.href}async function Sr(t,e,n,r={},i=kI){let o=e;for(let s=1,a=0;;s++){let c=zn(t)-Date.now();if(c>0)await gI(c,void 0,{signal:n});let u;try{u=await fetch(o,{headers:{"User-Agent":qd,Referer:`${t.origin}/`,...r},redirect:"manual",signal:i?AbortSignal.any([n,AbortSignal.timeout(i)]):n})}catch(d){if(s<dw&&!n.aborted&&VI(d))continue;throw d}let l=u.headers.get("location");if(l&&u.status>=300&&u.status<400&&a<MI){await u.body?.cancel(),o=QI(o,l),a++,s--;continue}if(u.status===429&&s<dw){await u.body?.cancel();let d=JI(u.headers.get("retry-after"),Date.now());if(d>yw)throw Error(`${t.name} asks to wait ${Math.ceil(d/1000)}s`);Sw.set(t.key,Math.max(zn(t),Date.now()+d));continue}if(!u.ok)throw await u.body?.cancel(),Object.assign(Error(ZI(u)?`${t.name} is behind a Cloudflare challenge`:`${t.name} answered ${u.status}`),{status:u.status});return u}}async function xc(t,e,n){try{return await(await Sr(t,e,n)).text()}catch(r){if(t.missing!==void 0&&r.status===t.missing)return"";throw r}}async function Aw(t,e,n,r){return t.parse(await xc(t,t.postsUrl(e,n),r))}async function Qd(t,e,n){return t.count(await xc(t,t.countUrl(e),n))}async function So(t,e,n){let[r]=t.parse(await xc(t,t.postUrl(e),n));return r}async function Oc(t,e,n){return t.credits?.(await xc(t,t.pageUrl(e),n))}var XI=/^https?:\/\/(?:i\.pximg\.net|i\d*\.pixiv\.net|img\d*\.pixiv\.net)\/\S*\/(\d+)(?:_p\d+)?(?:_\w+)?\.\w+(?:[?#]\S*)?$/i,tR=/^https?:\/\/(?:www\.)?pixiv\.net\/member_illust\.php\?\S*\billust_id=(\d+)/i;function Bs(t){let e=XI.exec(t)?.[1]??tR.exec(t)?.[1];return e?`https://www.pixiv.net/artworks/${e}`:t}function Ic(t,e){return t.credits!==void 0&&e.named.artist.length===0}function Gs(t,e){for(let n of PI){let r=e.named?.[n]??[];if(t.named[n].length===0&&r.length>0)t.named[n]=r}if(t.source||=e.source??"",t.owner||=e.owner??"",!t.posted&&e.posted)t.posted=e.posted}function eR(t){let e=new URLSearchParams({limit:String(2*vr),only:"md5,tag_string,tag_string_artist,tag_string_character,tag_string_copyright,source,file_url",tags:`md5:${t.join(",")}`});return`${ie.origin}/posts.json?${e}`}function nR(t){return new Map(Fs(t).flatMap((e)=>{let n=String(e.md5??"");return n?[[n,{tags:Kn(e.tag_string),named:{artist:Kn(e.tag_string_artist),character:Kn(e.tag_string_character),copyright:Kn(e.tag_string_copyright)},source:String(e.source??""),file:yo(String(e.file_url??""))}]]:[]}))}function Rc(t,e){for(let n of t){let r=e.get(n.md5);if(!r)continue;if(n.tags=[...new Set([...n.tags,...r.tags])],Gs(n,r),n.solo=r.tags.includes("solo"),r.file.includes("/original/")){if(n.mirror={file:r.file,preview:r.file.replace("/original/","/360x360/").replace(/\.[a-z0-9]+$/i,".jpg")},!n.file)n.file=r.file,n.ext=Er(r.file)}}}async function Pc(t,e){let n=new Map;if(zn(ie)>Date.now())return n;for(let r=0;r<t.length;r+=vr){let i=await(await Sr(ie,eR(t.slice(r,r+vr)),e,{},yI)).text();for(let[o,s]of nR(i))n.set(o,s)}return n}async function Us(t,e,n){if(e.file||!t.guesses)return;for(let r of t.guesses(e))try{let i=await Sr(t,r,n,{Range:`bytes=0-${kw}`}),o=$n(new Uint8Array(await i.arrayBuffer()));return e.file=r,e.ext=Er(r),o}catch(i){if(n.aborted||i.status!==404)throw i}throw Error(`${t.name} keeps no png or jpg of ${e.id}`)}async function Tw(t,e){if(zn(ie)<=Date.now())try{let i=new URLSearchParams({"search[query]":t,"search[type]":"tag_query",limit:String(lw)}),o=`${ie.origin}/autocomplete.json?${i}`;return BI(await(await Sr(ie,o,e,{},uw)).text())}catch(i){if(e.aborted)throw i}let n=J.find((i)=>i.key==="yande"),r=new URLSearchParams({name:t,order:"count",limit:String(lw)});return GI(await(await Sr(n,`${n.origin}/tag.json?${r}`,e,{},uw)).text())}function rR(t){try{return(JSON.parse(t).related_tags??[]).flatMap(({tag:n})=>n?.name?[{value:n.name,count:Number(n.post_count)||0}]:[])}catch{return[]}}async function Hw(t,e){if(zn(ie)>Date.now())return[];let n=new URLSearchParams({"search[query]":t,"search[category]":"character",limit:String(vI)});return rR(await(await Sr(ie,`${ie.origin}/related_tag.json?${n}`,e,{},SI)).text())}function Cw(t,e){return e.slice(0,t.ors?t.tagBudget:1)}async function Lw(t,e,n){let r=await Sr(t,e,n,{Range:`bytes=0-${kw}`});return $n(new Uint8Array(await r.arrayBuffer()))}async function Nc(t,e,n,r){let i=await Sr(t,e,n,{},0),o=Number(i.headers.get("content-length"))||0,s=i.body?.getReader();if(!s)return new Uint8Array(await i.arrayBuffer());let a=[],c=0;for(;;){let{done:d,value:f}=await s.read();if(d)break;a.push(f),c+=f.length,r?.(c,o)}let u=new Uint8Array(c),l=0;for(let d of a)u.set(d,l),l+=d.length;return u}var dR=12,fR=/^[0-9a-f]{40}$/;function Eo(){return Mo(xr(),"drawn")}function Fw(t){return iR("sha1").update(JSON.stringify(t)).digest("hex")}function jw(t){return oR(Mo(Eo(),t))}function _w(t){let e=Mo(Eo(),t);try{let n=aR(e),r=n.readUInt32BE(0),i=JSON.parse(n.toString("utf8",4,4+r)),o=n.subarray(4+r,4+r+i.figure),s=n.subarray(4+r+i.figure,4+r+i.figure+i.picture);if(o.length!==i.figure||s.length!==i.picture)return;let a=new Date;return lR(e,a,a),{stem:i.stem,fill:i.fill,...i.peak?{peak:i.peak}:{},figure:o,picture:s}}catch{return}}function Xd(t,e){let n=Buffer.from(JSON.stringify({stem:e.stem,fill:e.fill,...e.peak?{peak:e.peak}:{},figure:e.figure.length,picture:e.picture.length})),r=Buffer.alloc(4);r.writeUInt32BE(n.length),F(Mo(Eo(),t),Buffer.concat([r,n,e.figure,e.picture])),hR()}function hR(){let t=sR(Eo()).filter((e)=>fR.test(e)).flatMap((e)=>{try{return[{name:e,at:uR(Mo(Eo(),e)).mtimeMs}]}catch{return[]}}).sort((e,n)=>n.at-e.at);for(let{name:e}of t.slice(dR))cR(Mo(Eo(),e),{force:!0})}import{readdirSync as kR,readFileSync as Yw}from"node:fs";import{basename as yR,join as Jw}from"node:path";/*!
4
4
  * Copyright (c) Squirrel Chat et al., All rights reserved.
5
5
  * SPDX-License-Identifier: BSD-3-Clause
6
6
  *
@@ -26,11 +26,11 @@ import{createRequire as BM}from"node:module";var HM=Object.create;var{getPrototy
26
26
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
27
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
28
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
- */function LI(t,e){let n=t.slice(0,e).split(/\r?\n/);return[n.length,n.pop().length+1]}function jI(t,e,n){let r=t.split(/\r?\n/),i="",s=(Math.log10(e+1)|0)+1;for(let o=e-1;o<=e+1;o++){let a=r[o-1];if(!a)continue;if(i+=o.toString().padEnd(s," "),i+=": ",i+=a,i+=`
30
- `,o===e)i+=" ".repeat(s+n+2),i+=`^
31
- `}return i}class K extends Error{line;column;codeblock;constructor(t,e){let[n,r]=LI(e.toml,e.ptr),i=jI(e.toml,n,r);super(`Invalid TOML document: ${t}
29
+ */function mR(t,e){let n=t.slice(0,e).split(/\r?\n/);return[n.length,n.pop().length+1]}function pR(t,e,n){let r=t.split(/\r?\n/),i="",o=(Math.log10(e+1)|0)+1;for(let s=e-1;s<=e+1;s++){let a=r[s-1];if(!a)continue;if(i+=s.toString().padEnd(o," "),i+=": ",i+=a,i+=`
30
+ `,s===e)i+=" ".repeat(o+n+2),i+=`^
31
+ `}return i}class D extends Error{line;column;codeblock;constructor(t,e){let[n,r]=mR(e.toml,e.ptr),i=pR(e.toml,n,r);super(`Invalid TOML document: ${t}
32
32
 
33
- ${i}`,e);this.line=n,this.column=r,this.codeblock=i}static x(t,e,n){throw new K(t,{toml:e.s,ptr:n??e.p})}}/*!
33
+ ${i}`,e);this.line=n,this.column=r,this.codeblock=i}static x(t,e,n){throw new D(t,{toml:e.s,ptr:n??e.p})}}/*!
34
34
  * Copyright (c) Squirrel Chat et al., All rights reserved.
35
35
  * SPDX-License-Identifier: BSD-3-Clause
36
36
  *
@@ -56,8 +56,8 @@ ${i}`,e);this.line=n,this.column=r,this.codeblock=i}static x(t,e,n){throw new K(
56
56
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
57
57
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
58
58
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59
- */function ic(t){let e=t.p,n=t.s.charCodeAt(t.p++),r=n,i=n===39,s=n===t.s.charCodeAt(t.p)&&n===t.s.charCodeAt(t.p+1);if(s){if((n=t.s.charCodeAt(t.p+=2))===10)t.p++;else if(n===13&&t.s.charCodeAt(t.p+1)===10)t.p+=2}let o="",a=t.p,c=0;for(;t.p<t.s.length;t.p++)if(n=t.s.charCodeAt(t.p),s&&(n===10||n===13&&t.s.charCodeAt(t.p+1)===10))c=c&&3;else if(n<32&&n!==9||n===127)K.x("control characters are not allowed in strings",t);else if((!c||c===3)&&n===r&&(!s||t.s.charCodeAt(t.p+1)===r&&t.s.charCodeAt(t.p+2)===r)){if(s){if(t.s.charCodeAt(t.p+3)===r)t.p++;if(t.s.charCodeAt(t.p+3)===r)t.p++}if(!c){let u=t.s.slice(a,t.p);o=o?o+u:u}return t.p+=s?3:1,o}else if(!c){if(!i&&n===92)o+=t.s.slice(a,a=t.p),c=1}else if(c===1)if(n===120||n===117||n===85){let u=t.p++-1,l=0,f=n===120?2:n===117?4:8;for(let d=0;d<f;d++,t.p++){let h=t.s.charCodeAt(t.p),m=h>=48&&h<=57?h-48:h>=65&&h<=70?h-65+10:h>=97&&h<=102?h-97+10:-1;if(m<0)K.x("invalid non-hex character in unicode escape",t);l=l<<4|m}if(l<0||l>1114111||l>=55296&&l<=57343)K.x("invalid unicode escape",t,u);o+=String.fromCodePoint(l),a=t.p--,c=0}else if(s&&(n===32||n===9))c=2;else{if(n===98)o+="\b";else if(n===116)o+="\t";else if(n===110)o+=`
60
- `;else if(n===102)o+="\f";else if(n===114)o+="\r";else if(n===101)o+="\x1B";else if(n===34)o+='"';else if(n===92)o+="\\";else K.x("unrecognised escape sequence",t);a=t.p+1,c=0}else if(n!==32&&n!==9){if(c===2)K.x("invalid escape: only line-ending whitespace may be escaped",t,a);c=!i&&n===92?1:0,a=t.p}K.x("unfinished string",t,e)}/*!
59
+ */function Ac(t){let e=t.p,n=t.s.charCodeAt(t.p++),r=n,i=n===39,o=n===t.s.charCodeAt(t.p)&&n===t.s.charCodeAt(t.p+1);if(o){if((n=t.s.charCodeAt(t.p+=2))===10)t.p++;else if(n===13&&t.s.charCodeAt(t.p+1)===10)t.p+=2}let s="",a=t.p,c=0;for(;t.p<t.s.length;t.p++)if(n=t.s.charCodeAt(t.p),o&&(n===10||n===13&&t.s.charCodeAt(t.p+1)===10))c=c&&3;else if(n<32&&n!==9||n===127)D.x("control characters are not allowed in strings",t);else if((!c||c===3)&&n===r&&(!o||t.s.charCodeAt(t.p+1)===r&&t.s.charCodeAt(t.p+2)===r)){if(o){if(t.s.charCodeAt(t.p+3)===r)t.p++;if(t.s.charCodeAt(t.p+3)===r)t.p++}if(!c){let u=t.s.slice(a,t.p);s=s?s+u:u}return t.p+=o?3:1,s}else if(!c){if(!i&&n===92)s+=t.s.slice(a,a=t.p),c=1}else if(c===1)if(n===120||n===117||n===85){let u=t.p++-1,l=0,d=n===120?2:n===117?4:8;for(let f=0;f<d;f++,t.p++){let h=t.s.charCodeAt(t.p),m=h>=48&&h<=57?h-48:h>=65&&h<=70?h-65+10:h>=97&&h<=102?h-97+10:-1;if(m<0)D.x("invalid non-hex character in unicode escape",t);l=l<<4|m}if(l<0||l>1114111||l>=55296&&l<=57343)D.x("invalid unicode escape",t,u);s+=String.fromCodePoint(l),a=t.p--,c=0}else if(o&&(n===32||n===9))c=2;else{if(n===98)s+="\b";else if(n===116)s+="\t";else if(n===110)s+=`
60
+ `;else if(n===102)s+="\f";else if(n===114)s+="\r";else if(n===101)s+="\x1B";else if(n===34)s+='"';else if(n===92)s+="\\";else D.x("unrecognised escape sequence",t);a=t.p+1,c=0}else if(n!==32&&n!==9){if(c===2)D.x("invalid escape: only line-ending whitespace may be escaped",t,a);c=!i&&n===92?1:0,a=t.p}D.x("unfinished string",t,e)}/*!
61
61
  * Copyright (c) Squirrel Chat et al., All rights reserved.
62
62
  * SPDX-License-Identifier: BSD-3-Clause
63
63
  *
@@ -83,7 +83,7 @@ ${i}`,e);this.line=n,this.column=r,this.codeblock=i}static x(t,e,n){throw new K(
83
83
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
84
84
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
85
85
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
86
- */var _I=/^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;class mr extends Date{#e=!1;#n=!1;#t=null;constructor(t,e,n){let r=!0,i=!0,s="Z",o;if(typeof t==="string")if(e)t:{if(e<3){if(+t.slice(11,13)>23){t="";break t}if(e===2)s=null,t+="Z";else if((o=t.charCodeAt(t.length-1))!==90&&o!==122)s=t.slice(t.length-6);if(n)t=t.slice(0,10)+"T"+t.slice(11)}else if(e===4)t=+t.slice(0,2)>23?"":`0000-01-01T${t}Z`;r=e!==4,i=e!==3}else{let a=t.match(_I);if(a){if(!a[1])r=!1,t=`0000-01-01T${t}`;if(i=!!a[2],i&&t[10]===" "&&(t=t.replace(" ","T")),a[2]&&+a[2]>23)t="";else if(s=a[3]||null,!s&&i)t+="Z"}else t=""}super(t);if(!isNaN(this.getTime()))this.#e=r,this.#n=i,this.#t=s}isDateTime(){return this.#e&&this.#n}isLocal(){return!this.#e||!this.#n||!this.#t}isDate(){return this.#e&&!this.#n}isTime(){return this.#n&&!this.#e}isValid(){return this.#e||this.#n}toISOString(){let t=super.toISOString();if(this.isDate())return t.slice(0,10);if(this.isTime())return t.slice(11,23);if(this.#t===null)return t.slice(0,-1);if(this.#t==="Z"||this.#t==="z")return t;let e=+this.#t.slice(1,3)*60+ +this.#t.slice(4,6);return e=this.#t[0]==="-"?e:-e,new Date(this.getTime()-e*60000).toISOString().slice(0,-1)+this.#t}static wrapAsOffsetDateTime(t,e="Z"){let n=new mr(t);return n.#t=e,n}static wrapAsLocalDateTime(t){let e=new mr(t);return e.#t=null,e}static wrapAsLocalDate(t){let e=new mr(t);return e.#n=!1,e.#t=null,e}static wrapAsLocalTime(t){let e=new mr(t);return e.#e=!1,e.#t=null,e}}/*!
86
+ */var gR=/^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;class Or extends Date{#e=!1;#n=!1;#t=null;constructor(t,e,n){let r=!0,i=!0,o="Z",s;if(typeof t==="string")if(e)t:{if(e<3){if(+t.slice(11,13)>23){t="";break t}if(e===2)o=null,t+="Z";else if((s=t.charCodeAt(t.length-1))!==90&&s!==122)o=t.slice(t.length-6);if(n)t=t.slice(0,10)+"T"+t.slice(11)}else if(e===4)t=+t.slice(0,2)>23?"":`0000-01-01T${t}Z`;r=e!==4,i=e!==3}else{let a=t.match(gR);if(a){if(!a[1])r=!1,t=`0000-01-01T${t}`;if(i=!!a[2],i&&t[10]===" "&&(t=t.replace(" ","T")),a[2]&&+a[2]>23)t="";else if(o=a[3]||null,!o&&i)t+="Z"}else t=""}super(t);if(!isNaN(this.getTime()))this.#e=r,this.#n=i,this.#t=o}isDateTime(){return this.#e&&this.#n}isLocal(){return!this.#e||!this.#n||!this.#t}isDate(){return this.#e&&!this.#n}isTime(){return this.#n&&!this.#e}isValid(){return this.#e||this.#n}toISOString(){let t=super.toISOString();if(this.isDate())return t.slice(0,10);if(this.isTime())return t.slice(11,23);if(this.#t===null)return t.slice(0,-1);if(this.#t==="Z"||this.#t==="z")return t;let e=+this.#t.slice(1,3)*60+ +this.#t.slice(4,6);return e=this.#t[0]==="-"?e:-e,new Date(this.getTime()-e*60000).toISOString().slice(0,-1)+this.#t}static wrapAsOffsetDateTime(t,e="Z"){let n=new Or(t);return n.#t=e,n}static wrapAsLocalDateTime(t){let e=new Or(t);return e.#t=null,e}static wrapAsLocalDate(t){let e=new Or(t);return e.#n=!1,e.#t=null,e}static wrapAsLocalTime(t){let e=new Or(t);return e.#e=!1,e.#t=null,e}}/*!
87
87
  * Copyright (c) Squirrel Chat et al., All rights reserved.
88
88
  * SPDX-License-Identifier: BSD-3-Clause
89
89
  *
@@ -109,7 +109,7 @@ ${i}`,e);this.line=n,this.column=r,this.codeblock=i}static x(t,e,n){throw new K(
109
109
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
110
110
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
111
111
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
112
- */function ye(t,e=10){return e===16?t>47&&t<58||t>64&&t<71||t>96&&t<103:t>47&&t<48+e}function Ef(t,e){return t===32||t===9||t===10||t===13||e&&(t===e||t===44)||t===35}function Oo(t,e){let n=t.p,r=t.s.charCodeAt(t.p);if(r===91||r===123){t.d--||K.x("document contains excessively nested structures. aborting.",t);let i=r===91?qb(t):Db(t);return t.d++,i}if(r===34||r===39)return ic(t);if(r===116){if(t.s.charCodeAt(++t.p)!==114||t.s.charCodeAt(++t.p)!==117||t.s.charCodeAt(++t.p)!==101)K.x("invalid value",t,n);return t.p++,!0}if(r===102){if(t.s.charCodeAt(++t.p)!==97||t.s.charCodeAt(++t.p)!==108||t.s.charCodeAt(++t.p)!==115||t.s.charCodeAt(++t.p)!==101)K.x("invalid value",t,n);return t.p++,!1}if(r===43||r===45)return sc(t,t.p,t.s.charCodeAt(++t.p),44-r,e);if(t.s.charCodeAt(t.p+4)===45&&t.s.charCodeAt(t.p+7)===45)return GI(t,r,e);if(t.s.charCodeAt(t.p+2)===58)return BI(t,r,e);return sc(t,t.p,r,0,e)}function sc(t,e,n,r,i){let s=n,o=0,a=!1;if(s===105){if(t.s.charCodeAt(++t.p)!==110||t.s.charCodeAt(++t.p)!==102)K.x("invalid value",t,e);return t.p++,(r||1)/0}if(s===110){if(t.s.charCodeAt(++t.p)!==97||t.s.charCodeAt(++t.p)!==110)K.x("invalid value",t,e);return t.p++,NaN}if(s===48){if(++t.p>=t.s.length||Ef(s=t.s.charCodeAt(t.p),i))return t.bi===!0?0n:0;if(!r){if(s===120)return vf(t,e,16,i);else if(s===98)return vf(t,e,2,i);else if(s===111)return vf(t,e,8,i)}if(s===46)o=2;else if(s===101||s===69)o=4;else K.x("illegal leading zero",t,e)}else if(!ye(s))K.x("invalid value",t,e);while(++t.p<t.s.length&&(s=t.s.charCodeAt(t.p),!Ef(s,i))){if(!o)o=1;if(s===95){if(!(o&1))K.x("illegal underscore",t);o+=11,a=!0}else if(o===1&&s===46)o=2;else if((o===1||o===3)&&(s===101||s===69))o=4;else if(o===4&&(s===43||s===45));else if(!ye(s))K.x("illegal character in numeric literal",t);else if(o>9)o-=11;else if(!(o&1))o++}if(!o){let u=(n-48)*(r||1);return t.bi===!0?BigInt(u):u}if(!(o&1))K.x("unfinished numeric value",t,e);let c=t.s.slice(e,t.p);if(a)c=c.replaceAll("_","");return o>1?parseFloat(c):zb(t,c,10,e)}function vf(t,e,n,r){let i,s=1;while(++t.p<t.s.length&&(i=t.s.charCodeAt(t.p),!Ef(i,r)))if(i===95){if(s&1)K.x("illegal underscore",t);s=3}else if(!ye(i,n))K.x("illegal character in numeric literal",t);else if(s&1)s--;if(s&1)K.x("unfinished numeric value",t);let o=t.s.slice(e+2,t.p);if(s)o=o.replaceAll("_","");return zb(t,o,n,e)}function zb(t,e,n,r){if(t.bi!==!0)t:{let i=parseInt(e,n);if(!Number.isSafeInteger(i)){if(t.bi)break t;K.x("integer value cannot be represented losslessly",t,r)}return i}return n===10?BigInt(e):BigInt((n===2?"0b":n===8?"0o":"0x")+e)}function GI(t,e,n){let r=t.p++,i;if(!ye(e)||!ye(t.s.charCodeAt(t.p++))||!ye(t.s.charCodeAt(t.p++))||!ye(t.s.charCodeAt(t.p++)))return sc(t,t.p=r,e,0,n);if(t.p+=5,!ye(t.s.charCodeAt(t.p++)))K.x("invalid date-time: date part is malformed",t,r);if(t.p>=t.s.length||((e=t.s.charCodeAt(t.p))!==32||(i=!0,!ye(t.s.charCodeAt(t.p+1))))&&e!==84&&e!==116){let o=t.s.slice(r,t.p);return Mo(t,o,3,!1,r)}if(t.s.charCodeAt(t.p+=3)!==58)K.x("invalid date-time: time part is malformed",t,r);if(t.s.charCodeAt(t.p+=3)===58)t.p+=3;if(t.s.charCodeAt(t.p)===46)while(ye(t.s.charCodeAt(++t.p)));if(e=t.s.charCodeAt(t.p)){if(e===90||e===122){let o=t.s.slice(r,++t.p);return Mo(t,o,1,i,r,"[+00:00]")}if(e===43||e===45){let o=t.s.slice(r,t.p+=6);return Mo(t,o,1,i,r,!t.ld&&"["+t.s.slice(t.p-6,t.p)+"]")}}let s=t.s.slice(r,t.p);return Mo(t,s,2,i,r)}function BI(t,e,n){let r=t.p;if(!ye(e)||!ye(t.s.charCodeAt(++t.p)))return sc(t,--t.p,e,0,n);if(t.s.charCodeAt(t.p+=4)===58)t.p+=3;if(t.s.charCodeAt(t.p)===46)while(ye(t.s.charCodeAt(++t.p)));let i=t.s.slice(r,t.p);return Mo(t,i,4,!1,r)}function Mo(t,e,n,r,i,s){if(t.ld){let o=new mr(e,n,r);if(!o.isValid())K.x("invalid date",t,i);return o}try{if(s)e+=s;switch(n){case 1:return Temporal.ZonedDateTime.from(e);case 2:return Temporal.PlainDateTime.from(e);case 3:return Temporal.PlainDate.from(e);case 4:return Temporal.PlainTime.from(e)}}catch(o){K.x(o instanceof Error?o.message:""+o,t,i)}}/*!
112
+ */function Me(t,e=10){return e===16?t>47&&t<58||t>64&&t<71||t>96&&t<103:t>47&&t<48+e}function ef(t,e){return t===32||t===9||t===10||t===13||e&&(t===e||t===44)||t===35}function Ks(t,e){let n=t.p,r=t.s.charCodeAt(t.p);if(r===91||r===123){t.d--||D.x("document contains excessively nested structures. aborting.",t);let i=r===91?Uw(t):Gw(t);return t.d++,i}if(r===34||r===39)return Ac(t);if(r===116){if(t.s.charCodeAt(++t.p)!==114||t.s.charCodeAt(++t.p)!==117||t.s.charCodeAt(++t.p)!==101)D.x("invalid value",t,n);return t.p++,!0}if(r===102){if(t.s.charCodeAt(++t.p)!==97||t.s.charCodeAt(++t.p)!==108||t.s.charCodeAt(++t.p)!==115||t.s.charCodeAt(++t.p)!==101)D.x("invalid value",t,n);return t.p++,!1}if(r===43||r===45)return Tc(t,t.p,t.s.charCodeAt(++t.p),44-r,e);if(t.s.charCodeAt(t.p+4)===45&&t.s.charCodeAt(t.p+7)===45)return bR(t,r,e);if(t.s.charCodeAt(t.p+2)===58)return wR(t,r,e);return Tc(t,t.p,r,0,e)}function Tc(t,e,n,r,i){let o=n,s=0,a=!1;if(o===105){if(t.s.charCodeAt(++t.p)!==110||t.s.charCodeAt(++t.p)!==102)D.x("invalid value",t,e);return t.p++,(r||1)/0}if(o===110){if(t.s.charCodeAt(++t.p)!==97||t.s.charCodeAt(++t.p)!==110)D.x("invalid value",t,e);return t.p++,NaN}if(o===48){if(++t.p>=t.s.length||ef(o=t.s.charCodeAt(t.p),i))return t.bi===!0?0n:0;if(!r){if(o===120)return tf(t,e,16,i);else if(o===98)return tf(t,e,2,i);else if(o===111)return tf(t,e,8,i)}if(o===46)s=2;else if(o===101||o===69)s=4;else D.x("illegal leading zero",t,e)}else if(!Me(o))D.x("invalid value",t,e);while(++t.p<t.s.length&&(o=t.s.charCodeAt(t.p),!ef(o,i))){if(!s)s=1;if(o===95){if(!(s&1))D.x("illegal underscore",t);s+=11,a=!0}else if(s===1&&o===46)s=2;else if((s===1||s===3)&&(o===101||o===69))s=4;else if(s===4&&(o===43||o===45));else if(!Me(o))D.x("illegal character in numeric literal",t);else if(s>9)s-=11;else if(!(s&1))s++}if(!s){let u=(n-48)*(r||1);return t.bi===!0?BigInt(u):u}if(!(s&1))D.x("unfinished numeric value",t,e);let c=t.s.slice(e,t.p);if(a)c=c.replaceAll("_","");return s>1?parseFloat(c):Bw(t,c,10,e)}function tf(t,e,n,r){let i,o=1;while(++t.p<t.s.length&&(i=t.s.charCodeAt(t.p),!ef(i,r)))if(i===95){if(o&1)D.x("illegal underscore",t);o=3}else if(!Me(i,n))D.x("illegal character in numeric literal",t);else if(o&1)o--;if(o&1)D.x("unfinished numeric value",t);let s=t.s.slice(e+2,t.p);if(o)s=s.replaceAll("_","");return Bw(t,s,n,e)}function Bw(t,e,n,r){if(t.bi!==!0)t:{let i=parseInt(e,n);if(!Number.isSafeInteger(i)){if(t.bi)break t;D.x("integer value cannot be represented losslessly",t,r)}return i}return n===10?BigInt(e):BigInt((n===2?"0b":n===8?"0o":"0x")+e)}function bR(t,e,n){let r=t.p++,i;if(!Me(e)||!Me(t.s.charCodeAt(t.p++))||!Me(t.s.charCodeAt(t.p++))||!Me(t.s.charCodeAt(t.p++)))return Tc(t,t.p=r,e,0,n);if(t.p+=5,!Me(t.s.charCodeAt(t.p++)))D.x("invalid date-time: date part is malformed",t,r);if(t.p>=t.s.length||((e=t.s.charCodeAt(t.p))!==32||(i=!0,!Me(t.s.charCodeAt(t.p+1))))&&e!==84&&e!==116){let s=t.s.slice(r,t.p);return Ws(t,s,3,!1,r)}if(t.s.charCodeAt(t.p+=3)!==58)D.x("invalid date-time: time part is malformed",t,r);if(t.s.charCodeAt(t.p+=3)===58)t.p+=3;if(t.s.charCodeAt(t.p)===46)while(Me(t.s.charCodeAt(++t.p)));if(e=t.s.charCodeAt(t.p)){if(e===90||e===122){let s=t.s.slice(r,++t.p);return Ws(t,s,1,i,r,"[+00:00]")}if(e===43||e===45){let s=t.s.slice(r,t.p+=6);return Ws(t,s,1,i,r,!t.ld&&"["+t.s.slice(t.p-6,t.p)+"]")}}let o=t.s.slice(r,t.p);return Ws(t,o,2,i,r)}function wR(t,e,n){let r=t.p;if(!Me(e)||!Me(t.s.charCodeAt(++t.p)))return Tc(t,--t.p,e,0,n);if(t.s.charCodeAt(t.p+=4)===58)t.p+=3;if(t.s.charCodeAt(t.p)===46)while(Me(t.s.charCodeAt(++t.p)));let i=t.s.slice(r,t.p);return Ws(t,i,4,!1,r)}function Ws(t,e,n,r,i,o){if(t.ld){let s=new Or(e,n,r);if(!s.isValid())D.x("invalid date",t,i);return s}try{if(o)e+=o;switch(n){case 1:return Temporal.ZonedDateTime.from(e);case 2:return Temporal.PlainDateTime.from(e);case 3:return Temporal.PlainDate.from(e);case 4:return Temporal.PlainTime.from(e)}}catch(s){D.x(s instanceof Error?s.message:""+s,t,i)}}/*!
113
113
  * Copyright (c) Squirrel Chat et al., All rights reserved.
114
114
  * SPDX-License-Identifier: BSD-3-Clause
115
115
  *
@@ -135,7 +135,7 @@ ${i}`,e);this.line=n,this.column=r,this.codeblock=i}static x(t,e,n){throw new K(
135
135
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
136
136
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
137
137
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
138
- */function UI(t){for(;t.p<t.s.length;t.p++){let e=t.s.charCodeAt(t.p);if(e===10)break;if(e===13&&t.s.charCodeAt(t.p+1)===10){t.p++;break}if(e<32&&e!==9||e===127)K.x("control characters are not allowed in comments",t)}}function ze(t,e,n){let r;while(t.p<t.s.length){while(t.p<t.s.length&&((r=t.s.charCodeAt(t.p))===32||r===9||!e&&(r===10||r===13&&t.s.charCodeAt(t.p+1)===10)))t.p++;if(n||r!==35)break;UI(t)}}/*!
138
+ */function $R(t){for(;t.p<t.s.length;t.p++){let e=t.s.charCodeAt(t.p);if(e===10)break;if(e===13&&t.s.charCodeAt(t.p+1)===10){t.p++;break}if(e<32&&e!==9||e===127)D.x("control characters are not allowed in comments",t)}}function Ze(t,e,n){let r;while(t.p<t.s.length){while(t.p<t.s.length&&((r=t.s.charCodeAt(t.p))===32||r===9||!e&&(r===10||r===13&&t.s.charCodeAt(t.p+1)===10)))t.p++;if(n||r!==35)break;$R(t)}}/*!
139
139
  * Copyright (c) Squirrel Chat et al., All rights reserved.
140
140
  * SPDX-License-Identifier: BSD-3-Clause
141
141
  *
@@ -161,7 +161,7 @@ ${i}`,e);this.line=n,this.column=r,this.codeblock=i}static x(t,e,n){throw new K(
161
161
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
162
162
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
163
163
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
164
- */function oc(t,e=61){let n,r=0,i=[],s,o=t.s.charCodeAt(n=t.p);do if(o===e){if(!r)K.x("unexpected end of key",t);if(r===1)i.push(t.s.slice(s,t.p));return t.p++,i}else if(o===46){if(!r)K.x("illegal empty bare key",t);if(r===1)i.push(t.s.slice(s,t.p));r=0}else if(!r&&(o===34||o===39)){if(o===t.s.charCodeAt(t.p+1)&&o===t.s.charCodeAt(t.p+2))K.x("illegal quoted key: multiline strings are not allowed",t);i.push(ic(t)),r=2,t.p--}else if(o===32||o===9){if(r===1)i.push(t.s.slice(s,t.p)),r=2}else if(r===2||o<48&&o!==45||o>57&&o<65||o>90&&o<97&&o!==95||o>122)K.x("illegal character in key",t);else if(!r)r=1,s=t.p;while(o=t.s.charCodeAt(++t.p));K.x("incomplete key-value: cannot find end of key",t,n)}function Db(t){let e=t.p++,n=Object.create(null),r=new Set,i;while(t.p<t.s.length){if(ze(t),(i=t.s.charCodeAt(t.p))===125)return t.p++,n;let s,o=n,a=!1,c=t.p,u=oc(t);for(let f=0;f<u.length;f++){if(f)o=a?o[s]:o[s]=Object.create(null);if(s=u[f],(a=Object.hasOwn(o,s))&&(typeof o[s]!=="object"||r.has(o[s])))K.x("trying to redefine an already defined value",t,c);let d=s==="__proto__";if(t.uk&&(d||s==="constructor")){o=t.uk!==1&&K.x("document contains an unsafe property",t,c);break}if(!a&&d)Object.defineProperty(o,s,{enumerable:!0,configurable:!0,writable:!0})}if(a)K.x("trying to redefine an already defined value",t,c);ze(t,!0,!0);let l=Oo(t,125);if(o&&typeof(o[s]=l)==="object")r.add(l);if(ze(t),(i=t.s.charCodeAt(t.p++))===125)return n;if(i!==44)K.x("expected comma or end of structure",t,t.p-1)}K.x("unfinished table",t,e)}function qb(t){let e=t.p++,n=[],r;while(t.p<t.s.length){if(ze(t),(r=t.s.charCodeAt(t.p))===93)return t.p++,n;if(n.push(Oo(t,93)),ze(t),(r=t.s.charCodeAt(t.p++))===93)return n;if(r!==44)K.x("expected comma or end of structure",t,t.p-1)}K.x("unfinished array",t,e)}/*!
164
+ */function Hc(t,e=61){let n,r=0,i=[],o,s=t.s.charCodeAt(n=t.p);do if(s===e){if(!r)D.x("unexpected end of key",t);if(r===1)i.push(t.s.slice(o,t.p));return t.p++,i}else if(s===46){if(!r)D.x("illegal empty bare key",t);if(r===1)i.push(t.s.slice(o,t.p));r=0}else if(!r&&(s===34||s===39)){if(s===t.s.charCodeAt(t.p+1)&&s===t.s.charCodeAt(t.p+2))D.x("illegal quoted key: multiline strings are not allowed",t);i.push(Ac(t)),r=2,t.p--}else if(s===32||s===9){if(r===1)i.push(t.s.slice(o,t.p)),r=2}else if(r===2||s<48&&s!==45||s>57&&s<65||s>90&&s<97&&s!==95||s>122)D.x("illegal character in key",t);else if(!r)r=1,o=t.p;while(s=t.s.charCodeAt(++t.p));D.x("incomplete key-value: cannot find end of key",t,n)}function Gw(t){let e=t.p++,n=Object.create(null),r=new Set,i;while(t.p<t.s.length){if(Ze(t),(i=t.s.charCodeAt(t.p))===125)return t.p++,n;let o,s=n,a=!1,c=t.p,u=Hc(t);for(let d=0;d<u.length;d++){if(d)s=a?s[o]:s[o]=Object.create(null);if(o=u[d],(a=Object.hasOwn(s,o))&&(typeof s[o]!=="object"||r.has(s[o])))D.x("trying to redefine an already defined value",t,c);let f=o==="__proto__";if(t.uk&&(f||o==="constructor")){s=t.uk!==1&&D.x("document contains an unsafe property",t,c);break}if(!a&&f)Object.defineProperty(s,o,{enumerable:!0,configurable:!0,writable:!0})}if(a)D.x("trying to redefine an already defined value",t,c);Ze(t,!0,!0);let l=Ks(t,125);if(s&&typeof(s[o]=l)==="object")r.add(l);if(Ze(t),(i=t.s.charCodeAt(t.p++))===125)return n;if(i!==44)D.x("expected comma or end of structure",t,t.p-1)}D.x("unfinished table",t,e)}function Uw(t){let e=t.p++,n=[],r;while(t.p<t.s.length){if(Ze(t),(r=t.s.charCodeAt(t.p))===93)return t.p++,n;if(n.push(Ks(t,93)),Ze(t),(r=t.s.charCodeAt(t.p++))===93)return n;if(r!==44)D.x("expected comma or end of structure",t,t.p-1)}D.x("unfinished array",t,e)}/*!
165
165
  * Copyright (c) Squirrel Chat et al., All rights reserved.
166
166
  * SPDX-License-Identifier: BSD-3-Clause
167
167
  *
@@ -187,7 +187,7 @@ ${i}`,e);this.line=n,this.column=r,this.codeblock=i}static x(t,e,n){throw new K(
187
187
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
188
188
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
189
189
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
190
- */function Yb(t,e,n,r,i){let s=n,o=r,a,c=!1,u;for(let l=0;l<e.length;l++){if(l){if(s=c?s[a]:s[a]=Object.create(null),o=(u=o[a]).c,i===0&&(u.t===1||u.t===2))return null;if(u.t===2){let f=s.length-1;s=s[f],o=o[f].c}}if(a=e[l],(c=Object.hasOwn(s,a))&&o[a]?.t===0&&o[a]?.d)return null;if(!c){let f=a==="__proto__";if(t.uk&&(f||a==="constructor"))return!1;if(f)Object.defineProperty(s,a,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(o,a,{enumerable:!0,configurable:!0,writable:!0});o[a]={t:l<e.length-1&&i===2?3:i,d:!1,i:0,c:Object.create(null)}}}if(u=o[a],u.t!==i&&!(i===1&&u.t===3))return null;if(i===2){if(!u.d)u.d=!0,s[a]=[];s[a].push(s=Object.create(null)),u.c[u.i++]=u={t:1,d:!1,i:0,c:Object.create(null)}}if(u.d)return null;if(u.d=!0,i===1)s=c?s[a]:s[a]=Object.create(null);else if(i===0&&c)return null;return[a,s,u.c]}function Jb(t,e,n){if(e===null||t.uk===2)K.x(e===null?"trying to redefine an already defined table or value":"document contains an unsafe property",t,n)}function ai(t,e={}){let n={s:t,p:0,d:e.maxDepth??1000,bi:e.integersAsBigInt??!1,ld:e.useLegacyDate??!0,uk:e.unsafeKeyBehaviour==="throw"?2:e.unsafeKeyBehaviour==="drop"?1:0},r=Object.create(null),i=Object.create(null),s,o=!1,a=r,c=i;if(t.charCodeAt(0)===65279)n.p++;ze(n);while(n.p<t.length){if(t.charCodeAt(n.p)===91){let u=t.charCodeAt(++n.p)===91;s=n.p+=+u,o=!1;let l=oc(n,93);if(u){if(t.charCodeAt(n.p)!==93)K.x("expected end of table array declaration",n);n.p++}let f=Yb(n,l,r,i,u?2:1);if(!f)Jb(n,f,s),o=!0;else c=f[2],a=f[1]}else{s=n.p;let u=oc(n),l=Yb(n,u,a,c,0);if(!l&&!o)Jb(n,l,s);ze(n,!0,!0);let f=Oo(n,void 0);if(l&&!o)l[1][l[0]]=f}if(ze(n,!0),n.p<t.length&&(s=t.charCodeAt(n.p))!==10&&(s!==13||t.charCodeAt(n.p+1)!==10))K.x("each key-value declaration must be followed by an end-of-line",n);ze(n)}return r}/*!
190
+ */function Ww(t,e,n,r,i){let o=n,s=r,a,c=!1,u;for(let l=0;l<e.length;l++){if(l){if(o=c?o[a]:o[a]=Object.create(null),s=(u=s[a]).c,i===0&&(u.t===1||u.t===2))return null;if(u.t===2){let d=o.length-1;o=o[d],s=s[d].c}}if(a=e[l],(c=Object.hasOwn(o,a))&&s[a]?.t===0&&s[a]?.d)return null;if(!c){let d=a==="__proto__";if(t.uk&&(d||a==="constructor"))return!1;if(d)Object.defineProperty(o,a,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(s,a,{enumerable:!0,configurable:!0,writable:!0});s[a]={t:l<e.length-1&&i===2?3:i,d:!1,i:0,c:Object.create(null)}}}if(u=s[a],u.t!==i&&!(i===1&&u.t===3))return null;if(i===2){if(!u.d)u.d=!0,o[a]=[];o[a].push(o=Object.create(null)),u.c[u.i++]=u={t:1,d:!1,i:0,c:Object.create(null)}}if(u.d)return null;if(u.d=!0,i===1)o=c?o[a]:o[a]=Object.create(null);else if(i===0&&c)return null;return[a,o,u.c]}function Kw(t,e,n){if(e===null||t.uk===2)D.x(e===null?"trying to redefine an already defined table or value":"document contains an unsafe property",t,n)}function wi(t,e={}){let n={s:t,p:0,d:e.maxDepth??1000,bi:e.integersAsBigInt??!1,ld:e.useLegacyDate??!0,uk:e.unsafeKeyBehaviour==="throw"?2:e.unsafeKeyBehaviour==="drop"?1:0},r=Object.create(null),i=Object.create(null),o,s=!1,a=r,c=i;if(t.charCodeAt(0)===65279)n.p++;Ze(n);while(n.p<t.length){if(t.charCodeAt(n.p)===91){let u=t.charCodeAt(++n.p)===91;o=n.p+=+u,s=!1;let l=Hc(n,93);if(u){if(t.charCodeAt(n.p)!==93)D.x("expected end of table array declaration",n);n.p++}let d=Ww(n,l,r,i,u?2:1);if(!d)Kw(n,d,o),s=!0;else c=d[2],a=d[1]}else{o=n.p;let u=Hc(n),l=Ww(n,u,a,c,0);if(!l&&!s)Kw(n,l,o);Ze(n,!0,!0);let d=Ks(n,void 0);if(l&&!s)l[1][l[0]]=d}if(Ze(n,!0),n.p<t.length&&(o=t.charCodeAt(n.p))!==10&&(o!==13||t.charCodeAt(n.p+1)!==10))D.x("each key-value declaration must be followed by an end-of-line",n);Ze(n)}return r}/*!
191
191
  * Copyright (c) Squirrel Chat et al., All rights reserved.
192
192
  * SPDX-License-Identifier: BSD-3-Clause
193
193
  *
@@ -213,7 +213,7 @@ ${i}`,e);this.line=n,this.column=r,this.codeblock=i}static x(t,e,n){throw new K(
213
213
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
214
214
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
215
215
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
216
- */var P8=!!"".isWellFormed;/*!
216
+ */var kj=!!"".isWellFormed;/*!
217
217
  * Copyright (c) Squirrel Chat et al., All rights reserved.
218
218
  * SPDX-License-Identifier: BSD-3-Clause
219
219
  *
@@ -239,168 +239,168 @@ ${i}`,e);this.line=n,this.column=r,this.codeblock=i}static x(t,e,n){throw new K(
239
239
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
240
240
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
241
241
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
242
- */var Ut=["top-left","top-center","top-right","center-left","center","center-right","bottom-left","bottom-center","bottom-right"],xo="Original",zI=1e6,dn="_groups.toml",Vb=3,Zb=8,Sf="[a-z0-9]+(?:-[a-z0-9]+)*",DI=new RegExp(`^(?:(${Sf})@(${Sf})/)?(${Sf})$`),ew=["background","foreground","cursor","selection"];function it(t,e){throw Error(`${t}: ${e}`)}function ci(t,e,n){if(typeof n!=="string"||!oe(n))it(t,`${e} must be "#rrggbb" (lowercase), got ${JSON.stringify(n)}`);return n}function Ro(t,e,n){if(typeof n!=="string"||n.length===0)it(t,`${e} must be a non-empty string`);return n}function Xt(t){return t.replace("@","--").replace("/","--")}function H(t){return`ttheme-${Xt(t)}`}function lt(t){let e=t.indexOf("/");return e<0?void 0:t.slice(0,e)}function ae(t){return t.slice(t.indexOf("/")+1)}function ve(t){let e=DI.exec(t);if(!e)return"takes lowercase letters, digits and single hyphens, as <palette> or <owner>@<market>/<palette>";if((e[1]?.length??0)>39)return"has an owner longer than a GitHub handle can be";return(e[2]?.length??0)>40||(e[3]?.length??0)>40?"is longer than 40 characters":void 0}function No(t){if(/[\p{Cc}"$`\\]/u.test(t))return"holds a control character, a quote, $, ` or \\";return t.length>80?"is longer than 80 characters":void 0}function Io(t,e,n){let r=Ro(t,e,n),i=No(r);if(i)it(t,`${e} ${JSON.stringify(r)} ${i}`);return r}function Qb(t,e,n){let r=Ro(t,e,n),i=ve(r);if(i)it(t,`${e} "${r}" ${i}`);return r}function ds(t){return t&&typeof t==="object"?t:{}}function qI(t,e,n){if(e===void 0)return[n.cursor,n.selectionBackground,n.background];let r=Array.isArray(e)?e:[e];if(r.length===0)it(t,"ghostty.icon_screen must not be empty");return r.map((i,s)=>ci(t,`ghostty.icon_screen[${s}]`,i))}function YI(t,e,n){let r=ds(e);return{iconGhost:r.icon_ghost===void 0?n.cursor:ci(t,"ghostty.icon_ghost",r.icon_ghost),iconScreen:qI(t,r.icon_screen,n)}}function JI(t){return new Map([...ew.map((e)=>[e,t[e]]),...t.ansi.map((e,n)=>[`ansi${n}`,e])])}function VI(t,e,n){if(!Array.isArray(e)||e.length!==Vb)it(t,`meta.signature must name exactly ${Vb} palette slots`);let r=JI(n),i=[],s=[];for(let[o,a]of e.entries()){let c=`meta.signature[${o}]`,u=Ro(t,c,a),l=r.get(u);if(l===void 0)it(t,`${c} ${JSON.stringify(a)} is not a palette slot — use ${ew.join(", ")} or ansi0-ansi15`);i.push(u),s.push(l)}if(new Set(s).size!==s.length)it(t,"meta.signature slots must resolve to three different colors");return{names:i,colors:s}}function ZI(t,e,n,r=!1){if(e===void 0)return;if(!n)it(t,"meta.booru_sites renames meta.booru per site, so it needs meta.booru");if(!e||typeof e!=="object"||Array.isArray(e))it(t,'meta.booru_sites must be a table of site = "tag" or site = ["tag", ...]');let i={};for(let[s,o]of Object.entries(e)){let a=Y.find((u)=>u.key===s);if(!a){if(r)continue;it(t,`meta.booru_sites.${s} is not a find site — use ${Y.map((u)=>u.key).join(", ")}`)}let c=typeof o==="string"?[o]:Array.isArray(o)?o:void 0;if(!c||c.some((u)=>typeof u!=="string"||u===""||/\s/.test(u)))it(t,`meta.booru_sites.${s} must be one tag or a list of tags, got ${JSON.stringify(o)}`);if(c.length>1&&!a.ors)it(t,`meta.booru_sites.${s} takes one tag — ${a.name} does not OR tags`);if(c.length>a.tagBudget)it(t,`meta.booru_sites.${s} takes ${a.tagBudget} tags at most — ${a.name} searches that many at a time`);i[s]=c}return i}function QI(t,e,n){if(e===void 0)return;if(!Array.isArray(e)||e.length===0||e.length>Zb)it(t,`[[picture]] holds 1 to ${Zb} pictures`);let r=e.flatMap((i,s)=>{let o=ds(i),a=`picture[${s}]`,c=Y.find((h)=>h.key===o.site);if(!c){if(n)return[];it(t,`${a}.site must be one of ${Y.map((h)=>h.key).join(", ")}`)}if(typeof o.id!=="number"||!Number.isSafeInteger(o.id)||o.id<=0)it(t,`${a}.id must be the post's number on ${c.name}`);let{size:u,position:l,opacity:f}=o;if(u!==void 0&&u!=="fill"&&!(Number.isInteger(u)&&Number(u)>=20&&Number(u)<=999))it(t,`${a}.size must be "fill" or a percentage from 20 to 999`);let d=l===void 0||Ut.includes(l);if(!d&&!n)it(t,`${a}.position must be one of ${Ut.join(", ")}`);if(f!==void 0&&!(typeof f==="number"&&f>=0&&f<=1))it(t,`${a}.opacity must be a number from 0 to 1`);return[{site:c.key,id:o.id,...u!==void 0?{size:u}:{},...l!==void 0&&d?{position:l}:{},...f!==void 0?{opacity:f}:{}}]});return r.length>0?r:void 0}function Of(t,e){try{return ai(e)}catch(n){it(t,`is not valid TOML — ${(n instanceof Error?n.message:String(n)).split(`
243
- `)[0]}`)}}function XI(t){let n=Of(dn,Xb(tw(t,dn),"utf8")).group;if(!Array.isArray(n)||n.length===0)it(dn,"needs at least one [[group]] table");return n.map((r)=>{let i=ds(r);return{name:Io(dn,"group.name",i.name),native:i.native===void 0?void 0:Io(dn,"group.native",i.native),lead:Ro(dn,"group.lead",i.lead)}})}function t2(t,e){if(!Array.isArray(e)||e.length===0)it(t,'meta.native_names must be a list of names, like ["後藤ひとり"]');return e.map((n,r)=>{let i=Io(t,`meta.native_names[${r}]`,n);if(i.includes("|"))it(t,`meta.native_names[${r}] ${JSON.stringify(i)} contains |`);return i})}var Mf={"":["$schema","meta","colors","contrast","ghostty","picture"],meta:["name","base","group","ansi_source","booru","booru_sites","native_names","signature","order","role"],colors:["background","foreground","cursor","selection_background","ansi"],contrast:["waive","reason"],ghostty:["icon_ghost","icon_screen"],picture:["site","id","size","position","opacity"]};function nw(t,e){let n=Of(t,e),r=(i,s,o=[])=>s&&typeof s==="object"&&!Array.isArray(s)?Object.keys(s).filter((a)=>!o.includes(a)).map((a)=>i?`${i}.${a}`:a):[];return[...r("",n,Mf[""]),...["meta","colors","contrast","ghostty"].flatMap((i)=>r(i,n[i],Mf[i])),...(Array.isArray(n.picture)?n.picture:[]).flatMap((i,s)=>r(`picture[${s}]`,i,Mf.picture))]}function xf(t,e,n){let r=Of(t,e),i=ds(r.meta),s=ds(r.colors),o=ds(r.contrast),a=s.ansi;if(!Array.isArray(a)||a.length!==16)it(t,`colors.ansi must hold exactly 16 colors, got ${Array.isArray(a)?a.length:typeof a}`);let c=Qb(t,"meta.name",i.name);if(c!==n.name)it(t,`meta.name "${c}" does not match its file — it lives at ${n.name}`);let u=n.open===!0;for(let B of["order","role"])if(u&&i[B]!==void 0)it(t,`meta.${B} is for the official palettes — a market palette follows its base`);let l=i.role;if(l!==void 0&&l!=="default")it(t,`meta.role must be "default", got ${JSON.stringify(l)}`);let f=i.base===void 0?void 0:Qb(t,"meta.base",i.base);if(f!==void 0&&!u)it(t,"meta.base is for market palettes");let d=f===void 0?void 0:n.bases?.get(f),h=u&&i.group===void 0?d?.group??xo:Io(t,"meta.group",i.group),m=n.groups.get(h);if(!m&&!(u&&(h===xo||n.open)))it(t,`meta.group "${h}" has no [[group]] table in ${dn}`);let $=ci(t,"colors.background",s.background),g=ci(t,"colors.foreground",s.foreground),b=ci(t,"colors.cursor",s.cursor),y=ci(t,"colors.selection_background",s.selection_background),E=a.map((B,tt)=>ci(t,`colors.ansi[${tt}]`,B)),S=VI(t,i.signature,{background:$,foreground:g,cursor:b,selection:y,ansi:E}),x=i.booru===void 0?void 0:Ro(t,"meta.booru",i.booru);if(x!==void 0&&/[\s\p{Cc}]/u.test(x))it(t,`meta.booru must be a single booru tag, got ${JSON.stringify(x)}`);let R=ZI(t,i.booru_sites,x,n.foreign===!0),N=i.native_names===void 0?void 0:t2(t,i.native_names),F=Array.isArray(o.waive)?o.waive.map(String):[];if(F.length>0&&typeof o.reason!=="string")it(t,"contrast.waive needs a contrast.reason explaining why");let _=QI(t,r.picture,n.foreign===!0);return{name:c,...f?{base:f}:{},group:h,native:m?.native,...N?{nativeNames:N}:{},lead:!u&&m?.lead===c,order:u?d?.order??zI:Number(i.order),role:l,ansiSource:u&&i.ansi_source===void 0?f??"original":Io(t,"meta.ansi_source",i.ansi_source),...x?{booru:x}:{},...R?{booruSites:R}:{},background:$,foreground:g,cursor:b,selectionBackground:y,ansi:E,signature:S.colors,signatureSlots:S.names,ghostty:YI(t,r.ghostty,{background:$,cursor:b,selectionBackground:y}),waive:F,waiveReason:typeof o.reason==="string"?o.reason:void 0,..._?{pictures:_}:{}}}function rw(t){let e=XI(t),n=new Map(e.map((s)=>[s.name,s]));if(n.size!==e.length)it(dn,"group.name must be unique");let r=WI(t).filter((s)=>s.endsWith(".toml")&&!s.startsWith("_")).map((s)=>xf(s,Xb(tw(t,s),"utf8"),{name:KI(s,".toml"),groups:n})).sort((s,o)=>s.order-o.order);if(new Set(r.map((s)=>s.order)).size!==r.length)throw Error("themes: meta.order must be unique across all themes");for(let s of e){let o=r.filter((a)=>a.group===s.name);if(o.length===0)it(dn,`group "${s.name}" has no themes`);if(!o.some((a)=>a.name===s.lead))it(dn,`group "${s.name}" lead "${s.lead}" is not one of its themes`)}return r}function iw(t){return t.filter((e)=>e.role===void 0)}function ui(t){let e=(r,i)=>r<i?-1:r>i?1:0,n=(r)=>lt(r.name)?r.name:r.base??r.name;return[...t].sort((r,i)=>Number(lt(r.name)!==void 0)-Number(lt(i.name)!==void 0)||e(r.group.toLowerCase(),i.group.toLowerCase())||Number(r.catalog===void 0)-Number(i.catalog===void 0)||e((r.catalog??"").toLowerCase(),(i.catalog??"").toLowerCase())||e(n(r),n(i))||Number(r.base!==void 0)-Number(i.base!==void 0)||e(r.name,i.name))}var To={width:2560,height:1550},o2=1,a2=2560,c2=0.1,mw=0.99,u2=2,li={tall:1.15,reach:0.4,widest:0.95,headroom:0.04,margin:0.03,stands:12},l2=vt(Bt("#19161e","#9b86c8",0.2)),f2="shelf",uc="originals",d2="images.json",Rf=1;function h2(t,e){if(e==="background"||e==="foreground"||e==="cursor")return t[e];if(e==="selection"&&t.selection)return t.selection;let n=/^ansi(\d|1[0-5])$/.exec(e),r=n?t.ansi[Number(n[1])]:void 0;if(!r)throw Error(`${t.name} has no slot ${e}`);return r}function sw(t){if(t(1))return 1;let e=0,n=1;for(let r=0;r<40;r++){let i=(e+n)/2;if(t(i))e=i;else n=i}return e}function pw(t,e){let r=sw((s)=>Vp({name:t.name,background:Bt(t.background,e,s),foreground:t.foreground,ansi:t.ansi,waive:t.waived??[]}).length===0),i=sw((s)=>vt(Bt(t.background,e,s))<=l2);return{cap:r,matched:i,opacity:Math.floor(Math.min(r,i)*100)/100}}function ow(t,e){let n=h2(t,e),{cap:r,matched:i,opacity:s}=pw(t,n),o=rt(t.background),a=Math.hypot(...rt(n).map((c,u)=>(c-(o[u]??0))*s));return{slot:e,color:n,cap:r,matched:i,opacity:s,reach:a}}function ps(t,e){return pw(t,e).opacity}function hn(t,e){let n=ow(t,"cursor");if(n.opacity>=c2)return n;return e.filter((r)=>r!=="cursor"&&r!=="background").map((r)=>ow(t,r)).reduce((r,i)=>i.reach>r.reach?i:r,n)}function m2(t){return ib(t)??{x:0,y:0,w:t.width,h:t.height}}function Ff(t,e){if(t<=0||e<=0)return To;let n=Math.min(1,To.width/Math.max(t,e));return{width:Math.round(t*n),height:Math.round(e*n)}}function gw(t,e,n,r){if(r<li.stands){let c=t.w*n>t.h*e?{x:t.x+(t.w-t.h*e/n)/2,y:t.y,w:t.h*e/n,h:t.h}:{x:t.x,y:t.y,w:t.w,h:t.w*n/e};return{crop:c,at:{x:0,y:0,w:e,h:n},focus:(c.y-t.y+c.h/2)/t.h}}let i=Math.max(li.tall*n,li.reach*e*t.h/t.w),s=i*t.w/t.h;if(s>li.widest*e)s=li.widest*e,i=s*t.h/t.w;let o=li.headroom*n,a=Math.min(1,(n-o)/i);return{crop:{x:t.x,y:t.y,w:t.w,h:t.h*a},at:{x:e*(1-li.margin)-s,y:o,w:s,h:i*a},focus:Math.min(1,(n/2-o)/i)}}function p2(t,e){return 0.299*(t[e]??0)+0.587*(t[e+1]??0)+0.114*(t[e+2]??0)}function g2(t,e){let n=new Uint32Array(256),r=Math.max(1,Math.floor(e.w*e.h/400000)),i=0;for(let o=0;o<e.w*e.h;o+=r){let a=((e.y+Math.floor(o/e.w))*t.width+e.x+o%e.w)*4;if((t.data[a+3]??0)>=128){let c=Math.round(p2(t.data,a));n[c]=(n[c]??0)+1,i++}}let s=0;for(let o=0;o<256&&i>0;o++)if(s+=n[o]??0,s>=i*mw)return Math.min(u2,Math.max(1,255/Math.max(1,o)));return 1}var If=Float64Array.from({length:256},(t,e)=>{let n=e/255;return n<=0.04045?n/12.92:((n+0.055)/1.055)**2.4});function b2(t,e,n){return`#${[t,e,n].map((r)=>Math.round(r).toString(16).padStart(2,"0")).join("")}`}function w2(t,e){let n=new Uint32Array(256),r=new Float64Array(768),i=Math.max(1,Math.floor(e.w*e.h/400000)),s=0;for(let a=0;a<e.w*e.h;a+=i){let c=((e.y+Math.floor(a/e.w))*t.width+e.x+a%e.w)*4;if((t.data[c+3]??0)>=128){let u=t.data[c]??0,l=t.data[c+1]??0,f=t.data[c+2]??0,d=Math.round(255*Math.sqrt(0.2126*(If[u]??0)+0.7152*(If[l]??0)+0.0722*(If[f]??0)));n[d]=(n[d]??0)+1,r[d*3]=(r[d*3]??0)+u,r[d*3+1]=(r[d*3+1]??0)+l,r[d*3+2]=(r[d*3+2]??0)+f,s++}}let o=0;for(let a=0;a<256&&s>0;a++)if(o+=n[a]??0,o>=s*mw){let c=Math.max(1,n[a]??1);return b2((r[a*3]??0)/c,(r[a*3+1]??0)/c,(r[a*3+2]??0)/c)}return"#ffffff"}function $2(t,e){let n=t.data,r=new Uint8Array(t.width*t.height);for(let i=0,s=0;i<r.length;i++,s+=4){let o=n[s+3];if(o===0)continue;let a=(0.299*n[s]+0.587*n[s+1]+0.114*n[s+2])*e;r[i]=(a>255?255:a)*o/255+0.5}return{width:t.width,height:t.height,data:r}}function bw(t,e,n){let r=Math.max(0,Math.round(t.at.x)),i=Math.max(0,Math.round(t.at.y)),s=Math.min(e,Math.round(t.at.x+t.at.w)),o=Math.min(n,Math.round(t.at.y+t.at.h));if(s<=r||o<=i)return;let a=t.crop.w/t.at.w,c=t.crop.h/t.at.h;return{x0:r,y0:i,x1:s,y1:o,box:{x:t.crop.x+(r-t.at.x)*a,y:t.crop.y+(i-t.at.y)*c,w:(s-r)*a,h:(o-i)*c}}}function ac(t,e,n,r){let i=new Float32Array(n*r),s=bw(e,n,r);if(s){let o=cb(t,s.box,s.x1-s.x0,s.y1-s.y0);for(let a=s.y0;a<s.y1;a++)i.set(o.data.subarray((a-s.y0)*(s.x1-s.x0),(a-s.y0+1)*(s.x1-s.x0)),a*n+s.x0)}return{width:n,height:r,data:i}}function Cf(t,e,n,r){let i=new Uint8Array(n*r*4),s=bw(e,n,r);if(s){let o=s.x1-s.x0,a=mo(t,s.box,o,s.y1-s.y0);for(let c=s.y0;c<s.y1;c++)i.set(a.data.subarray((c-s.y0)*o*4,(c-s.y0+1)*o*4),(c*n+s.x0)*4)}return{width:n,height:r,data:i}}function Nf(t,e){if(e<=0)return t;let{width:n,height:r}=t,i=[0,1,2,3].map(()=>({width:n,height:r,data:new Float32Array(n*r)}));for(let a=0;a<n*r;a++){let c=t.data[a*4+3]??0;for(let u=0;u<3;u++)i[u].data[a]=(t.data[a*4+u]??0)*c/255;i[3].data[a]=c}let s=i.map((a)=>po(a,e).data),o=new Uint8Array(n*r*4);for(let a=0;a<n*r;a++){let c=s[3]?.[a]??0;if(c<=0)continue;for(let u=0;u<3;u++)o[a*4+u]=Math.min(255,Math.max(0,Math.round((s[u]?.[a]??0)*255/c)));o[a*4+3]=Math.min(255,Math.round(c))}return{width:n,height:r,data:o}}function Lf(t){let e=m2(t),n,r;return{box:e,clear:Tn(t,e),get ink(){return n??=$2(t,g2(t,e)),n},image:t,get peak(){return r??=w2(t,e),r}}}function ww(t,e,n,r,i){let s=Lf(t),{box:o,clear:a,ink:c}=s,u=gw(o,e,n,a),l=Math.min(1,a2/Math.max(o.w,o.h)),f={x:0,y:0,w:Math.round(o.w*l),h:Math.round(o.h*l)},d=r*f.w*u.crop.w/(o.w*u.at.w);if(i==="original")return{coloring:i,figure:Nf(mo(t,o,f.w,f.h),d),fill:Nf(Cf(t,u,e,n),r),focus:u.focus,peak:s.peak};let h=ac(c,{crop:o,at:f,focus:u.focus},f.w,f.h),m=ac(c,u,e,n);return{coloring:i,figure:go(po(h,d)),fill:go(po(m,r)),focus:u.focus}}function k2(t,e,n,r){let i=rt(e),s=rt(n),o=new Uint8Array(t.width*t.height*4);for(let a=0;a<t.data.length;a++){let c=(t.data[a]??0)/255*r;for(let u=0;u<3;u++)o[a*4+u]=Math.round((i[u]??0)+((s[u]??0)-(i[u]??0))*c);o[a*4+3]=255}return{width:t.width,height:t.height,data:o}}function y2(t,e,n){let r=rt(e),i=new Uint8Array(t.width*t.height*4);for(let s=0;s<t.width*t.height;s++){let o=(t.data[s*4+3]??0)/255*n;for(let a=0;a<3;a++)i[s*4+a]=Math.round((r[a]??0)+((t.data[s*4+a]??0)-(r[a]??0))*o);i[s*4+3]=255}return{width:t.width,height:t.height,data:i}}function $w(t,e,n,r,i,s,o,a="tone"){let{box:c,clear:u,ink:l}=t,f=gw(c,r,i,u),d=Math.round(100*f.at.w/f.crop.w/Math.min(r/c.w,i/c.h)),h=o?.size??"fill",m=h==="fill"?f:{crop:c,at:ws(c.w,c.h,r,i,h,o?.at??5,!1,h>100?Math.round(f.focus*100):-1),focus:f.focus},$=a==="original"?ps(e,t.peak):n.opacity,g=o?.opacity??$;return{image:a==="original"?y2(Nf(Cf(t.image,m,r,i),s),e.background,g):k2(go(po(ac(l,m,r,i),s)),e.background,n.color,g),fill:d,opacity:$}}function q(t){return D(t,"ttheme","backgrounds")}function Tf(t){return D(t,d2)}function gr(t){try{return ms(t,"utf8")}catch{return}}function pr(t){try{return r2(t)}catch{return[]}}function kt(t){let e=gr(Tf(t));if(e===void 0)return v2(t);let n=JSON.parse(e);if(n.version!==Rf)throw Error(`${Tf(t)} is version ${n.version} — this ttheme reads version ${Rf}`);return n}function Ee(t){return t.coloring??"tone"}function jf(t){return{name:t.name,background:t.background,foreground:t.foreground,cursor:t.cursor,...t.selection?{selection:t.selection}:{},ansi:t.ansi,...t.waived?{waived:t.waived}:{}}}function br(t){return{hue:{color:t.backdrop.color,opacity:t.backdrop.opacity},colors:jf(t)}}function gs(t){return t.tone===void 0&&Ee(t)==="tone"}function aw(t){return(t.artist??[]).map((e)=>e.replace(/[\s,]+/g,"_")).join(",")}function kw(t,e){let n=e.pictures.findIndex((i)=>i.key===e.active),r=e.pictures[n];return[...r.artist?.length?[`# by ${aw(r)}`]:[],...r.from?[`# from ${r.from}`]:[],`# image ${r.key} ${n+1}/${e.pictures.length}`,...e.pictures.map((i)=>[`# picture ${i.key} ${i.stem} ${i.fill} ${i.opacity} ${i.artist?.length?aw(i):"-"}`,...i.from?[i.from]:[]].join(" ")),...e.pictures.filter((i)=>Ee(i)==="original").map((i)=>`# colors ${i.key} original`),`background-image = ${D(t,r.fill)}`,"background-image-fit = cover","background-image-position = top-right",`background-image-opacity = ${r.opacity}`,`config-file = ?${r.stem}.tune.conf`,`config-file = ?${r.stem}.off.conf`,""].join(`
244
- `)}function yw(t){let e=q(t);for(let[n,r]of Object.entries(kt(e).palettes)){let i=D(e,`${Xt(n)}.conf`),s=kw(e,r);if(gr(i)!==s)P(i,s)}}function fi(t,e,n){P(Tf(t),`${JSON.stringify(e,null,2)}
245
- `);for(let r of n){let i=e.palettes[r],s=D(t,`${Xt(r)}.conf`);if(i)P(s,kw(t,i));else hs(s,{force:!0})}}function vw(t,e){let n=q(t),r=kt(n),i=[];for(let[s,o]of e){let a=r.palettes[s];if(a&&!r.palettes[o])r.palettes[o]=a,delete r.palettes[s],i.push(s,o)}if(i.length>0)fi(n,r,i)}function Ew(t,e){return pr(t).filter((n)=>n.startsWith(`${e}.`)||n.startsWith(`${e}@`))}function _f(t,e){for(let n of Ew(t,e))hs(D(t,n),{force:!0})}function Sw(t,e){_f(t,e.stem);for(let n of[e.original,e.cut])if(n)hs(D(t,n),{force:!0})}function cw(t,e,n,r){let i=hw(/^background-image\s*=\s*(.*?)\s*$/m.exec(e??"")?.[1]??"");if(!i.startsWith(`${t}.`)||!/^\.[0-9a-f]{8}@fill-\d+\.png$/.test(i.slice(t.length)))return;let s=i.slice(0,i.indexOf("@")),o=r??/^# image (\S+)$/m.exec(e??"")?.[1]??`picture_${s.slice(t.length+1)}`,a=/^# from (.+)$/m.exec(e??"")?.[1],c=Number(/^background-image-opacity\s*=\s*(\S+)/m.exec(e??"")?.[1]??1),u=n.find((l)=>l.startsWith(`${t}-${o}.`));return{key:o,stem:s,fill:i,opacity:Number.isFinite(c)?c:1,...a?{from:a}:{},...u?{original:D(uc,u)}:{}}}function uw(t,e){if(Hf(t))dw(t,e)}function v2(t){let e={version:Rf,palettes:{}};if(!Hf(t))return e;let n=pr(D(t,uc)),r=pr(t).filter((s)=>s.endsWith(".conf")&&s!=="shown.conf"&&!/\.(tune|off)\.conf$/.test(s)).map((s)=>s.slice(0,-5)),i=D(t,f2);for(let s of new Set([...r,...pr(i)])){let o=[],a=cw(s,gr(D(t,`${s}.conf`)),n);if(a)uw(D(t,`${s}.tune.conf`),D(t,`${a.stem}.tune.conf`)),uw(D(t,`${s}.off.conf`),D(t,`${a.stem}.off.conf`)),o.push(a);for(let c of pr(D(i,s))){let u=D(i,s,c),l=cw(s,gr(D(u,".conf")),n,c);if(!l)continue;for(let f of pr(u)){let d=f===".tune.conf"||f===".off.conf"?`${l.stem}${f}`:`${s}${f}`;if(f!==".conf")dw(D(u,f),D(t,d))}hs(u,{recursive:!0}),o.push(l)}if(pr(D(i,s)).length===0)hs(D(i,s),{recursive:!0,force:!0});if(o.length>0)o.sort((c,u)=>c.key<u.key?-1:c.key>u.key?1:0),e.palettes[s]={active:(a??o[0]).key,pictures:o}}if(pr(i).length===0)hs(i,{recursive:!0,force:!0});return fi(t,e,Object.keys(e.palettes)),e}function lw(t,e,n){return e.startsWith("~/")?D(n,e.slice(2)):s2(e)?e:D(t,e)}function Se(t,e,n){let r=new Map,i=(a,c)=>{let u=gr(a);if(u===void 0)return!1;for(let l of u.split(`
246
- `)){let f=/^([a-z-]+)\s*=\s*(.*?)\s*$/.exec(l);if(f?.[1]==="config-file"&&c<4)i(lw(t,f[2].replace(/^\?/,""),n),c+1);else if(f&&/^background-image(?:-fit|-opacity|-position)?$/.test(f[1]))r.set(f[1],f[2])}return!0};if(!i(D(t,`${Xt(e)}.conf`),0))return;let s=r.get("background-image")??"";if(s==="")return;let o=Number(r.get("background-image-opacity")??1);return{image:lw(t,s,n),opacity:Number.isFinite(o)?o:1,cover:r.get("background-image-fit")==="cover",position:r.get("background-image-position")??"center"}}function te(t){return`${t.site}_${t.id}`}function lc(t,e,n){let r=q(t),i=kt(r),s=i.palettes[e];if(!s)throw Error(`${e} has no image`);let o=s.pictures.findIndex((u)=>u.key===(n??s.active));if(o===-1)throw Error(`${e} has no picture ${n}`);let[a]=s.pictures.splice(o,1);Sw(r,a);let c=s.pictures[o%Math.max(s.pictures.length,1)];if(!c)delete i.palettes[e];else if(a.key===s.active)s.active=c.key;return fi(r,i,[e]),{key:a.key,left:s.pictures.length}}function Mw(t,e,n,r){let i=n.coloring==="original"?ln(n.figure):ri(n.figure,r),s=n.coloring==="original"?ln(n.fill):ri(n.fill,r),o=`${Xt(t)}.${fw("sha1").update(e).update(i).update(s).digest("hex").slice(0,8)}`,a=`${o}@fill-${Math.round(n.focus*100)}.png`;return{stem:o,fill:a,files:[[`${o}.png`,i],[a,s]]}}function Ow(t,e,n,r){return n==="original"&&r?{coloring:"original",opacity:ps(t,r),peak:r}:{coloring:"tone",opacity:e.opacity,tone:e.color}}function Af(t,e){return D(uc,`${Xt(t)}-${e}`)}function Gf(t,e){return e.map(([n,r])=>{let i=D(t,n);return P(i,r),i})}function fc(t,e,n,r,i,s,o,a="tone"){let c=q(t),u=e.name,l=te(i),f=kt(c),d=f.palettes[u]??{active:l,pictures:[]},h=Ff(s.width,s.height),m=ww(r,h.width,h.height,o,a),$=Mw(u,l,m,n.color),g=Af(u,l),b={key:l,stem:$.stem,fill:$.fill,...Ow(e,n,m.coloring,m.coloring==="original"?m.peak:void 0),blur:o,window:h,...i.from?{from:i.from}:{},...i.artist?.length?{artist:i.artist}:{},...i.source?{source:i.source}:{},original:`${g}.${i.ext}`,...i.cut?{cut:`${g}.cut.png`}:{}},y=d.pictures.find((S)=>S.key===l);if(y)Sw(c,y);n2(D(c,uc),{recursive:!0});let E=Gf(c,[...$.files,[b.original,i.bytes],...b.cut?[[b.cut,lf(ni(r))]]:[]]);return d.pictures=y?d.pictures.map((S)=>S===y?b:S):[...d.pictures,b],d.active=l,f.palettes[u]=d,fi(c,f,[u]),[...E,D(c,`${Xt(u)}.conf`)]}function bs(t,e,n){let r=q(t),i=kt(r),s=i.palettes[e],o=s?s.pictures.findIndex((a)=>a.key===n):-1;if(!s||o===-1)throw Error(`${e} has no picture ${n}`);if(s.active!==n)s.active=n,fi(r,i,[e]);return{at:o+1,of:s.pictures.length}}function ce(t,e){let n=kt(q(t)).palettes[e];if(!n)return[];return[...n.pictures.filter((i)=>i.key===n.active),...n.pictures.filter((i)=>i.key!==n.active)]}var Pf="top-right";function ws(t,e,n,r,i,s,o,a=-1){let c=Math.trunc,u=(s-1)%3,l=c((s-1)/3),f=n*e>=r*t!==!o,d=f?c(i*n/100):c(i*r*t/(100*e)),h=f?c(i*n*e/(100*t)):c(i*r/100),m=c(u*(n-d)/2),$=c(l*(r-h)/2);if(a>=0){if(d>n)m=c((n-d)/2);if(h>r)$=Math.max(r-h,Math.min(0,c(r/2)-c(a*h/100)))}return{x:m,y:$,w:d,h}}function Bf(t,e){let n=gr(D(t,`${e.stem}.tune.conf`));if(n===void 0)return{};let r=(u)=>new RegExp(`^${u}\\s*=\\s*(.*?)\\s*$`,"m").exec(n)?.[1]??"",i=hw(r("background-image")),s=/@(\d+)-/.exec(i)?.[1],o=/@fill-\d+\.png$/.test(i)?"fill":s?Number(s):r("background-image-fit")==="cover"?"fill":100,a=r("background-image-position").replace("center-center","center")||"center",c=Number(r("background-image-opacity")||1);return{...o!=="fill"?{size:o}:{},...a!==Pf?{position:a}:{},...Number.isFinite(c)&&c!==e.opacity?{opacity:c}:{}}}function Ao(t,e,n,r,i){let s=n.size??"fill",o=n.position??Pf,a=n.opacity??e.opacity;if(s==="fill"&&o===Pf&&a===e.opacity)return;let c=Ut.indexOf(o)+1,u=D(t,`${e.stem}.png`),l=D(t,e.fill),f=!0,d=typeof s==="number"&&(s>100||!r&&o!=="center");if(s===100&&!d)l=u,f=!1;else if(typeof s==="number"){if(gs(e))throw Error(`${e.stem} was drawn before pictures kept their tone — init draws it again`);let m=Ht(new Uint8Array(ms(u))),{width:$,height:g}=d?To:m,b=d?Number(/@fill-(\d+)\.png$/.exec(e.fill)?.[1]??50):-1,y=ws(m.width,m.height,$,g,s,c,!1,b);l=D(t,`${e.stem}@${s}-${o}${d?`-${$}x${g}`:""}.png`);let S={crop:{x:0,y:0,w:m.width,h:m.height},at:y,focus:b};P(l,e.tone?ri(go(ac(ni(m),S,$,g)),e.tone):ln(Cf(m,S,$,g))),f=d}let h=D(t,`${e.stem}.tune.conf`);return P(h,[`background-image = ${l.startsWith(`${i}/`)?`~${l.slice(i.length)}`:l}`,`background-image-fit = ${f?"cover":"contain"}`,`background-image-position = ${o}`,`background-image-opacity = ${a}`,""].join(`
247
- `)),h}function xw(t){let e=new Map;for(let[n,r]of Object.entries(kt(q(t)).palettes)){let[,i,s]=/^([a-z.]+)_(\d+)$/.exec(r.active)??[];if(i&&s)e.set(n,{site:i,id:Number(s)})}return e}function Iw(t){try{let e=un(new Uint8Array(ms(t)));return e?{width:e.width,height:e.height}:void 0}catch{return}}function Rw(t,e,n,r,i,s,o){let a=[n.original,n.cut].map((c)=>{if(!c)return"";try{let{size:u,mtimeMs:l}=i2(D(t,c));return`${c}:${u}:${l}`}catch{return}});if(!n.original||a.includes(void 0))return;return Ub([o2,Xt(e),n.key,...a,r.width,r.height,i,s,s==="tone"?o:""])}function E2(t,e,n){if(!n.window||n.blur===void 0)return;let r=Rw(t,e,n,n.window,n.blur,Ee(n),n.tone??"");if(!r||Wb(r))return;try{yf(r,{stem:n.stem,fill:n.fill,...n.peak?{peak:n.peak}:{},figure:ms(D(t,`${n.stem}.png`)),picture:ms(D(t,n.fill))})}catch{}}function Nw(t,e,n,r,i,s,o,a,c){let u=c?void 0:Rw(t,e,n,r,o,a,s.hue.color),l=u?Kb(u):void 0;if(l)return{made:{stem:l.stem,fill:l.fill,files:[[`${l.stem}.png`,l.figure],[l.fill,l.picture]]},peak:l.peak,image:void 0};let f=i();if(!f)return null;let d=ww(f,r.width,r.height,o,a),h=Mw(e,n.key,d,s.hue.color),m=d.coloring==="original"?d.peak:void 0;if(u)yf(u,{stem:h.stem,fill:h.fill,...m?{peak:m}:{},figure:h.files[0]?.[1],picture:h.files[1]?.[1]});return{made:h,peak:m,image:f}}function Po(t,e,n,r,i,s,o,a,c,u=Ee(n)){let l=q(t),f=n.window??Iw(D(l,n.fill))??To,d=Nw(l,e,n,f,r,i,s,u,c);if(!d)return null;let{made:h,peak:m,image:$}=d,g={...n,stem:h.stem,fill:h.fill,...Ow(i.colors,i.hue,u,m),blur:s,window:f,...c?{cut:`${Af(e,n.key)}.cut.png`}:{}};if(u==="original")delete g.tone;else delete g.peak;if(c&&$)P(D(l,`${Af(e,n.key)}.cut.png`),lf(ni($)));if(h.stem===n.stem)return g;if(Ee(n)!==u)E2(l,e,n);Gf(l,h.files);let b=Bf(l,n);Ao(l,g,Ee(n)===u?b:{...b,opacity:void 0},o,a);let y=D(l,`${n.stem}.off.conf`);if(Hf(y))e2(y,D(l,`${g.stem}.off.conf`));return g}function Tw(t,e,n,r,i,s,o){let a=q(t),c=n.window??Iw(D(a,n.fill))??To;return Nw(a,e,n,c,r,i,s,o,!1)!==null}function Uf(t,e){let n=q(t),r=kt(n),i=new Set,s=[];for(let{name:o,picture:a}of e){let c=r.palettes[o],u=c?.pictures.findIndex((f)=>f.key===a.key)??-1,l=c?.pictures[u];if(!c||!l)continue;if(c.pictures[u]=a,i.add(o),l.stem!==a.stem)s.push(l.stem)}if(i.size===0)return;fi(n,r,[...i]);for(let o of s)_f(n,o)}function Aw(t,e,n){return t.replace(/^background-image-opacity = (\S+)$/m,(r,i)=>Number(i)===e?`background-image-opacity = ${n}`:r)}function Pw(t,e,n){let r=D(t,`${e.stem}.tune.conf`),i=gr(r);if(i!==void 0)P(r,Aw(i,e.opacity,n));return{...e,opacity:n}}function S2(t,e,n,r){if(n.tone===r.color)return Pw(t,n,r.opacity);let i=Ew(t,n.stem).filter((a)=>a.endsWith(".png")).map((a)=>{let c=new Uint8Array(ms(D(t,a)));return[a,za(c,r.color)??ri(ni(Ht(c)),r.color)]}),s=(a)=>i.find(([c])=>c===a)?.[1]??new Uint8Array,o=`${Xt(e)}.${fw("sha1").update(n.key).update(s(`${n.stem}.png`)).update(s(n.fill)).digest("hex").slice(0,8)}`;Gf(t,i.map(([a,c])=>[o+a.slice(n.stem.length),c]));for(let a of["tune","off"]){let c=gr(D(t,`${n.stem}.${a}.conf`));if(c!==void 0)P(D(t,`${o}.${a}.conf`),Aw(c.split(n.stem).join(o),n.opacity,r.opacity))}return{...n,stem:o,fill:o+n.fill.slice(n.stem.length),opacity:r.opacity,tone:r.color}}function cc(t,e){if(Ee(t)==="original")return t.peak!==void 0&&ps(e.colors,t.peak)!==t.opacity;return t.tone!==void 0&&(t.tone!==e.hue.color||t.opacity!==e.hue.opacity)}function Hw(t,e){let n=q(t),r=kt(n),i=[],s=[];for(let[o,a]of Object.entries(r.palettes)){let c=e.get(o);if(!c||!a.pictures.some((u)=>cc(u,c)))continue;a.pictures=a.pictures.map((u)=>{if(!cc(u,c))return u;let l=Ee(u)==="original"?Pw(n,u,ps(c.colors,u.peak)):S2(n,o,u,c.hue);if(l.stem!==u.stem)s.push(u.stem);return l}),i.push(o)}if(i.length>0){fi(n,r,i);for(let o of s)_f(n,o)}return i}var Wf=1,Kf="npx @kecan0406/ttheme@latest init";class dc extends Error{}function Fw(t,e,n){if(typeof t!=="number"||!Number.isInteger(t)||t<1)throw Error(`${e} schema is not a whole number from 1`);if(t>n)throw new dc(`${e} is schema ${t}, newer than the schema ${n} this ttheme reads — \`${Kf}\` updates it`)}function mn(t){let{slot:e,color:n,opacity:r}=hn({name:t.name,background:t.background,foreground:t.foreground,cursor:t.cursor,selection:t.selectionBackground,ansi:t.ansi,waived:t.waive},t.signatureSlots);return{name:t.name,...t.base?{base:t.base}:{},group:t.group,...t.native?{native:t.native}:{},...t.nativeNames?{nativeNames:t.nativeNames}:{},...t.lead?{lead:!0}:{},order:t.order,ansiSource:t.ansiSource,...t.booru?{booru:t.booru}:{},...t.booruSites?{booruSites:t.booruSites}:{},...t.role==="default"?{default:!0}:{},background:t.background,foreground:t.foreground,cursor:t.cursor,selection:t.selectionBackground,signature:t.signature,signatureSlots:t.signatureSlots,ansi:t.ansi,gate:on(t),...t.waive.length>0?{waived:t.waive}:{},backdrop:{slot:e,color:n,opacity:r},...t.pictures?{pictures:t.pictures}:{}}}function De(t){return{name:t.name,...t.base?{base:t.base}:{},group:t.group,...t.native?{native:t.native}:{},...t.nativeNames?{nativeNames:t.nativeNames}:{},lead:t.lead===!0,order:t.order,...t.default?{role:"default"}:{},ansiSource:t.ansiSource,...t.booru?{booru:t.booru}:{},...t.booruSites?{booruSites:t.booruSites}:{},background:t.background,foreground:t.foreground,cursor:t.cursor,selectionBackground:t.selection,ansi:t.ansi,signature:t.signature,signatureSlots:t.signatureSlots,ghostty:{iconGhost:t.cursor,iconScreen:[t.cursor,t.selection,t.background]},waive:t.waived??[],...t.pictures?{pictures:t.pictures}:{}}}var M2=6,O2=["ansi1","ansi2","ansi4","ansi3","ansi5","ansi6"];function hc(t){let e=(s)=>s.startsWith("ansi")?t.ansi[Number(s.slice(4))]:s==="foreground"?t.foreground:s==="cursor"?t.cursor:s==="selection"?t.selection:void 0,n=(s)=>s.startsWith("ansi")?`ansi${Number(s.slice(4))%8}`:s,r=new Set,i=[];for(let s of["foreground",...t.signatureSlots,...O2]){let o=e(s);if(i.length===M2||!o||r.has(n(s))||i.includes(o))continue;r.add(n(s)),i.push(o)}return i}function Mt(t){return t.filter((e)=>e.default!==!0)}function mc(){return{schema:Wf,version:It.version,gate:we,palettes:[]}}import{existsSync as x2,readFileSync as gc,statSync as Cw}from"node:fs";import{homedir as vs}from"node:os";import{join as ks}from"node:path";var I2=["core","kowiki","unlicensed"],R2=["ko","ja","en","zh","other"],_w=["keys","keyAt","ownAt","owners","cards","cardAt","ranks","tags","tagAt","tagCard"],Gw="TTNI";function wr(t=vs()){return ks(process.env.XDG_CACHE_HOME??ks(t,".cache"),"ttheme","aninames")}var N2=/[ァ-ヶ]/g,T2=/[\s\p{P}\p{S}]+/gu;function ys(t){return t.normalize("NFKC").toLowerCase().replace(N2,(e)=>String.fromCharCode(e.charCodeAt(0)-96)).replace(T2,"")}function di(t,e){let n=ys(e);if(n===""){let r=e.toLowerCase();return t.some((i)=>i.toLowerCase().includes(r))}return t.some((r)=>ys(r).includes(n))}function Yf(t){return t.length>=2||/[\p{Script=Han}\p{Script=Hangul}\p{Script=Hiragana}]/u.test(t)}function Bw(t){let e=wr(t);return I2.map((n)=>ks(e,`ttheme-${n}.json`)).filter((n)=>x2(n))}var A2=6;function Uw(t){return[`format ${A2}`,...t.map((e)=>`${e}:${Cw(e).size}:${Cw(e).mtimeMs}`)].join("|")}function P2(t){try{return JSON.parse(gc(t,"utf8"))}catch{return{}}}function H2(t){let e=new Map;for(let i of t)for(let[s,o]of Object.entries(P2(i))){let a=e.get(s)??{tags:new Set,names:[],japanese:[],generated:[],rank:0,weight:0,posts:0};a.posts=Math.max(a.posts,o.posts??0),a.generated.push(...o.generated??[]),a.japanese.push(...o.names?.ja??[]),a.tag??=o.tag;for(let c of o.danbooru??[])a.tags.add(c);for(let c of R2)a.names.push(...o.names?.[c]??[]);if(o.rank!==void 0){let c=o.weight??1;a.rank=(a.rank*a.weight+o.rank*c)/(a.weight+c),a.weight+=c}e.set(s,a)}let n=[],r=Math.log1p([...e.values()].reduce((i,s)=>Math.max(i,s.posts),1));for(let i of e.values()){if(i.tags.size===0)continue;let s=[...i.tags];n.push({tag:i.tag&&i.tags.has(i.tag)?i.tag:s[0],tags:s,names:[...new Set(i.names)],japanese:[...new Set(i.japanese)],generated:[...new Set(i.generated)],rank:i.posts>0?Math.log1p(i.posts)/r:i.rank})}return n}function Ho(t,e){let n=new t(e.length);return n.set(e),n}function zf(t){let e=[0];for(let n of t)e.push(e.at(-1)+n.length);return{bytes:Buffer.concat(t),at:Ho(Uint32Array,e)}}function F2(t,e){let n=H2(t),r=new Map,i=(E,S,x)=>{let R=r.get(E),N=S*4+x;if(!R)r.set(E,[N]);else if(R.at(-1)>>>2!==S)R.push(N);else if(R.at(-1)<N)R[R.length-1]=N};n.forEach((E,S)=>{let x=[...E.names,...E.tags.map((R)=>R.replaceAll("_"," "))];for(let[R,N]of[[x,1],[E.generated,0]])for(let F of R){let _=ys(F);if(_&&Yf(_))i(_,S,2|N);let B=F.split(/[\s・·_]+/);if(B.length<2)continue;for(let tt of B){let W=ys(tt);if(W&&Yf(W))i(W,S,N)}}});let s=[...r.keys()].sort(),o=[0],a=[];for(let E of s){for(let S of r.get(E)??[])a.push(S);o.push(a.length)}let c=n.flatMap((E,S)=>E.tags.map((x)=>[x,S])).sort(([E],[S])=>E<S?-1:E>S?1:0),u=zf(s.map((E)=>Buffer.from(E))),l=zf(n.map((E)=>Buffer.from(JSON.stringify([E.tag,E.tags,E.names,E.japanese,E.generated])))),f=zf(c.map(([E])=>Buffer.from(E))),d={keys:u.bytes,keyAt:u.at,ownAt:Ho(Uint32Array,o),owners:Ho(Uint32Array,a),cards:l.bytes,cardAt:l.at,ranks:Ho(Float32Array,n.map((E)=>E.rank)),tags:f.bytes,tagAt:f.at,tagCard:Ho(Uint32Array,c.map(([,E])=>E))},h=_w.map((E)=>{let S=d[E];return Buffer.from(S.buffer,S.byteOffset,S.byteLength)}),m=0,$=h.map((E)=>{let S=[m,E.length];return m+=Math.ceil(E.length/4)*4,S}),g=Buffer.from(JSON.stringify({stamp:e,sections:$})),b=Math.ceil((8+g.length)/4)*4,y=Buffer.alloc(b+m);y.write(Gw,0,"latin1"),y.writeUInt32LE(g.length,4),g.copy(y,8);for(let[E,S]of h.entries())S.copy(y,b+($[E]?.[0]??0));return y}function Lw(t,e,n,r){let i=e.byteOffset+n;if(i%4===0)return new t(e.buffer,i,r/4);return new t(e.buffer.slice(i,i+r),0,r/4)}function jw(t,e){if(t.toString("latin1",0,4)!==Gw)return;let n=t.readUInt32LE(4),r=JSON.parse(t.toString("utf8",8,8+n));if(r.stamp!==e)return;let i=Math.ceil((8+n)/4)*4,s=(c)=>{let[u,l]=r.sections[_w.indexOf(c)];return[i+u,l]},o=(c)=>{let[u,l]=s(c);return t.subarray(u,u+l)},a=(c)=>Lw(Uint32Array,t,...s(c));return{keys:o("keys"),keyAt:a("keyAt"),ownAt:a("ownAt"),owners:a("owners"),cards:o("cards"),cardAt:a("cardAt"),ranks:Lw(Float32Array,t,...s("ranks")),tags:o("tags"),tagAt:a("tagAt"),tagCard:a("tagCard")}}var Df;function Jf(t){try{let e=Bw(t);if(e.length===0)return;let n=Uw(e);if(Df?.stamp===n)return Df.index;let r=ks(wr(t),"index.bin"),i;try{i=jw(gc(r),n)}catch{}if(!i){let s=F2(e,n);try{P(r,s)}catch{}i=jw(s,n)}if(i)Df={stamp:n,index:i};return i}catch{return}}function Ww(t,e){let[n,r,i,s,o]=JSON.parse(t.cards.toString("utf8",t.cardAt[e],t.cardAt[e+1]));return{tag:n,tags:r,names:i,japanese:s,generated:o,rank:t.ranks[e]??0}}function Kw(t,e,n,r){let i=0,s=n;while(i<s){let o=i+s>>1;if(t.toString("utf8",e[o],e[o+1])<r)i=o+1;else s=o}return i}function zw(t,e){let n=Buffer.from(e),r=t.tagCard.length,i=Kw(t.tags,t.tagAt,r,e);if(i>=r||t.tags.compare(n,0,n.length,t.tagAt[i],t.tagAt[i+1])!==0)return;return t.tagCard[i]}var qf=/\s*[((][^()()]*[))]$/u,pc={ko:4,en:4,ja:5,zh:3};function C2(t){if(!t)return[];let e=/\p{Script=Hangul}/u,n=/^[\p{Script=Latin}\p{N}\s.'’-]+$/u,r=new Set([...t.names,...t.generated].filter((f)=>!qf.test(f))),i=(f)=>!qf.test(f)||!r.has(f.replace(qf,"")),s=t.names.filter(i),o=s.filter((f)=>e.test(f)),a=[...o,...t.generated.slice(0,o.length>0?0:2)],c=s.filter((f)=>n.test(f)),u=t.japanese.filter(i),l=s.filter((f)=>!e.test(f)&&!n.test(f)&&!u.includes(f));return[...new Set([...a.slice(0,pc.ko),...c.slice(0,pc.en),...u.slice(0,pc.ja),...l.slice(0,pc.zh)])]}var $s;function bc(t,e=vs()){if(!t)return[];if(!$s)try{$s=JSON.parse(gc(ks(wr(e),"aliases.json"),"utf8")).tags}catch{$s={}}return $s[t]??[]}function Vf(t,e=vs()){try{return L2(t,e)}catch{return new Map}}function L2(t,e){let n=new Map,r=Bw(e);if(r.length===0||t.length===0)return n;let i=Uw(r),s=ks(wr(e),"aliases.json"),o;try{o=JSON.parse(gc(s,"utf8"))}catch{}if(o?.stamp===i&&t.every((l)=>(l in o.tags))){$s=o.tags;for(let l of t)n.set(l,o.tags[l]??[]);return n}let a=Jf(e);if(!a)return n;let c=new Set([...t,...o?.stamp===i?Object.keys(o.tags):[]]),u={};for(let l of c){let f=zw(a,l);u[l]=f===void 0?[]:C2(Ww(a,f))}try{P(s,`${JSON.stringify({stamp:i,tags:u})}
248
- `)}catch{}$s=u;for(let l of t)n.set(l,u[l]??[]);return n}function hi(t,e=vs()){Vf(t.flatMap((n)=>n.booru?[n.booru]:[]),e)}var j2=0.25,_2=0.1;function Dw(t,e,n=new Set,r=vs()){let i=ys(t);if(!i||!Yf(i))return[];let s=Jf(r);if(!s)return[];let o=Buffer.from(i),a=s.ownAt.length-1,c=new Set([...n].flatMap((l)=>zw(s,l)??[])),u=new Map;for(let l=Kw(s.keys,s.keyAt,a,i);l<a;l++){let f=s.keyAt[l],d=s.keyAt[l+1]-f;if(d<o.length||s.keys.compare(o,0,o.length,f,f+o.length)!==0)break;let h=d===o.length;for(let m=s.ownAt[l];m<s.ownAt[l+1];m++){let $=s.owners[m],g=$>>>2,b=h?Math.max(0,($&2?2:1)-($&1?0:1)):0,y=(s.ranks[g]??0)+j2*b+(c.has(g)?_2:0);if((u.get(g)?.score??-1)<y)u.set(g,{score:y,key:l})}}return[...u].sort(([,l],[,f])=>f.score-l.score).slice(0,e).map(([l,{key:f}])=>{let d=Ww(s,l),h=s.keys.toString("utf8",s.keyAt[f],s.keyAt[f+1]);return{tag:d.tags.find((m)=>n.has(m))??d.tag,name:[...d.names,...d.generated].find((m)=>ys(m).includes(h))??d.tag.replaceAll("_"," ")}})}function wc(t=vs()){Jf(t)}import{existsSync as J2,readdirSync as n0,readFileSync as V2}from"node:fs";import{basename as r0,join as kc}from"node:path";import{existsSync as G2,readFileSync as qw}from"node:fs";import{homedir as Yw}from"node:os";import{isAbsolute as Jw,join as mi,resolve as B2}from"node:path";var z="official",Ft="ttheme-market.toml",U2="https://www.schemastore.org/ttheme-market.json",Vw="https://www.schemastore.org/ttheme-palette.json",Zw=["$schema","name","description","owner","renames","force_remove_deleted_palettes","metadata"],Qw=["name","email","url"],Es="ttheme-market",W2=/^[a-z0-9](?:[a-z0-9]|-(?=[a-z0-9])){0,38}$/i,K2=/^[\w.-]{1,100}$/,z2=/^\w[\w.+/-]{0,199}$/;function Hn(t){return mi(t,"ttheme","installed.json")}function Ct(t){return t??[z]}function Ss(t){try{let{markets:e}=JSON.parse(qw(Hn(t),"utf8"));return Ct(Array.isArray(e)?e.filter((n)=>typeof n==="string"):void 0)}catch{return[z]}}function ct(t){return Jw(t)}function ee(t){return t!==z&&!ct(t)}function $r(t){let e=t.indexOf("#");return ee(t)&&e>=0?t.slice(0,e):t}function Fo(t){let e=t.indexOf("#");return ee(t)&&e>=0?t.slice(e+1):void 0}function Ms(t,e){return $r(t)===$r(e)}function kr(t,e){return!ct(t)&&(e?.[t]??t===z)}function D2(t){return!z2.test(t)||t.includes("..")||t.includes("//")||/(?:[./]|\.lock)$/.test(t)}function yr(t,e=process.cwd()){if(t===z)return z;if(t==="~"||t.startsWith("~/"))return mi(Yw(),t.slice(1));if(t.startsWith(".")||Jw(t))return B2(e,t);let[n="",r,...i]=t.split("#"),[s,o,...a]=n.replace(/^https:\/\/github\.com\//,"").replace(/\.git$/,"").split("/");if(!s||!W2.test(s)||!o||!K2.test(o)||a.length>0||i.length>0||r!==void 0&&D2(r))throw Error(`${t} is not a market — give a repository (alice/ttheme-dust, #v1 pins a tag or branch) or a path (./my-market)`);return`${s.toLowerCase()}/${o}${r===void 0?"":`#${r}`}`}function Xw(t){let e=Fo(t)?.split("/").map(encodeURIComponent).join("/")??"HEAD";return`https://codeload.github.com/${$r(t)}/tar.gz/${e}`}function t0(t){return t.slice(0,t.indexOf("/"))}function Xf(t){return mi(t,"ttheme","markets")}function He(t,e){return mi(Xf(t),`${$r(e).replace("/","--")}.json`)}function $c(t){return mi(t,"ttheme","market")}function td(t,e){return mi($c(t),e)}function q2(t,e){if(typeof t!=="string"||typeof e!=="string")return'needs a "name" and an [owner] table whose name is the GitHub handle';return ve(`${t}@${e}/x`)}function ne({owner:t,name:e}){return`${t}@${e}`}function e0({owner:t,name:e}){return`"$schema" = ${JSON.stringify(U2)}
242
+ */var Ut=["top-left","top-center","top-right","center-left","center","center-right","bottom-left","bottom-center","bottom-right"],zs="Original",vR=1e6,yn="_groups.toml",zw=3,Dw=8,nf="[a-z0-9]+(?:-[a-z0-9]+)*",SR=new RegExp(`^(?:(${nf})@(${nf})/)?(${nf})$`),Vw=["background","foreground","cursor","selection"];function ot(t,e){throw Error(`${t}: ${e}`)}function $i(t,e,n){if(typeof n!=="string"||!le(n))ot(t,`${e} must be "#rrggbb" (lowercase), got ${JSON.stringify(n)}`);return n}function qs(t,e,n){if(typeof n!=="string"||n.length===0)ot(t,`${e} must be a non-empty string`);return n}function oe(t){return t.replace("@","--").replace("/","--")}function j(t){return`ttheme-${oe(t)}`}function lt(t){let e=t.indexOf("/");return e<0?void 0:t.slice(0,e)}function de(t){return t.slice(t.indexOf("/")+1)}function xe(t){let e=SR.exec(t);if(!e)return"takes lowercase letters, digits and single hyphens, as <palette> or <owner>@<market>/<palette>";if((e[1]?.length??0)>39)return"has an owner longer than a GitHub handle can be";return(e[2]?.length??0)>40||(e[3]?.length??0)>40?"is longer than 40 characters":void 0}function Ys(t){if(/[\p{Cc}"$`\\]/u.test(t))return"holds a control character, a quote, $, ` or \\";return t.length>80?"is longer than 80 characters":void 0}function Ds(t,e,n){let r=qs(t,e,n),i=Ys(r);if(i)ot(t,`${e} ${JSON.stringify(r)} ${i}`);return r}function qw(t,e,n){let r=qs(t,e,n),i=xe(r);if(i)ot(t,`${e} "${r}" ${i}`);return r}function xo(t){return t&&typeof t==="object"?t:{}}function ER(t,e,n){if(e===void 0)return[n.cursor,n.selectionBackground,n.background];let r=Array.isArray(e)?e:[e];if(r.length===0)ot(t,"ghostty.icon_screen must not be empty");return r.map((i,o)=>$i(t,`ghostty.icon_screen[${o}]`,i))}function MR(t,e,n){let r=xo(e);return{iconGhost:r.icon_ghost===void 0?n.cursor:$i(t,"ghostty.icon_ghost",r.icon_ghost),iconScreen:ER(t,r.icon_screen,n)}}function xR(t){return new Map([...Vw.map((e)=>[e,t[e]]),...t.ansi.map((e,n)=>[`ansi${n}`,e])])}function OR(t,e,n){if(!Array.isArray(e)||e.length!==zw)ot(t,`meta.signature must name exactly ${zw} palette slots`);let r=xR(n),i=[],o=[];for(let[s,a]of e.entries()){let c=`meta.signature[${s}]`,u=qs(t,c,a),l=r.get(u);if(l===void 0)ot(t,`${c} ${JSON.stringify(a)} is not a palette slot — use ${Vw.join(", ")} or ansi0-ansi15`);i.push(u),o.push(l)}if(new Set(o).size!==o.length)ot(t,"meta.signature slots must resolve to three different colors");return{names:i,colors:o}}function IR(t,e,n,r=!1){if(e===void 0)return;if(!n)ot(t,"meta.booru_sites renames meta.booru per site, so it needs meta.booru");if(!e||typeof e!=="object"||Array.isArray(e))ot(t,'meta.booru_sites must be a table of site = "tag" or site = ["tag", ...]');let i={};for(let[o,s]of Object.entries(e)){let a=J.find((u)=>u.key===o);if(!a){if(r)continue;ot(t,`meta.booru_sites.${o} is not a find site — use ${J.map((u)=>u.key).join(", ")}`)}let c=typeof s==="string"?[s]:Array.isArray(s)?s:void 0;if(!c||c.some((u)=>typeof u!=="string"||u===""||/\s/.test(u)))ot(t,`meta.booru_sites.${o} must be one tag or a list of tags, got ${JSON.stringify(s)}`);if(c.length>1&&!a.ors)ot(t,`meta.booru_sites.${o} takes one tag — ${a.name} does not OR tags`);if(c.length>a.tagBudget)ot(t,`meta.booru_sites.${o} takes ${a.tagBudget} tags at most — ${a.name} searches that many at a time`);i[o]=c}return i}function RR(t,e,n){if(e===void 0)return;if(!Array.isArray(e)||e.length===0||e.length>Dw)ot(t,`[[picture]] holds 1 to ${Dw} pictures`);let r=e.flatMap((i,o)=>{let s=xo(i),a=`picture[${o}]`,c=J.find((h)=>h.key===s.site);if(!c){if(n)return[];ot(t,`${a}.site must be one of ${J.map((h)=>h.key).join(", ")}`)}if(typeof s.id!=="number"||!Number.isSafeInteger(s.id)||s.id<=0)ot(t,`${a}.id must be the post's number on ${c.name}`);let{size:u,position:l,opacity:d}=s;if(u!==void 0&&u!=="fill"&&!(Number.isInteger(u)&&Number(u)>=20&&Number(u)<=999))ot(t,`${a}.size must be "fill" or a percentage from 20 to 999`);let f=l===void 0||Ut.includes(l);if(!f&&!n)ot(t,`${a}.position must be one of ${Ut.join(", ")}`);if(d!==void 0&&!(typeof d==="number"&&d>=0&&d<=1))ot(t,`${a}.opacity must be a number from 0 to 1`);return[{site:c.key,id:s.id,...u!==void 0?{size:u}:{},...l!==void 0&&f?{position:l}:{},...d!==void 0?{opacity:d}:{}}]});return r.length>0?r:void 0}function of(t,e){try{return wi(e)}catch(n){ot(t,`is not valid TOML — ${(n instanceof Error?n.message:String(n)).split(`
243
+ `)[0]}`)}}function PR(t){let n=of(yn,Yw(Jw(t,yn),"utf8")).group;if(!Array.isArray(n)||n.length===0)ot(yn,"needs at least one [[group]] table");return n.map((r)=>{let i=xo(r);return{name:Ds(yn,"group.name",i.name),native:i.native===void 0?void 0:Ds(yn,"group.native",i.native),lead:qs(yn,"group.lead",i.lead)}})}function NR(t,e){if(!Array.isArray(e)||e.length===0)ot(t,'meta.native_names must be a list of names, like ["後藤ひとり"]');return e.map((n,r)=>{let i=Ds(t,`meta.native_names[${r}]`,n);if(i.includes("|"))ot(t,`meta.native_names[${r}] ${JSON.stringify(i)} contains |`);return i})}var rf={"":["$schema","meta","colors","contrast","ghostty","picture"],meta:["name","base","group","ansi_source","booru","booru_sites","native_names","signature","order","role"],colors:["background","foreground","cursor","selection_background","ansi"],contrast:["waive","reason"],ghostty:["icon_ghost","icon_screen"],picture:["site","id","size","position","opacity"]};function Zw(t,e){let n=of(t,e),r=(i,o,s=[])=>o&&typeof o==="object"&&!Array.isArray(o)?Object.keys(o).filter((a)=>!s.includes(a)).map((a)=>i?`${i}.${a}`:a):[];return[...r("",n,rf[""]),...["meta","colors","contrast","ghostty"].flatMap((i)=>r(i,n[i],rf[i])),...(Array.isArray(n.picture)?n.picture:[]).flatMap((i,o)=>r(`picture[${o}]`,i,rf.picture))]}function sf(t,e,n){let r=of(t,e),i=xo(r.meta),o=xo(r.colors),s=xo(r.contrast),a=o.ansi;if(!Array.isArray(a)||a.length!==16)ot(t,`colors.ansi must hold exactly 16 colors, got ${Array.isArray(a)?a.length:typeof a}`);let c=qw(t,"meta.name",i.name);if(c!==n.name)ot(t,`meta.name "${c}" does not match its file — it lives at ${n.name}`);let u=n.open===!0;for(let L of["order","role"])if(u&&i[L]!==void 0)ot(t,`meta.${L} is for the official palettes — a market palette follows its base`);let l=i.role;if(l!==void 0&&l!=="default")ot(t,`meta.role must be "default", got ${JSON.stringify(l)}`);let d=i.base===void 0?void 0:qw(t,"meta.base",i.base);if(d!==void 0&&!u)ot(t,"meta.base is for market palettes");let f=d===void 0?void 0:n.bases?.get(d),h=u&&i.group===void 0?f?.group??zs:Ds(t,"meta.group",i.group),m=n.groups.get(h);if(!m&&!(u&&(h===zs||n.open)))ot(t,`meta.group "${h}" has no [[group]] table in ${yn}`);let g=$i(t,"colors.background",o.background),b=$i(t,"colors.foreground",o.foreground),w=$i(t,"colors.cursor",o.cursor),k=$i(t,"colors.selection_background",o.selection_background),v=a.map((L,K)=>$i(t,`colors.ansi[${K}]`,L)),S=OR(t,i.signature,{background:g,foreground:b,cursor:w,selection:k,ansi:v}),M=i.booru===void 0?void 0:qs(t,"meta.booru",i.booru);if(M!==void 0&&/[\s\p{Cc}]/u.test(M))ot(t,`meta.booru must be a single booru tag, got ${JSON.stringify(M)}`);let I=IR(t,i.booru_sites,M,n.foreign===!0),O=i.native_names===void 0?void 0:NR(t,i.native_names),H=Array.isArray(s.waive)?s.waive.map(String):[];if(H.length>0&&typeof s.reason!=="string")ot(t,"contrast.waive needs a contrast.reason explaining why");let N=RR(t,r.picture,n.foreign===!0);return{name:c,...d?{base:d}:{},group:h,native:m?.native,...O?{nativeNames:O}:{},lead:!u&&m?.lead===c,order:u?f?.order??vR:Number(i.order),role:l,ansiSource:u&&i.ansi_source===void 0?d??"original":Ds(t,"meta.ansi_source",i.ansi_source),...M?{booru:M}:{},...I?{booruSites:I}:{},background:g,foreground:b,cursor:w,selectionBackground:k,ansi:v,signature:S.colors,signatureSlots:S.names,ghostty:MR(t,r.ghostty,{background:g,cursor:w,selectionBackground:k}),waive:H,waiveReason:typeof s.reason==="string"?s.reason:void 0,...N?{pictures:N}:{}}}function Qw(t){let e=PR(t),n=new Map(e.map((o)=>[o.name,o]));if(n.size!==e.length)ot(yn,"group.name must be unique");let r=kR(t).filter((o)=>o.endsWith(".toml")&&!o.startsWith("_")).map((o)=>sf(o,Yw(Jw(t,o),"utf8"),{name:yR(o,".toml"),groups:n})).sort((o,s)=>o.order-s.order);if(new Set(r.map((o)=>o.order)).size!==r.length)throw Error("themes: meta.order must be unique across all themes");for(let o of e){let s=r.filter((a)=>a.group===o.name);if(s.length===0)ot(yn,`group "${o.name}" has no themes`);if(!s.some((a)=>a.name===o.lead))ot(yn,`group "${o.name}" lead "${o.lead}" is not one of its themes`)}return r}function Xw(t){return t.filter((e)=>e.role===void 0)}function ki(t){let e=(r,i)=>r<i?-1:r>i?1:0,n=(r)=>lt(r.name)?r.name:r.base??r.name;return[...t].sort((r,i)=>Number(lt(r.name)!==void 0)-Number(lt(i.name)!==void 0)||e(r.group.toLowerCase(),i.group.toLowerCase())||Number(r.catalog===void 0)-Number(i.catalog===void 0)||e((r.catalog??"").toLowerCase(),(i.catalog??"").toLowerCase())||e(n(r),n(i))||Number(r.base!==void 0)-Number(i.base!==void 0)||e(r.name,i.name))}var Js={width:2560,height:1550},FR=1,jR=2560,_R=0.1,l0=0.99,BR=2,yi={tall:1.15,reach:0.4,widest:0.95,headroom:0.04,margin:0.03,stands:12},GR=vt(pt("#19161e","#9b86c8",0.2)),UR="shelf",Lc="originals",WR="images.json",cf=1;function KR(t,e){if(e==="background"||e==="foreground"||e==="cursor")return t[e];if(e==="selection"&&t.selection)return t.selection;let n=/^ansi(\d|1[0-5])$/.exec(e),r=n?t.ansi[Number(n[1])]:void 0;if(!r)throw Error(`${t.name} has no slot ${e}`);return r}function t0(t){if(t(1))return 1;let e=0,n=1;for(let r=0;r<40;r++){let i=(e+n)/2;if(t(i))e=i;else n=i}return e}function d0(t,e){let n=(s)=>zg({name:t.name,background:pt(t.background,e,s),foreground:t.foreground,ansi:t.ansi,waive:t.waived??[]}).map((a)=>a.rule),r=new Set(n(0)),i=t0((s)=>n(s).every((a)=>r.has(a))),o=t0((s)=>vt(pt(t.background,e,s))<=GR);return{cap:i,matched:o,opacity:Math.floor(Math.min(i,o)*100)/100}}function e0(t,e){let n=KR(t,e),{cap:r,matched:i,opacity:o}=d0(t,n),s=et(t.background),a=Math.hypot(...et(n).map((c,u)=>(c-(s[u]??0))*o));return{slot:e,color:n,cap:r,matched:i,opacity:o,reach:a}}function f0(t,e){return d0(t,e).opacity}function vn(t,e){let n=e0(t,"cursor");if(n.opacity>=_R)return n;return e.filter((r)=>r!=="cursor"&&r!=="background").map((r)=>e0(t,r)).reduce((r,i)=>i.reach>r.reach?i:r,n)}function zR(t){return Xb(t)??{x:0,y:0,w:t.width,h:t.height}}function mf(t,e){if(t<=0||e<=0)return Js;let n=Math.min(1,Js.width/Math.max(t,e));return{width:Math.round(t*n),height:Math.round(e*n)}}function h0(t,e,n,r){if(r<yi.stands){let c=t.w*n>t.h*e?{x:t.x+(t.w-t.h*e/n)/2,y:t.y,w:t.h*e/n,h:t.h}:{x:t.x,y:t.y,w:t.w,h:t.w*n/e};return{crop:c,at:{x:0,y:0,w:e,h:n},focus:(c.y-t.y+c.h/2)/t.h}}let i=Math.max(yi.tall*n,yi.reach*e*t.h/t.w),o=i*t.w/t.h;if(o>yi.widest*e)o=yi.widest*e,i=o*t.h/t.w;let s=yi.headroom*n,a=Math.min(1,(n-s)/i);return{crop:{x:t.x,y:t.y,w:t.w,h:t.h*a},at:{x:e*(1-yi.margin)-o,y:s,w:o,h:i*a},focus:Math.min(1,(n/2-s)/i)}}function DR(t,e){return 0.299*(t[e]??0)+0.587*(t[e+1]??0)+0.114*(t[e+2]??0)}function qR(t,e){let n=new Uint32Array(256),r=Math.max(1,Math.floor(e.w*e.h/400000)),i=0;for(let s=0;s<e.w*e.h;s+=r){let a=((e.y+Math.floor(s/e.w))*t.width+e.x+s%e.w)*4;if((t.data[a+3]??0)>=128){let c=Math.round(DR(t.data,a));n[c]=(n[c]??0)+1,i++}}let o=0;for(let s=0;s<256&&i>0;s++)if(o+=n[s]??0,o>=i*l0)return Math.min(BR,Math.max(1,255/Math.max(1,s)));return 1}var af=Float64Array.from({length:256},(t,e)=>{let n=e/255;return n<=0.04045?n/12.92:((n+0.055)/1.055)**2.4});function YR(t,e,n){return`#${[t,e,n].map((r)=>Math.round(r).toString(16).padStart(2,"0")).join("")}`}function JR(t,e){let n=new Uint32Array(256),r=new Float64Array(768),i=Math.max(1,Math.floor(e.w*e.h/400000)),o=0;for(let a=0;a<e.w*e.h;a+=i){let c=((e.y+Math.floor(a/e.w))*t.width+e.x+a%e.w)*4;if((t.data[c+3]??0)>=128){let u=t.data[c]??0,l=t.data[c+1]??0,d=t.data[c+2]??0,f=Math.round(255*Math.sqrt(0.2126*(af[u]??0)+0.7152*(af[l]??0)+0.0722*(af[d]??0)));n[f]=(n[f]??0)+1,r[f*3]=(r[f*3]??0)+u,r[f*3+1]=(r[f*3+1]??0)+l,r[f*3+2]=(r[f*3+2]??0)+d,o++}}let s=0;for(let a=0;a<256&&o>0;a++)if(s+=n[a]??0,s>=o*l0){let c=Math.max(1,n[a]??1);return YR((r[a*3]??0)/c,(r[a*3+1]??0)/c,(r[a*3+2]??0)/c)}return"#ffffff"}function VR(t,e){let n=t.data,r=new Uint8Array(t.width*t.height);for(let i=0,o=0;i<r.length;i++,o+=4){let s=n[o+3];if(s===0)continue;let a=(0.299*n[o]+0.587*n[o+1]+0.114*n[o+2])*e;r[i]=(a>255?255:a)*s/255+0.5}return{width:t.width,height:t.height,data:r}}function m0(t,e,n){let r=Math.max(0,Math.round(t.at.x)),i=Math.max(0,Math.round(t.at.y)),o=Math.min(e,Math.round(t.at.x+t.at.w)),s=Math.min(n,Math.round(t.at.y+t.at.h));if(o<=r||s<=i)return;let a=t.crop.w/t.at.w,c=t.crop.h/t.at.h;return{x0:r,y0:i,x1:o,y1:s,box:{x:t.crop.x+(r-t.at.x)*a,y:t.crop.y+(i-t.at.y)*c,w:(o-r)*a,h:(s-i)*c}}}function Cc(t,e,n,r){let i=new Float32Array(n*r),o=m0(e,n,r);if(o){let s=rw(t,o.box,o.x1-o.x0,o.y1-o.y0);for(let a=o.y0;a<o.y1;a++)i.set(s.data.subarray((a-o.y0)*(o.x1-o.x0),(a-o.y0+1)*(o.x1-o.x0)),a*n+o.x0)}return{width:n,height:r,data:i}}function pf(t,e,n,r){let i=new Uint8Array(n*r*4),o=m0(e,n,r);if(o){let s=o.x1-o.x0,a=As(t,o.box,s,o.y1-o.y0);for(let c=o.y0;c<o.y1;c++)i.set(a.data.subarray((c-o.y0)*s*4,(c-o.y0+1)*s*4),(c*n+o.x0)*4)}return{width:n,height:r,data:i}}function uf(t,e){if(e<=0)return t;let{width:n,height:r}=t,i=[0,1,2,3].map(()=>({width:n,height:r,data:new Float32Array(n*r)}));for(let a=0;a<n*r;a++){let c=t.data[a*4+3]??0;for(let u=0;u<3;u++)i[u].data[a]=(t.data[a*4+u]??0)*c/255;i[3].data[a]=c}let o=i.map((a)=>Ts(a,e).data),s=new Uint8Array(n*r*4);for(let a=0;a<n*r;a++){let c=o[3]?.[a]??0;if(c<=0)continue;for(let u=0;u<3;u++)s[a*4+u]=Math.min(255,Math.max(0,Math.round((o[u]?.[a]??0)*255/c)));s[a*4+3]=Math.min(255,Math.round(c))}return{width:n,height:r,data:s}}function gf(t){let e=zR(t),n,r;return{box:e,clear:Wn(t,e),get ink(){return n??=VR(t,qR(t,e)),n},image:t,get peak(){return r??=JR(t,e),r}}}function p0(t,e,n,r,i){let o=gf(t),{box:s,clear:a,ink:c}=o,u=h0(s,e,n,a),l=Math.min(1,jR/Math.max(s.w,s.h)),d={x:0,y:0,w:Math.round(s.w*l),h:Math.round(s.h*l)},f=r*d.w*u.crop.w/(s.w*u.at.w);if(i==="original")return{coloring:i,figure:uf(As(t,s,d.w,d.h),f),fill:uf(pf(t,u,e,n),r),focus:u.focus,peak:o.peak};let h=Cc(c,{crop:s,at:d,focus:u.focus},d.w,d.h),m=Cc(c,u,e,n);return{coloring:i,figure:Hs(Ts(h,f)),fill:Hs(Ts(m,r)),focus:u.focus}}function ZR(t,e,n,r){let i=et(e),o=et(n),s=new Uint8Array(t.width*t.height*4);for(let a=0;a<t.data.length;a++){let c=(t.data[a]??0)/255*r;for(let u=0;u<3;u++)s[a*4+u]=Math.round((i[u]??0)+((o[u]??0)-(i[u]??0))*c);s[a*4+3]=255}return{width:t.width,height:t.height,data:s}}function QR(t,e,n){let r=et(e),i=new Uint8Array(t.width*t.height*4);for(let o=0;o<t.width*t.height;o++){let s=(t.data[o*4+3]??0)/255*n;for(let a=0;a<3;a++)i[o*4+a]=Math.round((r[a]??0)+((t.data[o*4+a]??0)-(r[a]??0))*s);i[o*4+3]=255}return{width:t.width,height:t.height,data:i}}function g0(t,e,n,r,i,o,s,a="tone"){let{box:c,clear:u,ink:l}=t,d=h0(c,r,i,u),f=Math.round(100*d.at.w/d.crop.w/Math.min(r/c.w,i/c.h)),h=s?.size??"fill",m=h==="fill"?d:{crop:c,at:Ao(c.w,c.h,r,i,h,s?.at??5,!1,h>100?Math.round(d.focus*100):-1),focus:d.focus},g=a==="original"?f0(e,t.peak):n.opacity,b=s?.opacity??g;return{image:a==="original"?QR(uf(pf(t.image,m,r,i),o),e.background,b):ZR(Hs(Ts(Cc(l,m,r,i),o)),e.background,n.color,b),fill:f,opacity:g}}function V(t){return Y(t,"ttheme","backgrounds")}function lf(t){return Y(t,WR)}function vi(t){try{return Io(t,"utf8")}catch{return}}function Ir(t){try{return HR(t)}catch{return[]}}function Ot(t){let e=vi(lf(t));if(e===void 0)return XR(t);let n=JSON.parse(e);if(n.version!==cf)throw Error(`${lf(t)} is version ${n.version} — this ttheme reads version ${cf}`);return n}function _e(t){return t.coloring??"tone"}function bf(t){return{name:t.name,background:t.background,foreground:t.foreground,cursor:t.cursor,...t.selection?{selection:t.selection}:{},ansi:t.ansi,...t.waived?{waived:t.waived}:{}}}function Ro(t){return{hue:{color:t.backdrop.color,opacity:t.backdrop.opacity},colors:bf(t)}}function Po(t){return t.tone===void 0&&_e(t)==="tone"}function n0(t){return(t.artist??[]).map((e)=>e.replace(/[\s,]+/g,"_")).join(",")}function b0(t,e){let n=e.pictures.findIndex((i)=>i.key===e.active),r=e.pictures[n];return[...r.artist?.length?[`# by ${n0(r)}`]:[],...r.from?[`# from ${r.from}`]:[],`# image ${r.key} ${n+1}/${e.pictures.length}`,...e.pictures.map((i)=>[`# picture ${i.key} ${i.stem} ${i.fill} ${i.opacity} ${i.artist?.length?n0(i):"-"}`,...i.from?[i.from]:[]].join(" ")),...e.pictures.filter((i)=>_e(i)==="original").map((i)=>`# colors ${i.key} original`),`background-image = ${Y(t,r.fill)}`,"background-image-fit = cover","background-image-position = top-right",`background-image-opacity = ${r.opacity}`,`config-file = ?${r.stem}.tune.conf`,`config-file = ?${r.stem}.off.conf`,""].join(`
244
+ `)}function w0(t){let e=V(t);for(let[n,r]of Object.entries(Ot(e).palettes)){let i=Y(e,`${oe(n)}.conf`),o=b0(e,r);if(vi(i)!==o)F(i,o)}}function Si(t,e,n){F(lf(t),`${JSON.stringify(e,null,2)}
245
+ `);for(let r of n){let i=e.palettes[r],o=Y(t,`${oe(r)}.conf`);if(i)F(o,b0(t,i));else Oo(o,{force:!0})}}function $0(t,e){let n=V(t),r=Ot(n),i=[];for(let[o,s]of e){let a=r.palettes[o];if(a&&!r.palettes[s])r.palettes[s]=a,delete r.palettes[o],i.push(o,s)}if(i.length>0)Si(n,r,i)}function k0(t,e){return Ir(t).filter((n)=>n.startsWith(`${e}.`)||n.startsWith(`${e}@`))}function wf(t,e){for(let n of k0(t,e))Oo(Y(t,n),{force:!0})}function y0(t,e){wf(t,e.stem);for(let n of[e.original,e.cut])if(n)Oo(Y(t,n),{force:!0})}function r0(t,e,n,r){let i=u0(/^background-image\s*=\s*(.*?)\s*$/m.exec(e??"")?.[1]??"");if(!i.startsWith(`${t}.`)||!/^\.[0-9a-f]{8}@fill-\d+\.png$/.test(i.slice(t.length)))return;let o=i.slice(0,i.indexOf("@")),s=r??/^# image (\S+)$/m.exec(e??"")?.[1]??`picture_${o.slice(t.length+1)}`,a=/^# from (.+)$/m.exec(e??"")?.[1],c=Number(/^background-image-opacity\s*=\s*(\S+)/m.exec(e??"")?.[1]??1),u=n.find((l)=>l.startsWith(`${t}-${s}.`));return{key:s,stem:o,fill:i,opacity:Number.isFinite(c)?c:1,...a?{from:a}:{},...u?{original:Y(Lc,u)}:{}}}function i0(t,e){if(hf(t))c0(t,e)}function XR(t){let e={version:cf,palettes:{}};if(!hf(t))return e;let n=Ir(Y(t,Lc)),r=Ir(t).filter((o)=>o.endsWith(".conf")&&o!=="shown.conf"&&!/\.(tune|off)\.conf$/.test(o)).map((o)=>o.slice(0,-5)),i=Y(t,UR);for(let o of new Set([...r,...Ir(i)])){let s=[],a=r0(o,vi(Y(t,`${o}.conf`)),n);if(a)i0(Y(t,`${o}.tune.conf`),Y(t,`${a.stem}.tune.conf`)),i0(Y(t,`${o}.off.conf`),Y(t,`${a.stem}.off.conf`)),s.push(a);for(let c of Ir(Y(i,o))){let u=Y(i,o,c),l=r0(o,vi(Y(u,".conf")),n,c);if(!l)continue;for(let d of Ir(u)){let f=d===".tune.conf"||d===".off.conf"?`${l.stem}${d}`:`${o}${d}`;if(d!==".conf")c0(Y(u,d),Y(t,f))}Oo(u,{recursive:!0}),s.push(l)}if(Ir(Y(i,o)).length===0)Oo(Y(i,o),{recursive:!0,force:!0});if(s.length>0)s.sort((c,u)=>c.key<u.key?-1:c.key>u.key?1:0),e.palettes[o]={active:(a??s[0]).key,pictures:s}}if(Ir(i).length===0)Oo(i,{recursive:!0,force:!0});return Si(t,e,Object.keys(e.palettes)),e}function o0(t,e,n){return e.startsWith("~/")?Y(n,e.slice(2)):LR(e)?e:Y(t,e)}function Oe(t,e,n){let r=new Map,i=(a,c)=>{let u=vi(a);if(u===void 0)return!1;for(let l of u.split(`
246
+ `)){let d=/^([a-z-]+)\s*=\s*(.*?)\s*$/.exec(l);if(d?.[1]==="config-file"&&c<4)i(o0(t,d[2].replace(/^\?/,""),n),c+1);else if(d&&/^background-image(?:-fit|-opacity|-position)?$/.test(d[1]))r.set(d[1],d[2])}return!0};if(!i(Y(t,`${oe(e)}.conf`),0))return;let o=r.get("background-image")??"";if(o==="")return;let s=Number(r.get("background-image-opacity")??1);return{image:o0(t,o,n),opacity:Number.isFinite(s)?s:1,cover:r.get("background-image-fit")==="cover",position:r.get("background-image-position")??"center"}}function se(t){return`${t.site}_${t.id}`}function Fc(t,e,n){let r=V(t),i=Ot(r),o=i.palettes[e];if(!o)throw Error(`${e} has no image`);let s=o.pictures.findIndex((u)=>u.key===(n??o.active));if(s===-1)throw Error(`${e} has no picture ${n}`);let[a]=o.pictures.splice(s,1);y0(r,a);let c=o.pictures[s%Math.max(o.pictures.length,1)];if(!c)delete i.palettes[e];else if(a.key===o.active)o.active=c.key;return Si(r,i,[e]),{key:a.key,left:o.pictures.length}}function v0(t,e,n,r){let i=n.coloring==="original"?je(n.figure):mi(n.figure,r),o=n.coloring==="original"?je(n.fill):mi(n.fill,r),s=`${oe(t)}.${a0("sha1").update(e).update(i).update(o).digest("hex").slice(0,8)}`,a=`${s}@fill-${Math.round(n.focus*100)}.png`;return{stem:s,fill:a,files:[[`${s}.png`,i],[a,o]]}}function S0(t,e,n,r){return n==="original"&&r?{coloring:"original",opacity:f0(t,r),peak:r}:{coloring:"tone",opacity:e.opacity,tone:e.color}}function df(t,e){return Y(Lc,`${oe(t)}-${e}`)}function $f(t,e){return e.map(([n,r])=>{let i=Y(t,n);return F(i,r),i})}function jc(t,e,n,r,i,o,s,a="tone"){let c=V(t),u=e.name,l=se(i),d=Ot(c),f=d.palettes[u]??{active:l,pictures:[]},h=mf(o.width,o.height),m=p0(r,h.width,h.height,s,a),g=v0(u,l,m,n.color),b=df(u,l),w={key:l,stem:g.stem,fill:g.fill,...S0(e,n,m.coloring,m.coloring==="original"?m.peak:void 0),blur:s,window:h,...i.from?{from:i.from}:{},...i.artist?.length?{artist:i.artist}:{},...i.source?{source:i.source}:{},original:`${b}.${i.ext}`,...i.cut?{cut:`${b}.cut.png`}:{}},k=f.pictures.find((S)=>S.key===l);if(k)y0(c,k);TR(Y(c,Lc),{recursive:!0});let v=$f(c,[...g.files,[w.original,i.bytes],...w.cut?[[w.cut,Ud(hi(r))]]:[]]);return f.pictures=k?f.pictures.map((S)=>S===k?w:S):[...f.pictures,w],f.active=l,d.palettes[u]=f,Si(c,d,[u]),[...v,Y(c,`${oe(u)}.conf`)]}function No(t,e,n){let r=V(t),i=Ot(r),o=i.palettes[e],s=o?o.pictures.findIndex((a)=>a.key===n):-1;if(!o||s===-1)throw Error(`${e} has no picture ${n}`);if(o.active!==n)o.active=n,Si(r,i,[e]);return{at:s+1,of:o.pictures.length}}function fe(t,e){let n=Ot(V(t)).palettes[e];if(!n)return[];return[...n.pictures.filter((i)=>i.key===n.active),...n.pictures.filter((i)=>i.key!==n.active)]}var ff="top-right";function Ao(t,e,n,r,i,o,s,a=-1){let c=Math.trunc,u=(o-1)%3,l=c((o-1)/3),d=n*e>=r*t!==!s,f=d?c(i*n/100):c(i*r*t/(100*e)),h=d?c(i*n*e/(100*t)):c(i*r/100),m=c(u*(n-f)/2),g=c(l*(r-h)/2);if(a>=0){if(f>n)m=c((n-f)/2);if(h>r)g=Math.max(r-h,Math.min(0,c(r/2)-c(a*h/100)))}return{x:m,y:g,w:f,h}}function kf(t,e){let n=vi(Y(t,`${e.stem}.tune.conf`));if(n===void 0)return{};let r=(u)=>new RegExp(`^${u}\\s*=\\s*(.*?)\\s*$`,"m").exec(n)?.[1]??"",i=u0(r("background-image")),o=/@(\d+)-/.exec(i)?.[1],s=/@fill-\d+\.png$/.test(i)?"fill":o?Number(o):r("background-image-fit")==="cover"?"fill":100,a=r("background-image-position").replace("center-center","center")||"center",c=Number(r("background-image-opacity")||1);return{...s!=="fill"?{size:s}:{},...a!==ff?{position:a}:{},...Number.isFinite(c)&&c!==e.opacity?{opacity:c}:{}}}function Vs(t,e,n,r,i){let o=n.size??"fill",s=n.position??ff,a=n.opacity??e.opacity;if(o==="fill"&&s===ff&&a===e.opacity)return;let c=Ut.indexOf(s)+1,u=Y(t,`${e.stem}.png`),l=Y(t,e.fill),d=!0,f=typeof o==="number"&&(o>100||!r&&s!=="center");if(o===100&&!f)l=u,d=!1;else if(typeof o==="number"){if(Po(e))throw Error(`${e.stem} was drawn before pictures kept their tone — init draws it again`);let m=jt(new Uint8Array(Io(u))),{width:g,height:b}=f?Js:m,w=f?Number(/@fill-(\d+)\.png$/.exec(e.fill)?.[1]??50):-1,k=Ao(m.width,m.height,g,b,o,c,!1,w);l=Y(t,`${e.stem}@${o}-${s}${f?`-${g}x${b}`:""}.png`);let S={crop:{x:0,y:0,w:m.width,h:m.height},at:k,focus:w};F(l,e.tone?mi(Hs(Cc(hi(m),S,g,b)),e.tone):je(pf(m,S,g,b))),d=f}let h=Y(t,`${e.stem}.tune.conf`);return F(h,[`background-image = ${l.startsWith(`${i}/`)?`~${l.slice(i.length)}`:l}`,`background-image-fit = ${d?"cover":"contain"}`,`background-image-position = ${s}`,`background-image-opacity = ${a}`,""].join(`
247
+ `)),h}function E0(t){let e=new Map;for(let[n,r]of Object.entries(Ot(V(t)).palettes)){let[,i,o]=/^([a-z.]+)_(\d+)$/.exec(r.active)??[];if(i&&o)e.set(n,{site:i,id:Number(o)})}return e}function M0(t){try{let e=$n(new Uint8Array(Io(t)));return e?{width:e.width,height:e.height}:void 0}catch{return}}function x0(t,e,n,r,i,o,s){let a=[n.original,n.cut].map((c)=>{if(!c)return"";try{let{size:u,mtimeMs:l}=CR(Y(t,c));return`${c}:${u}:${l}`}catch{return}});if(!n.original||a.includes(void 0))return;return Fw([FR,oe(e),n.key,...a,r.width,r.height,i,o,o==="tone"?s:""])}function tP(t,e,n){if(!n.window||n.blur===void 0)return;let r=x0(t,e,n,n.window,n.blur,_e(n),n.tone??"");if(!r||jw(r))return;try{Xd(r,{stem:n.stem,fill:n.fill,...n.peak?{peak:n.peak}:{},figure:Io(Y(t,`${n.stem}.png`)),picture:Io(Y(t,n.fill))})}catch{}}function O0(t,e,n,r,i,o,s,a,c){let u=c?void 0:x0(t,e,n,r,s,a,o.hue.color),l=u?_w(u):void 0;if(l)return{made:{stem:l.stem,fill:l.fill,files:[[`${l.stem}.png`,l.figure],[l.fill,l.picture]]},peak:l.peak,image:void 0};let d=i();if(!d)return null;let f=p0(d,r.width,r.height,s,a),h=v0(e,n.key,f,o.hue.color),m=f.coloring==="original"?f.peak:void 0;if(u)Xd(u,{stem:h.stem,fill:h.fill,...m?{peak:m}:{},figure:h.files[0]?.[1],picture:h.files[1]?.[1]});return{made:h,peak:m,image:d}}function Zs(t,e,n,r,i,o,s,a,c,u=_e(n)){let l=V(t),d=n.window??M0(Y(l,n.fill))??Js,f=O0(l,e,n,d,r,i,o,u,c);if(!f)return null;let{made:h,peak:m,image:g}=f,b={...n,stem:h.stem,fill:h.fill,...S0(i.colors,i.hue,u,m),blur:o,window:d,...c?{cut:`${df(e,n.key)}.cut.png`}:{}};if(u==="original")delete b.tone;else delete b.peak;if(c&&g)F(Y(l,`${df(e,n.key)}.cut.png`),Ud(hi(g)));if(h.stem===n.stem)return b;if(_e(n)!==u)tP(l,e,n);$f(l,h.files);let w=kf(l,n);Vs(l,b,_e(n)===u?w:{...w,opacity:void 0},s,a);let k=Y(l,`${n.stem}.off.conf`);if(hf(k))AR(k,Y(l,`${b.stem}.off.conf`));return b}function I0(t,e,n,r,i,o,s){let a=V(t),c=n.window??M0(Y(a,n.fill))??Js;return O0(a,e,n,c,r,i,o,s,!1)!==null}function yf(t,e){let n=V(t),r=Ot(n),i=new Set,o=[];for(let{name:s,picture:a}of e){let c=r.palettes[s],u=c?.pictures.findIndex((d)=>d.key===a.key)??-1,l=c?.pictures[u];if(!c||!l)continue;if(c.pictures[u]=a,i.add(s),l.stem!==a.stem)o.push(l.stem)}if(i.size===0)return;Si(n,r,[...i]);for(let s of o)wf(n,s)}function eP(t,e,n,r){let i=k0(t,n.stem).filter((a)=>a.endsWith(".png")).map((a)=>{let c=new Uint8Array(Io(Y(t,a)));return[a,$c(c,r.color)??mi(hi(jt(c)),r.color)]}),o=(a)=>i.find(([c])=>c===a)?.[1]??new Uint8Array,s=`${oe(e)}.${a0("sha1").update(n.key).update(o(`${n.stem}.png`)).update(o(n.fill)).digest("hex").slice(0,8)}`;$f(t,i.map(([a,c])=>[s+a.slice(n.stem.length),c]));for(let a of["tune","off"]){let c=vi(Y(t,`${n.stem}.${a}.conf`));if(c!==void 0)F(Y(t,`${s}.${a}.conf`),c.split(n.stem).join(s))}return{...n,stem:s,fill:s+n.fill.slice(n.stem.length),tone:r.color}}function s0(t,e){return _e(t)!=="original"&&t.tone!==void 0&&t.tone!==e.hue.color}function R0(t,e){let n=V(t),r=Ot(n),i=[],o=[];for(let[s,a]of Object.entries(r.palettes)){let c=e.get(s);if(!c||!a.pictures.some((u)=>s0(u,c)))continue;a.pictures=a.pictures.map((u)=>{if(!s0(u,c))return u;let l=eP(n,s,u,c.hue);if(l.stem!==u.stem)o.push(u.stem);return l}),i.push(s)}if(i.length>0){Si(n,r,i);for(let s of o)wf(n,s)}return i}var vf=1,Sf="npx @kecan0406/ttheme@latest init";class _c extends Error{}function P0(t,e,n){if(typeof t!=="number"||!Number.isInteger(t)||t<1)throw Error(`${e} schema is not a whole number from 1`);if(t>n)throw new _c(`${e} is schema ${t}, newer than the schema ${n} this ttheme reads — \`${Sf}\` updates it`)}function Qe(t){let{slot:e,color:n,opacity:r}=vn({name:t.name,background:t.background,foreground:t.foreground,cursor:t.cursor,selection:t.selectionBackground,ansi:t.ansi,waived:t.waive},t.signatureSlots);return{name:t.name,...t.base?{base:t.base}:{},group:t.group,...t.native?{native:t.native}:{},...t.nativeNames?{nativeNames:t.nativeNames}:{},...t.lead?{lead:!0}:{},order:t.order,ansiSource:t.ansiSource,...t.booru?{booru:t.booru}:{},...t.booruSites?{booruSites:t.booruSites}:{},...t.role==="default"?{default:!0}:{},background:t.background,foreground:t.foreground,cursor:t.cursor,selection:t.selectionBackground,signature:t.signature,signatureSlots:t.signatureSlots,ansi:t.ansi,gate:gn(t),...t.waive.length>0?{waived:t.waive}:{},backdrop:{slot:e,color:n,opacity:r},...t.pictures?{pictures:t.pictures}:{}}}function Ie(t){return{name:t.name,...t.base?{base:t.base}:{},group:t.group,...t.native?{native:t.native}:{},...t.nativeNames?{nativeNames:t.nativeNames}:{},lead:t.lead===!0,order:t.order,...t.default?{role:"default"}:{},ansiSource:t.ansiSource,...t.booru?{booru:t.booru}:{},...t.booruSites?{booruSites:t.booruSites}:{},background:t.background,foreground:t.foreground,cursor:t.cursor,selectionBackground:t.selection,ansi:t.ansi,signature:t.signature,signatureSlots:t.signatureSlots,ghostty:{iconGhost:t.cursor,iconScreen:[t.cursor,t.selection,t.background]},waive:t.waived??[],...t.pictures?{pictures:t.pictures}:{}}}var nP=6,rP=["ansi1","ansi2","ansi4","ansi3","ansi5","ansi6"];function Bc(t){let e=(o)=>o.startsWith("ansi")?t.ansi[Number(o.slice(4))]:o==="foreground"?t.foreground:o==="cursor"?t.cursor:o==="selection"?t.selection:void 0,n=(o)=>o.startsWith("ansi")?`ansi${Number(o.slice(4))%8}`:o,r=new Set,i=[];for(let o of["foreground",...t.signatureSlots,...rP]){let s=e(o);if(i.length===nP||!s||r.has(n(o))||i.includes(s))continue;r.add(n(o)),i.push(s)}return i}function It(t){return t.filter((e)=>e.default!==!0)}function Gc(){return{schema:vf,version:At.version,gate:ve,palettes:[]}}import{existsSync as iP,readFileSync as Wc,statSync as N0}from"node:fs";import{homedir as Lo}from"node:os";import{join as Ho}from"node:path";var oP=["core","kowiki","unlicensed"],sP=["ko","ja","en","zh","other"],H0=["keys","keyAt","ownAt","owners","cards","cardAt","ranks","tags","tagAt","tagCard"],C0="TTNI";function Rr(t=Lo()){return Ho(process.env.XDG_CACHE_HOME??Ho(t,".cache"),"ttheme","aninames")}var aP=/[ァ-ヶ]/g,cP=/[\s\p{P}\p{S}]+/gu;function Co(t){return t.normalize("NFKC").toLowerCase().replace(aP,(e)=>String.fromCharCode(e.charCodeAt(0)-96)).replace(cP,"")}function Ei(t,e){let n=Co(e);if(n===""){let r=e.toLowerCase();return t.some((i)=>i.toLowerCase().includes(r))}return t.some((r)=>Co(r).includes(n))}function Of(t){return t.length>=2||/[\p{Script=Han}\p{Script=Hangul}\p{Script=Hiragana}]/u.test(t)}function L0(t){let e=Rr(t);return oP.map((n)=>Ho(e,`ttheme-${n}.json`)).filter((n)=>iP(n))}var uP=6;function F0(t){return[`format ${uP}`,...t.map((e)=>`${e}:${N0(e).size}:${N0(e).mtimeMs}`)].join("|")}function lP(t){try{return JSON.parse(Wc(t,"utf8"))}catch{return{}}}function dP(t){let e=new Map;for(let i of t)for(let[o,s]of Object.entries(lP(i))){let a=e.get(o)??{tags:new Set,names:[],japanese:[],generated:[],rank:0,weight:0,posts:0};a.posts=Math.max(a.posts,s.posts??0),a.generated.push(...s.generated??[]),a.japanese.push(...s.names?.ja??[]),a.tag??=s.tag;for(let c of s.danbooru??[])a.tags.add(c);for(let c of sP)a.names.push(...s.names?.[c]??[]);if(s.rank!==void 0){let c=s.weight??1;a.rank=(a.rank*a.weight+s.rank*c)/(a.weight+c),a.weight+=c}e.set(o,a)}let n=[],r=Math.log1p([...e.values()].reduce((i,o)=>Math.max(i,o.posts),1));for(let i of e.values()){if(i.tags.size===0)continue;let o=[...i.tags];n.push({tag:i.tag&&i.tags.has(i.tag)?i.tag:o[0],tags:o,names:[...new Set(i.names)],japanese:[...new Set(i.japanese)],generated:[...new Set(i.generated)],rank:i.posts>0?Math.log1p(i.posts)/r:i.rank})}return n}function Qs(t,e){let n=new t(e.length);return n.set(e),n}function Ef(t){let e=[0];for(let n of t)e.push(e.at(-1)+n.length);return{bytes:Buffer.concat(t),at:Qs(Uint32Array,e)}}function fP(t,e){let n=dP(t),r=new Map,i=(v,S,M)=>{let I=r.get(v),O=S*4+M;if(!I)r.set(v,[O]);else if(I.at(-1)>>>2!==S)I.push(O);else if(I.at(-1)<O)I[I.length-1]=O};n.forEach((v,S)=>{let M=[...v.names,...v.tags.map((I)=>I.replaceAll("_"," "))];for(let[I,O]of[[M,1],[v.generated,0]])for(let H of I){let N=Co(H);if(N&&Of(N))i(N,S,2|O);let L=H.split(/[\s・·_]+/);if(L.length<2)continue;for(let K of L){let B=Co(K);if(B&&Of(B))i(B,S,O)}}});let o=[...r.keys()].sort(),s=[0],a=[];for(let v of o){for(let S of r.get(v)??[])a.push(S);s.push(a.length)}let c=n.flatMap((v,S)=>v.tags.map((M)=>[M,S])).sort(([v],[S])=>v<S?-1:v>S?1:0),u=Ef(o.map((v)=>Buffer.from(v))),l=Ef(n.map((v)=>Buffer.from(JSON.stringify([v.tag,v.tags,v.names,v.japanese,v.generated])))),d=Ef(c.map(([v])=>Buffer.from(v))),f={keys:u.bytes,keyAt:u.at,ownAt:Qs(Uint32Array,s),owners:Qs(Uint32Array,a),cards:l.bytes,cardAt:l.at,ranks:Qs(Float32Array,n.map((v)=>v.rank)),tags:d.bytes,tagAt:d.at,tagCard:Qs(Uint32Array,c.map(([,v])=>v))},h=H0.map((v)=>{let S=f[v];return Buffer.from(S.buffer,S.byteOffset,S.byteLength)}),m=0,g=h.map((v)=>{let S=[m,v.length];return m+=Math.ceil(v.length/4)*4,S}),b=Buffer.from(JSON.stringify({stamp:e,sections:g})),w=Math.ceil((8+b.length)/4)*4,k=Buffer.alloc(w+m);k.write(C0,0,"latin1"),k.writeUInt32LE(b.length,4),b.copy(k,8);for(let[v,S]of h.entries())S.copy(k,w+(g[v]?.[0]??0));return k}function A0(t,e,n,r){let i=e.byteOffset+n;if(i%4===0)return new t(e.buffer,i,r/4);return new t(e.buffer.slice(i,i+r),0,r/4)}function T0(t,e){if(t.toString("latin1",0,4)!==C0)return;let n=t.readUInt32LE(4),r=JSON.parse(t.toString("utf8",8,8+n));if(r.stamp!==e)return;let i=Math.ceil((8+n)/4)*4,o=(c)=>{let[u,l]=r.sections[H0.indexOf(c)];return[i+u,l]},s=(c)=>{let[u,l]=o(c);return t.subarray(u,u+l)},a=(c)=>A0(Uint32Array,t,...o(c));return{keys:s("keys"),keyAt:a("keyAt"),ownAt:a("ownAt"),owners:a("owners"),cards:s("cards"),cardAt:a("cardAt"),ranks:A0(Float32Array,t,...o("ranks")),tags:s("tags"),tagAt:a("tagAt"),tagCard:a("tagCard")}}var Mf;function If(t){try{let e=L0(t);if(e.length===0)return;let n=F0(e);if(Mf?.stamp===n)return Mf.index;let r=Ho(Rr(t),"index.bin"),i;try{i=T0(Wc(r),n)}catch{}if(!i){let o=fP(e,n);try{F(r,o)}catch{}i=T0(o,n)}if(i)Mf={stamp:n,index:i};return i}catch{return}}function j0(t,e){let[n,r,i,o,s]=JSON.parse(t.cards.toString("utf8",t.cardAt[e],t.cardAt[e+1]));return{tag:n,tags:r,names:i,japanese:o,generated:s,rank:t.ranks[e]??0}}function _0(t,e,n,r){let i=0,o=n;while(i<o){let s=i+o>>1;if(t.toString("utf8",e[s],e[s+1])<r)i=s+1;else o=s}return i}function B0(t,e){let n=Buffer.from(e),r=t.tagCard.length,i=_0(t.tags,t.tagAt,r,e);if(i>=r||t.tags.compare(n,0,n.length,t.tagAt[i],t.tagAt[i+1])!==0)return;return t.tagCard[i]}var xf=/\s*[((][^()()]*[))]$/u,Uc={ko:4,en:4,ja:5,zh:3};function hP(t){if(!t)return[];let e=/\p{Script=Hangul}/u,n=/^[\p{Script=Latin}\p{N}\s.'’-]+$/u,r=new Set([...t.names,...t.generated].filter((d)=>!xf.test(d))),i=(d)=>!xf.test(d)||!r.has(d.replace(xf,"")),o=t.names.filter(i),s=o.filter((d)=>e.test(d)),a=[...s,...t.generated.slice(0,s.length>0?0:2)],c=o.filter((d)=>n.test(d)),u=t.japanese.filter(i),l=o.filter((d)=>!e.test(d)&&!n.test(d)&&!u.includes(d));return[...new Set([...a.slice(0,Uc.ko),...c.slice(0,Uc.en),...u.slice(0,Uc.ja),...l.slice(0,Uc.zh)])]}var To;function Kc(t,e=Lo()){if(!t)return[];if(!To)try{To=JSON.parse(Wc(Ho(Rr(e),"aliases.json"),"utf8")).tags}catch{To={}}return To[t]??[]}function Rf(t,e=Lo()){try{return mP(t,e)}catch{return new Map}}function mP(t,e){let n=new Map,r=L0(e);if(r.length===0||t.length===0)return n;let i=F0(r),o=Ho(Rr(e),"aliases.json"),s;try{s=JSON.parse(Wc(o,"utf8"))}catch{}if(s?.stamp===i&&t.every((l)=>(l in s.tags))){To=s.tags;for(let l of t)n.set(l,s.tags[l]??[]);return n}let a=If(e);if(!a)return n;let c=new Set([...t,...s?.stamp===i?Object.keys(s.tags):[]]),u={};for(let l of c){let d=B0(a,l);u[l]=d===void 0?[]:hP(j0(a,d))}try{F(o,`${JSON.stringify({stamp:i,tags:u})}
248
+ `)}catch{}To=u;for(let l of t)n.set(l,u[l]??[]);return n}function Mi(t,e=Lo()){Rf(t.flatMap((n)=>n.booru?[n.booru]:[]),e)}var pP=0.25,gP=0.1;function G0(t,e,n=new Set,r=Lo()){let i=Co(t);if(!i||!Of(i))return[];let o=If(r);if(!o)return[];let s=Buffer.from(i),a=o.ownAt.length-1,c=new Set([...n].flatMap((l)=>B0(o,l)??[])),u=new Map;for(let l=_0(o.keys,o.keyAt,a,i);l<a;l++){let d=o.keyAt[l],f=o.keyAt[l+1]-d;if(f<s.length||o.keys.compare(s,0,s.length,d,d+s.length)!==0)break;let h=f===s.length;for(let m=o.ownAt[l];m<o.ownAt[l+1];m++){let g=o.owners[m],b=g>>>2,w=h?Math.max(0,(g&2?2:1)-(g&1?0:1)):0,k=(o.ranks[b]??0)+pP*w+(c.has(b)?gP:0);if((u.get(b)?.score??-1)<k)u.set(b,{score:k,key:l})}}return[...u].sort(([,l],[,d])=>d.score-l.score).slice(0,e).map(([l,{key:d}])=>{let f=j0(o,l),h=o.keys.toString("utf8",o.keyAt[d],o.keyAt[d+1]);return{tag:f.tags.find((m)=>n.has(m))??f.tag,name:[...f.names,...f.generated].find((m)=>Co(m).includes(h))??f.tag.replaceAll("_"," ")}})}function zc(t=Lo()){If(t)}import{existsSync as xP,readdirSync as Z0,readFileSync as OP}from"node:fs";import{basename as Q0,join as qc}from"node:path";import{existsSync as bP,readFileSync as U0}from"node:fs";import{homedir as W0}from"node:os";import{isAbsolute as K0,join as xi,resolve as wP}from"node:path";var q="official",_t="ttheme-market.toml",$P="https://www.schemastore.org/ttheme-market.json",z0="https://www.schemastore.org/ttheme-palette.json",D0=["$schema","name","description","owner","renames","force_remove_deleted_palettes","metadata"],q0=["name","email","url"],Fo="ttheme-market",kP=/^[a-z0-9](?:[a-z0-9]|-(?=[a-z0-9])){0,38}$/i,yP=/^[\w.-]{1,100}$/,vP=/^\w[\w.+/-]{0,199}$/;function Dn(t){return xi(t,"ttheme","installed.json")}function Bt(t){return t??[q]}function jo(t){try{let{markets:e}=JSON.parse(U0(Dn(t),"utf8"));return Bt(Array.isArray(e)?e.filter((n)=>typeof n==="string"):void 0)}catch{return[q]}}function ut(t){return K0(t)}function ae(t){return t!==q&&!ut(t)}function Pr(t){let e=t.indexOf("#");return ae(t)&&e>=0?t.slice(0,e):t}function Xs(t){let e=t.indexOf("#");return ae(t)&&e>=0?t.slice(e+1):void 0}function _o(t,e){return Pr(t)===Pr(e)}function Nr(t,e){return!ut(t)&&(e?.[t]??t===q)}function SP(t){return!vP.test(t)||t.includes("..")||t.includes("//")||/(?:[./]|\.lock)$/.test(t)}function Ar(t,e=process.cwd()){if(t===q)return q;if(t==="~"||t.startsWith("~/"))return xi(W0(),t.slice(1));if(t.startsWith(".")||K0(t))return wP(e,t);let[n="",r,...i]=t.split("#"),[o,s,...a]=n.replace(/^https:\/\/github\.com\//,"").replace(/\.git$/,"").split("/");if(!o||!kP.test(o)||!s||!yP.test(s)||a.length>0||i.length>0||r!==void 0&&SP(r))throw Error(`${t} is not a market — give a repository (alice/ttheme-dust, #v1 pins a tag or branch) or a path (./my-market)`);return`${o.toLowerCase()}/${s}${r===void 0?"":`#${r}`}`}function Y0(t){let e=Xs(t)?.split("/").map(encodeURIComponent).join("/")??"HEAD";return`https://codeload.github.com/${Pr(t)}/tar.gz/${e}`}function J0(t){return t.slice(0,t.indexOf("/"))}function Af(t){return xi(t,"ttheme","markets")}function Be(t,e){return xi(Af(t),`${Pr(e).replace("/","--")}.json`)}function Dc(t){return xi(t,"ttheme","market")}function Tf(t,e){return xi(Dc(t),e)}function EP(t,e){if(typeof t!=="string"||typeof e!=="string")return'needs a "name" and an [owner] table whose name is the GitHub handle';return xe(`${t}@${e}/x`)}function ce({owner:t,name:e}){return`${t}@${e}`}function V0({owner:t,name:e}){return`"$schema" = ${JSON.stringify($P)}
249
249
  name = ${JSON.stringify(e)}
250
250
 
251
251
  [owner]
252
252
  name = ${JSON.stringify(t)}
253
- `}function Qf(t,e,n,r){if(typeof n!=="string"||n===""||/\p{Cc}/u.test(n)||n.length>200)throw Error(`${t}: ${e} must be ${r}`);return n}function Zf(t,e,n){return n===void 0?void 0:Qf(t,e,n,"one line of text, 200 characters at most")}function Y2(t,e){if(e===void 0)return{};if(!e||typeof e!=="object"||Array.isArray(e))throw Error(`${t}: [renames] maps an old palette name to its new name, or to false once it is gone`);let n={};for(let[r,i]of Object.entries(e)){if(ve(r)||i!==!1&&(typeof i!=="string"||ve(i)))throw Error(`${t}: renames.${r} must map a palette name to a palette name, or to false`);n[r]=i}return n}function ed(t,e){let n;try{n=ai(t)}catch(d){throw Error(`${e} is not valid TOML — ${d.message.split(`
254
- `)[0]}`)}let r=Qf(e,"name",n.name,"the market name"),i=n.owner;if(!i||typeof i!=="object"||Array.isArray(i))throw Error(`${e}: owner is a table — [owner] with name = "<GitHub handle>"`);let s=i,o={name:Qf(e,"owner.name",s.name,"the GitHub handle")},a=Zf(e,"owner.email",s.email),c=Zf(e,"owner.url",s.url),u=Zf(e,"description",n.description),l=n.force_remove_deleted_palettes;if(l!==void 0&&typeof l!=="boolean")throw Error(`${e}: force_remove_deleted_palettes must be true or false`);let f=q2(o.name,r);if(f)throw Error(`${e} ${f}`);return{owner:o.name,name:r,about:{...o,...a?{email:a}:{},...c?{url:c}:{}},...u?{description:u}:{},renames:Y2(e,n.renames),forceRemove:l===!0}}function Fe(t){let e=mi(t,Ft);if(!G2(e))throw Error(`${t} has no ${Ft} — \`ttheme market init ${t}\` makes one`);return ed(qw(e,"utf8"),e)}function Z(t){if(t===z)return"the ttheme catalog";if(!ct(t))return`github.com/${t}`;let e=Yw();return t===e||t.startsWith(`${e}/`)?`~${t.slice(e.length)}`:t}var Fn="tt1:",i0=["background","foreground","cursor","selection",...Array.from({length:16},(t,e)=>`ansi${e}`)];function pi(t,e=!0){return Ss(t).filter(ct).flatMap((n)=>{try{let r=Fe(n);return[{dir:n,...r,id:ne(r)}]}catch(r){if(e)process.stderr.write(`ttheme: skipping the market at ${n} — ${r.message}
255
- `);return[]}})}function yc(t){return kc(t,"palettes")}function nd(t,e){return t<e?-1:t>e?1:0}function rd(t,e){let n=[],r=[];for(let i of t){let[s,o,a,...c]=i.split("/");if(s!=="palettes"||!o||o.startsWith(".")||c.length>0)continue;if(a===void 0){if(o.endsWith(".toml"))r.push({file:{path:e(i),slug:r0(o,".toml")},name:o})}else if(a.endsWith(".toml"))n.push({file:{path:e(i),slug:r0(a,".toml"),catalog:o},name:a})}return n.sort((i,s)=>nd(i.file.catalog??"",s.file.catalog??"")||nd(i.name,s.name)),r.sort((i,s)=>nd(i.name,s.name)),[...n,...r].map(({file:i})=>i)}function Os(t){let e=yc(t);if(!J2(e))return[];let n=n0(e,{withFileTypes:!0}).flatMap((r)=>r.isDirectory()?n0(kc(e,r.name)).map((i)=>`palettes/${r.name}/${i}`):[`palettes/${r.name}`]);return rd(n,(r)=>kc(t,r))}function Z2(t,e){let n=e.get(t.slug);if(n)return`${t.slug} is also ${n.catalog?`in ${n.catalog}`:"outside a catalog"} — a palette name is used once in a market`;let r=t.catalog===void 0?void 0:No(t.catalog);return r?`the catalog folder ${JSON.stringify(t.catalog)} ${r}`:void 0}function id(t,e){let n=lt(e);if(!n)throw Error(`${e} is an official palette — yours are named <you>@<market>/<palette>`);let r=pi(t,!1).find((s)=>s.id===n);if(!r)throw Error(`${n} is not a local market — \`ttheme market add <dir>\` adds the folder that holds it`);let i=ae(e);return Os(r.dir).find((s)=>s.slug===i)?.path??kc(yc(r.dir),`${i}.toml`)}function Q2(t,e,n=!1){let r=new Map;for(let s of e)if(s.group!==xo&&!r.has(s.group)){let o=e.find((a)=>a.group===s.group&&a.lead)?.name??"";r.set(s.group,{name:s.group,...s.native?{native:s.native}:{},lead:o})}let i=new Map(e.filter((s)=>!s.default&&!lt(s.name)).map((s)=>[s.name,{group:s.group,order:s.order}]));return{name:t,groups:r,bases:i,open:!0,...n?{foreign:!0}:{}}}function Cn(t,e,n,r=!1){let i=ae(t),{native:s,...o}=xf(`${i}.toml`,e,Q2(i,n,r)),a=lt(t);return{...o,name:t,...a?{group:a,lead:!1}:{}}}function re(t){return t?(e,n)=>process.stderr.write(`ttheme: skipping ${e} — ${n}
256
- `):()=>{}}function sd(t,e,n,r,i,s=!1){let o=new Map;return t.flatMap((a)=>{try{let c=Z2(a,o);if(c)throw Error(c);o.set(a.slug,a);let u=mn(Cn(`${n}/${a.slug}`,e(a),r,s));return[a.catalog?{...u,catalog:a.catalog}:u]}catch(c){return i(a.path,c.message),[]}})}function qe(t,e,n,r=re(!0)){return sd(Os(t),(i)=>V2(i.path,"utf8"),e,n,r)}function vc(t,e,n=!0){return pi(t,n).flatMap(({dir:r,id:i})=>qe(r,i,e,re(n)))}function od(t,e=t.name,n){return{name:e,...t.base?{base:t.base}:{},...t.group!==xo?{group:t.group}:{},ansiSource:t.ansiSource,...t.booru?{booru:t.booru}:{},...t.booruSites?{booruSites:t.booruSites}:{},signature:t.signatureSlots,background:t.background,foreground:t.foreground,cursor:t.cursor,selection:t.selection,ansi:t.ansi,...t.waived&&t.waived.length>0?{waive:t.waived,reason:n??"kept from the palette"}:{},...t.pictures?{pictures:t.pictures}:{}}}var Et=(t)=>JSON.stringify(t);function s0(t){return["[[picture]]",`site = ${Et(t.site)}`,`id = ${t.id}`,...t.size===void 0?[]:[`size = ${typeof t.size==="number"?t.size:Et(t.size)}`],...t.position===void 0?[]:[`position = ${Et(t.position)}`],...t.opacity===void 0?[]:[`opacity = ${t.opacity}`]]}function o0(t,e){return e.length===0?t:`${t.replace(/\n*$/,`
253
+ `}function Nf(t,e,n,r){if(typeof n!=="string"||n===""||/\p{Cc}/u.test(n)||n.length>200)throw Error(`${t}: ${e} must be ${r}`);return n}function Pf(t,e,n){return n===void 0?void 0:Nf(t,e,n,"one line of text, 200 characters at most")}function MP(t,e){if(e===void 0)return{};if(!e||typeof e!=="object"||Array.isArray(e))throw Error(`${t}: [renames] maps an old palette name to its new name, or to false once it is gone`);let n={};for(let[r,i]of Object.entries(e)){if(xe(r)||i!==!1&&(typeof i!=="string"||xe(i)))throw Error(`${t}: renames.${r} must map a palette name to a palette name, or to false`);n[r]=i}return n}function Hf(t,e){let n;try{n=wi(t)}catch(f){throw Error(`${e} is not valid TOML — ${f.message.split(`
254
+ `)[0]}`)}let r=Nf(e,"name",n.name,"the market name"),i=n.owner;if(!i||typeof i!=="object"||Array.isArray(i))throw Error(`${e}: owner is a table — [owner] with name = "<GitHub handle>"`);let o=i,s={name:Nf(e,"owner.name",o.name,"the GitHub handle")},a=Pf(e,"owner.email",o.email),c=Pf(e,"owner.url",o.url),u=Pf(e,"description",n.description),l=n.force_remove_deleted_palettes;if(l!==void 0&&typeof l!=="boolean")throw Error(`${e}: force_remove_deleted_palettes must be true or false`);let d=EP(s.name,r);if(d)throw Error(`${e} ${d}`);return{owner:s.name,name:r,about:{...s,...a?{email:a}:{},...c?{url:c}:{}},...u?{description:u}:{},renames:MP(e,n.renames),forceRemove:l===!0}}function Ge(t){let e=xi(t,_t);if(!bP(e))throw Error(`${t} has no ${_t} — \`ttheme market init ${t}\` makes one`);return Hf(U0(e,"utf8"),e)}function nt(t){if(t===q)return"the ttheme catalog";if(!ut(t))return`github.com/${t}`;let e=W0();return t===e||t.startsWith(`${e}/`)?`~${t.slice(e.length)}`:t}var Sn="tt1:",X0=["background","foreground","cursor","selection",...Array.from({length:16},(t,e)=>`ansi${e}`)];function Oi(t,e=!0){return jo(t).filter(ut).flatMap((n)=>{try{let r=Ge(n);return[{dir:n,...r,id:ce(r)}]}catch(r){if(e)process.stderr.write(`ttheme: skipping the market at ${n} — ${r.message}
255
+ `);return[]}})}function Yc(t){return qc(t,"palettes")}function Cf(t,e){return t<e?-1:t>e?1:0}function Lf(t,e){let n=[],r=[];for(let i of t){let[o,s,a,...c]=i.split("/");if(o!=="palettes"||!s||s.startsWith(".")||c.length>0)continue;if(a===void 0){if(s.endsWith(".toml"))r.push({file:{path:e(i),slug:Q0(s,".toml")},name:s})}else if(a.endsWith(".toml"))n.push({file:{path:e(i),slug:Q0(a,".toml"),catalog:s},name:a})}return n.sort((i,o)=>Cf(i.file.catalog??"",o.file.catalog??"")||Cf(i.name,o.name)),r.sort((i,o)=>Cf(i.name,o.name)),[...n,...r].map(({file:i})=>i)}function Bo(t){let e=Yc(t);if(!xP(e))return[];let n=Z0(e,{withFileTypes:!0}).flatMap((r)=>r.isDirectory()?Z0(qc(e,r.name)).map((i)=>`palettes/${r.name}/${i}`):[`palettes/${r.name}`]);return Lf(n,(r)=>qc(t,r))}function IP(t,e){let n=e.get(t.slug);if(n)return`${t.slug} is also ${n.catalog?`in ${n.catalog}`:"outside a catalog"} — a palette name is used once in a market`;let r=t.catalog===void 0?void 0:Ys(t.catalog);return r?`the catalog folder ${JSON.stringify(t.catalog)} ${r}`:void 0}function Ff(t,e){let n=lt(e);if(!n)throw Error(`${e} is an official palette — yours are named <you>@<market>/<palette>`);let r=Oi(t,!1).find((o)=>o.id===n);if(!r)throw Error(`${n} is not a local market — \`ttheme market add <dir>\` adds the folder that holds it`);let i=de(e);return Bo(r.dir).find((o)=>o.slug===i)?.path??qc(Yc(r.dir),`${i}.toml`)}function RP(t,e,n=!1){let r=new Map;for(let o of e)if(o.group!==zs&&!r.has(o.group)){let s=e.find((a)=>a.group===o.group&&a.lead)?.name??"";r.set(o.group,{name:o.group,...o.native?{native:o.native}:{},lead:s})}let i=new Map(e.filter((o)=>!o.default&&!lt(o.name)).map((o)=>[o.name,{group:o.group,order:o.order}]));return{name:t,groups:r,bases:i,open:!0,...n?{foreign:!0}:{}}}function En(t,e,n,r=!1){let i=de(t),{native:o,...s}=sf(`${i}.toml`,e,RP(i,n,r)),a=lt(t);return{...s,name:t,...a?{group:a,lead:!1}:{}}}function ue(t){return t?(e,n)=>process.stderr.write(`ttheme: skipping ${e} — ${n}
256
+ `):()=>{}}function jf(t,e,n,r,i,o=!1){let s=new Map;return t.flatMap((a)=>{try{let c=IP(a,s);if(c)throw Error(c);s.set(a.slug,a);let u=Qe(En(`${n}/${a.slug}`,e(a),r,o));return[a.catalog?{...u,catalog:a.catalog}:u]}catch(c){return i(a.path,c.message),[]}})}function Xe(t,e,n,r=ue(!0)){return jf(Bo(t),(i)=>OP(i.path,"utf8"),e,n,r)}function Jc(t,e,n=!0){return Oi(t,n).flatMap(({dir:r,id:i})=>Xe(r,i,e,ue(n)))}function _f(t,e=t.name,n){return{name:e,...t.base?{base:t.base}:{},...t.group!==zs?{group:t.group}:{},ansiSource:t.ansiSource,...t.booru?{booru:t.booru}:{},...t.booruSites?{booruSites:t.booruSites}:{},signature:t.signatureSlots,background:t.background,foreground:t.foreground,cursor:t.cursor,selection:t.selection,ansi:t.ansi,...t.waived&&t.waived.length>0?{waive:t.waived,reason:n??"kept from the palette"}:{},...t.pictures?{pictures:t.pictures}:{}}}var xt=(t)=>JSON.stringify(t);function t$(t){return["[[picture]]",`site = ${xt(t.site)}`,`id = ${t.id}`,...t.size===void 0?[]:[`size = ${typeof t.size==="number"?t.size:xt(t.size)}`],...t.position===void 0?[]:[`position = ${xt(t.position)}`],...t.opacity===void 0?[]:[`opacity = ${t.opacity}`]]}function e$(t,e){return e.length===0?t:`${t.replace(/\n*$/,`
257
257
  `)}${e.map((n)=>`
258
- ${s0(n).join(`
258
+ ${t$(n).join(`
259
259
  `)}
260
- `).join("")}`}function ad(t){let e=[`"$schema" = ${Et(Vw)}`,"","[meta]",`name = ${Et(ae(t.name))}`,...t.base?[`base = ${Et(t.base)}`]:[],...t.group?[`group = ${Et(t.group)}`]:[],...t.ansiSource?[`ansi_source = ${Et(t.ansiSource)}`]:[],...t.booru?[`booru = ${Et(t.booru)}`]:[],`signature = [${t.signature.map(Et).join(", ")}]`,...t.booruSites?["","[meta.booru_sites]",...Object.entries(t.booruSites).map(([n,r])=>`${n} = [${r.map(Et).join(", ")}]`)]:[],"","[colors]",`background = ${Et(t.background)}`,`foreground = ${Et(t.foreground)}`,`cursor = ${Et(t.cursor)}`,`selection_background = ${Et(t.selection)}`,"ansi = [",...t.ansi.slice(0,8).map((n)=>` ${Et(n)},`),"",...t.ansi.slice(8).map((n)=>` ${Et(n)},`),"]"];if(t.waive&&t.waive.length>0)e.push("","[contrast]",`waive = [${t.waive.map(Et).join(", ")}]`,`reason = ${Et(t.reason??"")}`);for(let n of t.pictures??[])e.push("",...s0(n));return`${e.join(`
260
+ `).join("")}`}function Bf(t){let e=[`"$schema" = ${xt(z0)}`,"","[meta]",`name = ${xt(de(t.name))}`,...t.base?[`base = ${xt(t.base)}`]:[],...t.group?[`group = ${xt(t.group)}`]:[],...t.ansiSource?[`ansi_source = ${xt(t.ansiSource)}`]:[],...t.booru?[`booru = ${xt(t.booru)}`]:[],`signature = [${t.signature.map(xt).join(", ")}]`,...t.booruSites?["","[meta.booru_sites]",...Object.entries(t.booruSites).map(([n,r])=>`${n} = [${r.map(xt).join(", ")}]`)]:[],"","[colors]",`background = ${xt(t.background)}`,`foreground = ${xt(t.foreground)}`,`cursor = ${xt(t.cursor)}`,`selection_background = ${xt(t.selection)}`,"ansi = [",...t.ansi.slice(0,8).map((n)=>` ${xt(n)},`),"",...t.ansi.slice(8).map((n)=>` ${xt(n)},`),"]"];if(t.waive&&t.waive.length>0)e.push("","[contrast]",`waive = [${t.waive.map(xt).join(", ")}]`,`reason = ${xt(t.reason??"")}`);for(let n of t.pictures??[])e.push("",...t$(n));return`${e.join(`
261
261
  `)}
262
- `}class a0{bytes=[];u8(t){this.bytes.push(t&255)}u16(t){this.u8(t>>8),this.u8(t)}u32(t){this.u16(Math.floor(t/65536)),this.u16(t%65536)}str(t=""){let e=new TextEncoder().encode(t);if(e.length>255)throw Error(`"${t}" is too long to share`);this.u8(e.length),this.bytes.push(...e)}color(t){let e=Number.parseInt(t.slice(1),16);this.u8(e>>16),this.u8(e>>8),this.u8(e)}done(){return Buffer.from(this.bytes).toString("base64url")}}class c0{at=0;bytes;constructor(t){this.bytes=t}u8(){let t=this.bytes[this.at++];if(t===void 0)throw Error("the share code is cut short");return t}u16(){return this.u8()*256+this.u8()}u32(){return this.u16()*65536+this.u16()}str(){let t=this.u8(),e=this.bytes.subarray(this.at,this.at+t);if(e.length!==t)throw Error("the share code is cut short");return this.at+=t,new TextDecoder("utf-8",{fatal:!0}).decode(e)}color(){return`#${[this.u8(),this.u8(),this.u8()].map((t)=>t.toString(16).padStart(2,"0")).join("")}`}end(){if(this.at!==this.bytes.length)throw Error("the share code has bytes left over")}}function u0(t){let e=new a0;e.str(t.name);for(let r of[t.background,t.foreground,t.cursor,t.selection,...t.ansi])e.color(r);for(let r of t.signature)e.u8(i0.indexOf(r));e.str(t.base),e.str(t.group),e.str(t.ansiSource),e.str(t.booru),e.u16((t.waive??[]).reduce((r,i)=>r|1<<Kl.indexOf(i),0)),e.str(t.waive&&t.waive.length>0?t.reason:"");let n=t.pictures??[];e.u8(n.length);for(let r of n)e.u8(Y.findIndex((i)=>i.key===r.site)),e.u32(r.id),e.u16(r.size===void 0?0:r.size==="fill"?1:r.size),e.u8(r.position===void 0?0:Ut.indexOf(r.position)+1),e.u16(r.opacity===void 0?0:Math.round(r.opacity*1000)+1);return`${Fn}${e.done()}`}function l0(t){if(!t.startsWith(Fn))throw Error(`a share code starts with ${Fn}`);let e=t.slice(Fn.length);if(!/^[A-Za-z0-9_-]+$/.test(e))throw Error("the share code holds characters it never uses — was it copied whole?");let n=new c0(new Uint8Array(Buffer.from(e,"base64url"))),r=n.str(),[i,s,o,a,...c]=Array.from({length:20},()=>n.color()),u=[n.u8(),n.u8(),n.u8()].map((y)=>i0[y]??`slot${y}`),l=n.str(),f=n.str(),d=n.str(),h=n.str(),m=n.u16(),$=n.str(),g=Kl.filter((y,E)=>m&1<<E),b=Array.from({length:n.u8()},()=>{let y=Y[n.u8()]?.key??"unknown",E=n.u32(),S=n.u16(),x=n.u8(),R=n.u16();return{site:y,id:E,...S===1?{size:"fill"}:S>1?{size:S}:{},...x>0?{position:Ut[x-1]??"unknown"}:{},...R>0?{opacity:(R-1)/1000}:{}}});if(n.end(),![i,s,o,a,...c].every(oe))throw Error("the share code holds a color that is not one");return{name:r,...l?{base:l}:{},...f?{group:f}:{},...d?{ansiSource:d}:{},...h?{booru:h}:{},signature:u,background:i,foreground:s,cursor:o,selection:a,ansi:c,...g.length>0?{waive:g,reason:$}:{},...b.length>0?{pictures:b}:{}}}function cd(t){return{background:t.background,foreground:t.foreground,cursor:t.cursor,selection:t.selectionBackground,ansi:t.ansi}}function ud(t,e){let n=t.indexOf("ansi = ["),r=t.indexOf("]",n);if(n<0||r<0)throw Error("no ansi = [...] list to rewrite");let i=0,s=t.slice(n,r).replace(/"#[0-9a-fA-F]{6}"/g,()=>Et(e.ansi[i++]));return[["background",e.background],["foreground",e.foreground],["cursor",e.cursor],["selection_background",e.selection]].reduce((a,[c,u])=>a.replace(new RegExp(`^(${c}\\s*=\\s*)"#[0-9a-fA-F]{6}"`,"m"),(l,f)=>`${f}${Et(u)}`),t.slice(0,n)+s+t.slice(r))}function f0(t,e){return t.replace(/^(signature\s*=\s*)\[[^\]]*\]/m,(n,r)=>`${r}[${e.map(Et).join(", ")}]`)}function Co(t){let e=on(De(t)),n=new Set(t.waived??[]),r=Math.max(...we.map((i)=>i.label.length));return we.map((i,s)=>{let o=e[s],a=n.has(i.rule)||Number.isNaN(o)||(i.min===void 0||o>=i.min)&&(i.max===void 0||o<=i.max),c=i.min!==void 0?`≥ ${i.min}`:i.max!==void 0?`≤ ${i.max}`:"",u=Number.isNaN(o)?"—":Number.isInteger(o)?String(o):o.toFixed(2);return` ${a?"✓":"✗"} ${i.label.padEnd(r)} ${u.padStart(6)} ${c}${n.has(i.rule)?" waived":""}`})}import{existsSync as X2,readFileSync as tR,rmSync as eR}from"node:fs";import{join as nR}from"node:path";var Sc=["background","foreground","cursor","selection",...Array.from({length:16},(t,e)=>`ansi${e}`)],rR=1;function d0(t){return nR(t,"ttheme","tone.json")}function h0(t){return Sc.includes(t)}function pn(t){let e=d0(t);if(!X2(e))return{};let n;try{n=JSON.parse(tR(e,"utf8"))}catch{return{}}let r=n?.palettes;if(typeof r!=="object"||r===null)return{};let i={};for(let[s,o]of Object.entries(r)){if(typeof o!=="object"||o===null)continue;let a={};for(let[c,u]of Object.entries(o))if(h0(c)&&typeof u==="string"&&oe(u.toLowerCase()))a[c]=u.toLowerCase();if(Object.keys(a).length>0)i[s]=a}return i}function ld(t,e){let n=d0(t),r=Object.fromEntries(Object.entries(e).filter(([,i])=>Object.keys(i).length>0));if(Object.keys(r).length===0){eR(n,{force:!0});return}P(n,`${JSON.stringify({version:rR,palettes:r},null,2)}
263
- `)}function Ec(t,e){if(e==="background"||e==="foreground"||e==="cursor"||e==="selection")return t[e];return t.ansi[Number(e.slice(4))]}function fd(t,e){let n={};return Sc.forEach((r,i)=>{let s=e[i].toLowerCase();if(s!==Ec(t,r).toLowerCase())n[r]=s}),n}function xs(t,e){if(!e)return t;let n=(u)=>e[u]===void 0||e[u]===Ec(t,u).toLowerCase();if(Sc.every(n))return t;let r=(u)=>e[u]??Ec(t,u),i={background:r("background"),foreground:r("foreground"),cursor:r("cursor"),selection:r("selection"),ansi:Sc.slice(4).map(r)},s=t.signatureSlots.map((u)=>h0(u)?r(u):Ec(i,u)),o={...t,...i,signature:s},a=De(o),c=hn({name:o.name,background:i.background,foreground:i.foreground,cursor:i.cursor,selection:i.selection,ansi:i.ansi,waived:a.waive},o.signatureSlots);return{...o,gate:on(a),backdrop:c}}function Mc(t,e){return Object.keys(e).length===0?t:t.map((n)=>xs(n,e[n.name]))}function m0(t,e,n){let r={...t};if(Object.keys(n).length===0)delete r[e];else r[e]=n;return r}function p0(t,e,n){let r=pn(t);if(!Object.keys(r).some((s)=>e.has(s)||n.includes(s)))return;ld(t,Object.fromEntries(Object.entries(r).filter(([s])=>!n.includes(s)).map(([s,o])=>[e.get(s)??s,o])))}var w0="https://kecan0406.github.io/ttheme/manifest.json",$0=20000;function Me(t){return b0(t,"ttheme","catalog.json")}function Oc(t,e){P(Me(t),`${JSON.stringify(e,null,2)}
264
- `)}function ut(t,e=!0,n){let r=Ss(t),i=Me(t),s=mc();if(r.includes(z))if(n)s=n;else{if(!g0(i))throw Error(`no catalog at ${i} — run \`ttheme init\` first`);s=Je(dd(i,"utf8"))}let o=r.filter(ee).flatMap((a)=>sR(t,a,s.palettes,e));return{...s,palettes:[...s.palettes,...o]}}function iR(t){let e;try{e=JSON.parse(t)}catch{throw Error("is not valid JSON")}let n=e?.files;if(!n||typeof n!=="object"||Object.values(n).some((r)=>typeof r!=="string"))throw Error("is not a copy of a market this ttheme fetched — `ttheme update` fetches it again");return{...typeof e?.etag==="string"?{etag:e.etag}:{},files:n}}function Ye(t,e){return iR(dd(He(t,e),"utf8"))}function k0(t,e){return ne({owner:t0(t),name:e.name})}function y0(t,e){let n=e.files[Ft];if(n===void 0)throw Error(`${Z(t)} has no ${Ft} — \`ttheme market init\` makes one`);return ed(n,Ft)}function xc(t,e){return k0(t,y0(t,e))}function Ln(t,e,n,r){let i=y0(t,e),s=k0(t,i),o=Z(t),a=new Map(Object.entries(e.files).map(([u,l])=>[`${o}/${u}`,l])),c=rd(Object.keys(e.files),(u)=>`${o}/${u}`);return{id:s,info:i,entries:sd(c,(u)=>a.get(u.path)??"",s,n,r,!0)}}function sR(t,e,n,r){let i=He(t,e);if(!g0(i))return[];try{return Ln(e,Ye(t,e),n,re(!1)).entries}catch(s){if(r)process.stderr.write(`ttheme: skipping ${i} — ${s.message}
265
- `);return[]}}function Je(t){let e;try{e=JSON.parse(t)}catch{throw Error("catalog is not valid JSON")}let n=e?.schema;if(n===void 0)throw Error("catalog has no schema — `ttheme update` fetches it again");Fw(n,"catalog",Wf);let r=e;if(typeof r.version!=="string"||!Array.isArray(r.palettes))throw Error("catalog has no version or palettes");for(let i of r.palettes){let s=v0(i);if(s)throw Error(`catalog entry ${JSON.stringify(i?.name)} ${s}`)}return r}function v0(t){if(typeof t?.name!=="string"||!Array.isArray(t.ansi)||t.ansi.length!==16)return"is missing name or its 16 ANSI colors";let e=ve(t.name)??(t.base===void 0?void 0:ve(t.base));if(e)return e;if(![t.background,t.foreground,t.cursor,t.selection,...t.ansi].every((n)=>typeof n==="string"&&oe(n)))return'holds a color that is not "#rrggbb"';for(let n of[t.group,t.native??"-",t.catalog??"-",t.ansiSource]){let r=typeof n==="string"?No(n):"has a field that is not text";if(r)return r}return}function E0(t){return b0(t,"ttheme","kept.json")}function Ic(t,e){P(E0(t),`${JSON.stringify({palettes:e},null,2)}
266
- `)}function jn(t){try{let{palettes:e}=JSON.parse(dd(E0(t),"utf8"));return Array.isArray(e)?e.filter((n)=>v0(n)===void 0):[]}catch{return[]}}function gi(t,e,n=!0){let r=[...e.palettes,...vc(t,e.palettes,n)],i=new Set(r.map((s)=>s.name));return{...e,palettes:[...r,...jn(t).filter((s)=>!i.has(s.name))]}}function Ot(t,e,n=!0){let r=gi(t,e,n);return{...r,palettes:Mc(r.palettes,pn(t))}}function ue(t){return Ot(t,ut(t))}class Rc extends Error{}class Nc extends Error{}async function hd(t,e=$0,n,r={}){let i;try{let s=AbortSignal.timeout(e);i=await fetch(t,{headers:r,signal:n?AbortSignal.any([s,n]):s})}catch(s){throw Error(`cannot reach ${t} — ${s instanceof Error?s.message:String(s)}`)}if(i.status===404)throw new Rc(`nothing at ${t}`);if(i.status===403||i.status===429)throw new Nc(`${new URL(t).host} is turning requests away for now (${i.status}) — try again in a minute`);if(!i.ok&&i.status!==304)throw Error(`${t} answered ${i.status}`);return i}async function Tc(t,e,n=$0,r){return e(await(await hd(t,n,r)).text())}function Lo(t){let e=new Set(t.waived??[]),n=t.gate??on(De(t));return we.flatMap((r,i)=>{let s=n[i];if(e.has(r.rule)||typeof s!=="number"||Number.isNaN(s))return[];if(r.min!==void 0&&s<r.min)return[`${r.label} ${s} < ${r.min}`];if(r.max!==void 0&&s>r.max)return[`${r.label} ${s} > ${r.max}`];return[]})}function _n(t,e){let n=t.find((r)=>r.name===e);if(!n)throw Error(`no palette named ${e} in the catalog — ${md(t,[e])}`);return n}function md(t,e){let n=e.map((o)=>o.toLowerCase()),r=t.filter((o)=>n.some((a)=>o.name.includes(a))),i=t.filter((o)=>!r.includes(o)&&n.some((a)=>o.group.toLowerCase().includes(a))),s=[...r,...i].map((o)=>o.name).slice(0,3);return s.length>0?`did you mean: ${s.join(", ")}?`:"`ttheme list` shows what is there"}function S0(t,e){return t.filter((n)=>di([n.name,n.group,n.native??"",n.ansiSource,...n.nativeNames??[],...bc(n.booru)],e))}function M0(t,e,n){let r=n.toLowerCase(),i=(s)=>s.name===e.name?0:s.group===e.group?1:2;return t.filter((s)=>s.booru?.toLowerCase().includes(r)).map((s,o)=>({p:s,at:o})).sort((s,o)=>i(s.p)-i(o.p)||s.at-o.at).map(({p:s})=>s)}function O0(t,e){return t.booruSites?.[e]??(t.booru?[t.booru]:[])}var oR=9999,Is;function le(t,e){if(!Is||e===""||Is.length>=oR)return e;return`\x1B[?${Is.push(t)}y${e}\x1B[?0y`}function Ac(t){let e=Is,n=[];Is=n;try{return{drawn:t(),targets:n}}finally{Is=e}}function aR(t){let e=t.slice(3,-1);return t.startsWith("\x1B[?")&&t.endsWith("y")&&/^\d{1,4}$/.test(e)?Number(e):void 0}function cR(t){let e=t.slice(2,-1);return t.startsWith("\x1B[")&&t.endsWith("G")&&/^\d*$/.test(e)?Math.max(1,Number(e||1))-1:void 0}function uR(t,e,n){if(!t.includes("\x1B[?"))return{text:t,zones:[]};let r=[],i=[],s="",o=0,a="",c=()=>{let l=i.pop();if(l&&o>l.col)r.push({row:e,col:l.col,width:o-l.col,height:1,target:l.target})},u=0;while(u<t.length){let l=t.indexOf("\x1B",u);if(l!==u){let m=l===-1?t.length:l;a+=t.slice(u,m),s+=t.slice(u,m),u=m;continue}let f=t.slice(u,u+(_l(t,u)||1));u+=f.length;let d=aR(f),h=d===void 0?cR(f):void 0;if(d===void 0&&h===void 0){s+=f;continue}if(o+=X(a),a="",h!==void 0)o=h,s+=f;else if(d===0)c();else if(d!==void 0)i.push({target:n[d-1],col:o})}o+=X(a);while(i.length>0)c();return{text:s,zones:r}}function Pc(t,e){let n=[];return{lines:t.map((i,s)=>{let o=uR(i,s,e);return n.push(...o.zones),o.text}),zones:n}}function x0(t,e,n){let r=n-t.col,i=e-t.row;return{target:t.target,x:r,y:i,width:t.width,height:t.height,inside:r>=0&&r<t.width&&i>=0&&i<t.height}}function lR(t,e,n){let r;for(let i of t)if(e>=i.row&&e<i.row+i.height&&n>=i.col&&n<i.col+i.width&&(!r||i.width*i.height<=r.width*r.height))r=i;return r}var fR={space:" ",enter:"enter",esc:"esc",tab:"tab",bksp:"backspace","←":"left","→":"right"};function pd(t){let e=/^(ctrl|alt)\+([a-z])$/.exec(t);if(e)return`${e[1]}-${e[2]}`;return fR[t]??([...t].length===1&&t!==" "?t:void 0)}function gn(t,e){let n=pd(t);return n?le({kind:"key",key:n},e):e}class jo{zones=[];held;point(t){if(t.action==="drag"||t.action==="release"){let n=this.held;if(t.action==="release")this.held=void 0;return n&&x0(n,t.row,t.col)}let e=lR(this.zones,t.row,t.col);if(t.action==="press")this.held=t.button==="left"?e:void 0;return e&&x0(e,t.row,t.col)}drop(){this.held=void 0}}var Gn=[{name:"preview",title:"Preview"},{name:"browse",title:"Browse"}],Hc=10,Fc=20,dR="\x1B[7;1m\x1B[36m";function I0(t){return Gn.find((e)=>e.name===t.TTHEME_HUB)?.name}function R0(t,e){let n=Gn.findIndex((r)=>r.name===t);return Fc+(n+e+Gn.length)%Gn.length+1}function N0(t){return Fc+Gn.findIndex((e)=>e.name===t)+1}function gd(t,e){let n=Gn.map(({name:i,title:s})=>{let o={kind:"hub",tab:i};if(!e)return le(o,i===t?`[${s}]`:` ${s} `);return i===t?`${dR}${le(o,` ${s} `)}${At}`:`${A}${le(o,` ${s} `)}${At}`}),r="tab next";return` ${n.join(" ")} ${e?`${A}tab next${At}`:"tab next"}`}import{execFileSync as lA}from"node:child_process";import{existsSync as Au,mkdirSync as fA,readdirSync as dA,readFileSync as Pu,rmSync as Xk}from"node:fs";import{basename as ry,join as aa,relative as ty}from"node:path";import{styleText as Gc}from"node:util";import{stdout as B0,stdin as kR}from"node:process";import yR from"node:readline";var Cc="\x1B",F0="›",hR=39,wd="\x07",C0="[",mR="]",L0="m",$d=`${mR}8;;`,T0=new RegExp(`(?:\\${C0}(?<code>\\d+)m|\\${$d}(?<uri>.*)${wd})`,"y"),A0=(t)=>{if(t>=30&&t<=37)return 39;if(t>=90&&t<=97)return 39;if(t>=40&&t<=47)return 49;if(t>=100&&t<=107)return 49;if(t===1||t===2)return 22;if(t===3)return 23;if(t===4)return 24;if(t===7)return 27;if(t===8)return 28;if(t===9)return 29;if(t===0)return 0;return},P0=(t)=>`${Cc}${C0}${t}${L0}`,H0=(t)=>`${Cc}${$d}${t}${wd}`,bd=(t,e,n)=>{let r=e[Symbol.iterator](),i=!1,s=!1,o=t.at(-1),a=o===void 0?0:X(o),c=r.next(),u=r.next(),l=0;while(!c.done){let f=c.value,d=X(f);if(a+d<=n)t[t.length-1]+=f;else t.push(f),a=0;if(f===Cc||f===F0)i=!0,s=e.startsWith($d,l+1);if(i){if(s){if(f===wd)i=!1,s=!1}else if(f===L0)i=!1}else if(a+=d,a===n&&!u.done)t.push(""),a=0;c=u,u=r.next(),l+=f.length}if(o=t.at(-1),!a&&o!==void 0&&o.length&&t.length>1)t[t.length-2]+=t.pop()},pR=(t)=>{let e=t.split(" "),n=e.length;while(n){if(X(e[n-1]))break;n--}if(n===e.length)return t;return e.slice(0,n).join(" ")+e.slice(n).join("")},gR=(t,e,n={})=>{if(n.trim!==!1&&t.trim()==="")return"";let r="",i,s,o=t.split(" "),a=[""],c=0;for(let f=0;f<o.length;f++){let d=o[f];if(n.trim!==!1){let m=a.at(-1)??"",$=m.trimStart();if(m.length!==$.length)a[a.length-1]=$,c=X($)}if(f!==0){if(c>=e&&(n.wordWrap===!1||n.trim===!1))a.push(""),c=0;if(c||n.trim===!1)a[a.length-1]+=" ",c++}let h=X(d);if(n.hard&&h>e){let m=e-c,$=1+Math.floor((h-m-1)/e);if(Math.floor((h-1)/e)<$)a.push("");bd(a,d,e),c=X(a.at(-1)??"");continue}if(c+h>e&&c&&h){if(n.wordWrap===!1&&c<e){bd(a,d,e),c=X(a.at(-1)??"");continue}a.push(""),c=0}if(c+h>e&&n.wordWrap===!1){bd(a,d,e),c=X(a.at(-1)??"");continue}a[a.length-1]+=d,c+=h}if(n.trim!==!1)a=a.map((f)=>pR(f));let u=a.join(`
267
- `),l=!1;for(let f=0;f<u.length;f++){let d=u[f];if(r+=d,!l){if(l=d>="\uD800"&&d<="\uDBFF",l)continue}else l=!1;if(d===Cc||d===F0){T0.lastIndex=f+1;let m=T0.exec(u)?.groups;if(m?.code!==void 0){let $=Number.parseFloat(m.code);i=$===hR?void 0:$}else if(m?.uri!==void 0)s=m.uri.length===0?void 0:m.uri}if(u[f+1]===`
268
- `){if(s)r+=H0("");let h=i?A0(i):void 0;if(i&&h)r+=P0(h)}else if(d===`
269
- `){if(i&&A0(i))r+=P0(i);if(s)r+=H0(s)}}return r},bR=/\r?\n/;function vr(t,e,n){return String(t).normalize().split(bR).map((r)=>gR(r,e,n)).join(`
270
- `)}var Oe=Ll(yd(),1);function Bn(t,e,n){if(!n.some((o)=>!o.disabled))return t;let r=t+e,i=Math.max(n.length-1,0),s=r<0?i:r>i?0:r;return n[s]?.disabled?Bn(s,e<0?-1:1,n):s}function Lc(t,e,n,r){let i=r.split(`
271
- `),s=0,o=t;for(let c of i){if(o<=c.length)break;o-=c.length+1,s++}for(s=Math.max(0,Math.min(i.length-1,s+n)),o=Math.min(o,i[s].length)+e;o<0&&s>0;)s--,o+=i[s].length+1;for(;o>i[s].length&&s<i.length-1;)o-=i[s].length+1,s++;o=Math.max(0,Math.min(i[s].length,o));let a=0;for(let c=0;c<s;c++)a+=i[c].length+1;return a+o}var vR=["up","down","left","right","space","enter","cancel"],ER=["January","February","March","April","May","June","July","August","September","October","November","December"],Wt={actions:new Set(vR),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0,date:{monthNames:[...ER],messages:{required:"Please enter a valid date",invalidMonth:"There are only 12 months in a year",invalidDay:(t,e)=>`There are only ${t} days in ${e}`,afterMin:(t)=>`Date must be on or after ${t.toISOString().slice(0,10)}`,beforeMax:(t)=>`Date must be on or before ${t.toISOString().slice(0,10)}`}}};function U0(t,e){if(typeof t=="string")return Wt.aliases.get(t)===e;for(let n of t)if(n!==void 0&&U0(n,e))return!0;return!1}function SR(t,e){if(t===e)return;let n=t.split(`
262
+ `}class n${bytes=[];u8(t){this.bytes.push(t&255)}u16(t){this.u8(t>>8),this.u8(t)}u32(t){this.u16(Math.floor(t/65536)),this.u16(t%65536)}str(t=""){let e=new TextEncoder().encode(t);if(e.length>255)throw Error(`"${t}" is too long to share`);this.u8(e.length),this.bytes.push(...e)}color(t){let e=Number.parseInt(t.slice(1),16);this.u8(e>>16),this.u8(e>>8),this.u8(e)}done(){return Buffer.from(this.bytes).toString("base64url")}}class r${at=0;bytes;constructor(t){this.bytes=t}u8(){let t=this.bytes[this.at++];if(t===void 0)throw Error("the share code is cut short");return t}u16(){return this.u8()*256+this.u8()}u32(){return this.u16()*65536+this.u16()}str(){let t=this.u8(),e=this.bytes.subarray(this.at,this.at+t);if(e.length!==t)throw Error("the share code is cut short");return this.at+=t,new TextDecoder("utf-8",{fatal:!0}).decode(e)}color(){return`#${[this.u8(),this.u8(),this.u8()].map((t)=>t.toString(16).padStart(2,"0")).join("")}`}end(){if(this.at!==this.bytes.length)throw Error("the share code has bytes left over")}}function Gf(t){let e=new n$;e.str(t.name);for(let r of[t.background,t.foreground,t.cursor,t.selection,...t.ansi])e.color(r);for(let r of t.signature)e.u8(X0.indexOf(r));e.str(t.base),e.str(t.group),e.str(t.ansiSource),e.str(t.booru),e.u16((t.waive??[]).reduce((r,i)=>r|1<<Sd.indexOf(i),0)),e.str(t.waive&&t.waive.length>0?t.reason:"");let n=t.pictures??[];e.u8(n.length);for(let r of n)e.u8(J.findIndex((i)=>i.key===r.site)),e.u32(r.id),e.u16(r.size===void 0?0:r.size==="fill"?1:r.size),e.u8(r.position===void 0?0:Ut.indexOf(r.position)+1),e.u16(r.opacity===void 0?0:Math.round(r.opacity*1000)+1);return`${Sn}${e.done()}`}function Uf(t){if(!t.startsWith(Sn))throw Error(`a share code starts with ${Sn}`);let e=t.slice(Sn.length);if(!/^[A-Za-z0-9_-]+$/.test(e))throw Error("the share code holds characters it never uses — was it copied whole?");let n=new r$(new Uint8Array(Buffer.from(e,"base64url"))),r=n.str(),[i,o,s,a,...c]=Array.from({length:20},()=>n.color()),u=[n.u8(),n.u8(),n.u8()].map((k)=>X0[k]??`slot${k}`),l=n.str(),d=n.str(),f=n.str(),h=n.str(),m=n.u16(),g=n.str(),b=Sd.filter((k,v)=>m&1<<v),w=Array.from({length:n.u8()},()=>{let k=J[n.u8()]?.key??"unknown",v=n.u32(),S=n.u16(),M=n.u8(),I=n.u16();return{site:k,id:v,...S===1?{size:"fill"}:S>1?{size:S}:{},...M>0?{position:Ut[M-1]??"unknown"}:{},...I>0?{opacity:(I-1)/1000}:{}}});if(n.end(),![i,o,s,a,...c].every(le))throw Error("the share code holds a color that is not one");return{name:r,...l?{base:l}:{},...d?{group:d}:{},...f?{ansiSource:f}:{},...h?{booru:h}:{},signature:u,background:i,foreground:o,cursor:s,selection:a,ansi:c,...b.length>0?{waive:b,reason:g}:{},...w.length>0?{pictures:w}:{}}}function ta(t){return{background:t.background,foreground:t.foreground,cursor:t.cursor,selection:t.selectionBackground,ansi:t.ansi}}function Wf(t,e){let n=t.indexOf("ansi = ["),r=t.indexOf("]",n);if(n<0||r<0)throw Error("no ansi = [...] list to rewrite");let i=0,o=t.slice(n,r).replace(/"#[0-9a-fA-F]{6}"/g,()=>xt(e.ansi[i++]));return[["background",e.background],["foreground",e.foreground],["cursor",e.cursor],["selection_background",e.selection]].reduce((a,[c,u])=>a.replace(new RegExp(`^(${c}\\s*=\\s*)"#[0-9a-fA-F]{6}"`,"m"),(l,d)=>`${d}${xt(u)}`),t.slice(0,n)+o+t.slice(r))}function i$(t,e){return t.replace(/^(signature\s*=\s*)\[[^\]]*\]/m,(n,r)=>`${r}[${e.map(xt).join(", ")}]`)}function ea(t){let e=gn(Ie(t)),n=new Set(t.waived??[]),r=Math.max(...ve.map((i)=>i.label.length));return ve.map((i,o)=>{let s=e[o],a=n.has(i.rule)||Number.isNaN(s)||(i.min===void 0||s>=i.min)&&(i.max===void 0||s<=i.max),c=i.min!==void 0?`≥ ${i.min}`:i.max!==void 0?`≤ ${i.max}`:"",u=Number.isNaN(s)?"—":Number.isInteger(s)?String(s):s.toFixed(2);return` ${a?"✓":"✗"} ${i.label.padEnd(r)} ${u.padStart(6)} ${c}${n.has(i.rule)?" waived":""}`})}import{existsSync as PP,readFileSync as NP,rmSync as AP}from"node:fs";import{join as TP}from"node:path";var ra=["background","foreground","cursor","selection",...Array.from({length:16},(t,e)=>`ansi${e}`)],HP=1;function o$(t){return TP(t,"ttheme","tone.json")}function s$(t){return ra.includes(t)}function qn(t){let e=o$(t);if(!PP(e))return{};let n;try{n=JSON.parse(NP(e,"utf8"))}catch{return{}}let r=n?.palettes;if(typeof r!=="object"||r===null)return{};let i={};for(let[o,s]of Object.entries(r)){if(typeof s!=="object"||s===null)continue;let a={};for(let[c,u]of Object.entries(s))if(s$(c)&&typeof u==="string"&&le(u.toLowerCase()))a[c]=u.toLowerCase();if(Object.keys(a).length>0)i[o]=a}return i}function Kf(t,e){let n=o$(t),r=Object.fromEntries(Object.entries(e).filter(([,i])=>Object.keys(i).length>0));if(Object.keys(r).length===0){AP(n,{force:!0});return}F(n,`${JSON.stringify({version:HP,palettes:r},null,2)}
263
+ `)}function na(t,e){if(e==="background"||e==="foreground"||e==="cursor"||e==="selection")return t[e];return t.ansi[Number(e.slice(4))]}function a$(t){return ra.map((e)=>na(t,e))}function c$(t,e){let n={};return ra.forEach((r,i)=>{let o=e[i].toLowerCase();if(o!==na(t,r).toLowerCase())n[r]=o}),n}function Vc(t,e){if(!e)return t;let n=(u)=>e[u]===void 0||e[u]===na(t,u).toLowerCase();if(ra.every(n))return t;let r=(u)=>e[u]??na(t,u),i={background:r("background"),foreground:r("foreground"),cursor:r("cursor"),selection:r("selection"),ansi:ra.slice(4).map(r)},o=t.signatureSlots.map((u)=>s$(u)?r(u):na(i,u)),s={...t,...i,signature:o},a=Ie(s),c=vn({name:s.name,background:i.background,foreground:i.foreground,cursor:i.cursor,selection:i.selection,ansi:i.ansi,waived:a.waive},s.signatureSlots);return{...s,gate:gn(a),backdrop:c}}function Zc(t,e){return Object.keys(e).length===0?t:t.map((n)=>Vc(n,e[n.name]))}function u$(t,e,n){let r={...t};if(Object.keys(n).length===0)delete r[e];else r[e]=n;return r}function l$(t,e,n){let r=qn(t);if(!Object.keys(r).some((o)=>e.has(o)||n.includes(o)))return;Kf(t,Object.fromEntries(Object.entries(r).filter(([o])=>!n.includes(o)).map(([o,s])=>[e.get(o)??o,s])))}var h$="https://kecan0406.github.io/ttheme/manifest.json",m$=20000;function Re(t){return f$(t,"ttheme","catalog.json")}function Qc(t,e){F(Re(t),`${JSON.stringify(e,null,2)}
264
+ `)}function dt(t,e=!0,n){let r=jo(t),i=Re(t),o=Gc();if(r.includes(q))if(n)o=n;else{if(!d$(i))throw Error(`no catalog at ${i} — run \`ttheme init\` first`);o=en(zf(i,"utf8"))}let s=r.filter(ae).flatMap((a)=>LP(t,a,o.palettes,e));return{...o,palettes:[...o.palettes,...s]}}function CP(t){let e;try{e=JSON.parse(t)}catch{throw Error("is not valid JSON")}let n=e?.files;if(!n||typeof n!=="object"||Object.values(n).some((r)=>typeof r!=="string"))throw Error("is not a copy of a market this ttheme fetched — `ttheme update` fetches it again");return{...typeof e?.etag==="string"?{etag:e.etag}:{},files:n}}function tn(t,e){return CP(zf(Be(t,e),"utf8"))}function p$(t,e){return ce({owner:J0(t),name:e.name})}function g$(t,e){let n=e.files[_t];if(n===void 0)throw Error(`${nt(t)} has no ${_t} — \`ttheme market init\` makes one`);return Hf(n,_t)}function Xc(t,e){return p$(t,g$(t,e))}function Yn(t,e,n,r){let i=g$(t,e),o=p$(t,i),s=nt(t),a=new Map(Object.entries(e.files).map(([u,l])=>[`${s}/${u}`,l])),c=Lf(Object.keys(e.files),(u)=>`${s}/${u}`);return{id:o,info:i,entries:jf(c,(u)=>a.get(u.path)??"",o,n,r,!0)}}function LP(t,e,n,r){let i=Be(t,e);if(!d$(i))return[];try{return Yn(e,tn(t,e),n,ue(!1)).entries}catch(o){if(r)process.stderr.write(`ttheme: skipping ${i} — ${o.message}
265
+ `);return[]}}function en(t){let e;try{e=JSON.parse(t)}catch{throw Error("catalog is not valid JSON")}let n=e?.schema;if(n===void 0)throw Error("catalog has no schema — `ttheme update` fetches it again");P0(n,"catalog",vf);let r=e;if(typeof r.version!=="string"||!Array.isArray(r.palettes))throw Error("catalog has no version or palettes");for(let i of r.palettes){let o=b$(i);if(o)throw Error(`catalog entry ${JSON.stringify(i?.name)} ${o}`)}return r}function b$(t){if(typeof t?.name!=="string"||!Array.isArray(t.ansi)||t.ansi.length!==16)return"is missing name or its 16 ANSI colors";let e=xe(t.name)??(t.base===void 0?void 0:xe(t.base));if(e)return e;if(![t.background,t.foreground,t.cursor,t.selection,...t.ansi].every((n)=>typeof n==="string"&&le(n)))return'holds a color that is not "#rrggbb"';for(let n of[t.group,t.native??"-",t.catalog??"-",t.ansiSource]){let r=typeof n==="string"?Ys(n):"has a field that is not text";if(r)return r}return}function w$(t){return f$(t,"ttheme","kept.json")}function tu(t,e){F(w$(t),`${JSON.stringify({palettes:e},null,2)}
266
+ `)}function Jn(t){try{let{palettes:e}=JSON.parse(zf(w$(t),"utf8"));return Array.isArray(e)?e.filter((n)=>b$(n)===void 0):[]}catch{return[]}}function Go(t,e,n=!0){let r=[...e.palettes,...Jc(t,e.palettes,n)],i=new Set(r.map((o)=>o.name));return{...e,palettes:[...r,...Jn(t).filter((o)=>!i.has(o.name))]}}function Rt(t,e,n=!0){let r=Go(t,e,n);return{...r,palettes:Zc(r.palettes,qn(t))}}function he(t){return Rt(t,dt(t))}class eu extends Error{}class nu extends Error{}async function Df(t,e=m$,n,r={}){let i;try{let o=AbortSignal.timeout(e);i=await fetch(t,{headers:r,signal:n?AbortSignal.any([o,n]):o})}catch(o){throw Error(`cannot reach ${t} — ${o instanceof Error?o.message:String(o)}`)}if(i.status===404)throw new eu(`nothing at ${t}`);if(i.status===403||i.status===429)throw new nu(`${new URL(t).host} is turning requests away for now (${i.status}) — try again in a minute`);if(!i.ok&&i.status!==304)throw Error(`${t} answered ${i.status}`);return i}async function ru(t,e,n=m$,r){return e(await(await Df(t,n,r)).text())}function ia(t){let e=new Set(t.waived??[]),n=t.gate??gn(Ie(t));return ve.flatMap((r,i)=>{let o=n[i];if(e.has(r.rule)||typeof o!=="number"||Number.isNaN(o))return[];if(r.min!==void 0&&o<r.min)return[`${r.label} ${o} < ${r.min}`];if(r.max!==void 0&&o>r.max)return[`${r.label} ${o} > ${r.max}`];return[]})}function Tr(t,e){let n=t.find((r)=>r.name===e);if(!n)throw Error(`no palette named ${e} in the catalog — ${qf(t,[e])}`);return n}function qf(t,e){let n=e.map((s)=>s.toLowerCase()),r=t.filter((s)=>n.some((a)=>s.name.includes(a))),i=t.filter((s)=>!r.includes(s)&&n.some((a)=>s.group.toLowerCase().includes(a))),o=[...r,...i].map((s)=>s.name).slice(0,3);return o.length>0?`did you mean: ${o.join(", ")}?`:"`ttheme list` shows what is there"}function $$(t,e){return t.filter((n)=>Ei([n.name,n.group,n.native??"",n.ansiSource,...n.nativeNames??[],...Kc(n.booru)],e))}function k$(t,e,n){let r=n.toLowerCase(),i=(o)=>o.name===e.name?0:o.group===e.group?1:2;return t.filter((o)=>o.booru?.toLowerCase().includes(r)).map((o,s)=>({p:o,at:s})).sort((o,s)=>i(o.p)-i(s.p)||o.at-s.at).map(({p:o})=>o)}function y$(t,e){return t.booruSites?.[e]??(t.booru?[t.booru]:[])}var FP=9999,Uo;function Vt(t,e){if(!Uo||e===""||Uo.length>=FP)return e;return`\x1B[?${Uo.push(t)}y${e}\x1B[?0y`}function S$(t){let e=Uo,n=[];Uo=n;try{return{drawn:t(),targets:n}}finally{Uo=e}}function E$(t){let e=t.slice(3,-1);return t.startsWith("\x1B[?")&&t.endsWith("y")&&/^\d{1,4}$/.test(e)?Number(e):void 0}function jP(t){let e=t.slice(2,-1);return t.startsWith("\x1B[")&&t.endsWith("G")&&/^\d*$/.test(e)?Math.max(1,Number(e||1))-1:void 0}function _P(t,e,n){if(!t.includes("\x1B[?"))return{text:t,zones:[]};let r=[],i=[],o="",s=0,a="",c=()=>{let l=i.pop();if(l&&s>l.col)r.push({row:e,col:l.col,width:s-l.col,height:1,target:l.target})},u=0;while(u<t.length){let l=t.indexOf("\x1B",u);if(l!==u){let m=l===-1?t.length:l;a+=t.slice(u,m),o+=t.slice(u,m),u=m;continue}let d=t.slice(u,u+(Rs(t,u)||1));u+=d.length;let f=E$(d),h=f===void 0?jP(d):void 0;if(f===void 0&&h===void 0){o+=d;continue}if(s+=_(a),a="",h!==void 0)s=h,o+=d;else if(f===0)c();else if(f!==void 0)i.push({target:n[f-1],col:s})}s+=_(a);while(i.length>0)c();return{text:o,zones:r}}function M$(t,e,n){let r=[],i=[],o="",s=(m)=>{let g=E$(m);if(g===0)r.pop();else if(g!==void 0)r.push(m);else if(m.startsWith("\x1B]8;"))o=m.slice(m.indexOf(";",4)+1).replace("\x07","").replace("\x1B\\","")===""?"":m;else if(m.startsWith("\x1B[")&&m.endsWith("m"))i.push(m)},a=t.includes("\x1B")||n.includes("\x1B")?"\x1B[0m":"",c="",u=0,l=0;while(l<t.length&&u<e){let m=Rs(t,l);if(m>0){let b=t.slice(l,l+m);s(b),c+=b,l+=m;continue}let g=String.fromCodePoint(t.codePointAt(l));if(u+_(g)>e)break;c+=g,u+=_(g),l+=g.length}c+=" ".repeat(e-Math.min(e,u));let d=`${"\x1B[?0y".repeat(r.length)}${o?"\x1B]8;;\x1B\\":""}${a}`,f=e+_(n);while(l<t.length&&u<f){let m=Rs(t,l);if(m>0){s(t.slice(l,l+m)),l+=m;continue}let g=String.fromCodePoint(t.codePointAt(l));u+=_(g),l+=g.length}if(l>=t.length)return`${c}${d}${n}${a}`;let h=`${i.join("")}${o}${r.join("")}${" ".repeat(Math.max(0,u-f))}`;return`${c}${d}${n}${a}${h}${t.slice(l)}`}function x$(t,e){let n=[];return{lines:t.map((i,o)=>{let s=_P(i,o,e);return n.push(...s.zones),s.text}),zones:n}}function v$(t,e,n,r=0.5,i=0.5){let o=n-t.col,s=e-t.row;return{target:t.target,x:o,y:s,exact:{x:o+r,y:s+i},width:t.width,height:t.height,inside:o>=0&&o<t.width&&s>=0&&s<t.height}}function BP(t,e,n){let r;for(let i of t)if(e>=i.row&&e<i.row+i.height&&n>=i.col&&n<i.col+i.width&&(!r||i.width*i.height<=r.width*r.height))r=i;return r}var GP={space:" ",enter:"enter",esc:"esc",tab:"tab",bksp:"backspace","←":"left","→":"right"};function Yf(t){let e=/^(ctrl|alt)\+([a-z])$/.exec(t);if(e)return`${e[1]}-${e[2]}`;return GP[t]??([...t].length===1&&t!==" "?t:void 0)}function Wt(t,e){let n=Yf(t);return n?Vt({kind:"key",key:n},e):e}class Jf{zones=[];held;point(t){if(t.action==="drag"||t.action==="release"){let n=this.held;if(t.action==="release")this.held=void 0;return n&&v$(n,t.row,t.col,t.fx,t.fy)}let e=BP(this.zones,t.row,t.col);if(t.action==="press")this.held=t.button==="left"?e:void 0;return e&&v$(e,t.row,t.col,t.fx,t.fy)}drop(){this.held=void 0}}var Vn=[{name:"preview",title:"Preview"},{name:"browse",title:"Browse"}],iu=10,ou=20,UP="\x1B[7;1m\x1B[36m";function O$(t){return Vn.find((e)=>e.name===t.TTHEME_HUB)?.name}function I$(t,e){let n=Vn.findIndex((r)=>r.name===t);return ou+(n+e+Vn.length)%Vn.length+1}function R$(t){return ou+Vn.findIndex((e)=>e.name===t)+1}function Vf(t,e){let n=Vn.map(({name:i,title:o})=>{let s={kind:"hub",tab:i};if(!e)return Vt(s,i===t?`[${o}]`:` ${o} `);return i===t?`${UP}${Vt(s,` ${o} `)}${Lt}`:`${C}${Vt(s,` ${o} `)}${Lt}`}),r="tab next";return` ${n.join(" ")} ${e?`${C}tab next${Lt}`:"tab next"}`}import{execFileSync as _T}from"node:child_process";import{existsSync as Xu,mkdirSync as BT,readdirSync as GT,readFileSync as tl,rmSync as t1}from"node:fs";import{basename as i1,join as xa,relative as e1}from"node:path";import{styleText as lu}from"node:util";import{stdout as B$,stdin as VP}from"node:process";import ZP from"node:readline";var su="\x1B",H$="›",WP=39,Qf="\x07",C$="[",KP="]",L$="m",Xf=`${KP}8;;`,P$=new RegExp(`(?:\\${C$}(?<code>\\d+)m|\\${Xf}(?<uri>.*)${Qf})`,"y"),N$=(t)=>{if(t>=30&&t<=37)return 39;if(t>=90&&t<=97)return 39;if(t>=40&&t<=47)return 49;if(t>=100&&t<=107)return 49;if(t===1||t===2)return 22;if(t===3)return 23;if(t===4)return 24;if(t===7)return 27;if(t===8)return 28;if(t===9)return 29;if(t===0)return 0;return},A$=(t)=>`${su}${C$}${t}${L$}`,T$=(t)=>`${su}${Xf}${t}${Qf}`,Zf=(t,e,n)=>{let r=e[Symbol.iterator](),i=!1,o=!1,s=t.at(-1),a=s===void 0?0:_(s),c=r.next(),u=r.next(),l=0;while(!c.done){let d=c.value,f=_(d);if(a+f<=n)t[t.length-1]+=d;else t.push(d),a=0;if(d===su||d===H$)i=!0,o=e.startsWith(Xf,l+1);if(i){if(o){if(d===Qf)i=!1,o=!1}else if(d===L$)i=!1}else if(a+=f,a===n&&!u.done)t.push(""),a=0;c=u,u=r.next(),l+=d.length}if(s=t.at(-1),!a&&s!==void 0&&s.length&&t.length>1)t[t.length-2]+=t.pop()},zP=(t)=>{let e=t.split(" "),n=e.length;while(n){if(_(e[n-1]))break;n--}if(n===e.length)return t;return e.slice(0,n).join(" ")+e.slice(n).join("")},DP=(t,e,n={})=>{if(n.trim!==!1&&t.trim()==="")return"";let r="",i,o,s=t.split(" "),a=[""],c=0;for(let d=0;d<s.length;d++){let f=s[d];if(n.trim!==!1){let m=a.at(-1)??"",g=m.trimStart();if(m.length!==g.length)a[a.length-1]=g,c=_(g)}if(d!==0){if(c>=e&&(n.wordWrap===!1||n.trim===!1))a.push(""),c=0;if(c||n.trim===!1)a[a.length-1]+=" ",c++}let h=_(f);if(n.hard&&h>e){let m=e-c,g=1+Math.floor((h-m-1)/e);if(Math.floor((h-1)/e)<g)a.push("");Zf(a,f,e),c=_(a.at(-1)??"");continue}if(c+h>e&&c&&h){if(n.wordWrap===!1&&c<e){Zf(a,f,e),c=_(a.at(-1)??"");continue}a.push(""),c=0}if(c+h>e&&n.wordWrap===!1){Zf(a,f,e),c=_(a.at(-1)??"");continue}a[a.length-1]+=f,c+=h}if(n.trim!==!1)a=a.map((d)=>zP(d));let u=a.join(`
267
+ `),l=!1;for(let d=0;d<u.length;d++){let f=u[d];if(r+=f,!l){if(l=f>="\uD800"&&f<="\uDBFF",l)continue}else l=!1;if(f===su||f===H$){P$.lastIndex=d+1;let m=P$.exec(u)?.groups;if(m?.code!==void 0){let g=Number.parseFloat(m.code);i=g===WP?void 0:g}else if(m?.uri!==void 0)o=m.uri.length===0?void 0:m.uri}if(u[d+1]===`
268
+ `){if(o)r+=T$("");let h=i?N$(i):void 0;if(i&&h)r+=A$(h)}else if(f===`
269
+ `){if(i&&N$(i))r+=A$(i);if(o)r+=T$(o)}}return r},qP=/\r?\n/;function Hr(t,e,n){return String(t).normalize().split(qP).map((r)=>DP(r,e,n)).join(`
270
+ `)}var Pe=bd(eh(),1);function Zn(t,e,n){if(!n.some((s)=>!s.disabled))return t;let r=t+e,i=Math.max(n.length-1,0),o=r<0?i:r>i?0:r;return n[o]?.disabled?Zn(o,e<0?-1:1,n):o}function au(t,e,n,r){let i=r.split(`
271
+ `),o=0,s=t;for(let c of i){if(s<=c.length)break;s-=c.length+1,o++}for(o=Math.max(0,Math.min(i.length-1,o+n)),s=Math.min(s,i[o].length)+e;s<0&&o>0;)o--,s+=i[o].length+1;for(;s>i[o].length&&o<i.length-1;)s-=i[o].length+1,o++;s=Math.max(0,Math.min(i[o].length,s));let a=0;for(let c=0;c<o;c++)a+=i[c].length+1;return a+s}var QP=["up","down","left","right","space","enter","cancel"],XP=["January","February","March","April","May","June","July","August","September","October","November","December"],Kt={actions:new Set(QP),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0,date:{monthNames:[...XP],messages:{required:"Please enter a valid date",invalidMonth:"There are only 12 months in a year",invalidDay:(t,e)=>`There are only ${t} days in ${e}`,afterMin:(t)=>`Date must be on or after ${t.toISOString().slice(0,10)}`,beforeMax:(t)=>`Date must be on or before ${t.toISOString().slice(0,10)}`}}};function G$(t,e){if(typeof t=="string")return Kt.aliases.get(t)===e;for(let n of t)if(n!==void 0&&G$(n,e))return!0;return!1}function tN(t,e){if(t===e)return;let n=t.split(`
272
272
  `),r=e.split(`
273
- `),i=Math.max(n.length,r.length),s=[];for(let o=0;o<i;o++)n[o]!==r[o]&&s.push(o);return{lines:s,numLinesBefore:n.length,numLinesAfter:r.length,numLines:i}}var s5=globalThis.process.platform.startsWith("win"),Ed=Symbol("clack:cancel");function fe(t){return t===Ed}function jc(t,e){let n=t;n.isTTY&&n.setRawMode(e)}var Bc=(t)=>("columns"in t)&&typeof t.columns=="number"?t.columns:80,Md=(t)=>("rows"in t)&&typeof t.rows=="number"?t.rows:20;function Er(t,e,n,r=n,i=n,s){let o=Bc(t??B0);return vr(e,o-n.length,{hard:!0,trim:!1}).split(`
274
- `).map((a,c,u)=>{let l=s?s(a,c):a;return c===0?`${r}${l}`:c===u.length-1?`${i}${l}`:`${n}${l}`}).join(`
275
- `)}function W0(t,e){if("~standard"in t){let n=t["~standard"].validate(e);if(n instanceof Promise)throw TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");return n.issues?.at(0)?.message}return t(e)}class Un{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";constructor(t,e=!0){let{input:n=kR,output:r=B0,render:i,signal:s,...o}=t;this.opts=o,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=i.bind(this),this._track=e,this._abortSignal=s,this.input=n,this.output=r}unsubscribe(){this._subscribers.clear()}setSubscriber(t,e){let n=this._subscribers.get(t)??[];n.push(e),this._subscribers.set(t,n)}on(t,e){this.setSubscriber(t,{cb:e})}once(t,e){this.setSubscriber(t,{cb:e,once:!0})}emit(t,...e){let n=this._subscribers.get(t)??[],r=[];for(let i of n)i.cb(...e),i.once&&r.push(()=>n.splice(n.indexOf(i),1));for(let i of r)i()}prompt(){return new Promise((t)=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),t(Ed);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=yR.createInterface({input:this.input,tabSize:2,prompt:"",escapeCodeTimeout:50,terminal:!0}),this.rl.prompt(),this.opts.initialUserInput!==void 0&&this._setUserInput(this.opts.initialUserInput,!0),this.input.on("keypress",this.onKeypress),jc(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(Oe.cursor.show),this.output.off("resize",this.render),jc(this.input,!1),t(this.value)}),this.once("cancel",()=>{this.output.write(Oe.cursor.show),this.output.off("resize",this.render),jc(this.input,!1),t(Ed)})})}_isActionKey(t,e){return t==="\t"}_shouldSubmit(t,e){return!0}_setValue(t){this.value=t,this.emit("value",this.value)}_setUserInput(t,e){this.userInput=t??"",this.emit("userInput",this.userInput),e&&this._track&&this.rl&&(this.rl.write(this.userInput),this._cursor=this.rl.cursor)}_clearUserInput(){this.rl?.write(null,{ctrl:!0,name:"u"}),this._setUserInput("")}onKeypress(t,e){if(this._track&&e.name!=="return"&&(e.name&&this._isActionKey(t,e)&&this.rl?.write(null,{ctrl:!0,name:"h"}),this._cursor=this.rl?.cursor??0,this._setUserInput(this.rl?.line)),this.state==="error"&&(this.state="active"),e?.name&&(!this._track&&Wt.aliases.has(e.name)&&this.emit("cursor",Wt.aliases.get(e.name)),Wt.actions.has(e.name)&&this.emit("cursor",e.name)),t&&(t.toLowerCase()==="y"||t.toLowerCase()==="n")&&this.emit("confirm",t.toLowerCase()==="y"),this.emit("key",t,e),e?.name==="return"&&this._shouldSubmit(t,e)){if(this.opts.validate){let n=W0(this.opts.validate,this.value);n&&(this.error=n instanceof Error?n.message:n,this.state="error",this.rl?.write(this.userInput))}this.state!=="error"&&(this.state="submit")}U0([t,e?.name,e?.sequence],"cancel")&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close()}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
276
- `),jc(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let t=vr(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
277
- `).length-1;this.output.write(Oe.cursor.move(-999,t*-1))}render(){let t=vr(this._render(this)??"",process.stdout.columns,{hard:!0,trim:!1});if(t!==this._prevFrame){if(this.state==="initial")this.output.write(Oe.cursor.hide);else{let e=SR(this._prevFrame,t),n=Md(this.output);if(this.restoreCursor(),e){let r=Math.max(0,e.numLinesAfter-n),i=Math.max(0,e.numLinesBefore-n),s=e.lines.find((o)=>o>=r);if(s===void 0){this._prevFrame=t;return}if(e.lines.length===1){this.output.write(Oe.cursor.move(0,s-i)),this.output.write(Oe.erase.lines(1));let o=t.split(`
278
- `);this.output.write(o[s]),this._prevFrame=t,this.output.write(Oe.cursor.move(0,o.length-s-1));return}else if(e.lines.length>1){if(r<i)s=r;else{let a=s-i;a>0&&this.output.write(Oe.cursor.move(0,a))}this.output.write(Oe.erase.down());let o=t.split(`
279
- `).slice(s);this.output.write(o.join(`
280
- `)),this._prevFrame=t;return}}this.output.write(Oe.erase.down())}this.output.write(t),this.state==="initial"&&(this.state="active"),this._prevFrame=t}}}function MR(t,e){if(t===void 0||e.length===0)return 0;let n=e.findIndex((r)=>r.value===t);return n!==-1?n:0}function OR(t,e){return(e.label??String(e.value)).toLowerCase().includes(t.toLowerCase())}function xR(t,e){if(e)return t?e:e[0]}var IR=class extends Un{filteredOptions;multiple;isNavigating=!1;selectedValues=[];focusedValue;#e=0;#n="";#t;#s;#a;get cursor(){return this.#e}get userInputWithCursor(){if(!this.userInput)return Gc(["inverse","hidden"],"_");if(this._cursor>=this.userInput.length)return`${this.userInput}█`;let e=this.userInput.slice(0,this.cursor),n=this.userInput.slice(this.cursor,this.cursor+1),r=this.userInput.slice(this.cursor+1);return`${e}${Gc("inverse",n)}${r}`}get options(){return typeof this.#s=="function"?this.#s():this.#s}constructor(e){super(e),this.#s=e.options,this.#a=e.placeholder;let n=this.options;this.filteredOptions=[...n],this.multiple=e.multiple===!0,this.#t=typeof e.options=="function"?e.filter:e.filter??OR;let r;if(e.initialValue&&Array.isArray(e.initialValue)?this.multiple?r=e.initialValue:r=e.initialValue.slice(0,1):!this.multiple&&this.options.length>0&&(r=[this.options[0]?.value]),r)for(let i of r){let s=n.findIndex((o)=>o.value===i);s!==-1&&(this.toggleSelected(i),this.#e=s)}this.focusedValue=this.options[this.#e]?.value,this.on("key",(i,s)=>this.#r(i,s)),this.on("userInput",(i)=>this.#i(i))}_isActionKey(e,n){return e==="\t"||this.multiple&&this.isNavigating&&n.name==="space"&&e!==void 0&&e!==""}#r(e,n){let r=n.name==="up",i=n.name==="down",s=n.name==="return",o=this.userInput===""||this.userInput==="\t",a=this.#a,c=this.options,u=a!==void 0&&a!==""&&c.some((l)=>!l.disabled&&(this.#t?this.#t(a,l):!0));if(n.name==="tab"&&o&&u){this.userInput==="\t"&&this._clearUserInput(),this._setUserInput(a,!0),this.isNavigating=!1;return}r||i?(this.#e=Bn(this.#e,r?-1:1,this.filteredOptions),this.focusedValue=this.filteredOptions[this.#e]?.value,this.multiple||(this.selectedValues=[this.focusedValue]),this.isNavigating=!0):s?this.value=xR(this.multiple,this.selectedValues):this.multiple?this.focusedValue!==void 0&&(n.name==="tab"||this.isNavigating&&n.name==="space")?this.toggleSelected(this.focusedValue):this.isNavigating=!1:(this.focusedValue&&(this.selectedValues=[this.focusedValue]),this.isNavigating=!1)}deselectAll(){this.selectedValues=[]}toggleSelected(e){this.filteredOptions.length!==0&&(this.multiple?this.selectedValues.includes(e)?this.selectedValues=this.selectedValues.filter((n)=>n!==e):this.selectedValues=[...this.selectedValues,e]:this.selectedValues=[e])}#i(e){if(e!==this.#n){this.#n=e;let n=this.options;e&&this.#t?this.filteredOptions=n.filter((s)=>this.#t?.(e,s)):this.filteredOptions=[...n];let r=MR(this.focusedValue,this.filteredOptions);this.#e=Bn(r,0,this.filteredOptions);let i=this.filteredOptions[this.#e];i&&!i.disabled?this.focusedValue=i.value:this.focusedValue=void 0,this.multiple||(this.focusedValue!==void 0?this.toggleSelected(this.focusedValue):this.deselectAll())}}};class Od extends Un{get cursor(){return this.value?0:1}get _value(){return this.cursor===0}constructor(t){super(t,!1),this.value=!!t.initialValue,this.on("userInput",()=>{this.value=this._value}),this.on("confirm",(e)=>{this.output.write(Oe.cursor.move(0,-1)),this.value=e,this.state="submit",this.close()}),this.on("cursor",()=>{this.value=!this.value})}}var RR={Y:{type:"year",len:4},M:{type:"month",len:2},D:{type:"day",len:2}};function _0(t){return[...t].map((e)=>RR[e])}function NR(t){let e=new Intl.DateTimeFormat(t,{year:"numeric",month:"2-digit",day:"2-digit"}).formatToParts(new Date(2000,0,15)),n=[],r="/";for(let i of e)i.type==="literal"?r=i.value.trim()||i.value:(i.type==="year"||i.type==="month"||i.type==="day")&&n.push({type:i.type,len:i.type==="year"?4:2});return{segments:n,separator:r}}function vd(t){return Number.parseInt((t||"0").replace(/_/g,"0"),10)||0}function _c(t){return{year:vd(t.year),month:vd(t.month),day:vd(t.day)}}function Sd(t,e){return new Date(t||2001,e||1,0).getDate()}function K0(t){let{year:e,month:n,day:r}=_c(t);if(!e||e<0||e>9999||!n||n<1||n>12||!r||r<1)return;let i=new Date(Date.UTC(e,n-1,r));if(!(i.getUTCFullYear()!==e||i.getUTCMonth()!==n-1||i.getUTCDate()!==r))return{year:e,month:n,day:r}}function G0(t){let e=K0(t);return e?new Date(Date.UTC(e.year,e.month-1,e.day)):void 0}function TR(t,e,n,r){let i=n?{year:n.getUTCFullYear(),month:n.getUTCMonth()+1,day:n.getUTCDate()}:null,s=r?{year:r.getUTCFullYear(),month:r.getUTCMonth()+1,day:r.getUTCDate()}:null;return t==="year"?{min:i?.year??1,max:s?.year??9999}:t==="month"?{min:i&&e.year===i.year?i.month:1,max:s&&e.year===s.year?s.month:12}:{min:i&&e.year===i.year&&e.month===i.month?i.day:1,max:s&&e.year===s.year&&e.month===s.month?s.day:Sd(e.year,e.month)}}class z0 extends Un{#e;#n;#t;#s;#a;#r={segmentIndex:0,positionInSegment:0};#i=!0;#o=null;inlineError="";get segmentCursor(){return{...this.#r}}get segmentValues(){return{...this.#t}}get segments(){return this.#e}get separator(){return this.#n}get formattedValue(){return this.#f(this.#t)}#f(t){return this.#e.map((e)=>t[e.type]).join(this.#n)}#c(){this._setUserInput(this.#f(this.#t)),this._setValue(G0(this.#t)??void 0)}constructor(t){let e=t.format?{segments:_0(t.format),separator:t.separator??"/"}:NR(t.locale),n=t.separator??e.separator,r=t.format?_0(t.format):e.segments,i=t.initialValue??t.defaultValue,s=i?{year:String(i.getUTCFullYear()).padStart(4,"0"),month:String(i.getUTCMonth()+1).padStart(2,"0"),day:String(i.getUTCDate()).padStart(2,"0")}:{year:"____",month:"__",day:"__"},o=r.map((a)=>s[a.type]).join(n);super({...t,initialUserInput:o},!1),this.#e=r,this.#n=n,this.#t=s,this.#s=t.minDate,this.#a=t.maxDate,this.#c(),this.on("cursor",(a)=>this.#m(a)),this.on("key",(a,c)=>this.#p(a,c)),this.on("finalize",()=>this.#g(t))}#u(){let t=Math.max(0,Math.min(this.#r.segmentIndex,this.#e.length-1)),e=this.#e[t];if(e)return this.#r.positionInSegment=Math.max(0,Math.min(this.#r.positionInSegment,e.len-1)),{segment:e,index:t}}#l(t){this.inlineError="",this.#o=null;let e=this.#u();e&&(this.#r.segmentIndex=Math.max(0,Math.min(this.#e.length-1,e.index+t)),this.#r.positionInSegment=0,this.#i=!0)}#d(t){let e=this.#u();if(!e)return;let{segment:n}=e,r=this.#t[n.type],i=!r||r.replace(/_/g,"")==="",s=Number.parseInt((r||"0").replace(/_/g,"0"),10)||0,o=TR(n.type,_c(this.#t),this.#s,this.#a),a;i?a=t===1?o.min:o.max:a=Math.max(Math.min(o.max,s+t),o.min),this.#t={...this.#t,[n.type]:a.toString().padStart(n.len,"0")},this.#i=!0,this.#o=null,this.#c()}#m(t){if(t)switch(t){case"right":return this.#l(1);case"left":return this.#l(-1);case"up":return this.#d(1);case"down":return this.#d(-1)}}#p(t,e){if(e?.name==="backspace"||e?.sequence===""||e?.sequence==="\b"||t===""||t==="\b"){this.inlineError="";let n=this.#u();if(!n)return;if(!this.#t[n.segment.type].replace(/_/g,"")){this.#l(-1);return}this.#t[n.segment.type]="_".repeat(n.segment.len),this.#i=!0,this.#r.positionInSegment=0,this.#c();return}if(e?.name==="tab"){this.inlineError="";let n=this.#u();if(!n)return;let r=e.shift?-1:1,i=n.index+r;i>=0&&i<this.#e.length&&(this.#r.segmentIndex=i,this.#r.positionInSegment=0,this.#i=!0);return}if(t&&/^[0-9]$/.test(t)){let n=this.#u();if(!n)return;let{segment:r}=n,i=!this.#t[r.type].replace(/_/g,"");if(this.#i&&this.#o!==null&&!i){let d=this.#o+t,h={...this.#t,[r.type]:d},m=this.#h(h,r);if(m){this.inlineError=m,this.#o=null,this.#i=!1;return}this.inlineError="",this.#t[r.type]=d,this.#o=null,this.#i=!1,this.#c(),n.index<this.#e.length-1&&(this.#r.segmentIndex=n.index+1,this.#r.positionInSegment=0,this.#i=!0);return}this.#i&&!i&&(this.#t[r.type]="_".repeat(r.len),this.#r.positionInSegment=0),this.#i=!1,this.#o=null;let s=this.#t[r.type],o=s.indexOf("_"),a=o>=0?o:Math.min(this.#r.positionInSegment,r.len-1);if(a<0||a>=r.len)return;let c=s.slice(0,a)+t+s.slice(a+1),u=!1;if(a===0&&s==="__"&&(r.type==="month"||r.type==="day")){let d=Number.parseInt(t,10);c=`0${t}`,u=d<=(r.type==="month"?1:2)}if(r.type==="year"&&(c=(s.replace(/_/g,"")+t).padStart(r.len,"_")),!c.includes("_")){let d={...this.#t,[r.type]:c},h=this.#h(d,r);if(h){this.inlineError=h;return}}this.inlineError="",this.#t[r.type]=c;let l=c.includes("_")?void 0:K0(this.#t);if(l){let{year:d,month:h}=l,m=Sd(d,h);this.#t={year:String(Math.max(0,Math.min(9999,d))).padStart(4,"0"),month:String(Math.max(1,Math.min(12,h))).padStart(2,"0"),day:String(Math.max(1,Math.min(m,l.day))).padStart(2,"0")}}this.#c();let f=c.indexOf("_");u?(this.#i=!0,this.#o=t):f>=0?this.#r.positionInSegment=f:o>=0&&n.index<this.#e.length-1?(this.#r.segmentIndex=n.index+1,this.#r.positionInSegment=0,this.#i=!0):this.#r.positionInSegment=Math.min(a+1,r.len-1)}}#h(t,e){let{month:n,day:r}=_c(t);if(e.type==="month"&&(n<0||n>12))return Wt.date.messages.invalidMonth;if(e.type==="day"&&(r<0||r>31))return Wt.date.messages.invalidDay(31,"any month")}#g(t){let{year:e,month:n,day:r}=_c(this.#t);if(e&&n&&r){let i=Sd(e,n);this.#t={...this.#t,day:String(Math.min(r,i)).padStart(2,"0")}}this.value=G0(this.#t)??t.defaultValue??void 0}}var AR=class extends Un{options;cursor=0;#e;getGroupItems(e){return this.options.filter((n)=>n.group===e)}isGroupSelected(e){let n=this.getGroupItems(e),r=this.value;return r===void 0?!1:n.every((i)=>r.includes(i.value))}toggleValue(){let e=this.options[this.cursor];if(e!==void 0)if(this.value===void 0&&(this.value=[]),e.group===!0){let n=e.value,r=this.getGroupItems(n);this.isGroupSelected(n)?this.value=this.value.filter((i)=>r.findIndex((s)=>s.value===i)===-1):this.value=[...this.value,...r.map((i)=>i.value)],this.value=Array.from(new Set(this.value))}else{let n=this.value.includes(e.value);this.value=n?this.value.filter((r)=>r!==e.value):[...this.value,e.value]}}constructor(e){super(e,!1);let{options:n}=e;this.#e=e.selectableGroups!==!1,this.options=Object.entries(n).flatMap(([r,i])=>[{value:r,group:!0,label:r},...i.map((s)=>({...s,group:r}))]),this.value=[...e.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:r})=>r===e.cursorAt),this.#e?0:1),this.on("cursor",(r)=>{switch(r){case"left":case"up":{this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;let i=this.options[this.cursor]?.group===!0;!this.#e&&i&&(this.cursor=this.cursor===0?this.options.length-1:this.cursor-1);break}case"down":case"right":{this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;let i=this.options[this.cursor]?.group===!0;!this.#e&&i&&(this.cursor=this.cursor===this.options.length-1?0:this.cursor+1);break}case"space":this.toggleValue();break}})}},PR=new Set(["up","down","left","right"]);class D0 extends Un{#e=!1;#n;focused="editor";get userInputWithCursor(){if(this.state==="submit")return this.userInput;let t=this.userInput;if(this.cursor>=t.length)return`${t}█`;let e=t.slice(0,this.cursor),n=t.slice(this.cursor,this.cursor+1),r=t.slice(this.cursor+1);return n===`
273
+ `),i=Math.max(n.length,r.length),o=[];for(let s=0;s<i;s++)n[s]!==r[s]&&o.push(s);return{lines:o,numLinesBefore:n.length,numLinesAfter:r.length,numLines:i}}var D6=globalThis.process.platform.startsWith("win"),rh=Symbol("clack:cancel");function me(t){return t===rh}function cu(t,e){let n=t;n.isTTY&&n.setRawMode(e)}var du=(t)=>("columns"in t)&&typeof t.columns=="number"?t.columns:80,oh=(t)=>("rows"in t)&&typeof t.rows=="number"?t.rows:20;function Cr(t,e,n,r=n,i=n,o){let s=du(t??B$);return Hr(e,s-n.length,{hard:!0,trim:!1}).split(`
274
+ `).map((a,c,u)=>{let l=o?o(a,c):a;return c===0?`${r}${l}`:c===u.length-1?`${i}${l}`:`${n}${l}`}).join(`
275
+ `)}function U$(t,e){if("~standard"in t){let n=t["~standard"].validate(e);if(n instanceof Promise)throw TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");return n.issues?.at(0)?.message}return t(e)}class Qn{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";constructor(t,e=!0){let{input:n=VP,output:r=B$,render:i,signal:o,...s}=t;this.opts=s,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=i.bind(this),this._track=e,this._abortSignal=o,this.input=n,this.output=r}unsubscribe(){this._subscribers.clear()}setSubscriber(t,e){let n=this._subscribers.get(t)??[];n.push(e),this._subscribers.set(t,n)}on(t,e){this.setSubscriber(t,{cb:e})}once(t,e){this.setSubscriber(t,{cb:e,once:!0})}emit(t,...e){let n=this._subscribers.get(t)??[],r=[];for(let i of n)i.cb(...e),i.once&&r.push(()=>n.splice(n.indexOf(i),1));for(let i of r)i()}prompt(){return new Promise((t)=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),t(rh);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=ZP.createInterface({input:this.input,tabSize:2,prompt:"",escapeCodeTimeout:50,terminal:!0}),this.rl.prompt(),this.opts.initialUserInput!==void 0&&this._setUserInput(this.opts.initialUserInput,!0),this.input.on("keypress",this.onKeypress),cu(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(Pe.cursor.show),this.output.off("resize",this.render),cu(this.input,!1),t(this.value)}),this.once("cancel",()=>{this.output.write(Pe.cursor.show),this.output.off("resize",this.render),cu(this.input,!1),t(rh)})})}_isActionKey(t,e){return t==="\t"}_shouldSubmit(t,e){return!0}_setValue(t){this.value=t,this.emit("value",this.value)}_setUserInput(t,e){this.userInput=t??"",this.emit("userInput",this.userInput),e&&this._track&&this.rl&&(this.rl.write(this.userInput),this._cursor=this.rl.cursor)}_clearUserInput(){this.rl?.write(null,{ctrl:!0,name:"u"}),this._setUserInput("")}onKeypress(t,e){if(this._track&&e.name!=="return"&&(e.name&&this._isActionKey(t,e)&&this.rl?.write(null,{ctrl:!0,name:"h"}),this._cursor=this.rl?.cursor??0,this._setUserInput(this.rl?.line)),this.state==="error"&&(this.state="active"),e?.name&&(!this._track&&Kt.aliases.has(e.name)&&this.emit("cursor",Kt.aliases.get(e.name)),Kt.actions.has(e.name)&&this.emit("cursor",e.name)),t&&(t.toLowerCase()==="y"||t.toLowerCase()==="n")&&this.emit("confirm",t.toLowerCase()==="y"),this.emit("key",t,e),e?.name==="return"&&this._shouldSubmit(t,e)){if(this.opts.validate){let n=U$(this.opts.validate,this.value);n&&(this.error=n instanceof Error?n.message:n,this.state="error",this.rl?.write(this.userInput))}this.state!=="error"&&(this.state="submit")}G$([t,e?.name,e?.sequence],"cancel")&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close()}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
276
+ `),cu(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let t=Hr(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
277
+ `).length-1;this.output.write(Pe.cursor.move(-999,t*-1))}render(){let t=Hr(this._render(this)??"",process.stdout.columns,{hard:!0,trim:!1});if(t!==this._prevFrame){if(this.state==="initial")this.output.write(Pe.cursor.hide);else{let e=tN(this._prevFrame,t),n=oh(this.output);if(this.restoreCursor(),e){let r=Math.max(0,e.numLinesAfter-n),i=Math.max(0,e.numLinesBefore-n),o=e.lines.find((s)=>s>=r);if(o===void 0){this._prevFrame=t;return}if(e.lines.length===1){this.output.write(Pe.cursor.move(0,o-i)),this.output.write(Pe.erase.lines(1));let s=t.split(`
278
+ `);this.output.write(s[o]),this._prevFrame=t,this.output.write(Pe.cursor.move(0,s.length-o-1));return}else if(e.lines.length>1){if(r<i)o=r;else{let a=o-i;a>0&&this.output.write(Pe.cursor.move(0,a))}this.output.write(Pe.erase.down());let s=t.split(`
279
+ `).slice(o);this.output.write(s.join(`
280
+ `)),this._prevFrame=t;return}}this.output.write(Pe.erase.down())}this.output.write(t),this.state==="initial"&&(this.state="active"),this._prevFrame=t}}}function eN(t,e){if(t===void 0||e.length===0)return 0;let n=e.findIndex((r)=>r.value===t);return n!==-1?n:0}function nN(t,e){return(e.label??String(e.value)).toLowerCase().includes(t.toLowerCase())}function rN(t,e){if(e)return t?e:e[0]}var iN=class extends Qn{filteredOptions;multiple;isNavigating=!1;selectedValues=[];focusedValue;#e=0;#n="";#t;#o;#a;get cursor(){return this.#e}get userInputWithCursor(){if(!this.userInput)return lu(["inverse","hidden"],"_");if(this._cursor>=this.userInput.length)return`${this.userInput}█`;let e=this.userInput.slice(0,this.cursor),n=this.userInput.slice(this.cursor,this.cursor+1),r=this.userInput.slice(this.cursor+1);return`${e}${lu("inverse",n)}${r}`}get options(){return typeof this.#o=="function"?this.#o():this.#o}constructor(e){super(e),this.#o=e.options,this.#a=e.placeholder;let n=this.options;this.filteredOptions=[...n],this.multiple=e.multiple===!0,this.#t=typeof e.options=="function"?e.filter:e.filter??nN;let r;if(e.initialValue&&Array.isArray(e.initialValue)?this.multiple?r=e.initialValue:r=e.initialValue.slice(0,1):!this.multiple&&this.options.length>0&&(r=[this.options[0]?.value]),r)for(let i of r){let o=n.findIndex((s)=>s.value===i);o!==-1&&(this.toggleSelected(i),this.#e=o)}this.focusedValue=this.options[this.#e]?.value,this.on("key",(i,o)=>this.#r(i,o)),this.on("userInput",(i)=>this.#i(i))}_isActionKey(e,n){return e==="\t"||this.multiple&&this.isNavigating&&n.name==="space"&&e!==void 0&&e!==""}#r(e,n){let r=n.name==="up",i=n.name==="down",o=n.name==="return",s=this.userInput===""||this.userInput==="\t",a=this.#a,c=this.options,u=a!==void 0&&a!==""&&c.some((l)=>!l.disabled&&(this.#t?this.#t(a,l):!0));if(n.name==="tab"&&s&&u){this.userInput==="\t"&&this._clearUserInput(),this._setUserInput(a,!0),this.isNavigating=!1;return}r||i?(this.#e=Zn(this.#e,r?-1:1,this.filteredOptions),this.focusedValue=this.filteredOptions[this.#e]?.value,this.multiple||(this.selectedValues=[this.focusedValue]),this.isNavigating=!0):o?this.value=rN(this.multiple,this.selectedValues):this.multiple?this.focusedValue!==void 0&&(n.name==="tab"||this.isNavigating&&n.name==="space")?this.toggleSelected(this.focusedValue):this.isNavigating=!1:(this.focusedValue&&(this.selectedValues=[this.focusedValue]),this.isNavigating=!1)}deselectAll(){this.selectedValues=[]}toggleSelected(e){this.filteredOptions.length!==0&&(this.multiple?this.selectedValues.includes(e)?this.selectedValues=this.selectedValues.filter((n)=>n!==e):this.selectedValues=[...this.selectedValues,e]:this.selectedValues=[e])}#i(e){if(e!==this.#n){this.#n=e;let n=this.options;e&&this.#t?this.filteredOptions=n.filter((o)=>this.#t?.(e,o)):this.filteredOptions=[...n];let r=eN(this.focusedValue,this.filteredOptions);this.#e=Zn(r,0,this.filteredOptions);let i=this.filteredOptions[this.#e];i&&!i.disabled?this.focusedValue=i.value:this.focusedValue=void 0,this.multiple||(this.focusedValue!==void 0?this.toggleSelected(this.focusedValue):this.deselectAll())}}};class sh extends Qn{get cursor(){return this.value?0:1}get _value(){return this.cursor===0}constructor(t){super(t,!1),this.value=!!t.initialValue,this.on("userInput",()=>{this.value=this._value}),this.on("confirm",(e)=>{this.output.write(Pe.cursor.move(0,-1)),this.value=e,this.state="submit",this.close()}),this.on("cursor",()=>{this.value=!this.value})}}var oN={Y:{type:"year",len:4},M:{type:"month",len:2},D:{type:"day",len:2}};function j$(t){return[...t].map((e)=>oN[e])}function sN(t){let e=new Intl.DateTimeFormat(t,{year:"numeric",month:"2-digit",day:"2-digit"}).formatToParts(new Date(2000,0,15)),n=[],r="/";for(let i of e)i.type==="literal"?r=i.value.trim()||i.value:(i.type==="year"||i.type==="month"||i.type==="day")&&n.push({type:i.type,len:i.type==="year"?4:2});return{segments:n,separator:r}}function nh(t){return Number.parseInt((t||"0").replace(/_/g,"0"),10)||0}function uu(t){return{year:nh(t.year),month:nh(t.month),day:nh(t.day)}}function ih(t,e){return new Date(t||2001,e||1,0).getDate()}function W$(t){let{year:e,month:n,day:r}=uu(t);if(!e||e<0||e>9999||!n||n<1||n>12||!r||r<1)return;let i=new Date(Date.UTC(e,n-1,r));if(!(i.getUTCFullYear()!==e||i.getUTCMonth()!==n-1||i.getUTCDate()!==r))return{year:e,month:n,day:r}}function _$(t){let e=W$(t);return e?new Date(Date.UTC(e.year,e.month-1,e.day)):void 0}function aN(t,e,n,r){let i=n?{year:n.getUTCFullYear(),month:n.getUTCMonth()+1,day:n.getUTCDate()}:null,o=r?{year:r.getUTCFullYear(),month:r.getUTCMonth()+1,day:r.getUTCDate()}:null;return t==="year"?{min:i?.year??1,max:o?.year??9999}:t==="month"?{min:i&&e.year===i.year?i.month:1,max:o&&e.year===o.year?o.month:12}:{min:i&&e.year===i.year&&e.month===i.month?i.day:1,max:o&&e.year===o.year&&e.month===o.month?o.day:ih(e.year,e.month)}}class K$ extends Qn{#e;#n;#t;#o;#a;#r={segmentIndex:0,positionInSegment:0};#i=!0;#s=null;inlineError="";get segmentCursor(){return{...this.#r}}get segmentValues(){return{...this.#t}}get segments(){return this.#e}get separator(){return this.#n}get formattedValue(){return this.#d(this.#t)}#d(t){return this.#e.map((e)=>t[e.type]).join(this.#n)}#c(){this._setUserInput(this.#d(this.#t)),this._setValue(_$(this.#t)??void 0)}constructor(t){let e=t.format?{segments:j$(t.format),separator:t.separator??"/"}:sN(t.locale),n=t.separator??e.separator,r=t.format?j$(t.format):e.segments,i=t.initialValue??t.defaultValue,o=i?{year:String(i.getUTCFullYear()).padStart(4,"0"),month:String(i.getUTCMonth()+1).padStart(2,"0"),day:String(i.getUTCDate()).padStart(2,"0")}:{year:"____",month:"__",day:"__"},s=r.map((a)=>o[a.type]).join(n);super({...t,initialUserInput:s},!1),this.#e=r,this.#n=n,this.#t=o,this.#o=t.minDate,this.#a=t.maxDate,this.#c(),this.on("cursor",(a)=>this.#m(a)),this.on("key",(a,c)=>this.#p(a,c)),this.on("finalize",()=>this.#g(t))}#u(){let t=Math.max(0,Math.min(this.#r.segmentIndex,this.#e.length-1)),e=this.#e[t];if(e)return this.#r.positionInSegment=Math.max(0,Math.min(this.#r.positionInSegment,e.len-1)),{segment:e,index:t}}#l(t){this.inlineError="",this.#s=null;let e=this.#u();e&&(this.#r.segmentIndex=Math.max(0,Math.min(this.#e.length-1,e.index+t)),this.#r.positionInSegment=0,this.#i=!0)}#f(t){let e=this.#u();if(!e)return;let{segment:n}=e,r=this.#t[n.type],i=!r||r.replace(/_/g,"")==="",o=Number.parseInt((r||"0").replace(/_/g,"0"),10)||0,s=aN(n.type,uu(this.#t),this.#o,this.#a),a;i?a=t===1?s.min:s.max:a=Math.max(Math.min(s.max,o+t),s.min),this.#t={...this.#t,[n.type]:a.toString().padStart(n.len,"0")},this.#i=!0,this.#s=null,this.#c()}#m(t){if(t)switch(t){case"right":return this.#l(1);case"left":return this.#l(-1);case"up":return this.#f(1);case"down":return this.#f(-1)}}#p(t,e){if(e?.name==="backspace"||e?.sequence===""||e?.sequence==="\b"||t===""||t==="\b"){this.inlineError="";let n=this.#u();if(!n)return;if(!this.#t[n.segment.type].replace(/_/g,"")){this.#l(-1);return}this.#t[n.segment.type]="_".repeat(n.segment.len),this.#i=!0,this.#r.positionInSegment=0,this.#c();return}if(e?.name==="tab"){this.inlineError="";let n=this.#u();if(!n)return;let r=e.shift?-1:1,i=n.index+r;i>=0&&i<this.#e.length&&(this.#r.segmentIndex=i,this.#r.positionInSegment=0,this.#i=!0);return}if(t&&/^[0-9]$/.test(t)){let n=this.#u();if(!n)return;let{segment:r}=n,i=!this.#t[r.type].replace(/_/g,"");if(this.#i&&this.#s!==null&&!i){let f=this.#s+t,h={...this.#t,[r.type]:f},m=this.#h(h,r);if(m){this.inlineError=m,this.#s=null,this.#i=!1;return}this.inlineError="",this.#t[r.type]=f,this.#s=null,this.#i=!1,this.#c(),n.index<this.#e.length-1&&(this.#r.segmentIndex=n.index+1,this.#r.positionInSegment=0,this.#i=!0);return}this.#i&&!i&&(this.#t[r.type]="_".repeat(r.len),this.#r.positionInSegment=0),this.#i=!1,this.#s=null;let o=this.#t[r.type],s=o.indexOf("_"),a=s>=0?s:Math.min(this.#r.positionInSegment,r.len-1);if(a<0||a>=r.len)return;let c=o.slice(0,a)+t+o.slice(a+1),u=!1;if(a===0&&o==="__"&&(r.type==="month"||r.type==="day")){let f=Number.parseInt(t,10);c=`0${t}`,u=f<=(r.type==="month"?1:2)}if(r.type==="year"&&(c=(o.replace(/_/g,"")+t).padStart(r.len,"_")),!c.includes("_")){let f={...this.#t,[r.type]:c},h=this.#h(f,r);if(h){this.inlineError=h;return}}this.inlineError="",this.#t[r.type]=c;let l=c.includes("_")?void 0:W$(this.#t);if(l){let{year:f,month:h}=l,m=ih(f,h);this.#t={year:String(Math.max(0,Math.min(9999,f))).padStart(4,"0"),month:String(Math.max(1,Math.min(12,h))).padStart(2,"0"),day:String(Math.max(1,Math.min(m,l.day))).padStart(2,"0")}}this.#c();let d=c.indexOf("_");u?(this.#i=!0,this.#s=t):d>=0?this.#r.positionInSegment=d:s>=0&&n.index<this.#e.length-1?(this.#r.segmentIndex=n.index+1,this.#r.positionInSegment=0,this.#i=!0):this.#r.positionInSegment=Math.min(a+1,r.len-1)}}#h(t,e){let{month:n,day:r}=uu(t);if(e.type==="month"&&(n<0||n>12))return Kt.date.messages.invalidMonth;if(e.type==="day"&&(r<0||r>31))return Kt.date.messages.invalidDay(31,"any month")}#g(t){let{year:e,month:n,day:r}=uu(this.#t);if(e&&n&&r){let i=ih(e,n);this.#t={...this.#t,day:String(Math.min(r,i)).padStart(2,"0")}}this.value=_$(this.#t)??t.defaultValue??void 0}}var cN=class extends Qn{options;cursor=0;#e;getGroupItems(e){return this.options.filter((n)=>n.group===e)}isGroupSelected(e){let n=this.getGroupItems(e),r=this.value;return r===void 0?!1:n.every((i)=>r.includes(i.value))}toggleValue(){let e=this.options[this.cursor];if(e!==void 0)if(this.value===void 0&&(this.value=[]),e.group===!0){let n=e.value,r=this.getGroupItems(n);this.isGroupSelected(n)?this.value=this.value.filter((i)=>r.findIndex((o)=>o.value===i)===-1):this.value=[...this.value,...r.map((i)=>i.value)],this.value=Array.from(new Set(this.value))}else{let n=this.value.includes(e.value);this.value=n?this.value.filter((r)=>r!==e.value):[...this.value,e.value]}}constructor(e){super(e,!1);let{options:n}=e;this.#e=e.selectableGroups!==!1,this.options=Object.entries(n).flatMap(([r,i])=>[{value:r,group:!0,label:r},...i.map((o)=>({...o,group:r}))]),this.value=[...e.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:r})=>r===e.cursorAt),this.#e?0:1),this.on("cursor",(r)=>{switch(r){case"left":case"up":{this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;let i=this.options[this.cursor]?.group===!0;!this.#e&&i&&(this.cursor=this.cursor===0?this.options.length-1:this.cursor-1);break}case"down":case"right":{this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;let i=this.options[this.cursor]?.group===!0;!this.#e&&i&&(this.cursor=this.cursor===this.options.length-1?0:this.cursor+1);break}case"space":this.toggleValue();break}})}},uN=new Set(["up","down","left","right"]);class z$ extends Qn{#e=!1;#n;focused="editor";get userInputWithCursor(){if(this.state==="submit")return this.userInput;let t=this.userInput;if(this.cursor>=t.length)return`${t}█`;let e=t.slice(0,this.cursor),n=t.slice(this.cursor,this.cursor+1),r=t.slice(this.cursor+1);return n===`
281
281
  `?`${e}█
282
- ${r}`:`${e}${Gc("inverse",n)}${r}`}get cursor(){return this._cursor}#t(t){if(this.userInput.length===0){this._setUserInput(t);return}this._setUserInput(this.userInput.slice(0,this.cursor)+t+this.userInput.slice(this.cursor))}#s(t){let e=this.value??"";switch(t){case"up":this._cursor=Lc(this._cursor,0,-1,e);return;case"down":this._cursor=Lc(this._cursor,0,1,e);return;case"left":this._cursor=Lc(this._cursor,-1,0,e);return;case"right":this._cursor=Lc(this._cursor,1,0,e);return}}_shouldSubmit(t,e){if(this.#n)return this.focused==="submit"?!0:(this.#t(`
282
+ ${r}`:`${e}${lu("inverse",n)}${r}`}get cursor(){return this._cursor}#t(t){if(this.userInput.length===0){this._setUserInput(t);return}this._setUserInput(this.userInput.slice(0,this.cursor)+t+this.userInput.slice(this.cursor))}#o(t){let e=this.value??"";switch(t){case"up":this._cursor=au(this._cursor,0,-1,e);return;case"down":this._cursor=au(this._cursor,0,1,e);return;case"left":this._cursor=au(this._cursor,-1,0,e);return;case"right":this._cursor=au(this._cursor,1,0,e);return}}_shouldSubmit(t,e){if(this.#n)return this.focused==="submit"?!0:(this.#t(`
283
283
  `),this._cursor++,!1);let n=this.#e;return this.#e=!0,n&&this.cursor===this.userInput.length?(this.userInput[this.cursor-1]===`
284
284
  `&&(this._setUserInput(this.userInput.slice(0,this.cursor-1)+this.userInput.slice(this.cursor)),this._cursor--),!0):(this.#t(`
285
- `),this._cursor++,!1)}constructor(t){let e=t.initialUserInput??t.initialValue;super({...t,initialUserInput:e},!1),e!==void 0&&(this._cursor=e.length),this.#n=t.showSubmit??!1,this.on("key",(n,r)=>{if(r?.name&&PR.has(r.name)){this.#e=!1,this.#s(r.name);return}if(n==="\t"&&this.#n){this.focused=this.focused==="editor"?"submit":"editor";return}if(r?.name!=="return"){if(this.#e=!1,r?.name==="backspace"&&this.cursor>0){this._setUserInput(this.userInput.slice(0,this.cursor-1)+this.userInput.slice(this.cursor)),this._cursor--;return}if(r?.name==="delete"&&this.cursor<this.userInput.length){this._setUserInput(this.userInput.slice(0,this.cursor)+this.userInput.slice(this.cursor+1));return}n&&(this.#n&&this.focused==="submit"&&(this.focused="editor"),this.#t(n??""),this._cursor++)}}),this.on("userInput",(n)=>{this._setValue(n)}),this.on("finalize",()=>{this.value||(this.value=t.defaultValue),this.value===void 0&&(this.value="")})}}class xd extends Un{options;cursor=0;get _value(){return this.options[this.cursor]?.value}get _enabledOptions(){return this.options.filter((t)=>t.disabled!==!0)}toggleAll(){let t=this._enabledOptions,e=this.value!==void 0&&this.value.length===t.length;this.value=e?[]:t.map((n)=>n.value)}toggleInvert(){let t=this.value;if(!t)return;let e=this._enabledOptions.filter((n)=>!t.includes(n.value));this.value=e.map((n)=>n.value)}toggleValue(){this.value===void 0&&(this.value=[]);let t=this.value.includes(this._value);this.value=t?this.value.filter((e)=>e!==this._value):[...this.value,this._value]}constructor(t){super(t,!1),this.options=t.options,this.value=[...t.initialValues??[]];let e=Math.max(this.options.findIndex(({value:n})=>n===t.cursorAt),0);this.cursor=this.options[e]?.disabled?Bn(e,1,this.options):e,this.on("key",(n,r)=>{r.name==="a"&&this.toggleAll(),r.name==="i"&&this.toggleInvert()}),this.on("cursor",(n)=>{switch(n){case"left":case"up":this.cursor=Bn(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=Bn(this.cursor,1,this.options);break;case"space":this.toggleValue();break}})}}var q0=class extends Un{options;cursor=0;get _selectedValue(){return this.options[this.cursor]}changeValue(){let e=this._selectedValue;this.value=e===void 0?void 0:e.value}constructor(e){super(e,!1),this.options=e.options;let n=this.options.findIndex(({value:i})=>i===e.initialValue),r=n===-1?0:n;this.cursor=this.options[r]?.disabled?Bn(r,1,this.options):r,this.changeValue(),this.on("cursor",(i)=>{switch(i){case"left":case"up":this.cursor=Bn(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=Bn(this.cursor,1,this.options);break}this.changeValue()})}};class Id extends Un{get userInputWithCursor(){if(this.state==="submit")return this.userInput;let t=this.userInput;if(this.cursor>=t.length)return`${this.userInput}█`;let e=t.slice(0,this.cursor),n=t.slice(this.cursor,this.cursor+1),r=t.slice(this.cursor+1);return`${e}${Gc("inverse",n)}${r}`}get cursor(){return this._cursor}constructor(t){super({...t,initialUserInput:t.initialUserInput??t.initialValue}),this.on("userInput",(e)=>{this._setValue(e)}),this.on("finalize",()=>{this.value||(this.value=t.defaultValue),this.value===void 0&&(this.value="")})}}import{styleText as M,stripVTControlCharacters as h5}from"node:util";import Ce from"node:process";var Q0=Ll(yd(),1);function HR(){if(Ce.platform!=="win32")return Ce.env.TERM!=="linux";return Boolean(Ce.env.CI)||Boolean(Ce.env.WT_SESSION)||Boolean(Ce.env.TERMINUS_SUBLIME)||Ce.env.ConEmuTask==="{cmd::Cmder}"||Ce.env.TERM_PROGRAM==="Terminus-Sublime"||Ce.env.TERM_PROGRAM==="vscode"||Ce.env.TERM==="xterm-256color"||Ce.env.TERM==="alacritty"||Ce.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var FR=HR();var dt=(t,e)=>FR?t:e,CR=dt("◆","*"),LR=dt("■","x"),jR=dt("▲","x"),Td=dt("◇","o"),_R=dt("┌","T"),nt=dt("│","|"),Wn=dt("└","—"),b5=dt("┐","T"),w5=dt("┘","—"),Rd=dt("●",">"),Wc=dt("○"," "),GR=dt("◻","[•]"),Y0=dt("◼","[+]"),J0=dt("◻","[ ]"),$5=dt("▪","•"),V0=dt("─","-"),BR=dt("╮","+"),UR=dt("├","+"),WR=dt("╯","+"),KR=dt("╰","+"),k5=dt("╭","+"),zR=dt("●","•"),DR=dt("◆","*"),qR=dt("▲","!"),YR=dt("■","x"),Kc=(t)=>{switch(t){case"initial":case"active":return M("cyan",CR);case"cancel":return M("red",LR);case"error":return M("yellow",jR);case"submit":return M("green",Td)}},X0=(t)=>{switch(t){case"initial":case"active":return M("cyan",nt);case"cancel":return M("red",nt);case"error":return M("yellow",nt);case"submit":return M("green",nt)}};function t$(t,e){let n=[`${e?`${M("cyan",nt)} `:""}${t.join(" • ")}`];return e&&n.push(M("cyan",Wn)),n}var Z0=(t,e,n,r,i,s=!1)=>{let o=e,a=0;if(s)for(let c=r-1;c>=n;c--){let u=t[c];if(u&&(o-=u.length),a++,o<=i)break}else for(let c=n;c<r;c++){let u=t[c];if(u&&(o-=u.length),a++,o<=i)break}return{lineCount:o,removals:a}},Nd=({cursor:t,options:e,style:n,output:r=process.stdout,maxItems:i=Number.POSITIVE_INFINITY,columnPadding:s=0,rowPadding:o=4})=>{let a=Bc(r)-s,c=Md(r),u=M("dim","..."),l=Math.max(c-o,0),f=Math.max(Math.min(i,l),5),d=0;t>=f-3&&(d=Math.max(Math.min(t-f+3,e.length-f),0));let h=f<e.length&&d>0,m=f<e.length&&d+f<e.length,$=Math.min(d+f,e.length),g=[],b=0;h&&b++,m&&b++;let y=d+(h?1:0),E=$-(m?1:0);for(let x=y;x<E;x++){let R=e[x],N=R?n(R,x===t):"",F=vr(N,a,{hard:!0,trim:!1}).split(`
286
- `);g.push(F),b+=F.length}if(b>l){let x=0,R=0,N=b,F=t-y,_=l,B=()=>Z0(g,N,0,F,_),tt=()=>Z0(g,N,F+1,g.length,_,!0);h?({lineCount:N,removals:x}=B(),N>_&&(m||(_-=1),{lineCount:N,removals:R}=tt())):(m||(_-=1),{lineCount:N,removals:R}=tt(),N>_&&(_-=1,{lineCount:N,removals:x}=B())),x>0&&(h=!0,g.splice(0,x)),R>0&&(m=!0,g.splice(g.length-R,R))}let S=[];h&&S.push(u);for(let x of g)for(let R of x)S.push(R);return m&&S.push(u),S};var Ve=(t)=>{let e=t.active??"Yes",n=t.inactive??"No";return new Od({active:e,inactive:n,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue??!0,render(){let r=t.withGuide??Wt.withGuide,i=`${Kc(this.state)} `,s=r?`${M("gray",nt)} `:"",o=Er(t.output,t.message,s,i),a=`${r?`${M("gray",nt)}
287
- `:""}${o}
288
- `,c=this.value?e:n;switch(this.state){case"submit":{let u=r?`${M("gray",nt)} `:"";return`${a}${u}${M("dim",c)}`}case"cancel":{let u=r?`${M("gray",nt)} `:"";return`${a}${u}${M(["strikethrough","dim"],c)}${r?`
289
- ${M("gray",nt)}`:""}`}default:{let u=r?`${M("cyan",nt)} `:"",l=r?M("cyan",Wn):"";return`${a}${u}${this.value?`${M("green",Rd)} ${e}`:`${M("dim",Wc)} ${M("dim",e)}`}${t.vertical?r?`
290
- ${M("cyan",nt)} `:`
291
- `:` ${M("dim","/")} `}${this.value?`${M("dim",Wc)} ${M("dim",n)}`:`${M("green",Rd)} ${n}`}
285
+ `),this._cursor++,!1)}constructor(t){let e=t.initialUserInput??t.initialValue;super({...t,initialUserInput:e},!1),e!==void 0&&(this._cursor=e.length),this.#n=t.showSubmit??!1,this.on("key",(n,r)=>{if(r?.name&&uN.has(r.name)){this.#e=!1,this.#o(r.name);return}if(n==="\t"&&this.#n){this.focused=this.focused==="editor"?"submit":"editor";return}if(r?.name!=="return"){if(this.#e=!1,r?.name==="backspace"&&this.cursor>0){this._setUserInput(this.userInput.slice(0,this.cursor-1)+this.userInput.slice(this.cursor)),this._cursor--;return}if(r?.name==="delete"&&this.cursor<this.userInput.length){this._setUserInput(this.userInput.slice(0,this.cursor)+this.userInput.slice(this.cursor+1));return}n&&(this.#n&&this.focused==="submit"&&(this.focused="editor"),this.#t(n??""),this._cursor++)}}),this.on("userInput",(n)=>{this._setValue(n)}),this.on("finalize",()=>{this.value||(this.value=t.defaultValue),this.value===void 0&&(this.value="")})}}class ah extends Qn{options;cursor=0;get _value(){return this.options[this.cursor]?.value}get _enabledOptions(){return this.options.filter((t)=>t.disabled!==!0)}toggleAll(){let t=this._enabledOptions,e=this.value!==void 0&&this.value.length===t.length;this.value=e?[]:t.map((n)=>n.value)}toggleInvert(){let t=this.value;if(!t)return;let e=this._enabledOptions.filter((n)=>!t.includes(n.value));this.value=e.map((n)=>n.value)}toggleValue(){this.value===void 0&&(this.value=[]);let t=this.value.includes(this._value);this.value=t?this.value.filter((e)=>e!==this._value):[...this.value,this._value]}constructor(t){super(t,!1),this.options=t.options,this.value=[...t.initialValues??[]];let e=Math.max(this.options.findIndex(({value:n})=>n===t.cursorAt),0);this.cursor=this.options[e]?.disabled?Zn(e,1,this.options):e,this.on("key",(n,r)=>{r.name==="a"&&this.toggleAll(),r.name==="i"&&this.toggleInvert()}),this.on("cursor",(n)=>{switch(n){case"left":case"up":this.cursor=Zn(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=Zn(this.cursor,1,this.options);break;case"space":this.toggleValue();break}})}}var D$=class extends Qn{options;cursor=0;get _selectedValue(){return this.options[this.cursor]}changeValue(){let e=this._selectedValue;this.value=e===void 0?void 0:e.value}constructor(e){super(e,!1),this.options=e.options;let n=this.options.findIndex(({value:i})=>i===e.initialValue),r=n===-1?0:n;this.cursor=this.options[r]?.disabled?Zn(r,1,this.options):r,this.changeValue(),this.on("cursor",(i)=>{switch(i){case"left":case"up":this.cursor=Zn(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=Zn(this.cursor,1,this.options);break}this.changeValue()})}};class ch extends Qn{get userInputWithCursor(){if(this.state==="submit")return this.userInput;let t=this.userInput;if(this.cursor>=t.length)return`${this.userInput}█`;let e=t.slice(0,this.cursor),n=t.slice(this.cursor,this.cursor+1),r=t.slice(this.cursor+1);return`${e}${lu("inverse",n)}${r}`}get cursor(){return this._cursor}constructor(t){super({...t,initialUserInput:t.initialUserInput??t.initialValue}),this.on("userInput",(e)=>{this._setValue(e)}),this.on("finalize",()=>{this.value||(this.value=t.defaultValue),this.value===void 0&&(this.value="")})}}import{styleText as x,stripVTControlCharacters as t_}from"node:util";import Ue from"node:process";var Z$=bd(eh(),1);function lN(){if(Ue.platform!=="win32")return Ue.env.TERM!=="linux";return Boolean(Ue.env.CI)||Boolean(Ue.env.WT_SESSION)||Boolean(Ue.env.TERMINUS_SUBLIME)||Ue.env.ConEmuTask==="{cmd::Cmder}"||Ue.env.TERM_PROGRAM==="Terminus-Sublime"||Ue.env.TERM_PROGRAM==="vscode"||Ue.env.TERM==="xterm-256color"||Ue.env.TERM==="alacritty"||Ue.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var dN=lN();var ht=(t,e)=>dN?t:e,fN=ht("◆","*"),hN=ht("■","x"),mN=ht("▲","x"),dh=ht("◇","o"),pN=ht("┌","T"),it=ht("│","|"),Xn=ht("└","—"),i_=ht("┐","T"),o_=ht("┘","—"),uh=ht("●",">"),hu=ht("○"," "),gN=ht("◻","[•]"),q$=ht("◼","[+]"),Y$=ht("◻","[ ]"),s_=ht("▪","•"),J$=ht("─","-"),bN=ht("╮","+"),wN=ht("├","+"),$N=ht("╯","+"),kN=ht("╰","+"),a_=ht("╭","+"),yN=ht("●","•"),vN=ht("◆","*"),SN=ht("▲","!"),EN=ht("■","x"),mu=(t)=>{switch(t){case"initial":case"active":return x("cyan",fN);case"cancel":return x("red",hN);case"error":return x("yellow",mN);case"submit":return x("green",dh)}},Q$=(t)=>{switch(t){case"initial":case"active":return x("cyan",it);case"cancel":return x("red",it);case"error":return x("yellow",it);case"submit":return x("green",it)}};function X$(t,e){let n=[`${e?`${x("cyan",it)} `:""}${t.join(" • ")}`];return e&&n.push(x("cyan",Xn)),n}var V$=(t,e,n,r,i,o=!1)=>{let s=e,a=0;if(o)for(let c=r-1;c>=n;c--){let u=t[c];if(u&&(s-=u.length),a++,s<=i)break}else for(let c=n;c<r;c++){let u=t[c];if(u&&(s-=u.length),a++,s<=i)break}return{lineCount:s,removals:a}},lh=({cursor:t,options:e,style:n,output:r=process.stdout,maxItems:i=Number.POSITIVE_INFINITY,columnPadding:o=0,rowPadding:s=4})=>{let a=du(r)-o,c=oh(r),u=x("dim","..."),l=Math.max(c-s,0),d=Math.max(Math.min(i,l),5),f=0;t>=d-3&&(f=Math.max(Math.min(t-d+3,e.length-d),0));let h=d<e.length&&f>0,m=d<e.length&&f+d<e.length,g=Math.min(f+d,e.length),b=[],w=0;h&&w++,m&&w++;let k=f+(h?1:0),v=g-(m?1:0);for(let M=k;M<v;M++){let I=e[M],O=I?n(I,M===t):"",H=Hr(O,a,{hard:!0,trim:!1}).split(`
286
+ `);b.push(H),w+=H.length}if(w>l){let M=0,I=0,O=w,H=t-k,N=l,L=()=>V$(b,O,0,H,N),K=()=>V$(b,O,H+1,b.length,N,!0);h?({lineCount:O,removals:M}=L(),O>N&&(m||(N-=1),{lineCount:O,removals:I}=K())):(m||(N-=1),{lineCount:O,removals:I}=K(),O>N&&(N-=1,{lineCount:O,removals:M}=L())),M>0&&(h=!0,b.splice(0,M)),I>0&&(m=!0,b.splice(b.length-I,I))}let S=[];h&&S.push(u);for(let M of b)for(let I of M)S.push(I);return m&&S.push(u),S};var nn=(t)=>{let e=t.active??"Yes",n=t.inactive??"No";return new sh({active:e,inactive:n,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue??!0,render(){let r=t.withGuide??Kt.withGuide,i=`${mu(this.state)} `,o=r?`${x("gray",it)} `:"",s=Cr(t.output,t.message,o,i),a=`${r?`${x("gray",it)}
287
+ `:""}${s}
288
+ `,c=this.value?e:n;switch(this.state){case"submit":{let u=r?`${x("gray",it)} `:"";return`${a}${u}${x("dim",c)}`}case"cancel":{let u=r?`${x("gray",it)} `:"";return`${a}${u}${x(["strikethrough","dim"],c)}${r?`
289
+ ${x("gray",it)}`:""}`}default:{let u=r?`${x("cyan",it)} `:"",l=r?x("cyan",Xn):"";return`${a}${u}${this.value?`${x("green",uh)} ${e}`:`${x("dim",hu)} ${x("dim",e)}`}${t.vertical?r?`
290
+ ${x("cyan",it)} `:`
291
+ `:` ${x("dim","/")} `}${this.value?`${x("dim",hu)} ${x("dim",n)}`:`${x("green",uh)} ${n}`}
292
292
  ${l}
293
- `}}}}).prompt()};var JR=[`${M("dim","↑/↓")} to navigate`,`${M("dim","Space:")} select`,`${M("dim","Enter:")} confirm`],_o=(t,e)=>t.split(`
293
+ `}}}}).prompt()};var MN=[`${x("dim","↑/↓")} to navigate`,`${x("dim","Space:")} select`,`${x("dim","Enter:")} confirm`],oa=(t,e)=>t.split(`
294
294
  `).map((n)=>e(n)).join(`
295
- `),e$=(t)=>{let e=(i,s)=>{let o=i.label??String(i.value);return s==="disabled"?`${M("gray",J0)} ${_o(o,(a)=>M(["strikethrough","gray"],a))}${i.hint?` ${M("dim",`(${i.hint??"disabled"})`)}`:""}`:s==="active"?`${M("cyan",GR)} ${o}${i.hint?` ${M("dim",`(${i.hint})`)}`:""}`:s==="selected"?`${M("green",Y0)} ${_o(o,(a)=>M("dim",a))}${i.hint?` ${M("dim",`(${i.hint})`)}`:""}`:s==="cancelled"?`${_o(o,(a)=>M(["strikethrough","dim"],a))}`:s==="active-selected"?`${M("green",Y0)} ${o}${i.hint?` ${M("dim",`(${i.hint})`)}`:""}`:s==="submitted"?`${_o(o,(a)=>M("dim",a))}`:`${M("dim",J0)} ${_o(o,(a)=>M("dim",a))}`},n=t.required??!0,r=t.showInstructions??!0;return new xd({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValues:t.initialValues,required:n,cursorAt:t.cursorAt,validate(i){if(n&&(i===void 0||i.length===0))return`Please select at least one option.
296
- ${M("reset",M("dim",`Press ${M(["gray","bgWhite","inverse"]," space ")} to select, ${M("gray",M("bgWhite",M("inverse"," enter ")))} to submit`))}`},render(){let i=t.withGuide??Wt.withGuide,s=Er(t.output,t.message,i?`${X0(this.state)} `:"",`${Kc(this.state)} `),o=`${i?`${M("gray",nt)}
297
- `:""}${s}
298
- `,a=this.value??[],c=(u,l)=>{if(u.disabled)return e(u,"disabled");let f=a.includes(u.value);return l&&f?e(u,"active-selected"):f?e(u,"selected"):e(u,l?"active":"inactive")};switch(this.state){case"submit":{let u=this.options.filter(({value:f})=>a.includes(f)).map((f)=>e(f,"submitted")).join(M("dim",", "))||M("dim","none"),l=Er(t.output,u,i?`${M("gray",nt)} `:"");return`${o}${l}`}case"cancel":{let u=this.options.filter(({value:f})=>a.includes(f)).map((f)=>e(f,"cancelled")).join(M("dim",", "));if(u.trim()==="")return`${o}${M("gray",nt)}`;let l=Er(t.output,u,i?`${M("gray",nt)} `:"");return`${o}${l}${i?`
299
- ${M("gray",nt)}`:""}`}case"error":{let u=i?`${M("yellow",nt)} `:"",l=this.error.split(`
300
- `).map((h,m)=>m===0?`${i?`${M("yellow",Wn)} `:""}${M("yellow",h)}`:` ${h}`).join(`
301
- `),f=o.split(`
302
- `).length,d=l.split(`
303
- `).length+1;return`${o}${u}${Nd({output:t.output,options:this.options,cursor:this.cursor,maxItems:t.maxItems,columnPadding:u.length,rowPadding:f+d,style:c}).join(`
295
+ `),tk=(t)=>{let e=(i,o)=>{let s=i.label??String(i.value);return o==="disabled"?`${x("gray",Y$)} ${oa(s,(a)=>x(["strikethrough","gray"],a))}${i.hint?` ${x("dim",`(${i.hint??"disabled"})`)}`:""}`:o==="active"?`${x("cyan",gN)} ${s}${i.hint?` ${x("dim",`(${i.hint})`)}`:""}`:o==="selected"?`${x("green",q$)} ${oa(s,(a)=>x("dim",a))}${i.hint?` ${x("dim",`(${i.hint})`)}`:""}`:o==="cancelled"?`${oa(s,(a)=>x(["strikethrough","dim"],a))}`:o==="active-selected"?`${x("green",q$)} ${s}${i.hint?` ${x("dim",`(${i.hint})`)}`:""}`:o==="submitted"?`${oa(s,(a)=>x("dim",a))}`:`${x("dim",Y$)} ${oa(s,(a)=>x("dim",a))}`},n=t.required??!0,r=t.showInstructions??!0;return new ah({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValues:t.initialValues,required:n,cursorAt:t.cursorAt,validate(i){if(n&&(i===void 0||i.length===0))return`Please select at least one option.
296
+ ${x("reset",x("dim",`Press ${x(["gray","bgWhite","inverse"]," space ")} to select, ${x("gray",x("bgWhite",x("inverse"," enter ")))} to submit`))}`},render(){let i=t.withGuide??Kt.withGuide,o=Cr(t.output,t.message,i?`${Q$(this.state)} `:"",`${mu(this.state)} `),s=`${i?`${x("gray",it)}
297
+ `:""}${o}
298
+ `,a=this.value??[],c=(u,l)=>{if(u.disabled)return e(u,"disabled");let d=a.includes(u.value);return l&&d?e(u,"active-selected"):d?e(u,"selected"):e(u,l?"active":"inactive")};switch(this.state){case"submit":{let u=this.options.filter(({value:d})=>a.includes(d)).map((d)=>e(d,"submitted")).join(x("dim",", "))||x("dim","none"),l=Cr(t.output,u,i?`${x("gray",it)} `:"");return`${s}${l}`}case"cancel":{let u=this.options.filter(({value:d})=>a.includes(d)).map((d)=>e(d,"cancelled")).join(x("dim",", "));if(u.trim()==="")return`${s}${x("gray",it)}`;let l=Cr(t.output,u,i?`${x("gray",it)} `:"");return`${s}${l}${i?`
299
+ ${x("gray",it)}`:""}`}case"error":{let u=i?`${x("yellow",it)} `:"",l=this.error.split(`
300
+ `).map((h,m)=>m===0?`${i?`${x("yellow",Xn)} `:""}${x("yellow",h)}`:` ${h}`).join(`
301
+ `),d=s.split(`
302
+ `).length,f=l.split(`
303
+ `).length+1;return`${s}${u}${lh({output:t.output,options:this.options,cursor:this.cursor,maxItems:t.maxItems,columnPadding:u.length,rowPadding:d+f,style:c}).join(`
304
304
  ${u}`)}
305
305
  ${l}
306
- `}default:{let u=i?`${M("cyan",nt)} `:"",l=o.split(`
307
- `).length,f=r?t$(JR,i):i?[M("cyan",Wn)]:[],d=f.join(`
308
- `),h=f.length+1;return`${o}${u}${Nd({output:t.output,options:this.options,cursor:this.cursor,maxItems:t.maxItems,columnPadding:u.length,rowPadding:l+h,style:c}).join(`
306
+ `}default:{let u=i?`${x("cyan",it)} `:"",l=s.split(`
307
+ `).length,d=r?X$(MN,i):i?[x("cyan",Xn)]:[],f=d.join(`
308
+ `),h=d.length+1;return`${s}${u}${lh({output:t.output,options:this.options,cursor:this.cursor,maxItems:t.maxItems,columnPadding:u.length,rowPadding:l+h,style:c}).join(`
309
309
  ${u}`)}
310
- ${d}
311
- `}}}}).prompt()};var Sr={message:(t=[],{symbol:e=M("gray",nt),secondarySymbol:n=M("gray",nt),output:r=process.stdout,spacing:i=1,withGuide:s}={})=>{let o=[],a=s??Wt.withGuide,c=a?n:"",u=a?`${e} `:"",l=a?`${n} `:"";for(let d=0;d<i;d++)o.push(c);let f=Array.isArray(t)?t:t.split(`
312
- `);if(f.length>0){let[d,...h]=f;d.length>0?o.push(`${u}${d}`):o.push(a?e:"");for(let m of h)m.length>0?o.push(`${l}${m}`):o.push(a?n:"")}r.write(`${o.join(`
310
+ ${f}
311
+ `}}}}).prompt()};var Lr={message:(t=[],{symbol:e=x("gray",it),secondarySymbol:n=x("gray",it),output:r=process.stdout,spacing:i=1,withGuide:o}={})=>{let s=[],a=o??Kt.withGuide,c=a?n:"",u=a?`${e} `:"",l=a?`${n} `:"";for(let f=0;f<i;f++)s.push(c);let d=Array.isArray(t)?t:t.split(`
312
+ `);if(d.length>0){let[f,...h]=d;f.length>0?s.push(`${u}${f}`):s.push(a?e:"");for(let m of h)m.length>0?s.push(`${l}${m}`):s.push(a?n:"")}r.write(`${s.join(`
313
313
  `)}
314
- `)},info:(t,e)=>{Sr.message(t,{...e,symbol:M("blue",zR)})},success:(t,e)=>{Sr.message(t,{...e,symbol:M("green",DR)})},step:(t,e)=>{Sr.message(t,{...e,symbol:M("green",Td)})},warn:(t,e)=>{Sr.message(t,{...e,symbol:M("yellow",qR)})},warning:(t,e)=>{Sr.warn(t,e)},error:(t,e)=>{Sr.message(t,{...e,symbol:M("red",YR)})}},Mr=(t="",e)=>{let n=e?.output??process.stdout,r=e?.withGuide??Wt.withGuide?`${M("gray",Wn)} `:"";n.write(`${r}${M("red",t)}
314
+ `)},info:(t,e)=>{Lr.message(t,{...e,symbol:x("blue",yN)})},success:(t,e)=>{Lr.message(t,{...e,symbol:x("green",vN)})},step:(t,e)=>{Lr.message(t,{...e,symbol:x("green",dh)})},warn:(t,e)=>{Lr.message(t,{...e,symbol:x("yellow",SN)})},warning:(t,e)=>{Lr.warn(t,e)},error:(t,e)=>{Lr.message(t,{...e,symbol:x("red",EN)})}},Fr=(t="",e)=>{let n=e?.output??process.stdout,r=e?.withGuide??Kt.withGuide?`${x("gray",Xn)} `:"";n.write(`${r}${x("red",t)}
315
315
 
316
- `)},zc=(t="",e)=>{let n=e?.output??process.stdout,r=e?.withGuide??Wt.withGuide?`${M("gray",_R)} `:"";n.write(`${r}${t}
317
- `)},Go=(t="",e)=>{let n=e?.output??process.stdout,r=e?.withGuide??Wt.withGuide?`${M("gray",nt)}
318
- ${M("gray",Wn)} `:"";n.write(`${r}${t}
316
+ `)},pu=(t="",e)=>{let n=e?.output??process.stdout,r=e?.withGuide??Kt.withGuide?`${x("gray",pN)} `:"";n.write(`${r}${t}
317
+ `)},sa=(t="",e)=>{let n=e?.output??process.stdout,r=e?.withGuide??Kt.withGuide?`${x("gray",it)}
318
+ ${x("gray",Xn)} `:"";n.write(`${r}${t}
319
319
 
320
- `)};var VR=(t)=>t,ZR=(t,e,n)=>{let r={hard:!0,trim:!1},i=vr(t,e,r).split(`
321
- `),s=i.reduce((c,u)=>Math.max(X(u),c),0),o=i.map(n).reduce((c,u)=>Math.max(X(u),c),0),a=e-(o-s);return vr(t,a,r)},bn=(t="",e="",n)=>{let r=n?.output??Ce.stdout,i=n?.withGuide??Wt.withGuide,s=n?.format??VR,o=["",...ZR(t,Bc(r)-6,s).split(`
322
- `).map(s),""],a=X(e),c=Math.max(o.reduce((d,h)=>{let m=X(h);return m>d?m:d},0),a)+2,u=o.map((d)=>`${M("gray",nt)} ${d}${" ".repeat(c-X(d))}${M("gray",nt)}`).join(`
323
- `),l=i?`${M("gray",nt)}
324
- `:"",f=i?UR:KR;r.write(`${l}${M("green",Td)} ${M("reset",e)} ${M("gray",V0.repeat(Math.max(c-a-1,1))+BR)}
320
+ `)};var xN=(t)=>t,ON=(t,e,n)=>{let r={hard:!0,trim:!1},i=Hr(t,e,r).split(`
321
+ `),o=i.reduce((c,u)=>Math.max(_(u),c),0),s=i.map(n).reduce((c,u)=>Math.max(_(u),c),0),a=e-(s-o);return Hr(t,a,r)},Mn=(t="",e="",n)=>{let r=n?.output??Ue.stdout,i=n?.withGuide??Kt.withGuide,o=n?.format??xN,s=["",...ON(t,du(r)-6,o).split(`
322
+ `).map(o),""],a=_(e),c=Math.max(s.reduce((f,h)=>{let m=_(h);return m>f?m:f},0),a)+2,u=s.map((f)=>`${x("gray",it)} ${f}${" ".repeat(c-_(f))}${x("gray",it)}`).join(`
323
+ `),l=i?`${x("gray",it)}
324
+ `:"",d=i?wN:kN;r.write(`${l}${x("green",dh)} ${x("reset",e)} ${x("gray",J$.repeat(Math.max(c-a-1,1))+bN)}
325
325
  ${u}
326
- ${M("gray",f+V0.repeat(c+2)+WR)}
327
- `)};var y5={light:dt("─","-"),heavy:dt("━","="),block:dt("█","#")};var QR=[`${M("dim","↑/↓")} to navigate`,`${M("dim","Enter:")} confirm`],Uc=(t,e)=>t.includes(`
326
+ ${x("gray",d+J$.repeat(c+2)+$N)}
327
+ `)};var c_={light:ht("─","-"),heavy:ht("━","="),block:ht("█","#")};var IN=[`${x("dim","↑/↓")} to navigate`,`${x("dim","Enter:")} confirm`],fu=(t,e)=>t.includes(`
328
328
  `)?t.split(`
329
329
  `).map((n)=>e(n)).join(`
330
- `):e(t),n$=(t)=>{let e=(r,i)=>{if(r===void 0)return"";let s=r.label??String(r.value);switch(i){case"disabled":return`${M("gray",Wc)} ${Uc(s,(o)=>M("gray",o))}${r.hint?` ${M("dim",`(${r.hint??"disabled"})`)}`:""}`;case"selected":return`${Uc(s,(o)=>M("dim",o))}`;case"active":return`${M("green",Rd)} ${s}${r.hint?` ${M("dim",`(${r.hint})`)}`:""}`;case"cancelled":return`${Uc(s,(o)=>M(["strikethrough","dim"],o))}`;default:return`${M("dim",Wc)} ${Uc(s,(o)=>M("dim",o))}`}},n=t.showInstructions??!0;return new q0({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue,render(){let r=t.withGuide??Wt.withGuide,i=`${Kc(this.state)} `,s=`${X0(this.state)} `,o=Er(t.output,t.message,s,i),a=`${r?`${M("gray",nt)}
331
- `:""}${o}
332
- `;switch(this.state){case"submit":{let c=r?`${M("gray",nt)} `:"",u=Er(t.output,e(this.options[this.cursor],"selected"),c);return`${a}${u}`}case"cancel":{let c=r?`${M("gray",nt)} `:"",u=Er(t.output,e(this.options[this.cursor],"cancelled"),c);return`${a}${u}${r?`
333
- ${M("gray",nt)}`:""}`}default:{let c=r?`${M("cyan",nt)} `:"",u=a.split(`
334
- `).length,l=n?t$(QR,r):r?[M("cyan",Wn)]:[],f=l.join(`
335
- `),d=l.length+1;return`${a}${c}${Nd({output:t.output,cursor:this.cursor,options:this.options,maxItems:t.maxItems,columnPadding:c.length,rowPadding:u+d,style:(h,m)=>e(h,h.disabled?"disabled":m?"active":"inactive")}).join(`
330
+ `):e(t),ek=(t)=>{let e=(r,i)=>{if(r===void 0)return"";let o=r.label??String(r.value);switch(i){case"disabled":return`${x("gray",hu)} ${fu(o,(s)=>x("gray",s))}${r.hint?` ${x("dim",`(${r.hint??"disabled"})`)}`:""}`;case"selected":return`${fu(o,(s)=>x("dim",s))}`;case"active":return`${x("green",uh)} ${o}${r.hint?` ${x("dim",`(${r.hint})`)}`:""}`;case"cancelled":return`${fu(o,(s)=>x(["strikethrough","dim"],s))}`;default:return`${x("dim",hu)} ${fu(o,(s)=>x("dim",s))}`}},n=t.showInstructions??!0;return new D$({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue,render(){let r=t.withGuide??Kt.withGuide,i=`${mu(this.state)} `,o=`${Q$(this.state)} `,s=Cr(t.output,t.message,o,i),a=`${r?`${x("gray",it)}
331
+ `:""}${s}
332
+ `;switch(this.state){case"submit":{let c=r?`${x("gray",it)} `:"",u=Cr(t.output,e(this.options[this.cursor],"selected"),c);return`${a}${u}`}case"cancel":{let c=r?`${x("gray",it)} `:"",u=Cr(t.output,e(this.options[this.cursor],"cancelled"),c);return`${a}${u}${r?`
333
+ ${x("gray",it)}`:""}`}default:{let c=r?`${x("cyan",it)} `:"",u=a.split(`
334
+ `).length,l=n?X$(IN,r):r?[x("cyan",Xn)]:[],d=l.join(`
335
+ `),f=l.length+1;return`${a}${c}${lh({output:t.output,cursor:this.cursor,options:this.options,maxItems:t.maxItems,columnPadding:c.length,rowPadding:u+f,style:(h,m)=>e(h,h.disabled?"disabled":m?"active":"inactive")}).join(`
336
336
  ${c}`)}
337
- ${f}
338
- `}}}}).prompt()};var v5=`${M("gray",nt)} `;var Ad=(t)=>new Id({validate:t.validate,placeholder:t.placeholder,defaultValue:t.defaultValue,initialValue:t.initialValue,output:t.output,signal:t.signal,input:t.input,render(){let e=t?.withGuide??Wt.withGuide,n=`${`${e?`${M("gray",nt)}
339
- `:""}${Kc(this.state)} `}${t.message}
340
- `,r=t.placeholder&&t.placeholder.length>0?M("inverse",t.placeholder[0])+M("dim",t.placeholder.slice(1)):M(["inverse","hidden"],"_"),i=this.userInput?this.userInputWithCursor:r,s=this.value??"";switch(this.state){case"error":{let o=this.error?` ${M("yellow",this.error)}`:"",a=e?`${M("yellow",nt)} `:"",c=e?M("yellow",Wn):"";return`${n.trim()}
337
+ ${d}
338
+ `}}}}).prompt()};var u_=`${x("gray",it)} `;var fh=(t)=>new ch({validate:t.validate,placeholder:t.placeholder,defaultValue:t.defaultValue,initialValue:t.initialValue,output:t.output,signal:t.signal,input:t.input,render(){let e=t?.withGuide??Kt.withGuide,n=`${`${e?`${x("gray",it)}
339
+ `:""}${mu(this.state)} `}${t.message}
340
+ `,r=t.placeholder&&t.placeholder.length>0?x("inverse",t.placeholder[0])+x("dim",t.placeholder.slice(1)):x(["inverse","hidden"],"_"),i=this.userInput?this.userInputWithCursor:r,o=this.value??"";switch(this.state){case"error":{let s=this.error?` ${x("yellow",this.error)}`:"",a=e?`${x("yellow",it)} `:"",c=e?x("yellow",Xn):"";return`${n.trim()}
341
341
  ${a}${i}
342
- ${c}${o}
343
- `}case"submit":{let o=s?` ${M("dim",s)}`:"",a=e?M("gray",nt):"";return`${n}${a}${o}`}case"cancel":{let o=s?` ${M(["strikethrough","dim"],s)}`:"",a=e?M("gray",nt):"";return`${n}${a}${o}${s.trim()?`
344
- ${a}`:""}`}default:{let o=e?`${M("cyan",nt)} `:"",a=e?M("cyan",Wn):"";return`${n}${o}${i}
342
+ ${c}${s}
343
+ `}case"submit":{let s=o?` ${x("dim",o)}`:"",a=e?x("gray",it):"";return`${n}${a}${s}`}case"cancel":{let s=o?` ${x(["strikethrough","dim"],o)}`:"",a=e?x("gray",it):"";return`${n}${a}${s}${o.trim()?`
344
+ ${a}`:""}`}default:{let s=e?`${x("cyan",it)} `:"",a=e?x("cyan",Xn):"";return`${n}${s}${i}
345
345
  ${a}
346
- `}}}}).prompt();import{existsSync as vu,readFileSync as $k,rmSync as Ih}from"node:fs";import{homedir as Xe}from"node:os";import{join as Ls}from"node:path";var r$=44,ie=[{name:"Shell",lines:["«B4»~/code/demo«d» on «5»main«2» +2«3» ~1","«2»❯ «»git status -sb","«w»## «2»main«»...«1»origin/main«3» [ahead 1]","«1» M«» src/main.rs","«1»??«» notes.md","","«w»«2»❯ «»ls","«w»«B4»docs«» «B4»src«» «B4»tests«» Cargo.toml README.md","«w»","«2»❯ «»cargo test","«2» ✓«» parses config","«n»«1» ✗«» renders frame","«w»«1» ✗«» renders frame«d» expected «2»3«d», received «1»2","","«2»❯ «»echo «s»selected text«» «c» "]},{name:"Code",lines:["«d» 12 │ «5»import«» { readFile } «5»from «2»'node:fs/promises'","«d» 13 │","«d» 14 │ «8»// Read a palette and check its sixteen colors","«d» 15 │ «5»export async function «4»load«»(path: «6»string«») {","«d» 16 │ «5»const«» text = «5»await «4»readFile«»(path, «2»'utf8'«»)","«b» 17 «d»│ «5»const«» colors = «s»parse(text)«».colors ?? {}","«d» 18 │ «5»if«» (colors.ansi.length !== «3»16«») {","«d» 19 │ «5»throw new «6»Error«»(«2»'needs 16 colors'«»)","«d» 20 │ }","«d» 21 │ «5»return«» { ...colors, ratio: «c»4«3».5«» }","«d» 22 │ }"]},{name:"Diff",lines:["«2»❯ «»git diff --stat","«» src/theme.ts | 3 «2»++«1»-","«2»❯ «»git diff","«b»diff --git a/src/theme.ts b/src/theme.ts","«6»@@ -16,3 +16,4 @@«» export async function load(","«» const text = await readFile(path, 'utf8')","«1»- const colors = parse(text).colors","«2»+ const colors = parse(text).colors ?? {}","«2»+ const ratio = contrast(colors)","«2»❯ «»git log --oneline --graph -4","«3»* 3f2a1c9 («B6»HEAD -> «B2»main«3»)«» Check contrast on load","«3»* 9b04e7d«» Merge branch ansi","«1»|«5»\\","«1»| «5»* «3»51cd0aa«» Add sixteen ANSI colors","«1»|«5»/","«3»* 07be2f1 («B1»origin/main«3», «B3»tag: v1.0«3»)«» Read palette files"]},{name:"Logs",lines:["«2»❯ «»npm run dev","«B2» VITE v6.2.0«d» ready in «b»412«d» ms","«2» ➜ «b»Local«»: «6»http://localhost:5173/","«d»10:42:07 «2»INFO «» GET /api/palettes «2»200«d» 12 ms","«d»10:42:08 «2»INFO «» GET /api/themes/kita «2»200«d» 8 ms","«d»10:42:09 «3»WARN «» slow query: palettes «3»812 ms","«d»10:42:10 «4»DEBUG«» cache hit themes/kita","«d»10:42:11 «B1»ERROR«» POST /api/share «1»500«d» 41 ms","«1» Error«»: read ECONNRESET","«d» at «»TCP.onStreamRead «d»(«6»node:net:216:20«d»)","«d» at «»share «d»(«6»src/share.ts:48:11«d»)","«d»10:42:12 «2»INFO «» retry 1/3 in 200 ms"]},{name:"Monitor",lines:["«6» 1 «b»[«2»|||||||||||||«1»||«» 42.1%«b»]«6» Tasks: «b»128«», 412 thr; «B2»3«» running","«6» 2 «b»[«2»||||||«4»||«» 21.4%«b»]«6» Load average: «b»1.42 «»1.18 0.97","«6» 3 «b»[«2»||||||||||||||«1»|||||«» 71.0%«b»]«6» Uptime: «b»3 days, 04:12:55","«6» 4 «b»[«2»||«» 7.9%«b»]","«6» Mem«b»[«2»||||||||«4»||«3»||«» 6.21G/16.0G«b»]","«6» Swp«b»[«1»|«» 0.10G/2.00G«b»]","","«K2» PID USER CPU% MEM% TIME+ Command ","«s» 4127 kec 38.2 2.1 3:12.44 node dev.js ","«» 2210 kec 12.0 4.8 1:02.10 «b»ghostty","«» 3301 kec 4.4 1.2 0:05.61 «b»zsh","«» 812 «1»root«» 3.1 0.3 0:44.02 «d»kernel_task","«» 167 «1»root«» 0.9 0.1 0:12.80 «d»WindowServer"]}];function bi(t){let e=ie.length;return ie[(t%e+e)%e]}function Dc(t,e){let n=t.split("«"),r=n[0]?[[n[0],""]]:[];for(let i of n.slice(1)){let s=i.indexOf("»"),o=i.slice(0,s),a=i.slice(s+1);if(o==="w"||o==="n"){if(o==="w"!==e>=44)return}if(a)r.push([a,o==="w"||o==="n"?"":o])}return r}import{createHash as cN}from"node:crypto";import{existsSync as Jc,readFileSync as _d,rmSync as s$}from"node:fs";import{homedir as o$}from"node:os";import{join as wi}from"node:path";function Or(t){return[`# ${t.name} — ${t.group}${t.native?` (${t.native})`:""}`,`# ANSI: ${t.ansiSource}`]}function Kn(t,e){return[`[${t}]`,`Color=${rt(e).join(",")}`,""]}function Pd(t,e,n=["Wallpaper="]){let r=(i)=>Bt(i,t.background,0.5);return[...Kn("Background",t.background),...Kn("BackgroundFaint",t.background),...Kn("BackgroundIntense",t.background),...t.ansi.slice(0,8).flatMap((i,s)=>[...Kn(`Color${s}`,i),...Kn(`Color${s}Faint`,r(i)),...Kn(`Color${s}Intense`,t.ansi[s+8])]),...Kn("Foreground",t.foreground),...Kn("ForegroundFaint",r(t.foreground)),...Kn("ForegroundIntense",t.foreground),"[General]","Blur=false","ColorRandomization=false",`Description=${e}`,"Opacity=1",...n,""]}var i$={left:"0",top:"0",center:"0.5",right:"1",bottom:"1"};function XR(t){if(!t||t.opacity<=0)return["Wallpaper="];let[e="center",n="center"]=t.position.split("-");return[`Wallpaper=${t.image}`,`FillStyle=${t.cover?"Crop":"Adapt"}`,`Anchor=${i$[n]??"0.5"},${i$[e]??"0.5"}`,`WallpaperOpacity=${t.opacity}`]}function Hd(t,e){return[...Or(t),"",...Pd(t,`ttheme · ${t.name}`,XR(e))].join(`
347
- `)}var Fd={id:"konsole",limits:"draws no OSC 4, so a tab repaints by switching color scheme",emit(t){return[{path:`konsole/${H(t.name)}.colorscheme`,content:Hd(t)}]}};import{openSync as tN,writeSync as eN}from"node:fs";import{ReadStream as nN}from"node:tty";var xr=["11","10","12","17",...Array.from({length:16},(t,e)=>`4;${e}`)];function Lt(t=process.env){return Boolean(t.NO_COLOR)||t.TERM==="dumb"}function Uo(t,e){return`\x1B]${xr[t]};${e}\x1B\\`}function zn(t,e){return[t.background,t.foreground,t.cursor,t.selection,...t.ansi].map((n,r)=>e&&!e.includes(r)?"":Uo(r,n)).join("")}function rN(t){return`\x1B]${t.startsWith("4;")?`104;${t.slice(2)}`:`1${t}`}\x1B\\`}function iN(t){let e=new Map;for(let n of t.split("\x1B")){let r=n.match(/^\](\d+(?:;\d+)?);(rgba?:[0-9a-fA-F/]+)/),[,i,s]=r??[];if(i&&s)e.set(i,s)}return e}function sN(t){return`#${t.slice(t.indexOf(":")+1).split("/").slice(0,3).map((n)=>n.slice(0,2).padStart(2,"0")).join("")}`}function qc(t,e=[...t.keys()],n=!1){return e.map((r)=>{let i=t.get(r);return i?`\x1B]${r};${n?sN(i):i}\x1B\\`:rN(r)}).join("")}function Yc(t,e){return`\x1B]50;ColorScheme=${t};UseCustomCursorColor=true;customCursorColor=${e}\x07`}function oN(t=xr){return`${t.map((e)=>`\x1B]${e};?\x1B\\`).join("")}\x1B[5n`}function aN(t){return t.includes("\x1B[0n")}async function Cd(t=xr){let e,n;try{e=tN("/dev/tty","r+"),n=new nN(e),n.setRawMode(!0)}catch{return new Map}try{eN(e,oN(t));let r="";return await new Promise((i)=>{let s=setTimeout(i,120);n.on("data",(o)=>{if(r+=o.toString(),aN(r))clearTimeout(s),i()})}),iN(r)}finally{n.setRawMode(!1),n.destroy()}}function Gd(t){if(t.NVIM)return"nvim";if(t.VIM_TERMINAL)return"vim";if(t.INSIDE_EMACS)return"emacs";return t.TERM_PROGRAM==="vscode"?"vscode":void 0}function Kt(t){if(Gd(t))return"editor";if(t.TERM_PROGRAM==="WarpTerminal")return"warp";if(t.GHOSTTY_RESOURCES_DIR||t.TERM_PROGRAM==="ghostty")return"ghostty";if(t.KITTY_WINDOW_ID)return"kitty";if(t.WEZTERM_PANE)return"wezterm";if(t.ALACRITTY_WINDOW_ID)return"alacritty";if(t.KONSOLE_VERSION)return"konsole";if(t.ITERM_SESSION_ID||t.TERM_PROGRAM==="iTerm.app")return"iterm2";if(t.TERM_PROGRAM==="Apple_Terminal")return"terminal-app";if(t.WT_SESSION&&!t.TERM_PROGRAM)return"windows-terminal";if(t.TERM?.startsWith("foot"))return"foot";return"unknown"}var de={ghostty:{links:!0,pictures:!0,bands:!1,files:!0,moves:!0,layers:!0,paints:!0},kitty:{links:!0,pictures:!0,bands:!1,files:!0,moves:!0,layers:!0,paints:!0},iterm2:{links:!0,pictures:!0,bands:!0,files:!0,moves:!0,layers:!0,paints:!0,repaint:[0,1]},wezterm:{links:!0,pictures:!0,bands:!1,files:!0,moves:!0,layers:!1,paints:!0,wipes:!0,views:!0},alacritty:{links:!0,pictures:!1,bands:!1,files:!0,moves:!0,layers:!0,paints:!0},"windows-terminal":{links:!0,pictures:!1,bands:!1,files:!0,moves:!0,layers:!0,paints:!0},konsole:{links:!1,pictures:!0,bands:!1,files:!0,moves:!0,layers:!0,paints:!0,repaint:[0,1],hex:!0,schemes:!0},foot:{links:!0,pictures:!1,bands:!1,files:!0,moves:!0,layers:!0,paints:!0},"terminal-app":{links:!1,pictures:!1,bands:!1,files:!0,moves:!0,layers:!0,paints:!0},warp:{links:!0,pictures:!0,bands:!0,files:!1,moves:!1,layers:!1,paints:!1},editor:{links:!1,pictures:!1,bands:!1,files:!0,moves:!0,layers:!0,paints:!1},unknown:{links:!1,pictures:!1,bands:!1,files:!0,moves:!0,layers:!0,paints:!0}};function Ld(t,e,n){let r="";for(let i of t.split(`
348
- `)){let s=i.trim();if(s.startsWith("[")&&s.endsWith("]"))r=s.slice(1,-1);else if(r===e&&s.startsWith(`${n}=`))return s.slice(n.length+1)}return}function uN(t){let e=t.XDG_CONFIG_HOME??wi(o$(),".config"),n=wi(e,"konsolerc"),r=Jc(n)?Ld(_d(n,"utf8"),"Desktop Entry","DefaultProfile"):void 0;for(let i=0;i<8&&r&&r!=="FALLBACK/";i++){let s=r.endsWith(".profile")?r:`${r}.profile`,o=l$(t).map((u)=>wi(u,s)).find((u)=>Jc(u));if(!o)return!1;let a=_d(o,"utf8"),c=Ld(a,"Interaction Options","AllowEscapedLinks");if(c!==void 0)return c==="true";r=Ld(a,"General","Parent")}return!1}function a$(t){let e=Kt(t);return e==="konsole"?uN(t):de[e].links}function Vc(t,e){let n=Kt(t),r=de[n];return r.pictures&&!t.TMUX&&(!r.views||e.includes(n))}function Zc(t){return de[Kt(t)].bands}function Qc(t){return de[Kt(t)].files}function Xc(t){return de[Kt(t)].layers}function c$(t){return de[Kt(t)].moves}function u$(t){return de[Kt(t)].wipes===!0}function $i(t){return de[Kt(t)].views===!0}function ki(t){return`\x1B]1337;SetUserVar=ttheme_view=${Buffer.from(t).toString("base64")}\x07`}var yi="\x1B[H\x1B[K\x1B[2H\x1B[J\x1B[H",Bd=120,jd=4,lN=40;function fN(t){let e=t.TTHEME_ITERM_SHOWN;return t.TTHEME_ITERM_SWITCH==="1"&&t.TTHEME_ITERM_DYED==="0"&&e?`ttheme · ${e}`:void 0}function dN(t,e){let n=de.iterm2.repaint??[],r=xr.map((c,u)=>u).filter((c)=>!n.includes(c)),i=new Set(n),s=fN(t),o=[],a=()=>{for(let c of o)clearTimeout(c);o=[]};return{slots:n,paint(c){a();for(let u=0;u<r.length;u+=jd){let l=r.slice(u,u+jd),f=setTimeout(()=>{for(let d of l)i.add(d);e(zn(c,l))},Bd+u/jd*lN);f.unref?.(),o.push(f)}return zn(c,n)},wear:(c)=>zn(c),saved:()=>Cd(),restore(c){a();let u=xr.filter((l,f)=>i.has(f));return s?`\x1B[?2026h${qc(new Map,u)}\x1B]1337;SetProfile=${s}\x07\x1B[?2026l`:qc(c,u)},stop:a}}var hN=3,mN=/^(Wallpaper|FillStyle|Anchor|WallpaperOpacity|WallpaperFlipType)=/;function l$(t){return[t.XDG_DATA_HOME??wi(o$(),".local","share"),...(t.XDG_DATA_DIRS||"/usr/local/share:/usr/share").split(":")].map((e)=>wi(e,"konsole"))}function pN(t,e){let n=/(?:^|;)ColorScheme=([^;]+)/.exec(e)?.[1],r=n&&t.map((c)=>wi(c,`${n}.colorscheme`)).find((c)=>Jc(c));if(!r)return["Wallpaper="];let i=_d(r,"utf8").split(`
349
- `),s=i.findIndex((c)=>c.trim()==="[General]"),o=i.findIndex((c,u)=>u>s&&c.trimStart().startsWith("[")),a=s<0?[]:i.slice(s+1,o<0?void 0:o).filter((c)=>mN.test(c));return a.length>0?a:["Wallpaper="]}function gN(t,e,n){let r=l$(t),i=r[0],s=pN(r,e),o=[],a=(u,l,f)=>{let d=Pd(l,`ttheme · ${u}`,s).join(`
350
- `),h=`${H("view")}.${cN("sha1").update(d).digest("hex").slice(0,10)}`,m=wi(i,`${h}.colorscheme`);if(!Jc(m))P(m,d);if(!o.includes(m))o.push(m);for(let $ of o.splice(0,Math.max(0,o.length-hN)))s$($,{force:!0});return Yc(h,f)},c=()=>{for(let u of o.splice(0))s$(u,{force:!0})};return{slots:[],paint:(u)=>a(u.name,u,u.cursor),look:(u,l)=>{let[f="",d="",h="",,...m]=l;n(a(u,{background:f,foreground:d,ansi:m},h))},wear:(u,l)=>l.includes("konsole")?Yc(H(u.name),u.cursor):void 0,saved:async()=>new Map,restore:()=>{return c(),`\x1B]50;${e}\x07`},stop:c}}function f$(t,e,n=(r)=>{process.stdout.write(r)}){let r=Kt(t),i=de[r];if(!e||Lt(t)||t.TMUX||!i.paints)return;if(r==="iterm2")return dN(t,n);if(r==="konsole"&&t.TTHEME_KONSOLE_LOOK)return gN(t,t.TTHEME_KONSOLE_LOOK,n);let s=i.repaint??xr.map((a,c)=>c),o=xr.filter((a,c)=>s.includes(c));return{slots:s,paint:(a)=>zn(a,s),wear:(a,c)=>!i.schemes?zn(a):c.includes(r)?Yc(H(a.name),a.cursor):void 0,saved:()=>Cd(o),restore:(a)=>qc(a,o,i.hex===!0)}}var qt=["ghostty","kitty","alacritty","wezterm","iterm2","windows-terminal","warp","konsole","terminal-app"];var bN=[{section:"tab",title:"This tab"},{section:"startup",title:"New tabs"},{section:"catalog",title:"Palettes"},{section:"own",title:"Your own"},{section:"setup",title:"Setup"},{section:"support",title:"Support"}],Ko=[{name:"preview",args:[],about:"Try palettes live — focus repaints, enter edits its tone and picture and applies it, esc restores, ? lists keys",section:"tab",start:"Try every palette live — enter tunes the one you land on and applies it",shell:!0},{name:"use",args:["<palette>"],about:"Paint this tab — a unique prefix works: ttheme use ho",section:"tab",start:"Paint this tab with one — ttheme use homura",shell:!0},{name:"next",args:[],about:"Advance this tab to the next palette",section:"tab",shell:!0},{name:"default",args:["<palette>"],about:"Make a palette the one new tabs open with",section:"startup"},{name:"on",args:[],about:"Wear the default palette in new tabs again",section:"startup"},{name:"off",args:[],about:"Take the palette and picture off every tab — the terminal's own colors until `ttheme on`",section:"startup"},{name:"pin",args:["[directory|ssh:<host>]"],about:"Pick a palette for this directory, everything below it, its repository or an ssh host — cd or ssh in repaints, leaving restores",section:"tab",shell:!0},{name:"unpin",args:["[directory|ssh:<host>]"],about:"Drop a pin — this directory's, every one below it, the one above that paints it, or an ssh host's",section:"tab",shell:!0},{name:"pins",args:[],about:"Map every pinned directory as a tree in its palette's colors, every ssh host, and the pin that covers this one",section:"tab",shell:!0},{name:"config",args:[],about:"Edit settings in $EDITOR — they apply in new tabs",section:"startup",shell:!0},{name:"browse",args:[],about:"Pick palettes and markets in a live picker — shift+←/→ moves between Catalog, Installed, Markets and Errors",section:"catalog",start:"Install or drop palettes, add markets — every change applies at once on enter"},{name:"list",args:["[query]"],about:"Show the catalog, marking what is installed",section:"catalog",flags:{json:{type:"boolean",about:"Print the matches as JSON: name, group, catalog, installed"}}},{name:"add",args:["<palette...>"],about:"Install palettes from the catalog, or from a share code: ttheme add tt1:…",section:"catalog",flags:{market:{type:"string",value:"<source>",about:"Add this market first — a repository, a folder or official — and take bare palette names from it"}}},{name:"remove",args:["<palette...>"],about:"Uninstall palettes",section:"catalog"},{name:"update",args:[],about:"Refresh every market you added now — those with auto-update refresh on their own once a day",section:"catalog"},{name:"market",args:["[action]","[source]"],about:"The markets you added — add, remove and search them; init makes one of your own",actions:[["(none)","List the markets you added: palettes, auto-update and the last update"],["add <source>","Add one: a repository (alice/ttheme-pastel, #v1 pins a tag or branch), a folder, or official — asks whether it updates on its own"],["remove <market>","Drop one by its name (alice@pastel) — the palettes you installed from it keep working"],["search [query]","Repositories on GitHub with the ttheme-market topic"],["init [name]","Make a market of your own, <you>@<name>, in ~/.config/ttheme/market/<name> (or give a folder)"],["check [dir]","Check a market's folder before you push it — ttheme-market.toml, every palette, the renames and the gate; nothing is written"]],section:"catalog"},{name:"new",args:["<name>"],about:"Make a palette of your own, <you>@<market>/<name>, from blank in the palette editor — installed at once",section:"own",flags:{from:{type:"string",value:"<palette>",about:"Open the editor on this palette's colors instead of blank"},in:{type:"string",value:"<market>",about:"The local market to put it in, when you have more than one"}}},{name:"edit",args:["<palette>"],about:"Change one of your palettes in the palette editor — the contrast gate advises, never refuses",section:"own"},{name:"check",args:["<palette>"],about:"Measure a palette against the contrast gate and suggest colors that pass",section:"own",flags:{fix:{type:"boolean",about:"Write the suggested colors into your palette"}}},{name:"share",args:["<palette>"],about:"Print a share code — ttheme add <code> installs it anywhere, pictures included",section:"own",flags:{tone:{type:"string",value:"<tuned|original>",choices:["tuned","original"],about:"Share the palette as you tuned its colors, or as it was — asked when you tuned it and omit this"}}},{name:"init",args:[],about:"Install the shell layer and wire your terminal configs",section:"setup",flags:{yes:{type:"boolean",short:"y",about:"Accept every default without prompting"}}},{name:"uninstall",args:[],about:"Take ttheme out of every terminal config and delete what it wrote",section:"setup",flags:{yes:{type:"boolean",short:"y",about:"Remove without asking"}}},{name:"wire",args:["<terminal>"],about:"Wire one more terminal into this setup, after showing what it edits — the shell offers it in a terminal that paints only through the config init would have wired",section:"setup",hidden:!0},{name:"info",args:[],about:"Print what a bug report needs — version, OS, shell, terminal and the settings you changed",section:"support"},{name:"build",args:[],about:"Emit dist/ for every terminal, plus the zsh palette table — from a checkout",section:"setup",hidden:!0,flags:{only:{type:"string",multiple:!0,value:"<terminal>",choices:qt,about:"Rebuild just this terminal — repeat it for more"}}},{name:"find",args:["<palette>"],about:"Pick a booru background for a palette — preview opens this on tab",section:"setup",hidden:!0},{name:"image",args:["<palette>","<action>","[picture]"],about:"Show one of a palette's saved backgrounds, remove one, draw one in its palette's tone or its own colors (or get the other ready before it is asked for), or pass on tuning — preview calls this",section:"setup",hidden:!0},{name:"flatten",args:["<source>","<out>","<background>","<opacity>","[canvas]","[place]","[into]"],about:"Lay a picture on a background color at an opacity, placed on a canvas when given one, for Warp, which fades the window instead, and Terminal.app, which takes it written into the file its profile points at and renamed to the out — preview calls this",section:"setup",hidden:!0},{name:"bake",args:["<source>","<out>","<canvas>","<place>"],about:"Place a picture on a transparent canvas the way sips bakes preview's tuning — preview in Warp calls this",section:"setup",hidden:!0},{name:"tone",args:["<palette>"],about:"Serve a palette's tone editor over stdin and stdout — preview's palette panel runs it",section:"setup",hidden:!0},{name:"redraw",args:[],about:"Draw the background pictures again after TTHEME_BG_BLUR changed — ttheme config and preview call this",section:"setup",hidden:!0},{name:"names",args:[],about:"Download aninames' character names when its release changed and index them — any command starts this in the background once a day",section:"setup",hidden:!0}];function Wo(t){let e=Object.entries(t.flags??{}).map(([n,{value:r}])=>`[--${n}${r?` ${r}`:""}]`);return[t.name,...e,...t.args].join(" ")}function Ud(t,e=Math.max(...t.map(([n])=>n.length))){return t.map(([n,r])=>` ${n.padEnd(e)} ${r}`)}var wN=[["npx @kecan0406/ttheme init -y","Wire the terminals found here, no prompts"],["ttheme add homura madoka","Install two palettes"],["ttheme use homura","Paint this tab with one"],["ttheme list --json madoka","The madoka series as JSON"],["ttheme market add alice/ttheme-pastel","alice's market, alice@pastel — ttheme add alice@pastel/dusk"],["ttheme add dusk --market alice/ttheme-pastel","The same in one step"],["ttheme new rei --from rei","Your own rei, <you>@<market>/rei, to edit and share"]];function zo(t,e=!1){let n=Ko.filter((o)=>!o.hidden&&!(e&&o.section==="setup")),r=bN.filter(({section:o})=>n.some((a)=>a.section===o)),i=[...e?["ttheme alone opens preview and browse as tabs — tab and shift+tab move between them"]:[],t?"ttheme help <command> describes one command · ttheme --version prints the version":"ttheme help <command> describes one · ttheme help all lists every command with what it does","https://kecan0406.github.io/ttheme"];if(!t){let o=n.filter((c)=>c.start),a=Math.max(...r.map(({title:c})=>c.length));return["Usage: ttheme <command>","",It.description,"","Start here",...Ud(o.map((c)=>[Wo(c),c.start])),"",...r.map(({section:c,title:u})=>`${u.padEnd(a)} ${n.filter((l)=>l.section===c).map((l)=>l.name).join(" · ")}`),"",...i].join(`
351
- `)}let s=Math.max(...n.map((o)=>Wo(o).length));return["Usage: ttheme <command>","",It.description,...r.flatMap(({section:o,title:a})=>["",a,...Ud(n.filter((c)=>c.section===o).map((c)=>[Wo(c),c.about]),s)]),"","Examples",...Ud(wN),"",...i].join(`
352
- `)}import{readFileSync as $N}from"node:fs";import{join as kN}from"node:path";var Wd="# ttheme begin",Kd="# ttheme end",Rs=/# ttheme begin\n[\s\S]*?# ttheme end\n?/;function Ir(t,e){let n=`${Wd}
346
+ `}}}}).prompt();import{existsSync as Wu,readFileSync as ky,rmSync as um}from"node:fs";import{homedir as an}from"node:os";import{join as ts}from"node:path";var nk=44,zt=[{name:"Shell",lines:["«B4»~/code/demo«d» on «5»main«2» +2«3» ~1","«2»❯ «»git status -sb","«w»## «2»main«»...«1»origin/main«3» [ahead 1]","«1» M«» src/main.rs","«1»??«» notes.md","","«w»«2»❯ «»ls","«w»«B4»docs«» «B4»src«» «B4»tests«» Cargo.toml README.md","«w»","«2»❯ «»cargo test","«2» ✓«» parses config","«n»«1» ✗«» renders frame","«w»«1» ✗«» renders frame«d» expected «2»3«d», received «1»2","","«2»❯ «»echo «s»selected text«» «c» "]},{name:"Code",lines:["«d» 12 │ «5»import«» { readFile } «5»from «2»'node:fs/promises'","«d» 13 │","«d» 14 │ «8»// Read a palette and check its sixteen colors","«d» 15 │ «5»export async function «4»load«»(path: «6»string«») {","«d» 16 │ «5»const«» text = «5»await «4»readFile«»(path, «2»'utf8'«»)","«b» 17 «d»│ «5»const«» colors = «s»parse(text)«».colors ?? {}","«d» 18 │ «5»if«» (colors.ansi.length !== «3»16«») {","«d» 19 │ «5»throw new «6»Error«»(«2»'needs 16 colors'«»)","«d» 20 │ }","«d» 21 │ «5»return«» { ...colors, ratio: «c»4«3».5«» }","«d» 22 │ }"]},{name:"Diff",lines:["«2»❯ «»git diff --stat","«» src/theme.ts | 3 «2»++«1»-","«2»❯ «»git diff","«b»diff --git a/src/theme.ts b/src/theme.ts","«6»@@ -16,3 +16,4 @@«» export async function load(","«» const text = await readFile(path, 'utf8')","«1»- const colors = parse(text).colors","«2»+ const colors = parse(text).colors ?? {}","«2»+ const ratio = contrast(colors)","«2»❯ «»git log --oneline --graph -4","«3»* 3f2a1c9 («B6»HEAD -> «B2»main«3»)«» Check contrast on load","«3»* 9b04e7d«» Merge branch ansi","«1»|«5»\\","«1»| «5»* «3»51cd0aa«» Add sixteen ANSI colors","«1»|«5»/","«3»* 07be2f1 («B1»origin/main«3», «B3»tag: v1.0«3»)«» Read palette files"]},{name:"Logs",lines:["«2»❯ «»npm run dev","«B2» VITE v6.2.0«d» ready in «b»412«d» ms","«2» ➜ «b»Local«»: «6»http://localhost:5173/","«d»10:42:07 «2»INFO «» GET /api/palettes «2»200«d» 12 ms","«d»10:42:08 «2»INFO «» GET /api/themes/kita «2»200«d» 8 ms","«d»10:42:09 «3»WARN «» slow query: palettes «3»812 ms","«d»10:42:10 «4»DEBUG«» cache hit themes/kita","«d»10:42:11 «B1»ERROR«» POST /api/share «1»500«d» 41 ms","«1» Error«»: read ECONNRESET","«d» at «»TCP.onStreamRead «d»(«6»node:net:216:20«d»)","«d» at «»share «d»(«6»src/share.ts:48:11«d»)","«d»10:42:12 «2»INFO «» retry 1/3 in 200 ms"]},{name:"Monitor",lines:["«6» 1 «b»[«2»|||||||||||||«1»||«» 42.1%«b»]«6» Tasks: «b»128«», 412 thr; «B2»3«» running","«6» 2 «b»[«2»||||||«4»||«» 21.4%«b»]«6» Load average: «b»1.42 «»1.18 0.97","«6» 3 «b»[«2»||||||||||||||«1»|||||«» 71.0%«b»]«6» Uptime: «b»3 days, 04:12:55","«6» 4 «b»[«2»||«» 7.9%«b»]","«6» Mem«b»[«2»||||||||«4»||«3»||«» 6.21G/16.0G«b»]","«6» Swp«b»[«1»|«» 0.10G/2.00G«b»]","","«K2» PID USER CPU% MEM% TIME+ Command ","«s» 4127 kec 38.2 2.1 3:12.44 node dev.js ","«» 2210 kec 12.0 4.8 1:02.10 «b»ghostty","«» 3301 kec 4.4 1.2 0:05.61 «b»zsh","«» 812 «1»root«» 3.1 0.3 0:44.02 «d»kernel_task","«» 167 «1»root«» 0.9 0.1 0:12.80 «d»WindowServer"]}];function Ii(t){let e=zt.length;return zt[(t%e+e)%e]}function Wo(t,e){let n=t.split("«"),r=n[0]?[[n[0],""]]:[];for(let i of n.slice(1)){let o=i.indexOf("»"),s=i.slice(0,o),a=i.slice(o+1);if(s==="w"||s==="n"){if(s==="w"!==e>=44)return}if(a)r.push([a,s==="w"||s==="n"?"":s])}return r}import{createHash as FN}from"node:crypto";import{existsSync as wu,readFileSync as kh,rmSync as sk}from"node:fs";import{homedir as ak}from"node:os";import{join as Ri}from"node:path";function jr(t){return[`# ${t.name} — ${t.group}${t.native?` (${t.native})`:""}`,`# ANSI: ${t.ansiSource}`]}function tr(t,e){return[`[${t}]`,`Color=${et(e).join(",")}`,""]}function hh(t,e,n=["Wallpaper="]){let r=(i)=>pt(i,t.background,0.5);return[...tr("Background",t.background),...tr("BackgroundFaint",t.background),...tr("BackgroundIntense",t.background),...t.ansi.slice(0,8).flatMap((i,o)=>[...tr(`Color${o}`,i),...tr(`Color${o}Faint`,r(i)),...tr(`Color${o}Intense`,t.ansi[o+8])]),...tr("Foreground",t.foreground),...tr("ForegroundFaint",r(t.foreground)),...tr("ForegroundIntense",t.foreground),"[General]","Blur=false","ColorRandomization=false",`Description=${e}`,"Opacity=1",...n,""]}var rk={left:"0",top:"0",center:"0.5",right:"1",bottom:"1"};function RN(t){if(!t||t.opacity<=0)return["Wallpaper="];let[e="center",n="center"]=t.position.split("-");return[`Wallpaper=${t.image}`,`FillStyle=${t.cover?"Crop":"Adapt"}`,`Anchor=${rk[n]??"0.5"},${rk[e]??"0.5"}`,`WallpaperOpacity=${t.opacity}`]}function mh(t,e){return[...jr(t),"",...hh(t,`ttheme · ${t.name}`,RN(e))].join(`
347
+ `)}var ph={id:"konsole",limits:"draws no OSC 4, so a tab repaints by switching color scheme",emit(t){return[{path:`konsole/${j(t.name)}.colorscheme`,content:mh(t)}]}};import{openSync as PN,writeSync as NN}from"node:fs";import{ReadStream as AN}from"node:tty";var rn=["11","10","12","17",...Array.from({length:16},(t,e)=>`4;${e}`)];function Pt(t=process.env){return Boolean(t.NO_COLOR)||t.TERM==="dumb"}function TN(t,e){return`\x1B]${rn[t]};${e}\x1B\\`}function er(t,e){return[t.background,t.foreground,t.cursor,t.selection,...t.ansi].map((n,r)=>e&&!e.includes(r)?"":TN(r,n)).join("")}function HN(t){return`\x1B]${t.startsWith("4;")?`104;${t.slice(2)}`:`1${t}`}\x1B\\`}function CN(t){let e=new Map;for(let n of t.split("\x1B")){let r=n.match(/^\](\d+(?:;\d+)?);(rgba?:[0-9a-fA-F/]+)/),[,i,o]=r??[];if(i&&o)e.set(i,o)}return e}function ik(t){return`#${t.slice(t.indexOf(":")+1).split("/").slice(0,3).map((n)=>n.slice(0,2).padStart(2,"0")).join("")}`}function ok(t){return rn.map((e)=>{let n=t.get(e);return n?ik(n):void 0})}function gu(t,e=[...t.keys()],n=!1){return e.map((r)=>{let i=t.get(r);return i?`\x1B]${r};${n?ik(i):i}\x1B\\`:HN(r)}).join("")}function bu(t,e){return`\x1B]50;ColorScheme=${t};UseCustomCursorColor=true;customCursorColor=${e}\x07`}function gh(t=rn,e="\x1B[5n"){return`${t.map((n)=>`\x1B]${n};?\x1B\\`).join("")}${e}`}function LN(t){return t.includes("\x1B[0n")}async function bh(t=rn){let e,n;try{e=PN("/dev/tty","r+"),n=new AN(e),n.setRawMode(!0)}catch{return new Map}try{NN(e,gh(t));let r="";return await new Promise((i)=>{let o=setTimeout(i,120);n.on("data",(s)=>{if(r+=s.toString(),LN(r))clearTimeout(o),i()})}),CN(r)}finally{n.setRawMode(!1),n.destroy()}}function yh(t){if(t.NVIM)return"nvim";if(t.VIM_TERMINAL)return"vim";if(t.INSIDE_EMACS)return"emacs";return t.TERM_PROGRAM==="vscode"?"vscode":void 0}function Dt(t){if(yh(t))return"editor";if(t.TERM_PROGRAM==="WarpTerminal")return"warp";if(t.GHOSTTY_RESOURCES_DIR||t.TERM_PROGRAM==="ghostty")return"ghostty";if(t.KITTY_WINDOW_ID)return"kitty";if(t.WEZTERM_PANE)return"wezterm";if(t.ALACRITTY_WINDOW_ID)return"alacritty";if(t.KONSOLE_VERSION)return"konsole";if(t.ITERM_SESSION_ID||t.TERM_PROGRAM==="iTerm.app")return"iterm2";if(t.TERM_PROGRAM==="Apple_Terminal")return"terminal-app";if(t.WT_SESSION&&!t.TERM_PROGRAM)return"windows-terminal";if(t.TERM?.startsWith("foot"))return"foot";return"unknown"}var pe={ghostty:{links:!0,pictures:!0,bands:!1,files:!0,moves:!0,layers:!0,paints:!0},kitty:{links:!0,pictures:!0,bands:!1,files:!0,moves:!0,layers:!0,paints:!0},iterm2:{links:!0,pictures:!0,bands:!0,files:!0,moves:!0,layers:!0,paints:!0,repaint:[0,1]},wezterm:{links:!0,pictures:!0,bands:!1,files:!0,moves:!0,layers:!1,paints:!0,wipes:!0,views:!0},alacritty:{links:!0,pictures:!1,bands:!1,files:!0,moves:!0,layers:!0,paints:!0},"windows-terminal":{links:!0,pictures:!1,bands:!1,files:!0,moves:!0,layers:!0,paints:!0},konsole:{links:!1,pictures:!0,bands:!1,files:!0,moves:!0,layers:!0,paints:!0,repaint:[0,1],hex:!0,schemes:!0},foot:{links:!0,pictures:!1,bands:!1,files:!0,moves:!0,layers:!0,paints:!0},"terminal-app":{links:!1,pictures:!1,bands:!1,files:!0,moves:!0,layers:!0,paints:!0},warp:{links:!0,pictures:!0,bands:!0,files:!1,moves:!1,layers:!1,paints:!1},editor:{links:!1,pictures:!1,bands:!1,files:!0,moves:!0,layers:!0,paints:!1},unknown:{links:!1,pictures:!1,bands:!1,files:!0,moves:!0,layers:!0,paints:!0}};function wh(t,e,n){let r="";for(let i of t.split(`
348
+ `)){let o=i.trim();if(o.startsWith("[")&&o.endsWith("]"))r=o.slice(1,-1);else if(r===e&&o.startsWith(`${n}=`))return o.slice(n.length+1)}return}function jN(t){let e=t.XDG_CONFIG_HOME??Ri(ak(),".config"),n=Ri(e,"konsolerc"),r=wu(n)?wh(kh(n,"utf8"),"Desktop Entry","DefaultProfile"):void 0;for(let i=0;i<8&&r&&r!=="FALLBACK/";i++){let o=r.endsWith(".profile")?r:`${r}.profile`,s=dk(t).map((u)=>Ri(u,o)).find((u)=>wu(u));if(!s)return!1;let a=kh(s,"utf8"),c=wh(a,"Interaction Options","AllowEscapedLinks");if(c!==void 0)return c==="true";r=wh(a,"General","Parent")}return!1}function ck(t){let e=Dt(t);return e==="konsole"?jN(t):pe[e].links}function Ko(t,e){let n=Dt(t),r=pe[n];return r.pictures&&!t.TMUX&&(!r.views||e.includes(n))}function $u(t){return pe[Dt(t)].bands}function ku(t){return pe[Dt(t)].files}function zo(t){return pe[Dt(t)].layers}function uk(t){return pe[Dt(t)].moves}function lk(t){return pe[Dt(t)].wipes===!0}function Pi(t){return pe[Dt(t)].views===!0}function Ni(t){return`\x1B]1337;SetUserVar=ttheme_view=${Buffer.from(t).toString("base64")}\x07`}var Ai="\x1B[H\x1B[K\x1B[2H\x1B[J\x1B[H",vh=120,$h=4,_N=40;function BN(t){let e=t.TTHEME_ITERM_SHOWN;return t.TTHEME_ITERM_SWITCH==="1"&&t.TTHEME_ITERM_DYED==="0"&&e?`ttheme · ${e}`:void 0}function GN(t,e){let n=pe.iterm2.repaint??[],r=rn.map((c,u)=>u).filter((c)=>!n.includes(c)),i=new Set(n),o=BN(t),s=[],a=()=>{for(let c of s)clearTimeout(c);s=[]};return{slots:n,paint(c){a();for(let u=0;u<r.length;u+=$h){let l=r.slice(u,u+$h),d=setTimeout(()=>{for(let f of l)i.add(f);e(er(c,l))},vh+u/$h*_N);d.unref?.(),s.push(d)}return er(c,n)},wear:(c)=>er(c),saved:()=>bh(),restore(c){a();let u=rn.filter((l,d)=>i.has(d));return o?`\x1B[?2026h${gu(new Map,u)}\x1B]1337;SetProfile=${o}\x07\x1B[?2026l`:gu(c,u)},stop:a}}var UN=3,WN=/^(Wallpaper|FillStyle|Anchor|WallpaperOpacity|WallpaperFlipType)=/;function dk(t){return[t.XDG_DATA_HOME??Ri(ak(),".local","share"),...(t.XDG_DATA_DIRS||"/usr/local/share:/usr/share").split(":")].map((e)=>Ri(e,"konsole"))}function KN(t,e){let n=/(?:^|;)ColorScheme=([^;]+)/.exec(e)?.[1],r=n&&t.map((c)=>Ri(c,`${n}.colorscheme`)).find((c)=>wu(c));if(!r)return["Wallpaper="];let i=kh(r,"utf8").split(`
349
+ `),o=i.findIndex((c)=>c.trim()==="[General]"),s=i.findIndex((c,u)=>u>o&&c.trimStart().startsWith("[")),a=o<0?[]:i.slice(o+1,s<0?void 0:s).filter((c)=>WN.test(c));return a.length>0?a:["Wallpaper="]}function zN(t,e){let n=dk(t),r=n[0],i=KN(n,e),o=[],s=(c,u,l)=>{let d=hh(u,`ttheme · ${c}`,i).join(`
350
+ `),f=`${j("view")}.${FN("sha1").update(d).digest("hex").slice(0,10)}`,h=Ri(r,`${f}.colorscheme`);if(!wu(h))F(h,d);if(!o.includes(h))o.push(h);for(let m of o.splice(0,Math.max(0,o.length-UN)))sk(m,{force:!0});return bu(f,l)},a=()=>{for(let c of o.splice(0))sk(c,{force:!0})};return{slots:[],paint:(c)=>s(c.name,c,c.cursor),wear:(c,u)=>u.includes("konsole")?bu(j(c.name),c.cursor):void 0,saved:async()=>new Map,restore:()=>{return a(),`\x1B]50;${e}\x07`},stop:a}}function fk(t,e,n=(r)=>{process.stdout.write(r)}){let r=Dt(t),i=pe[r];if(!e||Pt(t)||t.TMUX||!i.paints)return;if(r==="iterm2")return GN(t,n);if(r==="konsole"&&t.TTHEME_KONSOLE_LOOK)return zN(t,t.TTHEME_KONSOLE_LOOK);let o=i.repaint??rn.map((a,c)=>c),s=rn.filter((a,c)=>o.includes(c));return{slots:o,paint:(a)=>er(a,o),wear:(a,c)=>!i.schemes?er(a):c.includes(r)?bu(j(a.name),a.cursor):void 0,saved:()=>bh(s),restore:(a)=>gu(a,s,i.hex===!0)}}var Zt=["ghostty","kitty","alacritty","wezterm","iterm2","windows-terminal","warp","konsole","terminal-app"];var DN=[{section:"tab",title:"This tab"},{section:"startup",title:"New tabs"},{section:"catalog",title:"Palettes"},{section:"own",title:"Your own"},{section:"setup",title:"Setup"},{section:"support",title:"Support"}],ua=[{name:"preview",args:[],about:"Try palettes live — focus repaints, enter edits its tone and picture and applies it, esc restores, ? lists keys",section:"tab",start:"Try every palette live — enter tunes the one you land on and applies it",shell:!0},{name:"use",args:["<palette>"],about:"Paint this tab — a unique prefix works: ttheme use ho",section:"tab",start:"Paint this tab with one — ttheme use homura",shell:!0},{name:"next",args:[],about:"Advance this tab to the next palette",section:"tab",shell:!0},{name:"default",args:["<palette>"],about:"Make a palette the one new tabs open with",section:"startup"},{name:"on",args:[],about:"Wear the default palette in new tabs again",section:"startup"},{name:"off",args:[],about:"Take the palette and picture off every tab — the terminal's own colors until `ttheme on`",section:"startup"},{name:"pin",args:["[directory|ssh:<host>]"],about:"Pick a palette for this directory, everything below it, its repository or an ssh host — cd or ssh in repaints, leaving restores",section:"tab",shell:!0},{name:"unpin",args:["[directory|ssh:<host>]"],about:"Drop a pin — this directory's, every one below it, the one above that paints it, or an ssh host's",section:"tab",shell:!0},{name:"pins",args:[],about:"Map every pinned directory as a tree in its palette's colors, every ssh host, and the pin that covers this one",section:"tab",shell:!0},{name:"config",args:[],about:"Edit settings in $EDITOR — they apply in new tabs",section:"startup",shell:!0},{name:"browse",args:[],about:"Pick palettes and markets in a live picker — shift+←/→ moves between Catalog, Installed, Markets and Errors",section:"catalog",start:"Install or drop palettes, add markets — every change applies at once on enter"},{name:"list",args:["[query]"],about:"Show the catalog, marking what is installed",section:"catalog",flags:{json:{type:"boolean",about:"Print the matches as JSON: name, group, catalog, installed"}}},{name:"add",args:["<palette...>"],about:"Install palettes from the catalog, or from a share code: ttheme add tt1:…",section:"catalog",flags:{market:{type:"string",value:"<source>",about:"Add this market first — a repository, a folder or official — and take bare palette names from it"}}},{name:"remove",args:["<palette...>"],about:"Uninstall palettes",section:"catalog"},{name:"update",args:[],about:"Refresh every market you added now — those with auto-update refresh on their own once a day",section:"catalog"},{name:"market",args:["[action]","[source]"],about:"The markets you added — add, remove and search them; init makes one of your own",actions:[["(none)","List the markets you added: palettes, auto-update and the last update"],["add <source>","Add one: a repository (alice/ttheme-pastel, #v1 pins a tag or branch), a folder, or official — asks whether it updates on its own"],["remove <market>","Drop one by its name (alice@pastel) — the palettes you installed from it keep working"],["search [query]","Repositories on GitHub with the ttheme-market topic"],["init [name]","Make a market of your own, <you>@<name>, in ~/.config/ttheme/market/<name> (or give a folder)"],["check [dir]","Check a market's folder before you push it — ttheme-market.toml, every palette, the renames and the gate; nothing is written"]],section:"catalog"},{name:"new",args:["<name>"],about:"Make a palette of your own, <you>@<market>/<name>, from blank in the palette editor — installed at once",section:"own",flags:{from:{type:"string",value:"<palette>",about:"Open the editor on this palette's colors instead of blank"},in:{type:"string",value:"<market>",about:"The local market to put it in, when you have more than one"}}},{name:"edit",args:["<palette>"],about:"Change one of your palettes in the palette editor — the contrast gate advises, never refuses",section:"own"},{name:"check",args:["<palette>"],about:"Measure a palette against the contrast gate and suggest colors that pass",section:"own",flags:{fix:{type:"boolean",about:"Write the suggested colors into your palette"}}},{name:"share",args:["<palette>"],about:"Print a share code — ttheme add <code> installs it anywhere, pictures included",section:"own",flags:{tone:{type:"string",value:"<tuned|original>",choices:["tuned","original"],about:"Share the palette as you tuned its colors, or as it was — asked when you tuned it and omit this"}}},{name:"init",args:[],about:"Install the shell layer and wire your terminal configs",section:"setup",flags:{yes:{type:"boolean",short:"y",about:"Accept every default without prompting"}}},{name:"uninstall",args:[],about:"Take ttheme out of every terminal config and delete what it wrote",section:"setup",flags:{yes:{type:"boolean",short:"y",about:"Remove without asking"}}},{name:"wire",args:["<terminal>"],about:"Wire one more terminal into this setup, after showing what it edits — the shell offers it in a terminal that paints only through the config init would have wired",section:"setup",hidden:!0},{name:"info",args:[],about:"Print what a bug report needs — version, OS, shell, terminal and the settings you changed",section:"support"},{name:"build",args:[],about:"Emit dist/ for every terminal, plus the zsh palette table — from a checkout",section:"setup",hidden:!0,flags:{only:{type:"string",multiple:!0,value:"<terminal>",choices:Zt,about:"Rebuild just this terminal — repeat it for more"}}},{name:"find",args:["<palette>"],about:"Pick a booru background for a palette — preview opens this on tab",section:"setup",hidden:!0},{name:"image",args:["<palette>","<action>","[picture]"],about:"Show one of a palette's saved backgrounds, remove one, draw one in its palette's tone or its own colors (or get the other ready before it is asked for), or pass on tuning — preview calls this",section:"setup",hidden:!0},{name:"flatten",args:["<source>","<out>","<background>","<opacity>","[canvas]","[place]","[into]"],about:"Lay a picture on a background color at an opacity, placed on a canvas when given one, for Warp, which fades the window instead, and Terminal.app, which takes it written into the file its profile points at and renamed to the out — preview calls this",section:"setup",hidden:!0},{name:"bake",args:["<source>","<out>","<canvas>","<place>"],about:"Place a picture on a transparent canvas the way sips bakes preview's tuning — preview in Warp calls this",section:"setup",hidden:!0},{name:"tone",args:["<palette>","<action>"],about:"Print a palette's colors for preview's panel, or open them in the palette editor — preview calls this",section:"setup",hidden:!0},{name:"redraw",args:[],about:"Draw the background pictures again after TTHEME_BG_BLUR changed — ttheme config and preview call this",section:"setup",hidden:!0},{name:"names",args:[],about:"Download aninames' character names when its release changed and index them — any command starts this in the background once a day",section:"setup",hidden:!0}];function ca(t){let e=Object.entries(t.flags??{}).map(([n,{value:r}])=>`[--${n}${r?` ${r}`:""}]`);return[t.name,...e,...t.args].join(" ")}function Sh(t,e=Math.max(...t.map(([n])=>n.length))){return t.map(([n,r])=>` ${n.padEnd(e)} ${r}`)}var qN=[["npx @kecan0406/ttheme init -y","Wire the terminals found here, no prompts"],["ttheme add homura madoka","Install two palettes"],["ttheme use homura","Paint this tab with one"],["ttheme list --json madoka","The madoka series as JSON"],["ttheme market add alice/ttheme-pastel","alice's market, alice@pastel — ttheme add alice@pastel/dusk"],["ttheme add dusk --market alice/ttheme-pastel","The same in one step"],["ttheme new rei --from rei","Your own rei, <you>@<market>/rei, to edit and share"]];function la(t,e=!1){let n=ua.filter((s)=>!s.hidden&&!(e&&s.section==="setup")),r=DN.filter(({section:s})=>n.some((a)=>a.section===s)),i=[...e?["ttheme alone opens preview and browse as tabs — tab and shift+tab move between them"]:[],t?"ttheme help <command> describes one command · ttheme --version prints the version":"ttheme help <command> describes one · ttheme help all lists every command with what it does","https://kecan0406.github.io/ttheme"];if(!t){let s=n.filter((c)=>c.start),a=Math.max(...r.map(({title:c})=>c.length));return["Usage: ttheme <command>","",At.description,"","Start here",...Sh(s.map((c)=>[ca(c),c.start])),"",...r.map(({section:c,title:u})=>`${u.padEnd(a)} ${n.filter((l)=>l.section===c).map((l)=>l.name).join(" · ")}`),"",...i].join(`
351
+ `)}let o=Math.max(...n.map((s)=>ca(s).length));return["Usage: ttheme <command>","",At.description,...r.flatMap(({section:s,title:a})=>["",a,...Sh(n.filter((c)=>c.section===s).map((c)=>[ca(c),c.about]),o)]),"","Examples",...Sh(qN),"",...i].join(`
352
+ `)}import{readFileSync as YN}from"node:fs";import{join as JN}from"node:path";var Eh="# ttheme begin",Mh="# ttheme end",Do=/# ttheme begin\n[\s\S]*?# ttheme end\n?/;function _r(t,e){let n=`${Eh}
353
353
  ${e}
354
- ${Kd}
355
- `;if(Rs.test(t))return t.replace(Rs,n);if(t==="")return n;return`${t.replace(/\n*$/,`
354
+ ${Mh}
355
+ `;if(Do.test(t))return t.replace(Do,n);if(t==="")return n;return`${t.replace(/\n*$/,`
356
356
  `)}
357
- ${n}`}function Rr(t){let e=t.replace(/\n?# ttheme begin\n[\s\S]*?# ttheme end(?=\n|$)/,"");if(e===t)return t;return e.trim()===""?"":e.replace(/\n*$/,`
358
- `)}function Nr(t,e){let n=t.replace(Rs,"");return new RegExp(String.raw`^[ \t]*${e}(?:[ \t]*=|[ \t]+\S)`,"m").test(n)}function d$(t){return`source ${t}/ttheme.zsh`}var yN="# ttheme settings — uncomment a line to change it; exported variables win over this file",Ns={TTHEME_TAB_PALETTE:{doc:"# new tabs: off keeps the configured terminal theme, seq rotates through the palettes (default off)",default:"off"},TTHEME_ANNOUNCE:{doc:'# the palette notice under "Last login:": 1 shows it, 0 silences it (default 1)',default:"1"},TTHEME_FX:{doc:"# search hint animation: typewriter, decode or glitch (default typewriter)",default:"typewriter"},TTHEME_SORT:{doc:"# series and palettes in ttheme and preview: abc sorts them by name, series keeps the order they were added (default abc)",default:"abc"},TTHEME_MOUSE:{doc:"# clicks, the wheel and drags in preview, browse, the palette editor and find: on, or off to leave the mouse to the terminal, so a drag selects text again without a modifier (default on)",default:"on"},TTHEME_BG_BLUR:{doc:"# soften the background pictures behind the text: a blur radius in screen pixels, 0 keeps them sharp — changing it draws every picture again (default 0)",default:"0"},TTHEME_BG_COLORS:{doc:"# the colors new background pictures are drawn in: tone tints a picture in one color of its palette, original keeps its own — preview switches each picture later (default tone)",default:"tone"},TTHEME_WARP_FAST:{doc:"# Warp tab switches: on keeps Warp rereading its settings while it is in front with tabs of different palettes, so the tab you switch to shows its palette in about 0.2 s instead of 0.6 s — about 8% CPU meanwhile; off leaves it to Warp (default on)",default:"on"},TTHEME_NAMES:{doc:"# character names in every language for searching palettes and find's search box, from aninames' weekly release: on downloads them (about 7 MB) and checks once a day in the background; off leaves them as they are (default on)",default:"on"},TTHEME_MARKET_LOOKUP:{doc:"# the Markets tab in browse: on looks GitHub up by itself — the markets carrying the ttheme-market topic when the tab opens or you type, and the palettes of a repository you type or move onto; off waits for space (default on)",default:"on"},TTHEME_FIND_RATING:{doc:"# the ratings find lists, any of safe, questionable and explicit, each booru read in its own rating vocabulary (default safe)",default:"safe"},TTHEME_FIND_BLOCK:{doc:'# the posts find drops by tag: nudity, underwear, both, or none to keep them all (default "nudity underwear")',default:"nudity underwear"},TTHEME_FIND_POSTS:{doc:"# what find lists first: all is every post of the character, cutouts are the transparent ones (default all)",default:"all"},TTHEME_FIND_SOLO:{doc:"# on keeps the posts tagged solo, the character alone, by danbooru or zerochan; off lists every post (default on)",default:"on"},TTHEME_FIND_CUTOUTS:{doc:'# the tags find calls a transparent cutout, per site as key=tag,tag pairs — e.g. "konachan=transparent,vector yande=transparent_png" (default the built-in tags)',default:""},TTHEME_FIND_ORDER:{doc:"# the order find lists posts in: fit ranks each page by how well it makes a backdrop, newest or score (default fit)",default:"fit"},TTHEME_FIND_SETS:{doc:"# runs of the same picture at the same size from one uploader: fold shows them as one tile, show lists each (default fold)",default:"fold"},TTHEME_FIND_REMOVE_BG:{doc:"# an opaque picture tried on in find: on cuts the character out with macOS Vision, off leaves it as it is (default on)",default:"on"},TTHEME_FIND_MIN_SCORE:{doc:"# the lowest score find lists: off, or a number such as 5, 10, 25, 50 or 100 — danbooru, konachan and yande.re filter by it, zerochan keeps no score (default off)",default:"off"},TTHEME_FIND_MIN_SIZE:{doc:"# the shortest side a picture find lists must reach, in pixels: off, or a number such as 720, 1080, 1440, 1800 or 2560 (default off)",default:"off"},TTHEME_FIND_SITES:{doc:"# the sites find mixes in its all tab: any of danbooru, konachan, yande.re and zerochan (default all four)",default:"danbooru konachan yande.re zerochan"},TTHEME_FIND_HIDE:{doc:"# the kinds of picture find leaves out by tag: comic, monochrome, sketch, chibi, or none to keep them all (default none)",default:"none"},TTHEME_FIND_HIDE_TAGS:{doc:'# more tags find leaves out, spaced — e.g. "cosplay multiple_girls" (default none)',default:""},TTHEME_FIND_PNG:{doc:"# on lists PNG originals only — a zerochan post counts only where danbooru holds the same file (default off)",default:"off"},TTHEME_FIND_HOSTS:{doc:'# send a find site somewhere else, as key=https://host pairs — e.g. "danbooru=https://danbooru.donmai.us" (default none)',default:""}};function Do(t){return Ns[t]?.default}function zd(t,e){let n=`: \${${t}:=${e}}`;return Do(t)===e?`# ${n}`:n}function h$(t){return new RegExp(String.raw`^#? ?: \$\{${t}[^\n]*$`,"m")}function vN(t,e){if(h$(e).test(t))return t;let n=Ns[e];return`${t.replace(/\n*$/,`
357
+ ${n}`}function Br(t){let e=t.replace(/\n?# ttheme begin\n[\s\S]*?# ttheme end(?=\n|$)/,"");if(e===t)return t;return e.trim()===""?"":e.replace(/\n*$/,`
358
+ `)}function Gr(t,e){let n=t.replace(Do,"");return new RegExp(String.raw`^[ \t]*${e}(?:[ \t]*=|[ \t]+\S)`,"m").test(n)}function hk(t){return`source ${t}/ttheme.zsh`}var VN="# ttheme settings — uncomment a line to change it; exported variables win over this file",qo={TTHEME_TAB_PALETTE:{doc:"# new tabs: off keeps the configured terminal theme, seq rotates through the palettes (default off)",default:"off"},TTHEME_ANNOUNCE:{doc:'# the palette notice under "Last login:": 1 shows it, 0 silences it (default 1)',default:"1"},TTHEME_FX:{doc:"# search hint animation: typewriter, decode or glitch (default typewriter)",default:"typewriter"},TTHEME_SORT:{doc:"# series and palettes in ttheme and preview: abc sorts them by name, series keeps the order they were added (default abc)",default:"abc"},TTHEME_MOUSE:{doc:"# clicks, the wheel and drags in preview, browse, the palette editor and find: on, or off to leave the mouse to the terminal, so a drag selects text again without a modifier (default on)",default:"on"},TTHEME_BG_BLUR:{doc:"# soften the background pictures behind the text: a blur radius in screen pixels, 0 keeps them sharp — changing it draws every picture again (default 0)",default:"0"},TTHEME_BG_COLORS:{doc:"# the colors new background pictures are drawn in: tone tints a picture in one color of its palette, original keeps its own — preview switches each picture later (default tone)",default:"tone"},TTHEME_WARP_FAST:{doc:"# Warp tab switches: on keeps Warp rereading its settings while it is in front with tabs of different palettes, so the tab you switch to shows its palette in about 0.2 s instead of 0.6 s — about 8% CPU meanwhile; off leaves it to Warp (default on)",default:"on"},TTHEME_NAMES:{doc:"# character names in every language for searching palettes and find's search box, from aninames' weekly release: on downloads them (about 7 MB) and checks once a day in the background; off leaves them as they are (default on)",default:"on"},TTHEME_MARKET_LOOKUP:{doc:"# the Markets tab in browse: on looks GitHub up by itself — the markets carrying the ttheme-market topic when the tab opens or you type, and the palettes of a repository you type or move onto; off waits for space (default on)",default:"on"},TTHEME_FIND_RATING:{doc:"# the ratings find lists, any of safe, questionable and explicit, each booru read in its own rating vocabulary (default safe)",default:"safe"},TTHEME_FIND_BLOCK:{doc:'# the posts find drops by tag: nudity, underwear, both, or none to keep them all (default "nudity underwear")',default:"nudity underwear"},TTHEME_FIND_POSTS:{doc:"# what find lists first: all is every post of the character, cutouts are the transparent ones (default all)",default:"all"},TTHEME_FIND_SOLO:{doc:"# on keeps the posts tagged solo, the character alone, by danbooru or zerochan; off lists every post (default on)",default:"on"},TTHEME_FIND_CUTOUTS:{doc:'# the tags find calls a transparent cutout, per site as key=tag,tag pairs — e.g. "konachan=transparent,vector yande=transparent_png" (default the built-in tags)',default:""},TTHEME_FIND_ORDER:{doc:"# the order find lists posts in: fit ranks each page by how well it makes a backdrop, newest or score (default fit)",default:"fit"},TTHEME_FIND_SETS:{doc:"# runs of the same picture at the same size from one uploader: fold shows them as one tile, show lists each (default fold)",default:"fold"},TTHEME_FIND_REMOVE_BG:{doc:"# an opaque picture tried on in find: on cuts the character out with macOS Vision, off leaves it as it is (default on)",default:"on"},TTHEME_FIND_MIN_SCORE:{doc:"# the lowest score find lists: off, or a number such as 5, 10, 25, 50 or 100 — danbooru, konachan and yande.re filter by it, zerochan keeps no score (default off)",default:"off"},TTHEME_FIND_MIN_SIZE:{doc:"# the shortest side a picture find lists must reach, in pixels: off, or a number such as 720, 1080, 1440, 1800 or 2560 (default off)",default:"off"},TTHEME_FIND_SITES:{doc:"# the sites find mixes in its all tab: any of danbooru, konachan, yande.re and zerochan (default all four)",default:"danbooru konachan yande.re zerochan"},TTHEME_FIND_HIDE:{doc:"# the kinds of picture find leaves out by tag: comic, monochrome, sketch, chibi, or none to keep them all (default none)",default:"none"},TTHEME_FIND_HIDE_TAGS:{doc:'# more tags find leaves out, spaced — e.g. "cosplay multiple_girls" (default none)',default:""},TTHEME_FIND_PNG:{doc:"# on lists PNG originals only — a zerochan post counts only where danbooru holds the same file (default off)",default:"off"},TTHEME_FIND_HOSTS:{doc:'# send a find site somewhere else, as key=https://host pairs — e.g. "danbooru=https://danbooru.donmai.us" (default none)',default:""}};function da(t){return qo[t]?.default}function xh(t,e){let n=`: \${${t}:=${e}}`;return da(t)===e?`# ${n}`:n}function mk(t){return new RegExp(String.raw`^#? ?: \$\{${t}[^\n]*$`,"m")}function ZN(t,e){if(mk(e).test(t))return t;let n=qo[e];return`${t.replace(/\n*$/,`
359
359
  `)}
360
360
  ${n.doc}
361
- ${zd(e,n.default)}
362
- `}var tu=Object.keys(Ns),EN=8;function eu(t,e){let n="";try{n=$N(kN(t,"ttheme","config.zsh"),"utf8")}catch{}return(new RegExp(String.raw`^: \$\{${e}:=([^}\n]*)\}`,"m").exec(n)?.[1]??Ns[e].default).replace(/^(["'])(.*)\1$/,"$2")}function Tr(t){let e=Number(eu(t,"TTHEME_BG_BLUR"));return Number.isFinite(e)?Math.min(EN,Math.max(0,e)):0}function nu(t){return eu(t,"TTHEME_BG_COLORS")==="original"?"original":"tone"}function Dd(){let t=Object.entries(Ns).map(([e,n])=>`${n.doc}
363
- ${zd(e,n.default)}`);return`${[yN,...t].join(`
361
+ ${xh(e,n.default)}
362
+ `}var yu=Object.keys(qo),QN=8;function vu(t,e){let n="";try{n=YN(JN(t,"ttheme","config.zsh"),"utf8")}catch{}return(new RegExp(String.raw`^: \$\{${e}:=([^}\n]*)\}`,"m").exec(n)?.[1]??qo[e].default).replace(/^(["'])(.*)\1$/,"$2")}function Ur(t){let e=Number(vu(t,"TTHEME_BG_BLUR"));return Number.isFinite(e)?Math.min(QN,Math.max(0,e)):0}function Su(t){return vu(t,"TTHEME_BG_COLORS")==="original"?"original":"tone"}function Oh(){let t=Object.entries(qo).map(([e,n])=>`${n.doc}
363
+ ${xh(e,n.default)}`);return`${[VN,...t].join(`
364
364
 
365
365
  `)}
366
- `}function ru(t,e,n){let r=zd(e,n),i=h$(e);if(i.test(t))return t.replace(i,r);return`${t.replace(/\n*$/,`
366
+ `}function Eu(t,e,n){let r=xh(e,n),i=mk(e);if(i.test(t))return t.replace(i,r);return`${t.replace(/\n*$/,`
367
367
  `)}
368
368
  ${r}
369
- `}function m$(t){if(t==="")return Dd();return Object.keys(Ns).reduce(vN,t)}var iu=/["$`\\]/;function SN(t){return t.replace(/_\([^)]*\)$/,"").replaceAll("_"," ")}function qd(t,e,n=[],r={}){for(let l of t)for(let f of[l.name,l.group,l.native??"",...l.nativeNames??[],l.ansiSource])if(iu.test(f))throw Error(`${l.name}: "${f}" contains a character that breaks zsh quoting`);let i=Math.max(0,...t.map((l)=>l.name.length)),s=(l,f)=>` ${l.name.padEnd(i)} "${f}"`,o=(l)=>l.map((f)=>f.name).join(" "),a=Mt(t),c=(l)=>`'${l.replaceAll("'","'\\''")}'`,u=Ko.filter((l)=>l.section!=="setup"&&!l.hidden);return["# Generated by `mise run build` — do not edit.","# Source of truth: themes/*.toml in the ttheme repo.","",`typeset -g TTHEME_VERSION=${It.version}`,"",'# the palette new tabs open with, which the iTerm2 "ttheme · default" profile wears',`typeset -g TTHEME_STARTUP=${e??""}`,"","# the terminals ttheme is wired into: a picture change reaches every one of them, from whichever runs the shell",`typeset -ga TTHEME_TERMINALS=(${n.join(" ")})`,...Object.keys(r).length>0?["","# what a wired terminal's adapter needs to know of it (src/terminals/)",...Object.entries(r).map(([l,f])=>`typeset -g ${l}=${c(f)}`)]:[],"","# the commands the shell layer knows (src/verbs.ts): help, completion and argument checks read them",`typeset -ga TTHEME_VERBS=(${u.map((l)=>l.name).join(" ")})`,`typeset -ga TTHEME_TAB_VERBS=(${u.filter((l)=>l.section==="tab").map((l)=>l.name).join(" ")})`,`typeset -ga TTHEME_SHELL_VERBS=(${u.filter((l)=>l.shell).map((l)=>l.name).join(" ")})`,"typeset -gA TTHEME_VERB_ARGS=(",...u.map((l)=>` ${l.name} ${c(l.args.join(" "))}`),")","typeset -gA TTHEME_VERB_ABOUT=(",...u.map((l)=>` ${l.name} ${c(l.about)}`),")",`typeset -g TTHEME_HELP=${c(zo(!1,!0))}`,`typeset -g TTHEME_HELP_ALL=${c(zo(!0,!0))}`,"","# the screens the bare ttheme switches between (src/hub.ts): the exit status of a screen run by the CLI says where it went",`typeset -ga TTHEME_HUB_TABS=(${Gn.map((l)=>l.name).join(" ")})`,`typeset -ga TTHEME_HUB_TITLES=(${Gn.map((l)=>l.title).join(" ")})`,`typeset -gi TTHEME_HUB_CLOSED=${Hc} TTHEME_HUB_SWITCH=${Fc}`,"","# the settings config.zsh holds, handed to the CLI on every call",`typeset -ga TTHEME_SETTINGS=(${tu.join(" ")})`,"","# seed for `ttheme config` when no config.zsh exists yet",`typeset -g TTHEME_CONFIG_TEMPLATE='${Dd().trimEnd().replaceAll("'","'\\''")}'`,"","typeset -gA TTHEME_PALETTE=(",...t.map((l)=>s(l,[l.background,l.foreground,l.cursor,l.selection,...l.ansi].join(" "))),")","","# series order: new tabs cycle through it and TTHEME_SORT=series lists it — the default role stays applyable but unlisted",`typeset -ga TTHEME_ORDER=(${o(a)})`,"","# the same palettes by series name, then palette name: TTHEME_SORT=abc lists them this way",`typeset -ga TTHEME_ABC=(${o(ui(a))})`,"","typeset -gA TTHEME_GROUP=(",...t.map((l)=>s(l,l.group)),")","","# the catalog a market palette sits in — the folder under the market's palettes/, one level below the market in every list","typeset -gA TTHEME_CATALOG=(",...t.filter((l)=>l.catalog).map((l)=>s(l,l.catalog??"")),")","","# original-language title, rendered dim next to the group","typeset -gA TTHEME_NATIVE=(",...t.filter((l)=>l.native).map((l)=>s(l,l.native??"")),")","","# the character's names in its original language, |-separated, and as its booru tag spells it: preview searches both","typeset -gA TTHEME_NATIVE_NAMES=(",...t.filter((l)=>l.nativeNames).map((l)=>s(l,(l.nativeNames??[]).join("|"))),")","typeset -gA TTHEME_CHARACTER=(",...t.filter((l)=>l.booru&&!iu.test(l.booru)).map((l)=>s(l,SN(l.booru??""))),")","","# the example scenes preview draws beside the list (src/scenes.ts), each line as «role»text runs",`typeset -ga TTHEME_SCENES=(${ie.map((l)=>l.name).join(" ")})`,...ie.flatMap((l,f)=>[`typeset -ga TTHEME_SCENE_${f+1}=(`,...l.lines.map((d)=>` ${c(d)}`),")"]),"","# each booru's ANSI color, which marks a link to one of its posts",`typeset -gA TTHEME_SITE_ANSI=(${Y.map((l)=>`${l.name} ${l.ansi}`).join(" ")})`,"","# the terminals that open OSC 8 links (src/terminal.ts)",`typeset -ga TTHEME_LINKS=(${Object.entries(de).flatMap(([l,f])=>f.links?[l]:[]).join(" ")})`,"","# the six colors a list row shows: foreground, the signature, then red and green","typeset -gA TTHEME_SWATCH=(",...t.map((l)=>s(l,hc(l).join(" "))),")","","# where each palette's 16 ANSI colors came from","typeset -gA TTHEME_SRC=(",...t.map((l)=>s(l,l.ansiSource)),")",""].join(`
370
- `)}function p$(t){let e=Object.entries(t).flatMap(([r,i])=>{let s=i.filter((o)=>!iu.test(o)&&!o.includes("|"));return s.length>0&&!iu.test(r)?[[r,s.join("|")]]:[]}),n=Math.max(0,...e.map(([r])=>r.length));return["# the character's other names in every language, |-separated, from the aninames index in the cache: preview reads this when it opens and searches them too","typeset -gA TTHEME_ALIASES=(",...e.map(([r,i])=>` ${r.padEnd(n)} "${i}"`),")",""].join(`
371
- `)}var Yd={id:"shell",emitShared(t){return[{path:"shell/palettes.zsh",content:qd(t.map(mn))}]}};import{execFileSync as MN}from"node:child_process";import{existsSync as g$,readdirSync as ON,readFileSync as xN}from"node:fs";import{join as b$}from"node:path";function st(t){return g$(t)?xN(t,"utf8"):""}function Tt(t,e){return t.startsWith(`${e}/`)?`~${t.slice(e.length)}`:t}function su(t){return[...new Set(t.split(`
372
- `).map((e)=>e.split(/[ =]/)[0]))].join(", ")}function wn(t,e){let n=st(t),r=e(n);return r===n?[]:[{file:t,content:r}]}function qo(t){return process.env.XDG_DATA_HOME??b$(t,".local","share")}function Ts(t){return g$(t)?ON(t).flatMap((e)=>e.startsWith(H(""))?[b$(t,e)]:[]):[]}function Jd(t,e){if(!t.shelf)return[];let n=`${[t.id,t.shelf.from].filter(Boolean).join("/")}/`;return(t.emitter.emit?.(e)??[]).flatMap((r)=>{let i=r.path.startsWith(n)?r.path.slice(n.length):"";return i!==""&&!i.includes("/")?[{file:i,content:r.content}]:[]})}function Ze(){return{platform:process.platform,env:process.env,run:(t,e)=>{try{return MN(t,[...e],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5000}).trim()}catch{return}}}}import{existsSync as N$}from"node:fs";import{join as au}from"node:path";var IN=["black","red","green","yellow","blue","magenta","cyan","white"];function w$(t,e){return[t,...IN.map((n,r)=>`${n} = '${e[r]}'`),""].join(`
373
- `)}var Vd={id:"alacritty",limits:"no runtime color API (OSC only)",emit(t){let e=[...Or(t),"","[colors.primary]",`background = '${t.background}'`,`foreground = '${t.foreground}'`,"","[colors.cursor]",`cursor = '${t.cursor}'`,`text = '${t.background}'`,"","[colors.selection]",`background = '${t.selectionBackground}'`,`text = '${t.foreground}'`,"",w$("[colors.normal]",t.ansi.slice(0,8)),w$("[colors.bright]",t.ansi.slice(8,16))].join(`
374
- `);return[{path:`alacritty/themes/${H(t.name)}.toml`,content:e}]}};var Zd={id:"ghostty",emit(t){let e=[...Or(t),`background = ${t.background}`,`foreground = ${t.foreground}`,`cursor-color = ${t.cursor}`,`selection-background = ${t.selectionBackground}`,`selection-foreground = ${t.foreground}`,...t.ansi.map((n,r)=>`palette = ${r}=${n}`),"","macos-icon = custom-style",`macos-icon-ghost-color = ${t.ghostty.iconGhost}`,`macos-icon-screen-color = ${t.ghostty.iconScreen.join(",")}`,"macos-icon-frame = chrome",""].join(`
375
- `);return[{path:`ghostty/themes/${H(t.name)}`,content:e}]}};function Ar(t){let[e,n,r]=rt(t);return{"Alpha Component":1,"Blue Component":r/255,"Color Space":"P3","Green Component":n/255,"Red Component":e/255}}function k$(t){return{...Object.fromEntries(t.ansi.map((e,n)=>[`Ansi ${n} Color`,Ar(e)])),"Background Color":Ar(t.background),"Bold Color":Ar(t.foreground),"Cursor Color":Ar(t.cursor),"Cursor Text Color":Ar(t.background),"Foreground Color":Ar(t.foreground),"Selected Text Color":Ar(t.foreground),"Selection Color":Ar(t.selectionBackground)}}function $$(t){return t?{"Background Image Location":t.image,"Background Image Mode":t.cover?2:3,Blend:t.opacity}:{"Background Image Location":""}}function y$(t,e,n,r,i=!1){let s=(c,u)=>({Name:`ttheme · ${u}`,Guid:H(u),...r?{"Dynamic Profile Parent GUID":r}:{},"Use Separate Colors for Light and Dark Mode":!1,...$$(e.get(c.name)),...k$(c)}),o={Name:"ttheme · default",Guid:H("default"),"Dynamic Profile Parent GUID":r,...$$(void 0)},a=[...n?[s(n,"default")]:i&&r?[o]:[],...t.map((c)=>s(c,c.name))];return`${JSON.stringify({Profiles:a},null,2)}
376
- `}function RN(t,e){return[` <key>${t}</key>`,"\t<dict>",...Object.entries(e).flatMap(([n,r])=>[` <key>${n}</key>`,typeof r==="string"?` <string>${r}</string>`:` <real>${r}</real>`]),"\t</dict>"].join(`
377
- `)}var Qd={id:"iterm2",limits:"colors are Display P3, the space iTerm2 reads OSC colors in",emit(t){let e=['<?xml version="1.0" encoding="UTF-8"?>','<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">','<plist version="1.0">',"<dict>",...Object.entries(k$(t)).map(([n,r])=>RN(n,r)),"</dict>","</plist>",""].join(`
378
- `);return[{path:`iterm2/${H(t.name)}.itermcolors`,content:e}]}};var Xd={id:"kitty",emit(t){let e=[...Or(t),`background ${t.background}`,`foreground ${t.foreground}`,`cursor ${t.cursor}`,`cursor_text_color ${t.background}`,`selection_background ${t.selectionBackground}`,`selection_foreground ${t.foreground}`,...t.ansi.map((n,r)=>`color${r} ${n}`),""].join(`
379
- `);return[{path:`kitty/themes/${H(t.name)}.conf`,content:e}]}};function v$(t){return["# Generated by ttheme — rewritten on every add, remove and default; do not edit.","import os","",`THEMES = ${JSON.stringify(t.themes)}`,`BACKGROUNDS = ${JSON.stringify(t.backgrounds)}`,"PLACES = {"," 'top-left': 'top-left', 'top-center': 'top', 'top-right': 'top-right',"," 'center-left': 'left', 'center': 'center', 'center-center': 'center', 'center-right': 'right',"," 'bottom-left': 'bottom-left', 'bottom-center': 'bottom', 'bottom-right': 'bottom-right',","}","","shown = {}","faded = {}","worn = {}","","","def locate(path):"," if path.startswith('~/'):"," return os.path.expanduser(path)"," return path if os.path.isabs(path) else os.path.join(BACKGROUNDS, path)","","","def read(path, into):"," try:"," with open(path, encoding='utf-8') as f:"," lines = f.read().splitlines()"," except OSError:"," return False"," for line in lines:"," key, sep, value = line.partition('=')"," key, value = key.strip(), value.strip()"," if not sep or not key or key.startswith('#'):"," continue"," if key == 'config-file':"," read(locate(value.lstrip('?')), into)"," else:"," into[key] = value"," return True","","","def logo(palette):"," c = {}"," if not palette or not read(os.path.join(BACKGROUNDS, palette.replace('@', '--', 1).replace('/', '--', 1) + '.conf'), c):"," return None"," image = c.get('background-image', '')"," try:"," opacity = min(float(c.get('background-image-opacity', '1')), 1.0)"," except ValueError:"," opacity = 1.0"," if not image or opacity <= 0:"," return None"," return locate(image), PLACES.get(c.get('background-image-position', 'center'), 'center'), opacity","","","def fade(path, opacity):"," key = f'{path}#{opacity}'"," if key not in faded:"," from kitty.fast_data_types import load_png_data, png_from_32bit_rgba_data"," with open(path, 'rb') as f:"," rgba, width, height = load_png_data(f.read())"," data = bytearray(rgba)"," data[3::4] = data[3::4].translate(bytes(round(a * opacity) for a in range(256)))"," if len(faded) > 8:"," faded.clear()"," faded[key] = png_from_32bit_rgba_data(bytes(data), width, height)"," return key, faded[key]","","","def show(window):"," want = logo(window.user_vars.get('ttheme_shown') or '')"," if window.id in shown and shown[window.id] == want:"," return"," shown[window.id] = want"," try:"," if want is None:"," window.set_logo('')"," elif want[2] < 1:"," key, png = fade(want[0], want[2])"," window.set_logo(key, want[1], 1, png)"," else:"," window.set_logo(want[0], want[1], 1)"," except Exception:"," shown.pop(window.id, None)","","","def theme(palette):"," path = os.path.join(THEMES, 'ttheme-' + palette.replace('@', '--', 1).replace('/', '--', 1) + '.conf')"," if not palette or not os.path.exists(path):"," return None"," from kitty.colors import parse_colors"," return parse_colors([path])","","","def wear(palette):"," colors = theme(palette) if worn.get('startup') != palette else None"," if colors is None:"," return"," from kitty.colors import patch_colors"," patch_colors(colors[0], colors[1], True, ())"," worn['startup'] = palette","","","def rewear(boss):"," from kitty.colors import patch_colors"," for window in tuple(boss.all_windows):"," colors = theme(window.user_vars.get('ttheme_worn') or '')"," if colors is not None:"," patch_colors(colors[0], colors[1], False, (window,))","","","def on_load(boss, data):"," if getattr(boss, 'ttheme_rewears', False):"," return"," load = boss.load_config_file",""," def reload(*args, **kwargs):"," load(*args, **kwargs)"," worn.pop('startup', None)"," rewear(boss)",""," boss.load_config_file = reload"," boss.ttheme_rewears = True","","","def on_set_user_var(boss, window, data):"," if data['key'] == 'ttheme_shown':"," show(window)"," elif data['key'] == 'ttheme_startup':"," wear(data['value'] or '')","","","def on_focus_change(boss, window, data):"," if data['focused']:"," show(window)","","","def on_close(boss, window, data):"," shown.pop(window.id, None)",""].join(`
380
- `)}function NN(t){let[e]=t;if(!e)throw Error("manifest needs at least one theme");return{...mc(),palettes:t.map(mn)}}var th={id:"meta",emitShared(t){return[{path:"manifest.json",content:`${JSON.stringify(NN(t),null,2)}
381
- `}]}};var eh={id:"terminal-app",limits:"profiles go into its own settings at init, so the archive carries none"};import{createHash as TN}from"node:crypto";var AN=["black","red","green","yellow","blue","magenta","cyan","white"];function E$(t,e){return[` ${t}:`,...AN.map((n,r)=>` ${n}: "${e[r]}"`)]}function PN(t,e,n){let r=TN("sha1");for(let i of e)r.update(i);return`${H(t)}.${r.digest("hex").slice(0,8)}.${n}`}function S$(t,e,n){let r=2166136261;for(let i of Buffer.from(`${e}
382
- ${n.toLowerCase()}`,"utf8"))r=Math.imul(r^i,16777619)>>>0;return`${H(t)}.${r.toString(16).padStart(8,"0")}.png`}function Yo(t,e){return e?PN(t,[e.image,String(M$(e))],"yaml"):`${H(t)}.yaml`}function M$(t){return Math.max(0,Math.min(100,Math.round(t.opacity*100)))}function Jo(t,e){return[`name: "${t.name}"`,`background: "${t.background}"`,`foreground: "${t.foreground}"`,`accent: "${t.cursor}"`,`cursor: "${t.cursor}"`,`details: ${vt(t.background)<0.18?"darker":"lighter"}`,...e?["background_image:",` path: "${e.image}"`,` opacity: ${M$(e)}`]:[],"terminal_colors:",...E$("normal",t.ansi.slice(0,8)),...E$("bright",t.ansi.slice(8,16)),""].join(`
383
- `)}var nh={id:"warp",limits:"no selection color, and Warp paints one theme app-wide",emit(t){return[{path:`warp/themes/${Yo(t.name)}`,content:Jo(t)}]}};var O$=(t)=>`[${t.map((e)=>`"${e}"`).join(", ")}]`,rh={id:"wezterm",limits:"OSC repaints per pane, pictures show per window",emit(t){let e=["[metadata]",`name = "${H(t.name)}"`,`origin_url = "${t.ansiSource}"`,"","[colors]",`foreground = "${t.foreground}"`,`background = "${t.background}"`,`cursor_bg = "${t.cursor}"`,`cursor_border = "${t.cursor}"`,`cursor_fg = "${t.background}"`,`selection_bg = "${t.selectionBackground}"`,`selection_fg = "${t.foreground}"`,"",`ansi = ${O$(t.ansi.slice(0,8))}`,`brights = ${O$(t.ansi.slice(8,16))}`,""].join(`
384
- `);return[{path:`wezterm/colors/${H(t.name)}.toml`,content:e}]}},As=(t)=>JSON.stringify(t);function x$(t){return["-- Generated by ttheme — rewritten on every add, remove and default; do not edit.","local wezterm = require 'wezterm'","",`local MODULE = ${As(t.path)}`,`local COLORS = ${As(t.colors)}`,`local BACKGROUNDS = ${As(t.backgrounds)}`,`local STARTUP = ${t.startup?As(H(t.startup)):"nil"}`,"local PALETTES = {",...t.palettes.map((e)=>` [${As(e.name)}] = ${As(e.background)},`),"}","","local X = { left = 'Left', center = 'Center', right = 'Right' }","local Y = { top = 'Top', center = 'Middle', bottom = 'Bottom' }","local SIZE = { cover = 'Cover', contain = 'Contain', stretch = '100%' }","","local function locate(path)"," if path:sub(1, 2) == '~/' then"," return os.getenv('HOME') .. path:sub(2)"," elseif path:sub(1, 1) == '/' or path:match('^%a:[/\\\\]') then"," return path"," end"," return BACKGROUNDS .. '/' .. path","end","","local function read(path, into)"," local f = io.open(path, 'r')"," if not f then"," return false"," end"," for line in f:lines() do"," local key, value = line:match('^%s*([%w%-]+)%s*=%s*(.-)%s*$')"," if key == 'config-file' then"," read(locate((value:gsub('^%?', ''))), into)"," elseif key then"," into[key] = value"," end"," end"," f:close()"," return true","end","","local function layers(palette)"," local color = PALETTES[palette]"," local c = {}"," if not color or not read(BACKGROUNDS .. '/' .. ((palette:gsub('@', '--', 1)):gsub('/', '--', 1)) .. '.conf', c) then"," return nil, 'none'"," end"," local image = c['background-image'] or ''"," local opacity = tonumber(c['background-image-opacity'] or '1') or 1"," if image == '' or opacity <= 0 then"," return nil, 'none'"," end"," local fit = c['background-image-fit'] or 'contain'"," local position = c['background-image-position'] or 'center'"," local y, x = position:match('^(%a+)-(%a+)$')"," local rep = c['background-image-repeat'] == 'true' and 'Repeat' or 'NoRepeat'"," return {"," { source = { Color = color }, width = '100%', height = '100%' },"," {"," source = { File = locate(image) },"," opacity = opacity,"," width = SIZE[fit],"," height = SIZE[fit],"," horizontal_align = X[x or 'center'],"," vertical_align = Y[y or 'center'],"," repeat_x = rep,"," repeat_y = rep,"," },"," }, table.concat({ color, image, opacity, fit, position, rep }, '|')","end","","local function framed(window, view)"," local color, image, opacity, W, H, w, h, x, y, at ="," view:match('^([^|]*)|([^|]*)|([^|]*)|(%d+)|(%d+)|(%-?%d+)|(%-?%d+)|(%-?%d+)|(%-?%d+)|(%d)$')"," if not image or image == '' or tonumber(W) == 0 or tonumber(H) == 0 then"," return nil, 'none'"," end"," local d = window:get_dimensions()"," local k = math.max(d.pixel_width / W, d.pixel_height / H)"," local n = tonumber(at) - 1"," local ax, ay = n % 3, n // 3"," local px = function(n) return string.format('%.2fpx', n) end"," return {"," { source = { Color = color }, width = '100%', height = '100%' },"," {"," source = { File = image },"," opacity = tonumber(opacity) or 1,"," width = px(w * k),"," height = px(h * k),"," horizontal_align = 'Left',"," vertical_align = 'Top',"," horizontal_offset = px(ax * (d.pixel_width - W * k) / 2 + x * k),"," vertical_offset = px(ay * (d.pixel_height - H * k) / 2 + y * k),"," repeat_x = 'NoRepeat',"," repeat_y = 'NoRepeat',"," },"," }, table.concat({ view, d.pixel_width, d.pixel_height }, '|')","end","","local shown = {}","","local function show(window, pane)"," local vars = pane:get_user_vars()"," local id = window:window_id()"," local background, key"," if vars.ttheme_view and vars.ttheme_view ~= '' then"," background, key = framed(window, vars.ttheme_view)"," elseif vars.ttheme_shown and vars.ttheme_shown ~= '' then"," background, key = layers(vars.ttheme_shown)"," elseif shown[id] == nil then"," return"," end"," if shown[id] == key then"," return"," end"," shown[id] = key"," local overrides = window:get_config_overrides() or {}"," overrides.background = background"," window:set_config_overrides(overrides)","end","","wezterm.on('user-var-changed', function(window, pane, name)"," if name == 'ttheme_shown' or name == 'ttheme_view' then"," show(window, pane)"," end","end)","wezterm.on('update-status', show)","","return function(config)"," local dirs = config.color_scheme_dirs or {}"," table.insert(dirs, COLORS)"," config.color_scheme_dirs = dirs"," if STARTUP then"," config.color_scheme = STARTUP"," end"," wezterm.add_to_config_reload_watch_list(MODULE)","end",""].join(`
385
- `)}var I$=["black","red","green","yellow","blue","purple","cyan","white"];function R$(t){return{name:H(t.name),background:t.background,foreground:t.foreground,cursorColor:t.cursor,selectionBackground:t.selectionBackground,...Object.fromEntries(I$.map((e,n)=>[e,t.ansi[n]])),...Object.fromEntries(I$.map((e,n)=>[`bright${e[0]?.toUpperCase()}${e.slice(1)}`,t.ansi[n+8]]))}}function ih(t,e,n){let r={...e&&n?{profiles:[{updates:e,colorScheme:H(n)}]}:{},schemes:t.map(R$)};return`${JSON.stringify(r,null,2)}
386
- `}var sh={id:"windows-terminal",limits:"a picture belongs to a profile, which a pane cannot change, so none; OSC repaints per pane",emit(t){return[{path:`windows-terminal/schemes/${H(t.name)}.json`,content:`${JSON.stringify(R$(t),null,2)}
387
- `}]},emitShared(t){return[{path:"windows-terminal/ttheme.json",content:ih(t)}]}};function HN(t){let e=t.replace(Rs,"");return/^[ \t]*\[colors[\].]/m.test(e)||/^[ \t]*colors[ \t]*[.=]/m.test(e)}var FN=/^[ \t]*\[general\][ \t]*(?:#.*)?$/m,T$=/^[ \t]*\[/m,A$=/^[ \t]*import[ \t]*=/m,CN=/^[ \t]*general[ \t]*[.=]/m;function LN(t){return t?`[general]
388
- import = ["${t}"]`:""}function oh(t,e){let n=t.replace(Rs,""),r=FN.exec(n);if(!r){let c=n.search(T$),u=c<0?n:n.slice(0,c);if(CN.test(n)||A$.test(u))return;return Ir(t,LN(e))}let i=r.index+r[0].length,s=n.slice(i),o=s.search(T$);if(A$.test(o<0?s:s.slice(0,o)))return;let a=e?`import = ["${e}"]
369
+ `}function pk(t){if(t==="")return Oh();return Object.keys(qo).reduce(ZN,t)}var Mu=/["$`\\]/;function XN(t){return t.replace(/_\([^)]*\)$/,"").replaceAll("_"," ")}function Ih(t,e,n=[],r={}){for(let l of t)for(let d of[l.name,l.group,l.native??"",...l.nativeNames??[],l.ansiSource])if(Mu.test(d))throw Error(`${l.name}: "${d}" contains a character that breaks zsh quoting`);let i=Math.max(0,...t.map((l)=>l.name.length)),o=(l,d)=>` ${l.name.padEnd(i)} "${d}"`,s=(l)=>l.map((d)=>d.name).join(" "),a=It(t),c=(l)=>`'${l.replaceAll("'","'\\''")}'`,u=ua.filter((l)=>l.section!=="setup"&&!l.hidden);return["# Generated by `mise run build` — do not edit.","# Source of truth: themes/*.toml in the ttheme repo.","",`typeset -g TTHEME_VERSION=${At.version}`,"",'# the palette new tabs open with, which the iTerm2 "ttheme · default" profile wears',`typeset -g TTHEME_STARTUP=${e??""}`,"","# the terminals ttheme is wired into: a picture change reaches every one of them, from whichever runs the shell",`typeset -ga TTHEME_TERMINALS=(${n.join(" ")})`,...Object.keys(r).length>0?["","# what a wired terminal's adapter needs to know of it (src/terminals/)",...Object.entries(r).map(([l,d])=>`typeset -g ${l}=${c(d)}`)]:[],"","# the commands the shell layer knows (src/verbs.ts): help, completion and argument checks read them",`typeset -ga TTHEME_VERBS=(${u.map((l)=>l.name).join(" ")})`,`typeset -ga TTHEME_TAB_VERBS=(${u.filter((l)=>l.section==="tab").map((l)=>l.name).join(" ")})`,`typeset -ga TTHEME_SHELL_VERBS=(${u.filter((l)=>l.shell).map((l)=>l.name).join(" ")})`,"typeset -gA TTHEME_VERB_ARGS=(",...u.map((l)=>` ${l.name} ${c(l.args.join(" "))}`),")","typeset -gA TTHEME_VERB_ABOUT=(",...u.map((l)=>` ${l.name} ${c(l.about)}`),")",`typeset -g TTHEME_HELP=${c(la(!1,!0))}`,`typeset -g TTHEME_HELP_ALL=${c(la(!0,!0))}`,"","# the screens the bare ttheme switches between (src/hub.ts): the exit status of a screen run by the CLI says where it went",`typeset -ga TTHEME_HUB_TABS=(${Vn.map((l)=>l.name).join(" ")})`,`typeset -ga TTHEME_HUB_TITLES=(${Vn.map((l)=>l.title).join(" ")})`,`typeset -gi TTHEME_HUB_CLOSED=${iu} TTHEME_HUB_SWITCH=${ou}`,"","# the settings config.zsh holds, handed to the CLI on every call",`typeset -ga TTHEME_SETTINGS=(${yu.join(" ")})`,"","# seed for `ttheme config` when no config.zsh exists yet",`typeset -g TTHEME_CONFIG_TEMPLATE='${Oh().trimEnd().replaceAll("'","'\\''")}'`,"","typeset -gA TTHEME_PALETTE=(",...t.map((l)=>o(l,[l.background,l.foreground,l.cursor,l.selection,...l.ansi].join(" "))),")","","# series order: new tabs cycle through it and TTHEME_SORT=series lists it — the default role stays applyable but unlisted",`typeset -ga TTHEME_ORDER=(${s(a)})`,"","# the same palettes by series name, then palette name: TTHEME_SORT=abc lists them this way",`typeset -ga TTHEME_ABC=(${s(ki(a))})`,"","typeset -gA TTHEME_GROUP=(",...t.map((l)=>o(l,l.group)),")","","# the catalog a market palette sits in — the folder under the market's palettes/, one level below the market in every list","typeset -gA TTHEME_CATALOG=(",...t.filter((l)=>l.catalog).map((l)=>o(l,l.catalog??"")),")","","# original-language title, rendered dim next to the group","typeset -gA TTHEME_NATIVE=(",...t.filter((l)=>l.native).map((l)=>o(l,l.native??"")),")","","# the character's names in its original language, |-separated, and as its booru tag spells it: preview searches both","typeset -gA TTHEME_NATIVE_NAMES=(",...t.filter((l)=>l.nativeNames).map((l)=>o(l,(l.nativeNames??[]).join("|"))),")","typeset -gA TTHEME_CHARACTER=(",...t.filter((l)=>l.booru&&!Mu.test(l.booru)).map((l)=>o(l,XN(l.booru??""))),")","","# the example scenes preview draws beside the list (src/scenes.ts), each line as «role»text runs",`typeset -ga TTHEME_SCENES=(${zt.map((l)=>l.name).join(" ")})`,...zt.flatMap((l,d)=>[`typeset -ga TTHEME_SCENE_${d+1}=(`,...l.lines.map((f)=>` ${c(f)}`),")"]),"","# each booru's ANSI color, which marks a link to one of its posts",`typeset -gA TTHEME_SITE_ANSI=(${J.map((l)=>`${l.name} ${l.ansi}`).join(" ")})`,"","# the terminals that open OSC 8 links (src/terminal.ts)",`typeset -ga TTHEME_LINKS=(${Object.entries(pe).flatMap(([l,d])=>d.links?[l]:[]).join(" ")})`,"","# the six colors a list row shows: foreground, the signature, then red and green","typeset -gA TTHEME_SWATCH=(",...t.map((l)=>o(l,Bc(l).join(" "))),")","","# where each palette's 16 ANSI colors came from","typeset -gA TTHEME_SRC=(",...t.map((l)=>o(l,l.ansiSource)),")",""].join(`
370
+ `)}function gk(t){let e=Object.entries(t).flatMap(([r,i])=>{let o=i.filter((s)=>!Mu.test(s)&&!s.includes("|"));return o.length>0&&!Mu.test(r)?[[r,o.join("|")]]:[]}),n=Math.max(0,...e.map(([r])=>r.length));return["# the character's other names in every language, |-separated, from the aninames index in the cache: preview reads this when it opens and searches them too","typeset -gA TTHEME_ALIASES=(",...e.map(([r,i])=>` ${r.padEnd(n)} "${i}"`),")",""].join(`
371
+ `)}var Rh={id:"shell",emitShared(t){return[{path:"shell/palettes.zsh",content:Ih(t.map(Qe))}]}};import{execFileSync as tA}from"node:child_process";import{existsSync as bk,readdirSync as eA,readFileSync as nA}from"node:fs";import{join as wk}from"node:path";function at(t){return bk(t)?nA(t,"utf8"):""}function Ct(t,e){return t.startsWith(`${e}/`)?`~${t.slice(e.length)}`:t}function xu(t){return[...new Set(t.split(`
372
+ `).map((e)=>e.split(/[ =]/)[0]))].join(", ")}function xn(t,e){let n=at(t),r=e(n);return r===n?[]:[{file:t,content:r}]}function fa(t){return process.env.XDG_DATA_HOME??wk(t,".local","share")}function Yo(t){return bk(t)?eA(t).flatMap((e)=>e.startsWith(j(""))?[wk(t,e)]:[]):[]}function Ph(t,e){if(!t.shelf)return[];let n=`${[t.id,t.shelf.from].filter(Boolean).join("/")}/`;return(t.emitter.emit?.(e)??[]).flatMap((r)=>{let i=r.path.startsWith(n)?r.path.slice(n.length):"";return i!==""&&!i.includes("/")?[{file:i,content:r.content}]:[]})}function on(){return{platform:process.platform,env:process.env,run:(t,e)=>{try{return tA(t,[...e],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5000}).trim()}catch{return}}}}import{existsSync as Nk}from"node:fs";import{join as Iu}from"node:path";var rA=["black","red","green","yellow","blue","magenta","cyan","white"];function $k(t,e){return[t,...rA.map((n,r)=>`${n} = '${e[r]}'`),""].join(`
373
+ `)}var Nh={id:"alacritty",limits:"no runtime color API (OSC only)",emit(t){let e=[...jr(t),"","[colors.primary]",`background = '${t.background}'`,`foreground = '${t.foreground}'`,"","[colors.cursor]",`cursor = '${t.cursor}'`,`text = '${t.background}'`,"","[colors.selection]",`background = '${t.selectionBackground}'`,`text = '${t.foreground}'`,"",$k("[colors.normal]",t.ansi.slice(0,8)),$k("[colors.bright]",t.ansi.slice(8,16))].join(`
374
+ `);return[{path:`alacritty/themes/${j(t.name)}.toml`,content:e}]}};var Ah={id:"ghostty",emit(t){let e=[...jr(t),`background = ${t.background}`,`foreground = ${t.foreground}`,`cursor-color = ${t.cursor}`,`selection-background = ${t.selectionBackground}`,`selection-foreground = ${t.foreground}`,...t.ansi.map((n,r)=>`palette = ${r}=${n}`),"","macos-icon = custom-style",`macos-icon-ghost-color = ${t.ghostty.iconGhost}`,`macos-icon-screen-color = ${t.ghostty.iconScreen.join(",")}`,"macos-icon-frame = chrome",""].join(`
375
+ `);return[{path:`ghostty/themes/${j(t.name)}`,content:e}]}};function Wr(t){let[e,n,r]=et(t);return{"Alpha Component":1,"Blue Component":r/255,"Color Space":"P3","Green Component":n/255,"Red Component":e/255}}function yk(t){return{...Object.fromEntries(t.ansi.map((e,n)=>[`Ansi ${n} Color`,Wr(e)])),"Background Color":Wr(t.background),"Bold Color":Wr(t.foreground),"Cursor Color":Wr(t.cursor),"Cursor Text Color":Wr(t.background),"Foreground Color":Wr(t.foreground),"Selected Text Color":Wr(t.foreground),"Selection Color":Wr(t.selectionBackground)}}function kk(t){return t?{"Background Image Location":t.image,"Background Image Mode":t.cover?2:3,Blend:t.opacity}:{"Background Image Location":""}}function vk(t,e,n,r,i=!1){let o=(c,u)=>({Name:`ttheme · ${u}`,Guid:j(u),...r?{"Dynamic Profile Parent GUID":r}:{},"Use Separate Colors for Light and Dark Mode":!1,...kk(e.get(c.name)),...yk(c)}),s={Name:"ttheme · default",Guid:j("default"),"Dynamic Profile Parent GUID":r,...kk(void 0)},a=[...n?[o(n,"default")]:i&&r?[s]:[],...t.map((c)=>o(c,c.name))];return`${JSON.stringify({Profiles:a},null,2)}
376
+ `}function iA(t,e){return[` <key>${t}</key>`,"\t<dict>",...Object.entries(e).flatMap(([n,r])=>[` <key>${n}</key>`,typeof r==="string"?` <string>${r}</string>`:` <real>${r}</real>`]),"\t</dict>"].join(`
377
+ `)}var Th={id:"iterm2",limits:"colors are Display P3, the space iTerm2 reads OSC colors in",emit(t){let e=['<?xml version="1.0" encoding="UTF-8"?>','<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">','<plist version="1.0">',"<dict>",...Object.entries(yk(t)).map(([n,r])=>iA(n,r)),"</dict>","</plist>",""].join(`
378
+ `);return[{path:`iterm2/${j(t.name)}.itermcolors`,content:e}]}};var Hh={id:"kitty",emit(t){let e=[...jr(t),`background ${t.background}`,`foreground ${t.foreground}`,`cursor ${t.cursor}`,`cursor_text_color ${t.background}`,`selection_background ${t.selectionBackground}`,`selection_foreground ${t.foreground}`,...t.ansi.map((n,r)=>`color${r} ${n}`),""].join(`
379
+ `);return[{path:`kitty/themes/${j(t.name)}.conf`,content:e}]}};function Sk(t){return["# Generated by ttheme — rewritten on every add, remove and default; do not edit.","import os","",`THEMES = ${JSON.stringify(t.themes)}`,`BACKGROUNDS = ${JSON.stringify(t.backgrounds)}`,"PLACES = {"," 'top-left': 'top-left', 'top-center': 'top', 'top-right': 'top-right',"," 'center-left': 'left', 'center': 'center', 'center-center': 'center', 'center-right': 'right',"," 'bottom-left': 'bottom-left', 'bottom-center': 'bottom', 'bottom-right': 'bottom-right',","}","","shown = {}","faded = {}","worn = {}","","","def locate(path):"," if path.startswith('~/'):"," return os.path.expanduser(path)"," return path if os.path.isabs(path) else os.path.join(BACKGROUNDS, path)","","","def read(path, into):"," try:"," with open(path, encoding='utf-8') as f:"," lines = f.read().splitlines()"," except OSError:"," return False"," for line in lines:"," key, sep, value = line.partition('=')"," key, value = key.strip(), value.strip()"," if not sep or not key or key.startswith('#'):"," continue"," if key == 'config-file':"," read(locate(value.lstrip('?')), into)"," else:"," into[key] = value"," return True","","","def logo(palette):"," c = {}"," if not palette or not read(os.path.join(BACKGROUNDS, palette.replace('@', '--', 1).replace('/', '--', 1) + '.conf'), c):"," return None"," image = c.get('background-image', '')"," try:"," opacity = min(float(c.get('background-image-opacity', '1')), 1.0)"," except ValueError:"," opacity = 1.0"," if not image or opacity <= 0:"," return None"," return locate(image), PLACES.get(c.get('background-image-position', 'center'), 'center'), opacity","","","def fade(path, opacity):"," key = f'{path}#{opacity}'"," if key not in faded:"," from kitty.fast_data_types import load_png_data, png_from_32bit_rgba_data"," with open(path, 'rb') as f:"," rgba, width, height = load_png_data(f.read())"," data = bytearray(rgba)"," data[3::4] = data[3::4].translate(bytes(round(a * opacity) for a in range(256)))"," if len(faded) > 8:"," faded.clear()"," faded[key] = png_from_32bit_rgba_data(bytes(data), width, height)"," return key, faded[key]","","","def show(window):"," want = logo(window.user_vars.get('ttheme_shown') or '')"," if window.id in shown and shown[window.id] == want:"," return"," shown[window.id] = want"," try:"," if want is None:"," window.set_logo('')"," elif want[2] < 1:"," key, png = fade(want[0], want[2])"," window.set_logo(key, want[1], 1, png)"," else:"," window.set_logo(want[0], want[1], 1)"," except Exception:"," shown.pop(window.id, None)","","","def theme(palette):"," path = os.path.join(THEMES, 'ttheme-' + palette.replace('@', '--', 1).replace('/', '--', 1) + '.conf')"," if not palette or not os.path.exists(path):"," return None"," from kitty.colors import parse_colors"," return parse_colors([path])","","","def wear(palette):"," colors = theme(palette) if worn.get('startup') != palette else None"," if colors is None:"," return"," from kitty.colors import patch_colors"," patch_colors(colors[0], colors[1], True, ())"," worn['startup'] = palette","","","def rewear(boss):"," from kitty.colors import patch_colors"," for window in tuple(boss.all_windows):"," colors = theme(window.user_vars.get('ttheme_worn') or '')"," if colors is not None:"," patch_colors(colors[0], colors[1], False, (window,))","","","def on_load(boss, data):"," if getattr(boss, 'ttheme_rewears', False):"," return"," load = boss.load_config_file",""," def reload(*args, **kwargs):"," load(*args, **kwargs)"," worn.pop('startup', None)"," rewear(boss)",""," boss.load_config_file = reload"," boss.ttheme_rewears = True","","","def on_set_user_var(boss, window, data):"," if data['key'] == 'ttheme_shown':"," show(window)"," elif data['key'] == 'ttheme_startup':"," wear(data['value'] or '')","","","def on_focus_change(boss, window, data):"," if data['focused']:"," show(window)","","","def on_close(boss, window, data):"," shown.pop(window.id, None)",""].join(`
380
+ `)}function oA(t){let[e]=t;if(!e)throw Error("manifest needs at least one theme");return{...Gc(),palettes:t.map(Qe)}}var Ch={id:"meta",emitShared(t){return[{path:"manifest.json",content:`${JSON.stringify(oA(t),null,2)}
381
+ `}]}};var Lh={id:"terminal-app",limits:"profiles go into its own settings at init, so the archive carries none"};import{createHash as sA}from"node:crypto";var aA=["black","red","green","yellow","blue","magenta","cyan","white"];function Ek(t,e){return[` ${t}:`,...aA.map((n,r)=>` ${n}: "${e[r]}"`)]}function cA(t,e,n){let r=sA("sha1");for(let i of e)r.update(i);return`${j(t)}.${r.digest("hex").slice(0,8)}.${n}`}function Mk(t,e,n){let r=2166136261;for(let i of Buffer.from(`${e}
382
+ ${n.toLowerCase()}`,"utf8"))r=Math.imul(r^i,16777619)>>>0;return`${j(t)}.${r.toString(16).padStart(8,"0")}.png`}function ha(t,e){return e?cA(t,[e.image,String(xk(e))],"yaml"):`${j(t)}.yaml`}function xk(t){return Math.max(0,Math.min(100,Math.round(t.opacity*100)))}function ma(t,e){return[`name: "${t.name}"`,`background: "${t.background}"`,`foreground: "${t.foreground}"`,`accent: "${t.cursor}"`,`cursor: "${t.cursor}"`,`details: ${vt(t.background)<0.18?"darker":"lighter"}`,...e?["background_image:",` path: "${e.image}"`,` opacity: ${xk(e)}`]:[],"terminal_colors:",...Ek("normal",t.ansi.slice(0,8)),...Ek("bright",t.ansi.slice(8,16)),""].join(`
383
+ `)}var Fh={id:"warp",limits:"no selection color, and Warp paints one theme app-wide",emit(t){return[{path:`warp/themes/${ha(t.name)}`,content:ma(t)}]}};var Ok=(t)=>`[${t.map((e)=>`"${e}"`).join(", ")}]`,jh={id:"wezterm",limits:"OSC repaints per pane, pictures show per window",emit(t){let e=["[metadata]",`name = "${j(t.name)}"`,`origin_url = "${t.ansiSource}"`,"","[colors]",`foreground = "${t.foreground}"`,`background = "${t.background}"`,`cursor_bg = "${t.cursor}"`,`cursor_border = "${t.cursor}"`,`cursor_fg = "${t.background}"`,`selection_bg = "${t.selectionBackground}"`,`selection_fg = "${t.foreground}"`,"",`ansi = ${Ok(t.ansi.slice(0,8))}`,`brights = ${Ok(t.ansi.slice(8,16))}`,""].join(`
384
+ `);return[{path:`wezterm/colors/${j(t.name)}.toml`,content:e}]}},Jo=(t)=>JSON.stringify(t);function Ik(t){return["-- Generated by ttheme — rewritten on every add, remove and default; do not edit.","local wezterm = require 'wezterm'","",`local MODULE = ${Jo(t.path)}`,`local COLORS = ${Jo(t.colors)}`,`local BACKGROUNDS = ${Jo(t.backgrounds)}`,`local STARTUP = ${t.startup?Jo(j(t.startup)):"nil"}`,"local PALETTES = {",...t.palettes.map((e)=>` [${Jo(e.name)}] = ${Jo(e.background)},`),"}","","local X = { left = 'Left', center = 'Center', right = 'Right' }","local Y = { top = 'Top', center = 'Middle', bottom = 'Bottom' }","local SIZE = { cover = 'Cover', contain = 'Contain', stretch = '100%' }","","local function locate(path)"," if path:sub(1, 2) == '~/' then"," return os.getenv('HOME') .. path:sub(2)"," elseif path:sub(1, 1) == '/' or path:match('^%a:[/\\\\]') then"," return path"," end"," return BACKGROUNDS .. '/' .. path","end","","local function read(path, into)"," local f = io.open(path, 'r')"," if not f then"," return false"," end"," for line in f:lines() do"," local key, value = line:match('^%s*([%w%-]+)%s*=%s*(.-)%s*$')"," if key == 'config-file' then"," read(locate((value:gsub('^%?', ''))), into)"," elseif key then"," into[key] = value"," end"," end"," f:close()"," return true","end","","local function layers(palette)"," local color = PALETTES[palette]"," local c = {}"," if not color or not read(BACKGROUNDS .. '/' .. ((palette:gsub('@', '--', 1)):gsub('/', '--', 1)) .. '.conf', c) then"," return nil, 'none'"," end"," local image = c['background-image'] or ''"," local opacity = tonumber(c['background-image-opacity'] or '1') or 1"," if image == '' or opacity <= 0 then"," return nil, 'none'"," end"," local fit = c['background-image-fit'] or 'contain'"," local position = c['background-image-position'] or 'center'"," local y, x = position:match('^(%a+)-(%a+)$')"," local rep = c['background-image-repeat'] == 'true' and 'Repeat' or 'NoRepeat'"," return {"," { source = { Color = color }, width = '100%', height = '100%' },"," {"," source = { File = locate(image) },"," opacity = opacity,"," width = SIZE[fit],"," height = SIZE[fit],"," horizontal_align = X[x or 'center'],"," vertical_align = Y[y or 'center'],"," repeat_x = rep,"," repeat_y = rep,"," },"," }, table.concat({ color, image, opacity, fit, position, rep }, '|')","end","","local function framed(window, view)"," local color, image, opacity, W, H, w, h, x, y, at ="," view:match('^([^|]*)|([^|]*)|([^|]*)|(%d+)|(%d+)|(%-?%d+)|(%-?%d+)|(%-?%d+)|(%-?%d+)|(%d)$')"," if not image or image == '' or tonumber(W) == 0 or tonumber(H) == 0 then"," return nil, 'none'"," end"," local d = window:get_dimensions()"," local k = math.max(d.pixel_width / W, d.pixel_height / H)"," local n = tonumber(at) - 1"," local ax, ay = n % 3, n // 3"," local px = function(n) return string.format('%.2fpx', n) end"," return {"," { source = { Color = color }, width = '100%', height = '100%' },"," {"," source = { File = image },"," opacity = tonumber(opacity) or 1,"," width = px(w * k),"," height = px(h * k),"," horizontal_align = 'Left',"," vertical_align = 'Top',"," horizontal_offset = px(ax * (d.pixel_width - W * k) / 2 + x * k),"," vertical_offset = px(ay * (d.pixel_height - H * k) / 2 + y * k),"," repeat_x = 'NoRepeat',"," repeat_y = 'NoRepeat',"," },"," }, table.concat({ view, d.pixel_width, d.pixel_height }, '|')","end","","local shown = {}","","local function show(window, pane)"," local vars = pane:get_user_vars()"," local id = window:window_id()"," local background, key"," if vars.ttheme_view and vars.ttheme_view ~= '' then"," background, key = framed(window, vars.ttheme_view)"," elseif vars.ttheme_shown and vars.ttheme_shown ~= '' then"," background, key = layers(vars.ttheme_shown)"," elseif shown[id] == nil then"," return"," end"," if shown[id] == key then"," return"," end"," shown[id] = key"," local overrides = window:get_config_overrides() or {}"," overrides.background = background"," window:set_config_overrides(overrides)","end","","wezterm.on('user-var-changed', function(window, pane, name)"," if name == 'ttheme_shown' or name == 'ttheme_view' then"," show(window, pane)"," end","end)","wezterm.on('update-status', show)","","return function(config)"," local dirs = config.color_scheme_dirs or {}"," table.insert(dirs, COLORS)"," config.color_scheme_dirs = dirs"," if STARTUP then"," config.color_scheme = STARTUP"," end"," wezterm.add_to_config_reload_watch_list(MODULE)","end",""].join(`
385
+ `)}var Rk=["black","red","green","yellow","blue","purple","cyan","white"];function Pk(t){return{name:j(t.name),background:t.background,foreground:t.foreground,cursorColor:t.cursor,selectionBackground:t.selectionBackground,...Object.fromEntries(Rk.map((e,n)=>[e,t.ansi[n]])),...Object.fromEntries(Rk.map((e,n)=>[`bright${e[0]?.toUpperCase()}${e.slice(1)}`,t.ansi[n+8]]))}}function _h(t,e,n){let r={...e&&n?{profiles:[{updates:e,colorScheme:j(n)}]}:{},schemes:t.map(Pk)};return`${JSON.stringify(r,null,2)}
386
+ `}var Bh={id:"windows-terminal",limits:"a picture belongs to a profile, which a pane cannot change, so none; OSC repaints per pane",emit(t){return[{path:`windows-terminal/schemes/${j(t.name)}.json`,content:`${JSON.stringify(Pk(t),null,2)}
387
+ `}]},emitShared(t){return[{path:"windows-terminal/ttheme.json",content:_h(t)}]}};function uA(t){let e=t.replace(Do,"");return/^[ \t]*\[colors[\].]/m.test(e)||/^[ \t]*colors[ \t]*[.=]/m.test(e)}var lA=/^[ \t]*\[general\][ \t]*(?:#.*)?$/m,Ak=/^[ \t]*\[/m,Tk=/^[ \t]*import[ \t]*=/m,dA=/^[ \t]*general[ \t]*[.=]/m;function fA(t){return t?`[general]
388
+ import = ["${t}"]`:""}function Gh(t,e){let n=t.replace(Do,""),r=lA.exec(n);if(!r){let c=n.search(Ak),u=c<0?n:n.slice(0,c);if(dA.test(n)||Tk.test(u))return;return _r(t,fA(e))}let i=r.index+r[0].length,o=n.slice(i),s=o.search(Ak);if(Tk.test(s<0?o:o.slice(0,s)))return;let a=e?`import = ["${e}"]
389
389
  `:"";return`${n.slice(0,i)}
390
- ${Wd}
391
- ${a}${Kd}${s}`}function ou(t){return au(t,"alacritty","alacritty.toml")}function P$(t){return au(t.configHome,"alacritty","themes")}function jN(t,e){return e?au(t,"alacritty","themes",`${H(e)}.toml`):void 0}var ah={id:"alacritty",name:"Alacritty",emitter:Vd,shelf:{from:"themes",dir:P$},offered:()=>!0,present:(t)=>N$(au(t.configHome,"alacritty")),sync(t,e){e.themes(ah);let n=ou(t.configHome),r=oh(st(n),jN(t.configHome,t.startup));if(r!==void 0)e.wire(n,r)},plan(t){let e=ou(t.configHome);return oh(st(e),void 0)!==void 0?[`Edit ${Tt(e,t.home)} — a ttheme block: general.import`]:[]},notes(t){let e=ou(t.configHome),n=st(e);return[...N$(e)&&oh(n,void 0)===void 0?[`${e} already imports files under [general] — ttheme left it alone; add ${P$(t)}/<palette>.toml to that import list yourself`]:[],...HN(n)?[`${Tt(e,t.home)} sets its own colors, which win over an imported palette — remove them to open with ttheme's`]:[]]},next:()=>["Alacritty Reloads its config by itself"],unwire:(t)=>({edits:wn(ou(t.configHome),Rr),removals:[],touches:[]})};import{existsSync as _N}from"node:fs";import{join as uu}from"node:path";function GN(t,e,n=""){let r=[];if(!Nr(n,"command")){if(r.push(`command = ${t}/launch-tab.zsh`),!Nr(n,"shell-integration"))r.push("shell-integration = zsh")}if(e)r.push(`theme = ${H(e)}`);return r.push(`config-file = ?${t}/backgrounds/shown.conf`),r.join(`
392
- `)}function cu(t){return uu(t,"ghostty","config")}function H$(t,e,n){return GN(uu(t.configHome,"ttheme"),e,n)}var ch={id:"ghostty",name:"Ghostty",emitter:Zd,shelf:{from:"themes",dir:(t)=>uu(t.configHome,"ghostty","themes")},offered:()=>!0,present:(t)=>_N(uu(t.configHome,"ghostty")),sync(t,e){e.themes(ch);let n=cu(t.configHome),r=st(n);e.wire(n,Ir(r,H$(t,t.startup,r)))},plan(t){let e=cu(t.configHome);return[`Edit ${Tt(e,t.home)} — a ttheme block: ${su(H$(t,t.startup,st(e)))}`]},notes(t){let e=cu(t.configHome);return Nr(st(e),"command")?[`${Tt(e,t.home)} sets its own command — ttheme leaves it, so a new tab takes its palette once zsh starts`]:[]},next:()=>["Restart Ghostty New tabs pick up its config"],unwire:(t)=>({edits:wn(cu(t.configHome),Rr),removals:[],touches:[]})};import{existsSync as F$}from"node:fs";import{join as j$}from"node:path";var uh="ttheme-default";function Ps(t){return j$(t,"Library","Application Support","iTerm2","DynamicProfiles","ttheme.json")}function _$(t){return t.itermBase!==void 0&&t.palettes.length>0}function C$(t){let e=q(t.configHome),n=new Map;for(let i of t.themes){let s=Se(e,i.name,t.home);if(s)n.set(i.name,s)}let r=new Set(Mt(t.entries).map((i)=>i.name));return y$(t.themes.filter((i)=>r.has(i.name)),n,t.themes.find((i)=>i.name===t.startup),t.state.itermBase,_$(t.state))}function lh(t){return t.env.TTHEME_ITERM_SUITE??"com.googlecode.iterm2"}function L$(t){return t.run("defaults",["read",lh(t),"Default Bookmark Guid"])||void 0}function BN(t){return t.run("defaults",["read",lh(t),"PreventEscapeSequenceFromChangingProfile"])==="0"}var UN={key:"itermBase",profile:()=>"ttheme · default",base(t){let e=L$(t.host);return e&&!e.startsWith("ttheme-")?{...t.state,itermBase:e}:t.state},point(t,e){let n=L$(t.host),r=t.startup?e||n===uh?uh:void 0:n===uh&&!_$(t.state)?t.state.itermBase:void 0;if(!r||r===n)return;return t.host.run("defaults",["write",lh(t.host),"Default Bookmark Guid","-string",r]),{restart:Boolean(t.host.run("pgrep",["-x","iTerm2"]))}}},G$={id:"iterm2",name:"iTerm2",emitter:Qd,bakes:!0,offered:(t,e)=>e.platform==="darwin",present:(t)=>F$(j$(t.home,"Library","Application Support","iTerm2")),sync(t,e){e.write(Ps(t.home),C$(t))},pictures(t,e){e.write(Ps(t.home),C$(t))},layer:(t,e)=>({TTHEME_ITERM_SWITCH:BN(e)?"1":"",TTHEME_ITERM_PROFILES:Ps(t.home)}),plan:(t)=>[`Write ${Tt(Ps(t.home),t.home)} — a "ttheme · <palette>" profile per palette`],notes:()=>[],next(t,e){let n=['iTerm2 profiles A "ttheme · <palette>" per palette in Settings › Profiles'];if(t.startup)n.push(e?.restart?`Restart iTerm2 New tabs open on "ttheme · default", which wears ${t.startup}`:`iTerm2 default "ttheme · default" wears ${t.startup} and follows \`ttheme default\``);return n},unwire:(t)=>({edits:[],removals:F$(Ps(t.home))?[Ps(t.home)]:[],touches:[]}),defaults:UN};import{existsSync as WN}from"node:fs";import{join as fu}from"node:path";function B$(t,e,n=""){return[...t?[`include themes/${H(t)}.conf`]:[],`watcher ${e}`,...["window_logo_scale 100","window_logo_alpha 1"].filter((r)=>!Nr(n,r.split(" ")[0]))].join(`
393
- `)}function lu(t){return fu(t,"kitty","kitty.conf")}function fh(t){return fu(t,"ttheme","kitty.py")}function U$(t){return fu(t.configHome,"kitty","themes")}var dh={id:"kitty",name:"kitty",emitter:Xd,shelf:{from:"themes",dir:U$},offered:()=>!0,present:(t)=>WN(fu(t.configHome,"kitty")),sync(t,e){e.themes(dh),e.write(fh(t.configHome),v$({themes:U$(t),backgrounds:q(t.configHome)}));let n=lu(t.configHome),r=st(n);e.wire(n,Ir(r,B$(t.startup,fh(t.configHome),r)))},plan(t){let e=lu(t.configHome),n=B$(t.startup,fh(t.configHome),st(e));return[`Edit ${Tt(e,t.home)} — a ttheme block: ${su(n)}`]},notes(t){let e=st(lu(t.configHome));return Nr(e,"window_logo_scale")||Nr(e,"window_logo_alpha")?["kitty.conf sets its own window_logo_scale or window_logo_alpha — pictures are drawn with them"]:[]},next:()=>["New kitty window Pictures follow it — kitty reloads its colors by itself"],unwire:(t)=>({edits:wn(lu(t.configHome),Rr),removals:[],touches:[]})};import{createHash as KN}from"node:crypto";import{existsSync as du}from"node:fs";import{basename as K$,isAbsolute as zN,join as vi}from"node:path";function Hs(t){return vi(qo(t),"konsole")}function Vo(t){return vi(t,"konsolerc")}function z$(t){return`${H(t)}.profile`}function Zo(t){return`ttheme · ${t}`}function D$(t,e){let n=t.findIndex((i)=>i.trim()===`[${e}]`);if(n<0)return;let r=t.findIndex((i,s)=>s>n&&i.trimStart().startsWith("["));return[n,r<0?t.length:r]}function hh(t){return new RegExp(String.raw`^\s*${t}\s*=`)}function Pr(t,e,n){let r=t.split(`
394
- `),i=D$(r,e);return(i&&r.slice(i[0]+1,i[1]).find((o)=>hh(n).test(o)))?.replace(hh(n),"").trim()}function q$(t,e){let n=t.split(`
395
- `),r=D$(n,"Desktop Entry"),i=e===void 0?[]:[`DefaultProfile=${e}`];if(!r)return e===void 0?t:`${t===""?"":t.replace(/\n*$/,`
390
+ ${Eh}
391
+ ${a}${Mh}${o}`}function Ou(t){return Iu(t,"alacritty","alacritty.toml")}function Hk(t){return Iu(t.configHome,"alacritty","themes")}function hA(t,e){return e?Iu(t,"alacritty","themes",`${j(e)}.toml`):void 0}var Uh={id:"alacritty",name:"Alacritty",emitter:Nh,shelf:{from:"themes",dir:Hk},offered:()=>!0,present:(t)=>Nk(Iu(t.configHome,"alacritty")),sync(t,e){e.themes(Uh);let n=Ou(t.configHome),r=Gh(at(n),hA(t.configHome,t.startup));if(r!==void 0)e.wire(n,r)},plan(t){let e=Ou(t.configHome);return Gh(at(e),void 0)!==void 0?[`Edit ${Ct(e,t.home)} — a ttheme block: general.import`]:[]},notes(t){let e=Ou(t.configHome),n=at(e);return[...Nk(e)&&Gh(n,void 0)===void 0?[`${e} already imports files under [general] — ttheme left it alone; add ${Hk(t)}/<palette>.toml to that import list yourself`]:[],...uA(n)?[`${Ct(e,t.home)} sets its own colors, which win over an imported palette — remove them to open with ttheme's`]:[]]},next:()=>["Alacritty Reloads its config by itself"],unwire:(t)=>({edits:xn(Ou(t.configHome),Br),removals:[],touches:[]})};import{existsSync as mA}from"node:fs";import{join as Pu}from"node:path";function pA(t,e,n=""){let r=[];if(!Gr(n,"command")){if(r.push(`command = ${t}/launch-tab.zsh`),!Gr(n,"shell-integration"))r.push("shell-integration = zsh")}if(e)r.push(`theme = ${j(e)}`);return r.push(`config-file = ?${t}/backgrounds/shown.conf`),r.join(`
392
+ `)}function Ru(t){return Pu(t,"ghostty","config")}function Ck(t,e,n){return pA(Pu(t.configHome,"ttheme"),e,n)}var Wh={id:"ghostty",name:"Ghostty",emitter:Ah,shelf:{from:"themes",dir:(t)=>Pu(t.configHome,"ghostty","themes")},offered:()=>!0,present:(t)=>mA(Pu(t.configHome,"ghostty")),sync(t,e){e.themes(Wh);let n=Ru(t.configHome),r=at(n);e.wire(n,_r(r,Ck(t,t.startup,r)))},plan(t){let e=Ru(t.configHome);return[`Edit ${Ct(e,t.home)} — a ttheme block: ${xu(Ck(t,t.startup,at(e)))}`]},notes(t){let e=Ru(t.configHome);return Gr(at(e),"command")?[`${Ct(e,t.home)} sets its own command — ttheme leaves it, so a new tab takes its palette once zsh starts`]:[]},next:()=>["Restart Ghostty New tabs pick up its config"],unwire:(t)=>({edits:xn(Ru(t.configHome),Br),removals:[],touches:[]})};import{existsSync as Lk}from"node:fs";import{join as _k}from"node:path";var Kh="ttheme-default";function Vo(t){return _k(t,"Library","Application Support","iTerm2","DynamicProfiles","ttheme.json")}function Bk(t){return t.itermBase!==void 0&&t.palettes.length>0}function Fk(t){let e=V(t.configHome),n=new Map;for(let i of t.themes){let o=Oe(e,i.name,t.home);if(o)n.set(i.name,o)}let r=new Set(It(t.entries).map((i)=>i.name));return vk(t.themes.filter((i)=>r.has(i.name)),n,t.themes.find((i)=>i.name===t.startup),t.state.itermBase,Bk(t.state))}function zh(t){return t.env.TTHEME_ITERM_SUITE??"com.googlecode.iterm2"}function jk(t){return t.run("defaults",["read",zh(t),"Default Bookmark Guid"])||void 0}function gA(t){return t.run("defaults",["read",zh(t),"PreventEscapeSequenceFromChangingProfile"])==="0"}var bA={key:"itermBase",profile:()=>"ttheme · default",base(t){let e=jk(t.host);return e&&!e.startsWith("ttheme-")?{...t.state,itermBase:e}:t.state},point(t,e){let n=jk(t.host),r=t.startup?e||n===Kh?Kh:void 0:n===Kh&&!Bk(t.state)?t.state.itermBase:void 0;if(!r||r===n)return;return t.host.run("defaults",["write",zh(t.host),"Default Bookmark Guid","-string",r]),{restart:Boolean(t.host.run("pgrep",["-x","iTerm2"]))}}},Gk={id:"iterm2",name:"iTerm2",emitter:Th,bakes:!0,offered:(t,e)=>e.platform==="darwin",present:(t)=>Lk(_k(t.home,"Library","Application Support","iTerm2")),sync(t,e){e.write(Vo(t.home),Fk(t))},pictures(t,e){e.write(Vo(t.home),Fk(t))},layer:(t,e)=>({TTHEME_ITERM_SWITCH:gA(e)?"1":"",TTHEME_ITERM_PROFILES:Vo(t.home)}),plan:(t)=>[`Write ${Ct(Vo(t.home),t.home)} — a "ttheme · <palette>" profile per palette`],notes:()=>[],next(t,e){let n=['iTerm2 profiles A "ttheme · <palette>" per palette in Settings › Profiles'];if(t.startup)n.push(e?.restart?`Restart iTerm2 New tabs open on "ttheme · default", which wears ${t.startup}`:`iTerm2 default "ttheme · default" wears ${t.startup} and follows \`ttheme default\``);return n},unwire:(t)=>({edits:[],removals:Lk(Vo(t.home))?[Vo(t.home)]:[],touches:[]}),defaults:bA};import{existsSync as wA}from"node:fs";import{join as Au}from"node:path";function Uk(t,e,n=""){return[...t?[`include themes/${j(t)}.conf`]:[],`watcher ${e}`,...["window_logo_scale 100","window_logo_alpha 1"].filter((r)=>!Gr(n,r.split(" ")[0]))].join(`
393
+ `)}function Nu(t){return Au(t,"kitty","kitty.conf")}function Dh(t){return Au(t,"ttheme","kitty.py")}function Wk(t){return Au(t.configHome,"kitty","themes")}var qh={id:"kitty",name:"kitty",emitter:Hh,shelf:{from:"themes",dir:Wk},offered:()=>!0,present:(t)=>wA(Au(t.configHome,"kitty")),sync(t,e){e.themes(qh),e.write(Dh(t.configHome),Sk({themes:Wk(t),backgrounds:V(t.configHome)}));let n=Nu(t.configHome),r=at(n);e.wire(n,_r(r,Uk(t.startup,Dh(t.configHome),r)))},plan(t){let e=Nu(t.configHome),n=Uk(t.startup,Dh(t.configHome),at(e));return[`Edit ${Ct(e,t.home)} — a ttheme block: ${xu(n)}`]},notes(t){let e=at(Nu(t.configHome));return Gr(e,"window_logo_scale")||Gr(e,"window_logo_alpha")?["kitty.conf sets its own window_logo_scale or window_logo_alpha — pictures are drawn with them"]:[]},next:()=>["New kitty window Pictures follow it — kitty reloads its colors by itself"],unwire:(t)=>({edits:xn(Nu(t.configHome),Br),removals:[],touches:[]})};import{createHash as $A}from"node:crypto";import{existsSync as Tu}from"node:fs";import{basename as zk,isAbsolute as kA,join as Ti}from"node:path";function Zo(t){return Ti(fa(t),"konsole")}function pa(t){return Ti(t,"konsolerc")}function Dk(t){return`${j(t)}.profile`}function ga(t){return`ttheme · ${t}`}function qk(t,e){let n=t.findIndex((i)=>i.trim()===`[${e}]`);if(n<0)return;let r=t.findIndex((i,o)=>o>n&&i.trimStart().startsWith("["));return[n,r<0?t.length:r]}function Yh(t){return new RegExp(String.raw`^\s*${t}\s*=`)}function Kr(t,e,n){let r=t.split(`
394
+ `),i=qk(r,e);return(i&&r.slice(i[0]+1,i[1]).find((s)=>Yh(n).test(s)))?.replace(Yh(n),"").trim()}function Yk(t,e){let n=t.split(`
395
+ `),r=qk(n,"Desktop Entry"),i=e===void 0?[]:[`DefaultProfile=${e}`];if(!r)return e===void 0?t:`${t===""?"":t.replace(/\n*$/,`
396
396
 
397
397
  `)}[Desktop Entry]
398
398
  ${i[0]}
399
- `;let s=n.findIndex((a,c)=>c>r[0]&&c<r[1]&&hh("DefaultProfile").test(a));if(s>=0)n.splice(s,1,...i);else n.splice(r[0]+1,0,...i);let o=r[1]+i.length-(s>=0?1:0);if(n.slice(r[0]+1,o).every((a)=>a.trim()==="")){let a=r[0]>0&&n[r[0]-1]?.trim()===""?r[0]-1:r[0],c=o===n.length&&n[o-1]===""?o-1:o;n.splice(a,c-a)}return n.join(`
400
- `)}function DN(t){if(t&&oe(t.toLowerCase()))return t.toLowerCase();let e=t?.split(",").map((n)=>Number(n.trim()));if(!e||e.length<3||e.slice(0,3).some((n)=>!Number.isInteger(n)||n<0||n>255))return;return`#${e.slice(0,3).map((n)=>n.toString(16).padStart(2,"0")).join("")}`}function Y$(t,e){let n=e.endsWith(".profile")?e:`${e}.profile`;if(zN(n))return du(n)?n:void 0;let r=n.includes("/")?n:vi("konsole",n);return[qo(t.home),...(process.env.XDG_DATA_DIRS||"/usr/local/share:/usr/share").split(":")].map((s)=>vi(s,r)).find((s)=>du(s))}function J$(t,e,n=0){let r=e&&e!=="FALLBACK/"&&n<8?Y$(t,e):void 0;if(!r)return{};let i=st(r),s=J$(t,Pr(i,"General","Parent"),n+1);return{scheme:Pr(i,"Appearance","ColorScheme")||s.scheme,use:Pr(i,"Cursor Options","UseCustomCursorColor")??s.use,cursor:Pr(i,"Cursor Options","CustomCursorColor")??s.cursor}}function qN(t,e){let n=J$(t,e),r=n.use==="true"?DN(n.cursor):void 0;return[`ColorScheme=${n.scheme??"Breeze"}`,`UseCustomCursorColor=${r?"true":"false"}`,...r?[`customCursorColor=${r}`]:[]].join(";")}function YN(t,e){return["[Appearance]",`ColorScheme=${H(t.name)}`,"","[Cursor Options]",`CustomCursorColor=${rt(t.cursor).join(",")}`,`CustomCursorTextColor=${rt(t.background).join(",")}`,"UseCustomCursorColor=true","","[General]",`Name=${Zo(t.name)}`,`Parent=${e}`,""].join(`
401
- `)}var V$=/^ttheme-(.+)\.([0-9a-f]{8})\.colorscheme$/;function JN(t){return KN("sha1").update(t).digest("hex").slice(0,8)}function W$(t,e){let n=Hs(t.home),r=q(t.configHome),i=new Set;for(let s of t.themes){let o=Hd(s,Se(r,s.name,t.home)),a=vi(n,`${H(s.name)}.${JN(o)}.colorscheme`);i.add(a),e.write(vi(n,`${H(s.name)}.colorscheme`),o),e.write(a,o)}for(let s of Ts(n))if(V$.test(K$(s))&&!i.has(s))e.remove(s)}function VN(t){return Ts(t).flatMap((e)=>{let[,n,r]=V$.exec(K$(e))??[];return n&&r?[`${n} ${r}`]:[]}).sort().join(" ")}function ZN(t){let e=new Set(Mt(t.entries).map((n)=>n.name));return t.themes.filter((n)=>e.has(n.name)||n.name===t.startup)}var mh=["--session","--print-reply","--reply-timeout=2000"];function QN(t){return[...(t.run("dbus-send",[...mh,"--dest=org.freedesktop.DBus","/org/freedesktop/DBus","org.freedesktop.DBus.ListNames"])??"").matchAll(/string "(org\.kde\.konsole(?:-\d+)?)"/g)].flatMap(([,n=""])=>{let i=t.run("dbus-send",[...mh,`--dest=${n}`,"/Windows","org.freedesktop.DBus.Introspectable.Introspect"])?.match(/<node name="(\d+)"/)?.[1];return i?[{service:n,window:`/Windows/${i}`}]:[]})}function XN(t,{service:e,window:n},r){let i=(s,...o)=>t.run("dbus-send",[...mh,`--dest=${e}`,n,`org.kde.konsole.Window.${s}`,...o]);return i("setDefaultProfile",`string:${r}`),i("defaultProfile")?.includes(`string "${r}"`)===!0}function tT(t,e){let n=Y$(t,e);return n?Pr(st(n),"General","Name"):void 0}function eT(t){return Pr(st(Vo(t)),"Desktop Entry","DefaultProfile")}var nT={key:"konsoleBase",profile:Zo,base(t){let e=eT(t.configHome);return e&&!e.startsWith(H(""))?{...t.state,konsoleBase:e}:t.state},point(t,e){let n=Vo(t.configHome),r=st(n),i=Pr(r,"Desktop Entry","DefaultProfile"),s=i?.startsWith(H(""))===!0,o=t.startup?e||s?z$(t.startup):void 0:s?t.state.konsoleBase??"":void 0;if(o===void 0||o===(i??"")&&!e)return;if(o!==(i??""))an(n,q$(r,o||void 0));let a=t.startup?Zo(t.startup):o?tT(t,o):void 0,c=QN(t.host),u=a!==void 0&&c.every((l)=>XN(t.host,l,a));return{restart:c.length>0&&!u}}},Z$={id:"konsole",name:"Konsole",emitter:Fd,shelf:{from:"",dir:(t)=>Hs(t.home)},offered:(t,e)=>e.platform!=="darwin"&&e.platform!=="win32",present:(t)=>du(Hs(t.home))||du(Vo(t.configHome)),sync(t,e){W$(t,e);let n=Hs(t.home),r=t.state.konsoleBase??"FALLBACK/",i=new Set;for(let s of ZN(t)){let o=vi(n,z$(s.name));i.add(o),e.write(o,YN(s,r))}for(let s of Ts(n))if(s.endsWith(".profile")&&!i.has(s))e.remove(s)},pictures:W$,layer:(t)=>({TTHEME_KONSOLE_BASE:qN(t,t.state.konsoleBase),TTHEME_KONSOLE_SCHEMES:VN(Hs(t.home))}),plan(t){return[`Write ${Tt(Hs(t.home),t.home)}/${H("*")}.profile — a "ttheme · <palette>" profile per palette, on top of your own`,...t.startup?[`Edit ${Tt(Vo(t.configHome),t.home)} — DefaultProfile; \`ttheme off\` puts yours back`]:[]]},notes:()=>[],next(t,e){let n=['Konsole profiles A "ttheme · <palette>" per palette in its profile list'];if(t.startup)n.push(e?.restart?`Restart Konsole New tabs open on "${Zo(t.startup)}"`:`Konsole default "${Zo(t.startup)}", which follows \`ttheme default\``);return n},unwire(t,e){let n=Vo(t.configHome),r=st(n);return{edits:Pr(r,"Desktop Entry","DefaultProfile")?.startsWith(H(""))?[{file:n,content:q$(r,e?.konsoleBase)}]:[],removals:[],touches:[]}},defaults:nT};import{createHash as rT}from"node:crypto";import{existsSync as tk,readdirSync as iT,readFileSync as sT,rmSync as oT}from"node:fs";import{join as Ei}from"node:path";var ek="com.apple.Terminal",Qo="ttheme · ";function Qe(t){return`${Qo}${t}`}function hu(t){return Ei(t,"ttheme","terminal-app.js")}function Fs(t){return Ei(t,"ttheme","terminal-app")}function aT(t,e){return Ei(t.XDG_STATE_HOME??Ei(e,".local","state"),"ttheme","terminal-app.window")}var cT=`ObjC.import('AppKit')
399
+ `;let o=n.findIndex((a,c)=>c>r[0]&&c<r[1]&&Yh("DefaultProfile").test(a));if(o>=0)n.splice(o,1,...i);else n.splice(r[0]+1,0,...i);let s=r[1]+i.length-(o>=0?1:0);if(n.slice(r[0]+1,s).every((a)=>a.trim()==="")){let a=r[0]>0&&n[r[0]-1]?.trim()===""?r[0]-1:r[0],c=s===n.length&&n[s-1]===""?s-1:s;n.splice(a,c-a)}return n.join(`
400
+ `)}function yA(t){if(t&&le(t.toLowerCase()))return t.toLowerCase();let e=t?.split(",").map((n)=>Number(n.trim()));if(!e||e.length<3||e.slice(0,3).some((n)=>!Number.isInteger(n)||n<0||n>255))return;return`#${e.slice(0,3).map((n)=>n.toString(16).padStart(2,"0")).join("")}`}function Jk(t,e){let n=e.endsWith(".profile")?e:`${e}.profile`;if(kA(n))return Tu(n)?n:void 0;let r=n.includes("/")?n:Ti("konsole",n);return[fa(t.home),...(process.env.XDG_DATA_DIRS||"/usr/local/share:/usr/share").split(":")].map((o)=>Ti(o,r)).find((o)=>Tu(o))}function Vk(t,e,n=0){let r=e&&e!=="FALLBACK/"&&n<8?Jk(t,e):void 0;if(!r)return{};let i=at(r),o=Vk(t,Kr(i,"General","Parent"),n+1);return{scheme:Kr(i,"Appearance","ColorScheme")||o.scheme,use:Kr(i,"Cursor Options","UseCustomCursorColor")??o.use,cursor:Kr(i,"Cursor Options","CustomCursorColor")??o.cursor}}function vA(t,e){let n=Vk(t,e),r=n.use==="true"?yA(n.cursor):void 0;return[`ColorScheme=${n.scheme??"Breeze"}`,`UseCustomCursorColor=${r?"true":"false"}`,...r?[`customCursorColor=${r}`]:[]].join(";")}function SA(t,e){return["[Appearance]",`ColorScheme=${j(t.name)}`,"","[Cursor Options]",`CustomCursorColor=${et(t.cursor).join(",")}`,`CustomCursorTextColor=${et(t.background).join(",")}`,"UseCustomCursorColor=true","","[General]",`Name=${ga(t.name)}`,`Parent=${e}`,""].join(`
401
+ `)}var Zk=/^ttheme-(.+)\.([0-9a-f]{8})\.colorscheme$/;function EA(t){return $A("sha1").update(t).digest("hex").slice(0,8)}function Kk(t,e){let n=Zo(t.home),r=V(t.configHome),i=new Set;for(let o of t.themes){let s=mh(o,Oe(r,o.name,t.home)),a=Ti(n,`${j(o.name)}.${EA(s)}.colorscheme`);i.add(a),e.write(Ti(n,`${j(o.name)}.colorscheme`),s),e.write(a,s)}for(let o of Yo(n))if(Zk.test(zk(o))&&!i.has(o))e.remove(o)}function MA(t){return Yo(t).flatMap((e)=>{let[,n,r]=Zk.exec(zk(e))??[];return n&&r?[`${n} ${r}`]:[]}).sort().join(" ")}function xA(t){let e=new Set(It(t.entries).map((n)=>n.name));return t.themes.filter((n)=>e.has(n.name)||n.name===t.startup)}var Jh=["--session","--print-reply","--reply-timeout=2000"];function OA(t){return[...(t.run("dbus-send",[...Jh,"--dest=org.freedesktop.DBus","/org/freedesktop/DBus","org.freedesktop.DBus.ListNames"])??"").matchAll(/string "(org\.kde\.konsole(?:-\d+)?)"/g)].flatMap(([,n=""])=>{let i=t.run("dbus-send",[...Jh,`--dest=${n}`,"/Windows","org.freedesktop.DBus.Introspectable.Introspect"])?.match(/<node name="(\d+)"/)?.[1];return i?[{service:n,window:`/Windows/${i}`}]:[]})}function IA(t,{service:e,window:n},r){let i=(o,...s)=>t.run("dbus-send",[...Jh,`--dest=${e}`,n,`org.kde.konsole.Window.${o}`,...s]);return i("setDefaultProfile",`string:${r}`),i("defaultProfile")?.includes(`string "${r}"`)===!0}function RA(t,e){let n=Jk(t,e);return n?Kr(at(n),"General","Name"):void 0}function PA(t){return Kr(at(pa(t)),"Desktop Entry","DefaultProfile")}var NA={key:"konsoleBase",profile:ga,base(t){let e=PA(t.configHome);return e&&!e.startsWith(j(""))?{...t.state,konsoleBase:e}:t.state},point(t,e){let n=pa(t.configHome),r=at(n),i=Kr(r,"Desktop Entry","DefaultProfile"),o=i?.startsWith(j(""))===!0,s=t.startup?e||o?Dk(t.startup):void 0:o?t.state.konsoleBase??"":void 0;if(s===void 0||s===(i??"")&&!e)return;if(s!==(i??""))bn(n,Yk(r,s||void 0));let a=t.startup?ga(t.startup):s?RA(t,s):void 0,c=OA(t.host),u=a!==void 0&&c.every((l)=>IA(t.host,l,a));return{restart:c.length>0&&!u}}},Qk={id:"konsole",name:"Konsole",emitter:ph,shelf:{from:"",dir:(t)=>Zo(t.home)},offered:(t,e)=>e.platform!=="darwin"&&e.platform!=="win32",present:(t)=>Tu(Zo(t.home))||Tu(pa(t.configHome)),sync(t,e){Kk(t,e);let n=Zo(t.home),r=t.state.konsoleBase??"FALLBACK/",i=new Set;for(let o of xA(t)){let s=Ti(n,Dk(o.name));i.add(s),e.write(s,SA(o,r))}for(let o of Yo(n))if(o.endsWith(".profile")&&!i.has(o))e.remove(o)},pictures:Kk,layer:(t)=>({TTHEME_KONSOLE_BASE:vA(t,t.state.konsoleBase),TTHEME_KONSOLE_SCHEMES:MA(Zo(t.home))}),plan(t){return[`Write ${Ct(Zo(t.home),t.home)}/${j("*")}.profile — a "ttheme · <palette>" profile per palette, on top of your own`,...t.startup?[`Edit ${Ct(pa(t.configHome),t.home)} — DefaultProfile; \`ttheme off\` puts yours back`]:[]]},notes:()=>[],next(t,e){let n=['Konsole profiles A "ttheme · <palette>" per palette in its profile list'];if(t.startup)n.push(e?.restart?`Restart Konsole New tabs open on "${ga(t.startup)}"`:`Konsole default "${ga(t.startup)}", which follows \`ttheme default\``);return n},unwire(t,e){let n=pa(t.configHome),r=at(n);return{edits:Kr(r,"Desktop Entry","DefaultProfile")?.startsWith(j(""))?[{file:n,content:Yk(r,e?.konsoleBase)}]:[],removals:[],touches:[]}},defaults:NA};import{createHash as AA}from"node:crypto";import{existsSync as ey,readdirSync as TA,readFileSync as HA,rmSync as CA}from"node:fs";import{join as Hi}from"node:path";var ny="com.apple.Terminal",ba="ttheme · ";function sn(t){return`${ba}${t}`}function Hu(t){return Hi(t,"ttheme","terminal-app.js")}function Qo(t){return Hi(t,"ttheme","terminal-app")}function LA(t,e){return Hi(t.XDG_STATE_HOME??Hi(e,".local","state"),"ttheme","terminal-app.window")}var FA=`ObjC.import('AppKit')
402
402
 
403
- const OURS = '${Qo}'
403
+ const OURS = '${ba}'
404
404
  const IMAGE = 'BackgroundImageBookmark'
405
405
  const KEYS = ['BackgroundColor', 'TextColor', 'CursorColor', 'SelectionColor', 'ANSIBlackColor', 'ANSIRedColor',
406
406
  'ANSIGreenColor', 'ANSIYellowColor', 'ANSIBlueColor', 'ANSIMagentaColor', 'ANSICyanColor', 'ANSIWhiteColor',
@@ -584,32 +584,32 @@ function run(argv) {
584
584
  }
585
585
  return changed ? 'wrote' : 'same'
586
586
  }
587
- `;function ph(t,e,n){return t.run("osascript",["-l","JavaScript",hu(e),...n])}function gh(t){return t.run("defaults",["read",ek,"Default Window Settings"])||void 0}function uT(t){return[t.background,t.foreground,t.cursor,t.selectionBackground,...t.ansi]}function nk(t){let e=new Set(Mt(t.entries).map((n)=>n.name));return t.themes.filter((n)=>e.has(n.name)||n.name===t.startup)}function bh(t,e){let n=gh(e);return t.terminalBase??(n&&!n.startsWith(Qo)?n:"Basic")}function wh(t,e){let n=/^(\d+)x(\d+)$/.exec(st(aT(t,e)).trim());return n?{width:Number(n[1])*2,height:Number(n[2])*2}:void 0}function $h(t,e,n,r){let i=r?.width??t,s=r?.height??e,o=Ut.indexOf(n.position)+1||5,a=ws(t,e,i,s,100,o,n.cover),c=Math.min(1,t/Math.max(1,a.w));return{width:Math.max(1,Math.round(i*c)),height:Math.max(1,Math.round(s*c)),at:{x:Math.round(a.x*c),y:Math.round(a.y*c),w:Math.round(a.w*c),h:Math.round(a.h*c)}}}var rk=/^ttheme-(.+)\.([0-9a-z-]+)\.png$/;function mu(t){let e=new Map;for(let n of tk(t)?iT(t):[]){let[,r]=rk.exec(n)??[];if(r)e.set(r,[...e.get(r)??[],n])}return e}function lT(t){return[...mu(t)].map(([e,n])=>`${e} ${(rk.exec(n[0])??[])[2]}`).sort().join(" ")}function Q$(t){let e=Fs(t.configHome),n=mu(e),r=wh(t.host.env,t.home),i=new Map,s=(o)=>{for(let a of o)oT(Ei(e,a),{force:!0})};for(let o of nk(t)){let a=n.get(Xt(o.name))??[];n.delete(Xt(o.name));let c=Se(q(t.configHome),o.name,t.home),u=c&&tk(c.image)?new Uint8Array(sT(c.image)):void 0,l=u&&un(u);if(!c||!u||!l||c.opacity<=0){s(a);continue}let f=$h(l.width,l.height,c,r),d=rT("sha1").update(u).update(JSON.stringify([o.background.toLowerCase(),c.opacity,f])).digest("hex").slice(0,8),h=`${H(o.name)}.${d}.png`,m=Ei(e,h);if(!a.includes(h)){let $;try{$=cr(ar(Ht(u),o.background,c.opacity,f))}catch{s(a);continue}let[g,...b]=a;if(g)Xr(Ei(e,g),m,$);else P(m,$);s(b)}else s(a.filter(($)=>$!==h));i.set(o.name,m)}for(let o of n.values())s(o);return i}function X$(t,e){ph(t.host,t.configHome,["write",bh(t.state,t.host),...nk(t).flatMap((n)=>[Qe(n.name),...uT(n),e.get(n.name)??"-"])])}var fT={key:"terminalBase",profile:Qe,base(t){let e=gh(t.host);return e&&!e.startsWith(Qo)?{...t.state,terminalBase:e}:t.state},point(t,e){let n=gh(t.host),r=n?.startsWith(Qo)===!0;if(t.state.palettes.length===0)ph(t.host,t.configHome,["drop"]);let i=t.startup?e||r?Qe(t.startup):void 0:r?bh(t.state,t.host):void 0;if(i===void 0||i===n&&!e)return;for(let o of["Default Window Settings","Startup Window Settings"])t.host.run("defaults",["write",ek,o,"-string",i]);return{restart:Boolean(t.host.run("pgrep",["-x","Terminal"]))&&ph(t.host,t.configHome,["loaded",i])!=="1"}}},ik={id:"terminal-app",name:"Terminal.app",emitter:eh,offered:(t,e)=>e.platform==="darwin",present:()=>!1,sync(t,e){e.write(hu(t.configHome),cT),X$(t,Q$(t))},pictures(t){X$(t,Q$(t))},layer:(t,e)=>({TTHEME_TERMINAL_APP_BASE:bh(t.state,e),TTHEME_TERMINAL_PICTURES:lT(Fs(t.configHome))}),plan:(t)=>[`Add a "${Qe("<palette>")}" profile per palette to Terminal.app's settings — a copy of your own profile in the palette's colors, with its picture`,...t.startup?[`Make "${Qe(t.startup)}" Terminal.app's default — \`ttheme off\` puts yours back`]:[]],notes:()=>[],next(t,e){let n=[`Terminal.app A "${Qe("<palette>")}" profile per palette in Settings › Profiles`];if(t.startup)n.push(e?.restart?`Restart Terminal New windows and tabs open on "${Qe(t.startup)}"`:`Terminal default "${Qe(t.startup)}", which follows \`ttheme default\``);return n},unwire:()=>({edits:[],removals:[],touches:[]}),defaults:fT};import{spawn as dT}from"node:child_process";import{existsSync as Hr,mkdirSync as hT,readdirSync as kh,readFileSync as yh,realpathSync as mT,rmSync as pT,writeFileSync as gT}from"node:fs";import{dirname as ck,join as xe}from"node:path";function Si(t){return process.platform==="darwin"?xe(t,".warp","themes"):xe(qo(t),"warp-terminal","themes")}function Fr(t,e){return process.platform==="darwin"?xe(t,".warp","settings.toml"):xe(e,"warp-terminal","settings.toml")}var pu='"dark"';function gu(t){return xe(t,"ttheme","warp.base")}var uk="[appearance.themes]";function lk(t){let e=t.findIndex((r)=>r.trim()===uk);if(e<0)return;let n=t.findIndex((r,i)=>i>e&&r.trimStart().startsWith("["));return[e,n<0?t.length:n]}function Cr(t){let e=t.split(`
588
- `),n=lk(e);if(!n)return;return e.slice(n[0]+1,n[1]).find((i)=>/^theme\s*=/.test(i))?.replace(/^theme\s*=\s*/,"").trim()}function Eh(t,e=`${H(t)}.yaml`){return`{ custom = { name = "${t}", path = "${e}" } }`}function bT(t){return t?.includes(`path = "${H("")}`)===!0?/name = "([^"]+)"/.exec(t)?.[1]:void 0}function bu(t,e){let n=t.split(`
589
- `),r=lk(n);if(!r)return e===void 0?t:`${t.replace(/\n*$/,`
587
+ `;function Vh(t,e,n){return t.run("osascript",["-l","JavaScript",Hu(e),...n])}function Zh(t){return t.run("defaults",["read",ny,"Default Window Settings"])||void 0}function jA(t){return[t.background,t.foreground,t.cursor,t.selectionBackground,...t.ansi]}function ry(t){let e=new Set(It(t.entries).map((n)=>n.name));return t.themes.filter((n)=>e.has(n.name)||n.name===t.startup)}function Qh(t,e){let n=Zh(e);return t.terminalBase??(n&&!n.startsWith(ba)?n:"Basic")}function Xh(t,e){let n=/^(\d+)x(\d+)$/.exec(at(LA(t,e)).trim());return n?{width:Number(n[1])*2,height:Number(n[2])*2}:void 0}function tm(t,e,n,r){let i=r?.width??t,o=r?.height??e,s=Ut.indexOf(n.position)+1||5,a=Ao(t,e,i,o,100,s,n.cover),c=Math.min(1,t/Math.max(1,a.w));return{width:Math.max(1,Math.round(i*c)),height:Math.max(1,Math.round(o*c)),at:{x:Math.round(a.x*c),y:Math.round(a.y*c),w:Math.round(a.w*c),h:Math.round(a.h*c)}}}var iy=/^ttheme-(.+)\.([0-9a-z-]+)\.png$/;function Cu(t){let e=new Map;for(let n of ey(t)?TA(t):[]){let[,r]=iy.exec(n)??[];if(r)e.set(r,[...e.get(r)??[],n])}return e}function _A(t){return[...Cu(t)].map(([e,n])=>`${e} ${(iy.exec(n[0])??[])[2]}`).sort().join(" ")}function Xk(t){let e=Qo(t.configHome),n=Cu(e),r=Xh(t.host.env,t.home),i=new Map,o=(s)=>{for(let a of s)CA(Hi(e,a),{force:!0})};for(let s of ry(t)){let a=n.get(oe(s.name))??[];n.delete(oe(s.name));let c=Oe(V(t.configHome),s.name,t.home),u=c&&ey(c.image)?new Uint8Array(HA(c.image)):void 0,l=u&&$n(u);if(!c||!u||!l||c.opacity<=0){o(a);continue}let d=tm(l.width,l.height,c,r),f=AA("sha1").update(u).update(JSON.stringify([s.background.toLowerCase(),c.opacity,d])).digest("hex").slice(0,8),h=`${j(s.name)}.${f}.png`,m=Hi(e,h);if(!a.includes(h)){let g;try{g=yr(kr(jt(u),s.background,c.opacity,d))}catch{o(a);continue}let[b,...w]=a;if(b)li(Hi(e,b),m,g);else F(m,g);o(w)}else o(a.filter((g)=>g!==h));i.set(s.name,m)}for(let s of n.values())o(s);return i}function ty(t,e){Vh(t.host,t.configHome,["write",Qh(t.state,t.host),...ry(t).flatMap((n)=>[sn(n.name),...jA(n),e.get(n.name)??"-"])])}var BA={key:"terminalBase",profile:sn,base(t){let e=Zh(t.host);return e&&!e.startsWith(ba)?{...t.state,terminalBase:e}:t.state},point(t,e){let n=Zh(t.host),r=n?.startsWith(ba)===!0;if(t.state.palettes.length===0)Vh(t.host,t.configHome,["drop"]);let i=t.startup?e||r?sn(t.startup):void 0:r?Qh(t.state,t.host):void 0;if(i===void 0||i===n&&!e)return;for(let s of["Default Window Settings","Startup Window Settings"])t.host.run("defaults",["write",ny,s,"-string",i]);return{restart:Boolean(t.host.run("pgrep",["-x","Terminal"]))&&Vh(t.host,t.configHome,["loaded",i])!=="1"}}},oy={id:"terminal-app",name:"Terminal.app",emitter:Lh,offered:(t,e)=>e.platform==="darwin",present:()=>!1,sync(t,e){e.write(Hu(t.configHome),FA),ty(t,Xk(t))},pictures(t){ty(t,Xk(t))},layer:(t,e)=>({TTHEME_TERMINAL_APP_BASE:Qh(t.state,e),TTHEME_TERMINAL_PICTURES:_A(Qo(t.configHome))}),plan:(t)=>[`Add a "${sn("<palette>")}" profile per palette to Terminal.app's settings — a copy of your own profile in the palette's colors, with its picture`,...t.startup?[`Make "${sn(t.startup)}" Terminal.app's default — \`ttheme off\` puts yours back`]:[]],notes:()=>[],next(t,e){let n=[`Terminal.app A "${sn("<palette>")}" profile per palette in Settings › Profiles`];if(t.startup)n.push(e?.restart?`Restart Terminal New windows and tabs open on "${sn(t.startup)}"`:`Terminal default "${sn(t.startup)}", which follows \`ttheme default\``);return n},unwire:()=>({edits:[],removals:[],touches:[]}),defaults:BA};import{spawn as GA}from"node:child_process";import{existsSync as zr,mkdirSync as UA,readdirSync as em,readFileSync as nm,realpathSync as WA,rmSync as KA,writeFileSync as zA}from"node:fs";import{dirname as uy,join as Ne}from"node:path";function Ci(t){return process.platform==="darwin"?Ne(t,".warp","themes"):Ne(fa(t),"warp-terminal","themes")}function Dr(t,e){return process.platform==="darwin"?Ne(t,".warp","settings.toml"):Ne(e,"warp-terminal","settings.toml")}var Lu='"dark"';function Fu(t){return Ne(t,"ttheme","warp.base")}var ly="[appearance.themes]";function dy(t){let e=t.findIndex((r)=>r.trim()===ly);if(e<0)return;let n=t.findIndex((r,i)=>i>e&&r.trimStart().startsWith("["));return[e,n<0?t.length:n]}function qr(t){let e=t.split(`
588
+ `),n=dy(e);if(!n)return;return e.slice(n[0]+1,n[1]).find((i)=>/^theme\s*=/.test(i))?.replace(/^theme\s*=\s*/,"").trim()}function im(t,e=`${j(t)}.yaml`){return`{ custom = { name = "${t}", path = "${e}" } }`}function DA(t){return t?.includes(`path = "${j("")}`)===!0?/name = "([^"]+)"/.exec(t)?.[1]:void 0}function ju(t,e){let n=t.split(`
589
+ `),r=dy(n);if(!r)return e===void 0?t:`${t.replace(/\n*$/,`
590
590
  `)}
591
- ${uk}
591
+ ${ly}
592
592
  theme = ${e}
593
- `;let i=n.findIndex((s,o)=>o>r[0]&&o<r[1]&&/^theme\s*=/.test(s));if(i>=0)n.splice(i,1,...e===void 0?[]:[`theme = ${e}`]);else if(e!==void 0)n.splice(r[0]+1,0,`theme = ${e}`);return n.join(`
594
- `)}function vh(t){return Cr(t)?.includes(`path = "${H("")}`)===!0}var wT="setTimeout(() => { const fs = require('node:fs'); const [file, next, seen, theme] = process.argv.slice(-4); if (fs.readFileSync(file, 'utf8') !== seen || !fs.existsSync(theme)) return; const tmp = file + '.ttheme-' + process.pid; fs.writeFileSync(tmp, next); fs.chmodSync(tmp, fs.statSync(file).mode & 0o7777); fs.renameSync(tmp, file) }, 500)";function fk(t,e,n){return{image:xe(t,S$(e.name,n.image,e.background)),opacity:n.opacity}}function sk(t){let e=Si(t.home),n=q(t.configHome),r=new Map,i=new Set;for(let s of t.themes){let o=Se(n,s.name,t.home),a=Yo(s.name,o&&fk(e,s,o));r.set(s.name,a);for(let c of new Set([a,Yo(s.name)]))if(!Hr(xe(e,c)))i.add(c)}return{files:r,fresh:i}}function ok(t,e,n){let r=Si(t.home),i=q(t.configHome),s=new Set(n.values()),o=Cr(st(Fr(t.home,t.configHome)))??"";for(let u of t.themes){let l=Se(i,u.name,t.home),f=n.get(u.name);if(l&&f){let d=fk(r,u,l);if(!Hr(d.image))try{let h=Ht(new Uint8Array(yh(l.image)));P(d.image,cr(ar(h,u.background,1)))}catch{n.set(u.name,Yo(u.name));continue}e.write(xe(r,f),Jo(u,d))}}if(!Hr(r))return;let a=(u,l)=>u.startsWith(H(""))&&new RegExp(`\\.[0-9a-f]{8}\\.${l}$`).test(u);for(let u of kh(r))if(a(u,"yaml")&&!s.has(u)&&!o.includes(`path = "${u}"`))e.remove(xe(r,u));let c=new Set;for(let u of kh(r)){let l=u.startsWith(H(""))&&u.endsWith(".yaml")?/^ {2}path: "(.+)"$/m.exec(st(xe(r,u)))?.[1]:void 0;if(l)c.add(l)}for(let u of kh(r))if(a(u,"png")&&!c.has(xe(r,u)))e.remove(xe(r,u))}function $T(t,e){let n=process.env.TTHEME_WARP_WEARS;return t!==void 0&&n!==void 0&&e.files.has(n)?n:t}function ak(t,e,n,r=!1){let i=Fr(t.home,t.configHome);if(!Hr(i))return;let s=gu(t.configHome),o=yh(i,"utf8"),a=r?bT(Cr(o)):e;if(r&&(a===void 0||!n.files.has(a)))return;let c;if(a){if(!vh(o)&&!Hr(s))hT(ck(s),{recursive:!0}),gT(s,Cr(o)??"");c=Eh(a,n.files.get(a))}else{if(!vh(o))return;c=Hr(s)&&yh(s,"utf8")||pu,pT(s,{force:!0})}let u=bu(o,c);if(u===o)return;let l=a===void 0?void 0:n.files.get(a)??`${H(a)}.yaml`;if(l!==void 0&&n.fresh.has(l))Dl(i),dT(process.execPath,["-e",wT,mT(i),u,o,xe(Si(t.home),l)],{detached:!0,stdio:"ignore"}).unref();else an(i,u);return i}var Sh={id:"warp",name:"Warp",emitter:nh,shelf:{from:"themes",dir:(t)=>Si(t.home)},bakes:!0,offered:(t,e)=>e.platform!=="win32",present:(t)=>Hr(ck(Si(t.home))),sync(t,e){let n=sk(t);e.themes(Sh),ok(t,e,n.files);let r=ak(t,$T(t.startup,n),n);if(r)e.note(r)},pictures(t,e){let n=sk(t);ok(t,e,n.files),ak(t,void 0,n,!0)},plan(t){let e=Fr(t.home,t.configHome);return t.startup&&Hr(e)?[`Edit ${Tt(e,t.home)} — [appearance.themes] theme; \`ttheme off\` puts yours back`]:[]},notes:()=>["Warp wears one theme for the whole app, set through its settings.toml — a tab that takes a palette (`ttheme use`, a pin, preview) switches it, and switching tabs puts on the palette of the tab in front, read from Warp’s session database with sqlite3"],next:()=>[],unwire(t){let e=Fr(t.home,t.configHome),n=st(e);return{edits:vh(n)?[{file:e,content:bu(n,st(gu(t.configHome))||pu)}]:[],removals:[],touches:[]}}};import{existsSync as ku}from"node:fs";import{join as Cs}from"node:path";var dk=/-- ttheme begin\n[\s\S]*?-- ttheme end\n?/,kT=/^return config[ \t]*$/gm;function yT(t){return`dofile(${JSON.stringify(t)})(config)`}var mk=`local wezterm = require 'wezterm'
593
+ `;let i=n.findIndex((o,s)=>s>r[0]&&s<r[1]&&/^theme\s*=/.test(o));if(i>=0)n.splice(i,1,...e===void 0?[]:[`theme = ${e}`]);else if(e!==void 0)n.splice(r[0]+1,0,`theme = ${e}`);return n.join(`
594
+ `)}function rm(t){return qr(t)?.includes(`path = "${j("")}`)===!0}var qA="setTimeout(() => { const fs = require('node:fs'); const [file, next, seen, theme] = process.argv.slice(-4); if (fs.readFileSync(file, 'utf8') !== seen || !fs.existsSync(theme)) return; const tmp = file + '.ttheme-' + process.pid; fs.writeFileSync(tmp, next); fs.chmodSync(tmp, fs.statSync(file).mode & 0o7777); fs.renameSync(tmp, file) }, 500)";function fy(t,e,n){return{image:Ne(t,Mk(e.name,n.image,e.background)),opacity:n.opacity}}function sy(t){let e=Ci(t.home),n=V(t.configHome),r=new Map,i=new Set;for(let o of t.themes){let s=Oe(n,o.name,t.home),a=ha(o.name,s&&fy(e,o,s));r.set(o.name,a);for(let c of new Set([a,ha(o.name)]))if(!zr(Ne(e,c)))i.add(c)}return{files:r,fresh:i}}function ay(t,e,n){let r=Ci(t.home),i=V(t.configHome),o=new Set(n.values()),s=qr(at(Dr(t.home,t.configHome)))??"";for(let u of t.themes){let l=Oe(i,u.name,t.home),d=n.get(u.name);if(l&&d){let f=fy(r,u,l);if(!zr(f.image))try{let h=jt(new Uint8Array(nm(l.image)));F(f.image,yr(kr(h,u.background,1)))}catch{n.set(u.name,ha(u.name));continue}e.write(Ne(r,d),ma(u,f))}}if(!zr(r))return;let a=(u,l)=>u.startsWith(j(""))&&new RegExp(`\\.[0-9a-f]{8}\\.${l}$`).test(u);for(let u of em(r))if(a(u,"yaml")&&!o.has(u)&&!s.includes(`path = "${u}"`))e.remove(Ne(r,u));let c=new Set;for(let u of em(r)){let l=u.startsWith(j(""))&&u.endsWith(".yaml")?/^ {2}path: "(.+)"$/m.exec(at(Ne(r,u)))?.[1]:void 0;if(l)c.add(l)}for(let u of em(r))if(a(u,"png")&&!c.has(Ne(r,u)))e.remove(Ne(r,u))}function YA(t,e){let n=process.env.TTHEME_WARP_WEARS;return t!==void 0&&n!==void 0&&e.files.has(n)?n:t}function cy(t,e,n,r=!1){let i=Dr(t.home,t.configHome);if(!zr(i))return;let o=Fu(t.configHome),s=nm(i,"utf8"),a=r?DA(qr(s)):e;if(r&&(a===void 0||!n.files.has(a)))return;let c;if(a){if(!rm(s)&&!zr(o))UA(uy(o),{recursive:!0}),zA(o,qr(s)??"");c=im(a,n.files.get(a))}else{if(!rm(s))return;c=zr(o)&&nm(o,"utf8")||Lu,KA(o,{force:!0})}let u=ju(s,c);if(u===s)return;let l=a===void 0?void 0:n.files.get(a)??`${j(a)}.yaml`;if(l!==void 0&&n.fresh.has(l))Md(i),GA(process.execPath,["-e",qA,WA(i),u,s,Ne(Ci(t.home),l)],{detached:!0,stdio:"ignore"}).unref();else bn(i,u);return i}var om={id:"warp",name:"Warp",emitter:Fh,shelf:{from:"themes",dir:(t)=>Ci(t.home)},bakes:!0,offered:(t,e)=>e.platform!=="win32",present:(t)=>zr(uy(Ci(t.home))),sync(t,e){let n=sy(t);e.themes(om),ay(t,e,n.files);let r=cy(t,YA(t.startup,n),n);if(r)e.note(r)},pictures(t,e){let n=sy(t);ay(t,e,n.files),cy(t,void 0,n,!0)},plan(t){let e=Dr(t.home,t.configHome);return t.startup&&zr(e)?[`Edit ${Ct(e,t.home)} — [appearance.themes] theme; \`ttheme off\` puts yours back`]:[]},notes:()=>["Warp wears one theme for the whole app, set through its settings.toml — a tab that takes a palette (`ttheme use`, a pin, preview) switches it, and switching tabs puts on the palette of the tab in front, read from Warp’s session database with sqlite3"],next:()=>[],unwire(t){let e=Dr(t.home,t.configHome),n=at(e);return{edits:rm(n)?[{file:e,content:ju(n,at(Fu(t.configHome))||Lu)}]:[],removals:[],touches:[]}}};import{existsSync as Gu}from"node:fs";import{join as Xo}from"node:path";var hy=/-- ttheme begin\n[\s\S]*?-- ttheme end\n?/,JA=/^return config[ \t]*$/gm;function VA(t){return`dofile(${JSON.stringify(t)})(config)`}var py=`local wezterm = require 'wezterm'
595
595
  local config = wezterm.config_builder()
596
596
 
597
- `;function vT(t){let e=t.replace(/-- ttheme begin\n[\s\S]*?-- ttheme end\n\n?/,"");return e===`${mk}return config
598
- `?"":e}function Mh(t,e){let n=`-- ttheme begin
597
+ `;function ZA(t){let e=t.replace(/-- ttheme begin\n[\s\S]*?-- ttheme end\n\n?/,"");return e===`${py}return config
598
+ `?"":e}function sm(t,e){let n=`-- ttheme begin
599
599
  ${e}
600
600
  -- ttheme end
601
- `;if(dk.test(t))return t.replace(dk,n);if(t==="")return`${mk}${n}
601
+ `;if(hy.test(t))return t.replace(hy,n);if(t==="")return`${py}${n}
602
602
  return config
603
- `;let r=[...t.matchAll(kT)].at(-1);if(r?.index===void 0)return;return`${t.slice(0,r.index)}${n}
604
- ${t.slice(r.index)}`}function wu(t,e){let n=Cs(e,".wezterm.lua");return ku(n)?n:Cs(t,"wezterm","wezterm.lua")}function hk(t){return Cs(t.configHome,"wezterm","colors")}function $u(t){return Cs(t.configHome,"ttheme","wezterm.lua")}var Oh={id:"wezterm",name:"WezTerm",emitter:rh,shelf:{from:"colors",dir:hk},offered:()=>!0,present:(t)=>ku(Cs(t.configHome,"wezterm"))||ku(Cs(t.home,".wezterm.lua")),sync(t,e){e.themes(Oh),e.write($u(t),x$({path:$u(t),colors:hk(t),backgrounds:q(t.configHome),...t.startup?{startup:t.startup}:{},palettes:t.themes}));let n=wu(t.configHome,t.home),r=Mh(st(n),yT($u(t)));if(r!==void 0)e.wire(n,r)},plan(t){let e=wu(t.configHome,t.home);return Mh(st(e),"")!==void 0?[`Edit ${Tt(e,t.home)} — a ttheme block before \`return config\`: color_scheme_dirs, color_scheme, pictures`]:[]},notes(t){let e=wu(t.configHome,t.home);return ku(e)&&Mh(st(e),"")===void 0?[`${e} has no \`return config\` line — ttheme left it alone; call \`dofile("${$u(t)}")(config)\` from it yourself`]:[]},next:()=>["WezTerm Reloads its config by itself"],unwire:(t)=>({edits:wn(wu(t.configHome,t.home),vT),removals:[],touches:[]})};import{existsSync as gk,readFileSync as ET,utimesSync as ST}from"node:fs";import{dirname as MT,join as yu}from"node:path";function xh(t){return yu(t,"Microsoft","Windows Terminal","Fragments","ttheme","ttheme.json")}function pk(t){return[yu(t,"Packages","Microsoft.WindowsTerminal_8wekyb3d8bbwe","LocalState","settings.json"),yu(t,"Packages","Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe","LocalState","settings.json"),yu(t,"Microsoft","Windows Terminal","settings.json")].filter((e)=>gk(e))}function OT(t){for(let e of t){let n=/"defaultProfile"\s*:\s*"(\{[0-9a-fA-F-]+\})"/.exec(ET(e,"utf8"))?.[1];if(n)return n}return}function bk(t){if(t.platform==="win32")return t.env.LOCALAPPDATA;if(!t.env.WSL_DISTRO_NAME)return;let e=t.run("cmd.exe",["/d","/c","echo %LOCALAPPDATA%"]);return e&&t.run("wslpath",["-u",e])||void 0}var wk={id:"windows-terminal",name:"Windows Terminal",emitter:sh,offered:(t)=>t.wtHome!==void 0,present:(t)=>t.wtHome!==void 0,installs:(t)=>({wtHome:t.wtHome,wtProfile:t.wtProfile}),sync(t,e){let{wtHome:n,wtProfile:r}=t.state;if(!n)return;let i=pk(n);if(e.write(xh(n),ih(t.themes,r??OT(i),t.startup))){let s=new Date;for(let o of i)ST(o,s,s);if(i.length>0)e.repaint()}},plan:(t)=>t.state.wtHome?[`Write ${xh(t.state.wtHome)} — its schemes, and touch settings.json so it reloads`]:[],notes:(t)=>t.state.wtHome?[]:["Windows Terminal: %LOCALAPPDATA% was not found — drop the release fragment into its Fragments folder yourself"],next:()=>["Windows Terminal Reloads its settings by itself"],unwire(t,e){let n=e?.wtHome,r=n?MT(xh(n)):void 0;return{edits:[],removals:r&&gk(r)?[r]:[],touches:n?pk(n):[]}}};var $n={ghostty:ch,kitty:dh,alacritty:ah,wezterm:Oh,iterm2:G$,"windows-terminal":wk,warp:Sh,konsole:Z$,"terminal-app":ik};function pt(t=qt){return t.map((e)=>$n[e])}function Oi(t){return t.startup&&t.palettes.includes(t.startup)?t.startup:t.palettes[0]}function Ie(t){return t.off?void 0:Oi(t)}function J(){return process.env.XDG_CONFIG_HOME??Ls(Xe(),".config")}var Mi=(t)=>typeof t==="string"&&t!==""?t:void 0,xT={author:Mi,startup:Mi,off:(t)=>t?!0:void 0,itermBase:Mi,konsoleBase:Mi,terminalBase:Mi,wtHome:Mi,wtProfile:Mi,markets:(t)=>Array.isArray(t)?t.filter((e)=>typeof e==="string"):void 0,updates:(t)=>t&&typeof t==="object"?Object.fromEntries(Object.entries(t).filter((e)=>typeof e[1]==="boolean")):void 0};function L(t){let e=Hn(t);if(!vu(e))throw Error(`nothing installed yet at ${e} — run \`ttheme init\` first`);let n=JSON.parse($k(e,"utf8"));if(!Array.isArray(n?.palettes)||!Array.isArray(n.terminals))throw Error(`${e} has no palettes or terminals`);return{terminals:n.terminals.filter((r)=>qt.includes(r)),...Object.fromEntries(Object.entries(xT).flatMap(([r,i])=>{let s=i(n[r]);return s===void 0?[]:[[r,s]]})),palettes:n.palettes}}function Le(t,e){P(Hn(t),`${JSON.stringify(e,null,2)}
605
- `)}function kk(t,e){let n=new Map(t.palettes.map((i)=>[i.name,i])),r=e.filter((i)=>!n.has(i));if(r.length>0){let i=[...new Set(r.flatMap((o)=>lt(o)??[]))].filter((o)=>!t.palettes.some((a)=>lt(a.name)===o)),s=i.length>0?`add ${i.join(", ")} first — \`ttheme market search\` finds a market's repository`:md(Mt(t.palettes),r);throw Error(`not in any market: ${r.join(", ")} — ${s}`)}return t.palettes.filter((i)=>e.includes(i.name))}function Xo(t,e,n){return{configHome:t,home:n,state:e,startup:Ie(e)}}function yk(t,e,n,r,i){return{...Xo(t,n,r),entries:e,themes:e.map(De),host:i}}function vk(t){let e=[],n={written:e,repainted:!1,write(r,i){if(e.push(r),vu(r)&&$k(r,"utf8")===i)return!1;return P(r,i),!0},wire(r,i){e.push(r),an(r,i)},note(r){e.push(r)},remove(r){Ih(r,{force:!0})},themes(r){let i=r.shelf?.dir(t);if(!i)return;for(let s of t.themes)for(let{file:o,content:a}of Jd(r,s))n.write(Ls(i,o),a)},repaint(){n.repainted=!0}};return n}function IT(t,e){return Object.assign({},...pt(t.state.terminals).map((n)=>n.layer?.(t,e)??{}))}function jt(t,e,n,r=Xe(),i=Ze()){kt(q(t));let s=kk(gi(t,e),n.palettes),o=Mc(s,pn(t));Hw(t,new Map(o.map((u)=>[u.name,br(u)]))),yw(t),Ic(t,s);let a=yk(t,o,n,r,i),c=vk(a);for(let u of pt(n.terminals))u.sync(a,c);return c.written.push(Mk(a,i,c.repainted)),Sk(t,o,r),c.written}function Ek(t,e=Xe()){if(!vu(Ls(t,"ttheme","palettes.zsh")))return;let n=new Set(L(t).palettes);Sk(t,ue(t).palettes.filter((r)=>n.has(r.name)),e)}function Sk(t,e,n){let r=Ls(t,"ttheme","aliases.zsh"),i=p$(RT(e,n));if(st(r)!==i)P(r,i)}function RT(t,e){let n=t.flatMap((s)=>s.booru?[s.booru]:[]),r=Vf(n,e),i={};for(let s of t){let o=new Set(s.nativeNames??[]),a=(s.booru?r.get(s.booru)??[]:[]).filter((c)=>!o.has(c));if(a.length>0)i[s.name]=a}return i}function Mk(t,e,n){let r=Ls(t.configHome,"ttheme","palettes.zsh"),i=qd(t.entries,t.startup,t.state.terminals,IT(t,e));if(n||st(r)!==i)P(r,i),Ih(`${r}.zwc`,{force:!0});return r}function Re(t,e=Xe(),n=Ze()){let r=L(t),i=pt(r.terminals).filter((a)=>a.pictures);if(i.length===0)return;let s=yk(t,kk(ue(t),r.palettes),r,e,n),o=vk(s);for(let a of i)a.pictures?.(s,o);Mk(s,n,!1)}function xi(t){return!pt(t).some((e)=>e.bakes)}function Eu(t,e,n=Xe()){let r=Xo(t,e,n);return pt(e.terminals).flatMap((i)=>[...i.shelf?[`Write ${Tt(i.shelf.dir(r),n)}/${H("*")} — a theme file per palette`]:[],...i.plan(r)])}function Su(t,e,n=Xe()){let r=Xo(t,e,n);return pt(e.terminals).flatMap((i)=>i.notes(r))}function Mu(t,e,n,r=Xe()){let i=Xo(t,e,r);return pt(e.terminals).flatMap((s)=>s.next(i,n.get(s.id)))}function js(t,e,n,r,i=Xe()){let s=[],o=Ot(t,e,!1).palettes;for(let a of pt(n)){let c=a.shelf?.dir({configHome:t,home:i});for(let u of c?o.filter((l)=>r.includes(l.name)):[])for(let{file:l}of Jd(a,De(u))){let f=Ls(c,l);if(vu(f))Ih(f,{force:!0}),s.push(f)}}return s}function Ok(t,e,n,r){return{...Xo(t,e,r),host:n}}function ta(t,e,n,r=Xe()){return pt(e.terminals).reduce((i,s)=>s.defaults?.base(Ok(t,i,n,r))??i,e)}function Ii(t,e,n,r,i=Xe()){let s=new Map;for(let o of pt(e.terminals)){let a=o.defaults?.point(Ok(t,e,r,i),n);if(a)s.set(o.id,a)}return s}function je(t,e,n,r,i=!1,s=Ze(),o=Xe()){let a=i||!Ie(n)&&Ie(r)!==void 0,c=a?ta(t,r,s,o):r;return jt(t,e,c,o,s),Le(t,c),a||Ie(n)!==Ie(r)?Ii(t,c,a,s,o):new Map}import{performance as xk}from"node:perf_hooks";var NT=16,Rh=80,Ik="\x1B[?2026h",Rk="\x1B[?2026l";class Ri{shown=[];pointer=new jo;cursor="";wipe="";immediate;delayed;ticker;last=Number.NEGATIVE_INFINITY;stopped=!1;write;view;beat;constructor(t){this.write=t.write,this.view=t.view,this.beat=t.beat??(()=>{})}request(){if(this.stopped||this.immediate||this.delayed)return;let t=this.last+NT-xk.now();if(t>0)this.delayed=setTimeout(this.paint,t);else this.immediate=setImmediate(this.paint)}soon(){if(this.stopped||this.immediate)return;clearTimeout(this.delayed),this.delayed=void 0,this.immediate=setImmediate(this.paint)}now(){this.cancel(),this.paint()}reset(t=""){this.shown=[],this.cursor="",this.wipe=t}stop(){this.stopped=!0,this.cancel(),clearInterval(this.ticker),this.ticker=void 0}point(t){return this.pointer.point(t)}drop(){this.pointer.drop()}cancel(){clearImmediate(this.immediate),clearTimeout(this.delayed),this.immediate=void 0,this.delayed=void 0}paint=()=>{if(this.immediate=void 0,this.delayed=void 0,this.stopped)return;let{drawn:t,targets:e}=Ac(()=>this.view());if(!t)return;this.last=xk.now();let{lines:n,zones:r}=Pc(t.lines,e);this.pointer.zones=[...t.zones??[],...r];let i=this.wipe;this.wipe="";let s=new Set,o=Math.max(n.length,this.shown.length);for(let l=0;l<o;l++){let f=n[l];if(f!==this.shown[l])i+=`\x1B[${l+1};1H\x1B[0m\x1B[2K${f??""}`,s.add(l)}this.shown=n;let a=t.after?.(s)??"",c=t.cursor??"",u=c!==""&&(i!==""||a!==""||c!==this.cursor);if(this.cursor=c,i||a||u)this.write(`${Ik}${i}${a}\x1B[0m${u?c:""}${Rk}`);this.tick(t.ticking===!0)};tick(t){if(t&&!this.ticker)this.ticker=setInterval(()=>{this.beat(),this.request()},Rh);else if(!t&&this.ticker)clearInterval(this.ticker),this.ticker=void 0}}class Nh{shown=[];write;cols;constructor(t,e){this.write=t,this.cols=e}draw(t){this.put(t,"")}redraw(t){let e=`${this.shown.length>1?`\x1B[${this.shown.length-1}A`:""}${this.shown.length>0?"\r\x1B[J":""}`;this.shown=[],this.put(t,e)}end(t){this.put(t,""),this.write(`
606
- `),this.shown=[]}put(t,e){let n=t.map((s)=>ot(s,this.cols()-1,!1)),r=0;while(r<n.length&&r<this.shown.length&&n[r]===this.shown[r])r++;if(r===n.length&&n.length===this.shown.length)return;if(r===n.length)r=Math.max(0,n.length-1);let i="";if(this.shown.length===0)i=n.join(`
603
+ `;let r=[...t.matchAll(JA)].at(-1);if(r?.index===void 0)return;return`${t.slice(0,r.index)}${n}
604
+ ${t.slice(r.index)}`}function _u(t,e){let n=Xo(e,".wezterm.lua");return Gu(n)?n:Xo(t,"wezterm","wezterm.lua")}function my(t){return Xo(t.configHome,"wezterm","colors")}function Bu(t){return Xo(t.configHome,"ttheme","wezterm.lua")}var am={id:"wezterm",name:"WezTerm",emitter:jh,shelf:{from:"colors",dir:my},offered:()=>!0,present:(t)=>Gu(Xo(t.configHome,"wezterm"))||Gu(Xo(t.home,".wezterm.lua")),sync(t,e){e.themes(am),e.write(Bu(t),Ik({path:Bu(t),colors:my(t),backgrounds:V(t.configHome),...t.startup?{startup:t.startup}:{},palettes:t.themes}));let n=_u(t.configHome,t.home),r=sm(at(n),VA(Bu(t)));if(r!==void 0)e.wire(n,r)},plan(t){let e=_u(t.configHome,t.home);return sm(at(e),"")!==void 0?[`Edit ${Ct(e,t.home)} — a ttheme block before \`return config\`: color_scheme_dirs, color_scheme, pictures`]:[]},notes(t){let e=_u(t.configHome,t.home);return Gu(e)&&sm(at(e),"")===void 0?[`${e} has no \`return config\` line — ttheme left it alone; call \`dofile("${Bu(t)}")(config)\` from it yourself`]:[]},next:()=>["WezTerm Reloads its config by itself"],unwire:(t)=>({edits:xn(_u(t.configHome,t.home),ZA),removals:[],touches:[]})};import{existsSync as by,readFileSync as QA,utimesSync as XA}from"node:fs";import{dirname as tT,join as Uu}from"node:path";function cm(t){return Uu(t,"Microsoft","Windows Terminal","Fragments","ttheme","ttheme.json")}function gy(t){return[Uu(t,"Packages","Microsoft.WindowsTerminal_8wekyb3d8bbwe","LocalState","settings.json"),Uu(t,"Packages","Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe","LocalState","settings.json"),Uu(t,"Microsoft","Windows Terminal","settings.json")].filter((e)=>by(e))}function eT(t){for(let e of t){let n=/"defaultProfile"\s*:\s*"(\{[0-9a-fA-F-]+\})"/.exec(QA(e,"utf8"))?.[1];if(n)return n}return}function wy(t){if(t.platform==="win32")return t.env.LOCALAPPDATA;if(!t.env.WSL_DISTRO_NAME)return;let e=t.run("cmd.exe",["/d","/c","echo %LOCALAPPDATA%"]);return e&&t.run("wslpath",["-u",e])||void 0}var $y={id:"windows-terminal",name:"Windows Terminal",emitter:Bh,offered:(t)=>t.wtHome!==void 0,present:(t)=>t.wtHome!==void 0,installs:(t)=>({wtHome:t.wtHome,wtProfile:t.wtProfile}),sync(t,e){let{wtHome:n,wtProfile:r}=t.state;if(!n)return;let i=gy(n);if(e.write(cm(n),_h(t.themes,r??eT(i),t.startup))){let o=new Date;for(let s of i)XA(s,o,o);if(i.length>0)e.repaint()}},plan:(t)=>t.state.wtHome?[`Write ${cm(t.state.wtHome)} — its schemes, and touch settings.json so it reloads`]:[],notes:(t)=>t.state.wtHome?[]:["Windows Terminal: %LOCALAPPDATA% was not found — drop the release fragment into its Fragments folder yourself"],next:()=>["Windows Terminal Reloads its settings by itself"],unwire(t,e){let n=e?.wtHome,r=n?tT(cm(n)):void 0;return{edits:[],removals:r&&by(r)?[r]:[],touches:n?gy(n):[]}}};var On={ghostty:Wh,kitty:qh,alacritty:Uh,wezterm:am,iterm2:Gk,"windows-terminal":$y,warp:om,konsole:Qk,"terminal-app":oy};function $t(t=Zt){return t.map((e)=>On[e])}function Fi(t){return t.startup&&t.palettes.includes(t.startup)?t.startup:t.palettes[0]}function Ae(t){return t.off?void 0:Fi(t)}function Q(){return process.env.XDG_CONFIG_HOME??ts(an(),".config")}var Li=(t)=>typeof t==="string"&&t!==""?t:void 0,nT={author:Li,startup:Li,off:(t)=>t?!0:void 0,itermBase:Li,konsoleBase:Li,terminalBase:Li,wtHome:Li,wtProfile:Li,markets:(t)=>Array.isArray(t)?t.filter((e)=>typeof e==="string"):void 0,updates:(t)=>t&&typeof t==="object"?Object.fromEntries(Object.entries(t).filter((e)=>typeof e[1]==="boolean")):void 0};function W(t){let e=Dn(t);if(!Wu(e))throw Error(`nothing installed yet at ${e} — run \`ttheme init\` first`);let n=JSON.parse(ky(e,"utf8"));if(!Array.isArray(n?.palettes)||!Array.isArray(n.terminals))throw Error(`${e} has no palettes or terminals`);return{terminals:n.terminals.filter((r)=>Zt.includes(r)),...Object.fromEntries(Object.entries(nT).flatMap(([r,i])=>{let o=i(n[r]);return o===void 0?[]:[[r,o]]})),palettes:n.palettes}}function We(t,e){F(Dn(t),`${JSON.stringify(e,null,2)}
605
+ `)}function yy(t,e){let n=new Map(t.palettes.map((i)=>[i.name,i])),r=e.filter((i)=>!n.has(i));if(r.length>0){let i=[...new Set(r.flatMap((s)=>lt(s)??[]))].filter((s)=>!t.palettes.some((a)=>lt(a.name)===s)),o=i.length>0?`add ${i.join(", ")} first — \`ttheme market search\` finds a market's repository`:qf(It(t.palettes),r);throw Error(`not in any market: ${r.join(", ")} — ${o}`)}return t.palettes.filter((i)=>e.includes(i.name))}function wa(t,e,n){return{configHome:t,home:n,state:e,startup:Ae(e)}}function vy(t,e,n,r,i){return{...wa(t,n,r),entries:e,themes:e.map(Ie),host:i}}function Sy(t){let e=[],n={written:e,repainted:!1,write(r,i){if(e.push(r),Wu(r)&&ky(r,"utf8")===i)return!1;return F(r,i),!0},wire(r,i){e.push(r),bn(r,i)},note(r){e.push(r)},remove(r){um(r,{force:!0})},themes(r){let i=r.shelf?.dir(t);if(!i)return;for(let o of t.themes)for(let{file:s,content:a}of Ph(r,o))n.write(ts(i,s),a)},repaint(){n.repainted=!0}};return n}function rT(t,e){return Object.assign({},...$t(t.state.terminals).map((n)=>n.layer?.(t,e)??{}))}function qt(t,e,n,r=an(),i=on()){Ot(V(t));let o=yy(Go(t,e),n.palettes),s=Zc(o,qn(t));R0(t,new Map(s.map((u)=>[u.name,Ro(u)]))),w0(t),tu(t,o);let a=vy(t,s,n,r,i),c=Sy(a);for(let u of $t(n.terminals))u.sync(a,c);return c.written.push(xy(a,i,c.repainted)),My(t,s,r),c.written}function Ey(t,e=an()){if(!Wu(ts(t,"ttheme","palettes.zsh")))return;let n=new Set(W(t).palettes);My(t,he(t).palettes.filter((r)=>n.has(r.name)),e)}function My(t,e,n){let r=ts(t,"ttheme","aliases.zsh"),i=gk(iT(e,n));if(at(r)!==i)F(r,i)}function iT(t,e){let n=t.flatMap((o)=>o.booru?[o.booru]:[]),r=Rf(n,e),i={};for(let o of t){let s=new Set(o.nativeNames??[]),a=(o.booru?r.get(o.booru)??[]:[]).filter((c)=>!s.has(c));if(a.length>0)i[o.name]=a}return i}function xy(t,e,n){let r=ts(t.configHome,"ttheme","palettes.zsh"),i=Ih(t.entries,t.startup,t.state.terminals,rT(t,e));if(n||at(r)!==i)F(r,i),um(`${r}.zwc`,{force:!0});return r}function Te(t,e=an(),n=on()){let r=W(t),i=$t(r.terminals).filter((a)=>a.pictures);if(i.length===0)return;let o=vy(t,yy(he(t),r.palettes),r,e,n),s=Sy(o);for(let a of i)a.pictures?.(o,s);xy(o,n,!1)}function ji(t){return!$t(t).some((e)=>e.bakes)}function Ku(t,e,n=an()){let r=wa(t,e,n);return $t(e.terminals).flatMap((i)=>[...i.shelf?[`Write ${Ct(i.shelf.dir(r),n)}/${j("*")} — a theme file per palette`]:[],...i.plan(r)])}function zu(t,e,n=an()){let r=wa(t,e,n);return $t(e.terminals).flatMap((i)=>i.notes(r))}function Du(t,e,n,r=an()){let i=wa(t,e,r);return $t(e.terminals).flatMap((o)=>o.next(i,n.get(o.id)))}function es(t,e,n,r,i=an()){let o=[],s=Rt(t,e,!1).palettes;for(let a of $t(n)){let c=a.shelf?.dir({configHome:t,home:i});for(let u of c?s.filter((l)=>r.includes(l.name)):[])for(let{file:l}of Ph(a,Ie(u))){let d=ts(c,l);if(Wu(d))um(d,{force:!0}),o.push(d)}}return o}function Oy(t,e,n,r){return{...wa(t,e,r),host:n}}function $a(t,e,n,r=an()){return $t(e.terminals).reduce((i,o)=>o.defaults?.base(Oy(t,i,n,r))??i,e)}function _i(t,e,n,r,i=an()){let o=new Map;for(let s of $t(e.terminals)){let a=s.defaults?.point(Oy(t,e,r,i),n);if(a)o.set(s.id,a)}return o}function Ke(t,e,n,r,i=!1,o=on(),s=an()){let a=i||!Ae(n)&&Ae(r)!==void 0,c=a?$a(t,r,o,s):r;return qt(t,e,c,s,o),We(t,c),a||Ae(n)!==Ae(r)?_i(t,c,a,o,s):new Map}import{performance as Iy}from"node:perf_hooks";var oT=16,lm=80,Ry="\x1B[?2026h",Py="\x1B[?2026l";class Bi{shown=[];pointer=new Jf;cursor="";wipe="";immediate;delayed;ticker;last=Number.NEGATIVE_INFINITY;stopped=!1;write;view;beat;constructor(t){this.write=t.write,this.view=t.view,this.beat=t.beat??(()=>{})}request(){if(this.stopped||this.immediate||this.delayed)return;let t=this.last+oT-Iy.now();if(t>0)this.delayed=setTimeout(this.paint,t);else this.immediate=setImmediate(this.paint)}soon(){if(this.stopped||this.immediate)return;clearTimeout(this.delayed),this.delayed=void 0,this.immediate=setImmediate(this.paint)}now(){this.cancel(),this.paint()}reset(t=""){this.shown=[],this.cursor="",this.wipe=t}stop(){this.stopped=!0,this.cancel(),clearInterval(this.ticker),this.ticker=void 0}point(t){return this.pointer.point(t)}drop(){this.pointer.drop()}cancel(){clearImmediate(this.immediate),clearTimeout(this.delayed),this.immediate=void 0,this.delayed=void 0}paint=()=>{if(this.immediate=void 0,this.delayed=void 0,this.stopped)return;let{drawn:t,targets:e}=S$(()=>this.view());if(!t)return;this.last=Iy.now();let{lines:n,zones:r}=x$(t.lines,e);this.pointer.zones=[...t.zones??[],...r];let i=this.wipe;this.wipe="";let o=new Set,s=Math.max(n.length,this.shown.length);for(let l=0;l<s;l++){let d=n[l];if(d!==this.shown[l])i+=`\x1B[${l+1};1H\x1B[0m\x1B[2K${d??""}`,o.add(l)}this.shown=n;let a=t.after?.(o)??"",c=t.cursor??"",u=c!==""&&(i!==""||a!==""||c!==this.cursor);if(this.cursor=c,i||a||u)this.write(`${Ry}${i}${a}\x1B[0m${u?c:""}${Py}`);this.tick(t.ticking===!0)};tick(t){if(t&&!this.ticker)this.ticker=setInterval(()=>{this.beat(),this.request()},lm);else if(!t&&this.ticker)clearInterval(this.ticker),this.ticker=void 0}}class dm{shown=[];write;cols;constructor(t,e){this.write=t,this.cols=e}draw(t){this.put(t,"")}redraw(t){let e=`${this.shown.length>1?`\x1B[${this.shown.length-1}A`:""}${this.shown.length>0?"\r\x1B[J":""}`;this.shown=[],this.put(t,e)}end(t){this.put(t,""),this.write(`
606
+ `),this.shown=[]}put(t,e){let n=t.map((o)=>rt(o,this.cols()-1,!1)),r=0;while(r<n.length&&r<this.shown.length&&n[r]===this.shown[r])r++;if(r===n.length&&n.length===this.shown.length)return;if(r===n.length)r=Math.max(0,n.length-1);let i="";if(this.shown.length===0)i=n.join(`
607
607
  `);else if(r>=this.shown.length)i=`
608
608
  ${n.slice(r).join(`
609
- `)}`;else{let s=this.shown.length-1-r;i=`${s>0?`\x1B[${s}A`:""}\r\x1B[J${n.slice(r).join(`
610
- `)}`}this.shown=n,this.write(`${Ik}${e}${i}${Rk}`)}}var TT=300;function Ou(t){return t>=1e6?`${(t/1e6).toFixed(1)} MB`:`${Math.max(1,Math.round(t/1000))} KB`}function xu(t,e){if(!e)return Ou(t);return e>=1e6?`${(t/1e6).toFixed(1)}/${(e/1e6).toFixed(1)} MB`:`${Math.round(t/1000)}/${Math.round(e/1000)} KB`}var _s;async function Nk(t,e){_s=t;try{return await e()}finally{_s=void 0}}function Lr(t){if(_s)_s.say(t);else console.log(t)}function jr(t=""){if(_s){let u=_s;return u.set(t),{set:(l)=>u.set(l),say:(l)=>u.say(l),done:()=>u.set("")}}let e=process.stdout;if(!e.isTTY||process.env.TERM==="dumb")return{set(){},say:(u)=>console.log(u),done(){}};let[n,r]=Lt()?["",""]:[A,ge],i=0,s=!1,o,a=()=>{e.write(`\r\x1B[2K${n}${ot(`${xn[i%xn.length]} ${t}`,(e.columns||80)-1,!1)}${r}`)},c=setTimeout(()=>{s=!0,a(),o=setInterval(()=>{i++,a()},Rh),o.unref()},TT);return c.unref(),{set(u){if(t=u,s)a()},say(u){if(s)e.write("\r\x1B[2K");if(console.log(u),s)a()},done(){if(clearTimeout(c),clearInterval(o),s)e.write("\r\x1B[2K"),s=!1}}}import{existsSync as Dk,mkdirSync as qk,readFileSync as Yk,statSync as ZT,utimesSync as QT}from"node:fs";import{homedir as XT}from"node:os";import{dirname as tA,join as Wk}from"node:path";function Th(t){if(t.length>0&&process.stderr.isTTY)process.stderr.write(`${t.join(`
609
+ `)}`;else{let o=this.shown.length-1-r;i=`${o>0?`\x1B[${o}A`:""}\r\x1B[J${n.slice(r).join(`
610
+ `)}`}this.shown=n,this.write(`${Ry}${e}${i}${Py}`)}}var sT=300;function qu(t){return t>=1e6?`${(t/1e6).toFixed(1)} MB`:`${Math.max(1,Math.round(t/1000))} KB`}function Yu(t,e){if(!e)return qu(t);return e>=1e6?`${(t/1e6).toFixed(1)}/${(e/1e6).toFixed(1)} MB`:`${Math.round(t/1000)}/${Math.round(e/1000)} KB`}var ns;async function Ny(t,e){ns=t;try{return await e()}finally{ns=void 0}}function Yr(t){if(ns)ns.say(t);else console.log(t)}function Jr(t=""){if(ns){let u=ns;return u.set(t),{set:(l)=>u.set(l),say:(l)=>u.say(l),done:()=>u.set("")}}let e=process.stdout;if(!e.isTTY||process.env.TERM==="dumb")return{set(){},say:(u)=>console.log(u),done(){}};let[n,r]=Pt()?["",""]:[C,$e],i=0,o=!1,s,a=()=>{e.write(`\r\x1B[2K${n}${rt(`${jn[i%jn.length]} ${t}`,(e.columns||80)-1,!1)}${r}`)},c=setTimeout(()=>{o=!0,a(),s=setInterval(()=>{i++,a()},lm),s.unref()},sT);return c.unref(),{set(u){if(t=u,o)a()},say(u){if(o)e.write("\r\x1B[2K");if(console.log(u),o)a()},done(){if(clearTimeout(c),clearInterval(s),o)e.write("\r\x1B[2K"),o=!1}}}import{existsSync as qy,mkdirSync as Yy,readFileSync as Jy,statSync as xT,utimesSync as OT}from"node:fs";import{homedir as IT}from"node:os";import{dirname as RT,join as Ky}from"node:path";function fm(t){if(t.length>0&&process.stderr.isTTY)process.stderr.write(`${t.join(`
611
611
  `)}
612
- `)}import{existsSync as Ah,mkdirSync as Tk,readFileSync as Bs}from"node:fs";import{homedir as LT}from"node:os";import{dirname as Ak,join as Ni}from"node:path";import{spawn as AT}from"node:child_process";var PT=30000,HT=3,FT=97,CT=`ObjC.import('Vision')
612
+ `)}import{existsSync as hm,mkdirSync as Ay,readFileSync as is}from"node:fs";import{homedir as fT}from"node:os";import{dirname as Ty,join as Gi}from"node:path";import{spawn as aT}from"node:child_process";var cT=30000,uT=3,lT=97,dT=`ObjC.import('Vision')
613
613
  ObjC.import('CoreImage')
614
614
  ObjC.import('CoreGraphics')
615
615
  function run(argv) {
@@ -628,39 +628,39 @@ function run(argv) {
628
628
  $.CIImage.imageWithCVPixelBuffer(buffer), $.NSURL.fileURLWithPath(argv[1]), $.kCIFormatRGBA8,
629
629
  $.CGColorSpaceCreateWithName($.kCGColorSpaceSRGB), $({}), error)
630
630
  if (!written) throw new Error('write failed')
631
- }`;function Gs(){return process.platform==="darwin"}function Iu(t){return t>=HT&&t<=FT}function ea(t,e,n){return new Promise((r,i)=>{let s=AT("osascript",["-l","JavaScript","-e",CT,t,e],{stdio:["ignore","ignore","pipe"],signal:AbortSignal.any([n,AbortSignal.timeout(PT)])}),o="";s.stderr.on("data",(a)=>{o+=a}),s.on("error",i),s.on("close",(a)=>{if(a===0){r();return}i(Error(o.trim().split(`
632
- `).at(-1)||`osascript exited ${a}`))})})}var Pk=90000;function Nu(t,e){let n=q(t),r=ce(t,e).flatMap((i)=>{let[,s,o]=/^([a-z.]+)_(\d+)$/.exec(i.key)??[];return s&&o&&Y.some((a)=>a.key===s)?[{site:s,id:Number(o),...Bf(n,i)}]:[]});return r.length>0?r:void 0}function jT(t,e){let n=new Set(kt(q(t)).palettes[e.name]?.pictures.map((r)=>r.key));return(e.pictures??[]).filter((r)=>!n.has(te(r)))}function Us(t,e){let n=new Set((e??[]).map((r)=>te(r)));return{...t,pictures:(t.pictures??[]).filter((r)=>!n.has(te(r)))}}async function _T(t,e,n,r,i,s){let o=Y.find((g)=>g.key===n.site);if(!o)throw Error(`no site called ${n.site}`);s("Fetching");let a=await us(o,n.id,i);if(!a)throw Error("the post is gone");if(o!==Qt&&a.md5)try{ec([a],await nc([a.md5],i))}catch{}let c=tc(o,a)?Xa(o,a.id,i).then((g)=>{if(g)Eo(a,g)},()=>{}):void 0;if(!Za(o,a,si(process.env.TTHEME_FIND_RATING))||Va(a,cs(process.env.TTHEME_FIND_BLOCK)).length>0)throw Error("outside your find filters — TTHEME_FIND_RATING and TTHEME_FIND_BLOCK");let u=fn(a);if(!u)throw Error("too large to use");let l=Ni(Ke(o),"orig",`${n.id}.${u.ext}`),f;if(Ah(l))f=new Uint8Array(Bs(l));else{s("Downloading");let g=oi(o,a,u);f=await rc(g.site,g.url,i,(b,y)=>s("Downloading",xu(b,y))),P(l,f)}let d=or(f,$e),h=!1;if(Tn(d)===0&&Gs()&&process.env.TTHEME_FIND_REMOVE_BG!=="off"){let g=Ni(Ke(o),"cut",`${n.id}.png`);try{if(!Ah(g))s("Cutting out"),Tk(Ak(g),{recursive:!0}),await ea(l,g,i);let b=or(new Uint8Array(Bs(g)),$e);if(Iu(Tn(b)))d=b,h=!0}catch{}}await c;let m=jf(e);s("Drawing"),fc(t,m,hn(m,e.signatureSlots),d,{site:o.key,id:n.id,ext:u.ext,bytes:f,from:`${o.name} ${n.id} ${o.pageUrl(n.id)}`,artist:a.named.artist,source:vo(a.source),cut:h},{width:0,height:0},Tr(t),nu(t));let $=ce(t,e.name).find((g)=>g.key===te(n));if($)Ao(q(t),$,n,r,LT())}function GT(t,e){let n=Y.find((s)=>s.key===t.site),r=`${n?.name??t.site} ${t.id}`;if(!n||!e)return r;return`${Lt()?uo:`\x1B[${30+n.ansi}m${uo}\x1B[39m`} ${Ua(r,n.pageUrl(t.id))}`}async function Dn(t,e,n){let r=e.flatMap((c)=>jT(t,c).map((u)=>({entry:c,shared:u})));if(r.length===0)return;let i=xi(n),s=process.stdout.isTTY&&a$(process.env),o=new Set,a=jr();for(let[c,{entry:u,shared:l}]of r.entries()){let f=`${u.name} · ${GT(l,s)}`,d=r.length>1?` · ${c+1}/${r.length}`:"",h=(m,$)=>a.set(`${m} ${f}${$?` · ${$}`:""}${d}`);try{await _T(t,u,l,i,AbortSignal.timeout(Pk),h),a.say(` ▣ ${f}`),o.add(u)}catch(m){a.say(` ▢ ${f} — ${m instanceof Error?m.message:String(m)}`)}}a.done();for(let c of o){let u=(c.pictures??[]).find((l)=>ce(t,c.name).some((f)=>f.key===te(l)));if(u)bs(t,c.name,te(u))}if(o.size>0)Re(t)}function Hk(t,e,n){if(e.width!==t.width||e.height!==t.height)return!1;for(let r=0;r<t.width*t.height;r++)t.data[r*4+3]=e.data[r*4+n]??0;return!0}async function BT(t,e){let[,n,r]=/^(.+)_(\d+)$/.exec(t)??[],i=Ni(hr(),n??"local","cut",`${r??t}.png`);if(!Ah(i)){if(!Gs())return;Tk(Ak(i),{recursive:!0}),await ea(e,i,AbortSignal.timeout(Pk))}return or(new Uint8Array(Bs(i)),$e)}function UT(t,e){try{return Tn(Ht(new Uint8Array(Bs(Ni(t,`${e.stem}.png`)))))>0}catch{return!1}}function Ru(t,e){return()=>or(new Uint8Array(Bs(Ni(t,e.original))),$e)}function Fk(t,e){let n=Ru(t,e);return()=>{let r=n(),i=Ht(new Uint8Array(Bs(Ni(t,e.cut))));return Hk(r,i,0)?r:null}}async function Tu(t,e,n,r,i,s,o,a){let c=q(t),u=kt(c).palettes[e]?.pictures.find((l)=>l.key===n);if(!u?.original)return null;if(u.cut)return Po(t,e,u,Fk(c,u),r,i,s,o,!1,a);if(gs(u)){let l=Ru(c,u)();if(Tn(l)===0&&UT(c,u)){let f=await BT(n,Ni(c,u.original));if(!f||!Hk(l,f,3))return null;return Po(t,e,u,()=>l,r,i,s,o,!0,a)}return Po(t,e,u,()=>l,r,i,s,o,!1,a)}return Po(t,e,u,Ru(c,u),r,i,s,o,!1,a)}function Ck(t,e,n,r,i,s){let o=q(t),a=kt(o).palettes[e]?.pictures.find((u)=>u.key===n);if(!a?.original||gs(a))return!1;let c=a.cut?Fk(o,a):Ru(o,a);return Tw(t,e,a,c,r,i,s)}import{existsSync as WT,readFileSync as KT}from"node:fs";import{join as zT}from"node:path";function DT(t){return zT(t,"ttheme","pins")}function Lk(t,e,n){let r=DT(t);if(!WT(r))return;let i=KT(r,"utf8"),o=i.split(`
633
- `).flatMap((a)=>{let c=/^((?:[~/]|ssh:).*\s)(\S+)(\s*)$/.exec(a);if(!c)return[a];let[,u,l,f]=c;if(n.includes(l))return[];let d=e.get(l);return[d?`${u}${d}${f}`:a]}).join(`
634
- `);if(o!==i)P(r,o)}function jk(t,e){let n=e,r=new Set;while(Object.hasOwn(t,n)&&!r.has(n)){r.add(n);let i=t[n];if(i===!1)return!1;n=i}return r.has(n)||n===e?void 0:n}function _k(t,e,n,r,i){let s=`${t}/`;for(let o of r){let a=o.startsWith(s)?o.slice(s.length):void 0;if(a===void 0||n.has(a))continue;let c=jk(e.renames,a);if(c===!1)i.removed.push(o);else if(c!==void 0&&n.has(c))i.renamed.set(o,`${s}${c}`);else if(e.forceRemove)i.removed.push(o)}}function Gk(t,e){let n=[],r=[];for(let i of Object.keys(t)){if(e.has(i)){r.push(`renames.${i}: ${i} is still a palette here, so the rename never applies`);continue}let s=jk(t,i);if(s===void 0)n.push(`renames.${i}: the chain comes back to a name it already passed`);else if(s!==!1&&!e.has(s))n.push(`renames.${i}: the chain ends at ${s}, which is not a palette here — end it at one, or at false`)}return{errors:n,warnings:r}}import{gunzipSync as qT}from"node:zlib";var Ti=512,Bk=67108864,Ph=new TextDecoder;function Ws(t,e,n){let r=t.subarray(e,e+n),i=r.indexOf(0);return Ph.decode(i<0?r:r.subarray(0,i))}function YT(t){if((t[124]??0)&128)throw Error("the archive holds a file too large to be a palette");let e=Number.parseInt(Ws(t,124,12).trim()||"0",8);if(!Number.isFinite(e)||e<0)throw Error("the archive has a header that does not read");return e}function JT(t){let e=0,n;while(e<t.length){let r=t.indexOf(32,e),i=r<0?Number.NaN:Number.parseInt(Ph.decode(t.subarray(e,r)),10);if(!Number.isFinite(i)||i<=0)break;let s=Ph.decode(t.subarray(r+1,e+i-1)),o=s.indexOf("=");if(s.slice(0,o)==="path")n=s.slice(o+1);e+=i}return n}function VT(t){if(t[0]!==31||t[1]!==139)return t;try{return qT(t,{maxOutputLength:Bk})}catch(e){throw Error(e instanceof RangeError?`the archive unpacks to more than ${Bk/1024/1024} MB`:"the archive is not a gzip file that reads")}}function Uk(t){let e=VT(t),n=new Map,r,i=0;while(i+Ti<=e.length){let s=e.subarray(i,i+Ti);if(s.every((f)=>f===0))break;let o=YT(s),a=e.subarray(i+Ti,i+Ti+o);i+=Ti+Math.ceil(o/Ti)*Ti;let c=String.fromCharCode(s[156]??0);if(c==="x"){r=JT(a)??r;continue}if(c==="L"){r=Ws(a,0,a.length);continue}let u=Ws(s,257,5)==="ustar"?Ws(s,345,155):"",l=r??(u?`${u}/${Ws(s,0,100)}`:Ws(s,0,100));if(r=void 0,c==="0"||c==="\x00")n.set(l.split("/").slice(1).join("/"),a)}return n}var eA=86400000,nA=3600000,Fh=5000;function Hh(){return Wk(process.env.XDG_STATE_HOME??Wk(XT(),".local","state"),"ttheme","markets.json")}function qn(){try{let t=JSON.parse(Yk(Hh(),"utf8"));return Object.fromEntries(Object.entries(t).filter((e)=>typeof e[1]?.at==="number"&&typeof e[1].error==="string"))}catch{return{}}}function Kk(t,e){let n=qn();if(e===void 0){if(!(t in n))return;delete n[t]}else n[t]={at:Date.now(),error:e};qk(tA(Hh()),{recursive:!0}),P(Hh(),`${JSON.stringify(n,null,2)}
635
- `)}function na(t,e){let n=e===z?Me(t):ee(e)?He(t,e):void 0;try{return n?ZT(n).mtimeMs:void 0}catch{return}}function rA(t,e,n,r){return t&&(e===void 0||r-e>=eA)&&(n===void 0||r-n>=nA)}function Ch(t,e,n=Date.now()){let r=qn();return Ct(e.markets).filter((i)=>rA(kr(i,e.updates),na(t,i),r[i]?.at,n))}function iA(t,e){let n={},r=new TextDecoder;for(let[i,s]of Uk(t))if(i===Ft||i.startsWith("palettes/")&&i.endsWith(".toml"))n[i]=r.decode(s);return{...e?{etag:e}:{},files:n}}async function Jk(t,e,n,r){let i;try{i=await hd(Xw(t),e,n,r?{"if-none-match":r}:{})}catch(s){if(s instanceof Rc){let o=Fo(t);throw Error(`${Z(t)}${o?` has no ${o}`:" is not there"} — is the repository public?`)}throw s}if(i.status===304)return;return iA(new Uint8Array(await i.arrayBuffer()),i.headers.get("etag"))}function Vk(t,e,n){let{id:r,info:i,entries:s}=Ln(t,e,n,re(!1));return{source:t,id:r,entries:s,archive:e,info:i}}function ra(t){return Ai(t,z)}async function ia(t,e,n,r){if(e===z){let s=await Tc(w0,Je,n,r);return{source:e,id:z,manifest:s,entries:s.palettes}}let i=await Jk(e,n,r);if(!i)throw Error(`${Z(e)} answered as if nothing had changed`);return Vk(e,i,ra(t))}function Ks(t,e){if("manifest"in e){Oc(t,e.manifest);return}qk(Xf(t),{recursive:!0}),P(He(t,e.source),`${JSON.stringify(e.archive)}
636
- `)}function sA(t,e){try{return Ye(t,e)}catch{return}}function Ai(t,e){try{if(e===z)return Je(Yk(Me(t),"utf8")).palettes;return Ln(e,Ye(t,e),ra(t),re(!1)).entries}catch{return[]}}function oA(t,e){let n=new Map(t.map((i)=>[i.name,JSON.stringify(i)])),r=new Map(e.map((i)=>[i.name,JSON.stringify(i)]));return{added:[...r.keys()].filter((i)=>!n.has(i)),changed:[...r].filter(([i,s])=>n.has(i)&&n.get(i)!==s).map(([i])=>i),gone:[...n.keys()].filter((i)=>!r.has(i))}}async function aA(t,e,n){if(!ee(e))return ia(t,e,n);let r=sA(t,e),i=await Jk(e,n,void 0,r?.etag);return i&&Vk(e,i,ra(t))}async function Lh(t,e,n){let r=Ai(t,e),i;try{i=await aA(t,e,n)}catch(o){throw Kk(e,o.message),o}if(i)Ks(t,i);else{let o=new Date;QT(He(t,e),o,o)}Kk(e,void 0);let s=i?.entries??r;return{source:e,id:i?.id??xc(e,Ye(t,e)),...i&&"manifest"in i?{version:i.manifest.version}:{},count:Mt(s).length,change:oA(r,s)}}async function jh(t,e,n){try{return{source:e,refreshed:await Lh(t,e,n)}}catch(r){return{source:e,failure:r instanceof Error?r:Error(String(r))}}}function _h(t,e){return`${Z(t)}: ${e.message}`}function cA(t){return"failure"in t&&t.failure instanceof dc?_h(t.source,t.failure):void 0}function Rt(t){return`${t} palette${t===1?"":"s"}`}function sa(t,e=Date.now()){let n=Math.floor(Math.max(0,e-t)/60000);if(n<1)return"just now";if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<48?`${r}h ago`:`${Math.floor(r/24)}d ago`}function Zk({added:t,changed:e,gone:n}){return[t.length>0?`${t.length} new`:"",e.length>0?`${e.length} changed`:"",n.length>0?`${n.length} gone`:""].filter(Boolean).join(", ")}function Gh(t){let e=Zk(t.change);return`${t.version?`${t.id} ${t.version}`:t.id} — ${Rt(t.count)}${e?` (${e})`:""}`}function Bh(t){return Zk(t.change)?`Updated ${Gh(t)}`:void 0}var zk=/^(\d+)\.(\d+)\.(\d+)$/;function uA(t,e){let n=zk.exec(t),r=zk.exec(e);if(!n||!r)return!1;for(let i of[1,2,3]){let s=Number(n[i])-Number(r[i]);if(s!==0)return s>0}return!1}function Uh(t,e=It.version){return t.version&&uA(t.version,e)?`ttheme ${t.version} is out, you have ${e} — \`${Kf}\` updates it`:void 0}function oa(t,e,n=ra(t)){try{if(ct(e)){let r=Fe(e),i=ne(r);return{id:i,info:r,entries:qe(e,i,n,re(!1))}}return ee(e)?Ln(e,Ye(t,e),n,re(!1)):void 0}catch{return}}function Wh(t){if(!Dk(Hn(t)))return[];let e=L(t),n=ra(t),r={renamed:new Map,removed:[]};for(let u of Ct(e.markets)){let l=oa(t,u,n);if(l)_k(l.id,l.info,new Set(l.entries.map((f)=>ae(f.name))),e.palettes,r)}if(r.renamed.size===0&&r.removed.length===0)return[];let i=ut(t,!1);js(t,i,e.terminals,[...r.renamed.keys(),...r.removed]),p0(t,r.renamed,r.removed),vw(t,r.renamed),Lk(t,r.renamed,r.removed);let s=[...new Set(e.palettes.filter((u)=>!r.removed.includes(u)).map((u)=>r.renamed.get(u)??u))],{startup:o,...a}=e,c=o&&!r.removed.includes(o)?r.renamed.get(o)??o:void 0;return je(t,i,e,{...a,palettes:s,...c?{startup:c}:{}}),[...[...r.renamed].map(([u,l])=>`${u} is ${l} now — its market renamed it`),...r.removed.map((u)=>`${u} was removed from its market`)]}async function Kh(t,e,n,r){let i=Wh(t),s=i.length>0?L(t):e,o=new Set(r.flatMap((d)=>[...d.change.changed,...d.change.gone])),a=s.palettes.filter((d)=>o.has(d));if(a.length===0)return i;let c=ut(t,!1);jt(t,c,s);let u=new Set(r.flatMap((d)=>d.change.gone)),l=a.filter((d)=>u.has(d)).map((d)=>`${d} left its market — ttheme keeps the copy you have`),f=new Map(n.map((d)=>[d.name,d.pictures]));return await Dn(t,Ot(t,c,!1).palettes.filter((d)=>a.includes(d.name)&&f.has(d.name)).map((d)=>Us(d,f.get(d.name))),s.terminals),[...i,...l]}async function Qk(t=J()){try{if(!Dk(Hn(t)))return;let e=L(t),n=Ch(t,e);if(n.length===0)return;let r=jn(t),i=jr(`Checking ${n.map(Z).join(", ")} for updates`),s=await Promise.all(n.map((u)=>jh(t,u,Fh)));i.done();let o=s.flatMap((u)=>("refreshed"in u)?[u.refreshed]:[]),a=o.flatMap((u)=>Bh(u)??[]);Th(a);let c=a.length>0?await Kh(t,e,r,o):[];Th([...c,...s.flatMap((u)=>cA(u)??[]),...o.flatMap((u)=>Uh(u)??[])])}catch{return}}var iy=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,hA=["add","remove","search","init","check"];function Dh(){return process.stdin.isTTY===!0&&process.stdout.isTTY===!0}function mA(){try{let t=lA("gh",["api","user","--jq",".login"],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:1e4}).trim().toLowerCase();return iy.test(t)?t:void 0}catch{return}}async function pA(t,e){if(e.author)return e.author;let n=mA();if(!n){if(!Dh())throw Error("your palettes are named after your GitHub handle — log in with `gh auth login`, or run this in a terminal");let r=await Ad({message:"Your GitHub handle — your palettes are named <handle>@<market>/<palette>",validate:(i)=>iy.test((i??"").toLowerCase())&&(i??"").length<=39?void 0:"that is not a GitHub handle"});if(fe(r))throw Error("no handle given");n=r.toLowerCase()}return Le(t,{...e,author:n}),console.log(`Your palettes are named ${n}@<market>/<palette>`),n}function zs(t,e){if(e===z)return z;return ct(e)?ne(Fe(e)):xc(e,Ye(t,e))}function Hu(t,e){try{return zs(t,e)}catch{return}}function sy(t){return lt(t)??z}function ca(t){return ut(t).palettes.filter((e)=>lt(e.name)===void 0)}function gA(t){let e=aa(import.meta.dirname,"..","dist","manifest.json");return Au(e)?Je(Pu(e,"utf8")).palettes:ca(t)}function ua(t,e,n){let{updates:r,...i}=t,s=Object.entries(n).filter(([o,a])=>e.includes(o)&&a!==kr(o,{}));return{...i,markets:e,...s.length>0?{updates:Object.fromEntries(s)}:{}}}function oy(t,e,n,r){return e.find((i)=>i!==n&&!Ms(i,n)&&Hu(t,i)===r)}function zh(t,e,n,r){let i=L(t),s=Ct(i.markets),o=oy(t,s,e,n);if(o)throw Error(`${n} already names the market at ${Z(o)} — \`ttheme market remove ${n}\` first`);let a=r===void 0?{...i.updates}:{...i.updates,[e]:r};Le(t,ua(i,s.includes(e)?s:[...s,e],a))}async function bA(t){if(!Dh())return!1;let e=await Ve({message:`Update ${t} on its own when its author changes it? ttheme checks once a day, when you run it`,initialValue:!1});if(fe(e))throw Error("no answer given — nothing was added");return e}async function ay(t,e){let n=jr(`Fetching ${Z(e)}`);try{return await ia(t,e)}finally{n.done()}}async function wA(t,e,n){let r=await ay(t,n),i=L(t),s=Ct(i.markets),o=oy(t,s,n,r.id);if(o)throw Error(`${r.id} already names the market at ${Z(o)} — \`ttheme market remove ${r.id}\` first`);let{[e]:a,...c}=i.updates??{},u=a===void 0?c:{...c,[n]:a};return Le(t,ua(i,s.map((l)=>l===e?n:l),u)),Ks(t,r),r}async function qh(t,e){let n=yr(e),r=Ct(L(t).markets);if(r.includes(n))return console.log(`${Z(n)} is already added`),{source:n,id:zs(t,n),fresh:!1};let i=ee(n)?r.find((c)=>ee(c)&&Ms(c,n)):void 0;if(i){let c=await wA(t,i,n);return console.log(`Moved ${c.id} to ${Fo(n)??"its default branch"} · ${Z(n)} — ${Rt(Mt(c.entries).length)}`),{source:n,id:c.id,fresh:!1}}if(ct(n)){let c=ne(Fe(n));zh(t,n,c);let u=qe(n,c,ca(t)).length;return console.log(`Added ${c} · ${Z(n)} — ${Rt(u)}, read in place`),{source:n,id:c,fresh:!0}}let s=await ay(t,n),o=n===z?void 0:await bA(s.id);zh(t,n,s.id,o),Ks(t,s);let a=Rt(Mt(s.entries).length);return console.log(n===z?`Added the ttheme catalog — ${a}`:`Added ${s.id} · ${Z(n)} — ${a}${o?", updating on its own":""}`),{source:n,id:s.id,fresh:!0}}async function $A(t){let e=J(),{source:n,id:r,fresh:i}=await qh(e,t);if(!i)return;if(ct(n))console.log("\n`ttheme browse` picks them · once the folder is on GitHub, `ttheme market add <owner>/<repo>` adds it anywhere");else if(n===z)console.log("\n`ttheme browse` picks them");else console.log(`
637
- \`ttheme browse\` picks them, or \`ttheme add ${r}/<palette>\``)}function Yh(t,e){if(e===z)Xk(Me(t),{force:!0});else if(ee(e))Xk(He(t,e),{force:!0})}function Jh(t){return`${Rt(t.length)} installed from it keep${t.length===1?"s":""} working: ${t.join(", ")} — \`ttheme remove\` drops ${t.length===1?"it":"them"}`}function kA(t){let e=J(),n=L(e),r=Ct(n.markets),i=r.find((u)=>Hu(e,u)===t)??r.find((u)=>u===cy(t));if(!i)throw Error(`no market named ${t} — \`ttheme market\` lists them`);let s=Hu(e,i),o=n.palettes.filter((u)=>sy(u)===s),a=r.filter((u)=>u!==i),c=ua(n,a,n.updates??{});if(Le(e,c),Yh(e,i),jt(e,ut(e),c),console.log(`Removed ${s??t} · ${Z(i)}`),o.length>0)console.log(Jh(o))}function cy(t){try{return yr(t)}catch{return}}function yA(t,e){try{if(e===z)return Mt(Je(Pu(Me(t),"utf8")).palettes).length;if(ct(e))return qe(e,zs(t,e),ca(t),re(!1)).length;return Ln(e,Ye(t,e),ca(t),re(!1)).entries.length}catch{return}}function Vh(t,e,n=qn(),r=Date.now()){if(ct(e))return"read in place";let i=n[e],s=na(t,e);if(i&&(s===void 0||i.at>s))return`update failed ${sa(i.at,r)}`;return s===void 0?"never updated":`updated ${sa(s,r)}`}function vA(){let t=J(),e=L(t),n=Ct(e.markets);if(n.length===0){console.log("No markets — `ttheme market add official` brings the ttheme catalog back");return}let r=qn(),i=n.map((a)=>{let c=Hu(t,a)??"?",u=yA(t,a),l=e.palettes.filter((h)=>sy(h)===c).length,f=ct(a)?[]:[`auto-update ${kr(a,e.updates)?"on":"off"}`],d=a===z?void 0:oa(t,a)?.info.description;return{name:c,where:Z(a),about:d,note:[u===void 0?"Unreadable":Rt(u),...l>0?[`${l} installed`]:[],...f,Vh(t,a,r)].join(" · ")}}),s=Math.max(...i.map((a)=>a.name.length)),o=Math.max(...i.map((a)=>a.where.length));for(let a of i)if(console.log(` ${a.name.padEnd(s)} ${a.where.padEnd(o)} ${a.note}`),a.about)console.log(` ${" ".repeat(s)} ${a.about}`)}function Zh(t){return`${t.owner.login.toLowerCase()}/${t.name}`}async function Qh(t,e){let n=encodeURIComponent(`topic:${Es}${t?` ${t}`:""}`);try{let{items:r}=await Tc(`https://api.github.com/search/repositories?q=${n}&sort=stars&per_page=50`,(i)=>JSON.parse(i),void 0,e);return r}catch(r){if(r instanceof Nc)throw Error("GitHub lets a search through about ten times a minute without signing in — try again in a minute");throw r}}async function EA(t){let e=J(),n=await Qh(t);if(n.length===0){console.log(`No repository carries the ${Es} topic${t?` and matches ${t}`:""} yet`);return}let r=new Set(Ct(L(e).markets).map($r)),i=n.map((o)=>{let a=Zh(o);return{arg:a,added:r.has(a),stars:`★${o.stargazers_count}`,about:o.description??""}}),s=Math.max(...i.map((o)=>o.arg.length));for(let o of i)console.log(` ${o.added?"●":"○"} ${o.arg.padEnd(s)} ${o.stars.padStart(5)} ${o.about}`);console.log("\n`ttheme market add <name>` adds one")}function uy({name:t}){return`ttheme-${t}`}function SA(t,e){fA(yc(t),{recursive:!0}),P(aa(t,Ft),e0(e)),P(aa(t,"README.md"),`# ${ne(e)}
631
+ }`;function rs(){return process.platform==="darwin"}function Ju(t){return t>=uT&&t<=lT}function ka(t,e,n){return new Promise((r,i)=>{let o=aT("osascript",["-l","JavaScript","-e",dT,t,e],{stdio:["ignore","ignore","pipe"],signal:AbortSignal.any([n,AbortSignal.timeout(cT)])}),s="";o.stderr.on("data",(a)=>{s+=a}),o.on("error",i),o.on("close",(a)=>{if(a===0){r();return}i(Error(s.trim().split(`
632
+ `).at(-1)||`osascript exited ${a}`))})})}var Hy=90000;function Zu(t,e){let n=V(t),r=fe(t,e).flatMap((i)=>{let[,o,s]=/^([a-z.]+)_(\d+)$/.exec(i.key)??[];return o&&s&&J.some((a)=>a.key===o)?[{site:o,id:Number(s),...kf(n,i)}]:[]});return r.length>0?r:void 0}function hT(t,e){let n=new Set(Ot(V(t)).palettes[e.name]?.pictures.map((r)=>r.key));return(e.pictures??[]).filter((r)=>!n.has(se(r)))}function os(t,e){let n=new Set((e??[]).map((r)=>se(r)));return{...t,pictures:(t.pictures??[]).filter((r)=>!n.has(se(r)))}}async function mT(t,e,n,r,i,o){let s=J.find((b)=>b.key===n.site);if(!s)throw Error(`no site called ${n.site}`);o("Fetching");let a=await So(s,n.id,i);if(!a)throw Error("the post is gone");if(s!==ie&&a.md5)try{Rc([a],await Pc([a.md5],i))}catch{}let c=Ic(s,a)?Oc(s,a.id,i).then((b)=>{if(b)Gs(a,b)},()=>{}):void 0;if(!Mc(s,a,gi(process.env.TTHEME_FIND_RATING))||Ec(a,vo(process.env.TTHEME_FIND_BLOCK)).length>0)throw Error("outside your find filters — TTHEME_FIND_RATING and TTHEME_FIND_BLOCK");let u=kn(a);if(!u)throw Error("too large to use");let l=Gi(Ve(s),"orig",`${n.id}.${u.ext}`),d;if(hm(l))d=new Uint8Array(is(l));else{o("Downloading");let b=bi(s,a,u);d=await Nc(b.site,b.url,i,(w,k)=>o("Downloading",Yu(w,k))),F(l,d)}let f=$r(d,Se),h=!1;if(Wn(f)===0&&rs()&&process.env.TTHEME_FIND_REMOVE_BG!=="off"){let b=Gi(Ve(s),"cut",`${n.id}.png`);try{if(!hm(b))o("Cutting out"),Ay(Ty(b),{recursive:!0}),await ka(l,b,i);let w=$r(new Uint8Array(is(b)),Se);if(Ju(Wn(w)))f=w,h=!0}catch{}}await c;let m=bf(e);o("Drawing"),jc(t,m,vn(m,e.signatureSlots),f,{site:s.key,id:n.id,ext:u.ext,bytes:d,from:`${s.name} ${n.id} ${s.pageUrl(n.id)}`,artist:a.named.artist,source:Bs(a.source),cut:h},{width:0,height:0},Ur(t),Su(t));let g=fe(t,e.name).find((b)=>b.key===se(n));if(g)Vs(V(t),g,n,r,fT())}function pT(t,e){let n=J.find((o)=>o.key===t.site),r=`${n?.name??t.site} ${t.id}`;if(!n||!e)return r;return`${Pt()?Is:`\x1B[${30+n.ansi}m${Is}\x1B[39m`} ${gc(r,n.pageUrl(t.id))}`}async function nr(t,e,n){let r=e.flatMap((c)=>hT(t,c).map((u)=>({entry:c,shared:u})));if(r.length===0)return;let i=ji(n),o=process.stdout.isTTY&&ck(process.env),s=new Set,a=Jr();for(let[c,{entry:u,shared:l}]of r.entries()){let d=`${u.name} · ${pT(l,o)}`,f=r.length>1?` · ${c+1}/${r.length}`:"",h=(m,g)=>a.set(`${m} ${d}${g?` · ${g}`:""}${f}`);try{await mT(t,u,l,i,AbortSignal.timeout(Hy),h),a.say(` ▣ ${d}`),s.add(u)}catch(m){a.say(` ▢ ${d} — ${m instanceof Error?m.message:String(m)}`)}}a.done();for(let c of s){let u=(c.pictures??[]).find((l)=>fe(t,c.name).some((d)=>d.key===se(l)));if(u)No(t,c.name,se(u))}if(s.size>0)Te(t)}function Cy(t,e,n){if(e.width!==t.width||e.height!==t.height)return!1;for(let r=0;r<t.width*t.height;r++)t.data[r*4+3]=e.data[r*4+n]??0;return!0}async function gT(t,e){let[,n,r]=/^(.+)_(\d+)$/.exec(t)??[],i=Gi(xr(),n??"local","cut",`${r??t}.png`);if(!hm(i)){if(!rs())return;Ay(Ty(i),{recursive:!0}),await ka(e,i,AbortSignal.timeout(Hy))}return $r(new Uint8Array(is(i)),Se)}function bT(t,e){try{return Wn(jt(new Uint8Array(is(Gi(t,`${e.stem}.png`)))))>0}catch{return!1}}function Vu(t,e){return()=>$r(new Uint8Array(is(Gi(t,e.original))),Se)}function Ly(t,e){let n=Vu(t,e);return()=>{let r=n(),i=jt(new Uint8Array(is(Gi(t,e.cut))));return Cy(r,i,0)?r:null}}async function Qu(t,e,n,r,i,o,s,a){let c=V(t),u=Ot(c).palettes[e]?.pictures.find((l)=>l.key===n);if(!u?.original)return null;if(u.cut)return Zs(t,e,u,Ly(c,u),r,i,o,s,!1,a);if(Po(u)){let l=Vu(c,u)();if(Wn(l)===0&&bT(c,u)){let d=await gT(n,Gi(c,u.original));if(!d||!Cy(l,d,3))return null;return Zs(t,e,u,()=>l,r,i,o,s,!0,a)}return Zs(t,e,u,()=>l,r,i,o,s,!1,a)}return Zs(t,e,u,Vu(c,u),r,i,o,s,!1,a)}function Fy(t,e,n,r,i,o){let s=V(t),a=Ot(s).palettes[e]?.pictures.find((u)=>u.key===n);if(!a?.original||Po(a))return!1;let c=a.cut?Ly(s,a):Vu(s,a);return I0(t,e,a,c,r,i,o)}import{existsSync as wT,readFileSync as $T}from"node:fs";import{join as kT}from"node:path";function yT(t){return kT(t,"ttheme","pins")}function jy(t,e,n){let r=yT(t);if(!wT(r))return;let i=$T(r,"utf8"),s=i.split(`
633
+ `).flatMap((a)=>{let c=/^((?:[~/]|ssh:).*\s)(\S+)(\s*)$/.exec(a);if(!c)return[a];let[,u,l,d]=c;if(n.includes(l))return[];let f=e.get(l);return[f?`${u}${f}${d}`:a]}).join(`
634
+ `);if(s!==i)F(r,s)}function _y(t,e){let n=e,r=new Set;while(Object.hasOwn(t,n)&&!r.has(n)){r.add(n);let i=t[n];if(i===!1)return!1;n=i}return r.has(n)||n===e?void 0:n}function By(t,e,n,r,i){let o=`${t}/`;for(let s of r){let a=s.startsWith(o)?s.slice(o.length):void 0;if(a===void 0||n.has(a))continue;let c=_y(e.renames,a);if(c===!1)i.removed.push(s);else if(c!==void 0&&n.has(c))i.renamed.set(s,`${o}${c}`);else if(e.forceRemove)i.removed.push(s)}}function Gy(t,e){let n=[],r=[];for(let i of Object.keys(t)){if(e.has(i)){r.push(`renames.${i}: ${i} is still a palette here, so the rename never applies`);continue}let o=_y(t,i);if(o===void 0)n.push(`renames.${i}: the chain comes back to a name it already passed`);else if(o!==!1&&!e.has(o))n.push(`renames.${i}: the chain ends at ${o}, which is not a palette here — end it at one, or at false`)}return{errors:n,warnings:r}}import{gunzipSync as vT}from"node:zlib";var Ui=512,Uy=67108864,mm=new TextDecoder;function ss(t,e,n){let r=t.subarray(e,e+n),i=r.indexOf(0);return mm.decode(i<0?r:r.subarray(0,i))}function ST(t){if((t[124]??0)&128)throw Error("the archive holds a file too large to be a palette");let e=Number.parseInt(ss(t,124,12).trim()||"0",8);if(!Number.isFinite(e)||e<0)throw Error("the archive has a header that does not read");return e}function ET(t){let e=0,n;while(e<t.length){let r=t.indexOf(32,e),i=r<0?Number.NaN:Number.parseInt(mm.decode(t.subarray(e,r)),10);if(!Number.isFinite(i)||i<=0)break;let o=mm.decode(t.subarray(r+1,e+i-1)),s=o.indexOf("=");if(o.slice(0,s)==="path")n=o.slice(s+1);e+=i}return n}function MT(t){if(t[0]!==31||t[1]!==139)return t;try{return vT(t,{maxOutputLength:Uy})}catch(e){throw Error(e instanceof RangeError?`the archive unpacks to more than ${Uy/1024/1024} MB`:"the archive is not a gzip file that reads")}}function Wy(t){let e=MT(t),n=new Map,r,i=0;while(i+Ui<=e.length){let o=e.subarray(i,i+Ui);if(o.every((d)=>d===0))break;let s=ST(o),a=e.subarray(i+Ui,i+Ui+s);i+=Ui+Math.ceil(s/Ui)*Ui;let c=String.fromCharCode(o[156]??0);if(c==="x"){r=ET(a)??r;continue}if(c==="L"){r=ss(a,0,a.length);continue}let u=ss(o,257,5)==="ustar"?ss(o,345,155):"",l=r??(u?`${u}/${ss(o,0,100)}`:ss(o,0,100));if(r=void 0,c==="0"||c==="\x00")n.set(l.split("/").slice(1).join("/"),a)}return n}var PT=86400000,NT=3600000,gm=5000;function pm(){return Ky(process.env.XDG_STATE_HOME??Ky(IT(),".local","state"),"ttheme","markets.json")}function rr(){try{let t=JSON.parse(Jy(pm(),"utf8"));return Object.fromEntries(Object.entries(t).filter((e)=>typeof e[1]?.at==="number"&&typeof e[1].error==="string"))}catch{return{}}}function zy(t,e){let n=rr();if(e===void 0){if(!(t in n))return;delete n[t]}else n[t]={at:Date.now(),error:e};Yy(RT(pm()),{recursive:!0}),F(pm(),`${JSON.stringify(n,null,2)}
635
+ `)}function ya(t,e){let n=e===q?Re(t):ae(e)?Be(t,e):void 0;try{return n?xT(n).mtimeMs:void 0}catch{return}}function AT(t,e,n,r){return t&&(e===void 0||r-e>=PT)&&(n===void 0||r-n>=NT)}function bm(t,e,n=Date.now()){let r=rr();return Bt(e.markets).filter((i)=>AT(Nr(i,e.updates),ya(t,i),r[i]?.at,n))}function TT(t,e){let n={},r=new TextDecoder;for(let[i,o]of Wy(t))if(i===_t||i.startsWith("palettes/")&&i.endsWith(".toml"))n[i]=r.decode(o);return{...e?{etag:e}:{},files:n}}async function Vy(t,e,n,r){let i;try{i=await Df(Y0(t),e,n,r?{"if-none-match":r}:{})}catch(o){if(o instanceof eu){let s=Xs(t);throw Error(`${nt(t)}${s?` has no ${s}`:" is not there"} — is the repository public?`)}throw o}if(i.status===304)return;return TT(new Uint8Array(await i.arrayBuffer()),i.headers.get("etag"))}function Zy(t,e,n){let{id:r,info:i,entries:o}=Yn(t,e,n,ue(!1));return{source:t,id:r,entries:o,archive:e,info:i}}function va(t){return Wi(t,q)}async function Sa(t,e,n,r){if(e===q){let o=await ru(h$,en,n,r);return{source:e,id:q,manifest:o,entries:o.palettes}}let i=await Vy(e,n,r);if(!i)throw Error(`${nt(e)} answered as if nothing had changed`);return Zy(e,i,va(t))}function as(t,e){if("manifest"in e){Qc(t,e.manifest);return}Yy(Af(t),{recursive:!0}),F(Be(t,e.source),`${JSON.stringify(e.archive)}
636
+ `)}function HT(t,e){try{return tn(t,e)}catch{return}}function Wi(t,e){try{if(e===q)return en(Jy(Re(t),"utf8")).palettes;return Yn(e,tn(t,e),va(t),ue(!1)).entries}catch{return[]}}function CT(t,e){let n=new Map(t.map((i)=>[i.name,JSON.stringify(i)])),r=new Map(e.map((i)=>[i.name,JSON.stringify(i)]));return{added:[...r.keys()].filter((i)=>!n.has(i)),changed:[...r].filter(([i,o])=>n.has(i)&&n.get(i)!==o).map(([i])=>i),gone:[...n.keys()].filter((i)=>!r.has(i))}}async function LT(t,e,n){if(!ae(e))return Sa(t,e,n);let r=HT(t,e),i=await Vy(e,n,void 0,r?.etag);return i&&Zy(e,i,va(t))}async function wm(t,e,n){let r=Wi(t,e),i;try{i=await LT(t,e,n)}catch(s){throw zy(e,s.message),s}if(i)as(t,i);else{let s=new Date;OT(Be(t,e),s,s)}zy(e,void 0);let o=i?.entries??r;return{source:e,id:i?.id??Xc(e,tn(t,e)),...i&&"manifest"in i?{version:i.manifest.version}:{},count:It(o).length,change:CT(r,o)}}async function $m(t,e,n){try{return{source:e,refreshed:await wm(t,e,n)}}catch(r){return{source:e,failure:r instanceof Error?r:Error(String(r))}}}function km(t,e){return`${nt(t)}: ${e.message}`}function FT(t){return"failure"in t&&t.failure instanceof _c?km(t.source,t.failure):void 0}function Tt(t){return`${t} palette${t===1?"":"s"}`}function Ea(t,e=Date.now()){let n=Math.floor(Math.max(0,e-t)/60000);if(n<1)return"just now";if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<48?`${r}h ago`:`${Math.floor(r/24)}d ago`}function Qy({added:t,changed:e,gone:n}){return[t.length>0?`${t.length} new`:"",e.length>0?`${e.length} changed`:"",n.length>0?`${n.length} gone`:""].filter(Boolean).join(", ")}function ym(t){let e=Qy(t.change);return`${t.version?`${t.id} ${t.version}`:t.id} — ${Tt(t.count)}${e?` (${e})`:""}`}function vm(t){return Qy(t.change)?`Updated ${ym(t)}`:void 0}var Dy=/^(\d+)\.(\d+)\.(\d+)$/;function jT(t,e){let n=Dy.exec(t),r=Dy.exec(e);if(!n||!r)return!1;for(let i of[1,2,3]){let o=Number(n[i])-Number(r[i]);if(o!==0)return o>0}return!1}function Sm(t,e=At.version){return t.version&&jT(t.version,e)?`ttheme ${t.version} is out, you have ${e} — \`${Sf}\` updates it`:void 0}function Ma(t,e,n=va(t)){try{if(ut(e)){let r=Ge(e),i=ce(r);return{id:i,info:r,entries:Xe(e,i,n,ue(!1))}}return ae(e)?Yn(e,tn(t,e),n,ue(!1)):void 0}catch{return}}function Em(t){if(!qy(Dn(t)))return[];let e=W(t),n=va(t),r={renamed:new Map,removed:[]};for(let u of Bt(e.markets)){let l=Ma(t,u,n);if(l)By(l.id,l.info,new Set(l.entries.map((d)=>de(d.name))),e.palettes,r)}if(r.renamed.size===0&&r.removed.length===0)return[];let i=dt(t,!1);es(t,i,e.terminals,[...r.renamed.keys(),...r.removed]),l$(t,r.renamed,r.removed),$0(t,r.renamed),jy(t,r.renamed,r.removed);let o=[...new Set(e.palettes.filter((u)=>!r.removed.includes(u)).map((u)=>r.renamed.get(u)??u))],{startup:s,...a}=e,c=s&&!r.removed.includes(s)?r.renamed.get(s)??s:void 0;return Ke(t,i,e,{...a,palettes:o,...c?{startup:c}:{}}),[...[...r.renamed].map(([u,l])=>`${u} is ${l} now — its market renamed it`),...r.removed.map((u)=>`${u} was removed from its market`)]}async function Mm(t,e,n,r){let i=Em(t),o=i.length>0?W(t):e,s=new Set(r.flatMap((f)=>[...f.change.changed,...f.change.gone])),a=o.palettes.filter((f)=>s.has(f));if(a.length===0)return i;let c=dt(t,!1);qt(t,c,o);let u=new Set(r.flatMap((f)=>f.change.gone)),l=a.filter((f)=>u.has(f)).map((f)=>`${f} left its market — ttheme keeps the copy you have`),d=new Map(n.map((f)=>[f.name,f.pictures]));return await nr(t,Rt(t,c,!1).palettes.filter((f)=>a.includes(f.name)&&d.has(f.name)).map((f)=>os(f,d.get(f.name))),o.terminals),[...i,...l]}async function Xy(t=Q()){try{if(!qy(Dn(t)))return;let e=W(t),n=bm(t,e);if(n.length===0)return;let r=Jn(t),i=Jr(`Checking ${n.map(nt).join(", ")} for updates`),o=await Promise.all(n.map((u)=>$m(t,u,gm)));i.done();let s=o.flatMap((u)=>("refreshed"in u)?[u.refreshed]:[]),a=s.flatMap((u)=>vm(u)??[]);fm(a);let c=a.length>0?await Mm(t,e,r,s):[];fm([...c,...o.flatMap((u)=>FT(u)??[]),...s.flatMap((u)=>Sm(u)??[])])}catch{return}}var o1=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,UT=["add","remove","search","init","check"];function Om(){return process.stdin.isTTY===!0&&process.stdout.isTTY===!0}function WT(){try{let t=_T("gh",["api","user","--jq",".login"],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:1e4}).trim().toLowerCase();return o1.test(t)?t:void 0}catch{return}}async function KT(t,e){if(e.author)return e.author;let n=WT();if(!n){if(!Om())throw Error("your palettes are named after your GitHub handle — log in with `gh auth login`, or run this in a terminal");let r=await fh({message:"Your GitHub handle — your palettes are named <handle>@<market>/<palette>",validate:(i)=>o1.test((i??"").toLowerCase())&&(i??"").length<=39?void 0:"that is not a GitHub handle"});if(me(r))throw Error("no handle given");n=r.toLowerCase()}return We(t,{...e,author:n}),console.log(`Your palettes are named ${n}@<market>/<palette>`),n}function cs(t,e){if(e===q)return q;return ut(e)?ce(Ge(e)):Xc(e,tn(t,e))}function el(t,e){try{return cs(t,e)}catch{return}}function s1(t){return lt(t)??q}function Oa(t){return dt(t).palettes.filter((e)=>lt(e.name)===void 0)}function zT(t){let e=xa(import.meta.dirname,"..","dist","manifest.json");return Xu(e)?en(tl(e,"utf8")).palettes:Oa(t)}function Ia(t,e,n){let{updates:r,...i}=t,o=Object.entries(n).filter(([s,a])=>e.includes(s)&&a!==Nr(s,{}));return{...i,markets:e,...o.length>0?{updates:Object.fromEntries(o)}:{}}}function a1(t,e,n,r){return e.find((i)=>i!==n&&!_o(i,n)&&el(t,i)===r)}function xm(t,e,n,r){let i=W(t),o=Bt(i.markets),s=a1(t,o,e,n);if(s)throw Error(`${n} already names the market at ${nt(s)} — \`ttheme market remove ${n}\` first`);let a=r===void 0?{...i.updates}:{...i.updates,[e]:r};We(t,Ia(i,o.includes(e)?o:[...o,e],a))}async function DT(t){if(!Om())return!1;let e=await nn({message:`Update ${t} on its own when its author changes it? ttheme checks once a day, when you run it`,initialValue:!1});if(me(e))throw Error("no answer given — nothing was added");return e}async function c1(t,e){let n=Jr(`Fetching ${nt(e)}`);try{return await Sa(t,e)}finally{n.done()}}async function qT(t,e,n){let r=await c1(t,n),i=W(t),o=Bt(i.markets),s=a1(t,o,n,r.id);if(s)throw Error(`${r.id} already names the market at ${nt(s)} — \`ttheme market remove ${r.id}\` first`);let{[e]:a,...c}=i.updates??{},u=a===void 0?c:{...c,[n]:a};return We(t,Ia(i,o.map((l)=>l===e?n:l),u)),as(t,r),r}async function Im(t,e){let n=Ar(e),r=Bt(W(t).markets);if(r.includes(n))return console.log(`${nt(n)} is already added`),{source:n,id:cs(t,n),fresh:!1};let i=ae(n)?r.find((c)=>ae(c)&&_o(c,n)):void 0;if(i){let c=await qT(t,i,n);return console.log(`Moved ${c.id} to ${Xs(n)??"its default branch"} · ${nt(n)} — ${Tt(It(c.entries).length)}`),{source:n,id:c.id,fresh:!1}}if(ut(n)){let c=ce(Ge(n));xm(t,n,c);let u=Xe(n,c,Oa(t)).length;return console.log(`Added ${c} · ${nt(n)} — ${Tt(u)}, read in place`),{source:n,id:c,fresh:!0}}let o=await c1(t,n),s=n===q?void 0:await DT(o.id);xm(t,n,o.id,s),as(t,o);let a=Tt(It(o.entries).length);return console.log(n===q?`Added the ttheme catalog — ${a}`:`Added ${o.id} · ${nt(n)} — ${a}${s?", updating on its own":""}`),{source:n,id:o.id,fresh:!0}}async function YT(t){let e=Q(),{source:n,id:r,fresh:i}=await Im(e,t);if(!i)return;if(ut(n))console.log("\n`ttheme browse` picks them · once the folder is on GitHub, `ttheme market add <owner>/<repo>` adds it anywhere");else if(n===q)console.log("\n`ttheme browse` picks them");else console.log(`
637
+ \`ttheme browse\` picks them, or \`ttheme add ${r}/<palette>\``)}function Rm(t,e){if(e===q)t1(Re(t),{force:!0});else if(ae(e))t1(Be(t,e),{force:!0})}function Pm(t){return`${Tt(t.length)} installed from it keep${t.length===1?"s":""} working: ${t.join(", ")} — \`ttheme remove\` drops ${t.length===1?"it":"them"}`}function JT(t){let e=Q(),n=W(e),r=Bt(n.markets),i=r.find((u)=>el(e,u)===t)??r.find((u)=>u===u1(t));if(!i)throw Error(`no market named ${t} — \`ttheme market\` lists them`);let o=el(e,i),s=n.palettes.filter((u)=>s1(u)===o),a=r.filter((u)=>u!==i),c=Ia(n,a,n.updates??{});if(We(e,c),Rm(e,i),qt(e,dt(e),c),console.log(`Removed ${o??t} · ${nt(i)}`),s.length>0)console.log(Pm(s))}function u1(t){try{return Ar(t)}catch{return}}function VT(t,e){try{if(e===q)return It(en(tl(Re(t),"utf8")).palettes).length;if(ut(e))return Xe(e,cs(t,e),Oa(t),ue(!1)).length;return Yn(e,tn(t,e),Oa(t),ue(!1)).entries.length}catch{return}}function Nm(t,e,n=rr(),r=Date.now()){if(ut(e))return"read in place";let i=n[e],o=ya(t,e);if(i&&(o===void 0||i.at>o))return`update failed ${Ea(i.at,r)}`;return o===void 0?"never updated":`updated ${Ea(o,r)}`}function ZT(){let t=Q(),e=W(t),n=Bt(e.markets);if(n.length===0){console.log("No markets — `ttheme market add official` brings the ttheme catalog back");return}let r=rr(),i=n.map((a)=>{let c=el(t,a)??"?",u=VT(t,a),l=e.palettes.filter((h)=>s1(h)===c).length,d=ut(a)?[]:[`auto-update ${Nr(a,e.updates)?"on":"off"}`],f=a===q?void 0:Ma(t,a)?.info.description;return{name:c,where:nt(a),about:f,note:[u===void 0?"Unreadable":Tt(u),...l>0?[`${l} installed`]:[],...d,Nm(t,a,r)].join(" · ")}}),o=Math.max(...i.map((a)=>a.name.length)),s=Math.max(...i.map((a)=>a.where.length));for(let a of i)if(console.log(` ${a.name.padEnd(o)} ${a.where.padEnd(s)} ${a.note}`),a.about)console.log(` ${" ".repeat(o)} ${a.about}`)}function Am(t){return`${t.owner.login.toLowerCase()}/${t.name}`}async function Tm(t,e){let n=encodeURIComponent(`topic:${Fo}${t?` ${t}`:""}`);try{let{items:r}=await ru(`https://api.github.com/search/repositories?q=${n}&sort=stars&per_page=50`,(i)=>JSON.parse(i),void 0,e);return r}catch(r){if(r instanceof nu)throw Error("GitHub lets a search through about ten times a minute without signing in — try again in a minute");throw r}}async function QT(t){let e=Q(),n=await Tm(t);if(n.length===0){console.log(`No repository carries the ${Fo} topic${t?` and matches ${t}`:""} yet`);return}let r=new Set(Bt(W(e).markets).map(Pr)),i=n.map((s)=>{let a=Am(s);return{arg:a,added:r.has(a),stars:`★${s.stargazers_count}`,about:s.description??""}}),o=Math.max(...i.map((s)=>s.arg.length));for(let s of i)console.log(` ${s.added?"●":"○"} ${s.arg.padEnd(o)} ${s.stars.padStart(5)} ${s.about}`);console.log("\n`ttheme market add <name>` adds one")}function l1({name:t}){return`ttheme-${t}`}function XT(t,e){BT(Yc(t),{recursive:!0}),F(xa(t,_t),V0(e)),F(xa(t,"README.md"),`# ${ce(e)}
638
638
 
639
639
  A [ttheme](https://github.com/kecan0406/ttheme) market:
640
640
 
641
641
  \`\`\`sh
642
- ttheme market add ${e.owner}/${uy(e)}
642
+ ttheme market add ${e.owner}/${l1(e)}
643
643
  ttheme browse
644
644
  \`\`\`
645
- `)}function ly(t){return ve(`x@${t}/x`)?"takes lowercase letters, digits and single hyphens":void 0}async function fy(){if(!Dh())throw Error("name the market: ttheme market init <name>, or --in <name> on new");let t=await Ad({message:"Your market's name — its palettes are <you>@<name>/<palette>",validate:(e)=>ly((e??"").toLowerCase())});if(fe(t))throw Error("no market name given");return t.toLowerCase()}async function dy(t,e){let n=pi(t);if(e){let o=n.find((a)=>a.name===e||a.id===e||a.dir===cy(e));if(!o)throw Error(`${e} is not one of your local markets — \`ttheme market init ${e}\` makes it one`);return o}let[r,...i]=n;if(r&&i.length===0)return r;if(r)throw Error(`you have ${n.length} local markets — --in names one: ${n.map((o)=>o.name).join(", ")}`);let s=await fy();return hy(t,td(t,s),s)}async function hy(t,e,n){let r=!Au(aa(e,Ft)),i;if(r){let o=ly(n);if(o)throw Error(`the market name ${n} ${o}`);if(Au(e)&&dA(e).length>0)throw Error(`${e} is not empty — pick a new folder for the market`);i={owner:await pA(t,L(t)),name:n},SA(e,i)}else i=Fe(e);let s=ne(i);return zh(t,e,s),console.log(`${r?"Made":"Added"} your market ${s} · ${Z(e)}`),{dir:e,...i,id:s}}function ey(t){return t.startsWith(".")||t.startsWith("/")||t.startsWith("~")}async function MA(t){let e=J(),n=t&&!ey(t)?t.toLowerCase():t?ry(yr(t)).toLowerCase():await fy(),r=t&&ey(t)?yr(t):td(e,n),i=await hy(e,r,n),s=`${i.owner}/${uy(i)}`;console.log(`
645
+ `)}function d1(t){return xe(`x@${t}/x`)?"takes lowercase letters, digits and single hyphens":void 0}async function f1(){if(!Om())throw Error("name the market: ttheme market init <name>, or --in <name> on new");let t=await fh({message:"Your market's name — its palettes are <you>@<name>/<palette>",validate:(e)=>d1((e??"").toLowerCase())});if(me(t))throw Error("no market name given");return t.toLowerCase()}async function h1(t,e){let n=Oi(t);if(e){let s=n.find((a)=>a.name===e||a.id===e||a.dir===u1(e));if(!s)throw Error(`${e} is not one of your local markets — \`ttheme market init ${e}\` makes it one`);return s}let[r,...i]=n;if(r&&i.length===0)return r;if(r)throw Error(`you have ${n.length} local markets — --in names one: ${n.map((s)=>s.name).join(", ")}`);let o=await f1();return m1(t,Tf(t,o),o)}async function m1(t,e,n){let r=!Xu(xa(e,_t)),i;if(r){let s=d1(n);if(s)throw Error(`the market name ${n} ${s}`);if(Xu(e)&&GT(e).length>0)throw Error(`${e} is not empty — pick a new folder for the market`);i={owner:await KT(t,W(t)),name:n},XT(e,i)}else i=Ge(e);let o=ce(i);return xm(t,e,o),console.log(`${r?"Made":"Added"} your market ${o} · ${nt(e)}`),{dir:e,...i,id:o}}function n1(t){return t.startsWith(".")||t.startsWith("/")||t.startsWith("~")}async function tH(t){let e=Q(),n=t&&!n1(t)?t.toLowerCase():t?i1(Ar(t)).toLowerCase():await f1(),r=t&&n1(t)?Ar(t):Tf(e,n),i=await m1(e,r,n),o=`${i.owner}/${l1(i)}`;console.log(`
646
646
  \`ttheme new <palette> --from <palette>\` puts palettes in it, and a folder under palettes/ shelves them in a catalog — others see them once it is on GitHub:
647
647
 
648
- cd ${Z(r)}
648
+ cd ${nt(r)}
649
649
  git init -b main && git add -A && git commit -m "${i.id}"
650
- gh repo create ${s} --public --source . --push
651
- gh repo edit ${s} --add-topic ${Es}
650
+ gh repo create ${o} --public --source . --push
651
+ gh repo edit ${o} --add-topic ${Fo}
652
652
 
653
- Every push is the market: \`ttheme market add ${s}\` works anywhere`)}function OA(t){let e=t?yr(t):process.cwd(),n=aa(e,Ft);if(!Au(n))throw Error(`${Z(e)} has no ${Ft} — \`ttheme market init ${Z(e)}\` makes one`);let r=[],i=[],s=Pu(n,"utf8"),o;try{o=Fe(e)}catch(h){return console.error(` ✗ ${h.message}`),1}let a=ai(s),c=a.owner;for(let h of Object.keys(a).filter((m)=>!Zw.includes(m)))i.push(`${Ft}: unknown key ${h} — ttheme ignores it`);for(let h of Object.keys(c).filter((m)=>!Qw.includes(m)))i.push(`${Ft}: unknown key owner.${h} — ttheme ignores it`);if(!o.description)i.push(`${Ft}: no description — browse and the market page show one`);let u=ne(o),l=qe(e,u,gA(J()),(h,m)=>r.push(`${ty(e,h)}: ${m.replace(`${ry(h)}: `,"")}`));for(let h of Os(e)){let m;try{m=nw(h.path,Pu(h.path,"utf8"))}catch{m=[]}for(let $ of m)i.push(`${ty(e,h.path)}: unknown key ${$} — ttheme ignores it`)}let f=Gk(o.renames,new Set(l.map((h)=>ae(h.name))));r.push(...f.errors.map((h)=>`${Ft}: ${h}`)),i.push(...f.warnings.map((h)=>`${Ft}: ${h}`));for(let h of l){let m=Co(h).filter((g)=>g.startsWith(" ✗")),$=h.catalog?`${h.catalog}/${ae(h.name)}`:ae(h.name);console.log(` ${$}${m.length>0?`
653
+ Every push is the market: \`ttheme market add ${o}\` works anywhere`)}function eH(t){let e=t?Ar(t):process.cwd(),n=xa(e,_t);if(!Xu(n))throw Error(`${nt(e)} has no ${_t} — \`ttheme market init ${nt(e)}\` makes one`);let r=[],i=[],o=tl(n,"utf8"),s;try{s=Ge(e)}catch(h){return console.error(` ✗ ${h.message}`),1}let a=wi(o),c=a.owner;for(let h of Object.keys(a).filter((m)=>!D0.includes(m)))i.push(`${_t}: unknown key ${h} — ttheme ignores it`);for(let h of Object.keys(c).filter((m)=>!q0.includes(m)))i.push(`${_t}: unknown key owner.${h} — ttheme ignores it`);if(!s.description)i.push(`${_t}: no description — browse and the market page show one`);let u=ce(s),l=Xe(e,u,zT(Q()),(h,m)=>r.push(`${e1(e,h)}: ${m.replace(`${i1(h)}: `,"")}`));for(let h of Bo(e)){let m;try{m=Zw(h.path,tl(h.path,"utf8"))}catch{m=[]}for(let g of m)i.push(`${e1(e,h.path)}: unknown key ${g} — ttheme ignores it`)}let d=Gy(s.renames,new Set(l.map((h)=>de(h.name))));r.push(...d.errors.map((h)=>`${_t}: ${h}`)),i.push(...d.warnings.map((h)=>`${_t}: ${h}`));for(let h of l){let m=ea(h).filter((b)=>b.startsWith(" ✗")),g=h.catalog?`${h.catalog}/${de(h.name)}`:de(h.name);console.log(` ${g}${m.length>0?`
654
654
  ${m.join(`
655
- `)}`:" passes the gate"}`)}for(let h of r)console.error(` ✗ ${h}`);for(let h of i)console.log(` ! ${h}`);let d=(h,m)=>`${h} ${m}${h===1?"":"s"}`;return console.log(`
656
- ${u} · ${Rt(l.length)} · ${d(r.length,"error")} · ${d(i.length,"warning")}`),r.length>0?1:0}async function my(t,e){switch(t){case void 0:vA();return;case"add":await $A(ny(t,e));return;case"remove":kA(ny(t,e));return;case"search":await EA(e);return;case"init":await MA(e);return;case"check":return OA(e);default:throw Error(`unknown market action ${t} — ${hA.join(", ")}, or none to list them`)}}function ny(t,e){if(!e)throw Error(t==="add"?"market add takes a repository or a folder: ttheme market add alice/ttheme-dust":"market remove takes a market name — `ttheme market` lists them");return e}function py(t,e){let n=zs(t,e);return`${n} — ${Rt(qe(e,n,ca(t),re(!1)).length)}, read in place`}var xA=new Intl.Segmenter(void 0,{granularity:"grapheme"});function gy(t){return[...t].length===1&&t>=" "&&t!==""}function IA(t){return[...t.replace(/[\r\n\t]+/g," ")].filter(gy).join("")}function Pi(t,e,n=()=>!0){if(e==="backspace")return[...xA.segment(t)].slice(0,-1).map((r)=>r.segment).join("");if(e==="ctrl-u")return"";if(e==="ctrl-w"||e==="alt-backspace")return t.replace(/\S*\s*$/,"");return gy(e)&&n(e)?t+e:void 0}class _r{value;constructor(t=""){this.value=t}key(t){let e=Pi(this.value,t);if(e===void 0)return!1;return this.value=e,!0}paste(t){this.value+=IA(t)}}import{performance as RA}from"node:perf_hooks";import{StringDecoder as NA}from"node:string_decoder";var TA=30,by=50,AA=500,PA=5,wy=Buffer.from("\x1B[M"),Cu="\x1B]1337;ReportCellSize\x07\x1B[16t\x1B[14t\x1B[18t",Sy={A:"up",B:"down",C:"right",D:"left",H:"home",F:"end","1~":"home","7~":"home","3~":"delete","4~":"end","8~":"end","5~":"pgup","6~":"pgdn",I:"focus-in",O:"focus-out",Z:"shift-tab","1;2C":"shift-right","1;2D":"shift-left"},HA={"\r":"enter","\n":"enter","\t":"tab","\b":"backspace","":"backspace","\x1B":"esc","\x00":"ctrl-space"},$y=/\[([0-?]*)([ -/]*)([@-~])/y,FA=/^\[[0-?]*[ -/]*$/,ky=/\](\d+)/y,CA=/^\]\d*$/,yy=/\]\d+;/y,LA=/^1337;ReportCellSize=([\d.]+);([\d.]+)(?:;([\d.]+))?$/,My="\x1B[200~",Fu="\x1B[201~";function Xh(t){let e=HA[t];if(e)return e;let n=t.codePointAt(0)??0;if(n<27)return`ctrl-${String.fromCharCode(n+96)}`;return n<32?void 0:t}function Ds(t){return{kind:"key",key:t}}function qs(t){return{events:[Ds("esc")],end:t+1}}function jA(t){let e={};for(let n of t.split(":")){let r=n.indexOf("=");if(r>0)e[n.slice(0,r)]=n.slice(r+1)}return e}var _A=["left","middle","right",void 0];function Oy(t,e,n,r){if(!Number.isInteger(t)||t<0||t>=128||!(e>=0)||!(n>=0))return;let i=t&3,s={kind:"mouse",row:n,col:e,shift:(t&4)!==0,alt:(t&8)!==0,ctrl:(t&16)!==0};if(t&64)return{...s,action:"wheel",button:void 0,wheel:i%2===0?-1:1,sideways:i>=2,count:0};let o=_A[i],a=t&32?o?"drag":"move":r||!o?"release":"press";return{...s,action:a,button:o,wheel:0,sideways:!1,count:a==="press"?1:0}}function GA(t,e,n){let r=[],i=e;while(r.length<3&&i<t.length){let u=t.codePointAt(i);r.push(u),i+=u>65535?2:1}if(r.length<3)return n?{events:[],end:t.length}:void 0;let[s=0,o=0,a=0]=r,c=Math.max(s,o,a)<128?Oy(s-32,o-33,a-33,!1):void 0;return{events:c?[c]:[],end:i}}function BA(t,e,n){if((n==="M"||n==="m")&&e===""&&t.startsWith("<")){let[i=-1,s=0,o=0]=t.slice(1).split(";").map(Number),a=Oy(i,s-1,o-1,n==="m");return a?[a]:[]}if(n==="t"&&e===""){let[i,s=0,o=0]=t.split(";").map(Number),a=i===6?"cell":i===4?"window":i===8?"grid":void 0;return a?[{kind:"size",of:a,h:s,w:o}]:[]}if(n==="y"&&e==="$"&&t.startsWith("?")){let[i=0,s=0]=t.slice(1).split(";").map(Number);return[{kind:"mode",mode:i,value:s}]}if(n==="c"&&t.startsWith("?"))return[{kind:"attributes"}];let r=e===""?Sy[`${t}${n}`]:void 0;return r?[Ds(r)]:[]}function UA(t,e,n){$y.lastIndex=e+1;let r=$y.exec(t);if(!r)return!n&&FA.test(t.slice(e+1))?void 0:qs(e);let[i,s="",o="",a=""]=r,c=e+1+i.length;if(s===""&&o===""&&a==="M")return GA(t,c,n);if(s==="200"&&a==="~"){let u=t.indexOf(Fu,c);if(u===-1)return n?{events:[{kind:"paste",text:t.slice(c)}],end:t.length}:void 0;return{events:[{kind:"paste",text:t.slice(c,u)}],end:u+Fu.length}}return{events:BA(s,o,a),end:c}}function WA(t){let e=LA.exec(t);if(e){let s=Number(e[3]??1);return[{kind:"size",of:"cell",h:Math.round(Number(e[1])*s),w:Math.round(Number(e[2])*s)}]}let[n="",r="",...i]=t.split(";");return[{kind:"osc",code:n,meta:jA(r),payload:i.join(";")}]}function KA(t,e,n){ky.lastIndex=e+1;let r=ky.exec(t),i=r?t[e+1+r[0].length]:void 0;if(i!==";"&&i!=="\x07"&&i!=="\x1B")return!n&&CA.test(t.slice(e+1))?void 0:qs(e);let s=[t.indexOf("\x07",e),t.indexOf("\x1B\\",e+2)].filter((a)=>a!==-1);if(s.length===0)return n?{events:[],end:t.length}:void 0;let o=Math.min(...s);return{events:WA(t.slice(e+2,o)),end:o+(t[o]==="\x07"?1:2)}}function zA(t,e,n){let r=t[e+2];if(r===void 0)return n?qs(e):void 0;if(!/^[A-Za-z]$/.test(r))return qs(e);let i=Sy[r];return{events:i?[Ds(i)]:[],end:e+3}}function DA(t,e,n){let r=t[e+1];if(r===void 0)return n?qs(e):void 0;if(r==="[")return UA(t,e,n);if(r==="]")return KA(t,e,n);if(r==="O")return zA(t,e,n);if(r==="")return{events:[Ds("alt-backspace")],end:e+2};if(/^[a-z]$/.test(r))return{events:[Ds(`alt-${r}`)],end:e+2};return qs(e)}function vy(t,e=!1){let n=[],r=0;while(r<t.length){if(t[r]==="\x1B"){let o=DA(t,r,e);if(!o)return{events:n,rest:t.slice(r)};n.push(...o.events),r=o.end;continue}let i=String.fromCodePoint(t.codePointAt(r)),s=Xh(i);if(s)n.push(Ds(s));r+=i.length}return{events:n,rest:""}}function qA(t){let e=t.indexOf(wy);if(e===-1)return{bytes:t,carry:void 0};let n=[],r=0;while(e!==-1&&e+6<=t.length){n.push(t.subarray(r,e));let[i=0,s=0,o=0]=t.subarray(e+3,e+6);if(s>32&&o>32)n.push(Buffer.from(`\x1B[<${i-32};${s-32};${o-32}M`));r=e+6,e=t.indexOf(wy,r)}return n.push(t.subarray(r,e===-1?t.length:e)),{bytes:Buffer.concat(n),carry:e===-1?void 0:t.subarray(e)}}function Ey(t){return yy.lastIndex=1,t.startsWith(My)||t.startsWith("\x1B]")&&yy.test(t)}function YA(t,e){let n=t.slice(-Fu.length)+e;return t.startsWith(My)?n.includes(Fu):n.includes("\x07")||n.includes("\x1B\\")}class tm{held="";timer;carry;pressed;wheeled;utf8=new NA("utf8");burst;take;constructor(t,e=()=>!1){this.burst=e,this.take=(n)=>{let r=this.counted(n);if(r.length>0)t(r)}}counted(t){let e=RA.now();return t.filter((n)=>{if(n.kind!=="mouse")return!0;if(n.action==="wheel"){let s=n.wheel*(n.sideways?2:1),o=this.wheeled;if(o!==void 0&&o.way===s&&e-o.at<PA)return!1;return this.wheeled={at:e,way:s},!0}if(n.action==="release")n.count=this.pressed?.count??0;if(n.action!=="press"||!n.button)return!0;let r=this.pressed,i=r!==void 0&&r.button===n.button&&r.row===n.row&&Math.abs(r.col-n.col)<=1&&e-r.at<=AA;return n.count=i?r.count+1:1,this.pressed={at:e,button:n.button,row:n.row,col:n.col,count:n.count},!0})}feed(t){clearTimeout(this.timer);let e=typeof t==="string"?t:this.bytes(t);if(this.carry)this.wait(by);if(!this.held&&!e.includes("\x1B")&&this.burst(e)){this.take([{kind:"paste",text:e}]);return}if(Ey(this.held)&&!YA(this.held,e)){this.held+=e;return}let{events:n,rest:r}=vy(this.held+e);if(this.held=r,r&&!Ey(r))this.wait(r.length===1?TA:by);if(n.length>0)this.take(n)}bytes(t){let{bytes:e,carry:n}=qA(this.carry?Buffer.concat([this.carry,t]):t);return this.carry=n,this.utf8.write(e)}wait(t){clearTimeout(this.timer),this.timer=setTimeout(()=>this.flush(),t)}flush(){clearTimeout(this.timer),this.carry=void 0;let{events:t}=vy(this.held,!0);if(this.held="",t.length>0)this.take(t)}stop(){clearTimeout(this.timer),this.held="",this.carry=void 0}}class la{window;grid;see(t){if(t.kind!=="size")return;if(t.of==="cell")return{w:t.w,h:t.h};if(t.of==="window")this.window=t;else this.grid=t;let e=this.window,n=this.grid;return e&&n&&n.h>0&&n.w>0?{h:Math.floor(e.h/n.h),w:Math.floor(e.w/n.w)}:void 0}}var ju={on:"\x1B[?1049h",off:"\x1B[?1049l"},Yn={on:"\x1B[?25l",off:"\x1B[?25h"},Hi={on:"\x1B[?7l",off:"\x1B[?7h"},Gr={on:"\x1B[?2004h",off:"\x1B[?2004l"},Ny={on:"\x1B[?1004h",off:"\x1B[?1004l"},JA={on:"\x1B[?1000h\x1B[?1002h\x1B[?1006h",off:"\x1B[?1006l\x1B[?1002l\x1B[?1000l"};function Js(t=process.env){return t.TTHEME_MOUSE==="off"?[]:[JA]}var Ty={SIGHUP:1,SIGINT:2,SIGQUIT:3,SIGTERM:15},VA=3000;class da extends Error{exit;constructor(t){super(t);this.exit=128+Ty[t]}}var kn=[],Ys=new Map,fa=new Map;function xy(t){return kn.findLast((e)=>e.input===t)}var Iy;function Ay(t){for(let e of[...kn].reverse())e.abort(t);if(!Iy)Iy=setTimeout(()=>{Py(),process.exit(t instanceof da?t.exit:1)},VA).unref()}var ZA=Object.fromEntries(Object.keys(Ty).map((t)=>[t,()=>Ay(new da(t))]));function Py(){for(let t of[...kn].reverse())t.close()}function QA(){for(let t of kn)t.reassert();kn.at(-1)?.redraw()}function Ry(t){let e=t?"on":"off";for(let[n,r]of Object.entries(ZA))process[e](n,r);if(process[e]("uncaughtException",Ay),process[e]("exit",Py),process.platform!=="win32")process[e]("SIGCONT",QA)}function Lu(){}class Hy{input;output;failed;modes=[];assumed;owned=[];keys;tty;take;resized;queued=[];asking;reject=Lu;open=!0;aborted=!1;constructor(t={}){if(this.input=t.input??process.stdin,this.output=t.output??process.stdout,this.tty=this.output.isTTY===!0&&this.input.isTTY===!0,this.assumed=t.assume??[],this.keys=new tm((r)=>this.deliver(r),t.burst),this.failed=new Promise((r,i)=>{this.reject=i}),this.failed.catch(Lu),this.tty&&!kn.some((r)=>r.tty))Ry(!0);kn.push(this);let e="";for(let r of this.assumed)if(!Ys.has(r))e+=r.on;for(let r of t.modes??[])e+=this.claim(r);this.write(e);let n=fa.get(this.input)??0;if(n===0)this.input.setRawMode?.(!0);fa.set(this.input,n+1),this.input.on("data",this.received),this.input.resume(),this.output.on("resize",this.resizing),this.output.on("error",Lu)}hold(t){this.write(this.claim(t))}get cols(){return this.output.columns||80}get rows(){return this.output.rows||24}write(t){if(t&&this.open)this.output.write(t)}listen(t){this.take=t;let e=this.queued;if(this.queued=[],e.length>0)t(e)}onResize(t){this.resized=t}until(t){return Promise.race([t,this.failed])}loop(t,e=()=>{}){return this.until(new Promise((n)=>{let r=!1;this.listen((i)=>{for(let s of i){let o=r?void 0:t(s);if(o!==void 0)r=!0,n(o)}if(!r)e()})}))}ask(t,e,n,r=!0){return new Promise((i)=>{let s={hold:r,pick:(c)=>{let u=e(c);if(u===void 0)return!1;return o(u),!0}},o=(c)=>{if(clearTimeout(a),this.asking===s)this.asking=void 0;i(c),this.release()},a=setTimeout(()=>o(void 0),n);this.asking=s,this.write(t)})}abort(t){if(this.aborted)return;this.aborted=!0,this.keys.stop(),this.reject(t)}redraw(){this.resized?.()}reassert(){if(this.open)this.input.setRawMode?.(!0),this.write([...this.assumed,...this.owned].map((t)=>t.on).join(""))}close(){if(!this.open)return;this.keys.stop(),this.input.off("data",this.received),this.output.off("resize",this.resizing);let t="";for(let n of[...this.modes].reverse()){let r=(Ys.get(n)??1)-1;if(r===0)Ys.delete(n),t+=n.off;else Ys.set(n,r)}this.write(t),this.open=!1;let e=(fa.get(this.input)??1)-1;if(e===0)fa.delete(this.input),this.input.setRawMode?.(!1),this.input.pause();else fa.set(this.input,e);if(this.output.off("error",Lu),kn.splice(kn.indexOf(this),1),this.tty&&!kn.some((n)=>n.tty))Ry(!1)}received=(t)=>{if(xy(this.input)===this&&!this.aborted)this.keys.feed(t)};resizing=()=>{if(xy(this.input)===this)this.resized?.()};claim(t){this.modes.push(t);let e=Ys.get(t)??0;if(Ys.set(t,e+1),e>0)return"";return this.owned.push(t),t.on}deliver(t){let e=this.asking,n=e?t.filter((r)=>!e.pick(r)):t;if(n.length===0)return;if(!this.take||this.asking?.hold){this.queued.push(...n);return}this.take(n)}release(){if(this.take&&this.queued.length>0){let t=this.queued;this.queued=[],this.take(t)}}}async function Br(t,e){let n=new Hy(t);try{return await e(n)}finally{n.close()}}var XA=3;function ha(t,e){return`${t}/${e}`}function Fy(t){return lt(t.name)?ae(t.name):t.name}function Vs(t){return t.catalog!==void 0&&Ly(t.group)?ha(t.group,t.catalog):void 0}function em(t){if(t?.kind==="palette")return`palette ${t.entry.name}`;if(t?.kind==="group")return`group ${t.name}`;if(t?.kind==="catalog")return`catalog ${ha(t.group,t.name)}`;return t?.kind??""}function _u(t,e){return di([t.name,t.group,t.native??"",t.catalog??"",...t.nativeNames??[],...bc(t.booru)],e)}function Cy(t,e,n){let r=n.trim(),i=[],s=new Set,o=(a)=>({kind:"palette",entry:a});for(let a of t){if(a.default||s.has(a.group))continue;s.add(a.group);let c=t.filter((d)=>!d.default&&d.group===a.group),u=r?c.filter((d)=>_u(d,r)):c;if(r&&u.length===0)continue;let l=r.length>0||e.has(a.group);if(i.push({kind:"group",name:a.group,native:a.native,lead:c.find((d)=>d.lead)??a,expanded:l,count:u.length}),!l)continue;let f=u.filter((d)=>Vs(d)!==void 0);for(let d of new Set(f.map((h)=>h.catalog))){let h=f.filter(($)=>$.catalog===d),m=r.length>0||e.has(ha(a.group,d));if(i.push({kind:"catalog",group:a.group,name:d,lead:h[0],expanded:m,count:h.length}),m)i.push(...h.map(o))}i.push(...u.filter((d)=>Vs(d)===void 0).map(o))}return i}function tP(t,e){let n=e.trim(),r=new Set(t.filter((i)=>!i.default&&(n===""||_u(i,n))).map((i)=>i.group));return Cy(t,new Set,"").filter((i)=>i.kind==="group"&&r.has(i.name))}function Ly(t){return t.includes("@")}function nm(t,e,n,r,i=!0){let s=n-1;if(s<0)return t;let o;if(!Number.isFinite(e))o=e>0?s:0;else if(e>0)o=t>=s?i?0:s:Math.min(s,t+e);else o=t<=0?i?s:0:Math.max(0,t+e);return r(o)?o+Math.sign(e):o}function Gu(t,e){let n={home:Number.NEGATIVE_INFINITY,end:Number.POSITIVE_INFINITY,pgup:-e,pgdn:e};return t===void 0?void 0:n[t]}function eP(t){let e=t.findIndex((n)=>n.kind==="group"&&Ly(n.name));return e>0&&t.slice(0,e).some((n)=>n.kind==="group")?[...t.slice(0,e),{kind:"rule"},...t.slice(e)]:t}function nP(t){let e=t.findIndex((n)=>n.kind==="palette");return e===-1?0:e}function Bu(t){return t==="decode"||t==="glitch"?t:"typewriter"}function Zs(t,e,n){return le({kind:"row",at:t,part:e},n)}class ma{picked;scope;maxItems;named=[];series=[];color;onFocus;entries=[];seriesPad=0;namePad=0;expanded=new Set;rows=[];cursor=0;top=0;filter="";lastFocused="";constructor(t){this.picked=t.picked,this.scope=t.scope??"palette",this.maxItems=t.maxItems??12,this.color=t.color??!0,this.onFocus=t.onFocus,this.load(t.entries),this.rebuild("first")}load(t){this.entries=t,this.named=t.filter((e)=>!e.default),this.series=[...new Set(this.named.map((e)=>e.group))],this.seriesPad=Math.max(0,...this.series.map((e)=>e.length)),this.namePad=Math.max(0,...this.named.map((e)=>this.indent(e).length+Fy(e).length))}indent(t){return Vs(t)===void 0?" ":" "}setEntries(t){this.load(t),this.rebuild("stay")}setFilter(t){if(t!==this.filter)this.filter=t,this.rebuild("keep")}clear(){let t=this.rows[this.cursor];if(t?.kind==="palette"&&!t.entry.default){this.expanded.add(t.entry.group);let e=Vs(t.entry);if(e!==void 0)this.expanded.add(e)}this.setFilter("")}focusedRow(){return this.rows[this.cursor]}refocus(){this.lastFocused="",this.sync()}members(t,e){let n=this.scope==="palette"?this.filter.trim():"";return this.named.filter((r)=>r.group===t&&(e===void 0||r.catalog===e)&&(n===""||_u(r,n)))}everyone(t){return t.flatMap((e)=>e.kind==="group"?this.members(e.name):[])}pick(){let t=this.rows[this.cursor],e=t?.kind==="palette"?[t.entry.name]:t?.kind==="group"?this.members(t.name).map((r)=>r.name):t?.kind==="catalog"?this.members(t.group,t.name).map((r)=>r.name):t?.kind==="all"?this.everyone(this.rows).map((r)=>r.name):[];if(e.length===0)return;let n=e.some((r)=>!this.picked.has(r));for(let r of e)if(n)this.picked.add(r);else this.picked.delete(r)}pickedIn(t,e){return this.members(t,e).filter((n)=>this.picked.has(n.name)).length}pickedCount(){if(this.scope==="palette")return this.named.filter((t)=>this.picked.has(t.name)).length;return this.series.filter((t)=>this.members(t).every((e)=>this.picked.has(e.name))).length}total(){return this.scope==="series"?this.series.length:this.named.length}matched(){let t=this.filter.trim();if(this.scope==="series")return this.rows.filter((e)=>e.kind==="group").length;return t?this.named.filter((e)=>_u(e,t)).length:this.named.length}sync(){let t=this.rows[this.cursor],e=t?.kind==="palette"?t.entry:t?.kind==="group"&&this.scope==="series"?t.lead:void 0;if(e&&e.name!==this.lastFocused)this.lastFocused=e.name,this.onFocus?.(e)}rebuild(t){let e=this.rows[this.cursor],n=this.scope==="series"?tP(this.entries,this.filter):Cy(this.entries,this.expanded,this.filter);this.rows=n.length>0?eP([{kind:"all",count:this.allCount(n)},...n]):[];let r=n.length>0?this.rows.indexOf(n[nP(n)]):0;if(t==="first")this.cursor=r;else if(t==="keep"||t==="stay"){let i=em(e),s=e?.kind==="palette"||t==="stay"?this.rows.findIndex((o)=>em(o)===i):-1;this.cursor=s===-1?r:s}else if(this.cursor>=this.rows.length)this.cursor=Math.max(0,this.rows.length-1);this.sync()}allCount(t){return this.scope==="series"?t.length:this.everyone(t).length}move(t,e=!0){this.cursor=nm(this.cursor,t,this.rows.length,(n)=>this.rows[n]?.kind==="rule",e),this.sync()}point(t){let e=this.rows[t];if(!e||e.kind==="rule")return!1;return this.cursor=t,this.sync(),!0}flip(){let t=this.rows[this.cursor];if(t?.kind==="group"||t?.kind==="catalog")this.fold(!t.expanded)}foldable(){let t=this.rows[this.cursor];return(t?.kind==="group"||t?.kind==="catalog")&&this.scope==="palette"&&!this.filter}open(){if(this.foldable())this.flip();else this.pick()}toggle(t){if(this.expanded.has(t))this.expanded.delete(t);else this.expanded.add(t);this.rebuild("clamp")}climb(t,e){this.expanded.delete(t),this.rebuild("clamp"),this.reach(e)}reach(t){this.cursor=Math.max(0,this.rows.findIndex((e)=>em(e)===t)),this.sync()}fold(t){if(this.filter||this.scope==="series")return;let e=this.rows[this.cursor];if(e?.kind==="group"){if(t!==e.expanded)this.toggle(e.name)}else if(e?.kind==="catalog"){if(t!==e.expanded)this.toggle(ha(e.group,e.name));else if(!t)this.reach(`group ${e.group}`)}else if(e?.kind==="palette"&&!t&&!e.entry.default){let n=Vs(e.entry);if(n===void 0)this.climb(e.entry.group,`group ${e.entry.group}`);else this.climb(n,`catalog ${n}`)}}window(){if(this.cursor<this.top)this.top=this.cursor;if(this.cursor>=this.top+this.maxItems)this.top=this.cursor-this.maxItems+1;this.top=Math.min(this.top,Math.max(0,this.rows.length-this.maxItems));let t=this.rows.slice(this.top,this.top+this.maxItems);return{lines:t.map((e,n)=>this.renderRow(e,this.top+n)),above:this.top,below:this.rows.length-this.top-t.length}}renderRow(t,e){if(t.kind==="rule")return` ${this.color?`${A}${"── Markets ──────────"}${At}`:"── Markets ──────────"}`;return Zs(e,"row",this.rowText(t,e))}rowText(t,e){let n=e===this.cursor,r=t.kind==="palette"?t.entry:t.kind==="all"?void 0:t.lead,i=this.color&&n&&r!==void 0,s=(E)=>this.color?`${A}${E}${ge}`:E,o=(E)=>this.color?`${at}${E}${ge}`:E,a=(E)=>this.color?` ${Up(hc(E),i?Be(E.foreground):"\x1B[39m")}`:"",c=n?i?`${Be(r.cursor)}▌\x1B[39m `:"▌ ":" ",u=(E)=>i?`${c}${Ga(r.selection,r.foreground)} ${E} ${At}`:`${c} ${E}`,l=(E)=>Zs(e,"box",`${E?"●":"○"} `),f=(E)=>Zs(e,"fold",`${E?"▾":"▸"} `);if(t.kind==="all")return u(`${l(this.everyone(this.rows).every((E)=>this.picked.has(E.name)))}Select all ${s(`(${t.count})`)}`);if(t.kind==="group"&&this.scope==="series"){let E=`(${t.count})${t.native?` ${t.native}`:""}`;return u(`${l(this.pickedIn(t.name)===t.count)}${o(t.name.padEnd(this.seriesPad))}${a(t.lead)}${this.color?" ":" "}${s(E)}`)}let d=this.rows[this.cursor],h=(E,S)=>this.color&&d?.kind==="palette"&&E?`${at}${Be(d.entry.cursor)}${S}${ge}\x1B[39m`:o(S);if(t.kind==="group"){let E=h(d?.kind==="palette"&&d.entry.group===t.name,t.name),S=t.native?` ${s(t.native)}`:"";return u(`${f(t.expanded)}${E} ${s(`(${this.pickedIn(t.name)}/${t.count})`)}${S}`)}if(t.kind==="catalog"){let E=d?.kind==="palette"&&Vs(d.entry)===ha(t.group,t.name),S=s(`(${this.pickedIn(t.group,t.name)}/${t.count})`);return u(` ${f(t.expanded)}${h(E,t.name)} ${S}`)}let m=t.entry,$=this.indent(m),g=Fy(m),b=this.color?g.padEnd(this.namePad-$.length):g,y=n?o(b):b;return u(`${$}${l(this.picked.has(m.name))}${y}${a(m)}`)}}function rm(t){let e=t.named[Math.floor(Math.random()*t.named.length)],n=t.series[Math.floor(Math.random()*t.series.length)];return e&&n?`${e.name} | ${n}`:""}class Uu{fx;make;redraw;roller;example="";step=0;seed=0;timer;constructor(t,e,n){this.fx=t,this.make=e,this.redraw=n,this.roll(),this.roller=setInterval(()=>{this.roll(),this.step=8,this.redraw()},3000),this.roller.unref?.()}stop(){clearInterval(this.roller),clearTimeout(this.timer)}roll(){let t=this.make();this.example=t.length>30?`${t.slice(0,29)}…`:t,this.seed=Math.floor(Math.random()*997)}text(){if(this.step===0)return this.example;if(!this.timer)this.timer=setTimeout(()=>{this.timer=void 0,this.step-=1,this.redraw()},60),this.timer.unref?.();let t=Math.floor(this.example.length*(8-this.step)/8);if(this.fx==="typewriter")return`${this.example.slice(0,t)}▏`;let e=this.fx==="decode"?"abcdefghijklmnopqrstuvwxyz":"▓▒░#*+=<>?/-_",n=this.fx==="decode"?(r)=>!/[a-z0-9]/i.test(r):(r)=>r===" ";return[...this.example].map((r,i)=>i+(i*7+this.seed)%3<t||n(r)?r:e[Math.floor(Math.random()*e.length)]??r).join("")}}var rP=5;class im{picked;list;scope;color;required;most;hint;field=new _r;input;output;state="active";error="";redraw=()=>{};constructor(t){this.scope=t.scope??"palette",this.picked=new Set(t.installed??[]),this.color=t.color??!0,this.required=t.required??!1,this.most=t.maxItems??12,this.input=t.input,this.output=t.output,this.list=new ma({entries:t.entries,picked:this.picked,scope:this.scope,maxItems:this.most,color:this.color,...t.onFocus?{onFocus:t.onFocus}:{}}),this.hint=new Uu(t.fx??"typewriter",()=>rm(this.list),()=>this.redraw())}prompt(){return Br({input:this.input,output:this.output,modes:[Yn,Gr]},async(t)=>{let e=new Nh((r)=>t.write(r),()=>t.cols),n=()=>{return this.list.maxItems=Math.max(XA,Math.min(this.most,t.rows-rP)),this.draw()};this.redraw=()=>e.draw(n()),t.onResize(()=>e.redraw(n())),this.redraw();try{let r=await t.loop((i)=>{return this.take(i),this.state==="submit"||this.state==="cancel"?this.state:void 0},()=>this.redraw());return this.redraw=()=>{},e.end(this.draw()),r}finally{this.hint.stop()}})}take(t){if(t.kind==="paste"){this.field.paste(t.text),this.list.setFilter(this.field.value);return}if(t.kind!=="key")return;let e=t.key;if(this.state==="error")this.state="active";let n=Gu(e,this.list.maxItems);if(e==="esc"||e==="ctrl-c")this.state="cancel";else if(e==="enter")if(this.required&&this.picked.size===0)this.error=`Pick at least one ${this.scope}`,this.state="error";else this.state="submit";else if(e==="up"||e==="down")this.list.move(e==="up"?-1:1);else if(e==="left"||e==="right")this.list.fold(e==="right");else if(n!==void 0)this.list.move(n);else if(e===" ")this.list.pick();else if(this.field.key(e))this.list.setFilter(this.field.value)}draw(){let t=(m)=>this.color?`${A}${m}${At}`:m,e=(m)=>this.color?`${Ba}${m}${At}`:m,n=this.scope==="series"?"Series":"Catalog";if(this.state==="submit")return[`${t("◇")} ${n} ${t(`· ${this.list.pickedCount()} picked`)}`];if(this.state==="cancel")return[`${t(`◇ ${n} · cancelled`)}`];let r=this.field.value,i=`${e("◆")} ${n} ${t(`(${this.list.matched()}/${this.list.total()} · ${this.list.pickedCount()} picked)`)}`,s=this.hint.text(),o=`${e("│")} ${r?`${r}_`:t(`Search…${s?` e.g. ${s}`:""}`)}`,{lines:a,below:c}=this.list.window(),u=a.length>0?a.map((m)=>`${e("│")} ${m}`):[`${e("│")} ${t(`No ${this.scope==="series"?"series":"palettes"} match '${r}'`)}`];while(u.length<this.list.maxItems)u.push(e("│"));let l=c>0?`${e("│")} ${t(`↓ ${c} more`)}`:e("│"),f=this.scope==="series"?"":" · ←→ fold",d=this.scope==="series"?"continue":"install",h=this.state==="error"?`${e("└")} ${this.color?`${Vt}${this.error}${At}`:this.error}`:`${e("└")} ${t(`↑↓ move${f} · space pick · type to filter · enter ${d} · esc cancel`)}`;return[i,o,...u,l,h]}}var Qs=[{tab:"catalog",title:"Catalog",heading:"Discover palettes"},{tab:"installed",title:"Installed",heading:"Installed palettes"},{tab:"markets",title:"Markets",heading:"Manage markets"},{tab:"errors",title:"Errors",heading:"Problems"}],sm=34,iP=72,sP=94,oP=22,jy=40,_y=10,Gy=3,aP=600,cP=500,uP=300,By=12,lP="\x1B[7;1m",om={title:"",lines:[],brief:""};function pa(t){let e=t.trim();if(e!==z&&!e.includes("/")&&!e.startsWith("~"))return;try{return yr(e)}catch{return}}function fP(t){return t.charAt(0).toUpperCase()+t.slice(1)}class am{picked;tab="catalog";fields={catalog:new _r,installed:new _r,markets:new _r,errors:new _r};cursor={markets:0,errors:0};top={markets:0,errors:0};adds=new Map;removes=new Set;want=new Map;scope={catalog:void 0,installed:void 0};busy=new Map;failed=new Map;peeked=new Map;peekFailed=new Map;staging=new Set;timers=new Map;refreshed=[];inflight=new Set;markets;problems;kept;installed;startup;io;order;color;hub;owns;input;output;maxItems=12;paint;catalog;mine;hint;screen;state="active";phase="browse";offset=0;started=!1;log=[];working="";stopped;beat=0;asking;leaving;goto;repos;searching=!1;searchError;searched;asked=0;help=!1;worn;live;constructor(t){this.markets=t.markets,this.problems=t.problems,this.kept=t.kept,this.installed=new Set(t.installed),this.startup=t.startup,this.io=t.io,this.order=t.order??((n)=>n),this.color=t.color??!0,this.hub=t.hub,this.owns=t.owns??!1,this.input=t.input,this.output=t.output,this.live=t.lookups??!0,this.paint=t.onFocus,this.picked=new Set(t.installed);let e=this.entries();this.catalog=new ma({entries:e,picked:this.picked,color:this.color,maxItems:this.maxItems,onFocus:(n)=>this.focus("catalog",n)}),this.mine=new ma({entries:this.mineOf(e),picked:this.picked,color:this.color,maxItems:this.maxItems,onFocus:(n)=>this.focus("installed",n)}),this.hint=new Uu(t.fx??"typewriter",()=>rm(this.tab==="installed"?this.mine:this.catalog),()=>this.redraw());for(let n of t.due)this.update(n)}run(){let t=[...this.owns?[ju,Yn,Hi]:[],Gr,...Js()],e=this.owns?[]:[Yn,Hi];return Br({input:this.input,output:this.output,modes:t,assume:e},async(n)=>{let r=new Ri({write:(i)=>n.write(i),view:()=>this.state==="active"?{lines:this.view(),ticking:this.phase==="applying"}:void 0,beat:()=>{this.beat+=1}});this.screen=r,n.onResize(()=>{r.reset(),r.request()}),r.now();try{return await n.loop((i)=>{if(i.kind==="key")this.key(i.key);else if(i.kind==="paste")this.pasted(i.text);else if(i.kind==="mouse")this.mouse(i,r);return this.state==="active"?void 0:this.state},()=>r.soon())}finally{r.stop(),this.screen=void 0,this.hint.stop();for(let i of this.timers.values())clearTimeout(i);this.timers.clear()}})}applied(){return this.started}lines(){return this.log}failure(){return this.stopped}next(){return this.goto}async idle(){await Promise.allSettled([...this.inflight])}result(){let t=new Set(this.entries().map((e)=>e.name));return{picked:new Set([...this.picked].filter((e)=>t.has(e))),adds:[...this.adds.values()],removes:[...this.removes],auto:Object.fromEntries(this.want),refreshed:this.refreshed}}key(t){if(t==="ctrl-c"){this.state="cancel";return}if(this.help){if(t==="?"||t==="esc")this.help=!1;return}if(this.leaving!==void 0){if(t==="esc")this.leaving=void 0;else if(/^[yn]$/i.test(t)){if(t.toLowerCase()==="y")this.begin();else this.goto=this.leaving,this.state="cancel";this.leaving=void 0}return}if(this.asking){if(t==="esc")this.asking=void 0;else if(/^[yn]$/i.test(t))this.answer(t.toLowerCase()==="y");return}if(this.phase!=="browse"){this.steer(t);return}let e=Gu(t,this.maxItems),n=this.list();if(t==="enter")if(n?.foldable())n.flip();else if(this.dirty())this.phase="review",this.offset=0;else this.state="submit";else if((t==="esc"||t==="ctrl-u")&&this.fields[this.tab].value)this.clear();else if(t==="esc")this.state="cancel";else if(t==="?")this.help=!0;else if(e!==void 0)this.move(e);else if(t==="up"||t==="down")this.move(t==="up"?-1:1);else if(t==="left"||t==="right")this.side(t==="right");else if(t==="tab"||t==="shift-tab"){if(this.hub)this.leave(R0(this.hub,t==="tab"?1:-1))}else if(t==="shift-left"||t==="shift-right")this.switchTab(t==="shift-right"?1:-1);else if(t===" ")this.activate();else if(t==="ctrl-r"){let r=this.tab==="markets"?this.marketRow():void 0;if(r?.kind==="market"&&!this.adds.has(r.market.source))this.update(r.market.source);else if(r?.kind==="find")this.search()}else if(t==="ctrl-s")this.cycle();else if(this.fields[this.tab].key(t))this.typed()}pasted(t){if(this.phase==="browse"&&!this.help&&!this.asking&&this.leaving===void 0)this.fields[this.tab].paste(t),this.typed()}mouse(t,e){if(this.help){if(t.action==="release")this.help=!1;return}let n=e.point(t),r=n?.target,i=this.phase==="browse"&&this.leaving===void 0&&!this.asking;if(t.action==="wheel"){if(!t.sideways&&(i||this.phase!=="browse"))this.wheel(t.wheel);return}if(!r)return;if(t.action==="press"&&t.button==="left"){if(!i)return;if(r.kind==="tab")this.show(r.tab);else if(r.kind==="chip")this.scopeTo(r.source);else if(r.kind==="row")this.pointRow(r.at)}else if(t.action==="release"&&n?.inside){if(r.kind==="key")this.key(r.key);else if(r.kind==="page"){if(this.phase!=="browse")this.scroll(r.step*this.span());else if(i)this.move(r.step*this.maxItems)}else if(r.kind==="hub"){if(i&&this.hub&&r.tab!==this.hub)this.leave(N0(r.tab))}else if(r.kind==="row"&&i)this.openRow(r,t.count)}}wheel(t){if(this.phase!=="browse"){this.scroll(t);return}let e=this.list();if(e)e.move(t,!1);else this.move(t,!1)}pointRow(t){let e=this.list();if(e){e.point(t);return}this.cursor[this.tab==="markets"?"markets":"errors"]=t,this.watch()}openRow(t,e){let n=this.list();if(n){if(t.part==="box")n.pick();else if(t.part==="fold")n.flip();else if(e===2)n.open()}else if(t.part==="box"||e===2)this.activate()}typed(){let t=this.fields[this.tab].value;if(this.list()?.setFilter(t),this.tab==="markets")this.later("search",aP,()=>this.lookup()),this.watch()}clear(){this.fields[this.tab].value="";let t=this.list();if(t)t.clear();else this.typed()}redraw(){if(this.state==="active")this.screen?.request()}focus(t,e){if(this.tab===t&&this.state!=="submit"&&this.state!=="cancel")this.worn=e,this.paint?.(e)}track(t){this.inflight.add(t);let e=()=>this.inflight.delete(t);return t.then(e,e),t}list(){return this.tab==="catalog"?this.catalog:this.tab==="installed"?this.mine:void 0}active(){return[...this.markets.filter((t)=>!this.removes.has(t.source)),...this.adds.values()]}entries(){let t=this.active().flatMap((i)=>i.entries),e=new Set(t.map((i)=>i.name)),n=new Map,r=this.markets.filter((i)=>this.removes.has(i.source)).flatMap((i)=>i.entries);for(let i of[...this.kept,...r])if(this.installed.has(i.name)&&!e.has(i.name))n.set(i.name,i);return this.order([...t,...n.values()])}mineOf(t){return t.filter((e)=>this.installed.has(e.name))}scoped(t,e){let n=this.scope[e],r=n===void 0?void 0:this.active().find((s)=>s.source===n);if(!r)return this.scope[e]=void 0,t;let i=new Set(r.entries.map((s)=>s.name));return t.filter((s)=>i.has(s.name))}reload(){let t=this.entries();this.catalog.setEntries(this.scoped(t,"catalog")),this.mine.setEntries(this.scoped(this.mineOf(t),"installed"))}chips(t){let e=t==="catalog"?this.entries():this.mineOf(this.entries()),n=this.active().map((r)=>({source:r.source,label:r.id,count:r.entries.filter((i)=>!i.default&&(t==="catalog"||this.installed.has(i.name))).length})).filter((r)=>t==="catalog"||r.count>0||r.source===this.scope[t]);return[{source:void 0,label:"All",count:e.filter((r)=>!r.default).length},...n]}cycle(){let t=this.tab;if(t!=="catalog"&&t!=="installed"||this.active().length<2)return;let e=this.chips(t),n=Math.max(0,e.findIndex((r)=>r.source===this.scope[t]));this.scopeTo(e[(n+1)%e.length]?.source)}scopeTo(t){let e=this.tab;if(e!=="catalog"&&e!=="installed")return;this.scope[e]=t,this.reload(),this.list()?.refocus()}switchTab(t){let e=Qs.findIndex((n)=>n.tab===this.tab);this.show(Qs[(e+t+Qs.length)%Qs.length]?.tab??"catalog")}show(t){if(this.tab=t,this.list()?.refocus(),t==="markets")this.lookup(),this.watch()}move(t,e=!0){let n=this.list();if(n){n.move(t,e);return}let r=this.tab==="markets"?"markets":"errors",i=r==="markets"?this.marketRows().map((s)=>s.kind==="rule"):this.problemRows().map(()=>!1);this.cursor[r]=nm(this.cursor[r],t,i.length,(s)=>i[s]===!0,e),this.watch()}side(t){let e=this.list();if(e){e.fold(t);return}let n=this.tab==="markets"?this.marketRow():void 0;if(n?.kind==="market"&&!ct(n.market.source))if(t===n.market.auto)this.want.delete(n.market.source);else this.want.set(n.market.source,t)}activate(){let t=this.list();if(t){t.pick();return}let e=this.tab==="markets"?this.marketRow():void 0;if(e?.kind==="market")this.toggleMarket(e.market);else if(e?.kind==="add")this.load(e.source,!0);else if(e?.kind==="repo"){let n=this.known(e.source),r=this.marketRows().findIndex((i)=>i.kind==="market"&&i.market===n);if(n&&r>=0)this.cursor.markets=r;else if(!n)this.load(e.source,!0)}else if(e?.kind==="find")this.search()}toggleMarket(t){if(this.adds.has(t.source))this.adds.delete(t.source),this.want.delete(t.source);else if(this.removes.has(t.source))this.removes.delete(t.source);else this.removes.add(t.source);this.reload()}known(t){return[...this.markets,...this.adds.values()].find((e)=>Ms(e.source,t))}load(t,e){let n=this.peeked.get(t);if(n){if(e)this.arrive(t,n);return}if(e)this.staging.add(t);if(this.busy.has(t))return;this.failed.delete(t),this.peekFailed.delete(t),this.busy.set(t,"Fetching…"),this.track(this.io.fetch(t)).then((r)=>{if(this.busy.delete(t),this.peeked.set(t,r),this.staging.delete(t))this.arrive(t,r);this.redraw()},(r)=>{if(this.busy.delete(t),this.staging.delete(t))this.failed.set(t,r.message);else this.peekFailed.set(t,r.message);this.redraw()})}arrive(t,e){let n=this.active().find((r)=>r.id===e.id);if(n)this.failed.set(t,`${e.id} already names the market at ${n.shown}`);else if(ct(t)||t===z)this.stage(e,e.auto);else this.asking=e;this.redraw()}later(t,e,n){this.cancel(t),this.timers.set(t,setTimeout(()=>{if(this.timers.delete(t),this.state!=="submit"&&this.state!=="cancel")n()},e))}cancel(t){clearTimeout(this.timers.get(t)),this.timers.delete(t)}wants(t){return!this.known(t)&&!this.peeked.has(t)&&!this.busy.has(t)&&!this.peekFailed.has(t)}watch(){if(!this.live||this.tab!=="markets")return;let t=pa(this.fields.markets.value);if(t&&this.wants(t))this.later("typed",cP,()=>this.load(t,!1));else this.cancel("typed");let e=this.marketRow();if(e?.kind==="repo"&&this.wants(e.source)){let n=e.source;this.later("focus",uP,()=>{let r=this.marketRow();if(this.tab==="markets"&&r?.kind==="repo"&&r.source===n)this.load(n,!1)})}else this.cancel("focus")}answer(t){let e=this.asking;if(this.asking=void 0,e)this.stage(e,t)}stage(t,e){if(this.adds.set(t.source,t),e===t.auto)this.want.delete(t.source);else this.want.set(t.source,e);this.reload(),this.cursor.markets=Math.max(0,this.marketRows().findIndex((n)=>n.kind==="market"&&n.market.source===t.source))}update(t){if(this.busy.has(t))return;this.failed.delete(t),this.busy.set(t,"Updating…"),this.track(this.io.refresh(t)).then(({market:e,refreshed:n})=>{this.busy.delete(t),this.markets=this.markets.map((r)=>r.source===t?e:r),this.problems=this.problems.filter((r)=>r.source!==t),this.refreshed.push(n),this.reload(),this.redraw()},(e)=>{this.busy.delete(t),this.failed.set(t,`Update failed: ${e.message}`),this.redraw()})}wanted(){let t=this.fields.markets.value.trim();return t&&!pa(t)?t:""}lookup(){if(this.live&&this.searched!==this.wanted())this.search()}search(){let t=this.wanted(),e=++this.asked;this.searched=t,this.searching=!0,this.searchError=void 0,this.track(this.io.search(t||void 0)).then((n)=>{if(e===this.asked)this.searching=!1,this.repos=n,this.watch(),this.redraw()},(n)=>{if(e===this.asked)this.searching=!1,this.searchError=n.message,this.redraw()})}marketRows(){let t=(...s)=>di(s,this.fields.markets.value),e=[...this.markets,...this.adds.values()],n=e.filter((s)=>t(s.id,s.shown,s.source)).map((s)=>({kind:"market",market:s})),r=pa(this.fields.markets.value);if(r&&!e.some((s)=>Ms(s.source,r)))n.push({kind:"add",source:r});let i=(this.repos??[]).map((s)=>({repo:s,source:Zh(s)})).filter(({repo:s,source:o})=>t(o,s.description??""));return n.push({kind:"rule"},...i.length>0?i.map(({repo:s,source:o})=>({kind:"repo",repo:s,source:o})):[{kind:"find"}]),n}marketRow(){let t=this.marketRows();return t[this.at(t,"markets",(e)=>e?.kind==="rule")]}problemList(){let t=new Map([...this.markets,...this.adds.values()].map((e)=>[e.source,e.id]));return[...this.problems.filter((e)=>!(e.update&&e.source&&this.failed.has(e.source))),...[...this.failed].map(([e,n])=>({where:t.get(e)??e,message:n,source:e}))]}problemRows(){return this.problemList().filter((t)=>di([`${t.where} ${t.message}`],this.fields.errors.value))}at(t,e,n=()=>!1){let r=Math.min(this.cursor[e],Math.max(0,t.length-1));if(!n(t[r]))return r;return r>0?r-1:r+1}windowOf(t,e,n,r=()=>!1){let i=this.at(t,e,r);this.cursor[e]=i;let s=(l)=>r(t[l])?1:2,o=(l,f)=>{let d=0;for(let h=l;h<=f;h++)d+=s(h);return d},a=Math.min(this.top[e],i);while(a<i&&o(a,i)>this.maxItems)a+=1;while(a>0&&o(a-1,t.length-1)<=this.maxItems)a-=1;this.top[e]=a;let c=[],u=0;for(let l=a;l<t.length&&u+s(l)<=this.maxItems;l++)c.push(l),u+=s(l);return{lines:c.flatMap((l)=>{let f=n(t[l],l===i,l);return r(t[l])?f:f.map((d)=>Zs(l,"row",d))}),above:a,below:t.length-a-c.length}}dim(t){return this.color?`${A}${t}${ge}`:t}bold(t){return this.color?`${at}${t}${ge}`:t}warn(t){return this.color?`${Vt}${t}\x1B[39m`:t}lit(t,e,n){if(e&&this.color&&t)return`${Be(t.cursor)}▌\x1B[39m ${Ga(t.selection,t.foreground)} ${n} ${At}`;return`${e?"▌ ":" "} ${n}`}status(t){return this.adds.has(t.source)?"Will add":this.removes.has(t.source)?"Will remove":this.busy.get(t.source)??(this.failed.has(t.source)||t.status.startsWith("update failed")?"Update failed":"")}note(t){return` ${this.dim(t)}`}peeking(t){let e=this.peeked.get(t);return e?Rt(e.entries.filter((n)=>!n.default).length):""}marketLine(t,e,n){let r=(s)=>Zs(n,"box",`${s} `);if(t.kind==="rule")return[` ${this.dim(`── On GitHub${this.searching?" · searching…":""} ──────────`)}`];if(t.kind==="market"){let s=t.market,o=this.status(s),a=e?this.bold(s.id):s.id,c=s.entries.filter((l)=>!l.default),u=!ct(s.source)&&(this.want.get(s.source)??s.auto)?` ${this.dim("↻ auto-update")}`:"";return[this.lit(s.entries.find((l)=>!l.default),e,`${r(this.removes.has(s.source)?"○":"●")}${a}${u}${o?` ${this.dim(o)}`:""}`),this.note([s.source===z?"The ttheme catalog":ct(s.source)?s.shown:s.source,Rt(c.length),`${c.filter((l)=>this.installed.has(l.name)).length} installed`,s.status].join(" · "))]}if(t.kind==="add"){let s=this.busy.get(t.source),o=this.failed.get(t.source)??this.peekFailed.get(t.source),a=this.peeked.get(t.source);return[this.lit(void 0,e,`${r("+")}Add ${Z(t.source)}${s?` ${this.dim(s)}`:""}`),o?` ${this.warn(o)}`:this.note(a?`${a.id} · ${this.peeking(t.source)}`:this.live?"Fetching its palettes…":"space fetches its palettes")]}if(t.kind==="find"){let s=this.fields.markets.value.trim(),o=s&&!pa(s),a=!this.searching&&!this.searchError&&this.repos===void 0,c=this.searching?"Searching GitHub…":this.searchError?"GitHub search failed":a?o?`Find "${s}" on GitHub`:"Find markets on GitHub":o?`No market on GitHub matches "${s}"`:"No market on GitHub yet";return[this.lit(void 0,e,`${r("⌕")}${c}`),this.note(this.searchError??(this.searching?"":a?"space searches GitHub":"space searches again"))]}let i=this.busy.get(t.source);return[this.lit(void 0,e,`${r(this.known(t.source)?"●":"○")}${t.source} ${this.dim(`★${t.repo.stargazers_count}`)}${i?` ${this.dim(i)}`:""}`),this.note([this.peeking(t.source),t.repo.description??""].filter(Boolean).join(" · "))]}problemLine(t,e){return[this.lit(void 0,e,`${this.warn("✗")} ${t.where}`),this.note(t.message)]}body(){let t=this.list();if(t){let n=this.fields[this.tab].value;return{...t.window(),empty:n?`No palettes match '${n}'`:this.tab==="installed"?"Nothing installed yet":"No palettes"}}if(this.tab==="markets")return{...this.windowOf(this.marketRows(),"markets",(n,r,i)=>this.marketLine(n,r,i),(n)=>n?.kind==="rule"),empty:""};let e=this.fields.errors.value;return{...this.windowOf(this.problemRows(),"errors",(n,r)=>this.problemLine(n,r)),empty:e?`No problems match '${e}'`:"No problems"}}changes(){return this.adds.size+this.removes.size+this.want.size}dirty(){let{picked:t}=this.result();return this.changes()>0||t.size!==this.installed.size||[...t].some((e)=>!this.installed.has(e))}leave(t){if(this.dirty()){this.leaving=t;return}this.goto=t,this.state="cancel"}steer(t){if(this.phase==="review"){if(t==="enter")this.begin();else if(t==="esc")this.phase="browse"}else if(this.phase==="done"&&(t==="enter"||t==="esc"))this.state="submit";let e=t==="up"?-1:t==="down"?1:Gu(t,this.span());if(e!==void 0)this.scroll(e)}scroll(t){this.offset=Number.isFinite(t)?Math.max(0,this.offset+t):t>0?Number.MAX_SAFE_INTEGER:0,this.redraw()}span(){return Math.max(Gy,this.rows()-(this.hub?1:0)-4)}begin(){this.phase="applying",this.started=!0,this.offset=0,this.log=[],this.working="";let t={say:(e)=>{this.log.push(...e.split(`
657
- `)),this.redraw()},status:(e)=>{this.working=e,this.redraw()}};this.track(this.io.apply(this.result(),t)).then(()=>this.ended(),(e)=>this.ended(e))}ended(t){this.working="",this.stopped=t,this.phase="done",this.offset=0,this.redraw()}pending(){let t=this.entries().filter((e)=>!e.default);return{names:t.filter((e)=>this.picked.has(e.name)&&!this.installed.has(e.name)),dropped:t.filter((e)=>this.installed.has(e.name)&&!this.picked.has(e.name))}}marketChanges(){let t=[];for(let e of this.adds.values()){let n=e.source!==z&&(this.want.get(e.source)??e.auto)?"updates on its own":"";t.push(`+ ${e.id} ${this.dim([e.source===z?"The ttheme catalog":e.shown,Rt(e.entries.filter((r)=>!r.default).length),n].filter(Boolean).join(" · "))}`)}for(let e of this.removes){let n=this.markets.find((i)=>i.source===e),r=(n?.entries??[]).filter((i)=>!i.default&&this.installed.has(i.name)&&this.picked.has(i.name));t.push(`- ${n?.id??e} ${this.dim([n?.shown??Z(e),r.length>0?`its ${Rt(r.length)} installed keep working`:""].filter(Boolean).join(" · "))}`)}for(let[e,n]of this.want){let r=this.markets.find((i)=>i.source===e);if(r&&!this.removes.has(e))t.push(`↻ ${r.id} ${this.dim(n?"updates on its own from now":"stops updating on its own")}`)}return t}reviewLines(){let t=this.marketChanges(),{names:e,dropped:n}=this.pending(),r=Math.max(0,...[...e,...n].map((o)=>o.name.length)),i=(o,a)=>` ${o} ${a.name.padEnd(r)} ${this.dim(lt(a.name)?a.catalog??"":a.group)}`,s=[e.length>0?`${e.length} to install`:"",n.length>0?`${n.length} to remove`:""].filter(Boolean);return[...t.length>0?[` ${this.bold("Markets")} ${this.dim(`(${t.length})`)}`,...t.map((o)=>` ${o}`),""]:[],...s.length>0?[` ${this.bold("Palettes")} ${this.dim(`(${s.join(" · ")})`)}`,...e.map((o)=>i("+",o)),...n.map((o)=>i("-",o))]:[]]}summary(){let{names:t,dropped:e}=this.pending(),n=this.adds.size;return[n>0?`${n} market${n===1?"":"s"} added`:"",this.removes.size>0?`${this.removes.size} removed`:"",t.length>0?`${t.length} installed`:"",e.length>0?`${e.length} removed`:""].filter(Boolean).join(" · ")}progressLines(){let t=this.log.map((e)=>` ${e}`);if(this.phase==="applying"){let e=xn[this.beat%xn.length];t.push(` ${this.dim(`${e} ${this.working||"Working…"}`)}`)}else if(this.stopped)t.push("",...bt(this.stopped.message,Math.max(20,this.columns()-6)).map((e,n)=>` ${n===0?this.warn("✗"):" "} ${e}`));return t}frame(t,e){let n=t-1,r=this.phase==="review",i=r?this.reviewLines():this.progressLines(),s=this.phase==="review"?`${this.bold("Review changes")}`:this.phase==="applying"?this.bold("Applying changes"):this.stopped?`${this.warn("✗")} ${this.bold("Stopped")}`:`${this.bold("✓ Applied")} ${this.dim(this.summary()?`(${this.summary()})`:"")}`,o=this.span(),a=Math.max(0,i.length-o),c=this.phase==="applying"?a:Math.min(this.offset,a);this.offset=c;let u=i.slice(c,c+o),l=i.length-c-u.length,f=[c>0?` ${this.more(-1,`↑ ${c} more`)}`:"",...u];while(f.length<o+1)f.push("");f.push(l>0?` ${this.more(1,`↓ ${l} more`)}`:"");let d=a>0?[["↑↓","scroll"]]:[],h=r?{badge:"BROWSE (APPLY)",keys:[...d,["enter","apply"]],right:["esc","back"]}:this.phase==="applying"?{badge:"BROWSE (APPLY)",note:"Keys wait until it ends",keys:[]}:{badge:"BROWSE (APPLY)",keys:d,right:["enter","close"]};return[...this.hub?[ot(gd(this.hub,this.color),n,!1)]:[],ot(` ${s}`,n,!1),...f.map((m)=>ot(m,n,!1)),` ${this.keyBar(h,n-1)}`].slice(0,e).join(`
658
- `)}keyBar(t,e){let n=this.color&&this.worn?Be(this.worn.cursor):"",r=this.color?`\x1B[7;1m${n} ${t.badge} ${At} `:`[${t.badge}] `,i=([c,u])=>gn(c.split(" ")[0]??"",`${this.bold(c)} ${this.dim(u)}`),{note:s,keys:o,right:a}=t;for(;;){let c=`${r}${[t.lead??"",s?this.dim(s):"",...o.map(i)].filter(Boolean).join(" ")}`,u=a?i(a):"";if(X(c)+(a?3+X(u):0)<=e)return a?Gt(c,u,e):ot(c,e,!1);if(s)s=void 0;else if(o.length>2||!a&&o.length>1){let l=o.length-2;o=o.filter((f,d)=>d!==l)}else if(a)a=void 0;else return ot(c,e,!1)}}more(t,e){return this.dim(le({kind:"page",step:t},e))}counts(){let t=[...this.busy.values()].includes("Updating…")?"Updating… · ":"",e=this.list();if(e)return`${t}${e.matched()}/${e.total()} · ${e.pickedCount()} picked`;if(this.tab==="markets"){let n=this.markets.length+this.adds.size,r=this.marketRows().filter((s)=>s.kind==="market").length,i=this.changes();return`${t}${r}/${n}${i>0?` · ${i} to apply`:""}`}return`${this.problemRows().length}/${this.problemList().length}`}searchText(){let t=this.fields[this.tab].value;if(t)return`${t}_`;if(this.tab==="markets")return this.dim("Search… or add one: owner/repo");let e=this.tab==="errors"?"":this.hint.text();return this.dim(`Search…${e?` e.g. ${e}`:""}`)}tabBar(){return Qs.map(({tab:t,title:e})=>{let n=t==="errors"?this.problemList().length:0,r=n>0?`${e} ${n}`:e,i={kind:"tab",tab:t};if(!this.color)return le(i,t===this.tab?`[${r}]`:` ${r} `);return`${t===this.tab?lP:A}${le(i,` ${r} `)}${At}`}).join(" ")}heading(){let t=Qs.find((e)=>e.tab===this.tab)?.heading??"";return`${this.bold(t)} ${this.dim(`(${this.counts()})`)}`}searchBox(t){let e=(r,i)=>this.dim(`${r}${"─".repeat(t-2)}${i}`),n=this.dim("│");return[e("╭","╮"),`${n} ${ot(`${this.dim("⌕")} ${this.searchText()}`,t-4)} ${n}`,e("╰","╯")]}strip(t){let e=this.tab;if(e!=="catalog"&&e!=="installed"||this.active().length<2)return;let n=this.chips(e),r=Math.max(0,n.findIndex((g)=>g.source===this.scope[e])),i=n.map((g,b)=>b===r&&!this.color?`[${g.label} ${g.count}]`:`${g.label} ${g.count}`),s=" · ",o=(g)=>g>0?`${s}+${g} more`.length:0,a=(g)=>{let b=g>0?2:0,y=0;for(let E=g;E<i.length;E++){let S=b+(y>0?s.length:0)+i[E].length;if(S+o(i.length-E-1)>t)break;b=S,y+=1}return y},c=0;while(c<r&&c+a(c)<=r)c+=1;let u=Math.max(1,a(c)),l=i.slice(c,c+u),f=i.length-c-u,d=l.map((g,b)=>{let y=le({kind:"chip",source:n[c+b]?.source},g);if(c+b===r)return this.color?`${at}${Ba}${y}${At}`:y;return this.dim(y)}),h=`${c>0?`${this.dim(gn("ctrl+s","…"))} `:""}${d.join(this.dim(s))}${f>0?this.dim(`${s}${gn("ctrl+s",`+${f} more`)}`):""}`,m=(c>0?2:0)+l.join(s).length+o(f),$="ctrl+s market";return m+2+$.length<=t?`${h} ${this.dim(gn("ctrl+s",$))}`:h}sourceOf(t){let e=this.active().find((n)=>n.entries.some((r)=>r.name===t.name));if(!e)return"In no market you added";return e.source===z?"The ttheme catalog":e.shown}paletteState(t){let e=this.picked.has(t.name),n=this.installed.has(t.name),r=e&&n?"Installed":e?"Will install":n?"Will remove":"Not installed";return this.startup===t.name?`${r} · Default`:r}paletteDetail(t,e){if(!t||t.kind==="rule")return om;if(t.kind==="all")return{title:this.bold("Select all"),lines:["space picks every palette shown"],brief:""};if(t.kind==="group"){let u=this.entries().filter((d)=>d.group===t.name&&!d.default),l=this.sourceOf(t.lead),f=`${Rt(u.length)} · ${u.filter((d)=>this.installed.has(d.name)).length} installed`;return{title:this.bold(t.name),lines:[...t.native?bt(t.native,e).map((d)=>this.dim(d)):[],...bt(l,e),f],brief:`${l} · ${f}`}}if(t.kind==="catalog"){let u=this.entries().filter((d)=>d.group===t.group&&d.catalog===t.name),l=this.sourceOf(t.lead),f=`${Rt(u.length)} · ${u.filter((d)=>this.installed.has(d.name)).length} installed`;return{title:this.bold(t.name),lines:[t.group,...bt(l,e),f],brief:`${t.group} · ${f}`}}let n=t.entry,r=this.sourceOf(n),i=Lo(n),s=`Gate ${we.length-i.length}/${we.length}`,o=n.pictures?.length??0,a=[...o>0?[`${o} picture${o===1?"":"s"}`]:[],...n.base?[`Base ${n.base}`]:[]].join(" · "),c=lt(n.name)?n.catalog?[n.catalog]:[]:[n.group,...n.native?[this.dim(n.native)]:[]];return{title:this.color?`${at}${Be(n.cursor)}${n.name}${ge}\x1B[39m`:n.name,lines:[...bt(r,e),...c,this.paletteState(n),"",i.length===0?`${s} · passes`:s,...i.flatMap((u)=>bt(u,e-2).map((l,f)=>`${f===0?this.warn("✗"):" "} ${l}`)),...a?["",a]:[]],brief:[r,s,...a?[a]:[],this.paletteState(n)].join(" · ")}}marketDetail(t,e){if(!t||t.kind==="rule")return om;if(t.kind==="market"){let i=t.market,s=i.source===z?"The ttheme catalog":i.shown,o=i.entries.filter((h)=>!h.default),a=o.filter((h)=>this.installed.has(h.name)).map((h)=>h.name),c=`${Rt(o.length)} · ${a.length} installed`,u=ct(i.source)?"Read in place":`Auto-update ${this.want.get(i.source)??i.auto?"on":"off"}`,l=this.busy.get(i.source)??fP(i.status),f=this.failed.get(i.source),d=this.adds.has(i.source)?["Will add"]:this.removes.has(i.source)?[a.length>0?`Will remove — ${a.join(", ")} stay${a.length===1?"s":""} installed`:"Will remove"]:this.want.has(i.source)?[`Auto-update turns ${this.want.get(i.source)?"on":"off"}`]:[];return{title:this.bold(i.id),lines:[...bt(s,e),...i.description?bt(i.description,e).map((h)=>this.dim(h)):[],c,"",ct(i.source)?u:`${u} ${this.dim("←→")}`,...ct(i.source)?[]:[l],...f?bt(f,e).map((h)=>this.warn(h)):[],...d.length>0?["",...d.flatMap((h)=>bt(h,e))]:[]],brief:[s,u,...d,...ct(i.source)?[]:[l]].join(" · ")}}if(t.kind==="add"){let i=this.busy.get(t.source)??this.failed.get(t.source)??this.peekFailed.get(t.source)??(this.peeked.has(t.source)?"space adds it":this.live?"Fetching its palettes…":"space fetches its palettes");return{title:this.bold(Z(t.source)),lines:["Not added",...this.peekLines(t.source,e),"",...bt(i,e)],brief:[this.peeking(t.source),i].filter(Boolean).join(" · ")}}if(t.kind==="find"){let i=this.fields.markets.value.trim(),s=this.searchError??(this.searching?"Searching…":this.repos?`${this.repos.length} found · space searches again`:"space searches GitHub");return{title:this.bold("GitHub"),lines:[...bt(`Repositories with the ${Es} topic`,e),...i&&!pa(i)?[`Matching "${i}"`]:[],"",...bt(s,e)],brief:s}}let r=this.known(t.source)?"Added":this.busy.get(t.source)??this.failed.get(t.source)??this.peekFailed.get(t.source)??"space adds it";return{title:this.bold(t.source),lines:[`★ ${t.repo.stargazers_count}`,...bt(t.repo.description??"",e),...this.peekLines(t.source,e),"",...bt(r,e)],brief:[this.peeking(t.source),r].filter(Boolean).join(" · ")}}peekLines(t,e){let n=this.peeked.get(t);if(!n)return[];let r=n.entries.filter((s)=>!s.default),i=`${r.slice(0,By).map((s)=>ae(s.name)).join(", ")}${r.length>By?", …":""}`;return["",n.id,...n.description?bt(n.description,e):[],Rt(r.length),...bt(i,e).map((s)=>this.dim(s))]}detail(t){let e=this.list();if(e)return this.paletteDetail(e.focusedRow(),t);if(this.tab==="markets")return this.marketDetail(this.marketRow(),t);let n=this.problemRows(),r=n[Math.min(this.cursor.errors,n.length-1)];return r?{title:this.bold(r.where),lines:bt(r.message,t),brief:r.message}:om}footer(){if(this.help)return{badge:"HELP",keys:[],right:["? esc","close"]};if(this.leaving!==void 0)return{badge:"BROWSE",lead:"Apply your changes before you leave?",keys:[["y","apply"],["n","discard"]],right:["esc","stay"]};if(this.asking)return{badge:"BROWSE",lead:`Update ${this.asking.id} on its own when its author changes it?`,keys:[["y","yes"],["n","no"]],right:["esc","back"]};let t=this.fields[this.tab].value,e=["enter",this.dirty()?"apply":"close"],n=[["⇧←→","tabs"],...t?[["bksp","edit"]]:[],["?","keys"]];return{badge:t?"BROWSE (FILTER)":"BROWSE",keys:[...this.rowKeys(e),...n],right:t?["esc","clear filter"]:["esc","cancel"]}}rowKeys(t){let e=this.list();if(e){let r=e.focusedRow();if(!r)return[t];if(e.foldable())return[(r.kind==="group"||r.kind==="catalog")&&r.expanded?["←","close"]:["→","open"],["space","pick"]];return[["space","pick"],t]}if(this.tab==="errors")return[t];let n=this.marketRow();if(n?.kind==="market"){let r=n.market;return[["space",this.adds.has(r.source)||this.removes.has(r.source)?"undo":"remove"],...ct(r.source)?[]:[["←→","auto-update"]],...this.adds.has(r.source)?[]:[["ctrl+r","update"]],t]}if(n?.kind==="find")return[["space","search"],t];if(n?.kind==="add"||n?.kind==="repo"&&!this.known(n.source))return[["space","add"],t];return[t]}columns(){return(this.output??process.stdout).columns??100}rows(){return(this.output??process.stdout).rows??24}fitItems(t){let e=Math.max(Gy,this.rows()-t);this.maxItems=e,this.catalog.maxItems=e,this.mine.maxItems=e}view(){let t=this.draw().split(`
659
- `);return Array.from({length:this.rows()},(e,n)=>t[n]??"")}draw(){let t=this.columns(),e=this.rows();if(t<jy||e<_y)return`Needs ${jy}×${_y} — now ${t}×${e}
660
- ${this.dim("esc cancels")}`;if(this.phase!=="browse")return this.frame(t,e);let n=t>=sP,r=t-1,i=n?Math.min(t-sm-4,iP):r,s=this.strip(r-1),o=[` ${this.tabBar()}`,...e>=oP?[` ${this.heading()}`,...this.searchBox(t-3).map((g)=>` ${g}`)]:[Gt(` ${this.dim("⌕")} ${this.searchText()}`,this.dim(this.counts()),r)],...s?[` ${s}`]:[]];this.fitItems(o.length+3+(n?0:1)+(this.hub?1:0));let{lines:a,above:c,below:u,empty:l}=this.body(),f=a.length>0?a.map((g)=>` ${g}`):[` ${this.dim(l)}`];while(f.length<this.maxItems)f.push("");let d=[c>0?` ${this.more(-1,`↑ ${c} more`)}`:"",...f,u>0?` ${this.more(1,`↓ ${u} more`)}`:""],h=this.detail(n?sm:i-2),m=n?d.map((g,b)=>`${ot(g,i)} ${this.dim("│")} ${ot(b===0?h.title:h.lines[b-1]??"",sm,!1)}`):[...d.map((g)=>ot(g,i,!1)),ot(` ${this.dim(h.brief)}`,i,!1)],$=[...this.hub?[ot(gd(this.hub,this.color),r,!1)]:[],...o.map((g)=>ot(g,r,!1)),...m,` ${this.keyBar(this.footer(),r-1)}`];return(this.help?this.helpBox($,t,e,$.length-m.length-1):$).join(`
661
- `)}helpRows(){return[["Move","↑↓ home end pgup pgdn"],["Series","←→ · enter on a series"],["Pick","space · a palette, a series, all"],["Filter","Any text · bksp · ctrl-u clears"],["","Each tab keeps its own"],["Tabs","⇧←→ Catalog, Installed, Markets, Errors"],...this.active().length>=2?[["Market","ctrl+s · one market, then all"]]:[],["Markets","space adds or removes · ←→ auto-update"],["","ctrl+r updates it, or searches again"],["Apply","enter reviews and applies · esc cancels"],...this.hub?[["Screens","tab · shift+tab"]]:[],["Close","? esc"]]}helpBox(t,e,n,r){let i=this.helpRows(),s=Math.min(e-2,58),o=Math.floor((e-s)/2),a=`│${" ".repeat(s-2)}│`,c=[`╭─ Help ${"─".repeat(s-9)}╮`,a,...i.map(([l,f])=>`│${ot(` ${this.bold(l.padEnd(10))}${f}`,s-4)} │`),a,`╰${"─".repeat(s-2)}╯`],u=Math.max(0,Math.min(Math.max(r,Math.floor((n-c.length)/2)),n-1-c.length));return t.map((l,f)=>{let d=c[f-u];return d===void 0?l:`${Wp(l,o)}${d}`})}}import{existsSync as LC}from"node:fs";import{existsSync as Aa,mkdirSync as IC,readFileSync as Vm}from"node:fs";import{dirname as RC}from"node:path";class Ne extends Error{}import{closeSync as QH,mkdtempSync as XH,openSync as tF,readSync as eF,rmSync as Gv}from"node:fs";import{homedir as nF,tmpdir as rF}from"node:os";import{join as Bv}from"node:path";import{readFileSync as dP}from"node:fs";var gt={pitch:25,cols:22,rows:9,height:13},Ci={cols:25,rows:21},me={cols:10,rows:3,pitch:12,top:4},he=me.top+me.rows+1,hP=1073741824,mm=2147483648,mP=-1073741826,pP=1600,gP=56,bP=4,Uy=20,wP=50,Wy=[["space","unfolds a set of ×N"],["o","opens the post page in a browser"],["c","switches between cutouts and every post"],["a","opens the advanced filters"],["1-9","turn a tag of the tags row on or off"],["ctrl+v","tries on a picture from the clipboard — or drop one on the window"]];function pm(t){return Math.max(0,Math.floor((t-1)/me.pitch))}function Jn(t,e){let n=e-he-2;return{perRow:Math.max(1,Math.floor((t-1)/gt.pitch)),rowsVis:Math.max(1,Math.floor(n/gt.height)),height:n}}function Du(t,e=!0){if(e)return`\x1B_Ga=t,t=f,f=100,i=${t.id},q=2;${Buffer.from(t.path).toString("base64")}\x1B\\`;let n;try{n=dP(t.path).toString("base64")}catch{return}let r=n.match(/.{1,4096}/g)??[""];return r.map((i,s)=>{let o=s<r.length-1?1:0;return s===0?`\x1B_Ga=t,f=100,i=${t.id},m=${o},q=2;${i}\x1B\\`:`\x1B_Gm=${o},q=2;${i}\x1B\\`}).join("")}function Zy(t,e){let n=t.crop===void 0?"":`,x=0,y=${t.crop*e.h},w=${t.cols*e.w},h=${t.rows*e.h}`;return`\x1B[${t.row+1};${t.col+1}H\x1B_Ga=p,i=${t.id},p=${t.id}${n},c=${t.cols},r=${t.rows},C=1,z=${t.z},q=2\x1B\\`}function gm(t){return`\x1B_Ga=d,d=i,i=${t},p=${t},q=2\x1B\\`}function ka(t){return`\x1B_Ga=d,d=I,i=${t},q=2\x1B\\`}function Xs(t){return`\x1B[38;2;${rt(t).join(";")}m`}function zu(t){return`\x1B[48;2;${rt(t).join(";")}m`}var um=!1;function qu(t){return um=!0,t.beat}function to(t){return xn[qu(t)%xn.length]}function ft(t){return X(t)}function lm(t,e){if(X(t)<=e)return t;let n="";for(let r of t){if(X(n+r)>e)break;n+=r}return n}function Ur(t){return`\x1B[${30+t}m`}function Li(t,e,n,r){return n?[[`${uo} `,r,void 0,{kind:"link",url:n}],[t,e,n]]:[[t,e]]}function cm(t){let e=pd(t);return e?{kind:"key",key:e}:void 0}function fm(t){return t.reduce((e,[n])=>e+ft(n),0)}function $P(t,e){let n=[],r=e;for(let[i,s,o,a]of t){let c=ft(i);if(c<=r){n.push([i,s,o,a]),r-=c;continue}n.push([`${lm(i,r)}…`,s,o,a]);break}return n}class Ku{parts=[];cols;constructor(t){this.cols=t}put(t,e,n="",r,i){return this.parts.push({col:t,text:e,sgr:n,...r?{link:r}:{},...i?{spot:i}:{}}),t+ft(e)}run(t,e){let n=t;for(let[r,i,s,o]of e)n=this.put(n,r,i,s,o);return n}mark(t,e,n){this.parts.push({col:t,text:" ".repeat(Math.max(0,e)),sgr:"",spot:n,hidden:!0})}zones(t){return this.parts.flatMap(({col:e,text:n,link:r,spot:i})=>{let s=i??(r?{kind:"link",url:r}:void 0),o=e>=0&&e<this.cols?ft(lm(n,this.cols-e)):0;return s&&o>0?[{row:t,col:e,width:o,height:1,target:s}]:[]})}right(t,e){this.run(t-e.reduce((n,[r])=>n+ft(r),0),e)}center(t,e){this.run(Math.floor((t-e.reduce((n,[r])=>n+ft(r),0))/2),e)}render(){let t="";for(let{col:e,text:n,sgr:r,link:i,hidden:s}of this.parts){if(s||e>=this.cols||e<0)continue;let o=lm(n,this.cols-e);t+=`\x1B[${e+1}G${r}${Ua(o,i)}${r?At:""}`}return t}}function kP(t){return t.replace(/_\([^)]*\)?$/,"")}function Qy(t){return[`${t.reduced?"↓":""}${t.width}×${t.height}`,Math.max(t.width,t.height)<pP?Vt:A]}function wa(t,e,n,r){let i=[...r.keys??[]],s=r.lead,o=r.right,a=()=>{let l=[...s?[fm(s)]:[],...i.map(([d,h])=>ft(d)+1+ft(h))];return(r.badge?ft(r.badge)+4:0)+l.reduce((d,h)=>d+h,0)+3*Math.max(0,l.length-1)+(o?3+ft(o[0])+1+ft(o[1]):0)};while(a()>e)if(i.length>2)i.splice(-2,1);else if(o)o=void 0;else if(i.length>1)i.splice(-2,1);else break;if(s&&a()>e)s=$P(s,Math.max(0,fm(s)-(a()-e)-1));let c=0;if(r.badge)c=t.put(0,` ${r.badge} `,`\x1B[7;1m${n}`)+2;if([...s?[s]:[],...i.map(([l,f])=>[[l,at,void 0,cm(l)],[` ${f}`,A,void 0,cm(l)]])].forEach((l,f)=>{c=t.run(c+(f?3:0),l)}),o){let l=cm(o[0].split(" ")[0]??"");t.right(e,[[o[0],at,void 0,l],[` ${o[1]}`,A,void 0,l]])}}function yP(t,e){if(t==="d")return A;if(t==="b")return at;if(t==="s")return zu(e.colors.selection);if(t==="c")return zu(e.colors.cursor);let n=/^([BK]?)(\d+)$/.exec(t);if(!n)return"";let r=Number(n[2]),i=(s)=>r<8?s+r:s+52+r;if(n[1]==="K")return`\x1B[30;${i(40)}m`;return`\x1B[${n[1]==="B"?"1;":""}${i(30)}m`}function vP(t,e,n,r,i){let s=ie.indexOf(bi(r.scene)),o=ie.flatMap((c,u)=>[...u?[[" ",""]]:[],[c.name,u===s?at+i:A,void 0,{kind:"scene",scene:u}]]),a=o.reduce((c,[u])=>c+ft(u),0)<=n;t?.run(e,a?o:[[bi(r.scene).name,at+i],[` ${s+1}/${ie.length}`,A]])}function EP(t,e,n,r,i,s,o){let{ansi:a,cursor:c}=s.colors;vP(t[e-2],n,r,s,o);let u=r<r$?3:4;if(r>=56)u=Math.min(7,Math.floor((r+1)/8)-1);let l=n;for(let d=0;d<8;d++)l=(t[e]?.put(l,"▀".repeat(u),Xs(a[d]??c)+zu(a[d+8]??c))??l)+1;let f=e+2;for(let d of bi(s.scene).lines){let h=Dc(d,r);if(!h)continue;if(f>i)return;t[f]?.run(n,h.map(([m,$])=>[m,yP($,s)])),f++}}function SP(t,e,n){let r=[[]];for(let o of t){let a=r[r.length-1];if(a.length===0||ft([...a,o].join(" "))<=e)a.push(o);else if(r.length<n)r.push([o]);else break}let i=r.reduce((o,a)=>o+a.length,0),s=r[r.length-1];while(i<t.length&&s.length>0&&ft([...s,`+${t.length-i}`].join(" "))>e)s.pop(),i--;if(i<t.length)s.push(`+${t.length-i}`);return r.filter((o)=>o.length>0).map((o)=>o.join(" "))}function Ky(t){return t.replace(/^https?:\/\/(?:www\.)?/,"")}function MP(t,e,n,r,i){let s=r.info,o=s?.artists??[],a=Ur(r.tiles[r.focus]?.siteAnsi??r.siteAnsi);[["Post",s?.page?Li(Ky(s.page),"",s.page,a):[["—",A]]],["Source",s?.source?Li(Ky(s.source),"",s.link,i):[["—",A]]],["Artist",[o.length>0?[o.join(" "),""]:["—",A]]]].forEach(([u,l],f)=>{t[e+f]?.put(n,u,A),t[e+f]?.run(n+12,l)})}function OP(t,e,n,r,i,s){let o=s.info,a=s.tiles[s.focus];if(!o||!a)return;let c=s.shown?.id===a.key?s.shown:void 0,u=n+12,l=Math.max(12,r-12),f=[`${a.width}×${a.height}${o.ext?` ${o.ext.toUpperCase()}`:""}`,...c?[Ou(c.bytes)]:[]].join(" · "),d=[o.rating??"—",a.score>0?`★${a.score}`:"",o.posted??""].filter(Boolean).join(" · "),h=(g,b)=>g.length>0?SP(g,l,b).map((y)=>[[y,""]]):[[["—",A]]],m=[["Characters",h(o.characters,2)],["Series",h(o.series,1)],["Tags",h(o.tags,3)],["Rating",[[[d,d==="—"?A:""]]]],["File",[[[f,""],...c?[[" ",""]]:[],...c?Xy(c):[]]]],["Uploader",[[o.uploader?[o.uploader,""]:["—",A]]]]],$=e;for(let[g,b]of m){if($+b.length-1>i)return;t[$]?.put(n,g,A);for(let y of b)t[$]?.run(u,y),$++}}var xP=["Size","Position","Opacity"],IP=[0,3,6];function RP(t,e){let{tune:n,untuned:r}=t;return e===0?n.size!==r.size:e===1?n.at!==r.at:n.opacity!==r.opacity}function NP(t){return t.toFixed(2)}function TP(t,e,n,r,i,s){let o=i.tuning;if(!o)return;let a=i.tiles[i.focus];t[e-3]?.run(n,[[i.palette,at+s],[" Background",A],...a?[[" · ",A],...Li(`${a.site} ${a.id}`,A,a.page||void 0,Ur(a.siteAnsi))]:[]]);let c=Math.max(8,r-n-21),u=20,l=Math.max(100,o.fill);for(let[f,d]of xP.entries()){let h=e+IP[f],m=o.field===f,$=m?at:A;if(m)t[h]?.put(n,"▶",s,void 0,{kind:"field",field:f});t[h]?.put(n+2,d,$,void 0,{kind:"field",field:f});let g;if(f===1){for(let b=1;b<=9;b++){let y=b===i.tune.at,E=t[e+2+Math.floor((b-1)/3)],S=n+12+(b-1)%3*3;E?.mark(S-1,3,{kind:"place",at:b}),E?.put(S,y?"■":"·",y?at+s:A)}g=Ut[i.tune.at-1]??"center"}else{let b;if(f===0){let{size:y}=i.tune;b=y==="fill"?c-1:Math.floor((y-u)*(c-1)/(l-u+1)),g=y==="fill"?"fill":`${y}%`}else b=Math.floor(Math.round(i.tune.opacity*100)*(c-1)/100),g=NP(i.tune.opacity);b=Math.max(0,Math.min(c-1,b)),t[h]?.run(n+12,[["━".repeat(b),s],["●",at],["─".repeat(c-1-b),A]]),t[h]?.mark(n+12,c,{kind:"track",field:f})}if(t[h]?.right(r-2,[[g,$]]),RP(i,f))t[h]?.put(r-1,"↺",m?at+s:A)}}function AP(t,e,n,r,i,s){t[e]?.put(n,`╭${"─".repeat(i-2)}╮`,s);for(let o=e+1;o<e+r-1;o++)t[o]?.put(n,"│",s),t[o]?.put(n+i-1,"│",s);t[e+r-1]?.put(n,`╰${"─".repeat(i-2)}╯`,s)}function dm(t,e=t.site,n=t.siteAnsi){return[` ${e} `,`\x1B[7;${30+n}m`]}function ba(t){return`${Y[Math.floor(t/dr)]?.name??"local"} ${t%dr}`}function ga(t,e,n){let r=Y[Math.floor(e/dr)],i=ba(e),s=t.indexOf(i);if(!r||s===-1)return[[t,n]];return[[t.slice(0,s),n],...Li(i,n,r.pageUrl(e%dr),Ur(r.ansi)),[t.slice(s+i.length),n]].filter(([a])=>a!=="")}function PP(t,e,n){let r=[{name:"all",moved:!1},...Y].flatMap((s,o)=>{let a=`${s.name}${s.moved?"*":""}`,[c,u]=s.name===n.site?dm(n,a):[` ${a} `,A],l=[c,u,void 0,{kind:"site",tab:o}];return o?[[" ",""],l]:[l]}),i=r.reduce((s,[o])=>s+ft(o),0)<=e;t.run(0,i?r:[dm(n)])}function HP(t,e,n,r){if(n.chips.length===0)return;let i=[["tags ",A]],s=ft("tags "),o=n.chips.length;for(let[a,c]of n.chips.entries()){let u=` ${a+1} ${c.name} `;if(s+ft(u)+1>e-2)break;i.push([u,c.on?`\x1B[7m${r}`:A,void 0,{kind:"chip",index:a}],[" ",""]),s+=ft(u)+1,o--}if(o>0)i.push([`+${o}`,A]);t.run(0,i)}function FP(t,e,n,r,i){t[he-1]?.put(0,"─".repeat(n-1),A);let s=t[me.top-1],o=pm(n),a=r.held.length>o?Math.max(0,o-1):r.held.length;for(let[c,u]of r.held.slice(0,a).entries()){let l=c*me.pitch,f=u.up?at:"";if(s.run(l+1,u.page?Li(String(u.id),f,u.page,Ur(u.ansi)):[["● ",Ur(u.ansi)],[String(u.id),f]]),u.up)for(let d=0;d<me.rows;d++)t[me.top+d]?.put(l,"▌",i);if(u.thumb)e.push({id:hP+c,path:u.thumb,row:me.top,col:l+1,cols:me.cols,rows:me.rows,z:-1})}if(a<r.held.length)s.put(a*me.pitch+1,`+${r.held.length-a}`,A)}function CP(t,e,n,r){if(n.editing!==void 0){let c=t.run(0,[["⌕ ",r],[n.editing,""],["█",r]]),u=n.suggest?.length?" ↑↓ pick enter searches":" enter searches";t.put(c,n.editing?u:` A tag, a post URL or an id, or drop a picture or ctrl+v — ${n.tag||"esc leaves"}`,A);return}let i=t.run(0,[["⌕ ",r,void 0,{kind:"query"}],[n.tag||"Nothing yet — / searches, ctrl+v pastes a picture",n.tag?"":A,void 0,{kind:"query"}]]),s=ii.filter((c)=>!n.block.includes(c)),o=Y.filter((c)=>!n.enabled.includes(c.name)).map((c)=>c.name),a=[n.preset,...n.solo?["solo"]:[],n.order,...n.rating.join("+")==="safe"?[]:[n.rating.join("+")],...s.length>0?[`allows ${s.join("+")}`]:[],...n.narrow.size>0?[`≥${n.narrow.size}px`]:[],...n.narrow.score>0?[`score≥${n.narrow.score}`]:[],...n.narrow.png?["png"]:[],...n.hide.length+n.hideTags.length>0?[`hides ${[...n.hide,...n.hideTags].join("+")}`]:[],...o.length>0?[`all skips ${o.join("+")}`]:[]];if(t.put(i,` ${a.join(" ")}`,A),n.total>0||!n.searching){let c=[[`${n.tiles.length}/${n.checked}`,""]];if(n.checked<n.total)c.push([` of ${n.total}`,A]);t.right(e,c)}}function Xy(t){if(t.cut==="on")return[[`Cut out · ${t.clear}% transparent`,Zi]];if(t.cut==="off")return[["Opaque · x cuts out",Vt]];if(t.cut==="failed")return[["Opaque · no cut-out",Vt]];return[t.clear>0?[`${t.clear}% transparent`,Zi]:["Opaque",Vt]]}function zy(t){return t.site==="all"?"any site":t.site}function hm(t,e){if(t.installing!==void 0)return ga(`${to(t)} Installing ${t.palette} ← ${ba(t.installing)}`,t.installing,Vt);if(t.hint)return[[t.hint,Zi]];if(t.error)return[[t.error,Vt]];if(t.waiting!==void 0)return[[`${t.slow??t.site} asked to slow down · ${t.waiting}s`,Vt]];if(t.fetching){let{id:n,got:r,size:i}=t.fetching;return ga(`${to(t)} Fetching ${ba(n)} · ${xu(r,i)}`,n,Vt)}if(t.cutting!==void 0)return ga(`${to(t)} Cutting out ${ba(t.cutting)}`,t.cutting,Vt);if(t.preparing!==void 0)return ga(`${to(t)} Preparing ${ba(t.preparing)}`,t.preparing,Vt);if(e)return[e];if(t.saved)return ga(t.saved.text,t.saved.key,Zi);if(t.note)return[[t.note,A]];return}function tv(t){if(t.ranking)return"Ranking previews by palette colors";if(t.stage==="check")return t.preset==="cutouts"?"Checking PNG headers":"Loading previews";return"Fetching posts"}function ev(t,e){return t.ranking?`${e}${t.ranking.done}/${t.ranking.total}`:""}function LP(t,e,n,r,i){let{background:s,cursor:o,selection:a}=r.colors,{ranking:c}=r,u=c?Math.round(n*c.done/c.total):-1,l=Math.max(6,Math.round(n*0.22)),f=qu(r)%(Uy*2)/Uy,d=Math.round((n-l)*(0.5-0.5*Math.cos(Math.PI*(f<1?f:2-f)))),h=Bt(s,o,i),m=Bt(s,Bt(a,s,0.15),i),$=Array.from({length:n},(b,y)=>{let E=(u>=0?y<u:y>=d&&y<d+l)?h:m;return y===0||y===n-1?Bt(E,s,0.55):E}),g=0;for(let b=1;b<=n;b++)if(b===n||$[b]!==$[g])t?.put(e+g," ".repeat(b-g),zu($[g])),g=b}function jP(t,e,n,r,i){let{background:s,foreground:o}=i.colors,a=i.loaderFrom===void 0?0:Math.min(1,(qu(i)-i.loaderFrom)/bP),c=e+(n>=5?Math.floor((n-5)/2):0);t[c]?.center(r,[[tv(i),at+Xs(Bt(s,o,a))],[ev(i," "),Xs(Bt(s,Bt(o,s,0.45),a))]]);let u=Math.min(gP,r-8);if(LP(t[c+(n>=3?2:1)],Math.floor((r-u)/2),u,i,a),n<5)return;t[c+4]?.center(r,i.sites.flatMap(({name:l,arrived:f},d)=>[...d?[[" · ",Xs(Bt(s,o,0.25*a))]]:[],[l,Xs(Bt(s,f?Bt(o,s,0.2):o,f?a:0.32*a))]]))}function _P(t,e,n,r,i,s){if(i<=r)return;let o=Math.max(1,Math.round(r*r/i)),a=Math.max(0,Math.min(r-o,Math.round(n.scroll*r/i)));for(let c=0;c<r;c++){let u=c>=a&&c<a+o;t[he+c]?.put(e-1,u?"┃":"│",u?s:A)}}function GP(t,e,n){if(e)return[`${to(t)} ${tv(t)}${ev(t," · ")}`,A];let r=n.filter((s)=>!s.missing),i=r.filter((s)=>s.thumb).length;return i<r.length?[`${to(t)} Loading thumbnails · ${i}/${r.length}`,A]:void 0}function BP(t,e,n,r,i,s,o){let{perRow:a,rowsVis:c,height:u}=Jn(r,i);CP(t[0],r,s,o),PP(t[1],r,s),HP(t[2],r,s,o),FP(t,e,r,s,o);let l=t.map((F,_)=>_>=he&&_<he+u?F:void 0),f=Math.floor(s.scroll/gt.height),d=Math.floor((s.scroll+u-1)/gt.height),h=[];for(let F=f;F<=d;F++){let _=he+F*gt.height-s.scroll;for(let B=0;B<a;B++){let tt=F*a+B,W=B*gt.pitch,Q=s.tiles[tt];if(!Q)continue;h.push(Q);let U=Math.max(_,he),yt=Math.min(_+gt.height,he+u);if(yt>U)n.push({row:U,col:W,width:gt.pitch-1,height:yt-U,target:{kind:"tile",index:tt}});let et=tt===s.focus;if(et)AP(l,_,W,gt.height,gt.pitch-1,o);let Xn=_+1,en=Math.max(Xn,he),nn=Math.min(Xn+gt.rows,he+u);if(Q.thumb&&nn>en)e.push({id:Q.key,path:Q.thumb,row:en,col:W+1,cols:gt.cols,rows:nn-en,...nn-en<gt.rows?{crop:en-Xn}:{},z:-1});let rn=[...s.installed.includes(Q.key)?[["✓ ",Zi]]:[],...Q.page||s.site!=="all"?Li(String(Q.id),et?at:"",Q.page||void 0,Ur(Q.siteAnsi)):[["● ",Ur(Q.siteAnsi)],[String(Q.id),et?at:""]],[" ",""],Qy(Q)],Ca=gt.cols-(Q.mates.length>0?1:0);if(l[_+10]?.run(W+1,fm(rn)>Ca?rn.map(([El,Sl,Ml])=>[El.replace(/^(\S) $/,"$1"),Sl,Ml]):rn),Q.mates.length>0)l[_+10]?.put(W+gt.cols,"≈",o);l[_+11]?.put(W+1,Q.artist?kP(Q.artist).slice(0,gt.cols-8):"—",A);let Dr=[];if(Q.score>0)Dr.push([`★${Q.score}`,A]);if(Q.variants>1)Dr.push([` ×${Q.variants}`,o]);if(Dr.length>0)l[_+11]?.right(W+gt.cols+1,Dr)}}let m=Math.ceil(s.tiles.length/a)*gt.height;_P(t,r,s,u,m,o);let $=Math.max(he,he+m-s.scroll),g=he+u-$,b=s.searching&&g>=2;if(b)jP(l,$,g,r-1,s);let y=s.searching&&s.tiles.length===0;if(y&&!s.error){let[F,_]=Wy[Math.floor(qu(s)/wP)%Wy.length];t[i-2]?.run(0,[["Tip ",A],[F,at],[` ${_}`,A]])}let E=s.top*a,S=s.tiles.length-(s.top+c)*a,x=[...E>0?[`↑ ${E} above`]:[],...S>0?[`↓ ${S} more`]:[]];if(x.length>0)t[i-2]?.put(0,x.join(" "),A);if(!s.searching&&s.tiles.length===0&&!s.error&&s.tag)t[he+1]?.put(0,s.preset==="cutouts"?`No transparent cutouts of ${s.tag} on ${zy(s)} — c searches every post, tab tries ${s.nextSite}`:`No posts of ${s.tag} on ${zy(s)} — tab tries ${s.nextSite}`,A);let R=GP(s,b,h),N=hm(s,R);return wa(t[i-1],r,o,{badge:"IMAGE SEARCH",lead:N,keys:y&&N?.[0]===R?[]:[["←↑↓→","move"],["enter","try on"],["tab","site"],["ctrl+v","picture"],["s","settings"],["/","search"],["?","keys"]],right:["esc","back"]}),b}function UP(t,e,n,r,i,s){let o=i.tiles[i.focus];if(!o)return;let a=i.shown?.id===o.key?i.shown:void 0,c=[dm(i,o.site,o.siteAnsi),[" ",""],...Li(String(o.id),at,o.page||void 0,Ur(o.siteAnsi)),[" ",""],Qy(o)];if(o.score>0)c.push([` · ★${o.score}`,A]);if(a)c.push([` · ${Ou(a.bytes)}`,A]);if(a){if(c.push([" ",""],...Xy(a)),i.coloring==="original")c.push([" · own colors",A])}if(t[0]?.run(0,c),o.mates.length>0)t[0]?.right(n,[["≈ ",s],[o.mates.join(" "),A]]);if(MP(t,1,2,i,s),i.tuning)TP(t,8,2,2+Math.min(n-4,60),i,s);else if(i.details)OP(t,5,2,Math.min(n-4,Math.max(48,Math.floor(n*0.55))),r-2,i);else EP(t,7,2,n-4,r-2,i,s);if(i.shown)e.push({id:mm+i.shown.id,path:i.shown.path,row:0,col:0,cols:n,rows:r,z:mP});if(i.tuning){wa(t[r-1],n,s,{badge:"IMAGE EDIT",lead:hm(i),keys:[["↑↓","field"],["←→","step"],["=","reset"],["+","reset all"],i.tuning.field===1?["1-9","place"]:["⇧←→","×10"],["c","colors"],["enter","keep"]],right:["esc","undo"]});return}let u=hm(i);wa(t[r-1],n,s,{badge:"IMAGE PREVIEW",lead:u,keys:i.installing===void 0?[["←→","browse"],["enter","install"],["t","tune"],["c","colors"],["i","details"],...i.details?[]:[["⇧←→","example"]],...i.shown?.cut==="on"||i.shown?.cut==="off"?[["x","cut out"]]:[],["?","keys"]]:[],right:i.installing===void 0?["esc","grid"]:void 0})}var WP=[["Field","↑↓ size, position, opacity"],["Step","←→ · ⇧←→ ×10"],["Place","1-9 the nine positions"],["Reset","= this field back to its default · + every field"],["Colors","c the palette's tone or its own colors, opacity back to its default"],["Keep","enter back to try, installed with the picture"],["Undo","esc"],["Close","? esc"]],KP={grid:[["Move","←↑↓→ j k home end pgup pgdn"],["Try on","enter"],["Site",`tab shift+tab all, ${Y.map((t)=>t.name).join(", ")}`],["Posts","c cutouts or every post"],["Search","/ a tag, a post URL or an id"],["Tags","1-9 turn a tag of the tags row on or off — the palette's own, then danbooru's related characters"],["Your own","ctrl+v or v a picture from the clipboard · drop one on the window or paste its link"],["Unfold","space a set of ×N"],["Open","o the post page in a browser"],["Settings","s rating, block, posts, solo, order, sets, remove bg"],["Advanced","a or Advanced › in settings min score, min size, sites, hide, hide tags, PNG only"],["Back","esc returns to preview"],["Close","? esc"]],try:[["Browse","←→"],["Install","enter"],["Tune","t size, position and opacity, installed with the picture"],["Colors","c the palette's tone or its own colors, installed with the picture"],["Details","i characters, series, tags, rating and file, under Post, Source and Artist"],["Example",`⇧←→ ${ie.map((t)=>t.name.toLowerCase()).join(", ")}`],["Cut out","x the background off or on, on an opaque picture"],["Open","o the post page in a browser"],["Your own","ctrl+v or v a picture from the clipboard · drop one on the window"],["Grid","esc"],["Close","? esc"]]},bm=6,zP=24;function $a(t){return[...t.settings.flatMap((e,n)=>Boolean(e.advanced)===t.advanced?[n]:[]),t.settings.length]}function DP(t){return t.replace(/^[A-Z](?=[a-z])/,(e)=>e.toLowerCase())}function Dy(t){let e=t.settings.filter((n)=>Boolean(n.advanced)!==t.advanced).map((n)=>DP(n.label));return`${t.advanced?"Back to":"More filters:"} ${e.join(", ")} — enter opens the page, or a from any row`}function nv(t,e,n){let r=t.indexOf(e);if(r!==-1)return t[(r+n+t.length)%t.length];let i=Number(e)||0;return(n>0?t.find((o)=>(Number(o)||0)>i):[...t].reverse().find((o)=>(Number(o)||0)<i))??t[n>0?0:t.length-1]}function Fi(t,e){let n=[],r="";for(let i of t.split(" "))if(r&&ft(r)+1+ft(i)>e)n.push(r),r=i;else r=r?`${r} ${i}`:i;return r?[...n,r]:n}function qP(t){if(t.entry!=="number"||t.choices.includes(t.value))return t.choices;let e=t.choices.findIndex((n)=>(Number(n)||0)>Number(t.value));return e===-1?[...t.choices,t.value]:[...t.choices.slice(0,e),t.value,...t.choices.slice(e)]}function YP(t,e,n,r){let i=`\x1B[7;${30+r}m`,s=e&&n!==void 0;if(t.entry==="text")return[{text:` ${s?`${n}█`:t.value||"none"} `,sgr:s||e&&t.value?i:t.value?"":A}];let o=s?[]:t.value.split(" "),a=(s?t.choices:qP(t)).map((c,u)=>{let l=o.includes(c),f=t.multi&&e&&u===t.cursor?"4;":"";return{text:t.multi?` ${l?"[x]":"[ ]"} ${c} `:` ${c} `,sgr:l?e?`\x1B[${f}7;${30+r}m`:"":f?`\x1B[4m${A}`:A,choice:c}});return s?[...a,{text:` ${n}█ `,sgr:i}]:a}function qy(t){if(t.entry==="text")return[{text:" ".repeat(zP),sgr:""}];let e=t.choices.map((n)=>({text:t.multi?` [x] ${n} `:` ${n} `,sgr:""}));return t.entry==="number"?[...e,{text:` ${"0".repeat(bm)}█ `,sgr:""}]:e}function JP(t){return t.reduce((e,n)=>e+ft(n.text)+1,0)-1}function Yy(t,e){let n=[[]],r=0;for(let i of t){let s=ft(i.text)>e?{...i,text:` …${Array.from(i.text).slice(-(e-2)).join("")}`}:i;if(r>0&&r+ft(s.text)>e)n.push([]),r=0;n[n.length-1]?.push(s),r+=ft(s.text)+1}return n}function Jy(t){if(t.multi&&t.choices.every((e)=>t.default.split(" ").includes(e)))return"Default all";return`Default ${t.default&&t.default!==t.multi?.none?t.default:"none"}`}function Vy(t){if(!t.tag)return"";if(!t.counts)return`${t.tag}: counting…`;let e=t.counts.map(({site:n,count:r})=>`${n} ${r===void 0?"no count":r.toLocaleString("en-US")}`);return`${t.tag}: ${e.join(" · ")}`}function VP(t,e){let n=t.advanced?"basic":"advanced";if(!e)return{keys:[["↑↓","setting"],["enter",n],["s","save"]],right:["esc","undo"]};if(t.typing!==void 0)return{keys:[["⌫","erase"],["enter","done"]],right:["esc","cancel"]};if(e.entry)return{keys:[["↑↓","setting"],...e.entry==="number"?[["←→","step"]]:[],["a",n],["enter","type"],["s","save"]],right:["esc","undo"]};return{keys:[["↑↓","setting"],["←→","value"],["a",n],...e.multi?[["space","toggle"]]:[],["enter","save"]],right:["esc","undo"]}}function ZP(t,e,n,r,i){let s=r.panel??0,o=r.settings.length,c=6+Math.max(...r.settings.map((U)=>ft(U.label))),u=Math.max(...r.settings.map((U)=>ft(Jy(U)))),l=c+Math.max(...r.settings.map((U)=>JP(qy(U))))+u+5,f=Math.min(e-2,Math.max(48,l)),d=f-c-u-5,h=f-7,m=[!1,!0].map((U)=>({advanced:U,rows:$a({settings:r.settings,advanced:U}).slice(0,-1)})),$=r.settings.map((U)=>Yy(qy(U),d).length),g=Math.max(...m.map((U)=>U.rows.reduce((yt,et)=>yt+$[et],0))),b=Math.max(...m.map((U)=>Fi(Dy({settings:r.settings,advanced:U.advanced}),h).length),...r.settings.map((U)=>Fi(U.about,h).length)),y=`${r.tag}: ${Y.map((U)=>`${U.name} 0,000,000`).join(" · ")}`,E=r.tag?Math.max(Fi(y,h).length,Fi(Vy(r),h).length):0,S=g+b+E+8,x=Math.floor((e-f)/2),R=Math.max(1,Math.floor((n-1-S)/2)),N=`\x1B[7;${30+r.siteAnsi}m`;t[R]?.put(x,`╭─ Settings ${"─".repeat(Math.max(0,f-13))}╮`);for(let U=R+1;U<R+S-1;U++)t[U]?.put(x,`│${" ".repeat(f-2)}│`);let F=R+2;for(let U of $a(r).slice(0,-1)){let yt=r.settings[U],et=U===s;if(et)t[F]?.put(x+2,"▶",i);if(t[F]?.mark(x+2,c-3,{kind:"setting",index:U}),t[F]?.put(x+4,yt.label,et?at:""),yt.value!==yt.default)t[F]?.right(x+f-3,[[Jy(yt),A]]);Yy(YP(yt,et,r.typing,r.siteAnsi),d).forEach((Xn,en)=>{let nn=x+c;for(let rn of Xn)nn=t[F+en].put(nn,rn.text,rn.sgr,void 0,{kind:"choice",index:U,choice:rn.choice}),nn+=1}),F+=$[U]}let _=m.find((U)=>U.advanced!==r.advanced)?.rows??[],B=t[R+3+g];if(s===o)B.put(x+2,"▶",i);let tt=B.put(x+3,r.advanced?" ‹ Basic ":" Advanced › ",s===o?N:at,void 0,{kind:"setting",index:o});if(_.some((U)=>r.settings[U]?.value!==r.settings[U]?.default))B.put(tt+1,"•",A);t[R+5+g]?.put(x+2,"─".repeat(f-4),A),Fi(r.settings[s]?.about??Dy(r),h).forEach((U,yt)=>{t[R+6+g+yt]?.put(x+4,U)}),Fi(Vy(r),h).forEach((U,yt)=>{t[R+6+g+b+yt]?.put(x+4,U,A)}),t[R+S-1]?.put(x,`╰${"─".repeat(f-2)}╯`);let{keys:W,right:Q}=VP(r,r.settings[s]);wa(t[n-1],e,i,{keys:W,right:Q})}function QP(t,e,n,r,i){let s=r.tuning?WP:KP[r.mode],o=Math.min(e-2,Math.max(50,...s.map(([,d])=>ft(d)+16))),a=s.map(([d,h])=>({label:d,parts:Fi(h,o-16)})),c=a.reduce((d,{parts:h})=>d+h.length,0)+4,u=Math.floor((e-o)/2),l=Math.max(2,Math.floor((n-c)/2));t[l]?.put(u,`╭─ Help ${"─".repeat(o-9)}╮`);for(let d=l+1;d<l+c-1;d++)t[d]?.put(u,`│${" ".repeat(o-2)}│`);let f=l+2;for(let{label:d,parts:h}of a){t[f]?.put(u+3,d,at);for(let m of h)t[f]?.put(u+13,m),f++}t[l+c-1]?.put(u,`╰${"─".repeat(o-2)}╯`),wa(t[n-1],e,i,{badge:"HELP",right:["? esc","close"]})}function XP(t,e,n){let r=e.suggest??[],i=r.map((a)=>a.alias??(a.count>0?String(a.count):a.palette??"0")),s=Math.max(...r.map((a)=>ft(a.value))),o=Math.max(7,...i.map(ft));r.forEach((a,c)=>{let u=c===e.pick,l=t[1+c];l?.run(0,[[u?"▸ ":" ",n,void 0,{kind:"suggest",index:c}],[a.value,u?at+n:"",void 0,{kind:"suggest",index:c}]]),l?.right(2+s+2+o,[[i[c],A]])})}function Wu(t,e=[]){return[...e,...t.flatMap((n,r)=>n.zones(r))]}function wm(t,e,n){let r=Array.from({length:n},()=>new Ku(e)),i=[],s=[],o=Xs(t.colors.cursor);if(um=!1,e<Ci.cols||n<Ci.rows)return r[0]?.put(0,"ttheme find",at+o),r[1]?.put(0,`Needs ${Ci.cols}×${Ci.rows} — now ${e}×${n}`),r[2]?.put(0,"esc quits",A,void 0,{kind:"key",key:"esc"}),{lines:r.map((c)=>c.render()),images:i,zones:Wu(r),loader:!1,tick:!1};let a=!1;if(t.mode==="try")UP(r,i,e,n,t,o);else a=BP(r,i,s,e,n,t,o);if(t.mode==="grid"&&t.editing!==void 0&&t.suggest?.length){for(let c=1;c<n-1;c++)r[c]=new Ku(e);return XP(r,t,o),{lines:r.map((c)=>c.render()),images:[],zones:Wu(r),loader:!1,tick:!1}}if(t.help||t.panel!==void 0){let c=t.mode==="try"?i:[];for(let u=0;u<n;u++)r[u]=new Ku(e);if(t.help)QP(r,e,n,t,o);else ZP(r,e,n,t,o);return{lines:r.map((u)=>u.render()),images:c,zones:Wu(r),loader:!1,tick:!1}}return{lines:r.map((c)=>c.render()),images:i,zones:Wu(r,s),loader:a,tick:um}}import{execFile as tH}from"node:child_process";import{createHash as ov}from"node:crypto";import{existsSync as eH,mkdtempSync as nH,readFileSync as Zu,rmSync as rH,statSync as av,writeFileSync as cv}from"node:fs";import{homedir as iH,tmpdir as sH}from"node:os";import{join as Yu}from"node:path";import{fileURLToPath as oH}from"node:url";import{promisify as aH}from"node:util";var yn=aH(tH),Ju=67108864,cH=4096,ym=["image/png","image/jpeg","image/webp","image/gif","image/tiff","image/heic"],uH=["text/uri-list","text/plain;charset=utf-8","text/plain"],$m=[...ym,"text/uri-list","text/plain"];function lH(t){try{return av(t).isFile()}catch{return!1}}function fH(t){let e=[],n="",r="",i=!1;for(let s=0;s<t.length;s++){let o=t[s];if(r==="'")if(o==="'")r="";else n+=o;else if(r==='"')if(o==='"')r="";else if(o==="\\"&&'"\\$`'.includes(t[s+1]??""))n+=t[++s];else n+=o;else if(o==="\\"&&s+1<t.length)n+=t[++s],i=!0;else if(o==="'"||o==='"')r=o,i=!0;else if(/\s/.test(o)){if(i)e.push(n);n="",i=!1}else n+=o,i=!0}if(i)e.push(n);return e}function rv(t){if(/^file:\/\//i.test(t))try{return oH(t)}catch{return}if(t.startsWith("~/"))return Yu(iH(),t.slice(2));return t.startsWith("/")?t:void 0}function eo(t,e=lH){let n=[];for(let r of t.replace(/\r\n?/g,`
655
+ `)}`:" passes the gate"}`)}for(let h of r)console.error(` ✗ ${h}`);for(let h of i)console.log(` ! ${h}`);let f=(h,m)=>`${h} ${m}${h===1?"":"s"}`;return console.log(`
656
+ ${u} · ${Tt(l.length)} · ${f(r.length,"error")} · ${f(i.length,"warning")}`),r.length>0?1:0}async function p1(t,e){switch(t){case void 0:ZT();return;case"add":await YT(r1(t,e));return;case"remove":JT(r1(t,e));return;case"search":await QT(e);return;case"init":await tH(e);return;case"check":return eH(e);default:throw Error(`unknown market action ${t} — ${UT.join(", ")}, or none to list them`)}}function r1(t,e){if(!e)throw Error(t==="add"?"market add takes a repository or a folder: ttheme market add alice/ttheme-dust":"market remove takes a market name — `ttheme market` lists them");return e}function g1(t,e){let n=cs(t,e);return`${n} — ${Tt(Xe(e,n,Oa(t),ue(!1)).length)}, read in place`}var nH=new Intl.Segmenter(void 0,{granularity:"grapheme"});function b1(t){return[...t].length===1&&t>=" "&&t!==""}function rH(t){return[...t.replace(/[\r\n\t]+/g," ")].filter(b1).join("")}function Ki(t,e,n=()=>!0){if(e==="backspace")return[...nH.segment(t)].slice(0,-1).map((r)=>r.segment).join("");if(e==="ctrl-u")return"";if(e==="ctrl-w"||e==="alt-backspace")return t.replace(/\S*\s*$/,"");return b1(e)&&n(e)?t+e:void 0}class Vr{value;constructor(t=""){this.value=t}key(t){let e=Ki(this.value,t);if(e===void 0)return!1;return this.value=e,!0}paste(t){this.value+=rH(t)}}import{performance as iH}from"node:perf_hooks";import{StringDecoder as oH}from"node:string_decoder";var sH=30,w1=50,aH=500,cH=5,$1=Buffer.from("\x1B[M"),rl="\x1B]1337;ReportCellSize\x07\x1B[16t\x1B[14t\x1B[18t",O1="\x1B[?1016$p\x1B[16t",I1={A:"up",B:"down",C:"right",D:"left",H:"home",F:"end","1~":"home","7~":"home","3~":"delete","4~":"end","8~":"end","5~":"pgup","6~":"pgdn",I:"focus-in",O:"focus-out",Z:"shift-tab","1;2C":"shift-right","1;2D":"shift-left"},uH={"\r":"enter","\n":"enter","\t":"tab","\b":"backspace","":"backspace","\x1B":"esc","\x00":"ctrl-space"},k1=/\[([0-?]*)([ -/]*)([@-~])/y,lH=/^\[[0-?]*[ -/]*$/,y1=/\[(<-?\d+;-?\d+;-?\d+)([Mm])/y,dH=/^\[<[-\d;]*$/,v1=/\](\d+)/y,fH=/^\]\d*$/,S1=/\]\d+;/y,hH=/^1337;ReportCellSize=([\d.]+);([\d.]+)(?:;([\d.]+))?$/,mH=/^(1[0-2]|17|4;\d{1,3});(rgba?:[0-9a-fA-F/]+)$/,R1="\x1B[200~",nl="\x1B[201~";function pH(t){let e=uH[t];if(e)return e;let n=t.codePointAt(0)??0;if(n<27)return`ctrl-${String.fromCharCode(n+96)}`;return n<32?void 0:t}function us(t){return{kind:"key",key:t}}function ls(t){return{events:[us("esc")],end:t+1}}function gH(t){let e={};for(let n of t.split(":")){let r=n.indexOf("=");if(r>0)e[n.slice(0,r)]=n.slice(r+1)}return e}var bH=["left","middle","right",void 0];function Hm(t,e,n,r){if(!Number.isInteger(t)||t<0||t>=128||!(e>=0)||!(n>=0))return;let i=t&3,o={kind:"mouse",row:n,col:e,shift:(t&4)!==0,alt:(t&8)!==0,ctrl:(t&16)!==0};if(t&64)return{...o,action:"wheel",button:void 0,wheel:i%2===0?-1:1,sideways:i>=2,count:0};let s=bH[i],a=t&32?s?"drag":"move":r||!s?"release":"press";return{...o,action:a,button:s,wheel:0,sideways:!1,count:a==="press"?1:0}}function wH(t,e,n){let r=[],i=e;while(r.length<3&&i<t.length){let u=t.codePointAt(i);r.push(u),i+=u>65535?2:1}if(r.length<3)return n?{events:[],end:t.length}:void 0;let[o=0,s=0,a=0]=r,c=Math.max(o,s,a)<128?Hm(o-32,s-33,a-33,!1):void 0;return{events:c?[c]:[],end:i}}function $H(t,e,n,r,i){let o=Math.max(0,e)/i.w,s=Math.max(0,n)/i.h,a=Math.floor(o),c=Math.floor(s),u=Hm(t,a,c,r);return u&&{...u,fx:o-a,fy:s-c}}function E1(t,e,n,r){if((n==="M"||n==="m")&&e===""&&t.startsWith("<")){let[o=-1,s=0,a=0]=t.slice(1).split(";").map(Number),c=r?$H(o,s,a,n==="m",r):Hm(o,s-1,a-1,n==="m");return c?[c]:[]}if(n==="t"&&e===""){let[o,s=0,a=0]=t.split(";").map(Number),c=o===6?"cell":o===4?"window":o===8?"grid":void 0;return c?[{kind:"size",of:c,h:s,w:a}]:[]}if(n==="y"&&e==="$"&&t.startsWith("?")){let[o=0,s=0]=t.slice(1).split(";").map(Number);return[{kind:"mode",mode:o,value:s}]}if(n==="c"&&t.startsWith("?"))return[{kind:"attributes"}];let i=e===""?I1[`${t}${n}`]:void 0;return i?[us(i)]:[]}function kH(t,e,n,r){y1.lastIndex=e+1;let i=y1.exec(t);if(i)return{events:E1(i[1],"",i[2],r),end:e+1+i[0].length};k1.lastIndex=e+1;let o=k1.exec(t);if(!o){let d=t.slice(e+1);return!n&&(lH.test(d)||dH.test(d))?void 0:ls(e)}let[s,a="",c="",u=""]=o,l=e+1+s.length;if(a===""&&c===""&&u==="M")return wH(t,l,n);if(a==="200"&&u==="~"){let d=t.indexOf(nl,l);if(d===-1)return n?{events:[{kind:"paste",text:t.slice(l)}],end:t.length}:void 0;return{events:[{kind:"paste",text:t.slice(l,d)}],end:d+nl.length}}return{events:E1(a,c,u,r),end:l}}function yH(t){let e=hH.exec(t);if(e){let s=Number(e[3]??1);return[{kind:"size",of:"cell",h:Math.round(Number(e[1])*s),w:Math.round(Number(e[2])*s)}]}let n=mH.exec(t);if(n)return[{kind:"color",code:n[1],value:n[2]}];let[r="",i="",...o]=t.split(";");return[{kind:"osc",code:r,meta:gH(i),payload:o.join(";")}]}function vH(t,e,n){v1.lastIndex=e+1;let r=v1.exec(t),i=r?t[e+1+r[0].length]:void 0;if(i!==";"&&i!=="\x07"&&i!=="\x1B")return!n&&fH.test(t.slice(e+1))?void 0:ls(e);let o=[t.indexOf("\x07",e),t.indexOf("\x1B\\",e+2)].filter((a)=>a!==-1);if(o.length===0)return n?{events:[],end:t.length}:void 0;let s=Math.min(...o);return{events:yH(t.slice(e+2,s)),end:s+(t[s]==="\x07"?1:2)}}function SH(t,e,n){let r=t[e+2];if(r===void 0)return n?ls(e):void 0;if(!/^[A-Za-z]$/.test(r))return ls(e);let i=I1[r];return{events:i?[us(i)]:[],end:e+3}}function EH(t,e,n,r){let i=t[e+1];if(i===void 0)return n?ls(e):void 0;if(i==="[")return kH(t,e,n,r);if(i==="]")return vH(t,e,n);if(i==="O")return SH(t,e,n);if(i==="")return{events:[us("alt-backspace")],end:e+2};if(/^[a-z]$/.test(i))return{events:[us(`alt-${i}`)],end:e+2};return ls(e)}function M1(t,e=!1,n){let r=[],i=0;while(i<t.length){if(t[i]==="\x1B"){let a=EH(t,i,e,n);if(!a)return{events:r,rest:t.slice(i)};r.push(...a.events),i=a.end;continue}let o=String.fromCodePoint(t.codePointAt(i)),s=pH(o);if(s)r.push(us(s));i+=o.length}return{events:r,rest:""}}function MH(t){let e=t.indexOf($1);if(e===-1)return{bytes:t,carry:void 0};let n=[],r=0;while(e!==-1&&e+6<=t.length){n.push(t.subarray(r,e));let[i=0,o=0,s=0]=t.subarray(e+3,e+6);if(o>32&&s>32)n.push(Buffer.from(`\x1B[<${i-32};${o-32};${s-32}M`));r=e+6,e=t.indexOf($1,r)}return n.push(t.subarray(r,e===-1?t.length:e)),{bytes:Buffer.concat(n),carry:e===-1?void 0:t.subarray(e)}}function x1(t){return S1.lastIndex=1,t.startsWith(R1)||t.startsWith("\x1B]")&&S1.test(t)}function xH(t,e){let n=t.slice(-nl.length)+e;return t.startsWith(R1)?n.includes(nl):n.includes("\x07")||n.includes("\x1B\\")}class Cm{held="";timer;carry;pressed;wheeled;utf8=new oH("utf8");burst;cell;take;constructor(t,e=()=>!1,n=()=>{return}){this.burst=e,this.cell=n,this.take=(r)=>{let i=this.counted(r);if(i.length>0)t(i)}}counted(t){let e=iH.now();return t.filter((n)=>{if(n.kind!=="mouse")return!0;if(n.action==="wheel"){let o=n.wheel*(n.sideways?2:1),s=this.wheeled;if(s!==void 0&&s.way===o&&e-s.at<cH)return!1;return this.wheeled={at:e,way:o},!0}if(n.action==="release")n.count=this.pressed?.count??0;if(n.action!=="press"||!n.button)return!0;let r=this.pressed,i=r!==void 0&&r.button===n.button&&r.row===n.row&&Math.abs(r.col-n.col)<=1&&e-r.at<=aH;return n.count=i?r.count+1:1,this.pressed={at:e,button:n.button,row:n.row,col:n.col,count:n.count},!0})}feed(t){clearTimeout(this.timer);let e=typeof t==="string"?t:this.bytes(t);if(this.carry)this.wait(w1);if(!this.held&&!e.includes("\x1B")&&this.burst(e)){this.take([{kind:"paste",text:e}]);return}if(x1(this.held)&&!xH(this.held,e)){this.held+=e;return}let{events:n,rest:r}=M1(this.held+e,!1,this.cell());if(this.held=r,r&&!x1(r))this.wait(r.length===1?sH:w1);if(n.length>0)this.take(n)}bytes(t){let{bytes:e,carry:n}=MH(this.carry?Buffer.concat([this.carry,t]):t);return this.carry=n,this.utf8.write(e)}wait(t){clearTimeout(this.timer),this.timer=setTimeout(()=>this.flush(),t)}flush(){clearTimeout(this.timer),this.carry=void 0;let{events:t}=M1(this.held,!0,this.cell());if(this.held="",t.length>0)this.take(t)}stop(){clearTimeout(this.timer),this.held="",this.carry=void 0}}class Ra{window;grid;see(t){if(t.kind!=="size")return;if(t.of==="cell")return{w:t.w,h:t.h};if(t.of==="window")this.window=t;else this.grid=t;let e=this.window,n=this.grid;return e&&n&&n.h>0&&n.w>0?{h:Math.floor(e.h/n.h),w:Math.floor(e.w/n.w)}:void 0}}class Lm{known=!1;cell;see(t){if(t.kind==="mode"&&t.mode===1016)this.known=t.value===1||t.value===2;else if(t.kind==="size"&&t.of==="cell"&&t.w>0&&t.h>0)this.cell={w:t.w,h:t.h};else if(t.kind==="attributes")return{cell:this.known?this.cell:void 0};return}}var ol={on:"\x1B[?1049h",off:"\x1B[?1049l"},Rn={on:"\x1B[?25l",off:"\x1B[?25h"},Zr={on:"\x1B[?7l",off:"\x1B[?7h"},ir={on:"\x1B[?2004h",off:"\x1B[?2004l"},C1={on:"\x1B[?1004h",off:"\x1B[?1004l"},OH={on:"\x1B[?1000h\x1B[?1002h\x1B[?1006h",off:"\x1B[?1006l\x1B[?1002l\x1B[?1000l"},P1={on:"\x1B[?1016h",off:"\x1B[?1016l\x1B[?1006h"};function Qr(t=process.env){return t.TTHEME_MOUSE==="off"?[]:[OH]}var L1={SIGHUP:1,SIGINT:2,SIGQUIT:3,SIGTERM:15},IH=3000;class Na extends Error{exit;constructor(t){super(t);this.exit=128+L1[t]}}var In=[],zi=new Map,Pa=new Map,N1;function A1(t){return In.findLast((e)=>e.input===t)}var T1;function F1(t){for(let e of[...In].reverse())e.abort(t);if(!T1)T1=setTimeout(()=>{j1(),process.exit(t instanceof Na?t.exit:1)},IH).unref()}var RH=Object.fromEntries(Object.keys(L1).map((t)=>[t,()=>F1(new Na(t))]));function j1(){for(let t of[...In].reverse())t.close()}function PH(){for(let t of In)t.reassert();In.at(-1)?.redraw()}function H1(t){let e=t?"on":"off";for(let[n,r]of Object.entries(RH))process[e](n,r);if(process[e]("uncaughtException",F1),process[e]("exit",j1),process.platform!=="win32")process[e]("SIGCONT",PH)}function il(){}class _1{input;output;failed;modes=[];assumed;owned=[];keys;tty;take;resized;queued=[];asking;reject=il;open=!0;aborted=!1;constructor(t={}){if(this.input=t.input??process.stdin,this.output=t.output??process.stdout,this.tty=this.output.isTTY===!0&&this.input.isTTY===!0,this.assumed=t.assume??[],this.keys=new Cm((r)=>this.deliver(r),t.burst,()=>zi.has(P1)?N1:void 0),this.failed=new Promise((r,i)=>{this.reject=i}),this.failed.catch(il),this.tty&&!In.some((r)=>r.tty))H1(!0);In.push(this);let e="";for(let r of this.assumed)if(!zi.has(r))e+=r.on;for(let r of t.modes??[])e+=this.claim(r);this.write(e);let n=Pa.get(this.input)??0;if(n===0)this.input.setRawMode?.(!0);Pa.set(this.input,n+1),this.input.on("data",this.received),this.input.resume(),this.output.on("resize",this.resizing),this.output.on("error",il)}hold(t){this.write(this.claim(t))}pixels(t){N1=t,this.hold(P1)}get cols(){return this.output.columns||80}get rows(){return this.output.rows||24}write(t){if(t&&this.open)this.output.write(t)}listen(t){this.take=t;let e=this.queued;if(this.queued=[],e.length>0)t(e)}onResize(t){this.resized=t}until(t){return Promise.race([t,this.failed])}loop(t,e=()=>{}){return this.until(new Promise((n)=>{let r=!1;this.listen((i)=>{for(let o of i){let s=r?void 0:t(o);if(s!==void 0)r=!0,n(s)}if(!r)e()})}))}ask(t,e,n,r=!0){return new Promise((i)=>{let o={hold:r,pick:(c)=>{let u=e(c);if(u===void 0)return!1;return s(u),!0}},s=(c)=>{if(clearTimeout(a),this.asking===o)this.asking=void 0;i(c),this.release()},a=setTimeout(()=>s(void 0),n);this.asking=o,this.write(t)})}abort(t){if(this.aborted)return;this.aborted=!0,this.keys.stop(),this.reject(t)}redraw(){this.resized?.()}reassert(){if(this.open)this.input.setRawMode?.(!0),this.write([...this.assumed,...this.owned].map((t)=>t.on).join(""))}close(){if(!this.open)return;this.keys.stop(),this.input.off("data",this.received),this.output.off("resize",this.resizing);let t="";for(let n of[...this.modes].reverse()){let r=(zi.get(n)??1)-1;if(r===0)zi.delete(n),t+=n.off;else zi.set(n,r)}this.write(t),this.open=!1;let e=(Pa.get(this.input)??1)-1;if(e===0)Pa.delete(this.input),this.input.setRawMode?.(!1),this.input.pause();else Pa.set(this.input,e);if(this.output.off("error",il),In.splice(In.indexOf(this),1),this.tty&&!In.some((n)=>n.tty))H1(!1)}received=(t)=>{if(A1(this.input)===this&&!this.aborted)this.keys.feed(t)};resizing=()=>{if(A1(this.input)===this)this.resized?.()};claim(t){this.modes.push(t);let e=zi.get(t)??0;if(zi.set(t,e+1),e>0)return"";return this.owned.push(t),t.on}deliver(t){let e=this.asking,n=e?t.filter((r)=>!e.pick(r)):t;if(n.length===0)return;if(!this.take||this.asking?.hold){this.queued.push(...n);return}this.take(n)}release(){if(this.take&&this.queued.length>0){let t=this.queued;this.queued=[],this.take(t)}}}async function Xr(t,e){let n=new _1(t);try{return await e(n)}finally{n.close()}}var NH=3;function Aa(t,e){return`${t}/${e}`}function B1(t){return lt(t.name)?de(t.name):t.name}function ds(t){return t.catalog!==void 0&&U1(t.group)?Aa(t.group,t.catalog):void 0}function Fm(t){if(t?.kind==="palette")return`palette ${t.entry.name}`;if(t?.kind==="group")return`group ${t.name}`;if(t?.kind==="catalog")return`catalog ${Aa(t.group,t.name)}`;return t?.kind??""}function sl(t,e){return Ei([t.name,t.group,t.native??"",t.catalog??"",...t.nativeNames??[],...Kc(t.booru)],e)}function G1(t,e,n){let r=n.trim(),i=[],o=new Set,s=(a)=>({kind:"palette",entry:a});for(let a of t){if(a.default||o.has(a.group))continue;o.add(a.group);let c=t.filter((f)=>!f.default&&f.group===a.group),u=r?c.filter((f)=>sl(f,r)):c;if(r&&u.length===0)continue;let l=r.length>0||e.has(a.group);if(i.push({kind:"group",name:a.group,native:a.native,lead:c.find((f)=>f.lead)??a,expanded:l,count:u.length}),!l)continue;let d=u.filter((f)=>ds(f)!==void 0);for(let f of new Set(d.map((h)=>h.catalog))){let h=d.filter((g)=>g.catalog===f),m=r.length>0||e.has(Aa(a.group,f));if(i.push({kind:"catalog",group:a.group,name:f,lead:h[0],expanded:m,count:h.length}),m)i.push(...h.map(s))}i.push(...u.filter((f)=>ds(f)===void 0).map(s))}return i}function AH(t,e){let n=e.trim(),r=new Set(t.filter((i)=>!i.default&&(n===""||sl(i,n))).map((i)=>i.group));return G1(t,new Set,"").filter((i)=>i.kind==="group"&&r.has(i.name))}function U1(t){return t.includes("@")}function jm(t,e,n,r,i=!0){let o=n-1;if(o<0)return t;let s;if(!Number.isFinite(e))s=e>0?o:0;else if(e>0)s=t>=o?i?0:o:Math.min(o,t+e);else s=t<=0?i?o:0:Math.max(0,t+e);return r(s)?s+Math.sign(e):s}function al(t,e){let n={home:Number.NEGATIVE_INFINITY,end:Number.POSITIVE_INFINITY,pgup:-e,pgdn:e};return t===void 0?void 0:n[t]}function TH(t){let e=t.findIndex((n)=>n.kind==="group"&&U1(n.name));return e>0&&t.slice(0,e).some((n)=>n.kind==="group")?[...t.slice(0,e),{kind:"rule"},...t.slice(e)]:t}function HH(t){let e=t.findIndex((n)=>n.kind==="palette");return e===-1?0:e}function cl(t){return t==="decode"||t==="glitch"?t:"typewriter"}function fs(t,e,n){return Vt({kind:"row",at:t,part:e},n)}class Ta{picked;scope;maxItems;named=[];series=[];color;onFocus;entries=[];seriesPad=0;namePad=0;expanded=new Set;rows=[];cursor=0;top=0;filter="";lastFocused="";constructor(t){this.picked=t.picked,this.scope=t.scope??"palette",this.maxItems=t.maxItems??12,this.color=t.color??!0,this.onFocus=t.onFocus,this.load(t.entries),this.rebuild("first")}load(t){this.entries=t,this.named=t.filter((e)=>!e.default),this.series=[...new Set(this.named.map((e)=>e.group))],this.seriesPad=Math.max(0,...this.series.map((e)=>e.length)),this.namePad=Math.max(0,...this.named.map((e)=>this.indent(e).length+B1(e).length))}indent(t){return ds(t)===void 0?" ":" "}setEntries(t){this.load(t),this.rebuild("stay")}setFilter(t){if(t!==this.filter)this.filter=t,this.rebuild("keep")}clear(){let t=this.rows[this.cursor];if(t?.kind==="palette"&&!t.entry.default){this.expanded.add(t.entry.group);let e=ds(t.entry);if(e!==void 0)this.expanded.add(e)}this.setFilter("")}focusedRow(){return this.rows[this.cursor]}refocus(){this.lastFocused="",this.sync()}members(t,e){let n=this.scope==="palette"?this.filter.trim():"";return this.named.filter((r)=>r.group===t&&(e===void 0||r.catalog===e)&&(n===""||sl(r,n)))}everyone(t){return t.flatMap((e)=>e.kind==="group"?this.members(e.name):[])}pick(){let t=this.rows[this.cursor],e=t?.kind==="palette"?[t.entry.name]:t?.kind==="group"?this.members(t.name).map((r)=>r.name):t?.kind==="catalog"?this.members(t.group,t.name).map((r)=>r.name):t?.kind==="all"?this.everyone(this.rows).map((r)=>r.name):[];if(e.length===0)return;let n=e.some((r)=>!this.picked.has(r));for(let r of e)if(n)this.picked.add(r);else this.picked.delete(r)}pickedIn(t,e){return this.members(t,e).filter((n)=>this.picked.has(n.name)).length}pickedCount(){if(this.scope==="palette")return this.named.filter((t)=>this.picked.has(t.name)).length;return this.series.filter((t)=>this.members(t).every((e)=>this.picked.has(e.name))).length}total(){return this.scope==="series"?this.series.length:this.named.length}matched(){let t=this.filter.trim();if(this.scope==="series")return this.rows.filter((e)=>e.kind==="group").length;return t?this.named.filter((e)=>sl(e,t)).length:this.named.length}sync(){let t=this.rows[this.cursor],e=t?.kind==="palette"?t.entry:t?.kind==="group"&&this.scope==="series"?t.lead:void 0;if(e&&e.name!==this.lastFocused)this.lastFocused=e.name,this.onFocus?.(e)}rebuild(t){let e=this.rows[this.cursor],n=this.scope==="series"?AH(this.entries,this.filter):G1(this.entries,this.expanded,this.filter);this.rows=n.length>0?TH([{kind:"all",count:this.allCount(n)},...n]):[];let r=n.length>0?this.rows.indexOf(n[HH(n)]):0;if(t==="first")this.cursor=r;else if(t==="keep"||t==="stay"){let i=Fm(e),o=e?.kind==="palette"||t==="stay"?this.rows.findIndex((s)=>Fm(s)===i):-1;this.cursor=o===-1?r:o}else if(this.cursor>=this.rows.length)this.cursor=Math.max(0,this.rows.length-1);this.sync()}allCount(t){return this.scope==="series"?t.length:this.everyone(t).length}move(t,e=!0){this.cursor=jm(this.cursor,t,this.rows.length,(n)=>this.rows[n]?.kind==="rule",e),this.sync()}point(t){let e=this.rows[t];if(!e||e.kind==="rule")return!1;return this.cursor=t,this.sync(),!0}flip(){let t=this.rows[this.cursor];if(t?.kind==="group"||t?.kind==="catalog")this.fold(!t.expanded)}foldable(){let t=this.rows[this.cursor];return(t?.kind==="group"||t?.kind==="catalog")&&this.scope==="palette"&&!this.filter}open(){if(this.foldable())this.flip();else this.pick()}toggle(t){if(this.expanded.has(t))this.expanded.delete(t);else this.expanded.add(t);this.rebuild("clamp")}climb(t,e){this.expanded.delete(t),this.rebuild("clamp"),this.reach(e)}reach(t){this.cursor=Math.max(0,this.rows.findIndex((e)=>Fm(e)===t)),this.sync()}fold(t){if(this.filter||this.scope==="series")return;let e=this.rows[this.cursor];if(e?.kind==="group"){if(t!==e.expanded)this.toggle(e.name)}else if(e?.kind==="catalog"){if(t!==e.expanded)this.toggle(Aa(e.group,e.name));else if(!t)this.reach(`group ${e.group}`)}else if(e?.kind==="palette"&&!t&&!e.entry.default){let n=ds(e.entry);if(n===void 0)this.climb(e.entry.group,`group ${e.entry.group}`);else this.climb(n,`catalog ${n}`)}}window(){if(this.cursor<this.top)this.top=this.cursor;if(this.cursor>=this.top+this.maxItems)this.top=this.cursor-this.maxItems+1;this.top=Math.min(this.top,Math.max(0,this.rows.length-this.maxItems));let t=this.rows.slice(this.top,this.top+this.maxItems);return{lines:t.map((e,n)=>this.renderRow(e,this.top+n)),above:this.top,below:this.rows.length-this.top-t.length}}renderRow(t,e){if(t.kind==="rule")return` ${this.color?`${C}${"── Markets ──────────"}${Lt}`:"── Markets ──────────"}`;return fs(e,"row",this.rowText(t,e))}rowText(t,e){let n=e===this.cursor,r=t.kind==="palette"?t.entry:t.kind==="all"?void 0:t.lead,i=this.color&&n&&r!==void 0,o=(v)=>this.color?`${C}${v}${$e}`:v,s=(v)=>this.color?`${ct}${v}${$e}`:v,a=(v)=>this.color?` ${Fg(Bc(v),i?qe(v.foreground):"\x1B[39m")}`:"",c=n?i?`${qe(r.cursor)}▌\x1B[39m `:"▌ ":" ",u=(v)=>i?`${c}${mc(r.selection,r.foreground)} ${v} ${Lt}`:`${c} ${v}`,l=(v)=>fs(e,"box",`${v?"●":"○"} `),d=(v)=>fs(e,"fold",`${v?"▾":"▸"} `);if(t.kind==="all")return u(`${l(this.everyone(this.rows).every((v)=>this.picked.has(v.name)))}Select all ${o(`(${t.count})`)}`);if(t.kind==="group"&&this.scope==="series"){let v=`(${t.count})${t.native?` ${t.native}`:""}`;return u(`${l(this.pickedIn(t.name)===t.count)}${s(t.name.padEnd(this.seriesPad))}${a(t.lead)}${this.color?" ":" "}${o(v)}`)}let f=this.rows[this.cursor],h=(v,S)=>this.color&&f?.kind==="palette"&&v?`${ct}${qe(f.entry.cursor)}${S}${$e}\x1B[39m`:s(S);if(t.kind==="group"){let v=h(f?.kind==="palette"&&f.entry.group===t.name,t.name),S=t.native?` ${o(t.native)}`:"";return u(`${d(t.expanded)}${v} ${o(`(${this.pickedIn(t.name)}/${t.count})`)}${S}`)}if(t.kind==="catalog"){let v=f?.kind==="palette"&&ds(f.entry)===Aa(t.group,t.name),S=o(`(${this.pickedIn(t.group,t.name)}/${t.count})`);return u(` ${d(t.expanded)}${h(v,t.name)} ${S}`)}let m=t.entry,g=this.indent(m),b=B1(m),w=this.color?b.padEnd(this.namePad-g.length):b,k=n?s(w):w;return u(`${g}${l(this.picked.has(m.name))}${k}${a(m)}`)}}function _m(t){let e=t.named[Math.floor(Math.random()*t.named.length)],n=t.series[Math.floor(Math.random()*t.series.length)];return e&&n?`${e.name} | ${n}`:""}class ul{fx;make;redraw;roller;example="";step=0;seed=0;timer;constructor(t,e,n){this.fx=t,this.make=e,this.redraw=n,this.roll(),this.roller=setInterval(()=>{this.roll(),this.step=8,this.redraw()},3000),this.roller.unref?.()}stop(){clearInterval(this.roller),clearTimeout(this.timer)}roll(){let t=this.make();this.example=t.length>30?`${t.slice(0,29)}…`:t,this.seed=Math.floor(Math.random()*997)}text(){if(this.step===0)return this.example;if(!this.timer)this.timer=setTimeout(()=>{this.timer=void 0,this.step-=1,this.redraw()},60),this.timer.unref?.();let t=Math.floor(this.example.length*(8-this.step)/8);if(this.fx==="typewriter")return`${this.example.slice(0,t)}▏`;let e=this.fx==="decode"?"abcdefghijklmnopqrstuvwxyz":"▓▒░#*+=<>?/-_",n=this.fx==="decode"?(r)=>!/[a-z0-9]/i.test(r):(r)=>r===" ";return[...this.example].map((r,i)=>i+(i*7+this.seed)%3<t||n(r)?r:e[Math.floor(Math.random()*e.length)]??r).join("")}}var CH=5;class Bm{picked;list;scope;color;required;most;hint;field=new Vr;input;output;state="active";error="";redraw=()=>{};constructor(t){this.scope=t.scope??"palette",this.picked=new Set(t.installed??[]),this.color=t.color??!0,this.required=t.required??!1,this.most=t.maxItems??12,this.input=t.input,this.output=t.output,this.list=new Ta({entries:t.entries,picked:this.picked,scope:this.scope,maxItems:this.most,color:this.color,...t.onFocus?{onFocus:t.onFocus}:{}}),this.hint=new ul(t.fx??"typewriter",()=>_m(this.list),()=>this.redraw())}prompt(){return Xr({input:this.input,output:this.output,modes:[Rn,ir]},async(t)=>{let e=new dm((r)=>t.write(r),()=>t.cols),n=()=>{return this.list.maxItems=Math.max(NH,Math.min(this.most,t.rows-CH)),this.draw()};this.redraw=()=>e.draw(n()),t.onResize(()=>e.redraw(n())),this.redraw();try{let r=await t.loop((i)=>{return this.take(i),this.state==="submit"||this.state==="cancel"?this.state:void 0},()=>this.redraw());return this.redraw=()=>{},e.end(this.draw()),r}finally{this.hint.stop()}})}take(t){if(t.kind==="paste"){this.field.paste(t.text),this.list.setFilter(this.field.value);return}if(t.kind!=="key")return;let e=t.key;if(this.state==="error")this.state="active";let n=al(e,this.list.maxItems);if(e==="esc"||e==="ctrl-c")this.state="cancel";else if(e==="enter")if(this.required&&this.picked.size===0)this.error=`Pick at least one ${this.scope}`,this.state="error";else this.state="submit";else if(e==="up"||e==="down")this.list.move(e==="up"?-1:1);else if(e==="left"||e==="right")this.list.fold(e==="right");else if(n!==void 0)this.list.move(n);else if(e===" ")this.list.pick();else if(this.field.key(e))this.list.setFilter(this.field.value)}draw(){let t=(m)=>this.color?`${C}${m}${Lt}`:m,e=(m)=>this.color?`${pc}${m}${Lt}`:m,n=this.scope==="series"?"Series":"Catalog";if(this.state==="submit")return[`${t("◇")} ${n} ${t(`· ${this.list.pickedCount()} picked`)}`];if(this.state==="cancel")return[`${t(`◇ ${n} · cancelled`)}`];let r=this.field.value,i=`${e("◆")} ${n} ${t(`(${this.list.matched()}/${this.list.total()} · ${this.list.pickedCount()} picked)`)}`,o=this.hint.text(),s=`${e("│")} ${r?`${r}_`:t(`Search…${o?` e.g. ${o}`:""}`)}`,{lines:a,below:c}=this.list.window(),u=a.length>0?a.map((m)=>`${e("│")} ${m}`):[`${e("│")} ${t(`No ${this.scope==="series"?"series":"palettes"} match '${r}'`)}`];while(u.length<this.list.maxItems)u.push(e("│"));let l=c>0?`${e("│")} ${t(`↓ ${c} more`)}`:e("│"),d=this.scope==="series"?"":" · ←→ fold",f=this.scope==="series"?"continue":"install",h=this.state==="error"?`${e("└")} ${this.color?`${ne}${this.error}${Lt}`:this.error}`:`${e("└")} ${t(`↑↓ move${d} · space pick · type to filter · enter ${f} · esc cancel`)}`;return[i,s,...u,l,h]}}var hs=[{tab:"catalog",title:"Catalog",heading:"Discover palettes"},{tab:"installed",title:"Installed",heading:"Installed palettes"},{tab:"markets",title:"Markets",heading:"Manage markets"},{tab:"errors",title:"Errors",heading:"Problems"}],Gm=34,LH=72,FH=94,jH=22,W1=40,K1=10,z1=3,_H=600,BH=500,GH=300,D1=12,UH="\x1B[7;1m",Um={title:"",lines:[],brief:""};function Ha(t){let e=t.trim();if(e!==q&&!e.includes("/")&&!e.startsWith("~"))return;try{return Ar(e)}catch{return}}function WH(t){return t.charAt(0).toUpperCase()+t.slice(1)}class Wm{picked;tab="catalog";fields={catalog:new Vr,installed:new Vr,markets:new Vr,errors:new Vr};cursor={markets:0,errors:0};top={markets:0,errors:0};adds=new Map;removes=new Set;want=new Map;scope={catalog:void 0,installed:void 0};busy=new Map;failed=new Map;peeked=new Map;peekFailed=new Map;staging=new Set;timers=new Map;refreshed=[];inflight=new Set;markets;problems;kept;installed;startup;io;order;color;hub;owns;input;output;maxItems=12;paint;catalog;mine;hint;screen;state="active";phase="browse";offset=0;started=!1;log=[];working="";stopped;beat=0;asking;leaving;goto;repos;searching=!1;searchError;searched;asked=0;help=!1;worn;live;constructor(t){this.markets=t.markets,this.problems=t.problems,this.kept=t.kept,this.installed=new Set(t.installed),this.startup=t.startup,this.io=t.io,this.order=t.order??((n)=>n),this.color=t.color??!0,this.hub=t.hub,this.owns=t.owns??!1,this.input=t.input,this.output=t.output,this.live=t.lookups??!0,this.paint=t.onFocus,this.picked=new Set(t.installed);let e=this.entries();this.catalog=new Ta({entries:e,picked:this.picked,color:this.color,maxItems:this.maxItems,onFocus:(n)=>this.focus("catalog",n)}),this.mine=new Ta({entries:this.mineOf(e),picked:this.picked,color:this.color,maxItems:this.maxItems,onFocus:(n)=>this.focus("installed",n)}),this.hint=new ul(t.fx??"typewriter",()=>_m(this.tab==="installed"?this.mine:this.catalog),()=>this.redraw());for(let n of t.due)this.update(n)}run(){let t=[...this.owns?[ol,Rn,Zr]:[],ir,...Qr()],e=this.owns?[]:[Rn,Zr];return Xr({input:this.input,output:this.output,modes:t,assume:e},async(n)=>{let r=new Bi({write:(i)=>n.write(i),view:()=>this.state==="active"?{lines:this.view(),ticking:this.phase==="applying"}:void 0,beat:()=>{this.beat+=1}});this.screen=r,n.onResize(()=>{r.reset(),r.request()}),r.now();try{return await n.loop((i)=>{if(i.kind==="key")this.key(i.key);else if(i.kind==="paste")this.pasted(i.text);else if(i.kind==="mouse")this.mouse(i,r);return this.state==="active"?void 0:this.state},()=>r.soon())}finally{r.stop(),this.screen=void 0,this.hint.stop();for(let i of this.timers.values())clearTimeout(i);this.timers.clear()}})}applied(){return this.started}lines(){return this.log}failure(){return this.stopped}next(){return this.goto}async idle(){await Promise.allSettled([...this.inflight])}result(){let t=new Set(this.entries().map((e)=>e.name));return{picked:new Set([...this.picked].filter((e)=>t.has(e))),adds:[...this.adds.values()],removes:[...this.removes],auto:Object.fromEntries(this.want),refreshed:this.refreshed}}key(t){if(t==="ctrl-c"){this.state="cancel";return}if(this.help){if(t==="?"||t==="esc")this.help=!1;return}if(this.leaving!==void 0){if(t==="esc")this.leaving=void 0;else if(/^[yn]$/i.test(t)){if(t.toLowerCase()==="y")this.begin();else this.goto=this.leaving,this.state="cancel";this.leaving=void 0}return}if(this.asking){if(t==="esc")this.asking=void 0;else if(/^[yn]$/i.test(t))this.answer(t.toLowerCase()==="y");return}if(this.phase!=="browse"){this.steer(t);return}let e=al(t,this.maxItems),n=this.list();if(t==="enter")if(n?.foldable())n.flip();else if(this.dirty())this.phase="review",this.offset=0;else this.state="submit";else if((t==="esc"||t==="ctrl-u")&&this.fields[this.tab].value)this.clear();else if(t==="esc")this.state="cancel";else if(t==="?")this.help=!0;else if(e!==void 0)this.move(e);else if(t==="up"||t==="down")this.move(t==="up"?-1:1);else if(t==="left"||t==="right")this.side(t==="right");else if(t==="tab"||t==="shift-tab"){if(this.hub)this.leave(I$(this.hub,t==="tab"?1:-1))}else if(t==="shift-left"||t==="shift-right")this.switchTab(t==="shift-right"?1:-1);else if(t===" ")this.activate();else if(t==="ctrl-r"){let r=this.tab==="markets"?this.marketRow():void 0;if(r?.kind==="market"&&!this.adds.has(r.market.source))this.update(r.market.source);else if(r?.kind==="find")this.search()}else if(t==="ctrl-s")this.cycle();else if(this.fields[this.tab].key(t))this.typed()}pasted(t){if(this.phase==="browse"&&!this.help&&!this.asking&&this.leaving===void 0)this.fields[this.tab].paste(t),this.typed()}mouse(t,e){if(this.help){if(t.action==="release")this.help=!1;return}let n=e.point(t),r=n?.target,i=this.phase==="browse"&&this.leaving===void 0&&!this.asking;if(t.action==="wheel"){if(!t.sideways&&(i||this.phase!=="browse"))this.wheel(t.wheel);return}if(!r)return;if(t.action==="press"&&t.button==="left"){if(!i)return;if(r.kind==="tab")this.show(r.tab);else if(r.kind==="chip")this.scopeTo(r.source);else if(r.kind==="row")this.pointRow(r.at)}else if(t.action==="release"&&n?.inside){if(r.kind==="key")this.key(r.key);else if(r.kind==="page"){if(this.phase!=="browse")this.scroll(r.step*this.span());else if(i)this.move(r.step*this.maxItems)}else if(r.kind==="hub"){if(i&&this.hub&&r.tab!==this.hub)this.leave(R$(r.tab))}else if(r.kind==="row"&&i)this.openRow(r,t.count)}}wheel(t){if(this.phase!=="browse"){this.scroll(t);return}let e=this.list();if(e)e.move(t,!1);else this.move(t,!1)}pointRow(t){let e=this.list();if(e){e.point(t);return}this.cursor[this.tab==="markets"?"markets":"errors"]=t,this.watch()}openRow(t,e){let n=this.list();if(n){if(t.part==="box")n.pick();else if(t.part==="fold")n.flip();else if(e===2)n.open()}else if(t.part==="box"||e===2)this.activate()}typed(){let t=this.fields[this.tab].value;if(this.list()?.setFilter(t),this.tab==="markets")this.later("search",_H,()=>this.lookup()),this.watch()}clear(){this.fields[this.tab].value="";let t=this.list();if(t)t.clear();else this.typed()}redraw(){if(this.state==="active")this.screen?.request()}focus(t,e){if(this.tab===t&&this.state!=="submit"&&this.state!=="cancel")this.worn=e,this.paint?.(e)}track(t){this.inflight.add(t);let e=()=>this.inflight.delete(t);return t.then(e,e),t}list(){return this.tab==="catalog"?this.catalog:this.tab==="installed"?this.mine:void 0}active(){return[...this.markets.filter((t)=>!this.removes.has(t.source)),...this.adds.values()]}entries(){let t=this.active().flatMap((i)=>i.entries),e=new Set(t.map((i)=>i.name)),n=new Map,r=this.markets.filter((i)=>this.removes.has(i.source)).flatMap((i)=>i.entries);for(let i of[...this.kept,...r])if(this.installed.has(i.name)&&!e.has(i.name))n.set(i.name,i);return this.order([...t,...n.values()])}mineOf(t){return t.filter((e)=>this.installed.has(e.name))}scoped(t,e){let n=this.scope[e],r=n===void 0?void 0:this.active().find((o)=>o.source===n);if(!r)return this.scope[e]=void 0,t;let i=new Set(r.entries.map((o)=>o.name));return t.filter((o)=>i.has(o.name))}reload(){let t=this.entries();this.catalog.setEntries(this.scoped(t,"catalog")),this.mine.setEntries(this.scoped(this.mineOf(t),"installed"))}chips(t){let e=t==="catalog"?this.entries():this.mineOf(this.entries()),n=this.active().map((r)=>({source:r.source,label:r.id,count:r.entries.filter((i)=>!i.default&&(t==="catalog"||this.installed.has(i.name))).length})).filter((r)=>t==="catalog"||r.count>0||r.source===this.scope[t]);return[{source:void 0,label:"All",count:e.filter((r)=>!r.default).length},...n]}cycle(){let t=this.tab;if(t!=="catalog"&&t!=="installed"||this.active().length<2)return;let e=this.chips(t),n=Math.max(0,e.findIndex((r)=>r.source===this.scope[t]));this.scopeTo(e[(n+1)%e.length]?.source)}scopeTo(t){let e=this.tab;if(e!=="catalog"&&e!=="installed")return;this.scope[e]=t,this.reload(),this.list()?.refocus()}switchTab(t){let e=hs.findIndex((n)=>n.tab===this.tab);this.show(hs[(e+t+hs.length)%hs.length]?.tab??"catalog")}show(t){if(this.tab=t,this.list()?.refocus(),t==="markets")this.lookup(),this.watch()}move(t,e=!0){let n=this.list();if(n){n.move(t,e);return}let r=this.tab==="markets"?"markets":"errors",i=r==="markets"?this.marketRows().map((o)=>o.kind==="rule"):this.problemRows().map(()=>!1);this.cursor[r]=jm(this.cursor[r],t,i.length,(o)=>i[o]===!0,e),this.watch()}side(t){let e=this.list();if(e){e.fold(t);return}let n=this.tab==="markets"?this.marketRow():void 0;if(n?.kind==="market"&&!ut(n.market.source))if(t===n.market.auto)this.want.delete(n.market.source);else this.want.set(n.market.source,t)}activate(){let t=this.list();if(t){t.pick();return}let e=this.tab==="markets"?this.marketRow():void 0;if(e?.kind==="market")this.toggleMarket(e.market);else if(e?.kind==="add")this.load(e.source,!0);else if(e?.kind==="repo"){let n=this.known(e.source),r=this.marketRows().findIndex((i)=>i.kind==="market"&&i.market===n);if(n&&r>=0)this.cursor.markets=r;else if(!n)this.load(e.source,!0)}else if(e?.kind==="find")this.search()}toggleMarket(t){if(this.adds.has(t.source))this.adds.delete(t.source),this.want.delete(t.source);else if(this.removes.has(t.source))this.removes.delete(t.source);else this.removes.add(t.source);this.reload()}known(t){return[...this.markets,...this.adds.values()].find((e)=>_o(e.source,t))}load(t,e){let n=this.peeked.get(t);if(n){if(e)this.arrive(t,n);return}if(e)this.staging.add(t);if(this.busy.has(t))return;this.failed.delete(t),this.peekFailed.delete(t),this.busy.set(t,"Fetching…"),this.track(this.io.fetch(t)).then((r)=>{if(this.busy.delete(t),this.peeked.set(t,r),this.staging.delete(t))this.arrive(t,r);this.redraw()},(r)=>{if(this.busy.delete(t),this.staging.delete(t))this.failed.set(t,r.message);else this.peekFailed.set(t,r.message);this.redraw()})}arrive(t,e){let n=this.active().find((r)=>r.id===e.id);if(n)this.failed.set(t,`${e.id} already names the market at ${n.shown}`);else if(ut(t)||t===q)this.stage(e,e.auto);else this.asking=e;this.redraw()}later(t,e,n){this.cancel(t),this.timers.set(t,setTimeout(()=>{if(this.timers.delete(t),this.state!=="submit"&&this.state!=="cancel")n()},e))}cancel(t){clearTimeout(this.timers.get(t)),this.timers.delete(t)}wants(t){return!this.known(t)&&!this.peeked.has(t)&&!this.busy.has(t)&&!this.peekFailed.has(t)}watch(){if(!this.live||this.tab!=="markets")return;let t=Ha(this.fields.markets.value);if(t&&this.wants(t))this.later("typed",BH,()=>this.load(t,!1));else this.cancel("typed");let e=this.marketRow();if(e?.kind==="repo"&&this.wants(e.source)){let n=e.source;this.later("focus",GH,()=>{let r=this.marketRow();if(this.tab==="markets"&&r?.kind==="repo"&&r.source===n)this.load(n,!1)})}else this.cancel("focus")}answer(t){let e=this.asking;if(this.asking=void 0,e)this.stage(e,t)}stage(t,e){if(this.adds.set(t.source,t),e===t.auto)this.want.delete(t.source);else this.want.set(t.source,e);this.reload(),this.cursor.markets=Math.max(0,this.marketRows().findIndex((n)=>n.kind==="market"&&n.market.source===t.source))}update(t){if(this.busy.has(t))return;this.failed.delete(t),this.busy.set(t,"Updating…"),this.track(this.io.refresh(t)).then(({market:e,refreshed:n})=>{this.busy.delete(t),this.markets=this.markets.map((r)=>r.source===t?e:r),this.problems=this.problems.filter((r)=>r.source!==t),this.refreshed.push(n),this.reload(),this.redraw()},(e)=>{this.busy.delete(t),this.failed.set(t,`Update failed: ${e.message}`),this.redraw()})}wanted(){let t=this.fields.markets.value.trim();return t&&!Ha(t)?t:""}lookup(){if(this.live&&this.searched!==this.wanted())this.search()}search(){let t=this.wanted(),e=++this.asked;this.searched=t,this.searching=!0,this.searchError=void 0,this.track(this.io.search(t||void 0)).then((n)=>{if(e===this.asked)this.searching=!1,this.repos=n,this.watch(),this.redraw()},(n)=>{if(e===this.asked)this.searching=!1,this.searchError=n.message,this.redraw()})}marketRows(){let t=(...o)=>Ei(o,this.fields.markets.value),e=[...this.markets,...this.adds.values()],n=e.filter((o)=>t(o.id,o.shown,o.source)).map((o)=>({kind:"market",market:o})),r=Ha(this.fields.markets.value);if(r&&!e.some((o)=>_o(o.source,r)))n.push({kind:"add",source:r});let i=(this.repos??[]).map((o)=>({repo:o,source:Am(o)})).filter(({repo:o,source:s})=>t(s,o.description??""));return n.push({kind:"rule"},...i.length>0?i.map(({repo:o,source:s})=>({kind:"repo",repo:o,source:s})):[{kind:"find"}]),n}marketRow(){let t=this.marketRows();return t[this.at(t,"markets",(e)=>e?.kind==="rule")]}problemList(){let t=new Map([...this.markets,...this.adds.values()].map((e)=>[e.source,e.id]));return[...this.problems.filter((e)=>!(e.update&&e.source&&this.failed.has(e.source))),...[...this.failed].map(([e,n])=>({where:t.get(e)??e,message:n,source:e}))]}problemRows(){return this.problemList().filter((t)=>Ei([`${t.where} ${t.message}`],this.fields.errors.value))}at(t,e,n=()=>!1){let r=Math.min(this.cursor[e],Math.max(0,t.length-1));if(!n(t[r]))return r;return r>0?r-1:r+1}windowOf(t,e,n,r=()=>!1){let i=this.at(t,e,r);this.cursor[e]=i;let o=(l)=>r(t[l])?1:2,s=(l,d)=>{let f=0;for(let h=l;h<=d;h++)f+=o(h);return f},a=Math.min(this.top[e],i);while(a<i&&s(a,i)>this.maxItems)a+=1;while(a>0&&s(a-1,t.length-1)<=this.maxItems)a-=1;this.top[e]=a;let c=[],u=0;for(let l=a;l<t.length&&u+o(l)<=this.maxItems;l++)c.push(l),u+=o(l);return{lines:c.flatMap((l)=>{let d=n(t[l],l===i,l);return r(t[l])?d:d.map((f)=>fs(l,"row",f))}),above:a,below:t.length-a-c.length}}dim(t){return this.color?`${C}${t}${$e}`:t}bold(t){return this.color?`${ct}${t}${$e}`:t}warn(t){return this.color?`${ne}${t}\x1B[39m`:t}lit(t,e,n){if(e&&this.color&&t)return`${qe(t.cursor)}▌\x1B[39m ${mc(t.selection,t.foreground)} ${n} ${Lt}`;return`${e?"▌ ":" "} ${n}`}status(t){return this.adds.has(t.source)?"Will add":this.removes.has(t.source)?"Will remove":this.busy.get(t.source)??(this.failed.has(t.source)||t.status.startsWith("update failed")?"Update failed":"")}note(t){return` ${this.dim(t)}`}peeking(t){let e=this.peeked.get(t);return e?Tt(e.entries.filter((n)=>!n.default).length):""}marketLine(t,e,n){let r=(o)=>fs(n,"box",`${o} `);if(t.kind==="rule")return[` ${this.dim(`── On GitHub${this.searching?" · searching…":""} ──────────`)}`];if(t.kind==="market"){let o=t.market,s=this.status(o),a=e?this.bold(o.id):o.id,c=o.entries.filter((l)=>!l.default),u=!ut(o.source)&&(this.want.get(o.source)??o.auto)?` ${this.dim("↻ auto-update")}`:"";return[this.lit(o.entries.find((l)=>!l.default),e,`${r(this.removes.has(o.source)?"○":"●")}${a}${u}${s?` ${this.dim(s)}`:""}`),this.note([o.source===q?"The ttheme catalog":ut(o.source)?o.shown:o.source,Tt(c.length),`${c.filter((l)=>this.installed.has(l.name)).length} installed`,o.status].join(" · "))]}if(t.kind==="add"){let o=this.busy.get(t.source),s=this.failed.get(t.source)??this.peekFailed.get(t.source),a=this.peeked.get(t.source);return[this.lit(void 0,e,`${r("+")}Add ${nt(t.source)}${o?` ${this.dim(o)}`:""}`),s?` ${this.warn(s)}`:this.note(a?`${a.id} · ${this.peeking(t.source)}`:this.live?"Fetching its palettes…":"space fetches its palettes")]}if(t.kind==="find"){let o=this.fields.markets.value.trim(),s=o&&!Ha(o),a=!this.searching&&!this.searchError&&this.repos===void 0,c=this.searching?"Searching GitHub…":this.searchError?"GitHub search failed":a?s?`Find "${o}" on GitHub`:"Find markets on GitHub":s?`No market on GitHub matches "${o}"`:"No market on GitHub yet";return[this.lit(void 0,e,`${r("⌕")}${c}`),this.note(this.searchError??(this.searching?"":a?"space searches GitHub":"space searches again"))]}let i=this.busy.get(t.source);return[this.lit(void 0,e,`${r(this.known(t.source)?"●":"○")}${t.source} ${this.dim(`★${t.repo.stargazers_count}`)}${i?` ${this.dim(i)}`:""}`),this.note([this.peeking(t.source),t.repo.description??""].filter(Boolean).join(" · "))]}problemLine(t,e){return[this.lit(void 0,e,`${this.warn("✗")} ${t.where}`),this.note(t.message)]}body(){let t=this.list();if(t){let n=this.fields[this.tab].value;return{...t.window(),empty:n?`No palettes match '${n}'`:this.tab==="installed"?"Nothing installed yet":"No palettes"}}if(this.tab==="markets")return{...this.windowOf(this.marketRows(),"markets",(n,r,i)=>this.marketLine(n,r,i),(n)=>n?.kind==="rule"),empty:""};let e=this.fields.errors.value;return{...this.windowOf(this.problemRows(),"errors",(n,r)=>this.problemLine(n,r)),empty:e?`No problems match '${e}'`:"No problems"}}changes(){return this.adds.size+this.removes.size+this.want.size}dirty(){let{picked:t}=this.result();return this.changes()>0||t.size!==this.installed.size||[...t].some((e)=>!this.installed.has(e))}leave(t){if(this.dirty()){this.leaving=t;return}this.goto=t,this.state="cancel"}steer(t){if(this.phase==="review"){if(t==="enter")this.begin();else if(t==="esc")this.phase="browse"}else if(this.phase==="done"&&(t==="enter"||t==="esc"))this.state="submit";let e=t==="up"?-1:t==="down"?1:al(t,this.span());if(e!==void 0)this.scroll(e)}scroll(t){this.offset=Number.isFinite(t)?Math.max(0,this.offset+t):t>0?Number.MAX_SAFE_INTEGER:0,this.redraw()}span(){return Math.max(z1,this.rows()-(this.hub?1:0)-4)}begin(){this.phase="applying",this.started=!0,this.offset=0,this.log=[],this.working="";let t={say:(e)=>{this.log.push(...e.split(`
657
+ `)),this.redraw()},status:(e)=>{this.working=e,this.redraw()}};this.track(this.io.apply(this.result(),t)).then(()=>this.ended(),(e)=>this.ended(e))}ended(t){this.working="",this.stopped=t,this.phase="done",this.offset=0,this.redraw()}pending(){let t=this.entries().filter((e)=>!e.default);return{names:t.filter((e)=>this.picked.has(e.name)&&!this.installed.has(e.name)),dropped:t.filter((e)=>this.installed.has(e.name)&&!this.picked.has(e.name))}}marketChanges(){let t=[];for(let e of this.adds.values()){let n=e.source!==q&&(this.want.get(e.source)??e.auto)?"updates on its own":"";t.push(`+ ${e.id} ${this.dim([e.source===q?"The ttheme catalog":e.shown,Tt(e.entries.filter((r)=>!r.default).length),n].filter(Boolean).join(" · "))}`)}for(let e of this.removes){let n=this.markets.find((i)=>i.source===e),r=(n?.entries??[]).filter((i)=>!i.default&&this.installed.has(i.name)&&this.picked.has(i.name));t.push(`- ${n?.id??e} ${this.dim([n?.shown??nt(e),r.length>0?`its ${Tt(r.length)} installed keep working`:""].filter(Boolean).join(" · "))}`)}for(let[e,n]of this.want){let r=this.markets.find((i)=>i.source===e);if(r&&!this.removes.has(e))t.push(`↻ ${r.id} ${this.dim(n?"updates on its own from now":"stops updating on its own")}`)}return t}reviewLines(){let t=this.marketChanges(),{names:e,dropped:n}=this.pending(),r=Math.max(0,...[...e,...n].map((s)=>s.name.length)),i=(s,a)=>` ${s} ${a.name.padEnd(r)} ${this.dim(lt(a.name)?a.catalog??"":a.group)}`,o=[e.length>0?`${e.length} to install`:"",n.length>0?`${n.length} to remove`:""].filter(Boolean);return[...t.length>0?[` ${this.bold("Markets")} ${this.dim(`(${t.length})`)}`,...t.map((s)=>` ${s}`),""]:[],...o.length>0?[` ${this.bold("Palettes")} ${this.dim(`(${o.join(" · ")})`)}`,...e.map((s)=>i("+",s)),...n.map((s)=>i("-",s))]:[]]}summary(){let{names:t,dropped:e}=this.pending(),n=this.adds.size;return[n>0?`${n} market${n===1?"":"s"} added`:"",this.removes.size>0?`${this.removes.size} removed`:"",t.length>0?`${t.length} installed`:"",e.length>0?`${e.length} removed`:""].filter(Boolean).join(" · ")}progressLines(){let t=this.log.map((e)=>` ${e}`);if(this.phase==="applying"){let e=jn[this.beat%jn.length];t.push(` ${this.dim(`${e} ${this.working||"Working…"}`)}`)}else if(this.stopped)t.push("",...bt(this.stopped.message,Math.max(20,this.columns()-6)).map((e,n)=>` ${n===0?this.warn("✗"):" "} ${e}`));return t}frame(t,e){let n=t-1,r=this.phase==="review",i=r?this.reviewLines():this.progressLines(),o=this.phase==="review"?`${this.bold("Review changes")}`:this.phase==="applying"?this.bold("Applying changes"):this.stopped?`${this.warn("✗")} ${this.bold("Stopped")}`:`${this.bold("✓ Applied")} ${this.dim(this.summary()?`(${this.summary()})`:"")}`,s=this.span(),a=Math.max(0,i.length-s),c=this.phase==="applying"?a:Math.min(this.offset,a);this.offset=c;let u=i.slice(c,c+s),l=i.length-c-u.length,d=[c>0?` ${this.more(-1,`↑ ${c} more`)}`:"",...u];while(d.length<s+1)d.push("");d.push(l>0?` ${this.more(1,`↓ ${l} more`)}`:"");let f=a>0?[["↑↓","scroll"]]:[],h=r?{badge:"BROWSE (APPLY)",keys:[...f,["enter","apply"]],right:["esc","back"]}:this.phase==="applying"?{badge:"BROWSE (APPLY)",note:"Keys wait until it ends",keys:[]}:{badge:"BROWSE (APPLY)",keys:f,right:["enter","close"]};return[...this.hub?[rt(Vf(this.hub,this.color),n,!1)]:[],rt(` ${o}`,n,!1),...d.map((m)=>rt(m,n,!1)),` ${this.keyBar(h,n-1)}`].slice(0,e).join(`
658
+ `)}keyBar(t,e){let n=this.color&&this.worn?qe(this.worn.cursor):"",r=this.color?`\x1B[7;1m${n} ${t.badge} ${Lt} `:`[${t.badge}] `,i=([c,u])=>Wt(c.split(" ")[0]??"",`${this.bold(c)} ${this.dim(u)}`),{note:o,keys:s,right:a}=t;for(;;){let c=`${r}${[t.lead??"",o?this.dim(o):"",...s.map(i)].filter(Boolean).join(" ")}`,u=a?i(a):"";if(_(c)+(a?3+_(u):0)<=e)return a?yt(c,u,e):rt(c,e,!1);if(o)o=void 0;else if(s.length>2||!a&&s.length>1){let l=s.length-2;s=s.filter((d,f)=>f!==l)}else if(a)a=void 0;else return rt(c,e,!1)}}more(t,e){return this.dim(Vt({kind:"page",step:t},e))}counts(){let t=[...this.busy.values()].includes("Updating…")?"Updating… · ":"",e=this.list();if(e)return`${t}${e.matched()}/${e.total()} · ${e.pickedCount()} picked`;if(this.tab==="markets"){let n=this.markets.length+this.adds.size,r=this.marketRows().filter((o)=>o.kind==="market").length,i=this.changes();return`${t}${r}/${n}${i>0?` · ${i} to apply`:""}`}return`${this.problemRows().length}/${this.problemList().length}`}searchText(){let t=this.fields[this.tab].value;if(t)return`${t}_`;if(this.tab==="markets")return this.dim("Search… or add one: owner/repo");let e=this.tab==="errors"?"":this.hint.text();return this.dim(`Search…${e?` e.g. ${e}`:""}`)}tabBar(){return hs.map(({tab:t,title:e})=>{let n=t==="errors"?this.problemList().length:0,r=n>0?`${e} ${n}`:e,i={kind:"tab",tab:t};if(!this.color)return Vt(i,t===this.tab?`[${r}]`:` ${r} `);return`${t===this.tab?UH:C}${Vt(i,` ${r} `)}${Lt}`}).join(" ")}heading(){let t=hs.find((e)=>e.tab===this.tab)?.heading??"";return`${this.bold(t)} ${this.dim(`(${this.counts()})`)}`}searchBox(t){let e=(r,i)=>this.dim(`${r}${"─".repeat(t-2)}${i}`),n=this.dim("│");return[e("╭","╮"),`${n} ${rt(`${this.dim("⌕")} ${this.searchText()}`,t-4)} ${n}`,e("╰","╯")]}strip(t){let e=this.tab;if(e!=="catalog"&&e!=="installed"||this.active().length<2)return;let n=this.chips(e),r=Math.max(0,n.findIndex((b)=>b.source===this.scope[e])),i=n.map((b,w)=>w===r&&!this.color?`[${b.label} ${b.count}]`:`${b.label} ${b.count}`),o=" · ",s=(b)=>b>0?`${o}+${b} more`.length:0,a=(b)=>{let w=b>0?2:0,k=0;for(let v=b;v<i.length;v++){let S=w+(k>0?o.length:0)+i[v].length;if(S+s(i.length-v-1)>t)break;w=S,k+=1}return k},c=0;while(c<r&&c+a(c)<=r)c+=1;let u=Math.max(1,a(c)),l=i.slice(c,c+u),d=i.length-c-u,f=l.map((b,w)=>{let k=Vt({kind:"chip",source:n[c+w]?.source},b);if(c+w===r)return this.color?`${ct}${pc}${k}${Lt}`:k;return this.dim(k)}),h=`${c>0?`${this.dim(Wt("ctrl+s","…"))} `:""}${f.join(this.dim(o))}${d>0?this.dim(`${o}${Wt("ctrl+s",`+${d} more`)}`):""}`,m=(c>0?2:0)+l.join(o).length+s(d),g="ctrl+s market";return m+2+g.length<=t?`${h} ${this.dim(Wt("ctrl+s",g))}`:h}sourceOf(t){let e=this.active().find((n)=>n.entries.some((r)=>r.name===t.name));if(!e)return"In no market you added";return e.source===q?"The ttheme catalog":e.shown}paletteState(t){let e=this.picked.has(t.name),n=this.installed.has(t.name),r=e&&n?"Installed":e?"Will install":n?"Will remove":"Not installed";return this.startup===t.name?`${r} · Default`:r}paletteDetail(t,e){if(!t||t.kind==="rule")return Um;if(t.kind==="all")return{title:this.bold("Select all"),lines:["space picks every palette shown"],brief:""};if(t.kind==="group"){let u=this.entries().filter((f)=>f.group===t.name&&!f.default),l=this.sourceOf(t.lead),d=`${Tt(u.length)} · ${u.filter((f)=>this.installed.has(f.name)).length} installed`;return{title:this.bold(t.name),lines:[...t.native?bt(t.native,e).map((f)=>this.dim(f)):[],...bt(l,e),d],brief:`${l} · ${d}`}}if(t.kind==="catalog"){let u=this.entries().filter((f)=>f.group===t.group&&f.catalog===t.name),l=this.sourceOf(t.lead),d=`${Tt(u.length)} · ${u.filter((f)=>this.installed.has(f.name)).length} installed`;return{title:this.bold(t.name),lines:[t.group,...bt(l,e),d],brief:`${t.group} · ${d}`}}let n=t.entry,r=this.sourceOf(n),i=ia(n),o=`Gate ${ve.length-i.length}/${ve.length}`,s=n.pictures?.length??0,a=[...s>0?[`${s} picture${s===1?"":"s"}`]:[],...n.base?[`Base ${n.base}`]:[]].join(" · "),c=lt(n.name)?n.catalog?[n.catalog]:[]:[n.group,...n.native?[this.dim(n.native)]:[]];return{title:this.color?`${ct}${qe(n.cursor)}${n.name}${$e}\x1B[39m`:n.name,lines:[...bt(r,e),...c,this.paletteState(n),"",i.length===0?`${o} · passes`:o,...i.flatMap((u)=>bt(u,e-2).map((l,d)=>`${d===0?this.warn("✗"):" "} ${l}`)),...a?["",a]:[]],brief:[r,o,...a?[a]:[],this.paletteState(n)].join(" · ")}}marketDetail(t,e){if(!t||t.kind==="rule")return Um;if(t.kind==="market"){let i=t.market,o=i.source===q?"The ttheme catalog":i.shown,s=i.entries.filter((h)=>!h.default),a=s.filter((h)=>this.installed.has(h.name)).map((h)=>h.name),c=`${Tt(s.length)} · ${a.length} installed`,u=ut(i.source)?"Read in place":`Auto-update ${this.want.get(i.source)??i.auto?"on":"off"}`,l=this.busy.get(i.source)??WH(i.status),d=this.failed.get(i.source),f=this.adds.has(i.source)?["Will add"]:this.removes.has(i.source)?[a.length>0?`Will remove — ${a.join(", ")} stay${a.length===1?"s":""} installed`:"Will remove"]:this.want.has(i.source)?[`Auto-update turns ${this.want.get(i.source)?"on":"off"}`]:[];return{title:this.bold(i.id),lines:[...bt(o,e),...i.description?bt(i.description,e).map((h)=>this.dim(h)):[],c,"",ut(i.source)?u:`${u} ${this.dim("←→")}`,...ut(i.source)?[]:[l],...d?bt(d,e).map((h)=>this.warn(h)):[],...f.length>0?["",...f.flatMap((h)=>bt(h,e))]:[]],brief:[o,u,...f,...ut(i.source)?[]:[l]].join(" · ")}}if(t.kind==="add"){let i=this.busy.get(t.source)??this.failed.get(t.source)??this.peekFailed.get(t.source)??(this.peeked.has(t.source)?"space adds it":this.live?"Fetching its palettes…":"space fetches its palettes");return{title:this.bold(nt(t.source)),lines:["Not added",...this.peekLines(t.source,e),"",...bt(i,e)],brief:[this.peeking(t.source),i].filter(Boolean).join(" · ")}}if(t.kind==="find"){let i=this.fields.markets.value.trim(),o=this.searchError??(this.searching?"Searching…":this.repos?`${this.repos.length} found · space searches again`:"space searches GitHub");return{title:this.bold("GitHub"),lines:[...bt(`Repositories with the ${Fo} topic`,e),...i&&!Ha(i)?[`Matching "${i}"`]:[],"",...bt(o,e)],brief:o}}let r=this.known(t.source)?"Added":this.busy.get(t.source)??this.failed.get(t.source)??this.peekFailed.get(t.source)??"space adds it";return{title:this.bold(t.source),lines:[`★ ${t.repo.stargazers_count}`,...bt(t.repo.description??"",e),...this.peekLines(t.source,e),"",...bt(r,e)],brief:[this.peeking(t.source),r].filter(Boolean).join(" · ")}}peekLines(t,e){let n=this.peeked.get(t);if(!n)return[];let r=n.entries.filter((o)=>!o.default),i=`${r.slice(0,D1).map((o)=>de(o.name)).join(", ")}${r.length>D1?", …":""}`;return["",n.id,...n.description?bt(n.description,e):[],Tt(r.length),...bt(i,e).map((o)=>this.dim(o))]}detail(t){let e=this.list();if(e)return this.paletteDetail(e.focusedRow(),t);if(this.tab==="markets")return this.marketDetail(this.marketRow(),t);let n=this.problemRows(),r=n[Math.min(this.cursor.errors,n.length-1)];return r?{title:this.bold(r.where),lines:bt(r.message,t),brief:r.message}:Um}footer(){if(this.help)return{badge:"HELP",keys:[],right:["? esc","close"]};if(this.leaving!==void 0)return{badge:"BROWSE",lead:"Apply your changes before you leave?",keys:[["y","apply"],["n","discard"]],right:["esc","stay"]};if(this.asking)return{badge:"BROWSE",lead:`Update ${this.asking.id} on its own when its author changes it?`,keys:[["y","yes"],["n","no"]],right:["esc","back"]};let t=this.fields[this.tab].value,e=["enter",this.dirty()?"apply":"close"],n=[["⇧←→","tabs"],...t?[["bksp","edit"]]:[],["?","keys"]];return{badge:t?"BROWSE (FILTER)":"BROWSE",keys:[...this.rowKeys(e),...n],right:t?["esc","clear filter"]:["esc","cancel"]}}rowKeys(t){let e=this.list();if(e){let r=e.focusedRow();if(!r)return[t];if(e.foldable())return[(r.kind==="group"||r.kind==="catalog")&&r.expanded?["←","close"]:["→","open"],["space","pick"]];return[["space","pick"],t]}if(this.tab==="errors")return[t];let n=this.marketRow();if(n?.kind==="market"){let r=n.market;return[["space",this.adds.has(r.source)||this.removes.has(r.source)?"undo":"remove"],...ut(r.source)?[]:[["←→","auto-update"]],...this.adds.has(r.source)?[]:[["ctrl+r","update"]],t]}if(n?.kind==="find")return[["space","search"],t];if(n?.kind==="add"||n?.kind==="repo"&&!this.known(n.source))return[["space","add"],t];return[t]}columns(){return(this.output??process.stdout).columns??100}rows(){return(this.output??process.stdout).rows??24}fitItems(t){let e=Math.max(z1,this.rows()-t);this.maxItems=e,this.catalog.maxItems=e,this.mine.maxItems=e}view(){let t=this.draw().split(`
659
+ `);return Array.from({length:this.rows()},(e,n)=>t[n]??"")}draw(){let t=this.columns(),e=this.rows();if(t<W1||e<K1)return`Needs ${W1}×${K1} — now ${t}×${e}
660
+ ${this.dim("esc cancels")}`;if(this.phase!=="browse")return this.frame(t,e);let n=t>=FH,r=t-1,i=n?Math.min(t-Gm-4,LH):r,o=this.strip(r-1),s=[` ${this.tabBar()}`,...e>=jH?[` ${this.heading()}`,...this.searchBox(t-3).map((b)=>` ${b}`)]:[yt(` ${this.dim("⌕")} ${this.searchText()}`,this.dim(this.counts()),r)],...o?[` ${o}`]:[]];this.fitItems(s.length+3+(n?0:1)+(this.hub?1:0));let{lines:a,above:c,below:u,empty:l}=this.body(),d=a.length>0?a.map((b)=>` ${b}`):[` ${this.dim(l)}`];while(d.length<this.maxItems)d.push("");let f=[c>0?` ${this.more(-1,`↑ ${c} more`)}`:"",...d,u>0?` ${this.more(1,`↓ ${u} more`)}`:""],h=this.detail(n?Gm:i-2),m=n?f.map((b,w)=>`${rt(b,i)} ${this.dim("│")} ${rt(w===0?h.title:h.lines[w-1]??"",Gm,!1)}`):[...f.map((b)=>rt(b,i,!1)),rt(` ${this.dim(h.brief)}`,i,!1)],g=[...this.hub?[rt(Vf(this.hub,this.color),r,!1)]:[],...s.map((b)=>rt(b,r,!1)),...m,` ${this.keyBar(this.footer(),r-1)}`];return(this.help?this.helpBox(g,t,e,g.length-m.length-1):g).join(`
661
+ `)}helpRows(){return[["Move","↑↓ home end pgup pgdn"],["Series","←→ · enter on a series"],["Pick","space · a palette, a series, all"],["Filter","Any text · bksp · ctrl-u clears"],["","Each tab keeps its own"],["Tabs","⇧←→ Catalog, Installed, Markets, Errors"],...this.active().length>=2?[["Market","ctrl+s · one market, then all"]]:[],["Markets","space adds or removes · ←→ auto-update"],["","ctrl+r updates it, or searches again"],["Apply","enter reviews and applies · esc cancels"],...this.hub?[["Screens","tab · shift+tab"]]:[],["Close","? esc"]]}helpBox(t,e,n,r){let i=this.helpRows(),o=Math.min(e-2,58),s=Math.floor((e-o)/2),a=`│${" ".repeat(o-2)}│`,c=[`╭─ Help ${"─".repeat(o-9)}╮`,a,...i.map(([l,d])=>`│${rt(` ${this.bold(l.padEnd(10))}${d}`,o-4)} │`),a,`╰${"─".repeat(o-2)}╯`],u=Math.max(0,Math.min(Math.max(r,Math.floor((n-c.length)/2)),n-1-c.length));return t.map((l,d)=>{let f=c[d-u];return f===void 0?l:`${jg(l,s)}${f}`})}}import{existsSync as I8}from"node:fs";import{existsSync as oc,mkdirSync as d8,readFileSync as zp}from"node:fs";import{dirname as f8}from"node:path";class He extends Error{}import{closeSync as QL,mkdtempSync as XL,openSync as tF,readSync as eF,rmSync as iS}from"node:fs";import{homedir as nF,tmpdir as rF}from"node:os";import{join as oS}from"node:path";import{readFileSync as KH}from"node:fs";var kt={pitch:25,cols:22,rows:9,height:13},qi={cols:25,rows:21},be={cols:10,rows:3,pitch:12,top:4},ge=be.top+be.rows+1,zH=1073741824,Vm=2147483648,DH=-1073741826,qH=1600,YH=56,JH=4,q1=20,VH=50,Y1=[["space","unfolds a set of ×N"],["o","opens the post page in a browser"],["c","switches between cutouts and every post"],["a","opens the advanced filters"],["1-9","turn a tag of the tags row on or off"],["ctrl+v","tries on a picture from the clipboard — or drop one on the window"]];function Zm(t){return Math.max(0,Math.floor((t-1)/be.pitch))}function or(t,e){let n=e-ge-2;return{perRow:Math.max(1,Math.floor((t-1)/kt.pitch)),rowsVis:Math.max(1,Math.floor(n/kt.height)),height:n}}function hl(t,e=!0){if(e)return`\x1B_Ga=t,t=f,f=100,i=${t.id},q=2;${Buffer.from(t.path).toString("base64")}\x1B\\`;let n;try{n=KH(t.path).toString("base64")}catch{return}let r=n.match(/.{1,4096}/g)??[""];return r.map((i,o)=>{let s=o<r.length-1?1:0;return o===0?`\x1B_Ga=t,f=100,i=${t.id},m=${s},q=2;${i}\x1B\\`:`\x1B_Gm=${s},q=2;${i}\x1B\\`}).join("")}function nv(t,e){let n=t.crop===void 0?"":`,x=0,y=${t.crop*e.h},w=${t.cols*e.w},h=${t.rows*e.h}`;return`\x1B[${t.row+1};${t.col+1}H\x1B_Ga=p,i=${t.id},p=${t.id}${n},c=${t.cols},r=${t.rows},C=1,z=${t.z},q=2\x1B\\`}function Qm(t){return`\x1B_Ga=d,d=i,i=${t},p=${t},q=2\x1B\\`}function _a(t){return`\x1B_Ga=d,d=I,i=${t},q=2\x1B\\`}function ms(t){return`\x1B[38;2;${et(t).join(";")}m`}function fl(t){return`\x1B[48;2;${et(t).join(";")}m`}var zm=!1;function ml(t){return zm=!0,t.beat}function ps(t){return jn[ml(t)%jn.length]}function ft(t){return _(t)}function Dm(t,e){if(_(t)<=e)return t;let n="";for(let r of t){if(_(n+r)>e)break;n+=r}return n}function ti(t){return`\x1B[${30+t}m`}function Yi(t,e,n,r){return n?[[`${Is} `,r,void 0,{kind:"link",url:n}],[t,e,n]]:[[t,e]]}function Km(t){let e=Yf(t);return e?{kind:"key",key:e}:void 0}function qm(t){return t.reduce((e,[n])=>e+ft(n),0)}function ZH(t,e){let n=[],r=e;for(let[i,o,s,a]of t){let c=ft(i);if(c<=r){n.push([i,o,s,a]),r-=c;continue}n.push([`${Dm(i,r)}…`,o,s,a]);break}return n}class dl{parts=[];cols;constructor(t){this.cols=t}put(t,e,n="",r,i){return this.parts.push({col:t,text:e,sgr:n,...r?{link:r}:{},...i?{spot:i}:{}}),t+ft(e)}run(t,e){let n=t;for(let[r,i,o,s]of e)n=this.put(n,r,i,o,s);return n}mark(t,e,n){this.parts.push({col:t,text:" ".repeat(Math.max(0,e)),sgr:"",spot:n,hidden:!0})}zones(t){return this.parts.flatMap(({col:e,text:n,link:r,spot:i})=>{let o=i??(r?{kind:"link",url:r}:void 0),s=e>=0&&e<this.cols?ft(Dm(n,this.cols-e)):0;return o&&s>0?[{row:t,col:e,width:s,height:1,target:o}]:[]})}right(t,e){this.run(t-e.reduce((n,[r])=>n+ft(r),0),e)}center(t,e){this.run(Math.floor((t-e.reduce((n,[r])=>n+ft(r),0))/2),e)}render(){let t="";for(let{col:e,text:n,sgr:r,link:i,hidden:o}of this.parts){if(o||e>=this.cols||e<0)continue;let s=Dm(n,this.cols-e);t+=`\x1B[${e+1}G${r}${gc(s,i)}${r?Lt:""}`}return t}}function QH(t){return t.replace(/_\([^)]*\)?$/,"")}function rv(t){return[`${t.reduced?"↓":""}${t.width}×${t.height}`,Math.max(t.width,t.height)<qH?ne:C]}function Fa(t,e,n,r){let i=[...r.keys??[]],o=r.lead,s=r.right,a=()=>{let l=[...o?[qm(o)]:[],...i.map(([f,h])=>ft(f)+1+ft(h))];return(r.badge?ft(r.badge)+4:0)+l.reduce((f,h)=>f+h,0)+3*Math.max(0,l.length-1)+(s?3+ft(s[0])+1+ft(s[1]):0)};while(a()>e)if(i.length>2)i.splice(-2,1);else if(s)s=void 0;else if(i.length>1)i.splice(-2,1);else break;if(o&&a()>e)o=ZH(o,Math.max(0,qm(o)-(a()-e)-1));let c=0;if(r.badge)c=t.put(0,` ${r.badge} `,`\x1B[7;1m${n}`)+2;if([...o?[o]:[],...i.map(([l,d])=>[[l,ct,void 0,Km(l)],[` ${d}`,C,void 0,Km(l)]])].forEach((l,d)=>{c=t.run(c+(d?3:0),l)}),s){let l=Km(s[0].split(" ")[0]??"");t.right(e,[[s[0],ct,void 0,l],[` ${s[1]}`,C,void 0,l]])}}function XH(t,e){if(t==="d")return C;if(t==="b")return ct;if(t==="s")return fl(e.colors.selection);if(t==="c")return fl(e.colors.cursor);let n=/^([BK]?)(\d+)$/.exec(t);if(!n)return"";let r=Number(n[2]),i=(o)=>r<8?o+r:o+52+r;if(n[1]==="K")return`\x1B[30;${i(40)}m`;return`\x1B[${n[1]==="B"?"1;":""}${i(30)}m`}function tC(t,e,n,r,i){let o=zt.indexOf(Ii(r.scene)),s=zt.flatMap((c,u)=>[...u?[[" ",""]]:[],[c.name,u===o?ct+i:C,void 0,{kind:"scene",scene:u}]]),a=s.reduce((c,[u])=>c+ft(u),0)<=n;t?.run(e,a?s:[[Ii(r.scene).name,ct+i],[` ${o+1}/${zt.length}`,C]])}function eC(t,e,n,r,i,o,s){let{ansi:a,cursor:c}=o.colors;tC(t[e-2],n,r,o,s);let u=r<nk?3:4;if(r>=56)u=Math.min(7,Math.floor((r+1)/8)-1);let l=n;for(let f=0;f<8;f++)l=(t[e]?.put(l,"▀".repeat(u),ms(a[f]??c)+fl(a[f+8]??c))??l)+1;let d=e+2;for(let f of Ii(o.scene).lines){let h=Wo(f,r);if(!h)continue;if(d>i)return;t[d]?.run(n,h.map(([m,g])=>[m,XH(g,o)])),d++}}function nC(t,e,n){let r=[[]];for(let s of t){let a=r[r.length-1];if(a.length===0||ft([...a,s].join(" "))<=e)a.push(s);else if(r.length<n)r.push([s]);else break}let i=r.reduce((s,a)=>s+a.length,0),o=r[r.length-1];while(i<t.length&&o.length>0&&ft([...o,`+${t.length-i}`].join(" "))>e)o.pop(),i--;if(i<t.length)o.push(`+${t.length-i}`);return r.filter((s)=>s.length>0).map((s)=>s.join(" "))}function J1(t){return t.replace(/^https?:\/\/(?:www\.)?/,"")}function rC(t,e,n,r,i){let o=r.info,s=o?.artists??[],a=ti(r.tiles[r.focus]?.siteAnsi??r.siteAnsi);[["Post",o?.page?Yi(J1(o.page),"",o.page,a):[["—",C]]],["Source",o?.source?Yi(J1(o.source),"",o.link,i):[["—",C]]],["Artist",[s.length>0?[s.join(" "),""]:["—",C]]]].forEach(([u,l],d)=>{t[e+d]?.put(n,u,C),t[e+d]?.run(n+12,l)})}function iC(t,e,n,r,i,o){let s=o.info,a=o.tiles[o.focus];if(!s||!a)return;let c=o.shown?.id===a.key?o.shown:void 0,u=n+12,l=Math.max(12,r-12),d=[`${a.width}×${a.height}${s.ext?` ${s.ext.toUpperCase()}`:""}`,...c?[qu(c.bytes)]:[]].join(" · "),f=[s.rating??"—",a.score>0?`★${a.score}`:"",s.posted??""].filter(Boolean).join(" · "),h=(b,w)=>b.length>0?nC(b,l,w).map((k)=>[[k,""]]):[[["—",C]]],m=[["Characters",h(s.characters,2)],["Series",h(s.series,1)],["Tags",h(s.tags,3)],["Rating",[[[f,f==="—"?C:""]]]],["File",[[[d,""],...c?[[" ",""]]:[],...c?iv(c):[]]]],["Uploader",[[s.uploader?[s.uploader,""]:["—",C]]]]],g=e;for(let[b,w]of m){if(g+w.length-1>i)return;t[g]?.put(n,b,C);for(let k of w)t[g]?.run(u,k),g++}}var oC=["Size","Position","Opacity"],sC=[0,3,6];function aC(t,e){let{tune:n,untuned:r}=t;return e===0?n.size!==r.size:e===1?n.at!==r.at:n.opacity!==r.opacity}function cC(t){return t.toFixed(2)}function uC(t,e,n,r,i,o){let s=i.tuning;if(!s)return;let a=i.tiles[i.focus];t[e-3]?.run(n,[[i.palette,ct+o],[" Background",C],...a?[[" · ",C],...Yi(`${a.site} ${a.id}`,C,a.page||void 0,ti(a.siteAnsi))]:[]]);let c=Math.max(8,r-n-21),u=20,l=Math.max(100,s.fill);for(let[d,f]of oC.entries()){let h=e+sC[d],m=s.field===d,g=m?ct:C;if(m)t[h]?.put(n,"▶",o,void 0,{kind:"field",field:d});t[h]?.put(n+2,f,g,void 0,{kind:"field",field:d});let b;if(d===1){for(let w=1;w<=9;w++){let k=w===i.tune.at,v=t[e+2+Math.floor((w-1)/3)],S=n+12+(w-1)%3*3;v?.mark(S-1,3,{kind:"place",at:w}),v?.put(S,k?"■":"·",k?ct+o:C)}b=Ut[i.tune.at-1]??"center"}else{let w;if(d===0){let{size:k}=i.tune;w=k==="fill"?c-1:Math.floor((k-u)*(c-1)/(l-u+1)),b=k==="fill"?"fill":`${k}%`}else w=Math.floor(Math.round(i.tune.opacity*100)*(c-1)/100),b=cC(i.tune.opacity);w=Math.max(0,Math.min(c-1,w)),t[h]?.run(n+12,[["━".repeat(w),o],["●",ct],["─".repeat(c-1-w),C]]),t[h]?.mark(n+12,c,{kind:"track",field:d})}if(t[h]?.right(r-2,[[b,g]]),aC(i,d))t[h]?.put(r-1,"↺",m?ct+o:C)}}function lC(t,e,n,r,i,o){t[e]?.put(n,`╭${"─".repeat(i-2)}╮`,o);for(let s=e+1;s<e+r-1;s++)t[s]?.put(n,"│",o),t[s]?.put(n+i-1,"│",o);t[e+r-1]?.put(n,`╰${"─".repeat(i-2)}╯`,o)}function Ym(t,e=t.site,n=t.siteAnsi){return[` ${e} `,`\x1B[7;${30+n}m`]}function La(t){return`${J[Math.floor(t/Mr)]?.name??"local"} ${t%Mr}`}function Ca(t,e,n){let r=J[Math.floor(e/Mr)],i=La(e),o=t.indexOf(i);if(!r||o===-1)return[[t,n]];return[[t.slice(0,o),n],...Yi(i,n,r.pageUrl(e%Mr),ti(r.ansi)),[t.slice(o+i.length),n]].filter(([a])=>a!=="")}function dC(t,e,n){let r=[{name:"all",moved:!1},...J].flatMap((o,s)=>{let a=`${o.name}${o.moved?"*":""}`,[c,u]=o.name===n.site?Ym(n,a):[` ${a} `,C],l=[c,u,void 0,{kind:"site",tab:s}];return s?[[" ",""],l]:[l]}),i=r.reduce((o,[s])=>o+ft(s),0)<=e;t.run(0,i?r:[Ym(n)])}function fC(t,e,n,r){if(n.chips.length===0)return;let i=[["tags ",C]],o=ft("tags "),s=n.chips.length;for(let[a,c]of n.chips.entries()){let u=` ${a+1} ${c.name} `;if(o+ft(u)+1>e-2)break;i.push([u,c.on?`\x1B[7m${r}`:C,void 0,{kind:"chip",index:a}],[" ",""]),o+=ft(u)+1,s--}if(s>0)i.push([`+${s}`,C]);t.run(0,i)}function hC(t,e,n,r,i){t[ge-1]?.put(0,"─".repeat(n-1),C);let o=t[be.top-1],s=Zm(n),a=r.held.length>s?Math.max(0,s-1):r.held.length;for(let[c,u]of r.held.slice(0,a).entries()){let l=c*be.pitch,d=u.up?ct:"";if(o.run(l+1,u.page?Yi(String(u.id),d,u.page,ti(u.ansi)):[["● ",ti(u.ansi)],[String(u.id),d]]),u.up)for(let f=0;f<be.rows;f++)t[be.top+f]?.put(l,"▌",i);if(u.thumb)e.push({id:zH+c,path:u.thumb,row:be.top,col:l+1,cols:be.cols,rows:be.rows,z:-1})}if(a<r.held.length)o.put(a*be.pitch+1,`+${r.held.length-a}`,C)}function mC(t,e,n,r){if(n.editing!==void 0){let c=t.run(0,[["⌕ ",r],[n.editing,""],["█",r]]),u=n.suggest?.length?" ↑↓ pick enter searches":" enter searches";t.put(c,n.editing?u:` A tag, a post URL or an id, or drop a picture or ctrl+v — ${n.tag||"esc leaves"}`,C);return}let i=t.run(0,[["⌕ ",r,void 0,{kind:"query"}],[n.tag||"Nothing yet — / searches, ctrl+v pastes a picture",n.tag?"":C,void 0,{kind:"query"}]]),o=pi.filter((c)=>!n.block.includes(c)),s=J.filter((c)=>!n.enabled.includes(c.name)).map((c)=>c.name),a=[n.preset,...n.solo?["solo"]:[],n.order,...n.rating.join("+")==="safe"?[]:[n.rating.join("+")],...o.length>0?[`allows ${o.join("+")}`]:[],...n.narrow.size>0?[`≥${n.narrow.size}px`]:[],...n.narrow.score>0?[`score≥${n.narrow.score}`]:[],...n.narrow.png?["png"]:[],...n.hide.length+n.hideTags.length>0?[`hides ${[...n.hide,...n.hideTags].join("+")}`]:[],...s.length>0?[`all skips ${s.join("+")}`]:[]];if(t.put(i,` ${a.join(" ")}`,C),n.total>0||!n.searching){let c=[[`${n.tiles.length}/${n.checked}`,""]];if(n.checked<n.total)c.push([` of ${n.total}`,C]);t.right(e,c)}}function iv(t){if(t.cut==="on")return[[`Cut out · ${t.clear}% transparent`,lo]];if(t.cut==="off")return[["Opaque · x cuts out",ne]];if(t.cut==="failed")return[["Opaque · no cut-out",ne]];return[t.clear>0?[`${t.clear}% transparent`,lo]:["Opaque",ne]]}function V1(t){return t.site==="all"?"any site":t.site}function Jm(t,e){if(t.installing!==void 0)return Ca(`${ps(t)} Installing ${t.palette} ← ${La(t.installing)}`,t.installing,ne);if(t.hint)return[[t.hint,lo]];if(t.error)return[[t.error,ne]];if(t.waiting!==void 0)return[[`${t.slow??t.site} asked to slow down · ${t.waiting}s`,ne]];if(t.fetching){let{id:n,got:r,size:i}=t.fetching;return Ca(`${ps(t)} Fetching ${La(n)} · ${Yu(r,i)}`,n,ne)}if(t.cutting!==void 0)return Ca(`${ps(t)} Cutting out ${La(t.cutting)}`,t.cutting,ne);if(t.preparing!==void 0)return Ca(`${ps(t)} Preparing ${La(t.preparing)}`,t.preparing,ne);if(e)return[e];if(t.saved)return Ca(t.saved.text,t.saved.key,lo);if(t.note)return[[t.note,C]];return}function ov(t){if(t.ranking)return"Ranking previews by palette colors";if(t.stage==="check")return t.preset==="cutouts"?"Checking PNG headers":"Loading previews";return"Fetching posts"}function sv(t,e){return t.ranking?`${e}${t.ranking.done}/${t.ranking.total}`:""}function pC(t,e,n,r,i){let{background:o,cursor:s,selection:a}=r.colors,{ranking:c}=r,u=c?Math.round(n*c.done/c.total):-1,l=Math.max(6,Math.round(n*0.22)),d=ml(r)%(q1*2)/q1,f=Math.round((n-l)*(0.5-0.5*Math.cos(Math.PI*(d<1?d:2-d)))),h=pt(o,s,i),m=pt(o,pt(a,o,0.15),i),g=Array.from({length:n},(w,k)=>{let v=(u>=0?k<u:k>=f&&k<f+l)?h:m;return k===0||k===n-1?pt(v,o,0.55):v}),b=0;for(let w=1;w<=n;w++)if(w===n||g[w]!==g[b])t?.put(e+b," ".repeat(w-b),fl(g[b])),b=w}function gC(t,e,n,r,i){let{background:o,foreground:s}=i.colors,a=i.loaderFrom===void 0?0:Math.min(1,(ml(i)-i.loaderFrom)/JH),c=e+(n>=5?Math.floor((n-5)/2):0);t[c]?.center(r,[[ov(i),ct+ms(pt(o,s,a))],[sv(i," "),ms(pt(o,pt(s,o,0.45),a))]]);let u=Math.min(YH,r-8);if(pC(t[c+(n>=3?2:1)],Math.floor((r-u)/2),u,i,a),n<5)return;t[c+4]?.center(r,i.sites.flatMap(({name:l,arrived:d},f)=>[...f?[[" · ",ms(pt(o,s,0.25*a))]]:[],[l,ms(pt(o,d?pt(s,o,0.2):s,d?a:0.32*a))]]))}function bC(t,e,n,r,i,o){if(i<=r)return;let s=Math.max(1,Math.round(r*r/i)),a=Math.max(0,Math.min(r-s,Math.round(n.scroll*r/i)));for(let c=0;c<r;c++){let u=c>=a&&c<a+s;t[ge+c]?.put(e-1,u?"┃":"│",u?o:C)}}function wC(t,e,n){if(e)return[`${ps(t)} ${ov(t)}${sv(t," · ")}`,C];let r=n.filter((o)=>!o.missing),i=r.filter((o)=>o.thumb).length;return i<r.length?[`${ps(t)} Loading thumbnails · ${i}/${r.length}`,C]:void 0}function $C(t,e,n,r,i,o,s){let{perRow:a,rowsVis:c,height:u}=or(r,i);mC(t[0],r,o,s),dC(t[1],r,o),fC(t[2],r,o,s),hC(t,e,r,o,s);let l=t.map((H,N)=>N>=ge&&N<ge+u?H:void 0),d=Math.floor(o.scroll/kt.height),f=Math.floor((o.scroll+u-1)/kt.height),h=[];for(let H=d;H<=f;H++){let N=ge+H*kt.height-o.scroll;for(let L=0;L<a;L++){let K=H*a+L,B=L*kt.pitch,X=o.tiles[K];if(!X)continue;h.push(X);let z=Math.max(N,ge),Mt=Math.min(N+kt.height,ge+u);if(Mt>z)n.push({row:z,col:B,width:kt.pitch-1,height:Mt-z,target:{kind:"tile",index:K}});let tt=K===o.focus;if(tt)lC(l,N,B,kt.height,kt.pitch-1,s);let fr=N+1,fn=Math.max(fr,ge),hn=Math.min(fr+kt.rows,ge+u);if(X.thumb&&hn>fn)e.push({id:X.key,path:X.thumb,row:fn,col:B+1,cols:kt.cols,rows:hn-fn,...hn-fn<kt.rows?{crop:fn-fr}:{},z:-1});let mn=[...o.installed.includes(X.key)?[["✓ ",lo]]:[],...X.page||o.site!=="all"?Yi(String(X.id),tt?ct:"",X.page||void 0,ti(X.siteAnsi)):[["● ",ti(X.siteAnsi)],[String(X.id),tt?ct:""]],[" ",""],rv(X)],lc=kt.cols-(X.mates.length>0?1:0);if(l[N+10]?.run(B+1,qm(mn)>lc?mn.map(([rd,id,od])=>[rd.replace(/^(\S) $/,"$1"),id,od]):mn),X.mates.length>0)l[N+10]?.put(B+kt.cols,"≈",s);l[N+11]?.put(B+1,X.artist?QH(X.artist).slice(0,kt.cols-8):"—",C);let ri=[];if(X.score>0)ri.push([`★${X.score}`,C]);if(X.variants>1)ri.push([` ×${X.variants}`,s]);if(ri.length>0)l[N+11]?.right(B+kt.cols+1,ri)}}let m=Math.ceil(o.tiles.length/a)*kt.height;bC(t,r,o,u,m,s);let g=Math.max(ge,ge+m-o.scroll),b=ge+u-g,w=o.searching&&b>=2;if(w)gC(l,g,b,r-1,o);let k=o.searching&&o.tiles.length===0;if(k&&!o.error){let[H,N]=Y1[Math.floor(ml(o)/VH)%Y1.length];t[i-2]?.run(0,[["Tip ",C],[H,ct],[` ${N}`,C]])}let v=o.top*a,S=o.tiles.length-(o.top+c)*a,M=[...v>0?[`↑ ${v} above`]:[],...S>0?[`↓ ${S} more`]:[]];if(M.length>0)t[i-2]?.put(0,M.join(" "),C);if(!o.searching&&o.tiles.length===0&&!o.error&&o.tag)t[ge+1]?.put(0,o.preset==="cutouts"?`No transparent cutouts of ${o.tag} on ${V1(o)} — c searches every post, tab tries ${o.nextSite}`:`No posts of ${o.tag} on ${V1(o)} — tab tries ${o.nextSite}`,C);let I=wC(o,w,h),O=Jm(o,I);return Fa(t[i-1],r,s,{badge:"IMAGE SEARCH",lead:O,keys:k&&O?.[0]===I?[]:[["←↑↓→","move"],["enter","try on"],["tab","site"],["ctrl+v","picture"],["s","settings"],["/","search"],["?","keys"]],right:["esc","back"]}),w}function kC(t,e,n,r,i,o){let s=i.tiles[i.focus];if(!s)return;let a=i.shown?.id===s.key?i.shown:void 0,c=[Ym(i,s.site,s.siteAnsi),[" ",""],...Yi(String(s.id),ct,s.page||void 0,ti(s.siteAnsi)),[" ",""],rv(s)];if(s.score>0)c.push([` · ★${s.score}`,C]);if(a)c.push([` · ${qu(a.bytes)}`,C]);if(a){if(c.push([" ",""],...iv(a)),i.coloring==="original")c.push([" · own colors",C])}if(t[0]?.run(0,c),s.mates.length>0)t[0]?.right(n,[["≈ ",o],[s.mates.join(" "),C]]);if(rC(t,1,2,i,o),i.tuning)uC(t,8,2,2+Math.min(n-4,60),i,o);else if(i.details)iC(t,5,2,Math.min(n-4,Math.max(48,Math.floor(n*0.55))),r-2,i);else eC(t,7,2,n-4,r-2,i,o);if(i.shown)e.push({id:Vm+i.shown.id,path:i.shown.path,row:0,col:0,cols:n,rows:r,z:DH});if(i.tuning){Fa(t[r-1],n,o,{badge:"IMAGE EDIT",lead:Jm(i),keys:[["↑↓","field"],["←→","step"],["=","reset"],["+","reset all"],i.tuning.field===1?["1-9","place"]:["⇧←→","×10"],["c","colors"],["enter","keep"]],right:["esc","undo"]});return}let u=Jm(i);Fa(t[r-1],n,o,{badge:"IMAGE PREVIEW",lead:u,keys:i.installing===void 0?[["←→","browse"],["enter","install"],["t","tune"],["c","colors"],["i","details"],...i.details?[]:[["⇧←→","example"]],...i.shown?.cut==="on"||i.shown?.cut==="off"?[["x","cut out"]]:[],["?","keys"]]:[],right:i.installing===void 0?["esc","grid"]:void 0})}var yC=[["Field","↑↓ size, position, opacity"],["Step","←→ · ⇧←→ ×10"],["Place","1-9 the nine positions"],["Reset","= this field back to its default · + every field"],["Colors","c the palette's tone or its own colors, opacity back to its default"],["Keep","enter back to try, installed with the picture"],["Undo","esc"],["Close","? esc"]],vC={grid:[["Move","←↑↓→ j k home end pgup pgdn"],["Try on","enter"],["Site",`tab shift+tab all, ${J.map((t)=>t.name).join(", ")}`],["Posts","c cutouts or every post"],["Search","/ a tag, a post URL or an id"],["Tags","1-9 turn a tag of the tags row on or off — the palette's own, then danbooru's related characters"],["Your own","ctrl+v or v a picture from the clipboard · drop one on the window or paste its link"],["Unfold","space a set of ×N"],["Open","o the post page in a browser"],["Settings","s rating, block, posts, solo, order, sets, remove bg"],["Advanced","a or Advanced › in settings min score, min size, sites, hide, hide tags, PNG only"],["Back","esc returns to preview"],["Close","? esc"]],try:[["Browse","←→"],["Install","enter"],["Tune","t size, position and opacity, installed with the picture"],["Colors","c the palette's tone or its own colors, installed with the picture"],["Details","i characters, series, tags, rating and file, under Post, Source and Artist"],["Example",`⇧←→ ${zt.map((t)=>t.name.toLowerCase()).join(", ")}`],["Cut out","x the background off or on, on an opaque picture"],["Open","o the post page in a browser"],["Your own","ctrl+v or v a picture from the clipboard · drop one on the window"],["Grid","esc"],["Close","? esc"]]},Xm=6,SC=24;function ja(t){return[...t.settings.flatMap((e,n)=>Boolean(e.advanced)===t.advanced?[n]:[]),t.settings.length]}function EC(t){return t.replace(/^[A-Z](?=[a-z])/,(e)=>e.toLowerCase())}function Z1(t){let e=t.settings.filter((n)=>Boolean(n.advanced)!==t.advanced).map((n)=>EC(n.label));return`${t.advanced?"Back to":"More filters:"} ${e.join(", ")} — enter opens the page, or a from any row`}function av(t,e,n){let r=t.indexOf(e);if(r!==-1)return t[(r+n+t.length)%t.length];let i=Number(e)||0;return(n>0?t.find((s)=>(Number(s)||0)>i):[...t].reverse().find((s)=>(Number(s)||0)<i))??t[n>0?0:t.length-1]}function Di(t,e){let n=[],r="";for(let i of t.split(" "))if(r&&ft(r)+1+ft(i)>e)n.push(r),r=i;else r=r?`${r} ${i}`:i;return r?[...n,r]:n}function MC(t){if(t.entry!=="number"||t.choices.includes(t.value))return t.choices;let e=t.choices.findIndex((n)=>(Number(n)||0)>Number(t.value));return e===-1?[...t.choices,t.value]:[...t.choices.slice(0,e),t.value,...t.choices.slice(e)]}function xC(t,e,n,r){let i=`\x1B[7;${30+r}m`,o=e&&n!==void 0;if(t.entry==="text")return[{text:` ${o?`${n}█`:t.value||"none"} `,sgr:o||e&&t.value?i:t.value?"":C}];let s=o?[]:t.value.split(" "),a=(o?t.choices:MC(t)).map((c,u)=>{let l=s.includes(c),d=t.multi&&e&&u===t.cursor?"4;":"";return{text:t.multi?` ${l?"[x]":"[ ]"} ${c} `:` ${c} `,sgr:l?e?`\x1B[${d}7;${30+r}m`:"":d?`\x1B[4m${C}`:C,choice:c}});return o?[...a,{text:` ${n}█ `,sgr:i}]:a}function Q1(t){if(t.entry==="text")return[{text:" ".repeat(SC),sgr:""}];let e=t.choices.map((n)=>({text:t.multi?` [x] ${n} `:` ${n} `,sgr:""}));return t.entry==="number"?[...e,{text:` ${"0".repeat(Xm)}█ `,sgr:""}]:e}function OC(t){return t.reduce((e,n)=>e+ft(n.text)+1,0)-1}function X1(t,e){let n=[[]],r=0;for(let i of t){let o=ft(i.text)>e?{...i,text:` …${Array.from(i.text).slice(-(e-2)).join("")}`}:i;if(r>0&&r+ft(o.text)>e)n.push([]),r=0;n[n.length-1]?.push(o),r+=ft(o.text)+1}return n}function tv(t){if(t.multi&&t.choices.every((e)=>t.default.split(" ").includes(e)))return"Default all";return`Default ${t.default&&t.default!==t.multi?.none?t.default:"none"}`}function ev(t){if(!t.tag)return"";if(!t.counts)return`${t.tag}: counting…`;let e=t.counts.map(({site:n,count:r})=>`${n} ${r===void 0?"no count":r.toLocaleString("en-US")}`);return`${t.tag}: ${e.join(" · ")}`}function IC(t,e){let n=t.advanced?"basic":"advanced";if(!e)return{keys:[["↑↓","setting"],["enter",n],["s","save"]],right:["esc","undo"]};if(t.typing!==void 0)return{keys:[["⌫","erase"],["enter","done"]],right:["esc","cancel"]};if(e.entry)return{keys:[["↑↓","setting"],...e.entry==="number"?[["←→","step"]]:[],["a",n],["enter","type"],["s","save"]],right:["esc","undo"]};return{keys:[["↑↓","setting"],["←→","value"],["a",n],...e.multi?[["space","toggle"]]:[],["enter","save"]],right:["esc","undo"]}}function RC(t,e,n,r,i){let o=r.panel??0,s=r.settings.length,c=6+Math.max(...r.settings.map((z)=>ft(z.label))),u=Math.max(...r.settings.map((z)=>ft(tv(z)))),l=c+Math.max(...r.settings.map((z)=>OC(Q1(z))))+u+5,d=Math.min(e-2,Math.max(48,l)),f=d-c-u-5,h=d-7,m=[!1,!0].map((z)=>({advanced:z,rows:ja({settings:r.settings,advanced:z}).slice(0,-1)})),g=r.settings.map((z)=>X1(Q1(z),f).length),b=Math.max(...m.map((z)=>z.rows.reduce((Mt,tt)=>Mt+g[tt],0))),w=Math.max(...m.map((z)=>Di(Z1({settings:r.settings,advanced:z.advanced}),h).length),...r.settings.map((z)=>Di(z.about,h).length)),k=`${r.tag}: ${J.map((z)=>`${z.name} 0,000,000`).join(" · ")}`,v=r.tag?Math.max(Di(k,h).length,Di(ev(r),h).length):0,S=b+w+v+8,M=Math.floor((e-d)/2),I=Math.max(1,Math.floor((n-1-S)/2)),O=`\x1B[7;${30+r.siteAnsi}m`;t[I]?.put(M,`╭─ Settings ${"─".repeat(Math.max(0,d-13))}╮`);for(let z=I+1;z<I+S-1;z++)t[z]?.put(M,`│${" ".repeat(d-2)}│`);let H=I+2;for(let z of ja(r).slice(0,-1)){let Mt=r.settings[z],tt=z===o;if(tt)t[H]?.put(M+2,"▶",i);if(t[H]?.mark(M+2,c-3,{kind:"setting",index:z}),t[H]?.put(M+4,Mt.label,tt?ct:""),Mt.value!==Mt.default)t[H]?.right(M+d-3,[[tv(Mt),C]]);X1(xC(Mt,tt,r.typing,r.siteAnsi),f).forEach((fr,fn)=>{let hn=M+c;for(let mn of fr)hn=t[H+fn].put(hn,mn.text,mn.sgr,void 0,{kind:"choice",index:z,choice:mn.choice}),hn+=1}),H+=g[z]}let N=m.find((z)=>z.advanced!==r.advanced)?.rows??[],L=t[I+3+b];if(o===s)L.put(M+2,"▶",i);let K=L.put(M+3,r.advanced?" ‹ Basic ":" Advanced › ",o===s?O:ct,void 0,{kind:"setting",index:s});if(N.some((z)=>r.settings[z]?.value!==r.settings[z]?.default))L.put(K+1,"•",C);t[I+5+b]?.put(M+2,"─".repeat(d-4),C),Di(r.settings[o]?.about??Z1(r),h).forEach((z,Mt)=>{t[I+6+b+Mt]?.put(M+4,z)}),Di(ev(r),h).forEach((z,Mt)=>{t[I+6+b+w+Mt]?.put(M+4,z,C)}),t[I+S-1]?.put(M,`╰${"─".repeat(d-2)}╯`);let{keys:B,right:X}=IC(r,r.settings[o]);Fa(t[n-1],e,i,{keys:B,right:X})}function PC(t,e,n,r,i){let o=r.tuning?yC:vC[r.mode],s=Math.min(e-2,Math.max(50,...o.map(([,f])=>ft(f)+16))),a=o.map(([f,h])=>({label:f,parts:Di(h,s-16)})),c=a.reduce((f,{parts:h})=>f+h.length,0)+4,u=Math.floor((e-s)/2),l=Math.max(2,Math.floor((n-c)/2));t[l]?.put(u,`╭─ Help ${"─".repeat(s-9)}╮`);for(let f=l+1;f<l+c-1;f++)t[f]?.put(u,`│${" ".repeat(s-2)}│`);let d=l+2;for(let{label:f,parts:h}of a){t[d]?.put(u+3,f,ct);for(let m of h)t[d]?.put(u+13,m),d++}t[l+c-1]?.put(u,`╰${"─".repeat(s-2)}╯`),Fa(t[n-1],e,i,{badge:"HELP",right:["? esc","close"]})}function NC(t,e,n){let r=e.suggest??[],i=r.map((a)=>a.alias??(a.count>0?String(a.count):a.palette??"0")),o=Math.max(...r.map((a)=>ft(a.value))),s=Math.max(7,...i.map(ft));r.forEach((a,c)=>{let u=c===e.pick,l=t[1+c];l?.run(0,[[u?"▸ ":" ",n,void 0,{kind:"suggest",index:c}],[a.value,u?ct+n:"",void 0,{kind:"suggest",index:c}]]),l?.right(2+o+2+s,[[i[c],C]])})}function ll(t,e=[]){return[...e,...t.flatMap((n,r)=>n.zones(r))]}function tp(t,e,n){let r=Array.from({length:n},()=>new dl(e)),i=[],o=[],s=ms(t.colors.cursor);if(zm=!1,e<qi.cols||n<qi.rows)return r[0]?.put(0,"ttheme find",ct+s),r[1]?.put(0,`Needs ${qi.cols}×${qi.rows} — now ${e}×${n}`),r[2]?.put(0,"esc quits",C,void 0,{kind:"key",key:"esc"}),{lines:r.map((c)=>c.render()),images:i,zones:ll(r),loader:!1,tick:!1};let a=!1;if(t.mode==="try")kC(r,i,e,n,t,s);else a=$C(r,i,o,e,n,t,s);if(t.mode==="grid"&&t.editing!==void 0&&t.suggest?.length){for(let c=1;c<n-1;c++)r[c]=new dl(e);return NC(r,t,s),{lines:r.map((c)=>c.render()),images:[],zones:ll(r),loader:!1,tick:!1}}if(t.help||t.panel!==void 0){let c=t.mode==="try"?i:[];for(let u=0;u<n;u++)r[u]=new dl(e);if(t.help)PC(r,e,n,t,s);else RC(r,e,n,t,s);return{lines:r.map((u)=>u.render()),images:c,zones:ll(r),loader:!1,tick:!1}}return{lines:r.map((c)=>c.render()),images:i,zones:ll(r,o),loader:a,tick:zm}}var AC=130,TC=38,HC=96,CC=28,Ga=[{id:"shell",scenes:["Diff","Logs","Shell"],name:"zsh",tail:!0},{id:"code",scenes:["Editor"],name:"nvim",tail:!1},{id:"monitor",scenes:["Top"],name:"htop",tail:!1}],LC={Shell:[0,1,2,3,4,6,7,9,10,12,14],Diff:[0,1,3,4,6,7,8,9,10,15],Logs:[0,1,2,3,4,5,6,7,8,9,10]},cv=(t)=>Array.from({length:8},(e,n)=>`«K${t+n}» «»`).join(" "),FC=["«2»❯ «»colortest",`«d»0-7 ${cv(0)}`,`«d»8-15 ${cv(8)}`],uv=2;function jC(t){let e=Ga.length;return Ga[(t%e+e)%e]}function fv(){return Ga.map((t)=>t.name)}function Ua(t,e,n){let r=t>=AC&&e>=TC?"full":t>=HC&&e>=CC?"tabs":void 0;if(!r)return;let i=r==="full"?t>=140?47:38:37,o=t-i-1,s=i+1+uv,a=i+o-uv,c=3,u=e-3,l={col:s,row:c,cols:a-s+1,rows:u-c+1},d={col:s+1,row:c+3,cols:l.cols-2,rows:u-c-3},f=[{row:c,col:s,length:l.cols,down:!1},{row:c+2,col:s,length:l.cols,down:!1},{row:u,col:s,length:l.cols,down:!1},{row:c,col:s,length:u-c+1,down:!0},{row:c,col:a,length:u-c+1,down:!0}],h=jC(n);return{tier:r,side:i,width:o,frame:l,title:{col:d.col,row:c+1,cols:d.cols,rows:1},inner:d,rules:f,tiles:[{id:h.id,name:h.name,col:d.col,row:d.row,width:d.cols,rows:d.rows}]}}var Ba="«2»▎ ",lv="«3»▎ ",_C="«1»▁ ",BC=[["","«5»import«» { «4»readFile«» } «5»from «2»'node:fs/promises'"],["","«5»import«» { «5»type «6»Hex«», «4»contrast«» } «5»from «2»'./color.ts'"],["",""],["","«8»/** A palette read from disk and checked against the gate. */"],[Ba,"«5»export interface «6»Palette «»{"],[Ba," name: «6»string"],[Ba," ansi: «6»Hex«»[]"],[Ba," ratio?: «6»number"],[Ba,"}"],["",""],["","«5»const «»SIXTEEN = «3»16"],["","«5»const «»FLOOR = «3»4.5 «8»// WCAG AA for body text"],["",""],["","«5»export async function «4»load«»(path: «6»string«»): «6»Promise«»<«6»Palette«»> {"],[lv," «5»const «»text = «5»await «4»readFile«»(path, «2»'utf8'«»)"],[lv," «5»const «»colors = «s»parse(text)«».colors ?? {}"],[""," «5»if «»(colors.ansi.length !== «K3»SIXTEEN«») { «1»● needs 16 ANSI colors"],[""," «5»throw new «6»Error«»(«2»'expected sixteen colors, got '«» + colors.ansi.length)"],[""," }"],[_C," «5»const «»ratio = «4»contrast«»(colors.ansi[«3»0«»], colors.ansi[«3»7«»]) «3»● ratio is read once"],[""," «5»return «»{ name: path, ...colors, ratio: «c»r«»atio }"],["","}"],["",""],["","«5»export function «4»passes«»(palette: «6»Palette«»): «6»boolean «»{"],[""," «5»return «»(palette.ratio ?? «3»0«») >= FLOOR «8»// TODO: check the bright pairs"],["","}"]],GC=21;function UC(){return["«K4» theme.ts «s» scenes.ts «s» contrast.ts ",...BC.map(([t,e],n)=>{let r=String(n+1).padStart(3);return`${n+1===GC?`«b»${r}`:`«d»${r}`} ${t||"«» "}«»${e}`})]}function ep(t,e,n,r){let i=Math.max(1,r-t.length-2-n.length),o=0,s=`«6»${t}«b»[`;for(let[a,c]of e){let u=Math.min(i-o,Math.round(c*i));s+=`«${a}»${"|".repeat(u)}`,o+=u}return`${s}«»${" ".repeat(i-o)}${n}«b»]`}var WC=[[0.31,0.07,0],[0.22,0.02,0.03],[0.04,0.01,0],[0.52,0.12,0],[0.1,0.02,0],[0.41,0.11,0],[0.02,0,0],[0.15,0.03,0.04]],KC=["«s» 4127 kec 24 0 412G 612M «s»R 38.2 3.7 3:12.44 node dev.js"," 2210 kec 31 0 411G 1.2G «2»R«» 12.0 7.5 1:02.10 «d»/Applications/«b»Ghostty"," 3301 kec 31 0 409G 12M S 4.4 0.1 0:05.61 «b»zsh"," 3302 kec 31 0 409G 9.8M S 0.0 0.1 0:00.42 «d»├─ «b»nvim «»src/theme.ts"," 3310 kec 31 0 410G 88M S 1.2 0.5 0:03.18 «d»│ └─ «b»tsserver"," 3402 kec 24 0 409G 21M «2»R«» 0.6 0.1 0:01.02 «d»└─ «b»htop"," 501 kec 31 «4»10«» 409G 34M S 0.3 0.2 0:02.77 «b»bun «»test --watch"," 1180 kec 31 0 409G 72M «1»D«» 0.0 0.4 0:00.91 «b»rsync «»-a ~/Pictures backup:"," 812 «d»root«» «1» 4 -20«» 410G 1.5G S 3.1 9.4 0:44.02 «d»kernel_task"," 167 «d»root«» 31 0 411G 402M S 0.9 2.5 0:12.80 «d»WindowServer"," 344 «d»_mdns«» 31 0 408G 5.1M S 0.0 0.0 0:00.33 «d»mDNSResponder"],zC=["Help","Setup","Search","Filter","Tree","SortBy","Nice -","Nice +","Kill","Quit"];function DC(t,e,n){return`«${t}»${e}${" ".repeat(Math.max(0,n-_(e)))}`}function qC(t){let e=t-2,n=Math.floor((e-2)/2),r=(i)=>{let[o,s,a]=WC[i],c=`${((o+s+a)*100).toFixed(1)}%`;return ep(String(i).padStart(3),[["2",o],["1",s],["4",a]],c,n)};return[...[0,1,2,3].map((i)=>`${r(i)} ${r(i+4)}`),`${ep("Mem",[["2",0.45],["4",0.1],["3",0.07]],"9.84G/16.0G",n)} «6»Tasks: «b»214«», 1093 thr; «B2»4«» running`,`${ep("Swp",[["1",0.15]],"0.31G/2.00G",n)} «6»Load average: «b»2.14 «»1.87 «d»1.52`,`${" ".repeat(n)} «6»Uptime: «b»3 days, 04:12:55`,"",DC("K2"," PID USER PRI NI VIRT RES S CPU% MEM% TIME+ Command",e),...KC.map((i)=>i.startsWith("«s»")?`${i}${" ".repeat(Math.max(0,e-_(i.replace(/«[^»]*»/g,""))))}`:i)]}function YC(t){let e=t-2,n="",r=0;return zC.forEach((i,o)=>{let s=`F${o+1}`,a=i.padEnd(6);if(r+s.length+a.length<=e)n+=`«»${s}«K6»${a}`,r+=s.length+a.length}),`${n}«K6»${" ".repeat(Math.max(0,e-r))}`}function dv(t,e,n){if(t==="Editor")return UC();if(t==="Top")return qC(n);let r=zt.find((s)=>s.name===t)?.lines??[],i=e?LC[t]:void 0,o=i?i.map((s)=>r[s]??""):r;return t==="Shell"?[...o.slice(0,-1),...FC,...o.slice(-1)]:o}function pl(t,e){let n=[];for(let r of t){let i=Wo(r,e);if(!i)continue;let o=0;n.push(i.map(([s,a])=>{let c={text:s,role:a,col:o};return o+=_(s),c}))}return n}function JC(t){let r=t-2-_("«K4» NORMAL «s» main src/theme.ts [+] ".replace(/«[^»]*»/g,""))-_("«K1» 1 «K3» 1 «s» utf-8 typescript 21:28 «K4» 80% ".replace(/«[^»]*»/g,""));return`${"«K4» NORMAL «s» main src/theme.ts [+] "}${" ".repeat(Math.max(0,r))}${"«K1» 1 «K3» 1 «s» utf-8 typescript 21:28 «K4» 80% "}`}function VC(t,e){if(t.id==="code")return[JC(e),'«d»"src/theme.ts" 26L, 912B written'];return t.id==="monitor"?[YC(e)]:[]}function ZC(t,e,n){let r=pl(VC(t,e),e),i=Math.max(0,n-r.length),o=[];for(let a of[...t.scenes].reverse()){let c=pl(dv(a,!1,e),e),u=pl(dv(a,!0,e),e),l=[c,u].find((d)=>o.length+d.length<=i);if(!l){if(o.length===0)o=t.tail?u.slice(u.length-i):u.slice(0,i);break}o=[...l,...o]}if(r.length===0)return o;let s=pl(Array.from({length:i-o.length},()=>t.id==="code"?"«4»~":""),e);return[...o,...s,...r]}function Wa(t){let e=Ga.find((n)=>n.id===t.id);return e?ZC(e,t.width,t.rows):[]}function np(t,e){let{text:n,ground:r}=mv(t);return n===e||r===e}function hv(t,e){let n=t.inner;return Ga.map((r)=>({name:r.name,count:Wa({id:r.id,name:r.name,col:n.col,row:n.row,width:n.cols,rows:n.rows}).flat().filter((i)=>np(i.role,e)).length}))}function mv(t){if(t==="s")return{text:1,ground:3};if(t==="c")return{text:1,ground:2};let e=/^([BK]?)(\d+)$/.exec(t);if(!e)return{text:1,ground:0};let n=4+Number(e[2]);return e[1]==="K"?{text:4,ground:n}:{text:n,ground:0}}function rp(t,e){if(e>=4){let n=/^([BK]?)(\d+)$/.exec(t);return n!==null&&Number(n[2])===e-4}return e===3&&t==="s"||e===2&&t==="c"}function gl(t){let e=[];for(let n of t.tiles)Wa(n).forEach((r,i)=>{r.forEach((o,s)=>{e.push({spot:{pane:n.id,line:i,run:s},col:o.col,text:o.text,role:o.role})})});return e}function ip(t,e){return t.pane===e.pane&&t.line===e.line&&t.run===e.run}function pv(t,e){let n=gl(t);return(n.find((r)=>rp(r.role,e))??n[0])?.spot}function bl(t,e){return e&&gl(t).find((n)=>ip(n.spot,e))?.spot}function gv(t,e,n){let r=gl(t);if(r.length===0)return;let i=e?r.findIndex((f)=>ip(f.spot,e)):-1;if(i<0)return r[0]?.spot;let o=r[i];if(n==="left"||n==="right")return r[(i+(n==="left"?r.length-1:1))%r.length]?.spot;if(n==="next"||n==="previous"){let f=t.tiles.map((g)=>g.id),h=f.indexOf(o.spot.pane),m=f[(h+(n==="next"?1:f.length-1))%f.length];return r.find((g)=>g.spot.pane===m)?.spot}let s=n==="up"?-1:1,a=r.filter((f)=>f.spot.pane===o.spot.pane),c=[...new Set(a.map((f)=>f.spot.line))],u=c[c.indexOf(o.spot.line)+s];if(u===void 0){let f=t.tiles.map((k)=>k.id),h=f.indexOf(o.spot.pane)+s,m=f[(h+f.length)%f.length],g=r.filter((k)=>k.spot.pane===m),b=s<0?g.at(-1)?.spot.line??0:g[0]?.spot.line??0,w=g.filter((k)=>k.spot.line===b);return(w.find((k)=>k.col>=o.col)??w.at(-1))?.spot}let l=a.filter((f)=>f.spot.line===u);return(l.find((f)=>f.col<=o.col&&f.col+_(f.text)>o.col)??l.find((f)=>f.col>=o.col)??l.at(-1))?.spot}function bv(t,e){let n=gl(t).find((r)=>ip(r.spot,e));return n?mv(n.role):void 0}var QC={lr:"─",du:"│",dr:"╭",dl:"╮",ru:"╰",lu:"╯",dlr:"┬",lru:"┴",dru:"├",dlu:"┤",dlru:"┼"};function wv(t){let e=new Map,n=(i,o,s)=>{let a=e.get(i)??new Map;e.set(i,a);let c=a.get(o)??new Set;a.set(o,c),c.add(s)};for(let i of t)for(let o=0;o<i.length;o++){let s=i.down?i.row+o:i.row,a=i.down?i.col:i.col+o;if(o>0)n(s,a,i.down?"u":"l");if(o<i.length-1)n(s,a,i.down?"d":"r")}let r=new Map;for(let[i,o]of e){let s=new Map;for(let[a,c]of o){let u=[...c].sort().join("");s.set(a,QC[u]??(c.has("l")||c.has("r")?"─":"│"))}r.set(i,s)}return r}import{execFile as XC}from"node:child_process";import{createHash as vv}from"node:crypto";import{existsSync as tL,mkdtempSync as eL,readFileSync as yl,rmSync as nL,statSync as Sv,writeFileSync as Ev}from"node:fs";import{homedir as rL,tmpdir as iL}from"node:os";import{join as wl}from"node:path";import{fileURLToPath as oL}from"node:url";import{promisify as sL}from"node:util";var Pn=sL(XC),$l=67108864,aL=4096,ap=["image/png","image/jpeg","image/webp","image/gif","image/tiff","image/heic"],cL=["text/uri-list","text/plain;charset=utf-8","text/plain"],op=[...ap,"text/uri-list","text/plain"];function uL(t){try{return Sv(t).isFile()}catch{return!1}}function lL(t){let e=[],n="",r="",i=!1;for(let o=0;o<t.length;o++){let s=t[o];if(r==="'")if(s==="'")r="";else n+=s;else if(r==='"')if(s==='"')r="";else if(s==="\\"&&'"\\$`'.includes(t[o+1]??""))n+=t[++o];else n+=s;else if(s==="\\"&&o+1<t.length)n+=t[++o],i=!0;else if(s==="'"||s==='"')r=s,i=!0;else if(/\s/.test(s)){if(i)e.push(n);n="",i=!1}else n+=s,i=!0}if(i)e.push(n);return e}function $v(t){if(/^file:\/\//i.test(t))try{return oL(t)}catch{return}if(t.startsWith("~/"))return wl(rL(),t.slice(2));return t.startsWith("/")?t:void 0}function gs(t,e=uL){let n=[];for(let r of t.replace(/\r\n?/g,`
662
662
  `).split(`
663
- `)){let i=rv(r.trim());if(i&&e(i)){n.push(i);continue}for(let s of fH(r)){if(/^https?:\/\/\S+$/i.test(s)){n.push(s);continue}let o=rv(s);if(o&&e(o))n.push(o)}}return n}function iv(t){let e=ei(t)?un(t):cf(t);if(!e)return;return{ext:ei(t)?"png":"jpg",width:e.width,height:e.height}}async function Vu(t,e){let n=iv(t);if(n&&n.width*n.height<=$e)return{bytes:t,...n,source:e};if(process.platform!=="darwin")throw Error(n?`${n.width}×${n.height} is over ${$e/1e6} megapixels`:"only PNG and JPEG pictures work here");let r=nH(Yu(sH(),"ttheme-attach-"));try{let i=Yu(r,"in"),s=Yu(r,"out.png");cv(i,t);let o=!n||n.width*n.height>$e?["--resampleHeightWidthMax",String(cH)]:[];await yn("sips",["-s","format","png",...o,i,"--out",s]).catch(()=>{throw Error("that is not a picture macOS can read")});let a=new Uint8Array(Zu(s)),c=iv(a);if(!c)throw Error("that is not a picture macOS can read");return{bytes:a,...c,source:e}}finally{rH(r,{recursive:!0,force:!0})}}async function vm(t,e){if(/^https?:\/\//i.test(t)){let n=await fetch(t,{headers:{"User-Agent":pf},signal:e});if(!n.ok)throw Error(`${new URL(t).host} answered ${n.status}`);if(Number(n.headers.get("content-length")??0)>Ju)throw Error("that picture is over 64 MB");let r=new Uint8Array(await n.arrayBuffer());if(/^text\/html/i.test(n.headers.get("content-type")??""))throw Error(`${new URL(t).host} sent a web page, not a picture — copy the image address instead`);return Vu(r,t)}if(av(t).size>Ju)throw Error("that picture is over 64 MB");return Vu(new Uint8Array(Zu(t)),t)}var uv=new Map,Vn={key:"local",name:"local",origin:"file://",moved:!1,cutouts:"",best:"",tagBudget:0,ors:!1,vouched:!0,scored:!1,ansi:7,ratings:{safe:new Set,questionable:new Set,explicit:new Set},rate:()=>"",narrow:()=>[],postsUrl:()=>"",countUrl:()=>"",postUrl:()=>"",pageUrl:(t)=>uv.get(t)??"",parse:()=>[],count:()=>0};function lv(t){if(/^https?:\/\//i.test(t))return"";return t.split("/").pop()??t}function fv(t,e){uv.set(t,e)}function dv(t){return Number.parseInt(ov("sha1").update(t).digest("hex").slice(0,8),16)%dr}var dH=`ObjC.import('AppKit')
663
+ `)){let i=$v(r.trim());if(i&&e(i)){n.push(i);continue}for(let o of lL(r)){if(/^https?:\/\/\S+$/i.test(o)){n.push(o);continue}let s=$v(o);if(s&&e(s))n.push(s)}}return n}function kv(t){let e=fi(t)?$n(t):Bd(t);if(!e)return;return{ext:fi(t)?"png":"jpg",width:e.width,height:e.height}}async function kl(t,e){let n=kv(t);if(n&&n.width*n.height<=Se)return{bytes:t,...n,source:e};if(process.platform!=="darwin")throw Error(n?`${n.width}×${n.height} is over ${Se/1e6} megapixels`:"only PNG and JPEG pictures work here");let r=eL(wl(iL(),"ttheme-attach-"));try{let i=wl(r,"in"),o=wl(r,"out.png");Ev(i,t);let s=!n||n.width*n.height>Se?["--resampleHeightWidthMax",String(aL)]:[];await Pn("sips",["-s","format","png",...s,i,"--out",o]).catch(()=>{throw Error("that is not a picture macOS can read")});let a=new Uint8Array(yl(o)),c=kv(a);if(!c)throw Error("that is not a picture macOS can read");return{bytes:a,...c,source:e}}finally{nL(r,{recursive:!0,force:!0})}}async function cp(t,e){if(/^https?:\/\//i.test(t)){let n=await fetch(t,{headers:{"User-Agent":qd},signal:e});if(!n.ok)throw Error(`${new URL(t).host} answered ${n.status}`);if(Number(n.headers.get("content-length")??0)>$l)throw Error("that picture is over 64 MB");let r=new Uint8Array(await n.arrayBuffer());if(/^text\/html/i.test(n.headers.get("content-type")??""))throw Error(`${new URL(t).host} sent a web page, not a picture — copy the image address instead`);return kl(r,t)}if(Sv(t).size>$l)throw Error("that picture is over 64 MB");return kl(new Uint8Array(yl(t)),t)}var Mv=new Map,sr={key:"local",name:"local",origin:"file://",moved:!1,cutouts:"",best:"",tagBudget:0,ors:!1,vouched:!0,scored:!1,ansi:7,ratings:{safe:new Set,questionable:new Set,explicit:new Set},rate:()=>"",narrow:()=>[],postsUrl:()=>"",countUrl:()=>"",postUrl:()=>"",pageUrl:(t)=>Mv.get(t)??"",parse:()=>[],count:()=>0};function xv(t){if(/^https?:\/\//i.test(t))return"";return t.split("/").pop()??t}function Ov(t,e){Mv.set(t,e)}function Iv(t){return Number.parseInt(vv("sha1").update(t).digest("hex").slice(0,8),16)%Mr}var dL=`ObjC.import('AppKit')
664
664
  function run(argv) {
665
665
  const pb = $.NSPasteboard.generalPasteboard
666
666
  const files = pb.readObjectsForClassesOptions($([$.NSURL]), $({ NSPasteboardURLReadingFileURLsOnlyKey: true }))
@@ -685,16 +685,16 @@ function run(argv) {
685
685
  if (web && web.count > 0) return web.objectAtIndex(0).absoluteString.js
686
686
  const text = pb.stringForType('public.utf8-plain-text')
687
687
  return text && !text.isNil() ? text.js : ''
688
- }`,hH=`Add-Type -AssemblyName System.Windows.Forms,System.Drawing
688
+ }`,fL=`Add-Type -AssemblyName System.Windows.Forms,System.Drawing
689
689
  $c = [Windows.Forms.Clipboard]
690
690
  $f = $c::GetFileDropList(); if ($f.Count) { $f; exit }
691
691
  $p = Join-Path $env:TEMP 'ttheme-clipboard.png'
692
692
  $s = $c::GetData('PNG'); if ($s -is [IO.MemoryStream]) { [IO.File]::WriteAllBytes($p, $s.ToArray()); $p; exit }
693
693
  $i = $c::GetImage(); if ($i) { $i.Save($p, [Drawing.Imaging.ImageFormat]::Png); $p; exit }
694
- $c::GetText()`;function hv(){if(process.platform!=="linux")return!1;try{return/microsoft/i.test(Zu("/proc/version","utf8"))}catch{return!1}}async function mH(t){let e=Boolean(process.env.WAYLAND_DISPLAY),n=e?["wl-paste",["--list-types"]]:["xclip",["-selection","clipboard","-t","TARGETS","-o"]],r=(await yn(n[0],n[1])).stdout.split(`
695
- `).map((o)=>o.trim()),i=(o)=>e?yn("wl-paste",["--no-newline","--type",o],{encoding:"buffer",maxBuffer:Ju}):yn("xclip",["-selection","clipboard","-t",o,"-o"],{encoding:"buffer",maxBuffer:Ju});if(r.includes("text/uri-list"))return{text:(await i("text/uri-list")).stdout.toString("utf8")};let s=ym.find((o)=>r.includes(o));if(s)return cv(t,(await i(s)).stdout),{image:t};return{text:r.some((o)=>o.startsWith("text/plain")||o==="UTF8_STRING")?(await i(r.includes("text/plain")?"text/plain":"UTF8_STRING")).stdout.toString("utf8"):""}}function Em(){return Boolean(process.env.SSH_CONNECTION||process.env.SSH_TTY)}async function mv(t){if(process.platform==="darwin"){let e=(await yn("osascript",["-l","JavaScript","-e",dH,t])).stdout.trim();return e===t?{image:t}:{text:e}}if(hv()){let e=(await yn("powershell.exe",["-NoProfile","-STA","-Command",hH])).stdout.replace(/\r/g,"").trim(),n=await Promise.all(e.split(`
696
- `).map(async(r)=>/^[A-Za-z]:\\/.test(r)?(await yn("wslpath",["-u",r])).stdout.trim():r));return n.length===1&&/ttheme-clipboard\.png$/.test(n[0]??"")?{image:n[0]}:{text:n.join(`
697
- `)}}if(process.platform==="linux")return mH(t);throw Error(`reading the clipboard is not supported on ${process.platform}`)}var pH=`ObjC.import('AppKit')
694
+ $c::GetText()`;function Rv(){if(process.platform!=="linux")return!1;try{return/microsoft/i.test(yl("/proc/version","utf8"))}catch{return!1}}async function hL(t){let e=Boolean(process.env.WAYLAND_DISPLAY),n=e?["wl-paste",["--list-types"]]:["xclip",["-selection","clipboard","-t","TARGETS","-o"]],r=(await Pn(n[0],n[1])).stdout.split(`
695
+ `).map((s)=>s.trim()),i=(s)=>e?Pn("wl-paste",["--no-newline","--type",s],{encoding:"buffer",maxBuffer:$l}):Pn("xclip",["-selection","clipboard","-t",s,"-o"],{encoding:"buffer",maxBuffer:$l});if(r.includes("text/uri-list"))return{text:(await i("text/uri-list")).stdout.toString("utf8")};let o=ap.find((s)=>r.includes(s));if(o)return Ev(t,(await i(o)).stdout),{image:t};return{text:r.some((s)=>s.startsWith("text/plain")||s==="UTF8_STRING")?(await i(r.includes("text/plain")?"text/plain":"UTF8_STRING")).stdout.toString("utf8"):""}}function up(){return Boolean(process.env.SSH_CONNECTION||process.env.SSH_TTY)}async function Pv(t){if(process.platform==="darwin"){let e=(await Pn("osascript",["-l","JavaScript","-e",dL,t])).stdout.trim();return e===t?{image:t}:{text:e}}if(Rv()){let e=(await Pn("powershell.exe",["-NoProfile","-STA","-Command",fL])).stdout.replace(/\r/g,"").trim(),n=await Promise.all(e.split(`
696
+ `).map(async(r)=>/^[A-Za-z]:\\/.test(r)?(await Pn("wslpath",["-u",r])).stdout.trim():r));return n.length===1&&/ttheme-clipboard\.png$/.test(n[0]??"")?{image:n[0]}:{text:n.join(`
697
+ `)}}if(process.platform==="linux")return hL(t);throw Error(`reading the clipboard is not supported on ${process.platform}`)}var mL=`ObjC.import('AppKit')
698
698
  function run() {
699
699
  const pb = $.NSPasteboard.generalPasteboard
700
700
  const files = pb.readObjectsForClassesOptions($([$.NSURL]), $({ NSPasteboardURLReadingFileURLsOnlyKey: true }))
@@ -706,57 +706,55 @@ function run() {
706
706
  picture = ['public.png', 'public.tiff', 'public.jpeg', 'public.heic'].some((t) => types.includes(t))
707
707
  }
708
708
  return pb.changeCount + '\\t' + (picture ? 'picture' : '')
709
- }`;async function pv(){if(Em())return;if(process.platform==="darwin"){let[t="",e=""]=(await yn("osascript",["-l","JavaScript","-e",pH])).stdout.trim().split("\t");return{stamp:t,picture:e==="picture"}}if(process.platform==="linux"&&!hv()){let e=Boolean(process.env.WAYLAND_DISPLAY)?(await yn("wl-paste",["--list-types"])).stdout:(await yn("xclip",["-selection","clipboard","-t","TARGETS","-o"])).stdout;return{stamp:e,picture:/^image\//m.test(e)}}return}function Qu(t){return t.length>8&&/^(?:\/|~\/|file:|https?:)/.test(t)}var ya=(t)=>Buffer.from(t).toString("base64"),km=(t)=>Buffer.from(t,"base64");function sv(t,e){return e.find((n)=>t.includes(n))}class Sm{clipboard=!1;drops=!1;reading;offered=[];dropping;pw=ya(ov("sha1").update(`${process.pid}:${Date.now()}`).digest("hex"));send;deliver;constructor(t,e){this.send=t,this.deliver=e}start(){let t="";if(this.clipboard)t+="\x1B[?5522h";if(this.drops)t+=`\x1B]72;t=a;${$m.join(" ")}\x1B\\`;this.send(t)}stop(){this.send(`${this.clipboard?"\x1B[?5522l":""}${this.drops?"\x1B]72;t=A\x1B\\":""}`)}ask(){this.reading={mime:".",chunks:[],pw:"",listing:!0},this.send(`\x1B]5522;type=read:name=${ya("ttheme")}:pw=${this.pw};${ya(".")}\x1B\\`)}take(t){if(t.code==="5522")this.clip(t.meta,t.payload);else if(t.code==="72")this.drop(t.meta,t.payload)}clip(t,e){if(t.type!=="read")return;let n=t.status??"";if(n==="OK"){if(this.reading??={mime:".",chunks:[],pw:t.pw??"",listing:!0},t.pw)this.reading.pw=t.pw;return}let r=this.reading;if(!r)return;if(n==="DATA"){if(r.mime=t.mime?km(t.mime).toString("utf8"):r.mime,e)r.chunks.push(km(e));return}if(this.reading=void 0,n!=="DONE"){this.deliver({kind:"error",message:n==="EPERM"?"The clipboard read was not allowed":`The terminal answered ${n}`});return}let i=Buffer.concat(r.chunks);if(r.listing){let s=i.toString("utf8").split(/\s+/).filter(Boolean),o=sv(s,[...ym,...uH]);if(!o){this.deliver({kind:"text",text:""});return}let a=r.pw||this.pw,c=r.pw?"Paste event":"ttheme";this.reading={mime:o,chunks:[],pw:a,listing:!1},this.send(`\x1B]5522;type=read:name=${ya(c)}:pw=${a};${ya(o)}\x1B\\`);return}this.deliver(r.mime.startsWith("image/")?{kind:"bytes",bytes:new Uint8Array(i),source:"clipboard"}:{kind:"text",text:i.toString("utf8")})}drop(t,e){let n=t.t??"";if(n==="m"){if(t.x==="-1"){this.offered=[];return}if(e){this.offered=e.split(" ").filter(Boolean);let a=$m.filter((c)=>this.offered.includes(c));this.send(`\x1B]72;t=m:o=${a.length>0?1:0};${a.join(" ")}\x1B\\`)}return}if(n==="M"){let a=e?e.split(" ").filter(Boolean):this.offered,c=sv(a,$m);if(!c){this.send("\x1B]72;t=r:o=0\x1B\\");return}this.dropping={mimes:a,index:a.indexOf(c)+1,chunks:[]},this.send(`\x1B]72;t=r:x=${this.dropping.index}\x1B\\`);return}let r=this.dropping;if(!r)return;if(n==="R"){this.dropping=void 0,this.send("\x1B]72;t=r:o=0\x1B\\"),this.deliver({kind:"error",message:`The drop failed: ${e.split(":")[0]||"unknown error"}`});return}if(n!=="r"&&n!=="")return;if(e)r.chunks.push(km(e));if(t.m==="1"||e)return;this.dropping=void 0;let i=Buffer.concat(r.chunks),s=r.mimes[r.index-1]??"",o;if(s.startsWith("image/"))o={kind:"bytes",bytes:new Uint8Array(i),source:"drop"};else{let a=i.toString("utf8"),c=s==="text/uri-list"?eo(a).find((u)=>eH(u)):void 0;o=c?{kind:"bytes",bytes:new Uint8Array(Zu(c)),source:c}:{kind:"text",text:a}}this.send("\x1B]72;t=r:o=1\x1B\\"),this.deliver(o)}}var Mm=5,gH=6,gv=0.05,bH=[1,2,3,4,5,6,9,10,11,12,13,14],bv=(t,e)=>(e-t+360)%360<=180?1:-1;function va(t,e,n){let r=e*Math.cos(n*Math.PI/180),i=e*Math.sin(n*Math.PI/180),s=[t+0.3963377774*r+0.2158037573*i,t-0.1055613458*r-0.0638541728*i,t-0.0894841775*r-1.291485548*i].map((l)=>l**3),[o,a,c]=s,u=[4.0767416621*o-3.3077115913*a+0.2309699292*c,-1.2684380046*o+2.6097574011*a-0.3413193965*c,-0.0041960863*o-0.7034186147*a+1.707614701*c];if(u.some((l)=>l<-0.0001||l>1.0001))return;return u.map((l)=>{let f=Math.min(1,Math.max(0,l));return Math.round(255*(f<=0.0031308?12.92*f:1.055*f**0.4166666666666667-0.055))})}function Om(t,e,n){if(va(t,n,e)!==void 0)return n;let r=0,i=n;for(let s=0;s<24;s++){let o=(r+i)/2;if(va(t,o,e)===void 0)i=o;else r=o}return r}function _e(t,e,n){return`#${(va(t,Om(t,n,e),n)??[0,0,0]).map((i)=>i.toString(16).padStart(2,"0")).join("")}`}function wH(t,e){let{l:n,c:r}=St(t);return _e(n,r,(e+360)%360)}function $H(t,e,n){let{l:r,c:i,h:s}=St(t),o=vt(e)<0.18,a=(l)=>_e(o?r+(1-r)*l:r*(1-l),i,s);if(wt(a(1),e)<n+gv)return a(1);let c=0,u=1;for(let l=0;l<30;l++){let f=(c+u)/2;if(wt(a(f),e)>=n+gv)u=f;else c=f}return a(u)}function kH(t,e){let{l:n,c:r,h:i}=St(t),s=0,o=n;for(let a=0;a<30;a++){let c=(s+o)/2;if(vt(_e(c,r,i))<=e-0.005)s=c;else o=c}return _e(s,r,i)}function yH(t,e,n){let r=be[e],[i,s]=[St(t[e]),St(t[e+8])],o=(l,f)=>n.has(l)?[f]:Array.from({length:2*r.width+1},(d,h)=>(r.center-r.width+h+360)%360),a=(l,f,d)=>er.every((h)=>{let m=(l>8?8:0)+h;if(m===l)return!0;let $=St(t[m]);return $.c<fo||Ae($.h,f)>=Qi+1||Math.abs($.l-d)>=Xi}),c,u=Number.POSITIVE_INFINITY;for(let l of o(e,i.h)){if(!n.has(e)&&!a(e,l,i.l))continue;for(let f of o(e+8,s.h)){if(Ae(l,f)>Ue-Mm||!n.has(e+8)&&!a(e+8,f,s.l))continue;let d=Ae(l,i.h)+Ae(f,s.h);if(d<u)u=d,c=[l,f]}}return c}class wv{theme;moves=[];constructor(t){this.theme={...t,ansi:[...t.ansi]}}set(t,e,n){let r=this.get(t);if(n===r)return;if(this.moves.push({slot:t,rule:e,from:r,to:n}),t==="foreground")this.theme.foreground=n;else if(t==="selection")this.theme.selectionBackground=n;else this.theme.ansi[Number(t.slice(4))]=n}get(t){if(t==="foreground")return this.theme.foreground;if(t==="selection")return this.theme.selectionBackground;return this.theme.ansi[Number(t.slice(4))]}rehue(t,e,n){this.set(`ansi${t}`,e,wH(this.theme.ansi[t],n))}roles(){let t=new Set(this.theme.signatureSlots);for(let{slot:n,hue:r}of nr(this.theme)){let i=be[sn(n)];this.rehue(n,"ansi-role",i.center+bv(i.center,r)*(i.width-Mm))}for(let{normal:n,gap:r}of Rn(this.theme)){if(r<=Ue)continue;let[i,s]=t.has(`ansi${n+8}`)?[n+8,n]:[n,n+8],o=St(this.theme.ansi[i]).h,a=St(this.theme.ansi[s]).h;this.rehue(s,"bright-follows",o+bv(o,a)*(Ue-Mm))}let e=ts(this.theme);for(let[n,r]of Nn(this.theme)){let i=sn(e.has(r)?n:r),s=yH(this.theme.ansi,i,e);if(s===void 0)continue;this.rehue(i,"distinct",s[0]),this.rehue(i+8,"distinct",s[1])}}readability(){let t=new Set(this.theme.waive),{background:e}=this.theme,n=(r,i,s,o=e)=>{if(t.has(r))return;for(let a of i)if(wt(this.get(a),o)<s)this.set(a,r,$H(this.get(a),o,s))};if(n("foreground",["foreground"],7),n("accents",bH.map((r)=>`ansi${r}`),3),n("light-ansi",["ansi7","ansi15"],7),n("ansi8-visible",["ansi8"],1.6),!t.has("ansi0-dark")&&vt(this.get("ansi0"))>0.15)this.set("ansi0","ansi0-dark",kH(this.get("ansi0"),0.15));n("selection",["selection"],7,this.theme.foreground)}net(){return[...new Set(this.moves.map((t)=>t.slot))].flatMap((t)=>{let e=this.moves.filter((i)=>i.slot===t),n=e[0].from,r=this.get(t);return n===r?[]:[{slot:t,rule:[...new Set(e.map((i)=>i.rule))].join(", "),from:n,to:r}]})}}function Xu(t){let e=new wv(t);for(let n=0;n<gH;n++)if(e.readability(),e.roles(),Qr(e.theme).length===0)break;return{theme:e.theme,moves:e.net(),left:Qr(e.theme)}}var ji=[{key:"background",label:"Background",min:0,max:0.5,step:0.01,digits:2},{key:"foreground",label:"Foreground",min:0.5,max:1,step:0.01,digits:2},{key:"hue",label:"Hue",min:0,max:360,step:1,digits:0,wraps:!0},{key:"tint",label:"Tint",min:0,max:0.1,step:0.005,digits:3},{key:"lightness",label:"Accent lightness",min:0.4,max:0.95,step:0.01,digits:2},{key:"chroma",label:"Accent chroma",min:0,max:0.3,step:0.005,digits:3},{key:"brights",label:"Brights",min:-0.2,max:0.2,step:0.01,digits:2}],Ea={background:0.21,foreground:0.88,hue:265,tint:0.02,lightness:0.72,chroma:0.12,brights:0.06},$v=(t,e,n)=>Math.min(n,Math.max(e,t));function xm(t,e,n){let r=t[e.key]+e.step*n,i=e.wraps?(r%e.max+e.max)%e.max:$v(r,e.min,e.max);return{...t,[e.key]:Math.round(i*1e4)/1e4}}function Wr(t){let e=(r,i,s)=>_e($v(r,0,1),i,s),n=Array.from({length:16},()=>"#000000");n[0]=e(t.background+0.06,t.tint,t.hue),n[8]=e(t.background+0.25,t.tint,t.hue),n[7]=e(t.foreground-0.06,t.tint/2,t.hue),n[15]=e(t.foreground+0.06,t.tint/2,t.hue);for(let r of er){let i=be[r].center;n[r]=e(t.lightness,t.chroma,i),n[r+8]=e(t.lightness+t.brights,t.chroma,i)}return{background:e(t.background,t.tint,t.hue),foreground:e(t.foreground,t.tint/2,t.hue),cursor:e(t.lightness+t.brights,Math.max(t.chroma,0.08),t.hue),selection:e(t.background+0.1,t.tint*2,t.hue),ansi:n}}var Ui=["background","foreground","cursor","selection",...Array.from({length:16},(t,e)=>`ansi${e}`)],j=["Background","Foreground","Cursor","Selection"],tl=["Black","Red","Green","Yellow","Blue","Magenta","Cyan","White"],Kr=j.length+tl.length,tn=[{key:"l",label:"Lightness",min:0,max:1,step:0.01,digits:2},{key:"c",label:"Chroma",min:0,max:0.37,step:0.005,digits:3},{key:"h",label:"Hue",min:0,max:360,step:1,digits:0,wraps:!0}],kv=5,Qn=tn.length,ro=["this","pair","normals","brights","accents"],el=[1,2,3,4,5,6,9,10,11,12,13,14],yv=el.filter((t)=>t<8).map((t)=>j.length+t),vv=el.filter((t)=>t>8).map((t)=>j.length+t);function Im(t,e){let n=e-j.length;if(n<0||t==="this")return[e];if(t==="pair")return[j.length+n%8,j.length+8+n%8];let r=t==="normals"?yv:t==="brights"?vv:[...yv,...vv];return r.includes(e)?r:[e]}function vH(){return Array.from({length:Kr},(t,e)=>e<j.length?[e]:[e,e+8]).flat()}function EH(t){let e=t.trim();return/^https?:\/\/\S+$/i.test(e)||eo(e).length>0}function no(t){return[t.background,t.foreground,t.cursor,t.selection,...t.ansi]}function se(t){let[e,n,r,i,...s]=t;return{background:e,foreground:n,cursor:r,selection:i,ansi:s}}function Gi(t){if(t<j.length)return{name:j[t],about:Ui[t]};let e=t-j.length,n=tl[e%8];return e<8?{name:n,about:`ansi ${e}`}:{name:`Bright ${n.toLowerCase()}`,about:`ansi ${e}`}}var io=(t,e,n)=>Math.min(n,Math.max(e,t));function Ev(t){return t.length===1?t.toLowerCase():t}function SH(t){return io(Math.round(t),0,255).toString(16).padStart(2,"0")}function Sv(t){let e=t.trim().toLowerCase(),n=/^#?([0-9a-f]{6}|[0-9a-f]{3})$/.exec(e);if(n){let s=n[1];return`#${s.length===3?[...s].map((o)=>o+o).join(""):s}`}let r=/^rgb\(\s*(\d+)[\s,]+(\d+)[\s,]+(\d+)\s*\)$/.exec(e);if(r)return`#${r.slice(1,4).map((s)=>SH(Number(s))).join("")}`;let i=/^oklch\(\s*([\d.]+)(%?)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:deg|°)?\s*\)$/.exec(e);if(i){let s=Number(i[1])/(i[2]?100:1);return _e(io(s,0,1),Number(i[3]),Number(i[4])%360)}return}function _i(t){let e=we.find((n)=>n.rule===t);return e?.min??e?.max??0}function Bi(t,e,n){let r=se(t);return{name:"draft",background:r.background,foreground:r.foreground,selectionBackground:r.selection,ansi:r.ansi,waive:n,signatureSlots:e}}function MH(t,e){let n=t-j.length,r=t<=1?"foreground":t===3?"selection":n===7||n===15?"light-ansi":n===8?"ansi8-visible":el.includes(n)?"accents":void 0;return{against:t===0||t===3?1:0,floor:r===void 0||e.includes(r)?void 0:_i(r)}}function Tm(t,e,n,r){let i=Bi(t,e,n),{background:s,foreground:o,selection:a,ansi:c}=se(t),u=(l,f,d)=>wt(f,d)<_i(r)?[l]:[];if(r==="foreground")return wt(o,s)<_i(r)?[1,0]:[];if(r==="selection")return wt(o,a)<_i(r)?[3,1]:[];if(r==="accents")return el.flatMap((l)=>u(j.length+l,c[l],s));if(r==="light-ansi")return[7,15].flatMap((l)=>u(j.length+l,c[l],s));if(r==="ansi8-visible")return u(j.length+8,c[8],s);if(r==="ansi0-dark")return vt(c[0])>_i(r)?[j.length]:[];if(r==="ansi-role")return nr(i).map(({slot:l})=>j.length+l);if(r==="bright-follows")return Rn(i).filter(({gap:l})=>l>Ue).flatMap(({normal:l})=>[j.length+l,j.length+l+8]);if(r==="distinct")return Nn(i).flatMap(([l,f])=>[j.length+l,j.length+f]);return[]}function OH(t,e,n){return new Set(Ui.flatMap((r,i)=>nl(t,e,n,i).some((s)=>s.ok===!1)?[i]:[]))}function Zn(t,e,n,r,i){let s=wt(t,e),o=_i(n);if(i.includes(n))return{ok:void 0,text:`${r} ${s.toFixed(2)}:1 · waived`};return{ok:s>=o,text:`${r} ${s.toFixed(2)}:1 · ≥ ${o}`}}function nl(t,e,n,r){let i=se(t),s=Bi(t,e,n);if(r===0){let b=[1,2,3,4,5,6,9,10,11,12,13,14].reduce((y,E)=>wt(i.ansi[y],i.background)<=wt(i.ansi[E],i.background)?y:E);return[Zn(i.foreground,i.background,"foreground","Foreground on it",n),Zn(i.ansi[b],i.background,"accents",`Weakest, ANSI ${b},`,n),Zn(i.ansi[8],i.background,"ansi8-visible","ANSI 8 on it",n)]}if(r===1)return[Zn(i.foreground,i.background,"foreground","On background",n),Zn(i.foreground,i.selection,"selection","On the selection",n)];if(r===2)return[{ok:void 0,text:`On background ${wt(i.cursor,i.background).toFixed(2)}:1`}];if(r===3)return[Zn(i.foreground,i.selection,"selection","Foreground on it",n)];let o=r-j.length,a=i.ansi[o];if(o===0){let g=vt(a),b=_i("ansi0-dark");return[n.includes("ansi0-dark")?{ok:void 0,text:`Luminance ${g.toFixed(3)} · waived`}:{ok:g<=b,text:`Luminance ${g.toFixed(3)} · ≤ ${b}`}]}if(o===7||o===15)return[Zn(a,i.background,"light-ansi","On background",n)];if(o===8)return[Zn(a,i.background,"ansi8-visible","On background",n)];let c=[Zn(a,i.background,"accents","On background",n)],u=St(a),l=sn(o),f=be[l],d=`${f.name} ${f.center}±${f.width}°`;if(u.c<fo)c.push({ok:void 0,text:"Too grey to have a hue"});else if(ts(s).has(o))c.push({ok:void 0,text:`Hue ${u.h.toFixed(0)}° · a signature, free of ${d}`});else if(n.includes("ansi-role"))c.push({ok:void 0,text:`Hue ${u.h.toFixed(0)}° · ${d} waived`});else{let g=Ae(u.h,f.center)-f.width;c.push(g>0?{ok:!1,text:`Hue ${u.h.toFixed(0)}° · ${g.toFixed(0)}° outside ${d}`}:{ok:!0,text:`Hue ${u.h.toFixed(0)}° · in ${d}`})}let h=o<8?o+8:o-8,m=Rn(s).find((g)=>g.normal===l);if(m)c.push(n.includes("bright-follows")?{ok:void 0,text:`${m.gap.toFixed(0)}° from ANSI ${h} · waived`}:{ok:m.gap<=Ue,text:`${m.gap.toFixed(0)}° from ANSI ${h} · ≤ ${Ue}°`});let $=Nn(s).flatMap(([g,b])=>g===o?[b]:b===o?[g]:[]);if($.length>0&&!n.includes("distinct"))c.push({ok:!1,text:`Reads as ANSI ${$.join(", ")} · within ${Qi}° and ${Xi} lightness`});return c}function Ov(t,e,n){let r=on(Bi(t,e,n));return we.map((i,s)=>{let o=r[s],a=n.includes(i.rule),c=a||Number.isNaN(o)?void 0:(i.min===void 0||o>=i.min)&&(i.max===void 0||o<=i.max);return{ok:c,label:i.label,value:Number.isNaN(o)?"—":Number.isInteger(o)?String(o):o.toFixed(2),bound:a?"waived":i.min!==void 0?`≥ ${i.min}`:i.max!==void 0?`≤ ${i.max}`:"",slots:c===!1?Tm(t,e,n,i.rule):[]}})}var xH=new Set(["reset","reset-all","hex","paste","fix","open","tune","sig","follow"]),xv=tn[1].max;function Rm(t){let[e,n,r]=rt(t);return e===n&&n===r}function Nm(t,e){return Math.floor(Om(t,e,xv)*1e4)/1e4}function Mv(t,e){let n=t.wraps?t.max-t.step:t.max;return Math.min(n,Math.round((t.min+(t.max-t.min)*e)/t.step)*t.step)}class Sa{mode;seeds=Ea;field=0;list;lch;start;original;signature;row=0;col=0;channel=0;scope="this";view="slot";scene=0;typing;overlay;quitting=!1;compare=!1;notice;filter="";pick=0;result;act;wants;pictures;startPictures;options;fresh;theme;startSignature;seeded=!1;tuneFrom;holds=new Map;clip;history=[];future=[];lastEdit;constructor(t){this.options=t,this.theme=t.variant==="theme",this.fresh=t.colors===void 0,this.mode=this.fresh?"seeds":"list",this.list=no(t.colors??Wr(this.seeds)),this.lch=this.lchs(),this.start=[...this.list],this.original=t.original?no(t.original):[...this.list],this.signature=[...t.signature],this.startSignature=[...t.signature],this.pictures=t.pictures??0,this.startPictures=this.pictures}markSaved(){this.start=[...this.list],this.history=[],this.future=[],this.lastEdit=void 0}offDefault(t){return this.list[t]!==this.original[t]}get added(){return Math.max(0,this.pictures-this.startPictures)}found(t){this.pictures=t.count,this.notice=t.note}get waive(){return this.options.waive??[]}get held(){return this.holds.get(this.slot())}colors(){return se(this.list)}edited(){return{colors:this.colors(),signature:[...this.signature]}}shown(){return this.compare?this.start:this.list}slot(){return this.row<j.length?this.row:this.row+(this.col===1?8:0)}dirty(){return this.seeded||this.pictures!==this.startPictures||this.list.some((t,e)=>t!==this.start[e])||this.signature.join()!==this.startSignature.join()}misses(){return OH(this.list,this.signature,this.waive)}failing(){return Qr(Bi(this.list,this.signature,this.waive))}choices(){let t=this.filter.toLowerCase();return(this.options.palettes??[]).filter((e)=>e.name.toLowerCase().includes(t))}paste(t){if(this.notice=void 0,this.overlay==="open"){this.filter+=t.replace(/\s+/g,"").toLowerCase(),this.pick=0;return}if(this.overlay)return;if(t.trim()===""){this.findPictures({clipboard:!0});return}if(EH(t)){this.findPictures({paste:t});return}if(this.mode==="seeds")return;let e=Sv(t);if(!e){this.notice="Not a color — #rrggbb, rgb(r g b) or oklch(l c h)";return}this.typing=void 0,this.take(e,"paste")}press(t){if(this.notice=void 0,t==="ctrl-c"){if(this.theme)this.act="cancel";else this.result="cancelled";return}if(this.quitting){if(this.quitting=!1,t==="y"||t==="Y")this.result="cancelled";return}if(this.typing!==void 0){this.type(t);return}if(this.overlay==="keys"){this.overlay=void 0;return}if(this.overlay==="open"){this.openKey(t);return}if(t==="?"){this.overlay="keys";return}if(this.theme&&(t==="ctrl-v"||t==="alt-v"||t==="p"))return;if(t==="ctrl-v"||t==="alt-v"){this.findPictures({clipboard:!0});return}if(t==="p"&&this.mode!=="tune"){this.findPictures();return}if(t===" "&&this.mode!=="seeds"){this.compare=!this.compare;return}if(this.compare&&t==="esc"){this.compare=!1;return}if(t==="g"&&this.mode!=="seeds"){this.view=this.view==="slot"?"relations":"slot";return}let e=t==="j"?"down":t==="k"?"up":t;if(this.mode==="seeds")this.seedKey(e);else if(this.mode==="tune")this.tuneKey(e);else this.listKey(e)}select(t){if(this.mode==="seeds"||this.typing!==void 0||this.overlay||this.quitting)return;if(this.mode==="tune"){if(t===this.slot())return;this.tuneKey("enter")}if(this.notice=void 0,this.row=t<j.length?t:j.length+(t-j.length)%8,t>=j.length)this.col=t-j.length>=8?1:0;this.lastEdit=void 0}grip(t){if(this.mode==="seeds"||this.typing!==void 0||this.overlay||this.quitting)return!1;if(this.notice=void 0,this.mode==="list")this.tune();return this.channel=t,!0}slide(t,e){if(!this.grip(t))return;let n=Math.min(1,Math.max(0,e));if(t===Qn){this.reach(21**n);return}this.put(Mv(tn[t],n))}sow(t,e){let n=ji[t];if(this.mode!=="seeds"||this.overlay||this.quitting||!n)return;this.notice=void 0,this.field=t;let r=Math.min(1,Math.max(0,e));this.seeds=xm({...this.seeds,[n.key]:Mv(n,r)},n,0),this.list=no(Wr(this.seeds)),this.lch=this.lchs()}scroll(t){let e=(n,r)=>Math.min(r,Math.max(0,n+t));if(this.overlay==="open")this.pick=e(this.pick,Math.max(0,this.choices().length-1));else if(this.overlay||this.quitting||this.typing!==void 0)return;else if(this.mode==="seeds")this.field=e(this.field,ji.length-1);else if(this.mode==="tune")this.channel=e(this.channel,Qn);else this.row=e(this.row,Kr-1),this.lastEdit=void 0}lchOf(t){let e=St(t);return Rm(t)?{...e,h:this.neutralHue()}:e}lchs(){return this.list.map((t)=>this.lchOf(t))}neutralHue(){let t=[0,1,3,2].map((e)=>this.list[e]).find((e)=>!Rm(e));return t?St(t).h:Ea.hue}seedKey(t){let e=ji.length;if(t==="up"||t==="down")this.field=(this.field+(t==="up"?e-1:1))%e;else if(t==="home"||t==="end")this.field=t==="home"?0:e-1;else if(t==="left"||t==="right"||t==="shift-left"||t==="shift-right"){let n=ji[this.field],r=(t.endsWith("left")?-1:1)*(t.startsWith("shift")?n.wraps?10:kv:1);this.seeds=xm(this.seeds,n,r),this.list=no(Wr(this.seeds)),this.lch=this.lchs()}else if(t==="enter")this.leaveSeeds();else if(t==="o")this.openPalettes();else if(t==="esc")this.leave()}leaveSeeds(){this.start=[...this.list],this.original=[...this.list],this.seeded=!0,this.mode="list"}leave(){if(this.theme)this.act="cancel";else if(this.dirty())this.quitting=!0;else this.result="cancelled"}findPictures(t){if(!this.options.find){this.notice="Pictures need Ghostty, iTerm2 or kitty, outside tmux";return}this.wants=t?{start:t}:{}}openPalettes(){if((this.options.palettes??[]).length>0)this.overlay="open",this.pick=0;else this.notice="No other palettes to take colors from"}listKey(t){if(t==="up"||t==="down"){if(this.theme&&this.row===(t==="up"?0:Kr-1))this.act=t==="up"?"above":"below";else this.row=(this.row+(t==="up"?Kr-1:1))%Kr;this.lastEdit=void 0}else if(t==="home"||t==="end")this.row=t==="home"?0:Kr-1;else if(t==="pgup"||t==="pgdn")this.row=t==="pgup"?0:j.length;else if(t==="left"||t==="right"){if(this.row>=j.length)this.col=t==="left"?0:1,this.lastEdit=void 0}else if((t==="shift-left"||t==="shift-right")&&!this.theme)this.scene+=t==="shift-left"?-1:1;else if(t==="n"||t==="N")this.nextMiss(t==="n"?1:-1);else if(t==="enter"||t==="tab")this.tune();else if(t==="#")this.typing="";else if(t==="c")this.clip=this.list[this.slot()],this.notice=`Copied ${this.clip}`;else if(t==="v")if(this.clip)this.set(this.slot(),this.clip,"paste");else this.notice="Nothing copied yet — c copies a slot";else if(t==="r")this.set(this.slot(),this.original[this.slot()],"reset");else if(t==="R")this.remember("reset-all"),this.list=[...this.original],this.lch=this.lchs();else if(t==="=")this.follow();else if(t==="*"&&!this.theme)this.mark();else if(t==="f")this.fix();else if(t==="o"&&!this.theme)this.openPalettes();else if(t==="u")this.undo();else if(t==="ctrl-r")this.redo();else if(t==="s"||t==="ctrl-s")if(this.theme)this.act="save";else this.save();else if(t==="esc")this.leave()}nextMiss(t){let e=vH(),n=this.misses();if(n.size===0){this.notice="The gate passes";return}let r=e.indexOf(this.slot());for(let i=1;i<=e.length;i++){let s=e[((r+t*i)%e.length+e.length)%e.length];if(n.has(s)){if(this.row=s<j.length?s:j.length+(s-j.length)%8,s>=j.length)this.col=s-j.length>=8?1:0;return}}}tune(){this.remember("tune"),this.tuneFrom={list:[...this.list],lch:[...this.lch]},this.holds=new Map,this.hold(),this.mode="tune"}hold(){for(let t of this.scoped())if(!this.holds.has(t))this.holds.set(t,this.lch[t].c)}scoped(){return Im(this.scope,this.slot())}tuneKey(t){let e=tn.length+1,n=this.channel===Qn;if(t==="up"||t==="down"||t==="tab"||t==="shift-tab")this.channel=(this.channel+(t==="up"||t==="shift-tab"?e-1:1))%e;else if(t==="left"||t==="right"||t==="shift-left"||t==="shift-right"){let r=t.endsWith("left")?-1:1;if(n)this.reach(this.ratio()+r*(t.startsWith("shift")?0.5:0.1));else{let i=tn[this.channel];this.step(r*(t.startsWith("shift")?i.wraps?10:kv:1))}}else if(t==="home"||t==="end")if(n)this.reach(t==="home"?this.partner().floor??1:21);else{let r=tn[this.channel];this.put(t==="home"?r.min:r.wraps?r.max-r.step:r.max)}else if(/^[0-9]$/.test(t))if(n){if(t!=="0")this.reach(Number(t))}else{let r=tn[this.channel];this.put(r.min+(r.max-r.min)*Number(t)/10)}else if(t==="a")this.rescope();else if(t==="#")this.typing="";else if(t==="enter"){if(this.tuneFrom&&this.list.every((r,i)=>r===this.tuneFrom?.list[i]))this.history.pop();this.endTune()}else if(t==="esc"){if(this.tuneFrom)this.list=[...this.tuneFrom.list],this.lch=[...this.tuneFrom.lch],this.history.pop();this.endTune()}}rescope(){if(this.slot()<j.length){this.notice="A base color moves alone";return}let t=ro.indexOf(this.scope);for(let e=1;e<=ro.length;e++){let n=ro[(t+e)%ro.length];if(n==="this"||Im(n,this.slot()).length>1){this.scopeTo(n);return}}}scopeTo(t){if(this.mode!=="tune"||this.typing!==void 0||this.quitting||this.slot()<j.length)return;if(t!=="this"&&Im(t,this.slot()).length<=1)return;this.scope=t,this.hold();let e=this.scoped().length;this.notice=e>1?`${e} slots move together`:"This slot moves alone"}endTune(){this.tuneFrom=void 0,this.holds=new Map,this.mode="list"}partner(){return MH(this.slot(),this.waive)}ratio(){return wt(this.list[this.slot()],this.list[this.partner().against])}reach(t){let e=this.slot(),n=this.list[this.partner().against],r=this.lch[e],i=this.holds.get(e)??r.c,s=(d)=>_e(d,Math.min(i,Nm(d,r.h)),r.h),o=(d)=>wt(s(d),n),a=vt(this.list[e])>=vt(n),c=St(n).l,u=Math.max(1,Math.round(t*100)/100),l=a?1:0,f;if(o(l)<u)f=l,this.notice=`The ratio stops at ${o(l).toFixed(2)}:1 on this side of the color it is read against`;else{let d=c,h=l;for(let m=0;m<24;m++){let $=(d+h)/2;if(o($)>=u)h=$;else d=$}f=h}this.place(e,f,i,r.h);for(let d=0;d<40&&f!==l&&wt(this.list[e],n)<u;d++)f=a?Math.min(1,f+0.001):Math.max(0,f-0.001),this.place(e,f,i,r.h);this.lch[e]={...this.lch[e],l:Math.round(f*1e4)/1e4}}step(t){let e=tn[this.channel],n=this.lch[this.slot()][e.key];this.put(n+e.step*t)}put(t){let e=this.slot(),n=tn[this.channel],r=n.wraps?(t%n.max+n.max)%n.max:io(t,n.min,n.max),i=Math.round(r*1e4)/1e4,s=this.lch[e],o=this.scoped().filter((u)=>u!==e),a=(u)=>Math.round(u*1e4)/1e4;if(n.key==="c"){let u=Nm(s.l,s.h);if(i>u)this.notice=`Chroma stops at ${u.toFixed(3)}, the sRGB edge for this lightness and hue`;let l=Math.min(i,u),f=l-s.c;this.holds.set(e,l),this.place(e,s.l,l,s.h);for(let d of o){let h=this.lch[d],m=a(io((this.holds.get(d)??h.c)+f,0,xv));this.holds.set(d,m),this.place(d,h.l,m,h.h)}return}let c=n.key==="h"?((i-s.h)%360+540)%360-180:i-s.l;if(this.place(e,n.key==="l"?i:s.l,this.holds.get(e)??s.c,n.key==="h"?i:s.h),n.key==="h"&&Rm(this.list[e]))this.notice="A grey shows no hue — raise its chroma first";for(let u of o){let l=this.lch[u];this.place(u,n.key==="l"?a(io(l.l+c,0,1)):l.l,this.holds.get(u)??l.c,n.key==="h"?a(((l.h+c)%360+360)%360):l.h)}}place(t,e,n,r){let i=Math.min(n,Nm(e,r));this.lch[t]={l:e,c:i,h:r},this.list[t]=_e(e,i,r)}take(t,e){if(this.mode==="tune")this.list[this.slot()]=t,this.lch[this.slot()]=this.lchOf(t),this.holds.set(this.slot(),this.lch[this.slot()].c);else this.set(this.slot(),t,e)}type(t){let e=this.typing??"";if(t==="esc")this.typing=void 0;else if(t==="enter"){let n=Sv(e);if(!n){this.notice="Not a color — #rrggbb, rgb(r g b) or oklch(l c h)";return}this.typing=void 0,this.take(n,"hex")}else{let n=Pi(e,Ev(t),(r)=>/^[0-9a-z#(),.% ]$/.test(r)&&e.length<28);if(n!==void 0)this.typing=n}}openKey(t){let e=this.choices();if(t==="esc")this.overlay=void 0,this.filter="";else if(t==="up"||t==="down"){let n=Math.max(1,e.length);this.pick=(this.pick+(t==="up"?n-1:1))%n}else if(t==="home"||t==="end")this.pick=t==="home"?0:Math.max(0,e.length-1);else if(t==="enter"){let n=e[this.pick];if(!n)return;if(this.remember("open"),this.list=no(n.colors),this.lch=this.lchs(),this.overlay=void 0,this.filter="",this.notice=`Took the colors of ${n.name}`,this.mode==="seeds")this.leaveSeeds()}else{let n=Pi(this.filter,Ev(t),(r)=>/^[a-z0-9@/-]$/.test(r));if(n!==void 0)this.filter=n,this.pick=0}}remember(t){if(t!==this.lastEdit||xH.has(t))this.history.push({list:[...this.list],lch:[...this.lch],signature:[...this.signature]}),this.future=[];this.lastEdit=t}set(t,e,n){if(!oe(e)||this.list[t]===e)return;this.remember(n),this.list[t]=e,this.lch[t]=this.lchOf(e)}follow(){if(this.row<j.length){this.notice="= works on an ANSI row — the bright takes its normal";return}let t=this.row,e=this.row+8,n=this.lch[t];this.remember("follow"),this.place(e,io(n.l+0.06,0,1),n.c,n.h),this.col=1,this.notice=`${Gi(e).name} follows ${Gi(t).name.toLowerCase()}`}mark(){let t=Ui[this.slot()];this.remember("sig");let e=this.signature.includes(t)?this.signature.filter((r)=>r!==t):[...this.signature,t],n=e.length>3?e[0]:void 0;this.signature=e.slice(-3),this.notice=this.signature.length===3?`Signature: ${this.signature.join(", ")}${n?` — ${n} dropped`:""}`:`The signature needs three slots — ${this.signature.length} marked`}fix(){let t=Bi(this.list,this.signature,this.waive),{theme:e,moves:n,left:r}=Xu({...t,selectionBackground:t.selectionBackground,signatureSlots:this.signature});if(n.length===0){this.notice=Qr(t).length===0?"Already passes the gate":"No color change fixes it";return}this.remember("fix");let i=no({...this.colors(),foreground:e.foreground,selection:e.selectionBackground,ansi:e.ansi}),s=this.list;this.list=i,this.lch=i.map((o,a)=>o===s[a]?this.lch[a]:this.lchOf(o)),this.notice=`Moved ${n.length} ${n.length===1?"color":"colors"}${r.length===0?" — passes the gate":" closer to the gate"}`}save(){let t=this.options.check(this.edited());if(t){this.notice=t;return}this.result="saved"}undo(){let t=this.history.pop();if(!t){this.notice="Nothing to undo";return}this.future.push({list:[...this.list],lch:[...this.lch],signature:[...this.signature]}),this.restore(t)}redo(){let t=this.future.pop();if(!t){this.notice="Nothing to redo";return}this.history.push({list:[...this.list],lch:[...this.lch],signature:[...this.signature]}),this.restore(t)}restore(t){this.list=[...t.list],this.lch=[...t.lch],this.signature=[...t.signature],this.lastEdit=void 0}}import{mkdirSync as _H,readFileSync as Hm,writeFileSync as Fv}from"node:fs";import{dirname as GH}from"node:path";import{isMainThread as BH,parentPort as Cv,Worker as UH}from"node:worker_threads";var IH=new Set(["comic","4koma","monochrome","greyscale","sketch","lineart","speech_bubble"]),RH=new Set(["scenery","landscape","scenic","no_humans","wide_shot","very_wide_shot"]),NH=0.04,TH=0.1,AH=0.05,PH=4096;function HH(t){return new Set(t.cutouts.split(/\s+/).map((e)=>e.replace(/^~/,"")).filter(Boolean))}function FH(t,e,n,r=0){let{site:i,post:s}=t,o=new Set(s.tags),a=[...HH(i)].some((l)=>o.has(l)),c=Math.min(s.width,s.height),u=s.width>0&&s.height>0?s.width/s.height/(e.w/e.h):1;return(s.solo?2:0)+([...IH].some((l)=>o.has(l))?-3:0)+([...RH].some((l)=>o.has(l))?-1.5:0)+2*Math.min(1,c/e.h)+(a?1.5:-Math.min(1.5,Math.abs(Math.log(u))))+(n>0?1.5*Math.log1p(Math.max(0,s.score))/Math.log1p(n):0)+2*r}function rl(t,e,n=new Map){let r=new Map;for(let{site:i,post:s}of t)r.set(i,Math.max(r.get(i)??0,s.score));return t.map((i,s)=>({pick:i,at:s,score:FH(i,e,r.get(i.site)??0,n.get(i.post))})).sort((i,s)=>s.score-i.score||i.at-s.at).map(({pick:i})=>i)}function Rv(t){let e=new Map;for(let r of t)e.set(r.site,[...e.get(r.site)??[],r]);let n=[];for(let r=0;n.length<t.length;r++)for(let i of e.values()){let s=i[r];if(s)n.push(s)}return n}function Am(t){let e=t/255;return e<=0.04045?e/12.92:((e+0.055)/1.055)**2.4}function Iv(t,e,n){let[r,i,s]=[Am(t),Am(e),Am(n)],o=Math.cbrt(0.4122214708*r+0.5363325363*i+0.0514459929*s),a=Math.cbrt(0.2119034982*r+0.6806995451*i+0.1073969566*s),c=Math.cbrt(0.0883024619*r+0.2817188376*i+0.6299787005*s);return[0.2104542553*o+0.793617785*a-0.0040720468*c,1.9779984951*o-2.428592205*a+0.4505937099*c,0.0259040371*o+0.7827717662*a-0.808675766*c]}function Nv(t,e){let n=e.map((o)=>Iv(...rt(o))).filter(([,o,a])=>Math.hypot(o,a)>=NH);if(n.length===0)return 0;let r=Math.max(1,Math.floor(Math.sqrt(t.width*t.height/PH))),i=n.map(()=>0),s=0;for(let o=0;o<t.height;o+=r)for(let a=0;a<t.width;a+=r){let c=(o*t.width+a)*4;if(t.data[c+3]<128)continue;s++;let[u,l,f]=Iv(t.data[c],t.data[c+1],t.data[c+2]);n.forEach(([d,h,m],$)=>{if(Math.hypot(u-d,l-h,f-m)<TH)i[$]=i[$]+1})}if(s===0)return 0;return i.reduce((o,a)=>o+Math.min(1,a/s/AH),0)/n.length}var CH=/(?:^|[^0-9a-f])([0-9a-f]{32})(?:[^0-9a-f]|$)/i,LH=[[/yande\.re\/post\/show\/(\d+)/,"yande"],[/konachan\.(?:com|net)\/post\/show\/(\d+)/,"konachan"],[/danbooru\.donmai\.us\/(?:posts|post\/show)\/(\d+)/,"danbooru"],[/zerochan\.net\/(\d+)(?:[?#\s]|$)/,"zerochan"]];function Pm(t){let e=/(\d+)_p(\d+)/.exec(t.source);return[...t.md5?[`md5:${t.md5}`]:[],...e&&t.source.includes("pximg")?[`pixiv:${e[1]}_p${e[2]}`]:[]]}function Tv(t,e){let n=CH.exec(e.source)?.[1]?.toLowerCase();return[`post:${t.key}:${e.id}`,...e.md5?[`md5:${e.md5}`]:[],...n&&n!==e.md5?[`md5:${n}`]:[],...LH.flatMap(([r,i])=>{let s=r.exec(e.source)?.[1];return s?[`post:${i}:${Number(s)}`]:[]}),...e.family?[`family:${t.key}:${e.family}`]:[]]}function Av(t,e){let n=t.owner||t.named.artist[0]||"";return n!==""&&n===(e.owner||e.named.artist[0]||"")&&t.width===e.width&&t.height===e.height}function Pv(t){let r=[];for(let s=0;s<8;s++){let o=Math.floor(s*t.height/8),a=Math.max(o+1,Math.floor((s+1)*t.height/8));for(let c=0;c<9;c++){let u=Math.floor(c*t.width/9),l=Math.max(u+1,Math.floor((c+1)*t.width/9)),f=0;for(let d=o;d<a;d++)for(let h=u;h<l;h++){let m=(d*t.width+h)*4,$=t.data[m+3]/255,g=0.299*t.data[m]+0.587*t.data[m+1]+0.114*t.data[m+2];f+=g*$+255*(1-$)}r.push(f/((l-u)*(a-o)))}}let i=0n;for(let s=0;s<8;s++)for(let o=0;o<8;o++)i=i<<1n|(r[s*9+o]>r[s*9+o+1]?1n:0n);return i.toString(16).padStart(16,"0")}function jH(t,e){let n=BigInt(`0x${t}`)^BigInt(`0x${e}`),r=0;while(n>0n)r+=Number(n&1n),n>>=1n;return r}function Hv(t,e){if(t.width<=0||t.height<=0||e.width<=0||e.height<=0)return!1;return Math.abs(Math.log(t.width/t.height/(e.width/e.height)))<0.01&&jH(t.hash,e.hash)<=2}var WH={thumb:"tile",band:"band",match:"tile",show:"view",backdrop:"view",redraw:"view"},il;async function KH(t){if(t.job==="redraw")return Tu(t.home,t.name,t.key,t.paint,t.blur,t.aligns,t.user);if(t.job==="show"){if(il?.from!==t.from){let o=or(new Uint8Array(Hm(t.from)),$e);il={from:t.from,clear:Tn(o),inked:Lf(o)}}let{image:r,fill:i,opacity:s}=$w(il.inked,t.colors,t.tone,t.width,t.height,t.blur,t.tune,t.coloring);return _H(GH(t.to),{recursive:!0}),Fv(t.to,ln(r)),{clear:il.clear,fill:i,opacity:s}}let e=or(new Uint8Array(Hm(t.from)),$e);if(t.job==="backdrop"){fc(t.home,t.colors,t.tone,e,{...t.origin,bytes:new Uint8Array(Hm(t.source)),cut:t.from!==t.source},t,t.blur,t.coloring);let r=t.tune&&ce(t.home,t.colors.name).find((i)=>i.key===te(t.origin));if(t.tune&&r)Ao(q(t.home),r,t.tune,t.aligns??!0,t.user??t.home);return 0}if(t.job==="match")return{match:Nv(e,t.colors),hash:Pv(e)};if(t.job==="thumb")return P(t.to,ln(sb(e,t.width,t.height))),0;let n=e.data.subarray(t.y*e.width*4,(t.y+t.height)*e.width*4);return Fv(t.to,ln({width:e.width,height:t.height,data:n})),0}function zH(t){t.on("message",async(e)=>{try{t.postMessage({id:e.id,value:await KH(e)})}catch(n){t.postMessage({id:e.id,error:n instanceof Error?n.message:String(n)})}})}class Fm{worker;next=1;waiting=new Map;send(t){let e=this.next++;return new Promise((n,r)=>{let i=this.open();this.waiting.set(e,{ok:n,no:r}),i.ref(),i.postMessage({...t,id:e})})}close(){this.worker?.terminate(),this.worker=void 0,this.drop(Error("renderer closed"))}open(){if(this.worker)return this.worker;let t=new UH(import.meta.filename);t.unref(),t.on("message",({id:n,value:r,error:i})=>{let s=this.waiting.get(n);if(this.waiting.delete(n),this.waiting.size===0)t.unref();if(i!==void 0)s?.no(Error(i));else s?.ok(r)});let e=(n)=>{if(this.worker===t)this.worker=void 0;this.drop(n instanceof Error?n:Error("renderer stopped"))};return t.on("error",e),t.on("exit",()=>e(void 0)),this.worker=t,t}drop(t){for(let e of this.waiting.values())e.no(t);this.waiting.clear()}}class Ma{lines=new Map;run(t){let e=WH[t.job],n=this.lines.get(e);if(!n)n=new Fm,this.lines.set(e,n);return n.send(t)}close(){for(let t of this.lines.values())t.close();this.lines.clear()}}class Cm{lines;constructor(t){this.lines=Array.from({length:Math.max(1,t)},()=>new Fm)}async map(t){let e=[],n=0;return await Promise.all(this.lines.map(async(r)=>{while(n<t.length){let i=n++;try{e[i]=await r.send(t[i])}catch(s){e[i]=s instanceof Error?s:Error(String(s))}}})),e}close(){for(let t of this.lines)t.close()}}if(!BH&&Cv)zH(Cv);import{existsSync as DH,mkdtempSync as qH,readFileSync as YH,rmSync as Lv,writeFileSync as JH}from"node:fs";import{tmpdir as VH}from"node:os";import{basename as _v,join as jv}from"node:path";var ZH=6;class Oa{dir;made=[];of(t,e){this.dir??=qH(jv(VH(),"ttheme-tint-"));let n=jv(this.dir,`${_v(t,".png")}.${e.slice(1).toLowerCase()}.png`);if(!DH(n)){let r=new Uint8Array(YH(t));JH(n,za(r,e)??ri(ni(Ht(r)),e)),this.made.push(n);while(this.made.length>ZH)Lv(this.made.shift(),{force:!0})}return n}clear(){if(this.dir)Lv(this.dir,{recursive:!0,force:!0});this.dir=void 0,this.made.length=0}}function sl(t,e,n,r,i){if(Ee(t)==="original")return{image:e,opacity:t.peak?ps(n,t.peak):t.opacity};let s=hn(n,[...r]);return{image:s.color===t.tone?e:i.of(e,s.color),opacity:s.opacity}}function ol(t,e){let n=_v(e);return t.find((r)=>n.startsWith(`${r.stem}.`)||n.startsWith(`${r.stem}@`))}var iF=2147483625,Uv=2147483626,vn=2147483627,sF=-1073741827,Wv=-1073741826,oF=-1073741825,aF=4;function cF(t,e,n,r,i,s){let o=Math.trunc,a=n*i.w,c=r*i.h,u=o((Math.max(s.x,0)+i.w-1)/i.w),l=o(Math.min(s.x+s.w,a)/i.w),f=o((Math.max(s.y,0)+i.h-1)/i.h),d=o(Math.min(s.y+s.h,c)/i.h);if(l<=u||d<=f)return;return{col:u,row:f,cols:l-u,rows:d-f,x:o((u*i.w-s.x)*t/s.w),y:o((f*i.h-s.y)*e/s.h),w:o((l-u)*i.w*t/s.w),h:o((d-f)*i.h*e/s.h)}}function uF(t){try{let e=tF(t,"r"),n=Buffer.alloc(24);return eF(e,n,0,24,0),QH(e),n.readUInt32BE(0)===2303741511?{width:n.readUInt32BE(16),height:n.readUInt32BE(20)}:void 0}catch{return}}class al{ready=()=>{};cell={w:0,h:0};held;tints=new Oa;sent=new Map;placed=new Map;viewed="";renders;scratch;made=0;bands=new Map;home;name;views;banded;files;static of(t,e,n,r){if(Lt(t)||!Vc(t,r)||!(Xc(t)||$i(t)))return;return new al(t,e,n)}constructor(t,e,n){this.home=e,this.name=n,this.views=$i(t),this.banded=Zc(t),this.files=Qc(t)}measured(t){if(this.cell.w===0&&t.w>0&&t.h>0)this.cell=t}load(){let t=q(this.home),e=Se(t,this.name,nF()),n=[];try{n=kt(t).palettes[this.name]?.pictures??[]}catch{}let r=e?ol(n,e.image):void 0;this.held=e&&r?{picture:r,image:e.image,opacity:e.opacity,cover:e.cover,at:Ut.indexOf(e.position)+1||5}:void 0}draw(t,e,n,r,i){if(this.cell.w===0)return"";let s=t[0],o=this.look(t,e,n,r,i);if(this.views){let c=r*this.cell.w,u=i*this.cell.h,l=o?`${s}|${o.image}|${o.opacity}|${c}|${u}|${o.box.w}|${o.box.h}|${o.box.x}|${o.box.y}|${this.held?.at??5}`:`${s}||1|${c}|${u}|0|0|0|0|5`;if(l===this.viewed)return"";return this.viewed=l,ki(l)}let a=this.layer(iF,sF,"f=24",Buffer.from(rt(s)),r,i);if(o){let c=Math.max(0,Math.min(255,Math.round((1-o.opacity)*255)));a+=this.picture(o),a+=this.layer(Uv,oF,"f=32",Buffer.from([...rt(s),c]),r,i)}else a+=this.drop(vn)+this.drop(Uv);return a}resized(){this.sent.clear(),this.placed.clear(),this.viewed=""}clear(){let t=this.views&&this.viewed?ki(""):"";for(let e of this.sent.keys())t+=ka(e);return this.resized(),t}close(){let t=this.clear();if(this.tints.clear(),this.renders?.close(),this.scratch)Gv(this.scratch,{recursive:!0,force:!0});return t}look(t,e,n,r,i){let s=this.held;if(!s)return;let o={name:this.name,...se([...t]),waived:[...n]},a=sl(s.picture,s.image,o,e,this.tints),c=uF(a.image);if(!c)return;let u=ws(c.width,c.height,r*this.cell.w,i*this.cell.h,100,s.at,s.cover),l=cF(c.width,c.height,r,i,this.cell,u);if(!l)return;return{image:a.image,opacity:s.opacity===s.picture.opacity?a.opacity:s.opacity,...c,box:u,rect:l}}layer(t,e,n,r,i,s){let o=r.toString("base64"),a=`${o}|${i}|${s}`;if(this.placed.get(t)===a)return"";return this.sent.set(t,a),this.placed.set(t,a),`\x1B_Ga=t,${n},s=1,v=1,i=${t},q=2;${o}\x1B\\\x1B[H\x1B_Ga=p,i=${t},p=${t},c=${i},r=${s},C=1,z=${e},q=2\x1B\\`}picture(t){let{image:e,rect:n}=t;if(this.banded&&(2*n.y+n.h-t.height)**2>1){let s=this.band(t.image,n.y,n.h);if(!s.ready)return"";e=s.path,n={...n,y:0}}let r="";if(this.sent.get(vn)!==e){let s=Du({id:vn,path:e,row:0,col:0,cols:0,rows:0,z:Wv},this.files);if(s===void 0)return"";r+=s,this.sent.set(vn,e),this.placed.delete(vn)}let i=`${n.col};${n.row};${n.cols};${n.rows};${n.x};${n.y};${n.w};${n.h}`;if(this.placed.get(vn)!==i)r+=`\x1B[${n.row+1};${n.col+1}H\x1B_Ga=p,i=${vn},p=${vn},x=${n.x},y=${n.y},w=${n.w},h=${n.h},c=${n.cols},r=${n.rows},C=1,z=${Wv},q=2\x1B\\`,this.placed.set(vn,i);return r}drop(t){if(!this.sent.has(t))return"";return this.sent.delete(t),this.placed.delete(t),ka(t)}band(t,e,n){let r=`${t}|${e}|${n}`,i=this.bands.get(r);if(i)return i;this.scratch??=XH(Bv(rF(),"ttheme-edit-")),this.renders??=new Ma;let s={path:Bv(this.scratch,`band-${++this.made}.png`),ready:!1};this.bands.set(r,s),this.renders.run({job:"band",from:t,to:s.path,y:e,height:n}).then(()=>{s.ready=!0,this.ready()}).catch(()=>{});for(let[o,a]of this.bands){if(this.bands.size<=aF)break;if(a.ready&&a.path!==this.sent.get(vn))this.bands.delete(o),Gv(a.path,{force:!0})}return s}}var Kv=80,zv=24,xa=50,Lm=11;function _t(t,e){return le(t,e)}function Jv(t){return{color:t,dim:(e)=>t?`${A}${e}${ge}`:e,bold:(e)=>t?`${at}${e}${ge}`:e,fg:(e)=>t?Be(e):"",bg:(e)=>t?`\x1B[48;2;${rt(e).join(";")}m`:""}}function Dv(t){return vt(t)>0.35?"#000000":"#ffffff"}function Vv(t,e,n,r,i){let s=e.length-1,o=Math.max(0,Math.min(s,n)),a=i===void 0?-1:Math.max(0,Math.min(s,i));if(!t.color)return e.map((c,u)=>u===o?"●":u===a?"○":r?"━":"─").join("");return e.map((c,u)=>{let l=c??"#000000";if(u===o)return`${t.bg(l)}${t.fg(Dv(l))}●\x1B[39;49m`;if(u===a)return c?`${t.bg(c)}${t.fg(Dv(c))}○\x1B[39;49m`:`${t.fg("#aaaaaa")}○`;return c?`${t.fg(c)}█`:`${t.fg(r?"#777777":"#555555")}░`}).join("").concat("\x1B[39m")}function lF(t,e,n){return Array.from({length:n},(r,i)=>{let s=e.min+(e.max-e.min)*i/(n-1),o={...t,[e.key]:s};return va(o.l,o.c,o.h)?_e(o.l,o.c,o.h):void 0})}function jm(t,e,n,r){return Math.round((t-e)/(n-e)*(r-1))}function Zv(t,e){return t.held!==void 0&&t.held-e.c>0.0005?t.held:void 0}function Qv(t,e,n,r){let i=Zv(e,n);return tn.map((s,o)=>{let a=e.mode==="tune"&&o===e.channel,c=n[s.key],u=`${c.toFixed(s.digits)}${s.wraps?"°":""}`.padStart(6),l=Vv(t,lF(n,s,r),jm(c,s.min,s.max,r),a,s.key==="c"&&i!==void 0?jm(i,s.min,s.max,r):void 0),f=s.key.toUpperCase(),d={kind:"channel",channel:o};return`${_t(d,a?t.bold(`▸${f}`):t.dim(` ${f}`))} ${_t({kind:"bar",channel:o},l)} ${_t(d,a?t.bold(u):t.dim(u))}`})}function Xv(t,e,n){let r=e.mode==="tune"&&e.channel===Qn,i=e.ratio(),{floor:s}=e.partner(),o=(h)=>Math.round(Math.log(Math.max(1,h))/Math.log(21)*(n-1)),a=o(i),c=s===void 0?-1:o(s),u=r?"━":"─",l=Array.from({length:n},(h,m)=>m===a?t.bold("●"):m===c?"┃":m<c?t.dim(u):u).join(""),f=`${i.toFixed(2)}:1`.padStart(6),d={kind:"channel",channel:Qn};return`${_t(d,r?t.bold("▸◐"):t.dim(" ◐"))} ${_t({kind:"bar",channel:Qn},l)} ${_t(d,r?t.bold(f):t.dim(f))}`}function t1(t,e){if(e.mode!=="tune"||e.slot()<j.length)return[];let n=se(e.list),r=ro.map((s)=>_t({kind:"scope",scope:s},s!==e.scope?t.dim(s):t.color?`${t.bg(n.selection)}${t.fg(n.foreground)} ${s} \x1B[39;49m`:`[${s}]`)),i=e.scoped().length;return[`${t.dim("Scope")} ${r.join(" ")}`,t.dim(i>1?`${i} slots move by the same step, each keeping its own color`:"This slot moves alone · a widens it")]}function fF(t,e){if(!t.misses().has(e))return;if(Tm(t.list,t.signature,t.waive,"bright-follows").includes(e))return e-j.length<8?"= makes the bright follow its normal":"= on the normal makes this follow it";return"f moves the colors the gate misses"}function e1(t,e,n){let r=nl(t.list,t.signature,t.waive,e),i=Zv(t,n);if(i!==void 0)r.push({ok:void 0,text:`Chroma ○ ${i.toFixed(3)} is held while you tune — ${n.c.toFixed(3)} fits this lightness and hue`});return r}var qv={background:(t)=>t.background,foreground:(t)=>t.foreground,hue:(t)=>t.cursor,tint:(t)=>t.background,lightness:(t)=>t.ansi[4],chroma:(t)=>t.ansi[1],brights:(t)=>t.ansi[12]};function dF(t){return`oklch ${t.l.toFixed(3)} ${t.c.toFixed(3)} ${t.h.toFixed(0)}°`}function _m(t){return`${t.l.toFixed(2)} ${t.c.toFixed(3)} ${t.h.toFixed(0).padStart(3)}°`}function n1(t,e){return`${t.dim("oklch")} ${t.bold(`${e.l.toFixed(3)} ${e.c.toFixed(3)} ${e.h.toFixed(0)}°`)}`}function cl(t,e){return e===void 0?t.dim("·"):e?t.dim("✓"):t.bold("✗")}function r1(t,e,n,r=xa){let i=Ov(e.list,e.signature,e.waive).sort((u,l)=>Number(u.ok!==!1)-Number(l.ok!==!1)),s=i.filter((u)=>u.ok===!1).length,o=` ${t.dim("Gate")} ${s===0?t.dim("passes"):t.bold(`${s} ${s===1?"miss":"misses"}`)}`,a=r-4,c=i.flatMap((u)=>{let l=`${u.value} ${u.bound}`,f=` ${cl(t,u.ok)} ${Gt(u.ok===!1?u.label:t.dim(u.label),t.dim(l),a-2)}`,d=[...new Set(u.slots)].map(($)=>Gi($).name),h=u.slots[0],m=($)=>h===void 0?$:_t({kind:"slot",slot:h},$);return d.length>0?[m(f),m(` ${t.dim(ot(d.join(" · "),a-2))}`)]:[m(f)]});return[s===0?o:Gt(o,`${t.bold("n")} ${t.dim("next miss")}`,r-2),...c.slice(0,Math.max(0,n-1))]}function i1(t,e,n,r=xa,i=!0){let s=e.misses(),o=se(e.list),a=i?e.slot():-1,c=(f)=>{let d=e.list[f],h=f===a,m=e.signature.includes(Ui[f])?"◆":t.color?"■":" ",$=s.has(f)?"✗":e.theme&&e.offDefault(f)?"↺":" ",b=`${t.color?`${t.fg(d)}${m}${h?t.fg(o.foreground):"\x1B[39m"} `:`${m} `}${_m(e.lch[f])}${$}`;if(!h)return _t({kind:"slot",slot:f},` ${b}`);return _t({kind:"slot",slot:f},t.color?`${t.bg(o.selection)}${t.fg(o.foreground)} ${b}\x1B[39;49m`:`›${b}`)},u=(f)=>f?t.color?`${t.fg(o.cursor)}▌\x1B[39m `:"▌ ":" ",l=[` ${t.dim("Base")}`];for(let f=0;f<j.length;f++){let d=i&&f===e.row,h=j[f].padEnd(10);l.push(`${_t({kind:"slot",slot:f},`${u(d)}${d?t.bold(h):h}`)}${c(f)}`)}l.push("",` ${t.dim(`${"ANSI".padEnd(10)} ${"Normal".padEnd(18)} Bright`)}`);for(let f=j.length;f<Kr;f++){let d=i&&f===e.row,h=tl[f-j.length].padEnd(10),m=_t({kind:"slot",slot:f+(e.col===1?8:0)},`${u(d)}${d?t.bold(h):h}`);l.push(`${m}${c(f)}${c(f+8)}`)}return l.push(""),[...l,...r1(t,e,n-l.length,r)]}function hF(t,e,n){let r=se(e.list),i=[` ${t.dim("Seeds")}`];ji.forEach((s,o)=>{let a=o===e.field,c=e.seeds[s.key],u=Array.from({length:Lm},(g,b)=>{let y=s.min+(s.max-s.min)*b/(Lm-1);return qv[s.key](Wr({...e.seeds,[s.key]:y}))}),l=Vv(t,u,jm(c,s.min,s.max,Lm),a),f=`${c.toFixed(s.digits)}${s.wraps?"°":""}`.padStart(6),d=qv[s.key](r),h=a?t.color?`${t.fg(r.cursor)}▌\x1B[39m `:"▌ ":" ",m=s.label.padEnd(17),$={kind:"field",field:o};i.push(`${_t($,`${h}${a?t.bold(m):m}`)}${_t({kind:"seed",field:o},l)}${_t($,` ${f} ${t.color?`${t.fg(d)}■\x1B[39m `:""}${t.dim(d)}`)}`)}),i.push("");for(let s of bt("Seven seeds grow all twenty colors, each accent on the hue its ANSI role reads as — whatever the seeds, they pass the gate. enter moves on to tune each slot, and the seeds stay behind.",xa-4))i.push(` ${t.dim(s)}`);return i.push(""),[...i,...r1(t,e,n-i.length)]}function mF(t,e){let n=t-j.length;if(n>=0)return e===String(n)||e===`B${n}`||e===`K${n}`;return t===3&&e==="s"||t===2&&e==="c"}function pF(t,e,n,r){let i=r?"\x1B[4m":"";if(n==="d")return`${t.fg(e.foreground)}\x1B[2m${i}`;if(n==="b")return`${t.fg(e.foreground)}\x1B[1m${i}`;if(n==="s")return`${t.bg(e.selection)}${t.fg(e.foreground)}${i}`;if(n==="c")return`${t.bg(e.cursor)}${i}`;let s=/^([BK]?)(\d+)$/.exec(n);if(!s)return`${t.fg(e.foreground)}${i}`;let o=e.ansi[Number(s[2])];if(s[1]==="K")return`${t.fg(e.ansi[0])}${t.bg(o)}${i}`;return`${t.fg(o)}${s[1]==="B"?"\x1B[1m":""}${i}`}function s1(t,e,n,r,i,s){let o=ie.indexOf(bi(i)),a=ie.map((l,f)=>_t({kind:"scene",scene:f},f!==o?t.dim(l.name):t.color?`${t.bg(e.selection)}${t.fg(e.foreground)} ${l.name} \x1B[39;49m`:`[${l.name}]`)).join(" "),c=[Gt(a,t.dim("⇧←→"),n)],u=`${t.bg(e.background)}${t.fg(e.foreground)}`;for(let l of bi(i).lines){let f=Dc(l,n-2);if(!f)continue;if(c.length>=r)break;let d=t.color?f.map(([h,m])=>`${pF(t,e,m,mF(s,m))}${h}\x1B[0m${u}`).join(""):f.map(([h])=>h).join("");c.push(`${u} ${ot(d,n-2)} ${t.color?"\x1B[0m":""}`)}return c}var gF=["Bk","Rd","Gr","Ye","Bl","Ma","Cy","Wh"];function Yv(t,e,n,r,i,s,o){let a=(i-s)/(o-1),c=o1(e),u=se(n),l=(f)=>Math.min(o-1,Math.max(0,Math.round((i-r(St(f)))/a)));return Array.from({length:o},(f,d)=>{let m=`${(d%2===0?(i-a*d).toFixed(i>=1?1:2).replace(/^0(?=\.\d\d)/,""):"").padStart(4)} ${t.dim(d%2===0?"┤":"│")}`;for(let $=0;$<8;$++){let g=[" "," "," "," "," "],b=u.ansi[$],y=u.ansi[$+8],E=l(b)===d,S=l(y)===d,x=(N)=>{if(N===1&&E)return t.color?`${t.fg(b)}●`:"●";if(N===3&&S)return t.color?`${t.fg(y)}○`:"○";return g[N]},R=[0,1,2,3,4].map(x).join("");m+=c.has($)?t.color?`${t.bg(u.selection)}${R}\x1B[39;49m`:R:`${R}${t.color?"\x1B[39m":""}`}return m})}function o1(t){let e=t.mode==="tune"?t.scoped():[t.slot()];return new Set(e.filter((n)=>n>=j.length).map((n)=>(n-j.length)%8))}function bF(t,e){let n=o1(e);return` ${gF.map((r,i)=>n.has(i)?t.bold(` ${r} `):t.dim(` ${r} `)).join("")}`}function wF(t,e){let n=se(e),r=Array.from({length:40},(s,o)=>{let a=o*9+4.5,c=-1,u=999;for(let[l,f]of Object.entries(be)){let d=Ae(a,f.center);if(d<=f.width&&d<u)u=d,c=Number(l)}return c<0?" ":t.color?`${t.fg(n.ansi[c])}─`:"─"}).join(""),i=(s,o)=>{let a=Array.from({length:40},()=>" ");for(let c of Object.keys(be).map(Number)){let u=n.ansi[c+s],l=Math.min(39,Math.round(St(u).h/9));a[l]=t.color?`${t.fg(u)}${o}\x1B[39m`:o}return` ${a.join("")}`};return[`${t.bold("Hue")} ${t.dim("0° 90° 180° 270° 360°")}`,`${t.dim("bands")} ${r}${t.color?"\x1B[39m":""}`,i(0,"●"),i(8,"○")]}function $F(t,e,n){let r=Bi(n,e.signature,e.waive),i=(a)=>Gi(j.length+a).name,s=(a)=>St(n[j.length+a]).h.toFixed(0),o=[...Rn(r).filter(({gap:a})=>a>25).map(({normal:a,gap:c})=>`${i(a)} ${s(a)}° → bright ${s(a+8)}° · ${c.toFixed(0)}° apart · ≤ 25°`),...nr(r).map(({slot:a,over:c})=>{let u=be[sn(a)];return`${i(a)} ${s(a)}° · ${c.toFixed(0)}° outside ${u.name} ${u.center}±${u.width}°`}),...Nn(r).map(([a,c])=>`${i(a)} and ${i(c).toLowerCase()} read as one color`)];return o.length>0?o.map((a)=>`${t.bold("✗")} ${a}`):[t.dim("✓ Every accent keeps its role and its bright")]}function Gm(t,e,n,r,i){let s=e.shown(),o=Math.max(...s.slice(j.length).map((u)=>St(u).c)),a=Math.max(0.2,Math.ceil(o/0.05)*0.05),c=[Gt(t.bold("Lightness"),t.dim("● normal ○ bright"),n),...Yv(t,e,s,(u)=>u.l,1,0.3,8),bF(t,e)];if(i)c.push("",t.bold("Chroma"),...Yv(t,e,s,(u)=>u.c,a,0,5),"",...wF(t,s));return[...c,...$F(t,e,s)].slice(0,r)}function kF(t,e,n){let r=se(e.list),i=(s,o)=>_t({kind:"view",view:o},e.view!==o?t.dim(` ${s} `):t.color?`${t.bg(r.selection)}${t.fg(r.foreground)}${t.bold(` ${s} `)}\x1B[39;49m`:`[${s}]`);return Gt(`${i("Slot","slot")}${i("Relations","relations")}`,gn("g",`${t.bold("g")} ${t.dim("switch")}`),n)}function yF(t,e,n,r){let i=e.slot(),s=e.list[i],o=e.lch[i],a=e.start[i],{name:c,about:u}=Gi(i),l=e.signature.includes(Ui[i]),f=Math.max(8,Math.min(64,n-12));if(e.view==="relations"&&e.mode!=="tune")return[kF(t,e,n),"",...Gm(t,e,n,r-2,!0)];let d=i>=j.length?t.dim("Uses underlined below"):l?t.dim("◆ signature"):"",h=[Gt(`${t.bold(c)} ${t.dim(u)}`,e.view==="relations"?"":d,n),""],m=t.color?`${t.fg(s)}${"█".repeat(8)}\x1B[39m `:"",$=e.typing!==void 0?`${t.bold(`${e.typing}▏`)}`:void 0,[g,b,y]=rt(s);if(h.push(`${m}${$??n1(t,o)}`),h.push(`${m}${t.dim(`${s} · rgb ${g} ${b} ${y}`)}`),e.view!=="relations"){let R=t.color?`${t.fg(a)}■\x1B[39m `:"";h.push(`${m}${a!==s?t.dim(`was ${R}${dF(e.lchOf(a)).slice(6)} · ${a}`):t.dim("as it opened")}`)}h.push(""),h.push(...Qv(t,e,o,f),Xv(t,e,f));let E=t1(t,e);if(E.length>0)h.push(...E);if(e.view==="relations")return h.push("",...Gm(t,e,n,r-h.length-1,!1)),h;h.push("");for(let R of e1(e,i,o))bt(R.text,n-2).forEach((N,F)=>{h.push(`${F===0?cl(t,R.ok):" "} ${R.ok===!1?N:t.dim(N)}`)});let S=fF(e,i);if(S)h.push(t.dim(` ${S}`));let x=r-h.length-1;if(x>=3)h.push("",...s1(t,se(e.shown()),n,x,e.scene,i));return h}function vF(t,e,n,r){return[Gt(`${t.bold("Sample")} ${t.dim("what the seeds grow")}`,"",n),"",...s1(t,se(e.list),n,r-2,e.scene,-1)]}var EF=[["Slots","↑↓ slot · ←→ normal or bright · home end · pgup the base colors · pgdn the ANSI ones · n N the next and last miss"],["Tune","enter or tab · ↑↓ lightness, chroma, hue or contrast · ←→ step · ⇧←→ ×5, hue ×10 · home end the ends · 0-9 jump · enter keeps · esc undoes"],["Contrast","◐ moves lightness until the ratio to the color it is read against changes · home the gate’s floor · 1-9 that ratio"],["Chroma","stops at the sRGB edge · what lightness or hue takes away comes back while you tune, where it fits again (○)"],["Scope","a while tuning: this, pair, normals, brights or accents — the slots in it move by the same step, each keeping its own color"],["Relations","g shows the lightness, chroma and hue of every ANSI color at once, and the relations the gate checks"],["Sample","⇧←→ another scene · the slot under the cursor is underlined where it is used"],["Type","# then #rrggbb, rgb(r g b) or oklch(l c h) — a paste works too"],["Slot","c copies · v pastes · r puts it back as it opened, R all of them · = the bright follows its normal · * marks it a signature color"],["Palette","f moves the colors the gate misses · o takes another palette’s colors"],["Gate","✗ marks every slot whose own checks miss, and each miss names its slots"],["History","u undo · ctrl+r redo"],["Pictures","p finds one on the boorus, tried on in these colors · drop a picture on the window, or paste one, its path or its link · ctrl+v takes the clipboard’s"],["Compare","space shows the colors you started from, on the terminal too"],["Save","s saves · esc cancels, asking first when something changed"]];function SF(t,e,n){let r=[` ${t.bold("Help")}`,""];for(let[i,s]of EF.filter(([o])=>o!=="Pictures"||e.options.find))bt(s,n-16).forEach((o,a)=>{r.push(` ${t.bold((a===0?i:"").padEnd(11))} ${o}`)});return r}function MF(t,e,n,r){let i=e.choices(),s=e.options.palettes?.length??0,o=e.filter?`${t.bold(e.filter)}▏`:t.dim("type to filter"),a=[Gt(` ${t.bold("Take colors from")} ${o}`,t.dim(`${i.length}/${s}`),n),""],c=r-2,u=Math.max(0,Math.min(e.pick-Math.floor(c/2),i.length-c)),l=Math.min(40,Math.max(12,...i.map((f)=>X(f.name))));if(i.slice(u,u+c).forEach((f,d)=>{let h=u+d===e.pick,m=f.colors,$=t.color?`${t.bg(m.background)} ${[...m.ansi].map((y)=>`${t.fg(y)}■`).join("")} ${t.fg(m.foreground)}Aa \x1B[0m`:"",g=h?"▌ ":" ",b=f.name.padEnd(l);a.push(_t({kind:"choice",index:u+d},`${g}${h?t.bold(b):b} ${$}`))}),i.length===0)a.push(` ${t.dim(`No palettes match '${e.filter}'`)}`);return a}var OF=new Set(["enter","s","?","g","a"]);function xF(t,e,n){let r=t.fg(e.list[2]),i="EDIT",s="",o=[],a="";if(e.quitting)i="EDIT (QUIT)",s=e.added>0?`Discard changes and ${e.added} ${e.added===1?"picture":"pictures"}?`:"Discard changes?",o=[["y","discard"],["n","keep editing"]];else if(e.typing!==void 0)i="EDIT (TYPE)",s=t.dim("#rrggbb, rgb(r g b) or oklch(l c h)"),o=[["enter","set"],["ctrl+u","clear"]],a="esc back";else if(e.overlay==="keys")i="HELP",a="any key closes";else if(e.overlay==="open")i="EDIT (OPEN)",o=[["↑↓","palette"],["a-z","filter"],["enter","take its colors"]],a="esc close";else if(e.compare)i="EDIT (BEFORE)",s="The colors you started from",o=[["space","back to yours"]],a="esc back";else if(e.mode==="seeds")i="EDIT (SEEDS)",o=[["↑↓","seed"],["←→","step"],["⇧←→","×5"],["enter","tune the slots"],["o","open a palette"],["p","picture"],["?","keys"]],a="esc cancel";else if(e.mode==="tune")i="EDIT (TUNE)",o=[["↑↓","L C H ◐"],["←→","step"],...e.slot()>=j.length?[["a","scope"]]:[],["⇧←→","faster"],[e.channel===Qn?"1-9":"0-9",e.channel===Qn?"ratio":"jump"],["#","type"],["enter","keep"]],a="esc undo";else o=[["↑↓","slot"],["←→","normal or bright"],["enter","tune"],["g",e.view==="slot"?"relations":"slot"],...e.misses().size>0?[["n","next miss"]]:[],["#","type"],["f","fix"],["p","picture"],["u","undo"],["s","save"],["?","keys"]],a="esc cancel";if(!e.options.find)o=o.filter(([l])=>l!=="p");if(e.notice)s=t.color?`\x1B[33m${e.notice}\x1B[39m`:e.notice,o=[];let c=t.color?`\x1B[7;1m${r} ${i} \x1B[0m `:`[${i}] `,u=a?gn(a.split(" ")[0],`${t.bold(a.split(" ")[0])} ${t.dim(a.split(" ").slice(1).join(" "))}`):"";for(;;){let l=[s,...o.map(([h,m])=>gn(h,`${t.bold(h)} ${t.dim(m)}`))].filter(Boolean),f=`${c}${l.join(" ")}`,d=-1;if(o.forEach(([h],m)=>{if(m>0&&!OF.has(h))d=m}),X(f)+X(a)+3<=n||d<0)return a?Gt(f,u,n):ot(f,n);o=o.filter((h,m)=>m!==d)}}var Bm=50,Um=22;function a1(t){let e=t.notice??"";if(t.typing!==void 0)return{mode:"type",keys:[["enter","set"],["ctrl+u","clear"],["esc","back"]],note:e};if(t.compare)return{mode:"compare",keys:[["space","back to yours"],["esc","back"]],note:e};if(t.mode==="tune")return{mode:"tune",keys:[["↑↓","L C H ◐"],["←→","step"],...t.slot()>=j.length?[["a","scope"]]:[],["⇧←→","×5"],["enter","keep"],["esc","undo"]],note:e};return{mode:"list",keys:[["↑↓←→","slot"],["enter","tune"],["g",t.view==="slot"?"relations":"slots"],...t.misses().size>0?[["n","next miss"]]:[],["r","reset slot"],["R","reset all"],["#","type a color"],["space","before"]],note:e}}function IF(t,e,n,r){let i=e.slot(),s=e.list[i],o=e.lch[i],a=e.start[i],c=e.original[i],{name:u,about:l}=Gi(i),f=e.signature.includes(Ui[i]),d=t.color?`${t.fg(s)}${"█".repeat(4)}\x1B[39m `:"",h=e.typing!==void 0?t.bold(`${e.typing}▏`):void 0,m=[a!==s?`was ${t.color?`${t.fg(a)}■\x1B[39m `:""}${_m(e.lchOf(a))}`:"",c!==s?`default ${t.color?`${t.fg(c)}■\x1B[39m `:""}${_m(e.lchOf(c))}`:""].filter(Boolean),$=[Gt(`${t.bold(u)} ${t.dim(l)}`,f?t.dim("◆ signature"):"",n),`${d}${h??n1(t,o)} ${t.dim(s)}`,...r>=7?[`${d}${t.dim(m.length>0?m.join(" "):"as the palette has it")}`]:[]],g=Math.max(8,Math.min(40,n-12));$.push(...Qv(t,e,o,g),Xv(t,e,g));for(let b of t1(t,e))if($.length<r)$.push(ot(b,n));for(let b of e1(e,i,o))for(let[y,E]of bt(b.text,n-2).entries()){if($.length>=r)return $;$.push(`${y===0?cl(t,b.ok):" "} ${b.ok===!1?E:t.dim(E)}`)}return $}function c1(t,e,n,r,i){let s=Jv(r);if(t.view==="relations"&&t.mode==="list"&&t.typing===void 0){let y=i?s.bold("Palette"):s.dim("Palette"),E=Gm(s,t,e-2,n-1,!1).map((R)=>` ${R}`),x=[` ${Gt(`${y} ${s.dim("Relations")}`,gn("g",`${s.bold("g")} ${s.dim("slots")}`),e-2)}`,...E];return{lines:Array.from({length:n},(R,N)=>ot(x[N]??"",e)),at:2}}let o=i1(s,t,0,e,i).slice(1,-2),a=(t.mode==="tune"||t.typing!==void 0)&&n-1-o.length<6,c=a?[]:[...o],u=t.row<j.length?t.row+2:t.row+4;if(!a&&n-1-c.length>=9)c.push("");let l=n-1-c.length;if(l>=5){let y=c.length+1;if(c.push(...IF(s,t,e-2,l).map((E)=>` ${E}`)),t.mode==="tune")u=y+3+(l>=7?1:0)+t.channel;else if(t.typing!==void 0)u=y+2}let f=i?s.bold("Palette"):s.dim("Palette"),d=i&&l<5?nl(t.list,t.signature,t.waive,t.slot()).find((y)=>y.ok===!1):void 0,h=t.failing().length,m=h===0?"passes the gate":`${h} ${h===1?"miss":"misses"} in the gate`,$=t.list.filter((y,E)=>t.offDefault(E)).length,b=[` ${d?`${f} ${cl(s,!1)} ${d.text}`:Gt(`${f}${$>0?s.dim(` ${$} off its default`):""}`,s.dim(m),e-2)}`,...c];return{lines:Array.from({length:n},(y,E)=>ot(b[E]??"",e)),at:u}}function RF(t,e,n,r){let i=Jv(r);if(e<Kv||n<zv){let m=[i.bold("ttheme palette editor"),`Needs ${Kv}×${zv} — now ${e}×${n}`,i.dim("esc cancels")];return Array.from({length:n},($,g)=>ot(m[g]??"",e))}let s=t.failing().length,o=s===0?"✓ Passes the gate":`✗ ${s} ${s===1?"miss":"misses"} in the gate`,a=t.pictures>0?i.dim(`▣ ${t.pictures} ${t.pictures===1?"picture":"pictures"} `):"",c=`${t.dirty()?`${i.color?"\x1B[33m●\x1B[39m":"●"} unsaved `:""}${a}${i.dim(o)}`,l=`${i.fg(t.list[2])}◆${i.color?"\x1B[39m":""} ${i.bold(t.options.title)} ${i.dim(`· ${t.options.name}`)}`,f=n-4,d;if(t.overlay==="keys")d=SF(i,t,e);else if(t.overlay==="open")d=MF(i,t,e,f);else{let m=e-xa-2,$=t.mode==="seeds"?hF(i,t,f):i1(i,t,f),g=t.mode==="seeds"?vF(i,t,m,f):yF(i,t,m,f);d=Array.from({length:f},(b,y)=>`${ot($[y]??"",xa)}${i.dim("│")} ${ot(g[y]??"",m)}`)}let h=[Gt(l,c,e),""];for(let m=0;m<f;m++)h.push(ot(d[m]??"",e));return h.push("",xF(i,t,e)),h}function Wm(t,e,n){if(n.action==="wheel"){if(!n.sideways)t.scroll(n.wheel);return}if((n.action==="press"||n.action==="drag")&&n.button!=="left")return;if(n.action==="press"&&t.overlay==="keys"){t.press("esc");return}let r=e?.target;if(!e||!r)return;let i=e.width>1?e.x/(e.width-1):0;if(n.action==="release"){if(!e.inside)return;if(r.kind==="key")t.press(r.key);else if(n.count===2&&r.kind==="slot"&&t.mode==="list")t.press("enter");else if(n.count===2&&r.kind==="choice"&&t.overlay==="open")t.press("enter");return}if(r.kind==="bar")t.slide(r.channel,i);else if(r.kind==="seed")t.sow(r.field,i);else if(n.action!=="press")return;else if(r.kind==="slot")t.select(r.slot);else if(r.kind==="channel")t.grip(r.channel);else if(r.kind==="scope")t.scopeTo(r.scope);else if(r.kind==="choice"){if(t.overlay==="open")t.pick=r.index}else if(t.typing===void 0&&!t.overlay&&!t.quitting){if(r.kind==="field"&&t.mode==="seeds")t.field=r.field;else if(r.kind==="view"&&t.mode!=="seeds")t.view=r.view;else if(r.kind==="scene")t.scene=r.scene}}var NF=[ju,Yn,Hi,Gr],TF=33;async function u1(t,e){let n=new Sa(t),r=e.backdrop,i=(s)=>n.typing===void 0&&Qu(s);return Br({modes:[...NF,...Js()],burst:i},async(s)=>{let o=[],a="",c,u=!1,l=!1,f=()=>{if(c=void 0,e.look){let g=n.shown();if(g.join(" ")!==a)a=g.join(" "),e.look(g);return}let $="";n.shown().forEach((g,b)=>{if(o[b]!==g&&e.only?.includes(b))$+=Uo(b,g),o[b]=g}),s.write($)},d=new Ri({write:($)=>s.write($),view:()=>u?void 0:{lines:RF(n,s.cols,s.rows,e.color),after:()=>r?.draw(n.shown(),n.signature,n.waive,s.cols,s.rows)??""}}),h=($=!1)=>{if($)d.soon();else d.request();if(e.only||e.look)c??=setTimeout(f,TF)},m=async($)=>{let g=t.find;if(!g)return;if(u=!0,clearTimeout(c),c=void 0,r)s.write(r.clear());try{n.found(await g(n.edited(),$))}catch(b){n.notice=b instanceof Error?b.message:String(b)}if(l)return;u=!1,r?.load(),o.length=0,a="",d.reset(yi),h()};if(s.write(yi),s.onResize(()=>{r?.resized(),d.reset(yi),d.request()}),r){r.load(),r.ready=()=>d.request();let $=new la;s.ask(Cu,(g)=>$.see(g),1000).then((g)=>{if(g)r.measured(g);d.request()})}h();try{let{edited:$}=await s.loop((g)=>{if(u)return;if(g.kind==="paste")n.paste(g.text);else if(g.kind==="key")n.press(g.key);else if(g.kind==="mouse")Wm(n,d.point(g),g);if(n.result)return{edited:n.result==="saved"?n.edited():void 0};let b=n.wants;if(b)n.wants=void 0,m(b.start);return},()=>{if(!u)h(!0)});return $}finally{if(l=!0,clearTimeout(c),d.stop(),r)s.write(r.close())}})}import{spawn as zF}from"node:child_process";import{createHash as S1}from"node:crypto";import{existsSync as Ra,mkdirSync as DF,mkdtempSync as qF,readFileSync as YF,rmSync as ul}from"node:fs";import{homedir as JF,tmpdir as VF}from"node:os";import{basename as ZF,dirname as QF,join as En}from"node:path";import{pathToFileURL as d1}from"node:url";import{existsSync as AF,readFileSync as PF,statSync as HF}from"node:fs";import{join as l1}from"node:path";function FF(t,e){try{return JSON.parse(PF(l1(Ke(t),e),"utf8"))}catch{return{}}}function CF(t,e,n){P(l1(Ke(t),e),`${JSON.stringify(n)}
710
- `)}class Km{caches=new Map;unsaved=new Set;owners=new Map;crediting=new Map;inflight=new Map;home;catalog;entry;signal;credited;constructor(t){this.home=t.home,this.catalog=t.catalog,this.entry=t.entry,this.signal=t.signal,this.credited=t.credited}matesOf(t,e){return this.owners.get(t.key)?.get(e)??[]}async transparent(t,e){let n=this.keep(t,"probes.json"),r=n[e.id];if(r!==void 0)return r;try{let i=await So(t,e,this.signal),s=oi(t,e),o=(i===void 0?await Bb(s.site,s.url,this.signal):i)?.alpha===!0;return n[e.id]=o,this.unsaved.add(`${t.key}/probes.json`),o}catch{return!1}}save(){for(let t of this.unsaved){let[e,n]=t.split("/"),r=Y.find((i)=>i.key===e);if(r)CF(r,n,this.keep(r,n))}this.unsaved.clear()}owned(t,e,n){this.keep(t,"owners.json")[e]=n,this.unsaved.add(`${t.key}/owners.json`)}credit(t,e){let{site:n,post:r}=t;if(!tc(n,r))return Promise.resolve();let i=ke(n,r.id),s=this.crediting.get(i);if(!s)s=this.credits(t,e).finally(()=>this.crediting.delete(i)),this.crediting.set(i,s);return s}async mateOwners(t){let e=this.owners.get(t.key);if(e)return e;let n=xw(this.home),r=this.keep(t,"owners.json"),i=this.catalog.palettes.flatMap((c)=>{let u=n.get(c.name);return c.group===this.entry.group&&c.name!==this.entry.name&&u?.site===t.key?[{name:c.name,id:u.id}]:[]}),s=await Promise.all(i.map(async(c)=>{let u=r[c.id];if(u!==void 0)return{...c,owner:u};try{return{...c,owner:(await us(t,c.id,this.signal))?.owner??""}}catch{return}})),o=new Map;for(let c of s)if(c)r[c.id]=c.owner,o.set(c.name,c.owner);this.unsaved.add(`${t.key}/owners.json`);let a=Fb(o);return this.owners.set(t.key,a),a}async cached(t,e,n,r){if(AF(e))return HF(e).size;let i=this.inflight.get(e);if(i)return i;let s=(async()=>{let o=await rc(t,n,this.signal,r);return P(e,o),o.length})();this.inflight.set(e,s);try{return await s}finally{this.inflight.delete(e)}}keep(t,e){let n=`${t.key}/${e}`,r=this.caches.get(n);if(!r)r=FF(t,e),this.caches.set(n,r);return r}async credits({site:t,post:e},n){let r=this.keep(t,"credits.json"),i=r[e.id];if(!i){try{i=await Xa(t,e.id,n)}catch{return}if(!i?.owner)return;r[e.id]=i,this.unsaved.add(`${t.key}/credits.json`)}Eo(e,i),this.credited()}}import{rmSync as LF}from"node:fs";import{join as jF}from"node:path";var so=2147483645,Ia=2147483646,f1=-1073741827,_F=-1073741828,GF=16,BF=0.4,UF=3221225472,WF=256;function KF(t){let e=/^(\d+) (\d+)$/.exec(t??"");return e&&(Number(e[1])>0||Number(e[2])>0)?{x:Number(e[1]),y:Number(e[2])}:void 0}var zm=KF(process.env.TTHEME_BG_MARGIN);class Dm{screen;gliding;sent=new Map;placed=new Map;covered="";viewed="";bands=Zc(process.env);files=Qc(process.env);moves=c$(process.env);layers=Xc(process.env);wipes=u$(process.env);views=$i(process.env);bandFiles=new Map;nextBand=UF;view;grid;background;renders;scratch;signal;write;constructor(t){this.view=t.view,this.grid=t.grid,this.background=t.background,this.renders=t.renders,this.scratch=t.scratch,this.signal=t.signal,this.write=t.write,this.screen=new Ri({write:(e)=>this.write(e),view:()=>this.frame(),beat:()=>{this.view.beat++}})}draw(){if(!this.signal.aborted)this.screen.request()}soon(){if(!this.signal.aborted)this.screen.soon()}flush(){if(!this.signal.aborted)this.screen.now()}point(t){return this.screen.point(t)}drop(){this.screen.drop()}frame(){if(this.signal.aborted)return;let{cols:t,rows:e,cell:n}=this.grid(),r=wm(this.view,t,e);return this.view.loaderFrom=r.loader?this.view.loaderFrom??this.view.beat:void 0,{lines:r.lines,zones:r.zones,after:(i)=>this.images(r.images,i,n),...this.view.mode==="grid"&&this.view.editing!==void 0?{cursor:this.caret()}:{},ticking:r.tick}}images(t,e,n){let r="",i=new Set,s;for(let o of t){if(this.views&&o.id>=mm){s=o;continue}let a=this.bands?this.banded(o):o;if(!a)continue;if(this.wipes&&[...e].some((u)=>u>=a.row&&u<a.row+a.rows))this.placed.delete(a.id);if(i.add(a.id),this.sent.get(a.id)!==a.path){let u=Du(a,this.files);if(u===void 0)continue;r+=u,this.sent.set(a.id,a.path),this.placed.delete(a.id)}let c=`${a.row};${a.col};${a.cols};${a.rows};${a.crop};${a.z}`;if(this.placed.get(a.id)!==c){if(!this.moves&&this.placed.has(a.id))r+=gm(a.id);r+=Zy(a,n),this.placed.set(a.id,c)}}for(let o of this.sent.keys())if(!i.has(o))r+=ka(o),this.sent.delete(o),this.placed.delete(o);return r+(this.views?this.backdrop(s):this.cover())}glide(){if(this.bands)this.prebake();if(this.gliding)return;let{cols:t,rows:e}=this.grid(),n=Jn(t,e).height,r=()=>{let i=this.view,s=i.top*gt.height,o=s-i.scroll;if(o===0||i.mode!=="grid"){i.scroll=s;let a=this.gliding!==void 0;if(this.gliding=void 0,a)this.draw();return}if(Math.abs(o)>2*n)i.scroll=s-Math.sign(o)*n,o=s-i.scroll;i.scroll+=Math.sign(o)*Math.max(1,Math.round(Math.abs(o)*BF)),this.draw(),this.gliding=setTimeout(r,GF)};r()}snap(){clearTimeout(this.gliding),this.gliding=void 0,this.view.scroll=this.view.top*gt.height}resized(){this.screen.reset()}stop(){this.screen.stop(),clearTimeout(this.gliding)}prebake(){let t=this.view,{cols:e,rows:n}=this.grid();for(let r of wm({...t,scroll:t.top*gt.height},e,n).images)if(r.crop!==void 0)this.band(r.path,r.crop,r.rows)}cover(){let{cols:t,rows:e}=this.grid(),n=`${t};${e}`;if(!this.layers||this.covered===n)return"";let r="";if(!this.covered){let i=Buffer.from(rt(this.background)).toString("base64");if(r+=`\x1B_Ga=t,f=24,s=1,v=1,i=${so},q=2;${i}\x1B\\`,zm)r+=`\x1B_Ga=t,f=32,s=1,v=1,i=${Ia},q=2;AAAAAA==\x1B\\\x1B[H\x1B_Ga=p,i=${Ia},p=${Ia},c=1,r=1,C=1,z=${_F},q=2\x1B\\`}else if(!this.moves)r+=gm(so);if(this.covered=n,zm){let{x:i,y:s}=zm;return`${r}\x1B_Ga=p,i=${so},p=${so},P=${Ia},Q=${Ia},H=${-i},V=${-s},c=${t+2*i},r=${e+2*s},C=1,z=${f1},q=2\x1B\\`}return`${r}\x1B[H\x1B_Ga=p,i=${so},p=${so},c=${t},r=${e},C=1,z=${f1},q=2\x1B\\`}backdrop(t){let{cols:e,rows:n,cell:r}=this.grid(),i=e*r.w,s=n*r.h,o=t?`${this.background}|${t.path}|1|${i}|${s}|${i}|${s}|0|0|1`:`${this.background}||1|${i}|${s}|0|0|0|0|5`;if(o===this.viewed)return"";return this.viewed=o,ki(o)}caret(){return`\x1B[1;${Math.min(this.grid().cols,X(`⌕ ${this.view.editing??""}`)+1)}H`}banded(t){if(t.crop===void 0)return t;let e=this.band(t.path,t.crop,t.rows,!this.gliding);return e?.ready?{...t,id:e.id,path:e.path,crop:void 0}:void 0}band(t,e,n,r=!0){let i=`${t}|${e}|${n}`,s=this.bandFiles.get(i);if(s||!r)return s;let{cell:o}=this.grid(),a=this.nextBand++,c={id:a,path:jF(this.scratch,`band-${a}.png`),ready:!1};return this.bandFiles.set(i,c),this.renders.run({job:"band",from:t,to:c.path,y:e*o.h,height:n*o.h}).then(()=>{c.ready=!0,this.draw()}).catch(()=>{}),this.trimBands(),c}trimBands(){for(let[t,e]of this.bandFiles){if(this.bandFiles.size<=WF)return;if(e.ready&&!this.sent.has(e.id))this.bandFiles.delete(t),LF(e.path,{force:!0})}}}var Wi=[{name:"TTHEME_FIND_RATING",label:"Rating",about:"The ratings to list, each site read in its own words — space ticks one, and one stays ticked",choices:os,multi:{read:si}},{name:"TTHEME_FIND_BLOCK",label:"Block",about:"Posts tagged with nudity or underwear are left out — space unticks one",choices:ii,multi:{read:cs,none:"none"}},{name:"TTHEME_FIND_POSTS",label:"Posts",about:"Every post of the character, or only the transparent cutouts",choices:["all","cutouts"]},{name:"TTHEME_FIND_SOLO",label:"Solo",about:"When on, only the posts known to show the character alone — checked as posts arrive, so the counts below leave it out",choices:["on","off"]},{name:"TTHEME_FIND_ORDER",label:"Order",about:"How posts are ranked: fit, by how well each makes a backdrop; newest; or score",choices:["fit","newest","score"]},{name:"TTHEME_FIND_SETS",label:"Sets",about:"One picture posted over and over, or held by another site too: fold it into one tile, or show each",choices:["fold","show"]},...Gs()?[{name:"TTHEME_FIND_REMOVE_BG",label:"Remove bg",about:"Cut the character out of an opaque picture you try on, with macOS Vision",choices:["on","off"]}]:[],{name:"TTHEME_FIND_MIN_SCORE",label:"Min score",about:"Posts scored at least this — danbooru, konachan and yande.re; zerochan keeps no score. ←→ steps, or type any number",choices:vb,entry:"number",advanced:!0},{name:"TTHEME_FIND_MIN_SIZE",label:"Min size",about:"The shorter side of a picture, in px — every site filters it. ←→ steps, or type any number",choices:Eb,entry:"number",advanced:!0},{name:"TTHEME_FIND_SITES",label:"Sites",about:"The sites the all tab mixes — each keeps its own tab. Space ticks one, and one stays ticked",choices:Y.map((t)=>t.name),multi:{read:ko},advanced:!0},{name:"TTHEME_FIND_HIDE",label:"Hide",about:"Comics, monochrome, sketches or chibi, told by tag in every site's spelling — checked as posts arrive",choices:mf,multi:{read:qa,none:"none"},advanced:!0},{name:"TTHEME_FIND_HIDE_TAGS",label:"Hide tags",about:"Posts with any of these tags are left out, spaced like cosplay multiple_girls — checked as posts arrive",choices:[],entry:"text",advanced:!0},{name:"TTHEME_FIND_PNG",label:"PNG only",about:"PNG originals only — danbooru counts it, the others are told by the file; zerochan only where danbooru holds it",choices:["off","on"],advanced:!0}];function h1(t,e){if(t.multi)return t.multi.read(e).join(" ")||t.multi.none;if(t.entry==="number")return/^\d+$/.test(e??"")&&Number(e)>0?String(Number(e)):"off";if(t.entry==="text")return yo(e).join(" ");return t.choices.find((n)=>n===e)??t.choices[0]}var XF=["fit","newest","score"];function qm(t){return XF.find((e)=>e===t)??"fit"}var tC={left:-1,right:1,"shift-left":-10,"shift-right":10};function m1(t){if(process.env.SSH_CONNECTION||!/^(?:https?|file):/i.test(t))return;try{let e=zF(process.platform==="darwin"?"open":"xdg-open",[t],{stdio:"ignore",detached:!0});e.on("error",()=>{}),e.unref()}catch{}}function eC(t,e,n){if(e<0){if(t!=="fill")return Math.max(fl,t+e);if(!n)return t;return Math.max(fl,Math.max(100,n)+e+1)}return t==="fill"||t+e>n?"fill":t+e}function M1(t,e){return t.size===e.size&&t.at===e.at&&t.opacity===e.opacity}function nC(t,e){if(M1(t,e))return;return{...t.size!=="fill"?{size:t.size}:{},...t.at!==e.at?{position:Ut[t.at-1]}:{},...t.opacity!==e.opacity?{opacity:t.opacity}:{}}}function p1(t,e){let n=q(t);return ce(t,e).flatMap((r,i)=>{let[,s,o]=/^([a-z.]+)_(\d+)$/.exec(r.key)??[],a=[...Y,Vn].find((c)=>c.key===s);if(!a||!o)return[];return[{key:r.key,id:Number(o),ansi:a.ansi,...a===Vn?{}:{page:a.pageUrl(Number(o))},up:i===0,from:En(n,r.original??r.fill)}]})}function rC(t){return t.length>=2&&!/^\d+$/.test(t)&&!t.includes("://")&&!/^[\w.]+:\d+$/.test(t)}var g1=12,iC=4,sC=150,oC=300,b1=12,aC=2,cC=150,uC="\x1B[?5522$p\x1B]72;t=q\x1B\\\x1B[c",lC=4000,fC=8000,w1=/\.(png|jpe?g|gif|webp|heic|tiff?|bmp)$/i,dC=process.platform==="win32"?"alt+v":"ctrl+v",$1=process.platform==="darwin"?"ctrl+shift+cmd+4 copies a screenshot":"copy a picture first",hC=1280,mC=16,pC=Ut.indexOf("top-right")+1,fl=20,k1=2,y1=3,gC=/[\p{Script=Hangul}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]/u,bC=8,wC=9;function ll(t,e){return{key:t,groups:[],sources:[],queue:[],rounds:0,roundOf:new Map,last:new Map,kin:new Map,kindred:new Map,shapes:[],seen:new Set,same:new Map,checked:0,total:0,focus:0,top:0,searching:e,stage:"fetch",arrived:new Set}}function Na(t){if(!(t instanceof Error))return String(t);if(t instanceof AggregateError&&t.errors[0])return Na(t.errors[0]);if(t.cause)return Na(t.cause);let e=t.code;if(typeof e==="string")return e;let n=(t.message||t.name).split(".")[0]??"";return n.length>56?`${n.slice(0,55)}…`:n}function Ym(t,e){return`${t}: ${Na(e)}`}function v1(t){return t.width*t.height}function E1(t,e){return`${t}-${S1("sha1").update(e).digest("hex").slice(0,8)}`}class Jm{view;tone;session=new AbortController;cell={w:0,h:0};cols=process.stdout.columns||80;rows=process.stdout.rows||24;gen=0;pumping=0;boards=new Map;board;posts=new Map;thumbPath=new Map;looking=new Map;looked=new Map;matched=new Map;aheading=!1;pages=new Map;tab=0;values=new Map(Wi.map((t)=>[t.name,h1(t,process.env[t.name])]));direction=1;prefetching=0;related=new Map;pool=[];relating;thumbQueue=[];heldFiles=new Map;heldAsked=new Set;thumbing=0;clarity=new Map;tunedFiles=[];presenting=!1;again=!1;renders=new Ma;showing;thumbless=new Set;current;fetch;settle;suggestTimer;suggesting;countTimer;counting;terminal;grabber=new Sm((t)=>this.write(t),(t)=>void this.got(t));noticeTimer;peekTimer;peeked;attaching;done;scratch=qF(En(VF(),"ttheme-find-"));home;catalog;entry;tagged;blurring;start;paint;kept;constructor(t,e,n,r,i){this.start=i,this.home=t,this.catalog=e,this.entry=n,this.tagged=new Set(e.palettes.flatMap((o)=>o.booru?[o.booru]:[])),this.tone=hn(n,n.signatureSlots),this.blurring=Tr(t);let s={size:"fill",at:pC,opacity:this.tone.opacity};this.view={palette:n.name,tag:r,site:this.tabName,siteAnsi:this.tabAnsi,nextSite:this.nextTabName,preset:this.setting("TTHEME_FIND_POSTS")==="all"?"all":"cutouts",order:qm(this.setting("TTHEME_FIND_ORDER")),solo:this.setting("TTHEME_FIND_SOLO")==="on",rating:si(this.setting("TTHEME_FIND_RATING")),block:cs(this.setting("TTHEME_FIND_BLOCK")),sets:this.setting("TTHEME_FIND_SETS")==="show"?"show":"fold",narrow:this.narrowed(),enabled:ko(this.setting("TTHEME_FIND_SITES")),hide:qa(this.setting("TTHEME_FIND_HIDE")),hideTags:yo(this.setting("TTHEME_FIND_HIDE_TAGS")),advanced:!1,settings:Wi.map((o)=>({label:o.label,choices:[...o.choices],value:this.setting(o.name),default:h1(o,Do(o.name)),multi:o.multi&&{none:o.multi.none},about:o.about,entry:o.entry,advanced:o.advanced,cursor:0})),colors:{cursor:n.cursor,selection:n.selection,background:n.background,foreground:n.foreground,ansi:n.ansi},tiles:[],installed:[],held:p1(t,n.name),checked:0,total:0,searching:r!=="",stage:"fetch",sites:[],focus:0,top:0,scroll:0,beat:0,mode:"grid",help:!1,scene:Math.max(0,ie.findIndex((o)=>o.name.toLowerCase()===process.env.TTHEME_SCENE)),details:!1,tune:{...s},untuned:s,coloring:nu(t),editing:r===""?"":void 0,chips:[]},this.paint=new Dm({view:this.view,grid:()=>({cols:this.cols,rows:this.rows,cell:this.cell}),background:n.background,renders:this.renders,scratch:this.scratch,signal:this.signal,write:(o)=>this.write(o)}),this.kept=new Km({home:t,catalog:e,entry:n,signal:this.signal,credited:()=>{this.show(),this.inform(),this.paint.draw()}}),this.pool=this.selected(this.view),this.syncChips(),this.board=ll(this.boardKey,r!==""),this.boards.set(this.board.key,this.board)}get signal(){return this.session.signal}get site(){return this.tab===0?void 0:Y[this.tab-1]}get sites(){return this.site?[this.site]:Y.filter((t)=>this.view.enabled.includes(t.name))}get tabName(){return this.site?.name??"all"}get tabAnsi(){return this.site?.ansi??iC}get nextTabName(){let t=(this.tab+1)%(Y.length+1);return t===0?"all":Y[t-1].name}frame(){return{w:this.cols*(this.cell.w||10),h:this.rows*(this.cell.h||20)}}setting(t){return this.values.get(t)}narrowed(){return gf(this.setting("TTHEME_FIND_MIN_SCORE"),this.setting("TTHEME_FIND_MIN_SIZE"),this.setting("TTHEME_FIND_PNG"))}get boardKey(){return`${this.site?.key??"all"}|${this.view.preset}|${this.view.order}`}origPath(t,e,n){return En(Ke(t),"orig",`${e}.${n}`)}previewPath(t){let{url:e}=Ja(t.site,t.post);return En(Ke(t.site),"thumb",`${E1(t.post.id,e)}.${fr(e)}`)}tileOf(t,e){let{site:n,post:r}=t,i=ke(n,r.id),s=fn(r)??r;return{id:r.id,key:i,site:n.name,siteAnsi:n.ansi,width:s.width,height:s.height,reduced:s!==r,page:n===Vn?"":n.pageUrl(r.id),artist:n===Vn?lv(r.source):r.named.artist[0]??"",score:r.score,variants:e,mates:this.kept.matesOf(n,r.owner),thumb:this.thumbPath.get(i),missing:this.thumbless.has(i)}}show(){let t=this.view,e=this.board;if(t.tiles=e.groups.flatMap((n)=>n.open?n.posts.map((r)=>this.tileOf(r,0)):[this.tileOf(n.posts[0],n.posts.length)]),t.checked=e.checked,t.total=e.total,t.searching=e.searching,this.stageOf(e),t.note=e.note,t.focus=Math.max(0,Math.min(e.focus,t.tiles.length-1)),t.top=e.top,this.showing!==e)this.showing=e,this.paint.snap()}stageOf(t){let e=this.view;e.stage=t.stage,e.ranking=t.ranking,e.sites=this.sites.map((n)=>({name:n.name,arrived:t.arrived.has(n.name)}))}syncSite(){let t=this.view;t.site=this.tabName,t.siteAnsi=this.tabAnsi,t.nextSite=this.nextTabName}run(){let t=(e)=>this.view.editing===void 0&&Qu(e);return Br({modes:[Gr,...Js()],assume:[Yn,Hi],burst:t},async(e)=>{this.terminal=e,e.onResize(this.onResize),e.listen((i)=>{for(let s of i)this.inbound(s);this.paint.soon()}),e.write(yi);let n=new Promise((i)=>{this.done=i}),r=setInterval(this.onClock,250);setTimeout(wc,0);try{let i=new la,s=await e.ask(Cu,(o)=>i.see(o),1000);if(s){if(this.cell=s,this.holdThumbs(),this.view.tag)this.search(),this.relate(this.view.tag)}else this.view.searching=!1,this.view.error="This terminal does not report its cell size — find needs kitty graphics";if(!process.env.TMUX)await e.ask(uC,(o)=>o.kind==="attributes"?!0:void 0,500,!1);if(this.grabber.start(),e.hold(Ny),this.start&&"paste"in this.start)this.pasted(this.start.paste);else if(this.start)this.fromClipboard();else this.peek();return this.paint.draw(),await e.until(n)}finally{this.session.abort(),this.grabber.stop(),this.attaching?.abort(),clearTimeout(this.noticeTimer),clearTimeout(this.peekTimer),this.fetch?.abort(),clearTimeout(this.settle),this.quietSuggest(),this.quietCount(),clearInterval(r),this.paint.stop(),e.write(`\x1B_Ga=d,d=A,q=2\x1B\\${yi}`),this.kept.save(),this.renders.close(),ul(this.scratch,{recursive:!0,force:!0}),Cb()}})}write(t){this.terminal?.write(t)}get saved(){return this.view.saved?.text}get installs(){return this.view.installed.length}finish(t){this.done?.(t===2&&this.saved?0:t)}inbound(t){if(t.kind==="key")this.key(t.key);else if(t.kind==="mouse")this.pointer(t);else if(t.kind==="paste")this.pasted(t.text);else if(t.kind==="mode"){if(t.mode===5522)this.grabber.clipboard=t.value!==0&&t.value!==4}else if(t.kind==="osc")if(t.code==="72"&&t.meta.t==="q")this.grabber.drops=!0;else this.grabber.take(t)}pasted(t){let e=this.view;if(e.editing!==void 0&&t.trim()!==""&&!this.picture(t)){e.editing+=t.replace(/[\r\n]+/g," "),this.suggest(),this.paint.draw();return}if(e.installing!==void 0||e.panel!==void 0||e.help)return;if(t.trim()===""){this.fromClipboard();return}this.attach(t)}picture(t){let e=t.trim();if(/^https?:\/\/\S+$/i.test(e))return!Ya(e,this.site??Y[0]);return eo(e).length>0}async got(t){if(t.kind==="error"){this.notice(t.message);return}if(t.kind==="text"){if(t.text.trim()===""){this.notice(`No picture on the clipboard — ${$1}`);return}this.pasted(t.text);return}await this.bring(()=>Vu(t.bytes,t.source))}notice(t,e=lC){let n=this.view;n.error=t,clearTimeout(this.noticeTimer),this.noticeTimer=setTimeout(()=>{if(n.error===t)n.error=void 0,this.paint.draw()},e),this.paint.draw()}async peek(){let t=this.view,e;try{e=await pv()}catch{return}if(!e||e.stamp===this.peeked)return;if(this.peeked=e.stamp,!e.picture||t.installing!==void 0)return;t.hint=`Picture on the clipboard · ${dC} uses it`,clearTimeout(this.peekTimer),this.peekTimer=setTimeout(()=>{t.hint=void 0,this.paint.draw()},fC),this.paint.draw()}async fromClipboard(){let t=this.view;if(Em()){if(this.grabber.clipboard){this.grabber.ask();return}this.notice("Over SSH the clipboard is not here — drop the file");return}let e;try{e=await mv(En(this.scratch,`clipboard-${Date.now()}.png`))}catch(r){this.notice(`Could not read the clipboard: ${Na(r)}`);return}if(clearTimeout(this.peekTimer),t.hint=void 0,"image"in e){await this.bring(async(r)=>({...await vm(e.image,r),source:"clipboard"}));return}let n=e.text.trim();if(!n){this.notice(`No picture on the clipboard — ${$1}`);return}if(this.picture(n)){await this.attach(n);return}if(t.editing===void 0)t.editing="";this.pasted(n)}async attach(t){let e=t.trim();if(/^https?:\/\//i.test(e)){let i=Ya(e,this.site??Y[0]);if(i){await this.jump(i.site,i.id);return}}let[n,...r]=eo(e).sort((i,s)=>Number(!w1.test(i))-Number(!w1.test(s)));if(!n){this.notice("Nothing to use in that — drop a picture, or paste one or its link");return}await this.bring((i)=>vm(n,i),r.length)}async bring(t,e=0){let n=this.view;this.attaching?.abort();let r=new AbortController;this.attaching=r,n.error=void 0,n.saved=void 0,n.note="Reading the picture…",this.paint.draw();let i;try{i=await t(AbortSignal.any([r.signal,this.signal]))}catch(d){if(!r.signal.aborted)n.note=void 0,this.notice(Na(d),8000);return}if(r.signal.aborted)return;n.note=e>0?`The first picture of ${e+1} — drop one at a time to try the others`:void 0,this.quietSuggest(),n.editing=void 0,n.suggest=void 0,n.pick=void 0;let s=dv(i.bytes);fv(s,i.source);let o=this.origPath(Vn,s,i.ext);P(o,i.bytes);let a=d1(o).href,c={id:s,file:a,width:i.width,height:i.height,ext:i.ext,preview:a,owner:"",score:0,rating:"s",md5:S1("md5").update(i.bytes).digest("hex"),source:i.source,tags:[],named:{artist:[],character:[],copyright:[]},solo:void 0,family:0,smaller:[]},u={site:Vn,post:c},l=this.previewPath(u);P(l,i.bytes),++this.gen,this.current=void 0,n.shown=void 0;let f=ll(`local|post:${s}`,!1);this.board=f,this.boards.set(f.key,f),this.single(f,u)}single(t,e){t.searching=!1,this.posts.set(ke(e.site,e.post.id),e),t.groups=[{posts:[e],open:!1}],t.checked=1,t.total=1,this.thumbQueue.push(e),this.thumbs(),this.view.mode="try",this.show(),this.select(),this.paint.draw()}onClock=()=>{let t=this.sites.reduce((r,i)=>Pn(i)>Pn(r)?i:r),e=Math.ceil((Pn(t)-Date.now())/1000),n=e>0?e:void 0;if(n!==this.view.waiting)this.view.waiting=n,this.view.slow=t.name,this.paint.draw()};onResize=()=>{if(this.cols=process.stdout.columns||this.cols,this.rows=process.stdout.rows||this.rows,this.paint.resized(),this.holdThumbs(),this.scroll(),this.paint.snap(),this.view.mode==="try"&&this.current)this.reveal();this.pump(),this.paint.draw()};key(t){let e=this.view;if(t==="ctrl-c"){this.finish(2);return}if(e.installing!==void 0)return;if(t==="focus-in"){this.peek();return}if(t==="focus-out")return;if((t==="ctrl-v"||t==="alt-v")&&e.panel===void 0){this.fromClipboard();return}if(e.editing!==void 0){this.editKey(t);return}if(e.panel!==void 0){this.panelKey(t);return}if(e.help){if(t==="?"||t==="esc")e.help=!1,this.paint.draw();return}if(this.cols<Ci.cols||this.rows<Ci.rows){if(t==="esc")this.finish(2);return}if(t==="?"){e.help=!0,this.paint.draw();return}if(e.mode==="try"){this.tryKey(t);return}this.gridKey(t)}pointer(t){let e=this.view,n=this.paint.point(t),r=n?.target;if(e.installing!==void 0)return;if(t.action==="wheel"){if(!t.sideways)this.wheel(t.wheel);return}if((t.action==="press"||t.action==="drag")&&t.button!=="left")return;if(r?.kind==="track"&&n&&t.action!=="release")this.slide(r.field,n);else if(t.action==="press")this.pressed(r);else if(t.action==="release"&&n?.inside)this.released(r,t)}pressed(t){let e=this.view;if(e.help)this.paint.drop(),this.key("esc");else if(e.editing!==void 0||t===void 0)return;else if(e.panel!==void 0){if(t.kind==="setting"&&t.index<e.settings.length&&e.typing===void 0)e.panel=t.index,this.paint.draw()}else if(e.mode==="try")this.tryPoint(t);else if(t.kind==="tile")this.focus(t.index);else if(t.kind==="query")this.gridKey("/");else if(t.kind==="site")this.tab=t.tab,this.syncSite(),this.turn()}released(t,e){let n=this.view;if(t?.kind==="key")this.key(t.key);else if(t?.kind==="link"){if(!e.shift&&!e.alt&&!e.ctrl)m1(t.url)}else if(n.editing!==void 0){if(t?.kind==="suggest")n.pick=t.index,this.editKey("enter")}else if(n.panel!==void 0)this.panelPoint(t);else if(n.mode==="try"){if(t?.kind==="place"&&n.tuning)this.tuneKey(String(t.at))}else if(t?.kind==="tile"&&e.count===2)this.gridKey("enter");else if(t?.kind==="chip")this.toggle(t.index)}wheel(t){let e=this.view;if(e.help)return;if(e.editing!==void 0){if(e.suggest?.length)this.editKey(t<0?"up":"down")}else if(e.panel!==void 0){if(e.typing===void 0)this.panelKey(t<0?"up":"down")}else if(e.tuning)this.tuneKey(t<0?"up":"down");else if(e.mode==="try")this.tryKey(t<0?"left":"right");else this.focus(e.focus+t*Jn(this.cols,this.rows).perRow)}panelPoint(t){let e=this.view;if(t?.kind!=="setting"&&t?.kind!=="choice")return;let n=e.settings[t.index];if(e.typing!==void 0){let r=e.settings[e.panel??0];if(r&&(t.index!==e.panel||t.kind==="setting"))this.typeKey(r,"enter");else return}if(t.kind==="setting"&&t.index===e.settings.length){e.panel=t.index,this.panelKey("enter");return}if(e.panel=t.index,t.kind==="choice"&&n){if(n.entry==="text"||t.choice===void 0){this.panelKey("enter");return}if(n.multi){n.cursor=Math.max(0,n.choices.indexOf(t.choice)),this.panelKey(" ");return}if(n.value!==t.choice)n.value=t.choice,this.recount()}this.paint.draw()}tryPoint(t){let e=this.view;if(t.kind==="scene")e.scene=t.scene,e.details=!1,this.paint.draw();else if(e.tuning&&t.kind==="field")e.tuning.field=t.field,this.paint.draw()}slide(t,e){let n=this.view,r=n.tuning;if(!r)return;let i=Math.min(1,Math.max(0,e.width>1?e.x/(e.width-1):0));if(r.field=t,t===0){let s=Math.max(100,r.fill),o=fl+Math.round(i*(s-fl+1));n.tune.size=i===1||r.fill>0&&o>=r.fill?"fill":Math.min(s,o)}else n.tune.opacity=Math.round(i*100)/100;this.retune()}gridKey(t){let e=this.view,{perRow:n,rowsVis:r}=Jn(this.cols,this.rows),s={left:-1,right:1,up:-n,down:n,k:-n,j:n,pgup:-n*r,pgdn:n*r,home:-e.focus,end:e.tiles.length}[t];if(s!==void 0){this.focus(e.focus+s);return}if(/^[1-9]$/.test(t)){this.toggle(Number(t)-1);return}if(t==="enter"&&e.tiles[e.focus]){e.mode="try",e.error=void 0,this.select();return}if(t==="v"){this.fromClipboard();return}if(t==="c"){e.preset=e.preset==="cutouts"?"all":"cutouts",this.turn();return}if(t==="tab"||t==="shift-tab"){let o=Y.length+1;this.tab=(this.tab+(t==="tab"?1:o-1))%o,this.syncSite(),this.turn();return}if(t==="/"){e.editing="",this.paint.draw();return}if(t===" "){this.unfold();return}if(t==="o"){this.openPage();return}if(t==="s"){e.panel=0,e.advanced=!1,this.recount(),this.paint.draw();return}if(t==="esc")this.finish(2)}panelKey(t){let e=this.view,n=e.panel??0,r=e.settings[n];if(e.typing!==void 0&&r){this.typeKey(r,t);return}let i=$a(e);if(t==="up"||t==="down"){let s=i.indexOf(n)+(t==="up"?-1:1);e.panel=i[(s+i.length)%i.length]??n,this.paint.draw();return}if(t==="a"||t==="enter"&&n===e.settings.length){e.advanced=!e.advanced,e.panel=$a(e)[0]??0,this.paint.draw();return}if(r?.entry&&(t==="enter"||r.entry==="number"&&/^[0-9]$/.test(t))){e.typing=t==="enter"?r.entry==="text"?r.value:"":t,this.paint.draw();return}if((t==="left"||t==="right")&&r&&r.entry!=="text"){let s=t==="left"?-1:1;if(r.multi)r.cursor=(r.cursor+s+r.choices.length)%r.choices.length;else r.value=nv(r.choices,r.value,s),this.recount();this.paint.draw();return}if(t===" "&&r?.multi){let s=r.value.split(" "),o=r.choices.filter((c,u)=>u===r.cursor?!s.includes(c):s.includes(c)),a=r.multi.none;if(o.length>0||a!==void 0)r.value=o.length>0?o.join(" "):a,this.recount(),this.paint.draw();return}if(t==="esc"){e.settings.forEach((s,o)=>{s.value=this.setting(Wi[o]?.name??"")}),e.panel=void 0,e.advanced=!1,this.quietCount(),this.paint.draw();return}if(t==="enter"||t==="s"||t==="alt-c")e.panel=void 0,e.advanced=!1,this.quietCount(),this.adopt()}typeKey(t,e){let n=this.view,r=n.typing??"";if(e==="esc"){n.typing=void 0,this.paint.draw();return}if(e==="enter"||e==="up"||e==="down"){if(t.value=t.entry==="number"?Number(r)>0?String(Number(r)):"off":yo(r).join(" "),n.typing=void 0,this.recount(),e==="enter"){this.paint.draw();return}this.panelKey(e);return}let i=Pi(r,e,(s)=>t.entry==="number"?/^[0-9]$/.test(s)&&r.length<bm:/^[\x20-\x7e]$/.test(s));if(i!==void 0)n.typing=i,this.paint.draw()}quietCount(){clearTimeout(this.countTimer),this.counting?.abort(),this.counting=void 0}recount(){if(this.quietCount(),this.view.counts=void 0,!this.view.tag)return;let t=new AbortController;this.counting=t,this.countTimer=setTimeout(()=>void this.countPending(t),oC)}pending(){let t=(e)=>this.view.settings[Wi.findIndex((n)=>n.name===e)]?.value??this.setting(e);return{tag:this.view.tag,chosen:this.view.chosen,preset:t("TTHEME_FIND_POSTS")==="all"?"all":"cutouts",order:qm(t("TTHEME_FIND_ORDER")),rating:si(t("TTHEME_FIND_RATING")),narrow:gf(t("TTHEME_FIND_MIN_SCORE"),t("TTHEME_FIND_MIN_SIZE"),t("TTHEME_FIND_PNG")),enabled:ko(t("TTHEME_FIND_SITES"))}}async countPending(t){let e=this.pending(),n=this.site?[this.site]:Y.filter((s)=>e.enabled.includes(s.name)),r=AbortSignal.any([this.signal,t.signal]),i=await Promise.all(n.map(async(s)=>{let o=this.query(s,e);if(!o)return{site:s.name,count:0};if(s.counts&&!s.counts(o.tags))return{site:s.name};try{let a=await kf(s,o.tags,r);return{site:s.name,...Number.isFinite(a)?{count:a}:{}}}catch{return{site:s.name}}}));if(this.counting===t&&this.view.panel!==void 0)this.view.counts=i,this.paint.draw()}adopt(){let t=this.view,e=Wi.map((r)=>this.setting(r.name));t.settings.forEach((r,i)=>{let s=Wi[i];if(s)this.values.set(s.name,r.value)});let n=Wi.filter((r,i)=>this.setting(r.name)!==e[i]);if(n.length===0){this.paint.draw();return}this.save(n),t.rating=si(this.setting("TTHEME_FIND_RATING")),t.block=cs(this.setting("TTHEME_FIND_BLOCK")),t.sets=this.setting("TTHEME_FIND_SETS")==="show"?"show":"fold",t.preset=this.setting("TTHEME_FIND_POSTS")==="all"?"all":"cutouts",t.order=qm(this.setting("TTHEME_FIND_ORDER")),t.solo=this.setting("TTHEME_FIND_SOLO")==="on",t.narrow=this.narrowed(),t.enabled=ko(this.setting("TTHEME_FIND_SITES")),t.hide=qa(this.setting("TTHEME_FIND_HIDE")),t.hideTags=yo(this.setting("TTHEME_FIND_HIDE_TAGS")),this.boards.clear(),this.current=void 0,t.shown=void 0,t.mode="grid",this.search()}save(t){this.store(t.map((e)=>[e.name,this.setting(e.name)]))}store(t){let e=En(this.home,"ttheme","config.zsh");try{let n=Ra(e)?YF(e,"utf8"):"";return P(e,t.reduce((r,[i,s])=>ru(r,i,s),n)),!0}catch(n){return this.view.error=n instanceof Error?n.message:String(n),!1}}editKey(t){let e=this.view,n=e.editing??"",r=e.suggest??[];if((t==="up"||t==="down")&&r.length>0){let o=((e.pick??r.length)+(t==="down"?1:r.length))%(r.length+1);e.pick=o===r.length?void 0:o,this.paint.draw();return}if(t==="esc"||t==="enter")this.quietSuggest();if(t==="esc"){if(e.editing=void 0,e.tag===""){this.finish(2);return}this.paint.draw();return}if(t==="enter"){let s=e.pick===void 0?void 0:r[e.pick],o=s?s.whole?s.value:n.replace(/\S*$/,s.value):n;if(e.editing=void 0,e.suggest=void 0,e.pick=void 0,o.trim()){this.commit(o.trim());return}if(e.tag===""){this.finish(2);return}this.paint.draw();return}let i=Pi(n,t);if(i!==void 0)e.editing=i,this.suggest(),this.paint.draw()}quietSuggest(){clearTimeout(this.suggestTimer),this.suggesting?.abort(),this.suggesting=void 0}suggest(){this.quietSuggest();let t=this.view;t.pick=void 0;let e=t.editing??"",n=/\S*$/.exec(e)?.[0]??"",r=rC(n),i=Dw(e,y1,this.tagged).map((c)=>({value:c.tag,count:0,alias:c.name,whole:!0}));if(!r&&i.length===0){t.suggest=void 0;return}let s=r?M0(this.catalog.palettes,this.entry,n).map((c)=>({value:c.booru,count:0,palette:c.name})):[],o=[...new Map([...s.slice(0,y1),...i].map((c)=>[c.value,c])).values()];if(t.suggest=o.length>0?o:void 0,i.length>0&&gC.test(e))t.pick=o.findIndex((c)=>("whole"in c));if(!r)return;let a=new AbortController;this.suggesting=a,this.suggestTimer=setTimeout(async()=>{try{let c=await jb(n,AbortSignal.any([this.signal,a.signal]));if(this.suggesting===a&&t.editing!==void 0){let u=new Map(c.map((f)=>[f.value,f.count])),l=new Set(o.map((f)=>f.value));t.suggest=[...o.map((f)=>({...f,count:u.get(f.value)??0})),...c.filter((f)=>!l.has(f.value))].slice(0,bC),t.pick=t.pick!==void 0&&t.pick<o.length?t.pick:void 0,this.paint.draw()}}catch{}},sC)}async commit(t){let e=Ya(t,this.site??Y[0]);if(e){await this.jump(e.site,e.id);return}if(this.picture(t)){await this.attach(t);return}this.view.tag=t,this.view.chosen=void 0,this.relate(t),this.boards.clear(),await this.search()}async jump(t,e){let n=++this.gen;this.tab=Y.indexOf(t)+1,this.syncSite(),this.current=void 0,this.view.shown=void 0,this.view.error=void 0;let r=ll(`${t.key}|post:${e}`,!0);this.board=r,this.boards.set(r.key,r),this.show(),this.paint.draw();try{let i=await us(t,e,this.signal);if(n!==this.gen)return;if(!i){r.searching=!1,r.error=`${t.name} has no post ${e}`,this.view.error=r.error,this.show(),this.paint.draw();return}this.single(r,{site:t,post:i})}catch(i){this.fail(n,i,t)}}async turn(){this.fetch?.abort(),this.current=void 0,this.view.shown=void 0;let t=this.boards.get(this.boardKey);if(!t){await this.search();return}this.gen++,this.board=t,this.view.error=t.error,this.show(),this.paint.draw(),await this.pump()}unfold(){let t=this.view,e=0;for(let n of this.board.groups){let r=n.open?n.posts.length:1;if(t.focus<e+r){if(n.posts.length<2)return;n.open=!n.open,this.board.focus=e;for(let i of n.posts)if(!this.thumbPath.has(ke(i.site,i.post.id)))this.thumbQueue.push(i);this.thumbs(),this.show(),this.scroll(),this.paint.glide(),this.paint.draw();return}e+=r}}openPage(){let t=this.view.tiles[this.view.focus],e=t&&this.posts.get(t.key);if(e)m1(e.site.pageUrl(e.post.id))}tryKey(t){let e=this.view;if(e.tuning){this.tuneKey(t);return}if(t==="left"||t==="right"){this.direction=t==="left"?-1:1,this.focus(e.focus+this.direction);return}if(t==="shift-left"||t==="shift-right"){e.scene+=t==="shift-left"?-1:1,e.details=!1,this.paint.draw();return}if(t==="i"){e.details=!e.details,this.inform(),this.paint.draw();return}if(t==="t"){e.tuning={field:0,held:{...e.tune},fill:this.current?.fill??0,coloring:e.coloring},this.paint.draw();return}if(t==="c"){this.recolor();return}if(t==="o"){this.openPage();return}if(t==="x"){this.swap();return}if(t==="v"){this.fromClipboard();return}if(t==="enter"){this.install();return}if(t==="esc")this.fetch?.abort(),clearTimeout(this.settle),e.fetching=void 0,e.mode="grid",e.error=void 0,this.paint.draw()}tuneKey(t){let e=this.view,n=e.tuning,r=e.tune;if(t==="up"||t==="down"){n.field=(n.field+(t==="up"?2:1))%3,this.paint.draw();return}let i=tC[t];if(i!==void 0){if(n.field===0)r.size=eC(r.size,i,n.fill);else if(n.field===1)r.at=(r.at-1+Math.sign(i)+9)%9+1;else r.opacity=Math.max(0,Math.min(100,Math.round(r.opacity*100)+i))/100;this.retune();return}if(/^[1-9]$/.test(t)){n.field=1,r.at=Number(t),this.retune();return}if(t==="="){let s=e.untuned;if(n.field===0)r.size=s.size;else if(n.field===1)r.at=s.at;else r.opacity=s.opacity;this.retune();return}if(t==="+"){e.tune={...e.untuned},this.retune();return}if(t==="enter"){e.tuning=void 0,this.paint.draw();return}if(t==="c"){this.recolor();return}if(t==="esc")e.tune={...n.held,...n.coloring===e.coloring?{}:{opacity:e.untuned.opacity}},e.tuning=void 0,this.retune()}recolor(){let t=this.view;if(!this.current||t.shown?.id!==this.current.key)return;t.coloring=t.coloring==="tone"?"original":"tone",t.tune.opacity=t.untuned.opacity,this.paint.draw(),this.reveal()}retune(){if(this.paint.draw(),this.current&&this.view.shown?.id===this.current.key)this.reveal()}inform(){let t=this.view,e=t.tiles[t.focus],n=e&&this.posts.get(e.key);t.info=n?this.infoOf(n):void 0}infoOf(t){let{site:e,post:n}=t,r=n.named,i=Hb(e,n),s=new Set([...r.artist,...r.character,...r.copyright]),o=vo(n.source),a=/^https?:\/\//i.test(o)?o:e===Vn&&o.startsWith("/")?d1(o).href:void 0;return{page:e===Vn?"":e.pageUrl(n.id),source:o,...a?{link:a}:{},artists:r.artist,characters:r.character,series:r.copyright,tags:n.tags.filter((c)=>!s.has(c)),...i?{rating:i}:{},...n.posted?{posted:n.posted}:{},ext:(fn(n)??n).ext,uploader:n.owner}}focus(t){let e=this.view;if(e.tiles.length===0)return;let n=Math.max(0,Math.min(e.tiles.length-1,t));if(n===e.focus)return;if(e.focus=n,this.board.focus=n,this.scroll(),this.paint.glide(),this.pump(),e.mode==="try")this.select();this.paint.draw()}scroll(){let t=this.view,{perRow:e,rowsVis:n}=Jn(this.cols,this.rows),r=Math.floor(t.focus/e);if(r<t.top)t.top=r;if(r>t.top+n-1)t.top=r-n+1;this.board.top=t.top}selected(t){if(t.chosen)return t.chosen;if(!t.tag)return[];return this.namesOf(t.tag,"danbooru")}namesOf(t,e){let n=t===this.entry.booru?this.entry:this.catalog.palettes.find((r)=>r.booru===t);return n?O0(n,e):[t]}syncChips(){let t=this.selected(this.view);this.view.chips=this.pool.slice(0,wC).map((e)=>({name:e,on:t.includes(e)}))}toggle(t){let e=this.view,n=e.chips[t];if(!n)return;let r=this.selected(e),i=n.on?r.filter((s)=>s!==n.name):[...r,n.name];if(i.length===0)return;e.chosen=i,e.tag=i.join(" or "),this.syncChips(),this.boards.clear(),this.search()}async relate(t){this.relating?.abort();let e=this.selected({tag:t,chosen:void 0});if(this.pool=e,this.syncChips(),this.paint.draw(),!t||/\s/.test(t))return;let n=this.related.get(t);if(!n){let r=new AbortController;this.relating=r;try{n=(await _b(t,AbortSignal.any([this.signal,r.signal]))).map((i)=>i.value)}catch{return}if(this.relating!==r)return;this.related.set(t,n)}this.pool=[...new Set([...e,...n])],this.syncChips(),this.paint.draw()}query(t,e=this.view){let n=e.chosen?Gb(t,e.chosen):this.namesOf(e.tag,t.key);if(n.length===0)return;let r=e.chosen?.slice(n.length)??[],i=n.length>1,s=e.preset==="cutouts"?t.cutouts:"",o=i&&s.includes("~"),a=[i?n.map((l)=>`~${l}`).join(" "):n[0],t.rate(e.rating),...t.narrow(e.narrow),o?"":s,e.order==="score"?t.best:""].filter(Boolean),c=[],u=[];for(let l of a)if($f([...c,l].join(" "))<=t.tagBudget)c.push(l);else u.push(l);return{tags:c.join(" "),notes:[...u.length>0?[`${t.name} takes ${t.tagBudget} tags — ${u.join(" ")} left out`]:[],...r.length>0?[`${t.name} takes ${n.length} tag${n.length===1?"":"s"} — ${r.join(" ")} left out`]:[],...o?[`${t.name} ORs the names, so cutouts are told by the file`]:[],...e.narrow.score>0&&!t.scored?[`${t.name} keeps no score`]:[],...e.narrow.png&&t.guesses?[`${t.name} names a file type only where danbooru holds the file`]:[]]}}async search(){let t=++this.gen,e=ll(this.boardKey,!0);this.board=e,this.boards.set(e.key,e),this.view.error=void 0;let n=this.sites.flatMap((s)=>{let o=this.query(s);return o?[{site:s,...o}]:[]}),r=this.sites.filter((s)=>!n.some((o)=>o.site===s)),i=[...n.flatMap(({notes:s})=>s),...r.length>0?[`${this.entry.name} has no tag on ${r.map((s)=>s.name).join(", ")}`]:[]];if(e.note=i.length>0?i.join(" · "):void 0,n.length===0)e.searching=!1;this.show(),this.paint.draw(),this.tally(t,e,n);try{let s=await Promise.all(n.map(async(o)=>({plan:o,owners:await this.kept.mateOwners(o.site)})));if(t!==this.gen)return;e.sources=s.flatMap(({plan:{site:o,tags:a},owners:c})=>{let u=$f(a)+1<=o.tagBudget?o.uploadedBy:void 0;return[...u?[...c.keys()].map((l)=>({site:o,tags:`${a} ${u(l)}`,page:0,done:!1})):[],{site:o,tags:a,page:0,done:!1}]}),this.show(),this.paint.draw(),await this.pump()}catch(s){this.fail(t,s)}}async tally(t,e,n){let r=await Promise.allSettled(n.map(({site:i,tags:s})=>kf(i,s,this.signal)));if(t===this.gen)e.total=r.reduce((i,s)=>i+(s.status==="fulfilled"&&Number.isFinite(s.value)?s.value:0),0),this.show(),this.paint.draw()}fail(t,e,n=this.site){if(t!==this.gen||this.signal.aborted)return;this.board.error=Ym(n?.name??this.tabName,e),this.board.searching=!1,this.view.error=this.board.error,this.show(),this.paint.draw()}drop(t,e,n){for(let r of t.sources)if(r.site===e)r.done=!0;t.note=[t.note,Ym(e.name,n)].filter(Boolean).join(" · ")}wants(){let{perRow:t,rowsVis:e}=Jn(this.cols,this.rows);return this.view.tiles.length<(this.board.top+e+k1)*t}need(){let{perRow:t,rowsVis:e}=Jn(this.cols,this.rows);return(e+k1)*t}live(t){return this.boards.get(t.key)===t}page(t,e,n){let r=`${t.key}|${e}|${n}`,i=this.pages.get(r);if(!i)i=Lb(t,e,n,this.signal).then((s)=>this.borrow(t,s)),this.pages.set(r,i),i.catch(()=>this.pages.delete(r));return i}async borrow(t,e){let n=t===Qt?[]:e.filter((r)=>r.md5!=="");if(n.length>0)try{ec(n,await nc(n.map((r)=>r.md5),this.signal))}catch{}return e}staged(t){if(t===this.board)this.stageOf(t),this.paint.draw()}async round(t){t.stage="fetch",this.staged(t);let e=Y.flatMap((a)=>{let c=t.sources.find((u)=>u.site===a&&!u.done);return c?[c]:[]}),n=await Promise.all(e.map(async(a)=>{try{let c=await this.page(a.site,a.tags,a.page);return t.arrived.add(a.site.name),this.staged(t),{source:a,posts:c}}catch(c){if(t.sources.every((u)=>u.site===a.site)||this.signal.aborted)throw c;return this.drop(t,a.site,c),{source:a,posts:void 0}}}));if(!this.live(t))return;let r=[];for(let{source:a,posts:c}of n){if(!c)continue;a.page++,a.done=c.length<ur;let u=t.last.get(a);for(let l of c){let f=u&&Av(u.post,l)?u.set:`set:${a.site.key}:${l.id}`;u={post:l,set:f};let d=ke(a.site,l.id);if(t.seen.has(d))continue;t.seen.add(d);let h={site:a.site,post:l};if(this.eligible(h))t.kin.set(h,[f,...Tv(a.site,l)]),r.push(h);else t.checked++}if(u)t.last.set(a,u)}let i=this.dedupe(t,r),s=++t.rounds,o;if(this.view.order!=="fit")o=e.length>1?Rv(i):i;else{let a=rl(i,this.frame(),this.matched),c=a.slice(0,this.need()),u={done:0,total:c.length};if(t.ranking=u,this.staged(t),await this.looks(c,()=>{u.done++,this.staged(t)}),t.ranking=void 0,!this.live(t))return;o=[...rl(c,this.frame(),this.matched),...a.slice(c.length)]}t.stage="check",this.staged(t);for(let a of o)t.roundOf.set(a,s);t.queue.push(...o),this.ahead(t)}ahead(t){if(this.aheading||this.view.order!=="fit"||!this.live(t))return;let e=t.queue.slice(0,this.need()).filter((n)=>!this.looking.has(ke(n.site,n.post.id)));if(e.length===0)return;this.aheading=!0,this.looks(e).then(()=>{this.aheading=!1;for(let n of new Set(e.map((r)=>t.roundOf.get(r)??0)))this.resort(t,n);this.ahead(t)})}resort(t,e){let n=t.queue.flatMap((i,s)=>t.roundOf.get(i)===e?[s]:[]),r=rl(n.map((i)=>t.queue[i]),this.frame(),this.matched);n.forEach((i,s)=>{t.queue[i]=r[s]})}dedupe(t,e){let n=[];for(let r of e){let i=Pm(r.post),s=i.map((a)=>t.same.get(a)).find(Boolean);if(!s){for(let a of i)t.same.set(a,r);n.push(r);continue}if(t.checked++,v1(r.post)<=v1(s.post))continue;for(let a of[...i,...Pm(s.post)])t.same.set(a,r);let o=n.indexOf(s);if(o>=0){n[o]=r;continue}this.replace(t,s,r)}return n}replace(t,e,n){t.roundOf.set(n,t.roundOf.get(e)??0);let r=t.queue.indexOf(e);if(r>=0){t.queue[r]=n;return}for(let i of t.groups){let s=i.posts.indexOf(e);if(s>=0){i.posts[s]=n,this.posts.set(ke(n.site,n.post.id),n),this.thumbQueue.push(n),this.thumbs();return}}}async looks(t,e){let n=0;await Promise.all(Array.from({length:b1},async()=>{while(n<t.length)await this.look(t[n++]),e?.()}))}look(t){let e=ke(t.site,t.post.id),n=this.looking.get(e);if(!n)n=(async()=>{let r=this.previewPath(t),i=Ja(t.site,t.post);await this.kept.cached(i.site,r,i.url);let s=await this.renders.run({job:"match",from:r,colors:this.entry.signature});return this.looked.set(e,s),this.matched.set(t.post,s.match),s})().catch(()=>{return}),this.looking.set(e,n);return n}async pump(){let t=this.gen,e=this.board;if(this.pumping===t||e.sources.length===0)return;this.pumping=t;let n=[],r;try{e.searching=!0;while(t===this.gen){while(n.length<g1&&e.queue.length>0&&this.wants()){let o=e.queue.shift();n.push({pick:o,passed:this.vet(o)})}if(this.ahead(e),!r&&e.queue.length<g1&&e.sources.some((o)=>!o.done)&&this.wants()){let o=this.round(e).then(()=>{if(r===o)r=void 0});o.catch(()=>{}),r=o}let i=n.shift();if(!i){if(!r)break;await r,this.show(),this.paint.draw();continue}let s=await i.passed;if(t!==this.gen)return;if(e.checked++,s)this.admit(i.pick);this.show(),this.paint.draw()}if(t===this.gen)e.searching=!1,this.show(),this.paint.draw()}catch(i){this.fail(t,i)}finally{if(this.kept.save(),this.pumping===t)this.pumping=0}}eligible({site:t,post:e}){let n=fn(e);if(!Za(t,e,this.view.rating)||Va(e,this.view.block).length>0||!n)return!1;if(this.view.solo&&e.solo===!1)return!1;let{score:r,size:i,png:s}=this.view.narrow;if(Math.min(e.width,e.height)<i||t.scored&&e.score<r||s&&e.ext!=="png"||Pb(e,this.view.hide).length>0||this.view.hideTags.some((o)=>e.tags.includes(o)))return!1;return this.view.preset==="all"?["png","jpg","jpeg",""].includes(n.ext):["png",""].includes(e.ext)}async vet(t){let[e]=await Promise.all([this.passes(t),this.look(t)]);return e}async passes({site:t,post:e}){return this.view.preset==="all"||t.vouched||this.kept.transparent(t,e)}admit(t){let{site:e,post:n}=t,r=this.board,i=ke(e,n.id);this.posts.set(i,t);let s=r.kin.get(t)??[],o=this.looked.get(i),a=o&&{hash:o.hash,width:n.width,height:n.height},c=this.view.sets==="fold"?this.kindred(r,s,a):void 0;if(c){if(c.posts.push(t),this.register(r,c,s,a),c.open)this.thumbQueue.push(t),this.thumbs();return}let u={posts:[t],open:!1};r.groups.push(u),this.register(r,u,s,a),this.thumbQueue.push(t),this.thumbs()}kindred(t,e,n){for(let r of e){let i=t.kindred.get(r);if(i)return i}return n&&t.shapes.find((r)=>Hv(r.shape,n))?.group}register(t,e,n,r){for(let i of n)if(!t.kindred.has(i))t.kindred.set(i,e);if(r)t.shapes.push({shape:r,group:e})}holds(){this.view.held=p1(this.home,this.entry.name).map((t)=>{let e=this.heldFiles.get(t.from);return e?{...t,thumb:e}:t}),this.holdThumbs()}holdThumbs(){let t=me.cols*this.cell.w,e=me.rows*this.cell.h;if(t===0||e===0)return;for(let n of this.view.held.slice(0,pm(this.cols))){if(n.thumb||this.heldAsked.has(n.from))continue;this.heldAsked.add(n.from);let r=En(this.scratch,`held-${ZF(n.from)}-${t}x${e}.png`);this.renders.run({job:"thumb",from:n.from,to:r,width:t,height:e}).then(()=>{this.heldFiles.set(n.from,r),this.holds(),this.paint.draw()}).catch(()=>{})}}thumbs(){while(!this.signal.aborted&&this.thumbing<b1&&this.thumbQueue.length>0){let t=this.thumbQueue.shift();this.thumbing++,this.thumb(t).catch(()=>{this.thumbless.add(ke(t.site,t.post.id)),this.show(),this.paint.draw()}).finally(()=>{this.thumbing--,this.thumbs()})}}async thumb(t){let{site:e,post:n}=t,r=gt.cols*this.cell.w,i=gt.rows*this.cell.h,s=Ja(e,n),o=En(Ke(e),"tile",`${E1(n.id,s.url)}-${r}x${i}.png`);if(!Ra(o)){let a=this.previewPath(t);if(await this.kept.cached(s.site,a,s.url),this.signal.aborted)return;await this.renders.run({job:"thumb",from:a,to:o,width:r,height:i})}this.thumbPath.set(ke(e,n.id),o),this.show(),this.paint.draw()}select(){let t=this.view,e=t.tiles[t.focus];if(this.fetch?.abort(),clearTimeout(this.settle),t.fetching=void 0,this.inform(),!e)return;if(this.current?.key===e.key){this.reveal();return}this.settle=setTimeout(()=>void this.load(e),cC),this.paint.draw()}async load(t){let e=this.view,n=this.posts.get(t.key);if(!n)return;let r=new AbortController;if(this.fetch=r,this.kept.credit(n,r.signal),!fn(n.post))return;let{site:i}=n,s=this.board;try{await So(i,n.post,r.signal);let o=fn(n.post),a=this.origPath(i,t.id,o.ext);if(!Ra(a))e.fetching={id:t.key,got:0,size:0},this.paint.draw();let c=oi(i,n.post,o),u=await this.kept.cached(c.site,a,c.url,(d,h)=>{if(e.fetching?.id===t.key)e.fetching={id:t.key,got:d,size:h},this.paint.draw()});if(r.signal.aborted)return;if(e.fetching=void 0,s!==this.board)return;let l={site:i,id:t.id,key:t.key,path:a,ext:o.ext,size:u,using:"plain",failed:!1};e.preparing=t.key,this.paint.flush();let f=await this.render(l,"plain");if(r.signal.aborted||s!==this.board)return;if(f.clear===0&&Gs()&&this.setting("TTHEME_FIND_REMOVE_BG")!=="off"){if(e.preparing=void 0,e.cutting=t.key,this.paint.flush(),l.cut=await this.cutOut(i,t.id,a,r.signal),r.signal.aborted||s!==this.board)return;if(e.cutting=void 0,l.cut){e.preparing=t.key,this.paint.flush();let d=await this.render(l,"cut").catch(()=>{return});if(r.signal.aborted||s!==this.board)return;if(d&&Iu(d.clear))l.using="cut";else ul(l.cut,{force:!0}),l.cut=void 0,l.failed=!0}else l.failed=!0}if(this.current=l,e.tiles[e.focus]?.key===t.key)await this.present();this.preload()}catch(o){if(!r.signal.aborted&&!this.signal.aborted)e.error=Ym(i.name,o)}finally{if(e.fetching?.id===t.key)e.fetching=void 0;if(e.preparing===t.key)e.preparing=void 0;if(e.cutting===t.key)e.cutting=void 0;this.paint.draw()}}async cutOut(t,e,n,r){let i=En(Ke(t),"cut",`${e}.png`);if(Ra(i))return i;try{return DF(QF(i),{recursive:!0}),await ea(n,i,r),i}catch{ul(i,{force:!0});return}}swap(){let t=this.current;if(!t?.cut||this.view.shown?.id!==t.key)return;t.using=t.using==="cut"?"plain":"cut",this.reveal()}preload(){let t=this.view;if(t.mode!=="try")return;for(let e of[t.focus+this.direction,t.focus-this.direction]){let n=t.tiles[e],r=n&&this.posts.get(n.key);if(r)this.kept.credit(r,this.signal);if(this.prefetching>=aC||!r||!fn(r.post))continue;let{site:i,post:s}=r;this.prefetching++,So(i,s,this.signal).then(async()=>{let o=fn(s),a=this.origPath(i,s.id,o.ext),c=oi(i,s,o);return await this.kept.cached(c.site,a,c.url),this.render({site:i,id:s.id,key:n.key,path:a,ext:o.ext,size:0,using:"plain",failed:!1},"plain")}).catch(()=>{}).finally(()=>{this.prefetching--})}}async render(t,e){let n=this.cols*this.cell.w,r=this.rows*this.cell.h,i=Math.min(n,hC),s=Math.max(1,Math.round(r*i/n)),o={...this.view.tune},{coloring:a}=this.view,c=!M1(o,this.view.untuned),u=o.opacity!==this.view.untuned.opacity,l=c?`-${o.size}-${o.at}${u?`-${Math.round(o.opacity*100)}`:""}`:"",f=En(this.scratch,`${t.site.key}-${t.id}${e==="cut"?"c":""}${a==="original"?"o":""}-${i}x${s}${l}.png`),d=`${t.site.key}:${t.id}:${e}:${a}:${i}x${s}`,h=this.clarity.get(d);if(h&&Ra(f))return t.fill=h.fill,{clear:h.clear,path:f,opacity:h.opacity,touched:u};let m=await this.renders.run({job:"show",from:e==="cut"?t.cut:t.path,to:f,width:i,height:s,colors:this.entry,tone:this.tone,blur:this.blurring*i/Ff(n,r).width,coloring:a,...c?{tune:{size:o.size,at:o.at,...u?{opacity:o.opacity}:{}}}:{}});if(this.clarity.set(d,m),t.fill=m.fill,c)this.keepTuned(f);return{clear:m.clear,path:f,opacity:m.opacity,touched:u}}keepTuned(t){this.tunedFiles.push(t);while(this.tunedFiles.length>mC){let e=this.tunedFiles.findIndex((n)=>n!==this.view.shown?.path&&n!==t);if(e===-1)return;ul(this.tunedFiles.splice(e,1)[0],{force:!0})}}async present(){let t=this.current;if(!t)return;let e=t.using,{coloring:n}=this.view,r=this.view.tune.opacity,{clear:i,path:s,opacity:o,touched:a}=await this.render(t,e);if(this.current!==t||t.using!==e||this.view.coloring!==n)return;if(!a&&this.view.tune.opacity===r)this.view.untuned.opacity=o,this.view.tune.opacity=o;if(this.view.tuning&&t.fill)this.view.tuning.fill=t.fill;this.view.shown={id:t.key,clear:i,bytes:t.size,path:s,cut:t.cut?e==="cut"?"on":"off":t.failed?"failed":"none"}}reveal(){let t=this.view;if(this.presenting){this.again=!0;return}this.presenting=!0,t.preparing=this.current?.key,this.paint.flush(),this.present().catch((e)=>{t.error=e instanceof Error?e.message:String(e)}).finally(()=>{if(this.presenting=!1,this.again){this.again=!1,this.reveal();return}if(t.preparing===this.current?.key)t.preparing=void 0;this.paint.draw()})}async install(){let t=this.view,e=t.tiles[t.focus],n=this.current;if(!e||n?.key!==e.key||t.preparing!==void 0||t.shown?.id!==e.key)return;t.installing=e.key,t.error=void 0,this.paint.flush();let r=nC(t.tune,t.untuned),i=this.posts.get(n.key)?.post;try{await this.renders.run({job:"backdrop",from:n.using==="cut"?n.cut:n.path,source:n.path,home:this.home,colors:this.entry,tone:this.tone,origin:{site:n.site.key,id:n.id,ext:n.ext,from:`${n.site.name} ${n.id} ${n.site.pageUrl(n.id)}`,artist:i?.named.artist??[],source:vo(i?.source??"")},width:this.cols*this.cell.w,height:this.rows*this.cell.h,blur:this.blurring,coloring:t.coloring,...r?{tune:r,aligns:xi(L(this.home).terminals),user:JF()}:{}}),this.kept.owned(n.site,n.id,i?.owner??""),Re(this.home),this.holds();let{size:s,at:o,opacity:a}=t.tune,c=r?` · ${s==="fill"?"fill":`${s}%`} · ${Ut[o-1]} · ${a.toFixed(2)}`:"",u=i?.named.artist.length?`${i.named.artist.join(", ")} · `:"";t.saved={text:`Background · ${this.entry.name} ← ${u}${n.site.name} ${n.id}${c}`,key:e.key},t.installed.push(e.key),this.fetch?.abort(),clearTimeout(this.settle),t.fetching=void 0,t.mode="grid"}catch(s){t.error=s instanceof Error?s.message:String(s)}t.installing=void 0,this.paint.draw()}}async function O1(t,e,n){let r=new Jm(t,ue(t),e,e.booru??"",n);if(await r.run(),$i(process.env))process.stdout.write(ki(""));return{saved:r.saved,installs:r.installs}}async function x1(t){let e=J(),n=ue(e),r=_n(n.palettes,t);if(!process.stdin.isTTY||!process.stdout.isTTY)throw Error("needs a terminal");let i=new Jm(e,n,r,r.booru??""),s=await i.run();if(i.saved&&s!==0)return process.stderr.write(`${i.saved}
711
- `),0;return s}import{spawn as $C,spawnSync as I1}from"node:child_process";import{existsSync as kC,readFileSync as R1}from"node:fs";import{homedir as yC}from"node:os";import{join as N1}from"node:path";function T1(t,e,n,r=yC(),i=(s)=>{process.stdout.write(s)}){if(!e||Lt(t)||t.TMUX||Kt(t)!=="terminal-app")return;let[s="",o="-"]=(t.TTHEME_TERMINAL_SHOWN??"").split(" "),a=t.TTHEME_TTY,c=s?Se(q(n),s,r):void 0,u=mu(Fs(n)).get(Xt(s))??[],l=u.find((W)=>W===`${H(s)}.${o}.png`)??u[0];if(!a||!c||o==="-"||!l||!kC(c.image))return;let f=N1(Fs(n),l),d=["-l","JavaScript",hu(n),"tab",a,Qe(s)],h=L(n).terminalBase??"Basic",m=wh(t,r),$=R1(f),g,b=f,y=0,E,S=!1,x=!1,R,N=(W)=>{S=!0,$C("osascript",[...d,h],{stdio:"ignore"}).on("close",()=>{if(S=!1,x)return;i(W);let Q=R;R=void 0,Q?.()})},F=(W,Q)=>{g??=Ht(new Uint8Array(R1(c.image)));let U=N1(Fs(n),`${H(s)}.h${process.pid}-${++y}.png`);Xr(b,U,cr(ar(g,W,c.opacity,$h(g.width,g.height,c,m)))),b=U,N(Q)},_=()=>{if(b!==f)Xr(b,f,$),b=f},B=(W)=>{clearTimeout(E),E=setTimeout(()=>{if(S)R=W;else W()},Bd)},tt=()=>{clearTimeout(E),R=void 0};return{slots:[],paint(W){return B(W.name===s?()=>{_(),N("")}:()=>F(W.background,zn(W))),""},look(W,Q){B(()=>F(Q[0]??"",Q.map((U,yt)=>Uo(yt,U)).join("")))},wear(W){return I1("osascript",[...d.slice(0,-1),Qe(W.name),h],{encoding:"utf8"}).stdout?.trim()==="worn"?"":zn(W)},saved:async()=>new Map,restore(){return tt(),x=!0,_(),I1("osascript",[...d,h],{stdio:"ignore"}),""},stop:tt}}import{existsSync as Ta,readdirSync as vC,readFileSync as hl,rmSync as A1,statSync as H1}from"node:fs";import{homedir as EC}from"node:os";import{join as Ki}from"node:path";var SC=150,MC=260;function dl(t){return t?.includes(`path = "${H("")}`)===!0}function OC(t){try{return L(t).terminals.includes("warp")}catch{return!1}}function P1(t,e){let n=H(e);if(!Ta(t))return;return vC(t).filter((i)=>i.startsWith(`${n}.`)&&/^[0-9a-f]{8}\.yaml$/.test(i.slice(n.length+1))).map((i)=>({file:i,at:H1(Ki(t,i)).mtimeMs})).sort((i,s)=>s.at-i.at)[0]?.file??(Ta(Ki(t,`${n}.yaml`))?`${n}.yaml`:void 0)}function xC(t,e){if(!e)return;let n;try{n=hl(Ki(t,e),"utf8")}catch{return}let r=/^background_image:\n\s+path:\s*"([^"]*)"\n\s+opacity:\s*(\d+)/m.exec(n);return r?.[1]?{image:r[1],opacity:Number(r[2])/100}:void 0}function F1(t,e,n,r=EC()){if(!e||Lt(t)||t.TMUX||Kt(t)!=="warp")return;let i=Fr(r,n);if(!Ta(i)||!OC(n))return;let s=Si(r),o=gu(n),a=[],c=t.TTHEME_WARP_WEARS??Ie(L(n)),u=xC(s,c&&P1(s,c)),l,f,d=(g)=>{let b=hl(i,"utf8"),y=Cr(b);if(y===g)return;if(dl(g)&&!dl(y)&&!Ta(o))P(o,y??"");if(an(i,bu(b,g)),!dl(g))A1(o,{force:!0})},h=(g)=>{for(let b of a.splice(0))if(b===g)a.push(b);else A1(Ki(s,b),{force:!0})},m=()=>{clearTimeout(l),clearTimeout(f)},$=(g,b,y)=>{m(),l=setTimeout(()=>{let E=b;if(!E)E=`${H(g.name)}.view-${process.pid}-${a.length+1}.yaml`,P(Ki(s,E),Jo(g,y)),a.push(E);let S=E,x=Date.now()-H1(Ki(s,S)).mtimeMs;f=setTimeout(()=>{d(Eh(g.name,S)),h(S)},Math.max(0,MC-x))},SC)};return{slots:[],paint:(g)=>{if(g.name===c)$(g,P1(s,g.name));else if(u)$(g,void 0,u);else $(g,Ta(Ki(s,`${H(g.name)}.yaml`))?`${H(g.name)}.yaml`:void 0);return""},look:(g,b)=>{let[y="",E="",S="",,...x]=b;$({name:g,background:y,foreground:E,cursor:S,ansi:x},void 0,u)},wear:(g,b)=>b.includes("warp")?"":void 0,saved:async()=>new Map([["theme",Cr(hl(i,"utf8"))??""]]),restore:(g)=>{m();let b=g.get("theme");if(b)d(b);else if(dl(Cr(hl(i,"utf8"))))d(pu);return h(),""}}}function zr(t,e,n){return T1(t,e,n)??f$(t,e)??F1(t,e,n)}function Zm(){return process.stdin.isTTY===!0&&process.stdout.isTTY===!0}function C1(t,e){if(t.includes("/"))return t;let n=pi(e,!1),r=n.filter((s)=>Os(s.dir).some((o)=>o.slug===t)),[i]=r.length===1?r:n.length===1?n:[];return i?`${i.id}/${t}`:t}function NC(t,e,n){let r=L(t),i=n.filter((s)=>!r.palettes.includes(s));if(i.length>0)je(t,e,r,{...r,palettes:[...r.palettes,...i]});else if(n.some((s)=>r.palettes.includes(s)))jt(t,e,r);return{state:r,fresh:i}}function TC(t){let e=Math.max(0,...t.map((n)=>n.slot.length));return t.map((n)=>` ${n.slot.padEnd(e)} ${n.from} → ${n.to} ${n.rule}`)}function L1(t,e,n){let r=l0(e),i=mn(Cn(r.name,ad(r),n.palettes,!0)),s=Ot(t,n,!1).palettes.find((o)=>o.name===i.name);if(s&&JSON.stringify(s)!==JSON.stringify(i))throw Error(`${i.name} is already in ${lt(i.name)??"the ttheme catalog"} and differs — \`ttheme add ${i.name}\` wears that one`);if(!s)Ic(t,[...jn(t),i]);return i.name}var AC=["background","foreground","cursor"];function j1(t){try{t();return}catch(e){return e.message}}function _1(t,e,n){return Ot(t,e,!1).palettes.filter((r)=>r.name!==n).map((r)=>({name:r.name,colors:{background:r.background,foreground:r.foreground,cursor:r.cursor,selection:r.selection,ansi:r.ansi}}))}function G1(t,e){let n=new Set(ce(t,e).map((r)=>r.key));return{count:()=>ce(t,e).length,added:()=>ce(t,e).filter((r)=>!n.has(r.key)).length,fresh:()=>(Nu(t,e)??[]).filter((r)=>!n.has(te(r))),discard:()=>{let r=ce(t,e).filter((i)=>!n.has(i.key));for(let i of r)bs(t,e,i.key),lc(t,e);if(r.length>0)Re(t)}}}function PC(...t){let e=new Map;for(let n of t.flatMap((r)=>r??[]))e.set(te(n),n);return e.size>0?[...e.values()]:void 0}function B1(t,e,n,r){if(!Vc(process.env,L(t).terminals))return;return async(i,s)=>{let o=mn(Cn(e,r(i),n.palettes)),{saved:a}=await O1(t,o,s);return{...a?{note:a}:{},count:ce(t,e).length}}}async function U1(t){let e=process.stdout.isTTY===!0,n=J(),r=zr(process.env,e,n),i=r?await r.saved():new Map,s=r?.look?{look:(a)=>r.look?.(t.name,a)}:r?{only:r.slots}:{},o=e?al.of(process.env,n,t.name,L(n).terminals):void 0;try{return await u1(t,{color:!Lt(),...s,...o?{backdrop:o}:{}})}finally{if(r)process.stdout.write(r.restore(i))}}async function W1(t,e,n){let r=J(),i=ut(r),s=await dy(r,n),o=t.includes("/")?t:`${s.id}/${t}`,a=ve(o);if(a)throw Error(`${o} ${a}`);if(lt(o)!==s.id)throw Error(`palettes in ${s.dir} are named ${s.id}/<palette> — ${o} belongs elsewhere`);let c=id(r,o);if(Aa(c))throw Error(`${o} already exists — \`ttheme edit ${o}\` changes it`);let u=e?_n(Ot(r,i).palettes,e):void 0;if(!Zm())throw Error("new opens the palette editor — run it in a terminal");let l=u&&(lt(u.name)?u.base:u.default?void 0:u.name),f=u?od(u,o,`kept from ${u.name}`):void 0,d=u?Nu(r,u.name)??u.pictures:void 0,{base:h,ansiSource:m,group:$,...g}=f??{name:o,signature:AC,...Wr(Ea)},b=G1(r,o),y=({colors:x,signature:R})=>{let N=PC(d,b.fresh());return ad({...g,...x,signature:R,...l?{base:l}:{},...N?{pictures:N}:{}})},E=await U1({title:"New palette",name:o,...f?{colors:f}:{},signature:g.signature,...g.waive?{waive:g.waive}:{},palettes:_1(r,i,o),pictures:b.count(),find:B1(r,o,i,y),check:(x)=>j1(()=>Cn(o,y(x),i.palettes))});if(!E){b.discard(),console.log("Nothing made");return}IC(RC(c),{recursive:!0}),P(c,y(E));let{state:S}=NC(r,i,[o]);console.log(` + ${o}${u?` from ${u.name}`:""}
712
- ${c}`),await Dn(r,Ot(r,i).palettes.filter((x)=>x.name===o),S.terminals),console.log(`
713
- \`ttheme use ${o}\` wears it · \`ttheme edit ${o}\` opens it again`)}function HC(t,e,n){let r=mn(Cn(t,e,n.palettes));return Lo(r).length>0?Co(r).filter((i)=>i.startsWith(" ✗")):[]}async function K1(t){let e=J(),n=ut(e),r=L(e),i=Ot(e,n,!1),s=C1(t,e),o=pl(e,s),a=o&&Aa(o)?s:i.palettes.some((b)=>b.name===t)?t:s,c=pl(e,a);if(!c||!Aa(c)){let b=i.palettes.some((y)=>y.name===a);throw Error(b?`${a} is not one of yours — \`ttheme new <name> --from ${a}\` makes your own copy`:`no palette of yours called ${a} — \`ttheme new\` makes one`)}if(!Zm())throw Error("edit opens the palette editor — run it in a terminal");let u=Vm(c,"utf8"),l;try{l=Cn(a,u,n.palettes)}catch(b){throw Error(`${c} cannot be read — ${b.message}`)}let f=G1(e,a),d=new Set((l.pictures??[]).map((b)=>te(b))),h=({colors:b,signature:y})=>o0(f0(ud(u,b),y),f.fresh().filter((E)=>!d.has(te(E)))),m=await U1({title:"Edit palette",name:a,colors:cd(l),signature:l.signatureSlots,waive:l.waive,palettes:_1(e,n,a),pictures:f.count(),find:B1(e,a,n,h),check:(b)=>j1(()=>Cn(a,h(b),n.palettes))});if(!m){f.discard(),console.log("Nothing changed");return}let $=h(m);if($===u){console.log(f.added()>0?`Kept the pictures you added to ${a}`:"Nothing changed");return}if(P(c,$),r.palettes.includes(a))jt(e,n,r);console.log(`Saved ${a}${r.palettes.includes(a)?" — new tabs and `ttheme use` wear it":` — \`ttheme add ${a}\` installs it`}`);let g=HC(a,$,n);if(g.length>0)console.log(`
709
+ }`;async function Nv(){if(up())return;if(process.platform==="darwin"){let[t="",e=""]=(await Pn("osascript",["-l","JavaScript","-e",mL])).stdout.trim().split("\t");return{stamp:t,picture:e==="picture"}}if(process.platform==="linux"&&!Rv()){let e=Boolean(process.env.WAYLAND_DISPLAY)?(await Pn("wl-paste",["--list-types"])).stdout:(await Pn("xclip",["-selection","clipboard","-t","TARGETS","-o"])).stdout;return{stamp:e,picture:/^image\//m.test(e)}}return}function vl(t){return t.length>8&&/^(?:\/|~\/|file:|https?:)/.test(t)}var Ka=(t)=>Buffer.from(t).toString("base64"),sp=(t)=>Buffer.from(t,"base64");function yv(t,e){return e.find((n)=>t.includes(n))}class lp{clipboard=!1;drops=!1;reading;offered=[];dropping;pw=Ka(vv("sha1").update(`${process.pid}:${Date.now()}`).digest("hex"));send;deliver;constructor(t,e){this.send=t,this.deliver=e}start(){let t="";if(this.clipboard)t+="\x1B[?5522h";if(this.drops)t+=`\x1B]72;t=a;${op.join(" ")}\x1B\\`;this.send(t)}stop(){this.send(`${this.clipboard?"\x1B[?5522l":""}${this.drops?"\x1B]72;t=A\x1B\\":""}`)}ask(){this.reading={mime:".",chunks:[],pw:"",listing:!0},this.send(`\x1B]5522;type=read:name=${Ka("ttheme")}:pw=${this.pw};${Ka(".")}\x1B\\`)}take(t){if(t.code==="5522")this.clip(t.meta,t.payload);else if(t.code==="72")this.drop(t.meta,t.payload)}clip(t,e){if(t.type!=="read")return;let n=t.status??"";if(n==="OK"){if(this.reading??={mime:".",chunks:[],pw:t.pw??"",listing:!0},t.pw)this.reading.pw=t.pw;return}let r=this.reading;if(!r)return;if(n==="DATA"){if(r.mime=t.mime?sp(t.mime).toString("utf8"):r.mime,e)r.chunks.push(sp(e));return}if(this.reading=void 0,n!=="DONE"){this.deliver({kind:"error",message:n==="EPERM"?"The clipboard read was not allowed":`The terminal answered ${n}`});return}let i=Buffer.concat(r.chunks);if(r.listing){let o=i.toString("utf8").split(/\s+/).filter(Boolean),s=yv(o,[...ap,...cL]);if(!s){this.deliver({kind:"text",text:""});return}let a=r.pw||this.pw,c=r.pw?"Paste event":"ttheme";this.reading={mime:s,chunks:[],pw:a,listing:!1},this.send(`\x1B]5522;type=read:name=${Ka(c)}:pw=${a};${Ka(s)}\x1B\\`);return}this.deliver(r.mime.startsWith("image/")?{kind:"bytes",bytes:new Uint8Array(i),source:"clipboard"}:{kind:"text",text:i.toString("utf8")})}drop(t,e){let n=t.t??"";if(n==="m"){if(t.x==="-1"){this.offered=[];return}if(e){this.offered=e.split(" ").filter(Boolean);let a=op.filter((c)=>this.offered.includes(c));this.send(`\x1B]72;t=m:o=${a.length>0?1:0};${a.join(" ")}\x1B\\`)}return}if(n==="M"){let a=e?e.split(" ").filter(Boolean):this.offered,c=yv(a,op);if(!c){this.send("\x1B]72;t=r:o=0\x1B\\");return}this.dropping={mimes:a,index:a.indexOf(c)+1,chunks:[]},this.send(`\x1B]72;t=r:x=${this.dropping.index}\x1B\\`);return}let r=this.dropping;if(!r)return;if(n==="R"){this.dropping=void 0,this.send("\x1B]72;t=r:o=0\x1B\\"),this.deliver({kind:"error",message:`The drop failed: ${e.split(":")[0]||"unknown error"}`});return}if(n!=="r"&&n!=="")return;if(e)r.chunks.push(sp(e));if(t.m==="1"||e)return;this.dropping=void 0;let i=Buffer.concat(r.chunks),o=r.mimes[r.index-1]??"",s;if(o.startsWith("image/"))s={kind:"bytes",bytes:new Uint8Array(i),source:"drop"};else{let a=i.toString("utf8"),c=o==="text/uri-list"?gs(a).find((u)=>tL(u)):void 0;s=c?{kind:"bytes",bytes:new Uint8Array(yl(c)),source:c}:{kind:"text",text:a}}this.send("\x1B]72;t=r:o=1\x1B\\"),this.deliver(s)}}var dp=5,pL=6,Av=0.05,gL=[1,2,3,4,5,6,9,10,11,12,13,14],Tv=(t,e)=>(e-t+360)%360<=180?1:-1;function Nn(t,e,n){let r=e*Math.cos(n*Math.PI/180),i=e*Math.sin(n*Math.PI/180),o=[t+0.3963377774*r+0.2158037573*i,t-0.1055613458*r-0.0638541728*i,t-0.0894841775*r-1.291485548*i].map((l)=>l**3),[s,a,c]=o,u=[4.0767416621*s-3.3077115913*a+0.2309699292*c,-1.2684380046*s+2.6097574011*a-0.3413193965*c,-0.0041960863*s-0.7034186147*a+1.707614701*c];if(u.some((l)=>l<-0.0001||l>1.0001))return;return u.map((l)=>{let d=Math.min(1,Math.max(0,l));return Math.round(255*(d<=0.0031308?12.92*d:1.055*d**0.4166666666666667-0.055))})}function bs(t,e,n){if(Nn(t,n,e)!==void 0)return n;let r=0,i=n;for(let o=0;o<24;o++){let s=(r+i)/2;if(Nn(t,s,e)===void 0)i=s;else r=s}return r}function ze(t,e,n){return`#${(Nn(t,bs(t,n,e),n)??[0,0,0]).map((i)=>i.toString(16).padStart(2,"0")).join("")}`}function bL(t,e){let{l:n,c:r}=Et(t);return ze(n,r,(e+360)%360)}function wL(t,e,n){let{l:r,c:i,h:o}=Et(t),s=vt(e)<0.18,a=(l)=>ze(s?r+(1-r)*l:r*(1-l),i,o);if(wt(a(1),e)<n+Av)return a(1);let c=0,u=1;for(let l=0;l<30;l++){let d=(c+u)/2;if(wt(a(d),e)>=n+Av)u=d;else c=d}return a(u)}function $L(t,e){let{l:n,c:r,h:i}=Et(t),o=0,s=n;for(let a=0;a<30;a++){let c=(o+s)/2;if(vt(ze(c,r,i))<=e-0.005)o=c;else s=c}return ze(o,r,i)}function kL(t,e,n){let r=ke[e],[i,o]=[Et(t[e]),Et(t[e+8])],s=(l,d)=>n.has(l)?[d]:Array.from({length:2*r.width+1},(f,h)=>(r.center-r.width+h+360)%360),a=(l,d,f)=>mr.every((h)=>{let m=(l>8?8:0)+h;if(m===l)return!0;let g=Et(t[m]);return g.c<ui||ye(g.h,d)>=fo+1||Math.abs(g.l-f)>=ho}),c,u=Number.POSITIVE_INFINITY;for(let l of s(e,i.h)){if(!n.has(e)&&!a(e,l,i.l))continue;for(let d of s(e+8,o.h)){if(ye(l,d)>Ye-dp||!n.has(e+8)&&!a(e+8,d,o.l))continue;let f=ye(l,i.h)+ye(d,o.h);if(f<u)u=f,c=[l,d]}}return c}class Hv{theme;moves=[];constructor(t){this.theme={...t,ansi:[...t.ansi]}}set(t,e,n){let r=this.get(t);if(n===r)return;if(this.moves.push({slot:t,rule:e,from:r,to:n}),t==="foreground")this.theme.foreground=n;else if(t==="selection")this.theme.selectionBackground=n;else this.theme.ansi[Number(t.slice(4))]=n}get(t){if(t==="foreground")return this.theme.foreground;if(t==="selection")return this.theme.selectionBackground;return this.theme.ansi[Number(t.slice(4))]}rehue(t,e,n){this.set(`ansi${t}`,e,bL(this.theme.ansi[t],n))}roles(){let t=new Set(this.theme.signatureSlots);for(let{slot:n,hue:r}of pr(this.theme)){let i=ke[pn(n)];this.rehue(n,"ansi-role",i.center+Tv(i.center,r)*(i.width-dp))}for(let{normal:n,gap:r}of Bn(this.theme)){if(r<=Ye)continue;let[i,o]=t.has(`ansi${n+8}`)?[n+8,n]:[n,n+8],s=Et(this.theme.ansi[i]).h,a=Et(this.theme.ansi[o]).h;this.rehue(o,"bright-follows",s+Tv(s,a)*(Ye-dp))}let e=mo(this.theme);for(let[n,r]of Gn(this.theme)){let i=pn(e.has(r)?n:r),o=kL(this.theme.ansi,i,e);if(o===void 0)continue;this.rehue(i,"distinct",o[0]),this.rehue(i+8,"distinct",o[1])}}readability(){let t=new Set(this.theme.waive),{background:e}=this.theme,n=(r,i,o,s=e)=>{if(t.has(r))return;for(let a of i)if(wt(this.get(a),s)<o)this.set(a,r,wL(this.get(a),s,o))};if(n("foreground",["foreground"],7),n("accents",gL.map((r)=>`ansi${r}`),3),n("light-ansi",["ansi7","ansi15"],7),n("ansi8-visible",["ansi8"],1.6),!t.has("ansi0-dark")&&vt(this.get("ansi0"))>0.15)this.set("ansi0","ansi0-dark",$L(this.get("ansi0"),0.15));n("selection",["selection"],7,this.theme.foreground)}net(){return[...new Set(this.moves.map((t)=>t.slot))].flatMap((t)=>{let e=this.moves.filter((i)=>i.slot===t),n=e[0].from,r=this.get(t);return n===r?[]:[{slot:t,rule:[...new Set(e.map((i)=>i.rule))].join(", "),from:n,to:r}]})}}function Sl(t){let e=new Hv(t);for(let n=0;n<pL;n++)if(e.readability(),e.roles(),Un(e.theme).length===0)break;return{theme:e.theme,moves:e.net(),left:Un(e.theme)}}var Ji=[{key:"background",label:"Background",min:0,max:0.5,step:0.01,digits:2},{key:"foreground",label:"Foreground",min:0.5,max:1,step:0.01,digits:2},{key:"hue",label:"Hue",min:0,max:360,step:1,digits:0,wraps:!0},{key:"tint",label:"Tint",min:0,max:0.1,step:0.005,digits:3},{key:"lightness",label:"Accent lightness",min:0.4,max:0.95,step:0.01,digits:2},{key:"chroma",label:"Accent chroma",min:0,max:0.3,step:0.005,digits:3},{key:"brights",label:"Brights",min:-0.2,max:0.2,step:0.01,digits:2}],za={background:0.21,foreground:0.88,hue:265,tint:0.02,lightness:0.72,chroma:0.12,brights:0.06},Cv=(t,e,n)=>Math.min(n,Math.max(e,t));function fp(t,e,n){let r=t[e.key]+e.step*n,i=e.wraps?(r%e.max+e.max)%e.max:Cv(r,e.min,e.max);return{...t,[e.key]:Math.round(i*1e4)/1e4}}function ei(t){let e=(r,i,o)=>ze(Cv(r,0,1),i,o),n=Array.from({length:16},()=>"#000000");n[0]=e(t.background+0.06,t.tint,t.hue),n[8]=e(t.background+0.25,t.tint,t.hue),n[7]=e(t.foreground-0.06,t.tint/2,t.hue),n[15]=e(t.foreground+0.06,t.tint/2,t.hue);for(let r of mr){let i=ke[r].center;n[r]=e(t.lightness,t.chroma,i),n[r+8]=e(t.lightness+t.brights,t.chroma,i)}return{background:e(t.background,t.tint,t.hue),foreground:e(t.foreground,t.tint/2,t.hue),cursor:e(t.lightness+t.brights,Math.max(t.chroma,0.08),t.hue),selection:e(t.background+0.1,t.tint*2,t.hue),ansi:n}}var An=["background","foreground","cursor","selection",...Array.from({length:16},(t,e)=>`ansi${e}`)],A=["Background","Foreground","Cursor","Selection"],ln=["Black","Red","Green","Yellow","Blue","Magenta","Cyan","White"],yL=["Behind every cell","Plain text","The cursor block","Selected text","Text on colored bars, dark shades","Errors, deleted lines, failed tests","Success, added lines, prompts","Warnings, commit hashes, skipped tests","Directories, info, keywords","Keywords, branches, pictures in ls","Links, diff hunks, types","Light shades, text in some programs","Comments, muted text, suggestions"],cr=A.length+ln.length,un=[{key:"l",label:"Lightness",min:0,max:1,step:0.01,digits:2},{key:"c",label:"Chroma",min:0,max:0.37,step:0.005,digits:3},{key:"h",label:"Hue",min:0,max:360,step:1,digits:0,wraps:!0}],Lv=5,vL=5,Qt=un.length,ws=["this","pair","normals","brights","accents"],El=[1,2,3,4,5,6,9,10,11,12,13,14],Fv=El.filter((t)=>t<8).map((t)=>A.length+t),jv=El.filter((t)=>t>8).map((t)=>A.length+t);function hp(t,e){let n=e-A.length;if(n<0||t==="this")return[e];if(t==="pair")return[A.length+n%8,A.length+8+n%8];let r=t==="normals"?Fv:t==="brights"?jv:[...Fv,...jv];return r.includes(e)?r:[e]}function SL(){return Array.from({length:cr},(t,e)=>e<A.length?[e]:[e,e+8]).flat()}function EL(t){let e=t.trim();return/^https?:\/\/\S+$/i.test(e)||gs(e).length>0}function cn(t){return[t.background,t.foreground,t.cursor,t.selection,...t.ansi]}function Gt(t){let[e,n,r,i,...o]=t;return{background:e,foreground:n,cursor:r,selection:i,ansi:o}}function Ce(t){if(t<A.length)return{name:A[t],about:An[t]};let e=t-A.length,n=ln[e%8];return e<8?{name:n,about:`ANSI ${e}`}:{name:`Bright ${n.toLowerCase()}`,about:`ANSI ${e}`}}function Uv(t){let e=t-A.length;if(e>=9&&e<=15)return`Bold or bright ${ln[e-8].toLowerCase()} text`;return yL[t]}var Vi=(t,e,n)=>Math.min(n,Math.max(e,t));function _v(t){return t.length===1?t.toLowerCase():t}function ML(t){return Vi(Math.round(t),0,255).toString(16).padStart(2,"0")}function Bv(t){let e=t.trim().toLowerCase(),n=/^#?([0-9a-f]{6}|[0-9a-f]{3})$/.exec(e);if(n){let o=n[1];return`#${o.length===3?[...o].map((s)=>s+s).join(""):o}`}let r=/^rgb\(\s*(\d+)[\s,]+(\d+)[\s,]+(\d+)\s*\)$/.exec(e);if(r)return`#${r.slice(1,4).map((o)=>ML(Number(o))).join("")}`;let i=/^oklch\(\s*([\d.]+)(%?)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:deg|°)?\s*\)$/.exec(e);if(i){let o=Number(i[1])/(i[2]?100:1);return ze(Vi(o,0,1),Number(i[3]),Number(i[4])%360)}return}function Zi(t){let e=ve.find((n)=>n.rule===t);return e?.min??e?.max??0}function ur(t,e,n){let r=Gt(t);return{name:"draft",background:r.background,foreground:r.foreground,selectionBackground:r.selection,ansi:r.ansi,waive:n,signatureSlots:e}}function xL(t,e){let n=t-A.length,r=t<=1?"foreground":t===3?"selection":n===7||n===15?"light-ansi":n===8?"ansi8-visible":El.includes(n)?"accents":void 0;return{against:t===0||t===3?1:0,floor:r===void 0||e.includes(r)?void 0:Zi(r)}}function bp(t,e,n,r){let i=ur(t,e,n),{background:o,foreground:s,selection:a,ansi:c}=Gt(t),u=(l,d,f)=>wt(d,f)<Zi(r)?[l]:[];if(r==="foreground")return wt(s,o)<Zi(r)?[1,0]:[];if(r==="selection")return wt(s,a)<Zi(r)?[3,1]:[];if(r==="accents")return El.flatMap((l)=>u(A.length+l,c[l],o));if(r==="light-ansi")return[7,15].flatMap((l)=>u(A.length+l,c[l],o));if(r==="ansi8-visible")return u(A.length+8,c[8],o);if(r==="ansi0-dark")return vt(c[0])>Zi(r)?[A.length]:[];if(r==="ansi-role")return pr(i).map(({slot:l})=>A.length+l);if(r==="bright-follows")return Bn(i).filter(({gap:l})=>l>Ye).flatMap(({normal:l})=>[A.length+l,A.length+l+8]);if(r==="distinct")return Gn(i).flatMap(([l,d])=>[A.length+l,A.length+d]);return[]}function wp(t,e,n){return new Set(An.flatMap((r,i)=>$p(t,e,n,i).some((o)=>o.ok===!1)?[i]:[]))}function ar(t,e,n,r,i){let o=wt(t,e),s=Zi(n);if(i.includes(n))return{ok:void 0,text:`${r} ${o.toFixed(2)}:1 · waived`};return{ok:o>=s,text:`${r} ${o.toFixed(2)}:1 · ≥ ${s}`}}function $p(t,e,n,r){let i=Gt(t),o=ur(t,e,n);if(r===0){let w=[1,2,3,4,5,6,9,10,11,12,13,14].reduce((k,v)=>wt(i.ansi[k],i.background)<=wt(i.ansi[v],i.background)?k:v);return[ar(i.foreground,i.background,"foreground","Foreground on it",n),ar(i.ansi[w],i.background,"accents",`Weakest, ANSI ${w},`,n),ar(i.ansi[8],i.background,"ansi8-visible","ANSI 8 on it",n)]}if(r===1)return[ar(i.foreground,i.background,"foreground","On background",n),ar(i.foreground,i.selection,"selection","On the selection",n)];if(r===2)return[{ok:void 0,text:`On background ${wt(i.cursor,i.background).toFixed(2)}:1`}];if(r===3)return[ar(i.foreground,i.selection,"selection","Foreground on it",n)];let s=r-A.length,a=i.ansi[s];if(s===0){let b=vt(a),w=Zi("ansi0-dark");return[n.includes("ansi0-dark")?{ok:void 0,text:`Luminance ${b.toFixed(3)} · waived`}:{ok:b<=w,text:`Luminance ${b.toFixed(3)} · ≤ ${w}`}]}if(s===7||s===15)return[ar(a,i.background,"light-ansi","On background",n)];if(s===8)return[ar(a,i.background,"ansi8-visible","On background",n)];let c=[ar(a,i.background,"accents","On background",n)],u=Et(a),l=pn(s),d=ke[l],f=`${d.name} ${d.center}±${d.width}°`;if(u.c<ui)c.push({ok:void 0,text:"Too grey to have a hue"});else if(mo(o).has(s))c.push({ok:void 0,text:`Hue ${u.h.toFixed(0)}° · a signature, free of ${f}`});else if(n.includes("ansi-role"))c.push({ok:void 0,text:`Hue ${u.h.toFixed(0)}° · ${f} waived`});else{let b=ye(u.h,d.center)-d.width;c.push(b>0?{ok:!1,text:`Hue ${u.h.toFixed(0)}° · ${b.toFixed(0)}° outside ${f}`}:{ok:!0,text:`Hue ${u.h.toFixed(0)}° · in ${f}`})}let h=s<8?s+8:s-8,m=Bn(o).find((b)=>b.normal===l);if(m)c.push(n.includes("bright-follows")?{ok:void 0,text:`${m.gap.toFixed(0)}° from ANSI ${h} · waived`}:{ok:m.gap<=Ye,text:`${m.gap.toFixed(0)}° from ANSI ${h} · ≤ ${Ye}°`});let g=Gn(o).flatMap(([b,w])=>b===s?[w]:w===s?[b]:[]);if(g.length>0&&!n.includes("distinct"))c.push({ok:!1,text:`Reads as ANSI ${g.join(", ")} · within ${fo}° and ${ho} lightness`});return c}function kp(t,e,n){let r=gn(ur(t,e,n));return ve.map((i,o)=>{let s=r[o],a=n.includes(i.rule),c=a||Number.isNaN(s)?void 0:(i.min===void 0||s>=i.min)&&(i.max===void 0||s<=i.max);return{ok:c,label:i.label,value:Number.isNaN(s)?"—":Number.isInteger(s)?String(s):s.toFixed(2),bound:a?"waived":i.min!==void 0?`≥ ${i.min}`:i.max!==void 0?`≤ ${i.max}`:"",slots:c===!1?bp(t,e,n,i.rule):[]}})}var OL=new Set(["reset","reset-all","hex","paste","fix","open","tune","sig","follow"]),Wv=un[1].max;function mp(t){let[e,n,r]=et(t);return e===n&&n===r}function pp(t,e){return Math.floor(bs(t,e,Wv)*1e4)/1e4}function gp(t,e){return{l:e.l-t.l,c:e.c-t.c,h:((e.h-t.h)%360+540)%360-180}}function Gv(t,e){let n=t.wraps?t.max-t.step:t.max;return Math.min(n,Math.round((t.min+(t.max-t.min)*e)/t.step)*t.step)}class yp{mode;seeds=za;field=0;list;lch;start;original;signature;row=0;col=0;channel=0;scope="this";view="slot";scene=0;typing;overlay;quitting=!1;compare=!1;notice;filter="";pick=0;result;wants;pictures;inspect=!1;spot;format="hex";pic=!0;menu;entry=0;changedOnly=!1;where=!1;size;copied;startPictures;options;fresh;tone;startSignature;seeded=!1;tuneFrom;holds=new Map;clip;history=[];future=[];lastEdit;links=new Map;unlinked=new Set;offsets=new Map;constructor(t){this.options=t,this.tone=t.tone===!0,this.fresh=t.colors===void 0,this.mode=this.fresh?"seeds":"list",this.list=cn(t.colors??ei(this.seeds)),this.lch=this.lchs(),this.start=[...this.list],this.original=t.original?cn(t.original):[...this.list],this.signature=[...t.signature],this.startSignature=[...t.signature],this.pictures=t.pictures??0,this.startPictures=this.pictures,this.chain(this.original)}chain(t){this.links=new Map,this.unlinked=new Set,this.offsets=new Map;for(let e=0;e<8;e++){let n=A.length+e,r=n+8,i=this.lchOf(t[n]),o=this.lchOf(t[r]);if(i.c>=ui&&o.c>=ui&&ye(i.h,o.h)<=3)this.links.set(r,n),this.offsets.set(r,gp(i,o))}}pair(t){if(t<A.length)return;let e=A.length+(t-A.length)%8,n=e+8;return{normal:e,bright:n,on:this.linkOf(n)!==void 0,lift:this.lch[n].l-this.lch[e].l}}linkOf(t){let e=this.links.get(t);return e!==void 0&&!this.unlinked.has(t)?e:void 0}changed(t){return this.list[t]!==this.original[t]}visible(t){return!this.changedOnly||this.changed(t)}changes(){return this.list.filter((t,e)=>this.changed(e)).length}slotAt(t,e){return t<A.length?t:t+(e===1?8:0)}get added(){return Math.max(0,this.pictures-this.startPictures)}found(t){this.pictures=t.count,this.notice=t.note}get waive(){return this.options.waive??[]}get held(){return this.holds.get(this.slot())}colors(){return Gt(this.list)}edited(){return{colors:this.colors(),signature:[...this.signature]}}shown(){return this.compare?this.start:this.list}slot(){return this.row<A.length?this.row:this.row+(this.col===1?8:0)}dirty(){return this.seeded||this.pictures!==this.startPictures||this.list.some((t,e)=>t!==this.start[e])||this.signature.join()!==this.startSignature.join()}misses(){return wp(this.list,this.signature,this.waive)}failing(){return Un(ur(this.list,this.signature,this.waive))}choices(){let t=this.filter.toLowerCase();return(this.options.palettes??[]).filter((e)=>e.name.toLowerCase().includes(t))}paste(t){if(this.notice=void 0,this.overlay==="open"){this.filter+=t.replace(/\s+/g,"").toLowerCase(),this.pick=0;return}if(this.overlay)return;if(!this.tone&&t.trim()===""){this.findPictures({clipboard:!0});return}if(!this.tone&&EL(t)){this.findPictures({paste:t});return}if(this.mode==="seeds")return;let e=this.options.decode?.(t);if(e){this.remember("open"),this.list=cn(e),this.lch=this.lchs(),this.chain(this.list),this.notice="Took the colors of the share code";return}let n=Bv(t);if(!n){this.notice="Not a color — #rrggbb, rgb(r g b) or oklch(l c h)";return}this.typing=void 0,this.take(n,"paste")}press(t){if(this.notice=void 0,t==="ctrl-c"){this.result="cancelled";return}if(this.quitting){if(this.quitting=!1,t==="y"||t==="Y")this.result="cancelled";return}if(this.typing!==void 0){this.type(t);return}if(this.overlay==="keys"){this.overlay=void 0;return}if(this.overlay==="open"){this.openKey(t);return}if(this.menu){this.menuKey(t);return}if(t==="?"){this.overlay="keys";return}if(this.inspect&&this.mode==="list"&&this.inspectKey(t))return;if(this.tone&&(t==="ctrl-v"||t==="alt-v"||t==="p"))return;if(t==="ctrl-v"||t==="alt-v"){this.findPictures({clipboard:!0});return}if(t==="p"&&this.mode!=="tune"){this.findPictures();return}if(t===" "&&this.mode!=="seeds"){this.compare=!this.compare;return}if(this.compare&&t==="esc"){this.compare=!1;return}if(t==="g"&&this.mode!=="seeds"){this.view=this.view==="slot"?"relations":"slot";return}let e=t==="j"?"down":t==="k"?"up":t;if(this.mode==="seeds")this.seedKey(e);else if(this.mode==="tune")this.tuneKey(e);else this.listKey(e)}select(t){if(this.mode==="seeds"||this.typing!==void 0||this.overlay||this.quitting)return;if(this.mode==="tune"){if(t===this.slot())return;this.tuneKey("enter")}this.notice=void 0,this.seat(t),this.lastEdit=void 0}seat(t){if(this.row=t<A.length?t:A.length+(t-A.length)%8,t>=A.length)this.col=t-A.length>=8?1:0}grip(t){if(this.mode==="seeds"||this.typing!==void 0||this.overlay||this.quitting)return!1;if(this.notice=void 0,this.mode==="list")this.tune();return this.channel=t,!0}slide(t,e){if(!this.grip(t))return;let n=Math.min(1,Math.max(0,e));if(t===Qt){this.reach(21**n);return}this.put(Gv(un[t],n))}sow(t,e){let n=Ji[t];if(this.mode!=="seeds"||this.overlay||this.quitting||!n)return;this.notice=void 0,this.field=t;let r=Math.min(1,Math.max(0,e));this.seeds=fp({...this.seeds,[n.key]:Gv(n,r)},n,0),this.list=cn(ei(this.seeds)),this.lch=this.lchs()}scroll(t){let e=(n,r)=>Math.min(r,Math.max(0,n+t));if(this.overlay==="open")this.pick=e(this.pick,Math.max(0,this.choices().length-1));else if(this.overlay||this.quitting||this.typing!==void 0)return;else if(this.mode==="seeds")this.field=e(this.field,Ji.length-1);else if(this.mode==="tune")this.channel=0,this.step(-t);else this.row=e(this.row,cr-1),this.lastEdit=void 0}lchOf(t){let e=Et(t);return mp(t)?{...e,h:this.neutralHue()}:e}lchs(){return this.list.map((t)=>this.lchOf(t))}neutralHue(){let t=[0,1,3,2].map((e)=>this.list[e]).find((e)=>!mp(e));return t?Et(t).h:za.hue}seedKey(t){let e=Ji.length;if(t==="up"||t==="down")this.field=(this.field+(t==="up"?e-1:1))%e;else if(t==="home"||t==="end")this.field=t==="home"?0:e-1;else if(t==="left"||t==="right"||t==="shift-left"||t==="shift-right"){let n=Ji[this.field],r=(t.endsWith("left")?-1:1)*(t.startsWith("shift")?n.wraps?10:Lv:1);this.seeds=fp(this.seeds,n,r),this.list=cn(ei(this.seeds)),this.lch=this.lchs()}else if(t==="enter")this.leaveSeeds();else if(t==="o")this.openPalettes();else if(t==="esc")this.leave()}leaveSeeds(){this.start=[...this.list],this.original=[...this.list],this.chain(this.original),this.seeded=!0,this.mode="list"}leave(){if(this.dirty())this.quitting=!0;else this.result="cancelled"}findPictures(t){if(!this.options.find){this.notice="Pictures need Ghostty, iTerm2 or kitty, outside tmux";return}this.wants=t?{start:t}:{}}openPalettes(){if((this.options.palettes??[]).length>0)this.overlay="open",this.pick=0;else this.notice="No other palettes to take colors from"}listKey(t){if(t==="up"||t==="down"){let e=t==="up"?-1:1;this.land(this.row+e,e),this.lastEdit=void 0}else if(t==="home"||t==="end")this.land(t==="home"?0:cr-1,t==="home"?1:-1);else if(t==="pgup"||t==="pgdn")this.land(t==="pgup"?0:A.length,1);else if(t==="left"||t==="right"){let e=t==="left"?0:1;if(this.row>=A.length&&this.visible(this.slotAt(this.row,e)))this.col=e,this.lastEdit=void 0}else if(this.builderKey(t))return;else if(t==="shift-left"||t==="shift-right")this.scene+=t==="shift-left"?-1:1;else if(t==="n"||t==="N")this.nextMiss(t==="n"?1:-1);else if(t==="enter"||t==="tab")this.tune();else if(t==="#")this.typing="";else if(t==="c")this.clip=this.list[this.slot()],this.notice=`Copied ${this.clip}`;else if(t==="v")if(this.clip)this.set(this.slot(),this.clip,"paste");else this.notice="Nothing copied yet — c copies a slot";else if(t==="r")this.set(this.slot(),this.original[this.slot()],"reset");else if(t==="R")this.remember("reset-all"),this.list=[...this.original],this.lch=this.lchs();else if(t==="=")this.follow();else if(t==="*"&&!this.tone)this.mark();else if(t==="f")this.fix();else if(t==="o"&&!this.tone)this.openPalettes();else if(t==="u")this.undo();else if(t==="ctrl-r")this.redo();else if(t==="s"||t==="ctrl-s")this.save();else if(t==="esc")this.leave()}viewport(t,e){this.size={cols:t,rows:e}}layout(){return this.size?Ua(this.size.cols,this.size.rows,this.scene):void 0}get roomy(){return this.layout()!==void 0}reseat(){if(!this.visible(this.slot()))this.land(this.row,1)}rowShown(t){return this.visible(this.slotAt(t,0))||t>=A.length&&this.visible(this.slotAt(t,1))}land(t,e){for(let n=0;n<cr;n++){let r=((t+e*n)%cr+cr)%cr;if(this.rowShown(r)){if(this.row=r,r>=A.length&&!this.visible(this.slotAt(r,this.col)))this.col=1-this.col;return}}}builderKey(t){if(["i","m","w","x","I"].includes(t)&&!this.roomy)return this.notice="The builder needs a window of at least 96×28",!0;if(t==="i")this.startInspect();else if(t==="l")this.linkKey();else if(t==="m")this.changedOnly=!this.changedOnly,this.reseat(),this.notice=this.changedOnly?this.changes()>0?void 0:"Nothing changed yet":void 0;else if(t==="b")this.pic=!this.pic;else if(t==="w")this.where=!this.where;else if(t==="x"&&this.options.exports)this.menu="export",this.entry=0;else if(t==="I")this.menu="import",this.entry=0;else return!1;return!0}menuKey(t){let e=this.menu==="export"?3:2;if(t==="esc")this.menu=void 0;else if(t==="up"||t==="down"||t==="k"||t==="j")this.entry=(this.entry+(t==="up"||t==="k"?e-1:1))%e;else if(t==="enter")this.choose(this.entry)}choose(t){let e=this.menu;if(this.menu=void 0,e==="import"){if(t===0)this.openPalettes();else this.notice=this.options.decode?"Paste a tt1: share code into this window":"Share codes are not read here";return}let n=this.options.exports;if(e!=="export"||!n)return;try{let r=this.edited(),i=n.code(r);this.copied=t===0?i:t===1?`${n.command} ${i}`:n.toml(r),this.notice=`Copied ${t===0?"the share code":t===1?"the add command":"the palette file"} — paste it where you need it`}catch(r){this.notice=r instanceof Error?r.message:String(r)}}openMenu(t){if(this.mode==="seeds"||this.typing!==void 0||this.overlay||this.quitting)return;this.menu=this.menu===t?void 0:t,this.entry=0}startInspect(){let t=this.layout();if(!t){this.notice="The builder needs a window of at least 96×28";return}this.inspect=!0,this.spot=pv(t,this.slot())}toggleInspect(){if(this.mode==="seeds"||this.typing!==void 0||this.overlay||this.quitting)return;if(this.inspect)this.inspect=!1,this.spot=void 0;else this.startInspect()}inspectKey(t){let e=this.layout();if(!e)return this.inspect=!1,!1;let r={left:"left",right:"right",up:"up",k:"up",down:"down",j:"down",tab:"next","shift-tab":"previous"}[t];if(t==="i"||t==="esc")this.inspect=!1,this.spot=void 0;else if(r)this.spot=gv(e,bl(e,this.spot),r);else if(t==="shift-left"||t==="shift-right")this.scene+=t==="shift-left"?-1:1,this.spot=void 0;else if(t==="enter")this.jump();else return!1;return!0}point(t){if(this.mode!=="seeds"&&!this.overlay&&!this.quitting&&this.typing===void 0&&this.layout())this.inspect=!0,this.spot=t}slotsHere(){let t=this.layout();return t&&this.spot?bv(t,this.spot):void 0}jump(){let t=this.slotsHere();if(!t)return;let e=t.ground!==0?t.ground:t.text;this.inspect=!1,this.spot=void 0,this.show(e),this.select(e)}show(t){if(!this.visible(t))this.changedOnly=!1}openSlot(t){if(this.mode==="seeds"||this.typing!==void 0||this.overlay||this.quitting)return;let e=this.mode==="tune"&&t===this.slot();if(this.mode==="tune")this.tuneKey("enter");if(e)return;if(this.show(t),this.select(t),this.mode==="list")this.tune()}dismiss(){if(this.mode!=="tune"||this.overlay||this.quitting)return;this.typing=void 0,this.tuneKey("enter")}plane(t,e){if(!this.grip(0))return;this.channel=0,this.put(t),this.channel=1,this.put(e)}linkKey(){let t=this.slot();if(t<A.length){this.notice="l links a bright to its normal — pick an ANSI row";return}let e=A.length+(t-A.length)%8,n=e+8,r=`${Ce(n).name} and ${Ce(e).name.toLowerCase()}`;if(this.mode!=="tune")this.remember("link");if(this.linkOf(n)!==void 0){this.unlinked.add(n),this.notice=`${r} move apart`;return}this.links.set(n,e),this.unlinked.delete(n),this.offsets.set(n,gp(this.lch[e],this.lch[n])),this.notice=`${r} move together`}nextMiss(t){let e=SL(),n=this.misses();if(n.size===0){this.notice="The gate passes";return}let r=e.indexOf(this.slot());for(let i=1;i<=e.length;i++){let o=e[((r+t*i)%e.length+e.length)%e.length];if(n.has(o)){this.seat(o);return}}}tune(){this.remember("tune"),this.tuneFrom={list:[...this.list],lch:[...this.lch]},this.holds=new Map,this.hold(),this.mode="tune"}hold(){for(let t of this.scoped())if(!this.holds.has(t))this.holds.set(t,this.lch[t].c)}scoped(){return hp(this.scope,this.slot())}tuneKey(t){let e=this.channel===Qt;if(t==="tab"||t==="shift-tab")this.channel=e?0:Qt;else if(t==="up"||t==="down"||t==="pgup"||t==="pgdn")this.channel=0,this.step((t==="up"||t==="pgup"?1:-1)*(t.startsWith("pg")?Lv:1));else if(t==="left"||t==="right"){let n=t==="left"?-1:1;if(e)this.reach(this.ratio()+n*0.1);else this.channel=1,this.step(n)}else if(t==="shift-left"||t==="shift-right"){let n=t==="shift-left"?-1:1;if(e)this.reach(this.ratio()+n*0.5);else this.channel=2,this.step(n*vL)}else if((t===","||t===".")&&!e)this.channel=2,this.step(t===","?-1:1);else if(t==="home"||t==="end")if(e)this.reach(t==="home"?this.partner().floor??1:21);else{let n=un[this.channel];this.put(t==="home"?n.min:n.wraps?n.max-n.step:n.max)}else if(/^[0-9]$/.test(t))if(e){if(t!=="0")this.reach(Number(t))}else{let n=un[this.channel];this.put(n.min+(n.max-n.min)*Number(t)/10)}else if(t==="a")this.rescope();else if(t==="#")this.typing="";else if(t==="l")this.linkKey();else if(t==="s"||t==="ctrl-s")this.tuneKey("enter"),this.save();else if(t==="enter"){if(this.tuneFrom&&this.list.every((n,r)=>n===this.tuneFrom?.list[r]))this.history.pop();this.endTune()}else if(t==="esc"){if(this.tuneFrom)this.list=[...this.tuneFrom.list],this.lch=[...this.tuneFrom.lch],this.history.pop();this.endTune()}}rescope(){if(this.slot()<A.length){this.notice="A base color moves alone";return}let t=ws.indexOf(this.scope);for(let e=1;e<=ws.length;e++){let n=ws[(t+e)%ws.length];if(n==="this"||hp(n,this.slot()).length>1){this.scopeTo(n);return}}}scopeTo(t){if(this.mode!=="tune"||this.typing!==void 0||this.quitting||this.slot()<A.length)return;if(t!=="this"&&hp(t,this.slot()).length<=1)return;this.scope=t,this.hold();let e=this.scoped().length;this.notice=e>1?`${e} slots move together`:"This slot moves alone"}endTune(){this.tuneFrom=void 0,this.holds=new Map,this.mode="list"}partner(){return xL(this.slot(),this.waive)}ratio(){return wt(this.list[this.slot()],this.list[this.partner().against])}origin(){let t=this.slot(),e=this.original[t];if(e===this.list[t])return;return{hex:e,lch:this.lchOf(e),ratio:wt(e,this.original[this.partner().against])}}reach(t){let e=this.slot(),n=this.list[this.partner().against],r=this.lch[e],i=this.holds.get(e)??r.c,o=(f)=>ze(f,Math.min(i,pp(f,r.h)),r.h),s=(f)=>wt(o(f),n),a=vt(this.list[e])>=vt(n),c=Et(n).l,u=Math.max(1,Math.round(t*100)/100),l=a?1:0,d;if(s(l)<u)d=l,this.notice=`The ratio stops at ${s(l).toFixed(2)}:1 on this side of the color it is read against`;else{let f=c,h=l;for(let m=0;m<24;m++){let g=(f+h)/2;if(s(g)>=u)h=g;else f=g}d=h}this.place(e,d,i,r.h);for(let f=0;f<40&&d!==l&&wt(this.list[e],n)<u;f++)d=a?Math.min(1,d+0.001):Math.max(0,d-0.001),this.place(e,d,i,r.h);this.lch[e]={...this.lch[e],l:Math.round(d*1e4)/1e4}}step(t){let e=un[this.channel],n=this.lch[this.slot()][e.key];this.put(n+e.step*t)}put(t){let e=this.slot(),n=un[this.channel],r=n.wraps?(t%n.max+n.max)%n.max:Vi(t,n.min,n.max),i=Math.round(r*1e4)/1e4,o=this.lch[e],s=this.scoped().filter((u)=>u!==e),a=(u)=>Math.round(u*1e4)/1e4;if(n.key==="c"){let u=pp(o.l,o.h);if(i>u)this.notice=`Chroma stops at ${u.toFixed(3)}, the sRGB edge for this lightness and hue`;let l=Math.min(i,u),d=l-o.c;this.holds.set(e,l),this.place(e,o.l,l,o.h);for(let f of s){let h=this.lch[f],m=a(Vi((this.holds.get(f)??h.c)+d,0,Wv));this.holds.set(f,m),this.place(f,h.l,m,h.h)}this.trail([e,...s]);return}let c=n.key==="h"?((i-o.h)%360+540)%360-180:i-o.l;if(this.place(e,n.key==="l"?i:o.l,this.holds.get(e)??o.c,n.key==="h"?i:o.h),n.key==="h"&&mp(this.list[e]))this.notice="A grey shows no hue — raise its chroma first";for(let u of s){let l=this.lch[u];this.place(u,n.key==="l"?a(Vi(l.l+c,0,1)):l.l,this.holds.get(u)??l.c,n.key==="h"?a(((l.h+c)%360+360)%360):l.h)}this.trail([e,...s])}trail(t){let e=new Set(t);for(let[n,r]of this.links){if(this.unlinked.has(n))continue;if(e.has(n)&&!e.has(r))this.unlinked.add(n);else if(e.has(r)&&!e.has(n)){let i=this.lch[r],o=this.offsets.get(n);this.place(n,Vi(i.l+o.l,0,1),Math.max(0,i.c+o.c),((i.h+o.h)%360+360)%360)}}}place(t,e,n,r){let i=Math.min(n,pp(e,r));this.lch[t]={l:e,c:i,h:r},this.list[t]=ze(e,i,r)}take(t,e){if(this.mode==="tune")this.list[this.slot()]=t,this.lch[this.slot()]=this.lchOf(t),this.holds.set(this.slot(),this.lch[this.slot()].c),this.trail([this.slot()]);else this.set(this.slot(),t,e)}type(t){let e=this.typing??"";if(t==="esc")this.typing=void 0;else if(t==="enter"){let n=Bv(e);if(!n){this.notice="Not a color — #rrggbb, rgb(r g b) or oklch(l c h)";return}this.typing=void 0,this.take(n,"hex")}else{let n=Ki(e,_v(t),(r)=>/^[0-9a-z#(),.% ]$/.test(r)&&e.length<28);if(n!==void 0)this.typing=n}}openKey(t){let e=this.choices();if(t==="esc")this.overlay=void 0,this.filter="";else if(t==="up"||t==="down"){let n=Math.max(1,e.length);this.pick=(this.pick+(t==="up"?n-1:1))%n}else if(t==="home"||t==="end")this.pick=t==="home"?0:Math.max(0,e.length-1);else if(t==="enter"){let n=e[this.pick];if(!n)return;if(this.remember("open"),this.list=cn(n.colors),this.lch=this.lchs(),this.chain(this.list),this.overlay=void 0,this.filter="",this.notice=`Took the colors of ${n.name}`,this.mode==="seeds")this.leaveSeeds()}else{let n=Ki(this.filter,_v(t),(r)=>/^[a-z0-9@/-]$/.test(r));if(n!==void 0)this.filter=n,this.pick=0}}remember(t){if(t!==this.lastEdit||OL.has(t))this.history.push({list:[...this.list],lch:[...this.lch],signature:[...this.signature]}),this.future=[];this.lastEdit=t}set(t,e,n){if(!le(e)||this.list[t]===e)return;this.remember(n),this.list[t]=e,this.lch[t]=this.lchOf(e),this.trail([t])}follow(){if(this.row<A.length){this.notice="= works on an ANSI row — the bright takes its normal";return}let t=this.row,e=this.row+8,n=this.lch[t];this.remember("follow"),this.place(e,Vi(n.l+0.06,0,1),n.c,n.h),this.links.set(e,t),this.unlinked.delete(e),this.offsets.set(e,gp(n,this.lch[e])),this.seat(e),this.notice=`${Ce(e).name} follows ${Ce(t).name.toLowerCase()}`}mark(){let t=An[this.slot()];this.remember("sig");let e=this.signature.includes(t)?this.signature.filter((r)=>r!==t):[...this.signature,t],n=e.length>3?e[0]:void 0;this.signature=e.slice(-3),this.notice=this.signature.length===3?`Signature: ${this.signature.join(", ")}${n?` — ${n} dropped`:""}`:`The signature needs three slots — ${this.signature.length} marked`}fix(){let t=ur(this.list,this.signature,this.waive),{theme:e,moves:n,left:r}=Sl({...t,selectionBackground:t.selectionBackground,signatureSlots:this.signature});if(n.length===0){this.notice=Un(t).length===0?"Already passes the gate":"No color change fixes it";return}this.remember("fix");let i=cn({...this.colors(),foreground:e.foreground,selection:e.selectionBackground,ansi:e.ansi}),o=this.list;this.list=i,this.lch=i.map((s,a)=>s===o[a]?this.lch[a]:this.lchOf(s)),this.notice=`Moved ${n.length} ${n.length===1?"color":"colors"}${r.length===0?" — passes the gate":" closer to the gate"}`}save(){let t=this.options.check(this.edited());if(t){this.notice=t;return}this.result="saved"}undo(){let t=this.history.pop();if(!t){this.notice="Nothing to undo";return}this.future.push({list:[...this.list],lch:[...this.lch],signature:[...this.signature]}),this.restore(t)}redo(){let t=this.future.pop();if(!t){this.notice="Nothing to redo";return}this.history.push({list:[...this.list],lch:[...this.lch],signature:[...this.signature]}),this.restore(t)}restore(t){this.list=[...t.list],this.lch=[...t.lch],this.signature=[...t.signature],this.lastEdit=void 0}}import{mkdirSync as _L,readFileSync as Ep,writeFileSync as Zv}from"node:fs";import{dirname as BL}from"node:path";import{isMainThread as GL,parentPort as Qv,Worker as UL}from"node:worker_threads";var IL=new Set(["comic","4koma","monochrome","greyscale","sketch","lineart","speech_bubble"]),RL=new Set(["scenery","landscape","scenic","no_humans","wide_shot","very_wide_shot"]),PL=0.04,NL=0.1,AL=0.05,TL=4096;function HL(t){return new Set(t.cutouts.split(/\s+/).map((e)=>e.replace(/^~/,"")).filter(Boolean))}function CL(t,e,n,r=0){let{site:i,post:o}=t,s=new Set(o.tags),a=[...HL(i)].some((l)=>s.has(l)),c=Math.min(o.width,o.height),u=o.width>0&&o.height>0?o.width/o.height/(e.w/e.h):1;return(o.solo?2:0)+([...IL].some((l)=>s.has(l))?-3:0)+([...RL].some((l)=>s.has(l))?-1.5:0)+2*Math.min(1,c/e.h)+(a?1.5:-Math.min(1.5,Math.abs(Math.log(u))))+(n>0?1.5*Math.log1p(Math.max(0,o.score))/Math.log1p(n):0)+2*r}function Ml(t,e,n=new Map){let r=new Map;for(let{site:i,post:o}of t)r.set(i,Math.max(r.get(i)??0,o.score));return t.map((i,o)=>({pick:i,at:o,score:CL(i,e,r.get(i.site)??0,n.get(i.post))})).sort((i,o)=>o.score-i.score||i.at-o.at).map(({pick:i})=>i)}function zv(t){let e=new Map;for(let r of t)e.set(r.site,[...e.get(r.site)??[],r]);let n=[];for(let r=0;n.length<t.length;r++)for(let i of e.values()){let o=i[r];if(o)n.push(o)}return n}function vp(t){let e=t/255;return e<=0.04045?e/12.92:((e+0.055)/1.055)**2.4}function Kv(t,e,n){let[r,i,o]=[vp(t),vp(e),vp(n)],s=Math.cbrt(0.4122214708*r+0.5363325363*i+0.0514459929*o),a=Math.cbrt(0.2119034982*r+0.6806995451*i+0.1073969566*o),c=Math.cbrt(0.0883024619*r+0.2817188376*i+0.6299787005*o);return[0.2104542553*s+0.793617785*a-0.0040720468*c,1.9779984951*s-2.428592205*a+0.4505937099*c,0.0259040371*s+0.7827717662*a-0.808675766*c]}function Dv(t,e){let n=e.map((s)=>Kv(...et(s))).filter(([,s,a])=>Math.hypot(s,a)>=PL);if(n.length===0)return 0;let r=Math.max(1,Math.floor(Math.sqrt(t.width*t.height/TL))),i=n.map(()=>0),o=0;for(let s=0;s<t.height;s+=r)for(let a=0;a<t.width;a+=r){let c=(s*t.width+a)*4;if(t.data[c+3]<128)continue;o++;let[u,l,d]=Kv(t.data[c],t.data[c+1],t.data[c+2]);n.forEach(([f,h,m],g)=>{if(Math.hypot(u-f,l-h,d-m)<NL)i[g]=i[g]+1})}if(o===0)return 0;return i.reduce((s,a)=>s+Math.min(1,a/o/AL),0)/n.length}var LL=/(?:^|[^0-9a-f])([0-9a-f]{32})(?:[^0-9a-f]|$)/i,FL=[[/yande\.re\/post\/show\/(\d+)/,"yande"],[/konachan\.(?:com|net)\/post\/show\/(\d+)/,"konachan"],[/danbooru\.donmai\.us\/(?:posts|post\/show)\/(\d+)/,"danbooru"],[/zerochan\.net\/(\d+)(?:[?#\s]|$)/,"zerochan"]];function Sp(t){let e=/(\d+)_p(\d+)/.exec(t.source);return[...t.md5?[`md5:${t.md5}`]:[],...e&&t.source.includes("pximg")?[`pixiv:${e[1]}_p${e[2]}`]:[]]}function qv(t,e){let n=LL.exec(e.source)?.[1]?.toLowerCase();return[`post:${t.key}:${e.id}`,...e.md5?[`md5:${e.md5}`]:[],...n&&n!==e.md5?[`md5:${n}`]:[],...FL.flatMap(([r,i])=>{let o=r.exec(e.source)?.[1];return o?[`post:${i}:${Number(o)}`]:[]}),...e.family?[`family:${t.key}:${e.family}`]:[]]}function Yv(t,e){let n=t.owner||t.named.artist[0]||"";return n!==""&&n===(e.owner||e.named.artist[0]||"")&&t.width===e.width&&t.height===e.height}function Jv(t){let r=[];for(let o=0;o<8;o++){let s=Math.floor(o*t.height/8),a=Math.max(s+1,Math.floor((o+1)*t.height/8));for(let c=0;c<9;c++){let u=Math.floor(c*t.width/9),l=Math.max(u+1,Math.floor((c+1)*t.width/9)),d=0;for(let f=s;f<a;f++)for(let h=u;h<l;h++){let m=(f*t.width+h)*4,g=t.data[m+3]/255,b=0.299*t.data[m]+0.587*t.data[m+1]+0.114*t.data[m+2];d+=b*g+255*(1-g)}r.push(d/((l-u)*(a-s)))}}let i=0n;for(let o=0;o<8;o++)for(let s=0;s<8;s++)i=i<<1n|(r[o*9+s]>r[o*9+s+1]?1n:0n);return i.toString(16).padStart(16,"0")}function jL(t,e){let n=BigInt(`0x${t}`)^BigInt(`0x${e}`),r=0;while(n>0n)r+=Number(n&1n),n>>=1n;return r}function Vv(t,e){if(t.width<=0||t.height<=0||e.width<=0||e.height<=0)return!1;return Math.abs(Math.log(t.width/t.height/(e.width/e.height)))<0.01&&jL(t.hash,e.hash)<=2}var WL={thumb:"tile",band:"band",match:"tile",show:"view",backdrop:"view",redraw:"view"},xl;async function KL(t){if(t.job==="redraw")return Qu(t.home,t.name,t.key,t.paint,t.blur,t.aligns,t.user);if(t.job==="show"){if(xl?.from!==t.from){let s=$r(new Uint8Array(Ep(t.from)),Se);xl={from:t.from,clear:Wn(s),inked:gf(s)}}let{image:r,fill:i,opacity:o}=g0(xl.inked,t.colors,t.tone,t.width,t.height,t.blur,t.tune,t.coloring);return _L(BL(t.to),{recursive:!0}),Zv(t.to,je(r)),{clear:xl.clear,fill:i,opacity:o}}let e=$r(new Uint8Array(Ep(t.from)),Se);if(t.job==="backdrop"){jc(t.home,t.colors,t.tone,e,{...t.origin,bytes:new Uint8Array(Ep(t.source)),cut:t.from!==t.source},t,t.blur,t.coloring);let r=t.tune&&fe(t.home,t.colors.name).find((i)=>i.key===se(t.origin));if(t.tune&&r)Vs(V(t.home),r,t.tune,t.aligns??!0,t.user??t.home);return 0}if(t.job==="match")return{match:Dv(e,t.colors),hash:Jv(e)};if(t.job==="thumb")return F(t.to,je(tw(e,t.width,t.height))),0;let n=e.data.subarray(t.y*e.width*4,(t.y+t.height)*e.width*4);return Zv(t.to,je({width:e.width,height:t.height,data:n})),0}function zL(t){t.on("message",async(e)=>{try{t.postMessage({id:e.id,value:await KL(e)})}catch(n){t.postMessage({id:e.id,error:n instanceof Error?n.message:String(n)})}})}class Mp{worker;next=1;waiting=new Map;send(t){let e=this.next++;return new Promise((n,r)=>{let i=this.open();this.waiting.set(e,{ok:n,no:r}),i.ref(),i.postMessage({...t,id:e})})}close(){this.worker?.terminate(),this.worker=void 0,this.drop(Error("renderer closed"))}open(){if(this.worker)return this.worker;let t=new UL(import.meta.filename);t.unref(),t.on("message",({id:n,value:r,error:i})=>{let o=this.waiting.get(n);if(this.waiting.delete(n),this.waiting.size===0)t.unref();if(i!==void 0)o?.no(Error(i));else o?.ok(r)});let e=(n)=>{if(this.worker===t)this.worker=void 0;this.drop(n instanceof Error?n:Error("renderer stopped"))};return t.on("error",e),t.on("exit",()=>e(void 0)),this.worker=t,t}drop(t){for(let e of this.waiting.values())e.no(t);this.waiting.clear()}}class Da{lines=new Map;run(t){let e=WL[t.job],n=this.lines.get(e);if(!n)n=new Mp,this.lines.set(e,n);return n.send(t)}close(){for(let t of this.lines.values())t.close();this.lines.clear()}}class xp{lines;constructor(t){this.lines=Array.from({length:Math.max(1,t)},()=>new Mp)}async map(t){let e=[],n=0;return await Promise.all(this.lines.map(async(r)=>{while(n<t.length){let i=n++;try{e[i]=await r.send(t[i])}catch(o){e[i]=o instanceof Error?o:Error(String(o))}}})),e}close(){for(let t of this.lines)t.close()}}if(!GL&&Qv)zL(Qv);import{existsSync as DL,mkdtempSync as qL,readFileSync as YL,rmSync as Xv,writeFileSync as JL}from"node:fs";import{tmpdir as VL}from"node:os";import{basename as eS,join as tS}from"node:path";var ZL=6;class Op{dir;made=[];of(t,e){this.dir??=qL(tS(VL(),"ttheme-tint-"));let n=tS(this.dir,`${eS(t,".png")}.${e.slice(1).toLowerCase()}.png`);if(!DL(n)){let r=new Uint8Array(YL(t));JL(n,$c(r,e)??mi(hi(jt(r)),e)),this.made.push(n);while(this.made.length>ZL)Xv(this.made.shift(),{force:!0})}return n}clear(){if(this.dir)Xv(this.dir,{recursive:!0,force:!0});this.dir=void 0,this.made.length=0}}function nS(t,e,n,r,i){if(_e(t)==="original")return e;let o=vn(n,[...r]);return o.color===t.tone?e:i.of(e,o.color)}function rS(t,e){let n=eS(e);return t.find((r)=>n.startsWith(`${r.stem}.`)||n.startsWith(`${r.stem}@`))}var iF=2147483625,sS=2147483626,Tn=2147483627,oF=-1073741831,aS=-1073741830,sF=-1073741829,aF=4;function cF(t,e,n,r,i){let o=Math.trunc,s=n.col*r.w,a=n.row*r.h,c=o((Math.max(i.x,s)+r.w-1)/r.w),u=o(Math.min(i.x+i.w,s+n.cols*r.w)/r.w),l=o((Math.max(i.y,a)+r.h-1)/r.h),d=o(Math.min(i.y+i.h,a+n.rows*r.h)/r.h);if(u<=c||d<=l)return;return{col:c,row:l,cols:u-c,rows:d-l,x:o((c*r.w-i.x)*t/i.w),y:o((l*r.h-i.y)*e/i.h),w:o((u-c)*r.w*t/i.w),h:o((d-l)*r.h*e/i.h)}}function uF(t){try{let e=tF(t,"r"),n=Buffer.alloc(24);return eF(e,n,0,24,0),QL(e),n.readUInt32BE(0)===2303741511?{width:n.readUInt32BE(16),height:n.readUInt32BE(20)}:void 0}catch{return}}class Ol{ready=()=>{};cell={w:0,h:0};held;tints=new Op;sent=new Map;placed=new Map;viewed="";renders;scratch;made=0;bands=new Map;home;name;views;banded;files;static of(t,e,n,r){if(Pt(t)||!Ko(t,r)||!(zo(t)||Pi(t)))return;return new Ol(t,e,n)}constructor(t,e,n){this.home=e,this.name=n,this.views=Pi(t),this.banded=$u(t),this.files=ku(t)}get laid(){return this.cell.w>0}measured(t){if(this.cell.w===0&&t.w>0&&t.h>0)this.cell=t}load(){let t=V(this.home),e=Oe(t,this.name,nF()),n=[];try{n=Ot(t).palettes[this.name]?.pictures??[]}catch{}let r=e?rS(n,e.image):void 0;this.held=e&&r?{picture:r,image:e.image,opacity:e.opacity,cover:e.cover,at:Ut.indexOf(e.position)+1||5}:void 0}draw(t,e,n,r,i,o={col:0,row:0,cols:r,rows:i}){if(this.cell.w===0)return"";let s=t[0],a=this.look(t,e,n,o,!this.views||o.cols===r&&o.rows===i);if(this.views){let u=r*this.cell.w,l=i*this.cell.h,d=a?`${s}|${a.image}|${a.opacity}|${u}|${l}|${a.box.w}|${a.box.h}|${a.box.x}|${a.box.y}|${this.held?.at??5}`:`${s}||1|${u}|${l}|0|0|0|0|5`;if(d===this.viewed)return"";return this.viewed=d,Ni(d)}let c=this.layer(iF,oF,"f=24",Buffer.from(et(s)),o);if(a){let u=Math.max(0,Math.min(255,Math.round((1-a.opacity)*255)));c+=this.picture(a),c+=this.layer(sS,sF,"f=32",Buffer.from([...et(s),u]),o)}else c+=this.drop(Tn)+this.drop(sS);return c}resized(){this.sent.clear(),this.placed.clear(),this.viewed=""}clear(){let t=this.views&&this.viewed?Ni(""):"";for(let e of this.sent.keys())t+=_a(e);return this.resized(),t}close(){let t=this.clear();if(this.tints.clear(),this.renders?.close(),this.scratch)iS(this.scratch,{recursive:!0,force:!0});return t}look(t,e,n,r,i){let o=this.held;if(!o)return;let s={name:this.name,...Gt([...t]),waived:[...n]},a=nS(o.picture,o.image,s,e,this.tints),c=uF(a);if(!c)return;let u=Ao(c.width,c.height,r.cols*this.cell.w,r.rows*this.cell.h,100,o.at,o.cover&&i),l={...u,x:u.x+r.col*this.cell.w,y:u.y+r.row*this.cell.h},d=cF(c.width,c.height,r,this.cell,l);if(!d)return;return{image:a,opacity:o.opacity,...c,box:l,rect:d}}layer(t,e,n,r,i){let o=r.toString("base64"),s=`${o}|${i.col}|${i.row}|${i.cols}|${i.rows}`;if(this.placed.get(t)===s)return"";return this.sent.set(t,s),this.placed.set(t,s),`\x1B_Ga=t,${n},s=1,v=1,i=${t},q=2;${o}\x1B\\\x1B[${i.row+1};${i.col+1}H\x1B_Ga=p,i=${t},p=${t},c=${i.cols},r=${i.rows},C=1,z=${e},q=2\x1B\\`}picture(t){let{image:e,rect:n}=t;if(this.banded&&(2*n.y+n.h-t.height)**2>1){let o=this.band(t.image,n.y,n.h);if(!o.ready)return"";e=o.path,n={...n,y:0}}let r="";if(this.sent.get(Tn)!==e){let o=hl({id:Tn,path:e,row:0,col:0,cols:0,rows:0,z:aS},this.files);if(o===void 0)return"";r+=o,this.sent.set(Tn,e),this.placed.delete(Tn)}let i=`${n.col};${n.row};${n.cols};${n.rows};${n.x};${n.y};${n.w};${n.h}`;if(this.placed.get(Tn)!==i)r+=`\x1B[${n.row+1};${n.col+1}H\x1B_Ga=p,i=${Tn},p=${Tn},x=${n.x},y=${n.y},w=${n.w},h=${n.h},c=${n.cols},r=${n.rows},C=1,z=${aS},q=2\x1B\\`,this.placed.set(Tn,i);return r}drop(t){if(!this.sent.has(t))return"";return this.sent.delete(t),this.placed.delete(t),_a(t)}band(t,e,n){let r=`${t}|${e}|${n}`,i=this.bands.get(r);if(i)return i;this.scratch??=XL(oS(rF(),"ttheme-edit-")),this.renders??=new Da;let o={path:oS(this.scratch,`band-${++this.made}.png`),ready:!1};this.bands.set(r,o),this.renders.run({job:"band",from:t,to:o.path,y:e,height:n}).then(()=>{o.ready=!0,this.ready()}).catch(()=>{});for(let[s,a]of this.bands){if(this.bands.size<=aF)break;if(a.ready&&a.path!==this.sent.get(Tn))this.bands.delete(s),iS(a.path,{force:!0})}return o}}var Qi=50;function st(t,e){return Vt(t,e)}function $s(t){return{color:t,dim:(e)=>t?`${C}${e}${$e}`:e,bold:(e)=>t?`${ct}${e}${$e}`:e,fg:(e)=>t?qe(e):"",bg:(e)=>t?`\x1B[48;2;${et(e).join(";")}m`:""}}function qa(t){return vt(t)>0.35?"#000000":"#ffffff"}function Ip(t,e){return t.held!==void 0&&t.held-e.c>0.0005?t.held:void 0}function Il(t,e,n,r){let i=e.mode==="tune"&&e.channel===Qt,o=e.ratio(),{floor:s}=e.partner(),a=(g)=>Math.round(Math.log(Math.max(1,g))/Math.log(21)*(n-1)),c=a(o),u=s===void 0?-1:a(s),l=r===void 0?-1:a(r),d=i?"━":"─",f=Array.from({length:n},(g,b)=>b===c?t.bold("●"):b===l?"○":b===u?"┃":b<u?t.dim(d):d).join(""),h=`${o.toFixed(2)}:1`.padStart(6),m={kind:"channel",channel:Qt};return`${st(m,i?t.bold("▸◐"):t.dim(" ◐"))} ${st({kind:"bar",channel:Qt},f)} ${st(m,i?t.bold(h):t.dim(h))}`}function Rl(t,e){if(!t.misses().has(e))return;if(bp(t.list,t.signature,t.waive,"bright-follows").includes(e))return e-A.length<8?"= makes the bright follow its normal":"= on the normal makes this follow it";return"f moves the colors the gate misses"}function Pl(t,e,n){let r=$p(t.list,t.signature,t.waive,e),i=Ip(t,n);if(i!==void 0)r.push({ok:void 0,text:`Chroma ○ ${i.toFixed(3)} is held while you tune — ${n.c.toFixed(3)} fits this lightness and hue`});return r}var lF={top:"╭╮",mid:"├┤",bottom:"╰╯"};function Xt(t,e,n=[]){let[r,i]=[...lF[e]],o=[...`${r}${"─".repeat(Math.max(0,t-2))}${i}`];for(let[s,a]of n)[...a].forEach((c,u)=>{if(s+u>0&&s+u<t-1)o[s+u]=c});return o.join("")}function dn(t,e,n){return`${t.dim("│")}${rt(e,n-2)}${t.dim("│")}`}function Nl(t){let e=(n,r)=>n.toFixed(r).replace(/^0(?=\.)/,"");return`${e(t.l,2)} ${e(t.c,3)} ${t.h.toFixed(0).padStart(3)}°`}function cS(t){return`${t.l.toFixed(2)} ${t.c.toFixed(3)} ${t.h.toFixed(0).padStart(3)}°`}function Rp(t,e){return e===void 0?t.dim("·"):e?t.dim("✓"):t.bold("✗")}function dF(t,e,n,r=Qi){let i=kp(e.list,e.signature,e.waive).sort((u,l)=>Number(u.ok!==!1)-Number(l.ok!==!1)),o=i.filter((u)=>u.ok===!1).length,s=` ${t.dim("Gate")} ${o===0?t.dim("passes"):t.bold(`${o} ${o===1?"miss":"misses"}`)}`,a=r-4,c=i.flatMap((u)=>{let l=`${u.value} ${u.bound}`,d=` ${Rp(t,u.ok)} ${yt(u.ok===!1?u.label:t.dim(u.label),t.dim(l),a-2)}`,f=[...new Set(u.slots)].map((g)=>Ce(g).name),h=u.slots[0],m=(g)=>h===void 0?g:st({kind:"slot",slot:h},g);return f.length>0?[m(d),m(` ${t.dim(rt(f.join(" · "),a-2))}`)]:[m(d)]});return[o===0?s:yt(s,`${t.bold("n")} ${t.dim("next miss")}`,r-2),...c.slice(0,Math.max(0,n-1))]}function uS(t,e){let n=t-A.length;if(n>=0)return e===String(n)||e===`B${n}`||e===`K${n}`;return t===3&&e==="s"||t===2&&e==="c"}function Al(t,e,n,r){let i=r?"\x1B[4m":"";if(n==="d")return`${t.fg(e.foreground)}\x1B[2m${i}`;if(n==="b")return`${t.fg(e.foreground)}\x1B[1m${i}`;if(n==="s")return`${t.bg(e.selection)}${t.fg(e.foreground)}${i}`;if(n==="c")return`${t.bg(e.cursor)}${i}`;let o=/^([BK]?)(\d+)$/.exec(n);if(!o)return`${t.fg(e.foreground)}${i}`;let s=e.ansi[Number(o[2])];if(o[1]==="K")return`${t.fg(e.ansi[0])}${t.bg(s)}${i}`;return`${t.fg(s)}${o[1]==="B"?"\x1B[1m":""}${i}`}function Ya(t,e,n,r,i){let o=e.length-1,s=Math.max(0,Math.min(o,n)),a=i===void 0?-1:Math.max(0,Math.min(o,i));if(!t.color)return e.map((c,u)=>u===s?"●":u===a?"○":r?"━":"─").join("");return e.map((c,u)=>{let l=c??"#000000";if(u===s)return`${t.bg(l)}${t.fg(qa(l))}●\x1B[39;49m`;if(u===a)return c?`${t.bg(c)}${t.fg(qa(c))}○\x1B[39;49m`:`${t.fg("#aaaaaa")}○`;return c?`${t.fg(c)}█`:`${t.fg(r?"#777777":"#555555")}░`}).join("").concat("\x1B[39m")}function Tl(t,e,n){return Array.from({length:n},(r,i)=>{let o=e.min+(e.max-e.min)*i/(n-1),s={...t,[e.key]:o};return Nn(s.l,s.c,s.h)?ze(s.l,s.c,s.h):void 0})}function Xi(t,e,n,r){return Math.round((t-e)/(n-e)*(r-1))}function Pp(t){return kp(t.list,t.signature,t.waive).filter((e)=>e.ok===!1).length}function Ja(t,e,n,r){if(n<3)return[];let i=Pp(e),o=i===0?" Gate ✓ passes ":` Gate ✗ ${i} · n next `;return[t.dim(Xt(r,"top",[[2,o]])),...dF(t,e,n-1,r-1).slice(1).map((s)=>dn(t,s,r)),t.dim(Xt(r,"bottom"))]}var dr=0.98,Va=0.12,fF=0.37,lS=0.74,hF=0.15,mF=-1073741828,Np=-1073741827,Ap=-1073741826,pF=-1073741825,gF=2147483584,bF=["panel","plane","hue","contrast","mark","hue-thumb","contrast-thumb","origin","hue-origin","contrast-origin"],wF=4096;function Za(t,e){return bs(t,e,fF)}function Cl(t,e,n){let r=Za(t,n);return r>0.000001?Math.min(1,e/r):0}function Qa(t,e){return{width:t,height:e,data:new Uint8Array(t*e*4)}}function ni(t,e,n,r,i){let o=r[3]*i;if(o<=0||e<0||n<0||e>=t.width||n>=t.height)return;let s=(n*t.width+e)*4,a=t.data;if(o>=1){a[s]=r[0],a[s+1]=r[1],a[s+2]=r[2],a[s+3]=255;return}let c=a[s+3]/255,u=o+c*(1-o);for(let l=0;l<3;l++)a[s+l]=Math.round((r[l]*o+a[s+l]*c*(1-o))/u);a[s+3]=Math.round(u*255)}function lr(t,e=1){return[...et(t),e]}function ys(t,e,n,r,i,o,s){let a=Math.abs(t-(n+i/2))-(i/2-s),c=Math.abs(e-(r+o/2))-(o/2-s);return Math.hypot(Math.max(a,0),Math.max(c,0))+Math.min(Math.max(a,c),0)-s}function to(t,e,n,r){let i=[],o=[],s=Math.max(0,Math.floor(r?.x??0)),a=Math.max(0,Math.floor(r?.y??0)),c=Math.min(t,Math.ceil(r?r.x+r.w:t)),u=Math.min(e,Math.ceil(r?r.y+r.h:e));for(let l=a;l<u;l++)for(let d=s;d<c;d++){let f=n(d+0.5,l+0.5);if(f>0.002)i.push(l*t+d),o.push(Math.min(1,f))}return{at:Uint32Array.from(i),cover:Float32Array.from(o)}}function eo(t,e,n){for(let r=0;r<e.at.length;r++){let i=e.at[r];ni(t,i%t.width,Math.floor(i/t.width),n,e.cover[r])}}function Tp(t,e){return(n,r)=>Math.max(0,0.5-ys(n,r,t.x,t.y,t.w,t.h,e))}function dS(t,e,n){return(r,i)=>Math.max(0,0.5-Math.abs(ys(r,i,t.x,t.y,t.w,t.h,e)+n/2)+n/2)}var Hl=new Map;function $F(t,e,n,r){let i=`${e.w}x${e.h} ${mS({...t,ground:"#000000",ink:"#000000",accent:"#000000"})}`,o=Hl.get(i);if(o)return o;let{panel:s}=t,a={x:e.w,y:0,w:s.cols*e.w,h:s.rows*e.h},c=Math.round(e.h*0.45),u=Math.round(e.h*0.18),l=e.h*0.6,d=Math.max(1,Math.round(e.h/22)),f=(O)=>({x:(O.col-s.col+1)*e.w,y:(O.row-s.row)*e.h}),h=Math.max(1,Math.round(e.h*0.08)),m=f(t.tabs),g={x:m.x,y:m.y+h,w:t.tabs.cols*e.w,h:e.h-2*h},b=Math.floor(t.tabs.cols/t.tabs.count)*e.w,w=Math.max(1,Math.round(h/2)),k={x:g.x+t.tabs.active*b+w,y:g.y+w,w:(t.tabs.active===t.tabs.count-1?g.w-t.tabs.active*b:b)-2*w,h:g.h-2*w},v=f(t.field),S={x:v.x,y:v.y+h,w:t.field.cols*e.w,h:e.h-2*h},M=t.divider===void 0?void 0:{x:a.x+e.w*0.6,y:(t.divider-s.row)*e.h,w:a.w-e.w*1.2,h:d},I={shadow:to(n,r,(O,H)=>{let N=ys(O,H,a.x,u,a.w,a.h,c);return N>0&&N<l?(1-N/l)**2:0}),fill:to(n,r,Tp(a,c),a),border:to(n,r,dS(a,c,d),a),track:to(n,r,Tp(g,g.h*0.3),g),segment:to(n,r,Tp(k,k.h*0.3),k),field:to(n,r,dS(S,S.h*0.3,d),S),divider:M&&to(n,r,()=>1,M)};if(Hl.size>8)Hl.clear();return Hl.set(i,I),I}function kF(t){let e=vt(t.ground)<0.18;return{dark:e,surface:pt(t.ground,t.ink,e?0.07:0.04)}}function yF(t,e){let n=Qa((t.panel.cols+2)*e.w,(t.panel.rows+1)*e.h),r=$F(t,e,n.width,n.height),{dark:i,surface:o}=kF(t);if(eo(n,r.shadow,[0,0,0,i?0.45:0.18]),eo(n,r.fill,lr(o)),eo(n,r.border,lr(t.ink,i?0.16:0.2)),eo(n,r.track,lr(t.ink,i?0.06:0.07)),eo(n,r.segment,lr(t.accent,i?0.24:0.2)),eo(n,r.field,lr(t.ink,i?0.22:0.28)),r.divider)eo(n,r.divider,lr(t.ink,i?0.12:0.16));return n}function vF(t,e,n){let r=Qa(Math.round(t.cols*n.w),Math.round(t.rows*n.h)),{width:i,height:o,data:s}=r,a=Math.round(n.h*0.3),c=Math.max(1,(t.cols-1)*n.w),u=(h)=>Math.min(1,Math.max(0,(h+0.5-n.w/2)/c)),l=t.rows*2-1,d=(h)=>dr-Math.min(1,Math.max(0,((h+0.5)/n.h*2-0.5)/l))*(dr-Va),f=[];for(let h=0;h<o;h++){if(h%2===0){let m=d(h+0.5),g=Za(m,e);f=Array.from({length:Math.ceil(i/2)},(b,w)=>Nn(m,u(w*2+0.5)*g,e)??[0,0,0])}for(let m=0;m<i;m++){let b=(m<a||m>=i-a)&&(h<a||h>=o-a)?Math.min(1,Math.max(0,0.5-ys(m+0.5,h+0.5,0,0,i,o,a))):1;if(b<=0)continue;let w=f[m>>1],k=(h*i+m)*4;s[k]=w[0],s[k+1]=w[1],s[k+2]=w[2],s[k+3]=Math.round(b*255)}}return r}function hS(t,e){let n=Math.max(4,Math.round(t.h*0.42));return{top:Math.round((t.h-n)/2),height:n,width:e*t.w}}function SF(t,e){let n=Qa(t.cols*e.w,e.h),{top:r,height:i,width:o}=hS(e,t.cols),s=Array.from({length:o},(a,c)=>{let l=Math.min(1,Math.max(0,((c+0.5)/e.w-0.5)/Math.max(1,t.cols-1)))*360;return Nn(lS,bs(lS,l,hF),l)??[0,0,0]});for(let a=r;a<r+i;a++)for(let c=0;c<o;c++){let u=Math.min(1,Math.max(0,0.5-ys(c+0.5,a+0.5,0,r,o,i,i/2))),l=s[c];ni(n,c,a,[l[0],l[1],l[2],1],u)}return n}function EF(t,e,n){let r=Qa(t.cols*n.w,n.h),{top:i,height:o,width:s}=hS(n,t.cols),a=t.floor===void 0?-1:Math.round((t.floor*(t.cols-1)+0.5)*n.w),c=Math.max(2,Math.round(o*0.45)),u=i+Math.round((o-c)/2);for(let l=u;l<u+c;l++)for(let d=0;d<s;d++){let f=Math.min(1,Math.max(0,0.5-ys(d+0.5,l+0.5,0,u,s,c,c/2))),h=a<0||d>=a;ni(r,d,l,lr(e,h?t.lit?0.5:0.36:0.14),f)}if(a>=0){let l=Math.max(2,Math.round(n.w/5));for(let d=i-1;d<i+o+1;d++)for(let f=a-Math.floor(l/2);f<a-Math.floor(l/2)+l;f++)ni(r,f,d,lr(e,0.85),1)}return r}function MF(t,e,n,r,i,o,s){let a=Qa(t*s.w,e*s.h),c=Math.max(2,Math.round(i*0.3)),u=(d,f)=>Math.min(1,Math.max(0,d-f+0.5)),l=[0,0,0,0.5];for(let d=0;d<a.height;d++)for(let f=0;f<a.width;f++){let h=Math.hypot(f+0.5-n,d+0.5-r);if(o)ni(a,f,d,lr(o),u(i-c,h));else ni(a,f,d,l,u(i-c,h)-u(i-c-1,h));ni(a,f,d,l,u(i+1,h)-u(i,h)),ni(a,f,d,[255,255,255,1],u(i,h)-u(i-c,h))}return a}function ks(t,e,n,r,i,o,s=pF){let a=Math.floor((e-r-2)/o.w),c=Math.floor((e+r+2)/o.w),u=Math.floor((n-r-2)/o.h),l=Math.floor((n+r+2)/o.h),d={row:u,col:a,cols:c-a+1,rows:l-u+1},f=Math.round((e-a*o.w)*2)/2,h=Math.round((n-u*o.h)*2)/2;return{name:t,key:`${d.cols}x${d.rows} ${f},${h} ${r} ${i??"-"}`,box:d,z:s,paint:()=>MF(d.cols,d.rows,f,h,r,i,o)}}function mS(t){let{panel:e}=t,n=(i)=>`${i.row-e.row},${i.col-e.col},${i.cols}`,r=t.divider===void 0?"-":t.divider-e.row;return`${e.cols}x${e.rows} ${t.ground} ${t.ink} ${t.accent} ${n(t.tabs)},${t.tabs.active}/${t.tabs.count} ${n(t.field)} ${r}`}function xF(t,e){let n=`${e.w}x${e.h}`,r=Math.max(4,Math.round(e.h*0.34)),i=(d,f)=>(d.col+0.5+f*(d.cols-1))*e.w,o=(d)=>(d.row+0.5)*e.h,s=t.plane,a=(d)=>{let f=(dr-d)/(dr-Va)*(s.rows*2-1);return s.row*e.h+(Math.min(s.rows*2-1,Math.max(0,f))+0.5)*e.h/2},c=a(s.l),u=[{name:"panel",key:`${n} ${mS(t)}`,box:{row:t.panel.row,col:t.panel.col-1,cols:t.panel.cols+2,rows:t.panel.rows+1},z:mF,paint:()=>yF(t,e)},{name:"plane",key:`${n} ${s.cols}x${s.rows} ${s.h.toFixed(2)}`,box:s,z:Np,paint:()=>vF(s,s.h,e.h>=24?{w:e.w/2,h:e.h/2}:e)},{name:"hue",key:`${n} ${t.hue.cols}`,box:{...t.hue,rows:1},z:Np,paint:()=>SF(t.hue,e)},{name:"contrast",key:`${n} ${t.contrast.cols} ${t.contrast.floor??"-"} ${t.contrast.lit} ${t.ink}`,box:{...t.contrast,rows:1},z:Np,paint:()=>EF(t.contrast,t.ink,e)},ks("mark",i(s,Cl(s.l,s.c,s.h)),c,r,void 0,e),ks("hue-thumb",i(t.hue,t.hue.h/360),o(t.hue),r,t.hue.color,e),ks("contrast-thumb",i(t.contrast,t.contrast.at),o(t.contrast),r,t.contrast.color,e)],l=t.origin;if(l){let d=Math.max(3,Math.round(r*0.55));u.push(ks("origin",i(s,Cl(l.l,l.c,l.h)),a(l.l),d,l.color,e,Ap),ks("hue-origin",i(t.hue,l.h/360),o(t.hue),d,l.color,e,Ap),ks("contrast-origin",i(t.contrast,l.at),o(t.contrast),d,l.color,e,Ap))}return u}function OF(t,e){let r=e.toString("base64").match(new RegExp(`.{1,${wF}}`,"g"))??[""];return r.map((i,o)=>{let s=o<r.length-1?1:0;return o===0?`\x1B_Ga=t,f=100,i=${t},m=${s},q=2;${i}\x1B\\`:`\x1B_Gm=${s},q=2;${i}\x1B\\`}).join("")}function fS(t,e,n){return`\x1B[${e.row+1};${e.col+1}H\x1B_Ga=p,i=${t},p=${t},c=${e.cols},r=${e.rows},C=1,z=${n},q=2\x1B\\`}function Hp(t){return`\x1B_Ga=d,d=I,i=${t},q=2\x1B\\`}class Ll{cell={w:0,h:0};shown=new Map;static of(t,e){return Pt(t)||!Ko(t,e)||!zo(t)?void 0:new Ll}get ready(){return this.cell.w>0}measured(t){if(this.cell.w===0&&t.w>0&&t.h>0)this.cell=t}draw(t){if(!this.ready)return"";let e=t?xF(t,this.cell):[],n="";for(let r of e)n+=this.put(r);for(let[r,i]of this.shown)if(!e.some((o)=>o.name===r))n+=Hp(i.id),this.shown.delete(r);return n}clear(){let t="";for(let e of this.shown.values())t+=Hp(e.id);return this.shown.clear(),t}put(t){let e=`${t.box.row};${t.box.col};${t.box.cols};${t.box.rows}`,n=this.shown.get(t.name);if(n&&n.key===t.key){if(n.at===e)return"";return n.at=e,fS(n.id,t.box,t.z)}let r=gF+bF.indexOf(t.name)*2,i=n?.id===r?r+1:r;return this.shown.set(t.name,{key:t.key,id:i,at:e}),`${OF(i,je(t.paint()))}${fS(i,t.box,t.z)}${n?Hp(n.id):""}`}}var IF="\x1B[0m",Fp="\x1B[33m",Xa=34,Cp=2,RF=6,jl=3,PF=7,gS="↑↓ L ←→ C ⇧←→ H tab ◐";function NF(t,e,n){let r="",i=0;for(let o of t){let s=i+_(o);if(s>e&&i<n)r+=i>=e&&s<=n?o:" ".repeat(Math.min(s,n)-Math.max(i,e));if(i=s,i>=n)break}return r}function _l(t){return t.reduce((e,n)=>e+_(n.text),0)}function Bl(t,e,n){let r=[],i=0;for(let o of t){let s=_(o.text),a=Math.max(e,i),c=Math.min(n,i+s);if(c>a)r.push({...o,text:NF(o.text,a-i,c-i)});i+=s}return r}function AF(t,e,n){return[...Bl(t,0,e),...n,...Bl(t,e+_l(n),_l(t))]}function TF(t,e){return t.map((n)=>{let r=e&&n.sgr?`${n.sgr}${n.text}${IF}`:n.text;return n.target?Vt(n.target,r):r}).join("")}function Gl(t,e,n){return t.color?`${t.bg(e.selection)}${t.fg(e.foreground)}${t.bold(` ${n} `)}\x1B[39;49m`:`[${n}]`}function bS(t){return t<A.length?A[t]:ln[(t-A.length)%8]}function wS(t,e,n,r){let i=t.signature.includes(An[n])?"◆":e.color?"■":" ";return e.color?`${e.fg(t.list[n])}${i}${r}`:i}function $S(t,e,n,r,i){return r.has(n)?e.bold("✗"):t.changed(n)?e.color?`${Fp}●${i}`:"●":" "}function kS(t,e,n){return n?t.color?`${t.fg(e.cursor)}▌\x1B[39m `:"▌ ":" "}function HF(t,e,n,r,i,o){let s=r===t.slot(),a=s?e.fg(n.foreground):"\x1B[39m",c=bS(r).padEnd(12),u=t.lch[r],l=`${kS(e,n,s)}${wS(t,e,r,a)} ${s?e.bold(c):c}${cS(u)} ${$S(t,e,r,o,a)}`,d=rt(l,i);return st({kind:"open",slot:r},s&&e.color?`${e.bg(n.selection)}${e.fg(n.foreground)}${d}\x1B[39;49m`:d)}var Lp=8,yS=44;function ec(t){return t>=yS?16:11}function pS(t,e,n,r,i,o){let s=ec(i);if(!t.visible(r))return" ".repeat(s);let a=r===t.slot(),c=a&&e.color?e.fg(n.foreground):"\x1B[39m",u=t.lch[r],l=(g,b)=>g.toFixed(b).replace(/^0(?=\.)/,""),d=`${u.h.toFixed(0).padStart(3)}°`,f=i>=yS?`${l(u.l,2)} ${l(u.c,3)} ${d}`:`${l(u.l,2)} ${d}`,h=`${wS(t,e,r,c)} ${f}${$S(t,e,r,o,c)}`,m=a&&e.color?`${e.bg(n.selection)}${e.fg(n.foreground)}${h}\x1B[39;49m`:h;return st({kind:"open",slot:r},m)}function CF(t,e,n,r,i,o){let s=A.length+r,a=s+8,c=t.row===s,u=ln[r].padEnd(Lp),l=t.linkOf(a)!==void 0?e.dim("⇠"):" ";return`${st({kind:"open",slot:s},`${kS(e,n,c)}${c?e.bold(u):u}`)}${pS(t,e,n,s,i,o)}${l} ${pS(t,e,n,a,i,o)}`}function vS(t){return 14+2*ec(t)}function LF(t){let e=ec(t)>=16;return[[2," ANSI "],[2+Lp,e?" Normal 0–7 ":" Normal "],[5+Lp+ec(t),e?" Bright 8–15 ":" Bright "]]}function FF(t,e,n,r,i){let o=t.slot(),s=Ce(o),a=vS(i),c=a-2,u=` ${s.name}${o>=A.length?` · ${s.about}`:""} `,l=[` ${e.dim(Uv(o))}`];if(o>=2){let f=hv(r,o).filter((g)=>g.count>0),h=f.length>0?f.map((g)=>`${g.name} ${g.count}`).join(" · "):"none",m=Wt("w",t.where?Gl(e,n,"w where"):e.dim("w where"));l.push(yt(` ${e.dim("Shown in")} ${h}`,`${m} `,c))}let d=o-A.length;if(d===0||d===7||d===8||d===15){let f=t.lch[o].l,h=t.lch[0].l,m=t.lch[1].l,g=Math.abs(f-h)<=Math.abs(f-m)?"the background":"the text";l.push(` ${e.dim(`L ${f.toFixed(2)} reads near ${g}`)}`)}return[e.dim(Xt(a,"top",[[2,u]])),...l.map((f)=>dn(e,f,a)),e.dim(Xt(a,"bottom"))]}function Fl(t,e){return dr-t*(dr-Va)/(e*2-1)}function SS(t,e,n,r,i){let o=Fl(Math.max(0,Math.min(e*2-1,t*2-0.5)),e),s=Math.max(0,Math.min(1,(n-0.5)/Math.max(1,r-1)));return{lightness:o,chroma:s*Za(o,i)}}function jF(t,e,n,r,i,o){let s=(d)=>{let f=Math.max(0,Math.min(i*2-1,Math.round((dr-d.l)/(dr-Va)*(i*2-1))));return{row:Math.floor(f/2),col:Math.round(Cl(d.l,d.c,d.h)*(r-1))}},{row:a,col:c}=s(e),u=o?s(o):{row:-1,col:-1},l=(d,f)=>{return`#${(Nn(d,f*Za(d,e.h),e.h)??[0,0,0]).map((m)=>m.toString(16).padStart(2,"0")).join("")}`};return Array.from({length:i},(d,f)=>{let h="";for(let m=0;m<r;m++){if(f===a&&m===c){h+=t.color?`${t.bg(n)}${t.fg(qa(n))}●\x1B[39;49m`:"●";continue}let g=m/Math.max(1,r-1);if(f===u.row&&m===u.col){let b=l(Fl(f*2+1,i),g);h+=t.color?`${t.bg(b)}${t.fg(qa(b))}○\x1B[39;49m`:"○";continue}h+=t.color?`${t.fg(l(Fl(f*2,i),g))}${t.bg(l(Fl(f*2+1,i),g))}▀\x1B[39;49m`:"·"}return st({kind:"plane",row:f,rows:i},h)})}function _F(t,e,n){if(t.format==="rgb"){let[r,i,o]=[1,3,5].map((s)=>Number.parseInt(e.slice(s,s+2),16));return`rgb(${r} ${i} ${o})`}if(t.format==="oklch")return`oklch(${n.l.toFixed(3)} ${n.c.toFixed(3)} ${n.h.toFixed(0)})`;return e}function ES(t,e,n){let r=t.slot(),i=t.lch[r],s=Pl(t,r,i).filter((c)=>c.ok===!1||c.text.startsWith("Chroma ○")).flatMap((c)=>bt(c.text,n-2).map((u,l)=>`${l===0?c.ok===!1?e.bold("✗"):e.dim("○"):" "} ${u}`)),a=Rl(t,r);return[...s.slice(0,3),...a?[e.dim(a)]:[]]}function MS(t,e,n){let r=t.pair(t.slot());if(!r)return;let i=t.slot()>=r.bright,o=bS(i?r.normal:r.bright).toLowerCase(),s=`${r.lift>=0?"+":""}${r.lift.toFixed(2)}`,a=n-9,c=i?r.on?[`⇠ Linked to ${o} · L ${s}`,`⇠ ${o} · L ${s}`,`⇠ ${o}`]:[`Not linked to ${o}`,"Not linked"]:r.on?[`Bright follows · L ${s}`,"Bright follows"]:["Its bright moves on its own","Moves on its own"],u=c.find((l)=>_(l)<=a)??c[c.length-1]??"";return yt(e.dim(u),Wt("l",`${e.bold("l")} ${e.dim(r.on?"unlink":"link")}`),n)}function xS(t,e,n){let r=t.slot(),i=t.list[r],o=t.lch[r],s=t.typing!==void 0?e.bold(`${t.typing}▏`):Wt("#",e.bold(_F(t,i,o))),a=t.start[r],c=e.color?`${e.fg(a)}■\x1B[39m `:"";return yt(s,a!==i?e.dim(`was ${c}${a}`):"",n)}function BF(t,e,n,r,i){let o=t.slot(),s=t.lch[o],a=t.list[o],c=r-4,u=e.dim("│"),l=(O)=>`${u} ${rt(O,c)} ${u}`,d=MS(t,e,c),f=6+(d?1:0),h=ES(t,e,c).slice(0,Math.max(0,i-f-jl)),m=Math.max(jl,Math.min(RF,i-f-h.length)),g=" L × C ",b=` H ${s.h.toFixed(0)}° `,w=Math.max(0,r-4-_(" L × C ")-_(b)),k=[`${e.dim("╭─")}${e.dim(" L × C ")}${e.dim("─".repeat(w))}${e.dim(b)}${e.dim("─╮")}`],v=t.origin();for(let O of jF(e,s,a,c,m,v?.lch))k.push(l(O));let S=un[2];k.push(l(st({kind:"bar",channel:2},Ya(e,Tl(s,S,c),Xi(s.h,S.min,S.max,c),t.mode==="tune"&&t.channel===2,v&&Xi(v.lch.h,S.min,S.max,c))))),k.push(l(Il(e,t,Math.max(8,c-11),v?.ratio)));let M=(O,H)=>st({kind:"format",format:H},t.format===H?Gl(e,n,O):e.dim(` ${O} `));if(k.push(l(`${M("Hex","hex")} ${M("RGB","rgb")} ${M("OKLCH","oklch")}`)),k.push(l(xS(t,e,c))),d)k.push(l(d));for(let O of h)k.push(l(O));let I=rt(` ${gS} `,r-4,!1);return k.push(`${e.dim("╰─")}${e.dim(I)}${e.dim("─".repeat(Math.max(0,r-4-_(I))))}${e.dim("─╯")}`),{lines:k.map((O)=>st({kind:"picker"},O))}}var tc=[["Hex","hex"],["RGB","rgb"],["OKLCH","oklch"]];function GF(t,e,n,r,i){let o=t.lch[t.slot()],s=r-2,a=MS(t,e,s),c=6+(a?1:0),u=ES(t,e,s).slice(0,Math.max(0,i-c-jl)),l=Math.max(jl,Math.min(PF,i-c-u.length)),d=(O)=>` ${rt(O,s)} `,f=[d(yt(e.dim("L × C"),e.dim(`H ${o.h.toFixed(0)}°`),s))];for(let O=0;O<l;O++)f.push(d(st({kind:"plane",row:O,rows:l}," ".repeat(s))));let h=f.length;f.push(d(st({kind:"bar",channel:2}," ".repeat(s))));let m=f.length,g=t.mode==="tune"&&t.channel===Qt,b={kind:"channel",channel:Qt},w=`${t.ratio().toFixed(2)}:1`.padStart(8),k=s-11;f.push(d(`${st(b,g?e.bold("◐"):e.dim("◐"))} ${st({kind:"bar",channel:Qt}," ".repeat(k))} ${st(b,g?e.bold(w):e.dim(w))}`));let v=f.length,S=Math.floor(s/tc.length);f.push(d(tc.map(([O,H],N)=>{let L=N===tc.length-1?s-S*N:S,K=Math.floor((L-_(O))/2),B=`${" ".repeat(K)}${O}${" ".repeat(L-K-_(O))}`,X=t.format===H?e.color?`${e.fg(n.cursor)}${e.bold(B)}\x1B[39m`:`[${O}]`.padEnd(L):e.dim(B);return st({kind:"format",format:H},X)}).join("")));let M=f.length;f.push(d(` ${xS(t,e,s-2)} `));let I=a?f.length:void 0;if(a)f.push(d(a));for(let O of u)f.push(d(O));return f.push(d(e.dim(gS))),{lines:f.map((O)=>st({kind:"picker"},O)),parts:{plane:{row:1,col:1,cols:s,rows:l},hue:{row:h,col:1,cols:s,rows:1},contrast:{row:m,col:3,cols:k,rows:1},tabs:{row:v,col:1,cols:s,rows:1},field:{row:M,col:1,cols:s,rows:1},divider:I}}}function UF(t,e,n,r,i,o){let s=t.slot(),a=t.lch[s],c=t.list[s],u=(h)=>({row:r+h.row,col:i+h.col,cols:h.cols,rows:h.rows}),l=(h)=>Math.log(Math.max(1,h))/Math.log(21),d=t.partner().floor,f=t.origin();return{panel:{row:r,col:i,cols:n.plane.cols+2,rows:o},ground:e.background,ink:e.foreground,accent:e.cursor,plane:{...u(n.plane),h:a.h,l:a.l,c:a.c},hue:{...u(n.hue),h:a.h,color:c},contrast:{...u(n.contrast),at:l(t.ratio()),floor:d===void 0?void 0:l(d),color:c,lit:t.channel===Qt},tabs:{...u(n.tabs),active:tc.findIndex(([,h])=>h===t.format),count:tc.length},field:u(n.field),divider:n.divider===void 0?void 0:r+n.divider,origin:f&&{...f.lch,color:f.hex,at:l(f.ratio)}}}function WF(t,e,n,r,i,o,s,a){let u=o??1,l=s-1-u,d=u-2,f=12+2*ec(r)-Cp,h=a?GF:BF,m=h(t,e,n,f,Number.POSITIVE_INFINITY),g=m.lines.length<=l||m.lines.length>d&&l>=d,b=g?l:d,w=m.lines.length<=b?m:h(t,e,n,f,b),k=g?u+1:u-w.lines.length,v=Array.from({length:s},(S,M)=>i[M]??"");return w.lines.forEach((S,M)=>{let I=k+M;if(I>=0&&I<s)v[I]=M$(v[I],Cp,S)}),{lines:v,art:w.parts&&UF(t,n,w.parts,k,Cp,w.lines.length)}}function KF(t,e,n,r,i){let o=r.side,s=Pp(t),a=t.changedOnly?e.color?`${Fp}●\x1B[39m`:"●":" ",c=s===0?e.dim("Gate ✓"):e.bold(`Gate ✗ ${s}`),u=yt(` ${e.bold("Colors")} ${c}`,Wt("m",`${t.changedOnly?e.bold("⧩ changed"):e.dim("⧩ changed")}${a} `),o),l=i-1,d=t.misses(),f=vS(o),h=[],m,g=A.map((k,v)=>v).filter((k)=>t.visible(k));if(g.length>0){h.push(e.dim(Xt(f,"top",[[2," Base "]])));for(let k of g){if(k===t.slot())m=h.length;h.push(dn(e,HF(t,e,n,k,f-2,d),f))}}let b=ln.map((k,v)=>v).filter((k)=>t.visible(A.length+k)||t.visible(A.length+k+8));if(b.length>0){h.push(e.dim(Xt(f,g.length>0?"mid":"top",LF(o))));for(let k of b){if(t.row===A.length+k)m=h.length;h.push(dn(e,CF(t,e,n,k,o,d),f))}}if(g.length>0||b.length>0)h.push(e.dim(Xt(f,"bottom")));if(t.visible(t.slot()))h.push(...FF(t,e,n,r,o));let w=Ja(e,t,l-h.length,f);return h.push(...Array.from({length:Math.max(0,l-h.length-w.length)},()=>""),...w),{lines:[u,...h.slice(0,l)],anchor:m===void 0?void 0:m+1}}function zF(t,e,n,r){let o=`${e.fg(t.list[2])}◆${e.color?"\x1B[39m":""} ${e.bold(t.options.title)} ${e.dim(`· ${t.options.name}`)}`,s=t.dirty(),a=t.changes(),c=e.color?`${Fp}●\x1B[39m`:"●",u=s?`${c} ${e.dim(a>0?`unsaved · ${a} changed`:"unsaved")}`:"",l=s?`${Wt("R",e.dim("Reset"))} ${Wt("s",Gl(e,n,"Save"))}`:"",d=[o,u,l].filter(Boolean).join(" "),f=(g,b,w)=>Wt(g,w?Gl(e,n,b):e.dim(b)),m=[...t.options.find||t.pictures>0?[f("b",`▣ ${t.pictures>0?`${t.pictures} `:""}Picture`,t.pic&&(t.pictures>0||!!t.options.find))]:[],f("i","⌖ Inspect",t.inspect),`${f("u","↶",!1)} ${f("ctrl+r","↷",!1)}`,f("I","Import ▾",t.menu==="import"),...t.options.exports?[f("x","Export ▾",t.menu==="export")]:[]].join(" ");return yt(d,`${m} `,r)}var DF={kind:"open",slot:0};function qF(t,e,n){return t.color?`${n?"\x1B[49m":t.bg(e.background)}${t.fg(e.foreground)}`:""}function YF(t,e,n,r,i,o){let s=Wa(r),a=qF(e,n,o),c=t.slot();return Array.from({length:r.rows},(u,l)=>{let d=s[l],f=[{text:" ",sgr:a}];if(d)d.forEach((g,b)=>{let w=i&&i.pane===r.id&&i.line===l&&i.run===b,k=e.color?w?`${a}${e.bg(n.foreground)}${e.fg(n.background)}`:`${a}${Al(e,n,g.role,rp(g.role,c))}${t.where&&!np(g.role,c)?"\x1B[2m":""}`:"";f.push({text:g.text,sgr:k,target:{kind:"run",spot:{pane:r.id,line:l,run:b}}})});let h=Bl(f,0,r.width-1),m=r.width-_l(h);return m>0?[...h,{text:" ".repeat(m),sgr:a,target:DF}]:h})}function JF(t,e,n){let r=t.slotsHere();if(!r)return;let i=e.color?`${e.bg(n.background)}${e.fg(n.foreground)}`:"",o=e.color?`${i}\x1B[2m`:"",s=(d)=>({text:d,sgr:o}),a="┌ Slots here ",c="└ enter its slot · esc ",u=[[s(`${a}${"─".repeat(Xa-_(a)-1)}┐`)]],l=[["text",r.text]];if(r.ground!==r.text)l.push(["ground",r.ground]);for(let[d,f]of l){let h={kind:"open",slot:f},m=t.shown()[f],g=f<A.length?"":Ce(f).about;u.push([{text:"│ ",sgr:o,target:h},{text:d.padEnd(7),sgr:o,target:h},{text:"■",sgr:e.color?`${i}${e.fg(m)}`:"",target:h},{text:" ",sgr:i,target:h},{text:Ce(f).name.slice(0,14).padEnd(14),sgr:i,target:h},{text:g.padEnd(Xa-27),sgr:o,target:h},{text:" │",sgr:o,target:h}])}return u.push([s(`${c}${"─".repeat(Xa-_(c)-1)}┘`)]),u.map((d)=>Bl(d,0,Xa))}function VF(t,e,n){if(!t.menu)return;let r=t.menu==="export"?["Share code","Add command","Palette file"]:["Another palette","A share code"],i=24,o=e.color?`${e.bg(n.background)}${e.fg(n.foreground)}`:"",s=e.color?`${o}\x1B[2m`:"",a=t.menu==="export"?"Copy ":"Take from ",c=[[{text:`┌ ${a}${"─".repeat(Math.max(0,i-3-a.length))}┐`,sgr:s}]];return r.forEach((u,l)=>{let d=l===t.entry,f={kind:"entry",index:l};c.push([{text:"│",sgr:s},{text:` ${d?"▌":" "} ${u.padEnd(i-6)}`,sgr:d&&e.color?`${e.bg(n.selection)}${e.fg(n.foreground)}\x1B[1m`:o,target:f},{text:"│",sgr:s}])}),c.push([{text:`└${"─".repeat(i-2)}┘`,sgr:s}]),c}var ZF=["#ff5f57","#febc2e","#28c840"];function QF(t,e,n,r){let i=e.color?`${e.bg(OS(n))}${e.fg(n.foreground)}`:"",o=[{text:" ",sgr:i}];for(let u of ZF)o.push({text:"●",sgr:e.color?`${i}${e.fg(u)}`:""},{text:" ",sgr:i});o.push({text:" ",sgr:i});let s=fv(),a=(t.scene%s.length+s.length)%s.length;s.forEach((u,l)=>{let d={kind:"scene",scene:l};o.push(l===a?{text:` ${u} `,sgr:e.color?`${i}${e.bg(pt(n.background,n.foreground,0.3))}\x1B[1m`:"",target:d}:{text:` ${u} `,sgr:e.color?`${i}\x1B[2m`:"",target:d},{text:" ",sgr:i})});let c="⇧←→ ";return[...o,{text:" ".repeat(Math.max(0,r-_l(o)-_(c))),sgr:i},{text:c,sgr:e.color?`${i}\x1B[2m`:""}]}function OS(t){return pt(t.background,t.foreground,0.14)}function XF(t,e,n){let{frame:r}=n,i=pt(e.background,e.foreground,0.45),o=t.color?`${t.bg(IS(e))}${t.fg(i)}`:"",s=t.color?`${t.bg(OS(e))}${t.fg(i)}`:"",a=(u,l)=>u===r.row||u===r.row+r.rows-1||l===r.col||l===r.col+r.cols-1,c=[];for(let[u,l]of wv(n.rules))for(let[d,f]of l)c.push([u,d,[{text:f,sgr:a(u,d)?o:s}]]);return c}function IS(t){return pt(t.background,t.foreground,0.08)}function RS(t,e){return Ua(t,e,0)?.inner}function PS(t,e,n,r,i={}){let o=Ua(e,n,t.scene);if(!o)return;let s=$s(r),a=t.shown(),c=Gt(a),u=Gt(i.chrome?[...i.chrome]:t.list),l=KF(t,s,u,o,n-1),d=t.mode==="tune"?WF(t,s,u,o.side,l.lines,l.anchor,n-1,r&&i.art===!0):{lines:l.lines,art:void 0},f=d.lines,h=i.behind===!0,m=t.inspect?bl(o,t.spot):void 0,g=s.color?s.bg(IS(u)):"",b=Array.from({length:n-3},()=>[{text:" ".repeat(o.width),sgr:g}]),w=(N,L,K)=>{let B=N-2;if(B>=0&&B<b.length)b[B]=AF(b[B],L,K)},k=o.side+1;for(let[N,L,K]of XF(s,u,o))w(N,L-k,K);for(let N of o.tiles)YF(t,s,c,N,m,h).forEach((L,K)=>{w(N.row+K,N.col-k,L)});w(o.title.row,o.title.col-k,QF(t,s,u,o.title.cols));let v=m?JF(t,s,c):void 0;if(m&&v){let N=o.tiles.find((K)=>K.id===m.pane),L=Wa(N)[m.line]?.[m.run];if(L){let K=Math.max(0,Math.min(N.col-k+1+L.col,o.width-Xa)),B=N.row+m.line,X=B+1,z=X+v.length-2>n-2?B-v.length:X;v.forEach((Mt,tt)=>{w(z+tt,K,Mt)})}}let S=VF(t,s,c);if(S){let N=Math.max(0,o.width-24-(t.menu==="import"?12:2));S.forEach((L,K)=>{w(2+K,N,L)})}let M=zF(t,s,u,o.width),I=s.dim("─".repeat(o.width)),O=s.dim("│"),H=[];for(let N=0;N<n-1;N++){let L=N===0?M:N===1?I:TF(b[N-2]??[],r);H.push(`${rt(f[N]??"",o.side)}${O}${L}`)}return{lines:H,art:d.art}}var NS=80,AS=24,jp=11;function t3(t,e,n,r){let i=Ip(e,n);return un.map((o,s)=>{let a=e.mode==="tune"&&s===e.channel,c=n[o.key],u=`${c.toFixed(o.digits)}${o.wraps?"°":""}`.padStart(6),l=Ya(t,Tl(n,o,r),Xi(c,o.min,o.max,r),a,o.key==="c"&&i!==void 0?Xi(i,o.min,o.max,r):void 0),d=o.key.toUpperCase(),f={kind:"channel",channel:s};return`${st(f,a?t.bold(`▸${d}`):t.dim(` ${d}`))} ${st({kind:"bar",channel:s},l)} ${st(f,a?t.bold(u):t.dim(u))}`})}function e3(t,e){if(e.mode!=="tune"||e.slot()<A.length)return[];let n=Gt(e.list),r=ws.map((o)=>st({kind:"scope",scope:o},o!==e.scope?t.dim(o):t.color?`${t.bg(n.selection)}${t.fg(n.foreground)} ${o} \x1B[39;49m`:`[${o}]`)),i=e.scoped().length;return[`${t.dim("Scope")} ${r.join(" ")}`,t.dim(i>1?`${i} slots move by the same step, each keeping its own color`:"This slot moves alone · a widens it")]}var TS={background:(t)=>t.background,foreground:(t)=>t.foreground,hue:(t)=>t.cursor,tint:(t)=>t.background,lightness:(t)=>t.ansi[4],chroma:(t)=>t.ansi[1],brights:(t)=>t.ansi[12]};function n3(t){return`oklch ${t.l.toFixed(3)} ${t.c.toFixed(3)} ${t.h.toFixed(0)}°`}function r3(t,e){return`${t.dim("oklch")} ${t.bold(`${e.l.toFixed(3)} ${e.c.toFixed(3)} ${e.h.toFixed(0)}°`)}`}function i3(t,e,n,r=Qi){let i=e.misses(),o=Gt(e.list),s=e.slot(),a=(d)=>{let f=e.list[d],h=d===s,m=e.signature.includes(An[d])?"◆":t.color?"■":" ",g=i.has(d)?"✗":e.tone&&e.changed(d)?"●":" ",w=`${t.color?`${t.fg(f)}${m}${h?t.fg(o.foreground):"\x1B[39m"} `:`${m} `}${Nl(e.lch[d])}${g}`;if(!h)return st({kind:"slot",slot:d},` ${w}`);return st({kind:"slot",slot:d},t.color?`${t.bg(o.selection)}${t.fg(o.foreground)} ${w}\x1B[39;49m`:`›${w}`)},c=(d)=>d?t.color?`${t.fg(o.cursor)}▌\x1B[39m `:"▌ ":" ",u=[t.dim(Xt(r,"top",[[2," Base "]]))];for(let d=0;d<A.length;d++){let f=d===e.row,h=A[d].padEnd(10);u.push(dn(t,`${st({kind:"slot",slot:d},`${c(f)}${f?t.bold(h):h}`)}${a(d)}`,r))}u.push(t.dim(Xt(r,"mid",[[2," ANSI "],[12," Normal 0–7 "],[29," Bright 8–15 "]])));for(let d=A.length;d<cr;d++){let f=d===e.row,h=ln[d-A.length].padEnd(10),m=st({kind:"slot",slot:d+(e.col===1?8:0)},`${c(f)}${f?t.bold(h):h}`);u.push(dn(t,`${m}${a(d)}${a(d+8)}`,r))}u.push(t.dim(Xt(r,"bottom")));let l=Ja(t,e,n-u.length,r);return[...u,...Array.from({length:Math.max(0,n-u.length-l.length)},()=>""),...l]}function o3(t,e,n){let r=Gt(e.list),i=[` ${t.dim("Seeds")}`];Ji.forEach((o,s)=>{let a=s===e.field,c=e.seeds[o.key],u=Array.from({length:jp},(b,w)=>{let k=o.min+(o.max-o.min)*w/(jp-1);return TS[o.key](ei({...e.seeds,[o.key]:k}))}),l=Ya(t,u,Xi(c,o.min,o.max,jp),a),d=`${c.toFixed(o.digits)}${o.wraps?"°":""}`.padStart(6),f=TS[o.key](r),h=a?t.color?`${t.fg(r.cursor)}▌\x1B[39m `:"▌ ":" ",m=o.label.padEnd(17),g={kind:"field",field:s};i.push(`${st(g,`${h}${a?t.bold(m):m}`)}${st({kind:"seed",field:s},l)}${st(g,` ${d} ${t.color?`${t.fg(f)}■\x1B[39m `:""}${t.dim(f)}`)}`)}),i.push("");for(let o of bt("Seven seeds grow all twenty colors, each accent on the hue its ANSI role reads as — whatever the seeds, they pass the gate. enter moves on to tune each slot, and the seeds stay behind.",Qi-4))i.push(` ${t.dim(o)}`);return i.push(""),[...i,...Ja(t,e,n-i.length,Qi)]}function FS(t,e,n,r,i,o){let s=zt.indexOf(Ii(i)),a=zt.map((l,d)=>st({kind:"scene",scene:d},d!==s?t.dim(l.name):t.color?`${t.bg(e.selection)}${t.fg(e.foreground)} ${l.name} \x1B[39;49m`:`[${l.name}]`)).join(" "),c=[yt(a,t.dim("⇧←→"),n)],u=`${t.bg(e.background)}${t.fg(e.foreground)}`;for(let l of Ii(i).lines){let d=Wo(l,n-2);if(!d)continue;if(c.length>=r)break;let f=t.color?d.map(([h,m])=>`${Al(t,e,m,uS(o,m))}${h}\x1B[0m${u}`).join(""):d.map(([h])=>h).join("");c.push(`${u} ${rt(f,n-2)} ${t.color?"\x1B[0m":""}`)}return c}var s3=["Bk","Rd","Gr","Ye","Bl","Ma","Cy","Wh"];function HS(t,e,n,r,i,o,s){let a=(i-o)/(s-1),c=jS(e),u=Gt(n),l=(d)=>Math.min(s-1,Math.max(0,Math.round((i-r(Et(d)))/a)));return Array.from({length:s},(d,f)=>{let m=`${(f%2===0?(i-a*f).toFixed(i>=1?1:2).replace(/^0(?=\.\d\d)/,""):"").padStart(4)} ${t.dim(f%2===0?"┤":"│")}`;for(let g=0;g<8;g++){let b=[" "," "," "," "," "],w=u.ansi[g],k=u.ansi[g+8],v=l(w)===f,S=l(k)===f,M=(O)=>{if(O===1&&v)return t.color?`${t.fg(w)}●`:"●";if(O===3&&S)return t.color?`${t.fg(k)}○`:"○";return b[O]},I=[0,1,2,3,4].map(M).join("");m+=c.has(g)?t.color?`${t.bg(u.selection)}${I}\x1B[39;49m`:I:`${I}${t.color?"\x1B[39m":""}`}return m})}function jS(t){let e=t.mode==="tune"?t.scoped():[t.slot()];return new Set(e.filter((n)=>n>=A.length).map((n)=>(n-A.length)%8))}function a3(t,e){let n=jS(e);return` ${s3.map((r,i)=>n.has(i)?t.bold(` ${r} `):t.dim(` ${r} `)).join("")}`}function c3(t,e){let n=Gt(e),r=Array.from({length:40},(o,s)=>{let a=s*9+4.5,c=-1,u=999;for(let[l,d]of Object.entries(ke)){let f=ye(a,d.center);if(f<=d.width&&f<u)u=f,c=Number(l)}return c<0?" ":t.color?`${t.fg(n.ansi[c])}─`:"─"}).join(""),i=(o,s)=>{let a=Array.from({length:40},()=>" ");for(let c of Object.keys(ke).map(Number)){let u=n.ansi[c+o],l=Math.min(39,Math.round(Et(u).h/9));a[l]=t.color?`${t.fg(u)}${s}\x1B[39m`:s}return` ${a.join("")}`};return[`${t.bold("Hue")} ${t.dim("0° 90° 180° 270° 360°")}`,`${t.dim("bands")} ${r}${t.color?"\x1B[39m":""}`,i(0,"●"),i(8,"○")]}function u3(t,e,n){let r=ur(n,e.signature,e.waive),i=(a)=>Ce(A.length+a).name,o=(a)=>Et(n[A.length+a]).h.toFixed(0),s=[...Bn(r).filter(({gap:a})=>a>25).map(({normal:a,gap:c})=>`${i(a)} ${o(a)}° → bright ${o(a+8)}° · ${c.toFixed(0)}° apart · ≤ 25°`),...pr(r).map(({slot:a,over:c})=>{let u=ke[pn(a)];return`${i(a)} ${o(a)}° · ${c.toFixed(0)}° outside ${u.name} ${u.center}±${u.width}°`}),...Gn(r).map(([a,c])=>`${i(a)} and ${i(c).toLowerCase()} read as one color`)];return s.length>0?s.map((a)=>`${t.bold("✗")} ${a}`):[t.dim("✓ Every accent keeps its role and its bright")]}function CS(t,e,n,r,i){let o=e.shown(),s=Math.max(...o.slice(A.length).map((u)=>Et(u).c)),a=Math.max(0.2,Math.ceil(s/0.05)*0.05),c=[yt(t.bold("Lightness"),t.dim("● normal ○ bright"),n),...HS(t,e,o,(u)=>u.l,1,0.3,8),a3(t,e)];if(i)c.push("",t.bold("Chroma"),...HS(t,e,o,(u)=>u.c,a,0,5),"",...c3(t,o));return[...c,...u3(t,e,o)].slice(0,r)}function l3(t,e,n){let r=Gt(e.list),i=(o,s)=>st({kind:"view",view:s},e.view!==s?t.dim(` ${o} `):t.color?`${t.bg(r.selection)}${t.fg(r.foreground)}${t.bold(` ${o} `)}\x1B[39;49m`:`[${o}]`);return yt(`${i("Slot","slot")}${i("Relations","relations")}`,Wt("g",`${t.bold("g")} ${t.dim("switch")}`),n)}function d3(t,e,n,r){let i=e.slot(),o=e.list[i],s=e.lch[i],a=e.start[i],{name:c,about:u}=Ce(i),l=e.signature.includes(An[i]),d=Math.max(8,Math.min(64,n-12));if(e.view==="relations"&&e.mode!=="tune")return[l3(t,e,n),"",...CS(t,e,n,r-2,!0)];let f=i>=A.length?t.dim("Uses underlined below"):l?t.dim("◆ signature"):"",h=[yt(`${t.bold(c)} ${t.dim(u)}`,e.view==="relations"?"":f,n),""],m=t.color?`${t.fg(o)}${"█".repeat(8)}\x1B[39m `:"",g=e.typing!==void 0?`${t.bold(`${e.typing}▏`)}`:void 0,[b,w,k]=et(o);if(h.push(`${m}${g??r3(t,s)}`),h.push(`${m}${t.dim(`${o} · rgb ${b} ${w} ${k}`)}`),e.view!=="relations"){let I=t.color?`${t.fg(a)}■\x1B[39m `:"";h.push(`${m}${a!==o?t.dim(`was ${I}${n3(e.lchOf(a)).slice(6)} · ${a}`):t.dim("as it opened")}`)}h.push(""),h.push(...t3(t,e,s,d),Il(t,e,d));let v=e3(t,e);if(v.length>0)h.push(...v);if(e.view==="relations")return h.push("",...CS(t,e,n,r-h.length-1,!1)),h;h.push("");for(let I of Pl(e,i,s))bt(I.text,n-2).forEach((O,H)=>{h.push(`${H===0?Rp(t,I.ok):" "} ${I.ok===!1?O:t.dim(O)}`)});let S=Rl(e,i);if(S)h.push(t.dim(` ${S}`));let M=r-h.length-1;if(M>=3)h.push("",...FS(t,Gt(e.shown()),n,M,e.scene,i));return h}function f3(t,e,n,r){return[yt(`${t.bold("Sample")} ${t.dim("what the seeds grow")}`,"",n),"",...FS(t,Gt(e.list),n,r-2,e.scene,-1)]}var h3=[["Slots","↑↓ slot · ←→ normal or bright · home end · pgup the base colors · pgdn the ANSI ones · n N the next and last miss"],["Tune","enter or tab opens the picker over the list, under the slot · ↑↓ lightness · ←→ chroma · ⇧←→ hue by 5, , . by 1 · pgup pgdn lightness ×5 · tab ◐ contrast · home end the ends · 0-9 jump · enter keeps · esc undoes · a click outside it keeps"],["Contrast","◐ moves lightness until the ratio to the color it is read against changes · home the gate’s floor · 1-9 that ratio"],["Chroma","stops at the sRGB edge · what lightness or hue takes away comes back while you tune, where it fits again (○)"],["Scope","a while tuning: this, pair, normals, brights or accents — the slots in it move by the same step, each keeping its own color"],["Relations","g shows the lightness, chroma and hue of every ANSI color at once, and the relations the gate checks"],["Sample","⇧←→ another tab · the slot under the cursor is underlined where it is used · w dims the rest"],["Inspect","i, or a click on the sample, finds the slots a spot uses · ←→↑↓ move · enter goes to the slot · esc leaves"],["Link","l makes a bright follow its normal — tuning the normal moves it, tuning the bright alone unlinks it · = snaps it to its normal"],["Filter","m only the slots that changed · n and N walk the gate misses listed under the slots"],["Export","x copies the share code, an add command or the palette file · I takes colors from another palette or a share code"],["Type","# then #rrggbb, rgb(r g b) or oklch(l c h) — a paste works too"],["Slot","c copies · v pastes · r puts it back as it opened, R all of them · = the bright follows its normal · * marks it a signature color"],["Palette","f moves the colors the gate misses · o takes another palette’s colors"],["Gate","✗ marks every slot whose own checks miss, and each miss names its slots"],["History","u undo · ctrl+r redo"],["Pictures","p finds one on the boorus, tried on in these colors · b shows or hides it behind the editor · drop a picture on the window, or paste one, its path or its link · ctrl+v takes the clipboard’s"],["Compare","space shows the colors you started from, on the terminal too"],["Save","s saves · esc cancels, asking first when something changed"]];function m3(t,e,n){let r=[` ${t.bold("Help")}`,""];for(let[i,o]of h3.filter(([s])=>s!=="Pictures"||e.options.find))bt(o,n-16).forEach((s,a)=>{r.push(` ${t.bold((a===0?i:"").padEnd(11))} ${s}`)});return r}function p3(t,e,n,r){let i=e.choices(),o=e.options.palettes?.length??0,s=e.filter?`${t.bold(e.filter)}▏`:t.dim("type to filter"),a=[yt(` ${t.bold("Take colors from")} ${s}`,t.dim(`${i.length}/${o}`),n),""],c=r-2,u=Math.max(0,Math.min(e.pick-Math.floor(c/2),i.length-c)),l=Math.min(40,Math.max(12,...i.map((d)=>_(d.name))));if(i.slice(u,u+c).forEach((d,f)=>{let h=u+f===e.pick,m=d.colors,g=t.color?`${t.bg(m.background)} ${[...m.ansi].map((k)=>`${t.fg(k)}■`).join("")} ${t.fg(m.foreground)}Aa \x1B[0m`:"",b=h?"▌ ":" ",w=d.name.padEnd(l);a.push(st({kind:"choice",index:u+f},`${b}${h?t.bold(w):w} ${g}`))}),i.length===0)a.push(` ${t.dim(`No palettes match '${e.filter}'`)}`);return a}var g3=new Set(["enter","s","?","g","a","i"]);function LS(t,e,n,r){let i=t.fg((r??e.list)[2]),o="EDIT",s="",a=[],c="";if(e.quitting)o="EDIT (QUIT)",s=e.added>0?`Discard changes and ${e.added} ${e.added===1?"picture":"pictures"}?`:"Discard changes?",a=[["y","discard"],["n","keep editing"]];else if(e.typing!==void 0)o="EDIT (TYPE)",s=t.dim("#rrggbb, rgb(r g b) or oklch(l c h)"),a=[["enter","set"],["ctrl+u","clear"]],c="esc back";else if(e.overlay==="keys")o="HELP",c="any key closes";else if(e.overlay==="open")o="EDIT (OPEN)",a=[["↑↓","palette"],["a-z","filter"],["enter","take its colors"]],c="esc close";else if(e.menu)o=e.menu==="export"?"EDIT (EXPORT)":"EDIT (IMPORT)",a=[["↑↓","item"],["enter","choose"]],c="esc close";else if(e.compare)o="EDIT (BEFORE)",s="The colors you started from",a=[["space","back to yours"]],c="esc back";else if(e.mode==="seeds")o="EDIT (SEEDS)",a=[["↑↓","seed"],["←→","step"],["⇧←→","×5"],["enter","tune the slots"],["o","open a palette"],["p","picture"],["?","keys"]],c="esc cancel";else if(e.mode==="tune")o="EDIT (TUNE)",a=[["↑↓","L"],["←→",e.channel===Qt?"ratio":"C"],["⇧←→","H"],["tab","◐"],...e.slot()>=A.length?[["a","scope"]]:[],[e.channel===Qt?"1-9":"0-9",e.channel===Qt?"ratio":"jump"],["#","type"],["enter","keep"]],c="esc undo";else if(e.inspect)o="EDIT (INSPECT)",a=[["←→↑↓","spot"],["tab","pane"],["enter","its slot"],["i","leave"]],c="esc leave";else a=[["↑↓","slot"],["←→","normal or bright"],["enter","tune"],["i","inspect"],["l","link"],["m","changed"],["g",e.view==="slot"?"relations":"slot"],...e.misses().size>0?[["n","next miss"]]:[],["#","type"],["f","fix"],["p","picture"],["b","picture layer"],["x","export"],["u","undo"],["s","save"],["?","keys"]],c="esc cancel";if(!e.options.find)a=a.filter(([d])=>d!=="p"&&d!=="b");if(!e.options.exports||!e.roomy)a=a.filter(([d])=>d!=="x");if(!e.roomy)a=a.filter(([d])=>d!=="i"&&d!=="m");if(e.notice)s=t.color?`\x1B[33m${e.notice}\x1B[39m`:e.notice,a=[];let u=t.color?`\x1B[7;1m${i} ${o} \x1B[0m `:`[${o}] `,l=c?Wt(c.split(" ")[0],`${t.bold(c.split(" ")[0])} ${t.dim(c.split(" ").slice(1).join(" "))}`):"";for(;;){let d=[s,...a.map(([m,g])=>Wt(m,`${t.bold(m)} ${t.dim(g)}`))].filter(Boolean),f=`${u}${d.join(" ")}`,h=-1;if(a.forEach(([m],g)=>{if(g>0&&!g3.has(m))h=g}),_(f)+_(c)+3<=n||h<0)return c?yt(f,l,n):rt(f,n);a=a.filter((m,g)=>g!==h)}}function b3(t,e,n,r,i={}){let o=$s(r);if(e<NS||n<AS){let g=[o.bold("ttheme palette editor"),`Needs ${NS}×${AS} — now ${e}×${n}`,o.dim("esc cancels")];return{lines:Array.from({length:n},(b,w)=>rt(g[w]??"",e)),art:void 0}}if(t.viewport(e,n),!t.overlay&&t.mode!=="seeds"){let g=PS(t,e,n,r,i);if(g)return{lines:[...g.lines,LS(o,t,e,i.chrome)],art:g.art}}let s=t.failing().length,a=s===0?"✓ Passes the gate":`✗ ${s} ${s===1?"miss":"misses"} in the gate`,c=t.pictures>0?o.dim(`▣ ${t.pictures} ${t.pictures===1?"picture":"pictures"} `):"",u=`${t.dirty()?`${o.color?"\x1B[33m●\x1B[39m":"●"} unsaved `:""}${c}${o.dim(a)}`,d=`${o.fg(t.list[2])}◆${o.color?"\x1B[39m":""} ${o.bold(t.options.title)} ${o.dim(`· ${t.options.name}`)}`,f=n-4,h;if(t.overlay==="keys")h=m3(o,t,e);else if(t.overlay==="open")h=p3(o,t,e,f);else{let g=e-Qi-2,b=t.mode==="seeds"?o3(o,t,f):i3(o,t,f),w=t.mode==="seeds"?f3(o,t,g,f):d3(o,t,g,f);h=Array.from({length:f},(k,v)=>`${rt(b[v]??"",Qi)}${o.dim("│")} ${rt(w[v]??"",g)}`)}let m=[yt(d,u,e),""];for(let g=0;g<f;g++)m.push(rt(h[g]??"",e));return m.push("",LS(o,t,e,i.chrome)),{lines:m,art:void 0}}var w3=new Set(["tab","a","#","l","enter","esc"]),$3=new Set(["picker","plane","bar","channel","format","scope","open","slot"]);function k3(t){if(!t)return!0;return t.kind==="key"?!w3.has(t.key):!$3.has(t.kind)}function y3(t,e,n){if(n.action==="wheel"){if(!n.sideways)t.scroll(n.wheel);return}if((n.action==="press"||n.action==="drag")&&n.button!=="left")return;if(n.action==="press"&&t.overlay==="keys"){t.press("esc");return}let r=e?.target;if(n.action==="press"&&t.mode==="tune"&&t.roomy&&!t.overlay&&k3(r))t.dismiss();if(!e||!r)return;let i=e.width>1?(e.exact.x-0.5)/(e.width-1):0;if(n.action==="release"){if(!e.inside)return;if(r.kind==="key")t.press(r.key);else if(r.kind==="entry")t.choose(r.index);else if(n.count===2&&r.kind==="slot"&&t.mode==="list")t.press("enter");else if(n.count===2&&r.kind==="choice"&&t.overlay==="open")t.press("enter");return}if(r.kind==="plane"){let o=SS(r.row+e.exact.y,r.rows,e.exact.x,e.width,t.lch[t.slot()].h);t.plane(o.lightness,o.chroma)}else if(r.kind==="bar")t.slide(r.channel,i);else if(r.kind==="seed")t.sow(r.field,i);else if(n.action!=="press")return;else if(r.kind==="slot")t.select(r.slot);else if(r.kind==="open")t.openSlot(r.slot);else if(r.kind==="run")t.point(r.spot);else if(r.kind==="entry")t.entry=r.index;else if(r.kind==="format")t.format=r.format;else if(r.kind==="channel")t.grip(r.channel);else if(r.kind==="scope")t.scopeTo(r.scope);else if(r.kind==="choice"){if(t.overlay==="open")t.pick=r.index}else if(t.typing===void 0&&!t.overlay&&!t.quitting){if(r.kind==="field"&&t.mode==="seeds")t.field=r.field;else if(r.kind==="view"&&t.mode!=="seeds")t.view=r.view;else if(r.kind==="scene")t.scene=r.scene}}var v3=[ol,Rn,Zr,ir];async function _S(t,e){let n=new yp(t),r=e.backdrop,i=e.layer,o=(a)=>n.typing===void 0&&vl(a),s=e.hosted?{modes:[ir,...Qr()],assume:[Rn,Zr],burst:o}:{modes:[...v3,...Qr()],burst:o};return Xr(s,async(a)=>{let c=!1,u=!1,l=new Map,d=new Lm,f=await a.ask(`${gh(rn,"")}${Qr().length>0?O1:""}\x1B[c`,(S)=>{if(S.kind==="color"){l.set(S.code,S.value);return}return d.see(S)},1000);if(f?.cell)a.pixels(f.cell);let h=ok(l),m=h.map((S,M)=>S??n.start[M]),[g,b]=m;if(!h[3])m[3]=pt(g,b,0.2);let w=new Bi({write:(S)=>a.write(S),view:()=>{if(c)return;let{lines:S,art:M}=b3(n,a.cols,a.rows,e.color,{behind:n.pic&&r?.laid===!0,art:i?.ready===!0,chrome:m});return{lines:S,after:()=>`${(n.pic?r?.draw(n.shown(),n.signature,n.waive,a.cols,a.rows,RS(a.cols,a.rows)):r?.clear())??""}${i?.draw(M)??""}`}}}),k=(S=!1)=>{if(S)w.soon();else w.request()},v=async(S)=>{let M=t.find;if(!M)return;c=!0,a.write(`${r?.clear()??""}${i?.clear()??""}`);try{n.found(await M(n.edited(),S))}catch(I){n.notice=I instanceof Error?I.message:String(I)}if(u)return;c=!1,r?.load(),w.reset(Ai),k()};if(a.write(Ai),a.onResize(()=>{r?.resized(),a.write(i?.clear()??""),w.reset(Ai),w.request()}),r)r.load(),r.ready=()=>w.request();if(r||i){let S=new Ra;a.ask(rl,(M)=>S.see(M),1000).then((M)=>{if(M)r?.measured(M),i?.measured(M);w.request()})}k();try{let{edited:S}=await a.loop((M)=>{if(c)return;if(M.kind==="paste")n.paste(M.text);else if(M.kind==="key")n.press(M.key);else if(M.kind==="mouse")y3(n,w.point(M),M);if(n.copied!==void 0)a.write(`\x1B]52;c;${Buffer.from(n.copied).toString("base64")}\x07`),n.copied=void 0;if(n.result)return{edited:n.result==="saved"?n.edited():void 0};let I=n.wants;if(I)n.wants=void 0,v(I.start);return},()=>{if(!c)k(!0)});return S}finally{u=!0,w.stop(),a.write(`${r?.close()??""}${i?.clear()??""}`)}})}import{spawn as L3}from"node:child_process";import{createHash as tE}from"node:crypto";import{existsSync as rc,mkdirSync as F3,mkdtempSync as j3,readFileSync as _3,rmSync as Ul}from"node:fs";import{homedir as B3,tmpdir as G3}from"node:os";import{basename as U3,dirname as W3,join as Hn}from"node:path";import{pathToFileURL as US}from"node:url";import{existsSync as S3,readFileSync as E3,statSync as M3}from"node:fs";import{join as BS}from"node:path";function x3(t,e){try{return JSON.parse(E3(BS(Ve(t),e),"utf8"))}catch{return{}}}function O3(t,e,n){F(BS(Ve(t),e),`${JSON.stringify(n)}
710
+ `)}class _p{caches=new Map;unsaved=new Set;owners=new Map;crediting=new Map;inflight=new Map;home;catalog;entry;signal;credited;constructor(t){this.home=t.home,this.catalog=t.catalog,this.entry=t.entry,this.signal=t.signal,this.credited=t.credited}matesOf(t,e){return this.owners.get(t.key)?.get(e)??[]}async transparent(t,e){let n=this.keep(t,"probes.json"),r=n[e.id];if(r!==void 0)return r;try{let i=await Us(t,e,this.signal),o=bi(t,e),s=(i===void 0?await Lw(o.site,o.url,this.signal):i)?.alpha===!0;return n[e.id]=s,this.unsaved.add(`${t.key}/probes.json`),s}catch{return!1}}save(){for(let t of this.unsaved){let[e,n]=t.split("/"),r=J.find((i)=>i.key===e);if(r)O3(r,n,this.keep(r,n))}this.unsaved.clear()}owned(t,e,n){this.keep(t,"owners.json")[e]=n,this.unsaved.add(`${t.key}/owners.json`)}credit(t,e){let{site:n,post:r}=t;if(!Ic(n,r))return Promise.resolve();let i=Ee(n,r.id),o=this.crediting.get(i);if(!o)o=this.credits(t,e).finally(()=>this.crediting.delete(i)),this.crediting.set(i,o);return o}async mateOwners(t){let e=this.owners.get(t.key);if(e)return e;let n=E0(this.home),r=this.keep(t,"owners.json"),i=this.catalog.palettes.flatMap((c)=>{let u=n.get(c.name);return c.group===this.entry.group&&c.name!==this.entry.name&&u?.site===t.key?[{name:c.name,id:u.id}]:[]}),o=await Promise.all(i.map(async(c)=>{let u=r[c.id];if(u!==void 0)return{...c,owner:u};try{return{...c,owner:(await So(t,c.id,this.signal))?.owner??""}}catch{return}})),s=new Map;for(let c of o)if(c)r[c.id]=c.owner,s.set(c.name,c.owner);this.unsaved.add(`${t.key}/owners.json`);let a=Pw(s);return this.owners.set(t.key,a),a}async cached(t,e,n,r){if(S3(e))return M3(e).size;let i=this.inflight.get(e);if(i)return i;let o=(async()=>{let s=await Nc(t,n,this.signal,r);return F(e,s),s.length})();this.inflight.set(e,o);try{return await o}finally{this.inflight.delete(e)}}keep(t,e){let n=`${t.key}/${e}`,r=this.caches.get(n);if(!r)r=x3(t,e),this.caches.set(n,r);return r}async credits({site:t,post:e},n){let r=this.keep(t,"credits.json"),i=r[e.id];if(!i){try{i=await Oc(t,e.id,n)}catch{return}if(!i?.owner)return;r[e.id]=i,this.unsaved.add(`${t.key}/credits.json`)}Gs(e,i),this.credited()}}import{rmSync as I3}from"node:fs";import{join as R3}from"node:path";var vs=2147483645,nc=2147483646,GS=-1073741827,P3=-1073741828,N3=16,A3=0.4,T3=3221225472,H3=256;function C3(t){let e=/^(\d+) (\d+)$/.exec(t??"");return e&&(Number(e[1])>0||Number(e[2])>0)?{x:Number(e[1]),y:Number(e[2])}:void 0}var Bp=C3(process.env.TTHEME_BG_MARGIN);class Gp{screen;gliding;sent=new Map;placed=new Map;covered="";viewed="";bands=$u(process.env);files=ku(process.env);moves=uk(process.env);layers=zo(process.env);wipes=lk(process.env);views=Pi(process.env);bandFiles=new Map;nextBand=T3;view;grid;background;renders;scratch;signal;write;constructor(t){this.view=t.view,this.grid=t.grid,this.background=t.background,this.renders=t.renders,this.scratch=t.scratch,this.signal=t.signal,this.write=t.write,this.screen=new Bi({write:(e)=>this.write(e),view:()=>this.frame(),beat:()=>{this.view.beat++}})}draw(){if(!this.signal.aborted)this.screen.request()}soon(){if(!this.signal.aborted)this.screen.soon()}flush(){if(!this.signal.aborted)this.screen.now()}point(t){return this.screen.point(t)}drop(){this.screen.drop()}frame(){if(this.signal.aborted)return;let{cols:t,rows:e,cell:n}=this.grid(),r=tp(this.view,t,e);return this.view.loaderFrom=r.loader?this.view.loaderFrom??this.view.beat:void 0,{lines:r.lines,zones:r.zones,after:(i)=>this.images(r.images,i,n),...this.view.mode==="grid"&&this.view.editing!==void 0?{cursor:this.caret()}:{},ticking:r.tick}}images(t,e,n){let r="",i=new Set,o;for(let s of t){if(this.views&&s.id>=Vm){o=s;continue}let a=this.bands?this.banded(s):s;if(!a)continue;if(this.wipes&&[...e].some((u)=>u>=a.row&&u<a.row+a.rows))this.placed.delete(a.id);if(i.add(a.id),this.sent.get(a.id)!==a.path){let u=hl(a,this.files);if(u===void 0)continue;r+=u,this.sent.set(a.id,a.path),this.placed.delete(a.id)}let c=`${a.row};${a.col};${a.cols};${a.rows};${a.crop};${a.z}`;if(this.placed.get(a.id)!==c){if(!this.moves&&this.placed.has(a.id))r+=Qm(a.id);r+=nv(a,n),this.placed.set(a.id,c)}}for(let s of this.sent.keys())if(!i.has(s))r+=_a(s),this.sent.delete(s),this.placed.delete(s);return r+(this.views?this.backdrop(o):this.cover())}glide(){if(this.bands)this.prebake();if(this.gliding)return;let{cols:t,rows:e}=this.grid(),n=or(t,e).height,r=()=>{let i=this.view,o=i.top*kt.height,s=o-i.scroll;if(s===0||i.mode!=="grid"){i.scroll=o;let a=this.gliding!==void 0;if(this.gliding=void 0,a)this.draw();return}if(Math.abs(s)>2*n)i.scroll=o-Math.sign(s)*n,s=o-i.scroll;i.scroll+=Math.sign(s)*Math.max(1,Math.round(Math.abs(s)*A3)),this.draw(),this.gliding=setTimeout(r,N3)};r()}snap(){clearTimeout(this.gliding),this.gliding=void 0,this.view.scroll=this.view.top*kt.height}resized(){this.screen.reset()}stop(){this.screen.stop(),clearTimeout(this.gliding)}prebake(){let t=this.view,{cols:e,rows:n}=this.grid();for(let r of tp({...t,scroll:t.top*kt.height},e,n).images)if(r.crop!==void 0)this.band(r.path,r.crop,r.rows)}cover(){let{cols:t,rows:e}=this.grid(),n=`${t};${e}`;if(!this.layers||this.covered===n)return"";let r="";if(!this.covered){let i=Buffer.from(et(this.background)).toString("base64");if(r+=`\x1B_Ga=t,f=24,s=1,v=1,i=${vs},q=2;${i}\x1B\\`,Bp)r+=`\x1B_Ga=t,f=32,s=1,v=1,i=${nc},q=2;AAAAAA==\x1B\\\x1B[H\x1B_Ga=p,i=${nc},p=${nc},c=1,r=1,C=1,z=${P3},q=2\x1B\\`}else if(!this.moves)r+=Qm(vs);if(this.covered=n,Bp){let{x:i,y:o}=Bp;return`${r}\x1B_Ga=p,i=${vs},p=${vs},P=${nc},Q=${nc},H=${-i},V=${-o},c=${t+2*i},r=${e+2*o},C=1,z=${GS},q=2\x1B\\`}return`${r}\x1B[H\x1B_Ga=p,i=${vs},p=${vs},c=${t},r=${e},C=1,z=${GS},q=2\x1B\\`}backdrop(t){let{cols:e,rows:n,cell:r}=this.grid(),i=e*r.w,o=n*r.h,s=t?`${this.background}|${t.path}|1|${i}|${o}|${i}|${o}|0|0|1`:`${this.background}||1|${i}|${o}|0|0|0|0|5`;if(s===this.viewed)return"";return this.viewed=s,Ni(s)}caret(){return`\x1B[1;${Math.min(this.grid().cols,_(`⌕ ${this.view.editing??""}`)+1)}H`}banded(t){if(t.crop===void 0)return t;let e=this.band(t.path,t.crop,t.rows,!this.gliding);return e?.ready?{...t,id:e.id,path:e.path,crop:void 0}:void 0}band(t,e,n,r=!0){let i=`${t}|${e}|${n}`,o=this.bandFiles.get(i);if(o||!r)return o;let{cell:s}=this.grid(),a=this.nextBand++,c={id:a,path:R3(this.scratch,`band-${a}.png`),ready:!1};return this.bandFiles.set(i,c),this.renders.run({job:"band",from:t,to:c.path,y:e*s.h,height:n*s.h}).then(()=>{c.ready=!0,this.draw()}).catch(()=>{}),this.trimBands(),c}trimBands(){for(let[t,e]of this.bandFiles){if(this.bandFiles.size<=H3)return;if(e.ready&&!this.sent.has(e.id))this.bandFiles.delete(t),I3(e.path,{force:!0})}}}var no=[{name:"TTHEME_FIND_RATING",label:"Rating",about:"The ratings to list, each site read in its own words — space ticks one, and one stays ticked",choices:ko,multi:{read:gi}},{name:"TTHEME_FIND_BLOCK",label:"Block",about:"Posts tagged with nudity or underwear are left out — space unticks one",choices:pi,multi:{read:vo,none:"none"}},{name:"TTHEME_FIND_POSTS",label:"Posts",about:"Every post of the character, or only the transparent cutouts",choices:["all","cutouts"]},{name:"TTHEME_FIND_SOLO",label:"Solo",about:"When on, only the posts known to show the character alone — checked as posts arrive, so the counts below leave it out",choices:["on","off"]},{name:"TTHEME_FIND_ORDER",label:"Order",about:"How posts are ranked: fit, by how well each makes a backdrop; newest; or score",choices:["fit","newest","score"]},{name:"TTHEME_FIND_SETS",label:"Sets",about:"One picture posted over and over, or held by another site too: fold it into one tile, or show each",choices:["fold","show"]},...rs()?[{name:"TTHEME_FIND_REMOVE_BG",label:"Remove bg",about:"Cut the character out of an opaque picture you try on, with macOS Vision",choices:["on","off"]}]:[],{name:"TTHEME_FIND_MIN_SCORE",label:"Min score",about:"Posts scored at least this — danbooru, konachan and yande.re; zerochan keeps no score. ←→ steps, or type any number",choices:bw,entry:"number",advanced:!0},{name:"TTHEME_FIND_MIN_SIZE",label:"Min size",about:"The shorter side of a picture, in px — every site filters it. ←→ steps, or type any number",choices:ww,entry:"number",advanced:!0},{name:"TTHEME_FIND_SITES",label:"Sites",about:"The sites the all tab mixes — each keeps its own tab. Space ticks one, and one stays ticked",choices:J.map((t)=>t.name),multi:{read:js},advanced:!0},{name:"TTHEME_FIND_HIDE",label:"Hide",about:"Comics, monochrome, sketches or chibi, told by tag in every site's spelling — checked as posts arrive",choices:Dd,multi:{read:yc,none:"none"},advanced:!0},{name:"TTHEME_FIND_HIDE_TAGS",label:"Hide tags",about:"Posts with any of these tags are left out, spaced like cosplay multiple_girls — checked as posts arrive",choices:[],entry:"text",advanced:!0},{name:"TTHEME_FIND_PNG",label:"PNG only",about:"PNG originals only — danbooru counts it, the others are told by the file; zerochan only where danbooru holds it",choices:["off","on"],advanced:!0}];function WS(t,e){if(t.multi)return t.multi.read(e).join(" ")||t.multi.none;if(t.entry==="number")return/^\d+$/.test(e??"")&&Number(e)>0?String(Number(e)):"off";if(t.entry==="text")return _s(e).join(" ");return t.choices.find((n)=>n===e)??t.choices[0]}var K3=["fit","newest","score"];function Up(t){return K3.find((e)=>e===t)??"fit"}var z3={left:-1,right:1,"shift-left":-10,"shift-right":10};function KS(t){if(process.env.SSH_CONNECTION||!/^(?:https?|file):/i.test(t))return;try{let e=L3(process.platform==="darwin"?"open":"xdg-open",[t],{stdio:"ignore",detached:!0});e.on("error",()=>{}),e.unref()}catch{}}function D3(t,e,n){if(e<0){if(t!=="fill")return Math.max(Kl,t+e);if(!n)return t;return Math.max(Kl,Math.max(100,n)+e+1)}return t==="fill"||t+e>n?"fill":t+e}function eE(t,e){return t.size===e.size&&t.at===e.at&&t.opacity===e.opacity}function q3(t,e){if(eE(t,e))return;return{...t.size!=="fill"?{size:t.size}:{},...t.at!==e.at?{position:Ut[t.at-1]}:{},...t.opacity!==e.opacity?{opacity:t.opacity}:{}}}function zS(t,e){let n=V(t);return fe(t,e).flatMap((r,i)=>{let[,o,s]=/^([a-z.]+)_(\d+)$/.exec(r.key)??[],a=[...J,sr].find((c)=>c.key===o);if(!a||!s)return[];return[{key:r.key,id:Number(s),ansi:a.ansi,...a===sr?{}:{page:a.pageUrl(Number(s))},up:i===0,from:Hn(n,r.original??r.fill)}]})}function Y3(t){return t.length>=2&&!/^\d+$/.test(t)&&!t.includes("://")&&!/^[\w.]+:\d+$/.test(t)}var DS=12,J3=4,V3=150,Z3=300,qS=12,Q3=2,X3=150,t8="\x1B[?5522$p\x1B]72;t=q\x1B\\\x1B[c",e8=4000,n8=8000,YS=/\.(png|jpe?g|gif|webp|heic|tiff?|bmp)$/i,r8=process.platform==="win32"?"alt+v":"ctrl+v",JS=process.platform==="darwin"?"ctrl+shift+cmd+4 copies a screenshot":"copy a picture first",i8=1280,o8=16,s8=Ut.indexOf("top-right")+1,Kl=20,VS=2,ZS=3,a8=/[\p{Script=Hangul}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]/u,c8=8,u8=9;function Wl(t,e){return{key:t,groups:[],sources:[],queue:[],rounds:0,roundOf:new Map,last:new Map,kin:new Map,kindred:new Map,shapes:[],seen:new Set,same:new Map,checked:0,total:0,focus:0,top:0,searching:e,stage:"fetch",arrived:new Set}}function ic(t){if(!(t instanceof Error))return String(t);if(t instanceof AggregateError&&t.errors[0])return ic(t.errors[0]);if(t.cause)return ic(t.cause);let e=t.code;if(typeof e==="string")return e;let n=(t.message||t.name).split(".")[0]??"";return n.length>56?`${n.slice(0,55)}…`:n}function Wp(t,e){return`${t}: ${ic(e)}`}function QS(t){return t.width*t.height}function XS(t,e){return`${t}-${tE("sha1").update(e).digest("hex").slice(0,8)}`}class Kp{view;tone;session=new AbortController;cell={w:0,h:0};cols=process.stdout.columns||80;rows=process.stdout.rows||24;gen=0;pumping=0;boards=new Map;board;posts=new Map;thumbPath=new Map;looking=new Map;looked=new Map;matched=new Map;aheading=!1;pages=new Map;tab=0;values=new Map(no.map((t)=>[t.name,WS(t,process.env[t.name])]));direction=1;prefetching=0;related=new Map;pool=[];relating;thumbQueue=[];heldFiles=new Map;heldAsked=new Set;thumbing=0;clarity=new Map;tunedFiles=[];presenting=!1;again=!1;renders=new Da;showing;thumbless=new Set;current;fetch;settle;suggestTimer;suggesting;countTimer;counting;terminal;grabber=new lp((t)=>this.write(t),(t)=>void this.got(t));noticeTimer;peekTimer;peeked;attaching;done;scratch=j3(Hn(G3(),"ttheme-find-"));home;catalog;entry;tagged;blurring;start;paint;kept;constructor(t,e,n,r,i){this.start=i,this.home=t,this.catalog=e,this.entry=n,this.tagged=new Set(e.palettes.flatMap((s)=>s.booru?[s.booru]:[])),this.tone=vn(n,n.signatureSlots),this.blurring=Ur(t);let o={size:"fill",at:s8,opacity:this.tone.opacity};this.view={palette:n.name,tag:r,site:this.tabName,siteAnsi:this.tabAnsi,nextSite:this.nextTabName,preset:this.setting("TTHEME_FIND_POSTS")==="all"?"all":"cutouts",order:Up(this.setting("TTHEME_FIND_ORDER")),solo:this.setting("TTHEME_FIND_SOLO")==="on",rating:gi(this.setting("TTHEME_FIND_RATING")),block:vo(this.setting("TTHEME_FIND_BLOCK")),sets:this.setting("TTHEME_FIND_SETS")==="show"?"show":"fold",narrow:this.narrowed(),enabled:js(this.setting("TTHEME_FIND_SITES")),hide:yc(this.setting("TTHEME_FIND_HIDE")),hideTags:_s(this.setting("TTHEME_FIND_HIDE_TAGS")),advanced:!1,settings:no.map((s)=>({label:s.label,choices:[...s.choices],value:this.setting(s.name),default:WS(s,da(s.name)),multi:s.multi&&{none:s.multi.none},about:s.about,entry:s.entry,advanced:s.advanced,cursor:0})),colors:{cursor:n.cursor,selection:n.selection,background:n.background,foreground:n.foreground,ansi:n.ansi},tiles:[],installed:[],held:zS(t,n.name),checked:0,total:0,searching:r!=="",stage:"fetch",sites:[],focus:0,top:0,scroll:0,beat:0,mode:"grid",help:!1,scene:Math.max(0,zt.findIndex((s)=>s.name.toLowerCase()===process.env.TTHEME_SCENE)),details:!1,tune:{...o},untuned:o,coloring:Su(t),editing:r===""?"":void 0,chips:[]},this.paint=new Gp({view:this.view,grid:()=>({cols:this.cols,rows:this.rows,cell:this.cell}),background:n.background,renders:this.renders,scratch:this.scratch,signal:this.signal,write:(s)=>this.write(s)}),this.kept=new _p({home:t,catalog:e,entry:n,signal:this.signal,credited:()=>{this.show(),this.inform(),this.paint.draw()}}),this.pool=this.selected(this.view),this.syncChips(),this.board=Wl(this.boardKey,r!==""),this.boards.set(this.board.key,this.board)}get signal(){return this.session.signal}get site(){return this.tab===0?void 0:J[this.tab-1]}get sites(){return this.site?[this.site]:J.filter((t)=>this.view.enabled.includes(t.name))}get tabName(){return this.site?.name??"all"}get tabAnsi(){return this.site?.ansi??J3}get nextTabName(){let t=(this.tab+1)%(J.length+1);return t===0?"all":J[t-1].name}frame(){return{w:this.cols*(this.cell.w||10),h:this.rows*(this.cell.h||20)}}setting(t){return this.values.get(t)}narrowed(){return Yd(this.setting("TTHEME_FIND_MIN_SCORE"),this.setting("TTHEME_FIND_MIN_SIZE"),this.setting("TTHEME_FIND_PNG"))}get boardKey(){return`${this.site?.key??"all"}|${this.view.preset}|${this.view.order}`}origPath(t,e,n){return Hn(Ve(t),"orig",`${e}.${n}`)}previewPath(t){let{url:e}=Sc(t.site,t.post);return Hn(Ve(t.site),"thumb",`${XS(t.post.id,e)}.${Er(e)}`)}tileOf(t,e){let{site:n,post:r}=t,i=Ee(n,r.id),o=kn(r)??r;return{id:r.id,key:i,site:n.name,siteAnsi:n.ansi,width:o.width,height:o.height,reduced:o!==r,page:n===sr?"":n.pageUrl(r.id),artist:n===sr?xv(r.source):r.named.artist[0]??"",score:r.score,variants:e,mates:this.kept.matesOf(n,r.owner),thumb:this.thumbPath.get(i),missing:this.thumbless.has(i)}}show(){let t=this.view,e=this.board;if(t.tiles=e.groups.flatMap((n)=>n.open?n.posts.map((r)=>this.tileOf(r,0)):[this.tileOf(n.posts[0],n.posts.length)]),t.checked=e.checked,t.total=e.total,t.searching=e.searching,this.stageOf(e),t.note=e.note,t.focus=Math.max(0,Math.min(e.focus,t.tiles.length-1)),t.top=e.top,this.showing!==e)this.showing=e,this.paint.snap()}stageOf(t){let e=this.view;e.stage=t.stage,e.ranking=t.ranking,e.sites=this.sites.map((n)=>({name:n.name,arrived:t.arrived.has(n.name)}))}syncSite(){let t=this.view;t.site=this.tabName,t.siteAnsi=this.tabAnsi,t.nextSite=this.nextTabName}run(){let t=(e)=>this.view.editing===void 0&&vl(e);return Xr({modes:[ir,...Qr()],assume:[Rn,Zr],burst:t},async(e)=>{this.terminal=e,e.onResize(this.onResize),e.listen((i)=>{for(let o of i)this.inbound(o);this.paint.soon()}),e.write(Ai);let n=new Promise((i)=>{this.done=i}),r=setInterval(this.onClock,250);setTimeout(zc,0);try{let i=new Ra,o=await e.ask(rl,(s)=>i.see(s),1000);if(o){if(this.cell=o,this.holdThumbs(),this.view.tag)this.search(),this.relate(this.view.tag)}else this.view.searching=!1,this.view.error="This terminal does not report its cell size — find needs kitty graphics";if(!process.env.TMUX)await e.ask(t8,(s)=>s.kind==="attributes"?!0:void 0,500,!1);if(this.grabber.start(),e.hold(C1),this.start&&"paste"in this.start)this.pasted(this.start.paste);else if(this.start)this.fromClipboard();else this.peek();return this.paint.draw(),await e.until(n)}finally{this.session.abort(),this.grabber.stop(),this.attaching?.abort(),clearTimeout(this.noticeTimer),clearTimeout(this.peekTimer),this.fetch?.abort(),clearTimeout(this.settle),this.quietSuggest(),this.quietCount(),clearInterval(r),this.paint.stop(),e.write(`\x1B_Ga=d,d=A,q=2\x1B\\${Ai}`),this.kept.save(),this.renders.close(),Ul(this.scratch,{recursive:!0,force:!0}),Nw()}})}write(t){this.terminal?.write(t)}get saved(){return this.view.saved?.text}get installs(){return this.view.installed.length}finish(t){this.done?.(t===2&&this.saved?0:t)}inbound(t){if(t.kind==="key")this.key(t.key);else if(t.kind==="mouse")this.pointer(t);else if(t.kind==="paste")this.pasted(t.text);else if(t.kind==="mode"){if(t.mode===5522)this.grabber.clipboard=t.value!==0&&t.value!==4}else if(t.kind==="osc")if(t.code==="72"&&t.meta.t==="q")this.grabber.drops=!0;else this.grabber.take(t)}pasted(t){let e=this.view;if(e.editing!==void 0&&t.trim()!==""&&!this.picture(t)){e.editing+=t.replace(/[\r\n]+/g," "),this.suggest(),this.paint.draw();return}if(e.installing!==void 0||e.panel!==void 0||e.help)return;if(t.trim()===""){this.fromClipboard();return}this.attach(t)}picture(t){let e=t.trim();if(/^https?:\/\/\S+$/i.test(e))return!vc(e,this.site??J[0]);return gs(e).length>0}async got(t){if(t.kind==="error"){this.notice(t.message);return}if(t.kind==="text"){if(t.text.trim()===""){this.notice(`No picture on the clipboard — ${JS}`);return}this.pasted(t.text);return}await this.bring(()=>kl(t.bytes,t.source))}notice(t,e=e8){let n=this.view;n.error=t,clearTimeout(this.noticeTimer),this.noticeTimer=setTimeout(()=>{if(n.error===t)n.error=void 0,this.paint.draw()},e),this.paint.draw()}async peek(){let t=this.view,e;try{e=await Nv()}catch{return}if(!e||e.stamp===this.peeked)return;if(this.peeked=e.stamp,!e.picture||t.installing!==void 0)return;t.hint=`Picture on the clipboard · ${r8} uses it`,clearTimeout(this.peekTimer),this.peekTimer=setTimeout(()=>{t.hint=void 0,this.paint.draw()},n8),this.paint.draw()}async fromClipboard(){let t=this.view;if(up()){if(this.grabber.clipboard){this.grabber.ask();return}this.notice("Over SSH the clipboard is not here — drop the file");return}let e;try{e=await Pv(Hn(this.scratch,`clipboard-${Date.now()}.png`))}catch(r){this.notice(`Could not read the clipboard: ${ic(r)}`);return}if(clearTimeout(this.peekTimer),t.hint=void 0,"image"in e){await this.bring(async(r)=>({...await cp(e.image,r),source:"clipboard"}));return}let n=e.text.trim();if(!n){this.notice(`No picture on the clipboard — ${JS}`);return}if(this.picture(n)){await this.attach(n);return}if(t.editing===void 0)t.editing="";this.pasted(n)}async attach(t){let e=t.trim();if(/^https?:\/\//i.test(e)){let i=vc(e,this.site??J[0]);if(i){await this.jump(i.site,i.id);return}}let[n,...r]=gs(e).sort((i,o)=>Number(!YS.test(i))-Number(!YS.test(o)));if(!n){this.notice("Nothing to use in that — drop a picture, or paste one or its link");return}await this.bring((i)=>cp(n,i),r.length)}async bring(t,e=0){let n=this.view;this.attaching?.abort();let r=new AbortController;this.attaching=r,n.error=void 0,n.saved=void 0,n.note="Reading the picture…",this.paint.draw();let i;try{i=await t(AbortSignal.any([r.signal,this.signal]))}catch(f){if(!r.signal.aborted)n.note=void 0,this.notice(ic(f),8000);return}if(r.signal.aborted)return;n.note=e>0?`The first picture of ${e+1} — drop one at a time to try the others`:void 0,this.quietSuggest(),n.editing=void 0,n.suggest=void 0,n.pick=void 0;let o=Iv(i.bytes);Ov(o,i.source);let s=this.origPath(sr,o,i.ext);F(s,i.bytes);let a=US(s).href,c={id:o,file:a,width:i.width,height:i.height,ext:i.ext,preview:a,owner:"",score:0,rating:"s",md5:tE("md5").update(i.bytes).digest("hex"),source:i.source,tags:[],named:{artist:[],character:[],copyright:[]},solo:void 0,family:0,smaller:[]},u={site:sr,post:c},l=this.previewPath(u);F(l,i.bytes),++this.gen,this.current=void 0,n.shown=void 0;let d=Wl(`local|post:${o}`,!1);this.board=d,this.boards.set(d.key,d),this.single(d,u)}single(t,e){t.searching=!1,this.posts.set(Ee(e.site,e.post.id),e),t.groups=[{posts:[e],open:!1}],t.checked=1,t.total=1,this.thumbQueue.push(e),this.thumbs(),this.view.mode="try",this.show(),this.select(),this.paint.draw()}onClock=()=>{let t=this.sites.reduce((r,i)=>zn(i)>zn(r)?i:r),e=Math.ceil((zn(t)-Date.now())/1000),n=e>0?e:void 0;if(n!==this.view.waiting)this.view.waiting=n,this.view.slow=t.name,this.paint.draw()};onResize=()=>{if(this.cols=process.stdout.columns||this.cols,this.rows=process.stdout.rows||this.rows,this.paint.resized(),this.holdThumbs(),this.scroll(),this.paint.snap(),this.view.mode==="try"&&this.current)this.reveal();this.pump(),this.paint.draw()};key(t){let e=this.view;if(t==="ctrl-c"){this.finish(2);return}if(e.installing!==void 0)return;if(t==="focus-in"){this.peek();return}if(t==="focus-out")return;if((t==="ctrl-v"||t==="alt-v")&&e.panel===void 0){this.fromClipboard();return}if(e.editing!==void 0){this.editKey(t);return}if(e.panel!==void 0){this.panelKey(t);return}if(e.help){if(t==="?"||t==="esc")e.help=!1,this.paint.draw();return}if(this.cols<qi.cols||this.rows<qi.rows){if(t==="esc")this.finish(2);return}if(t==="?"){e.help=!0,this.paint.draw();return}if(e.mode==="try"){this.tryKey(t);return}this.gridKey(t)}pointer(t){let e=this.view,n=this.paint.point(t),r=n?.target;if(e.installing!==void 0)return;if(t.action==="wheel"){if(!t.sideways)this.wheel(t.wheel);return}if((t.action==="press"||t.action==="drag")&&t.button!=="left")return;if(r?.kind==="track"&&n&&t.action!=="release")this.slide(r.field,n);else if(t.action==="press")this.pressed(r);else if(t.action==="release"&&n?.inside)this.released(r,t)}pressed(t){let e=this.view;if(e.help)this.paint.drop(),this.key("esc");else if(e.editing!==void 0||t===void 0)return;else if(e.panel!==void 0){if(t.kind==="setting"&&t.index<e.settings.length&&e.typing===void 0)e.panel=t.index,this.paint.draw()}else if(e.mode==="try")this.tryPoint(t);else if(t.kind==="tile")this.focus(t.index);else if(t.kind==="query")this.gridKey("/");else if(t.kind==="site")this.tab=t.tab,this.syncSite(),this.turn()}released(t,e){let n=this.view;if(t?.kind==="key")this.key(t.key);else if(t?.kind==="link"){if(!e.shift&&!e.alt&&!e.ctrl)KS(t.url)}else if(n.editing!==void 0){if(t?.kind==="suggest")n.pick=t.index,this.editKey("enter")}else if(n.panel!==void 0)this.panelPoint(t);else if(n.mode==="try"){if(t?.kind==="place"&&n.tuning)this.tuneKey(String(t.at))}else if(t?.kind==="tile"&&e.count===2)this.gridKey("enter");else if(t?.kind==="chip")this.toggle(t.index)}wheel(t){let e=this.view;if(e.help)return;if(e.editing!==void 0){if(e.suggest?.length)this.editKey(t<0?"up":"down")}else if(e.panel!==void 0){if(e.typing===void 0)this.panelKey(t<0?"up":"down")}else if(e.tuning)this.tuneKey(t<0?"up":"down");else if(e.mode==="try")this.tryKey(t<0?"left":"right");else this.focus(e.focus+t*or(this.cols,this.rows).perRow)}panelPoint(t){let e=this.view;if(t?.kind!=="setting"&&t?.kind!=="choice")return;let n=e.settings[t.index];if(e.typing!==void 0){let r=e.settings[e.panel??0];if(r&&(t.index!==e.panel||t.kind==="setting"))this.typeKey(r,"enter");else return}if(t.kind==="setting"&&t.index===e.settings.length){e.panel=t.index,this.panelKey("enter");return}if(e.panel=t.index,t.kind==="choice"&&n){if(n.entry==="text"||t.choice===void 0){this.panelKey("enter");return}if(n.multi){n.cursor=Math.max(0,n.choices.indexOf(t.choice)),this.panelKey(" ");return}if(n.value!==t.choice)n.value=t.choice,this.recount()}this.paint.draw()}tryPoint(t){let e=this.view;if(t.kind==="scene")e.scene=t.scene,e.details=!1,this.paint.draw();else if(e.tuning&&t.kind==="field")e.tuning.field=t.field,this.paint.draw()}slide(t,e){let n=this.view,r=n.tuning;if(!r)return;let i=Math.min(1,Math.max(0,e.width>1?e.x/(e.width-1):0));if(r.field=t,t===0){let o=Math.max(100,r.fill),s=Kl+Math.round(i*(o-Kl+1));n.tune.size=i===1||r.fill>0&&s>=r.fill?"fill":Math.min(o,s)}else n.tune.opacity=Math.round(i*100)/100;this.retune()}gridKey(t){let e=this.view,{perRow:n,rowsVis:r}=or(this.cols,this.rows),o={left:-1,right:1,up:-n,down:n,k:-n,j:n,pgup:-n*r,pgdn:n*r,home:-e.focus,end:e.tiles.length}[t];if(o!==void 0){this.focus(e.focus+o);return}if(/^[1-9]$/.test(t)){this.toggle(Number(t)-1);return}if(t==="enter"&&e.tiles[e.focus]){e.mode="try",e.error=void 0,this.select();return}if(t==="v"){this.fromClipboard();return}if(t==="c"){e.preset=e.preset==="cutouts"?"all":"cutouts",this.turn();return}if(t==="tab"||t==="shift-tab"){let s=J.length+1;this.tab=(this.tab+(t==="tab"?1:s-1))%s,this.syncSite(),this.turn();return}if(t==="/"){e.editing="",this.paint.draw();return}if(t===" "){this.unfold();return}if(t==="o"){this.openPage();return}if(t==="s"){e.panel=0,e.advanced=!1,this.recount(),this.paint.draw();return}if(t==="esc")this.finish(2)}panelKey(t){let e=this.view,n=e.panel??0,r=e.settings[n];if(e.typing!==void 0&&r){this.typeKey(r,t);return}let i=ja(e);if(t==="up"||t==="down"){let o=i.indexOf(n)+(t==="up"?-1:1);e.panel=i[(o+i.length)%i.length]??n,this.paint.draw();return}if(t==="a"||t==="enter"&&n===e.settings.length){e.advanced=!e.advanced,e.panel=ja(e)[0]??0,this.paint.draw();return}if(r?.entry&&(t==="enter"||r.entry==="number"&&/^[0-9]$/.test(t))){e.typing=t==="enter"?r.entry==="text"?r.value:"":t,this.paint.draw();return}if((t==="left"||t==="right")&&r&&r.entry!=="text"){let o=t==="left"?-1:1;if(r.multi)r.cursor=(r.cursor+o+r.choices.length)%r.choices.length;else r.value=av(r.choices,r.value,o),this.recount();this.paint.draw();return}if(t===" "&&r?.multi){let o=r.value.split(" "),s=r.choices.filter((c,u)=>u===r.cursor?!o.includes(c):o.includes(c)),a=r.multi.none;if(s.length>0||a!==void 0)r.value=s.length>0?s.join(" "):a,this.recount(),this.paint.draw();return}if(t==="esc"){e.settings.forEach((o,s)=>{o.value=this.setting(no[s]?.name??"")}),e.panel=void 0,e.advanced=!1,this.quietCount(),this.paint.draw();return}if(t==="enter"||t==="s"||t==="alt-c")e.panel=void 0,e.advanced=!1,this.quietCount(),this.adopt()}typeKey(t,e){let n=this.view,r=n.typing??"";if(e==="esc"){n.typing=void 0,this.paint.draw();return}if(e==="enter"||e==="up"||e==="down"){if(t.value=t.entry==="number"?Number(r)>0?String(Number(r)):"off":_s(r).join(" "),n.typing=void 0,this.recount(),e==="enter"){this.paint.draw();return}this.panelKey(e);return}let i=Ki(r,e,(o)=>t.entry==="number"?/^[0-9]$/.test(o)&&r.length<Xm:/^[\x20-\x7e]$/.test(o));if(i!==void 0)n.typing=i,this.paint.draw()}quietCount(){clearTimeout(this.countTimer),this.counting?.abort(),this.counting=void 0}recount(){if(this.quietCount(),this.view.counts=void 0,!this.view.tag)return;let t=new AbortController;this.counting=t,this.countTimer=setTimeout(()=>void this.countPending(t),Z3)}pending(){let t=(e)=>this.view.settings[no.findIndex((n)=>n.name===e)]?.value??this.setting(e);return{tag:this.view.tag,chosen:this.view.chosen,preset:t("TTHEME_FIND_POSTS")==="all"?"all":"cutouts",order:Up(t("TTHEME_FIND_ORDER")),rating:gi(t("TTHEME_FIND_RATING")),narrow:Yd(t("TTHEME_FIND_MIN_SCORE"),t("TTHEME_FIND_MIN_SIZE"),t("TTHEME_FIND_PNG")),enabled:js(t("TTHEME_FIND_SITES"))}}async countPending(t){let e=this.pending(),n=this.site?[this.site]:J.filter((o)=>e.enabled.includes(o.name)),r=AbortSignal.any([this.signal,t.signal]),i=await Promise.all(n.map(async(o)=>{let s=this.query(o,e);if(!s)return{site:o.name,count:0};if(o.counts&&!o.counts(s.tags))return{site:o.name};try{let a=await Qd(o,s.tags,r);return{site:o.name,...Number.isFinite(a)?{count:a}:{}}}catch{return{site:o.name}}}));if(this.counting===t&&this.view.panel!==void 0)this.view.counts=i,this.paint.draw()}adopt(){let t=this.view,e=no.map((r)=>this.setting(r.name));t.settings.forEach((r,i)=>{let o=no[i];if(o)this.values.set(o.name,r.value)});let n=no.filter((r,i)=>this.setting(r.name)!==e[i]);if(n.length===0){this.paint.draw();return}this.save(n),t.rating=gi(this.setting("TTHEME_FIND_RATING")),t.block=vo(this.setting("TTHEME_FIND_BLOCK")),t.sets=this.setting("TTHEME_FIND_SETS")==="show"?"show":"fold",t.preset=this.setting("TTHEME_FIND_POSTS")==="all"?"all":"cutouts",t.order=Up(this.setting("TTHEME_FIND_ORDER")),t.solo=this.setting("TTHEME_FIND_SOLO")==="on",t.narrow=this.narrowed(),t.enabled=js(this.setting("TTHEME_FIND_SITES")),t.hide=yc(this.setting("TTHEME_FIND_HIDE")),t.hideTags=_s(this.setting("TTHEME_FIND_HIDE_TAGS")),this.boards.clear(),this.current=void 0,t.shown=void 0,t.mode="grid",this.search()}save(t){this.store(t.map((e)=>[e.name,this.setting(e.name)]))}store(t){let e=Hn(this.home,"ttheme","config.zsh");try{let n=rc(e)?_3(e,"utf8"):"";return F(e,t.reduce((r,[i,o])=>Eu(r,i,o),n)),!0}catch(n){return this.view.error=n instanceof Error?n.message:String(n),!1}}editKey(t){let e=this.view,n=e.editing??"",r=e.suggest??[];if((t==="up"||t==="down")&&r.length>0){let s=((e.pick??r.length)+(t==="down"?1:r.length))%(r.length+1);e.pick=s===r.length?void 0:s,this.paint.draw();return}if(t==="esc"||t==="enter")this.quietSuggest();if(t==="esc"){if(e.editing=void 0,e.tag===""){this.finish(2);return}this.paint.draw();return}if(t==="enter"){let o=e.pick===void 0?void 0:r[e.pick],s=o?o.whole?o.value:n.replace(/\S*$/,o.value):n;if(e.editing=void 0,e.suggest=void 0,e.pick=void 0,s.trim()){this.commit(s.trim());return}if(e.tag===""){this.finish(2);return}this.paint.draw();return}let i=Ki(n,t);if(i!==void 0)e.editing=i,this.suggest(),this.paint.draw()}quietSuggest(){clearTimeout(this.suggestTimer),this.suggesting?.abort(),this.suggesting=void 0}suggest(){this.quietSuggest();let t=this.view;t.pick=void 0;let e=t.editing??"",n=/\S*$/.exec(e)?.[0]??"",r=Y3(n),i=G0(e,ZS,this.tagged).map((c)=>({value:c.tag,count:0,alias:c.name,whole:!0}));if(!r&&i.length===0){t.suggest=void 0;return}let o=r?k$(this.catalog.palettes,this.entry,n).map((c)=>({value:c.booru,count:0,palette:c.name})):[],s=[...new Map([...o.slice(0,ZS),...i].map((c)=>[c.value,c])).values()];if(t.suggest=s.length>0?s:void 0,i.length>0&&a8.test(e))t.pick=s.findIndex((c)=>("whole"in c));if(!r)return;let a=new AbortController;this.suggesting=a,this.suggestTimer=setTimeout(async()=>{try{let c=await Tw(n,AbortSignal.any([this.signal,a.signal]));if(this.suggesting===a&&t.editing!==void 0){let u=new Map(c.map((d)=>[d.value,d.count])),l=new Set(s.map((d)=>d.value));t.suggest=[...s.map((d)=>({...d,count:u.get(d.value)??0})),...c.filter((d)=>!l.has(d.value))].slice(0,c8),t.pick=t.pick!==void 0&&t.pick<s.length?t.pick:void 0,this.paint.draw()}}catch{}},V3)}async commit(t){let e=vc(t,this.site??J[0]);if(e){await this.jump(e.site,e.id);return}if(this.picture(t)){await this.attach(t);return}this.view.tag=t,this.view.chosen=void 0,this.relate(t),this.boards.clear(),await this.search()}async jump(t,e){let n=++this.gen;this.tab=J.indexOf(t)+1,this.syncSite(),this.current=void 0,this.view.shown=void 0,this.view.error=void 0;let r=Wl(`${t.key}|post:${e}`,!0);this.board=r,this.boards.set(r.key,r),this.show(),this.paint.draw();try{let i=await So(t,e,this.signal);if(n!==this.gen)return;if(!i){r.searching=!1,r.error=`${t.name} has no post ${e}`,this.view.error=r.error,this.show(),this.paint.draw();return}this.single(r,{site:t,post:i})}catch(i){this.fail(n,i,t)}}async turn(){this.fetch?.abort(),this.current=void 0,this.view.shown=void 0;let t=this.boards.get(this.boardKey);if(!t){await this.search();return}this.gen++,this.board=t,this.view.error=t.error,this.show(),this.paint.draw(),await this.pump()}unfold(){let t=this.view,e=0;for(let n of this.board.groups){let r=n.open?n.posts.length:1;if(t.focus<e+r){if(n.posts.length<2)return;n.open=!n.open,this.board.focus=e;for(let i of n.posts)if(!this.thumbPath.has(Ee(i.site,i.post.id)))this.thumbQueue.push(i);this.thumbs(),this.show(),this.scroll(),this.paint.glide(),this.paint.draw();return}e+=r}}openPage(){let t=this.view.tiles[this.view.focus],e=t&&this.posts.get(t.key);if(e)KS(e.site.pageUrl(e.post.id))}tryKey(t){let e=this.view;if(e.tuning){this.tuneKey(t);return}if(t==="left"||t==="right"){this.direction=t==="left"?-1:1,this.focus(e.focus+this.direction);return}if(t==="shift-left"||t==="shift-right"){e.scene+=t==="shift-left"?-1:1,e.details=!1,this.paint.draw();return}if(t==="i"){e.details=!e.details,this.inform(),this.paint.draw();return}if(t==="t"){e.tuning={field:0,held:{...e.tune},fill:this.current?.fill??0,coloring:e.coloring},this.paint.draw();return}if(t==="c"){this.recolor();return}if(t==="o"){this.openPage();return}if(t==="x"){this.swap();return}if(t==="v"){this.fromClipboard();return}if(t==="enter"){this.install();return}if(t==="esc")this.fetch?.abort(),clearTimeout(this.settle),e.fetching=void 0,e.mode="grid",e.error=void 0,this.paint.draw()}tuneKey(t){let e=this.view,n=e.tuning,r=e.tune;if(t==="up"||t==="down"){n.field=(n.field+(t==="up"?2:1))%3,this.paint.draw();return}let i=z3[t];if(i!==void 0){if(n.field===0)r.size=D3(r.size,i,n.fill);else if(n.field===1)r.at=(r.at-1+Math.sign(i)+9)%9+1;else r.opacity=Math.max(0,Math.min(100,Math.round(r.opacity*100)+i))/100;this.retune();return}if(/^[1-9]$/.test(t)){n.field=1,r.at=Number(t),this.retune();return}if(t==="="){let o=e.untuned;if(n.field===0)r.size=o.size;else if(n.field===1)r.at=o.at;else r.opacity=o.opacity;this.retune();return}if(t==="+"){e.tune={...e.untuned},this.retune();return}if(t==="enter"){e.tuning=void 0,this.paint.draw();return}if(t==="c"){this.recolor();return}if(t==="esc")e.tune={...n.held,...n.coloring===e.coloring?{}:{opacity:e.untuned.opacity}},e.tuning=void 0,this.retune()}recolor(){let t=this.view;if(!this.current||t.shown?.id!==this.current.key)return;t.coloring=t.coloring==="tone"?"original":"tone",t.tune.opacity=t.untuned.opacity,this.paint.draw(),this.reveal()}retune(){if(this.paint.draw(),this.current&&this.view.shown?.id===this.current.key)this.reveal()}inform(){let t=this.view,e=t.tiles[t.focus],n=e&&this.posts.get(e.key);t.info=n?this.infoOf(n):void 0}infoOf(t){let{site:e,post:n}=t,r=n.named,i=Rw(e,n),o=new Set([...r.artist,...r.character,...r.copyright]),s=Bs(n.source),a=/^https?:\/\//i.test(s)?s:e===sr&&s.startsWith("/")?US(s).href:void 0;return{page:e===sr?"":e.pageUrl(n.id),source:s,...a?{link:a}:{},artists:r.artist,characters:r.character,series:r.copyright,tags:n.tags.filter((c)=>!o.has(c)),...i?{rating:i}:{},...n.posted?{posted:n.posted}:{},ext:(kn(n)??n).ext,uploader:n.owner}}focus(t){let e=this.view;if(e.tiles.length===0)return;let n=Math.max(0,Math.min(e.tiles.length-1,t));if(n===e.focus)return;if(e.focus=n,this.board.focus=n,this.scroll(),this.paint.glide(),this.pump(),e.mode==="try")this.select();this.paint.draw()}scroll(){let t=this.view,{perRow:e,rowsVis:n}=or(this.cols,this.rows),r=Math.floor(t.focus/e);if(r<t.top)t.top=r;if(r>t.top+n-1)t.top=r-n+1;this.board.top=t.top}selected(t){if(t.chosen)return t.chosen;if(!t.tag)return[];return this.namesOf(t.tag,"danbooru")}namesOf(t,e){let n=t===this.entry.booru?this.entry:this.catalog.palettes.find((r)=>r.booru===t);return n?y$(n,e):[t]}syncChips(){let t=this.selected(this.view);this.view.chips=this.pool.slice(0,u8).map((e)=>({name:e,on:t.includes(e)}))}toggle(t){let e=this.view,n=e.chips[t];if(!n)return;let r=this.selected(e),i=n.on?r.filter((o)=>o!==n.name):[...r,n.name];if(i.length===0)return;e.chosen=i,e.tag=i.join(" or "),this.syncChips(),this.boards.clear(),this.search()}async relate(t){this.relating?.abort();let e=this.selected({tag:t,chosen:void 0});if(this.pool=e,this.syncChips(),this.paint.draw(),!t||/\s/.test(t))return;let n=this.related.get(t);if(!n){let r=new AbortController;this.relating=r;try{n=(await Hw(t,AbortSignal.any([this.signal,r.signal]))).map((i)=>i.value)}catch{return}if(this.relating!==r)return;this.related.set(t,n)}this.pool=[...new Set([...e,...n])],this.syncChips(),this.paint.draw()}query(t,e=this.view){let n=e.chosen?Cw(t,e.chosen):this.namesOf(e.tag,t.key);if(n.length===0)return;let r=e.chosen?.slice(n.length)??[],i=n.length>1,o=e.preset==="cutouts"?t.cutouts:"",s=i&&o.includes("~"),a=[i?n.map((l)=>`~${l}`).join(" "):n[0],t.rate(e.rating),...t.narrow(e.narrow),s?"":o,e.order==="score"?t.best:""].filter(Boolean),c=[],u=[];for(let l of a)if(Zd([...c,l].join(" "))<=t.tagBudget)c.push(l);else u.push(l);return{tags:c.join(" "),notes:[...u.length>0?[`${t.name} takes ${t.tagBudget} tags — ${u.join(" ")} left out`]:[],...r.length>0?[`${t.name} takes ${n.length} tag${n.length===1?"":"s"} — ${r.join(" ")} left out`]:[],...s?[`${t.name} ORs the names, so cutouts are told by the file`]:[],...e.narrow.score>0&&!t.scored?[`${t.name} keeps no score`]:[],...e.narrow.png&&t.guesses?[`${t.name} names a file type only where danbooru holds the file`]:[]]}}async search(){let t=++this.gen,e=Wl(this.boardKey,!0);this.board=e,this.boards.set(e.key,e),this.view.error=void 0;let n=this.sites.flatMap((o)=>{let s=this.query(o);return s?[{site:o,...s}]:[]}),r=this.sites.filter((o)=>!n.some((s)=>s.site===o)),i=[...n.flatMap(({notes:o})=>o),...r.length>0?[`${this.entry.name} has no tag on ${r.map((o)=>o.name).join(", ")}`]:[]];if(e.note=i.length>0?i.join(" · "):void 0,n.length===0)e.searching=!1;this.show(),this.paint.draw(),this.tally(t,e,n);try{let o=await Promise.all(n.map(async(s)=>({plan:s,owners:await this.kept.mateOwners(s.site)})));if(t!==this.gen)return;e.sources=o.flatMap(({plan:{site:s,tags:a},owners:c})=>{let u=Zd(a)+1<=s.tagBudget?s.uploadedBy:void 0;return[...u?[...c.keys()].map((l)=>({site:s,tags:`${a} ${u(l)}`,page:0,done:!1})):[],{site:s,tags:a,page:0,done:!1}]}),this.show(),this.paint.draw(),await this.pump()}catch(o){this.fail(t,o)}}async tally(t,e,n){let r=await Promise.allSettled(n.map(({site:i,tags:o})=>Qd(i,o,this.signal)));if(t===this.gen)e.total=r.reduce((i,o)=>i+(o.status==="fulfilled"&&Number.isFinite(o.value)?o.value:0),0),this.show(),this.paint.draw()}fail(t,e,n=this.site){if(t!==this.gen||this.signal.aborted)return;this.board.error=Wp(n?.name??this.tabName,e),this.board.searching=!1,this.view.error=this.board.error,this.show(),this.paint.draw()}drop(t,e,n){for(let r of t.sources)if(r.site===e)r.done=!0;t.note=[t.note,Wp(e.name,n)].filter(Boolean).join(" · ")}wants(){let{perRow:t,rowsVis:e}=or(this.cols,this.rows);return this.view.tiles.length<(this.board.top+e+VS)*t}need(){let{perRow:t,rowsVis:e}=or(this.cols,this.rows);return(e+VS)*t}live(t){return this.boards.get(t.key)===t}page(t,e,n){let r=`${t.key}|${e}|${n}`,i=this.pages.get(r);if(!i)i=Aw(t,e,n,this.signal).then((o)=>this.borrow(t,o)),this.pages.set(r,i),i.catch(()=>this.pages.delete(r));return i}async borrow(t,e){let n=t===ie?[]:e.filter((r)=>r.md5!=="");if(n.length>0)try{Rc(n,await Pc(n.map((r)=>r.md5),this.signal))}catch{}return e}staged(t){if(t===this.board)this.stageOf(t),this.paint.draw()}async round(t){t.stage="fetch",this.staged(t);let e=J.flatMap((a)=>{let c=t.sources.find((u)=>u.site===a&&!u.done);return c?[c]:[]}),n=await Promise.all(e.map(async(a)=>{try{let c=await this.page(a.site,a.tags,a.page);return t.arrived.add(a.site.name),this.staged(t),{source:a,posts:c}}catch(c){if(t.sources.every((u)=>u.site===a.site)||this.signal.aborted)throw c;return this.drop(t,a.site,c),{source:a,posts:void 0}}}));if(!this.live(t))return;let r=[];for(let{source:a,posts:c}of n){if(!c)continue;a.page++,a.done=c.length<vr;let u=t.last.get(a);for(let l of c){let d=u&&Yv(u.post,l)?u.set:`set:${a.site.key}:${l.id}`;u={post:l,set:d};let f=Ee(a.site,l.id);if(t.seen.has(f))continue;t.seen.add(f);let h={site:a.site,post:l};if(this.eligible(h))t.kin.set(h,[d,...qv(a.site,l)]),r.push(h);else t.checked++}if(u)t.last.set(a,u)}let i=this.dedupe(t,r),o=++t.rounds,s;if(this.view.order!=="fit")s=e.length>1?zv(i):i;else{let a=Ml(i,this.frame(),this.matched),c=a.slice(0,this.need()),u={done:0,total:c.length};if(t.ranking=u,this.staged(t),await this.looks(c,()=>{u.done++,this.staged(t)}),t.ranking=void 0,!this.live(t))return;s=[...Ml(c,this.frame(),this.matched),...a.slice(c.length)]}t.stage="check",this.staged(t);for(let a of s)t.roundOf.set(a,o);t.queue.push(...s),this.ahead(t)}ahead(t){if(this.aheading||this.view.order!=="fit"||!this.live(t))return;let e=t.queue.slice(0,this.need()).filter((n)=>!this.looking.has(Ee(n.site,n.post.id)));if(e.length===0)return;this.aheading=!0,this.looks(e).then(()=>{this.aheading=!1;for(let n of new Set(e.map((r)=>t.roundOf.get(r)??0)))this.resort(t,n);this.ahead(t)})}resort(t,e){let n=t.queue.flatMap((i,o)=>t.roundOf.get(i)===e?[o]:[]),r=Ml(n.map((i)=>t.queue[i]),this.frame(),this.matched);n.forEach((i,o)=>{t.queue[i]=r[o]})}dedupe(t,e){let n=[];for(let r of e){let i=Sp(r.post),o=i.map((a)=>t.same.get(a)).find(Boolean);if(!o){for(let a of i)t.same.set(a,r);n.push(r);continue}if(t.checked++,QS(r.post)<=QS(o.post))continue;for(let a of[...i,...Sp(o.post)])t.same.set(a,r);let s=n.indexOf(o);if(s>=0){n[s]=r;continue}this.replace(t,o,r)}return n}replace(t,e,n){t.roundOf.set(n,t.roundOf.get(e)??0);let r=t.queue.indexOf(e);if(r>=0){t.queue[r]=n;return}for(let i of t.groups){let o=i.posts.indexOf(e);if(o>=0){i.posts[o]=n,this.posts.set(Ee(n.site,n.post.id),n),this.thumbQueue.push(n),this.thumbs();return}}}async looks(t,e){let n=0;await Promise.all(Array.from({length:qS},async()=>{while(n<t.length)await this.look(t[n++]),e?.()}))}look(t){let e=Ee(t.site,t.post.id),n=this.looking.get(e);if(!n)n=(async()=>{let r=this.previewPath(t),i=Sc(t.site,t.post);await this.kept.cached(i.site,r,i.url);let o=await this.renders.run({job:"match",from:r,colors:this.entry.signature});return this.looked.set(e,o),this.matched.set(t.post,o.match),o})().catch(()=>{return}),this.looking.set(e,n);return n}async pump(){let t=this.gen,e=this.board;if(this.pumping===t||e.sources.length===0)return;this.pumping=t;let n=[],r;try{e.searching=!0;while(t===this.gen){while(n.length<DS&&e.queue.length>0&&this.wants()){let s=e.queue.shift();n.push({pick:s,passed:this.vet(s)})}if(this.ahead(e),!r&&e.queue.length<DS&&e.sources.some((s)=>!s.done)&&this.wants()){let s=this.round(e).then(()=>{if(r===s)r=void 0});s.catch(()=>{}),r=s}let i=n.shift();if(!i){if(!r)break;await r,this.show(),this.paint.draw();continue}let o=await i.passed;if(t!==this.gen)return;if(e.checked++,o)this.admit(i.pick);this.show(),this.paint.draw()}if(t===this.gen)e.searching=!1,this.show(),this.paint.draw()}catch(i){this.fail(t,i)}finally{if(this.kept.save(),this.pumping===t)this.pumping=0}}eligible({site:t,post:e}){let n=kn(e);if(!Mc(t,e,this.view.rating)||Ec(e,this.view.block).length>0||!n)return!1;if(this.view.solo&&e.solo===!1)return!1;let{score:r,size:i,png:o}=this.view.narrow;if(Math.min(e.width,e.height)<i||t.scored&&e.score<r||o&&e.ext!=="png"||Iw(e,this.view.hide).length>0||this.view.hideTags.some((s)=>e.tags.includes(s)))return!1;return this.view.preset==="all"?["png","jpg","jpeg",""].includes(n.ext):["png",""].includes(e.ext)}async vet(t){let[e]=await Promise.all([this.passes(t),this.look(t)]);return e}async passes({site:t,post:e}){return this.view.preset==="all"||t.vouched||this.kept.transparent(t,e)}admit(t){let{site:e,post:n}=t,r=this.board,i=Ee(e,n.id);this.posts.set(i,t);let o=r.kin.get(t)??[],s=this.looked.get(i),a=s&&{hash:s.hash,width:n.width,height:n.height},c=this.view.sets==="fold"?this.kindred(r,o,a):void 0;if(c){if(c.posts.push(t),this.register(r,c,o,a),c.open)this.thumbQueue.push(t),this.thumbs();return}let u={posts:[t],open:!1};r.groups.push(u),this.register(r,u,o,a),this.thumbQueue.push(t),this.thumbs()}kindred(t,e,n){for(let r of e){let i=t.kindred.get(r);if(i)return i}return n&&t.shapes.find((r)=>Vv(r.shape,n))?.group}register(t,e,n,r){for(let i of n)if(!t.kindred.has(i))t.kindred.set(i,e);if(r)t.shapes.push({shape:r,group:e})}holds(){this.view.held=zS(this.home,this.entry.name).map((t)=>{let e=this.heldFiles.get(t.from);return e?{...t,thumb:e}:t}),this.holdThumbs()}holdThumbs(){let t=be.cols*this.cell.w,e=be.rows*this.cell.h;if(t===0||e===0)return;for(let n of this.view.held.slice(0,Zm(this.cols))){if(n.thumb||this.heldAsked.has(n.from))continue;this.heldAsked.add(n.from);let r=Hn(this.scratch,`held-${U3(n.from)}-${t}x${e}.png`);this.renders.run({job:"thumb",from:n.from,to:r,width:t,height:e}).then(()=>{this.heldFiles.set(n.from,r),this.holds(),this.paint.draw()}).catch(()=>{})}}thumbs(){while(!this.signal.aborted&&this.thumbing<qS&&this.thumbQueue.length>0){let t=this.thumbQueue.shift();this.thumbing++,this.thumb(t).catch(()=>{this.thumbless.add(Ee(t.site,t.post.id)),this.show(),this.paint.draw()}).finally(()=>{this.thumbing--,this.thumbs()})}}async thumb(t){let{site:e,post:n}=t,r=kt.cols*this.cell.w,i=kt.rows*this.cell.h,o=Sc(e,n),s=Hn(Ve(e),"tile",`${XS(n.id,o.url)}-${r}x${i}.png`);if(!rc(s)){let a=this.previewPath(t);if(await this.kept.cached(o.site,a,o.url),this.signal.aborted)return;await this.renders.run({job:"thumb",from:a,to:s,width:r,height:i})}this.thumbPath.set(Ee(e,n.id),s),this.show(),this.paint.draw()}select(){let t=this.view,e=t.tiles[t.focus];if(this.fetch?.abort(),clearTimeout(this.settle),t.fetching=void 0,this.inform(),!e)return;if(this.current?.key===e.key){this.reveal();return}this.settle=setTimeout(()=>void this.load(e),X3),this.paint.draw()}async load(t){let e=this.view,n=this.posts.get(t.key);if(!n)return;let r=new AbortController;if(this.fetch=r,this.kept.credit(n,r.signal),!kn(n.post))return;let{site:i}=n,o=this.board;try{await Us(i,n.post,r.signal);let s=kn(n.post),a=this.origPath(i,t.id,s.ext);if(!rc(a))e.fetching={id:t.key,got:0,size:0},this.paint.draw();let c=bi(i,n.post,s),u=await this.kept.cached(c.site,a,c.url,(f,h)=>{if(e.fetching?.id===t.key)e.fetching={id:t.key,got:f,size:h},this.paint.draw()});if(r.signal.aborted)return;if(e.fetching=void 0,o!==this.board)return;let l={site:i,id:t.id,key:t.key,path:a,ext:s.ext,size:u,using:"plain",failed:!1};e.preparing=t.key,this.paint.flush();let d=await this.render(l,"plain");if(r.signal.aborted||o!==this.board)return;if(d.clear===0&&rs()&&this.setting("TTHEME_FIND_REMOVE_BG")!=="off"){if(e.preparing=void 0,e.cutting=t.key,this.paint.flush(),l.cut=await this.cutOut(i,t.id,a,r.signal),r.signal.aborted||o!==this.board)return;if(e.cutting=void 0,l.cut){e.preparing=t.key,this.paint.flush();let f=await this.render(l,"cut").catch(()=>{return});if(r.signal.aborted||o!==this.board)return;if(f&&Ju(f.clear))l.using="cut";else Ul(l.cut,{force:!0}),l.cut=void 0,l.failed=!0}else l.failed=!0}if(this.current=l,e.tiles[e.focus]?.key===t.key)await this.present();this.preload()}catch(s){if(!r.signal.aborted&&!this.signal.aborted)e.error=Wp(i.name,s)}finally{if(e.fetching?.id===t.key)e.fetching=void 0;if(e.preparing===t.key)e.preparing=void 0;if(e.cutting===t.key)e.cutting=void 0;this.paint.draw()}}async cutOut(t,e,n,r){let i=Hn(Ve(t),"cut",`${e}.png`);if(rc(i))return i;try{return F3(W3(i),{recursive:!0}),await ka(n,i,r),i}catch{Ul(i,{force:!0});return}}swap(){let t=this.current;if(!t?.cut||this.view.shown?.id!==t.key)return;t.using=t.using==="cut"?"plain":"cut",this.reveal()}preload(){let t=this.view;if(t.mode!=="try")return;for(let e of[t.focus+this.direction,t.focus-this.direction]){let n=t.tiles[e],r=n&&this.posts.get(n.key);if(r)this.kept.credit(r,this.signal);if(this.prefetching>=Q3||!r||!kn(r.post))continue;let{site:i,post:o}=r;this.prefetching++,Us(i,o,this.signal).then(async()=>{let s=kn(o),a=this.origPath(i,o.id,s.ext),c=bi(i,o,s);return await this.kept.cached(c.site,a,c.url),this.render({site:i,id:o.id,key:n.key,path:a,ext:s.ext,size:0,using:"plain",failed:!1},"plain")}).catch(()=>{}).finally(()=>{this.prefetching--})}}async render(t,e){let n=this.cols*this.cell.w,r=this.rows*this.cell.h,i=Math.min(n,i8),o=Math.max(1,Math.round(r*i/n)),s={...this.view.tune},{coloring:a}=this.view,c=!eE(s,this.view.untuned),u=s.opacity!==this.view.untuned.opacity,l=c?`-${s.size}-${s.at}${u?`-${Math.round(s.opacity*100)}`:""}`:"",d=Hn(this.scratch,`${t.site.key}-${t.id}${e==="cut"?"c":""}${a==="original"?"o":""}-${i}x${o}${l}.png`),f=`${t.site.key}:${t.id}:${e}:${a}:${i}x${o}`,h=this.clarity.get(f);if(h&&rc(d))return t.fill=h.fill,{clear:h.clear,path:d,opacity:h.opacity,touched:u};let m=await this.renders.run({job:"show",from:e==="cut"?t.cut:t.path,to:d,width:i,height:o,colors:this.entry,tone:this.tone,blur:this.blurring*i/mf(n,r).width,coloring:a,...c?{tune:{size:s.size,at:s.at,...u?{opacity:s.opacity}:{}}}:{}});if(this.clarity.set(f,m),t.fill=m.fill,c)this.keepTuned(d);return{clear:m.clear,path:d,opacity:m.opacity,touched:u}}keepTuned(t){this.tunedFiles.push(t);while(this.tunedFiles.length>o8){let e=this.tunedFiles.findIndex((n)=>n!==this.view.shown?.path&&n!==t);if(e===-1)return;Ul(this.tunedFiles.splice(e,1)[0],{force:!0})}}async present(){let t=this.current;if(!t)return;let e=t.using,{coloring:n}=this.view,r=this.view.tune.opacity,{clear:i,path:o,opacity:s,touched:a}=await this.render(t,e);if(this.current!==t||t.using!==e||this.view.coloring!==n)return;if(!a&&this.view.tune.opacity===r)this.view.untuned.opacity=s,this.view.tune.opacity=s;if(this.view.tuning&&t.fill)this.view.tuning.fill=t.fill;this.view.shown={id:t.key,clear:i,bytes:t.size,path:o,cut:t.cut?e==="cut"?"on":"off":t.failed?"failed":"none"}}reveal(){let t=this.view;if(this.presenting){this.again=!0;return}this.presenting=!0,t.preparing=this.current?.key,this.paint.flush(),this.present().catch((e)=>{t.error=e instanceof Error?e.message:String(e)}).finally(()=>{if(this.presenting=!1,this.again){this.again=!1,this.reveal();return}if(t.preparing===this.current?.key)t.preparing=void 0;this.paint.draw()})}async install(){let t=this.view,e=t.tiles[t.focus],n=this.current;if(!e||n?.key!==e.key||t.preparing!==void 0||t.shown?.id!==e.key)return;t.installing=e.key,t.error=void 0,this.paint.flush();let r=q3(t.tune,t.untuned),i=this.posts.get(n.key)?.post;try{await this.renders.run({job:"backdrop",from:n.using==="cut"?n.cut:n.path,source:n.path,home:this.home,colors:this.entry,tone:this.tone,origin:{site:n.site.key,id:n.id,ext:n.ext,from:`${n.site.name} ${n.id} ${n.site.pageUrl(n.id)}`,artist:i?.named.artist??[],source:Bs(i?.source??"")},width:this.cols*this.cell.w,height:this.rows*this.cell.h,blur:this.blurring,coloring:t.coloring,...r?{tune:r,aligns:ji(W(this.home).terminals),user:B3()}:{}}),this.kept.owned(n.site,n.id,i?.owner??""),Te(this.home),this.holds();let{size:o,at:s,opacity:a}=t.tune,c=r?` · ${o==="fill"?"fill":`${o}%`} · ${Ut[s-1]} · ${a.toFixed(2)}`:"",u=i?.named.artist.length?`${i.named.artist.join(", ")} · `:"";t.saved={text:`Background · ${this.entry.name} ← ${u}${n.site.name} ${n.id}${c}`,key:e.key},t.installed.push(e.key),this.fetch?.abort(),clearTimeout(this.settle),t.fetching=void 0,t.mode="grid"}catch(o){t.error=o instanceof Error?o.message:String(o)}t.installing=void 0,this.paint.draw()}}async function nE(t,e,n){let r=new Kp(t,he(t),e,e.booru??"",n);if(await r.run(),Pi(process.env))process.stdout.write(Ni(""));return{saved:r.saved,installs:r.installs}}async function rE(t){let e=Q(),n=he(e),r=Tr(n.palettes,t);if(!process.stdin.isTTY||!process.stdout.isTTY)throw Error("needs a terminal");let i=new Kp(e,n,r,r.booru??""),o=await i.run();if(i.saved&&o!==0)return process.stderr.write(`${i.saved}
711
+ `),0;return o}var Ss=50;function l8(t){return{background:t.background,foreground:t.foreground,cursor:t.cursor,selection:t.selection,ansi:t.ansi}}function iE(t,e,n){let r=$s(n),i=cn(l8(e)),o=a$(t).map((h)=>h.toLowerCase()),s=wp(i,e.signatureSlots,e.waived??[]),a=Un(ur(i,e.signatureSlots,e.waived??[])).length,c=(h)=>i[h]?.toLowerCase()!==o[h],u=i.filter((h,m)=>c(m)).length,l=(h)=>{let m=i[h],g=e.signatureSlots.includes(An[h])?"◆":n?"■":" ",b=n?`${r.fg(m)}${g}\x1B[39m`:g,w=s.has(h)?r.bold("✗"):c(h)?n?"\x1B[33m●\x1B[39m":"●":" ";return` ${b} ${Nl(Et(m))}${w}`},d=a===0?"passes the gate":`${a} ${a===1?"miss":"misses"} in the gate`,f=[` ${yt(`${r.dim("Palette")}${u>0?r.dim(` ${u} tuned`):""}`,r.dim(d),Ss-2)}`];f.push(r.dim(Xt(Ss,"top",[[2," Base "]])));for(let h=0;h<A.length;h++)f.push(dn(r,` ${A[h].padEnd(10)}${l(h)}`,Ss));return f.push(r.dim(Xt(Ss,"mid",[[2," ANSI "],[12," Normal 0–7 "],[29," Bright 8–15 "]]))),ln.forEach((h,m)=>{f.push(dn(r,` ${h.padEnd(10)}${l(A.length+m)}${l(A.length+8+m)}`,Ss))}),f.push(r.dim(Xt(Ss,"bottom"))),f}function ql(){return process.stdin.isTTY===!0&&process.stdout.isTTY===!0}function sE(t,e){if(t.includes("/"))return t;let n=Oi(e,!1),r=n.filter((o)=>Bo(o.dir).some((s)=>s.slug===t)),[i]=r.length===1?r:n.length===1?n:[];return i?`${i.id}/${t}`:t}function h8(t,e,n){let r=W(t),i=n.filter((o)=>!r.palettes.includes(o));if(i.length>0)Ke(t,e,r,{...r,palettes:[...r.palettes,...i]});else if(n.some((o)=>r.palettes.includes(o)))qt(t,e,r);return{state:r,fresh:i}}function m8(t){let e=Math.max(0,...t.map((n)=>n.slot.length));return t.map((n)=>` ${n.slot.padEnd(e)} ${n.from} → ${n.to} ${n.rule}`)}function aE(t,e,n){let r=Uf(e),i=Qe(En(r.name,Bf(r),n.palettes,!0)),o=Rt(t,n,!1).palettes.find((s)=>s.name===i.name);if(o&&JSON.stringify(o)!==JSON.stringify(i))throw Error(`${i.name} is already in ${lt(i.name)??"the ttheme catalog"} and differs — \`ttheme add ${i.name}\` wears that one`);if(!o)tu(t,[...Jn(t),i]);return i.name}var p8=["background","foreground","cursor"];function cE(t){try{t();return}catch(e){return e.message}}function uE(t,e,n){return Rt(t,e,!1).palettes.filter((r)=>r.name!==n).map((r)=>({name:r.name,colors:{background:r.background,foreground:r.foreground,cursor:r.cursor,selection:r.selection,ansi:r.ansi}}))}function lE(t,e){let n=new Set(fe(t,e).map((r)=>r.key));return{count:()=>fe(t,e).length,added:()=>fe(t,e).filter((r)=>!n.has(r.key)).length,fresh:()=>(Zu(t,e)??[]).filter((r)=>!n.has(se(r))),discard:()=>{let r=fe(t,e).filter((i)=>!n.has(i.key));for(let i of r)No(t,e,i.key),Fc(t,e);if(r.length>0)Te(t)}}}function g8(...t){let e=new Map;for(let n of t.flatMap((r)=>r??[]))e.set(se(n),n);return e.size>0?[...e.values()]:void 0}function dE(t,e,n,r){if(!Ko(process.env,W(t).terminals))return;return async(i,o)=>{let s=Qe(En(e,r(i),n.palettes)),{saved:a}=await nE(t,s,o);return{...a?{note:a}:{},count:fe(t,e).length}}}async function Dp(t,e=!1){let n=process.stdout.isTTY===!0,r=Q(),i=W(r).terminals,o=n?Ol.of(process.env,r,t.name,i):void 0,s=n?Ll.of(process.env,i):void 0;return _S(t,{color:!Pt(),...o?{backdrop:o}:{},...s?{layer:s}:{},...e?{hosted:!0}:{}})}async function fE(t,e,n){let r=Q(),i=dt(r),o=await h1(r,n),s=t.includes("/")?t:`${o.id}/${t}`,a=xe(s);if(a)throw Error(`${s} ${a}`);if(lt(s)!==o.id)throw Error(`palettes in ${o.dir} are named ${o.id}/<palette> — ${s} belongs elsewhere`);let c=Ff(r,s);if(oc(c))throw Error(`${s} already exists — \`ttheme edit ${s}\` changes it`);let u=e?Tr(Rt(r,i).palettes,e):void 0;if(!ql())throw Error("new opens the palette editor — run it in a terminal");let l=u&&(lt(u.name)?u.base:u.default?void 0:u.name),d=u?_f(u,s,`kept from ${u.name}`):void 0,f=u?Zu(r,u.name)??u.pictures:void 0,{base:h,ansiSource:m,group:g,...b}=d??{name:s,signature:p8,...ei(za)},w=lE(r,s),k=({colors:M,signature:I})=>{let O=g8(f,w.fresh());return Bf({...b,...M,signature:I,...l?{base:l}:{},...O?{pictures:O}:{}})},v=await Dp({title:"New palette",name:s,...d?{colors:d}:{},signature:b.signature,...b.waive?{waive:b.waive}:{},palettes:uE(r,i,s),pictures:w.count(),find:dE(r,s,i,k),exports:bE(r,s,i,k),decode:qp,check:(M)=>cE(()=>En(s,k(M),i.palettes))});if(!v){w.discard(),console.log("Nothing made");return}d8(f8(c),{recursive:!0}),F(c,k(v));let{state:S}=h8(r,i,[s]);console.log(` + ${s}${u?` from ${u.name}`:""}
712
+ ${c}`),await nr(r,Rt(r,i).palettes.filter((M)=>M.name===s),S.terminals),console.log(`
713
+ \`ttheme use ${s}\` wears it · \`ttheme edit ${s}\` opens it again`)}function b8(t,e,n){let r=Qe(En(t,e,n.palettes));return ia(r).length>0?ea(r).filter((i)=>i.startsWith(" ✗")):[]}async function hE(t){let e=Q(),n=dt(e),r=W(e),i=Rt(e,n,!1),o=sE(t,e),s=Dl(e,o),a=s&&oc(s)?o:i.palettes.some((w)=>w.name===t)?t:o,c=Dl(e,a);if(!c||!oc(c)){let w=i.palettes.some((k)=>k.name===a);throw Error(w?`${a} is not one of yours — \`ttheme new <name> --from ${a}\` makes your own copy`:`no palette of yours called ${a} — \`ttheme new\` makes one`)}if(!ql())throw Error("edit opens the palette editor — run it in a terminal");let u=zp(c,"utf8"),l;try{l=En(a,u,n.palettes)}catch(w){throw Error(`${c} cannot be read — ${w.message}`)}let d=lE(e,a),f=new Set((l.pictures??[]).map((w)=>se(w))),h=({colors:w,signature:k})=>e$(i$(Wf(u,w),k),d.fresh().filter((v)=>!f.has(se(v)))),m=await Dp({title:"Edit palette",name:a,colors:ta(l),signature:l.signatureSlots,waive:l.waive,palettes:uE(e,n,a),pictures:d.count(),find:dE(e,a,n,h),exports:bE(e,a,n,h),decode:qp,check:(w)=>cE(()=>En(a,h(w),n.palettes))});if(!m){d.discard(),console.log("Nothing changed");return}let g=h(m);if(g===u){console.log(d.added()>0?`Kept the pictures you added to ${a}`:"Nothing changed");return}if(F(c,g),r.palettes.includes(a))qt(e,n,r);console.log(`Saved ${a}${r.palettes.includes(a)?" — new tabs and `ttheme use` wear it":` — \`ttheme add ${a}\` installs it`}`);let b=b8(a,g,n);if(b.length>0)console.log(`
714
714
  It misses the contrast gate:
715
- ${g.join(`
715
+ ${b.join(`
716
716
  `)}
717
- \`ttheme check --fix ${a}\` suggests colors that pass`)}function z1(t,e,n){return _n(t.palettes,t.palettes.some((r)=>r.name===e)?e:C1(e,n))}function D1(t,e=!1){let n=J(),r=ut(n),i=L(n),s=z1(Ot(n,r),t,n);if(console.log(`${s.name} · ${s.group}
718
- `),console.log(Co(s).join(`
719
- `)),Lo(s).length===0)return console.log(`
720
- Passes the gate`),0;let{theme:a,moves:c,left:u}=Xu(De(s));if(c.length===0)return console.log(`
717
+ \`ttheme check --fix ${a}\` suggests colors that pass`)}var oE=2;async function mE(t,e){let n=Q(),r=Tr(Go(n,dt(n),!1).palettes,t),i=Vc(r,qn(n)[t]);if(e==="show")return console.log(iE(r,i,!Pt()).join(`
718
+ `)),0;if(e!=="edit")throw Error(`tone takes show or edit, not ${e}`);if(!ql())throw Error("needs a terminal");let o=await Dp({title:"Edit palette",name:t,colors:ta(Ie(i)),original:ta(Ie(r)),tone:!0,signature:i.signatureSlots,...i.waived?{waive:i.waived}:{},decode:qp,check:()=>{return}},!0);if(!o)return oE;let s=qn(n),a=c$(r,cn(o.colors));if(JSON.stringify(a)===JSON.stringify(s[t]??{}))return oE;Kf(n,u$(s,t,a)),qt(n,dt(n),W(n));let c=Object.keys(a).length;return process.stderr.write(c===0?"Back to the original colors":`Saved · ${c} ${c===1?"color":"colors"} tuned`),0}function pE(t,e,n){return Tr(t.palettes,t.palettes.some((r)=>r.name===e)?e:sE(e,n))}function gE(t,e=!1){let n=Q(),r=dt(n),i=W(n),o=pE(Rt(n,r),t,n);if(console.log(`${o.name} · ${o.group}
719
+ `),console.log(ea(o).join(`
720
+ `)),ia(o).length===0)return console.log(`
721
+ Passes the gate`),0;let{theme:a,moves:c,left:u}=Sl(Ie(o));if(c.length===0)return console.log(`
721
722
  No color change fixes it — waive the rule in [contrast] with a reason, or pick other colors`),1;console.log(`
722
723
  ${u.length===0?"These colors pass":"These colors come closer"}:
723
- ${TC(c).join(`
724
- `)}`);let l=pl(n,s.name);if(!l||!Aa(l))return console.log(`
725
- \`ttheme new <name> --from ${s.name}\` makes a copy you can fix`),1;if(!e)return console.log(`
726
- \`ttheme check --fix ${s.name}\` writes them`),1;if(P(l,ud(Vm(l,"utf8"),cd(a))),i.palettes.includes(s.name))jt(n,r,i);return console.log(`
727
- Wrote ${l}`),u.length===0?0:1}function pl(t,e){let n=lt(e);return n&&pi(t,!1).some((r)=>r.id===n)?id(t,e):void 0}function FC(t,e){let n=pl(t,e.name),r=n&&Aa(n)?Cn(e.name,Vm(n,"utf8"),[e]).waiveReason:void 0,i=Nu(t,e.name)??e.pictures,{pictures:s,...o}=od(e,e.name,r);return{...o,...i?{pictures:i}:{}}}async function CC(t,e,n){if(t===e)return e;let r=n;if(r===void 0)if(!Zm())r="tuned";else{let i=await n$({message:`Share ${e.name} as…`,options:[{value:"tuned",label:"Your tone",hint:`named ${ml(e.name)}`},{value:"original",label:"The original"}]});if(fe(i))throw new Ne;r=i}return r==="original"?e:t}function ml(t){return`${t}-tuned`}async function q1(t,e){let n=J(),r=ut(n),i=z1(gi(n,r),t,n),s=xs(i,pn(n)[i.name]),o=await CC(s,i,e),a=FC(n,o),c=o===s&&s!==i;if(c){let u=ve(ml(o.name));if(u)throw Error(`${ml(o.name)} ${u} — share the original, or tune a palette with a shorter name`);a.name=ml(o.name)}if(console.log(u0(a)),process.stdout.isTTY)console.error(`
728
- Anyone with ttheme wears it with: ttheme add ${Fn}…${c?`
729
- It carries your tone, named ${a.name} so it does not clash with ${o.name}`:""}`)}function gl(t){Lr(`
730
- ${t} palettes installed — open a new tab, or reload your terminal config`)}function jC(t,e){return t.map((n)=>{if(n.startsWith(Fn))return n;let r=lt(n);if(r===void 0)return e===z?n:`${e}/${n}`;if(r!==e)throw Error(`${n} is not in ${e} — give its bare name, or leave --market out`);return n})}async function Y1(t,e){let n=J(),r=e?jC(t,(await qh(n,e)).id):t,i=ut(n),s=[...new Set(r.map((l)=>l.startsWith(Fn)?L1(n,l,i):l))],o=L(n),a=s.filter((l)=>o.palettes.includes(l)),c=s.filter((l)=>!o.palettes.includes(l));if(c.length===0){jt(n,i,o),console.log(`Already installed: ${a.join(", ")}`);return}let u={...o,palettes:[...o.palettes,...c]};je(n,i,o,u);for(let l of c)console.log(` + ${l}`);await Dn(n,Ot(n,i,!1).palettes.filter((l)=>c.includes(l.name)),u.terminals),gl(u.palettes.length)}function J1(t){let e=J(),n=ut(e),r=L(e),i=t.filter((a)=>r.palettes.includes(a)),s=t.filter((a)=>!r.palettes.includes(a));if(i.length===0)throw Error(`not installed: ${s.join(", ")} — \`ttheme list\` marks what is`);let o={...r,palettes:r.palettes.filter((a)=>!i.includes(a))};je(e,n,r,o),js(e,n,r.terminals,i);for(let a of i)console.log(` - ${a}`);if(gl(o.palettes.length),s.length>0)return console.error(`ttheme remove: not installed: ${s.join(", ")}`),1;return 0}function V1(t){let e=J(),n=ut(e),r=L(e);if(!r.palettes.includes(t))throw Error(`${t} is not installed — \`ttheme add ${t}\` first`);let{off:i,...s}=r,o=je(e,n,r,{...s,startup:t},!0);console.log(X1(t,r.terminals,o).join(`
731
- `))}function Z1(){let t=J(),e=L(t),n=Oi(e);if(!n)throw Error("no palettes installed — `ttheme browse` picks some");if(!e.off){console.log(`Already on · ${n}`);return}let{off:r,...i}=e,s=je(t,ut(t),e,i);console.log(X1(n,i.terminals,s).join(`
732
- `))}function Q1(){let t=J(),e=L(t);if(e.off){console.log("Already off");return}let n=je(t,ut(t),e,{...e,off:!0}),r=Oi(e);console.log(`Off · new tabs open in the terminal's own colors${r?` — \`ttheme on\` wears ${r} again`:""}`);for(let i of pt(e.terminals))if(n.get(i.id)?.restart)console.log(`${i.name} new tabs open on your own profile once ${i.name} restarts`)}function X1(t,e,n){let r=pt(e).filter((s)=>!s.defaults),i=r.length>0?[`Default ${t} · ${r.map((s)=>s.name).join(", ")} open new tabs with it once their config reloads`]:[];for(let s of pt(e)){let o=s.defaults?.profile(t);if(o)i.push(n.get(s.id)?.restart?`${s.name} new tabs open with it once ${s.name} restarts — "${o}" is now its default profile`:`${s.name} new tabs open with it — "${o}" is its default profile`)}return i.length>0?i:[`Default ${t} · no terminal is wired to open with it — \`ttheme init\` wires one`]}function tE(t,e){let n=new Map(e.palettes.map((r)=>[r.name,"market"]));for(let r of vc(t,e.palettes,!1))n.set(r.name,"mine");return n}function eE(t,e=!1){let n=J(),r=ut(n),i=new Set(L(n).palettes),s=tE(n,r),o=Mt(Ot(n,r).palettes);if(t)hi(o);let a=ui(t?S0(o,t):o),c=(f)=>s.get(f)??"kept";if(e){let f=a.map((d)=>({name:d.name,group:d.group,...d.catalog?{catalog:d.catalog}:{},installed:i.has(d.name),source:c(d.name)}));console.log(JSON.stringify(f,null,2));return}let u=Math.max(...a.map((f)=>f.name.length),0),l={market:"",mine:" · yours",kept:" · in no market you added"};for(let f of a){let d=f.catalog?`${f.group} / ${f.catalog}`:f.group;console.log(` ${i.has(f.name)?"●":"○"} ${f.name.padEnd(u)} ${d}${l[c(f.name)]}`)}if(process.stdout.isTTY){let f=t?`${a.length} of ${o.length}`:`${o.length}`;console.log(`
733
- ${f} palettes — ${a.filter((d)=>i.has(d.name)).length} installed`)}}async function nE(){let t=J(),e=Ss(t);if(e.length===0)console.log("No markets to update — `ttheme market add official` brings the ttheme catalog back");let n=(h,m)=>`${_h(h,m)} — kept the copy from the last update`;for(let h of e.filter(ct))try{console.log(` ${py(t,h)}`)}catch(m){console.log(` ${n(h,m)}`)}let r=e.filter((h)=>!ct(h)),i=new Set(r),s=[],o=jr(),a=()=>o.set(`Updating ${[...i].map(Z).join(", ")}${r.length>1?` · ${r.length-i.size}/${r.length}`:""}`);a(),await Promise.all(r.map(async(h)=>{let m=await jh(t,h),$;if("refreshed"in m){$=Gh(m.refreshed);let g=Uh(m.refreshed);if(g)s.push(g)}else $=n(h,m.failure);if(i.delete(h),i.size>0)a();else o.done();o.say(` ${$}`)})),o.done();for(let h of s)console.log(h);if(!LC(Hn(t)))return;for(let h of Wh(t))console.log(` ${h}`);let c=ut(t),u=L(t),l=tE(t,c),f=u.palettes.filter((h)=>!l.has(h)),d=new Map(jn(t).map((h)=>[h.name,h.pictures]));jt(t,c,u);for(let h of f)console.log(` ${h} left its market — ttheme keeps the copy you have`);await Dn(t,Ot(t,c,!1).palettes.filter((h)=>u.palettes.includes(h.name)&&d.has(h.name)).map((h)=>Us(h,d.get(h.name))),u.terminals)}async function Qm(t,e,n,r=!1){let i=process.env.TTHEME_SORT==="series"?t.palettes:ui(t.palettes);hi(i);let s=process.stdout.isTTY===!0,o=zr(process.env,s,J()),a=o?await o.saved():new Map,c=new im({entries:i,scope:n,installed:e,required:r,color:!Lt(),fx:Bu(process.env.TTHEME_FX),onFocus:o?(l)=>process.stdout.write(o.paint(l)):void 0}),u=await c.prompt();if(o)process.stdout.write(o.restore(a));if(u==="cancel")return;return t.palettes.filter((l)=>c.picked.has(l.name)).map((l)=>l.name)}function tp(t,e,n,r){let i=n===z?void 0:oa(t,n),s;try{s=i?.id??zs(t,n)}catch{s=ee(n)?$r(n):Z(n)}return{source:n,id:s,...i?.info.description?{description:i.info.description}:{},shown:Z(n),entries:n===z?Ai(t,n):i?.entries??[],auto:kr(n,e.updates),status:Vh(t,n,r)}}function Xm(t){return t instanceof Error?t.message:String(t)}function BC(t,e,n,r){let i=new Map(r.map((a)=>[a.source,a.id])),s=[],o=(a,c)=>s.push({where:a,message:c});for(let a of Ct(e.markets)){let c=i.get(a)??Z(a),u=n[a],l=na(t,a);if(u&&(l===void 0||u.at>l))s.push({where:c,source:a,update:!0,message:`Update failed ${sa(u.at)}: ${u.error}`});if(a===z)try{Je(GC(Me(t),"utf8"))}catch(f){s.push({where:c,source:a,message:`${Z(Me(t))}: ${Xm(f)}`})}else if(ee(a))if(!_C(He(t,a)))s.push({where:c,source:a,message:"No copy of it yet — `ttheme update` fetches it"});else try{Ln(a,Ye(t,a),Ai(t,z),o)}catch(f){s.push({where:c,source:a,message:`${Z(He(t,a))}: ${Xm(f)}`})}else try{qe(a,ne(Fe(a)),Ai(t,z),(f,d)=>o(Z(f),d))}catch(f){s.push({where:c,message:Xm(f)})}}return s}function UC(t,e,n,r,i){return{refresh:async(s)=>{if(ct(s)){let a=tp(t,e,s,qn());return{market:a,refreshed:{source:s,id:a.id,count:Mt(a.entries).length,change:{added:[],changed:[],gone:[]}}}}let o=await Lh(t,s,Fh);return{market:tp(t,e,s,qn()),refreshed:o}},fetch:async(s)=>{if(ct(s)){let a=Fe(s),c=ne(a);return{source:s,id:c,...a.description?{description:a.description}:{},shown:Z(s),entries:qe(s,c,Ai(t,z),re(!1)),auto:!1,status:"read in place"}}let o=await ia(t,s,void 0,r);return n.set(s,o),{source:s,id:o.id,..."info"in o&&o.info.description?{description:o.info.description}:{},shown:Z(s),entries:o.entries,auto:kr(s,{}),status:"not added yet"}},search:(s)=>Qh(s,r),apply:i}}async function ep(...t){for(let e of await Kh(...t))Lr(e)}function WC(t,e,n){let r=[];for(let i of t.adds){let s=i.source!==z&&(t.auto[i.source]??i.auto);r.push(`Added ${i.id} · ${i.shown} — ${Rt(Mt(i.entries).length)}${s?", updating on its own":""}`)}for(let i of t.removes){let s=e.find((a)=>a.source===i)?.id??i;r.push(`Removed ${s} · ${Z(i)}`);let o=n.filter((a)=>(lt(a)??z)===s);if(o.length>0)r.push(Jh(o))}for(let[i,s]of Object.entries(t.auto)){let o=e.find((a)=>a.source===i);if(o&&!t.removes.includes(i))r.push(`${o.id} ${s?"updates on its own now":"no longer updates on its own"}`)}return r}async function KC(t,e,n,r,i){let s=L(t),o=r.adds.length+r.removes.length+Object.keys(r.auto).length>0;for(let b of r.adds){let y=i.get(b.source);if(y)Ks(t,y)}for(let b of r.removes)Yh(t,b);let a=[...Ct(s.markets).filter((b)=>!r.removes.includes(b)),...r.adds.map((b)=>b.source)],c=ua(s,a,{...s.updates,...r.auto});if(o)Le(t,c);let u=ut(t,!1),l=Ot(t,u,!1).palettes.filter((b)=>r.picked.has(b.name)).map((b)=>b.name),f=s.palettes.filter((b)=>!l.includes(b)),d=l.filter((b)=>!s.palettes.includes(b));if(!o&&d.length===0&&f.length===0){await ep(t,s,e,r.refreshed),Lr("Nothing changed");return}let h={...c,palettes:l};je(t,u,s,h),js(t,u,s.terminals,f);for(let b of WC(r,n,l))Lr(b);for(let b of d)Lr(` + ${b}`);for(let b of f)Lr(` - ${b}`);let m=new Map(e.map((b)=>[b.name,b.pictures])),$=new Set(r.refreshed.flatMap((b)=>[...b.change.changed,...b.change.gone])),g=Ot(t,u,!1).palettes;if(await Dn(t,[...g.filter((b)=>d.includes(b.name)),...g.filter((b)=>l.includes(b.name)&&!d.includes(b.name)&&$.has(b.name)&&m.has(b.name)).map((b)=>Us(b,m.get(b.name)))],h.terminals),d.length>0||f.length>0)gl(h.palettes.length)}async function rE(){let t=I0(process.env),e=J(),n=L(e),r=jn(e),i=qn(),s=Ct(n.markets).map((b)=>tp(e,n,b,i)),o=new Set(s.flatMap((b)=>b.entries.map((y)=>y.name))),a=r.filter((b)=>n.palettes.includes(b.name)&&!o.has(b.name));hi([...s.flatMap((b)=>b.entries),...a]);let c=new Map,u=new AbortController,l=process.stdout.isTTY===!0,f=zr(process.env,l,e),d=f&&!t?await f.saved():new Map,h=Ie(n);if(t)process.stdout.write("\x1B[?2026h");let m=new am({markets:s,kept:a,installed:n.palettes,...h?{startup:h}:{},...t?{hub:t}:{},problems:BC(e,n,i,s),due:Ch(e,n),io:UC(e,n,c,u.signal,(b,y)=>Nk({say:y.say,set:y.status},()=>KC(e,r,s,b,c))),...process.env.TTHEME_SORT==="series"?{}:{order:ui},color:!Lt(),lookups:process.env.TTHEME_MARKET_LOOKUP!=="off",fx:Bu(process.env.TTHEME_FX),owns:l&&!t,...f?{onFocus:(b)=>process.stdout.write(f.paint(b))}:{}});try{await m.run()}finally{if(f?.stop?.(),f&&!t)process.stdout.write(f.restore(d));u.abort()}await m.idle();let $=m.result(),g=m.next();if(t&&g!==void 0)return await ep(e,L(e),r,$.refreshed),g;if(l&&t)process.stdout.write("\x1B[?1049l\x1B[?25h");for(let b of $.refreshed){let y=Bh(b);if(y)console.log(y)}if(m.applied()){for(let y of m.lines())console.log(y);let b=m.failure();if(b)throw b}else await ep(e,L(e),r,$.refreshed),console.log("Nothing changed");return t?Hc:0}import{rmSync as iE}from"node:fs";import{basename as zC,join as Pa}from"node:path";var sE=Pa(import.meta.dirname,".."),DC=Pa(sE,"themes"),np=Pa(sE,"dist"),bl=qt.map((t)=>$n[t].emitter),qC=[Yd,th],AK=bl.map((t)=>t.id);async function wl({only:t}={}){if(typeof Bun>"u")throw Error("needs bun — run it from a checkout: bun src/bin.ts build");let e=t&&t.length>0?bl.filter((s)=>t.includes(s.id)):bl,n=rw(DC),r=Zp(n);if(r.length>0){for(let s of r)console.error(` ✗ ${s.theme} [${s.rule}] ${s.detail}`);throw Error(`${r.length} contrast violation(s). Fix the palette, or waive the rule in its [contrast] section with a reason.`)}if(e.length===bl.length)iE(np,{recursive:!0,force:!0});else for(let s of e)iE(Pa(np,s.id),{recursive:!0,force:!0});let i=0;for(let s of[...e,...qC]){let o=n.flatMap((u)=>s.emit?.(u)??[]),a=s.emitShared?.(n)??[];for(let u of[...o,...a])await Bun.write(Pa(np,u.path),u.content),i++;let c=o.length>0?`${n.length} themes${s.limits?` (${s.limits})`:""}`:a.length>0?a.map((u)=>zC(u.path)).join(" "):`no files (${s.limits??"nothing to write"})`;console.log(` ${s.id.padEnd(16)} ${c}`)}console.log(`
734
- ${n.length} themes (${iw(n).length} in the new-tab rotation) -> ${i} files in dist/`)}import{existsSync as VC,readFileSync as lE}from"node:fs";import{availableParallelism as YC,homedir as oE}from"node:os";var JC=4;async function $l(t,e,n=oE()){let r=kt(q(t)),i=Tr(t),s=new Map(ue(t).palettes.map((f)=>[f.name,br(f)])),o=Object.entries(r.palettes).flatMap(([f,d])=>{let h=s.get(f);return h?d.pictures.filter((m)=>gs(m)||(m.blur??0)!==i).map((m)=>({name:f,key:m.key,paint:h})):[]});if(o.length===0)return 0;e(`Drawing ${o.length} background picture${o.length===1?"":"s"} again${i?` · blur ${i}px`:""}`);let a=xi(L(t).terminals),c=new Cm(Math.min(JC,YC()-1)),u=await c.map(o.map(({name:f,key:d,paint:h})=>({job:"redraw",home:t,user:n,name:f,key:d,paint:h,blur:i,aligns:a})));c.close();let l=[];return u.forEach((f,d)=>{let{name:h,key:m}=o[d];if(f instanceof Error||f===null){e(` ▢ ${h} ${m} — ${f instanceof Error?f.message:"no original to draw it from"}, left as it was`);return}l.push({name:h,picture:f})}),Uf(t,l),Re(t,n),l.length}async function aE(t,e,n,r,i=oE()){let s=kt(q(t)).palettes[e],o=s?.pictures.find((l)=>l.key===(r??s.active));if(!s||!o)throw Error(`${e} has no picture ${r??"shown"}`);if(Ee(o)===n)return{key:o.key,changed:!1};let a=ue(t).palettes.find((l)=>l.name===e);if(!a)throw Error(`no palette called ${e}`);let c=xi(L(t).terminals),u=await Tu(t,e,o.key,br(a),Tr(t),c,i,n);if(!u)throw Error(`${e} ${o.key} has no original to draw it from`);return Uf(t,[{name:e,picture:u}]),Re(t,i),{key:o.key,changed:!0}}function cE(t,e,n){let r=kt(q(t)).palettes[e],i=r?.pictures.find((a)=>a.key===(n??r.active));if(!r||!i)throw Error(`${e} has no picture ${n??"shown"}`);let s=ue(t).palettes.find((a)=>a.name===e);if(!s)throw Error(`no palette called ${e}`);let o=Ee(i)==="original"?"tone":"original";if(!Ck(t,e,i.key,br(s),Tr(t),o))throw Error(`${e} ${i.key} has no original to draw it from`);return{key:i.key,coloring:o}}async function uE(){return await $l(J(),(t)=>process.stderr.write(`${t}
735
- `)),0}async function fE(t,e,n){let r=J();if(_n(ue(r).palettes,t),e==="show"){if(!n)throw Error("image show needs the picture to show");let{at:i,of:s}=bs(r,t,n);return Re(r),process.stderr.write(`Background · ${t} ${i}/${s} ${n}
736
- `),0}if(e==="drop"){let{key:i,left:s}=lc(r,t,n);return Re(r),process.stderr.write(`Background · ${t} removed ${i} · ${s} left
737
- `),0}if(e==="tone"||e==="original"){let i=await aE(r,t,e,n);return process.stderr.write(`Background · ${t} ${i.key} ${e==="tone"?"tinted":"in its own colors"}
738
- `),0}if(e==="prepare"){let{key:i,coloring:s}=cE(r,t,n);return process.stderr.write(`Background · ${t} ${i} ready in ${s==="tone"?"its tone":"its own colors"}
739
- `),0}if(e==="tuned")return Re(r),0;throw Error(`unknown image action ${e} — show, drop, tone, original, prepare or tuned`)}function dE(t,e){let n=/^(\d+)x(\d+)$/.exec(t),r=/^(\d+)x(\d+)([+-]\d+)([+-]\d+)$/.exec(e);if(!n||!r)throw Error("a canvas is <width>x<height> and a place <width>x<height>+<x>+<y>");let[i,s]=n.slice(1).map(Number),[o,a,c,u]=r.slice(1).map(Number);return{width:i,height:s,at:{x:c,y:u,w:o,h:a}}}function ZC(t,e,n){let r=dE(e,n),i=Math.min(1,t.width/r.at.w);if(i===1)return r;return{width:Math.max(1,Math.round(r.width*i)),height:Math.max(1,Math.round(r.height*i)),at:{x:Math.round(r.at.x*i),y:Math.round(r.at.y*i),w:t.width,h:t.height}}}function hE(t,e,n,r){let i=Ht(new Uint8Array(lE(t)));return P(e,ln(rb(i,dE(n,r)))),0}function mE(t,e,n,r,i,s,o){let a=Number(r);if(!oe(n)||!Number.isFinite(a))throw Error("flatten needs a #rrggbb background and an opacity from 0 to 1");let c=Ht(new Uint8Array(lE(t))),u=i?ZC(c,i,s??""):void 0,l=cr(ar(c,n,Math.max(0,Math.min(1,a)),u));if(o&&VC(o))Xr(o,e,l);else P(e,l);return 0}import{execFileSync as QC}from"node:child_process";import{readFileSync as XC}from"node:fs";import{arch as tL,platform as kl,release as rp}from"node:os";var eL={ghostty:"ghostty",iterm2:"iTerm.app",wezterm:"WezTerm","terminal-app":"Apple_Terminal",warp:"WarpTerminal"};function nL(t,e){if(t==="konsole"){let r=/^(\d{2})(\d{2})(\d{2})$/.exec(e.KONSOLE_VERSION??"");return r?`${r[1]}.${r[2]}.${Number(r[3])}`:e.KONSOLE_VERSION}let n=eL[t];return n!==void 0&&e.TERM_PROGRAM===n?e.TERM_PROGRAM_VERSION:void 0}function rL(t){let e=Kt(t),n=t.TERM_PROGRAM&&t.TERM_PROGRAM!=="tmux"?t.TERM_PROGRAM:void 0,r=e==="unknown"?`unknown${n?` (TERM_PROGRAM=${n})`:""}`:e==="editor"?`editor (${Gd(t)})`:`${e} ${nL(e,t)??"(version unknown)"}`,i=t.TERM_PROGRAM==="tmux"?t.TERM_PROGRAM_VERSION:void 0;return[r,t.TMUX?`tmux ${i??"yes"}`:"tmux no",t.SSH_CONNECTION||t.SSH_TTY?"ssh yes":"ssh no"].join(" · ")}function pE(t,e){try{return QC(t,e,{encoding:"utf8",timeout:2000,stdio:["ignore","pipe","ignore"]}).trim()}catch{return}}function iL(){let t=tL();if(kl()==="darwin")return`macOS ${pE("sw_vers",["-productVersion"])??`(Darwin ${rp()})`} · ${t}`;if(kl()==="linux"){let e="";try{e=XC("/etc/os-release","utf8")}catch{}return`${/^PRETTY_NAME="?([^"\n]*)"?$/m.exec(e)?.[1]??"Linux"} · linux ${rp()} · ${t}`}return`${kl()==="win32"?"Windows":kl()} ${rp()} · ${t}`}function sL(t){if(t.TTHEME_ZSH)return`zsh ${t.TTHEME_ZSH}`;return(t.SHELL?pE(t.SHELL,["--version"])?.split(`
740
- `)[0]:void 0)??t.SHELL??"unknown"}function oL(t){try{let{terminals:e}=L(t);return e.length>0?e.join(", "):"none"}catch{return"installed.json missing or unreadable"}}function aL(t){let e=tu.flatMap((n)=>{let r=t[n];return r===void 0||r===Do(n)?[]:[`${n}=${/\s/.test(r)?JSON.stringify(r):r}`]});return e.length>0?e.join(" "):void 0}function gE(){let t=process.env,n=[["ttheme",It.version],["OS",iL()],["Shell",sL(t)],["Terminal",rL(t)],["Wired",oL(J())],["Settings",aL(t)]].filter((i)=>i[1]!==void 0),r=Math.max(...n.map(([i])=>i.length));for(let[i,s]of n)console.log(`${i.padEnd(r)} ${s}`)}import{execFileSync as cL,spawnSync as uL}from"node:child_process";import{chmodSync as lL,copyFileSync as fL,existsSync as zi,mkdirSync as bE,readdirSync as dL,readFileSync as vl,rmSync as ip}from"node:fs";import{homedir as hL}from"node:os";import{dirname as oo,join as mt}from"node:path";function mL(t,e,n){for(let r of dL(e))t.push({from:mt(e,r),to:mt(n,r)})}function cp(t){return Je(vl(mt(t,"dist","manifest.json"),"utf8"))}function yl(t,e){let n=mt(e.configHome,"ttheme"),r=[{from:mt(e.root,"bin","ttheme.js"),to:mt(n,"ttheme.js")},{from:mt(e.root,"bin","ttheme.js.map"),to:mt(n,"ttheme.js.map")},{from:mt(e.root,"shell","ttheme.zsh"),to:mt(n,"ttheme.zsh")},{from:mt(e.root,"shell","preview.zsh"),to:mt(n,"preview.zsh")},{from:mt(e.root,"shell","launch-tab.zsh"),to:mt(n,"launch-tab.zsh"),executable:!0}];mL(r,mt(e.root,"shell","adapters"),mt(n,"adapters"));let i=[{file:mt(e.zdotdir,".zshrc"),block:d$(n)}],s=mt(n,"config.zsh"),o=m$(zi(s)?vl(s,"utf8"):""),a={file:s,content:t.warpFast===void 0?o:ru(o,"TTHEME_WARP_FAST",t.warpFast?"on":"off")},c={terminals:t.terminals,palettes:t.palettes,...Object.fromEntries(pt(t.terminals).flatMap((f)=>Object.entries(f.installs?.(e)??{}).filter(([,d])=>d!==void 0))),...t.off?{off:!0}:{}},u=Su(e.configHome,c,e.home),l=e.stateDir?[mt(e.stateDir,"ghostty",".blind")]:[];return{home:e.home,copies:r,edits:i,settings:a,forget:l,catalog:cp(e.root),installed:c,notes:u}}function $E(t){try{return L(t)}catch{return}}function kE(t,e){try{return Ot(t,ut(t,!1,e),!1).palettes}catch{return[]}}function pL(t,e){let n=cp(e.root),r=Ct(t.markets).includes(z)?n.palettes:[],i=new Set(r.map((o)=>o.name)),s=kE(e.configHome,n).filter((o)=>!i.has(o.name)&&(lt(o.name)!==void 0||t.palettes.includes(o.name)));return{...n,palettes:[...r,...s]}}function yE(t,e){let n=Oi(t);return n&&e.includes(n)?n:void 0}function gL(t,e,n){let r=yl(e,n),i=yE(t,e.palettes),s=new Set(["terminals","palettes","off","startup",...qt.flatMap((a)=>Object.keys($n[a].installs?.(n)??{}))]),o=Object.fromEntries(Object.entries(t).filter(([a])=>!s.has(a)));return{...r,installed:{...o,...r.installed,...i?{startup:i}:{}}}}function bL(t,e){let n=yl({terminals:t.terminals,palettes:t.palettes,off:t.off},e),r=new Set([...n.catalog.palettes,...kE(e.configHome,n.catalog)].map((l)=>l.name)),i=t.palettes.filter((l)=>r.has(l)),s=t.palettes.filter((l)=>!r.has(l)),{startup:o,...a}=t,c={...a,palettes:i,...o&&i.includes(o)?{startup:o}:{}},u=s.length>0?[`Dropped ${s.join(", ")} — no longer in the catalog`,...n.notes]:n.notes;return{...n,installed:c,notes:u}}function wL(t){try{return cL(process.execPath,[mt(t,"ttheme","ttheme.js"),"--version"],{encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim()||void 0}catch{return}}function vE(t){let e=Ie(t);return[pt(t.terminals).map((n)=>n.name).join(", "),`${t.palettes.length} palettes`,e?`default ${e}`:"no default — ttheme is off"].join(" · ")}function sp(t,e=Ze()){for(let o of t.copies)if(bE(oo(o.to),{recursive:!0}),ip(o.to,{force:!0}),ip(`${o.to}.zwc`,{force:!0}),fL(o.from,o.to),o.executable)lL(o.to,493);P(t.settings.file,t.settings.content);for(let o of t.forget)ip(o,{force:!0});let n=oo(oo(t.settings.file)),r=$E(n),i=Object.fromEntries(pt(t.installed.terminals).flatMap((o)=>{let a=o.defaults?.key,c=a?r?.[a]:void 0;return a&&c?[[a,c]]:[]})),s=ta(n,{...t.installed,...i},e,t.home);if(Ct(s.markets).includes(z))Oc(n,t.catalog);Le(n,s),jt(n,ut(n),s,t.home,e);for(let o of t.edits){bE(oo(o.file),{recursive:!0});let a=zi(o.file)?vl(o.file,"utf8"):"";an(o.file,Ir(a,o.block))}return Ii(n,s,!0,e,t.home)}function Ha(t){if(fe(t))throw Mr("Nothing changed"),new Ne;return t}function op(t,e){return qt.filter((n)=>$n[n].offered(t,e))}async function $L(t,e,n,r){return Ha(await e$({message:"Wire which terminals?",options:op(n,r).map((i)=>({value:i,label:$n[i].name,hint:i===t?"detected":void 0})),initialValues:e,required:!0}))}async function kL(t){return Ha(await Ve({message:"Switch Warp to each tab's palette in about 0.2 s instead of 0.6 s?\nAbout 8% CPU while Warp is in front with tabs of different palettes — `ttheme config` changes it",initialValue:eu(t,"TTHEME_WARP_FAST")!=="off"}))}function ap(t){let e=[...t.copies.filter((n)=>!zi(n.to)).map((n)=>n.to),...zi(t.settings.file)?[]:[t.settings.file],...t.edits.filter((n)=>!vl(n.file,"utf8").includes("# ttheme begin")).map((n)=>n.file)];if(e.length>0)throw Error(`init left gaps:
724
+ ${m8(c).join(`
725
+ `)}`);let l=Dl(n,o.name);if(!l||!oc(l))return console.log(`
726
+ \`ttheme new <name> --from ${o.name}\` makes a copy you can fix`),1;if(!e)return console.log(`
727
+ \`ttheme check --fix ${o.name}\` writes them`),1;if(F(l,Wf(zp(l,"utf8"),ta(a))),i.palettes.includes(o.name))qt(n,r,i);return console.log(`
728
+ Wrote ${l}`),u.length===0?0:1}function Dl(t,e){let n=lt(e);return n&&Oi(t,!1).some((r)=>r.id===n)?Ff(t,e):void 0}function qp(t){let e=t.trim();if(!e.startsWith(Sn))return;try{let{background:n,foreground:r,cursor:i,selection:o,ansi:s}=Uf(e);return{background:n,foreground:r,cursor:i,selection:o,ansi:s}}catch{return}}function bE(t,e,n,r){return{code:(i)=>Gf(wE(t,Qe(En(e,r(i),n.palettes)))),toml:r,command:"ttheme add"}}function wE(t,e){let n=Dl(t,e.name),r=n&&oc(n)?En(e.name,zp(n,"utf8"),[e]).waiveReason:void 0,i=Zu(t,e.name)??e.pictures,{pictures:o,...s}=_f(e,e.name,r);return{...s,...i?{pictures:i}:{}}}async function w8(t,e,n){if(t===e)return e;let r=n;if(r===void 0)if(!ql())r="tuned";else{let i=await ek({message:`Share ${e.name} as…`,options:[{value:"tuned",label:"Your tone",hint:`named ${zl(e.name)}`},{value:"original",label:"The original"}]});if(me(i))throw new He;r=i}return r==="original"?e:t}function zl(t){return`${t}-tuned`}async function $E(t,e){let n=Q(),r=dt(n),i=pE(Go(n,r),t,n),o=Vc(i,qn(n)[i.name]),s=await w8(o,i,e),a=wE(n,s),c=s===o&&o!==i;if(c){let u=xe(zl(s.name));if(u)throw Error(`${zl(s.name)} ${u} — share the original, or tune a palette with a shorter name`);a.name=zl(s.name)}if(console.log(Gf(a)),process.stdout.isTTY)console.error(`
729
+ Anyone with ttheme wears it with: ttheme add ${Sn}…${c?`
730
+ It carries your tone, named ${a.name} so it does not clash with ${s.name}`:""}`)}import{spawn as $8,spawnSync as kE}from"node:child_process";import{existsSync as k8,readFileSync as yE}from"node:fs";import{homedir as y8}from"node:os";import{join as vE}from"node:path";function SE(t,e,n,r=y8(),i=(o)=>{process.stdout.write(o)}){if(!e||Pt(t)||t.TMUX||Dt(t)!=="terminal-app")return;let[o="",s="-"]=(t.TTHEME_TERMINAL_SHOWN??"").split(" "),a=t.TTHEME_TTY,c=o?Oe(V(n),o,r):void 0,u=Cu(Qo(n)).get(oe(o))??[],l=u.find((B)=>B===`${j(o)}.${s}.png`)??u[0];if(!a||!c||s==="-"||!l||!k8(c.image))return;let d=vE(Qo(n),l),f=["-l","JavaScript",Hu(n),"tab",a,sn(o)],h=W(n).terminalBase??"Basic",m=Xh(t,r),g=yE(d),b,w=d,k=0,v,S=!1,M=!1,I,O=(B)=>{S=!0,$8("osascript",[...f,h],{stdio:"ignore"}).on("close",()=>{if(S=!1,M)return;i(B);let X=I;I=void 0,X?.()})},H=(B,X)=>{b??=jt(new Uint8Array(yE(c.image)));let z=vE(Qo(n),`${j(o)}.h${process.pid}-${++k}.png`);li(w,z,yr(kr(b,B,c.opacity,tm(b.width,b.height,c,m)))),w=z,O(X)},N=()=>{if(w!==d)li(w,d,g),w=d},L=(B)=>{clearTimeout(v),v=setTimeout(()=>{if(S)I=B;else B()},vh)},K=()=>{clearTimeout(v),I=void 0};return{slots:[],paint(B){return L(B.name===o?()=>{N(),O("")}:()=>H(B.background,er(B))),""},wear(B){return kE("osascript",[...f.slice(0,-1),sn(B.name),h],{encoding:"utf8"}).stdout?.trim()==="worn"?"":er(B)},saved:async()=>new Map,restore(){return K(),M=!0,N(),kE("osascript",[...f,h],{stdio:"ignore"}),""},stop:K}}import{existsSync as sc,readdirSync as v8,readFileSync as Jl,rmSync as EE,statSync as xE}from"node:fs";import{homedir as S8}from"node:os";import{join as ro}from"node:path";var E8=150,M8=260;function Yl(t){return t?.includes(`path = "${j("")}`)===!0}function x8(t){try{return W(t).terminals.includes("warp")}catch{return!1}}function ME(t,e){let n=j(e);if(!sc(t))return;return v8(t).filter((i)=>i.startsWith(`${n}.`)&&/^[0-9a-f]{8}\.yaml$/.test(i.slice(n.length+1))).map((i)=>({file:i,at:xE(ro(t,i)).mtimeMs})).sort((i,o)=>o.at-i.at)[0]?.file??(sc(ro(t,`${n}.yaml`))?`${n}.yaml`:void 0)}function O8(t,e){if(!e)return;let n;try{n=Jl(ro(t,e),"utf8")}catch{return}let r=/^background_image:\n\s+path:\s*"([^"]*)"\n\s+opacity:\s*(\d+)/m.exec(n);return r?.[1]?{image:r[1],opacity:Number(r[2])/100}:void 0}function OE(t,e,n,r=S8()){if(!e||Pt(t)||t.TMUX||Dt(t)!=="warp")return;let i=Dr(r,n);if(!sc(i)||!x8(n))return;let o=Ci(r),s=Fu(n),a=[],c=t.TTHEME_WARP_WEARS??Ae(W(n)),u=O8(o,c&&ME(o,c)),l,d,f=(b)=>{let w=Jl(i,"utf8"),k=qr(w);if(k===b)return;if(Yl(b)&&!Yl(k)&&!sc(s))F(s,k??"");if(bn(i,ju(w,b)),!Yl(b))EE(s,{force:!0})},h=(b)=>{for(let w of a.splice(0))if(w===b)a.push(w);else EE(ro(o,w),{force:!0})},m=()=>{clearTimeout(l),clearTimeout(d)},g=(b,w,k)=>{m(),l=setTimeout(()=>{let v=w;if(!v)v=`${j(b.name)}.view-${process.pid}-${a.length+1}.yaml`,F(ro(o,v),ma(b,k)),a.push(v);let S=v,M=Date.now()-xE(ro(o,S)).mtimeMs;d=setTimeout(()=>{f(im(b.name,S)),h(S)},Math.max(0,M8-M))},E8)};return{slots:[],paint:(b)=>{if(b.name===c)g(b,ME(o,b.name));else if(u)g(b,void 0,u);else g(b,sc(ro(o,`${j(b.name)}.yaml`))?`${j(b.name)}.yaml`:void 0);return""},wear:(b,w)=>w.includes("warp")?"":void 0,saved:async()=>new Map([["theme",qr(Jl(i,"utf8"))??""]]),restore:(b)=>{m();let w=b.get("theme");if(w)f(w);else if(Yl(qr(Jl(i,"utf8"))))f(Lu);return h(),""}}}function Es(t,e,n){return SE(t,e,n)??fk(t,e)??OE(t,e,n)}function Vl(t){Yr(`
731
+ ${t} palettes installed — open a new tab, or reload your terminal config`)}function R8(t,e){return t.map((n)=>{if(n.startsWith(Sn))return n;let r=lt(n);if(r===void 0)return e===q?n:`${e}/${n}`;if(r!==e)throw Error(`${n} is not in ${e} — give its bare name, or leave --market out`);return n})}async function IE(t,e){let n=Q(),r=e?R8(t,(await Im(n,e)).id):t,i=dt(n),o=[...new Set(r.map((l)=>l.startsWith(Sn)?aE(n,l,i):l))],s=W(n),a=o.filter((l)=>s.palettes.includes(l)),c=o.filter((l)=>!s.palettes.includes(l));if(c.length===0){qt(n,i,s),console.log(`Already installed: ${a.join(", ")}`);return}let u={...s,palettes:[...s.palettes,...c]};Ke(n,i,s,u);for(let l of c)console.log(` + ${l}`);await nr(n,Rt(n,i,!1).palettes.filter((l)=>c.includes(l.name)),u.terminals),Vl(u.palettes.length)}function RE(t){let e=Q(),n=dt(e),r=W(e),i=t.filter((a)=>r.palettes.includes(a)),o=t.filter((a)=>!r.palettes.includes(a));if(i.length===0)throw Error(`not installed: ${o.join(", ")} — \`ttheme list\` marks what is`);let s={...r,palettes:r.palettes.filter((a)=>!i.includes(a))};Ke(e,n,r,s),es(e,n,r.terminals,i);for(let a of i)console.log(` - ${a}`);if(Vl(s.palettes.length),o.length>0)return console.error(`ttheme remove: not installed: ${o.join(", ")}`),1;return 0}function PE(t){let e=Q(),n=dt(e),r=W(e);if(!r.palettes.includes(t))throw Error(`${t} is not installed — \`ttheme add ${t}\` first`);let{off:i,...o}=r,s=Ke(e,n,r,{...o,startup:t},!0);console.log(TE(t,r.terminals,s).join(`
732
+ `))}function NE(){let t=Q(),e=W(t),n=Fi(e);if(!n)throw Error("no palettes installed — `ttheme browse` picks some");if(!e.off){console.log(`Already on · ${n}`);return}let{off:r,...i}=e,o=Ke(t,dt(t),e,i);console.log(TE(n,i.terminals,o).join(`
733
+ `))}function AE(){let t=Q(),e=W(t);if(e.off){console.log("Already off");return}let n=Ke(t,dt(t),e,{...e,off:!0}),r=Fi(e);console.log(`Off · new tabs open in the terminal's own colors${r?` — \`ttheme on\` wears ${r} again`:""}`);for(let i of $t(e.terminals))if(n.get(i.id)?.restart)console.log(`${i.name} new tabs open on your own profile once ${i.name} restarts`)}function TE(t,e,n){let r=$t(e).filter((o)=>!o.defaults),i=r.length>0?[`Default ${t} · ${r.map((o)=>o.name).join(", ")} open new tabs with it once their config reloads`]:[];for(let o of $t(e)){let s=o.defaults?.profile(t);if(s)i.push(n.get(o.id)?.restart?`${o.name} new tabs open with it once ${o.name} restarts — "${s}" is now its default profile`:`${o.name} new tabs open with it — "${s}" is its default profile`)}return i.length>0?i:[`Default ${t} · no terminal is wired to open with it — \`ttheme init\` wires one`]}function HE(t,e){let n=new Map(e.palettes.map((r)=>[r.name,"market"]));for(let r of Jc(t,e.palettes,!1))n.set(r.name,"mine");return n}function CE(t,e=!1){let n=Q(),r=dt(n),i=new Set(W(n).palettes),o=HE(n,r),s=It(Rt(n,r).palettes);if(t)Mi(s);let a=ki(t?$$(s,t):s),c=(d)=>o.get(d)??"kept";if(e){let d=a.map((f)=>({name:f.name,group:f.group,...f.catalog?{catalog:f.catalog}:{},installed:i.has(f.name),source:c(f.name)}));console.log(JSON.stringify(d,null,2));return}let u=Math.max(...a.map((d)=>d.name.length),0),l={market:"",mine:" · yours",kept:" · in no market you added"};for(let d of a){let f=d.catalog?`${d.group} / ${d.catalog}`:d.group;console.log(` ${i.has(d.name)?"●":"○"} ${d.name.padEnd(u)} ${f}${l[c(d.name)]}`)}if(process.stdout.isTTY){let d=t?`${a.length} of ${s.length}`:`${s.length}`;console.log(`
734
+ ${d} palettes — ${a.filter((f)=>i.has(f.name)).length} installed`)}}async function LE(){let t=Q(),e=jo(t);if(e.length===0)console.log("No markets to update — `ttheme market add official` brings the ttheme catalog back");let n=(h,m)=>`${km(h,m)} — kept the copy from the last update`;for(let h of e.filter(ut))try{console.log(` ${g1(t,h)}`)}catch(m){console.log(` ${n(h,m)}`)}let r=e.filter((h)=>!ut(h)),i=new Set(r),o=[],s=Jr(),a=()=>s.set(`Updating ${[...i].map(nt).join(", ")}${r.length>1?` · ${r.length-i.size}/${r.length}`:""}`);a(),await Promise.all(r.map(async(h)=>{let m=await $m(t,h),g;if("refreshed"in m){g=ym(m.refreshed);let b=Sm(m.refreshed);if(b)o.push(b)}else g=n(h,m.failure);if(i.delete(h),i.size>0)a();else s.done();s.say(` ${g}`)})),s.done();for(let h of o)console.log(h);if(!I8(Dn(t)))return;for(let h of Em(t))console.log(` ${h}`);let c=dt(t),u=W(t),l=HE(t,c),d=u.palettes.filter((h)=>!l.has(h)),f=new Map(Jn(t).map((h)=>[h.name,h.pictures]));qt(t,c,u);for(let h of d)console.log(` ${h} left its market — ttheme keeps the copy you have`);await nr(t,Rt(t,c,!1).palettes.filter((h)=>u.palettes.includes(h.name)&&f.has(h.name)).map((h)=>os(h,f.get(h.name))),u.terminals)}async function Yp(t,e,n,r=!1){let i=process.env.TTHEME_SORT==="series"?t.palettes:ki(t.palettes);Mi(i);let o=process.stdout.isTTY===!0,s=Es(process.env,o,Q()),a=s?await s.saved():new Map,c=new Bm({entries:i,scope:n,installed:e,required:r,color:!Pt(),fx:cl(process.env.TTHEME_FX),onFocus:s?(l)=>process.stdout.write(s.paint(l)):void 0}),u=await c.prompt();if(s)process.stdout.write(s.restore(a));if(u==="cancel")return;return t.palettes.filter((l)=>c.picked.has(l.name)).map((l)=>l.name)}function Vp(t,e,n,r){let i=n===q?void 0:Ma(t,n),o;try{o=i?.id??cs(t,n)}catch{o=ae(n)?Pr(n):nt(n)}return{source:n,id:o,...i?.info.description?{description:i.info.description}:{},shown:nt(n),entries:n===q?Wi(t,n):i?.entries??[],auto:Nr(n,e.updates),status:Nm(t,n,r)}}function Jp(t){return t instanceof Error?t.message:String(t)}function A8(t,e,n,r){let i=new Map(r.map((a)=>[a.source,a.id])),o=[],s=(a,c)=>o.push({where:a,message:c});for(let a of Bt(e.markets)){let c=i.get(a)??nt(a),u=n[a],l=ya(t,a);if(u&&(l===void 0||u.at>l))o.push({where:c,source:a,update:!0,message:`Update failed ${Ea(u.at)}: ${u.error}`});if(a===q)try{en(N8(Re(t),"utf8"))}catch(d){o.push({where:c,source:a,message:`${nt(Re(t))}: ${Jp(d)}`})}else if(ae(a))if(!P8(Be(t,a)))o.push({where:c,source:a,message:"No copy of it yet — `ttheme update` fetches it"});else try{Yn(a,tn(t,a),Wi(t,q),s)}catch(d){o.push({where:c,source:a,message:`${nt(Be(t,a))}: ${Jp(d)}`})}else try{Xe(a,ce(Ge(a)),Wi(t,q),(d,f)=>s(nt(d),f))}catch(d){o.push({where:c,message:Jp(d)})}}return o}function T8(t,e,n,r,i){return{refresh:async(o)=>{if(ut(o)){let a=Vp(t,e,o,rr());return{market:a,refreshed:{source:o,id:a.id,count:It(a.entries).length,change:{added:[],changed:[],gone:[]}}}}let s=await wm(t,o,gm);return{market:Vp(t,e,o,rr()),refreshed:s}},fetch:async(o)=>{if(ut(o)){let a=Ge(o),c=ce(a);return{source:o,id:c,...a.description?{description:a.description}:{},shown:nt(o),entries:Xe(o,c,Wi(t,q),ue(!1)),auto:!1,status:"read in place"}}let s=await Sa(t,o,void 0,r);return n.set(o,s),{source:o,id:s.id,..."info"in s&&s.info.description?{description:s.info.description}:{},shown:nt(o),entries:s.entries,auto:Nr(o,{}),status:"not added yet"}},search:(o)=>Tm(o,r),apply:i}}async function Zp(...t){for(let e of await Mm(...t))Yr(e)}function H8(t,e,n){let r=[];for(let i of t.adds){let o=i.source!==q&&(t.auto[i.source]??i.auto);r.push(`Added ${i.id} · ${i.shown} — ${Tt(It(i.entries).length)}${o?", updating on its own":""}`)}for(let i of t.removes){let o=e.find((a)=>a.source===i)?.id??i;r.push(`Removed ${o} · ${nt(i)}`);let s=n.filter((a)=>(lt(a)??q)===o);if(s.length>0)r.push(Pm(s))}for(let[i,o]of Object.entries(t.auto)){let s=e.find((a)=>a.source===i);if(s&&!t.removes.includes(i))r.push(`${s.id} ${o?"updates on its own now":"no longer updates on its own"}`)}return r}async function C8(t,e,n,r,i){let o=W(t),s=r.adds.length+r.removes.length+Object.keys(r.auto).length>0;for(let w of r.adds){let k=i.get(w.source);if(k)as(t,k)}for(let w of r.removes)Rm(t,w);let a=[...Bt(o.markets).filter((w)=>!r.removes.includes(w)),...r.adds.map((w)=>w.source)],c=Ia(o,a,{...o.updates,...r.auto});if(s)We(t,c);let u=dt(t,!1),l=Rt(t,u,!1).palettes.filter((w)=>r.picked.has(w.name)).map((w)=>w.name),d=o.palettes.filter((w)=>!l.includes(w)),f=l.filter((w)=>!o.palettes.includes(w));if(!s&&f.length===0&&d.length===0){await Zp(t,o,e,r.refreshed),Yr("Nothing changed");return}let h={...c,palettes:l};Ke(t,u,o,h),es(t,u,o.terminals,d);for(let w of H8(r,n,l))Yr(w);for(let w of f)Yr(` + ${w}`);for(let w of d)Yr(` - ${w}`);let m=new Map(e.map((w)=>[w.name,w.pictures])),g=new Set(r.refreshed.flatMap((w)=>[...w.change.changed,...w.change.gone])),b=Rt(t,u,!1).palettes;if(await nr(t,[...b.filter((w)=>f.includes(w.name)),...b.filter((w)=>l.includes(w.name)&&!f.includes(w.name)&&g.has(w.name)&&m.has(w.name)).map((w)=>os(w,m.get(w.name)))],h.terminals),f.length>0||d.length>0)Vl(h.palettes.length)}async function FE(){let t=O$(process.env),e=Q(),n=W(e),r=Jn(e),i=rr(),o=Bt(n.markets).map((w)=>Vp(e,n,w,i)),s=new Set(o.flatMap((w)=>w.entries.map((k)=>k.name))),a=r.filter((w)=>n.palettes.includes(w.name)&&!s.has(w.name));Mi([...o.flatMap((w)=>w.entries),...a]);let c=new Map,u=new AbortController,l=process.stdout.isTTY===!0,d=Es(process.env,l,e),f=d&&!t?await d.saved():new Map,h=Ae(n);if(t)process.stdout.write("\x1B[?2026h");let m=new Wm({markets:o,kept:a,installed:n.palettes,...h?{startup:h}:{},...t?{hub:t}:{},problems:A8(e,n,i,o),due:bm(e,n),io:T8(e,n,c,u.signal,(w,k)=>Ny({say:k.say,set:k.status},()=>C8(e,r,o,w,c))),...process.env.TTHEME_SORT==="series"?{}:{order:ki},color:!Pt(),lookups:process.env.TTHEME_MARKET_LOOKUP!=="off",fx:cl(process.env.TTHEME_FX),owns:l&&!t,...d?{onFocus:(w)=>process.stdout.write(d.paint(w))}:{}});try{await m.run()}finally{if(d?.stop?.(),d&&!t)process.stdout.write(d.restore(f));u.abort()}await m.idle();let g=m.result(),b=m.next();if(t&&b!==void 0)return await Zp(e,W(e),r,g.refreshed),b;if(l&&t)process.stdout.write("\x1B[?1049l\x1B[?25h");for(let w of g.refreshed){let k=vm(w);if(k)console.log(k)}if(m.applied()){for(let k of m.lines())console.log(k);let w=m.failure();if(w)throw w}else await Zp(e,W(e),r,g.refreshed),console.log("Nothing changed");return t?iu:0}import{rmSync as jE}from"node:fs";import{basename as L8,join as ac}from"node:path";var _E=ac(import.meta.dirname,".."),F8=ac(_E,"themes"),Qp=ac(_E,"dist"),Zl=Zt.map((t)=>On[t].emitter),j8=[Rh,Ch],tq=Zl.map((t)=>t.id);async function Ql({only:t}={}){if(typeof Bun>"u")throw Error("needs bun — run it from a checkout: bun src/bin.ts build");let e=t&&t.length>0?Zl.filter((o)=>t.includes(o.id)):Zl,n=Qw(F8),r=Dg(n);if(r.length>0){for(let o of r)console.error(` ✗ ${o.theme} [${o.rule}] ${o.detail}`);throw Error(`${r.length} contrast violation(s). Fix the palette, or waive the rule in its [contrast] section with a reason.`)}if(e.length===Zl.length)jE(Qp,{recursive:!0,force:!0});else for(let o of e)jE(ac(Qp,o.id),{recursive:!0,force:!0});let i=0;for(let o of[...e,...j8]){let s=n.flatMap((u)=>o.emit?.(u)??[]),a=o.emitShared?.(n)??[];for(let u of[...s,...a])await Bun.write(ac(Qp,u.path),u.content),i++;let c=s.length>0?`${n.length} themes${o.limits?` (${o.limits})`:""}`:a.length>0?a.map((u)=>L8(u.path)).join(" "):`no files (${o.limits??"nothing to write"})`;console.log(` ${o.id.padEnd(16)} ${c}`)}console.log(`
735
+ ${n.length} themes (${Xw(n).length} in the new-tab rotation) -> ${i} files in dist/`)}import{existsSync as G8,readFileSync as KE}from"node:fs";import{availableParallelism as _8,homedir as BE}from"node:os";var B8=4;async function Xl(t,e,n=BE()){let r=Ot(V(t)),i=Ur(t),o=new Map(he(t).palettes.map((d)=>[d.name,Ro(d)])),s=Object.entries(r.palettes).flatMap(([d,f])=>{let h=o.get(d);return h?f.pictures.filter((m)=>Po(m)||(m.blur??0)!==i).map((m)=>({name:d,key:m.key,paint:h})):[]});if(s.length===0)return 0;e(`Drawing ${s.length} background picture${s.length===1?"":"s"} again${i?` · blur ${i}px`:""}`);let a=ji(W(t).terminals),c=new xp(Math.min(B8,_8()-1)),u=await c.map(s.map(({name:d,key:f,paint:h})=>({job:"redraw",home:t,user:n,name:d,key:f,paint:h,blur:i,aligns:a})));c.close();let l=[];return u.forEach((d,f)=>{let{name:h,key:m}=s[f];if(d instanceof Error||d===null){e(` ▢ ${h} ${m} — ${d instanceof Error?d.message:"no original to draw it from"}, left as it was`);return}l.push({name:h,picture:d})}),yf(t,l),Te(t,n),l.length}async function GE(t,e,n,r,i=BE()){let o=Ot(V(t)).palettes[e],s=o?.pictures.find((l)=>l.key===(r??o.active));if(!o||!s)throw Error(`${e} has no picture ${r??"shown"}`);if(_e(s)===n)return{key:s.key,changed:!1};let a=he(t).palettes.find((l)=>l.name===e);if(!a)throw Error(`no palette called ${e}`);let c=ji(W(t).terminals),u=await Qu(t,e,s.key,Ro(a),Ur(t),c,i,n);if(!u)throw Error(`${e} ${s.key} has no original to draw it from`);return yf(t,[{name:e,picture:u}]),Te(t,i),{key:s.key,changed:!0}}function UE(t,e,n){let r=Ot(V(t)).palettes[e],i=r?.pictures.find((a)=>a.key===(n??r.active));if(!r||!i)throw Error(`${e} has no picture ${n??"shown"}`);let o=he(t).palettes.find((a)=>a.name===e);if(!o)throw Error(`no palette called ${e}`);let s=_e(i)==="original"?"tone":"original";if(!Fy(t,e,i.key,Ro(o),Ur(t),s))throw Error(`${e} ${i.key} has no original to draw it from`);return{key:i.key,coloring:s}}async function WE(){return await Xl(Q(),(t)=>process.stderr.write(`${t}
736
+ `)),0}async function zE(t,e,n){let r=Q();if(Tr(he(r).palettes,t),e==="show"){if(!n)throw Error("image show needs the picture to show");let{at:i,of:o}=No(r,t,n);return Te(r),process.stderr.write(`Background · ${t} ${i}/${o} ${n}
737
+ `),0}if(e==="drop"){let{key:i,left:o}=Fc(r,t,n);return Te(r),process.stderr.write(`Background · ${t} removed ${i} · ${o} left
738
+ `),0}if(e==="tone"||e==="original"){let i=await GE(r,t,e,n);return process.stderr.write(`Background · ${t} ${i.key} ${e==="tone"?"tinted":"in its own colors"}
739
+ `),0}if(e==="prepare"){let{key:i,coloring:o}=UE(r,t,n);return process.stderr.write(`Background · ${t} ${i} ready in ${o==="tone"?"its tone":"its own colors"}
740
+ `),0}if(e==="tuned")return Te(r),0;throw Error(`unknown image action ${e} — show, drop, tone, original, prepare or tuned`)}function DE(t,e){let n=/^(\d+)x(\d+)$/.exec(t),r=/^(\d+)x(\d+)([+-]\d+)([+-]\d+)$/.exec(e);if(!n||!r)throw Error("a canvas is <width>x<height> and a place <width>x<height>+<x>+<y>");let[i,o]=n.slice(1).map(Number),[s,a,c,u]=r.slice(1).map(Number);return{width:i,height:o,at:{x:c,y:u,w:s,h:a}}}function U8(t,e,n){let r=DE(e,n),i=Math.min(1,t.width/r.at.w);if(i===1)return r;return{width:Math.max(1,Math.round(r.width*i)),height:Math.max(1,Math.round(r.height*i)),at:{x:Math.round(r.at.x*i),y:Math.round(r.at.y*i),w:t.width,h:t.height}}}function qE(t,e,n,r){let i=jt(new Uint8Array(KE(t)));return F(e,je(Qb(i,DE(n,r)))),0}function YE(t,e,n,r,i,o,s){let a=Number(r);if(!le(n)||!Number.isFinite(a))throw Error("flatten needs a #rrggbb background and an opacity from 0 to 1");let c=jt(new Uint8Array(KE(t))),u=i?U8(c,i,o??""):void 0,l=yr(kr(c,n,Math.max(0,Math.min(1,a)),u));if(s&&G8(s))li(s,e,l);else F(e,l);return 0}import{execFileSync as W8}from"node:child_process";import{readFileSync as K8}from"node:fs";import{arch as z8,platform as td,release as Xp}from"node:os";var D8={ghostty:"ghostty",iterm2:"iTerm.app",wezterm:"WezTerm","terminal-app":"Apple_Terminal",warp:"WarpTerminal"};function q8(t,e){if(t==="konsole"){let r=/^(\d{2})(\d{2})(\d{2})$/.exec(e.KONSOLE_VERSION??"");return r?`${r[1]}.${r[2]}.${Number(r[3])}`:e.KONSOLE_VERSION}let n=D8[t];return n!==void 0&&e.TERM_PROGRAM===n?e.TERM_PROGRAM_VERSION:void 0}function Y8(t){let e=Dt(t),n=t.TERM_PROGRAM&&t.TERM_PROGRAM!=="tmux"?t.TERM_PROGRAM:void 0,r=e==="unknown"?`unknown${n?` (TERM_PROGRAM=${n})`:""}`:e==="editor"?`editor (${yh(t)})`:`${e} ${q8(e,t)??"(version unknown)"}`,i=t.TERM_PROGRAM==="tmux"?t.TERM_PROGRAM_VERSION:void 0;return[r,t.TMUX?`tmux ${i??"yes"}`:"tmux no",t.SSH_CONNECTION||t.SSH_TTY?"ssh yes":"ssh no"].join(" · ")}function JE(t,e){try{return W8(t,e,{encoding:"utf8",timeout:2000,stdio:["ignore","pipe","ignore"]}).trim()}catch{return}}function J8(){let t=z8();if(td()==="darwin")return`macOS ${JE("sw_vers",["-productVersion"])??`(Darwin ${Xp()})`} · ${t}`;if(td()==="linux"){let e="";try{e=K8("/etc/os-release","utf8")}catch{}return`${/^PRETTY_NAME="?([^"\n]*)"?$/m.exec(e)?.[1]??"Linux"} · linux ${Xp()} · ${t}`}return`${td()==="win32"?"Windows":td()} ${Xp()} · ${t}`}function V8(t){if(t.TTHEME_ZSH)return`zsh ${t.TTHEME_ZSH}`;return(t.SHELL?JE(t.SHELL,["--version"])?.split(`
741
+ `)[0]:void 0)??t.SHELL??"unknown"}function Z8(t){try{let{terminals:e}=W(t);return e.length>0?e.join(", "):"none"}catch{return"installed.json missing or unreadable"}}function Q8(t){let e=yu.flatMap((n)=>{let r=t[n];return r===void 0||r===da(n)?[]:[`${n}=${/\s/.test(r)?JSON.stringify(r):r}`]});return e.length>0?e.join(" "):void 0}function VE(){let t=process.env,n=[["ttheme",At.version],["OS",J8()],["Shell",V8(t)],["Terminal",Y8(t)],["Wired",Z8(Q())],["Settings",Q8(t)]].filter((i)=>i[1]!==void 0),r=Math.max(...n.map(([i])=>i.length));for(let[i,o]of n)console.log(`${i.padEnd(r)} ${o}`)}import{execFileSync as X8,spawnSync as t5}from"node:child_process";import{chmodSync as e5,copyFileSync as n5,existsSync as io,mkdirSync as ZE,readdirSync as r5,readFileSync as nd,rmSync as tg}from"node:fs";import{homedir as i5}from"node:os";import{dirname as Ms,join as gt}from"node:path";function o5(t,e,n){for(let r of r5(e))t.push({from:gt(e,r),to:gt(n,r)})}function ig(t){return en(nd(gt(t,"dist","manifest.json"),"utf8"))}function ed(t,e){let n=gt(e.configHome,"ttheme"),r=[{from:gt(e.root,"bin","ttheme.js"),to:gt(n,"ttheme.js")},{from:gt(e.root,"bin","ttheme.js.map"),to:gt(n,"ttheme.js.map")},{from:gt(e.root,"shell","ttheme.zsh"),to:gt(n,"ttheme.zsh")},{from:gt(e.root,"shell","preview.zsh"),to:gt(n,"preview.zsh")},{from:gt(e.root,"shell","launch-tab.zsh"),to:gt(n,"launch-tab.zsh"),executable:!0}];o5(r,gt(e.root,"shell","adapters"),gt(n,"adapters"));let i=[{file:gt(e.zdotdir,".zshrc"),block:hk(n)}],o=gt(n,"config.zsh"),s=pk(io(o)?nd(o,"utf8"):""),a={file:o,content:t.warpFast===void 0?s:Eu(s,"TTHEME_WARP_FAST",t.warpFast?"on":"off")},c={terminals:t.terminals,palettes:t.palettes,...Object.fromEntries($t(t.terminals).flatMap((d)=>Object.entries(d.installs?.(e)??{}).filter(([,f])=>f!==void 0))),...t.off?{off:!0}:{}},u=zu(e.configHome,c,e.home),l=e.stateDir?[gt(e.stateDir,"ghostty",".blind")]:[];return{home:e.home,copies:r,edits:i,settings:a,forget:l,catalog:ig(e.root),installed:c,notes:u}}function XE(t){try{return W(t)}catch{return}}function tM(t,e){try{return Rt(t,dt(t,!1,e),!1).palettes}catch{return[]}}function s5(t,e){let n=ig(e.root),r=Bt(t.markets).includes(q)?n.palettes:[],i=new Set(r.map((s)=>s.name)),o=tM(e.configHome,n).filter((s)=>!i.has(s.name)&&(lt(s.name)!==void 0||t.palettes.includes(s.name)));return{...n,palettes:[...r,...o]}}function eM(t,e){let n=Fi(t);return n&&e.includes(n)?n:void 0}function a5(t,e,n){let r=ed(e,n),i=eM(t,e.palettes),o=new Set(["terminals","palettes","off","startup",...Zt.flatMap((a)=>Object.keys(On[a].installs?.(n)??{}))]),s=Object.fromEntries(Object.entries(t).filter(([a])=>!o.has(a)));return{...r,installed:{...s,...r.installed,...i?{startup:i}:{}}}}function c5(t,e){let n=ed({terminals:t.terminals,palettes:t.palettes,off:t.off},e),r=new Set([...n.catalog.palettes,...tM(e.configHome,n.catalog)].map((l)=>l.name)),i=t.palettes.filter((l)=>r.has(l)),o=t.palettes.filter((l)=>!r.has(l)),{startup:s,...a}=t,c={...a,palettes:i,...s&&i.includes(s)?{startup:s}:{}},u=o.length>0?[`Dropped ${o.join(", ")} — no longer in the catalog`,...n.notes]:n.notes;return{...n,installed:c,notes:u}}function u5(t){try{return X8(process.execPath,[gt(t,"ttheme","ttheme.js"),"--version"],{encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim()||void 0}catch{return}}function nM(t){let e=Ae(t);return[$t(t.terminals).map((n)=>n.name).join(", "),`${t.palettes.length} palettes`,e?`default ${e}`:"no default — ttheme is off"].join(" · ")}function eg(t,e=on()){for(let s of t.copies)if(ZE(Ms(s.to),{recursive:!0}),tg(s.to,{force:!0}),tg(`${s.to}.zwc`,{force:!0}),n5(s.from,s.to),s.executable)e5(s.to,493);F(t.settings.file,t.settings.content);for(let s of t.forget)tg(s,{force:!0});let n=Ms(Ms(t.settings.file)),r=XE(n),i=Object.fromEntries($t(t.installed.terminals).flatMap((s)=>{let a=s.defaults?.key,c=a?r?.[a]:void 0;return a&&c?[[a,c]]:[]})),o=$a(n,{...t.installed,...i},e,t.home);if(Bt(o.markets).includes(q))Qc(n,t.catalog);We(n,o),qt(n,dt(n),o,t.home,e);for(let s of t.edits){ZE(Ms(s.file),{recursive:!0});let a=io(s.file)?nd(s.file,"utf8"):"";bn(s.file,_r(a,s.block))}return _i(n,o,!0,e,t.home)}function cc(t){if(me(t))throw Fr("Nothing changed"),new He;return t}function ng(t,e){return Zt.filter((n)=>On[n].offered(t,e))}async function l5(t,e,n,r){return cc(await tk({message:"Wire which terminals?",options:ng(n,r).map((i)=>({value:i,label:On[i].name,hint:i===t?"detected":void 0})),initialValues:e,required:!0}))}async function d5(t){return cc(await nn({message:"Switch Warp to each tab's palette in about 0.2 s instead of 0.6 s?\nAbout 8% CPU while Warp is in front with tabs of different palettes — `ttheme config` changes it",initialValue:vu(t,"TTHEME_WARP_FAST")!=="off"}))}function rg(t){let e=[...t.copies.filter((n)=>!io(n.to)).map((n)=>n.to),...io(t.settings.file)?[]:[t.settings.file],...t.edits.filter((n)=>!nd(n.file,"utf8").includes("# ttheme begin")).map((n)=>n.file)];if(e.length>0)throw Error(`init left gaps:
741
742
  ${e.join(`
742
- `)}`)}function EE(t,e){return[...new Set(t.palettes.filter((n)=>e.includes(n.name)).map((n)=>n.group))]}function yL(t,e,n){let r=t.palettes.find((o)=>o.name===Ie(e)),i=process.stdout.isTTY===!0,s=r&&zr(process.env,i,n)?.wear(r,e.terminals);if(s===void 0)return!1;return process.stdout.write(s),!0}function vL(t,e){let n=Ie(t);if(!n)return["Default none — new tabs keep the terminal colors",`Turn on \`ttheme on\` wears ${Oi(t)}`];return[`Default ${n}${e?" — this tab wears it already":""}`,"Change it `ttheme preview`, enter on a palette, then default"]}function EL(t){uL("zsh",["-c",'source "$1" && __tt_preview init',"zsh",mt(t,"ttheme","ttheme.zsh")],{stdio:"inherit"})}function SL(t,e,n,r){let i=EE(t.catalog,e.palettes);bn([`${i.join(", ")} (${e.palettes.length})`,...vL(t.installed,n)].join(`
743
- `),`Installed ${e.palettes.length} palettes`),bn(["exec zsh The ttheme command in this tab",...up(t,r)].join(`
744
- `),"Next"),Go("Done")}function up(t,e){return[...Mu(oo(oo(t.settings.file)),t.installed,e,t.home),...t.notes]}function SE(t){return t?(e)=>Sr.step(e):(e)=>console.log(e)}async function wE(t,e,n,r){let i=bL(t,e),s=sp(i,n);ap(i),await $l(e.configHome,SE(r),e.home);let o=["exec zsh Open tabs run the new layer — new tabs already do",...up(i,s)],a=`Updated to ${It.version} — kept ${vE(i.installed)}`;if(!r){console.log([a,...o].join(`
745
- `));return}bn(o.join(`
746
- `),a),Go("Done")}function ML(t,e){let n=[`Placed ${t.copies.length} files`,`Settings in ${t.settings.file} — edit later with \`ttheme config\``,...t.edits.map((r)=>`Wired ${r.file}`),...up(t,e),"No palettes yet — open a new shell (`exec zsh`), then `ttheme browse` picks them from the catalog"];console.log(n.join(`
747
- `))}async function ME(t={}){let e=mt(import.meta.dirname,"..");if(!zi(mt(e,"bin","ttheme.js")))throw Error("bin/ttheme.js is missing — run `mise run bin:build` first");if(!zi(mt(e,"dist"))){if(typeof Bun>"u")throw Error("this package is missing dist/ — reinstall @kecan0406/ttheme");await wl()}let n=hL(),r=J(),i=process.env.ZDOTDIR??n,s=Ze(),o=bk(s),a=process.env.WT_PROFILE_ID,c={root:e,home:n,configHome:r,zdotdir:i,stateDir:mt(process.env.XDG_STATE_HOME??mt(n,".local","state"),"ttheme"),...o?{wtHome:o}:{},...a?{wtProfile:a}:{}},u=Kt(process.env),l=op(c,s).filter((N)=>N===u||$n[N].present(c));if(!t.yes&&(process.stdin.isTTY!==!0||process.stdout.isTTY!==!0))throw Error("init asks before it edits your configs — run it in a terminal, or pass --yes to accept the defaults");let f=$E(r);if(t.yes&&f){await wE(f,c,s,!1);return}if(t.yes){if(l.length===0)throw Error(`no supported terminal detected — run this inside ${pt(op(c,s)).map((B)=>B.name.toLowerCase()).join(", ").replace(/, ([^,]*)$/," or $1")}`);let F=yl({terminals:l,palettes:[]},c),_=sp(F,s);ap(F),ML(F,_);return}if(zc("ttheme init"),f){let N=wL(r);if(Ha(await Ve({message:`ttheme${N?` ${N}`:""} is installed — ${vE(f)}
748
- ${N===It.version?"Reinstall":"Update to"} ${It.version} and keep all of it?`,active:"Yes",inactive:"No, set it up again",initialValue:!0}))){await wE(f,c,s,!0);return}}let d=await $L(u,f?.terminals??l,c,s),h=d.includes("warp")?await kL(r):void 0,m=f?pL(f,c):cp(e),$=f?await Qm(m,f.palettes,"palette",!0):await Qm(m,[],"series",!0);if(!$)throw Mr("Nothing changed"),new Ne;let g=(f&&yE(f,$))??$[0],b=$.length>1&&(de[u].paints||u==="warp"&&d.includes("warp")&&zi(Fr(n,r))),y=Ha(await Ve({message:b?"Pick a default palette in ttheme preview once installed?":`Wear ${g} in every tab?`,initialValue:f?!f.off:!0})),E={terminals:d,palettes:$,off:!y,warpFast:h},S=f?gL(f,E,c):yl(E,c);if(bn([`Install ${$.length} palettes — ${EE(m,$).join(", ")}`,`Copy ${S.copies.length} files under ${r}`,`Write ${S.settings.file}`,...S.edits.map((N)=>`Edit ${N.file} — a ttheme block: source ttheme.zsh`),...Eu(r,S.installed,n),"Each config is backed up once to <file>.ttheme.bak before the first edit — `npx @kecan0406/ttheme uninstall` takes it all out",y?b?`Open ttheme preview — every tab wears the palette picked there, ${g} until then`:`Paint every tab with ${g}, this one now`:"Leave the terminal colors as they are — `ttheme on` wears a palette later",...y&&g?pt(d).flatMap((N)=>N.defaults?[`Make "${N.defaults.profile(g)}" the ${N.name} default profile`]:[]):[]].join(`
749
- `),`Wiring ${pt(d).map((N)=>N.name).join(", ")}`),!Ha(await Ve({message:"Apply these changes?"})))throw Mr("Nothing changed"),new Ne;let x=sp(S,s);if(ap(S),await $l(r,SE(!0),n),y&&b)EL(r);let R=L(r);SL({...S,catalog:m,installed:R},E,yL(m,R,r),x)}import{spawn as OL}from"node:child_process";import{createHash as xL}from"node:crypto";import{existsSync as lp,mkdirSync as IL,readFileSync as RL,statSync as NL,utimesSync as TL,writeFileSync as AL}from"node:fs";import{homedir as RE}from"node:os";import{join as NE}from"node:path";import{gunzipSync as PL}from"node:zlib";var OE="https://github.com/kecan0406/aninames/releases/latest/download",TE=86400000,HL=3600000,FL=120000;function AE(t){return NE(wr(t),".checked")}function CL(t=process.env){return t.TTHEME_NAMES!=="off"}function LL(t){try{return Date.now()-NL(AE(t)).mtimeMs>=TE}catch{return!0}}function fp(t,e){let n=AE(t);if(IL(wr(t),{recursive:!0}),!lp(n))AL(n,"");TL(n,e/1000,e/1000)}function PE(t=RE()){if(!CL()||!LL(t))return;try{fp(t,Date.now()),OL(process.execPath,[process.argv[1],"names"],{detached:!0,stdio:"ignore",env:process.env}).unref()}catch{}}function xE(t){return xL("sha256").update(t).digest("hex")}async function IE(t){let e=await fetch(t,{signal:AbortSignal.timeout(FL)});if(!e.ok)throw Error(`${t} answered ${e.status}`);return new Uint8Array(await e.arrayBuffer())}async function HE(t=RE()){let e=wr(t);try{let r=JSON.parse(new TextDecoder().decode(await IE(`${OE}/ttheme.json`)));for(let[i,{file:s,sha256:o}]of Object.entries(r.layers)){let a=NE(e,`ttheme-${i}.json`);if(lp(a)&&xE(RL(a))===o)continue;let c=PL(await IE(`${OE}/${s}`));if(xE(c)!==o)throw Error(`${s} does not match its hash`);P(a,c)}fp(t,Date.now())}catch{return fp(t,Date.now()-TE+HL),1}wc(t);let n=J();if(lp(Me(n)))hi(ue(n).palettes,t),Ek(n,t);return 0}import{createInterface as jL}from"node:readline";var _L="\x1F",dp="\x1E",GL=new Set(["up","down","left","right","home","end","pgup","pgdn","tab","shift-tab","shift-left","shift-right","enter","esc","backspace","ctrl-c"]);function BL([t="",e="",n="",r=""]){if(t!=="press"&&t!=="drag"&&t!=="release"&&t!=="wheel"||!/^\d+$/.test(e)||!/^\d+$/.test(n)||!/^-?\d+$/.test(r))return;return{kind:"mouse",action:t,button:t==="wheel"?void 0:"left",wheel:t==="wheel"?Number(r)<0?-1:1:0,sideways:!1,row:Number(e),col:Number(n),shift:!1,alt:!1,ctrl:!1,count:t==="press"||t==="release"?Number(r):0}}function FE(t){return{background:t.background,foreground:t.foreground,cursor:t.cursor,selection:t.selection,ansi:t.ansi}}class CE{editor;base;cols=Bm;rows=Um;focused=!0;home;name;color;shown="";tints=new Oa;pointer=new jo;drawn={key:"",recolors:!1,look:""};constructor(t,e,n){this.home=t,this.name=e,this.color=n,this.base=_n(gi(t,ut(t),!1).palettes,e);let r=xs(this.base,pn(t)[e]);this.editor=new Sa({title:"Tone",name:e,colors:FE(r),original:FE(this.base),variant:"theme",signature:r.signatureSlots,...r.waived?{waive:r.waived}:{},check:()=>{return}})}save(){try{let t=fd(this.base,this.editor.list);ld(this.home,m0(pn(this.home),this.name,t)),jt(this.home,ut(this.home),L(this.home)),this.editor.markSaved();return}catch(t){return t instanceof Error?t.message:String(t)}}close(){this.tints.clear()}pictures(){try{return kt(q(this.home)).palettes[this.name]?.pictures??[]}catch{return[]}}draft(){let t=this.editor.dirty(),e=`${t}
750
- ${this.shown}
751
- ${this.editor.list.join(" ")}`;if(e!==this.drawn.key){let n=this.pictures(),r=br(xs(this.base,fd(this.base,this.editor.list))),i=this.shown?ol(n,this.shown):void 0,s={name:this.name,...this.editor.colors(),waived:this.editor.waive},o=i?sl(i,this.shown,s,this.editor.signature,this.tints):void 0;this.drawn={key:e,recolors:t&&n.some((a)=>cc(a,r)),look:o?`${o.image}${dp}${o.opacity}`:""}}return this.drawn}frame(t="ok",e){let n=a1(this.editor),r=this.editor.act??"-";this.editor.act=void 0;let{drawn:i,targets:s}=Ac(()=>c1(this.editor,this.cols,this.rows,this.color,this.focused)),{lines:o,zones:a}=Pc(i.lines,s);this.pointer.zones=a;let{recolors:c,look:u}=this.draft();return[t,r,n.mode,this.editor.dirty()?"1":"0",this.editor.shown().join(" "),n.keys.map(([l])=>l).join(dp),n.keys.map(([,l])=>l).join(dp),e??n.note,String(i.at),c?"1":"0",u,...o].join(_L)}handle(t){let[e="",...n]=t.split(" "),r=n.join(" ");if(e==="quit")return;if(e==="size"){let[i,s]=r.split(" ").map(Number);this.cols=Math.max(30,i??Bm),this.rows=Math.max(10,s??Um)}else if(e==="focus")this.focused=r==="1";else if(e==="show")this.shown=r;else if(e==="key"&&GL.has(r))this.editor.press(r);else if(e==="ch"){let i=Number(r),s=Number.isInteger(i)&&i>0&&i<=1114111?Xh(String.fromCodePoint(i)):void 0;if(s)this.editor.press(s)}else if(e==="mouse"){let i=BL(n);if(i)Wm(this.editor,this.pointer.point(i),i)}else if(e==="save"){let i=this.save();return i===void 0?this.frame("saved","Saved"):this.frame("error",i)}return this.frame()}}async function LE(t){let e=new CE(J(),t,process.env.NO_COLOR===void 0);process.once("exit",()=>e.close()),process.once("SIGTERM",()=>process.exit(0));let n=jL({input:process.stdin});for await(let r of n){let i=e.handle(r);if(i===void 0)break;process.stdout.write(`${i}
752
- `)}return n.close(),process.stdin.destroy(),e.close(),0}import{existsSync as jE,rmSync as UL,utimesSync as WL}from"node:fs";import{homedir as KL}from"node:os";import{join as Fa}from"node:path";function zL(t){try{return L(t)}catch{return}}function DL(t){let{home:e,configHome:n}=t,r=zL(n),i={configHome:n,home:e},s=pt(qt),o=s.map((c)=>c.unwire(i,r)),a=[Fa(n,"ttheme"),t.cacheDir,t.stateDir];return{edits:[...wn(Fa(t.zdotdir,".zshrc"),Rr),...o.flatMap((c)=>c.edits)],removals:[...s.flatMap((c)=>c.shelf?Ts(c.shelf.dir(i)):[]),...o.flatMap((c)=>c.removals),...a.filter((c)=>jE(c))],touches:o.flatMap((c)=>c.touches),...r?{state:r}:{}}}function qL(t,e,n=Ze()){let r=[];for(let{file:s,content:o}of t.edits){let a=ng(s,o);r.push(a==="removed"?`Removed ${s} — ttheme had created it`:a==="restored"?`Took ttheme out of ${s}`:`Took ttheme out of ${s} — kept ${s}.ttheme.bak, since the file changed after ttheme's first edit`)}if(t.state){let s=Ii(e.configHome,{...t.state,off:!0,palettes:[]},!1,n,e.home);for(let o of pt(t.state.terminals))if(s.has(o.id))r.push(`Gave ${o.name} its own default profile back — it takes it at its next start`)}for(let s of t.removals)UL(s,{recursive:!0,force:!0});if(t.removals.length>0)r.push(`Deleted ${t.removals.length} files and folders ttheme wrote`);let i=new Date;for(let s of t.touches)WL(s,i,i);return r}function YL(){let t=KL();return{home:t,configHome:J(),zdotdir:process.env.ZDOTDIR??t,cacheDir:hr(),stateDir:Fa(process.env.XDG_STATE_HOME??Fa(t,".local","state"),"ttheme")}}async function _E(t=!1){let e=YL(),n=DL(e);if(n.edits.length===0&&n.removals.length===0){console.log("Nothing of ttheme is installed");return}if(!t){if(process.stdin.isTTY!==!0||process.stdout.isTTY!==!0)throw Error("uninstall asks before it deletes anything — run it in a terminal, or pass --yes");let r=Fa(e.configHome,"ttheme");zc("ttheme uninstall"),bn([...n.edits.map((s)=>`Take ttheme out of ${s.file}`),...n.removals.map((s)=>s===r?`Delete ${s} — settings, pins, every installed picture${jE($c(e.configHome))?`, and your markets under ${$c(e.configHome)} (push them to GitHub first to keep them)`:""}`:`Delete ${s}`)].join(`
753
- `),"Uninstall");let i=await Ve({message:"Remove ttheme?"});if(fe(i)||!i)throw Mr("Nothing changed"),new Ne}for(let r of qL(n,e))console.log(r);console.log("Open tabs keep their colors until they close — restart your terminal to drop ttheme everywhere")}import{homedir as JL}from"node:os";async function GE(t){if(!qt.includes(t))throw Error(`no terminal ${t} — one of ${qt.join(", ")}`);let e=t,n=$n[e],r=J(),i=JL(),s=Ze(),o=L(r);if(o.terminals.includes(e))return console.log(`${n.name} is wired already`),0;let a={configHome:r,home:i};if(!n.offered(a,s))throw Error(`${n.name} cannot be wired on this system`);if(process.stdin.isTTY!==!0||process.stdout.isTTY!==!0)throw Error("wire asks before it edits your configs — run it in a terminal");let c={...o,...n.installs?.(a)??{},terminals:[e]};bn([...Eu(r,c,i),...Su(r,c,i),"Each config is backed up once to <file>.ttheme.bak before the first edit — `npx @kecan0406/ttheme uninstall` takes it all out"].join(`
754
- `),`Wiring ${n.name}`);let u=await Ve({message:`Wire ${n.name} now?`,initialValue:!1});if(fe(u)||!u)throw Mr("Nothing changed"),new Ne;let l=ta(r,c,s,i),f={...l,terminals:[...o.terminals,e]};Le(r,f),jt(r,ut(r),f,i,s);let d=Ii(r,l,!0,s,i),h=Mu(r,l,d,i);if(h.length>0)bn(h.join(`
755
- `),"Next");return Go(`Wired ${n.name}`),0}var ZL=new Set(["add","remove","market","default","on","off"]),QL={default:([t])=>V1(t),on:()=>Z1(),off:()=>Q1(),browse:()=>rE(),list:([t],{json:e})=>eE(t,e),add:(t,{market:e})=>Y1(t,e),remove:(t)=>J1(t),update:()=>nE(),market:([t,e])=>my(t,e),new:([t],{from:e,in:n})=>W1(t,e,n),edit:([t])=>K1(t),check:([t],{fix:e})=>D1(t,e),share:([t],{tone:e})=>q1(t,e),init:(t,{yes:e})=>ME({yes:e}),uninstall:(t,{yes:e})=>_E(e),wire:([t])=>GE(t),info:()=>gE(),build:(t,{only:e})=>wl({only:e}),find:([t])=>x1(t),image:([t,e,n])=>fE(t,e,n),redraw:()=>uE(),names:()=>HE(),tone:([t])=>LE(t),flatten:([t,e,n,r,i,s,o])=>mE(t,e,n,r,i,s,o),bake:([t,e,n,r])=>hE(t,e,n,r)},XL=Ko.map((t)=>({...t,run:QL[t.name]}));class Di extends Error{verb;constructor(t,e){super(t);this.verb=e}}function BE(t){let e=XL.find((n)=>n.name===t);if(!e)throw new Di(t.startsWith("-")?`unknown option '${t}'`:`unknown command '${t}'`);return e}function t3(t,e){let n={help:{type:"boolean",short:"h"}};for(let[r,{type:i,short:s,multiple:o}]of Object.entries(t.flags??{}))n[r]={type:i,multiple:o===!0,...s?{short:s}:{}};try{return VL({args:e,options:n,allowPositionals:!0})}catch(r){let[i=""]=(r instanceof Error?r.message:String(r)).split(". ");throw new Di(`${i.charAt(0).toLowerCase()}${i.slice(1)}`,t)}}function e3(t){let[e,...n]=t;if(e===void 0)return{kind:"help",code:1};if(e==="-h"||e==="--help")return{kind:"help",code:0};if(e==="-V"||e==="--version")return{kind:"version"};if(e==="help"){if(n[0]===void 0||n[0]==="all")return{kind:"help",all:n[0]==="all",code:0};return{kind:"help",verb:BE(n[0]),code:0}}let r=BE(e),i=t3(r,n);if(i.values.help)return{kind:"help",verb:r,code:0};for(let[l,{choices:f}]of Object.entries(r.flags??{}))for(let d of[i.values[l]??[]].flat())if(f&&!f.includes(String(d)))throw new Di(`--${l} takes ${f.join(", ")} — not ${d}`,r);let s=i.positionals,o=r.args.filter((l)=>l.startsWith("<")).length,a=r.args.some((l)=>l.includes("..."))?Number.POSITIVE_INFINITY:r.args.length;if(s.length<o)throw new Di(`missing ${r.args[s.length]}`,r);if(s.length>a)throw new Di(`too many arguments: ${s.slice(a).join(" ")}`,r);let{help:c,...u}=i.values;return{kind:"run",verb:r,args:s,flags:u}}function UE(t){let e=Math.max(0,...t.map(([n])=>n.length));return t.map(([n,r])=>` ${n.padEnd(e)} ${r}`)}function hp(t,e=!1){if(!t)return zo(e);let n=Object.entries(t.flags??{}).map(([r,{short:i,value:s,about:o}])=>[`${i?`-${i}, `:""}--${r}${s?` ${s}`:""}`,o]);return[`Usage: ttheme ${Wo(t)}`,"",t.about,...t.actions?["","Actions:",...UE(t.actions)]:[],...n.length>0?["","Options:",...UE(n)]:[]].join(`
756
- `)}var n3=[TypeError,RangeError,ReferenceError,SyntaxError];function r3(t){return n3.some((e)=>t instanceof e)||t instanceof Error&&"code"in t}async function WE(t){let e;try{let n=e3(t);if(n.kind==="version")return console.log(It.version),0;if(n.kind==="help"){if(n.code===0)console.log(hp(n.verb,n.all));else console.error(hp(n.verb,n.all));return n.code}if(e=n.verb,!n.verb.run)throw Error("runs in the shell layer — open a new tab once `ttheme init` has wired it");if(ZL.has(n.verb.name))await Qk();let r=await n.verb.run(n.args,n.flags);if(!n.verb.hidden&&n.verb.name!=="uninstall")PE();return typeof r==="number"?r:0}catch(n){if(n instanceof Di)return console.error(n.verb?`ttheme ${n.verb.name}: ${n.message}
743
+ `)}`)}function rM(t,e){return[...new Set(t.palettes.filter((n)=>e.includes(n.name)).map((n)=>n.group))]}function f5(t,e,n){let r=t.palettes.find((s)=>s.name===Ae(e)),i=process.stdout.isTTY===!0,o=r&&Es(process.env,i,n)?.wear(r,e.terminals);if(o===void 0)return!1;return process.stdout.write(o),!0}function h5(t,e){let n=Ae(t);if(!n)return["Default none — new tabs keep the terminal colors",`Turn on \`ttheme on\` wears ${Fi(t)}`];return[`Default ${n}${e?" — this tab wears it already":""}`,"Change it `ttheme preview`, enter on a palette, then default"]}function m5(t){t5("zsh",["-c",'source "$1" && __tt_preview init',"zsh",gt(t,"ttheme","ttheme.zsh")],{stdio:"inherit"})}function p5(t,e,n,r){let i=rM(t.catalog,e.palettes);Mn([`${i.join(", ")} (${e.palettes.length})`,...h5(t.installed,n)].join(`
744
+ `),`Installed ${e.palettes.length} palettes`),Mn(["exec zsh The ttheme command in this tab",...og(t,r)].join(`
745
+ `),"Next"),sa("Done")}function og(t,e){return[...Du(Ms(Ms(t.settings.file)),t.installed,e,t.home),...t.notes]}function iM(t){return t?(e)=>Lr.step(e):(e)=>console.log(e)}async function QE(t,e,n,r){let i=c5(t,e),o=eg(i,n);rg(i),await Xl(e.configHome,iM(r),e.home);let s=["exec zsh Open tabs run the new layer — new tabs already do",...og(i,o)],a=`Updated to ${At.version} — kept ${nM(i.installed)}`;if(!r){console.log([a,...s].join(`
746
+ `));return}Mn(s.join(`
747
+ `),a),sa("Done")}function g5(t,e){let n=[`Placed ${t.copies.length} files`,`Settings in ${t.settings.file} — edit later with \`ttheme config\``,...t.edits.map((r)=>`Wired ${r.file}`),...og(t,e),"No palettes yet — open a new shell (`exec zsh`), then `ttheme browse` picks them from the catalog"];console.log(n.join(`
748
+ `))}async function oM(t={}){let e=gt(import.meta.dirname,"..");if(!io(gt(e,"bin","ttheme.js")))throw Error("bin/ttheme.js is missing — run `mise run bin:build` first");if(!io(gt(e,"dist"))){if(typeof Bun>"u")throw Error("this package is missing dist/ — reinstall @kecan0406/ttheme");await Ql()}let n=i5(),r=Q(),i=process.env.ZDOTDIR??n,o=on(),s=wy(o),a=process.env.WT_PROFILE_ID,c={root:e,home:n,configHome:r,zdotdir:i,stateDir:gt(process.env.XDG_STATE_HOME??gt(n,".local","state"),"ttheme"),...s?{wtHome:s}:{},...a?{wtProfile:a}:{}},u=Dt(process.env),l=ng(c,o).filter((O)=>O===u||On[O].present(c));if(!t.yes&&(process.stdin.isTTY!==!0||process.stdout.isTTY!==!0))throw Error("init asks before it edits your configs — run it in a terminal, or pass --yes to accept the defaults");let d=XE(r);if(t.yes&&d){await QE(d,c,o,!1);return}if(t.yes){if(l.length===0)throw Error(`no supported terminal detected — run this inside ${$t(ng(c,o)).map((L)=>L.name.toLowerCase()).join(", ").replace(/, ([^,]*)$/," or $1")}`);let H=ed({terminals:l,palettes:[]},c),N=eg(H,o);rg(H),g5(H,N);return}if(pu("ttheme init"),d){let O=u5(r);if(cc(await nn({message:`ttheme${O?` ${O}`:""} is installed — ${nM(d)}
749
+ ${O===At.version?"Reinstall":"Update to"} ${At.version} and keep all of it?`,active:"Yes",inactive:"No, set it up again",initialValue:!0}))){await QE(d,c,o,!0);return}}let f=await l5(u,d?.terminals??l,c,o),h=f.includes("warp")?await d5(r):void 0,m=d?s5(d,c):ig(e),g=d?await Yp(m,d.palettes,"palette",!0):await Yp(m,[],"series",!0);if(!g)throw Fr("Nothing changed"),new He;let b=(d&&eM(d,g))??g[0],w=g.length>1&&(pe[u].paints||u==="warp"&&f.includes("warp")&&io(Dr(n,r))),k=cc(await nn({message:w?"Pick a default palette in ttheme preview once installed?":`Wear ${b} in every tab?`,initialValue:d?!d.off:!0})),v={terminals:f,palettes:g,off:!k,warpFast:h},S=d?a5(d,v,c):ed(v,c);if(Mn([`Install ${g.length} palettes — ${rM(m,g).join(", ")}`,`Copy ${S.copies.length} files under ${r}`,`Write ${S.settings.file}`,...S.edits.map((O)=>`Edit ${O.file} — a ttheme block: source ttheme.zsh`),...Ku(r,S.installed,n),"Each config is backed up once to <file>.ttheme.bak before the first edit — `npx @kecan0406/ttheme uninstall` takes it all out",k?w?`Open ttheme preview — every tab wears the palette picked there, ${b} until then`:`Paint every tab with ${b}, this one now`:"Leave the terminal colors as they are — `ttheme on` wears a palette later",...k&&b?$t(f).flatMap((O)=>O.defaults?[`Make "${O.defaults.profile(b)}" the ${O.name} default profile`]:[]):[]].join(`
750
+ `),`Wiring ${$t(f).map((O)=>O.name).join(", ")}`),!cc(await nn({message:"Apply these changes?"})))throw Fr("Nothing changed"),new He;let M=eg(S,o);if(rg(S),await Xl(r,iM(!0),n),k&&w)m5(r);let I=W(r);p5({...S,catalog:m,installed:I},v,f5(m,I,r),M)}import{spawn as b5}from"node:child_process";import{createHash as w5}from"node:crypto";import{existsSync as sg,mkdirSync as $5,readFileSync as k5,statSync as y5,utimesSync as v5,writeFileSync as S5}from"node:fs";import{homedir as uM}from"node:os";import{join as lM}from"node:path";import{gunzipSync as E5}from"node:zlib";var sM="https://github.com/kecan0406/aninames/releases/latest/download",dM=86400000,M5=3600000,x5=120000;function fM(t){return lM(Rr(t),".checked")}function O5(t=process.env){return t.TTHEME_NAMES!=="off"}function I5(t){try{return Date.now()-y5(fM(t)).mtimeMs>=dM}catch{return!0}}function ag(t,e){let n=fM(t);if($5(Rr(t),{recursive:!0}),!sg(n))S5(n,"");v5(n,e/1000,e/1000)}function hM(t=uM()){if(!O5()||!I5(t))return;try{ag(t,Date.now()),b5(process.execPath,[process.argv[1],"names"],{detached:!0,stdio:"ignore",env:process.env}).unref()}catch{}}function aM(t){return w5("sha256").update(t).digest("hex")}async function cM(t){let e=await fetch(t,{signal:AbortSignal.timeout(x5)});if(!e.ok)throw Error(`${t} answered ${e.status}`);return new Uint8Array(await e.arrayBuffer())}async function mM(t=uM()){let e=Rr(t);try{let r=JSON.parse(new TextDecoder().decode(await cM(`${sM}/ttheme.json`)));for(let[i,{file:o,sha256:s}]of Object.entries(r.layers)){let a=lM(e,`ttheme-${i}.json`);if(sg(a)&&aM(k5(a))===s)continue;let c=E5(await cM(`${sM}/${o}`));if(aM(c)!==s)throw Error(`${o} does not match its hash`);F(a,c)}ag(t,Date.now())}catch{return ag(t,Date.now()-dM+M5),1}zc(t);let n=Q();if(sg(Re(n)))Mi(he(n).palettes,t),Ey(n,t);return 0}import{existsSync as pM,rmSync as R5,utimesSync as P5}from"node:fs";import{homedir as N5}from"node:os";import{join as uc}from"node:path";function A5(t){try{return W(t)}catch{return}}function T5(t){let{home:e,configHome:n}=t,r=A5(n),i={configHome:n,home:e},o=$t(Zt),s=o.map((c)=>c.unwire(i,r)),a=[uc(n,"ttheme"),t.cacheDir,t.stateDir];return{edits:[...xn(uc(t.zdotdir,".zshrc"),Br),...s.flatMap((c)=>c.edits)],removals:[...o.flatMap((c)=>c.shelf?Yo(c.shelf.dir(i)):[]),...s.flatMap((c)=>c.removals),...a.filter((c)=>pM(c))],touches:s.flatMap((c)=>c.touches),...r?{state:r}:{}}}function H5(t,e,n=on()){let r=[];for(let{file:o,content:s}of t.edits){let a=Zg(o,s);r.push(a==="removed"?`Removed ${o} — ttheme had created it`:a==="restored"?`Took ttheme out of ${o}`:`Took ttheme out of ${o} — kept ${o}.ttheme.bak, since the file changed after ttheme's first edit`)}if(t.state){let o=_i(e.configHome,{...t.state,off:!0,palettes:[]},!1,n,e.home);for(let s of $t(t.state.terminals))if(o.has(s.id))r.push(`Gave ${s.name} its own default profile back — it takes it at its next start`)}for(let o of t.removals)R5(o,{recursive:!0,force:!0});if(t.removals.length>0)r.push(`Deleted ${t.removals.length} files and folders ttheme wrote`);let i=new Date;for(let o of t.touches)P5(o,i,i);return r}function C5(){let t=N5();return{home:t,configHome:Q(),zdotdir:process.env.ZDOTDIR??t,cacheDir:xr(),stateDir:uc(process.env.XDG_STATE_HOME??uc(t,".local","state"),"ttheme")}}async function gM(t=!1){let e=C5(),n=T5(e);if(n.edits.length===0&&n.removals.length===0){console.log("Nothing of ttheme is installed");return}if(!t){if(process.stdin.isTTY!==!0||process.stdout.isTTY!==!0)throw Error("uninstall asks before it deletes anything — run it in a terminal, or pass --yes");let r=uc(e.configHome,"ttheme");pu("ttheme uninstall"),Mn([...n.edits.map((o)=>`Take ttheme out of ${o.file}`),...n.removals.map((o)=>o===r?`Delete ${o} — settings, pins, every installed picture${pM(Dc(e.configHome))?`, and your markets under ${Dc(e.configHome)} (push them to GitHub first to keep them)`:""}`:`Delete ${o}`)].join(`
751
+ `),"Uninstall");let i=await nn({message:"Remove ttheme?"});if(me(i)||!i)throw Fr("Nothing changed"),new He}for(let r of H5(n,e))console.log(r);console.log("Open tabs keep their colors until they close — restart your terminal to drop ttheme everywhere")}import{homedir as L5}from"node:os";async function bM(t){if(!Zt.includes(t))throw Error(`no terminal ${t} — one of ${Zt.join(", ")}`);let e=t,n=On[e],r=Q(),i=L5(),o=on(),s=W(r);if(s.terminals.includes(e))return console.log(`${n.name} is wired already`),0;let a={configHome:r,home:i};if(!n.offered(a,o))throw Error(`${n.name} cannot be wired on this system`);if(process.stdin.isTTY!==!0||process.stdout.isTTY!==!0)throw Error("wire asks before it edits your configs — run it in a terminal");let c={...s,...n.installs?.(a)??{},terminals:[e]};Mn([...Ku(r,c,i),...zu(r,c,i),"Each config is backed up once to <file>.ttheme.bak before the first edit — `npx @kecan0406/ttheme uninstall` takes it all out"].join(`
752
+ `),`Wiring ${n.name}`);let u=await nn({message:`Wire ${n.name} now?`,initialValue:!1});if(me(u)||!u)throw Fr("Nothing changed"),new He;let l=$a(r,c,o,i),d={...l,terminals:[...s.terminals,e]};We(r,d),qt(r,dt(r),d,i,o);let f=_i(r,l,!0,o,i),h=Du(r,l,f,i);if(h.length>0)Mn(h.join(`
753
+ `),"Next");return sa(`Wired ${n.name}`),0}var j5=new Set(["add","remove","market","default","on","off"]),_5={default:([t])=>PE(t),on:()=>NE(),off:()=>AE(),browse:()=>FE(),list:([t],{json:e})=>CE(t,e),add:(t,{market:e})=>IE(t,e),remove:(t)=>RE(t),update:()=>LE(),market:([t,e])=>p1(t,e),new:([t],{from:e,in:n})=>fE(t,e,n),edit:([t])=>hE(t),check:([t],{fix:e})=>gE(t,e),share:([t],{tone:e})=>$E(t,e),init:(t,{yes:e})=>oM({yes:e}),uninstall:(t,{yes:e})=>gM(e),wire:([t])=>bM(t),info:()=>VE(),build:(t,{only:e})=>Ql({only:e}),find:([t])=>rE(t),image:([t,e,n])=>zE(t,e,n),redraw:()=>WE(),names:()=>mM(),tone:([t,e])=>mE(t,e),flatten:([t,e,n,r,i,o,s])=>YE(t,e,n,r,i,o,s),bake:([t,e,n,r])=>qE(t,e,n,r)},B5=ua.map((t)=>({...t,run:_5[t.name]}));class oo extends Error{verb;constructor(t,e){super(t);this.verb=e}}function wM(t){let e=B5.find((n)=>n.name===t);if(!e)throw new oo(t.startsWith("-")?`unknown option '${t}'`:`unknown command '${t}'`);return e}function G5(t,e){let n={help:{type:"boolean",short:"h"}};for(let[r,{type:i,short:o,multiple:s}]of Object.entries(t.flags??{}))n[r]={type:i,multiple:s===!0,...o?{short:o}:{}};try{return F5({args:e,options:n,allowPositionals:!0})}catch(r){let[i=""]=(r instanceof Error?r.message:String(r)).split(". ");throw new oo(`${i.charAt(0).toLowerCase()}${i.slice(1)}`,t)}}function U5(t){let[e,...n]=t;if(e===void 0)return{kind:"help",code:1};if(e==="-h"||e==="--help")return{kind:"help",code:0};if(e==="-V"||e==="--version")return{kind:"version"};if(e==="help"){if(n[0]===void 0||n[0]==="all")return{kind:"help",all:n[0]==="all",code:0};return{kind:"help",verb:wM(n[0]),code:0}}let r=wM(e),i=G5(r,n);if(i.values.help)return{kind:"help",verb:r,code:0};for(let[l,{choices:d}]of Object.entries(r.flags??{}))for(let f of[i.values[l]??[]].flat())if(d&&!d.includes(String(f)))throw new oo(`--${l} takes ${d.join(", ")} — not ${f}`,r);let o=i.positionals,s=r.args.filter((l)=>l.startsWith("<")).length,a=r.args.some((l)=>l.includes("..."))?Number.POSITIVE_INFINITY:r.args.length;if(o.length<s)throw new oo(`missing ${r.args[o.length]}`,r);if(o.length>a)throw new oo(`too many arguments: ${o.slice(a).join(" ")}`,r);let{help:c,...u}=i.values;return{kind:"run",verb:r,args:o,flags:u}}function $M(t){let e=Math.max(0,...t.map(([n])=>n.length));return t.map(([n,r])=>` ${n.padEnd(e)} ${r}`)}function cg(t,e=!1){if(!t)return la(e);let n=Object.entries(t.flags??{}).map(([r,{short:i,value:o,about:s}])=>[`${i?`-${i}, `:""}--${r}${o?` ${o}`:""}`,s]);return[`Usage: ttheme ${ca(t)}`,"",t.about,...t.actions?["","Actions:",...$M(t.actions)]:[],...n.length>0?["","Options:",...$M(n)]:[]].join(`
754
+ `)}var W5=[TypeError,RangeError,ReferenceError,SyntaxError];function K5(t){return W5.some((e)=>t instanceof e)||t instanceof Error&&"code"in t}async function kM(t){let e;try{let n=U5(t);if(n.kind==="version")return console.log(At.version),0;if(n.kind==="help"){if(n.code===0)console.log(cg(n.verb,n.all));else console.error(cg(n.verb,n.all));return n.code}if(e=n.verb,!n.verb.run)throw Error("runs in the shell layer — open a new tab once `ttheme init` has wired it");if(j5.has(n.verb.name))await Xy();let r=await n.verb.run(n.args,n.flags);if(!n.verb.hidden&&n.verb.name!=="uninstall")hM();return typeof r==="number"?r:0}catch(n){if(n instanceof oo)return console.error(n.verb?`ttheme ${n.verb.name}: ${n.message}
757
755
 
758
- ${hp(n.verb)}`:`ttheme: ${n.message} — see \`ttheme help\``),1;if(n instanceof Ne)return 1;if(n instanceof da)return n.exit;let r=process.env.TTHEME_DEBUG&&n instanceof Error?n.stack:void 0;return console.error(`
759
- ttheme${e?` ${e.name}`:""}: ${r??(n instanceof Error?n.message:String(n))}${r3(n)?"\nReport a bug with the output of `ttheme info`":""}`),1}}if(s3)if(process.env.TTHEME_DEBUG&&typeof Bun>"u"&&!process.sourceMapsEnabled){let t=i3(process.execPath,["--enable-source-maps",...process.argv.slice(1)],{stdio:"inherit"});process.exitCode=t.status??1}else process.exitCode=await WE(process.argv.slice(2));
756
+ ${cg(n.verb)}`:`ttheme: ${n.message} — see \`ttheme help\``),1;if(n instanceof He)return 1;if(n instanceof Na)return n.exit;let r=process.env.TTHEME_DEBUG&&n instanceof Error?n.stack:void 0;return console.error(`
757
+ ttheme${e?` ${e.name}`:""}: ${r??(n instanceof Error?n.message:String(n))}${K5(n)?"\nReport a bug with the output of `ttheme info`":""}`),1}}if(D5)if(process.env.TTHEME_DEBUG&&typeof Bun>"u"&&!process.sourceMapsEnabled){let t=z5(process.execPath,["--enable-source-maps",...process.argv.slice(1)],{stdio:"inherit"});process.exitCode=t.status??1}else process.exitCode=await kM(process.argv.slice(2));
760
758
 
761
- //# debugId=39F8DB426D51F96064756E2164756E21
759
+ //# debugId=CC4380ED83DBF72264756E2164756E21
762
760
  //# sourceMappingURL=ttheme.js.map