const E=r=>{const s=r.getBoundingClientRect();return{top:s.top,left:s.left,width:s.width,height:s.height}},g=(r,s,n)=>{const o=r.getBoundingClientRect(),a=Math.max(o.left-s,s-o.right,0),c=Math.max(o.top-n,n-o.bottom,0);return Math.hypot(a,c)};const P=(r,s,n)=>{let o=n;const a=u=>{const f=u.getBoundingClientRect();return u===document.documentElement||u===document.body||f.height>=(innerHeight||1)*.8};for(let u=0;u<8&&a(o);u++){const f=[...o.children].filter(i=>{const l=i.getBoundingClientRect();return l.width>0&&l.height>0});if(f.length===0)break;const p=f.find(i=>g(i,r,s)===0)??f.reduce((i,l)=>g(l,r,s)<g(i,r,s)?l:i);if(p===o)break;o=p}const c=g(o,r,s);return{el:o,bg:o===document.documentElement||o===document.body||c>0&&c>24}},S=r=>P(r.clientX,r.clientY,r.target instanceof Element?r.target:document.documentElement).el,L=r=>{const s=[];let n=r;for(let o=0;n&&n.parentElement&&o<10;o++){if(n.id){s.unshift("#"+CSS.escape(n.id));break}let a=1;for(let c=n.previousElementSibling;c;c=c.previousElementSibling)c.tagName===n.tagName&&a++;s.unshift(n.tagName.toLowerCase()+":nth-of-type("+a+")"),n=n.parentElement}return s.join(" > ").slice(0,1e3)},M="<svg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 28 28'><path d='M 2 26 L 2 14 A 12 12 0 1 1 14 26 Z' fill='%23D97757' stroke='%23fff' stroke-width='2'/></svg>",R=`url("data:image/svg+xml,${M}") 2 26, crosshair`;function k(r,s){let n=s,o=!1,a=[],c=null,u=null,f=null;const h=()=>{const t=n&&!o,e=document.documentElement.style;t&&!c?(u={value:e.getPropertyValue("cursor"),priority:e.getPropertyPriority("cursor")},c=document.createElement("style"),c.textContent=`* { cursor: ${R} !important; }`,(document.head??document.documentElement).appendChild(c),e.setProperty("cursor",R,"important"),f=e.getPropertyValue("cursor")):!t&&c&&(c.remove(),c=null,e.getPropertyValue("cursor")===f&&e.getPropertyPriority("cursor")==="important"&&(u&&u.value?e.setProperty("cursor",u.value,u.priority):e.removeProperty("cursor")),u=null,f=null)};h();const p=t=>{const e=Object.create(null);for(const d of t){let m=null;try{m=document.querySelector(d)}catch{}e[d]=m?E(m):null}parent.postMessage({__fc_rects:{rects:e}},r)};let i=null,l=null,v=!1;const b=(t,e)=>t.top===e.top&&t.left===e.left&&t.width===e.width&&t.height===e.height,w=()=>{if(!n||o||!i)return;const{el:t,bg:e}=P(i.x,i.y,document.elementFromPoint(i.x,i.y)??document.documentElement);if(e){l&&(l=null,parent.postMessage({__fc_hover:null},r));return}const d=E(t);l&&l.el===t&&b(l.rect,d)||(l={el:t,rect:d},parent.postMessage({__fc_hover:{rect:d}},r))},x=()=>{v||(v=!0,requestAnimationFrame(()=>{v=!1,w()}))},_=()=>{i=null,l&&(l=null,parent.postMessage({__fc_hover:null},r))};addEventListener("pointermove",t=>{!n||o||t.pointerType!=="mouse"&&t.pointerType!=="pen"||(i={x:t.clientX,y:t.clientY},x())},{capture:!0,passive:!0}),document.documentElement.addEventListener("pointerleave",_),addEventListener("pointercancel",_);let y=!1;const C=()=>{!n||y||a.length===0&&!i||(y=!0,requestAnimationFrame(()=>{y=!1,n&&(a.length>0&&p(a),w())}))};addEventListener("scroll",C,{capture:!0,passive:!0}),addEventListener("resize",C),addEventListener("click",t=>{if(!n)return;t.preventDefault(),t.stopPropagation();const{el:e,bg:d}=P(t.clientX,t.clientY,t.target instanceof Element?t.target:document.documentElement);parent.postMessage({__fc_click:{path:L(e),x:t.clientX/(innerWidth||1),y:t.clientY/(innerHeight||1),rect:E(e),bg:d}},r)},!0),addEventListener("message",t=>{if(t.source!==parent||t.origin!==r)return;const e=t.data;if(!e||typeof e!="object")return;if(e.__fc_mode){n=e.__fc_mode.on===!0,o=e.__fc_mode.composing===!0,h(),(!n||o)&&_();return}const d=e.__fc_locate;d&&Array.isArray(d.paths)&&(a=d.paths.slice(0,128).filter(m=>typeof m=="string"&&m.length<=1024),p(a))})}export{S as anchorTarget,k as install,P as refineTarget};
