import{$ as T,am as k,al as f,a6 as w,a2 as V,bT as j}from"./Commands.e655848c.js";import{c as U}from"./colors.f6cbcb11.js";function D(s,d){const o=h=>s&&!s.contains(h.target)&&!h.defaultPrevented&&d();return document.addEventListener("click",o,!0),{destroy(){document.removeEventListener("click",o,!0)}}}const I=600,H=50;function F(s,d,o){const h=j(s),e=[];for(const[p,n]of Object.entries(d)){const l=w(p),a=o[l],i=T(l);if(!(a==null||a.length===0))for(const c of n){const m=f.span(c);for(const u of a){const P=u.path.slice(i.length),S=k(c,P);if(S==null)continue;const x=f.value(S),v=f.path(S);if(m==null||v==null)continue;const t={value:x,info:u,specificPath:f.path(S)},R=t.info.type==="keyword",y=u.type==="concept_score",N=u.type==="semantic_similarity",L=u.type==="metadata"&&!V(u.dtype),g=u.type==="metadata",_=u.type==="leaf_span";let r=!1;if(y||N?x>.5?r=!0:r=!1:r=!0,!r)continue;const E=h.slice(m.start,m.end).join("");e.push({span:c,isKeywordSearch:R,isConceptSearch:y,isSemanticSearch:N,isMetadata:g,isLeafSpan:_,hasNonNumericMetadata:L,namedValue:t,path:v,text:E,value:x})}}}return e}function G(s,d,o){const h=[],e=new Set;for(const p of s){let n=!1;const l=[];for(const t of p.paths)e.has(t)||(l.push(t),e.add(t));const a=[],i=[];let c=-1/0;for(const[t,R]of Object.entries(p.originalSpans)){const y=d[t],N=T(t);if(!(y==null||y.length===0))for(const L of R)for(const g of y){const _=g.path.slice(N.length),r=k(L,_);if(r==null)continue;const E=f.value(r),B=f.span(r);if(E==null&&B==null)continue;if(g.dtype.type==="float32"){const C=f.value(r);C!=null&&(c=Math.max(c,C))}const M=w(f.path(L)),O=!l.includes(M),b={value:E,info:g,specificPath:f.path(r)};O||a.push(b),i.push(b),g.type==="concept_score"||g.type==="semantic_similarity"?E>.5&&(n=!0):n=!0}}const m=i.some(t=>t.info.type==="label"),u=i.some(t=>t.info.type==="leaf_span"),P=i.some(t=>t.info.type==="keyword"),S=i.some(t=>t.info.type==="metadata"&&!V(t.info.dtype)),x=p.paths.some(t=>o.has(t)),v=x&&l.length>0&&Array.from(o).some(t=>l.includes(t));h.push({backgroundColor:U(c),isBlackBolded:P||S||u,isHighlightBolded:m,isHighlighted:n,snippetScore:c,namedValues:a,paths:p.paths,text:p.text,originalSpans:p.originalSpans,isHovered:x,isFirstHover:v})}return h}function K(s,d){var p;let o=!1,h=!1,e=[];for(let n=0;n<s.length;n++){const l=s[n],a=n-1>=0?s[n-1]:null,i=n+1<s.length?s[n+1]:null,c=(p=e.at(-1))==null?void 0:p.isEllipsis;if(!l.isHighlighted){if(c||a!=null&&a.isHighlighted||i!=null&&i.isHighlighted)continue;o=!0,e.push({isEllipsis:!0});continue}h=!0,a!=null&&!a.isHighlighted&&(!c&&a.text.length>H&&(e.push({isEllipsis:!0}),o=!0),e.push({renderSpan:a,snippetText:a.text.slice(-H)})),e.push({renderSpan:l,snippetText:l.text}),i!=null&&!i.isHighlighted&&(e.push({renderSpan:i,snippetText:i.text.slice(0,H)}),!c&&i.text.length>H&&(e.push({isEllipsis:!0}),o=!0))}return h||(e=[],o=!1,e.push({renderSpan:s[0],snippetText:s[0].text.slice(0,I)}),((s[1]||null)!=null||s[0].text.length>I)&&(e.push({isEllipsis:!0}),o=!0)),d&&(e=s.map(n=>({renderSpan:n,snippetText:n.text}))),{snippetSpans:e,textIsOverBudget:o}}export{I as S,G as a,K as b,D as c,F as g};
