You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tauri-plugins-workspace/plugins/log/guest-js/dist/index.min.js

177 lines
6.3 KiB

var d=Object.defineProperty;var e=(c,a)=>{for(var b in a)d(c,b,{get:a[b],enumerable:!0});};
var f={};e(f,{convertFileSrc:()=>w,invoke:()=>c$1,transformCallback:()=>s$1});function u$1(){return window.crypto.getRandomValues(new Uint32Array(1))[0]}function s$1(e,r=!1){let n=u$1(),t=`_${n}`;return Object.defineProperty(window,t,{value:o=>(r&&Reflect.deleteProperty(window,t),e==null?void 0:e(o)),writable:!1,configurable:!0}),n}async function c$1(e,r={}){return new Promise((n,t)=>{let o=s$1(i=>{n(i),Reflect.deleteProperty(window,`_${a}`);},!0),a=s$1(i=>{t(i),Reflect.deleteProperty(window,`_${o}`);},!0);window.__TAURI_IPC__({cmd:e,callback:o,error:a,...r});})}function w(e,r="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${r}.localhost/${n}`:`${r}://localhost/${n}`}
async function a(i){return c$1("tauri",i)}
var W={};e(W,{TauriEvent:()=>c,emit:()=>D,listen:()=>E,once:()=>_});async function s(n,t){return a({__tauriModule:"Event",message:{cmd:"unlisten",event:n,eventId:t}})}async function m(n,t,i){await a({__tauriModule:"Event",message:{cmd:"emit",event:n,windowLabel:t,payload:i}});}async function o(n,t,i){return a({__tauriModule:"Event",message:{cmd:"listen",event:n,windowLabel:t,handler:s$1(i)}}).then(r=>async()=>s(n,r))}async function u(n,t,i){return o(n,t,r=>{i(r),s(n,r.id).catch(()=>{});})}var c=(e=>(e.WINDOW_RESIZED="tauri://resize",e.WINDOW_MOVED="tauri://move",e.WINDOW_CLOSE_REQUESTED="tauri://close-requested",e.WINDOW_CREATED="tauri://window-created",e.WINDOW_DESTROYED="tauri://destroyed",e.WINDOW_FOCUS="tauri://focus",e.WINDOW_BLUR="tauri://blur",e.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",e.WINDOW_THEME_CHANGED="tauri://theme-changed",e.WINDOW_FILE_DROP="tauri://file-drop",e.WINDOW_FILE_DROP_HOVER="tauri://file-drop-hover",e.WINDOW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled",e.MENU="tauri://menu",e.CHECK_UPDATE="tauri://update",e.UPDATE_AVAILABLE="tauri://update-available",e.INSTALL_UPDATE="tauri://update-install",e.STATUS_UPDATE="tauri://update-status",e.DOWNLOAD_PROGRESS="tauri://update-download-progress",e))(c||{});async function E(n,t){return o(n,null,t)}async function _(n,t){return u(n,null,t)}async function D(n,t){return m(n,void 0,t)}
var LogLevel;
(function (LogLevel) {
/**
* The "trace" level.
*
* Designates very low priority, often extremely verbose, information.
*/
LogLevel[LogLevel["Trace"] = 1] = "Trace";
/**
* The "debug" level.
*
* Designates lower priority information.
*/
LogLevel[LogLevel["Debug"] = 2] = "Debug";
/**
* The "info" level.
*
* Designates useful information.
*/
LogLevel[LogLevel["Info"] = 3] = "Info";
/**
* The "warn" level.
*
* Designates hazardous situations.
*/
LogLevel[LogLevel["Warn"] = 4] = "Warn";
/**
* The "error" level.
*
* Designates very serious errors.
*/
LogLevel[LogLevel["Error"] = 5] = "Error";
})(LogLevel || (LogLevel = {}));
async function log(level, message, options) {
var _a, _b;
const traces = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n").map((line) => line.split("@"));
const filtered = traces === null || traces === void 0 ? void 0 : traces.filter(([name, location]) => {
return name.length > 0 && location !== "[native code]";
});
const { file, line, ...keyValues } = options !== null && options !== void 0 ? options : {};
await c$1("plugin:log|log", {
level,
message,
location: (_b = filtered === null || filtered === void 0 ? void 0 : filtered[0]) === null || _b === void 0 ? void 0 : _b.filter((v) => v.length > 0).join("@"),
file,
line,
keyValues,
});
}
/**
* Logs a message at the error level.
*
* @param message
*
* # Examples
*
* ```js
* import { error } from 'tauri-plugin-log-api';
*
* const err_info = "No connection";
* const port = 22;
*
* error(`Error: ${err_info} on port ${port}`);
* ```
*/
async function error(message, options) {
await log(LogLevel.Error, message, options);
}
/**
* Logs a message at the warn level.
*
* @param message
*
* # Examples
*
* ```js
* import { warn } from 'tauri-plugin-log-api';
*
* const warn_description = "Invalid Input";
*
* warn(`Warning! {warn_description}!`);
* ```
*/
async function warn(message, options) {
await log(LogLevel.Warn, message, options);
}
/**
* Logs a message at the info level.
*
* @param message
*
* # Examples
*
* ```js
* import { info } from 'tauri-plugin-log-api';
*
* const conn_info = { port: 40, speed: 3.20 };
*
* info(`Connected to port {conn_info.port} at {conn_info.speed} Mb/s`);
* ```
*/
async function info(message, options) {
await log(LogLevel.Info, message, options);
}
/**
* Logs a message at the debug level.
*
* @param message
*
* # Examples
*
* ```js
* import { debug } from 'tauri-plugin-log-api';
*
* const pos = { x: 3.234, y: -1.223 };
*
* debug(`New position: x: {pos.x}, y: {pos.y}`);
* ```
*/
async function debug(message, options) {
await log(LogLevel.Debug, message, options);
}
/**
* Logs a message at the trace level.
*
* @param message
*
* # Examples
*
* ```js
* import { trace } from 'tauri-plugin-log-api';
*
* let pos = { x: 3.234, y: -1.223 };
*
* trace(`Position is: x: {pos.x}, y: {pos.y}`);
* ```
*/
async function trace(message, options) {
await log(LogLevel.Trace, message, options);
}
async function attachConsole() {
return await E("log://log", (event) => {
const payload = event.payload;
switch (payload.level) {
case LogLevel.Trace:
console.log(payload.message);
break;
case LogLevel.Debug:
console.debug(payload.message);
break;
case LogLevel.Info:
console.info(payload.message);
break;
case LogLevel.Warn:
console.warn(payload.message);
break;
case LogLevel.Error:
console.error(payload.message);
break;
default:
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
throw new Error(`unknown log level ${payload.level}`);
}
});
}
export { attachConsole, debug, error, info, trace, warn };
//# sourceMappingURL=index.min.js.map