UNPKG

@cmtlyt/logger

Version:
3 lines 3.46 kB
function e(){return void 0!==globalThis.window}let t={debug:{primary:"#eb2f96",tagColor:"#fff",titleColor:"#a7a7a7"},info:{primary:"#d9d9d9",tagColor:"#000",titleColor:"#a7a7a7"},warn:{primary:"#fa8c16",tagColor:"#fff",titleColor:"#a7a7a7"},error:{primary:"#f5222d",tagColor:"#fff",titleColor:"#a7a7a7"}},n={borderRadiusSize:"6px",paddingBlock:"4px",paddingInline:"8px",lineWidth:"2px",fontSize:"10px"},o=new Set(["string","number","boolean","undefined","symbol","null","bigint"]),r=r=>{var i;let l,a={options:{group:{enable:!1!==(l=(i=r||{}).group||{}).enable,collapsed:!1!==l.collapsed},consoleLevel:i.consoleLevel||"log",allowTypes:i.allowTypes||[],getSubTitle:i.getSubTitle||(()=>""),getMessages:i.getMessages||(()=>null),customStyle:i.customStyle||(e=>e),isEnvironmentValid:i.isEnvironmentValid||e,getWindowWidth:i.getWindowWidth||(()=>e()?window.outerWidth:500)}},s=function(e){let t=new Set(["debug","info","warn","error"]);if(!e)return t;if("function"==typeof e)return e;if(Array.isArray(e)){let n=new Set(t);return e.forEach(e=>{n.add(e)}),n}return e}(a.options.allowTypes);return a.options.isEnvironmentValid()?e=>("function"==typeof s?s(e):s.has(e))?function(e){let{group:r,consoleLevel:i,getSubTitle:l,getMessages:a}=e.options;return s=>{let{type:d,messages:u}=s,f=l(s)||d,p=function(e,r,i,l){var a;let s=t[e]||t.debug,{group:d,customStyle:u}=l.options,{theme:f,baseStyle:p}=(a=u({type:e,theme:{...s},baseStyle:{...n}}),{theme:{...s,...a.theme},baseStyle:{...n,...a.baseStyle}}),g=function(e,t,n){let r,i,l,a=[],s=[];for(let t=0;t<e.length;++t){let n=e[t],r=Object.prototype.toString.call(n).slice(8,-1).toLowerCase();o.has(r)?s.push(String(n)):(a.push(s.join(" "),function(e){let t=new Map,n=JSON.stringify(e,(e,n)=>{if("bigint"==typeof n)return n.toString();if("function"==typeof n){let e=n.toString();return e.includes("=>")||e.startsWith("function")?e:`function ${e}`}if("object"==typeof n){if(t.has(n)){let e=t.get(n);return`[Circular ${e?`key: ${e}`:"self"}]`}return t.set(n,e),n}return n},2);return n&&"function"==typeof n.replace?n.replace(/\n(\s+)/g,(e,{length:t})=>` ${"\xa0".repeat(t)}`):n}(n)),s.length=0)}a.push(s.join(" ")),s.length=0;let d=(r=Number.parseFloat(t),(!Number.isFinite(i=n.options.getWindowWidth())||i<=0)&&(i=2048),l=Math.min(1e3,Math.floor(i/r*1.12))," ".repeat(l));return a.flatMap(e=>e.split("\n")).join(d)}(i,p.fontSize,l),c=`margin-left:${d.enable?"-16px":"0"};padding:${p.paddingBlock} ${p.paddingInline};font-size:${p.fontSize};`,b=r!==e&&!d.enable,h=function(e){if(e.includes("gradient")){let t=[/#[0-9a-fA-F]{8}/,/#[0-9a-fA-F]{6}/,/#[0-9a-fA-F]{4}/,/#[0-9a-fA-F]{3}/,/rgba?\([^)]+\)/,/hsla?\([^)]+\)/];for(let n=0;n<t.length;n++){let o=e.match(t[n]);if(o)return o[0]}return"#d9d9d9"}return e}(f.primary);return{message:`%c${e}${b?`%c(${r})`:""}%c %c${g.padEnd(e.length," ")}`,styles:[`${c}background:${f.primary};color:${f.tagColor};border-radius:${p.borderRadiusSize} ${p.borderRadiusSize} 0 0;text-transform:uppercase;`,...b?[`${c}margin-left:${p.lineWidth};padding-inline:0;color:${f.titleColor};`]:[],"font-size:0;line-height:0;",`${c}display:inline-block;margin-top:-${p.lineWidth};background:#fff;border:${p.lineWidth} solid ${h};border-radius: 0 ${p.borderRadiusSize} ${p.borderRadiusSize};`]}}(d,f,a(s)||u,e);r.enable?(console[r.collapsed?"groupCollapsed":"group"](f),console[i](p.message,...p.styles),console.groupEnd()):console[i](p.message,...p.styles)}}(a):null:{}};export{r as webConsoleAdapter};