@deepcitation/deepcitation-js 1.1.49 → 1.1.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +73 -157
  2. package/lib/chunk-2HINOG74.js +3 -0
  3. package/lib/chunk-2HINOG74.js.map +1 -0
  4. package/lib/chunk-4UWAUWYL.cjs +3 -0
  5. package/lib/chunk-4UWAUWYL.cjs.map +1 -0
  6. package/lib/chunk-5XGN7UAV.js +2 -0
  7. package/lib/chunk-5XGN7UAV.js.map +1 -0
  8. package/lib/chunk-7TORYXU4.cjs +3 -0
  9. package/lib/chunk-7TORYXU4.cjs.map +1 -0
  10. package/lib/chunk-BDSA6VGC.js +125 -0
  11. package/lib/chunk-BDSA6VGC.js.map +1 -0
  12. package/lib/chunk-BEYJEW3Y.js +2 -0
  13. package/lib/chunk-BEYJEW3Y.js.map +1 -0
  14. package/lib/chunk-BWQLFMTV.js +2 -0
  15. package/lib/chunk-BWQLFMTV.js.map +1 -0
  16. package/lib/{chunk-F2MMVEVC.cjs → chunk-BYLIBOAU.cjs} +2 -1
  17. package/lib/chunk-BYLIBOAU.cjs.map +1 -0
  18. package/lib/chunk-DS6SOU4L.cjs +2 -0
  19. package/lib/chunk-DS6SOU4L.cjs.map +1 -0
  20. package/lib/{chunk-UUR2SQKU.cjs → chunk-HL3AXCDL.cjs} +2 -1
  21. package/lib/chunk-HL3AXCDL.cjs.map +1 -0
  22. package/lib/chunk-N7FTXSGM.js +3 -0
  23. package/lib/chunk-N7FTXSGM.js.map +1 -0
  24. package/lib/chunk-WS4CQVDI.cjs +125 -0
  25. package/lib/chunk-WS4CQVDI.cjs.map +1 -0
  26. package/lib/client/index.cjs +2 -1
  27. package/lib/client/index.cjs.map +1 -0
  28. package/lib/client/index.d.cts +58 -13
  29. package/lib/client/index.d.ts +58 -13
  30. package/lib/client/index.js +2 -1
  31. package/lib/client/index.js.map +1 -0
  32. package/lib/{index-fvVBZYVK.d.ts → index-BHjI8Bh1.d.cts} +61 -22
  33. package/lib/{index-fvVBZYVK.d.cts → index-BHjI8Bh1.d.ts} +61 -22
  34. package/lib/index.cjs +2 -1
  35. package/lib/index.cjs.map +1 -0
  36. package/lib/index.d.cts +137 -16
  37. package/lib/index.d.ts +137 -16
  38. package/lib/index.js +2 -1
  39. package/lib/index.js.map +1 -0
  40. package/lib/prompts/index.cjs +2 -1
  41. package/lib/prompts/index.cjs.map +1 -0
  42. package/lib/prompts/index.d.cts +177 -55
  43. package/lib/prompts/index.d.ts +177 -55
  44. package/lib/prompts/index.js +2 -1
  45. package/lib/prompts/index.js.map +1 -0
  46. package/lib/react/index.cjs +8 -5
  47. package/lib/react/index.cjs.map +1 -0
  48. package/lib/react/index.d.cts +348 -21
  49. package/lib/react/index.d.ts +348 -21
  50. package/lib/react/index.js +8 -5
  51. package/lib/react/index.js.map +1 -0
  52. package/lib/styles.css +1 -1
  53. package/lib/types/index.cjs +2 -1
  54. package/lib/types/index.cjs.map +1 -0
  55. package/lib/types/index.d.cts +1 -1
  56. package/lib/types/index.d.ts +1 -1
  57. package/lib/types/index.js +2 -1
  58. package/lib/types/index.js.map +1 -0
  59. package/lib/{utils-q6anRKO_.d.cts → utils-CCi9_JTv.d.cts} +5 -5
  60. package/lib/{utils-DuacFTtu.d.ts → utils-CoSP-i76.d.ts} +5 -5
  61. package/package.json +165 -152
  62. package/src/tailwind.css +5 -5
  63. package/lib/chunk-2PRW5PVT.cjs +0 -2
  64. package/lib/chunk-3XSZLKJW.js +0 -2
  65. package/lib/chunk-D2TKEF6D.cjs +0 -2
  66. package/lib/chunk-DHVODVIA.cjs +0 -71
  67. package/lib/chunk-HRCAI3NV.js +0 -1
  68. package/lib/chunk-ND6LFDGK.js +0 -71
  69. package/lib/chunk-O2XFH626.js +0 -1
  70. package/lib/chunk-PKXMJNRX.js +0 -2
