silvery 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ var CI_ENVS=["CI","GITHUB_ACTIONS","GITLAB_CI","JENKINS_URL","BUILDKITE","CIRCLECI","TRAVIS"];function detectColor(stdout){if(process.env.NO_COLOR!==void 0)return null;let forceColor=process.env.FORCE_COLOR;if(forceColor!==void 0){if(forceColor==="0"||forceColor==="false")return null;if(forceColor==="1")return"basic";if(forceColor==="2")return"256";if(forceColor==="3")return"truecolor";return"basic"}if(!stdout.isTTY)return null;if(process.env.TERM==="dumb")return null;let colorTerm=process.env.COLORTERM;if(colorTerm==="truecolor"||colorTerm==="24bit")return"truecolor";let term=process.env.TERM??"";if(term.includes("truecolor")||term.includes("24bit")||term.includes("xterm-ghostty")||term.includes("xterm-kitty")||term.includes("wezterm"))return"truecolor";if(term.includes("256color")||term.includes("256"))return"256";let termProgram=process.env.TERM_PROGRAM;if(termProgram==="iTerm.app"||termProgram==="Apple_Terminal")return termProgram==="iTerm.app"?"truecolor":"256";if(termProgram==="Ghostty"||termProgram==="WezTerm")return"truecolor";if(process.env.KITTY_WINDOW_ID)return"truecolor";if(term.includes("xterm")||term.includes("color")||term.includes("ansi"))return"basic";if(CI_ENVS.some((env)=>process.env[env]!==void 0))return"basic";if(process.env.WT_SESSION)return"truecolor";return"basic"}import stringWidth from"string-width";var MODIFIERS={reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],inverse:[7,27],hidden:[8,28],strikethrough:[9,29],overline:[53,55]},FG_COLORS={black:30,red:31,green:32,yellow:33,blue:34,magenta:35,cyan:36,white:37,blackBright:90,gray:90,grey:90,redBright:91,greenBright:92,yellowBright:93,blueBright:94,magentaBright:95,cyanBright:96,whiteBright:97},BG_COLORS={bgBlack:40,bgRed:41,bgGreen:42,bgYellow:43,bgBlue:44,bgMagenta:45,bgCyan:46,bgWhite:47,bgBlackBright:100,bgGray:100,bgGrey:100,bgRedBright:101,bgGreenBright:102,bgYellowBright:103,bgBlueBright:104,bgMagentaBright:105,bgCyanBright:106,bgWhiteBright:107},ANSI_16_COLORS=[[0,0,0],[128,0,0],[0,128,0],[128,128,0],[0,0,128],[128,0,128],[0,128,128],[192,192,192],[128,128,128],[255,0,0],[0,255,0],[255,255,0],[0,0,255],[255,0,255],[0,255,255],[255,255,255]];function nearestAnsi16(r,g,b){let bestIdx=0,bestDist=1/0;for(let i=0;i<16;i++){let[cr,cg,cb]=ANSI_16_COLORS[i],dist=(r-cr)**2+(g-cg)**2+(b-cb)**2;if(dist<bestDist)bestDist=dist,bestIdx=i}return bestIdx}function rgbToAnsi256(r,g,b){if(r===g&&g===b){if(r<8)return 16;if(r>248)return 231;return Math.round((r-8)/247*24)+232}let ri=Math.round(r/255*5),gi=Math.round(g/255*5),bi=Math.round(b/255*5);return 16+36*ri+6*gi+bi}function fgFromRgb(r,g,b,level){if(level==="truecolor")return`38;2;${r};${g};${b}`;if(level==="256")return`38;5;${rgbToAnsi256(r,g,b)}`;let idx=nearestAnsi16(r,g,b);return idx<8?`${30+idx}`:`${82+idx}`}function bgFromRgb(r,g,b,level){if(level==="truecolor")return`48;2;${r};${g};${b}`;if(level==="256")return`48;5;${rgbToAnsi256(r,g,b)}`;let idx=nearestAnsi16(r,g,b);return idx<8?`${40+idx}`:`${92+idx}`}function hexToRgb(hex){if(hex[0]!=="#")return null;let h=hex.slice(1);if(h.length===3)return[parseInt(h[0]+h[0],16),parseInt(h[1]+h[1],16),parseInt(h[2]+h[2],16)];if(h.length===6)return[parseInt(h.slice(0,2),16),parseInt(h.slice(2,4),16),parseInt(h.slice(4,6),16)];return null}var THEME_TOKEN_DEFAULTS={primary:33,secondary:36,accent:35,error:31,warning:33,success:32,info:36,muted:2,link:34,border:90,surface:37};function resolveToken(name,theme){if(!theme)return;let token=name.startsWith("$")?name.slice(1):name;if(token.startsWith("color")){let idx=parseInt(token.slice(5),10);if(idx>=0&&idx<16&&theme.palette&&idx<theme.palette.length)return theme.palette[idx]}let key=token.replace(/-/g,""),val=theme[key];return typeof val==="string"?val:void 0}var ESC="\x1B[",KNOWN_METHODS=new Set(["hex","rgb","bgHex","bgRgb","ansi256","bgAnsi256","resolve"]),THEME_TOKENS=new Set(["primary","secondary","accent","error","warning","success","info","muted","link","border","surface"]);function fromChalkLevel(n){if(n<=0)return null;if(n===1)return"basic";if(n===2)return"256";return"truecolor"}function toChalkLevel(cl){if(cl===null)return 0;if(cl==="basic")return 1;if(cl==="256")return 2;return 3}function createStyle(options){let ref={level:null,theme:options?.theme};if(options?.level!==void 0)ref.level=options.level;else try{ref.level=detectColor(process.stdout)}catch{ref.level=null}return createChainWithRef({opens:[],closes:[]},ref)}var style=createStyle();function createChainWithRef(state,ref){let proxyRef={proxy:null},proxy=new Proxy(function(){},{apply(_target,_thisArg,args){let level=ref.level;if(state.visible&&level===null)return"";let text;if(args.length===0)text="";else if(Array.isArray(args[0])&&"raw"in args[0])text=String.raw(args[0],...args.slice(1));else if(args.length>1)text=args.map((a)=>String(a??"")).join(" ");else text=String(args[0]??"");if(text==="")return"";if(level===null||state.opens.length===0)return text;let open=`${ESC}${state.opens.join(";")}m`,close=`${ESC}${state.closes.join(";")}m`;for(let closeCode of state.closes){let closeSeq=`${ESC}${closeCode}m`,parts=text.split(closeSeq);if(parts.length>1)text=parts.join(`${closeSeq}${open}`)}if(text.includes(`
2
+ `))text=text.replace(/\r?\n/g,`${close}$&${open}`);return`${open}${text}${close}`},get(_target,prop){if(typeof prop==="symbol")return;if(prop==="level")return toChalkLevel(ref.level);if(prop==="resolve")return(token)=>resolveToken(token,ref.theme);if(prop==="visible")return createChainWithRef({...state,visible:!0},ref);if(prop==="call"||prop==="apply"||prop==="bind")return Function.prototype[prop].bind(proxyRef.proxy);let level=ref.level;if(prop==="hex"||prop==="bgHex")return(color)=>{if(level===null)return createChainWithRef(state,ref);let rgb=hexToRgb(color);if(!rgb)return createChainWithRef(state,ref);let code=prop==="hex"?fgFromRgb(rgb[0],rgb[1],rgb[2],level):bgFromRgb(rgb[0],rgb[1],rgb[2],level),close=prop==="hex"?"39":"49";return createChainWithRef({opens:[...state.opens,code],closes:[...state.closes,close]},ref)};if(prop==="rgb"||prop==="bgRgb")return(r,g,b)=>{if(level===null)return createChainWithRef(state,ref);let code=prop==="rgb"?fgFromRgb(r,g,b,level):bgFromRgb(r,g,b,level),close=prop==="rgb"?"39":"49";return createChainWithRef({opens:[...state.opens,code],closes:[...state.closes,close]},ref)};if(prop==="ansi256")return(code)=>{if(level===null)return createChainWithRef(state,ref);return createChainWithRef({opens:[...state.opens,`38;5;${code}`],closes:[...state.closes,"39"]},ref)};if(prop==="bgAnsi256")return(code)=>{if(level===null)return createChainWithRef(state,ref);return createChainWithRef({opens:[...state.opens,`48;5;${code}`],closes:[...state.closes,"49"]},ref)};if(prop in MODIFIERS){if(level===null)return createChainWithRef(state,ref);let[open,close]=MODIFIERS[prop];return createChainWithRef({opens:[...state.opens,String(open)],closes:[...state.closes,String(close)]},ref)}if(prop in FG_COLORS){if(level===null)return createChainWithRef(state,ref);return createChainWithRef({opens:[...state.opens,String(FG_COLORS[prop])],closes:[...state.closes,"39"]},ref)}if(prop in BG_COLORS){if(level===null)return createChainWithRef(state,ref);return createChainWithRef({opens:[...state.opens,String(BG_COLORS[prop])],closes:[...state.closes,"49"]},ref)}if(THEME_TOKENS.has(prop)){if(level===null)return createChainWithRef(state,ref);let hex=resolveToken(prop,ref.theme);if(hex){let rgb=hexToRgb(hex);if(rgb){let code=fgFromRgb(rgb[0],rgb[1],rgb[2],level);if(prop==="link")return createChainWithRef({opens:[...state.opens,code,"4"],closes:[...state.closes,"39","24"]},ref);return createChainWithRef({opens:[...state.opens,code],closes:[...state.closes,"39"]},ref)}}let fallback=THEME_TOKEN_DEFAULTS[prop];if(fallback!==void 0){if(prop==="muted")return createChainWithRef({opens:[...state.opens,String(fallback)],closes:[...state.closes,"22"]},ref);if(prop==="link")return createChainWithRef({opens:[...state.opens,String(fallback),"4"],closes:[...state.closes,"39","24"]},ref);return createChainWithRef({opens:[...state.opens,String(fallback)],closes:[...state.closes,"39"]},ref)}}return},set(_target,prop,value){if(prop==="level")return ref.level=fromChalkLevel(value),!0;return!1},has(_target,prop){if(prop==="level")return!0;if(typeof prop==="symbol")return!1;return prop in MODIFIERS||prop in FG_COLORS||prop in BG_COLORS||THEME_TOKENS.has(prop)||KNOWN_METHODS.has(prop)}});return proxyRef.proxy=proxy,proxy}function toChalkLevel2(cl){if(cl===null)return 0;if(cl==="basic")return 1;if(cl==="256")return 2;return 3}var detectedColor=typeof process<"u"&&process.stdout?detectColor(process.stdout):null,chalk=createStyle({level:detectedColor}),chalk_default=chalk;var detectedLevel=toChalkLevel2(detectedColor);var supportsColorStderr=(()=>{if(!process?.stderr)return!1;let level=toChalkLevel2(detectColor(process.stderr));return level===0?!1:{level}})();var foregroundColorNames=["black","red","green","yellow","blue","magenta","cyan","white","gray","grey","blackBright","redBright","greenBright","yellowBright","blueBright","magentaBright","cyanBright","whiteBright"],backgroundColorNames=["bgBlack","bgRed","bgGreen","bgYellow","bgBlue","bgMagenta","bgCyan","bgWhite","bgGray","bgGrey","bgBlackBright","bgRedBright","bgGreenBright","bgYellowBright","bgBlueBright","bgMagentaBright","bgCyanBright","bgWhiteBright"],colorNames=[...foregroundColorNames,...backgroundColorNames];var CURSOR_HIDE="\x1B[?25l",CURSOR_SHOW="\x1B[?25h",CURSOR_TO_START="\r",CLEAR_LINE_END="\x1B[K";var cursorUp=(n=1)=>`\x1B[${n}A`;function write(text,stream=process.stdout){stream.write(text)}function isTTY(stream=process.stdout){if(process.env.FORCE_TTY==="1")return!0;return stream.isTTY??!1}function getTerminalWidth(stream=process.stdout){return stream.columns??80}var SPINNER_FRAMES={dots:["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"],line:["-","\\","|","/"],arc:["◜","◠","◝","◞","◡","◟"],bounce:["⠁","⠂","⠄","⠂"],pulse:["█","▓","▒","░","▒","▓"]},SPINNER_INTERVALS={dots:80,line:120,arc:100,bounce:120,pulse:100};class Spinner{text;style;color;stream;hideCursor;interval;frameIndex=0;timer=null;isSpinning=!1;constructor(textOrOptions){let options=typeof textOrOptions==="string"?{text:textOrOptions}:textOrOptions??{};this.text=options.text??"",this.style=options.style??"dots",this.color=options.color??"cyan",this.stream=options.stream??process.stdout,this.hideCursor=options.hideCursor??!0,this.interval=options.interval??SPINNER_INTERVALS[this.style]}get currentText(){return this.text}set currentText(value){if(this.text=value,this.isSpinning)this.render()}get spinning(){return this.isSpinning}start(text){if(text!==void 0)this.text=text;if(this.isSpinning)return this;if(this.isSpinning=!0,this.frameIndex=0,this.hideCursor&&isTTY(this.stream))write(CURSOR_HIDE,this.stream);return this.render(),this.timer=setInterval(()=>{this.frameIndex=(this.frameIndex+1)%SPINNER_FRAMES[this.style].length,this.render()},this.interval),this}stop(){if(!this.isSpinning)return this;if(this.isSpinning=!1,this.timer)clearInterval(this.timer),this.timer=null;if(this.clear(),this.hideCursor&&isTTY(this.stream))write(CURSOR_SHOW,this.stream);return this}succeed(text){return this.stopWithSymbol(chalk_default.green("✔"),text??this.text)}fail(text){return this.stopWithSymbol(chalk_default.red("✖"),text??this.text)}warn(text){return this.stopWithSymbol(chalk_default.yellow("⚠"),text??this.text)}info(text){return this.stopWithSymbol(chalk_default.blue("ℹ"),text??this.text)}clear(){if(isTTY(this.stream))write(`${CURSOR_TO_START}${CLEAR_LINE_END}`,this.stream);return this}render(){let frame=SPINNER_FRAMES[this.style][this.frameIndex],colorFn=chalk_default[this.color],coloredFrame=colorFn?colorFn(frame):frame,output=this.text?`${coloredFrame} ${this.text}`:coloredFrame;if(isTTY(this.stream))write(`${CURSOR_TO_START}${output}${CLEAR_LINE_END}`,this.stream)}stopWithSymbol(symbol,text){return this.stop(),write(`${symbol} ${text}
3
+ `,this.stream),this}[Symbol.dispose](){this.stop()}static start(textOrOptions){let spinner=new Spinner(textOrOptions);return spinner.start(),()=>spinner.stop()}}async function withSpinner(promise,text,options={}){let spinner=new Spinner({text:typeof text==="string"?text:text(0),style:options.style,color:options.color}),timer=null,startTime=Date.now();if(spinner.start(),typeof text==="function")timer=setInterval(()=>{let elapsed=Math.floor((Date.now()-startTime)/1000);spinner.currentText=text(elapsed)},1000);try{let result=await(typeof promise==="function"?promise():promise);if(timer)clearInterval(timer);if(options.clearOnComplete)spinner.stop();else spinner.succeed();return result}catch(error){if(timer)clearInterval(timer);throw spinner.fail(error instanceof Error?error.message:"Failed"),error}}function attachSpinner(promise,text,options={}){let spinner=new Spinner({text,style:options.style,color:options.color});spinner.start();async function wrapPromise(){try{return await promise}catch(error){throw spinner.fail(error instanceof Error?error.message:"Failed"),error}}return[wrapPromise(),spinner]}function calculateETA(buffer,current,total){if(buffer.length<2)return null;let first=buffer[0],last=buffer[buffer.length-1],elapsed=(last.time-first.time)/1000,progress=last.value-first.value;if(elapsed<=0||progress<=0)return null;let rate=progress/elapsed;return(total-current)/rate}function formatETA(eta){if(eta===null||!isFinite(eta))return"--:--";if(eta>86400)return">1d";let hours=Math.floor(eta/3600),minutes=Math.floor(eta%3600/60),seconds=Math.floor(eta%60);if(hours>0)return`${hours}:${minutes.toString().padStart(2,"0")}:${seconds.toString().padStart(2,"0")}`;return`${minutes}:${seconds.toString().padStart(2,"0")}`}var DEFAULT_ETA_BUFFER_SIZE=10;var DEFAULT_FORMAT=":bar :percent | :current/:total | ETA: :eta";class ProgressBar{total;format;width;complete;incomplete;stream;hideCursor;phases;current=0;phase=null;startTime=null;isActive=!1;etaBuffer=[];constructor(options={}){this.total=options.total??100,this.format=options.format??DEFAULT_FORMAT,this.width=options.width??40,this.complete=options.complete??"█",this.incomplete=options.incomplete??"░",this.stream=options.stream??process.stdout,this.hideCursor=options.hideCursor??!0,this.phases=options.phases??{}}start(initialValue=0,initialTotal){if(initialTotal!==void 0)this.total=initialTotal;if(this.current=initialValue,this.startTime=Date.now(),this.isActive=!0,this.etaBuffer=[{time:this.startTime,value:initialValue}],this.hideCursor&&isTTY(this.stream))write(CURSOR_HIDE,this.stream);return this.render(),this}update(value,tokens){this.current=Math.min(value,this.total);let now=Date.now();if(this.etaBuffer.push({time:now,value:this.current}),this.etaBuffer.length>DEFAULT_ETA_BUFFER_SIZE)this.etaBuffer.shift();if(this.isActive)this.render(tokens);return this}increment(amount=1,tokens){return this.update(this.current+amount,tokens)}setPhase(phaseName,options){if(this.phase=phaseName,options?.total!==void 0)this.total=options.total;if(options?.current!==void 0)this.current=options.current,this.etaBuffer=[{time:Date.now(),value:this.current}];if(this.isActive)this.render();return this}stop(clear=!1){if(!this.isActive)return this;if(this.isActive=!1,clear&&isTTY(this.stream))write(`${CURSOR_TO_START}${CLEAR_LINE_END}`,this.stream);else write(`
4
+ `,this.stream);if(this.hideCursor&&isTTY(this.stream))write(CURSOR_SHOW,this.stream);return this}getETASeconds(){return calculateETA(this.etaBuffer,this.current,this.total)}render(tokens){let percent=this.total>0?this.current/this.total:0,eta=this.getETASeconds(),completeLength=Math.round(this.width*percent),incompleteLength=this.width-completeLength,bar=this.complete.repeat(completeLength)+this.incomplete.repeat(incompleteLength),phaseDisplay=this.phase?this.phases[this.phase]??this.phase:"",elapsed=this.startTime?(Date.now()-this.startTime)/1000:0,rate=elapsed>0?this.current/elapsed:0,output=this.format.replace(":bar",chalk_default.cyan(bar)).replace(":percent",`${Math.round(percent*100)}%`.padStart(4)).replace(":current",String(this.current)).replace(":total",String(this.total)).replace(":eta",formatETA(eta)).replace(":elapsed",formatETA(elapsed)).replace(":rate",rate.toFixed(1)).replace(":phase",chalk_default.dim(phaseDisplay));if(tokens)for(let[key,value]of Object.entries(tokens))output=output.replace(`:${key}`,String(value));let termWidth=getTerminalWidth(this.stream);if(output.length>termWidth)output=output.slice(0,termWidth-1);if(isTTY(this.stream))write(`${CURSOR_TO_START}${output}${CLEAR_LINE_END}`,this.stream)}get ratio(){return this.total>0?this.current/this.total:0}get percentage(){return Math.round(this.ratio*100)}[Symbol.dispose](){this.stop()}}async function withProgress(fn,options={}){let stream=process.stdout,isTty=isTTY(stream),format=options.format??(options.phases?":phase [:bar] :current/:total":"[:bar] :current/:total :percent"),bar=new ProgressBar({format,phases:options.phases??{},hideCursor:!0}),lastPhase=null,started=!1,showAfter=options.showAfter??1000,initialMessage=options.initialMessage??"Loading...",spinner=null,spinnerTimerId=null;if(isTty)write(CURSOR_HIDE,stream);if(isTty&&showAfter>=0)spinnerTimerId=setTimeout(()=>{if(!started)spinner=new Spinner({text:initialMessage}),spinner.start()},showAfter);let onProgress=(info)=>{if(spinner)spinner.stop(),spinner=null;if(spinnerTimerId!==null)clearTimeout(spinnerTimerId),spinnerTimerId=null;if(info.phase&&info.phase!==lastPhase){if(lastPhase!==null&&isTty)write(`
5
+ `,stream);if(lastPhase=info.phase,!started)bar.start(info.current,info.total),started=!0;bar.setPhase(info.phase,{current:info.current,total:info.total})}else{if(!started)bar.start(info.current,info.total),started=!0;bar.update(info.current)}};try{let result=await fn(onProgress);if(spinnerTimerId!==null)clearTimeout(spinnerTimerId);let pendingSpinner=spinner;if(pendingSpinner)pendingSpinner.stop();if(started)bar.stop(options.clearOnComplete);if(isTty)write(CURSOR_SHOW,stream);return result}catch(error){if(spinnerTimerId!==null)clearTimeout(spinnerTimerId);let errorSpinner=spinner;if(errorSpinner)errorSpinner.stop();if(started)bar.stop();if(isTty)write(CURSOR_SHOW,stream);throw error}}function createProgressCallback(options={}){let stream=process.stdout,isTty=isTTY(stream),format=options.format??(options.phases?":phase [:bar] :current/:total":"[:bar] :current/:total :percent"),bar=new ProgressBar({format,phases:options.phases??{},hideCursor:!0}),lastPhase=null,started=!1;if(isTty)write(CURSOR_HIDE,stream);return[(info)=>{if(info.phase&&info.phase!==lastPhase){if(lastPhase!==null&&isTty)write(`
6
+ `,stream);if(lastPhase=info.phase,!started)bar.start(info.current,info.total),started=!0;bar.setPhase(info.phase,{current:info.current,total:info.total})}else{if(!started)bar.start(info.current,info.total),started=!0;bar.update(info.current)}},()=>{if(started)bar.stop(options.clearOnComplete);if(isTty)write(CURSOR_SHOW,stream)}]}async function wrapGenerator(generator,textOrFormat,options={}){let stream=process.stdout,isTty=isTTY(stream),label=typeof textOrFormat==="function"?"":textOrFormat,bar=new ProgressBar({format:label?`${label} [:bar] :current/:total :percent`:":bar :current/:total :percent",hideCursor:!0});if(isTty)write(CURSOR_HIDE,stream);let started=!1,result;try{while(!0){if(result=generator.next(),result.done)break;let{current,total}=result.value;if(!started)bar.start(current,total),started=!0;else bar.update(current)}if(started)bar.stop(options.clearOnComplete);if(isTty)write(CURSOR_SHOW,stream);return result.value}catch(error){if(started)bar.stop();if(isTty)write(CURSOR_SHOW,stream);throw error}}async function*withIterableProgress(iterable,label,options={}){let stream=process.stdout,isTty=isTTY(stream),total=(Array.isArray(iterable)?iterable:null)?.length??0,bar=new ProgressBar({format:`${label} [:bar] :current/:total :percent`,total,hideCursor:!0});if(isTty)write(CURSOR_HIDE,stream);let current=0;bar.start(0,total);try{for await(let item of iterable)yield item,current++,bar.update(current);if(bar.stop(options.clearOnComplete),isTty)write(CURSOR_SHOW,stream)}catch(error){if(bar.stop(),isTty)write(CURSOR_SHOW,stream);throw error}}function wrapEmitter(emitter,config){let spinner=new Spinner(config.initialText??""),handlers=new Map;spinner.start();for(let[eventName,eventConfig]of Object.entries(config.events)){let handler=(data)=>{if(eventConfig.getText)spinner.currentText=eventConfig.getText(data);else if(eventConfig.text)spinner.currentText=eventConfig.text;if(eventConfig.succeed)spinner.succeed(),cleanup();else if(eventConfig.fail){let message=data instanceof Error?data.message:String(data??"Failed");spinner.fail(message),cleanup()}else if(eventConfig.stop)spinner.stop(),cleanup()};handlers.set(eventName,handler),emitter.on(eventName,handler)}function cleanup(){for(let[eventName,handler]of handlers)emitter.off(eventName,handler);handlers.clear()}return()=>{spinner.stop(),cleanup()}}async function waitForEvent(emitter,eventName,text,options={}){return new Promise((resolve,reject)=>{let spinner=new Spinner(text);spinner.start();let timer=null,cleanup=()=>{if(emitter.off(eventName,successHandler),options.errorEvent)emitter.off(options.errorEvent,errorHandler);if(timer)clearTimeout(timer)},successHandler=(data)=>{cleanup(),spinner.succeed(),resolve(data)},errorHandler=(error)=>{cleanup(),spinner.fail(error instanceof Error?error.message:"Error"),reject(error instanceof Error?error:Error(String(error)))};if(emitter.once(eventName,successHandler),options.errorEvent)emitter.once(options.errorEvent,errorHandler);if(options.timeout)timer=setTimeout(()=>{cleanup(),spinner.fail("Timeout"),reject(Error(`Timeout waiting for ${eventName}`))},options.timeout)})}async function withSelect(prompt,options,selectOptions={}){let{initial=0,maxVisible=10}=selectOptions,stream=process.stdout,stdin=process.stdin;if(!isTTY(stream)||!stdin.isTTY)return options[initial]?.value??options[0].value;return new Promise((resolve,reject)=>{let highlightIndex=Math.min(Math.max(0,initial),options.length-1),linesRendered=0;stdin.setRawMode(!0),stdin.resume(),stdin.setEncoding("utf8"),write(CURSOR_HIDE,stream);function render(){if(linesRendered>0)write(cursorUp(linesRendered),stream);let scrollOffset=Math.max(0,Math.min(highlightIndex-Math.floor(maxVisible/2),options.length-maxVisible)),visibleCount=Math.min(maxVisible,options.length),visibleOptions=options.slice(scrollOffset,scrollOffset+visibleCount),hasMoreAbove=scrollOffset>0,hasMoreBelow=scrollOffset+visibleCount<options.length;write(`${CURSOR_TO_START}${chalk_default.bold(prompt)}${CLEAR_LINE_END}
7
+ `,stream);let lines=1;if(hasMoreAbove)write(`${CURSOR_TO_START} ${chalk_default.dim("...")}${CLEAR_LINE_END}
8
+ `,stream),lines++;for(let i=0;i<visibleOptions.length;i++){let option=visibleOptions[i],isHighlighted=scrollOffset+i===highlightIndex,indicator=isHighlighted?chalk_default.cyan(">"):" ",label=isHighlighted?chalk_default.cyan(option.label):option.label;write(`${CURSOR_TO_START}${indicator} ${label}${CLEAR_LINE_END}
9
+ `,stream),lines++}if(hasMoreBelow)write(`${CURSOR_TO_START} ${chalk_default.dim("...")}${CLEAR_LINE_END}
10
+ `,stream),lines++;linesRendered=lines}function cleanup(){stdin.setRawMode(!1),stdin.pause(),stdin.removeListener("data",onKeypress),write(CURSOR_SHOW,stream)}function onKeypress(key){let keyCode=key.charCodeAt(0);if(key==="\x03"){cleanup(),reject(Error("User cancelled"));return}if(key==="\r"||key===`
11
+ `){cleanup(),resolve(options[highlightIndex].value);return}if(key==="\x1B"&&key.length===1){cleanup(),reject(Error("User cancelled"));return}if(key.startsWith("\x1B[")){let code=key.slice(2);if(code==="A")highlightIndex=Math.max(0,highlightIndex-1),render();else if(code==="B")highlightIndex=Math.min(options.length-1,highlightIndex+1),render();return}if(key==="j"||key==="J"){highlightIndex=Math.min(options.length-1,highlightIndex+1),render();return}if(key==="k"||key==="K"){highlightIndex=Math.max(0,highlightIndex-1),render();return}if(key===" "){cleanup(),resolve(options[highlightIndex].value);return}}stdin.on("data",onKeypress),render()})}function createSelect(defaultOptions={}){return(prompt,options,overrides={})=>withSelect(prompt,options,{...defaultOptions,...overrides})}async function withTextInput(prompt,options={}){let stream=options.stream??process.stdout,inputStream=options.inputStream??process.stdin,isTty=isTTY(stream),value=options.defaultValue??"",cursorPosition=value.length,errorMessage;if(inputStream.isTTY)inputStream.setRawMode(!0);inputStream.resume();let render=()=>{let displayValue=options.mask?options.mask.repeat(value.length):value,suggestion=getAutocompleteSuggestion(value,options.autocomplete),suggestionSuffix=suggestion?chalk_default.dim(suggestion.slice(value.length)):"",beforeCursor=displayValue.slice(0,cursorPosition),cursorChar=displayValue[cursorPosition]??" ",afterCursor=displayValue.slice(cursorPosition+1),inputDisplay=!value&&options.placeholder?chalk_default.dim(options.placeholder)+chalk_default.inverse(" "):beforeCursor+chalk_default.inverse(cursorChar)+afterCursor+suggestionSuffix,errorDisplay=errorMessage?chalk_default.red(` (${errorMessage})`):"",line=`${chalk_default.cyan("?")} ${chalk_default.bold(prompt)} ${inputDisplay}${errorDisplay}`;if(isTty)write(`${CURSOR_TO_START}${line}${CLEAR_LINE_END}`,stream)};if(isTty)write(CURSOR_HIDE,stream);return render(),new Promise((resolve,reject)=>{let cleanup=()=>{if(inputStream.removeListener("data",onData),inputStream.removeListener("error",onError),inputStream.isTTY)inputStream.setRawMode(!1);if(inputStream.pause(),isTty)write(CURSOR_SHOW,stream)},submit=()=>{if(options.validate){let error=options.validate(value);if(error){errorMessage=error,render();return}}cleanup();let displayValue=options.mask?options.mask.repeat(value.length):value;write(`${CURSOR_TO_START}${chalk_default.green("✔")} ${chalk_default.bold(prompt)} ${chalk_default.dim(displayValue)}${CLEAR_LINE_END}
12
+ `,stream),resolve(value)},onError=(err)=>{cleanup(),reject(err)},onData=(data)=>{let input=data.toString();errorMessage=void 0;for(let i=0;i<input.length;i++){let char=input[i],code=char.charCodeAt(0);if(code===13||code===10){submit();return}if(code===3){cleanup(),write(`
13
+ `,stream),reject(Error("User aborted"));return}if(code===27){if(input[i+1]==="["){let arrowCode=input[i+2];if(arrowCode==="D"){cursorPosition=Math.max(0,cursorPosition-1),i+=2;continue}if(arrowCode==="C"){cursorPosition=Math.min(value.length,cursorPosition+1),i+=2;continue}if(arrowCode==="H"){cursorPosition=0,i+=2;continue}if(arrowCode==="F"){cursorPosition=value.length,i+=2;continue}i+=2;continue}value="",cursorPosition=0;continue}if(code===127||code===8){if(cursorPosition>0)value=value.slice(0,cursorPosition-1)+value.slice(cursorPosition),cursorPosition--;continue}if(code===4){if(cursorPosition<value.length)value=value.slice(0,cursorPosition)+value.slice(cursorPosition+1);continue}if(code===9){let suggestion=getAutocompleteSuggestion(value,options.autocomplete);if(suggestion)value=suggestion,cursorPosition=value.length;continue}if(code===1){cursorPosition=0;continue}if(code===5){cursorPosition=value.length;continue}if(code===21){value=value.slice(cursorPosition),cursorPosition=0;continue}if(code===11){value=value.slice(0,cursorPosition);continue}if(code===23){let before=value.slice(0,cursorPosition),after=value.slice(cursorPosition),trimmed=before.trimEnd(),lastSpace=trimmed.lastIndexOf(" "),newBefore=lastSpace===-1?"":trimmed.slice(0,lastSpace+1);value=newBefore+after,cursorPosition=newBefore.length;continue}if(code>=32&&code<127){value=value.slice(0,cursorPosition)+char+value.slice(cursorPosition),cursorPosition++;continue}if(code>127){value=value.slice(0,cursorPosition)+char+value.slice(cursorPosition),cursorPosition++;continue}}render()};inputStream.on("data",onData),inputStream.on("error",onError)})}function createTextInput(prompt,options={}){let stream=options.stream??process.stdout,isTty=isTTY(stream),value=options.defaultValue??"",cursorPosition=value.length;return{get value(){return value},set value(v){value=v,cursorPosition=Math.min(cursorPosition,v.length)},get cursorPosition(){return cursorPosition},set cursorPosition(pos){cursorPosition=Math.max(0,Math.min(value.length,pos))},render:()=>{let displayValue=options.mask?options.mask.repeat(value.length):value,suggestion=getAutocompleteSuggestion(value,options.autocomplete),suggestionSuffix=suggestion?chalk_default.dim(suggestion.slice(value.length)):"",beforeCursor=displayValue.slice(0,cursorPosition),cursorChar=displayValue[cursorPosition]??" ",afterCursor=displayValue.slice(cursorPosition+1),inputDisplay=!value&&options.placeholder?chalk_default.dim(options.placeholder)+chalk_default.inverse(" "):beforeCursor+chalk_default.inverse(cursorChar)+afterCursor+suggestionSuffix,line=`${chalk_default.cyan("?")} ${chalk_default.bold(prompt)} ${inputDisplay}`;if(isTty)write(`${CURSOR_TO_START}${line}${CLEAR_LINE_END}`,stream)},insert(char){value=value.slice(0,cursorPosition)+char+value.slice(cursorPosition),cursorPosition+=char.length},backspace(){if(cursorPosition>0)value=value.slice(0,cursorPosition-1)+value.slice(cursorPosition),cursorPosition--},delete(){if(cursorPosition<value.length)value=value.slice(0,cursorPosition)+value.slice(cursorPosition+1)},clear(){value="",cursorPosition=0},acceptSuggestion(){let suggestion=getAutocompleteSuggestion(value,options.autocomplete);if(suggestion)value=suggestion,cursorPosition=value.length}}}function getAutocompleteSuggestion(value,autocomplete){if(!value||!autocomplete?.length)return;let lowerValue=value.toLowerCase();return autocomplete.find((item)=>item.toLowerCase().startsWith(lowerValue)&&item.length>value.length)}export{wrapGenerator,wrapEmitter,withTextInput,withSpinner,withSelect,withProgress,withIterableProgress,waitForEvent,createTextInput,createSelect,createProgressCallback,attachSpinner};
14
+
15
+ //# debugId=932FC8FC0518EC6764756E2164756E21
package/dist/ui.js ADDED
@@ -0,0 +1,18 @@
1
+ var CI_ENVS=["CI","GITHUB_ACTIONS","GITLAB_CI","JENKINS_URL","BUILDKITE","CIRCLECI","TRAVIS"];function detectColor(stdout){if(process.env.NO_COLOR!==void 0)return null;let forceColor=process.env.FORCE_COLOR;if(forceColor!==void 0){if(forceColor==="0"||forceColor==="false")return null;if(forceColor==="1")return"basic";if(forceColor==="2")return"256";if(forceColor==="3")return"truecolor";return"basic"}if(!stdout.isTTY)return null;if(process.env.TERM==="dumb")return null;let colorTerm=process.env.COLORTERM;if(colorTerm==="truecolor"||colorTerm==="24bit")return"truecolor";let term=process.env.TERM??"";if(term.includes("truecolor")||term.includes("24bit")||term.includes("xterm-ghostty")||term.includes("xterm-kitty")||term.includes("wezterm"))return"truecolor";if(term.includes("256color")||term.includes("256"))return"256";let termProgram=process.env.TERM_PROGRAM;if(termProgram==="iTerm.app"||termProgram==="Apple_Terminal")return termProgram==="iTerm.app"?"truecolor":"256";if(termProgram==="Ghostty"||termProgram==="WezTerm")return"truecolor";if(process.env.KITTY_WINDOW_ID)return"truecolor";if(term.includes("xterm")||term.includes("color")||term.includes("ansi"))return"basic";if(CI_ENVS.some((env)=>process.env[env]!==void 0))return"basic";if(process.env.WT_SESSION)return"truecolor";return"basic"}import stringWidth from"string-width";var MODIFIERS={reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],inverse:[7,27],hidden:[8,28],strikethrough:[9,29],overline:[53,55]},FG_COLORS={black:30,red:31,green:32,yellow:33,blue:34,magenta:35,cyan:36,white:37,blackBright:90,gray:90,grey:90,redBright:91,greenBright:92,yellowBright:93,blueBright:94,magentaBright:95,cyanBright:96,whiteBright:97},BG_COLORS={bgBlack:40,bgRed:41,bgGreen:42,bgYellow:43,bgBlue:44,bgMagenta:45,bgCyan:46,bgWhite:47,bgBlackBright:100,bgGray:100,bgGrey:100,bgRedBright:101,bgGreenBright:102,bgYellowBright:103,bgBlueBright:104,bgMagentaBright:105,bgCyanBright:106,bgWhiteBright:107},ANSI_16_COLORS=[[0,0,0],[128,0,0],[0,128,0],[128,128,0],[0,0,128],[128,0,128],[0,128,128],[192,192,192],[128,128,128],[255,0,0],[0,255,0],[255,255,0],[0,0,255],[255,0,255],[0,255,255],[255,255,255]];function nearestAnsi16(r,g,b){let bestIdx=0,bestDist=1/0;for(let i=0;i<16;i++){let[cr,cg,cb]=ANSI_16_COLORS[i],dist=(r-cr)**2+(g-cg)**2+(b-cb)**2;if(dist<bestDist)bestDist=dist,bestIdx=i}return bestIdx}function rgbToAnsi256(r,g,b){if(r===g&&g===b){if(r<8)return 16;if(r>248)return 231;return Math.round((r-8)/247*24)+232}let ri=Math.round(r/255*5),gi=Math.round(g/255*5),bi=Math.round(b/255*5);return 16+36*ri+6*gi+bi}function fgFromRgb(r,g,b,level){if(level==="truecolor")return`38;2;${r};${g};${b}`;if(level==="256")return`38;5;${rgbToAnsi256(r,g,b)}`;let idx=nearestAnsi16(r,g,b);return idx<8?`${30+idx}`:`${82+idx}`}function bgFromRgb(r,g,b,level){if(level==="truecolor")return`48;2;${r};${g};${b}`;if(level==="256")return`48;5;${rgbToAnsi256(r,g,b)}`;let idx=nearestAnsi16(r,g,b);return idx<8?`${40+idx}`:`${92+idx}`}function hexToRgb(hex){if(hex[0]!=="#")return null;let h=hex.slice(1);if(h.length===3)return[parseInt(h[0]+h[0],16),parseInt(h[1]+h[1],16),parseInt(h[2]+h[2],16)];if(h.length===6)return[parseInt(h.slice(0,2),16),parseInt(h.slice(2,4),16),parseInt(h.slice(4,6),16)];return null}var THEME_TOKEN_DEFAULTS={primary:33,secondary:36,accent:35,error:31,warning:33,success:32,info:36,muted:2,link:34,border:90,surface:37};function resolveToken(name,theme){if(!theme)return;let token=name.startsWith("$")?name.slice(1):name;if(token.startsWith("color")){let idx=parseInt(token.slice(5),10);if(idx>=0&&idx<16&&theme.palette&&idx<theme.palette.length)return theme.palette[idx]}let key=token.replace(/-/g,""),val=theme[key];return typeof val==="string"?val:void 0}var ESC="\x1B[",KNOWN_METHODS=new Set(["hex","rgb","bgHex","bgRgb","ansi256","bgAnsi256","resolve"]),THEME_TOKENS=new Set(["primary","secondary","accent","error","warning","success","info","muted","link","border","surface"]);function fromChalkLevel(n){if(n<=0)return null;if(n===1)return"basic";if(n===2)return"256";return"truecolor"}function toChalkLevel(cl){if(cl===null)return 0;if(cl==="basic")return 1;if(cl==="256")return 2;return 3}function createStyle(options){let ref={level:null,theme:options?.theme};if(options?.level!==void 0)ref.level=options.level;else try{ref.level=detectColor(process.stdout)}catch{ref.level=null}return createChainWithRef({opens:[],closes:[]},ref)}var style=createStyle();function createChainWithRef(state,ref){let proxyRef={proxy:null},proxy=new Proxy(function(){},{apply(_target,_thisArg,args){let level=ref.level;if(state.visible&&level===null)return"";let text;if(args.length===0)text="";else if(Array.isArray(args[0])&&"raw"in args[0])text=String.raw(args[0],...args.slice(1));else if(args.length>1)text=args.map((a)=>String(a??"")).join(" ");else text=String(args[0]??"");if(text==="")return"";if(level===null||state.opens.length===0)return text;let open=`${ESC}${state.opens.join(";")}m`,close=`${ESC}${state.closes.join(";")}m`;for(let closeCode of state.closes){let closeSeq=`${ESC}${closeCode}m`,parts=text.split(closeSeq);if(parts.length>1)text=parts.join(`${closeSeq}${open}`)}if(text.includes(`
2
+ `))text=text.replace(/\r?\n/g,`${close}$&${open}`);return`${open}${text}${close}`},get(_target,prop){if(typeof prop==="symbol")return;if(prop==="level")return toChalkLevel(ref.level);if(prop==="resolve")return(token)=>resolveToken(token,ref.theme);if(prop==="visible")return createChainWithRef({...state,visible:!0},ref);if(prop==="call"||prop==="apply"||prop==="bind")return Function.prototype[prop].bind(proxyRef.proxy);let level=ref.level;if(prop==="hex"||prop==="bgHex")return(color)=>{if(level===null)return createChainWithRef(state,ref);let rgb=hexToRgb(color);if(!rgb)return createChainWithRef(state,ref);let code=prop==="hex"?fgFromRgb(rgb[0],rgb[1],rgb[2],level):bgFromRgb(rgb[0],rgb[1],rgb[2],level),close=prop==="hex"?"39":"49";return createChainWithRef({opens:[...state.opens,code],closes:[...state.closes,close]},ref)};if(prop==="rgb"||prop==="bgRgb")return(r,g,b)=>{if(level===null)return createChainWithRef(state,ref);let code=prop==="rgb"?fgFromRgb(r,g,b,level):bgFromRgb(r,g,b,level),close=prop==="rgb"?"39":"49";return createChainWithRef({opens:[...state.opens,code],closes:[...state.closes,close]},ref)};if(prop==="ansi256")return(code)=>{if(level===null)return createChainWithRef(state,ref);return createChainWithRef({opens:[...state.opens,`38;5;${code}`],closes:[...state.closes,"39"]},ref)};if(prop==="bgAnsi256")return(code)=>{if(level===null)return createChainWithRef(state,ref);return createChainWithRef({opens:[...state.opens,`48;5;${code}`],closes:[...state.closes,"49"]},ref)};if(prop in MODIFIERS){if(level===null)return createChainWithRef(state,ref);let[open,close]=MODIFIERS[prop];return createChainWithRef({opens:[...state.opens,String(open)],closes:[...state.closes,String(close)]},ref)}if(prop in FG_COLORS){if(level===null)return createChainWithRef(state,ref);return createChainWithRef({opens:[...state.opens,String(FG_COLORS[prop])],closes:[...state.closes,"39"]},ref)}if(prop in BG_COLORS){if(level===null)return createChainWithRef(state,ref);return createChainWithRef({opens:[...state.opens,String(BG_COLORS[prop])],closes:[...state.closes,"49"]},ref)}if(THEME_TOKENS.has(prop)){if(level===null)return createChainWithRef(state,ref);let hex=resolveToken(prop,ref.theme);if(hex){let rgb=hexToRgb(hex);if(rgb){let code=fgFromRgb(rgb[0],rgb[1],rgb[2],level);if(prop==="link")return createChainWithRef({opens:[...state.opens,code,"4"],closes:[...state.closes,"39","24"]},ref);return createChainWithRef({opens:[...state.opens,code],closes:[...state.closes,"39"]},ref)}}let fallback=THEME_TOKEN_DEFAULTS[prop];if(fallback!==void 0){if(prop==="muted")return createChainWithRef({opens:[...state.opens,String(fallback)],closes:[...state.closes,"22"]},ref);if(prop==="link")return createChainWithRef({opens:[...state.opens,String(fallback),"4"],closes:[...state.closes,"39","24"]},ref);return createChainWithRef({opens:[...state.opens,String(fallback)],closes:[...state.closes,"39"]},ref)}}return},set(_target,prop,value){if(prop==="level")return ref.level=fromChalkLevel(value),!0;return!1},has(_target,prop){if(prop==="level")return!0;if(typeof prop==="symbol")return!1;return prop in MODIFIERS||prop in FG_COLORS||prop in BG_COLORS||THEME_TOKENS.has(prop)||KNOWN_METHODS.has(prop)}});return proxyRef.proxy=proxy,proxy}function toChalkLevel2(cl){if(cl===null)return 0;if(cl==="basic")return 1;if(cl==="256")return 2;return 3}var detectedColor=typeof process<"u"&&process.stdout?detectColor(process.stdout):null,chalk=createStyle({level:detectedColor}),chalk_default=chalk;var detectedLevel=toChalkLevel2(detectedColor);var supportsColorStderr=(()=>{if(!process?.stderr)return!1;let level=toChalkLevel2(detectColor(process.stderr));return level===0?!1:{level}})();var foregroundColorNames=["black","red","green","yellow","blue","magenta","cyan","white","gray","grey","blackBright","redBright","greenBright","yellowBright","blueBright","magentaBright","cyanBright","whiteBright"],backgroundColorNames=["bgBlack","bgRed","bgGreen","bgYellow","bgBlue","bgMagenta","bgCyan","bgWhite","bgGray","bgGrey","bgBlackBright","bgRedBright","bgGreenBright","bgYellowBright","bgBlueBright","bgMagentaBright","bgCyanBright","bgWhiteBright"],colorNames=[...foregroundColorNames,...backgroundColorNames];var CURSOR_HIDE="\x1B[?25l",CURSOR_SHOW="\x1B[?25h",CURSOR_TO_START="\r",CLEAR_LINE_END="\x1B[K",CLEAR_LINE="\x1B[2K",CLEAR_SCREEN="\x1B[2J\x1B[H",cursorUp=(n=1)=>`\x1B[${n}A`,cursorDown=(n=1)=>`\x1B[${n}B`,CURSOR_SAVE="\x1B[s",CURSOR_RESTORE="\x1B[u";function write(text,stream=process.stdout){stream.write(text)}function writeLine(text,stream=process.stdout){stream.write(`\r${text}\x1B[K`)}function withCursor(fn,stream=process.stdout){stream.write("\x1B[?25l");let restore=()=>stream.write("\x1B[?25h");try{let result=fn();if(result instanceof Promise)return result.finally(restore);return restore(),Promise.resolve(result)}catch(error){throw restore(),error}}function isTTY(stream=process.stdout){if(process.env.FORCE_TTY==="1")return!0;return stream.isTTY??!1}function getTerminalWidth(stream=process.stdout){return stream.columns??80}var SPINNER_FRAMES={dots:["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"],line:["-","\\","|","/"],arc:["◜","◠","◝","◞","◡","◟"],bounce:["⠁","⠂","⠄","⠂"],pulse:["█","▓","▒","░","▒","▓"]},SPINNER_INTERVALS={dots:80,line:120,arc:100,bounce:120,pulse:100};class Spinner{text;style;color;stream;hideCursor;interval;frameIndex=0;timer=null;isSpinning=!1;constructor(textOrOptions){let options=typeof textOrOptions==="string"?{text:textOrOptions}:textOrOptions??{};this.text=options.text??"",this.style=options.style??"dots",this.color=options.color??"cyan",this.stream=options.stream??process.stdout,this.hideCursor=options.hideCursor??!0,this.interval=options.interval??SPINNER_INTERVALS[this.style]}get currentText(){return this.text}set currentText(value){if(this.text=value,this.isSpinning)this.render()}get spinning(){return this.isSpinning}start(text){if(text!==void 0)this.text=text;if(this.isSpinning)return this;if(this.isSpinning=!0,this.frameIndex=0,this.hideCursor&&isTTY(this.stream))write(CURSOR_HIDE,this.stream);return this.render(),this.timer=setInterval(()=>{this.frameIndex=(this.frameIndex+1)%SPINNER_FRAMES[this.style].length,this.render()},this.interval),this}stop(){if(!this.isSpinning)return this;if(this.isSpinning=!1,this.timer)clearInterval(this.timer),this.timer=null;if(this.clear(),this.hideCursor&&isTTY(this.stream))write(CURSOR_SHOW,this.stream);return this}succeed(text){return this.stopWithSymbol(chalk_default.green("✔"),text??this.text)}fail(text){return this.stopWithSymbol(chalk_default.red("✖"),text??this.text)}warn(text){return this.stopWithSymbol(chalk_default.yellow("⚠"),text??this.text)}info(text){return this.stopWithSymbol(chalk_default.blue("ℹ"),text??this.text)}clear(){if(isTTY(this.stream))write(`${CURSOR_TO_START}${CLEAR_LINE_END}`,this.stream);return this}render(){let frame=SPINNER_FRAMES[this.style][this.frameIndex],colorFn=chalk_default[this.color],coloredFrame=colorFn?colorFn(frame):frame,output=this.text?`${coloredFrame} ${this.text}`:coloredFrame;if(isTTY(this.stream))write(`${CURSOR_TO_START}${output}${CLEAR_LINE_END}`,this.stream)}stopWithSymbol(symbol,text){return this.stop(),write(`${symbol} ${text}
3
+ `,this.stream),this}[Symbol.dispose](){this.stop()}static start(textOrOptions){let spinner=new Spinner(textOrOptions);return spinner.start(),()=>spinner.stop()}}function createSpinner(options){let spinner=new Spinner({...options,text:""}),callable=(text)=>{if(!spinner.spinning)spinner.start(text);else spinner.currentText=text};return callable.stop=()=>spinner.stop(),callable.succeed=(text)=>spinner.succeed(text),callable.fail=(text)=>spinner.fail(text),callable.warn=(text)=>spinner.warn(text),callable.info=(text)=>spinner.info(text),callable[Symbol.dispose]=()=>spinner.stop(),callable}function calculateETA(buffer,current,total){if(buffer.length<2)return null;let first=buffer[0],last=buffer[buffer.length-1],elapsed=(last.time-first.time)/1000,progress=last.value-first.value;if(elapsed<=0||progress<=0)return null;let rate=progress/elapsed;return(total-current)/rate}function formatETA(eta){if(eta===null||!isFinite(eta))return"--:--";if(eta>86400)return">1d";let hours=Math.floor(eta/3600),minutes=Math.floor(eta%3600/60),seconds=Math.floor(eta%60);if(hours>0)return`${hours}:${minutes.toString().padStart(2,"0")}:${seconds.toString().padStart(2,"0")}`;return`${minutes}:${seconds.toString().padStart(2,"0")}`}var DEFAULT_ETA_BUFFER_SIZE=10;var DEFAULT_FORMAT=":bar :percent | :current/:total | ETA: :eta";class ProgressBar{total;format;width;complete;incomplete;stream;hideCursor;phases;current=0;phase=null;startTime=null;isActive=!1;etaBuffer=[];constructor(options={}){this.total=options.total??100,this.format=options.format??DEFAULT_FORMAT,this.width=options.width??40,this.complete=options.complete??"█",this.incomplete=options.incomplete??"░",this.stream=options.stream??process.stdout,this.hideCursor=options.hideCursor??!0,this.phases=options.phases??{}}start(initialValue=0,initialTotal){if(initialTotal!==void 0)this.total=initialTotal;if(this.current=initialValue,this.startTime=Date.now(),this.isActive=!0,this.etaBuffer=[{time:this.startTime,value:initialValue}],this.hideCursor&&isTTY(this.stream))write(CURSOR_HIDE,this.stream);return this.render(),this}update(value,tokens){this.current=Math.min(value,this.total);let now=Date.now();if(this.etaBuffer.push({time:now,value:this.current}),this.etaBuffer.length>DEFAULT_ETA_BUFFER_SIZE)this.etaBuffer.shift();if(this.isActive)this.render(tokens);return this}increment(amount=1,tokens){return this.update(this.current+amount,tokens)}setPhase(phaseName,options){if(this.phase=phaseName,options?.total!==void 0)this.total=options.total;if(options?.current!==void 0)this.current=options.current,this.etaBuffer=[{time:Date.now(),value:this.current}];if(this.isActive)this.render();return this}stop(clear=!1){if(!this.isActive)return this;if(this.isActive=!1,clear&&isTTY(this.stream))write(`${CURSOR_TO_START}${CLEAR_LINE_END}`,this.stream);else write(`
4
+ `,this.stream);if(this.hideCursor&&isTTY(this.stream))write(CURSOR_SHOW,this.stream);return this}getETASeconds(){return calculateETA(this.etaBuffer,this.current,this.total)}render(tokens){let percent=this.total>0?this.current/this.total:0,eta=this.getETASeconds(),completeLength=Math.round(this.width*percent),incompleteLength=this.width-completeLength,bar=this.complete.repeat(completeLength)+this.incomplete.repeat(incompleteLength),phaseDisplay=this.phase?this.phases[this.phase]??this.phase:"",elapsed=this.startTime?(Date.now()-this.startTime)/1000:0,rate=elapsed>0?this.current/elapsed:0,output=this.format.replace(":bar",chalk_default.cyan(bar)).replace(":percent",`${Math.round(percent*100)}%`.padStart(4)).replace(":current",String(this.current)).replace(":total",String(this.total)).replace(":eta",formatETA(eta)).replace(":elapsed",formatETA(elapsed)).replace(":rate",rate.toFixed(1)).replace(":phase",chalk_default.dim(phaseDisplay));if(tokens)for(let[key,value]of Object.entries(tokens))output=output.replace(`:${key}`,String(value));let termWidth=getTerminalWidth(this.stream);if(output.length>termWidth)output=output.slice(0,termWidth-1);if(isTTY(this.stream))write(`${CURSOR_TO_START}${output}${CLEAR_LINE_END}`,this.stream)}get ratio(){return this.total>0?this.current/this.total:0}get percentage(){return Math.round(this.ratio*100)}[Symbol.dispose](){this.stop()}}var STATUS_ICONS={pending:chalk_default.gray("○"),running:"",completed:chalk_default.green("✔"),failed:chalk_default.red("✖"),skipped:chalk_default.yellow("⊘")};class MultiProgress{tasks=new Map;taskOrder=[];stream;isActive=!1;timer=null;frameIndex=0;renderedLines=0;constructor(stream=process.stdout){this.stream=stream}add(title,options={}){let id=`task-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,task={id,title,type:options.type??"spinner",status:"pending",total:options.total,current:0,spinnerStyle:options.spinnerStyle??"dots",indent:options.indent??0};if(this.tasks.set(id,task),options.insertAfter){let afterIndex=this.taskOrder.indexOf(options.insertAfter);if(afterIndex>=0)this.taskOrder.splice(afterIndex+1,0,id);else this.taskOrder.push(id)}else this.taskOrder.push(id);if(this.isActive)this.render();return new TaskHandle(this,id)}start(){if(this.isActive)return this;if(this.isActive=!0,isTTY(this.stream))write(CURSOR_HIDE,this.stream);return this.render(),this.timer=setInterval(()=>{this.frameIndex=(this.frameIndex+1)%10,this.render()},80),this}[Symbol.dispose](){this.stop()}stop(clear=!1){if(!this.isActive)return this;if(this.isActive=!1,this.timer)clearInterval(this.timer),this.timer=null;if(clear&&isTTY(this.stream)){if(this.renderedLines>0){write(cursorUp(this.renderedLines),this.stream);for(let i=0;i<this.renderedLines;i++)write(`${CLEAR_LINE}
5
+ `,this.stream);write(cursorUp(this.renderedLines),this.stream)}}else this.render(),write(`
6
+ `,this.stream);if(isTTY(this.stream))write(CURSOR_SHOW,this.stream);return this}_updateTask(id,updates){let task=this.tasks.get(id);if(task){if(Object.assign(task,updates),this.isActive&&updates.status)this.render()}}_getTask(id){return this.tasks.get(id)}render(){if(!isTTY(this.stream))return;if(this.renderedLines>0)write(cursorUp(this.renderedLines),this.stream);let lines=[];for(let id of this.taskOrder){let task=this.tasks.get(id);if(!task)continue;let icon;if(task.status==="running")if(task.type==="group")icon=STATUS_ICONS.pending;else{let frames=SPINNER_FRAMES[task.spinnerStyle??"dots"];icon=chalk_default.cyan(frames[this.frameIndex%frames.length])}else icon=STATUS_ICONS[task.status];let line=`${" ".repeat(task.indent??0)}${icon} ${task.title}`;if(task.type==="bar"&&task.total&&task.total>0){let percent=task.current/task.total,barWidth=20,filled=Math.round(20*percent),empty=20-filled,bar=chalk_default.cyan("█".repeat(filled))+chalk_default.gray("░".repeat(empty));line+=` ${bar} ${Math.round(percent*100)}%`}if(task.status==="completed"&&task.completionTime!==void 0)line+=chalk_default.dim(` ${task.completionTime}ms`);lines.push(line)}for(let line of lines)write(`${CLEAR_LINE}${line}
7
+ `,this.stream);this.renderedLines=lines.length}}class TaskHandle{multi;_id;constructor(multi,_id){this.multi=multi;this._id=_id}get id(){return this._id}start(){return this.multi._updateTask(this._id,{status:"running"}),this}update(current){return this.multi._updateTask(this._id,{current}),this}complete(titleOrTime){let updates={status:"completed"};if(typeof titleOrTime==="number")updates.completionTime=titleOrTime;else if(titleOrTime)updates.title=titleOrTime;return this.multi._updateTask(this._id,updates),this}fail(title){let updates={status:"failed"};if(title)updates.title=title;return this.multi._updateTask(this._id,updates),this}skip(title){let updates={status:"skipped"};if(title)updates.title=title;return this.multi._updateTask(this._id,updates),this}setTitle(title){return this.multi._updateTask(this._id,{title}),this}setType(type){return this.multi._updateTask(this._id,{type}),this}get status(){return this.multi._getTask(this._id)?.status??"pending"}}async function withSpinner(promise,text,options={}){let spinner=new Spinner({text:typeof text==="string"?text:text(0),style:options.style,color:options.color}),timer=null,startTime=Date.now();if(spinner.start(),typeof text==="function")timer=setInterval(()=>{let elapsed=Math.floor((Date.now()-startTime)/1000);spinner.currentText=text(elapsed)},1000);try{let result=await(typeof promise==="function"?promise():promise);if(timer)clearInterval(timer);if(options.clearOnComplete)spinner.stop();else spinner.succeed();return result}catch(error){if(timer)clearInterval(timer);throw spinner.fail(error instanceof Error?error.message:"Failed"),error}}function attachSpinner(promise,text,options={}){let spinner=new Spinner({text,style:options.style,color:options.color});spinner.start();async function wrapPromise(){try{return await promise}catch(error){throw spinner.fail(error instanceof Error?error.message:"Failed"),error}}return[wrapPromise(),spinner]}async function withProgress(fn,options={}){let stream=process.stdout,isTty=isTTY(stream),format=options.format??(options.phases?":phase [:bar] :current/:total":"[:bar] :current/:total :percent"),bar=new ProgressBar({format,phases:options.phases??{},hideCursor:!0}),lastPhase=null,started=!1,showAfter=options.showAfter??1000,initialMessage=options.initialMessage??"Loading...",spinner=null,spinnerTimerId=null;if(isTty)write(CURSOR_HIDE,stream);if(isTty&&showAfter>=0)spinnerTimerId=setTimeout(()=>{if(!started)spinner=new Spinner({text:initialMessage}),spinner.start()},showAfter);let onProgress=(info)=>{if(spinner)spinner.stop(),spinner=null;if(spinnerTimerId!==null)clearTimeout(spinnerTimerId),spinnerTimerId=null;if(info.phase&&info.phase!==lastPhase){if(lastPhase!==null&&isTty)write(`
8
+ `,stream);if(lastPhase=info.phase,!started)bar.start(info.current,info.total),started=!0;bar.setPhase(info.phase,{current:info.current,total:info.total})}else{if(!started)bar.start(info.current,info.total),started=!0;bar.update(info.current)}};try{let result=await fn(onProgress);if(spinnerTimerId!==null)clearTimeout(spinnerTimerId);let pendingSpinner=spinner;if(pendingSpinner)pendingSpinner.stop();if(started)bar.stop(options.clearOnComplete);if(isTty)write(CURSOR_SHOW,stream);return result}catch(error){if(spinnerTimerId!==null)clearTimeout(spinnerTimerId);let errorSpinner=spinner;if(errorSpinner)errorSpinner.stop();if(started)bar.stop();if(isTty)write(CURSOR_SHOW,stream);throw error}}function createProgressCallback(options={}){let stream=process.stdout,isTty=isTTY(stream),format=options.format??(options.phases?":phase [:bar] :current/:total":"[:bar] :current/:total :percent"),bar=new ProgressBar({format,phases:options.phases??{},hideCursor:!0}),lastPhase=null,started=!1;if(isTty)write(CURSOR_HIDE,stream);return[(info)=>{if(info.phase&&info.phase!==lastPhase){if(lastPhase!==null&&isTty)write(`
9
+ `,stream);if(lastPhase=info.phase,!started)bar.start(info.current,info.total),started=!0;bar.setPhase(info.phase,{current:info.current,total:info.total})}else{if(!started)bar.start(info.current,info.total),started=!0;bar.update(info.current)}},()=>{if(started)bar.stop(options.clearOnComplete);if(isTty)write(CURSOR_SHOW,stream)}]}async function wrapGenerator(generator,textOrFormat,options={}){let stream=process.stdout,isTty=isTTY(stream),label=typeof textOrFormat==="function"?"":textOrFormat,bar=new ProgressBar({format:label?`${label} [:bar] :current/:total :percent`:":bar :current/:total :percent",hideCursor:!0});if(isTty)write(CURSOR_HIDE,stream);let started=!1,result;try{while(!0){if(result=generator.next(),result.done)break;let{current,total}=result.value;if(!started)bar.start(current,total),started=!0;else bar.update(current)}if(started)bar.stop(options.clearOnComplete);if(isTty)write(CURSOR_SHOW,stream);return result.value}catch(error){if(started)bar.stop();if(isTty)write(CURSOR_SHOW,stream);throw error}}async function*withIterableProgress(iterable,label,options={}){let stream=process.stdout,isTty=isTTY(stream),total=(Array.isArray(iterable)?iterable:null)?.length??0,bar=new ProgressBar({format:`${label} [:bar] :current/:total :percent`,total,hideCursor:!0});if(isTty)write(CURSOR_HIDE,stream);let current=0;bar.start(0,total);try{for await(let item of iterable)yield item,current++,bar.update(current);if(bar.stop(options.clearOnComplete),isTty)write(CURSOR_SHOW,stream)}catch(error){if(bar.stop(),isTty)write(CURSOR_SHOW,stream);throw error}}function wrapEmitter(emitter,config){let spinner=new Spinner(config.initialText??""),handlers=new Map;spinner.start();for(let[eventName,eventConfig]of Object.entries(config.events)){let handler=(data)=>{if(eventConfig.getText)spinner.currentText=eventConfig.getText(data);else if(eventConfig.text)spinner.currentText=eventConfig.text;if(eventConfig.succeed)spinner.succeed(),cleanup();else if(eventConfig.fail){let message=data instanceof Error?data.message:String(data??"Failed");spinner.fail(message),cleanup()}else if(eventConfig.stop)spinner.stop(),cleanup()};handlers.set(eventName,handler),emitter.on(eventName,handler)}function cleanup(){for(let[eventName,handler]of handlers)emitter.off(eventName,handler);handlers.clear()}return()=>{spinner.stop(),cleanup()}}async function waitForEvent(emitter,eventName,text,options={}){return new Promise((resolve,reject)=>{let spinner=new Spinner(text);spinner.start();let timer=null,cleanup=()=>{if(emitter.off(eventName,successHandler),options.errorEvent)emitter.off(options.errorEvent,errorHandler);if(timer)clearTimeout(timer)},successHandler=(data)=>{cleanup(),spinner.succeed(),resolve(data)},errorHandler=(error)=>{cleanup(),spinner.fail(error instanceof Error?error.message:"Error"),reject(error instanceof Error?error:Error(String(error)))};if(emitter.once(eventName,successHandler),options.errorEvent)emitter.once(options.errorEvent,errorHandler);if(options.timeout)timer=setTimeout(()=>{cleanup(),spinner.fail("Timeout"),reject(Error(`Timeout waiting for ${eventName}`))},options.timeout)})}async function withSelect(prompt,options,selectOptions={}){let{initial=0,maxVisible=10}=selectOptions,stream=process.stdout,stdin=process.stdin;if(!isTTY(stream)||!stdin.isTTY)return options[initial]?.value??options[0].value;return new Promise((resolve,reject)=>{let highlightIndex=Math.min(Math.max(0,initial),options.length-1),linesRendered=0;stdin.setRawMode(!0),stdin.resume(),stdin.setEncoding("utf8"),write(CURSOR_HIDE,stream);function render(){if(linesRendered>0)write(cursorUp(linesRendered),stream);let scrollOffset=Math.max(0,Math.min(highlightIndex-Math.floor(maxVisible/2),options.length-maxVisible)),visibleCount=Math.min(maxVisible,options.length),visibleOptions=options.slice(scrollOffset,scrollOffset+visibleCount),hasMoreAbove=scrollOffset>0,hasMoreBelow=scrollOffset+visibleCount<options.length;write(`${CURSOR_TO_START}${chalk_default.bold(prompt)}${CLEAR_LINE_END}
10
+ `,stream);let lines=1;if(hasMoreAbove)write(`${CURSOR_TO_START} ${chalk_default.dim("...")}${CLEAR_LINE_END}
11
+ `,stream),lines++;for(let i=0;i<visibleOptions.length;i++){let option=visibleOptions[i],isHighlighted=scrollOffset+i===highlightIndex,indicator=isHighlighted?chalk_default.cyan(">"):" ",label=isHighlighted?chalk_default.cyan(option.label):option.label;write(`${CURSOR_TO_START}${indicator} ${label}${CLEAR_LINE_END}
12
+ `,stream),lines++}if(hasMoreBelow)write(`${CURSOR_TO_START} ${chalk_default.dim("...")}${CLEAR_LINE_END}
13
+ `,stream),lines++;linesRendered=lines}function cleanup(){stdin.setRawMode(!1),stdin.pause(),stdin.removeListener("data",onKeypress),write(CURSOR_SHOW,stream)}function onKeypress(key){let keyCode=key.charCodeAt(0);if(key==="\x03"){cleanup(),reject(Error("User cancelled"));return}if(key==="\r"||key===`
14
+ `){cleanup(),resolve(options[highlightIndex].value);return}if(key==="\x1B"&&key.length===1){cleanup(),reject(Error("User cancelled"));return}if(key.startsWith("\x1B[")){let code=key.slice(2);if(code==="A")highlightIndex=Math.max(0,highlightIndex-1),render();else if(code==="B")highlightIndex=Math.min(options.length-1,highlightIndex+1),render();return}if(key==="j"||key==="J"){highlightIndex=Math.min(options.length-1,highlightIndex+1),render();return}if(key==="k"||key==="K"){highlightIndex=Math.max(0,highlightIndex-1),render();return}if(key===" "){cleanup(),resolve(options[highlightIndex].value);return}}stdin.on("data",onKeypress),render()})}function createSelect(defaultOptions={}){return(prompt,options,overrides={})=>withSelect(prompt,options,{...defaultOptions,...overrides})}async function withTextInput(prompt,options={}){let stream=options.stream??process.stdout,inputStream=options.inputStream??process.stdin,isTty=isTTY(stream),value=options.defaultValue??"",cursorPosition=value.length,errorMessage;if(inputStream.isTTY)inputStream.setRawMode(!0);inputStream.resume();let render=()=>{let displayValue=options.mask?options.mask.repeat(value.length):value,suggestion=getAutocompleteSuggestion(value,options.autocomplete),suggestionSuffix=suggestion?chalk_default.dim(suggestion.slice(value.length)):"",beforeCursor=displayValue.slice(0,cursorPosition),cursorChar=displayValue[cursorPosition]??" ",afterCursor=displayValue.slice(cursorPosition+1),inputDisplay=!value&&options.placeholder?chalk_default.dim(options.placeholder)+chalk_default.inverse(" "):beforeCursor+chalk_default.inverse(cursorChar)+afterCursor+suggestionSuffix,errorDisplay=errorMessage?chalk_default.red(` (${errorMessage})`):"",line=`${chalk_default.cyan("?")} ${chalk_default.bold(prompt)} ${inputDisplay}${errorDisplay}`;if(isTty)write(`${CURSOR_TO_START}${line}${CLEAR_LINE_END}`,stream)};if(isTty)write(CURSOR_HIDE,stream);return render(),new Promise((resolve,reject)=>{let cleanup=()=>{if(inputStream.removeListener("data",onData),inputStream.removeListener("error",onError),inputStream.isTTY)inputStream.setRawMode(!1);if(inputStream.pause(),isTty)write(CURSOR_SHOW,stream)},submit=()=>{if(options.validate){let error=options.validate(value);if(error){errorMessage=error,render();return}}cleanup();let displayValue=options.mask?options.mask.repeat(value.length):value;write(`${CURSOR_TO_START}${chalk_default.green("✔")} ${chalk_default.bold(prompt)} ${chalk_default.dim(displayValue)}${CLEAR_LINE_END}
15
+ `,stream),resolve(value)},onError=(err)=>{cleanup(),reject(err)},onData=(data)=>{let input=data.toString();errorMessage=void 0;for(let i=0;i<input.length;i++){let char=input[i],code=char.charCodeAt(0);if(code===13||code===10){submit();return}if(code===3){cleanup(),write(`
16
+ `,stream),reject(Error("User aborted"));return}if(code===27){if(input[i+1]==="["){let arrowCode=input[i+2];if(arrowCode==="D"){cursorPosition=Math.max(0,cursorPosition-1),i+=2;continue}if(arrowCode==="C"){cursorPosition=Math.min(value.length,cursorPosition+1),i+=2;continue}if(arrowCode==="H"){cursorPosition=0,i+=2;continue}if(arrowCode==="F"){cursorPosition=value.length,i+=2;continue}i+=2;continue}value="",cursorPosition=0;continue}if(code===127||code===8){if(cursorPosition>0)value=value.slice(0,cursorPosition-1)+value.slice(cursorPosition),cursorPosition--;continue}if(code===4){if(cursorPosition<value.length)value=value.slice(0,cursorPosition)+value.slice(cursorPosition+1);continue}if(code===9){let suggestion=getAutocompleteSuggestion(value,options.autocomplete);if(suggestion)value=suggestion,cursorPosition=value.length;continue}if(code===1){cursorPosition=0;continue}if(code===5){cursorPosition=value.length;continue}if(code===21){value=value.slice(cursorPosition),cursorPosition=0;continue}if(code===11){value=value.slice(0,cursorPosition);continue}if(code===23){let before=value.slice(0,cursorPosition),after=value.slice(cursorPosition),trimmed=before.trimEnd(),lastSpace=trimmed.lastIndexOf(" "),newBefore=lastSpace===-1?"":trimmed.slice(0,lastSpace+1);value=newBefore+after,cursorPosition=newBefore.length;continue}if(code>=32&&code<127){value=value.slice(0,cursorPosition)+char+value.slice(cursorPosition),cursorPosition++;continue}if(code>127){value=value.slice(0,cursorPosition)+char+value.slice(cursorPosition),cursorPosition++;continue}}render()};inputStream.on("data",onData),inputStream.on("error",onError)})}function createTextInput(prompt,options={}){let stream=options.stream??process.stdout,isTty=isTTY(stream),value=options.defaultValue??"",cursorPosition=value.length;return{get value(){return value},set value(v){value=v,cursorPosition=Math.min(cursorPosition,v.length)},get cursorPosition(){return cursorPosition},set cursorPosition(pos){cursorPosition=Math.max(0,Math.min(value.length,pos))},render:()=>{let displayValue=options.mask?options.mask.repeat(value.length):value,suggestion=getAutocompleteSuggestion(value,options.autocomplete),suggestionSuffix=suggestion?chalk_default.dim(suggestion.slice(value.length)):"",beforeCursor=displayValue.slice(0,cursorPosition),cursorChar=displayValue[cursorPosition]??" ",afterCursor=displayValue.slice(cursorPosition+1),inputDisplay=!value&&options.placeholder?chalk_default.dim(options.placeholder)+chalk_default.inverse(" "):beforeCursor+chalk_default.inverse(cursorChar)+afterCursor+suggestionSuffix,line=`${chalk_default.cyan("?")} ${chalk_default.bold(prompt)} ${inputDisplay}`;if(isTty)write(`${CURSOR_TO_START}${line}${CLEAR_LINE_END}`,stream)},insert(char){value=value.slice(0,cursorPosition)+char+value.slice(cursorPosition),cursorPosition+=char.length},backspace(){if(cursorPosition>0)value=value.slice(0,cursorPosition-1)+value.slice(cursorPosition),cursorPosition--},delete(){if(cursorPosition<value.length)value=value.slice(0,cursorPosition)+value.slice(cursorPosition+1)},clear(){value="",cursorPosition=0},acceptSuggestion(){let suggestion=getAutocompleteSuggestion(value,options.autocomplete);if(suggestion)value=suggestion,cursorPosition=value.length}}}function getAutocompleteSuggestion(value,autocomplete){if(!value||!autocomplete?.length)return;let lowerValue=value.toLowerCase();return autocomplete.find((item)=>item.toLowerCase().startsWith(lowerValue)&&item.length>value.length)}export{writeLine,write,wrapGenerator,wrapEmitter,withTextInput,withSpinner,withSelect,withProgress,withIterableProgress,withCursor,waitForEvent,isTTY,getTerminalWidth,cursorUp,cursorDown,createTextInput,createSpinner,createSelect,createProgressCallback,attachSpinner,Spinner,SPINNER_FRAMES,ProgressBar,MultiProgress,CURSOR_TO_START,CURSOR_SHOW,CURSOR_SAVE,CURSOR_RESTORE,CURSOR_HIDE,CLEAR_SCREEN,CLEAR_LINE_END,CLEAR_LINE};
17
+
18
+ //# debugId=9E654CBD2D379FC764756E2164756E21
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silvery",
3
- "version": "0.9.0",
4
- "description": "React terminal UI renderer for complex interactive apps \u2014 layout-aware rendering, flexbox, scrolling, and incremental updates",
3
+ "version": "0.11.0",
4
+ "description": "React terminal UI renderer for complex interactive apps layout-aware rendering, flexbox, scrolling, and incremental updates",
5
5
  "keywords": [
6
6
  "ansi",
7
7
  "chalk",
@@ -25,7 +25,7 @@
25
25
  "url": "https://github.com/beorn/silvery/issues"
26
26
  },
27
27
  "license": "MIT",
28
- "author": "Bj\u00f8rn Stabell <bjorn@stabell.org>",
28
+ "author": "Bjørn Stabell <bjorn@stabell.org>",
29
29
  "repository": {
30
30
  "type": "git",
31
31
  "url": "https://github.com/beorn/silvery.git"
@@ -35,24 +35,85 @@
35
35
  "!packages/examples"
36
36
  ],
37
37
  "files": [
38
- "src"
38
+ "dist/**/*.js",
39
+ "dist/**/*.d.ts",
40
+ "src",
41
+ "README.md",
42
+ "CHANGELOG.md",
43
+ "LICENSE"
39
44
  ],
40
45
  "type": "module",
41
46
  "exports": {
42
- ".": "./src/index.ts",
43
- "./runtime": "./src/runtime.ts",
44
- "./theme": "./src/theme.ts",
45
- "./ui": "./src/ui.ts",
46
- "./ui/cli": "./src/ui/cli.ts",
47
- "./ui/react": "./src/ui/react.ts",
48
- "./ui/progress": "./src/ui/progress.ts",
49
- "./ui/wrappers": "./src/ui/wrappers.ts",
50
- "./ui/ansi": "./src/ui/ansi.ts",
51
- "./ui/display": "./src/ui/display.ts",
52
- "./ui/input": "./src/ui/input.ts",
53
- "./ui/animation": "./src/ui/animation.ts",
54
- "./ui/image": "./src/ui/image.ts",
55
- "./ui/utils": "./src/ui/utils.ts",
47
+ ".": {
48
+ "bun": "./src/index.ts",
49
+ "types": "./src/index.ts",
50
+ "default": "./dist/index.js"
51
+ },
52
+ "./runtime": {
53
+ "bun": "./src/runtime.ts",
54
+ "types": "./src/runtime.ts",
55
+ "default": "./dist/runtime.js"
56
+ },
57
+ "./theme": {
58
+ "bun": "./src/theme.ts",
59
+ "types": "./src/theme.ts",
60
+ "default": "./dist/theme.js"
61
+ },
62
+ "./ui": {
63
+ "bun": "./src/ui.ts",
64
+ "types": "./src/ui.ts",
65
+ "default": "./dist/ui.js"
66
+ },
67
+ "./ui/cli": {
68
+ "bun": "./src/ui/cli.ts",
69
+ "types": "./src/ui/cli.ts",
70
+ "default": "./dist/ui/cli.js"
71
+ },
72
+ "./ui/react": {
73
+ "bun": "./src/ui/react.ts",
74
+ "types": "./src/ui/react.ts",
75
+ "default": "./dist/ui/react.js"
76
+ },
77
+ "./ui/progress": {
78
+ "bun": "./src/ui/progress.ts",
79
+ "types": "./src/ui/progress.ts",
80
+ "default": "./dist/ui/progress.js"
81
+ },
82
+ "./ui/wrappers": {
83
+ "bun": "./src/ui/wrappers.ts",
84
+ "types": "./src/ui/wrappers.ts",
85
+ "default": "./dist/ui/wrappers.js"
86
+ },
87
+ "./ui/ansi": {
88
+ "bun": "./src/ui/ansi.ts",
89
+ "types": "./src/ui/ansi.ts",
90
+ "default": "./dist/ui/ansi.js"
91
+ },
92
+ "./ui/display": {
93
+ "bun": "./src/ui/display.ts",
94
+ "types": "./src/ui/display.ts",
95
+ "default": "./dist/ui/display.js"
96
+ },
97
+ "./ui/input": {
98
+ "bun": "./src/ui/input.ts",
99
+ "types": "./src/ui/input.ts",
100
+ "default": "./dist/ui/input.js"
101
+ },
102
+ "./ui/animation": {
103
+ "bun": "./src/ui/animation.ts",
104
+ "types": "./src/ui/animation.ts",
105
+ "default": "./dist/ui/animation.js"
106
+ },
107
+ "./ui/image": {
108
+ "bun": "./src/ui/image.ts",
109
+ "types": "./src/ui/image.ts",
110
+ "default": "./dist/ui/image.js"
111
+ },
112
+ "./ui/utils": {
113
+ "bun": "./src/ui/utils.ts",
114
+ "types": "./src/ui/utils.ts",
115
+ "default": "./dist/ui/utils.js"
116
+ },
56
117
  "./ink": "@silvery/ink",
57
118
  "./chalk": "@silvery/ink/chalk"
58
119
  },
@@ -61,6 +122,7 @@
61
122
  },
62
123
  "scripts": {
63
124
  "build": "bun run scripts/build.ts",
125
+ "prepublishOnly": "bun run scripts/build.ts",
64
126
  "test": "bunx --bun vitest run",
65
127
  "test:fast": "bunx --bun vitest run --reporter=dot",
66
128
  "typecheck": "tsc --noEmit",
@@ -76,20 +138,22 @@
76
138
  "compat:chalk": "bun packages/ink/scripts/compat-check.ts chalk"
77
139
  },
78
140
  "dependencies": {
141
+ "@chenglou/pretext": "^0.0.3",
79
142
  "@silvery/commander": "workspace:*",
80
143
  "loggily": "github:beorn/loggily",
81
144
  "react-reconciler": "^0.33.0",
82
145
  "slice-ansi": "^8.0.0",
83
- "string-width": "^8.2.0",
84
- "zustand": "^5.0.11"
146
+ "string-width": "^8.2.0"
85
147
  },
86
148
  "devDependencies": {
87
149
  "@types/bun": "^1.1.0",
88
150
  "@types/react": "^19.0.0",
151
+ "@vue/server-renderer": "^3.5.31",
89
152
  "@xterm/addon-fit": "^0.11.0",
90
153
  "@xterm/xterm": "^6.0.0",
91
154
  "chalk": "^5.6.2",
92
155
  "fast-check": "^4.6.0",
156
+ "mermaid": "^11.14.0",
93
157
  "mitata": "^1.0.34",
94
158
  "oxfmt": "^0.36.0",
95
159
  "oxlint": "^1.51.0",
@@ -98,8 +162,13 @@
98
162
  "typescript": "^5.5.0",
99
163
  "vimonkey": "^0.2.0",
100
164
  "vitepress": "^1.5.0",
165
+ "vitepress-enrich": "^0.4.0",
166
+ "vitepress-plugin-d2": "^1.1.0",
167
+ "vitepress-plugin-diagrams": "^1.2.2",
101
168
  "vitepress-plugin-llms": "^1.0.0",
169
+ "vitepress-plugin-mermaid": "^2.0.17",
102
170
  "vitest": "^4.0.18",
171
+ "vue": "^3.5.31",
103
172
  "yoga-wasm-web": "^0.3.3"
104
173
  },
105
174
  "peerDependencies": {
package/src/index.ts CHANGED
@@ -9,7 +9,7 @@ export * from "@silvery/ag-react"
9
9
  import type { ReactElement } from "react"
10
10
  import { render as reactRender, type RenderOptions } from "@silvery/ag-react"
11
11
  import type { Term } from "@silvery/ag-react"
12
- import type { TermDef } from "@silvery/ag/types"
12
+ import type { TermDef } from "@silvery/ag-term/term-def"
13
13
 
14
14
  /**
15
15
  * Render a React element to the terminal.