5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-05 07:19:04 +08:00
wails/v3/internal/runtime/runtime_production_desktop_windows.js

2 lines
8.7 KiB
JavaScript

(()=>{var pe=Object.defineProperty;var v=(e,t)=>{for(var n in t)pe(e,n,{get:t[n],enumerable:!0})};var k={};v(k,{SetText:()=>Ce,Text:()=>ve});var we=window.location.origin+"/wails/runtime",l={Call:0,Clipboard:1,Application:2,Events:3,ContextMenu:4,Dialog:5,Window:6,Screens:7,System:8};function ge(e,t,n,o){let i=new URL(we);i.searchParams.append("object",e),i.searchParams.append("method",t);let r={headers:{}};return n&&(r.headers["x-wails-window-name"]=n),o&&i.searchParams.append("args",JSON.stringify(o)),new Promise((u,p)=>{fetch(i,r).then(s=>{if(s.ok)return s.headers.get("Content-Type")&&s.headers.get("Content-Type").indexOf("application/json")!==-1?s.json():s.text();p(Error(s.statusText))}).then(s=>u(s)).catch(s=>p(s))})}function a(e,t){return function(n,o=null){return ge(e,n,t,o)}}var F=a(l.Clipboard),he=0,xe=1;function Ce(e){F(he,{text:e})}function ve(){return F(xe)}var I={};v(I,{Hide:()=>We,Quit:()=>Se,Show:()=>be});var O=a(l.Application),N={Hide:0,Show:1,Quit:2};function We(){O(N.Hide)}function be(){O(N.Show)}function Se(){O(N.Quit)}var z={};v(z,{GetAll:()=>Ee,GetCurrent:()=>ke,GetPrimary:()=>Re});var L=a(l.Screens),Me=0,De=1,ye=2;function Ee(){return L(Me)}function Re(){return L(De)}function ke(){return L(ye)}var P={};v(P,{IsDarkMode:()=>Ie});var Oe=a(l.System),Ne=0;function Ie(){return Oe(Ne)}var Le="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var W=(e=21)=>{let t="",n=e;for(;n--;)t+=Le[Math.random()*64|0];return t};var ze=a(l.Call),b=0,f=new Map;function Pe(){let e;do e=W();while(f.has(e));return e}function G(e,t,n){let o=f.get(e);o&&(n?o.resolve(JSON.parse(t)):o.resolve(t),f.delete(e))}function U(e,t){let n=f.get(e);n&&(n.reject(t),f.delete(e))}function S(e,t){return new Promise((n,o)=>{let i=Pe();t=t||{},t["call-id"]=i,f.set(i,{resolve:n,reject:o}),ze(e,t).catch(r=>{o(r),f.delete(i)})})}function Z(e){return S(b,e)}function Y(e,...t){if(typeof e!="string"||e.split(".").length!==3)throw new Error("CallByName requires a string in the format 'package.struct.method'");let n=e.split(".");return S(b,{packageName:n[0],structName:n[1],methodName:n[2],args:t})}function Q(e,...t){return S(b,{methodID:e,args:t})}function X(e,t,...n){return S(b,{packageName:"wails-plugins",structName:e,methodName:t,args:n})}var Te=0,Ae=1,je=2,Be=3,He=4,Fe=5,Ge=6,Ue=7,Ze=8,Ye=9,Qe=10,Xe=11,Ve=12,Je=13,qe=14,_e=15,Ke=16,$e=17,et=18,tt=19,nt=20,ot=21,it=22,rt=23,lt=24,at=25,st=26,ut=27,ct=28,dt=29;function V(e){let t=a(l.Window,e);return{Center:()=>void t(Te),SetTitle:n=>void t(Ae,{title:n}),Fullscreen:()=>void t(je),UnFullscreen:()=>void t(Be),SetSize:(n,o)=>t(He,{width:n,height:o}),Size:()=>t(Fe),SetMaxSize:(n,o)=>void t(Ge,{width:n,height:o}),SetMinSize:(n,o)=>void t(Ue,{width:n,height:o}),SetAlwaysOnTop:n=>void t(Ze,{alwaysOnTop:n}),SetRelativePosition:(n,o)=>t(Ye,{x:n,y:o}),RelativePosition:()=>t(Qe),Screen:()=>t(Xe),Hide:()=>void t(Ve),Maximise:()=>void t(Je),Show:()=>void t(tt),Close:()=>void t(nt),ToggleMaximise:()=>void t(_e),UnMaximise:()=>void t(qe),Minimise:()=>void t(Ke),UnMinimise:()=>void t($e),Restore:()=>void t(et),SetBackgroundColour:(n,o,i,r)=>void t(ot,{r:n,g:o,b:i,a:r}),SetResizable:n=>void t(it,{resizable:n}),Width:()=>t(rt),Height:()=>t(lt),ZoomIn:()=>void t(at),ZoomOut:()=>void t(st),ZoomReset:()=>void t(ut),GetZoomLevel:()=>t(ct),SetZoomLevel:n=>void t(dt,{zoomLevel:n})}}var ft=a(l.Events),mt=0,T=class{constructor(t,n,o){this.eventName=t,this.maxCallbacks=o||-1,this.Callback=i=>(n(i),this.maxCallbacks===-1?!1:(this.maxCallbacks-=1,this.maxCallbacks===0))}},M=class{constructor(t,n=null){this.name=t,this.data=n}},c=new Map;function D(e,t,n){let o=c.get(e)||[],i=new T(e,t,n);return o.push(i),c.set(e,o),()=>pt(i)}function J(e,t){return D(e,t,-1)}function q(e,t){return D(e,t,1)}function pt(e){let t=e.eventName,n=c.get(t).filter(o=>o!==e);n.length===0?c.delete(t):c.set(t,n)}function _(e){let t=c.get(e.name);if(t){let n=[];t.forEach(o=>{o.Callback(e)&&n.push(o)}),n.length>0&&(t=t.filter(o=>!n.includes(o)),t.length===0?c.delete(e.name):c.set(e.name,t))}}function K(e,...t){[e,...t].forEach(o=>{c.delete(o)})}function $(){c.clear()}function y(e){ft(mt,e)}var wt=a(l.Dialog),gt=0,ht=1,xt=2,Ct=3,vt=4,Wt=5,m=new Map;function bt(){let e;do e=W();while(m.has(e));return e}function ee(e,t,n){let o=m.get(e);o&&(n?o.resolve(JSON.parse(t)):o.resolve(t),m.delete(e))}function te(e,t){let n=m.get(e);n&&(n.reject(t),m.delete(e))}function g(e,t){return new Promise((n,o)=>{let i=bt();t=t||{},t["dialog-id"]=i,m.set(i,{resolve:n,reject:o}),wt(e,t).catch(r=>{o(r),m.delete(i)})})}function ne(e){return g(gt,e)}function oe(e){return g(ht,e)}function ie(e){return g(xt,e)}function x(e){return g(Ct,e)}function re(e){return g(vt,e)}function le(e){return g(Wt,e)}var St=a(l.ContextMenu),Mt=0;function Dt(e,t,n,o){St(Mt,{id:e,x:t,y:n,data:o})}function ae(){window.addEventListener("contextmenu",yt)}function yt(e){let t=e.target,n=window.getComputedStyle(t).getPropertyValue("--custom-contextmenu");if(n=n?n.trim():"",n){e.preventDefault();let o=window.getComputedStyle(t).getPropertyValue("--custom-contextmenu-data");Dt(n,e.clientX,e.clientY,o);return}Et(e)}function Et(e){let t=e.target;switch(window.getComputedStyle(t).getPropertyValue("--default-contextmenu").trim()){case"show":return;case"hide":e.preventDefault();return;default:if(t.isContentEditable)return;let i=window.getSelection(),r=i.toString().length>0;if(r)for(let u=0;u<i.rangeCount;u++){let s=i.getRangeAt(u).getClientRects();for(let w=0;w<s.length;w++){let h=s[w];if(document.elementFromPoint(h.left,h.top)===t)return}}if((t.tagName==="INPUT"||t.tagName==="TEXTAREA")&&(r||!t.readOnly&&!t.disabled))return;e.preventDefault()}}function se(e,t=null){let n=new M(e,t);y(n)}function Rt(){document.querySelectorAll("[data-wml-event]").forEach(function(t){let n=t.getAttribute("data-wml-event"),o=t.getAttribute("data-wml-confirm"),i=t.getAttribute("data-wml-trigger")||"click",r=function(){if(o){x({Title:"Confirm",Message:o,Detached:!1,Buttons:[{Label:"Yes"},{Label:"No",IsDefault:!0}]}).then(function(u){u!=="No"&&se(n)});return}se(n)};t.removeEventListener(i,r),t.addEventListener(i,r)})}function ue(e){wails.Window[e]===void 0&&console.log("Window method "+e+" not found"),wails.Window[e]()}function kt(){document.querySelectorAll("[data-wml-window]").forEach(function(t){let n=t.getAttribute("data-wml-window"),o=t.getAttribute("data-wml-confirm"),i=t.getAttribute("data-wml-trigger")||"click",r=function(){if(o){x({Title:"Confirm",Message:o,Buttons:[{Label:"Yes"},{Label:"No",IsDefault:!0}]}).then(function(u){u!=="No"&&ue(n)});return}ue(n)};t.removeEventListener(i,r),t.addEventListener(i,r)})}function A(){Rt(),kt()}var j=function(e){chrome.webview.postMessage(e)};var ce=new Map;function de(e){let t=new Map;for(let[n,o]of Object.entries(e))typeof o=="object"&&o!==null?t.set(n,de(o)):t.set(n,o);return t}fetch("/wails/flags").then(e=>{e.json().then(t=>{ce=de(t)})});function Ot(e){let t=e.split("."),n=ce;for(let o of t)if(n instanceof Map?n=n.get(o):n=n[o],n===void 0)break;return n}function E(e){return Ot(e)}var C=!1;function Nt(e){let t=window.getComputedStyle(e.target).getPropertyValue("--webkit-app-region");return t&&(t=t.trim()),t!=="drag"||e.buttons!==1?!1:e.detail===1}function fe(){window.addEventListener("mousedown",Lt),window.addEventListener("mousemove",Pt),window.addEventListener("mouseup",zt)}var R=null;function It(e){return R?(j("resize:"+R),!0):!1}function Lt(e){if(!It())if(Nt(e)){if(e.offsetX>e.target.clientWidth||e.offsetY>e.target.clientHeight)return;C=!0}else C=!1}function zt(e){(e.buttons!==void 0?e.buttons:e.which)>0&&B()}function B(){document.body.style.cursor="default",C=!1}function d(e){document.documentElement.style.cursor=e||Tt,R=e}function Pt(e){if(C){C=!1,(e.buttons!==void 0?e.buttons:e.which)>0&&j("drag");return}At(e)}var Tt="auto";function At(e){let t=E("system.resizeHandleHeight")||5,n=E("system.resizeHandleWidth")||5,o=E("resizeCornerExtra")||3,i=window.outerWidth-e.clientX<n,r=e.clientX<n,u=e.clientY<t,p=window.outerHeight-e.clientY<t,s=window.outerWidth-e.clientX<n+o,w=e.clientX<n+o,h=e.clientY<t+o,H=window.outerHeight-e.clientY<t+o;!r&&!i&&!u&&!p&&R!==void 0?d():s&&H?d("se-resize"):w&&H?d("sw-resize"):w&&h?d("nw-resize"):h&&s?d("ne-resize"):r?d("w-resize"):u?d("n-resize"):p?d("s-resize"):i&&d("e-resize")}window.wails={...me(null),Capabilities:{}};fetch("/wails/capabilities").then(e=>{e.json().then(t=>{window.wails.Capabilities=t})});window._wails={dialogCallback:ee,dialogErrorCallback:te,dispatchWailsEvent:_,callCallback:G,callErrorCallback:U,endDrag:B};function me(e){return{Clipboard:{...k},Application:{...I,GetWindowByName(t){return me(t)}},System:P,Screens:z,Call:Z,CallByID:Q,CallByName:Y,Plugin:X,WML:{Reload:A},Dialog:{Info:ne,Warning:oe,Error:ie,Question:x,OpenFile:re,SaveFile:le},Events:{Emit:y,On:J,Once:q,OnMultiple:D,Off:K,OffAll:$},Window:V(e)}}ae();fe();document.addEventListener("DOMContentLoaded",function(){A()});})();