@kecan0406/ttheme 1.2.21 → 1.2.22

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,27 @@
1
1
  #!/usr/bin/env node
2
- import{createRequire as _P}from"node:module";var NP=Object.create;var{getPrototypeOf:TP,defineProperty:_b,getOwnPropertyNames:HP}=Object;var LP=Object.prototype.hasOwnProperty;function FP(t){return this[t]}var CP,jP,ld=(t,e,n)=>{var r=t!=null&&typeof t==="object";if(r){var i=e?CP??=new WeakMap:jP??=new WeakMap,s=i.get(t);if(s)return s}n=t!=null?NP(TP(t)):{};let o=e||!t||!t.__esModule?_b(n,"default",{value:t,enumerable:!0}):n;for(let a of HP(t))if(!LP.call(o,a))_b(o,a,{get:FP.bind(t,a),enumerable:!0});if(r)i.set(t,o);return o};var xt=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Xt=_P(import.meta.url);var gd=xt((q_,tw)=>{var ZP=Xt("util"),Qb=Xt("stream"),on=tw.exports=function(){Qb.call(this),this._buffers=[],this._buffered=0,this._reads=[],this._paused=!1,this._encoding="utf8",this.writable=!0};ZP.inherits(on,Qb);on.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))};on.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};on.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()};on.prototype.destroySoon=on.prototype.end;on.prototype._end=function(){if(this._reads.length>0)this.emit("error",Error("Unexpected end of input"));this.destroy()};on.prototype.destroy=function(){if(!this._buffers)return;this.writable=!1,this._reads=null,this._buffers=null,this.emit("close")};on.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)};on.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)};on.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 bd=xt((XP)=>{var Hr=[{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]}];XP.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<Hr.length;a++){let c=Hr[a],u=s*c.x.length,f=o*c.y.length;for(let l=0;l<c.x.length;l++)if(c.x[l]<r)u++;else break;for(let l=0;l<c.y.length;l++)if(c.y[l]<i)f++;else break;if(u>0&&f>0)n.push({width:u,height:f,index:a})}return n};XP.getInterlaceIterator=function(t){return function(e,n,r){let i=e%Hr[r].x.length,s=(e-i)/Hr[r].x.length*8+Hr[r].x[i],o=n%Hr[r].y.length,a=(n-o)/Hr[r].y.length*8+Hr[r].y[o];return s*4+a*t*4}}});var wd=xt((J_,ew)=>{ew.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 $d=xt((Y_,rw)=>{var eR=bd(),nR=wd();function nw(t,e,n){let r=t*e;if(n!==8)r=Math.ceil(r/(8/n));return r}var Gs=rw.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=eR.getImagePasses(n,r);for(let c=0;c<a.length;c++)this._images.push({byteWidth:nw(a[c].width,s,o),height:a[c].height,lineIndex:0})}else this._images.push({byteWidth:nw(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};Gs.prototype.start=function(){this.read(this._images[this._imageIndex].byteWidth+1,this._reverseFilterLine.bind(this))};Gs.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}};Gs.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}};Gs.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,f=Math.floor((u+c)/2);e[o]=a+f}};Gs.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,f=o>i&&s?s[o-r]:0,l=nR(u,c,f);e[o]=a+l}};Gs.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 ow=xt((V_,sw)=>{var rR=Xt("util"),iw=gd(),iR=$d(),sR=sw.exports=function(t){iw.call(this);let e=[],n=this;this._filter=new iR(t,{read:this.read.bind(this),write:function(r){e.push(r)},complete:function(){n.emit("complete",Buffer.concat(e))}}),this._filter.start()};rR.inherits(sR,iw)});var Bs=xt((Z_,aw)=>{aw.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 vd=xt((X_,cw)=>{var kd=[];(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;kd[t]=e}})();var yd=cw.exports=function(){this._crc=-1};yd.prototype.write=function(t){for(let e=0;e<t.length;e++)this._crc=kd[(this._crc^t[e])&255]^this._crc>>>8;return!0};yd.prototype.crc32=function(){return this._crc^-1};yd.crc32=function(t){let e=-1;for(let n=0;n<t.length;n++)e=kd[(e^t[n])&255]^e>>>8;return e^-1}});var Sd=xt((Q_,uw)=>{var _t=Bs(),oR=vd(),Ut=uw.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[_t.TYPE_IHDR]=this._handleIHDR.bind(this),this._chunks[_t.TYPE_IEND]=this._handleIEND.bind(this),this._chunks[_t.TYPE_IDAT]=this._handleIDAT.bind(this),this._chunks[_t.TYPE_PLTE]=this._handlePLTE.bind(this),this._chunks[_t.TYPE_tRNS]=this._handleTRNS.bind(this),this._chunks[_t.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(){}};Ut.prototype.start=function(){this.read(_t.PNG_SIGNATURE.length,this._parseSignature.bind(this))};Ut.prototype._parseSignature=function(t){let e=_t.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))};Ut.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!==_t.TYPE_IHDR){this.error(Error("Expected IHDR on beggining"));return}if(this._crc=new oR,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))};Ut.prototype._skipChunk=function(){this.read(8,this._parseChunkBegin.bind(this))};Ut.prototype._handleChunkEnd=function(){this.read(4,this._parseChunkEnd.bind(this))};Ut.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))};Ut.prototype._handleIHDR=function(t){this.read(t,this._parseIHDR.bind(this))};Ut.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 _t.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=_t.COLORTYPE_TO_BPP_MAP[this._colorType];this._hasIHDR=!0,this.metadata({width:e,height:n,depth:r,interlace:Boolean(a),palette:Boolean(i&_t.COLORTYPE_PALETTE),color:Boolean(i&_t.COLORTYPE_COLOR),alpha:Boolean(i&_t.COLORTYPE_ALPHA),bpp:c,colorType:i}),this._handleChunkEnd()};Ut.prototype._handlePLTE=function(t){this.read(t,this._parsePLTE.bind(this))};Ut.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()};Ut.prototype._handleTRNS=function(t){this.simpleTransparency(),this.read(t,this._parseTRNS.bind(this))};Ut.prototype._parseTRNS=function(t){if(this._crc.write(t),this._colorType===_t.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===_t.COLORTYPE_GRAYSCALE)this.transColor([t.readUInt16BE(0)]);if(this._colorType===_t.COLORTYPE_COLOR)this.transColor([t.readUInt16BE(0),t.readUInt16BE(2),t.readUInt16BE(4)]);this._handleChunkEnd()};Ut.prototype._handleGAMA=function(t){this.read(t,this._parseGAMA.bind(this))};Ut.prototype._parseGAMA=function(t){this._crc.write(t),this.gamma(t.readUInt32BE(0)/_t.GAMMA_DIVISION),this._handleChunkEnd()};Ut.prototype._handleIDAT=function(t){if(!this._emittedHeadersFinished)this._emittedHeadersFinished=!0,this.headersFinished();this.read(-t,this._parseIDAT.bind(this,t))};Ut.prototype._parseIDAT=function(t,e){if(this._crc.write(e),this._colorType===_t.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()};Ut.prototype._handleIEND=function(t){this.read(t,this._parseIEND.bind(this))};Ut.prototype._parseIEND=function(t){if(this._crc.write(t),this._hasIEND=!0,this._handleChunkEnd(),this.finished)this.finished()}});var Ed=xt((dR)=>{var lw=bd(),aR=[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]}],cR=[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 uR(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,f,l,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:f=s&3,l=s>>2&3,d=s>>4&3,h=s>>6&3,n.push(h,d,l,f);break;case 1:o=s&1,a=s>>1&1,c=s>>2&1,u=s>>3&1,f=s>>4&1,l=s>>5&1,d=s>>6&1,h=s>>7&1,n.push(h,d,l,f,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 lR(t,e,n,r,i,s){let{width:o,height:a,index:c}=t;for(let u=0;u<a;u++)for(let f=0;f<o;f++){let l=n(f,u,c);aR[r](e,i,l,s),s+=r}return s}function fR(t,e,n,r,i,s){let{width:o,height:a,index:c}=t;for(let u=0;u<a;u++){for(let f=0;f<o;f++){let l=i.get(r),d=n(f,u,c);cR[r](e,l,d,s)}i.resetAfterLine()}}dR.dataToBitMap=function(t,e){let{width:n,height:r,depth:i,bpp:s,interlace:o}=e,a;if(i!==8)a=uR(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,f=0,l,d;if(o)l=lw.getImagePasses(n,r),d=lw.getInterlaceIterator(n,r);else{let h=0;d=function(){let m=h;return h+=4,m},l=[{width:n,height:r}]}for(let h=0;h<l.length;h++)if(i===8)f=lR(l[h],c,d,s,t,f);else fR(l[h],c,d,s,a,u);if(i===8){if(f!==t.length)throw Error("extra data found")}else a.end();return c}});var Md=xt((eG,fw)=>{function mR(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 pR(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 gR(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 f=0;f<4;f++)e[a+f]=Math.floor(t[a+f]*s/o+0.5);a+=4}}fw.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)mR(t,u,i,s,c);else{if(a)pR(t,u,i,s,a);if(r!==8&&!n){if(r===16)u=Buffer.alloc(i*s*4);gR(t,u,i,s,r)}}return u}});var mw=xt((nG,hw)=>{var bR=Xt("util"),xd=Xt("zlib"),dw=gd(),wR=ow(),$R=Sd(),kR=Ed(),yR=Md(),En=hw.exports=function(t){dw.call(this),this._parser=new $R(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()};bR.inherits(En,dw);En.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};En.prototype._inflateData=function(t){if(!this._inflate)if(this._bitmapInfo.interlace)this._inflate=xd.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,xd.Z_MIN_CHUNK);this._inflate=xd.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)};En.prototype._handleMetaData=function(t){this._metaData=t,this._bitmapInfo=Object.create(t),this._filter=new wR(this._bitmapInfo)};En.prototype._handleTransColor=function(t){this._bitmapInfo.transColor=t};En.prototype._handlePalette=function(t){this._bitmapInfo.palette=t};En.prototype._simpleTransparency=function(){this._metaData.alpha=!0};En.prototype._headersFinished=function(){this.emit("metadata",this._metaData)};En.prototype._finished=function(){if(this.errord)return;if(!this._inflate)this.emit("error","No Inflate block");else this._inflate.end()};En.prototype._complete=function(t){if(this.errord)return;let e;try{let n=kR.dataToBitMap(t,this._bitmapInfo);e=yR(n,this._bitmapInfo,this._options.skipRescale),n=null}catch(n){this._handleError(n);return}this.emit("parsed",e)}});var gw=xt((rG,pw)=>{var ze=Bs();pw.exports=function(t,e,n,r){let i=[ze.COLORTYPE_COLOR_ALPHA,ze.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 s=r.bitDepth!==16?t:new Uint16Array(t.buffer),o=255,a=ze.COLORTYPE_TO_BPP_MAP[r.inputColorType];if(a===4&&!r.inputHasAlpha)a=3;let c=ze.COLORTYPE_TO_BPP_MAP[r.colorType];if(r.bitDepth===16)o=65535,c*=2;let u=Buffer.alloc(e*n*c),f=0,l=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,w=o;switch(r.inputColorType){case ze.COLORTYPE_COLOR_ALPHA:w=s[f+3],m=s[f],g=s[f+1],b=s[f+2];break;case ze.COLORTYPE_COLOR:m=s[f],g=s[f+1],b=s[f+2];break;case ze.COLORTYPE_ALPHA:w=s[f+1],m=s[f],g=m,b=m;break;case ze.COLORTYPE_GRAYSCALE:m=s[f],g=m,b=m;break;default:throw Error("input color type:"+r.inputColorType+" is not supported at present")}if(r.inputHasAlpha){if(!i)w/=o,m=Math.min(Math.max(Math.round((1-w)*d.red+w*m),0),o),g=Math.min(Math.max(Math.round((1-w)*d.green+w*g),0),o),b=Math.min(Math.max(Math.round((1-w)*d.blue+w*b),0),o)}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(s,f);switch(r.colorType){case ze.COLORTYPE_COLOR_ALPHA:case ze.COLORTYPE_COLOR:if(r.bitDepth===8){if(u[l]=b.red,u[l+1]=b.green,u[l+2]=b.blue,i)u[l+3]=b.alpha}else if(u.writeUInt16BE(b.red,l),u.writeUInt16BE(b.green,l+2),u.writeUInt16BE(b.blue,l+4),i)u.writeUInt16BE(b.alpha,l+6);break;case ze.COLORTYPE_ALPHA:case ze.COLORTYPE_GRAYSCALE:{let w=(b.red+b.green+b.blue)/3;if(r.bitDepth===8){if(u[l]=w,i)u[l+1]=b.alpha}else if(u.writeUInt16BE(w,l),i)u.writeUInt16BE(b.alpha,l+2);break}default:throw Error("unrecognised color Type "+r.colorType)}f+=a,l+=c}return u}});var $w=xt((iG,ww)=>{var bw=wd();function vR(t,e,n,r,i){for(let s=0;s<n;s++)r[i+s]=t[e+s]}function SR(t,e,n){let r=0,i=e+n;for(let s=e;s<i;s++)r+=Math.abs(t[s]);return r}function ER(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 MR(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 xR(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 OR(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 PR(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 RR(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 IR(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,f=t[e+o]-bw(a,c,u);r[i+o]=f}}function AR(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]-bw(o,a,c);i+=Math.abs(u)}return i}var NR={0:vR,1:ER,2:xR,3:PR,4:IR},TR={0:SR,1:MR,2:OR,3:RR,4:AR};ww.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),f=s[0];for(let l=0;l<n;l++){if(s.length>1){let d=1/0;for(let h=0;h<s.length;h++){let m=TR[s[h]](t,c,o,i);if(m<d)f=s[h],d=m}}u[a]=f,a++,NR[f](t,c,o,u,a,i),a+=o,c+=o}return u}});var Od=xt((sG,kw)=>{var Qt=Bs(),HR=vd(),LR=gw(),FR=$w(),CR=Xt("zlib"),Lr=kw.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||CR.createDeflate,t.bitDepth=t.bitDepth||8,t.colorType=typeof t.colorType==="number"?t.colorType:Qt.COLORTYPE_COLOR_ALPHA,t.inputColorType=typeof t.inputColorType==="number"?t.inputColorType:Qt.COLORTYPE_COLOR_ALPHA,[Qt.COLORTYPE_GRAYSCALE,Qt.COLORTYPE_COLOR,Qt.COLORTYPE_COLOR_ALPHA,Qt.COLORTYPE_ALPHA].indexOf(t.colorType)===-1)throw Error("option color type:"+t.colorType+" is not supported at present");if([Qt.COLORTYPE_GRAYSCALE,Qt.COLORTYPE_COLOR,Qt.COLORTYPE_COLOR_ALPHA,Qt.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")};Lr.prototype.getDeflateOptions=function(){return{chunkSize:this._options.deflateChunkSize,level:this._options.deflateLevel,strategy:this._options.deflateStrategy}};Lr.prototype.createDeflate=function(){return this._options.deflateFactory(this.getDeflateOptions())};Lr.prototype.filterData=function(t,e,n){let r=LR(t,e,n,this._options),i=Qt.COLORTYPE_TO_BPP_MAP[this._options.colorType];return FR(r,e,n,this._options,i)};Lr.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(HR.crc32(r.slice(4,r.length-4)),r.length-4),r};Lr.prototype.packGAMA=function(t){let e=Buffer.alloc(4);return e.writeUInt32BE(Math.floor(t*Qt.GAMMA_DIVISION),0),this._packChunk(Qt.TYPE_gAMA,e)};Lr.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(Qt.TYPE_IHDR,n)};Lr.prototype.packIDAT=function(t){return this._packChunk(Qt.TYPE_IDAT,t)};Lr.prototype.packIEND=function(){return this._packChunk(Qt.TYPE_IEND,null)}});var Ew=xt((oG,Sw)=>{var jR=Xt("util"),yw=Xt("stream"),_R=Bs(),GR=Od(),vw=Sw.exports=function(t){yw.call(this);let e=t||{};this._packer=new GR(e),this._deflate=this._packer.createDeflate(),this.readable=!0};jR.inherits(vw,yw);vw.prototype.pack=function(t,e,n,r){if(this.emit("data",Buffer.from(_R.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 Iw=xt((ha,Rw)=>{var Mw=Xt("assert").ok,Us=Xt("zlib"),BR=Xt("util"),xw=Xt("buffer").kMaxLength;function Ri(t){if(!(this instanceof Ri))return new Ri(t);if(t&&t.chunkSize<Us.Z_MIN_CHUNK)t.chunkSize=Us.Z_MIN_CHUNK;if(Us.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 UR(t){return new Ri(t)}function Ow(t,e){if(e)process.nextTick(e);if(!t._handle)return;t._handle.close(),t._handle=null}Ri.prototype._processChunk=function(t,e,n){if(typeof n==="function")return Us.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,f;this.on("error",function(m){f=m});function l(m,g){if(r._hadError)return;let b=s-g;if(Mw(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>o)w=w.slice(0,o);if(c.push(w),u+=w.length,o-=w.length,o===0)return!1}if(g===0||r._offset>=r._chunkSize)s=r._chunkSize,r._offset=0,r._buffer=Buffer.allocUnsafe(r._chunkSize);if(g===0)return a+=i-m,i=m,!0;return!1}Mw(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&&l(d[0],d[1]));if(this._hadError)throw f;if(u>=xw)throw Ow(this),RangeError("Cannot create final Buffer. It would be larger than 0x"+xw.toString(16)+" bytes");let h=Buffer.concat(c,u);return Ow(this),h};BR.inherits(Ri,Us.Inflate);function WR(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=Us.Z_FINISH;return t._processChunk(e,n)}function Pw(t,e){return WR(new Ri(e),t)}Rw.exports=ha=Pw;ha.Inflate=Ri;ha.createInflate=UR;ha.inflateSync=Pw});var Pd=xt((aG,Nw)=>{var Aw=Nw.exports=function(t){this._buffer=t,this._reads=[]};Aw.prototype.read=function(t,e){this._reads.push({length:Math.abs(t),allowLess:t<0,func:e})};Aw.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 Tw=xt((qR)=>{var KR=Pd(),zR=$d();qR.process=function(t,e){let n=[],r=new KR(t);return new zR(e,{read:r.read.bind(r),write:function(s){n.push(s)},complete:function(){}}).start(),r.process(),Buffer.concat(n)}});var Cw=xt((uG,Fw)=>{var Hw=!0,Lw=Xt("zlib"),JR=Iw();if(!Lw.deflateSync)Hw=!1;var YR=Pd(),VR=Tw(),ZR=Sd(),XR=Ed(),QR=Md();Fw.exports=function(t,e){if(!Hw)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 f(S){u=S}let l=[];function d(S){l.push(S)}let h=new YR(t);if(new ZR(e,{read:h.read.bind(h),error:r,metadata:s,gamma:f,palette:a,transColor:o,inflateData:d,simpleTransparency:c}).start(),h.process(),n)throw n;let g=Buffer.concat(l);l.length=0;let b;if(i.interlace)b=Lw.inflateSync(g);else{let x=((i.width*i.bpp*i.depth+7>>3)+1)*i.height;b=JR(g,{chunkSize:x,maxLength:x})}if(g=null,!b||!b.length)throw Error("bad png - invalid inflate data response");let w=VR.process(b,i);g=null;let k=XR.dataToBitMap(w,i);w=null;let v=QR(k,i,e.skipRescale);return i.data=v,i.gamma=u||0,i}});var Bw=xt((lG,Gw)=>{var jw=!0,_w=Xt("zlib");if(!_w.deflateSync)jw=!1;var tI=Bs(),eI=Od();Gw.exports=function(t,e){if(!jw)throw Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");let r=new eI(e||{}),i=[];if(i.push(Buffer.from(tI.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=_w.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 Uw=xt((iI)=>{var nI=Cw(),rI=Bw();iI.read=function(t,e){return nI(t,e||{})};iI.write=function(t,e){return rI(t,e)}});var Kw=xt((fI)=>{var aI=Xt("util"),Ww=Xt("stream"),cI=mw(),uI=Ew(),lI=Uw(),ue=fI.PNG=function(t){if(Ww.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 cI(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 uI(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"))};aI.inherits(ue,Ww);ue.sync=lI;ue.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};ue.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};ue.prototype.write=function(t){return this._parser.write(t),!0};ue.prototype.end=function(t){this._parser.end(t)};ue.prototype._metadata=function(t){this.width=t.width,this.height=t.height,this.emit("metadata",t)};ue.prototype._gamma=function(t){this.gamma=t};ue.prototype._handleClose=function(){if(!this._parser.writable&&!this._packer.readable)this.emit("close")};ue.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)};ue.prototype.bitblt=function(t,e,n,r,i,s,o){return ue.bitblt(this,t,e,n,r,i,s,o),this};ue.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}};ue.prototype.adjustGamma=function(){ue.adjustGamma(this)}});var Qh=xt((KU,sy)=>{var Xh={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"},TT={up:(t=1)=>"\x1B[S".repeat(t),down:(t=1)=>"\x1B[T".repeat(t)},HT={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?Xh.up():"");if(t)e+=Xh.left;return e}};sy.exports={cursor:Xh,scroll:TT,erase:HT,beep:"\x07"}});import{spawnSync as L_}from"node:child_process";import{isMainThread as F_}from"node:worker_threads";import{parseArgs as O_}from"node:util";var dt={name:"@kecan0406/ttheme",version:"1.2.21",type:"module",bin:{ttheme:"bin/ttheme.js"},files:["bin","dist/manifest.json","shell","!shell/check.zsh"],description:"Character terminal palettes for Ghostty, iTerm2, kitty, Alacritty, WezTerm, Windows Terminal, Warp, Konsole and Terminal.app",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","warp","windows-terminal"],devDependencies:{"@biomejs/biome":"^2.5.15","@clack/prompts":"^1.8.1","@jsquash/jpeg":"^1.6.0","@material/material-color-utilities":"^0.4.0","@oxlint/plugins":"1.87.0","@types/bun":"^1.4.2","@types/pngjs":"6.0.5","@xterm/headless":"6.0.0","fast-string-width":"^3.0.2",oxlint:"1.87.0",pngjs:"7.0.0","smol-toml":"^1.9.0",typescript:"^7.0.2",uqr:"^0.1.3"},engines:{bun:">=1.3",node:">=22"}};import{existsSync as $k,readFileSync as Ch}from"node:fs";import{join as kk}from"node:path";var BP=/^#[0-9a-f]{6}$/;function ge(t){return BP.test(t)}function ct(t){let e=Number.parseInt(t.slice(1),16);return[e>>16&255,e>>8&255,e&255]}function Tt(t,e,n){let r=ct(t),i=ct(e);return`#${r.map((s,o)=>Math.round(s+((i[o]??0)-s)*n).toString(16).padStart(2,"0")).join("")}`}function Mt(t){let[e,n,r]=ct(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 yt(t,e){let n=Mt(t),r=Mt(e);return(Math.max(n,r)+0.05)/(Math.min(n,r)+0.05)}function eu(t,e){return Math.round(yt(t,e)*100)/100}function UP(t){let e=t/255;return e<=0.04045?e/12.92:((e+0.055)/1.055)**2.4}function Ot(t){let[e,n,r]=ct(t).map(UP),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 Ir=7,Gb=3,fd=0.15,Bb=1.6,hd=[1,2,3,4,5,6,9,10,11,12,13,14],Ub=[7,15],Ar=[1,2,3,4,5,6],Pe={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}},Oi=0.03,sn=25,Cs=15,js=0.08;function Xn(t,e){let n=t.ansi[e];if(n===void 0)throw Error(`${t.name}: missing ANSI ${e}`);return n}function dd(t,e,n){let r=t.background;return e.flatMap((i)=>{let s=Xn(t,i);return yt(s,r)<n?[`ANSI ${i} ${s} on ${r} is ${eu(s,r)}:1, needs ${n}:1`]:[]})}function Wb(t,e){return Math.min(...e.map((n)=>yt(Xn(t,n),t.background)))}var Kb=[{rule:"foreground",label:"foreground on background",unit:"ratio",min:Ir,measure:({foreground:t,background:e})=>yt(t,e),check:({foreground:t,background:e})=>yt(t,e)<Ir?[`foreground ${t} on ${e} is ${eu(t,e)}:1, needs ${Ir}:1`]:[]},{rule:"accents",label:"weakest accent on background",unit:"ratio",min:Gb,measure:(t)=>Wb(t,hd),check:(t)=>dd(t,hd,Gb)},{rule:"ansi0-dark",label:"ansi0 luminance",unit:"luminance",max:fd,measure:(t)=>Mt(Xn(t,0)),check:(t)=>{let e=Xn(t,0);return Mt(e)>fd?[`ANSI 0 ${e} has luminance ${Mt(e).toFixed(3)}, needs <= ${fd}`]:[]}},{rule:"light-ansi",label:"ansi7 and ansi15 on background",unit:"ratio",min:Ir,measure:(t)=>Wb(t,Ub),check:(t)=>dd(t,Ub,Ir)},{rule:"ansi8-visible",label:"ansi8 on background",unit:"ratio",min:Bb,measure:(t)=>yt(Xn(t,8),t.background),check:(t)=>dd(t,[8],Bb)},{rule:"selection",label:"foreground on selection",unit:"ratio",min:Ir,measure:({foreground:t,selectionBackground:e})=>e===void 0?Number.NaN:yt(t,e),check:({foreground:t,selectionBackground:e})=>e!==void 0&&yt(t,e)<Ir?[`foreground ${t} on selection ${e} is ${eu(t,e)}:1, needs ${Ir}:1`]:[]}];function Re(t,e){let n=Math.abs(t-e)%360;return Math.min(n,360-n)}var yn=(t)=>t>8?t-8:t;function _s(t){let e=t.signatureSlots.filter((n)=>n.startsWith("ansi")).map((n)=>Number(n.slice(4)));return new Set(e.flatMap((n)=>Ar.includes(yn(n))?[n,n>8?n-8:n+8]:[n]))}function la(t,e){let n=Ot(Xn(t,e));return n.c<Oi?void 0:n}function Nr(t){let e=_s(t);return hd.flatMap((n)=>{let r=la(t,n),i=Pe[yn(n)];if(r===void 0||i===void 0||e.has(n))return[];let s=Re(r.h,i.center)-i.width;return s>0?[{slot:n,hue:r.h,over:s}]:[]})}function Qn(t){let e=new Set(t.signatureSlots);return Ar.flatMap((n)=>{let r=la(t,n),i=la(t,n+8);if(r===void 0||i===void 0||e.has(`ansi${n}`)&&e.has(`ansi${n+8}`))return[];return[{normal:n,gap:Re(r.h,i.h)}]})}function tr(t){let e=_s(t);return[0,8].flatMap((n)=>Ar.flatMap((r)=>Ar.filter((i)=>i>r).flatMap((i)=>{let[s,o]=[n+r,n+i],a=la(t,s),c=la(t,o);if(a===void 0||c===void 0||e.has(s)&&e.has(o))return[];return Re(a.h,c.h)<Cs&&Math.abs(a.l-c.l)<js?[[s,o]]:[]})))}var WP=[{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=Pe[yn(e)];return`ANSI ${e} ${Xn(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:sn,measure:(t)=>Math.max(0,...Qn(t).map((e)=>e.gap)),check:(t)=>Qn(t).filter((e)=>e.gap>sn).map(({normal:e,gap:n})=>`ANSI ${e+8} is ${n.toFixed(0)}° from ANSI ${e}, needs <= ${sn}°`)},{rule:"distinct",label:"accent pairs that read as one color",unit:"pairs",max:0,measure:(t)=>tr(t).length,check:(t)=>tr(t).map(([e,n])=>`ANSI ${e} ${Xn(t,e)} and ANSI ${n} ${Xn(t,n)} are within ${Cs}° hue and ${js} lightness`)}],nu=[...Kb,...WP],md=nu.map((t)=>t.rule),Ie=nu.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 vn(t){return nu.map((e)=>Math.round(e.measure(t)*1000)/1000)}function zb(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 er(t){return zb(nu,t)}function qb(t){return zb(Kb,t)}function Db(t){return t.flatMap(er)}import{chmodSync as KP,copyFileSync as zP,existsSync as Tr,mkdirSync as qP,readFileSync as fa,realpathSync as DP,renameSync as Yb,rmSync as Jb,statSync as JP,writeFileSync as Vb}from"node:fs";import{dirname as YP}from"node:path";function da(t){return`${t}.ttheme.bak`}var VP=/^(?:#|--) ttheme begin$|path = "ttheme-|^DefaultProfile=ttheme-/m;function pd(t){let e=da(t);if(Tr(t)&&!Tr(e)&&!VP.test(fa(t,"utf8")))zP(t,e)}function L(t,e){let n=Tr(t)?DP(t):t;qP(YP(n),{recursive:!0});let r=`${n}.ttheme-${process.pid}`;if(Vb(r,e),Tr(n))KP(r,JP(n).mode&4095);Yb(r,n)}function Pi(t,e,n){if(Vb(t,n),t!==e)Yb(t,e)}function Sn(t,e){if((Tr(t)?fa(t,"utf8"):void 0)===e)return!1;return pd(t),L(t,e),!0}function Zb(t,e){return t.replace(/\n*$/,"")===e.replace(/\n*$/,"")}function Xb(t,e){let n=da(t),r=Tr(n)?fa(n,"utf8"):void 0;if(e===""&&r===void 0)return Jb(t,{force:!0}),"removed";let i=r!==void 0&&Zb(r,e);if(L(t,i?r:e),r===void 0||i)return Jb(n,{force:!0}),"restored";return"kept backup"}function ru(t){let e=da(t);return Tr(t)&&Tr(e)&&Zb(fa(t,"utf8"),fa(e,"utf8"))?[e]:[]}import{createHash as d$}from"node:crypto";import{copyFileSync as rN,existsSync as sh,mkdirSync as iN,readdirSync as sN,readFileSync as to,renameSync as h$,rmSync as Qs,statSync as oN}from"node:fs";import{basename as m$,isAbsolute as aN,join as V}from"node:path";import{readdirSync as EI,rmSync as MI,statSync as xI}from"node:fs";import{setDefaultAutoSelectFamilyAttemptTimeout as OI}from"node:net";import{homedir as PI}from"node:os";import{join as wa}from"node:path";import{setTimeout as RI}from"node:timers/promises";var Jw=ld(Kw(),1);import{constants as pI,deflateSync as gI,inflateSync as bI}from"node:zlib";import{inflateRawSync as hI}from"node:zlib";var dI=(()=>{var t=import.meta.url;return function(e={}){var n=e,r,i,s=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),f=[],l="./this.program",d=(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 x=n.print||console.log.bind(console),M=n.printErr||console.error.bind(console);if(Object.assign(n,u),u=null,n.arguments)f=n.arguments;if(n.thisProgram)l=n.thisProgram;if(n.quit)d=n.quit;var N;if(n.wasmBinary)N=n.wasmBinary;var C,P=!1,_,K,B,F,gt,Zt,at,Rr,We;function kn(){var p=C.buffer;n.HEAP8=K=new Int8Array(p),n.HEAP16=F=new Int16Array(p),n.HEAPU8=B=new Uint8Array(p),n.HEAPU16=gt=new Uint16Array(p),n.HEAP32=Zt=new Int32Array(p),n.HEAPU32=at=new Uint32Array(p),n.HEAPF32=Rr=new Float32Array(p),n.HEAPF64=We=new Float64Array(p)}var Ns=[],Zc=[],yi=[],Vf=!1;function Zf(){if(n.preRun){if(typeof n.preRun=="function")n.preRun=[n.preRun];while(n.preRun.length)W2(n.preRun.shift())}td(Ns)}function Xf(){Vf=!0,td(Zc)}function U2(){if(n.postRun){if(typeof n.postRun=="function")n.postRun=[n.postRun];while(n.postRun.length)z2(n.postRun.shift())}td(yi)}function W2(p){Ns.unshift(p)}function K2(p){Zc.unshift(p)}function z2(p){yi.unshift(p)}var vi=0,Qf=null,ca=null;function q2(p){vi++,n.monitorRunDependencies?.(vi)}function D2(p){if(vi--,n.monitorRunDependencies?.(vi),vi==0){if(Qf!==null)clearInterval(Qf),Qf=null;if(ca){var $=ca;ca=null,$()}}}function $b(p){n.onAbort?.(p),p="Aborted("+p+")",M(p),P=!0,_=1,p+=". Build with -sASSERTIONS for more info.";var $=new WebAssembly.RuntimeError(p);throw i($),$}var J2="data:application/octet-stream;base64,",kb=(p)=>p.startsWith(J2),Si;if(n.locateFile){if(Si="mozjpeg_dec.wasm",!kb(Si))Si=w(Si)}else Si=new URL("mozjpeg_dec.wasm",import.meta.url).href;function yb(p){if(p==Si&&N)return new Uint8Array(N);if(S)return S(p);throw"both async and sync fetching of the wasm failed"}function Y2(p){if(!N&&(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(()=>yb(p))}return Promise.resolve().then(()=>yb(p))}function vb(p,$,y){return Y2(p).then((E)=>WebAssembly.instantiate(E,$)).then(y,(E)=>{M(`failed to asynchronously prepare wasm: ${E}`),$b(E)})}function V2(p,$,y,E){if(!p&&typeof WebAssembly.instantiateStreaming=="function"&&!kb($)&&typeof fetch=="function")return fetch($,{credentials:"same-origin"}).then((R)=>{var A=WebAssembly.instantiateStreaming(R,y);return A.then(E,function(U){return M(`wasm streaming compile failed: ${U}`),M("falling back to ArrayBuffer instantiation"),vb($,y,E)})});return vb($,y,E)}function Z2(){var p={a:yP};function $(E,R){return ae=E.exports,C=ae.A,kn(),Ib=ae.F,K2(ae.B),D2("wasm-instantiate"),ae}q2("wasm-instantiate");function y(E){$(E.instance)}if(n.instantiateWasm)try{return n.instantiateWasm(p,$)}catch(E){M(`Module.instantiateWasm callback failed with error: ${E}`),i(E)}return V2(N,Si,p,y).catch(i),{}}function X2(p){this.name="ExitStatus",this.message=`Program terminated with exit(${p})`,this.status=p}var td=(p)=>{while(p.length>0)p.shift()(n)},Q2=n.noExitRuntime||!0;class Sb{constructor(p){this.excPtr=p,this.ptr=p-24}set_type(p){at[this.ptr+4>>2]=p}get_type(){return at[this.ptr+4>>2]}set_destructor(p){at[this.ptr+8>>2]=p}get_destructor(){return at[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){at[this.ptr+16>>2]=p}get_adjusted_ptr(){return at[this.ptr+16>>2]}get_exception_ptr(){var p=Cb(this.get_type());if(p)return at[this.excPtr>>2];var $=this.get_adjusted_ptr();if($!==0)return $;return this.excPtr}}var Eb=0,tO=0,eO=(p,$,y)=>{var E=new Sb(p);throw E.init($,y),Eb=p,tO++,Eb},nO=(p,$,y,E,R)=>{},rO=()=>{var p=Array(256);for(var $=0;$<256;++$)p[$]=String.fromCharCode($);Mb=p},Mb,rn=(p)=>{var $="",y=p;while(B[y])$+=Mb[B[y++]];return $},Ts={},Ei={},Xc={},xb,Oe=(p)=>{throw new xb(p)},Ob,Pb=(p)=>{throw new Ob(p)},iO=(p,$,y)=>{p.forEach(function(H){Xc[H]=$});function E(H){var z=y(H);if(z.length!==p.length)Pb("Mismatched type converter count");for(var Q=0;Q<p.length;++Q)Yn(p[Q],z[Q])}var R=Array($.length),A=[],U=0;if($.forEach((H,z)=>{if(Ei.hasOwnProperty(H))R[z]=Ei[H];else{if(A.push(H),!Ts.hasOwnProperty(H))Ts[H]=[];Ts[H].push(()=>{if(R[z]=Ei[H],++U,U===A.length)E(R)})}}),A.length===0)E(R)};function sO(p,$,y={}){var E=$.name;if(!p)Oe(`type "${E}" must have a positive integer typeid pointer`);if(Ei.hasOwnProperty(p))if(y.ignoreDuplicateRegistrations)return;else Oe(`Cannot register type '${E}' twice`);if(Ei[p]=$,delete Xc[p],Ts.hasOwnProperty(p)){var R=Ts[p];delete Ts[p],R.forEach((A)=>A())}}function Yn(p,$,y={}){if(!("argPackAdvance"in $))throw TypeError("registerType registeredInstance requires argPackAdvance");return sO(p,$,y)}var Mi=8,oO=(p,$,y,E)=>{$=rn($),Yn(p,{name:$,fromWireType:function(R){return!!R},toWireType:function(R,A){return A?y:E},argPackAdvance:Mi,readValueFromPointer:function(R){return this.fromWireType(B[R])},destructorFunction:null})},ed=[],Vn=[],nd=(p)=>{if(p>9&&--Vn[p+1]===0)Vn[p]=void 0,ed.push(p)},aO=()=>Vn.length/2-5-ed.length,cO=()=>{Vn.push(0,1,void 0,1,null,1,!0,1,!1,1),n.count_emval_handles=aO},xi={toValue:(p)=>{if(!p)Oe("Cannot use deleted val. handle = "+p);return Vn[p]},toHandle:(p)=>{switch(p){case void 0:return 2;case null:return 4;case!0:return 6;case!1:return 8;default:{let $=ed.pop()||Vn.length;return Vn[$]=p,Vn[$+1]=1,$}}}};function rd(p){return this.fromWireType(at[p>>2])}var uO={name:"emscripten::val",fromWireType:(p)=>{var $=xi.toValue(p);return nd(p),$},toWireType:(p,$)=>xi.toHandle($),argPackAdvance:Mi,readValueFromPointer:rd,destructorFunction:null},lO=(p)=>Yn(p,uO),fO=(p,$)=>{switch($){case 4:return function(y){return this.fromWireType(Rr[y>>2])};case 8:return function(y){return this.fromWireType(We[y>>3])};default:throw TypeError(`invalid float width (${$}): ${p}`)}},dO=(p,$,y)=>{$=rn($),Yn(p,{name:$,fromWireType:(E)=>E,toWireType:(E,R)=>R,argPackAdvance:Mi,readValueFromPointer:fO($,y),destructorFunction:null})},id=(p,$)=>Object.defineProperty($,"name",{value:p}),Rb=(p)=>{while(p.length){var $=p.pop(),y=p.pop();y($)}};function hO(p){for(var $=1;$<p.length;++$)if(p[$]!==null&&p[$].destructorFunction===void 0)return!0;return!1}function mO(p,$,y,E,R,A){var U=$.length;if(U<2)Oe("argTypes array size mismatch! Must at least get return value and 'this' types!");var H=$[1]!==null&&y!==null,z=hO($),Q=$[0].name!=="void",bt=U-2,Ct=Array(bt),ce=[],Ke=[],Hs=function(...cd){if(cd.length!==bt)Oe(`function ${p} called with ${cd.length} arguments, expected ${bt}`);Ke.length=0;var ud;if(ce.length=H?2:1,ce[0]=R,H)ud=$[1].toWireType(Ke,this),ce[1]=ud;for(var Ls=0;Ls<bt;++Ls)Ct[Ls]=$[Ls+2].toWireType(Ke,cd[Ls]),ce.push(Ct[Ls]);var PP=E(...ce);function RP(IP){if(z)Rb(Ke);else for(var Fs=H?1:2;Fs<$.length;Fs++){var AP=Fs===1?ud:Ct[Fs-2];if($[Fs].destructorFunction!==null)$[Fs].destructorFunction(AP)}if(Q)return $[0].fromWireType(IP)}return RP(PP)};return id(p,Hs)}var pO=(p,$,y)=>{if(p[$].overloadTable===void 0){var E=p[$];p[$]=function(...R){if(!p[$].overloadTable.hasOwnProperty(R.length))Oe(`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}},gO=(p,$,y)=>{if(n.hasOwnProperty(p)){if(y===void 0||n[p].overloadTable!==void 0&&n[p].overloadTable[y]!==void 0)Oe(`Cannot register public name '${p}' twice`);if(pO(n,p,p),n.hasOwnProperty(y))Oe(`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},bO=(p,$)=>{var y=[];for(var E=0;E<p;E++)y.push(at[$+E*4>>2]);return y},wO=(p,$,y)=>{if(!n.hasOwnProperty(p))Pb("Replacing nonexistent public symbol");if(n[p].overloadTable!==void 0&&y!==void 0)n[p].overloadTable[y]=$;else n[p]=$,n[p].argCount=y},$O=(p,$,y)=>{p=p.replace(/p/g,"i");var E=n["dynCall_"+p];return E($,...y)},Qc=[],Ib,Ab=(p)=>{var $=Qc[p];if(!$){if(p>=Qc.length)Qc.length=p+1;Qc[p]=$=Ib.get(p)}return $},kO=(p,$,y=[])=>{if(p.includes("j"))return $O(p,$,y);var E=Ab($)(...y);return E},yO=(p,$)=>(...y)=>kO(p,$,y),vO=(p,$)=>{p=rn(p);function y(){if(p.includes("j"))return yO(p,$);return Ab($)}var E=y();if(typeof E!="function")Oe(`unknown function pointer with signature ${p}: ${$}`);return E},SO=(p,$)=>{var y=id($,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},Nb,Tb=(p)=>{var $=Fb(p),y=rn($);return Zn($),y},EO=(p,$)=>{var y=[],E={};function R(A){if(E[A])return;if(Ei[A])return;if(Xc[A]){Xc[A].forEach(R);return}y.push(A),E[A]=!0}throw $.forEach(R),new Nb(`${p}: `+y.map(Tb).join([", "]))},MO=(p)=>{p=p.trim();let $=p.indexOf("(");if($!==-1)return p.substr(0,$);else return p},xO=(p,$,y,E,R,A,U)=>{var H=bO($,y);p=rn(p),p=MO(p),R=vO(E,R),gO(p,function(){EO(`Cannot call ${p} due to unbound types`,H)},$-1),iO([],H,(z)=>{var Q=[z[0],null].concat(z.slice(1));return wO(p,mO(p,Q,null,R,A,U),$-1),[]})},OO=(p,$,y)=>{switch($){case 1:return y?(E)=>K[E]:(E)=>B[E];case 2:return y?(E)=>F[E>>1]:(E)=>gt[E>>1];case 4:return y?(E)=>Zt[E>>2]:(E)=>at[E>>2];default:throw TypeError(`invalid integer width (${$}): ${p}`)}},PO=(p,$,y,E,R)=>{if($=rn($),R===-1)R=4294967295;var A=(bt)=>bt;if(E===0){var U=32-8*y;A=(bt)=>bt<<U>>>U}var H=$.includes("unsigned"),z=(bt,Ct)=>{},Q;if(H)Q=function(bt,Ct){return z(Ct,this.name),Ct>>>0};else Q=function(bt,Ct){return z(Ct,this.name),Ct};Yn(p,{name:$,fromWireType:A,toWireType:Q,argPackAdvance:Mi,readValueFromPointer:OO($,y,E!==0),destructorFunction:null})},RO=(p,$,y)=>{var E=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],R=E[$];function A(U){var H=at[U>>2],z=at[U+4>>2];return new R(K.buffer,z,H)}y=rn(y),Yn(p,{name:y,fromWireType:A,argPackAdvance:Mi,readValueFromPointer:A},{ignoreDuplicateRegistrations:!0})},IO=(p,$,y,E)=>{if(!(E>0))return 0;var R=y,A=y+E-1;for(var U=0;U<p.length;++U){var H=p.charCodeAt(U);if(H>=55296&&H<=57343){var z=p.charCodeAt(++U);H=65536+((H&1023)<<10)|z&1023}if(H<=127){if(y>=A)break;$[y++]=H}else if(H<=2047){if(y+1>=A)break;$[y++]=192|H>>6,$[y++]=128|H&63}else if(H<=65535){if(y+2>=A)break;$[y++]=224|H>>12,$[y++]=128|H>>6&63,$[y++]=128|H&63}else{if(y+3>=A)break;$[y++]=240|H>>18,$[y++]=128|H>>12&63,$[y++]=128|H>>6&63,$[y++]=128|H&63}}return $[y]=0,y-R},AO=(p,$,y)=>IO(p,B,$,y),NO=(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 $},Hb=(p,$,y)=>{var E=$+y,R="";while(!($>=E)){var A=p[$++];if(!A)return R;if(!(A&128)){R+=String.fromCharCode(A);continue}var U=p[$++]&63;if((A&224)==192){R+=String.fromCharCode((A&31)<<6|U);continue}var H=p[$++]&63;if((A&240)==224)A=(A&15)<<12|U<<6|H;else A=(A&7)<<18|U<<12|H<<6|p[$++]&63;if(A<65536)R+=String.fromCharCode(A);else{var z=A-65536;R+=String.fromCharCode(55296|z>>10,56320|z&1023)}}return R},TO=(p,$)=>p?Hb(B,p,$):"",HO=(p,$)=>{$=rn($);var y=$==="std::string";Yn(p,{name:$,fromWireType(E){var R=at[E>>2],A=E+4,U;if(y){var H=A;for(var z=0;z<=R;++z){var Q=A+z;if(z==R||B[Q]==0){var bt=Q-H,Ct=TO(H,bt);if(U===void 0)U=Ct;else U+=String.fromCharCode(0),U+=Ct;H=Q+1}}}else{var ce=Array(R);for(var z=0;z<R;++z)ce[z]=String.fromCharCode(B[A+z]);U=ce.join("")}return Zn(E),U},toWireType(E,R){if(R instanceof ArrayBuffer)R=new Uint8Array(R);var A,U=typeof R=="string";if(!(U||R instanceof Uint8Array||R instanceof Uint8ClampedArray||R instanceof Int8Array))Oe("Cannot pass non-string to std::string");if(y&&U)A=NO(R);else A=R.length;var H=ad(4+A+1),z=H+4;if(at[H>>2]=A,y&&U)AO(R,z,A+1);else if(U)for(var Q=0;Q<A;++Q){var bt=R.charCodeAt(Q);if(bt>255)Zn(z),Oe("String has UTF-16 code units that do not fit in 8 bits");B[z+Q]=bt}else for(var Q=0;Q<A;++Q)B[z+Q]=R[Q];if(E!==null)E.push(Zn,H);return H},argPackAdvance:Mi,readValueFromPointer:rd,destructorFunction(E){Zn(E)}})},LO=(p,$)=>{var y="";for(var E=0;!(E>=$/2);++E){var R=F[p+E*2>>1];if(R==0)break;y+=String.fromCharCode(R)}return y},FO=(p,$,y)=>{if(y??=2147483647,y<2)return 0;y-=2;var E=$,R=y<p.length*2?y/2:p.length;for(var A=0;A<R;++A){var U=p.charCodeAt(A);F[$>>1]=U,$+=2}return F[$>>1]=0,$-E},CO=(p)=>p.length*2,jO=(p,$)=>{var y=0,E="";while(!(y>=$/4)){var R=Zt[p+y*4>>2];if(R==0)break;if(++y,R>=65536){var A=R-65536;E+=String.fromCharCode(55296|A>>10,56320|A&1023)}else E+=String.fromCharCode(R)}return E},_O=(p,$,y)=>{if(y??=2147483647,y<4)return 0;var E=$,R=E+y-4;for(var A=0;A<p.length;++A){var U=p.charCodeAt(A);if(U>=55296&&U<=57343){var H=p.charCodeAt(++A);U=65536+((U&1023)<<10)|H&1023}if(Zt[$>>2]=U,$+=4,$+4>R)break}return Zt[$>>2]=0,$-E},GO=(p)=>{var $=0;for(var y=0;y<p.length;++y){var E=p.charCodeAt(y);if(E>=55296&&E<=57343)++y;$+=4}return $},BO=(p,$,y)=>{y=rn(y);var E,R,A,U;if($===2)E=LO,R=FO,U=CO,A=(H)=>gt[H>>1];else if($===4)E=jO,R=_O,U=GO,A=(H)=>at[H>>2];Yn(p,{name:y,fromWireType:(H)=>{var z=at[H>>2],Q,bt=H+4;for(var Ct=0;Ct<=z;++Ct){var ce=H+4+Ct*$;if(Ct==z||A(ce)==0){var Ke=ce-bt,Hs=E(bt,Ke);if(Q===void 0)Q=Hs;else Q+=String.fromCharCode(0),Q+=Hs;bt=ce+$}}return Zn(H),Q},toWireType:(H,z)=>{if(typeof z!="string")Oe(`Cannot pass non-string to C++ string type ${y}`);var Q=U(z),bt=ad(4+Q+$);if(at[bt>>2]=Q/$,R(z,bt+4,Q+$),H!==null)H.push(Zn,bt);return bt},argPackAdvance:Mi,readValueFromPointer:rd,destructorFunction(H){Zn(H)}})},UO=(p,$)=>{$=rn($),Yn(p,{isVoid:!0,name:$,argPackAdvance:0,fromWireType:()=>{return},toWireType:(y,E)=>{return}})},WO=(p,$,y)=>B.copyWithin(p,$,$+y),sd=[],KO=(p,$,y,E)=>{return p=sd[p],$=xi.toValue($),p(null,$,y,E)},zO={},qO=(p)=>{var $=zO[p];if($===void 0)return rn(p);return $},Lb=()=>{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.")},DO=(p)=>{if(p===0)return xi.toHandle(Lb());else return p=qO(p),xi.toHandle(Lb()[p])},JO=(p)=>{var $=sd.length;return sd.push(p),$},YO=(p,$)=>{var y=Ei[p];if(y===void 0)Oe(`${$} has unknown type ${Tb(p)}`);return y},VO=(p,$)=>{var y=Array(p);for(var E=0;E<p;++E)y[E]=YO(at[$+E*4>>2],"parameter "+E);return y},ZO=Reflect.construct,XO=(p,$,y)=>{var E=[],R=p.toWireType(E,y);if(E.length)at[$>>2]=xi.toHandle(E);return R},QO=(p,$,y)=>{var E=VO(p,$),R=E.shift();p--;var A=Array(p),U=(z,Q,bt,Ct)=>{var ce=0;for(var Ke=0;Ke<p;++Ke)A[Ke]=E[Ke].readValueFromPointer(Ct+ce),ce+=E[Ke].argPackAdvance;var Hs=y===1?ZO(Q,A):Q.apply(z,A);return XO(R,bt,Hs)},H=`methodCaller<(${E.map((z)=>z.name).join(", ")}) => ${R.name}>`;return JO(id(H,U))},tP=(p)=>{if(p>9)Vn[p+1]+=1},eP=(p)=>{var $=xi.toValue(p);Rb($),nd(p)},nP=()=>{$b("")},rP=()=>2147483648,iP=(p)=>{var $=C.buffer,y=(p-$.byteLength+65535)/65536;try{return C.grow(y),kn(),1}catch(E){}},sP=(p)=>{var $=B.length;p>>>=0;var y=rP();if(p>y)return!1;var E=(z,Q)=>z+(Q-z%Q)%Q;for(var R=1;R<=4;R*=2){var A=$*(1+0.2/R);A=Math.min(A,p+100663296);var U=Math.min(y,E(Math.max(p,A),65536)),H=iP(U);if(H)return!0}return!1},od={},oP=()=>l||"./this.program",ua=()=>{if(!ua.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,_:oP()};for(var y in od)if(od[y]===void 0)delete $[y];else $[y]=od[y];var E=[];for(var y in $)E.push(`${y}=${$[y]}`);ua.strings=E}return ua.strings},aP=(p,$)=>{for(var y=0;y<p.length;++y)K[$++]=p.charCodeAt(y);K[$]=0},cP=(p,$)=>{var y=0;return ua().forEach((E,R)=>{var A=$+y;at[p+R*4>>2]=A,aP(E,A),y+=E.length+1}),0},uP=(p,$)=>{var y=ua();at[p>>2]=y.length;var E=0;return y.forEach((R)=>E+=R.length+1),at[$>>2]=E,0},lP=0,fP=()=>Q2||lP>0,dP=(p)=>{if(_=p,!fP())n.onExit?.(p),P=!0;d(p,new X2(p))},hP=(p,$)=>{_=p,dP(p)},mP=hP,pP=(p)=>52,gP=(p,$)=>$+2097152>>>0<4194305-!!p?(p>>>0)+$*4294967296:NaN;function bP(p,$,y,E,R){var A=gP($,y);return 70}var wP=[null,[],[]],$P=(p,$)=>{var y=wP[p];if($===0||$===10)(p===1?x:M)(Hb(y,0)),y.length=0;else y.push($)},kP=(p,$,y,E)=>{var R=0;for(var A=0;A<y;A++){var U=at[$>>2],H=at[$+4>>2];$+=8;for(var z=0;z<H;z++)$P(p,B[U+z]);R+=H}return at[E>>2]=R,0};rO(),xb=n.BindingError=class extends Error{constructor($){super($);this.name="BindingError"}},Ob=n.InternalError=class extends Error{constructor($){super($);this.name="InternalError"}},cO(),Nb=n.UnboundTypeError=SO(Error,"UnboundTypeError");var yP={o:eO,q:nO,m:oO,l:lO,j:dO,f:xO,b:PO,a:RO,e:HO,c:BO,n:UO,v:WO,i:KO,d:nd,k:DO,h:QO,y:tP,g:eP,r:nP,s:sP,t:cP,u:uP,z:mP,w:pP,p:bP,x:kP},ae=Z2(),vP=()=>(vP=ae.B)(),Fb=(p)=>(Fb=ae.C)(p),ad=(p)=>(ad=ae.D)(p),Zn=(p)=>(Zn=ae.E)(p),SP=(p)=>(SP=ae._emscripten_stack_restore)(p),EP=(p)=>(EP=ae._emscripten_stack_alloc)(p),MP=()=>(MP=ae.emscripten_stack_get_current)(),xP=(p)=>(xP=ae.__cxa_increment_exception_refcount)(p),Cb=(p)=>(Cb=ae.G)(p),OP=n.dynCall_jiji=(p,$,y,E,R)=>(OP=n.dynCall_jiji=ae.H)(p,$,y,E,R),tu;ca=function p(){if(!tu)jb();if(!tu)ca=p};function jb(){if(vi>0)return;if(Zf(),vi>0)return;function p(){if(tu)return;if(tu=!0,n.calledRun=!0,P)return;if(Xf(),r(n),n.onRuntimeInitialized)n.onRuntimeInitialized();U2()}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 jb(),s}})(),zw=dI;function Id(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 Rd;function mI(){if(Rd)return Rd;let t=new WebAssembly.Module(hI(Buffer.from("7L0NnFzHVSd6q+5H3+7bPdMjjeyRZmTf7ohFITZWgpFN4mBdEX3Y8leI15jfy+6a3UC8Mwp4ZEWYRdaMY9kICESA2TWsCXrBb+2wNugtejwvmBcFDBFgFgXMRkkMEYtJzB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is/8ImFkqcTeeZxAZZlqsIrMYZhb/7+hcvEQm08Rqmo1waIRifVQlbntcmWGHB0s8i8/bo5gwxjFhjGNSGA8K6z0OQj8eFpZ7HBPJONp2HE0xjuYbJ9Yf1R9HtcdRxXHUaxxNNo4Cjs+UZcE4Cj6OThlHb4yjguOYSMYxYYxjQhjHJDAOIj+O8t6Hyeso8j+K/I8i/6PI/yjyP4r8jyL/o8j/KPI/ivyPIv+jyP8p5H8U+R9Fz3wdR9AQP4b4McSP/biazzypX4Wj0R5yqiPe0DijaSYzKPPmv+PU06zmltNPLvy/+Yf6BGqMkB446onyn6uLP/v3Z14+sr3++PHzzyDGIA13DI0ex0x76GqfWrW6Xl1+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(zw(e),typeof e.decode!=="function")throw Error("the JPEG decoder did not start");return Rd=e,e}function qw(t,e){let n=Id(t);if(n&&n.width*n.height>e)throw Error(`${n.width}×${n.height} is over ${e/1e6} megapixels`);let r=null;try{r=mI().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 Ws=[137,80,78,71,13,10,26,10],Yw=13,Vw=3;function Ii(t){return t.length>=Ws.length&&Ws.every((e,n)=>t[n]===e)}var Zw={0:1,2:3,4:2,6:4};function wI(t){if(t.length<33||!Ii(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||Zw[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 $I(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,f=s>0?c-e-1:0;if(a===1)for(let l=r;l<e;l++)t[c+l]=t[c+l]+t[c+l-r];else if(a===2)for(let l=0;l<e;l++)t[c+l]=t[c+l]+u[f+l];else if(a===3){for(let l=0;l<r;l++)t[c+l]=t[c+l]+(u[f+l]>>1);for(let l=r;l<e;l++)t[c+l]=t[c+l]+(t[c+l-r]+u[f+l]>>1)}else if(a===4){for(let l=0;l<r;l++)t[c+l]=t[c+l]+u[f+l];for(let l=r;l<e;l++){let d=t[c+l-r],h=u[f+l],m=u[f+l-r],g=Math.abs(h-m),b=Math.abs(d-m),w=Math.abs(d+h-2*m);t[c+l]=t[c+l]+(g<=b&&g<=w?d:b<=w?h:m)}}else if(a!==0)throw Error(`bad PNG filter ${a}`)}}function kI(t){let{width:e,height:n,type:r}=t,i=Zw[r],s=e*i,o=bI(Buffer.concat(t.idat),{chunkSize:Math.min(268435456,Math.max(65536,n*(s+1)))});if(o.length<n*(s+1))throw Error("truncated PNG");$I(o,s,n,i);let a=new Uint8Array(e*n*4);for(let c=0;c<n;c++){let u=c*(s+1)+1,f=c*e*4;if(r===6)a.set(o.subarray(u,u+s),f);else if(r===2)for(let l=0,d=u,h=f;l<e;l++,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 l=0,d=f;l<e;l++,d+=4){let h=o[u+l];a[d]=h,a[d+1]=h,a[d+2]=h,a[d+3]=255}else for(let l=0,d=u,h=f;l<e;l++,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 Wt(t){let e=wI(t);if(e)return kI(e);let n=Jw.PNG.sync.read(Buffer.from(t));return{width:n.width,height:n.height,data:new Uint8Array(n.data)}}function Cr(t,e){if(Ii(t)){let n=Mn(t);if(n&&n.width*n.height>e)throw Error(`${n.width}×${n.height} is over ${e/1e6} megapixels`);return Wt(t)}if(t[0]===255&&t[1]===216)return qw(t,e);throw Error("not a PNG or JPEG image")}function Xw(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 f={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:ma(t,f,u.w,u.h),box:u,dx:0,dy:0}}function Qw(t,e){let n=new Uint8Array(e.width*e.height*4),r=Xw(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 jr(t,e,n,r={width:t.width,height:t.height,at:{x:0,y:0,w:t.width,h:t.height}}){let i=ct(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=Xw(t,r);if(!c)return{width:s,height:o,data:a};let{part:u,box:f,dx:l,dy:d}=c;for(let h=0;h<f.h;h++)for(let m=0;m<f.w;m++){let g=((h+d)*u.width+m+l)*4,b=((f.y+h)*s+f.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:s,height:o,data:a}}function Dw(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 Mn(t){if(t.length<33||!Ii(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=Dw(t,"IDAT");return{width:n,height:r,alpha:Dw(i===-1?t:t.subarray(0,i),"tRNS")!==-1}}function t0(t,e=Yw){let{width:n,height:r,data:i}=t,s=(f)=>{for(let l=f*n*4+3,d=l+n*4;l<d;l+=4)if(i[l]>=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 f=o;f<=a;f++){let l=f*n*4+3;for(let d=0;d<c;d++)if(i[l+d*4]>=e){c=d;break}for(let d=n-1;d>u;d--)if(i[l+d*4]>=e){u=d;break}}return{x:c,y:o,w:u-c+1,h:a-o+1}}function nr(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)<Yw)n++;return Math.round(n*100/(e.w*e.h))}function e0(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=ma(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 f=0;f<s;f++)a.set(o.data.subarray(f*i*4,(f+1)*i*4),((u+f)*e+c)*4);return{width:e,height:n,data:a}}function yI(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 Ad(t,e,n,r){if(n===r&&Number.isInteger(e)&&e>=0&&e+r<=t)return{first:Int32Array.from({length:r},(f,l)=>e+l),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 f=0;f<r;f++){let l=e+(f+0.5)*i,d=Math.floor(l-o-0.5),h=Math.max(0,Math.min(t-a,d));c[f]=h;let m=0;for(let g=d;g<=Math.ceil(l+o-0.5);g++){let b=yI((g+0.5-l)/s),w=f*a+Math.min(t-1,Math.max(0,g))-h;u[w]=(u[w]??0)+b,m+=b}for(let g=f*a;g<(f+1)*a;g++)u[g]=(u[g]??0)/m}return{first:c,size:a,weights:u}}function n0(t,e,n,r,i,s,o){let a=Ad(t,e.y,e.h,r),c=n*i,u=a.size+1,f=Array.from({length:u},()=>new Float32Array(c)),l=new Int32Array(u).fill(-1),d=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,x=S%u,M=f[x];if(l[x]!==S)s(S,M),l[x]=S;h.push(M),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],x=h[w+2],M=h[w+3],N=m[w+1],C=m[w+2],P=m[w+3];if(w===0)for(let _=0;_<c;_++)d[_]=k[_]*v+S[_]*N+x[_]*C+M[_]*P;else for(let _=0;_<c;_++)d[_]=d[_]+(k[_]*v+S[_]*N+x[_]*C+M[_]*P);w+=4}else{if(w===0)for(let S=0;S<c;S++)d[S]=k[S]*v;else for(let S=0;S<c;S++)d[S]=d[S]+k[S]*v;w+=1}}if(h.length===0)d.fill(0);o(g,d)}}function r0(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 ma(t,e,n,r){let i=Ad(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 n0(t.height,e,n,r,4,(u,f)=>{let l=u*o*4,d=o,h=-1;for(let b=0,w=0;b<o*4;b+=4,w++){let k=s[l+b+3];if(k===0){a[b]=0,a[b+1]=0,a[b+2]=0,a[b+3]=0;continue}if(w<d)d=w;h=w,a[b]=s[l+b]*k,a[b+1]=s[l+b+1]*k,a[b+2]=s[l+b+2]*k,a[b+3]=k}if(f.fill(0),h<0)return;let[m,g]=r0(i.first,i.size,n,d,h);for(let b=m;b<g;b++){let w=i.first[b]*4,k=b*i.size,v=0,S=0,x=0,M=0;for(let N=0;N<i.size;N++){let C=i.weights[k+N],P=w+N*4;v+=a[P]*C,S+=a[P+1]*C,x+=a[P+2]*C,M+=a[P+3]*C}f[b*4]=v,f[b*4+1]=S,f[b*4+2]=x,f[b*4+3]=M}},(u,f)=>{let l=u*n*4;for(let d=0;d<n;d++){let h=d*4,m=f[h+3];if(m<=0)continue;let g=f[h]/m;c[l+h]=(g<0?0:g>255?255:g)+0.5,g=f[h+1]/m,c[l+h+1]=(g<0?0:g>255?255:g)+0.5,g=f[h+2]/m,c[l+h+2]=(g<0?0:g>255?255:g)+0.5,c[l+h+3]=(m>255?255:m)+0.5}}),{width:n,height:r,data:c}}function i0(t,e,n,r){let i=Ad(t.width,e.x,e.w,n),s=t.data,o=t.width,a=new Float32Array(n*r);return n0(t.height,e,n,r,1,(c,u)=>{let f=c*o,l=o,d=-1;for(let g=0;g<o;g++)if(s[f+g]!==0){if(g<l)l=g;d=g}if(u.fill(0),d<0)return;let[h,m]=r0(i.first,i.size,n,l,d);for(let g=h;g<m;g++){let b=f+i.first[g],w=g*i.size,k=0;for(let v=0;v<i.size;v++)k+=s[b+v]*i.weights[w+v];u[g]=k}},(c,u)=>{a.set(u,c*n)}),{width:n,height:r,data:a}}function pa(t,e){if(e<=0)return t;let n=Math.max(1,Math.ceil(e*3)),r=Array.from({length:2*n+1},(f,l)=>Math.exp(-((l-n)**2)/(2*e*e))),i=r.reduce((f,l)=>f+l,0),{width:s,height:o,data:a}=t,c=new Float32Array(s*o);for(let f=0;f<o;f++){let l=f*s;for(let d=0;d<s;d++){let h=0;for(let m=-n;m<=n;m++)h+=(a[l+Math.min(s-1,Math.max(0,d+m))]??0)*(r[m+n]??0);c[l+d]=h/i}}let u=new Float32Array(s*o);for(let f=0;f<o;f++){let l=f*s;for(let d=-n;d<=n;d++){let h=(r[d+n]??0)/i,m=Math.min(o-1,Math.max(0,f+d))*s;for(let g=0;g<s;g++)u[l+g]=(u[l+g]??0)+(c[m+g]??0)*h}}return{width:s,height:o,data:u}}function ga(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 Ai(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 vI=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 SI(t){let e=4294967295;for(let n of t)e=(vI[(e^n)&255]??0)^e>>>8;return(e^4294967295)>>>0}function Fr(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(SI(n.subarray(4,8+e.length)),8+e.length),n}function s0(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 o0(t){return gI(t,{level:1,strategy:pI.Z_RLE})}function a0(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(Ws),Fr("IHDR",r),...n,Fr("IDAT",o0(s0(t.data,t.width,t.height))),Fr("IEND",new Uint8Array)])}function c0(t){let[e,n,r]=ct(t),i=new Uint8Array(768);for(let s=0;s<256;s++)i.set([e,n,r],s*3);return Fr("PLTE",i)}function u0(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(Ws),Fr("IHDR",s),Fr("IDAT",o0(s0(i,t*r,e))),Fr("IEND",new Uint8Array)])}function _r(t){return u0(t.width,t.height,2,3,t.data)}function qe(t){return u0(t.width,t.height,6,4,t.data)}function Ni(t,e){return a0(t,Vw,[c0(e),Fr("tRNS",Uint8Array.from({length:256},(n,r)=>r))])}function Nd(t){return a0(t,0,[])}function iu(t,e){if(!Ii(t)||t[25]!==Vw)return;let n=Buffer.from(t.buffer,t.byteOffset,t.byteLength),r=[Buffer.from(Ws)],i=Ws.length;while(i+8<=n.length){let s=i+12+n.readUInt32BE(i);r.push(n.toString("latin1",i+4,i+8)==="PLTE"?c0(e):n.subarray(i,s)),i=s}return Buffer.concat(r)}var xn=100,Ae=25000000,II=536870912,Ks=["safe","questionable","explicit"],Ti=["nudity","underwear"],Fd=["comic","monochrome","sketch","chibi"],w0=["off","5","10","25","50","100"],$0=["off","720","1080","1440","1800","2560"],k0={nudity:new Set(["nude","naked","topless","bottomless","nipples","naked_towel","undressing"]),underwear:new Set(["underwear","panties","pantsu","bra","lingerie","pantyshot"])},AI={comic:new Set(["comic","4koma"]),monochrome:new Set(["monochrome","greyscale"]),sketch:new Set(["sketch","lineart","line_art"]),chibi:new Set(["chibi"])},NI=/^(?:rating|score|width|height|filetype|dimension):/,ba={safe:"s",questionable:"q",explicit:"e"},y0=8191,TI=20000,v0=5000,l0=3000,f0=8,HI=8,LI=8000,FI=3000,S0=60000,d0=3,CI=3,jI="https://static.zerochan.net",E0="https://s1.zerochan.net",Cd=`ttheme/${dt.version} (+${dt.homepage})`,_I=["orig","tile","thumb","cut"],M0=new Map,GI=rA(process.env.TTHEME_FIND_HOSTS),BI=nA(process.env.TTHEME_FIND_CUTOUTS);OI(FI);var UI=["artist","character","copyright"];function h0(t){try{return EI(t)}catch{return[]}}function zs(t){return t.startsWith("//")?`https:${t}`:t}function Gr(t){return(/\.([a-z0-9]+)(?:\?.*)?$/i.exec(t)?.[1]??"").toLowerCase()}function qs(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 WI(t){let e=t.trim(),r=(e?JSON.parse(e):{}).tags??{};return new Map(Object.entries(r).map(([i,s])=>[i,String(s)]))}function Hd(t,e,n){let r=zs(String(t??""));return{file:r,width:Number(e)||0,height:Number(n)||0,ext:Gr(r)}}function rr(t){return String(t??"").split(/\s+/).filter(Boolean)}function Ld(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 x0(t,e){let n=zs(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:rr(e.tags),named:e.named,...Ld(t.created_at)?{posted:Ld(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 KI(t){let e=WI(t);return qs(t).flatMap((n)=>{let r=zs(String(n.file_url??"")),i=String(n.tags??""),s=(o)=>rr(i).filter((a)=>e.get(a)===o);return x0(n,{preview:n.preview_url,file:r,ext:String(n.file_ext||Gr(r)).toLowerCase(),owner:n.author,md5:n.md5,tags:i,named:{artist:s("artist"),character:s("character"),copyright:s("copyright")},solo:void 0,versions:[Hd(n.jpeg_url,n.jpeg_width,n.jpeg_height),Hd(n.sample_url,n.sample_width,n.sample_height)]})})}function zI(t){return qs(t).flatMap((e)=>{let n=zs(String(e.file_url??"")),r=String(e.tag_string??""),i=e.media_asset??{};return x0(e,{preview:i.variants?.find((s)=>s.type==="360x360")?.url??e.preview_file_url,file:n,ext:String(e.file_ext||Gr(n)).toLowerCase(),owner:"",md5:e.md5,tags:r,named:{artist:rr(e.tag_string_artist),character:rr(e.tag_string_character),copyright:rr(e.tag_string_copyright)},solo:r.split(/\s+/).includes("solo"),versions:(i.variants??[]).map((s)=>Hd(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 O0(t){return t.toLowerCase().replace(/\s+/g,"_")}function qI(t){return(Array.isArray(t)?t:[]).map((e)=>O0(String(e)))}function DI(t){return String(t??"").replace(/[^0-9a-z]+/gi,".").replace(/^\.+|\.+$/g,"")||"zerochan"}function JI(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=qI(i.tags),a=zs(String(i.full??""));return[{id:s,width:Number(i.width)||0,height:Number(i.height)||0,file:a,ext:Gr(a),preview:`${E0}/${DI(i.tag??i.primary)}.600.${s}.jpg`,owner:"",score:0,rating:o.some((c)=>k0.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 YI={mangaka:"artist",studio:"artist",character:"character",series:"copyright",game:"copyright"};function m0(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 VI(t){let e={artist:[],character:[],copyright:[]};for(let[,r,i]of t.matchAll(/<li class="([a-z]+)[^"]*"[^>]*\bdata-tag="([^"]*)"/g)){let s=YI[r],o=O0(m0(i));if(s&&!e[s].includes(o))e[s].push(o)}let n=Ld(/"datePublished":\s*"([^"]+)"/.exec(t)?.[1]);return{named:e,source:"",owner:m0(/\buploader = \{\s*name: '([^']*)'/.exec(t)?.[1]??""),...n?{posted:n}:{}}}function ZI(t){return Number(/Zerochan has ([\d,]+) /.exec(t)?.[1]?.replace(/,/g,"")??0)}function XI(t){return qs(t).flatMap((e)=>{let n=String(e.value??"");return n?[{value:n,count:Number(e.post_count)||0}]:[]})}function QI(t){return qs(t).flatMap((e)=>{let n=String(e.name??"");return n?[{value:n,count:Number(e.count)||0}]:[]})}function tA(t){return Number(/count="(\d+)"/.exec(t)?.[1]??0)}function eA(t){let n=(t.trim()?JSON.parse(t):{}).counts?.posts;return n===null?Number.NaN:Number(n)||0}function nA(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 rA(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 su(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 Hi(t){return su(t,Ks,["safe"])}function Ds(t){return su(t,Ti,Ti,"none")}function ou(t){return su(t,Fd,[],"none")}function $a(t){let e=Z.map((n)=>n.name);return su(t,e,e)}function jd(t,e,n){return{score:Number(t)||0,size:Number(e)||0,png:n==="on"}}function ka(t){return[...new Set((t??"").toLowerCase().split(/[\s,]+/).map((e)=>e.replace(/^-+/,"")).filter(Boolean))]}function _d(t,e,n){return{safe:new Set(t),questionable:new Set(e),explicit:new Set(n)}}function Gd(t){let e=GI.get(t.key),n=BI.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 P0(t){return t.length<2?t.join(""):t.map((e)=>`~${e}`).join(" ")}function R0(t){return t>0?[`width:>=${t}`,`height:>=${t}`]:[]}function p0(t){let e=Gd(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}`]:[],...R0(i)],cutouts:P0(e.cutouts),ratings:_d([ba.safe],[ba.questionable],[ba.explicit]),rate:(r)=>{let[i]=r;if(r.length===1&&i)return`rating:${ba[i]}`;let s=Ks.filter((a)=>!r.includes(a)),[o]=s;return s.length===1&&o?`-rating:${ba[o]}`:""},best:"order:score",tagBudget:Number.POSITIVE_INFINITY,ors:!0,postsUrl:(r,i)=>`${e.origin}/post.json?${n({limit:String(xn),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:KI,count:tA,uploadedBy:(r)=>`user:${r}`}}function iA(t){let e=Gd(t),n=_d(["g"],["s","q"],["e"]);return{...e,scored:!0,narrow:({score:r,size:i,png:s})=>[...r>0?[`score:>=${r}`]:[],...R0(i),...s?["filetype:png"]:[]],cutouts:P0(e.cutouts),ratings:n,rate:(r)=>r.length===Ks.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(xn),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:zI,count:eA,uploadedBy:(r)=>`user:${r}`}}function Td(t){return t.split(/\s+/).filter((e)=>e&&!/^(?:order|dimension):/.test(e)).map((e)=>e.split("_").map(encodeURIComponent).join("+")).join(",")}function g0(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 sA(t){let e=Gd(t);return{...e,scored:!1,narrow:({size:n})=>n>=1800?["dimension:huge"]:n>0?["dimension:large"]:[],cutouts:e.cutouts[0]??"",ratings:_d(["g"],["q"],["e"]),rate:()=>"",best:"order:fav",tagBudget:3,ors:!1,missing:404,postsUrl:(n,r)=>`${e.origin}/${Td(n)}?${new URLSearchParams({json:"",l:String(xn),p:String(r+1),...g0(n)})}`,countUrl:(n)=>`${e.origin}/${Td(n)}?${new URLSearchParams({xml:"",l:"1"})}`,postUrl:(n)=>`${e.origin}/${n}?json=`,pageUrl:(n)=>`${e.origin}/${n}`,parse:JI,count:ZI,credits:VI,counts:(n)=>Td(n).split(",").length===1&&!("d"in g0(n)),guesses:(n)=>(n.tags.includes("transparent_background")?["png","jpg"]:["jpg","png"]).map((r)=>n.preview.replace(E0,jI).replace(/\.600\.(\d+)\.jpg$/,`.full.$1.${r}`))}}function oA(t){let e=b0(`https://${t}`);return Z.find((n)=>b0(n.origin)===e)}function Bd(t){return t.split(/\s+/).filter((e)=>e&&!NI.test(e)).length}function au(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=Z.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=oA(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 Z=[iA({key:"danbooru",name:"danbooru",origin:"https://shima.donmai.us",cutouts:["transparent_background"],vouched:!1,ansi:2}),p0({key:"konachan",name:"konachan",origin:"https://konachan.net",cutouts:["transparent","vector"],vouched:!1,ansi:6}),p0({key:"yande",name:"yande.re",origin:"https://yande.re",cutouts:["transparent_png"],vouched:!0,ansi:5}),sA({key:"zerochan",name:"zerochan",origin:"https://www.zerochan.net",cutouts:["transparent_background"],vouched:!1,ansi:3})],Pt=Z.find((t)=>t.key==="danbooru"),Br=134217728;function Ne(t,e){let n=Z.indexOf(t);return(n===-1?Z.length:n)*Br+e}function b0(t){let e;try{e=new URL(t).hostname}catch{return""}return e.split(".").slice(-2).join(".")}function Li(t,e,n=e){return e.mirror&&n===e?{site:Pt,url:e.mirror.file}:{site:t,url:n.file}}function cu(t,e){return e.mirror?{site:Pt,url:e.mirror.preview}:{site:t,url:e.preview}}function uu(t,e=Ti){return t.tags.filter((n)=>e.some((r)=>k0[r].has(n)))}function I0(t,e){return t.tags.filter((n)=>e.some((r)=>AI[r].has(n)))}function lu(t,e,n=["safe"]){return n.some((r)=>t.ratings[r].has(e.rating))}function A0(t,e){return t.rate(["safe"])===""?void 0:Ks.find((n)=>t.ratings[n].has(e.rating))}function Pn(t){return[t,...t.smaller].find((e)=>e.width*e.height<=Ae)}function N0(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 Rn(){return wa(process.env.XDG_CACHE_HOME??wa(PI(),".cache"),"ttheme")}function an(t){return wa(Rn(),t.key)}function T0(t=II,e=Rn()){let n=[],r=0;for(let i of h0(e))for(let s of _I){let o=wa(e,i,s);for(let a of h0(o)){let c=wa(o,a);try{let{size:u,mtimeMs:f}=xI(c);n.push({path:c,size:u,at:f}),r+=u}catch{}}}n.sort((i,s)=>i.at-s.at);for(let i of n){if(r<=t)return;try{MI(i.path,{force:!0}),r-=i.size}catch{}}}function aA(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)?S0:Math.max(0,n-e)}function On(t){return M0.get(t.key)??0}function cA(t){for(let e=t;e instanceof Error;e=e.cause)if(e.code==="ECONNRESET")return!0;return!1}function uA(t){return(t.headers.get("server")??"").startsWith("cloudflare")&&t.headers.get("cf-mitigated")==="challenge"}function lA(t,e){let n=new URL(e,t);if(!n.search)n.search=new URL(t).search;return n.href}async function ir(t,e,n,r={},i=TI){let s=e;for(let o=1,a=0;;o++){let c=On(t)-Date.now();if(c>0)await RI(c,void 0,{signal:n});let u;try{u=await fetch(s,{headers:{"User-Agent":Cd,Referer:`${t.origin}/`,...r},redirect:"manual",signal:i?AbortSignal.any([n,AbortSignal.timeout(i)]):n})}catch(l){if(o<d0&&!n.aborted&&cA(l))continue;throw l}let f=u.headers.get("location");if(f&&u.status>=300&&u.status<400&&a<CI){await u.body?.cancel(),s=lA(s,f),a++,o--;continue}if(u.status===429&&o<d0){await u.body?.cancel();let l=aA(u.headers.get("retry-after"),Date.now());if(l>S0)throw Error(`${t.name} asks to wait ${Math.ceil(l/1000)}s`);M0.set(t.key,Math.max(On(t),Date.now()+l));continue}if(!u.ok)throw await u.body?.cancel(),Object.assign(Error(uA(u)?`${t.name} is behind a Cloudflare challenge`:`${t.name} answered ${u.status}`),{status:u.status});return u}}async function fu(t,e,n){try{return await(await ir(t,e,n)).text()}catch(r){if(t.missing!==void 0&&r.status===t.missing)return"";throw r}}async function H0(t,e,n,r){return t.parse(await fu(t,t.postsUrl(e,n),r))}async function Ud(t,e,n){return t.count(await fu(t,t.countUrl(e),n))}async function Fi(t,e,n){let[r]=t.parse(await fu(t,t.postUrl(e),n));return r}async function ya(t,e,n){return t.credits?.(await fu(t,t.pageUrl(e),n))}var fA=/^https?:\/\/(?:i\.pximg\.net|i\d*\.pixiv\.net|img\d*\.pixiv\.net)\/\S*\/(\d+)(?:_p\d+)?(?:_\w+)?\.\w+(?:[?#]\S*)?$/i,dA=/^https?:\/\/(?:www\.)?pixiv\.net\/member_illust\.php\?\S*\billust_id=(\d+)/i;function Ci(t){let e=fA.exec(t)?.[1]??dA.exec(t)?.[1];return e?`https://www.pixiv.net/artworks/${e}`:t}function va(t,e){return t.credits!==void 0&&e.named.artist.length===0}function Js(t,e){for(let n of UI){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 hA(t){let e=new URLSearchParams({limit:String(2*xn),only:"md5,tag_string,tag_string_artist,tag_string_character,tag_string_copyright,source,file_url",tags:`md5:${t.join(",")}`});return`${Pt.origin}/posts.json?${e}`}function mA(t){return new Map(qs(t).flatMap((e)=>{let n=String(e.md5??"");return n?[[n,{tags:rr(e.tag_string),named:{artist:rr(e.tag_string_artist),character:rr(e.tag_string_character),copyright:rr(e.tag_string_copyright)},source:String(e.source??""),file:zs(String(e.file_url??""))}]]:[]}))}function Sa(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])],Js(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=Gr(r.file)}}}async function Ea(t,e){let n=new Map;if(On(Pt)>Date.now())return n;for(let r=0;r<t.length;r+=xn){let i=await(await ir(Pt,hA(t.slice(r,r+xn)),e,{},v0)).text();for(let[s,o]of mA(i))n.set(s,o)}return n}function pA(t){let e=new URLSearchParams([...t.map((n)=>["search[name_array][]",n]),["only","name,is_deleted,urls"],["limit",String(t.length)]]);return`${Pt.origin}/artists.json?${e}`}function gA(t){return new Map(qs(t).flatMap((e)=>{let n=String(e.name??"");if(!n||e.is_deleted===!0)return[];let r=Array.isArray(e.urls)?e.urls:[];return[[n,r.flatMap((i)=>i.is_active===!1||!i.url?[]:[String(i.url)])]]}))}async function L0(t,e){let n=new Map;if(On(Pt)>Date.now())return n;for(let r=0;r<t.length;r+=xn){let i=await(await ir(Pt,pA(t.slice(r,r+xn)),e,{},v0)).text();for(let[s,o]of gA(i))n.set(s,o)}return n}async function Ma(t,e,n){if(e.file||!t.guesses)return;for(let r of t.guesses(e))try{let i=await ir(t,r,n,{Range:`bytes=0-${y0}`}),s=Mn(new Uint8Array(await i.arrayBuffer()));return e.file=r,e.ext=Gr(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 F0(t,e){if(On(Pt)<=Date.now())try{let i=new URLSearchParams({"search[query]":t,"search[type]":"tag_query",limit:String(f0)}),s=`${Pt.origin}/autocomplete.json?${i}`;return XI(await(await ir(Pt,s,e,{},l0)).text())}catch(i){if(e.aborted)throw i}let n=Z.find((i)=>i.key==="yande"),r=new URLSearchParams({name:t,order:"count",limit:String(f0)});return QI(await(await ir(n,`${n.origin}/tag.json?${r}`,e,{},l0)).text())}function bA(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 C0(t,e){if(On(Pt)>Date.now())return[];let n=new URLSearchParams({"search[query]":t,"search[category]":"character",limit:String(HI)});return bA(await(await ir(Pt,`${Pt.origin}/related_tag.json?${n}`,e,{},LI)).text())}function j0(t,e){return e.slice(0,t.ors?t.tagBudget:1)}async function _0(t,e,n){let r=await ir(t,e,n,{Range:`bytes=0-${y0}`});return Mn(new Uint8Array(await r.arrayBuffer()))}async function du(t,e,n,r){let i=await ir(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:l,value:d}=await o.read();if(l)break;a.push(d),c+=d.length,r?.(c,s)}let u=new Uint8Array(c),f=0;for(let l of a)u.set(l,f),f+=l.length;return u}var wA=["pixiv","x","bsky","fanbox","skeb","patreon","fantia"],G0=[["pixiv",/^https?:\/\/(?:www\.)?pixiv\.net\/(?:en\/)?users\/(\d+)\/?$/i,(t)=>`https://www.pixiv.net/users/${t}`],["pixiv",/^https?:\/\/(?:www\.)?pixiv\.net\/member\.php\?id=(\d+)$/i,(t)=>`https://www.pixiv.net/users/${t}`],["x",/^https?:\/\/(?:www\.|mobile\.)?(?:twitter|x)\.com\/(?!(?:i|intent|home|search|explore|hashtag|share|settings)\/?$)(\w{1,15})\/?$/i,(t)=>`https://x.com/${t}`],["bsky",/^https?:\/\/bsky\.app\/profile\/(?!did:)([\w.-]+)\/?$/i,(t)=>`https://bsky.app/profile/${t}`],["fanbox",/^https?:\/\/([\w-]+)\.fanbox\.cc\/?$/i,(t)=>`https://${t}.fanbox.cc`],["fanbox",/^https?:\/\/(?:www\.)?pixiv\.net\/fanbox\/creator\/(\d+)\/?$/i,(t)=>`https://www.pixiv.net/fanbox/creator/${t}`],["skeb",/^https?:\/\/skeb\.jp\/@([\w-]+)\/?$/i,(t)=>`https://skeb.jp/@${t}`],["patreon",/^https?:\/\/(?:www\.)?patreon\.com\/(?:c\/)?(?!(?:user|posts|join|home|login|search)\/?$)([\w-]+)\/?$/i,(t)=>`https://www.patreon.com/${t}`],["fantia",/^https?:\/\/fantia\.jp\/fanclubs\/(\d+)\/?$/i,(t)=>`https://fantia.jp/fanclubs/${t}`]],$A=[[/^https?:\/\/(?:www\.)?pixiv\.net\/(?:en\/)?artworks\/(\d+)/i,(t)=>`pixiv ${t[1]}`],[/^https?:\/\/(?:www\.|mobile\.)?(?:twitter|x)\.com\/(\w{1,15})\/status\/\d+/i,(t)=>`x ${t[1]}`],[/^https?:\/\/bsky\.app\/profile\/([\w.-]+)\/post\//i,(t)=>`bsky ${t[1]}`],[/^https?:\/\/([\w-]+)\.fanbox\.cc\/posts\/\d+/i,(t)=>`fanbox ${t[1]}`]],kA=[[/^https?:\/\/(?:www\.)?pixiv\.net\//i,"pixiv"],[/^https?:\/\/(?:www\.|mobile\.)?(?:twitter|x)\.com\//i,"x"],[/^https?:\/\/bsky\.app\//i,"bsky"]],yA=["x","pixiv","bsky"],vA={"shima.donmai.us":"danbooru.donmai.us"},SA=/^https?:\/\/[^\s\p{Cc}]+$/u;function B0(t){return SA.test(t)}function EA(t){return G0.find(([,e])=>e.test(t))?.[0]}function MA(t){return wA.flatMap((e)=>{for(let[n,r,i]of G0){if(n!==e)continue;for(let s of t){let o=r.exec(s)?.[1];if(o)return[i(o)]}}return[]})}function xa(t){return(t??[]).flatMap((e)=>{let n=EA(e);return n?[{kind:n,url:e}]:[]})}function xA(t){for(let[e,n]of $A){let r=e.exec(t);if(r)return n(r)}try{return new URL(t).hostname.replace(/^www\./,"")}catch{return t}}function OA(t){try{let e=new URL(t),n=vA[e.hostname];if(n)e.hostname=n;return e.href}catch{return t}}function PA(t){return t.replace(/^https?:\/\/(?:www\.)?/,"")}function Wd(t){let e=t.source??"";return B0(e)?{label:xA(e),url:e}:void 0}function RA(t){let e=(t.from??"").split(" "),n=e[2]??"";return B0(n)?{label:e.slice(0,2).join(" "),url:n}:void 0}function IA(t,e){let n=e?kA.find(([i])=>i.test(e))?.[1]:void 0,r=xa(t);return yA.flatMap((i)=>i===n?[]:r.filter((s)=>s.kind===i))[0]?.url}function U0(t){let e=Wd(t)?.url??RA(t)?.url,n=t.artist??[];if(!e&&n.length===0)return;let r=n.length>0?`Background art by ${n.map((i)=>{let s=IA(t.profiles?.[i],e);return s?`${i} (${PA(s)})`:i}).join(", ")}`:"Background art (artist unknown)";return e?`${r} · ${OA(e)}`:r}async function hu(t,e){let n=await L0(t,e);return new Map(t.map((r)=>[r,MA(n.get(r)??[])]))}import{createHash as AA}from"node:crypto";import{existsSync as NA,readdirSync as TA,readFileSync as HA,rmSync as LA,statSync as FA,utimesSync as CA}from"node:fs";import{join as Vs}from"node:path";var jA=12,_A=/^[0-9a-f]{40}$/;function Ys(){return Vs(Rn(),"drawn")}function W0(t){return AA("sha1").update(JSON.stringify(t)).digest("hex")}function K0(t){return NA(Vs(Ys(),t))}function z0(t){let e=Vs(Ys(),t);try{let n=HA(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 CA(e,a,a),{stem:i.stem,fill:i.fill,...i.peak?{peak:i.peak}:{},figure:s,picture:o}}catch{return}}function Kd(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),L(Vs(Ys(),t),Buffer.concat([r,n,e.figure,e.picture])),GA()}function GA(){let t=TA(Ys()).filter((e)=>_A.test(e)).flatMap((e)=>{try{return[{name:e,at:FA(Vs(Ys(),e)).mtimeMs}]}catch{return[]}}).sort((e,n)=>n.at-e.at);for(let{name:e}of t.slice(jA))LA(Vs(Ys(),e),{force:!0})}import{readdirSync as Z0,readFileSync as X0}from"node:fs";import{basename as DA,join as bu}from"node:path";/*!
2
+ import{createRequire as eI}from"node:module";var JP=Object.create;var{getPrototypeOf:YP,defineProperty:Jb,getOwnPropertyNames:VP}=Object;var ZP=Object.prototype.hasOwnProperty;function XP(t){return this[t]}var QP,tI,gd=(t,e,n)=>{var r=t!=null&&typeof t==="object";if(r){var i=e?QP??=new WeakMap:tI??=new WeakMap,s=i.get(t);if(s)return s}n=t!=null?JP(YP(t)):{};let o=e||!t||!t.__esModule?Jb(n,"default",{value:t,enumerable:!0}):n;for(let a of VP(t))if(!ZP.call(o,a))Jb(o,a,{get:XP.bind(t,a),enumerable:!0});if(r)i.set(t,o);return o};var Ot=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Qt=eI(import.meta.url);var vd=Ot((pB,uw)=>{var hI=Qt("util"),cw=Qt("stream"),cn=uw.exports=function(){cw.call(this),this._buffers=[],this._buffered=0,this._reads=[],this._paused=!1,this._encoding="utf8",this.writable=!0};hI.inherits(cn,cw);cn.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))};cn.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};cn.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()};cn.prototype.destroySoon=cn.prototype.end;cn.prototype._end=function(){if(this._reads.length>0)this.emit("error",Error("Unexpected end of input"));this.destroy()};cn.prototype.destroy=function(){if(!this._buffers)return;this.writable=!1,this._reads=null,this._buffers=null,this.emit("close")};cn.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)};cn.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)};cn.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 Sd=Ot((mI)=>{var Cr=[{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]}];mI.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<Cr.length;a++){let c=Cr[a],u=s*c.x.length,f=o*c.y.length;for(let l=0;l<c.x.length;l++)if(c.x[l]<r)u++;else break;for(let l=0;l<c.y.length;l++)if(c.y[l]<i)f++;else break;if(u>0&&f>0)n.push({width:u,height:f,index:a})}return n};mI.getInterlaceIterator=function(t){return function(e,n,r){let i=e%Cr[r].x.length,s=(e-i)/Cr[r].x.length*8+Cr[r].x[i],o=n%Cr[r].y.length,a=(n-o)/Cr[r].y.length*8+Cr[r].y[o];return s*4+a*t*4}}});var Ed=Ot((bB,lw)=>{lw.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 Md=Ot((wB,dw)=>{var bI=Sd(),wI=Ed();function fw(t,e,n){let r=t*e;if(n!==8)r=Math.ceil(r/(8/n));return r}var Ws=dw.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=bI.getImagePasses(n,r);for(let c=0;c<a.length;c++)this._images.push({byteWidth:fw(a[c].width,s,o),height:a[c].height,lineIndex:0})}else this._images.push({byteWidth:fw(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};Ws.prototype.start=function(){this.read(this._images[this._imageIndex].byteWidth+1,this._reverseFilterLine.bind(this))};Ws.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}};Ws.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}};Ws.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,f=Math.floor((u+c)/2);e[o]=a+f}};Ws.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,f=o>i&&s?s[o-r]:0,l=wI(u,c,f);e[o]=a+l}};Ws.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 pw=Ot(($B,mw)=>{var $I=Qt("util"),hw=vd(),kI=Md(),yI=mw.exports=function(t){hw.call(this);let e=[],n=this;this._filter=new kI(t,{read:this.read.bind(this),write:function(r){e.push(r)},complete:function(){n.emit("complete",Buffer.concat(e))}}),this._filter.start()};$I.inherits(yI,hw)});var Ks=Ot((kB,gw)=>{gw.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 Pd=Ot((yB,bw)=>{var xd=[];(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;xd[t]=e}})();var Od=bw.exports=function(){this._crc=-1};Od.prototype.write=function(t){for(let e=0;e<t.length;e++)this._crc=xd[(this._crc^t[e])&255]^this._crc>>>8;return!0};Od.prototype.crc32=function(){return this._crc^-1};Od.crc32=function(t){let e=-1;for(let n=0;n<t.length;n++)e=xd[(e^t[n])&255]^e>>>8;return e^-1}});var Id=Ot((vB,ww)=>{var Bt=Ks(),vI=Pd(),Wt=ww.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[Bt.TYPE_IHDR]=this._handleIHDR.bind(this),this._chunks[Bt.TYPE_IEND]=this._handleIEND.bind(this),this._chunks[Bt.TYPE_IDAT]=this._handleIDAT.bind(this),this._chunks[Bt.TYPE_PLTE]=this._handlePLTE.bind(this),this._chunks[Bt.TYPE_tRNS]=this._handleTRNS.bind(this),this._chunks[Bt.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(){}};Wt.prototype.start=function(){this.read(Bt.PNG_SIGNATURE.length,this._parseSignature.bind(this))};Wt.prototype._parseSignature=function(t){let e=Bt.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))};Wt.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!==Bt.TYPE_IHDR){this.error(Error("Expected IHDR on beggining"));return}if(this._crc=new vI,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))};Wt.prototype._skipChunk=function(){this.read(8,this._parseChunkBegin.bind(this))};Wt.prototype._handleChunkEnd=function(){this.read(4,this._parseChunkEnd.bind(this))};Wt.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))};Wt.prototype._handleIHDR=function(t){this.read(t,this._parseIHDR.bind(this))};Wt.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 Bt.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=Bt.COLORTYPE_TO_BPP_MAP[this._colorType];this._hasIHDR=!0,this.metadata({width:e,height:n,depth:r,interlace:Boolean(a),palette:Boolean(i&Bt.COLORTYPE_PALETTE),color:Boolean(i&Bt.COLORTYPE_COLOR),alpha:Boolean(i&Bt.COLORTYPE_ALPHA),bpp:c,colorType:i}),this._handleChunkEnd()};Wt.prototype._handlePLTE=function(t){this.read(t,this._parsePLTE.bind(this))};Wt.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()};Wt.prototype._handleTRNS=function(t){this.simpleTransparency(),this.read(t,this._parseTRNS.bind(this))};Wt.prototype._parseTRNS=function(t){if(this._crc.write(t),this._colorType===Bt.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===Bt.COLORTYPE_GRAYSCALE)this.transColor([t.readUInt16BE(0)]);if(this._colorType===Bt.COLORTYPE_COLOR)this.transColor([t.readUInt16BE(0),t.readUInt16BE(2),t.readUInt16BE(4)]);this._handleChunkEnd()};Wt.prototype._handleGAMA=function(t){this.read(t,this._parseGAMA.bind(this))};Wt.prototype._parseGAMA=function(t){this._crc.write(t),this.gamma(t.readUInt32BE(0)/Bt.GAMMA_DIVISION),this._handleChunkEnd()};Wt.prototype._handleIDAT=function(t){if(!this._emittedHeadersFinished)this._emittedHeadersFinished=!0,this.headersFinished();this.read(-t,this._parseIDAT.bind(this,t))};Wt.prototype._parseIDAT=function(t,e){if(this._crc.write(e),this._colorType===Bt.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()};Wt.prototype._handleIEND=function(t){this.read(t,this._parseIEND.bind(this))};Wt.prototype._parseIEND=function(t){if(this._crc.write(t),this._hasIEND=!0,this._handleChunkEnd(),this.finished)this.finished()}});var Rd=Ot((PI)=>{var $w=Sd(),SI=[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]}],EI=[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 MI(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,f,l,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:f=s&3,l=s>>2&3,d=s>>4&3,h=s>>6&3,n.push(h,d,l,f);break;case 1:o=s&1,a=s>>1&1,c=s>>2&1,u=s>>3&1,f=s>>4&1,l=s>>5&1,d=s>>6&1,h=s>>7&1,n.push(h,d,l,f,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 xI(t,e,n,r,i,s){let{width:o,height:a,index:c}=t;for(let u=0;u<a;u++)for(let f=0;f<o;f++){let l=n(f,u,c);SI[r](e,i,l,s),s+=r}return s}function OI(t,e,n,r,i,s){let{width:o,height:a,index:c}=t;for(let u=0;u<a;u++){for(let f=0;f<o;f++){let l=i.get(r),d=n(f,u,c);EI[r](e,l,d,s)}i.resetAfterLine()}}PI.dataToBitMap=function(t,e){let{width:n,height:r,depth:i,bpp:s,interlace:o}=e,a;if(i!==8)a=MI(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,f=0,l,d;if(o)l=$w.getImagePasses(n,r),d=$w.getInterlaceIterator(n,r);else{let h=0;d=function(){let m=h;return h+=4,m},l=[{width:n,height:r}]}for(let h=0;h<l.length;h++)if(i===8)f=xI(l[h],c,d,s,t,f);else OI(l[h],c,d,s,a,u);if(i===8){if(f!==t.length)throw Error("extra data found")}else a.end();return c}});var Ad=Ot((EB,kw)=>{function RI(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 AI(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 NI(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 f=0;f<4;f++)e[a+f]=Math.floor(t[a+f]*s/o+0.5);a+=4}}kw.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)RI(t,u,i,s,c);else{if(a)AI(t,u,i,s,a);if(r!==8&&!n){if(r===16)u=Buffer.alloc(i*s*4);NI(t,u,i,s,r)}}return u}});var Sw=Ot((MB,vw)=>{var TI=Qt("util"),Nd=Qt("zlib"),yw=vd(),HI=pw(),FI=Id(),LI=Rd(),CI=Ad(),Pn=vw.exports=function(t){yw.call(this),this._parser=new FI(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()};TI.inherits(Pn,yw);Pn.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};Pn.prototype._inflateData=function(t){if(!this._inflate)if(this._bitmapInfo.interlace)this._inflate=Nd.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,Nd.Z_MIN_CHUNK);this._inflate=Nd.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)};Pn.prototype._handleMetaData=function(t){this._metaData=t,this._bitmapInfo=Object.create(t),this._filter=new HI(this._bitmapInfo)};Pn.prototype._handleTransColor=function(t){this._bitmapInfo.transColor=t};Pn.prototype._handlePalette=function(t){this._bitmapInfo.palette=t};Pn.prototype._simpleTransparency=function(){this._metaData.alpha=!0};Pn.prototype._headersFinished=function(){this.emit("metadata",this._metaData)};Pn.prototype._finished=function(){if(this.errord)return;if(!this._inflate)this.emit("error","No Inflate block");else this._inflate.end()};Pn.prototype._complete=function(t){if(this.errord)return;let e;try{let n=LI.dataToBitMap(t,this._bitmapInfo);e=CI(n,this._bitmapInfo,this._options.skipRescale),n=null}catch(n){this._handleError(n);return}this.emit("parsed",e)}});var Mw=Ot((xB,Ew)=>{var qe=Ks();Ew.exports=function(t,e,n,r){let i=[qe.COLORTYPE_COLOR_ALPHA,qe.COLORTYPE_ALPHA].indexOf(r.colorType)!==-1;if(r.colorType===r.inputColorType){let m=function(){let p=new ArrayBuffer(2);return new DataView(p).setInt16(0,256,!0),new Int16Array(p)[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=qe.COLORTYPE_TO_BPP_MAP[r.inputColorType];if(a===4&&!r.inputHasAlpha)a=3;let c=qe.COLORTYPE_TO_BPP_MAP[r.colorType];if(r.bitDepth===16)o=65535,c*=2;let u=Buffer.alloc(e*n*c),f=0,l=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,p,b,$=o;switch(r.inputColorType){case qe.COLORTYPE_COLOR_ALPHA:$=s[f+3],m=s[f],p=s[f+1],b=s[f+2];break;case qe.COLORTYPE_COLOR:m=s[f],p=s[f+1],b=s[f+2];break;case qe.COLORTYPE_ALPHA:$=s[f+1],m=s[f],p=m,b=m;break;case qe.COLORTYPE_GRAYSCALE:m=s[f],p=m,b=m;break;default:throw Error("input color type:"+r.inputColorType+" is not supported at present")}if(r.inputHasAlpha){if(!i)$/=o,m=Math.min(Math.max(Math.round((1-$)*d.red+$*m),0),o),p=Math.min(Math.max(Math.round((1-$)*d.green+$*p),0),o),b=Math.min(Math.max(Math.round((1-$)*d.blue+$*b),0),o)}return{red:m,green:p,blue:b,alpha:$}}for(let m=0;m<n;m++)for(let p=0;p<e;p++){let b=h(s,f);switch(r.colorType){case qe.COLORTYPE_COLOR_ALPHA:case qe.COLORTYPE_COLOR:if(r.bitDepth===8){if(u[l]=b.red,u[l+1]=b.green,u[l+2]=b.blue,i)u[l+3]=b.alpha}else if(u.writeUInt16BE(b.red,l),u.writeUInt16BE(b.green,l+2),u.writeUInt16BE(b.blue,l+4),i)u.writeUInt16BE(b.alpha,l+6);break;case qe.COLORTYPE_ALPHA:case qe.COLORTYPE_GRAYSCALE:{let $=(b.red+b.green+b.blue)/3;if(r.bitDepth===8){if(u[l]=$,i)u[l+1]=b.alpha}else if(u.writeUInt16BE($,l),i)u.writeUInt16BE(b.alpha,l+2);break}default:throw Error("unrecognised color Type "+r.colorType)}f+=a,l+=c}return u}});var Pw=Ot((OB,Ow)=>{var xw=Ed();function jI(t,e,n,r,i){for(let s=0;s<n;s++)r[i+s]=t[e+s]}function _I(t,e,n){let r=0,i=e+n;for(let s=e;s<i;s++)r+=Math.abs(t[s]);return r}function BI(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 GI(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 UI(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 WI(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 KI(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 zI(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 qI(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,f=t[e+o]-xw(a,c,u);r[i+o]=f}}function DI(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]-xw(o,a,c);i+=Math.abs(u)}return i}var JI={0:jI,1:BI,2:UI,3:KI,4:qI},YI={0:_I,1:GI,2:WI,3:zI,4:DI};Ow.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),f=s[0];for(let l=0;l<n;l++){if(s.length>1){let d=1/0;for(let h=0;h<s.length;h++){let m=YI[s[h]](t,c,o,i);if(m<d)f=s[h],d=m}}u[a]=f,a++,JI[f](t,c,o,u,a,i),a+=o,c+=o}return u}});var Td=Ot((PB,Iw)=>{var te=Ks(),VI=Pd(),ZI=Mw(),XI=Pw(),QI=Qt("zlib"),jr=Iw.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||QI.createDeflate,t.bitDepth=t.bitDepth||8,t.colorType=typeof t.colorType==="number"?t.colorType:te.COLORTYPE_COLOR_ALPHA,t.inputColorType=typeof t.inputColorType==="number"?t.inputColorType:te.COLORTYPE_COLOR_ALPHA,[te.COLORTYPE_GRAYSCALE,te.COLORTYPE_COLOR,te.COLORTYPE_COLOR_ALPHA,te.COLORTYPE_ALPHA].indexOf(t.colorType)===-1)throw Error("option color type:"+t.colorType+" is not supported at present");if([te.COLORTYPE_GRAYSCALE,te.COLORTYPE_COLOR,te.COLORTYPE_COLOR_ALPHA,te.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")};jr.prototype.getDeflateOptions=function(){return{chunkSize:this._options.deflateChunkSize,level:this._options.deflateLevel,strategy:this._options.deflateStrategy}};jr.prototype.createDeflate=function(){return this._options.deflateFactory(this.getDeflateOptions())};jr.prototype.filterData=function(t,e,n){let r=ZI(t,e,n,this._options),i=te.COLORTYPE_TO_BPP_MAP[this._options.colorType];return XI(r,e,n,this._options,i)};jr.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(VI.crc32(r.slice(4,r.length-4)),r.length-4),r};jr.prototype.packGAMA=function(t){let e=Buffer.alloc(4);return e.writeUInt32BE(Math.floor(t*te.GAMMA_DIVISION),0),this._packChunk(te.TYPE_gAMA,e)};jr.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(te.TYPE_IHDR,n)};jr.prototype.packIDAT=function(t){return this._packChunk(te.TYPE_IDAT,t)};jr.prototype.packIEND=function(){return this._packChunk(te.TYPE_IEND,null)}});var Tw=Ot((IB,Nw)=>{var tR=Qt("util"),Rw=Qt("stream"),eR=Ks(),nR=Td(),Aw=Nw.exports=function(t){Rw.call(this);let e=t||{};this._packer=new nR(e),this._deflate=this._packer.createDeflate(),this.readable=!0};tR.inherits(Aw,Rw);Aw.prototype.pack=function(t,e,n,r){if(this.emit("data",Buffer.from(eR.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 _w=Ot((wa,jw)=>{var Hw=Qt("assert").ok,zs=Qt("zlib"),rR=Qt("util"),Fw=Qt("buffer").kMaxLength;function Hi(t){if(!(this instanceof Hi))return new Hi(t);if(t&&t.chunkSize<zs.Z_MIN_CHUNK)t.chunkSize=zs.Z_MIN_CHUNK;if(zs.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 iR(t){return new Hi(t)}function Lw(t,e){if(e)process.nextTick(e);if(!t._handle)return;t._handle.close(),t._handle=null}Hi.prototype._processChunk=function(t,e,n){if(typeof n==="function")return zs.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,f;this.on("error",function(m){f=m});function l(m,p){if(r._hadError)return;let b=s-p;if(Hw(b>=0,"have should not go down"),b>0){let $=r._buffer.slice(r._offset,r._offset+b);if(r._offset+=b,$.length>o)$=$.slice(0,o);if(c.push($),u+=$.length,o-=$.length,o===0)return!1}if(p===0||r._offset>=r._chunkSize)s=r._chunkSize,r._offset=0,r._buffer=Buffer.allocUnsafe(r._chunkSize);if(p===0)return a+=i-m,i=m,!0;return!1}Hw(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&&l(d[0],d[1]));if(this._hadError)throw f;if(u>=Fw)throw Lw(this),RangeError("Cannot create final Buffer. It would be larger than 0x"+Fw.toString(16)+" bytes");let h=Buffer.concat(c,u);return Lw(this),h};rR.inherits(Hi,zs.Inflate);function sR(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=zs.Z_FINISH;return t._processChunk(e,n)}function Cw(t,e){return sR(new Hi(e),t)}jw.exports=wa=Cw;wa.Inflate=Hi;wa.createInflate=iR;wa.inflateSync=Cw});var Hd=Ot((RB,Gw)=>{var Bw=Gw.exports=function(t){this._buffer=t,this._reads=[]};Bw.prototype.read=function(t,e){this._reads.push({length:Math.abs(t),allowLess:t<0,func:e})};Bw.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 Uw=Ot((cR)=>{var oR=Hd(),aR=Md();cR.process=function(t,e){let n=[],r=new oR(t);return new aR(e,{read:r.read.bind(r),write:function(s){n.push(s)},complete:function(){}}).start(),r.process(),Buffer.concat(n)}});var qw=Ot((NB,zw)=>{var Ww=!0,Kw=Qt("zlib"),lR=_w();if(!Kw.deflateSync)Ww=!1;var fR=Hd(),dR=Uw(),hR=Id(),mR=Rd(),pR=Ad();zw.exports=function(t,e){if(!Ww)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 f(S){u=S}let l=[];function d(S){l.push(S)}let h=new fR(t);if(new hR(e,{read:h.read.bind(h),error:r,metadata:s,gamma:f,palette:a,transColor:o,inflateData:d,simpleTransparency:c}).start(),h.process(),n)throw n;let p=Buffer.concat(l);l.length=0;let b;if(i.interlace)b=Kw.inflateSync(p);else{let x=((i.width*i.bpp*i.depth+7>>3)+1)*i.height;b=lR(p,{chunkSize:x,maxLength:x})}if(p=null,!b||!b.length)throw Error("bad png - invalid inflate data response");let $=dR.process(b,i);p=null;let k=mR.dataToBitMap($,i);$=null;let v=pR(k,i,e.skipRescale);return i.data=v,i.gamma=u||0,i}});var Vw=Ot((TB,Yw)=>{var Dw=!0,Jw=Qt("zlib");if(!Jw.deflateSync)Dw=!1;var gR=Ks(),bR=Td();Yw.exports=function(t,e){if(!Dw)throw Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");let r=new bR(e||{}),i=[];if(i.push(Buffer.from(gR.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=Jw.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 Zw=Ot((kR)=>{var wR=qw(),$R=Vw();kR.read=function(t,e){return wR(t,e||{})};kR.write=function(t,e){return $R(t,e)}});var Qw=Ot((OR)=>{var SR=Qt("util"),Xw=Qt("stream"),ER=Sw(),MR=Tw(),xR=Zw(),fe=OR.PNG=function(t){if(Xw.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 ER(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 MR(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"))};SR.inherits(fe,Xw);fe.sync=xR;fe.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};fe.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};fe.prototype.write=function(t){return this._parser.write(t),!0};fe.prototype.end=function(t){this._parser.end(t)};fe.prototype._metadata=function(t){this.width=t.width,this.height=t.height,this.emit("metadata",t)};fe.prototype._gamma=function(t){this.gamma=t};fe.prototype._handleClose=function(){if(!this._parser.writable&&!this._packer.readable)this.emit("close")};fe.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)};fe.prototype.bitblt=function(t,e,n,r,i,s,o){return fe.bitblt(this,t,e,n,r,i,s,o),this};fe.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}};fe.prototype.adjustGamma=function(){fe.adjustGamma(this)}});var lm=Ot((gW,gy)=>{var um={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"},eH={up:(t=1)=>"\x1B[S".repeat(t),down:(t=1)=>"\x1B[T".repeat(t)},nH={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?um.up():"");if(t)e+=um.left;return e}};gy.exports={cursor:um,scroll:eH,erase:nH,beep:"\x07"}});import{spawnSync as iB}from"node:child_process";import{isMainThread as sB}from"node:worker_threads";import{parseArgs as V_}from"node:util";var dt={name:"@kecan0406/ttheme",version:"1.2.22",type:"module",bin:{ttheme:"bin/ttheme.js"},files:["bin","dist/manifest.json","shell","!shell/check.zsh"],description:"Character terminal palettes for Ghostty, iTerm2, kitty, Alacritty, WezTerm, Windows Terminal, Warp, Konsole and Terminal.app",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","warp","windows-terminal"],devDependencies:{"@biomejs/biome":"^2.5.15","@clack/prompts":"^1.8.1","@jsquash/jpeg":"^1.6.0","@material/material-color-utilities":"^0.4.0","@oxlint/plugins":"1.87.0","@types/bun":"^1.4.2","@types/pngjs":"6.0.5","@xterm/headless":"6.0.0","fast-string-width":"^3.0.2",oxlint:"1.87.0",pngjs:"7.0.0","smol-toml":"^1.9.0",typescript:"^7.0.2",uqr:"^0.1.3"},engines:{bun:">=1.3",node:">=22"}};import{existsSync as Rk,readFileSync as Jh}from"node:fs";import{join as Ak}from"node:path";var rI=/^#[0-9a-f]{6}$/;function $e(t){return rI.test(t)}function ct(t){let e=Number.parseInt(t.slice(1),16);return[e>>16&255,e>>8&255,e&255]}function Ht(t,e,n){let r=ct(t),i=ct(e);return`#${r.map((s,o)=>Math.round(s+((i[o]??0)-s)*n).toString(16).padStart(2,"0")).join("")}`}function xt(t){let[e,n,r]=ct(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 yt(t,e){let n=xt(t),r=xt(e);return(Math.max(n,r)+0.05)/(Math.min(n,r)+0.05)}function au(t,e){return Math.round(yt(t,e)*100)/100}function iI(t){let e=t/255;return e<=0.04045?e/12.92:((e+0.055)/1.055)**2.4}function Pt(t){let[e,n,r]=ct(t).map(iI),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 Hr=7,Yb=3,bd=0.15,Vb=1.6,$d=[1,2,3,4,5,6,9,10,11,12,13,14],Zb=[7,15],an=[1,2,3,4,5,6],Ae={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}},Ni=0.03,on=25,Bs=15,Gs=0.08;function er(t,e){let n=t.ansi[e];if(n===void 0)throw Error(`${t.name}: missing ANSI ${e}`);return n}function wd(t,e,n){let r=t.background;return e.flatMap((i)=>{let s=er(t,i);return yt(s,r)<n?[`ANSI ${i} ${s} on ${r} is ${au(s,r)}:1, needs ${n}:1`]:[]})}function Xb(t,e){return Math.min(...e.map((n)=>yt(er(t,n),t.background)))}var Qb=[{rule:"foreground",label:"foreground on background",unit:"ratio",min:Hr,measure:({foreground:t,background:e})=>yt(t,e),check:({foreground:t,background:e})=>yt(t,e)<Hr?[`foreground ${t} on ${e} is ${au(t,e)}:1, needs ${Hr}:1`]:[]},{rule:"accents",label:"weakest accent on background",unit:"ratio",min:Yb,measure:(t)=>Xb(t,$d),check:(t)=>wd(t,$d,Yb)},{rule:"ansi0-dark",label:"ansi0 luminance",unit:"luminance",max:bd,measure:(t)=>xt(er(t,0)),check:(t)=>{let e=er(t,0);return xt(e)>bd?[`ANSI 0 ${e} has luminance ${xt(e).toFixed(3)}, needs <= ${bd}`]:[]}},{rule:"light-ansi",label:"ansi7 and ansi15 on background",unit:"ratio",min:Hr,measure:(t)=>Xb(t,Zb),check:(t)=>wd(t,Zb,Hr)},{rule:"ansi8-visible",label:"ansi8 on background",unit:"ratio",min:Vb,measure:(t)=>yt(er(t,8),t.background),check:(t)=>wd(t,[8],Vb)},{rule:"selection",label:"foreground on selection",unit:"ratio",min:Hr,measure:({foreground:t,selectionBackground:e})=>e===void 0?Number.NaN:yt(t,e),check:({foreground:t,selectionBackground:e})=>e!==void 0&&yt(t,e)<Hr?[`foreground ${t} on selection ${e} is ${au(t,e)}:1, needs ${Hr}:1`]:[]}];function Ne(t,e){let n=Math.abs(t-e)%360;return Math.min(n,360-n)}var Mn=(t)=>t>8?t-8:t;function Us(t){let e=t.signatureSlots.filter((n)=>n.startsWith("ansi")).map((n)=>Number(n.slice(4)));return new Set(e.flatMap((n)=>an.includes(Mn(n))?[n,n>8?n-8:n+8]:[n]))}function pa(t,e){let n=Pt(er(t,e));return n.c<Ni?void 0:n}function Fr(t){let e=Us(t);return $d.flatMap((n)=>{let r=pa(t,n),i=Ae[Mn(n)];if(r===void 0||i===void 0||e.has(n))return[];let s=Ne(r.h,i.center)-i.width;return s>0?[{slot:n,hue:r.h,over:s}]:[]})}function nr(t){let e=new Set(t.signatureSlots);return an.flatMap((n)=>{let r=pa(t,n),i=pa(t,n+8);if(r===void 0||i===void 0||e.has(`ansi${n}`)&&e.has(`ansi${n+8}`))return[];return[{normal:n,gap:Ne(r.h,i.h)}]})}function rr(t){let e=Us(t);return[0,8].flatMap((n)=>an.flatMap((r)=>an.filter((i)=>i>r).flatMap((i)=>{let[s,o]=[n+r,n+i],a=pa(t,s),c=pa(t,o);if(a===void 0||c===void 0||e.has(s)&&e.has(o))return[];return Ne(a.h,c.h)<Bs&&Math.abs(a.l-c.l)<Gs?[[s,o]]:[]})))}var sI=[{rule:"ansi-role",label:"accent hue outside its ANSI role",unit:"degrees",max:0,measure:(t)=>Math.max(0,...Fr(t).map((e)=>e.over)),check:(t)=>Fr(t).map(({slot:e,hue:n,over:r})=>{let i=Ae[Mn(e)];return`ANSI ${e} ${er(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:on,measure:(t)=>Math.max(0,...nr(t).map((e)=>e.gap)),check:(t)=>nr(t).filter((e)=>e.gap>on).map(({normal:e,gap:n})=>`ANSI ${e+8} is ${n.toFixed(0)}° from ANSI ${e}, needs <= ${on}°`)},{rule:"distinct",label:"accent pairs that read as one color",unit:"pairs",max:0,measure:(t)=>rr(t).length,check:(t)=>rr(t).map(([e,n])=>`ANSI ${e} ${er(t,e)} and ANSI ${n} ${er(t,n)} are within ${Bs}° hue and ${Gs} lightness`)}],cu=[...Qb,...sI],kd=cu.map((t)=>t.rule),Te=cu.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 xn(t){return cu.map((e)=>Math.round(e.measure(t)*1000)/1000)}function tw(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 ir(t){return tw(cu,t)}function ew(t){return tw(Qb,t)}function nw(t){return t.flatMap(ir)}import{chmodSync as oI,copyFileSync as aI,existsSync as Lr,mkdirSync as cI,readFileSync as ga,realpathSync as uI,renameSync as iw,rmSync as rw,statSync as lI,writeFileSync as sw}from"node:fs";import{dirname as fI}from"node:path";function ba(t){return`${t}.ttheme.bak`}var dI=/^(?:#|--) ttheme begin$|path = "ttheme-|^DefaultProfile=ttheme-/m;function yd(t){let e=ba(t);if(Lr(t)&&!Lr(e)&&!dI.test(ga(t,"utf8")))aI(t,e)}function H(t,e){let n=Lr(t)?uI(t):t;cI(fI(n),{recursive:!0});let r=`${n}.ttheme-${process.pid}`;if(sw(r,e),Lr(n))oI(r,lI(n).mode&4095);iw(r,n)}function Ti(t,e,n){if(sw(t,n),t!==e)iw(t,e)}function On(t,e){if((Lr(t)?ga(t,"utf8"):void 0)===e)return!1;return yd(t),H(t,e),!0}function ow(t,e){return t.replace(/\n*$/,"")===e.replace(/\n*$/,"")}function aw(t,e){let n=ba(t),r=Lr(n)?ga(n,"utf8"):void 0;if(e===""&&r===void 0)return rw(t,{force:!0}),"removed";let i=r!==void 0&&ow(r,e);if(H(t,i?r:e),r===void 0||i)return rw(n,{force:!0}),"restored";return"kept backup"}function uu(t){let e=ba(t);return Lr(t)&&Lr(e)&&ow(ga(t,"utf8"),ga(e,"utf8"))?[e]:[]}import{createHash as S$}from"node:crypto";import{copyFileSync as MN,existsSync as gh,mkdirSync as xN,readdirSync as ON,readFileSync as so,renameSync as E$,rmSync as io,statSync as PN}from"node:fs";import{basename as M$,isAbsolute as IN,join as V}from"node:path";import{readdirSync as BR,rmSync as GR,statSync as UR}from"node:fs";import{setDefaultAutoSelectFamilyAttemptTimeout as WR}from"node:net";import{homedir as KR}from"node:os";import{join as va}from"node:path";import{setTimeout as zR}from"node:timers/promises";var i0=gd(Qw(),1);import{constants as AR,deflateSync as NR,inflateSync as TR}from"node:zlib";import{inflateRawSync as IR}from"node:zlib";var PR=(()=>{var t=import.meta.url;return function(e={}){var n=e,r,i,s=new Promise((g,w)=>{r=g,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,y,E){this.data=w,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),f=[],l="./this.program",d=(g,w)=>{throw w},h=typeof window=="object",m=typeof importScripts=="function",p=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string",b="";function $(g){if(n.locateFile)return n.locateFile(g,b);return b+g}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=(g)=>{var w=new XMLHttpRequest;return w.open("GET",g,!1),w.send(null),w.responseText},m)S=(g)=>{var w=new XMLHttpRequest;return w.open("GET",g,!1),w.responseType="arraybuffer",w.send(null),new Uint8Array(w.response)};v=(g,w,y)=>{var E=new XMLHttpRequest;E.open("GET",g,!0),E.responseType="arraybuffer",E.onload=()=>{if(E.status==200||E.status==0&&E.response){w(E.response);return}y()},E.onerror=y,E.send(null)}}}var x=n.print||console.log.bind(console),M=n.printErr||console.error.bind(console);if(Object.assign(n,u),u=null,n.arguments)f=n.arguments;if(n.thisProgram)l=n.thisProgram;if(n.quit)d=n.quit;var N;if(n.wasmBinary)N=n.wasmBinary;var C,I=!1,j,U,G,L,gt,Xt,at,Tr,Ke;function En(){var g=C.buffer;n.HEAP8=U=new Int8Array(g),n.HEAP16=L=new Int16Array(g),n.HEAPU8=G=new Uint8Array(g),n.HEAPU16=gt=new Uint16Array(g),n.HEAP32=Xt=new Int32Array(g),n.HEAPU32=at=new Uint32Array(g),n.HEAPF32=Tr=new Float32Array(g),n.HEAPF64=Ke=new Float64Array(g)}var Fs=[],ru=[],xi=[],nd=!1;function rd(){if(n.preRun){if(typeof n.preRun=="function")n.preRun=[n.preRun];while(n.preRun.length)sO(n.preRun.shift())}od(Fs)}function id(){nd=!0,od(ru)}function iO(){if(n.postRun){if(typeof n.postRun=="function")n.postRun=[n.postRun];while(n.postRun.length)aO(n.postRun.shift())}od(xi)}function sO(g){Fs.unshift(g)}function oO(g){ru.unshift(g)}function aO(g){xi.unshift(g)}var Oi=0,sd=null,ha=null;function cO(g){Oi++,n.monitorRunDependencies?.(Oi)}function uO(g){if(Oi--,n.monitorRunDependencies?.(Oi),Oi==0){if(sd!==null)clearInterval(sd),sd=null;if(ha){var w=ha;ha=null,w()}}}function Pb(g){n.onAbort?.(g),g="Aborted("+g+")",M(g),I=!0,j=1,g+=". Build with -sASSERTIONS for more info.";var w=new WebAssembly.RuntimeError(g);throw i(w),w}var lO="data:application/octet-stream;base64,",Ib=(g)=>g.startsWith(lO),Pi;if(n.locateFile){if(Pi="mozjpeg_dec.wasm",!Ib(Pi))Pi=$(Pi)}else Pi=new URL("mozjpeg_dec.wasm",import.meta.url).href;function Rb(g){if(g==Pi&&N)return new Uint8Array(N);if(S)return S(g);throw"both async and sync fetching of the wasm failed"}function fO(g){if(!N&&(h||m)){if(typeof fetch=="function")return fetch(g,{credentials:"same-origin"}).then((w)=>{if(!w.ok)throw`failed to load wasm binary file at '${g}'`;return w.arrayBuffer()}).catch(()=>Rb(g))}return Promise.resolve().then(()=>Rb(g))}function Ab(g,w,y){return fO(g).then((E)=>WebAssembly.instantiate(E,w)).then(y,(E)=>{M(`failed to asynchronously prepare wasm: ${E}`),Pb(E)})}function dO(g,w,y,E){if(!g&&typeof WebAssembly.instantiateStreaming=="function"&&!Ib(w)&&typeof fetch=="function")return fetch(w,{credentials:"same-origin"}).then((P)=>{var A=WebAssembly.instantiateStreaming(P,y);return A.then(E,function(W){return M(`wasm streaming compile failed: ${W}`),M("falling back to ArrayBuffer instantiation"),Ab(w,y,E)})});return Ab(w,y,E)}function hO(){var g={a:CP};function w(E,P){return ue=E.exports,C=ue.A,En(),_b=ue.F,oO(ue.B),uO("wasm-instantiate"),ue}cO("wasm-instantiate");function y(E){w(E.instance)}if(n.instantiateWasm)try{return n.instantiateWasm(g,w)}catch(E){M(`Module.instantiateWasm callback failed with error: ${E}`),i(E)}return dO(N,Pi,g,y).catch(i),{}}function mO(g){this.name="ExitStatus",this.message=`Program terminated with exit(${g})`,this.status=g}var od=(g)=>{while(g.length>0)g.shift()(n)},pO=n.noExitRuntime||!0;class Nb{constructor(g){this.excPtr=g,this.ptr=g-24}set_type(g){at[this.ptr+4>>2]=g}get_type(){return at[this.ptr+4>>2]}set_destructor(g){at[this.ptr+8>>2]=g}get_destructor(){return at[this.ptr+8>>2]}set_caught(g){g=g?1:0,U[this.ptr+12]=g}get_caught(){return U[this.ptr+12]!=0}set_rethrown(g){g=g?1:0,U[this.ptr+13]=g}get_rethrown(){return U[this.ptr+13]!=0}init(g,w){this.set_adjusted_ptr(0),this.set_type(g),this.set_destructor(w)}set_adjusted_ptr(g){at[this.ptr+16>>2]=g}get_adjusted_ptr(){return at[this.ptr+16>>2]}get_exception_ptr(){var g=qb(this.get_type());if(g)return at[this.excPtr>>2];var w=this.get_adjusted_ptr();if(w!==0)return w;return this.excPtr}}var Tb=0,gO=0,bO=(g,w,y)=>{var E=new Nb(g);throw E.init(w,y),Tb=g,gO++,Tb},wO=(g,w,y,E,P)=>{},$O=()=>{var g=Array(256);for(var w=0;w<256;++w)g[w]=String.fromCharCode(w);Hb=g},Hb,sn=(g)=>{var w="",y=g;while(G[y])w+=Hb[G[y++]];return w},Ls={},Ii={},iu={},Fb,Re=(g)=>{throw new Fb(g)},Lb,Cb=(g)=>{throw new Lb(g)},kO=(g,w,y)=>{g.forEach(function(T){iu[T]=w});function E(T){var z=y(T);if(z.length!==g.length)Cb("Mismatched type converter count");for(var Q=0;Q<g.length;++Q)Xn(g[Q],z[Q])}var P=Array(w.length),A=[],W=0;if(w.forEach((T,z)=>{if(Ii.hasOwnProperty(T))P[z]=Ii[T];else{if(A.push(T),!Ls.hasOwnProperty(T))Ls[T]=[];Ls[T].push(()=>{if(P[z]=Ii[T],++W,W===A.length)E(P)})}}),A.length===0)E(P)};function yO(g,w,y={}){var E=w.name;if(!g)Re(`type "${E}" must have a positive integer typeid pointer`);if(Ii.hasOwnProperty(g))if(y.ignoreDuplicateRegistrations)return;else Re(`Cannot register type '${E}' twice`);if(Ii[g]=w,delete iu[g],Ls.hasOwnProperty(g)){var P=Ls[g];delete Ls[g],P.forEach((A)=>A())}}function Xn(g,w,y={}){if(!("argPackAdvance"in w))throw TypeError("registerType registeredInstance requires argPackAdvance");return yO(g,w,y)}var Ri=8,vO=(g,w,y,E)=>{w=sn(w),Xn(g,{name:w,fromWireType:function(P){return!!P},toWireType:function(P,A){return A?y:E},argPackAdvance:Ri,readValueFromPointer:function(P){return this.fromWireType(G[P])},destructorFunction:null})},ad=[],Qn=[],cd=(g)=>{if(g>9&&--Qn[g+1]===0)Qn[g]=void 0,ad.push(g)},SO=()=>Qn.length/2-5-ad.length,EO=()=>{Qn.push(0,1,void 0,1,null,1,!0,1,!1,1),n.count_emval_handles=SO},Ai={toValue:(g)=>{if(!g)Re("Cannot use deleted val. handle = "+g);return Qn[g]},toHandle:(g)=>{switch(g){case void 0:return 2;case null:return 4;case!0:return 6;case!1:return 8;default:{let w=ad.pop()||Qn.length;return Qn[w]=g,Qn[w+1]=1,w}}}};function ud(g){return this.fromWireType(at[g>>2])}var MO={name:"emscripten::val",fromWireType:(g)=>{var w=Ai.toValue(g);return cd(g),w},toWireType:(g,w)=>Ai.toHandle(w),argPackAdvance:Ri,readValueFromPointer:ud,destructorFunction:null},xO=(g)=>Xn(g,MO),OO=(g,w)=>{switch(w){case 4:return function(y){return this.fromWireType(Tr[y>>2])};case 8:return function(y){return this.fromWireType(Ke[y>>3])};default:throw TypeError(`invalid float width (${w}): ${g}`)}},PO=(g,w,y)=>{w=sn(w),Xn(g,{name:w,fromWireType:(E)=>E,toWireType:(E,P)=>P,argPackAdvance:Ri,readValueFromPointer:OO(w,y),destructorFunction:null})},ld=(g,w)=>Object.defineProperty(w,"name",{value:g}),jb=(g)=>{while(g.length){var w=g.pop(),y=g.pop();y(w)}};function IO(g){for(var w=1;w<g.length;++w)if(g[w]!==null&&g[w].destructorFunction===void 0)return!0;return!1}function RO(g,w,y,E,P,A){var W=w.length;if(W<2)Re("argTypes array size mismatch! Must at least get return value and 'this' types!");var T=w[1]!==null&&y!==null,z=IO(w),Q=w[0].name!=="void",bt=W-2,jt=Array(bt),le=[],ze=[],Cs=function(...md){if(md.length!==bt)Re(`function ${g} called with ${md.length} arguments, expected ${bt}`);ze.length=0;var pd;if(le.length=T?2:1,le[0]=P,T)pd=w[1].toWireType(ze,this),le[1]=pd;for(var js=0;js<bt;++js)jt[js]=w[js+2].toWireType(ze,md[js]),le.push(jt[js]);var KP=E(...le);function zP(qP){if(z)jb(ze);else for(var _s=T?1:2;_s<w.length;_s++){var DP=_s===1?pd:jt[_s-2];if(w[_s].destructorFunction!==null)w[_s].destructorFunction(DP)}if(Q)return w[0].fromWireType(qP)}return zP(KP)};return ld(g,Cs)}var AO=(g,w,y)=>{if(g[w].overloadTable===void 0){var E=g[w];g[w]=function(...P){if(!g[w].overloadTable.hasOwnProperty(P.length))Re(`Function '${y}' called with an invalid number of arguments (${P.length}) - expects one of (${g[w].overloadTable})!`);return g[w].overloadTable[P.length].apply(this,P)},g[w].overloadTable=[],g[w].overloadTable[E.argCount]=E}},NO=(g,w,y)=>{if(n.hasOwnProperty(g)){if(y===void 0||n[g].overloadTable!==void 0&&n[g].overloadTable[y]!==void 0)Re(`Cannot register public name '${g}' twice`);if(AO(n,g,g),n.hasOwnProperty(y))Re(`Cannot register multiple overloads of a function with the same number of arguments (${y})!`);n[g].overloadTable[y]=w}else if(n[g]=w,y!==void 0)n[g].numArguments=y},TO=(g,w)=>{var y=[];for(var E=0;E<g;E++)y.push(at[w+E*4>>2]);return y},HO=(g,w,y)=>{if(!n.hasOwnProperty(g))Cb("Replacing nonexistent public symbol");if(n[g].overloadTable!==void 0&&y!==void 0)n[g].overloadTable[y]=w;else n[g]=w,n[g].argCount=y},FO=(g,w,y)=>{g=g.replace(/p/g,"i");var E=n["dynCall_"+g];return E(w,...y)},su=[],_b,Bb=(g)=>{var w=su[g];if(!w){if(g>=su.length)su.length=g+1;su[g]=w=_b.get(g)}return w},LO=(g,w,y=[])=>{if(g.includes("j"))return FO(g,w,y);var E=Bb(w)(...y);return E},CO=(g,w)=>(...y)=>LO(g,w,y),jO=(g,w)=>{g=sn(g);function y(){if(g.includes("j"))return CO(g,w);return Bb(w)}var E=y();if(typeof E!="function")Re(`unknown function pointer with signature ${g}: ${w}`);return E},_O=(g,w)=>{var y=ld(w,function(E){this.name=w,this.message=E;var P=Error(E).stack;if(P!==void 0)this.stack=this.toString()+`
3
+ `+P.replace(/^Error(:[^\n]*)?\n/,"")});return y.prototype=Object.create(g.prototype),y.prototype.constructor=y,y.prototype.toString=function(){if(this.message===void 0)return this.name;else return`${this.name}: ${this.message}`},y},Gb,Ub=(g)=>{var w=zb(g),y=sn(w);return tr(w),y},BO=(g,w)=>{var y=[],E={};function P(A){if(E[A])return;if(Ii[A])return;if(iu[A]){iu[A].forEach(P);return}y.push(A),E[A]=!0}throw w.forEach(P),new Gb(`${g}: `+y.map(Ub).join([", "]))},GO=(g)=>{g=g.trim();let w=g.indexOf("(");if(w!==-1)return g.substr(0,w);else return g},UO=(g,w,y,E,P,A,W)=>{var T=TO(w,y);g=sn(g),g=GO(g),P=jO(E,P),NO(g,function(){BO(`Cannot call ${g} due to unbound types`,T)},w-1),kO([],T,(z)=>{var Q=[z[0],null].concat(z.slice(1));return HO(g,RO(g,Q,null,P,A,W),w-1),[]})},WO=(g,w,y)=>{switch(w){case 1:return y?(E)=>U[E]:(E)=>G[E];case 2:return y?(E)=>L[E>>1]:(E)=>gt[E>>1];case 4:return y?(E)=>Xt[E>>2]:(E)=>at[E>>2];default:throw TypeError(`invalid integer width (${w}): ${g}`)}},KO=(g,w,y,E,P)=>{if(w=sn(w),P===-1)P=4294967295;var A=(bt)=>bt;if(E===0){var W=32-8*y;A=(bt)=>bt<<W>>>W}var T=w.includes("unsigned"),z=(bt,jt)=>{},Q;if(T)Q=function(bt,jt){return z(jt,this.name),jt>>>0};else Q=function(bt,jt){return z(jt,this.name),jt};Xn(g,{name:w,fromWireType:A,toWireType:Q,argPackAdvance:Ri,readValueFromPointer:WO(w,y,E!==0),destructorFunction:null})},zO=(g,w,y)=>{var E=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],P=E[w];function A(W){var T=at[W>>2],z=at[W+4>>2];return new P(U.buffer,z,T)}y=sn(y),Xn(g,{name:y,fromWireType:A,argPackAdvance:Ri,readValueFromPointer:A},{ignoreDuplicateRegistrations:!0})},qO=(g,w,y,E)=>{if(!(E>0))return 0;var P=y,A=y+E-1;for(var W=0;W<g.length;++W){var T=g.charCodeAt(W);if(T>=55296&&T<=57343){var z=g.charCodeAt(++W);T=65536+((T&1023)<<10)|z&1023}if(T<=127){if(y>=A)break;w[y++]=T}else if(T<=2047){if(y+1>=A)break;w[y++]=192|T>>6,w[y++]=128|T&63}else if(T<=65535){if(y+2>=A)break;w[y++]=224|T>>12,w[y++]=128|T>>6&63,w[y++]=128|T&63}else{if(y+3>=A)break;w[y++]=240|T>>18,w[y++]=128|T>>12&63,w[y++]=128|T>>6&63,w[y++]=128|T&63}}return w[y]=0,y-P},DO=(g,w,y)=>qO(g,G,w,y),JO=(g)=>{var w=0;for(var y=0;y<g.length;++y){var E=g.charCodeAt(y);if(E<=127)w++;else if(E<=2047)w+=2;else if(E>=55296&&E<=57343)w+=4,++y;else w+=3}return w},Wb=(g,w,y)=>{var E=w+y,P="";while(!(w>=E)){var A=g[w++];if(!A)return P;if(!(A&128)){P+=String.fromCharCode(A);continue}var W=g[w++]&63;if((A&224)==192){P+=String.fromCharCode((A&31)<<6|W);continue}var T=g[w++]&63;if((A&240)==224)A=(A&15)<<12|W<<6|T;else A=(A&7)<<18|W<<12|T<<6|g[w++]&63;if(A<65536)P+=String.fromCharCode(A);else{var z=A-65536;P+=String.fromCharCode(55296|z>>10,56320|z&1023)}}return P},YO=(g,w)=>g?Wb(G,g,w):"",VO=(g,w)=>{w=sn(w);var y=w==="std::string";Xn(g,{name:w,fromWireType(E){var P=at[E>>2],A=E+4,W;if(y){var T=A;for(var z=0;z<=P;++z){var Q=A+z;if(z==P||G[Q]==0){var bt=Q-T,jt=YO(T,bt);if(W===void 0)W=jt;else W+=String.fromCharCode(0),W+=jt;T=Q+1}}}else{var le=Array(P);for(var z=0;z<P;++z)le[z]=String.fromCharCode(G[A+z]);W=le.join("")}return tr(E),W},toWireType(E,P){if(P instanceof ArrayBuffer)P=new Uint8Array(P);var A,W=typeof P=="string";if(!(W||P instanceof Uint8Array||P instanceof Uint8ClampedArray||P instanceof Int8Array))Re("Cannot pass non-string to std::string");if(y&&W)A=JO(P);else A=P.length;var T=hd(4+A+1),z=T+4;if(at[T>>2]=A,y&&W)DO(P,z,A+1);else if(W)for(var Q=0;Q<A;++Q){var bt=P.charCodeAt(Q);if(bt>255)tr(z),Re("String has UTF-16 code units that do not fit in 8 bits");G[z+Q]=bt}else for(var Q=0;Q<A;++Q)G[z+Q]=P[Q];if(E!==null)E.push(tr,T);return T},argPackAdvance:Ri,readValueFromPointer:ud,destructorFunction(E){tr(E)}})},ZO=(g,w)=>{var y="";for(var E=0;!(E>=w/2);++E){var P=L[g+E*2>>1];if(P==0)break;y+=String.fromCharCode(P)}return y},XO=(g,w,y)=>{if(y??=2147483647,y<2)return 0;y-=2;var E=w,P=y<g.length*2?y/2:g.length;for(var A=0;A<P;++A){var W=g.charCodeAt(A);L[w>>1]=W,w+=2}return L[w>>1]=0,w-E},QO=(g)=>g.length*2,tP=(g,w)=>{var y=0,E="";while(!(y>=w/4)){var P=Xt[g+y*4>>2];if(P==0)break;if(++y,P>=65536){var A=P-65536;E+=String.fromCharCode(55296|A>>10,56320|A&1023)}else E+=String.fromCharCode(P)}return E},eP=(g,w,y)=>{if(y??=2147483647,y<4)return 0;var E=w,P=E+y-4;for(var A=0;A<g.length;++A){var W=g.charCodeAt(A);if(W>=55296&&W<=57343){var T=g.charCodeAt(++A);W=65536+((W&1023)<<10)|T&1023}if(Xt[w>>2]=W,w+=4,w+4>P)break}return Xt[w>>2]=0,w-E},nP=(g)=>{var w=0;for(var y=0;y<g.length;++y){var E=g.charCodeAt(y);if(E>=55296&&E<=57343)++y;w+=4}return w},rP=(g,w,y)=>{y=sn(y);var E,P,A,W;if(w===2)E=ZO,P=XO,W=QO,A=(T)=>gt[T>>1];else if(w===4)E=tP,P=eP,W=nP,A=(T)=>at[T>>2];Xn(g,{name:y,fromWireType:(T)=>{var z=at[T>>2],Q,bt=T+4;for(var jt=0;jt<=z;++jt){var le=T+4+jt*w;if(jt==z||A(le)==0){var ze=le-bt,Cs=E(bt,ze);if(Q===void 0)Q=Cs;else Q+=String.fromCharCode(0),Q+=Cs;bt=le+w}}return tr(T),Q},toWireType:(T,z)=>{if(typeof z!="string")Re(`Cannot pass non-string to C++ string type ${y}`);var Q=W(z),bt=hd(4+Q+w);if(at[bt>>2]=Q/w,P(z,bt+4,Q+w),T!==null)T.push(tr,bt);return bt},argPackAdvance:Ri,readValueFromPointer:ud,destructorFunction(T){tr(T)}})},iP=(g,w)=>{w=sn(w),Xn(g,{isVoid:!0,name:w,argPackAdvance:0,fromWireType:()=>{return},toWireType:(y,E)=>{return}})},sP=(g,w,y)=>G.copyWithin(g,w,w+y),fd=[],oP=(g,w,y,E)=>{return g=fd[g],w=Ai.toValue(w),g(null,w,y,E)},aP={},cP=(g)=>{var w=aP[g];if(w===void 0)return sn(g);return w},Kb=()=>{if(typeof globalThis=="object")return globalThis;function g(w){w.$$$embind_global$$$=w;var y=typeof $$$embind_global$$$=="object"&&w.$$$embind_global$$$==w;if(!y)delete w.$$$embind_global$$$;return y}if(typeof $$$embind_global$$$=="object")return $$$embind_global$$$;if(typeof global=="object"&&g(global))$$$embind_global$$$=global;else if(typeof self=="object"&&g(self))$$$embind_global$$$=self;if(typeof $$$embind_global$$$=="object")return $$$embind_global$$$;throw Error("unable to get global object.")},uP=(g)=>{if(g===0)return Ai.toHandle(Kb());else return g=cP(g),Ai.toHandle(Kb()[g])},lP=(g)=>{var w=fd.length;return fd.push(g),w},fP=(g,w)=>{var y=Ii[g];if(y===void 0)Re(`${w} has unknown type ${Ub(g)}`);return y},dP=(g,w)=>{var y=Array(g);for(var E=0;E<g;++E)y[E]=fP(at[w+E*4>>2],"parameter "+E);return y},hP=Reflect.construct,mP=(g,w,y)=>{var E=[],P=g.toWireType(E,y);if(E.length)at[w>>2]=Ai.toHandle(E);return P},pP=(g,w,y)=>{var E=dP(g,w),P=E.shift();g--;var A=Array(g),W=(z,Q,bt,jt)=>{var le=0;for(var ze=0;ze<g;++ze)A[ze]=E[ze].readValueFromPointer(jt+le),le+=E[ze].argPackAdvance;var Cs=y===1?hP(Q,A):Q.apply(z,A);return mP(P,bt,Cs)},T=`methodCaller<(${E.map((z)=>z.name).join(", ")}) => ${P.name}>`;return lP(ld(T,W))},gP=(g)=>{if(g>9)Qn[g+1]+=1},bP=(g)=>{var w=Ai.toValue(g);jb(w),cd(g)},wP=()=>{Pb("")},$P=()=>2147483648,kP=(g)=>{var w=C.buffer,y=(g-w.byteLength+65535)/65536;try{return C.grow(y),En(),1}catch(E){}},yP=(g)=>{var w=G.length;g>>>=0;var y=$P();if(g>y)return!1;var E=(z,Q)=>z+(Q-z%Q)%Q;for(var P=1;P<=4;P*=2){var A=w*(1+0.2/P);A=Math.min(A,g+100663296);var W=Math.min(y,E(Math.max(g,A),65536)),T=kP(W);if(T)return!0}return!1},dd={},vP=()=>l||"./this.program",ma=()=>{if(!ma.strings){var g=(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:g,_:vP()};for(var y in dd)if(dd[y]===void 0)delete w[y];else w[y]=dd[y];var E=[];for(var y in w)E.push(`${y}=${w[y]}`);ma.strings=E}return ma.strings},SP=(g,w)=>{for(var y=0;y<g.length;++y)U[w++]=g.charCodeAt(y);U[w]=0},EP=(g,w)=>{var y=0;return ma().forEach((E,P)=>{var A=w+y;at[g+P*4>>2]=A,SP(E,A),y+=E.length+1}),0},MP=(g,w)=>{var y=ma();at[g>>2]=y.length;var E=0;return y.forEach((P)=>E+=P.length+1),at[w>>2]=E,0},xP=0,OP=()=>pO||xP>0,PP=(g)=>{if(j=g,!OP())n.onExit?.(g),I=!0;d(g,new mO(g))},IP=(g,w)=>{j=g,PP(g)},RP=IP,AP=(g)=>52,NP=(g,w)=>w+2097152>>>0<4194305-!!g?(g>>>0)+w*4294967296:NaN;function TP(g,w,y,E,P){var A=NP(w,y);return 70}var HP=[null,[],[]],FP=(g,w)=>{var y=HP[g];if(w===0||w===10)(g===1?x:M)(Wb(y,0)),y.length=0;else y.push(w)},LP=(g,w,y,E)=>{var P=0;for(var A=0;A<y;A++){var W=at[w>>2],T=at[w+4>>2];w+=8;for(var z=0;z<T;z++)FP(g,G[W+z]);P+=T}return at[E>>2]=P,0};$O(),Fb=n.BindingError=class extends Error{constructor(w){super(w);this.name="BindingError"}},Lb=n.InternalError=class extends Error{constructor(w){super(w);this.name="InternalError"}},EO(),Gb=n.UnboundTypeError=_O(Error,"UnboundTypeError");var CP={o:bO,q:wO,m:vO,l:xO,j:PO,f:UO,b:KO,a:zO,e:VO,c:rP,n:iP,v:sP,i:oP,d:cd,k:uP,h:pP,y:gP,g:bP,r:wP,s:yP,t:EP,u:MP,z:RP,w:AP,p:TP,x:LP},ue=hO(),jP=()=>(jP=ue.B)(),zb=(g)=>(zb=ue.C)(g),hd=(g)=>(hd=ue.D)(g),tr=(g)=>(tr=ue.E)(g),_P=(g)=>(_P=ue._emscripten_stack_restore)(g),BP=(g)=>(BP=ue._emscripten_stack_alloc)(g),GP=()=>(GP=ue.emscripten_stack_get_current)(),UP=(g)=>(UP=ue.__cxa_increment_exception_refcount)(g),qb=(g)=>(qb=ue.G)(g),WP=n.dynCall_jiji=(g,w,y,E,P)=>(WP=n.dynCall_jiji=ue.H)(g,w,y,E,P),ou;ha=function g(){if(!ou)Db();if(!ou)ha=g};function Db(){if(Oi>0)return;if(rd(),Oi>0)return;function g(){if(ou)return;if(ou=!0,n.calledRun=!0,I)return;if(id(),r(n),n.onRuntimeInitialized)n.onRuntimeInitialized();iO()}if(n.setStatus)n.setStatus("Running..."),setTimeout(function(){setTimeout(function(){n.setStatus("")},1),g()},1);else g()}if(n.preInit){if(typeof n.preInit=="function")n.preInit=[n.preInit];while(n.preInit.length>0)n.preInit.pop()()}return Db(),s}})(),t0=PR;function Ld(t){let e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=t[0]===73&&t[1]===73;if(t.length<8||!n&&(t[0]!==77||t[1]!==77))return 1;let r=e.getUint32(4,n);if(r+2>t.length)return 1;for(let i=r+2,s=e.getUint16(r,n);s>0&&i+12<=t.length;s--,i+=12)if(e.getUint16(i,n)===274){let o=e.getUint16(i+8,n);return o>=1&&o<=8?o:1}return 1}function Cd(t){if(t[0]!==255||t[1]!==216)return null;let e=1,n=2;while(n+9<t.length){if(t[n]!==255){n++;continue}let r=t[n+1];if(r===255){n++;continue}let i=t[n+2]<<8|t[n+3];if(r===225&&String.fromCharCode(...t.subarray(n+4,n+10))==="Exif\x00\x00")e=Ld(t.subarray(n+10,Math.min(t.length,n+2+i)));if(r>=192&&r<=207&&r!==196&&r!==200&&r!==204){let s=t[n+5]<<8|t[n+6],o=t[n+7]<<8|t[n+8];return e>=5?{width:s,height:o}:{width:o,height:s}}n+=2+i}return null}var Fd;function RR(){if(Fd)return Fd;let t=new WebAssembly.Module(IR(Buffer.from("7L0NnFzHVSd6q+5H3+7bPdMjjeyRZmTf7ohFITZWgpFN4mBdEX3Y8leI15jfy+6a3UC8Mwp4ZEWYRdaMY9kICESA2TWsCXrBb+2wNugtejwvmBcFDBFgFgXMRkkMEYtJzBLA720A78PY+/+fU3X73u4eSVYMC1mUePre+rqnTp06derUqXOCb7rzPSYIAvN/m9nbzFKA/8zSbeHSEn/sEhLiJf4Lbov0x0pOY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pZ7HBPJONp2HE0xjuYbJ9Yf1R9HtcdRxXHUaxxNNo4Cjs+UZcE4Cj6OThlHb4yjguOYSMYxYYxjQhjHJDAOIj+O8t6Hyeso8j+K/I8i/6PI/yjyP4r8jyL/o8j/KPI/ivyPIv+jyP8p5H8U+R9Fz3wdR9AQP4b4McSP/biazzypX4Wj0R5yqiPe0DijaSYzKPPmv+PU06zmltNPLvy/+Yf6BGqMkB446onyn6uLP/v3Z14+sr3++PHzzyDGIA13DI0ex0x76GqfWrW6Xl1+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(t0(e),typeof e.decode!=="function")throw Error("the JPEG decoder did not start");return Fd=e,e}function e0(t,e){let n=Cd(t);if(n&&n.width*n.height>e)throw Error(`${n.width}×${n.height} is over ${e/1e6} megapixels`);let r=null;try{r=RR().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 qs=[137,80,78,71,13,10,26,10],s0=13,$a=3;function Br(t){return t.length>=qs.length&&qs.every((e,n)=>t[n]===e)}var o0={0:1,2:3,3:1,4:2,6:4};function a0(t){if(t.length<33||!Br(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||o0[i]===void 0)return;let s=[],o,a;for(let c=8;c+12<=e.length;){let u=e.readUInt32BE(c),f=e.toString("latin1",c+4,c+8),l=e.subarray(c+8,c+8+u);if(f==="IDAT")s.push(l);else if(f==="PLTE")o=l;else if(f==="tRNS"){if(i!==$a)return;a=l}else if(f==="IEND")break;c+=12+u}if(s.length===0||i===$a&&!o)return;return{width:n,height:r,type:i,idat:s,palette:o,opacity:a}}function HR(t,e){let n=new Uint32Array(256),r=new Uint8Array(n.buffer);for(let i=0;i<256;i++)r[i*4]=t[i*3]??0,r[i*4+1]=t[i*3+1]??0,r[i*4+2]=t[i*3+2]??0,r[i*4+3]=e?.[i]??255;return n}function FR(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,f=s>0?c-e-1:0;if(a===1)for(let l=r;l<e;l++)t[c+l]=t[c+l]+t[c+l-r];else if(a===2)for(let l=0;l<e;l++)t[c+l]=t[c+l]+u[f+l];else if(a===3){for(let l=0;l<r;l++)t[c+l]=t[c+l]+(u[f+l]>>1);for(let l=r;l<e;l++)t[c+l]=t[c+l]+(t[c+l-r]+u[f+l]>>1)}else if(a===4){for(let l=0;l<r;l++)t[c+l]=t[c+l]+u[f+l];for(let l=r;l<e;l++){let d=t[c+l-r],h=u[f+l],m=u[f+l-r],p=Math.abs(h-m),b=Math.abs(d-m),$=Math.abs(d+h-2*m);t[c+l]=t[c+l]+(p<=b&&p<=$?d:b<=$?h:m)}}else if(a!==0)throw Error(`bad PNG filter ${a}`)}}function LR(t){let{width:e,height:n,type:r}=t,i=o0[r],s=e*i,o=TR(Buffer.concat(t.idat),{chunkSize:Math.min(268435456,Math.max(65536,n*(s+1)))});if(o.length<n*(s+1))throw Error("truncated PNG");FR(o,s,n,i);let a=new Uint8Array(e*n*4),c=r===$a?HR(t.palette,t.opacity):void 0,u=new Uint32Array(a.buffer);for(let f=0;f<n;f++){let l=f*(s+1)+1,d=f*e*4;if(c)for(let h=0,m=f*e;h<e;h++,m++)u[m]=c[o[l+h]];else if(r===6)a.set(o.subarray(l,l+s),d);else if(r===2)for(let h=0,m=l,p=d;h<e;h++,m+=3,p+=4)a[p]=o[m],a[p+1]=o[m+1],a[p+2]=o[m+2],a[p+3]=255;else if(r===0)for(let h=0,m=d;h<e;h++,m+=4){let p=o[l+h];a[m]=p,a[m+1]=p,a[m+2]=p,a[m+3]=255}else for(let h=0,m=l,p=d;h<e;h++,m+=2,p+=4){let b=o[m];a[p]=b,a[p+1]=b,a[p+2]=b,a[p+3]=o[m+1]}}return{width:e,height:n,data:a}}function jd(t){let e=Buffer.from(t.buffer,t.byteOffset,t.byteLength);for(let n=8;n+12<=e.length;){let r=e.readUInt32BE(n),i=e.toString("latin1",n+4,n+8);if(i==="eXIf")return Ld(e.subarray(n+8,Math.min(e.length,n+8+r)));if(i==="IDAT"||i==="IEND")return 1;n+=12+r}return 1}function n0(t,e){if(e<=1)return t;let{width:n,height:r}=t,i=e>=5?r:n,s=e>=5?n:r,o=new Uint32Array(t.data.buffer,t.data.byteOffset,n*r),a=new Uint8Array(i*s*4),c=new Uint32Array(a.buffer);for(let u=0;u<s;u++)for(let f=0;f<i;f++){let l=e<=3&&e>=2?n-1-f:e===5||e===6?u:e>=7?n-1-u:f,d=e===3||e===4?r-1-u:e===5||e===8?f:e>=6?r-1-f:u;c[u*i+f]=o[d*n+l]}return{width:i,height:s,data:a}}function Kt(t){let e=a0(t);if(e)return n0(LR(e),jd(t));let n=i0.PNG.sync.read(Buffer.from(t));return n0({width:n.width,height:n.height,data:new Uint8Array(n.data)},jd(t))}function In(t,e){if(Br(t)){let n=Rn(t);if(n&&n.width*n.height>e)throw Error(`${n.width}×${n.height} is over ${e/1e6} megapixels`);return Kt(t)}if(t[0]===255&&t[1]===216)return e0(t,e);throw Error("not a PNG or JPEG image")}function _d(t,e,n){let{width:r,height:i,at:s}=e,o=Math.max(0,s.x),a=Math.max(0,s.y),c=Math.min(r,s.x+s.w),u=Math.min(i,s.y+s.h);if(c<=o||u<=a)return;let f={x:o,y:a,w:c-o,h:u-a};if(s.w===t.width&&s.h===t.height)return{part:t,box:f,dx:o-s.x,dy:a-s.y};let l={x:(o-s.x)*t.width/s.w,y:(a-s.y)*t.height/s.h,w:f.w*t.width/s.w,h:f.h*t.height/s.h};return{part:n(t,l,f.w,f.h),box:f,dx:0,dy:0}}function c0(t,e){let n=new Uint8Array(e.width*e.height*4),r=_d(t,e,Ur);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 u0(t,e){let n=new Uint8Array(e.width*e.height),r=_d(t,e,(i,s,o,a)=>Ds(Gd(i,s,o,a)));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;n.set(i.data.subarray(u,u+s.w),(s.y+c)*e.width+s.x)}}return{width:e.width,height:e.height,data:n}}function Gr(t,e,n,r={width:t.width,height:t.height,at:{x:0,y:0,w:t.width,h:t.height}}){let i=ct(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=_d(t,r,Ur);if(!c)return{width:s,height:o,data:a};let{part:u,box:f,dx:l,dy:d}=c;for(let h=0;h<f.h;h++)for(let m=0;m<f.w;m++){let p=((h+d)*u.width+m+l)*4,b=((f.y+h)*s+f.x+m)*3,$=u.data[p+3]/255*n;for(let k=0;k<3;k++)a[b+k]=Math.round(i[k]*(1-$)+u.data[p+k]*$)}return{width:s,height:o,data:a}}function r0(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 Rn(t){if(t.length<33||!Br(t))return null;let e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=jd(t)>=5,r=e.getUint32(n?20:16),i=e.getUint32(n?16:20);if(t[25]===4||t[25]===6)return{width:r,height:i,alpha:!0};let s=r0(t,"IDAT");return{width:r,height:i,alpha:r0(s===-1?t:t.subarray(0,s),"tRNS")!==-1}}function l0(t,e=s0){let{width:n,height:r,data:i}=t,s=(f)=>{for(let l=f*n*4+3,d=l+n*4;l<d;l+=4)if(i[l]>=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 f=o;f<=a;f++){let l=f*n*4+3;for(let d=0;d<c;d++)if(i[l+d*4]>=e){c=d;break}for(let d=n-1;d>u;d--)if(i[l+d*4]>=e){u=d;break}}return{x:c,y:o,w:u-c+1,h:a-o+1}}function sr(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)<s0)n++;return Math.round(n*100/(e.w*e.h))}function f0(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=Ur(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 f=0;f<s;f++)a.set(o.data.subarray(f*i*4,(f+1)*i*4),((u+f)*e+c)*4);return{width:e,height:n,data:a}}function CR(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 Bd(t,e,n,r){if(n===r&&Number.isInteger(e)&&e>=0&&e+r<=t)return{first:Int32Array.from({length:r},(f,l)=>e+l),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 f=0;f<r;f++){let l=e+(f+0.5)*i,d=Math.floor(l-o-0.5),h=Math.max(0,Math.min(t-a,d));c[f]=h;let m=0;for(let p=d;p<=Math.ceil(l+o-0.5);p++){let b=CR((p+0.5-l)/s),$=f*a+Math.min(t-1,Math.max(0,p))-h;u[$]=(u[$]??0)+b,m+=b}for(let p=f*a;p<(f+1)*a;p++)u[p]=(u[p]??0)/m}return{first:c,size:a,weights:u}}function d0(t,e,n,r,i,s,o){let a=Bd(t,e.y,e.h,r),c=n*i,u=a.size+1,f=Array.from({length:u},()=>new Float32Array(c)),l=new Int32Array(u).fill(-1),d=new Float32Array(c),h=[],m=[];for(let p=0;p<r;p++){h.length=0,m.length=0;let b=a.first[p];for(let k=0;k<a.size;k++){let v=a.weights[p*a.size+k];if(v===0)continue;let S=b+k,x=S%u,M=f[x];if(l[x]!==S)s(S,M),l[x]=S;h.push(M),m.push(v)}let $=0;while($<h.length){let k=h[$],v=m[$];if(h.length-$>=4){let S=h[$+1],x=h[$+2],M=h[$+3],N=m[$+1],C=m[$+2],I=m[$+3];if($===0)for(let j=0;j<c;j++)d[j]=k[j]*v+S[j]*N+x[j]*C+M[j]*I;else for(let j=0;j<c;j++)d[j]=d[j]+(k[j]*v+S[j]*N+x[j]*C+M[j]*I);$+=4}else{if($===0)for(let S=0;S<c;S++)d[S]=k[S]*v;else for(let S=0;S<c;S++)d[S]=d[S]+k[S]*v;$+=1}}if(h.length===0)d.fill(0);o(p,d)}}function h0(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 Ur(t,e,n,r){let i=Bd(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 d0(t.height,e,n,r,4,(u,f)=>{let l=u*o*4,d=o,h=-1;for(let b=0,$=0;b<o*4;b+=4,$++){let k=s[l+b+3];if(k===0){a[b]=0,a[b+1]=0,a[b+2]=0,a[b+3]=0;continue}if($<d)d=$;h=$,a[b]=s[l+b]*k,a[b+1]=s[l+b+1]*k,a[b+2]=s[l+b+2]*k,a[b+3]=k}if(f.fill(0),h<0)return;let[m,p]=h0(i.first,i.size,n,d,h);for(let b=m;b<p;b++){let $=i.first[b]*4,k=b*i.size,v=0,S=0,x=0,M=0;for(let N=0;N<i.size;N++){let C=i.weights[k+N],I=$+N*4;v+=a[I]*C,S+=a[I+1]*C,x+=a[I+2]*C,M+=a[I+3]*C}f[b*4]=v,f[b*4+1]=S,f[b*4+2]=x,f[b*4+3]=M}},(u,f)=>{let l=u*n*4;for(let d=0;d<n;d++){let h=d*4,m=f[h+3];if(m<=0)continue;let p=f[h]/m;c[l+h]=(p<0?0:p>255?255:p)+0.5,p=f[h+1]/m,c[l+h+1]=(p<0?0:p>255?255:p)+0.5,p=f[h+2]/m,c[l+h+2]=(p<0?0:p>255?255:p)+0.5,c[l+h+3]=(m>255?255:m)+0.5}}),{width:n,height:r,data:c}}function Gd(t,e,n,r){let i=Bd(t.width,e.x,e.w,n),s=t.data,o=t.width,a=new Float32Array(n*r);return d0(t.height,e,n,r,1,(c,u)=>{let f=c*o,l=o,d=-1;for(let p=0;p<o;p++)if(s[f+p]!==0){if(p<l)l=p;d=p}if(u.fill(0),d<0)return;let[h,m]=h0(i.first,i.size,n,l,d);for(let p=h;p<m;p++){let b=f+i.first[p],$=p*i.size,k=0;for(let v=0;v<i.size;v++)k+=s[b+v]*i.weights[$+v];u[p]=k}},(c,u)=>{a.set(u,c*n)}),{width:n,height:r,data:a}}function ka(t,e){if(e<=0)return t;let n=Math.max(1,Math.ceil(e*3)),r=Array.from({length:2*n+1},(f,l)=>Math.exp(-((l-n)**2)/(2*e*e))),i=r.reduce((f,l)=>f+l,0),{width:s,height:o,data:a}=t,c=new Float32Array(s*o);for(let f=0;f<o;f++){let l=f*s;for(let d=0;d<s;d++){let h=0;for(let m=-n;m<=n;m++)h+=(a[l+Math.min(s-1,Math.max(0,d+m))]??0)*(r[m+n]??0);c[l+d]=h/i}}let u=new Float32Array(s*o);for(let f=0;f<o;f++){let l=f*s;for(let d=-n;d<=n;d++){let h=(r[d+n]??0)/i,m=Math.min(o-1,Math.max(0,f+d))*s;for(let p=0;p<s;p++)u[l+p]=(u[l+p]??0)+(c[m+p]??0)*h}}return{width:s,height:o,data:u}}function Ds(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 or(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 jR=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 _R(t){let e=4294967295;for(let n of t)e=(jR[(e^n)&255]??0)^e>>>8;return(e^4294967295)>>>0}function _r(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(_R(n.subarray(4,8+e.length)),8+e.length),n}function m0(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 p0(t){return NR(t,{level:1,strategy:AR.Z_RLE})}function g0(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(qs),_r("IHDR",r),...n,_r("IDAT",p0(m0(t.data,t.width,t.height))),_r("IEND",new Uint8Array)])}function b0(t){let[e,n,r]=ct(t),i=new Uint8Array(768);for(let s=0;s<256;s++)i.set([e,n,r],s*3);return _r("PLTE",i)}function w0(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(qs),_r("IHDR",s),_r("IDAT",p0(m0(i,t*r,e))),_r("IEND",new Uint8Array)])}function Wr(t){return w0(t.width,t.height,2,3,t.data)}function De(t){return w0(t.width,t.height,6,4,t.data)}function ar(t,e){return g0(t,$a,[b0(e),_r("tRNS",Uint8Array.from({length:256},(n,r)=>r))])}function Ud(t){return g0(t,0,[])}function $0(t){let e=a0(t)?.palette;if(!e||e.length<3)return;for(let n=3;n+2<e.length;n+=3)if(e[n]!==e[0]||e[n+1]!==e[1]||e[n+2]!==e[2])return;return`#${[...e.subarray(0,3)].map((n)=>n.toString(16).padStart(2,"0")).join("")}`}function lu(t,e){if(!Br(t)||t[25]!==$a)return;let n=Buffer.from(t.buffer,t.byteOffset,t.byteLength),r=[Buffer.from(qs)],i=qs.length;while(i+8<=n.length){let s=i+12+n.readUInt32BE(i);r.push(n.toString("latin1",i+4,i+8)==="PLTE"?b0(e):n.subarray(i,s)),i=s}return Buffer.concat(r)}var An=100,de=25000000,qR=536870912,Js=["safe","questionable","explicit"],Fi=["nudity","underwear"],qd=["comic","monochrome","sketch","chibi"],P0=["off","5","10","25","50","100"],I0=["off","720","1080","1440","1800","2560"],R0={nudity:new Set(["nude","naked","topless","bottomless","nipples","naked_towel","undressing"]),underwear:new Set(["underwear","panties","pantsu","bra","lingerie","pantyshot"])},DR={comic:new Set(["comic","4koma"]),monochrome:new Set(["monochrome","greyscale"]),sketch:new Set(["sketch","lineart","line_art"]),chibi:new Set(["chibi"])},JR=/^(?:rating|score|width|height|filetype|dimension):/,ya={safe:"s",questionable:"q",explicit:"e"},A0=8191,YR=20000,N0=5000,k0=3000,y0=8,VR=8,ZR=8000,XR=3000,T0=60000,v0=3,QR=3,tA="https://static.zerochan.net",H0="https://s1.zerochan.net",Dd=`ttheme/${dt.version} (+${dt.homepage})`,eA=["orig","tile","thumb","cut"],F0=new Map,nA=$A(process.env.TTHEME_FIND_HOSTS),rA=wA(process.env.TTHEME_FIND_CUTOUTS);WR(XR);var iA=["artist","character","copyright"];function S0(t){try{return BR(t)}catch{return[]}}function Ys(t){return t.startsWith("//")?`https:${t}`:t}function Kr(t){return(/\.([a-z0-9]+)(?:\?.*)?$/i.exec(t)?.[1]??"").toLowerCase()}function Vs(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 sA(t){let e=t.trim(),r=(e?JSON.parse(e):{}).tags??{};return new Map(Object.entries(r).map(([i,s])=>[i,String(s)]))}function Kd(t,e,n){let r=Ys(String(t??""));return{file:r,width:Number(e)||0,height:Number(n)||0,ext:Kr(r)}}function cr(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 L0(t,e){let n=Ys(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:cr(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((s)=>s.file&&s.width>0&&s.height>0&&s.width*s.height<r*i)}]}function oA(t){let e=sA(t);return Vs(t).flatMap((n)=>{let r=Ys(String(n.file_url??"")),i=String(n.tags??""),s=(o)=>cr(i).filter((a)=>e.get(a)===o);return L0(n,{preview:n.preview_url,file:r,ext:String(n.file_ext||Kr(r)).toLowerCase(),owner:n.author,md5:n.md5,tags:i,named:{artist:s("artist"),character:s("character"),copyright:s("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 aA(t){return Vs(t).flatMap((e)=>{let n=Ys(String(e.file_url??"")),r=String(e.tag_string??""),i=e.media_asset??{};return L0(e,{preview:i.variants?.find((s)=>s.type==="360x360")?.url??e.preview_file_url,file:n,ext:String(e.file_ext||Kr(n)).toLowerCase(),owner:"",md5:e.md5,tags:r,named:{artist:cr(e.tag_string_artist),character:cr(e.tag_string_character),copyright:cr(e.tag_string_copyright)},solo:r.split(/\s+/).includes("solo"),versions:(i.variants??[]).map((s)=>Kd(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 C0(t){return t.toLowerCase().replace(/\s+/g,"_")}function cA(t){return(Array.isArray(t)?t:[]).map((e)=>C0(String(e)))}function uA(t){return String(t??"").replace(/[^0-9a-z]+/gi,".").replace(/^\.+|\.+$/g,"")||"zerochan"}function lA(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=cA(i.tags),a=Ys(String(i.full??""));return[{id:s,width:Number(i.width)||0,height:Number(i.height)||0,file:a,ext:Kr(a),preview:`${H0}/${uA(i.tag??i.primary)}.600.${s}.jpg`,owner:"",score:0,rating:o.some((c)=>R0.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 fA={mangaka:"artist",studio:"artist",character:"character",series:"copyright",game:"copyright"};function E0(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 dA(t){let e={artist:[],character:[],copyright:[]};for(let[,r,i]of t.matchAll(/<li class="([a-z]+)[^"]*"[^>]*\bdata-tag="([^"]*)"/g)){let s=fA[r],o=C0(E0(i));if(s&&!e[s].includes(o))e[s].push(o)}let n=zd(/"datePublished":\s*"([^"]+)"/.exec(t)?.[1]);return{named:e,source:"",owner:E0(/\buploader = \{\s*name: '([^']*)'/.exec(t)?.[1]??""),...n?{posted:n}:{}}}function hA(t){return Number(/Zerochan has ([\d,]+) /.exec(t)?.[1]?.replace(/,/g,"")??0)}function mA(t){return Vs(t).flatMap((e)=>{let n=String(e.value??"");return n?[{value:n,count:Number(e.post_count)||0}]:[]})}function pA(t){return Vs(t).flatMap((e)=>{let n=String(e.name??"");return n?[{value:n,count:Number(e.count)||0}]:[]})}function gA(t){return Number(/count="(\d+)"/.exec(t)?.[1]??0)}function bA(t){let n=(t.trim()?JSON.parse(t):{}).counts?.posts;return n===null?Number.NaN:Number(n)||0}function wA(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 $A(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 fu(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 Li(t){return fu(t,Js,["safe"])}function Zs(t){return fu(t,Fi,Fi,"none")}function du(t){return fu(t,qd,[],"none")}function Sa(t){let e=Z.map((n)=>n.name);return fu(t,e,e)}function Jd(t,e,n){return{score:Number(t)||0,size:Number(e)||0,png:n==="on"}}function Ea(t){return[...new Set((t??"").toLowerCase().split(/[\s,]+/).map((e)=>e.replace(/^-+/,"")).filter(Boolean))]}function Yd(t,e,n){return{safe:new Set(t),questionable:new Set(e),explicit:new Set(n)}}function Vd(t){let e=nA.get(t.key),n=rA.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 j0(t){return t.length<2?t.join(""):t.map((e)=>`~${e}`).join(" ")}function _0(t){return t>0?[`width:>=${t}`,`height:>=${t}`]:[]}function M0(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}`]:[],..._0(i)],cutouts:j0(e.cutouts),ratings:Yd([ya.safe],[ya.questionable],[ya.explicit]),rate:(r)=>{let[i]=r;if(r.length===1&&i)return`rating:${ya[i]}`;let s=Js.filter((a)=>!r.includes(a)),[o]=s;return s.length===1&&o?`-rating:${ya[o]}`:""},best:"order:score",tagBudget:Number.POSITIVE_INFINITY,ors:!0,postsUrl:(r,i)=>`${e.origin}/post.json?${n({limit:String(An),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:oA,count:gA,uploadedBy:(r)=>`user:${r}`}}function kA(t){let e=Vd(t),n=Yd(["g"],["s","q"],["e"]);return{...e,scored:!0,narrow:({score:r,size:i,png:s})=>[...r>0?[`score:>=${r}`]:[],..._0(i),...s?["filetype:png"]:[]],cutouts:j0(e.cutouts),ratings:n,rate:(r)=>r.length===Js.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(An),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:aA,count:bA,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 x0(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 yA(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:Yd(["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(An),p:String(r+1),...x0(n)})}`,countUrl:(n)=>`${e.origin}/${Wd(n)}?${new URLSearchParams({xml:"",l:"1"})}`,postUrl:(n)=>`${e.origin}/${n}?json=`,pageUrl:(n)=>`${e.origin}/${n}`,parse:lA,count:hA,credits:dA,counts:(n)=>Wd(n).split(",").length===1&&!("d"in x0(n)),guesses:(n)=>(n.tags.includes("transparent_background")?["png","jpg"]:["jpg","png"]).map((r)=>n.preview.replace(H0,tA).replace(/\.600\.(\d+)\.jpg$/,`.full.$1.${r}`))}}function vA(t){let e=O0(`https://${t}`);return Z.find((n)=>O0(n.origin)===e)}function Zd(t){return t.split(/\s+/).filter((e)=>e&&!JR.test(e)).length}function hu(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=Z.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=vA(i.host),o=Number(i.searchParams.get("id")??i.pathname.split("/").findLast(Boolean));return s&&o>0?{site:s,id:o}:void 0}var Z=[kA({key:"danbooru",name:"danbooru",origin:"https://shima.donmai.us",cutouts:["transparent_background"],vouched:!1,ansi:2}),M0({key:"konachan",name:"konachan",origin:"https://konachan.net",cutouts:["transparent","vector"],vouched:!1,ansi:6}),M0({key:"yande",name:"yande.re",origin:"https://yande.re",cutouts:["transparent_png"],vouched:!0,ansi:5}),yA({key:"zerochan",name:"zerochan",origin:"https://www.zerochan.net",cutouts:["transparent_background"],vouched:!1,ansi:3})],It=Z.find((t)=>t.key==="danbooru"),zr=134217728;function ee(t,e){let n=Z.indexOf(t);return(n===-1?Z.length:n)*zr+e}function O0(t){let e;try{e=new URL(t).hostname}catch{return""}return e.split(".").slice(-2).join(".")}function qr(t,e,n=e){return e.mirror&&n===e?{site:It,url:e.mirror.file}:{site:t,url:n.file}}function mu(t,e){return e.mirror?{site:It,url:e.mirror.preview}:{site:t,url:e.preview}}function pu(t,e=Fi){return t.tags.filter((n)=>e.some((r)=>R0[r].has(n)))}function B0(t,e){return t.tags.filter((n)=>e.some((r)=>DR[r].has(n)))}function gu(t,e,n=["safe"]){return n.some((r)=>t.ratings[r].has(e.rating))}function G0(t,e){return t.rate(["safe"])===""?void 0:Js.find((n)=>t.ratings[n].has(e.rating))}function un(t){return[t,...t.smaller].find((e)=>e.width*e.height<=de)}function U0(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 Tn(){return va(process.env.XDG_CACHE_HOME??va(KR(),".cache"),"ttheme")}function ln(t){return va(Tn(),t.key)}function W0(t=qR,e=Tn()){let n=[],r=0;for(let i of S0(e))for(let s of eA){let o=va(e,i,s);for(let a of S0(o)){let c=va(o,a);try{let{size:u,mtimeMs:f}=UR(c);n.push({path:c,size:u,at:f}),r+=u}catch{}}}n.sort((i,s)=>i.at-s.at);for(let i of n){if(r<=t)return;try{GR(i.path,{force:!0}),r-=i.size}catch{}}}function SA(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)?T0:Math.max(0,n-e)}function Nn(t){return F0.get(t.key)??0}function EA(t){for(let e=t;e instanceof Error;e=e.cause)if(e.code==="ECONNRESET")return!0;return!1}function MA(t){return(t.headers.get("server")??"").startsWith("cloudflare")&&t.headers.get("cf-mitigated")==="challenge"}function xA(t,e){let n=new URL(e,t);if(!n.search)n.search=new URL(t).search;return n.href}async function ur(t,e,n,r={},i=YR){let s=e;for(let o=1,a=0;;o++){let c=Nn(t)-Date.now();if(c>0)await zR(c,void 0,{signal:n});let u;try{u=await fetch(s,{headers:{"User-Agent":Dd,Referer:`${t.origin}/`,...r},redirect:"manual",signal:i?AbortSignal.any([n,AbortSignal.timeout(i)]):n})}catch(l){if(o<v0&&!n.aborted&&EA(l))continue;throw l}let f=u.headers.get("location");if(f&&u.status>=300&&u.status<400&&a<QR){await u.body?.cancel(),s=xA(s,f),a++,o--;continue}if(u.status===429&&o<v0){await u.body?.cancel();let l=SA(u.headers.get("retry-after"),Date.now());if(l>T0)throw Error(`${t.name} asks to wait ${Math.ceil(l/1000)}s`);F0.set(t.key,Math.max(Nn(t),Date.now()+l));continue}if(!u.ok)throw await u.body?.cancel(),Object.assign(Error(MA(u)?`${t.name} is behind a Cloudflare challenge`:`${t.name} answered ${u.status}`),{status:u.status});return u}}async function bu(t,e,n){try{return await(await ur(t,e,n)).text()}catch(r){if(t.missing!==void 0&&r.status===t.missing)return"";throw r}}async function K0(t,e,n,r){return t.parse(await bu(t,t.postsUrl(e,n),r))}async function Xd(t,e,n){return t.count(await bu(t,t.countUrl(e),n))}async function Ci(t,e,n){let[r]=t.parse(await bu(t,t.postUrl(e),n));return r}async function Ma(t,e,n){return t.credits?.(await bu(t,t.pageUrl(e),n))}var OA=/^https?:\/\/(?:i\.pximg\.net|i\d*\.pixiv\.net|img\d*\.pixiv\.net)\/\S*\/(\d+)(?:_p\d+)?(?:_\w+)?\.\w+(?:[?#]\S*)?$/i,PA=/^https?:\/\/(?:www\.)?pixiv\.net\/member_illust\.php\?\S*\billust_id=(\d+)/i;function ji(t){let e=OA.exec(t)?.[1]??PA.exec(t)?.[1];return e?`https://www.pixiv.net/artworks/${e}`:t}function xa(t,e){return t.credits!==void 0&&e.named.artist.length===0}function Xs(t,e){for(let n of iA){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 IA(t){let e=new URLSearchParams({limit:String(2*An),only:"md5,tag_string,tag_string_artist,tag_string_character,tag_string_copyright,source,file_url",tags:`md5:${t.join(",")}`});return`${It.origin}/posts.json?${e}`}function RA(t){return new Map(Vs(t).flatMap((e)=>{let n=String(e.md5??"");return n?[[n,{tags:cr(e.tag_string),named:{artist:cr(e.tag_string_artist),character:cr(e.tag_string_character),copyright:cr(e.tag_string_copyright)},source:String(e.source??""),file:Ys(String(e.file_url??""))}]]:[]}))}function Oa(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])],Xs(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=Kr(r.file)}}}async function Pa(t,e){let n=new Map;if(Nn(It)>Date.now())return n;for(let r=0;r<t.length;r+=An){let i=await(await ur(It,IA(t.slice(r,r+An)),e,{},N0)).text();for(let[s,o]of RA(i))n.set(s,o)}return n}function AA(t){let e=new URLSearchParams([...t.map((n)=>["search[name_array][]",n]),["only","name,is_deleted,urls"],["limit",String(t.length)]]);return`${It.origin}/artists.json?${e}`}function NA(t){return new Map(Vs(t).flatMap((e)=>{let n=String(e.name??"");if(!n||e.is_deleted===!0)return[];let r=Array.isArray(e.urls)?e.urls:[];return[[n,r.flatMap((i)=>i.is_active===!1||!i.url?[]:[String(i.url)])]]}))}async function z0(t,e){let n=new Map;if(Nn(It)>Date.now())return n;for(let r=0;r<t.length;r+=An){let i=await(await ur(It,AA(t.slice(r,r+An)),e,{},N0)).text();for(let[s,o]of NA(i))n.set(s,o)}return n}async function Ia(t,e,n){if(e.file||!t.guesses)return;for(let r of t.guesses(e))try{let i=await ur(t,r,n,{Range:`bytes=0-${A0}`}),s=Rn(new Uint8Array(await i.arrayBuffer()));return e.file=r,e.ext=Kr(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 q0(t,e){if(Nn(It)<=Date.now())try{let i=new URLSearchParams({"search[query]":t,"search[type]":"tag_query",limit:String(y0)}),s=`${It.origin}/autocomplete.json?${i}`;return mA(await(await ur(It,s,e,{},k0)).text())}catch(i){if(e.aborted)throw i}let n=Z.find((i)=>i.key==="yande"),r=new URLSearchParams({name:t,order:"count",limit:String(y0)});return pA(await(await ur(n,`${n.origin}/tag.json?${r}`,e,{},k0)).text())}function TA(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 D0(t,e){if(Nn(It)>Date.now())return[];let n=new URLSearchParams({"search[query]":t,"search[category]":"character",limit:String(VR)});return TA(await(await ur(It,`${It.origin}/related_tag.json?${n}`,e,{},ZR)).text())}function J0(t,e){return e.slice(0,t.ors?t.tagBudget:1)}async function Y0(t,e,n){let r=await ur(t,e,n,{Range:`bytes=0-${A0}`});return Rn(new Uint8Array(await r.arrayBuffer()))}async function wu(t,e,n,r){let i=await ur(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:l,value:d}=await o.read();if(l)break;a.push(d),c+=d.length,r?.(c,s)}let u=new Uint8Array(c),f=0;for(let l of a)u.set(l,f),f+=l.length;return u}var HA=["pixiv","x","bsky","fanbox","skeb","patreon","fantia"],V0=[["pixiv",/^https?:\/\/(?:www\.)?pixiv\.net\/(?:en\/)?users\/(\d+)\/?$/i,(t)=>`https://www.pixiv.net/users/${t}`],["pixiv",/^https?:\/\/(?:www\.)?pixiv\.net\/member\.php\?id=(\d+)$/i,(t)=>`https://www.pixiv.net/users/${t}`],["x",/^https?:\/\/(?:www\.|mobile\.)?(?:twitter|x)\.com\/(?!(?:i|intent|home|search|explore|hashtag|share|settings)\/?$)(\w{1,15})\/?$/i,(t)=>`https://x.com/${t}`],["bsky",/^https?:\/\/bsky\.app\/profile\/(?!did:)([\w.-]+)\/?$/i,(t)=>`https://bsky.app/profile/${t}`],["fanbox",/^https?:\/\/([\w-]+)\.fanbox\.cc\/?$/i,(t)=>`https://${t}.fanbox.cc`],["fanbox",/^https?:\/\/(?:www\.)?pixiv\.net\/fanbox\/creator\/(\d+)\/?$/i,(t)=>`https://www.pixiv.net/fanbox/creator/${t}`],["skeb",/^https?:\/\/skeb\.jp\/@([\w-]+)\/?$/i,(t)=>`https://skeb.jp/@${t}`],["patreon",/^https?:\/\/(?:www\.)?patreon\.com\/(?:c\/)?(?!(?:user|posts|join|home|login|search)\/?$)([\w-]+)\/?$/i,(t)=>`https://www.patreon.com/${t}`],["fantia",/^https?:\/\/fantia\.jp\/fanclubs\/(\d+)\/?$/i,(t)=>`https://fantia.jp/fanclubs/${t}`]],FA=[[/^https?:\/\/(?:www\.)?pixiv\.net\/(?:en\/)?artworks\/(\d+)/i,(t)=>`pixiv ${t[1]}`],[/^https?:\/\/(?:www\.|mobile\.)?(?:twitter|x)\.com\/(\w{1,15})\/status\/\d+/i,(t)=>`x ${t[1]}`],[/^https?:\/\/bsky\.app\/profile\/([\w.-]+)\/post\//i,(t)=>`bsky ${t[1]}`],[/^https?:\/\/([\w-]+)\.fanbox\.cc\/posts\/\d+/i,(t)=>`fanbox ${t[1]}`]],LA=[[/^https?:\/\/(?:www\.)?pixiv\.net\//i,"pixiv"],[/^https?:\/\/(?:www\.|mobile\.)?(?:twitter|x)\.com\//i,"x"],[/^https?:\/\/bsky\.app\//i,"bsky"]],CA=["x","pixiv","bsky"],jA={"shima.donmai.us":"danbooru.donmai.us"},_A=/^https?:\/\/[^\s\p{Cc}]+$/u;function Z0(t){return _A.test(t)}function BA(t){return V0.find(([,e])=>e.test(t))?.[0]}function GA(t){return HA.flatMap((e)=>{for(let[,n,r]of V0.filter(([i])=>i===e))for(let i of t){let s=n.exec(i)?.[1];if(s)return[r(s)]}return[]})}function Ra(t){return(t??[]).flatMap((e)=>{let n=BA(e);return n?[{kind:n,url:e}]:[]})}function UA(t){for(let[e,n]of FA){let r=e.exec(t);if(r)return n(r)}try{return new URL(t).hostname.replace(/^www\./,"")}catch{return t}}function WA(t){try{let e=new URL(t),n=jA[e.hostname];if(n)e.hostname=n;return e.href}catch{return t}}function KA(t){return t.replace(/^https?:\/\/(?:www\.)?/,"")}function Qd(t){let e=t.source??"";return Z0(e)?{label:UA(e),url:e}:void 0}function zA(t){let e=(t.from??"").split(" "),n=e[2]??"";return Z0(n)?{label:e.slice(0,2).join(" "),url:n}:void 0}function qA(t,e){let n=e?LA.find(([s])=>s.test(e))?.[1]:void 0,r=Ra(t),i=CA.find((s)=>s!==n&&r.some((o)=>o.kind===s));return r.find((s)=>s.kind===i)?.url}function X0(t){let e=Qd(t)?.url??zA(t)?.url,n=t.artist??[];if(!e&&n.length===0)return;let r=n.length>0?`Background art by ${n.map((i)=>{let s=qA(t.profiles?.[i],e);return s?`${i} (${KA(s)})`:i}).join(", ")}`:"Background art (artist unknown)";return e?`${r} · ${WA(e)}`:r}async function $u(t,e){let n=await z0(t,e);return new Map(t.map((r)=>[r,GA(n.get(r)??[])]))}import{spawn as DA}from"node:child_process";var JA=30000,YA=3,VA=97,th={from:0.45,to:0.75},ku=2,Aa=1,ZA=Uint8Array.from({length:256},(t,e)=>Math.round(255*Math.min(1,Math.max(0,(e/255-th.from)/(th.to-th.from))))),XA=`ObjC.import('Vision')
4
+ ObjC.import('CoreImage')
5
+ ObjC.import('CoreGraphics')
6
+ function run(argv) {
7
+ const error = Ref()
8
+ const image = $.CIImage.imageWithContentsOfURLOptions($.NSURL.fileURLWithPath(argv[0]),
9
+ $.NSDictionary.dictionaryWithObjectForKey($.NSNumber.numberWithBool(true), $.kCIImageApplyOrientationProperty))
10
+ if (!image) throw new Error('unreadable image')
11
+ const handler = $.VNImageRequestHandler.alloc.initWithCIImageOptions(image, $({}))
12
+ const request = $.VNGenerateForegroundInstanceMaskRequest.alloc.init
13
+ if (!handler.performRequestsError($([request]), error)) throw new Error('vision failed')
14
+ if (request.results.count === 0) throw new Error('no foreground')
15
+ const found = request.results.objectAtIndex(0)
16
+ const buffer = found.generateMaskedImageOfInstancesFromRequestHandlerCroppedToInstancesExtentError(
17
+ found.allInstances, handler, false, error)
18
+ if (!buffer) throw new Error('mask failed')
19
+ const written = $.CIContext.context.writePNGRepresentationOfImageToURLFormatColorSpaceOptionsError(
20
+ $.CIImage.imageWithCVPixelBuffer(buffer), $.NSURL.fileURLWithPath(argv[1]), $.kCIFormatRGBA8,
21
+ $.CGColorSpaceCreateWithName($.kCGColorSpaceSRGB), $({}), error)
22
+ if (!written) throw new Error('write failed')
23
+ }`;function Qs(){return process.platform==="darwin"}function yu(t){return t>=YA&&t<=VA}function Q0(t){let{width:e,height:n}=t,r=t.data.slice();for(let i=3;i<r.length;i+=4)r[i]=ZA[r[i]];for(let i=0;i<n;i++)for(let s=0;s<e;s++){let o=(i*e+s)*4,a=r[o+3];if(a===0||a===255)continue;let c=0,u=0,f=0,l=0;for(let d=Math.max(0,i-ku);d<=Math.min(n-1,i+ku);d++)for(let h=Math.max(0,s-ku);h<=Math.min(e-1,s+ku);h++){let m=(d*e+h)*4;if(r[m+3]===255)c+=r[m],u+=r[m+1],f+=r[m+2],l++}if(l>0)r[o]=Math.round(c/l),r[o+1]=Math.round(u/l),r[o+2]=Math.round(f/l)}return{width:e,height:n,data:r}}function Na(t,e,n){return new Promise((r,i)=>{let s=DA("osascript",["-l","JavaScript","-e",XA,t,e],{stdio:["ignore","ignore","pipe"],signal:AbortSignal.any([n,AbortSignal.timeout(JA)])}),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(`
24
+ `).at(-1)||`osascript exited ${a}`))})})}import{createHash as QA}from"node:crypto";import{existsSync as tN,readdirSync as eN,readFileSync as nN,rmSync as rN,statSync as iN,utimesSync as sN}from"node:fs";import{join as eo}from"node:path";var oN=12,aN=/^[0-9a-f]{40}$/;function to(){return eo(Tn(),"drawn")}function t$(t){return QA("sha1").update(JSON.stringify(t)).digest("hex")}function e$(t){return tN(eo(to(),t))}function n$(t){let e=eo(to(),t);try{let n=nN(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 sN(e,a,a),{stem:i.stem,fill:i.fill,...i.peak?{peak:i.peak}:{},figure:s,picture:o}}catch{return}}function eh(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),H(eo(to(),t),Buffer.concat([r,n,e.figure,e.picture])),cN()}function cN(){let t=eN(to()).filter((e)=>aN.test(e)).flatMap((e)=>{try{return[{name:e,at:iN(eo(to(),e)).mtimeMs}]}catch{return[]}}).sort((e,n)=>n.at-e.at);for(let{name:e}of t.slice(oN))rN(eo(to(),e),{force:!0})}import{readdirSync as c$,readFileSync as u$}from"node:fs";import{basename as pN,join as Mu}from"node:path";/*!
4
25
  * Copyright (c) Squirrel Chat et al., All rights reserved.
5
26
  * SPDX-License-Identifier: BSD-3-Clause
6
27
  *
@@ -26,9 +47,9 @@ import{createRequire as _P}from"node:module";var NP=Object.create;var{getPrototy
26
47
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
48
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
49
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
- */function BA(t,e){let n=t.slice(0,e).split(/\r?\n/);return[n.length,n.pop().length+1]}function UA(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+=`
50
+ */function uN(t,e){let n=t.slice(0,e).split(/\r?\n/);return[n.length,n.pop().length+1]}function lN(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
51
  `,o===e)i+=" ".repeat(s+n+2),i+=`^
31
- `}return i}class D extends Error{line;column;codeblock;constructor(t,e){let[n,r]=BA(e.toml,e.ptr),i=UA(e.toml,n,r);super(`Invalid TOML document: ${t}
52
+ `}return i}class D extends Error{line;column;codeblock;constructor(t,e){let[n,r]=uN(e.toml,e.ptr),i=lN(e.toml,n,r);super(`Invalid TOML document: ${t}
32
53
 
33
54
  ${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
55
  * Copyright (c) Squirrel Chat et al., All rights reserved.
@@ -56,7 +77,7 @@ ${i}`,e);this.line=n,this.column=r,this.codeblock=i}static x(t,e,n){throw new D(
56
77
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
57
78
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
58
79
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59
- */function mu(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)D.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,f=0,l=n===120?2:n===117?4:8;for(let d=0;d<l;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)D.x("invalid non-hex character in unicode escape",t);f=f<<4|m}if(f<0||f>1114111||f>=55296&&f<=57343)D.x("invalid unicode escape",t,u);o+=String.fromCodePoint(f),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+=`
80
+ */function vu(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)D.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,f=0,l=n===120?2:n===117?4:8;for(let d=0;d<l;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)D.x("invalid non-hex character in unicode escape",t);f=f<<4|m}if(f<0||f>1114111||f>=55296&&f<=57343)D.x("invalid unicode escape",t,u);o+=String.fromCodePoint(f),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
81
  `;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 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
82
  * Copyright (c) Squirrel Chat et al., All rights reserved.
62
83
  * SPDX-License-Identifier: BSD-3-Clause
@@ -83,7 +104,7 @@ ${i}`,e);this.line=n,this.column=r,this.codeblock=i}static x(t,e,n){throw new D(
83
104
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
84
105
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
85
106
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
86
- */var WA=/^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;class Ur extends Date{#e=!1;#r=!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(WA);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.#r=i,this.#t=s}isDateTime(){return this.#e&&this.#r}isLocal(){return!this.#e||!this.#r||!this.#t}isDate(){return this.#e&&!this.#r}isTime(){return this.#r&&!this.#e}isValid(){return this.#e||this.#r}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 Ur(t);return n.#t=e,n}static wrapAsLocalDateTime(t){let e=new Ur(t);return e.#t=null,e}static wrapAsLocalDate(t){let e=new Ur(t);return e.#r=!1,e.#t=null,e}static wrapAsLocalTime(t){let e=new Ur(t);return e.#e=!1,e.#t=null,e}}/*!
107
+ */var fN=/^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;class Dr extends Date{#e=!1;#r=!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(fN);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.#r=i,this.#t=s}isDateTime(){return this.#e&&this.#r}isLocal(){return!this.#e||!this.#r||!this.#t}isDate(){return this.#e&&!this.#r}isTime(){return this.#r&&!this.#e}isValid(){return this.#e||this.#r}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 Dr(t);return n.#t=e,n}static wrapAsLocalDateTime(t){let e=new Dr(t);return e.#t=null,e}static wrapAsLocalDate(t){let e=new Dr(t);return e.#r=!1,e.#t=null,e}static wrapAsLocalTime(t){let e=new Dr(t);return e.#e=!1,e.#t=null,e}}/*!
87
108
  * Copyright (c) Squirrel Chat et al., All rights reserved.
88
109
  * SPDX-License-Identifier: BSD-3-Clause
89
110
  *
@@ -109,7 +130,7 @@ ${i}`,e);this.line=n,this.column=r,this.codeblock=i}static x(t,e,n){throw new D(
109
130
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
110
131
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
111
132
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
112
- */function Te(t,e=10){return e===16?t>47&&t<58||t>64&&t<71||t>96&&t<103:t>47&&t<48+e}function qd(t,e){return t===32||t===9||t===10||t===13||e&&(t===e||t===44)||t===35}function Pa(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?J0(t):D0(t);return t.d++,i}if(r===34||r===39)return mu(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 pu(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 KA(t,r,e);if(t.s.charCodeAt(t.p+2)===58)return zA(t,r,e);return pu(t,t.p,r,0,e)}function pu(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)D.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)D.x("invalid value",t,e);return t.p++,NaN}if(s===48){if(++t.p>=t.s.length||qd(s=t.s.charCodeAt(t.p),i))return t.bi===!0?0n:0;if(!r){if(s===120)return zd(t,e,16,i);else if(s===98)return zd(t,e,2,i);else if(s===111)return zd(t,e,8,i)}if(s===46)o=2;else if(s===101||s===69)o=4;else D.x("illegal leading zero",t,e)}else if(!Te(s))D.x("invalid value",t,e);while(++t.p<t.s.length&&(s=t.s.charCodeAt(t.p),!qd(s,i))){if(!o)o=1;if(s===95){if(!(o&1))D.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(!Te(s))D.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))D.x("unfinished numeric value",t,e);let c=t.s.slice(e,t.p);if(a)c=c.replaceAll("_","");return o>1?parseFloat(c):q0(t,c,10,e)}function zd(t,e,n,r){let i,s=1;while(++t.p<t.s.length&&(i=t.s.charCodeAt(t.p),!qd(i,r)))if(i===95){if(s&1)D.x("illegal underscore",t);s=3}else if(!Te(i,n))D.x("illegal character in numeric literal",t);else if(s&1)s--;if(s&1)D.x("unfinished numeric value",t);let o=t.s.slice(e+2,t.p);if(s)o=o.replaceAll("_","");return q0(t,o,n,e)}function q0(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 KA(t,e,n){let r=t.p++,i;if(!Te(e)||!Te(t.s.charCodeAt(t.p++))||!Te(t.s.charCodeAt(t.p++))||!Te(t.s.charCodeAt(t.p++)))return pu(t,t.p=r,e,0,n);if(t.p+=5,!Te(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,!Te(t.s.charCodeAt(t.p+1))))&&e!==84&&e!==116){let o=t.s.slice(r,t.p);return Oa(t,o,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(Te(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 Oa(t,o,1,i,r,"[+00:00]")}if(e===43||e===45){let o=t.s.slice(r,t.p+=6);return Oa(t,o,1,i,r,!t.ld&&"["+t.s.slice(t.p-6,t.p)+"]")}}let s=t.s.slice(r,t.p);return Oa(t,s,2,i,r)}function zA(t,e,n){let r=t.p;if(!Te(e)||!Te(t.s.charCodeAt(++t.p)))return pu(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(Te(t.s.charCodeAt(++t.p)));let i=t.s.slice(r,t.p);return Oa(t,i,4,!1,r)}function Oa(t,e,n,r,i,s){if(t.ld){let o=new Ur(e,n,r);if(!o.isValid())D.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){D.x(o instanceof Error?o.message:""+o,t,i)}}/*!
133
+ */function He(t,e=10){return e===16?t>47&&t<58||t>64&&t<71||t>96&&t<103:t>47&&t<48+e}function rh(t,e){return t===32||t===9||t===10||t===13||e&&(t===e||t===44)||t===35}function Ha(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?s$(t):i$(t);return t.d++,i}if(r===34||r===39)return vu(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 Su(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 dN(t,r,e);if(t.s.charCodeAt(t.p+2)===58)return hN(t,r,e);return Su(t,t.p,r,0,e)}function Su(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)D.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)D.x("invalid value",t,e);return t.p++,NaN}if(s===48){if(++t.p>=t.s.length||rh(s=t.s.charCodeAt(t.p),i))return t.bi===!0?0n:0;if(!r){if(s===120)return nh(t,e,16,i);else if(s===98)return nh(t,e,2,i);else if(s===111)return nh(t,e,8,i)}if(s===46)o=2;else if(s===101||s===69)o=4;else D.x("illegal leading zero",t,e)}else if(!He(s))D.x("invalid value",t,e);while(++t.p<t.s.length&&(s=t.s.charCodeAt(t.p),!rh(s,i))){if(!o)o=1;if(s===95){if(!(o&1))D.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(!He(s))D.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))D.x("unfinished numeric value",t,e);let c=t.s.slice(e,t.p);if(a)c=c.replaceAll("_","");return o>1?parseFloat(c):r$(t,c,10,e)}function nh(t,e,n,r){let i,s=1;while(++t.p<t.s.length&&(i=t.s.charCodeAt(t.p),!rh(i,r)))if(i===95){if(s&1)D.x("illegal underscore",t);s=3}else if(!He(i,n))D.x("illegal character in numeric literal",t);else if(s&1)s--;if(s&1)D.x("unfinished numeric value",t);let o=t.s.slice(e+2,t.p);if(s)o=o.replaceAll("_","");return r$(t,o,n,e)}function r$(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 dN(t,e,n){let r=t.p++,i;if(!He(e)||!He(t.s.charCodeAt(t.p++))||!He(t.s.charCodeAt(t.p++))||!He(t.s.charCodeAt(t.p++)))return Su(t,t.p=r,e,0,n);if(t.p+=5,!He(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,!He(t.s.charCodeAt(t.p+1))))&&e!==84&&e!==116){let o=t.s.slice(r,t.p);return Ta(t,o,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(He(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 Ta(t,o,1,i,r,"[+00:00]")}if(e===43||e===45){let o=t.s.slice(r,t.p+=6);return Ta(t,o,1,i,r,!t.ld&&"["+t.s.slice(t.p-6,t.p)+"]")}}let s=t.s.slice(r,t.p);return Ta(t,s,2,i,r)}function hN(t,e,n){let r=t.p;if(!He(e)||!He(t.s.charCodeAt(++t.p)))return Su(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(He(t.s.charCodeAt(++t.p)));let i=t.s.slice(r,t.p);return Ta(t,i,4,!1,r)}function Ta(t,e,n,r,i,s){if(t.ld){let o=new Dr(e,n,r);if(!o.isValid())D.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){D.x(o instanceof Error?o.message:""+o,t,i)}}/*!
113
134
  * Copyright (c) Squirrel Chat et al., All rights reserved.
114
135
  * SPDX-License-Identifier: BSD-3-Clause
115
136
  *
@@ -135,7 +156,7 @@ ${i}`,e);this.line=n,this.column=r,this.codeblock=i}static x(t,e,n){throw new D(
135
156
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
136
157
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
137
158
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
138
- */function qA(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 cn(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;qA(t)}}/*!
159
+ */function mN(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 fn(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;mN(t)}}/*!
139
160
  * Copyright (c) Squirrel Chat et al., All rights reserved.
140
161
  * SPDX-License-Identifier: BSD-3-Clause
141
162
  *
@@ -161,7 +182,7 @@ ${i}`,e);this.line=n,this.column=r,this.codeblock=i}static x(t,e,n){throw new D(
161
182
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
162
183
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
163
184
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
164
- */function gu(t,e=61){let n,r=0,i=[],s,o=t.s.charCodeAt(n=t.p);do if(o===e){if(!r)D.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)D.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))D.x("illegal quoted key: multiline strings are not allowed",t);i.push(mu(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)D.x("illegal character in key",t);else if(!r)r=1,s=t.p;while(o=t.s.charCodeAt(++t.p));D.x("incomplete key-value: cannot find end of key",t,n)}function D0(t){let e=t.p++,n=Object.create(null),r=new Set,i;while(t.p<t.s.length){if(cn(t),(i=t.s.charCodeAt(t.p))===125)return t.p++,n;let s,o=n,a=!1,c=t.p,u=gu(t);for(let l=0;l<u.length;l++){if(l)o=a?o[s]:o[s]=Object.create(null);if(s=u[l],(a=Object.hasOwn(o,s))&&(typeof o[s]!=="object"||r.has(o[s])))D.x("trying to redefine an already defined value",t,c);let d=s==="__proto__";if(t.uk&&(d||s==="constructor")){o=t.uk!==1&&D.x("document contains an unsafe property",t,c);break}if(!a&&d)Object.defineProperty(o,s,{enumerable:!0,configurable:!0,writable:!0})}if(a)D.x("trying to redefine an already defined value",t,c);cn(t,!0,!0);let f=Pa(t,125);if(o&&typeof(o[s]=f)==="object")r.add(f);if(cn(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 J0(t){let e=t.p++,n=[],r;while(t.p<t.s.length){if(cn(t),(r=t.s.charCodeAt(t.p))===93)return t.p++,n;if(n.push(Pa(t,93)),cn(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)}/*!
185
+ */function Eu(t,e=61){let n,r=0,i=[],s,o=t.s.charCodeAt(n=t.p);do if(o===e){if(!r)D.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)D.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))D.x("illegal quoted key: multiline strings are not allowed",t);i.push(vu(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)D.x("illegal character in key",t);else if(!r)r=1,s=t.p;while(o=t.s.charCodeAt(++t.p));D.x("incomplete key-value: cannot find end of key",t,n)}function i$(t){let e=t.p++,n=Object.create(null),r=new Set,i;while(t.p<t.s.length){if(fn(t),(i=t.s.charCodeAt(t.p))===125)return t.p++,n;let s,o=n,a=!1,c=t.p,u=Eu(t);for(let l=0;l<u.length;l++){if(l)o=a?o[s]:o[s]=Object.create(null);if(s=u[l],(a=Object.hasOwn(o,s))&&(typeof o[s]!=="object"||r.has(o[s])))D.x("trying to redefine an already defined value",t,c);let d=s==="__proto__";if(t.uk&&(d||s==="constructor")){o=t.uk!==1&&D.x("document contains an unsafe property",t,c);break}if(!a&&d)Object.defineProperty(o,s,{enumerable:!0,configurable:!0,writable:!0})}if(a)D.x("trying to redefine an already defined value",t,c);fn(t,!0,!0);let f=Ha(t,125);if(o&&typeof(o[s]=f)==="object")r.add(f);if(fn(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 s$(t){let e=t.p++,n=[],r;while(t.p<t.s.length){if(fn(t),(r=t.s.charCodeAt(t.p))===93)return t.p++,n;if(n.push(Ha(t,93)),fn(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
186
  * Copyright (c) Squirrel Chat et al., All rights reserved.
166
187
  * SPDX-License-Identifier: BSD-3-Clause
167
188
  *
@@ -187,7 +208,7 @@ ${i}`,e);this.line=n,this.column=r,this.codeblock=i}static x(t,e,n){throw new D(
187
208
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
188
209
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
189
210
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
190
- */function Y0(t,e,n,r,i){let s=n,o=r,a,c=!1,u;for(let f=0;f<e.length;f++){if(f){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 l=s.length-1;s=s[l],o=o[l].c}}if(a=e[f],(c=Object.hasOwn(s,a))&&o[a]?.t===0&&o[a]?.d)return null;if(!c){let l=a==="__proto__";if(t.uk&&(l||a==="constructor"))return!1;if(l)Object.defineProperty(s,a,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(o,a,{enumerable:!0,configurable:!0,writable:!0});o[a]={t:f<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 V0(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 ji(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++;cn(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 f=gu(n,93);if(u){if(t.charCodeAt(n.p)!==93)D.x("expected end of table array declaration",n);n.p++}let l=Y0(n,f,r,i,u?2:1);if(!l)V0(n,l,s),o=!0;else c=l[2],a=l[1]}else{s=n.p;let u=gu(n),f=Y0(n,u,a,c,0);if(!f&&!o)V0(n,f,s);cn(n,!0,!0);let l=Pa(n,void 0);if(f&&!o)f[1][f[0]]=l}if(cn(n,!0),n.p<t.length&&(s=t.charCodeAt(n.p))!==10&&(s!==13||t.charCodeAt(n.p+1)!==10))D.x("each key-value declaration must be followed by an end-of-line",n);cn(n)}return r}/*!
211
+ */function o$(t,e,n,r,i){let s=n,o=r,a,c=!1,u;for(let f=0;f<e.length;f++){if(f){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 l=s.length-1;s=s[l],o=o[l].c}}if(a=e[f],(c=Object.hasOwn(s,a))&&o[a]?.t===0&&o[a]?.d)return null;if(!c){let l=a==="__proto__";if(t.uk&&(l||a==="constructor"))return!1;if(l)Object.defineProperty(s,a,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(o,a,{enumerable:!0,configurable:!0,writable:!0});o[a]={t:f<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 a$(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 _i(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++;fn(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 f=Eu(n,93);if(u){if(t.charCodeAt(n.p)!==93)D.x("expected end of table array declaration",n);n.p++}let l=o$(n,f,r,i,u?2:1);if(!l)a$(n,l,s),o=!0;else c=l[2],a=l[1]}else{s=n.p;let u=Eu(n),f=o$(n,u,a,c,0);if(!f&&!o)a$(n,f,s);fn(n,!0,!0);let l=Ha(n,void 0);if(f&&!o)f[1][f[0]]=l}if(fn(n,!0),n.p<t.length&&(s=t.charCodeAt(n.p))!==10&&(s!==13||t.charCodeAt(n.p+1)!==10))D.x("each key-value declaration must be followed by an end-of-line",n);fn(n)}return r}/*!
191
212
  * Copyright (c) Squirrel Chat et al., All rights reserved.
192
213
  * SPDX-License-Identifier: BSD-3-Clause
193
214
  *
@@ -213,7 +234,7 @@ ${i}`,e);this.line=n,this.column=r,this.codeblock=i}static x(t,e,n){throw new D(
213
234
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
214
235
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
215
236
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
216
- */var sB=!!"".isWellFormed;/*!
237
+ */var RG=!!"".isWellFormed;/*!
217
238
  * Copyright (c) Squirrel Chat et al., All rights reserved.
218
239
  * SPDX-License-Identifier: BSD-3-Clause
219
240
  *
@@ -239,181 +260,181 @@ ${i}`,e);this.line=n,this.column=r,this.codeblock=i}static x(t,e,n){throw new D(
239
260
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
240
261
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
241
262
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
242
- */var Dt=["top-left","top-center","top-right","center-left","center","center-right","bottom-left","bottom-center","bottom-right"],ot="ttheme-marketplace.toml",JA=1e6,Q0=3,t$=8,Dd="[a-z0-9]+(?:-[a-z0-9]+)*",YA=new RegExp(`^(?:(${Dd})@(${Dd})/)?(${Dd})$`),e$=["background","foreground","cursor","selection"];function nt(t,e){throw Error(`${t}: ${e}`)}function _i(t,e,n){if(typeof n!=="string"||!ge(n))nt(t,`${e} must be "#rrggbb" (lowercase), got ${JSON.stringify(n)}`);return n}function $u(t,e,n){if(typeof n!=="string"||n.length===0)nt(t,`${e} must be a non-empty string`);return n}function le(t){return t.replace("@","--").replace("/","--")}function j(t){return`ttheme-${le(t)}`}function et(t){let e=t.indexOf("/");return e<0?void 0:t.slice(0,e)}function te(t){return t.slice(t.indexOf("/")+1)}function ee(t){let e=YA.exec(t);if(!e)return"takes lowercase letters, digits and single hyphens, as <palette> or <owner>@<marketplace>/<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 Ra(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 wu(t,e,n){let r=$u(t,e,n),i=Ra(r);if(i)nt(t,`${e} ${JSON.stringify(r)} ${i}`);return r}function Yd(t,e,n){let r=$u(t,e,n),i=ee(r);if(i)nt(t,`${e} "${r}" ${i}`);return r}function Zs(t){return t&&typeof t==="object"?t:{}}function VA(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)nt(t,"ghostty.icon_screen must not be empty");return r.map((i,s)=>_i(t,`ghostty.icon_screen[${s}]`,i))}function ZA(t,e,n){let r=Zs(e);return{iconGhost:r.icon_ghost===void 0?n.cursor:_i(t,"ghostty.icon_ghost",r.icon_ghost),iconScreen:VA(t,r.icon_screen,n)}}function XA(t){return new Map([...e$.map((e)=>[e,t[e]]),...t.ansi.map((e,n)=>[`ansi${n}`,e])])}function QA(t,e,n){if(!Array.isArray(e)||e.length!==Q0)nt(t,`meta.signature must name exactly ${Q0} palette slots`);let r=XA(n),i=[],s=[];for(let[o,a]of e.entries()){let c=`meta.signature[${o}]`,u=$u(t,c,a),f=r.get(u);if(f===void 0)nt(t,`${c} ${JSON.stringify(a)} is not a palette slot — use ${e$.join(", ")} or ansi0-ansi15`);i.push(u),s.push(f)}if(new Set(s).size!==s.length)nt(t,"meta.signature slots must resolve to three different colors");return{names:i,colors:s}}function tN(t,e,n,r=!1){if(e===void 0)return;if(!n)nt(t,"meta.booru_sites renames meta.booru per site, so it needs meta.booru");if(!e||typeof e!=="object"||Array.isArray(e))nt(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=Z.find((u)=>u.key===s);if(!a){if(r)continue;nt(t,`meta.booru_sites.${s} is not a find site — use ${Z.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)))nt(t,`meta.booru_sites.${s} must be one tag or a list of tags, got ${JSON.stringify(o)}`);if(c.length>1&&!a.ors)nt(t,`meta.booru_sites.${s} takes one tag — ${a.name} does not OR tags`);if(c.length>a.tagBudget)nt(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 eN(t,e,n){if(e===void 0)return;if(!Array.isArray(e)||e.length===0||e.length>t$)nt(t,`[[picture]] holds 1 to ${t$} pictures`);let r=e.flatMap((i,s)=>{let o=Zs(i),a=`picture[${s}]`,c=Z.find((h)=>h.key===o.site);if(!c){if(n)return[];nt(t,`${a}.site must be one of ${Z.map((h)=>h.key).join(", ")}`)}if(typeof o.id!=="number"||!Number.isSafeInteger(o.id)||o.id<=0)nt(t,`${a}.id must be the post's number on ${c.name}`);let{size:u,position:f,opacity:l}=o;if(u!==void 0&&u!=="fill"&&!(Number.isInteger(u)&&Number(u)>=20&&Number(u)<=999))nt(t,`${a}.size must be "fill" or a percentage from 20 to 999`);let d=f===void 0||Dt.includes(f);if(!d&&!n)nt(t,`${a}.position must be one of ${Dt.join(", ")}`);if(l!==void 0&&!(typeof l==="number"&&l>=0&&l<=1))nt(t,`${a}.opacity must be a number from 0 to 1`);return[{site:c.key,id:o.id,...u!==void 0?{size:u}:{},...f!==void 0&&d?{position:f}:{},...l!==void 0?{opacity:l}:{}}]});return r.length>0?r:void 0}function Vd(t,e){try{return ji(e)}catch(n){nt(t,`is not valid TOML — ${(n instanceof Error?n.message:String(n)).split(`
243
- `)[0]}`)}}function Zd(t,e){if(e===void 0)return[];if(!Array.isArray(e))nt(t,"catalog must be [[catalog]] tables");let n=e.map((r,i)=>{let s=Zs(r);return{name:wu(t,`catalog[${i}].name`,s.name),...s.native===void 0?{}:{native:wu(t,`catalog[${i}].native`,s.native)},...s.lead===void 0?{}:{lead:Yd(t,`catalog[${i}].lead`,s.lead)}}});if(new Set(n.map((r)=>r.name)).size!==n.length)nt(t,"catalog.name must be unique");return n}function nN(t,e){if(!Array.isArray(e)||e.length===0)nt(t,'meta.native_names must be a list of names, like ["後藤ひとり"]');return e.map((n,r)=>{let i=wu(t,`meta.native_names[${r}]`,n);if(i.includes("|"))nt(t,`meta.native_names[${r}] ${JSON.stringify(i)} contains |`);return i})}var Jd={"":["$schema","meta","colors","contrast","ghostty","picture"],meta:["name","base","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 n$(t,e){let n=Vd(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,Jd[""]),...["meta","colors","contrast","ghostty"].flatMap((i)=>r(i,n[i],Jd[i])),...(Array.isArray(n.picture)?n.picture:[]).flatMap((i,s)=>r(`picture[${s}]`,i,Jd.picture))]}function Xd(t,e,n){let r=Vd(t,e),i=Zs(r.meta),s=Zs(r.colors),o=Zs(r.contrast),a=s.ansi;if(!Array.isArray(a)||a.length!==16)nt(t,`colors.ansi must hold exactly 16 colors, got ${Array.isArray(a)?a.length:typeof a}`);let c=Yd(t,"meta.name",i.name);if(c!==n.name)nt(t,`meta.name "${c}" does not match its file — it lives at ${n.name}`);let u=n.open===!0;for(let P of["order","role"])if(u&&i[P]!==void 0)nt(t,`meta.${P} is for the official palettes — a marketplace palette follows its base`);let f=i.role;if(f!==void 0&&f!=="default")nt(t,`meta.role must be "default", got ${JSON.stringify(f)}`);let l=i.base===void 0?void 0:Yd(t,"meta.base",i.base);if(l!==void 0&&!u)nt(t,"meta.base is for marketplace palettes");let d=l===void 0?void 0:n.bases?.get(l),h=n.catalog===void 0?void 0:n.catalogs.get(n.catalog);if(!u&&!h)nt(t,n.catalog===void 0?"an official palette lives in a catalog folder, palettes/<catalog>/<palette>.toml":`its folder "${n.catalog}" has no [[catalog]] table in ${ot}`);let m=_i(t,"colors.background",s.background),g=_i(t,"colors.foreground",s.foreground),b=_i(t,"colors.cursor",s.cursor),w=_i(t,"colors.selection_background",s.selection_background),k=a.map((P,_)=>_i(t,`colors.ansi[${_}]`,P)),v=QA(t,i.signature,{background:m,foreground:g,cursor:b,selection:w,ansi:k}),S=i.booru===void 0?void 0:$u(t,"meta.booru",i.booru);if(S!==void 0&&/[\s\p{Cc}]/u.test(S))nt(t,`meta.booru must be a single booru tag, got ${JSON.stringify(S)}`);let x=tN(t,i.booru_sites,S,n.foreign===!0),M=i.native_names===void 0?void 0:nN(t,i.native_names),N=Array.isArray(o.waive)?o.waive.map(String):[];if(N.length>0&&typeof o.reason!=="string")nt(t,"contrast.waive needs a contrast.reason explaining why");let C=eN(t,r.picture,n.foreign===!0);return{name:c,...l?{base:l}:{},...n.catalog===void 0?{}:{catalog:n.catalog},native:h?.native,...M?{nativeNames:M}:{},lead:h?.lead===c,order:u?d?.order??JA:Number(i.order),role:f,ansiSource:u&&i.ansi_source===void 0?l??"original":wu(t,"meta.ansi_source",i.ansi_source),...S?{booru:S}:{},...x?{booruSites:x}:{},background:m,foreground:g,cursor:b,selectionBackground:w,ansi:k,signature:v.colors,signatureSlots:v.names,ghostty:ZA(t,r.ghostty,{background:m,cursor:b,selectionBackground:w}),waive:N,waiveReason:typeof o.reason==="string"?o.reason:void 0,...C?{pictures:C}:{}}}function r$(t){let e=Zd(ot,Vd(ot,X0(bu(t,ot),"utf8")).catalog);if(e.length===0)nt(ot,"needs at least one [[catalog]] table");let n=new Map(e.map((a)=>[a.name,a])),r=bu(t,"palettes"),i=Z0(r,{withFileTypes:!0}).filter((a)=>!a.name.startsWith(".")).flatMap((a)=>{if(!a.isDirectory())nt(`palettes/${a.name}`,"an official palette lives in a catalog folder, palettes/<catalog>/<palette>.toml");return Z0(bu(r,a.name)).filter((c)=>c.endsWith(".toml")).map((c)=>Xd(`palettes/${a.name}/${c}`,X0(bu(r,a.name,c),"utf8"),{name:DA(c,".toml"),catalog:a.name,catalogs:n}))}).sort((a,c)=>a.order-c.order);if(new Set(i.map((a)=>a.order)).size!==i.length)throw Error("themes: meta.order must be unique across all themes");for(let a of e){let c=i.filter((u)=>u.catalog===a.name);if(c.length===0)nt(ot,`catalog "${a.name}" has no palettes`);if(!c.some((u)=>u.name===a.lead))nt(ot,`catalog "${a.name}" needs a lead, one of its palettes`)}if([...new Set(i.map((a)=>a.catalog))].join(`
263
+ */var Jt=["top-left","top-center","top-right","center-left","center","center-right","bottom-left","bottom-center","bottom-right"],ot="ttheme-marketplace.toml",gN=1e6,l$=3,f$=8,ih="[a-z0-9]+(?:-[a-z0-9]+)*",bN=new RegExp(`^(?:(${ih})@(${ih})/)?(${ih})$`),d$=["background","foreground","cursor","selection"];function nt(t,e){throw Error(`${t}: ${e}`)}function Bi(t,e,n){if(typeof n!=="string"||!$e(n))nt(t,`${e} must be "#rrggbb" (lowercase), got ${JSON.stringify(n)}`);return n}function Ou(t,e,n){if(typeof n!=="string"||n.length===0)nt(t,`${e} must be a non-empty string`);return n}function he(t){return t.replace("@","--").replace("/","--")}function _(t){return`ttheme-${he(t)}`}function et(t){let e=t.indexOf("/");return e<0?void 0:t.slice(0,e)}function ne(t){return t.slice(t.indexOf("/")+1)}function re(t){let e=bN.exec(t);if(!e)return"takes lowercase letters, digits and single hyphens, as <palette> or <owner>@<marketplace>/<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 Fa(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 xu(t,e,n){let r=Ou(t,e,n),i=Fa(r);if(i)nt(t,`${e} ${JSON.stringify(r)} ${i}`);return r}function oh(t,e,n){let r=Ou(t,e,n),i=re(r);if(i)nt(t,`${e} "${r}" ${i}`);return r}function no(t){return t&&typeof t==="object"?t:{}}function wN(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)nt(t,"ghostty.icon_screen must not be empty");return r.map((i,s)=>Bi(t,`ghostty.icon_screen[${s}]`,i))}function $N(t,e,n){let r=no(e);return{iconGhost:r.icon_ghost===void 0?n.cursor:Bi(t,"ghostty.icon_ghost",r.icon_ghost),iconScreen:wN(t,r.icon_screen,n)}}function kN(t){return new Map([...d$.map((e)=>[e,t[e]]),...t.ansi.map((e,n)=>[`ansi${n}`,e])])}function yN(t,e,n){if(!Array.isArray(e)||e.length!==l$)nt(t,`meta.signature must name exactly ${l$} palette slots`);let r=kN(n),i=[],s=[];for(let[o,a]of e.entries()){let c=`meta.signature[${o}]`,u=Ou(t,c,a),f=r.get(u);if(f===void 0)nt(t,`${c} ${JSON.stringify(a)} is not a palette slot — use ${d$.join(", ")} or ansi0-ansi15`);i.push(u),s.push(f)}if(new Set(s).size!==s.length)nt(t,"meta.signature slots must resolve to three different colors");return{names:i,colors:s}}function vN(t,e,n,r=!1){if(e===void 0)return;if(!n)nt(t,"meta.booru_sites renames meta.booru per site, so it needs meta.booru");if(!e||typeof e!=="object"||Array.isArray(e))nt(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=Z.find((u)=>u.key===s);if(!a){if(r)continue;nt(t,`meta.booru_sites.${s} is not a find site — use ${Z.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)))nt(t,`meta.booru_sites.${s} must be one tag or a list of tags, got ${JSON.stringify(o)}`);if(c.length>1&&!a.ors)nt(t,`meta.booru_sites.${s} takes one tag — ${a.name} does not OR tags`);if(c.length>a.tagBudget)nt(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 SN(t,e,n){if(e===void 0)return;if(!Array.isArray(e)||e.length===0||e.length>f$)nt(t,`[[picture]] holds 1 to ${f$} pictures`);let r=e.flatMap((i,s)=>{let o=no(i),a=`picture[${s}]`,c=Z.find((h)=>h.key===o.site);if(!c){if(n)return[];nt(t,`${a}.site must be one of ${Z.map((h)=>h.key).join(", ")}`)}if(typeof o.id!=="number"||!Number.isSafeInteger(o.id)||o.id<=0)nt(t,`${a}.id must be the post's number on ${c.name}`);let{size:u,position:f,opacity:l}=o;if(u!==void 0&&u!=="fill"&&!(Number.isInteger(u)&&Number(u)>=20&&Number(u)<=999))nt(t,`${a}.size must be "fill" or a percentage from 20 to 999`);let d=f===void 0||Jt.includes(f);if(!d&&!n)nt(t,`${a}.position must be one of ${Jt.join(", ")}`);if(l!==void 0&&!(typeof l==="number"&&l>=0&&l<=1))nt(t,`${a}.opacity must be a number from 0 to 1`);return[{site:c.key,id:o.id,...u!==void 0?{size:u}:{},...f!==void 0&&d?{position:f}:{},...l!==void 0?{opacity:l}:{}}]});return r.length>0?r:void 0}function ah(t,e){try{return _i(e)}catch(n){nt(t,`is not valid TOML — ${(n instanceof Error?n.message:String(n)).split(`
264
+ `)[0]}`)}}function ch(t,e){if(e===void 0)return[];if(!Array.isArray(e))nt(t,"catalog must be [[catalog]] tables");let n=e.map((r,i)=>{let s=no(r);return{name:xu(t,`catalog[${i}].name`,s.name),...s.native===void 0?{}:{native:xu(t,`catalog[${i}].native`,s.native)},...s.lead===void 0?{}:{lead:oh(t,`catalog[${i}].lead`,s.lead)}}});if(new Set(n.map((r)=>r.name)).size!==n.length)nt(t,"catalog.name must be unique");return n}function EN(t,e){if(!Array.isArray(e)||e.length===0)nt(t,'meta.native_names must be a list of names, like ["後藤ひとり"]');return e.map((n,r)=>{let i=xu(t,`meta.native_names[${r}]`,n);if(i.includes("|"))nt(t,`meta.native_names[${r}] ${JSON.stringify(i)} contains |`);return i})}var sh={"":["$schema","meta","colors","contrast","ghostty","picture"],meta:["name","base","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 h$(t,e){let n=ah(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,sh[""]),...["meta","colors","contrast","ghostty"].flatMap((i)=>r(i,n[i],sh[i])),...(Array.isArray(n.picture)?n.picture:[]).flatMap((i,s)=>r(`picture[${s}]`,i,sh.picture))]}function uh(t,e,n){let r=ah(t,e),i=no(r.meta),s=no(r.colors),o=no(r.contrast),a=s.ansi;if(!Array.isArray(a)||a.length!==16)nt(t,`colors.ansi must hold exactly 16 colors, got ${Array.isArray(a)?a.length:typeof a}`);let c=oh(t,"meta.name",i.name);if(c!==n.name)nt(t,`meta.name "${c}" does not match its file — it lives at ${n.name}`);let u=n.open===!0;for(let I of["order","role"])if(u&&i[I]!==void 0)nt(t,`meta.${I} is for the official palettes — a marketplace palette follows its base`);let f=i.role;if(f!==void 0&&f!=="default")nt(t,`meta.role must be "default", got ${JSON.stringify(f)}`);let l=i.base===void 0?void 0:oh(t,"meta.base",i.base);if(l!==void 0&&!u)nt(t,"meta.base is for marketplace palettes");let d=l===void 0?void 0:n.bases?.get(l),h=n.catalog===void 0?void 0:n.catalogs.get(n.catalog);if(!u&&!h)nt(t,n.catalog===void 0?"an official palette lives in a catalog folder, palettes/<catalog>/<palette>.toml":`its folder "${n.catalog}" has no [[catalog]] table in ${ot}`);let m=Bi(t,"colors.background",s.background),p=Bi(t,"colors.foreground",s.foreground),b=Bi(t,"colors.cursor",s.cursor),$=Bi(t,"colors.selection_background",s.selection_background),k=a.map((I,j)=>Bi(t,`colors.ansi[${j}]`,I)),v=yN(t,i.signature,{background:m,foreground:p,cursor:b,selection:$,ansi:k}),S=i.booru===void 0?void 0:Ou(t,"meta.booru",i.booru);if(S!==void 0&&/[\s\p{Cc}]/u.test(S))nt(t,`meta.booru must be a single booru tag, got ${JSON.stringify(S)}`);let x=vN(t,i.booru_sites,S,n.foreign===!0),M=i.native_names===void 0?void 0:EN(t,i.native_names),N=Array.isArray(o.waive)?o.waive.map(String):[];if(N.length>0&&typeof o.reason!=="string")nt(t,"contrast.waive needs a contrast.reason explaining why");let C=SN(t,r.picture,n.foreign===!0);return{name:c,...l?{base:l}:{},...n.catalog===void 0?{}:{catalog:n.catalog},native:h?.native,...M?{nativeNames:M}:{},lead:h?.lead===c,order:u?d?.order??gN:Number(i.order),role:f,ansiSource:u&&i.ansi_source===void 0?l??"original":xu(t,"meta.ansi_source",i.ansi_source),...S?{booru:S}:{},...x?{booruSites:x}:{},background:m,foreground:p,cursor:b,selectionBackground:$,ansi:k,signature:v.colors,signatureSlots:v.names,ghostty:$N(t,r.ghostty,{background:m,cursor:b,selectionBackground:$}),waive:N,waiveReason:typeof o.reason==="string"?o.reason:void 0,...C?{pictures:C}:{}}}function m$(t){let e=ch(ot,ah(ot,u$(Mu(t,ot),"utf8")).catalog);if(e.length===0)nt(ot,"needs at least one [[catalog]] table");let n=new Map(e.map((a)=>[a.name,a])),r=Mu(t,"palettes"),i=c$(r,{withFileTypes:!0}).filter((a)=>!a.name.startsWith(".")).flatMap((a)=>{if(!a.isDirectory())nt(`palettes/${a.name}`,"an official palette lives in a catalog folder, palettes/<catalog>/<palette>.toml");return c$(Mu(r,a.name)).filter((c)=>c.endsWith(".toml")).map((c)=>uh(`palettes/${a.name}/${c}`,u$(Mu(r,a.name,c),"utf8"),{name:pN(c,".toml"),catalog:a.name,catalogs:n}))}).sort((a,c)=>a.order-c.order);if(new Set(i.map((a)=>a.order)).size!==i.length)throw Error("themes: meta.order must be unique across all themes");let o=Map.groupBy(i,(a)=>a.catalog);for(let a of e){let c=o.get(a.name);if(!c)nt(ot,`catalog "${a.name}" has no palettes`);if(!c.some((u)=>u.name===a.lead))nt(ot,`catalog "${a.name}" needs a lead, one of its palettes`)}if([...o.keys()].join(`
244
265
  `)!==e.map((a)=>a.name).join(`
245
- `))nt(ot,"the [[catalog]] tables must follow the order meta.order gives their palettes");return i}function i$(t){return t.filter((e)=>e.role===void 0)}function ne(t){return[et(t.name),t.catalog].filter((e)=>e!==void 0).join(" / ")}function Xs(t){return et(t.name)??t.catalog??""}function Gi(t){let e=(r,i)=>r<i?-1:r>i?1:0,n=(r)=>et(r.name)?r.name:r.base??r.name;return[...t].sort((r,i)=>Number(et(r.name)!==void 0)-Number(et(i.name)!==void 0)||e(Xs(r).toLowerCase(),Xs(i).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 Ia={width:2560,height:1550},cN=1,uN=2560,lN=0.1,p$=0.99,fN=2,Bi={tall:1.15,reach:0.4,widest:0.95,headroom:0.04,margin:0.03,stands:12},dN=Mt(Tt("#19161e","#9b86c8",0.2)),hN="shelf",yu="originals",mN="images.json",th=1;function pN(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 s$(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 g$(t,e){let n=(o)=>qb({name:t.name,background:Tt(t.background,e,o),foreground:t.foreground,ansi:t.ansi,waive:t.waived??[]}).map((a)=>a.rule),r=new Set(n(0)),i=s$((o)=>n(o).every((a)=>r.has(a))),s=s$((o)=>Mt(Tt(t.background,e,o))<=dN);return{cap:i,matched:s,opacity:Math.floor(Math.min(i,s)*100)/100}}function o$(t,e){let n=pN(t,e),{cap:r,matched:i,opacity:s}=g$(t,n),o=ct(t.background),a=Math.hypot(...ct(n).map((c,u)=>(c-(o[u]??0))*s));return{slot:e,color:n,cap:r,matched:i,opacity:s,reach:a}}function b$(t,e){return g$(t,e).opacity}function In(t,e){let n=o$(t,"cursor");if(n.opacity>=lN)return n;return e.filter((r)=>r!=="cursor"&&r!=="background").map((r)=>o$(t,r)).reduce((r,i)=>i.reach>r.reach?i:r,n)}function gN(t){return t0(t)??{x:0,y:0,w:t.width,h:t.height}}function oh(t,e){if(t<=0||e<=0)return Ia;let n=Math.min(1,Ia.width/Math.max(t,e));return{width:Math.round(t*n),height:Math.round(e*n)}}function w$(t,e,n,r){if(r<Bi.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(Bi.tall*n,Bi.reach*e*t.h/t.w),s=i*t.w/t.h;if(s>Bi.widest*e)s=Bi.widest*e,i=s*t.h/t.w;let o=Bi.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-Bi.margin)-s,y:o,w:s,h:i*a},focus:Math.min(1,(n/2-o)/i)}}function bN(t,e){return 0.299*(t[e]??0)+0.587*(t[e+1]??0)+0.114*(t[e+2]??0)}function wN(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(bN(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*p$)return Math.min(fN,Math.max(1,255/Math.max(1,o)));return 1}var Qd=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 $N(t,e,n){return`#${[t,e,n].map((r)=>Math.round(r).toString(16).padStart(2,"0")).join("")}`}function kN(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,f=t.data[c+1]??0,l=t.data[c+2]??0,d=Math.round(255*Math.sqrt(0.2126*(Qd[u]??0)+0.7152*(Qd[f]??0)+0.0722*(Qd[l]??0)));n[d]=(n[d]??0)+1,r[d*3]=(r[d*3]??0)+u,r[d*3+1]=(r[d*3+1]??0)+f,r[d*3+2]=(r[d*3+2]??0)+l,s++}}let o=0;for(let a=0;a<256&&s>0;a++)if(o+=n[a]??0,o>=s*p$){let c=Math.max(1,n[a]??1);return $N((r[a*3]??0)/c,(r[a*3+1]??0)/c,(r[a*3+2]??0)/c)}return"#ffffff"}function yN(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 $$(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 ku(t,e,n,r){let i=new Float32Array(n*r),s=$$(e,n,r);if(s){let o=i0(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 ah(t,e,n,r){let i=new Uint8Array(n*r*4),s=$$(e,n,r);if(s){let o=s.x1-s.x0,a=ma(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 eh(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)=>pa(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 ch(t){let e=gN(t),n,r;return{box:e,clear:nr(t,e),get ink(){return n??=yN(t,wN(t,e)),n},image:t,get peak(){return r??=kN(t,e),r}}}function k$(t,e,n,r,i){let s=ch(t),{box:o,clear:a,ink:c}=s,u=w$(o,e,n,a),f=Math.min(1,uN/Math.max(o.w,o.h)),l={x:0,y:0,w:Math.round(o.w*f),h:Math.round(o.h*f)},d=r*l.w*u.crop.w/(o.w*u.at.w);if(i==="original")return{coloring:i,figure:eh(ma(t,o,l.w,l.h),d),fill:eh(ah(t,u,e,n),r),focus:u.focus,peak:s.peak};let h=ku(c,{crop:o,at:l,focus:u.focus},l.w,l.h),m=ku(c,u,e,n);return{coloring:i,figure:ga(pa(h,d)),fill:ga(pa(m,r)),focus:u.focus}}function vN(t,e,n,r){let i=ct(e),s=ct(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 SN(t,e,n){let r=ct(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 y$(t,e,n,r,i,s,o,a="tone"){let{box:c,clear:u,ink:f}=t,l=w$(c,r,i,u),d=Math.round(100*l.at.w/l.crop.w/Math.min(r/c.w,i/c.h)),h=o?.size??"fill",m=h==="fill"?l:{crop:c,at:io(c.w,c.h,r,i,h,o?.at??5,!1,h>100?Math.round(l.focus*100):-1),focus:l.focus},g=a==="original"?b$(e,t.peak):n.opacity,b=o?.opacity??g;return{image:a==="original"?SN(eh(ah(t.image,m,r,i),s),e.background,b):vN(ga(pa(ku(f,m,r,i),s)),e.background,n.color,b),fill:d,opacity:g}}function X(t){return V(t,"ttheme","backgrounds")}function nh(t){return V(t,mN)}function Ui(t){try{return to(t,"utf8")}catch{return}}function Wr(t){try{return sN(t)}catch{return[]}}function Ht(t){let e=Ui(nh(t));if(e===void 0)return MN(t);let n=JSON.parse(e);if(n.version!==th)throw Error(`${nh(t)} is version ${n.version} — this ttheme reads version ${th}`);return n}function De(t){return t.coloring??"tone"}function uh(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 eo(t){return{hue:{color:t.backdrop.color,opacity:t.backdrop.opacity},colors:uh(t)}}function no(t){return t.tone===void 0&&De(t)==="tone"}function v$(t){return t.replace(/[\s,\p{Cc}]+/gu,"_")}function a$(t){return(t.artist??[]).map(v$).join(",")}function EN(t){let e=Wd(t),n=U0(t)?.replace(/\p{Cc}+/gu,"");return[...n?[`# credit ${t.key} ${n}`]:[],...e?[`# source ${t.key} ${e.label} ${e.url}`]:[],...(t.artist??[]).flatMap((r)=>{let i=xa(t.profiles?.[r]);return i.length>0?[`# profile ${t.key} ${v$(r)} ${i.map((s)=>`${s.kind} ${s.url}`).join(" ")}`]:[]})]}function S$(t,e){let n=e.pictures.findIndex((i)=>i.key===e.active),r=e.pictures[n];return[...r.artist?.length?[`# by ${a$(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?a$(i):"-"}`,...i.from?[i.from]:[]].join(" ")),...e.pictures.filter((i)=>De(i)==="original").map((i)=>`# colors ${i.key} original`),...e.pictures.flatMap(EN),`background-image = ${V(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(`
246
- `)}function E$(t){let e=X(t);for(let[n,r]of Object.entries(Ht(e).palettes)){let i=V(e,`${le(n)}.conf`),s=S$(e,r);if(Ui(i)!==s)L(i,s)}}function Wi(t,e,n){L(nh(t),`${JSON.stringify(e,null,2)}
247
- `);for(let r of n){let i=e.palettes[r],s=V(t,`${le(r)}.conf`);if(i)L(s,S$(t,i));else Qs(s,{force:!0})}}function M$(t,e){let n=X(t),r=Ht(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)Wi(n,r,i)}function x$(t,e){return Wr(t).filter((n)=>n.startsWith(`${e}.`)||n.startsWith(`${e}@`))}function lh(t,e){for(let n of x$(t,e))Qs(V(t,n),{force:!0})}function O$(t,e){lh(t,e.stem);for(let n of[e.original,e.cut])if(n)Qs(V(t,n),{force:!0})}function c$(t,e,n,r){let i=m$(/^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((f)=>f.startsWith(`${t}-${o}.`));return{key:o,stem:s,fill:i,opacity:Number.isFinite(c)?c:1,...a?{from:a}:{},...u?{original:V(yu,u)}:{}}}function u$(t,e){if(sh(t))h$(t,e)}function MN(t){let e={version:th,palettes:{}};if(!sh(t))return e;let n=Wr(V(t,yu)),r=Wr(t).filter((s)=>s.endsWith(".conf")&&s!=="shown.conf"&&!/\.(tune|off)\.conf$/.test(s)).map((s)=>s.slice(0,-5)),i=V(t,hN);for(let s of new Set([...r,...Wr(i)])){let o=[],a=c$(s,Ui(V(t,`${s}.conf`)),n);if(a)u$(V(t,`${s}.tune.conf`),V(t,`${a.stem}.tune.conf`)),u$(V(t,`${s}.off.conf`),V(t,`${a.stem}.off.conf`)),o.push(a);for(let c of Wr(V(i,s))){let u=V(i,s,c),f=c$(s,Ui(V(u,".conf")),n,c);if(!f)continue;for(let l of Wr(u)){let d=l===".tune.conf"||l===".off.conf"?`${f.stem}${l}`:`${s}${l}`;if(l!==".conf")h$(V(u,l),V(t,d))}Qs(u,{recursive:!0}),o.push(f)}if(Wr(V(i,s)).length===0)Qs(V(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(Wr(i).length===0)Qs(i,{recursive:!0,force:!0});return Wi(t,e,Object.keys(e.palettes)),e}function l$(t,e,n){return e.startsWith("~/")?V(n,e.slice(2)):aN(e)?e:V(t,e)}function He(t,e,n){let r=new Map,i=(a,c)=>{let u=Ui(a);if(u===void 0)return!1;for(let f of u.split(`
248
- `)){let l=/^([a-z-]+)\s*=\s*(.*?)\s*$/.exec(f);if(l?.[1]==="config-file"&&c<4)i(l$(t,l[2].replace(/^\?/,""),n),c+1);else if(l&&/^background-image(?:-fit|-opacity|-position)?$/.test(l[1]))r.set(l[1],l[2])}return!0};if(!i(V(t,`${le(e)}.conf`),0))return;let s=r.get("background-image")??"";if(s==="")return;let o=Number(r.get("background-image-opacity")??1);return{image:l$(t,s,n),opacity:Number.isFinite(o)?o:1,cover:r.get("background-image-fit")==="cover",position:r.get("background-image-position")??"center"}}function fe(t){return`${t.site}_${t.id}`}function vu(t,e,n){let r=X(t),i=Ht(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);O$(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 Wi(r,i,[e]),{key:a.key,left:s.pictures.length}}function P$(t,e,n,r){let i=n.coloring==="original"?qe(n.figure):Ni(n.figure,r),s=n.coloring==="original"?qe(n.fill):Ni(n.fill,r),o=`${le(t)}.${d$("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 R$(t,e,n,r){return n==="original"&&r?{coloring:"original",opacity:b$(t,r),peak:r}:{coloring:"tone",opacity:e.opacity,tone:e.color}}function rh(t,e){return V(yu,`${le(t)}-${e}`)}function fh(t,e){return e.map(([n,r])=>{let i=V(t,n);return L(i,r),i})}function Su(t,e,n,r,i,s,o,a="tone"){let c=X(t),u=e.name,f=fe(i),l=Ht(c),d=l.palettes[u]??{active:f,pictures:[]},h=oh(s.width,s.height),m=k$(r,h.width,h.height,o,a),g=P$(u,f,m,n.color),b=rh(u,f),w={key:f,stem:g.stem,fill:g.fill,...R$(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.profiles&&Object.keys(i.profiles).length>0?{profiles:i.profiles}:{},...i.source?{source:i.source}:{},original:`${b}.${i.ext}`,...i.cut?{cut:`${b}.cut.png`}:{}},k=d.pictures.find((S)=>S.key===f);if(k)O$(c,k);iN(V(c,yu),{recursive:!0});let v=fh(c,[...g.files,[w.original,i.bytes],...w.cut?[[w.cut,Nd(Ai(r))]]:[]]);return d.pictures=k?d.pictures.map((S)=>S===k?w:S):[...d.pictures,w],d.active=f,l.palettes[u]=d,Wi(c,l,[u]),[...v,V(c,`${le(u)}.conf`)]}function ro(t,e,n){let r=X(t),i=Ht(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,Wi(r,i,[e]);return{at:o+1,of:s.pictures.length}}function be(t,e){let n=Ht(X(t)).palettes[e];if(!n)return[];return[...n.pictures.filter((i)=>i.key===n.active),...n.pictures.filter((i)=>i.key!==n.active)]}var ih="top-right";function io(t,e,n,r,i,s,o,a=-1){let c=Math.trunc,u=(s-1)%3,f=c((s-1)/3),l=n*e>=r*t!==!o,d=l?c(i*n/100):c(i*r*t/(100*e)),h=l?c(i*n*e/(100*t)):c(i*r/100),m=c(u*(n-d)/2),g=c(f*(r-h)/2);if(a>=0){if(d>n)m=c((n-d)/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:d,h}}function dh(t,e){let n=Ui(V(t,`${e.stem}.tune.conf`));if(n===void 0)return{};let r=(u)=>new RegExp(`^${u}\\s*=\\s*(.*?)\\s*$`,"m").exec(n)?.[1]??"",i=m$(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!==ih?{position:a}:{},...Number.isFinite(c)&&c!==e.opacity?{opacity:c}:{}}}function Aa(t,e,n,r,i){let s=n.size??"fill",o=n.position??ih,a=n.opacity??e.opacity;if(s==="fill"&&o===ih&&a===e.opacity)return;let c=Dt.indexOf(o)+1,u=V(t,`${e.stem}.png`),f=V(t,e.fill),l=!0,d=typeof s==="number"&&(s>100||!r&&o!=="center");if(s===100&&!d)f=u,l=!1;else if(typeof s==="number"){if(no(e))throw Error(`${e.stem} was drawn before pictures kept their tone — init draws it again`);let m=Wt(new Uint8Array(to(u))),{width:g,height:b}=d?Ia:m,w=d?Number(/@fill-(\d+)\.png$/.exec(e.fill)?.[1]??50):-1,k=io(m.width,m.height,g,b,s,c,!1,w);f=V(t,`${e.stem}@${s}-${o}${d?`-${g}x${b}`:""}.png`);let S={crop:{x:0,y:0,w:m.width,h:m.height},at:k,focus:w};L(f,e.tone?Ni(ga(ku(Ai(m),S,g,b)),e.tone):qe(ah(m,S,g,b))),l=d}let h=V(t,`${e.stem}.tune.conf`);return L(h,[`background-image = ${f.startsWith(`${i}/`)?`~${f.slice(i.length)}`:f}`,`background-image-fit = ${l?"cover":"contain"}`,`background-image-position = ${o}`,`background-image-opacity = ${a}`,""].join(`
249
- `)),h}function I$(t){let e=new Map;for(let[n,r]of Object.entries(Ht(X(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 A$(t){try{let e=Mn(new Uint8Array(to(t)));return e?{width:e.width,height:e.height}:void 0}catch{return}}function N$(t,e,n,r,i,s,o){let a=[n.original,n.cut].map((c)=>{if(!c)return"";try{let{size:u,mtimeMs:f}=oN(V(t,c));return`${c}:${u}:${f}`}catch{return}});if(!n.original||a.includes(void 0))return;return W0([cN,le(e),n.key,...a,r.width,r.height,i,s,s==="tone"?o:""])}function xN(t,e,n){if(!n.window||n.blur===void 0)return;let r=N$(t,e,n,n.window,n.blur,De(n),n.tone??"");if(!r||K0(r))return;try{Kd(r,{stem:n.stem,fill:n.fill,...n.peak?{peak:n.peak}:{},figure:to(V(t,`${n.stem}.png`)),picture:to(V(t,n.fill))})}catch{}}function T$(t,e,n,r,i,s,o,a,c){let u=c?void 0:N$(t,e,n,r,o,a,s.hue.color),f=u?z0(u):void 0;if(f)return{made:{stem:f.stem,fill:f.fill,files:[[`${f.stem}.png`,f.figure],[f.fill,f.picture]]},peak:f.peak,image:void 0};let l=i();if(!l)return null;let d=k$(l,r.width,r.height,o,a),h=P$(e,n.key,d,s.hue.color),m=d.coloring==="original"?d.peak:void 0;if(u)Kd(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:l}}function Na(t,e,n,r,i,s,o,a,c,u=De(n)){let f=X(t),l=n.window??A$(V(f,n.fill))??Ia,d=T$(f,e,n,l,r,i,s,u,c);if(!d)return null;let{made:h,peak:m,image:g}=d,b={...n,stem:h.stem,fill:h.fill,...R$(i.colors,i.hue,u,m),blur:s,window:l,...c?{cut:`${rh(e,n.key)}.cut.png`}:{}};if(u==="original")delete b.tone;else delete b.peak;if(c&&g)L(V(f,`${rh(e,n.key)}.cut.png`),Nd(Ai(g)));if(h.stem===n.stem)return b;if(De(n)!==u)xN(f,e,n);fh(f,h.files);let w=dh(f,n);Aa(f,b,De(n)===u?w:{...w,opacity:void 0},o,a);let k=V(f,`${n.stem}.off.conf`);if(sh(k))rN(k,V(f,`${b.stem}.off.conf`));return b}function H$(t,e,n,r,i,s,o){let a=X(t),c=n.window??A$(V(a,n.fill))??Ia;return T$(a,e,n,c,r,i,s,o,!1)!==null}function hh(t,e){let n=X(t),r=Ht(n),i=new Set,s=[];for(let{name:o,picture:a}of e){let c=r.palettes[o],u=c?.pictures.findIndex((l)=>l.key===a.key)??-1,f=c?.pictures[u];if(!c||!f)continue;if(c.pictures[u]=a,i.add(o),f.stem!==a.stem)s.push(f.stem)}if(i.size===0)return;Wi(n,r,[...i]);for(let o of s)lh(n,o)}function ON(t,e,n,r){let i=x$(t,n.stem).filter((a)=>a.endsWith(".png")).map((a)=>{let c=new Uint8Array(to(V(t,a)));return[a,iu(c,r.color)??Ni(Ai(Wt(c)),r.color)]}),s=(a)=>i.find(([c])=>c===a)?.[1]??new Uint8Array,o=`${le(e)}.${d$("sha1").update(n.key).update(s(`${n.stem}.png`)).update(s(n.fill)).digest("hex").slice(0,8)}`;fh(t,i.map(([a,c])=>[o+a.slice(n.stem.length),c]));for(let a of["tune","off"]){let c=Ui(V(t,`${n.stem}.${a}.conf`));if(c!==void 0)L(V(t,`${o}.${a}.conf`),c.split(n.stem).join(o))}return{...n,stem:o,fill:o+n.fill.slice(n.stem.length),tone:r.color}}function f$(t,e){return De(t)!=="original"&&t.tone!==void 0&&t.tone!==e.hue.color}function L$(t,e){let n=X(t),r=Ht(n),i=[],s=[];for(let[o,a]of Object.entries(r.palettes)){let c=e.get(o);if(!c||!a.pictures.some((u)=>f$(u,c)))continue;a.pictures=a.pictures.map((u)=>{if(!f$(u,c))return u;let f=ON(n,o,u,c.hue);if(f.stem!==u.stem)s.push(u.stem);return f}),i.push(o)}if(i.length>0){Wi(n,r,i);for(let o of s)lh(n,o)}return i}var PN=1;function un(t){let{slot:e,color:n,opacity:r}=In({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}:{},...t.catalog?{catalog:t.catalog}:{},...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:vn(t),...t.waive.length>0?{waived:t.waive}:{},backdrop:{slot:e,color:n,opacity:r},...t.pictures?{pictures:t.pictures}:{}}}function Le(t){return{name:t.name,...t.base?{base:t.base}:{},...t.catalog?{catalog:t.catalog}:{},...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 RN=6,IN=["ansi1","ansi2","ansi4","ansi3","ansi5","ansi6"];function so(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,...IN]){let o=e(s);if(i.length===RN||!o||r.has(n(s))||i.includes(o))continue;r.add(n(s)),i.push(o)}return i}function It(t){return t.filter((e)=>e.default!==!0)}function Eu(){return{schema:PN,version:dt.version,gate:Ie,palettes:[]}}import{existsSync as AN,readFileSync as xu,statSync as F$}from"node:fs";import{homedir as uo}from"node:os";import{join as ao}from"node:path";var NN=["core","kowiki","unlicensed"],TN=["ko","ja","en","zh","other"],_$=["keys","keyAt","ownAt","owners","cards","cardAt","ranks","tags","tagAt","tagCard"],G$="TTNI";function Kr(t=uo()){return ao(process.env.XDG_CACHE_HOME??ao(t,".cache"),"ttheme","aninames")}var HN=/[ァ-ヶ]/g,LN=/[\s\p{P}\p{S}]+/gu;function co(t){return t.normalize("NFKC").toLowerCase().replace(HN,(e)=>String.fromCharCode(e.charCodeAt(0)-96)).replace(LN,"")}function Ki(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 bh(t){return t.length>=2||/[\p{Script=Han}\p{Script=Hangul}\p{Script=Hiragana}]/u.test(t)}function B$(t){let e=Kr(t);return NN.map((n)=>ao(e,`ttheme-${n}.json`)).filter((n)=>AN(n))}var FN=6;function U$(t){return[`format ${FN}`,...t.map((e)=>`${e}:${F$(e).size}:${F$(e).mtimeMs}`)].join("|")}function CN(t){try{return JSON.parse(xu(t,"utf8"))}catch{return{}}}function jN(t){let e=new Map;for(let i of t)for(let[s,o]of Object.entries(CN(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 TN)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 Ta(t,e){let n=new t(e.length);return n.set(e),n}function mh(t){let e=[0];for(let n of t)e.push(e.at(-1)+n.length);return{bytes:Buffer.concat(t),at:Ta(Uint32Array,e)}}function _N(t,e){let n=jN(t),r=new Map,i=(v,S,x)=>{let M=r.get(v),N=S*4+x;if(!M)r.set(v,[N]);else if(M.at(-1)>>>2!==S)M.push(N);else if(M.at(-1)<N)M[M.length-1]=N};n.forEach((v,S)=>{let x=[...v.names,...v.tags.map((M)=>M.replaceAll("_"," "))];for(let[M,N]of[[x,1],[v.generated,0]])for(let C of M){let P=co(C);if(P&&bh(P))i(P,S,2|N);let _=C.split(/[\s・·_]+/);if(_.length<2)continue;for(let K of _){let B=co(K);if(B&&bh(B))i(B,S,N)}}});let s=[...r.keys()].sort(),o=[0],a=[];for(let v of s){for(let S of r.get(v)??[])a.push(S);o.push(a.length)}let c=n.flatMap((v,S)=>v.tags.map((x)=>[x,S])).sort(([v],[S])=>v<S?-1:v>S?1:0),u=mh(s.map((v)=>Buffer.from(v))),f=mh(n.map((v)=>Buffer.from(JSON.stringify([v.tag,v.tags,v.names,v.japanese,v.generated])))),l=mh(c.map(([v])=>Buffer.from(v))),d={keys:u.bytes,keyAt:u.at,ownAt:Ta(Uint32Array,o),owners:Ta(Uint32Array,a),cards:f.bytes,cardAt:f.at,ranks:Ta(Float32Array,n.map((v)=>v.rank)),tags:l.bytes,tagAt:l.at,tagCard:Ta(Uint32Array,c.map(([,v])=>v))},h=_$.map((v)=>{let S=d[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(G$,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 C$(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 j$(t,e){if(t.toString("latin1",0,4)!==G$)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,f]=r.sections[_$.indexOf(c)];return[i+u,f]},o=(c)=>{let[u,f]=s(c);return t.subarray(u,u+f)},a=(c)=>C$(Uint32Array,t,...s(c));return{keys:o("keys"),keyAt:a("keyAt"),ownAt:a("ownAt"),owners:a("owners"),cards:o("cards"),cardAt:a("cardAt"),ranks:C$(Float32Array,t,...s("ranks")),tags:o("tags"),tagAt:a("tagAt"),tagCard:a("tagCard")}}var ph;function wh(t){try{let e=B$(t);if(e.length===0)return;let n=U$(e);if(ph?.stamp===n)return ph.index;let r=ao(Kr(t),"index.bin"),i;try{i=j$(xu(r),n)}catch{}if(!i){let s=_N(e,n);try{L(r,s)}catch{}i=j$(s,n)}if(i)ph={stamp:n,index:i};return i}catch{return}}function W$(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 K$(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 z$(t,e){let n=Buffer.from(e),r=t.tagCard.length,i=K$(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 gh=/\s*[((][^()()]*[))]$/u,Mu={ko:4,en:4,ja:5,zh:3};function GN(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((l)=>!gh.test(l))),i=(l)=>!gh.test(l)||!r.has(l.replace(gh,"")),s=t.names.filter(i),o=s.filter((l)=>e.test(l)),a=[...o,...t.generated.slice(0,o.length>0?0:2)],c=s.filter((l)=>n.test(l)),u=t.japanese.filter(i),f=s.filter((l)=>!e.test(l)&&!n.test(l)&&!u.includes(l));return[...new Set([...a.slice(0,Mu.ko),...c.slice(0,Mu.en),...u.slice(0,Mu.ja),...f.slice(0,Mu.zh)])]}var oo;function Ou(t,e=uo()){if(!t)return[];if(!oo)try{oo=JSON.parse(xu(ao(Kr(e),"aliases.json"),"utf8")).tags}catch{oo={}}return oo[t]??[]}function $h(t,e=uo()){try{return BN(t,e)}catch{return new Map}}function BN(t,e){let n=new Map,r=B$(e);if(r.length===0||t.length===0)return n;let i=U$(r),s=ao(Kr(e),"aliases.json"),o;try{o=JSON.parse(xu(s,"utf8"))}catch{}if(o?.stamp===i&&t.every((f)=>(f in o.tags))){oo=o.tags;for(let f of t)n.set(f,o.tags[f]??[]);return n}let a=wh(e);if(!a)return n;let c=new Set([...t,...o?.stamp===i?Object.keys(o.tags):[]]),u={};for(let f of c){let l=z$(a,f);u[f]=l===void 0?[]:GN(W$(a,l))}try{L(s,`${JSON.stringify({stamp:i,tags:u})}
250
- `)}catch{}oo=u;for(let f of t)n.set(f,u[f]??[]);return n}function zi(t,e=uo()){$h(t.flatMap((n)=>n.booru?[n.booru]:[]),e)}var UN=0.25,WN=0.1;function q$(t,e,n=new Set,r=uo()){let i=co(t);if(!i||!bh(i))return[];let s=wh(r);if(!s)return[];let o=Buffer.from(i),a=s.ownAt.length-1,c=new Set([...n].flatMap((f)=>z$(s,f)??[])),u=new Map;for(let f=K$(s.keys,s.keyAt,a,i);f<a;f++){let l=s.keyAt[f],d=s.keyAt[f+1]-l;if(d<o.length||s.keys.compare(o,0,o.length,l,l+o.length)!==0)break;let h=d===o.length;for(let m=s.ownAt[f];m<s.ownAt[f+1];m++){let g=s.owners[m],b=g>>>2,w=h?Math.max(0,(g&2?2:1)-(g&1?0:1)):0,k=(s.ranks[b]??0)+UN*w+(c.has(b)?WN:0);if((u.get(b)?.score??-1)<k)u.set(b,{score:k,key:f})}}return[...u].sort(([,f],[,l])=>l.score-f.score).slice(0,e).map(([f,{key:l}])=>{let d=W$(s,f),h=s.keys.toString("utf8",s.keyAt[l],s.keyAt[l+1]);return{tag:d.tags.find((m)=>n.has(m))??d.tag,name:[...d.names,...d.generated].find((m)=>co(m).includes(h))??d.tag.replaceAll("_"," ")}})}function Pu(t=uo()){wh(t)}import{createHash as XN}from"node:crypto";import{existsSync as QN,readdirSync as rk,readFileSync as tT}from"node:fs";import{basename as ik,join as Iu}from"node:path";import{existsSync as KN,readFileSync as D$}from"node:fs";import{homedir as J$}from"node:os";import{isAbsolute as Y$,join as qi,resolve as zN}from"node:path";var J="official",vh="https://www.schemastore.org/ttheme-marketplace.json",V$="https://www.schemastore.org/ttheme-palette.json",Z$=["$schema","name","description","owner","catalog","renames","force_remove_deleted_palettes","metadata"],X$=["name","email","url"],Q$=["name","native","lead"],Di="ttheme-marketplace",qN=/^[a-z0-9](?:[a-z0-9]|-(?=[a-z0-9])){0,38}$/i,DN=/^[\w.-]{1,100}$/,JN=/^\w[\w.+/-]{0,199}$/;function ln(t){return qi(t,"ttheme","installed.json")}function Jt(t){return t??[J]}function lo(t){try{let{marketplaces:e}=JSON.parse(D$(ln(t),"utf8"));return Jt(Array.isArray(e)?e.filter((n)=>typeof n==="string"):void 0)}catch{return[J]}}function Rt(t){return Y$(t)}function wt(t){return t!==J&&!Rt(t)}function zr(t){let e=t.indexOf("#");return wt(t)&&e>=0?t.slice(0,e):t}function Ha(t){let e=t.indexOf("#");return wt(t)&&e>=0?t.slice(e+1):void 0}function sr(t,e){return zr(t)===zr(e)}function qr(t,e){return wt(t)&&(e?.[t]??!1)}function YN(t){return!JN.test(t)||t.includes("..")||t.includes("//")||/(?:[./]|\.lock)$/.test(t)}function An(t,e=process.cwd()){if(t===J)return J;if(t==="~"||t.startsWith("~/"))return qi(J$(),t.slice(1));if(t.startsWith(".")||Y$(t))return zN(e,t);let[n="",r,...i]=t.split("#"),[s,o,...a]=n.replace(/^https:\/\/github\.com\//,"").replace(/\.git$/,"").split("/");if(!s||!qN.test(s)||!o||!DN.test(o)||a.length>0||i.length>0||r!==void 0&&YN(r))throw Error(`${t} is not a marketplace — give a repository (alice/ttheme-dust, #v1 pins a tag or branch) or a path (./my-marketplace)`);return`${s.toLowerCase()}/${o}${r===void 0?"":`#${r}`}`}function tk(t){let e=Ha(t)?.split("/").map(encodeURIComponent).join("/")??"HEAD";return`https://codeload.github.com/${zr(t)}/tar.gz/${e}`}function ek(t){return t.slice(0,t.indexOf("/"))}function fo(t){return qi(t,"ttheme","marketplaces")}function or(t,e){return qi(fo(t),`${zr(e).replace("/","--")}.json`)}function Ji(t){return qi(t,"ttheme","marketplace")}function Sh(t,e){return qi(Ji(t),e)}function VN(t,e){if(typeof t!=="string"||typeof e!=="string")return'needs a "name" and an [owner] table whose name is the GitHub handle';return ee(`${t}@${e}/x`)}function we({owner:t,name:e}){return`${t}@${e}`}function nk({owner:t,name:e}){return`"$schema" = ${JSON.stringify(vh)}
266
+ `))nt(ot,"the [[catalog]] tables must follow the order meta.order gives their palettes");return i}function p$(t){return t.filter((e)=>e.role===void 0)}function ie(t){return[et(t.name),t.catalog].filter((e)=>e!==void 0).join(" / ")}function ro(t){return et(t.name)??t.catalog??""}function Gi(t){let e=(r,i)=>r<i?-1:r>i?1:0,n=(r)=>et(r.name)?r.name:r.base??r.name;return t.toSorted((r,i)=>Number(et(r.name)!==void 0)-Number(et(i.name)!==void 0)||e(ro(r).toLowerCase(),ro(i).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 La={width:2560,height:1550},RN=2,AN=2560,NN=0.1,x$=0.99,TN=2,Ui={tall:1.15,reach:0.4,widest:0.95,headroom:0.04,margin:0.03,stands:12},HN=xt(Ht("#19161e","#9b86c8",0.2)),FN="shelf",Iu="originals",LN="images.json",fh=1;function CN(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 g$(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 O$(t,e){let n=(o)=>ew({name:t.name,background:Ht(t.background,e,o),foreground:t.foreground,ansi:t.ansi,waive:t.waived??[]}).map((a)=>a.rule),r=new Set(n(0)),i=g$((o)=>n(o).every((a)=>r.has(a))),s=g$((o)=>xt(Ht(t.background,e,o))<=HN);return{cap:i,matched:s,opacity:Math.floor(Math.min(i,s)*100)/100}}function b$(t,e){let n=CN(t,e),{cap:r,matched:i,opacity:s}=O$(t,n),o=ct(t.background),a=Math.hypot(...ct(n).map((c,u)=>(c-(o[u]??0))*s));return{slot:e,color:n,cap:r,matched:i,opacity:s,reach:a}}function P$(t,e){return O$(t,e).opacity}function Hn(t,e){let n=b$(t,"cursor");if(n.opacity>=NN)return n;return e.values().filter((r)=>r!=="cursor"&&r!=="background").map((r)=>b$(t,r)).reduce((r,i)=>i.reach>r.reach?i:r,n)}function jN(t){return l0(t)??{x:0,y:0,w:t.width,h:t.height}}function bh(t,e){if(t<=0||e<=0)return La;let n=Math.min(1,La.width/Math.max(t,e));return{width:Math.round(t*n),height:Math.round(e*n)}}function I$(t,e,n,r){if(r<Ui.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(Ui.tall*n,Ui.reach*e*t.h/t.w),s=i*t.w/t.h;if(s>Ui.widest*e)s=Ui.widest*e,i=s*t.h/t.w;let o=Ui.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-Ui.margin)-s,y:o,w:s,h:i*a},focus:Math.min(1,(n/2-o)/i)}}function _N(t,e){return 0.299*(t[e]??0)+0.587*(t[e+1]??0)+0.114*(t[e+2]??0)}function BN(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(_N(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*x$)return Math.min(TN,Math.max(1,255/Math.max(1,o)));return 1}var lh=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 GN(t,e,n){return`#${[t,e,n].map((r)=>Math.round(r).toString(16).padStart(2,"0")).join("")}`}function UN(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,f=t.data[c+1]??0,l=t.data[c+2]??0,d=Math.round(255*Math.sqrt(0.2126*(lh[u]??0)+0.7152*(lh[f]??0)+0.0722*(lh[l]??0)));n[d]=(n[d]??0)+1,r[d*3]=(r[d*3]??0)+u,r[d*3+1]=(r[d*3+1]??0)+f,r[d*3+2]=(r[d*3+2]??0)+l,s++}}let o=0;for(let a=0;a<256&&s>0;a++)if(o+=n[a]??0,o>=s*x$){let c=Math.max(1,n[a]??1);return GN((r[a*3]??0)/c,(r[a*3+1]??0)/c,(r[a*3+2]??0)/c)}return"#ffffff"}function WN(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 R$(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 Pu(t,e,n,r){let i=new Float32Array(n*r),s=R$(e,n,r);if(s){let o=Gd(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 wh(t,e,n,r){let i=new Uint8Array(n*r*4),s=R$(e,n,r);if(s){let o=s.x1-s.x0,a=Ur(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 dh(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)=>ka(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 $h(t,e=!1){let n=e?Q0(t):t,r=jN(n),i,s;return{box:r,clear:sr(n,r),get ink(){return i??=WN(n,BN(n,r)),i},image:n,get peak(){return s??=UN(n,r),s}}}function A$(t,e,n,r,i,s){let o=$h(t,s),{box:a,clear:c,ink:u,image:f}=o,l=I$(a,e,n,c),d=Math.min(1,AN/Math.max(a.w,a.h)),h={x:0,y:0,w:Math.round(a.w*d),h:Math.round(a.h*d)},m=r*h.w*l.crop.w/(a.w*l.at.w);if(i==="original")return{coloring:i,figure:dh(Ur(f,a,h.w,h.h),m),fill:dh(wh(f,l,e,n),r),focus:l.focus,peak:o.peak};let p=Pu(u,{crop:a,at:h,focus:l.focus},h.w,h.h),b=Pu(u,l,e,n);return{coloring:i,figure:Ds(ka(p,m)),fill:Ds(ka(b,r)),focus:l.focus}}function KN(t,e,n,r){let i=ct(e),s=ct(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 zN(t,e,n){let r=ct(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 N$(t,e,n,r,i,s,o,a="tone"){let{box:c,clear:u,ink:f}=t,l=I$(c,r,i,u),d=Math.round(100*l.at.w/l.crop.w/Math.min(r/c.w,i/c.h)),h=o?.size??"fill",m=h==="fill"?l:{crop:c,at:uo(c.w,c.h,r,i,h,o?.at??5,!1,h>100?Math.round(l.focus*100):-1),focus:l.focus},p=a==="original"?P$(e,t.peak):n.opacity,b=o?.opacity??p;return{image:a==="original"?zN(dh(wh(t.image,m,r,i),s),e.background,b):KN(Ds(ka(Pu(f,m,r,i),s)),e.background,n.color,b),fill:d,opacity:p}}function X(t){return V(t,"ttheme","backgrounds")}function hh(t){return V(t,LN)}function Wi(t){try{return so(t,"utf8")}catch{return}}function Jr(t){try{return ON(t)}catch{return[]}}function Ft(t){let e=Wi(hh(t));if(e===void 0)return DN(t);let n=JSON.parse(e);if(n.version!==fh)throw Error(`${hh(t)} is version ${n.version} — this ttheme reads version ${fh}`);return n}function Je(t){return t.coloring??"tone"}function kh(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 oo(t){return{hue:{color:t.backdrop.color,opacity:t.backdrop.opacity},colors:kh(t)}}function ao(t){return t.tone===void 0&&Je(t)==="tone"}function T$(t){return t.replace(/[\s,\p{Cc}]+/gu,"_")}function w$(t){return(t.artist??[]).map(T$).join(",")}function qN(t){let e=Qd(t),n=X0(t)?.replace(/\p{Cc}+/gu,"");return[...n?[`# credit ${t.key} ${n}`]:[],...e?[`# source ${t.key} ${e.label} ${e.url}`]:[],...(t.artist??[]).flatMap((r)=>{let i=Ra(t.profiles?.[r]);return i.length>0?[`# profile ${t.key} ${T$(r)} ${i.map((s)=>`${s.kind} ${s.url}`).join(" ")}`]:[]})]}function H$(t,e){let n=e.pictures.findIndex((i)=>i.key===e.active),r=e.pictures[n];return[...r.artist?.length?[`# by ${w$(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?w$(i):"-"}`,...i.from?[i.from]:[]].join(" ")),...e.pictures.filter((i)=>Je(i)==="original").map((i)=>`# colors ${i.key} original`),...e.pictures.flatMap(qN),`background-image = ${V(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(`
267
+ `)}function F$(t){let e=X(t);for(let[n,r]of Object.entries(Ft(e).palettes)){let i=V(e,`${he(n)}.conf`),s=H$(e,r);if(Wi(i)!==s)H(i,s)}}function Ki(t,e,n){H(hh(t),`${JSON.stringify(e,null,2)}
268
+ `);for(let r of n){let i=e.palettes[r],s=V(t,`${he(r)}.conf`);if(i)H(s,H$(t,i));else io(s,{force:!0})}}function L$(t,e){let n=X(t),r=Ft(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)Ki(n,r,i)}function C$(t,e){return Jr(t).filter((n)=>n.startsWith(`${e}.`)||n.startsWith(`${e}@`))}function yh(t,e){for(let n of C$(t,e))io(V(t,n),{force:!0})}function j$(t,e){yh(t,e.stem);for(let n of[e.original,e.cut])if(n)io(V(t,n),{force:!0})}function $$(t,e,n,r){let i=M$(/^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((f)=>f.startsWith(`${t}-${o}.`));return{key:o,stem:s,fill:i,opacity:Number.isFinite(c)?c:1,...a?{from:a}:{},...u?{original:V(Iu,u)}:{}}}function k$(t,e){if(gh(t))E$(t,e)}function DN(t){let e={version:fh,palettes:{}};if(!gh(t))return e;let n=Jr(V(t,Iu)),r=Jr(t).filter((s)=>s.endsWith(".conf")&&s!=="shown.conf"&&!/\.(tune|off)\.conf$/.test(s)).map((s)=>s.slice(0,-5)),i=V(t,FN);for(let s of new Set([...r,...Jr(i)])){let o=[],a=$$(s,Wi(V(t,`${s}.conf`)),n);if(a)k$(V(t,`${s}.tune.conf`),V(t,`${a.stem}.tune.conf`)),k$(V(t,`${s}.off.conf`),V(t,`${a.stem}.off.conf`)),o.push(a);for(let c of Jr(V(i,s))){let u=V(i,s,c),f=$$(s,Wi(V(u,".conf")),n,c);if(!f)continue;for(let l of Jr(u)){let d=l===".tune.conf"||l===".off.conf"?`${f.stem}${l}`:`${s}${l}`;if(l!==".conf")E$(V(u,l),V(t,d))}io(u,{recursive:!0}),o.push(f)}if(Jr(V(i,s)).length===0)io(V(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(Jr(i).length===0)io(i,{recursive:!0,force:!0});return Ki(t,e,Object.keys(e.palettes)),e}function y$(t,e,n){return e.startsWith("~/")?V(n,e.slice(2)):IN(e)?e:V(t,e)}function Fe(t,e,n){let r=new Map,i=(a,c)=>{let u=Wi(a);if(u===void 0)return!1;for(let f of u.split(`
269
+ `)){let l=/^([a-z-]+)\s*=\s*(.*?)\s*$/.exec(f);if(l?.[1]==="config-file"&&c<4)i(y$(t,l[2].replace(/^\?/,""),n),c+1);else if(l&&/^background-image(?:-fit|-opacity|-position)?$/.test(l[1]))r.set(l[1],l[2])}return!0};if(!i(V(t,`${he(e)}.conf`),0))return;let s=r.get("background-image")??"";if(s==="")return;let o=Number(r.get("background-image-opacity")??1);return{image:y$(t,s,n),opacity:Number.isFinite(o)?o:1,cover:r.get("background-image-fit")==="cover",position:r.get("background-image-position")??"center"}}function me(t){return`${t.site}_${t.id}`}function Ru(t,e,n){let r=X(t),i=Ft(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);j$(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 Ki(r,i,[e]),{key:a.key,left:s.pictures.length}}function _$(t,e,n,r){let i=n.coloring==="original"?De(n.figure):ar(n.figure,r),s=n.coloring==="original"?De(n.fill):ar(n.fill,r),o=`${he(t)}.${S$("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 B$(t,e,n,r){return n==="original"&&r?{coloring:"original",opacity:P$(t,r),peak:r}:{coloring:"tone",opacity:e.opacity,tone:e.color}}function mh(t,e){return V(Iu,`${he(t)}-${e}`)}function vh(t,e){return e.map(([n,r])=>{let i=V(t,n);return H(i,r),i})}function Au(t,e,n,r,i,s,o,a="tone"){let c=X(t),u=e.name,f=me(i),l=Ft(c),d=l.palettes[u]??{active:f,pictures:[]},h=bh(s.width,s.height),m=A$(r,h.width,h.height,o,a,i.cut===!0),p=_$(u,f,m,n.color),b=mh(u,f),$={key:f,stem:p.stem,fill:p.fill,...B$(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.profiles&&Object.keys(i.profiles).length>0?{profiles:i.profiles}:{},...i.source?{source:i.source}:{},original:`${b}.${i.ext}`,...i.cut?{cut:`${b}.cut.png`,matte:Aa}:{}},k=d.pictures.find((S)=>S.key===f);if(k)j$(c,k);xN(V(c,Iu),{recursive:!0});let v=vh(c,[...p.files,[$.original,i.bytes],...$.cut?[[$.cut,Ud(or(r))]]:[]]);return d.pictures=k?d.pictures.map((S)=>S===k?$:S):[...d.pictures,$],d.active=f,l.palettes[u]=d,Ki(c,l,[u]),[...v,V(c,`${he(u)}.conf`)]}function co(t,e,n){let r=X(t),i=Ft(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,Ki(r,i,[e]);return{at:o+1,of:s.pictures.length}}function ke(t,e){let n=Ft(X(t)).palettes[e];if(!n)return[];return[...n.pictures.filter((i)=>i.key===n.active),...n.pictures.filter((i)=>i.key!==n.active)]}var ph="top-right";function uo(t,e,n,r,i,s,o,a=-1){let c=Math.trunc,u=(s-1)%3,f=c((s-1)/3),l=n*e>=r*t!==!o,d=l?c(i*n/100):c(i*r*t/(100*e)),h=l?c(i*n*e/(100*t)):c(i*r/100),m=c(u*(n-d)/2),p=c(f*(r-h)/2);if(a>=0){if(d>n)m=c((n-d)/2);if(h>r)p=Math.max(r-h,Math.min(0,c(r/2)-c(a*h/100)))}return{x:m,y:p,w:d,h}}function Sh(t,e){let n=Wi(V(t,`${e.stem}.tune.conf`));if(n===void 0)return{};let r=(u)=>new RegExp(`^${u}\\s*=\\s*(.*?)\\s*$`,"m").exec(n)?.[1]??"",i=M$(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!==ph?{position:a}:{},...Number.isFinite(c)&&c!==e.opacity?{opacity:c}:{}}}function Ca(t,e,n,r,i){let s=n.size??"fill",o=n.position??ph,a=n.opacity??e.opacity;if(s==="fill"&&o===ph&&a===e.opacity)return;let c=Jt.indexOf(o)+1,u=V(t,`${e.stem}.png`),f=V(t,e.fill),l=!0,d=typeof s==="number"&&(s>100||!r&&o!=="center");if(s===100&&!d)f=u,l=!1;else if(typeof s==="number"){if(ao(e))throw Error(`${e.stem} was drawn before pictures kept their tone — init draws it again`);let m=Kt(new Uint8Array(so(u))),{width:p,height:b}=d?La:m,$=d?Number(/@fill-(\d+)\.png$/.exec(e.fill)?.[1]??50):-1,k=uo(m.width,m.height,p,b,s,c,!1,$);f=V(t,`${e.stem}@${s}-${o}${d?`-${p}x${b}`:""}.png`);let S={crop:{x:0,y:0,w:m.width,h:m.height},at:k,focus:$};H(f,e.tone?ar(Ds(Pu(or(m),S,p,b)),e.tone):De(wh(m,S,p,b))),l=d}let h=V(t,`${e.stem}.tune.conf`);return H(h,[`background-image = ${f.startsWith(`${i}/`)?`~${f.slice(i.length)}`:f}`,`background-image-fit = ${l?"cover":"contain"}`,`background-image-position = ${o}`,`background-image-opacity = ${a}`,""].join(`
270
+ `)),h}function G$(t){return new Map(Object.entries(Ft(X(t)).palettes).flatMap(([e,n])=>{let[,r,i]=/^([a-z.]+)_(\d+)$/.exec(n.active)??[];return r&&i?[[e,{site:r,id:Number(i)}]]:[]}))}function U$(t){try{let e=Rn(new Uint8Array(so(t)));return e?{width:e.width,height:e.height}:void 0}catch{return}}function W$(t,e,n,r,i,s,o){let a=[n.original,n.cut].map((c)=>{if(!c)return"";try{let{size:u,mtimeMs:f}=PN(V(t,c));return`${c}:${u}:${f}`}catch{return}});if(!n.original||a.includes(void 0))return;return t$([RN,he(e),n.key,...a,r.width,r.height,i,s,s==="tone"?o:""])}function JN(t,e,n){if(!n.window||n.blur===void 0)return;let r=W$(t,e,n,n.window,n.blur,Je(n),n.tone??"");if(!r||e$(r))return;try{eh(r,{stem:n.stem,fill:n.fill,...n.peak?{peak:n.peak}:{},figure:so(V(t,`${n.stem}.png`)),picture:so(V(t,n.fill))})}catch{}}function K$(t,e,n,r,i,s,o,a,c){let u=c?void 0:W$(t,e,n,r,o,a,s.hue.color),f=u?n$(u):void 0;if(f)return{made:{stem:f.stem,fill:f.fill,files:[[`${f.stem}.png`,f.figure],[f.fill,f.picture]]},peak:f.peak,image:void 0};let l=i();if(!l)return null;let d=A$(l,r.width,r.height,o,a,c||n.cut!==void 0),h=_$(e,n.key,d,s.hue.color),m=d.coloring==="original"?d.peak:void 0;if(u)eh(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:l}}function ja(t,e,n,r,i,s,o,a,c,u=Je(n)){let f=X(t),l=n.window??U$(V(f,n.fill))??La,d=K$(f,e,n,l,r,i,s,u,c);if(!d)return null;let{made:h,peak:m,image:p}=d,b={...n,stem:h.stem,fill:h.fill,...B$(i.colors,i.hue,u,m),blur:s,window:l,...c?{cut:`${mh(e,n.key)}.cut.png`}:{},...c||n.cut?{matte:Aa}:{}};if(u==="original")delete b.tone;else delete b.peak;if(c&&p)H(V(f,`${mh(e,n.key)}.cut.png`),Ud(or(p)));if(h.stem===n.stem)return b;if(Je(n)!==u)JN(f,e,n);vh(f,h.files);let $=Sh(f,n);Ca(f,b,Je(n)===u?$:{...$,opacity:void 0},o,a);let k=V(f,`${n.stem}.off.conf`);if(gh(k))MN(k,V(f,`${b.stem}.off.conf`));return b}function z$(t,e,n,r,i,s,o){let a=X(t),c=n.window??U$(V(a,n.fill))??La;return K$(a,e,n,c,r,i,s,o,!1)!==null}function Eh(t,e){let n=X(t),r=Ft(n),i=new Set,s=[];for(let{name:o,picture:a}of e){let c=r.palettes[o],u=c?.pictures.findIndex((l)=>l.key===a.key)??-1,f=c?.pictures[u];if(!c||!f)continue;if(c.pictures[u]=a,i.add(o),f.stem!==a.stem)s.push(f.stem)}if(i.size===0)return;Ki(n,r,[...i]);for(let o of s)yh(n,o)}function YN(t,e,n,r){let i=C$(t,n.stem).filter((a)=>a.endsWith(".png")).map((a)=>{let c=new Uint8Array(so(V(t,a)));return[a,lu(c,r.color)??ar(or(Kt(c)),r.color)]}),s=(a)=>i.find(([c])=>c===a)?.[1]??new Uint8Array,o=`${he(e)}.${S$("sha1").update(n.key).update(s(`${n.stem}.png`)).update(s(n.fill)).digest("hex").slice(0,8)}`;vh(t,i.map(([a,c])=>[o+a.slice(n.stem.length),c]));for(let a of["tune","off"]){let c=Wi(V(t,`${n.stem}.${a}.conf`));if(c!==void 0)H(V(t,`${o}.${a}.conf`),c.split(n.stem).join(o))}return{...n,stem:o,fill:o+n.fill.slice(n.stem.length),tone:r.color}}function v$(t,e){return Je(t)!=="original"&&t.tone!==void 0&&t.tone!==e.hue.color}function q$(t,e){let n=X(t),r=Ft(n),i=[],s=[];for(let[o,a]of Object.entries(r.palettes)){let c=e.get(o);if(!c||!a.pictures.some((u)=>v$(u,c)))continue;a.pictures=a.pictures.map((u)=>{if(!v$(u,c))return u;let f=YN(n,o,u,c.hue);if(f.stem!==u.stem)s.push(u.stem);return f}),i.push(o)}if(i.length>0){Ki(n,r,i);for(let o of s)yh(n,o)}return i}var VN=1;function dn(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}:{},...t.catalog?{catalog:t.catalog}:{},...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:xn(t),...t.waive.length>0?{waived:t.waive}:{},backdrop:{slot:e,color:n,opacity:r},...t.pictures?{pictures:t.pictures}:{}}}function Le(t){return{name:t.name,...t.base?{base:t.base}:{},...t.catalog?{catalog:t.catalog}:{},...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 ZN=6,XN=["ansi1","ansi2","ansi4","ansi3","ansi5","ansi6"];function lo(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,...XN]){let o=e(s);if(i.length===ZN||!o||r.has(n(s))||i.includes(o))continue;r.add(n(s)),i.push(o)}return i}function At(t){return t.filter((e)=>e.default!==!0)}function Nu(){return{schema:VN,version:dt.version,gate:Te,palettes:[]}}import{existsSync as QN,readFileSync as Hu,statSync as D$}from"node:fs";import{homedir as po}from"node:os";import{join as ho}from"node:path";var tT=["core","kowiki","unlicensed"],eT=["ko","ja","en","zh","other"],V$=["keys","keyAt","ownAt","owners","cards","cardAt","ranks","tags","tagAt","tagCard"],Z$="TTNI";function Yr(t=po()){return ho(process.env.XDG_CACHE_HOME??ho(t,".cache"),"ttheme","aninames")}var nT=/[ァ-ヶ]/g,rT=/[\s\p{P}\p{S}]+/gu;function mo(t){return t.normalize("NFKC").toLowerCase().replace(nT,(e)=>String.fromCharCode(e.charCodeAt(0)-96)).replace(rT,"")}function zi(t,e){let n=mo(e);if(n===""){let r=e.toLowerCase();return t.some((i)=>i.toLowerCase().includes(r))}return t.some((r)=>mo(r).includes(n))}function Ph(t){return t.length>=2||/[\p{Script=Han}\p{Script=Hangul}\p{Script=Hiragana}]/u.test(t)}function X$(t){let e=Yr(t);return tT.values().map((n)=>ho(e,`ttheme-${n}.json`)).filter((n)=>QN(n)).toArray()}var iT=6;function Q$(t){return[`format ${iT}`,...t.map((e)=>`${e}:${D$(e).size}:${D$(e).mtimeMs}`)].join("|")}function sT(t){try{return JSON.parse(Hu(t,"utf8"))}catch{return{}}}function oT(t){let e=new Map;for(let r of t)for(let[i,s]of Object.entries(sT(r))){let o=e.get(i)??{tags:new Set,names:[],japanese:[],generated:[],rank:0,weight:0,posts:0};o.posts=Math.max(o.posts,s.posts??0),o.generated.push(...s.generated??[]),o.japanese.push(...s.names?.ja??[]),o.tag??=s.tag;for(let a of s.danbooru??[])o.tags.add(a);for(let a of eT)o.names.push(...s.names?.[a]??[]);if(s.rank!==void 0){let a=s.weight??1;o.rank=(o.rank*o.weight+s.rank*a)/(o.weight+a),o.weight+=a}e.set(i,o)}let n=Math.log1p(e.values().reduce((r,i)=>Math.max(r,i.posts),1));return e.values().filter((r)=>r.tags.size>0).map((r)=>{let i=[...r.tags];return{tag:r.tag&&r.tags.has(r.tag)?r.tag:i[0],tags:i,names:[...new Set(r.names)],japanese:[...new Set(r.japanese)],generated:[...new Set(r.generated)],rank:r.posts>0?Math.log1p(r.posts)/n:r.rank}}).toArray()}function _a(t,e){let n=new t(e.length);return n.set(e),n}function Mh(t){let e=[0];for(let n of t)e.push(e.at(-1)+n.length);return{bytes:Buffer.concat(t),at:_a(Uint32Array,e)}}function aT(t,e){let n=oT(t),r=new Map,i=(v,S,x)=>{let M=r.get(v),N=S*4+x;if(!M)r.set(v,[N]);else if(M.at(-1)>>>2!==S)M.push(N);else if(M.at(-1)<N)M[M.length-1]=N};n.forEach((v,S)=>{let x=[...v.names,...v.tags.map((M)=>M.replaceAll("_"," "))];for(let[M,N]of[[x,1],[v.generated,0]])for(let C of M){let I=mo(C);if(I&&Ph(I))i(I,S,2|N);let j=C.split(/[\s・·_]+/);if(j.length<2)continue;for(let U of j){let G=mo(U);if(G&&Ph(G))i(G,S,N)}}});let s=[...r.keys()].sort(),o=[0],a=[];for(let v of s){for(let S of r.get(v)??[])a.push(S);o.push(a.length)}let c=n.flatMap((v,S)=>v.tags.map((x)=>[x,S])).sort(([v],[S])=>v<S?-1:v>S?1:0),u=Mh(s.map((v)=>Buffer.from(v))),f=Mh(n.map((v)=>Buffer.from(JSON.stringify([v.tag,v.tags,v.names,v.japanese,v.generated])))),l=Mh(c.map(([v])=>Buffer.from(v))),d={keys:u.bytes,keyAt:u.at,ownAt:_a(Uint32Array,o),owners:_a(Uint32Array,a),cards:f.bytes,cardAt:f.at,ranks:_a(Float32Array,n.map((v)=>v.rank)),tags:l.bytes,tagAt:l.at,tagCard:_a(Uint32Array,c.map(([,v])=>v))},h=V$.map((v)=>{let S=d[v];return Buffer.from(S.buffer,S.byteOffset,S.byteLength)}),m=0,p=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:p})),$=Math.ceil((8+b.length)/4)*4,k=Buffer.alloc($+m);k.write(Z$,0,"latin1"),k.writeUInt32LE(b.length,4),b.copy(k,8);for(let[v,S]of h.entries())S.copy(k,$+(p[v]?.[0]??0));return k}function J$(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 Y$(t,e){if(t.toString("latin1",0,4)!==Z$)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,f]=r.sections[V$.indexOf(c)];return[i+u,f]},o=(c)=>{let[u,f]=s(c);return t.subarray(u,u+f)},a=(c)=>J$(Uint32Array,t,...s(c));return{keys:o("keys"),keyAt:a("keyAt"),ownAt:a("ownAt"),owners:a("owners"),cards:o("cards"),cardAt:a("cardAt"),ranks:J$(Float32Array,t,...s("ranks")),tags:o("tags"),tagAt:a("tagAt"),tagCard:a("tagCard")}}var xh;function Ih(t){try{let e=X$(t);if(e.length===0)return;let n=Q$(e);if(xh?.stamp===n)return xh.index;let r=ho(Yr(t),"index.bin"),i;try{i=Y$(Hu(r),n)}catch{}if(!i){let s=aT(e,n);try{H(r,s)}catch{}i=Y$(s,n)}if(i)xh={stamp:n,index:i};return i}catch{return}}function tk(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 ek(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 nk(t,e){let n=Buffer.from(e),r=t.tagCard.length,i=ek(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 Oh=/\s*[((][^()()]*[))]$/u,Tu={ko:4,en:4,ja:5,zh:3};function cT(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((l)=>!Oh.test(l))),i=(l)=>!Oh.test(l)||!r.has(l.replace(Oh,"")),s=t.names.filter(i),o=s.filter((l)=>e.test(l)),a=[...o,...t.generated.slice(0,o.length>0?0:2)],c=s.filter((l)=>n.test(l)),u=t.japanese.filter(i),f=s.filter((l)=>!e.test(l)&&!n.test(l)&&!u.includes(l));return[...new Set([...a.slice(0,Tu.ko),...c.slice(0,Tu.en),...u.slice(0,Tu.ja),...f.slice(0,Tu.zh)])]}var fo;function Fu(t,e=po()){if(!t)return[];if(!fo)try{fo=JSON.parse(Hu(ho(Yr(e),"aliases.json"),"utf8")).tags}catch{fo={}}return fo[t]??[]}function Rh(t,e=po()){try{return uT(t,e)}catch{return new Map}}function uT(t,e){let n=X$(e);if(n.length===0||t.length===0)return new Map;let r=Q$(n),i=ho(Yr(e),"aliases.json"),s;try{s=JSON.parse(Hu(i,"utf8"))}catch{}if(s?.stamp===r&&t.every((u)=>(u in s.tags)))return fo=s.tags,new Map(t.map((u)=>[u,s.tags[u]??[]]));let o=Ih(e);if(!o)return new Map;let a=new Set([...t,...s?.stamp===r?Object.keys(s.tags):[]]),c={};for(let u of a){let f=nk(o,u);c[u]=f===void 0?[]:cT(tk(o,f))}try{H(i,`${JSON.stringify({stamp:r,tags:c})}
271
+ `)}catch{}return fo=c,new Map(t.map((u)=>[u,c[u]??[]]))}function qi(t,e=po()){Rh(t.flatMap((n)=>n.booru?[n.booru]:[]),e)}var lT=0.25,fT=0.1;function rk(t,e,n=new Set,r=po()){let i=mo(t);if(!i||!Ph(i))return[];let s=Ih(r);if(!s)return[];let o=Buffer.from(i),a=s.ownAt.length-1,c=new Set([...n].flatMap((f)=>nk(s,f)??[])),u=new Map;for(let f=ek(s.keys,s.keyAt,a,i);f<a;f++){let l=s.keyAt[f],d=s.keyAt[f+1]-l;if(d<o.length||s.keys.compare(o,0,o.length,l,l+o.length)!==0)break;let h=d===o.length;for(let m=s.ownAt[f];m<s.ownAt[f+1];m++){let p=s.owners[m],b=p>>>2,$=h?Math.max(0,(p&2?2:1)-(p&1?0:1)):0,k=(s.ranks[b]??0)+lT*$+(c.has(b)?fT:0);if((u.get(b)?.score??-1)<k)u.set(b,{score:k,key:f})}}return[...u].sort(([,f],[,l])=>l.score-f.score).slice(0,e).map(([f,{key:l}])=>{let d=tk(s,f),h=s.keys.toString("utf8",s.keyAt[l],s.keyAt[l+1]);return{tag:d.tags.find((m)=>n.has(m))??d.tag,name:[...d.names,...d.generated].find((m)=>mo(m).includes(h))??d.tag.replaceAll("_"," ")}})}function Lu(t=po()){Ih(t)}import{createHash as kT}from"node:crypto";import{existsSync as yT,readdirSync as mk,readFileSync as vT}from"node:fs";import{basename as pk,join as ju}from"node:path";import{existsSync as dT,readFileSync as ik}from"node:fs";import{homedir as sk}from"node:os";import{isAbsolute as ok,join as Di,resolve as hT}from"node:path";var J="official",Th="https://www.schemastore.org/ttheme-marketplace.json",ak="https://www.schemastore.org/ttheme-palette.json",ck=["$schema","name","description","owner","catalog","renames","force_remove_deleted_palettes","metadata"],uk=["name","email","url"],lk=["name","native","lead"],Ji="ttheme-marketplace",mT=/^[a-z0-9](?:[a-z0-9]|-(?=[a-z0-9])){0,38}$/i,pT=/^[\w.-]{1,100}$/,gT=/^\w[\w.+/-]{0,199}$/;function hn(t){return Di(t,"ttheme","installed.json")}function Yt(t){return t??[J]}function go(t){try{let{marketplaces:e}=JSON.parse(ik(hn(t),"utf8"));return Yt(Array.isArray(e)?e.filter((n)=>typeof n==="string"):void 0)}catch{return[J]}}function Rt(t){return ok(t)}function wt(t){return t!==J&&!Rt(t)}function Vr(t){let e=t.indexOf("#");return wt(t)&&e>=0?t.slice(0,e):t}function Ba(t){let e=t.indexOf("#");return wt(t)&&e>=0?t.slice(e+1):void 0}function lr(t,e){return Vr(t)===Vr(e)}function Zr(t,e){return wt(t)&&(e?.[t]??!1)}function bT(t){return!gT.test(t)||t.includes("..")||t.includes("//")||/(?:[./]|\.lock)$/.test(t)}function Fn(t,e=process.cwd()){if(t===J)return J;if(t==="~"||t.startsWith("~/"))return Di(sk(),t.slice(1));if(t.startsWith(".")||ok(t))return hT(e,t);let[n="",r,...i]=t.split("#"),[s,o,...a]=n.replace(/^https:\/\/github\.com\//,"").replace(/\.git$/,"").split("/");if(!s||!mT.test(s)||!o||!pT.test(o)||a.length>0||i.length>0||r!==void 0&&bT(r))throw Error(`${t} is not a marketplace — give a repository (alice/ttheme-dust, #v1 pins a tag or branch) or a path (./my-marketplace)`);return`${s.toLowerCase()}/${o}${r===void 0?"":`#${r}`}`}function fk(t){let e=Ba(t)?.split("/").map(encodeURIComponent).join("/")??"HEAD";return`https://codeload.github.com/${Vr(t)}/tar.gz/${e}`}function dk(t){return t.slice(0,t.indexOf("/"))}function bo(t){return Di(t,"ttheme","marketplaces")}function fr(t,e){return Di(bo(t),`${Vr(e).replace("/","--")}.json`)}function Yi(t){return Di(t,"ttheme","marketplace")}function Hh(t,e){return Di(Yi(t),e)}function wT(t,e){if(typeof t!=="string"||typeof e!=="string")return'needs a "name" and an [owner] table whose name is the GitHub handle';return re(`${t}@${e}/x`)}function ye({owner:t,name:e}){return`${t}@${e}`}function hk({owner:t,name:e}){return`"$schema" = ${JSON.stringify(Th)}
251
272
  name = ${JSON.stringify(e)}
252
273
 
253
274
  [owner]
254
275
  name = ${JSON.stringify(t)}
255
- `}function yh(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 kh(t,e,n){return n===void 0?void 0:yh(t,e,n,"one line of text, 200 characters at most")}function ZN(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(ee(r)||i!==!1&&(typeof i!=="string"||ee(i)))throw Error(`${t}: renames.${r} must map a palette name to a palette name, or to false`);n[r]=i}return n}function Eh(t,e){let n;try{n=ji(t)}catch(d){throw Error(`${e} is not valid TOML — ${d.message.split(`
256
- `)[0]}`)}let r=yh(e,"name",n.name,"the marketplace 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:yh(e,"owner.name",s.name,"the GitHub handle")},a=kh(e,"owner.email",s.email),c=kh(e,"owner.url",s.url),u=kh(e,"description",n.description),f=n.force_remove_deleted_palettes;if(f!==void 0&&typeof f!=="boolean")throw Error(`${e}: force_remove_deleted_palettes must be true or false`);let l=VN(o.name,r);if(l)throw Error(`${e} ${l}`);return{owner:o.name,name:r,about:{...o,...a?{email:a}:{},...c?{url:c}:{}},...u?{description:u}:{},catalogs:Zd(e,n.catalog),renames:ZN(e,n.renames),forceRemove:f===!0}}function Je(t){let e=qi(t,ot);if(!KN(e))throw Error(`${t} has no ${ot} — \`ttheme marketplace init ${t}\` makes one`);return Eh(D$(e,"utf8"),e)}function st(t){if(t===J)return"the official marketplace";if(!Rt(t))return`github.com/${t}`;let e=J$();return t===e||t.startsWith(`${e}/`)?`~${t.slice(e.length)}`:t}var La="tt2:",Oh="https://ttheme.vercel.app/p/",Ru=4,sk=["background","foreground","cursor","selection",...Array.from({length:16},(t,e)=>`ansi${e}`)];function Yi(t,e=!0){return lo(t).filter(Rt).flatMap((n)=>{try{let r=Je(n);return[{dir:n,...r,id:we(r)}]}catch(r){if(e)process.stderr.write(`ttheme: skipping the marketplace at ${n} — ${r.message}
257
- `);return[]}})}function Au(t){return Iu(t,"palettes")}function Mh(t,e){return t<e?-1:t>e?1:0}function Ph(t,e,n=[]){let r=[],i=[];for(let o of t){let[a,c,u,...f]=o.split("/");if(a!=="palettes"||!c||c.startsWith(".")||f.length>0)continue;if(u===void 0){if(c.endsWith(".toml"))i.push({file:{path:e(o),slug:ik(c,".toml")},name:c})}else if(u.endsWith(".toml"))r.push({file:{path:e(o),slug:ik(u,".toml"),catalog:c},name:u})}let s=(o="")=>{let a=n.findIndex((c)=>c.name===o);return a<0?n.length:a};return r.sort((o,a)=>s(o.file.catalog)-s(a.file.catalog)||Mh(o.file.catalog??"",a.file.catalog??"")||Mh(o.name,a.name)),i.sort((o,a)=>Mh(o.name,a.name)),[...r,...i].map(({file:o})=>o)}function eT(t){try{return Je(t).catalogs}catch{return[]}}function ho(t,e=[]){let n=Au(t);if(!QN(n))return[];let r=rk(n,{withFileTypes:!0}).flatMap((i)=>i.isDirectory()?rk(Iu(n,i.name)).map((s)=>`palettes/${i.name}/${s}`):[`palettes/${i.name}`]);return Ph(r,(i)=>Iu(t,i),e)}function nT(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 marketplace`;let r=t.catalog===void 0?void 0:Ra(t.catalog);return r?`the catalog folder ${JSON.stringify(t.catalog)} ${r}`:void 0}function Rh(t,e){let n=et(e);if(!n)throw Error(`${e} is an official palette — yours are named <you>@<marketplace>/<palette>`);let r=Yi(t,!1).find((s)=>s.id===n);if(!r)throw Error(`${n} is not a local marketplace — \`ttheme marketplace add <dir>\` adds the folder that holds it`);let i=te(e);return ho(r.dir).find((s)=>s.slug===i)?.path??Iu(Au(r.dir),`${i}.toml`)}function rT(t,e,n,r){let i=new Map(e.filter((s)=>!s.default&&!et(s.name)).map((s)=>[s.name,{order:s.order}]));return{name:t,...r.catalog===void 0?{}:{catalog:r.catalog},catalogs:new Map((r.catalogs??[]).map((s)=>[s.name,s])),bases:i,open:!0,...n?{foreign:!0}:{}}}function Nn(t,e,n,r=!1,i={}){let s=te(t);return{...Xd(`${s}.toml`,e,rT(s,n,r,i)),name:t}}function de(t){return t?(e,n)=>process.stderr.write(`ttheme: skipping ${e} — ${n}
258
- `):()=>{}}function Ih(t,e,n,r,i,s=!1,o=[]){let a=new Map;return t.flatMap((c)=>{try{let u=nT(c,a);if(u)throw Error(u);a.set(c.slug,c);let f={...c.catalog===void 0?{}:{catalog:c.catalog},catalogs:o};return[un(Nn(`${n}/${c.slug}`,e(c),r,s,f))]}catch(u){return i(c.path,u.message),[]}})}function Tn(t,e,n,r=de(!0)){let i=eT(t);return Ih(ho(t,i),(s)=>tT(s.path,"utf8"),e,n,r,!1,i)}function Nu(t,e,n=!0){return Yi(t,n).flatMap(({dir:r,id:i})=>Tn(r,i,e,de(n)))}function Ah(t,e=t.name,n){return{name:e,...t.base?{base:t.base}:{},...t.catalog?{catalog:t.catalog}:{},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 Lt=(t)=>JSON.stringify(t);function ok(t){return["[[picture]]",`site = ${Lt(t.site)}`,`id = ${t.id}`,...t.size===void 0?[]:[`size = ${typeof t.size==="number"?t.size:Lt(t.size)}`],...t.position===void 0?[]:[`position = ${Lt(t.position)}`],...t.opacity===void 0?[]:[`opacity = ${t.opacity}`]]}function ak(t,e){return e.length===0?t:`${t.replace(/\n*$/,`
276
+ `}function Nh(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 Ah(t,e,n){return n===void 0?void 0:Nh(t,e,n,"one line of text, 200 characters at most")}function $T(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(re(r)||i!==!1&&(typeof i!=="string"||re(i)))throw Error(`${t}: renames.${r} must map a palette name to a palette name, or to false`);n[r]=i}return n}function Fh(t,e){let n;try{n=_i(t)}catch(d){throw Error(`${e} is not valid TOML — ${d.message.split(`
277
+ `)[0]}`)}let r=Nh(e,"name",n.name,"the marketplace 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:Nh(e,"owner.name",s.name,"the GitHub handle")},a=Ah(e,"owner.email",s.email),c=Ah(e,"owner.url",s.url),u=Ah(e,"description",n.description),f=n.force_remove_deleted_palettes;if(f!==void 0&&typeof f!=="boolean")throw Error(`${e}: force_remove_deleted_palettes must be true or false`);let l=wT(o.name,r);if(l)throw Error(`${e} ${l}`);return{owner:o.name,name:r,about:{...o,...a?{email:a}:{},...c?{url:c}:{}},...u?{description:u}:{},catalogs:ch(e,n.catalog),renames:$T(e,n.renames),forceRemove:f===!0}}function Ye(t){let e=Di(t,ot);if(!dT(e))throw Error(`${t} has no ${ot} — \`ttheme marketplace init ${t}\` makes one`);return Fh(ik(e,"utf8"),e)}function st(t){if(t===J)return"the official marketplace";if(!Rt(t))return`github.com/${t}`;let e=sk();return t===e||t.startsWith(`${e}/`)?`~${t.slice(e.length)}`:t}var Ga="tt2:",jh="https://ttheme.vercel.app/p/",Cu=4,gk=["background","foreground","cursor","selection",...Array.from({length:16},(t,e)=>`ansi${e}`)];function Vi(t,e=!0){return go(t).filter(Rt).flatMap((n)=>{try{let r=Ye(n);return[{dir:n,...r,id:ye(r)}]}catch(r){if(e)process.stderr.write(`ttheme: skipping the marketplace at ${n} — ${r.message}
278
+ `);return[]}})}function _u(t){return ju(t,"palettes")}function Lh(t,e){return t<e?-1:t>e?1:0}function _h(t,e,n=[]){let r=[],i=[];for(let o of t){let[a,c,u,...f]=o.split("/");if(a!=="palettes"||!c||c.startsWith(".")||f.length>0)continue;if(u===void 0){if(c.endsWith(".toml"))i.push({file:{path:e(o),slug:pk(c,".toml")},name:c})}else if(u.endsWith(".toml"))r.push({file:{path:e(o),slug:pk(u,".toml"),catalog:c},name:u})}let s=(o="")=>{let a=n.findIndex((c)=>c.name===o);return a<0?n.length:a};return r.sort((o,a)=>s(o.file.catalog)-s(a.file.catalog)||Lh(o.file.catalog??"",a.file.catalog??"")||Lh(o.name,a.name)),i.sort((o,a)=>Lh(o.name,a.name)),[...r,...i].map(({file:o})=>o)}function ST(t){try{return Ye(t).catalogs}catch{return[]}}function wo(t,e=[]){let n=_u(t);if(!yT(n))return[];let r=mk(n,{withFileTypes:!0}).flatMap((i)=>i.isDirectory()?mk(ju(n,i.name)).map((s)=>`palettes/${i.name}/${s}`):[`palettes/${i.name}`]);return _h(r,(i)=>ju(t,i),e)}function ET(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 marketplace`;let r=t.catalog===void 0?void 0:Fa(t.catalog);return r?`the catalog folder ${JSON.stringify(t.catalog)} ${r}`:void 0}function Bh(t,e){let n=et(e);if(!n)throw Error(`${e} is an official palette — yours are named <you>@<marketplace>/<palette>`);let r=Vi(t,!1).find((s)=>s.id===n);if(!r)throw Error(`${n} is not a local marketplace — \`ttheme marketplace add <dir>\` adds the folder that holds it`);let i=ne(e);return wo(r.dir).find((s)=>s.slug===i)?.path??ju(_u(r.dir),`${i}.toml`)}function MT(t,e,n,r){let i=new Map(e.values().filter((s)=>!s.default&&!et(s.name)).map((s)=>[s.name,{order:s.order}]));return{name:t,...r.catalog===void 0?{}:{catalog:r.catalog},catalogs:new Map((r.catalogs??[]).map((s)=>[s.name,s])),bases:i,open:!0,...n?{foreign:!0}:{}}}function Ln(t,e,n,r=!1,i={}){let s=ne(t);return{...uh(`${s}.toml`,e,MT(s,n,r,i)),name:t}}function pe(t){return t?(e,n)=>process.stderr.write(`ttheme: skipping ${e} — ${n}
279
+ `):()=>{}}function Gh(t,e,n,r,i,s=!1,o=[]){let a=new Map;return t.flatMap((c)=>{try{let u=ET(c,a);if(u)throw Error(u);a.set(c.slug,c);let f={...c.catalog===void 0?{}:{catalog:c.catalog},catalogs:o};return[dn(Ln(`${n}/${c.slug}`,e(c),r,s,f))]}catch(u){return i(c.path,u.message),[]}})}function Cn(t,e,n,r=pe(!0)){let i=ST(t);return Gh(wo(t,i),(s)=>vT(s.path,"utf8"),e,n,r,!1,i)}function Bu(t,e,n=!0){return Vi(t,n).flatMap(({dir:r,id:i})=>Cn(r,i,e,pe(n)))}function Uh(t,e=t.name,n){return{name:e,...t.base?{base:t.base}:{},...t.catalog?{catalog:t.catalog}:{},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 Lt=(t)=>JSON.stringify(t);function bk(t){return["[[picture]]",`site = ${Lt(t.site)}`,`id = ${t.id}`,...t.size===void 0?[]:[`size = ${typeof t.size==="number"?t.size:Lt(t.size)}`],...t.position===void 0?[]:[`position = ${Lt(t.position)}`],...t.opacity===void 0?[]:[`opacity = ${t.opacity}`]]}function wk(t,e){return e.length===0?t:`${t.replace(/\n*$/,`
259
280
  `)}${e.map((n)=>`
260
- ${ok(n).join(`
281
+ ${bk(n).join(`
261
282
  `)}
262
- `).join("")}`}function Nh(t){let e=[`"$schema" = ${Lt(V$)}`,"","[meta]",`name = ${Lt(te(t.name))}`,...t.base?[`base = ${Lt(t.base)}`]:[],...t.ansiSource?[`ansi_source = ${Lt(t.ansiSource)}`]:[],...t.booru?[`booru = ${Lt(t.booru)}`]:[],`signature = [${t.signature.map(Lt).join(", ")}]`,...t.booruSites?["","[meta.booru_sites]",...Object.entries(t.booruSites).map(([n,r])=>`${n} = [${r.map(Lt).join(", ")}]`)]:[],"","[colors]",`background = ${Lt(t.background)}`,`foreground = ${Lt(t.foreground)}`,`cursor = ${Lt(t.cursor)}`,`selection_background = ${Lt(t.selection)}`,"ansi = [",...t.ansi.slice(0,8).map((n)=>` ${Lt(n)},`),"",...t.ansi.slice(8).map((n)=>` ${Lt(n)},`),"]"];if(t.waive&&t.waive.length>0)e.push("","[contrast]",`waive = [${t.waive.map(Lt).join(", ")}]`,`reason = ${Lt(t.reason??"")}`);for(let n of t.pictures??[])e.push("",...ok(n));return`${e.join(`
283
+ `).join("")}`}function Wh(t){return`${[`"$schema" = ${Lt(ak)}`,"","[meta]",`name = ${Lt(ne(t.name))}`,...t.base?[`base = ${Lt(t.base)}`]:[],...t.ansiSource?[`ansi_source = ${Lt(t.ansiSource)}`]:[],...t.booru?[`booru = ${Lt(t.booru)}`]:[],`signature = [${t.signature.map(Lt).join(", ")}]`,...t.booruSites?["","[meta.booru_sites]",...Object.entries(t.booruSites).map(([n,r])=>`${n} = [${r.map(Lt).join(", ")}]`)]:[],"","[colors]",`background = ${Lt(t.background)}`,`foreground = ${Lt(t.foreground)}`,`cursor = ${Lt(t.cursor)}`,`selection_background = ${Lt(t.selection)}`,"ansi = [",...t.ansi.slice(0,8).map((n)=>` ${Lt(n)},`),"",...t.ansi.slice(8).map((n)=>` ${Lt(n)},`),"]",...t.waive&&t.waive.length>0?["","[contrast]",`waive = [${t.waive.map(Lt).join(", ")}]`,`reason = ${Lt(t.reason??"")}`]:[],...(t.pictures??[]).flatMap((n)=>["",...bk(n)])].join(`
263
284
  `)}
264
- `}class ck{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(){let t=Buffer.from(this.bytes);return Buffer.concat([t,lk(t)]).toString("base64url")}}class uk{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");this.at+=t;try{return new TextDecoder("utf-8",{fatal:!0}).decode(e)}catch{throw Error("the share code holds text it cannot read — was it copied whole?")}}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 lk(t){return XN("sha256").update(t).digest().subarray(0,Ru)}function xh(t){return/^tt\d+:/.test(t)}function fk(t){return`${Oh}${t}`}function mo(t){let e=t.trim();if(!/^https?:\/\//i.test(e))return xh(e)?e:void 0;let r=(URL.canParse(e)?/^\/p\/([^/]+)\/?$/.exec(new URL(e).pathname)?.[1]:void 0)?.replace(/%3a/gi,":");return r&&xh(r)?r:void 0}function dk(t,e){let n=Hh(t),r=un(Nn(n.name,Nh(n),e,!0));return n.catalog?{...r,catalog:n.catalog}:r}function Th(t){let e=new ck;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(sk.indexOf(r));e.str(t.base),e.str(t.catalog),e.str(t.ansiSource),e.str(t.booru),e.u16((t.waive??[]).reduce((r,i)=>r|1<<md.indexOf(i),0)),e.str(t.waive&&t.waive.length>0?t.reason:"");let n=t.pictures??[];if(n.length>255)throw Error(`a share code carries at most 255 pictures, and ${t.name} holds ${n.length}`);e.u8(n.length);for(let r of n)e.u8(Z.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:Dt.indexOf(r.position)+1),e.u16(r.opacity===void 0?0:Math.round(r.opacity*1000)+1);return`${La}${e.done()}`}function Hh(t){if(!t.startsWith(La))throw Error(xh(t)?`this ttheme reads ${La} share codes, not ${t.slice(0,t.indexOf(":")+1)}`:`a share code starts with ${La}`);let e=t.slice(La.length);if(!/^[A-Za-z0-9_-]+$/.test(e))throw Error("the share code holds characters it never uses — was it copied whole?");let n=Buffer.from(e,"base64url");if(n.length<=Ru)throw Error("the share code is cut short");let r=n.subarray(0,-Ru);if(!lk(r).equals(n.subarray(-Ru)))throw Error("the share code does not add up — was it copied whole?");let i=new uk(new Uint8Array(r)),s=i.str(),[o,a,c,u,...f]=Array.from({length:20},()=>i.color()),l=[i.u8(),i.u8(),i.u8()].map((S)=>sk[S]??`slot${S}`),d=i.str(),h=i.str(),m=i.str(),g=i.str(),b=i.u16(),w=i.str(),k=md.filter((S,x)=>b&1<<x),v=Array.from({length:i.u8()},()=>{let S=Z[i.u8()]?.key??"unknown",x=i.u32(),M=i.u16(),N=i.u8(),C=i.u16();return{site:S,id:x,...M===1?{size:"fill"}:M>1?{size:M}:{},...N>0?{position:Dt[N-1]??"unknown"}:{},...C>0?{opacity:(C-1)/1000}:{}}});if(i.end(),![o,a,c,u,...f].every(ge))throw Error("the share code holds a color that is not one");return{name:s,...d?{base:d}:{},...h?{catalog:h}:{},...m?{ansiSource:m}:{},...g?{booru:g}:{},signature:l,background:o,foreground:a,cursor:c,selection:u,ansi:f,...k.length>0?{waive:k,reason:w}:{},...v.length>0?{pictures:v}:{}}}function po(t){return{background:t.background,foreground:t.foreground,cursor:t.cursor,selection:t.selectionBackground,ansi:t.ansi}}function Lh(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,()=>Lt(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"),(f,l)=>`${l}${Lt(u)}`),t.slice(0,n)+s+t.slice(r))}function hk(t,e){return t.replace(/^(signature\s*=\s*)\[[^\]]*\]/m,(n,r)=>`${r}[${e.map(Lt).join(", ")}]`)}function Fa(t){let e=vn(Le(t)),n=new Set(t.waived??[]),r=Math.max(...Ie.map((i)=>i.label.length));return Ie.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 iT,readFileSync as sT,rmSync as oT}from"node:fs";import{join as aT}from"node:path";var ja=["background","foreground","cursor","selection",...Array.from({length:16},(t,e)=>`ansi${e}`)],cT=1;function mk(t){return aT(t,"ttheme","tone.json")}function pk(t){return ja.includes(t)}function Kt(t){let e=mk(t);if(!iT(e))return{};let n;try{n=JSON.parse(sT(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(pk(c)&&typeof u==="string"&&ge(u.toLowerCase()))a[c]=u.toLowerCase();if(Object.keys(a).length>0)i[s]=a}return i}function _a(t,e){let n=mk(t),r=Object.fromEntries(Object.entries(e).filter(([,i])=>Object.keys(i).length>0));if(Object.keys(r).length===0){oT(n,{force:!0});return}L(n,`${JSON.stringify({version:cT,palettes:r},null,2)}
265
- `)}function Ca(t,e){if(e==="background"||e==="foreground"||e==="cursor"||e==="selection")return t[e];return t.ansi[Number(e.slice(4))]}function gk(t){return ja.map((e)=>Ca(t,e))}function Fh(t,e){let n={};return ja.forEach((r,i)=>{let s=e[i].toLowerCase();if(s!==Ca(t,r).toLowerCase())n[r]=s}),n}function Ga(t,e){if(!e)return t;let n=(u)=>e[u]===void 0||e[u]===Ca(t,u).toLowerCase();if(ja.every(n))return t;let r=(u)=>e[u]??Ca(t,u),i={background:r("background"),foreground:r("foreground"),cursor:r("cursor"),selection:r("selection"),ansi:ja.slice(4).map(r)},s=t.signatureSlots.map((u)=>pk(u)?r(u):Ca(i,u)),o={...t,...i,signature:s},a=Le(o),c=In({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:vn(a),backdrop:c}}function Tu(t,e){return Object.keys(e).length===0?t:t.map((n)=>Ga(n,e[n.name]))}function Hu(t,e,n){let r={...t};if(Object.keys(n).length===0)delete r[e];else r[e]=n;return r}function bk(t,e,n){let r=Kt(t);if(!Object.keys(r).some((s)=>e.has(s)||n.includes(s)))return;_a(t,Object.fromEntries(Object.entries(r).filter(([s])=>!n.includes(s)).map(([s,o])=>[e.get(s)??s,o])))}var uT=20000;function fn(t){return kk(t,"ttheme","official.json")}function yk(t,e){L(fn(t),`${JSON.stringify(e,null,2)}
266
- `)}function lt(t,e=!0,n){let r=lo(t),i=fn(t),s=Eu();if(r.includes(J))if(n)s=n;else{if(!$k(i))throw Error(`no official marketplace at ${i} — run \`ttheme init\` first`);s=Dr(Ch(i,"utf8"))}let o=r.filter(wt).flatMap((a)=>fT(t,a,s.palettes,e));return{...s,palettes:[...s.palettes,...o]}}function lT(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 marketplace this ttheme fetched — `ttheme update` fetches it again");return{...typeof e?.etag==="string"?{etag:e.etag}:{},files:n}}function ar(t,e){return lT(Ch(or(t,e),"utf8"))}function vk(t,e){return we({owner:ek(t),name:e.name})}function Sk(t,e){let n=e.files[ot];if(n===void 0)throw Error(`${st(t)} has no ${ot} — \`ttheme marketplace init\` makes one`);return Eh(n,ot)}function Lu(t,e){return vk(t,Sk(t,e))}function Vi(t,e,n,r){let i=Sk(t,e),s=vk(t,i),o=st(t),a=new Map(Object.entries(e.files).map(([u,f])=>[`${o}/${u}`,f])),c=Ph(Object.keys(e.files),(u)=>`${o}/${u}`);return{id:s,info:i,entries:Ih(c,(u)=>a.get(u.path)??"",s,n,r,!0)}}function fT(t,e,n,r){let i=or(t,e);if(!$k(i))return[];try{return Vi(e,ar(t,e),n,de(!1)).entries}catch(s){if(r)process.stderr.write(`ttheme: skipping ${i} — ${s.message}
267
- `);return[]}}function Dr(t){let e;try{e=JSON.parse(t)}catch{throw Error("the manifest is not valid JSON")}let n=e;if(typeof n?.version!=="string"||!Array.isArray(n.palettes))throw Error("the manifest has no version or palettes");for(let r of n.palettes){let i=Ek(r);if(i)throw Error(`manifest entry ${JSON.stringify(r?.name)} ${i}`)}return n}function Ek(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=ee(t.name)??(t.base===void 0?void 0:ee(t.base));if(e)return e;if(![t.background,t.foreground,t.cursor,t.selection,...t.ansi].every((n)=>typeof n==="string"&&ge(n)))return'holds a color that is not "#rrggbb"';for(let n of[t.native??"-",t.catalog??"-",t.ansiSource]){let r=typeof n==="string"?Ra(n):"has a field that is not text";if(r)return r}return}function Mk(t){return kk(t,"ttheme","kept.json")}function go(t,e){L(Mk(t),`${JSON.stringify({palettes:e},null,2)}
268
- `)}function Jr(t){try{let{palettes:e}=JSON.parse(Ch(Mk(t),"utf8"));return Array.isArray(e)?e.filter((n)=>Ek(n)===void 0):[]}catch{return[]}}function wk(t){return JSON.stringify([t.background,t.foreground,t.cursor,t.selection,t.ansi,t.pictures??[]])}function bo(t,e){let n=new Map(Jr(t).map((r)=>[r.name,r]));return e.palettes.filter((r)=>{let i=n.get(r.name);return et(r.name)!==void 0&&i!==void 0&&wk(i)!==wk(r)})}function cr(t,e,n=!0){let r=Jr(t),i=new Map(r.filter((a)=>et(a.name)!==void 0).map((a)=>[a.name,a])),s=[...e.palettes.map((a)=>i.get(a.name)??a),...Nu(t,e.palettes,n)],o=new Set(s.map((a)=>a.name));return{...e,palettes:[...s,...r.filter((a)=>!o.has(a.name))]}}function zt(t,e,n=!0){let r=cr(t,e,n);return{...r,palettes:Tu(r.palettes,Kt(t))}}function $e(t){return zt(t,lt(t))}class Fu extends Error{}class xk extends Error{}async function Ba(t,e=uT,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 Fu(`nothing at ${t}`);if(i.status===403||i.status===429)throw new xk(`${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}function Ua(t){let e=new Set(t.waived??[]),n=t.gate??vn(Le(t));return Ie.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 Hn(t,e){let n=t.find((r)=>r.name===e);if(!n)throw Error(`no palette named ${e} in your marketplaces — ${jh(t,[e])}`);return n}function jh(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)=>ne(o).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 Ok(t,e){return t.filter((n)=>Ki([n.name,ne(n),n.native??"",n.ansiSource,...n.nativeNames??[],...Ou(n.booru)],e))}function Pk(t,e,n){let r=n.toLowerCase(),i=(s)=>s.name===e.name?0:ne(s)===ne(e)?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 Rk(t,e){return t.booruSites?.[e]??(t.booru?[t.booru]:[])}var Ik=(()=>{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}})(),Ak=(t)=>{return t===12288||t>=65281&&t<=65376||t>=65504&&t<=65510},Nk=(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 dT=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,hT=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,Tk=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,mT=/\t{1,1000}/y,Hk=/[\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,pT=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,gT=/\p{M}+/gu,bT={limit:1/0,ellipsis:""},Lk=(t,e={},n={})=>{let r=e.limit??1/0,i=e.ellipsis??"",s=e?.ellipsisWidth??(i?Lk(i,bT,n).width:0),o=0,a=n.controlWidth??0,c=n.tabWidth??8,u=n.emojiWidth??2,f=2,l=n.regularWidth??1,d=n.wideWidth??2,h=[[pT,l],[dT,0],[hT,a],[mT,c],[Hk,u],[Tk,d]],m=0,g=0,b=t.length,w=0,k=!1,v=b,S=Math.max(0,r-s),x=0,M=0,N=0,C=0;t:while(!0){if(M>x||g>=b&&g>m){let P=t.slice(x,M)||t.slice(m,g);w=0;for(let _ of P.replaceAll(gT,"")){let K=_.codePointAt(0)||0;if(Ak(K))C=2;else if(Nk(K))C=d;else C=l;if(N+C>S)v=Math.min(v,Math.max(x,m)+w);if(N+C>r){k=!0;break t}w+=_.length,N+=C}x=M=0}if(g>=b)break t;for(let P=0,_=h.length;P<_;P++){let[K,B]=h[P];if(K.lastIndex=g,K.test(t)){if(w=K===Tk?Ik(t.slice(g,K.lastIndex)):K===Hk?1:K.lastIndex-g,C=w*B,N+C>S)v=Math.min(v,g+Math.floor((S-N)/B));if(N+C>r){k=!0;break t}N+=C,x=m,M=g,g=m=K.lastIndex;continue t}}g+=1}return{width:k?S:N,index:k?v:b,truncated:k,ellipsed:k&&r>=s}},Fk=Lk;var wT={limit:1/0,ellipsis:"",ellipsisWidth:0},$T=(t,e={})=>{return Fk(t,wT,e).width},G=$T;var Ck={dim:["2","22"],bold:["1","22"],under:["4","24"],reverse:["7","27"],accent:["36","39"],pill:["7;1;36","22;27;39"],match:["1;4;36","22;24;39"],ok:["32","39"],warn:["33","39"],error:["31","39"]},kT={stage:0.08,bar:0.14,selection:0.2,tab:0.3,line:0.45},I={gutter:"▌",current:"◆",signature:"✦",closed:"▸",opened:"▾",on:"●",off:"○",ok:"✓",miss:"✗",above:"↑",below:"↓",update:"⇡",auto:"↻",star:"★",link:"⧉",search:"⌕",linked:"⇠",contrast:"◐",swatch:"■",pictures:"▣",sep:"·",cut:"…"},ur=["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];function Fe(t){return`\x1B[${t}m`}function $t(t){return Fe(Ck[t][0])}function _h(t){return Fe(Ck[t][1])}var ke=Fe("0"),kt=Fe("39"),jk=Fe("49"),he=Fe("39;49");function Zi(t){return Fe(String(t<8?30+t:82+t))}function _k(t){return Fe(String(t<8?40+t:92+t))}function Gk(t,e){return Fe(`38;5;${t};48;5;${e}`)}function Cu(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 lr(t){return Fe(`38;2;${Cu(t)}`)}function Gh(t){return Fe(`48;2;${Cu(t)}`)}function Bk(t,e){return Fe(`48;2;${Cu(t)};38;2;${Cu(e)}`)}function ju(t,e=kt){return`${t.map((n)=>`${lr(n)}${I.swatch}`).join(" ")}${e}`}function Xi(t,e,n){return Tt(t,e,kT[n])}function Bh(t){let e=!1,n=!1,r=!1,i=!1,s=!1,o=!1;for(let c of t.split("\x1B[").slice(1)){let u=/^([0-9;]*)m/.exec(c)?.[1];if(u===void 0)continue;let f=(u||"0").split(";").map(Number);for(let l=0;l<f.length;l++){let d=f[l];if(d===0)e=n=r=i=s=o=!1;else if(d===1||d===2)e=!0;else if(d===22)e=!1;else if(d===3||d===23)n=d===3;else if(d===4||d===24)r=d===4;else if(d===7||d===27)i=d===7;else if(d===38||d===48)s||=d===38,o||=d===48,l+=f[l+1]===5?2:4;else if(d===39)s=!1;else if(d===49)o=!1;else if(d>=30&&d<=37||d>=90&&d<=97)s=!0;else if(d>=40&&d<=47||d>=100&&d<=107)o=!0}}let a=[e&&"22",n&&"23",r&&"24",i&&"27",s&&"39",o&&"49"].filter(Boolean);return a.length>0?Fe(a.join(";")):""}function Ce(t){let e=(n)=>(r)=>t?`${$t(n)}${r}${_h(n)}`:r;return{color:t,dim:e("dim"),bold:e("bold"),accent:e("accent"),pill:e("pill"),ok:e("ok"),warn:e("warn"),error:e("error"),fg:(n)=>t?lr(n):"",bg:(n)=>t?Gh(n):""}}function _u(t,e){return e&&!/\p{Cc}/u.test(e)?`\x1B]8;;${e}\x1B\\${t}\x1B]8;;\x1B\\`:t}function Uh(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}var Uk;function Wh(t){return Uk??=new Intl.Segmenter(void 0,{granularity:"grapheme"}),Uk.segment(t)}function wo(t){let e=[],n=0;while(n<t.length){let r=Uh(t,n);if(r>0){e.push({text:t.slice(n,n+r),start:n,end:n+r,width:0,sequence:!0}),n+=r;continue}let i=t.indexOf("\x1B",n+1),s=i===-1?t.length:i;for(let{segment:o,index:a}of Wh(t.slice(n,s)))e.push({text:o,start:n+a,end:n+a+o.length,width:G(o),sequence:!1});n=s}return e}function yT(t){let e=t.slice(3,-1);return t.startsWith("\x1B[?")&&t.endsWith("y")&&/^\d{1,4}$/.test(e)?e:void 0}function Kh(t,e){let n="",r=0,i=0;for(let s of wo(t)){if(!s.sequence){if(r+s.width>e)break;r+=s.width}else{let o=yT(s.text);if(o!==void 0)i=o==="0"?Math.max(0,i-1):i+1}n+=s.text}return{head:n,used:r,ends:"\x1B[?0y".repeat(i)}}function tt(t,e,n=!0){if(e<=0)return"";let r=G(t);if(r<=e)return n?t+" ".repeat(e-r):t;let{head:i,used:s,ends:o}=Kh(t,e-1);return`${i}${Bh(i)}…${o}${n?" ".repeat(e-1-s):""}`}function Wk(t,e){let{head:n,used:r,ends:i}=Kh(t,e);return`${n}${Bh(n)}${i}${" ".repeat(e-r)}`}function At(t,e,n){let r=n-G(e)-1;return r<=0?tt(t,n):`${tt(t,r)} ${e}`}function vt(t,e){let n=[],r="";for(let i of t.split(/\s+/).filter(Boolean)){let s=r?`${r} ${i}`:i;if(G(s)<=e){r=s;continue}if(r)n.push(r);while(G(i)>e){let{head:o}=Kh(i,e),a=Math.max(o.lastIndexOf("/")+1,o.lastIndexOf("#")),c=a>0?a:o.length||wo(i)[0].end;n.push(i.slice(0,c)),i=i.slice(c)}r=i}if(r)n.push(r);return n}var vT=9999,$o;function dn(t,e){if(!$o||e===""||$o.length>=vT)return e;return`\x1B[?${$o.push(t)}y${e}\x1B[?0y`}function zk(t){let e=$o,n=[];$o=n;try{return{drawn:t(),targets:n}}finally{$o=e}}function qk(t){let e=t.slice(3,-1);return t.startsWith("\x1B[?")&&t.endsWith("y")&&/^\d{1,4}$/.test(e)?Number(e):void 0}function ST(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 ET(t,e,n){if(!t.includes("\x1B[?"))return{text:t,zones:[]};let r=[],i=[],s="",o=0,a="",c=()=>{let f=i.pop();if(f&&o>f.col)r.push({row:e,col:f.col,width:o-f.col,height:1,target:f.target})},u=0;while(u<t.length){let f=t.indexOf("\x1B",u);if(f!==u){let m=f===-1?t.length:f;a+=t.slice(u,m),s+=t.slice(u,m),u=m;continue}let l=t.slice(u,u+(Uh(t,u)||1));u+=l.length;let d=qk(l),h=d===void 0?ST(l):void 0;if(d===void 0&&h===void 0){s+=l;continue}if(o+=G(a),a="",h!==void 0)o=h,s+=l;else if(d===0)c();else if(d!==void 0)i.push({target:n[d-1],col:o})}o+=G(a);while(i.length>0)c();return{text:s,zones:r}}function Dk(t,e,n){let r=[],i=[],s="",o=(b)=>{let w=qk(b);if(w===0)r.pop();else if(w!==void 0)r.push(b);else if(b.startsWith("\x1B]8;"))s=b.slice(b.indexOf(";",4)+1).replace("\x07","").replace("\x1B\\","")===""?"":b;else if(b.startsWith("\x1B[")&&b.endsWith("m"))i.push(b)},a=t.includes("\x1B")||n.includes("\x1B")?ke:"",c=wo(t),u="",f=0,l=0;while(l<c.length&&f<e){let b=c[l];if(b.sequence)o(b.text);else if(f+b.width>e)break;else f+=b.width;u+=b.text,l++}u+=" ".repeat(e-Math.min(e,f));let d=`${"\x1B[?0y".repeat(r.length)}${s?"\x1B]8;;\x1B\\":""}${a}`,h=e+G(n);while(l<c.length&&f<h){let b=c[l];if(b.sequence)o(b.text);else f+=b.width;l++}let m=l<c.length?t.slice(c[l].start):"";if(m===""&&f<=h)return`${u}${d}${n}${a}`;let g=`${i.join("")}${s}${r.join("")}${" ".repeat(Math.max(0,f-h))}`;return`${u}${d}${n}${a}${g}${m}`}function Jk(t,e){let n=[];return{lines:t.map((i,s)=>{let o=ET(i,s,e);return n.push(...o.zones),o.text}),zones:n}}function Kk(t,e,n,r=0.5,i=0.5){let s=n-t.col,o=e-t.row;return{target:t.target,x:s,y:o,exact:{x:s+r,y:o+i},width:t.width,height:t.height,inside:s>=0&&s<t.width&&o>=0&&o<t.height}}function MT(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 xT={space:" ",enter:"enter",esc:"esc",tab:"tab",bksp:"backspace",del:"delete","←":"left","→":"right"};function zh(t){let e=/^(ctrl|alt)\+([a-z])$/.exec(t);if(e)return`${e[1]}-${e[2]}`;return xT[t]??([...t].length===1&&t!==" "?t:void 0)}function me(t,e){let n=zh(t);return n?dn({kind:"key",key:n},e):e}class qh{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&&Kk(n,t.row,t.col,t.fx,t.fy)}let e=MT(this.zones,t.row,t.col);if(t.action==="press")this.held=t.button==="left"?e:void 0;return e&&Kk(e,t.row,t.col,t.fx,t.fy)}drop(){this.held=void 0}}function Gu(t,e,n,r=(i)=>i){if(!t.color)return r(n?`[${e}]`:` ${e} `);return n?t.pill(r(` ${e} `)):t.dim(r(` ${e} `))}function Ye(t,e){return t.color?t.pill(` ${e} `):`[${e}]`}function Yk(t,e,n){return me(e.split(" ")[0]??"",`${t.bold(e)} ${t.dim(n)}`)}function Bu(t,e){return e===void 0?t.dim(I.sep):e?t.dim(I.ok):t.bold(I.miss)}var OT={top:"╭╮",mid:"├┤",bottom:"╰╯"};function Gt(t,e,n=[]){let[r,i]=[...OT[e]],s=[...`${r}${"─".repeat(Math.max(0,t-2))}${i}`];for(let[o,a]of n)[...a].forEach((c,u)=>{if(o+u>0&&o+u<t-1)s[o+u]=c});return s.join("")}function Ve(t,e,n){return`${t.dim("│")}${tt(e,n-2)}${t.dim("│")}`}var fr=[{name:"preview",title:"Preview"},{name:"browse",title:"Browse"}],Uu=10,Wu=20;function Vk(t){return fr.find((e)=>e.name===t.TTHEME_HUB)?.name}function Dh(t,e){let n=fr.findIndex((r)=>r.name===t);return Wu+(n+e+fr.length)%fr.length+1}function Zk(t){return Wu+fr.findIndex((e)=>e.name===t)+1}function Jh(t,e){let n=Ce(e);return` ${fr.map(({name:i,title:s})=>{let o={kind:"hub",tab:i};return Gu(n,s,i===t,(a)=>dn(o,a))}).join(" ")} ${n.dim("tab next")}`}import{execFileSync as jF}from"node:child_process";import{existsSync as Hl,mkdirSync as _F,readdirSync as GF,readFileSync as Ll,rmSync as BF}from"node:fs";import{basename as Wv,join as uc,relative as Gv}from"node:path";import{styleText as Ju}from"node:util";import{stdout as cy,stdin as LT}from"node:process";import FT from"node:readline";var Ku="\x1B",ny="›",PT=39,Vh="\x07",ry="[",RT="]",iy="m",Zh=`${RT}8;;`,Xk=new RegExp(`(?:\\${ry}(?<code>\\d+)m|\\${Zh}(?<uri>.*)${Vh})`,"y"),Qk=(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},ty=(t)=>`${Ku}${ry}${t}${iy}`,ey=(t)=>`${Ku}${Zh}${t}${Vh}`,Yh=(t,e,n)=>{let r=e[Symbol.iterator](),i=!1,s=!1,o=t.at(-1),a=o===void 0?0:G(o),c=r.next(),u=r.next(),f=0;while(!c.done){let l=c.value,d=G(l);if(a+d<=n)t[t.length-1]+=l;else t.push(l),a=0;if(l===Ku||l===ny)i=!0,s=e.startsWith(Zh,f+1);if(i){if(s){if(l===Vh)i=!1,s=!1}else if(l===iy)i=!1}else if(a+=d,a===n&&!u.done)t.push(""),a=0;c=u,u=r.next(),f+=l.length}if(o=t.at(-1),!a&&o!==void 0&&o.length&&t.length>1)t[t.length-2]+=t.pop()},IT=(t)=>{let e=t.split(" "),n=e.length;while(n){if(G(e[n-1]))break;n--}if(n===e.length)return t;return e.slice(0,n).join(" ")+e.slice(n).join("")},AT=(t,e,n={})=>{if(n.trim!==!1&&t.trim()==="")return"";let r="",i,s,o=t.split(" "),a=[""],c=0;for(let l=0;l<o.length;l++){let d=o[l];if(n.trim!==!1){let m=a.at(-1)??"",g=m.trimStart();if(m.length!==g.length)a[a.length-1]=g,c=G(g)}if(l!==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=G(d);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("");Yh(a,d,e),c=G(a.at(-1)??"");continue}if(c+h>e&&c&&h){if(n.wordWrap===!1&&c<e){Yh(a,d,e),c=G(a.at(-1)??"");continue}a.push(""),c=0}if(c+h>e&&n.wordWrap===!1){Yh(a,d,e),c=G(a.at(-1)??"");continue}a[a.length-1]+=d,c+=h}if(n.trim!==!1)a=a.map((l)=>IT(l));let u=a.join(`
269
- `),f=!1;for(let l=0;l<u.length;l++){let d=u[l];if(r+=d,!f){if(f=d>="\uD800"&&d<="\uDBFF",f)continue}else f=!1;if(d===Ku||d===ny){Xk.lastIndex=l+1;let m=Xk.exec(u)?.groups;if(m?.code!==void 0){let g=Number.parseFloat(m.code);i=g===PT?void 0:g}else if(m?.uri!==void 0)s=m.uri.length===0?void 0:m.uri}if(u[l+1]===`
270
- `){if(s)r+=ey("");let h=i?Qk(i):void 0;if(i&&h)r+=ty(h)}else if(d===`
271
- `){if(i&&Qk(i))r+=ty(i);if(s)r+=ey(s)}}return r},NT=/\r?\n/;function Yr(t,e,n){return String(t).normalize().split(NT).map((r)=>AT(r,e,n)).join(`
272
- `)}var je=ld(Qh(),1);function dr(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?dr(s,e<0?-1:1,n):s}function zu(t,e,n,r){let i=r.split(`
273
- `),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 CT=["up","down","left","right","space","enter","cancel"],jT=["January","February","March","April","May","June","July","August","September","October","November","December"],Bt={actions:new Set(CT),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0,accessible:void 0,date:{monthNames:[...jT],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 _T(t){if(t!==void 0)return t;if(Bt.accessible!==void 0)return Bt.accessible;let e=process.env.ACCESSIBLE;return e!==void 0&&e!==""&&e!=="0"&&e!=="false"}function uy(t,e){if(typeof t=="string")return Bt.aliases.get(t)===e;for(let n of t)if(n!==void 0&&uy(n,e))return!0;return!1}function GT(t,e){if(t===e)return;let n=t.split(`
285
+ `}class $k{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(){let t=Buffer.from(this.bytes);return Buffer.concat([t,yk(t)]).toString("base64url")}}class kk{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");this.at+=t;try{return new TextDecoder("utf-8",{fatal:!0}).decode(e)}catch{throw Error("the share code holds text it cannot read — was it copied whole?")}}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 yk(t){return kT("sha256").update(t).digest().subarray(0,Cu)}function Ch(t){return/^tt\d+:/.test(t)}function vk(t){return`${jh}${t}`}function $o(t){let e=t.trim();if(!/^https?:\/\//i.test(e))return Ch(e)?e:void 0;let r=(URL.canParse(e)?/^\/p\/([^/]+)\/?$/.exec(new URL(e).pathname)?.[1]:void 0)?.replace(/%3a/gi,":");return r&&Ch(r)?r:void 0}function Sk(t,e){let n=zh(t),r=dn(Ln(n.name,Wh(n),e,!0));return n.catalog?{...r,catalog:n.catalog}:r}function Kh(t){let e=new $k;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(gk.indexOf(r));e.str(t.base),e.str(t.catalog),e.str(t.ansiSource),e.str(t.booru),e.u16((t.waive??[]).reduce((r,i)=>r|1<<kd.indexOf(i),0)),e.str(t.waive&&t.waive.length>0?t.reason:"");let n=t.pictures??[];if(n.length>255)throw Error(`a share code carries at most 255 pictures, and ${t.name} holds ${n.length}`);e.u8(n.length);for(let r of n)e.u8(Z.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:Jt.indexOf(r.position)+1),e.u16(r.opacity===void 0?0:Math.round(r.opacity*1000)+1);return`${Ga}${e.done()}`}function zh(t){if(!t.startsWith(Ga))throw Error(Ch(t)?`this ttheme reads ${Ga} share codes, not ${t.slice(0,t.indexOf(":")+1)}`:`a share code starts with ${Ga}`);let e=t.slice(Ga.length);if(!/^[A-Za-z0-9_-]+$/.test(e))throw Error("the share code holds characters it never uses — was it copied whole?");let n=Buffer.from(e,"base64url");if(n.length<=Cu)throw Error("the share code is cut short");let r=n.subarray(0,-Cu);if(!yk(r).equals(n.subarray(-Cu)))throw Error("the share code does not add up — was it copied whole?");let i=new kk(new Uint8Array(r)),s=i.str(),[o,a,c,u,...f]=Array.from({length:20},()=>i.color()),l=[i.u8(),i.u8(),i.u8()].map((S)=>gk[S]??`slot${S}`),d=i.str(),h=i.str(),m=i.str(),p=i.str(),b=i.u16(),$=i.str(),k=kd.filter((S,x)=>b&1<<x),v=Array.from({length:i.u8()},()=>{let S=Z[i.u8()]?.key??"unknown",x=i.u32(),M=i.u16(),N=i.u8(),C=i.u16();return{site:S,id:x,...M===1?{size:"fill"}:M>1?{size:M}:{},...N>0?{position:Jt[N-1]??"unknown"}:{},...C>0?{opacity:(C-1)/1000}:{}}});if(i.end(),![o,a,c,u,...f].every($e))throw Error("the share code holds a color that is not one");return{name:s,...d?{base:d}:{},...h?{catalog:h}:{},...m?{ansiSource:m}:{},...p?{booru:p}:{},signature:l,background:o,foreground:a,cursor:c,selection:u,ansi:f,...k.length>0?{waive:k,reason:$}:{},...v.length>0?{pictures:v}:{}}}function ko(t){return{background:t.background,foreground:t.foreground,cursor:t.cursor,selection:t.selectionBackground,ansi:t.ansi}}function qh(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,()=>Lt(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"),(f,l)=>`${l}${Lt(u)}`),t.slice(0,n)+s+t.slice(r))}function Ek(t,e){return t.replace(/^(signature\s*=\s*)\[[^\]]*\]/m,(n,r)=>`${r}[${e.map(Lt).join(", ")}]`)}function Ua(t){let e=xn(Le(t)),n=new Set(t.waived??[]),r=Math.max(...Te.map((i)=>i.label.length));return Te.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 xT,readFileSync as OT,rmSync as PT}from"node:fs";import{join as IT}from"node:path";var Ka=["background","foreground","cursor","selection",...Array.from({length:16},(t,e)=>`ansi${e}`)],RT=1;function Mk(t){return IT(t,"ttheme","tone.json")}function xk(t){return Ka.includes(t)}function zt(t){let e=Mk(t);if(!xT(e))return{};let n;try{n=JSON.parse(OT(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(xk(c)&&typeof u==="string"&&$e(u.toLowerCase()))a[c]=u.toLowerCase();if(Object.keys(a).length>0)i[s]=a}return i}function za(t,e){let n=Mk(t),r=Object.fromEntries(Object.entries(e).filter(([,i])=>Object.keys(i).length>0));if(Object.keys(r).length===0){PT(n,{force:!0});return}H(n,`${JSON.stringify({version:RT,palettes:r},null,2)}
286
+ `)}function Wa(t,e){if(e==="background"||e==="foreground"||e==="cursor"||e==="selection")return t[e];return t.ansi[Number(e.slice(4))]}function Ok(t){return Ka.map((e)=>Wa(t,e))}function Dh(t,e){return Object.fromEntries(Ka.flatMap((n,r)=>{let i=e[r].toLowerCase();return i===Wa(t,n).toLowerCase()?[]:[[n,i]]}))}function qa(t,e){if(!e)return t;let n=(u)=>e[u]===void 0||e[u]===Wa(t,u).toLowerCase();if(Ka.every(n))return t;let r=(u)=>e[u]??Wa(t,u),i={background:r("background"),foreground:r("foreground"),cursor:r("cursor"),selection:r("selection"),ansi:Ka.slice(4).map(r)},s=t.signatureSlots.map((u)=>xk(u)?r(u):Wa(i,u)),o={...t,...i,signature:s},a=Le(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:xn(a),backdrop:c}}function Gu(t,e){return Object.keys(e).length===0?t:t.map((n)=>qa(n,e[n.name]))}function Uu(t,e,n){let r={...t};if(Object.keys(n).length===0)delete r[e];else r[e]=n;return r}function Pk(t,e,n){let r=zt(t);if(!Object.keys(r).some((s)=>e.has(s)||n.includes(s)))return;za(t,Object.fromEntries(Object.entries(r).filter(([s])=>!n.includes(s)).map(([s,o])=>[e.get(s)??s,o])))}var AT=20000;function mn(t){return Ak(t,"ttheme","official.json")}function Nk(t,e){H(mn(t),`${JSON.stringify(e,null,2)}
287
+ `)}function lt(t,e=!0,n){let r=go(t),i=mn(t),s=Nu();if(r.includes(J))if(n)s=n;else{if(!Rk(i))throw Error(`no official marketplace at ${i} — run \`ttheme init\` first`);s=Xr(Jh(i,"utf8"))}let o=r.filter(wt).flatMap((a)=>TT(t,a,s.palettes,e));return{...s,palettes:[...s.palettes,...o]}}function NT(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 marketplace this ttheme fetched — `ttheme update` fetches it again");return{...typeof e?.etag==="string"?{etag:e.etag}:{},files:n}}function dr(t,e){return NT(Jh(fr(t,e),"utf8"))}function Tk(t,e){return ye({owner:dk(t),name:e.name})}function Hk(t,e){let n=e.files[ot];if(n===void 0)throw Error(`${st(t)} has no ${ot} — \`ttheme marketplace init\` makes one`);return Fh(n,ot)}function Wu(t,e){return Tk(t,Hk(t,e))}function Zi(t,e,n,r){let i=Hk(t,e),s=Tk(t,i),o=st(t),a=new Map(Object.entries(e.files).map(([u,f])=>[`${o}/${u}`,f])),c=_h(Object.keys(e.files),(u)=>`${o}/${u}`);return{id:s,info:i,entries:Gh(c,(u)=>a.get(u.path)??"",s,n,r,!0)}}function TT(t,e,n,r){let i=fr(t,e);if(!Rk(i))return[];try{return Zi(e,dr(t,e),n,pe(!1)).entries}catch(s){if(r)process.stderr.write(`ttheme: skipping ${i} — ${s.message}
288
+ `);return[]}}function Xr(t){let e;try{e=JSON.parse(t)}catch{throw Error("the manifest is not valid JSON")}let n=e;if(typeof n?.version!=="string"||!Array.isArray(n.palettes))throw Error("the manifest has no version or palettes");for(let r of n.palettes){let i=Fk(r);if(i)throw Error(`manifest entry ${JSON.stringify(r?.name)} ${i}`)}return n}function Fk(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=re(t.name)??(t.base===void 0?void 0:re(t.base));if(e)return e;if(![t.background,t.foreground,t.cursor,t.selection,...t.ansi].every((n)=>typeof n==="string"&&$e(n)))return'holds a color that is not "#rrggbb"';return[t.native??"-",t.catalog??"-",t.ansiSource].values().map((n)=>typeof n==="string"?Fa(n):"has a field that is not text").find(Boolean)}function Lk(t){return Ak(t,"ttheme","kept.json")}function yo(t,e){H(Lk(t),`${JSON.stringify({palettes:e},null,2)}
289
+ `)}function Qr(t){try{let{palettes:e}=JSON.parse(Jh(Lk(t),"utf8"));return Array.isArray(e)?e.filter((n)=>Fk(n)===void 0):[]}catch{return[]}}function Ik(t){return JSON.stringify([t.background,t.foreground,t.cursor,t.selection,t.ansi,t.pictures??[]])}function vo(t,e){let n=new Map(Qr(t).map((r)=>[r.name,r]));return e.palettes.filter((r)=>{let i=n.get(r.name);return et(r.name)!==void 0&&i!==void 0&&Ik(i)!==Ik(r)})}function hr(t,e,n=!0){let r=Qr(t),i=new Map(r.filter((a)=>et(a.name)!==void 0).map((a)=>[a.name,a])),s=[...e.palettes.map((a)=>i.get(a.name)??a),...Bu(t,e.palettes,n)],o=new Set(s.map((a)=>a.name));return{...e,palettes:[...s,...r.filter((a)=>!o.has(a.name))]}}function qt(t,e,n=!0){let r=hr(t,e,n);return{...r,palettes:Gu(r.palettes,zt(t))}}function ve(t){return qt(t,lt(t))}class Ku extends Error{}class Ck extends Error{}async function Da(t,e=AT,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 Ku(`nothing at ${t}`);if(i.status===403||i.status===429)throw new Ck(`${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}function Ja(t){let e=new Set(t.waived??[]),n=t.gate??xn(Le(t));return Te.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 jn(t,e){let n=t.find((r)=>r.name===e);if(!n)throw Error(`no palette named ${e} in your marketplaces — ${Yh(t,[e])}`);return n}function Yh(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)=>ie(o).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 jk(t,e){return t.filter((n)=>zi([n.name,ie(n),n.native??"",n.ansiSource,...n.nativeNames??[],...Fu(n.booru)],e))}function _k(t,e,n){let r=n.toLowerCase(),i=(s)=>s.name===e.name?0:ie(s)===ie(e)?1:2;return t.filter((s)=>s.booru?.toLowerCase().includes(r)).sort((s,o)=>i(s)-i(o))}function Bk(t,e){return t.booruSites?.[e]??(t.booru?[t.booru]:[])}var Gk=(()=>{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}})(),Uk=(t)=>{return t===12288||t>=65281&&t<=65376||t>=65504&&t<=65510},Wk=(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 HT=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,FT=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,Kk=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,LT=/\t{1,1000}/y,zk=/[\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,CT=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,jT=/\p{M}+/gu,_T={limit:1/0,ellipsis:""},qk=(t,e={},n={})=>{let r=e.limit??1/0,i=e.ellipsis??"",s=e?.ellipsisWidth??(i?qk(i,_T,n).width:0),o=0,a=n.controlWidth??0,c=n.tabWidth??8,u=n.emojiWidth??2,f=2,l=n.regularWidth??1,d=n.wideWidth??2,h=[[CT,l],[HT,0],[FT,a],[LT,c],[zk,u],[Kk,d]],m=0,p=0,b=t.length,$=0,k=!1,v=b,S=Math.max(0,r-s),x=0,M=0,N=0,C=0;t:while(!0){if(M>x||p>=b&&p>m){let I=t.slice(x,M)||t.slice(m,p);$=0;for(let j of I.replaceAll(jT,"")){let U=j.codePointAt(0)||0;if(Uk(U))C=2;else if(Wk(U))C=d;else C=l;if(N+C>S)v=Math.min(v,Math.max(x,m)+$);if(N+C>r){k=!0;break t}$+=j.length,N+=C}x=M=0}if(p>=b)break t;for(let I=0,j=h.length;I<j;I++){let[U,G]=h[I];if(U.lastIndex=p,U.test(t)){if($=U===Kk?Gk(t.slice(p,U.lastIndex)):U===zk?1:U.lastIndex-p,C=$*G,N+C>S)v=Math.min(v,p+Math.floor((S-N)/G));if(N+C>r){k=!0;break t}N+=C,x=m,M=p,p=m=U.lastIndex;continue t}}p+=1}return{width:k?S:N,index:k?v:b,truncated:k,ellipsed:k&&r>=s}},Dk=qk;var BT={limit:1/0,ellipsis:"",ellipsisWidth:0},GT=(t,e={})=>{return Dk(t,BT,e).width},B=GT;var Jk={dim:["2","22"],bold:["1","22"],under:["4","24"],reverse:["7","27"],accent:["36","39"],pill:["7;1;36","22;27;39"],match:["1;4;36","22;24;39"],ok:["32","39"],warn:["33","39"],error:["31","39"]},UT={stage:0.08,bar:0.14,selection:0.2,tab:0.3,line:0.45},R={gutter:"▌",current:"◆",signature:"✦",closed:"▸",opened:"▾",on:"●",off:"○",ok:"✓",miss:"✗",above:"↑",below:"↓",update:"⇡",auto:"↻",star:"★",link:"⧉",search:"⌕",linked:"⇠",contrast:"◐",swatch:"■",pictures:"▣",sep:"·",cut:"…"},mr=["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];function Ce(t){return`\x1B[${t}m`}function $t(t){return Ce(Jk[t][0])}function Vh(t){return Ce(Jk[t][1])}var Se=Ce("0"),kt=Ce("39"),Yk=Ce("49"),ge=Ce("39;49");function Xi(t){return Ce(String(t<8?30+t:82+t))}function Vk(t){return Ce(String(t<8?40+t:92+t))}function Zk(t,e){return Ce(`38;5;${t};48;5;${e}`)}function zu(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 pr(t){return Ce(`38;2;${zu(t)}`)}function Zh(t){return Ce(`48;2;${zu(t)}`)}function Xk(t,e){return Ce(`48;2;${zu(t)};38;2;${zu(e)}`)}function qu(t,e=kt){return`${t.map((n)=>`${pr(n)}${R.swatch}`).join(" ")}${e}`}function Qi(t,e,n){return Ht(t,e,UT[n])}function Xh(t){let e=!1,n=!1,r=!1,i=!1,s=!1,o=!1;for(let c of t.split("\x1B[").slice(1)){let u=/^([0-9;]*)m/.exec(c)?.[1];if(u===void 0)continue;let f=(u||"0").split(";").map(Number);for(let l=0;l<f.length;l++){let d=f[l];if(d===0)e=n=r=i=s=o=!1;else if(d===1||d===2)e=!0;else if(d===22)e=!1;else if(d===3||d===23)n=d===3;else if(d===4||d===24)r=d===4;else if(d===7||d===27)i=d===7;else if(d===38||d===48)s||=d===38,o||=d===48,l+=f[l+1]===5?2:4;else if(d===39)s=!1;else if(d===49)o=!1;else if(d>=30&&d<=37||d>=90&&d<=97)s=!0;else if(d>=40&&d<=47||d>=100&&d<=107)o=!0}}let a=[e&&"22",n&&"23",r&&"24",i&&"27",s&&"39",o&&"49"].filter(Boolean);return a.length>0?Ce(a.join(";")):""}function je(t){let e=(n)=>(r)=>t?`${$t(n)}${r}${Vh(n)}`:r;return{color:t,dim:e("dim"),bold:e("bold"),accent:e("accent"),pill:e("pill"),ok:e("ok"),warn:e("warn"),error:e("error"),fg:(n)=>t?pr(n):"",bg:(n)=>t?Zh(n):""}}function Du(t,e){return e&&!/\p{Cc}/u.test(e)?`\x1B]8;;${e}\x1B\\${t}\x1B]8;;\x1B\\`:t}function Qh(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}var Qk;function tm(t){return Qk??=new Intl.Segmenter(void 0,{granularity:"grapheme"}),Qk.segment(t)}function So(t){let e=[],n=0;while(n<t.length){let r=Qh(t,n);if(r>0){e.push({text:t.slice(n,n+r),start:n,end:n+r,width:0,sequence:!0}),n+=r;continue}let i=t.indexOf("\x1B",n+1),s=i===-1?t.length:i;for(let{segment:o,index:a}of tm(t.slice(n,s)))e.push({text:o,start:n+a,end:n+a+o.length,width:B(o),sequence:!1});n=s}return e}function WT(t){let e=t.slice(3,-1);return t.startsWith("\x1B[?")&&t.endsWith("y")&&/^\d{1,4}$/.test(e)?e:void 0}function em(t,e){let n="",r=0,i=0;for(let s of So(t)){if(!s.sequence){if(r+s.width>e)break;r+=s.width}else{let o=WT(s.text);if(o!==void 0)i=o==="0"?Math.max(0,i-1):i+1}n+=s.text}return{head:n,used:r,ends:"\x1B[?0y".repeat(i)}}function tt(t,e,n=!0){if(e<=0)return"";let r=B(t);if(r<=e)return n?t+" ".repeat(e-r):t;let{head:i,used:s,ends:o}=em(t,e-1);return`${i}${Xh(i)}…${o}${n?" ".repeat(e-1-s):""}`}function ty(t,e){let{head:n,used:r,ends:i}=em(t,e);return`${n}${Xh(n)}${i}${" ".repeat(e-r)}`}function Nt(t,e,n){let r=n-B(e)-1;return r<=0?tt(t,n):`${tt(t,r)} ${e}`}function vt(t,e){let n=[],r="";for(let i of t.split(/\s+/).filter(Boolean)){let s=r?`${r} ${i}`:i;if(B(s)<=e){r=s;continue}if(r)n.push(r);while(B(i)>e){let{head:o}=em(i,e),a=Math.max(o.lastIndexOf("/")+1,o.lastIndexOf("#")),c=a>0?a:o.length||So(i)[0].end;n.push(i.slice(0,c)),i=i.slice(c)}r=i}if(r)n.push(r);return n}var KT=9999,Eo;function pn(t,e){if(!Eo||e===""||Eo.length>=KT)return e;return`\x1B[?${Eo.push(t)}y${e}\x1B[?0y`}function ny(t){let e=Eo,n=[];Eo=n;try{return{drawn:t(),targets:n}}finally{Eo=e}}function ry(t){let e=t.slice(3,-1);return t.startsWith("\x1B[?")&&t.endsWith("y")&&/^\d{1,4}$/.test(e)?Number(e):void 0}function zT(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 qT(t,e,n){if(!t.includes("\x1B[?"))return{text:t,zones:[]};let r=[],i=[],s="",o=0,a="",c=()=>{let f=i.pop();if(f&&o>f.col)r.push({row:e,col:f.col,width:o-f.col,height:1,target:f.target})},u=0;while(u<t.length){let f=t.indexOf("\x1B",u);if(f!==u){let m=f===-1?t.length:f;a+=t.slice(u,m),s+=t.slice(u,m),u=m;continue}let l=t.slice(u,u+(Qh(t,u)||1));u+=l.length;let d=ry(l),h=d===void 0?zT(l):void 0;if(d===void 0&&h===void 0){s+=l;continue}if(o+=B(a),a="",h!==void 0)o=h,s+=l;else if(d===0)c();else if(d!==void 0)i.push({target:n[d-1],col:o})}o+=B(a);while(i.length>0)c();return{text:s,zones:r}}function iy(t,e,n){let r=[],i=[],s="",o=(b)=>{let $=ry(b);if($===0)r.pop();else if($!==void 0)r.push(b);else if(b.startsWith("\x1B]8;"))s=b.slice(b.indexOf(";",4)+1).replace("\x07","").replace("\x1B\\","")===""?"":b;else if(b.startsWith("\x1B[")&&b.endsWith("m"))i.push(b)},a=t.includes("\x1B")||n.includes("\x1B")?Se:"",c=So(t),u="",f=0,l=0;while(l<c.length&&f<e){let b=c[l];if(b.sequence)o(b.text);else if(f+b.width>e)break;else f+=b.width;u+=b.text,l++}u+=" ".repeat(e-Math.min(e,f));let d=`${"\x1B[?0y".repeat(r.length)}${s?"\x1B]8;;\x1B\\":""}${a}`,h=e+B(n);while(l<c.length&&f<h){let b=c[l];if(b.sequence)o(b.text);else f+=b.width;l++}let m=l<c.length?t.slice(c[l].start):"";if(m===""&&f<=h)return`${u}${d}${n}${a}`;let p=`${i.join("")}${s}${r.join("")}${" ".repeat(Math.max(0,f-h))}`;return`${u}${d}${n}${a}${p}${m}`}function sy(t,e){let n=t.map((r,i)=>qT(r,i,e));return{lines:n.map((r)=>r.text),zones:n.flatMap((r)=>r.zones)}}function ey(t,e,n,r=0.5,i=0.5){let s=n-t.col,o=e-t.row;return{target:t.target,x:s,y:o,exact:{x:s+r,y:o+i},width:t.width,height:t.height,inside:s>=0&&s<t.width&&o>=0&&o<t.height}}function DT(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 JT={space:" ",enter:"enter",esc:"esc",tab:"tab",bksp:"backspace",del:"delete","←":"left","→":"right"};function nm(t){let e=/^(ctrl|alt)\+([a-z])$/.exec(t);if(e)return`${e[1]}-${e[2]}`;return JT[t]??([...t].length===1&&t!==" "?t:void 0)}function be(t,e){let n=nm(t);return n?pn({kind:"key",key:n},e):e}class rm{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&&ey(n,t.row,t.col,t.fx,t.fy)}let e=DT(this.zones,t.row,t.col);if(t.action==="press")this.held=t.button==="left"?e:void 0;return e&&ey(e,t.row,t.col,t.fx,t.fy)}drop(){this.held=void 0}}function Ju(t,e,n,r=(i)=>i){if(!t.color)return r(n?`[${e}]`:` ${e} `);return n?t.pill(r(` ${e} `)):t.dim(r(` ${e} `))}function Ve(t,e){return t.color?t.pill(` ${e} `):`[${e}]`}function oy(t,e,n){return be(e.split(" ")[0]??"",`${t.bold(e)} ${t.dim(n)}`)}function Yu(t,e){return e===void 0?t.dim(R.sep):e?t.dim(R.ok):t.bold(R.miss)}var YT={top:"╭╮",mid:"├┤",bottom:"╰╯"};function Gt(t,e,n=[]){let[r,i]=[...YT[e]],s=[...`${r}${"─".repeat(Math.max(0,t-2))}${i}`];for(let[o,a]of n)[...a].forEach((c,u)=>{if(o+u>0&&o+u<t-1)s[o+u]=c});return s.join("")}function Ze(t,e,n){return`${t.dim("│")}${tt(e,n-2)}${t.dim("│")}`}var gr=[{name:"preview",title:"Preview"},{name:"browse",title:"Browse"}],Vu=10,Zu=20;function ay(t){return gr.find((e)=>e.name===t.TTHEME_HUB)?.name}function im(t,e){let n=gr.findIndex((r)=>r.name===t);return Zu+(n+e+gr.length)%gr.length+1}function cy(t){return Zu+gr.findIndex((e)=>e.name===t)+1}function sm(t,e){let n=je(e);return` ${gr.map(({name:i,title:s})=>{let o={kind:"hub",tab:i};return Ju(n,s,i===t,(a)=>pn(o,a))}).join(" ")} ${n.dim("tab next")}`}import{execFileSync as oC}from"node:child_process";import{existsSync as Ul,mkdirSync as aC,readdirSync as cC,readFileSync as Wl,rmSync as uC}from"node:fs";import{basename as tS,join as pc,relative as Zv}from"node:path";import{styleText as nl}from"node:util";import{stdout as $y,stdin as rH}from"node:process";import iH from"node:readline";var Xu="\x1B",hy="›",VT=39,am="\x07",my="[",ZT="]",py="m",cm=`${ZT}8;;`,uy=new RegExp(`(?:\\${my}(?<code>\\d+)m|\\${cm}(?<uri>.*)${am})`,"y"),ly=(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},fy=(t)=>`${Xu}${my}${t}${py}`,dy=(t)=>`${Xu}${cm}${t}${am}`,om=(t,e,n)=>{let r=e[Symbol.iterator](),i=!1,s=!1,o=t.at(-1),a=o===void 0?0:B(o),c=r.next(),u=r.next(),f=0;while(!c.done){let l=c.value,d=B(l);if(a+d<=n)t[t.length-1]+=l;else t.push(l),a=0;if(l===Xu||l===hy)i=!0,s=e.startsWith(cm,f+1);if(i){if(s){if(l===am)i=!1,s=!1}else if(l===py)i=!1}else if(a+=d,a===n&&!u.done)t.push(""),a=0;c=u,u=r.next(),f+=l.length}if(o=t.at(-1),!a&&o!==void 0&&o.length&&t.length>1)t[t.length-2]+=t.pop()},XT=(t)=>{let e=t.split(" "),n=e.length;while(n){if(B(e[n-1]))break;n--}if(n===e.length)return t;return e.slice(0,n).join(" ")+e.slice(n).join("")},QT=(t,e,n={})=>{if(n.trim!==!1&&t.trim()==="")return"";let r="",i,s,o=t.split(" "),a=[""],c=0;for(let l=0;l<o.length;l++){let d=o[l];if(n.trim!==!1){let m=a.at(-1)??"",p=m.trimStart();if(m.length!==p.length)a[a.length-1]=p,c=B(p)}if(l!==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=B(d);if(n.hard&&h>e){let m=e-c,p=1+Math.floor((h-m-1)/e);if(Math.floor((h-1)/e)<p)a.push("");om(a,d,e),c=B(a.at(-1)??"");continue}if(c+h>e&&c&&h){if(n.wordWrap===!1&&c<e){om(a,d,e),c=B(a.at(-1)??"");continue}a.push(""),c=0}if(c+h>e&&n.wordWrap===!1){om(a,d,e),c=B(a.at(-1)??"");continue}a[a.length-1]+=d,c+=h}if(n.trim!==!1)a=a.map((l)=>XT(l));let u=a.join(`
290
+ `),f=!1;for(let l=0;l<u.length;l++){let d=u[l];if(r+=d,!f){if(f=d>="\uD800"&&d<="\uDBFF",f)continue}else f=!1;if(d===Xu||d===hy){uy.lastIndex=l+1;let m=uy.exec(u)?.groups;if(m?.code!==void 0){let p=Number.parseFloat(m.code);i=p===VT?void 0:p}else if(m?.uri!==void 0)s=m.uri.length===0?void 0:m.uri}if(u[l+1]===`
291
+ `){if(s)r+=dy("");let h=i?ly(i):void 0;if(i&&h)r+=fy(h)}else if(d===`
292
+ `){if(i&&ly(i))r+=fy(i);if(s)r+=dy(s)}}return r},tH=/\r?\n/;function ti(t,e,n){return String(t).normalize().split(tH).map((r)=>QT(r,e,n)).join(`
293
+ `)}var _e=gd(lm(),1);function br(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?br(s,e<0?-1:1,n):s}function Qu(t,e,n,r){let i=r.split(`
294
+ `),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 sH=["up","down","left","right","space","enter","cancel"],oH=["January","February","March","April","May","June","July","August","September","October","November","December"],Ut={actions:new Set(sH),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0,accessible:void 0,date:{monthNames:[...oH],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 aH(t){if(t!==void 0)return t;if(Ut.accessible!==void 0)return Ut.accessible;let e=process.env.ACCESSIBLE;return e!==void 0&&e!==""&&e!=="0"&&e!=="false"}function ky(t,e){if(typeof t=="string")return Ut.aliases.get(t)===e;for(let n of t)if(n!==void 0&&ky(n,e))return!0;return!1}function cH(t,e){if(t===e)return;let n=t.split(`
274
295
  `),r=e.split(`
275
- `),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 YU=globalThis.process.platform.startsWith("win"),Yu=Symbol("clack:cancel");function re(t){return t===Yu}function qu(t,e){let n=t;n.isTTY&&n.setRawMode(e)}var Vu=(t)=>("columns"in t)&&typeof t.columns=="number"?t.columns:80,nm=(t)=>("rows"in t)&&typeof t.rows=="number"?t.rows:20;function Vr(t,e,n,r=n,i=n,s){let o=Vu(t??cy);return Yr(e,o-n.length,{hard:!0,trim:!1}).split(`
296
+ `),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 yW=globalThis.process.platform.startsWith("win"),rl=Symbol("clack:cancel");function se(t){return t===rl}function tl(t,e){let n=t;n.isTTY&&n.setRawMode(e)}var il=(t)=>("columns"in t)&&typeof t.columns=="number"?t.columns:80,hm=(t)=>("rows"in t)&&typeof t.rows=="number"?t.rows:20;function ei(t,e,n,r=n,i=n,s){let o=il(t??$y);return ti(e,o-n.length,{hard:!0,trim:!1}).split(`
276
297
  `).map((a,c,u)=>{let f=s?s(a,c):a;return c===0?`${r}${f}`:c===u.length-1?`${i}${f}`:`${n}${f}`}).join(`
277
- `)}function ly(t,e){if("~standard"in t){let n=t["~standard"].validate(e);return n instanceof Promise?n.then((r)=>r.issues?.at(0)?.message):n.issues?.at(0)?.message}return t(e)}class hr{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";get accessible(){return _T(this.opts.accessible)}constructor(t,e=!0){let{input:n=LT,output:r=cy,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(Yu);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=FT.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),qu(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(je.cursor.show),this.output.off("resize",this.render),qu(this.input,!1),t(this.value)}),this.once("cancel",()=>{this.output.write(je.cursor.show),this.output.off("resize",this.render),qu(this.input,!1),t(Yu)})})}_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("")}async onKeypress(t,e){if(this.state!=="validating"){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&&Bt.aliases.has(e.name)&&this.emit("cursor",Bt.aliases.get(e.name)),Bt.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=ly(this.opts.validate,this.value),r;n instanceof Promise?(this.state="validating",this.render(),r=await n):r=n,r&&(this.error=r instanceof Error?r.message:r,this.state="error",this.rl?.write(this.userInput))}this.state!=="error"&&(this.state="submit")}uy([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(`
278
- `),qu(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let t=Yr(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
279
- `).length-1;this.output.write(je.cursor.move(-999,t*-1))}render(){let t=Yr(this._render(this)??"",process.stdout.columns,{hard:!0,trim:!1});if(t!==this._prevFrame){if(this.state==="initial")this.output.write(je.cursor.hide);else{let e=GT(this._prevFrame,t),n=nm(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(je.cursor.move(0,s-i)),this.output.write(je.erase.lines(1));let o=t.split(`
280
- `);this.output.write(o[s]),this._prevFrame=t,this.output.write(je.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(je.cursor.move(0,a))}this.output.write(je.erase.down());let o=t.split(`
298
+ `)}function yy(t,e){if("~standard"in t){let n=t["~standard"].validate(e);return n instanceof Promise?n.then((r)=>r.issues?.at(0)?.message):n.issues?.at(0)?.message}return t(e)}class wr{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";get accessible(){return aH(this.opts.accessible)}constructor(t,e=!0){let{input:n=rH,output:r=$y,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(rl);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=iH.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),tl(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(_e.cursor.show),this.output.off("resize",this.render),tl(this.input,!1),t(this.value)}),this.once("cancel",()=>{this.output.write(_e.cursor.show),this.output.off("resize",this.render),tl(this.input,!1),t(rl)})})}_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("")}async onKeypress(t,e){if(this.state!=="validating"){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&&Ut.aliases.has(e.name)&&this.emit("cursor",Ut.aliases.get(e.name)),Ut.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=yy(this.opts.validate,this.value),r;n instanceof Promise?(this.state="validating",this.render(),r=await n):r=n,r&&(this.error=r instanceof Error?r.message:r,this.state="error",this.rl?.write(this.userInput))}this.state!=="error"&&(this.state="submit")}ky([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(`
299
+ `),tl(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let t=ti(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
300
+ `).length-1;this.output.write(_e.cursor.move(-999,t*-1))}render(){let t=ti(this._render(this)??"",process.stdout.columns,{hard:!0,trim:!1});if(t!==this._prevFrame){if(this.state==="initial")this.output.write(_e.cursor.hide);else{let e=cH(this._prevFrame,t),n=hm(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(_e.cursor.move(0,s-i)),this.output.write(_e.erase.lines(1));let o=t.split(`
301
+ `);this.output.write(o[s]),this._prevFrame=t,this.output.write(_e.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(_e.cursor.move(0,a))}this.output.write(_e.erase.down());let o=t.split(`
281
302
  `).slice(s);this.output.write(o.join(`
282
- `)),this._prevFrame=t;return}}this.output.write(je.erase.down())}this.output.write(t),this.state==="initial"&&(this.state="active"),this._prevFrame=t}}}function BT(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 UT(t,e){return(e.label??String(e.value)).toLowerCase().includes(t.toLowerCase())}function WT(t,e){if(e)return t?e:e[0]}var KT=class extends hr{filteredOptions;multiple;isNavigating=!1;selectedValues=[];focusedValue;#e=0;#r="";#t;#o;#a;#n;get cursor(){return this.#e}get userInputWithCursor(){if(!this.userInput)return Ju(["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}${Ju("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,this.#n=e.completeOnTab===!0;let n=this.options;this.filteredOptions=[...n],this.multiple=e.multiple===!0,this.#t=typeof e.options=="function"?e.filter:e.filter??UT;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.#i(i,s)),this.on("userInput",(i)=>this.#s(i))}_isActionKey(e,n){return e==="\t"||this.multiple&&this.isNavigating&&n.name==="space"&&e!==void 0&&e!==""}#i(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((f)=>!f.disabled&&(this.#t?this.#t(a,f):!0));if(n.name==="tab"&&o&&u){this.userInput==="\t"&&this._clearUserInput(),this._setUserInput(a,!0),this.isNavigating=!1;return}if(n.name==="tab"&&this.#n&&!this.multiple&&this.focusedValue!==void 0){let f=String(this.focusedValue);this._clearUserInput(),this._setUserInput(f,!0),this.isNavigating=!1;return}r||i?(this.#e=dr(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=WT(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])}#s(e){if(e!==this.#r){this.#r=e;let n=this.options;e&&this.#t?this.filteredOptions=n.filter((s)=>this.#t?.(e,s)):this.filteredOptions=[...n];let r=BT(this.focusedValue,this.filteredOptions);this.#e=dr(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 rm extends hr{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(je.cursor.move(0,-1)),this.value=e,this.state="submit",this.close()}),this.on("cursor",()=>{this.value=!this.value})}}var zT={Y:{type:"year",len:4},M:{type:"month",len:2},D:{type:"day",len:2}};function oy(t){return[...t].map((e)=>zT[e])}function qT(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 tm(t){return Number.parseInt((t||"0").replace(/_/g,"0"),10)||0}function Du(t){return{year:tm(t.year),month:tm(t.month),day:tm(t.day)}}function em(t,e){return new Date(t||2001,e||1,0).getDate()}function fy(t){let{year:e,month:n,day:r}=Du(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 ay(t){let e=fy(t);return e?new Date(Date.UTC(e.year,e.month-1,e.day)):void 0}function DT(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:em(e.year,e.month)}}class dy extends hr{#e;#r;#t;#o;#a;#n={segmentIndex:0,positionInSegment:0};#i=!0;#s=null;inlineError="";get segmentCursor(){return{...this.#n}}get segmentValues(){return{...this.#t}}get segments(){return this.#e}get separator(){return this.#r}get formattedValue(){return this.#f(this.#t)}#f(t){return this.#e.map((e)=>t[e.type]).join(this.#r)}#c(){this._setUserInput(this.#f(this.#t)),this._setValue(ay(this.#t)??void 0)}constructor(t){let e=t.format?{segments:oy(t.format),separator:t.separator??"/"}:qT(t.locale),n=t.separator??e.separator,r=t.format?oy(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.#r=n,this.#t=s,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.#n.segmentIndex,this.#e.length-1)),e=this.#e[t];if(e)return this.#n.positionInSegment=Math.max(0,Math.min(this.#n.positionInSegment,e.len-1)),{segment:e,index:t}}#l(t){this.inlineError="",this.#s=null;let e=this.#u();e&&(this.#n.segmentIndex=Math.max(0,Math.min(this.#e.length-1,e.index+t)),this.#n.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=DT(n.type,Du(this.#t),this.#o,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.#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.#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.#n.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.#n.segmentIndex=i,this.#n.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 d=this.#s+t,h={...this.#t,[r.type]:d},m=this.#h(h,r);if(m){this.inlineError=m,this.#s=null,this.#i=!1;return}this.inlineError="",this.#t[r.type]=d,this.#s=null,this.#i=!1,this.#c(),n.index<this.#e.length-1&&(this.#n.segmentIndex=n.index+1,this.#n.positionInSegment=0,this.#i=!0);return}this.#i&&!i&&(this.#t[r.type]="_".repeat(r.len),this.#n.positionInSegment=0),this.#i=!1,this.#s=null;let s=this.#t[r.type],o=s.indexOf("_"),a=o>=0?o:Math.min(this.#n.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 f=c.includes("_")?void 0:fy(this.#t);if(f){let{year:d,month:h}=f,m=em(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,f.day))).padStart(2,"0")}}this.#c();let l=c.indexOf("_");u?(this.#i=!0,this.#s=t):l>=0?this.#n.positionInSegment=l:o>=0&&n.index<this.#e.length-1?(this.#n.segmentIndex=n.index+1,this.#n.positionInSegment=0,this.#i=!0):this.#n.positionInSegment=Math.min(a+1,r.len-1)}}#h(t,e){let{month:n,day:r}=Du(t);if(e.type==="month"&&(n<0||n>12))return Bt.date.messages.invalidMonth;if(e.type==="day"&&(r<0||r>31))return Bt.date.messages.invalidDay(31,"any month")}#g(t){let{year:e,month:n,day:r}=Du(this.#t);if(e&&n&&r){let i=em(e,n);this.#t={...this.#t,day:String(Math.min(r,i)).padStart(2,"0")}}this.value=ay(this.#t)??t.defaultValue??void 0}}var JT=class extends hr{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}})}},YT=new Set(["up","down","left","right"]);class hy extends hr{#e=!1;#r;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===`
303
+ `)),this._prevFrame=t;return}}this.output.write(_e.erase.down())}this.output.write(t),this.state==="initial"&&(this.state="active"),this._prevFrame=t}}}function uH(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 lH(t,e){return(e.label??String(e.value)).toLowerCase().includes(t.toLowerCase())}function fH(t,e){if(e)return t?e:e[0]}var dH=class extends wr{filteredOptions;multiple;isNavigating=!1;selectedValues=[];focusedValue;#e=0;#r="";#t;#o;#a;#n;get cursor(){return this.#e}get userInputWithCursor(){if(!this.userInput)return nl(["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}${nl("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,this.#n=e.completeOnTab===!0;let n=this.options;this.filteredOptions=[...n],this.multiple=e.multiple===!0,this.#t=typeof e.options=="function"?e.filter:e.filter??lH;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.#i(i,s)),this.on("userInput",(i)=>this.#s(i))}_isActionKey(e,n){return e==="\t"||this.multiple&&this.isNavigating&&n.name==="space"&&e!==void 0&&e!==""}#i(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((f)=>!f.disabled&&(this.#t?this.#t(a,f):!0));if(n.name==="tab"&&o&&u){this.userInput==="\t"&&this._clearUserInput(),this._setUserInput(a,!0),this.isNavigating=!1;return}if(n.name==="tab"&&this.#n&&!this.multiple&&this.focusedValue!==void 0){let f=String(this.focusedValue);this._clearUserInput(),this._setUserInput(f,!0),this.isNavigating=!1;return}r||i?(this.#e=br(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=fH(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])}#s(e){if(e!==this.#r){this.#r=e;let n=this.options;e&&this.#t?this.filteredOptions=n.filter((s)=>this.#t?.(e,s)):this.filteredOptions=[...n];let r=uH(this.focusedValue,this.filteredOptions);this.#e=br(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 mm extends wr{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(_e.cursor.move(0,-1)),this.value=e,this.state="submit",this.close()}),this.on("cursor",()=>{this.value=!this.value})}}var hH={Y:{type:"year",len:4},M:{type:"month",len:2},D:{type:"day",len:2}};function by(t){return[...t].map((e)=>hH[e])}function mH(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 fm(t){return Number.parseInt((t||"0").replace(/_/g,"0"),10)||0}function el(t){return{year:fm(t.year),month:fm(t.month),day:fm(t.day)}}function dm(t,e){return new Date(t||2001,e||1,0).getDate()}function vy(t){let{year:e,month:n,day:r}=el(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 wy(t){let e=vy(t);return e?new Date(Date.UTC(e.year,e.month-1,e.day)):void 0}function pH(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:dm(e.year,e.month)}}class Sy extends wr{#e;#r;#t;#o;#a;#n={segmentIndex:0,positionInSegment:0};#i=!0;#s=null;inlineError="";get segmentCursor(){return{...this.#n}}get segmentValues(){return{...this.#t}}get segments(){return this.#e}get separator(){return this.#r}get formattedValue(){return this.#f(this.#t)}#f(t){return this.#e.map((e)=>t[e.type]).join(this.#r)}#c(){this._setUserInput(this.#f(this.#t)),this._setValue(wy(this.#t)??void 0)}constructor(t){let e=t.format?{segments:by(t.format),separator:t.separator??"/"}:mH(t.locale),n=t.separator??e.separator,r=t.format?by(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.#r=n,this.#t=s,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.#n.segmentIndex,this.#e.length-1)),e=this.#e[t];if(e)return this.#n.positionInSegment=Math.max(0,Math.min(this.#n.positionInSegment,e.len-1)),{segment:e,index:t}}#l(t){this.inlineError="",this.#s=null;let e=this.#u();e&&(this.#n.segmentIndex=Math.max(0,Math.min(this.#e.length-1,e.index+t)),this.#n.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=pH(n.type,el(this.#t),this.#o,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.#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.#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.#n.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.#n.segmentIndex=i,this.#n.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 d=this.#s+t,h={...this.#t,[r.type]:d},m=this.#h(h,r);if(m){this.inlineError=m,this.#s=null,this.#i=!1;return}this.inlineError="",this.#t[r.type]=d,this.#s=null,this.#i=!1,this.#c(),n.index<this.#e.length-1&&(this.#n.segmentIndex=n.index+1,this.#n.positionInSegment=0,this.#i=!0);return}this.#i&&!i&&(this.#t[r.type]="_".repeat(r.len),this.#n.positionInSegment=0),this.#i=!1,this.#s=null;let s=this.#t[r.type],o=s.indexOf("_"),a=o>=0?o:Math.min(this.#n.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 f=c.includes("_")?void 0:vy(this.#t);if(f){let{year:d,month:h}=f,m=dm(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,f.day))).padStart(2,"0")}}this.#c();let l=c.indexOf("_");u?(this.#i=!0,this.#s=t):l>=0?this.#n.positionInSegment=l:o>=0&&n.index<this.#e.length-1?(this.#n.segmentIndex=n.index+1,this.#n.positionInSegment=0,this.#i=!0):this.#n.positionInSegment=Math.min(a+1,r.len-1)}}#h(t,e){let{month:n,day:r}=el(t);if(e.type==="month"&&(n<0||n>12))return Ut.date.messages.invalidMonth;if(e.type==="day"&&(r<0||r>31))return Ut.date.messages.invalidDay(31,"any month")}#g(t){let{year:e,month:n,day:r}=el(this.#t);if(e&&n&&r){let i=dm(e,n);this.#t={...this.#t,day:String(Math.min(r,i)).padStart(2,"0")}}this.value=wy(this.#t)??t.defaultValue??void 0}}var gH=class extends wr{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}})}},bH=new Set(["up","down","left","right"]);class Ey extends wr{#e=!1;#r;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===`
283
304
  `?`${e}█
284
- ${r}`:`${e}${Ju("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=zu(this._cursor,0,-1,e);return;case"down":this._cursor=zu(this._cursor,0,1,e);return;case"left":this._cursor=zu(this._cursor,-1,0,e);return;case"right":this._cursor=zu(this._cursor,1,0,e);return}}_shouldSubmit(t,e){if(this.#r)return this.focused==="submit"?!0:(this.#t(`
305
+ ${r}`:`${e}${nl("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=Qu(this._cursor,0,-1,e);return;case"down":this._cursor=Qu(this._cursor,0,1,e);return;case"left":this._cursor=Qu(this._cursor,-1,0,e);return;case"right":this._cursor=Qu(this._cursor,1,0,e);return}}_shouldSubmit(t,e){if(this.#r)return this.focused==="submit"?!0:(this.#t(`
285
306
  `),this._cursor++,!1);let n=this.#e;return this.#e=!0,n&&this.cursor===this.userInput.length?(this.userInput[this.cursor-1]===`
286
307
  `&&(this._setUserInput(this.userInput.slice(0,this.cursor-1)+this.userInput.slice(this.cursor)),this._cursor--),!0):(this.#t(`
287
- `),this._cursor++,!1)}constructor(t){let e=t.initialUserInput??t.initialValue;super({...t,initialUserInput:e},!1),e!==void 0&&(this._cursor=e.length),this.#r=t.showSubmit??!1,this.on("key",(n,r)=>{if(r?.name&&YT.has(r.name)){this.#e=!1,this.#o(r.name);return}if(n==="\t"&&this.#r){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.#r&&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 im extends hr{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?dr(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=dr(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=dr(this.cursor,1,this.options);break;case"space":this.toggleValue();break}})}}var my=class extends hr{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?dr(r,1,this.options):r,this.changeValue(),this.on("cursor",(i)=>{switch(i){case"left":case"up":this.cursor=dr(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=dr(this.cursor,1,this.options);break}this.changeValue()})}};class sm extends hr{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}${Ju("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 O,stripVTControlCharacters as rW}from"node:util";import Ze from"node:process";var ky=ld(Qh(),1);function VT(){if(Ze.platform!=="win32")return Ze.env.TERM!=="linux";return Boolean(Ze.env.CI)||Boolean(Ze.env.WT_SESSION)||Boolean(Ze.env.TERMINUS_SUBLIME)||Ze.env.ConEmuTask==="{cmd::Cmder}"||Ze.env.TERM_PROGRAM==="Terminus-Sublime"||Ze.env.TERM_PROGRAM==="vscode"||Ze.env.TERM==="xterm-256color"||Ze.env.TERM==="alacritty"||Ze.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var ZT=VT();var pt=(t,e)=>ZT?t:e,py=pt("◆","*"),XT=pt("■","x"),QT=pt("▲","x"),cm=pt("◇","o"),tH=pt("┌","T"),it=pt("│","|"),Ln=pt("└","—"),aW=pt("┐","T"),cW=pt("┘","—"),om=pt("●",">"),Xu=pt("○"," "),eH=pt("◻","[•]"),gy=pt("◼","[+]"),by=pt("◻","[ ]"),uW=pt("▪","•"),wy=pt("─","-"),nH=pt("╮","+"),rH=pt("├","+"),iH=pt("╯","+"),sH=pt("╰","+"),lW=pt("╭","+"),oH=pt("●","•"),aH=pt("◆","*"),cH=pt("▲","!"),uH=pt("■","x"),Qu=(t)=>{switch(t){case"initial":case"active":return O("cyan",py);case"cancel":return O("red",XT);case"error":return O("yellow",QT);case"submit":return O("green",cm);case"validating":return O("dim",py)}},yy=(t)=>{switch(t){case"initial":case"active":return O("cyan",it);case"cancel":return O("red",it);case"error":return O("yellow",it);case"submit":return O("green",it)}};function vy(t,e){let n=[`${e?`${O("cyan",it)} `:""}${t.join(" • ")}`];return e&&n.push(O("cyan",Ln)),n}var $y=(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}},am=({cursor:t,options:e,style:n,output:r=process.stdout,maxItems:i=Number.POSITIVE_INFINITY,columnPadding:s=0,rowPadding:o=4})=>{let a=Vu(r)-s,c=nm(r),u=O("dim","..."),f=Math.max(c-o,0),l=Math.max(Math.min(i,f),5),d=0;t>=l-3&&(d=Math.max(Math.min(t-l+3,e.length-l),0));let h=l<e.length&&d>0,m=l<e.length&&d+l<e.length,g=Math.min(d+l,e.length),b=[],w=0;h&&w++,m&&w++;let k=d+(h?1:0),v=g-(m?1:0);for(let x=k;x<v;x++){let M=e[x],N=M?n(M,x===t):"",C=Yr(N,a,{hard:!0,trim:!1}).split(`
288
- `);b.push(C),w+=C.length}if(w>f){let x=0,M=0,N=w,C=t-k,P=f,_=()=>$y(b,N,0,C,P),K=()=>$y(b,N,C+1,b.length,P,!0);h?({lineCount:N,removals:x}=_(),N>P&&(m||(P-=1),{lineCount:N,removals:M}=K())):(m||(P-=1),{lineCount:N,removals:M}=K(),N>P&&(P-=1,{lineCount:N,removals:x}=_())),x>0&&(h=!0,b.splice(0,x)),M>0&&(m=!0,b.splice(b.length-M,M))}let S=[];h&&S.push(u);for(let x of b)for(let M of x)S.push(M);return m&&S.push(u),S};var _e=(t)=>{let e=t.active??"Yes",n=t.inactive??"No";return new rm({active:e,inactive:n,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue??!0,render(){let r=t.withGuide??Bt.withGuide,i=`${Qu(this.state)} `,s=r?`${O("gray",it)} `:"",o=Vr(t.output,t.message,s,i),a=`${r?`${O("gray",it)}
308
+ `),this._cursor++,!1)}constructor(t){let e=t.initialUserInput??t.initialValue;super({...t,initialUserInput:e},!1),e!==void 0&&(this._cursor=e.length),this.#r=t.showSubmit??!1,this.on("key",(n,r)=>{if(r?.name&&bH.has(r.name)){this.#e=!1,this.#o(r.name);return}if(n==="\t"&&this.#r){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.#r&&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 pm extends wr{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?br(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=br(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=br(this.cursor,1,this.options);break;case"space":this.toggleValue();break}})}}var My=class extends wr{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?br(r,1,this.options):r,this.changeValue(),this.on("cursor",(i)=>{switch(i){case"left":case"up":this.cursor=br(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=br(this.cursor,1,this.options);break}this.changeValue()})}};class gm extends wr{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}${nl("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 O,stripVTControlCharacters as IW}from"node:util";import Xe from"node:process";var Ay=gd(lm(),1);function wH(){if(Xe.platform!=="win32")return Xe.env.TERM!=="linux";return Boolean(Xe.env.CI)||Boolean(Xe.env.WT_SESSION)||Boolean(Xe.env.TERMINUS_SUBLIME)||Xe.env.ConEmuTask==="{cmd::Cmder}"||Xe.env.TERM_PROGRAM==="Terminus-Sublime"||Xe.env.TERM_PROGRAM==="vscode"||Xe.env.TERM==="xterm-256color"||Xe.env.TERM==="alacritty"||Xe.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var $H=wH();var mt=(t,e)=>$H?t:e,xy=mt("◆","*"),kH=mt("■","x"),yH=mt("▲","x"),$m=mt("◇","o"),vH=mt("┌","T"),it=mt("│","|"),_n=mt("└","—"),TW=mt("┐","T"),HW=mt("┘","—"),bm=mt("●",">"),ol=mt("○"," "),SH=mt("◻","[•]"),Oy=mt("◼","[+]"),Py=mt("◻","[ ]"),FW=mt("▪","•"),Iy=mt("─","-"),EH=mt("╮","+"),MH=mt("├","+"),xH=mt("╯","+"),OH=mt("╰","+"),LW=mt("╭","+"),PH=mt("●","•"),IH=mt("◆","*"),RH=mt("▲","!"),AH=mt("■","x"),al=(t)=>{switch(t){case"initial":case"active":return O("cyan",xy);case"cancel":return O("red",kH);case"error":return O("yellow",yH);case"submit":return O("green",$m);case"validating":return O("dim",xy)}},Ny=(t)=>{switch(t){case"initial":case"active":return O("cyan",it);case"cancel":return O("red",it);case"error":return O("yellow",it);case"submit":return O("green",it)}};function Ty(t,e){let n=[`${e?`${O("cyan",it)} `:""}${t.join(" • ")}`];return e&&n.push(O("cyan",_n)),n}var Ry=(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}},wm=({cursor:t,options:e,style:n,output:r=process.stdout,maxItems:i=Number.POSITIVE_INFINITY,columnPadding:s=0,rowPadding:o=4})=>{let a=il(r)-s,c=hm(r),u=O("dim","..."),f=Math.max(c-o,0),l=Math.max(Math.min(i,f),5),d=0;t>=l-3&&(d=Math.max(Math.min(t-l+3,e.length-l),0));let h=l<e.length&&d>0,m=l<e.length&&d+l<e.length,p=Math.min(d+l,e.length),b=[],$=0;h&&$++,m&&$++;let k=d+(h?1:0),v=p-(m?1:0);for(let x=k;x<v;x++){let M=e[x],N=M?n(M,x===t):"",C=ti(N,a,{hard:!0,trim:!1}).split(`
309
+ `);b.push(C),$+=C.length}if($>f){let x=0,M=0,N=$,C=t-k,I=f,j=()=>Ry(b,N,0,C,I),U=()=>Ry(b,N,C+1,b.length,I,!0);h?({lineCount:N,removals:x}=j(),N>I&&(m||(I-=1),{lineCount:N,removals:M}=U())):(m||(I-=1),{lineCount:N,removals:M}=U(),N>I&&(I-=1,{lineCount:N,removals:x}=j())),x>0&&(h=!0,b.splice(0,x)),M>0&&(m=!0,b.splice(b.length-M,M))}let S=[];h&&S.push(u);for(let x of b)for(let M of x)S.push(M);return m&&S.push(u),S};var Be=(t)=>{let e=t.active??"Yes",n=t.inactive??"No";return new mm({active:e,inactive:n,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue??!0,render(){let r=t.withGuide??Ut.withGuide,i=`${al(this.state)} `,s=r?`${O("gray",it)} `:"",o=ei(t.output,t.message,s,i),a=`${r?`${O("gray",it)}
289
310
  `:""}${o}
290
311
  `,c=this.value?e:n;switch(this.state){case"submit":{let u=r?`${O("gray",it)} `:"";return`${a}${u}${O("dim",c)}`}case"cancel":{let u=r?`${O("gray",it)} `:"";return`${a}${u}${O(["strikethrough","dim"],c)}${r?`
291
- ${O("gray",it)}`:""}`}default:{let u=r?`${O("cyan",it)} `:"",f=r?O("cyan",Ln):"";return`${a}${u}${this.value?`${O("green",om)} ${e}`:`${O("dim",Xu)} ${O("dim",e)}`}${t.vertical?r?`
312
+ ${O("gray",it)}`:""}`}default:{let u=r?`${O("cyan",it)} `:"",f=r?O("cyan",_n):"";return`${a}${u}${this.value?`${O("green",bm)} ${e}`:`${O("dim",ol)} ${O("dim",e)}`}${t.vertical?r?`
292
313
  ${O("cyan",it)} `:`
293
- `:` ${O("dim","/")} `}${this.value?`${O("dim",Xu)} ${O("dim",n)}`:`${O("green",om)} ${n}`}
314
+ `:` ${O("dim","/")} `}${this.value?`${O("dim",ol)} ${O("dim",n)}`:`${O("green",bm)} ${n}`}
294
315
  ${f}
295
- `}}}}).prompt()};var lH=[`${O("dim","↑/↓")} to navigate`,`${O("dim","Space:")} select`,`${O("dim","Enter:")} confirm`],Wa=(t,e)=>t.split(`
316
+ `}}}}).prompt()};var NH=[`${O("dim","↑/↓")} to navigate`,`${O("dim","Space:")} select`,`${O("dim","Enter:")} confirm`],Ya=(t,e)=>t.split(`
296
317
  `).map((n)=>e(n)).join(`
297
- `),Sy=(t)=>{let e=(i,s)=>{let o=i.label??String(i.value);return s==="disabled"?`${O("gray",by)} ${Wa(o,(a)=>O(["strikethrough","gray"],a))}${i.hint?` ${O("dim",`(${i.hint??"disabled"})`)}`:""}`:s==="active"?`${O("cyan",eH)} ${o}${i.hint?` ${O("dim",`(${i.hint})`)}`:""}`:s==="selected"?`${O("green",gy)} ${Wa(o,(a)=>O("dim",a))}${i.hint?` ${O("dim",`(${i.hint})`)}`:""}`:s==="cancelled"?`${Wa(o,(a)=>O(["strikethrough","dim"],a))}`:s==="active-selected"?`${O("green",gy)} ${o}${i.hint?` ${O("dim",`(${i.hint})`)}`:""}`:s==="submitted"?`${Wa(o,(a)=>O("dim",a))}`:`${O("dim",by)} ${Wa(o,(a)=>O("dim",a))}`},n=t.required??!0,r=t.showInstructions??!0;return new im({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.
298
- ${O("reset",O("dim",`Press ${O(["gray","bgWhite","inverse"]," space ")} to select, ${O("gray",O("bgWhite",O("inverse"," enter ")))} to submit`))}`},render(){let i=t.withGuide??Bt.withGuide,s=Vr(t.output,t.message,i?`${yy(this.state)} `:"",`${Qu(this.state)} `),o=`${i?`${O("gray",it)}
318
+ `),Hy=(t)=>{let e=(i,s)=>{let o=i.label??String(i.value);return s==="disabled"?`${O("gray",Py)} ${Ya(o,(a)=>O(["strikethrough","gray"],a))}${i.hint?` ${O("dim",`(${i.hint??"disabled"})`)}`:""}`:s==="active"?`${O("cyan",SH)} ${o}${i.hint?` ${O("dim",`(${i.hint})`)}`:""}`:s==="selected"?`${O("green",Oy)} ${Ya(o,(a)=>O("dim",a))}${i.hint?` ${O("dim",`(${i.hint})`)}`:""}`:s==="cancelled"?`${Ya(o,(a)=>O(["strikethrough","dim"],a))}`:s==="active-selected"?`${O("green",Oy)} ${o}${i.hint?` ${O("dim",`(${i.hint})`)}`:""}`:s==="submitted"?`${Ya(o,(a)=>O("dim",a))}`:`${O("dim",Py)} ${Ya(o,(a)=>O("dim",a))}`},n=t.required??!0,r=t.showInstructions??!0;return new pm({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.
319
+ ${O("reset",O("dim",`Press ${O(["gray","bgWhite","inverse"]," space ")} to select, ${O("gray",O("bgWhite",O("inverse"," enter ")))} to submit`))}`},render(){let i=t.withGuide??Ut.withGuide,s=ei(t.output,t.message,i?`${Ny(this.state)} `:"",`${al(this.state)} `),o=`${i?`${O("gray",it)}
299
320
  `:""}${s}
300
- `,a=this.value??[],c=(u,f)=>{if(u.disabled)return e(u,"disabled");let l=a.includes(u.value);return f&&l?e(u,"active-selected"):l?e(u,"selected"):e(u,f?"active":"inactive")};switch(this.state){case"submit":{let u=this.options.filter(({value:l})=>a.includes(l)).map((l)=>e(l,"submitted")).join(O("dim",", "))||O("dim","none"),f=Vr(t.output,u,i?`${O("gray",it)} `:"");return`${o}${f}`}case"cancel":{let u=this.options.filter(({value:l})=>a.includes(l)).map((l)=>e(l,"cancelled")).join(O("dim",", "));if(u.trim()==="")return`${o}${O("gray",it)}`;let f=Vr(t.output,u,i?`${O("gray",it)} `:"");return`${o}${f}${i?`
321
+ `,a=this.value??[],c=(u,f)=>{if(u.disabled)return e(u,"disabled");let l=a.includes(u.value);return f&&l?e(u,"active-selected"):l?e(u,"selected"):e(u,f?"active":"inactive")};switch(this.state){case"submit":{let u=this.options.filter(({value:l})=>a.includes(l)).map((l)=>e(l,"submitted")).join(O("dim",", "))||O("dim","none"),f=ei(t.output,u,i?`${O("gray",it)} `:"");return`${o}${f}`}case"cancel":{let u=this.options.filter(({value:l})=>a.includes(l)).map((l)=>e(l,"cancelled")).join(O("dim",", "));if(u.trim()==="")return`${o}${O("gray",it)}`;let f=ei(t.output,u,i?`${O("gray",it)} `:"");return`${o}${f}${i?`
301
322
  ${O("gray",it)}`:""}`}case"error":{let u=i?`${O("yellow",it)} `:"",f=this.error.split(`
302
- `).map((h,m)=>m===0?`${i?`${O("yellow",Ln)} `:""}${O("yellow",h)}`:` ${h}`).join(`
323
+ `).map((h,m)=>m===0?`${i?`${O("yellow",_n)} `:""}${O("yellow",h)}`:` ${h}`).join(`
303
324
  `),l=o.split(`
304
325
  `).length,d=f.split(`
305
- `).length+1;return`${o}${u}${am({output:t.output,options:this.options,cursor:this.cursor,maxItems:t.maxItems,columnPadding:u.length,rowPadding:l+d,style:c}).join(`
326
+ `).length+1;return`${o}${u}${wm({output:t.output,options:this.options,cursor:this.cursor,maxItems:t.maxItems,columnPadding:u.length,rowPadding:l+d,style:c}).join(`
306
327
  ${u}`)}
307
328
  ${f}
308
329
  `}default:{let u=i?`${O("cyan",it)} `:"",f=o.split(`
309
- `).length,l=r?vy(lH,i):i?[O("cyan",Ln)]:[],d=l.join(`
310
- `),h=l.length+1;return`${o}${u}${am({output:t.output,options:this.options,cursor:this.cursor,maxItems:t.maxItems,columnPadding:u.length,rowPadding:f+h,style:c}).join(`
330
+ `).length,l=r?Ty(NH,i):i?[O("cyan",_n)]:[],d=l.join(`
331
+ `),h=l.length+1;return`${o}${u}${wm({output:t.output,options:this.options,cursor:this.cursor,maxItems:t.maxItems,columnPadding:u.length,rowPadding:f+h,style:c}).join(`
311
332
  ${u}`)}
312
333
  ${d}
313
- `}}}}).prompt()};var mr={message:(t=[],{symbol:e=O("gray",it),secondarySymbol:n=O("gray",it),output:r=process.stdout,spacing:i=1,withGuide:s}={})=>{let o=[],a=s??Bt.withGuide,c=a?n:"",u=a?`${e} `:"",f=a?`${n} `:"";for(let d=0;d<i;d++)o.push(c);let l=Array.isArray(t)?t:t.split(`
334
+ `}}}}).prompt()};var $r={message:(t=[],{symbol:e=O("gray",it),secondarySymbol:n=O("gray",it),output:r=process.stdout,spacing:i=1,withGuide:s}={})=>{let o=[],a=s??Ut.withGuide,c=a?n:"",u=a?`${e} `:"",f=a?`${n} `:"";for(let d=0;d<i;d++)o.push(c);let l=Array.isArray(t)?t:t.split(`
314
335
  `);if(l.length>0){let[d,...h]=l;d.length>0?o.push(`${u}${d}`):o.push(a?e:"");for(let m of h)m.length>0?o.push(`${f}${m}`):o.push(a?n:"")}r.write(`${o.join(`
315
336
  `)}
316
- `)},info:(t,e)=>{mr.message(t,{...e,symbol:O("blue",oH)})},success:(t,e)=>{mr.message(t,{...e,symbol:O("green",aH)})},step:(t,e)=>{mr.message(t,{...e,symbol:O("green",cm)})},warn:(t,e)=>{mr.message(t,{...e,symbol:O("yellow",cH)})},warning:(t,e)=>{mr.warn(t,e)},error:(t,e)=>{mr.message(t,{...e,symbol:O("red",uH)})}},Zr=(t="",e)=>{let n=e?.output??process.stdout,r=e?.withGuide??Bt.withGuide?`${O("gray",Ln)} `:"";n.write(`${r}${O("red",t)}
337
+ `)},info:(t,e)=>{$r.message(t,{...e,symbol:O("blue",PH)})},success:(t,e)=>{$r.message(t,{...e,symbol:O("green",IH)})},step:(t,e)=>{$r.message(t,{...e,symbol:O("green",$m)})},warn:(t,e)=>{$r.message(t,{...e,symbol:O("yellow",RH)})},warning:(t,e)=>{$r.warn(t,e)},error:(t,e)=>{$r.message(t,{...e,symbol:O("red",AH)})}},ni=(t="",e)=>{let n=e?.output??process.stdout,r=e?.withGuide??Ut.withGuide?`${O("gray",_n)} `:"";n.write(`${r}${O("red",t)}
317
338
 
318
- `)},tl=(t="",e)=>{let n=e?.output??process.stdout,r=e?.withGuide??Bt.withGuide?`${O("gray",tH)} `:"";n.write(`${r}${t}
319
- `)},Ka=(t="",e)=>{let n=e?.output??process.stdout,r=e?.withGuide??Bt.withGuide?`${O("gray",it)}
320
- ${O("gray",Ln)} `:"";n.write(`${r}${t}
339
+ `)},cl=(t="",e)=>{let n=e?.output??process.stdout,r=e?.withGuide??Ut.withGuide?`${O("gray",vH)} `:"";n.write(`${r}${t}
340
+ `)},Va=(t="",e)=>{let n=e?.output??process.stdout,r=e?.withGuide??Ut.withGuide?`${O("gray",it)}
341
+ ${O("gray",_n)} `:"";n.write(`${r}${t}
321
342
 
322
- `)};var fH=(t)=>t,dH=(t,e,n)=>{let r={hard:!0,trim:!1},i=Yr(t,e,r).split(`
323
- `),s=i.reduce((c,u)=>Math.max(G(u),c),0),o=i.map(n).reduce((c,u)=>Math.max(G(u),c),0),a=e-(o-s);return Yr(t,a,r)},Fn=(t="",e="",n)=>{let r=n?.output??Ze.stdout,i=n?.withGuide??Bt.withGuide,s=n?.format??fH,o=["",...dH(t,Vu(r)-6,s).split(`
324
- `).map(s),""],a=G(e),c=Math.max(o.reduce((d,h)=>{let m=G(h);return m>d?m:d},0),a)+2,u=o.map((d)=>`${O("gray",it)} ${d}${" ".repeat(c-G(d))}${O("gray",it)}`).join(`
343
+ `)};var TH=(t)=>t,HH=(t,e,n)=>{let r={hard:!0,trim:!1},i=ti(t,e,r).split(`
344
+ `),s=i.reduce((c,u)=>Math.max(B(u),c),0),o=i.map(n).reduce((c,u)=>Math.max(B(u),c),0),a=e-(o-s);return ti(t,a,r)},Bn=(t="",e="",n)=>{let r=n?.output??Xe.stdout,i=n?.withGuide??Ut.withGuide,s=n?.format??TH,o=["",...HH(t,il(r)-6,s).split(`
345
+ `).map(s),""],a=B(e),c=Math.max(o.reduce((d,h)=>{let m=B(h);return m>d?m:d},0),a)+2,u=o.map((d)=>`${O("gray",it)} ${d}${" ".repeat(c-B(d))}${O("gray",it)}`).join(`
325
346
  `),f=i?`${O("gray",it)}
326
- `:"",l=i?rH:sH;r.write(`${f}${O("green",cm)} ${O("reset",e)} ${O("gray",wy.repeat(Math.max(c-a-1,1))+nH)}
347
+ `:"",l=i?MH:OH;r.write(`${f}${O("green",$m)} ${O("reset",e)} ${O("gray",Iy.repeat(Math.max(c-a-1,1))+EH)}
327
348
  ${u}
328
- ${O("gray",l+wy.repeat(c+2)+iH)}
329
- `)};var fW={light:pt("─","-"),heavy:pt("━","="),block:pt("█","#")};var hH=[`${O("dim","↑/↓")} to navigate`,`${O("dim","Enter:")} confirm`],Zu=(t,e)=>t.includes(`
349
+ ${O("gray",l+Iy.repeat(c+2)+xH)}
350
+ `)};var CW={light:mt("─","-"),heavy:mt("━","="),block:mt("█","#")};var FH=[`${O("dim","↑/↓")} to navigate`,`${O("dim","Enter:")} confirm`],sl=(t,e)=>t.includes(`
330
351
  `)?t.split(`
331
352
  `).map((n)=>e(n)).join(`
332
- `):e(t),um=(t)=>{let e=(r,i)=>{if(r===void 0)return"";let s=r.label??String(r.value);switch(i){case"disabled":return`${O("gray",Xu)} ${Zu(s,(o)=>O("gray",o))}${r.hint?` ${O("dim",`(${r.hint??"disabled"})`)}`:""}`;case"selected":return`${Zu(s,(o)=>O("dim",o))}`;case"active":return`${O("green",om)} ${s}${r.hint?` ${O("dim",`(${r.hint})`)}`:""}`;case"cancelled":return`${Zu(s,(o)=>O(["strikethrough","dim"],o))}`;default:return`${O("dim",Xu)} ${Zu(s,(o)=>O("dim",o))}`}},n=t.showInstructions??!0;return new my({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue,render(){let r=t.withGuide??Bt.withGuide,i=`${Qu(this.state)} `,s=`${yy(this.state)} `,o=Vr(t.output,t.message,s,i),a=`${r?`${O("gray",it)}
353
+ `):e(t),km=(t)=>{let e=(r,i)=>{if(r===void 0)return"";let s=r.label??String(r.value);switch(i){case"disabled":return`${O("gray",ol)} ${sl(s,(o)=>O("gray",o))}${r.hint?` ${O("dim",`(${r.hint??"disabled"})`)}`:""}`;case"selected":return`${sl(s,(o)=>O("dim",o))}`;case"active":return`${O("green",bm)} ${s}${r.hint?` ${O("dim",`(${r.hint})`)}`:""}`;case"cancelled":return`${sl(s,(o)=>O(["strikethrough","dim"],o))}`;default:return`${O("dim",ol)} ${sl(s,(o)=>O("dim",o))}`}},n=t.showInstructions??!0;return new My({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue,render(){let r=t.withGuide??Ut.withGuide,i=`${al(this.state)} `,s=`${Ny(this.state)} `,o=ei(t.output,t.message,s,i),a=`${r?`${O("gray",it)}
333
354
  `:""}${o}
334
- `;switch(this.state){case"submit":{let c=r?`${O("gray",it)} `:"",u=Vr(t.output,e(this.options[this.cursor],"selected"),c);return`${a}${u}`}case"cancel":{let c=r?`${O("gray",it)} `:"",u=Vr(t.output,e(this.options[this.cursor],"cancelled"),c);return`${a}${u}${r?`
355
+ `;switch(this.state){case"submit":{let c=r?`${O("gray",it)} `:"",u=ei(t.output,e(this.options[this.cursor],"selected"),c);return`${a}${u}`}case"cancel":{let c=r?`${O("gray",it)} `:"",u=ei(t.output,e(this.options[this.cursor],"cancelled"),c);return`${a}${u}${r?`
335
356
  ${O("gray",it)}`:""}`}default:{let c=r?`${O("cyan",it)} `:"",u=a.split(`
336
- `).length,f=n?vy(hH,r):r?[O("cyan",Ln)]:[],l=f.join(`
337
- `),d=f.length+1;return`${a}${c}${am({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(`
357
+ `).length,f=n?Ty(FH,r):r?[O("cyan",_n)]:[],l=f.join(`
358
+ `),d=f.length+1;return`${a}${c}${wm({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(`
338
359
  ${c}`)}
339
360
  ${l}
340
- `}}}}).prompt()};var dW=`${O("gray",it)} `;var lm=(t)=>new sm({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??Bt.withGuide,n=`${`${e?`${O("gray",it)}
341
- `:""}${Qu(this.state)} `}${t.message}
342
- `,r=t.placeholder&&t.placeholder.length>0?O("inverse",t.placeholder[0])+O("dim",t.placeholder.slice(1)):O(["inverse","hidden"],"_"),i=this.userInput?this.userInputWithCursor:r,s=this.value??"";switch(this.state){case"validating":{let o=e?`${O("cyan",it)} `:"",a=e?O("cyan",Ln):"",c=O("dim",i),u=O("dim","Validating...");return`${n}${o}${c}
361
+ `}}}}).prompt()};var jW=`${O("gray",it)} `;var ym=(t)=>new gm({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??Ut.withGuide,n=`${`${e?`${O("gray",it)}
362
+ `:""}${al(this.state)} `}${t.message}
363
+ `,r=t.placeholder&&t.placeholder.length>0?O("inverse",t.placeholder[0])+O("dim",t.placeholder.slice(1)):O(["inverse","hidden"],"_"),i=this.userInput?this.userInputWithCursor:r,s=this.value??"";switch(this.state){case"validating":{let o=e?`${O("cyan",it)} `:"",a=e?O("cyan",_n):"",c=O("dim",i),u=O("dim","Validating...");return`${n}${o}${c}
343
364
  ${a} ${u}
344
- `}case"error":{let o=this.error?` ${O("yellow",this.error)}`:"",a=e?`${O("yellow",it)} `:"",c=e?O("yellow",Ln):"";return`${n.trim()}
365
+ `}case"error":{let o=this.error?` ${O("yellow",this.error)}`:"",a=e?`${O("yellow",it)} `:"",c=e?O("yellow",_n):"";return`${n.trim()}
345
366
  ${a}${i}
346
367
  ${c}${o}
347
368
  `}case"submit":{let o=s?`${e?" ":""}${O("dim",s)}`:"",a=e?O("gray",it):"";return`${n}${a}${o}`}case"cancel":{let o=s?` ${O(["strikethrough","dim"],s)}`:"",a=e?O("gray",it):"";return`${n}${a}${o}${s.trim()?`
348
- ${a}`:""}`}default:{let o=e?`${O("cyan",it)} `:"",a=e?O("cyan",Ln):"";return`${n}${o}${i}
369
+ ${a}`:""}`}default:{let o=e?`${O("cyan",it)} `:"",a=e?O("cyan",_n):"";return`${n}${o}${i}
349
370
  ${a}
350
- `}}}}).prompt();import{readFileSync as OF}from"node:fs";import{join as PF}from"node:path";import{existsSync as kp,mkdirSync as Tv,readFileSync as Hv,statSync as pF,utimesSync as gF}from"node:fs";import{homedir as bF}from"node:os";import{dirname as wF,join as Av}from"node:path";function el(t){if(t.length>0&&process.stderr.isTTY)process.stderr.write(`${t.join(`
371
+ `}}}}).prompt();import{readFileSync as YL}from"node:fs";import{join as VL}from"node:path";import{existsSync as Ap,mkdirSync as Kv,readFileSync as zv,statSync as CL,utimesSync as jL}from"node:fs";import{homedir as _L}from"node:os";import{dirname as BL,join as Uv}from"node:path";function ul(t){if(t.length>0&&process.stderr.isTTY)process.stderr.write(`${t.join(`
351
372
  `)}
352
- `)}import{existsSync as Ol,readFileSync as ev,rmSync as lp}from"node:fs";import{homedir as bn}from"node:os";import{join as Ho}from"node:path";var Ey=44,Yt=[{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 Qi(t){let e=Yt.length;return Yt[(t%e+e)%e]}function ko(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 vH}from"node:crypto";import{existsSync as il,readFileSync as wm,rmSync as Py}from"node:fs";import{homedir as Ry}from"node:os";import{join as ts}from"node:path";function Xr(t){return[`# ${t.name} — ${ne(t)}${t.native?` (${t.native})`:""}`,`# ANSI: ${t.ansiSource}`]}function pr(t,e){return[`[${t}]`,`Color=${ct(e).join(",")}`,""]}function fm(t,e,n=["Wallpaper="]){let r=(i)=>Tt(i,t.background,0.5);return[...pr("Background",t.background),...pr("BackgroundFaint",t.background),...pr("BackgroundIntense",t.background),...t.ansi.slice(0,8).flatMap((i,s)=>[...pr(`Color${s}`,i),...pr(`Color${s}Faint`,r(i)),...pr(`Color${s}Intense`,t.ansi[s+8])]),...pr("Foreground",t.foreground),...pr("ForegroundFaint",r(t.foreground)),...pr("ForegroundIntense",t.foreground),"[General]","Blur=false","ColorRandomization=false",`Description=${e}`,"Opacity=1",...n,""]}var My={left:"0",top:"0",center:"0.5",right:"1",bottom:"1"};function mH(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=${My[n]??"0.5"},${My[e]??"0.5"}`,`WallpaperOpacity=${t.opacity}`]}function dm(t,e){return[...Xr(t),"",...fm(t,`ttheme · ${t.name}`,mH(e))].join(`
353
- `)}var hm={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:dm(t)}]}};import{openSync as pH,writeSync as gH}from"node:fs";import{ReadStream as bH}from"node:tty";var hn=["11","10","12","17",...Array.from({length:16},(t,e)=>`4;${e}`)];function Ft(t=process.env){return Boolean(t.NO_COLOR)||t.TERM==="dumb"}function wH(t,e){return`\x1B]${hn[t]};${e}\x1B\\`}function gr(t,e){return[t.background,t.foreground,t.cursor,t.selection,...t.ansi].map((n,r)=>e&&!e.includes(r)?"":wH(r,n)).join("")}function $H(t){return`\x1B]${t.startsWith("4;")?`104;${t.slice(2)}`:`1${t}`}\x1B\\`}function kH(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 xy(t){return`#${t.slice(t.indexOf(":")+1).split("/").slice(0,3).map((n)=>n.slice(0,2).padStart(2,"0")).join("")}`}function Oy(t){return hn.map((e)=>{let n=t.get(e);return n?xy(n):void 0})}function nl(t,e=[...t.keys()],n=!1){return e.map((r)=>{let i=t.get(r);return i?`\x1B]${r};${n?xy(i):i}\x1B\\`:$H(r)}).join("")}function rl(t,e){return`\x1B]50;ColorScheme=${t};UseCustomCursorColor=true;customCursorColor=${e}\x07`}function mm(t=hn,e="\x1B[5n"){return`${t.map((n)=>`\x1B]${n};?\x1B\\`).join("")}${e}`}function yH(t){return t.includes("\x1B[0n")}async function pm(t=hn){let e,n;try{e=pH("/dev/tty","r+"),n=new bH(e),n.setRawMode(!0)}catch{return new Map}try{gH(e,mm(t));let r="";return await new Promise((i)=>{let s=setTimeout(i,120);n.on("data",(o)=>{if(r+=o.toString(),yH(r))clearTimeout(s),i()})}),kH(r)}finally{n.setRawMode(!1),n.destroy()}}function $m(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 Vt(t){if($m(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 ye={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 gm(t,e,n){let r="";for(let i of t.split(`
354
- `)){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 SH(t){let e=t.XDG_CONFIG_HOME??ts(Ry(),".config"),n=ts(e,"konsolerc"),r=il(n)?gm(wm(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=Ty(t).map((u)=>ts(u,s)).find((u)=>il(u));if(!o)return!1;let a=wm(o,"utf8"),c=gm(a,"Interaction Options","AllowEscapedLinks");if(c!==void 0)return c==="true";r=gm(a,"General","Parent")}return!1}function Iy(t){let e=Vt(t);return e==="konsole"?SH(t):ye[e].links}function yo(t,e){let n=Vt(t),r=ye[n];return r.pictures&&!t.TMUX&&(!r.views||e.includes(n))}function sl(t){return ye[Vt(t)].bands}function ol(t){return ye[Vt(t)].files}function vo(t){return ye[Vt(t)].layers}function Ay(t){return ye[Vt(t)].moves}function Ny(t){return ye[Vt(t)].wipes===!0}function es(t){return ye[Vt(t)].views===!0}function ns(t){return`\x1B]1337;SetUserVar=ttheme_view=${Buffer.from(t).toString("base64")}\x07`}var rs="\x1B[H\x1B[K\x1B[2H\x1B[J\x1B[H",km=120,bm=4,EH=40;function MH(t){let e=t.TTHEME_ITERM_SHOWN;return t.TTHEME_ITERM_SWITCH==="1"&&t.TTHEME_ITERM_DYED==="0"&&e?`ttheme · ${e}`:void 0}function xH(t,e){let n=ye.iterm2.repaint??[],r=hn.map((c,u)=>u).filter((c)=>!n.includes(c)),i=new Set(n),s=MH(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+=bm){let f=r.slice(u,u+bm),l=setTimeout(()=>{for(let d of f)i.add(d);e(gr(c,f))},km+u/bm*EH);l.unref?.(),o.push(l)}return gr(c,n)},wear:(c)=>gr(c),saved:()=>pm(),restore(c){a();let u=hn.filter((f,l)=>i.has(l));return s?`\x1B[?2026h${nl(new Map,u)}\x1B]1337;SetProfile=${s}\x07\x1B[?2026l`:nl(c,u)},stop:a}}var OH=3,PH=/^(Wallpaper|FillStyle|Anchor|WallpaperOpacity|WallpaperFlipType)=/;function Ty(t){return[t.XDG_DATA_HOME??ts(Ry(),".local","share"),...(t.XDG_DATA_DIRS||"/usr/local/share:/usr/share").split(":")].map((e)=>ts(e,"konsole"))}function RH(t,e){let n=/(?:^|;)ColorScheme=([^;]+)/.exec(e)?.[1],r=n&&t.map((c)=>ts(c,`${n}.colorscheme`)).find((c)=>il(c));if(!r)return["Wallpaper="];let i=wm(r,"utf8").split(`
355
- `),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)=>PH.test(c));return a.length>0?a:["Wallpaper="]}function IH(t,e){let n=Ty(t),r=n[0],i=RH(n,e),s=[],o=(c,u,f)=>{let l=fm(u,`ttheme · ${c}`,i).join(`
356
- `),d=`${j("view")}.${vH("sha1").update(l).digest("hex").slice(0,10)}`,h=ts(r,`${d}.colorscheme`);if(!il(h))L(h,l);if(!s.includes(h))s.push(h);for(let m of s.splice(0,Math.max(0,s.length-OH)))Py(m,{force:!0});return rl(d,f)},a=()=>{for(let c of s.splice(0))Py(c,{force:!0})};return{slots:[],paint:(c)=>o(c.name,c,c.cursor),wear:(c,u)=>u.includes("konsole")?rl(j(c.name),c.cursor):void 0,saved:async()=>new Map,restore:()=>{return a(),`\x1B]50;${e}\x07`},stop:a}}function Hy(t,e,n=(r)=>{process.stdout.write(r)}){let r=Vt(t),i=ye[r];if(!e||Ft(t)||t.TMUX||!i.paints)return;if(r==="iterm2")return xH(t,n);if(r==="konsole"&&t.TTHEME_KONSOLE_LOOK)return IH(t,t.TTHEME_KONSOLE_LOOK);let s=i.repaint??hn.map((a,c)=>c),o=hn.filter((a,c)=>s.includes(c));return{slots:s,paint:(a)=>gr(a,s),wear:(a,c)=>!i.schemes?gr(a):c.includes(r)?rl(j(a.name),a.cursor):void 0,saved:()=>pm(o),restore:(a)=>nl(a,o,i.hex===!0)}}var ie=["ghostty","kitty","alacritty","wezterm","iterm2","windows-terminal","warp","konsole","terminal-app"];var AH=[{section:"tab",title:"This tab"},{section:"startup",title:"New tabs"},{section:"palettes",title:"Palettes"},{section:"own",title:"Your own"},{section:"setup",title:"Setup"},{section:"support",title:"Support"}],Eo=[{name:"use",args:["<palette>"],about:"Paint this tab — a unique prefix works: ttheme use ho",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:["[dir|ssh:<host>]"],about:"Pin a palette to a directory or an ssh host — the pin covers everything below it, or its whole repository; cd or ssh in repaints, leaving restores",section:"tab",shell:!0},{name:"unpin",args:["[dir|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 pin as a file tree — the pinned directories in their palettes' 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 marketplaces in a live picker — one list with every marketplace as a row, which ctrl+s narrows to one marketplace at a time",section:"palettes",hidden:!0},{name:"list",args:["[query]"],about:"List palettes, marking what is installed",section:"palettes",flags:{json:{type:"boolean",about:"Print the matches as JSON — name, group, catalog, installed"}}},{name:"add",args:["<palette...>"],about:"Install palettes — from your marketplaces, or from a share link: ttheme add https://ttheme.vercel.app/p/tt2:…",section:"palettes",flags:{marketplace:{type:"string",value:"<source>",about:"Add this marketplace first — a repository, a folder or official — and take bare palette names from it"}}},{name:"remove",args:["<palette...>"],about:"Uninstall palettes",section:"palettes"},{name:"update",args:["[marketplace...]"],about:"Update ttheme and refresh your marketplaces — official palettes come with ttheme; an installed palette from another marketplace keeps its colors until ctrl+r on it in Browse takes its update",section:"palettes"},{name:"marketplace",args:["[action]","[source]"],about:"The marketplaces you added — add, remove and search them; init makes one of your own",actions:[["(none)","List the marketplaces you added — their palettes, auto-update and last update"],["add <source>","Add a marketplace — a repository (alice/ttheme-pastel, #v1 pins a tag or branch), a folder, or official; asks whether it updates on its own"],["remove <marketplace>","Drop one by its name (alice@pastel) — the palettes you installed from it keep working"],["search [query]","The marketplaces on GitHub with the ttheme-marketplace topic, listed every half hour — a query matches names, palettes and descriptions"],["init [name]","Make a marketplace of your own — <you>@<name>, in ~/.config/ttheme/marketplace/<name> or a folder you give"],["check [dir]","Check a marketplace's folder before you push it — ttheme-marketplace.toml, every palette, the renames and the gate; nothing is written"]],section:"palettes"},{name:"new",args:["<name>"],about:"Make a palette of your own in the palette editor — <you>@<marketplace>/<name>, from blank, installed at once",section:"own",flags:{from:{type:"string",value:"<palette>",about:"Start from this palette's colors instead of blank"},in:{type:"string",value:"<marketplace>",about:"The local marketplace to put it in — when you have more than one"}}},{name:"edit",args:["[palette]"],about:"Change a palette in the palette editor — your own in its file, any other as your tone over its marketplace's colors, which R and s in the editor put back; with none named, asks to edit the one this tab wears",section:"own"},{name:"check",args:["[palette]"],about:"Measure a palette against the contrast gate — where it misses, suggest colors that pass; with none named, asks to check the one this tab wears",section:"own",flags:{fix:{type:"boolean",about:"Write the suggested colors into your palette"}}},{name:"share",args:["[palette]"],about:"Print a share link and its QR code — the page shows the palette, and ttheme add <link> installs it anywhere, pictures included; with none named, asks to share the one this tab wears — or shares it without asking when the link goes to a pipe",section:"own",flags:{tone:{type:"string",value:"<tuned|original>",choices:["tuned","original"],about:"Share it as you tuned it, or as it was — asked when you tuned it and omit this"}}},{name:"init",args:[],about:"Install the shell layer and wire your terminals",section:"setup",flags:{yes:{type:"boolean",short:"y",about:"Accept every default without prompting"}}},{name:"uninstall",args:[],about:"Remove ttheme — its block comes out of every terminal config and what it wrote is deleted",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:ie,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>","[width]"],about:"Print a palette's colors for preview's panel at its width, open them in the palette editor, or reset them to its marketplace's — preview calls this",section:"setup",hidden:!0},{name:"sync",args:[],about:"Write every wired terminal's config again from what is installed and config.zsh — ttheme config and preview call this when TTHEME_TAB_PALETTE changed",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:"latest",args:[],about:"Ask npm for the newest ttheme — any command starts this in the background once a day",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 NH(t){let e=Object.entries(t.flags??{}).map(([n,{value:r}])=>`[--${n}${r?` ${r}`:""}]`);return[t.name,...e,...t.args].join(" ")}function So(t,e=TH){return t.map(([n,r])=>` ${n.padEnd(e)} ${r}`)}function Ly(t){return t.split(" — ")[0]}function Cy(t){return Object.entries(t.flags??{}).map(([e,{short:n,value:r,about:i}])=>[`${n?`-${n}, `:""}--${e}${r?` ${r}`:""}`,i])}function jy(t,e){let n=e?[...t.actions??[],...Cy(t)]:[];return[[[t.name,...t.args].join(" "),Ly(t.about)],...n.map(([r,i])=>[` ${r}`,Ly(i)])]}var _y=[`ttheme ${dt.version}`,dt.description,"Usage: ttheme <command> [options] [args]"],Gy=[["ttheme help","Every command"],["ttheme help all","Every command with its options, and examples"],["ttheme help <command>","One command in full"]],By=[["-h, --help","Show help — after a command, that command's"],["-v, --version","Print the version"]],TH=Math.max(...[...Gy,...By,...Eo.filter((t)=>!t.hidden).flatMap((t)=>jy(t,!0))].map(([t])=>t.length)),Fy=[["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 Magica catalog as JSON"],["ttheme marketplace add alice/ttheme-pastel","alice's marketplace, alice@pastel — ttheme add alice@pastel/dusk"],["ttheme add dusk --marketplace alice/ttheme-pastel","The same in one step"],["ttheme new rei --from rei","Your own rei, <you>@<marketplace>/rei, to edit and share"]];function Uy(){return[..._y,"","Use --help to list every command, or init to set ttheme up"].join(`
357
- `)}function ym(t){let e=Cy(t);return[`Usage: ttheme ${NH(t)}`,"",t.about,...t.actions?["","Actions:",...So(t.actions)]:[],...e.length>0?["","Options:",...So(e)]:[]].join(`
358
- `)}function qa(t,e=!1){let n=Eo.filter((i)=>!i.hidden&&!(e&&i.section==="setup")),r=AH.filter(({section:i})=>n.some((s)=>s.section===i));return[..._y,"ttheme alone opens Preview and Browse as tabs — tab and shift+tab move between them","","Getting help:",...So(Gy),"","Global options:",...So(By),...r.flatMap(({section:i,title:s})=>["",`${s}:`,...So(n.filter((o)=>o.section===i).flatMap((o)=>jy(o,t)))]),...t?["","Examples:",...So(Fy,Math.max(...Fy.map(([i])=>i.length)))]:[],"","https://ttheme.vercel.app"].join(`
359
- `)}import{readFileSync as HH}from"node:fs";import{join as LH}from"node:path";var vm="# ttheme begin",Sm="# ttheme end",is=/# ttheme begin\n[\s\S]*?# ttheme end\n?/,ve="Managed by ttheme — npx @kecan0406/ttheme@latest uninstall takes it out",Cn="Generated by ttheme — rewritten on every add, remove and default; do not edit.";function Qr(t,e,n){return t.startsWith(`${e}/`)?`${n}${t.slice(e.length)}`:void 0}function ti(t,e){let n=`${vm}
373
+ `)}import{existsSync as Fl,readFileSync as dv,rmSync as yp}from"node:fs";import{homedir as kn}from"node:os";import{join as _o}from"node:path";var Fy=44,Vt=[{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 ts(t){let e=Vt.length;return Vt[(t%e+e)%e]}function Mo(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 KH}from"node:crypto";import{existsSync as dl,readFileSync as Im,rmSync as _y}from"node:fs";import{homedir as By}from"node:os";import{join as es}from"node:path";function ri(t){return[`# ${t.name} — ${ie(t)}${t.native?` (${t.native})`:""}`,`# ANSI: ${t.ansiSource}`]}function kr(t,e){return[`[${t}]`,`Color=${ct(e).join(",")}`,""]}function vm(t,e,n=["Wallpaper="]){let r=(i)=>Ht(i,t.background,0.5);return[...kr("Background",t.background),...kr("BackgroundFaint",t.background),...kr("BackgroundIntense",t.background),...t.ansi.slice(0,8).flatMap((i,s)=>[...kr(`Color${s}`,i),...kr(`Color${s}Faint`,r(i)),...kr(`Color${s}Intense`,t.ansi[s+8])]),...kr("Foreground",t.foreground),...kr("ForegroundFaint",r(t.foreground)),...kr("ForegroundIntense",t.foreground),"[General]","Blur=false","ColorRandomization=false",`Description=${e}`,"Opacity=1",...n,""]}var Ly={left:"0",top:"0",center:"0.5",right:"1",bottom:"1"};function LH(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=${Ly[n]??"0.5"},${Ly[e]??"0.5"}`,`WallpaperOpacity=${t.opacity}`]}function Sm(t,e){return[...ri(t),"",...vm(t,`ttheme · ${t.name}`,LH(e))].join(`
374
+ `)}var Em={id:"konsole",limits:"draws no OSC 4, so a tab repaints by switching color scheme",emit(t){return[{path:`konsole/${_(t.name)}.colorscheme`,content:Sm(t)}]}};import{openSync as CH,writeSync as jH}from"node:fs";import{ReadStream as _H}from"node:tty";var gn=["11","10","12","17",...Array.from({length:16},(t,e)=>`4;${e}`)];function Ct(t=process.env){return Boolean(t.NO_COLOR)||t.TERM==="dumb"}function BH(t,e){return`\x1B]${gn[t]};${e}\x1B\\`}function yr(t,e){return[t.background,t.foreground,t.cursor,t.selection,...t.ansi].map((n,r)=>e&&!e.includes(r)?"":BH(r,n)).join("")}function GH(t){return`\x1B]${t.startsWith("4;")?`104;${t.slice(2)}`:`1${t}`}\x1B\\`}function UH(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 Cy(t){return`#${t.slice(t.indexOf(":")+1).split("/").slice(0,3).map((n)=>n.slice(0,2).padStart(2,"0")).join("")}`}function jy(t){return gn.map((e)=>{let n=t.get(e);return n?Cy(n):void 0})}function ll(t,e=[...t.keys()],n=!1){return e.map((r)=>{let i=t.get(r);return i?`\x1B]${r};${n?Cy(i):i}\x1B\\`:GH(r)}).join("")}function fl(t,e){return`\x1B]50;ColorScheme=${t};UseCustomCursorColor=true;customCursorColor=${e}\x07`}function Mm(t=gn,e="\x1B[5n"){return`${t.map((n)=>`\x1B]${n};?\x1B\\`).join("")}${e}`}function WH(t){return t.includes("\x1B[0n")}async function xm(t=gn){let e,n;try{e=CH("/dev/tty","r+"),n=new _H(e),n.setRawMode(!0)}catch{return new Map}try{jH(e,Mm(t));let r="";return await new Promise((i)=>{let s=setTimeout(i,120);n.on("data",(o)=>{if(r+=o.toString(),WH(r))clearTimeout(s),i()})}),UH(r)}finally{n.setRawMode(!1),n.destroy()}}function Rm(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 Zt(t){if(Rm(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 Ee={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 Om(t,e,n){let r="";for(let i of t.split(`
375
+ `)){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 zH(t){let e=t.XDG_CONFIG_HOME??es(By(),".config"),n=es(e,"konsolerc"),r=dl(n)?Om(Im(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=Ky(t).map((u)=>es(u,s)).find((u)=>dl(u));if(!o)return!1;let a=Im(o,"utf8"),c=Om(a,"Interaction Options","AllowEscapedLinks");if(c!==void 0)return c==="true";r=Om(a,"General","Parent")}return!1}function Gy(t){let e=Zt(t);return e==="konsole"?zH(t):Ee[e].links}function xo(t,e){let n=Zt(t),r=Ee[n];return r.pictures&&!t.TMUX&&(!r.views||e.includes(n))}function hl(t){return Ee[Zt(t)].bands}function ml(t){return Ee[Zt(t)].files}function Oo(t){return Ee[Zt(t)].layers}function Uy(t){return Ee[Zt(t)].moves}function Wy(t){return Ee[Zt(t)].wipes===!0}function ns(t){return Ee[Zt(t)].views===!0}function rs(t){return`\x1B]1337;SetUserVar=ttheme_view=${Buffer.from(t).toString("base64")}\x07`}var is="\x1B[H\x1B[K\x1B[2H\x1B[J\x1B[H",Am=120,Pm=4,qH=40;function DH(t){let e=t.TTHEME_ITERM_SHOWN;return t.TTHEME_ITERM_SWITCH==="1"&&t.TTHEME_ITERM_DYED==="0"&&e?`ttheme · ${e}`:void 0}function JH(t,e){let n=Ee.iterm2.repaint??[],r=[...gn.keys()].filter((c)=>!n.includes(c)),i=new Set(n),s=DH(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+=Pm){let f=r.slice(u,u+Pm),l=setTimeout(()=>{for(let d of f)i.add(d);e(yr(c,f))},Am+u/Pm*qH);l.unref?.(),o.push(l)}return yr(c,n)},wear:(c)=>yr(c),saved:()=>xm(),restore(c){a();let u=gn.filter((f,l)=>i.has(l));return s?`\x1B[?2026h${ll(new Map,u)}\x1B]1337;SetProfile=${s}\x07\x1B[?2026l`:ll(c,u)},stop:a}}var YH=3,VH=/^(Wallpaper|FillStyle|Anchor|WallpaperOpacity|WallpaperFlipType)=/;function Ky(t){return[t.XDG_DATA_HOME??es(By(),".local","share"),...(t.XDG_DATA_DIRS||"/usr/local/share:/usr/share").split(":")].map((e)=>es(e,"konsole"))}function ZH(t,e){let n=/(?:^|;)ColorScheme=([^;]+)/.exec(e)?.[1],r=n&&t.map((c)=>es(c,`${n}.colorscheme`)).find((c)=>dl(c));if(!r)return["Wallpaper="];let i=Im(r,"utf8").split(`
376
+ `),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)=>VH.test(c));return a.length>0?a:["Wallpaper="]}function XH(t,e){let n=Ky(t),r=n[0],i=ZH(n,e),s=[],o=(c,u,f)=>{let l=vm(u,`ttheme · ${c}`,i).join(`
377
+ `),d=`${_("view")}.${KH("sha1").update(l).digest("hex").slice(0,10)}`,h=es(r,`${d}.colorscheme`);if(!dl(h))H(h,l);if(!s.includes(h))s.push(h);for(let m of s.splice(0,Math.max(0,s.length-YH)))_y(m,{force:!0});return fl(d,f)},a=()=>{for(let c of s.splice(0))_y(c,{force:!0})};return{slots:[],paint:(c)=>o(c.name,c,c.cursor),wear:(c,u)=>u.includes("konsole")?fl(_(c.name),c.cursor):void 0,saved:async()=>new Map,restore:()=>{return a(),`\x1B]50;${e}\x07`},stop:a}}function zy(t,e,n=(r)=>{process.stdout.write(r)}){let r=Zt(t),i=Ee[r];if(!e||Ct(t)||t.TMUX||!i.paints)return;if(r==="iterm2")return JH(t,n);if(r==="konsole"&&t.TTHEME_KONSOLE_LOOK)return XH(t,t.TTHEME_KONSOLE_LOOK);let s=i.repaint??[...gn.keys()],o=gn.filter((a,c)=>s.includes(c));return{slots:s,paint:(a)=>yr(a,s),wear:(a,c)=>!i.schemes?yr(a):c.includes(r)?fl(_(a.name),a.cursor):void 0,saved:()=>xm(o),restore:(a)=>ll(a,o,i.hex===!0)}}var oe=["ghostty","kitty","alacritty","wezterm","iterm2","windows-terminal","warp","konsole","terminal-app"];var QH=[{section:"tab",title:"This tab"},{section:"startup",title:"New tabs"},{section:"palettes",title:"Palettes"},{section:"own",title:"Your own"},{section:"setup",title:"Setup"},{section:"support",title:"Support"}],Io=[{name:"use",args:["<palette>"],about:"Paint this tab — a unique prefix works: ttheme use ho",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:["[dir|ssh:<host>]"],about:"Pin a palette to a directory or an ssh host — the pin covers everything below it, or its whole repository; cd or ssh in repaints, leaving restores",section:"tab",shell:!0},{name:"unpin",args:["[dir|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 pin as a file tree — the pinned directories in their palettes' 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 marketplaces in a live picker — one list with every marketplace as a row, which ctrl+s narrows to one marketplace at a time",section:"palettes",hidden:!0},{name:"list",args:["[query]"],about:"List palettes, marking what is installed",section:"palettes",flags:{json:{type:"boolean",about:"Print the matches as JSON — name, group, catalog, installed"}}},{name:"add",args:["<palette...>"],about:"Install palettes — from your marketplaces, or from a share link: ttheme add https://ttheme.vercel.app/p/tt2:…",section:"palettes",flags:{marketplace:{type:"string",value:"<source>",about:"Add this marketplace first — a repository, a folder or official — and take bare palette names from it"}}},{name:"remove",args:["<palette...>"],about:"Uninstall palettes",section:"palettes"},{name:"update",args:["[marketplace...]"],about:"Update ttheme and refresh your marketplaces — official palettes come with ttheme; an installed palette from another marketplace keeps its colors until ctrl+r on it in Browse takes its update",section:"palettes"},{name:"marketplace",args:["[action]","[source]"],about:"The marketplaces you added — add, remove and search them; init makes one of your own",actions:[["(none)","List the marketplaces you added — their palettes, auto-update and last update"],["add <source>","Add a marketplace — a repository (alice/ttheme-pastel, #v1 pins a tag or branch), a folder, or official; asks whether it updates on its own"],["remove <marketplace>","Drop one by its name (alice@pastel) — the palettes you installed from it keep working"],["search [query]","The marketplaces on GitHub with the ttheme-marketplace topic, listed every half hour — a query matches names, palettes and descriptions"],["init [name]","Make a marketplace of your own — <you>@<name>, in ~/.config/ttheme/marketplace/<name> or a folder you give"],["check [dir]","Check a marketplace's folder before you push it — ttheme-marketplace.toml, every palette, the renames and the gate; nothing is written"]],section:"palettes"},{name:"new",args:["<name>"],about:"Make a palette of your own in the palette editor — <you>@<marketplace>/<name>, from blank, installed at once",section:"own",flags:{from:{type:"string",value:"<palette>",about:"Start from this palette's colors instead of blank"},in:{type:"string",value:"<marketplace>",about:"The local marketplace to put it in — when you have more than one"}}},{name:"edit",args:["[palette]"],about:"Change a palette in the palette editor — your own in its file, any other as your tone over its marketplace's colors, which R and s in the editor put back; with none named, asks to edit the one this tab wears",section:"own"},{name:"check",args:["[palette]"],about:"Measure a palette against the contrast gate — where it misses, suggest colors that pass; with none named, asks to check the one this tab wears",section:"own",flags:{fix:{type:"boolean",about:"Write the suggested colors into your palette"}}},{name:"share",args:["[palette]"],about:"Print a share link and its QR code — the page shows the palette, and ttheme add <link> installs it anywhere, pictures included; with none named, asks to share the one this tab wears — or shares it without asking when the link goes to a pipe",section:"own",flags:{tone:{type:"string",value:"<tuned|original>",choices:["tuned","original"],about:"Share it as you tuned it, or as it was — asked when you tuned it and omit this"}}},{name:"init",args:[],about:"Install the shell layer and wire your terminals",section:"setup",flags:{yes:{type:"boolean",short:"y",about:"Accept every default without prompting"}}},{name:"uninstall",args:[],about:"Remove ttheme — its block comes out of every terminal config and what it wrote is deleted",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:oe,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 where preview's tuning puts it — preview calls this for a size the terminal cannot scale and for the bands iTerm2 shows",section:"setup",hidden:!0},{name:"tone",args:["<palette>","<action>","[width]"],about:"Print a palette's colors for preview's panel at its width, open them in the palette editor, or reset them to its marketplace's — preview calls this",section:"setup",hidden:!0},{name:"sync",args:[],about:"Write every wired terminal's config again from what is installed and config.zsh — ttheme config and preview call this when TTHEME_TAB_PALETTE changed",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:"latest",args:[],about:"Ask npm for the newest ttheme — any command starts this in the background once a day",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 tF(t){let e=Object.entries(t.flags??{}).map(([n,{value:r}])=>`[--${n}${r?` ${r}`:""}]`);return[t.name,...e,...t.args].join(" ")}function Po(t,e=eF){return t.map(([n,r])=>` ${n.padEnd(e)} ${r}`)}function qy(t){return t.split(" — ")[0]}function Jy(t){return Object.entries(t.flags??{}).map(([e,{short:n,value:r,about:i}])=>[`${n?`-${n}, `:""}--${e}${r?` ${r}`:""}`,i])}function Yy(t,e){let n=e?[...t.actions??[],...Jy(t)]:[];return[[[t.name,...t.args].join(" "),qy(t.about)],...n.map(([r,i])=>[` ${r}`,qy(i)])]}var Vy=[`ttheme ${dt.version}`,dt.description,"Usage: ttheme <command> [options] [args]"],Zy=[["ttheme help","Every command"],["ttheme help all","Every command with its options, and examples"],["ttheme help <command>","One command in full"]],Xy=[["-h, --help","Show help — after a command, that command's"],["-v, --version","Print the version"]],eF=Math.max(...[...Zy,...Xy,...Io.filter((t)=>!t.hidden).flatMap((t)=>Yy(t,!0))].map(([t])=>t.length)),Dy=[["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 Magica catalog as JSON"],["ttheme marketplace add alice/ttheme-pastel","alice's marketplace, alice@pastel — ttheme add alice@pastel/dusk"],["ttheme add dusk --marketplace alice/ttheme-pastel","The same in one step"],["ttheme new rei --from rei","Your own rei, <you>@<marketplace>/rei, to edit and share"]];function Qy(){return[...Vy,"","Use --help to list every command, or init to set ttheme up"].join(`
378
+ `)}function Nm(t){let e=Jy(t);return[`Usage: ttheme ${tF(t)}`,"",t.about,...t.actions?["","Actions:",...Po(t.actions)]:[],...e.length>0?["","Options:",...Po(e)]:[]].join(`
379
+ `)}function Xa(t,e=!1){let n=Io.filter((i)=>!i.hidden&&!(e&&i.section==="setup")),r=QH.filter(({section:i})=>n.some((s)=>s.section===i));return[...Vy,"ttheme alone opens Preview and Browse as tabs — tab and shift+tab move between them","","Getting help:",...Po(Zy),"","Global options:",...Po(Xy),...r.flatMap(({section:i,title:s})=>["",`${s}:`,...Po(n.filter((o)=>o.section===i).flatMap((o)=>Yy(o,t)))]),...t?["","Examples:",...Po(Dy,Math.max(...Dy.map(([i])=>i.length)))]:[],"","https://ttheme.vercel.app"].join(`
380
+ `)}import{readFileSync as nF}from"node:fs";import{join as rF}from"node:path";var Tm="# ttheme begin",Hm="# ttheme end",ss=/# ttheme begin\n[\s\S]*?# ttheme end\n?/,Me="Managed by ttheme — npx @kecan0406/ttheme@latest uninstall takes it out",Gn="Generated by ttheme — rewritten on every add, remove and default; do not edit.";function ii(t,e,n){return t.startsWith(`${e}/`)?`${n}${t.slice(e.length)}`:void 0}function si(t,e){let n=`${Tm}
360
381
  ${e}
361
- ${Sm}
362
- `;if(is.test(t))return t.replace(is,n);if(t==="")return n;return`${t.replace(/\n*$/,`
382
+ ${Hm}
383
+ `;if(ss.test(t))return t.replace(ss,n);if(t==="")return n;return`${t.replace(/\n*$/,`
363
384
  `)}
364
- ${n}`}function jn(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*$/,`
365
- `)}function Mo(t,e){let n=t.replace(is,"");return new RegExp(String.raw`^[ \t]*${e}(?:[ \t]*=|[ \t]+\S)`,"m").test(n)}var al='"${XDG_CONFIG_HOME:-$HOME/.config}/ttheme/ttheme.zsh"';function Wy(){return`# ${ve}
366
- [[ -r ${al} ]] && source ${al}`}var FH="# ttheme settings — uncomment a line to change it; exported variables win over this file",xo={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:"# catalogs and palettes in ttheme and preview: abc sorts them by name, catalog 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_AUTO_UPDATE:{doc:"# checks in the background: on refreshes the marketplaces you set to update on their own once a day and says when a newer ttheme is out; off leaves both to ttheme update (default on)",default:"on"},TTHEME_MARKETPLACE_LOOKUP:{doc:"# GitHub lookups in browse: on looks GitHub up by itself — the marketplaces carrying the ttheme-marketplace topic when browse 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 xo[t]?.default}function Em(t,e){let n=`: \${${t}:=${e}}`;return Da(t)===e?`# ${n}`:n}function Ky(t){return new RegExp(String.raw`^#? ?: \$\{${t}[^\n]*$`,"m")}function CH(t,e){if(Ky(e).test(t))return t;let n=xo[e];return`${t.replace(/\n*$/,`
385
+ ${n}`}function Un(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*$/,`
386
+ `)}function Ro(t,e){let n=t.replace(ss,"");return new RegExp(String.raw`^[ \t]*${e}(?:[ \t]*=|[ \t]+\S)`,"m").test(n)}var pl='"${XDG_CONFIG_HOME:-$HOME/.config}/ttheme/ttheme.zsh"';function t1(){return`# ${Me}
387
+ [[ -r ${pl} ]] && source ${pl}`}var iF="# ttheme settings — uncomment a line to change it; exported variables win over this file",Ao={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:"# catalogs and palettes in ttheme and preview: abc sorts them by name, catalog 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_AUTO_UPDATE:{doc:"# checks in the background: on refreshes the marketplaces you set to update on their own once a day and says when a newer ttheme is out; off leaves both to ttheme update (default on)",default:"on"},TTHEME_MARKETPLACE_LOOKUP:{doc:"# GitHub lookups in browse: on looks GitHub up by itself — the marketplaces carrying the ttheme-marketplace topic when browse 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 Qa(t){return Ao[t]?.default}function Fm(t,e){let n=`: \${${t}:=${e}}`;return Qa(t)===e?`# ${n}`:n}function e1(t){return new RegExp(String.raw`^#? ?: \$\{${t}[^\n]*$`,"m")}function sF(t,e){if(e1(e).test(t))return t;let n=Ao[e];return`${t.replace(/\n*$/,`
367
388
  `)}
368
389
  ${n.doc}
369
- ${Em(e,n.default)}
370
- `}var cl=Object.keys(xo),jH=8;function Oo(t,e){let n="";try{n=HH(LH(t,"ttheme","config.zsh"),"utf8")}catch{}return(new RegExp(String.raw`^: \$\{${e}:=([^}\n]*)\}`,"m").exec(n)?.[1]??xo[e].default).replace(/^(["'])(.*)\1$/,"$2")}function ei(t){let e=Number(Oo(t,"TTHEME_BG_BLUR"));return Number.isFinite(e)?Math.min(jH,Math.max(0,e)):0}function ul(t){return Oo(t,"TTHEME_BG_COLORS")==="original"?"original":"tone"}function Mm(){let t=Object.entries(xo).map(([e,n])=>`${n.doc}
371
- ${Em(e,n.default)}`);return`${[FH,...t].join(`
390
+ ${Fm(e,n.default)}
391
+ `}var gl=Object.keys(Ao),oF=8;function No(t,e){let n="";try{n=nF(rF(t,"ttheme","config.zsh"),"utf8")}catch{}return(new RegExp(String.raw`^: \$\{${e}:=([^}\n]*)\}`,"m").exec(n)?.[1]??Ao[e].default).replace(/^(["'])(.*)\1$/,"$2")}function oi(t){let e=Number(No(t,"TTHEME_BG_BLUR"));return Number.isFinite(e)?Math.min(oF,Math.max(0,e)):0}function bl(t){return No(t,"TTHEME_BG_COLORS")==="original"?"original":"tone"}function Lm(){let t=Object.entries(Ao).map(([e,n])=>`${n.doc}
392
+ ${Fm(e,n.default)}`);return`${[iF,...t].join(`
372
393
 
373
394
  `)}
374
- `}function ll(t,e,n){let r=Em(e,n),i=Ky(e);if(i.test(t))return t.replace(i,r);return`${t.replace(/\n*$/,`
395
+ `}function wl(t,e,n){let r=Fm(e,n),i=e1(e);if(i.test(t))return t.replace(i,r);return`${t.replace(/\n*$/,`
375
396
  `)}
376
397
  ${r}
377
- `}function zy(t){if(t==="")return Mm();return Object.keys(xo).reduce(CH,t)}var fl=/["$`\\]/;function _H(t){return t.replace(/_\([^)]*\)$/,"").replaceAll("_"," ")}function xm(t,e,n=[],r={},i=[]){for(let l of t)for(let d of[l.name,l.catalog??"",l.native??"",...l.nativeNames??[],l.ansiSource])if(fl.test(d))throw Error(`${l.name}: "${d}" contains a character that breaks zsh quoting`);let s=Math.max(0,...t.map((l)=>l.name.length)),o=(l,d)=>` ${l.name.padEnd(s)} "${d}"`,a=(l)=>l.map((d)=>d.name).join(" "),c=It(t),u=(l)=>`'${l.replaceAll("'","'\\''")}'`,f=Eo.filter((l)=>l.section!=="setup"&&!l.hidden);return["# Generated by `mise run build` — do not edit.","# Source of truth: themes/palettes/<catalog>/*.toml in the ttheme repo.","",`typeset -g TTHEME_VERSION=${dt.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}=${u(d)}`)]:[],"","# the commands the shell layer knows (src/verbs.ts): help, completion and argument checks read them",`typeset -ga TTHEME_VERBS=(${f.map((l)=>l.name).join(" ")})`,`typeset -ga TTHEME_TAB_VERBS=(${f.filter((l)=>l.section==="tab").map((l)=>l.name).join(" ")})`,`typeset -ga TTHEME_SHELL_VERBS=(${f.filter((l)=>l.shell).map((l)=>l.name).join(" ")})`,"typeset -gA TTHEME_VERB_ARGS=(",...f.map((l)=>` ${l.name} ${u(l.args.join(" "))}`),")","typeset -gA TTHEME_VERB_ABOUT=(",...f.map((l)=>` ${l.name} ${u(l.about)}`),")",`typeset -g TTHEME_HELP=${u(qa(!1,!0))}`,`typeset -g TTHEME_HELP_ALL=${u(qa(!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=(${fr.map((l)=>l.name).join(" ")})`,`typeset -ga TTHEME_HUB_TITLES=(${fr.map((l)=>l.title).join(" ")})`,`typeset -gi TTHEME_HUB_CLOSED=${Uu} TTHEME_HUB_SWITCH=${Wu}`,"","# the settings config.zsh holds, handed to the CLI on every call",`typeset -ga TTHEME_SETTINGS=(${cl.join(" ")})`,"","# seed for `ttheme config` when no config.zsh exists yet",`typeset -g TTHEME_CONFIG_TEMPLATE='${Mm().trimEnd().replaceAll("'","'\\''")}'`,"","typeset -gA TTHEME_PALETTE=(",...t.map((l)=>o(l,[l.background,l.foreground,l.cursor,l.selection,...l.ansi].join(" "))),")","","# the palettes whose colors your tone moves off their marketplace's (tone.json): lists mark them, and preview's panel offers to reset them",`typeset -ga TTHEME_TUNED=(${t.filter((l)=>i.includes(l.name)).map((l)=>l.name).join(" ")})`,"","# the order palettes were added: new tabs cycle through it and TTHEME_SORT=catalog lists it — the default role stays applyable but unlisted",`typeset -ga TTHEME_ORDER=(${a(c)})`,"","# the same palettes by catalog name, then palette name: TTHEME_SORT=abc lists them this way",`typeset -ga TTHEME_ABC=(${a(Gi(c))})`,"","# the marketplace a palette came from, for every one but the official palettes, whose catalogs head the lists","typeset -gA TTHEME_MARKETPLACE=(",...t.flatMap((l)=>{let d=et(l.name);return d?[o(l,d)]:[]}),")","","# the catalog a palette sits in — the folder under its marketplace's palettes/, one level below a marketplace in every list","typeset -gA TTHEME_CATALOG=(",...t.filter((l)=>l.catalog).map((l)=>o(l,l.catalog??"")),")","","# the catalog's original-language title, rendered dim next to it","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&&!fl.test(l.booru)).map((l)=>o(l,_H(l.booru??""))),")","","# the example scenes preview draws beside the list (src/scenes.ts), each line as «role»text runs",`typeset -ga TTHEME_SCENES=(${Yt.map((l)=>l.name).join(" ")})`,...Yt.flatMap((l,d)=>[`typeset -ga TTHEME_SCENE_${d+1}=(`,...l.lines.map((h)=>` ${u(h)}`),")"]),"","# each booru's ANSI color, which marks a link to one of its posts",`typeset -gA TTHEME_SITE_ANSI=(${Z.map((l)=>`${l.name} ${l.ansi}`).join(" ")})`,"","# the terminals that open OSC 8 links (src/terminal.ts)",`typeset -ga TTHEME_LINKS=(${Object.entries(ye).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,so(l).join(" "))),")","","# where each palette's 16 ANSI colors came from","typeset -gA TTHEME_SRC=(",...t.map((l)=>o(l,l.ansiSource)),")",""].join(`
378
- `)}function qy(t){let e=Object.entries(t).flatMap(([r,i])=>{let s=i.filter((o)=>!fl.test(o)&&!o.includes("|"));return s.length>0&&!fl.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(`
379
- `)}var Om={id:"shell",emitShared(t){return[{path:"shell/palettes.zsh",content:xm(t.map(un))}]}};import{execFileSync as GH}from"node:child_process";import{existsSync as Dy,readdirSync as BH,readFileSync as UH}from"node:fs";import{join as Jy}from"node:path";function ft(t){return Dy(t)?UH(t,"utf8"):""}function ht(t,e){return t.startsWith(`${e}/`)?`~${t.slice(e.length)}`:t}function dl(t){let e=t.split(`
380
- `).filter((n)=>n!==""&&!n.startsWith("#"));return[...new Set(e.map((n)=>n.split(/[ =]/)[0]))].join(", ")}function mn(t,e){let n=ft(t),r=e(n);return r===n?[]:[{file:t,content:r}]}function Ja(t){return process.env.XDG_DATA_HOME??Jy(t,".local","share")}function Po(t){return Dy(t)?BH(t).flatMap((e)=>e.startsWith(j(""))?[Jy(t,e)]:[]):[]}function Pm(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 Xe(){return{platform:process.platform,env:process.env,run:(t,e)=>{try{return GH(t,[...e],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5000}).trim()}catch{return}}}}import{existsSync as Za}from"node:fs";import{join as ri}from"node:path";var WH=["black","red","green","yellow","blue","magenta","cyan","white"];function Yy(t,e){return[t,...WH.map((n,r)=>`${n} = '${e[r]}'`),""].join(`
381
- `)}var Rm={id:"alacritty",limits:"no runtime color API (OSC only)",emit(t){let e=[...Xr(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}'`,"",Yy("[colors.normal]",t.ansi.slice(0,8)),Yy("[colors.bright]",t.ansi.slice(8,16))].join(`
382
- `);return[{path:`alacritty/themes/${j(t.name)}.toml`,content:e}]}};var Im={id:"ghostty",emit(t){let e=[...Xr(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(`
383
- `);return[{path:`ghostty/themes/${j(t.name)}`,content:e}]}};function ni(t){let[e,n,r]=ct(t);return{"Alpha Component":1,"Blue Component":r/255,"Color Space":"P3","Green Component":n/255,"Red Component":e/255}}function Zy(t){return{...Object.fromEntries(t.ansi.map((e,n)=>[`Ansi ${n} Color`,ni(e)])),"Background Color":ni(t.background),"Bold Color":ni(t.foreground),"Cursor Color":ni(t.cursor),"Cursor Text Color":ni(t.background),"Foreground Color":ni(t.foreground),"Selected Text Color":ni(t.foreground),"Selection Color":ni(t.selectionBackground)}}function Vy(t){return t?{"Background Image Location":t.image,"Background Image Mode":t.cover?2:3,Blend:t.opacity}:{"Background Image Location":""}}function Xy(t,e,n,r,i=!1){let s=(c,u)=>({Name:`ttheme · ${u}`,Guid:j(u),...r?{"Dynamic Profile Parent GUID":r}:{},"Use Separate Colors for Light and Dark Mode":!1,...Vy(e.get(c.name)),...Zy(c)}),o={Name:"ttheme · default",Guid:j("default"),"Dynamic Profile Parent GUID":r,...Vy(void 0)},a=[...n?[s(n,"default")]:i&&r?[o]:[],...t.map((c)=>s(c,c.name))];return`${JSON.stringify({Profiles:a},null,2)}
384
- `}function KH(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(`
385
- `)}var Am={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(Zy(t)).map(([n,r])=>KH(n,r)),"</dict>","</plist>",""].join(`
386
- `);return[{path:`iterm2/${j(t.name)}.itermcolors`,content:e}]}};var Nm={id:"kitty",emit(t){let e=[...Xr(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(`
387
- `);return[{path:`kitty/themes/${j(t.name)}.conf`,content:e}]}};function Qy(t){return[`# ${Cn}`,"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(`
388
- `)}function zH(t){let[e]=t;if(!e)throw Error("manifest needs at least one theme");return{...Eu(),palettes:t.map(un)}}var Tm={id:"meta",emitShared(t){return[{path:"manifest.json",content:`${JSON.stringify(zH(t),null,2)}
389
- `}]}};var Hm={id:"terminal-app",limits:"profiles go into its own settings at init, so the archive carries none"};import{createHash as qH}from"node:crypto";var DH=["black","red","green","yellow","blue","magenta","cyan","white"];function t1(t,e){return[` ${t}:`,...DH.map((n,r)=>` ${n}: "${e[r]}"`)]}function JH(t,e,n){let r=qH("sha1");for(let i of e)r.update(i);return`${j(t)}.${r.digest("hex").slice(0,8)}.${n}`}function e1(t,e,n){let r=2166136261;for(let i of Buffer.from(`${e}
390
- ${n.toLowerCase()}`,"utf8"))r=Math.imul(r^i,16777619)>>>0;return`${j(t)}.${r.toString(16).padStart(8,"0")}.png`}function Ya(t,e){return e?JH(t,[e.image,String(n1(e))],"yaml"):`${j(t)}.yaml`}function n1(t){return Math.max(0,Math.min(100,Math.round(t.opacity*100)))}function Va(t,e){return[`name: "${t.name}"`,`background: "${t.background}"`,`foreground: "${t.foreground}"`,`accent: "${t.cursor}"`,`cursor: "${t.cursor}"`,`details: ${Mt(t.background)<0.18?"darker":"lighter"}`,...e?["background_image:",` path: "${e.image}"`,` opacity: ${n1(e)}`]:[],"terminal_colors:",...t1("normal",t.ansi.slice(0,8)),...t1("bright",t.ansi.slice(8,16)),""].join(`
391
- `)}var Lm={id:"warp",limits:"no selection color, and Warp paints one theme app-wide",emit(t){return[{path:`warp/themes/${Ya(t.name)}`,content:Va(t)}]}};var r1=(t)=>`[${t.map((e)=>`"${e}"`).join(", ")}]`,Fm={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 = ${r1(t.ansi.slice(0,8))}`,`brights = ${r1(t.ansi.slice(8,16))}`,""].join(`
392
- `);return[{path:`wezterm/colors/${j(t.name)}.toml`,content:e}]}},Ro=(t)=>JSON.stringify(t);function i1(t){return[`-- ${Cn}`,"local wezterm = require 'wezterm'","",`local MODULE = ${Ro(t.path)}`,`local COLORS = ${Ro(t.colors)}`,`local BACKGROUNDS = ${Ro(t.backgrounds)}`,`local STARTUP = ${t.startup?Ro(j(t.startup)):"nil"}`,"local PALETTES = {",...t.palettes.map((e)=>` [${Ro(e.name)}] = ${Ro(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(`
393
- `)}var s1=["black","red","green","yellow","blue","purple","cyan","white"];function o1(t){return{name:j(t.name),background:t.background,foreground:t.foreground,cursorColor:t.cursor,selectionBackground:t.selectionBackground,...Object.fromEntries(s1.map((e,n)=>[e,t.ansi[n]])),...Object.fromEntries(s1.map((e,n)=>[`bright${e[0]?.toUpperCase()}${e.slice(1)}`,t.ansi[n+8]]))}}function Cm(t,e,n){let r={...e&&n?{profiles:[{updates:e,colorScheme:j(n)}]}:{},schemes:t.map(o1)};return`${JSON.stringify(r,null,2)}
394
- `}var jm={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(o1(t),null,2)}
395
- `}]},emitShared(t){return[{path:"windows-terminal/ttheme.json",content:Cm(t)}]}};function YH(t){let e=t.replace(is,"");return/^[ \t]*\[colors[\].]/m.test(e)||/^[ \t]*colors[ \t]*[.=]/m.test(e)}var VH=/^[ \t]*\[general\][ \t]*(?:#.*)?\r?$/m,a1=/^[ \t]*\[/m,c1=/^[ \t]*import[ \t]*=/m,ZH=/^[ \t]*general[ \t]*[.=]/m;function Bm(t){return`import = [${JSON.stringify(t)}]`}function _m(t,e){let n=t.replace(is,""),r=VH.exec(n);if(!r){let a=n.search(a1),c=a<0?n:n.slice(0,a);if(ZH.test(n)||c1.test(c))return;return ti(t,`# ${ve}
398
+ `}function n1(t){if(t==="")return Lm();return Object.keys(Ao).reduce(sF,t)}var $l=/["$`\\]/;function aF(t){return t.replace(/_\([^)]*\)$/,"").replaceAll("_"," ")}function Cm(t,e,n=[],r={},i=[]){for(let l of t)for(let d of[l.name,l.catalog??"",l.native??"",...l.nativeNames??[],l.ansiSource])if($l.test(d))throw Error(`${l.name}: "${d}" contains a character that breaks zsh quoting`);let s=Math.max(0,...t.map((l)=>l.name.length)),o=(l,d)=>` ${l.name.padEnd(s)} "${d}"`,a=(l)=>l.map((d)=>d.name).join(" "),c=At(t),u=(l)=>`'${l.replaceAll("'","'\\''")}'`,f=Io.filter((l)=>l.section!=="setup"&&!l.hidden);return["# Generated by `mise run build` — do not edit.","# Source of truth: themes/palettes/<catalog>/*.toml in the ttheme repo.","",`typeset -g TTHEME_VERSION=${dt.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}=${u(d)}`)]:[],"","# the commands the shell layer knows (src/verbs.ts): help, completion and argument checks read them",`typeset -ga TTHEME_VERBS=(${f.map((l)=>l.name).join(" ")})`,`typeset -ga TTHEME_TAB_VERBS=(${f.filter((l)=>l.section==="tab").map((l)=>l.name).join(" ")})`,`typeset -ga TTHEME_SHELL_VERBS=(${f.filter((l)=>l.shell).map((l)=>l.name).join(" ")})`,"typeset -gA TTHEME_VERB_ARGS=(",...f.map((l)=>` ${l.name} ${u(l.args.join(" "))}`),")","typeset -gA TTHEME_VERB_ABOUT=(",...f.map((l)=>` ${l.name} ${u(l.about)}`),")",`typeset -g TTHEME_HELP=${u(Xa(!1,!0))}`,`typeset -g TTHEME_HELP_ALL=${u(Xa(!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=(${gr.map((l)=>l.name).join(" ")})`,`typeset -ga TTHEME_HUB_TITLES=(${gr.map((l)=>l.title).join(" ")})`,`typeset -gi TTHEME_HUB_CLOSED=${Vu} TTHEME_HUB_SWITCH=${Zu}`,"","# the settings config.zsh holds, handed to the CLI on every call",`typeset -ga TTHEME_SETTINGS=(${gl.join(" ")})`,"","# seed for `ttheme config` when no config.zsh exists yet",`typeset -g TTHEME_CONFIG_TEMPLATE='${Lm().trimEnd().replaceAll("'","'\\''")}'`,"","typeset -gA TTHEME_PALETTE=(",...t.map((l)=>o(l,[l.background,l.foreground,l.cursor,l.selection,...l.ansi].join(" "))),")","","# the palettes whose colors your tone moves off their marketplace's (tone.json): lists mark them, and preview's panel offers to reset them",`typeset -ga TTHEME_TUNED=(${t.flatMap((l)=>i.includes(l.name)?[l.name]:[]).join(" ")})`,"","# the order palettes were added: new tabs cycle through it and TTHEME_SORT=catalog lists it — the default role stays applyable but unlisted",`typeset -ga TTHEME_ORDER=(${a(c)})`,"","# the same palettes by catalog name, then palette name: TTHEME_SORT=abc lists them this way",`typeset -ga TTHEME_ABC=(${a(Gi(c))})`,"","# the marketplace a palette came from, for every one but the official palettes, whose catalogs head the lists","typeset -gA TTHEME_MARKETPLACE=(",...t.flatMap((l)=>{let d=et(l.name);return d?[o(l,d)]:[]}),")","","# the catalog a palette sits in — the folder under its marketplace's palettes/, one level below a marketplace in every list","typeset -gA TTHEME_CATALOG=(",...t.flatMap((l)=>l.catalog?[o(l,l.catalog)]:[]),")","","# the catalog's original-language title, rendered dim next to it","typeset -gA TTHEME_NATIVE=(",...t.flatMap((l)=>l.native?[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.flatMap((l)=>l.nativeNames?[o(l,l.nativeNames.join("|"))]:[]),")","typeset -gA TTHEME_CHARACTER=(",...t.flatMap((l)=>l.booru&&!$l.test(l.booru)?[o(l,aF(l.booru))]:[]),")","","# the example scenes preview draws beside the list (src/scenes.ts), each line as «role»text runs",`typeset -ga TTHEME_SCENES=(${Vt.map((l)=>l.name).join(" ")})`,...Vt.flatMap((l,d)=>[`typeset -ga TTHEME_SCENE_${d+1}=(`,...l.lines.map((h)=>` ${u(h)}`),")"]),"","# each booru's ANSI color, which marks a link to one of its posts",`typeset -gA TTHEME_SITE_ANSI=(${Z.map((l)=>`${l.name} ${l.ansi}`).join(" ")})`,"","# the terminals that open OSC 8 links (src/terminal.ts)",`typeset -ga TTHEME_LINKS=(${Object.entries(Ee).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,lo(l).join(" "))),")","","# where each palette's 16 ANSI colors came from","typeset -gA TTHEME_SRC=(",...t.map((l)=>o(l,l.ansiSource)),")",""].join(`
399
+ `)}function r1(t){let e=Object.entries(t).flatMap(([r,i])=>{let s=i.filter((o)=>!$l.test(o)&&!o.includes("|"));return s.length>0&&!$l.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(`
400
+ `)}var jm={id:"shell",emitShared(t){return[{path:"shell/palettes.zsh",content:Cm(t.map(dn))}]}};import{execFileSync as cF}from"node:child_process";import{existsSync as i1,readdirSync as uF,readFileSync as lF}from"node:fs";import{join as s1}from"node:path";function ft(t){return i1(t)?lF(t,"utf8"):""}function ht(t,e){return t.startsWith(`${e}/`)?`~${t.slice(e.length)}`:t}function kl(t){let e=t.split(`
401
+ `).filter((n)=>n!==""&&!n.startsWith("#"));return[...new Set(e.map((n)=>n.split(/[ =]/)[0]))].join(", ")}function bn(t,e){let n=ft(t),r=e(n);return r===n?[]:[{file:t,content:r}]}function tc(t){return process.env.XDG_DATA_HOME??s1(t,".local","share")}function To(t){return i1(t)?uF(t).flatMap((e)=>e.startsWith(_(""))?[s1(t,e)]:[]):[]}function _m(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 Qe(){return{platform:process.platform,env:process.env,run:(t,e)=>{try{return cF(t,[...e],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5000}).trim()}catch{return}}}}import{existsSync as rc}from"node:fs";import{join as ci}from"node:path";var fF=["black","red","green","yellow","blue","magenta","cyan","white"];function o1(t,e){return[t,...fF.map((n,r)=>`${n} = '${e[r]}'`),""].join(`
402
+ `)}var Bm={id:"alacritty",limits:"no runtime color API (OSC only)",emit(t){let e=[...ri(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}'`,"",o1("[colors.normal]",t.ansi.slice(0,8)),o1("[colors.bright]",t.ansi.slice(8,16))].join(`
403
+ `);return[{path:`alacritty/themes/${_(t.name)}.toml`,content:e}]}};var Gm={id:"ghostty",emit(t){let e=[...ri(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(`
404
+ `);return[{path:`ghostty/themes/${_(t.name)}`,content:e}]}};function ai(t){let[e,n,r]=ct(t);return{"Alpha Component":1,"Blue Component":r/255,"Color Space":"P3","Green Component":n/255,"Red Component":e/255}}function c1(t){return{...Object.fromEntries(t.ansi.map((e,n)=>[`Ansi ${n} Color`,ai(e)])),"Background Color":ai(t.background),"Bold Color":ai(t.foreground),"Cursor Color":ai(t.cursor),"Cursor Text Color":ai(t.background),"Foreground Color":ai(t.foreground),"Selected Text Color":ai(t.foreground),"Selection Color":ai(t.selectionBackground)}}function a1(t){return t?{"Background Image Location":t.image,"Background Image Mode":t.cover?2:3,Blend:t.opacity}:{"Background Image Location":""}}function u1(t,e,n,r,i=!1){let s=(c,u)=>({Name:`ttheme · ${u}`,Guid:_(u),...r?{"Dynamic Profile Parent GUID":r}:{},"Use Separate Colors for Light and Dark Mode":!1,...a1(e.get(c.name)),...c1(c)}),o={Name:"ttheme · default",Guid:_("default"),"Dynamic Profile Parent GUID":r,...a1(void 0)},a=[...n?[s(n,"default")]:i&&r?[o]:[],...t.map((c)=>s(c,c.name))];return`${JSON.stringify({Profiles:a},null,2)}
405
+ `}function dF(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(`
406
+ `)}var Um={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(c1(t)).map(([n,r])=>dF(n,r)),"</dict>","</plist>",""].join(`
407
+ `);return[{path:`iterm2/${_(t.name)}.itermcolors`,content:e}]}};var Wm={id:"kitty",emit(t){let e=[...ri(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(`
408
+ `);return[{path:`kitty/themes/${_(t.name)}.conf`,content:e}]}};function l1(t){return[`# ${Gn}`,"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(`
409
+ `)}function hF(t){let[e]=t;if(!e)throw Error("manifest needs at least one theme");return{...Nu(),palettes:t.map(dn)}}var Km={id:"meta",emitShared(t){return[{path:"manifest.json",content:`${JSON.stringify(hF(t),null,2)}
410
+ `}]}};var zm={id:"terminal-app",limits:"profiles go into its own settings at init, so the archive carries none"};import{createHash as mF}from"node:crypto";var pF=["black","red","green","yellow","blue","magenta","cyan","white"];function f1(t,e){return[` ${t}:`,...pF.map((n,r)=>` ${n}: "${e[r]}"`)]}function gF(t,e,n){let r=mF("sha1");for(let i of e)r.update(i);return`${_(t)}.${r.digest("hex").slice(0,8)}.${n}`}function d1(t,e,n){let r=2166136261;for(let i of Buffer.from(`${e}
411
+ ${n.toLowerCase()}`,"utf8"))r=Math.imul(r^i,16777619)>>>0;return`${_(t)}.${r.toString(16).padStart(8,"0")}.png`}function ec(t,e){return e?gF(t,[e.image,String(h1(e))],"yaml"):`${_(t)}.yaml`}function h1(t){return Math.max(0,Math.min(100,Math.round(t.opacity*100)))}function nc(t,e){return[`name: "${t.name}"`,`background: "${t.background}"`,`foreground: "${t.foreground}"`,`accent: "${t.cursor}"`,`cursor: "${t.cursor}"`,`details: ${xt(t.background)<0.18?"darker":"lighter"}`,...e?["background_image:",` path: "${e.image}"`,` opacity: ${h1(e)}`]:[],"terminal_colors:",...f1("normal",t.ansi.slice(0,8)),...f1("bright",t.ansi.slice(8,16)),""].join(`
412
+ `)}var qm={id:"warp",limits:"no selection color, and Warp paints one theme app-wide",emit(t){return[{path:`warp/themes/${ec(t.name)}`,content:nc(t)}]}};var m1=(t)=>`[${t.map((e)=>`"${e}"`).join(", ")}]`,Dm={id:"wezterm",limits:"OSC repaints per pane, pictures show per window",emit(t){let e=["[metadata]",`name = "${_(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 = ${m1(t.ansi.slice(0,8))}`,`brights = ${m1(t.ansi.slice(8,16))}`,""].join(`
413
+ `);return[{path:`wezterm/colors/${_(t.name)}.toml`,content:e}]}},Ho=(t)=>JSON.stringify(t);function p1(t){return[`-- ${Gn}`,"local wezterm = require 'wezterm'","",`local MODULE = ${Ho(t.path)}`,`local COLORS = ${Ho(t.colors)}`,`local BACKGROUNDS = ${Ho(t.backgrounds)}`,`local STARTUP = ${t.startup?Ho(_(t.startup)):"nil"}`,"local PALETTES = {",...t.palettes.map((e)=>` [${Ho(e.name)}] = ${Ho(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(`
414
+ `)}var g1=["black","red","green","yellow","blue","purple","cyan","white"];function b1(t){return{name:_(t.name),background:t.background,foreground:t.foreground,cursorColor:t.cursor,selectionBackground:t.selectionBackground,...Object.fromEntries(g1.map((e,n)=>[e,t.ansi[n]])),...Object.fromEntries(g1.map((e,n)=>[`bright${e[0]?.toUpperCase()}${e.slice(1)}`,t.ansi[n+8]]))}}function Jm(t,e,n){let r={...e&&n?{profiles:[{updates:e,colorScheme:_(n)}]}:{},schemes:t.map(b1)};return`${JSON.stringify(r,null,2)}
415
+ `}var Ym={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/${_(t.name)}.json`,content:`${JSON.stringify(b1(t),null,2)}
416
+ `}]},emitShared(t){return[{path:"windows-terminal/ttheme.json",content:Jm(t)}]}};function bF(t){let e=t.replace(ss,"");return/^[ \t]*\[colors[\].]/m.test(e)||/^[ \t]*colors[ \t]*[.=]/m.test(e)}var wF=/^[ \t]*\[general\][ \t]*(?:#.*)?\r?$/m,w1=/^[ \t]*\[/m,$1=/^[ \t]*import[ \t]*=/m,$F=/^[ \t]*general[ \t]*[.=]/m;function Xm(t){return`import = [${JSON.stringify(t)}]`}function Vm(t,e){let n=t.replace(ss,""),r=wF.exec(n);if(!r){let a=n.search(w1),c=a<0?n:n.slice(0,a);if($F.test(n)||$1.test(c))return;return si(t,`# ${Me}
396
417
  [general]
397
- ${Bm(e)}`)}let i=r.index+r[0].length,s=n.slice(i),o=s.search(a1);if(c1.test(o<0?s:s.slice(0,o)))return;return`${n.slice(0,i)}
398
- ${vm}
399
- # ${ve}
400
- ${Bm(e)}
401
- ${Sm}${s}`}function u1(t){return[...new Set([ri(t.configHome,"alacritty","alacritty.toml"),ri(t.configHome,"alacritty.toml"),ri(t.home,".config","alacritty","alacritty.toml"),ri(t.home,".alacritty.toml")])]}function XH(t){let e=ft(t);return is.test(e)&&jn(e)===""&&!Za(da(t))}function Gm(t){let e=u1(t),n=e.filter(XH),r=e.find((s)=>Za(s)&&!n.includes(s)),i=r?void 0:e.map((s)=>s.replace(/\.toml$/,".yml")).find((s)=>Za(s));if(!r&&!i)return{file:n[0]??e[0]};return{file:r??e[0],...i?{yaml:i}:{},...n.length>0?{leftover:n}:{}}}function Um(t){return ri(t,"ttheme","alacritty.toml")}function QH(t){return[`# ${Cn}`,...t?["[general]",Bm(t)]:[],""].join(`
402
- `)}function hl(t){let e=Um(t.configHome);return Qr(e,t.home,"~")??e}function l1(t){return ri(t.configHome,"alacritty","themes")}function tL(t){return t.startup?ri(l1(t),`${j(t.startup)}.toml`):void 0}var Wm={id:"alacritty",name:"Alacritty",emitter:Rm,shelf:{from:"themes",dir:l1},offered:()=>!0,present:(t)=>Za(ri(t.configHome,"alacritty")),sync(t,e){e.themes(Wm),e.write(Um(t.configHome),QH(tL(t)));let n=Gm(t);for(let i of n.leftover??[])e.remove(i);let r=n.yaml?void 0:_m(ft(n.file),hl(t));if(r!==void 0)e.wire(n.file,r)},plan(t){let e=Gm(t);return!e.yaml&&_m(ft(e.file),hl(t))!==void 0?[`Edit ${ht(e.file,t.home)} — a ttheme block: general.import`,`Write ${ht(Um(t.configHome),t.home)} — general.import`]:[]},notes(t){let e=Gm(t),n=(e.leftover??[]).map((i)=>`${ht(i,t.home)} held only ttheme's import and hid ${ht(e.yaml??e.file,t.home)} from Alacritty — ttheme removed it`);if(e.yaml)return[...n,`${ht(e.yaml,t.home)} is the config Alacritty reads, and ttheme edits TOML only — \`alacritty migrate\` converts it, and ttheme wires the TOML at its next add, remove or default`];let r=ft(e.file);return[...n,...Za(e.file)&&_m(r,hl(t))===void 0?[`${ht(e.file,t.home)} already imports files under [general] — ttheme left it alone; add ${hl(t)} to that import list yourself`]:[],...t.startup&&YH(r)?[`${ht(e.file,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:u1(t).flatMap((e)=>mn(e,jn)),removals:[],touches:[]})};import{existsSync as eL}from"node:fs";import{join as pn}from"node:path";var nL=["background","foreground","palette","cursor-color","cursor-text","selection-background","selection-foreground"];function ml(t){return pn(t,"ghostty","config")}function f1(t){return pn(t,"ttheme","ghostty.conf")}function rL(t,e=process.platform){let n=pn(t.home,"Library","Application Support","com.mitchellh.ghostty");return[ml(t.configHome),pn(t.configHome,"ghostty","config.ghostty"),...e==="darwin"?[pn(n,"config"),pn(n,"config.ghostty")]:[]]}function pl(t,e){return rL(t).find((n)=>Mo(ft(n),e))}function iL(t,e){let n=pn(t,"ghostty.conf");return`# ${ve}
403
- config-file = ?${Qr(n,e,"~")??n}`}function sL(t,e,n,r){return[`# ${Cn}`,...n?[`command = ${t}/launch-tab.zsh`,...r?["shell-integration = zsh"]:[]]:[],...e?[`theme = ${j(e)}`]:[],"config-file = ?backgrounds/shown.conf",""].join(`
404
- `)}function h1(t){return Oo(t.configHome,"TTHEME_TAB_PALETTE")!=="off"}function d1(t){return sL(pn(t.configHome,"ttheme"),t.startup,h1(t)&&pl(t,"command")===void 0,pl(t,"shell-integration")===void 0)}var Km={id:"ghostty",name:"Ghostty",emitter:Im,shelf:{from:"themes",dir:(t)=>pn(t.configHome,"ghostty","themes")},offered:()=>!0,present:(t)=>eL(pn(t.configHome,"ghostty")),sync(t,e){e.themes(Km),e.write(f1(t.configHome),d1(t));let n=ml(t.configHome);e.wire(n,ti(ft(n),iL(pn(t.configHome,"ttheme"),t.home)))},plan(t){return[`Edit ${ht(ml(t.configHome),t.home)} — a ttheme block: config-file`,`Write ${ht(f1(t.configHome),t.home)} — ${dl(d1(t))}`]},notes(t){let e=pl(t,"command"),n=t.startup?nL.map((r)=>pl(t,r)).find(Boolean):void 0;return[...e&&h1(t)?[`${ht(e,t.home)} sets its own command — ttheme leaves it, so a new tab takes its palette once zsh starts`]:[],...n?[`${ht(n,t.home)} sets its own colors, which win over a theme — remove them to open with ttheme's`]:[]]},next:()=>["Restart Ghostty New tabs pick up its config"],unwire:(t)=>({edits:mn(ml(t.configHome),jn),removals:[],touches:[]})};import{existsSync as m1}from"node:fs";import{join as b1}from"node:path";var zm="ttheme-default";function Io(t){return b1(t,"Library","Application Support","iTerm2","DynamicProfiles","ttheme.json")}function w1(t){return t.itermBase!==void 0&&t.palettes.length>0}function p1(t){let e=X(t.configHome),n=new Map;for(let i of t.themes){let s=He(e,i.name,t.home);if(s)n.set(i.name,s)}let r=new Set(It(t.entries).map((i)=>i.name));return Xy(t.themes.filter((i)=>r.has(i.name)),n,t.themes.find((i)=>i.name===t.startup),t.state.itermBase,w1(t.state))}function qm(t){return t.env.TTHEME_ITERM_SUITE??"com.googlecode.iterm2"}function g1(t){return t.run("defaults",["read",qm(t),"Default Bookmark Guid"])||void 0}function oL(t){return t.run("defaults",["read",qm(t),"PreventEscapeSequenceFromChangingProfile"])==="0"}var aL={key:"itermBase",profile:()=>"ttheme · default",base(t){let e=g1(t.host);return e&&!e.startsWith("ttheme-")?{...t.state,itermBase:e}:t.state},point(t,e){let n=g1(t.host),r=t.startup?e||n===zm?zm:void 0:n===zm&&!w1(t.state)?t.state.itermBase:void 0;if(!r||r===n)return;return t.host.run("defaults",["write",qm(t.host),"Default Bookmark Guid","-string",r]),{restart:Boolean(t.host.run("pgrep",["-x","iTerm2"]))}}},$1={id:"iterm2",name:"iTerm2",emitter:Am,bakes:!0,offered:(t,e)=>e.platform==="darwin",present:(t)=>m1(b1(t.home,"Library","Application Support","iTerm2")),sync(t,e){e.write(Io(t.home),p1(t))},pictures(t,e){e.write(Io(t.home),p1(t))},layer:(t,e)=>({TTHEME_ITERM_SWITCH:oL(e)?"1":"",TTHEME_ITERM_PROFILES:Io(t.home)}),plan:(t)=>[`Write ${ht(Io(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:m1(Io(t.home))?[Io(t.home)]:[],touches:[]}),defaults:aL};import{existsSync as cL}from"node:fs";import{join as ii}from"node:path";function uL(t,e){let n=ii(t,"kitty.conf");return`# ${ve}
405
- include ${Qr(n,e,"~")??n}`}function lL(t,e,n=""){return[`# ${Cn}`,...t?[`include ${t}`]:[],`watcher ${e}`,...["window_logo_scale 100","window_logo_alpha 1"].filter((r)=>!Mo(n,r.split(" ")[0])),""].join(`
406
- `)}function Xa(t){return ii(t,"kitty","kitty.conf")}function k1(t){return ii(t,"ttheme","kitty.conf")}function v1(t){return ii(t,"ttheme","kitty.py")}function Dm(t){return ii(t.configHome,"kitty","themes")}function y1(t){return lL(t.startup&&ii(Dm(t),`${j(t.startup)}.conf`),v1(t.configHome),ft(Xa(t.configHome)))}var Jm={id:"kitty",name:"kitty",emitter:Nm,shelf:{from:"themes",dir:Dm},offered:()=>!0,present:(t)=>cL(ii(t.configHome,"kitty")),sync(t,e){e.themes(Jm),e.write(v1(t.configHome),Qy({themes:Dm(t),backgrounds:X(t.configHome)})),e.write(k1(t.configHome),y1(t));let n=Xa(t.configHome);e.wire(n,ti(ft(n),uL(ii(t.configHome,"ttheme"),t.home)))},plan(t){return[`Edit ${ht(Xa(t.configHome),t.home)} — a ttheme block: include`,`Write ${ht(k1(t.configHome),t.home)} — ${dl(y1(t))}`]},notes(t){let e=ft(Xa(t.configHome));return Mo(e,"window_logo_scale")||Mo(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:mn(Xa(t.configHome),jn),removals:[],touches:[]})};import{createHash as fL}from"node:crypto";import{existsSync as gl}from"node:fs";import{basename as E1,isAbsolute as dL,join as ss}from"node:path";function Ao(t){return ss(Ja(t),"konsole")}function Qa(t){return ss(t,"konsolerc")}function M1(t){return`${j(t)}.profile`}function tc(t){return`ttheme · ${t}`}function x1(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 Ym(t){return new RegExp(String.raw`^\s*${t}\s*=`)}function si(t,e,n){let r=t.split(`
407
- `),i=x1(r,e);return(i&&r.slice(i[0]+1,i[1]).find((o)=>Ym(n).test(o)))?.replace(Ym(n),"").trim()}function O1(t,e){let n=t.split(`
408
- `),r=x1(n,"Desktop Entry"),i=e===void 0?[]:[`DefaultProfile=${e}`];if(!r)return e===void 0?t:`${t===""?"":t.replace(/\n*$/,`
418
+ ${Xm(e)}`)}let i=r.index+r[0].length,s=n.slice(i),o=s.search(w1);if($1.test(o<0?s:s.slice(0,o)))return;return`${n.slice(0,i)}
419
+ ${Tm}
420
+ # ${Me}
421
+ ${Xm(e)}
422
+ ${Hm}${s}`}function k1(t){return[...new Set([ci(t.configHome,"alacritty","alacritty.toml"),ci(t.configHome,"alacritty.toml"),ci(t.home,".config","alacritty","alacritty.toml"),ci(t.home,".alacritty.toml")])]}function kF(t){let e=ft(t);return ss.test(e)&&Un(e)===""&&!rc(ba(t))}function Zm(t){let e=k1(t),n=e.filter(kF),r=e.find((s)=>rc(s)&&!n.includes(s)),i=r?void 0:e.map((s)=>s.replace(/\.toml$/,".yml")).find((s)=>rc(s));if(!r&&!i)return{file:n[0]??e[0]};return{file:r??e[0],...i?{yaml:i}:{},...n.length>0?{leftover:n}:{}}}function Qm(t){return ci(t,"ttheme","alacritty.toml")}function yF(t){return[`# ${Gn}`,...t?["[general]",Xm(t)]:[],""].join(`
423
+ `)}function yl(t){let e=Qm(t.configHome);return ii(e,t.home,"~")??e}function y1(t){return ci(t.configHome,"alacritty","themes")}function vF(t){return t.startup?ci(y1(t),`${_(t.startup)}.toml`):void 0}var tp={id:"alacritty",name:"Alacritty",emitter:Bm,shelf:{from:"themes",dir:y1},offered:()=>!0,present:(t)=>rc(ci(t.configHome,"alacritty")),sync(t,e){e.themes(tp),e.write(Qm(t.configHome),yF(vF(t)));let n=Zm(t);for(let i of n.leftover??[])e.remove(i);let r=n.yaml?void 0:Vm(ft(n.file),yl(t));if(r!==void 0)e.wire(n.file,r)},plan(t){let e=Zm(t);return!e.yaml&&Vm(ft(e.file),yl(t))!==void 0?[`Edit ${ht(e.file,t.home)} — a ttheme block: general.import`,`Write ${ht(Qm(t.configHome),t.home)} — general.import`]:[]},notes(t){let e=Zm(t),n=(e.leftover??[]).map((i)=>`${ht(i,t.home)} held only ttheme's import and hid ${ht(e.yaml??e.file,t.home)} from Alacritty — ttheme removed it`);if(e.yaml)return[...n,`${ht(e.yaml,t.home)} is the config Alacritty reads, and ttheme edits TOML only — \`alacritty migrate\` converts it, and ttheme wires the TOML at its next add, remove or default`];let r=ft(e.file);return[...n,...rc(e.file)&&Vm(r,yl(t))===void 0?[`${ht(e.file,t.home)} already imports files under [general] — ttheme left it alone; add ${yl(t)} to that import list yourself`]:[],...t.startup&&bF(r)?[`${ht(e.file,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:k1(t).flatMap((e)=>bn(e,Un)),removals:[],touches:[]})};import{existsSync as SF}from"node:fs";import{join as wn}from"node:path";var EF=["background","foreground","palette","cursor-color","cursor-text","selection-background","selection-foreground"];function vl(t){return wn(t,"ghostty","config")}function v1(t){return wn(t,"ttheme","ghostty.conf")}function MF(t,e=process.platform){let n=wn(t.home,"Library","Application Support","com.mitchellh.ghostty");return[vl(t.configHome),wn(t.configHome,"ghostty","config.ghostty"),...e==="darwin"?[wn(n,"config"),wn(n,"config.ghostty")]:[]]}function Sl(t,e){return MF(t).find((n)=>Ro(ft(n),e))}function xF(t,e){let n=wn(t,"ghostty.conf");return`# ${Me}
424
+ config-file = ?${ii(n,e,"~")??n}`}function OF(t,e,n,r){return[`# ${Gn}`,...n?[`command = ${t}/launch-tab.zsh`,...r?["shell-integration = zsh"]:[]]:[],...e?[`theme = ${_(e)}`]:[],"config-file = ?backgrounds/shown.conf",""].join(`
425
+ `)}function E1(t){return No(t.configHome,"TTHEME_TAB_PALETTE")!=="off"}function S1(t){return OF(wn(t.configHome,"ttheme"),t.startup,E1(t)&&Sl(t,"command")===void 0,Sl(t,"shell-integration")===void 0)}var ep={id:"ghostty",name:"Ghostty",emitter:Gm,shelf:{from:"themes",dir:(t)=>wn(t.configHome,"ghostty","themes")},offered:()=>!0,present:(t)=>SF(wn(t.configHome,"ghostty")),sync(t,e){e.themes(ep),e.write(v1(t.configHome),S1(t));let n=vl(t.configHome);e.wire(n,si(ft(n),xF(wn(t.configHome,"ttheme"),t.home)))},plan(t){return[`Edit ${ht(vl(t.configHome),t.home)} — a ttheme block: config-file`,`Write ${ht(v1(t.configHome),t.home)} — ${kl(S1(t))}`]},notes(t){let e=Sl(t,"command"),n=t.startup?EF.map((r)=>Sl(t,r)).find(Boolean):void 0;return[...e&&E1(t)?[`${ht(e,t.home)} sets its own command — ttheme leaves it, so a new tab takes its palette once zsh starts`]:[],...n?[`${ht(n,t.home)} sets its own colors, which win over a theme — remove them to open with ttheme's`]:[]]},next:()=>["Restart Ghostty New tabs pick up its config"],unwire:(t)=>({edits:bn(vl(t.configHome),Un),removals:[],touches:[]})};import{existsSync as M1}from"node:fs";import{join as P1}from"node:path";var np="ttheme-default";function Fo(t){return P1(t,"Library","Application Support","iTerm2","DynamicProfiles","ttheme.json")}function I1(t){return t.itermBase!==void 0&&t.palettes.length>0}function x1(t){let e=X(t.configHome),n=new Map;for(let i of t.themes){let s=Fe(e,i.name,t.home);if(s)n.set(i.name,s)}let r=new Set(At(t.entries).map((i)=>i.name));return u1(t.themes.filter((i)=>r.has(i.name)),n,t.themes.find((i)=>i.name===t.startup),t.state.itermBase,I1(t.state))}function rp(t){return t.env.TTHEME_ITERM_SUITE??"com.googlecode.iterm2"}function O1(t){return t.run("defaults",["read",rp(t),"Default Bookmark Guid"])||void 0}function PF(t){return t.run("defaults",["read",rp(t),"PreventEscapeSequenceFromChangingProfile"])==="0"}var IF={key:"itermBase",profile:()=>"ttheme · default",base(t){let e=O1(t.host);return e&&!e.startsWith("ttheme-")?{...t.state,itermBase:e}:t.state},point(t,e){let n=O1(t.host),r=t.startup?e||n===np?np:void 0:n===np&&!I1(t.state)?t.state.itermBase:void 0;if(!r||r===n)return;return t.host.run("defaults",["write",rp(t.host),"Default Bookmark Guid","-string",r]),{restart:Boolean(t.host.run("pgrep",["-x","iTerm2"]))}}},R1={id:"iterm2",name:"iTerm2",emitter:Um,bakes:!0,offered:(t,e)=>e.platform==="darwin",present:(t)=>M1(P1(t.home,"Library","Application Support","iTerm2")),sync(t,e){e.write(Fo(t.home),x1(t))},pictures(t,e){e.write(Fo(t.home),x1(t))},layer:(t,e)=>({TTHEME_ITERM_SWITCH:PF(e)?"1":"",TTHEME_ITERM_PROFILES:Fo(t.home)}),plan:(t)=>[`Write ${ht(Fo(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:M1(Fo(t.home))?[Fo(t.home)]:[],touches:[]}),defaults:IF};import{existsSync as RF}from"node:fs";import{join as ui}from"node:path";function AF(t,e){let n=ui(t,"kitty.conf");return`# ${Me}
426
+ include ${ii(n,e,"~")??n}`}function NF(t,e,n=""){return[`# ${Gn}`,...t?[`include ${t}`]:[],`watcher ${e}`,...["window_logo_scale 100","window_logo_alpha 1"].filter((r)=>!Ro(n,r.split(" ")[0])),""].join(`
427
+ `)}function ic(t){return ui(t,"kitty","kitty.conf")}function A1(t){return ui(t,"ttheme","kitty.conf")}function T1(t){return ui(t,"ttheme","kitty.py")}function ip(t){return ui(t.configHome,"kitty","themes")}function N1(t){return NF(t.startup&&ui(ip(t),`${_(t.startup)}.conf`),T1(t.configHome),ft(ic(t.configHome)))}var sp={id:"kitty",name:"kitty",emitter:Wm,shelf:{from:"themes",dir:ip},offered:()=>!0,present:(t)=>RF(ui(t.configHome,"kitty")),sync(t,e){e.themes(sp),e.write(T1(t.configHome),l1({themes:ip(t),backgrounds:X(t.configHome)})),e.write(A1(t.configHome),N1(t));let n=ic(t.configHome);e.wire(n,si(ft(n),AF(ui(t.configHome,"ttheme"),t.home)))},plan(t){return[`Edit ${ht(ic(t.configHome),t.home)} — a ttheme block: include`,`Write ${ht(A1(t.configHome),t.home)} — ${kl(N1(t))}`]},notes(t){let e=ft(ic(t.configHome));return Ro(e,"window_logo_scale")||Ro(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:bn(ic(t.configHome),Un),removals:[],touches:[]})};import{createHash as TF}from"node:crypto";import{existsSync as El}from"node:fs";import{basename as F1,isAbsolute as HF,join as os}from"node:path";function Lo(t){return os(tc(t),"konsole")}function sc(t){return os(t,"konsolerc")}function L1(t){return`${_(t)}.profile`}function oc(t){return`ttheme · ${t}`}function C1(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 op(t){return new RegExp(String.raw`^\s*${t}\s*=`)}function li(t,e,n){let r=t.split(`
428
+ `),i=C1(r,e);return(i&&r.slice(i[0]+1,i[1]).find((o)=>op(n).test(o)))?.replace(op(n),"").trim()}function j1(t,e){let n=t.split(`
429
+ `),r=C1(n,"Desktop Entry"),i=e===void 0?[]:[`DefaultProfile=${e}`];if(!r)return e===void 0?t:`${t===""?"":t.replace(/\n*$/,`
409
430
 
410
431
  `)}[Desktop Entry]
411
432
  ${i[0]}
412
- `;let s=n.findIndex((a,c)=>c>r[0]&&c<r[1]&&Ym("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(`
413
- `)}function hL(t){if(t&&ge(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 P1(t,e){let n=e.endsWith(".profile")?e:`${e}.profile`;if(dL(n))return gl(n)?n:void 0;let r=n.includes("/")?n:ss("konsole",n);return[Ja(t.home),...(process.env.XDG_DATA_DIRS||"/usr/local/share:/usr/share").split(":")].map((s)=>ss(s,r)).find((s)=>gl(s))}function R1(t,e,n=0){let r=e&&e!=="FALLBACK/"&&n<8?P1(t,e):void 0;if(!r)return{};let i=ft(r),s=R1(t,si(i,"General","Parent"),n+1);return{scheme:si(i,"Appearance","ColorScheme")||s.scheme,use:si(i,"Cursor Options","UseCustomCursorColor")??s.use,cursor:si(i,"Cursor Options","CustomCursorColor")??s.cursor}}function mL(t,e){let n=R1(t,e),r=n.use==="true"?hL(n.cursor):void 0;return[`ColorScheme=${n.scheme??"Breeze"}`,`UseCustomCursorColor=${r?"true":"false"}`,...r?[`customCursorColor=${r}`]:[]].join(";")}function pL(t,e){return["[Appearance]",`ColorScheme=${j(t.name)}`,"","[Cursor Options]",`CustomCursorColor=${ct(t.cursor).join(",")}`,`CustomCursorTextColor=${ct(t.background).join(",")}`,"UseCustomCursorColor=true","","[General]",`Name=${tc(t.name)}`,`Parent=${e}`,""].join(`
414
- `)}var I1=/^ttheme-(.+)\.([0-9a-f]{8})\.colorscheme$/;function gL(t){return fL("sha1").update(t).digest("hex").slice(0,8)}function S1(t,e){let n=Ao(t.home),r=X(t.configHome),i=new Set;for(let s of t.themes){let o=dm(s,He(r,s.name,t.home)),a=ss(n,`${j(s.name)}.${gL(o)}.colorscheme`);i.add(a),e.write(ss(n,`${j(s.name)}.colorscheme`),o),e.write(a,o)}for(let s of Po(n))if(I1.test(E1(s))&&!i.has(s))e.remove(s)}function bL(t){return Po(t).flatMap((e)=>{let[,n,r]=I1.exec(E1(e))??[];return n&&r?[`${n} ${r}`]:[]}).sort().join(" ")}function wL(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 Vm=["--session","--print-reply","--reply-timeout=2000"];function $L(t){return[...(t.run("dbus-send",[...Vm,"--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",[...Vm,`--dest=${n}`,"/Windows","org.freedesktop.DBus.Introspectable.Introspect"])?.match(/<node name="(\d+)"/)?.[1];return i?[{service:n,window:`/Windows/${i}`}]:[]})}function kL(t,{service:e,window:n},r){let i=(s,...o)=>t.run("dbus-send",[...Vm,`--dest=${e}`,n,`org.kde.konsole.Window.${s}`,...o]);return i("setDefaultProfile",`string:${r}`),i("defaultProfile")?.includes(`string "${r}"`)===!0}function yL(t,e){let n=P1(t,e);return n?si(ft(n),"General","Name"):void 0}function vL(t){return si(ft(Qa(t)),"Desktop Entry","DefaultProfile")}var SL={key:"konsoleBase",profile:tc,base(t){let e=vL(t.configHome);return e&&!e.startsWith(j(""))?{...t.state,konsoleBase:e}:t.state},point(t,e){let n=Qa(t.configHome),r=ft(n),i=si(r,"Desktop Entry","DefaultProfile"),s=i?.startsWith(j(""))===!0,o=t.startup?e||s?M1(t.startup):void 0:s?t.state.konsoleBase??"":void 0;if(o===void 0||o===(i??"")&&!e)return;if(o!==(i??""))Sn(n,O1(r,o||void 0));let a=t.startup?tc(t.startup):o?yL(t,o):void 0,c=$L(t.host),u=a!==void 0&&c.every((f)=>kL(t.host,f,a));return{restart:c.length>0&&!u}}},A1={id:"konsole",name:"Konsole",emitter:hm,shelf:{from:"",dir:(t)=>Ao(t.home)},offered:(t,e)=>e.platform!=="darwin"&&e.platform!=="win32",present:(t)=>gl(Ao(t.home))||gl(Qa(t.configHome)),sync(t,e){S1(t,e);let n=Ao(t.home),r=t.state.konsoleBase??"FALLBACK/",i=new Set;for(let s of wL(t)){let o=ss(n,M1(s.name));i.add(o),e.write(o,pL(s,r))}for(let s of Po(n))if(s.endsWith(".profile")&&!i.has(s))e.remove(s)},pictures:S1,layer:(t)=>({TTHEME_KONSOLE_BASE:mL(t,t.state.konsoleBase),TTHEME_KONSOLE_SCHEMES:bL(Ao(t.home))}),plan(t){return[`Write ${ht(Ao(t.home),t.home)}/${j("*")}.profile — a "ttheme · <palette>" profile per palette, on top of your own`,...t.startup?[`Edit ${ht(Qa(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 "${tc(t.startup)}"`:`Konsole default "${tc(t.startup)}", which follows \`ttheme default\``);return n},unwire(t,e){let n=Qa(t.configHome),r=ft(n),i=si(r,"Desktop Entry","DefaultProfile")?.startsWith(j(""))===!0;return{edits:i?[{file:n,content:O1(r,e?.konsoleBase)}]:[],removals:i?[]:ru(n),touches:[]}},defaults:SL};import{createHash as EL}from"node:crypto";import{existsSync as H1,readdirSync as ML,readFileSync as xL,rmSync as OL}from"node:fs";import{join as os}from"node:path";var L1="com.apple.Terminal",ec="ttheme · ";function gn(t){return`${ec}${t}`}function bl(t){return os(t,"ttheme","terminal-app.js")}function No(t){return os(t,"ttheme","terminal-app")}function PL(t,e){return os(t.XDG_STATE_HOME??os(e,".local","state"),"ttheme","terminal-app.window")}var RL=`ObjC.import('AppKit')
433
+ `;let s=n.findIndex((a,c)=>c>r[0]&&c<r[1]&&op("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(`
434
+ `)}function FF(t){if(t&&$e(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 _1(t,e){let n=e.endsWith(".profile")?e:`${e}.profile`;if(HF(n))return El(n)?n:void 0;let r=n.includes("/")?n:os("konsole",n);return[tc(t.home),...(process.env.XDG_DATA_DIRS||"/usr/local/share:/usr/share").split(":")].map((s)=>os(s,r)).find((s)=>El(s))}function B1(t,e,n=0){let r=e&&e!=="FALLBACK/"&&n<8?_1(t,e):void 0;if(!r)return{};let i=ft(r),s=B1(t,li(i,"General","Parent"),n+1);return{scheme:li(i,"Appearance","ColorScheme")||s.scheme,use:li(i,"Cursor Options","UseCustomCursorColor")??s.use,cursor:li(i,"Cursor Options","CustomCursorColor")??s.cursor}}function LF(t,e){let n=B1(t,e),r=n.use==="true"?FF(n.cursor):void 0;return[`ColorScheme=${n.scheme??"Breeze"}`,`UseCustomCursorColor=${r?"true":"false"}`,...r?[`customCursorColor=${r}`]:[]].join(";")}function CF(t,e){return["[Appearance]",`ColorScheme=${_(t.name)}`,"","[Cursor Options]",`CustomCursorColor=${ct(t.cursor).join(",")}`,`CustomCursorTextColor=${ct(t.background).join(",")}`,"UseCustomCursorColor=true","","[General]",`Name=${oc(t.name)}`,`Parent=${e}`,""].join(`
435
+ `)}var G1=/^ttheme-(.+)\.([0-9a-f]{8})\.colorscheme$/;function jF(t){return TF("sha1").update(t).digest("hex").slice(0,8)}function H1(t,e){let n=Lo(t.home),r=X(t.configHome),i=new Set;for(let s of t.themes){let o=Sm(s,Fe(r,s.name,t.home)),a=os(n,`${_(s.name)}.${jF(o)}.colorscheme`);i.add(a),e.write(os(n,`${_(s.name)}.colorscheme`),o),e.write(a,o)}for(let s of To(n))if(G1.test(F1(s))&&!i.has(s))e.remove(s)}function _F(t){return To(t).flatMap((e)=>{let[,n,r]=G1.exec(F1(e))??[];return n&&r?[`${n} ${r}`]:[]}).sort().join(" ")}function BF(t){let e=new Set(At(t.entries).map((n)=>n.name));return t.themes.filter((n)=>e.has(n.name)||n.name===t.startup)}var ap=["--session","--print-reply","--reply-timeout=2000"];function GF(t){return[...(t.run("dbus-send",[...ap,"--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",[...ap,`--dest=${n}`,"/Windows","org.freedesktop.DBus.Introspectable.Introspect"])?.match(/<node name="(\d+)"/)?.[1];return i?[{service:n,window:`/Windows/${i}`}]:[]})}function UF(t,{service:e,window:n},r){let i=(s,...o)=>t.run("dbus-send",[...ap,`--dest=${e}`,n,`org.kde.konsole.Window.${s}`,...o]);return i("setDefaultProfile",`string:${r}`),i("defaultProfile")?.includes(`string "${r}"`)===!0}function WF(t,e){let n=_1(t,e);return n?li(ft(n),"General","Name"):void 0}function KF(t){return li(ft(sc(t)),"Desktop Entry","DefaultProfile")}var zF={key:"konsoleBase",profile:oc,base(t){let e=KF(t.configHome);return e&&!e.startsWith(_(""))?{...t.state,konsoleBase:e}:t.state},point(t,e){let n=sc(t.configHome),r=ft(n),i=li(r,"Desktop Entry","DefaultProfile"),s=i?.startsWith(_(""))===!0,o=t.startup?e||s?L1(t.startup):void 0:s?t.state.konsoleBase??"":void 0;if(o===void 0||o===(i??"")&&!e)return;if(o!==(i??""))On(n,j1(r,o||void 0));let a=t.startup?oc(t.startup):o?WF(t,o):void 0,c=GF(t.host),u=a!==void 0&&c.every((f)=>UF(t.host,f,a));return{restart:c.length>0&&!u}}},U1={id:"konsole",name:"Konsole",emitter:Em,shelf:{from:"",dir:(t)=>Lo(t.home)},offered:(t,e)=>e.platform!=="darwin"&&e.platform!=="win32",present:(t)=>El(Lo(t.home))||El(sc(t.configHome)),sync(t,e){H1(t,e);let n=Lo(t.home),r=t.state.konsoleBase??"FALLBACK/",i=new Set;for(let s of BF(t)){let o=os(n,L1(s.name));i.add(o),e.write(o,CF(s,r))}for(let s of To(n))if(s.endsWith(".profile")&&!i.has(s))e.remove(s)},pictures:H1,layer:(t)=>({TTHEME_KONSOLE_BASE:LF(t,t.state.konsoleBase),TTHEME_KONSOLE_SCHEMES:_F(Lo(t.home))}),plan(t){return[`Write ${ht(Lo(t.home),t.home)}/${_("*")}.profile — a "ttheme · <palette>" profile per palette, on top of your own`,...t.startup?[`Edit ${ht(sc(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 "${oc(t.startup)}"`:`Konsole default "${oc(t.startup)}", which follows \`ttheme default\``);return n},unwire(t,e){let n=sc(t.configHome),r=ft(n),i=li(r,"Desktop Entry","DefaultProfile")?.startsWith(_(""))===!0;return{edits:i?[{file:n,content:j1(r,e?.konsoleBase)}]:[],removals:i?[]:uu(n),touches:[]}},defaults:zF};import{createHash as qF}from"node:crypto";import{existsSync as z1,readdirSync as DF,readFileSync as JF,rmSync as YF}from"node:fs";import{join as as}from"node:path";var q1="com.apple.Terminal",ac="ttheme · ";function $n(t){return`${ac}${t}`}function Ml(t){return as(t,"ttheme","terminal-app.js")}function Co(t){return as(t,"ttheme","terminal-app")}function VF(t,e){return as(t.XDG_STATE_HOME??as(e,".local","state"),"ttheme","terminal-app.window")}var ZF=`ObjC.import('AppKit')
415
436
 
416
- const OURS = '${ec}'
437
+ const OURS = '${ac}'
417
438
  const IMAGE = 'BackgroundImageBookmark'
418
439
  const KEYS = ['BackgroundColor', 'TextColor', 'CursorColor', 'SelectionColor', 'ANSIBlackColor', 'ANSIRedColor',
419
440
  'ANSIGreenColor', 'ANSIYellowColor', 'ANSIBlueColor', 'ANSIMagentaColor', 'ANSICyanColor', 'ANSIWhiteColor',
@@ -597,68 +618,68 @@ function run(argv) {
597
618
  }
598
619
  return changed ? 'wrote' : 'same'
599
620
  }
600
- `;function Zm(t,e,n){return t.run("osascript",["-l","JavaScript",bl(e),...n])}function Xm(t){return t.run("defaults",["read",L1,"Default Window Settings"])||void 0}function IL(t){return[t.background,t.foreground,t.cursor,t.selectionBackground,...t.ansi]}function F1(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 Qm(t,e){let n=Xm(e);return t.terminalBase??(n&&!n.startsWith(ec)?n:"Basic")}function tp(t,e){let n=/^(\d+)x(\d+)$/.exec(ft(PL(t,e)).trim());return n?{width:Number(n[1])*2,height:Number(n[2])*2}:void 0}function ep(t,e,n,r){let i=r?.width??t,s=r?.height??e,o=Dt.indexOf(n.position)+1||5,a=io(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 C1=/^ttheme-(.+)\.([0-9a-z-]+)\.png$/;function wl(t){let e=new Map;for(let n of H1(t)?ML(t):[]){let[,r]=C1.exec(n)??[];if(r)e.set(r,[...e.get(r)??[],n])}return e}function AL(t){return[...wl(t)].map(([e,n])=>`${e} ${(C1.exec(n[0])??[])[2]}`).sort().join(" ")}function N1(t){let e=No(t.configHome),n=wl(e),r=tp(t.host.env,t.home),i=new Map,s=(o)=>{for(let a of o)OL(os(e,a),{force:!0})};for(let o of F1(t)){let a=n.get(le(o.name))??[];n.delete(le(o.name));let c=He(X(t.configHome),o.name,t.home),u=c&&H1(c.image)?new Uint8Array(xL(c.image)):void 0,f=u&&Mn(u);if(!c||!u||!f||c.opacity<=0){s(a);continue}let l=ep(f.width,f.height,c,r),d=EL("sha1").update(u).update(JSON.stringify([o.background.toLowerCase(),c.opacity,l])).digest("hex").slice(0,8),h=`${j(o.name)}.${d}.png`,m=os(e,h);if(!a.includes(h)){let g;try{g=_r(jr(Wt(u),o.background,c.opacity,l))}catch{s(a);continue}let[b,...w]=a;if(b)Pi(os(e,b),m,g);else L(m,g);s(w)}else s(a.filter((g)=>g!==h));i.set(o.name,m)}for(let o of n.values())s(o);return i}function T1(t,e){Zm(t.host,t.configHome,["write",Qm(t.state,t.host),...F1(t).flatMap((n)=>[gn(n.name),...IL(n),e.get(n.name)??"-"])])}var NL={key:"terminalBase",profile:gn,base(t){let e=Xm(t.host);return e&&!e.startsWith(ec)?{...t.state,terminalBase:e}:t.state},point(t,e){let n=Xm(t.host),r=n?.startsWith(ec)===!0;if(t.state.palettes.length===0)Zm(t.host,t.configHome,["drop"]);let i=t.startup?e||r?gn(t.startup):void 0:r?Qm(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",L1,o,"-string",i]);return{restart:Boolean(t.host.run("pgrep",["-x","Terminal"]))&&Zm(t.host,t.configHome,["loaded",i])!=="1"}}},j1={id:"terminal-app",name:"Terminal.app",emitter:Hm,offered:(t,e)=>e.platform==="darwin",present:()=>!1,sync(t,e){e.write(bl(t.configHome),RL),T1(t,N1(t))},pictures(t){T1(t,N1(t))},layer:(t,e)=>({TTHEME_TERMINAL_APP_BASE:Qm(t.state,e),TTHEME_TERMINAL_PICTURES:AL(No(t.configHome))}),plan:(t)=>[`Add a "${gn("<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 "${gn(t.startup)}" Terminal.app's default — \`ttheme off\` puts yours back`]:[]],notes:()=>[],next(t,e){let n=[`Terminal.app A "${gn("<palette>")}" profile per palette in Settings › Profiles`];if(t.startup)n.push(e?.restart?`Restart Terminal New windows and tabs open on "${gn(t.startup)}"`:`Terminal default "${gn(t.startup)}", which follows \`ttheme default\``);return n},unwire:()=>({edits:[],removals:[],touches:[]}),defaults:NL};import{spawn as TL}from"node:child_process";import{randomUUID as HL}from"node:crypto";import{existsSync as oi,mkdirSync as _1,readdirSync as np,readFileSync as rp,realpathSync as LL,rmSync as G1,writeFileSync as B1}from"node:fs";import{dirname as ip,join as Se}from"node:path";function as(t){return process.platform==="darwin"?Se(t,".warp","themes"):Se(Ja(t),"warp-terminal","themes")}function ai(t,e){return process.platform==="darwin"?Se(t,".warp","settings.toml"):Se(e,"warp-terminal","settings.toml")}var kl='"dark"';function yl(t){return Se(t,"ttheme","warp.base")}function FL(t){return Se(t,"ttheme","warp.later")}var z1="[appearance.themes]";function q1(t){let e=t.findIndex((r)=>r.trim()===z1);if(e<0)return;let n=t.findIndex((r,i)=>i>e&&r.trimStart().startsWith("["));return[e,n<0?t.length:n]}function ci(t){let e=t.split(`
601
- `),n=q1(e);if(!n)return;return e.slice(n[0]+1,n[1]).find((i)=>/^theme\s*=/.test(i))?.replace(/^theme\s*=\s*/,"").trim()}function sp(t,e=`${j(t)}.yaml`){return`{ custom = { name = "${t}", path = "${e}" } }`}function CL(t){return t?.includes(`path = "${j("")}`)===!0?/name = "([^"]+)"/.exec(t)?.[1]:void 0}function vl(t,e){let n=t.split(`
602
- `),r=q1(n);if(!r)return e===void 0?t:`${t.replace(/\n*$/,`
621
+ `;function cp(t,e,n){return t.run("osascript",["-l","JavaScript",Ml(e),...n])}function up(t){return t.run("defaults",["read",q1,"Default Window Settings"])||void 0}function XF(t){return[t.background,t.foreground,t.cursor,t.selectionBackground,...t.ansi]}function D1(t){let e=new Set(At(t.entries).map((n)=>n.name));return t.themes.filter((n)=>e.has(n.name)||n.name===t.startup)}function lp(t,e){let n=up(e);return t.terminalBase??(n&&!n.startsWith(ac)?n:"Basic")}function fp(t,e){let n=/^(\d+)x(\d+)$/.exec(ft(VF(t,e)).trim());return n?{width:Number(n[1])*2,height:Number(n[2])*2}:void 0}function dp(t,e,n,r){let i=r?.width??t,s=r?.height??e,o=Jt.indexOf(n.position)+1||5,a=uo(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 J1=/^ttheme-(.+)\.([0-9a-z-]+)\.png$/;function xl(t){let e=new Map;for(let n of z1(t)?DF(t):[]){let[,r]=J1.exec(n)??[];if(r)e.set(r,[...e.get(r)??[],n])}return e}function QF(t){return[...xl(t)].map(([e,n])=>`${e} ${(J1.exec(n[0])??[])[2]}`).sort().join(" ")}function W1(t){let e=Co(t.configHome),n=xl(e),r=fp(t.host.env,t.home),i=new Map,s=(o)=>{for(let a of o)YF(as(e,a),{force:!0})};for(let o of D1(t)){let a=n.get(he(o.name))??[];n.delete(he(o.name));let c=Fe(X(t.configHome),o.name,t.home),u=c&&z1(c.image)?new Uint8Array(JF(c.image)):void 0,f=u&&Rn(u);if(!c||!u||!f||c.opacity<=0){s(a);continue}let l=dp(f.width,f.height,c,r),d=qF("sha1").update(u).update(JSON.stringify([o.background.toLowerCase(),c.opacity,l])).digest("hex").slice(0,8),h=`${_(o.name)}.${d}.png`,m=as(e,h);if(!a.includes(h)){let p;try{p=Wr(Gr(Kt(u),o.background,c.opacity,l))}catch{s(a);continue}let[b,...$]=a;if(b)Ti(as(e,b),m,p);else H(m,p);s($)}else s(a.filter((p)=>p!==h));i.set(o.name,m)}for(let o of n.values())s(o);return i}function K1(t,e){cp(t.host,t.configHome,["write",lp(t.state,t.host),...D1(t).flatMap((n)=>[$n(n.name),...XF(n),e.get(n.name)??"-"])])}var tL={key:"terminalBase",profile:$n,base(t){let e=up(t.host);return e&&!e.startsWith(ac)?{...t.state,terminalBase:e}:t.state},point(t,e){let n=up(t.host),r=n?.startsWith(ac)===!0;if(t.state.palettes.length===0)cp(t.host,t.configHome,["drop"]);let i=t.startup?e||r?$n(t.startup):void 0:r?lp(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",q1,o,"-string",i]);return{restart:Boolean(t.host.run("pgrep",["-x","Terminal"]))&&cp(t.host,t.configHome,["loaded",i])!=="1"}}},Y1={id:"terminal-app",name:"Terminal.app",emitter:zm,offered:(t,e)=>e.platform==="darwin",present:()=>!1,sync(t,e){e.write(Ml(t.configHome),ZF),K1(t,W1(t))},pictures(t){K1(t,W1(t))},layer:(t,e)=>({TTHEME_TERMINAL_APP_BASE:lp(t.state,e),TTHEME_TERMINAL_PICTURES:QF(Co(t.configHome))}),plan:(t)=>[`Add a "${$n("<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 "${$n(t.startup)}" Terminal.app's default — \`ttheme off\` puts yours back`]:[]],notes:()=>[],next(t,e){let n=[`Terminal.app A "${$n("<palette>")}" profile per palette in Settings › Profiles`];if(t.startup)n.push(e?.restart?`Restart Terminal New windows and tabs open on "${$n(t.startup)}"`:`Terminal default "${$n(t.startup)}", which follows \`ttheme default\``);return n},unwire:()=>({edits:[],removals:[],touches:[]}),defaults:tL};import{spawn as eL}from"node:child_process";import{randomUUID as nL}from"node:crypto";import{existsSync as fi,mkdirSync as V1,readdirSync as hp,readFileSync as mp,realpathSync as rL,rmSync as Z1,writeFileSync as X1}from"node:fs";import{dirname as pp,join as xe}from"node:path";function cs(t){return process.platform==="darwin"?xe(t,".warp","themes"):xe(tc(t),"warp-terminal","themes")}function di(t,e){return process.platform==="darwin"?xe(t,".warp","settings.toml"):xe(e,"warp-terminal","settings.toml")}var Pl='"dark"';function Il(t){return xe(t,"ttheme","warp.base")}function iL(t){return xe(t,"ttheme","warp.later")}var nv="[appearance.themes]";function rv(t){let e=t.findIndex((r)=>r.trim()===nv);if(e<0)return;let n=t.findIndex((r,i)=>i>e&&r.trimStart().startsWith("["));return[e,n<0?t.length:n]}function hi(t){let e=t.split(`
622
+ `),n=rv(e);if(!n)return;return e.slice(n[0]+1,n[1]).find((i)=>/^theme\s*=/.test(i))?.replace(/^theme\s*=\s*/,"").trim()}function gp(t,e=`${_(t)}.yaml`){return`{ custom = { name = "${t}", path = "${e}" } }`}function sL(t){return t?.includes(`path = "${_("")}`)===!0?/name = "([^"]+)"/.exec(t)?.[1]:void 0}function Rl(t,e){let n=t.split(`
623
+ `),r=rv(n);if(!r)return e===void 0?t:`${t.replace(/\n*$/,`
603
624
  `)}
604
- ${z1}
625
+ ${nv}
605
626
  theme = ${e}
606
627
  `;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(`
607
- `)}function $l(t){return ci(t)?.includes(`path = "${j("")}`)===!0}var jL="setTimeout(() => { const fs = require('node:fs'); const [file, next, seen, theme, later, token] = process.argv.slice(-6); if (!fs.existsSync(later) || fs.readFileSync(later, 'utf8') !== token || 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 D1(t,e,n){return{image:Se(t,e1(e.name,n.image,e.background)),opacity:n.opacity}}function U1(t){let e=as(t.home),n=X(t.configHome),r=new Map,i=new Set;for(let s of t.themes){let o=He(n,s.name,t.home),a=Ya(s.name,o&&D1(e,s,o));r.set(s.name,a);for(let c of new Set([a,Ya(s.name)]))if(!oi(Se(e,c)))i.add(c)}return{files:r,fresh:i}}function W1(t,e,n){let r=as(t.home),i=X(t.configHome),s=new Set(n.values()),o=ci(ft(ai(t.home,t.configHome)))??"";for(let u of t.themes){let f=He(i,u.name,t.home),l=n.get(u.name);if(f&&l){let d=D1(r,u,f);if(!oi(d.image))try{let h=Wt(new Uint8Array(rp(f.image)));L(d.image,_r(jr(h,u.background,1)))}catch{n.set(u.name,Ya(u.name));continue}e.write(Se(r,l),Va(u,d))}}if(!oi(r))return;let a=(u,f)=>u.startsWith(j(""))&&new RegExp(`\\.[0-9a-f]{8}\\.${f}$`).test(u);for(let u of np(r))if(a(u,"yaml")&&!s.has(u)&&!o.includes(`path = "${u}"`))e.remove(Se(r,u));let c=new Set;for(let u of np(r)){let f=u.startsWith(j(""))&&u.endsWith(".yaml")?/^ {2}path: "(.+)"$/m.exec(ft(Se(r,u)))?.[1]:void 0;if(f)c.add(f)}for(let u of np(r))if(a(u,"png")&&!c.has(Se(r,u)))e.remove(Se(r,u))}function _L(t,e){let n=process.env.TTHEME_WARP_WEARS;return t!==void 0&&n!==void 0&&e.files.has(n)?n:t}function K1(t,e,n,r=!1){let i=ai(t.home,t.configHome);if(!oi(i))return;let s=yl(t.configHome),o=rp(i,"utf8"),a=r?CL(ci(o)):e;if(r&&(a===void 0||!n.files.has(a)))return;let c=FL(t.configHome);G1(c,{force:!0});let u;if(a){if(!$l(o)&&!oi(s))_1(ip(s),{recursive:!0}),B1(s,ci(o)??"");u=sp(a,n.files.get(a))}else{if(!$l(o))return;u=oi(s)&&rp(s,"utf8")||kl,G1(s,{force:!0})}let f=vl(o,u);if(f===o)return;let l=a===void 0?void 0:n.files.get(a)??`${j(a)}.yaml`;if(l!==void 0&&n.fresh.has(l)){pd(i);let d=HL();_1(ip(c),{recursive:!0}),B1(c,d),TL(process.execPath,["-e",jL,LL(i),f,o,Se(as(t.home),l),c,d],{detached:!0,stdio:"ignore"}).unref()}else Sn(i,f);return i}var op={id:"warp",name:"Warp",emitter:Lm,shelf:{from:"themes",dir:(t)=>as(t.home)},bakes:!0,offered:(t,e)=>e.platform!=="win32",present:(t)=>oi(ip(as(t.home))),sync(t,e){let n=U1(t);e.themes(op),W1(t,e,n.files);let r=K1(t,_L(t.startup,n),n);if(r)e.note(r)},pictures(t,e){let n=U1(t);W1(t,e,n.files),K1(t,void 0,n,!0)},plan(t){let e=ai(t.home,t.configHome);return t.startup&&oi(e)?[`Edit ${ht(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=ai(t.home,t.configHome),n=ft(e);return{edits:$l(n)?[{file:e,content:vl(n,ft(yl(t.configHome))||kl)}]:[],removals:$l(n)?[]:ru(e),touches:[]}}};import{existsSync as Ml}from"node:fs";import{join as To}from"node:path";var J1=/-- ttheme begin\n[\s\S]*?-- ttheme end\n?/,GL=/^return config[ \t]*$/gm;function BL(t,e){let n=Qr(t,e,""),r=n===void 0?JSON.stringify(t):`require('wezterm').home_dir .. ${JSON.stringify(n)}`;return`-- ${ve}
608
- do local path = ${r} local file = io.open(path) if file then file:close() dofile(path)(config) end end`}var V1=`local wezterm = require 'wezterm'
628
+ `)}function Ol(t){return hi(t)?.includes(`path = "${_("")}`)===!0}var oL="setTimeout(() => { const fs = require('node:fs'); const [file, next, seen, theme, later, token] = process.argv.slice(-6); if (!fs.existsSync(later) || fs.readFileSync(later, 'utf8') !== token || 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 iv(t,e,n){return{image:xe(t,d1(e.name,n.image,e.background)),opacity:n.opacity}}function Q1(t){let e=cs(t.home),n=X(t.configHome),r=new Map,i=new Set;for(let s of t.themes){let o=Fe(n,s.name,t.home),a=ec(s.name,o&&iv(e,s,o));r.set(s.name,a);for(let c of new Set([a,ec(s.name)]))if(!fi(xe(e,c)))i.add(c)}return{files:r,fresh:i}}function tv(t,e,n){let r=cs(t.home),i=X(t.configHome),s=new Set(n.values()),o=hi(ft(di(t.home,t.configHome)))??"";for(let u of t.themes){let f=Fe(i,u.name,t.home),l=n.get(u.name);if(f&&l){let d=iv(r,u,f);if(!fi(d.image))try{let h=Kt(new Uint8Array(mp(f.image)));H(d.image,Wr(Gr(h,u.background,1)))}catch{n.set(u.name,ec(u.name));continue}e.write(xe(r,l),nc(u,d))}}if(!fi(r))return;let a=(u,f)=>u.startsWith(_(""))&&new RegExp(`\\.[0-9a-f]{8}\\.${f}$`).test(u);for(let u of hp(r))if(a(u,"yaml")&&!s.has(u)&&!o.includes(`path = "${u}"`))e.remove(xe(r,u));let c=new Set(hp(r).values().filter((u)=>u.startsWith(_(""))&&u.endsWith(".yaml")).map((u)=>/^ {2}path: "(.+)"$/m.exec(ft(xe(r,u)))?.[1]).filter((u)=>u!==void 0));for(let u of hp(r))if(a(u,"png")&&!c.has(xe(r,u)))e.remove(xe(r,u))}function aL(t,e){let n=process.env.TTHEME_WARP_WEARS;return t!==void 0&&n!==void 0&&e.files.has(n)?n:t}function ev(t,e,n,r=!1){let i=di(t.home,t.configHome);if(!fi(i))return;let s=Il(t.configHome),o=mp(i,"utf8"),a=r?sL(hi(o)):e;if(r&&(a===void 0||!n.files.has(a)))return;let c=iL(t.configHome);Z1(c,{force:!0});let u;if(a){if(!Ol(o)&&!fi(s))V1(pp(s),{recursive:!0}),X1(s,hi(o)??"");u=gp(a,n.files.get(a))}else{if(!Ol(o))return;u=fi(s)&&mp(s,"utf8")||Pl,Z1(s,{force:!0})}let f=Rl(o,u);if(f===o)return;let l=a===void 0?void 0:n.files.get(a)??`${_(a)}.yaml`;if(l!==void 0&&n.fresh.has(l)){yd(i);let d=nL();V1(pp(c),{recursive:!0}),X1(c,d),eL(process.execPath,["-e",oL,rL(i),f,o,xe(cs(t.home),l),c,d],{detached:!0,stdio:"ignore"}).unref()}else On(i,f);return i}var bp={id:"warp",name:"Warp",emitter:qm,shelf:{from:"themes",dir:(t)=>cs(t.home)},bakes:!0,offered:(t,e)=>e.platform!=="win32",present:(t)=>fi(pp(cs(t.home))),sync(t,e){let n=Q1(t);e.themes(bp),tv(t,e,n.files);let r=ev(t,aL(t.startup,n),n);if(r)e.note(r)},pictures(t,e){let n=Q1(t);tv(t,e,n.files),ev(t,void 0,n,!0)},plan(t){let e=di(t.home,t.configHome);return t.startup&&fi(e)?[`Edit ${ht(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=di(t.home,t.configHome),n=ft(e);return{edits:Ol(n)?[{file:e,content:Rl(n,ft(Il(t.configHome))||Pl)}]:[],removals:Ol(n)?[]:uu(e),touches:[]}}};import{existsSync as Tl}from"node:fs";import{join as jo}from"node:path";var sv=/-- ttheme begin\n[\s\S]*?-- ttheme end\n?/,cL=/^return config[ \t]*$/gm;function uL(t,e){let n=ii(t,e,""),r=n===void 0?JSON.stringify(t):`require('wezterm').home_dir .. ${JSON.stringify(n)}`;return`-- ${Me}
629
+ do local path = ${r} local file = io.open(path) if file then file:close() dofile(path)(config) end end`}var av=`local wezterm = require 'wezterm'
609
630
  local config = wezterm.config_builder()
610
631
 
611
- `;function UL(t){let e=t.replace(/-- ttheme begin\n[\s\S]*?-- ttheme end\n\n?/,"");return e===`${V1}return config
612
- `?"":e}function ap(t,e){let n=`-- ttheme begin
632
+ `;function lL(t){let e=t.replace(/-- ttheme begin\n[\s\S]*?-- ttheme end\n\n?/,"");return e===`${av}return config
633
+ `?"":e}function wp(t,e){let n=`-- ttheme begin
613
634
  ${e}
614
635
  -- ttheme end
615
- `;if(J1.test(t))return t.replace(J1,n);if(t==="")return`${V1}${n}
636
+ `;if(sv.test(t))return t.replace(sv,n);if(t==="")return`${av}${n}
616
637
  return config
617
- `;let r=[...t.matchAll(GL)].at(-1);if(r?.index===void 0)return;return`${t.slice(0,r.index)}${n}
618
- ${t.slice(r.index)}`}function Sl(t,e){let n=To(e,".wezterm.lua");return Ml(n)?n:To(t,"wezterm","wezterm.lua")}function Y1(t){return To(t.configHome,"wezterm","colors")}function El(t){return To(t.configHome,"ttheme","wezterm.lua")}var cp={id:"wezterm",name:"WezTerm",emitter:Fm,shelf:{from:"colors",dir:Y1},offered:()=>!0,present:(t)=>Ml(To(t.configHome,"wezterm"))||Ml(To(t.home,".wezterm.lua")),sync(t,e){e.themes(cp),e.write(El(t),i1({path:El(t),colors:Y1(t),backgrounds:X(t.configHome),...t.startup?{startup:t.startup}:{},palettes:t.themes}));let n=Sl(t.configHome,t.home),r=ap(ft(n),BL(El(t),t.home));if(r!==void 0)e.wire(n,r)},plan(t){let e=Sl(t.configHome,t.home);return ap(ft(e),"")!==void 0?[`Edit ${ht(e,t.home)} — a ttheme block before \`return config\`: color_scheme_dirs, color_scheme, pictures`]:[]},notes(t){let e=Sl(t.configHome,t.home);return Ml(e)&&ap(ft(e),"")===void 0?[`${e} has no \`return config\` line — ttheme left it alone; call \`dofile("${El(t)}")(config)\` from it yourself`]:[]},next:()=>["WezTerm Reloads its config by itself"],unwire:(t)=>({edits:mn(Sl(t.configHome,t.home),UL),removals:[],touches:[]})};import{existsSync as X1,readFileSync as WL,utimesSync as KL}from"node:fs";import{dirname as zL,join as xl}from"node:path";function up(t){return xl(t,"Microsoft","Windows Terminal","Fragments","ttheme","ttheme.json")}function Z1(t){return[xl(t,"Packages","Microsoft.WindowsTerminal_8wekyb3d8bbwe","LocalState","settings.json"),xl(t,"Packages","Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe","LocalState","settings.json"),xl(t,"Microsoft","Windows Terminal","settings.json")].filter((e)=>X1(e))}function qL(t){for(let e of t){let n=/"defaultProfile"\s*:\s*"(\{[0-9a-fA-F-]+\})"/.exec(WL(e,"utf8"))?.[1];if(n)return n}return}function Q1(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 tv={id:"windows-terminal",name:"Windows Terminal",emitter:jm,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=Z1(n);if(e.write(up(n),Cm(t.themes,r??qL(i),t.startup))){let s=new Date;for(let o of i)KL(o,s,s);if(i.length>0)e.repaint()}},plan:(t)=>t.state.wtHome?[`Write ${up(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?zL(up(n)):void 0;return{edits:[],removals:r&&X1(r)?[r]:[],touches:n?Z1(n):[]}}};var br={ghostty:Km,kitty:Jm,alacritty:Wm,wezterm:cp,iterm2:$1,"windows-terminal":tv,warp:op,konsole:A1,"terminal-app":j1};function St(t=ie){return t.map((e)=>br[e])}function us(t){return t.startup&&t.palettes.includes(t.startup)?t.startup:t.palettes[0]}function Ge(t){return t.off?void 0:us(t)}function Y(){return process.env.XDG_CONFIG_HOME??Ho(bn(),".config")}var cs=(t)=>typeof t==="string"&&t!==""?t:void 0,DL={author:cs,startup:cs,off:(t)=>t?!0:void 0,itermBase:cs,konsoleBase:cs,terminalBase:cs,wtHome:cs,wtProfile:cs,marketplaces:(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 q(t){let e=ln(t);if(!Ol(e))throw Error(`nothing installed yet at ${e} — run \`ttheme init\` first`);let n=JSON.parse(ev(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)=>ie.includes(r)),...Object.fromEntries(Object.entries(DL).flatMap(([r,i])=>{let s=i(n[r]);return s===void 0?[]:[[r,s]]})),palettes:n.palettes}}function Qe(t,e){L(ln(t),`${JSON.stringify(e,null,2)}
619
- `)}function nv(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)=>et(o)??[]))].filter((o)=>!t.palettes.some((a)=>et(a.name)===o)),s=i.length>0?`add ${i.join(", ")} first — \`ttheme marketplace search\` finds a marketplace's repository`:jh(It(t.palettes),r);throw Error(`not in any marketplace: ${r.join(", ")} — ${s}`)}return t.palettes.filter((i)=>e.includes(i.name))}function nc(t,e,n){return{configHome:t,home:n,state:e,startup:Ge(e)}}function rv(t,e,n,r,i){return{...nc(t,n,r),entries:e,themes:e.map(Le),host:i}}function iv(t){let e=[],n={written:e,repainted:!1,write(r,i){if(e.push(r),Ol(r)&&ev(r,"utf8")===i)return!1;return L(r,i),!0},wire(r,i){e.push(r),Sn(r,i)},note(r){e.push(r)},remove(r){lp(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 Pm(r,s))n.write(Ho(i,o),a)},repaint(){n.repainted=!0}};return n}function JL(t,e){return Object.assign({},...St(t.state.terminals).map((n)=>n.layer?.(t,e)??{}))}function qt(t,e,n,r=bn(),i=Xe()){Ht(X(t));let s=nv(cr(t,e),n.palettes),o=Tu(s,Kt(t));L$(t,new Map(o.map((u)=>[u.name,eo(u)]))),E$(t),go(t,s);let a=rv(t,o,n,r,i),c=iv(a);for(let u of St(n.terminals))u.sync(a,c);return c.written.push(av(a,i,c.repainted)),ov(t,o,r),c.written}function sv(t,e=bn()){if(!Ol(Ho(t,"ttheme","palettes.zsh")))return;let n=new Set(q(t).palettes);ov(t,$e(t).palettes.filter((r)=>n.has(r.name)),e)}function ov(t,e,n){let r=Ho(t,"ttheme","aliases.zsh"),i=qy(YL(e,n));if(ft(r)!==i)L(r,i)}function YL(t,e){let n=t.flatMap((s)=>s.booru?[s.booru]:[]),r=$h(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 av(t,e,n){let r=Ho(t.configHome,"ttheme","palettes.zsh"),i=xm(t.entries,t.startup,t.state.terminals,JL(t,e),Object.keys(Kt(t.configHome)));if(n||ft(r)!==i)L(r,i),lp(`${r}.zwc`,{force:!0});return r}function Be(t,e=bn(),n=Xe()){let r=q(t),i=St(r.terminals).filter((a)=>a.pictures);if(i.length===0)return;let s=rv(t,nv($e(t),r.palettes),r,e,n),o=iv(s);for(let a of i)a.pictures?.(s,o);av(s,n,!1)}function ls(t){return!St(t).some((e)=>e.bakes)}function Pl(t,e,n=bn()){let r=nc(t,e,n);return St(e.terminals).flatMap((i)=>[...i.shelf?[`Write ${ht(i.shelf.dir(r),n)}/${j("*")} — a theme file per palette`]:[],...i.plan(r)])}function Rl(t,e,n=bn()){let r=nc(t,e,n);return St(e.terminals).flatMap((i)=>i.notes(r))}function Il(t,e,n,r=bn()){let i=nc(t,e,r);return St(e.terminals).flatMap((s)=>s.next(i,n.get(s.id)))}function Lo(t,e,n,r,i=bn()){let s=[],o=zt(t,e,!1).palettes;for(let a of St(n)){let c=a.shelf?.dir({configHome:t,home:i});for(let u of c?o.filter((f)=>r.includes(f.name)):[])for(let{file:f}of Pm(a,Le(u))){let l=Ho(c,f);if(Ol(l))lp(l,{force:!0}),s.push(l)}}return s}function cv(t,e,n,r){return{...nc(t,e,r),host:n}}function rc(t,e,n,r=bn()){return St(e.terminals).reduce((i,s)=>s.defaults?.base(cv(t,i,n,r))??i,e)}function fs(t,e,n,r,i=bn()){let s=new Map;for(let o of St(e.terminals)){let a=o.defaults?.point(cv(t,e,r,i),n);if(a)s.set(o.id,a)}return s}function tn(t,e,n,r,i=!1,s=Xe(),o=bn()){let a=i||!Ge(n)&&Ge(r)!==void 0,c=a?rc(t,r,s,o):r;return qt(t,e,c,o,s),Qe(t,c),a||Ge(n)!==Ge(r)?fs(t,c,a,s,o):new Map}import{performance as uv}from"node:perf_hooks";var VL=16,fp=80,lv="\x1B[?2026h",fv="\x1B[?2026l";class ds{shown=[];pointer=new qh;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+VL-uv.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}=zk(()=>this.view());if(!t)return;this.last=uv.now();let{lines:n,zones:r}=Jk(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 f=0;f<o;f++){let l=n[f];if(l!==this.shown[f])i+=`\x1B[${f+1};1H${ke}\x1B[2K${l??""}`,s.add(f)}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(`${lv}${i}${a}${ke}${u?c:""}${fv}`);this.tick(t.ticking===!0)};tick(t){if(t&&!this.ticker)this.ticker=setInterval(()=>{this.beat(),this.request()},fp);else if(!t&&this.ticker)clearInterval(this.ticker),this.ticker=void 0}}class dp{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(`
638
+ `;let r=[...t.matchAll(cL)].at(-1);if(r?.index===void 0)return;return`${t.slice(0,r.index)}${n}
639
+ ${t.slice(r.index)}`}function Al(t,e){let n=jo(e,".wezterm.lua");return Tl(n)?n:jo(t,"wezterm","wezterm.lua")}function ov(t){return jo(t.configHome,"wezterm","colors")}function Nl(t){return jo(t.configHome,"ttheme","wezterm.lua")}var $p={id:"wezterm",name:"WezTerm",emitter:Dm,shelf:{from:"colors",dir:ov},offered:()=>!0,present:(t)=>Tl(jo(t.configHome,"wezterm"))||Tl(jo(t.home,".wezterm.lua")),sync(t,e){e.themes($p),e.write(Nl(t),p1({path:Nl(t),colors:ov(t),backgrounds:X(t.configHome),...t.startup?{startup:t.startup}:{},palettes:t.themes}));let n=Al(t.configHome,t.home),r=wp(ft(n),uL(Nl(t),t.home));if(r!==void 0)e.wire(n,r)},plan(t){let e=Al(t.configHome,t.home);return wp(ft(e),"")!==void 0?[`Edit ${ht(e,t.home)} — a ttheme block before \`return config\`: color_scheme_dirs, color_scheme, pictures`]:[]},notes(t){let e=Al(t.configHome,t.home);return Tl(e)&&wp(ft(e),"")===void 0?[`${e} has no \`return config\` line — ttheme left it alone; call \`dofile("${Nl(t)}")(config)\` from it yourself`]:[]},next:()=>["WezTerm Reloads its config by itself"],unwire:(t)=>({edits:bn(Al(t.configHome,t.home),lL),removals:[],touches:[]})};import{existsSync as uv,readFileSync as fL,utimesSync as dL}from"node:fs";import{dirname as hL,join as Hl}from"node:path";function kp(t){return Hl(t,"Microsoft","Windows Terminal","Fragments","ttheme","ttheme.json")}function cv(t){return[Hl(t,"Packages","Microsoft.WindowsTerminal_8wekyb3d8bbwe","LocalState","settings.json"),Hl(t,"Packages","Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe","LocalState","settings.json"),Hl(t,"Microsoft","Windows Terminal","settings.json")].filter((e)=>uv(e))}function mL(t){return t.values().map((e)=>/"defaultProfile"\s*:\s*"(\{[0-9a-fA-F-]+\})"/.exec(fL(e,"utf8"))?.[1]).find((e)=>e!==void 0)}function lv(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 fv={id:"windows-terminal",name:"Windows Terminal",emitter:Ym,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=cv(n);if(e.write(kp(n),Jm(t.themes,r??mL(i),t.startup))){let s=new Date;for(let o of i)dL(o,s,s);if(i.length>0)e.repaint()}},plan:(t)=>t.state.wtHome?[`Write ${kp(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?hL(kp(n)):void 0;return{edits:[],removals:r&&uv(r)?[r]:[],touches:n?cv(n):[]}}};var vr={ghostty:ep,kitty:sp,alacritty:tp,wezterm:$p,iterm2:R1,"windows-terminal":fv,warp:bp,konsole:U1,"terminal-app":Y1};function St(t=oe){return t.map((e)=>vr[e])}function ls(t){return t.startup&&t.palettes.includes(t.startup)?t.startup:t.palettes[0]}function Ge(t){return t.off?void 0:ls(t)}function Y(){return process.env.XDG_CONFIG_HOME??_o(kn(),".config")}var us=(t)=>typeof t==="string"&&t!==""?t:void 0,pL={author:us,startup:us,off:(t)=>t?!0:void 0,itermBase:us,konsoleBase:us,terminalBase:us,wtHome:us,wtProfile:us,marketplaces:(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 q(t){let e=hn(t);if(!Fl(e))throw Error(`nothing installed yet at ${e} — run \`ttheme init\` first`);let n=JSON.parse(dv(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)=>oe.includes(r)),...Object.fromEntries(Object.entries(pL).flatMap(([r,i])=>{let s=i(n[r]);return s===void 0?[]:[[r,s]]})),palettes:n.palettes}}function tn(t,e){H(hn(t),`${JSON.stringify(e,null,2)}
640
+ `)}function hv(t,e){let n=new Map(t.palettes.map((s)=>[s.name,s])),r=e.filter((s)=>!n.has(s));if(r.length>0){let s=new Set(t.palettes.flatMap((c)=>et(c.name)??[])),o=[...new Set(r.flatMap((c)=>et(c)??[])).difference(s)],a=o.length>0?`add ${o.join(", ")} first — \`ttheme marketplace search\` finds a marketplace's repository`:Yh(At(t.palettes),r);throw Error(`not in any marketplace: ${r.join(", ")} — ${a}`)}let i=new Set(e);return t.palettes.filter((s)=>i.has(s.name))}function cc(t,e,n){return{configHome:t,home:n,state:e,startup:Ge(e)}}function mv(t,e,n,r,i){return{...cc(t,n,r),entries:e,themes:e.map(Le),host:i}}function pv(t){let e=[],n={written:e,repainted:!1,write(r,i){if(e.push(r),Fl(r)&&dv(r,"utf8")===i)return!1;return H(r,i),!0},wire(r,i){e.push(r),On(r,i)},note(r){e.push(r)},remove(r){yp(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 _m(r,s))n.write(_o(i,o),a)},repaint(){n.repainted=!0}};return n}function gL(t,e){return Object.assign({},...St(t.state.terminals).map((n)=>n.layer?.(t,e)??{}))}function Dt(t,e,n,r=kn(),i=Qe()){Ft(X(t));let s=hv(hr(t,e),n.palettes),o=Gu(s,zt(t));q$(t,new Map(o.map((u)=>[u.name,oo(u)]))),F$(t),yo(t,s);let a=mv(t,o,n,r,i),c=pv(a);for(let u of St(n.terminals))u.sync(a,c);return c.written.push(wv(a,i,c.repainted)),bv(t,o,r),c.written}function gv(t,e=kn()){if(!Fl(_o(t,"ttheme","palettes.zsh")))return;let n=new Set(q(t).palettes);bv(t,ve(t).palettes.filter((r)=>n.has(r.name)),e)}function bv(t,e,n){let r=_o(t,"ttheme","aliases.zsh"),i=r1(bL(e,n));if(ft(r)!==i)H(r,i)}function bL(t,e){let n=t.flatMap((s)=>s.booru?[s.booru]:[]),r=Rh(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 wv(t,e,n){let r=_o(t.configHome,"ttheme","palettes.zsh"),i=Cm(t.entries,t.startup,t.state.terminals,gL(t,e),Object.keys(zt(t.configHome)));if(n||ft(r)!==i)H(r,i),yp(`${r}.zwc`,{force:!0});return r}function Ue(t,e=kn(),n=Qe()){let r=q(t),i=St(r.terminals).filter((a)=>a.pictures);if(i.length===0)return;let s=mv(t,hv(ve(t),r.palettes),r,e,n),o=pv(s);for(let a of i)a.pictures?.(s,o);wv(s,n,!1)}function fs(t){return!St(t).some((e)=>e.bakes)}function Ll(t,e,n=kn()){let r=cc(t,e,n);return St(e.terminals).flatMap((i)=>[...i.shelf?[`Write ${ht(i.shelf.dir(r),n)}/${_("*")} — a theme file per palette`]:[],...i.plan(r)])}function Cl(t,e,n=kn()){let r=cc(t,e,n);return St(e.terminals).flatMap((i)=>i.notes(r))}function jl(t,e,n,r=kn()){let i=cc(t,e,r);return St(e.terminals).flatMap((s)=>s.next(i,n.get(s.id)))}function Bo(t,e,n,r,i=kn()){let s=[],o=qt(t,e,!1).palettes.filter((a)=>r.includes(a.name));for(let a of St(n)){let c=a.shelf?.dir({configHome:t,home:i});if(!c)continue;for(let u of o)for(let{file:f}of _m(a,Le(u))){let l=_o(c,f);if(Fl(l))yp(l,{force:!0}),s.push(l)}}return s}function $v(t,e,n,r){return{...cc(t,e,r),host:n}}function uc(t,e,n,r=kn()){return St(e.terminals).reduce((i,s)=>s.defaults?.base($v(t,i,n,r))??i,e)}function ds(t,e,n,r,i=kn()){let s=new Map;for(let o of St(e.terminals)){let a=o.defaults?.point($v(t,e,r,i),n);if(a)s.set(o.id,a)}return s}function en(t,e,n,r,i=!1,s=Qe(),o=kn()){let a=i||!Ge(n)&&Ge(r)!==void 0,c=a?uc(t,r,s,o):r;return Dt(t,e,c,o,s),tn(t,c),a||Ge(n)!==Ge(r)?ds(t,c,a,s,o):new Map}import{performance as kv}from"node:perf_hooks";var wL=16,vp=80,yv="\x1B[?2026h",vv="\x1B[?2026l";class hs{shown=[];pointer=new rm;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+wL-kv.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}=ny(()=>this.view());if(!t)return;this.last=kv.now();let{lines:n,zones:r}=sy(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 f=0;f<o;f++){let l=n[f];if(l!==this.shown[f])i+=`\x1B[${f+1};1H${Se}\x1B[2K${l??""}`,s.add(f)}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(`${yv}${i}${a}${Se}${u?c:""}${vv}`);this.tick(t.ticking===!0)};tick(t){if(t&&!this.ticker)this.ticker=setInterval(()=>{this.beat(),this.request()},vp);else if(!t&&this.ticker)clearInterval(this.ticker),this.ticker=void 0}}class Sp{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(`
620
641
  `),this.shown=[]}put(t,e){let n=t.map((s)=>tt(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(`
621
642
  `);else if(r>=this.shown.length)i=`
622
643
  ${n.slice(r).join(`
623
644
  `)}`;else{let s=this.shown.length-1-r;i=`${s>0?`\x1B[${s}A`:""}\r\x1B[J${n.slice(r).join(`
624
- `)}`}this.shown=n,this.write(`${lv}${e}${i}${fv}`)}}var ZL=300;function Al(t){return t>=1e6?`${(t/1e6).toFixed(1)} MB`:`${Math.max(1,Math.round(t/1000))} KB`}function Nl(t,e){if(!e)return Al(t);return e>=1e6?`${(t/1e6).toFixed(1)}/${(e/1e6).toFixed(1)} MB`:`${Math.round(t/1000)}/${Math.round(e/1000)} KB`}var Fo;async function dv(t,e){Fo=t;try{return await e()}finally{Fo=void 0}}function _n(t){if(Fo)Fo.say(t);else console.log(t)}function ui(t=""){if(Fo){let u=Fo;return u.set(t),{set:(f)=>u.set(f),say:(f)=>u.say(f),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]=Ft()?["",""]:[$t("dim"),_h("dim")],i=0,s=!1,o,a=()=>{e.write(`\r\x1B[2K${n}${tt(`${ur[i%ur.length]} ${t}`,(e.columns||80)-1,!1)}${r}`)},c=setTimeout(()=>{s=!0,a(),o=setInterval(()=>{i++,a()},fp),o.unref()},ZL);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 XL,readFileSync as QL}from"node:fs";import{join as tF}from"node:path";function eF(t){return tF(t,"ttheme","pins")}function hv(t,e,n){let r=eF(t);if(!XL(r))return;let i=QL(r,"utf8"),o=i.split(`
645
+ `)}`}this.shown=n,this.write(`${yv}${e}${i}${vv}`)}}var $L=300;function _l(t){return t>=1e6?`${(t/1e6).toFixed(1)} MB`:`${Math.max(1,Math.round(t/1000))} KB`}function Bl(t,e){if(!e)return _l(t);return e>=1e6?`${(t/1e6).toFixed(1)}/${(e/1e6).toFixed(1)} MB`:`${Math.round(t/1000)}/${Math.round(e/1000)} KB`}var Go;async function Sv(t,e){Go=t;try{return await e()}finally{Go=void 0}}function Wn(t){if(Go)Go.say(t);else console.log(t)}function mi(t=""){if(Go){let u=Go;return u.set(t),{set:(f)=>u.set(f),say:(f)=>u.say(f),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]=Ct()?["",""]:[$t("dim"),Vh("dim")],i=0,s=!1,o,a=()=>{e.write(`\r\x1B[2K${n}${tt(`${mr[i%mr.length]} ${t}`,(e.columns||80)-1,!1)}${r}`)},c=setTimeout(()=>{s=!0,a(),o=setInterval(()=>{i++,a()},vp),o.unref()},$L);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 kL,readFileSync as yL}from"node:fs";import{join as vL}from"node:path";function SL(t){return vL(t,"ttheme","pins")}function Ev(t,e,n){let r=SL(t);if(!kL(r))return;let i=yL(r,"utf8"),o=i.split(`
625
646
  `).flatMap((a)=>{let c=/^((?:[~/]|ssh:).*\s)(\S+)(\s*)$/.exec(a);if(!c)return[a];let[,u,f,l]=c;if(n.includes(f))return[];let d=e.get(f);return[d?`${u}${d}${l}`:a]}).join(`
626
- `);if(o!==i)L(r,o)}import{execFile as nF,spawn as rF,spawnSync as hp}from"node:child_process";import{mkdirSync as iF,readFileSync as sF,realpathSync as mv}from"node:fs";import{homedir as oF,tmpdir as pv}from"node:os";import{dirname as aF,join as mp}from"node:path";var ic=`npx ${dt.name}@latest init`,bp=86400000,cF=3600000,uF=1e4,pp=/^(\d+)\.(\d+)\.(\d+)$/;function gv(t,e){let n=pp.exec(t),r=pp.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 jo(t=process.env){return t.TTHEME_AUTO_UPDATE!=="off"&&(t.CI===void 0||t.CI===""||t.CI==="false")}function gp(){return mp(process.env.XDG_STATE_HOME??mp(oF(),".local","state"),"ttheme","release.json")}function sc(){try{let t=JSON.parse(sF(gp(),"utf8"));return{checked:typeof t.checked==="number"?t.checked:0,...typeof t.latest==="string"?{latest:t.latest}:{},...typeof t.told==="number"?{told:t.told}:{}}}catch{return{checked:0}}}function Co(t){iF(aF(gp()),{recursive:!0}),L(gp(),`${JSON.stringify(t)}
627
- `)}function bv(t=uF){return new Promise((e,n)=>{nF("npm",["view",`${dt.name}@latest`,"version","--prefer-online"],{cwd:pv(),encoding:"utf8",timeout:t,env:{...process.env,npm_config_update_notifier:"false"}},(r,i,s)=>{if(r){let a=s.split(`
628
- `).find((f)=>/\S/.test(f))?.replace(/^npm (error|ERR!) /,""),{code:c,killed:u}=r;n(Error(c==="ENOENT"?"cannot run npm":u?`npm did not answer within ${t/1000} s`:`npm could not ask its registry — ${a??"it gave no reason"}`));return}let o=i.trim();if(!pp.test(o)){n(Error("the npm registry named no version"));return}e(o)})})}function wv(t=Date.now()){let e=sc();if(!jo()||t-e.checked<bp)return;try{Co({...e,checked:t}),rF(process.execPath,[process.argv[1],"latest"],{detached:!0,stdio:"ignore",env:process.env}).unref()}catch{}}async function $v(){let t=sc();try{return Co({...t,checked:Date.now(),latest:await bv()}),0}catch{return Co({...t,checked:Date.now()-bp+cF}),1}}function kv(t=Y()){return mp(t,"ttheme","ttheme.js")}function yv(){try{return mv(process.argv[1])===mv(kv())}catch{return!1}}function lF(){return yv()?"`ttheme update` updates it":`\`${ic}\` updates it`}function vv(t,e=dt.version){return`ttheme ${t} is out, you have ${e} — ${lF()}`}function Sv(t=Date.now()){let e=sc();if(!jo()||!e.latest||!gv(e.latest,dt.version)||t-(e.told??0)<bp)return;if(process.stderr.isTTY)Co({...e,told:t});el([vv(e.latest)])}function Ev(t,e){console.log(`Updating ttheme ${dt.version} → ${t}`);let n=hp("npx",["--yes",`${dt.name}@${t}`,"init","--yes"],{cwd:pv(),stdio:"inherit",env:{...process.env,npm_config_prefer_online:"true"}});if(n.error)throw Error(`cannot run npx — ${n.error.message}; \`${ic}\` updates ttheme once npm is there`);if(n.status!==0)throw Error(`npx stopped with status ${n.status} — ttheme ${dt.version} is still installed`);let r=kv(),i=hp(process.execPath,[r,"--version"],{encoding:"utf8"}).stdout?.trim();if(i!==t)throw Error(`${r} is ${i||"unreadable"} after the update, not ${t} — \`${ic}\` tries again`);let s=sc();return Co({...s,latest:t}),hp(process.execPath,[r,"update",...e],{stdio:"inherit",env:{...process.env,TTHEME_UPDATED:t}}).status??1}async function Mv(){if(process.env.TTHEME_UPDATED)return{note:` ttheme ${dt.version} — updated`};let t;try{t=await bv()}catch(e){return{note:` ttheme ${dt.version} — could not check for a newer one: ${e.message}`}}if(Co({...sc(),checked:Date.now(),latest:t}),!gv(t,dt.version))return{note:` ttheme ${dt.version} — up to date`};return yv()?{latest:t,note:""}:{note:` ${vv(t)}`}}function xv(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 Ov(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=xv(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 Pv(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=xv(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 fF}from"node:zlib";var hs=512,Rv=67108864,wp=new TextDecoder;function _o(t,e,n){let r=t.subarray(e,e+n),i=r.indexOf(0);return wp.decode(i<0?r:r.subarray(0,i))}function dF(t){if((t[124]??0)&128)throw Error("the archive holds a file too large to be a palette");let e=Number.parseInt(_o(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 hF(t){let e=0,n;while(e<t.length){let r=t.indexOf(32,e),i=r<0?Number.NaN:Number.parseInt(wp.decode(t.subarray(e,r)),10);if(!Number.isFinite(i)||i<=0)break;let s=wp.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 mF(t){if(t[0]!==31||t[1]!==139)return t;try{return fF(t,{maxOutputLength:Rv})}catch(e){throw Error(e instanceof RangeError?`the archive unpacks to more than ${Rv/1024/1024} MB`:"the archive is not a gzip file that reads")}}function Iv(t){let e=mF(t),n=new Map,r,i=0;while(i+hs<=e.length){let s=e.subarray(i,i+hs);if(s.every((l)=>l===0))break;let o=dF(s),a=e.subarray(i+hs,i+hs+o);i+=hs+Math.ceil(o/hs)*hs;let c=String.fromCharCode(s[156]??0);if(c==="x"){r=hF(a)??r;continue}if(c==="L"){r=_o(a,0,a.length);continue}let u=_o(s,257,5)==="ustar"?_o(s,345,155):"",f=r??(u?`${u}/${_o(s,0,100)}`:_o(s,0,100));if(r=void 0,c==="0"||c==="\x00")n.set(f.split("/").slice(1).join("/"),a)}return n}var $F=86400000,kF=3600000,yp=5000;function $p(){return Av(process.env.XDG_STATE_HOME??Av(bF(),".local","state"),"ttheme","marketplaces.json")}function wr(){try{let t=JSON.parse(Hv($p(),"utf8"));return Object.fromEntries(Object.entries(t).filter((e)=>typeof e[1]?.at==="number"&&typeof e[1].error==="string"))}catch{return{}}}function Nv(t,e){let n=wr();if(e===void 0){if(!(t in n))return;delete n[t]}else n[t]={at:Date.now(),error:e};Tv(wF($p()),{recursive:!0}),L($p(),`${JSON.stringify(n,null,2)}
629
- `)}function vp(t,e){let n=wt(e)?or(t,e):void 0;try{return n?pF(n).mtimeMs:void 0}catch{return}}function yF(t,e,n,r){return t&&(e===void 0||r-e>=$F)&&(n===void 0||r-n>=kF)}function Sp(t,e,n=Date.now()){let r=wr();return Jt(e.marketplaces).filter((i)=>yF(qr(i,e.updates),vp(t,i),r[i]?.at,n))}function vF(t,e){let n={},r=new TextDecoder;for(let[i,s]of Iv(t))if(i===ot||i.startsWith("palettes/")&&i.endsWith(".toml"))n[i]=r.decode(s);return{...e?{etag:e}:{},files:n}}async function Ep(t,e,n,r){let i;try{i=await Ba(tk(t),e,n,r?{"if-none-match":r}:{})}catch(s){if(s instanceof Fu){let o=Ha(t);throw Error(`${st(t)}${o?` has no ${o}`:" is not there"} — is the repository public?`)}throw s}if(i.status===304)return;return vF(new Uint8Array(await i.arrayBuffer()),i.headers.get("etag"))}function Mp(t,e,n){let{id:r,info:i,entries:s}=Vi(t,e,n,de(!1));return{source:t,id:r,entries:s,archive:e,info:i}}function oc(t){return Bo(t,J)}async function ac(t,e,n,r){if(e===J){if(!kp(fn(t)))throw Error(`the official marketplace is not on this machine — \`${ic}\` puts it back`);return{source:e,id:J,entries:Bo(t,J)}}let i=await Ep(e,n,r);if(!i)throw Error(`${st(e)} answered as if nothing had changed`);return Mp(e,i,oc(t))}function Go(t,e){if(!("archive"in e))return;Tv(fo(t),{recursive:!0}),L(or(t,e.source),`${JSON.stringify(e.archive)}
630
- `)}function SF(t,e){try{return ar(t,e)}catch{return}}function Bo(t,e){try{if(e===J)return Dr(Hv(fn(t),"utf8")).palettes;return Vi(e,ar(t,e),oc(t),de(!1)).entries}catch{return[]}}function EF(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 MF(t,e,n){if(!wt(e))return ac(t,e,n);let r=SF(t,e),i=await Ep(e,n,void 0,r?.etag);return i&&Mp(e,i,oc(t))}async function xp(t,e,n){let r=Bo(t,e),i;try{i=await MF(t,e,n)}catch(o){throw Nv(e,o.message),o}if(i)Go(t,i);else{let o=new Date;gF(or(t,e),o,o)}Nv(e,void 0);let s=i?.entries??r;return{source:e,id:i?.id??Lu(e,ar(t,e)),count:It(s).length,change:EF(r,s)}}async function Op(t,e,n){try{return{source:e,refreshed:await xp(t,e,n)}}catch(r){return{source:e,failure:r instanceof Error?r:Error(String(r))}}}function Lv(t,e){return`${st(t)}: ${e.message}`}function jt(t){return`${t} palette${t===1?"":"s"}`}function Uo(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 Fv({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 Pp(t){let e=Fv(t.change);return`${t.id} — ${jt(t.count)}${e?` (${e})`:""}`}function Rp(t){return Fv(t.change)?`Updated ${Pp(t)}`:void 0}function cc(t,e,n=oc(t)){try{if(Rt(e)){let r=Je(e),i=we(r);return{id:i,info:r,entries:Tn(e,i,n,de(!1))}}return wt(e)?Vi(e,ar(t,e),n,de(!1)):void 0}catch{return}}function xF(t){if(!kp(ln(t)))return[];let e=q(t),n=oc(t),r={renamed:new Map,removed:[]};for(let u of Jt(e.marketplaces)){let f=cc(t,u,n);if(f)Ov(f.id,f.info,new Set(f.entries.map((l)=>te(l.name))),e.palettes,r)}if(r.renamed.size===0&&r.removed.length===0)return[];let i=lt(t,!1);Lo(t,i,e.terminals,[...r.renamed.keys(),...r.removed]),bk(t,r.renamed,r.removed),M$(t,r.renamed),hv(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 tn(t,i,e,{...a,palettes:s,...c?{startup:c}:{}}),[...[...r.renamed].map(([u,f])=>`${u} is ${f} now — its marketplace renamed it`),...r.removed.map((u)=>`${u} was removed from its marketplace`)]}function Ip(t){let e=bo(t,lt(t,!1)).map((n)=>n.name);if(e.length===0)return;return`${e.join(", ")} ${e.length===1?"has":"have"} an update from ${e.length===1?"its marketplace":"their marketplaces"} — ctrl+r on a palette marked ↑ in Browse (\`ttheme\`) takes it`}function ms(t,e){let n=xF(t),r=q(t),i=new Set(e.flatMap((o)=>o.change.gone)),s=r.palettes.filter((o)=>i.has(o)).map((o)=>`${o} left its marketplace — ttheme keeps the copy you have`);return[...n,...s]}async function Cv(t=Y()){try{if(!jo()||!kp(ln(t)))return;let e=Sp(t,q(t));if(e.length===0)return;let n=ui(`Checking ${e.map(st).join(", ")} for updates`),r=await Promise.all(e.map((o)=>Op(t,o,yp)));n.done();let i=r.flatMap((o)=>("refreshed"in o)?[o.refreshed]:[]),s=i.flatMap((o)=>Rp(o)??[]);if(s.length===0)return;el([...s,...ms(t,i),...[Ip(t)??[]].flat()])}catch{return}}var RF="https://kecan0406.github.io/ttheme/marketplaces.json",IF=/^#[0-9a-f]{6}$/i,AF=/^(cursor|foreground|background|selection|ansi(1[0-5]|[0-9]))$/,NF=/^\d{4}-\d{2}-\d{2}$/;function TF(t){return t.replace(/[\p{Cc}\s]+/gu," ").trim()}function Wo(t){return typeof t==="string"?TF(t):void 0}function jv(t){return typeof t==="string"&&IF.test(t)?t.toLowerCase():void 0}function HF(t,e){if(typeof e!=="object"||e===null)return;let n=e,r=Wo(n.name),[i,s,o,a]=[n.background,n.foreground,n.cursor,n.selection].map(jv),c=Array.isArray(n.ansi)?n.ansi.map(jv):[],u=Array.isArray(n.signatureSlots)?n.signatureSlots:[];if(!r||ee(`${t}/${r}`)||!i||!s||!o||!a||c.length!==16||c.some((l)=>l===void 0)||u.length!==3||!u.every((l)=>typeof l==="string"&&AF.test(l)))return;let f=Wo(n.catalog);return{name:r,...f?{catalog:f}:{},background:i,foreground:s,cursor:o,selection:a,ansi:c.filter((l)=>l!==void 0),signatureSlots:u}}function LF(t){if(typeof t!=="object"||t===null)return;let e=t,n=Wo(e.id),r=Wo(e.source);if(!n||!r||ee(`${n}/x`))return;let i;try{i=An(r)}catch{return}if(!wt(i))return;let s=(Array.isArray(e.palettes)?e.palettes:[]).flatMap((c)=>HF(n,c)??[]);if(s.length===0)return;let o=typeof e.stars==="number"&&Number.isFinite(e.stars)&&e.stars>=0?Math.floor(e.stars):0,a=Wo(e.updated)??"";return{id:n,source:i,about:Wo(e.about)??"",stars:o,updated:NF.test(a)?a:"",palettes:s}}function _v(t){let e=JSON.parse(t),n=typeof e==="object"&&e!==null?e.marketplaces:void 0;if(!Array.isArray(n))throw Error("the marketplace index lists no marketplaces");let r=new Set;return n.flatMap((i)=>{let s=LF(i);if(!s||r.has(s.id))return[];return r.add(s.id),[s]})}function FF(){return PF(Rn(),"marketplace-index.json")}function CF(t){try{let e=JSON.parse(OF(t,"utf8")),n=typeof e==="object"&&e!==null?e:{};return typeof n.etag==="string"&&typeof n.at==="number"&&typeof n.text==="string"?{etag:n.etag,at:n.at,text:n.text}:void 0}catch{return}}async function Tl(t,e=FF(),n=RF){let r=CF(e),i;try{i=r?_v(r.text):void 0}catch{i=void 0}try{let s=await Ba(n,void 0,t,r&&i?{"if-none-match":r.etag}:{}),o=Date.now();if(s.status===304&&r&&i)return L(e,JSON.stringify({...r,at:o})),{marketplaces:i,at:o};let a=await s.text(),c=_v(a);return L(e,JSON.stringify({etag:s.headers.get("etag")??"",at:o,text:a})),{marketplaces:c,at:o}}catch(s){if(!r||!i)throw s;return{marketplaces:i,at:r.at,offline:s instanceof Error?s.message:String(s)}}}var Kv=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,UF=["add","remove","search","init","check"];function Np(){return process.stdin.isTTY===!0&&process.stdout.isTTY===!0}function WF(){try{let t=jF("gh",["api","user","--jq",".login"],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:1e4}).trim().toLowerCase();return Kv.test(t)?t:void 0}catch{return}}async function KF(t,e){if(e.author)return e.author;let n=WF();if(!n){if(!Np())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 lm({message:"Your GitHub handle — your palettes are named <handle>@<marketplace>/<palette>",validate:(i)=>Kv.test((i??"").toLowerCase())&&(i??"").length<=39?void 0:"that is not a GitHub handle"});if(re(r))throw Error("no handle given");n=r.toLowerCase()}return Qe(t,{...e,author:n}),console.log(`Your palettes are named ${n}@<marketplace>/<palette>`),n}function li(t,e){if(e===J)return J;return Rt(e)?we(Je(e)):Lu(e,ar(t,e))}function Fl(t,e){try{return li(t,e)}catch{return}}function zv(t){return et(t)??J}function lc(t){return lt(t).palettes.filter((e)=>et(e.name)===void 0)}function zF(t){let e=uc(import.meta.dirname,"..","dist","manifest.json");return Hl(e)?Dr(Ll(e,"utf8")).palettes:lc(t)}function fc(t,e,n){let{updates:r,...i}=t,s=Object.entries(n).filter(([o,a])=>wt(o)&&e.includes(o)&&a!==qr(o,{}));return{...i,marketplaces:e,...s.length>0?{updates:Object.fromEntries(s)}:{}}}function qv(t,e,n,r){return e.find((i)=>i!==n&&!sr(i,n)&&Fl(t,i)===r)}function Ap(t,e,n,r){let i=q(t),s=Jt(i.marketplaces),o=qv(t,s,e,n);if(o)throw Error(`${n} already names the marketplace at ${st(o)} — \`ttheme marketplace remove ${n}\` first`);let a=r===void 0?{...i.updates}:{...i.updates,[e]:r};Qe(t,fc(i,s.includes(e)?s:[...s,e],a))}async function qF(t){if(!Np())return!1;let e=await _e({message:`Update ${t} on its own when its author changes it? ttheme checks once a day, when you run it`,initialValue:!1});if(re(e))throw Error("no answer given — nothing was added");return e}async function Dv(t,e){let n=ui(`Fetching ${st(e)}`);try{return await ac(t,e)}finally{n.done()}}async function DF(t,e,n){let r=await Dv(t,n),i=q(t),s=Jt(i.marketplaces),o=qv(t,s,n,r.id);if(o)throw Error(`${r.id} already names the marketplace at ${st(o)} — \`ttheme marketplace remove ${r.id}\` first`);let{[e]:a,...c}=i.updates??{},u=a===void 0?c:{...c,[n]:a};return Qe(t,fc(i,s.map((f)=>f===e?n:f),u)),Go(t,r),r}async function Tp(t,e){let n=An(e),r=Jt(q(t).marketplaces);if(r.includes(n))return console.log(`${st(n)} is already added`),{source:n,id:li(t,n),fresh:!1};let i=wt(n)?r.find((c)=>wt(c)&&sr(c,n)):void 0;if(i){let c=await DF(t,i,n);return console.log(`Moved ${c.id} to ${Ha(n)??"its default branch"} · ${st(n)} — ${jt(It(c.entries).length)}`),{source:n,id:c.id,fresh:!1}}if(Rt(n)){let c=we(Je(n));Ap(t,n,c);let u=Tn(n,c,lc(t)).length;return console.log(`Added ${c} · ${st(n)} — ${jt(u)}, read in place`),{source:n,id:c,fresh:!0}}let s=await Dv(t,n),o=n===J?void 0:await qF(s.id);Ap(t,n,s.id,o),Go(t,s);let a=jt(It(s.entries).length);return console.log(n===J?`Added the official marketplace — ${a}`:`Added ${s.id} · ${st(n)} — ${a}${o?", updating on its own":""}`),{source:n,id:s.id,fresh:!0}}async function JF(t){let e=Y(),{source:n,id:r,fresh:i}=await Tp(e,t);if(!i)return;if(Rt(n))console.log("\nThe Browse tab of `ttheme` picks them · once the folder is on GitHub, `ttheme marketplace add <owner>/<repo>` adds it anywhere");else if(n===J)console.log("\nThe Browse tab of `ttheme` picks them");else console.log(`
631
- The Browse tab of \`ttheme\` picks them, or \`ttheme add ${r}/<palette>\``)}function Hp(t,e){if(wt(e))BF(or(t,e),{force:!0})}function Lp(t){return`${jt(t.length)} installed from it keep${t.length===1?"s":""} working: ${t.join(", ")} — \`ttheme remove\` drops ${t.length===1?"it":"them"}`}function YF(t){let e=Y(),n=q(e),r=Jt(n.marketplaces),i=r.find((u)=>Fl(e,u)===t)??r.find((u)=>u===Jv(t));if(!i)throw Error(`no marketplace named ${t} — \`ttheme marketplace\` lists them`);let s=Fl(e,i),o=n.palettes.filter((u)=>zv(u)===s),a=r.filter((u)=>u!==i),c=fc(n,a,n.updates??{});if(Qe(e,c),Hp(e,i),qt(e,lt(e),c),console.log(`Removed ${s??t} · ${st(i)}`),o.length>0)console.log(Lp(o))}function Jv(t){try{return An(t)}catch{return}}function VF(t,e){try{if(e===J)return It(Dr(Ll(fn(t),"utf8")).palettes).length;if(Rt(e))return Tn(e,li(t,e),lc(t),de(!1)).length;return Vi(e,ar(t,e),lc(t),de(!1)).entries.length}catch{return}}function Fp(t,e,n=wr(),r=Date.now()){if(Rt(e))return"read in place";if(e===J)return"comes with ttheme";let i=n[e],s=vp(t,e);if(i&&(s===void 0||i.at>s))return`update failed ${Uo(i.at,r)}`;return s===void 0?"never updated":`updated ${Uo(s,r)}`}function ZF(){let t=Y(),e=q(t),n=Jt(e.marketplaces);if(n.length===0){console.log("No marketplaces — `ttheme marketplace add official` brings the official one back");return}let r=wr(),i=n.map((a)=>{let c=Fl(t,a)??"?",u=VF(t,a),f=e.palettes.filter((h)=>zv(h)===c).length,l=Rt(a)?[]:[`auto-update ${qr(a,e.updates)?"on":"off"}`],d=a===J?void 0:cc(t,a)?.info.description;return{name:c,where:st(a),about:d,note:[u===void 0?"Unreadable":jt(u),...f>0?[`${f} installed`]:[],...l,Fp(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 Cp(t,e){return Ki([t.id,t.source,t.about,...t.palettes.flatMap((n)=>[n.name,n.catalog??""])],e)}async function XF(t){let e=Y(),{marketplaces:n,at:r,offline:i}=await Tl();if(i)console.log(`Offline — the list from ${Uo(r)} (${i})
632
- `);let s=n.filter((u)=>!t||Cp(u,t));if(s.length===0){console.log(`No marketplace carries the ${Di} topic${t?` and matches ${t}`:""} yet`);return}let o=new Set(Jt(q(e).marketplaces).map(zr)),a=Math.max(...s.map((u)=>u.id.length)),c=Math.max(...s.map((u)=>u.source.length));for(let u of s){let f=`★${u.stars}`.padStart(5);console.log(` ${o.has(u.source)?"●":"○"} ${u.id.padEnd(a)} ${u.source.padEnd(c)} ${f} ${jt(u.palettes.length)} ${u.about}`)}console.log("\n`ttheme marketplace add <owner/repo>` adds one")}function Yv({name:t}){return`ttheme-${t}`}function QF(t,e){_F(Au(t),{recursive:!0}),L(uc(t,ot),nk(e)),L(uc(t,"README.md"),`# ${we(e)}
647
+ `);if(o!==i)H(r,o)}import{execFile as EL,spawn as ML,spawnSync as Ep}from"node:child_process";import{mkdirSync as xL,readFileSync as OL,realpathSync as Mv}from"node:fs";import{homedir as PL,tmpdir as xv}from"node:os";import{dirname as IL,join as Mp}from"node:path";var lc=`npx ${dt.name}@latest init`,Pp=86400000,RL=3600000,AL=1e4,xp=/^(\d+)\.(\d+)\.(\d+)$/;function Ov(t,e){let n=xp.exec(t),r=xp.exec(e);if(!n||!r)return!1;return([1,2,3].map((s)=>Number(n[s])-Number(r[s])).find((s)=>s!==0)??0)>0}function Wo(t=process.env){return t.TTHEME_AUTO_UPDATE!=="off"&&(t.CI===void 0||t.CI===""||t.CI==="false")}function Op(){return Mp(process.env.XDG_STATE_HOME??Mp(PL(),".local","state"),"ttheme","release.json")}function fc(){try{let t=JSON.parse(OL(Op(),"utf8"));return{checked:typeof t.checked==="number"?t.checked:0,...typeof t.latest==="string"?{latest:t.latest}:{},...typeof t.told==="number"?{told:t.told}:{}}}catch{return{checked:0}}}function Uo(t){xL(IL(Op()),{recursive:!0}),H(Op(),`${JSON.stringify(t)}
648
+ `)}function Pv(t=AL){return new Promise((e,n)=>{EL("npm",["view",`${dt.name}@latest`,"version","--prefer-online"],{cwd:xv(),encoding:"utf8",timeout:t,env:{...process.env,npm_config_update_notifier:"false"}},(r,i,s)=>{if(r){let a=s.split(`
649
+ `).find((f)=>/\S/.test(f))?.replace(/^npm (error|ERR!) /,""),{code:c,killed:u}=r;n(Error(c==="ENOENT"?"cannot run npm":u?`npm did not answer within ${t/1000} s`:`npm could not ask its registry — ${a??"it gave no reason"}`));return}let o=i.trim();if(!xp.test(o)){n(Error("the npm registry named no version"));return}e(o)})})}function Iv(t=Date.now()){let e=fc();if(!Wo()||t-e.checked<Pp)return;try{Uo({...e,checked:t}),ML(process.execPath,[process.argv[1],"latest"],{detached:!0,stdio:"ignore",env:process.env}).unref()}catch{}}async function Rv(){let t=fc();try{return Uo({...t,checked:Date.now(),latest:await Pv()}),0}catch{return Uo({...t,checked:Date.now()-Pp+RL}),1}}function Av(t=Y()){return Mp(t,"ttheme","ttheme.js")}function Nv(){try{return Mv(process.argv[1])===Mv(Av())}catch{return!1}}function NL(){return Nv()?"`ttheme update` updates it":`\`${lc}\` updates it`}function Tv(t,e=dt.version){return`ttheme ${t} is out, you have ${e} — ${NL()}`}function Hv(t=Date.now()){let e=fc();if(!Wo()||!e.latest||!Ov(e.latest,dt.version)||t-(e.told??0)<Pp)return;if(process.stderr.isTTY)Uo({...e,told:t});ul([Tv(e.latest)])}function Fv(t,e){console.log(`Updating ttheme ${dt.version} → ${t}`);let n=Ep("npx",["--yes",`${dt.name}@${t}`,"init","--yes"],{cwd:xv(),stdio:"inherit",env:{...process.env,npm_config_prefer_online:"true"}});if(n.error)throw Error(`cannot run npx — ${n.error.message}; \`${lc}\` updates ttheme once npm is there`);if(n.status!==0)throw Error(`npx stopped with status ${n.status} — ttheme ${dt.version} is still installed`);let r=Av(),i=Ep(process.execPath,[r,"--version"],{encoding:"utf8"}).stdout?.trim();if(i!==t)throw Error(`${r} is ${i||"unreadable"} after the update, not ${t} — \`${lc}\` tries again`);let s=fc();return Uo({...s,latest:t}),Ep(process.execPath,[r,"update",...e],{stdio:"inherit",env:{...process.env,TTHEME_UPDATED:t}}).status??1}async function Lv(){if(process.env.TTHEME_UPDATED)return{note:` ttheme ${dt.version} — updated`};let t;try{t=await Pv()}catch(e){return{note:` ttheme ${dt.version} — could not check for a newer one: ${e.message}`}}if(Uo({...fc(),checked:Date.now(),latest:t}),!Ov(t,dt.version))return{note:` ttheme ${dt.version} — up to date`};return Nv()?{latest:t,note:""}:{note:` ${Tv(t)}`}}function Cv(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 jv(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=Cv(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 _v(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=Cv(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 TL}from"node:zlib";var ms=512,Bv=67108864,Ip=new TextDecoder;function Ko(t,e,n){let r=t.subarray(e,e+n),i=r.indexOf(0);return Ip.decode(i<0?r:r.subarray(0,i))}function HL(t){if((t[124]??0)&128)throw Error("the archive holds a file too large to be a palette");let e=Number.parseInt(Ko(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 FL(t){let e=0,n;while(e<t.length){let r=t.indexOf(32,e),i=r<0?Number.NaN:Number.parseInt(Ip.decode(t.subarray(e,r)),10);if(!Number.isFinite(i)||i<=0)break;let s=Ip.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 LL(t){if(t[0]!==31||t[1]!==139)return t;try{return TL(t,{maxOutputLength:Bv})}catch(e){throw Error(e instanceof RangeError?`the archive unpacks to more than ${Bv/1024/1024} MB`:"the archive is not a gzip file that reads")}}function Gv(t){let e=LL(t),n=new Map,r,i=0;while(i+ms<=e.length){let s=e.subarray(i,i+ms);if(s.every((l)=>l===0))break;let o=HL(s),a=e.subarray(i+ms,i+ms+o);i+=ms+Math.ceil(o/ms)*ms;let c=String.fromCharCode(s[156]??0);if(c==="x"){r=FL(a)??r;continue}if(c==="L"){r=Ko(a,0,a.length);continue}let u=Ko(s,257,5)==="ustar"?Ko(s,345,155):"",f=r??(u?`${u}/${Ko(s,0,100)}`:Ko(s,0,100));if(r=void 0,c==="0"||c==="\x00")n.set(f.split("/").slice(1).join("/"),a)}return n}var GL=86400000,UL=3600000,Np=5000;function Rp(){return Uv(process.env.XDG_STATE_HOME??Uv(_L(),".local","state"),"ttheme","marketplaces.json")}function Sr(){try{let t=JSON.parse(zv(Rp(),"utf8"));return Object.fromEntries(Object.entries(t).filter((e)=>typeof e[1]?.at==="number"&&typeof e[1].error==="string"))}catch{return{}}}function Wv(t,e){let n=Sr();if(e===void 0){if(!(t in n))return;delete n[t]}else n[t]={at:Date.now(),error:e};Kv(BL(Rp()),{recursive:!0}),H(Rp(),`${JSON.stringify(n,null,2)}
650
+ `)}function Tp(t,e){let n=wt(e)?fr(t,e):void 0;try{return n?CL(n).mtimeMs:void 0}catch{return}}function WL(t,e,n,r){return t&&(e===void 0||r-e>=GL)&&(n===void 0||r-n>=UL)}function Hp(t,e,n=Date.now()){let r=Sr();return Yt(e.marketplaces).filter((i)=>WL(Zr(i,e.updates),Tp(t,i),r[i]?.at,n))}function KL(t,e){let n=new TextDecoder,r=Object.fromEntries(Gv(t).entries().filter(([i])=>i===ot||i.startsWith("palettes/")&&i.endsWith(".toml")).map(([i,s])=>[i,n.decode(s)]));return{...e?{etag:e}:{},files:r}}async function Fp(t,e,n,r){let i;try{i=await Da(fk(t),e,n,r?{"if-none-match":r}:{})}catch(s){if(s instanceof Ku){let o=Ba(t);throw Error(`${st(t)}${o?` has no ${o}`:" is not there"} — is the repository public?`)}throw s}if(i.status===304)return;return KL(new Uint8Array(await i.arrayBuffer()),i.headers.get("etag"))}function Lp(t,e,n){let{id:r,info:i,entries:s}=Zi(t,e,n,pe(!1));return{source:t,id:r,entries:s,archive:e,info:i}}function dc(t){return qo(t,J)}async function hc(t,e,n,r){if(e===J){if(!Ap(mn(t)))throw Error(`the official marketplace is not on this machine — \`${lc}\` puts it back`);return{source:e,id:J,entries:qo(t,J)}}let i=await Fp(e,n,r);if(!i)throw Error(`${st(e)} answered as if nothing had changed`);return Lp(e,i,dc(t))}function zo(t,e){if(!("archive"in e))return;Kv(bo(t),{recursive:!0}),H(fr(t,e.source),`${JSON.stringify(e.archive)}
651
+ `)}function zL(t,e){try{return dr(t,e)}catch{return}}function qo(t,e){try{if(e===J)return Xr(zv(mn(t),"utf8")).palettes;return Zi(e,dr(t,e),dc(t),pe(!1)).entries}catch{return[]}}function qL(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.keys()].filter((i)=>n.has(i)&&n.get(i)!==r.get(i)),gone:[...n.keys()].filter((i)=>!r.has(i))}}async function DL(t,e,n){if(!wt(e))return hc(t,e,n);let r=zL(t,e),i=await Fp(e,n,void 0,r?.etag);return i&&Lp(e,i,dc(t))}async function Cp(t,e,n){let r=qo(t,e),i;try{i=await DL(t,e,n)}catch(o){throw Wv(e,o.message),o}if(i)zo(t,i);else{let o=new Date;jL(fr(t,e),o,o)}Wv(e,void 0);let s=i?.entries??r;return{source:e,id:i?.id??Wu(e,dr(t,e)),count:At(s).length,change:qL(r,s)}}async function jp(t,e,n){try{return{source:e,refreshed:await Cp(t,e,n)}}catch(r){return{source:e,failure:r instanceof Error?r:Error(String(r))}}}function qv(t,e){return`${st(t)}: ${e.message}`}function _t(t){return`${t} palette${t===1?"":"s"}`}function Do(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 Dv({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 _p(t){let e=Dv(t.change);return`${t.id} — ${_t(t.count)}${e?` (${e})`:""}`}function Bp(t){return Dv(t.change)?`Updated ${_p(t)}`:void 0}function mc(t,e,n=dc(t)){try{if(Rt(e)){let r=Ye(e),i=ye(r);return{id:i,info:r,entries:Cn(e,i,n,pe(!1))}}return wt(e)?Zi(e,dr(t,e),n,pe(!1)):void 0}catch{return}}function JL(t){if(!Ap(hn(t)))return[];let e=q(t),n=dc(t),r={renamed:new Map,removed:[]};for(let u of Yt(e.marketplaces)){let f=mc(t,u,n);if(f)jv(f.id,f.info,new Set(f.entries.map((l)=>ne(l.name))),e.palettes,r)}if(r.renamed.size===0&&r.removed.length===0)return[];let i=lt(t,!1);Bo(t,i,e.terminals,[...r.renamed.keys(),...r.removed]),Pk(t,r.renamed,r.removed),L$(t,r.renamed),Ev(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 en(t,i,e,{...a,palettes:s,...c?{startup:c}:{}}),[...[...r.renamed].map(([u,f])=>`${u} is ${f} now — its marketplace renamed it`),...r.removed.map((u)=>`${u} was removed from its marketplace`)]}function Gp(t){let e=vo(t,lt(t,!1)).map((n)=>n.name);if(e.length===0)return;return`${e.join(", ")} ${e.length===1?"has":"have"} an update from ${e.length===1?"its marketplace":"their marketplaces"} — ctrl+r on a palette marked ↑ in Browse (\`ttheme\`) takes it`}function ps(t,e){let n=JL(t),r=q(t),i=new Set(e.flatMap((o)=>o.change.gone)),s=r.palettes.filter((o)=>i.has(o)).map((o)=>`${o} left its marketplace — ttheme keeps the copy you have`);return[...n,...s]}async function Jv(t=Y()){try{if(!Wo()||!Ap(hn(t)))return;let e=Hp(t,q(t));if(e.length===0)return;let n=mi(`Checking ${e.map(st).join(", ")} for updates`),r=await Promise.all(e.map((o)=>jp(t,o,Np)));n.done();let i=r.flatMap((o)=>("refreshed"in o)?[o.refreshed]:[]),s=i.flatMap((o)=>Bp(o)??[]);if(s.length===0)return;ul([...s,...ps(t,i),...[Gp(t)??[]].flat()])}catch{return}}var ZL="https://kecan0406.github.io/ttheme/marketplaces.json",XL=/^#[0-9a-f]{6}$/i,QL=/^(cursor|foreground|background|selection|ansi(1[0-5]|[0-9]))$/,tC=/^\d{4}-\d{2}-\d{2}$/;function eC(t){return t.replace(/[\p{Cc}\s]+/gu," ").trim()}function Jo(t){return typeof t==="string"?eC(t):void 0}function Yv(t){return typeof t==="string"&&XL.test(t)?t.toLowerCase():void 0}function nC(t,e){if(typeof e!=="object"||e===null)return;let n=e,r=Jo(n.name),[i,s,o,a]=[n.background,n.foreground,n.cursor,n.selection].map(Yv),c=Array.isArray(n.ansi)?n.ansi.map(Yv):[],u=Array.isArray(n.signatureSlots)?n.signatureSlots:[];if(!r||re(`${t}/${r}`)||!i||!s||!o||!a||c.length!==16||c.some((l)=>l===void 0)||u.length!==3||!u.every((l)=>typeof l==="string"&&QL.test(l)))return;let f=Jo(n.catalog);return{name:r,...f?{catalog:f}:{},background:i,foreground:s,cursor:o,selection:a,ansi:c.filter((l)=>l!==void 0),signatureSlots:u}}function rC(t){if(typeof t!=="object"||t===null)return;let e=t,n=Jo(e.id),r=Jo(e.source);if(!n||!r||re(`${n}/x`))return;let i;try{i=Fn(r)}catch{return}if(!wt(i))return;let s=(Array.isArray(e.palettes)?e.palettes:[]).flatMap((c)=>nC(n,c)??[]);if(s.length===0)return;let o=typeof e.stars==="number"&&Number.isFinite(e.stars)&&e.stars>=0?Math.floor(e.stars):0,a=Jo(e.updated)??"";return{id:n,source:i,about:Jo(e.about)??"",stars:o,updated:tC.test(a)?a:"",palettes:s}}function Vv(t){let e=JSON.parse(t),n=typeof e==="object"&&e!==null?e.marketplaces:void 0;if(!Array.isArray(n))throw Error("the marketplace index lists no marketplaces");let r=new Set;return n.flatMap((i)=>{let s=rC(i);if(!s||r.has(s.id))return[];return r.add(s.id),[s]})}function iC(){return VL(Tn(),"marketplace-index.json")}function sC(t){try{let e=JSON.parse(YL(t,"utf8")),n=typeof e==="object"&&e!==null?e:{};return typeof n.etag==="string"&&typeof n.at==="number"&&typeof n.text==="string"?{etag:n.etag,at:n.at,text:n.text}:void 0}catch{return}}async function Gl(t,e=iC(),n=ZL){let r=sC(e),i;try{i=r?Vv(r.text):void 0}catch{i=void 0}try{let s=await Da(n,void 0,t,r&&i?{"if-none-match":r.etag}:{}),o=Date.now();if(s.status===304&&r&&i)return H(e,JSON.stringify({...r,at:o})),{marketplaces:i,at:o};let a=await s.text(),c=Vv(a);return H(e,JSON.stringify({etag:s.headers.get("etag")??"",at:o,text:a})),{marketplaces:c,at:o}}catch(s){if(!r||!i)throw s;return{marketplaces:i,at:r.at,offline:s instanceof Error?s.message:String(s)}}}var eS=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,lC=["add","remove","search","init","check"];function Wp(){return process.stdin.isTTY===!0&&process.stdout.isTTY===!0}function fC(){try{let t=oC("gh",["api","user","--jq",".login"],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:1e4}).trim().toLowerCase();return eS.test(t)?t:void 0}catch{return}}async function dC(t,e){if(e.author)return e.author;let n=fC();if(!n){if(!Wp())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 ym({message:"Your GitHub handle — your palettes are named <handle>@<marketplace>/<palette>",validate:(i)=>eS.test((i??"").toLowerCase())&&(i??"").length<=39?void 0:"that is not a GitHub handle"});if(se(r))throw Error("no handle given");n=r.toLowerCase()}return tn(t,{...e,author:n}),console.log(`Your palettes are named ${n}@<marketplace>/<palette>`),n}function pi(t,e){if(e===J)return J;return Rt(e)?ye(Ye(e)):Wu(e,dr(t,e))}function Kl(t,e){try{return pi(t,e)}catch{return}}function nS(t){return et(t)??J}function gc(t){return lt(t).palettes.filter((e)=>et(e.name)===void 0)}function hC(t){let e=pc(import.meta.dirname,"..","dist","manifest.json");return Ul(e)?Xr(Wl(e,"utf8")).palettes:gc(t)}function bc(t,e,n){let{updates:r,...i}=t,s=Object.entries(n).filter(([o,a])=>wt(o)&&e.includes(o)&&a!==Zr(o,{}));return{...i,marketplaces:e,...s.length>0?{updates:Object.fromEntries(s)}:{}}}function rS(t,e,n,r){return e.find((i)=>i!==n&&!lr(i,n)&&Kl(t,i)===r)}function Up(t,e,n,r){let i=q(t),s=Yt(i.marketplaces),o=rS(t,s,e,n);if(o)throw Error(`${n} already names the marketplace at ${st(o)} — \`ttheme marketplace remove ${n}\` first`);let a=r===void 0?{...i.updates}:{...i.updates,[e]:r};tn(t,bc(i,s.includes(e)?s:[...s,e],a))}async function mC(t){if(!Wp())return!1;let e=await Be({message:`Update ${t} on its own when its author changes it? ttheme checks once a day, when you run it`,initialValue:!1});if(se(e))throw Error("no answer given — nothing was added");return e}async function iS(t,e){let n=mi(`Fetching ${st(e)}`);try{return await hc(t,e)}finally{n.done()}}async function pC(t,e,n){let r=await iS(t,n),i=q(t),s=Yt(i.marketplaces),o=rS(t,s,n,r.id);if(o)throw Error(`${r.id} already names the marketplace at ${st(o)} — \`ttheme marketplace remove ${r.id}\` first`);let{[e]:a,...c}=i.updates??{},u=a===void 0?c:{...c,[n]:a};return tn(t,bc(i,s.map((f)=>f===e?n:f),u)),zo(t,r),r}async function Kp(t,e){let n=Fn(e),r=Yt(q(t).marketplaces);if(r.includes(n))return console.log(`${st(n)} is already added`),{source:n,id:pi(t,n),fresh:!1};let i=wt(n)?r.find((c)=>wt(c)&&lr(c,n)):void 0;if(i){let c=await pC(t,i,n);return console.log(`Moved ${c.id} to ${Ba(n)??"its default branch"} · ${st(n)} — ${_t(At(c.entries).length)}`),{source:n,id:c.id,fresh:!1}}if(Rt(n)){let c=ye(Ye(n));Up(t,n,c);let u=Cn(n,c,gc(t)).length;return console.log(`Added ${c} · ${st(n)} — ${_t(u)}, read in place`),{source:n,id:c,fresh:!0}}let s=await iS(t,n),o=n===J?void 0:await mC(s.id);Up(t,n,s.id,o),zo(t,s);let a=_t(At(s.entries).length);return console.log(n===J?`Added the official marketplace — ${a}`:`Added ${s.id} · ${st(n)} — ${a}${o?", updating on its own":""}`),{source:n,id:s.id,fresh:!0}}async function gC(t){let e=Y(),{source:n,id:r,fresh:i}=await Kp(e,t);if(!i)return;if(Rt(n))console.log("\nThe Browse tab of `ttheme` picks them · once the folder is on GitHub, `ttheme marketplace add <owner>/<repo>` adds it anywhere");else if(n===J)console.log("\nThe Browse tab of `ttheme` picks them");else console.log(`
652
+ The Browse tab of \`ttheme\` picks them, or \`ttheme add ${r}/<palette>\``)}function zp(t,e){if(wt(e))uC(fr(t,e),{force:!0})}function qp(t){return`${_t(t.length)} installed from it keep${t.length===1?"s":""} working: ${t.join(", ")} — \`ttheme remove\` drops ${t.length===1?"it":"them"}`}function bC(t){let e=Y(),n=q(e),r=Yt(n.marketplaces),i=r.find((u)=>Kl(e,u)===t)??r.find((u)=>u===sS(t));if(!i)throw Error(`no marketplace named ${t} — \`ttheme marketplace\` lists them`);let s=Kl(e,i),o=n.palettes.filter((u)=>nS(u)===s),a=r.filter((u)=>u!==i),c=bc(n,a,n.updates??{});if(tn(e,c),zp(e,i),Dt(e,lt(e),c),console.log(`Removed ${s??t} · ${st(i)}`),o.length>0)console.log(qp(o))}function sS(t){try{return Fn(t)}catch{return}}function wC(t,e){try{if(e===J)return At(Xr(Wl(mn(t),"utf8")).palettes).length;if(Rt(e))return Cn(e,pi(t,e),gc(t),pe(!1)).length;return Zi(e,dr(t,e),gc(t),pe(!1)).entries.length}catch{return}}function Dp(t,e,n=Sr(),r=Date.now()){if(Rt(e))return"read in place";if(e===J)return"comes with ttheme";let i=n[e],s=Tp(t,e);if(i&&(s===void 0||i.at>s))return`update failed ${Do(i.at,r)}`;return s===void 0?"never updated":`updated ${Do(s,r)}`}function $C(){let t=Y(),e=q(t),n=Yt(e.marketplaces);if(n.length===0){console.log("No marketplaces — `ttheme marketplace add official` brings the official one back");return}let r=Sr(),i=n.map((a)=>{let c=Kl(t,a)??"?",u=wC(t,a),f=e.palettes.filter((h)=>nS(h)===c).length,l=Rt(a)?[]:[`auto-update ${Zr(a,e.updates)?"on":"off"}`],d=a===J?void 0:mc(t,a)?.info.description;return{name:c,where:st(a),about:d,note:[u===void 0?"Unreadable":_t(u),...f>0?[`${f} installed`]:[],...l,Dp(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 Jp(t,e){return zi([t.id,t.source,t.about,...t.palettes.flatMap((n)=>[n.name,n.catalog??""])],e)}async function kC(t){let e=Y(),{marketplaces:n,at:r,offline:i}=await Gl();if(i)console.log(`Offline — the list from ${Do(r)} (${i})
653
+ `);let s=n.filter((u)=>!t||Jp(u,t));if(s.length===0){console.log(`No marketplace carries the ${Ji} topic${t?` and matches ${t}`:""} yet`);return}let o=new Set(Yt(q(e).marketplaces).map(Vr)),a=Math.max(...s.map((u)=>u.id.length)),c=Math.max(...s.map((u)=>u.source.length));for(let u of s){let f=`★${u.stars}`.padStart(5);console.log(` ${o.has(u.source)?"●":"○"} ${u.id.padEnd(a)} ${u.source.padEnd(c)} ${f} ${_t(u.palettes.length)} ${u.about}`)}console.log("\n`ttheme marketplace add <owner/repo>` adds one")}function oS({name:t}){return`ttheme-${t}`}function yC(t,e){aC(_u(t),{recursive:!0}),H(pc(t,ot),hk(e)),H(pc(t,"README.md"),`# ${ye(e)}
633
654
 
634
655
  A [ttheme](https://github.com/kecan0406/ttheme) marketplace:
635
656
 
636
657
  \`\`\`sh
637
- ttheme marketplace add ${e.owner}/${Yv(e)}
658
+ ttheme marketplace add ${e.owner}/${oS(e)}
638
659
  ttheme
639
660
  \`\`\`
640
- `)}function Vv(t){return ee(`x@${t}/x`)?"takes lowercase letters, digits and single hyphens":void 0}async function Zv(){if(!Np())throw Error("name the marketplace: ttheme marketplace init <name>, or --in <name> on new");let t=await lm({message:"Your marketplace's name — its palettes are <you>@<name>/<palette>",validate:(e)=>Vv((e??"").toLowerCase())});if(re(t))throw Error("no marketplace name given");return t.toLowerCase()}async function Xv(t,e){let n=Yi(t);if(e){let o=n.find((a)=>a.name===e||a.id===e||a.dir===Jv(e));if(!o)throw Error(`${e} is not one of your local marketplaces — \`ttheme marketplace 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 marketplaces — --in names one: ${n.map((o)=>o.name).join(", ")}`);let s=await Zv();return Qv(t,Sh(t,s),s)}async function Qv(t,e,n){let r=!Hl(uc(e,ot)),i;if(r){let o=Vv(n);if(o)throw Error(`the marketplace name ${n} ${o}`);if(Hl(e)&&GF(e).length>0)throw Error(`${e} is not empty — pick a new folder for the marketplace`);i={owner:await KF(t,q(t)),name:n},QF(e,i)}else i=Je(e);let s=we(i);return Ap(t,e,s),console.log(`${r?"Made":"Added"} your marketplace ${s} · ${st(e)}`),{dir:e,...i,id:s}}function Bv(t){return t.startsWith(".")||t.startsWith("/")||t.startsWith("~")}async function tC(t){let e=Y(),n=t&&!Bv(t)?t.toLowerCase():t?Wv(An(t)).toLowerCase():await Zv(),r=t&&Bv(t)?An(t):Sh(e,n),i=await Qv(e,r,n),s=`${i.owner}/${Yv(i)}`;console.log(`
661
+ `)}function aS(t){return re(`x@${t}/x`)?"takes lowercase letters, digits and single hyphens":void 0}async function cS(){if(!Wp())throw Error("name the marketplace: ttheme marketplace init <name>, or --in <name> on new");let t=await ym({message:"Your marketplace's name — its palettes are <you>@<name>/<palette>",validate:(e)=>aS((e??"").toLowerCase())});if(se(t))throw Error("no marketplace name given");return t.toLowerCase()}async function uS(t,e){let n=Vi(t);if(e){let o=n.find((a)=>a.name===e||a.id===e||a.dir===sS(e));if(!o)throw Error(`${e} is not one of your local marketplaces — \`ttheme marketplace 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 marketplaces — --in names one: ${n.map((o)=>o.name).join(", ")}`);let s=await cS();return lS(t,Hh(t,s),s)}async function lS(t,e,n){let r=!Ul(pc(e,ot)),i;if(r){let o=aS(n);if(o)throw Error(`the marketplace name ${n} ${o}`);if(Ul(e)&&cC(e).length>0)throw Error(`${e} is not empty — pick a new folder for the marketplace`);i={owner:await dC(t,q(t)),name:n},yC(e,i)}else i=Ye(e);let s=ye(i);return Up(t,e,s),console.log(`${r?"Made":"Added"} your marketplace ${s} · ${st(e)}`),{dir:e,...i,id:s}}function Xv(t){return t.startsWith(".")||t.startsWith("/")||t.startsWith("~")}async function vC(t){let e=Y(),n=t&&!Xv(t)?t.toLowerCase():t?tS(Fn(t)).toLowerCase():await cS(),r=t&&Xv(t)?Fn(t):Hh(e,n),i=await lS(e,r,n),s=`${i.owner}/${oS(i)}`;console.log(`
641
662
  \`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:
642
663
 
643
664
  cd ${st(r)}
644
665
  git init -b main && git add -A && git commit -m "${i.id}"
645
666
  gh repo create ${s} --public --source . --push
646
- gh repo edit ${s} --add-topic ${Di}
667
+ gh repo edit ${s} --add-topic ${Ji}
647
668
 
648
- Every push is the marketplace: \`ttheme marketplace add ${s}\` works anywhere`)}function eC(t){let e=t?An(t):process.cwd(),n=uc(e,ot);if(!Hl(n))throw Error(`${st(e)} has no ${ot} — \`ttheme marketplace init ${st(e)}\` makes one`);let r=[],i=[],s=Ll(n,"utf8"),o;try{o=Je(e)}catch(h){return console.error(` ✗ ${h.message}`),1}let a=ji(s),c=a.owner;for(let h of Object.keys(a).filter((m)=>!Z$.includes(m)))i.push(`${ot}: unknown key ${h} — ttheme ignores it`);for(let h of Object.keys(c).filter((m)=>!X$.includes(m)))i.push(`${ot}: unknown key owner.${h} — ttheme ignores it`);for(let[h,m]of(Array.isArray(a.catalog)?a.catalog:[]).entries())for(let g of Object.keys(m).filter((b)=>!Q$.includes(b)))i.push(`${ot}: unknown key catalog[${h}].${g} — ttheme ignores it`);if(!o.description)i.push(`${ot}: no description — Browse and the marketplace page show one`);let u=we(o),f=Tn(e,u,zF(Y()),(h,m)=>r.push(`${Gv(e,h)}: ${m.replace(`${Wv(h)}: `,"")}`));for(let h of ho(e)){let m;try{m=n$(h.path,Ll(h.path,"utf8"))}catch{m=[]}for(let g of m)i.push(`${Gv(e,h.path)}: unknown key ${g} — ttheme ignores it`)}for(let h of o.catalogs){let m=f.filter((g)=>g.catalog===h.name);if(m.length===0)i.push(`${ot}: catalog ${h.name} has no folder under palettes/ — ttheme ignores it`);else if(h.lead&&!m.some((g)=>te(g.name)===h.lead))i.push(`${ot}: catalog ${h.name} leads with ${h.lead}, which is not in it — its first palette leads instead`)}let l=Pv(o.renames,new Set(f.map((h)=>te(h.name))));r.push(...l.errors.map((h)=>`${ot}: ${h}`)),i.push(...l.warnings.map((h)=>`${ot}: ${h}`));for(let h of f){let m=Fa(h).filter((b)=>b.startsWith(" ✗")),g=h.catalog?`${h.catalog}/${te(h.name)}`:te(h.name);console.log(` ${g}${m.length>0?`
669
+ Every push is the marketplace: \`ttheme marketplace add ${s}\` works anywhere`)}function SC(t){let e=t?Fn(t):process.cwd(),n=pc(e,ot);if(!Ul(n))throw Error(`${st(e)} has no ${ot} — \`ttheme marketplace init ${st(e)}\` makes one`);let r=[],i=[],s=Wl(n,"utf8"),o;try{o=Ye(e)}catch(h){return console.error(` ✗ ${h.message}`),1}let a=_i(s),c=a.owner;for(let h of Object.keys(a).filter((m)=>!ck.includes(m)))i.push(`${ot}: unknown key ${h} — ttheme ignores it`);for(let h of Object.keys(c).filter((m)=>!uk.includes(m)))i.push(`${ot}: unknown key owner.${h} — ttheme ignores it`);for(let[h,m]of(Array.isArray(a.catalog)?a.catalog:[]).entries())for(let p of Object.keys(m).filter((b)=>!lk.includes(b)))i.push(`${ot}: unknown key catalog[${h}].${p} — ttheme ignores it`);if(!o.description)i.push(`${ot}: no description — Browse and the marketplace page show one`);let u=ye(o),f=Cn(e,u,hC(Y()),(h,m)=>r.push(`${Zv(e,h)}: ${m.replace(`${tS(h)}: `,"")}`));for(let h of wo(e)){let m;try{m=h$(h.path,Wl(h.path,"utf8"))}catch{m=[]}for(let p of m)i.push(`${Zv(e,h.path)}: unknown key ${p} — ttheme ignores it`)}for(let h of o.catalogs){let m=f.filter((p)=>p.catalog===h.name);if(m.length===0)i.push(`${ot}: catalog ${h.name} has no folder under palettes/ — ttheme ignores it`);else if(h.lead&&!m.some((p)=>ne(p.name)===h.lead))i.push(`${ot}: catalog ${h.name} leads with ${h.lead}, which is not in it — its first palette leads instead`)}let l=_v(o.renames,new Set(f.map((h)=>ne(h.name))));r.push(...l.errors.map((h)=>`${ot}: ${h}`)),i.push(...l.warnings.map((h)=>`${ot}: ${h}`));for(let h of f){let m=Ua(h).filter((b)=>b.startsWith(" ✗")),p=h.catalog?`${h.catalog}/${ne(h.name)}`:ne(h.name);console.log(` ${p}${m.length>0?`
649
670
  ${m.join(`
650
671
  `)}`:" 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(`
651
- ${u} · ${jt(f.length)} · ${d(r.length,"error")} · ${d(i.length,"warning")}`),r.length>0?1:0}async function tS(t,e){switch(t){case void 0:ZF();return;case"add":await JF(Uv(t,e));return;case"remove":YF(Uv(t,e));return;case"search":await XF(e);return;case"init":await tC(e);return;case"check":return eC(e);default:throw Error(`unknown marketplace action ${t} — ${UF.join(", ")}, or none to list them`)}}function Uv(t,e){if(!e)throw Error(t==="add"?"marketplace add takes a repository or a folder: ttheme marketplace add alice/ttheme-dust":"marketplace remove takes a marketplace name — `ttheme marketplace` lists them");return e}function eS(t,e){let n=li(t,e);return`${n} — ${jt(Tn(e,n,lc(t),de(!1)).length)}, read in place`}function nS(t){return[...t].length===1&&t>=" "&&t!==""}function nC(t){return[...t.replace(/[\r\n\t]+/g," ")].filter(nS).join("")}function ps(t,e,n=()=>!0){if(e==="backspace")return[...Wh(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 nS(e)&&n(e)?t+e:void 0}class Ko{value;constructor(t=""){this.value=t}key(t){let e=ps(this.value,t);if(e===void 0)return!1;return this.value=e,!0}paste(t){this.value+=nC(t)}}import{performance as rC}from"node:perf_hooks";import{StringDecoder as iC}from"node:string_decoder";var sC=30,oC=50,aC=500,cC=5,zo=Buffer.from("\x1B[M"),jl="\x1B]1337;ReportCellSize\x07\x1B[16t\x1B[14t\x1B[18t",lS="\x1B[?1016$p\x1B[16t",fS={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"},uC={"\r":"enter","\n":"enter","\t":"tab","\b":"backspace","":"backspace","\x1B":"esc","\x00":"ctrl-space"},rS=/\[([0-?]*)([ -/]*)([@-~])/y,lC=/^\[[0-?]*[ -/]*$/,iS=/\[(<-?\d+;-?\d+;-?\d+)([Mm])/y,fC=/^\[<[-\d;]*$/,sS=/\](\d+)/y,dC=/^\]\d*$/,oS=/\]\d+;/y,hC=/^1337;ReportCellSize=([\d.]+);([\d.]+)(?:;([\d.]+))?$/,mC=/^(1[0-2]|17|4;\d{1,3});(rgba?:[0-9a-fA-F/]+)$/,dS="\x1B[200~",Cl="\x1B[201~";function pC(t){let e=uC[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 qo(t){return{kind:"key",key:t}}function Do(t){return{events:[qo("esc")],end:t+1}}function gC(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 bC=["left","middle","right",void 0];function jp(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=bC[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 wC(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?jp(s-32,o-33,a-33,!1):void 0;return{events:c?[c]:[],end:i}}function $C(t,e,n,r,i){let s=Math.max(0,e)/i.w,o=Math.max(0,n)/i.h,a=Math.floor(s),c=Math.floor(o),u=jp(t,a,c,r);return u&&{...u,fx:s-a,fy:o-c}}function aS(t,e,n,r){if((n==="M"||n==="m")&&e===""&&t.startsWith("<")){let[s=-1,o=0,a=0]=t.slice(1).split(";").map(Number),c=r?$C(s,o,a,n==="m",r):jp(s,o-1,a-1,n==="m");return c?[c]:[]}if(n==="t"&&e===""){let[s,o=0,a=0]=t.split(";").map(Number),c=s===6?"cell":s===4?"window":s===8?"grid":void 0;return c?[{kind:"size",of:c,h:o,w:a}]:[]}if(n==="y"&&e==="$"&&t.startsWith("?")){let[s=0,o=0]=t.slice(1).split(";").map(Number);return[{kind:"mode",mode:s,value:o}]}if(n==="c"&&t.startsWith("?"))return[{kind:"attributes"}];let i=e===""?fS[`${t}${n}`]:void 0;return i?[qo(i)]:[]}function kC(t,e,n,r){iS.lastIndex=e+1;let i=iS.exec(t);if(i)return{events:aS(i[1],"",i[2],r),end:e+1+i[0].length};rS.lastIndex=e+1;let s=rS.exec(t);if(!s){let l=t.slice(e+1);return!n&&(lC.test(l)||fC.test(l))?void 0:Do(e)}let[o,a="",c="",u=""]=s,f=e+1+o.length;if(a===""&&c===""&&u==="M")return wC(t,f,n);if(a==="200"&&u==="~"){let l=t.indexOf(Cl,f);if(l===-1)return n?{events:[{kind:"paste",text:t.slice(f)}],end:t.length}:void 0;return{events:[{kind:"paste",text:t.slice(f,l)}],end:l+Cl.length}}return{events:aS(a,c,u,r),end:f}}function yC(t){let e=hC.exec(t);if(e){let o=Number(e[3]??1);return[{kind:"size",of:"cell",h:Math.round(Number(e[1])*o),w:Math.round(Number(e[2])*o)}]}let n=mC.exec(t);if(n)return[{kind:"color",code:n[1],value:n[2]}];let[r="",i="",...s]=t.split(";");return[{kind:"osc",code:r,meta:gC(i),payload:s.join(";")}]}function vC(t,e,n){sS.lastIndex=e+1;let r=sS.exec(t),i=r?t[e+1+r[0].length]:void 0;if(i!==";"&&i!=="\x07"&&i!=="\x1B")return!n&&dC.test(t.slice(e+1))?void 0:Do(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:yC(t.slice(e+2,o)),end:o+(t[o]==="\x07"?1:2)}}function SC(t,e,n){let r=t[e+2];if(r===void 0)return n?Do(e):void 0;if(!/^[A-Za-z]$/.test(r))return Do(e);let i=fS[r];return{events:i?[qo(i)]:[],end:e+3}}function EC(t,e,n,r){let i=t[e+1];if(i===void 0)return n?Do(e):void 0;if(i==="[")return kC(t,e,n,r);if(i==="]")return vC(t,e,n);if(i==="O")return SC(t,e,n);if(i==="")return{events:[qo("alt-backspace")],end:e+2};if(/^[a-z]$/.test(i))return{events:[qo(`alt-${i}`)],end:e+2};return Do(e)}function cS(t,e=!1,n){let r=[],i=0;while(i<t.length){if(t[i]==="\x1B"){let a=EC(t,i,e,n);if(!a)return{events:r,rest:t.slice(i)};r.push(...a.events),i=a.end;continue}let s=String.fromCodePoint(t.codePointAt(i)),o=pC(s);if(o)r.push(qo(o));i+=s.length}return{events:r,rest:""}}function MC(t,e){for(let n=Math.min(zo.length-1,t.length-e);n>0;n--)if(t.subarray(t.length-n).equals(zo.subarray(0,n)))return t.length-n;return t.length}function xC(t){let e=[],n=0,r=t.indexOf(zo);while(r!==-1&&r+6<=t.length){e.push(t.subarray(n,r));let[s=0,o=0,a=0]=t.subarray(r+3,r+6);if(o>32&&a>32)e.push(Buffer.from(`\x1B[<${s-32};${o-32};${a-32}M`));n=r+6,r=t.indexOf(zo,n)}let i=r===-1?MC(t,n):r;return e.push(t.subarray(n,i)),{bytes:Buffer.concat(e),carry:i<t.length?t.subarray(i):void 0}}function uS(t){return oS.lastIndex=1,t.startsWith(dS)||t.startsWith("\x1B]")&&oS.test(t)}function OC(t,e){let n=t.slice(-Cl.length)+e;return t.startsWith(dS)?n.includes(Cl):n.includes("\x07")||n.includes("\x1B\\")}class _p{held="";timer;carry;pressed;wheeled;utf8=new iC("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=rC.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<cC)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<=aC;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.held&&!e.includes("\x1B")&&this.burst(e)){this.settle(),this.take([{kind:"paste",text:e}]);return}if(uS(this.held)&&!OC(this.held,e)){this.held+=e;return}let{events:n,rest:r}=cS(this.held+e,!1,this.cell());if(this.held=r,this.settle(),n.length>0)this.take(n)}settle(){let t=this.held.length+(this.carry?.length??0);if(t>0&&!uS(this.held))this.wait(t===1?sC:oC)}bytes(t){let{bytes:e,carry:n}=xC(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);let t=this.carry;this.carry=void 0;let e=t&&!t.subarray(0,zo.length).equals(zo)?this.utf8.write(t):"",{events:n}=cS(this.held+e,!0,this.cell());if(this.held="",n.length>0)this.take(n)}stop(){clearTimeout(this.timer),this.held="",this.carry=void 0}}class dc{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 Gp{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 Gl={on:"\x1B[?1049h",off:"\x1B[?1049l"},Bn={on:"\x1B[?25l",off:"\x1B[?25h"},fi={on:"\x1B[?7l",off:"\x1B[?7h"},$r={on:"\x1B[?2004h",off:"\x1B[?2004l"},wS={on:"\x1B[?1004h",off:"\x1B[?1004l"},PC={on:"\x1B[?1000h\x1B[?1002h\x1B[?1006h",off:"\x1B[?1006l\x1B[?1002l\x1B[?1000l"},hS={on:"\x1B[?1016h",off:"\x1B[?1016l\x1B[?1006h"};function di(t=process.env){return t.TTHEME_MOUSE==="off"?[]:[PC]}var $S={SIGHUP:1,SIGINT:2,SIGQUIT:3,SIGTERM:15},RC=3000;class mc extends Error{exit;constructor(t){super(t);this.exit=128+$S[t]}}var Gn=[],gs=new Map,hc=new Map,mS;function pS(t){return Gn.findLast((e)=>e.input===t)}var gS;function kS(t){for(let e of[...Gn].reverse())e.abort(t);if(!gS)gS=setTimeout(()=>{yS(),process.exit(t instanceof mc?t.exit:1)},RC).unref()}var IC=Object.fromEntries(Object.keys($S).map((t)=>[t,()=>kS(new mc(t))]));function yS(){for(let t of[...Gn].reverse())t.close()}function AC(){for(let t of Gn)t.reassert();Gn.at(-1)?.redraw()}function bS(t){let e=t?"on":"off";for(let[n,r]of Object.entries(IC))process[e](n,r);if(process[e]("uncaughtException",kS),process[e]("exit",yS),process.platform!=="win32")process[e]("SIGCONT",AC)}function _l(){}class vS{input;output;failed;modes=[];assumed;owned=[];keys;tty;take;resized;queued=[];asking;reject=_l;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 _p((r)=>this.deliver(r),t.burst,()=>gs.has(hS)?mS:void 0),this.failed=new Promise((r,i)=>{this.reject=i}),this.failed.catch(_l),this.tty&&!Gn.some((r)=>r.tty))bS(!0);Gn.push(this);let e="";for(let r of this.assumed)if(!gs.has(r))e+=r.on;for(let r of t.modes??[])e+=this.claim(r);this.write(e);let n=hc.get(this.input)??0;if(n===0)this.input.setRawMode?.(!0);hc.set(this.input,n+1),this.input.on("data",this.received),this.input.resume(),this.output.on("resize",this.resizing),this.output.on("error",_l)}hold(t){this.write(this.claim(t))}pixels(t){mS=t,this.hold(hS)}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=(gs.get(n)??1)-1;if(r===0)gs.delete(n),t+=n.off;else gs.set(n,r)}this.write(t),this.open=!1;let e=(hc.get(this.input)??1)-1;if(e===0)hc.delete(this.input),this.input.setRawMode?.(!1),this.input.pause();else hc.set(this.input,e);if(this.output.off("error",_l),Gn.splice(Gn.indexOf(this),1),this.tty&&!Gn.some((n)=>n.tty))bS(!1)}received=(t)=>{if(pS(this.input)===this&&!this.aborted)this.keys.feed(t)};resizing=()=>{if(pS(this.input)===this)this.resized?.()};claim(t){this.modes.push(t);let e=gs.get(t)??0;if(gs.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 hi(t,e){let n=new vS(t);try{return await e(n)}finally{n.close()}}var NC=3,ES={catalogs:{top:Xs,shelf:(t)=>et(t.name)?t.catalog:void 0},marketplaces:{top:(t)=>et(t.name)??J,shelf:(t)=>t.catalog}};function pc(t,e){return`${t}/${e}`}function SS(t){return et(t.name)?te(t.name):t.name}function Bl(t,e){let n=e.shelf(t);return n===void 0?void 0:pc(e.top(t),n)}function Ul(t){if(t?.kind==="palette")return`palette ${t.entry.name}`;if(t?.kind==="top")return`top ${t.name}`;if(t?.kind==="catalog")return`catalog ${pc(t.top,t.name)}`;if(t?.kind==="extra")return`extra ${t.extra.key}`;return t?.kind??""}function Jo(t){return t?.kind==="rule"}function Wl(t,e){return Ki([t.name,et(t.name)??"",t.native??"",t.catalog??"",...t.nativeNames??[],...Ou(t.booru)],e)}function MS(t,e,n,r="catalogs",i=[],s="tree"){let o=ES[r],a=n.trim(),c=[],u=new Set,f=(l)=>({kind:"palette",entry:l});for(let l of t){let d=o.top(l);if(l.default||u.has(d))continue;u.add(d);let h=t.filter((w)=>!w.default&&o.top(w)===d),m=a?h.filter((w)=>Wl(w,a)):h;if(a&&m.length===0)continue;let g=s==="inside"||s==="tree"&&(a.length>0||e.has(d));if(s!=="inside")c.push({kind:"top",name:d,...!et(l.name)&&d===l.catalog&&l.native?{native:l.native}:{},lead:h.find((w)=>w.lead)??l,expanded:g,count:m.length});if(!g)continue;let b=m.filter((w)=>o.shelf(w)!==void 0);for(let w of new Set(b.map((k)=>o.shelf(k)))){let k=b.filter((x)=>o.shelf(x)===w),v=k.find((x)=>x.lead)??k[0],S=a.length>0||e.has(pc(d,w));if(c.push({kind:"catalog",top:d,name:w,...v.native?{native:v.native}:{},lead:v,expanded:S,count:k.length}),S)c.push(...k.map(f))}c.push(...m.filter((w)=>o.shelf(w)===void 0).map(f))}for(let l of i)if(!u.has(l)&&(a===""||Ki([l],a)))c.push({kind:"top",name:l,expanded:e.has(l),count:0});return c}function TC(t,e){let n=e.trim(),r=new Set(t.filter((i)=>!i.default&&(n===""||Wl(i,n))).map(Xs));return MS(t,new Set,"").filter((i)=>i.kind==="top"&&r.has(i.name))}function HC(t){return t.includes("@")}function LC(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);if(!r(o))return o;let a=Math.sign(e),c=o+a;if(c>=0&&c<=s)return c;return i&&Math.abs(e)===1?c<0?s:0:o-a}function gc(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 FC(t){let e=t.findIndex((n)=>n.kind==="top"&&HC(n.name));return e>0&&t.slice(0,e).some((n)=>n.kind==="top")?[...t.slice(0,e),{kind:"rule"},...t.slice(e)]:t}function CC(t){let e=t.findIndex((n)=>n.kind==="palette");return e===-1?0:e}function Kl(t){return t==="decode"||t==="glitch"?t:"typewriter"}function bs(t,e,n,r){return dn({kind:"row",at:t,part:e,...r?{pane:r}:{}},n)}class Yo{picked;scope;maxItems;focus="lit";named=[];catalogs=[];layout;mode;pane;place;color;p;onFocus;note;badge;about;tops;heads;extras;entries=[];catalogPad=0;namePad=0;expanded=new Set;rows=[];cursor=0;top=0;span=1;filter="";lastFocused="";constructor(t){this.picked=t.picked,this.scope=t.scope??"palette",this.layout=t.layout??"catalogs",this.mode=t.mode??"tree",this.pane=t.pane,this.place=ES[this.layout],this.maxItems=t.maxItems??12,this.color=t.color??!0,this.p=Ce(this.color),this.onFocus=t.onFocus,this.note=t.note,this.badge=t.badge,this.about=t.about,this.tops=t.tops,this.heads=t.heads,this.extras=t.extras,this.load(t.entries),this.rebuild("first")}load(t){this.entries=t,this.named=t.filter((e)=>!e.default),this.catalogs=[...new Set(this.named.map(Xs))],this.catalogPad=Math.max(0,...this.catalogs.map((e)=>e.length)),this.namePad=Math.max(0,...this.named.map((e)=>this.indent(e).length+SS(e).length))}lead(){return this.mode==="inside"?"":" "}indent(t){return this.place.shelf(t)===void 0?this.lead():`${this.lead()} `}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(this.place.top(t.entry));let e=Bl(t.entry,this.place);if(e!==void 0)this.expanded.add(e)}this.setFilter("")}focusedRow(){return this.rows[this.cursor]}refocus(){this.lastFocused="",this.sync()}refresh(){this.rebuild("stay")}select(t){let e=this.rows.findIndex((n)=>Ul(n)===t);if(e===-1)return!1;return this.cursor=e,this.sync(),!0}members(t,e){let n=this.scope==="palette"?this.filter.trim():"";return this.under(t,e).filter((r)=>n===""||Wl(r,n))}under(t,e){return this.named.filter((n)=>this.place.top(n)===t&&(e===void 0||this.place.shelf(n)===e))}inside(t){return t.kind==="palette"?[t.entry]:t.kind==="top"?this.under(t.name):t.kind==="catalog"?this.under(t.top,t.name):[]}everyone(t){return t.flatMap((e)=>e.kind==="top"?this.members(e.name):[])}pick(){let t=this.rows[this.cursor],e=t?.kind==="palette"?[t.entry.name]:t?.kind==="top"?this.members(t.name).map((r)=>r.name):t?.kind==="catalog"?this.members(t.top,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.catalogs.filter((t)=>this.members(t).every((e)=>this.picked.has(e.name))).length}total(){return this.scope==="catalog"?this.catalogs.length:this.named.length}matched(){let t=this.filter.trim();if(this.scope==="catalog")return this.rows.filter((e)=>e.kind==="top").length;return t?this.named.filter((e)=>Wl(e,t)).length:this.named.length}sync(){let t=this.rows[this.cursor],e=t?.kind==="palette"?t.entry:t?.kind==="top"&&this.scope==="catalog"?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==="catalog"?TC(this.entries,this.filter):MS(this.entries,this.expanded,this.filter,this.layout,this.tops?.()??[],this.mode),r=this.layout==="marketplaces"||n.length===0?n:FC([{kind:"all",count:this.allCount(n)},...n]),i=(o)=>(o??[]).map((a)=>({kind:"extra",extra:a}));this.rows=[...i(this.heads?.()),...r,...i(this.extras?.())];let s=n.length>0?this.rows.indexOf(n[this.mode==="inside"&&!this.filter.trim()?0:CC(n)]):Math.max(0,this.rows.findIndex((o)=>!Jo(o)&&!(o.kind==="extra"&&o.extra.idle)));if(t==="first")this.cursor=s;else if(t==="keep"||t==="stay"){let o=Ul(e),a=e?.kind==="palette"||t==="stay"?this.rows.findIndex((u)=>Ul(u)===o):-1,c=e?.kind==="extra"&&t==="stay";this.cursor=a!==-1?a:c?Math.min(this.cursor,this.rows.length-1):s}else if(this.cursor>=this.rows.length)this.cursor=Math.max(0,this.rows.length-1);this.settle(),this.sync()}settle(){if(!Jo(this.rows[this.cursor]))return;let t=this.rows.findIndex((n,r)=>r>this.cursor&&!Jo(n)),e=this.rows.findLastIndex((n,r)=>r<this.cursor&&!Jo(n));this.cursor=t!==-1?t:e!==-1?e:this.cursor}allCount(t){return this.scope==="catalog"?t.length:this.everyone(t).length}move(t,e=!0){this.cursor=LC(this.cursor,t,this.rows.length,(n)=>Jo(this.rows[n]),e),this.sync()}point(t){let e=this.rows[t];if(!e||Jo(e))return!1;return this.cursor=t,this.sync(),!0}size(){return this.rows.length}outer(){let t=this.rows[this.cursor];return this.mode==="inside"&&(this.filter.trim()!==""||t===void 0||t.kind==="catalog"&&!t.expanded||t.kind==="palette"&&Bl(t.entry,this.place)===void 0)}flip(){let t=this.rows[this.cursor];if(t?.kind==="top"||t?.kind==="catalog")this.fold(!t.expanded)}foldable(){let t=this.rows[this.cursor];return(t?.kind==="catalog"||t?.kind==="top"&&this.mode==="tree")&&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)=>Ul(e)===t)),this.sync()}fold(t){if(this.filter||this.scope==="catalog")return;let e=this.rows[this.cursor];if(e?.kind==="top"){if(t!==e.expanded)this.toggle(e.name)}else if(e?.kind==="catalog"){if(t!==e.expanded)this.toggle(pc(e.top,e.name));else if(!t&&this.mode==="tree")this.reach(`top ${e.top}`)}else if(e?.kind==="palette"&&!t&&!e.entry.default){let n=Bl(e.entry,this.place);if(n===void 0){if(this.mode==="tree"){let r=this.place.top(e.entry);this.climb(r,`top ${r}`)}}else this.climb(n,`catalog ${n}`)}}page(){return this.span}window(){let t=this.rows.map((a,c)=>this.renderRow(a,c)),e=(a)=>t[a]?.length??0,n=Math.max(1,this.maxItems);this.top=Math.min(this.top,this.cursor);let r=0;for(let a=this.top;a<=this.cursor;a++)r+=e(a);while(this.top<this.cursor&&r>n)r-=e(this.top),this.top+=1;let i=0;for(let a=this.top;a<t.length;a++)i+=e(a);while(this.top>0&&i+e(this.top-1)<=n)this.top-=1,i+=e(this.top);let s=[],o=this.top;while(o<t.length&&(o===this.top||s.length+e(o)<=n))s.push(...t[o]??[]),o+=1;return this.span=Math.max(1,o-this.top),s.push(...t[o]??[]),{lines:s.slice(0,n),above:this.top,below:t.length-o}}renderRow(t,e){if(t.kind==="rule")return[` ${this.p.dim("── Marketplaces ──────────")}`];return(t.kind==="extra"?t.extra.text(e===this.cursor&&this.focus==="lit",e):this.rowText(t,e)).split(`
652
- `).map((r)=>r?bs(e,"row",r,this.pane):r)}rowText(t,e){let n=e===this.cursor&&this.focus!=="off",r=t.kind==="palette"?t.entry:t.kind==="all"?void 0:t.lead,i=this.color&&n&&this.focus==="lit"&&r!==void 0,{dim:s,bold:o}=this.p,a=(v)=>this.color?` ${ju(so(v),i?lr(v.foreground):kt)}`:"",c=!n?" ":i?`${lr(r.cursor)}${I.gutter}${kt} `:this.focus==="held"?this.color?`${this.p.dim(I.gutter)} `:" ":`${I.gutter} `,u=(v)=>i?`${c}${Bk(r.selection,r.foreground)} ${v} ${he}`:`${c} ${v}`,f=(v)=>bs(e,"box",`${v?I.on:I.off} `,this.pane),l=(v)=>bs(e,"fold",`${v?I.opened:I.closed} `,this.pane);if(t.kind==="all")return u(`${f(this.everyone(this.rows).every((v)=>this.picked.has(v.name)))}Select all ${s(`(${t.count})`)}`);if(t.kind==="top"&&this.scope==="catalog"){let v=`(${t.count})${t.native?` ${t.native}`:""}`;return u(`${f(this.pickedIn(t.name)===t.count)}${o(t.name.padEnd(this.catalogPad))}${t.lead?a(t.lead):""}${this.color?" ":" "}${s(v)}`)}let d=this.rows[this.cursor],h=(v,S)=>this.color&&d?.kind==="palette"&&v?this.p.accent(o(S)):o(S);if(t.kind==="top"){let v=h(d?.kind==="palette"&&this.place.top(d.entry)===t.name,t.name),S=t.native?` ${s(t.native)}`:"",x=this.badge?.(t.name)??"";if(this.about){let M=this.about(t.name,this.under(t.name),this.filter.trim()?t.count:void 0);return[...e>0?[""]:[],u(`${bs(e,"fold",`${M.added?I.on:I.off} `,this.pane)}${v}${S}${x}`),...M.lines.map((N)=>u(` ${N}`))].join(`
653
- `)}return u(`${l(t.expanded)}${v} ${s(`(${this.pickedIn(t.name)}/${t.count})`)}${S}${x}`)}if(t.kind==="catalog"){let v=d?.kind==="palette"&&Bl(d.entry,this.place)===pc(t.top,t.name),S=s(`(${this.pickedIn(t.top,t.name)}/${t.count})`),x=t.native?` ${s(t.native)}`:"";return u(`${this.lead()}${l(t.expanded)}${h(v,t.name)} ${S}${x}`)}let m=t.entry,g=this.indent(m),b=SS(m),w=this.color?b.padEnd(this.namePad-g.length):b,k=n?o(w):w;return u(`${g}${f(this.picked.has(m.name))}${k}${a(m)}${this.note?.(m)??""}`)}}function Bp(t){let e=t.named[Math.floor(Math.random()*t.named.length)],n=t.catalogs[Math.floor(Math.random()*t.catalogs.length)];return e&&n?`${e.name} | ${n}`:""}class zl{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 jC=5;class Up{picked;list;scope;color;required;most;hint;field=new Ko;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 Yo({entries:t.entries,picked:this.picked,scope:this.scope,maxItems:this.most,color:this.color,...t.onFocus?{onFocus:t.onFocus}:{}}),this.hint=new zl(t.fx??"typewriter",()=>Bp(this.list),()=>this.redraw())}prompt(){return hi({input:this.input,output:this.output,modes:[Bn,$r]},async(t)=>{let e=new dp((r)=>t.write(r),()=>t.cols),n=()=>{return this.list.maxItems=Math.max(NC,Math.min(this.most,t.rows-jC)),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=gc(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{dim:t,accent:e,warn:n}=Ce(this.color),r=this.scope==="catalog"?"Catalogs":"Palettes";if(this.state==="submit")return[`${t("◇")} ${r} ${t(`· ${this.list.pickedCount()} picked`)}`];if(this.state==="cancel")return[`${t(`◇ ${r} · cancelled`)}`];let i=this.field.value,s=`${e("◆")} ${r} ${t(`(${this.list.matched()}/${this.list.total()} · ${this.list.pickedCount()} picked)`)}`,o=this.hint.text(),a=`${e("│")} ${i?`${i}_`:t(`Search…${o?` e.g. ${o}`:""}`)}`,{lines:c,below:u}=this.list.window(),f=c.length>0?c.map((g)=>`${e("│")} ${g}`):[`${e("│")} ${t(`No ${this.scope==="catalog"?"catalogs":"palettes"} match '${i}'`)}`];while(f.length<this.list.maxItems)f.push(e("│"));let l=u>0?`${e("│")} ${t(`↓ ${u} more`)}`:e("│"),d=this.scope==="catalog"?"":" · ←→ fold",h=this.scope==="catalog"?"continue":"install",m=this.state==="error"?`${e("└")} ${n(this.error)}`:`${e("└")} ${t(`↑↓ move${d} · space pick · type to filter · enter ${h} · esc cancel`)}`;return[s,a,...f,l,m]}}var _C=40,GC=60,BC=42,UC=94,WC=22,xS=40,OS=10,ql=3,KC=500,PS=12,RS={title:"",lines:[],brief:""};function mi(t){let e=t.trim();if(e!==J&&!e.includes("/")&&!e.startsWith("~"))return;try{return An(e)}catch{return}}function Wp(t){return t===J?"Built in":wt(t)?t:st(t)}function IS(t){return t.charAt(0).toUpperCase()+t.slice(1)}class Kp{picked;field=new Ko;query=new Ko;adds=new Map;removes=new Set;want=new Map;renew=new Set;updates;tuned;busy=new Map;failed=new Map;peeked=new Map;peekFailed=new Map;staging=new Set;timers=new Map;refreshed=[];inflight=new Set;marketplaces;kept;installed;startup;io;order;color;p;hub;owns;input;output;maxItems=12;paint;list;inside;results;side="cards";showing="browse";landing;open;split=0;hint;screen;state="active";phase="browse";offset=0;started=!1;log=[];working="";stopped;beat=0;asking;leaving;goto;listing;loading=!1;loadError;asked=0;help=!1;live;constructor(t){this.marketplaces=t.marketplaces,this.kept=t.kept,this.installed=new Set(t.installed),this.updates=new Set(t.updates??[]),this.tuned=new Set(t.tuned??[]),this.startup=t.startup,this.io=t.io,this.order=t.order??((e)=>e),this.color=t.color??!0,this.p=Ce(this.color),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),this.list=new Yo({entries:this.entries(),picked:this.picked,layout:"marketplaces",mode:"cards",color:this.color,maxItems:this.maxItems,note:(e)=>this.mark(e),badge:(e)=>this.badge(e),about:(e,n,r)=>this.about(e,n,r),tops:()=>this.tops(),heads:()=>this.heads(),onFocus:(e)=>this.focus(e)}),this.inside=new Yo({entries:[],picked:this.picked,layout:"marketplaces",mode:"inside",pane:"panel",color:this.color,maxItems:this.maxItems,note:(e)=>this.mark(e),onFocus:(e)=>{if(this.side==="panel")this.focus(e)}}),this.inside.focus="off",this.results=new Yo({entries:[],picked:new Set,layout:"marketplaces",mode:"cards",color:this.color,maxItems:this.maxItems,heads:()=>this.searchHeads(),extras:()=>this.found()}),this.follow(),this.hint=new zl(t.fx??"typewriter",()=>Bp(this.list),()=>this.redraw());for(let e of t.due)this.update(e)}run(){let t=[...this.owns?[Gl,Bn,fi]:[],$r,...di()],e=this.owns?[]:[Bn,fi];return hi({input:this.input,output:this.output,modes:t,assume:e},async(n)=>{let r=new ds({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),renew:[...this.renew].filter((e)=>this.updates.has(e)&&this.picked.has(e)&&t.has(e)),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,this.landing=void 0;else if(/^[yn]$/i.test(t))this.answer(t.toLowerCase()==="y");return}if(this.phase!=="browse"){this.steer(t);return}if(this.showing==="search"){this.searchKey(t);return}let e=this.side==="panel",n=gc(t,(e?this.inside:this.list).page());if(t==="enter")if(e&&this.inside.foldable())this.inside.flip();else if(!e&&this.list.focusedRow()?.kind==="top")this.enter();else if(!e&&this.focusedFound()?.kind==="search")this.openSearch();else this.finish();else if((t==="esc"||t==="ctrl-u")&&this.field.value)this.clear();else if(t==="esc")if(e)this.back();else this.state="cancel";else if(t==="?")this.help=!0;else if(n!==void 0)this.move(n);else if(t==="up"||t==="down")this.move(t==="up"?-1:1);else if(t==="right")if(e)this.inside.fold(!0);else if(this.focusedFound()?.kind==="search")this.openSearch();else this.enter();else if(t==="left"){if(e&&this.inside.outer())this.back();else if(e)this.inside.fold(!1)}else if(t==="tab"||t==="shift-tab"){if(this.hub)this.leave(Dh(this.hub,t==="tab"?1:-1))}else if(t==="shift-left"||t==="shift-right"){if(!e)this.autoUpdate(t==="shift-right")}else if(t===" ")if(e)this.inside.pick();else this.activate();else if(t==="delete"){let r=this.focusedMarketplace();if(r&&!e)this.toggleMarketplace(r)}else if(t==="ctrl-r")this.refresh();else if(this.field.key(t))this.typed()}searchKey(t){let e=gc(t,this.results.page());if(t==="enter"||t===" ")this.take(t==="enter");else if((t==="esc"||t==="ctrl-u")&&this.query.value)this.query.value="",this.searchTyped();else if(t==="esc"||t==="left")this.closeSearch();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==="tab"||t==="shift-tab"){if(this.hub)this.leave(Dh(this.hub,t==="tab"?1:-1))}else if(t==="ctrl-r")this.loadIndex();else if(this.query.key(t))this.searchTyped()}take(t){let e=this.focusedFound();if(e?.kind==="back"){this.closeSearch();return}if(e?.kind==="state"){this.loadIndex();return}let n=e?.kind==="add"?e.source:e?.kind==="listed"?e.listed.source:void 0;if(n===void 0)return;let r=this.known(n);if(!r)this.landing=t?n:void 0,this.load(n,!0);else if(t)this.closeSearch(),this.list.select(`top ${r.id}`);else if(this.adds.has(r.source))this.adds.delete(r.source),this.want.delete(r.source),this.reload()}openSearch(){let t=this.field.value.trim();if(t&&!mi(t))this.query.value=t;if(this.showing="search",this.results.setFilter(this.query.value),this.results.refresh(),this.live&&!this.listing)this.loadIndex();this.watch()}closeSearch(){this.showing="browse",this.landing=void 0,this.follow(),this.watch()}searchTyped(){this.results.setFilter(this.query.value),this.watch()}loadIndex(){if(this.loading)return;this.loading=!0,this.loadError=void 0,this.redraw(),this.track(this.io.index()).then((t)=>{this.loading=!1,this.listing=t,this.results.refresh(),this.redraw()},(t)=>{this.loading=!1,this.loadError=t.message,this.results.refresh(),this.redraw()})}finish(){if(this.dirty())this.phase="review",this.offset=0;else this.state="submit"}enter(){if(this.follow(),this.side==="panel")return!0;if(this.list.focusedRow()?.kind!=="top"||this.inside.size()===0)return!1;return this.side="panel",this.list.focus="held",this.inside.focus="lit",this.inside.refocus(),!0}back(){this.side="cards",this.list.focus="lit",this.inside.focus="off"}follow(t=!1){let e=this.list.focusedRow(),n=e?.kind==="top"?e.name:void 0;if(t||n!==this.open)this.open=n,this.inside.setEntries(n===void 0?[]:this.membersOf(n));if(this.side==="panel"&&this.inside.size()===0)this.back()}membersOf(t){return this.entries().filter((e)=>(et(e.name)??J)===t)}refresh(){let t=this.focusedMarketplace();if(this.side==="panel")this.toggleRenew();else if(t&&wt(t.source)&&!this.adds.has(t.source))this.update(t.source)}pasted(t){if(this.phase!=="browse"||this.help||this.asking||this.leaving!==void 0)return;if(this.showing==="search")this.query.paste(t),this.searchTyped();else this.field.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,this.split>0&&t.col>=this.split);return}if(!r)return;if(t.action==="press"&&t.button==="left"){if(i&&r.kind==="row")this.point(r)}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.side===(r.pane?"panel":"cards"))this.move(r.step*(r.pane?this.inside:this.current()).page())}else if(r.kind==="hub"){if(i&&this.hub&&r.tab!==this.hub)this.leave(Zk(r.tab))}else if(r.kind==="row"&&i)this.openRow(r,t.count)}}point(t){if(this.showing==="search"){this.results.point(t.at),this.watch();return}if(t.pane){if(this.enter())this.inside.point(t.at);return}this.back(),this.list.point(t.at),this.watch()}wheel(t,e){if(this.phase!=="browse"){this.scroll(t);return}if(this.showing==="search"){this.move(t,!1);return}if(e&&!this.enter())return;if(!e)this.back();this.move(t,!1)}openRow(t,e){if(this.showing==="search"){if(t.part==="box"||e===2)this.take(e===2)}else if(t.pane){if(t.part==="box")this.inside.pick();else if(t.part==="fold")this.inside.flip();else if(e===2)this.inside.open()}else if(this.list.focusedRow()?.kind==="extra"){if(t.part==="box"||e===2)this.activate()}else if(t.part==="fold"||e===2)this.enter()}typed(){let t=this.field.value,e=this.list.focusedRow();if(this.list.setFilter(t),e?.kind==="top")this.list.select(`top ${e.name}`);if(this.inside.setFilter(t),this.follow(),t.trim()&&this.list.focusedRow()?.kind==="top"&&this.inside.matched()>0)this.enter();else if(t.trim())this.back();this.watch()}clear(){this.field.value="";let t=this.list.focusedRow();if(this.inside.clear(),this.list.setFilter(""),t?.kind==="top")this.list.select(`top ${t.name}`);this.follow(),this.watch()}redraw(){if(this.state==="active")this.screen?.request()}focus(t){if(this.state!=="submit"&&this.state!=="cancel")this.paint?.(t)}track(t){this.inflight.add(t);let e=()=>this.inflight.delete(t);return t.then(e,e),t}active(){return[...this.marketplaces.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.marketplaces.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()])}reload(){this.list.setEntries(this.entries()),this.follow(!0)}tops(){return[...this.marketplaces,...this.adds.values()].map((t)=>t.id)}marketplaceNamed(t){return[...this.marketplaces,...this.adds.values()].find((e)=>e.id===t)}focusedMarketplace(){let t=this.list.focusedRow();return t?.kind==="top"?this.marketplaceNamed(t.name):void 0}current(){return this.showing==="search"?this.results:this.list}move(t,e=!0){(this.side==="panel"?this.inside:this.current()).move(t,e),this.watch()}autoUpdate(t){let e=this.focusedMarketplace();if(e&&wt(e.source))if(t===e.auto)this.want.delete(e.source);else this.want.set(e.source,t)}activate(){let t=this.list.focusedRow();if(t?.kind!=="extra"){this.list.pick();return}let e=t.extra.found;if(e?.kind==="add")this.load(e.source,!0);else if(e?.kind==="search")this.openSearch()}toggleMarketplace(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.marketplaces,...this.adds.values()].find((e)=>sr(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),this.landing=void 0;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 marketplace at ${n.shown}`),this.landing=void 0;else if(Rt(t)||t===J)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)}focusedFound(){let t=this.current().focusedRow();return t?.kind==="extra"?t.extra.found:void 0}watch(){if(!this.live)return;let t=mi((this.showing==="search"?this.query:this.field).value);if(t&&this.wants(t))this.later("typed",KC,()=>this.load(t,!1));else this.cancel("typed")}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);let n=mi(this.field.value);if(n&&sr(n,t.source))this.field.value="",this.list.setFilter("");let r=mi(this.query.value);if(r&&sr(r,t.source))this.query.value="",this.results.setFilter("");if(this.reload(),this.list.select(`top ${t.id}`),this.landing!==void 0&&sr(this.landing,t.source))this.closeSearch();else this.results.refresh()}update(t){if(this.busy.has(t))return;this.failed.delete(t),this.busy.set(t,"Updating…"),this.track(this.io.refresh(t)).then(({marketplace:e,refreshed:n,updates:r})=>{this.busy.delete(t),this.updates=new Set(r),this.marketplaces=this.marketplaces.map((i)=>i.source===t?e:i),this.refreshed.push(n),this.reload(),this.redraw()},(e)=>{this.busy.delete(t),this.failed.set(t,`Update failed: ${e.message}`),this.redraw()})}row(t,e=!1){return{key:t.kind==="listed"?`listed ${t.listed.source}`:t.kind,...e?{idle:e}:{},found:t,text:(n,r)=>this.foundLine(t,n,r)}}heads(){let t=mi(this.field.value),e=t&&!this.known(t)?{kind:"add",source:t}:{kind:"new"};return[this.row(e,e.kind==="new"),this.row({kind:"search"})]}searchHeads(){let t=mi(this.query.value),e=t&&this.listing?.marketplaces.some((n)=>sr(n.source,t));return[this.row({kind:"back"},!0),...t&&!e&&!this.known(t)?[this.row({kind:"add",source:t})]:[]]}matches(){let t=this.query.value.trim();return(this.listing?.marketplaces??[]).filter((e)=>!t||Cp(e,t))}found(){let t=this.matches();if(t.length>0)return t.map((e)=>this.row({kind:"listed",listed:e}));return mi(this.query.value)&&!this.loading?[]:[this.row({kind:"state"})]}lit(t,e){return`${t?`${I.gutter} `:" "} ${e}`}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)?"Update failed":"")}about(t,e,n){let r=this.marketplaceNamed(t),i=e.filter((c)=>this.installed.has(c.name)).length,s=e.filter((c)=>this.picked.has(c.name)&&!this.installed.has(c.name)).length,o=e.filter((c)=>this.installed.has(c.name)&&!this.picked.has(c.name)).length,a=[...r&&n!==void 0?[`${n} of ${r.entries.filter((c)=>!c.default).length} match`]:[],...r&&n===void 0?[`${r.entries.filter((c)=>!c.default).length} available`]:[],...i>0||!r?[`${i} installed`]:[],...s>0?[`${s} to install`]:[],...o>0?[`${o} to remove`]:[],...r&&r.source!==J&&!(this.adds.has(r.source)&&wt(r.source))?[IS(r.status)]:[]];return{added:r!==void 0&&!this.removes.has(r.source),lines:[this.p.dim(r?Wp(r.source):"Not added"),this.p.dim(a.join(" · "))]}}badge(t){let e=this.marketplaceNamed(t);if(!e)return"";return[wt(e.source)&&(this.want.get(e.source)??e.auto)?`${I.auto} auto-update`:"",this.status(e)].filter(Boolean).map((r)=>` ${this.p.dim(r)}`).join("")}peeking(t){let e=this.peeked.get(t);return e?jt(e.entries.filter((n)=>!n.default).length):""}foundLine(t,e,n){let r=(u)=>bs(n,"box",`${u} `),i=(u)=>u?` ${this.p.dim(u)}`:"";if(t.kind==="new"){let u=mi(this.field.value),f=u?this.known(u):void 0,l=f?`${f.id} is already added`:"type owner/repo or a folder";return this.lit(e,`${r("+")}Add marketplace${i(l)}`)}if(t.kind==="add"){let u=this.failed.get(t.source)??this.peekFailed.get(t.source),f=this.peeked.get(t.source),l=u?` ${this.p.error(u)}`:i(this.busy.get(t.source)??(f?`${f.id} · ${this.peeking(t.source)}`:this.live?"Fetching its palettes…":"space fetches its palettes"));return this.lit(e,`${r("+")}Add ${Wp(t.source)}${l}`)}if(t.kind==="search")return this.lit(e,`${r(I.search)}Search marketplace${i("find one on GitHub")}`);if(t.kind==="back")return` ${bs(n,"box",Gu(this.p,"← Back",e))}
654
- `;if(t.kind==="state"){let[u,f]=this.stateOf();return this.lit(e,`${r(I.search)}${u}${i(f)}`)}let s=t.listed,o=this.known(s.source),a=this.failed.get(s.source),c=[`${I.star}${s.stars}`,o?this.addedNote(o):jt(s.palettes.length),this.busy.get(s.source)??""].filter(Boolean);return this.lit(e,`${r(o?I.on:I.off)}${s.id}${i(c.join(" · "))}${a?` ${this.p.error(a)}`:""}`)}stateOf(){let t=this.query.value.trim();return this.loading?["Loading the marketplace list…",""]:this.loadError?["The marketplace list did not load","space retries"]:!this.listing?["Load the marketplace list","space loads it"]:t?[`No marketplace matches "${t}"`,""]:["No marketplace yet",""]}addedNote(t){return this.adds.has(t.source)?"Will add":"Added"}changes(){return this.adds.size+this.removes.size+this.want.size}dirty(){let{picked:t,renew:e}=this.result();return this.changes()>0||e.length>0||t.size!==this.installed.size||[...t].some((n)=>!this.installed.has(n))}mark(t){let e=this.tuned.has(t.name)?` ${this.p.warn(I.on)}`:"";if(!this.updates.has(t.name)||!this.installed.has(t.name))return e;return`${e}${this.renew.has(t.name)?` ${this.p.bold(`${I.update} update`)}`:` ${this.p.dim(I.update)}`}`}toggleRenew(){let t=this.inside,e=t.focusedRow(),n=(e?t.inside(e):[]).map((i)=>i.name).filter((i)=>this.updates.has(i)&&this.installed.has(i));if(n.length===0)return;let r=n.some((i)=>!this.renew.has(i));for(let i of n)if(r)this.renew.add(i);else this.renew.delete(i)}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:gc(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(ql,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(`
655
- `)),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))}}marketplaceChanges(){let t=[];for(let e of this.adds.values()){let n=e.source!==J&&(this.want.get(e.source)??e.auto)?"updates on its own":"";t.push(`+ ${e.id} ${this.p.dim([e.source===J?"The official marketplace":e.shown,jt(e.entries.filter((r)=>!r.default).length),n].filter(Boolean).join(" · "))}`)}for(let e of this.removes){let n=this.marketplaces.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.p.dim([n?.shown??st(e),r.length>0?`its ${jt(r.length)} installed keep working`:""].filter(Boolean).join(" · "))}`)}for(let[e,n]of this.want){let r=this.marketplaces.find((i)=>i.source===e);if(r&&!this.removes.has(e))t.push(`${I.auto} ${r.id} ${this.p.dim(n?"updates on its own from now":"stops updating on its own")}`)}return t}reviewLines(){let t=this.marketplaceChanges(),{names:e,dropped:n}=this.pending(),r=new Set(this.result().renew),i=this.entries().filter((c)=>r.has(c.name)),s=Math.max(0,...[...e,...n,...i].map((c)=>c.name.length)),o=(c,u)=>` ${c} ${u.name.padEnd(s)} ${this.p.dim(u.catalog??"")}`,a=[e.length>0?`${e.length} to install`:"",n.length>0?`${n.length} to remove`:"",i.length>0?`${i.length} to update`:""].filter(Boolean);return[...t.length>0?[` ${this.p.bold("Marketplaces")} ${this.p.dim(`(${t.length})`)}`,...t.map((c)=>` ${c}`),""]:[],...a.length>0?[` ${this.p.bold("Palettes")} ${this.p.dim(`(${a.join(" · ")})`)}`,...e.map((c)=>o("+",c)),...n.map((c)=>o("-",c)),...i.map((c)=>o(I.update,c))]:[]]}summary(){let{names:t,dropped:e}=this.pending(),n=this.adds.size;return[n>0?`${n} marketplace${n===1?"":"s"} added`:"",this.removes.size>0?`${this.removes.size} removed`:"",t.length>0?`${t.length} installed`:"",e.length>0?`${e.length} removed`:"",this.result().renew.length>0?`${this.result().renew.length} updated`:""].filter(Boolean).join(" · ")}progressLines(){let t=this.log.map((e)=>` ${e}`);if(this.phase==="applying"){let e=ur[this.beat%ur.length];t.push(` ${this.p.dim(`${e} ${this.working||"Working…"}`)}`)}else if(this.stopped)t.push("",...vt(this.stopped.message,Math.max(20,this.columns()-6)).map((e,n)=>` ${n===0?this.p.error(I.miss):" "} ${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.p.bold("Review changes")}`:this.phase==="applying"?this.p.bold("Applying changes"):this.stopped?`${this.p.error(I.miss)} ${this.p.bold("Stopped")}`:`${this.p.bold(`${I.ok} Applied`)} ${this.p.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),f=i.length-c-u.length,l=[c>0?` ${this.more(-1,`↑ ${c} more`)}`:"",...u];while(l.length<o+1)l.push("");l.push(f>0?` ${this.more(1,`↓ ${f} 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?[tt(Jh(this.hub,this.color),n,!1)]:[],tt(` ${s}`,n,!1),...l.map((m)=>tt(m,n,!1)),` ${this.keyBar(h,n-1)}`].slice(0,e).join(`
656
- `)}keyBar(t,e){let n=`${Ye(this.p,t.badge)}${this.color?" ":" "}`,r=([a,c])=>Yk(this.p,a,c),{note:i,keys:s,right:o}=t;for(;;){let a=`${n}${[t.lead??"",i?this.p.dim(i):"",...s.map(r)].filter(Boolean).join(" ")}`,c=o?r(o):"";if(G(a)+(o?3+G(c):0)<=e)return o?At(a,c,e):tt(a,e,!1);if(i)i=void 0;else if(s.length>2||!o&&s.length>1){let u=s.length-2;s=s.filter((f,l)=>l!==u)}else if(o)o=void 0;else return tt(a,e,!1)}}more(t,e,n){return this.p.dim(dn({kind:"page",step:t,...n?{pane:n}:{}},e))}counts(){if(this.showing==="search"){let n=[...this.loading?["Loading…"]:[],...this.listing?[`${this.matches().length} found`]:[],...this.listing?.offline?[`offline, from ${Uo(this.listing.at)}`]:[]];return n.length>0?n.join(" · "):"on GitHub"}let t=[...this.busy.values()].includes("Updating…")?"Updating… · ":"",e=this.list;return`${t}${e.matched()}/${e.total()} · ${e.pickedCount()} picked`}searchText(){let t=(this.showing==="search"?this.query:this.field).value;if(t)return`${t}_`;if(this.showing==="search")return this.p.dim("Search… a marketplace, a palette, or type owner/repo or a folder");let e=this.hint.text();return this.p.dim(`Search…${e?` e.g. ${e}`:""}`)}heading(){let t=this.showing==="search"?"Search marketplace":"Browse";return`${this.p.bold(t)} ${this.p.dim(`(${this.counts()})`)}`}searchBox(t){let e=(r,i)=>this.p.dim(`${r}${"─".repeat(t-2)}${i}`),n=this.p.dim("│");return[e("╭","╮"),`${n} ${tt(`${this.p.dim(I.search)} ${this.searchText()}`,t-4)} ${n}`,e("╰","╯")]}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",i=e&&n&&this.updates.has(t.name)?this.renew.has(t.name)?" · Will update":" · Update ready":"";return`${r}${i}${this.startup===t.name?" · Default":""}`}detail(t){let e=this.current().focusedRow();if(e?.kind==="extra")return e.extra.found?this.foundDetail(e.extra.found,t):RS;if(e?.kind!=="top")return RS;let n=this.marketplaceNamed(e.name);if(n)return this.marketplaceDetail(n,t);let r="In no marketplace you added — its installed palettes stay";return{title:this.p.bold(e.name),lines:vt(r,t),brief:r}}foot(t){let e=this.inside.focusedRow();if(e?.kind==="catalog"){let c=this.inside.inside(e),u=c.filter((f)=>this.installed.has(f.name)).length;return[`${this.p.bold(e.name)}${e.native?` ${this.p.dim(e.native)}`:""}`,this.p.dim(`${jt(c.length)} · ${u} installed`),""]}if(e?.kind!=="palette")return["","",""];let n=e.entry,r=Ua(n),i=`Gate ${Ie.length-r.length}/${Ie.length}`,s=n.pictures?.length??0,o=[...s>0?[`${s} picture${s===1?"":"s"}`]:[],...n.base?[`Base ${n.base}`]:[]].join(" · "),a=r.length>1?` · +${r.length-1}`:"";return[`${this.color?this.p.bold(`${lr(n.cursor)}${n.name}${kt}`):n.name} ${this.p.dim(this.paletteState(n))}`,r[0]===void 0?this.p.dim(`${i} · passes`):`${i} · ${this.p.bold(I.miss)} ${r[0]}${a}`,tt(this.p.dim(o),t)]}marketplaceDetail(t,e){let r=t.entries.filter((a)=>!a.default).filter((a)=>this.installed.has(a.name)).map((a)=>a.name),i=wt(t.source)?`Auto-update ${this.want.get(t.source)??t.auto?"on":"off"}`:IS(t.status),s=this.failed.get(t.source),o=this.adds.has(t.source)?["Will add"]:this.removes.has(t.source)?[r.length>0?`Will remove — ${r.join(", ")} stay${r.length===1?"s":""} installed`:"Will remove"]:this.want.has(t.source)?[`Auto-update turns ${this.want.get(t.source)?"on":"off"}`]:[];return{title:this.p.bold(t.id),lines:[...t.description?[...vt(t.description,e).map((a)=>this.p.dim(a)),""]:[],wt(t.source)?`${i} ${this.p.dim("⇧←→")}`:i,...s?vt(s,e).map((a)=>this.p.error(a)):[],...o.length>0?["",...o.flatMap((a)=>vt(a,e))]:[]],brief:[i,...o].join(" · ")}}foundDetail(t,e){if(t.kind==="new")return{title:this.p.bold("Add marketplace"),lines:[...vt("Type owner/repo, owner/repo#ref or a folder into the search, and space adds it",e),"",...vt("Or find one on GitHub with Search marketplace",e)],brief:"Type owner/repo, owner/repo#ref or a folder into the search, and space adds it"};if(t.kind==="search"){let s=`The marketplaces anyone publishes on GitHub with the ${Di} topic, listed every half hour`;return{title:this.p.bold("Search marketplace"),lines:[...vt(s,e),"",...vt("enter opens the search",e)],brief:"enter searches the marketplaces on GitHub"}}if(t.kind==="back")return{title:this.p.bold("Back"),lines:["Back to your marketplaces"],brief:"enter goes back"};if(t.kind==="add"){let s=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.p.bold(Wp(t.source)),lines:["Not added",...this.peekLines(t.source,e),"",...vt(s,e)],brief:[this.peeking(t.source),s].filter(Boolean).join(" · ")}}if(t.kind==="state"){let[s,o]=this.stateOf(),a=`Repositories with the ${Di} topic, read every half hour into one list`;return{title:this.p.bold("Marketplaces"),lines:[...vt(a,e),"",...vt([s,o].filter(Boolean).join(" · "),e),...this.loadError?vt(this.loadError,e).map((c)=>this.p.error(c)):[],"",...vt("Type owner/repo or a folder to add one",e)],brief:[s,o].filter(Boolean).join(" · ")}}let n=t.listed,r=this.known(n.source),i=r?this.addedNote(r):this.busy.get(n.source)??this.failed.get(n.source)??"space adds it, enter adds it and goes back";return{title:this.p.bold(n.id),lines:[this.p.dim(n.source),...vt(n.about,e).map((s)=>this.p.dim(s)),this.p.dim([`★ ${n.stars}`,...n.updated?[`updated ${n.updated}`]:[]].join(" · ")),"",...vt(i,e),"",...this.paletteLines(n,e)],brief:[jt(n.palettes.length),i].join(" · ")}}paletteLines(t,e){let n=Math.min(Math.max(...t.palettes.map((i)=>G(i.name))),Math.max(8,e-16)),r;return t.palettes.flatMap((i)=>{let s=i.catalog!==r&&i.catalog?[this.p.dim(i.catalog)]:[];r=i.catalog;let o=this.color?` ${ju(so(i))}`:"";return[...s,` ${tt(i.name,n)}${o}`]})}peekLines(t,e){let n=this.peeked.get(t);if(!n)return[];let r=n.entries.filter((s)=>!s.default),i=`${r.slice(0,PS).map((s)=>te(s.name)).join(", ")}${r.length>PS?", …":""}`;return["",n.id,...n.description?vt(n.description,e):[],jt(r.length),...vt(i,e).map((s)=>this.p.dim(s))]}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"]};if(this.showing==="search")return{badge:"SEARCH",keys:[...this.searchKeys(),...this.query.value?[["bksp","edit"]]:[],["?","keys"]],right:this.query.value?["esc","clear search"]:["esc","back"]};let t=this.field.value,e=["enter",this.dirty()?"apply":"close"],n=[...t?[["bksp","edit"]]:[],["?","keys"]];return{badge:t?"BROWSE (FILTER)":"BROWSE",keys:[...this.side==="panel"?this.panelKeys(e):this.cardKeys(e),...n],right:t?["esc","clear filter"]:this.side==="panel"?["esc","back"]:["esc","cancel"]}}panelKeys(t){let e=this.inside,n=e.focusedRow();if(n?.kind==="catalog"&&e.foldable())return[n.expanded?["←","close"]:["→","open"],["space","pick"]];let r=n?.kind==="palette"&&this.updates.has(n.entry.name)&&this.installed.has(n.entry.name);return[["space","pick"],...r?[["ctrl+r",this.renew.has(n.entry.name)?"keep":"update"]]:[],t]}searchKeys(){let t=this.focusedFound();if(t?.kind==="back")return[["enter","back"]];if(t?.kind==="state")return this.loading?[]:[["space","load"]];let e=t?.kind==="add"?t.source:t?.kind==="listed"?t.listed.source:void 0;if(e===void 0)return[];let n=this.known(e);if(!n)return[["space","add"],["enter","add and go back"]];return[...this.adds.has(n.source)?[["space","undo"]]:[],["enter","go to it"]]}cardKeys(t){let e=this.list.focusedRow();if(e?.kind==="extra"){let o=e.extra.found;if(o?.kind==="search")return[["enter","open"]];return o?.kind==="add"?[["space","add"],t]:[t]}if(e?.kind!=="top")return[t];let n=this.inside.size()>0?[["→","open"]]:[],r=this.focusedMarketplace();if(!r)return[...n,["space","pick"]];let i=wt(r.source),s=this.adds.has(r.source)||this.removes.has(r.source);return[...n,["space","pick"],...i?[["⇧←→","auto-update"]]:[],...i&&!this.adds.has(r.source)?[["ctrl+r","update"]]:[],["del",s?"undo":"remove"]]}columns(){return(this.output??process.stdout).columns??100}rows(){return(this.output??process.stdout).rows??24}fitItems(t){let e=Math.max(ql,this.rows()-t);this.maxItems=e,this.list.maxItems=e,this.results.maxItems=e}view(){let t=this.draw().split(`
657
- `);return Array.from({length:this.rows()},(e,n)=>t[n]??"")}small(t,e,n){return`Needs ${xS}×${n} — now ${t}×${e}
658
- ${this.p.dim("esc cancels")}`}draw(){let t=this.columns(),e=this.rows();if(t<xS||e<OS)return this.small(t,e,OS);if(this.phase!=="browse")return this.frame(t,e);this.follow();let n=t>=UC,r=t-1,i=e>=WC?[` ${this.heading()}`,...this.searchBox(t-3).map((d)=>` ${d}`)]:[At(` ${this.p.dim(I.search)} ${this.searchText()}`,this.p.dim(this.counts()),r)],s=i.length+3+(n?0:1)+(this.hub?1:0);if(e<s+ql)return this.small(t,e,s+ql);this.fitItems(s);let o=this.current().window(),a=(d)=>wo(d).flatMap((h)=>h.sequence?[]:[h.text]).join("").trimEnd(),c=Math.max(0,...o.lines.map((d)=>G(a(d))+3)),u=n?Math.min(GC,r-BC-1,Math.max(_C,c)):r;this.split=n?u+1:0;let f=!n&&this.side==="panel"?this.panel(r-1,this.maxItems+3).map((d)=>` ${d}`):this.cards(o,n,u,r),l=[...this.hub?[tt(Jh(this.hub,this.color),r,!1)]:[],...i.map((d)=>tt(d,r,!1)),...f,` ${this.keyBar(this.footer(),r-1)}`];return(this.help?this.helpBox(l,t,e,l.length-f.length-1):l).join(`
659
- `)}cards({lines:t,above:e,below:n},r,i,s){let o=t.map((u)=>` ${u}`);while(o.length<this.maxItems)o.push("");let a=[e>0?` ${this.more(-1,`↑ ${e} more`)}`:"",...o,n>0?` ${this.more(1,`↓ ${n} more`)}`:""];if(!r)return[...a.map((u)=>tt(u,i,!1)),tt(` ${this.p.dim(this.detail(i-2).brief)}`,i,!1)];let c=this.panel(s-i-1,a.length);return a.map((u,f)=>`${tt(u,i)} ${c[f]??""}`)}panel(t,e){let n=this.side==="panel",r=(b)=>n?this.p.accent(b):this.p.dim(b),i=t-4,s=(b)=>`${r("│")} ${tt(b,i)} ${r("│")}`,o=this.detail(i),a=n?this.p.accent(o.title):o.title,c=e-2;if(this.current().focusedRow()?.kind!=="top"){let b=o.lines.length>c?[...o.lines.slice(0,c-1),this.p.dim("…")]:o.lines.slice(0);while(b.length<c)b.push("");return[this.edge(t,"top",a,"",n),...b.map(s),this.edge(t,"bottom","","",n)]}let u=n?this.foot(i):[],f=o.lines.slice(0,Math.max(0,c-2-(u.length>0?u.length+1:0)));this.inside.maxItems=Math.max(1,c-f.length-1-(u.length>0?u.length+1:0));let{lines:l,above:d,below:h}=this.inside.window(),m=this.inside.size()>0?l:[this.p.dim(" No palettes yet")];while(m.length<this.inside.maxItems)m.push("");let g=h>0?this.more(1,`↓ ${h} more`,"panel"):"";return[this.edge(t,"top",a,"",n),...f.map(s),s(d>0?this.more(-1,`↑ ${d} more`,"panel"):""),...m.map(s),...u.length>0?[this.edge(t,"mid","",g,n),...u.map(s)]:[],this.edge(t,"bottom","",u.length>0?"":g,n)]}edge(t,e,n,r,i){let s=(l)=>i?this.p.accent(l):this.p.dim(l),[o="",a=""]=[...Gt(2,e)],c=n?` ${tt(n,t-8,!1)} `:"",u=r?` ${r} `:"",f=Math.max(0,t-3-G(c)-G(u)-(r?1:0));return`${s(`${o}─`)}${c}${s("─".repeat(f))}${u}${s(`${r?"─":""}${a}`)}`}helpRows(){if(this.showing==="search")return[["Move","↑↓ home end pgup pgdn"],["Filter","Any text · bksp · ctrl-u clears"],["Add","space adds it · again to undo"],["","enter adds it and goes back to its card"],["Reload","ctrl+r the list, which GitHub fills every half hour"],["Back","← esc · ← Back"],...this.hub?[["Screens","tab · shift+tab"]]:[],["Close","? esc"]];return[["Move","↑↓ home end pgup pgdn"],["Open","→ enter · a marketplace into the panel, a catalog"],["Back","← esc · from the panel to the marketplaces"],["Pick","space · a palette, a catalog, a marketplace"],["Filter","Any text · bksp · ctrl-u clears"],["Marketplace","⇧←→ auto-update · ctrl+r updates it"],["","del removes it · again to undo"],["Add","owner/repo or a folder typed in · space adds it"],["Search","enter on Search marketplace · finds one on GitHub"],["Update","ctrl+r on a palette marked ↑"],["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.max(...i.map(([l])=>l.length))+3,o=Math.min(e-2,6+s+Math.max(...i.map(([,l])=>G(l)))),a=Math.floor((e-o)/2),c=`│${" ".repeat(o-2)}│`,u=[`╭─ Help ${"─".repeat(o-9)}╮`,c,...i.map(([l,d])=>`│${tt(` ${this.p.bold(l.padEnd(s))}${d}`,o-4)} │`),c,`╰${"─".repeat(o-2)}╯`],f=Math.max(0,Math.min(Math.max(r,Math.floor((n-u.length)/2)),n-1-u.length));return t.map((l,d)=>{let h=u[d-f];return h===void 0?l:`${Wk(l,a)}${h}`})}}import{existsSync as f6}from"node:fs";import{existsSync as zc,mkdirSync as Jj,readFileSync as Zg}from"node:fs";import{dirname as Yj}from"node:path";class pe extends Error{}import{closeSync as d5,mkdtempSync as h5,openSync as m5,readSync as p5,rmSync as VE}from"node:fs";import{homedir as g5,tmpdir as b5}from"node:os";import{join as ZE}from"node:path";import{readFileSync as zC}from"node:fs";var Et={pitch:25,cols:22,rows:9,height:13},$s={cols:25,rows:21},Me={cols:10,rows:3,pitch:12,top:4},Ee=Me.top+Me.rows+1,qC=1073741824,Zp=2147483648,DC=-1073741826,JC=1600,YC=56,VC=4,AS=20,ZC=50,NS=[["space","unfolds a set of ×N"],["o","opens the artwork 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 Xp(t){return Math.max(0,Math.floor((t-1)/Me.pitch))}function kr(t,e){let n=e-Ee-2;return{perRow:Math.max(1,Math.floor((t-1)/Et.pitch)),rowsVis:Math.max(1,Math.floor(n/Et.height)),height:n}}function Vl(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=zC(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 GS(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 Qp(t){return`\x1B_Ga=d,d=i,i=${t},p=${t},q=2\x1B\\`}function Sc(t){return`\x1B_Ga=d,d=I,i=${t},q=2\x1B\\`}var Nt=$t("bold"),W=$t("dim"),kc=$t("ok"),Un=$t("warn"),wc=lr,Yl=Gh,qp=!1;function Zl(t){return qp=!0,t.beat}function Vo(t){return ur[Zl(t)%ur.length]}function mt(t){return G(t)}function Dp(t,e){if(G(t)<=e)return t;let n="";for(let r of t){if(G(n+r)>e)break;n+=r}return n}function pi(t){return Zi(t)}function tg(t){return`${$t("reverse")}${Zi(t)}`}function gi(t,e,n,r){return n?[[`${I.link} `,r,void 0,{kind:"link",url:n}],[t,e,n]]:[[t,e]]}function zp(t){let e=zh(t);return e?{kind:"key",key:e}:void 0}function Jp(t){return t.reduce((e,[n])=>e+mt(n),0)}function XC(t,e){let n=[],r=e;for(let[i,s,o,a]of t){let c=mt(i);if(c<=r){n.push([i,s,o,a]),r-=c;continue}n.push([`${Dp(i,r)}…`,s,o,a]);break}return n}class Jl{parts=[];cols;constructor(t){this.cols=t}put(t,e,n="",r,i){let s=e.replace(/\p{Cc}/gu,"");return this.parts.push({col:t,text:s,sgr:n,...r?{link:r}:{},...i?{spot:i}:{}}),t+mt(s)}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?mt(Dp(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+mt(r),0),e)}center(t,e){this.run(Math.floor((t-e.reduce((n,[r])=>n+mt(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=Dp(n,this.cols-e);t+=`\x1B[${e+1}G${r}${_u(o,i)}${r?ke:""}`}return t}}function QC(t){return t.replace(/_\([^)]*\)?$/,"")}function BS(t){return[`${t.reduced?"↓":""}${t.width}×${t.height}`,Math.max(t.width,t.height)<JC?Un:W]}function yc(t,e,n){let r=[...n.keys??[]],i=n.lead,s=n.right,o=()=>{let u=[...i?[Jp(i)]:[],...r.map(([l,d])=>mt(l)+1+mt(d))];return(n.badge?mt(n.badge)+4:0)+u.reduce((l,d)=>l+d,0)+3*Math.max(0,u.length-1)+(s?3+mt(s[0])+1+mt(s[1]):0)};while(o()>e)if(r.length>2)r.splice(-2,1);else if(s)s=void 0;else if(r.length>1)r.splice(-2,1);else break;if(i&&o()>e)i=XC(i,Math.max(0,Jp(i)-(o()-e)-1));let a=0;if(n.badge)a=t.put(0,` ${n.badge} `,$t("pill"))+2;if([...i?[i]:[],...r.map(([u,f])=>[[u,Nt,void 0,zp(u)],[` ${f}`,W,void 0,zp(u)]])].forEach((u,f)=>{a=t.run(a+(f?3:0),u)}),s){let u=zp(s[0].split(" ")[0]??"");t.right(e,[[s[0],Nt,void 0,u],[` ${s[1]}`,W,void 0,u]])}}function t8(t,e){if(t==="d")return W;if(t==="b")return Nt;if(t==="s")return Yl(e.colors.selection);if(t==="c")return Yl(e.colors.cursor);let n=/^([BK]?)(\d+)$/.exec(t);if(!n)return"";let r=Number(n[2]);if(n[1]==="K")return`${Zi(0)}${_k(r)}`;return`${n[1]==="B"?Nt:""}${Zi(r)}`}function e8(t,e,n,r,i){let s=Yt.indexOf(Qi(r.scene)),o=Yt.flatMap((c,u)=>[...u?[[" ",""]]:[],[c.name,u===s?Nt+i:W,void 0,{kind:"scene",scene:u}]]),a=o.reduce((c,[u])=>c+mt(u),0)<=n;t?.run(e,a?o:[[Qi(r.scene).name,Nt+i],[` ${s+1}/${Yt.length}`,W]])}function n8(t,e,n,r,i,s,o){let{ansi:a,cursor:c}=s.colors;e8(t[e-2],n,r,s,o);let u=r<Ey?3:4;if(r>=56)u=Math.min(7,Math.floor((r+1)/8)-1);let f=n;for(let d=0;d<8;d++)f=(t[e]?.put(f,"▀".repeat(u),wc(a[d]??c)+Yl(a[d+8]??c))??f)+1;let l=e+2;for(let d of Qi(s.scene).lines){let h=ko(d,r);if(!h)continue;if(l>i)return;t[l]?.run(n,h.map(([m,g])=>[m,t8(g,s)])),l++}}function r8(t,e,n){let r=[[]];for(let o of t){let a=r[r.length-1];if(a.length===0||mt([...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&&mt([...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 TS(t){return t.replace(/^https?:\/\/(?:www\.)?/,"")}function i8(t,e,n){return t.flatMap((r,i)=>[...i>0?[[" ",""]]:[],[r,""],...(e[r]??[]).flatMap((s)=>[[" ",""],...gi(s.kind,"",s.url,n)])])}function s8(t,e,n,r,i){let s=r.info,o=s?.artists??[],a=pi(r.tiles[r.focus]?.siteAnsi??r.siteAnsi);[["Post",s?.page?gi(TS(s.page),"",s.page,a):[["—",W]]],["Source",s?.source?gi(TS(s.source),"",s.link,i):[["—",W]]],["Artist",o.length>0?i8(o,s?.profiles??{},i):[["—",W]]]].forEach(([u,f],l)=>{t[e+l]?.put(n,u,W),t[e+l]?.run(n+12,f)})}function o8(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,f=Math.max(12,r-12),l=[`${a.width}×${a.height}${o.ext?` ${o.ext.toUpperCase()}`:""}`,...c?[Al(c.bytes)]:[]].join(" · "),d=[o.rating??"—",a.score>0?`★${a.score}`:"",o.posted??""].filter(Boolean).join(" · "),h=(b,w)=>b.length>0?r8(b,f,w).map((k)=>[[k,""]]):[[["—",W]]],m=[["Characters",h(o.characters,2)],["Series",h(o.series,1)],["Tags",h(o.tags,3)],["Rating",[[[d,d==="—"?W:""]]]],["File",[[[l,""],...c?[[" ",""]]:[],...c?US(c):[]]]],["Uploader",[[o.uploader?[o.uploader,""]:["—",W]]]]],g=e;for(let[b,w]of m){if(g+w.length-1>i)return;t[g]?.put(n,b,W);for(let k of w)t[g]?.run(u,k),g++}}var a8=["Size","Position","Opacity"],c8=[0,3,6];function u8(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 l8(t){return t.toFixed(2)}function f8(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,Nt+s],[" Background",W],...a?[[" · ",W],...gi(`${a.site} ${a.id}`,W,a.page||void 0,pi(a.siteAnsi))]:[]]);let c=Math.max(8,r-n-21),u=20,f=Math.max(100,o.fill);for(let[l,d]of a8.entries()){let h=e+c8[l],m=o.field===l,g=m?Nt:W;if(m)t[h]?.put(n,"▶",s,void 0,{kind:"field",field:l});t[h]?.put(n+2,d,g,void 0,{kind:"field",field:l});let b;if(l===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?Nt+s:W)}b=Dt[i.tune.at-1]??"center"}else{let w;if(l===0){let{size:k}=i.tune;w=k==="fill"?c-1:Math.floor((k-u)*(c-1)/(f-u+1)),b=k==="fill"?"fill":`${k}%`}else w=Math.floor(Math.round(i.tune.opacity*100)*(c-1)/100),b=l8(i.tune.opacity);w=Math.max(0,Math.min(c-1,w)),t[h]?.run(n+12,[["━".repeat(w),s],["●",Nt],["─".repeat(c-1-w),W]]),t[h]?.mark(n+12,c,{kind:"track",field:l})}if(t[h]?.right(r-2,[[b,g]]),u8(i,l))t[h]?.put(r-1,"↺",m?Nt+s:W)}}function d8(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 Yp(t,e=t.site,n=t.siteAnsi){return[` ${e} `,tg(n)]}function $c(t){return`${Z[Math.floor(t/Br)]?.name??"local"} ${t%Br}`}function bc(t,e,n){let r=Z[Math.floor(e/Br)],i=$c(e),s=t.indexOf(i);if(!r||s===-1)return[[t,n]];return[[t.slice(0,s),n],...gi(i,n,r.pageUrl(e%Br),pi(r.ansi)),[t.slice(s+i.length),n]].filter(([a])=>a!=="")}function h8(t,e,n){let r=[{name:"all",moved:!1},...Z].flatMap((s,o)=>{let a=`${s.name}${s.moved?"*":""}`,[c,u]=s.name===n.site?Yp(n,a):[` ${a} `,W],f=[c,u,void 0,{kind:"site",tab:o}];return o?[[" ",""],f]:[f]}),i=r.reduce((s,[o])=>s+mt(o),0)<=e;t.run(0,i?r:[Yp(n)])}function m8(t,e,n,r){if(n.chips.length===0)return;let i=[["tags ",W]],s=mt("tags "),o=n.chips.length;for(let[a,c]of n.chips.entries()){let u=` ${a+1} ${c.name} `;if(s+mt(u)+1>e-2)break;i.push([u,c.on?`${$t("reverse")}${r}`:W,void 0,{kind:"chip",index:a}],[" ",""]),s+=mt(u)+1,o--}if(o>0)i.push([`+${o}`,W]);t.run(0,i)}function p8(t,e,n,r,i){t[Ee-1]?.put(0,"─".repeat(n-1),W);let s=t[Me.top-1],o=Xp(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 f=c*Me.pitch,l=u.up?Nt:"";if(s.run(f+1,u.page?gi(String(u.id),l,u.page,pi(u.ansi)):[["● ",pi(u.ansi)],[String(u.id),l]]),u.up)for(let d=0;d<Me.rows;d++)t[Me.top+d]?.put(f,"▌",i);if(u.thumb)e.push({id:qC+c,path:u.thumb,row:Me.top,col:f+1,cols:Me.cols,rows:Me.rows,z:-1})}if(a<r.held.length)s.put(a*Me.pitch+1,`+${r.held.length-a}`,W)}function g8(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"}`,W);return}let i=t.run(0,[["⌕ ",r,void 0,{kind:"query"}],[n.tag||"Nothing yet — / searches, ctrl+v pastes a picture",n.tag?"":W,void 0,{kind:"query"}]]),s=Ti.filter((c)=>!n.block.includes(c)),o=Z.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(" ")}`,W),n.total>0||!n.searching){let c=[[`${n.tiles.length}/${n.checked}`,""]];if(n.checked<n.total)c.push([` of ${n.total}`,W]);t.right(e,c)}}function US(t){if(t.cut==="on")return[[`Cut out · ${t.clear}% transparent`,kc]];if(t.cut==="off")return[["Opaque · x cuts out",Un]];if(t.cut==="failed")return[["Opaque · no cut-out",Un]];return[t.clear>0?[`${t.clear}% transparent`,kc]:["Opaque",Un]]}function HS(t){return t.site==="all"?"any site":t.site}function Vp(t,e){if(t.installing!==void 0)return bc(`${Vo(t)} Installing ${t.palette} ← ${$c(t.installing)}`,t.installing,Un);if(t.hint)return[[t.hint,kc]];if(t.error)return[[t.error,Un]];if(t.waiting!==void 0)return[[`${t.slow??t.site} asked to slow down · ${t.waiting}s`,Un]];if(t.fetching){let{id:n,got:r,size:i}=t.fetching;return bc(`${Vo(t)} Fetching ${$c(n)} · ${Nl(r,i)}`,n,Un)}if(t.cutting!==void 0)return bc(`${Vo(t)} Cutting out ${$c(t.cutting)}`,t.cutting,Un);if(t.preparing!==void 0)return bc(`${Vo(t)} Preparing ${$c(t.preparing)}`,t.preparing,Un);if(e)return[e];if(t.saved)return bc(t.saved.text,t.saved.key,kc);if(t.note)return[[t.note,W]];return}function WS(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 KS(t,e){return t.ranking?`${e}${t.ranking.done}/${t.ranking.total}`:""}function b8(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,f=Math.max(6,Math.round(n*0.22)),l=Zl(r)%(AS*2)/AS,d=Math.round((n-f)*(0.5-0.5*Math.cos(Math.PI*(l<1?l:2-l)))),h=Tt(s,o,i),m=Tt(s,Tt(a,s,0.15),i),g=Array.from({length:n},(w,k)=>{let v=(u>=0?k<u:k>=d&&k<d+f)?h:m;return k===0||k===n-1?Tt(v,s,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),Yl(g[b])),b=w}function w8(t,e,n,r,i){let{background:s,foreground:o}=i.colors,a=i.loaderFrom===void 0?0:Math.min(1,(Zl(i)-i.loaderFrom)/VC),c=e+(n>=5?Math.floor((n-5)/2):0);t[c]?.center(r,[[WS(i),Nt+wc(Tt(s,o,a))],[KS(i," "),wc(Tt(s,Tt(o,s,0.45),a))]]);let u=Math.min(YC,r-8);if(b8(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:f,arrived:l},d)=>[...d?[[" · ",wc(Tt(s,o,0.25*a))]]:[],[f,wc(Tt(s,l?Tt(o,s,0.2):o,l?a:0.32*a))]]))}function $8(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[Ee+c]?.put(e-1,u?"┃":"│",u?s:W)}}function k8(t,e,n){if(e)return[`${Vo(t)} ${WS(t)}${KS(t," · ")}`,W];let r=n.filter((s)=>!s.missing),i=r.filter((s)=>s.thumb).length;return i<r.length?[`${Vo(t)} Loading thumbnails · ${i}/${r.length}`,W]:void 0}function y8(t,e,n,r,i,s,o){let{perRow:a,rowsVis:c,height:u}=kr(r,i);g8(t[0],r,s,o),h8(t[1],r,s),m8(t[2],r,s,o),p8(t,e,r,s,o);let f=t.map((C,P)=>P>=Ee&&P<Ee+u?C:void 0),l=Math.floor(s.scroll/Et.height),d=Math.floor((s.scroll+u-1)/Et.height),h=[];for(let C=l;C<=d;C++){let P=Ee+C*Et.height-s.scroll;for(let _=0;_<a;_++){let K=C*a+_,B=_*Et.pitch,F=s.tiles[K];if(!F)continue;h.push(F);let gt=Math.max(P,Ee),Zt=Math.min(P+Et.height,Ee+u);if(Zt>gt)n.push({row:gt,col:B,width:Et.pitch-1,height:Zt-gt,target:{kind:"tile",index:K}});let at=K===s.focus;if(at)d8(f,P,B,Et.height,Et.pitch-1,o);let Rr=P+1,We=Math.max(Rr,Ee),kn=Math.min(Rr+Et.rows,Ee+u);if(F.thumb&&kn>We)e.push({id:F.key,path:F.thumb,row:We,col:B+1,cols:Et.cols,rows:kn-We,...kn-We<Et.rows?{crop:We-Rr}:{},z:-1});let Ns=[...s.installed.includes(F.key)?[["✓ ",kc]]:[],...F.page||s.site!=="all"?gi(String(F.id),at?Nt:"",F.page||void 0,pi(F.siteAnsi)):[["● ",pi(F.siteAnsi)],[String(F.id),at?Nt:""]],[" ",""],BS(F)],Zc=Et.cols-(F.mates.length>0?1:0);if(f[P+10]?.run(B+1,Jp(Ns)>Zc?Ns.map(([Vf,Zf,Xf])=>[Vf.replace(/^(\S) $/,"$1"),Zf,Xf]):Ns),F.mates.length>0)f[P+10]?.put(B+Et.cols,"≈",o);f[P+11]?.put(B+1,F.artist?QC(F.artist).slice(0,Et.cols-8):"—",W);let yi=[];if(F.score>0)yi.push([`★${F.score}`,W]);if(F.variants>1)yi.push([` ×${F.variants}`,o]);if(yi.length>0)f[P+11]?.right(B+Et.cols+1,yi)}}let m=Math.ceil(s.tiles.length/a)*Et.height;$8(t,r,s,u,m,o);let g=Math.max(Ee,Ee+m-s.scroll),b=Ee+u-g,w=s.searching&&b>=2;if(w)w8(f,g,b,r-1,s);let k=s.searching&&s.tiles.length===0;if(k&&!s.error){let[C,P]=NS[Math.floor(Zl(s)/ZC)%NS.length];t[i-2]?.run(0,[["Tip ",W],[C,Nt],[` ${P}`,W]])}let v=s.top*a,S=s.tiles.length-(s.top+c)*a,x=[...v>0?[`↑ ${v} above`]:[],...S>0?[`↓ ${S} more`]:[]];if(x.length>0)t[i-2]?.put(0,x.join(" "),W);if(!s.searching&&s.tiles.length===0&&!s.error&&s.tag)t[Ee+1]?.put(0,s.preset==="cutouts"?`No transparent cutouts of ${s.tag} on ${HS(s)} — c searches every post, tab tries ${s.nextSite}`:`No posts of ${s.tag} on ${HS(s)} — tab tries ${s.nextSite}`,W);let M=k8(s,w,h),N=Vp(s,M);return yc(t[i-1],r,{badge:"IMAGE SEARCH",lead:N,keys:k&&N?.[0]===M?[]:[["←↑↓→","move"],["enter","try on"],["tab","site"],["ctrl+v","picture"],["s","settings"],["/","search"],["?","keys"]],right:["esc","back"]}),w}function v8(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=[Yp(i,o.site,o.siteAnsi),[" ",""],...gi(String(o.id),Nt,o.page||void 0,pi(o.siteAnsi)),[" ",""],BS(o)];if(o.score>0)c.push([` · ★${o.score}`,W]);if(a)c.push([` · ${Al(a.bytes)}`,W]);if(a){if(c.push([" ",""],...US(a)),i.coloring==="original")c.push([" · own colors",W])}if(t[0]?.run(0,c),o.mates.length>0)t[0]?.right(n,[["≈ ",s],[o.mates.join(" "),W]]);if(s8(t,1,2,i,s),i.tuning)f8(t,8,2,2+Math.min(n-4,60),i,s);else if(i.details)o8(t,5,2,Math.min(n-4,Math.max(48,Math.floor(n*0.55))),r-2,i);else n8(t,7,2,n-4,r-2,i,s);if(i.shown)e.push({id:Zp+i.shown.id,path:i.shown.path,row:0,col:0,cols:n,rows:r,z:DC});if(i.tuning){yc(t[r-1],n,{badge:"IMAGE EDIT",lead:Vp(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=Vp(i);yc(t[r-1],n,{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 S8=[["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"]],E8={grid:[["Move","←↑↓→ j k home end pgup pgdn"],["Try on","enter"],["Site",`tab shift+tab all, ${Z.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 artwork page in a browser · O the post page"],["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",`⇧←→ ${Yt.map((t)=>t.name.toLowerCase()).join(", ")}`],["Cut out","x the background off or on, on an opaque picture"],["Open","o the artwork page in a browser · O the post page"],["Your own","ctrl+v or v a picture from the clipboard · drop one on the window"],["Grid","esc"],["Close","? esc"]]},eg=6,M8=24;function vc(t){return[...t.settings.flatMap((e,n)=>Boolean(e.advanced)===t.advanced?[n]:[]),t.settings.length]}function x8(t){return t.replace(/^[A-Z](?=[a-z])/,(e)=>e.toLowerCase())}function LS(t){let e=t.settings.filter((n)=>Boolean(n.advanced)!==t.advanced).map((n)=>x8(n.label));return`${t.advanced?"Back to":"More filters:"} ${e.join(", ")} — enter opens the page, or a from any row`}function zS(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 ws(t,e){let n=[],r="";for(let i of t.split(" "))if(r&&mt(r)+1+mt(i)>e)n.push(r),r=i;else r=r?`${r} ${i}`:i;return r?[...n,r]:n}function O8(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 P8(t,e,n,r){let i=tg(r),s=e&&n!==void 0;if(t.entry==="text")return[{text:` ${s?`${n}█`:t.value||"none"} `,sgr:s||e&&t.value?i:t.value?"":W}];let o=s?[]:t.value.split(" "),a=(s?t.choices:O8(t)).map((c,u)=>{let f=o.includes(c),l=t.multi&&e&&u===t.cursor?$t("under"):"";return{text:t.multi?` ${f?"[x]":"[ ]"} ${c} `:` ${c} `,sgr:f?e?`${l}${i}`:"":l?`${l}${W}`:W,choice:c}});return s?[...a,{text:` ${n}█ `,sgr:i}]:a}function FS(t){if(t.entry==="text")return[{text:" ".repeat(M8),sgr:""}];let e=t.choices.map((n)=>({text:t.multi?` [x] ${n} `:` ${n} `,sgr:""}));return t.entry==="number"?[...e,{text:` ${"0".repeat(eg)}█ `,sgr:""}]:e}function R8(t){return t.reduce((e,n)=>e+mt(n.text)+1,0)-1}function CS(t,e){let n=[[]],r=0;for(let i of t){let s=mt(i.text)>e?{...i,text:` …${Array.from(i.text).slice(-(e-2)).join("")}`}:i;if(r>0&&r+mt(s.text)>e)n.push([]),r=0;n[n.length-1]?.push(s),r+=mt(s.text)+1}return n}function jS(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 _S(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 I8(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 A8(t,e,n,r,i){let s=r.panel??0,o=r.settings.length,c=6+Math.max(...r.settings.map((F)=>mt(F.label))),u=Math.max(...r.settings.map((F)=>mt(jS(F)))),f=c+Math.max(...r.settings.map((F)=>R8(FS(F))))+u+5,l=Math.min(e-2,Math.max(48,f)),d=l-c-u-5,h=l-7,m=[!1,!0].map((F)=>({advanced:F,rows:vc({settings:r.settings,advanced:F}).slice(0,-1)})),g=r.settings.map((F)=>CS(FS(F),d).length),b=Math.max(...m.map((F)=>F.rows.reduce((gt,Zt)=>gt+g[Zt],0))),w=Math.max(...m.map((F)=>ws(LS({settings:r.settings,advanced:F.advanced}),h).length),...r.settings.map((F)=>ws(F.about,h).length)),k=`${r.tag}: ${Z.map((F)=>`${F.name} 0,000,000`).join(" · ")}`,v=r.tag?Math.max(ws(k,h).length,ws(_S(r),h).length):0,S=b+w+v+8,x=Math.floor((e-l)/2),M=Math.max(1,Math.floor((n-1-S)/2)),N=tg(r.siteAnsi);t[M]?.put(x,`╭─ Settings ${"─".repeat(Math.max(0,l-13))}╮`);for(let F=M+1;F<M+S-1;F++)t[F]?.put(x,`│${" ".repeat(l-2)}│`);let C=M+2;for(let F of vc(r).slice(0,-1)){let gt=r.settings[F],Zt=F===s;if(Zt)t[C]?.put(x+2,"▶",i);if(t[C]?.mark(x+2,c-3,{kind:"setting",index:F}),t[C]?.put(x+4,gt.label,Zt?Nt:""),gt.value!==gt.default)t[C]?.right(x+l-3,[[jS(gt),W]]);CS(P8(gt,Zt,r.typing,r.siteAnsi),d).forEach((at,Rr)=>{let We=x+c;for(let kn of at)We=(t[C+Rr]?.put(We,kn.text,kn.sgr,void 0,{kind:"choice",index:F,choice:kn.choice})??We)+1}),C+=g[F]}let P=m.find((F)=>F.advanced!==r.advanced)?.rows??[],_=t[M+3+b];if(_){if(s===o)_.put(x+2,"▶",i);let F=_.put(x+3,r.advanced?" ‹ Basic ":" Advanced › ",s===o?N:Nt,void 0,{kind:"setting",index:o});if(P.some((gt)=>r.settings[gt]?.value!==r.settings[gt]?.default))_.put(F+1,"•",W)}t[M+5+b]?.put(x+2,"─".repeat(l-4),W),ws(r.settings[s]?.about??LS(r),h).forEach((F,gt)=>{t[M+6+b+gt]?.put(x+4,F)}),ws(_S(r),h).forEach((F,gt)=>{t[M+6+b+w+gt]?.put(x+4,F,W)}),t[M+S-1]?.put(x,`╰${"─".repeat(l-2)}╯`);let{keys:K,right:B}=I8(r,r.settings[s]);yc(t[n-1],e,{keys:K,right:B})}function N8(t,e,n,r){let i=r.tuning?S8:E8[r.mode],s=Math.min(e-2,Math.max(50,...i.map(([,l])=>mt(l)+16))),o=i.map(([l,d])=>({label:l,parts:ws(d,s-16)})),a=o.reduce((l,{parts:d})=>l+d.length,0)+4,c=Math.floor((e-s)/2),u=Math.max(2,Math.floor((n-a)/2));t[u]?.put(c,`╭─ Help ${"─".repeat(s-9)}╮`);for(let l=u+1;l<u+a-1;l++)t[l]?.put(c,`│${" ".repeat(s-2)}│`);let f=u+2;for(let{label:l,parts:d}of o){t[f]?.put(c+3,l,Nt);for(let h of d)t[f]?.put(c+13,h),f++}t[u+a-1]?.put(c,`╰${"─".repeat(s-2)}╯`),yc(t[n-1],e,{badge:"HELP",right:["? esc","close"]})}function T8(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)=>mt(a.value))),o=Math.max(7,...i.map(mt));r.forEach((a,c)=>{let u=c===e.pick,f=t[1+c];f?.run(0,[[u?"▸ ":" ",n,void 0,{kind:"suggest",index:c}],[a.value,u?Nt+n:"",void 0,{kind:"suggest",index:c}]]),f?.right(2+s+2+o,[[i[c],W]])})}function Dl(t,e=[]){return[...e,...t.flatMap((n,r)=>n.zones(r))]}function ng(t,e,n){let r=Array.from({length:n},()=>new Jl(e)),i=[],s=[],o=$t("accent");if(qp=!1,e<$s.cols||n<$s.rows)return r[0]?.put(0,"ttheme find",Nt+o),r[1]?.put(0,`Needs ${$s.cols}×${$s.rows} — now ${e}×${n}`),r[2]?.put(0,"esc quits",W,void 0,{kind:"key",key:"esc"}),{lines:r.map((c)=>c.render()),images:i,zones:Dl(r),loader:!1,tick:!1};let a=!1;if(t.mode==="try")v8(r,i,e,n,t,o);else a=y8(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 Jl(e);return T8(r,t,o),{lines:r.map((c)=>c.render()),images:[],zones:Dl(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 Jl(e);if(t.help)N8(r,e,n,t);else A8(r,e,n,t,o);return{lines:r.map((u)=>u.render()),images:c,zones:Dl(r),loader:!1,tick:!1}}return{lines:r.map((c)=>c.render()),images:i,zones:Dl(r,s),loader:a,tick:qp}}var H8=130,L8=38,F8=96,C8=28,Mc=[{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}],j8={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]},qS=(t)=>Array.from({length:8},(e,n)=>`«K${t+n}» «»`).join(" "),_8=["«2»❯ «»colortest",`«d»0-7 ${qS(0)}`,`«d»8-15 ${qS(8)}`],DS=2;function G8(t){let e=Mc.length;return Mc[(t%e+e)%e]}function VS(){return Mc.map((t)=>t.name)}function xc(t,e,n){let r=t>=H8&&e>=L8?"full":t>=F8&&e>=C8?"tabs":void 0;if(!r)return;let i=r==="full"?t>=140?47:38:37,s=t-i-1,o=i+1+DS,a=i+s-DS,c=3,u=e-3,f={col:o,row:c,cols:a-o+1,rows:u-c+1},l={col:o+1,row:c+3,cols:f.cols-2,rows:u-c-3},d=[{row:c,col:o,length:f.cols,down:!1},{row:c+2,col:o,length:f.cols,down:!1},{row:u,col:o,length:f.cols,down:!1},{row:c,col:o,length:u-c+1,down:!0},{row:c,col:a,length:u-c+1,down:!0}],h=G8(n);return{tier:r,side:i,width:s,frame:f,title:{col:l.col,row:c+1,cols:l.cols,rows:1},inner:l,rules:d,tiles:[{id:h.id,name:h.name,col:l.col,row:l.row,width:l.cols,rows:l.rows}]}}var Ec="«2»▎ ",JS="«3»▎ ",B8="«1»▁ ",U8=[["","«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. */"],[Ec,"«5»export interface «6»Palette «»{"],[Ec," name: «6»string"],[Ec," ansi: «6»Hex«»[]"],[Ec," ratio?: «6»number"],[Ec,"}"],["",""],["","«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«»> {"],[JS," «5»const «»text = «5»await «4»readFile«»(path, «2»'utf8'«»)"],[JS," «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)"],[""," }"],[B8," «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"],["","}"]],W8=21;function K8(){return["«K4» theme.ts «s» scenes.ts «s» contrast.ts ",...U8.map(([t,e],n)=>{let r=String(n+1).padStart(3);return`${n+1===W8?`«b»${r}`:`«d»${r}`} ${t||"«» "}«»${e}`})]}function rg(t,e,n,r){let i=Math.max(1,r-t.length-2-n.length),s=0,o=`«6»${t}«b»[`;for(let[a,c]of e){let u=Math.min(i-s,Math.round(c*i));o+=`«${a}»${"|".repeat(u)}`,s+=u}return`${o}«»${" ".repeat(i-s)}${n}«b»]`}var z8=[[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]],q8=["«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"],D8=["Help","Setup","Search","Filter","Tree","SortBy","Nice -","Nice +","Kill","Quit"];function J8(t,e,n){return`«${t}»${e}${" ".repeat(Math.max(0,n-G(e)))}`}function Y8(t){let e=t-2,n=Math.floor((e-2)/2),r=(i)=>{let[s,o,a]=z8[i],c=`${((s+o+a)*100).toFixed(1)}%`;return rg(String(i).padStart(3),[["2",s],["1",o],["4",a]],c,n)};return[...[0,1,2,3].map((i)=>`${r(i)} ${r(i+4)}`),`${rg("Mem",[["2",0.45],["4",0.1],["3",0.07]],"9.84G/16.0G",n)} «6»Tasks: «b»214«», 1093 thr; «B2»4«» running`,`${rg("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`,"",J8("K2"," PID USER PRI NI VIRT RES S CPU% MEM% TIME+ Command",e),...q8.map((i)=>i.startsWith("«s»")?`${i}${" ".repeat(Math.max(0,e-G(i.replace(/«[^»]*»/g,""))))}`:i)]}function V8(t){let e=t-2,n="",r=0;return D8.forEach((i,s)=>{let o=`F${s+1}`,a=i.padEnd(6);if(r+o.length+a.length<=e)n+=`«»${o}«K6»${a}`,r+=o.length+a.length}),`${n}«K6»${" ".repeat(Math.max(0,e-r))}`}function YS(t,e,n){if(t==="Editor")return K8();if(t==="Top")return Y8(n);let r=Yt.find((o)=>o.name===t)?.lines??[],i=e?j8[t]:void 0,s=i?i.map((o)=>r[o]??""):r;return t==="Shell"?[...s.slice(0,-1),..._8,...s.slice(-1)]:s}function Xl(t,e){let n=[];for(let r of t){let i=ko(r,e);if(!i)continue;let s=0;n.push(i.map(([o,a])=>{let c={text:o,role:a,col:s};return s+=G(o),c}))}return n}function Z8(t){let r=t-2-G("«K4» NORMAL «s» main src/theme.ts [+] ".replace(/«[^»]*»/g,""))-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 X8(t,e){if(t.id==="code")return[Z8(e),'«d»"src/theme.ts" 26L, 912B written'];return t.id==="monitor"?[V8(e)]:[]}function Q8(t,e,n){let r=Xl(X8(t,e),e),i=Math.max(0,n-r.length),s=[];for(let a of[...t.scenes].reverse()){let c=Xl(YS(a,!1,e),e),u=Xl(YS(a,!0,e),e),f=[c,u].find((l)=>s.length+l.length<=i);if(!f){if(s.length===0)s=t.tail?u.slice(u.length-i):u.slice(0,i);break}s=[...f,...s]}if(r.length===0)return s;let o=Xl(Array.from({length:i-s.length},()=>t.id==="code"?"«4»~":""),e);return[...s,...o,...r]}function Oc(t){let e=Mc.find((r)=>r.id===t.id),n=t.width-2;return e?Q8(e,t.width,t.rows).map((r)=>r.filter((i)=>i.col<n)):[]}function ig(t,e){let{text:n,ground:r}=XS(t);return n===e||r===e}function ZS(t,e){let n=t.inner;return Mc.map((r)=>({name:r.name,count:Oc({id:r.id,name:r.name,col:n.col,row:n.row,width:n.cols,rows:n.rows}).flat().filter((i)=>ig(i.role,e)).length}))}function XS(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 sg(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 Ql(t){let e=[];for(let n of t.tiles)Oc(n).forEach((r,i)=>{r.forEach((s,o)=>{e.push({spot:{pane:n.id,line:i,run:o},col:s.col,text:s.text,role:s.role})})});return e}function og(t,e){return t.pane===e.pane&&t.line===e.line&&t.run===e.run}function QS(t,e){let n=Ql(t);return(n.find((r)=>sg(r.role,e))??n[0])?.spot}function tf(t,e){return e&&Ql(t).find((n)=>og(n.spot,e))?.spot}function tE(t,e,n){let r=Ql(t);if(r.length===0)return;let i=e?r.findIndex((d)=>og(d.spot,e)):-1;if(i<0)return r[0]?.spot;let s=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 d=t.tiles.map((g)=>g.id),h=d.indexOf(s.spot.pane),m=d[(h+(n==="next"?1:d.length-1))%d.length];return r.find((g)=>g.spot.pane===m)?.spot}let o=n==="up"?-1:1,a=r.filter((d)=>d.spot.pane===s.spot.pane),c=[...new Set(a.map((d)=>d.spot.line))],u=c[c.indexOf(s.spot.line)+o];if(u===void 0){let d=t.tiles.map((k)=>k.id),h=d.indexOf(s.spot.pane)+o,m=d[(h+d.length)%d.length],g=r.filter((k)=>k.spot.pane===m),b=o<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>=s.col)??w.at(-1))?.spot}let f=a.filter((d)=>d.spot.line===u);return(f.find((d)=>d.col<=s.col&&d.col+G(d.text)>s.col)??f.find((d)=>d.col>=s.col)??f.at(-1))?.spot}function eE(t,e){let n=Ql(t).find((r)=>og(r.spot,e));return n?XS(n.role):void 0}var t3={lr:"─",du:"│",dr:"╭",dl:"╮",ru:"╰",lu:"╯",dlr:"┬",lru:"┴",dru:"├",dlu:"┤",dlru:"┼"};function nE(t){let e=new Map,n=(i,s,o)=>{let a=e.get(i)??new Map;e.set(i,a);let c=a.get(s)??new Set;a.set(s,c),c.add(o)};for(let i of t)for(let s=0;s<i.length;s++){let o=i.down?i.row+s:i.row,a=i.down?i.col:i.col+s;if(s>0)n(o,a,i.down?"u":"l");if(s<i.length-1)n(o,a,i.down?"d":"r")}let r=new Map;for(let[i,s]of e){let o=new Map;for(let[a,c]of s){let u=[...c].sort().join("");o.set(a,t3[u]??(c.has("l")||c.has("r")?"─":"│"))}r.set(i,o)}return r}import{execFile as e3}from"node:child_process";import{createHash as oE}from"node:crypto";import{existsSync as n3,mkdtempSync as r3,readFileSync as sf,rmSync as i3,statSync as aE,writeFileSync as cE}from"node:fs";import{homedir as s3,tmpdir as o3}from"node:os";import{join as ef}from"node:path";import{fileURLToPath as a3}from"node:url";import{promisify as c3}from"node:util";var Wn=c3(e3),nf=67108864,u3=4096,ug=["image/png","image/jpeg","image/webp","image/gif","image/tiff","image/heic"],l3=["text/uri-list","text/plain;charset=utf-8","text/plain"],ag=[...ug,"text/uri-list","text/plain"];function f3(t){try{return aE(t).isFile()}catch{return!1}}function d3(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 rE(t){if(/^file:\/\//i.test(t))try{return a3(t)}catch{return}if(t.startsWith("~/"))return ef(s3(),t.slice(2));return t.startsWith("/")?t:void 0}function Zo(t,e=f3){let n=[];for(let r of t.replace(/\r\n?/g,`
672
+ ${u} · ${_t(f.length)} · ${d(r.length,"error")} · ${d(i.length,"warning")}`),r.length>0?1:0}async function fS(t,e){switch(t){case void 0:$C();return;case"add":await gC(Qv(t,e));return;case"remove":bC(Qv(t,e));return;case"search":await kC(e);return;case"init":await vC(e);return;case"check":return SC(e);default:throw Error(`unknown marketplace action ${t} — ${lC.join(", ")}, or none to list them`)}}function Qv(t,e){if(!e)throw Error(t==="add"?"marketplace add takes a repository or a folder: ttheme marketplace add alice/ttheme-dust":"marketplace remove takes a marketplace name — `ttheme marketplace` lists them");return e}function dS(t,e){let n=pi(t,e);return`${n} — ${_t(Cn(e,n,gc(t),pe(!1)).length)}, read in place`}function hS(t){return[...t].length===1&&t>=" "&&t!==""}function EC(t){return[...t.replace(/[\r\n\t]+/g," ")].filter(hS).join("")}function gs(t,e,n=()=>!0){if(e==="backspace")return[...tm(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 hS(e)&&n(e)?t+e:void 0}class Yo{value;constructor(t=""){this.value=t}key(t){let e=gs(this.value,t);if(e===void 0)return!1;return this.value=e,!0}paste(t){this.value+=EC(t)}}import{performance as MC}from"node:perf_hooks";import{StringDecoder as xC}from"node:string_decoder";var OC=30,PC=50,IC=500,RC=5,Vo=Buffer.from("\x1B[M"),ql="\x1B]1337;ReportCellSize\x07\x1B[16t\x1B[14t\x1B[18t",yS="\x1B[?1016$p\x1B[16t",vS={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"},AC={"\r":"enter","\n":"enter","\t":"tab","\b":"backspace","":"backspace","\x1B":"esc","\x00":"ctrl-space"},mS=/\[([0-?]*)([ -/]*)([@-~])/y,NC=/^\[[0-?]*[ -/]*$/,pS=/\[(<-?\d+;-?\d+;-?\d+)([Mm])/y,TC=/^\[<[-\d;]*$/,gS=/\](\d+)/y,HC=/^\]\d*$/,bS=/\]\d+;/y,FC=/^1337;ReportCellSize=([\d.]+);([\d.]+)(?:;([\d.]+))?$/,LC=/^(1[0-2]|17|4;\d{1,3});(rgba?:[0-9a-fA-F/]+)$/,SS="\x1B[200~",zl="\x1B[201~";function CC(t){let e=AC[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 Zo(t){return{kind:"key",key:t}}function Xo(t){return{events:[Zo("esc")],end:t+1}}function jC(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 _C=["left","middle","right",void 0];function Yp(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=_C[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 BC(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?Yp(s-32,o-33,a-33,!1):void 0;return{events:c?[c]:[],end:i}}function GC(t,e,n,r,i){let s=Math.max(0,e)/i.w,o=Math.max(0,n)/i.h,a=Math.floor(s),c=Math.floor(o),u=Yp(t,a,c,r);return u&&{...u,fx:s-a,fy:o-c}}function wS(t,e,n,r){if((n==="M"||n==="m")&&e===""&&t.startsWith("<")){let[s=-1,o=0,a=0]=t.slice(1).split(";").map(Number),c=r?GC(s,o,a,n==="m",r):Yp(s,o-1,a-1,n==="m");return c?[c]:[]}if(n==="t"&&e===""){let[s,o=0,a=0]=t.split(";").map(Number),c=s===6?"cell":s===4?"window":s===8?"grid":void 0;return c?[{kind:"size",of:c,h:o,w:a}]:[]}if(n==="y"&&e==="$"&&t.startsWith("?")){let[s=0,o=0]=t.slice(1).split(";").map(Number);return[{kind:"mode",mode:s,value:o}]}if(n==="c"&&t.startsWith("?"))return[{kind:"attributes"}];let i=e===""?vS[`${t}${n}`]:void 0;return i?[Zo(i)]:[]}function UC(t,e,n,r){pS.lastIndex=e+1;let i=pS.exec(t);if(i)return{events:wS(i[1],"",i[2],r),end:e+1+i[0].length};mS.lastIndex=e+1;let s=mS.exec(t);if(!s){let l=t.slice(e+1);return!n&&(NC.test(l)||TC.test(l))?void 0:Xo(e)}let[o,a="",c="",u=""]=s,f=e+1+o.length;if(a===""&&c===""&&u==="M")return BC(t,f,n);if(a==="200"&&u==="~"){let l=t.indexOf(zl,f);if(l===-1)return n?{events:[{kind:"paste",text:t.slice(f)}],end:t.length}:void 0;return{events:[{kind:"paste",text:t.slice(f,l)}],end:l+zl.length}}return{events:wS(a,c,u,r),end:f}}function WC(t){let e=FC.exec(t);if(e){let o=Number(e[3]??1);return[{kind:"size",of:"cell",h:Math.round(Number(e[1])*o),w:Math.round(Number(e[2])*o)}]}let n=LC.exec(t);if(n)return[{kind:"color",code:n[1],value:n[2]}];let[r="",i="",...s]=t.split(";");return[{kind:"osc",code:r,meta:jC(i),payload:s.join(";")}]}function KC(t,e,n){gS.lastIndex=e+1;let r=gS.exec(t),i=r?t[e+1+r[0].length]:void 0;if(i!==";"&&i!=="\x07"&&i!=="\x1B")return!n&&HC.test(t.slice(e+1))?void 0:Xo(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:WC(t.slice(e+2,o)),end:o+(t[o]==="\x07"?1:2)}}function zC(t,e,n){let r=t[e+2];if(r===void 0)return n?Xo(e):void 0;if(!/^[A-Za-z]$/.test(r))return Xo(e);let i=vS[r];return{events:i?[Zo(i)]:[],end:e+3}}function qC(t,e,n,r){let i=t[e+1];if(i===void 0)return n?Xo(e):void 0;if(i==="[")return UC(t,e,n,r);if(i==="]")return KC(t,e,n);if(i==="O")return zC(t,e,n);if(i==="")return{events:[Zo("alt-backspace")],end:e+2};if(/^[a-z]$/.test(i))return{events:[Zo(`alt-${i}`)],end:e+2};return Xo(e)}function $S(t,e=!1,n){let r=[],i=0;while(i<t.length){if(t[i]==="\x1B"){let a=qC(t,i,e,n);if(!a)return{events:r,rest:t.slice(i)};r.push(...a.events),i=a.end;continue}let s=String.fromCodePoint(t.codePointAt(i)),o=CC(s);if(o)r.push(Zo(o));i+=s.length}return{events:r,rest:""}}function DC(t,e){for(let n=Math.min(Vo.length-1,t.length-e);n>0;n--)if(t.subarray(t.length-n).equals(Vo.subarray(0,n)))return t.length-n;return t.length}function JC(t){let e=[],n=0,r=t.indexOf(Vo);while(r!==-1&&r+6<=t.length){e.push(t.subarray(n,r));let[s=0,o=0,a=0]=t.subarray(r+3,r+6);if(o>32&&a>32)e.push(Buffer.from(`\x1B[<${s-32};${o-32};${a-32}M`));n=r+6,r=t.indexOf(Vo,n)}let i=r===-1?DC(t,n):r;return e.push(t.subarray(n,i)),{bytes:Buffer.concat(e),carry:i<t.length?t.subarray(i):void 0}}function kS(t){return bS.lastIndex=1,t.startsWith(SS)||t.startsWith("\x1B]")&&bS.test(t)}function YC(t,e){let n=t.slice(-zl.length)+e;return t.startsWith(SS)?n.includes(zl):n.includes("\x07")||n.includes("\x1B\\")}class Vp{held="";timer;carry;pressed;wheeled;utf8=new xC("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=MC.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<RC)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<=IC;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.held&&!e.includes("\x1B")&&this.burst(e)){this.settle(),this.take([{kind:"paste",text:e}]);return}if(kS(this.held)&&!YC(this.held,e)){this.held+=e;return}let{events:n,rest:r}=$S(this.held+e,!1,this.cell());if(this.held=r,this.settle(),n.length>0)this.take(n)}settle(){let t=this.held.length+(this.carry?.length??0);if(t>0&&!kS(this.held))this.wait(t===1?OC:PC)}bytes(t){let{bytes:e,carry:n}=JC(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);let t=this.carry;this.carry=void 0;let e=t&&!t.subarray(0,Vo.length).equals(Vo)?this.utf8.write(t):"",{events:n}=$S(this.held+e,!0,this.cell());if(this.held="",n.length>0)this.take(n)}stop(){clearTimeout(this.timer),this.held="",this.carry=void 0}}class wc{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 Zp{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 Jl={on:"\x1B[?1049h",off:"\x1B[?1049l"},zn={on:"\x1B[?25l",off:"\x1B[?25h"},gi={on:"\x1B[?7l",off:"\x1B[?7h"},Er={on:"\x1B[?2004h",off:"\x1B[?2004l"},IS={on:"\x1B[?1004h",off:"\x1B[?1004l"},VC={on:"\x1B[?1000h\x1B[?1002h\x1B[?1006h",off:"\x1B[?1006l\x1B[?1002l\x1B[?1000l"},ES={on:"\x1B[?1016h",off:"\x1B[?1016l\x1B[?1006h"};function bi(t=process.env){return t.TTHEME_MOUSE==="off"?[]:[VC]}var RS={SIGHUP:1,SIGINT:2,SIGQUIT:3,SIGTERM:15},ZC=3000;class kc extends Error{exit;constructor(t){super(t);this.exit=128+RS[t]}}var Kn=[],bs=new Map,$c=new Map,MS;function xS(t){return Kn.findLast((e)=>e.input===t)}var OS;function AS(t){for(let e of Kn.toReversed())e.abort(t);if(!OS)OS=setTimeout(()=>{NS(),process.exit(t instanceof kc?t.exit:1)},ZC).unref()}var XC=Object.fromEntries(Object.keys(RS).map((t)=>[t,()=>AS(new kc(t))]));function NS(){for(let t of Kn.toReversed())t.close()}function QC(){for(let t of Kn)t.reassert();Kn.at(-1)?.redraw()}function PS(t){let e=t?"on":"off";for(let[n,r]of Object.entries(XC))process[e](n,r);if(process[e]("uncaughtException",AS),process[e]("exit",NS),process.platform!=="win32")process[e]("SIGCONT",QC)}function Dl(){}class TS{input;output;failed;modes=[];assumed;owned=[];keys;tty;take;resized;queued=[];asking;reject=Dl;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 Vp((r)=>this.deliver(r),t.burst,()=>bs.has(ES)?MS:void 0),this.failed=new Promise((r,i)=>{this.reject=i}),this.failed.catch(Dl),this.tty&&!Kn.some((r)=>r.tty))PS(!0);Kn.push(this);let e="";for(let r of this.assumed)if(!bs.has(r))e+=r.on;for(let r of t.modes??[])e+=this.claim(r);this.write(e);let n=$c.get(this.input)??0;if(n===0)this.input.setRawMode?.(!0);$c.set(this.input,n+1),this.input.on("data",this.received),this.input.resume(),this.output.on("resize",this.resizing),this.output.on("error",Dl)}hold(t){this.write(this.claim(t))}pixels(t){MS=t,this.hold(ES)}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.toReversed()){let r=(bs.get(n)??1)-1;if(r===0)bs.delete(n),t+=n.off;else bs.set(n,r)}this.write(t),this.open=!1;let e=($c.get(this.input)??1)-1;if(e===0)$c.delete(this.input),this.input.setRawMode?.(!1),this.input.pause();else $c.set(this.input,e);if(this.output.off("error",Dl),Kn.splice(Kn.indexOf(this),1),this.tty&&!Kn.some((n)=>n.tty))PS(!1)}received=(t)=>{if(xS(this.input)===this&&!this.aborted)this.keys.feed(t)};resizing=()=>{if(xS(this.input)===this)this.resized?.()};claim(t){this.modes.push(t);let e=bs.get(t)??0;if(bs.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 wi(t,e){let n=new TS(t);try{return await e(n)}finally{n.close()}}var t8=3,FS={catalogs:{top:ro,shelf:(t)=>et(t.name)?t.catalog:void 0},marketplaces:{top:(t)=>et(t.name)??J,shelf:(t)=>t.catalog}};function yc(t,e){return`${t}/${e}`}function HS(t){return et(t.name)?ne(t.name):t.name}function Yl(t,e){let n=e.shelf(t);return n===void 0?void 0:yc(e.top(t),n)}function Vl(t){if(t?.kind==="palette")return`palette ${t.entry.name}`;if(t?.kind==="top")return`top ${t.name}`;if(t?.kind==="catalog")return`catalog ${yc(t.top,t.name)}`;if(t?.kind==="extra")return`extra ${t.extra.key}`;return t?.kind??""}function Qo(t){return t?.kind==="rule"}function Zl(t,e){return zi([t.name,et(t.name)??"",t.native??"",t.catalog??"",...t.nativeNames??[],...Fu(t.booru)],e)}function LS(t,e,n,r="catalogs",i=[],s="tree"){let o=FS[r],a=n.trim(),c=[],u=(l)=>({kind:"palette",entry:l}),f=Map.groupBy(t.filter((l)=>!l.default),(l)=>o.top(l));for(let[l,d]of f){let h=d[0],m=a?d.filter(($)=>Zl($,a)):d;if(a&&m.length===0)continue;let p=s==="inside"||s==="tree"&&(a.length>0||e.has(l));if(s!=="inside")c.push({kind:"top",name:l,...!et(h.name)&&l===h.catalog&&h.native?{native:h.native}:{},lead:d.find(($)=>$.lead)??h,expanded:p,count:m.length});if(!p)continue;let b=m.filter(($)=>o.shelf($)!==void 0);for(let[$,k]of Map.groupBy(b,(v)=>o.shelf(v))){let v=k.find((x)=>x.lead)??k[0],S=a.length>0||e.has(yc(l,$));if(c.push({kind:"catalog",top:l,name:$,...v.native?{native:v.native}:{},lead:v,expanded:S,count:k.length}),S)c.push(...k.map(u))}c.push(...m.filter(($)=>o.shelf($)===void 0).map(u))}for(let l of i)if(!f.has(l)&&(a===""||zi([l],a)))c.push({kind:"top",name:l,expanded:e.has(l),count:0});return c}function e8(t,e){let n=e.trim(),r=new Set(t.values().filter((i)=>!i.default&&(n===""||Zl(i,n))).map(ro));return LS(t,new Set,"").filter((i)=>i.kind==="top"&&r.has(i.name))}function n8(t){return t.includes("@")}function r8(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);if(!r(o))return o;let a=Math.sign(e),c=o+a;if(c>=0&&c<=s)return c;return i&&Math.abs(e)===1?c<0?s:0:o-a}function vc(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 i8(t){let e=t.findIndex((n)=>n.kind==="top"&&n8(n.name));return e>0&&t.slice(0,e).some((n)=>n.kind==="top")?t.toSpliced(e,0,{kind:"rule"}):t}function s8(t){let e=t.findIndex((n)=>n.kind==="palette");return e===-1?0:e}function Xl(t){return t==="decode"||t==="glitch"?t:"typewriter"}function ws(t,e,n,r){return pn({kind:"row",at:t,part:e,...r?{pane:r}:{}},n)}class ta{picked;scope;maxItems;focus="lit";named=[];catalogs=[];layout;mode;pane;place;color;p;onFocus;note;badge;about;tops;heads;extras;entries=[];catalogPad=0;namePad=0;expanded=new Set;rows=[];cursor=0;top=0;span=1;filter="";lastFocused="";constructor(t){this.picked=t.picked,this.scope=t.scope??"palette",this.layout=t.layout??"catalogs",this.mode=t.mode??"tree",this.pane=t.pane,this.place=FS[this.layout],this.maxItems=t.maxItems??12,this.color=t.color??!0,this.p=je(this.color),this.onFocus=t.onFocus,this.note=t.note,this.badge=t.badge,this.about=t.about,this.tops=t.tops,this.heads=t.heads,this.extras=t.extras,this.load(t.entries),this.rebuild("first")}load(t){this.entries=t,this.named=t.filter((e)=>!e.default),this.catalogs=[...new Set(this.named.map(ro))],this.catalogPad=Math.max(0,...this.catalogs.map((e)=>e.length)),this.namePad=Math.max(0,...this.named.map((e)=>this.indent(e).length+HS(e).length))}lead(){return this.mode==="inside"?"":" "}indent(t){return this.place.shelf(t)===void 0?this.lead():`${this.lead()} `}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(this.place.top(t.entry));let e=Yl(t.entry,this.place);if(e!==void 0)this.expanded.add(e)}this.setFilter("")}focusedRow(){return this.rows[this.cursor]}refocus(){this.lastFocused="",this.sync()}refresh(){this.rebuild("stay")}select(t){let e=this.rows.findIndex((n)=>Vl(n)===t);if(e===-1)return!1;return this.cursor=e,this.sync(),!0}members(t,e){let n=this.scope==="palette"?this.filter.trim():"";return this.under(t,e).filter((r)=>n===""||Zl(r,n))}under(t,e){return this.named.filter((n)=>this.place.top(n)===t&&(e===void 0||this.place.shelf(n)===e))}inside(t){return t.kind==="palette"?[t.entry]:t.kind==="top"?this.under(t.name):t.kind==="catalog"?this.under(t.top,t.name):[]}everyone(t){return t.flatMap((e)=>e.kind==="top"?this.members(e.name):[])}pick(){let t=this.rows[this.cursor],e=t?.kind==="palette"?[t.entry.name]:t?.kind==="top"?this.members(t.name).map((r)=>r.name):t?.kind==="catalog"?this.members(t.top,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.catalogs.filter((t)=>this.members(t).every((e)=>this.picked.has(e.name))).length}total(){return this.scope==="catalog"?this.catalogs.length:this.named.length}matched(){let t=this.filter.trim();if(this.scope==="catalog")return this.rows.filter((e)=>e.kind==="top").length;return t?this.named.filter((e)=>Zl(e,t)).length:this.named.length}sync(){let t=this.rows[this.cursor],e=t?.kind==="palette"?t.entry:t?.kind==="top"&&this.scope==="catalog"?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==="catalog"?e8(this.entries,this.filter):LS(this.entries,this.expanded,this.filter,this.layout,this.tops?.()??[],this.mode),r=this.layout==="marketplaces"||n.length===0?n:i8([{kind:"all",count:this.allCount(n)},...n]),i=(o)=>(o??[]).map((a)=>({kind:"extra",extra:a}));this.rows=[...i(this.heads?.()),...r,...i(this.extras?.())];let s=n.length>0?this.rows.indexOf(n[this.mode==="inside"&&!this.filter.trim()?0:s8(n)]):Math.max(0,this.rows.findIndex((o)=>!Qo(o)&&!(o.kind==="extra"&&o.extra.idle)));if(t==="first")this.cursor=s;else if(t==="keep"||t==="stay"){let o=Vl(e),a=e?.kind==="palette"||t==="stay"?this.rows.findIndex((u)=>Vl(u)===o):-1,c=e?.kind==="extra"&&t==="stay";this.cursor=a!==-1?a:c?Math.min(this.cursor,this.rows.length-1):s}else if(this.cursor>=this.rows.length)this.cursor=Math.max(0,this.rows.length-1);this.settle(),this.sync()}settle(){if(!Qo(this.rows[this.cursor]))return;let t=this.rows.findIndex((n,r)=>r>this.cursor&&!Qo(n)),e=this.rows.findLastIndex((n,r)=>r<this.cursor&&!Qo(n));this.cursor=t!==-1?t:e!==-1?e:this.cursor}allCount(t){return this.scope==="catalog"?t.length:this.everyone(t).length}move(t,e=!0){this.cursor=r8(this.cursor,t,this.rows.length,(n)=>Qo(this.rows[n]),e),this.sync()}point(t){let e=this.rows[t];if(!e||Qo(e))return!1;return this.cursor=t,this.sync(),!0}size(){return this.rows.length}outer(){let t=this.rows[this.cursor];return this.mode==="inside"&&(this.filter.trim()!==""||t===void 0||t.kind==="catalog"&&!t.expanded||t.kind==="palette"&&Yl(t.entry,this.place)===void 0)}flip(){let t=this.rows[this.cursor];if(t?.kind==="top"||t?.kind==="catalog")this.fold(!t.expanded)}foldable(){let t=this.rows[this.cursor];return(t?.kind==="catalog"||t?.kind==="top"&&this.mode==="tree")&&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)=>Vl(e)===t)),this.sync()}fold(t){if(this.filter||this.scope==="catalog")return;let e=this.rows[this.cursor];if(e?.kind==="top"){if(t!==e.expanded)this.toggle(e.name)}else if(e?.kind==="catalog"){if(t!==e.expanded)this.toggle(yc(e.top,e.name));else if(!t&&this.mode==="tree")this.reach(`top ${e.top}`)}else if(e?.kind==="palette"&&!t&&!e.entry.default){let n=Yl(e.entry,this.place);if(n===void 0){if(this.mode==="tree"){let r=this.place.top(e.entry);this.climb(r,`top ${r}`)}}else this.climb(n,`catalog ${n}`)}}page(){return this.span}window(){let t=this.rows.map((a,c)=>this.renderRow(a,c)),e=(a)=>t[a]?.length??0,n=Math.max(1,this.maxItems);this.top=Math.min(this.top,this.cursor);let r=0;for(let a=this.top;a<=this.cursor;a++)r+=e(a);while(this.top<this.cursor&&r>n)r-=e(this.top),this.top+=1;let i=0;for(let a=this.top;a<t.length;a++)i+=e(a);while(this.top>0&&i+e(this.top-1)<=n)this.top-=1,i+=e(this.top);let s=[],o=this.top;while(o<t.length&&(o===this.top||s.length+e(o)<=n))s.push(...t[o]??[]),o+=1;return this.span=Math.max(1,o-this.top),s.push(...t[o]??[]),{lines:s.slice(0,n),above:this.top,below:t.length-o}}renderRow(t,e){if(t.kind==="rule")return[` ${this.p.dim("── Marketplaces ──────────")}`];return(t.kind==="extra"?t.extra.text(e===this.cursor&&this.focus==="lit",e):this.rowText(t,e)).split(`
673
+ `).map((r)=>r?ws(e,"row",r,this.pane):r)}rowText(t,e){let n=e===this.cursor&&this.focus!=="off",r=t.kind==="palette"?t.entry:t.kind==="all"?void 0:t.lead,i=this.color&&n&&this.focus==="lit"&&r!==void 0,{dim:s,bold:o}=this.p,a=(v)=>this.color?` ${qu(lo(v),i?pr(v.foreground):kt)}`:"",c=!n?" ":i?`${pr(r.cursor)}${R.gutter}${kt} `:this.focus==="held"?this.color?`${this.p.dim(R.gutter)} `:" ":`${R.gutter} `,u=(v)=>i?`${c}${Xk(r.selection,r.foreground)} ${v} ${ge}`:`${c} ${v}`,f=(v)=>ws(e,"box",`${v?R.on:R.off} `,this.pane),l=(v)=>ws(e,"fold",`${v?R.opened:R.closed} `,this.pane);if(t.kind==="all")return u(`${f(this.everyone(this.rows).every((v)=>this.picked.has(v.name)))}Select all ${s(`(${t.count})`)}`);if(t.kind==="top"&&this.scope==="catalog"){let v=`(${t.count})${t.native?` ${t.native}`:""}`;return u(`${f(this.pickedIn(t.name)===t.count)}${o(t.name.padEnd(this.catalogPad))}${t.lead?a(t.lead):""}${this.color?" ":" "}${s(v)}`)}let d=this.rows[this.cursor],h=(v,S)=>this.color&&d?.kind==="palette"&&v?this.p.accent(o(S)):o(S);if(t.kind==="top"){let v=h(d?.kind==="palette"&&this.place.top(d.entry)===t.name,t.name),S=t.native?` ${s(t.native)}`:"",x=this.badge?.(t.name)??"";if(this.about){let M=this.about(t.name,this.under(t.name),this.filter.trim()?t.count:void 0);return[...e>0?[""]:[],u(`${ws(e,"fold",`${M.added?R.on:R.off} `,this.pane)}${v}${S}${x}`),...M.lines.map((N)=>u(` ${N}`))].join(`
674
+ `)}return u(`${l(t.expanded)}${v} ${s(`(${this.pickedIn(t.name)}/${t.count})`)}${S}${x}`)}if(t.kind==="catalog"){let v=d?.kind==="palette"&&Yl(d.entry,this.place)===yc(t.top,t.name),S=s(`(${this.pickedIn(t.top,t.name)}/${t.count})`),x=t.native?` ${s(t.native)}`:"";return u(`${this.lead()}${l(t.expanded)}${h(v,t.name)} ${S}${x}`)}let m=t.entry,p=this.indent(m),b=HS(m),$=this.color?b.padEnd(this.namePad-p.length):b,k=n?o($):$;return u(`${p}${f(this.picked.has(m.name))}${k}${a(m)}${this.note?.(m)??""}`)}}function Xp(t){let e=t.named[Math.floor(Math.random()*t.named.length)],n=t.catalogs[Math.floor(Math.random()*t.catalogs.length)];return e&&n?`${e.name} | ${n}`:""}class Ql{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 o8=5;class Qp{picked;list;scope;color;required;most;hint;field=new Yo;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 Ql(t.fx??"typewriter",()=>Xp(this.list),()=>this.redraw())}prompt(){return wi({input:this.input,output:this.output,modes:[zn,Er]},async(t)=>{let e=new Sp((r)=>t.write(r),()=>t.cols),n=()=>{return this.list.maxItems=Math.max(t8,Math.min(this.most,t.rows-o8)),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=vc(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{dim:t,accent:e,warn:n}=je(this.color),r=this.scope==="catalog"?"Catalogs":"Palettes";if(this.state==="submit")return[`${t("◇")} ${r} ${t(`· ${this.list.pickedCount()} picked`)}`];if(this.state==="cancel")return[`${t(`◇ ${r} · cancelled`)}`];let i=this.field.value,s=`${e("◆")} ${r} ${t(`(${this.list.matched()}/${this.list.total()} · ${this.list.pickedCount()} picked)`)}`,o=this.hint.text(),a=`${e("│")} ${i?`${i}_`:t(`Search…${o?` e.g. ${o}`:""}`)}`,{lines:c,below:u}=this.list.window(),f=c.length>0?c.map((p)=>`${e("│")} ${p}`):[`${e("│")} ${t(`No ${this.scope==="catalog"?"catalogs":"palettes"} match '${i}'`)}`];while(f.length<this.list.maxItems)f.push(e("│"));let l=u>0?`${e("│")} ${t(`↓ ${u} more`)}`:e("│"),d=this.scope==="catalog"?"":" · ←→ fold",h=this.scope==="catalog"?"continue":"install",m=this.state==="error"?`${e("└")} ${n(this.error)}`:`${e("└")} ${t(`↑↓ move${d} · space pick · type to filter · enter ${h} · esc cancel`)}`;return[s,a,...f,l,m]}}var a8=40,c8=60,u8=42,l8=94,f8=22,CS=40,jS=10,tf=3,d8=500,_S=12,BS={title:"",lines:[],brief:""};function $i(t){let e=t.trim();if(e!==J&&!e.includes("/")&&!e.startsWith("~"))return;try{return Fn(e)}catch{return}}function tg(t){return t===J?"Built in":wt(t)?t:st(t)}function GS(t){return t.charAt(0).toUpperCase()+t.slice(1)}class eg{picked;field=new Yo;query=new Yo;adds=new Map;removes=new Set;want=new Map;renew=new Set;updates;tuned;busy=new Map;failed=new Map;peeked=new Map;peekFailed=new Map;staging=new Set;timers=new Map;refreshed=[];inflight=new Set;marketplaces;kept;installed;startup;io;order;color;p;hub;owns;input;output;maxItems=12;paint;list;inside;results;side="cards";showing="browse";landing;open;split=0;hint;screen;state="active";phase="browse";offset=0;started=!1;log=[];working="";stopped;beat=0;asking;leaving;goto;listing;loading=!1;loadError;help=!1;live;constructor(t){this.marketplaces=t.marketplaces,this.kept=t.kept,this.installed=new Set(t.installed),this.updates=new Set(t.updates??[]),this.tuned=new Set(t.tuned??[]),this.startup=t.startup,this.io=t.io,this.order=t.order??((e)=>e),this.color=t.color??!0,this.p=je(this.color),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),this.list=new ta({entries:this.entries(),picked:this.picked,layout:"marketplaces",mode:"cards",color:this.color,maxItems:this.maxItems,note:(e)=>this.mark(e),badge:(e)=>this.badge(e),about:(e,n,r)=>this.about(e,n,r),tops:()=>this.tops(),heads:()=>this.heads(),onFocus:(e)=>this.focus(e)}),this.inside=new ta({entries:[],picked:this.picked,layout:"marketplaces",mode:"inside",pane:"panel",color:this.color,maxItems:this.maxItems,note:(e)=>this.mark(e),onFocus:(e)=>{if(this.side==="panel")this.focus(e)}}),this.inside.focus="off",this.results=new ta({entries:[],picked:new Set,layout:"marketplaces",mode:"cards",color:this.color,maxItems:this.maxItems,heads:()=>this.searchHeads(),extras:()=>this.found()}),this.follow(),this.hint=new Ql(t.fx??"typewriter",()=>Xp(this.list),()=>this.redraw());for(let e of t.due)this.update(e)}run(){let t=[...this.owns?[Jl,zn,gi]:[],Er,...bi()],e=this.owns?[]:[zn,gi];return wi({input:this.input,output:this.output,modes:t,assume:e},async(n)=>{let r=new hs({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.values().filter((e)=>t.has(e))),adds:[...this.adds.values()],removes:[...this.removes],auto:Object.fromEntries(this.want),renew:[...this.renew].filter((e)=>this.updates.has(e)&&this.picked.has(e)&&t.has(e)),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,this.landing=void 0;else if(/^[yn]$/i.test(t))this.answer(t.toLowerCase()==="y");return}if(this.phase!=="browse"){this.steer(t);return}if(this.showing==="search"){this.searchKey(t);return}let e=this.side==="panel",n=vc(t,(e?this.inside:this.list).page());if(t==="enter")if(e&&this.inside.foldable())this.inside.flip();else if(!e&&this.list.focusedRow()?.kind==="top")this.enter();else if(!e&&this.focusedFound()?.kind==="search")this.openSearch();else this.finish();else if((t==="esc"||t==="ctrl-u")&&this.field.value)this.clear();else if(t==="esc")if(e)this.back();else this.state="cancel";else if(t==="?")this.help=!0;else if(n!==void 0)this.move(n);else if(t==="up"||t==="down")this.move(t==="up"?-1:1);else if(t==="right")if(e)this.inside.fold(!0);else if(this.focusedFound()?.kind==="search")this.openSearch();else this.enter();else if(t==="left"){if(e&&this.inside.outer())this.back();else if(e)this.inside.fold(!1)}else if(t==="tab"||t==="shift-tab"){if(this.hub)this.leave(im(this.hub,t==="tab"?1:-1))}else if(t==="shift-left"||t==="shift-right"){if(!e)this.autoUpdate(t==="shift-right")}else if(t===" ")if(e)this.inside.pick();else this.activate();else if(t==="delete"){let r=this.focusedMarketplace();if(r&&!e)this.toggleMarketplace(r)}else if(t==="ctrl-r")this.refresh();else if(this.field.key(t))this.typed()}searchKey(t){let e=vc(t,this.results.page());if(t==="enter"||t===" ")this.take(t==="enter");else if((t==="esc"||t==="ctrl-u")&&this.query.value)this.query.value="",this.searchTyped();else if(t==="esc"||t==="left")this.closeSearch();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==="tab"||t==="shift-tab"){if(this.hub)this.leave(im(this.hub,t==="tab"?1:-1))}else if(t==="ctrl-r")this.loadIndex();else if(this.query.key(t))this.searchTyped()}take(t){let e=this.focusedFound();if(e?.kind==="back"){this.closeSearch();return}if(e?.kind==="state"){this.loadIndex();return}let n=e?.kind==="add"?e.source:e?.kind==="listed"?e.listed.source:void 0;if(n===void 0)return;let r=this.known(n);if(!r)this.landing=t?n:void 0,this.load(n,!0);else if(t)this.closeSearch(),this.list.select(`top ${r.id}`);else if(this.adds.has(r.source))this.adds.delete(r.source),this.want.delete(r.source),this.reload()}openSearch(){let t=this.field.value.trim();if(t&&!$i(t))this.query.value=t;if(this.showing="search",this.results.setFilter(this.query.value),this.results.refresh(),this.live&&!this.listing)this.loadIndex();this.watch()}closeSearch(){this.showing="browse",this.landing=void 0,this.follow(),this.watch()}searchTyped(){this.results.setFilter(this.query.value),this.watch()}loadIndex(){if(this.loading)return;this.loading=!0,this.loadError=void 0,this.redraw(),this.track(this.io.index()).then((t)=>{this.loading=!1,this.listing=t,this.results.refresh(),this.redraw()},(t)=>{this.loading=!1,this.loadError=t.message,this.results.refresh(),this.redraw()})}finish(){if(this.dirty())this.phase="review",this.offset=0;else this.state="submit"}enter(){if(this.follow(),this.side==="panel")return!0;if(this.list.focusedRow()?.kind!=="top"||this.inside.size()===0)return!1;return this.side="panel",this.list.focus="held",this.inside.focus="lit",this.inside.refocus(),!0}back(){this.side="cards",this.list.focus="lit",this.inside.focus="off"}follow(t=!1){let e=this.list.focusedRow(),n=e?.kind==="top"?e.name:void 0;if(t||n!==this.open)this.open=n,this.inside.setEntries(n===void 0?[]:this.membersOf(n));if(this.side==="panel"&&this.inside.size()===0)this.back()}membersOf(t){return this.entries().filter((e)=>(et(e.name)??J)===t)}refresh(){let t=this.focusedMarketplace();if(this.side==="panel")this.toggleRenew();else if(t&&wt(t.source)&&!this.adds.has(t.source))this.update(t.source)}pasted(t){if(this.phase!=="browse"||this.help||this.asking||this.leaving!==void 0)return;if(this.showing==="search")this.query.paste(t),this.searchTyped();else this.field.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,this.split>0&&t.col>=this.split);return}if(!r)return;if(t.action==="press"&&t.button==="left"){if(i&&r.kind==="row")this.point(r)}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.side===(r.pane?"panel":"cards"))this.move(r.step*(r.pane?this.inside:this.current()).page())}else if(r.kind==="hub"){if(i&&this.hub&&r.tab!==this.hub)this.leave(cy(r.tab))}else if(r.kind==="row"&&i)this.openRow(r,t.count)}}point(t){if(this.showing==="search"){this.results.point(t.at),this.watch();return}if(t.pane){if(this.enter())this.inside.point(t.at);return}this.back(),this.list.point(t.at),this.watch()}wheel(t,e){if(this.phase!=="browse"){this.scroll(t);return}if(this.showing==="search"){this.move(t,!1);return}if(e&&!this.enter())return;if(!e)this.back();this.move(t,!1)}openRow(t,e){if(this.showing==="search"){if(t.part==="box"||e===2)this.take(e===2)}else if(t.pane){if(t.part==="box")this.inside.pick();else if(t.part==="fold")this.inside.flip();else if(e===2)this.inside.open()}else if(this.list.focusedRow()?.kind==="extra"){if(t.part==="box"||e===2)this.activate()}else if(t.part==="fold"||e===2)this.enter()}typed(){let t=this.field.value,e=this.list.focusedRow();if(this.list.setFilter(t),e?.kind==="top")this.list.select(`top ${e.name}`);if(this.inside.setFilter(t),this.follow(),t.trim()&&this.list.focusedRow()?.kind==="top"&&this.inside.matched()>0)this.enter();else if(t.trim())this.back();this.watch()}clear(){this.field.value="";let t=this.list.focusedRow();if(this.inside.clear(),this.list.setFilter(""),t?.kind==="top")this.list.select(`top ${t.name}`);this.follow(),this.watch()}redraw(){if(this.state==="active")this.screen?.request()}focus(t){if(this.state!=="submit"&&this.state!=="cancel")this.paint?.(t)}track(t){this.inflight.add(t);let e=()=>this.inflight.delete(t);return t.then(e,e),t}active(){return[...this.marketplaces.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.marketplaces.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()])}reload(){this.list.setEntries(this.entries()),this.follow(!0)}tops(){return[...this.marketplaces,...this.adds.values()].map((t)=>t.id)}marketplaceNamed(t){return[...this.marketplaces,...this.adds.values()].find((e)=>e.id===t)}focusedMarketplace(){let t=this.list.focusedRow();return t?.kind==="top"?this.marketplaceNamed(t.name):void 0}current(){return this.showing==="search"?this.results:this.list}move(t,e=!0){(this.side==="panel"?this.inside:this.current()).move(t,e),this.watch()}autoUpdate(t){let e=this.focusedMarketplace();if(e&&wt(e.source))if(t===e.auto)this.want.delete(e.source);else this.want.set(e.source,t)}activate(){let t=this.list.focusedRow();if(t?.kind!=="extra"){this.list.pick();return}let e=t.extra.found;if(e?.kind==="add")this.load(e.source,!0);else if(e?.kind==="search")this.openSearch()}toggleMarketplace(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.marketplaces,...this.adds.values()].find((e)=>lr(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),this.landing=void 0;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 marketplace at ${n.shown}`),this.landing=void 0;else if(Rt(t)||t===J)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)}focusedFound(){let t=this.current().focusedRow();return t?.kind==="extra"?t.extra.found:void 0}watch(){if(!this.live)return;let t=$i((this.showing==="search"?this.query:this.field).value);if(t&&this.wants(t))this.later("typed",d8,()=>this.load(t,!1));else this.cancel("typed")}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);let n=$i(this.field.value);if(n&&lr(n,t.source))this.field.value="",this.list.setFilter("");let r=$i(this.query.value);if(r&&lr(r,t.source))this.query.value="",this.results.setFilter("");if(this.reload(),this.list.select(`top ${t.id}`),this.landing!==void 0&&lr(this.landing,t.source))this.closeSearch();else this.results.refresh()}update(t){if(this.busy.has(t))return;this.failed.delete(t),this.busy.set(t,"Updating…"),this.track(this.io.refresh(t)).then(({marketplace:e,refreshed:n,updates:r})=>{this.busy.delete(t),this.updates=new Set(r),this.marketplaces=this.marketplaces.map((i)=>i.source===t?e:i),this.refreshed.push(n),this.reload(),this.redraw()},(e)=>{this.busy.delete(t),this.failed.set(t,`Update failed: ${e.message}`),this.redraw()})}row(t,e=!1){return{key:t.kind==="listed"?`listed ${t.listed.source}`:t.kind,...e?{idle:e}:{},found:t,text:(n,r)=>this.foundLine(t,n,r)}}heads(){let t=$i(this.field.value),e=t&&!this.known(t)?{kind:"add",source:t}:{kind:"new"};return[this.row(e,e.kind==="new"),this.row({kind:"search"})]}searchHeads(){let t=$i(this.query.value),e=t&&this.listing?.marketplaces.some((n)=>lr(n.source,t));return[this.row({kind:"back"},!0),...t&&!e&&!this.known(t)?[this.row({kind:"add",source:t})]:[]]}matches(){let t=this.query.value.trim();return(this.listing?.marketplaces??[]).filter((e)=>!t||Jp(e,t))}found(){let t=this.matches();if(t.length>0)return t.map((e)=>this.row({kind:"listed",listed:e}));return $i(this.query.value)&&!this.loading?[]:[this.row({kind:"state"})]}lit(t,e){return`${t?`${R.gutter} `:" "} ${e}`}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)?"Update failed":"")}about(t,e,n){let r=this.marketplaceNamed(t),i=e.filter((c)=>this.installed.has(c.name)).length,s=e.filter((c)=>this.picked.has(c.name)&&!this.installed.has(c.name)).length,o=e.filter((c)=>this.installed.has(c.name)&&!this.picked.has(c.name)).length,a=[...r&&n!==void 0?[`${n} of ${r.entries.filter((c)=>!c.default).length} match`]:[],...r&&n===void 0?[`${r.entries.filter((c)=>!c.default).length} available`]:[],...i>0||!r?[`${i} installed`]:[],...s>0?[`${s} to install`]:[],...o>0?[`${o} to remove`]:[],...r&&r.source!==J&&!(this.adds.has(r.source)&&wt(r.source))?[GS(r.status)]:[]];return{added:r!==void 0&&!this.removes.has(r.source),lines:[this.p.dim(r?tg(r.source):"Not added"),this.p.dim(a.join(" · "))]}}badge(t){let e=this.marketplaceNamed(t);if(!e)return"";return[wt(e.source)&&(this.want.get(e.source)??e.auto)?`${R.auto} auto-update`:"",this.status(e)].map((r)=>r?` ${this.p.dim(r)}`:"").join("")}peeking(t){let e=this.peeked.get(t);return e?_t(e.entries.filter((n)=>!n.default).length):""}foundLine(t,e,n){let r=(u)=>ws(n,"box",`${u} `),i=(u)=>u?` ${this.p.dim(u)}`:"";if(t.kind==="new"){let u=$i(this.field.value),f=u?this.known(u):void 0,l=f?`${f.id} is already added`:"type owner/repo or a folder";return this.lit(e,`${r("+")}Add marketplace${i(l)}`)}if(t.kind==="add"){let u=this.failed.get(t.source)??this.peekFailed.get(t.source),f=this.peeked.get(t.source),l=u?` ${this.p.error(u)}`:i(this.busy.get(t.source)??(f?`${f.id} · ${this.peeking(t.source)}`:this.live?"Fetching its palettes…":"space fetches its palettes"));return this.lit(e,`${r("+")}Add ${tg(t.source)}${l}`)}if(t.kind==="search")return this.lit(e,`${r(R.search)}Search marketplace${i("find one on GitHub")}`);if(t.kind==="back")return` ${ws(n,"box",Ju(this.p,"← Back",e))}
675
+ `;if(t.kind==="state"){let[u,f]=this.stateOf();return this.lit(e,`${r(R.search)}${u}${i(f)}`)}let s=t.listed,o=this.known(s.source),a=this.failed.get(s.source),c=[`${R.star}${s.stars}`,o?this.addedNote(o):_t(s.palettes.length),this.busy.get(s.source)??""].filter(Boolean);return this.lit(e,`${r(o?R.on:R.off)}${s.id}${i(c.join(" · "))}${a?` ${this.p.error(a)}`:""}`)}stateOf(){let t=this.query.value.trim();return this.loading?["Loading the marketplace list…",""]:this.loadError?["The marketplace list did not load","space retries"]:!this.listing?["Load the marketplace list","space loads it"]:t?[`No marketplace matches "${t}"`,""]:["No marketplace yet",""]}addedNote(t){return this.adds.has(t.source)?"Will add":"Added"}changes(){return this.adds.size+this.removes.size+this.want.size}dirty(){let{picked:t,renew:e}=this.result();return this.changes()>0||e.length>0||t.size!==this.installed.size||!t.isSubsetOf(this.installed)}mark(t){let e=this.tuned.has(t.name)?` ${this.p.warn(R.on)}`:"";if(!this.updates.has(t.name)||!this.installed.has(t.name))return e;return`${e}${this.renew.has(t.name)?` ${this.p.bold(`${R.update} update`)}`:` ${this.p.dim(R.update)}`}`}toggleRenew(){let t=this.inside,e=t.focusedRow(),n=(e?t.inside(e):[]).map((i)=>i.name).filter((i)=>this.updates.has(i)&&this.installed.has(i));if(n.length===0)return;let r=n.some((i)=>!this.renew.has(i));for(let i of n)if(r)this.renew.add(i);else this.renew.delete(i)}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:vc(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(tf,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(`
676
+ `)),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))}}marketplaceChanges(){let t=[];for(let e of this.adds.values()){let n=e.source!==J&&(this.want.get(e.source)??e.auto)?"updates on its own":"";t.push(`+ ${e.id} ${this.p.dim([e.source===J?"The official marketplace":e.shown,_t(e.entries.filter((r)=>!r.default).length),n].filter(Boolean).join(" · "))}`)}for(let e of this.removes){let n=this.marketplaces.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.p.dim([n?.shown??st(e),r.length>0?`its ${_t(r.length)} installed keep working`:""].filter(Boolean).join(" · "))}`)}for(let[e,n]of this.want){let r=this.marketplaces.find((i)=>i.source===e);if(r&&!this.removes.has(e))t.push(`${R.auto} ${r.id} ${this.p.dim(n?"updates on its own from now":"stops updating on its own")}`)}return t}reviewLines(){let t=this.marketplaceChanges(),{names:e,dropped:n}=this.pending(),r=new Set(this.result().renew),i=this.entries().filter((c)=>r.has(c.name)),s=Math.max(0,...[...e,...n,...i].map((c)=>c.name.length)),o=(c,u)=>` ${c} ${u.name.padEnd(s)} ${this.p.dim(u.catalog??"")}`,a=[e.length>0?`${e.length} to install`:"",n.length>0?`${n.length} to remove`:"",i.length>0?`${i.length} to update`:""].filter(Boolean);return[...t.length>0?[` ${this.p.bold("Marketplaces")} ${this.p.dim(`(${t.length})`)}`,...t.map((c)=>` ${c}`),""]:[],...a.length>0?[` ${this.p.bold("Palettes")} ${this.p.dim(`(${a.join(" · ")})`)}`,...e.map((c)=>o("+",c)),...n.map((c)=>o("-",c)),...i.map((c)=>o(R.update,c))]:[]]}summary(){let{names:t,dropped:e}=this.pending(),n=this.adds.size;return[n>0?`${n} marketplace${n===1?"":"s"} added`:"",this.removes.size>0?`${this.removes.size} removed`:"",t.length>0?`${t.length} installed`:"",e.length>0?`${e.length} removed`:"",this.result().renew.length>0?`${this.result().renew.length} updated`:""].filter(Boolean).join(" · ")}progressLines(){let t=this.log.map((e)=>` ${e}`);if(this.phase==="applying"){let e=mr[this.beat%mr.length];t.push(` ${this.p.dim(`${e} ${this.working||"Working…"}`)}`)}else if(this.stopped)t.push("",...vt(this.stopped.message,Math.max(20,this.columns()-6)).map((e,n)=>` ${n===0?this.p.error(R.miss):" "} ${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.p.bold("Review changes")}`:this.phase==="applying"?this.p.bold("Applying changes"):this.stopped?`${this.p.error(R.miss)} ${this.p.bold("Stopped")}`:`${this.p.bold(`${R.ok} Applied`)} ${this.p.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),f=i.length-c-u.length,l=[c>0?` ${this.more(-1,`↑ ${c} more`)}`:"",...u];while(l.length<o+1)l.push("");l.push(f>0?` ${this.more(1,`↓ ${f} 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?[tt(sm(this.hub,this.color),n,!1)]:[],tt(` ${s}`,n,!1),...l.map((m)=>tt(m,n,!1)),` ${this.keyBar(h,n-1)}`].slice(0,e).join(`
677
+ `)}keyBar(t,e){let n=`${Ve(this.p,t.badge)}${this.color?" ":" "}`,r=([a,c])=>oy(this.p,a,c),{note:i,keys:s,right:o}=t;for(;;){let a=`${n}${[t.lead??"",i?this.p.dim(i):"",...s.map(r)].filter(Boolean).join(" ")}`,c=o?r(o):"";if(B(a)+(o?3+B(c):0)<=e)return o?Nt(a,c,e):tt(a,e,!1);if(i)i=void 0;else if(s.length>2||!o&&s.length>1)s=s.toSpliced(-2,1);else if(o)o=void 0;else return tt(a,e,!1)}}more(t,e,n){return this.p.dim(pn({kind:"page",step:t,...n?{pane:n}:{}},e))}counts(){if(this.showing==="search"){let n=[...this.loading?["Loading…"]:[],...this.listing?[`${this.matches().length} found`]:[],...this.listing?.offline?[`offline, from ${Do(this.listing.at)}`]:[]];return n.length>0?n.join(" · "):"on GitHub"}let t=this.busy.values().some((n)=>n==="Updating…")?"Updating… · ":"",e=this.list;return`${t}${e.matched()}/${e.total()} · ${e.pickedCount()} picked`}searchText(){let t=(this.showing==="search"?this.query:this.field).value;if(t)return`${t}_`;if(this.showing==="search")return this.p.dim("Search… a marketplace, a palette, or type owner/repo or a folder");let e=this.hint.text();return this.p.dim(`Search…${e?` e.g. ${e}`:""}`)}heading(){let t=this.showing==="search"?"Search marketplace":"Browse";return`${this.p.bold(t)} ${this.p.dim(`(${this.counts()})`)}`}searchBox(t){let e=(r,i)=>this.p.dim(`${r}${"─".repeat(t-2)}${i}`),n=this.p.dim("│");return[e("╭","╮"),`${n} ${tt(`${this.p.dim(R.search)} ${this.searchText()}`,t-4)} ${n}`,e("╰","╯")]}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",i=e&&n&&this.updates.has(t.name)?this.renew.has(t.name)?" · Will update":" · Update ready":"";return`${r}${i}${this.startup===t.name?" · Default":""}`}detail(t){let e=this.current().focusedRow();if(e?.kind==="extra")return e.extra.found?this.foundDetail(e.extra.found,t):BS;if(e?.kind!=="top")return BS;let n=this.marketplaceNamed(e.name);if(n)return this.marketplaceDetail(n,t);let r="In no marketplace you added — its installed palettes stay";return{title:this.p.bold(e.name),lines:vt(r,t),brief:r}}foot(t){let e=this.inside.focusedRow();if(e?.kind==="catalog"){let c=this.inside.inside(e),u=c.filter((f)=>this.installed.has(f.name)).length;return[`${this.p.bold(e.name)}${e.native?` ${this.p.dim(e.native)}`:""}`,this.p.dim(`${_t(c.length)} · ${u} installed`),""]}if(e?.kind!=="palette")return["","",""];let n=e.entry,r=Ja(n),i=`Gate ${Te.length-r.length}/${Te.length}`,s=n.pictures?.length??0,o=[...s>0?[`${s} picture${s===1?"":"s"}`]:[],...n.base?[`Base ${n.base}`]:[]].join(" · "),a=r.length>1?` · +${r.length-1}`:"";return[`${this.color?this.p.bold(`${pr(n.cursor)}${n.name}${kt}`):n.name} ${this.p.dim(this.paletteState(n))}`,r[0]===void 0?this.p.dim(`${i} · passes`):`${i} · ${this.p.bold(R.miss)} ${r[0]}${a}`,tt(this.p.dim(o),t)]}marketplaceDetail(t,e){let r=t.entries.filter((a)=>!a.default).filter((a)=>this.installed.has(a.name)).map((a)=>a.name),i=wt(t.source)?`Auto-update ${this.want.get(t.source)??t.auto?"on":"off"}`:GS(t.status),s=this.failed.get(t.source),o=this.adds.has(t.source)?["Will add"]:this.removes.has(t.source)?[r.length>0?`Will remove — ${r.join(", ")} stay${r.length===1?"s":""} installed`:"Will remove"]:this.want.has(t.source)?[`Auto-update turns ${this.want.get(t.source)?"on":"off"}`]:[];return{title:this.p.bold(t.id),lines:[...t.description?[...vt(t.description,e).map((a)=>this.p.dim(a)),""]:[],wt(t.source)?`${i} ${this.p.dim("⇧←→")}`:i,...s?vt(s,e).map((a)=>this.p.error(a)):[],...o.length>0?["",...o.flatMap((a)=>vt(a,e))]:[]],brief:[i,...o].join(" · ")}}foundDetail(t,e){if(t.kind==="new")return{title:this.p.bold("Add marketplace"),lines:[...vt("Type owner/repo, owner/repo#ref or a folder into the search, and space adds it",e),"",...vt("Or find one on GitHub with Search marketplace",e)],brief:"Type owner/repo, owner/repo#ref or a folder into the search, and space adds it"};if(t.kind==="search"){let s=`The marketplaces anyone publishes on GitHub with the ${Ji} topic, listed every half hour`;return{title:this.p.bold("Search marketplace"),lines:[...vt(s,e),"",...vt("enter opens the search",e)],brief:"enter searches the marketplaces on GitHub"}}if(t.kind==="back")return{title:this.p.bold("Back"),lines:["Back to your marketplaces"],brief:"enter goes back"};if(t.kind==="add"){let s=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.p.bold(tg(t.source)),lines:["Not added",...this.peekLines(t.source,e),"",...vt(s,e)],brief:[this.peeking(t.source),s].filter(Boolean).join(" · ")}}if(t.kind==="state"){let[s,o]=this.stateOf(),a=`Repositories with the ${Ji} topic, read every half hour into one list`;return{title:this.p.bold("Marketplaces"),lines:[...vt(a,e),"",...vt([s,o].filter(Boolean).join(" · "),e),...this.loadError?vt(this.loadError,e).map((c)=>this.p.error(c)):[],"",...vt("Type owner/repo or a folder to add one",e)],brief:[s,o].filter(Boolean).join(" · ")}}let n=t.listed,r=this.known(n.source),i=r?this.addedNote(r):this.busy.get(n.source)??this.failed.get(n.source)??"space adds it, enter adds it and goes back";return{title:this.p.bold(n.id),lines:[this.p.dim(n.source),...vt(n.about,e).map((s)=>this.p.dim(s)),this.p.dim([`★ ${n.stars}`,...n.updated?[`updated ${n.updated}`]:[]].join(" · ")),"",...vt(i,e),"",...this.paletteLines(n,e)],brief:[_t(n.palettes.length),i].join(" · ")}}paletteLines(t,e){let n=Math.min(Math.max(...t.palettes.map((i)=>B(i.name))),Math.max(8,e-16)),r;return t.palettes.flatMap((i)=>{let s=i.catalog!==r&&i.catalog?[this.p.dim(i.catalog)]:[];r=i.catalog;let o=this.color?` ${qu(lo(i))}`:"";return[...s,` ${tt(i.name,n)}${o}`]})}peekLines(t,e){let n=this.peeked.get(t);if(!n)return[];let r=n.entries.filter((s)=>!s.default),i=`${r.slice(0,_S).map((s)=>ne(s.name)).join(", ")}${r.length>_S?", …":""}`;return["",n.id,...n.description?vt(n.description,e):[],_t(r.length),...vt(i,e).map((s)=>this.p.dim(s))]}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"]};if(this.showing==="search")return{badge:"SEARCH",keys:[...this.searchKeys(),...this.query.value?[["bksp","edit"]]:[],["?","keys"]],right:this.query.value?["esc","clear search"]:["esc","back"]};let t=this.field.value,e=["enter",this.dirty()?"apply":"close"],n=[...t?[["bksp","edit"]]:[],["?","keys"]];return{badge:t?"BROWSE (FILTER)":"BROWSE",keys:[...this.side==="panel"?this.panelKeys(e):this.cardKeys(e),...n],right:t?["esc","clear filter"]:this.side==="panel"?["esc","back"]:["esc","cancel"]}}panelKeys(t){let e=this.inside,n=e.focusedRow();if(n?.kind==="catalog"&&e.foldable())return[n.expanded?["←","close"]:["→","open"],["space","pick"]];let r=n?.kind==="palette"&&this.updates.has(n.entry.name)&&this.installed.has(n.entry.name);return[["space","pick"],...r?[["ctrl+r",this.renew.has(n.entry.name)?"keep":"update"]]:[],t]}searchKeys(){let t=this.focusedFound();if(t?.kind==="back")return[["enter","back"]];if(t?.kind==="state")return this.loading?[]:[["space","load"]];let e=t?.kind==="add"?t.source:t?.kind==="listed"?t.listed.source:void 0;if(e===void 0)return[];let n=this.known(e);if(!n)return[["space","add"],["enter","add and go back"]];return[...this.adds.has(n.source)?[["space","undo"]]:[],["enter","go to it"]]}cardKeys(t){let e=this.list.focusedRow();if(e?.kind==="extra"){let o=e.extra.found;if(o?.kind==="search")return[["enter","open"]];return o?.kind==="add"?[["space","add"],t]:[t]}if(e?.kind!=="top")return[t];let n=this.inside.size()>0?[["→","open"]]:[],r=this.focusedMarketplace();if(!r)return[...n,["space","pick"]];let i=wt(r.source),s=this.adds.has(r.source)||this.removes.has(r.source);return[...n,["space","pick"],...i?[["⇧←→","auto-update"]]:[],...i&&!this.adds.has(r.source)?[["ctrl+r","update"]]:[],["del",s?"undo":"remove"]]}columns(){return(this.output??process.stdout).columns??100}rows(){return(this.output??process.stdout).rows??24}fitItems(t){let e=Math.max(tf,this.rows()-t);this.maxItems=e,this.list.maxItems=e,this.results.maxItems=e}view(){let t=this.draw().split(`
678
+ `);return Array.from({length:this.rows()},(e,n)=>t[n]??"")}small(t,e,n){return`Needs ${CS}×${n} — now ${t}×${e}
679
+ ${this.p.dim("esc cancels")}`}draw(){let t=this.columns(),e=this.rows();if(t<CS||e<jS)return this.small(t,e,jS);if(this.phase!=="browse")return this.frame(t,e);this.follow();let n=t>=l8,r=t-1,i=e>=f8?[` ${this.heading()}`,...this.searchBox(t-3).map((d)=>` ${d}`)]:[Nt(` ${this.p.dim(R.search)} ${this.searchText()}`,this.p.dim(this.counts()),r)],s=i.length+3+(n?0:1)+(this.hub?1:0);if(e<s+tf)return this.small(t,e,s+tf);this.fitItems(s);let o=this.current().window(),a=(d)=>So(d).flatMap((h)=>h.sequence?[]:[h.text]).join("").trimEnd(),c=Math.max(0,...o.lines.map((d)=>B(a(d))+3)),u=n?Math.min(c8,r-u8-1,Math.max(a8,c)):r;this.split=n?u+1:0;let f=!n&&this.side==="panel"?this.panel(r-1,this.maxItems+3).map((d)=>` ${d}`):this.cards(o,n,u,r),l=[...this.hub?[tt(sm(this.hub,this.color),r,!1)]:[],...i.map((d)=>tt(d,r,!1)),...f,` ${this.keyBar(this.footer(),r-1)}`];return(this.help?this.helpBox(l,t,e,l.length-f.length-1):l).join(`
680
+ `)}cards({lines:t,above:e,below:n},r,i,s){let o=t.map((u)=>` ${u}`);while(o.length<this.maxItems)o.push("");let a=[e>0?` ${this.more(-1,`↑ ${e} more`)}`:"",...o,n>0?` ${this.more(1,`↓ ${n} more`)}`:""];if(!r)return[...a.map((u)=>tt(u,i,!1)),tt(` ${this.p.dim(this.detail(i-2).brief)}`,i,!1)];let c=this.panel(s-i-1,a.length);return a.map((u,f)=>`${tt(u,i)} ${c[f]??""}`)}panel(t,e){let n=this.side==="panel",r=(b)=>n?this.p.accent(b):this.p.dim(b),i=t-4,s=(b)=>`${r("│")} ${tt(b,i)} ${r("│")}`,o=this.detail(i),a=n?this.p.accent(o.title):o.title,c=e-2;if(this.current().focusedRow()?.kind!=="top"){let b=o.lines.length>c?[...o.lines.slice(0,c-1),this.p.dim("…")]:o.lines.slice(0);while(b.length<c)b.push("");return[this.edge(t,"top",a,"",n),...b.map(s),this.edge(t,"bottom","","",n)]}let u=n?this.foot(i):[],f=o.lines.slice(0,Math.max(0,c-2-(u.length>0?u.length+1:0)));this.inside.maxItems=Math.max(1,c-f.length-1-(u.length>0?u.length+1:0));let{lines:l,above:d,below:h}=this.inside.window(),m=this.inside.size()>0?l:[this.p.dim(" No palettes yet")];while(m.length<this.inside.maxItems)m.push("");let p=h>0?this.more(1,`↓ ${h} more`,"panel"):"";return[this.edge(t,"top",a,"",n),...f.map(s),s(d>0?this.more(-1,`↑ ${d} more`,"panel"):""),...m.map(s),...u.length>0?[this.edge(t,"mid","",p,n),...u.map(s)]:[],this.edge(t,"bottom","",u.length>0?"":p,n)]}edge(t,e,n,r,i){let s=(l)=>i?this.p.accent(l):this.p.dim(l),[o="",a=""]=[...Gt(2,e)],c=n?` ${tt(n,t-8,!1)} `:"",u=r?` ${r} `:"",f=Math.max(0,t-3-B(c)-B(u)-(r?1:0));return`${s(`${o}─`)}${c}${s("─".repeat(f))}${u}${s(`${r?"─":""}${a}`)}`}helpRows(){if(this.showing==="search")return[["Move","↑↓ home end pgup pgdn"],["Filter","Any text · bksp · ctrl-u clears"],["Add","space adds it · again to undo"],["","enter adds it and goes back to its card"],["Reload","ctrl+r the list, which GitHub fills every half hour"],["Back","← esc · ← Back"],...this.hub?[["Screens","tab · shift+tab"]]:[],["Close","? esc"]];return[["Move","↑↓ home end pgup pgdn"],["Open","→ enter · a marketplace into the panel, a catalog"],["Back","← esc · from the panel to the marketplaces"],["Pick","space · a palette, a catalog, a marketplace"],["Filter","Any text · bksp · ctrl-u clears"],["Marketplace","⇧←→ auto-update · ctrl+r updates it"],["","del removes it · again to undo"],["Add","owner/repo or a folder typed in · space adds it"],["Search","enter on Search marketplace · finds one on GitHub"],["Update","ctrl+r on a palette marked ↑"],["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.max(...i.map(([l])=>l.length))+3,o=Math.min(e-2,6+s+Math.max(...i.map(([,l])=>B(l)))),a=Math.floor((e-o)/2),c=`│${" ".repeat(o-2)}│`,u=[`╭─ Help ${"─".repeat(o-9)}╮`,c,...i.map(([l,d])=>`│${tt(` ${this.p.bold(l.padEnd(s))}${d}`,o-4)} │`),c,`╰${"─".repeat(o-2)}╯`],f=Math.max(0,Math.min(Math.max(r,Math.floor((n-u.length)/2)),n-1-u.length));return t.map((l,d)=>{let h=u[d-f];return h===void 0?l:`${ty(l,a)}${h}`})}}import{existsSync as H6}from"node:fs";import{existsSync as Zc,mkdirSync as b6,readFileSync as ob}from"node:fs";import{dirname as w6}from"node:path";class we extends Error{}import{closeSync as L5,mkdtempSync as C5,openSync as j5,readSync as _5,rmSync as fM}from"node:fs";import{homedir as B5,tmpdir as G5}from"node:os";import{join as dM}from"node:path";import{readFileSync as h8}from"node:fs";var Et={pitch:25,cols:22,rows:9,height:13},ks={cols:25,rows:21},Pe={cols:10,rows:3,pitch:12,top:4},Oe=Pe.top+Pe.rows+1,m8=1073741824,ag=2147483648,p8=-1073741826,g8=1600,b8=56,w8=4,US=20,$8=50,WS=[["space","unfolds a set of ×N"],["o","opens the artwork 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 cg(t){return Math.max(0,Math.floor((t-1)/Pe.pitch))}function Mr(t,e){let n=e-Oe-2;return{perRow:Math.max(1,Math.floor((t-1)/Et.pitch)),rowsVis:Math.max(1,Math.floor(n/Et.height)),height:n}}function sf(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=h8(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 ZS(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 ug(t){return`\x1B_Ga=d,d=i,i=${t},p=${t},q=2\x1B\\`}function Ic(t){return`\x1B_Ga=d,d=I,i=${t},q=2\x1B\\`}var Tt=$t("bold"),K=$t("dim"),xc=$t("ok"),qn=$t("warn"),Ec=pr,rf=Zh,rg=!1;function of(t){return rg=!0,t.beat}function ea(t){return mr[of(t)%mr.length]}function Mt(t){return B(t)}function ig(t,e){if(B(t)<=e)return t;let n="";for(let r of t){if(B(n+r)>e)break;n+=r}return n}function ki(t){return Xi(t)}function lg(t){return`${$t("reverse")}${Xi(t)}`}function yi(t,e,n,r){return n?[[`${R.link} `,r,void 0,{kind:"link",url:n}],[t,e,n]]:[[t,e]]}function ng(t){let e=nm(t);return e?{kind:"key",key:e}:void 0}function ys(t){return t.reduce((e,[n])=>e+Mt(n),0)}function k8(t,e){let n=[],r=e;for(let[i,s,o,a]of t){let c=Mt(i);if(c<=r){n.push([i,s,o,a]),r-=c;continue}n.push([`${ig(i,r)}…`,s,o,a]);break}return n}class nf{parts=[];cols;constructor(t){this.cols=t}put(t,e,n="",r,i){let s=e.replace(/\p{Cc}/gu,"");return this.parts.push({col:t,text:s,sgr:n,...r?{link:r}:{},...i?{spot:i}:{}}),t+Mt(s)}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?Mt(ig(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-ys(e),e)}center(t,e){this.run(Math.floor((t-ys(e))/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=ig(n,this.cols-e);t+=`\x1B[${e+1}G${r}${Du(o,i)}${r?Se:""}`}return t}}function y8(t){return t.replace(/_\([^)]*\)?$/,"")}function XS(t){return[`${t.reduced?"↓":""}${t.width}×${t.height}`,Math.max(t.width,t.height)<g8?qn:K]}function Oc(t,e,n){let r=[...n.keys??[]],i=n.lead,s=n.right,o=()=>{let u=[...i?[ys(i)]:[],...r.map(([l,d])=>Mt(l)+1+Mt(d))];return(n.badge?Mt(n.badge)+4:0)+u.reduce((l,d)=>l+d,0)+3*Math.max(0,u.length-1)+(s?3+Mt(s[0])+1+Mt(s[1]):0)};while(o()>e)if(r.length>2)r.splice(-2,1);else if(s)s=void 0;else if(r.length>1)r.splice(-2,1);else break;if(i&&o()>e)i=k8(i,Math.max(0,ys(i)-(o()-e)-1));let a=0;if(n.badge)a=t.put(0,` ${n.badge} `,$t("pill"))+2;if([...i?[i]:[],...r.map(([u,f])=>[[u,Tt,void 0,ng(u)],[` ${f}`,K,void 0,ng(u)]])].forEach((u,f)=>{a=t.run(a+(f?3:0),u)}),s){let u=ng(s[0].split(" ")[0]??"");t.right(e,[[s[0],Tt,void 0,u],[` ${s[1]}`,K,void 0,u]])}}function v8(t,e){if(t==="d")return K;if(t==="b")return Tt;if(t==="s")return rf(e.colors.selection);if(t==="c")return rf(e.colors.cursor);let n=/^([BK]?)(\d+)$/.exec(t);if(!n)return"";let r=Number(n[2]);if(n[1]==="K")return`${Xi(0)}${Vk(r)}`;return`${n[1]==="B"?Tt:""}${Xi(r)}`}function S8(t,e,n,r,i){let s=Vt.indexOf(ts(r.scene)),o=Vt.flatMap((c,u)=>[...u?[[" ",""]]:[],[c.name,u===s?Tt+i:K,void 0,{kind:"scene",scene:u}]]),a=ys(o)<=n;t?.run(e,a?o:[[ts(r.scene).name,Tt+i],[` ${s+1}/${Vt.length}`,K]])}function E8(t,e,n,r,i,s,o){let{ansi:a,cursor:c}=s.colors;S8(t[e-2],n,r,s,o);let u=r<Fy?3:4;if(r>=56)u=Math.min(7,Math.floor((r+1)/8)-1);let f=n;for(let d=0;d<8;d++)f=(t[e]?.put(f,"▀".repeat(u),Ec(a[d]??c)+rf(a[d+8]??c))??f)+1;let l=e+2;for(let d of ts(s.scene).lines){let h=Mo(d,r);if(!h)continue;if(l>i)return;t[l]?.run(n,h.map(([m,p])=>[m,v8(p,s)])),l++}}function M8(t,e,n){let r=[[]];for(let o of t){let a=r[r.length-1];if(a.length===0||Mt([...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&&Mt([...s,`+${t.length-i}`].join(" "))>e)s.pop(),i--;if(i<t.length)s.push(`+${t.length-i}`);return r.flatMap((o)=>o.length>0?[o.join(" ")]:[])}function KS(t){return t.replace(/^https?:\/\/(?:www\.)?/,"")}function x8(t,e,n){return t.flatMap((r,i)=>[...i>0?[[" ",""]]:[],[r,""],...(e[r]??[]).flatMap((s)=>[[" ",""],...yi(s.kind,"",s.url,n)])])}function O8(t,e,n,r,i){let s=r.info,o=s?.artists??[],a=ki(r.tiles[r.focus]?.siteAnsi??r.siteAnsi);[["Post",s?.page?yi(KS(s.page),"",s.page,a):[["—",K]]],["Source",s?.source?yi(KS(s.source),"",s.link,i):[["—",K]]],["Artist",o.length>0?x8(o,s?.profiles??{},i):[["—",K]]]].forEach(([u,f],l)=>{t[e+l]?.put(n,u,K),t[e+l]?.run(n+12,f)})}function P8(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,f=Math.max(12,r-12),l=[`${a.width}×${a.height}${o.ext?` ${o.ext.toUpperCase()}`:""}`,...c?[_l(c.bytes)]:[]].join(" · "),d=[o.rating??"—",a.score>0?`★${a.score}`:"",o.posted??""].filter(Boolean).join(" · "),h=(b,$)=>b.length>0?M8(b,f,$).map((k)=>[[k,""]]):[[["—",K]]],m=[["Characters",h(o.characters,2)],["Series",h(o.series,1)],["Tags",h(o.tags,3)],["Rating",[[[d,d==="—"?K:""]]]],["File",[[[l,""],...c?[[" ",""]]:[],...c?QS(c):[]]]],["Uploader",[[o.uploader?[o.uploader,""]:["—",K]]]]],p=e;for(let[b,$]of m){if(p+$.length-1>i)return;t[p]?.put(n,b,K);for(let k of $)t[p]?.run(u,k),p++}}var I8=["Size","Position","Opacity"],R8=[0,3,6];function A8(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 N8(t){return t.toFixed(2)}function T8(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,Tt+s],[" Background",K],...a?[[" · ",K],...yi(`${a.site} ${a.id}`,K,a.page||void 0,ki(a.siteAnsi))]:[]]);let c=Math.max(8,r-n-21),u=20,f=Math.max(100,o.fill);for(let[l,d]of I8.entries()){let h=e+R8[l],m=o.field===l,p=m?Tt:K;if(m)t[h]?.put(n,"▶",s,void 0,{kind:"field",field:l});t[h]?.put(n+2,d,p,void 0,{kind:"field",field:l});let b;if(l===1){for(let $=1;$<=9;$++){let k=$===i.tune.at,v=t[e+2+Math.floor(($-1)/3)],S=n+12+($-1)%3*3;v?.mark(S-1,3,{kind:"place",at:$}),v?.put(S,k?"■":"·",k?Tt+s:K)}b=Jt[i.tune.at-1]??"center"}else{let $;if(l===0){let{size:k}=i.tune;$=k==="fill"?c-1:Math.floor((k-u)*(c-1)/(f-u+1)),b=k==="fill"?"fill":`${k}%`}else $=Math.floor(Math.round(i.tune.opacity*100)*(c-1)/100),b=N8(i.tune.opacity);$=Math.max(0,Math.min(c-1,$)),t[h]?.run(n+12,[["━".repeat($),s],["●",Tt],["─".repeat(c-1-$),K]]),t[h]?.mark(n+12,c,{kind:"track",field:l})}if(t[h]?.right(r-2,[[b,p]]),A8(i,l))t[h]?.put(r-1,"↺",m?Tt+s:K)}}function H8(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 sg(t,e=t.site,n=t.siteAnsi){return[` ${e} `,lg(n)]}function Mc(t){return`${Z[Math.floor(t/zr)]?.name??"local"} ${t%zr}`}function Sc(t,e,n){let r=Z[Math.floor(e/zr)],i=Mc(e),s=t.indexOf(i);if(!r||s===-1)return[[t,n]];return[[t.slice(0,s),n],...yi(i,n,r.pageUrl(e%zr),ki(r.ansi)),[t.slice(s+i.length),n]].filter(([a])=>a!=="")}function F8(t,e,n){let r=[{name:"all",moved:!1},...Z].flatMap((s,o)=>{let a=`${s.name}${s.moved?"*":""}`,[c,u]=s.name===n.site?sg(n,a):[` ${a} `,K],f=[c,u,void 0,{kind:"site",tab:o}];return o?[[" ",""],f]:[f]}),i=ys(r)<=e;t.run(0,i?r:[sg(n)])}function L8(t,e,n,r){if(n.chips.length===0)return;let i=[["tags ",K]],s=Mt("tags "),o=n.chips.length;for(let[a,c]of n.chips.entries()){let u=` ${a+1} ${c.name} `;if(s+Mt(u)+1>e-2)break;i.push([u,c.on?`${$t("reverse")}${r}`:K,void 0,{kind:"chip",index:a}],[" ",""]),s+=Mt(u)+1,o--}if(o>0)i.push([`+${o}`,K]);t.run(0,i)}function C8(t,e,n,r,i){t[Oe-1]?.put(0,"─".repeat(n-1),K);let s=t[Pe.top-1],o=cg(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 f=c*Pe.pitch,l=u.up?Tt:"";if(s.run(f+1,u.page?yi(String(u.id),l,u.page,ki(u.ansi)):[["● ",ki(u.ansi)],[String(u.id),l]]),u.up)for(let d=0;d<Pe.rows;d++)t[Pe.top+d]?.put(f,"▌",i);if(u.thumb)e.push({id:m8+c,path:u.thumb,row:Pe.top,col:f+1,cols:Pe.cols,rows:Pe.rows,z:-1})}if(a<r.held.length)s.put(a*Pe.pitch+1,`+${r.held.length-a}`,K)}function j8(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"}`,K);return}let i=t.run(0,[["⌕ ",r,void 0,{kind:"query"}],[n.tag||"Nothing yet — / searches, ctrl+v pastes a picture",n.tag?"":K,void 0,{kind:"query"}]]),s=Fi.filter((c)=>!n.block.includes(c)),o=Z.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(" ")}`,K),n.total>0||!n.searching){let c=[[`${n.tiles.length}/${n.checked}`,""]];if(n.checked<n.total)c.push([` of ${n.total}`,K]);t.right(e,c)}}function QS(t){if(t.cut==="on")return[[`Cut out · ${t.clear}% transparent`,xc]];if(t.cut==="off")return[["Opaque · x cuts out",qn]];if(t.cut==="failed")return[["Opaque · no cut-out",qn]];return[t.clear>0?[`${t.clear}% transparent`,xc]:["Opaque",qn]]}function zS(t){return t.site==="all"?"any site":t.site}function og(t,e){if(t.installing!==void 0)return Sc(`${ea(t)} Installing ${t.palette} ← ${Mc(t.installing)}`,t.installing,qn);if(t.hint)return[[t.hint,xc]];if(t.error)return[[t.error,qn]];if(t.waiting!==void 0)return[[`${t.slow??t.site} asked to slow down · ${t.waiting}s`,qn]];if(t.fetching){let{id:n,got:r,size:i}=t.fetching;return Sc(`${ea(t)} Fetching ${Mc(n)} · ${Bl(r,i)}`,n,qn)}if(t.cutting!==void 0)return Sc(`${ea(t)} Cutting out ${Mc(t.cutting)}`,t.cutting,qn);if(t.preparing!==void 0)return Sc(`${ea(t)} Preparing ${Mc(t.preparing)}`,t.preparing,qn);if(e)return[e];if(t.saved)return Sc(t.saved.text,t.saved.key,xc);if(t.note)return[[t.note,K]];return}function tE(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 eE(t,e){return t.ranking?`${e}${t.ranking.done}/${t.ranking.total}`:""}function _8(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,f=Math.max(6,Math.round(n*0.22)),l=of(r)%(US*2)/US,d=Math.round((n-f)*(0.5-0.5*Math.cos(Math.PI*(l<1?l:2-l)))),h=Ht(s,o,i),m=Ht(s,Ht(a,s,0.15),i),p=Array.from({length:n},($,k)=>{let v=(u>=0?k<u:k>=d&&k<d+f)?h:m;return k===0||k===n-1?Ht(v,s,0.55):v}),b=0;for(let $=1;$<=n;$++)if($===n||p[$]!==p[b])t?.put(e+b," ".repeat($-b),rf(p[b])),b=$}function B8(t,e,n,r,i){let{background:s,foreground:o}=i.colors,a=i.loaderFrom===void 0?0:Math.min(1,(of(i)-i.loaderFrom)/w8),c=e+(n>=5?Math.floor((n-5)/2):0);t[c]?.center(r,[[tE(i),Tt+Ec(Ht(s,o,a))],[eE(i," "),Ec(Ht(s,Ht(o,s,0.45),a))]]);let u=Math.min(b8,r-8);if(_8(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:f,arrived:l},d)=>[...d?[[" · ",Ec(Ht(s,o,0.25*a))]]:[],[f,Ec(Ht(s,l?Ht(o,s,0.2):o,l?a:0.32*a))]]))}function G8(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[Oe+c]?.put(e-1,u?"┃":"│",u?s:K)}}function U8(t,e,n){if(e)return[`${ea(t)} ${tE(t)}${eE(t," · ")}`,K];let r=n.filter((s)=>!s.missing),i=r.filter((s)=>s.thumb).length;return i<r.length?[`${ea(t)} Loading thumbnails · ${i}/${r.length}`,K]:void 0}function W8(t,e,n,r,i,s,o){let{perRow:a,rowsVis:c,height:u}=Mr(r,i);j8(t[0],r,s,o),F8(t[1],r,s),L8(t[2],r,s,o),C8(t,e,r,s,o);let f=t.map((C,I)=>I>=Oe&&I<Oe+u?C:void 0),l=Math.floor(s.scroll/Et.height),d=Math.floor((s.scroll+u-1)/Et.height),h=[];for(let C=l;C<=d;C++){let I=Oe+C*Et.height-s.scroll;for(let j=0;j<a;j++){let U=C*a+j,G=j*Et.pitch,L=s.tiles[U];if(!L)continue;h.push(L);let gt=Math.max(I,Oe),Xt=Math.min(I+Et.height,Oe+u);if(Xt>gt)n.push({row:gt,col:G,width:Et.pitch-1,height:Xt-gt,target:{kind:"tile",index:U}});let at=U===s.focus;if(at)H8(f,I,G,Et.height,Et.pitch-1,o);let Tr=I+1,Ke=Math.max(Tr,Oe),En=Math.min(Tr+Et.rows,Oe+u);if(L.thumb&&En>Ke)e.push({id:L.key,path:L.thumb,row:Ke,col:G+1,cols:Et.cols,rows:En-Ke,...En-Ke<Et.rows?{crop:Ke-Tr}:{},z:-1});let Fs=[...s.installed.includes(L.key)?[["✓ ",xc]]:[],...L.page||s.site!=="all"?yi(String(L.id),at?Tt:"",L.page||void 0,ki(L.siteAnsi)):[["● ",ki(L.siteAnsi)],[String(L.id),at?Tt:""]],[" ",""],XS(L)],ru=Et.cols-(L.mates.length>0?1:0);if(f[I+10]?.run(G+1,ys(Fs)>ru?Fs.map(([nd,rd,id])=>[nd.replace(/^(\S) $/,"$1"),rd,id]):Fs),L.mates.length>0)f[I+10]?.put(G+Et.cols,"≈",o);f[I+11]?.put(G+1,L.artist?y8(L.artist).slice(0,Et.cols-8):"—",K);let xi=[];if(L.score>0)xi.push([`★${L.score}`,K]);if(L.variants>1)xi.push([` ×${L.variants}`,o]);if(xi.length>0)f[I+11]?.right(G+Et.cols+1,xi)}}let m=Math.ceil(s.tiles.length/a)*Et.height;G8(t,r,s,u,m,o);let p=Math.max(Oe,Oe+m-s.scroll),b=Oe+u-p,$=s.searching&&b>=2;if($)B8(f,p,b,r-1,s);let k=s.searching&&s.tiles.length===0;if(k&&!s.error){let[C,I]=WS[Math.floor(of(s)/$8)%WS.length];t[i-2]?.run(0,[["Tip ",K],[C,Tt],[` ${I}`,K]])}let v=s.top*a,S=s.tiles.length-(s.top+c)*a,x=[...v>0?[`↑ ${v} above`]:[],...S>0?[`↓ ${S} more`]:[]];if(x.length>0)t[i-2]?.put(0,x.join(" "),K);if(!s.searching&&s.tiles.length===0&&!s.error&&s.tag)t[Oe+1]?.put(0,s.preset==="cutouts"?`No transparent cutouts of ${s.tag} on ${zS(s)} — c searches every post, tab tries ${s.nextSite}`:`No posts of ${s.tag} on ${zS(s)} — tab tries ${s.nextSite}`,K);let M=U8(s,$,h),N=og(s,M);return Oc(t[i-1],r,{badge:"IMAGE SEARCH",lead:N,keys:k&&N?.[0]===M?[]:[["←↑↓→","move"],["enter","try on"],["tab","site"],["ctrl+v","picture"],["s","settings"],["/","search"],["?","keys"]],right:["esc","back"]}),$}function K8(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=[sg(i,o.site,o.siteAnsi),[" ",""],...yi(String(o.id),Tt,o.page||void 0,ki(o.siteAnsi)),[" ",""],XS(o)];if(o.score>0)c.push([` · ★${o.score}`,K]);if(a)c.push([` · ${_l(a.bytes)}`,K]);if(a){if(c.push([" ",""],...QS(a)),i.coloring==="original")c.push([" · own colors",K])}if(t[0]?.run(0,c),o.mates.length>0)t[0]?.right(n,[["≈ ",s],[o.mates.join(" "),K]]);if(O8(t,1,2,i,s),i.tuning)T8(t,8,2,2+Math.min(n-4,60),i,s);else if(i.details)P8(t,5,2,Math.min(n-4,Math.max(48,Math.floor(n*0.55))),r-2,i);else E8(t,7,2,n-4,r-2,i,s);if(i.shown)e.push({id:ag+i.shown.id,path:i.shown.path,row:0,col:0,cols:n,rows:r,z:p8});if(i.tuning){Oc(t[r-1],n,{badge:"IMAGE EDIT",lead:og(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=og(i);Oc(t[r-1],n,{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 z8=[["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"]],q8={grid:[["Move","←↑↓→ j k home end pgup pgdn"],["Try on","enter"],["Site",`tab shift+tab all, ${Z.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 artwork page in a browser · O the post page"],["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",`⇧←→ ${Vt.map((t)=>t.name.toLowerCase()).join(", ")}`],["Cut out","x the background off or on, on an opaque picture"],["Open","o the artwork page in a browser · O the post page"],["Your own","ctrl+v or v a picture from the clipboard · drop one on the window"],["Grid","esc"],["Close","? esc"]]},fg=6,D8=24;function Pc(t){return[...t.settings.flatMap((e,n)=>Boolean(e.advanced)===t.advanced?[n]:[]),t.settings.length]}function J8(t){return t.replace(/^[A-Z](?=[a-z])/,(e)=>e.toLowerCase())}function qS(t){let e=t.settings.filter((n)=>Boolean(n.advanced)!==t.advanced).map((n)=>J8(n.label));return`${t.advanced?"Back to":"More filters:"} ${e.join(", ")} — enter opens the page, or a from any row`}function nE(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.findLast((o)=>(Number(o)||0)<i))??t[n>0?0:t.length-1]}function $s(t,e){let n=[],r="";for(let i of t.split(" "))if(r&&Mt(r)+1+Mt(i)>e)n.push(r),r=i;else r=r?`${r} ${i}`:i;return r?[...n,r]:n}function Y8(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.toSpliced(e,0,t.value)}function V8(t,e,n,r){let i=lg(r),s=e&&n!==void 0;if(t.entry==="text")return[{text:` ${s?`${n}█`:t.value||"none"} `,sgr:s||e&&t.value?i:t.value?"":K}];let o=s?[]:t.value.split(" "),a=(s?t.choices:Y8(t)).map((c,u)=>{let f=o.includes(c),l=t.multi&&e&&u===t.cursor?$t("under"):"";return{text:t.multi?` ${f?"[x]":"[ ]"} ${c} `:` ${c} `,sgr:f?e?`${l}${i}`:"":l?`${l}${K}`:K,choice:c}});return s?[...a,{text:` ${n}█ `,sgr:i}]:a}function DS(t){if(t.entry==="text")return[{text:" ".repeat(D8),sgr:""}];let e=t.choices.map((n)=>({text:t.multi?` [x] ${n} `:` ${n} `,sgr:""}));return t.entry==="number"?[...e,{text:` ${"0".repeat(fg)}█ `,sgr:""}]:e}function Z8(t){return t.reduce((e,n)=>e+Mt(n.text)+1,0)-1}function JS(t,e){let n=[[]],r=0;for(let i of t){let s=Mt(i.text)>e?{...i,text:` …${Array.from(i.text).slice(-(e-2)).join("")}`}:i;if(r>0&&r+Mt(s.text)>e)n.push([]),r=0;n[n.length-1]?.push(s),r+=Mt(s.text)+1}return n}function YS(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 VS(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 X8(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 Q8(t,e,n,r,i){let s=r.panel??0,o=r.settings.length,c=6+Math.max(...r.settings.map((L)=>Mt(L.label))),u=Math.max(...r.settings.map((L)=>Mt(YS(L)))),f=c+Math.max(...r.settings.map((L)=>Z8(DS(L))))+u+5,l=Math.min(e-2,Math.max(48,f)),d=l-c-u-5,h=l-7,m=[!1,!0].map((L)=>({advanced:L,rows:Pc({settings:r.settings,advanced:L}).slice(0,-1)})),p=r.settings.map((L)=>JS(DS(L),d).length),b=Math.max(...m.map((L)=>L.rows.reduce((gt,Xt)=>gt+p[Xt],0))),$=Math.max(...m.map((L)=>$s(qS({settings:r.settings,advanced:L.advanced}),h).length),...r.settings.map((L)=>$s(L.about,h).length)),k=`${r.tag}: ${Z.map((L)=>`${L.name} 0,000,000`).join(" · ")}`,v=r.tag?Math.max($s(k,h).length,$s(VS(r),h).length):0,S=b+$+v+8,x=Math.floor((e-l)/2),M=Math.max(1,Math.floor((n-1-S)/2)),N=lg(r.siteAnsi);t[M]?.put(x,`╭─ Settings ${"─".repeat(Math.max(0,l-13))}╮`);for(let L=M+1;L<M+S-1;L++)t[L]?.put(x,`│${" ".repeat(l-2)}│`);let C=M+2;for(let L of Pc(r).slice(0,-1)){let gt=r.settings[L],Xt=L===s;if(Xt)t[C]?.put(x+2,"▶",i);if(t[C]?.mark(x+2,c-3,{kind:"setting",index:L}),t[C]?.put(x+4,gt.label,Xt?Tt:""),gt.value!==gt.default)t[C]?.right(x+l-3,[[YS(gt),K]]);JS(V8(gt,Xt,r.typing,r.siteAnsi),d).forEach((at,Tr)=>{let Ke=x+c;for(let En of at)Ke=(t[C+Tr]?.put(Ke,En.text,En.sgr,void 0,{kind:"choice",index:L,choice:En.choice})??Ke)+1}),C+=p[L]}let I=m.find((L)=>L.advanced!==r.advanced)?.rows??[],j=t[M+3+b];if(j){if(s===o)j.put(x+2,"▶",i);let L=j.put(x+3,r.advanced?" ‹ Basic ":" Advanced › ",s===o?N:Tt,void 0,{kind:"setting",index:o});if(I.some((gt)=>r.settings[gt]?.value!==r.settings[gt]?.default))j.put(L+1,"•",K)}t[M+5+b]?.put(x+2,"─".repeat(l-4),K),$s(r.settings[s]?.about??qS(r),h).forEach((L,gt)=>{t[M+6+b+gt]?.put(x+4,L)}),$s(VS(r),h).forEach((L,gt)=>{t[M+6+b+$+gt]?.put(x+4,L,K)}),t[M+S-1]?.put(x,`╰${"─".repeat(l-2)}╯`);let{keys:U,right:G}=X8(r,r.settings[s]);Oc(t[n-1],e,{keys:U,right:G})}function t3(t,e,n,r){let i=r.tuning?z8:q8[r.mode],s=Math.min(e-2,Math.max(50,...i.map(([,l])=>Mt(l)+16))),o=i.map(([l,d])=>({label:l,parts:$s(d,s-16)})),a=o.reduce((l,{parts:d})=>l+d.length,0)+4,c=Math.floor((e-s)/2),u=Math.max(2,Math.floor((n-a)/2));t[u]?.put(c,`╭─ Help ${"─".repeat(s-9)}╮`);for(let l=u+1;l<u+a-1;l++)t[l]?.put(c,`│${" ".repeat(s-2)}│`);let f=u+2;for(let{label:l,parts:d}of o){t[f]?.put(c+3,l,Tt);for(let h of d)t[f]?.put(c+13,h),f++}t[u+a-1]?.put(c,`╰${"─".repeat(s-2)}╯`),Oc(t[n-1],e,{badge:"HELP",right:["? esc","close"]})}function e3(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)=>Mt(a.value))),o=Math.max(7,...i.map(Mt));r.forEach((a,c)=>{let u=c===e.pick,f=t[1+c];f?.run(0,[[u?"▸ ":" ",n,void 0,{kind:"suggest",index:c}],[a.value,u?Tt+n:"",void 0,{kind:"suggest",index:c}]]),f?.right(2+s+2+o,[[i[c],K]])})}function ef(t,e=[]){return[...e,...t.flatMap((n,r)=>n.zones(r))]}function dg(t,e,n){let r=Array.from({length:n},()=>new nf(e)),i=[],s=[],o=$t("accent");if(rg=!1,e<ks.cols||n<ks.rows)return r[0]?.put(0,"ttheme find",Tt+o),r[1]?.put(0,`Needs ${ks.cols}×${ks.rows} — now ${e}×${n}`),r[2]?.put(0,"esc quits",K,void 0,{kind:"key",key:"esc"}),{lines:r.map((c)=>c.render()),images:i,zones:ef(r),loader:!1,tick:!1};let a=!1;if(t.mode==="try")K8(r,i,e,n,t,o);else a=W8(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 nf(e);return e3(r,t,o),{lines:r.map((c)=>c.render()),images:[],zones:ef(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 nf(e);if(t.help)t3(r,e,n,t);else Q8(r,e,n,t,o);return{lines:r.map((u)=>u.render()),images:c,zones:ef(r),loader:!1,tick:!1}}return{lines:r.map((c)=>c.render()),images:i,zones:ef(r,s),loader:a,tick:rg}}var n3=130,r3=38,i3=96,s3=28,Ac=[{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}],o3={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]},rE=(t)=>Array.from({length:8},(e,n)=>`«K${t+n}» «»`).join(" "),a3=["«2»❯ «»colortest",`«d»0-7 ${rE(0)}`,`«d»8-15 ${rE(8)}`],iE=2;function c3(t){let e=Ac.length;return Ac[(t%e+e)%e]}function aE(){return Ac.map((t)=>t.name)}function Nc(t,e,n){let r=t>=n3&&e>=r3?"full":t>=i3&&e>=s3?"tabs":void 0;if(!r)return;let i=r==="full"?t>=140?47:38:37,s=t-i-1,o=i+1+iE,a=i+s-iE,c=3,u=e-3,f={col:o,row:c,cols:a-o+1,rows:u-c+1},l={col:o+1,row:c+3,cols:f.cols-2,rows:u-c-3},d=[{row:c,col:o,length:f.cols,down:!1},{row:c+2,col:o,length:f.cols,down:!1},{row:u,col:o,length:f.cols,down:!1},{row:c,col:o,length:u-c+1,down:!0},{row:c,col:a,length:u-c+1,down:!0}],h=c3(n);return{tier:r,side:i,width:s,frame:f,title:{col:l.col,row:c+1,cols:l.cols,rows:1},inner:l,rules:d,tiles:[{id:h.id,name:h.name,col:l.col,row:l.row,width:l.cols,rows:l.rows}]}}var Rc="«2»▎ ",sE="«3»▎ ",u3="«1»▁ ",l3=[["","«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. */"],[Rc,"«5»export interface «6»Palette «»{"],[Rc," name: «6»string"],[Rc," ansi: «6»Hex«»[]"],[Rc," ratio?: «6»number"],[Rc,"}"],["",""],["","«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«»> {"],[sE," «5»const «»text = «5»await «4»readFile«»(path, «2»'utf8'«»)"],[sE," «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)"],[""," }"],[u3," «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"],["","}"]],f3=21;function d3(){return["«K4» theme.ts «s» scenes.ts «s» contrast.ts ",...l3.map(([t,e],n)=>{let r=String(n+1).padStart(3);return`${n+1===f3?`«b»${r}`:`«d»${r}`} ${t||"«» "}«»${e}`})]}function hg(t,e,n,r){let i=Math.max(1,r-t.length-2-n.length),s=0,o=`«6»${t}«b»[`;for(let[a,c]of e){let u=Math.min(i-s,Math.round(c*i));o+=`«${a}»${"|".repeat(u)}`,s+=u}return`${o}«»${" ".repeat(i-s)}${n}«b»]`}var h3=[[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]],m3=["«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"],p3=["Help","Setup","Search","Filter","Tree","SortBy","Nice -","Nice +","Kill","Quit"];function g3(t,e,n){return`«${t}»${e}${" ".repeat(Math.max(0,n-B(e)))}`}function b3(t){let e=t-2,n=Math.floor((e-2)/2),r=(i)=>{let[s,o,a]=h3[i],c=`${((s+o+a)*100).toFixed(1)}%`;return hg(String(i).padStart(3),[["2",s],["1",o],["4",a]],c,n)};return[...[0,1,2,3].map((i)=>`${r(i)} ${r(i+4)}`),`${hg("Mem",[["2",0.45],["4",0.1],["3",0.07]],"9.84G/16.0G",n)} «6»Tasks: «b»214«», 1093 thr; «B2»4«» running`,`${hg("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`,"",g3("K2"," PID USER PRI NI VIRT RES S CPU% MEM% TIME+ Command",e),...m3.map((i)=>i.startsWith("«s»")?`${i}${" ".repeat(Math.max(0,e-B(i.replace(/«[^»]*»/g,""))))}`:i)]}function w3(t){let e=t-2,n="",r=0;return p3.forEach((i,s)=>{let o=`F${s+1}`,a=i.padEnd(6);if(r+o.length+a.length<=e)n+=`«»${o}«K6»${a}`,r+=o.length+a.length}),`${n}«K6»${" ".repeat(Math.max(0,e-r))}`}function oE(t,e,n){if(t==="Editor")return d3();if(t==="Top")return b3(n);let r=Vt.find((o)=>o.name===t)?.lines??[],i=e?o3[t]:void 0,s=i?i.map((o)=>r[o]??""):r;return t==="Shell"?[...s.slice(0,-1),...a3,...s.slice(-1)]:s}function af(t,e){return t.values().map((n)=>Mo(n,e)).filter((n)=>n!==void 0).map((n)=>{let r=0;return n.map(([i,s])=>{let o={text:i,role:s,col:r};return r+=B(i),o})}).toArray()}function $3(t){let r=t-2-B("«K4» NORMAL «s» main src/theme.ts [+] ".replace(/«[^»]*»/g,""))-B("«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 k3(t,e){if(t.id==="code")return[$3(e),'«d»"src/theme.ts" 26L, 912B written'];return t.id==="monitor"?[w3(e)]:[]}function y3(t,e,n){let r=af(k3(t,e),e),i=Math.max(0,n-r.length),s=[];for(let a of t.scenes.toReversed()){let c=af(oE(a,!1,e),e),u=af(oE(a,!0,e),e),f=[c,u].find((l)=>s.length+l.length<=i);if(!f){if(s.length===0)s=t.tail?u.slice(u.length-i):u.slice(0,i);break}s=[...f,...s]}if(r.length===0)return s;let o=af(Array.from({length:i-s.length},()=>t.id==="code"?"«4»~":""),e);return[...s,...o,...r]}function Tc(t){let e=Ac.find((r)=>r.id===t.id),n=t.width-2;return e?y3(e,t.width,t.rows).map((r)=>r.filter((i)=>i.col<n)):[]}function mg(t,e){let{text:n,ground:r}=uE(t);return n===e||r===e}function cE(t,e){let n=t.inner;return Ac.map((r)=>({name:r.name,count:Tc({id:r.id,name:r.name,col:n.col,row:n.row,width:n.cols,rows:n.rows}).flat().filter((i)=>mg(i.role,e)).length}))}function uE(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 pg(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 cf(t){return t.tiles.flatMap((e)=>Tc(e).flatMap((n,r)=>n.map((i,s)=>({spot:{pane:e.id,line:r,run:s},col:i.col,text:i.text,role:i.role}))))}function gg(t,e){return t.pane===e.pane&&t.line===e.line&&t.run===e.run}function lE(t,e){let n=cf(t);return(n.find((r)=>pg(r.role,e))??n[0])?.spot}function uf(t,e){return e&&cf(t).find((n)=>gg(n.spot,e))?.spot}function fE(t,e,n){let r=cf(t);if(r.length===0)return;let i=e?r.findIndex((d)=>gg(d.spot,e)):-1;if(i<0)return r[0]?.spot;let s=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 d=t.tiles.map((p)=>p.id),h=d.indexOf(s.spot.pane),m=d[(h+(n==="next"?1:d.length-1))%d.length];return r.find((p)=>p.spot.pane===m)?.spot}let o=n==="up"?-1:1,a=r.filter((d)=>d.spot.pane===s.spot.pane),c=[...new Set(a.map((d)=>d.spot.line))],u=c[c.indexOf(s.spot.line)+o];if(u===void 0){let d=t.tiles.map((k)=>k.id),h=d.indexOf(s.spot.pane)+o,m=d[(h+d.length)%d.length],p=r.filter((k)=>k.spot.pane===m),b=o<0?p.at(-1)?.spot.line??0:p[0]?.spot.line??0,$=p.filter((k)=>k.spot.line===b);return($.find((k)=>k.col>=s.col)??$.at(-1))?.spot}let f=a.filter((d)=>d.spot.line===u);return(f.find((d)=>d.col<=s.col&&d.col+B(d.text)>s.col)??f.find((d)=>d.col>=s.col)??f.at(-1))?.spot}function dE(t,e){let n=cf(t).find((r)=>gg(r.spot,e));return n?uE(n.role):void 0}var v3={lr:"─",du:"│",dr:"╭",dl:"╮",ru:"╰",lu:"╯",dlr:"┬",lru:"┴",dru:"├",dlu:"┤",dlru:"┼"};function hE(t){let e=new Map,n=(i,s,o)=>{let a=e.get(i)??new Map;e.set(i,a);let c=a.get(s)??new Set;a.set(s,c),c.add(o)};for(let i of t)for(let s=0;s<i.length;s++){let o=i.down?i.row+s:i.row,a=i.down?i.col:i.col+s;if(s>0)n(o,a,i.down?"u":"l");if(s<i.length-1)n(o,a,i.down?"d":"r")}let r=(i)=>v3[[...i].sort().join("")]??(i.has("l")||i.has("r")?"─":"│");return new Map(e.entries().map(([i,s])=>[i,new Map(s.entries().map(([o,a])=>[o,r(a)]))]))}import{execFile as S3}from"node:child_process";import{createHash as bE}from"node:crypto";import{existsSync as E3,mkdtempSync as M3,readFileSync as hf,rmSync as x3,statSync as wE,writeFileSync as $E}from"node:fs";import{homedir as O3,tmpdir as P3}from"node:os";import{join as lf}from"node:path";import{fileURLToPath as I3}from"node:url";import{promisify as R3}from"node:util";import{inflateSync as A3}from"node:zlib";var yn=R3(S3),ff=67108864,N3=4096,T3="/System/Library/ColorSync/Profiles/sRGB Profile.icc",$g=["image/png","image/jpeg","image/webp","image/gif","image/tiff","image/heic"],H3=["text/uri-list","text/plain;charset=utf-8","text/plain"],bg=[...$g,"text/uri-list","text/plain"];function F3(t){try{return wE(t).isFile()}catch{return!1}}function L3(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 mE(t){if(/^file:\/\//i.test(t))try{return I3(t)}catch{return}if(t.startsWith("~/"))return lf(O3(),t.slice(2));return t.startsWith("/")?t:void 0}function na(t,e=F3){return t.replace(/\r\n?/g,`
660
681
  `).split(`
661
- `)){let i=rE(r.trim());if(i&&e(i)){n.push(i);continue}for(let s of d3(r)){if(/^https?:\/\/\S+$/i.test(s)){n.push(s);continue}let o=rE(s);if(o&&e(o))n.push(o)}}return n}function iE(t){let e=Ii(t)?Mn(t):Id(t);if(!e)return;return{ext:Ii(t)?"png":"jpg",width:e.width,height:e.height}}async function rf(t,e){let n=iE(t);if(n&&n.width*n.height<=Ae)return{bytes:t,...n,source:e};if(process.platform!=="darwin")throw Error(n?`${n.width}×${n.height} is over ${Ae/1e6} megapixels`:"only PNG and JPEG pictures work here");let r=r3(ef(o3(),"ttheme-attach-"));try{let i=ef(r,"in"),s=ef(r,"out.png");cE(i,t);let o=!n||n.width*n.height>Ae?["--resampleHeightWidthMax",String(u3)]:[];await Wn("sips",["-s","format","png",...o,i,"--out",s]).catch(()=>{throw Error("that is not a picture macOS can read")});let a=new Uint8Array(sf(s)),c=iE(a);if(!c)throw Error("that is not a picture macOS can read");return{bytes:a,...c,source:e}}finally{i3(r,{recursive:!0,force:!0})}}async function lg(t,e){if(/^https?:\/\//i.test(t)){let n=await fetch(t,{headers:{"User-Agent":Cd},signal:e});if(!n.ok)throw Error(`${new URL(t).host} answered ${n.status}`);if(Number(n.headers.get("content-length")??0)>nf)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 rf(r,t)}if(aE(t).size>nf)throw Error("that picture is over 64 MB");return rf(new Uint8Array(sf(t)),t)}var uE=new Map,Kn={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)=>uE.get(t)??"",parse:()=>[],count:()=>0};function lE(t){if(/^https?:\/\//i.test(t))return"";return t.split("/").pop()??t}function fE(t,e){uE.set(t,e)}function dE(t){return Number.parseInt(oE("sha1").update(t).digest("hex").slice(0,8),16)%Br}var h3=`ObjC.import('AppKit')
682
+ `).flatMap((n)=>{let r=mE(n.trim());if(r&&e(r))return[r];return L3(n).flatMap((i)=>{if(/^https?:\/\/\S+$/i.test(i))return[i];let s=mE(i);return s&&e(s)?[s]:[]})})}function pE(t){let e=Br(t)?Rn(t):Cd(t);if(!e)return;return{ext:Br(t)?"png":"jpg",width:e.width,height:e.height}}function C3(t){let e=Buffer.from(t.buffer,t.byteOffset,t.byteLength);if(Br(t)){for(let r=8;r+12<=e.length;){let i=e.readUInt32BE(r),s=e.toString("latin1",r+4,r+8);if(s==="iCCP"){let o=e.subarray(r+8,r+8+i);try{return A3(o.subarray(o.indexOf(0)+2))}catch{return}}if(s==="IDAT")return;r+=12+i}return}let n=[];for(let r=2;r+4<=e.length&&e[r]===255&&e[r+1]!==218;){let i=e.readUInt16BE(r+2);if(e[r+1]===226&&e.toString("latin1",r+4,r+16)==="ICC_PROFILE\x00")n[e[r+16]??0]=e.subarray(r+18,r+2+i);r+=2+i}return n.length>0?Buffer.concat(n.filter(Boolean)):void 0}function j3(t){let e=C3(t);if(!e||e.length<132||e.toString("latin1",16,20)==="GRAY")return!1;for(let n=132,r=e.readUInt32BE(128);r>0&&n+12<=e.length;r--,n+=12)if(e.toString("latin1",n,n+4)==="desc"){let i=e.readUInt32BE(n+4),s=e.toString("latin1",i,i+e.readUInt32BE(n+8)).replaceAll("\x00","");return!/sRGB/i.test(s)}return!0}async function _3(t){let{stdout:e}=await yn("sips",["-g","pixelWidth","-g","pixelHeight",t]).catch(()=>({stdout:""})),n=Number(/pixelWidth: (\d+)/.exec(e)?.[1]),r=Number(/pixelHeight: (\d+)/.exec(e)?.[1]);return n>0&&r>0?{width:n,height:r}:void 0}async function df(t,e){let n=pE(t),r=process.platform==="darwin";if(n&&n.width*n.height<=de&&!(r&&j3(t)))return{bytes:t,...n,source:e};if(!r)throw Error(n?`${n.width}×${n.height} is over ${de/1e6} megapixels`:"only PNG and JPEG pictures work here");let i=M3(lf(P3(),"ttheme-attach-"));try{let s=lf(i,"in"),o=lf(i,"out.png");$E(s,t);let a=n??await _3(s),c=a&&a.width*a.height>de?["--resampleHeightWidthMax",String(N3)]:[];await yn("sips",["-s","format","png","--matchTo",T3,...c,s,"--out",o]).catch(()=>{throw Error("that is not a picture macOS can read")});let u=new Uint8Array(hf(o)),f=pE(u);if(!f)throw Error("that is not a picture macOS can read");return{bytes:u,...f,source:e}}finally{x3(i,{recursive:!0,force:!0})}}async function kg(t,e){if(/^https?:\/\//i.test(t)){let n=await fetch(t,{headers:{"User-Agent":Dd},signal:e});if(!n.ok)throw Error(`${new URL(t).host} answered ${n.status}`);if(Number(n.headers.get("content-length")??0)>ff)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 df(r,t)}if(wE(t).size>ff)throw Error("that picture is over 64 MB");return df(new Uint8Array(hf(t)),t)}var kE=new Map,Dn={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)=>kE.get(t)??"",parse:()=>[],count:()=>0};function yE(t){if(/^https?:\/\//i.test(t))return"";return t.split("/").pop()??t}function vE(t,e){kE.set(t,e)}function SE(t){return Number.parseInt(bE("sha1").update(t).digest("hex").slice(0,8),16)%zr}var B3=`ObjC.import('AppKit')
662
683
  function run(argv) {
663
684
  const pb = $.NSPasteboard.generalPasteboard
664
685
  const files = pb.readObjectsForClassesOptions($([$.NSURL]), $({ NSPasteboardURLReadingFileURLsOnlyKey: true }))
@@ -683,16 +704,16 @@ function run(argv) {
683
704
  if (web && web.count > 0) return web.objectAtIndex(0).absoluteString.js
684
705
  const text = pb.stringForType('public.utf8-plain-text')
685
706
  return text && !text.isNil() ? text.js : ''
686
- }`,m3=`Add-Type -AssemblyName System.Windows.Forms,System.Drawing
707
+ }`,G3=`Add-Type -AssemblyName System.Windows.Forms,System.Drawing
687
708
  $c = [Windows.Forms.Clipboard]
688
709
  $f = $c::GetFileDropList(); if ($f.Count) { $f; exit }
689
710
  $p = Join-Path $env:TEMP 'ttheme-clipboard.png'
690
711
  $s = $c::GetData('PNG'); if ($s -is [IO.MemoryStream]) { [IO.File]::WriteAllBytes($p, $s.ToArray()); $p; exit }
691
712
  $i = $c::GetImage(); if ($i) { $i.Save($p, [Drawing.Imaging.ImageFormat]::Png); $p; exit }
692
- $c::GetText()`;function hE(){if(process.platform!=="linux")return!1;try{return/microsoft/i.test(sf("/proc/version","utf8"))}catch{return!1}}async function p3(t){let e=Boolean(process.env.WAYLAND_DISPLAY),n=e?["wl-paste",["--list-types"]]:["xclip",["-selection","clipboard","-t","TARGETS","-o"]],r=(await Wn(n[0],n[1])).stdout.split(`
693
- `).map((o)=>o.trim()),i=(o)=>e?Wn("wl-paste",["--no-newline","--type",o],{encoding:"buffer",maxBuffer:nf}):Wn("xclip",["-selection","clipboard","-t",o,"-o"],{encoding:"buffer",maxBuffer:nf});if(r.includes("text/uri-list"))return{text:(await i("text/uri-list")).stdout.toString("utf8")};let s=ug.find((o)=>r.includes(o));if(s)return cE(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 fg(){return Boolean(process.env.SSH_CONNECTION||process.env.SSH_TTY)}async function mE(t){if(process.platform==="darwin"){let e=(await Wn("osascript",["-l","JavaScript","-e",h3,t])).stdout.trim();return e===t?{image:t}:{text:e}}if(hE()){let e=(await Wn("powershell.exe",["-NoProfile","-STA","-Command",m3])).stdout.replace(/\r/g,"").trim(),n=await Promise.all(e.split(`
694
- `).map(async(r)=>/^[A-Za-z]:\\/.test(r)?(await Wn("wslpath",["-u",r])).stdout.trim():r));return n.length===1&&/ttheme-clipboard\.png$/.test(n[0]??"")?{image:n[0]}:{text:n.join(`
695
- `)}}if(process.platform==="linux")return p3(t);throw Error(`reading the clipboard is not supported on ${process.platform}`)}var g3=`ObjC.import('AppKit')
713
+ $c::GetText()`;function EE(){if(process.platform!=="linux")return!1;try{return/microsoft/i.test(hf("/proc/version","utf8"))}catch{return!1}}async function U3(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(`
714
+ `).map((o)=>o.trim()),i=(o)=>e?yn("wl-paste",["--no-newline","--type",o],{encoding:"buffer",maxBuffer:ff}):yn("xclip",["-selection","clipboard","-t",o,"-o"],{encoding:"buffer",maxBuffer:ff});if(r.includes("text/uri-list"))return{text:(await i("text/uri-list")).stdout.toString("utf8")};let s=$g.find((o)=>r.includes(o));if(s)return $E(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 yg(){return Boolean(process.env.SSH_CONNECTION||process.env.SSH_TTY)}async function ME(t){if(process.platform==="darwin"){let e=(await yn("osascript",["-l","JavaScript","-e",B3,t])).stdout.trim();return e===t?{image:t}:{text:e}}if(EE()){let e=(await yn("powershell.exe",["-NoProfile","-STA","-Command",G3])).stdout.replace(/\r/g,"").trim(),n=await Promise.all(e.split(`
715
+ `).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(`
716
+ `)}}if(process.platform==="linux")return U3(t);throw Error(`reading the clipboard is not supported on ${process.platform}`)}var W3=`ObjC.import('AppKit')
696
717
  function run() {
697
718
  const pb = $.NSPasteboard.generalPasteboard
698
719
  const files = pb.readObjectsForClassesOptions($([$.NSURL]), $({ NSPasteboardURLReadingFileURLsOnlyKey: true }))
@@ -704,84 +725,64 @@ function run() {
704
725
  picture = ['public.png', 'public.tiff', 'public.jpeg', 'public.heic'].some((t) => types.includes(t))
705
726
  }
706
727
  return pb.changeCount + '\\t' + (picture ? 'picture' : '')
707
- }`;async function pE(){if(fg())return;if(process.platform==="darwin"){let[t="",e=""]=(await Wn("osascript",["-l","JavaScript","-e",g3])).stdout.trim().split("\t");return{stamp:t,picture:e==="picture"}}if(process.platform==="linux"&&!hE()){let e=Boolean(process.env.WAYLAND_DISPLAY)?(await Wn("wl-paste",["--list-types"])).stdout:(await Wn("xclip",["-selection","clipboard","-t","TARGETS","-o"])).stdout;return{stamp:e,picture:/^image\//m.test(e)}}return}function of(t){return t.length>8&&/^(?:\/|~\/|file:|https?:)/.test(t)}var Pc=(t)=>Buffer.from(t).toString("base64"),cg=(t)=>Buffer.from(t,"base64");function sE(t,e){return e.find((n)=>t.includes(n))}class dg{clipboard=!1;drops=!1;reading;offered=[];dropping;pw=Pc(oE("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;${ag.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=${Pc("ttheme")}:pw=${this.pw};${Pc(".")}\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?cg(t.mime).toString("utf8"):r.mime,e)r.chunks.push(cg(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=sE(s,[...ug,...l3]);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=${Pc(c)}:pw=${a};${Pc(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=ag.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=sE(a,ag);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(cg(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"?Zo(a).find((u)=>n3(u)):void 0;o=c?{kind:"bytes",bytes:new Uint8Array(sf(c)),source:c}:{kind:"text",text:a}}this.send("\x1B]72;t=r:o=1\x1B\\"),this.deliver(o)}}var hg=5,b3=6,gE=0.05,w3=[1,2,3,4,5,6,9,10,11,12,13,14],bE=(t,e)=>(e-t+360)%360<=180?1:-1;function zn(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((f)=>f**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((f)=>f<-0.0001||f>1.0001))return;return u.map((f)=>{let l=Math.min(1,Math.max(0,f));return Math.round(255*(l<=0.0031308?12.92*l:1.055*l**0.4166666666666667-0.055))})}function Xo(t,e,n){if(zn(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(zn(t,o,e)===void 0)i=o;else r=o}return r}function en(t,e,n){return`#${(zn(t,Xo(t,n,e),n)??[0,0,0]).map((i)=>i.toString(16).padStart(2,"0")).join("")}`}function $3(t,e){let{l:n,c:r}=Ot(t);return en(n,r,(e+360)%360)}function k3(t,e,n){let{l:r,c:i,h:s}=Ot(t),o=Mt(e)<0.18,a=(f)=>en(o?r+(1-r)*f:r*(1-f),i,s);if(yt(a(1),e)<n+gE)return a(1);let c=0,u=1;for(let f=0;f<30;f++){let l=(c+u)/2;if(yt(a(l),e)>=n+gE)u=l;else c=l}return a(u)}function y3(t,e){let{l:n,c:r,h:i}=Ot(t),s=0,o=n;for(let a=0;a<30;a++){let c=(s+o)/2;if(Mt(en(c,r,i))<=e-0.005)s=c;else o=c}return en(s,r,i)}function v3(t,e,n){let r=Pe[e],[i,s]=[Ot(t[e]),Ot(t[e+8])],o=(f,l)=>n.has(f)?[l]:Array.from({length:2*r.width+1},(d,h)=>(r.center-r.width+h+360)%360),a=(f,l,d)=>Ar.every((h)=>{let m=(f>8?8:0)+h;if(m===f)return!0;let g=Ot(t[m]);return g.c<Oi||Re(g.h,l)>=Cs+1||Math.abs(g.l-d)>=js}),c,u=Number.POSITIVE_INFINITY;for(let f of o(e,i.h)){if(!n.has(e)&&!a(e,f,i.l))continue;for(let l of o(e+8,s.h)){if(Re(f,l)>sn-hg||!n.has(e+8)&&!a(e+8,l,s.l))continue;let d=Re(f,i.h)+Re(l,s.h);if(d<u)u=d,c=[f,l]}}return c}class wE{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,$3(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=Pe[yn(n)];this.rehue(n,"ansi-role",i.center+bE(i.center,r)*(i.width-hg))}for(let{normal:n,gap:r}of Qn(this.theme)){if(r<=sn)continue;let[i,s]=t.has(`ansi${n+8}`)?[n+8,n]:[n,n+8],o=Ot(this.theme.ansi[i]).h,a=Ot(this.theme.ansi[s]).h;this.rehue(s,"bright-follows",o+bE(o,a)*(sn-hg))}let e=_s(this.theme);for(let[n,r]of tr(this.theme)){let i=yn(e.has(r)?n:r),s=v3(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(yt(this.get(a),o)<s)this.set(a,r,k3(this.get(a),o,s))};if(n("foreground",["foreground"],7),n("accents",w3.map((r)=>`ansi${r}`),3),n("light-ansi",["ansi7","ansi15"],7),n("ansi8-visible",["ansi8"],1.6),!t.has("ansi0-dark")&&Mt(this.get("ansi0"))>0.15)this.set("ansi0","ansi0-dark",y3(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 af(t){let e=new wE(t);for(let n=0;n<b3;n++)if(e.readability(),e.roles(),er(e.theme).length===0)break;return{theme:e.theme,moves:e.net(),left:er(e.theme)}}var ks=[{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}],Rc={background:0.21,foreground:0.88,hue:265,tint:0.02,lightness:0.72,chroma:0.12,brights:0.06},$E=(t,e,n)=>Math.min(n,Math.max(e,t));function mg(t,e,n){let r=t[e.key]+e.step*n,i=e.wraps?(r%e.max+e.max)%e.max:$E(r,e.min,e.max);return{...t,[e.key]:Math.round(i*1e4)/1e4}}function bi(t){let e=(r,i,s)=>en($E(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 Ar){let i=Pe[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 qn=["background","foreground","cursor","selection",...Array.from({length:16},(t,e)=>`ansi${e}`)],T=["Background","Foreground","Cursor","Selection"],$n=["Black","Red","Green","Yellow","Blue","Magenta","Cyan","White"],S3=["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"],vr=T.length+$n.length,wn=[{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}],kE=5,E3=5,se=wn.length,Qo=["this","pair","normals","brights","accents"],cf=[1,2,3,4,5,6,9,10,11,12,13,14],yE=cf.filter((t)=>t<8).map((t)=>T.length+t),vE=cf.filter((t)=>t>8).map((t)=>T.length+t);function pg(t,e){let n=e-T.length;if(n<0||t==="this")return[e];if(t==="pair")return[T.length+n%8,T.length+8+n%8];let r=t==="normals"?yE:t==="brights"?vE:[...yE,...vE];return r.includes(e)?r:[e]}function M3(){return Array.from({length:vr},(t,e)=>e<T.length?[e]:[e,e+8]).flat()}function x3(t){let e=t.trim();return/^https?:\/\/\S+$/i.test(e)||Zo(e).length>0}function nn(t){return[t.background,t.foreground,t.cursor,t.selection,...t.ansi]}function oe(t){let[e,n,r,i,...s]=t;return{background:e,foreground:n,cursor:r,selection:i,ansi:s}}function Ue(t){if(t<T.length)return{name:T[t],about:qn[t]};let e=t-T.length,n=$n[e%8];return e<8?{name:n,about:`ANSI ${e}`}:{name:`Bright ${n.toLowerCase()}`,about:`ANSI ${e}`}}function xE(t){let e=t-T.length;if(e>=9&&e<=15)return`Bold or bright ${$n[e-8].toLowerCase()} text`;return S3[t]}var ys=(t,e,n)=>Math.min(n,Math.max(e,t));function SE(t){return t.length===1?t.toLowerCase():t}function O3(t){return ys(Math.round(t),0,255).toString(16).padStart(2,"0")}function EE(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)=>O3(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 en(ys(s,0,1),Number(i[3]),Number(i[4])%360)}return}function vs(t){let e=Ie.find((n)=>n.rule===t);return e?.min??e?.max??0}function Sr(t,e,n){let r=oe(t);return{name:"draft",background:r.background,foreground:r.foreground,selectionBackground:r.selection,ansi:r.ansi,waive:n,signatureSlots:e}}function P3(t,e){let n=t-T.length,r=t<=1?"foreground":t===3?"selection":n===7||n===15?"light-ansi":n===8?"ansi8-visible":cf.includes(n)?"accents":void 0;return{against:t===0||t===3?1:0,floor:r===void 0||e.includes(r)?void 0:vs(r)}}function $g(t,e,n,r){let i=Sr(t,e,n),{background:s,foreground:o,selection:a,ansi:c}=oe(t),u=(f,l,d)=>yt(l,d)<vs(r)?[f]:[];if(r==="foreground")return yt(o,s)<vs(r)?[1,0]:[];if(r==="selection")return yt(o,a)<vs(r)?[3,1]:[];if(r==="accents")return cf.flatMap((f)=>u(T.length+f,c[f],s));if(r==="light-ansi")return[7,15].flatMap((f)=>u(T.length+f,c[f],s));if(r==="ansi8-visible")return u(T.length+8,c[8],s);if(r==="ansi0-dark")return Mt(c[0])>vs(r)?[T.length]:[];if(r==="ansi-role")return Nr(i).map(({slot:f})=>T.length+f);if(r==="bright-follows")return Qn(i).filter(({gap:f})=>f>sn).flatMap(({normal:f})=>[T.length+f,T.length+f+8]);if(r==="distinct")return tr(i).flatMap(([f,l])=>[T.length+f,T.length+l]);return[]}function kg(t,e,n){return new Set(qn.flatMap((r,i)=>yg(t,e,n,i).some((s)=>s.ok===!1)?[i]:[]))}function yr(t,e,n,r,i){let s=yt(t,e),o=vs(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 yg(t,e,n,r){let i=oe(t),s=Sr(t,e,n);if(r===0){let w=[1,2,3,4,5,6,9,10,11,12,13,14].reduce((k,v)=>yt(i.ansi[k],i.background)<=yt(i.ansi[v],i.background)?k:v);return[yr(i.foreground,i.background,"foreground","Foreground on it",n),yr(i.ansi[w],i.background,"accents",`Weakest, ANSI ${w},`,n),yr(i.ansi[8],i.background,"ansi8-visible","ANSI 8 on it",n)]}if(r===1)return[yr(i.foreground,i.background,"foreground","On background",n),yr(i.foreground,i.selection,"selection","On the selection",n)];if(r===2)return[{ok:void 0,text:`On background ${yt(i.cursor,i.background).toFixed(2)}:1`}];if(r===3)return[yr(i.foreground,i.selection,"selection","Foreground on it",n)];let o=r-T.length,a=i.ansi[o];if(o===0){let b=Mt(a),w=vs("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(o===7||o===15)return[yr(a,i.background,"light-ansi","On background",n)];if(o===8)return[yr(a,i.background,"ansi8-visible","On background",n)];let c=[yr(a,i.background,"accents","On background",n)],u=Ot(a),f=yn(o),l=Pe[f],d=`${l.name} ${l.center}±${l.width}°`;if(u.c<Oi)c.push({ok:void 0,text:"Too grey to have a hue"});else if(_s(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 b=Re(u.h,l.center)-l.width;c.push(b>0?{ok:!1,text:`Hue ${u.h.toFixed(0)}° · ${b.toFixed(0)}° outside ${d}`}:{ok:!0,text:`Hue ${u.h.toFixed(0)}° · in ${d}`})}let h=o<8?o+8:o-8,m=Qn(s).find((b)=>b.normal===f);if(m)c.push(n.includes("bright-follows")?{ok:void 0,text:`${m.gap.toFixed(0)}° from ANSI ${h} · waived`}:{ok:m.gap<=sn,text:`${m.gap.toFixed(0)}° from ANSI ${h} · ≤ ${sn}°`});let g=tr(s).flatMap(([b,w])=>b===o?[w]:w===o?[b]:[]);if(g.length>0&&!n.includes("distinct"))c.push({ok:!1,text:`Reads as ANSI ${g.join(", ")} · within ${Cs}° and ${js} lightness`});return c}function vg(t,e,n){let r=vn(Sr(t,e,n));return Ie.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?$g(t,e,n,i.rule):[]}})}var R3=new Set(["reset","reset-all","hex","paste","fix","open","tune","sig","follow"]),OE=wn[1].max;function wg(t){let[e,n,r]=ct(t);return e===n&&n===r}function I3(t,e){let n=Ot(e);if(!wg(e))return n;let r=[0,1,3,2].map((i)=>t[i]).find((i)=>!wg(i));return{...n,h:r?Ot(r).h:Rc.hue}}function PE(t,e,n){if(t==="rgb"){let[r,i,s]=ct(e);return`rgb(${r} ${i} ${s})`}if(t==="oklch")return`oklch(${n.l.toFixed(3)} ${n.c.toFixed(3)} ${n.h.toFixed(0)})`;return e}function gg(t,e){return Math.floor(Xo(t,e,OE)*1e4)/1e4}function bg(t,e){return{l:e.l-t.l,c:e.c-t.c,h:((e.h-t.h)%360+540)%360-180}}function ME(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 Sg{mode;seeds=Rc;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=nn(t.colors??bi(this.seeds)),this.lch=this.lchs(),this.start=[...this.list],this.original=t.original?nn(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=T.length+e,r=n+8,i=this.lchOf(t[n]),s=this.lchOf(t[r]);if(i.c>=Oi&&s.c>=Oi&&Re(i.h,s.h)<=3)this.links.set(r,n),this.offsets.set(r,bg(i,s))}}pair(t){if(t<T.length)return;let e=T.length+(t-T.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<T.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 oe(this.list)}edited(){return{colors:this.colors(),signature:[...this.signature]}}shown(){return this.compare?this.start:this.list}slot(){return this.row<T.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()}resettable(){return this.dirty()||this.tone&&this.list.some((t,e)=>t!==this.original[e])}misses(){return kg(this.list,this.signature,this.waive)}failing(){return er(Sr(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&&x3(t)){this.findPictures({paste:t});return}if(this.mode==="seeds")return;let e=this.options.decode?.(t);if(e){this.remember("open"),this.list=nn(e),this.lch=this.lchs(),this.chain(this.list),this.notice="Took the colors of the share code";return}let n=EE(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",this.inspect=!1,this.spot=void 0;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<T.length?t:T.length+(t-T.length)%8,t>=T.length)this.col=t-T.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===se){this.reach(21**n);return}this.put(ME(wn[t],n))}sow(t,e){let n=ks[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=mg({...this.seeds,[n.key]:ME(n,r)},n,0),this.list=nn(bi(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,ks.length-1);else if(this.mode==="tune")this.channel=0,this.step(-t);else this.row=e(this.row,vr-1),this.lastEdit=void 0}lchOf(t){return I3(this.list,t)}lchs(){return this.list.map((t)=>this.lchOf(t))}seedKey(t){let e=ks.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=ks[this.field],r=(t.endsWith("left")?-1:1)*(t.startsWith("shift")?n.wraps?10:kE:1);this.seeds=mg(this.seeds,n,r),this.list=nn(bi(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:vr-1,t==="home"?1:-1);else if(t==="pgup"||t==="pgdn")this.land(t==="pgup"?0:T.length,1);else if(t==="left"||t==="right"){let e=t==="left"?0:1;if(this.row>=T.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&&this.view==="slot"?xc(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>=T.length&&this.visible(this.slotAt(t,1))}land(t,e){for(let n=0;n<vr;n++){let r=((t+e*n)%vr+vr)%vr;if(this.rowShown(r)){if(this.row=r,r>=T.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=this.view==="relations"?"g goes back to the builder":"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 share link or a tt2: 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)}}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=QS(t,this.slot())}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=tE(e,tf(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?eE(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<T.length){this.notice="l links a bright to its normal — pick an ANSI row";return}let e=T.length+(t-T.length)%8,n=e+8,r=`${Ue(n).name} and ${Ue(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,bg(this.lch[e],this.lch[n])),this.notice=`${r} move together`}nextMiss(t){let e=M3(),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)){this.seat(s);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 pg(this.scope,this.slot())}tuneKey(t){let e=this.channel===se;if(t==="tab"||t==="shift-tab")this.channel=e?0:se;else if(t==="up"||t==="down"||t==="pgup"||t==="pgdn")this.channel=0,this.step((t==="up"||t==="pgup"?1:-1)*(t.startsWith("pg")?kE: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*E3)}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=wn[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=wn[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()<T.length){this.notice="A base color moves alone";return}let t=Qo.indexOf(this.scope);for(let e=1;e<=Qo.length;e++){let n=Qo[(t+e)%Qo.length];if(n==="this"||pg(n,this.slot()).length>1){this.scopeTo(n);return}}}scopeTo(t){if(this.mode!=="tune"||this.typing!==void 0||this.quitting||this.slot()<T.length)return;if(t!=="this"&&pg(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 P3(this.slot(),this.waive)}ratio(){return yt(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:yt(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,s=(d)=>en(d,Math.min(i,gg(d,r.h)),r.h),o=(d)=>yt(s(d),n),a=Mt(this.list[e])>=Mt(n),c=Ot(n).l,u=Math.max(1,Math.round(t*100)/100),f=a?1:0,l;if(o(f)<u)l=f,this.notice=`The ratio stops at ${o(f).toFixed(2)}:1 on this side of the color it is read against`;else{let d=c,h=f;for(let m=0;m<24;m++){let g=(d+h)/2;if(o(g)>=u)h=g;else d=g}l=h}this.place(e,l,i,r.h);for(let d=0;d<40&&l!==f&&yt(this.list[e],n)<u;d++)l=a?Math.min(1,l+0.001):Math.max(0,l-0.001),this.place(e,l,i,r.h);this.lch[e]={...this.lch[e],l:Math.round(l*1e4)/1e4}}step(t){let e=wn[this.channel],n=this.lch[this.slot()][e.key];this.put(n+e.step*t)}put(t){let e=this.slot(),n=wn[this.channel],r=n.wraps?(t%n.max+n.max)%n.max:ys(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=gg(s.l,s.h);if(i>u)this.notice=`Chroma stops at ${u.toFixed(3)}, the sRGB edge for this lightness and hue`;let f=Math.min(i,u),l=f-s.c;this.holds.set(e,f),this.place(e,s.l,f,s.h);for(let d of o){let h=this.lch[d],m=a(ys((this.holds.get(d)??h.c)+l,0,OE));this.holds.set(d,m),this.place(d,h.l,m,h.h)}this.trail([e,...o]);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"&&wg(this.list[e]))this.notice="A grey shows no hue — raise its chroma first";for(let u of o){let f=this.lch[u];this.place(u,n.key==="l"?a(ys(f.l+c,0,1)):f.l,this.holds.get(u)??f.c,n.key==="h"?a(((f.h+c)%360+360)%360):f.h)}this.trail([e,...o])}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],s=this.offsets.get(n);this.place(n,ys(i.l+s.l,0,1),Math.max(0,i.c+s.c),((i.h+s.h)%360+360)%360)}}}place(t,e,n,r){let i=Math.min(n,gg(e,r));this.lch[t]={l:e,c:i,h:r},this.list[t]=en(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=EE(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=ps(e,SE(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=nn(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=ps(this.filter,SE(t),(r)=>/^[a-z0-9@/-]$/.test(r));if(n!==void 0)this.filter=n,this.pick=0}}remember(t){if(t!==this.lastEdit||R3.has(t))this.history.push({list:[...this.list],lch:[...this.lch],signature:[...this.signature]}),this.future=[];this.lastEdit=t}set(t,e,n){if(!ge(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<T.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,ys(n.l+0.06,0,1),n.c,n.h),this.links.set(e,t),this.unlinked.delete(e),this.offsets.set(e,bg(n,this.lch[e])),this.seat(e),this.notice=`${Ue(e).name} follows ${Ue(t).name.toLowerCase()}`}mark(){let t=qn[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=Sr(this.list,this.signature,this.waive),{theme:e,moves:n,left:r}=af({...t,selectionBackground:t.selectionBackground,signatureSlots:this.signature});if(n.length===0){this.notice=er(t).length===0?"Already passes the gate":"No color change fixes it";return}this.remember("fix");let i=nn({...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 Q3,readFileSync as Og,writeFileSync as WE}from"node:fs";import{dirname as t5}from"node:path";import{isMainThread as e5,parentPort as KE,Worker as n5}from"node:worker_threads";var A3=new Set(["comic","4koma","monochrome","greyscale","sketch","lineart","speech_bubble"]),N3=new Set(["scenery","landscape","scenic","no_humans","wide_shot","very_wide_shot"]),T3=0.04,H3=0.1,L3=0.05,F3=4096;function C3(t){return new Set(t.cutouts.split(/\s+/).map((e)=>e.replace(/^~/,"")).filter(Boolean))}function j3(t,e,n,r=0){let{site:i,post:s}=t,o=new Set(s.tags),a=[...C3(i)].some((f)=>o.has(f)),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)+([...A3].some((f)=>o.has(f))?-3:0)+([...N3].some((f)=>o.has(f))?-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 uf(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:j3(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 IE(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 Eg(t){let e=t/255;return e<=0.04045?e/12.92:((e+0.055)/1.055)**2.4}function RE(t,e,n){let[r,i,s]=[Eg(t),Eg(e),Eg(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 AE(t,e){let n=e.map((o)=>RE(...ct(o))).filter(([,o,a])=>Math.hypot(o,a)>=T3);if(n.length===0)return 0;let r=Math.max(1,Math.floor(Math.sqrt(t.width*t.height/F3))),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,f,l]=RE(t.data[c],t.data[c+1],t.data[c+2]);n.forEach(([d,h,m],g)=>{if(Math.hypot(u-d,f-h,l-m)<H3)i[g]=i[g]+1})}if(s===0)return 0;return i.reduce((o,a)=>o+Math.min(1,a/s/L3),0)/n.length}import{existsSync as Mg,mkdirSync as NE,readFileSync as ea}from"node:fs";import{homedir as K3}from"node:os";import{dirname as TE,join as Ss}from"node:path";import{spawn as _3}from"node:child_process";var G3=30000,B3=3,U3=97,W3=`ObjC.import('Vision')
708
- ObjC.import('CoreImage')
709
- ObjC.import('CoreGraphics')
710
- function run(argv) {
711
- const error = Ref()
712
- const image = $.CIImage.imageWithContentsOfURL($.NSURL.fileURLWithPath(argv[0]))
713
- if (!image) throw new Error('unreadable image')
714
- const handler = $.VNImageRequestHandler.alloc.initWithCIImageOptions(image, $({}))
715
- const request = $.VNGenerateForegroundInstanceMaskRequest.alloc.init
716
- if (!handler.performRequestsError($([request]), error)) throw new Error('vision failed')
717
- if (request.results.count === 0) throw new Error('no foreground')
718
- const found = request.results.objectAtIndex(0)
719
- const buffer = found.generateMaskedImageOfInstancesFromRequestHandlerCroppedToInstancesExtentError(
720
- found.allInstances, handler, false, error)
721
- if (!buffer) throw new Error('mask failed')
722
- const written = $.CIContext.context.writePNGRepresentationOfImageToURLFormatColorSpaceOptionsError(
723
- $.CIImage.imageWithCVPixelBuffer(buffer), $.NSURL.fileURLWithPath(argv[1]), $.kCIFormatRGBA8,
724
- $.CGColorSpaceCreateWithName($.kCGColorSpaceSRGB), $({}), error)
725
- if (!written) throw new Error('write failed')
726
- }`;function ta(){return process.platform==="darwin"}function lf(t){return t>=B3&&t<=U3}function Ic(t,e,n){return new Promise((r,i)=>{let s=_3("osascript",["-l","JavaScript","-e",W3,t,e],{stdio:["ignore","ignore","pipe"],signal:AbortSignal.any([n,AbortSignal.timeout(G3)])}),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(`
727
- `).at(-1)||`osascript exited ${a}`))})})}var HE=90000;function df(t,e){let n=X(t),r=be(t,e).flatMap((i)=>{let[,s,o]=/^([a-z.]+)_(\d+)$/.exec(i.key)??[];return s&&o&&Z.some((a)=>a.key===s)?[{site:s,id:Number(o),...dh(n,i)}]:[]});return r.length>0?r:void 0}function z3(t,e){let n=new Set(Ht(X(t)).palettes[e.name]?.pictures.map((r)=>r.key));return(e.pictures??[]).filter((r)=>!n.has(fe(r)))}function LE(t,e){let n=new Set((e??[]).map((r)=>fe(r)));return{...t,pictures:(t.pictures??[]).filter((r)=>!n.has(fe(r)))}}async function q3(t,e,n,r,i,s){let o=Z.find((w)=>w.key===n.site);if(!o)throw Error(`no site called ${n.site}`);s("Fetching");let a=await Fi(o,n.id,i);if(!a)throw Error("the post is gone");if(o!==Pt&&a.md5)try{Sa([a],await Ea([a.md5],i))}catch{}let c={},u=(va(o,a)?ya(o,a.id,i).then((w)=>{if(w)Js(a,w)},()=>{}):Promise.resolve()).then(()=>a.named.artist.length>0?hu(a.named.artist,i):new Map).then((w)=>{c=Object.fromEntries([...w].filter(([,k])=>k.length>0))},()=>{});if(!lu(o,a,Hi(process.env.TTHEME_FIND_RATING))||uu(a,Ds(process.env.TTHEME_FIND_BLOCK)).length>0)throw Error("outside your find filters — TTHEME_FIND_RATING and TTHEME_FIND_BLOCK");let f=Pn(a);if(!f)throw Error("too large to use");let l=Ss(an(o),"orig",`${n.id}.${f.ext}`),d;if(Mg(l))d=new Uint8Array(ea(l));else{s("Downloading");let w=Li(o,a,f);d=await du(w.site,w.url,i,(k,v)=>s("Downloading",Nl(k,v))),L(l,d)}let h=Cr(d,Ae),m=!1;if(nr(h)===0&&ta()&&process.env.TTHEME_FIND_REMOVE_BG!=="off"){let w=Ss(an(o),"cut",`${n.id}.png`);try{if(!Mg(w))s("Cutting out"),NE(TE(w),{recursive:!0}),await Ic(l,w,i);let k=Cr(new Uint8Array(ea(w)),Ae);if(lf(nr(k)))h=k,m=!0}catch{}}await u;let g=uh(e);s("Drawing"),Su(t,g,In(g,e.signatureSlots),h,{site:o.key,id:n.id,ext:f.ext,bytes:d,from:`${o.name} ${n.id} ${o.pageUrl(n.id)}`,artist:a.named.artist,profiles:c,source:Ci(a.source),cut:m},{width:0,height:0},ei(t),ul(t));let b=be(t,e.name).find((w)=>w.key===fe(n));if(b)Aa(X(t),b,n,r,K3())}function D3(t,e){let n=Z.find((s)=>s.key===t.site),r=`${n?.name??t.site} ${t.id}`;if(!n||!e)return r;return`${Ft()?I.link:`${Zi(n.ansi)}${I.link}${kt}`} ${_u(r,n.pageUrl(t.id))}`}async function Es(t,e,n){let r=e.flatMap((c)=>z3(t,c).map((u)=>({entry:c,shared:u})));if(r.length===0)return;let i=ls(n),s=process.stdout.isTTY&&Iy(process.env),o=new Set,a=ui();for(let[c,{entry:u,shared:f}]of r.entries()){let l=`${u.name} · ${D3(f,s)}`,d=r.length>1?` · ${c+1}/${r.length}`:"",h=(m,g)=>a.set(`${m} ${l}${g?` · ${g}`:""}${d}`);try{await q3(t,u,f,i,AbortSignal.timeout(HE),h),a.say(` ▣ ${l}`),o.add(u)}catch(m){a.say(` ▢ ${l} — ${m instanceof Error?m.message:String(m)}`)}}a.done();for(let c of o){let u=(c.pictures??[]).find((f)=>be(t,c.name).some((l)=>l.key===fe(f)));if(u)ro(t,c.name,fe(u))}if(o.size>0)Be(t)}function FE(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 J3(t,e){let[,n,r]=/^(.+)_(\d+)$/.exec(t)??[],i=Ss(Rn(),n??"local","cut",`${r??t}.png`);if(!Mg(i)){if(!ta())return;NE(TE(i),{recursive:!0}),await Ic(e,i,AbortSignal.timeout(HE))}return Cr(new Uint8Array(ea(i)),Ae)}function Y3(t,e){try{return nr(Wt(new Uint8Array(ea(Ss(t,`${e.stem}.png`)))))>0}catch{return!1}}function ff(t,e){return()=>Cr(new Uint8Array(ea(Ss(t,e.original))),Ae)}function CE(t,e){let n=ff(t,e);return()=>{let r=n(),i=Wt(new Uint8Array(ea(Ss(t,e.cut))));return FE(r,i,0)?r:null}}async function hf(t,e,n,r,i,s,o,a){let c=X(t),u=Ht(c).palettes[e]?.pictures.find((f)=>f.key===n);if(!u?.original)return null;if(u.cut)return Na(t,e,u,CE(c,u),r,i,s,o,!1,a);if(no(u)){let f=ff(c,u)();if(nr(f)===0&&Y3(c,u)){let l=await J3(n,Ss(c,u.original));if(!l||!FE(f,l,3))return null;return Na(t,e,u,()=>f,r,i,s,o,!0,a)}return Na(t,e,u,()=>f,r,i,s,o,!1,a)}return Na(t,e,u,ff(c,u),r,i,s,o,!1,a)}function jE(t,e,n,r,i,s){let o=X(t),a=Ht(o).palettes[e]?.pictures.find((u)=>u.key===n);if(!a?.original||no(a))return!1;let c=a.cut?CE(o,a):ff(o,a);return H$(t,e,a,c,r,i,s)}var V3=/(?:^|[^0-9a-f])([0-9a-f]{32})(?:[^0-9a-f]|$)/i,Z3=[[/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 xg(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 _E(t,e){let n=V3.exec(e.source)?.[1]?.toLowerCase();return[`post:${t.key}:${e.id}`,...e.md5?[`md5:${e.md5}`]:[],...n&&n!==e.md5?[`md5:${n}`]:[],...Z3.flatMap(([r,i])=>{let s=r.exec(e.source)?.[1];return s?[`post:${i}:${Number(s)}`]:[]}),...e.family?[`family:${t.key}:${e.family}`]:[]]}function GE(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 BE(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),f=Math.max(u+1,Math.floor((c+1)*t.width/9)),l=0;for(let d=o;d<a;d++)for(let h=u;h<f;h++){let m=(d*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];l+=b*g+255*(1-g)}r.push(l/((f-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 X3(t,e){let n=BigInt(`0x${t}`)^BigInt(`0x${e}`),r=0;while(n>0n)r+=Number(n&1n),n>>=1n;return r}function UE(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&&X3(t.hash,e.hash)<=2}var r5={thumb:"tile",band:"band",match:"tile",show:"view",backdrop:"view",redraw:"view"},mf;async function i5(t){if(t.job==="redraw")return hf(t.home,t.name,t.key,t.paint,t.blur,t.aligns,t.user);if(t.job==="show"){if(mf?.from!==t.from){let o=Cr(new Uint8Array(Og(t.from)),Ae);mf={from:t.from,clear:nr(o),inked:ch(o)}}let{image:r,fill:i,opacity:s}=y$(mf.inked,t.colors,t.tone,t.width,t.height,t.blur,t.tune,t.coloring);return Q3(t5(t.to),{recursive:!0}),WE(t.to,qe(r)),{clear:mf.clear,fill:i,opacity:s}}let e=Cr(new Uint8Array(Og(t.from)),Ae);if(t.job==="backdrop"){Su(t.home,t.colors,t.tone,e,{...t.origin,bytes:new Uint8Array(Og(t.source)),cut:t.from!==t.source},t,t.blur,t.coloring);let r=t.tune&&be(t.home,t.colors.name).find((i)=>i.key===fe(t.origin));if(t.tune&&r)Aa(X(t.home),r,t.tune,t.aligns??!0,t.user??t.home);return 0}if(t.job==="match")return{match:AE(e,t.colors),hash:BE(e)};if(t.job==="thumb")return L(t.to,qe(e0(e,t.width,t.height))),0;let n=e.data.subarray(t.y*e.width*4,(t.y+t.height)*e.width*4);return WE(t.to,qe({width:e.width,height:t.height,data:n})),0}function s5(t){t.on("message",async(e)=>{try{t.postMessage({id:e.id,value:await i5(e)})}catch(n){t.postMessage({id:e.id,error:n instanceof Error?n.message:String(n)})}})}class Pg{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 n5(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 Ac{lines=new Map;run(t){let e=r5[t.job],n=this.lines.get(e);if(!n)n=new Pg,this.lines.set(e,n);return n.send(t)}close(){for(let t of this.lines.values())t.close();this.lines.clear()}}class Rg{lines;constructor(t){this.lines=Array.from({length:Math.max(1,t)},()=>new Pg)}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(!e5&&KE)s5(KE);import{existsSync as o5,mkdtempSync as a5,readFileSync as c5,rmSync as zE,writeFileSync as u5}from"node:fs";import{tmpdir as l5}from"node:os";import{basename as DE,join as qE}from"node:path";var f5=6;class Ig{dir;made=[];of(t,e){this.dir??=a5(qE(l5(),"ttheme-tint-"));let n=qE(this.dir,`${DE(t,".png")}.${e.slice(1).toLowerCase()}.png`);if(!o5(n)){let r=new Uint8Array(c5(t));u5(n,iu(r,e)??Ni(Ai(Wt(r)),e)),this.made.push(n);while(this.made.length>f5)zE(this.made.shift(),{force:!0})}return n}clear(){if(this.dir)zE(this.dir,{recursive:!0,force:!0});this.dir=void 0,this.made.length=0}}function JE(t,e,n,r,i){if(De(t)==="original")return e;let s=In(n,[...r]);return s.color===t.tone?e:i.of(e,s.color)}function YE(t,e){let n=DE(e);return t.find((r)=>n.startsWith(`${r.stem}.`)||n.startsWith(`${r.stem}@`))}var w5=2147483625,XE=2147483626,Dn=2147483627,$5=-1073741831,QE=-1073741830,k5=-1073741829,y5=4;function v5(t,e,n,r,i){let s=Math.trunc,o=n.col*r.w,a=n.row*r.h,c=s((Math.max(i.x,o)+r.w-1)/r.w),u=s(Math.min(i.x+i.w,o+n.cols*r.w)/r.w),f=s((Math.max(i.y,a)+r.h-1)/r.h),l=s(Math.min(i.y+i.h,a+n.rows*r.h)/r.h);if(u<=c||l<=f)return;return{col:c,row:f,cols:u-c,rows:l-f,x:s((c*r.w-i.x)*t/i.w),y:s((f*r.h-i.y)*e/i.h),w:s((u-c)*r.w*t/i.w),h:s((l-f)*r.h*e/i.h)}}function S5(t){try{let e=m5(t,"r"),n=Buffer.alloc(24);return p5(e,n,0,24,0),d5(e),n.readUInt32BE(0)===2303741511?{width:n.readUInt32BE(16),height:n.readUInt32BE(20)}:void 0}catch{return}}class pf{ready=()=>{};cell={w:0,h:0};held;tints=new Ig;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(Ft(t)||!yo(t,r)||!(vo(t)||es(t)))return;return new pf(t,e,n)}constructor(t,e,n){this.home=e,this.name=n,this.views=es(t),this.banded=sl(t),this.files=ol(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=X(this.home),e=He(t,this.name,g5()),n=[];try{n=Ht(t).palettes[this.name]?.pictures??[]}catch{}let r=e?YE(n,e.image):void 0;this.held=e&&r?{picture:r,image:e.image,opacity:e.opacity,cover:e.cover,at:Dt.indexOf(e.position)+1||5}:void 0}draw(t,e,n,r,i,s={col:0,row:0,cols:r,rows:i}){if(this.cell.w===0)return"";let o=t[0],a=this.look(t,e,n,s,!this.views||s.cols===r&&s.rows===i);if(this.views){let u=r*this.cell.w,f=i*this.cell.h,l=a?`${o}|${a.image}|${a.opacity}|${u}|${f}|${a.box.w}|${a.box.h}|${a.box.x}|${a.box.y}|${this.held?.at??5}`:`${o}||1|${u}|${f}|0|0|0|0|5`;if(l===this.viewed)return"";return this.viewed=l,ns(l)}let c=this.layer(w5,$5,"f=24",Buffer.from(ct(o)),s);if(a){let u=Math.max(0,Math.min(255,Math.round((1-a.opacity)*255)));c+=this.picture(a),c+=this.layer(XE,k5,"f=32",Buffer.from([...ct(o),u]),s)}else c+=this.drop(Dn)+this.drop(XE);return c}resized(){this.sent.clear(),this.placed.clear(),this.viewed=""}clear(){let t=this.views&&this.viewed?ns(""):"";for(let e of this.sent.keys())t+=Sc(e);return this.resized(),t}close(){let t=this.clear();if(this.tints.clear(),this.renders?.close(),this.scratch)VE(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,...oe([...t]),waived:[...n]},a=JE(s.picture,s.image,o,e,this.tints),c=S5(a);if(!c)return;let u=io(c.width,c.height,r.cols*this.cell.w,r.rows*this.cell.h,100,s.at,s.cover&&i),f={...u,x:u.x+r.col*this.cell.w,y:u.y+r.row*this.cell.h},l=v5(c.width,c.height,r,this.cell,f);if(!l)return;return{image:a,opacity:s.opacity,...c,box:f,rect:l}}layer(t,e,n,r,i){let s=r.toString("base64"),o=`${s}|${i.col}|${i.row}|${i.cols}|${i.rows}`;if(this.placed.get(t)===o)return"";return this.sent.set(t,o),this.placed.set(t,o),`\x1B_Ga=t,${n},s=1,v=1,i=${t},q=2;${s}\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 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(Dn)!==e){let s=Vl({id:Dn,path:e,row:0,col:0,cols:0,rows:0,z:QE},this.files);if(s===void 0)return"";r+=s,this.sent.set(Dn,e),this.placed.delete(Dn)}let i=`${n.col};${n.row};${n.cols};${n.rows};${n.x};${n.y};${n.w};${n.h}`;if(this.placed.get(Dn)!==i)r+=`\x1B[${n.row+1};${n.col+1}H\x1B_Ga=p,i=${Dn},p=${Dn},x=${n.x},y=${n.y},w=${n.w},h=${n.h},c=${n.cols},r=${n.rows},C=1,z=${QE},q=2\x1B\\`,this.placed.set(Dn,i);return r}drop(t){if(!this.sent.has(t))return"";return this.sent.delete(t),this.placed.delete(t),Sc(t)}band(t,e,n){let r=`${t}|${e}|${n}`,i=this.bands.get(r);if(i)return i;this.scratch??=h5(ZE(b5(),"ttheme-edit-")),this.renders??=new Ac;let s={path:ZE(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<=y5)break;if(a.ready&&a.path!==this.sent.get(Dn))this.bands.delete(o),VE(a.path,{force:!0})}return s}}var Ms=50;function ut(t,e){return dn(t,e)}function Nc(t){return Mt(t)>0.35?"#000000":"#ffffff"}function Ag(t,e){return t.held!==void 0&&t.held-e.c>0.0005?t.held:void 0}function gf(t,e,n,r){let i=e.mode==="tune"&&e.channel===se,s=e.ratio(),{floor:o}=e.partner(),a=(g)=>Math.round(Math.log(Math.max(1,g))/Math.log(21)*(n-1)),c=a(s),u=o===void 0?-1:a(o),f=r===void 0?-1:a(r),l=i?"━":"─",d=Array.from({length:n},(g,b)=>b===c?t.bold("●"):b===f?"○":b===u?"┃":b<u?t.dim(l):l).join(""),h=`${s.toFixed(2)}:1`.padStart(6),m={kind:"channel",channel:se};return`${ut(m,i?t.bold("▸◐"):t.dim(" ◐"))} ${ut({kind:"bar",channel:se},d)} ${ut(m,i?t.bold(h):t.dim(h))}`}function bf(t,e){if(!t.misses().has(e))return;if($g(t.list,t.signature,t.waive,"bright-follows").includes(e))return e-T.length<8?"= makes the bright follow its normal":"= on the normal makes this follow it";return"f moves the colors the gate misses"}function wf(t,e,n){let r=yg(t.list,t.signature,t.waive,e),i=Ag(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}function $f(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 tM(t){return`${t.l.toFixed(2)} ${t.c.toFixed(3)} ${t.h.toFixed(0).padStart(3)}°`}function E5(t,e,n,r=Ms){let i=vg(e.list,e.signature,e.waive).sort((u,f)=>Number(u.ok!==!1)-Number(f.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 f=`${u.value} ${u.bound}`,l=` ${Bu(t,u.ok)} ${At(u.ok===!1?u.label:t.dim(u.label),t.dim(f),a-2)}`,d=[...new Set(u.slots)].map((g)=>Ue(g).name),h=u.slots[0],m=(g)=>h===void 0?g:ut({kind:"slot",slot:h},g);return d.length>0?[m(l),m(` ${t.dim(tt(d.join(" · "),a-2))}`)]:[m(l)]});return[s===0?o:At(o,`${t.bold("n")} ${t.dim("next miss")}`,r-2),...c.slice(0,Math.max(0,n-1))]}function eM(t,e){let n=t-T.length;if(n>=0)return e===String(n)||e===`B${n}`||e===`K${n}`;return t===3&&e==="s"||t===2&&e==="c"}function kf(t,e,n,r){let i=r?$t("under"):"";if(n==="d")return`${t.fg(e.foreground)}${$t("dim")}${i}`;if(n==="b")return`${t.fg(e.foreground)}${$t("bold")}${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"?$t("bold"):""}${i}`}function Tc(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 f=c??"#000000";if(u===o)return`${t.bg(f)}${t.fg(Nc(f))}${I.on}${he}`;if(u===a)return c?`${t.bg(c)}${t.fg(Nc(c))}${I.off}${he}`:`${t.fg("#aaaaaa")}${I.off}`;return c?`${t.fg(c)}█`:`${t.fg(r?"#777777":"#555555")}░`}).join("").concat(kt)}function yf(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 zn(o.l,o.c,o.h)?en(o.l,o.c,o.h):void 0})}function xs(t,e,n,r){return Math.round((t-e)/(n-e)*(r-1))}function Ng(t){return vg(t.list,t.signature,t.waive).filter((e)=>e.ok===!1).length}function Hc(t,e,n,r){if(n<3)return[];let i=Ng(e),s=i===0?" Gate ✓ passes ":` Gate ✗ ${i} · n next `;return[t.dim(Gt(r,"top",[[2,s]])),...E5(t,e,n-1,r-1).slice(1).map((o)=>Ve(t,o,r)),t.dim(Gt(r,"bottom"))]}var Mr=0.98,Lc=0.12,M5=0.37,nM=0.74,x5=0.15,O5=-1073741828,Tg=-1073741827,Hg=-1073741826,P5=-1073741825,R5=2147483584,I5=["panel","plane","hue","contrast","mark","hue-thumb","contrast-thumb","origin","hue-origin","contrast-origin"],A5=4096;function Fc(t,e){return Xo(t,e,M5)}function Sf(t,e,n){let r=Fc(t,n);return r>0.000001?Math.min(1,e/r):0}function Cc(t,e){return{width:t,height:e,data:new Uint8Array(t*e*4)}}function wi(t,e,n,r,i){let s=r[3]*i;if(s<=0||e<0||n<0||e>=t.width||n>=t.height)return;let o=(n*t.width+e)*4,a=t.data;if(s>=1){a[o]=r[0],a[o+1]=r[1],a[o+2]=r[2],a[o+3]=255;return}let c=a[o+3]/255,u=s+c*(1-s);for(let f=0;f<3;f++)a[o+f]=Math.round((r[f]*s+a[o+f]*c*(1-s))/u);a[o+3]=Math.round(u*255)}function Er(t,e=1){return[...ct(t),e]}function ra(t,e,n,r,i,s,o){let a=Math.abs(t-(n+i/2))-(i/2-o),c=Math.abs(e-(r+s/2))-(s/2-o);return Math.hypot(Math.max(a,0),Math.max(c,0))+Math.min(Math.max(a,c),0)-o}function Os(t,e,n,r){let i=[],s=[],o=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 f=a;f<u;f++)for(let l=o;l<c;l++){let d=n(l+0.5,f+0.5);if(d>0.002)i.push(f*t+l),s.push(Math.min(1,d))}return{at:Uint32Array.from(i),cover:Float32Array.from(s)}}function Ps(t,e,n){for(let r=0;r<e.at.length;r++){let i=e.at[r];wi(t,i%t.width,Math.floor(i/t.width),n,e.cover[r])}}function Lg(t,e){return(n,r)=>Math.max(0,0.5-ra(n,r,t.x,t.y,t.w,t.h,e))}function rM(t,e,n){return(r,i)=>Math.max(0,0.5-Math.abs(ra(r,i,t.x,t.y,t.w,t.h,e)+n/2)+n/2)}var vf=new Map;function N5(t,e,n,r){let i=`${e.w}x${e.h} ${oM({...t,ground:"#000000",ink:"#000000",accent:"#000000"})}`,s=vf.get(i);if(s)return s;let{panel:o}=t,a={x:e.w,y:0,w:o.cols*e.w,h:o.rows*e.h},c=Math.round(e.h*0.45),u=Math.round(e.h*0.18),f=e.h*0.6,l=Math.max(1,Math.round(e.h/22)),d=(N)=>({x:(N.col-o.col+1)*e.w,y:(N.row-o.row)*e.h}),h=Math.max(1,Math.round(e.h*0.08)),m=d(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=d(t.field),S={x:v.x,y:v.y+h,w:t.field.cols*e.w,h:e.h-2*h},x=t.divider===void 0?void 0:{x:a.x+e.w*0.6,y:(t.divider-o.row)*e.h,w:a.w-e.w*1.2,h:l},M={shadow:Os(n,r,(N,C)=>{let P=ra(N,C,a.x,u,a.w,a.h,c);return P>0&&P<f?(1-P/f)**2:0}),fill:Os(n,r,Lg(a,c),a),border:Os(n,r,rM(a,c,l),a),track:Os(n,r,Lg(g,g.h*0.3),g),segment:Os(n,r,Lg(k,k.h*0.3),k),field:Os(n,r,rM(S,S.h*0.3,l),S),divider:x&&Os(n,r,()=>1,x)};if(vf.size>8)vf.clear();return vf.set(i,M),M}function T5(t){let e=Mt(t.ground)<0.18;return{dark:e,surface:Tt(t.ground,t.ink,e?0.07:0.04)}}function H5(t,e){let n=Cc((t.panel.cols+2)*e.w,(t.panel.rows+1)*e.h),r=N5(t,e,n.width,n.height),{dark:i,surface:s}=T5(t);if(Ps(n,r.shadow,[0,0,0,i?0.45:0.18]),Ps(n,r.fill,Er(s)),Ps(n,r.border,Er(t.ink,i?0.16:0.2)),Ps(n,r.track,Er(t.ink,i?0.06:0.07)),Ps(n,r.segment,Er(t.accent,i?0.24:0.2)),Ps(n,r.field,Er(t.ink,i?0.22:0.28)),r.divider)Ps(n,r.divider,Er(t.ink,i?0.12:0.16));return n}function L5(t,e,n){let r=Cc(Math.round(t.cols*n.w),Math.round(t.rows*n.h)),{width:i,height:s,data:o}=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)),f=t.rows*2-1,l=(h)=>Mr-Math.min(1,Math.max(0,((h+0.5)/n.h*2-0.5)/f))*(Mr-Lc),d=[];for(let h=0;h<s;h++){if(h%2===0){let m=l(h+0.5),g=Fc(m,e);d=Array.from({length:Math.ceil(i/2)},(b,w)=>zn(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>=s-a)?Math.min(1,Math.max(0,0.5-ra(m+0.5,h+0.5,0,0,i,s,a))):1;if(b<=0)continue;let w=d[m>>1],k=(h*i+m)*4;o[k]=w[0],o[k+1]=w[1],o[k+2]=w[2],o[k+3]=Math.round(b*255)}}return r}function sM(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 F5(t,e){let n=Cc(t.cols*e.w,e.h),{top:r,height:i,width:s}=sM(e,t.cols),o=Array.from({length:s},(a,c)=>{let f=Math.min(1,Math.max(0,((c+0.5)/e.w-0.5)/Math.max(1,t.cols-1)))*360;return zn(nM,Xo(nM,f,x5),f)??[0,0,0]});for(let a=r;a<r+i;a++)for(let c=0;c<s;c++){let u=Math.min(1,Math.max(0,0.5-ra(c+0.5,a+0.5,0,r,s,i,i/2))),f=o[c];wi(n,c,a,[f[0],f[1],f[2],1],u)}return n}function C5(t,e,n){let r=Cc(t.cols*n.w,n.h),{top:i,height:s,width:o}=sM(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(s*0.45)),u=i+Math.round((s-c)/2);for(let f=u;f<u+c;f++)for(let l=0;l<o;l++){let d=Math.min(1,Math.max(0,0.5-ra(l+0.5,f+0.5,0,u,o,c,c/2))),h=a<0||l>=a;wi(r,l,f,Er(e,h?t.lit?0.5:0.36:0.14),d)}if(a>=0){let f=Math.max(2,Math.round(n.w/5));for(let l=i-1;l<i+s+1;l++)for(let d=a-Math.floor(f/2);d<a-Math.floor(f/2)+f;d++)wi(r,d,l,Er(e,0.85),1)}return r}function j5(t,e,n,r,i,s,o){let a=Cc(t*o.w,e*o.h),c=Math.max(2,Math.round(i*0.3)),u=(l,d)=>Math.min(1,Math.max(0,l-d+0.5)),f=[0,0,0,0.5];for(let l=0;l<a.height;l++)for(let d=0;d<a.width;d++){let h=Math.hypot(d+0.5-n,l+0.5-r);if(s)wi(a,d,l,Er(s),u(i-c,h));else wi(a,d,l,f,u(i-c,h)-u(i-c-1,h));wi(a,d,l,f,u(i+1,h)-u(i,h)),wi(a,d,l,[255,255,255,1],u(i,h)-u(i-c,h))}return a}function na(t,e,n,r,i,s,o=P5){let a=Math.floor((e-r-2)/s.w),c=Math.floor((e+r+2)/s.w),u=Math.floor((n-r-2)/s.h),f=Math.floor((n+r+2)/s.h),l={row:u,col:a,cols:c-a+1,rows:f-u+1},d=Math.round((e-a*s.w)*2)/2,h=Math.round((n-u*s.h)*2)/2;return{name:t,key:`${l.cols}x${l.rows} ${d},${h} ${r} ${i??"-"}`,box:l,z:o,paint:()=>j5(l.cols,l.rows,d,h,r,i,s)}}function oM(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 _5(t,e){let n=`${e.w}x${e.h}`,r=Math.max(4,Math.round(e.h*0.34)),i=(l,d)=>(l.col+0.5+d*(l.cols-1))*e.w,s=(l)=>(l.row+0.5)*e.h,o=t.plane,a=(l)=>{let d=(Mr-l)/(Mr-Lc)*(o.rows*2-1);return o.row*e.h+(Math.min(o.rows*2-1,Math.max(0,d))+0.5)*e.h/2},c=a(o.l),u=[{name:"panel",key:`${n} ${oM(t)}`,box:{row:t.panel.row,col:t.panel.col-1,cols:t.panel.cols+2,rows:t.panel.rows+1},z:O5,paint:()=>H5(t,e)},{name:"plane",key:`${n} ${o.cols}x${o.rows} ${o.h.toFixed(2)}`,box:o,z:Tg,paint:()=>L5(o,o.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:Tg,paint:()=>F5(t.hue,e)},{name:"contrast",key:`${n} ${t.contrast.cols} ${t.contrast.floor??"-"} ${t.contrast.lit} ${t.ink}`,box:{...t.contrast,rows:1},z:Tg,paint:()=>C5(t.contrast,t.ink,e)},na("mark",i(o,Sf(o.l,o.c,o.h)),c,r,void 0,e),na("hue-thumb",i(t.hue,t.hue.h/360),s(t.hue),r,t.hue.color,e),na("contrast-thumb",i(t.contrast,t.contrast.at),s(t.contrast),r,t.contrast.color,e)],f=t.origin;if(f){let l=Math.max(3,Math.round(r*0.55));u.push(na("origin",i(o,Sf(f.l,f.c,f.h)),a(f.l),l,f.color,e,Hg),na("hue-origin",i(t.hue,f.h/360),s(t.hue),l,f.color,e,Hg),na("contrast-origin",i(t.contrast,f.at),s(t.contrast),l,f.color,e,Hg))}return u}function G5(t,e){let r=e.toString("base64").match(new RegExp(`.{1,${A5}}`,"g"))??[""];return r.map((i,s)=>{let o=s<r.length-1?1:0;return s===0?`\x1B_Ga=t,f=100,i=${t},m=${o},q=2;${i}\x1B\\`:`\x1B_Gm=${o},q=2;${i}\x1B\\`}).join("")}function iM(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 Fg(t){return`\x1B_Ga=d,d=I,i=${t},q=2\x1B\\`}class Ef{cell={w:0,h:0};shown=new Map;static of(t,e){return Ft(t)||!yo(t,e)||!vo(t)?void 0:new Ef}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?_5(t,this.cell):[],n="";for(let r of e)n+=this.put(r);for(let[r,i]of this.shown)if(!e.some((s)=>s.name===r))n+=Fg(i.id),this.shown.delete(r);return n}clear(){let t="";for(let e of this.shown.values())t+=Fg(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,iM(n.id,t.box,t.z)}let r=R5+I5.indexOf(t.name)*2,i=n?.id===r?r+1:r;return this.shown.set(t.name,{key:t.key,id:i,at:e}),`${G5(i,qe(t.paint()))}${iM(i,t.box,t.z)}${n?Fg(n.id):""}`}}var jc=34,Cg=2,B5=6,xf=3,U5=7,cM="↑↓ L ←→ C ⇧←→ H tab ◐";function W5(t,e,n){let r="",i=0;for(let s of t){let o=i+G(s);if(o>e&&i<n)r+=i>=e&&o<=n?s:" ".repeat(Math.min(o,n)-Math.max(i,e));if(i=o,i>=n)break}return r}function Of(t){return t.reduce((e,n)=>e+G(n.text),0)}function Pf(t,e,n){let r=[],i=0;for(let s of t){let o=G(s.text),a=Math.max(e,i),c=Math.min(n,i+o);if(c>a)r.push({...s,text:W5(s.text,a-i,c-i)});i+=o}return r}function K5(t,e,n){return[...Pf(t,0,e),...n,...Pf(t,e+Of(n),Of(t))]}function z5(t,e){return t.map((n)=>{let r=e&&n.sgr?`${n.sgr}${n.text}${ke}`:n.text;return n.target?dn(n.target,r):r}).join("")}function uM(t){return t<T.length?T[t]:$n[(t-T.length)%8]}function lM(t,e,n,r){let i=t.signature.includes(qn[n])?I.signature:e.color?I.swatch:" ";return e.color?`${e.fg(t.list[n])}${i}${r}`:i}function fM(t,e,n,r,i){return r.has(n)?e.bold(I.miss):t.changed(n)?e.color?`${$t("warn")}${I.on}${i}`:I.on:" "}function dM(t,e,n){return n?t.color?`${t.fg(e.cursor)}${I.gutter}${kt} `:`${I.gutter} `:" "}function q5(t,e,n,r,i,s){let o=r===t.slot(),a=o?e.fg(n.foreground):kt,c=uM(r).padEnd(12),u=t.lch[r],f=`${dM(e,n,o)}${lM(t,e,r,a)} ${o?e.bold(c):c}${tM(u)} ${fM(t,e,r,s,a)}`,l=tt(f,i);return ut({kind:"open",slot:r},o&&e.color?`${e.bg(n.selection)}${e.fg(n.foreground)}${l}${he}`:l)}var jg=8,hM=44;function Gc(t){return t>=hM?16:11}function aM(t,e,n,r,i,s){let o=Gc(i);if(!t.visible(r))return" ".repeat(o);let a=r===t.slot(),c=a&&e.color?e.fg(n.foreground):kt,u=t.lch[r],f=(g,b)=>g.toFixed(b).replace(/^0(?=\.)/,""),l=`${u.h.toFixed(0).padStart(3)}°`,d=i>=hM?`${f(u.l,2)} ${f(u.c,3)} ${l}`:`${f(u.l,2)} ${l}`,h=`${lM(t,e,r,c)} ${d}${fM(t,e,r,s,c)}`,m=a&&e.color?`${e.bg(n.selection)}${e.fg(n.foreground)}${h}${he}`:h;return ut({kind:"open",slot:r},m)}function D5(t,e,n,r,i,s){let o=T.length+r,a=o+8,c=t.row===o,u=$n[r].padEnd(jg),f=t.linkOf(a)!==void 0?e.dim("⇠"):" ";return`${ut({kind:"open",slot:o},`${dM(e,n,c)}${c?e.bold(u):u}`)}${aM(t,e,n,o,i,s)}${f} ${aM(t,e,n,a,i,s)}`}function mM(t){return 14+2*Gc(t)}function J5(t){let e=Gc(t)>=16;return[[2," ANSI "],[2+jg,e?" Normal 0–7 ":" Normal "],[5+jg+Gc(t),e?" Bright 8–15 ":" Bright "]]}function Y5(t,e,n,r){let i=t.slot(),s=Ue(i),o=mM(r),a=o-2,c=` ${s.name}${i>=T.length?` · ${s.about}`:""} `,u=[` ${e.dim(xE(i))}`];if(i>=2){let l=ZS(n,i).filter((m)=>m.count>0),d=l.length>0?l.map((m)=>`${m.name} ${m.count}`).join(" · "):"none",h=me("w",t.where?Ye(e,"w where"):e.dim("w where"));u.push(At(` ${e.dim("Shown in")} ${d}`,`${h} `,a))}let f=i-T.length;if(f===0||f===7||f===8||f===15){let l=t.lch[i].l,d=t.lch[0].l,h=t.lch[1].l,m=Math.abs(l-d)<=Math.abs(l-h)?"the background":"the text";u.push(` ${e.dim(`L ${l.toFixed(2)} reads near ${m}`)}`)}return[e.dim(Gt(o,"top",[[2,c]])),...u.map((l)=>Ve(e,l,o)),e.dim(Gt(o,"bottom"))]}function Mf(t,e){return Mr-t*(Mr-Lc)/(e*2-1)}function pM(t,e,n,r,i){let s=Mf(Math.max(0,Math.min(e*2-1,t*2-0.5)),e),o=Math.max(0,Math.min(1,(n-0.5)/Math.max(1,r-1)));return{lightness:s,chroma:o*Fc(s,i)}}function V5(t,e,n,r,i,s){let o=(l)=>{let d=Math.max(0,Math.min(i*2-1,Math.round((Mr-l.l)/(Mr-Lc)*(i*2-1))));return{row:Math.floor(d/2),col:Math.round(Sf(l.l,l.c,l.h)*(r-1))}},{row:a,col:c}=o(e),u=s?o(s):{row:-1,col:-1},f=(l,d)=>{return`#${(zn(l,d*Fc(l,e.h),e.h)??[0,0,0]).map((m)=>m.toString(16).padStart(2,"0")).join("")}`};return Array.from({length:i},(l,d)=>{let h="";for(let m=0;m<r;m++){if(d===a&&m===c){h+=t.color?`${t.bg(n)}${t.fg(Nc(n))}${I.on}${he}`:I.on;continue}let g=m/Math.max(1,r-1);if(d===u.row&&m===u.col){let b=f(Mf(d*2+1,i),g);h+=t.color?`${t.bg(b)}${t.fg(Nc(b))}${I.off}${he}`:I.off;continue}h+=t.color?`${t.fg(f(Mf(d*2,i),g))}${t.bg(f(Mf(d*2+1,i),g))}▀${he}`:"·"}return ut({kind:"plane",row:d,rows:i},h)})}function gM(t,e,n){let r=t.slot(),i=t.lch[r],o=wf(t,r,i).filter((c)=>c.ok===!1||c.text.startsWith("Chroma ○")).flatMap((c)=>vt(c.text,n-2).map((u,f)=>`${f===0?c.ok===!1?e.bold(I.miss):e.dim(I.off):" "} ${u}`)),a=bf(t,r);return[...o.slice(0,3),...a?[e.dim(a)]:[]]}function bM(t,e,n){let r=t.pair(t.slot());if(!r)return;let i=t.slot()>=r.bright,s=uM(i?r.normal:r.bright).toLowerCase(),o=`${r.lift>=0?"+":""}${r.lift.toFixed(2)}`,a=n-9,c=i?r.on?[`⇠ Linked to ${s} · L ${o}`,`⇠ ${s} · L ${o}`,`⇠ ${s}`]:[`Not linked to ${s}`,"Not linked"]:r.on?[`Bright follows · L ${o}`,"Bright follows"]:["Its bright moves on its own","Moves on its own"],u=c.find((f)=>G(f)<=a)??c[c.length-1]??"";return At(e.dim(u),me("l",`${e.bold("l")} ${e.dim(r.on?"unlink":"link")}`),n)}function wM(t,e,n){let r=t.slot(),i=t.list[r],s=t.lch[r],o=t.typing!==void 0?e.bold(`${t.typing}▏`):me("#",e.bold(PE(t.format,i,s))),a=t.start[r],c=e.color?`${e.fg(a)}${I.swatch}${kt} `:"";return At(o,a!==i?e.dim(`was ${c}${a}`):"",n)}function Z5(t,e,n,r){let i=t.slot(),s=t.lch[i],o=t.list[i],a=n-4,c=e.dim("│"),u=(M)=>`${c} ${tt(M,a)} ${c}`,f=bM(t,e,a),l=6+(f?1:0),d=gM(t,e,a).slice(0,Math.max(0,r-l-xf)),h=Math.max(xf,Math.min(B5,r-l-d.length)),m=" L × C ",g=` H ${s.h.toFixed(0)}° `,b=Math.max(0,n-4-G(" L × C ")-G(g)),w=[`${e.dim("╭─")}${e.dim(" L × C ")}${e.dim("─".repeat(b))}${e.dim(g)}${e.dim("─╮")}`],k=t.origin();for(let M of V5(e,s,o,a,h,k?.lch))w.push(u(M));let v=wn[2];w.push(u(ut({kind:"bar",channel:2},Tc(e,yf(s,v,a),xs(s.h,v.min,v.max,a),t.mode==="tune"&&t.channel===2,k&&xs(k.lch.h,v.min,v.max,a))))),w.push(u(gf(e,t,Math.max(8,a-11),k?.ratio)));let S=(M,N)=>ut({kind:"format",format:N},t.format===N?Ye(e,M):e.dim(` ${M} `));if(w.push(u(`${S("Hex","hex")} ${S("RGB","rgb")} ${S("OKLCH","oklch")}`)),w.push(u(wM(t,e,a))),f)w.push(u(f));for(let M of d)w.push(u(M));let x=tt(` ${cM} `,n-4,!1);return w.push(`${e.dim("╰─")}${e.dim(x)}${e.dim("─".repeat(Math.max(0,n-4-G(x))))}${e.dim("─╯")}`),{lines:w.map((M)=>ut({kind:"picker"},M))}}var _c=[["Hex","hex"],["RGB","rgb"],["OKLCH","oklch"]];function X5(t,e,n,r){let i=t.lch[t.slot()],s=n-2,o=bM(t,e,s),a=6+(o?1:0),c=gM(t,e,s).slice(0,Math.max(0,r-a-xf)),u=Math.max(xf,Math.min(U5,r-a-c.length)),f=(M)=>` ${tt(M,s)} `,l=[f(At(e.dim("L × C"),e.dim(`H ${i.h.toFixed(0)}°`),s))];for(let M=0;M<u;M++)l.push(f(ut({kind:"plane",row:M,rows:u}," ".repeat(s))));let d=l.length;l.push(f(ut({kind:"bar",channel:2}," ".repeat(s))));let h=l.length,m=t.mode==="tune"&&t.channel===se,g={kind:"channel",channel:se},b=`${t.ratio().toFixed(2)}:1`.padStart(8),w=s-11;l.push(f(`${ut(g,m?e.bold("◐"):e.dim("◐"))} ${ut({kind:"bar",channel:se}," ".repeat(w))} ${ut(g,m?e.bold(b):e.dim(b))}`));let k=l.length,v=Math.floor(s/_c.length);l.push(f(_c.map(([M,N],C)=>{let P=C===_c.length-1?s-v*C:v,_=Math.floor((P-G(M))/2),K=`${" ".repeat(_)}${M}${" ".repeat(P-_-G(M))}`,B=t.format===N?e.color?e.accent(e.bold(K)):`[${M}]`.padEnd(P):e.dim(K);return ut({kind:"format",format:N},B)}).join("")));let S=l.length;l.push(f(` ${wM(t,e,s-2)} `));let x=o?l.length:void 0;if(o)l.push(f(o));for(let M of c)l.push(f(M));return l.push(f(e.dim(cM))),{lines:l.map((M)=>ut({kind:"picker"},M)),parts:{plane:{row:1,col:1,cols:s,rows:u},hue:{row:d,col:1,cols:s,rows:1},contrast:{row:h,col:3,cols:w,rows:1},tabs:{row:k,col:1,cols:s,rows:1},field:{row:S,col:1,cols:s,rows:1},divider:x}}}function Q5(t,e,n,r,i,s){let o=t.slot(),a=t.lch[o],c=t.list[o],u=(h)=>({row:r+h.row,col:i+h.col,cols:h.cols,rows:h.rows}),f=(h)=>Math.log(Math.max(1,h))/Math.log(21),l=t.partner().floor,d=t.origin();return{panel:{row:r,col:i,cols:n.plane.cols+2,rows:s},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:f(t.ratio()),floor:l===void 0?void 0:f(l),color:c,lit:t.channel===se},tabs:{...u(n.tabs),active:_c.findIndex(([,h])=>h===t.format),count:_c.length},field:u(n.field),divider:n.divider===void 0?void 0:r+n.divider,origin:d&&{...d.lch,color:d.hex,at:f(d.ratio)}}}function t4(t,e,n,r,i,s,o,a){let u=s??1,f=o-1-u,l=u-2,d=12+2*Gc(r)-Cg,h=a?X5:Z5,m=h(t,e,d,Number.POSITIVE_INFINITY),g=m.lines.length<=f||m.lines.length>l&&f>=l,b=g?f:l,w=m.lines.length<=b?m:h(t,e,d,b),k=g?u+1:u-w.lines.length,v=Array.from({length:o},(S,x)=>i[x]??"");return w.lines.forEach((S,x)=>{let M=k+x;if(M>=0&&M<o)v[M]=Dk(v[M],Cg,S)}),{lines:v,art:w.parts&&Q5(t,n,w.parts,k,Cg,w.lines.length)}}function e4(t,e,n,r,i){let s=r.side,o=Ng(t),a=t.changedOnly?e.warn(I.on):" ",c=o===0?e.dim("Gate ✓"):e.bold(`Gate ✗ ${o}`),u=At(` ${e.bold("Colors")} ${c}`,me("m",`${t.changedOnly?e.bold("⧩ changed"):e.dim("⧩ changed")}${a} `),s),f=i-1,l=t.misses(),d=mM(s),h=[],m,g=T.map((k,v)=>v).filter((k)=>t.visible(k));if(g.length>0){h.push(e.dim(Gt(d,"top",[[2," Base "]])));for(let k of g){if(k===t.slot())m=h.length;h.push(Ve(e,q5(t,e,n,k,d-2,l),d))}}let b=$n.map((k,v)=>v).filter((k)=>t.visible(T.length+k)||t.visible(T.length+k+8));if(b.length>0){h.push(e.dim(Gt(d,g.length>0?"mid":"top",J5(s))));for(let k of b){if(t.row===T.length+k)m=h.length;h.push(Ve(e,D5(t,e,n,k,s,l),d))}}if(g.length>0||b.length>0)h.push(e.dim(Gt(d,"bottom")));if(t.visible(t.slot()))h.push(...Y5(t,e,r,s));let w=Hc(e,t,f-h.length,d);return h.push(...Array.from({length:Math.max(0,f-h.length-w.length)},()=>""),...w),{lines:[u,...h.slice(0,f)],anchor:m===void 0?void 0:m+1}}function n4(t,e,n){let r=`${e.accent(I.current)} ${e.bold(t.options.title)} ${e.dim(`· ${t.options.name}`)}`,i=t.dirty(),s=t.changes(),o=e.warn(I.on),a=i?`${o} ${e.dim(s>0?`unsaved · ${s} changed`:"unsaved")}`:"",c=[t.resettable()?me("R",e.dim("Reset")):"",i?me("s",Ye(e,"Save")):""].filter(Boolean).join(" "),u=[r,a,c].filter(Boolean).join(" "),f=(h,m,g)=>me(h,g?Ye(e,m):e.dim(m)),d=[...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 At(u,`${d} `,n)}var r4={kind:"open",slot:0};function i4(t,e,n){return t.color?`${n?jk:t.bg(e.background)}${t.fg(e.foreground)}`:""}function s4(t,e,n,r,i,s){let o=Oc(r),a=i4(e,n,s),c=t.slot();return Array.from({length:r.rows},(u,f)=>{let l=o[f],d=[{text:" ",sgr:a}];if(l)l.forEach((g,b)=>{let w=i&&i.pane===r.id&&i.line===f&&i.run===b,k=e.color?w?`${a}${e.bg(n.foreground)}${e.fg(n.background)}`:`${a}${kf(e,n,g.role,sg(g.role,c))}${t.where&&!ig(g.role,c)?$t("dim"):""}`:"";d.push({text:g.text,sgr:k,target:{kind:"run",spot:{pane:r.id,line:f,run:b}}})});let h=Pf(d,0,r.width-1),m=r.width-Of(h);return m>0?[...h,{text:" ".repeat(m),sgr:a,target:r4}]:h})}function o4(t,e,n){let r=t.slotsHere();if(!r)return;let i=e.color?`${e.bg(n.background)}${e.fg(n.foreground)}`:"",s=e.color?`${i}${$t("dim")}`:"",o=(l)=>({text:l,sgr:s}),a="┌ Slots here ",c="└ enter its slot · esc ",u=[[o(`${a}${"─".repeat(jc-G(a)-1)}┐`)]],f=[["text",r.text]];if(r.ground!==r.text)f.push(["ground",r.ground]);for(let[l,d]of f){let h={kind:"open",slot:d},m=t.shown()[d],g=d<T.length?"":Ue(d).about;u.push([{text:"│ ",sgr:s,target:h},{text:l.padEnd(7),sgr:s,target:h},{text:I.swatch,sgr:e.color?`${i}${e.fg(m)}`:"",target:h},{text:" ",sgr:i,target:h},{text:Ue(d).name.slice(0,14).padEnd(14),sgr:i,target:h},{text:g.padEnd(jc-27),sgr:s,target:h},{text:" │",sgr:s,target:h}])}return u.push([o(`${c}${"─".repeat(jc-G(c)-1)}┘`)]),u.map((l)=>Pf(l,0,jc))}function a4(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,s=e.color?`${e.bg(n.background)}${e.fg(n.foreground)}`:"",o=e.color?`${s}${$t("dim")}`:"",a=t.menu==="export"?"Copy ":"Take from ",c=[[{text:`┌ ${a}${"─".repeat(Math.max(0,i-3-a.length))}┐`,sgr:o}]];return r.forEach((u,f)=>{let l=f===t.entry,d={kind:"entry",index:f};c.push([{text:"│",sgr:o},{text:` ${l?"▌":" "} ${u.padEnd(i-6)}`,sgr:l&&e.color?`${e.bg(n.selection)}${e.fg(n.foreground)}${$t("bold")}`:s,target:d},{text:"│",sgr:o}])}),c.push([{text:`└${"─".repeat(i-2)}┘`,sgr:o}]),c}var c4=["#ff5f57","#febc2e","#28c840"];function u4(t,e,n,r){let i=e.color?`${e.bg($M(n))}${e.fg(n.foreground)}`:"",s=[{text:" ",sgr:i}];for(let u of c4)s.push({text:"●",sgr:e.color?`${i}${e.fg(u)}`:""},{text:" ",sgr:i});s.push({text:" ",sgr:i});let o=VS(),a=(t.scene%o.length+o.length)%o.length;o.forEach((u,f)=>{let l={kind:"scene",scene:f};s.push(f===a?{text:` ${u} `,sgr:e.color?`${i}${e.bg(Xi(n.background,n.foreground,"tab"))}${$t("bold")}`:"",target:l}:{text:` ${u} `,sgr:e.color?`${i}${$t("dim")}`:"",target:l},{text:" ",sgr:i})});let c="⇧←→ ";return[...s,{text:" ".repeat(Math.max(0,r-Of(s)-G(c))),sgr:i},{text:c,sgr:e.color?`${i}${$t("dim")}`:""}]}function $M(t){return Xi(t.background,t.foreground,"bar")}function l4(t,e,n){let{frame:r}=n,i=Xi(e.background,e.foreground,"line"),s=t.color?`${t.bg(kM(e))}${t.fg(i)}`:"",o=t.color?`${t.bg($M(e))}${t.fg(i)}`:"",a=(u,f)=>u===r.row||u===r.row+r.rows-1||f===r.col||f===r.col+r.cols-1,c=[];for(let[u,f]of nE(n.rules))for(let[l,d]of f)c.push([u,l,[{text:d,sgr:a(u,l)?s:o}]]);return c}function kM(t){return Xi(t.background,t.foreground,"stage")}function yM(t,e){return xc(t,e,0)?.inner}function vM(t,e,n,r,i={}){let s=xc(e,n,t.scene);if(!s)return;let o=Ce(r),a=t.shown(),c=oe(a),u=oe(i.chrome?[...i.chrome]:t.list),f=e4(t,o,u,s,n-1),l=t.mode==="tune"?t4(t,o,u,s.side,f.lines,f.anchor,n-1,r&&i.art===!0):{lines:f.lines,art:void 0},d=l.lines,h=i.behind===!0,m=t.inspect?tf(s,t.spot):void 0,g=o.color?o.bg(kM(u)):"",b=Array.from({length:n-3},()=>[{text:" ".repeat(s.width),sgr:g}]),w=(P,_,K)=>{let B=P-2;if(B>=0&&B<b.length)b[B]=K5(b[B],_,K)},k=s.side+1;for(let[P,_,K]of l4(o,u,s))w(P,_-k,K);for(let P of s.tiles)s4(t,o,c,P,m,h).forEach((_,K)=>{w(P.row+K,P.col-k,_)});w(s.title.row,s.title.col-k,u4(t,o,u,s.title.cols));let v=m?o4(t,o,c):void 0;if(m&&v){let P=s.tiles.find((K)=>K.id===m.pane),_=Oc(P)[m.line]?.[m.run];if(_){let K=Math.max(0,Math.min(P.col-k+1+_.col,s.width-jc)),B=P.row+m.line,F=B+1,gt=F+v.length-2>n-2?B-v.length:F;v.forEach((Zt,at)=>{w(gt+at,K,Zt)})}}let S=a4(t,o,c);if(S){let P=Math.max(0,s.width-24-(t.menu==="import"?12:2));S.forEach((_,K)=>{w(2+K,P,_)})}let x=n4(t,o,s.width),M=o.dim("─".repeat(s.width)),N=o.dim("│"),C=[];for(let P=0;P<n-1;P++){let _=P===0?x:P===1?M:z5(b[P-2]??[],r);C.push(`${tt(d[P]??"",s.side)}${N}${_}`)}return{lines:C,art:l.art}}var SM=80,EM=24,_g=11;function f4(t,e,n,r){let i=Ag(e,n);return wn.map((s,o)=>{let a=e.mode==="tune"&&o===e.channel,c=n[s.key],u=`${c.toFixed(s.digits)}${s.wraps?"°":""}`.padStart(6),f=Tc(t,yf(n,s,r),xs(c,s.min,s.max,r),a,s.key==="c"&&i!==void 0?xs(i,s.min,s.max,r):void 0),l=s.key.toUpperCase(),d={kind:"channel",channel:o};return`${ut(d,a?t.bold(`▸${l}`):t.dim(` ${l}`))} ${ut({kind:"bar",channel:o},f)} ${ut(d,a?t.bold(u):t.dim(u))}`})}function d4(t,e){if(e.mode!=="tune"||e.slot()<T.length)return[];let n=Qo.map((i)=>ut({kind:"scope",scope:i},i!==e.scope?t.dim(i):Ye(t,i))),r=e.scoped().length;return[`${t.dim("Scope")} ${n.join(" ")}`,t.dim(r>1?`${r} slots move by the same step, each keeping its own color`:"This slot moves alone · a widens it")]}var MM={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 h4(t){return`oklch ${t.l.toFixed(3)} ${t.c.toFixed(3)} ${t.h.toFixed(0)}°`}function m4(t,e){return`${t.dim("oklch")} ${t.bold(`${e.l.toFixed(3)} ${e.c.toFixed(3)} ${e.h.toFixed(0)}°`)}`}function p4(t,e,n,r=Ms){let i=e.misses(),s=oe(e.list),o=e.slot(),a=(l)=>{let d=e.list[l],h=l===o,m=e.signature.includes(qn[l])?I.signature:t.color?I.swatch:" ",g=i.has(l)?I.miss:e.tone&&e.changed(l)?I.on:" ",w=`${t.color?`${t.fg(d)}${m}${h?t.fg(s.foreground):kt} `:`${m} `}${$f(e.lch[l])}${g}`;if(!h)return ut({kind:"slot",slot:l},` ${w}`);return ut({kind:"slot",slot:l},t.color?`${t.bg(s.selection)}${t.fg(s.foreground)} ${w}${he}`:`›${w}`)},c=(l)=>l?t.color?`${t.fg(s.cursor)}${I.gutter}${kt} `:`${I.gutter} `:" ",u=[t.dim(Gt(r,"top",[[2," Base "]]))];for(let l=0;l<T.length;l++){let d=l===e.row,h=T[l].padEnd(10);u.push(Ve(t,`${ut({kind:"slot",slot:l},`${c(d)}${d?t.bold(h):h}`)}${a(l)}`,r))}u.push(t.dim(Gt(r,"mid",[[2," ANSI "],[12," Normal 0–7 "],[29," Bright 8–15 "]])));for(let l=T.length;l<vr;l++){let d=l===e.row,h=$n[l-T.length].padEnd(10),m=ut({kind:"slot",slot:l+(e.col===1?8:0)},`${c(d)}${d?t.bold(h):h}`);u.push(Ve(t,`${m}${a(l)}${a(l+8)}`,r))}u.push(t.dim(Gt(r,"bottom")));let f=Hc(t,e,n-u.length,r);return[...u,...Array.from({length:Math.max(0,n-u.length-f.length)},()=>""),...f]}function g4(t,e,n){let r=oe(e.list),i=[` ${t.dim("Seeds")}`];ks.forEach((s,o)=>{let a=o===e.field,c=e.seeds[s.key],u=Array.from({length:_g},(b,w)=>{let k=s.min+(s.max-s.min)*w/(_g-1);return MM[s.key](bi({...e.seeds,[s.key]:k}))}),f=Tc(t,u,xs(c,s.min,s.max,_g),a),l=`${c.toFixed(s.digits)}${s.wraps?"°":""}`.padStart(6),d=MM[s.key](r),h=a?t.color?`${t.fg(r.cursor)}${I.gutter}${kt} `:`${I.gutter} `:" ",m=s.label.padEnd(17),g={kind:"field",field:o};i.push(`${ut(g,`${h}${a?t.bold(m):m}`)}${ut({kind:"seed",field:o},f)}${ut(g,` ${l} ${t.color?`${t.fg(d)}${I.swatch}${kt} `:""}${t.dim(d)}`)}`)}),i.push("");for(let s of vt("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.",Ms-4))i.push(` ${t.dim(s)}`);return i.push(""),[...i,...Hc(t,e,n-i.length,Ms)]}function RM(t,e,n,r,i,s){let o=Yt.indexOf(Qi(i)),a=Yt.map((f,l)=>ut({kind:"scene",scene:l},l!==o?t.dim(f.name):Ye(t,f.name))).join(" "),c=[At(a,t.dim("⇧←→"),n)],u=`${t.bg(e.background)}${t.fg(e.foreground)}`;for(let f of Qi(i).lines){let l=ko(f,n-2);if(!l)continue;if(c.length>=r)break;let d=t.color?l.map(([h,m])=>`${kf(t,e,m,eM(s,m))}${h}${ke}${u}`).join(""):l.map(([h])=>h).join("");c.push(`${u} ${tt(d,n-2)} ${t.color?ke:""}`)}return c}var b4=["Bk","Rd","Gr","Ye","Bl","Ma","Cy","Wh"];function xM(t,e,n,r,i,s,o){let a=(i-s)/(o-1),c=IM(e),u=oe(n),f=(l)=>Math.min(o-1,Math.max(0,Math.round((i-r(Ot(l)))/a)));return Array.from({length:o},(l,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 g=0;g<8;g++){let b=[" "," "," "," "," "],w=u.ansi[g],k=u.ansi[g+8],v=f(w)===d,S=f(k)===d,x=(N)=>{if(N===1&&v)return t.color?`${t.fg(w)}${I.on}`:I.on;if(N===3&&S)return t.color?`${t.fg(k)}${I.off}`:I.off;return b[N]},M=[0,1,2,3,4].map(x).join("");m+=c.has(g)?t.color?`${t.bg(u.selection)}${M}${he}`:M:`${M}${t.color?kt:""}`}return m})}function IM(t){let e=t.mode==="tune"?t.scoped():[t.slot()];return new Set(e.filter((n)=>n>=T.length).map((n)=>(n-T.length)%8))}function w4(t,e){let n=IM(e);return` ${b4.map((r,i)=>n.has(i)?t.bold(` ${r} `):t.dim(` ${r} `)).join("")}`}function $4(t,e){let n=oe(e),r=Array.from({length:40},(s,o)=>{let a=o*9+4.5,c=-1,u=999;for(let[f,l]of Object.entries(Pe)){let d=Re(a,l.center);if(d<=l.width&&d<u)u=d,c=Number(f)}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(Pe).map(Number)){let u=n.ansi[c+s],f=Math.min(39,Math.round(Ot(u).h/9));a[f]=t.color?`${t.fg(u)}${o}${kt}`:o}return` ${a.join("")}`};return[`${t.bold("Hue")} ${t.dim("0° 90° 180° 270° 360°")}`,`${t.dim("bands")} ${r}${t.color?kt:""}`,i(0,I.on),i(8,I.off)]}function k4(t,e,n){let r=Sr(n,e.signature,e.waive),i=(a)=>Ue(T.length+a).name,s=(a)=>Ot(n[T.length+a]).h.toFixed(0),o=[...Qn(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=Pe[yn(a)];return`${i(a)} ${s(a)}° · ${c.toFixed(0)}° outside ${u.name} ${u.center}±${u.width}°`}),...tr(r).map(([a,c])=>`${i(a)} and ${i(c).toLowerCase()} read as one color`)];return o.length>0?o.map((a)=>`${t.bold(I.miss)} ${a}`):[t.dim(`${I.ok} Every accent keeps its role and its bright`)]}function OM(t,e,n,r,i){let s=e.shown(),o=Math.max(...s.slice(T.length).map((u)=>Ot(u).c)),a=Math.max(0.2,Math.ceil(o/0.05)*0.05),c=[At(t.bold("Lightness"),t.dim("● normal ○ bright"),n),...xM(t,e,s,(u)=>u.l,1,0.3,8),w4(t,e)];if(i)c.push("",t.bold("Chroma"),...xM(t,e,s,(u)=>u.c,a,0,5),"",...$4(t,s));return[...c,...k4(t,e,s)].slice(0,r)}function y4(t,e,n){let r=(i,s)=>ut({kind:"view",view:s},e.view!==s?t.dim(` ${i} `):Ye(t,i));return At(`${r("Slot","slot")}${r("Relations","relations")}`,me("g",`${t.bold("g")} ${t.dim("switch")}`),n)}function v4(t,e,n,r){let i=e.slot(),s=e.list[i],o=e.lch[i],a=e.start[i],{name:c,about:u}=Ue(i),f=e.signature.includes(qn[i]),l=Math.max(8,Math.min(64,n-12));if(e.view==="relations"&&e.mode!=="tune")return[y4(t,e,n),"",...OM(t,e,n,r-2,!0)];let d=i>=T.length?t.dim("Uses underlined below"):f?t.dim("◆ signature"):"",h=[At(`${t.bold(c)} ${t.dim(u)}`,e.view==="relations"?"":d,n),""],m=t.color?`${t.fg(s)}${"█".repeat(8)}${kt} `:"",g=e.typing!==void 0?`${t.bold(`${e.typing}▏`)}`:void 0,[b,w,k]=ct(s);if(h.push(`${m}${g??m4(t,o)}`),h.push(`${m}${t.dim(`${s} · rgb ${b} ${w} ${k}`)}`),e.view!=="relations"){let M=t.color?`${t.fg(a)}${I.swatch}${kt} `:"";h.push(`${m}${a!==s?t.dim(`was ${M}${h4(e.lchOf(a)).slice(6)} · ${a}`):t.dim("as it opened")}`)}h.push(""),h.push(...f4(t,e,o,l),gf(t,e,l));let v=d4(t,e);if(v.length>0)h.push(...v);if(e.view==="relations")return h.push("",...OM(t,e,n,r-h.length-1,!1)),h;h.push("");for(let M of wf(e,i,o))vt(M.text,n-2).forEach((N,C)=>{h.push(`${C===0?Bu(t,M.ok):" "} ${M.ok===!1?N:t.dim(N)}`)});let S=bf(e,i);if(S)h.push(t.dim(` ${S}`));let x=r-h.length-1;if(x>=3)h.push("",...RM(t,oe(e.shown()),n,x,e.scene,i));return h}function S4(t,e,n,r){return[At(`${t.bold("Sample")} ${t.dim("what the seeds grow")}`,"",n),"",...RM(t,oe(e.list),n,r-2,e.scene,-1)]}var E4=[["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 M4(t,e,n){let r=[` ${t.bold("Help")}`,""];for(let[i,s]of E4.filter(([o])=>o!=="Pictures"||e.options.find))vt(s,n-16).forEach((o,a)=>{r.push(` ${t.bold((a===0?i:"").padEnd(11))} ${o}`)});return r}function x4(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=[At(` ${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)),f=Math.min(40,Math.max(12,...i.map((l)=>G(l.name))));if(i.slice(u,u+c).forEach((l,d)=>{let h=u+d===e.pick,m=l.colors,g=t.color?`${t.bg(m.background)} ${[...m.ansi].map((k)=>`${t.fg(k)}${I.swatch}`).join("")} ${t.fg(m.foreground)}Aa ${he}`:"",b=h?"▌ ":" ",w=l.name.padEnd(f);a.push(ut({kind:"choice",index:u+d},`${b}${h?t.bold(w):w} ${g}`))}),i.length===0)a.push(` ${t.dim(`No palettes match '${e.filter}'`)}`);return a}var O4=new Set(["enter","s","?","g","a","i"]);function PM(t,e,n){let r="EDIT",i="",s=[],o="";if(e.quitting)r="EDIT (QUIT)",i=e.added>0?`Discard changes and ${e.added} ${e.added===1?"picture":"pictures"}?`:"Discard changes?",s=[["y","discard"],["n","keep editing"]];else if(e.typing!==void 0)r="EDIT (TYPE)",i=t.dim("#rrggbb, rgb(r g b) or oklch(l c h)"),s=[["enter","set"],["ctrl+u","clear"]],o="esc back";else if(e.overlay==="keys")r="HELP",o="any key closes";else if(e.overlay==="open")r="EDIT (OPEN)",s=[["↑↓","palette"],["a-z","filter"],["enter","take its colors"]],o="esc close";else if(e.menu)r=e.menu==="export"?"EDIT (EXPORT)":"EDIT (IMPORT)",s=[["↑↓","item"],["enter","choose"]],o="esc close";else if(e.compare)r="EDIT (BEFORE)",i="The colors you started from",s=[["space","back to yours"]],o="esc back";else if(e.mode==="seeds")r="EDIT (SEEDS)",s=[["↑↓","seed"],["←→","step"],["⇧←→","×5"],["enter","tune the slots"],["o","open a palette"],["p","picture"],["?","keys"]],o="esc cancel";else if(e.mode==="tune")r="EDIT (TUNE)",s=[["↑↓","L"],["←→",e.channel===se?"ratio":"C"],["⇧←→","H"],["tab","◐"],...e.slot()>=T.length?[["a","scope"]]:[],[e.channel===se?"1-9":"0-9",e.channel===se?"ratio":"jump"],["#","type"],["enter","keep"]],o="esc undo";else if(e.inspect)r="EDIT (INSPECT)",s=[["←→↑↓","spot"],["⇧←→","tab"],["enter","its slot"],["i","leave"]],o="esc leave";else s=[["↑↓","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"]],o="esc cancel";if(!e.options.find)s=s.filter(([u])=>u!=="p"&&u!=="b");if(!e.options.exports||!e.roomy)s=s.filter(([u])=>u!=="x");if(!e.roomy)s=s.filter(([u])=>u!=="i"&&u!=="m");if(e.notice)i=t.warn(e.notice),s=[];let a=`${Ye(t,r)}${t.color?" ":" "}`,c=o?me(o.split(" ")[0],`${t.bold(o.split(" ")[0])} ${t.dim(o.split(" ").slice(1).join(" "))}`):"";for(;;){let u=[i,...s.map(([d,h])=>me(d,`${t.bold(d)} ${t.dim(h)}`))].filter(Boolean),f=`${a}${u.join(" ")}`,l=-1;if(s.forEach(([d],h)=>{if(h>0&&!O4.has(d))l=h}),G(f)+G(o)+3<=n||l<0)return o?At(f,c,n):tt(f,n);s=s.filter((d,h)=>h!==l)}}function P4(t,e,n,r,i={}){let s=Ce(r);if(e<SM||n<EM){let g=[s.bold("ttheme palette editor"),`Needs ${SM}×${EM} — now ${e}×${n}`,s.dim("esc cancels")];return{lines:Array.from({length:n},(b,w)=>tt(g[w]??"",e)),art:void 0}}if(t.viewport(e,n),!t.overlay&&t.mode!=="seeds"&&t.view==="slot"){let g=vM(t,e,n,r,i);if(g)return{lines:[...g.lines,PM(s,t,e)],art:g.art}}let o=t.failing().length,a=o===0?"✓ Passes the gate":`✗ ${o} ${o===1?"miss":"misses"} in the gate`,c=t.pictures>0?s.dim(`▣ ${t.pictures} ${t.pictures===1?"picture":"pictures"} `):"",u=t.resettable()?`${me("R",s.dim("Reset"))} `:"",f=`${t.dirty()?`${s.warn(I.on)} unsaved `:""}${u}${c}${s.dim(a)}`,l=`${s.accent(I.current)} ${s.bold(t.options.title)} ${s.dim(`· ${t.options.name}`)}`,d=n-4,h;if(t.overlay==="keys")h=M4(s,t,e);else if(t.overlay==="open")h=x4(s,t,e,d);else{let g=e-Ms-2,b=t.mode==="seeds"?g4(s,t,d):p4(s,t,d),w=t.mode==="seeds"?S4(s,t,g,d):v4(s,t,g,d);h=Array.from({length:d},(k,v)=>`${tt(b[v]??"",Ms)}${s.dim("│")} ${tt(w[v]??"",g)}`)}let m=[At(l,f,e),""];for(let g=0;g<d;g++)m.push(tt(h[g]??"",e));return m.push("",PM(s,t,e)),{lines:m,art:void 0}}var R4=new Set(["tab","a","#","l","enter","esc"]),I4=new Set(["picker","plane","bar","channel","format","scope","open","slot"]);function A4(t){if(!t)return!0;return t.kind==="key"?!R4.has(t.key):!I4.has(t.kind)}function N4(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&&A4(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 s=pM(r.row+e.exact.y,r.rows,e.exact.x,e.width,t.lch[t.slot()].h);t.plane(s.lightness,s.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 T4=[Gl,Bn,fi,$r];async function AM(t,e){let n=new Sg(t),r=e.backdrop,i=e.layer,s=(a)=>n.typing===void 0&&of(a),o=e.hosted?{modes:[$r,...di()],assume:[Bn,fi],burst:s}:{modes:[...T4,...di()],burst:s};return hi(o,async(a)=>{let c=!1,u=!1,f=new Map,l=new Gp,d=await a.ask(`${mm(hn,"")}${di().length>0?lS:""}\x1B[c`,(S)=>{if(S.kind==="color"){f.set(S.code,S.value);return}return l.see(S)},1000);if(d?.cell)a.pixels(d.cell);let h=Oy(f),m=h.map((S,x)=>S??n.start[x]),[g,b]=m;if(!h[3])m[3]=Xi(g,b,"selection");let w=new ds({write:(S)=>a.write(S),view:()=>{if(c)return;let{lines:S,art:x}=P4(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,yM(a.cols,a.rows)):r?.clear())??""}${i?.draw(x)??""}`}}}),k=(S=!1)=>{if(S)w.soon();else w.request()},v=async(S)=>{let x=t.find;if(!x)return;c=!0,a.write(`${r?.clear()??""}${i?.clear()??""}`);try{n.found(await x(n.edited(),S))}catch(M){n.notice=M instanceof Error?M.message:String(M)}if(u)return;c=!1,r?.load(),w.reset(rs),k()};if(a.write(rs),a.onResize(()=>{r?.resized(),a.write(i?.clear()??""),w.reset(rs),w.request()}),r)r.load(),r.ready=()=>w.request();if(r||i){let S=new dc;a.ask(jl,(x)=>S.see(x),1000).then((x)=>{if(x)r?.measured(x),i?.measured(x);w.request()})}k();try{let{edited:S}=await a.loop((x)=>{if(c)return;if(x.kind==="paste")n.paste(x.text);else if(x.kind==="key")n.press(x.key);else if(x.kind==="mouse")N4(n,w.point(x),x);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 M=n.wants;if(M)n.wants=void 0,v(M.start);return},()=>{if(!c)k(!0)});return S}finally{u=!0,w.stop(),a.write(`${r?.close()??""}${i?.clear()??""}`)}})}import{spawn as J4}from"node:child_process";import{createHash as qM}from"node:crypto";import{existsSync as Uc,mkdirSync as Y4,mkdtempSync as V4,readFileSync as Z4,rmSync as Rf}from"node:fs";import{homedir as X4,tmpdir as Q4}from"node:os";import{basename as tj,dirname as ej,join as Jn}from"node:path";import{setTimeout as nj}from"node:timers/promises";import{pathToFileURL as HM}from"node:url";import{existsSync as H4,readFileSync as L4,statSync as F4}from"node:fs";import{join as NM}from"node:path";function C4(t,e){try{return JSON.parse(L4(NM(an(t),e),"utf8"))}catch{return{}}}function j4(t,e,n){L(NM(an(t),e),`${JSON.stringify(n)}
728
- `)}var _4=604800000;class Gg{caches=new Map;unsaved=new Set;owners=new Map;crediting=new Map;inflight=new Map;asking=new Map;home;manifest;entry;signal;credited;constructor(t){this.home=t.home,this.manifest=t.manifest,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 Ma(t,e,this.signal),s=Li(t,e),o=(i===void 0?await _0(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=Z.find((i)=>i.key===e);if(r)j4(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(!va(n,r))return Promise.resolve();let i=Ne(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}links(t){let e=this.keep(Pt,"profiles.json");return Object.fromEntries(t.flatMap((n)=>{let r=e[n]?.urls??[];return r.length>0?[[n,r]]:[]}))}profile(t,e){return this.credit(t,e).then(()=>this.profiles(t.post.named.artist,e))}async mateOwners(t){let e=this.owners.get(t.key);if(e)return e;let n=I$(this.home),r=this.keep(t,"owners.json"),i=this.manifest.palettes.flatMap((c)=>{let u=n.get(c.name);return ne(c)===ne(this.entry)&&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 Fi(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=N0(o);return this.owners.set(t.key,a),a}async cached(t,e,n,r){if(H4(e))return F4(e).size;let i=this.inflight.get(e);if(i)return i;let s=(async()=>{let o=await du(t,n,this.signal,r);return L(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=C4(t,e),this.caches.set(n,r);return r}async profiles(t,e){let n=this.keep(Pt,"profiles.json"),r=Date.now(),i=t.filter((s)=>!this.asking.has(s)&&r-(n[s]?.at??0)>=_4);if(i.length>0){let s=hu(i,e).then((o)=>{for(let a of i)n[a]={at:Date.now(),urls:o.get(a)??[]};this.unsaved.add(`${Pt.key}/profiles.json`),this.credited()},()=>{}).finally(()=>{for(let o of i)this.asking.delete(o)});for(let o of i)this.asking.set(o,s)}await Promise.all(t.flatMap((s)=>this.asking.get(s)??[]))}async credits({site:t,post:e},n){let r=this.keep(t,"credits.json"),i=r[e.id];if(!i){try{i=await ya(t,e.id,n)}catch{return}if(!i?.owner)return;r[e.id]=i,this.unsaved.add(`${t.key}/credits.json`)}Js(e,i),this.credited()}}import{rmSync as G4}from"node:fs";import{join as B4}from"node:path";var ia=2147483645,Bc=2147483646,TM=-1073741827,U4=-1073741828,W4=16,K4=0.4,z4=3221225472,q4=256;function D4(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 Bg=D4(process.env.TTHEME_BG_MARGIN);class Ug{screen;gliding;sent=new Map;placed=new Map;covered="";viewed="";bands=sl(process.env);files=ol(process.env);moves=Ay(process.env);layers=vo(process.env);wipes=Ny(process.env);views=es(process.env);bandFiles=new Map;nextBand=z4;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 ds({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=ng(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>=Zp){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=Vl(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+=Qp(a.id);r+=GS(a,n),this.placed.set(a.id,c)}}for(let o of this.sent.keys())if(!i.has(o))r+=Sc(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=kr(t,e).height,r=()=>{let i=this.view,s=i.top*Et.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)*K4)),this.draw(),this.gliding=setTimeout(r,W4)};r()}snap(){clearTimeout(this.gliding),this.gliding=void 0,this.view.scroll=this.view.top*Et.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 ng({...t,scroll:t.top*Et.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(ct(this.background)).toString("base64");if(r+=`\x1B_Ga=t,f=24,s=1,v=1,i=${ia},q=2;${i}\x1B\\`,Bg)r+=`\x1B_Ga=t,f=32,s=1,v=1,i=${Bc},q=2;AAAAAA==\x1B\\\x1B[H\x1B_Ga=p,i=${Bc},p=${Bc},c=1,r=1,C=1,z=${U4},q=2\x1B\\`}else if(!this.moves)r+=Qp(ia);if(this.covered=n,Bg){let{x:i,y:s}=Bg;return`${r}\x1B_Ga=p,i=${ia},p=${ia},P=${Bc},Q=${Bc},H=${-i},V=${-s},c=${t+2*i},r=${e+2*s},C=1,z=${TM},q=2\x1B\\`}return`${r}\x1B[H\x1B_Ga=p,i=${ia},p=${ia},c=${t},r=${e},C=1,z=${TM},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,ns(o)}caret(){return`\x1B[1;${Math.min(this.grid().cols,G(`⌕ ${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:B4(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<=q4)return;if(e.ready&&!this.sent.has(e.id))this.bandFiles.delete(t),G4(e.path,{force:!0})}}}var Rs=[{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:Ks,multi:{read:Hi}},{name:"TTHEME_FIND_BLOCK",label:"Block",about:"Posts tagged with nudity or underwear are left out — space unticks one",choices:Ti,multi:{read:Ds,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"]},...ta()?[{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:w0,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:$0,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:Z.map((t)=>t.name),multi:{read:$a},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:Fd,multi:{read:ou,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 LM(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 ka(e).join(" ");return t.choices.find((n)=>n===e)??t.choices[0]}var rj=["fit","newest","score"];function Wg(t){return rj.find((e)=>e===t)??"fit"}var ij={left:-1,right:1,"shift-left":-10,"shift-right":10};function FM(t){if(process.env.SSH_CONNECTION||!/^(?:https?|file):/i.test(t))return;try{let e=J4(process.platform==="darwin"?"open":"xdg-open",[t],{stdio:"ignore",detached:!0});e.on("error",()=>{}),e.unref()}catch{}}function sj(t,e,n){if(e<0){if(t!=="fill")return Math.max(Af,t+e);if(!n)return t;return Math.max(Af,Math.max(100,n)+e+1)}return t==="fill"||t+e>n?"fill":t+e}function DM(t,e){return t.size===e.size&&t.at===e.at&&t.opacity===e.opacity}function oj(t,e){if(DM(t,e))return;return{...t.size!=="fill"?{size:t.size}:{},...t.at!==e.at?{position:Dt[t.at-1]}:{},...t.opacity!==e.opacity?{opacity:t.opacity}:{}}}function CM(t,e){let n=X(t);return be(t,e).flatMap((r,i)=>{let[,s,o]=/^([a-z.]+)_(\d+)$/.exec(r.key)??[],a=[...Z,Kn].find((c)=>c.key===s);if(!a||!o)return[];return[{key:r.key,id:Number(o),ansi:a.ansi,...a===Kn?{}:{page:a.pageUrl(Number(o))},up:i===0,from:Jn(n,r.original??r.fill)}]})}function aj(t){return t.length>=2&&!/^\d+$/.test(t)&&!t.includes("://")&&!/^[\w.]+:\d+$/.test(t)}var jM=12,cj=4,uj=150,lj=300,_M=12,fj=2,dj=5000,hj=150,mj="\x1B[?5522$p\x1B]72;t=q\x1B\\\x1B[c",pj=4000,gj=8000,GM=/\.(png|jpe?g|gif|webp|heic|tiff?|bmp)$/i,bj=process.platform==="win32"?"alt+v":"ctrl+v",BM=process.platform==="darwin"?"ctrl+shift+cmd+4 copies a screenshot":"copy a picture first",wj=1280,$j=16,kj=Dt.indexOf("top-right")+1,Af=20,UM=2,WM=3,yj=/[\p{Script=Hangul}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]/u,vj=8,Sj=9;function If(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 Wc(t){if(!(t instanceof Error))return String(t);if(t instanceof AggregateError&&t.errors[0])return Wc(t.errors[0]);if(t.cause)return Wc(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 Kg(t,e){return`${t}: ${Wc(e)}`}function KM(t){return t.width*t.height}function zM(t,e){return`${t}-${qM("sha1").update(e).digest("hex").slice(0,8)}`}class zg{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(Rs.map((t)=>[t.name,LM(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 Ac;showing;thumbless=new Set;current;fetch;settle;suggestTimer;suggesting;countTimer;counting;terminal;grabber=new dg((t)=>this.write(t),(t)=>void this.got(t));noticeTimer;peekTimer;peeked;attaching;done;scratch=V4(Jn(Q4(),"ttheme-find-"));home;manifest;entry;tagged;blurring;start;paint;kept;constructor(t,e,n,r,i){this.start=i,this.home=t,this.manifest=e,this.entry=n,this.tagged=new Set(e.palettes.flatMap((o)=>o.booru?[o.booru]:[])),this.tone=In(n,n.signatureSlots),this.blurring=ei(t);let s={size:"fill",at:kj,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:Wg(this.setting("TTHEME_FIND_ORDER")),solo:this.setting("TTHEME_FIND_SOLO")==="on",rating:Hi(this.setting("TTHEME_FIND_RATING")),block:Ds(this.setting("TTHEME_FIND_BLOCK")),sets:this.setting("TTHEME_FIND_SETS")==="show"?"show":"fold",narrow:this.narrowed(),enabled:$a(this.setting("TTHEME_FIND_SITES")),hide:ou(this.setting("TTHEME_FIND_HIDE")),hideTags:ka(this.setting("TTHEME_FIND_HIDE_TAGS")),advanced:!1,settings:Rs.map((o)=>({label:o.label,choices:[...o.choices],value:this.setting(o.name),default:LM(o,Da(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:CM(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,Yt.findIndex((o)=>o.name.toLowerCase()===process.env.TTHEME_SCENE)),details:!1,tune:{...s},untuned:s,coloring:ul(t),editing:r===""?"":void 0,chips:[]},this.paint=new Ug({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 Gg({home:t,manifest:e,entry:n,signal:this.signal,credited:()=>{this.show(),this.inform(),this.paint.draw()}}),this.pool=this.selected(this.view),this.syncChips(),this.board=If(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:Z[this.tab-1]}get sites(){return this.site?[this.site]:Z.filter((t)=>this.view.enabled.includes(t.name))}get tabName(){return this.site?.name??"all"}get tabAnsi(){return this.site?.ansi??cj}get nextTabName(){let t=(this.tab+1)%(Z.length+1);return t===0?"all":Z[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 jd(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 Jn(an(t),"orig",`${e}.${n}`)}previewPath(t){let{url:e}=cu(t.site,t.post);return Jn(an(t.site),"thumb",`${zM(t.post.id,e)}.${Gr(e)}`)}tileOf(t,e){let{site:n,post:r}=t,i=Ne(n,r.id),s=Pn(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===Kn?"":n.pageUrl(r.id),artist:n===Kn?lE(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&&of(e);return hi({modes:[$r,...di()],assume:[Bn,fi],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(rs);let n=new Promise((i)=>{this.done=i}),r=setInterval(this.onClock,250);setTimeout(Pu,0);try{let i=new dc,s=await e.ask(jl,(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(mj,(o)=>o.kind==="attributes"?!0:void 0,500,!1);if(this.grabber.start(),e.hold(wS),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\\${rs}`),this.kept.save(),this.renders.close(),Rf(this.scratch,{recursive:!0,force:!0}),T0()}})}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!au(e,this.site??Z[0]);return Zo(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 — ${BM}`);return}this.pasted(t.text);return}await this.bring(()=>rf(t.bytes,t.source))}notice(t,e=pj){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 pE()}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 · ${bj} uses it`,clearTimeout(this.peekTimer),this.peekTimer=setTimeout(()=>{t.hint=void 0,this.paint.draw()},gj),this.paint.draw()}async fromClipboard(){let t=this.view;if(fg()){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 mE(Jn(this.scratch,`clipboard-${Date.now()}.png`))}catch(r){this.notice(`Could not read the clipboard: ${Wc(r)}`);return}if(clearTimeout(this.peekTimer),t.hint=void 0,"image"in e){await this.bring(async(r)=>({...await lg(e.image,r),source:"clipboard"}));return}let n=e.text.trim();if(!n){this.notice(`No picture on the clipboard — ${BM}`);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=au(e,this.site??Z[0]);if(i){await this.jump(i.site,i.id);return}}let[n,...r]=Zo(e).sort((i,s)=>Number(!GM.test(i))-Number(!GM.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)=>lg(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(Wc(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=dE(i.bytes);fE(s,i.source);let o=this.origPath(Kn,s,i.ext);L(o,i.bytes);let a=HM(o).href,c={id:s,file:a,width:i.width,height:i.height,ext:i.ext,preview:a,owner:"",score:0,rating:"s",md5:qM("md5").update(i.bytes).digest("hex"),source:i.source,tags:[],named:{artist:[],character:[],copyright:[]},solo:void 0,family:0,smaller:[]},u={site:Kn,post:c},f=this.previewPath(u);L(f,i.bytes),++this.gen,this.current=void 0,n.shown=void 0;let l=If(`local|post:${s}`,!1);this.board=l,this.boards.set(l.key,l),this.single(l,u)}single(t,e){t.searching=!1,this.posts.set(Ne(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)=>On(i)>On(r)?i:r),e=Math.ceil((On(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<$s.cols||this.rows<$s.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)FM(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*kr(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=Af+Math.round(i*(s-Af+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}=kr(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=Z.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"||t==="O"){this.openPage(t==="O");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=vc(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=vc(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=zS(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(Rs[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":ka(r).join(" "),n.typing=void 0,this.recount(),e==="enter"){this.paint.draw();return}this.panelKey(e);return}let i=ps(r,e,(s)=>t.entry==="number"?/^[0-9]$/.test(s)&&r.length<eg:/^[\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),lj)}pending(){let t=(e)=>this.view.settings[Rs.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:Wg(t("TTHEME_FIND_ORDER")),rating:Hi(t("TTHEME_FIND_RATING")),narrow:jd(t("TTHEME_FIND_MIN_SCORE"),t("TTHEME_FIND_MIN_SIZE"),t("TTHEME_FIND_PNG")),enabled:$a(t("TTHEME_FIND_SITES"))}}async countPending(t){let e=this.pending(),n=this.site?[this.site]:Z.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 Ud(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=Rs.map((r)=>this.setting(r.name));t.settings.forEach((r,i)=>{let s=Rs[i];if(s)this.values.set(s.name,r.value)});let n=Rs.filter((r,i)=>this.setting(r.name)!==e[i]);if(n.length===0){this.paint.draw();return}this.save(n),t.rating=Hi(this.setting("TTHEME_FIND_RATING")),t.block=Ds(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=Wg(this.setting("TTHEME_FIND_ORDER")),t.solo=this.setting("TTHEME_FIND_SOLO")==="on",t.narrow=this.narrowed(),t.enabled=$a(this.setting("TTHEME_FIND_SITES")),t.hide=ou(this.setting("TTHEME_FIND_HIDE")),t.hideTags=ka(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=Jn(this.home,"ttheme","config.zsh");try{let n=Uc(e)?Z4(e,"utf8"):"";return L(e,t.reduce((r,[i,s])=>ll(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=ps(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=aj(n),i=q$(e,WM,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?Pk(this.manifest.palettes,this.entry,n).map((c)=>({value:c.booru,count:0,palette:c.name})):[],o=[...new Map([...s.slice(0,WM),...i].map((c)=>[c.value,c])).values()];if(t.suggest=o.length>0?o:void 0,i.length>0&&yj.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 F0(n,AbortSignal.any([this.signal,a.signal]));if(this.suggesting===a&&t.editing!==void 0){let u=new Map(c.map((l)=>[l.value,l.count])),f=new Set(o.map((l)=>l.value));t.suggest=[...o.map((l)=>({...l,count:u.get(l.value)??0})),...c.filter((l)=>!f.has(l.value))].slice(0,vj),t.pick=t.pick!==void 0&&t.pick<o.length?t.pick:void 0,this.paint.draw()}}catch{}},uj)}async commit(t){let e=au(t,this.site??Z[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=Z.indexOf(t)+1,this.syncSite(),this.current=void 0,this.view.shown=void 0,this.view.error=void 0;let r=If(`${t.key}|post:${e}`,!0);this.board=r,this.boards.set(r.key,r),this.show(),this.paint.draw();try{let i=await Fi(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(Ne(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(t){let e=this.view.tiles[this.view.focus],n=e&&this.posts.get(e.key);if(!n)return;let r=Ci(n.post.source),i=n.site===Kn?"":n.site.pageUrl(n.post.id),s=!t&&/^https?:\/\//i.test(r)?r:i;if(s)FM(s)}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"||t==="O"){this.openPage(t==="O");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=ij[t];if(i!==void 0){if(n.field===0)r.size=sj(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=A0(e,n),s=new Set([...r.artist,...r.character,...r.copyright]),o=Ci(n.source),a=/^https?:\/\//i.test(o)?o:e===Kn&&o.startsWith("/")?HM(o).href:void 0;return{page:e===Kn?"":e.pageUrl(n.id),source:o,...a?{link:a}:{},artists:r.artist,profiles:Object.fromEntries(Object.entries(this.kept.links(r.artist)).map(([c,u])=>[c,xa(u)])),characters:r.character,series:r.copyright,tags:n.tags.filter((c)=>!s.has(c)),...i?{rating:i}:{},...n.posted?{posted:n.posted}:{},ext:(Pn(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}=kr(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.manifest.palettes.find((r)=>r.booru===t);return n?Rk(n,e):[t]}syncChips(){let t=this.selected(this.view);this.view.chips=this.pool.slice(0,Sj).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 C0(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?j0(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((f)=>`~${f}`).join(" "):n[0],t.rate(e.rating),...t.narrow(e.narrow),o?"":s,e.order==="score"?t.best:""].filter(Boolean),c=[],u=[];for(let f of a)if(Bd([...c,f].join(" "))<=t.tagBudget)c.push(f);else u.push(f);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=If(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=Bd(a)+1<=o.tagBudget?o.uploadedBy:void 0;return[...u?[...c.keys()].map((f)=>({site:o,tags:`${a} ${u(f)}`,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})=>Ud(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=Kg(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,Kg(e.name,n)].filter(Boolean).join(" · ")}wants(){let{perRow:t,rowsVis:e}=kr(this.cols,this.rows);return this.view.tiles.length<(this.board.top+e+UM)*t}need(){let{perRow:t,rowsVis:e}=kr(this.cols,this.rows);return(e+UM)*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=H0(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===Pt?[]:e.filter((r)=>r.md5!=="");if(n.length>0)try{Sa(n,await Ea(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=Z.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<xn;let u=t.last.get(a);for(let f of c){let l=u&&GE(u.post,f)?u.set:`set:${a.site.key}:${f.id}`;u={post:f,set:l};let d=Ne(a.site,f.id);if(t.seen.has(d))continue;t.seen.add(d);let h={site:a.site,post:f};if(this.eligible(h))t.kin.set(h,[l,..._E(a.site,f)]),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?IE(i):i;else{let a=uf(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=[...uf(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(Ne(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=uf(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=xg(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++,KM(r.post)<=KM(s.post))continue;for(let a of[...i,...xg(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(Ne(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:_M},async()=>{while(n<t.length)await this.look(t[n++]),e?.()}))}look(t){let e=Ne(t.site,t.post.id),n=this.looking.get(e);if(!n)n=(async()=>{let r=this.previewPath(t),i=cu(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<jM&&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<jM&&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=Pn(e);if(!lu(t,e,this.view.rating)||uu(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"||I0(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=Ne(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)=>UE(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=CM(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,Xp(this.cols))){if(n.thumb||this.heldAsked.has(n.from))continue;this.heldAsked.add(n.from);let r=Jn(this.scratch,`held-${tj(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<_M&&this.thumbQueue.length>0){let t=this.thumbQueue.shift();this.thumbing++,this.thumb(t).catch(()=>{this.thumbless.add(Ne(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=Et.cols*this.cell.w,i=Et.rows*this.cell.h,s=cu(e,n),o=Jn(an(e),"tile",`${zM(n.id,s.url)}-${r}x${i}.png`);if(!Uc(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(Ne(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),hj),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.profile(n,r.signal),!Pn(n.post))return;let{site:i}=n,s=this.board;try{await Ma(i,n.post,r.signal);let o=Pn(n.post),a=this.origPath(i,t.id,o.ext);if(!Uc(a))e.fetching={id:t.key,got:0,size:0},this.paint.draw();let c=Li(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 f={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 l=await this.render(f,"plain");if(r.signal.aborted||s!==this.board)return;if(l.clear===0&&ta()&&this.setting("TTHEME_FIND_REMOVE_BG")!=="off"){if(e.preparing=void 0,e.cutting=t.key,this.paint.flush(),f.cut=await this.cutOut(i,t.id,a,r.signal),r.signal.aborted||s!==this.board)return;if(e.cutting=void 0,f.cut){e.preparing=t.key,this.paint.flush();let d=await this.render(f,"cut").catch(()=>{return});if(r.signal.aborted||s!==this.board)return;if(d&&lf(d.clear))f.using="cut";else Rf(f.cut,{force:!0}),f.cut=void 0,f.failed=!0}else f.failed=!0}if(this.current=f,e.tiles[e.focus]?.key===t.key)await this.present();this.preload()}catch(o){if(!r.signal.aborted&&!this.signal.aborted)e.error=Kg(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=Jn(an(t),"cut",`${e}.png`);if(Uc(i))return i;try{return Y4(ej(i),{recursive:!0}),await Ic(n,i,r),i}catch{Rf(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.profile(r,this.signal);if(this.prefetching>=fj||!r||!Pn(r.post))continue;let{site:i,post:s}=r;this.prefetching++,Ma(i,s,this.signal).then(async()=>{let o=Pn(s),a=this.origPath(i,s.id,o.ext),c=Li(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,wj),s=Math.max(1,Math.round(r*i/n)),o={...this.view.tune},{coloring:a}=this.view,c=!DM(o,this.view.untuned),u=o.opacity!==this.view.untuned.opacity,f=c?`-${o.size}-${o.at}${u?`-${Math.round(o.opacity*100)}`:""}`:"",l=Jn(this.scratch,`${t.site.key}-${t.id}${e==="cut"?"c":""}${a==="original"?"o":""}-${i}x${s}${f}.png`),d=`${t.site.key}:${t.id}:${e}:${a}:${i}x${s}`,h=this.clarity.get(d);if(h&&Uc(l))return t.fill=h.fill,{clear:h.clear,path:l,opacity:h.opacity,touched:u};let m=await this.renders.run({job:"show",from:e==="cut"?t.cut:t.path,to:l,width:i,height:s,colors:this.entry,tone:this.tone,blur:this.blurring*i/oh(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(l);return{clear:m.clear,path:l,opacity:m.opacity,touched:u}}keepTuned(t){this.tunedFiles.push(t);while(this.tunedFiles.length>$j){let e=this.tunedFiles.findIndex((n)=>n!==this.view.shown?.path&&n!==t);if(e===-1)return;Rf(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=oj(t.tune,t.untuned),i=this.posts.get(n.key),s=i?.post;if(i)await Promise.race([this.kept.profile(i,this.signal),nj(dj,void 0,{ref:!1})]);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:s?.named.artist??[],profiles:this.kept.links(s?.named.artist??[]),source:Ci(s?.source??"")},width:this.cols*this.cell.w,height:this.rows*this.cell.h,blur:this.blurring,coloring:t.coloring,...r?{tune:r,aligns:ls(q(this.home).terminals),user:X4()}:{}}),this.kept.owned(n.site,n.id,s?.owner??""),Be(this.home),this.holds();let{size:o,at:a,opacity:c}=t.tune,u=r?` · ${o==="fill"?"fill":`${o}%`} · ${Dt[a-1]} · ${c.toFixed(2)}`:"",f=s?.named.artist.length?`${s.named.artist.join(", ")} · `:"";t.saved={text:`Background · ${this.entry.name} ← ${f}${n.site.name} ${n.id}${u}`,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 JM(t,e,n){let r=new zg(t,$e(t),e,e.booru??"",n);if(await r.run(),es(process.env))process.stdout.write(ns(""));return{saved:r.saved,installs:r.installs}}async function YM(t){let e=Y(),n=$e(e),r=Hn(n.palettes,t);if(!process.stdin.isTTY||!process.stdout.isTTY)throw Error("needs a terminal");let i=new zg(e,n,r,r.booru??""),s=await i.run();if(i.saved&&s!==0)return process.stderr.write(`${i.saved}
729
- `),0;return s}var Is=((t)=>{return t[t.Border=-1]="Border",t[t.Data=0]="Data",t[t.Function=1]="Function",t[t.Position=2]="Position",t[t.Timing=3]="Timing",t[t.Alignment=4]="Alignment",t})(Is||{}),Ej=[0,1],ZM=[1,0],XM=[2,3],QM=[3,2],Mj={L:Ej,M:ZM,Q:XM,H:QM},xj=/^\d*$/,Oj=/^[A-Z0-9 $%*+./:-]*$/,qg="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:",Yg=1,Vg=40,VM=3,Pj=3,Nf=40,Rj=10,tx=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],ex=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]];class nx{constructor(t,e,n,r){if(this.version=t,this.ecc=e,t<Yg||t>Vg)throw RangeError("Version value out of range");if(r<-1||r>7)throw RangeError("Mask value out of range");this.size=t*4+17;let i=Array.from({length:this.size}).fill(!1);for(let o=0;o<this.size;o++)this.modules.push(i.slice()),this.types.push(i.map(()=>0));this.drawFunctionPatterns();let s=this.addEccAndInterleave(n);if(this.drawCodewords(s),r===-1){let o=1e9;for(let a=0;a<8;a++){this.applyMask(a),this.drawFormatBits(a);let c=this.getPenaltyScore();if(c<o)r=a,o=c;this.applyMask(a)}}this.mask=r,this.applyMask(r),this.drawFormatBits(r)}size;mask;modules=[];types=[];getModule(t,e){return t>=0&&t<this.size&&e>=0&&e<this.size&&this.modules[e][t]}drawFunctionPatterns(){for(let n=0;n<this.size;n++)this.setFunctionModule(6,n,n%2===0,Is.Timing),this.setFunctionModule(n,6,n%2===0,Is.Timing);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);let t=this.getAlignmentPatternPositions(),e=t.length;for(let n=0;n<e;n++)for(let r=0;r<e;r++)if(!(n===0&&r===0||n===0&&r===e-1||n===e-1&&r===0))this.drawAlignmentPattern(t[n],t[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(t){let e=this.ecc[1]<<3|t,n=e;for(let i=0;i<10;i++)n=n<<1^(n>>>9)*1335;let r=(e<<10|n)^21522;for(let i=0;i<=5;i++)this.setFunctionModule(8,i,xr(r,i));this.setFunctionModule(8,7,xr(r,6)),this.setFunctionModule(8,8,xr(r,7)),this.setFunctionModule(7,8,xr(r,8));for(let i=9;i<15;i++)this.setFunctionModule(14-i,8,xr(r,i));for(let i=0;i<8;i++)this.setFunctionModule(this.size-1-i,8,xr(r,i));for(let i=8;i<15;i++)this.setFunctionModule(8,this.size-15+i,xr(r,i));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let t=this.version;for(let n=0;n<12;n++)t=t<<1^(t>>>11)*7973;let e=this.version<<12|t;for(let n=0;n<18;n++){let r=xr(e,n),i=this.size-11+n%3,s=Math.floor(n/3);this.setFunctionModule(i,s,r),this.setFunctionModule(s,i,r)}}drawFinderPattern(t,e){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),s=t+r,o=e+n;if(s>=0&&s<this.size&&o>=0&&o<this.size)this.setFunctionModule(s,o,i!==2&&i!==4,Is.Position)}}drawAlignmentPattern(t,e){for(let n=-2;n<=2;n++)for(let r=-2;r<=2;r++)this.setFunctionModule(t+r,e+n,Math.max(Math.abs(r),Math.abs(n))!==1,Is.Alignment)}setFunctionModule(t,e,n,r=Is.Function){this.modules[e][t]=n,this.types[e][t]=r}addEccAndInterleave(t){let e=this.version,n=this.ecc;if(t.length!==Tf(e,n))throw RangeError("Invalid argument");let r=ex[n[0]][e],i=tx[n[0]][e],s=Math.floor(Dg(e)/8),o=r-s%r,a=Math.floor(s/r),c=[],u=jj(i);for(let l=0,d=0;l<r;l++){let h=t.slice(d,d+a-i+(l<o?0:1));d+=h.length;let m=_j(h,u);if(l<o)h.push(0);c.push(h.concat(m))}let f=[];for(let l=0;l<c[0].length;l++)c.forEach((d,h)=>{if(l!==a-i||h>=o)f.push(d[l])});return f}drawCodewords(t){if(t.length!==Math.floor(Dg(this.version)/8))throw RangeError("Invalid argument");let e=0;for(let n=this.size-1;n>=1;n-=2){if(n===6)n=5;for(let r=0;r<this.size;r++)for(let i=0;i<2;i++){let s=n-i,a=(n+1&2)===0?this.size-1-r:r;if(!this.types[a][s]&&e<t.length*8)this.modules[a][s]=xr(t[e>>>3],7-(e&7)),e++}}}applyMask(t){if(t<0||t>7)throw RangeError("Mask value out of range");for(let e=0;e<this.size;e++)for(let n=0;n<this.size;n++){let r;switch(t){case 0:r=(n+e)%2===0;break;case 1:r=e%2===0;break;case 2:r=n%3===0;break;case 3:r=(n+e)%3===0;break;case 4:r=(Math.floor(n/3)+Math.floor(e/2))%2===0;break;case 5:r=n*e%2+n*e%3===0;break;case 6:r=(n*e%2+n*e%3)%2===0;break;case 7:r=((n+e)%2+n*e%3)%2===0;break;default:throw Error("Unreachable")}if(!this.types[e][n]&&r)this.modules[e][n]=!this.modules[e][n]}}getPenaltyScore(){let t=0;for(let i=0;i<this.size;i++){let s=!1,o=0,a=[0,0,0,0,0,0,0];for(let c=0;c<this.size;c++)if(this.modules[i][c]===s){if(o++,o===5)t+=VM;else if(o>5)t++}else{if(this.finderPenaltyAddHistory(o,a),!s)t+=this.finderPenaltyCountPatterns(a)*Nf;s=this.modules[i][c],o=1}t+=this.finderPenaltyTerminateAndCount(s,o,a)*Nf}for(let i=0;i<this.size;i++){let s=!1,o=0,a=[0,0,0,0,0,0,0];for(let c=0;c<this.size;c++)if(this.modules[c][i]===s){if(o++,o===5)t+=VM;else if(o>5)t++}else{if(this.finderPenaltyAddHistory(o,a),!s)t+=this.finderPenaltyCountPatterns(a)*Nf;s=this.modules[c][i],o=1}t+=this.finderPenaltyTerminateAndCount(s,o,a)*Nf}for(let i=0;i<this.size-1;i++)for(let s=0;s<this.size-1;s++){let o=this.modules[i][s];if(o===this.modules[i][s+1]&&o===this.modules[i+1][s]&&o===this.modules[i+1][s+1])t+=Pj}let e=0;for(let i of this.modules)e=i.reduce((s,o)=>s+(o?1:0),e);let n=this.size*this.size,r=Math.ceil(Math.abs(e*20-n*10)/n)-1;return t+=r*Rj,t}getAlignmentPatternPositions(){if(this.version===1)return[];else{let t=Math.floor(this.version/7)+2,e=this.version===32?26:Math.ceil((this.version*4+4)/(t*2-2))*2,n=[6];for(let r=this.size-7;n.length<t;r-=e)n.splice(1,0,r);return n}}finderPenaltyCountPatterns(t){let e=t[1],n=e>0&&t[2]===e&&t[3]===e*3&&t[4]===e&&t[5]===e;return(n&&t[0]>=e*4&&t[6]>=e?1:0)+(n&&t[6]>=e*4&&t[0]>=e?1:0)}finderPenaltyTerminateAndCount(t,e,n){if(t)this.finderPenaltyAddHistory(e,n),e=0;return e+=this.size,this.finderPenaltyAddHistory(e,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(t,e){if(e[0]===0)t+=this.size;e.pop(),e.unshift(t)}}function Or(t,e,n){if(e<0||e>31||t>>>e!==0)throw RangeError("Value out of range");for(let r=e-1;r>=0;r--)n.push(t>>>r&1)}function xr(t,e){return(t>>>e&1)!==0}class Hf{constructor(t,e,n){if(this.mode=t,this.numChars=e,this.bitData=n,e<0)throw RangeError("Invalid argument");this.bitData=n.slice()}getData(){return this.bitData.slice()}}var Ij=[1,10,12,14],Aj=[2,9,11,13],Nj=[4,8,16,16];function rx(t,e){return t[Math.floor((e+7)/17)+1]}function ix(t){let e=[];for(let n of t)Or(n,8,e);return new Hf(Nj,t.length,e)}function Tj(t){if(!sx(t))throw RangeError("String contains non-numeric characters");let e=[];for(let n=0;n<t.length;){let r=Math.min(t.length-n,3);Or(Number.parseInt(t.substring(n,n+r),10),r*3+1,e),n+=r}return new Hf(Ij,t.length,e)}function Hj(t){if(!ox(t))throw RangeError("String contains unencodable characters in alphanumeric mode");let e=[],n;for(n=0;n+2<=t.length;n+=2){let r=qg.indexOf(t.charAt(n))*45;r+=qg.indexOf(t.charAt(n+1)),Or(r,11,e)}if(n<t.length)Or(qg.indexOf(t.charAt(n)),6,e);return new Hf(Aj,t.length,e)}function Lj(t){if(t==="")return[];else if(sx(t))return[Tj(t)];else if(ox(t))return[Hj(t)];else return[ix(Cj(t))]}function sx(t){return xj.test(t)}function ox(t){return Oj.test(t)}function Fj(t,e){let n=0;for(let r of t){let i=rx(r.mode,e);if(r.numChars>=1<<i)return Number.POSITIVE_INFINITY;n+=4+i+r.bitData.length}return n}function Cj(t){t=encodeURI(t);let e=[];for(let n=0;n<t.length;n++)if(t.charAt(n)!=="%")e.push(t.charCodeAt(n));else e.push(Number.parseInt(t.substring(n+1,n+3),16)),n+=2;return e}function Dg(t){if(t<Yg||t>Vg)throw RangeError("Version number out of range");let e=(16*t+128)*t+64;if(t>=2){let n=Math.floor(t/7)+2;if(e-=(25*n-10)*n-55,t>=7)e-=36}return e}function Tf(t,e){return Math.floor(Dg(t)/8)-tx[e[0]][t]*ex[e[0]][t]}function jj(t){if(t<1||t>255)throw RangeError("Degree out of range");let e=[];for(let r=0;r<t-1;r++)e.push(0);e.push(1);let n=1;for(let r=0;r<t;r++){for(let i=0;i<e.length;i++)if(e[i]=Jg(e[i],n),i+1<e.length)e[i]^=e[i+1];n=Jg(n,2)}return e}function _j(t,e){let n=e.map((r)=>0);for(let r of t){let i=r^n.shift();n.push(0),e.forEach((s,o)=>n[o]^=Jg(s,i))}return n}function Jg(t,e){if(t>>>8!==0||e>>>8!==0)throw RangeError("Byte out of range");let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(e>>>r&1)*t;return n}function Gj(t,e,n=1,r=40,i=-1,s=!0){if(!(Yg<=n&&n<=r&&r<=Vg)||i<-1||i>7)throw RangeError("Invalid value");let o,a;for(o=n;;o++){let l=Tf(o,e)*8,d=Fj(t,o);if(d<=l){a=d;break}if(o>=r)throw RangeError("Data too long")}for(let l of[ZM,XM,QM])if(s&&a<=Tf(o,l)*8)e=l;let c=[];for(let l of t){Or(l.mode[0],4,c),Or(l.numChars,rx(l.mode,o),c);for(let d of l.getData())c.push(d)}let u=Tf(o,e)*8;Or(0,Math.min(4,u-c.length),c),Or(0,(8-c.length%8)%8,c);for(let l=236;c.length<u;l^=253)Or(l,8,c);let f=Array.from({length:Math.ceil(c.length/8)},()=>0);return c.forEach((l,d)=>f[d>>>3]|=l<<7-(d&7)),new nx(o,e,f,i)}function ax(t,e){let{ecc:n="L",boostEcc:r=!1,minVersion:i=1,maxVersion:s=40,maskPattern:o=-1,border:a=1}=e||{},c=typeof t==="string"?Lj(t):Array.isArray(t)?[ix(t)]:void 0;if(!c)throw Error(`uqr only supports encoding string and binary data, but got: ${typeof t}`);let u=Gj(c,Mj[n],i,s,o,r),f=Bj({version:u.version,maskPattern:u.mask,size:u.size,data:u.modules,types:u.types},a);if(e?.invert)f.data=f.data.map((l)=>l.map((d)=>!d));return e?.onEncoded?.(f),f}function Bj(t,e=1){if(!e)return t;let{size:n}=t,r=n+e*2;t.size=r,t.data.forEach((s)=>{for(let o=0;o<e;o++)s.unshift(!1),s.push(!1)});for(let s=0;s<e;s++)t.data.unshift(Array.from({length:r},(o)=>!1)),t.data.push(Array.from({length:r},(o)=>!1));let i=Is.Border;t.types.forEach((s)=>{for(let o=0;o<e;o++)s.unshift(i),s.push(i)});for(let s=0;s<e;s++)t.types.unshift(Array.from({length:r},(o)=>i)),t.types.push(Array.from({length:r},(o)=>i));return t}var Uj=Gk(16,231),Wj=[" ","▀","▄","█"],Kj=2953;function cx(t){if(Buffer.byteLength(t)>Kj)return;let{data:e}=ax(t,{border:2,boostEcc:!0}),n=[];for(let r=0;r<e.length;r+=2){let i=e[r]??[],s=e[r+1]??[];n.push(`${Uj}${i.map((o,a)=>Wj[(o?1:0)+(s[a]?2:0)]).join("")}${ke}`)}return n}var zj=50;function qj(t){return{background:t.background,foreground:t.foreground,cursor:t.cursor,selection:t.selection,ansi:t.ansi}}function Dj(t,e,n){for(let r of n){let i=t-4-r.length;if(i>e.length+2)return[[2,e],[i,` ${r} `]]}return[[2,e]]}function ux(t,e,n,r=zj){let i=Ce(n),s=nn(qj(e)),o=gk(t).map((g)=>g.toLowerCase()),a=kg(s,e.signatureSlots,e.waived??[]),c=er(Sr(s,e.signatureSlots,e.waived??[])).length,u=(g)=>s[g]?.toLowerCase()!==o[g],f=s.filter((g,b)=>u(b)).length,l=(g)=>{let b=s[g],w=e.signatureSlots.includes(qn[g])?I.signature:n?I.swatch:" ",k=n?`${i.fg(b)}${w}${kt}`:w,v=a.has(g)?i.bold(I.miss):u(g)?i.warn(I.on):" ";return` ${k} ${$f(Ot(b))}${v}`},d=c===0?"passes the gate":`${c} ${c===1?"miss":"misses"} in the gate`,h=f>0?[`${f} tuned · ${d}`,d]:[d],m=[i.dim(Gt(r,"top",Dj(r," Palette ",h)))];for(let g=0;g<T.length;g++)m.push(Ve(i,` ${T[g].padEnd(10)}${l(g)}`,r));return m.push(i.dim(Gt(r,"mid",[[2," ANSI "],[12," Normal 0–7 "],[29," Bright 8–15 "]]))),$n.forEach((g,b)=>{m.push(Ve(i,` ${g.padEnd(10)}${l(T.length+b)}${l(T.length+8+b)}`,r))}),m.push(i.dim(Gt(r,"bottom"))),m}function sa(){return process.stdin.isTTY===!0&&process.stdout.isTTY===!0}async function Xg(){let t=process.env.TTHEME_WORN;if(!t||!sa())return;let e=await _e({message:`Use ${t}, the palette this tab wears?`});if(re(e)||!e)throw new pe;return t}async function dx(t){let e=process.env.TTHEME_WORN;if(!e)return;if(!sa())return console.error(`Sharing ${e}, the palette this tab wears`),{name:e,...t?{tone:t}:{}};if(t!==void 0||Kt(Y())[e]===void 0)return await Xg(),{name:e,...t?{tone:t}:{}};let n=await um({message:`Share ${e}, the palette this tab wears?`,options:[{value:"tuned",label:"Your tone",hint:`named ${Kc(e)}`},{value:"original",label:"The original"},{value:"no",label:"No"}]});if(re(n)||n==="no")throw new pe;return{name:e,tone:n}}function hx(t,e){if(t.includes("/"))return t;let n=Yi(e,!1),r=n.filter((s)=>ho(s.dir).some((o)=>o.slug===t)),[i]=r.length===1?r:n.length===1?n:[];return i?`${i.id}/${t}`:t}function Vj(t,e,n){let r=q(t),i=n.filter((s)=>!r.palettes.includes(s));if(i.length>0)tn(t,e,r,{...r,palettes:[...r.palettes,...i]});else if(n.some((s)=>r.palettes.includes(s)))qt(t,e,r);return{state:r,fresh:i}}function Zj(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 lx(t){return JSON.stringify([t.background,t.foreground,t.cursor,t.selection,t.ansi])}function mx(t,e,n){let r=dk(e,n.palettes),i=cr(t,n,!1).palettes.find((s)=>s.name===r.name);if(i&&lx(i)!==lx(r))throw Error(`${r.name} is already in ${et(r.name)??"the official marketplace"} and differs — \`ttheme add ${r.name}\` wears that one`);if(!i)go(t,[...Jr(t),r]);return r}var Xj=["background","foreground","cursor"];function px(t){try{t();return}catch(e){return e.message}}function gx(t,e,n){return zt(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 bx(t,e){let n=new Set(be(t,e).map((r)=>r.key));return{count:()=>be(t,e).length,added:()=>be(t,e).filter((r)=>!n.has(r.key)).length,fresh:()=>(df(t,e)??[]).filter((r)=>!n.has(fe(r))),discard:()=>{let r=be(t,e).filter((i)=>!n.has(i.key));for(let i of r)ro(t,e,i.key),vu(t,e);if(r.length>0)Be(t)}}}function Qj(...t){let e=new Map;for(let n of t.flatMap((r)=>r??[]))e.set(fe(n),n);return e.size>0?[...e.values()]:void 0}function wx(t,e,n,r){if(!yo(process.env,q(t).terminals))return;return async(i,s)=>{let o=un(Nn(e,r(i),n.palettes)),{saved:a}=await JM(t,o,s);return{...a?{note:a}:{},count:be(t,e).length}}}async function Qg(t,e=!1){let n=process.stdout.isTTY===!0,r=Y(),i=q(r).terminals,s=n?pf.of(process.env,r,t.name,i):void 0,o=n?Ef.of(process.env,i):void 0;return AM(t,{color:!Ft(),...s?{backdrop:s}:{},...o?{layer:o}:{},...e?{hosted:!0}:{}})}async function $x(t,e,n){let r=Y(),i=lt(r),s=await Xv(r,n),o=t.includes("/")?t:`${s.id}/${t}`,a=ee(o);if(a)throw Error(`${o} ${a}`);if(et(o)!==s.id)throw Error(`palettes in ${s.dir} are named ${s.id}/<palette> — ${o} belongs elsewhere`);let c=Rh(r,o);if(zc(c))throw Error(`${o} already exists — \`ttheme edit ${o}\` changes it`);let u=e?Hn(zt(r,i).palettes,e):void 0;if(!sa())throw Error("new opens the palette editor — run it in a terminal");let f=u&&(et(u.name)?u.base:u.default?void 0:u.name),l=u?Ah(u,o,`kept from ${u.name}`):void 0,d=u?df(r,u.name)??u.pictures:void 0,{base:h,ansiSource:m,...g}=l??{name:o,signature:Xj,...bi(Rc)},b=bx(r,o),w=({colors:S,signature:x})=>{let M=Qj(d,b.fresh());return Nh({...g,...S,signature:x,...f?{base:f}:{},...M?{pictures:M}:{}})},k=await Qg({title:"New palette",name:o,...l?{colors:l}:{},signature:g.signature,...g.waive?{waive:g.waive}:{},palettes:gx(r,i,o),pictures:b.count(),find:wx(r,o,i,w),exports:xx(r,o,i,w),decode:tb,check:(S)=>px(()=>Nn(o,w(S),i.palettes))});if(!k){b.discard(),console.log("Nothing made");return}Jj(Yj(c),{recursive:!0}),L(c,w(k));let{state:v}=Vj(r,i,[o]);console.log(` + ${o}${u?` from ${u.name}`:""}
730
- ${c}`),await Es(r,zt(r,i).palettes.filter((S)=>S.name===o),v.terminals),console.log(`
731
- \`ttheme use ${o}\` wears it · \`ttheme edit ${o}\` opens it again`)}function t6(t,e,n){let r=un(Nn(t,e,n.palettes));return Ua(r).length>0?Fa(r).filter((i)=>i.startsWith(" ✗")):[]}async function kx(t){let e=Y(),n=lt(e),r=q(e),i=zt(e,n,!1),s=hx(t,e),o=Lf(e,s),a=o&&zc(o)?s:i.palettes.some((k)=>k.name===t)?t:s,c=Lf(e,a),u=!c||!zc(c);if(u&&!i.palettes.some((k)=>k.name===a))throw Error(`no palette called ${a} — \`ttheme new\` makes one`);if(!sa())throw Error("edit opens the palette editor — run it in a terminal");if(u){let k=await Sx(e,a,!1);console.log(k===void 0?"Nothing changed":k===0?`${a} is back to its own colors`:`Saved ${a} · ${vx(k)} — R then s in \`ttheme edit ${a}\` puts its own colors back`);return}let f=Zg(c,"utf8"),l;try{l=Nn(a,f,n.palettes)}catch(k){throw Error(`${c} cannot be read — ${k.message}`)}let d=bx(e,a),h=new Set((l.pictures??[]).map((k)=>fe(k))),m=({colors:k,signature:v})=>ak(hk(Lh(f,k),v),d.fresh().filter((S)=>!h.has(fe(S)))),g=await Qg({title:"Edit palette",name:a,colors:po(l),signature:l.signatureSlots,waive:l.waive,palettes:gx(e,n,a),pictures:d.count(),find:wx(e,a,n,m),exports:xx(e,a,n,m),decode:tb,check:(k)=>px(()=>Nn(a,m(k),n.palettes))});if(!g){d.discard(),console.log("Nothing changed");return}let b=m(g);if(b===f){console.log(d.added()>0?`Kept the pictures you added to ${a}`:"Nothing changed");return}if(L(c,b),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 w=t6(a,b,n);if(w.length>0)console.log(`
728
+ }`;async function xE(){if(yg())return;if(process.platform==="darwin"){let[t="",e=""]=(await yn("osascript",["-l","JavaScript","-e",W3])).stdout.trim().split("\t");return{stamp:t,picture:e==="picture"}}if(process.platform==="linux"&&!EE()){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 mf(t){return t.length>8&&/^(?:\/|~\/|file:|https?:)/.test(t)}var Hc=(t)=>Buffer.from(t).toString("base64"),wg=(t)=>Buffer.from(t,"base64");function gE(t,e){return e.find((n)=>t.includes(n))}class vg{clipboard=!1;drops=!1;reading;offered=[];dropping;pw=Hc(bE("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;${bg.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=${Hc("ttheme")}:pw=${this.pw};${Hc(".")}\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?wg(t.mime).toString("utf8"):r.mime,e)r.chunks.push(wg(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=gE(s,[...$g,...H3]);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=${Hc(c)}:pw=${a};${Hc(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=bg.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=gE(a,bg);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(wg(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"?na(a).find((u)=>E3(u)):void 0;o=c?{kind:"bytes",bytes:new Uint8Array(hf(c)),source:c}:{kind:"text",text:a}}this.send("\x1B]72;t=r:o=1\x1B\\"),this.deliver(o)}}var Sg=5,K3=6,OE=0.05,z3=[1,2,3,4,5,6,9,10,11,12,13,14],PE=(t,e)=>(e-t+360)%360<=180?1:-1;function Jn(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((f)=>f**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((f)=>f<-0.0001||f>1.0001))return;return u.map((f)=>{let l=Math.min(1,Math.max(0,f));return Math.round(255*(l<=0.0031308?12.92*l:1.055*l**0.4166666666666667-0.055))})}function ra(t,e,n){if(Jn(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(Jn(t,o,e)===void 0)i=o;else r=o}return r}function nn(t,e,n){return`#${(Jn(t,ra(t,n,e),n)??[0,0,0]).map((i)=>i.toString(16).padStart(2,"0")).join("")}`}function q3(t,e){let{l:n,c:r}=Pt(t);return nn(n,r,(e+360)%360)}function D3(t,e,n){let{l:r,c:i,h:s}=Pt(t),o=xt(e)<0.18,a=(f)=>nn(o?r+(1-r)*f:r*(1-f),i,s);if(yt(a(1),e)<n+OE)return a(1);let c=0,u=1;for(let f=0;f<30;f++){let l=(c+u)/2;if(yt(a(l),e)>=n+OE)u=l;else c=l}return a(u)}function J3(t,e){let{l:n,c:r,h:i}=Pt(t),s=0,o=n;for(let a=0;a<30;a++){let c=(s+o)/2;if(xt(nn(c,r,i))<=e-0.005)s=c;else o=c}return nn(s,r,i)}function Y3(t,e,n){let r=Ae[e],[i,s]=[Pt(t[e]),Pt(t[e+8])],o=(f,l)=>n.has(f)?[l]:Array.from({length:2*r.width+1},(d,h)=>(r.center-r.width+h+360)%360),a=(f,l,d)=>an.every((h)=>{let m=(f>8?8:0)+h;if(m===f)return!0;let p=Pt(t[m]);return p.c<Ni||Ne(p.h,l)>=Bs+1||Math.abs(p.l-d)>=Gs}),c,u=Number.POSITIVE_INFINITY;for(let f of o(e,i.h)){if(!n.has(e)&&!a(e,f,i.l))continue;for(let l of o(e+8,s.h)){if(Ne(f,l)>on-Sg||!n.has(e+8)&&!a(e+8,l,s.l))continue;let d=Ne(f,i.h)+Ne(l,s.h);if(d<u)u=d,c=[f,l]}}return c}class IE{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,q3(this.theme.ansi[t],n))}roles(){let t=new Set(this.theme.signatureSlots);for(let{slot:n,hue:r}of Fr(this.theme)){let i=Ae[Mn(n)];this.rehue(n,"ansi-role",i.center+PE(i.center,r)*(i.width-Sg))}for(let{normal:n,gap:r}of nr(this.theme)){if(r<=on)continue;let[i,s]=t.has(`ansi${n+8}`)?[n+8,n]:[n,n+8],o=Pt(this.theme.ansi[i]).h,a=Pt(this.theme.ansi[s]).h;this.rehue(s,"bright-follows",o+PE(o,a)*(on-Sg))}let e=Us(this.theme);for(let[n,r]of rr(this.theme)){let i=Mn(e.has(r)?n:r),s=Y3(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(yt(this.get(a),o)<s)this.set(a,r,D3(this.get(a),o,s))};if(n("foreground",["foreground"],7),n("accents",z3.map((r)=>`ansi${r}`),3),n("light-ansi",["ansi7","ansi15"],7),n("ansi8-visible",["ansi8"],1.6),!t.has("ansi0-dark")&&xt(this.get("ansi0"))>0.15)this.set("ansi0","ansi0-dark",J3(this.get("ansi0"),0.15));n("selection",["selection"],7,this.theme.foreground)}net(){return[...Map.groupBy(this.moves,(t)=>t.slot)].flatMap(([t,e])=>{let 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 pf(t){let e=new IE(t);for(let n=0;n<K3;n++)if(e.readability(),e.roles(),ir(e.theme).length===0)break;return{theme:e.theme,moves:e.net(),left:ir(e.theme)}}var vs=[{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}],Fc={background:0.21,foreground:0.88,hue:265,tint:0.02,lightness:0.72,chroma:0.12,brights:0.06},RE=(t,e,n)=>Math.min(n,Math.max(e,t));function Eg(t,e,n){let r=t[e.key]+e.step*n,i=e.wraps?(r%e.max+e.max)%e.max:RE(r,e.min,e.max);return{...t,[e.key]:Math.round(i*1e4)/1e4}}function vi(t){let e=(r,i,s)=>nn(RE(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 an){let i=Ae[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 Yn=["background","foreground","cursor","selection",...Array.from({length:16},(t,e)=>`ansi${e}`)],F=["Background","Foreground","Cursor","Selection"],Sn=["Black","Red","Green","Yellow","Blue","Magenta","Cyan","White"],V3=["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"],Ss=F.length+Sn.length,vn=[{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}],AE=5,Z3=5,ae=vn.length,ia=["this","pair","normals","brights","accents"],CE=[1,2,3,4,5,6,9,10,11,12,13,14],NE=an.map((t)=>F.length+t),TE=an.map((t)=>F.length+8+t);function Mg(t,e){let n=e-F.length;if(n<0||t==="this")return[e];if(t==="pair")return[F.length+n%8,F.length+8+n%8];let r=t==="normals"?NE:t==="brights"?TE:[...NE,...TE];return r.includes(e)?r:[e]}function X3(){return Array.from({length:Ss},(t,e)=>e<F.length?[e]:[e,e+8]).flat()}function Q3(t){let e=t.trim();return/^https?:\/\/\S+$/i.test(e)||na(e).length>0}function rn(t){return[t.background,t.foreground,t.cursor,t.selection,...t.ansi]}function ce(t){let[e,n,r,i,...s]=t;return{background:e,foreground:n,cursor:r,selection:i,ansi:s}}function We(t){if(t<F.length)return{name:F[t],about:Yn[t]};let e=t-F.length,n=Sn[e%8];return e<8?{name:n,about:`ANSI ${e}`}:{name:`Bright ${n.toLowerCase()}`,about:`ANSI ${e}`}}function jE(t){let e=t-F.length;if(e>=9&&e<=15)return`Bold or bright ${Sn[e-8].toLowerCase()} text`;return V3[t]}var Es=(t,e,n)=>Math.min(n,Math.max(e,t));function HE(t){return t.length===1?t.toLowerCase():t}function t5(t){return Es(Math.round(t),0,255).toString(16).padStart(2,"0")}function FE(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)=>t5(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 nn(Es(s,0,1),Number(i[3]),Number(i[4])%360)}return}function Ms(t){let e=Te.find((n)=>n.rule===t);return e?.min??e?.max??0}function Or(t,e,n){let r=ce(t);return{name:"draft",background:r.background,foreground:r.foreground,selectionBackground:r.selection,ansi:r.ansi,waive:n,signatureSlots:e}}function e5(t,e){let n=t-F.length,r=t<=1?"foreground":t===3?"selection":n===7||n===15?"light-ansi":n===8?"ansi8-visible":CE.includes(n)?"accents":void 0;return{against:t===0||t===3?1:0,floor:r===void 0||e.includes(r)?void 0:Ms(r)}}function Ig(t,e,n,r){let i=Or(t,e,n),{background:s,foreground:o,selection:a,ansi:c}=ce(t),u=(f,l,d)=>yt(l,d)<Ms(r)?[f]:[];if(r==="foreground")return yt(o,s)<Ms(r)?[1,0]:[];if(r==="selection")return yt(o,a)<Ms(r)?[3,1]:[];if(r==="accents")return CE.flatMap((f)=>u(F.length+f,c[f],s));if(r==="light-ansi")return[7,15].flatMap((f)=>u(F.length+f,c[f],s));if(r==="ansi8-visible")return u(F.length+8,c[8],s);if(r==="ansi0-dark")return xt(c[0])>Ms(r)?[F.length]:[];if(r==="ansi-role")return Fr(i).map(({slot:f})=>F.length+f);if(r==="bright-follows")return nr(i).filter(({gap:f})=>f>on).flatMap(({normal:f})=>[F.length+f,F.length+f+8]);if(r==="distinct")return rr(i).flatMap(([f,l])=>[F.length+f,F.length+l]);return[]}function Rg(t,e,n){return new Set(Yn.keys().filter((r)=>Ag(t,e,n,r).some((i)=>i.ok===!1)))}function xr(t,e,n,r,i){let s=yt(t,e),o=Ms(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 Ag(t,e,n,r){let i=ce(t),s=Or(t,e,n);if(r===0){let $=[1,2,3,4,5,6,9,10,11,12,13,14].reduce((k,v)=>yt(i.ansi[k],i.background)<=yt(i.ansi[v],i.background)?k:v);return[xr(i.foreground,i.background,"foreground","Foreground on it",n),xr(i.ansi[$],i.background,"accents",`Weakest, ANSI ${$},`,n),xr(i.ansi[8],i.background,"ansi8-visible","ANSI 8 on it",n)]}if(r===1)return[xr(i.foreground,i.background,"foreground","On background",n),xr(i.foreground,i.selection,"selection","On the selection",n)];if(r===2)return[{ok:void 0,text:`On background ${yt(i.cursor,i.background).toFixed(2)}:1`}];if(r===3)return[xr(i.foreground,i.selection,"selection","Foreground on it",n)];let o=r-F.length,a=i.ansi[o];if(o===0){let b=xt(a),$=Ms("ansi0-dark");return[n.includes("ansi0-dark")?{ok:void 0,text:`Luminance ${b.toFixed(3)} · waived`}:{ok:b<=$,text:`Luminance ${b.toFixed(3)} · ≤ ${$}`}]}if(o===7||o===15)return[xr(a,i.background,"light-ansi","On background",n)];if(o===8)return[xr(a,i.background,"ansi8-visible","On background",n)];let c=[xr(a,i.background,"accents","On background",n)],u=Pt(a),f=Mn(o),l=Ae[f],d=`${l.name} ${l.center}±${l.width}°`;if(u.c<Ni)c.push({ok:void 0,text:"Too grey to have a hue"});else if(Us(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 b=Ne(u.h,l.center)-l.width;c.push(b>0?{ok:!1,text:`Hue ${u.h.toFixed(0)}° · ${b.toFixed(0)}° outside ${d}`}:{ok:!0,text:`Hue ${u.h.toFixed(0)}° · in ${d}`})}let h=o<8?o+8:o-8,m=nr(s).find((b)=>b.normal===f);if(m)c.push(n.includes("bright-follows")?{ok:void 0,text:`${m.gap.toFixed(0)}° from ANSI ${h} · waived`}:{ok:m.gap<=on,text:`${m.gap.toFixed(0)}° from ANSI ${h} · ≤ ${on}°`});let p=rr(s).flatMap(([b,$])=>b===o?[$]:$===o?[b]:[]);if(p.length>0&&!n.includes("distinct"))c.push({ok:!1,text:`Reads as ANSI ${p.join(", ")} · within ${Bs}° and ${Gs} lightness`});return c}function Ng(t,e,n){let r=xn(Or(t,e,n));return Te.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?Ig(t,e,n,i.rule):[]}})}var n5=new Set(["reset","reset-all","hex","paste","fix","open","tune","sig","follow"]),_E=vn[1].max;function Pg(t){let[e,n,r]=ct(t);return e===n&&n===r}function r5(t,e){let n=Pt(e);if(!Pg(e))return n;let r=[0,1,3,2].map((i)=>t[i]).find((i)=>!Pg(i));return{...n,h:r?Pt(r).h:Fc.hue}}function BE(t,e,n){if(t==="rgb"){let[r,i,s]=ct(e);return`rgb(${r} ${i} ${s})`}if(t==="oklch")return`oklch(${n.l.toFixed(3)} ${n.c.toFixed(3)} ${n.h.toFixed(0)})`;return e}function xg(t,e){return Math.floor(ra(t,e,_E)*1e4)/1e4}function Og(t,e){return{l:e.l-t.l,c:e.c-t.c,h:((e.h-t.h)%360+540)%360-180}}function LE(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 Tg{mode;seeds=Fc;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=rn(t.colors??vi(this.seeds)),this.lch=this.lchs(),this.start=this.list,this.original=t.original?rn(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=F.length+e,r=n+8,i=this.lchOf(t[n]),s=this.lchOf(t[r]);if(i.c>=Ni&&s.c>=Ni&&Ne(i.h,s.h)<=3)this.links.set(r,n),this.offsets.set(r,Og(i,s))}}pair(t){if(t<F.length)return;let e=F.length+(t-F.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<F.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 ce(this.list)}edited(){return{colors:this.colors(),signature:[...this.signature]}}shown(){return this.compare?this.start:this.list}slot(){return this.row<F.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()}resettable(){return this.dirty()||this.tone&&this.list.some((t,e)=>t!==this.original[e])}misses(){return Rg(this.list,this.signature,this.waive)}failing(){return ir(Or(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&&Q3(t)){this.findPictures({paste:t});return}if(this.mode==="seeds")return;let e=this.options.decode?.(t);if(e){this.remember("open"),this.list=rn(e),this.lch=this.lchs(),this.chain(this.list),this.notice="Took the colors of the share code";return}let n=FE(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",this.inspect=!1,this.spot=void 0;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<F.length?t:F.length+(t-F.length)%8,t>=F.length)this.col=t-F.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===ae){this.reach(21**n);return}this.put(LE(vn[t],n))}sow(t,e){let n=vs[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=Eg({...this.seeds,[n.key]:LE(n,r)},n,0),this.list=rn(vi(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,vs.length-1);else if(this.mode==="tune")this.channel=0,this.step(-t);else this.row=e(this.row,Ss-1),this.lastEdit=void 0}lchOf(t){return r5(this.list,t)}lchs(){return this.list.map((t)=>this.lchOf(t))}seedKey(t){let e=vs.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=vs[this.field],r=(t.endsWith("left")?-1:1)*(t.startsWith("shift")?n.wraps?10:AE:1);this.seeds=Eg(this.seeds,n,r),this.list=rn(vi(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:Ss-1,t==="home"?1:-1);else if(t==="pgup"||t==="pgdn")this.land(t==="pgup"?0:F.length,1);else if(t==="left"||t==="right"){let e=t==="left"?0:1;if(this.row>=F.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&&this.view==="slot"?Nc(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>=F.length&&this.visible(this.slotAt(t,1))}land(t,e){for(let n=0;n<Ss;n++){let r=((t+e*n)%Ss+Ss)%Ss;if(this.rowShown(r)){if(this.row=r,r>=F.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=this.view==="relations"?"g goes back to the builder":"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 share link or a tt2: 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)}}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=lE(t,this.slot())}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=fE(e,uf(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?dE(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<F.length){this.notice="l links a bright to its normal — pick an ANSI row";return}let e=F.length+(t-F.length)%8,n=e+8,r=`${We(n).name} and ${We(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,Og(this.lch[e],this.lch[n])),this.notice=`${r} move together`}nextMiss(t){let e=X3(),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)){this.seat(s);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 Mg(this.scope,this.slot())}tuneKey(t){let e=this.channel===ae;if(t==="tab"||t==="shift-tab")this.channel=e?0:ae;else if(t==="up"||t==="down"||t==="pgup"||t==="pgdn")this.channel=0,this.step((t==="up"||t==="pgup"?1:-1)*(t.startsWith("pg")?AE: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*Z3)}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=vn[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=vn[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()<F.length){this.notice="A base color moves alone";return}let t=ia.indexOf(this.scope);for(let e=1;e<=ia.length;e++){let n=ia[(t+e)%ia.length];if(n==="this"||Mg(n,this.slot()).length>1){this.scopeTo(n);return}}}scopeTo(t){if(this.mode!=="tune"||this.typing!==void 0||this.quitting||this.slot()<F.length)return;if(t!=="this"&&Mg(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 e5(this.slot(),this.waive)}ratio(){return yt(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:yt(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,s=(d)=>nn(d,Math.min(i,xg(d,r.h)),r.h),o=(d)=>yt(s(d),n),a=xt(this.list[e])>=xt(n),c=Pt(n).l,u=Math.max(1,Math.round(t*100)/100),f=a?1:0,l;if(o(f)<u)l=f,this.notice=`The ratio stops at ${o(f).toFixed(2)}:1 on this side of the color it is read against`;else{let d=c,h=f;for(let m=0;m<24;m++){let p=(d+h)/2;if(o(p)>=u)h=p;else d=p}l=h}this.place(e,l,i,r.h);for(let d=0;d<40&&l!==f&&yt(this.list[e],n)<u;d++)l=a?Math.min(1,l+0.001):Math.max(0,l-0.001),this.place(e,l,i,r.h);this.lch=this.lch.with(e,{...this.lch[e],l:Math.round(l*1e4)/1e4})}step(t){let e=vn[this.channel],n=this.lch[this.slot()][e.key];this.put(n+e.step*t)}put(t){let e=this.slot(),n=vn[this.channel],r=n.wraps?(t%n.max+n.max)%n.max:Es(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=xg(s.l,s.h);if(i>u)this.notice=`Chroma stops at ${u.toFixed(3)}, the sRGB edge for this lightness and hue`;let f=Math.min(i,u),l=f-s.c;this.holds.set(e,f),this.place(e,s.l,f,s.h);for(let d of o){let h=this.lch[d],m=a(Es((this.holds.get(d)??h.c)+l,0,_E));this.holds.set(d,m),this.place(d,h.l,m,h.h)}this.trail([e,...o]);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"&&Pg(this.list[e]))this.notice="A grey shows no hue — raise its chroma first";for(let u of o){let f=this.lch[u];this.place(u,n.key==="l"?a(Es(f.l+c,0,1)):f.l,this.holds.get(u)??f.c,n.key==="h"?a(((f.h+c)%360+360)%360):f.h)}this.trail([e,...o])}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],s=this.offsets.get(n);this.place(n,Es(i.l+s.l,0,1),Math.max(0,i.c+s.c),((i.h+s.h)%360+360)%360)}}}place(t,e,n,r){let i=Math.min(n,xg(e,r));this.lch=this.lch.with(t,{l:e,c:i,h:r}),this.list=this.list.with(t,nn(e,i,r))}take(t,e){if(this.mode==="tune"){let n=this.slot();this.list=this.list.with(n,t),this.lch=this.lch.with(n,this.lchOf(t)),this.holds.set(n,this.lch[n].c),this.trail([n])}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=FE(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=gs(e,HE(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=rn(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=gs(this.filter,HE(t),(r)=>/^[a-z0-9@/-]$/.test(r));if(n!==void 0)this.filter=n,this.pick=0}}snapshot(){return{list:this.list,lch:this.lch,signature:this.signature}}remember(t){if(t!==this.lastEdit||n5.has(t))this.history.push(this.snapshot()),this.future=[];this.lastEdit=t}set(t,e,n){if(!$e(e)||this.list[t]===e)return;this.remember(n),this.list=this.list.with(t,e),this.lch=this.lch.with(t,this.lchOf(e)),this.trail([t])}follow(){if(this.row<F.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,Es(n.l+0.06,0,1),n.c,n.h),this.links.set(e,t),this.unlinked.delete(e),this.offsets.set(e,Og(n,this.lch[e])),this.seat(e),this.notice=`${We(e).name} follows ${We(t).name.toLowerCase()}`}mark(){let t=Yn[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=Or(this.list,this.signature,this.waive),{theme:e,moves:n,left:r}=pf({...t,selectionBackground:t.selectionBackground,signatureSlots:this.signature});if(n.length===0){this.notice=ir(t).length===0?"Already passes the gate":"No color change fixes it";return}this.remember("fix");let i=rn({...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(this.snapshot()),this.restore(t)}redo(){let t=this.future.pop();if(!t){this.notice="Nothing to redo";return}this.history.push(this.snapshot()),this.restore(t)}restore(t){this.list=t.list,this.lch=t.lch,this.signature=t.signature,this.lastEdit=void 0}}import{mkdirSync as S5,readFileSync as Lc,writeFileSync as iM}from"node:fs";import{dirname as E5}from"node:path";import{isMainThread as M5,parentPort as sM,Worker as x5}from"node:worker_threads";var i5=new Set(["comic","4koma","monochrome","greyscale","sketch","lineart","speech_bubble"]),s5=new Set(["scenery","landscape","scenic","no_humans","wide_shot","very_wide_shot"]),o5=0.04,a5=0.1,c5=0.05,u5=4096;function l5(t){return new Set(t.cutouts.split(/\s+/).map((e)=>e.replace(/^~/,"")).filter(Boolean))}function f5(t,e,n,r=0){let{site:i,post:s}=t,o=new Set(s.tags),a=!l5(i).isDisjointFrom(o),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)+(i5.isDisjointFrom(o)?0:-3)+(s5.isDisjointFrom(o)?0:-1.5)+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 gf(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:f5(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 UE(t){let e=Map.groupBy(t,(r)=>r.site),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 Hg(t){let e=t/255;return e<=0.04045?e/12.92:((e+0.055)/1.055)**2.4}function GE(t,e,n){let[r,i,s]=[Hg(t),Hg(e),Hg(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 WE(t,e){let n=e.values().map((o)=>GE(...ct(o))).filter(([,o,a])=>Math.hypot(o,a)>=o5).toArray();if(n.length===0)return 0;let r=Math.max(1,Math.floor(Math.sqrt(t.width*t.height/u5))),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,f,l]=GE(t.data[c],t.data[c+1],t.data[c+2]);n.forEach(([d,h,m],p)=>{if(Math.hypot(u-d,f-h,l-m)<a5)i[p]=i[p]+1})}if(s===0)return 0;return i.reduce((o,a)=>o+Math.min(1,a/s/c5),0)/n.length}import{existsSync as Fg,mkdirSync as KE,readFileSync as sa}from"node:fs";import{homedir as d5}from"node:os";import{dirname as zE,join as xs}from"node:path";var qE=90000;function wf(t,e){let n=X(t),r=ke(t,e).flatMap((i)=>{let[,s,o]=/^([a-z.]+)_(\d+)$/.exec(i.key)??[];return s&&o&&Z.some((a)=>a.key===s)?[{site:s,id:Number(o),...Sh(n,i)}]:[]});return r.length>0?r:void 0}function h5(t,e){let n=new Set(Ft(X(t)).palettes[e.name]?.pictures.map((r)=>r.key));return(e.pictures??[]).filter((r)=>!n.has(me(r)))}function DE(t,e){let n=new Set((e??[]).map((r)=>me(r)));return{...t,pictures:(t.pictures??[]).filter((r)=>!n.has(me(r)))}}async function m5(t,e,n,r,i,s){let o=Z.find(($)=>$.key===n.site);if(!o)throw Error(`no site called ${n.site}`);s("Fetching");let a=await Ci(o,n.id,i);if(!a)throw Error("the post is gone");if(o!==It&&a.md5)try{Oa([a],await Pa([a.md5],i))}catch{}let c={},u=(xa(o,a)?Ma(o,a.id,i).then(($)=>{if($)Xs(a,$)},()=>{}):Promise.resolve()).then(()=>a.named.artist.length>0?$u(a.named.artist,i):new Map).then(($)=>{c=Object.fromEntries($.entries().filter(([,k])=>k.length>0))},()=>{});if(!gu(o,a,Li(process.env.TTHEME_FIND_RATING))||pu(a,Zs(process.env.TTHEME_FIND_BLOCK)).length>0)throw Error("outside your find filters — TTHEME_FIND_RATING and TTHEME_FIND_BLOCK");let f=un(a);if(!f)throw Error("too large to use");let l=xs(ln(o),"orig",`${n.id}.${f.ext}`),d;if(Fg(l))d=new Uint8Array(sa(l));else{s("Downloading");let $=qr(o,a,f);d=await wu($.site,$.url,i,(k,v)=>s("Downloading",Bl(k,v))),H(l,d)}let h=In(d,de),m=!1;if(sr(h)===0&&Qs()&&process.env.TTHEME_FIND_REMOVE_BG!=="off"){let $=xs(ln(o),"cut",`${n.id}.png`);try{if(!Fg($))s("Cutting out"),KE(zE($),{recursive:!0}),await Na(l,$,i);let k=In(new Uint8Array(sa($)),de);if(yu(sr(k)))h=k,m=!0}catch{}}await u;let p=kh(e);s("Drawing"),Au(t,p,Hn(p,e.signatureSlots),h,{site:o.key,id:n.id,ext:f.ext,bytes:d,from:`${o.name} ${n.id} ${o.pageUrl(n.id)}`,artist:a.named.artist,profiles:c,source:ji(a.source),cut:m},{width:0,height:0},oi(t),bl(t));let b=ke(t,e.name).find(($)=>$.key===me(n));if(b)Ca(X(t),b,n,r,d5())}function p5(t,e){let n=Z.find((s)=>s.key===t.site),r=`${n?.name??t.site} ${t.id}`;if(!n||!e)return r;return`${Ct()?R.link:`${Xi(n.ansi)}${R.link}${kt}`} ${Du(r,n.pageUrl(t.id))}`}async function Os(t,e,n){let r=e.flatMap((c)=>h5(t,c).map((u)=>({entry:c,shared:u})));if(r.length===0)return;let i=fs(n),s=process.stdout.isTTY&&Gy(process.env),o=new Set,a=mi();for(let[c,{entry:u,shared:f}]of r.entries()){let l=`${u.name} · ${p5(f,s)}`,d=r.length>1?` · ${c+1}/${r.length}`:"",h=(m,p)=>a.set(`${m} ${l}${p?` · ${p}`:""}${d}`);try{await m5(t,u,f,i,AbortSignal.timeout(qE),h),a.say(` ▣ ${l}`),o.add(u)}catch(m){a.say(` ▢ ${l} — ${m instanceof Error?m.message:String(m)}`)}}a.done();for(let c of o){let u=new Set(ke(t,c.name).map((l)=>l.key)),f=(c.pictures??[]).find((l)=>u.has(me(l)));if(f)co(t,c.name,me(f))}if(o.size>0)Ue(t)}function JE(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 g5(t,e){let[,n,r]=/^(.+)_(\d+)$/.exec(t)??[],i=xs(Tn(),n??"local","cut",`${r??t}.png`);if(!Fg(i)){if(!Qs())return;KE(zE(i),{recursive:!0}),await Na(e,i,AbortSignal.timeout(qE))}return In(new Uint8Array(sa(i)),de)}function b5(t,e){try{return sr(Kt(new Uint8Array(sa(xs(t,`${e.stem}.png`)))))>0}catch{return!1}}function bf(t,e){return()=>In(new Uint8Array(sa(xs(t,e.original))),de)}function YE(t,e){let n=bf(t,e);return()=>{let r=n(),i=Kt(new Uint8Array(sa(xs(t,e.cut))));return JE(r,i,0)?r:null}}async function $f(t,e,n,r,i,s,o,a){let c=X(t),u=Ft(c).palettes[e]?.pictures.find((f)=>f.key===n);if(!u?.original)return null;if(u.cut)return ja(t,e,u,YE(c,u),r,i,s,o,!1,a);if(ao(u)){let f=bf(c,u)();if(sr(f)===0&&b5(c,u)){let l=await g5(n,xs(c,u.original));if(!l||!JE(f,l,3))return null;return ja(t,e,u,()=>f,r,i,s,o,!0,a)}return ja(t,e,u,()=>f,r,i,s,o,!1,a)}return ja(t,e,u,bf(c,u),r,i,s,o,!1,a)}function VE(t,e,n,r,i,s){let o=X(t),a=Ft(o).palettes[e]?.pictures.find((u)=>u.key===n);if(!a?.original||ao(a))return!1;let c=a.cut?YE(o,a):bf(o,a);return z$(t,e,a,c,r,i,s)}var w5=2,$5=0.01,pt={coarse:64,fine:192,solid:230,far:48,score:15,outliers:0.03,least:0.03,most:0.97,smallest:0.25,largest:4,step:1.19,overhang:1.04,tiny:8,guesses:3,nudges:[0.97,1,1.03],reach:5},k5=/(?:^|[^0-9a-f])([0-9a-f]{32})(?:[^0-9a-f]|$)/i,y5=[[/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 Lg(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 XE(t,e){let n=k5.exec(e.source)?.[1]?.toLowerCase();return[`post:${t.key}:${e.id}`,...e.md5?[`md5:${e.md5}`]:[],...n&&n!==e.md5?[`md5:${n}`]:[],...y5.flatMap(([r,i])=>{let s=r.exec(e.source)?.[1];return s?[`post:${i}:${Number(s)}`]:[]}),...e.family?[`family:${t.key}:${e.family}`]:[]]}function QE(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 tM(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),f=Math.max(u+1,Math.floor((c+1)*t.width/9)),l=0;for(let d=o;d<a;d++)for(let h=u;h<f;h++){let m=(d*t.width+h)*4,p=t.data[m+3]/255,b=0.299*t.data[m]+0.587*t.data[m+1]+0.114*t.data[m+2];l+=b*p+255*(1-p)}r.push(l/((f-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 v5(t,e){let n=BigInt(`0x${t}`)^BigInt(`0x${e}`),r=0;while(n>0n)r+=Number(n&1n),n>>=1n;return r}function eM(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)))<$5&&v5(t.hash,e.hash)<=w5}var nM={score:Number.POSITIVE_INFINITY,far:1,x:0,y:0,scale:0};function kf(t,e){let n=Math.max(1,Math.round(t.width*e)),r=Math.max(1,Math.round(t.height*e));return Ur(t,{x:0,y:0,w:t.width,h:t.height},n,r)}function ZE(t,e,n,r,i,s,o){let a=[];for(let u=0;u<t.width*t.height;u++)if(t.data[u*4+3]>=pt.solid)a.push(u);let c=nM;if(a.length===0)return c;for(let u=i;u<=s;u++)for(let f=n;f<=r;f++){let l=0,d=0;for(let h of a){let m=h%t.width,p=f+m,b=u+(h-m)/t.width,$=255;if(p>=0&&b>=0&&p<e.width&&b<e.height){let k=h*4,v=(b*e.width+p)*4;$=Math.max(Math.abs(t.data[k]-e.data[v]),Math.abs(t.data[k+1]-e.data[v+1]),Math.abs(t.data[k+2]-e.data[v+2]))}if(l+=$,$>pt.far)d++;if(l>c.score*a.length)break}if(l/a.length<c.score)c={score:l/a.length,far:d/a.length,x:f,y:u,scale:o}}return c}function rM(t,e){let n=0;for(let f=3;f<t.data.length;f+=4)if(t.data[f]>=pt.solid)n++;let r=n/(t.width*t.height);if(r<pt.least||r>pt.most)return!1;let i=Math.max(e.width,e.height),s=new Set([1,e.width/t.width,e.height/t.height]);for(let f=pt.smallest;f<=pt.largest;f*=pt.step)s.add(f);let o=kf(e,pt.coarse/i),a=[];for(let f of s){let l=pt.coarse/i*f;if(t.width*f>e.width*pt.overhang||t.height*f>e.height*pt.overhang)continue;if(t.width*l<pt.tiny||t.height*l<pt.tiny)continue;let d=kf(t,l);a.push(ZE(d,o,-1,o.width-d.width+1,-1,o.height-d.height+1,f))}a.sort((f,l)=>f.score-l.score);let c=kf(e,pt.fine/i),u=nM;for(let f of a.slice(0,pt.guesses))for(let l of pt.nudges){let d=f.scale*l,h=kf(t,pt.fine/i*d),m=Math.round(f.x*pt.fine/pt.coarse),p=Math.round(f.y*pt.fine/pt.coarse),b=ZE(h,c,m-pt.reach,m+pt.reach,p-pt.reach,p+pt.reach,d);if(b.score<u.score)u=b}return u.score<=pt.score&&u.far<=pt.outliers}var O5={thumb:"tile",band:"band",match:"tile",twin:"view",show:"view",backdrop:"view",redraw:"view"},oa;async function P5(t){if(t.job==="twin"){let r=oa?.from===t.whole?oa.inked.image:In(new Uint8Array(Lc(t.whole)),de);return rM(In(new Uint8Array(Lc(t.cut)),de),r)}if(t.job==="redraw")return $f(t.home,t.name,t.key,t.paint,t.blur,t.aligns,t.user);if(t.job==="show"){if(oa?.from!==t.from){let o=In(new Uint8Array(Lc(t.from)),de);oa={from:t.from,clear:sr(o),inked:$h(o,t.cut)}}let{image:r,fill:i,opacity:s}=N$(oa.inked,t.colors,t.tone,t.width,t.height,t.blur,t.tune,t.coloring);return S5(E5(t.to),{recursive:!0}),iM(t.to,De(r)),{clear:oa.clear,fill:i,opacity:s}}let e=In(new Uint8Array(Lc(t.from)),de);if(t.job==="backdrop"){Au(t.home,t.colors,t.tone,e,{...t.origin,bytes:new Uint8Array(Lc(t.source)),cut:t.from!==t.source},t,t.blur,t.coloring);let r=t.tune&&ke(t.home,t.colors.name).find((i)=>i.key===me(t.origin));if(t.tune&&r)Ca(X(t.home),r,t.tune,t.aligns??!0,t.user??t.home);return 0}if(t.job==="match")return{match:WE(e,t.colors),hash:tM(e)};if(t.job==="thumb")return H(t.to,De(f0(e,t.width,t.height))),0;let n=e.data.subarray(t.y*e.width*4,(t.y+t.height)*e.width*4);return iM(t.to,De({width:e.width,height:t.height,data:n})),0}function I5(t){t.on("message",async(e)=>{try{t.postMessage({id:e.id,value:await P5(e)})}catch(n){t.postMessage({id:e.id,error:n instanceof Error?n.message:String(n)})}})}class Cg{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 x5(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 Cc{lines=new Map;run(t){let e=O5[t.job],n=this.lines.get(e);if(!n)n=new Cg,this.lines.set(e,n);return n.send(t)}close(){for(let t of this.lines.values())t.close();this.lines.clear()}}class jg{lines;constructor(t){this.lines=Array.from({length:Math.max(1,t)},()=>new Cg)}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(!M5&&sM)I5(sM);import{existsSync as R5,mkdtempSync as A5,readFileSync as N5,rmSync as oM,writeFileSync as T5}from"node:fs";import{tmpdir as H5}from"node:os";import{basename as cM,join as aM}from"node:path";var F5=6;class _g{dir;made=[];of(t,e){this.dir??=A5(aM(H5(),"ttheme-tint-"));let n=aM(this.dir,`${cM(t,".png")}.${e.slice(1).toLowerCase()}.png`);if(!R5(n)){let r=new Uint8Array(N5(t));T5(n,lu(r,e)??ar(or(Kt(r)),e)),this.made.push(n);while(this.made.length>F5)oM(this.made.shift(),{force:!0})}return n}clear(){if(this.dir)oM(this.dir,{recursive:!0,force:!0});this.dir=void 0,this.made.length=0}}function uM(t,e,n,r,i){if(Je(t)==="original")return e;let s=Hn(n,[...r]);return s.color===t.tone?e:i.of(e,s.color)}function lM(t,e){let n=cM(e);return t.find((r)=>n.startsWith(`${r.stem}.`)||n.startsWith(`${r.stem}@`))}var U5=2147483625,hM=2147483626,Vn=2147483627,W5=-1073741831,mM=-1073741830,K5=-1073741829,z5=4;function q5(t,e,n,r,i){let s=Math.trunc,o=n.col*r.w,a=n.row*r.h,c=s((Math.max(i.x,o)+r.w-1)/r.w),u=s(Math.min(i.x+i.w,o+n.cols*r.w)/r.w),f=s((Math.max(i.y,a)+r.h-1)/r.h),l=s(Math.min(i.y+i.h,a+n.rows*r.h)/r.h);if(u<=c||l<=f)return;return{col:c,row:f,cols:u-c,rows:l-f,x:s((c*r.w-i.x)*t/i.w),y:s((f*r.h-i.y)*e/i.h),w:s((u-c)*r.w*t/i.w),h:s((l-f)*r.h*e/i.h)}}function D5(t){try{let e=j5(t,"r"),n=Buffer.alloc(24);return _5(e,n,0,24,0),L5(e),n.readUInt32BE(0)===2303741511?{width:n.readUInt32BE(16),height:n.readUInt32BE(20)}:void 0}catch{return}}class yf{ready=()=>{};cell={w:0,h:0};held;tints=new _g;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(Ct(t)||!xo(t,r)||!(Oo(t)||ns(t)))return;return new yf(t,e,n)}constructor(t,e,n){this.home=e,this.name=n,this.views=ns(t),this.banded=hl(t),this.files=ml(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=X(this.home),e=Fe(t,this.name,B5()),n=[];try{n=Ft(t).palettes[this.name]?.pictures??[]}catch{}let r=e?lM(n,e.image):void 0;this.held=e&&r?{picture:r,image:e.image,opacity:e.opacity,cover:e.cover,at:Jt.indexOf(e.position)+1||5}:void 0}draw(t,e,n,r,i,s={col:0,row:0,cols:r,rows:i}){if(this.cell.w===0)return"";let o=t[0],a=this.look(t,e,n,s,!this.views||s.cols===r&&s.rows===i);if(this.views){let u=r*this.cell.w,f=i*this.cell.h,l=a?`${o}|${a.image}|${a.opacity}|${u}|${f}|${a.box.w}|${a.box.h}|${a.box.x}|${a.box.y}|${this.held?.at??5}`:`${o}||1|${u}|${f}|0|0|0|0|5`;if(l===this.viewed)return"";return this.viewed=l,rs(l)}let c=this.layer(U5,W5,"f=24",Buffer.from(ct(o)),s);if(a){let u=Math.max(0,Math.min(255,Math.round((1-a.opacity)*255)));c+=this.picture(a),c+=this.layer(hM,K5,"f=32",Buffer.from([...ct(o),u]),s)}else c+=this.drop(Vn)+this.drop(hM);return c}resized(){this.sent.clear(),this.placed.clear(),this.viewed=""}clear(){let t=this.views&&this.viewed?rs(""):"";for(let e of this.sent.keys())t+=Ic(e);return this.resized(),t}close(){let t=this.clear();if(this.tints.clear(),this.renders?.close(),this.scratch)fM(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,...ce([...t]),waived:[...n]},a=uM(s.picture,s.image,o,e,this.tints),c=D5(a);if(!c)return;let u=uo(c.width,c.height,r.cols*this.cell.w,r.rows*this.cell.h,100,s.at,s.cover&&i),f={...u,x:u.x+r.col*this.cell.w,y:u.y+r.row*this.cell.h},l=q5(c.width,c.height,r,this.cell,f);if(!l)return;return{image:a,opacity:s.opacity,...c,box:f,rect:l}}layer(t,e,n,r,i){let s=r.toString("base64"),o=`${s}|${i.col}|${i.row}|${i.cols}|${i.rows}`;if(this.placed.get(t)===o)return"";return this.sent.set(t,o),this.placed.set(t,o),`\x1B_Ga=t,${n},s=1,v=1,i=${t},q=2;${s}\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 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=sf({id:Vn,path:e,row:0,col:0,cols:0,rows:0,z:mM},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=${mM},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),Ic(t)}band(t,e,n){let r=`${t}|${e}|${n}`,i=this.bands.get(r);if(i)return i;this.scratch??=C5(dM(G5(),"ttheme-edit-")),this.renders??=new Cc;let s={path:dM(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<=z5)break;if(a.ready&&a.path!==this.sent.get(Vn))this.bands.delete(o),fM(a.path,{force:!0})}return s}}var Ps=50;function ut(t,e){return pn(t,e)}function jc(t){return xt(t)>0.35?"#000000":"#ffffff"}function Bg(t,e){return t.held!==void 0&&t.held-e.c>0.0005?t.held:void 0}function vf(t,e,n,r){let i=e.mode==="tune"&&e.channel===ae,s=e.ratio(),{floor:o}=e.partner(),a=(p)=>Math.round(Math.log(Math.max(1,p))/Math.log(21)*(n-1)),c=a(s),u=o===void 0?-1:a(o),f=r===void 0?-1:a(r),l=i?"━":"─",d=Array.from({length:n},(p,b)=>b===c?t.bold("●"):b===f?"○":b===u?"┃":b<u?t.dim(l):l).join(""),h=`${s.toFixed(2)}:1`.padStart(6),m={kind:"channel",channel:ae};return`${ut(m,i?t.bold("▸◐"):t.dim(" ◐"))} ${ut({kind:"bar",channel:ae},d)} ${ut(m,i?t.bold(h):t.dim(h))}`}function Sf(t,e){if(!t.misses().has(e))return;if(Ig(t.list,t.signature,t.waive,"bright-follows").includes(e))return e-F.length<8?"= makes the bright follow its normal":"= on the normal makes this follow it";return"f moves the colors the gate misses"}function Ef(t,e,n){let r=Ag(t.list,t.signature,t.waive,e),i=Bg(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}function Mf(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 pM(t){return`${t.l.toFixed(2)} ${t.c.toFixed(3)} ${t.h.toFixed(0).padStart(3)}°`}function J5(t,e,n,r=Ps){let i=Ng(e.list,e.signature,e.waive).sort((u,f)=>Number(u.ok!==!1)-Number(f.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 f=`${u.value} ${u.bound}`,l=` ${Yu(t,u.ok)} ${Nt(u.ok===!1?u.label:t.dim(u.label),t.dim(f),a-2)}`,d=[...new Set(u.slots)].map((p)=>We(p).name),h=u.slots[0],m=(p)=>h===void 0?p:ut({kind:"slot",slot:h},p);return d.length>0?[m(l),m(` ${t.dim(tt(d.join(" · "),a-2))}`)]:[m(l)]});return[s===0?o:Nt(o,`${t.bold("n")} ${t.dim("next miss")}`,r-2),...c.slice(0,Math.max(0,n-1))]}function gM(t,e){let n=t-F.length;if(n>=0)return e===String(n)||e===`B${n}`||e===`K${n}`;return t===3&&e==="s"||t===2&&e==="c"}function xf(t,e,n,r){let i=r?$t("under"):"";if(n==="d")return`${t.fg(e.foreground)}${$t("dim")}${i}`;if(n==="b")return`${t.fg(e.foreground)}${$t("bold")}${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"?$t("bold"):""}${i}`}function _c(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 f=c??"#000000";if(u===o)return`${t.bg(f)}${t.fg(jc(f))}${R.on}${ge}`;if(u===a)return c?`${t.bg(c)}${t.fg(jc(c))}${R.off}${ge}`:`${t.fg("#aaaaaa")}${R.off}`;return c?`${t.fg(c)}█`:`${t.fg(r?"#777777":"#555555")}░`}).join("").concat(kt)}function Of(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 Jn(o.l,o.c,o.h)?nn(o.l,o.c,o.h):void 0})}function Is(t,e,n,r){return Math.round((t-e)/(n-e)*(r-1))}function Gg(t){return Ng(t.list,t.signature,t.waive).filter((e)=>e.ok===!1).length}function Bc(t,e,n,r){if(n<3)return[];let i=Gg(e),s=i===0?" Gate ✓ passes ":` Gate ✗ ${i} · n next `;return[t.dim(Gt(r,"top",[[2,s]])),...J5(t,e,n-1,r-1).slice(1).map((o)=>Ze(t,o,r)),t.dim(Gt(r,"bottom"))]}var Ir=0.98,Gc=0.12,Y5=0.37,bM=0.74,V5=0.15,Z5=-1073741828,Ug=-1073741827,Wg=-1073741826,X5=-1073741825,Q5=2147483584,t4=["panel","plane","hue","contrast","mark","hue-thumb","contrast-thumb","origin","hue-origin","contrast-origin"],e4=4096;function Uc(t,e){return ra(t,e,Y5)}function If(t,e,n){let r=Uc(t,n);return r>0.000001?Math.min(1,e/r):0}function Wc(t,e){return{width:t,height:e,data:new Uint8Array(t*e*4)}}function Si(t,e,n,r,i){let s=r[3]*i;if(s<=0||e<0||n<0||e>=t.width||n>=t.height)return;let o=(n*t.width+e)*4,a=t.data;if(s>=1){a[o]=r[0],a[o+1]=r[1],a[o+2]=r[2],a[o+3]=255;return}let c=a[o+3]/255,u=s+c*(1-s);for(let f=0;f<3;f++)a[o+f]=Math.round((r[f]*s+a[o+f]*c*(1-s))/u);a[o+3]=Math.round(u*255)}function Pr(t,e=1){return[...ct(t),e]}function ca(t,e,n,r,i,s,o){let a=Math.abs(t-(n+i/2))-(i/2-o),c=Math.abs(e-(r+s/2))-(s/2-o);return Math.hypot(Math.max(a,0),Math.max(c,0))+Math.min(Math.max(a,c),0)-o}function Rs(t,e,n,r){let i=[],s=[],o=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 f=a;f<u;f++)for(let l=o;l<c;l++){let d=n(l+0.5,f+0.5);if(d>0.002)i.push(f*t+l),s.push(Math.min(1,d))}return{at:Uint32Array.from(i),cover:Float32Array.from(s)}}function As(t,e,n){for(let r=0;r<e.at.length;r++){let i=e.at[r];Si(t,i%t.width,Math.floor(i/t.width),n,e.cover[r])}}function Kg(t,e){return(n,r)=>Math.max(0,0.5-ca(n,r,t.x,t.y,t.w,t.h,e))}function wM(t,e,n){return(r,i)=>Math.max(0,0.5-Math.abs(ca(r,i,t.x,t.y,t.w,t.h,e)+n/2)+n/2)}var Pf=new Map;function n4(t,e,n,r){let i=`${e.w}x${e.h} ${yM({...t,ground:"#000000",ink:"#000000",accent:"#000000"})}`,s=Pf.get(i);if(s)return s;let{panel:o}=t,a={x:e.w,y:0,w:o.cols*e.w,h:o.rows*e.h},c=Math.round(e.h*0.45),u=Math.round(e.h*0.18),f=e.h*0.6,l=Math.max(1,Math.round(e.h/22)),d=(N)=>({x:(N.col-o.col+1)*e.w,y:(N.row-o.row)*e.h}),h=Math.max(1,Math.round(e.h*0.08)),m=d(t.tabs),p={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,$=Math.max(1,Math.round(h/2)),k={x:p.x+t.tabs.active*b+$,y:p.y+$,w:(t.tabs.active===t.tabs.count-1?p.w-t.tabs.active*b:b)-2*$,h:p.h-2*$},v=d(t.field),S={x:v.x,y:v.y+h,w:t.field.cols*e.w,h:e.h-2*h},x=t.divider===void 0?void 0:{x:a.x+e.w*0.6,y:(t.divider-o.row)*e.h,w:a.w-e.w*1.2,h:l},M={shadow:Rs(n,r,(N,C)=>{let I=ca(N,C,a.x,u,a.w,a.h,c);return I>0&&I<f?(1-I/f)**2:0}),fill:Rs(n,r,Kg(a,c),a),border:Rs(n,r,wM(a,c,l),a),track:Rs(n,r,Kg(p,p.h*0.3),p),segment:Rs(n,r,Kg(k,k.h*0.3),k),field:Rs(n,r,wM(S,S.h*0.3,l),S),divider:x&&Rs(n,r,()=>1,x)};if(Pf.size>8)Pf.clear();return Pf.set(i,M),M}function r4(t){let e=xt(t.ground)<0.18;return{dark:e,surface:Ht(t.ground,t.ink,e?0.07:0.04)}}function i4(t,e){let n=Wc((t.panel.cols+2)*e.w,(t.panel.rows+1)*e.h),r=n4(t,e,n.width,n.height),{dark:i,surface:s}=r4(t);if(As(n,r.shadow,[0,0,0,i?0.45:0.18]),As(n,r.fill,Pr(s)),As(n,r.border,Pr(t.ink,i?0.16:0.2)),As(n,r.track,Pr(t.ink,i?0.06:0.07)),As(n,r.segment,Pr(t.accent,i?0.24:0.2)),As(n,r.field,Pr(t.ink,i?0.22:0.28)),r.divider)As(n,r.divider,Pr(t.ink,i?0.12:0.16));return n}function s4(t,e,n){let r=Wc(Math.round(t.cols*n.w),Math.round(t.rows*n.h)),{width:i,height:s,data:o}=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)),f=t.rows*2-1,l=(h)=>Ir-Math.min(1,Math.max(0,((h+0.5)/n.h*2-0.5)/f))*(Ir-Gc),d=[];for(let h=0;h<s;h++){if(h%2===0){let m=l(h+0.5),p=Uc(m,e);d=Array.from({length:Math.ceil(i/2)},(b,$)=>Jn(m,u($*2+0.5)*p,e)??[0,0,0])}for(let m=0;m<i;m++){let b=(m<a||m>=i-a)&&(h<a||h>=s-a)?Math.min(1,Math.max(0,0.5-ca(m+0.5,h+0.5,0,0,i,s,a))):1;if(b<=0)continue;let $=d[m>>1],k=(h*i+m)*4;o[k]=$[0],o[k+1]=$[1],o[k+2]=$[2],o[k+3]=Math.round(b*255)}}return r}function kM(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 o4(t,e){let n=Wc(t.cols*e.w,e.h),{top:r,height:i,width:s}=kM(e,t.cols),o=Array.from({length:s},(a,c)=>{let f=Math.min(1,Math.max(0,((c+0.5)/e.w-0.5)/Math.max(1,t.cols-1)))*360;return Jn(bM,ra(bM,f,V5),f)??[0,0,0]});for(let a=r;a<r+i;a++)for(let c=0;c<s;c++){let u=Math.min(1,Math.max(0,0.5-ca(c+0.5,a+0.5,0,r,s,i,i/2))),f=o[c];Si(n,c,a,[f[0],f[1],f[2],1],u)}return n}function a4(t,e,n){let r=Wc(t.cols*n.w,n.h),{top:i,height:s,width:o}=kM(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(s*0.45)),u=i+Math.round((s-c)/2);for(let f=u;f<u+c;f++)for(let l=0;l<o;l++){let d=Math.min(1,Math.max(0,0.5-ca(l+0.5,f+0.5,0,u,o,c,c/2))),h=a<0||l>=a;Si(r,l,f,Pr(e,h?t.lit?0.5:0.36:0.14),d)}if(a>=0){let f=Math.max(2,Math.round(n.w/5));for(let l=i-1;l<i+s+1;l++)for(let d=a-Math.floor(f/2);d<a-Math.floor(f/2)+f;d++)Si(r,d,l,Pr(e,0.85),1)}return r}function c4(t,e,n,r,i,s,o){let a=Wc(t*o.w,e*o.h),c=Math.max(2,Math.round(i*0.3)),u=(l,d)=>Math.min(1,Math.max(0,l-d+0.5)),f=[0,0,0,0.5];for(let l=0;l<a.height;l++)for(let d=0;d<a.width;d++){let h=Math.hypot(d+0.5-n,l+0.5-r);if(s)Si(a,d,l,Pr(s),u(i-c,h));else Si(a,d,l,f,u(i-c,h)-u(i-c-1,h));Si(a,d,l,f,u(i+1,h)-u(i,h)),Si(a,d,l,[255,255,255,1],u(i,h)-u(i-c,h))}return a}function aa(t,e,n,r,i,s,o=X5){let a=Math.floor((e-r-2)/s.w),c=Math.floor((e+r+2)/s.w),u=Math.floor((n-r-2)/s.h),f=Math.floor((n+r+2)/s.h),l={row:u,col:a,cols:c-a+1,rows:f-u+1},d=Math.round((e-a*s.w)*2)/2,h=Math.round((n-u*s.h)*2)/2;return{name:t,key:`${l.cols}x${l.rows} ${d},${h} ${r} ${i??"-"}`,box:l,z:o,paint:()=>c4(l.cols,l.rows,d,h,r,i,s)}}function yM(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 u4(t,e){let n=`${e.w}x${e.h}`,r=Math.max(4,Math.round(e.h*0.34)),i=(l,d)=>(l.col+0.5+d*(l.cols-1))*e.w,s=(l)=>(l.row+0.5)*e.h,o=t.plane,a=(l)=>{let d=(Ir-l)/(Ir-Gc)*(o.rows*2-1);return o.row*e.h+(Math.min(o.rows*2-1,Math.max(0,d))+0.5)*e.h/2},c=a(o.l),u=[{name:"panel",key:`${n} ${yM(t)}`,box:{row:t.panel.row,col:t.panel.col-1,cols:t.panel.cols+2,rows:t.panel.rows+1},z:Z5,paint:()=>i4(t,e)},{name:"plane",key:`${n} ${o.cols}x${o.rows} ${o.h.toFixed(2)}`,box:o,z:Ug,paint:()=>s4(o,o.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:Ug,paint:()=>o4(t.hue,e)},{name:"contrast",key:`${n} ${t.contrast.cols} ${t.contrast.floor??"-"} ${t.contrast.lit} ${t.ink}`,box:{...t.contrast,rows:1},z:Ug,paint:()=>a4(t.contrast,t.ink,e)},aa("mark",i(o,If(o.l,o.c,o.h)),c,r,void 0,e),aa("hue-thumb",i(t.hue,t.hue.h/360),s(t.hue),r,t.hue.color,e),aa("contrast-thumb",i(t.contrast,t.contrast.at),s(t.contrast),r,t.contrast.color,e)],f=t.origin;if(f){let l=Math.max(3,Math.round(r*0.55));u.push(aa("origin",i(o,If(f.l,f.c,f.h)),a(f.l),l,f.color,e,Wg),aa("hue-origin",i(t.hue,f.h/360),s(t.hue),l,f.color,e,Wg),aa("contrast-origin",i(t.contrast,f.at),s(t.contrast),l,f.color,e,Wg))}return u}function l4(t,e){let r=e.toString("base64").match(new RegExp(`.{1,${e4}}`,"g"))??[""];return r.map((i,s)=>{let o=s<r.length-1?1:0;return s===0?`\x1B_Ga=t,f=100,i=${t},m=${o},q=2;${i}\x1B\\`:`\x1B_Gm=${o},q=2;${i}\x1B\\`}).join("")}function $M(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 zg(t){return`\x1B_Ga=d,d=I,i=${t},q=2\x1B\\`}class Rf{cell={w:0,h:0};shown=new Map;static of(t,e){return Ct(t)||!xo(t,e)||!Oo(t)?void 0:new Rf}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?u4(t,this.cell):[],n="";for(let r of e)n+=this.put(r);for(let[r,i]of this.shown)if(!e.some((s)=>s.name===r))n+=zg(i.id),this.shown.delete(r);return n}clear(){let t=[...this.shown.values()].map((e)=>zg(e.id)).join("");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,$M(n.id,t.box,t.z)}let r=Q5+t4.indexOf(t.name)*2,i=n?.id===r?r+1:r;return this.shown.set(t.name,{key:t.key,id:i,at:e}),`${l4(i,De(t.paint()))}${$M(i,t.box,t.z)}${n?zg(n.id):""}`}}var Kc=34,qg=2,f4=6,Nf=3,d4=7,SM="↑↓ L ←→ C ⇧←→ H tab ◐";function h4(t,e,n){let r="",i=0;for(let s of t){let o=i+B(s);if(o>e&&i<n)r+=i>=e&&o<=n?s:" ".repeat(Math.min(o,n)-Math.max(i,e));if(i=o,i>=n)break}return r}function Tf(t){return t.reduce((e,n)=>e+B(n.text),0)}function Hf(t,e,n){let r=[],i=0;for(let s of t){let o=B(s.text),a=Math.max(e,i),c=Math.min(n,i+o);if(c>a)r.push({...s,text:h4(s.text,a-i,c-i)});i+=o}return r}function m4(t,e,n){return[...Hf(t,0,e),...n,...Hf(t,e+Tf(n),Tf(t))]}function p4(t,e){return t.map((n)=>{let r=e&&n.sgr?`${n.sgr}${n.text}${Se}`:n.text;return n.target?pn(n.target,r):r}).join("")}function EM(t){return t<F.length?F[t]:Sn[(t-F.length)%8]}function MM(t,e,n,r){let i=t.signature.includes(Yn[n])?R.signature:e.color?R.swatch:" ";return e.color?`${e.fg(t.list[n])}${i}${r}`:i}function xM(t,e,n,r,i){return r.has(n)?e.bold(R.miss):t.changed(n)?e.color?`${$t("warn")}${R.on}${i}`:R.on:" "}function OM(t,e,n){return n?t.color?`${t.fg(e.cursor)}${R.gutter}${kt} `:`${R.gutter} `:" "}function g4(t,e,n,r,i,s){let o=r===t.slot(),a=o?e.fg(n.foreground):kt,c=EM(r).padEnd(12),u=t.lch[r],f=`${OM(e,n,o)}${MM(t,e,r,a)} ${o?e.bold(c):c}${pM(u)} ${xM(t,e,r,s,a)}`,l=tt(f,i);return ut({kind:"open",slot:r},o&&e.color?`${e.bg(n.selection)}${e.fg(n.foreground)}${l}${ge}`:l)}var Dg=8,PM=44;function qc(t){return t>=PM?16:11}function vM(t,e,n,r,i,s){let o=qc(i);if(!t.visible(r))return" ".repeat(o);let a=r===t.slot(),c=a&&e.color?e.fg(n.foreground):kt,u=t.lch[r],f=(p,b)=>p.toFixed(b).replace(/^0(?=\.)/,""),l=`${u.h.toFixed(0).padStart(3)}°`,d=i>=PM?`${f(u.l,2)} ${f(u.c,3)} ${l}`:`${f(u.l,2)} ${l}`,h=`${MM(t,e,r,c)} ${d}${xM(t,e,r,s,c)}`,m=a&&e.color?`${e.bg(n.selection)}${e.fg(n.foreground)}${h}${ge}`:h;return ut({kind:"open",slot:r},m)}function b4(t,e,n,r,i,s){let o=F.length+r,a=o+8,c=t.row===o,u=Sn[r].padEnd(Dg),f=t.linkOf(a)!==void 0?e.dim("⇠"):" ";return`${ut({kind:"open",slot:o},`${OM(e,n,c)}${c?e.bold(u):u}`)}${vM(t,e,n,o,i,s)}${f} ${vM(t,e,n,a,i,s)}`}function IM(t){return 14+2*qc(t)}function w4(t){let e=qc(t)>=16;return[[2," ANSI "],[2+Dg,e?" Normal 0–7 ":" Normal "],[5+Dg+qc(t),e?" Bright 8–15 ":" Bright "]]}function $4(t,e,n,r){let i=t.slot(),s=We(i),o=IM(r),a=o-2,c=` ${s.name}${i>=F.length?` · ${s.about}`:""} `,u=[` ${e.dim(jE(i))}`];if(i>=2){let l=cE(n,i).filter((m)=>m.count>0),d=l.length>0?l.map((m)=>`${m.name} ${m.count}`).join(" · "):"none",h=be("w",t.where?Ve(e,"w where"):e.dim("w where"));u.push(Nt(` ${e.dim("Shown in")} ${d}`,`${h} `,a))}let f=i-F.length;if(f===0||f===7||f===8||f===15){let l=t.lch[i].l,d=t.lch[0].l,h=t.lch[1].l,m=Math.abs(l-d)<=Math.abs(l-h)?"the background":"the text";u.push(` ${e.dim(`L ${l.toFixed(2)} reads near ${m}`)}`)}return[e.dim(Gt(o,"top",[[2,c]])),...u.map((l)=>Ze(e,l,o)),e.dim(Gt(o,"bottom"))]}function Af(t,e){return Ir-t*(Ir-Gc)/(e*2-1)}function RM(t,e,n,r,i){let s=Af(Math.max(0,Math.min(e*2-1,t*2-0.5)),e),o=Math.max(0,Math.min(1,(n-0.5)/Math.max(1,r-1)));return{lightness:s,chroma:o*Uc(s,i)}}function k4(t,e,n,r,i,s){let o=(l)=>{let d=Math.max(0,Math.min(i*2-1,Math.round((Ir-l.l)/(Ir-Gc)*(i*2-1))));return{row:Math.floor(d/2),col:Math.round(If(l.l,l.c,l.h)*(r-1))}},{row:a,col:c}=o(e),u=s?o(s):{row:-1,col:-1},f=(l,d)=>{return`#${(Jn(l,d*Uc(l,e.h),e.h)??[0,0,0]).map((m)=>m.toString(16).padStart(2,"0")).join("")}`};return Array.from({length:i},(l,d)=>{let h="";for(let m=0;m<r;m++){if(d===a&&m===c){h+=t.color?`${t.bg(n)}${t.fg(jc(n))}${R.on}${ge}`:R.on;continue}let p=m/Math.max(1,r-1);if(d===u.row&&m===u.col){let b=f(Af(d*2+1,i),p);h+=t.color?`${t.bg(b)}${t.fg(jc(b))}${R.off}${ge}`:R.off;continue}h+=t.color?`${t.fg(f(Af(d*2,i),p))}${t.bg(f(Af(d*2+1,i),p))}▀${ge}`:"·"}return ut({kind:"plane",row:d,rows:i},h)})}function AM(t,e,n){let r=t.slot(),i=t.lch[r],o=Ef(t,r,i).filter((c)=>c.ok===!1||c.text.startsWith("Chroma ○")).flatMap((c)=>vt(c.text,n-2).map((u,f)=>`${f===0?c.ok===!1?e.bold(R.miss):e.dim(R.off):" "} ${u}`)),a=Sf(t,r);return[...o.slice(0,3),...a?[e.dim(a)]:[]]}function NM(t,e,n){let r=t.pair(t.slot());if(!r)return;let i=t.slot()>=r.bright,s=EM(i?r.normal:r.bright).toLowerCase(),o=`${r.lift>=0?"+":""}${r.lift.toFixed(2)}`,a=n-9,c=i?r.on?[`⇠ Linked to ${s} · L ${o}`,`⇠ ${s} · L ${o}`,`⇠ ${s}`]:[`Not linked to ${s}`,"Not linked"]:r.on?[`Bright follows · L ${o}`,"Bright follows"]:["Its bright moves on its own","Moves on its own"],u=c.find((f)=>B(f)<=a)??c.at(-1)??"";return Nt(e.dim(u),be("l",`${e.bold("l")} ${e.dim(r.on?"unlink":"link")}`),n)}function TM(t,e,n){let r=t.slot(),i=t.list[r],s=t.lch[r],o=t.typing!==void 0?e.bold(`${t.typing}▏`):be("#",e.bold(BE(t.format,i,s))),a=t.start[r],c=e.color?`${e.fg(a)}${R.swatch}${kt} `:"";return Nt(o,a!==i?e.dim(`was ${c}${a}`):"",n)}function y4(t,e,n,r){let i=t.slot(),s=t.lch[i],o=t.list[i],a=n-4,c=e.dim("│"),u=(M)=>`${c} ${tt(M,a)} ${c}`,f=NM(t,e,a),l=6+(f?1:0),d=AM(t,e,a).slice(0,Math.max(0,r-l-Nf)),h=Math.max(Nf,Math.min(f4,r-l-d.length)),m=" L × C ",p=` H ${s.h.toFixed(0)}° `,b=Math.max(0,n-4-B(" L × C ")-B(p)),$=t.origin(),k=vn[2],v=(M,N)=>ut({kind:"format",format:N},t.format===N?Ve(e,M):e.dim(` ${M} `)),S=tt(` ${SM} `,n-4,!1);return{lines:[`${e.dim("╭─")}${e.dim(" L × C ")}${e.dim("─".repeat(b))}${e.dim(p)}${e.dim("─╮")}`,...k4(e,s,o,a,h,$?.lch).map((M)=>u(M)),u(ut({kind:"bar",channel:2},_c(e,Of(s,k,a),Is(s.h,k.min,k.max,a),t.mode==="tune"&&t.channel===2,$&&Is($.lch.h,k.min,k.max,a)))),u(vf(e,t,Math.max(8,a-11),$?.ratio)),u(`${v("Hex","hex")} ${v("RGB","rgb")} ${v("OKLCH","oklch")}`),u(TM(t,e,a)),...f?[u(f)]:[],...d.map((M)=>u(M)),`${e.dim("╰─")}${e.dim(S)}${e.dim("─".repeat(Math.max(0,n-4-B(S))))}${e.dim("─╯")}`].map((M)=>ut({kind:"picker"},M))}}var zc=[["Hex","hex"],["RGB","rgb"],["OKLCH","oklch"]];function v4(t,e,n,r){let i=t.lch[t.slot()],s=n-2,o=NM(t,e,s),a=6+(o?1:0),c=AM(t,e,s).slice(0,Math.max(0,r-a-Nf)),u=Math.max(Nf,Math.min(d4,r-a-c.length)),f=(M)=>` ${tt(M,s)} `,l=[f(Nt(e.dim("L × C"),e.dim(`H ${i.h.toFixed(0)}°`),s)),...Array.from({length:u},(M,N)=>f(ut({kind:"plane",row:N,rows:u}," ".repeat(s))))],d=l.length;l.push(f(ut({kind:"bar",channel:2}," ".repeat(s))));let h=l.length,m=t.mode==="tune"&&t.channel===ae,p={kind:"channel",channel:ae},b=`${t.ratio().toFixed(2)}:1`.padStart(8),$=s-11;l.push(f(`${ut(p,m?e.bold("◐"):e.dim("◐"))} ${ut({kind:"bar",channel:ae}," ".repeat($))} ${ut(p,m?e.bold(b):e.dim(b))}`));let k=l.length,v=Math.floor(s/zc.length);l.push(f(zc.map(([M,N],C)=>{let I=C===zc.length-1?s-v*C:v,j=Math.floor((I-B(M))/2),U=`${" ".repeat(j)}${M}${" ".repeat(I-j-B(M))}`,G=t.format===N?e.color?e.accent(e.bold(U)):`[${M}]`.padEnd(I):e.dim(U);return ut({kind:"format",format:N},G)}).join("")));let S=l.length;l.push(f(` ${TM(t,e,s-2)} `));let x=o?l.length:void 0;if(o)l.push(f(o));return l.push(...c.map((M)=>f(M)),f(e.dim(SM))),{lines:l.map((M)=>ut({kind:"picker"},M)),parts:{plane:{row:1,col:1,cols:s,rows:u},hue:{row:d,col:1,cols:s,rows:1},contrast:{row:h,col:3,cols:$,rows:1},tabs:{row:k,col:1,cols:s,rows:1},field:{row:S,col:1,cols:s,rows:1},divider:x}}}function S4(t,e,n,r,i,s){let o=t.slot(),a=t.lch[o],c=t.list[o],u=(h)=>({row:r+h.row,col:i+h.col,cols:h.cols,rows:h.rows}),f=(h)=>Math.log(Math.max(1,h))/Math.log(21),l=t.partner().floor,d=t.origin();return{panel:{row:r,col:i,cols:n.plane.cols+2,rows:s},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:f(t.ratio()),floor:l===void 0?void 0:f(l),color:c,lit:t.channel===ae},tabs:{...u(n.tabs),active:zc.findIndex(([,h])=>h===t.format),count:zc.length},field:u(n.field),divider:n.divider===void 0?void 0:r+n.divider,origin:d&&{...d.lch,color:d.hex,at:f(d.ratio)}}}function E4(t,e,n,r,i,s,o,a){let u=s??1,f=o-1-u,l=u-2,d=12+2*qc(r)-qg,h=a?v4:y4,m=h(t,e,d,Number.POSITIVE_INFINITY),p=m.lines.length<=f||m.lines.length>l&&f>=l,b=p?f:l,$=m.lines.length<=b?m:h(t,e,d,b),k=p?u+1:u-$.lines.length,v=Array.from({length:o},(S,x)=>i[x]??"");return $.lines.forEach((S,x)=>{let M=k+x;if(M>=0&&M<o)v[M]=iy(v[M],qg,S)}),{lines:v,art:$.parts&&S4(t,n,$.parts,k,qg,$.lines.length)}}function M4(t,e,n,r,i){let s=r.side,o=Gg(t),a=t.changedOnly?e.warn(R.on):" ",c=o===0?e.dim("Gate ✓"):e.bold(`Gate ✗ ${o}`),u=Nt(` ${e.bold("Colors")} ${c}`,be("m",`${t.changedOnly?e.bold("⧩ changed"):e.dim("⧩ changed")}${a} `),s),f=i-1,l=t.misses(),d=IM(s),h=[],m,p=[...F.keys()].filter((k)=>t.visible(k));if(p.length>0){h.push(e.dim(Gt(d,"top",[[2," Base "]])));for(let k of p){if(k===t.slot())m=h.length;h.push(Ze(e,g4(t,e,n,k,d-2,l),d))}}let b=[...Sn.keys()].filter((k)=>t.visible(F.length+k)||t.visible(F.length+k+8));if(b.length>0){h.push(e.dim(Gt(d,p.length>0?"mid":"top",w4(s))));for(let k of b){if(t.row===F.length+k)m=h.length;h.push(Ze(e,b4(t,e,n,k,s,l),d))}}if(p.length>0||b.length>0)h.push(e.dim(Gt(d,"bottom")));if(t.visible(t.slot()))h.push(...$4(t,e,r,s));let $=Bc(e,t,f-h.length,d);return h.push(...Array.from({length:Math.max(0,f-h.length-$.length)},()=>""),...$),{lines:[u,...h.slice(0,f)],anchor:m===void 0?void 0:m+1}}function x4(t,e,n){let r=`${e.accent(R.current)} ${e.bold(t.options.title)} ${e.dim(`· ${t.options.name}`)}`,i=t.dirty(),s=t.changes(),o=e.warn(R.on),a=i?`${o} ${e.dim(s>0?`unsaved · ${s} changed`:"unsaved")}`:"",c=[t.resettable()?be("R",e.dim("Reset")):"",i?be("s",Ve(e,"Save")):""].filter(Boolean).join(" "),u=[r,a,c].filter(Boolean).join(" "),f=(h,m,p)=>be(h,p?Ve(e,m):e.dim(m)),d=[...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 Nt(u,`${d} `,n)}var O4={kind:"open",slot:0};function P4(t,e,n){return t.color?`${n?Yk:t.bg(e.background)}${t.fg(e.foreground)}`:""}function I4(t,e,n,r,i,s){let o=Tc(r),a=P4(e,n,s),c=t.slot();return Array.from({length:r.rows},(u,f)=>{let l=[{text:" ",sgr:a},...(o[f]??[]).map((m,p)=>{let b=i&&i.pane===r.id&&i.line===f&&i.run===p,$=e.color?b?`${a}${e.bg(n.foreground)}${e.fg(n.background)}`:`${a}${xf(e,n,m.role,pg(m.role,c))}${t.where&&!mg(m.role,c)?$t("dim"):""}`:"";return{text:m.text,sgr:$,target:{kind:"run",spot:{pane:r.id,line:f,run:p}}}})],d=Hf(l,0,r.width-1),h=r.width-Tf(d);return h>0?[...d,{text:" ".repeat(h),sgr:a,target:O4}]:d})}function R4(t,e,n){let r=t.slotsHere();if(!r)return;let i=e.color?`${e.bg(n.background)}${e.fg(n.foreground)}`:"",s=e.color?`${i}${$t("dim")}`:"",o=(l)=>({text:l,sgr:s}),a="┌ Slots here ",c="└ enter its slot · esc ",u=[["text",r.text]];if(r.ground!==r.text)u.push(["ground",r.ground]);return[[o(`${a}${"─".repeat(Kc-B(a)-1)}┐`)],...u.map(([l,d])=>{let h={kind:"open",slot:d},m=t.shown()[d],p=d<F.length?"":We(d).about;return[{text:"│ ",sgr:s,target:h},{text:l.padEnd(7),sgr:s,target:h},{text:R.swatch,sgr:e.color?`${i}${e.fg(m)}`:"",target:h},{text:" ",sgr:i,target:h},{text:We(d).name.slice(0,14).padEnd(14),sgr:i,target:h},{text:p.padEnd(Kc-27),sgr:s,target:h},{text:" │",sgr:s,target:h}]}),[o(`${c}${"─".repeat(Kc-B(c)-1)}┘`)]].map((l)=>Hf(l,0,Kc))}function A4(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,s=e.color?`${e.bg(n.background)}${e.fg(n.foreground)}`:"",o=e.color?`${s}${$t("dim")}`:"",a=t.menu==="export"?"Copy ":"Take from ";return[[{text:`┌ ${a}${"─".repeat(Math.max(0,i-3-a.length))}┐`,sgr:o}],...r.map((c,u)=>{let f=u===t.entry,l={kind:"entry",index:u};return[{text:"│",sgr:o},{text:` ${f?"▌":" "} ${c.padEnd(i-6)}`,sgr:f&&e.color?`${e.bg(n.selection)}${e.fg(n.foreground)}${$t("bold")}`:s,target:l},{text:"│",sgr:o}]}),[{text:`└${"─".repeat(i-2)}┘`,sgr:o}]]}var N4=["#ff5f57","#febc2e","#28c840"];function T4(t,e,n,r){let i=e.color?`${e.bg(HM(n))}${e.fg(n.foreground)}`:"",s=aE(),o=(t.scene%s.length+s.length)%s.length,a=[{text:" ",sgr:i},...N4.flatMap((u)=>[{text:"●",sgr:e.color?`${i}${e.fg(u)}`:""},{text:" ",sgr:i}]),{text:" ",sgr:i},...s.flatMap((u,f)=>{let l={kind:"scene",scene:f};return[f===o?{text:` ${u} `,sgr:e.color?`${i}${e.bg(Qi(n.background,n.foreground,"tab"))}${$t("bold")}`:"",target:l}:{text:` ${u} `,sgr:e.color?`${i}${$t("dim")}`:"",target:l},{text:" ",sgr:i}]})],c="⇧←→ ";return[...a,{text:" ".repeat(Math.max(0,r-Tf(a)-B("⇧←→ "))),sgr:i},{text:"⇧←→ ",sgr:e.color?`${i}${$t("dim")}`:""}]}function HM(t){return Qi(t.background,t.foreground,"bar")}function H4(t,e,n){let{frame:r}=n,i=Qi(e.background,e.foreground,"line"),s=t.color?`${t.bg(FM(e))}${t.fg(i)}`:"",o=t.color?`${t.bg(HM(e))}${t.fg(i)}`:"",a=(u,f)=>u===r.row||u===r.row+r.rows-1||f===r.col||f===r.col+r.cols-1,c=[];for(let[u,f]of hE(n.rules))for(let[l,d]of f)c.push([u,l,[{text:d,sgr:a(u,l)?s:o}]]);return c}function FM(t){return Qi(t.background,t.foreground,"stage")}function LM(t,e){return Nc(t,e,0)?.inner}function CM(t,e,n,r,i={}){let s=Nc(e,n,t.scene);if(!s)return;let o=je(r),a=t.shown(),c=ce(a),u=ce(i.chrome?[...i.chrome]:t.list),f=M4(t,o,u,s,n-1),l=t.mode==="tune"?E4(t,o,u,s.side,f.lines,f.anchor,n-1,r&&i.art===!0):{lines:f.lines,art:void 0},d=l.lines,h=i.behind===!0,m=t.inspect?uf(s,t.spot):void 0,p=o.color?o.bg(FM(u)):"",b=Array.from({length:n-3},()=>[{text:" ".repeat(s.width),sgr:p}]),$=(I,j,U)=>{let G=I-2;if(G>=0&&G<b.length)b[G]=m4(b[G],j,U)},k=s.side+1;for(let[I,j,U]of H4(o,u,s))$(I,j-k,U);for(let I of s.tiles)I4(t,o,c,I,m,h).forEach((j,U)=>{$(I.row+U,I.col-k,j)});$(s.title.row,s.title.col-k,T4(t,o,u,s.title.cols));let v=m?R4(t,o,c):void 0;if(m&&v){let I=s.tiles.find((U)=>U.id===m.pane),j=Tc(I)[m.line]?.[m.run];if(j){let U=Math.max(0,Math.min(I.col-k+1+j.col,s.width-Kc)),G=I.row+m.line,L=G+1,gt=L+v.length-2>n-2?G-v.length:L;v.forEach((Xt,at)=>{$(gt+at,U,Xt)})}}let S=A4(t,o,c);if(S){let I=Math.max(0,s.width-24-(t.menu==="import"?12:2));S.forEach((j,U)=>{$(2+U,I,j)})}let x=x4(t,o,s.width),M=o.dim("─".repeat(s.width)),N=o.dim("│");return{lines:Array.from({length:n-1},(I,j)=>{let U=j===0?x:j===1?M:p4(b[j-2]??[],r);return`${tt(d[j]??"",s.side)}${N}${U}`}),art:l.art}}var jM=80,_M=24,Jg=11;function F4(t,e,n,r){let i=Bg(e,n);return vn.map((s,o)=>{let a=e.mode==="tune"&&o===e.channel,c=n[s.key],u=`${c.toFixed(s.digits)}${s.wraps?"°":""}`.padStart(6),f=_c(t,Of(n,s,r),Is(c,s.min,s.max,r),a,s.key==="c"&&i!==void 0?Is(i,s.min,s.max,r):void 0),l=s.key.toUpperCase(),d={kind:"channel",channel:o};return`${ut(d,a?t.bold(`▸${l}`):t.dim(` ${l}`))} ${ut({kind:"bar",channel:o},f)} ${ut(d,a?t.bold(u):t.dim(u))}`})}function L4(t,e){if(e.mode!=="tune"||e.slot()<F.length)return[];let n=ia.map((i)=>ut({kind:"scope",scope:i},i!==e.scope?t.dim(i):Ve(t,i))),r=e.scoped().length;return[`${t.dim("Scope")} ${n.join(" ")}`,t.dim(r>1?`${r} slots move by the same step, each keeping its own color`:"This slot moves alone · a widens it")]}var BM={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 C4(t){return`oklch ${t.l.toFixed(3)} ${t.c.toFixed(3)} ${t.h.toFixed(0)}°`}function j4(t,e){return`${t.dim("oklch")} ${t.bold(`${e.l.toFixed(3)} ${e.c.toFixed(3)} ${e.h.toFixed(0)}°`)}`}function _4(t,e,n,r=Ps){let i=e.misses(),s=ce(e.list),o=e.slot(),a=(l)=>{let d=e.list[l],h=l===o,m=e.signature.includes(Yn[l])?R.signature:t.color?R.swatch:" ",p=i.has(l)?R.miss:e.tone&&e.changed(l)?R.on:" ",$=`${t.color?`${t.fg(d)}${m}${h?t.fg(s.foreground):kt} `:`${m} `}${Mf(e.lch[l])}${p}`;if(!h)return ut({kind:"slot",slot:l},` ${$}`);return ut({kind:"slot",slot:l},t.color?`${t.bg(s.selection)}${t.fg(s.foreground)} ${$}${ge}`:`›${$}`)},c=(l)=>l?t.color?`${t.fg(s.cursor)}${R.gutter}${kt} `:`${R.gutter} `:" ",u=[t.dim(Gt(r,"top",[[2," Base "]])),...F.map((l,d)=>{let h=d===e.row,m=l.padEnd(10);return Ze(t,`${ut({kind:"slot",slot:d},`${c(h)}${h?t.bold(m):m}`)}${a(d)}`,r)}),t.dim(Gt(r,"mid",[[2," ANSI "],[12," Normal 0–7 "],[29," Bright 8–15 "]])),...Sn.map((l,d)=>{let h=F.length+d,m=h===e.row,p=l.padEnd(10),b=ut({kind:"slot",slot:h+(e.col===1?8:0)},`${c(m)}${m?t.bold(p):p}`);return Ze(t,`${b}${a(h)}${a(h+8)}`,r)}),t.dim(Gt(r,"bottom"))],f=Bc(t,e,n-u.length,r);return[...u,...Array.from({length:Math.max(0,n-u.length-f.length)},()=>""),...f]}function B4(t,e,n){let r=ce(e.list),i=[` ${t.dim("Seeds")}`,...vs.map((s,o)=>{let a=o===e.field,c=e.seeds[s.key],u=Array.from({length:Jg},(b,$)=>{let k=s.min+(s.max-s.min)*$/(Jg-1);return BM[s.key](vi({...e.seeds,[s.key]:k}))}),f=_c(t,u,Is(c,s.min,s.max,Jg),a),l=`${c.toFixed(s.digits)}${s.wraps?"°":""}`.padStart(6),d=BM[s.key](r),h=a?t.color?`${t.fg(r.cursor)}${R.gutter}${kt} `:`${R.gutter} `:" ",m=s.label.padEnd(17),p={kind:"field",field:o};return`${ut(p,`${h}${a?t.bold(m):m}`)}${ut({kind:"seed",field:o},f)}${ut(p,` ${l} ${t.color?`${t.fg(d)}${R.swatch}${kt} `:""}${t.dim(d)}`)}`}),"",...vt("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.",Ps-4).map((s)=>` ${t.dim(s)}`),""];return[...i,...Bc(t,e,n-i.length,Ps)]}function KM(t,e,n,r,i,s){let o=Vt.indexOf(ts(i)),a=Vt.map((u,f)=>ut({kind:"scene",scene:f},f!==o?t.dim(u.name):Ve(t,u.name))).join(" "),c=`${t.bg(e.background)}${t.fg(e.foreground)}`;return[Nt(a,t.dim("⇧←→"),n),...ts(i).lines.values().map((u)=>Mo(u,n-2)).filter((u)=>u!==void 0).take(Math.max(0,r-1)).map((u)=>{let f=t.color?u.map(([l,d])=>`${xf(t,e,d,gM(s,d))}${l}${Se}${c}`).join(""):u.map(([l])=>l).join("");return`${c} ${tt(f,n-2)} ${t.color?Se:""}`})]}var G4=["Bk","Rd","Gr","Ye","Bl","Ma","Cy","Wh"];function GM(t,e,n,r,i,s,o){let a=(i-s)/(o-1),c=zM(e),u=ce(n),f=(l)=>Math.min(o-1,Math.max(0,Math.round((i-r(Pt(l)))/a)));return Array.from({length:o},(l,d)=>{let h=d%2===0?(i-a*d).toFixed(i>=1?1:2).replace(/^0(?=\.\d\d)/,""):"",m=Array.from({length:8},(p,b)=>{let $=[" "," "," "," "," "],k=u.ansi[b],v=u.ansi[b+8],S=f(k)===d,x=f(v)===d,M=(C)=>{if(C===1&&S)return t.color?`${t.fg(k)}${R.on}`:R.on;if(C===3&&x)return t.color?`${t.fg(v)}${R.off}`:R.off;return $[C]},N=[0,1,2,3,4].map(M).join("");return c.has(b)?t.color?`${t.bg(u.selection)}${N}${ge}`:N:`${N}${t.color?kt:""}`});return`${h.padStart(4)} ${t.dim(d%2===0?"┤":"│")}${m.join("")}`})}function zM(t){let e=t.mode==="tune"?t.scoped():[t.slot()];return new Set(e.filter((n)=>n>=F.length).map((n)=>(n-F.length)%8))}function U4(t,e){let n=zM(e);return` ${G4.map((r,i)=>n.has(i)?t.bold(` ${r} `):t.dim(` ${r} `)).join("")}`}function W4(t,e){let n=ce(e),r=Array.from({length:40},(s,o)=>{let a=o*9+4.5,c=-1,u=999;for(let[f,l]of Object.entries(Ae)){let d=Ne(a,l.center);if(d<=l.width&&d<u)u=d,c=Number(f)}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(Ae).map(Number)){let u=n.ansi[c+s],f=Math.min(39,Math.round(Pt(u).h/9));a[f]=t.color?`${t.fg(u)}${o}${kt}`:o}return` ${a.join("")}`};return[`${t.bold("Hue")} ${t.dim("0° 90° 180° 270° 360°")}`,`${t.dim("bands")} ${r}${t.color?kt:""}`,i(0,R.on),i(8,R.off)]}function K4(t,e,n){let r=Or(n,e.signature,e.waive),i=(a)=>We(F.length+a).name,s=(a)=>Pt(n[F.length+a]).h.toFixed(0),o=[...nr(r).filter(({gap:a})=>a>25).map(({normal:a,gap:c})=>`${i(a)} ${s(a)}° → bright ${s(a+8)}° · ${c.toFixed(0)}° apart · ≤ 25°`),...Fr(r).map(({slot:a,over:c})=>{let u=Ae[Mn(a)];return`${i(a)} ${s(a)}° · ${c.toFixed(0)}° outside ${u.name} ${u.center}±${u.width}°`}),...rr(r).map(([a,c])=>`${i(a)} and ${i(c).toLowerCase()} read as one color`)];return o.length>0?o.map((a)=>`${t.bold(R.miss)} ${a}`):[t.dim(`${R.ok} Every accent keeps its role and its bright`)]}function UM(t,e,n,r,i){let s=e.shown(),o=Math.max(...s.slice(F.length).map((u)=>Pt(u).c)),a=Math.max(0.2,Math.ceil(o/0.05)*0.05),c=[Nt(t.bold("Lightness"),t.dim("● normal ○ bright"),n),...GM(t,e,s,(u)=>u.l,1,0.3,8),U4(t,e)];if(i)c.push("",t.bold("Chroma"),...GM(t,e,s,(u)=>u.c,a,0,5),"",...W4(t,s));return[...c,...K4(t,e,s)].slice(0,r)}function z4(t,e,n){let r=(i,s)=>ut({kind:"view",view:s},e.view!==s?t.dim(` ${i} `):Ve(t,i));return Nt(`${r("Slot","slot")}${r("Relations","relations")}`,be("g",`${t.bold("g")} ${t.dim("switch")}`),n)}function q4(t,e,n,r){let i=e.slot(),s=e.list[i],o=e.lch[i],a=e.start[i],{name:c,about:u}=We(i),f=e.signature.includes(Yn[i]),l=Math.max(8,Math.min(64,n-12));if(e.view==="relations"&&e.mode!=="tune")return[z4(t,e,n),"",...UM(t,e,n,r-2,!0)];let d=i>=F.length?t.dim("Uses underlined below"):f?t.dim("◆ signature"):"",h=[Nt(`${t.bold(c)} ${t.dim(u)}`,e.view==="relations"?"":d,n),""],m=t.color?`${t.fg(s)}${"█".repeat(8)}${kt} `:"",p=e.typing!==void 0?`${t.bold(`${e.typing}▏`)}`:void 0,[b,$,k]=ct(s);if(h.push(`${m}${p??j4(t,o)}`,`${m}${t.dim(`${s} · rgb ${b} ${$} ${k}`)}`),e.view!=="relations"){let x=t.color?`${t.fg(a)}${R.swatch}${kt} `:"";h.push(`${m}${a!==s?t.dim(`was ${x}${C4(e.lchOf(a)).slice(6)} · ${a}`):t.dim("as it opened")}`)}if(h.push("",...F4(t,e,o,l),vf(t,e,l),...L4(t,e)),e.view==="relations")return h.push("",...UM(t,e,n,r-h.length-1,!1)),h;h.push("",...Ef(e,i,o).flatMap((x)=>vt(x.text,n-2).map((M,N)=>`${N===0?Yu(t,x.ok):" "} ${x.ok===!1?M:t.dim(M)}`)));let v=Sf(e,i);if(v)h.push(t.dim(` ${v}`));let S=r-h.length-1;if(S>=3)h.push("",...KM(t,ce(e.shown()),n,S,e.scene,i));return h}function D4(t,e,n,r){return[Nt(`${t.bold("Sample")} ${t.dim("what the seeds grow")}`,"",n),"",...KM(t,ce(e.list),n,r-2,e.scene,-1)]}var J4=[["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 Y4(t,e,n){return[` ${t.bold("Help")}`,"",...J4.filter(([r])=>r!=="Pictures"||e.options.find).flatMap(([r,i])=>vt(i,n-16).map((s,o)=>` ${t.bold((o===0?r:"").padEnd(11))} ${s}`))]}function V4(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=r-2,c=Math.max(0,Math.min(e.pick-Math.floor(a/2),i.length-a)),u=Math.min(40,Math.max(12,...i.map((f)=>B(f.name))));return[Nt(` ${t.bold("Take colors from")} ${o}`,t.dim(`${i.length}/${s}`),n),"",...i.slice(c,c+a).map((f,l)=>{let d=c+l===e.pick,h=f.colors,m=t.color?`${t.bg(h.background)} ${h.ansi.map(($)=>`${t.fg($)}${R.swatch}`).join("")} ${t.fg(h.foreground)}Aa ${ge}`:"",p=d?"▌ ":" ",b=f.name.padEnd(u);return ut({kind:"choice",index:c+l},`${p}${d?t.bold(b):b} ${m}`)}),...i.length===0?[` ${t.dim(`No palettes match '${e.filter}'`)}`]:[]]}var Z4=new Set(["enter","s","?","g","a","i"]);function WM(t,e,n){let r="EDIT",i="",s=[],o="";if(e.quitting)r="EDIT (QUIT)",i=e.added>0?`Discard changes and ${e.added} ${e.added===1?"picture":"pictures"}?`:"Discard changes?",s=[["y","discard"],["n","keep editing"]];else if(e.typing!==void 0)r="EDIT (TYPE)",i=t.dim("#rrggbb, rgb(r g b) or oklch(l c h)"),s=[["enter","set"],["ctrl+u","clear"]],o="esc back";else if(e.overlay==="keys")r="HELP",o="any key closes";else if(e.overlay==="open")r="EDIT (OPEN)",s=[["↑↓","palette"],["a-z","filter"],["enter","take its colors"]],o="esc close";else if(e.menu)r=e.menu==="export"?"EDIT (EXPORT)":"EDIT (IMPORT)",s=[["↑↓","item"],["enter","choose"]],o="esc close";else if(e.compare)r="EDIT (BEFORE)",i="The colors you started from",s=[["space","back to yours"]],o="esc back";else if(e.mode==="seeds")r="EDIT (SEEDS)",s=[["↑↓","seed"],["←→","step"],["⇧←→","×5"],["enter","tune the slots"],["o","open a palette"],["p","picture"],["?","keys"]],o="esc cancel";else if(e.mode==="tune")r="EDIT (TUNE)",s=[["↑↓","L"],["←→",e.channel===ae?"ratio":"C"],["⇧←→","H"],["tab","◐"],...e.slot()>=F.length?[["a","scope"]]:[],[e.channel===ae?"1-9":"0-9",e.channel===ae?"ratio":"jump"],["#","type"],["enter","keep"]],o="esc undo";else if(e.inspect)r="EDIT (INSPECT)",s=[["←→↑↓","spot"],["⇧←→","tab"],["enter","its slot"],["i","leave"]],o="esc leave";else s=[["↑↓","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"]],o="esc cancel";if(!e.options.find)s=s.filter(([u])=>u!=="p"&&u!=="b");if(!e.options.exports||!e.roomy)s=s.filter(([u])=>u!=="x");if(!e.roomy)s=s.filter(([u])=>u!=="i"&&u!=="m");if(e.notice)i=t.warn(e.notice),s=[];let a=`${Ve(t,r)}${t.color?" ":" "}`,c=o?be(o.split(" ")[0],`${t.bold(o.split(" ")[0])} ${t.dim(o.split(" ").slice(1).join(" "))}`):"";for(;;){let u=[i,...s.map(([d,h])=>be(d,`${t.bold(d)} ${t.dim(h)}`))].filter(Boolean),f=`${a}${u.join(" ")}`,l=s.findLastIndex(([d],h)=>h>0&&!Z4.has(d));if(B(f)+B(o)+3<=n||l<0)return o?Nt(f,c,n):tt(f,n);s=s.toSpliced(l,1)}}function X4(t,e,n,r,i={}){let s=je(r);if(e<jM||n<_M){let p=[s.bold("ttheme palette editor"),`Needs ${jM}×${_M} — now ${e}×${n}`,s.dim("esc cancels")];return{lines:Array.from({length:n},(b,$)=>tt(p[$]??"",e)),art:void 0}}if(t.viewport(e,n),!t.overlay&&t.mode!=="seeds"&&t.view==="slot"){let p=CM(t,e,n,r,i);if(p)return{lines:[...p.lines,WM(s,t,e)],art:p.art}}let o=t.failing().length,a=o===0?"✓ Passes the gate":`✗ ${o} ${o===1?"miss":"misses"} in the gate`,c=t.pictures>0?s.dim(`▣ ${t.pictures} ${t.pictures===1?"picture":"pictures"} `):"",u=t.resettable()?`${be("R",s.dim("Reset"))} `:"",f=`${t.dirty()?`${s.warn(R.on)} unsaved `:""}${u}${c}${s.dim(a)}`,l=`${s.accent(R.current)} ${s.bold(t.options.title)} ${s.dim(`· ${t.options.name}`)}`,d=n-4,h;if(t.overlay==="keys")h=Y4(s,t,e);else if(t.overlay==="open")h=V4(s,t,e,d);else{let p=e-Ps-2,b=t.mode==="seeds"?B4(s,t,d):_4(s,t,d),$=t.mode==="seeds"?D4(s,t,p,d):q4(s,t,p,d);h=Array.from({length:d},(k,v)=>`${tt(b[v]??"",Ps)}${s.dim("│")} ${tt($[v]??"",p)}`)}return{lines:[Nt(l,f,e),"",...Array.from({length:d},(p,b)=>tt(h[b]??"",e)),"",WM(s,t,e)],art:void 0}}var Q4=new Set(["tab","a","#","l","enter","esc"]),tj=new Set(["picker","plane","bar","channel","format","scope","open","slot"]);function ej(t){if(!t)return!0;return t.kind==="key"?!Q4.has(t.key):!tj.has(t.kind)}function nj(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&&ej(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 s=RM(r.row+e.exact.y,r.rows,e.exact.x,e.width,t.lch[t.slot()].h);t.plane(s.lightness,s.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 rj=[Jl,zn,gi,Er];async function qM(t,e){let n=new Tg(t),r=e.backdrop,i=e.layer,s=(a)=>n.typing===void 0&&mf(a),o=e.hosted?{modes:[Er,...bi()],assume:[zn,gi],burst:s}:{modes:[...rj,...bi()],burst:s};return wi(o,async(a)=>{let c=!1,u=!1,f=new Map,l=new Zp,d=await a.ask(`${Mm(gn,"")}${bi().length>0?yS:""}\x1B[c`,(S)=>{if(S.kind==="color"){f.set(S.code,S.value);return}return l.see(S)},1000);if(d?.cell)a.pixels(d.cell);let h=jy(f),m=h.map((S,x)=>S??n.start[x]),[p,b]=m;if(!h[3])m[3]=Qi(p,b,"selection");let $=new hs({write:(S)=>a.write(S),view:()=>{if(c)return;let{lines:S,art:x}=X4(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,LM(a.cols,a.rows)):r?.clear())??""}${i?.draw(x)??""}`}}}),k=(S=!1)=>{if(S)$.soon();else $.request()},v=async(S)=>{let x=t.find;if(!x)return;c=!0,a.write(`${r?.clear()??""}${i?.clear()??""}`);try{n.found(await x(n.edited(),S))}catch(M){n.notice=M instanceof Error?M.message:String(M)}if(u)return;c=!1,r?.load(),$.reset(is),k()};if(a.write(is),a.onResize(()=>{r?.resized(),a.write(i?.clear()??""),$.reset(is),$.request()}),r)r.load(),r.ready=()=>$.request();if(r||i){let S=new wc;a.ask(ql,(x)=>S.see(x),1000).then((x)=>{if(x)r?.measured(x),i?.measured(x);$.request()})}k();try{let{edited:S}=await a.loop((x)=>{if(c)return;if(x.kind==="paste")n.paste(x.text);else if(x.kind==="key")n.press(x.key);else if(x.kind==="mouse")nj(n,$.point(x),x);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 M=n.wants;if(M)n.wants=void 0,v(M.start);return},()=>{if(!c)k(!0)});return S}finally{u=!0,$.stop(),a.write(`${r?.close()??""}${i?.clear()??""}`)}})}import{spawn as wj}from"node:child_process";import{createHash as cx}from"node:crypto";import{existsSync as Jc,mkdirSync as $j,mkdtempSync as kj,readFileSync as yj,rmSync as Ff}from"node:fs";import{homedir as vj,tmpdir as Sj}from"node:os";import{basename as Ej,dirname as Mj,join as Zn}from"node:path";import{setTimeout as xj}from"node:timers/promises";import{pathToFileURL as YM}from"node:url";import{existsSync as ij,readFileSync as sj,statSync as oj}from"node:fs";import{join as DM}from"node:path";function aj(t,e){try{return JSON.parse(sj(DM(ln(t),e),"utf8"))}catch{return{}}}function cj(t,e,n){H(DM(ln(t),e),`${JSON.stringify(n)}
729
+ `)}var uj=604800000;class Yg{caches=new Map;unsaved=new Set;owners=new Map;crediting=new Map;inflight=new Map;asking=new Map;home;manifest;entry;signal;credited;constructor(t){this.home=t.home,this.manifest=t.manifest,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 Ia(t,e,this.signal),s=qr(t,e),o=(i===void 0?await Y0(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=Z.find((i)=>i.key===e);if(r)cj(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(!xa(n,r))return Promise.resolve();let i=ee(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}links(t){let e=this.keep(It,"profiles.json");return Object.fromEntries(t.flatMap((n)=>{let r=e[n]?.urls??[];return r.length>0?[[n,r]]:[]}))}profile(t,e){return this.credit(t,e).then(()=>this.profiles(t.post.named.artist,e))}async mateOwners(t){let e=this.owners.get(t.key);if(e)return e;let n=G$(this.home),r=this.keep(t,"owners.json"),i=this.manifest.palettes.flatMap((c)=>{let u=n.get(c.name);return ie(c)===ie(this.entry)&&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 Ci(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=U0(o);return this.owners.set(t.key,a),a}async cached(t,e,n,r){if(ij(e))return oj(e).size;let i=this.inflight.get(e);if(i)return i;let s=(async()=>{let o=await wu(t,n,this.signal,r);return H(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=aj(t,e),this.caches.set(n,r);return r}async profiles(t,e){let n=this.keep(It,"profiles.json"),r=Date.now(),i=t.filter((s)=>!this.asking.has(s)&&r-(n[s]?.at??0)>=uj);if(i.length>0){let s=$u(i,e).then((o)=>{for(let a of i)n[a]={at:Date.now(),urls:o.get(a)??[]};this.unsaved.add(`${It.key}/profiles.json`),this.credited()},()=>{}).finally(()=>{for(let o of i)this.asking.delete(o)});for(let o of i)this.asking.set(o,s)}await Promise.all(t.flatMap((s)=>this.asking.get(s)??[]))}async credits({site:t,post:e},n){let r=this.keep(t,"credits.json"),i=r[e.id];if(!i){try{i=await Ma(t,e.id,n)}catch{return}if(!i?.owner)return;r[e.id]=i,this.unsaved.add(`${t.key}/credits.json`)}Xs(e,i),this.credited()}}import{rmSync as lj}from"node:fs";import{join as fj}from"node:path";var ua=2147483645,Dc=2147483646,JM=-1073741827,dj=-1073741828,hj=16,mj=0.4,pj=3221225472,gj=256;function bj(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 Vg=bj(process.env.TTHEME_BG_MARGIN);class Zg{screen;gliding;sent=new Map;placed=new Map;covered="";viewed="";bands=hl(process.env);files=ml(process.env);moves=Uy(process.env);layers=Oo(process.env);wipes=Wy(process.env);views=ns(process.env);bandFiles=new Map;nextBand=pj;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 hs({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=dg(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>=ag){s=o;continue}let a=this.bands?this.banded(o):o;if(!a)continue;if(this.wipes&&e.values().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=sf(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+=ug(a.id);r+=ZS(a,n),this.placed.set(a.id,c)}}for(let o of this.sent.keys())if(!i.has(o))r+=Ic(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=Mr(t,e).height,r=()=>{let i=this.view,s=i.top*Et.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)*mj)),this.draw(),this.gliding=setTimeout(r,hj)};r()}snap(){clearTimeout(this.gliding),this.gliding=void 0,this.view.scroll=this.view.top*Et.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 dg({...t,scroll:t.top*Et.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(ct(this.background)).toString("base64");if(r+=`\x1B_Ga=t,f=24,s=1,v=1,i=${ua},q=2;${i}\x1B\\`,Vg)r+=`\x1B_Ga=t,f=32,s=1,v=1,i=${Dc},q=2;AAAAAA==\x1B\\\x1B[H\x1B_Ga=p,i=${Dc},p=${Dc},c=1,r=1,C=1,z=${dj},q=2\x1B\\`}else if(!this.moves)r+=ug(ua);if(this.covered=n,Vg){let{x:i,y:s}=Vg;return`${r}\x1B_Ga=p,i=${ua},p=${ua},P=${Dc},Q=${Dc},H=${-i},V=${-s},c=${t+2*i},r=${e+2*s},C=1,z=${JM},q=2\x1B\\`}return`${r}\x1B[H\x1B_Ga=p,i=${ua},p=${ua},c=${t},r=${e},C=1,z=${JM},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,rs(o)}caret(){return`\x1B[1;${Math.min(this.grid().cols,B(`⌕ ${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:fj(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<=gj)return;if(e.ready&&!this.sent.has(e.id))this.bandFiles.delete(t),lj(e.path,{force:!0})}}}var Ns=[{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:Js,multi:{read:Li}},{name:"TTHEME_FIND_BLOCK",label:"Block",about:"Posts tagged with nudity or underwear are left out — space unticks one",choices:Fi,multi:{read:Zs,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"]},...Qs()?[{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:P0,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:I0,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:Z.map((t)=>t.name),multi:{read:Sa},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:qd,multi:{read:du,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 VM(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 Ea(e).join(" ");return t.choices.find((n)=>n===e)??t.choices[0]}var Oj=["fit","newest","score"];function Xg(t){return Oj.find((e)=>e===t)??"fit"}var Pj={left:-1,right:1,"shift-left":-10,"shift-right":10};function ZM(t){if(process.env.SSH_CONNECTION||!/^(?:https?|file):/i.test(t))return;try{let e=wj(process.platform==="darwin"?"open":"xdg-open",[t],{stdio:"ignore",detached:!0});e.on("error",()=>{}),e.unref()}catch{}}function Ij(t,e,n){if(e<0){if(t!=="fill")return Math.max(Cf,t+e);if(!n)return t;return Math.max(Cf,Math.max(100,n)+e+1)}return t==="fill"||t+e>n?"fill":t+e}function ux(t,e){return t.size===e.size&&t.at===e.at&&t.opacity===e.opacity}function Rj(t,e){if(ux(t,e))return;return{...t.size!=="fill"?{size:t.size}:{},...t.at!==e.at?{position:Jt[t.at-1]}:{},...t.opacity!==e.opacity?{opacity:t.opacity}:{}}}function XM(t,e){let n=X(t);return ke(t,e).flatMap((r,i)=>{let[,s,o]=/^([a-z.]+)_(\d+)$/.exec(r.key)??[],a=[...Z,Dn].find((c)=>c.key===s);if(!a||!o)return[];return[{key:r.key,id:Number(o),ansi:a.ansi,...a===Dn?{}:{page:a.pageUrl(Number(o))},up:i===0,from:Zn(n,r.original??r.fill)}]})}function Aj(t){return t.length>=2&&!/^\d+$/.test(t)&&!t.includes("://")&&!/^[\w.]+:\d+$/.test(t)}var QM=12,Nj=4,Tj=150,Hj=300,tx=12,Fj=2,Lj=5000,Cj=150,jj="\x1B[?5522$p\x1B]72;t=q\x1B\\\x1B[c",ex=4000,_j=8000,nx=/\.(png|jpe?g|gif|webp|heic|tiff?|bmp)$/i,Bj=process.platform==="win32"?"alt+v":"ctrl+v",rx=process.platform==="darwin"?"ctrl+shift+cmd+4 copies a screenshot":"copy a picture first",Gj=1280,Uj=16,Wj=Jt.indexOf("top-right")+1,Cf=20,ix=2,sx=3,Kj=/[\p{Script=Hangul}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]/u,zj=8,qj=9;function Lf(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 Yc(t){if(!(t instanceof Error))return String(t);if(t instanceof AggregateError&&t.errors[0])return Yc(t.errors[0]);if(t.cause)return Yc(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 Qg(t,e){return`${t}: ${Yc(e)}`}function ox(t){return t.width*t.height}function ax(t,e){return`${t}-${cx("sha1").update(e).digest("hex").slice(0,8)}`}class tb{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(Ns.map((t)=>[t.name,VM(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 Cc;showing;thumbless=new Set;current;fetch;settle;suggestTimer;suggesting;countTimer;counting;terminal;grabber=new vg((t)=>this.write(t),(t)=>void this.got(t));noticeTimer;peekTimer;peeked;twins=new Map;attaching;done;scratch=kj(Zn(Sj(),"ttheme-find-"));home;manifest;entry;tagged;blurring;start;paint;kept;constructor(t,e,n,r,i){this.start=i,this.home=t,this.manifest=e,this.entry=n,this.tagged=new Set(e.palettes.flatMap((o)=>o.booru?[o.booru]:[])),this.tone=Hn(n,n.signatureSlots),this.blurring=oi(t);let s={size:"fill",at:Wj,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:Xg(this.setting("TTHEME_FIND_ORDER")),solo:this.setting("TTHEME_FIND_SOLO")==="on",rating:Li(this.setting("TTHEME_FIND_RATING")),block:Zs(this.setting("TTHEME_FIND_BLOCK")),sets:this.setting("TTHEME_FIND_SETS")==="show"?"show":"fold",narrow:this.narrowed(),enabled:Sa(this.setting("TTHEME_FIND_SITES")),hide:du(this.setting("TTHEME_FIND_HIDE")),hideTags:Ea(this.setting("TTHEME_FIND_HIDE_TAGS")),advanced:!1,settings:Ns.map((o)=>({label:o.label,choices:[...o.choices],value:this.setting(o.name),default:VM(o,Qa(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:XM(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,Vt.findIndex((o)=>o.name.toLowerCase()===process.env.TTHEME_SCENE)),details:!1,tune:{...s},untuned:s,coloring:bl(t),editing:r===""?"":void 0,chips:[]},this.paint=new Zg({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 Yg({home:t,manifest:e,entry:n,signal:this.signal,credited:()=>{this.show(),this.inform(),this.paint.draw()}}),this.pool=this.selected(this.view),this.syncChips(),this.board=Lf(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:Z[this.tab-1]}get sites(){return this.site?[this.site]:Z.filter((t)=>this.view.enabled.includes(t.name))}get tabName(){return this.site?.name??"all"}get tabAnsi(){return this.site?.ansi??Nj}get nextTabName(){let t=(this.tab+1)%(Z.length+1);return t===0?"all":Z[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 Jd(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 Zn(ln(t),"orig",`${e}.${n}`)}previewPath(t){let{url:e}=mu(t.site,t.post);return Zn(ln(t.site),"thumb",`${ax(t.post.id,e)}.${Kr(e)}`)}tileOf(t,e){let{site:n,post:r}=t,i=ee(n,r.id),s=un(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===Dn?"":n.pageUrl(r.id),artist:n===Dn?yE(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&&mf(e);return wi({modes:[Er,...bi()],assume:[zn,gi],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(is);let n=new Promise((i)=>{this.done=i}),r=setInterval(this.onClock,250);setTimeout(Lu,0);try{let i=new wc,s=await e.ask(ql,(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(jj,(o)=>o.kind==="attributes"?!0:void 0,500,!1);if(this.grabber.start(),e.hold(IS),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\\${is}`),this.kept.save(),this.renders.close(),Ff(this.scratch,{recursive:!0,force:!0}),W0()}})}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!hu(e,this.site??Z[0]);return na(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 — ${rx}`);return}this.pasted(t.text);return}await this.bring(()=>df(t.bytes,t.source))}notice(t,e=ex){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 xE()}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 · ${Bj} uses it`,clearTimeout(this.peekTimer),this.peekTimer=setTimeout(()=>{t.hint=void 0,this.paint.draw()},_j),this.paint.draw()}async fromClipboard(){let t=this.view;if(yg()){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 ME(Zn(this.scratch,`clipboard-${Date.now()}.png`))}catch(r){this.notice(`Could not read the clipboard: ${Yc(r)}`);return}if(clearTimeout(this.peekTimer),t.hint=void 0,"image"in e){await this.bring(async(r)=>({...await kg(e.image,r),source:"clipboard"}));return}let n=e.text.trim();if(!n){this.notice(`No picture on the clipboard — ${rx}`);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=hu(e,this.site??Z[0]);if(i){await this.jump(i.site,i.id);return}}let[n,...r]=na(e).sort((i,s)=>Number(!nx.test(i))-Number(!nx.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)=>kg(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(Yc(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=SE(i.bytes);vE(s,i.source);let o=this.origPath(Dn,s,i.ext);H(o,i.bytes);let a=YM(o).href,c={id:s,file:a,width:i.width,height:i.height,ext:i.ext,preview:a,owner:"",score:0,rating:"s",md5:cx("md5").update(i.bytes).digest("hex"),source:i.source,tags:[],named:{artist:[],character:[],copyright:[]},solo:void 0,family:0,smaller:[]},u={site:Dn,post:c},f=this.previewPath(u);H(f,i.bytes),++this.gen,this.current=void 0,n.shown=void 0;let l=Lf(`local|post:${s}`,!1);this.board=l,this.boards.set(l.key,l),this.single(l,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)=>Nn(i)>Nn(r)?i:r),e=Math.ceil((Nn(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<ks.cols||this.rows<ks.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)ZM(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*Mr(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=Cf+Math.round(i*(s-Cf+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}=Mr(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=Z.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"||t==="O"){this.openPage(t==="O");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=Pc(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=Pc(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=nE(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(Ns[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":Ea(r).join(" "),n.typing=void 0,this.recount(),e==="enter"){this.paint.draw();return}this.panelKey(e);return}let i=gs(r,e,(s)=>t.entry==="number"?/^[0-9]$/.test(s)&&r.length<fg:/^[\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),Hj)}pending(){let t=(e)=>this.view.settings[Ns.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:Xg(t("TTHEME_FIND_ORDER")),rating:Li(t("TTHEME_FIND_RATING")),narrow:Jd(t("TTHEME_FIND_MIN_SCORE"),t("TTHEME_FIND_MIN_SIZE"),t("TTHEME_FIND_PNG")),enabled:Sa(t("TTHEME_FIND_SITES"))}}async countPending(t){let e=this.pending(),n=this.site?[this.site]:Z.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 Xd(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=Ns.map((r)=>this.setting(r.name));t.settings.forEach((r,i)=>{let s=Ns[i];if(s)this.values.set(s.name,r.value)});let n=Ns.filter((r,i)=>this.setting(r.name)!==e[i]);if(n.length===0){this.paint.draw();return}this.save(n),t.rating=Li(this.setting("TTHEME_FIND_RATING")),t.block=Zs(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=Xg(this.setting("TTHEME_FIND_ORDER")),t.solo=this.setting("TTHEME_FIND_SOLO")==="on",t.narrow=this.narrowed(),t.enabled=Sa(this.setting("TTHEME_FIND_SITES")),t.hide=du(this.setting("TTHEME_FIND_HIDE")),t.hideTags=Ea(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=Zn(this.home,"ttheme","config.zsh");try{let n=Jc(e)?yj(e,"utf8"):"";return H(e,t.reduce((r,[i,s])=>wl(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=gs(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=Aj(n),i=rk(e,sx,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?_k(this.manifest.palettes,this.entry,n).map((c)=>({value:c.booru,count:0,palette:c.name})):[],o=[...new Map([...s.slice(0,sx),...i].map((c)=>[c.value,c])).values()];if(t.suggest=o.length>0?o:void 0,i.length>0&&Kj.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 q0(n,AbortSignal.any([this.signal,a.signal]));if(this.suggesting===a&&t.editing!==void 0){let u=new Map(c.map((l)=>[l.value,l.count])),f=new Set(o.map((l)=>l.value));t.suggest=[...o.map((l)=>({...l,count:u.get(l.value)??0})),...c.filter((l)=>!f.has(l.value))].slice(0,zj),t.pick=t.pick!==void 0&&t.pick<o.length?t.pick:void 0,this.paint.draw()}}catch{}},Tj)}async commit(t){let e=hu(t,this.site??Z[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=Z.indexOf(t)+1,this.syncSite(),this.current=void 0,this.view.shown=void 0,this.view.error=void 0;let r=Lf(`${t.key}|post:${e}`,!0);this.board=r,this.boards.set(r.key,r),this.show(),this.paint.draw();try{let i=await Ci(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,this.thumbQueue.push(...n.posts.filter((i)=>!this.thumbPath.has(ee(i.site,i.post.id)))),this.thumbs(),this.show(),this.scroll(),this.paint.glide(),this.paint.draw();return}e+=r}}openPage(t){let e=this.view.tiles[this.view.focus],n=e&&this.posts.get(e.key);if(!n)return;let r=ji(n.post.source),i=n.site===Dn?"":n.site.pageUrl(n.post.id),s=!t&&/^https?:\/\//i.test(r)?r:i;if(s)ZM(s)}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"||t==="O"){this.openPage(t==="O");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=Pj[t];if(i!==void 0){if(n.field===0)r.size=Ij(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=G0(e,n),s=new Set([...r.artist,...r.character,...r.copyright]),o=ji(n.source),a=/^https?:\/\//i.test(o)?o:e===Dn&&o.startsWith("/")?YM(o).href:void 0;return{page:e===Dn?"":e.pageUrl(n.id),source:o,...a?{link:a}:{},artists:r.artist,profiles:Object.fromEntries(Object.entries(this.kept.links(r.artist)).map(([c,u])=>[c,Ra(u)])),characters:r.character,series:r.copyright,tags:n.tags.filter((c)=>!s.has(c)),...i?{rating:i}:{},...n.posted?{posted:n.posted}:{},ext:(un(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}=Mr(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.manifest.palettes.find((r)=>r.booru===t);return n?Bk(n,e):[t]}syncChips(){let t=this.selected(this.view);this.view.chips=this.pool.slice(0,qj).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 D0(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?J0(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((f)=>`~${f}`).join(" "):n[0],t.rate(e.rating),...t.narrow(e.narrow),o?"":s,e.order==="score"?t.best:""].filter(Boolean),c=[],u=[];for(let f of a)if(Zd([...c,f].join(" "))<=t.tagBudget)c.push(f);else u.push(f);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=Lf(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=Zd(a)+1<=o.tagBudget?o.uploadedBy:void 0;return[...u?c.keys().map((f)=>({site:o,tags:`${a} ${u(f)}`,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})=>Xd(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=Qg(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,Qg(e.name,n)].filter(Boolean).join(" · ")}wants(){let{perRow:t,rowsVis:e}=Mr(this.cols,this.rows);return this.view.tiles.length<(this.board.top+e+ix)*t}need(){let{perRow:t,rowsVis:e}=Mr(this.cols,this.rows);return(e+ix)*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=K0(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===It?[]:e.filter((r)=>r.md5!=="");if(n.length>0)try{Oa(n,await Pa(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=Z.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<An;let u=t.last.get(a);for(let f of c){let l=u&&QE(u.post,f)?u.set:`set:${a.site.key}:${f.id}`;u={post:f,set:l};let d=ee(a.site,f.id);if(t.seen.has(d))continue;t.seen.add(d);let h={site:a.site,post:f};if(this.eligible(h))t.kin.set(h,[l,...XE(a.site,f)]),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?UE(i):i;else{let a=gf(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=[...gf(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(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,s)=>t.roundOf.get(i)===e?[s]:[]),r=gf(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=Lg(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++,ox(r.post)<=ox(s.post))continue;for(let a of[...i,...Lg(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(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:tx},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=mu(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<QM&&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<QM&&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=un(e);if(!gu(t,e,this.view.rating)||pu(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"||B0(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=ee(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)=>eM(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=XM(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=Pe.cols*this.cell.w,e=Pe.rows*this.cell.h;if(t===0||e===0)return;for(let n of this.view.held.slice(0,cg(this.cols))){if(n.thumb||this.heldAsked.has(n.from))continue;this.heldAsked.add(n.from);let r=Zn(this.scratch,`held-${Ej(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<tx&&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=Et.cols*this.cell.w,i=Et.rows*this.cell.h,s=mu(e,n),o=Zn(ln(e),"tile",`${ax(n.id,s.url)}-${r}x${i}.png`);if(!Jc(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(ee(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),Cj),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.profile(n,r.signal),!un(n.post))return;let{site:i}=n,s=this.board,o;try{await Ia(i,n.post,r.signal);let c=un(n.post),u=this.origPath(i,t.id,c.ext);if(!Jc(u))e.fetching={id:t.key,got:0,size:0},this.paint.draw();let f=qr(i,n.post,c),l=await this.kept.cached(f.site,u,f.url,(m,p)=>{if(e.fetching?.id===t.key)e.fetching={id:t.key,got:m,size:p},this.paint.draw()});if(r.signal.aborted)return;if(e.fetching=void 0,s!==this.board)return;let d={site:i,id:t.id,key:t.key,path:u,ext:c.ext,size:l,using:"plain",failed:!1};e.preparing=t.key,this.paint.flush();let h=await this.render(d,"plain");if(r.signal.aborted||s!==this.board)return;if(o=h.clear===0?await this.twinOf(n,u,r.signal):void 0,o||r.signal.aborted||s!==this.board)return;if(h.clear===0&&Qs()&&this.setting("TTHEME_FIND_REMOVE_BG")!=="off"){if(e.preparing=void 0,e.cutting=t.key,this.paint.flush(),d.cut=await this.cutOut(i,t.id,u,r.signal),r.signal.aborted||s!==this.board)return;if(e.cutting=void 0,d.cut){e.preparing=t.key,this.paint.flush();let m=await this.render(d,"cut").catch(()=>{return});if(r.signal.aborted||s!==this.board)return;if(m&&yu(m.clear))d.using="cut";else Ff(d.cut,{force:!0}),d.cut=void 0,d.failed=!0}else d.failed=!0}if(this.current=d,e.tiles[e.focus]?.key===t.key)await this.present();this.preload()}catch(c){if(!r.signal.aborted&&!this.signal.aborted)e.error=Qg(i.name,c)}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()}let a=o&&s===this.board?this.swapIn(o):void 0;if(a)await this.load(a)}async twinOf(t,e,n){let r=this.view,i=this.board.groups.find((s)=>!s.open&&s.posts[0]===t);for(let s of i?.posts.slice(1)??[]){let o=ee(s.site,s.post.id),a=`${ee(t.site,t.post.id)}>${o}`;if(this.twins.get(a)===!1||!await this.kept.transparent(s.site,s.post))continue;let c=un(s.post);if(n.aborted||c?.ext!=="png")continue;try{let u=this.origPath(s.site,s.post.id,c.ext),f=qr(s.site,s.post,c);r.fetching={id:o,got:0,size:0},await this.kept.cached(f.site,u,f.url,(d,h)=>{if(r.fetching?.id===o)r.fetching={id:o,got:d,size:h},this.paint.draw()}),r.fetching=void 0,r.preparing=o,this.paint.flush();let l=this.twins.get(a)??await this.renders.run({job:"twin",cut:u,whole:e});if(this.twins.set(a,l),l&&i?.posts.includes(s)&&!n.aborted)return i.posts.splice(i.posts.indexOf(s),1),i.posts.unshift(s),s}catch{this.twins.set(a,!1)}finally{if(r.fetching?.id===o)r.fetching=void 0;if(r.preparing===o)r.preparing=void 0}}return}swapIn(t){let e=this.view,n=ee(t.site,t.post.id);if(!this.thumbPath.has(n))this.thumbQueue.push(t),this.thumbs();this.show(),this.inform();let r=e.tiles[e.focus];if(r?.key!==n)return;return e.hint=`Trying ${t.site.name} ${t.post.id}, the same picture with a transparent background`,clearTimeout(this.peekTimer),this.peekTimer=setTimeout(()=>{e.hint=void 0,this.paint.draw()},ex),this.paint.draw(),r}async cutOut(t,e,n,r){let i=Zn(ln(t),"cut",`${e}.png`);if(Jc(i))return i;try{return $j(Mj(i),{recursive:!0}),await Na(n,i,r),i}catch{Ff(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.profile(r,this.signal);if(this.prefetching>=Fj||!r||!un(r.post))continue;let{site:i,post:s}=r;this.prefetching++,Ia(i,s,this.signal).then(async()=>{let o=un(s),a=this.origPath(i,s.id,o.ext),c=qr(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,Gj),s=Math.max(1,Math.round(r*i/n)),o={...this.view.tune},{coloring:a}=this.view,c=!ux(o,this.view.untuned),u=o.opacity!==this.view.untuned.opacity,f=c?`-${o.size}-${o.at}${u?`-${Math.round(o.opacity*100)}`:""}`:"",l=Zn(this.scratch,`${t.site.key}-${t.id}${e==="cut"?"c":""}${a==="original"?"o":""}-${i}x${s}${f}.png`),d=`${t.site.key}:${t.id}:${e}:${a}:${i}x${s}`,h=this.clarity.get(d);if(h&&Jc(l))return t.fill=h.fill,{clear:h.clear,path:l,opacity:h.opacity,touched:u};let m=await this.renders.run({job:"show",from:e==="cut"?t.cut:t.path,cut:e==="cut",to:l,width:i,height:s,colors:this.entry,tone:this.tone,blur:this.blurring*i/bh(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(l);return{clear:m.clear,path:l,opacity:m.opacity,touched:u}}keepTuned(t){this.tunedFiles.push(t);while(this.tunedFiles.length>Uj){let e=this.tunedFiles.findIndex((n)=>n!==this.view.shown?.path&&n!==t);if(e===-1)return;Ff(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=Rj(t.tune,t.untuned),i=this.posts.get(n.key),s=i?.post;if(i)await Promise.race([this.kept.profile(i,this.signal),xj(Lj,void 0,{ref:!1})]);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:s?.named.artist??[],profiles:this.kept.links(s?.named.artist??[]),source:ji(s?.source??"")},width:this.cols*this.cell.w,height:this.rows*this.cell.h,blur:this.blurring,coloring:t.coloring,...r?{tune:r,aligns:fs(q(this.home).terminals),user:vj()}:{}}),this.kept.owned(n.site,n.id,s?.owner??""),Ue(this.home),this.holds();let{size:o,at:a,opacity:c}=t.tune,u=r?` · ${o==="fill"?"fill":`${o}%`} · ${Jt[a-1]} · ${c.toFixed(2)}`:"",f=s?.named.artist.length?`${s.named.artist.join(", ")} · `:"";t.saved={text:`Background · ${this.entry.name} ← ${f}${n.site.name} ${n.id}${u}`,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 lx(t,e,n){let r=new tb(t,ve(t),e,e.booru??"",n);if(await r.run(),ns(process.env))process.stdout.write(rs(""));return{saved:r.saved,installs:r.installs}}async function fx(t){let e=Y(),n=ve(e),r=jn(n.palettes,t);if(!process.stdin.isTTY||!process.stdout.isTTY)throw Error("needs a terminal");let i=new tb(e,n,r,r.booru??""),s=await i.run();if(i.saved&&s!==0)return process.stderr.write(`${i.saved}
730
+ `),0;return s}var Ts=((t)=>{return t[t.Border=-1]="Border",t[t.Data=0]="Data",t[t.Function=1]="Function",t[t.Position=2]="Position",t[t.Timing=3]="Timing",t[t.Alignment=4]="Alignment",t})(Ts||{}),Dj=[0,1],hx=[1,0],mx=[2,3],px=[3,2],Jj={L:Dj,M:hx,Q:mx,H:px},Yj=/^\d*$/,Vj=/^[A-Z0-9 $%*+./:-]*$/,eb="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:",ib=1,sb=40,dx=3,Zj=3,jf=40,Xj=10,gx=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],bx=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]];class wx{constructor(t,e,n,r){if(this.version=t,this.ecc=e,t<ib||t>sb)throw RangeError("Version value out of range");if(r<-1||r>7)throw RangeError("Mask value out of range");this.size=t*4+17;let i=Array.from({length:this.size}).fill(!1);for(let o=0;o<this.size;o++)this.modules.push(i.slice()),this.types.push(i.map(()=>0));this.drawFunctionPatterns();let s=this.addEccAndInterleave(n);if(this.drawCodewords(s),r===-1){let o=1e9;for(let a=0;a<8;a++){this.applyMask(a),this.drawFormatBits(a);let c=this.getPenaltyScore();if(c<o)r=a,o=c;this.applyMask(a)}}this.mask=r,this.applyMask(r),this.drawFormatBits(r)}size;mask;modules=[];types=[];getModule(t,e){return t>=0&&t<this.size&&e>=0&&e<this.size&&this.modules[e][t]}drawFunctionPatterns(){for(let n=0;n<this.size;n++)this.setFunctionModule(6,n,n%2===0,Ts.Timing),this.setFunctionModule(n,6,n%2===0,Ts.Timing);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);let t=this.getAlignmentPatternPositions(),e=t.length;for(let n=0;n<e;n++)for(let r=0;r<e;r++)if(!(n===0&&r===0||n===0&&r===e-1||n===e-1&&r===0))this.drawAlignmentPattern(t[n],t[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(t){let e=this.ecc[1]<<3|t,n=e;for(let i=0;i<10;i++)n=n<<1^(n>>>9)*1335;let r=(e<<10|n)^21522;for(let i=0;i<=5;i++)this.setFunctionModule(8,i,Rr(r,i));this.setFunctionModule(8,7,Rr(r,6)),this.setFunctionModule(8,8,Rr(r,7)),this.setFunctionModule(7,8,Rr(r,8));for(let i=9;i<15;i++)this.setFunctionModule(14-i,8,Rr(r,i));for(let i=0;i<8;i++)this.setFunctionModule(this.size-1-i,8,Rr(r,i));for(let i=8;i<15;i++)this.setFunctionModule(8,this.size-15+i,Rr(r,i));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let t=this.version;for(let n=0;n<12;n++)t=t<<1^(t>>>11)*7973;let e=this.version<<12|t;for(let n=0;n<18;n++){let r=Rr(e,n),i=this.size-11+n%3,s=Math.floor(n/3);this.setFunctionModule(i,s,r),this.setFunctionModule(s,i,r)}}drawFinderPattern(t,e){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),s=t+r,o=e+n;if(s>=0&&s<this.size&&o>=0&&o<this.size)this.setFunctionModule(s,o,i!==2&&i!==4,Ts.Position)}}drawAlignmentPattern(t,e){for(let n=-2;n<=2;n++)for(let r=-2;r<=2;r++)this.setFunctionModule(t+r,e+n,Math.max(Math.abs(r),Math.abs(n))!==1,Ts.Alignment)}setFunctionModule(t,e,n,r=Ts.Function){this.modules[e][t]=n,this.types[e][t]=r}addEccAndInterleave(t){let e=this.version,n=this.ecc;if(t.length!==_f(e,n))throw RangeError("Invalid argument");let r=bx[n[0]][e],i=gx[n[0]][e],s=Math.floor(nb(e)/8),o=r-s%r,a=Math.floor(s/r),c=[],u=a6(i);for(let l=0,d=0;l<r;l++){let h=t.slice(d,d+a-i+(l<o?0:1));d+=h.length;let m=c6(h,u);if(l<o)h.push(0);c.push(h.concat(m))}let f=[];for(let l=0;l<c[0].length;l++)c.forEach((d,h)=>{if(l!==a-i||h>=o)f.push(d[l])});return f}drawCodewords(t){if(t.length!==Math.floor(nb(this.version)/8))throw RangeError("Invalid argument");let e=0;for(let n=this.size-1;n>=1;n-=2){if(n===6)n=5;for(let r=0;r<this.size;r++)for(let i=0;i<2;i++){let s=n-i,a=(n+1&2)===0?this.size-1-r:r;if(!this.types[a][s]&&e<t.length*8)this.modules[a][s]=Rr(t[e>>>3],7-(e&7)),e++}}}applyMask(t){if(t<0||t>7)throw RangeError("Mask value out of range");for(let e=0;e<this.size;e++)for(let n=0;n<this.size;n++){let r;switch(t){case 0:r=(n+e)%2===0;break;case 1:r=e%2===0;break;case 2:r=n%3===0;break;case 3:r=(n+e)%3===0;break;case 4:r=(Math.floor(n/3)+Math.floor(e/2))%2===0;break;case 5:r=n*e%2+n*e%3===0;break;case 6:r=(n*e%2+n*e%3)%2===0;break;case 7:r=((n+e)%2+n*e%3)%2===0;break;default:throw Error("Unreachable")}if(!this.types[e][n]&&r)this.modules[e][n]=!this.modules[e][n]}}getPenaltyScore(){let t=0;for(let i=0;i<this.size;i++){let s=!1,o=0,a=[0,0,0,0,0,0,0];for(let c=0;c<this.size;c++)if(this.modules[i][c]===s){if(o++,o===5)t+=dx;else if(o>5)t++}else{if(this.finderPenaltyAddHistory(o,a),!s)t+=this.finderPenaltyCountPatterns(a)*jf;s=this.modules[i][c],o=1}t+=this.finderPenaltyTerminateAndCount(s,o,a)*jf}for(let i=0;i<this.size;i++){let s=!1,o=0,a=[0,0,0,0,0,0,0];for(let c=0;c<this.size;c++)if(this.modules[c][i]===s){if(o++,o===5)t+=dx;else if(o>5)t++}else{if(this.finderPenaltyAddHistory(o,a),!s)t+=this.finderPenaltyCountPatterns(a)*jf;s=this.modules[c][i],o=1}t+=this.finderPenaltyTerminateAndCount(s,o,a)*jf}for(let i=0;i<this.size-1;i++)for(let s=0;s<this.size-1;s++){let o=this.modules[i][s];if(o===this.modules[i][s+1]&&o===this.modules[i+1][s]&&o===this.modules[i+1][s+1])t+=Zj}let e=0;for(let i of this.modules)e=i.reduce((s,o)=>s+(o?1:0),e);let n=this.size*this.size,r=Math.ceil(Math.abs(e*20-n*10)/n)-1;return t+=r*Xj,t}getAlignmentPatternPositions(){if(this.version===1)return[];else{let t=Math.floor(this.version/7)+2,e=this.version===32?26:Math.ceil((this.version*4+4)/(t*2-2))*2,n=[6];for(let r=this.size-7;n.length<t;r-=e)n.splice(1,0,r);return n}}finderPenaltyCountPatterns(t){let e=t[1],n=e>0&&t[2]===e&&t[3]===e*3&&t[4]===e&&t[5]===e;return(n&&t[0]>=e*4&&t[6]>=e?1:0)+(n&&t[6]>=e*4&&t[0]>=e?1:0)}finderPenaltyTerminateAndCount(t,e,n){if(t)this.finderPenaltyAddHistory(e,n),e=0;return e+=this.size,this.finderPenaltyAddHistory(e,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(t,e){if(e[0]===0)t+=this.size;e.pop(),e.unshift(t)}}function Ar(t,e,n){if(e<0||e>31||t>>>e!==0)throw RangeError("Value out of range");for(let r=e-1;r>=0;r--)n.push(t>>>r&1)}function Rr(t,e){return(t>>>e&1)!==0}class Bf{constructor(t,e,n){if(this.mode=t,this.numChars=e,this.bitData=n,e<0)throw RangeError("Invalid argument");this.bitData=n.slice()}getData(){return this.bitData.slice()}}var Qj=[1,10,12,14],t6=[2,9,11,13],e6=[4,8,16,16];function $x(t,e){return t[Math.floor((e+7)/17)+1]}function kx(t){let e=[];for(let n of t)Ar(n,8,e);return new Bf(e6,t.length,e)}function n6(t){if(!yx(t))throw RangeError("String contains non-numeric characters");let e=[];for(let n=0;n<t.length;){let r=Math.min(t.length-n,3);Ar(Number.parseInt(t.substring(n,n+r),10),r*3+1,e),n+=r}return new Bf(Qj,t.length,e)}function r6(t){if(!vx(t))throw RangeError("String contains unencodable characters in alphanumeric mode");let e=[],n;for(n=0;n+2<=t.length;n+=2){let r=eb.indexOf(t.charAt(n))*45;r+=eb.indexOf(t.charAt(n+1)),Ar(r,11,e)}if(n<t.length)Ar(eb.indexOf(t.charAt(n)),6,e);return new Bf(t6,t.length,e)}function i6(t){if(t==="")return[];else if(yx(t))return[n6(t)];else if(vx(t))return[r6(t)];else return[kx(o6(t))]}function yx(t){return Yj.test(t)}function vx(t){return Vj.test(t)}function s6(t,e){let n=0;for(let r of t){let i=$x(r.mode,e);if(r.numChars>=1<<i)return Number.POSITIVE_INFINITY;n+=4+i+r.bitData.length}return n}function o6(t){t=encodeURI(t);let e=[];for(let n=0;n<t.length;n++)if(t.charAt(n)!=="%")e.push(t.charCodeAt(n));else e.push(Number.parseInt(t.substring(n+1,n+3),16)),n+=2;return e}function nb(t){if(t<ib||t>sb)throw RangeError("Version number out of range");let e=(16*t+128)*t+64;if(t>=2){let n=Math.floor(t/7)+2;if(e-=(25*n-10)*n-55,t>=7)e-=36}return e}function _f(t,e){return Math.floor(nb(t)/8)-gx[e[0]][t]*bx[e[0]][t]}function a6(t){if(t<1||t>255)throw RangeError("Degree out of range");let e=[];for(let r=0;r<t-1;r++)e.push(0);e.push(1);let n=1;for(let r=0;r<t;r++){for(let i=0;i<e.length;i++)if(e[i]=rb(e[i],n),i+1<e.length)e[i]^=e[i+1];n=rb(n,2)}return e}function c6(t,e){let n=e.map((r)=>0);for(let r of t){let i=r^n.shift();n.push(0),e.forEach((s,o)=>n[o]^=rb(s,i))}return n}function rb(t,e){if(t>>>8!==0||e>>>8!==0)throw RangeError("Byte out of range");let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(e>>>r&1)*t;return n}function u6(t,e,n=1,r=40,i=-1,s=!0){if(!(ib<=n&&n<=r&&r<=sb)||i<-1||i>7)throw RangeError("Invalid value");let o,a;for(o=n;;o++){let l=_f(o,e)*8,d=s6(t,o);if(d<=l){a=d;break}if(o>=r)throw RangeError("Data too long")}for(let l of[hx,mx,px])if(s&&a<=_f(o,l)*8)e=l;let c=[];for(let l of t){Ar(l.mode[0],4,c),Ar(l.numChars,$x(l.mode,o),c);for(let d of l.getData())c.push(d)}let u=_f(o,e)*8;Ar(0,Math.min(4,u-c.length),c),Ar(0,(8-c.length%8)%8,c);for(let l=236;c.length<u;l^=253)Ar(l,8,c);let f=Array.from({length:Math.ceil(c.length/8)},()=>0);return c.forEach((l,d)=>f[d>>>3]|=l<<7-(d&7)),new wx(o,e,f,i)}function Sx(t,e){let{ecc:n="L",boostEcc:r=!1,minVersion:i=1,maxVersion:s=40,maskPattern:o=-1,border:a=1}=e||{},c=typeof t==="string"?i6(t):Array.isArray(t)?[kx(t)]:void 0;if(!c)throw Error(`uqr only supports encoding string and binary data, but got: ${typeof t}`);let u=u6(c,Jj[n],i,s,o,r),f=l6({version:u.version,maskPattern:u.mask,size:u.size,data:u.modules,types:u.types},a);if(e?.invert)f.data=f.data.map((l)=>l.map((d)=>!d));return e?.onEncoded?.(f),f}function l6(t,e=1){if(!e)return t;let{size:n}=t,r=n+e*2;t.size=r,t.data.forEach((s)=>{for(let o=0;o<e;o++)s.unshift(!1),s.push(!1)});for(let s=0;s<e;s++)t.data.unshift(Array.from({length:r},(o)=>!1)),t.data.push(Array.from({length:r},(o)=>!1));let i=Ts.Border;t.types.forEach((s)=>{for(let o=0;o<e;o++)s.unshift(i),s.push(i)});for(let s=0;s<e;s++)t.types.unshift(Array.from({length:r},(o)=>i)),t.types.push(Array.from({length:r},(o)=>i));return t}var f6=Zk(16,231),d6=[" ","▀","▄","█"],h6=2953;function Ex(t){if(Buffer.byteLength(t)>h6)return;let{data:e}=Sx(t,{border:2,boostEcc:!0}),n=[];for(let r=0;r<e.length;r+=2){let i=e[r]??[],s=e[r+1]??[];n.push(`${f6}${i.map((o,a)=>d6[(o?1:0)+(s[a]?2:0)]).join("")}${Se}`)}return n}var m6=50;function p6(t){return{background:t.background,foreground:t.foreground,cursor:t.cursor,selection:t.selection,ansi:t.ansi}}function g6(t,e,n){for(let r of n){let i=t-4-r.length;if(i>e.length+2)return[[2,e],[i,` ${r} `]]}return[[2,e]]}function Mx(t,e,n,r=m6){let i=je(n),s=rn(p6(e)),o=Ok(t).map((m)=>m.toLowerCase()),a=Rg(s,e.signatureSlots,e.waived??[]),c=ir(Or(s,e.signatureSlots,e.waived??[])).length,u=(m)=>s[m]?.toLowerCase()!==o[m],f=s.filter((m,p)=>u(p)).length,l=(m)=>{let p=s[m],b=e.signatureSlots.includes(Yn[m])?R.signature:n?R.swatch:" ",$=n?`${i.fg(p)}${b}${kt}`:b,k=a.has(m)?i.bold(R.miss):u(m)?i.warn(R.on):" ";return` ${$} ${Mf(Pt(p))}${k}`},d=c===0?"passes the gate":`${c} ${c===1?"miss":"misses"} in the gate`,h=f>0?[`${f} tuned · ${d}`,d]:[d];return[i.dim(Gt(r,"top",g6(r," Palette ",h))),...F.map((m,p)=>Ze(i,` ${m.padEnd(10)}${l(p)}`,r)),i.dim(Gt(r,"mid",[[2," ANSI "],[12," Normal 0–7 "],[29," Bright 8–15 "]])),...Sn.map((m,p)=>Ze(i,` ${m.padEnd(10)}${l(F.length+p)}${l(F.length+8+p)}`,r)),i.dim(Gt(r,"bottom"))]}function la(){return process.stdin.isTTY===!0&&process.stdout.isTTY===!0}async function ab(){let t=process.env.TTHEME_WORN;if(!t||!la())return;let e=await Be({message:`Use ${t}, the palette this tab wears?`});if(se(e)||!e)throw new we;return t}async function Px(t){let e=process.env.TTHEME_WORN;if(!e)return;if(!la())return console.error(`Sharing ${e}, the palette this tab wears`),{name:e,...t?{tone:t}:{}};if(t!==void 0||zt(Y())[e]===void 0)return await ab(),{name:e,...t?{tone:t}:{}};let n=await km({message:`Share ${e}, the palette this tab wears?`,options:[{value:"tuned",label:"Your tone",hint:`named ${Vc(e)}`},{value:"original",label:"The original"},{value:"no",label:"No"}]});if(se(n)||n==="no")throw new we;return{name:e,tone:n}}function Ix(t,e){if(t.includes("/"))return t;let n=Vi(e,!1),r=n.filter((s)=>wo(s.dir).some((o)=>o.slug===t)),[i]=r.length===1?r:n.length===1?n:[];return i?`${i.id}/${t}`:t}function $6(t,e,n){let r=q(t),i=n.filter((s)=>!r.palettes.includes(s));if(i.length>0)en(t,e,r,{...r,palettes:[...r.palettes,...i]});else if(n.some((s)=>r.palettes.includes(s)))Dt(t,e,r);return{state:r,fresh:i}}function k6(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 xx(t){return JSON.stringify([t.background,t.foreground,t.cursor,t.selection,t.ansi])}function Rx(t,e,n){let r=Sk(e,n.palettes),i=hr(t,n,!1).palettes.find((s)=>s.name===r.name);if(i&&xx(i)!==xx(r))throw Error(`${r.name} is already in ${et(r.name)??"the official marketplace"} and differs — \`ttheme add ${r.name}\` wears that one`);if(!i)yo(t,[...Qr(t),r]);return r}var y6=["background","foreground","cursor"];function Ax(t){try{t();return}catch(e){return e.message}}function Nx(t,e,n){return qt(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 Tx(t,e){let n=new Set(ke(t,e).map((r)=>r.key));return{count:()=>ke(t,e).length,added:()=>ke(t,e).filter((r)=>!n.has(r.key)).length,fresh:()=>(wf(t,e)??[]).filter((r)=>!n.has(me(r))),discard:()=>{let r=ke(t,e).filter((i)=>!n.has(i.key));for(let i of r)co(t,e,i.key),Ru(t,e);if(r.length>0)Ue(t)}}}function v6(...t){let e=new Map(t.flatMap((n)=>n??[]).map((n)=>[me(n),n]));return e.size>0?[...e.values()]:void 0}function Hx(t,e,n,r){if(!xo(process.env,q(t).terminals))return;return async(i,s)=>{let o=dn(Ln(e,r(i),n.palettes)),{saved:a}=await lx(t,o,s);return{...a?{note:a}:{},count:ke(t,e).length}}}async function cb(t,e=!1){let n=process.stdout.isTTY===!0,r=Y(),i=q(r).terminals,s=n?yf.of(process.env,r,t.name,i):void 0,o=n?Rf.of(process.env,i):void 0;return qM(t,{color:!Ct(),...s?{backdrop:s}:{},...o?{layer:o}:{},...e?{hosted:!0}:{}})}async function Fx(t,e,n){let r=Y(),i=lt(r),s=await uS(r,n),o=t.includes("/")?t:`${s.id}/${t}`,a=re(o);if(a)throw Error(`${o} ${a}`);if(et(o)!==s.id)throw Error(`palettes in ${s.dir} are named ${s.id}/<palette> — ${o} belongs elsewhere`);let c=Bh(r,o);if(Zc(c))throw Error(`${o} already exists — \`ttheme edit ${o}\` changes it`);let u=e?jn(qt(r,i).palettes,e):void 0;if(!la())throw Error("new opens the palette editor — run it in a terminal");let f=u&&(et(u.name)?u.base:u.default?void 0:u.name),l=u?Uh(u,o,`kept from ${u.name}`):void 0,d=u?wf(r,u.name)??u.pictures:void 0,{base:h,ansiSource:m,...p}=l??{name:o,signature:y6,...vi(Fc)},b=Tx(r,o),$=({colors:S,signature:x})=>{let M=v6(d,b.fresh());return Wh({...p,...S,signature:x,...f?{base:f}:{},...M?{pictures:M}:{}})},k=await cb({title:"New palette",name:o,...l?{colors:l}:{},signature:p.signature,...p.waive?{waive:p.waive}:{},palettes:Nx(r,i,o),pictures:b.count(),find:Hx(r,o,i,$),exports:Ux(r,o,i,$),decode:ub,check:(S)=>Ax(()=>Ln(o,$(S),i.palettes))});if(!k){b.discard(),console.log("Nothing made");return}b6(w6(c),{recursive:!0}),H(c,$(k));let{state:v}=$6(r,i,[o]);console.log(` + ${o}${u?` from ${u.name}`:""}
731
+ ${c}`),await Os(r,qt(r,i).palettes.filter((S)=>S.name===o),v.terminals),console.log(`
732
+ \`ttheme use ${o}\` wears it · \`ttheme edit ${o}\` opens it again`)}function S6(t,e,n){let r=dn(Ln(t,e,n.palettes));return Ja(r).length>0?Ua(r).filter((i)=>i.startsWith(" ✗")):[]}async function Lx(t){let e=Y(),n=lt(e),r=q(e),i=qt(e,n,!1),s=Ix(t,e),o=Gf(e,s),a=o&&Zc(o)?s:i.palettes.some((k)=>k.name===t)?t:s,c=Gf(e,a),u=!c||!Zc(c);if(u&&!i.palettes.some((k)=>k.name===a))throw Error(`no palette called ${a} — \`ttheme new\` makes one`);if(!la())throw Error("edit opens the palette editor — run it in a terminal");if(u){let k=await _x(e,a,!1);console.log(k===void 0?"Nothing changed":k===0?`${a} is back to its own colors`:`Saved ${a} · ${jx(k)} — R then s in \`ttheme edit ${a}\` puts its own colors back`);return}let f=ob(c,"utf8"),l;try{l=Ln(a,f,n.palettes)}catch(k){throw Error(`${c} cannot be read — ${k.message}`)}let d=Tx(e,a),h=new Set((l.pictures??[]).map((k)=>me(k))),m=({colors:k,signature:v})=>wk(Ek(qh(f,k),v),d.fresh().filter((S)=>!h.has(me(S)))),p=await cb({title:"Edit palette",name:a,colors:ko(l),signature:l.signatureSlots,waive:l.waive,palettes:Nx(e,n,a),pictures:d.count(),find:Hx(e,a,n,m),exports:Ux(e,a,n,m),decode:ub,check:(k)=>Ax(()=>Ln(a,m(k),n.palettes))});if(!p){d.discard(),console.log("Nothing changed");return}let b=m(p);if(b===f){console.log(d.added()>0?`Kept the pictures you added to ${a}`:"Nothing changed");return}if(H(c,b),r.palettes.includes(a))Dt(e,n,r);console.log(`Saved ${a}${r.palettes.includes(a)?" — new tabs and `ttheme use` wear it":` — \`ttheme add ${a}\` installs it`}`);let $=S6(a,b,n);if($.length>0)console.log(`
732
733
  It misses the contrast gate:
733
- ${w.join(`
734
+ ${$.join(`
734
735
  `)}
735
- \`ttheme check --fix ${a}\` suggests colors that pass`)}var fx=2;async function yx(t,e,n){let r=Y();if(e==="show"){let s=Hn(cr(r,lt(r),!1).palettes,t),o=Ga(s,Kt(r)[t]);return console.log(ux(s,o,!Ft(),n===void 0?void 0:Number(n)).join(`
736
- `)),0}if(e==="reset"){let s=Kt(r);if(s[t]===void 0)return fx;return _a(r,Hu(s,t,{})),qt(r,lt(r),q(r)),process.stderr.write("Back to the original colors"),0}if(e!=="edit")throw Error(`tone takes show, edit or reset, not ${e}`);if(!sa())throw Error("needs a terminal");let i=await Sx(r,t,!0);if(i===void 0)return fx;return process.stderr.write(i===0?"Back to the original colors":`Saved · ${vx(i)}`),0}function vx(t){return`${t} ${t===1?"color":"colors"} tuned`}async function Sx(t,e,n){let r=Hn(cr(t,lt(t),!1).palettes,e),i=Ga(r,Kt(t)[e]),s=await Qg({title:"Edit palette",name:e,colors:po(Le(i)),original:po(Le(r)),tone:!0,signature:i.signatureSlots,...i.waived?{waive:i.waived}:{},decode:tb,check:()=>{return}},n);if(!s)return;let o=Kt(t),a=Fh(r,nn(s.colors));if(JSON.stringify(a)===JSON.stringify(o[e]??{}))return;return _a(t,Hu(o,e,a)),qt(t,lt(t),q(t)),Object.keys(a).length}function Ex(t,e,n){return Hn(t.palettes,t.palettes.some((r)=>r.name===e)?e:hx(e,n))}function Mx(t,e=!1){let n=Y(),r=lt(n),i=q(n),s=Ex(zt(n,r),t,n);if(console.log(`${s.name} · ${ne(s)}
737
- `),console.log(Fa(s).join(`
738
- `)),Ua(s).length===0)return console.log(`
739
- Passes the gate`),0;let{theme:a,moves:c,left:u}=af(Le(s));if(c.length===0)return console.log(`
736
+ \`ttheme check --fix ${a}\` suggests colors that pass`)}var Ox=2;async function Cx(t,e,n){let r=Y();if(e==="show"){let s=jn(hr(r,lt(r),!1).palettes,t),o=qa(s,zt(r)[t]);return console.log(Mx(s,o,!Ct(),n===void 0?void 0:Number(n)).join(`
737
+ `)),0}if(e==="reset"){let s=zt(r);if(s[t]===void 0)return Ox;return za(r,Uu(s,t,{})),Dt(r,lt(r),q(r)),process.stderr.write("Back to the original colors"),0}if(e!=="edit")throw Error(`tone takes show, edit or reset, not ${e}`);if(!la())throw Error("needs a terminal");let i=await _x(r,t,!0);if(i===void 0)return Ox;return process.stderr.write(i===0?"Back to the original colors":`Saved · ${jx(i)}`),0}function jx(t){return`${t} ${t===1?"color":"colors"} tuned`}async function _x(t,e,n){let r=jn(hr(t,lt(t),!1).palettes,e),i=qa(r,zt(t)[e]),s=await cb({title:"Edit palette",name:e,colors:ko(Le(i)),original:ko(Le(r)),tone:!0,signature:i.signatureSlots,...i.waived?{waive:i.waived}:{},decode:ub,check:()=>{return}},n);if(!s)return;let o=zt(t),a=Dh(r,rn(s.colors));if(JSON.stringify(a)===JSON.stringify(o[e]??{}))return;return za(t,Uu(o,e,a)),Dt(t,lt(t),q(t)),Object.keys(a).length}function Bx(t,e,n){return jn(t.palettes,t.palettes.some((r)=>r.name===e)?e:Ix(e,n))}function Gx(t,e=!1){let n=Y(),r=lt(n),i=q(n),s=Bx(qt(n,r),t,n);if(console.log(`${s.name} · ${ie(s)}
738
+ `),console.log(Ua(s).join(`
739
+ `)),Ja(s).length===0)return console.log(`
740
+ Passes the gate`),0;let{theme:a,moves:c,left:u}=pf(Le(s));if(c.length===0)return console.log(`
740
741
  No color change fixes it — waive the rule in [contrast] with a reason, or pick other colors`),1;console.log(`
741
742
  ${u.length===0?"These colors pass":"These colors come closer"}:
742
- ${Zj(c).join(`
743
- `)}`);let f=Lf(n,s.name),l=!f||!zc(f);if(!e)return console.log(`
744
- \`ttheme check --fix ${s.name}\` writes them${l?" as your tone of it":""}`),1;if(l){let d=Hn(cr(n,r,!1).palettes,s.name);return _a(n,Hu(Kt(n),s.name,Fh(d,nn(po(a))))),qt(n,r,i),console.log(`
745
- Saved as your tone of ${s.name} — R then s in \`ttheme edit ${s.name}\` puts its own colors back`),u.length===0?0:1}if(L(f,Lh(Zg(f,"utf8"),po(a))),i.palettes.includes(s.name))qt(n,r,i);return console.log(`
746
- Wrote ${f}`),u.length===0?0:1}function Lf(t,e){let n=et(e);return n&&Yi(t,!1).some((r)=>r.id===n)?Rh(t,e):void 0}function tb(t){let e=mo(t);if(!e)return;try{let{background:n,foreground:r,cursor:i,selection:s,ansi:o}=Hh(e);return{background:n,foreground:r,cursor:i,selection:s,ansi:o}}catch{return}}function xx(t,e,n,r){return{code:(i)=>Th(Ox(t,un(Nn(e,r(i),n.palettes)))),toml:r,command:"ttheme add"}}function Ox(t,e){let n=Lf(t,e.name),r=n&&zc(n)?Nn(e.name,Zg(n,"utf8"),[e]).waiveReason:void 0,i=df(t,e.name)??e.pictures,{pictures:s,...o}=Ah(e,e.name,r);return{...o,...i?{pictures:i}:{}}}async function e6(t,e,n){if(t===e)return e;let r=n;if(r===void 0)if(!sa())r="tuned";else{let i=await um({message:`Share ${e.name} as…`,options:[{value:"tuned",label:"Your tone",hint:`named ${Kc(e.name)}`},{value:"original",label:"The original"}]});if(re(i))throw new pe;r=i}return r==="original"?e:t}function Kc(t){return`${t}-tuned`}async function eb(t,e){let n=Y(),r=lt(n),i=Ex(cr(n,r),t,n),s=Ga(i,Kt(n)[i.name]),o=await e6(s,i,e),a=Ox(n,o),c=o===s&&s!==i;if(c){let f=ee(Kc(o.name));if(f)throw Error(`${Kc(o.name)} ${f} — share the original, or tune a palette with a shorter name`);a.name=Kc(o.name)}let u=fk(Th(a));if(console.log(u),process.stdout.isTTY){let f=cx(u);if(f)console.log(`
743
+ ${k6(c).join(`
744
+ `)}`);let f=Gf(n,s.name),l=!f||!Zc(f);if(!e)return console.log(`
745
+ \`ttheme check --fix ${s.name}\` writes them${l?" as your tone of it":""}`),1;if(l){let d=jn(hr(n,r,!1).palettes,s.name);return za(n,Uu(zt(n),s.name,Dh(d,rn(ko(a))))),Dt(n,r,i),console.log(`
746
+ Saved as your tone of ${s.name} — R then s in \`ttheme edit ${s.name}\` puts its own colors back`),u.length===0?0:1}if(H(f,qh(ob(f,"utf8"),ko(a))),i.palettes.includes(s.name))Dt(n,r,i);return console.log(`
747
+ Wrote ${f}`),u.length===0?0:1}function Gf(t,e){let n=et(e);return n&&Vi(t,!1).some((r)=>r.id===n)?Bh(t,e):void 0}function ub(t){let e=$o(t);if(!e)return;try{let{background:n,foreground:r,cursor:i,selection:s,ansi:o}=zh(e);return{background:n,foreground:r,cursor:i,selection:s,ansi:o}}catch{return}}function Ux(t,e,n,r){return{code:(i)=>Kh(Wx(t,dn(Ln(e,r(i),n.palettes)))),toml:r,command:"ttheme add"}}function Wx(t,e){let n=Gf(t,e.name),r=n&&Zc(n)?Ln(e.name,ob(n,"utf8"),[e]).waiveReason:void 0,i=wf(t,e.name)??e.pictures,{pictures:s,...o}=Uh(e,e.name,r);return{...o,...i?{pictures:i}:{}}}async function E6(t,e,n){if(t===e)return e;let r=n;if(r===void 0)if(!la())r="tuned";else{let i=await km({message:`Share ${e.name} as…`,options:[{value:"tuned",label:"Your tone",hint:`named ${Vc(e.name)}`},{value:"original",label:"The original"}]});if(se(i))throw new we;r=i}return r==="original"?e:t}function Vc(t){return`${t}-tuned`}async function lb(t,e){let n=Y(),r=lt(n),i=Bx(hr(n,r),t,n),s=qa(i,zt(n)[i.name]),o=await E6(s,i,e),a=Wx(n,o),c=o===s&&s!==i;if(c){let f=re(Vc(o.name));if(f)throw Error(`${Vc(o.name)} ${f} — share the original, or tune a palette with a shorter name`);a.name=Vc(o.name)}let u=vk(Kh(a));if(console.log(u),process.stdout.isTTY){let f=Ex(u);if(f)console.log(`
747
748
  ${f.join(`
748
749
  `)}`);console.error(`
749
750
  Anyone can open the link${f?" or scan the code":""} to see ${a.name}, and ttheme add <link> installs it${c?`
750
- It carries your tone, named ${a.name} so it does not clash with ${o.name}`:""}`)}}import{spawn as n6,spawnSync as Px}from"node:child_process";import{existsSync as r6,readFileSync as Rx}from"node:fs";import{homedir as i6}from"node:os";import{join as Ix}from"node:path";function Ax(t,e,n,r=i6(),i=(s)=>{process.stdout.write(s)}){if(!e||Ft(t)||t.TMUX||Vt(t)!=="terminal-app")return;let[s="",o="-"]=(t.TTHEME_TERMINAL_SHOWN??"").split(" "),a=t.TTHEME_TTY,c=s?He(X(n),s,r):void 0,u=wl(No(n)).get(le(s))??[],f=u.find((B)=>B===`${j(s)}.${o}.png`)??u[0];if(!a||!c||o==="-"||!f||!r6(c.image))return;let l=Ix(No(n),f),d=["-l","JavaScript",bl(n),"tab",a,gn(s)],h=q(n).terminalBase??"Basic",m=tp(t,r),g=Rx(l),b,w=l,k=0,v,S=!1,x=!1,M,N=(B)=>{S=!0,n6("osascript",[...d,h],{stdio:"ignore"}).on("close",()=>{if(S=!1,x)return;i(B);let F=M;M=void 0,F?.()})},C=(B,F)=>{b??=Wt(new Uint8Array(Rx(c.image)));let gt=Ix(No(n),`${j(s)}.h${process.pid}-${++k}.png`);Pi(w,gt,_r(jr(b,B,c.opacity,ep(b.width,b.height,c,m)))),w=gt,N(F)},P=()=>{if(w!==l)Pi(w,l,g),w=l},_=(B)=>{clearTimeout(v),v=setTimeout(()=>{if(S)M=B;else B()},km)},K=()=>{clearTimeout(v),M=void 0};return{slots:[],paint(B){return _(B.name===s?()=>{P(),N("")}:()=>C(B.background,gr(B))),""},wear(B){return Px("osascript",[...d.slice(0,-1),gn(B.name),h],{encoding:"utf8"}).stdout?.trim()==="worn"?"":gr(B)},saved:async()=>new Map,restore(){return K(),x=!0,P(),Px("osascript",[...d,h],{stdio:"ignore"}),""},stop:K}}import{existsSync as qc,readdirSync as s6,readFileSync as Cf,rmSync as Nx,statSync as Hx}from"node:fs";import{homedir as o6}from"node:os";import{join as As}from"node:path";var a6=150,c6=260;function Ff(t){return t?.includes(`path = "${j("")}`)===!0}function u6(t){try{return q(t).terminals.includes("warp")}catch{return!1}}function Tx(t,e){let n=j(e);if(!qc(t))return;return s6(t).filter((i)=>i.startsWith(`${n}.`)&&/^[0-9a-f]{8}\.yaml$/.test(i.slice(n.length+1))).map((i)=>({file:i,at:Hx(As(t,i)).mtimeMs})).sort((i,s)=>s.at-i.at)[0]?.file??(qc(As(t,`${n}.yaml`))?`${n}.yaml`:void 0)}function l6(t,e){if(!e)return;let n;try{n=Cf(As(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 Lx(t,e,n,r=o6()){if(!e||Ft(t)||t.TMUX||Vt(t)!=="warp")return;let i=ai(r,n);if(!qc(i)||!u6(n))return;let s=as(r),o=yl(n),a=[],c=t.TTHEME_WARP_WEARS??Ge(q(n)),u=l6(s,c&&Tx(s,c)),f,l,d=(b)=>{let w=Cf(i,"utf8"),k=ci(w);if(k===b)return;if(Ff(b)&&!Ff(k)&&!qc(o))L(o,k??"");if(Sn(i,vl(w,b)),!Ff(b))Nx(o,{force:!0})},h=(b)=>{for(let w of a.splice(0))if(w===b)a.push(w);else Nx(As(s,w),{force:!0})},m=()=>{clearTimeout(f),clearTimeout(l)},g=(b,w,k)=>{m(),f=setTimeout(()=>{let v=w;if(!v)v=`${j(b.name)}.view-${process.pid}-${a.length+1}.yaml`,L(As(s,v),Va(b,k)),a.push(v);let S=v,x=Date.now()-Hx(As(s,S)).mtimeMs;l=setTimeout(()=>{d(sp(b.name,S)),h(S)},Math.max(0,c6-x))},a6)};return{slots:[],paint:(b)=>{if(b.name===c)g(b,Tx(s,b.name));else if(u)g(b,void 0,u);else g(b,qc(As(s,`${j(b.name)}.yaml`))?`${j(b.name)}.yaml`:void 0);return""},wear:(b,w)=>w.includes("warp")?"":void 0,saved:async()=>new Map([["theme",ci(Cf(i,"utf8"))??""]]),restore:(b)=>{m();let w=b.get("theme");if(w)d(w);else if(Ff(ci(Cf(i,"utf8"))))d(kl);return h(),""}}}function oa(t,e,n){return Ax(t,e,n)??Hy(t,e)??Lx(t,e,n)}function jf(t){_n(`
751
- ${t} palettes installed — open a new tab, or reload your terminal config`)}function d6(t,e){return t.map((n)=>{if(mo(n))return n;let r=et(n);if(r===void 0)return e===J?n:`${e}/${n}`;if(r!==e)throw Error(`${n} is not in ${e} — give its bare name, or leave --marketplace out`);return n})}async function Fx(t,e){let n=t.find((d)=>/^https?:\/\//i.test(d.trim())&&!mo(d));if(n)throw Error(`${n} is not a share link — one reads ${Oh}tt2:…`);let r=Y(),i=e?d6(t,(await Tp(r,e)).id):t,s=lt(r),o=new Map,a=[...new Set(i.map((d)=>{let h=mo(d);if(!h)return d;let m=mx(r,h,s);return o.set(m.name,m),m.name}))],c=q(r),u=a.filter((d)=>c.palettes.includes(d)),f=a.filter((d)=>!c.palettes.includes(d));if(f.length===0){qt(r,s,c),console.log(`Already installed: ${u.join(", ")}`);return}let l={...c,palettes:[...c.palettes,...f]};tn(r,s,c,l);for(let d of f)console.log(` + ${d}`);await Es(r,zt(r,s,!1).palettes.filter((d)=>f.includes(d.name)).map((d)=>{let h=o.get(d.name);return h?{...d,pictures:h.pictures}:d}),l.terminals),jf(l.palettes.length)}function Cx(t){let e=Y(),n=lt(e),r=q(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))};tn(e,n,r,o),Lo(e,n,r.terminals,i);for(let a of i)console.log(` - ${a}`);if(jf(o.palettes.length),s.length>0)return console.error(`ttheme remove: not installed: ${s.join(", ")}`),1;return 0}function jx(t){let e=Y(),n=lt(e),r=q(e);if(!r.palettes.includes(t))throw Error(`${t} is not installed — \`ttheme add ${t}\` first`);let{off:i,...s}=r,o=tn(e,n,r,{...s,startup:t},!0);console.log(Ux(t,r.terminals,o).join(`
752
- `))}function _x(){let t=Y();qt(t,lt(t),q(t))}function Gx(){let t=Y(),e=q(t),n=us(e);if(!n)throw Error("no palettes installed — `ttheme` picks some");if(!e.off){console.log(`Already on · ${n}`);return}let{off:r,...i}=e,s=tn(t,lt(t),e,i);console.log(Ux(n,i.terminals,s).join(`
753
- `))}function Bx(){let t=Y(),e=q(t);if(e.off){console.log("Already off");return}let n=tn(t,lt(t),e,{...e,off:!0}),r=us(e);console.log(`Off · new tabs open in the terminal's own colors${r?` — \`ttheme on\` wears ${r} again`:""}`);for(let i of St(e.terminals))if(n.get(i.id)?.restart)console.log(`${i.name} new tabs open on your own profile once ${i.name} restarts`)}function Ux(t,e,n){let r=St(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 St(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 h6(t,e){let n=new Map(e.palettes.map((r)=>[r.name,"marketplace"]));for(let r of Nu(t,e.palettes,!1))n.set(r.name,"mine");return n}function Wx(t,e=!1){let n=Y(),r=lt(n),i=new Set(q(n).palettes),s=h6(n,r),o=It(zt(n,r).palettes);if(t)zi(o);let a=Gi(t?Ok(o,t):o),c=(d)=>s.get(d)??"kept";if(e){let d=a.map((h)=>({name:h.name,marketplace:et(h.name)??J,...h.catalog?{catalog:h.catalog}:{},installed:i.has(h.name),source:c(h.name)}));console.log(JSON.stringify(d,null,2));return}let u=Math.max(...a.map((d)=>d.name.length),0),f={marketplace:"",mine:" · yours",kept:" · in no marketplace you added"},l=Kt(n);for(let d of a){let h=l[d.name]?" · tuned":"";console.log(` ${i.has(d.name)?"●":"○"} ${d.name.padEnd(u)} ${ne(d)}${f[c(d.name)]}${h}`)}if(process.stdout.isTTY){let d=t?`${a.length} of ${o.length}`:`${o.length}`;console.log(`
754
- ${d} palettes — ${a.filter((h)=>i.has(h.name)).length} installed`)}}function m6(t,e,n){let r=(s)=>{try{return li(t,s)}catch{return}},i=e.find((s)=>s===n||st(s)===n||r(s)===n);if(!i)throw Error(`no marketplace named ${n} — \`ttheme marketplace\` lists them`);return i}async function Kx(t=[]){let e=Y(),n=lo(e),r=t.map((m)=>m6(e,n,m)),i=await Mv(),s=!1;if(i.latest)try{return Ev(i.latest,t)}catch(m){s=!0,console.log(` ttheme could not update to ${i.latest}: ${m.message}`)}else console.log(i.note);let o=(r.length>0?r:n).filter((m)=>m!==J);if(r.length===0&&o.length===0)console.log("No marketplaces to update — `ttheme marketplace add <owner>/<repo>` adds one");let a=(m,g)=>`${Lv(m,g)} — kept the copy from the last update`;for(let m of o.filter(Rt))try{console.log(` ${eS(e,m)}`)}catch(g){console.log(` ${a(m,g)}`)}let c=o.filter((m)=>!Rt(m)),u=new Set(c),f=[],l=ui(),d=()=>l.set(`Updating ${[...u].map(st).join(", ")}${c.length>1?` · ${c.length-u.size}/${c.length}`:""}`);if(d(),await Promise.all(c.map(async(m)=>{let g=await Op(e,m);if("refreshed"in g)f.push(g.refreshed);if(u.delete(m),u.size>0)d();else l.done();l.say(` ${"refreshed"in g?Pp(g.refreshed):a(m,g.failure)}`)})),l.done(),!f6(ln(e)))return s?1:0;for(let m of ms(e,f))console.log(` ${m}`);let h=Ip(e);if(h)console.log(h);return s?1:0}async function zx(t,e){let n=lt(t,!1),r=new Map(bo(t,n).filter((a)=>e.includes(a.name)).map((a)=>[a.name,a]));if(r.size===0)return;let i=Jr(t);go(t,i.map((a)=>r.get(a.name)??a));let s=q(t);qt(t,n,s);let o=new Map(i.map((a)=>[a.name,a.pictures]));await Es(t,zt(t,n,!1).palettes.filter((a)=>r.has(a.name)).map((a)=>LE(a,o.get(a.name))),s.terminals)}async function nb(t,e,n,r=!1){let i=process.env.TTHEME_SORT==="catalog"?t.palettes:Gi(t.palettes);zi(i);let s=process.stdout.isTTY===!0,o=oa(process.env,s,Y()),a=o?await o.saved():new Map,c=new Up({entries:i,scope:n,installed:e,required:r,color:!Ft(),fx:Kl(process.env.TTHEME_FX),onFocus:o?(f)=>process.stdout.write(o.paint(f)):void 0}),u=await c.prompt();if(o)process.stdout.write(o.restore(a));if(u==="cancel")return;return t.palettes.filter((f)=>c.picked.has(f.name)).map((f)=>f.name)}function rb(t,e,n,r){let i=n===J?void 0:cc(t,n),s;try{s=i?.id??li(t,n)}catch{s=wt(n)?zr(n):st(n)}return{source:n,id:s,...i?.info.description?{description:i.info.description}:{},shown:st(n),entries:n===J?Bo(t,n):i?.entries??[],auto:qr(n,e.updates),status:Fp(t,n,r)}}function ib(t){return bo(t,lt(t,!1)).map((e)=>e.name)}function p6(t,e,n,r,i){return{refresh:async(s)=>{if(Rt(s)){let a=rb(t,e,s,wr());return{marketplace:a,refreshed:{source:s,id:a.id,count:It(a.entries).length,change:{added:[],changed:[],gone:[]}},updates:ib(t)}}let o=await xp(t,s,yp);return{marketplace:rb(t,e,s,wr()),refreshed:o,updates:ib(t)}},fetch:async(s)=>{if(Rt(s)){let a=Je(s),c=we(a);return{source:s,id:c,...a.description?{description:a.description}:{},shown:st(s),entries:Tn(s,c,Bo(t,J),de(!1)),auto:!1,status:"read in place"}}let o=await ac(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:st(s),entries:o.entries,auto:qr(s,{}),status:"not added yet"}},index:()=>Tl(r),apply:i}}function qx(...t){for(let e of ms(...t))_n(e)}function g6(t,e,n){let r=[];for(let i of t.adds){let s=i.source!==J&&(t.auto[i.source]??i.auto);r.push(`Added ${i.id} · ${i.shown} — ${jt(It(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} · ${st(i)}`);let o=n.filter((a)=>(et(a)??J)===s);if(o.length>0)r.push(Lp(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 b6(t,e,n,r){let i=q(t),s=n.adds.length+n.removes.length+Object.keys(n.auto).length>0;for(let m of n.adds){let g=r.get(m.source);if(g)Go(t,g)}for(let m of n.removes)Hp(t,m);let o=[...Jt(i.marketplaces).filter((m)=>!n.removes.includes(m)),...n.adds.map((m)=>m.source)],a=fc(i,o,{...i.updates,...n.auto});if(s)Qe(t,a);let c=lt(t,!1),u=zt(t,c,!1).palettes.filter((m)=>n.picked.has(m.name)).map((m)=>m.name),f=i.palettes.filter((m)=>!u.includes(m)),l=u.filter((m)=>!i.palettes.includes(m)),d=n.renew.filter((m)=>u.includes(m));if(!s&&l.length===0&&f.length===0&&d.length===0){qx(t,n.refreshed),_n("Nothing changed");return}let h={...a,palettes:u};tn(t,c,i,h),Lo(t,c,i.terminals,f);for(let m of g6(n,e,u))_n(m);for(let m of l)_n(` + ${m}`);for(let m of f)_n(` - ${m}`);for(let m of ms(t,n.refreshed))_n(m);if(await Es(t,zt(t,c,!1).palettes.filter((m)=>l.includes(m.name)),h.terminals),d.length>0){await zx(t,d);for(let m of d)_n(` ↑ ${m}`)}if(l.length>0||f.length>0)jf(h.palettes.length)}async function Dx(){let t=Vk(process.env),e=Y(),n=q(e),r=Jr(e),i=wr(),s=jo(),o=Jt(n.marketplaces).map((k)=>rb(e,n,k,i)),a=new Set(o.flatMap((k)=>k.entries.map((v)=>v.name))),c=r.filter((k)=>n.palettes.includes(k.name)&&!a.has(k.name));zi([...o.flatMap((k)=>k.entries),...c]);let u=new Map,f=new AbortController,l=process.stdout.isTTY===!0,d=oa(process.env,l,e),h=d&&!t?await d.saved():new Map,m=Ge(n);if(t)process.stdout.write("\x1B[?2026h");let g=new Kp({marketplaces:o,kept:c,installed:n.palettes,updates:ib(e),tuned:Object.keys(Kt(e)),...m?{startup:m}:{},...t?{hub:t}:{},due:s?Sp(e,n):[],io:p6(e,n,u,f.signal,(k,v)=>dv({say:v.say,set:v.status},()=>b6(e,o,k,u))),...process.env.TTHEME_SORT==="catalog"?{}:{order:Gi},color:!Ft(),lookups:process.env.TTHEME_MARKETPLACE_LOOKUP!=="off",fx:Kl(process.env.TTHEME_FX),owns:l&&!t,...d?{onFocus:(k)=>process.stdout.write(d.paint(k))}:{}});try{await g.run()}finally{if(d?.stop?.(),d&&(!t||g.next()===void 0))process.stdout.write(d.restore(h));f.abort()}await g.idle();let b=g.result(),w=g.next();if(t&&w!==void 0)return qx(e,b.refreshed),w;if(l&&t)process.stdout.write("\x1B[?1049l\x1B[?25h");for(let k of b.refreshed){let v=Rp(k);if(v)console.log(v)}if(g.applied()){for(let v of g.lines())console.log(v);let k=g.failure();if(k)throw k}else{for(let k of ms(e,b.refreshed))console.log(k);console.log("Nothing changed")}return t?Uu:0}import{rmSync as Jx}from"node:fs";import{basename as w6,join as Dc}from"node:path";var Yx=Dc(import.meta.dirname,".."),$6=Dc(Yx,"themes"),sb=Dc(Yx,"dist"),_f=ie.map((t)=>br[t].emitter),k6=[Om,Tm],uX=_f.map((t)=>t.id);async function Gf({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?_f.filter((s)=>t.includes(s.id)):_f,n=r$($6),r=Db(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===_f.length)Jx(sb,{recursive:!0,force:!0});else for(let s of e)Jx(Dc(sb,s.id),{recursive:!0,force:!0});let i=0;for(let s of[...e,...k6]){let o=n.flatMap((u)=>s.emit?.(u)??[]),a=s.emitShared?.(n)??[];for(let u of[...o,...a])await Bun.write(Dc(sb,u.path),u.content),i++;let c=o.length>0?`${n.length} themes${s.limits?` (${s.limits})`:""}`:a.length>0?a.map((u)=>w6(u.path)).join(" "):`no files (${s.limits??"nothing to write"})`;console.log(` ${s.id.padEnd(16)} ${c}`)}console.log(`
755
- ${n.length} themes (${i$(n).length} in the new-tab rotation) -> ${i} files in dist/`)}import{existsSync as S6,readFileSync as t2}from"node:fs";import{availableParallelism as y6,homedir as Vx}from"node:os";var v6=4;async function Bf(t,e,n=Vx()){let r=Ht(X(t)),i=ei(t),s=new Map($e(t).palettes.map((l)=>[l.name,eo(l)])),o=Object.entries(r.palettes).flatMap(([l,d])=>{let h=s.get(l);return h?d.pictures.filter((m)=>no(m)||(m.blur??0)!==i).map((m)=>({name:l,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=ls(q(t).terminals),c=new Rg(Math.min(v6,y6()-1)),u=await c.map(o.map(({name:l,key:d,paint:h})=>({job:"redraw",home:t,user:n,name:l,key:d,paint:h,blur:i,aligns:a})));c.close();let f=[];return u.forEach((l,d)=>{let{name:h,key:m}=o[d];if(l instanceof Error||l===null){e(` ▢ ${h} ${m} — ${l instanceof Error?l.message:"no original to draw it from"}, left as it was`);return}f.push({name:h,picture:l})}),hh(t,f),Be(t,n),f.length}async function Zx(t,e,n,r,i=Vx()){let s=Ht(X(t)).palettes[e],o=s?.pictures.find((f)=>f.key===(r??s.active));if(!s||!o)throw Error(`${e} has no picture ${r??"shown"}`);if(De(o)===n)return{key:o.key,changed:!1};let a=$e(t).palettes.find((f)=>f.name===e);if(!a)throw Error(`no palette called ${e}`);let c=ls(q(t).terminals),u=await hf(t,e,o.key,eo(a),ei(t),c,i,n);if(!u)throw Error(`${e} ${o.key} has no original to draw it from`);return hh(t,[{name:e,picture:u}]),Be(t,i),{key:o.key,changed:!0}}function Xx(t,e,n){let r=Ht(X(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=$e(t).palettes.find((a)=>a.name===e);if(!s)throw Error(`no palette called ${e}`);let o=De(i)==="original"?"tone":"original";if(!jE(t,e,i.key,eo(s),ei(t),o))throw Error(`${e} ${i.key} has no original to draw it from`);return{key:i.key,coloring:o}}async function Qx(){return await Bf(Y(),(t)=>process.stderr.write(`${t}
756
- `)),0}async function e2(t,e,n){let r=Y();if(Hn($e(r).palettes,t),e==="show"){if(!n)throw Error("image show needs the picture to show");let{at:i,of:s}=ro(r,t,n);return Be(r),process.stderr.write(`Background · ${t} ${i}/${s} ${n}
757
- `),0}if(e==="drop"){let{key:i,left:s}=vu(r,t,n);return Be(r),process.stderr.write(`Background · ${t} removed ${i} · ${s} left
758
- `),0}if(e==="tone"||e==="original"){let i=await Zx(r,t,e,n);return process.stderr.write(`Background · ${t} ${i.key} ${e==="tone"?"tinted":"in its own colors"}
759
- `),0}if(e==="prepare"){let{key:i,coloring:s}=Xx(r,t,n);return process.stderr.write(`Background · ${t} ${i} ready in ${s==="tone"?"its tone":"its own colors"}
760
- `),0}if(e==="tuned")return Be(r),0;throw Error(`unknown image action ${e} — show, drop, tone, original, prepare or tuned`)}function n2(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 E6(t,e,n){let r=n2(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 r2(t,e,n,r){let i=Wt(new Uint8Array(t2(t)));return L(e,qe(Qw(i,n2(n,r)))),0}function i2(t,e,n,r,i,s,o){let a=Number(r);if(!ge(n)||!Number.isFinite(a))throw Error("flatten needs a #rrggbb background and an opacity from 0 to 1");let c=Wt(new Uint8Array(t2(t))),u=i?E6(c,i,s??""):void 0,f=_r(jr(c,n,Math.max(0,Math.min(1,a)),u));if(o&&S6(o))Pi(o,e,f);else L(e,f);return 0}import{execFileSync as M6}from"node:child_process";import{readFileSync as x6}from"node:fs";import{arch as O6,platform as Uf,release as ob}from"node:os";var P6={ghostty:"ghostty",iterm2:"iTerm.app",wezterm:"WezTerm","terminal-app":"Apple_Terminal",warp:"WarpTerminal"};function R6(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=P6[t];return n!==void 0&&e.TERM_PROGRAM===n?e.TERM_PROGRAM_VERSION:void 0}function I6(t){let e=Vt(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 (${$m(t)})`:`${e} ${R6(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 s2(t,e){try{return M6(t,e,{encoding:"utf8",timeout:2000,stdio:["ignore","pipe","ignore"]}).trim()}catch{return}}function A6(){let t=O6();if(Uf()==="darwin")return`macOS ${s2("sw_vers",["-productVersion"])??`(Darwin ${ob()})`} · ${t}`;if(Uf()==="linux"){let e="";try{e=x6("/etc/os-release","utf8")}catch{}return`${/^PRETTY_NAME="?([^"\n]*)"?$/m.exec(e)?.[1]??"Linux"} · linux ${ob()} · ${t}`}return`${Uf()==="win32"?"Windows":Uf()} ${ob()} · ${t}`}function N6(t){if(t.TTHEME_ZSH)return`zsh ${t.TTHEME_ZSH}`;return(t.SHELL?s2(t.SHELL,["--version"])?.split(`
761
- `)[0]:void 0)??t.SHELL??"unknown"}function T6(t){try{let{terminals:e}=q(t);return e.length>0?e.join(", "):"none"}catch{return"installed.json missing or unreadable"}}function H6(t){let e=cl.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 o2(){let t=process.env,n=[["ttheme",dt.version],["OS",A6()],["Shell",N6(t)],["Terminal",I6(t)],["Wired",T6(Y())],["Settings",H6(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 F6,spawnSync as C6}from"node:child_process";import{chmodSync as j6,copyFileSync as _6,existsSync as xe,mkdirSync as b2,readdirSync as $2,readFileSync as $i,renameSync as G6,rmSync as Yc}from"node:fs";import{homedir as B6}from"node:os";import{dirname as aa,join as rt}from"node:path";import{existsSync as a2}from"node:fs";import{basename as L6,join as Jc}from"node:path";var c2=["zsh","bash","fish"];function Wf(t){let e=L6(t??"").replace(/^-/,"");return c2.includes(e)?e:void 0}function cb(t,e){for(let n=e,r=0;n>1&&r<12;r++){let[i,...s]=t("ps",["-o","ppid=,comm=","-p",String(n)])?.trim().split(/\s+/)??[],o=Wf(s.join(" "));if(o)return o;n=Number(i)}return}function u2(t,e){let n=new Set(["zsh"]);for(let r of[Wf(t.env.SHELL),cb(t.run,e)])if(r)n.add(r);return c2.filter((r)=>n.has(r))}var ab="ttheme-zdotdir:";function Kf(t,e){if(t.env.ZDOTDIR)return t.env.ZDOTDIR;let n=t.run("zsh",["-c",`print -rn -- "${ab}\${ZDOTDIR:-$HOME}"`])??"",r=n.lastIndexOf(ab);return r>=0&&n.slice(r+ab.length)||e}function l2(t){return t.run("zsh",["-fc","print ok"])==="ok"}var f2=[".bash_profile",".bash_login",".profile"];function d2(t,e){let n=Jc(t,".bashrc"),r=f2.map((s)=>Jc(t,s)).find((s)=>a2(s)),i=[...a2(n)?[n]:[],...r?[r]:[]];if(e==="darwin"&&!r)i.push(Jc(t,".bash_profile"));return i.length>0?i:[n]}function h2(t){return[".bashrc",...f2].map((e)=>Jc(t,e))}var m2=`zsh -c 'source ${al} && ttheme "$@"' ttheme`;function p2(){return`# ${ve}
762
- ttheme() { ${m2} "$@"; }`}function zf(t){return Jc(t,"fish","functions","ttheme.fish")}function g2(){return[`# ${ve}`,"function ttheme --description 'Run ttheme through zsh'",` ${m2} $argv`,"end",""].join(`
763
- `)}function qf(t){return t.startsWith(`# ${ve}
764
- `)}function U6(t,e,n){for(let r of $2(e))t.push({from:rt(e,r),to:rt(n,r)})}function db(t){return Dr($i(rt(t,"dist","manifest.json"),"utf8"))}function Jf(t,e){let n=rt(e.configHome,"ttheme"),r=[{from:rt(e.root,"bin","ttheme.js"),to:rt(n,"ttheme.js")},{from:rt(e.root,"bin","ttheme.js.map"),to:rt(n,"ttheme.js.map")},{from:rt(e.root,"bin","package.json"),to:rt(n,"package.json")},{from:rt(e.root,"shell","ttheme.zsh"),to:rt(n,"ttheme.zsh")},{from:rt(e.root,"shell","preview.zsh"),to:rt(n,"preview.zsh")},{from:rt(e.root,"shell","launch-tab.zsh"),to:rt(n,"launch-tab.zsh"),executable:!0}];U6(r,rt(e.root,"shell","adapters"),rt(n,"adapters"));let i=e.shells??["zsh"],s=[{file:rt(e.zdotdir,".zshrc"),block:Wy(),about:"source ttheme.zsh"},...i.includes("bash")?d2(e.home,e.platform??process.platform).map((g)=>({file:g,block:p2(),about:"the ttheme command, run through zsh"})):[]],o=zf(e.configHome),a=!xe(o)||qf($i(o,"utf8")),c=i.includes("fish")&&a?[{file:o,content:g2(),about:"the ttheme command, run through zsh"}]:[],u=rt(n,"config.zsh"),f=zy(xe(u)?$i(u,"utf8"):""),l={file:u,content:t.warpFast===void 0?f:ll(f,"TTHEME_WARP_FAST",t.warpFast?"on":"off")},d={terminals:t.terminals,palettes:t.palettes,...Object.fromEntries(St(t.terminals).flatMap((g)=>Object.entries(g.installs?.(e)??{}).filter(([,b])=>b!==void 0))),...t.off?{off:!0}:{}},h=[...Rl(e.configHome,d,e.home),...i.includes("fish")&&!a?[`${ht(o,e.home)} is a function of your own — ttheme left it, so fish has no ttheme command`]:[],...i.some((g)=>g!=="zsh")?[`${i.filter((g)=>g!=="zsh").join(" and ")} run ttheme through zsh — a pin taking effect on cd, the picture following the tab in front and the repaint after a program resets the colors stay with zsh tabs`]:[]],m=e.stateDir?[rt(e.stateDir,"ghostty",".blind")]:[];return{home:e.home,copies:r,edits:s,writes:c,settings:l,forget:m,manifest:db(e.root),installed:d,notes:h}}function k2(t){try{return q(t)}catch{return}}var Df="ttheme-market.toml",W6="https://www.schemastore.org/ttheme-market.json";function K6(t,e){let n=rt(t,"ttheme"),r=rt(n,"market");for(let[c,u]of[[r,Ji(t)],[rt(n,"markets"),fo(t)],[rt(n,"catalog.json"),fn(t)]])if(xe(c)&&!xe(u))G6(c,u);Yc(rt(e,"markets.json"),{force:!0});let i=fo(t);for(let c of xe(i)?$2(i).filter((u)=>u.endsWith(".json")):[])try{let u=JSON.parse($i(rt(i,c),"utf8"));if(!u||typeof u!=="object"||!("files"in u))continue;let f=u.files;if(f&&typeof f==="object"&&Df in f&&!(ot in f)){let{[Df]:l,...d}=f;L(rt(i,c),`${JSON.stringify({...u,files:{...d,[ot]:l}})}
765
- `)}}catch{}let s=ln(t),o;try{o=JSON.parse($i(s,"utf8"))}catch{return[]}if(!o||typeof o!=="object")return[];if("markets"in o&&!("marketplaces"in o)){let{markets:c,...u}=o,f=(Array.isArray(c)?c:[]).map((l)=>typeof l==="string"&&l.startsWith(`${r}/`)?rt(Ji(t),l.slice(r.length+1)):l);o={...u,marketplaces:f},L(s,`${JSON.stringify(o,null,2)}
766
- `)}let a=o&&typeof o==="object"&&"marketplaces"in o?o.marketplaces:void 0;return(Array.isArray(a)?a:[]).flatMap((c)=>{if(typeof c!=="string"||!Rt(c))return[];let u=rt(c,Df),f=rt(c,ot);if(!xe(u)||xe(f))return[];return L(f,$i(u,"utf8").replace(W6,vh)),Yc(u),[`Renamed ${Df} to ${ot} in ${st(c)}`]})}function y2(t,e){try{return zt(t,lt(t,!1,e),!1).palettes}catch{return[]}}function z6(t,e){let n=db(e.root),r=Jt(t.marketplaces).includes(J)?n.palettes:[],i=new Set(r.map((o)=>o.name)),s=y2(e.configHome,n).filter((o)=>!i.has(o.name)&&(et(o.name)!==void 0||t.palettes.includes(o.name)));return{...n,palettes:[...r,...s]}}function v2(t,e){let n=us(t);return n&&e.includes(n)?n:void 0}function q6(t,e,n){let r=Jf(e,n),i=v2(t,e.palettes),s=new Set(["terminals","palettes","off","startup",...ie.flatMap((a)=>Object.keys(br[a].installs?.(n)??{}))]),o=Object.fromEntries(Object.entries(t).filter(([a])=>!s.has(a)));return{...r,installed:{...o,...r.installed,...i?{startup:i}:{}}}}function D6(t,e){let n=Jf({terminals:t.terminals,palettes:t.palettes,off:t.off},e),r=new Set([...n.manifest.palettes,...y2(e.configHome,n.manifest)].map((f)=>f.name)),i=t.palettes.filter((f)=>r.has(f)),s=t.palettes.filter((f)=>!r.has(f)),{startup:o,...a}=t,c={...a,palettes:i,...o&&i.includes(o)?{startup:o}:{}},u=s.length>0?[`Dropped ${s.join(", ")} — no longer in any marketplace`,...n.notes]:n.notes;return{...n,installed:c,notes:u}}function J6(t){try{return F6(process.execPath,[rt(t,"ttheme","ttheme.js"),"--version"],{encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim()||void 0}catch{return}}function S2(t){let e=Ge(t);return[St(t.terminals).map((n)=>n.name).join(", "),`${t.palettes.length} palettes`,e?`default ${e}`:"no default — ttheme is off"].join(" · ")}function ub(t,e=Xe()){for(let o of t.copies)if(b2(aa(o.to),{recursive:!0}),Yc(o.to,{force:!0}),Yc(`${o.to}.zwc`,{force:!0}),_6(o.from,o.to),o.executable)j6(o.to,493);L(t.settings.file,t.settings.content);for(let o of t.forget)Yc(o,{force:!0});let n=aa(aa(t.settings.file)),r=k2(n),i=Object.fromEntries(St(t.installed.terminals).flatMap((o)=>{let a=o.defaults?.key,c=a?r?.[a]:void 0;return a&&c?[[a,c]]:[]})),s=rc(n,{...t.installed,...i},e,t.home);if(Jt(s.marketplaces).includes(J))yk(n,t.manifest);Qe(n,s),qt(n,lt(n),s,t.home,e);for(let o of t.edits){b2(aa(o.file),{recursive:!0});let a=xe(o.file)?$i(o.file,"utf8"):"";Sn(o.file,ti(a,o.block))}for(let o of t.writes)L(o.file,o.content);return fs(n,s,!0,e,t.home)}function Vc(t){if(re(t))throw Zr("Nothing changed"),new pe;return t}function lb(t,e){return ie.filter((n)=>br[n].offered(t,e))}async function Y6(t,e,n,r){return Vc(await Sy({message:"Wire which terminals?",options:lb(n,r).map((i)=>({value:i,label:br[i].name,hint:i===t?"detected":void 0})),initialValues:e,required:!0}))}async function V6(t){return Vc(await _e({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:Oo(t,"TTHEME_WARP_FAST")!=="off"}))}function fb(t){let e=[...t.copies.filter((n)=>!xe(n.to)).map((n)=>n.to),...xe(t.settings.file)?[]:[t.settings.file],...t.edits.filter((n)=>!$i(n.file,"utf8").includes("# ttheme begin")).map((n)=>n.file),...t.writes.filter((n)=>!xe(n.file)).map((n)=>n.file)];if(e.length>0)throw Error(`init left gaps:
751
+ It carries your tone, named ${a.name} so it does not clash with ${o.name}`:""}`)}}import{spawn as M6,spawnSync as Kx}from"node:child_process";import{existsSync as x6,readFileSync as zx}from"node:fs";import{homedir as O6}from"node:os";import{join as qx}from"node:path";function Dx(t,e,n,r=O6(),i=(s)=>{process.stdout.write(s)}){if(!e||Ct(t)||t.TMUX||Zt(t)!=="terminal-app")return;let[s="",o="-"]=(t.TTHEME_TERMINAL_SHOWN??"").split(" "),a=t.TTHEME_TTY,c=s?Fe(X(n),s,r):void 0,u=xl(Co(n)).get(he(s))??[],f=u.find((G)=>G===`${_(s)}.${o}.png`)??u[0];if(!a||!c||o==="-"||!f||!x6(c.image))return;let l=qx(Co(n),f),d=["-l","JavaScript",Ml(n),"tab",a,$n(s)],h=q(n).terminalBase??"Basic",m=fp(t,r),p=zx(l),b,$=l,k=0,v,S=!1,x=!1,M,N=(G)=>{S=!0,M6("osascript",[...d,h],{stdio:"ignore"}).on("close",()=>{if(S=!1,x)return;i(G);let L=M;M=void 0,L?.()})},C=(G,L)=>{b??=Kt(new Uint8Array(zx(c.image)));let gt=qx(Co(n),`${_(s)}.h${process.pid}-${++k}.png`);Ti($,gt,Wr(Gr(b,G,c.opacity,dp(b.width,b.height,c,m)))),$=gt,N(L)},I=()=>{if($!==l)Ti($,l,p),$=l},j=(G)=>{clearTimeout(v),v=setTimeout(()=>{if(S)M=G;else G()},Am)},U=()=>{clearTimeout(v),M=void 0};return{slots:[],paint(G){return j(G.name===s?()=>{I(),N("")}:()=>C(G.background,yr(G))),""},wear(G){return Kx("osascript",[...d.slice(0,-1),$n(G.name),h],{encoding:"utf8"}).stdout?.trim()==="worn"?"":yr(G)},saved:async()=>new Map,restore(){return U(),x=!0,I(),Kx("osascript",[...d,h],{stdio:"ignore"}),""},stop:U}}import{existsSync as Xc,readdirSync as P6,readFileSync as Wf,rmSync as Jx,statSync as Vx}from"node:fs";import{homedir as I6}from"node:os";import{join as Hs}from"node:path";var R6=150,A6=260;function Uf(t){return t?.includes(`path = "${_("")}`)===!0}function N6(t){try{return q(t).terminals.includes("warp")}catch{return!1}}function Yx(t,e){let n=_(e);if(!Xc(t))return;return P6(t).filter((i)=>i.startsWith(`${n}.`)&&/^[0-9a-f]{8}\.yaml$/.test(i.slice(n.length+1))).map((i)=>({file:i,at:Vx(Hs(t,i)).mtimeMs})).sort((i,s)=>s.at-i.at)[0]?.file??(Xc(Hs(t,`${n}.yaml`))?`${n}.yaml`:void 0)}function T6(t,e){if(!e)return;let n;try{n=Wf(Hs(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 Zx(t,e,n,r=I6()){if(!e||Ct(t)||t.TMUX||Zt(t)!=="warp")return;let i=di(r,n);if(!Xc(i)||!N6(n))return;let s=cs(r),o=Il(n),a=[],c=t.TTHEME_WARP_WEARS??Ge(q(n)),u=T6(s,c&&Yx(s,c)),f,l,d=(b)=>{let $=Wf(i,"utf8"),k=hi($);if(k===b)return;if(Uf(b)&&!Uf(k)&&!Xc(o))H(o,k??"");if(On(i,Rl($,b)),!Uf(b))Jx(o,{force:!0})},h=(b)=>{for(let $ of a.splice(0))if($===b)a.push($);else Jx(Hs(s,$),{force:!0})},m=()=>{clearTimeout(f),clearTimeout(l)},p=(b,$,k)=>{m(),f=setTimeout(()=>{let v=$;if(!v)v=`${_(b.name)}.view-${process.pid}-${a.length+1}.yaml`,H(Hs(s,v),nc(b,k)),a.push(v);let S=v,x=Date.now()-Vx(Hs(s,S)).mtimeMs;l=setTimeout(()=>{d(gp(b.name,S)),h(S)},Math.max(0,A6-x))},R6)};return{slots:[],paint:(b)=>{if(b.name===c)p(b,Yx(s,b.name));else if(u)p(b,void 0,u);else p(b,Xc(Hs(s,`${_(b.name)}.yaml`))?`${_(b.name)}.yaml`:void 0);return""},wear:(b,$)=>$.includes("warp")?"":void 0,saved:async()=>new Map([["theme",hi(Wf(i,"utf8"))??""]]),restore:(b)=>{m();let $=b.get("theme");if($)d($);else if(Uf(hi(Wf(i,"utf8"))))d(Pl);return h(),""}}}function fa(t,e,n){return Dx(t,e,n)??zy(t,e)??Zx(t,e,n)}function Kf(t){Wn(`
752
+ ${t} palettes installed — open a new tab, or reload your terminal config`)}function F6(t,e){return t.map((n)=>{if($o(n))return n;let r=et(n);if(r===void 0)return e===J?n:`${e}/${n}`;if(r!==e)throw Error(`${n} is not in ${e} — give its bare name, or leave --marketplace out`);return n})}async function Xx(t,e){let n=t.find((d)=>/^https?:\/\//i.test(d.trim())&&!$o(d));if(n)throw Error(`${n} is not a share link — one reads ${jh}tt2:…`);let r=Y(),i=e?F6(t,(await Kp(r,e)).id):t,s=lt(r),o=new Map,a=[...new Set(i.map((d)=>{let h=$o(d);if(!h)return d;let m=Rx(r,h,s);return o.set(m.name,m),m.name}))],c=q(r),u=a.filter((d)=>c.palettes.includes(d)),f=a.filter((d)=>!c.palettes.includes(d));if(f.length===0){Dt(r,s,c),console.log(`Already installed: ${u.join(", ")}`);return}let l={...c,palettes:[...c.palettes,...f]};en(r,s,c,l);for(let d of f)console.log(` + ${d}`);await Os(r,qt(r,s,!1).palettes.filter((d)=>f.includes(d.name)).map((d)=>{let h=o.get(d.name);return h?{...d,pictures:h.pictures}:d}),l.terminals),Kf(l.palettes.length)}function Qx(t){let e=Y(),n=lt(e),r=q(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))};en(e,n,r,o),Bo(e,n,r.terminals,i);for(let a of i)console.log(` - ${a}`);if(Kf(o.palettes.length),s.length>0)return console.error(`ttheme remove: not installed: ${s.join(", ")}`),1;return 0}function t2(t){let e=Y(),n=lt(e),r=q(e);if(!r.palettes.includes(t))throw Error(`${t} is not installed — \`ttheme add ${t}\` first`);let{off:i,...s}=r,o=en(e,n,r,{...s,startup:t},!0);console.log(i2(t,r.terminals,o).join(`
753
+ `))}function e2(){let t=Y();Dt(t,lt(t),q(t))}function n2(){let t=Y(),e=q(t),n=ls(e);if(!n)throw Error("no palettes installed — `ttheme` picks some");if(!e.off){console.log(`Already on · ${n}`);return}let{off:r,...i}=e,s=en(t,lt(t),e,i);console.log(i2(n,i.terminals,s).join(`
754
+ `))}function r2(){let t=Y(),e=q(t);if(e.off){console.log("Already off");return}let n=en(t,lt(t),e,{...e,off:!0}),r=ls(e);console.log(`Off · new tabs open in the terminal's own colors${r?` — \`ttheme on\` wears ${r} again`:""}`);for(let i of St(e.terminals))if(n.get(i.id)?.restart)console.log(`${i.name} new tabs open on your own profile once ${i.name} restarts`)}function i2(t,e,n){let r=St(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 St(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 L6(t,e){let n=new Map(e.palettes.map((r)=>[r.name,"marketplace"]));for(let r of Bu(t,e.palettes,!1))n.set(r.name,"mine");return n}function s2(t,e=!1){let n=Y(),r=lt(n),i=new Set(q(n).palettes),s=L6(n,r),o=At(qt(n,r).palettes);if(t)qi(o);let a=Gi(t?jk(o,t):o),c=(d)=>s.get(d)??"kept";if(e){let d=a.map((h)=>({name:h.name,marketplace:et(h.name)??J,...h.catalog?{catalog:h.catalog}:{},installed:i.has(h.name),source:c(h.name)}));console.log(JSON.stringify(d,null,2));return}let u=Math.max(...a.map((d)=>d.name.length),0),f={marketplace:"",mine:" · yours",kept:" · in no marketplace you added"},l=zt(n);for(let d of a){let h=l[d.name]?" · tuned":"";console.log(` ${i.has(d.name)?"●":"○"} ${d.name.padEnd(u)} ${ie(d)}${f[c(d.name)]}${h}`)}if(process.stdout.isTTY){let d=t?`${a.length} of ${o.length}`:`${o.length}`;console.log(`
755
+ ${d} palettes — ${a.filter((h)=>i.has(h.name)).length} installed`)}}function C6(t,e,n){let r=(s)=>{try{return pi(t,s)}catch{return}},i=e.find((s)=>s===n||st(s)===n||r(s)===n);if(!i)throw Error(`no marketplace named ${n} — \`ttheme marketplace\` lists them`);return i}async function o2(t=[]){let e=Y(),n=go(e),r=t.map((m)=>C6(e,n,m)),i=await Lv(),s=!1;if(i.latest)try{return Fv(i.latest,t)}catch(m){s=!0,console.log(` ttheme could not update to ${i.latest}: ${m.message}`)}else console.log(i.note);let o=(r.length>0?r:n).filter((m)=>m!==J);if(r.length===0&&o.length===0)console.log("No marketplaces to update — `ttheme marketplace add <owner>/<repo>` adds one");let a=(m,p)=>`${qv(m,p)} — kept the copy from the last update`;for(let m of o.filter(Rt))try{console.log(` ${dS(e,m)}`)}catch(p){console.log(` ${a(m,p)}`)}let c=o.filter((m)=>!Rt(m)),u=new Set(c),f=[],l=mi(),d=()=>l.set(`Updating ${[...u].map(st).join(", ")}${c.length>1?` · ${c.length-u.size}/${c.length}`:""}`);if(d(),await Promise.all(c.map(async(m)=>{let p=await jp(e,m);if("refreshed"in p)f.push(p.refreshed);if(u.delete(m),u.size>0)d();else l.done();l.say(` ${"refreshed"in p?_p(p.refreshed):a(m,p.failure)}`)})),l.done(),!H6(hn(e)))return s?1:0;for(let m of ps(e,f))console.log(` ${m}`);let h=Gp(e);if(h)console.log(h);return s?1:0}async function a2(t,e){let n=lt(t,!1),r=new Map(vo(t,n).filter((a)=>e.includes(a.name)).map((a)=>[a.name,a]));if(r.size===0)return;let i=Qr(t);yo(t,i.map((a)=>r.get(a.name)??a));let s=q(t);Dt(t,n,s);let o=new Map(i.map((a)=>[a.name,a.pictures]));await Os(t,qt(t,n,!1).palettes.filter((a)=>r.has(a.name)).map((a)=>DE(a,o.get(a.name))),s.terminals)}async function fb(t,e,n,r=!1){let i=process.env.TTHEME_SORT==="catalog"?t.palettes:Gi(t.palettes);qi(i);let s=process.stdout.isTTY===!0,o=fa(process.env,s,Y()),a=o?await o.saved():new Map,c=new Qp({entries:i,scope:n,installed:e,required:r,color:!Ct(),fx:Xl(process.env.TTHEME_FX),onFocus:o?(f)=>process.stdout.write(o.paint(f)):void 0}),u=await c.prompt();if(o)process.stdout.write(o.restore(a));if(u==="cancel")return;return t.palettes.filter((f)=>c.picked.has(f.name)).map((f)=>f.name)}function db(t,e,n,r){let i=n===J?void 0:mc(t,n),s;try{s=i?.id??pi(t,n)}catch{s=wt(n)?Vr(n):st(n)}return{source:n,id:s,...i?.info.description?{description:i.info.description}:{},shown:st(n),entries:n===J?qo(t,n):i?.entries??[],auto:Zr(n,e.updates),status:Dp(t,n,r)}}function hb(t){return vo(t,lt(t,!1)).map((e)=>e.name)}function j6(t,e,n,r,i){return{refresh:async(s)=>{if(Rt(s)){let a=db(t,e,s,Sr());return{marketplace:a,refreshed:{source:s,id:a.id,count:At(a.entries).length,change:{added:[],changed:[],gone:[]}},updates:hb(t)}}let o=await Cp(t,s,Np);return{marketplace:db(t,e,s,Sr()),refreshed:o,updates:hb(t)}},fetch:async(s)=>{if(Rt(s)){let a=Ye(s),c=ye(a);return{source:s,id:c,...a.description?{description:a.description}:{},shown:st(s),entries:Cn(s,c,qo(t,J),pe(!1)),auto:!1,status:"read in place"}}let o=await hc(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:st(s),entries:o.entries,auto:Zr(s,{}),status:"not added yet"}},index:()=>Gl(r),apply:i}}function c2(...t){for(let e of ps(...t))Wn(e)}function _6(t,e,n){let r=[];for(let i of t.adds){let s=i.source!==J&&(t.auto[i.source]??i.auto);r.push(`Added ${i.id} · ${i.shown} — ${_t(At(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} · ${st(i)}`);let o=n.filter((a)=>(et(a)??J)===s);if(o.length>0)r.push(qp(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 B6(t,e,n,r){let i=q(t),s=n.adds.length+n.removes.length+Object.keys(n.auto).length>0;for(let m of n.adds){let p=r.get(m.source);if(p)zo(t,p)}for(let m of n.removes)zp(t,m);let o=[...Yt(i.marketplaces).filter((m)=>!n.removes.includes(m)),...n.adds.map((m)=>m.source)],a=bc(i,o,{...i.updates,...n.auto});if(s)tn(t,a);let c=lt(t,!1),u=qt(t,c,!1).palettes.filter((m)=>n.picked.has(m.name)).map((m)=>m.name),f=i.palettes.filter((m)=>!u.includes(m)),l=u.filter((m)=>!i.palettes.includes(m)),d=n.renew.filter((m)=>u.includes(m));if(!s&&l.length===0&&f.length===0&&d.length===0){c2(t,n.refreshed),Wn("Nothing changed");return}let h={...a,palettes:u};en(t,c,i,h),Bo(t,c,i.terminals,f);for(let m of _6(n,e,u))Wn(m);for(let m of l)Wn(` + ${m}`);for(let m of f)Wn(` - ${m}`);for(let m of ps(t,n.refreshed))Wn(m);if(await Os(t,qt(t,c,!1).palettes.filter((m)=>l.includes(m.name)),h.terminals),d.length>0){await a2(t,d);for(let m of d)Wn(` ↑ ${m}`)}if(l.length>0||f.length>0)Kf(h.palettes.length)}async function u2(){let t=ay(process.env),e=Y(),n=q(e),r=Qr(e),i=Sr(),s=Wo(),o=Yt(n.marketplaces).map((k)=>db(e,n,k,i)),a=new Set(o.flatMap((k)=>k.entries.map((v)=>v.name))),c=r.filter((k)=>n.palettes.includes(k.name)&&!a.has(k.name));qi([...o.flatMap((k)=>k.entries),...c]);let u=new Map,f=new AbortController,l=process.stdout.isTTY===!0,d=fa(process.env,l,e),h=d&&!t?await d.saved():new Map,m=Ge(n);if(t)process.stdout.write("\x1B[?2026h");let p=new eg({marketplaces:o,kept:c,installed:n.palettes,updates:hb(e),tuned:Object.keys(zt(e)),...m?{startup:m}:{},...t?{hub:t}:{},due:s?Hp(e,n):[],io:j6(e,n,u,f.signal,(k,v)=>Sv({say:v.say,set:v.status},()=>B6(e,o,k,u))),...process.env.TTHEME_SORT==="catalog"?{}:{order:Gi},color:!Ct(),lookups:process.env.TTHEME_MARKETPLACE_LOOKUP!=="off",fx:Xl(process.env.TTHEME_FX),owns:l&&!t,...d?{onFocus:(k)=>process.stdout.write(d.paint(k))}:{}});try{await p.run()}finally{if(d?.stop?.(),d&&(!t||p.next()===void 0))process.stdout.write(d.restore(h));f.abort()}await p.idle();let b=p.result(),$=p.next();if(t&&$!==void 0)return c2(e,b.refreshed),$;if(l&&t)process.stdout.write("\x1B[?1049l\x1B[?25h");for(let k of b.refreshed){let v=Bp(k);if(v)console.log(v)}if(p.applied()){for(let v of p.lines())console.log(v);let k=p.failure();if(k)throw k}else{for(let k of ps(e,b.refreshed))console.log(k);console.log("Nothing changed")}return t?Vu:0}import{rmSync as l2}from"node:fs";import{basename as G6,join as Qc}from"node:path";var f2=Qc(import.meta.dirname,".."),U6=Qc(f2,"themes"),mb=Qc(f2,"dist"),zf=oe.map((t)=>vr[t].emitter),W6=[jm,Km],FX=zf.map((t)=>t.id);async function qf({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?zf.filter((s)=>t.includes(s.id)):zf,n=m$(U6),r=nw(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===zf.length)l2(mb,{recursive:!0,force:!0});else for(let s of e)l2(Qc(mb,s.id),{recursive:!0,force:!0});let i=0;for(let s of[...e,...W6]){let o=n.flatMap((u)=>s.emit?.(u)??[]),a=s.emitShared?.(n)??[];for(let u of[...o,...a])await Bun.write(Qc(mb,u.path),u.content),i++;let c=o.length>0?`${n.length} themes${s.limits?` (${s.limits})`:""}`:a.length>0?a.map((u)=>G6(u.path)).join(" "):`no files (${s.limits??"nothing to write"})`;console.log(` ${s.id.padEnd(16)} ${c}`)}console.log(`
756
+ ${n.length} themes (${p$(n).length} in the new-tab rotation) -> ${i} files in dist/`)}import{existsSync as q6,readFileSync as g2}from"node:fs";import{availableParallelism as K6,homedir as d2}from"node:os";var z6=4;async function Df(t,e,n=d2()){let r=Ft(X(t)),i=oi(t),s=new Map(ve(t).palettes.map((l)=>[l.name,oo(l)])),o=Object.entries(r.palettes).flatMap(([l,d])=>{let h=s.get(l);return h?d.pictures.filter((m)=>ao(m)||(m.blur??0)!==i||m.cut!==void 0&&m.matte!==Aa).map((m)=>({name:l,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=fs(q(t).terminals),c=new jg(Math.min(z6,K6()-1)),u=await c.map(o.map(({name:l,key:d,paint:h})=>({job:"redraw",home:t,user:n,name:l,key:d,paint:h,blur:i,aligns:a})));c.close();let f=[];return u.forEach((l,d)=>{let{name:h,key:m}=o[d];if(l instanceof Error||l===null){e(` ▢ ${h} ${m} — ${l instanceof Error?l.message:"no original to draw it from"}, left as it was`);return}f.push({name:h,picture:l})}),Eh(t,f),Ue(t,n),f.length}async function h2(t,e,n,r,i=d2()){let s=Ft(X(t)).palettes[e],o=s?.pictures.find((f)=>f.key===(r??s.active));if(!s||!o)throw Error(`${e} has no picture ${r??"shown"}`);if(Je(o)===n)return{key:o.key,changed:!1};let a=ve(t).palettes.find((f)=>f.name===e);if(!a)throw Error(`no palette called ${e}`);let c=fs(q(t).terminals),u=await $f(t,e,o.key,oo(a),oi(t),c,i,n);if(!u)throw Error(`${e} ${o.key} has no original to draw it from`);return Eh(t,[{name:e,picture:u}]),Ue(t,i),{key:o.key,changed:!0}}function m2(t,e,n){let r=Ft(X(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=ve(t).palettes.find((a)=>a.name===e);if(!s)throw Error(`no palette called ${e}`);let o=Je(i)==="original"?"tone":"original";if(!VE(t,e,i.key,oo(s),oi(t),o))throw Error(`${e} ${i.key} has no original to draw it from`);return{key:i.key,coloring:o}}async function p2(){return await Df(Y(),(t)=>process.stderr.write(`${t}
757
+ `)),0}async function b2(t,e,n){let r=Y();if(jn(ve(r).palettes,t),e==="show"){if(!n)throw Error("image show needs the picture to show");let{at:i,of:s}=co(r,t,n);return Ue(r),process.stderr.write(`Background · ${t} ${i}/${s} ${n}
758
+ `),0}if(e==="drop"){let{key:i,left:s}=Ru(r,t,n);return Ue(r),process.stderr.write(`Background · ${t} removed ${i} · ${s} left
759
+ `),0}if(e==="tone"||e==="original"){let i=await h2(r,t,e,n);return process.stderr.write(`Background · ${t} ${i.key} ${e==="tone"?"tinted":"in its own colors"}
760
+ `),0}if(e==="prepare"){let{key:i,coloring:s}=m2(r,t,n);return process.stderr.write(`Background · ${t} ${i} ready in ${s==="tone"?"its tone":"its own colors"}
761
+ `),0}if(e==="tuned")return Ue(r),0;throw Error(`unknown image action ${e} — show, drop, tone, original, prepare or tuned`)}function w2(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 D6(t,e,n){let r=w2(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 $2(t,e,n,r){let i=new Uint8Array(g2(t)),s=w2(n,r),o=Kt(i),a=$0(i);return H(e,a?ar(u0(or(o),s),a):De(c0(o,s))),0}function k2(t,e,n,r,i,s,o){let a=Number(r);if(!$e(n)||!Number.isFinite(a))throw Error("flatten needs a #rrggbb background and an opacity from 0 to 1");let c=Kt(new Uint8Array(g2(t))),u=i?D6(c,i,s??""):void 0,f=Wr(Gr(c,n,Math.max(0,Math.min(1,a)),u));if(o&&q6(o))Ti(o,e,f);else H(e,f);return 0}import{execFileSync as J6}from"node:child_process";import{readFileSync as Y6}from"node:fs";import{arch as V6,platform as Jf,release as pb}from"node:os";var Z6={ghostty:"ghostty",iterm2:"iTerm.app",wezterm:"WezTerm","terminal-app":"Apple_Terminal",warp:"WarpTerminal"};function X6(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=Z6[t];return n!==void 0&&e.TERM_PROGRAM===n?e.TERM_PROGRAM_VERSION:void 0}function Q6(t){let e=Zt(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 (${Rm(t)})`:`${e} ${X6(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 y2(t,e){try{return J6(t,e,{encoding:"utf8",timeout:2000,stdio:["ignore","pipe","ignore"]}).trim()}catch{return}}function t_(){let t=V6();if(Jf()==="darwin")return`macOS ${y2("sw_vers",["-productVersion"])??`(Darwin ${pb()})`} · ${t}`;if(Jf()==="linux"){let e="";try{e=Y6("/etc/os-release","utf8")}catch{}return`${/^PRETTY_NAME="?([^"\n]*)"?$/m.exec(e)?.[1]??"Linux"} · linux ${pb()} · ${t}`}return`${Jf()==="win32"?"Windows":Jf()} ${pb()} · ${t}`}function e_(t){if(t.TTHEME_ZSH)return`zsh ${t.TTHEME_ZSH}`;return(t.SHELL?y2(t.SHELL,["--version"])?.split(`
762
+ `)[0]:void 0)??t.SHELL??"unknown"}function n_(t){try{let{terminals:e}=q(t);return e.length>0?e.join(", "):"none"}catch{return"installed.json missing or unreadable"}}function r_(t){let e=gl.flatMap((n)=>{let r=t[n];return r===void 0||r===Qa(n)?[]:[`${n}=${/\s/.test(r)?JSON.stringify(r):r}`]});return e.length>0?e.join(" "):void 0}function v2(){let t=process.env,n=[["ttheme",dt.version],["OS",t_()],["Shell",e_(t)],["Terminal",Q6(t)],["Wired",n_(Y())],["Settings",r_(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 s_,spawnSync as o_}from"node:child_process";import{chmodSync as a_,copyFileSync as c_,existsSync as Ie,mkdirSync as T2,readdirSync as F2,readFileSync as Ei,renameSync as u_,rmSync as eu}from"node:fs";import{homedir as l_}from"node:os";import{dirname as da,join as rt}from"node:path";import{existsSync as S2}from"node:fs";import{basename as i_,join as tu}from"node:path";var E2=["zsh","bash","fish"];function Yf(t){let e=i_(t??"").replace(/^-/,"");return E2.includes(e)?e:void 0}function bb(t,e){for(let n=e,r=0;n>1&&r<12;r++){let[i,...s]=t("ps",["-o","ppid=,comm=","-p",String(n)])?.trim().split(/\s+/)??[],o=Yf(s.join(" "));if(o)return o;n=Number(i)}return}function M2(t,e){let n=new Set(["zsh",Yf(t.env.SHELL),bb(t.run,e)]);return E2.filter((r)=>n.has(r))}var gb="ttheme-zdotdir:";function Vf(t,e){if(t.env.ZDOTDIR)return t.env.ZDOTDIR;let n=t.run("zsh",["-c",`print -rn -- "${gb}\${ZDOTDIR:-$HOME}"`])??"",r=n.lastIndexOf(gb);return r>=0&&n.slice(r+gb.length)||e}function x2(t){return t.run("zsh",["-fc","print ok"])==="ok"}var O2=[".bash_profile",".bash_login",".profile"];function P2(t,e){let n=tu(t,".bashrc"),r=O2.map((s)=>tu(t,s)).find((s)=>S2(s)),i=[...S2(n)?[n]:[],...r?[r]:[]];if(e==="darwin"&&!r)i.push(tu(t,".bash_profile"));return i.length>0?i:[n]}function I2(t){return[".bashrc",...O2].map((e)=>tu(t,e))}var R2=`zsh -c 'source ${pl} && ttheme "$@"' ttheme`;function A2(){return`# ${Me}
763
+ ttheme() { ${R2} "$@"; }`}function Zf(t){return tu(t,"fish","functions","ttheme.fish")}function N2(){return[`# ${Me}`,"function ttheme --description 'Run ttheme through zsh'",` ${R2} $argv`,"end",""].join(`
764
+ `)}function Xf(t){return t.startsWith(`# ${Me}
765
+ `)}function f_(t,e){return F2(t).map((n)=>({from:rt(t,n),to:rt(e,n)}))}function yb(t){return Xr(Ei(rt(t,"dist","manifest.json"),"utf8"))}function td(t,e){let n=rt(e.configHome,"ttheme"),r=[{from:rt(e.root,"bin","ttheme.js"),to:rt(n,"ttheme.js")},{from:rt(e.root,"bin","ttheme.js.map"),to:rt(n,"ttheme.js.map")},{from:rt(e.root,"bin","package.json"),to:rt(n,"package.json")},{from:rt(e.root,"shell","ttheme.zsh"),to:rt(n,"ttheme.zsh")},{from:rt(e.root,"shell","preview.zsh"),to:rt(n,"preview.zsh")},{from:rt(e.root,"shell","launch-tab.zsh"),to:rt(n,"launch-tab.zsh"),executable:!0},...f_(rt(e.root,"shell","adapters"),rt(n,"adapters"))],i=e.shells??["zsh"],s=[{file:rt(e.zdotdir,".zshrc"),block:t1(),about:"source ttheme.zsh"},...i.includes("bash")?P2(e.home,e.platform??process.platform).map((p)=>({file:p,block:A2(),about:"the ttheme command, run through zsh"})):[]],o=Zf(e.configHome),a=!Ie(o)||Xf(Ei(o,"utf8")),c=i.includes("fish")&&a?[{file:o,content:N2(),about:"the ttheme command, run through zsh"}]:[],u=rt(n,"config.zsh"),f=n1(Ie(u)?Ei(u,"utf8"):""),l={file:u,content:t.warpFast===void 0?f:wl(f,"TTHEME_WARP_FAST",t.warpFast?"on":"off")},d={terminals:t.terminals,palettes:t.palettes,...Object.fromEntries(St(t.terminals).flatMap((p)=>Object.entries(p.installs?.(e)??{}).filter(([,b])=>b!==void 0))),...t.off?{off:!0}:{}},h=[...Cl(e.configHome,d,e.home),...i.includes("fish")&&!a?[`${ht(o,e.home)} is a function of your own — ttheme left it, so fish has no ttheme command`]:[],...i.some((p)=>p!=="zsh")?[`${i.filter((p)=>p!=="zsh").join(" and ")} run ttheme through zsh — a pin taking effect on cd, the picture following the tab in front and the repaint after a program resets the colors stay with zsh tabs`]:[]],m=e.stateDir?[rt(e.stateDir,"ghostty",".blind")]:[];return{home:e.home,copies:r,edits:s,writes:c,settings:l,forget:m,manifest:yb(e.root),installed:d,notes:h}}function L2(t){try{return q(t)}catch{return}}var Qf="ttheme-market.toml",d_="https://www.schemastore.org/ttheme-market.json";function h_(t,e){let n=rt(t,"ttheme"),r=rt(n,"market");for(let[c,u]of[[r,Yi(t)],[rt(n,"markets"),bo(t)],[rt(n,"catalog.json"),mn(t)]])if(Ie(c)&&!Ie(u))u_(c,u);eu(rt(e,"markets.json"),{force:!0});let i=bo(t);for(let c of Ie(i)?F2(i).filter((u)=>u.endsWith(".json")):[])try{let u=JSON.parse(Ei(rt(i,c),"utf8"));if(!u||typeof u!=="object"||!("files"in u))continue;let f=u.files;if(f&&typeof f==="object"&&Qf in f&&!(ot in f)){let{[Qf]:l,...d}=f;H(rt(i,c),`${JSON.stringify({...u,files:{...d,[ot]:l}})}
766
+ `)}}catch{}let s=hn(t),o;try{o=JSON.parse(Ei(s,"utf8"))}catch{return[]}if(!o||typeof o!=="object")return[];if("markets"in o&&!("marketplaces"in o)){let{markets:c,...u}=o,f=(Array.isArray(c)?c:[]).map((l)=>typeof l==="string"&&l.startsWith(`${r}/`)?rt(Yi(t),l.slice(r.length+1)):l);o={...u,marketplaces:f},H(s,`${JSON.stringify(o,null,2)}
767
+ `)}let a=o&&typeof o==="object"&&"marketplaces"in o?o.marketplaces:void 0;return(Array.isArray(a)?a:[]).flatMap((c)=>{if(typeof c!=="string"||!Rt(c))return[];let u=rt(c,Qf),f=rt(c,ot);if(!Ie(u)||Ie(f))return[];return H(f,Ei(u,"utf8").replace(d_,Th)),eu(u),[`Renamed ${Qf} to ${ot} in ${st(c)}`]})}function C2(t,e){try{return qt(t,lt(t,!1,e),!1).palettes}catch{return[]}}function m_(t,e){let n=yb(e.root),r=Yt(t.marketplaces).includes(J)?n.palettes:[],i=new Set(r.map((o)=>o.name)),s=C2(e.configHome,n).filter((o)=>!i.has(o.name)&&(et(o.name)!==void 0||t.palettes.includes(o.name)));return{...n,palettes:[...r,...s]}}function j2(t,e){let n=ls(t);return n&&e.includes(n)?n:void 0}function p_(t,e,n){let r=td(e,n),i=j2(t,e.palettes),s=new Set(["terminals","palettes","off","startup",...oe.flatMap((a)=>Object.keys(vr[a].installs?.(n)??{}))]),o=Object.fromEntries(Object.entries(t).filter(([a])=>!s.has(a)));return{...r,installed:{...o,...r.installed,...i?{startup:i}:{}}}}function g_(t,e){let n=td({terminals:t.terminals,palettes:t.palettes,off:t.off},e),r=new Set([...n.manifest.palettes,...C2(e.configHome,n.manifest)].map((f)=>f.name)),i=t.palettes.filter((f)=>r.has(f)),s=t.palettes.filter((f)=>!r.has(f)),{startup:o,...a}=t,c={...a,palettes:i,...o&&i.includes(o)?{startup:o}:{}},u=s.length>0?[`Dropped ${s.join(", ")} — no longer in any marketplace`,...n.notes]:n.notes;return{...n,installed:c,notes:u}}function b_(t){try{return s_(process.execPath,[rt(t,"ttheme","ttheme.js"),"--version"],{encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim()||void 0}catch{return}}function _2(t){let e=Ge(t);return[St(t.terminals).map((n)=>n.name).join(", "),`${t.palettes.length} palettes`,e?`default ${e}`:"no default — ttheme is off"].join(" · ")}function wb(t,e=Qe()){for(let o of t.copies)if(T2(da(o.to),{recursive:!0}),eu(o.to,{force:!0}),eu(`${o.to}.zwc`,{force:!0}),c_(o.from,o.to),o.executable)a_(o.to,493);H(t.settings.file,t.settings.content);for(let o of t.forget)eu(o,{force:!0});let n=da(da(t.settings.file)),r=L2(n),i=Object.fromEntries(St(t.installed.terminals).flatMap((o)=>{let a=o.defaults?.key,c=a?r?.[a]:void 0;return a&&c?[[a,c]]:[]})),s=uc(n,{...t.installed,...i},e,t.home);if(Yt(s.marketplaces).includes(J))Nk(n,t.manifest);tn(n,s),Dt(n,lt(n),s,t.home,e);for(let o of t.edits){T2(da(o.file),{recursive:!0});let a=Ie(o.file)?Ei(o.file,"utf8"):"";On(o.file,si(a,o.block))}for(let o of t.writes)H(o.file,o.content);return ds(n,s,!0,e,t.home)}function nu(t){if(se(t))throw ni("Nothing changed"),new we;return t}function $b(t,e){return oe.filter((n)=>vr[n].offered(t,e))}async function w_(t,e,n,r){return nu(await Hy({message:"Wire which terminals?",options:$b(n,r).map((i)=>({value:i,label:vr[i].name,hint:i===t?"detected":void 0})),initialValues:e,required:!0}))}async function $_(t){return nu(await Be({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:No(t,"TTHEME_WARP_FAST")!=="off"}))}function kb(t){let e=[...t.copies.filter((n)=>!Ie(n.to)).map((n)=>n.to),...Ie(t.settings.file)?[]:[t.settings.file],...t.edits.filter((n)=>!Ei(n.file,"utf8").includes("# ttheme begin")).map((n)=>n.file),...t.writes.filter((n)=>!Ie(n.file)).map((n)=>n.file)];if(e.length>0)throw Error(`init left gaps:
767
768
  ${e.join(`
768
- `)}`)}function E2(t,e){return[...new Set(t.palettes.filter((n)=>e.includes(n.name)).map(ne))]}function Z6(t,e,n){let r=t.palettes.find((o)=>o.name===Ge(e)),i=process.stdout.isTTY===!0,s=r&&oa(process.env,i,n)?.wear(r,e.terminals);if(s===void 0)return!1;return process.stdout.write(s),!0}function X6(t,e){let n=Ge(t);if(!n)return["Default none — new tabs keep the terminal colors",`Turn on \`ttheme on\` wears ${us(t)}`];return[`Default ${n}${e?" — this tab wears it already":""}`,"Change it `ttheme`, enter on a palette, then default"]}function Q6(t){C6("zsh",["-c",'source "$1" && __tt_preview init',"zsh",rt(t,"ttheme","ttheme.zsh")],{stdio:"inherit"})}function hb(t){return t==="bash"?"exec bash -l":`exec ${t}`}function t_(t,e,n,r,i){let s=E2(t.manifest,e.palettes);Fn([`${s.join(", ")} (${e.palettes.length})`,...X6(t.installed,n)].join(`
769
- `),`Installed ${e.palettes.length} palettes`),Fn([`${hb(i).padEnd(18)}The ttheme command in this tab`,...mb(t,r)].join(`
770
- `),"Next"),Ka("Done")}function mb(t,e){return[...Il(aa(aa(t.settings.file)),t.installed,e,t.home),...t.notes]}function M2(t){return t?(e)=>mr.step(e):(e)=>console.log(e)}async function w2(t,e,n,r,i,s){let o=D6(t,e),a=ub(o,n);fb(o),await Bf(e.configHome,M2(r),e.home);let c=[`${hb(i).padEnd(18)}Open tabs run the new layer — new tabs already do`,...mb(o,a),...s],u=`Updated to ${dt.version} — kept ${S2(o.installed)}`;if(!r){console.log([u,...c].join(`
771
- `));return}Fn(c.join(`
772
- `),u),Ka("Done")}function e_(t,e,n){let r=[`Placed ${t.copies.length} files`,`Settings in ${t.settings.file} — edit later with \`ttheme config\``,...[...t.edits,...t.writes].map((i)=>`Wired ${i.file}`),...mb(t,e),`No palettes yet — open a new shell (\`${hb(n)}\`), then \`ttheme\` picks them from your marketplaces`];console.log(r.join(`
773
- `))}async function x2(t={}){let e=rt(import.meta.dirname,"..");for(let P of["ttheme.js","package.json"])if(!xe(rt(e,"bin",P)))throw Error(`bin/${P} is missing — run \`mise run bin:build\` first`);if(!xe(rt(e,"dist"))){if(typeof Bun>"u")throw Error("this package is missing dist/ — reinstall @kecan0406/ttheme");await Gf()}let n=B6(),r=Y(),i=Xe();if(!l2(i))throw Error("ttheme runs its tab layer in zsh, even for bash and fish — install zsh first");let s=Q1(i),o=process.env.WT_PROFILE_ID,a=rt(process.env.XDG_STATE_HOME??rt(n,".local","state"),"ttheme"),c={root:e,home:n,configHome:r,zdotdir:Kf(i,n),shells:u2(i,process.ppid),platform:i.platform,stateDir:a,...s?{wtHome:s}:{},...o?{wtProfile:o}:{}},u=cb(i.run,process.ppid)??Wf(i.env.SHELL)??"zsh",f=Vt(process.env),l=lb(c,i).filter((P)=>P===f);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=K6(r,a),h=k2(r);if(t.yes&&h){await w2(h,c,i,!1,u,d);return}if(t.yes){if(l.length===0)throw Error(`no supported terminal detected — run this inside ${St(lb(c,i)).map((B)=>B.name.toLowerCase()).join(", ").replace(/, ([^,]*)$/," or $1")}`);let _=Jf({terminals:l,palettes:[]},c),K=ub(_,i);fb(_),e_(_,K,u);return}if(tl("ttheme init"),h){let P=J6(r);if(Vc(await _e({message:`ttheme${P?` ${P}`:""} is installed — ${S2(h)}
774
- ${P===dt.version?"Reinstall":"Update to"} ${dt.version} and keep all of it?`,active:"Yes",inactive:"No, set it up again",initialValue:!0}))){await w2(h,c,i,!0,u,d);return}for(let K of d)mr.step(K)}let m=await Y6(f,h?.terminals??l,c,i),g=m.includes("warp")?await V6(r):void 0,b=h?z6(h,c):db(e),w=h?await nb(b,h.palettes,"palette",!0):await nb(b,[],"catalog",!0);if(!w)throw Zr("Nothing changed"),new pe;let k=(h&&v2(h,w))??w[0],v=w.length>1&&(ye[f].paints||f==="warp"&&m.includes("warp")&&xe(ai(n,r))),S=Vc(await _e({message:v?"Pick a default palette in ttheme once installed?":`Wear ${k} in every tab?`,initialValue:h?!h.off:!0})),x={terminals:m,palettes:w,off:!S,warpFast:g},M=h?q6(h,x,c):Jf(x,c);if(Fn([`Install ${w.length} palettes — ${E2(b,w).join(", ")}`,`Copy ${M.copies.length} files under ${r}`,`Write ${M.settings.file}`,...M.edits.map((P)=>`Edit ${P.file} — a ttheme block: ${P.about}`),...M.writes.map((P)=>`Write ${P.file} — ${P.about}`),...Pl(r,M.installed,n),"Each config is backed up once to <file>.ttheme.bak before the first edit — `npx @kecan0406/ttheme uninstall` takes it all out",S?v?`Open ttheme — every tab wears the palette picked there, ${k} until then`:`Paint every tab with ${k}, this one now`:"Leave the terminal colors as they are — `ttheme on` wears a palette later",...S&&k?St(m).flatMap((P)=>P.defaults?[`Make "${P.defaults.profile(k)}" the ${P.name} default profile`]:[]):[]].join(`
775
- `),`Wiring ${St(m).map((P)=>P.name).join(", ")}`),!Vc(await _e({message:"Apply these changes?"})))throw Zr("Nothing changed"),new pe;let N=ub(M,i);if(fb(M),await Bf(r,M2(!0),n),S&&v)Q6(r);let C=q(r);t_({...M,manifest:b,installed:C},x,Z6(b,C,r),N,u)}import{spawn as n_}from"node:child_process";import{createHash as r_}from"node:crypto";import{existsSync as pb,mkdirSync as i_,readFileSync as s_,statSync as o_,utimesSync as a_,writeFileSync as c_}from"node:fs";import{homedir as I2}from"node:os";import{join as A2}from"node:path";import{gunzipSync as u_}from"node:zlib";var O2="https://github.com/kecan0406/aninames/releases/latest/download",N2=86400000,l_=3600000,f_=120000;function T2(t){return A2(Kr(t),".checked")}function d_(t=process.env){return t.TTHEME_NAMES!=="off"}function h_(t){try{return Date.now()-o_(T2(t)).mtimeMs>=N2}catch{return!0}}function gb(t,e){let n=T2(t);if(i_(Kr(t),{recursive:!0}),!pb(n))c_(n,"");a_(n,e/1000,e/1000)}function H2(t=I2()){if(!d_()||!h_(t))return;try{gb(t,Date.now()),n_(process.execPath,[process.argv[1],"names"],{detached:!0,stdio:"ignore",env:process.env}).unref()}catch{}}function P2(t){return r_("sha256").update(t).digest("hex")}async function R2(t){let e=await fetch(t,{signal:AbortSignal.timeout(f_)});if(!e.ok)throw Error(`${t} answered ${e.status}`);return new Uint8Array(await e.arrayBuffer())}async function L2(t=I2()){let e=Kr(t);try{let r=JSON.parse(new TextDecoder().decode(await R2(`${O2}/ttheme.json`)));for(let[i,{file:s,sha256:o}]of Object.entries(r.layers)){let a=A2(e,`ttheme-${i}.json`);if(pb(a)&&P2(s_(a))===o)continue;let c=u_(await R2(`${O2}/${s}`));if(P2(c)!==o)throw Error(`${s} does not match its hash`);L(a,c)}gb(t,Date.now())}catch{return gb(t,Date.now()-N2+l_),1}Pu(t);let n=Y();if(pb(fn(n)))zi($e(n).palettes,t),sv(n,t);return 0}import{createHash as m_}from"node:crypto";import{existsSync as bb,readdirSync as F2,readFileSync as wb,rmSync as p_,statSync as g_,utimesSync as b_}from"node:fs";import{homedir as w_}from"node:os";import{join as ki}from"node:path";var $_=new Set(["814e75361c745b9f1467c82bee90ab3f47daeaa70a528d330a4bc8aec9faeeb9","668092ea188445700b02d60a102c429e092e46fcd88c33509b9f1fd64d68e6a6","bf52a8c6d019f59f71723be460d7fe450234d0f03ff0f35e94db2c42455f00ba","8df4e3246f2cf26deaa0f620f31e94efac21104ec2dbe81fba55ba066141aeb4","7bdc8051f34b902e970df84df0e4c8d27331b5e04da7f7b498d50b592eaa72f2","e06b39cd6fa2701bd360b7062d82d4a56766aba97889dfa547d14db5895454f1"]);function C2(t){try{return F2(t).map((e)=>ki(t,e)).filter((e)=>g_(e).isFile())}catch{return[]}}function k_(t){let e=t.slice(t.lastIndexOf("/")+1);if(e.startsWith(j("")))return!1;let n=e.replace(/\.(conf|toml)$/,""),r=wb(t,"utf8");return r.startsWith(`# ${n} — `)&&r.split(`
769
+ `)}`)}function B2(t,e){return[...new Set(t.palettes.filter((n)=>e.includes(n.name)).map(ie))]}function k_(t,e,n){let r=t.palettes.find((o)=>o.name===Ge(e)),i=process.stdout.isTTY===!0,s=r&&fa(process.env,i,n)?.wear(r,e.terminals);if(s===void 0)return!1;return process.stdout.write(s),!0}function y_(t,e){let n=Ge(t);if(!n)return["Default none — new tabs keep the terminal colors",`Turn on \`ttheme on\` wears ${ls(t)}`];return[`Default ${n}${e?" — this tab wears it already":""}`,"Change it `ttheme`, enter on a palette, then default"]}function v_(t){o_("zsh",["-c",'source "$1" && __tt_preview init',"zsh",rt(t,"ttheme","ttheme.zsh")],{stdio:"inherit"})}function vb(t){return t==="bash"?"exec bash -l":`exec ${t}`}function S_(t,e,n,r,i){let s=B2(t.manifest,e.palettes);Bn([`${s.join(", ")} (${e.palettes.length})`,...y_(t.installed,n)].join(`
770
+ `),`Installed ${e.palettes.length} palettes`),Bn([`${vb(i).padEnd(18)}The ttheme command in this tab`,...Sb(t,r)].join(`
771
+ `),"Next"),Va("Done")}function Sb(t,e){return[...jl(da(da(t.settings.file)),t.installed,e,t.home),...t.notes]}function G2(t){return t?(e)=>$r.step(e):(e)=>console.log(e)}async function H2(t,e,n,r,i,s){let o=g_(t,e),a=wb(o,n);kb(o),await Df(e.configHome,G2(r),e.home);let c=[`${vb(i).padEnd(18)}Open tabs run the new layer — new tabs already do`,...Sb(o,a),...s],u=`Updated to ${dt.version} — kept ${_2(o.installed)}`;if(!r){console.log([u,...c].join(`
772
+ `));return}Bn(c.join(`
773
+ `),u),Va("Done")}function E_(t,e,n){let r=[`Placed ${t.copies.length} files`,`Settings in ${t.settings.file} — edit later with \`ttheme config\``,...[...t.edits,...t.writes].map((i)=>`Wired ${i.file}`),...Sb(t,e),`No palettes yet — open a new shell (\`${vb(n)}\`), then \`ttheme\` picks them from your marketplaces`];console.log(r.join(`
774
+ `))}async function U2(t={}){let e=rt(import.meta.dirname,"..");for(let I of["ttheme.js","package.json"])if(!Ie(rt(e,"bin",I)))throw Error(`bin/${I} is missing — run \`mise run bin:build\` first`);if(!Ie(rt(e,"dist"))){if(typeof Bun>"u")throw Error("this package is missing dist/ — reinstall @kecan0406/ttheme");await qf()}let n=l_(),r=Y(),i=Qe();if(!x2(i))throw Error("ttheme runs its tab layer in zsh, even for bash and fish — install zsh first");let s=lv(i),o=process.env.WT_PROFILE_ID,a=rt(process.env.XDG_STATE_HOME??rt(n,".local","state"),"ttheme"),c={root:e,home:n,configHome:r,zdotdir:Vf(i,n),shells:M2(i,process.ppid),platform:i.platform,stateDir:a,...s?{wtHome:s}:{},...o?{wtProfile:o}:{}},u=bb(i.run,process.ppid)??Yf(i.env.SHELL)??"zsh",f=Zt(process.env),l=$b(c,i).filter((I)=>I===f);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=h_(r,a),h=L2(r);if(t.yes&&h){await H2(h,c,i,!1,u,d);return}if(t.yes){if(l.length===0)throw Error(`no supported terminal detected — run this inside ${St($b(c,i)).map((G)=>G.name.toLowerCase()).join(", ").replace(/, ([^,]*)$/," or $1")}`);let j=td({terminals:l,palettes:[]},c),U=wb(j,i);kb(j),E_(j,U,u);return}if(cl("ttheme init"),h){let I=b_(r);if(nu(await Be({message:`ttheme${I?` ${I}`:""} is installed — ${_2(h)}
775
+ ${I===dt.version?"Reinstall":"Update to"} ${dt.version} and keep all of it?`,active:"Yes",inactive:"No, set it up again",initialValue:!0}))){await H2(h,c,i,!0,u,d);return}for(let U of d)$r.step(U)}let m=await w_(f,h?.terminals??l,c,i),p=m.includes("warp")?await $_(r):void 0,b=h?m_(h,c):yb(e),$=h?await fb(b,h.palettes,"palette",!0):await fb(b,[],"catalog",!0);if(!$)throw ni("Nothing changed"),new we;let k=(h&&j2(h,$))??$[0],v=$.length>1&&(Ee[f].paints||f==="warp"&&m.includes("warp")&&Ie(di(n,r))),S=nu(await Be({message:v?"Pick a default palette in ttheme once installed?":`Wear ${k} in every tab?`,initialValue:h?!h.off:!0})),x={terminals:m,palettes:$,off:!S,warpFast:p},M=h?p_(h,x,c):td(x,c);if(Bn([`Install ${$.length} palettes — ${B2(b,$).join(", ")}`,`Copy ${M.copies.length} files under ${r}`,`Write ${M.settings.file}`,...M.edits.map((I)=>`Edit ${I.file} — a ttheme block: ${I.about}`),...M.writes.map((I)=>`Write ${I.file} — ${I.about}`),...Ll(r,M.installed,n),"Each config is backed up once to <file>.ttheme.bak before the first edit — `npx @kecan0406/ttheme uninstall` takes it all out",S?v?`Open ttheme — every tab wears the palette picked there, ${k} until then`:`Paint every tab with ${k}, this one now`:"Leave the terminal colors as they are — `ttheme on` wears a palette later",...S&&k?St(m).flatMap((I)=>I.defaults?[`Make "${I.defaults.profile(k)}" the ${I.name} default profile`]:[]):[]].join(`
776
+ `),`Wiring ${St(m).map((I)=>I.name).join(", ")}`),!nu(await Be({message:"Apply these changes?"})))throw ni("Nothing changed"),new we;let N=wb(M,i);if(kb(M),await Df(r,G2(!0),n),S&&v)v_(r);let C=q(r);S_({...M,manifest:b,installed:C},x,k_(b,C,r),N,u)}import{spawn as M_}from"node:child_process";import{createHash as x_}from"node:crypto";import{existsSync as Eb,mkdirSync as O_,readFileSync as P_,statSync as I_,utimesSync as R_,writeFileSync as A_}from"node:fs";import{homedir as q2}from"node:os";import{join as D2}from"node:path";import{gunzipSync as N_}from"node:zlib";var W2="https://github.com/kecan0406/aninames/releases/latest/download",J2=86400000,T_=3600000,H_=120000;function Y2(t){return D2(Yr(t),".checked")}function F_(t=process.env){return t.TTHEME_NAMES!=="off"}function L_(t){try{return Date.now()-I_(Y2(t)).mtimeMs>=J2}catch{return!0}}function Mb(t,e){let n=Y2(t);if(O_(Yr(t),{recursive:!0}),!Eb(n))A_(n,"");R_(n,e/1000,e/1000)}function V2(t=q2()){if(!F_()||!L_(t))return;try{Mb(t,Date.now()),M_(process.execPath,[process.argv[1],"names"],{detached:!0,stdio:"ignore",env:process.env}).unref()}catch{}}function K2(t){return x_("sha256").update(t).digest("hex")}async function z2(t){let e=await fetch(t,{signal:AbortSignal.timeout(H_)});if(!e.ok)throw Error(`${t} answered ${e.status}`);return new Uint8Array(await e.arrayBuffer())}async function Z2(t=q2()){let e=Yr(t);try{let r=JSON.parse(new TextDecoder().decode(await z2(`${W2}/ttheme.json`)));for(let[i,{file:s,sha256:o}]of Object.entries(r.layers)){let a=D2(e,`ttheme-${i}.json`);if(Eb(a)&&K2(P_(a))===o)continue;let c=N_(await z2(`${W2}/${s}`));if(K2(c)!==o)throw Error(`${s} does not match its hash`);H(a,c)}Mb(t,Date.now())}catch{return Mb(t,Date.now()-J2+T_),1}Lu(t);let n=Y();if(Eb(mn(n)))qi(ve(n).palettes,t),gv(n,t);return 0}import{createHash as C_}from"node:crypto";import{existsSync as xb,readdirSync as X2,readFileSync as Ob,rmSync as j_,statSync as __,utimesSync as B_}from"node:fs";import{homedir as G_}from"node:os";import{join as Mi}from"node:path";var U_=new Set(["814e75361c745b9f1467c82bee90ab3f47daeaa70a528d330a4bc8aec9faeeb9","668092ea188445700b02d60a102c429e092e46fcd88c33509b9f1fd64d68e6a6","bf52a8c6d019f59f71723be460d7fe450234d0f03ff0f35e94db2c42455f00ba","8df4e3246f2cf26deaa0f620f31e94efac21104ec2dbe81fba55ba066141aeb4","7bdc8051f34b902e970df84df0e4c8d27331b5e04da7f7b498d50b592eaa72f2","e06b39cd6fa2701bd360b7062d82d4a56766aba97889dfa547d14db5895454f1"]);function Q2(t){try{return X2(t).map((e)=>Mi(t,e)).filter((e)=>__(e).isFile())}catch{return[]}}function W_(t){let e=t.slice(t.lastIndexOf("/")+1);if(e.startsWith(_("")))return!1;let n=e.replace(/\.(conf|toml)$/,""),r=Ob(t,"utf8");return r.startsWith(`# ${n} — `)&&r.split(`
776
777
  `)[1]?.startsWith("# ANSI: ")===!0||r.startsWith(`[metadata]
777
778
  name = "${n}"
778
- origin_url = "`)}function y_(t){let n=C2(t).filter((r)=>$_.has(m_("sha256").update(wb(r)).digest("hex")));return n.length>0&&n.length===F2(t).length?[t]:n}function v_(t){try{return q(t)}catch{return}}function S_(t){let{home:e,configHome:n}=t,r=v_(n),i={configHome:n,home:e},s=St(ie),o=s.map((u)=>u.unwire(i,r)),a=[ki(n,"ttheme"),t.cacheDir,t.stateDir],c=zf(n);return{edits:[...[...new Set([ki(t.zdotdir,".zshrc"),ki(e,".zshrc")])].flatMap((u)=>mn(u,jn)),...h2(e).flatMap((u)=>mn(u,jn)),...o.flatMap((u)=>u.edits)],removals:[...bb(c)&&qf(wb(c,"utf8"))?[c]:[],...s.flatMap((u)=>u.shelf?Po(u.shelf.dir(i)):[]),...s.flatMap((u)=>u.shelf?C2(u.shelf.dir(i)).filter(k_):[]),...y_(ki(n,"ghostty","shaders")),...o.flatMap((u)=>u.removals),...a.filter((u)=>bb(u))],touches:o.flatMap((u)=>u.touches),...r?{state:r}:{}}}function E_(t,e,n=Xe()){let r=[];for(let{file:s,content:o}of t.edits){let a=Xb(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=fs(e.configHome,{...t.state,off:!0,palettes:[]},!1,n,e.home);for(let o of St(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)p_(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)b_(s,i,i);return r}function M_(){let t=w_();return{home:t,configHome:Y(),zdotdir:Kf(Xe(),t),cacheDir:Rn(),stateDir:ki(process.env.XDG_STATE_HOME??ki(t,".local","state"),"ttheme")}}async function j2(t=!1){let e=M_(),n=S_(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=ki(e.configHome,"ttheme");tl("ttheme uninstall"),Fn([...n.edits.map((s)=>`Take ttheme out of ${s.file}`),...n.removals.map((s)=>s===r?`Delete ${s} — settings, pins, every installed picture${bb(Ji(e.configHome))?`, and your marketplaces under ${Ji(e.configHome)} (push them to GitHub first to keep them)`:""}`:`Delete ${s}`)].join(`
779
- `),"Uninstall");let i=await _e({message:"Remove ttheme?"});if(re(i)||!i)throw Zr("Nothing changed"),new pe}for(let r of E_(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 x_}from"node:os";async function _2(t){if(!ie.includes(t))throw Error(`no terminal ${t} — one of ${ie.join(", ")}`);let e=t,n=br[e],r=Y(),i=x_(),s=Xe(),o=q(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]};Fn([...Pl(r,c,i),...Rl(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(`
780
- `),`Wiring ${n.name}`);let u=await _e({message:`Wire ${n.name} now?`,initialValue:!1});if(re(u)||!u)throw Zr("Nothing changed"),new pe;let f=rc(r,c,s,i),l={...f,terminals:[...o.terminals,e]};Qe(r,l),qt(r,lt(r),l,i,s);let d=fs(r,f,!0,s,i),h=Il(r,f,d,i);if(h.length>0)Fn(h.join(`
781
- `),"Next");return Ka(`Wired ${n.name}`),0}var P_=new Set(["add","remove","marketplace","default","on","off"]),R_={default:([t])=>jx(t),on:()=>Gx(),off:()=>Bx(),browse:()=>Dx(),list:([t],{json:e})=>Wx(t,e),add:(t,{marketplace:e})=>Fx(t,e),remove:(t)=>Cx(t),update:(t)=>Kx(t),marketplace:([t,e])=>tS(t,e),new:([t],{from:e,in:n})=>$x(t,e,n),edit:async(t)=>kx(await G2(t,"edit")),check:async(t,{fix:e})=>Mx(await G2(t,"check"),e),share:async([t],{tone:e})=>{let n=e;if(t!==void 0)return eb(t,n);let r=await dx(n);if(!r)throw new Pr("name a palette",Yf("share"));return eb(r.name,r.tone)},init:(t,{yes:e})=>x2({yes:e}),uninstall:(t,{yes:e})=>j2(e),wire:([t])=>_2(t),info:()=>o2(),build:(t,{only:e})=>Gf({only:e}),find:([t])=>YM(t),image:([t,e,n])=>e2(t,e,n),sync:()=>_x(),redraw:()=>Qx(),names:()=>L2(),latest:()=>$v(),tone:([t,e,n])=>yx(t,e,n),flatten:([t,e,n,r,i,s,o])=>i2(t,e,n,r,i,s,o),bake:([t,e,n,r])=>r2(t,e,n,r)},I_=Eo.map((t)=>({...t,run:R_[t.name]}));class Pr extends Error{verb;constructor(t,e){super(t);this.verb=e}}function Yf(t){let e=I_.find((n)=>n.name===t);if(!e)throw new Pr(t.startsWith("-")?`unknown option '${t}'`:`unknown command '${t}'`);return e}async function G2([t],e){let n=t??await Xg();if(n===void 0){let r=process.env.TTHEME_WORN;throw new Pr(`name a palette${r?` — this tab wears ${r}`:""}`,Yf(e))}return n}function A_(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 O_({args:e,options:n,allowPositionals:!0})}catch(r){let[i=""]=(r instanceof Error?r.message:String(r)).split(". ");throw new Pr(`${i.charAt(0).toLowerCase()}${i.slice(1)}`,t)}}function N_(t){let[e,...n]=t;if(e===void 0)return{kind:"brief"};if(e==="-h"||e==="--help")return{kind:"help"};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"};return{kind:"help",verb:Yf(n[0])}}let r=Yf(e),i=A_(r,n);if(i.values.help)return{kind:"help",verb:r};for(let[f,{choices:l}]of Object.entries(r.flags??{}))for(let d of[i.values[f]??[]].flat())if(l&&!l.includes(String(d)))throw new Pr(`--${f} takes ${l.join(", ")} — not ${d}`,r);let s=i.positionals,o=r.args.filter((f)=>f.startsWith("<")).length,a=r.args.some((f)=>f.includes("..."))?Number.POSITIVE_INFINITY:r.args.length;if(s.length<o)throw new Pr(`missing ${r.args[s.length]}`,r);if(s.length>a)throw new Pr(`too many arguments: ${s.slice(a).join(" ")}`,r);let{help:c,...u}=i.values;return{kind:"run",verb:r,args:s,flags:u}}var T_=[TypeError,RangeError,ReferenceError,SyntaxError];function H_(t){return T_.some((e)=>t instanceof e)||t instanceof Error&&"code"in t}async function B2(t){let e;try{let n=N_(t);if(n.kind==="version")return console.log(dt.version),0;if(n.kind==="brief")return console.error(Uy()),1;if(n.kind==="help")return console.log(n.verb?ym(n.verb):qa(n.all===!0)),0;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(P_.has(n.verb.name))await Cv();let r=await n.verb.run(n.args,n.flags);if(!n.verb.hidden&&n.verb.name!=="uninstall"){if(H2(),n.verb.name!=="update"&&n.verb.name!=="init")wv(),Sv()}return typeof r==="number"?r:0}catch(n){if(n instanceof Pr)return console.error(n.verb?`ttheme ${n.verb.name}: ${n.message}
779
+ origin_url = "`)}function K_(t){let n=Q2(t).filter((r)=>U_.has(C_("sha256").update(Ob(r)).digest("hex")));return n.length>0&&n.length===X2(t).length?[t]:n}function z_(t){try{return q(t)}catch{return}}function q_(t){let{home:e,configHome:n}=t,r=z_(n),i={configHome:n,home:e},s=St(oe),o=s.map((u)=>u.unwire(i,r)),a=[Mi(n,"ttheme"),t.cacheDir,t.stateDir],c=Zf(n);return{edits:[...[...new Set([Mi(t.zdotdir,".zshrc"),Mi(e,".zshrc")])].flatMap((u)=>bn(u,Un)),...I2(e).flatMap((u)=>bn(u,Un)),...o.flatMap((u)=>u.edits)],removals:[...xb(c)&&Xf(Ob(c,"utf8"))?[c]:[],...s.flatMap((u)=>u.shelf?To(u.shelf.dir(i)):[]),...s.flatMap((u)=>u.shelf?Q2(u.shelf.dir(i)).filter(W_):[]),...K_(Mi(n,"ghostty","shaders")),...o.flatMap((u)=>u.removals),...a.filter((u)=>xb(u))],touches:o.flatMap((u)=>u.touches),...r?{state:r}:{}}}function D_(t,e,n=Qe()){let r=[];for(let{file:s,content:o}of t.edits){let a=aw(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=ds(e.configHome,{...t.state,off:!0,palettes:[]},!1,n,e.home);for(let o of St(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)j_(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)B_(s,i,i);return r}function J_(){let t=G_();return{home:t,configHome:Y(),zdotdir:Vf(Qe(),t),cacheDir:Tn(),stateDir:Mi(process.env.XDG_STATE_HOME??Mi(t,".local","state"),"ttheme")}}async function tO(t=!1){let e=J_(),n=q_(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=Mi(e.configHome,"ttheme");cl("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${xb(Yi(e.configHome))?`, and your marketplaces under ${Yi(e.configHome)} (push them to GitHub first to keep them)`:""}`:`Delete ${s}`)].join(`
780
+ `),"Uninstall");let i=await Be({message:"Remove ttheme?"});if(se(i)||!i)throw ni("Nothing changed"),new we}for(let r of D_(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 Y_}from"node:os";async function eO(t){if(!oe.includes(t))throw Error(`no terminal ${t} — one of ${oe.join(", ")}`);let e=t,n=vr[e],r=Y(),i=Y_(),s=Qe(),o=q(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([...Ll(r,c,i),...Cl(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(`
781
+ `),`Wiring ${n.name}`);let u=await Be({message:`Wire ${n.name} now?`,initialValue:!1});if(se(u)||!u)throw ni("Nothing changed"),new we;let f=uc(r,c,s,i),l={...f,terminals:[...o.terminals,e]};tn(r,l),Dt(r,lt(r),l,i,s);let d=ds(r,f,!0,s,i),h=jl(r,f,d,i);if(h.length>0)Bn(h.join(`
782
+ `),"Next");return Va(`Wired ${n.name}`),0}var Z_=new Set(["add","remove","marketplace","default","on","off"]),X_={default:([t])=>t2(t),on:()=>n2(),off:()=>r2(),browse:()=>u2(),list:([t],{json:e})=>s2(t,e),add:(t,{marketplace:e})=>Xx(t,e),remove:(t)=>Qx(t),update:(t)=>o2(t),marketplace:([t,e])=>fS(t,e),new:([t],{from:e,in:n})=>Fx(t,e,n),edit:async(t)=>Lx(await nO(t,"edit")),check:async(t,{fix:e})=>Gx(await nO(t,"check"),e),share:async([t],{tone:e})=>{let n=e;if(t!==void 0)return lb(t,n);let r=await Px(n);if(!r)throw new Nr("name a palette",ed("share"));return lb(r.name,r.tone)},init:(t,{yes:e})=>U2({yes:e}),uninstall:(t,{yes:e})=>tO(e),wire:([t])=>eO(t),info:()=>v2(),build:(t,{only:e})=>qf({only:e}),find:([t])=>fx(t),image:([t,e,n])=>b2(t,e,n),sync:()=>e2(),redraw:()=>p2(),names:()=>Z2(),latest:()=>Rv(),tone:([t,e,n])=>Cx(t,e,n),flatten:([t,e,n,r,i,s,o])=>k2(t,e,n,r,i,s,o),bake:([t,e,n,r])=>$2(t,e,n,r)},Q_=Io.map((t)=>({...t,run:X_[t.name]}));class Nr extends Error{verb;constructor(t,e){super(t);this.verb=e}}function ed(t){let e=Q_.find((n)=>n.name===t);if(!e)throw new Nr(t.startsWith("-")?`unknown option '${t}'`:`unknown command '${t}'`);return e}async function nO([t],e){let n=t??await ab();if(n===void 0){let r=process.env.TTHEME_WORN;throw new Nr(`name a palette${r?` — this tab wears ${r}`:""}`,ed(e))}return n}function tB(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 V_({args:e,options:n,allowPositionals:!0})}catch(r){let[i=""]=(r instanceof Error?r.message:String(r)).split(". ");throw new Nr(`${i.charAt(0).toLowerCase()}${i.slice(1)}`,t)}}function eB(t){let[e,...n]=t;if(e===void 0)return{kind:"brief"};if(e==="-h"||e==="--help")return{kind:"help"};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"};return{kind:"help",verb:ed(n[0])}}let r=ed(e),i=tB(r,n);if(i.values.help)return{kind:"help",verb:r};for(let[f,{choices:l}]of Object.entries(r.flags??{}))for(let d of[i.values[f]??[]].flat())if(l&&!l.includes(String(d)))throw new Nr(`--${f} takes ${l.join(", ")} — not ${d}`,r);let s=i.positionals,o=r.args.filter((f)=>f.startsWith("<")).length,a=r.args.some((f)=>f.includes("..."))?Number.POSITIVE_INFINITY:r.args.length;if(s.length<o)throw new Nr(`missing ${r.args[s.length]}`,r);if(s.length>a)throw new Nr(`too many arguments: ${s.slice(a).join(" ")}`,r);let{help:c,...u}=i.values;return{kind:"run",verb:r,args:s,flags:u}}var nB=[TypeError,RangeError,ReferenceError,SyntaxError];function rB(t){return nB.some((e)=>t instanceof e)||t instanceof Error&&"code"in t}async function rO(t){let e;try{let n=eB(t);if(n.kind==="version")return console.log(dt.version),0;if(n.kind==="brief")return console.error(Qy()),1;if(n.kind==="help")return console.log(n.verb?Nm(n.verb):Xa(n.all===!0)),0;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(Z_.has(n.verb.name))await Jv();let r=await n.verb.run(n.args,n.flags);if(!n.verb.hidden&&n.verb.name!=="uninstall"){if(V2(),n.verb.name!=="update"&&n.verb.name!=="init")Iv(),Hv()}return typeof r==="number"?r:0}catch(n){if(n instanceof Nr)return console.error(n.verb?`ttheme ${n.verb.name}: ${n.message}
782
783
 
783
- ${ym(n.verb)}`:`ttheme: ${n.message} — see \`ttheme help\``),1;if(n instanceof pe)return 1;if(n instanceof mc)return n.exit;let r=process.env.TTHEME_DEBUG&&n instanceof Error?n.stack:void 0;return console.error(`
784
- ttheme${e?` ${e.name}`:""}: ${r??(n instanceof Error?n.message:String(n))}${H_(n)?"\nReport a bug with the output of `ttheme info`":""}`),1}}if(F_)if(process.env.TTHEME_DEBUG&&typeof Bun>"u"&&!process.sourceMapsEnabled){let t=L_(process.execPath,["--enable-source-maps",...process.argv.slice(1)],{stdio:"inherit"});process.exitCode=t.status??1}else process.exitCode=await B2(process.argv.slice(2));
784
+ ${Nm(n.verb)}`:`ttheme: ${n.message} — see \`ttheme help\``),1;if(n instanceof we)return 1;if(n instanceof kc)return n.exit;let r=process.env.TTHEME_DEBUG&&n instanceof Error?n.stack:void 0;return console.error(`
785
+ ttheme${e?` ${e.name}`:""}: ${r??(n instanceof Error?n.message:String(n))}${rB(n)?"\nReport a bug with the output of `ttheme info`":""}`),1}}if(sB)if(process.env.TTHEME_DEBUG&&typeof Bun>"u"&&!process.sourceMapsEnabled){let t=iB(process.execPath,["--enable-source-maps",...process.argv.slice(1)],{stdio:"inherit"});process.exitCode=t.status??1}else process.exitCode=await rO(process.argv.slice(2));
785
786
 
786
- //# debugId=1F17F1CDDB35463864756E2164756E21
787
+ //# debugId=C7575EB23D9953EC64756E2164756E21
787
788
  //# sourceMappingURL=ttheme.js.map