@vielzeug/logit 1.0.1 → 1.0.3

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/dist/index.d.ts CHANGED
@@ -77,6 +77,8 @@ export declare const Logit: {
77
77
 
78
78
  export declare type LogitColors = Exclude<LogitType, 'table'> | 'group' | 'ns';
79
79
 
80
+ /** biome-ignore-all lint/suspicious/noAssignInExpressions: - */
81
+ /** biome-ignore-all lint/suspicious/noExplicitAny: - */
80
82
  export declare type LogitInstance = typeof Logit;
81
83
 
82
84
  export declare type LogitLevel = LogitType | 'off';
package/dist/logit.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w={},v="🄿",$="🄳",L={debug:"log",success:"log"},x=()=>w?.NODE_ENV==="production",E=typeof window<"u"&&window.matchMedia?.("(prefers-color-scheme: dark)").matches,m={debug:{bg:"#616161",border:"#424242",color:"#fff",icon:"☕",symbol:"🅳"},error:{bg:"#d32f2f",border:"#c62828",color:"#fff",icon:"✘",symbol:"🅴"},group:{bg:"#546e7a",border:"#455a64",color:"#fff",icon:"⚭",symbol:"🅶"},info:{bg:"#1976d2",border:"#1565c0",color:"#fff",icon:"ℹ",symbol:"🅸"},ns:E?{bg:"#fafafa",border:"#c7c7c7",color:"#000"}:{bg:"#424242",border:"#212121",color:"#fff"},success:{bg:"#689f38",border:"#558b2f",color:"#fff",icon:"✔",symbol:"🆂"},time:{bg:"#0097a7",border:"#00838f",color:"#fff",icon:"⏲",symbol:"🆃"},trace:{bg:"#d81b60",border:"#c2185b",color:"#fff",icon:"⛢",symbol:"🆃"},warn:{bg:"#ffb300",border:"#ffa000",color:"#fff",icon:"⚠",symbol:"🆆"}},f={debug:0,trace:1,time:2,table:3,info:4,success:5,warn:6,error:7,off:8},e={environment:!0,logLevel:"debug",namespace:"",remote:{handler:void 0,logLevel:"off"},timestamp:!0,variant:"symbol"},d=o=>f[e.logLevel]<=f[o],u=()=>new Date().toISOString().slice(11,23),b=()=>x()?v:$,y=(o,r)=>{e.remote.handler&&f[e.remote.logLevel]<=f[o]&&e.remote.handler(o,...r)},p=o=>L[o]||o,g=(o,r="")=>{const{bg:t,color:s,border:n}=m[o],c=`color: ${t}; border: 1px solid ${n}; border-radius: 4px;`;switch(e.variant){case"symbol":return`${c} padding: 1px 1px 0;${r};`;case"icon":return`${c} padding: 0 3px;${r};`;default:return`background: ${t}; color: ${s}; border: 1px solid ${n}; border-radius: 4px; font-weight: bold; padding: 0 3px;${r}`}};function _(o){const r=m[o],{namespace:t,variant:s,timestamp:n,environment:c}=e;let i=`%c${r[s]??o.toUpperCase()}%c`;const a=[g(o),""];return t&&(i+=` %c${t}%c`,a.push(g("ns"," border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter;"),"")),c&&(i+=` %c${b()}%c`,a.push("color: darkgray;","")),n&&(i+=` %c${u()}%c`,a.push("color: gray;","")),{format:i,parts:a}}const l=(o,...r)=>{if(typeof window>"u"){const c=m[o],{variant:i}=e,a=console[p(o)];a(`${c[i]??o.toUpperCase()} | ${b()} |`,...r);return}if(!d(o))return;const{format:t,parts:s}=_(o),n=console[p(o)];n(t,...s,...r),y(o,r)},O=o=>{const r=Math.floor(Date.now()-o);return r?`${r}ms`:""},h={assert:(o,r,t)=>console.assert(o,r,t),debug:(...o)=>l("debug",...o),error:(...o)=>l("error",...o),getLevel:()=>e.logLevel,getPrefix:()=>e.namespace,getTimestamp:()=>e.timestamp,groupCollapsed:(o,r="GROUP",t=Date.now())=>{if(!d("success"))return;const s=O(t),n=b();console.groupCollapsed(`%c${r}%c${e.namespace}%c${n}%c${e.timestamp?u():""}%c${s}%c${o}`,g("group","margin-right: 6px; padding: 1px 3px 0"),g("ns"," border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter;margin-right: 6px;"),"color: darkgray; margin-right: 6px;","color: gray;font-weight: lighter;margin-right: 6px;","color: gray; font-weight: lighter;margin-right: 6px;","color: inherit;font-weight: lighter;")},groupEnd:()=>{d("success")&&console.groupEnd()},info:(...o)=>l("info",...o),initialise:o=>{Object.assign(e,o)},setLogLevel:o=>{e.logLevel=o},setPrefix:o=>{e.namespace=o},setRemote:o=>{e.remote=o},setRemoteLogLevel:o=>{e.remote.logLevel=o},setVariant:o=>{e.variant=o},showEnvironment:o=>{e.environment=o},showTimestamp:o=>{e.timestamp=o},success:(...o)=>l("success",...o),table:(...o)=>{d("table")&&console.table(...o)},time:o=>{d("time")&&console.time(o)},timeEnd:o=>{d("time")&&console.timeEnd(o)},trace:(...o)=>l("trace",...o),warn:(...o)=>l("warn",...o)};typeof window<"u"&&(window.Logit=h);exports.Logit=h;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v={},E="🄿",w="🄳",L={debug:"log",success:"log"},_=()=>typeof window<"u"&&v?.NODE_ENV?!1:typeof process<"u"&&process.env?.NODE_ENV?process.env.NODE_ENV==="production":!1,x=_(),y=typeof window<"u"&&window.matchMedia?.("(prefers-color-scheme: dark)").matches,b={debug:{bg:"#616161",border:"#424242",color:"#fff",icon:"☕",symbol:"🅳"},error:{bg:"#d32f2f",border:"#c62828",color:"#fff",icon:"✘",symbol:"🅴"},group:{bg:"#546e7a",border:"#455a64",color:"#fff",icon:"⚭",symbol:"🅶"},info:{bg:"#1976d2",border:"#1565c0",color:"#fff",icon:"ℹ",symbol:"🅸"},ns:y?{bg:"#fafafa",border:"#c7c7c7",color:"#000"}:{bg:"#424242",border:"#212121",color:"#fff"},success:{bg:"#689f38",border:"#558b2f",color:"#fff",icon:"✔",symbol:"🆂"},time:{bg:"#0097a7",border:"#00838f",color:"#fff",icon:"⏲",symbol:"🆃"},trace:{bg:"#d81b60",border:"#c2185b",color:"#fff",icon:"⛢",symbol:"🆃"},warn:{bg:"#ffb300",border:"#ffa000",color:"#fff",icon:"⚠",symbol:"🆆"}},l={debug:0,trace:1,time:2,table:3,info:4,success:5,warn:6,error:7,off:8},t={environment:!0,logLevel:"debug",namespace:"",remote:{handler:void 0,logLevel:"off"},timestamp:!0,variant:"symbol"},a=e=>l[t.logLevel]<=l[e],p=()=>new Date().toISOString().slice(11,23),d=()=>x?E:w,D=(e,o)=>{t.remote.handler&&l[t.remote.logLevel]<=l[e]&&t.remote.handler(e,...o)},g=e=>L[e]||e,m="border: 1px solid",u="border-radius: 4px",h="border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter",f=(e,o="")=>{const{bg:r,color:c,border:n}=b[e],s=`color: ${r}; ${m} ${n}; ${u}`;switch(t.variant){case"symbol":return`${s}; padding: 1px 1px 0${o}`;case"icon":return`${s}; padding: 0 3px${o}`;default:return`background: ${r}; color: ${c}; ${m} ${n}; ${u}; font-weight: bold; padding: 0 3px${o}`}},$=e=>{const o=b[e],{variant:r}=t;return r==="text"||!o[r]?e.toUpperCase():o[r]};function O(e){const{namespace:o,timestamp:r,environment:c}=t;let n=`%c${$(e)}%c`;const s=[f(e),""];return o&&(n+=` %c${o}%c`,s.push(f("ns",`; ${h}`),"")),c&&(n+=` %c${d()}%c`,s.push("color: darkgray","")),r&&(n+=` %c${p()}%c`,s.push("color: gray","")),{format:n,parts:s}}const i=(e,...o)=>{if(typeof window>"u"){const s=console[g(e)];s(`${$(e)} | ${d()} |`,...o);return}if(!a(e))return;const{format:r,parts:c}=O(e),n=console[g(e)];n(r,...c,...o),D(e,o)},S=e=>{const o=Math.floor(Date.now()-e);return o?`${o}ms`:""},R={assert:(e,o,r)=>console.assert(e,o,r),debug:(...e)=>i("debug",...e),error:(...e)=>i("error",...e),getLevel:()=>t.logLevel,getPrefix:()=>t.namespace,getTimestamp:()=>t.timestamp,groupCollapsed:(e,o="GROUP",r=Date.now())=>{if(!a("success"))return;const c=S(r),n=d(),s=t.timestamp?p():"";console.groupCollapsed(`%c${o}%c${t.namespace}%c${n}%c${s}%c${c}%c${e}`,f("group","; margin-right: 6px; padding: 1px 3px 0"),f("ns",`; ${h}; margin-right: 6px`),"color: darkgray; margin-right: 6px","color: gray; font-weight: lighter; margin-right: 6px","color: gray; font-weight: lighter; margin-right: 6px","color: inherit; font-weight: lighter")},groupEnd:()=>{a("success")&&console.groupEnd()},info:(...e)=>i("info",...e),initialise:e=>{Object.assign(t,e)},setLogLevel:e=>{t.logLevel=e},setPrefix:e=>{t.namespace=e},setRemote:e=>{t.remote=e},setRemoteLogLevel:e=>{t.remote.logLevel=e},setVariant:e=>{t.variant=e},showEnvironment:e=>{t.environment=e},showTimestamp:e=>{t.timestamp=e},success:(...e)=>i("success",...e),table:(...e)=>{a("table")&&console.table(...e)},time:e=>{a("time")&&console.time(e)},timeEnd:e=>{a("time")&&console.timeEnd(e)},trace:(...e)=>i("trace",...e),warn:(...e)=>i("warn",...e)};exports.Logit=R;
2
2
  //# sourceMappingURL=logit.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"logit.cjs","sources":["../src/logit.ts"],"sourcesContent":["/** biome-ignore-all lint/suspicious/noAssignInExpressions: - */\n/** biome-ignore-all lint/suspicious/noExplicitAny: - */\ndeclare global {\n interface Window {\n Logit: LogitInstance;\n }\n}\n\n/**\n * Environment indicator symbols.\n */\nconst ENV_PROD = '\\uD83C\\uDD3F'; // 🅿\nconst ENV_DEV = '\\uD83C\\uDD33'; // 🅳\n\n/**\n * Console method mappings for log types.\n */\nconst CONSOLE_METHOD_MAP: Record<string, keyof Console> = {\n debug: 'log',\n success: 'log',\n} as const;\n\n/**\n * Checks if the current environment is production.\n */\nconst isProd = (): boolean => (import.meta as any)?.env?.NODE_ENV === 'production';\n\nexport type LogitInstance = typeof Logit;\nexport type LogitType = 'debug' | 'trace' | 'time' | 'table' | 'info' | 'success' | 'warn' | 'error';\nexport type LogitColors = Exclude<LogitType, 'table'> | 'group' | 'ns';\nexport type LogitLevel = LogitType | 'off';\nexport type LogitRemoteOptions = {\n handler?: (...args: any[]) => void;\n logLevel: LogitLevel;\n};\nexport type LogitOptions = {\n environment?: boolean;\n variant?: 'text' | 'symbol' | 'icon';\n logLevel?: LogitLevel;\n namespace?: string;\n remote?: LogitRemoteOptions;\n timestamp?: boolean;\n};\nexport type LogitTheme = { color: string; bg: string; border: string; icon?: string; symbol?: string };\n\nconst isDark = typeof window !== 'undefined' && window.matchMedia?.('(prefers-color-scheme: dark)').matches;\nconst Theme: Readonly<Record<LogitColors, LogitTheme>> = {\n debug: { bg: '#616161', border: '#424242', color: '#fff', icon: '\\u2615', symbol: '\\uD83C\\uDD73' },\n error: { bg: '#d32f2f', border: '#c62828', color: '#fff', icon: '\\u2718', symbol: '\\uD83C\\uDD74' },\n group: { bg: '#546e7a', border: '#455a64', color: '#fff', icon: '\\u26AD', symbol: '\\uD83C\\uDD76' },\n info: { bg: '#1976d2', border: '#1565c0', color: '#fff', icon: '\\u2139', symbol: '\\uD83C\\uDD78' },\n ns: isDark\n ? { bg: '#fafafa', border: '#c7c7c7', color: '#000' }\n : { bg: '#424242', border: '#212121', color: '#fff' },\n success: { bg: '#689f38', border: '#558b2f', color: '#fff', icon: '\\u2714', symbol: '\\uD83C\\uDD82' },\n time: { bg: '#0097a7', border: '#00838f', color: '#fff', icon: '\\u23F2', symbol: '\\uD83C\\uDD83' },\n trace: { bg: '#d81b60', border: '#c2185b', color: '#fff', icon: '\\u26e2', symbol: '\\uD83C\\uDD83' },\n warn: { bg: '#ffb300', border: '#ffa000', color: '#fff', icon: '\\u26a0', symbol: '\\uD83C\\uDD86' },\n};\n\n// biome-ignore assist/source/useSortedKeys: -\nconst logLevel: Readonly<Record<LogitLevel, number>> = {\n debug: 0,\n trace: 1,\n time: 2,\n table: 3,\n info: 4,\n success: 5,\n warn: 6,\n error: 7,\n off: 8,\n};\n\nconst state: Required<LogitOptions> = {\n environment: true,\n logLevel: 'debug',\n namespace: '',\n remote: { handler: undefined, logLevel: 'off' },\n timestamp: true,\n variant: 'symbol',\n};\n\n/**\n * Determines if a log message should be shown based on the current log level.\n */\nconst shouldLog = (type: LogitType): boolean => logLevel[state.logLevel] <= logLevel[type];\n\n/**\n * Gets the current timestamp in ISO format (HH:MM:SS.mmm).\n */\nconst getTimestamp = (): string => new Date().toISOString().slice(11, 23);\n\n/**\n * Gets the environment indicator symbol.\n */\nconst getEnvIndicator = (): string => (isProd() ? ENV_PROD : ENV_DEV);\n\n/**\n * Sends log data to remote handler if configured.\n */\nconst sendRemoteLog = (type: LogitType, args: any[]): void => {\n if (state.remote.handler && logLevel[state.remote.logLevel] <= logLevel[type]) {\n state.remote.handler(type, ...args);\n }\n};\n\n/**\n * Gets the console method for a given log type.\n */\nconst getConsoleMethod = (type: LogitType): keyof Console => {\n return (CONSOLE_METHOD_MAP[type] || type) as keyof Console;\n};\n\n/**\n * Generates CSS styles for log messages based on theme and variant.\n */\nconst style = (type: LogitColors, extra = ''): string => {\n const { bg, color, border } = Theme[type];\n const baseStyle = `color: ${bg}; border: 1px solid ${border}; border-radius: 4px;`;\n\n switch (state.variant) {\n case 'symbol':\n return `${baseStyle} padding: 1px 1px 0;${extra};`;\n case 'icon':\n return `${baseStyle} padding: 0 3px;${extra};`;\n default:\n return `background: ${bg}; color: ${color}; border: 1px solid ${border}; border-radius: 4px; font-weight: bold; padding: 0 3px;${extra}`;\n }\n};\n\n/**\n * Builds the format string and style parts for browser console logging.\n */\nfunction buildBrowserLogParts(type: LogitType): { format: string; parts: string[] } {\n const theme = Theme[type as LogitColors];\n const { namespace, variant, timestamp, environment } = state;\n\n let format = `%c${theme[variant as keyof LogitTheme] ?? type.toUpperCase()}%c`;\n const parts: string[] = [style(type as any), ''];\n\n if (namespace) {\n format += ` %c${namespace}%c`;\n parts.push(style('ns', ' border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter;'), '');\n }\n\n if (environment) {\n format += ` %c${getEnvIndicator()}%c`;\n parts.push('color: darkgray;', '');\n }\n\n if (timestamp) {\n format += ` %c${getTimestamp()}%c`;\n parts.push('color: gray;', '');\n }\n\n return { format, parts };\n}\n\n/**\n * Logs messages to the console with styling and metadata.\n */\nconst log = (type: LogitType, ...args: any[]): void => {\n // Server-side logging (Node.js)\n if (typeof window === 'undefined') {\n const theme = Theme[type as LogitColors];\n const { variant } = state;\n const consoleMethod = console[getConsoleMethod(type)] as (...a: any) => void;\n consoleMethod(`${theme[variant as keyof LogitTheme] ?? type.toUpperCase()} | ${getEnvIndicator()} |`, ...args);\n return;\n }\n\n // Check log level\n if (!shouldLog(type)) return;\n\n // Browser-side logging with styling\n const { format, parts } = buildBrowserLogParts(type);\n const consoleMethod = console[getConsoleMethod(type)] as (...a: any) => void;\n\n consoleMethod(format, ...parts, ...args);\n sendRemoteLog(type, args);\n};\n\n/**\n * Formats the elapsed time for display.\n */\nconst formatElapsedTime = (startTime: number): string => {\n const elapsed = Math.floor(Date.now() - startTime);\n return elapsed ? `${elapsed}ms` : '';\n};\n\nexport const Logit = {\n /**\n * Asserts a condition and logs an error if it's false.\n */\n assert: (valid: boolean, message: string, context: Record<string, any>): void =>\n console.assert(valid, message, context),\n\n debug: (...args: any[]): void => log('debug', ...args),\n error: (...args: any[]): void => log('error', ...args),\n\n /**\n * Gets the current log level.\n */\n getLevel: (): LogitLevel => state.logLevel,\n\n /**\n * Gets the current namespace prefix.\n */\n getPrefix: (): string => state.namespace,\n\n /**\n * Gets whether timestamps are shown.\n */\n getTimestamp: (): boolean => state.timestamp,\n\n /**\n * Creates a collapsed group in the console.\n */\n groupCollapsed: (text: string, label = 'GROUP', time = Date.now()): void => {\n if (!shouldLog('success')) return;\n\n const elapsed = formatElapsedTime(time);\n const env = getEnvIndicator();\n\n console.groupCollapsed(\n `%c${label}%c${state.namespace}%c${env}%c${state.timestamp ? getTimestamp() : ''}%c${elapsed}%c${text}`,\n style('group', 'margin-right: 6px; padding: 1px 3px 0'),\n style('ns', ' border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter;margin-right: 6px;'),\n 'color: darkgray; margin-right: 6px;',\n 'color: gray;font-weight: lighter;margin-right: 6px;',\n 'color: gray; font-weight: lighter;margin-right: 6px;',\n 'color: inherit;font-weight: lighter;',\n );\n },\n\n /**\n * Ends the current console group.\n */\n groupEnd: (): void => {\n if (shouldLog('success')) console.groupEnd();\n },\n\n info: (...args: any[]): void => log('info', ...args),\n\n /**\n * Initializes Logit with custom options.\n */\n initialise: (options: LogitOptions): void => {\n Object.assign(state, options);\n },\n\n /**\n * Sets the minimum log level to display.\n */\n setLogLevel: (level: LogitLevel): void => {\n state.logLevel = level;\n },\n\n /**\n * Sets the namespace prefix for all logs.\n */\n setPrefix: (namespace: string): void => {\n state.namespace = namespace;\n },\n\n /**\n * Configures remote logging options.\n */\n setRemote: (remote: LogitRemoteOptions): void => {\n state.remote = remote;\n },\n\n /**\n * Sets the log level for remote logging.\n */\n setRemoteLogLevel: (level: LogitLevel): void => {\n state.remote.logLevel = level;\n },\n\n /**\n * Sets the display variant (text, icon, or symbol).\n */\n setVariant: (variant: 'text' | 'icon' | 'symbol'): void => {\n state.variant = variant;\n },\n\n /**\n * Shows or hides the environment indicator.\n */\n showEnvironment: (value: boolean): void => {\n state.environment = value;\n },\n\n /**\n * Shows or hides timestamps in logs.\n */\n showTimestamp: (value: boolean): void => {\n state.timestamp = value;\n },\n\n success: (...args: any[]): void => log('success', ...args),\n\n /**\n * Displays data in a table format.\n */\n table: (...args: any[]): void => {\n if (shouldLog('table')) console.table(...args);\n },\n\n /**\n * Starts a timer with the given label.\n */\n time: (label: string): void => {\n if (shouldLog('time')) console.time(label);\n },\n\n /**\n * Ends a timer with the given label.\n */\n timeEnd: (label: string): void => {\n if (shouldLog('time')) console.timeEnd(label);\n },\n\n trace: (...args: any[]): void => log('trace', ...args),\n warn: (...args: any[]): void => log('warn', ...args),\n};\n\nif (typeof window !== 'undefined') {\n window.Logit = Logit;\n}\n"],"names":["ENV_PROD","ENV_DEV","CONSOLE_METHOD_MAP","isProd","__vite_import_meta_env__","isDark","Theme","logLevel","state","shouldLog","type","getTimestamp","getEnvIndicator","sendRemoteLog","args","getConsoleMethod","style","extra","bg","color","border","baseStyle","buildBrowserLogParts","theme","namespace","variant","timestamp","environment","format","parts","log","consoleMethod","formatElapsedTime","startTime","elapsed","Logit","valid","message","context","text","label","time","env","options","level","remote","value"],"mappings":"2FAWMA,EAAW,KACXC,EAAU,KAKVC,EAAoD,CACxD,MAAO,MACP,QAAS,KACX,EAKMC,EAAS,IAAgBC,GAA0B,WAAa,aAoBhEC,EAAS,OAAO,OAAW,KAAe,OAAO,aAAa,8BAA8B,EAAE,QAC9FC,EAAmD,CACvD,MAAO,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,OAAQ,KAAM,IAAU,OAAQ,IAAA,EAClF,MAAO,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,OAAQ,KAAM,IAAU,OAAQ,IAAA,EAClF,MAAO,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,OAAQ,KAAM,IAAU,OAAQ,IAAA,EAClF,KAAM,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,OAAQ,KAAM,IAAU,OAAQ,IAAA,EACjF,GAAID,EACA,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,MAAA,EAC3C,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,MAAA,EAC/C,QAAS,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,OAAQ,KAAM,IAAU,OAAQ,IAAA,EACpF,KAAM,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,OAAQ,KAAM,IAAU,OAAQ,IAAA,EACjF,MAAO,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,OAAQ,KAAM,IAAU,OAAQ,IAAA,EAClF,KAAM,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,OAAQ,KAAM,IAAU,OAAQ,IAAA,CACnF,EAGME,EAAiD,CACrD,MAAO,EACP,MAAO,EACP,KAAM,EACN,MAAO,EACP,KAAM,EACN,QAAS,EACT,KAAM,EACN,MAAO,EACP,IAAK,CACP,EAEMC,EAAgC,CACpC,YAAa,GACb,SAAU,QACV,UAAW,GACX,OAAQ,CAAE,QAAS,OAAW,SAA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Content":["/** biome-ignore-all lint/suspicious/noAssignInExpressions: - */\n/** biome-ignore-all lint/suspicious/noExplicitAny: - */\n\n/**\n * Environment indicator symbols.\n */\nconst ENV_PROD = '\\uD83C\\uDD3F'; // 🅿\nconst ENV_DEV = '\\uD83C\\uDD33'; // 🅳\n\n/**\n * Console method mappings for log types.\n */\nconst CONSOLE_METHOD_MAP: Record<string, keyof Console> = {\n debug: 'log',\n success: 'log',\n} as const;\n\n/**\n * Checks if the current environment is production.\n * Cached for performance - evaluated once at a module load.\n */\nconst isProduction = (): boolean => {\n // Browser environment (Vite, Webpack, etc.)\n if (typeof window !== 'undefined' && (import.meta as any)?.env?.NODE_ENV) {\n return (import.meta as any).env.NODE_ENV === 'production';\n }\n\n // Node.js environment\n // @ts-expect-error\n if (typeof process !== 'undefined' && (process as any).env?.NODE_ENV) {\n // @ts-expect-error\n return (process as any).env.NODE_ENV === 'production';\n }\n\n return false;\n};\n\n// Cache the result to avoid repeated checks\nconst IS_PROD = isProduction();\n\nexport type LogitInstance = typeof Logit;\nexport type LogitType = 'debug' | 'trace' | 'time' | 'table' | 'info' | 'success' | 'warn' | 'error';\nexport type LogitColors = Exclude<LogitType, 'table'> | 'group' | 'ns';\nexport type LogitLevel = LogitType | 'off';\nexport type LogitRemoteOptions = {\n handler?: (...args: any[]) => void;\n logLevel: LogitLevel;\n};\nexport type LogitOptions = {\n environment?: boolean;\n variant?: 'text' | 'symbol' | 'icon';\n logLevel?: LogitLevel;\n namespace?: string;\n remote?: LogitRemoteOptions;\n timestamp?: boolean;\n};\nexport type LogitTheme = { color: string; bg: string; border: string; icon?: string; symbol?: string };\n\n/**\n * Detects dark mode preference at module load time.\n * Note: This is intentionally static and won't update if the user changes their theme.\n */\nconst isDark = typeof window !== 'undefined' && window.matchMedia?.('(prefers-color-scheme: dark)').matches;\n\nconst Theme: Readonly<Record<LogitColors, LogitTheme>> = {\n debug: { bg: '#616161', border: '#424242', color: '#fff', icon: '\\u2615', symbol: '\\uD83C\\uDD73' },\n error: { bg: '#d32f2f', border: '#c62828', color: '#fff', icon: '\\u2718', symbol: '\\uD83C\\uDD74' },\n group: { bg: '#546e7a', border: '#455a64', color: '#fff', icon: '\\u26AD', symbol: '\\uD83C\\uDD76' },\n info: { bg: '#1976d2', border: '#1565c0', color: '#fff', icon: '\\u2139', symbol: '\\uD83C\\uDD78' },\n ns: isDark\n ? { bg: '#fafafa', border: '#c7c7c7', color: '#000' }\n : { bg: '#424242', border: '#212121', color: '#fff' },\n success: { bg: '#689f38', border: '#558b2f', color: '#fff', icon: '\\u2714', symbol: '\\uD83C\\uDD82' },\n time: { bg: '#0097a7', border: '#00838f', color: '#fff', icon: '\\u23F2', symbol: '\\uD83C\\uDD83' },\n trace: { bg: '#d81b60', border: '#c2185b', color: '#fff', icon: '\\u26e2', symbol: '\\uD83C\\uDD83' },\n warn: { bg: '#ffb300', border: '#ffa000', color: '#fff', icon: '\\u26a0', symbol: '\\uD83C\\uDD86' },\n};\n\n// biome-ignore assist/source/useSortedKeys: -\nconst logLevel: Readonly<Record<LogitLevel, number>> = {\n debug: 0,\n trace: 1,\n time: 2,\n table: 3,\n info: 4,\n success: 5,\n warn: 6,\n error: 7,\n off: 8,\n};\n\nconst state: Required<LogitOptions> = {\n environment: true,\n logLevel: 'debug',\n namespace: '',\n remote: { handler: undefined, logLevel: 'off' },\n timestamp: true,\n variant: 'symbol',\n};\n\n/**\n * Determines if a log message should be shown based on the current log level.\n */\nconst shouldLog = (type: LogitType): boolean => logLevel[state.logLevel] <= logLevel[type];\n\n/**\n * Gets the current timestamp in ISO format (HH:MM:SS.mmm).\n */\nconst getCurrentTimestamp = (): string => new Date().toISOString().slice(11, 23);\n\n/**\n * Gets the environment indicator symbol.\n */\nconst getEnvIndicator = (): string => (IS_PROD ? ENV_PROD : ENV_DEV);\n\n/**\n * Sends log data to remote handler if configured.\n */\nconst sendRemoteLog = (type: LogitType, args: any[]): void => {\n if (state.remote.handler && logLevel[state.remote.logLevel] <= logLevel[type]) {\n state.remote.handler(type, ...args);\n }\n};\n\n/**\n * Gets the console method for a given log type.\n */\nconst getConsoleMethod = (type: LogitType): keyof Console => {\n return (CONSOLE_METHOD_MAP[type] || type) as keyof Console;\n};\n\n/**\n * CSS style constants for consistent formatting.\n */\nconst BASE_BORDER_STYLE = 'border: 1px solid';\nconst BASE_BORDER_RADIUS = 'border-radius: 4px';\nconst NAMESPACE_STYLE = 'border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter';\n\n/**\n * Generates CSS styles for log messages based on theme and variant.\n */\nconst style = (type: LogitColors, extra = ''): string => {\n const { bg, color, border } = Theme[type];\n const baseStyle = `color: ${bg}; ${BASE_BORDER_STYLE} ${border}; ${BASE_BORDER_RADIUS}`;\n\n switch (state.variant) {\n case 'symbol':\n return `${baseStyle}; padding: 1px 1px 0${extra}`;\n case 'icon':\n return `${baseStyle}; padding: 0 3px${extra}`;\n default:\n return `background: ${bg}; color: ${color}; ${BASE_BORDER_STYLE} ${border}; ${BASE_BORDER_RADIUS}; font-weight: bold; padding: 0 3px${extra}`;\n }\n};\n\n/**\n * Gets the display value for a log type based on current variant.\n */\nconst getDisplayValue = (type: LogitType): string => {\n const theme = Theme[type as LogitColors];\n const { variant } = state;\n\n // For 'text' variant or if the variant key doesn't exist, use uppercase type\n if (variant === 'text' || !theme[variant]) {\n return type.toUpperCase();\n }\n\n return theme[variant] as string;\n};\n\n/**\n * Builds the format string and style parts for browser console logging.\n */\nfunction buildBrowserLogParts(type: LogitType): { format: string; parts: string[] } {\n const { namespace, timestamp, environment } = state;\n\n let format = `%c${getDisplayValue(type)}%c`;\n const parts: string[] = [style(type as LogitColors), ''];\n\n if (namespace) {\n format += ` %c${namespace}%c`;\n parts.push(style('ns', `; ${NAMESPACE_STYLE}`), '');\n }\n\n if (environment) {\n format += ` %c${getEnvIndicator()}%c`;\n parts.push('color: darkgray', '');\n }\n\n if (timestamp) {\n format += ` %c${getCurrentTimestamp()}%c`;\n parts.push('color: gray', '');\n }\n\n return { format, parts };\n}\n\n/**\n * Logs messages to the console with styling and metadata.\n */\nconst log = (type: LogitType, ...args: any[]): void => {\n // Server-side logging (Node.js)\n if (typeof window === 'undefined') {\n const consoleMethod = console[getConsoleMethod(type)] as (...a: any[]) => void;\n consoleMethod(`${getDisplayValue(type)} | ${getEnvIndicator()} |`, ...args);\n return;\n }\n\n // Check log level\n if (!shouldLog(type)) return;\n\n // Browser-side logging with styling\n const { format, parts } = buildBrowserLogParts(type);\n const consoleMethod = console[getConsoleMethod(type)] as (...a: any[]) => void;\n\n consoleMethod(format, ...parts, ...args);\n sendRemoteLog(type, args);\n};\n\n/**\n * Formats the elapsed time for display.\n */\nconst formatElapsedTime = (startTime: number): string => {\n const elapsed = Math.floor(Date.now() - startTime);\n return elapsed ? `${elapsed}ms` : '';\n};\n\nexport const Logit = {\n /**\n * Asserts a condition and logs an error if it's false.\n */\n assert: (valid: boolean, message: string, context: Record<string, any>): void =>\n console.assert(valid, message, context),\n\n debug: (...args: any[]): void => log('debug', ...args),\n error: (...args: any[]): void => log('error', ...args),\n\n /**\n * Gets the current log level.\n */\n getLevel: (): LogitLevel => state.logLevel,\n\n /**\n * Gets the current namespace prefix.\n */\n getPrefix: (): string => state.namespace,\n\n /**\n * Gets whether timestamps are shown.\n */\n getTimestamp: (): boolean => state.timestamp,\n\n /**\n * Creates a collapsed group in the console.\n */\n groupCollapsed: (text: string, label = 'GROUP', time = Date.now()): void => {\n if (!shouldLog('success')) return;\n\n const elapsed = formatElapsedTime(time);\n const env = getEnvIndicator();\n const timestamp = state.timestamp ? getCurrentTimestamp() : '';\n\n console.groupCollapsed(\n `%c${label}%c${state.namespace}%c${env}%c${timestamp}%c${elapsed}%c${text}`,\n style('group', '; margin-right: 6px; padding: 1px 3px 0'),\n style('ns', `; ${NAMESPACE_STYLE}; margin-right: 6px`),\n 'color: darkgray; margin-right: 6px',\n 'color: gray; font-weight: lighter; margin-right: 6px',\n 'color: gray; font-weight: lighter; margin-right: 6px',\n 'color: inherit; font-weight: lighter',\n );\n },\n\n /**\n * Ends the current console group.\n */\n groupEnd: (): void => {\n if (shouldLog('success')) console.groupEnd();\n },\n\n info: (...args: any[]): void => log('info', ...args),\n\n /**\n * Initializes Logit with custom options.\n */\n initialise: (options: LogitOptions): void => {\n Object.assign(state, options);\n },\n\n /**\n * Sets the minimum log level to display.\n */\n setLogLevel: (level: LogitLevel): void => {\n state.logLevel = level;\n },\n\n /**\n * Sets the namespace prefix for all logs.\n */\n setPrefix: (namespace: string): void => {\n state.namespace = namespace;\n },\n\n /**\n * Configures remote logging options.\n */\n setRemote: (remote: LogitRemoteOptions): void => {\n state.remote = remote;\n },\n\n /**\n * Sets the log level for remote logging.\n */\n setRemoteLogLevel: (level: LogitLevel): void => {\n state.remote.logLevel = level;\n },\n\n /**\n * Sets the display variant (text, icon, or symbol).\n */\n setVariant: (variant: 'text' | 'icon' | 'symbol'): void => {\n state.variant = variant;\n },\n\n /**\n * Shows or hides the environment indicator.\n */\n showEnvironment: (value: boolean): void => {\n state.environment = value;\n },\n\n /**\n * Shows or hides timestamps in logs.\n */\n showTimestamp: (value: boolean): void => {\n state.timestamp = value;\n },\n\n success: (...args: any[]): void => log('success', ...args),\n\n /**\n * Displays data in a table format.\n */\n table: (...args: any[]): void => {\n if (shouldLog('table')) console.table(...args);\n },\n\n /**\n * Starts a timer with the given label.\n */\n time: (label: string): void => {\n if (shouldLog('time')) console.time(label);\n },\n\n /**\n * Ends a timer with the given label.\n */\n timeEnd: (label: string): void => {\n if (shouldLog('time')) console.timeEnd(label);\n },\n\n trace: (...args: any[]): void => log('trace', ...args),\n warn: (...args: any[]): void => log('warn', ...args),\n};\n\n"],"names":["ENV_PROD","ENV_DEV","CONSOLE_METHOD_MAP","isProduction","__vite_import_meta_env__","IS_PROD","isDark","Theme","logLevel","state","shouldLog","type","getCurrentTimestamp","getEnvIndicator","sendRemoteLog","args","getConsoleMethod","BASE_BORDER_STYLE","BASE_BORDER_RADIUS","NAMESPACE_STYLE","style","extra","bg","color","border","baseStyle","getDisplayValue","theme","variant","buildBrowserLogParts","namespace","timestamp","environment","format","parts","log","consoleMethod","formatElapsedTime","startTime","elapsed","Logit","valid","message","context","text","label","time","env","options","level","remote","value"],"mappings":"2FAMMA,EAAW,KACXC,EAAU,KAKVC,EAAoD,CACxD,MAAO,MACP,QAAS,KACX,EAMMC,EAAe,IAEf,OAAO,OAAW,KAAgBC,GAA0B,SACtD,GAKN,OAAO,QAAY,KAAgB,QAAgB,KAAK,SAElD,QAAgB,IAAI,WAAa,aAGpC,GAIHC,EAAUF,EAAA,EAwBVG,EAAS,OAAO,OAAW,KAAe,OAAO,aAAa,8BAA8B,EAAE,QAE9FC,EAAmD,CACvD,MAAO,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,OAAQ,KAAM,IAAU,OAAQ,IAAA,EAClF,MAAO,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,OAAQ,KAAM,IAAU,OAAQ,IAAA,EAClF,MAAO,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,OAAQ,KAAM,IAAU,OAAQ,IAAA,EAClF,KAAM,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,OAAQ,KAAM,IAAU,OAAQ,IAAA,EACjF,GAAID,EACA,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,MAAA,EAC3C,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,MAAA,EAC/C,QAAS,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,OAAQ,KAAM,IAAU,OAAQ,IAAA,EACpF,KAAM,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,OAAQ,KAAM,IAAU,OAAQ,IAAA,EACjF,MAAO,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,OAAQ,KAAM,IAAU,OAAQ,IAAA,EAClF,KAAM,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,OAAQ,KAAM,IAAU,OAAQ,IAAA,CACnF,EAGME,EAAiD,CACrD,MAAO,EACP,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AI,CAC/C,EAKA,KAAO8B,GAAwB,CACzBnC,EAAU,MAAM,GAAG,QAAQ,KAAKmC,CAAK,CAC3C,EAKA,QAAUA,GAAwB,CAC5BnC,EAAU,MAAM,GAAG,QAAQ,QAAQmC,CAAK,CAC9C,EAEA,MAAO,IAAI9B,IAAsBoB,EAAI,QAAS,GAAGpB,CAAI,EACrD,KAAM,IAAIA,IAAsBoB,EAAI,OAAQ,GAAGpB,CAAI,CACrD"}
package/dist/logit.js CHANGED
@@ -1,18 +1,18 @@
1
- const h = {};
2
- const w = {
1
+ const $ = {};
2
+ const v = {
3
3
  debug: "log",
4
4
  success: "log"
5
- }, v = () => h?.NODE_ENV === "production", $ = typeof window < "u" && window.matchMedia?.("(prefers-color-scheme: dark)").matches, m = {
5
+ }, w = () => typeof window < "u" && $?.NODE_ENV ? !1 : typeof process < "u" && process.env?.NODE_ENV ? process.env.NODE_ENV === "production" : !1, _ = w(), L = typeof window < "u" && window.matchMedia?.("(prefers-color-scheme: dark)").matches, b = {
6
6
  debug: { bg: "#616161", border: "#424242", color: "#fff", icon: "☕", symbol: "🅳" },
7
7
  error: { bg: "#d32f2f", border: "#c62828", color: "#fff", icon: "✘", symbol: "🅴" },
8
8
  group: { bg: "#546e7a", border: "#455a64", color: "#fff", icon: "⚭", symbol: "🅶" },
9
9
  info: { bg: "#1976d2", border: "#1565c0", color: "#fff", icon: "ℹ", symbol: "🅸" },
10
- ns: $ ? { bg: "#fafafa", border: "#c7c7c7", color: "#000" } : { bg: "#424242", border: "#212121", color: "#fff" },
10
+ ns: L ? { bg: "#fafafa", border: "#c7c7c7", color: "#000" } : { bg: "#424242", border: "#212121", color: "#fff" },
11
11
  success: { bg: "#689f38", border: "#558b2f", color: "#fff", icon: "✔", symbol: "🆂" },
12
12
  time: { bg: "#0097a7", border: "#00838f", color: "#fff", icon: "⏲", symbol: "🆃" },
13
13
  trace: { bg: "#d81b60", border: "#c2185b", color: "#fff", icon: "⛢", symbol: "🆃" },
14
14
  warn: { bg: "#ffb300", border: "#ffa000", color: "#fff", icon: "⚠", symbol: "🆆" }
15
- }, f = {
15
+ }, l = {
16
16
  debug: 0,
17
17
  trace: 1,
18
18
  time: 2,
@@ -22,158 +22,160 @@ const w = {
22
22
  warn: 6,
23
23
  error: 7,
24
24
  off: 8
25
- }, e = {
25
+ }, r = {
26
26
  environment: !0,
27
27
  logLevel: "debug",
28
28
  namespace: "",
29
29
  remote: { handler: void 0, logLevel: "off" },
30
30
  timestamp: !0,
31
31
  variant: "symbol"
32
- }, d = (o) => f[e.logLevel] <= f[o], u = () => (/* @__PURE__ */ new Date()).toISOString().slice(11, 23), b = () => v() ? "🄿" : "🄳", x = (o, r) => {
33
- e.remote.handler && f[e.remote.logLevel] <= f[o] && e.remote.handler(o, ...r);
34
- }, p = (o) => w[o] || o, g = (o, r = "") => {
35
- const { bg: t, color: s, border: n } = m[o], c = `color: ${t}; border: 1px solid ${n}; border-radius: 4px;`;
36
- switch (e.variant) {
32
+ }, a = (e) => l[r.logLevel] <= l[e], u = () => (/* @__PURE__ */ new Date()).toISOString().slice(11, 23), d = () => _ ? "🄿" : "🄳", x = (e, o) => {
33
+ r.remote.handler && l[r.remote.logLevel] <= l[e] && r.remote.handler(e, ...o);
34
+ }, g = (e) => v[e] || e, m = "border: 1px solid", p = "border-radius: 4px", h = "border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter", f = (e, o = "") => {
35
+ const { bg: t, color: c, border: n } = b[e], s = `color: ${t}; ${m} ${n}; ${p}`;
36
+ switch (r.variant) {
37
37
  case "symbol":
38
- return `${c} padding: 1px 1px 0;${r};`;
38
+ return `${s}; padding: 1px 1px 0${o}`;
39
39
  case "icon":
40
- return `${c} padding: 0 3px;${r};`;
40
+ return `${s}; padding: 0 3px${o}`;
41
41
  default:
42
- return `background: ${t}; color: ${s}; border: 1px solid ${n}; border-radius: 4px; font-weight: bold; padding: 0 3px;${r}`;
42
+ return `background: ${t}; color: ${c}; ${m} ${n}; ${p}; font-weight: bold; padding: 0 3px${o}`;
43
43
  }
44
+ }, E = (e) => {
45
+ const o = b[e], { variant: t } = r;
46
+ return t === "text" || !o[t] ? e.toUpperCase() : o[t];
44
47
  };
45
- function L(o) {
46
- const r = m[o], { namespace: t, variant: s, timestamp: n, environment: c } = e;
47
- let i = `%c${r[s] ?? o.toUpperCase()}%c`;
48
- const a = [g(o), ""];
49
- return t && (i += ` %c${t}%c`, a.push(g("ns", " border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter;"), "")), c && (i += ` %c${b()}%c`, a.push("color: darkgray;", "")), n && (i += ` %c${u()}%c`, a.push("color: gray;", "")), { format: i, parts: a };
48
+ function D(e) {
49
+ const { namespace: o, timestamp: t, environment: c } = r;
50
+ let n = `%c${E(e)}%c`;
51
+ const s = [f(e), ""];
52
+ return o && (n += ` %c${o}%c`, s.push(f("ns", `; ${h}`), "")), c && (n += ` %c${d()}%c`, s.push("color: darkgray", "")), t && (n += ` %c${u()}%c`, s.push("color: gray", "")), { format: n, parts: s };
50
53
  }
51
- const l = (o, ...r) => {
54
+ const i = (e, ...o) => {
52
55
  if (typeof window > "u") {
53
- const c = m[o], { variant: i } = e, a = console[p(o)];
54
- a(`${c[i] ?? o.toUpperCase()} | ${b()} |`, ...r);
56
+ const s = console[g(e)];
57
+ s(`${E(e)} | ${d()} |`, ...o);
55
58
  return;
56
59
  }
57
- if (!d(o)) return;
58
- const { format: t, parts: s } = L(o), n = console[p(o)];
59
- n(t, ...s, ...r), x(o, r);
60
- }, E = (o) => {
61
- const r = Math.floor(Date.now() - o);
62
- return r ? `${r}ms` : "";
63
- }, _ = {
60
+ if (!a(e)) return;
61
+ const { format: t, parts: c } = D(e), n = console[g(e)];
62
+ n(t, ...c, ...o), x(e, o);
63
+ }, O = (e) => {
64
+ const o = Math.floor(Date.now() - e);
65
+ return o ? `${o}ms` : "";
66
+ }, y = {
64
67
  /**
65
68
  * Asserts a condition and logs an error if it's false.
66
69
  */
67
- assert: (o, r, t) => console.assert(o, r, t),
68
- debug: (...o) => l("debug", ...o),
69
- error: (...o) => l("error", ...o),
70
+ assert: (e, o, t) => console.assert(e, o, t),
71
+ debug: (...e) => i("debug", ...e),
72
+ error: (...e) => i("error", ...e),
70
73
  /**
71
74
  * Gets the current log level.
72
75
  */
73
- getLevel: () => e.logLevel,
76
+ getLevel: () => r.logLevel,
74
77
  /**
75
78
  * Gets the current namespace prefix.
76
79
  */
77
- getPrefix: () => e.namespace,
80
+ getPrefix: () => r.namespace,
78
81
  /**
79
82
  * Gets whether timestamps are shown.
80
83
  */
81
- getTimestamp: () => e.timestamp,
84
+ getTimestamp: () => r.timestamp,
82
85
  /**
83
86
  * Creates a collapsed group in the console.
84
87
  */
85
- groupCollapsed: (o, r = "GROUP", t = Date.now()) => {
86
- if (!d("success")) return;
87
- const s = E(t), n = b();
88
+ groupCollapsed: (e, o = "GROUP", t = Date.now()) => {
89
+ if (!a("success")) return;
90
+ const c = O(t), n = d(), s = r.timestamp ? u() : "";
88
91
  console.groupCollapsed(
89
- `%c${r}%c${e.namespace}%c${n}%c${e.timestamp ? u() : ""}%c${s}%c${o}`,
90
- g("group", "margin-right: 6px; padding: 1px 3px 0"),
91
- g("ns", " border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter;margin-right: 6px;"),
92
- "color: darkgray; margin-right: 6px;",
93
- "color: gray;font-weight: lighter;margin-right: 6px;",
94
- "color: gray; font-weight: lighter;margin-right: 6px;",
95
- "color: inherit;font-weight: lighter;"
92
+ `%c${o}%c${r.namespace}%c${n}%c${s}%c${c}%c${e}`,
93
+ f("group", "; margin-right: 6px; padding: 1px 3px 0"),
94
+ f("ns", `; ${h}; margin-right: 6px`),
95
+ "color: darkgray; margin-right: 6px",
96
+ "color: gray; font-weight: lighter; margin-right: 6px",
97
+ "color: gray; font-weight: lighter; margin-right: 6px",
98
+ "color: inherit; font-weight: lighter"
96
99
  );
97
100
  },
98
101
  /**
99
102
  * Ends the current console group.
100
103
  */
101
104
  groupEnd: () => {
102
- d("success") && console.groupEnd();
105
+ a("success") && console.groupEnd();
103
106
  },
104
- info: (...o) => l("info", ...o),
107
+ info: (...e) => i("info", ...e),
105
108
  /**
106
109
  * Initializes Logit with custom options.
107
110
  */
108
- initialise: (o) => {
109
- Object.assign(e, o);
111
+ initialise: (e) => {
112
+ Object.assign(r, e);
110
113
  },
111
114
  /**
112
115
  * Sets the minimum log level to display.
113
116
  */
114
- setLogLevel: (o) => {
115
- e.logLevel = o;
117
+ setLogLevel: (e) => {
118
+ r.logLevel = e;
116
119
  },
117
120
  /**
118
121
  * Sets the namespace prefix for all logs.
119
122
  */
120
- setPrefix: (o) => {
121
- e.namespace = o;
123
+ setPrefix: (e) => {
124
+ r.namespace = e;
122
125
  },
123
126
  /**
124
127
  * Configures remote logging options.
125
128
  */
126
- setRemote: (o) => {
127
- e.remote = o;
129
+ setRemote: (e) => {
130
+ r.remote = e;
128
131
  },
129
132
  /**
130
133
  * Sets the log level for remote logging.
131
134
  */
132
- setRemoteLogLevel: (o) => {
133
- e.remote.logLevel = o;
135
+ setRemoteLogLevel: (e) => {
136
+ r.remote.logLevel = e;
134
137
  },
135
138
  /**
136
139
  * Sets the display variant (text, icon, or symbol).
137
140
  */
138
- setVariant: (o) => {
139
- e.variant = o;
141
+ setVariant: (e) => {
142
+ r.variant = e;
140
143
  },
141
144
  /**
142
145
  * Shows or hides the environment indicator.
143
146
  */
144
- showEnvironment: (o) => {
145
- e.environment = o;
147
+ showEnvironment: (e) => {
148
+ r.environment = e;
146
149
  },
147
150
  /**
148
151
  * Shows or hides timestamps in logs.
149
152
  */
150
- showTimestamp: (o) => {
151
- e.timestamp = o;
153
+ showTimestamp: (e) => {
154
+ r.timestamp = e;
152
155
  },
153
- success: (...o) => l("success", ...o),
156
+ success: (...e) => i("success", ...e),
154
157
  /**
155
158
  * Displays data in a table format.
156
159
  */
157
- table: (...o) => {
158
- d("table") && console.table(...o);
160
+ table: (...e) => {
161
+ a("table") && console.table(...e);
159
162
  },
160
163
  /**
161
164
  * Starts a timer with the given label.
162
165
  */
163
- time: (o) => {
164
- d("time") && console.time(o);
166
+ time: (e) => {
167
+ a("time") && console.time(e);
165
168
  },
166
169
  /**
167
170
  * Ends a timer with the given label.
168
171
  */
169
- timeEnd: (o) => {
170
- d("time") && console.timeEnd(o);
172
+ timeEnd: (e) => {
173
+ a("time") && console.timeEnd(e);
171
174
  },
172
- trace: (...o) => l("trace", ...o),
173
- warn: (...o) => l("warn", ...o)
175
+ trace: (...e) => i("trace", ...e),
176
+ warn: (...e) => i("warn", ...e)
174
177
  };
175
- typeof window < "u" && (window.Logit = _);
176
178
  export {
177
- _ as Logit
179
+ y as Logit
178
180
  };
179
181
  //# sourceMappingURL=logit.js.map
package/dist/logit.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"logit.js","sources":["../src/logit.ts"],"sourcesContent":["/** biome-ignore-all lint/suspicious/noAssignInExpressions: - */\n/** biome-ignore-all lint/suspicious/noExplicitAny: - */\ndeclare global {\n interface Window {\n Logit: LogitInstance;\n }\n}\n\n/**\n * Environment indicator symbols.\n */\nconst ENV_PROD = '\\uD83C\\uDD3F'; // 🅿\nconst ENV_DEV = '\\uD83C\\uDD33'; // 🅳\n\n/**\n * Console method mappings for log types.\n */\nconst CONSOLE_METHOD_MAP: Record<string, keyof Console> = {\n debug: 'log',\n success: 'log',\n} as const;\n\n/**\n * Checks if the current environment is production.\n */\nconst isProd = (): boolean => (import.meta as any)?.env?.NODE_ENV === 'production';\n\nexport type LogitInstance = typeof Logit;\nexport type LogitType = 'debug' | 'trace' | 'time' | 'table' | 'info' | 'success' | 'warn' | 'error';\nexport type LogitColors = Exclude<LogitType, 'table'> | 'group' | 'ns';\nexport type LogitLevel = LogitType | 'off';\nexport type LogitRemoteOptions = {\n handler?: (...args: any[]) => void;\n logLevel: LogitLevel;\n};\nexport type LogitOptions = {\n environment?: boolean;\n variant?: 'text' | 'symbol' | 'icon';\n logLevel?: LogitLevel;\n namespace?: string;\n remote?: LogitRemoteOptions;\n timestamp?: boolean;\n};\nexport type LogitTheme = { color: string; bg: string; border: string; icon?: string; symbol?: string };\n\nconst isDark = typeof window !== 'undefined' && window.matchMedia?.('(prefers-color-scheme: dark)').matches;\nconst Theme: Readonly<Record<LogitColors, LogitTheme>> = {\n debug: { bg: '#616161', border: '#424242', color: '#fff', icon: '\\u2615', symbol: '\\uD83C\\uDD73' },\n error: { bg: '#d32f2f', border: '#c62828', color: '#fff', icon: '\\u2718', symbol: '\\uD83C\\uDD74' },\n group: { bg: '#546e7a', border: '#455a64', color: '#fff', icon: '\\u26AD', symbol: '\\uD83C\\uDD76' },\n info: { bg: '#1976d2', border: '#1565c0', color: '#fff', icon: '\\u2139', symbol: '\\uD83C\\uDD78' },\n ns: isDark\n ? { bg: '#fafafa', border: '#c7c7c7', color: '#000' }\n : { bg: '#424242', border: '#212121', color: '#fff' },\n success: { bg: '#689f38', border: '#558b2f', color: '#fff', icon: '\\u2714', symbol: '\\uD83C\\uDD82' },\n time: { bg: '#0097a7', border: '#00838f', color: '#fff', icon: '\\u23F2', symbol: '\\uD83C\\uDD83' },\n trace: { bg: '#d81b60', border: '#c2185b', color: '#fff', icon: '\\u26e2', symbol: '\\uD83C\\uDD83' },\n warn: { bg: '#ffb300', border: '#ffa000', color: '#fff', icon: '\\u26a0', symbol: '\\uD83C\\uDD86' },\n};\n\n// biome-ignore assist/source/useSortedKeys: -\nconst logLevel: Readonly<Record<LogitLevel, number>> = {\n debug: 0,\n trace: 1,\n time: 2,\n table: 3,\n info: 4,\n success: 5,\n warn: 6,\n error: 7,\n off: 8,\n};\n\nconst state: Required<LogitOptions> = {\n environment: true,\n logLevel: 'debug',\n namespace: '',\n remote: { handler: undefined, logLevel: 'off' },\n timestamp: true,\n variant: 'symbol',\n};\n\n/**\n * Determines if a log message should be shown based on the current log level.\n */\nconst shouldLog = (type: LogitType): boolean => logLevel[state.logLevel] <= logLevel[type];\n\n/**\n * Gets the current timestamp in ISO format (HH:MM:SS.mmm).\n */\nconst getTimestamp = (): string => new Date().toISOString().slice(11, 23);\n\n/**\n * Gets the environment indicator symbol.\n */\nconst getEnvIndicator = (): string => (isProd() ? ENV_PROD : ENV_DEV);\n\n/**\n * Sends log data to remote handler if configured.\n */\nconst sendRemoteLog = (type: LogitType, args: any[]): void => {\n if (state.remote.handler && logLevel[state.remote.logLevel] <= logLevel[type]) {\n state.remote.handler(type, ...args);\n }\n};\n\n/**\n * Gets the console method for a given log type.\n */\nconst getConsoleMethod = (type: LogitType): keyof Console => {\n return (CONSOLE_METHOD_MAP[type] || type) as keyof Console;\n};\n\n/**\n * Generates CSS styles for log messages based on theme and variant.\n */\nconst style = (type: LogitColors, extra = ''): string => {\n const { bg, color, border } = Theme[type];\n const baseStyle = `color: ${bg}; border: 1px solid ${border}; border-radius: 4px;`;\n\n switch (state.variant) {\n case 'symbol':\n return `${baseStyle} padding: 1px 1px 0;${extra};`;\n case 'icon':\n return `${baseStyle} padding: 0 3px;${extra};`;\n default:\n return `background: ${bg}; color: ${color}; border: 1px solid ${border}; border-radius: 4px; font-weight: bold; padding: 0 3px;${extra}`;\n }\n};\n\n/**\n * Builds the format string and style parts for browser console logging.\n */\nfunction buildBrowserLogParts(type: LogitType): { format: string; parts: string[] } {\n const theme = Theme[type as LogitColors];\n const { namespace, variant, timestamp, environment } = state;\n\n let format = `%c${theme[variant as keyof LogitTheme] ?? type.toUpperCase()}%c`;\n const parts: string[] = [style(type as any), ''];\n\n if (namespace) {\n format += ` %c${namespace}%c`;\n parts.push(style('ns', ' border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter;'), '');\n }\n\n if (environment) {\n format += ` %c${getEnvIndicator()}%c`;\n parts.push('color: darkgray;', '');\n }\n\n if (timestamp) {\n format += ` %c${getTimestamp()}%c`;\n parts.push('color: gray;', '');\n }\n\n return { format, parts };\n}\n\n/**\n * Logs messages to the console with styling and metadata.\n */\nconst log = (type: LogitType, ...args: any[]): void => {\n // Server-side logging (Node.js)\n if (typeof window === 'undefined') {\n const theme = Theme[type as LogitColors];\n const { variant } = state;\n const consoleMethod = console[getConsoleMethod(type)] as (...a: any) => void;\n consoleMethod(`${theme[variant as keyof LogitTheme] ?? type.toUpperCase()} | ${getEnvIndicator()} |`, ...args);\n return;\n }\n\n // Check log level\n if (!shouldLog(type)) return;\n\n // Browser-side logging with styling\n const { format, parts } = buildBrowserLogParts(type);\n const consoleMethod = console[getConsoleMethod(type)] as (...a: any) => void;\n\n consoleMethod(format, ...parts, ...args);\n sendRemoteLog(type, args);\n};\n\n/**\n * Formats the elapsed time for display.\n */\nconst formatElapsedTime = (startTime: number): string => {\n const elapsed = Math.floor(Date.now() - startTime);\n return elapsed ? `${elapsed}ms` : '';\n};\n\nexport const Logit = {\n /**\n * Asserts a condition and logs an error if it's false.\n */\n assert: (valid: boolean, message: string, context: Record<string, any>): void =>\n console.assert(valid, message, context),\n\n debug: (...args: any[]): void => log('debug', ...args),\n error: (...args: any[]): void => log('error', ...args),\n\n /**\n * Gets the current log level.\n */\n getLevel: (): LogitLevel => state.logLevel,\n\n /**\n * Gets the current namespace prefix.\n */\n getPrefix: (): string => state.namespace,\n\n /**\n * Gets whether timestamps are shown.\n */\n getTimestamp: (): boolean => state.timestamp,\n\n /**\n * Creates a collapsed group in the console.\n */\n groupCollapsed: (text: string, label = 'GROUP', time = Date.now()): void => {\n if (!shouldLog('success')) return;\n\n const elapsed = formatElapsedTime(time);\n const env = getEnvIndicator();\n\n console.groupCollapsed(\n `%c${label}%c${state.namespace}%c${env}%c${state.timestamp ? getTimestamp() : ''}%c${elapsed}%c${text}`,\n style('group', 'margin-right: 6px; padding: 1px 3px 0'),\n style('ns', ' border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter;margin-right: 6px;'),\n 'color: darkgray; margin-right: 6px;',\n 'color: gray;font-weight: lighter;margin-right: 6px;',\n 'color: gray; font-weight: lighter;margin-right: 6px;',\n 'color: inherit;font-weight: lighter;',\n );\n },\n\n /**\n * Ends the current console group.\n */\n groupEnd: (): void => {\n if (shouldLog('success')) console.groupEnd();\n },\n\n info: (...args: any[]): void => log('info', ...args),\n\n /**\n * Initializes Logit with custom options.\n */\n initialise: (options: LogitOptions): void => {\n Object.assign(state, options);\n },\n\n /**\n * Sets the minimum log level to display.\n */\n setLogLevel: (level: LogitLevel): void => {\n state.logLevel = level;\n },\n\n /**\n * Sets the namespace prefix for all logs.\n */\n setPrefix: (namespace: string): void => {\n state.namespace = namespace;\n },\n\n /**\n * Configures remote logging options.\n */\n setRemote: (remote: LogitRemoteOptions): void => {\n state.remote = remote;\n },\n\n /**\n * Sets the log level for remote logging.\n */\n setRemoteLogLevel: (level: LogitLevel): void => {\n state.remote.logLevel = level;\n },\n\n /**\n * Sets the display variant (text, icon, or symbol).\n */\n setVariant: (variant: 'text' | 'icon' | 'symbol'): void => {\n state.variant = variant;\n },\n\n /**\n * Shows or hides the environment indicator.\n */\n showEnvironment: (value: boolean): void => {\n state.environment = value;\n },\n\n /**\n * Shows or hides timestamps in logs.\n */\n showTimestamp: (value: boolean): void => {\n state.timestamp = value;\n },\n\n success: (...args: any[]): void => log('success', ...args),\n\n /**\n * Displays data in a table format.\n */\n table: (...args: any[]): void => {\n if (shouldLog('table')) console.table(...args);\n },\n\n /**\n * Starts a timer with the given label.\n */\n time: (label: string): void => {\n if (shouldLog('time')) console.time(label);\n },\n\n /**\n * Ends a timer with the given label.\n */\n timeEnd: (label: string): void => {\n if (shouldLog('time')) console.timeEnd(label);\n },\n\n trace: (...args: any[]): void => log('trace', ...args),\n warn: (...args: any[]): void => log('warn', ...args),\n};\n\nif (typeof window !== 'undefined') {\n window.Logit = Logit;\n}\n"],"names":["CONSOLE_METHOD_MAP","isProd","__vite_import_meta_env__","isDark","Theme","logLevel","state","shouldLog","type","getTimestamp","getEnvIndicator","sendRemoteLog","args","getConsoleMethod","style","extra","bg","color","border","baseStyle","buildBrowserLogParts","theme","namespace","variant","timestamp","environment","format","parts","log","consoleMethod","formatElapsedTime","startTime","elapsed","Logit","valid","message","context","text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AAAA;AAAA;AAAA;AAAA,EAKA,iBAAiB,CAACqB,MAAyB;AACzC,IAAAtC,EAAM,cAAcsC;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKA,eAAe,CAACA,MAAyB;AACvC,IAAAtC,EAAM,YAAYsC;AAAA,EACpB;AAAA,EAEA,SAAS,IAAIhC,MAAsBgB,EAAI,WAAW,GAAGhB,CAAI;AAAA;AAAA;AAAA;AAAA,EAKzD,OAAO,IAAIA,MAAsB;AAC/B,IAAIL,EAAU,OAAO,KAAG,QAAQ,MAAM,GAAGK,CAAI;AAAA,EAC/C;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,CAAC0B,MAAwB;AAC7B,IAAI/B,EAAU,MAAM,KAAG,QAAQ,KAAK+B,CAAK;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA,EAKA,SAAS,CAACA,MAAwB;AAChC,IAAI/B,EAAU,MAAM,KAAG,QAAQ,QAAQ+B,CAAK;AAAA,EAC9C;AAAA,EAEA,OAAO,IAAI1B,MAAsBgB,EAAI,SAAS,GAAGhB,CAAI;AAAA,EACrD,MAAM,IAAIA,MAAsBgB,EAAI,QAAQ,GAAGhB,CAAI;AACrD;AAEI,OAAO,SAAW,QACpB,OAAO,QAAQqB;"}
1
+ {"version":3,"file":"logit.js","sources":["../src/logit.ts"],"sourcesContent":["/** biome-ignore-all lint/suspicious/noAssignInExpressions: - */\n/** biome-ignore-all lint/suspicious/noExplicitAny: - */\n\n/**\n * Environment indicator symbols.\n */\nconst ENV_PROD = '\\uD83C\\uDD3F'; // 🅿\nconst ENV_DEV = '\\uD83C\\uDD33'; // 🅳\n\n/**\n * Console method mappings for log types.\n */\nconst CONSOLE_METHOD_MAP: Record<string, keyof Console> = {\n debug: 'log',\n success: 'log',\n} as const;\n\n/**\n * Checks if the current environment is production.\n * Cached for performance - evaluated once at a module load.\n */\nconst isProduction = (): boolean => {\n // Browser environment (Vite, Webpack, etc.)\n if (typeof window !== 'undefined' && (import.meta as any)?.env?.NODE_ENV) {\n return (import.meta as any).env.NODE_ENV === 'production';\n }\n\n // Node.js environment\n // @ts-expect-error\n if (typeof process !== 'undefined' && (process as any).env?.NODE_ENV) {\n // @ts-expect-error\n return (process as any).env.NODE_ENV === 'production';\n }\n\n return false;\n};\n\n// Cache the result to avoid repeated checks\nconst IS_PROD = isProduction();\n\nexport type LogitInstance = typeof Logit;\nexport type LogitType = 'debug' | 'trace' | 'time' | 'table' | 'info' | 'success' | 'warn' | 'error';\nexport type LogitColors = Exclude<LogitType, 'table'> | 'group' | 'ns';\nexport type LogitLevel = LogitType | 'off';\nexport type LogitRemoteOptions = {\n handler?: (...args: any[]) => void;\n logLevel: LogitLevel;\n};\nexport type LogitOptions = {\n environment?: boolean;\n variant?: 'text' | 'symbol' | 'icon';\n logLevel?: LogitLevel;\n namespace?: string;\n remote?: LogitRemoteOptions;\n timestamp?: boolean;\n};\nexport type LogitTheme = { color: string; bg: string; border: string; icon?: string; symbol?: string };\n\n/**\n * Detects dark mode preference at module load time.\n * Note: This is intentionally static and won't update if the user changes their theme.\n */\nconst isDark = typeof window !== 'undefined' && window.matchMedia?.('(prefers-color-scheme: dark)').matches;\n\nconst Theme: Readonly<Record<LogitColors, LogitTheme>> = {\n debug: { bg: '#616161', border: '#424242', color: '#fff', icon: '\\u2615', symbol: '\\uD83C\\uDD73' },\n error: { bg: '#d32f2f', border: '#c62828', color: '#fff', icon: '\\u2718', symbol: '\\uD83C\\uDD74' },\n group: { bg: '#546e7a', border: '#455a64', color: '#fff', icon: '\\u26AD', symbol: '\\uD83C\\uDD76' },\n info: { bg: '#1976d2', border: '#1565c0', color: '#fff', icon: '\\u2139', symbol: '\\uD83C\\uDD78' },\n ns: isDark\n ? { bg: '#fafafa', border: '#c7c7c7', color: '#000' }\n : { bg: '#424242', border: '#212121', color: '#fff' },\n success: { bg: '#689f38', border: '#558b2f', color: '#fff', icon: '\\u2714', symbol: '\\uD83C\\uDD82' },\n time: { bg: '#0097a7', border: '#00838f', color: '#fff', icon: '\\u23F2', symbol: '\\uD83C\\uDD83' },\n trace: { bg: '#d81b60', border: '#c2185b', color: '#fff', icon: '\\u26e2', symbol: '\\uD83C\\uDD83' },\n warn: { bg: '#ffb300', border: '#ffa000', color: '#fff', icon: '\\u26a0', symbol: '\\uD83C\\uDD86' },\n};\n\n// biome-ignore assist/source/useSortedKeys: -\nconst logLevel: Readonly<Record<LogitLevel, number>> = {\n debug: 0,\n trace: 1,\n time: 2,\n table: 3,\n info: 4,\n success: 5,\n warn: 6,\n error: 7,\n off: 8,\n};\n\nconst state: Required<LogitOptions> = {\n environment: true,\n logLevel: 'debug',\n namespace: '',\n remote: { handler: undefined, logLevel: 'off' },\n timestamp: true,\n variant: 'symbol',\n};\n\n/**\n * Determines if a log message should be shown based on the current log level.\n */\nconst shouldLog = (type: LogitType): boolean => logLevel[state.logLevel] <= logLevel[type];\n\n/**\n * Gets the current timestamp in ISO format (HH:MM:SS.mmm).\n */\nconst getCurrentTimestamp = (): string => new Date().toISOString().slice(11, 23);\n\n/**\n * Gets the environment indicator symbol.\n */\nconst getEnvIndicator = (): string => (IS_PROD ? ENV_PROD : ENV_DEV);\n\n/**\n * Sends log data to remote handler if configured.\n */\nconst sendRemoteLog = (type: LogitType, args: any[]): void => {\n if (state.remote.handler && logLevel[state.remote.logLevel] <= logLevel[type]) {\n state.remote.handler(type, ...args);\n }\n};\n\n/**\n * Gets the console method for a given log type.\n */\nconst getConsoleMethod = (type: LogitType): keyof Console => {\n return (CONSOLE_METHOD_MAP[type] || type) as keyof Console;\n};\n\n/**\n * CSS style constants for consistent formatting.\n */\nconst BASE_BORDER_STYLE = 'border: 1px solid';\nconst BASE_BORDER_RADIUS = 'border-radius: 4px';\nconst NAMESPACE_STYLE = 'border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter';\n\n/**\n * Generates CSS styles for log messages based on theme and variant.\n */\nconst style = (type: LogitColors, extra = ''): string => {\n const { bg, color, border } = Theme[type];\n const baseStyle = `color: ${bg}; ${BASE_BORDER_STYLE} ${border}; ${BASE_BORDER_RADIUS}`;\n\n switch (state.variant) {\n case 'symbol':\n return `${baseStyle}; padding: 1px 1px 0${extra}`;\n case 'icon':\n return `${baseStyle}; padding: 0 3px${extra}`;\n default:\n return `background: ${bg}; color: ${color}; ${BASE_BORDER_STYLE} ${border}; ${BASE_BORDER_RADIUS}; font-weight: bold; padding: 0 3px${extra}`;\n }\n};\n\n/**\n * Gets the display value for a log type based on current variant.\n */\nconst getDisplayValue = (type: LogitType): string => {\n const theme = Theme[type as LogitColors];\n const { variant } = state;\n\n // For 'text' variant or if the variant key doesn't exist, use uppercase type\n if (variant === 'text' || !theme[variant]) {\n return type.toUpperCase();\n }\n\n return theme[variant] as string;\n};\n\n/**\n * Builds the format string and style parts for browser console logging.\n */\nfunction buildBrowserLogParts(type: LogitType): { format: string; parts: string[] } {\n const { namespace, timestamp, environment } = state;\n\n let format = `%c${getDisplayValue(type)}%c`;\n const parts: string[] = [style(type as LogitColors), ''];\n\n if (namespace) {\n format += ` %c${namespace}%c`;\n parts.push(style('ns', `; ${NAMESPACE_STYLE}`), '');\n }\n\n if (environment) {\n format += ` %c${getEnvIndicator()}%c`;\n parts.push('color: darkgray', '');\n }\n\n if (timestamp) {\n format += ` %c${getCurrentTimestamp()}%c`;\n parts.push('color: gray', '');\n }\n\n return { format, parts };\n}\n\n/**\n * Logs messages to the console with styling and metadata.\n */\nconst log = (type: LogitType, ...args: any[]): void => {\n // Server-side logging (Node.js)\n if (typeof window === 'undefined') {\n const consoleMethod = console[getConsoleMethod(type)] as (...a: any[]) => void;\n consoleMethod(`${getDisplayValue(type)} | ${getEnvIndicator()} |`, ...args);\n return;\n }\n\n // Check log level\n if (!shouldLog(type)) return;\n\n // Browser-side logging with styling\n const { format, parts } = buildBrowserLogParts(type);\n const consoleMethod = console[getConsoleMethod(type)] as (...a: any[]) => void;\n\n consoleMethod(format, ...parts, ...args);\n sendRemoteLog(type, args);\n};\n\n/**\n * Formats the elapsed time for display.\n */\nconst formatElapsedTime = (startTime: number): string => {\n const elapsed = Math.floor(Date.now() - startTime);\n return elapsed ? `${elapsed}ms` : '';\n};\n\nexport const Logit = {\n /**\n * Asserts a condition and logs an error if it's false.\n */\n assert: (valid: boolean, message: string, context: Record<string, any>): void =>\n console.assert(valid, message, context),\n\n debug: (...args: any[]): void => log('debug', ...args),\n error: (...args: any[]): void => log('error', ...args),\n\n /**\n * Gets the current log level.\n */\n getLevel: (): LogitLevel => state.logLevel,\n\n /**\n * Gets the current namespace prefix.\n */\n getPrefix: (): string => state.namespace,\n\n /**\n * Gets whether timestamps are shown.\n */\n getTimestamp: (): boolean => state.timestamp,\n\n /**\n * Creates a collapsed group in the console.\n */\n groupCollapsed: (text: string, label = 'GROUP', time = Date.now()): void => {\n if (!shouldLog('success')) return;\n\n const elapsed = formatElapsedTime(time);\n const env = getEnvIndicator();\n const timestamp = state.timestamp ? getCurrentTimestamp() : '';\n\n console.groupCollapsed(\n `%c${label}%c${state.namespace}%c${env}%c${timestamp}%c${elapsed}%c${text}`,\n style('group', '; margin-right: 6px; padding: 1px 3px 0'),\n style('ns', `; ${NAMESPACE_STYLE}; margin-right: 6px`),\n 'color: darkgray; margin-right: 6px',\n 'color: gray; font-weight: lighter; margin-right: 6px',\n 'color: gray; font-weight: lighter; margin-right: 6px',\n 'color: inherit; font-weight: lighter',\n );\n },\n\n /**\n * Ends the current console group.\n */\n groupEnd: (): void => {\n if (shouldLog('success')) console.groupEnd();\n },\n\n info: (...args: any[]): void => log('info', ...args),\n\n /**\n * Initializes Logit with custom options.\n */\n initialise: (options: LogitOptions): void => {\n Object.assign(state, options);\n },\n\n /**\n * Sets the minimum log level to display.\n */\n setLogLevel: (level: LogitLevel): void => {\n state.logLevel = level;\n },\n\n /**\n * Sets the namespace prefix for all logs.\n */\n setPrefix: (namespace: string): void => {\n state.namespace = namespace;\n },\n\n /**\n * Configures remote logging options.\n */\n setRemote: (remote: LogitRemoteOptions): void => {\n state.remote = remote;\n },\n\n /**\n * Sets the log level for remote logging.\n */\n setRemoteLogLevel: (level: LogitLevel): void => {\n state.remote.logLevel = level;\n },\n\n /**\n * Sets the display variant (text, icon, or symbol).\n */\n setVariant: (variant: 'text' | 'icon' | 'symbol'): void => {\n state.variant = variant;\n },\n\n /**\n * Shows or hides the environment indicator.\n */\n showEnvironment: (value: boolean): void => {\n state.environment = value;\n },\n\n /**\n * Shows or hides timestamps in logs.\n */\n showTimestamp: (value: boolean): void => {\n state.timestamp = value;\n },\n\n success: (...args: any[]): void => log('success', ...args),\n\n /**\n * Displays data in a table format.\n */\n table: (...args: any[]): void => {\n if (shouldLog('table')) console.table(...args);\n },\n\n /**\n * Starts a timer with the given label.\n */\n time: (label: string): void => {\n if (shouldLog('time')) console.time(label);\n },\n\n /**\n * Ends a timer with the given label.\n */\n timeEnd: (label: string): void => {\n if (shouldLog('time')) console.timeEnd(label);\n },\n\n trace: (...args: any[]): void => log('trace', ...args),\n warn: (...args: any[]): void => log('warn', ...args),\n};\n\n"],"names":["CONSOLE_METHOD_MAP","isProduction","__vite_import_meta_env__","IS_PROD","isDark","Theme","logLevel","state","shouldLog","type","getCurrentTimestamp","getEnvIndicator","sendRemoteLog","args","getConsoleMethod","BASE_BORDER_STYLE","BASE_BORDER_RADIUS","NAMESPACE_STYLE","style","extra","bg","color","border","baseStyle","getDisplayValue","theme","variant","buildBrowserLogParts","namespace","timestamp","environment","format","parts","log","consoleMethod","formatElapsedTime","startTime","elapsed","Logit","valid","message","context","text","label","time","env","options","level","remote","value"],"mappings":";AAYA,MAAMA,IAAoD;AAAA,EACxD,OAAO;AAAA,EACP,SAAS;AACX,GAMMC,IAAe,MAEf,OAAO,SAAW,OAAgBC,GAA0B,WACtD,KAKN,OAAO,UAAY,OAAgB,QAAgB,KAAK,WAElD,QAAgB,IAAI,aAAa,eAGpC,IAIHC,IAAUF,EAAA,GAwBVG,IAAS,OAAO,SAAW,OAAe,OAAO,aAAa,8BAA8B,EAAE,SAE9FC,IAAmD;AA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