// Code generated by `bun run build` from packages/bridge. DO NOT EDIT. (()=>{var ae=new Set(["button","checkbox","color","file","hidden","image","radio","range","reset","submit"]);function V(e,t){let n={},o=e?.closest("input,textarea")??null,s=o&&!(o.type&&ae.has(o.type.toLowerCase()));if(s&&!o.readOnly&&!o.disabled)n.e=!0;else if(e?.isContentEditable)n.e=!0;if(s&&o.type?.toLowerCase()!=="password"){let c=o.selectionStart??0,b=o.selectionEnd??0;if(b>c)t=(o.value??"").slice(c,b)}else if(s)t="";if(t)n.s=t;if(!e)return n;let a=e.closest("a[href],area[href]");if(a){let c=typeof a.href==="string"?a.href:a.href?.baseVal??"";if(c)n.l=c;let b=(a.innerText??a.textContent??"").trim();if(b)n.lt=b}let u=e.closest("img");if(u){let c=u.currentSrc||u.src;if(c)n.i=c}let m=e.closest("video,audio");if(m){let c=m.currentSrc||m.src;if(c)n.m=c}return n}var C=null,N=null,W=()=>typeof CSS<"u"&&("highlights"in CSS)&&typeof Highlight<"u";function ce(e,t){let n=[];if(!e||!document.body)return n;let o=t?e:e.toLowerCase(),s=document.createTreeWalker(document.body,NodeFilter.SHOW_TEXT,{acceptNode(a){let u=a.parentElement;if(!u||/^(SCRIPT|STYLE|NOSCRIPT|TEMPLATE|TEXTAREA)$/.test(u.tagName))return NodeFilter.FILTER_REJECT;return u.getClientRects().length?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}});for(let a=s.nextNode();a;a=s.nextNode()){let u=t?a.nodeValue:a.nodeValue.toLowerCase();for(let m=u.indexOf(o);m>=0;m=u.indexOf(o,m+o.length)){let c=document.createRange();c.setStart(a,m),c.setEnd(a,m+o.length),n.push(c)}}return n}function de(){if(N||!("adoptedStyleSheets"in document))return;N=new CSSStyleSheet,N.replaceSync("::highlight(mygo-find){background-color:#fdeb62;color:#000}::highlight(mygo-find-active){background-color:#ff9632;color:#000}"),document.adoptedStyleSheets=[...document.adoptedStyleSheets,N]}function q(e,t={}){let n=!!t.matchCase;if(!t.next||!C||C.text!==e||C.matchCase!==n)C={text:e,matchCase:n,ranges:ce(e,n),active:-1};let o=C.ranges.length;if(o===0)return H(),{matches:0,active:0};C.active=C.active<0?t.backward?o-1:0:(C.active+(t.backward?o-1:1))%o;let s=C.ranges[C.active];if(W())de(),CSS.highlights.set("mygo-find",new Highlight(...C.ranges)),CSS.highlights.set("mygo-find-active",new Highlight(s));else{let a=getSelection();a?.removeAllRanges(),a?.addRange(s)}return s.startContainer.parentElement?.scrollIntoView({block:"center",inline:"nearest"}),{matches:o,active:C.active+1}}function H(){if(C&&!W())getSelection()?.removeAllRanges();if(C=null,W())CSS.highlights.delete("mygo-find"),CSS.highlights.delete("mygo-find-active")}function ue(e,t){let n=["width:max-content"];if(e.minWidth>0)n.push(`min-width:${Math.max(e.minWidth-t,0)}px`);if(e.maxWidth>0)n.push(`max-width:${Math.max(e.maxWidth-t,0)}px`);if(e.minHeight>0)n.push(`min-height:${e.minHeight}px`);return`:where(:root){${n.join(";")}}`}function B(e){let t=null;return(n)=>{if(t&&t.w===n.w&&t.h===n.h&&t.sw===n.sw&&t.sh===n.sh)return;t=n,e(n)}}function J(e,t,n){let o=B(n),s=0,a=!1,u=!1,m=()=>t(ue(e,s)),c=(b)=>{let p=document.documentElement;if(!p)return;let h=document.scrollingElement??p,y=Math.max(innerWidth-h.clientWidth,0),O=Math.max(innerHeight-h.clientHeight,0),x=p.getBoundingClientRect(),r=e.maxHeight>0&&x.height>e.maxHeight?y:0;if(r!==s){if(s=r,!b)m(),x=p.getBoundingClientRect();else if(!u)u=!0,requestAnimationFrame(()=>{u=!1,m()})}let S=document.body,E=!!S&&S.scrollWidth>S.clientWidth;o({w:x.width,h:x.height,sw:y,sh:E?O:0})};return m(),{start(){if(a)return;if(a=!0,c(!1),typeof ResizeObserver<"u"&&document.documentElement)new ResizeObserver(()=>c(!0)).observe(document.documentElement);addEventListener("resize",()=>c(!1))},setLimits(b){if(e=b,m(),a)c(!1)},again(){if(o=B(n),a)c(!1)}}}var j=(e)=>setTimeout(()=>{throw e});function Y(e){if(e.reason!==void 0)return e.reason;return Error("mygo: the call was aborted")}class D extends Error{method;constructor(e,t){super(t);this.method=e;this.name="CallError"}}function X(e,t){let n=Math.random().toString(36).slice(2)+Date.now().toString(36),o=new Map,s=new Map,a={accent:null,reduceMotion:!1,reduceTransparency:!1,highContrast:!1,textScale:1},u=0,m=new Map,c=new WeakMap,b=0,p=e.locale||"en",h=e.dir==="rtl"?"rtl":"ltr",y=!0,O=(f)=>t(JSON.stringify(f)),x=(f,...i)=>S(f,i),r=(f,i,l)=>{let d=l?.signal;if(!d)return S(f,i);if(d.aborted)return Promise.reject(Y(d));return S(f,i,d)},S=(f,i,l)=>{let d=++u;return new Promise((L,A)=>{let M;for(let w of i){let v=typeof w==="object"&&w!==null?c.get(w):void 0;if(!v)continue;if(v.id||v.closed){M?.forEach((g)=>{m.delete(g.id),g.id=0}),A(Error("mygo: a channel can be passed to one call, before it is closed"));return}v.id=++b,m.set(v.id,v),(M??=[]).push(v)}let k,P;if(l)k=()=>{o.delete(d),M?.forEach((w)=>{m.delete(w.id),w.id=0});try{O({t:"cancel",id:d,k:n})}catch{}A(Y(l))},l.addEventListener("abort",k,{once:!0}),P=()=>l.removeEventListener("abort",k);o.set(d,{method:f,resolve:L,reject:A,channels:M,done:P});try{O({t:"call",id:d,k:n,m:f,a:i,cancel:l?!0:void 0})}catch(w){if(o.delete(d),k)l?.removeEventListener("abort",k);M?.forEach((v)=>{m.delete(v.id),v.id=0}),A(w)}})},E=(f)=>{let i=null,l=!1,d=[],L=[],A=0,M=(g)=>{try{O({t:"chan-ack",c:w.id,k:n,n:g})}catch{}},k=(g)=>{try{i(g)}catch(R){j(R)}},P=()=>{if(m.delete(w.id),d.length===0)L.splice(0).forEach((g)=>g({value:void 0,done:!0}));if(v.onclose)try{v.onclose()}catch(g){j(g)}},w={id:0,get closed(){return l},push(g,R){if(l)return;let G=++A;if(i)k(g);else if(L.length>0)L.shift()({value:g,done:!1});else return void d.push({value:g,n:G,ask:R});if(R)M(G)},end(){if(l)return;l=!0,P()}},v={get onmessage(){return i},set onmessage(g){i=g;while(i&&d.length>0){let R=d.shift();if(k(R.value),R.ask)M(R.n)}},onclose:null,get closed(){return l},close(){if(l)return;if(l=!0,d=[],w.id)try{O({t:"chan-close",c:w.id,k:n})}catch{}P()},[Symbol.asyncIterator](){return{next(){let g=d.shift();if(g){if(g.ask)M(g.n);return Promise.resolve({value:g.value,done:!1})}if(l)return Promise.resolve({value:void 0,done:!0});return new Promise((R)=>L.push(R))},return(){return v.close(),Promise.resolve({value:void 0,done:!0})}}},toJSON:()=>w.id};if(c.set(v,w),f)v.onmessage=f;return v},I=(f,i)=>{if(typeof i!=="function")throw TypeError("listener must be a function");let l=s.get(f);if(!l)s.set(f,l=new Set);let d=(L)=>i(L);return l.add(d),()=>{if(l.delete(d),l.size===0&&s.get(f)===l)s.delete(f)}},ie=(f,i)=>{let l=I(f,(d)=>{l(),i(d)});return l},se={receive(f){for(let i of Array.isArray(f)?f:[f])if(i.t==="event"){if(i.n==="mygo:preferences")a=Object.freeze(i.p);if(i.n==="mygo:window-active"){if(typeof i.p!=="boolean")continue;if(i.p===y)continue;y=i.p}if(i.n==="mygo:locale"){let d=i.p;if(typeof d?.locale!=="string")continue;if(d.locale===p)continue;p=d.locale,h=d.dir==="rtl"?"rtl":"ltr"}let l=s.get(i.n);if(!l)continue;for(let d of[...l])try{d(i.p)}catch(L){j(L)}}else if(i.t==="chan"){if(i.k!==n)continue;let l=m.get(i.c);if(!l)continue;if(i.end)l.end();else l.push(i.p,i.a===1)}else if(i.t==="reply"){if(i.k!==n)continue;let l=o.get(i.id);if(!l)continue;if(o.delete(i.id),l.done?.(),l.channels?.forEach((d)=>d.end()),i.ok)l.resolve(i.v);else l.reject(new D(l.method,i.e??"unknown error"))}}},le=()=>{let f=[...o.values()];o.clear();for(let i of f)i.done?.(),i.channels?.forEach((l)=>l.end()),i.reject(new D(i.method,"the page was left before the call returned"))},F=(f)=>()=>x(`mygo:window.${f}`);return{runtime:Object.freeze({call:x,callWith:r,channel:E,on:I,once:ie,platform:e.platform,windowId:e.windowId,version:e.version,get preferences(){return a},get locale(){return p},get dir(){return h},get windowActive(){return y},window:Object.freeze({minimize:F("Minimize"),maximize:F("Maximize"),unmaximize:F("Unmaximize"),toggleMaximize:F("ToggleMaximize"),isMaximized:F("IsMaximized"),toggleFullScreen:F("ToggleFullScreen"),close:F("Close"),setTitle:(f)=>x("mygo:window.SetTitle",f)})}),internal:se,restored:le}}function fe(e,t,n){for(let o of e){let s=o.getAttribute("media")?.trim();if(s&&!t(s))continue;let a=n(o.getAttribute("content")??"");if(a!==null)return a}return null}var _=(e)=>Math.round(Math.min(Math.max(e,0),255)).toString(16).padStart(2,"0");function me(e){if(/^#[0-9a-f]{6}$/i.test(e))return e.toLowerCase()+"ff";let t=/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:[\s,/]+([\d.]+))?\s*\)$/i.exec(e);if(!t)return null;return"#"+_(+t[1])+_(+t[2])+_(+t[3])+_(t[4]===void 0?255:+t[4]*255)}function U(e){let t,n=!1,o=(s)=>{if(s===t||s===null&&t===void 0&&!n)return;t=s,e(s??"")};return{report:o,ready(s){n=!0,o(s)}}}function Q(e){let t=U(e),n=new Map,o=(p)=>{let h=n.get(p);if(!h){if(h=matchMedia(p),h.addEventListener)h.addEventListener("change",a);else h.addListener(a);n.set(p,h)}return h.matches},s=()=>document.head?fe(document.head.querySelectorAll('meta[name="theme-color" i]'),o,ge):null;function a(){t.report(s())}let u=new MutationObserver((p)=>{let h=!1;for(let y of p)if(y.target===document||y.target===document.documentElement)b(),h=!0;else if(y.type==="attributes")h||=Z(y.target);else h||=K(y.addedNodes)||K(y.removedNodes);if(h)a()}),m=null,c=null;function b(){if(document.documentElement!==c&&(c=document.documentElement))u.observe(c,{childList:!0});if(document.head!==m&&(m=document.head))u.observe(m,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["name","content","media"]})}return u.observe(document,{childList:!0}),b(),a(),(p)=>{if(p)t=U(e);t.ready(s())}}var Z=(e)=>e.localName==="meta";function K(e){for(let t=0;t{let e=window;if(e.__mygo)return;let t=ve(e);if(!t)return;let n=(r)=>t.post(__MYGO_CONFIG__.secret+r),{runtime:o,internal:s,restored:a}=X(__MYGO_CONFIG__,n);Object.defineProperty(e,"mygo",{value:o,enumerable:!0}),Object.defineProperty(e,"__mygo",{value:Object.freeze({...s,find:q,stopFind:H})}),o.on("mygo:title-bar",(r)=>te({"--mygo-titlebar-height":`${r.height}px`,"--mygo-titlebar-inset-left":`${r.left}px`,"--mygo-titlebar-inset-right":`${r.right}px`,"--mygo-titlebar-controls-bottom":`${r.bottom}px`})),o.on("mygo:preferences",(r)=>te({"--mygo-accent":r.accent,"--mygo-text-scale":String(r.textScale)})),o.on("mygo:window-active",(r)=>ee(document.documentElement,r));let u=(r)=>{try{n(JSON.stringify({t:r}))}catch{}},m=Q((r)=>{try{n(JSON.stringify({t:"theme-color",v:r}))}catch{}}),c=__MYGO_CONFIG__.fit&&J(__MYGO_CONFIG__.fit,ye,(r)=>{try{n(JSON.stringify({t:"content-size",...r}))}catch{}});if(c)o.on("mygo:fit-content",c.setLimits);let b=()=>{if(m(),c)c.start();u("dom-ready")};if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",b,{once:!0});else b();e.addEventListener("pageshow",(r)=>{if(!r.persisted)return;if(a(),m(!0),c)c.again();u("dom-ready")}),e.addEventListener("pagehide",()=>{});let p=typeof CSS<"u"&&CSS.supports("-webkit-app-region","drag"),h=(r)=>{let S=getComputedStyle(r).getPropertyValue("--app-region").trim();if(S)return S;if(!p)return"";for(let E=r;E;E=E.parentElement){let I=getComputedStyle(E).getPropertyValue("-webkit-app-region").trim();if(I==="drag"||I==="no-drag")return I}return""},y=!1;e.addEventListener("dragstart",()=>y=!0,!0),e.addEventListener("dragend",()=>y=!1,!0);let O=(r)=>!y&&!!r.dataTransfer&&Array.from(r.dataTransfer.types).includes("Files");e.addEventListener("drop",(r)=>{let S=r.dataTransfer?.files;if(y||!S?.length)return;let E=__MYGO_CONFIG__.secret+JSON.stringify({t:"drop",x:Math.round(r.clientX),y:Math.round(r.clientY)});try{t.postWithFiles?t.postWithFiles(E,S):t.post(E)}catch{try{t.post(E)}catch{}}},!0);let x=(r)=>{if(O(r)&&!r.defaultPrevented)r.preventDefault()};e.addEventListener("dragover",x),e.addEventListener("drop",x),e.addEventListener("keydown",(r)=>{if(r.key!=="Escape"||r.isComposing)return;setTimeout(()=>{if(!r.defaultPrevented)u("escape")})}),e.addEventListener("contextmenu",(r)=>{let S=r.composedPath()[0],E=V(S instanceof Element?S:null,getSelection()?.toString()??"");try{n(JSON.stringify({t:"context-menu",x:r.clientX,y:r.clientY,...E}))}catch{}},!0),e.addEventListener("mousedown",(r)=>{if(r.button!==0||!(r.target instanceof Element))return;if(h(r.target)!=="drag"||r.target.closest(he))return;r.preventDefault(),u(r.detail===2?"dblclick":"drag")},!0)})();function te(e){Object.assign(ne,e),oe()}function ye(e){re=e,oe()}function oe(){let e=Object.entries(ne).filter(([,t])=>t!==null).map(([t,n])=>`${t}:${n}`).join(";");be((e?`:root{${e}}`:"")+re)}function be(e){if(document.adoptedStyleSheets){if(!z)z=new CSSStyleSheet,document.adoptedStyleSheets=[...document.adoptedStyleSheets,z];z.replaceSync(e);return}let t=pe??=document.createElement("style");t.textContent=e;let n=()=>{if(!t.isConnected)(document.head??document.documentElement)?.append(t)};if(document.documentElement)n();else document.addEventListener("DOMContentLoaded",n,{once:!0})}function ve(e){let t=e.webkit?.messageHandlers?.mygo;if(t)return{post:(s)=>t.postMessage(s)};let n=e.mygoAndroid;if(n)return{post:(s)=>n.postMessage(s)};let o=e.chrome?.webview;if(!o)return null;return{post:(s)=>o.postMessage(s),postWithFiles:o.postMessageWithAdditionalObjects?(s,a)=>o.postMessageWithAdditionalObjects(s,a):void 0}}})();