const f=n=>{const r=n.getBoundingClientRect();return{top:r.top,left:r.left,width:r.width,height:r.height}},g=n=>{let r=n.target instanceof Element?n.target:document.documentElement;const i=o=>{const s=o.getBoundingClientRect();return o===document.documentElement||o===document.body||s.height>=(innerHeight||1)*.8};for(let o=0;o<8&&i(r);o++){const s=[...r.children].filter(e=>{const t=e.getBoundingClientRect();return t.width>0&&t.height>0});if(s.length===0)break;const l=e=>{const t=e.getBoundingClientRect();return n.clientY<t.top?t.top-n.clientY:n.clientY>t.bottom?n.clientY-t.bottom:0},c=s.find(e=>{const t=e.getBoundingClientRect();return n.clientY>=t.top&&n.clientY<=t.bottom&&n.clientX>=t.left&&n.clientX<=t.right})??s.reduce((e,t)=>l(t)<l(e)?t:e);if(c===r)break;r=c}return r},d=n=>{const r=[];let i=n;for(let o=0;i&&i.parentElement&&o<10;o++){if(i.id){r.unshift("#"+CSS.escape(i.id));break}let s=1;for(let l=i.previousElementSibling;l;l=l.previousElementSibling)l.tagName===i.tagName&&s++;r.unshift(i.tagName.toLowerCase()+":nth-of-type("+s+")"),i=i.parentElement}return r.join(" > ").slice(0,1e3)};function p(n,r){let i=r,o=[];const s=c=>{const e=Object.create(null);for(const t of c){let a=null;try{a=document.querySelector(t)}catch{}e[t]=a?f(a):null}parent.postMessage({__fc_rects:{rects:e}},n)};let l=!1;const u=()=>{!i||o.length===0||l||(l=!0,requestAnimationFrame(()=>{l=!1,i&&o.length>0&&s(o)}))};addEventListener("scroll",u,{capture:!0,passive:!0}),addEventListener("resize",u),addEventListener("click",c=>{if(!i)return;c.preventDefault(),c.stopPropagation();const e=g(c);parent.postMessage({__fc_click:{path:d(e),x:c.clientX/(innerWidth||1),y:c.clientY/(innerHeight||1),rect:f(e)}},n)},!0),addEventListener("message",c=>{if(c.source!==parent||c.origin!==n)return;const e=c.data;if(!e||typeof e!="object")return;if(e.__fc_mode){i=e.__fc_mode.on===!0;return}const t=e.__fc_locate;t&&Array.isArray(t.paths)&&(o=t.paths.slice(0,128).filter(a=>typeof a=="string"&&a.length<=1024),s(o))})}export{g as anchorTarget,p as install};