@@ -1,5 +1,8 @@
1
- import {d,f,j,b}from'../chunk-PKXMJNRX.js';export{k as CITATION_X_PADDING,l as CITATION_Y_PADDING,j as classNames,f as generateCitationInstanceId,d as generateCitationKey,g as getCitationDisplayText,i as getCitationKeySpanText,h as getCitationNumber,c as isUrlCitation}from'../chunk-PKXMJNRX.js';import'../chunk-O2XFH626.js';import*as We from'react';import We__default,{forwardRef,useMemo,useCallback,memo,createContext,useState,useRef,useEffect,useContext}from'react';import {jsxs,Fragment,jsx}from'react/jsx-runtime';import {createPortal}from'react-dom';import*as H from'@radix-ui/react-popover';function K(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e.replace(/^https?:\/\/(www\.)?/,"").split("/")[0]}}function Ye(e,t){return e.length<=t?e:e.slice(0,t-1)+"\u2026"}function Vt(e){try{let t=new URL(e),r=t.pathname+t.search;return r==="/"?"":r}catch{return ""}}var Ze={verified:{icon:"\u2713",label:"Verified",className:"text-green-600 dark:text-green-500"},partial:{icon:"~",label:"Partial match",className:"text-amber-600 dark:text-amber-500"},pending:{icon:"\u2026",label:"Verifying",className:"text-gray-400 dark:text-gray-500"},accessible:{icon:"\u25CB",label:"Accessible",className:"text-blue-500 dark:text-blue-400"},redirected:{icon:"\u21AA",label:"Redirected",className:"text-amber-600 dark:text-amber-500"},redirected_valid:{icon:"\u21AA\u2713",label:"Redirected (valid)",className:"text-green-600 dark:text-green-500"},blocked_antibot:{icon:"\u{1F6E1}",label:"Blocked by anti-bot",className:"text-amber-600 dark:text-amber-500"},blocked_login:{icon:"\u{1F512}",label:"Login required",className:"text-amber-600 dark:text-amber-500"},blocked_paywall:{icon:"\u{1F4B3}",label:"Paywall",className:"text-amber-600 dark:text-amber-500"},blocked_geo:{icon:"\u{1F30D}",label:"Geo-restricted",className:"text-amber-600 dark:text-amber-500"},blocked_rate_limit:{icon:"\u23F1",label:"Rate limited",className:"text-amber-600 dark:text-amber-500"},error_timeout:{icon:"\u23F0",label:"Timed out",className:"text-red-500 dark:text-red-400"},error_not_found:{icon:"404",label:"Not found",className:"text-red-500 dark:text-red-400"},error_server:{icon:"\u26A0",label:"Server error",className:"text-red-500 dark:text-red-400"},error_network:{icon:"\u26A1",label:"Network error",className:"text-red-500 dark:text-red-400"},unknown:{icon:"?",label:"Unknown status",className:"text-gray-400 dark:text-gray-500"}};function Je(e){return e.startsWith("blocked_")}function qe(e){return e.startsWith("error_")}function jt(e){return e==="verified"||e==="partial"||e==="accessible"||e==="redirected_valid"}function zt(e){return e==="redirected"||e==="redirected_valid"}function Wt(e){return e==="verified"||e==="partial"||e==="redirected_valid"}var Ut=({status:e,errorMessage:t})=>{let r=Ze[e];return jsx("span",{className:j("inline-flex items-center gap-1",r.className),title:t||r.label,"aria-label":r.label,children:jsx("span",{className:"text-[0.9em]","aria-hidden":"true",children:r.icon})})},Se=({url:e,faviconUrl:t})=>{let r=K(e),n=t||`https://www.google.com/s2/favicons?domain=${r}&sz=16`;return jsx("img",{src:n,alt:"",className:"w-3.5 h-3.5 rounded-sm",width:14,height:14,loading:"lazy",onError:a=>{a.target.style.display="none";}})},Qe=forwardRef(({urlMeta:e,citation:t,children:r,className:n,variant:a="chip",showFullUrlOnHover:o=true,showFavicon:i=true,showTitle:d$1=false,maxDisplayLength:s=30,renderBlockedIndicator:c,onUrlClick:u,eventHandlers:l,preventTooltips:g=false},x)=>{let{url:p,domain:S,title:E,fetchStatus:h,faviconUrl:P,errorMessage:w}=e,L=useMemo(()=>t||{value:p,fullPhrase:E||p},[t,p,E]),_=useMemo(()=>d(L),[L]),j$1=useMemo(()=>f(_),[_]),T=useMemo(()=>S||K(p),[S,p]),A=useMemo(()=>Vt(p),[p]),U=useMemo(()=>{if(d$1&&E)return Ye(E,s);let M=A?Ye(A,s-T.length-1):"";return M?`${T}${M}`:T},[d$1,E,T,A,s]),v=Ze[h],ce=Je(h),b=qe(h),C=h==="verified",D=h==="partial",z=h==="pending",Y=useCallback(M=>{M.preventDefault(),M.stopPropagation(),u?u(p,M):window.open(p,"_blank","noopener,noreferrer"),l?.onClick?.(L,_,M);},[u,p,l,L,_]),de=useCallback(()=>{l?.onMouseEnter?.(L,_);},[l,L,_]),ue=useCallback(()=>{l?.onMouseLeave?.(L,_);},[l,L,_]),Q=()=>ce||b?c?c(h,w):jsx(Ut,{status:h,errorMessage:w}):C?jsx("span",{className:"text-[0.85em] text-green-600 dark:text-green-500","aria-hidden":"true",title:"Verified",children:"\u2713"}):D?jsx("span",{className:"text-[0.85em] text-amber-600 dark:text-amber-500","aria-hidden":"true",title:"Partial match",children:"~"}):z?jsx("span",{className:"opacity-70","aria-hidden":"true",children:"\u2026"}):null;return a==="chip"?jsxs(Fragment,{children:[r,jsxs("span",{ref:x,"data-citation-id":_,"data-citation-instance":j$1,"data-url":p,"data-fetch-status":h,"data-variant":"chip",className:j("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-sm cursor-pointer transition-colors no-underline","bg-blue-100 dark:bg-blue-900/30",v.className,n),title:o?p:void 0,onMouseEnter:g?void 0:de,onMouseLeave:g?void 0:ue,onMouseDown:Y,onClick:M=>M.stopPropagation(),role:"link","aria-label":`Link to ${T}: ${v.label}`,children:[i&&jsx(Se,{url:p,faviconUrl:P}),jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:U}),Q()]})]}):a==="inline"?jsxs(Fragment,{children:[r,jsxs("a",{ref:x,href:p,"data-citation-id":_,"data-citation-instance":j$1,"data-fetch-status":h,"data-variant":"inline",className:j("inline-flex items-center gap-1 cursor-pointer transition-colors no-underline border-b border-dotted border-current",v.className,n),title:o?p:void 0,onMouseEnter:g?void 0:de,onMouseLeave:g?void 0:ue,onClick:M=>{M.preventDefault(),Y(M);},target:"_blank",rel:"noopener noreferrer","aria-label":`Link to ${T}: ${v.label}`,children:[i&&jsx(Se,{url:p,faviconUrl:P}),jsx("span",{children:U}),Q()]})]}):jsxs(Fragment,{children:[r,jsxs("span",{ref:x,"data-citation-id":_,"data-citation-instance":j$1,"data-url":p,"data-fetch-status":h,"data-variant":"bracket",className:j("cursor-pointer transition-colors",v.className,n),title:o?p:void 0,onMouseEnter:g?void 0:de,onMouseLeave:g?void 0:ue,onMouseDown:Y,onClick:M=>M.stopPropagation(),role:"link","aria-label":`Link to ${T}: ${v.label}`,children:["[",i&&jsx(Se,{url:p,faviconUrl:P}),jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:U}),Q(),"]"]})]})});Qe.displayName="UrlCitationComponent";memo(Qe);var At=({className:e})=>jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"square",shapeRendering:"crispEdges",className:e,width:"1em",height:"1em",children:[jsx("path",{d:"M7 3 L3 3 L3 21 L7 21"}),jsx("path",{d:"M17 3 L21 3 L21 21 L17 21"})]}),q=({className:e})=>jsx("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{width:"100%",height:"100%"},children:jsx("polyline",{points:"20 6 9 17 4 12"})}),re=({className:e})=>jsx("svg",{className:e,viewBox:"0 0 256 256",fill:"currentColor","aria-hidden":"true",style:{width:"100%",height:"100%"},children:jsx("path",{d:"M236.8,188.09,149.35,36.22h0a24.76,24.76,0,0,0-42.7,0L19.2,188.09a23.51,23.51,0,0,0,0,23.72A24.35,24.35,0,0,0,40.55,224h174.9a24.35,24.35,0,0,0,21.33-12.19A23.51,23.51,0,0,0,236.8,188.09ZM120,104a8,8,0,0,1,16,0v40a8,8,0,0,1-16,0Zm8,88a12,12,0,1,1,12-12A12,12,0,0,1,128,192Z"})}),ie=({className:e})=>jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",style:{width:"100%",height:"100%"},children:[jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4",style:{opacity:.25}}),jsx("path",{fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z",style:{opacity:.75}})]}),Ht=({className:e})=>jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{width:"100%",height:"100%"},children:[jsx("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),jsx("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]}),$t=({className:e})=>jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{width:"100%",height:"100%"},children:[jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),jsx("polyline",{points:"15 3 21 3 21 9"}),jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]}),Ft=({className:e})=>jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{width:"100%",height:"100%"},children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]});function Kt(...e){return e.filter(Boolean).join(" ")}var rt=H.Root,at=H.Trigger;var Me=We.forwardRef(({className:e,align:t="center",sideOffset:r=8,...n},a)=>jsx(H.Portal,{children:jsx(H.Content,{ref:a,align:t,sideOffset:r,className:Kt("z-[9998] rounded-lg border bg-white shadow-xl outline-none","w-fit max-w-[min(400px,calc(100vw-2rem))]","border-gray-200 dark:border-gray-700 dark:bg-gray-900","data-[state=open]:animate-in data-[state=closed]:animate-out","data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0","data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95","data-[side=bottom]:slide-in-from-top-2","data-[side=left]:slide-in-from-right-2","data-[side=right]:slide-in-from-left-2","data-[side=top]:slide-in-from-bottom-2",e),...n})}));Me.displayName=H.Content.displayName;function lt(e,t,r=(n,a)=>n===a){let n=e.length,a=t.length;if(n===0&&a===0)return [];if(n===0)return [{value:t.join(""),added:true,count:t.length}];if(a===0)return [{value:e.join(""),removed:true,count:e.length}];let o=0;for(;o<n&&o<a&&r(e[o],t[o]);)o++;let i=0;for(;i<n-o&&i<a-o&&r(e[n-1-i],t[a-1-i]);)i++;let d=e.slice(o,n-i),s=t.slice(o,a-i);if(d.length===0&&s.length===0)return [{value:e.join(""),count:e.length}];let c=Gt(d,s,r),u=[];return o>0&&u.push({value:e.slice(0,o).join(""),count:o}),u.push(...c),i>0&&u.push({value:e.slice(n-i).join(""),count:i}),ct(u)}function Gt(e,t,r){let n=e.length,a=t.length,o=n+a,i={1:0},d=[];e:for(let s=0;s<=o;s++){d.push({...i});for(let c=-s;c<=s;c+=2){let u;c===-s||c!==s&&i[c-1]<i[c+1]?u=i[c+1]:u=i[c-1]+1;let l=u-c;for(;u<n&&l<a&&r(e[u],t[l]);)u++,l++;if(i[c]=u,u>=n&&l>=a)break e}}return Xt(d,e,t)}function Xt(e,t,r){let n=[],a=t.length,o=r.length;for(let i=e.length-1;i>=0;i--){let d=e[i],s=a-o,c;s===-i||s!==i&&d[s-1]<d[s+1]?c=s+1:c=s-1;let u=d[c]??0,l=u-c;for(;a>u&&o>l;)a--,o--,n.push({value:t[a],count:1});i>0&&(a===u?(o--,n.push({value:r[o],added:true,count:1})):(a--,n.push({value:t[a],removed:true,count:1})));}return n.reverse()}function ct(e){if(e.length===0)return [];let t=[];for(let r of e){let n=t[t.length-1];n&&n.added===r.added&&n.removed===r.removed?(n.value+=r.value,n.count=(n.count||1)+(r.count||1)):t.push({...r});}return t}function nt(e){if(!e)return [];let t=[],r=0;for(let n=0;n<e.length;n++)e[n]===`
2
- `&&(t.push(e.substring(r,n+1)),r=n+1);return r<e.length&&t.push(e.substring(r)),t}var ot="a-zA-Z0-9_\\u00AD\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C6\\u02C8-\\u02D7\\u02DE-\\u02FF\\u1E00-\\u1EFF",Yt=new RegExp(`[${ot}]+|\\s+|[^${ot}]`,"gu");function it(e){return e?e.match(Yt)||[]:[]}function st(e,t){let r=0;for(;r<e.length&&r<t.length&&e[r]===t[r];)r++;return e.slice(0,r)}function Ie(e,t){let r=0;for(;r<e.length&&r<t.length&&e[e.length-1-r]===t[t.length-1-r];)r++;return e.slice(e.length-r)}function Zt(e){let t=[];for(let r=0;r<e.length;r++){let n=e[r];if(n.removed&&e[r+1]?.added){let a=n,o=e[r+1],d=st(a.value,o.value).match(/^\s*/)?.[0]||"",s=a.value.slice(d.length),c=o.value.slice(d.length),l=Ie(s,c).match(/\s*$/)?.[0]||"";d&&t.push({value:d,count:1});let g=a.value.slice(d.length,a.value.length-l.length),x=o.value.slice(d.length,o.value.length-l.length);g&&t.push({value:g,removed:true,count:1}),x&&t.push({value:x,added:true,count:1}),l&&t.push({value:l,count:1}),r++;continue}if(n.added&&r>0&&!e[r-1].added&&!e[r-1].removed){let a=t[t.length-1];if(a&&!a.added&&!a.removed){let o=n.value.match(/^\s*/)?.[0]||"",i=a.value.match(/\s*$/)?.[0]||"";if(o&&i){let d=Ie(i,o);if(d){t.push({value:n.value.slice(d.length),added:true,count:1});continue}}}}if(n.removed&&!e[r+1]?.added&&r>0&&!e[r-1]?.added&&!e[r-1]?.removed){let a=t[t.length-1],o=e[r+1];if(a&&o&&!o.added&&!o.removed){let i=n.value.match(/^\s*/)?.[0]||"",d=n.value.match(/\s*$/)?.[0]||"",s=a.value.match(/\s*$/)?.[0]||"",c=o.value.match(/^\s*/)?.[0]||"";if(i&&s&&Ie(s,i).length===i.length){t.push({value:n.value.slice(i.length),removed:true,count:1});continue}if(d&&c&&st(d,c).length===d.length){t.push({value:n.value.slice(0,-d.length)||n.value,removed:true,count:1});continue}}}t.push({...n});}return ct(t)}function dt(e,t){let r=nt(e),n=nt(t);return lt(r,n)}function ut(e,t){let r=it(e),n=it(t),a=lt(r,n);return Zt(a)}var mt=(e="",t="")=>useMemo(()=>{let r=(e||"").trim().replace(/\r\n/g,`
3
- `),n=(t||"").trim().replace(/\r\n/g,`
4
- `),a=dt(r,n),o=[],i=false,d=0;for(let u=0;u<a.length;u++){let l=a[u],g=a[u+1];if(l.removed&&g&&g.added){let x=ut(l.value,g.value);o.push({type:"modified",parts:x}),i=true,d+=Math.abs(l.value.length-g.value.length),u++;}else l.added||l.removed?(o.push({type:l.added?"added":"removed",parts:[{value:l.value,added:l.added,removed:l.removed}]}),i=true,d+=l.value.length):o.push({type:"unchanged",parts:[{value:l.value}]});}let s=Math.max(r.length,n.length),c=s===0?1:1-d/s;return {diffResult:o,hasDiff:i,similarity:c,isHighVariance:c<.6}},[e,t]);var Ee=createContext(null);function tr({children:e}){let[t,r]=useState(0),n=useCallback(()=>{r(i=>i+1);},[]),a=useCallback(()=>{r(i=>Math.max(0,i-1));},[]),o=useMemo(()=>({isAnyOverlayOpen:t>0,registerOverlay:n,unregisterOverlay:a}),[t,n,a]);return jsx(Ee.Provider,{value:o,children:e})}function ve(){let e=useContext(Ee);return e||{isAnyOverlayOpen:false,registerOverlay:()=>{},unregisterOverlay:()=>{}}}function rr(){return useContext(Ee)!==null}function sr(e){switch(e){case "chip":case "text":case "brackets":return "keySpan";case "source":return "source";default:return "number"}}function lr(e){return e.replace(/^\[+\s*/,"").replace(/\s*\]+$/,"")}function cr(e,t,r){if(t==="indicator")return "";if(t==="keySpan"){let n=e.keySpan?.toString()||e.citationNumber?.toString()||r||"1";return lr(n)}return t==="source"?e.siteName||e.domain||e.keySpan?.toString()||"Source":e.citationNumber?.toString()||"1"}function dr(e){return e.isVerified&&!e.isPartialMatch?"Verified":e.isPartialMatch?"Partial Match":e.isMiss?"Not Found":e.isPending?"Verifying...":""}function ur(e){let t=e?.status;if(!e||!t)return {isVerified:false,isMiss:false,isPartialMatch:false,isPending:false};let r=t==="not_found",n=t==="pending"||t==="loading",a=t==="partial_text_found"||t==="found_on_other_page"||t==="found_on_other_line"||t==="first_word_found";return {isVerified:t==="found"||t==="found_key_span_only"||t==="found_phrase_missed_value"||a,isMiss:r,isPartialMatch:a,isPending:n}}function mr({src:e,alt:t,onClose:r}){let{registerOverlay:n,unregisterOverlay:a}=ve();return useEffect(()=>(n(),()=>a()),[n,a]),useEffect(()=>{let o=i=>{i.key==="Escape"&&r();};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[r]),createPortal(jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-sm animate-in fade-in-0 duration-[50ms]",onClick:r,role:"dialog","aria-modal":"true","aria-label":"Full size verification image",children:jsx("div",{className:"relative max-w-[95vw] max-h-[95vh] cursor-zoom-out animate-in zoom-in-95 duration-[50ms]",children:jsx("img",{src:e,alt:t,className:"max-w-full max-h-[95vh] object-contain rounded-lg shadow-2xl",draggable:false})})}),document.body)}var pr=()=>jsx("span",{className:"inline-flex relative ml-0.5 size-2 text-green-600 dark:text-green-500","aria-hidden":"true",children:jsx(q,{})}),gr=()=>jsx("span",{className:"inline-flex relative ml-0.5 size-2 text-amber-600 dark:text-amber-500","aria-hidden":"true",children:jsx(q,{})}),fr=()=>jsx("span",{className:"inline-flex ml-1 size-2 animate-spin text-gray-400 dark:text-gray-500","aria-hidden":"true",children:jsx(ie,{})}),xr=()=>jsx("span",{className:"inline-flex relative ml-0.5 size-2 text-amber-500 dark:text-amber-400","aria-hidden":"true",children:jsx(re,{})});function hr({citation:e,verification:t,isExpanded:r,onExpandChange:n}){let a=useMemo(()=>{let l=new Set;if(t?.searchAttempts){for(let g of t.searchAttempts)if(g.searchPhrases)for(let x of g.searchPhrases)x&&l.add(x);}return l.size===0&&(e.fullPhrase&&l.add(e.fullPhrase),e.keySpan&&l.add(e.keySpan.toString())),Array.from(l)},[e,t]),[o,i]=useState(false),d=r??o,s=useCallback(l=>{n?n(l):i(l);},[n]);if(a.length===0)return null;let c=d?a.length:1,u=a.length-1;return jsxs("div",{className:"mt-2",children:[jsxs("div",{className:"flex items-center gap-2 text-[10px] text-gray-500 dark:text-gray-400 uppercase font-medium",children:[jsxs("span",{children:["Searched ",a.length," phrase",a.length!==1?"s":""]}),u>0&&!d&&jsxs("button",{type:"button",onClick:()=>s(true),className:"text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300 lowercase",children:["+",u," more"]}),d&&u>0&&jsx("button",{type:"button",onClick:()=>s(false),className:"text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300 lowercase",children:"collapse"})]}),jsx("div",{className:"mt-1 space-y-1",children:a.slice(0,c).map((l,g)=>jsxs("p",{className:"pl-2 py-1 font-mono text-[11px] break-words text-gray-700 dark:text-gray-300 border-l-2 border-red-400 dark:border-red-500",children:['"',l.length>80?l.slice(0,80)+"\u2026":l,'"']},g))})]})}function yr({citation:e,verification:t,status:r,onImageClick:n,isLoading:a=false,isPhrasesExpanded:o,onPhrasesExpandChange:i}){let d=t?.verificationImageBase64,{isMiss:s,isPartialMatch:c,isPending:u}=r;if(d){let p=r.isVerified&&!r.isPartialMatch,S=p||r.isPartialMatch;return jsxs("div",{className:"p-2",style:{maxWidth:"100%",overflow:"hidden"},children:[jsxs("button",{type:"button",className:"group block cursor-zoom-in relative overflow-hidden rounded-md bg-gray-50 dark:bg-gray-800",style:{width:"100%",maxWidth:"384px",height:"200px"},onClick:E=>{E.preventDefault(),E.stopPropagation(),n?.();},"aria-label":"Click to view full size",children:[jsx("img",{src:t.verificationImageBase64,alt:"Citation verification",className:"block rounded-md",style:{width:"100%",height:"100%",objectFit:"cover",objectPosition:"left top"},loading:"lazy"}),jsxs("span",{className:"absolute left-0 right-0 bottom-0 flex items-center justify-between px-2 pb-1.5 pt-4 bg-gradient-to-t from-black/30 to-transparent rounded-b-md",children:[jsxs("span",{className:`inline-flex items-center gap-1 ${p?"text-green-400":r.isPartialMatch?"text-amber-400":r.isMiss?"text-red-400":"text-gray-400"}`,children:[S&&jsx("span",{className:"w-3 h-3",children:jsx(q,{})}),r.isMiss&&jsx("span",{className:"w-3 h-3",children:jsx(re,{})})]}),jsx("span",{className:"text-xs text-white/80 opacity-0 group-hover:opacity-100 transition-opacity",children:"Click to expand"})]})]}),(s||c)&&jsx(ft,{citation:e,verification:t,status:r})]})}if(a||u){let p=e.fullPhrase||e.keySpan?.toString();return jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[200px] max-w-[400px]",children:[jsxs("span",{className:"text-xs font-medium text-gray-500 dark:text-gray-400",children:[jsx("span",{className:"inline-block relative top-[0.1em] mr-1.5 size-2 animate-spin",children:jsx(ie,{})}),"Searching..."]}),p&&jsxs("p",{className:"p-2 bg-gray-100 dark:bg-gray-800 rounded font-mono text-[11px] break-words text-gray-600 dark:text-gray-400 italic",children:['"',p.length>80?p.slice(0,80)+"\u2026":p,'"']}),e.pageNumber&&e.pageNumber>0&&jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Looking on page ",e.pageNumber]})]})}if(s)return jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[200px] max-w-[400px]",children:[jsxs("span",{className:"text-xs font-medium text-red-600 dark:text-red-500",children:[jsx("span",{className:"inline-block relative top-[0.1em] mr-1.5 size-3 text-amber-500 dark:text-amber-400",children:jsx(re,{})}),"Not found: ",e.keySpan||e.fullPhrase]}),jsx(hr,{citation:e,verification:t,isExpanded:o,onExpandChange:i})]});let l=dr(r),g=t?.verifiedMatchSnippet,x=t?.verifiedPageNumber;return !g&&!l?null:jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[180px] max-w-full",children:[l&&jsx("span",{className:b("text-xs font-medium",r.isVerified&&!r.isPartialMatch&&"text-green-600 dark:text-green-500",r.isPartialMatch&&"text-amber-600 dark:text-amber-500",r.isMiss&&"text-red-600 dark:text-red-500",r.isPending&&"text-gray-500 dark:text-gray-400"),children:l}),g&&jsxs("span",{className:"text-sm text-gray-700 dark:text-gray-300 italic",children:['"',t.verifiedMatchSnippet,'"']}),x&&x>0&&jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Page ",x]}),(s||c)&&jsx(ft,{citation:e,verification:t,status:r})]})}function ft({citation:e,verification:t,status:r}){let{isMiss:n,isPartialMatch:a}=r,o=e.fullPhrase||e.keySpan?.toString()||"",i=t?.verifiedMatchSnippet||"",{diffResult:d,hasDiff:s,isHighVariance:c}=mt(o,i);if(!n&&!a)return null;let u=e.lineIds,l=t?.verifiedLineIds,g=u&&l&&JSON.stringify(u)!==JSON.stringify(l),x=e.pageNumber,p=t?.verifiedPageNumber,S=x!=null&&p!=null&&x!==p;return n?jsxs("div",{className:"mt-2 pt-2 border-t border-gray-200 dark:border-gray-700 text-xs space-y-2",children:[o&&jsxs("div",{children:[jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Expected"}),jsx("p",{className:"mt-1 p-2 bg-gray-100 dark:bg-gray-800 rounded font-mono text-[11px] break-words text-red-600 dark:text-red-400 line-through opacity-70",children:o.length>100?o.slice(0,100)+"\u2026":o})]}),jsxs("div",{children:[jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Found"}),jsxs("p",{className:"mt-1 p-2 bg-gray-100 dark:bg-gray-800 rounded font-mono text-[11px] text-amber-600 dark:text-amber-500 italic",children:['Not found: "',e.keySpan||e.fullPhrase,'"']})]})]}):jsxs("div",{className:"mt-2 pt-2 border-t border-gray-200 dark:border-gray-700 text-xs space-y-2",children:[o&&i&&s?jsxs("div",{children:[jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Diff"}),jsx("div",{className:"mt-1 p-2 bg-gray-100 dark:bg-gray-800 rounded font-mono text-[11px] break-words text-gray-700 dark:text-gray-300",children:c?jsxs("div",{className:"space-y-2",children:[jsxs("div",{children:[jsxs("span",{className:"text-gray-500 dark:text-gray-400 text-[10px]",children:["Expected:"," "]}),jsx("span",{className:"text-red-600 dark:text-red-400 line-through opacity-70",children:o.length>100?o.slice(0,100)+"\u2026":o})]}),jsxs("div",{children:[jsxs("span",{className:"text-gray-500 dark:text-gray-400 text-[10px]",children:["Found:"," "]}),jsx("span",{className:"text-green-600 dark:text-green-400",children:i.length>100?i.slice(0,100)+"\u2026":i})]})]}):d.map((E,h)=>jsx("span",{children:E.parts.map((P,w)=>{let L=`p-${h}-${w}`;return P.removed?jsx("span",{className:"bg-red-200 dark:bg-red-900/50 text-red-700 dark:text-red-300 line-through",title:"Expected text",children:P.value},L):P.added?jsx("span",{className:"bg-green-200 dark:bg-green-900/50 text-green-700 dark:text-green-300",title:"Actual text found",children:P.value},L):jsx("span",{children:P.value},L)})},`block-${h}`))})]}):o&&!s?jsxs("div",{children:[jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Text"}),jsx("p",{className:"mt-1 p-2 bg-gray-100 dark:bg-gray-800 rounded font-mono text-[11px] break-words text-gray-700 dark:text-gray-300",children:o.length>100?o.slice(0,100)+"\u2026":o})]}):null,S&&jsxs("div",{children:[jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Page"}),jsxs("p",{className:"mt-1 font-mono text-[11px] text-gray-700 dark:text-gray-300",children:[jsx("span",{className:"text-red-600 dark:text-red-400 line-through opacity-70",children:x})," \u2192 ",p]})]}),g&&jsxs("div",{children:[jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Line"}),jsxs("p",{className:"mt-1 font-mono text-[11px] text-gray-700 dark:text-gray-300",children:[jsx("span",{className:"text-red-600 dark:text-red-400 line-through opacity-70",children:u?.join(", ")})," \u2192 ",l?.join(", ")]})]})]})}var _e=forwardRef(({citation:e,children:t,className:r,fallbackDisplay:n,verification:a,isLoading:o=false,variant:i="brackets",content:d$1,eventHandlers:s,behaviorConfig:c,isMobile:u=false,renderIndicator:l,renderContent:g,popoverPosition:x="top",renderPopoverContent:p,additionalCount:S,faviconUrl:E},h)=>{let{isAnyOverlayOpen:P}=ve(),w=useMemo(()=>d$1||sr(i),[d$1,i]),[L,_]=useState(false),[j,T]=useState(null),[A,U]=useState(false),v=useMemo(()=>d(e),[e]),ce=useMemo(()=>f(v),[v]),b$1=useMemo(()=>ur(a),[a]),{isMiss:C,isPartialMatch:D,isVerified:z,isPending:Y}=b$1,de=5e3,[ue,Q]=useState(false),M=useRef(null),Ce=a?.verificationImageBase64||a?.status==="found"||a?.status==="found_key_span_only"||a?.status==="found_phrase_missed_value"||a?.status==="not_found"||a?.status==="partial_text_found"||a?.status==="found_on_other_page"||a?.status==="found_on_other_line"||a?.status==="first_word_found",V=(o||Y)&&!Ce&&!ue;useEffect(()=>(M.current&&(clearTimeout(M.current),M.current=null),(o||Y)&&!Ce?(Q(false),M.current=setTimeout(()=>{Q(true);},de)):Q(false),()=>{M.current&&clearTimeout(M.current);}),[o,Y,Ce]);let F=useMemo(()=>cr(e,w,n),[e,w,n]),Z=useCallback(()=>({citation:e,citationKey:v,verification:a??null,isTooltipExpanded:L,isImageExpanded:!!j,hasImage:!!a?.verificationImageBase64}),[e,v,a,L,j]),$e=useCallback(N=>{N.setImageExpanded!==void 0&&(typeof N.setImageExpanded=="string"?T(N.setImageExpanded):N.setImageExpanded===true&&a?.verificationImageBase64?T(a.verificationImageBase64):N.setImageExpanded===false&&T(null));},[a?.verificationImageBase64]),kt=useCallback(N=>{N.preventDefault(),N.stopPropagation();let te=Z();if(c?.onClick){let me=c.onClick(te,N);me&&typeof me=="object"&&$e(me),s?.onClick?.(e,v,N);return}if(s?.onClick){s.onClick(e,v,N);return}a?.verificationImageBase64?T(a.verificationImageBase64):C&&U(me=>!me);},[c,s,e,v,a?.verificationImageBase64,C,Z,$e]),Fe=150,ee=useRef(null),we=useRef(false),J=useCallback(()=>{ee.current&&(clearTimeout(ee.current),ee.current=null);},[]),Ct=useCallback(()=>{P||(J(),_(true),c?.onHover?.onEnter&&c.onHover.onEnter(Z()),s?.onMouseEnter?.(e,v));},[s,c,e,v,Z,J,P]),wt=useCallback(()=>{J(),ee.current=setTimeout(()=>{we.current||(_(false),c?.onHover?.onLeave&&c.onHover.onLeave(Z()),s?.onMouseLeave?.(e,v));},Fe);},[s,c,e,v,Z,J]),Nt=useCallback(()=>{J(),we.current=true;},[J]),Pt=useCallback(()=>{we.current=false,J(),ee.current=setTimeout(()=>{_(false),c?.onHover?.onLeave&&c.onHover.onLeave(Z()),s?.onMouseLeave?.(e,v);},Fe);},[s,c,e,v,Z,J]);useEffect(()=>()=>{ee.current&&clearTimeout(ee.current);},[]);let St=useCallback(N=>{u&&(N.preventDefault(),N.stopPropagation(),s?.onTouchEnd?.(e,v,N));},[s,e,v,u]);if(n!=null&&w==="keySpan"&&C)return jsx("span",{className:b("text-gray-400 dark:text-gray-500",r),children:n});let Ne=b((z||D)&&i==="brackets"&&"text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 hover:underline",C&&"opacity-70 line-through text-gray-400 dark:text-gray-500",V&&"text-gray-500 dark:text-gray-400"),ae=()=>l?l(b$1):V?jsx(fr,{}):z&&!D?jsx(pr,{}):D?jsx(gr,{}):C?jsx(xr,{}):null,Ke=()=>{if(g)return g({citation:e,status:b$1,citationKey:v,displayText:F,isMergedDisplay:w==="keySpan"});if(w==="indicator")return jsx("span",{children:ae()});if(i==="chip"){let N=b(z&&!D&&!V&&"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",D&&!V&&"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",C&&!V&&"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400 line-through",V&&"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400",!z&&!C&&!V&&"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400");return jsxs("span",{className:b("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-sm font-medium",N),children:[jsx("span",{className:"max-w-60 overflow-hidden text-ellipsis whitespace-nowrap",children:F}),ae()]})}if(i==="superscript"){let N=b(z&&!D&&!V&&"text-green-600 dark:text-green-500",D&&!V&&"text-amber-600 dark:text-amber-500",C&&!V&&"text-red-500 dark:text-red-400 line-through",V&&"text-gray-400 dark:text-gray-500",!z&&!C&&!V&&"text-blue-600 dark:text-blue-400");return jsxs("sup",{className:b("text-xs font-medium transition-colors hover:underline",N),children:["[",F,ae(),"]"]})}if(i==="text")return jsxs("span",{className:Ne,children:[F,ae()]});if(i==="minimal")return jsxs("span",{className:b("max-w-80 overflow-hidden text-ellipsis",Ne),children:[F,ae()]});if(i==="source"){let N=E||e.faviconUrl;return jsxs("span",{className:b("inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-sm font-medium","bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-300","hover:bg-gray-200 dark:hover:bg-gray-700","transition-colors cursor-pointer"),children:[N&&jsx("img",{src:N,alt:"",className:"w-4 h-4 rounded-sm object-contain",loading:"lazy",onError:te=>{te.target.style.display="none";}}),jsx("span",{className:"max-w-40 overflow-hidden text-ellipsis whitespace-nowrap",children:F}),S!==void 0&&S>0&&jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:["+",S]})]})}return jsxs("span",{className:b("inline-flex items-baseline gap-0.5 whitespace-nowrap","font-mono text-xs leading-tight","text-gray-500 dark:text-gray-400","transition-colors"),"aria-hidden":"true",children:["[",jsxs("span",{className:b("max-w-80 overflow-hidden text-ellipsis",Ne),children:[F,ae()]}),"]"]})},Lt=!(x==="hidden")&&(a&&(a.verificationImageBase64||a.verifiedMatchSnippet)||V||Y||o||C),Mt=!!a?.verificationImageBase64,Ge=j?jsx(mr,{src:j,alt:"Citation verification - full size",onClose:()=>T(null)}):null,Xe={"data-citation-id":v,"data-citation-instance":ce,className:b("relative inline-flex items-baseline cursor-pointer","px-0.5 -mx-0.5 rounded-sm","transition-all duration-[50ms]","hover:bg-blue-500/10 dark:hover:bg-blue-400/10",Mt&&"cursor-zoom-in",r),onMouseEnter:Ct,onMouseLeave:wt,onClick:kt,onTouchEndCapture:u?St:void 0,"aria-label":F?`[${F}]`:void 0};if(Lt){let N=p?p({citation:e,verification:a??null,status:b$1}):jsx(yr,{citation:e,verification:a??null,status:b$1,isLoading:o||V,isPhrasesExpanded:A,onPhrasesExpandChange:U,onImageClick:()=>{a?.verificationImageBase64&&T(a.verificationImageBase64);}});return jsxs(Fragment,{children:[t,jsxs(rt,{open:L,children:[jsx(at,{asChild:true,children:jsx("span",{ref:h,...Xe,children:Ke()})}),jsx(Me,{side:x==="bottom"?"bottom":"top",onPointerDownOutside:te=>te.preventDefault(),onInteractOutside:te=>te.preventDefault(),onMouseEnter:Nt,onMouseLeave:Pt,children:N})]}),Ge]})}return jsxs(Fragment,{children:[t,jsx("span",{ref:h,...Xe,children:Ke()}),Ge]})});_e.displayName="CitationComponent";var vr=memo(_e);function yt(e,t){return t||`https://www.google.com/s2/favicons?domain=${K(e)}&sz=32`}function Oe(e){if(!e.startsWith("http://")&&!e.startsWith("https://"))return "unknown";try{let t=K(e).toLowerCase();return t.includes("twitter.com")||t==="x.com"||t.endsWith(".x.com")||t.includes("facebook.com")||t.includes("instagram.com")||t.includes("linkedin.com")||t.includes("threads.net")||t.includes("mastodon")?"social":t.includes("youtube.com")||t.includes("youtu.be")||t.includes("twitch.tv")||t.includes("vimeo.com")||t.includes("tiktok.com")?"video":t.includes("github.com")||t.includes("gitlab.com")||t.includes("bitbucket.org")||t.includes("stackoverflow.com")?"code":t.includes("arxiv.org")||t.includes("scholar.google")||t.includes("pubmed")||t.includes("doi.org")||t.includes("researchgate.net")||t.includes("academia.edu")?"academic":t.includes("news.")||t.includes("reuters.com")||t.includes("bbc.com")||t.includes("cnn.com")||t.includes("nytimes.com")||t.includes("wsj.com")||t.includes("theguardian.com")||t.includes("washingtonpost.com")?"news":t.includes("wikipedia.org")||t.includes("britannica.com")||t.includes("merriam-webster.com")||t.includes("dictionary.com")?"reference":t.includes("reddit.com")||t.includes("quora.com")||t.includes("discourse")||t.includes("forum")?"forum":t.includes("amazon.")||t.includes("ebay.")||t.includes("shopify")||t.includes("etsy.com")?"commerce":e.toLowerCase().endsWith(".pdf")?"pdf":"web"}catch{return "unknown"}}function Ve(e,t){let r=(t||K(e)).toLowerCase(),n={"twitter.com":"X","x.com":"X","facebook.com":"Facebook","instagram.com":"Instagram","linkedin.com":"LinkedIn","youtube.com":"YouTube","youtu.be":"YouTube","twitch.tv":"Twitch","github.com":"GitHub","gitlab.com":"GitLab","stackoverflow.com":"Stack Overflow","reddit.com":"Reddit","wikipedia.org":"Wikipedia","arxiv.org":"arXiv","medium.com":"Medium","substack.com":"Substack","notion.so":"Notion","docs.google.com":"Google Docs","drive.google.com":"Google Drive","figma.com":"Figma","streamscharts.com":"Streams Charts","dexerto.com":"Dexerto"};if(n[r])return n[r];for(let[a,o]of Object.entries(n))if(r===a||r.endsWith("."+a))return o;return r.charAt(0).toUpperCase()+r.slice(1)}var Cr=()=>jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),wr=()=>jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:jsx("polyline",{points:"9 18 15 12 9 6"})}),Nr=()=>jsxs("svg",{className:"animate-spin",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),ye=forwardRef(({id:e,url:t,title:r,domain:n,sourceType:a,faviconUrl:o,citationNumbers:i,verificationStatus:d,onClick:s,className:c,showVerificationIndicator:u=false,showCitationBadges:l=false,renderFavicon:g},x)=>{let p=useCallback(w=>{s?s({id:e,url:t,title:r,domain:n,sourceType:a,faviconUrl:o,citationNumbers:i,verificationStatus:d},w):window.open(t,"_blank","noopener,noreferrer");},[s,e,t,r,n,a,o,i,d]),S=useMemo(()=>Ve(t,n),[t,n]),E=useMemo(()=>yt(t,o),[t,o]),h=useMemo(()=>a||Oe(t),[a,t]),P=()=>{if(!u||!d)return null;let L={verified:{icon:"\u2713",className:"text-green-600 dark:text-green-500"},partial:{icon:"~",className:"text-amber-600 dark:text-amber-500"},pending:{icon:"\u2026",className:"text-gray-400 dark:text-gray-500"},failed:{icon:"\u2717",className:"text-red-500 dark:text-red-400"},unknown:{icon:"?",className:"text-gray-400 dark:text-gray-500"}}[d];return jsx("span",{className:j("text-sm ml-1",L.className),"aria-label":d,children:L.icon})};return jsxs("div",{ref:x,"data-source-id":e,"data-source-type":h,className:j("flex items-start gap-3 p-3 cursor-pointer transition-colors","hover:bg-gray-50 dark:hover:bg-gray-800/50","border-b border-gray-100 dark:border-gray-800 last:border-b-0",c),onClick:p,role:"link",tabIndex:0,onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),p(w));},"aria-label":`${r} from ${S}`,children:[jsx("div",{className:"flex-shrink-0 mt-0.5",children:g?g({id:e,url:t,title:r,domain:n,sourceType:a,faviconUrl:o,citationNumbers:i,verificationStatus:d}):jsx("img",{src:E,alt:"",className:"w-5 h-5 rounded",width:20,height:20,loading:"lazy",onError:w=>{w.target.style.display="none";}})}),jsxs("div",{className:"flex-1 min-w-0",children:[jsxs("div",{className:"flex items-center gap-1",children:[jsx("span",{className:"text-gray-900 dark:text-gray-100 font-medium text-sm leading-tight line-clamp-2",children:r}),P()]}),jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[jsx("span",{className:"text-gray-500 dark:text-gray-400 text-xs",children:S}),l&&i&&i.length>0&&jsxs("div",{className:"flex items-center gap-1",children:[i.slice(0,3).map(w=>jsx("span",{className:"inline-flex items-center justify-center w-4 h-4 text-[10px] font-medium bg-gray-200 dark:bg-gray-700 text-gray-600 dark:text-gray-300 rounded",children:w},w)),i.length>3&&jsxs("span",{className:"text-xs text-gray-400",children:["+",i.length-3]})]})]})]}),jsx("div",{className:"flex-shrink-0 text-gray-400 dark:text-gray-500 mt-1",children:jsx(wr,{})})]})});ye.displayName="SourcesListItem";var je=forwardRef(({sources:e,maxIcons:t=3,onClick:r,label:n="Sources",className:a,isOpen:o},i)=>{let d=useMemo(()=>e.slice(0,t),[e,t]),s=e.length>t;return jsxs("button",{ref:i,type:"button",onClick:r,className:j("inline-flex items-center gap-2 px-3 py-1.5 rounded-full text-sm","bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300","hover:bg-gray-200 dark:hover:bg-gray-700 transition-colors","focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2",a),"aria-expanded":o,"aria-haspopup":"dialog",children:[jsx("span",{className:"font-medium",children:n}),jsxs("div",{className:"flex items-center -space-x-1",children:[d.map((c,u)=>jsx("img",{src:yt(c.url,c.faviconUrl),alt:"",className:j("w-4 h-4 rounded-full ring-2 ring-gray-100 dark:ring-gray-800",u>0&&"-ml-1"),width:16,height:16,loading:"lazy",onError:l=>{l.target.style.opacity="0";}},c.id)),s&&jsxs("span",{className:"w-4 h-4 rounded-full bg-gray-300 dark:bg-gray-600 ring-2 ring-gray-100 dark:ring-gray-800 flex items-center justify-center text-[9px] font-medium text-gray-600 dark:text-gray-300",children:["+",e.length-t]})]})]})});je.displayName="SourcesTrigger";var ze=forwardRef(({sources:e,variant:t="drawer",isOpen:r=true,onOpenChange:n,header:a={},isLoading:o=false,emptyMessage:i="No sources available",maxHeight:d,className:s,listClassName:c,onSourceClick:u,showVerificationIndicators:l=false,showCitationBadges:g=false,groupByDomain:x=false,renderItem:p,renderEmpty:S,renderLoading:E},h)=>{let P=useRef(null),[w,L]=useState(false);useEffect(()=>{if(!r||t==="inline")return;let b=C=>{C.key==="Escape"&&n?.(false);};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[r,n,t]),useEffect(()=>{L(true);},[]);let _=useMemo(()=>{if(!x)return null;let b={};for(let C of e){let D=C.domain||K(C.url);b[D]||(b[D]=[]),b[D].push(C);}return b},[e,x]),j$1=useCallback(()=>{n?.(false);},[n]),T=useCallback(b=>{b.target===b.currentTarget&&j$1();},[j$1]),A=()=>{let{title:b="Sources",showCloseButton:C=true,showCount:D=true,renderHeader:z}=a;return z?z({title:b,count:e.length,onClose:j$1}):jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-200 dark:border-gray-700",children:[C&&t!=="inline"&&jsx("button",{type:"button",onClick:j$1,className:"p-1 -ml-1 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 transition-colors","aria-label":"Close sources",children:jsx(Cr,{})}),jsxs("h2",{className:"text-base font-semibold text-gray-900 dark:text-gray-100 flex-1 text-center",children:[b,D&&jsxs("span",{className:"ml-2 text-sm font-normal text-gray-500 dark:text-gray-400",children:["(",e.length,")"]})]}),C&&t!=="inline"&&jsx("div",{className:"w-8"})]})},U=()=>o?E?E():jsxs("div",{className:"flex items-center justify-center py-8 text-gray-500 dark:text-gray-400",children:[jsx(Nr,{}),jsx("span",{className:"ml-2 text-sm",children:"Loading sources..."})]}):e.length===0?S?S():jsx("div",{className:"flex items-center justify-center py-8 text-gray-500 dark:text-gray-400 text-sm",children:i}):x&&_?jsx("div",{className:c,children:Object.entries(_).map(([b,C])=>jsxs("div",{children:[jsx("div",{className:"px-4 py-2 text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider bg-gray-50 dark:bg-gray-800/50",children:Ve(C[0].url,b)}),C.map((D,z)=>p?p(D,z):jsx(ye,{...D,onClick:u,showVerificationIndicator:l,showCitationBadges:g},D.id))]},b))}):jsx("div",{className:c,children:e.map((b,C)=>p?p(b,C):jsx(ye,{...b,onClick:u,showVerificationIndicator:l,showCitationBadges:g},b.id))}),v=d?{maxHeight:typeof d=="number"?`${d}px`:d}:void 0;if(t==="inline")return r?jsxs("div",{ref:h,className:j("bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700",s),style:v,children:[A(),jsx("div",{className:"overflow-y-auto",style:v,children:U()})]}):null;if(t==="panel")return r?jsxs("div",{ref:h,className:j("bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700 shadow-lg",s),children:[A(),jsx("div",{className:"overflow-y-auto",style:v||{maxHeight:"400px"},children:U()})]}):null;if(!w||!r)return null;let ce=jsxs("div",{ref:h,className:j("fixed inset-0 z-50",t==="modal"&&"flex items-center justify-center"),role:"dialog","aria-modal":"true","aria-labelledby":"sources-title",children:[jsx("div",{className:j("absolute inset-0 bg-black/40 dark:bg-black/60 transition-opacity",r?"opacity-100":"opacity-0"),onClick:T,"aria-hidden":"true"}),t==="drawer"?jsxs("div",{ref:P,className:j("absolute bottom-0 left-0 right-0 bg-white dark:bg-gray-900 rounded-t-2xl shadow-2xl","transform transition-transform duration-300 ease-out",r?"translate-y-0":"translate-y-full","max-h-[80vh] flex flex-col",s),children:[jsx("div",{className:"flex justify-center py-2",children:jsx("div",{className:"w-10 h-1 bg-gray-300 dark:bg-gray-600 rounded-full"})}),A(),jsx("div",{className:"overflow-y-auto flex-1",children:U()})]}):jsxs("div",{ref:P,className:j("relative bg-white dark:bg-gray-900 rounded-xl shadow-2xl","transform transition-all duration-200",r?"opacity-100 scale-100":"opacity-0 scale-95","w-full max-w-md max-h-[80vh] flex flex-col mx-4",s),children:[A(),jsx("div",{className:"overflow-y-auto flex-1",children:U()})]})]});return createPortal(ce,document.body)});ze.displayName="SourcesListComponent";var Pr=memo(ye),Sr=memo(je),Lr=memo(ze);function Mr(e){let t=new Map;for(let r of e){if(!r.url)continue;let n=r.domain||K(r.url),a=r.url;if(t.has(a)){let o=t.get(a);r.citationNumber&&!o.citationNumbers?.includes(r.citationNumber)&&(o.citationNumbers=[...o.citationNumbers||[],r.citationNumber]);}else t.set(a,{id:a,url:r.url,title:r.title||n,domain:n,sourceType:r.sourceType||Oe(r.url),faviconUrl:r.faviconUrl,citationNumbers:r.citationNumber?[r.citationNumber]:[]});}return Array.from(t.values())}function Ir(e=[]){let[t,r]=useState(e),[n,a]=useState(false),o=useCallback(s=>{r(c=>c.some(l=>l.url===s.url)?c:[...c,s]);},[]),i=useCallback(s=>{r(c=>c.filter(u=>u.id!==s));},[]),d=useCallback(()=>{r([]);},[]);return {sources:t,setSources:r,addSource:o,removeSource:i,clearSources:d,isOpen:n,setIsOpen:a,open:()=>a(true),close:()=>a(false),toggle:()=>a(s=>!s)}}function bt(e){let t=new Map;for(let r of e){let n=r.citation.domain||r.citation.siteName||r.citation.url||"unknown";t.has(n)||t.set(n,[]),t.get(n).push(r);}return Array.from(t.entries()).map(([r,n])=>{let a=n[0].citation;return {sourceName:a.siteName||a.domain||Ae(a.url)||"Unknown Source",sourceDomain:a.domain||Ae(a.url),sourceFavicon:a.faviconUrl||void 0,citations:n,additionalCount:n.length-1}})}function Ae(e){if(e)try{return new URL(e).hostname.replace(/^www\./,"")}catch{return}}function Dr(e){let t=e?.status;return !t||t==="pending"||t==="loading"?{color:"text-gray-400",icon:jsx(ie,{}),label:"Verifying"}:t==="not_found"?{color:"text-amber-500",icon:jsx(re,{}),label:"Not found"}:t==="partial_text_found"||t==="found_on_other_page"||t==="found_on_other_line"||t==="first_word_found"?{color:"text-amber-500",icon:jsx(q,{}),label:"Partial match"}:{color:"text-green-500",icon:jsx(q,{}),label:"Verified"}}function He({item:e,isLast:t=false,onClick:r,onReadMore:n,className:a}){let{citation:o,verification:i}=e,d=Dr(i),s=o.siteName||o.domain||Ae(o.url)||"Source",c=o.title||o.keySpan||o.fullPhrase,u=o.description||i?.actualContentSnippet||i?.verifiedMatchSnippet,l=o.faviconUrl,g=useCallback(()=>{r?.(e);},[e,r]),x=useCallback(p=>{p.stopPropagation(),n?.(e);},[e,n]);return jsx("div",{className:b("px-4 py-3 hover:bg-gray-50 dark:hover:bg-gray-800/50 cursor-pointer transition-colors",!t&&"border-b border-gray-200 dark:border-gray-700",a),onClick:g,role:"button",tabIndex:0,onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),g());},children:jsxs("div",{className:"flex items-start gap-3",children:[jsx("div",{className:"flex-shrink-0 mt-0.5",children:l?jsx("img",{src:l,alt:"",className:"w-5 h-5 rounded object-contain",loading:"lazy",onError:p=>{p.target.style.display="none";}}):jsx("div",{className:"w-5 h-5 rounded bg-gray-200 dark:bg-gray-700 flex items-center justify-center",children:jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:s.charAt(0).toUpperCase()})})}),jsxs("div",{className:"flex-1 min-w-0",children:[jsxs("div",{className:"flex items-center gap-1.5",children:[jsx("span",{className:"text-xs font-medium text-gray-500 dark:text-gray-400",children:s}),jsx("span",{className:b("inline-flex w-3 h-3",d.color,i?.status==="pending"||i?.status==="loading"?"animate-spin":""),title:d.label,children:d.icon})]}),c&&jsx("h4",{className:"mt-1 text-sm font-medium text-gray-900 dark:text-gray-100 line-clamp-2",children:c}),u&&jsxs("p",{className:"mt-1 text-sm text-gray-600 dark:text-gray-400 line-clamp-2",children:[u,n&&u.length>100&&jsx("button",{onClick:x,className:"ml-1 text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300",children:"Read more"})]})]})]})})}function _r({isOpen:e,onClose:t,citationGroups:r,title:n="Citations",showMoreSection:a=true,maxVisibleItems:o=3,onCitationClick:i,onReadMore:d,className:s,position:c="bottom",renderCitationItem:u}){let[l,g]=useState(false),x=useMemo(()=>r.flatMap(h=>h.citations),[r]),p=useMemo(()=>!a||l?x:x.slice(0,o),[x,a,l,o]),S=useMemo(()=>!a||l?[]:x.slice(o),[x,a,l,o]);if(We__default.useEffect(()=>{if(!e)return;let h=P=>{P.key==="Escape"&&t();};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[e,t]),!e)return null;let E=jsxs(Fragment,{children:[jsx("div",{className:"fixed inset-0 bg-black/40 z-[9998] animate-in fade-in-0 duration-150",onClick:t,"aria-hidden":"true"}),jsxs("div",{className:b("fixed z-[9999] bg-white dark:bg-gray-900 shadow-xl","animate-in duration-200",c==="bottom"&&"inset-x-0 bottom-0 max-h-[80vh] rounded-t-2xl slide-in-from-bottom-4",c==="right"&&"inset-y-0 right-0 w-full max-w-md slide-in-from-right-4",s),role:"dialog","aria-modal":"true","aria-label":n,children:[c==="bottom"&&jsx("div",{className:"flex justify-center pt-3 pb-1",children:jsx("div",{className:"w-10 h-1 rounded-full bg-gray-300 dark:bg-gray-600"})}),jsxs("div",{className:"px-4 py-3 border-b border-gray-200 dark:border-gray-700 flex items-center justify-between",children:[jsx("h2",{className:"text-base font-semibold text-gray-900 dark:text-gray-100",children:n}),jsx("button",{onClick:t,className:"p-1.5 rounded-full hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors","aria-label":"Close",children:jsx("svg",{className:"w-5 h-5 text-gray-500 dark:text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),jsx("div",{className:"overflow-y-auto max-h-[calc(80vh-100px)]",children:p.length===0?jsx("div",{className:"px-4 py-8 text-center text-gray-500 dark:text-gray-400",children:"No citations to display"}):jsxs(Fragment,{children:[p.map((h,P)=>u?jsx(We__default.Fragment,{children:u(h)},h.citationKey):jsx(He,{item:h,isLast:P===p.length-1&&S.length===0,onClick:i,onReadMore:d},h.citationKey)),S.length>0&&!l&&jsx("div",{className:"px-4 py-3 border-t border-gray-200 dark:border-gray-700",children:jsxs("button",{onClick:()=>g(true),className:"text-sm font-medium text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300",children:["More (",S.length,")"]})}),l&&S.map((h,P)=>u?jsx(We__default.Fragment,{children:u(h)},h.citationKey):jsx(He,{item:h,isLast:P===S.length-1,onClick:i,onReadMore:d},h.citationKey))]})})]})]});return createPortal(E,document.body)}function Rr(){let[e,t]=useState(false),[r,n]=useState([]),a=useCallback(()=>t(true),[]),o=useCallback(()=>t(false),[]),i=useCallback(()=>t(g=>!g),[]),d=useCallback(g=>{n(x=>x.some(p=>p.citationKey===g.citationKey)?x:[...x,g]);},[]),s=useCallback(g=>{n(x=>x.filter(p=>p.citationKey!==g));},[]),c=useCallback(()=>{n([]);},[]),u=useCallback(g=>{n(g);},[]),l=useMemo(()=>bt(r),[r]);return {isOpen:e,openDrawer:a,closeDrawer:o,toggleDrawer:i,citations:r,citationGroups:l,addCitation:d,removeCitation:s,clearCitations:c,setCitations:u}}
5
- export{q as CheckIcon,_e as CitationComponent,_r as CitationDrawer,He as CitationDrawerItemComponent,tr as CitationOverlayProvider,Ft as CloseIcon,At as DeepCitationIcon,$t as ExternalLinkIcon,Ht as LinkIcon,vr as MemoizedCitationComponent,Lr as MemoizedSourcesListComponent,Pr as MemoizedSourcesListItem,Sr as MemoizedSourcesTrigger,ze as SourcesListComponent,ye as SourcesListItem,je as SourcesTrigger,ie as SpinnerIcon,re as WarningIcon,Oe as detectSourceType,K as extractDomain,Ve as getPlatformName,bt as groupCitationsBySource,jt as isAccessibleStatus,Je as isBlockedStatus,qe as isErrorStatus,zt as isRedirectedStatus,Wt as isVerifiedStatus,Mr as sourceCitationsToListItems,Rr as useCitationDrawer,ve as useCitationOverlay,rr as useHasCitationOverlayProvider,Ir as useSourcesList};
1
+ import {d,f,j,b}from'../chunk-N7FTXSGM.js';export{k as CITATION_X_PADDING,l as CITATION_Y_PADDING,j as classNames,f as generateCitationInstanceId,d as generateCitationKey,i as getCitationAnchorText,g as getCitationDisplayText,h as getCitationNumber,c as isUrlCitation}from'../chunk-N7FTXSGM.js';import'../chunk-BDSA6VGC.js';import'../chunk-5XGN7UAV.js';import*as ft from'react';import ft__default,{forwardRef,useMemo,useCallback,memo,createContext,useState,useRef,useEffect,useContext}from'react';import {jsxs,Fragment,jsx}from'react/jsx-runtime';import {createPortal}from'react-dom';import*as ae from'@radix-ui/react-popover';var Tr=({className:e})=>jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"square",shapeRendering:"crispEdges",className:e,width:"1em",height:"1em",children:[jsx("path",{d:"M7 3 L3 3 L3 21 L7 21"}),jsx("path",{d:"M17 3 L21 3 L21 21 L17 21"})]}),Pe=({className:e})=>jsx("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round","aria-hidden":"true",width:"100%",height:"100%",children:jsx("line",{x1:"6",y1:"12",x2:"18",y2:"12"})}),B=({className:e})=>jsx("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",width:"100%",height:"100%",children:jsx("polyline",{points:"20 6 9 17 4 12"})}),Ne=({className:e})=>jsx("svg",{className:e,viewBox:"0 0 256 256",fill:"currentColor","aria-hidden":"true",width:"100%",height:"100%",children:jsx("path",{d:"M236.8,188.09,149.35,36.22h0a24.76,24.76,0,0,0-42.7,0L19.2,188.09a23.51,23.51,0,0,0,0,23.72A24.35,24.35,0,0,0,40.55,224h174.9a24.35,24.35,0,0,0,21.33-12.19A23.51,23.51,0,0,0,236.8,188.09ZM120,104a8,8,0,0,1,16,0v40a8,8,0,0,1-16,0Zm8,88a12,12,0,1,1,12-12A12,12,0,0,1,128,192Z"})}),ue=({className:e})=>jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",width:"100%",height:"100%",children:[jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4",style:{opacity:.25}}),jsx("path",{fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z",style:{opacity:.75}})]}),Lr=({className:e})=>jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",width:"100%",height:"100%",children:[jsx("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),jsx("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]}),Mr=({className:e})=>jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",width:"100%",height:"100%",children:[jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),jsx("polyline",{points:"15 3 21 3 21 9"}),jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]}),Be=({className:e})=>jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",width:"100%",height:"100%",children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),Qe=({className:e})=>jsx("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",width:"100%",height:"100%",children:jsx("path",{d:"M12 2a5 5 0 0 0-5 5v3H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8a2 2 0 0 0-2-2h-1V7a5 5 0 0 0-5-5zm3 8H9V7a3 3 0 0 1 6 0v3z"})});function q(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e.replace(/^https?:\/\/(www\.)?/,"").split("/")[0]}}function qe(e,t){return e.length<=t?e:e.slice(0,t-1)+"\u2026"}function Tt(e){try{let t=new URL(e),r=t.pathname+t.search;return r==="/"?"":r}catch{return ""}}var Lt={verified:{icon:"\u2713",label:"Verified",className:"text-green-600 dark:text-green-500"},partial:{icon:"~",label:"Partial match",className:"text-amber-600 dark:text-amber-500"},pending:{icon:"\u2026",label:"Verifying",className:"text-gray-400 dark:text-gray-500"},accessible:{icon:"\u25CB",label:"Accessible",className:"text-blue-500 dark:text-blue-400"},redirected:{icon:"\u21AA",label:"Redirected",className:"text-amber-600 dark:text-amber-500"},redirected_valid:{icon:"\u21AA\u2713",label:"Redirected (valid)",className:"text-green-600 dark:text-green-500"},blocked_antibot:{icon:"\u2298",label:"Blocked by anti-bot",className:"text-amber-600 dark:text-amber-500"},blocked_login:{icon:"\u2299",label:"Login required",className:"text-amber-600 dark:text-amber-500"},blocked_paywall:{icon:"$",label:"Paywall",className:"text-amber-600 dark:text-amber-500"},blocked_geo:{icon:"\u2295",label:"Geo-restricted",className:"text-amber-600 dark:text-amber-500"},blocked_rate_limit:{icon:"\u25D4",label:"Rate limited",className:"text-amber-600 dark:text-amber-500"},error_timeout:{icon:"\u25F7",label:"Timed out",className:"text-red-500 dark:text-red-400"},error_not_found:{icon:"404",label:"Not found",className:"text-red-500 dark:text-red-400"},error_server:{icon:"\u26A0",label:"Server error",className:"text-red-500 dark:text-red-400"},error_network:{icon:"\u21AF",label:"Network error",className:"text-red-500 dark:text-red-400"},unknown:{icon:"?",label:"Unknown status",className:"text-gray-400 dark:text-gray-500"}};function Ze(e){return e.startsWith("blocked_")}function Je(e){return e.startsWith("error_")}function Dr(e){return e==="verified"||e==="partial"||e==="accessible"||e==="redirected_valid"}function Ar(e){return e==="redirected"||e==="redirected_valid"}function Mt(e){return e==="verified"||e==="partial"||e==="redirected_valid"}var Rr=()=>jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-gray-400 dark:bg-gray-500 animate-pulse","aria-hidden":"true"}),Vr=()=>jsx(B,{className:"w-full h-full text-green-600 dark:text-green-500"}),Te=({children:e,className:t})=>jsx("span",{className:j("w-3 h-3 flex-shrink-0 flex items-center justify-center",t),children:e}),$e=({url:e,faviconUrl:t,isBroken:r})=>{let a=q(e),o=t||`https://www.google.com/s2/favicons?domain=${a}&sz=16`;return r?jsx("span",{className:"w-3.5 h-3.5 flex items-center justify-center text-xs text-gray-400 dark:text-gray-500 flex-shrink-0",children:"\u{1F310}"}):jsx("img",{src:o,alt:"",className:"w-3.5 h-3.5 rounded-sm flex-shrink-0",width:14,height:14,loading:"lazy",onError:n=>{n.target.style.display="none";}})},et=forwardRef(({urlMeta:e,citation:t,children:r,className:a,variant:o="badge",showFullUrlOnHover:n=true,showFavicon:s=true,showTitle:i=false,maxDisplayLength:c=30,renderBlockedIndicator:l,onUrlClick:d$1,eventHandlers:u,preventTooltips:f$1=false},x)=>{let{url:p,domain:P,title:I,fetchStatus:m,faviconUrl:_,errorMessage:k}=e,M=useMemo(()=>t||{value:p,fullPhrase:I||p},[t,p,I]),w=useMemo(()=>d(M),[M]),V=useMemo(()=>f(w),[w]),E=useMemo(()=>P||q(p),[P,p]),D=useMemo(()=>Tt(p),[p]),X=useMemo(()=>{if(i&&I)return qe(I,c);let z=D?qe(D,c-E.length-1):"";return z?`${E}${z}`:E},[i,I,E,D,c]),A=Lt[m],$=Ze(m),h=Je(m),K=m==="verified",G=m==="partial",F=m==="pending",Q=h,te=useCallback(z=>{z.preventDefault(),z.stopPropagation(),d$1?d$1(p,z):window.open(p,"_blank","noopener,noreferrer"),u?.onClick?.(M,w,z);},[d$1,p,u,M,w]),ne=useCallback(()=>{u?.onMouseEnter?.(M,w);},[u,M,w]),be=useCallback(()=>{u?.onMouseLeave?.(M,w);},[u,M,w]),ve=()=>K?jsx(Te,{children:jsx(Vr,{})}):G?jsx(Te,{className:"text-amber-600 dark:text-amber-500",children:jsx(B,{className:"w-full h-full"})}):$?l?l(m,k):jsx(Te,{className:"text-amber-600 dark:text-amber-500","aria-label":A.label,children:jsx(Qe,{className:"w-full h-full"})}):h?l?l(m,k):jsx(Te,{className:"text-red-500 dark:text-red-400","aria-label":A.label,children:jsx(Be,{className:"w-full h-full"})}):F?jsx(Te,{children:jsx(Rr,{})}):null;return o==="badge"?jsxs(Fragment,{children:[r,jsxs("a",{ref:x,href:p,"data-citation-id":w,"data-citation-instance":V,"data-url":p,"data-fetch-status":m,"data-variant":"badge",className:j("inline-flex items-center gap-2 px-2 py-1","bg-white dark:bg-gray-900","border border-gray-200 dark:border-gray-700","rounded-md","text-gray-800 dark:text-gray-200","no-underline cursor-pointer","transition-all duration-150 ease-in-out","hover:border-gray-400 dark:hover:border-gray-500","hover:bg-gray-50 dark:hover:bg-gray-800",Q&&"opacity-60",a),title:n?k||p:void 0,onMouseEnter:f$1?void 0:ne,onMouseLeave:f$1?void 0:be,onClick:z=>{z.preventDefault(),te(z);},target:"_blank",rel:"noopener noreferrer","aria-label":`Link to ${E}: ${A.label}`,children:[s&&jsx($e,{url:p,faviconUrl:_,isBroken:Q}),jsx("span",{className:j("font-mono text-[11px] font-medium whitespace-nowrap overflow-hidden text-ellipsis max-w-[140px]","text-gray-800 dark:text-gray-200",Q&&"line-through"),children:X}),ve()]})]}):o==="chip"?jsxs(Fragment,{children:[r,jsxs("span",{ref:x,"data-citation-id":w,"data-citation-instance":V,"data-url":p,"data-fetch-status":m,"data-variant":"chip",className:j("inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-sm cursor-pointer transition-colors no-underline mr-0.5","bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300","hover:bg-gray-200 dark:hover:bg-gray-700",Q&&"opacity-60",a),title:n?p:void 0,onMouseEnter:f$1?void 0:ne,onMouseLeave:f$1?void 0:be,onMouseDown:te,onClick:z=>z.stopPropagation(),role:"link","aria-label":`Link to ${E}: ${A.label}`,children:[s&&jsx($e,{url:p,faviconUrl:_}),jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap text-gray-700 dark:text-gray-300",children:X}),ve()]})]}):o==="inline"?jsxs(Fragment,{children:[r,jsxs("a",{ref:x,href:p,"data-citation-id":w,"data-citation-instance":V,"data-fetch-status":m,"data-variant":"inline",className:j("inline-flex items-center gap-1 cursor-pointer transition-colors no-underline border-b border-dotted mr-0.5","text-gray-700 dark:text-gray-300 border-gray-400 dark:border-gray-500","hover:border-gray-600 dark:hover:border-gray-300",Q&&"opacity-60 line-through",a),title:n?p:void 0,onMouseEnter:f$1?void 0:ne,onMouseLeave:f$1?void 0:be,onClick:z=>{z.preventDefault(),te(z);},target:"_blank",rel:"noopener noreferrer","aria-label":`Link to ${E}: ${A.label}`,children:[s&&jsx($e,{url:p,faviconUrl:_}),jsx("span",{children:X}),ve()]})]}):jsxs(Fragment,{children:[r,jsxs("span",{ref:x,"data-citation-id":w,"data-citation-instance":V,"data-url":p,"data-fetch-status":m,"data-variant":"bracket",className:j("inline-flex items-baseline gap-0.5 whitespace-nowrap cursor-pointer transition-colors mr-0.5","font-mono text-xs leading-tight","text-gray-500 dark:text-gray-400",Q&&"opacity-60",a),title:n?p:void 0,onMouseEnter:f$1?void 0:ne,onMouseLeave:f$1?void 0:be,onMouseDown:te,onClick:z=>z.stopPropagation(),role:"link","aria-label":`Link to ${E}: ${A.label}`,children:["[",s&&jsx($e,{url:p,faviconUrl:_}),jsx("span",{className:j("max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",Q&&"line-through"),children:X}),ve(),"]"]})]})});et.displayName="UrlCitationComponent";var Br=memo(et);function $r(e,t="unknown",r){return useMemo(()=>({url:e,domain:q(e),fetchStatus:t,...r}),[e,t,r])}var zr={extractDomain:q,truncateString:qe,getUrlPath:Tt,isBlockedStatus:Ze,isErrorStatus:Je,isVerifiedStatus:Mt};function Hr(...e){return e.filter(Boolean).join(" ")}var Dt=ae.Root,At=ae.Trigger;var tt=ft.forwardRef(({className:e,align:t="center",sideOffset:r=8,...a},o)=>jsx(ae.Portal,{children:jsx(ae.Content,{ref:o,align:t,sideOffset:r,className:Hr("z-[9998] rounded-lg border bg-white shadow-xl outline-none","w-fit max-w-[min(400px,calc(100vw-2rem))] max-h-[calc(100vh-4rem)]","overflow-auto","border-gray-200 dark:border-gray-700 dark:bg-gray-900","data-[state=open]:animate-in data-[state=closed]:animate-out","data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0","data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95","data-[side=bottom]:slide-in-from-top-2","data-[side=left]:slide-in-from-right-2","data-[side=right]:slide-in-from-left-2","data-[side=top]:slide-in-from-bottom-2",e),...a})}));tt.displayName=ae.Content.displayName;function zt(e,t,r=(a,o)=>a===o){let a=e.length,o=t.length;if(a===0&&o===0)return [];if(a===0)return [{value:t.join(""),added:true,count:t.length}];if(o===0)return [{value:e.join(""),removed:true,count:e.length}];let n=0;for(;n<a&&n<o&&r(e[n],t[n]);)n++;let s=0;for(;s<a-n&&s<o-n&&r(e[a-1-s],t[o-1-s]);)s++;let i=e.slice(n,a-s),c=t.slice(n,o-s);if(i.length===0&&c.length===0)return [{value:e.join(""),count:e.length}];let l=jr(i,c,r),d=[];return n>0&&d.push({value:e.slice(0,n).join(""),count:n}),d.push(...l),s>0&&d.push({value:e.slice(a-s).join(""),count:s}),Ht(d)}function jr(e,t,r){let a=e.length,o=t.length,n=a+o,s={1:0},i=[];e:for(let c=0;c<=n;c++){i.push({...s});for(let l=-c;l<=c;l+=2){let d;l===-c||l!==c&&s[l-1]<s[l+1]?d=s[l+1]:d=s[l-1]+1;let u=d-l;for(;d<a&&u<o&&r(e[d],t[u]);)d++,u++;if(s[l]=d,d>=a&&u>=o)break e}}return Or(i,e,t)}function Or(e,t,r){let a=[],o=t.length,n=r.length;for(let s=e.length-1;s>=0;s--){let i=e[s],c=o-n,l;c===-s||c!==s&&i[c-1]<i[c+1]?l=c+1:l=c-1;let d=i[l]??0,u=d-l;for(;o>d&&n>u;)o--,n--,a.push({value:t[o],count:1});s>0&&(o===d?(n--,a.push({value:r[n],added:true,count:1})):(o--,a.push({value:t[o],removed:true,count:1})));}return a.reverse()}function Ht(e){if(e.length===0)return [];let t=[];for(let r of e){let a=t[t.length-1];a&&a.added===r.added&&a.removed===r.removed?(a.value+=r.value,a.count=(a.count||1)+(r.count||1)):t.push({...r});}return t}function Rt(e){if(!e)return [];let t=[],r=0;for(let a=0;a<e.length;a++)e[a]===`
2
+ `&&(t.push(e.substring(r,a+1)),r=a+1);return r<e.length&&t.push(e.substring(r)),t}var Vt="a-zA-Z0-9_\\u00AD\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C6\\u02C8-\\u02D7\\u02DE-\\u02FF\\u1E00-\\u1EFF",Wr=new RegExp(`[${Vt}]+|\\s+|[^${Vt}]`,"gu");function Bt(e){return e?e.match(Wr)||[]:[]}function $t(e,t){let r=0;for(;r<e.length&&r<t.length&&e[r]===t[r];)r++;return e.slice(0,r)}function rt(e,t){let r=0;for(;r<e.length&&r<t.length&&e[e.length-1-r]===t[t.length-1-r];)r++;return e.slice(e.length-r)}function Fr(e){let t=[];for(let r=0;r<e.length;r++){let a=e[r];if(a.removed&&e[r+1]?.added){let o=a,n=e[r+1],i=$t(o.value,n.value).match(/^\s*/)?.[0]||"",c=o.value.slice(i.length),l=n.value.slice(i.length),u=rt(c,l).match(/\s*$/)?.[0]||"";i&&t.push({value:i,count:1});let f=o.value.slice(i.length,o.value.length-u.length),x=n.value.slice(i.length,n.value.length-u.length);f&&t.push({value:f,removed:true,count:1}),x&&t.push({value:x,added:true,count:1}),u&&t.push({value:u,count:1}),r++;continue}if(a.added&&r>0&&!e[r-1].added&&!e[r-1].removed){let o=t[t.length-1];if(o&&!o.added&&!o.removed){let n=a.value.match(/^\s*/)?.[0]||"",s=o.value.match(/\s*$/)?.[0]||"";if(n&&s){let i=rt(s,n);if(i){t.push({value:a.value.slice(i.length),added:true,count:1});continue}}}}if(a.removed&&!e[r+1]?.added&&r>0&&!e[r-1]?.added&&!e[r-1]?.removed){let o=t[t.length-1],n=e[r+1];if(o&&n&&!n.added&&!n.removed){let s=a.value.match(/^\s*/)?.[0]||"",i=a.value.match(/\s*$/)?.[0]||"",c=o.value.match(/\s*$/)?.[0]||"",l=n.value.match(/^\s*/)?.[0]||"";if(s&&c&&rt(c,s).length===s.length){t.push({value:a.value.slice(s.length),removed:true,count:1});continue}if(i&&l&&$t(i,l).length===i.length){t.push({value:a.value.slice(0,-i.length)||a.value,removed:true,count:1});continue}}}t.push({...a});}return Ht(t)}function jt(e,t){let r=Rt(e),a=Rt(t);return zt(r,a)}function Ot(e,t){let r=Bt(e),a=Bt(t),o=zt(r,a);return Fr(o)}var at=(e="",t="")=>useMemo(()=>{let r=(e||"").trim().replace(/\r\n/g,`
3
+ `),a=(t||"").trim().replace(/\r\n/g,`
4
+ `),o=jt(r,a),n=[],s=false,i=0;for(let d=0;d<o.length;d++){let u=o[d],f=o[d+1];if(u.removed&&f&&f.added){let x=Ot(u.value,f.value);n.push({type:"modified",parts:x}),s=true,i+=Math.abs(u.value.length-f.value.length),d++;}else u.added||u.removed?(n.push({type:u.added?"added":"removed",parts:[{value:u.value,added:u.added,removed:u.removed}]}),s=true,i+=u.value.length):n.push({type:"unchanged",parts:[{value:u.value}]});}let c=Math.max(r.length,a.length),l=c===0?1:1-i/c;return {diffResult:n,hasDiff:s,similarity:l,isHighVariance:l<.6}},[e,t]);var nt=createContext(null);function Qr({children:e}){let[t,r]=useState(0),a=useCallback(()=>{r(s=>s+1);},[]),o=useCallback(()=>{r(s=>Math.max(0,s-1));},[]),n=useMemo(()=>({isAnyOverlayOpen:t>0,registerOverlay:a,unregisterOverlay:o}),[t,a,o]);return jsx(nt.Provider,{value:n,children:e})}function He(){let e=useContext(nt);return e||{isAnyOverlayOpen:false,registerOverlay:()=>{},unregisterOverlay:()=>{}}}function Yr(){return useContext(nt)!==null}function ot(e,t,r){if(!e)return "";switch(e){case "found":return "Exact match found";case "found_anchor_text_only":return "Key phrase found, full context differs";case "found_phrase_missed_anchor_text":return "Full phrase found, anchor text highlight missed";case "partial_text_found":return "Partial text match found";case "found_on_other_page":return t!=null&&r!=null?`Found on page ${r} (expected page ${t})`:"Found on different page";case "found_on_other_line":return "Found on different line";case "first_word_found":return "Only first word matched";case "not_found":return "Not found in source";case "pending":case "loading":return "Searching...";default:return ""}}function Jr(e,t){if(!e&&!t)return 1;if(!e||!t)return 0;let r=Math.max(e.length,t.length);if(r===0)return 1;let a=[];for(let n=0;n<=e.length;n++)a[n]=[n];for(let n=0;n<=t.length;n++)a[0][n]=n;for(let n=1;n<=e.length;n++)for(let s=1;s<=t.length;s++)e[n-1]===t[s-1]?a[n][s]=a[n-1][s-1]:a[n][s]=Math.min(a[n-1][s-1]+1,a[n][s-1]+1,a[n-1][s]+1);return 1-a[e.length][t.length]/r}function ea(e,t,r){if(!t||!e.includes(t))return e;let a=e.indexOf(t),o=e.slice(0,a),n=e.slice(a,a+t.length),s=e.slice(a+t.length);return jsxs(Fragment,{children:[o,jsx("span",{className:r,children:n}),s]})}var Le=memo(({similarity:e,className:t})=>{let r=Math.round(e*100),a=r>=80?"bg-green-500 dark:bg-green-400":r>=40?"bg-amber-500 dark:bg-amber-400":"bg-red-500 dark:bg-red-400";return jsxs("div",{className:b("flex items-center gap-2",t),children:[jsx("div",{className:"flex-1 h-1.5 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden",children:jsx("div",{className:b("h-full rounded-full transition-all duration-300",a),style:{width:`${r}%`}})}),jsxs("span",{className:"text-[10px] font-medium text-gray-500 dark:text-gray-400 tabular-nums",children:[r,"%"]})]})});Le.displayName="MatchQualityBar";var xe=memo(({text:e,maxLength:t,className:r,anchorText:a,anchorTextClass:o="border-b-2 border-blue-400 dark:border-blue-500"})=>{let[n,s]=useState(false),i=e.length>t,c=i&&!n?e.slice(0,t)+"\u2026":e,l=a?ea(c,a,o):c;return jsxs("div",{className:r,children:[jsx("span",{className:"whitespace-pre-wrap break-words",children:l}),i&&jsx("button",{type:"button",onClick:d=>{d.stopPropagation(),s(!n);},className:"ml-1 text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300 text-[10px] font-medium",children:n?"Show less":"Show full text"})]})});xe.displayName="CollapsibleText";var Ut=memo(({expected:e,actual:t,maxCollapsedLength:r,anchorTextExpected:a,anchorTextFound:o,showMatchQuality:n,similarity:s})=>jsxs("div",{className:"space-y-2",children:[n&&jsx(Le,{similarity:s,className:"mb-3"}),jsx("div",{className:"rounded-md overflow-hidden",children:jsxs("div",{className:"flex items-start gap-2 p-2.5 bg-red-50 dark:bg-red-900/20",children:[jsx("span",{className:"shrink-0 text-[10px] font-medium text-red-600 dark:text-red-400 uppercase tracking-wide pt-0.5",children:"Expected:"}),jsx(xe,{text:e,maxLength:r,className:"flex-1 font-mono text-[11px] text-red-700 dark:text-red-300",anchorText:a,anchorTextClass:"bg-red-200 dark:bg-red-800/50 px-0.5 rounded"})]})}),jsx("div",{className:"rounded-md overflow-hidden",children:jsxs("div",{className:"flex items-start gap-2 p-2.5 bg-green-50 dark:bg-green-900/20",children:[jsxs("span",{className:"shrink-0 text-[10px] font-medium text-green-600 dark:text-green-400 uppercase tracking-wide pt-0.5 inline-flex items-center gap-1",children:["Found:",jsx("span",{className:"size-2.5 text-green-500 dark:text-green-400",children:jsx(B,{})})]}),t?jsx(xe,{text:t,maxLength:r,className:"flex-1 font-mono text-[11px] text-green-700 dark:text-green-300",anchorText:o,anchorTextClass:"bg-green-200 dark:bg-green-800/50 px-0.5 rounded"}):jsx("span",{className:"flex-1 font-mono text-[11px] text-gray-500 dark:text-gray-400 italic",children:"No text found"})]})})]}));Ut.displayName="SplitView";var We=memo(({expected:e,actual:t,label:r,className:a,sanitize:o,mode:n="auto",showMatchQuality:s=false,maxCollapsedLength:i=200,anchorTextExpected:c,anchorTextFound:l,status:d,similarity:u})=>{let f=useMemo(()=>{let m=(e||"").trim().replace(/\r\n/g,`
5
+ `);return o?o(m):m},[e,o]),x=useMemo(()=>{let m=(t||"").trim().replace(/\r\n/g,`
6
+ `);return o?o(m):m},[t,o]),p=useMemo(()=>u!==void 0?u:Jr(f,x),[f,x,u]),P=useMemo(()=>n!=="auto"?n:p>=.8?"inline":("split"),[n,p,d]);return f===x&&f.length>0?jsxs("div",{"data-testid":"split-diff-display","data-exact-match":"true",className:b("space-y-2",a),children:[r&&jsx("div",{className:"text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wide",children:r}),jsxs("div",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 rounded-full text-sm font-medium",children:[jsx("span",{className:"size-2.5",children:jsx(B,{})}),jsx("span",{children:"Exact match"})]}),jsx("div",{className:"p-3 bg-gray-50 dark:bg-gray-800 rounded-md text-sm text-gray-700 dark:text-gray-300 font-mono whitespace-pre-wrap break-words",children:x})]}):jsxs("div",{"data-testid":"split-diff-display","data-mode":P,className:b("space-y-2",a),children:[r&&jsx("div",{className:"text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wide",children:r}),jsx(Ut,{expected:f,actual:x,maxCollapsedLength:i,anchorTextExpected:c,anchorTextFound:l,showMatchQuality:s,similarity:p})]})});We.displayName="SplitDiffDisplay";var aa=150,qt=50,Gt="200px",Kt=60,Xt={green:"text-green-600 dark:text-green-400",amber:"text-amber-600 dark:text-amber-400",red:"text-red-500 dark:text-red-400",gray:"text-gray-400 dark:text-gray-500"},Zt={exact_line_match:"Exact location",line_with_buffer:"Nearby lines",current_page:"Expected page",anchor_text_fallback:"Key phrase",adjacent_pages:"Nearby pages",expanded_window:"Wider area",regex_search:"Entire document",first_word_fallback:"First word"};function na(e){if(!e)return "gray";switch(e){case "found":case "found_anchor_text_only":case "found_phrase_missed_anchor_text":return "green";case "found_on_other_page":case "found_on_other_line":case "partial_text_found":case "first_word_found":return "amber";case "not_found":return "red";default:return "gray"}}function oa(e){if(!e)return "Verifying...";switch(e){case "found":case "found_anchor_text_only":case "found_phrase_missed_anchor_text":return "Verified";case "found_on_other_page":return "Found on different page";case "found_on_other_line":return "Found on different line";case "partial_text_found":case "first_word_found":return "Partial match";case "not_found":return "Not found";case "pending":case "loading":return "Verifying...";default:return "Unknown"}}function sa(e){return Zt[e]||e}function Qt({expectedPage:e,foundPage:t}){let r=e!=null&&e>0,a=t!=null&&t>0;if(r&&a&&e!==t)return jsxs("span",{className:"text-xs font-mono text-gray-500 dark:text-gray-400 flex items-center gap-1",children:[jsxs("span",{className:"text-gray-400 dark:text-gray-500",children:["Pg ",e]}),jsx("span",{className:"text-gray-400 dark:text-gray-500",children:"\u2192"}),jsx("span",{className:"text-gray-700 dark:text-gray-300",children:t})]});let n=a?t:e;return n!=null&&n>0?jsxs("span",{className:"text-xs font-mono text-gray-500 dark:text-gray-400",children:["Pg ",n]}):null}function Me({status:e,foundPage:t,expectedPage:r,compact:a=false,anchorText:o,fullPhrase:n}){let s=na(e),i=oa(e),c=s==="green"?B:s==="amber"?B:s==="red"?Pe:ue;if(o||n){let d=o||n?.slice(0,qt)||"",u=n||o||"";return jsxs("div",{className:"border-b border-gray-200 dark:border-gray-700",children:[jsxs("div",{className:b("flex items-center justify-between gap-2 text-sm",a?"px-3 py-2":"px-4 py-2.5"),children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{className:b("size-4 max-w-4 max-h-4 flex-shrink-0",Xt[s]),children:jsx(c,{})}),jsx("span",{className:"font-medium text-gray-800 dark:text-gray-100",children:i})]}),jsx(Qt,{expectedPage:r,foundPage:t})]}),jsxs("div",{className:"px-4 pb-3 pt-1",children:[jsxs("div",{className:"text-[15px] font-semibold text-gray-800 dark:text-gray-100 mb-2",children:['"',d,'"']}),u&&u!==d&&jsx(st,{phrase:u})]})]})}return jsxs("div",{className:b("flex items-center justify-between gap-2 border-b border-gray-200 dark:border-gray-700 text-sm",a?"px-3 py-2":"px-4 py-2.5"),children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{className:b("size-4 max-w-4 max-h-4 flex-shrink-0",Xt[s]),children:jsx(c,{})}),jsx("span",{className:"font-medium text-gray-800 dark:text-gray-100",children:i})]}),jsx(Qt,{expectedPage:r,foundPage:t})]})}function st({phrase:e,maxLength:t=aa}){let r=e.length>t?e.slice(0,t)+"...":e;return jsxs("blockquote",{className:"text-gray-600 dark:text-gray-300 bg-gray-50 dark:bg-gray-800/50 p-3 border-l-[3px] border-gray-300 dark:border-gray-600 leading-relaxed text-sm",children:['"',r,'"']})}function ia({searchAttempts:e,isExpanded:t,onToggle:r}){let a=e.length,o=e.filter(n=>n.success).length;return jsx("button",{type:"button",onClick:r,"aria-expanded":t,"aria-controls":"verification-log-timeline",className:"w-full px-4 py-2.5 flex items-center justify-between text-xs hover:bg-gray-50 dark:hover:bg-gray-800/30 transition-colors",children:jsxs("div",{className:"flex items-center gap-1.5 text-gray-600 dark:text-gray-400",children:[jsx("svg",{className:b("size-3 transition-transform duration-200",t&&"rotate-90"),viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5","aria-hidden":"true",children:jsx("path",{d:"M9 6l6 6-6 6"})}),jsx("span",{children:"Details"}),jsxs("span",{className:"text-gray-400 dark:text-gray-500",children:["(",o," / ",a," ",a===1?"search":"searches",")"]})]})})}function ca({attempt:e,index:t,totalCount:r}){let a=e.searchPhrase??"",o=a.length===0?"(empty)":a.length>Kt?a.slice(0,Kt)+"...":a,n=e.searchScope==="document"?"Entire doc":e.pageSearched!=null?`Pg ${e.pageSearched}`:"",s=Zt[e.method]||e.method,i=String(r).length,c=e.searchVariations??[];return jsxs("div",{className:"flex items-start gap-2 py-0.5",children:[jsxs("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 font-mono flex-shrink-0 tabular-nums",style:{minWidth:`${i+1}ch`},children:[t,"."]}),jsx("span",{className:b("size-3 max-w-3 max-h-3 mt-0.5 flex-shrink-0",e.success?"text-green-600 dark:text-green-400":"text-gray-400 dark:text-gray-500"),role:"img","aria-label":e.success?"Found":"Not found",children:e.success?jsx(B,{}):jsx(Pe,{})}),jsxs("div",{className:"flex-1 min-w-0",children:[jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[jsxs("span",{className:"text-xs text-gray-700 dark:text-gray-200 font-mono break-all",children:['"',o,'"']}),jsxs("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0 whitespace-nowrap",children:[s,n&&` \xB7 ${n}`]})]}),c.length>0&&jsxs("div",{className:"text-[10px] text-gray-400 dark:text-gray-500 mt-0.5",children:["Also tried: ",c.slice(0,3).map(l=>`"${l}"`).join(", "),c.length>3&&` +${c.length-3} more`]})]})]})}function la({rejectedMatches:e}){return e.length===0?null:jsxs("div",{children:[jsx("div",{className:"text-[11px] text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1.5",children:"Found but rejected"}),jsx("div",{className:"space-y-1",children:e.map(t=>jsxs("div",{className:"text-xs text-gray-600 dark:text-gray-300 font-mono",children:['"',t.text,'"',t.count!=null&&` (${t.count} occurrences)`]},t.text))}),jsx("p",{className:"text-[11px] text-gray-500 dark:text-gray-400 mt-1.5 italic",children:"Context did not match citation"})]})}function da({searchAttempts:e,fullPhrase:t,anchorText:r}){let a=useMemo(()=>{let o=new Set,n=[];for(let s of e)!s.success&&s.matchedText&&!o.has(s.matchedText)&&(o.add(s.matchedText),n.push({text:s.matchedText}));return n},[e]);if(e.length===0){let o=[t,r].filter(n=>!!n);return o.length===0?null:jsx("div",{className:"px-4 py-3 space-y-3 text-sm",children:jsxs("div",{children:[jsx("div",{className:"text-[11px] text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1.5",children:"Searched for"}),jsx("div",{className:"space-y-1",children:o.map((n,s)=>jsxs("div",{className:"flex items-start gap-2",children:[jsx("span",{className:"size-3 max-w-3 max-h-3 mt-0.5 text-gray-400 dark:text-gray-500 flex-shrink-0",children:jsx(Pe,{})}),jsxs("span",{className:"text-xs text-gray-700 dark:text-gray-200 font-mono break-all",children:['"',n,'"']})]},s))})]})})}return jsxs("div",{className:"px-4 py-3 space-y-4 text-sm",children:[jsxs("div",{children:[jsx("div",{className:"text-[11px] text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-2",children:"Search attempts"}),jsx("div",{className:"space-y-0.5",children:e.map((o,n)=>jsx(ca,{attempt:o,index:n+1,totalCount:e.length},n))})]}),jsx(la,{rejectedMatches:a})]})}function ua({attempt:e,expectedPage:t}){let r=e.success,a=sa(e.method),o=e.foundLocation?.page,n=r&&o&&t&&o!==t,s=r?B:Pe;return jsxs("div",{className:"flex items-center gap-2 py-1.5 px-2 -mx-2 rounded hover:bg-gray-50 dark:hover:bg-gray-800/50 transition-colors",children:[jsx("span",{className:b("size-3.5 max-w-3.5 max-h-3.5 flex-shrink-0",r?"text-green-600 dark:text-green-400":"text-gray-400 dark:text-gray-500"),children:jsx(s,{})}),jsx("span",{className:"flex-1 text-xs text-gray-700 dark:text-gray-300",children:a}),n&&jsxs("span",{className:"text-[11px] text-gray-500 dark:text-gray-400 flex-shrink-0",children:["\u2192 Pg ",o]})]})}function pa({searchAttempts:e,expectedPage:t,showAuditDisplay:r,fullPhrase:a,anchorText:o}){return r?jsx("div",{id:"verification-log-timeline",style:{maxHeight:Gt},className:"overflow-y-auto",children:jsx(da,{searchAttempts:e,fullPhrase:a,anchorText:o})}):jsx("div",{id:"verification-log-timeline",className:"px-4 pb-3 overflow-y-auto",style:{maxHeight:Gt},children:e.map((n,s)=>{let i=Array.isArray(n.lineSearched)?n.lineSearched.join("-"):n.lineSearched??"none",c=`${n.method}-${n.pageSearched??"doc"}-${i}-${s}`;return jsx(ua,{attempt:n,expectedPage:t},c)})})}function Fe({searchAttempts:e,status:t,expectedPage:r,expectedLine:a,foundPage:o,foundLine:n,isExpanded:s,onExpandChange:i,fullPhrase:c,anchorText:l}){let[d,u]=useState(false),f=s??d,x=m=>{i?i(m):u(m);},p=useMemo(()=>e.find(m=>m.success),[e]);if(!e||e.length===0)return null;let P=o??p?.foundLocation?.page??p?.pageSearched,I=n??p?.foundLocation?.line;return jsxs("div",{className:"border-t border-gray-200 dark:border-gray-700",children:[jsx(ia,{status:t,searchAttempts:e,expectedPage:r,expectedLine:a,foundPage:P,foundLine:I,isExpanded:f,onToggle:()=>x(!f)}),f&&jsx(pa,{searchAttempts:e,expectedPage:r,showAuditDisplay:t==="not_found",fullPhrase:c,anchorText:l})]})}function ma({anchorText:e,fullPhrase:t}){let r=e||t?.slice(0,qt)||"Citation",a=t||e||"";return jsxs("div",{className:"px-4 py-3 space-y-2",children:[jsx("div",{className:"text-[10px] text-gray-500 dark:text-gray-400 uppercase font-medium tracking-wide",children:"Searching for:"}),jsxs("div",{className:"text-[15px] font-semibold text-gray-800 dark:text-gray-100",children:['"',r,'"']}),a&&a!==r&&jsx(st,{phrase:a})]})}var Jt=ft__default.Activity??(({children:e})=>jsx(Fragment,{children:e}));var er="380px",tr="90vw";var Ie=class extends ft__default.Component{constructor(t){super(t),this.state={hasError:false};}static getDerivedStateFromError(t){return {hasError:true,error:t}}componentDidCatch(t,r){console.error("[DeepCitation] Citation component error:",t,r);}render(){return this.state.hasError?this.props.fallback?this.props.fallback:jsx("span",{className:"inline-flex items-center text-red-500 dark:text-red-400",title:`Citation error: ${this.state.error?.message||"Unknown error"}`,children:jsx(Ne,{className:"size-3"})}):this.props.children}};function ha(e){switch(e){case "chip":case "text":case "brackets":case "linter":return "anchorText";case "source":return "source";default:return "number"}}function ya(e){return e.replace(/^\[+\s*/,"").replace(/\s*\]+$/,"")}function ba(e,t,r){if(t==="indicator")return "";if(t==="anchorText"){let a=e.anchorText?.toString()||e.citationNumber?.toString()||r||"1";return ya(a)}return t==="source"?e.siteName||e.domain||e.anchorText?.toString()||"Source":e.citationNumber?.toString()||"1"}function va(e){return e.isVerified&&!e.isPartialMatch?"Verified":e.isPartialMatch?"Partial Match":e.isMiss?"Not Found":e.isPending?"Verifying...":""}function ka(e){if(!e)return "medium";switch(e){case "exact_full_phrase":case "normalized_full_phrase":return "high";case "exact_anchor_text":case "normalized_anchor_text":return "medium";case "partial_full_phrase":case "partial_anchor_text":case "first_word_only":return "low";default:return "medium"}}function Na(e){return ka(e)==="low"}function wa(e){let t=e?.status;if(!e||!t)return {isVerified:false,isMiss:false,isPartialMatch:false,isPending:false};let r=t==="not_found",a=t==="pending"||t==="loading",o=e.searchAttempts?.some(i=>i.success&&Na(i.matchedVariation))??false,n=t==="found_anchor_text_only"||t==="found_on_other_page"||t==="found_on_other_line"||t==="partial_text_found"||t==="first_word_found"||o;return {isVerified:t==="found"||t==="found_phrase_missed_anchor_text"||n,isMiss:r,isPartialMatch:n,isPending:a}}function Ca({src:e,alt:t,onClose:r}){let{registerOverlay:a,unregisterOverlay:o}=He();return useEffect(()=>(a(),()=>o()),[a,o]),useEffect(()=>{let n=s=>{s.key==="Escape"&&r();};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)},[r]),createPortal(jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-sm animate-in fade-in-0 duration-[50ms]",onClick:r,role:"dialog","aria-modal":"true","aria-label":"Full size verification image",children:jsx("div",{className:"relative max-w-[95vw] max-h-[95vh] cursor-zoom-out animate-in zoom-in-95 duration-[50ms]",children:jsx("img",{src:e,alt:t,className:"max-w-full max-h-[95vh] object-contain rounded-lg shadow-2xl",draggable:false})})}),document.body)}var Sa=()=>jsx("span",{className:"inline-flex relative ml-0.5 top-[0.15em] size-2.5 text-green-600 dark:text-green-500","aria-hidden":"true",children:jsx(B,{})}),Pa=()=>jsx("span",{className:"inline-flex relative ml-0.5 top-[0.15em] size-2.5 text-amber-600 dark:text-amber-500","aria-hidden":"true",children:jsx(B,{})}),_a=()=>jsx("span",{className:"inline-flex relative ml-1 top-[0.15em] size-2.5 animate-spin text-gray-400 dark:text-gray-500","aria-hidden":"true",children:jsx(ue,{})}),Ta=()=>jsx("span",{className:"inline-flex relative ml-0.5 top-[0.15em] size-2.5 text-amber-500 dark:text-amber-400","aria-hidden":"true",children:jsx(Ne,{})});function La(e){if(!e)return null;let t=e.anchorTextMatchDeepItems;if(t&&t.length>0){let a=1/0,o=1/0,n=-1/0,s=-1/0;for(let i of t)a=Math.min(a,i.x),o=Math.min(o,i.y),n=Math.max(n,i.x+i.width),s=Math.max(s,i.y+i.height);return {x:a,y:o,width:n-a,height:s-o}}let r=e.phraseMatchDeepItem;return r?{x:r.x,y:r.y,width:r.width,height:r.height}:null}function rr({verification:e,onImageClick:t,maxWidth:r="min(70vw, 384px)",maxHeight:a="min(50vh, 300px)"}){let o=useRef(null),n=useRef(null),s=useRef(false),i=useMemo(()=>La(e),[e]),c=useCallback(()=>{if(s.current||!o.current||!n.current||!i)return;let l=o.current,d=n.current,u=e.verificationImageDimensions,f=u?.width||d.naturalWidth,x=u?.height||d.naturalHeight;if(f===0||x===0)return;let p=d.clientWidth/f,P=d.clientHeight/x,I=(i.x+i.width/2)*p,m=(i.y+i.height/2)*P,_=Math.max(0,I-l.clientWidth/2),k=Math.max(0,m-l.clientHeight*.4);l.scrollLeft=_,l.scrollTop=k,s.current=true;},[i,e.verificationImageDimensions]);return useEffect(()=>{s.current=false;},[e.verificationImageBase64]),jsxs("button",{type:"button",className:"group block cursor-zoom-in relative rounded-md bg-gray-50 dark:bg-gray-800",onClick:l=>{l.preventDefault(),l.stopPropagation(),t?.();},"aria-label":"Click to view full size",children:[jsx("div",{ref:o,className:"overflow-auto rounded-md",style:{maxWidth:r,maxHeight:a},children:jsx("img",{ref:n,src:e.verificationImageBase64,alt:"Citation verification",className:"block",style:{maxWidth:"none",maxHeight:"none",width:"auto",height:"auto"},loading:"eager",decoding:"async",onLoad:c})}),jsx("span",{className:"absolute left-0 right-0 bottom-0 flex items-center justify-end px-2 pb-1.5 pt-4 bg-gradient-to-t from-black/50 to-transparent rounded-b-md pointer-events-none",children:jsx("span",{className:"text-xs text-white font-medium drop-shadow-[0_1px_2px_rgba(0,0,0,0.8)] opacity-0 group-hover:opacity-100 transition-opacity",children:"Click to expand"})})]})}function Ma(e,t,r,a){if(!e)return null;let o=30,n=typeof t=="string"?t:null,s=n?n.length>o?`"${n.slice(0,o)}\u2026"`:`"${n}"`:"this phrase";switch(e){case "not_found":return `We couldn't find ${s} in this document.`;case "found_on_other_page":return r&&a?`Found ${s} on page ${a} instead of page ${r}.`:`Found ${s} on a different page than expected.`;case "found_on_other_line":return `Found ${s} at a different position than expected.`;case "partial_text_found":return `Only part of ${s} was found.`;case "first_word_found":return `Only the beginning of ${s} was found.`;case "found_anchor_text_only":return `Found ${s}, but not the full surrounding context.`;default:return null}}function ar({citation:e,verification:t,status:r,onImageClick:a,isLoading:o=false,isPhrasesExpanded:n,onPhrasesExpandChange:s,isVisible:i=true}){let c=t?.verificationImageBase64,{isMiss:l,isPartialMatch:d,isPending:u,isVerified:f}=r,x=t?.status,p=!!(t&&(t.anchorTextMatchDeepItems?.length||t.phraseMatchDeepItem)),P=l||d,I=f&&!d&&!l,m=e.pageNumber,_=e.lineIds?.[0],k=t?.verifiedPageNumber??void 0,M=t?.verifiedLineIds?.[0],w=e.anchorText?.toString(),V=e.fullPhrase,E=useMemo(()=>Ma(x,w,m??void 0,k),[x,w,m,k]);if(o||u){let $=V||w;return jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[200px] max-w-[400px]",children:[jsxs("span",{className:"text-xs font-medium text-gray-600 dark:text-gray-300",children:[jsx("span",{className:"inline-block relative top-[0.1em] mr-1.5 size-2 animate-spin",children:jsx(ue,{})}),"Searching..."]}),$&&jsxs("p",{className:"p-2 bg-gray-50 dark:bg-gray-800/50 rounded font-mono text-[11px] break-words text-gray-700 dark:text-gray-300",children:['"',$.length>80?$.slice(0,80)+"\u2026":$,'"']}),e.pageNumber&&e.pageNumber>0&&jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Looking on page ",e.pageNumber]})]})}if(I&&c&&t)return jsx(Jt,{mode:i?"visible":"hidden",children:jsxs("div",{className:"overflow-hidden rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900 shadow-md",style:{width:er,maxWidth:tr},children:[jsx(Me,{status:x,foundPage:k,expectedPage:m??void 0}),jsx("div",{className:"p-2",children:p?jsx(rr,{verification:t,onImageClick:a}):jsxs("button",{type:"button",className:"group block cursor-zoom-in relative overflow-hidden rounded-md bg-gray-50 dark:bg-gray-800 w-full",onClick:$=>{$.preventDefault(),$.stopPropagation(),a?.();},"aria-label":"Click to view full size",children:[jsx("img",{src:t.verificationImageBase64,alt:"Citation verification",className:"block rounded-md w-full",style:{maxHeight:"min(50vh, 300px)",objectFit:"contain"},loading:"eager",decoding:"async"}),jsx("span",{className:"absolute left-0 right-0 bottom-0 flex items-center justify-end px-2 pb-1.5 pt-4 bg-gradient-to-t from-black/50 to-transparent rounded-b-md",children:jsx("span",{className:"text-xs text-white font-medium drop-shadow-[0_1px_2px_rgba(0,0,0,0.8)] opacity-0 group-hover:opacity-100 transition-opacity",children:"Click to expand"})})]})}),t.searchAttempts&&t.searchAttempts.length>0&&jsx(Fe,{searchAttempts:t.searchAttempts,status:x,expectedPage:m??void 0,expectedLine:_,foundPage:k,foundLine:M,isExpanded:n,onExpandChange:s,fullPhrase:V??void 0,anchorText:w})]})});if(l||d)return jsx(Jt,{mode:i?"visible":"hidden",children:jsxs("div",{className:"overflow-hidden rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900 shadow-md",style:{width:er,maxWidth:tr},children:[c&&t?jsxs(Fragment,{children:[jsx(Me,{status:x,foundPage:k,expectedPage:m??void 0}),E&&jsx("div",{className:"px-4 py-2 text-sm text-gray-600 dark:text-gray-300 border-b border-gray-100 dark:border-gray-800",children:E}),jsx("div",{className:"p-2",children:p?jsx(rr,{verification:t,onImageClick:a}):jsxs("button",{type:"button",className:"group block cursor-zoom-in relative overflow-hidden rounded-md bg-gray-50 dark:bg-gray-800 w-full",onClick:$=>{$.preventDefault(),$.stopPropagation(),a?.();},"aria-label":"Click to view full size",children:[jsx("img",{src:t.verificationImageBase64,alt:"Citation verification",className:"block rounded-md w-full",style:{maxHeight:"min(50vh, 300px)",objectFit:"contain"},loading:"eager",decoding:"async"}),jsx("span",{className:"absolute left-0 right-0 bottom-0 flex items-center justify-end px-2 pb-1.5 pt-4 bg-gradient-to-t from-black/50 to-transparent rounded-b-md",children:jsx("span",{className:"text-xs text-white font-medium drop-shadow-[0_1px_2px_rgba(0,0,0,0.8)] opacity-0 group-hover:opacity-100 transition-opacity",children:"Click to expand"})})]})})]}):jsxs(Fragment,{children:[jsx(Me,{status:x,foundPage:k,expectedPage:m??void 0,anchorText:E?void 0:w,fullPhrase:E?void 0:V??void 0}),E&&jsx("div",{className:"px-4 py-3 text-sm text-gray-600 dark:text-gray-300",children:E})]}),P&&t?.searchAttempts&&jsx(Fe,{searchAttempts:t.searchAttempts,status:x,expectedPage:m??void 0,expectedLine:_,foundPage:k,foundLine:M,isExpanded:n,onExpandChange:s,fullPhrase:V??void 0,anchorText:w})]})});let D=va(r),X=t?.verifiedMatchSnippet,A=t?.verifiedPageNumber;return !X&&!D?null:jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[180px] max-w-full",children:[D&&jsx("span",{className:b("text-xs font-medium",r.isVerified&&!r.isPartialMatch&&"text-green-600 dark:text-green-400",r.isPartialMatch&&"text-amber-600 dark:text-amber-400",r.isMiss&&"text-red-500 dark:text-red-400",r.isPending&&"text-gray-500 dark:text-gray-400"),children:D}),X&&jsxs("span",{className:"text-sm text-gray-700 dark:text-gray-200",children:['"',t.verifiedMatchSnippet,'"']}),A&&A>0&&jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Page ",A]})]})}var it=forwardRef(({citation:e,children:t,className:r,fallbackDisplay:a,verification:o,isLoading:n=false,variant:s="brackets",content:i,eventHandlers:c,behaviorConfig:l,isMobile:d$1=false,renderIndicator:u,renderContent:f$1,popoverPosition:x="top",renderPopoverContent:p,additionalCount:P,faviconUrl:I,showIndicator:m=true},_)=>{let{isAnyOverlayOpen:k}=He(),M=useMemo(()=>i||ha(s),[i,s]),[w,V]=useState(false),[E,D]=useState(null),[X,A]=useState(false),$=useRef(false),h=useMemo(()=>d(e),[e]),K=useMemo(()=>f(h),[h]),G=useMemo(()=>wa(o),[o]),{isMiss:F,isPartialMatch:Q,isVerified:te,isPending:ne}=G,be=5e3,[ve,z]=useState(false),ke=useRef(null),Ke=o?.verificationImageBase64||o?.status==="found"||o?.status==="found_anchor_text_only"||o?.status==="found_phrase_missed_anchor_text"||o?.status==="not_found"||o?.status==="partial_text_found"||o?.status==="found_on_other_page"||o?.status==="found_on_other_line"||o?.status==="first_word_found",O=(n||ne)&&!Ke&&!ve;useEffect(()=>(ke.current&&(clearTimeout(ke.current),ke.current=null),(n||ne)&&!Ke?(z(false),ke.current=setTimeout(()=>{z(true);},be)):z(false),()=>{ke.current&&clearTimeout(ke.current);}),[n,ne,Ke]);let re=useMemo(()=>ba(e,M,a),[e,M,a]),ce=useCallback(()=>({citation:e,citationKey:h,verification:o??null,isTooltipExpanded:w,isImageExpanded:!!E,hasImage:!!o?.verificationImageBase64}),[e,h,o,w,E]),vt=useCallback(S=>{S.setImageExpanded!==void 0&&(typeof S.setImageExpanded=="string"?D(S.setImageExpanded):S.setImageExpanded===true&&o?.verificationImageBase64?D(o.verificationImageBase64):S.setImageExpanded===false&&D(null));},[o?.verificationImageBase64]),mr=useCallback(S=>{S.preventDefault(),S.stopPropagation();let de=ce();if(l?.onClick){let Y=l.onClick(de,S);Y&&typeof Y=="object"&&vt(Y),c?.onClick?.(e,h,S);return}if(c?.onClick){c.onClick(e,h,S);return}if(d$1&&!$.current){V(true);return}o?.verificationImageBase64?D(o.verificationImageBase64):F&&A(Y=>!Y);},[l,c,e,h,o?.verificationImageBase64,F,d$1,ce,vt]),kt=150,me=useRef(null),Xe=useRef(false),le=useCallback(()=>{me.current&&(clearTimeout(me.current),me.current=null);},[]),gr=useCallback(()=>{k||(le(),V(true),l?.onHover?.onEnter&&l.onHover.onEnter(ce()),c?.onMouseEnter?.(e,h));},[c,l,e,h,ce,le,k]),fr=useCallback(()=>{le(),me.current=setTimeout(()=>{Xe.current||(V(false),l?.onHover?.onLeave&&l.onHover.onLeave(ce()),c?.onMouseLeave?.(e,h));},kt);},[c,l,e,h,ce,le]),xr=useCallback(()=>{le(),Xe.current=true;},[le]),hr=useCallback(()=>{Xe.current=false,le(),me.current=setTimeout(()=>{V(false),l?.onHover?.onLeave&&l.onHover.onLeave(ce()),c?.onMouseLeave?.(e,h);},kt);},[c,l,e,h,ce,le]);useEffect(()=>()=>{me.current&&clearTimeout(me.current);},[]);let yr=useCallback(S=>{d$1&&($.current=w);},[d$1,w]),br=useCallback(S=>{d$1&&(S.preventDefault(),S.stopPropagation(),c?.onTouchEnd?.(e,h,S));},[c,e,h,d$1]);if(a!=null&&M==="anchorText"&&F)return jsx("span",{className:b("text-gray-400 dark:text-gray-500",r),children:a});let Nt=b((s==="text"||s==="minimal"||s==="superscript"||s==="linter")&&!F&&!O&&"text-gray-900 dark:text-gray-100",(te||Q)&&s==="brackets"&&"text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 hover:underline",F&&"opacity-70 line-through text-gray-700 dark:text-gray-200",O&&"text-gray-500 dark:text-gray-400"),ge=()=>u?u(G):m?O?jsx(_a,{}):te&&!Q?jsx(Sa,{}):Q?jsx(Pa,{}):F?jsx(Ta,{}):null:null,wt=()=>{if(f$1)return f$1({citation:e,status:G,citationKey:h,displayText:re,isMergedDisplay:M==="anchorText"});if(M==="indicator")return jsx("span",{children:ge()});if(s==="chip"){let S=b(te&&!Q&&!O&&"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",Q&&!O&&"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",F&&!O&&"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400 line-through",O&&"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400",!te&&!F&&!O&&"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400");return jsxs("span",{className:b("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-sm font-medium",S),children:[jsx("span",{className:"max-w-60 overflow-hidden text-ellipsis whitespace-nowrap",children:re}),ge()]})}if(s==="superscript"){let S=b(!O&&"text-gray-700 dark:text-gray-200",F&&!O&&"line-through opacity-60",O&&"text-gray-500 dark:text-gray-400");return jsxs("sup",{className:b("text-xs font-medium transition-colors hover:underline",S),children:["[",re,ge(),"]"]})}if(s==="text")return jsxs("span",{className:Nt,children:[re,ge()]});if(s==="minimal"){let S=b(!O&&"text-gray-700 dark:text-gray-200",F&&!O&&"opacity-70 line-through",O&&"text-gray-500 dark:text-gray-400");return jsxs("span",{className:b("max-w-80 overflow-hidden text-ellipsis",S),children:[re,ge()]})}if(s==="source"){let S=I||e.faviconUrl;return jsxs("span",{className:b("inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-sm font-medium","bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-300","hover:bg-gray-200 dark:hover:bg-gray-700","transition-colors cursor-pointer"),children:[S&&jsx("img",{src:S,alt:"",className:"w-4 h-4 rounded-sm object-contain",loading:"lazy",onError:de=>{de.target.style.display="none";}}),jsx("span",{className:"max-w-40 overflow-hidden text-ellipsis whitespace-nowrap",children:re}),P!==void 0&&P>0&&jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:["+",P]})]})}if(s==="linter"){let S=te&&!Q&&!O,de=Q&&!O,Y=F&&!O,_t=O,oe={textDecoration:"underline",textDecorationThickness:"2px",textUnderlineOffset:"3px",borderRadius:"2px",fontSize:"inherit",fontFamily:"inherit",lineHeight:"inherit"};Y?(oe.textDecorationStyle="wavy",oe.textDecorationColor="var(--dc-linter-error, #ef4444)"):de?(oe.textDecorationStyle="dashed",oe.textDecorationColor="var(--dc-linter-warning, #d97706)"):S?(oe.textDecorationStyle="solid",oe.textDecorationColor="var(--dc-linter-success, #16a34a)"):(oe.textDecorationStyle="dotted",oe.textDecorationColor="var(--dc-linter-pending, #9ca3af)");let kr=b("cursor-pointer",(S||de||Y)&&"text-gray-700 dark:text-gray-200",_t&&"text-gray-500 dark:text-gray-400",S&&"bg-green-600/[0.08] hover:bg-green-600/[0.15] dark:bg-green-500/[0.08] dark:hover:bg-green-500/[0.15]",de&&"hover:bg-amber-600/10 dark:hover:bg-amber-500/10",Y&&"hover:bg-red-500/10 dark:hover:bg-red-400/10",_t&&"bg-gray-500/[0.05] hover:bg-gray-500/10 dark:bg-gray-400/[0.05] dark:hover:bg-gray-400/10");return jsxs("span",{className:kr,style:oe,children:[re,m&&ge()]})}return jsxs("span",{className:b("inline-flex items-baseline gap-0.5 whitespace-nowrap","font-mono text-xs leading-tight","text-gray-500 dark:text-gray-400","transition-colors"),"aria-hidden":"true",children:["[",jsxs("span",{className:b("max-w-80 overflow-hidden text-ellipsis",Nt),children:[re,ge()]}),"]"]})},vr=!(x==="hidden")&&(o&&(o.verificationImageBase64||o.verifiedMatchSnippet)||O||ne||n||F),Ct=!!o?.verificationImageBase64,St=E?jsx(Ca,{src:E,alt:"Citation verification - full size",onClose:()=>D(null)}):null,Pt={"data-citation-id":h,"data-citation-instance":K,className:b("relative inline-flex items-baseline cursor-pointer","px-0.5 -mx-0.5 rounded-sm","transition-all duration-[50ms]",s!=="linter"&&"hover:bg-blue-500/10 dark:hover:bg-blue-400/10",Ct&&"cursor-zoom-in",r),onMouseEnter:gr,onMouseLeave:fr,onClick:mr,onTouchStart:d$1?yr:void 0,onTouchEndCapture:d$1?br:void 0,"aria-label":re?`[${re}]`:void 0};if(vr){let S=p?jsx(Ie,{children:p({citation:e,verification:o??null,status:G})}):jsx(Ie,{children:jsx(ar,{citation:e,verification:o??null,status:G,isLoading:n||O,isPhrasesExpanded:X,onPhrasesExpandChange:A,isVisible:w,onImageClick:()=>{o?.verificationImageBase64&&D(o.verificationImageBase64);}})});return jsxs(Fragment,{children:[t,Ct&&!w&&!p?jsx(Ie,{children:jsx(ar,{citation:e,verification:o??null,status:G,isLoading:false,isVisible:false,onImageClick:()=>{}})}):null,jsxs(Dt,{open:w,children:[jsx(At,{asChild:true,children:jsx("span",{ref:_,...Pt,children:wt()})}),jsx(tt,{side:x==="bottom"?"bottom":"top",onPointerDownOutside:Y=>Y.preventDefault(),onInteractOutside:Y=>Y.preventDefault(),onMouseEnter:xr,onMouseLeave:hr,children:S})]}),St]})}return jsxs(Fragment,{children:[t,jsx("span",{ref:_,...Pt,children:wt()}),St]})});it.displayName="CitationComponent";var Ia=memo(it);function sr(e,t){return t||`https://www.google.com/s2/favicons?domain=${q(e)}&sz=32`}function ut(e){if(!e.startsWith("http://")&&!e.startsWith("https://"))return "unknown";try{let t=q(e).toLowerCase();return t.includes("twitter.com")||t==="x.com"||t.endsWith(".x.com")||t.includes("facebook.com")||t.includes("instagram.com")||t.includes("linkedin.com")||t.includes("threads.net")||t.includes("mastodon")?"social":t.includes("youtube.com")||t.includes("youtu.be")||t.includes("twitch.tv")||t.includes("vimeo.com")||t.includes("tiktok.com")?"video":t.includes("github.com")||t.includes("gitlab.com")||t.includes("bitbucket.org")||t.includes("stackoverflow.com")?"code":t.includes("arxiv.org")||t.includes("scholar.google")||t.includes("pubmed")||t.includes("doi.org")||t.includes("researchgate.net")||t.includes("academia.edu")?"academic":t.includes("news.")||t.includes("reuters.com")||t.includes("bbc.com")||t.includes("cnn.com")||t.includes("nytimes.com")||t.includes("wsj.com")||t.includes("theguardian.com")||t.includes("washingtonpost.com")?"news":t.includes("wikipedia.org")||t.includes("britannica.com")||t.includes("merriam-webster.com")||t.includes("dictionary.com")?"reference":t.includes("reddit.com")||t.includes("quora.com")||t.includes("discourse")||t.includes("forum")?"forum":t.includes("amazon.")||t.includes("ebay.")||t.includes("shopify")||t.includes("etsy.com")?"commerce":e.toLowerCase().endsWith(".pdf")?"pdf":"web"}catch{return "unknown"}}function pt(e,t){let r=(t||q(e)).toLowerCase(),a={"twitter.com":"X","x.com":"X","facebook.com":"Facebook","instagram.com":"Instagram","linkedin.com":"LinkedIn","youtube.com":"YouTube","youtu.be":"YouTube","twitch.tv":"Twitch","github.com":"GitHub","gitlab.com":"GitLab","stackoverflow.com":"Stack Overflow","reddit.com":"Reddit","wikipedia.org":"Wikipedia","arxiv.org":"arXiv","medium.com":"Medium","substack.com":"Substack","notion.so":"Notion","docs.google.com":"Google Docs","drive.google.com":"Google Drive","figma.com":"Figma","streamscharts.com":"Streams Charts","dexerto.com":"Dexerto"};if(a[r])return a[r];for(let[o,n]of Object.entries(a))if(r===o||r.endsWith("."+o))return n;return r.charAt(0).toUpperCase()+r.slice(1)}var Aa=()=>jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),Ra=()=>jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:jsx("polyline",{points:"9 18 15 12 9 6"})}),Va=()=>jsxs("svg",{className:"animate-spin",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),Re=forwardRef(({id:e,url:t,title:r,domain:a,sourceType:o,faviconUrl:n,citationNumbers:s,verificationStatus:i,onClick:c,className:l,showVerificationIndicator:d=false,showCitationBadges:u=false,renderFavicon:f},x)=>{let p=useCallback(k=>{c?c({id:e,url:t,title:r,domain:a,sourceType:o,faviconUrl:n,citationNumbers:s,verificationStatus:i},k):window.open(t,"_blank","noopener,noreferrer");},[c,e,t,r,a,o,n,s,i]),P=useMemo(()=>pt(t,a),[t,a]),I=useMemo(()=>sr(t,n),[t,n]),m=useMemo(()=>o||ut(t),[o,t]),_=()=>{if(!d||!i)return null;let M={verified:{icon:"\u2713",className:"text-green-600 dark:text-green-500"},partial:{icon:"~",className:"text-amber-600 dark:text-amber-500"},pending:{icon:"\u2026",className:"text-gray-400 dark:text-gray-500"},failed:{icon:"\u2717",className:"text-red-500 dark:text-red-400"},unknown:{icon:"?",className:"text-gray-400 dark:text-gray-500"}}[i];return jsx("span",{className:j("text-sm ml-1",M.className),"aria-label":i,children:M.icon})};return jsxs("div",{ref:x,"data-source-id":e,"data-source-type":m,className:j("flex items-start gap-3 p-3 cursor-pointer transition-colors","hover:bg-gray-50 dark:hover:bg-gray-800/50","border-b border-gray-100 dark:border-gray-800 last:border-b-0",l),onClick:p,role:"link",tabIndex:0,onKeyDown:k=>{(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),p(k));},"aria-label":`${r} from ${P}`,children:[jsx("div",{className:"flex-shrink-0 mt-0.5",children:f?f({id:e,url:t,title:r,domain:a,sourceType:o,faviconUrl:n,citationNumbers:s,verificationStatus:i}):jsx("img",{src:I,alt:"",className:"w-5 h-5 rounded",width:20,height:20,loading:"lazy",onError:k=>{k.target.style.display="none";}})}),jsxs("div",{className:"flex-1 min-w-0",children:[jsxs("div",{className:"flex items-center gap-1",children:[jsx("span",{className:"text-gray-900 dark:text-gray-100 font-medium text-sm leading-tight line-clamp-2",children:r}),_()]}),jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[jsx("span",{className:"text-gray-500 dark:text-gray-400 text-xs",children:P}),u&&s&&s.length>0&&jsxs("div",{className:"flex items-center gap-1",children:[s.slice(0,3).map(k=>jsx("span",{className:"inline-flex items-center justify-center w-4 h-4 text-[10px] font-medium bg-gray-200 dark:bg-gray-700 text-gray-600 dark:text-gray-300 rounded",children:k},k)),s.length>3&&jsxs("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:["+",s.length-3]})]})]})]}),jsx("div",{className:"flex-shrink-0 text-gray-400 dark:text-gray-500 mt-1",children:jsx(Ra,{})})]})});Re.displayName="SourcesListItem";var mt=forwardRef(({sources:e,maxIcons:t=3,onClick:r,label:a="Sources",className:o,isOpen:n},s)=>{let i=useMemo(()=>e.slice(0,t),[e,t]),c=e.length>t;return jsxs("button",{ref:s,type:"button",onClick:r,className:j("inline-flex items-center gap-2 px-3 py-1.5 rounded-full text-sm","bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300","hover:bg-gray-200 dark:hover:bg-gray-700 transition-colors","focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2",o),"aria-expanded":n,"aria-haspopup":"dialog",children:[jsx("span",{className:"font-medium",children:a}),jsxs("div",{className:"flex items-center -space-x-1",children:[i.map((l,d)=>jsx("img",{src:sr(l.url,l.faviconUrl),alt:"",className:j("w-4 h-4 rounded-full ring-2 ring-gray-100 dark:ring-gray-800",d>0&&"-ml-1"),width:16,height:16,loading:"lazy",onError:u=>{u.target.style.opacity="0";}},l.id)),c&&jsxs("span",{className:"w-4 h-4 rounded-full bg-gray-300 dark:bg-gray-600 ring-2 ring-gray-100 dark:ring-gray-800 flex items-center justify-center text-[9px] font-medium text-gray-600 dark:text-gray-300",children:["+",e.length-t]})]})]})});mt.displayName="SourcesTrigger";var gt=forwardRef(({sources:e,variant:t="drawer",isOpen:r=true,onOpenChange:a,header:o={},isLoading:n=false,emptyMessage:s="No sources available",maxHeight:i,className:c,listClassName:l,onSourceClick:d,showVerificationIndicators:u=false,showCitationBadges:f=false,groupByDomain:x=false,renderItem:p,renderEmpty:P,renderLoading:I},m)=>{let _=useRef(null),[k,M]=useState(false);useEffect(()=>{if(!r||t==="inline")return;let h=K=>{K.key==="Escape"&&a?.(false);};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[r,a,t]),useEffect(()=>{M(true);},[]);let w=useMemo(()=>{if(!x)return null;let h={};for(let K of e){let G=K.domain||q(K.url);h[G]||(h[G]=[]),h[G].push(K);}return h},[e,x]),V=useCallback(()=>{a?.(false);},[a]),E=useCallback(h=>{h.target===h.currentTarget&&V();},[V]),D=()=>{let{title:h="Sources",showCloseButton:K=true,showCount:G=true,renderHeader:F}=o;return F?F({title:h,count:e.length,onClose:V}):jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-200 dark:border-gray-700",children:[K&&t!=="inline"&&jsx("button",{type:"button",onClick:V,className:"p-1 -ml-1 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 transition-colors","aria-label":"Close sources",children:jsx(Aa,{})}),jsxs("h2",{className:"text-base font-semibold text-gray-900 dark:text-gray-100 flex-1 text-center",children:[h,G&&jsxs("span",{className:"ml-2 text-sm font-normal text-gray-500 dark:text-gray-400",children:["(",e.length,")"]})]}),K&&t!=="inline"&&jsx("div",{className:"w-8"})]})},X=()=>n?I?I():jsxs("div",{className:"flex items-center justify-center py-8 text-gray-500 dark:text-gray-400",children:[jsx(Va,{}),jsx("span",{className:"ml-2 text-sm",children:"Loading sources..."})]}):e.length===0?P?P():jsx("div",{className:"flex items-center justify-center py-8 text-gray-500 dark:text-gray-400 text-sm",children:s}):x&&w?jsx("div",{className:l,children:Object.entries(w).map(([h,K])=>jsxs("div",{children:[jsx("div",{className:"px-4 py-2 text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider bg-gray-50 dark:bg-gray-800/50",children:pt(K[0].url,h)}),K.map((G,F)=>p?p(G,F):jsx(Re,{...G,onClick:d,showVerificationIndicator:u,showCitationBadges:f},G.id))]},h))}):jsx("div",{className:l,children:e.map((h,K)=>p?p(h,K):jsx(Re,{...h,onClick:d,showVerificationIndicator:u,showCitationBadges:f},h.id))}),A=i?{maxHeight:typeof i=="number"?`${i}px`:i}:void 0;if(t==="inline")return r?jsxs("div",{ref:m,className:j("bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700",c),style:A,children:[D(),jsx("div",{className:"overflow-y-auto",style:A,children:X()})]}):null;if(t==="panel")return r?jsxs("div",{ref:m,className:j("bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700 shadow-lg",c),children:[D(),jsx("div",{className:"overflow-y-auto",style:A||{maxHeight:"400px"},children:X()})]}):null;if(!k||!r)return null;let $=jsxs("div",{ref:m,className:j("fixed inset-0 z-50",t==="modal"&&"flex items-center justify-center"),role:"dialog","aria-modal":"true","aria-labelledby":"sources-title",children:[jsx("div",{className:j("absolute inset-0 bg-black/40 dark:bg-black/60 transition-opacity",r?"opacity-100":"opacity-0"),onClick:E,"aria-hidden":"true"}),t==="drawer"?jsxs("div",{ref:_,className:j("absolute bottom-0 left-0 right-0 bg-white dark:bg-gray-900 rounded-t-2xl shadow-2xl","transform transition-transform duration-300 ease-out",r?"translate-y-0":"translate-y-full","max-h-[80vh] flex flex-col",c),children:[jsx("div",{className:"flex justify-center py-2",children:jsx("div",{className:"w-10 h-1 bg-gray-300 dark:bg-gray-600 rounded-full"})}),D(),jsx("div",{className:"overflow-y-auto flex-1",children:X()})]}):jsxs("div",{ref:_,className:j("relative bg-white dark:bg-gray-900 rounded-xl shadow-2xl","transform transition-all duration-200",r?"opacity-100 scale-100":"opacity-0 scale-95","w-full max-w-md max-h-[80vh] flex flex-col mx-4",c),children:[D(),jsx("div",{className:"overflow-y-auto flex-1",children:X()})]})]});return createPortal($,document.body)});gt.displayName="SourcesListComponent";var Ba=memo(Re),$a=memo(mt),za=memo(gt);function Ha(e){let t=new Map;for(let r of e){if(!r.url)continue;let a=r.domain||q(r.url),o=r.url;if(t.has(o)){let n=t.get(o);r.citationNumber&&!n.citationNumbers?.includes(r.citationNumber)&&(n.citationNumbers=[...n.citationNumbers||[],r.citationNumber]);}else t.set(o,{id:o,url:r.url,title:r.title||a,domain:a,sourceType:r.sourceType||ut(r.url),faviconUrl:r.faviconUrl,citationNumbers:r.citationNumber?[r.citationNumber]:[]});}return Array.from(t.values())}function ja(e=[]){let[t,r]=useState(e),[a,o]=useState(false),n=useCallback(c=>{r(l=>l.some(u=>u.url===c.url)?l:[...l,c]);},[]),s=useCallback(c=>{r(l=>l.filter(d=>d.id!==c));},[]),i=useCallback(()=>{r([]);},[]);return {sources:t,setSources:r,addSource:n,removeSource:s,clearSources:i,isOpen:a,setIsOpen:o,open:()=>o(true),close:()=>o(false),toggle:()=>o(c=>!c)}}function cr(e){let t=new Map;for(let r of e){let a=r.citation.domain||r.citation.siteName||r.citation.url||"unknown";t.has(a)||t.set(a,[]),t.get(a).push(r);}return Array.from(t.entries()).map(([r,a])=>{let o=a[0].citation;return {sourceName:o.siteName||o.domain||ht(o.url)||"Unknown Source",sourceDomain:o.domain||ht(o.url),sourceFavicon:o.faviconUrl||void 0,citations:a,additionalCount:a.length-1}})}function ht(e){if(e)try{return new URL(e).hostname.replace(/^www\./,"")}catch{return}}function Wa(e){let t=e?.status;return !t||t==="pending"||t==="loading"?{color:"text-gray-400",icon:jsx(ue,{}),label:"Verifying"}:t==="not_found"?{color:"text-amber-500",icon:jsx(Ne,{}),label:"Not found"}:t==="partial_text_found"||t==="found_on_other_page"||t==="found_on_other_line"||t==="first_word_found"?{color:"text-amber-500",icon:jsx(B,{}),label:"Partial match"}:{color:"text-green-500",icon:jsx(B,{}),label:"Verified"}}function yt({item:e,isLast:t=false,onClick:r,onReadMore:a,className:o}){let{citation:n,verification:s}=e,i=Wa(s),c=n.siteName||n.domain||ht(n.url)||"Source",l=n.title||n.anchorText||n.fullPhrase,d=n.description||s?.actualContentSnippet||s?.verifiedMatchSnippet,u=n.faviconUrl,f=useCallback(()=>{r?.(e);},[e,r]),x=useCallback(p=>{p.stopPropagation(),a?.(e);},[e,a]);return jsx("div",{className:b("px-4 py-3 hover:bg-gray-50 dark:hover:bg-gray-800/50 cursor-pointer transition-colors",!t&&"border-b border-gray-200 dark:border-gray-700",o),onClick:f,role:"button",tabIndex:0,onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),f());},children:jsxs("div",{className:"flex items-start gap-3",children:[jsx("div",{className:"flex-shrink-0 mt-0.5",children:u?jsx("img",{src:u,alt:"",className:"w-5 h-5 rounded object-contain",loading:"lazy",onError:p=>{p.target.style.display="none";}}):jsx("div",{className:"w-5 h-5 rounded bg-gray-200 dark:bg-gray-700 flex items-center justify-center",children:jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:c.charAt(0).toUpperCase()})})}),jsxs("div",{className:"flex-1 min-w-0",children:[jsxs("div",{className:"flex items-center gap-1.5",children:[jsx("span",{className:"text-xs font-medium text-gray-500 dark:text-gray-400",children:c}),jsx("span",{className:b("inline-flex w-3 h-3",i.color,s?.status==="pending"||s?.status==="loading"?"animate-spin":""),title:i.label,children:i.icon})]}),l&&jsx("h4",{className:"mt-1 text-sm font-medium text-gray-900 dark:text-gray-100 line-clamp-2",children:l}),d&&jsxs("p",{className:"mt-1 text-sm text-gray-600 dark:text-gray-400 line-clamp-2",children:[d,a&&d.length>100&&jsx("button",{onClick:x,className:"ml-1 text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300",children:"Read more"})]})]})]})})}function Fa({isOpen:e,onClose:t,citationGroups:r,title:a="Citations",showMoreSection:o=true,maxVisibleItems:n=3,onCitationClick:s,onReadMore:i,className:c,position:l="bottom",renderCitationItem:d}){let[u,f]=useState(false),x=useMemo(()=>r.flatMap(m=>m.citations),[r]),p=useMemo(()=>!o||u?x:x.slice(0,n),[x,o,u,n]),P=useMemo(()=>!o||u?[]:x.slice(n),[x,o,u,n]);if(ft__default.useEffect(()=>{if(!e)return;let m=_=>{_.key==="Escape"&&t();};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[e,t]),!e)return null;let I=jsxs(Fragment,{children:[jsx("div",{className:"fixed inset-0 bg-black/40 z-[9998] animate-in fade-in-0 duration-150",onClick:t,"aria-hidden":"true"}),jsxs("div",{className:b("fixed z-[9999] bg-white dark:bg-gray-900 shadow-xl","animate-in duration-200",l==="bottom"&&"inset-x-0 bottom-0 max-h-[80vh] rounded-t-2xl slide-in-from-bottom-4",l==="right"&&"inset-y-0 right-0 w-full max-w-md slide-in-from-right-4",c),role:"dialog","aria-modal":"true","aria-label":a,children:[l==="bottom"&&jsx("div",{className:"flex justify-center pt-3 pb-1",children:jsx("div",{className:"w-10 h-1 rounded-full bg-gray-300 dark:bg-gray-600"})}),jsxs("div",{className:"px-4 py-3 border-b border-gray-200 dark:border-gray-700 flex items-center justify-between",children:[jsx("h2",{className:"text-base font-semibold text-gray-900 dark:text-gray-100",children:a}),jsx("button",{onClick:t,className:"p-1.5 rounded-full hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors","aria-label":"Close",children:jsx("svg",{className:"w-5 h-5 text-gray-500 dark:text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),jsx("div",{className:"overflow-y-auto max-h-[calc(80vh-100px)]",children:p.length===0?jsx("div",{className:"px-4 py-8 text-center text-gray-500 dark:text-gray-400",children:"No citations to display"}):jsxs(Fragment,{children:[p.map((m,_)=>d?jsx(ft__default.Fragment,{children:d(m)},m.citationKey):jsx(yt,{item:m,isLast:_===p.length-1&&P.length===0,onClick:s,onReadMore:i},m.citationKey)),P.length>0&&!u&&jsx("div",{className:"px-4 py-3 border-t border-gray-200 dark:border-gray-700",children:jsxs("button",{onClick:()=>f(true),className:"text-sm font-medium text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300",children:["More (",P.length,")"]})}),u&&P.map((m,_)=>d?jsx(ft__default.Fragment,{children:d(m)},m.citationKey):jsx(yt,{item:m,isLast:_===P.length-1,onClick:s,onReadMore:i},m.citationKey))]})})]})]});return createPortal(I,document.body)}function Ua(){let[e,t]=useState(false),[r,a]=useState([]),o=useCallback(()=>t(true),[]),n=useCallback(()=>t(false),[]),s=useCallback(()=>t(f=>!f),[]),i=useCallback(f=>{a(x=>x.some(p=>p.citationKey===f.citationKey)?x:[...x,f]);},[]),c=useCallback(f=>{a(x=>x.filter(p=>p.citationKey!==f));},[]),l=useCallback(()=>{a([]);},[]),d=useCallback(f=>{a(f);},[]),u=useMemo(()=>cr(r),[r]);return {isOpen:e,openDrawer:o,closeDrawer:n,toggleDrawer:s,citations:r,citationGroups:u,addCitation:i,removeCitation:c,clearCitations:l,setCitations:d}}var Ka=ft__default.Activity??(({children:e})=>jsx(Fragment,{children:e}));function dr({isVisible:e,src:t,alt:r,onClick:a,className:o,imageStyle:n}){return jsx(Ka,{mode:e?"visible":"hidden",children:jsx("div",{className:o,children:jsx("button",{type:"button",className:"group block cursor-zoom-in relative overflow-hidden rounded-md bg-gray-50 dark:bg-gray-800",onClick:s=>{s.preventDefault(),s.stopPropagation(),a?.();},"aria-label":"Click to view full size",children:jsx("img",{src:t,alt:r,className:"block rounded-md",style:n??{maxWidth:"min(70vw, 384px)",maxHeight:"min(50vh, 300px)",width:"auto",height:"auto",objectFit:"contain"},loading:"eager",decoding:"async"})})})})}var Xa=memo(dr);function Qa(){return ft__default.useCallback(t=>new Promise((r,a)=>{let o=new Image;o.onload=()=>r(),o.onerror=a,o.src=t;}),[])}async function Ya(e){let t=e.map(r=>new Promise((a,o)=>{let n=new Image;n.onload=()=>a(),n.onerror=o,n.src=r;}));return Promise.all(t)}var bt=({isActive:e,onClick:t,label:r})=>jsx("button",{onClick:a=>{a.stopPropagation(),t();},className:b("px-3 py-1.5 text-sm font-medium rounded-md transition-colors","focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-1",e?"bg-blue-100 text-blue-700 dark:bg-blue-900/50 dark:text-blue-300":"text-gray-600 hover:text-gray-900 hover:bg-gray-100 dark:text-gray-400 dark:hover:text-gray-200 dark:hover:bg-gray-800"),type:"button","data-active":e,children:r}),Ja=({mode:e,onModeChange:t})=>jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[jsx("button",{type:"button",onClick:r=>{r.stopPropagation(),t("inline");},className:b("p-1 rounded transition-colors",e==="inline"?"bg-gray-200 dark:bg-gray-700 text-gray-700 dark:text-gray-300":"text-gray-400 hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-400"),title:"Inline diff view","aria-label":"Inline diff view",children:jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 6h16M4 12h16M4 18h16"})})}),jsx("button",{type:"button",onClick:r=>{r.stopPropagation(),t("split");},className:b("p-1 rounded transition-colors",e==="split"?"bg-gray-200 dark:bg-gray-700 text-gray-700 dark:text-gray-300":"text-gray-400 hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-400"),title:"Split view","aria-label":"Split view",children:jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 6h16M4 12h16M4 18h7"})})})]}),en=({expected:e,actual:t,label:r,renderCopyButton:a,emptyText:o="No text found",status:n,anchorText:s,verifiedKeySpan:i,defaultMode:c="auto",expectedPage:l,actualPage:d,showMatchQuality:u=true,maxCollapsedLength:f=200})=>{let{diffResult:x,isHighVariance:p,hasDiff:P,similarity:I}=at(e,t),[m,_]=useState("diff"),[k,M]=useState(()=>c==="inline"?"inline":c==="split"||p?"split":"inline");useEffect(()=>{c==="auto"&&M(p?"split":"inline");},[p,c]),useEffect(()=>{_("diff");},[p,e,t]);let w=useMemo(()=>ot(n,l,d),[n,l,d]),V=()=>jsx("div",{"data-testid":"tab-content-found",className:"mt-3",children:t?jsxs("div",{className:"relative",children:[a&&jsx("div",{className:"absolute top-2 right-2",children:a(t,"found")}),jsx("div",{className:"p-3 bg-gray-50 dark:bg-gray-800 rounded-md text-sm text-gray-700 dark:text-gray-300 font-mono whitespace-pre-wrap break-words",children:jsx(xe,{text:t,maxLength:f,anchorText:i,anchorTextClass:"bg-green-200 dark:bg-green-800/50 px-0.5 rounded border-b-2 border-green-400 dark:border-green-500"})})]}):jsx("span",{"data-testid":"empty-text",className:"text-sm text-gray-500 dark:text-gray-400 italic",children:o})});return !P&&!!t&&!!e?jsxs("div",{"data-testid":"verification-tabs","data-exact-match":"true",className:"space-y-2",children:[r&&jsx("div",{className:"text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wide",children:r}),jsxs("div",{"data-testid":"exact-match-badge",className:"inline-flex items-center gap-1.5 px-2.5 py-1 bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 rounded-full text-sm font-medium",children:[jsx("span",{className:"size-2",children:jsx(B,{})}),jsx("span",{children:"Exact match"})]}),jsx("div",{children:V()})]}):jsxs("div",{"data-testid":"verification-tabs",className:"space-y-2",children:[r&&jsx("div",{"data-testid":"verification-label",className:"text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wide",children:r}),w&&n&&n!=="found"&&n!=="pending"&&n!=="loading"&&jsxs("div",{"data-testid":"status-message",className:b("text-xs font-medium px-2 py-1 rounded-md inline-flex items-center gap-1.5",n==="not_found"?"bg-red-100 dark:bg-red-900/30 text-red-600 dark:text-red-400":"bg-amber-100 dark:bg-amber-900/30 text-amber-600 dark:text-amber-400"),children:[n!=="not_found"&&jsx("span",{className:"size-2.5",children:jsx(B,{})}),w]}),jsx("div",{"data-testid":"tabs-container",children:jsxs("div",{"data-testid":"tabs-nav",className:"flex gap-1 p-1 bg-gray-100 dark:bg-gray-800 rounded-lg items-center",children:[jsx(bt,{label:"Expected",isActive:m==="expected",onClick:()=>_("expected")}),jsx(bt,{label:"Diff",isActive:m==="diff",onClick:()=>_("diff")}),jsx(bt,{label:"Found",isActive:m==="found",onClick:()=>_("found")}),m==="diff"&&P&&jsx(Ja,{mode:k,onModeChange:M})]})}),jsxs("div",{"data-testid":"tabs-content",children:[m==="found"&&V(),m==="expected"&&jsx("div",{"data-testid":"tab-content-expected",className:"mt-3",children:jsxs("div",{className:"relative",children:[a&&jsx("div",{className:"absolute top-2 right-2",children:a(e,"expected")}),jsx("div",{className:"p-3 bg-gray-50 dark:bg-gray-800 rounded-md text-sm text-gray-700 dark:text-gray-300 font-mono whitespace-pre-wrap break-words",children:jsx(xe,{text:e,maxLength:f,anchorText:s,anchorTextClass:"bg-blue-200 dark:bg-blue-800/50 px-0.5 rounded border-b-2 border-blue-400 dark:border-blue-500"})})]})}),m==="diff"&&jsx("div",{"data-testid":"tab-content-diff",className:"mt-3",children:P?k==="split"?jsx(We,{expected:e,actual:t,mode:"split",showMatchQuality:u,maxCollapsedLength:f,anchorTextExpected:s,anchorTextFound:i,status:n,similarity:I}):jsxs("div",{"data-testid":"diff-result",className:"space-y-2",children:[u&&jsx(Le,{similarity:I,className:"mb-2"}),jsx("div",{className:"p-3 bg-gray-50 dark:bg-gray-800 rounded-md text-sm font-mono whitespace-pre-wrap break-words",children:x.map((D,X)=>jsx("div",{className:b(D.type==="added"&&"bg-green-50 dark:bg-green-900/20",D.type==="removed"&&"bg-red-50 dark:bg-red-900/20"),children:D.parts.map((A,$)=>A.removed?jsx("span",{"data-diff-type":"removed",className:"bg-red-200 dark:bg-red-800/50 text-red-800 dark:text-red-200 line-through",title:"Expected but not found",children:A.value},$):A.added?jsx("span",{"data-diff-type":"added",className:"bg-green-200 dark:bg-green-800/50 text-green-800 dark:text-green-200",title:"Actually found in source",children:A.value},$):jsx("span",{className:"text-gray-700 dark:text-gray-300",children:A.value},$))},X))})]}):jsxs("div",{"data-testid":"exact-match-indicator",className:"inline-flex items-center gap-1.5 text-green-600 dark:text-green-500 text-sm",children:[jsx("span",{className:"size-2",children:jsx(B,{})}),jsx("span",{children:"Exact Match"})]})})]})]})};
7
+ export{ma as AttemptingToVerify,B as CheckIcon,it as CitationComponent,Fa as CitationDrawer,yt as CitationDrawerItemComponent,Qr as CitationOverlayProvider,Be as CloseIcon,xe as CollapsibleText,Tr as DeepCitationIcon,Mr as ExternalLinkIcon,Lr as LinkIcon,Qe as LockIcon,Le as MatchQualityBar,Ia as MemoizedCitationComponent,Xa as MemoizedPrefetchedPopoverImage,za as MemoizedSourcesListComponent,Ba as MemoizedSourcesListItem,$a as MemoizedSourcesTrigger,Br as MemoizedUrlCitationComponent,dr as PrefetchedPopoverImage,st as QuoteBox,gt as SourcesListComponent,Re as SourcesListItem,mt as SourcesTrigger,ue as SpinnerIcon,We as SplitDiffDisplay,Me as StatusHeader,Lt as URL_STATUS_ICONS,et as UrlCitationComponent,Fe as VerificationLog,en as VerificationTabs,Ne as WarningIcon,ut as detectSourceType,q as extractDomain,ot as getContextualStatusMessage,pt as getPlatformName,cr as groupCitationsBySource,Dr as isAccessibleStatus,Ze as isBlockedStatus,Je as isErrorStatus,Ar as isRedirectedStatus,Mt as isVerifiedStatus,Ya as prefetchImages,Ha as sourceCitationsToListItems,zr as urlDisplayUtils,Ua as useCitationDrawer,He as useCitationOverlay,Yr as useHasCitationOverlayProvider,Qa as usePrefetchImage,at as useSmartDiff,ja as useSourcesList,$r as useUrlMeta};//# sourceMappingURL=index.js.map
8
+ //# sourceMappingURL=index.js.map