copy plugin sources

This commit is contained in:
Jonas Kruckenberg
2022-12-14 18:43:39 +01:00
parent c15990d4e2
commit eb3495fb72
145 changed files with 16069 additions and 22 deletions
+176
View File
@@ -0,0 +1,176 @@
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
File diff suppressed because one or more lines are too long
+171
View File
@@ -0,0 +1,171 @@
import { invoke } from '@tauri-apps/api/tauri';
import { listen } from '@tauri-apps/api/event';
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 invoke("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 listen("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.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sources":["../index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAQA,IAAK,QA+BJ,CAAA;AA/BD,CAAA,UAAK,QAAQ,EAAA;AACX;;;;AAIG;AACH,IAAA,QAAA,CAAA,QAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,GAAA,OAAS,CAAA;AACT;;;;AAIG;AACH,IAAA,QAAA,CAAA,QAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,GAAA,OAAK,CAAA;AACL;;;;AAIG;AACH,IAAA,QAAA,CAAA,QAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAI,CAAA;AACJ;;;;AAIG;AACH,IAAA,QAAA,CAAA,QAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAI,CAAA;AACJ;;;;AAIG;AACH,IAAA,QAAA,CAAA,QAAA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,OAAO,CAAC,CAAC;gBAC/B,MAAM;YACR,KAAK,QAAQ,CAAC,IAAI;AAChB,gBAAA,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBAC9B,MAAM;YACR,KAAK,QAAQ,CAAC,IAAI;AAChB,gBAAA,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBAC9B,MAAM;YACR,KAAK,QAAQ,CAAC,KAAK;AACjB,gBAAA,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBAC/B,MAAM;AACR,YAAA;;gBAEE,MAAM,IAAI,KAAK,CAAC,CAAA,kBAAA,EAAqB,OAAO,CAAC,KAAK,CAAE,CAAA,CAAC,CAAC;AACzD,SAAA;AACH,KAAC,CAAC,CAAC;AACL;;;;"}
+206
View File
@@ -0,0 +1,206 @@
import { invoke } from "@tauri-apps/api/tauri";
import { listen, UnlistenFn } from "@tauri-apps/api/event";
export type LogOptions = {
file?: string;
line?: number;
} & Record<string, string | undefined>;
enum LogLevel {
/**
* The "trace" level.
*
* Designates very low priority, often extremely verbose, information.
*/
Trace = 1,
/**
* The "debug" level.
*
* Designates lower priority information.
*/
Debug,
/**
* The "info" level.
*
* Designates useful information.
*/
Info,
/**
* The "warn" level.
*
* Designates hazardous situations.
*/
Warn,
/**
* The "error" level.
*
* Designates very serious errors.
*/
Error,
}
async function log(
level: LogLevel,
message: string,
options?: LogOptions
): Promise<void> {
const traces = new Error().stack?.split("\n").map((line) => line.split("@"));
const filtered = traces?.filter(([name, location]) => {
return name.length > 0 && location !== "[native code]";
});
const { file, line, ...keyValues } = options ?? {};
await invoke("plugin:log|log", {
level,
message,
location: filtered?.[0]?.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}`);
* ```
*/
export async function error(
message: string,
options?: LogOptions
): Promise<void> {
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}!`);
* ```
*/
export async function warn(
message: string,
options?: LogOptions
): Promise<void> {
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`);
* ```
*/
export async function info(
message: string,
options?: LogOptions
): Promise<void> {
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}`);
* ```
*/
export async function debug(
message: string,
options?: LogOptions
): Promise<void> {
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}`);
* ```
*/
export async function trace(
message: string,
options?: LogOptions
): Promise<void> {
await log(LogLevel.Trace, message, options);
}
interface RecordPayload {
level: LogLevel;
message: string;
}
export async function attachConsole(): Promise<UnlistenFn> {
return await listen("log://log", (event) => {
const payload = event.payload as RecordPayload;
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}`);
}
});
}
+29
View File
@@ -0,0 +1,29 @@
{
"name": "tauri-plugin-log",
"version": "0.0.0",
"license": "MIT or APACHE-2.0",
"type": "module",
"browser": "dist/index.min.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"exports": {
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"browser": "./dist/index.min.js"
},
"scripts": {
"build": "rollup -c"
},
"files": [
"dist",
"!dist/**/*.map",
"README.md",
"LICENSE"
],
"devDependencies": {
"tslib": "^2.4.1"
},
"dependencies": {
"@tauri-apps/api": "^1.2.0"
}
}
+10
View File
@@ -0,0 +1,10 @@
import { readFileSync } from "fs";
import { createConfig } from "../../../shared/rollup.config.mjs";
export default createConfig({
pkg: JSON.parse(
readFileSync(new URL("./package.json", import.meta.url), "utf8")
),
external: [/^@tauri-apps\/api/],
});
+1
View File
@@ -0,0 +1 @@
../../../shared/tsconfig.json