import{I as S,j as E,r as x}from"./vendor-D3GnRMtz.js";import{c as H,M as T,a as f,b as p}from"./messageBroker-R4UMnmrm.js";const a=H("highlighter");function C(){let t=null,n=!1;function l(e){if(!e)return null;const o=[];for(;e.nodeType===Node.ELEMENT_NODE;){let i=e.nodeName.toLowerCase();if(e.id){i+=`#${e.id}`,o.unshift(i);break}else{let s=e,r=1;for(;s.previousElementSibling;)s=s.previousElementSibling,r++;i+=`:nth-child(${r})`}o.unshift(i),e.parentElement!=null&&(e=e.parentElement)}return o.join(" > ")}function c(e){if(t!==e.target){const o=e.target;o.style.outline="2px solid blue"}}function g(e){if(t!==e.target){const o=e.target;o.style.outline=""}}function u(e){var r,d,m,h;if(n)return;e.preventDefault(),e.stopPropagation(),t&&(t.style.outline=""),t=e.target,t.style.outline="2px solid red",a.debug("Selected element:",t);const o=l(t);a.info("Selected CSS Selector:",o);const i=((d=(r=window.getSelection())==null?void 0:r.toString())==null?void 0:d.trim())||"",s=((m=t.innerText)==null?void 0:m.trim())||((h=t.textContent)==null?void 0:h.trim())||i||t.outerHTML||"";o!=null&&(n=!0,chrome.storage.local.set({highlighterContext:{selector:o,content:s}},()=>{new T().passMessageToBroker({action:p.HIGHLIGHTER_CONTEXT_READY,recipients:[f.SIDE_PANEL,f.BACKGROUND_SCRIPT],payload:null}),L()}))}function L(){document.removeEventListener("mouseover",c),document.removeEventListener("mouseout",g),document.removeEventListener("click",u),t&&(t.style.outline=""),a.debug("Highlighter cleaned up")}document.addEventListener("mouseover",c),document.addEventListener("mouseout",g),document.addEventListener("click",u)}const b=()=>(x.useEffect(()=>{const t=(n,l)=>{console.info("Content script received message:",n),console.info(l.tab?`from a content script: ${l.tab.url}`:"from the extension"),((n==null?void 0:n.message)||n).action===p.START_HIGHLIGHTER&&(console.info("Starting highlighter..."),C())};return chrome.runtime.onMessage.addListener(t),()=>{chrome.runtime.onMessage.removeListener(t)}},[]),E.jsx("div",{})),v=document.createElement("div");document.body.appendChild(v);const R=S(v);R.render(E.jsx(b,{}));
