import{k as T}from"./engine-DyHa3vHM.js";const f=new Set(["SCRIPT","STYLE","NOSCRIPT","CODE","PRE","KBD","SAMP","TEXTAREA","INPUT","SELECT","OPTION","SVG","CANVAS","IMG","VIDEO","AUDIO"]),u=new Set(["ADDRESS","ARTICLE","ASIDE","BLOCKQUOTE","DD","DETAILS","DIV","DL","DT","FIELDSET","FIGCAPTION","FIGURE","FOOTER","FORM","H1","H2","H3","H4","H5","H6","HEADER","HR","LI","MAIN","NAV","OL","P","SECTION","TABLE","TD","TH","TR","UL"]),m=Array.from(u).join(",").toLowerCase(),A=2,s="data-yank-tr";let l=new Map,a=0;function S(t){return l.get(t)}function g(){l=new Map,a=0}function I(t){return!!(f.has(t.tagName)||t.isContentEditable||t.hasAttribute(s)||t.getAttribute("aria-hidden")==="true")}function h(t){return t.querySelector(m)!==null}function R(t){const e=t.getBoundingClientRect();if(e.width===0||e.height===0)return!1;const n=window.getComputedStyle(t);return n.display!=="none"&&n.visibility!=="hidden"&&n.opacity!=="0"}function C(t){const e=t.getBoundingClientRect(),n=window.innerHeight||document.documentElement.clientHeight,o=window.innerWidth||document.documentElement.clientWidth;return e.bottom>0&&e.top<n&&e.right>0&&e.left<o}function O(t){g();const e=[],n=document.body;if(!n)return e;const o=document.createTreeWalker(n,NodeFilter.SHOW_ELEMENT,{acceptNode(i){const c=i;return I(c)?NodeFilter.FILTER_REJECT:u.has(c.tagName)&&!h(c)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});let r=o.nextNode();for(;r;){const i=r,c=T(i);if(c.length>=A&&R(i)&&(t==="full"||C(i))){const d=a++;l.set(d,i),e.push({id:d,text:c})}r=o.nextNode()}return e}const E="data-yank-tr-id";function N(t,e){const n=t.nextElementSibling;return n!=null&&n.hasAttribute(s)&&n.getAttribute(E)===String(e)?n:null}function L(t,e,n){const o=u.has(t.tagName),r=document.createElement(o?"div":"span");return r.setAttribute(s,""),r.setAttribute(E,String(n)),r.setAttribute("dir","auto"),r.style.cssText=o?"margin:.15em 0 .4em;color:#6b7280;font-size:.95em;line-height:1.4;":"color:#6b7280;font-size:.95em;margin-inline-start:.4em;",r.textContent=e,r}function b(t){let e=0;for(const{id:n,text:o}of t){if(!o)continue;const r=S(n);if(!r||!r.isConnected)continue;const i=L(r,o,n),c=N(r,n);c?c.replaceWith(i):r.insertAdjacentElement("afterend",i),e++}return e}function p(){const t=document.querySelectorAll(`[${s}]`);for(const e of t)e.remove();return t.length}export{p as clearTranslations,O as collectUnits,b as renderTranslations};
