/** * echo.js by Jacob Bloom * This software is provided as-is, yadda yadda yadda */ !function(){"use strict";let e="browser";if(void 0!==typeof process)try{e=process.stdout.isTTY&&process.stdout.getColorDepth()>=4?"ansi":"off"}catch(e){}var t={colorMode:e,bracketNotationOptional:!0,constructorParensOptional:!0,parensOptional:!0,stringDelimiter:"'",theme:"undefined"!=typeof navigator&&navigator.userAgent.includes("Firefox")?"firefox":"chrome",autoLog:!0,autoLogMinLength:1};const o=Symbol("ECHO_INTERNALS"),r=Symbol("ECHO_SELF"),n=new Map(Object.entries({undefined:"undefined",null:"null",true:"boolean",false:"boolean",Infinity:"keyword","-Infinity":"keyword",NaN:"keyword"}));function a(e){const o=e.match("\n")?"`":t.stringDelimiter,r=new RegExp(o,"g");return o+e.replace(r,"\\"+o)+o}function l([{raw:e},...t]){let o={value:"`"+e[0],type:"string"};const r=[o];for(let n=0;n({value:e,type:"operator"}),string:([e])=>({value:e,type:"string"}),keyword:([e])=>({value:e,type:"keyword"}),default:([e])=>({value:e,type:"default"}),space:()=>({value:" ",type:"default"})};function s(e){if(e&&e[r])return f(e[r]);const t=[];switch(typeof e){case"string":t.push({value:a(e),type:"string"});break;case"function":e.name?t.push({value:e.name,type:"variable"}):t.push({value:String(e),type:"default"});break;case"object":if(e){const o=e.__proto__.name||e.constructor.name;Array.isArray(e)?t.push(i.operator`[`,...p(e),i.operator`]`):o&&"Object"!=o?t.push({value:o+" {}",type:"object"}):t.push({value:"{}",type:"object"})}else t.push({value:"null",type:"null"});break;case"bigint":t.push({value:String(e)+"n",type:"number"});break;default:n.has(String(e))?t.push({value:String(e),type:n.get(String(e))}):t.push({value:String(e),type:typeof e})}return t}function p(e){const t=[];return e.forEach((o,r)=>{t.push(...s(o)),r0?r[e-1].type:"",d=r[e];switch(d.type){case"get":if(s.length)if("symbol"==typeof d.identifier){const e=d.identifier.description,t=[{value:"Symbol",type:"variable"},i.operator`(`,{value:a(e),type:"string"},i.operator`)`];s=[...s,i.operator`[`,...t,i.operator`]`]}else{let e;if(n.has(d.identifier))e={value:d.identifier,type:n.get(d.identifier)};else if(d.identifier.trim())if(Number.isNaN(Number(d.identifier)))if(c.test(d.identifier)){const[,t]=d.identifier.match(c);e=t&&"Object"!=t?{value:t+" {}",type:"object"}:{value:"{}",type:"object"}}else e=t.bracketNotationOptional&&u.test(d.identifier)?{value:d.identifier,type:"property"}:{value:a(d.identifier),type:"string"};else e={value:d.identifier,type:"number"};else e={value:a(d.identifier),type:"string"};t.parensOptional&&"construct"!==o||(s=[i.operator`(`,...s,i.operator`)`]),s="property"===e.type?[...s,i.operator`.`,e]:[...s,i.operator`[`,e,i.operator`]`]}else s=[{value:String(d.identifier),type:"variable"}];break;case"construct":{let e=[];t.constructorParensOptional&&!d.args.length||(e=[i.operator`(`,...p(d.args),i.operator`)`]),s=t.parensOptional&&"apply"!==o?[i.keyword`new`,i.space(),...s,...e]:[i.keyword`new`,i.space(),i.operator`(`,...s,i.operator`)`,...e];break}case"apply":s=(f=d.args)[0]&&Array.isArray(f[0])&&Array.isArray(f[0].raw)?"construct"===o?[i.operator`(`,...s,i.operator`)`,...l(d.args)]:[...s,...l(d.args)]:t.parensOptional&&"construct"!==o?[...s,i.operator`(`,...p(d.args),i.operator`)`]:[i.operator`(`,...s,i.operator`)`,i.operator`(`,...p(d.args),i.operator`)`]}}var f;return s}const d="",y="",g="",b={chrome:{browser:{keyword:"color: hsl(310, 86%, 36%)",number:"color: hsl(248, 100%, 41%)",string:"color: hsl(1, 80%, 43%)",boolean:"color: hsl(248, 100%, 41%)",object:"color: black",null:"color: hsl(310, 86%, 36%)",undefined:"color: hsl(310, 86%, 36%)",operator:"color: black",variable:"color: black",property:"color: black",default:"color: black"},ansi:{keyword:g,number:y,string:"",boolean:y,object:d,null:g,undefined:g,operator:d,variable:d,property:d,default:d}},firefox:{browser:{keyword:"color: #dd00a9",number:"color: #30a",string:"color: #30a",boolean:"color: #dd00a9",object:"color: black",null:"color: #dd00a9",undefined:"color: #dd00a9",operator:"color: black",variable:"color: #8000d7",property:"color: #085;",default:"color: black"},ansi:{keyword:g,number:y,string:y,boolean:g,object:d,null:g,undefined:g,operator:d,variable:y,property:"",default:d}}};const h=["render","options","then","print","toString","__registerPublicGetter","valueOf","constructor","prototype","__proto__","name","Symbol(nodejs.util.inspect.custom)","Symbol(Symbol.toPrimitive)"],m=new Map,v="undefined"!=typeof process?Symbol.for("nodejs.util.inspect.custom"):null,k={get:(e,t)=>t===r?e:m.has(t)?m.get(t)(e):h.includes(String(t))?("options"==t&&(e[o].autoLogDisabled.value=!0),e[t]):(e[o].stack.push({type:"get",identifier:t}),e[o].proxy),construct:(e,t)=>(e[o].stack.push({type:"construct",args:t}),e[o].proxy),apply:(e,t,r)=>(e[o].stack.push({type:"apply",args:r}),e[o].proxy),has:(e,t)=>h.includes(String(t))||m.has(t),getOwnPropertyDescriptor:(e,t)=>"name"===t?{value:"Echo",configurable:!0}:h.includes(String(t))?Object.getOwnPropertyDescriptor(e,t):m.has(t)?{value:m.get(t)(e),configurable:!0}:{value:null,configurable:!0},ownKeys:e=>[...Reflect.ownKeys(e).filter(e=>e!==o),"name"]};function w(e,r){const n=function(){};return n[o]={autoLogDisabled:e,stack:[{type:"get",identifier:"Echo"}],proxy:new Proxy(n,k),id:r},n.render=(o=!0)=>{o&&(e.value=!0);return function(e){const o={tokens:e,plaintext:e.map(e=>"string"==typeof e?e:e.value).join(""),formatted:null,theme:null};if("off"===t.colorMode)o.formatted=[o.plaintext];else if("browser"===t.colorMode){o.theme="string"==typeof t.theme?b[t.theme].browser:t.theme;let r="";const n=[];let a;for(const t of e){const e=o.theme[t.type]||o.theme.default||"color: black";e!==a&&(r+="%c",n.push(e)),r+=t.value.replace(/%/g,"%%"),a=e}o.formatted=[r,...n]}else{o.theme="string"==typeof t.theme?b[t.theme].ansi:t.theme;let r,n="";for(const t of e){const e=o.theme[t.type]||o.theme.default||d;e!==r&&(n+=e),n+=t.value,r=e}n+=d,o.formatted=[n]}return o}(f(n))},n.print=()=>console.log(...n.render().formatted),n.then=(...e)=>Promise.prototype.then.apply(Promise.resolve(n.render()),e),n.toString=()=>n.render(0===r).plaintext,n[Symbol.toPrimitive]=n.toString,v&&(n[v]=()=>n.render(!1).formatted[0]),n.__registerPublicGetter=(e,t)=>{m.set(e,t)},n.options=t,delete n.__proto__,delete n.name,delete n.length,n}const S={value:!1};let _=0,j=0,O=[];!function(e,t){const o="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:null;if(null===o)throw new Error("Unable to locate global object");Object.defineProperty(o,e,{get:t})}("Echo",()=>{const e=w(S,_);return 0===_&&(S.value=!1),t.autoLog&&(_++,setTimeout(()=>{const o=e.render(!1);o.tokens.length>j&&(j=o.tokens.length,O=o.formatted),_--,0===_&&(j>=t.autoLogMinLength&&!S.value&&console.log(...O),S.value=!1,j=0,O=[])},0)),e[o].proxy})}();