Files
DeviceManager/_app/immutable/chunks/tauri-serial.BP-n-twb.js
2024-07-09 14:44:55 +00:00

4 lines
16 KiB
JavaScript

import{s as Q,e as w,a as S,c as f,b as q,g as v,l as N,f as M,i as G,h as y,q as C,n as R,C as Z,r as K,W as Y,T as X,t as B,d as ee,m as D,L as z,j as ae}from"./scheduler.CXEVs2ap.js";import{e as T}from"./each.CypvCfon.js";import{S as te,i as ne}from"./index.CTdcniaS.js";function ie(){return window.crypto.getRandomValues(new Uint32Array(1))[0]}function P(a,e=!1){const t=ie(),i=`_${t}`;return Object.defineProperty(window,i,{value:l=>(e&&Reflect.deleteProperty(window,i),a?.(l)),writable:!1,configurable:!0}),t}async function $(a,e={}){return new Promise((t,i)=>{const l=P(u=>{t(u),Reflect.deleteProperty(window,`_${r}`)},!0),r=P(u=>{i(u),Reflect.deleteProperty(window,`_${l}`)},!0);window.__TAURI_IPC__({cmd:a,callback:l,error:r,...e})})}async function n(a){return $("tauri",a)}async function j(a,e){return n({__tauriModule:"Event",message:{cmd:"unlisten",event:a,eventId:e}})}async function le(a,e,t){await n({__tauriModule:"Event",message:{cmd:"emit",event:a,windowLabel:e,payload:t}})}async function J(a,e,t){return n({__tauriModule:"Event",message:{cmd:"listen",event:a,windowLabel:e,handler:P(t)}}).then(i=>async()=>j(a,i))}async function se(a,e,t){return J(a,e,i=>{t(i),j(a,i.id).catch(()=>{})})}var m;(function(a){a.WINDOW_RESIZED="tauri://resize",a.WINDOW_MOVED="tauri://move",a.WINDOW_CLOSE_REQUESTED="tauri://close-requested",a.WINDOW_CREATED="tauri://window-created",a.WINDOW_DESTROYED="tauri://destroyed",a.WINDOW_FOCUS="tauri://focus",a.WINDOW_BLUR="tauri://blur",a.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",a.WINDOW_THEME_CHANGED="tauri://theme-changed",a.WINDOW_FILE_DROP="tauri://file-drop",a.WINDOW_FILE_DROP_HOVER="tauri://file-drop-hover",a.WINDOW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled",a.MENU="tauri://menu",a.CHECK_UPDATE="tauri://update",a.UPDATE_AVAILABLE="tauri://update-available",a.INSTALL_UPDATE="tauri://update-install",a.STATUS_UPDATE="tauri://update-status",a.DOWNLOAD_PROGRESS="tauri://update-download-progress"})(m||(m={}));var x;(function(a){a[a.Audio=1]="Audio",a[a.Cache=2]="Cache",a[a.Config=3]="Config",a[a.Data=4]="Data",a[a.LocalData=5]="LocalData",a[a.Desktop=6]="Desktop",a[a.Document=7]="Document",a[a.Download=8]="Download",a[a.Executable=9]="Executable",a[a.Font=10]="Font",a[a.Home=11]="Home",a[a.Picture=12]="Picture",a[a.Public=13]="Public",a[a.Runtime=14]="Runtime",a[a.Template=15]="Template",a[a.Video=16]="Video",a[a.Resource=17]="Resource",a[a.App=18]="App",a[a.Log=19]="Log",a[a.Temp=20]="Temp",a[a.AppConfig=21]="AppConfig",a[a.AppData=22]="AppData",a[a.AppLocalData=23]="AppLocalData",a[a.AppCache=24]="AppCache",a[a.AppLog=25]="AppLog"})(x||(x={}));var F;(function(a){a[a.JSON=1]="JSON",a[a.Text=2]="Text",a[a.Binary=3]="Binary"})(F||(F={}));function O(){return navigator.appVersion.includes("Win")}O();O();class re{constructor(e,t){this.type="Logical",this.width=e,this.height=t}}class A{constructor(e,t){this.type="Physical",this.width=e,this.height=t}toLogical(e){return new re(this.width/e,this.height/e)}}class oe{constructor(e,t){this.type="Logical",this.x=e,this.y=t}}class E{constructor(e,t){this.type="Physical",this.x=e,this.y=t}toLogical(e){return new oe(this.x/e,this.y/e)}}var I;(function(a){a[a.Critical=1]="Critical",a[a.Informational=2]="Informational"})(I||(I={}));function k(){return window.__TAURI_METADATA__.__windows.map(a=>new W(a.label,{skip:!0}))}const U=["tauri://created","tauri://error"];class de{constructor(e){this.label=e,this.listeners=Object.create(null)}async listen(e,t){return this._handleTauriEvent(e,t)?Promise.resolve(()=>{const i=this.listeners[e];i.splice(i.indexOf(t),1)}):J(e,this.label,t)}async once(e,t){return this._handleTauriEvent(e,t)?Promise.resolve(()=>{const i=this.listeners[e];i.splice(i.indexOf(t),1)}):se(e,this.label,t)}async emit(e,t){if(U.includes(e)){for(const i of this.listeners[e]||[])i({event:e,id:-1,windowLabel:this.label,payload:t});return Promise.resolve()}return le(e,this.label,t)}_handleTauriEvent(e,t){return U.includes(e)?(e in this.listeners?this.listeners[e].push(t):this.listeners[e]=[t],!0):!1}}class ue extends de{async scaleFactor(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"scaleFactor"}}}})}async innerPosition(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"innerPosition"}}}}).then(({x:e,y:t})=>new E(e,t))}async outerPosition(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"outerPosition"}}}}).then(({x:e,y:t})=>new E(e,t))}async innerSize(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"innerSize"}}}}).then(({width:e,height:t})=>new A(e,t))}async outerSize(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"outerSize"}}}}).then(({width:e,height:t})=>new A(e,t))}async isFullscreen(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isFullscreen"}}}})}async isMinimized(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isMinimized"}}}})}async isMaximized(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isMaximized"}}}})}async isFocused(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isFocused"}}}})}async isDecorated(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isDecorated"}}}})}async isResizable(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isResizable"}}}})}async isMaximizable(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isMaximizable"}}}})}async isMinimizable(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isMinimizable"}}}})}async isClosable(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isClosable"}}}})}async isVisible(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isVisible"}}}})}async title(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"title"}}}})}async theme(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"theme"}}}})}async center(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"center"}}}})}async requestUserAttention(e){let t=null;return e&&(e===I.Critical?t={type:"Critical"}:t={type:"Informational"}),n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"requestUserAttention",payload:t}}}})}async setResizable(e){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setResizable",payload:e}}}})}async setMaximizable(e){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setMaximizable",payload:e}}}})}async setMinimizable(e){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setMinimizable",payload:e}}}})}async setClosable(e){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setClosable",payload:e}}}})}async setTitle(e){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setTitle",payload:e}}}})}async maximize(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"maximize"}}}})}async unmaximize(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"unmaximize"}}}})}async toggleMaximize(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"toggleMaximize"}}}})}async minimize(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"minimize"}}}})}async unminimize(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"unminimize"}}}})}async show(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"show"}}}})}async hide(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"hide"}}}})}async close(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"close"}}}})}async setDecorations(e){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setDecorations",payload:e}}}})}async setAlwaysOnTop(e){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setAlwaysOnTop",payload:e}}}})}async setContentProtected(e){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setContentProtected",payload:e}}}})}async setSize(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setSize",payload:{type:e.type,data:{width:e.width,height:e.height}}}}}})}async setMinSize(e){if(e&&e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setMinSize",payload:e?{type:e.type,data:{width:e.width,height:e.height}}:null}}}})}async setMaxSize(e){if(e&&e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setMaxSize",payload:e?{type:e.type,data:{width:e.width,height:e.height}}:null}}}})}async setPosition(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setPosition",payload:{type:e.type,data:{x:e.x,y:e.y}}}}}})}async setFullscreen(e){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setFullscreen",payload:e}}}})}async setFocus(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setFocus"}}}})}async setIcon(e){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setIcon",payload:{icon:typeof e=="string"?e:Array.from(e)}}}}})}async setSkipTaskbar(e){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setSkipTaskbar",payload:e}}}})}async setCursorGrab(e){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setCursorGrab",payload:e}}}})}async setCursorVisible(e){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setCursorVisible",payload:e}}}})}async setCursorIcon(e){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setCursorIcon",payload:e}}}})}async setCursorPosition(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setCursorPosition",payload:{type:e.type,data:{x:e.x,y:e.y}}}}}})}async setIgnoreCursorEvents(e){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setIgnoreCursorEvents",payload:e}}}})}async startDragging(){return n({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"startDragging"}}}})}async onResized(e){return this.listen(m.WINDOW_RESIZED,t=>{t.payload=_e(t.payload),e(t)})}async onMoved(e){return this.listen(m.WINDOW_MOVED,t=>{t.payload=me(t.payload),e(t)})}async onCloseRequested(e){return this.listen(m.WINDOW_CLOSE_REQUESTED,t=>{const i=new ce(t);Promise.resolve(e(i)).then(()=>{if(!i.isPreventDefault())return this.close()})})}async onFocusChanged(e){const t=await this.listen(m.WINDOW_FOCUS,l=>{e({...l,payload:!0})}),i=await this.listen(m.WINDOW_BLUR,l=>{e({...l,payload:!1})});return()=>{t(),i()}}async onScaleChanged(e){return this.listen(m.WINDOW_SCALE_FACTOR_CHANGED,e)}async onMenuClicked(e){return this.listen(m.MENU,e)}async onFileDropEvent(e){const t=await this.listen(m.WINDOW_FILE_DROP,r=>{e({...r,payload:{type:"drop",paths:r.payload}})}),i=await this.listen(m.WINDOW_FILE_DROP_HOVER,r=>{e({...r,payload:{type:"hover",paths:r.payload}})}),l=await this.listen(m.WINDOW_FILE_DROP_CANCELLED,r=>{e({...r,payload:{type:"cancel"}})});return()=>{t(),i(),l()}}async onThemeChanged(e){return this.listen(m.WINDOW_THEME_CHANGED,e)}}class ce{constructor(e){this._preventDefault=!1,this.event=e.event,this.windowLabel=e.windowLabel,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}}class W extends ue{constructor(e,t={}){super(e),t?.skip||n({__tauriModule:"Window",message:{cmd:"createWebview",data:{options:{label:e,...t}}}}).then(async()=>this.emit("tauri://created")).catch(async i=>this.emit("tauri://error",i))}static getByLabel(e){return k().some(t=>t.label===e)?new W(e,{skip:!0}):null}static async getFocusedWindow(){for(const e of k())if(await e.isFocused())return e;return null}}"__TAURI_METADATA__"in window?new W(window.__TAURI_METADATA__.__currentWindow.label,{skip:!0}):(console.warn(`Could not find "window.__TAURI_METADATA__". The "appWindow" value will reference the "main" window label.
Note that this is not an issue if running this frontend on a browser instead of a Tauri window.`),new W("main",{skip:!0}));function me(a){return new E(a.x,a.y)}function _e(a){return new A(a.width,a.height)}O();const b=$;function H(a,e,t){const i=a.slice();i[7]=e[t];const l=i[7].getInfo();return i[8]=l,i}function V(a){let e,t=a[8].product+"",i,l,r,u=!1,h,_,g;return h=X(a[4][0]),{c(){e=w("label"),i=B(t),l=w("input"),this.h()},l(o){e=f(o,"LABEL",{});var s=q(e);i=ee(s,t),l=f(s,"INPUT",{type:!0,name:!0}),s.forEach(M),this.h()},h(){D(l,"type","radio"),D(l,"name","port"),l.__value=r=a[8].name,z(l,l.__value),h.p(l)},m(o,s){G(o,e,s),y(e,i),y(e,l),l.checked=l.__value===a[1],_||(g=C(l,"change",a[3]),_=!0)},p(o,s){s&1&&t!==(t=o[8].product+"")&&ae(i,t),s&1&&r!==(r=o[8].name)&&(l.__value=r,z(l,l.__value),u=!0),(u||s&3)&&(l.checked=l.__value===o[1])},d(o){o&&M(e),h.r(),_=!1,g()}}}function he(a){let e,t,i,l="Cancel",r,u,h="Ok",_,g,o=T(a[0]),s=[];for(let c=0;c<o.length;c+=1)s[c]=V(H(a,o,c));return{c(){e=w("dialog");for(let c=0;c<s.length;c+=1)s[c].c();t=S(),i=w("button"),i.textContent=l,r=S(),u=w("button"),u.textContent=h},l(c){e=f(c,"DIALOG",{});var p=q(e);for(let d=0;d<s.length;d+=1)s[d].l(p);t=v(p),i=f(p,"BUTTON",{"data-svelte-h":!0}),N(i)!=="svelte-1ays89h"&&(i.textContent=l),r=v(p),u=f(p,"BUTTON",{"data-svelte-h":!0}),N(u)!=="svelte-mb1c5p"&&(u.textContent=h),p.forEach(M)},m(c,p){G(c,e,p);for(let d=0;d<s.length;d+=1)s[d]&&s[d].m(e,null);y(e,t),y(e,i),y(e,r),y(e,u),_||(g=[C(i,"click",a[5]),C(u,"click",a[6])],_=!0)},p(c,[p]){if(p&3){o=T(c[0]);let d;for(d=0;d<o.length;d+=1){const L=H(c,o,d);s[d]?s[d].p(L,p):(s[d]=V(L),s[d].c(),s[d].m(e,t))}for(;d<s.length;d+=1)s[d].d(1);s.length=o.length}},i:R,o:R,d(c){c&&M(e),Z(s,c),_=!1,K(g)}}}function pe(a,e,t){let{ports:i}=e;const l=Y();let r=i[0]?.getInfo().name;const u=[[]];function h(){r=this.__value,t(1,r)}const _=()=>l("confirm",void 0),g=()=>l("confirm",i.find(o=>o.getInfo().name===r));return a.$$set=o=>{"ports"in o&&t(0,i=o.ports)},[i,r,l,h,u,_,g]}class ge extends te{constructor(e){super(),ne(this,e,pe,he,Q,{ports:0})}}function ye(a){return{getInfo(){return a},async open({baudRate:e}){await b("plugin:serial|open",{path:a.name,baudRate:e})},async close(){await b("plugin:serial|close",{path:a.name})},async forget(){},readable:new ReadableStream({async pull(e){const t=await b("plugin:serial|read",{path:a.name});e.enqueue(new Uint8Array(t))}}),writable:new WritableStream({async write(e){await b("plugin:serial|write",{path:a.name,chunk:Array.from(e)})}})}}navigator.serial={async getPorts(){return b("plugin:serial|get_serial_ports").then(a=>a.map(ye))},async requestPort(a){const e=await navigator.serial.getPorts().then(l=>a?.filters!==void 0?l.filter(r=>a.filters.some(({usbVendorId:u,usbProductId:h})=>{const _=r.getInfo();return(u===void 0||_.usbVendorId===u)&&(h===void 0||_.usbProductId===h)})):l),t=new ge({target:document.body,props:{ports:e}}),i=await new Promise(l=>t.$on("confirm",l));return t.$destroy(),i}};
//# sourceMappingURL=tauri-serial.BP-n-twb.js.map