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/fs/src/api-iife.js

2 lines
7.4 KiB

if("__TAURI__"in window){var __TAURI_FS__=function(e){"use strict";var t=Object.defineProperty,n=(e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})},r=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},i=(e,t,n)=>(r(e,t,"read from private field"),n?n.call(e):t.get(e));function o(e,t=!1){let n=window.crypto.getRandomValues(new Uint32Array(1))[0],r=`_${n}`;return Object.defineProperty(window,r,{value:n=>(t&&Reflect.deleteProperty(window,r),e?.(n)),writable:!1,configurable:!0}),n}n({},{Channel:()=>c,PluginListener:()=>s,addPluginListener:()=>u,convertFileSrc:()=>l,invoke:()=>p,transformCallback:()=>o});var a,c=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)})(this,a,(()=>{})),this.id=o((e=>{i(this,a).call(this,e)}))}set onmessage(e){((e,t,n,i)=>{r(e,t,"write to private field"),i?i.call(e,n):t.set(e,n)})(this,a,e)}get onmessage(){return i(this,a)}toJSON(){return`__CHANNEL__:${this.id}`}};a=new WeakMap;var s=class{constructor(e,t,n){this.plugin=e,this.event=t,this.channelId=n}async unregister(){return p(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function u(e,t,n){let r=new c;return r.onmessage=n,p(`plugin:${e}|register_listener`,{event:t,handler:r}).then((()=>new s(e,t,r.id)))}async function p(e,t={}){return new Promise(((n,r)=>{let i=o((e=>{n(e),Reflect.deleteProperty(window,`_${a}`)}),!0),a=o((e=>{r(e),Reflect.deleteProperty(window,`_${i}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:i,error:a,...t})}))}function l(e,t="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${t}.localhost/${n}`:`${t}://localhost/${n}`}function d(){return navigator.appVersion.includes("Win")}n({},{BaseDirectory:()=>y,appCacheDir:()=>g,appConfigDir:()=>f,appDataDir:()=>h,appLocalDataDir:()=>w,appLogDir:()=>x,audioDir:()=>v,basename:()=>H,cacheDir:()=>m,configDir:()=>A,dataDir:()=>D,delimiter:()=>$,desktopDir:()=>I,dirname:()=>M,documentDir:()=>R,downloadDir:()=>b,executableDir:()=>T,extname:()=>S,fontDir:()=>U,homeDir:()=>E,isAbsolute:()=>W,join:()=>B,localDataDir:()=>O,normalize:()=>z,pictureDir:()=>C,publicDir:()=>N,resolve:()=>k,resolveResource:()=>V,resourceDir:()=>P,runtimeDir:()=>j,sep:()=>L,templateDir:()=>F,videoDir:()=>K});var _,y=((_=y||{})[_.Audio=1]="Audio",_[_.Cache=2]="Cache",_[_.Config=3]="Config",_[_.Data=4]="Data",_[_.LocalData=5]="LocalData",_[_.Document=6]="Document",_[_.Download=7]="Download",_[_.Picture=8]="Picture",_[_.Public=9]="Public",_[_.Video=10]="Video",_[_.Resource=11]="Resource",_[_.Temp=12]="Temp",_[_.AppConfig=13]="AppConfig",_[_.AppData=14]="AppData",_[_.AppLocalData=15]="AppLocalData",_[_.AppCache=16]="AppCache",_[_.AppLog=17]="AppLog",_[_.Desktop=18]="Desktop",_[_.Executable=19]="Executable",_[_.Font=20]="Font",_[_.Home=21]="Home",_[_.Runtime=22]="Runtime",_[_.Template=23]="Template",_);async function f(){return p("plugin:path|resolve_directory",{directory:13})}async function h(){return p("plugin:path|resolve_directory",{directory:14})}async function w(){return p("plugin:path|resolve_directory",{directory:15})}async function g(){return p("plugin:path|resolve_directory",{directory:16})}async function v(){return p("plugin:path|resolve_directory",{directory:1})}async function m(){return p("plugin:path|resolve_directory",{directory:2})}async function A(){return p("plugin:path|resolve_directory",{directory:3})}async function D(){return p("plugin:path|resolve_directory",{directory:4})}async function I(){return p("plugin:path|resolve_directory",{directory:18})}async function R(){return p("plugin:path|resolve_directory",{directory:6})}async function b(){return p("plugin:path|resolve_directory",{directory:7})}async function T(){return p("plugin:path|resolve_directory",{directory:19})}async function U(){return p("plugin:path|resolve_directory",{directory:20})}async function E(){return p("plugin:path|resolve_directory",{directory:21})}async function O(){return p("plugin:path|resolve_directory",{directory:5})}async function C(){return p("plugin:path|resolve_directory",{directory:8})}async function N(){return p("plugin:path|resolve_directory",{directory:9})}async function P(){return p("plugin:path|resolve_directory",{directory:11})}async function V(e){return p("plugin:path|resolve_directory",{directory:11,path:e})}async function j(){return p("plugin:path|resolve_directory",{directory:22})}async function F(){return p("plugin:path|resolve_directory",{directory:23})}async function K(){return p("plugin:path|resolve_directory",{directory:10})}async function x(){return p("plugin:path|resolve_directory",{directory:17})}var L=d()?"\\":"/",$=d()?";":":";async function k(...e){return p("plugin:path|resolve",{paths:e})}async function z(e){return p("plugin:path|normalize",{path:e})}async function B(...e){return p("plugin:path|join",{paths:e})}async function M(e){return p("plugin:path|dirname",{path:e})}async function S(e){return p("plugin:path|extname",{path:e})}async function H(e,t){return p("plugin:path|basename",{path:e,ext:t})}async function W(e){return p("plugin:path|isAbsolute",{path:e})}async function J(e,t,n){"object"==typeof n&&Object.freeze(n),"object"==typeof e&&Object.freeze(e);const r={path:"",contents:""};let i=n;return"string"==typeof e?r.path=e:(r.path=e.path,r.contents=e.contents),"string"==typeof t?r.contents=null!=t?t:"":i=t,await window.__TAURI_INVOKE__("plugin:fs|write_file",{path:r.path,contents:Array.from((new TextEncoder).encode(r.contents)),options:i})}return e.BaseDirectory=y,e.Dir=y,e.copyFile=async function(e,t,n={}){return await window.__TAURI_INVOKE__("plugin:fs|copy_file",{source:e,destination:t,options:n})},e.createDir=async function(e,t={}){return await window.__TAURI_INVOKE__("plugin:fs|create_dir",{path:e,options:t})},e.exists=async function(e){return await window.__TAURI_INVOKE__("plugin:fs|exists",{path:e})},e.metadata=async function(e){return await window.__TAURI_INVOKE__("plugin:fs|metadata",{path:e}).then((e=>{const{accessedAtMs:t,createdAtMs:n,modifiedAtMs:r,...i}=e;return{accessedAt:new Date(t),createdAt:new Date(n),modifiedAt:new Date(r),...i}}))},e.readBinaryFile=async function(e,t={}){const n=await window.__TAURI_INVOKE__("plugin:fs|read_file",{path:e,options:t});return Uint8Array.from(n)},e.readDir=async function(e,t={}){return await window.__TAURI_INVOKE__("plugin:fs|read_dir",{path:e,options:t})},e.readTextFile=async function(e,t={}){return await window.__TAURI_INVOKE__("plugin:fs|read_text_file",{path:e,options:t})},e.removeDir=async function(e,t={}){return await window.__TAURI_INVOKE__("plugin:fs|remove_dir",{path:e,options:t})},e.removeFile=async function(e,t={}){return await window.__TAURI_INVOKE__("plugin:fs|remove_file",{path:e,options:t})},e.renameFile=async function(e,t,n={}){return await window.__TAURI_INVOKE__("plugin:fs|rename_file",{oldPath:e,newPath:t,options:n})},e.writeBinaryFile=async function(e,t,n){"object"==typeof n&&Object.freeze(n),"object"==typeof e&&Object.freeze(e);const r={path:"",contents:[]};let i=n;return"string"==typeof e?r.path=e:(r.path=e.path,r.contents=e.contents),t&&"dir"in t?i=t:"string"==typeof e&&(r.contents=null!=t?t:[]),await window.__TAURI_INVOKE__("plugin:fs|write_binary_file",{path:r.path,contents:Array.from(r.contents instanceof ArrayBuffer?new Uint8Array(r.contents):r.contents),options:i})},e.writeFile=J,e.writeTextFile=J,e}({});Object.defineProperty(window.__TAURI__,"fs",{value:__TAURI_FS__})}