"use strict";const M=require("electron");document.addEventListener("mouseup",t=>{switch(t.button){case 3:history.length>1&&(history.back(),t.preventDefault());break;case 4:history.forward(),t.preventDefault();break}});const f="data-heroic-cursor";let n=null;function k(){const t=document.createElement("style");t.setAttribute("data-heroic-cursor-style",""),t.textContent=`[${f}] { outline: 3px solid #ffae00 !important; outline-offset: 2px !important; }`,document.documentElement.appendChild(t)}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",k,{once:!0}):k();function v(){n&&n.removeAttribute(f),n=null}function d(t){n&&n!==t&&n.removeAttribute(f),n=t,t&&(t.setAttribute(f,""),t.scrollIntoView({block:"nearest",inline:"nearest",behavior:"smooth"}))}function p(){return n&&n.isConnected&&y(n)?n:null}const x='a[href], button:not([disabled]), input:not([type="hidden"]):not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]), [role="button"], [role="link"]';function y(t){if(!t.offsetParent&&t.tagName!=="BODY"&&window.getComputedStyle(t).position!=="fixed")return!1;const e=t.getBoundingClientRect();if(e.width===0||e.height===0)return!1;const i=window.innerHeight,s=window.innerWidth;return e.bottom>-200&&e.top<i+200&&e.right>-200&&e.left<s+200}function C(){return Array.from(document.querySelectorAll(x)).filter(y)}function m(){const t=C();return t.length?(t.sort((e,i)=>{const s=e.getBoundingClientRect(),a=i.getBoundingClientRect();return s.top-a.top||s.left-a.left}),t[0]):null}function R(t){const e=p()??m();if(!e)return!1;if(e!==n)return d(e),!0;const i=e.getBoundingClientRect(),s=i.left+i.width/2,a=i.top+i.height/2;let h=null,g=1/0;for(const b of C()){if(b===e)continue;const l=b.getBoundingClientRect(),o=l.left+l.width/2-s,r=l.top+l.height/2-a;let c=!1,u=0;switch(t){case"right":c=o>8&&Math.abs(r)<=Math.abs(o)*1.5,u=Math.abs(r);break;case"left":c=o<-8&&Math.abs(r)<=Math.abs(o)*1.5,u=Math.abs(r);break;case"down":c=r>8&&Math.abs(o)<=Math.abs(r)*1.5,u=Math.abs(o);break;case"up":c=r<-8&&Math.abs(o)<=Math.abs(r)*1.5,u=Math.abs(o);break}if(!c)continue;const w=Math.hypot(o,r)+u*2;w<g&&(g=w,h=b)}return h?(d(h),!0):t==="down"||t==="up"?(window.scrollBy({top:t==="down"?400:-400,behavior:"smooth"}),!0):!1}function A(){const t=p();if(!t)return;const e=t.tagName;e==="INPUT"||e==="TEXTAREA"||t.isContentEditable?t.focus():typeof t.click=="function"&&t.click()}function E(){const t=document.querySelectorAll('input[type="search"], input[type="text"], input[role="searchbox"], [role="search"] input');for(const e of t)if(y(e))return d(e),e.focus(),!0;return!1}function S(t){switch(t.type){case"enter":d(p()??m());break;case"exit":v();break;case"click":A();break;case"goBack":history.length>1&&history.back();break;case"goForward":history.forward();break;case"focusSearch":E();break;case"navigate":R(t.direction);break;case"scroll":window.scrollBy({top:t.direction==="down"?60:-60});break}}M.ipcRenderer.on("heroic-webview",(t,e)=>{e&&typeof e=="object"&&typeof e.type=="string"&&S(e)});
