@deepcitation/deepcitation-js 1.1.40 → 1.1.41

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.
@@ -0,0 +1 @@
1
+ function E(t){return new TextEncoder().encode(t)}function Z(t){let e=1732584193,i=4023233417,r=2562383102,n=271733878,o=3285377520,p=t.length,a=p*8,c=p+1+8,u=Math.ceil(c/64)*64,s=new ArrayBuffer(u),C=new Uint8Array(s),d=new DataView(s);C.set(t),C[p]=128,d.setUint32(u-8,Math.floor(a/4294967296),false),d.setUint32(u-4,a>>>0,false);let l=new Uint32Array(80);for(let x=0;x<u;x+=64){for(let g=0;g<16;g++)l[g]=d.getUint32(x+g*4,false);for(let g=16;g<80;g++){let I=l[g-3]^l[g-8]^l[g-14]^l[g-16];l[g]=I<<1|I>>>31;}let f=e,h=i,_=r,k=n,S=o;for(let g=0;g<80;g++){let I,m;g<20?(I=h&_|~h&k,m=1518500249):g<40?(I=h^_^k,m=1859775393):g<60?(I=h&_|h&k|_&k,m=2400959708):(I=h^_^k,m=3395469782);let b=(f<<5|f>>>27)+I+S+m+l[g]>>>0;S=k,k=_,_=(h<<30|h>>>2)>>>0,h=f,f=b;}e=e+f>>>0,i=i+h>>>0,r=r+_>>>0,n=n+k>>>0,o=o+S>>>0;}let y=x=>x.toString(16).padStart(8,"0");return y(e)+y(i)+y(r)+y(n)+y(o)}function P(t){try{if(!t)return "";let e=typeof t=="string"?t:JSON.stringify(t);return Z(E(e))}catch(e){console.error("Error in making the hash:",e);}return ""}function j(...t){return t.filter(Boolean).join(" ")}function U(t){return t.type==="url"||typeof t.url=="string"&&t.url.length>0}function A(t){let e=t.pageNumber||v(t.startPageKey),i=[t.attachmentId||"",e?.toString()||"",t.fullPhrase||"",t.keySpan?.toString()||"",t.lineIds?.join(",")||"",t.timestamps?.startTime||"",t.timestamps?.endTime||""];return U(t)&&i.push(t.url||"",t.title||"",t.domain||""),P(i.join("|")).slice(0,16)}function Q(t){let e=[t.attachmentId||"",t.label||"",t.verifiedFullPhrase||"",t.verifiedKeySpan||"",t.verifiedLineIds?.join(",")||"",t.verifiedPageNumber?.toString()||"",t.verifiedTimestamps?.startTime||"",t.verifiedTimestamps?.endTime||"",t.verifiedMatchSnippet||"",t.hitIndexWithinPage?.toString()||""];return P(e.join("|")).slice(0,16)}function tt(t){let e=Math.random().toString(36).slice(2,11);return `${t}-${e}`}function et(t,e={}){let{fallbackDisplay:i}=e;return t.keySpan?.toString()||t.citationNumber?.toString()||i||"1"}function nt(t){return t.citationNumber?.toString()||"1"}function it(t){return t.keySpan?.toString()||""}function rt(...t){return t.filter(Boolean).join(" ")}var st=4,at=1;function D(t){if(!t)return;let e=[],i=t.split(",");for(let r of i){let n=r.trim();if(n)if(n.includes("-")){let[o,p]=n.split("-"),a=parseInt(o,10),c=parseInt(p,10);if(!isNaN(a)&&!isNaN(c)&&a<=c)for(let u=a;u<=c;u++)e.push(u);else isNaN(a)||e.push(a);}else {let o=parseInt(n,10);isNaN(o)||e.push(o);}}if(e.length!==0)return [...new Set(e)].sort((r,n)=>r-n)}function R(t){let e=t?.status,i=e==="not_found",r=e==="found_phrase_missed_value",n=e==="found_key_span_only",o=e==="partial_text_found"||e==="found_on_other_page"||e==="found_on_other_line"||e==="first_word_found";return {isVerified:e==="found"||n||o||r,isMiss:i,isPartialMatch:o,isPending:e==="pending"||e==="loading"||!e}}var B=(t,e,i,r)=>{let n=m=>m?m.replace(/^['"]|['"]$/g,"").replace(/\\'/g,"'"):void 0,o=i?.current?i.current++:void 0,p=t.substring(0,t.indexOf("<cite")),a=t.includes("/>")?t.slice(t.indexOf("/>")+2):"",c=t.substring(t.indexOf("<cite"),t.indexOf("/>")+2),u=(m,b)=>{for(let O of b){let L=new RegExp(`${O}='((?:[^'\\\\]|\\\\.)*)'`),K=m.match(L);if(K)return K[1]}},s=u(c,["attachment_id","attachmentId","file_id","fileId"]),C=s?.length===20?s:e||s,d=u(c,["start_page_key","startPageKey","start_page"]),l,y;if(d){let m=d.match(/page[\_a-zA-Z]*(\d+)_index_(\d+)/);m&&(l=parseInt(m[1]),y=parseInt(m[2]));}let x=n(u(c,["full_phrase","fullPhrase"])),f=n(u(c,["key_span","keySpan"])),h=n(u(c,["reasoning"])),_=n(u(c,["value"])),k;try{let b=u(c,["line_ids","lineIds"])?.replace(/[A-Za-z_[\](){}:]/g,"");k=b?D(b):void 0;}catch(m){r&&console.error("Error parsing lineIds",m);}let S=u(c,["timestamps"]),g;if(S){let[m,b]=S.split("-")||[];g={startTime:m,endTime:b};}let I={attachmentId:C,pageNumber:l,startPageKey:`page_number_${l||1}_index_${y||0}`,fullPhrase:x,keySpan:f||_,citationNumber:o,lineIds:k,beforeCite:p,timestamps:g,reasoning:h};return {beforeCite:p,afterCite:a,citation:I}},J=(t,e)=>{if(!t)return null;let i=t.fullPhrase??t.full_phrase,r=t.startPageKey??t.start_page_key,n=t.keySpan??t.key_span,o=t.lineIds??t.line_ids,p=t.attachmentId??t.attachment_id??t.fileId??t.file_id,a=t.reasoning,c=t.value;if(!i)return null;let u;if(r){let d=r.match(/page[_a-zA-Z]*(\d+)_index_(\d+)/i);if(d)u=parseInt(d[1],10);else {let l=r.match(/^(\d+)_(\d+)$/);l&&(u=parseInt(l[1],10));}}let s=o?.length?[...o].sort((d,l)=>d-l):void 0;return {attachmentId:p,pageNumber:u,fullPhrase:i,citationNumber:e,lineIds:s,keySpan:n||c,reasoning:a}},V=t=>typeof t=="object"&&t!==null&&("fullPhrase"in t||"full_phrase"in t||"startPageKey"in t||"start_page_key"in t||"keySpan"in t||"key_span"in t||"lineIds"in t||"line_ids"in t),N=t=>Array.isArray(t)?t.length>0&&t.some(V):typeof t=="object"&&t!==null?V(t):false,T=t=>{let e={},i=Array.isArray(t)?t:[t],r=1;for(let n of i){let o=J(n,r++);if(o&&o.fullPhrase){let p=A(o);e[p]=o;}}return e},w=(t,e)=>{if(!(!t||typeof t!="object")){if(t.citation&&N(t.citation)){let i=Array.isArray(t.citation)?t.citation:[t.citation];e.push(...i);}if(t.citations&&N(t.citations)){let i=Array.isArray(t.citations)?t.citations:[t.citations];e.push(...i);}if(Array.isArray(t))for(let i of t)w(i,e);else for(let i of Object.keys(t))i!=="citation"&&i!=="citations"&&w(t[i],e);}},M=t=>{let e=$(t),i=/<cite\s+[^>]*\/>/g,r=e.match(i);if(!r||r.length===0)return {};let n={},o={current:1};for(let p of r){let{citation:a}=B(p,void 0,o);if(a&&a.fullPhrase){let c=A(a);n[c]=a;}}return n},ut=t=>{if(!t)return {};let e={};if(typeof t=="object"){if(N(t)){let n=T(t);Object.assign(e,n);}else {let n=[];if(w(t,n),n.length>0){let o=T(n);Object.assign(e,o);}}let i=JSON.stringify(t),r=M(i);Object.assign(e,r);}else if(typeof t=="string"){let i=M(t);Object.assign(e,i);}return e};function pt(t){let e=new Map,i=Array.isArray(t)?t.map((r,n)=>[A(r)||String(n+1),r]):Object.entries(t);for(let[r,n]of i){let o=n.attachmentId||"";e.has(o)||e.set(o,{}),e.get(o)[r]=n;}return e}function ft(t){let e={},i=Array.isArray(t)?t.map((r,n)=>[A(r)||String(n+1),r]):Object.entries(t);for(let[r,n]of i){let o=n.attachmentId||"";e[o]||(e[o]={}),e[o][r]=n;}return e}var F=t=>{let e={},i=/([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*(['"])((?:[^'"\\]|\\.)*)\2/g,r;for(;(r=i.exec(t))!==null;){let n=r[1].toLowerCase().replace(/([a-z])([A-Z])/g,"$1_$2").toLowerCase(),o=r[3],p=n==="fileid"||n==="file_id"||n==="attachmentid"?"attachment_id":n==="keyspan"?"key_span":n==="fullphrase"?"full_phrase":n==="lineids"?"line_ids":n==="startpagekey"||n==="start_pagekey"?"start_page_key":n;e[p]=o;}return e},W=t=>{if(!t)return "\u25CC";let e=R(t);return e.isPending?"\u25CC":e.isMiss?"\u2717":e.isPartialMatch?"\u26A0":e.isVerified?"\u2713":"\u25CC"},H=W,G=(t,e={})=>{let{leaveKeySpanBehind:i=false,verifications:r,showVerificationStatus:n=false}=e,o=0,p=/<cite\s+[^>]*?\/>/g;return t.replace(p,a=>{o++;let c=F(a),u="";if(i&&c.key_span&&(u=c.key_span.replace(/\\'/g,"'").replace(/\\"/g,'"')),n&&r){let s,C=String(o);if(s=r[C],!s&&c.attachment_id){for(let[,l]of Object.entries(r))if(l.attachmentId===c.attachment_id){s=l;break}}let d=H(s);u=u?`${u}${d}`:d;}return u})},mt=(t,e)=>G(t,{leaveKeySpanBehind:e}),ht=t=>t.replace(/<page_number_\d+_index_\d+>/g,"").replace(/<\/page_number_\d+_index_\d+>/g,"").trim(),yt=t=>{let e=/<line id="[^"]*">|<\/line>/g;return t.replace(e,"")},v=t=>{if(!t)return null;let e=t.match(/\d+/)?.[0];return e?parseInt(e):null},$=t=>{let e=t?.trim()||"",i=e.split(/(<cite[\s\S]*?(?:\/>|<\/cite>))/gm);return i.length<=1?z(e):(e=i.map(r=>r.startsWith("<cite")?z(r):r).join(""),e)},z=t=>{let e=t;e=e.replace(/\\_/g,"_"),e=e.replace(/><\/cite>/g,"/>");let i=p=>{let a=p.toLowerCase();return a==="fullphrase"||a==="full_phrase"?"full_phrase":a==="lineids"||a==="line_ids"?"line_ids":a==="startpagekey"||a==="start_pagekey"||a==="start_page_key"?"start_page_key":a==="fileid"||a==="file_id"||a==="attachmentid"||a==="attachment_id"?"attachment_id":a==="keyspan"||a==="key_span"?"key_span":a==="reasoning"||a==="value"?a:a==="timestamps"||a==="timestamp"||a==="timestamps"?"timestamps":a},r=p=>p.replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&"),n=/(fullPhrase|full_phrase|keySpan|key_span|reasoning|value)\s*=\s*(['"])([\s\S]*?)(?=\s+(?:line_ids|lineIds|timestamps|fileId|file_id|attachmentId|attachment_id|start_page_key|start_pageKey|startPageKey|keySpan|key_span|reasoning|value|full_phrase)|\s*\/?>)/gm;e=e.replace(n,(p,a,c,u)=>{let s=u;return s.endsWith(c)&&(s=s.slice(0,-1)),s=s.replace(/(\r?\n)+/g," "),s=r(s),s=s.replace(/(\*|_){2,}/g,""),s=s.replace(/\\\\'/g,"'"),s=s.replace(/\\'/g,"'"),s=s.replace(/'/g,"\\'"),s=s.replace(/\\\\"/g,'"'),s=s.replace(/\\"/g,'"'),s=s.replace(/"/g,'\\"'),s=s.replace(/\*/g,""),`${i(a)}='${s}'`}),e=e.replace(/(line_ids|lineIds|timestamps)=['"]?([\[\]\(\){}A-Za-z0-9_\-, ]+)['"]?(\s*\/?>|\s+)/gm,(p,a,c,u)=>{let s=c.replace(/[A-Za-z\[\]\(\){}]/g,"");return s=s.replace(/(\d+)-(\d+)/g,(C,d,l)=>{let y=parseInt(d,10),x=parseInt(l,10),f=[];if(y<=x)for(let h=y;h<=x;h++)f.push(h);else f.push(y);return f.join(",")}),s=s.replace(/,+/g,",").replace(/^,|,$/g,""),`${i(a)}='${s}'${u}`});let o=p=>{let a=/([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(['"])((?:[^'"\\\n]|\\.)*)(?:\2)/g,c={},u;for(;u=a.exec(p);){let f=u[1],h=u[3],_=i(f);c[_]=h;}let s=Object.keys(c);if(s.length===0)return p;let C=typeof c.timestamps=="string"&&c.timestamps.length>0,d=s.filter(f=>f.startsWith("start_page")),l=[];c.attachment_id&&l.push("attachment_id"),C?(c.full_phrase&&l.push("full_phrase"),c.key_span&&l.push("key_span"),l.push("timestamps")):(d.includes("start_page_key")&&l.push("start_page_key"),d.filter(f=>f!=="start_page_key").sort().forEach(f=>l.push(f)),c.full_phrase&&l.push("full_phrase"),c.key_span&&l.push("key_span"),c.line_ids&&l.push("line_ids")),c.reasoning&&l.push("reasoning"),c.value&&l.push("value");let y=new Set(l);return s.filter(f=>!y.has(f)).sort().forEach(f=>l.push(f)),`<cite ${l.map(f=>`${f}='${c[f]}'`).join(" ")} />`};return e=e.replace(/<cite\b[\s\S]*?\/>/gm,p=>o(p)),e};export{W as a,G as b,mt as c,ht as d,yt as e,v as f,$ as g,P as h,j as i,U as j,A as k,Q as l,tt as m,et as n,nt as o,it as p,rt as q,st as r,at as s,R as t,B as u,ut as v,pt as w,ft as x};
@@ -0,0 +1 @@
1
+ 'use strict';function E(t){return new TextEncoder().encode(t)}function Z(t){let e=1732584193,i=4023233417,r=2562383102,n=271733878,o=3285377520,p=t.length,a=p*8,c=p+1+8,u=Math.ceil(c/64)*64,s=new ArrayBuffer(u),C=new Uint8Array(s),d=new DataView(s);C.set(t),C[p]=128,d.setUint32(u-8,Math.floor(a/4294967296),false),d.setUint32(u-4,a>>>0,false);let l=new Uint32Array(80);for(let x=0;x<u;x+=64){for(let g=0;g<16;g++)l[g]=d.getUint32(x+g*4,false);for(let g=16;g<80;g++){let I=l[g-3]^l[g-8]^l[g-14]^l[g-16];l[g]=I<<1|I>>>31;}let f=e,h=i,_=r,k=n,S=o;for(let g=0;g<80;g++){let I,m;g<20?(I=h&_|~h&k,m=1518500249):g<40?(I=h^_^k,m=1859775393):g<60?(I=h&_|h&k|_&k,m=2400959708):(I=h^_^k,m=3395469782);let b=(f<<5|f>>>27)+I+S+m+l[g]>>>0;S=k,k=_,_=(h<<30|h>>>2)>>>0,h=f,f=b;}e=e+f>>>0,i=i+h>>>0,r=r+_>>>0,n=n+k>>>0,o=o+S>>>0;}let y=x=>x.toString(16).padStart(8,"0");return y(e)+y(i)+y(r)+y(n)+y(o)}function P(t){try{if(!t)return "";let e=typeof t=="string"?t:JSON.stringify(t);return Z(E(e))}catch(e){console.error("Error in making the hash:",e);}return ""}function j(...t){return t.filter(Boolean).join(" ")}function U(t){return t.type==="url"||typeof t.url=="string"&&t.url.length>0}function A(t){let e=t.pageNumber||v(t.startPageKey),i=[t.attachmentId||"",e?.toString()||"",t.fullPhrase||"",t.keySpan?.toString()||"",t.lineIds?.join(",")||"",t.timestamps?.startTime||"",t.timestamps?.endTime||""];return U(t)&&i.push(t.url||"",t.title||"",t.domain||""),P(i.join("|")).slice(0,16)}function Q(t){let e=[t.attachmentId||"",t.label||"",t.verifiedFullPhrase||"",t.verifiedKeySpan||"",t.verifiedLineIds?.join(",")||"",t.verifiedPageNumber?.toString()||"",t.verifiedTimestamps?.startTime||"",t.verifiedTimestamps?.endTime||"",t.verifiedMatchSnippet||"",t.hitIndexWithinPage?.toString()||""];return P(e.join("|")).slice(0,16)}function tt(t){let e=Math.random().toString(36).slice(2,11);return `${t}-${e}`}function et(t,e={}){let{fallbackDisplay:i}=e;return t.keySpan?.toString()||t.citationNumber?.toString()||i||"1"}function nt(t){return t.citationNumber?.toString()||"1"}function it(t){return t.keySpan?.toString()||""}function rt(...t){return t.filter(Boolean).join(" ")}var st=4,at=1;function D(t){if(!t)return;let e=[],i=t.split(",");for(let r of i){let n=r.trim();if(n)if(n.includes("-")){let[o,p]=n.split("-"),a=parseInt(o,10),c=parseInt(p,10);if(!isNaN(a)&&!isNaN(c)&&a<=c)for(let u=a;u<=c;u++)e.push(u);else isNaN(a)||e.push(a);}else {let o=parseInt(n,10);isNaN(o)||e.push(o);}}if(e.length!==0)return [...new Set(e)].sort((r,n)=>r-n)}function R(t){let e=t?.status,i=e==="not_found",r=e==="found_phrase_missed_value",n=e==="found_key_span_only",o=e==="partial_text_found"||e==="found_on_other_page"||e==="found_on_other_line"||e==="first_word_found";return {isVerified:e==="found"||n||o||r,isMiss:i,isPartialMatch:o,isPending:e==="pending"||e==="loading"||!e}}var B=(t,e,i,r)=>{let n=m=>m?m.replace(/^['"]|['"]$/g,"").replace(/\\'/g,"'"):void 0,o=i?.current?i.current++:void 0,p=t.substring(0,t.indexOf("<cite")),a=t.includes("/>")?t.slice(t.indexOf("/>")+2):"",c=t.substring(t.indexOf("<cite"),t.indexOf("/>")+2),u=(m,b)=>{for(let O of b){let L=new RegExp(`${O}='((?:[^'\\\\]|\\\\.)*)'`),K=m.match(L);if(K)return K[1]}},s=u(c,["attachment_id","attachmentId","file_id","fileId"]),C=s?.length===20?s:e||s,d=u(c,["start_page_key","startPageKey","start_page"]),l,y;if(d){let m=d.match(/page[\_a-zA-Z]*(\d+)_index_(\d+)/);m&&(l=parseInt(m[1]),y=parseInt(m[2]));}let x=n(u(c,["full_phrase","fullPhrase"])),f=n(u(c,["key_span","keySpan"])),h=n(u(c,["reasoning"])),_=n(u(c,["value"])),k;try{let b=u(c,["line_ids","lineIds"])?.replace(/[A-Za-z_[\](){}:]/g,"");k=b?D(b):void 0;}catch(m){r&&console.error("Error parsing lineIds",m);}let S=u(c,["timestamps"]),g;if(S){let[m,b]=S.split("-")||[];g={startTime:m,endTime:b};}let I={attachmentId:C,pageNumber:l,startPageKey:`page_number_${l||1}_index_${y||0}`,fullPhrase:x,keySpan:f||_,citationNumber:o,lineIds:k,beforeCite:p,timestamps:g,reasoning:h};return {beforeCite:p,afterCite:a,citation:I}},J=(t,e)=>{if(!t)return null;let i=t.fullPhrase??t.full_phrase,r=t.startPageKey??t.start_page_key,n=t.keySpan??t.key_span,o=t.lineIds??t.line_ids,p=t.attachmentId??t.attachment_id??t.fileId??t.file_id,a=t.reasoning,c=t.value;if(!i)return null;let u;if(r){let d=r.match(/page[_a-zA-Z]*(\d+)_index_(\d+)/i);if(d)u=parseInt(d[1],10);else {let l=r.match(/^(\d+)_(\d+)$/);l&&(u=parseInt(l[1],10));}}let s=o?.length?[...o].sort((d,l)=>d-l):void 0;return {attachmentId:p,pageNumber:u,fullPhrase:i,citationNumber:e,lineIds:s,keySpan:n||c,reasoning:a}},V=t=>typeof t=="object"&&t!==null&&("fullPhrase"in t||"full_phrase"in t||"startPageKey"in t||"start_page_key"in t||"keySpan"in t||"key_span"in t||"lineIds"in t||"line_ids"in t),N=t=>Array.isArray(t)?t.length>0&&t.some(V):typeof t=="object"&&t!==null?V(t):false,T=t=>{let e={},i=Array.isArray(t)?t:[t],r=1;for(let n of i){let o=J(n,r++);if(o&&o.fullPhrase){let p=A(o);e[p]=o;}}return e},w=(t,e)=>{if(!(!t||typeof t!="object")){if(t.citation&&N(t.citation)){let i=Array.isArray(t.citation)?t.citation:[t.citation];e.push(...i);}if(t.citations&&N(t.citations)){let i=Array.isArray(t.citations)?t.citations:[t.citations];e.push(...i);}if(Array.isArray(t))for(let i of t)w(i,e);else for(let i of Object.keys(t))i!=="citation"&&i!=="citations"&&w(t[i],e);}},M=t=>{let e=$(t),i=/<cite\s+[^>]*\/>/g,r=e.match(i);if(!r||r.length===0)return {};let n={},o={current:1};for(let p of r){let{citation:a}=B(p,void 0,o);if(a&&a.fullPhrase){let c=A(a);n[c]=a;}}return n},ut=t=>{if(!t)return {};let e={};if(typeof t=="object"){if(N(t)){let n=T(t);Object.assign(e,n);}else {let n=[];if(w(t,n),n.length>0){let o=T(n);Object.assign(e,o);}}let i=JSON.stringify(t),r=M(i);Object.assign(e,r);}else if(typeof t=="string"){let i=M(t);Object.assign(e,i);}return e};function pt(t){let e=new Map,i=Array.isArray(t)?t.map((r,n)=>[A(r)||String(n+1),r]):Object.entries(t);for(let[r,n]of i){let o=n.attachmentId||"";e.has(o)||e.set(o,{}),e.get(o)[r]=n;}return e}function ft(t){let e={},i=Array.isArray(t)?t.map((r,n)=>[A(r)||String(n+1),r]):Object.entries(t);for(let[r,n]of i){let o=n.attachmentId||"";e[o]||(e[o]={}),e[o][r]=n;}return e}var F=t=>{let e={},i=/([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*(['"])((?:[^'"\\]|\\.)*)\2/g,r;for(;(r=i.exec(t))!==null;){let n=r[1].toLowerCase().replace(/([a-z])([A-Z])/g,"$1_$2").toLowerCase(),o=r[3],p=n==="fileid"||n==="file_id"||n==="attachmentid"?"attachment_id":n==="keyspan"?"key_span":n==="fullphrase"?"full_phrase":n==="lineids"?"line_ids":n==="startpagekey"||n==="start_pagekey"?"start_page_key":n;e[p]=o;}return e},W=t=>{if(!t)return "\u25CC";let e=R(t);return e.isPending?"\u25CC":e.isMiss?"\u2717":e.isPartialMatch?"\u26A0":e.isVerified?"\u2713":"\u25CC"},H=W,G=(t,e={})=>{let{leaveKeySpanBehind:i=false,verifications:r,showVerificationStatus:n=false}=e,o=0,p=/<cite\s+[^>]*?\/>/g;return t.replace(p,a=>{o++;let c=F(a),u="";if(i&&c.key_span&&(u=c.key_span.replace(/\\'/g,"'").replace(/\\"/g,'"')),n&&r){let s,C=String(o);if(s=r[C],!s&&c.attachment_id){for(let[,l]of Object.entries(r))if(l.attachmentId===c.attachment_id){s=l;break}}let d=H(s);u=u?`${u}${d}`:d;}return u})},mt=(t,e)=>G(t,{leaveKeySpanBehind:e}),ht=t=>t.replace(/<page_number_\d+_index_\d+>/g,"").replace(/<\/page_number_\d+_index_\d+>/g,"").trim(),yt=t=>{let e=/<line id="[^"]*">|<\/line>/g;return t.replace(e,"")},v=t=>{if(!t)return null;let e=t.match(/\d+/)?.[0];return e?parseInt(e):null},$=t=>{let e=t?.trim()||"",i=e.split(/(<cite[\s\S]*?(?:\/>|<\/cite>))/gm);return i.length<=1?z(e):(e=i.map(r=>r.startsWith("<cite")?z(r):r).join(""),e)},z=t=>{let e=t;e=e.replace(/\\_/g,"_"),e=e.replace(/><\/cite>/g,"/>");let i=p=>{let a=p.toLowerCase();return a==="fullphrase"||a==="full_phrase"?"full_phrase":a==="lineids"||a==="line_ids"?"line_ids":a==="startpagekey"||a==="start_pagekey"||a==="start_page_key"?"start_page_key":a==="fileid"||a==="file_id"||a==="attachmentid"||a==="attachment_id"?"attachment_id":a==="keyspan"||a==="key_span"?"key_span":a==="reasoning"||a==="value"?a:a==="timestamps"||a==="timestamp"||a==="timestamps"?"timestamps":a},r=p=>p.replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&"),n=/(fullPhrase|full_phrase|keySpan|key_span|reasoning|value)\s*=\s*(['"])([\s\S]*?)(?=\s+(?:line_ids|lineIds|timestamps|fileId|file_id|attachmentId|attachment_id|start_page_key|start_pageKey|startPageKey|keySpan|key_span|reasoning|value|full_phrase)|\s*\/?>)/gm;e=e.replace(n,(p,a,c,u)=>{let s=u;return s.endsWith(c)&&(s=s.slice(0,-1)),s=s.replace(/(\r?\n)+/g," "),s=r(s),s=s.replace(/(\*|_){2,}/g,""),s=s.replace(/\\\\'/g,"'"),s=s.replace(/\\'/g,"'"),s=s.replace(/'/g,"\\'"),s=s.replace(/\\\\"/g,'"'),s=s.replace(/\\"/g,'"'),s=s.replace(/"/g,'\\"'),s=s.replace(/\*/g,""),`${i(a)}='${s}'`}),e=e.replace(/(line_ids|lineIds|timestamps)=['"]?([\[\]\(\){}A-Za-z0-9_\-, ]+)['"]?(\s*\/?>|\s+)/gm,(p,a,c,u)=>{let s=c.replace(/[A-Za-z\[\]\(\){}]/g,"");return s=s.replace(/(\d+)-(\d+)/g,(C,d,l)=>{let y=parseInt(d,10),x=parseInt(l,10),f=[];if(y<=x)for(let h=y;h<=x;h++)f.push(h);else f.push(y);return f.join(",")}),s=s.replace(/,+/g,",").replace(/^,|,$/g,""),`${i(a)}='${s}'${u}`});let o=p=>{let a=/([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(['"])((?:[^'"\\\n]|\\.)*)(?:\2)/g,c={},u;for(;u=a.exec(p);){let f=u[1],h=u[3],_=i(f);c[_]=h;}let s=Object.keys(c);if(s.length===0)return p;let C=typeof c.timestamps=="string"&&c.timestamps.length>0,d=s.filter(f=>f.startsWith("start_page")),l=[];c.attachment_id&&l.push("attachment_id"),C?(c.full_phrase&&l.push("full_phrase"),c.key_span&&l.push("key_span"),l.push("timestamps")):(d.includes("start_page_key")&&l.push("start_page_key"),d.filter(f=>f!=="start_page_key").sort().forEach(f=>l.push(f)),c.full_phrase&&l.push("full_phrase"),c.key_span&&l.push("key_span"),c.line_ids&&l.push("line_ids")),c.reasoning&&l.push("reasoning"),c.value&&l.push("value");let y=new Set(l);return s.filter(f=>!y.has(f)).sort().forEach(f=>l.push(f)),`<cite ${l.map(f=>`${f}='${c[f]}'`).join(" ")} />`};return e=e.replace(/<cite\b[\s\S]*?\/>/gm,p=>o(p)),e};exports.a=W;exports.b=G;exports.c=mt;exports.d=ht;exports.e=yt;exports.f=v;exports.g=$;exports.h=P;exports.i=j;exports.j=U;exports.k=A;exports.l=Q;exports.m=tt;exports.n=et;exports.o=nt;exports.p=it;exports.q=rt;exports.r=st;exports.s=at;exports.t=R;exports.u=B;exports.v=ut;exports.w=pt;exports.x=ft;
@@ -1,2 +1,2 @@
1
- 'use strict';var chunkSPCFZGGU_cjs=require('./chunk-SPCFZGGU.cjs'),chunkF2MMVEVC_cjs=require('./chunk-F2MMVEVC.cjs');var C="https://api.deepcitation.com";function F(p,t){if(typeof Buffer<"u"&&Buffer.isBuffer(p)){let e=Uint8Array.from(p);return {blob:new Blob([e]),name:t||"document"}}if(p instanceof Blob)return {blob:p,name:t||(p instanceof File?p.name:"document")};throw new Error("Invalid file type. Expected File, Blob, or Buffer.")}async function c(p,t){return (await p.json().catch(()=>({})))?.error?.message||`${t} failed with status ${p.status}`}var h=class{constructor(t){chunkF2MMVEVC_cjs.a(this,"apiKey");chunkF2MMVEVC_cjs.a(this,"apiUrl");if(!t.apiKey)throw new Error("DeepCitation API key is required. Get one at https://deepcitation.com/dashboard");this.apiKey=t.apiKey,this.apiUrl=t.apiUrl?.replace(/\/$/,"")||C;}async uploadFile(t,e){let{blob:l,name:a}=F(t,e?.filename),o=new FormData;o.append("file",l,a),e?.attachmentId&&o.append("attachmentId",e.attachmentId),e?.filename&&o.append("filename",e.filename);let i=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:o});if(!i.ok)throw new Error(await c(i,"Upload"));return await i.json()}async convertToPdf(t){let e=typeof t=="string"?{url:t}:t,{url:l,file:a,filename:o,attachmentId:i}=e;if(!l&&!a)throw new Error("Either url or file must be provided");let r;if(l)r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({url:l,filename:o,attachmentId:i})});else {let{blob:f,name:n}=F(a,o),s=new FormData;s.append("file",f,n),i&&s.append("attachmentId",i),o&&s.append("filename",o),r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:s});}if(!r.ok)throw new Error(await c(r,"Conversion"));return await r.json()}async prepareConvertedFile(t){let e=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({attachmentId:t.attachmentId})});if(!e.ok)throw new Error(await c(e,"Prepare"));return await e.json()}async prepareFiles(t){if(t.length===0)return {fileDataParts:[],deepTextPromptPortion:[]};let e=t.map(({file:i,filename:r,attachmentId:f})=>this.uploadFile(i,{filename:r,attachmentId:f}).then(n=>({result:n,filename:r}))),a=(await Promise.all(e)).map(({result:i,filename:r})=>({attachmentId:i.attachmentId,deepTextPromptPortion:i.deepTextPromptPortion,filename:r||i.metadata?.filename})),o=a.map(i=>i.deepTextPromptPortion);return {fileDataParts:a,deepTextPromptPortion:o}}async verifyAttachment(t,e,l){let a={};if(Array.isArray(e))for(let n of e){let s=chunkSPCFZGGU_cjs.j(n);a[s]=n;}else if(typeof e=="object"&&e!==null)if("fullPhrase"in e||"value"in e){let n=chunkSPCFZGGU_cjs.j(e);a[n]=e;}else Object.assign(a,e);else throw new Error("Invalid citations format");if(Object.keys(a).length===0)return {verifications:{}};let o=`${this.apiUrl}/verifyCitations`,i={data:{attachmentId:t,citations:a,outputImageFormat:l?.outputImageFormat||"avif"}},r=await fetch(o,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(!r.ok)throw new Error(await c(r,"Verification"));return await r.json()}async verify(t,e){let{llmOutput:l,outputImageFormat:a="avif"}=t;if(e||(e=chunkSPCFZGGU_cjs.u(l)),Object.keys(e).length===0)return {verifications:{}};let o=new Map;for(let[n,s]of Object.entries(e)){let m=s.attachmentId||"";o.has(m)||o.set(m,{}),o.get(m)[n]=s;}let i=[];for(let[n,s]of o)n&&i.push(this.verifyAttachment(n,s,{outputImageFormat:a}));let r=await Promise.all(i),f={};for(let n of r)Object.assign(f,n.verifications);return {verifications:f}}};
1
+ 'use strict';var chunkQDDCYCBV_cjs=require('./chunk-QDDCYCBV.cjs'),chunkF2MMVEVC_cjs=require('./chunk-F2MMVEVC.cjs');var C="https://api.deepcitation.com";function F(p,t){if(typeof Buffer<"u"&&Buffer.isBuffer(p)){let e=Uint8Array.from(p);return {blob:new Blob([e]),name:t||"document"}}if(p instanceof Blob)return {blob:p,name:t||(p instanceof File?p.name:"document")};throw new Error("Invalid file type. Expected File, Blob, or Buffer.")}async function c(p,t){return (await p.json().catch(()=>({})))?.error?.message||`${t} failed with status ${p.status}`}var h=class{constructor(t){chunkF2MMVEVC_cjs.a(this,"apiKey");chunkF2MMVEVC_cjs.a(this,"apiUrl");if(!t.apiKey)throw new Error("DeepCitation API key is required. Get one at https://deepcitation.com/dashboard");this.apiKey=t.apiKey,this.apiUrl=t.apiUrl?.replace(/\/$/,"")||C;}async uploadFile(t,e){let{blob:l,name:a}=F(t,e?.filename),o=new FormData;o.append("file",l,a),e?.attachmentId&&o.append("attachmentId",e.attachmentId),e?.filename&&o.append("filename",e.filename);let i=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:o});if(!i.ok)throw new Error(await c(i,"Upload"));return await i.json()}async convertToPdf(t){let e=typeof t=="string"?{url:t}:t,{url:l,file:a,filename:o,attachmentId:i}=e;if(!l&&!a)throw new Error("Either url or file must be provided");let r;if(l)r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({url:l,filename:o,attachmentId:i})});else {let{blob:f,name:n}=F(a,o),s=new FormData;s.append("file",f,n),i&&s.append("attachmentId",i),o&&s.append("filename",o),r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:s});}if(!r.ok)throw new Error(await c(r,"Conversion"));return await r.json()}async prepareConvertedFile(t){let e=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({attachmentId:t.attachmentId})});if(!e.ok)throw new Error(await c(e,"Prepare"));return await e.json()}async prepareFiles(t){if(t.length===0)return {fileDataParts:[],deepTextPromptPortion:[]};let e=t.map(({file:i,filename:r,attachmentId:f})=>this.uploadFile(i,{filename:r,attachmentId:f}).then(n=>({result:n,filename:r}))),a=(await Promise.all(e)).map(({result:i,filename:r})=>({attachmentId:i.attachmentId,deepTextPromptPortion:i.deepTextPromptPortion,filename:r||i.metadata?.filename})),o=a.map(i=>i.deepTextPromptPortion);return {fileDataParts:a,deepTextPromptPortion:o}}async verifyAttachment(t,e,l){let a={};if(Array.isArray(e))for(let n of e){let s=chunkQDDCYCBV_cjs.k(n);a[s]=n;}else if(typeof e=="object"&&e!==null)if("fullPhrase"in e||"value"in e){let n=chunkQDDCYCBV_cjs.k(e);a[n]=e;}else Object.assign(a,e);else throw new Error("Invalid citations format");if(Object.keys(a).length===0)return {verifications:{}};let o=`${this.apiUrl}/verifyCitations`,i={data:{attachmentId:t,citations:a,outputImageFormat:l?.outputImageFormat||"avif"}},r=await fetch(o,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(!r.ok)throw new Error(await c(r,"Verification"));return await r.json()}async verify(t,e){let{llmOutput:l,outputImageFormat:a="avif"}=t;if(e||(e=chunkQDDCYCBV_cjs.v(l)),Object.keys(e).length===0)return {verifications:{}};let o=new Map;for(let[n,s]of Object.entries(e)){let m=s.attachmentId||"";o.has(m)||o.set(m,{}),o.get(m)[n]=s;}let i=[];for(let[n,s]of o)n&&i.push(this.verifyAttachment(n,s,{outputImageFormat:a}));let r=await Promise.all(i),f={};for(let n of r)Object.assign(f,n.verifications);return {verifications:f}}};
2
2
  exports.a=h;
@@ -1,2 +1,2 @@
1
- import {j,u}from'./chunk-3PE4VRVE.js';import {a}from'./chunk-O2XFH626.js';var C="https://api.deepcitation.com";function F(p,t){if(typeof Buffer<"u"&&Buffer.isBuffer(p)){let e=Uint8Array.from(p);return {blob:new Blob([e]),name:t||"document"}}if(p instanceof Blob)return {blob:p,name:t||(p instanceof File?p.name:"document")};throw new Error("Invalid file type. Expected File, Blob, or Buffer.")}async function c(p,t){return (await p.json().catch(()=>({})))?.error?.message||`${t} failed with status ${p.status}`}var h=class{constructor(t){a(this,"apiKey");a(this,"apiUrl");if(!t.apiKey)throw new Error("DeepCitation API key is required. Get one at https://deepcitation.com/dashboard");this.apiKey=t.apiKey,this.apiUrl=t.apiUrl?.replace(/\/$/,"")||C;}async uploadFile(t,e){let{blob:l,name:a}=F(t,e?.filename),o=new FormData;o.append("file",l,a),e?.attachmentId&&o.append("attachmentId",e.attachmentId),e?.filename&&o.append("filename",e.filename);let i=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:o});if(!i.ok)throw new Error(await c(i,"Upload"));return await i.json()}async convertToPdf(t){let e=typeof t=="string"?{url:t}:t,{url:l,file:a,filename:o,attachmentId:i}=e;if(!l&&!a)throw new Error("Either url or file must be provided");let r;if(l)r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({url:l,filename:o,attachmentId:i})});else {let{blob:f,name:n}=F(a,o),s=new FormData;s.append("file",f,n),i&&s.append("attachmentId",i),o&&s.append("filename",o),r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:s});}if(!r.ok)throw new Error(await c(r,"Conversion"));return await r.json()}async prepareConvertedFile(t){let e=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({attachmentId:t.attachmentId})});if(!e.ok)throw new Error(await c(e,"Prepare"));return await e.json()}async prepareFiles(t){if(t.length===0)return {fileDataParts:[],deepTextPromptPortion:[]};let e=t.map(({file:i,filename:r,attachmentId:f})=>this.uploadFile(i,{filename:r,attachmentId:f}).then(n=>({result:n,filename:r}))),a=(await Promise.all(e)).map(({result:i,filename:r})=>({attachmentId:i.attachmentId,deepTextPromptPortion:i.deepTextPromptPortion,filename:r||i.metadata?.filename})),o=a.map(i=>i.deepTextPromptPortion);return {fileDataParts:a,deepTextPromptPortion:o}}async verifyAttachment(t,e,l){let a={};if(Array.isArray(e))for(let n of e){let s=j(n);a[s]=n;}else if(typeof e=="object"&&e!==null)if("fullPhrase"in e||"value"in e){let n=j(e);a[n]=e;}else Object.assign(a,e);else throw new Error("Invalid citations format");if(Object.keys(a).length===0)return {verifications:{}};let o=`${this.apiUrl}/verifyCitations`,i={data:{attachmentId:t,citations:a,outputImageFormat:l?.outputImageFormat||"avif"}},r=await fetch(o,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(!r.ok)throw new Error(await c(r,"Verification"));return await r.json()}async verify(t,e){let{llmOutput:l,outputImageFormat:a="avif"}=t;if(e||(e=u(l)),Object.keys(e).length===0)return {verifications:{}};let o=new Map;for(let[n,s]of Object.entries(e)){let m=s.attachmentId||"";o.has(m)||o.set(m,{}),o.get(m)[n]=s;}let i=[];for(let[n,s]of o)n&&i.push(this.verifyAttachment(n,s,{outputImageFormat:a}));let r=await Promise.all(i),f={};for(let n of r)Object.assign(f,n.verifications);return {verifications:f}}};
1
+ import {k,v}from'./chunk-OT5T6R53.js';import {a}from'./chunk-O2XFH626.js';var C="https://api.deepcitation.com";function F(p,t){if(typeof Buffer<"u"&&Buffer.isBuffer(p)){let e=Uint8Array.from(p);return {blob:new Blob([e]),name:t||"document"}}if(p instanceof Blob)return {blob:p,name:t||(p instanceof File?p.name:"document")};throw new Error("Invalid file type. Expected File, Blob, or Buffer.")}async function c(p,t){return (await p.json().catch(()=>({})))?.error?.message||`${t} failed with status ${p.status}`}var h=class{constructor(t){a(this,"apiKey");a(this,"apiUrl");if(!t.apiKey)throw new Error("DeepCitation API key is required. Get one at https://deepcitation.com/dashboard");this.apiKey=t.apiKey,this.apiUrl=t.apiUrl?.replace(/\/$/,"")||C;}async uploadFile(t,e){let{blob:l,name:a}=F(t,e?.filename),o=new FormData;o.append("file",l,a),e?.attachmentId&&o.append("attachmentId",e.attachmentId),e?.filename&&o.append("filename",e.filename);let i=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:o});if(!i.ok)throw new Error(await c(i,"Upload"));return await i.json()}async convertToPdf(t){let e=typeof t=="string"?{url:t}:t,{url:l,file:a,filename:o,attachmentId:i}=e;if(!l&&!a)throw new Error("Either url or file must be provided");let r;if(l)r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({url:l,filename:o,attachmentId:i})});else {let{blob:f,name:n}=F(a,o),s=new FormData;s.append("file",f,n),i&&s.append("attachmentId",i),o&&s.append("filename",o),r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:s});}if(!r.ok)throw new Error(await c(r,"Conversion"));return await r.json()}async prepareConvertedFile(t){let e=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({attachmentId:t.attachmentId})});if(!e.ok)throw new Error(await c(e,"Prepare"));return await e.json()}async prepareFiles(t){if(t.length===0)return {fileDataParts:[],deepTextPromptPortion:[]};let e=t.map(({file:i,filename:r,attachmentId:f})=>this.uploadFile(i,{filename:r,attachmentId:f}).then(n=>({result:n,filename:r}))),a=(await Promise.all(e)).map(({result:i,filename:r})=>({attachmentId:i.attachmentId,deepTextPromptPortion:i.deepTextPromptPortion,filename:r||i.metadata?.filename})),o=a.map(i=>i.deepTextPromptPortion);return {fileDataParts:a,deepTextPromptPortion:o}}async verifyAttachment(t,e,l){let a={};if(Array.isArray(e))for(let n of e){let s=k(n);a[s]=n;}else if(typeof e=="object"&&e!==null)if("fullPhrase"in e||"value"in e){let n=k(e);a[n]=e;}else Object.assign(a,e);else throw new Error("Invalid citations format");if(Object.keys(a).length===0)return {verifications:{}};let o=`${this.apiUrl}/verifyCitations`,i={data:{attachmentId:t,citations:a,outputImageFormat:l?.outputImageFormat||"avif"}},r=await fetch(o,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(!r.ok)throw new Error(await c(r,"Verification"));return await r.json()}async verify(t,e){let{llmOutput:l,outputImageFormat:a="avif"}=t;if(e||(e=v(l)),Object.keys(e).length===0)return {verifications:{}};let o=new Map;for(let[n,s]of Object.entries(e)){let m=s.attachmentId||"";o.has(m)||o.set(m,{}),o.get(m)[n]=s;}let i=[];for(let[n,s]of o)n&&i.push(this.verifyAttachment(n,s,{outputImageFormat:a}));let r=await Promise.all(i),f={};for(let n of r)Object.assign(f,n.verifications);return {verifications:f}}};
2
2
  export{h as a};
@@ -1 +1 @@
1
- 'use strict';var chunkCGNTWQHJ_cjs=require('../chunk-CGNTWQHJ.cjs');require('../chunk-SPCFZGGU.cjs'),require('../chunk-F2MMVEVC.cjs');Object.defineProperty(exports,"DeepCitation",{enumerable:true,get:function(){return chunkCGNTWQHJ_cjs.a}});
1
+ 'use strict';var chunkW5BUHPRT_cjs=require('../chunk-W5BUHPRT.cjs');require('../chunk-QDDCYCBV.cjs'),require('../chunk-F2MMVEVC.cjs');Object.defineProperty(exports,"DeepCitation",{enumerable:true,get:function(){return chunkW5BUHPRT_cjs.a}});
@@ -1 +1 @@
1
- export{a as DeepCitation}from'../chunk-XTD4YII6.js';import'../chunk-3PE4VRVE.js';import'../chunk-O2XFH626.js';
1
+ export{a as DeepCitation}from'../chunk-WIWLCVJK.js';import'../chunk-OT5T6R53.js';import'../chunk-O2XFH626.js';
package/lib/index.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunkCGNTWQHJ_cjs=require('./chunk-CGNTWQHJ.cjs'),chunk4G7LE6P4_cjs=require('./chunk-4G7LE6P4.cjs'),chunkCFXDRAJL_cjs=require('./chunk-CFXDRAJL.cjs'),chunkSPCFZGGU_cjs=require('./chunk-SPCFZGGU.cjs');require('./chunk-F2MMVEVC.cjs');var Y=t=>{if(!t)return false;let e=t.trim();if(e.length<64)return false;let a=e?.[0];for(let r=1;r<e.length;r++)if(e[r]!==a)return false;return true};function z(t){t=t.trim();let e=2,a=10,r=/[.?!](?=\s+|$)/g,c,n=[];for(;(c=r.exec(t))!==null;)n.push(c.index);if(n.length<2)return t;let m=n[n.length-1],l=n[n.length-2],o=t.substring(l+1,m+1),p=o.length;if(o.trim().slice(0,-1).length<a||p<=0||t.length<p*e)return t;let I=0,s=m+1;t.endsWith(o)&&(s=t.length);let f=-1;for(;;){let i=s-p;if(i<0)break;if(t.substring(i,s)===o)I++,f=i,s=i;else break}return I>=e?t.substring(0,f)+o:t}Object.defineProperty(exports,"DeepCitation",{enumerable:true,get:function(){return chunkCGNTWQHJ_cjs.a}});Object.defineProperty(exports,"AV_CITATION_MARKDOWN_SYNTAX_PROMPT",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.b}});Object.defineProperty(exports,"CITATION_AV_BASED_JSON_OUTPUT_FORMAT",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.h}});Object.defineProperty(exports,"CITATION_AV_REMINDER",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.d}});Object.defineProperty(exports,"CITATION_JSON_OUTPUT_FORMAT",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.g}});Object.defineProperty(exports,"CITATION_MARKDOWN_SYNTAX_PROMPT",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.a}});Object.defineProperty(exports,"CITATION_REMINDER",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.c}});Object.defineProperty(exports,"compressPromptIds",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.i}});Object.defineProperty(exports,"decompressPromptIds",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.j}});Object.defineProperty(exports,"wrapCitationPrompt",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.f}});Object.defineProperty(exports,"wrapSystemCitationPrompt",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.e}});Object.defineProperty(exports,"BLANK_VERIFICATION",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.d}});Object.defineProperty(exports,"DEFAULT_OUTPUT_IMAGE_FORMAT",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.a}});Object.defineProperty(exports,"NOT_FOUND_VERIFICATION_INDEX",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.b}});Object.defineProperty(exports,"PENDING_VERIFICATION_INDEX",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.c}});Object.defineProperty(exports,"CITATION_X_PADDING",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.q}});Object.defineProperty(exports,"CITATION_Y_PADDING",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.r}});Object.defineProperty(exports,"generateCitationInstanceId",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.l}});Object.defineProperty(exports,"generateCitationKey",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.j}});Object.defineProperty(exports,"generateVerificationKey",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.k}});Object.defineProperty(exports,"getAllCitationsFromLlmOutput",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.u}});Object.defineProperty(exports,"getCitationPageNumber",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.e}});Object.defineProperty(exports,"getCitationStatus",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.s}});Object.defineProperty(exports,"groupCitationsByAttachmentId",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.v}});Object.defineProperty(exports,"groupCitationsByAttachmentIdObject",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.w}});Object.defineProperty(exports,"normalizeCitations",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.f}});Object.defineProperty(exports,"parseCitation",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.t}});Object.defineProperty(exports,"removeCitations",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.b}});Object.defineProperty(exports,"removeLineIdMetadata",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.d}});Object.defineProperty(exports,"removePageNumberMetadata",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.c}});Object.defineProperty(exports,"replaceCitations",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.a}});Object.defineProperty(exports,"sha1Hash",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.g}});exports.cleanRepeatingLastSentence=z;exports.isGeminiGarbage=Y;
1
+ 'use strict';var chunkW5BUHPRT_cjs=require('./chunk-W5BUHPRT.cjs'),chunk4G7LE6P4_cjs=require('./chunk-4G7LE6P4.cjs'),chunkCFXDRAJL_cjs=require('./chunk-CFXDRAJL.cjs'),chunkQDDCYCBV_cjs=require('./chunk-QDDCYCBV.cjs');require('./chunk-F2MMVEVC.cjs');var z=t=>{if(!t)return false;let e=t.trim();if(e.length<64)return false;let a=e?.[0];for(let r=1;r<e.length;r++)if(e[r]!==a)return false;return true};function J(t){t=t.trim();let e=2,a=10,r=/[.?!](?=\s+|$)/g,c,n=[];for(;(c=r.exec(t))!==null;)n.push(c.index);if(n.length<2)return t;let I=n[n.length-1],T=n[n.length-2],o=t.substring(T+1,I+1),p=o.length;if(o.trim().slice(0,-1).length<a||p<=0||t.length<p*e)return t;let m=0,s=I+1;t.endsWith(o)&&(s=t.length);let f=-1;for(;;){let i=s-p;if(i<0)break;if(t.substring(i,s)===o)m++,f=i,s=i;else break}return m>=e?t.substring(0,f)+o:t}Object.defineProperty(exports,"DeepCitation",{enumerable:true,get:function(){return chunkW5BUHPRT_cjs.a}});Object.defineProperty(exports,"AV_CITATION_MARKDOWN_SYNTAX_PROMPT",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.b}});Object.defineProperty(exports,"CITATION_AV_BASED_JSON_OUTPUT_FORMAT",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.h}});Object.defineProperty(exports,"CITATION_AV_REMINDER",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.d}});Object.defineProperty(exports,"CITATION_JSON_OUTPUT_FORMAT",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.g}});Object.defineProperty(exports,"CITATION_MARKDOWN_SYNTAX_PROMPT",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.a}});Object.defineProperty(exports,"CITATION_REMINDER",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.c}});Object.defineProperty(exports,"compressPromptIds",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.i}});Object.defineProperty(exports,"decompressPromptIds",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.j}});Object.defineProperty(exports,"wrapCitationPrompt",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.f}});Object.defineProperty(exports,"wrapSystemCitationPrompt",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.e}});Object.defineProperty(exports,"BLANK_VERIFICATION",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.d}});Object.defineProperty(exports,"DEFAULT_OUTPUT_IMAGE_FORMAT",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.a}});Object.defineProperty(exports,"NOT_FOUND_VERIFICATION_INDEX",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.b}});Object.defineProperty(exports,"PENDING_VERIFICATION_INDEX",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.c}});Object.defineProperty(exports,"CITATION_X_PADDING",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.r}});Object.defineProperty(exports,"CITATION_Y_PADDING",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.s}});Object.defineProperty(exports,"generateCitationInstanceId",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.m}});Object.defineProperty(exports,"generateCitationKey",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.k}});Object.defineProperty(exports,"generateVerificationKey",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.l}});Object.defineProperty(exports,"getAllCitationsFromLlmOutput",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.v}});Object.defineProperty(exports,"getCitationPageNumber",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.f}});Object.defineProperty(exports,"getCitationStatus",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.t}});Object.defineProperty(exports,"getVerificationTextIndicator",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.a}});Object.defineProperty(exports,"groupCitationsByAttachmentId",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.w}});Object.defineProperty(exports,"groupCitationsByAttachmentIdObject",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.x}});Object.defineProperty(exports,"normalizeCitations",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.g}});Object.defineProperty(exports,"parseCitation",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.u}});Object.defineProperty(exports,"removeCitations",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.c}});Object.defineProperty(exports,"removeLineIdMetadata",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.e}});Object.defineProperty(exports,"removePageNumberMetadata",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.d}});Object.defineProperty(exports,"replaceCitations",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.b}});Object.defineProperty(exports,"sha1Hash",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.h}});exports.cleanRepeatingLastSentence=J;exports.isGeminiGarbage=z;
package/lib/index.d.cts CHANGED
@@ -100,6 +100,14 @@ interface ReplaceCitationsOptions {
100
100
  */
101
101
  showVerificationStatus?: boolean;
102
102
  }
103
+ /**
104
+ * Get verification status indicator character for plain text/terminal output.
105
+ * Returns: ✓ (verified), ⚠ (partial), ✗ (not found), ◌ (pending)
106
+ *
107
+ * For web UI, use the React CitationComponent instead which provides
108
+ * proper styled indicators with colors and accessibility.
109
+ */
110
+ declare const getVerificationTextIndicator: (verification: Verification | null | undefined) => string;
103
111
  /**
104
112
  * Replaces citation tags in markdown text with optional replacement content.
105
113
  *
@@ -148,4 +156,4 @@ declare function cleanRepeatingLastSentence(text: string): string;
148
156
  */
149
157
  declare function sha1Hash(data: string | any): string;
150
158
 
151
- export { Citation, CitationStatus, type ReplaceCitationsOptions, Verification, cleanRepeatingLastSentence, getAllCitationsFromLlmOutput, getCitationPageNumber, getCitationStatus, groupCitationsByAttachmentId, groupCitationsByAttachmentIdObject, isGeminiGarbage, normalizeCitations, parseCitation, removeCitations, removeLineIdMetadata, removePageNumberMetadata, replaceCitations, sha1Hash };
159
+ export { Citation, CitationStatus, type ReplaceCitationsOptions, Verification, cleanRepeatingLastSentence, getAllCitationsFromLlmOutput, getCitationPageNumber, getCitationStatus, getVerificationTextIndicator, groupCitationsByAttachmentId, groupCitationsByAttachmentIdObject, isGeminiGarbage, normalizeCitations, parseCitation, removeCitations, removeLineIdMetadata, removePageNumberMetadata, replaceCitations, sha1Hash };
package/lib/index.d.ts CHANGED
@@ -100,6 +100,14 @@ interface ReplaceCitationsOptions {
100
100
  */
101
101
  showVerificationStatus?: boolean;
102
102
  }
103
+ /**
104
+ * Get verification status indicator character for plain text/terminal output.
105
+ * Returns: ✓ (verified), ⚠ (partial), ✗ (not found), ◌ (pending)
106
+ *
107
+ * For web UI, use the React CitationComponent instead which provides
108
+ * proper styled indicators with colors and accessibility.
109
+ */
110
+ declare const getVerificationTextIndicator: (verification: Verification | null | undefined) => string;
103
111
  /**
104
112
  * Replaces citation tags in markdown text with optional replacement content.
105
113
  *
@@ -148,4 +156,4 @@ declare function cleanRepeatingLastSentence(text: string): string;
148
156
  */
149
157
  declare function sha1Hash(data: string | any): string;
150
158
 
151
- export { Citation, CitationStatus, type ReplaceCitationsOptions, Verification, cleanRepeatingLastSentence, getAllCitationsFromLlmOutput, getCitationPageNumber, getCitationStatus, groupCitationsByAttachmentId, groupCitationsByAttachmentIdObject, isGeminiGarbage, normalizeCitations, parseCitation, removeCitations, removeLineIdMetadata, removePageNumberMetadata, replaceCitations, sha1Hash };
159
+ export { Citation, CitationStatus, type ReplaceCitationsOptions, Verification, cleanRepeatingLastSentence, getAllCitationsFromLlmOutput, getCitationPageNumber, getCitationStatus, getVerificationTextIndicator, groupCitationsByAttachmentId, groupCitationsByAttachmentIdObject, isGeminiGarbage, normalizeCitations, parseCitation, removeCitations, removeLineIdMetadata, removePageNumberMetadata, replaceCitations, sha1Hash };
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- export{a as DeepCitation}from'./chunk-XTD4YII6.js';export{b as AV_CITATION_MARKDOWN_SYNTAX_PROMPT,h as CITATION_AV_BASED_JSON_OUTPUT_FORMAT,d as CITATION_AV_REMINDER,g as CITATION_JSON_OUTPUT_FORMAT,a as CITATION_MARKDOWN_SYNTAX_PROMPT,c as CITATION_REMINDER,i as compressPromptIds,j as decompressPromptIds,f as wrapCitationPrompt,e as wrapSystemCitationPrompt}from'./chunk-KSQJNKLA.js';export{d as BLANK_VERIFICATION,a as DEFAULT_OUTPUT_IMAGE_FORMAT,b as NOT_FOUND_VERIFICATION_INDEX,c as PENDING_VERIFICATION_INDEX}from'./chunk-RQPZSRID.js';export{q as CITATION_X_PADDING,r as CITATION_Y_PADDING,l as generateCitationInstanceId,j as generateCitationKey,k as generateVerificationKey,u as getAllCitationsFromLlmOutput,e as getCitationPageNumber,s as getCitationStatus,v as groupCitationsByAttachmentId,w as groupCitationsByAttachmentIdObject,f as normalizeCitations,t as parseCitation,b as removeCitations,d as removeLineIdMetadata,c as removePageNumberMetadata,a as replaceCitations,g as sha1Hash}from'./chunk-3PE4VRVE.js';import'./chunk-O2XFH626.js';var Y=t=>{if(!t)return false;let e=t.trim();if(e.length<64)return false;let a=e?.[0];for(let r=1;r<e.length;r++)if(e[r]!==a)return false;return true};function z(t){t=t.trim();let e=2,a=10,r=/[.?!](?=\s+|$)/g,c,n=[];for(;(c=r.exec(t))!==null;)n.push(c.index);if(n.length<2)return t;let m=n[n.length-1],l=n[n.length-2],o=t.substring(l+1,m+1),p=o.length;if(o.trim().slice(0,-1).length<a||p<=0||t.length<p*e)return t;let I=0,s=m+1;t.endsWith(o)&&(s=t.length);let f=-1;for(;;){let i=s-p;if(i<0)break;if(t.substring(i,s)===o)I++,f=i,s=i;else break}return I>=e?t.substring(0,f)+o:t}export{z as cleanRepeatingLastSentence,Y as isGeminiGarbage};
1
+ export{a as DeepCitation}from'./chunk-WIWLCVJK.js';export{b as AV_CITATION_MARKDOWN_SYNTAX_PROMPT,h as CITATION_AV_BASED_JSON_OUTPUT_FORMAT,d as CITATION_AV_REMINDER,g as CITATION_JSON_OUTPUT_FORMAT,a as CITATION_MARKDOWN_SYNTAX_PROMPT,c as CITATION_REMINDER,i as compressPromptIds,j as decompressPromptIds,f as wrapCitationPrompt,e as wrapSystemCitationPrompt}from'./chunk-KSQJNKLA.js';export{d as BLANK_VERIFICATION,a as DEFAULT_OUTPUT_IMAGE_FORMAT,b as NOT_FOUND_VERIFICATION_INDEX,c as PENDING_VERIFICATION_INDEX}from'./chunk-RQPZSRID.js';export{r as CITATION_X_PADDING,s as CITATION_Y_PADDING,m as generateCitationInstanceId,k as generateCitationKey,l as generateVerificationKey,v as getAllCitationsFromLlmOutput,f as getCitationPageNumber,t as getCitationStatus,a as getVerificationTextIndicator,w as groupCitationsByAttachmentId,x as groupCitationsByAttachmentIdObject,g as normalizeCitations,u as parseCitation,c as removeCitations,e as removeLineIdMetadata,d as removePageNumberMetadata,b as replaceCitations,h as sha1Hash}from'./chunk-OT5T6R53.js';import'./chunk-O2XFH626.js';var z=t=>{if(!t)return false;let e=t.trim();if(e.length<64)return false;let a=e?.[0];for(let r=1;r<e.length;r++)if(e[r]!==a)return false;return true};function J(t){t=t.trim();let e=2,a=10,r=/[.?!](?=\s+|$)/g,c,n=[];for(;(c=r.exec(t))!==null;)n.push(c.index);if(n.length<2)return t;let I=n[n.length-1],T=n[n.length-2],o=t.substring(T+1,I+1),p=o.length;if(o.trim().slice(0,-1).length<a||p<=0||t.length<p*e)return t;let m=0,s=I+1;t.endsWith(o)&&(s=t.length);let f=-1;for(;;){let i=s-p;if(i<0)break;if(t.substring(i,s)===o)m++,f=i,s=i;else break}return m>=e?t.substring(0,f)+o:t}export{J as cleanRepeatingLastSentence,z as isGeminiGarbage};
@@ -1,5 +1,5 @@
1
- 'use strict';var chunkSPCFZGGU_cjs=require('../chunk-SPCFZGGU.cjs');require('../chunk-F2MMVEVC.cjs');var ze=require('react'),jsxRuntime=require('react/jsx-runtime'),reactDom=require('react-dom'),F=require('@radix-ui/react-popover');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var ze__namespace=/*#__PURE__*/_interopNamespace(ze);var F__namespace=/*#__PURE__*/_interopNamespace(F);function X(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e.replace(/^https?:\/\/(www\.)?/,"").split("/")[0]}}function Oe(e,t){return e.length<=t?e:e.slice(0,t-1)+"\u2026"}function _t(e){try{let t=new URL(e),r=t.pathname+t.search;return r==="/"?"":r}catch{return ""}}var Ge={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 Xe(e){return e.startsWith("blocked_")}function Ye(e){return e.startsWith("error_")}function Rt(e){return e==="verified"||e==="partial"||e==="accessible"||e==="redirected_valid"}function Bt(e){return e==="redirected"||e==="redirected_valid"}function Tt(e){return e==="verified"||e==="partial"||e==="redirected_valid"}var jt=({status:e,errorMessage:t})=>{let r=Ge[e];return jsxRuntime.jsx("span",{className:chunkSPCFZGGU_cjs.p("inline-flex items-center gap-1",r.className),title:t||r.label,"aria-label":r.label,children:jsxRuntime.jsx("span",{className:"text-[0.9em]","aria-hidden":"true",children:r.icon})})},we=({url:e,faviconUrl:t})=>{let r=X(e),n=t||`https://www.google.com/s2/favicons?domain=${r}&sz=16`;return jsxRuntime.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";}})},Ze=ze.forwardRef(({urlMeta:e,citation:t,children:r,className:n,variant:a="chip",showFullUrlOnHover:o=true,showFavicon:i=true,showTitle:d=false,maxDisplayLength:s=30,renderBlockedIndicator:c,onUrlClick:u,eventHandlers:l,preventTooltips:g=false},x)=>{let{url:m,domain:I,title:B,fetchStatus:h,faviconUrl:k,errorMessage:N}=e,S=ze.useMemo(()=>t||{value:m,fullPhrase:B||m},[t,m,B]),M=ze.useMemo(()=>chunkSPCFZGGU_cjs.j(S),[S]),T=ze.useMemo(()=>chunkSPCFZGGU_cjs.l(M),[M]),W=ze.useMemo(()=>I||X(m),[I,m]),A=ze.useMemo(()=>_t(m),[m]),C=ze.useMemo(()=>{if(d&&B)return Oe(B,s);let D=A?Oe(A,s-W.length-1):"";return D?`${W}${D}`:W},[d,B,W,A,s]),U=Ge[h],O=Xe(h),v=Ye(h),P=h==="verified",E=h==="partial",H=h==="pending",de=ze.useCallback(D=>{D.preventDefault(),D.stopPropagation(),u?u(m,D):window.open(m,"_blank","noopener,noreferrer"),l?.onClick?.(S,M,D);},[u,m,l,S,M]),ue=ze.useCallback(()=>{l?.onMouseEnter?.(S,M);},[l,S,M]),Q=ze.useCallback(()=>{l?.onMouseLeave?.(S,M);},[l,S,M]),$=()=>O||v?c?c(h,N):jsxRuntime.jsx(jt,{status:h,errorMessage:N}):P?jsxRuntime.jsx("span",{className:"text-[0.85em] text-green-600 dark:text-green-500","aria-hidden":"true",title:"Verified",children:"\u2713"}):E?jsxRuntime.jsx("span",{className:"text-[0.85em] text-amber-600 dark:text-amber-500","aria-hidden":"true",title:"Partial match",children:"~"}):H?jsxRuntime.jsx("span",{className:"opacity-70","aria-hidden":"true",children:"\u2026"}):null;return a==="chip"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[r,jsxRuntime.jsxs("span",{ref:x,"data-citation-id":M,"data-citation-instance":T,"data-url":m,"data-fetch-status":h,"data-variant":"chip",className:chunkSPCFZGGU_cjs.p("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",U.className,n),title:o?m:void 0,onMouseEnter:g?void 0:ue,onMouseLeave:g?void 0:Q,onMouseDown:de,onClick:D=>D.stopPropagation(),role:"link","aria-label":`Link to ${W}: ${U.label}`,children:[i&&jsxRuntime.jsx(we,{url:m,faviconUrl:k}),jsxRuntime.jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:C}),$()]})]}):a==="inline"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[r,jsxRuntime.jsxs("a",{ref:x,href:m,"data-citation-id":M,"data-citation-instance":T,"data-fetch-status":h,"data-variant":"inline",className:chunkSPCFZGGU_cjs.p("inline-flex items-center gap-1 cursor-pointer transition-colors no-underline border-b border-dotted border-current",U.className,n),title:o?m:void 0,onMouseEnter:g?void 0:ue,onMouseLeave:g?void 0:Q,onClick:D=>{D.preventDefault(),de(D);},target:"_blank",rel:"noopener noreferrer","aria-label":`Link to ${W}: ${U.label}`,children:[i&&jsxRuntime.jsx(we,{url:m,faviconUrl:k}),jsxRuntime.jsx("span",{children:C}),$()]})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[r,jsxRuntime.jsxs("span",{ref:x,"data-citation-id":M,"data-citation-instance":T,"data-url":m,"data-fetch-status":h,"data-variant":"bracket",className:chunkSPCFZGGU_cjs.p("cursor-pointer transition-colors",U.className,n),title:o?m:void 0,onMouseEnter:g?void 0:ue,onMouseLeave:g?void 0:Q,onMouseDown:de,onClick:D=>D.stopPropagation(),role:"link","aria-label":`Link to ${W}: ${U.label}`,children:["[",i&&jsxRuntime.jsx(we,{url:m,faviconUrl:k}),jsxRuntime.jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:C}),$(),"]"]})]})});Ze.displayName="UrlCitationComponent";ze.memo(Ze);var zt=({className:e})=>jsxRuntime.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:[jsxRuntime.jsx("path",{d:"M7 3 L3 3 L3 21 L7 21"}),jsxRuntime.jsx("path",{d:"M17 3 L21 3 L21 21 L17 21"})]}),re=({className:e})=>jsxRuntime.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:jsxRuntime.jsx("polyline",{points:"20 6 9 17 4 12"})}),ie=({className:e})=>jsxRuntime.jsx("svg",{className:e,viewBox:"0 0 256 256",fill:"currentColor","aria-hidden":"true",style:{width:"100%",height:"100%"},children:jsxRuntime.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"})}),se=({className:e})=>jsxRuntime.jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",style:{width:"100%",height:"100%"},children:[jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4",style:{opacity:.25}}),jsxRuntime.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}})]}),Vt=({className:e})=>jsxRuntime.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:[jsxRuntime.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"}),jsxRuntime.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"})]}),Ut=({className:e})=>jsxRuntime.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:[jsxRuntime.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),jsxRuntime.jsx("polyline",{points:"15 3 21 3 21 9"}),jsxRuntime.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]}),Wt=({className:e})=>jsxRuntime.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:[jsxRuntime.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsxRuntime.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]});function At(...e){return e.filter(Boolean).join(" ")}var Qe=F__namespace.Root,et=F__namespace.Trigger;var Pe=ze__namespace.forwardRef(({className:e,align:t="center",sideOffset:r=8,...n},a)=>jsxRuntime.jsx(F__namespace.Portal,{children:jsxRuntime.jsx(F__namespace.Content,{ref:a,align:t,sideOffset:r,className:At("z-[9998] rounded-lg border bg-white shadow-xl outline-none","w-fit max-w-[min(600px,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})}));Pe.displayName=F__namespace.Content.displayName;function ot(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=Ht(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}),it(u)}function Ht(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 $t(d,e,t)}function $t(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.unshift({value:t[a],count:1});i>0&&(a===u?(o--,n.unshift({value:r[o],added:true,count:1})):(a--,n.unshift({value:t[a],removed:true,count:1})));}return n}function it(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 tt(e){if(!e)return [];let t=[],r="";for(let n=0;n<e.length;n++){let a=e[n];r+=a,a===`
1
+ 'use strict';var chunkQDDCYCBV_cjs=require('../chunk-QDDCYCBV.cjs');require('../chunk-F2MMVEVC.cjs');var ze=require('react'),jsxRuntime=require('react/jsx-runtime'),reactDom=require('react-dom'),F=require('@radix-ui/react-popover');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var ze__namespace=/*#__PURE__*/_interopNamespace(ze);var F__namespace=/*#__PURE__*/_interopNamespace(F);function X(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e.replace(/^https?:\/\/(www\.)?/,"").split("/")[0]}}function Oe(e,t){return e.length<=t?e:e.slice(0,t-1)+"\u2026"}function _t(e){try{let t=new URL(e),r=t.pathname+t.search;return r==="/"?"":r}catch{return ""}}var Ge={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 Xe(e){return e.startsWith("blocked_")}function Ye(e){return e.startsWith("error_")}function Rt(e){return e==="verified"||e==="partial"||e==="accessible"||e==="redirected_valid"}function Bt(e){return e==="redirected"||e==="redirected_valid"}function Tt(e){return e==="verified"||e==="partial"||e==="redirected_valid"}var jt=({status:e,errorMessage:t})=>{let r=Ge[e];return jsxRuntime.jsx("span",{className:chunkQDDCYCBV_cjs.q("inline-flex items-center gap-1",r.className),title:t||r.label,"aria-label":r.label,children:jsxRuntime.jsx("span",{className:"text-[0.9em]","aria-hidden":"true",children:r.icon})})},we=({url:e,faviconUrl:t})=>{let r=X(e),n=t||`https://www.google.com/s2/favicons?domain=${r}&sz=16`;return jsxRuntime.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";}})},Ze=ze.forwardRef(({urlMeta:e,citation:t,children:r,className:n,variant:a="chip",showFullUrlOnHover:o=true,showFavicon:i=true,showTitle:d=false,maxDisplayLength:s=30,renderBlockedIndicator:c,onUrlClick:u,eventHandlers:l,preventTooltips:g=false},x)=>{let{url:m,domain:I,title:B,fetchStatus:h,faviconUrl:k,errorMessage:N}=e,S=ze.useMemo(()=>t||{value:m,fullPhrase:B||m},[t,m,B]),M=ze.useMemo(()=>chunkQDDCYCBV_cjs.k(S),[S]),T=ze.useMemo(()=>chunkQDDCYCBV_cjs.m(M),[M]),W=ze.useMemo(()=>I||X(m),[I,m]),A=ze.useMemo(()=>_t(m),[m]),C=ze.useMemo(()=>{if(d&&B)return Oe(B,s);let D=A?Oe(A,s-W.length-1):"";return D?`${W}${D}`:W},[d,B,W,A,s]),U=Ge[h],O=Xe(h),v=Ye(h),P=h==="verified",E=h==="partial",H=h==="pending",de=ze.useCallback(D=>{D.preventDefault(),D.stopPropagation(),u?u(m,D):window.open(m,"_blank","noopener,noreferrer"),l?.onClick?.(S,M,D);},[u,m,l,S,M]),ue=ze.useCallback(()=>{l?.onMouseEnter?.(S,M);},[l,S,M]),Q=ze.useCallback(()=>{l?.onMouseLeave?.(S,M);},[l,S,M]),$=()=>O||v?c?c(h,N):jsxRuntime.jsx(jt,{status:h,errorMessage:N}):P?jsxRuntime.jsx("span",{className:"text-[0.85em] text-green-600 dark:text-green-500","aria-hidden":"true",title:"Verified",children:"\u2713"}):E?jsxRuntime.jsx("span",{className:"text-[0.85em] text-amber-600 dark:text-amber-500","aria-hidden":"true",title:"Partial match",children:"~"}):H?jsxRuntime.jsx("span",{className:"opacity-70","aria-hidden":"true",children:"\u2026"}):null;return a==="chip"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[r,jsxRuntime.jsxs("span",{ref:x,"data-citation-id":M,"data-citation-instance":T,"data-url":m,"data-fetch-status":h,"data-variant":"chip",className:chunkQDDCYCBV_cjs.q("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",U.className,n),title:o?m:void 0,onMouseEnter:g?void 0:ue,onMouseLeave:g?void 0:Q,onMouseDown:de,onClick:D=>D.stopPropagation(),role:"link","aria-label":`Link to ${W}: ${U.label}`,children:[i&&jsxRuntime.jsx(we,{url:m,faviconUrl:k}),jsxRuntime.jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:C}),$()]})]}):a==="inline"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[r,jsxRuntime.jsxs("a",{ref:x,href:m,"data-citation-id":M,"data-citation-instance":T,"data-fetch-status":h,"data-variant":"inline",className:chunkQDDCYCBV_cjs.q("inline-flex items-center gap-1 cursor-pointer transition-colors no-underline border-b border-dotted border-current",U.className,n),title:o?m:void 0,onMouseEnter:g?void 0:ue,onMouseLeave:g?void 0:Q,onClick:D=>{D.preventDefault(),de(D);},target:"_blank",rel:"noopener noreferrer","aria-label":`Link to ${W}: ${U.label}`,children:[i&&jsxRuntime.jsx(we,{url:m,faviconUrl:k}),jsxRuntime.jsx("span",{children:C}),$()]})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[r,jsxRuntime.jsxs("span",{ref:x,"data-citation-id":M,"data-citation-instance":T,"data-url":m,"data-fetch-status":h,"data-variant":"bracket",className:chunkQDDCYCBV_cjs.q("cursor-pointer transition-colors",U.className,n),title:o?m:void 0,onMouseEnter:g?void 0:ue,onMouseLeave:g?void 0:Q,onMouseDown:de,onClick:D=>D.stopPropagation(),role:"link","aria-label":`Link to ${W}: ${U.label}`,children:["[",i&&jsxRuntime.jsx(we,{url:m,faviconUrl:k}),jsxRuntime.jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:C}),$(),"]"]})]})});Ze.displayName="UrlCitationComponent";ze.memo(Ze);var zt=({className:e})=>jsxRuntime.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:[jsxRuntime.jsx("path",{d:"M7 3 L3 3 L3 21 L7 21"}),jsxRuntime.jsx("path",{d:"M17 3 L21 3 L21 21 L17 21"})]}),re=({className:e})=>jsxRuntime.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:jsxRuntime.jsx("polyline",{points:"20 6 9 17 4 12"})}),ie=({className:e})=>jsxRuntime.jsx("svg",{className:e,viewBox:"0 0 256 256",fill:"currentColor","aria-hidden":"true",style:{width:"100%",height:"100%"},children:jsxRuntime.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"})}),se=({className:e})=>jsxRuntime.jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",style:{width:"100%",height:"100%"},children:[jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4",style:{opacity:.25}}),jsxRuntime.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}})]}),Vt=({className:e})=>jsxRuntime.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:[jsxRuntime.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"}),jsxRuntime.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"})]}),Ut=({className:e})=>jsxRuntime.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:[jsxRuntime.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),jsxRuntime.jsx("polyline",{points:"15 3 21 3 21 9"}),jsxRuntime.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]}),Wt=({className:e})=>jsxRuntime.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:[jsxRuntime.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsxRuntime.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]});function At(...e){return e.filter(Boolean).join(" ")}var Qe=F__namespace.Root,et=F__namespace.Trigger;var Pe=ze__namespace.forwardRef(({className:e,align:t="center",sideOffset:r=8,...n},a)=>jsxRuntime.jsx(F__namespace.Portal,{children:jsxRuntime.jsx(F__namespace.Content,{ref:a,align:t,sideOffset:r,className:At("z-[9998] rounded-lg border bg-white shadow-xl outline-none","w-fit max-w-[min(600px,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})}));Pe.displayName=F__namespace.Content.displayName;function ot(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=Ht(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}),it(u)}function Ht(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 $t(d,e,t)}function $t(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.unshift({value:t[a],count:1});i>0&&(a===u?(o--,n.unshift({value:r[o],added:true,count:1})):(a--,n.unshift({value:t[a],removed:true,count:1})));}return n}function it(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 tt(e){if(!e)return [];let t=[],r="";for(let n=0;n<e.length;n++){let a=e[n];r+=a,a===`
2
2
  `&&(t.push(r),r="");}return r.length>0&&t.push(r),t}var rt="a-zA-Z0-9_\\u00AD\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C6\\u02C8-\\u02D7\\u02DE-\\u02FF\\u1E00-\\u1EFF",Ft=new RegExp(`[${rt}]+|\\s+|[^${rt}]`,"gu");function at(e){return e?e.match(Ft)||[]:[]}function nt(e,t){let r=0;for(;r<e.length&&r<t.length&&e[r]===t[r];)r++;return e.slice(0,r)}function Se(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 Kt(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=nt(a.value,o.value).match(/^\s*/)?.[0]||"",s=a.value.slice(d.length),c=o.value.slice(d.length),l=Se(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=Se(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&&Se(s,i).length===i.length){t.push({value:n.value.slice(i.length),removed:true,count:1});continue}if(d&&c&&nt(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 it(t)}function st(e,t){let r=tt(e),n=tt(t);return ot(r,n)}function lt(e,t){let r=at(e),n=at(t),a=ot(r,n);return Kt(a)}var ct=(e="",t="")=>ze.useMemo(()=>{let r=(e||"").trim().replace(/\r\n/g,`
3
3
  `),n=(t||"").trim().replace(/\r\n/g,`
4
- `),a=st(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=lt(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]);function Zt(e){switch(e){case "chip":case "text":case "brackets":return "keySpan";case "source":return "source";default:return "number"}}function Jt(e){return e.replace(/^\[+\s*/,"").replace(/\s*\]+$/,"")}function qt(e,t,r){if(t==="indicator")return "";if(t==="keySpan"){let n=e.keySpan?.toString()||e.citationNumber?.toString()||r||"1";return Jt(n)}return t==="source"?e.siteName||e.domain||e.keySpan?.toString()||"Source":e.citationNumber?.toString()||"1"}function Qt(e){return e.isVerified&&!e.isPartialMatch?"Verified":e.isPartialMatch?"Partial Match":e.isMiss?"Not Found":e.isPending?"Verifying...":""}function er(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 tr({src:e,alt:t,onClose:r}){return ze.useEffect(()=>{let n=a=>{a.key==="Escape"&&r();};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)},[r]),reactDom.createPortal(jsxRuntime.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:jsxRuntime.jsx("div",{className:"relative max-w-[95vw] max-h-[95vh] cursor-zoom-out animate-in zoom-in-95 duration-[50ms]",children:jsxRuntime.jsx("img",{src:e,alt:t,className:"max-w-full max-h-[95vh] object-contain rounded-lg shadow-2xl",draggable:false})})}),document.body)}var rr=()=>jsxRuntime.jsx("span",{className:"inline-flex relative ml-0.5 size-2 text-green-600 dark:text-green-500","aria-hidden":"true",children:jsxRuntime.jsx(re,{})}),ar=()=>jsxRuntime.jsx("span",{className:"inline-flex relative ml-0.5 size-2 text-amber-600 dark:text-amber-500","aria-hidden":"true",children:jsxRuntime.jsx(re,{})}),nr=()=>jsxRuntime.jsx("span",{className:"inline-flex ml-1 size-2 animate-spin text-gray-400 dark:text-gray-500","aria-hidden":"true",children:jsxRuntime.jsx(se,{})}),or=()=>jsxRuntime.jsx("span",{className:"inline-flex relative ml-0.5 size-2 text-amber-500 dark:text-amber-400","aria-hidden":"true",children:jsxRuntime.jsx(ie,{})});function ir({citation:e,verification:t,isExpanded:r,onExpandChange:n}){let a=ze.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]=ze.useState(false),d=r??o,s=ze.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 jsxRuntime.jsxs("div",{className:"mt-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-gray-500 dark:text-gray-400 uppercase font-medium",children:[jsxRuntime.jsxs("span",{children:["Searched ",a.length," phrase",a.length!==1?"s":""]}),u>0&&!d&&jsxRuntime.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&&jsxRuntime.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"})]}),jsxRuntime.jsx("div",{className:"mt-1 space-y-1",children:a.slice(0,c).map((l,g)=>jsxRuntime.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 sr({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)return jsxRuntime.jsxs("div",{className:"p-2",children:[jsxRuntime.jsxs("button",{type:"button",className:"group block cursor-zoom-in relative",onClick:m=>{m.preventDefault(),m.stopPropagation(),n?.();},"aria-label":"Click to view full size",children:[jsxRuntime.jsx("img",{src:t.verificationImageBase64,alt:"Citation verification",className:"max-w-full h-auto object-contain rounded-md bg-gray-50 dark:bg-gray-800",loading:"lazy"}),jsxRuntime.jsx("span",{className:"absolute inset-0 flex items-center justify-center bg-black/0 group-hover:bg-black/5 dark:group-hover:bg-white/5 transition-colors rounded-md",children:jsxRuntime.jsx("span",{className:"opacity-0 group-hover:opacity-100 transition-opacity text-xs text-gray-600 dark:text-gray-300 bg-white/90 dark:bg-gray-800/90 px-2 py-1 rounded shadow-sm",children:"Click to expand"})})]}),(s||c)&&jsxRuntime.jsx(dt,{citation:e,verification:t,status:r})]});if(a||u){let m=e.fullPhrase||e.keySpan?.toString();return jsxRuntime.jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[200px] max-w-[400px]",children:[jsxRuntime.jsxs("span",{className:"text-xs font-medium text-gray-500 dark:text-gray-400",children:[jsxRuntime.jsx("span",{className:"inline-block relative top-[0.1em] mr-1.5 size-2 animate-spin",children:jsxRuntime.jsx(se,{})}),"Searching..."]}),m&&jsxRuntime.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:['"',m.length>80?m.slice(0,80)+"\u2026":m,'"']}),e.pageNumber&&e.pageNumber>0&&jsxRuntime.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Looking on page ",e.pageNumber]})]})}if(s)return jsxRuntime.jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[200px] max-w-[400px]",children:[jsxRuntime.jsxs("span",{className:"text-xs font-medium text-red-600 dark:text-red-500",children:[jsxRuntime.jsx("span",{className:"inline-block relative top-[0.1em] mr-1.5 size-3 text-amber-500 dark:text-amber-400",children:jsxRuntime.jsx(ie,{})}),"Not found: ",e.keySpan||e.fullPhrase]}),jsxRuntime.jsx(ir,{citation:e,verification:t,isExpanded:o,onExpandChange:i})]});let l=Qt(r),g=t?.verifiedMatchSnippet,x=t?.verifiedPageNumber;return !g&&!l?null:jsxRuntime.jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[180px] max-w-full",children:[l&&jsxRuntime.jsx("span",{className:chunkSPCFZGGU_cjs.h("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&&jsxRuntime.jsxs("span",{className:"text-sm text-gray-700 dark:text-gray-300 italic",children:['"',t.verifiedMatchSnippet,'"']}),x&&x>0&&jsxRuntime.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Page ",x]}),(s||c)&&jsxRuntime.jsx(dt,{citation:e,verification:t,status:r})]})}function dt({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}=ct(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,m=t?.verifiedPageNumber,I=x!=null&&m!=null&&x!==m;return n?jsxRuntime.jsxs("div",{className:"mt-2 pt-2 border-t border-gray-200 dark:border-gray-700 text-xs space-y-2",children:[o&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Expected"}),jsxRuntime.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})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Found"}),jsxRuntime.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,'"']})]})]}):jsxRuntime.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?jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Diff"}),jsxRuntime.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?jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("span",{className:"text-gray-500 dark:text-gray-400 text-[10px]",children:["Expected:"," "]}),jsxRuntime.jsx("span",{className:"text-red-600 dark:text-red-400 line-through opacity-70",children:o.length>100?o.slice(0,100)+"\u2026":o})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("span",{className:"text-gray-500 dark:text-gray-400 text-[10px]",children:["Found:"," "]}),jsxRuntime.jsx("span",{className:"text-green-600 dark:text-green-400",children:i.length>100?i.slice(0,100)+"\u2026":i})]})]}):d.map((B,h)=>jsxRuntime.jsx("span",{children:B.parts.map((k,N)=>{let S=`p-${h}-${N}`;return k.removed?jsxRuntime.jsx("span",{className:"bg-red-200 dark:bg-red-900/50 text-red-700 dark:text-red-300 line-through",title:"Expected text",children:k.value},S):k.added?jsxRuntime.jsx("span",{className:"bg-green-200 dark:bg-green-900/50 text-green-700 dark:text-green-300",title:"Actual text found",children:k.value},S):jsxRuntime.jsx("span",{children:k.value},S)})},`block-${h}`))})]}):o&&!s?jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Text"}),jsxRuntime.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,I&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Page"}),jsxRuntime.jsxs("p",{className:"mt-1 font-mono text-[11px] text-gray-700 dark:text-gray-300",children:[jsxRuntime.jsx("span",{className:"text-red-600 dark:text-red-400 line-through opacity-70",children:x})," \u2192 ",m]})]}),g&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Line"}),jsxRuntime.jsxs("p",{className:"mt-1 font-mono text-[11px] text-gray-700 dark:text-gray-300",children:[jsxRuntime.jsx("span",{className:"text-red-600 dark:text-red-400 line-through opacity-70",children:u?.join(", ")})," \u2192 ",l?.join(", ")]})]})]})}var Me=ze.forwardRef(({citation:e,children:t,className:r,fallbackDisplay:n,verification:a,isLoading:o=false,variant:i="brackets",content:d,eventHandlers:s,behaviorConfig:c,isMobile:u=false,renderIndicator:l,renderContent:g,popoverPosition:x="top",renderPopoverContent:m,additionalCount:I,faviconUrl:B},h)=>{let k=ze.useMemo(()=>d||Zt(i),[d,i]),[N,S]=ze.useState(false),[M,T]=ze.useState(null),[W,A]=ze.useState(false),C=ze.useMemo(()=>chunkSPCFZGGU_cjs.j(e),[e]),U=ze.useMemo(()=>chunkSPCFZGGU_cjs.l(C),[C]),O=ze.useMemo(()=>er(a),[a]),{isMiss:v,isPartialMatch:P,isVerified:E,isPending:H}=O,de=5e3,[ue,Q]=ze.useState(false),$=ze.useRef(null),D=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",z=(o||H)&&!D&&!ue;ze.useEffect(()=>($.current&&(clearTimeout($.current),$.current=null),(o||H)&&!D?(Q(false),$.current=setTimeout(()=>{Q(true);},de)):Q(false),()=>{$.current&&clearTimeout($.current);}),[o,H,D]);let G=ze.useMemo(()=>qt(e,k,n),[e,k,n]),J=ze.useCallback(()=>({citation:e,citationKey:C,verification:a??null,isTooltipExpanded:N,isImageExpanded:!!M,hasImage:!!a?.verificationImageBase64}),[e,C,a,N,M]),Ae=ze.useCallback(w=>{w.setImageExpanded!==void 0&&(typeof w.setImageExpanded=="string"?T(w.setImageExpanded):w.setImageExpanded===true&&a?.verificationImageBase64?T(a.verificationImageBase64):w.setImageExpanded===false&&T(null));},[a?.verificationImageBase64]),xt=ze.useCallback(w=>{w.preventDefault(),w.stopPropagation();let te=J();if(c?.onClick){let me=c.onClick(te,w);me&&typeof me=="object"&&Ae(me),s?.onClick?.(e,C,w);return}if(s?.onClick){s.onClick(e,C,w);return}a?.verificationImageBase64?T(a.verificationImageBase64):v&&A(me=>!me);},[c,s,e,C,a?.verificationImageBase64,v,J,Ae]),He=150,ee=ze.useRef(null),be=ze.useRef(false),q=ze.useCallback(()=>{ee.current&&(clearTimeout(ee.current),ee.current=null);},[]),ht=ze.useCallback(()=>{q(),S(true),c?.onHover?.onEnter&&c.onHover.onEnter(J()),s?.onMouseEnter?.(e,C);},[s,c,e,C,J,q]),yt=ze.useCallback(()=>{q(),ee.current=setTimeout(()=>{be.current||(S(false),c?.onHover?.onLeave&&c.onHover.onLeave(J()),s?.onMouseLeave?.(e,C));},He);},[s,c,e,C,J,q]),vt=ze.useCallback(()=>{q(),be.current=true;},[q]),bt=ze.useCallback(()=>{be.current=false,q(),ee.current=setTimeout(()=>{S(false),c?.onHover?.onLeave&&c.onHover.onLeave(J()),s?.onMouseLeave?.(e,C);},He);},[s,c,e,C,J,q]);ze.useEffect(()=>()=>{ee.current&&clearTimeout(ee.current);},[]);let kt=ze.useCallback(w=>{u&&(w.preventDefault(),w.stopPropagation(),s?.onTouchEnd?.(e,C,w));},[s,e,C,u]);if(n!=null&&k==="keySpan"&&v)return jsxRuntime.jsx("span",{className:chunkSPCFZGGU_cjs.h("text-gray-400 dark:text-gray-500",r),children:n});let ke=chunkSPCFZGGU_cjs.h((E||P)&&i==="brackets"&&"text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 hover:underline",v&&"opacity-70 line-through text-gray-400 dark:text-gray-500",z&&"text-gray-500 dark:text-gray-400"),ae=()=>l?l(O):z?jsxRuntime.jsx(nr,{}):E&&!P?jsxRuntime.jsx(rr,{}):P?jsxRuntime.jsx(ar,{}):v?jsxRuntime.jsx(or,{}):null,$e=()=>{if(g)return g({citation:e,status:O,citationKey:C,displayText:G,isMergedDisplay:k==="keySpan"});if(k==="indicator")return jsxRuntime.jsx("span",{children:ae()});if(i==="chip"){let w=chunkSPCFZGGU_cjs.h(E&&!P&&!z&&"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",P&&!z&&"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",v&&!z&&"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400 line-through",z&&"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400",!E&&!v&&!z&&"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400");return jsxRuntime.jsxs("span",{className:chunkSPCFZGGU_cjs.h("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-sm font-medium",w),children:[jsxRuntime.jsx("span",{className:"max-w-60 overflow-hidden text-ellipsis whitespace-nowrap",children:G}),ae()]})}if(i==="superscript"){let w=chunkSPCFZGGU_cjs.h(E&&!P&&!z&&"text-green-600 dark:text-green-500",P&&!z&&"text-amber-600 dark:text-amber-500",v&&!z&&"text-red-500 dark:text-red-400 line-through",z&&"text-gray-400 dark:text-gray-500",!E&&!v&&!z&&"text-blue-600 dark:text-blue-400");return jsxRuntime.jsxs("sup",{className:chunkSPCFZGGU_cjs.h("text-xs font-medium transition-colors hover:underline",w),children:["[",G,ae(),"]"]})}if(i==="text")return jsxRuntime.jsxs("span",{className:ke,children:[G,ae()]});if(i==="minimal")return jsxRuntime.jsxs("span",{className:chunkSPCFZGGU_cjs.h("max-w-80 overflow-hidden text-ellipsis",ke),children:[G,ae()]});if(i==="source"){let w=B||e.faviconUrl;return jsxRuntime.jsxs("span",{className:chunkSPCFZGGU_cjs.h("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:[w&&jsxRuntime.jsx("img",{src:w,alt:"",className:"w-4 h-4 rounded-sm object-contain",loading:"lazy",onError:te=>{te.target.style.display="none";}}),jsxRuntime.jsx("span",{className:"max-w-40 overflow-hidden text-ellipsis whitespace-nowrap",children:G}),I!==void 0&&I>0&&jsxRuntime.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:["+",I]})]})}return jsxRuntime.jsxs("span",{className:chunkSPCFZGGU_cjs.h("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:["[",jsxRuntime.jsxs("span",{className:chunkSPCFZGGU_cjs.h("max-w-80 overflow-hidden text-ellipsis",ke),children:[G,ae()]}),"]"]})},Ct=!(x==="hidden")&&(a&&(a.verificationImageBase64||a.verifiedMatchSnippet)||z||H||o||v),wt=!!a?.verificationImageBase64,Fe=M?jsxRuntime.jsx(tr,{src:M,alt:"Citation verification - full size",onClose:()=>T(null)}):null,Ke={"data-citation-id":C,"data-citation-instance":U,className:chunkSPCFZGGU_cjs.h("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",wt&&"cursor-zoom-in",r),onMouseEnter:ht,onMouseLeave:yt,onClick:xt,onTouchEndCapture:u?kt:void 0,"aria-label":G?`[${G}]`:void 0};if(Ct){let w=m?m({citation:e,verification:a??null,status:O}):jsxRuntime.jsx(sr,{citation:e,verification:a??null,status:O,isLoading:o||z,isPhrasesExpanded:W,onPhrasesExpandChange:A,onImageClick:()=>{a?.verificationImageBase64&&T(a.verificationImageBase64);}});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[t,jsxRuntime.jsxs(Qe,{open:N,children:[jsxRuntime.jsx(et,{asChild:true,children:jsxRuntime.jsx("span",{ref:h,...Ke,children:$e()})}),jsxRuntime.jsx(Pe,{side:x==="bottom"?"bottom":"top",onPointerDownOutside:te=>te.preventDefault(),onInteractOutside:te=>te.preventDefault(),onMouseEnter:vt,onMouseLeave:bt,children:w})]}),Fe]})}return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[t,jsxRuntime.jsx("span",{ref:h,...Ke,children:$e()}),Fe]})});Me.displayName="CitationComponent";var lr=ze.memo(Me);function pt(e,t){return t||`https://www.google.com/s2/favicons?domain=${X(e)}&sz=32`}function Re(e){if(!e.startsWith("http://")&&!e.startsWith("https://"))return "unknown";try{let t=X(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 Be(e,t){let r=(t||X(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 ur=()=>jsxRuntime.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:[jsxRuntime.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsxRuntime.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),mr=()=>jsxRuntime.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:jsxRuntime.jsx("polyline",{points:"9 18 15 12 9 6"})}),pr=()=>jsxRuntime.jsxs("svg",{className:"animate-spin",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[jsxRuntime.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsxRuntime.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=ze.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 m=ze.useCallback(N=>{s?s({id:e,url:t,title:r,domain:n,sourceType:a,faviconUrl:o,citationNumbers:i,verificationStatus:d},N):window.open(t,"_blank","noopener,noreferrer");},[s,e,t,r,n,a,o,i,d]),I=ze.useMemo(()=>Be(t,n),[t,n]),B=ze.useMemo(()=>pt(t,o),[t,o]),h=ze.useMemo(()=>a||Re(t),[a,t]),k=()=>{if(!u||!d)return null;let S={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 jsxRuntime.jsx("span",{className:chunkSPCFZGGU_cjs.p("text-sm ml-1",S.className),"aria-label":d,children:S.icon})};return jsxRuntime.jsxs("div",{ref:x,"data-source-id":e,"data-source-type":h,className:chunkSPCFZGGU_cjs.p("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:m,role:"link",tabIndex:0,onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.preventDefault(),m(N));},"aria-label":`${r} from ${I}`,children:[jsxRuntime.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}):jsxRuntime.jsx("img",{src:B,alt:"",className:"w-5 h-5 rounded",width:20,height:20,loading:"lazy",onError:N=>{N.target.style.display="none";}})}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsx("span",{className:"text-gray-900 dark:text-gray-100 font-medium text-sm leading-tight line-clamp-2",children:r}),k()]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 text-xs",children:I}),l&&i&&i.length>0&&jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[i.slice(0,3).map(N=>jsxRuntime.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:N},N)),i.length>3&&jsxRuntime.jsxs("span",{className:"text-xs text-gray-400",children:["+",i.length-3]})]})]})]}),jsxRuntime.jsx("div",{className:"flex-shrink-0 text-gray-400 dark:text-gray-500 mt-1",children:jsxRuntime.jsx(mr,{})})]})});ye.displayName="SourcesListItem";var Te=ze.forwardRef(({sources:e,maxIcons:t=3,onClick:r,label:n="Sources",className:a,isOpen:o},i)=>{let d=ze.useMemo(()=>e.slice(0,t),[e,t]),s=e.length>t;return jsxRuntime.jsxs("button",{ref:i,type:"button",onClick:r,className:chunkSPCFZGGU_cjs.p("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:[jsxRuntime.jsx("span",{className:"font-medium",children:n}),jsxRuntime.jsxs("div",{className:"flex items-center -space-x-1",children:[d.map((c,u)=>jsxRuntime.jsx("img",{src:pt(c.url,c.faviconUrl),alt:"",className:chunkSPCFZGGU_cjs.p("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&&jsxRuntime.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]})]})]})});Te.displayName="SourcesTrigger";var je=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:m,renderEmpty:I,renderLoading:B},h)=>{let k=ze.useRef(null),[N,S]=ze.useState(false);ze.useEffect(()=>{if(!r||t==="inline")return;let v=P=>{P.key==="Escape"&&n?.(false);};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[r,n,t]),ze.useEffect(()=>{S(true);},[]);let M=ze.useMemo(()=>{if(!x)return null;let v={};for(let P of e){let E=P.domain||X(P.url);v[E]||(v[E]=[]),v[E].push(P);}return v},[e,x]),T=ze.useCallback(()=>{n?.(false);},[n]),W=ze.useCallback(v=>{v.target===v.currentTarget&&T();},[T]),A=()=>{let{title:v="Sources",showCloseButton:P=true,showCount:E=true,renderHeader:H}=a;return H?H({title:v,count:e.length,onClose:T}):jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-200 dark:border-gray-700",children:[P&&t!=="inline"&&jsxRuntime.jsx("button",{type:"button",onClick:T,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:jsxRuntime.jsx(ur,{})}),jsxRuntime.jsxs("h2",{className:"text-base font-semibold text-gray-900 dark:text-gray-100 flex-1 text-center",children:[v,E&&jsxRuntime.jsxs("span",{className:"ml-2 text-sm font-normal text-gray-500 dark:text-gray-400",children:["(",e.length,")"]})]}),P&&t!=="inline"&&jsxRuntime.jsx("div",{className:"w-8"})]})},C=()=>o?B?B():jsxRuntime.jsxs("div",{className:"flex items-center justify-center py-8 text-gray-500 dark:text-gray-400",children:[jsxRuntime.jsx(pr,{}),jsxRuntime.jsx("span",{className:"ml-2 text-sm",children:"Loading sources..."})]}):e.length===0?I?I():jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-gray-500 dark:text-gray-400 text-sm",children:i}):x&&M?jsxRuntime.jsx("div",{className:c,children:Object.entries(M).map(([v,P])=>jsxRuntime.jsxs("div",{children:[jsxRuntime.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:Be(P[0].url,v)}),P.map((E,H)=>m?m(E,H):jsxRuntime.jsx(ye,{...E,onClick:u,showVerificationIndicator:l,showCitationBadges:g},E.id))]},v))}):jsxRuntime.jsx("div",{className:c,children:e.map((v,P)=>m?m(v,P):jsxRuntime.jsx(ye,{...v,onClick:u,showVerificationIndicator:l,showCitationBadges:g},v.id))}),U=d?{maxHeight:typeof d=="number"?`${d}px`:d}:void 0;if(t==="inline")return r?jsxRuntime.jsxs("div",{ref:h,className:chunkSPCFZGGU_cjs.p("bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700",s),style:U,children:[A(),jsxRuntime.jsx("div",{className:"overflow-y-auto",style:U,children:C()})]}):null;if(t==="panel")return r?jsxRuntime.jsxs("div",{ref:h,className:chunkSPCFZGGU_cjs.p("bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700 shadow-lg",s),children:[A(),jsxRuntime.jsx("div",{className:"overflow-y-auto",style:U||{maxHeight:"400px"},children:C()})]}):null;if(!N||!r)return null;let O=jsxRuntime.jsxs("div",{ref:h,className:chunkSPCFZGGU_cjs.p("fixed inset-0 z-50",t==="modal"&&"flex items-center justify-center"),role:"dialog","aria-modal":"true","aria-labelledby":"sources-title",children:[jsxRuntime.jsx("div",{className:chunkSPCFZGGU_cjs.p("absolute inset-0 bg-black/40 dark:bg-black/60 transition-opacity",r?"opacity-100":"opacity-0"),onClick:W,"aria-hidden":"true"}),t==="drawer"?jsxRuntime.jsxs("div",{ref:k,className:chunkSPCFZGGU_cjs.p("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:[jsxRuntime.jsx("div",{className:"flex justify-center py-2",children:jsxRuntime.jsx("div",{className:"w-10 h-1 bg-gray-300 dark:bg-gray-600 rounded-full"})}),A(),jsxRuntime.jsx("div",{className:"overflow-y-auto flex-1",children:C()})]}):jsxRuntime.jsxs("div",{ref:k,className:chunkSPCFZGGU_cjs.p("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(),jsxRuntime.jsx("div",{className:"overflow-y-auto flex-1",children:C()})]})]});return reactDom.createPortal(O,document.body)});je.displayName="SourcesListComponent";var gr=ze.memo(ye),fr=ze.memo(Te),xr=ze.memo(je);function hr(e){let t=new Map;for(let r of e){if(!r.url)continue;let n=r.domain||X(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||Re(r.url),faviconUrl:r.faviconUrl,citationNumbers:r.citationNumber?[r.citationNumber]:[]});}return Array.from(t.values())}function yr(e=[]){let[t,r]=ze.useState(e),[n,a]=ze.useState(false),o=ze.useCallback(s=>{r(c=>c.some(l=>l.url===s.url)?c:[...c,s]);},[]),i=ze.useCallback(s=>{r(c=>c.filter(u=>u.id!==s));},[]),d=ze.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 ft(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||Ue(a.url)||"Unknown Source",sourceDomain:a.domain||Ue(a.url),sourceFavicon:a.faviconUrl||void 0,citations:n,additionalCount:n.length-1}})}function Ue(e){if(e)try{return new URL(e).hostname.replace(/^www\./,"")}catch{return}}function br(e){let t=e?.status;return !t||t==="pending"||t==="loading"?{color:"text-gray-400",icon:jsxRuntime.jsx(se,{}),label:"Verifying"}:t==="not_found"?{color:"text-amber-500",icon:jsxRuntime.jsx(ie,{}),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:jsxRuntime.jsx(re,{}),label:"Partial match"}:{color:"text-green-500",icon:jsxRuntime.jsx(re,{}),label:"Verified"}}function We({item:e,isLast:t=false,onClick:r,onReadMore:n,className:a}){let{citation:o,verification:i}=e,d=br(i),s=o.siteName||o.domain||Ue(o.url)||"Source",c=o.title||o.keySpan||o.fullPhrase,u=o.description||i?.actualContentSnippet||i?.verifiedMatchSnippet,l=o.faviconUrl,g=ze.useCallback(()=>{r?.(e);},[e,r]),x=ze.useCallback(m=>{m.stopPropagation(),n?.(e);},[e,n]);return jsxRuntime.jsx("div",{className:chunkSPCFZGGU_cjs.h("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:m=>{(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),g());},children:jsxRuntime.jsxs("div",{className:"flex items-start gap-3",children:[jsxRuntime.jsx("div",{className:"flex-shrink-0 mt-0.5",children:l?jsxRuntime.jsx("img",{src:l,alt:"",className:"w-5 h-5 rounded object-contain",loading:"lazy",onError:m=>{m.target.style.display="none";}}):jsxRuntime.jsx("div",{className:"w-5 h-5 rounded bg-gray-200 dark:bg-gray-700 flex items-center justify-center",children:jsxRuntime.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:s.charAt(0).toUpperCase()})})}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5",children:[jsxRuntime.jsx("span",{className:"text-xs font-medium text-gray-500 dark:text-gray-400",children:s}),jsxRuntime.jsx("span",{className:chunkSPCFZGGU_cjs.h("inline-flex w-3 h-3",d.color,i?.status==="pending"||i?.status==="loading"?"animate-spin":""),title:d.label,children:d.icon})]}),c&&jsxRuntime.jsx("h4",{className:"mt-1 text-sm font-medium text-gray-900 dark:text-gray-100 line-clamp-2",children:c}),u&&jsxRuntime.jsxs("p",{className:"mt-1 text-sm text-gray-600 dark:text-gray-400 line-clamp-2",children:[u,n&&u.length>100&&jsxRuntime.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 kr({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]=ze.useState(false),x=ze.useMemo(()=>r.flatMap(h=>h.citations),[r]),m=ze.useMemo(()=>!a||l?x:x.slice(0,o),[x,a,l,o]),I=ze.useMemo(()=>!a||l?[]:x.slice(o),[x,a,l,o]);if(ze__namespace.default.useEffect(()=>{if(!e)return;let h=k=>{k.key==="Escape"&&t();};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[e,t]),!e)return null;let B=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/40 z-[9998] animate-in fade-in-0 duration-150",onClick:t,"aria-hidden":"true"}),jsxRuntime.jsxs("div",{className:chunkSPCFZGGU_cjs.h("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"&&jsxRuntime.jsx("div",{className:"flex justify-center pt-3 pb-1",children:jsxRuntime.jsx("div",{className:"w-10 h-1 rounded-full bg-gray-300 dark:bg-gray-600"})}),jsxRuntime.jsxs("div",{className:"px-4 py-3 border-b border-gray-200 dark:border-gray-700 flex items-center justify-between",children:[jsxRuntime.jsx("h2",{className:"text-base font-semibold text-gray-900 dark:text-gray-100",children:n}),jsxRuntime.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:jsxRuntime.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:jsxRuntime.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),jsxRuntime.jsx("div",{className:"overflow-y-auto max-h-[calc(80vh-100px)]",children:m.length===0?jsxRuntime.jsx("div",{className:"px-4 py-8 text-center text-gray-500 dark:text-gray-400",children:"No citations to display"}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[m.map((h,k)=>u?jsxRuntime.jsx(ze__namespace.default.Fragment,{children:u(h)},h.citationKey):jsxRuntime.jsx(We,{item:h,isLast:k===m.length-1&&I.length===0,onClick:i,onReadMore:d},h.citationKey)),I.length>0&&!l&&jsxRuntime.jsx("div",{className:"px-4 py-3 border-t border-gray-200 dark:border-gray-700",children:jsxRuntime.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 (",I.length,")"]})}),l&&I.map((h,k)=>u?jsxRuntime.jsx(ze__namespace.default.Fragment,{children:u(h)},h.citationKey):jsxRuntime.jsx(We,{item:h,isLast:k===I.length-1,onClick:i,onReadMore:d},h.citationKey))]})})]})]});return reactDom.createPortal(B,document.body)}function Cr(){let[e,t]=ze.useState(false),[r,n]=ze.useState([]),a=ze.useCallback(()=>t(true),[]),o=ze.useCallback(()=>t(false),[]),i=ze.useCallback(()=>t(g=>!g),[]),d=ze.useCallback(g=>{n(x=>x.some(m=>m.citationKey===g.citationKey)?x:[...x,g]);},[]),s=ze.useCallback(g=>{n(x=>x.filter(m=>m.citationKey!==g));},[]),c=ze.useCallback(()=>{n([]);},[]),u=ze.useCallback(g=>{n(g);},[]),l=ze.useMemo(()=>ft(r),[r]);return {isOpen:e,openDrawer:a,closeDrawer:o,toggleDrawer:i,citations:r,citationGroups:l,addCitation:d,removeCitation:s,clearCitations:c,setCitations:u}}
5
- Object.defineProperty(exports,"CITATION_X_PADDING",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.q}});Object.defineProperty(exports,"CITATION_Y_PADDING",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.r}});Object.defineProperty(exports,"classNames",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.p}});Object.defineProperty(exports,"generateCitationInstanceId",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.l}});Object.defineProperty(exports,"generateCitationKey",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.j}});Object.defineProperty(exports,"getCitationDisplayText",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.m}});Object.defineProperty(exports,"getCitationKeySpanText",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.o}});Object.defineProperty(exports,"getCitationNumber",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.n}});Object.defineProperty(exports,"isUrlCitation",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.i}});exports.CheckIcon=re;exports.CitationComponent=Me;exports.CitationDrawer=kr;exports.CitationDrawerItemComponent=We;exports.CloseIcon=Wt;exports.DeepCitationIcon=zt;exports.ExternalLinkIcon=Ut;exports.LinkIcon=Vt;exports.MemoizedCitationComponent=lr;exports.MemoizedSourcesListComponent=xr;exports.MemoizedSourcesListItem=gr;exports.MemoizedSourcesTrigger=fr;exports.SourcesListComponent=je;exports.SourcesListItem=ye;exports.SourcesTrigger=Te;exports.SpinnerIcon=se;exports.WarningIcon=ie;exports.detectSourceType=Re;exports.extractDomain=X;exports.getPlatformName=Be;exports.groupCitationsBySource=ft;exports.isAccessibleStatus=Rt;exports.isBlockedStatus=Xe;exports.isErrorStatus=Ye;exports.isRedirectedStatus=Bt;exports.isVerifiedStatus=Tt;exports.sourceCitationsToListItems=hr;exports.useCitationDrawer=Cr;exports.useSourcesList=yr;
4
+ `),a=st(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=lt(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]);function Zt(e){switch(e){case "chip":case "text":case "brackets":return "keySpan";case "source":return "source";default:return "number"}}function Jt(e){return e.replace(/^\[+\s*/,"").replace(/\s*\]+$/,"")}function qt(e,t,r){if(t==="indicator")return "";if(t==="keySpan"){let n=e.keySpan?.toString()||e.citationNumber?.toString()||r||"1";return Jt(n)}return t==="source"?e.siteName||e.domain||e.keySpan?.toString()||"Source":e.citationNumber?.toString()||"1"}function Qt(e){return e.isVerified&&!e.isPartialMatch?"Verified":e.isPartialMatch?"Partial Match":e.isMiss?"Not Found":e.isPending?"Verifying...":""}function er(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 tr({src:e,alt:t,onClose:r}){return ze.useEffect(()=>{let n=a=>{a.key==="Escape"&&r();};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)},[r]),reactDom.createPortal(jsxRuntime.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:jsxRuntime.jsx("div",{className:"relative max-w-[95vw] max-h-[95vh] cursor-zoom-out animate-in zoom-in-95 duration-[50ms]",children:jsxRuntime.jsx("img",{src:e,alt:t,className:"max-w-full max-h-[95vh] object-contain rounded-lg shadow-2xl",draggable:false})})}),document.body)}var rr=()=>jsxRuntime.jsx("span",{className:"inline-flex relative ml-0.5 size-2 text-green-600 dark:text-green-500","aria-hidden":"true",children:jsxRuntime.jsx(re,{})}),ar=()=>jsxRuntime.jsx("span",{className:"inline-flex relative ml-0.5 size-2 text-amber-600 dark:text-amber-500","aria-hidden":"true",children:jsxRuntime.jsx(re,{})}),nr=()=>jsxRuntime.jsx("span",{className:"inline-flex ml-1 size-2 animate-spin text-gray-400 dark:text-gray-500","aria-hidden":"true",children:jsxRuntime.jsx(se,{})}),or=()=>jsxRuntime.jsx("span",{className:"inline-flex relative ml-0.5 size-2 text-amber-500 dark:text-amber-400","aria-hidden":"true",children:jsxRuntime.jsx(ie,{})});function ir({citation:e,verification:t,isExpanded:r,onExpandChange:n}){let a=ze.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]=ze.useState(false),d=r??o,s=ze.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 jsxRuntime.jsxs("div",{className:"mt-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-gray-500 dark:text-gray-400 uppercase font-medium",children:[jsxRuntime.jsxs("span",{children:["Searched ",a.length," phrase",a.length!==1?"s":""]}),u>0&&!d&&jsxRuntime.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&&jsxRuntime.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"})]}),jsxRuntime.jsx("div",{className:"mt-1 space-y-1",children:a.slice(0,c).map((l,g)=>jsxRuntime.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 sr({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)return jsxRuntime.jsxs("div",{className:"p-2",children:[jsxRuntime.jsxs("button",{type:"button",className:"group block cursor-zoom-in relative",onClick:m=>{m.preventDefault(),m.stopPropagation(),n?.();},"aria-label":"Click to view full size",children:[jsxRuntime.jsx("img",{src:t.verificationImageBase64,alt:"Citation verification",className:"max-w-full h-auto object-contain rounded-md bg-gray-50 dark:bg-gray-800",loading:"lazy"}),jsxRuntime.jsx("span",{className:"absolute inset-0 flex items-center justify-center bg-black/0 group-hover:bg-black/5 dark:group-hover:bg-white/5 transition-colors rounded-md",children:jsxRuntime.jsx("span",{className:"opacity-0 group-hover:opacity-100 transition-opacity text-xs text-gray-600 dark:text-gray-300 bg-white/90 dark:bg-gray-800/90 px-2 py-1 rounded shadow-sm",children:"Click to expand"})})]}),(s||c)&&jsxRuntime.jsx(dt,{citation:e,verification:t,status:r})]});if(a||u){let m=e.fullPhrase||e.keySpan?.toString();return jsxRuntime.jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[200px] max-w-[400px]",children:[jsxRuntime.jsxs("span",{className:"text-xs font-medium text-gray-500 dark:text-gray-400",children:[jsxRuntime.jsx("span",{className:"inline-block relative top-[0.1em] mr-1.5 size-2 animate-spin",children:jsxRuntime.jsx(se,{})}),"Searching..."]}),m&&jsxRuntime.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:['"',m.length>80?m.slice(0,80)+"\u2026":m,'"']}),e.pageNumber&&e.pageNumber>0&&jsxRuntime.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Looking on page ",e.pageNumber]})]})}if(s)return jsxRuntime.jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[200px] max-w-[400px]",children:[jsxRuntime.jsxs("span",{className:"text-xs font-medium text-red-600 dark:text-red-500",children:[jsxRuntime.jsx("span",{className:"inline-block relative top-[0.1em] mr-1.5 size-3 text-amber-500 dark:text-amber-400",children:jsxRuntime.jsx(ie,{})}),"Not found: ",e.keySpan||e.fullPhrase]}),jsxRuntime.jsx(ir,{citation:e,verification:t,isExpanded:o,onExpandChange:i})]});let l=Qt(r),g=t?.verifiedMatchSnippet,x=t?.verifiedPageNumber;return !g&&!l?null:jsxRuntime.jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[180px] max-w-full",children:[l&&jsxRuntime.jsx("span",{className:chunkQDDCYCBV_cjs.i("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&&jsxRuntime.jsxs("span",{className:"text-sm text-gray-700 dark:text-gray-300 italic",children:['"',t.verifiedMatchSnippet,'"']}),x&&x>0&&jsxRuntime.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Page ",x]}),(s||c)&&jsxRuntime.jsx(dt,{citation:e,verification:t,status:r})]})}function dt({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}=ct(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,m=t?.verifiedPageNumber,I=x!=null&&m!=null&&x!==m;return n?jsxRuntime.jsxs("div",{className:"mt-2 pt-2 border-t border-gray-200 dark:border-gray-700 text-xs space-y-2",children:[o&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Expected"}),jsxRuntime.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})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Found"}),jsxRuntime.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,'"']})]})]}):jsxRuntime.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?jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Diff"}),jsxRuntime.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?jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("span",{className:"text-gray-500 dark:text-gray-400 text-[10px]",children:["Expected:"," "]}),jsxRuntime.jsx("span",{className:"text-red-600 dark:text-red-400 line-through opacity-70",children:o.length>100?o.slice(0,100)+"\u2026":o})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("span",{className:"text-gray-500 dark:text-gray-400 text-[10px]",children:["Found:"," "]}),jsxRuntime.jsx("span",{className:"text-green-600 dark:text-green-400",children:i.length>100?i.slice(0,100)+"\u2026":i})]})]}):d.map((B,h)=>jsxRuntime.jsx("span",{children:B.parts.map((k,N)=>{let S=`p-${h}-${N}`;return k.removed?jsxRuntime.jsx("span",{className:"bg-red-200 dark:bg-red-900/50 text-red-700 dark:text-red-300 line-through",title:"Expected text",children:k.value},S):k.added?jsxRuntime.jsx("span",{className:"bg-green-200 dark:bg-green-900/50 text-green-700 dark:text-green-300",title:"Actual text found",children:k.value},S):jsxRuntime.jsx("span",{children:k.value},S)})},`block-${h}`))})]}):o&&!s?jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Text"}),jsxRuntime.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,I&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Page"}),jsxRuntime.jsxs("p",{className:"mt-1 font-mono text-[11px] text-gray-700 dark:text-gray-300",children:[jsxRuntime.jsx("span",{className:"text-red-600 dark:text-red-400 line-through opacity-70",children:x})," \u2192 ",m]})]}),g&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Line"}),jsxRuntime.jsxs("p",{className:"mt-1 font-mono text-[11px] text-gray-700 dark:text-gray-300",children:[jsxRuntime.jsx("span",{className:"text-red-600 dark:text-red-400 line-through opacity-70",children:u?.join(", ")})," \u2192 ",l?.join(", ")]})]})]})}var Me=ze.forwardRef(({citation:e,children:t,className:r,fallbackDisplay:n,verification:a,isLoading:o=false,variant:i="brackets",content:d,eventHandlers:s,behaviorConfig:c,isMobile:u=false,renderIndicator:l,renderContent:g,popoverPosition:x="top",renderPopoverContent:m,additionalCount:I,faviconUrl:B},h)=>{let k=ze.useMemo(()=>d||Zt(i),[d,i]),[N,S]=ze.useState(false),[M,T]=ze.useState(null),[W,A]=ze.useState(false),C=ze.useMemo(()=>chunkQDDCYCBV_cjs.k(e),[e]),U=ze.useMemo(()=>chunkQDDCYCBV_cjs.m(C),[C]),O=ze.useMemo(()=>er(a),[a]),{isMiss:v,isPartialMatch:P,isVerified:E,isPending:H}=O,de=5e3,[ue,Q]=ze.useState(false),$=ze.useRef(null),D=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",z=(o||H)&&!D&&!ue;ze.useEffect(()=>($.current&&(clearTimeout($.current),$.current=null),(o||H)&&!D?(Q(false),$.current=setTimeout(()=>{Q(true);},de)):Q(false),()=>{$.current&&clearTimeout($.current);}),[o,H,D]);let G=ze.useMemo(()=>qt(e,k,n),[e,k,n]),J=ze.useCallback(()=>({citation:e,citationKey:C,verification:a??null,isTooltipExpanded:N,isImageExpanded:!!M,hasImage:!!a?.verificationImageBase64}),[e,C,a,N,M]),Ae=ze.useCallback(w=>{w.setImageExpanded!==void 0&&(typeof w.setImageExpanded=="string"?T(w.setImageExpanded):w.setImageExpanded===true&&a?.verificationImageBase64?T(a.verificationImageBase64):w.setImageExpanded===false&&T(null));},[a?.verificationImageBase64]),xt=ze.useCallback(w=>{w.preventDefault(),w.stopPropagation();let te=J();if(c?.onClick){let me=c.onClick(te,w);me&&typeof me=="object"&&Ae(me),s?.onClick?.(e,C,w);return}if(s?.onClick){s.onClick(e,C,w);return}a?.verificationImageBase64?T(a.verificationImageBase64):v&&A(me=>!me);},[c,s,e,C,a?.verificationImageBase64,v,J,Ae]),He=150,ee=ze.useRef(null),be=ze.useRef(false),q=ze.useCallback(()=>{ee.current&&(clearTimeout(ee.current),ee.current=null);},[]),ht=ze.useCallback(()=>{q(),S(true),c?.onHover?.onEnter&&c.onHover.onEnter(J()),s?.onMouseEnter?.(e,C);},[s,c,e,C,J,q]),yt=ze.useCallback(()=>{q(),ee.current=setTimeout(()=>{be.current||(S(false),c?.onHover?.onLeave&&c.onHover.onLeave(J()),s?.onMouseLeave?.(e,C));},He);},[s,c,e,C,J,q]),vt=ze.useCallback(()=>{q(),be.current=true;},[q]),bt=ze.useCallback(()=>{be.current=false,q(),ee.current=setTimeout(()=>{S(false),c?.onHover?.onLeave&&c.onHover.onLeave(J()),s?.onMouseLeave?.(e,C);},He);},[s,c,e,C,J,q]);ze.useEffect(()=>()=>{ee.current&&clearTimeout(ee.current);},[]);let kt=ze.useCallback(w=>{u&&(w.preventDefault(),w.stopPropagation(),s?.onTouchEnd?.(e,C,w));},[s,e,C,u]);if(n!=null&&k==="keySpan"&&v)return jsxRuntime.jsx("span",{className:chunkQDDCYCBV_cjs.i("text-gray-400 dark:text-gray-500",r),children:n});let ke=chunkQDDCYCBV_cjs.i((E||P)&&i==="brackets"&&"text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 hover:underline",v&&"opacity-70 line-through text-gray-400 dark:text-gray-500",z&&"text-gray-500 dark:text-gray-400"),ae=()=>l?l(O):z?jsxRuntime.jsx(nr,{}):E&&!P?jsxRuntime.jsx(rr,{}):P?jsxRuntime.jsx(ar,{}):v?jsxRuntime.jsx(or,{}):null,$e=()=>{if(g)return g({citation:e,status:O,citationKey:C,displayText:G,isMergedDisplay:k==="keySpan"});if(k==="indicator")return jsxRuntime.jsx("span",{children:ae()});if(i==="chip"){let w=chunkQDDCYCBV_cjs.i(E&&!P&&!z&&"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",P&&!z&&"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",v&&!z&&"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400 line-through",z&&"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400",!E&&!v&&!z&&"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400");return jsxRuntime.jsxs("span",{className:chunkQDDCYCBV_cjs.i("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-sm font-medium",w),children:[jsxRuntime.jsx("span",{className:"max-w-60 overflow-hidden text-ellipsis whitespace-nowrap",children:G}),ae()]})}if(i==="superscript"){let w=chunkQDDCYCBV_cjs.i(E&&!P&&!z&&"text-green-600 dark:text-green-500",P&&!z&&"text-amber-600 dark:text-amber-500",v&&!z&&"text-red-500 dark:text-red-400 line-through",z&&"text-gray-400 dark:text-gray-500",!E&&!v&&!z&&"text-blue-600 dark:text-blue-400");return jsxRuntime.jsxs("sup",{className:chunkQDDCYCBV_cjs.i("text-xs font-medium transition-colors hover:underline",w),children:["[",G,ae(),"]"]})}if(i==="text")return jsxRuntime.jsxs("span",{className:ke,children:[G,ae()]});if(i==="minimal")return jsxRuntime.jsxs("span",{className:chunkQDDCYCBV_cjs.i("max-w-80 overflow-hidden text-ellipsis",ke),children:[G,ae()]});if(i==="source"){let w=B||e.faviconUrl;return jsxRuntime.jsxs("span",{className:chunkQDDCYCBV_cjs.i("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:[w&&jsxRuntime.jsx("img",{src:w,alt:"",className:"w-4 h-4 rounded-sm object-contain",loading:"lazy",onError:te=>{te.target.style.display="none";}}),jsxRuntime.jsx("span",{className:"max-w-40 overflow-hidden text-ellipsis whitespace-nowrap",children:G}),I!==void 0&&I>0&&jsxRuntime.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:["+",I]})]})}return jsxRuntime.jsxs("span",{className:chunkQDDCYCBV_cjs.i("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:["[",jsxRuntime.jsxs("span",{className:chunkQDDCYCBV_cjs.i("max-w-80 overflow-hidden text-ellipsis",ke),children:[G,ae()]}),"]"]})},Ct=!(x==="hidden")&&(a&&(a.verificationImageBase64||a.verifiedMatchSnippet)||z||H||o||v),wt=!!a?.verificationImageBase64,Fe=M?jsxRuntime.jsx(tr,{src:M,alt:"Citation verification - full size",onClose:()=>T(null)}):null,Ke={"data-citation-id":C,"data-citation-instance":U,className:chunkQDDCYCBV_cjs.i("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",wt&&"cursor-zoom-in",r),onMouseEnter:ht,onMouseLeave:yt,onClick:xt,onTouchEndCapture:u?kt:void 0,"aria-label":G?`[${G}]`:void 0};if(Ct){let w=m?m({citation:e,verification:a??null,status:O}):jsxRuntime.jsx(sr,{citation:e,verification:a??null,status:O,isLoading:o||z,isPhrasesExpanded:W,onPhrasesExpandChange:A,onImageClick:()=>{a?.verificationImageBase64&&T(a.verificationImageBase64);}});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[t,jsxRuntime.jsxs(Qe,{open:N,children:[jsxRuntime.jsx(et,{asChild:true,children:jsxRuntime.jsx("span",{ref:h,...Ke,children:$e()})}),jsxRuntime.jsx(Pe,{side:x==="bottom"?"bottom":"top",onPointerDownOutside:te=>te.preventDefault(),onInteractOutside:te=>te.preventDefault(),onMouseEnter:vt,onMouseLeave:bt,children:w})]}),Fe]})}return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[t,jsxRuntime.jsx("span",{ref:h,...Ke,children:$e()}),Fe]})});Me.displayName="CitationComponent";var lr=ze.memo(Me);function pt(e,t){return t||`https://www.google.com/s2/favicons?domain=${X(e)}&sz=32`}function Re(e){if(!e.startsWith("http://")&&!e.startsWith("https://"))return "unknown";try{let t=X(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 Be(e,t){let r=(t||X(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 ur=()=>jsxRuntime.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:[jsxRuntime.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsxRuntime.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),mr=()=>jsxRuntime.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:jsxRuntime.jsx("polyline",{points:"9 18 15 12 9 6"})}),pr=()=>jsxRuntime.jsxs("svg",{className:"animate-spin",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[jsxRuntime.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsxRuntime.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=ze.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 m=ze.useCallback(N=>{s?s({id:e,url:t,title:r,domain:n,sourceType:a,faviconUrl:o,citationNumbers:i,verificationStatus:d},N):window.open(t,"_blank","noopener,noreferrer");},[s,e,t,r,n,a,o,i,d]),I=ze.useMemo(()=>Be(t,n),[t,n]),B=ze.useMemo(()=>pt(t,o),[t,o]),h=ze.useMemo(()=>a||Re(t),[a,t]),k=()=>{if(!u||!d)return null;let S={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 jsxRuntime.jsx("span",{className:chunkQDDCYCBV_cjs.q("text-sm ml-1",S.className),"aria-label":d,children:S.icon})};return jsxRuntime.jsxs("div",{ref:x,"data-source-id":e,"data-source-type":h,className:chunkQDDCYCBV_cjs.q("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:m,role:"link",tabIndex:0,onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.preventDefault(),m(N));},"aria-label":`${r} from ${I}`,children:[jsxRuntime.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}):jsxRuntime.jsx("img",{src:B,alt:"",className:"w-5 h-5 rounded",width:20,height:20,loading:"lazy",onError:N=>{N.target.style.display="none";}})}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsx("span",{className:"text-gray-900 dark:text-gray-100 font-medium text-sm leading-tight line-clamp-2",children:r}),k()]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 text-xs",children:I}),l&&i&&i.length>0&&jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[i.slice(0,3).map(N=>jsxRuntime.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:N},N)),i.length>3&&jsxRuntime.jsxs("span",{className:"text-xs text-gray-400",children:["+",i.length-3]})]})]})]}),jsxRuntime.jsx("div",{className:"flex-shrink-0 text-gray-400 dark:text-gray-500 mt-1",children:jsxRuntime.jsx(mr,{})})]})});ye.displayName="SourcesListItem";var Te=ze.forwardRef(({sources:e,maxIcons:t=3,onClick:r,label:n="Sources",className:a,isOpen:o},i)=>{let d=ze.useMemo(()=>e.slice(0,t),[e,t]),s=e.length>t;return jsxRuntime.jsxs("button",{ref:i,type:"button",onClick:r,className:chunkQDDCYCBV_cjs.q("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:[jsxRuntime.jsx("span",{className:"font-medium",children:n}),jsxRuntime.jsxs("div",{className:"flex items-center -space-x-1",children:[d.map((c,u)=>jsxRuntime.jsx("img",{src:pt(c.url,c.faviconUrl),alt:"",className:chunkQDDCYCBV_cjs.q("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&&jsxRuntime.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]})]})]})});Te.displayName="SourcesTrigger";var je=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:m,renderEmpty:I,renderLoading:B},h)=>{let k=ze.useRef(null),[N,S]=ze.useState(false);ze.useEffect(()=>{if(!r||t==="inline")return;let v=P=>{P.key==="Escape"&&n?.(false);};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[r,n,t]),ze.useEffect(()=>{S(true);},[]);let M=ze.useMemo(()=>{if(!x)return null;let v={};for(let P of e){let E=P.domain||X(P.url);v[E]||(v[E]=[]),v[E].push(P);}return v},[e,x]),T=ze.useCallback(()=>{n?.(false);},[n]),W=ze.useCallback(v=>{v.target===v.currentTarget&&T();},[T]),A=()=>{let{title:v="Sources",showCloseButton:P=true,showCount:E=true,renderHeader:H}=a;return H?H({title:v,count:e.length,onClose:T}):jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-200 dark:border-gray-700",children:[P&&t!=="inline"&&jsxRuntime.jsx("button",{type:"button",onClick:T,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:jsxRuntime.jsx(ur,{})}),jsxRuntime.jsxs("h2",{className:"text-base font-semibold text-gray-900 dark:text-gray-100 flex-1 text-center",children:[v,E&&jsxRuntime.jsxs("span",{className:"ml-2 text-sm font-normal text-gray-500 dark:text-gray-400",children:["(",e.length,")"]})]}),P&&t!=="inline"&&jsxRuntime.jsx("div",{className:"w-8"})]})},C=()=>o?B?B():jsxRuntime.jsxs("div",{className:"flex items-center justify-center py-8 text-gray-500 dark:text-gray-400",children:[jsxRuntime.jsx(pr,{}),jsxRuntime.jsx("span",{className:"ml-2 text-sm",children:"Loading sources..."})]}):e.length===0?I?I():jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-gray-500 dark:text-gray-400 text-sm",children:i}):x&&M?jsxRuntime.jsx("div",{className:c,children:Object.entries(M).map(([v,P])=>jsxRuntime.jsxs("div",{children:[jsxRuntime.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:Be(P[0].url,v)}),P.map((E,H)=>m?m(E,H):jsxRuntime.jsx(ye,{...E,onClick:u,showVerificationIndicator:l,showCitationBadges:g},E.id))]},v))}):jsxRuntime.jsx("div",{className:c,children:e.map((v,P)=>m?m(v,P):jsxRuntime.jsx(ye,{...v,onClick:u,showVerificationIndicator:l,showCitationBadges:g},v.id))}),U=d?{maxHeight:typeof d=="number"?`${d}px`:d}:void 0;if(t==="inline")return r?jsxRuntime.jsxs("div",{ref:h,className:chunkQDDCYCBV_cjs.q("bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700",s),style:U,children:[A(),jsxRuntime.jsx("div",{className:"overflow-y-auto",style:U,children:C()})]}):null;if(t==="panel")return r?jsxRuntime.jsxs("div",{ref:h,className:chunkQDDCYCBV_cjs.q("bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700 shadow-lg",s),children:[A(),jsxRuntime.jsx("div",{className:"overflow-y-auto",style:U||{maxHeight:"400px"},children:C()})]}):null;if(!N||!r)return null;let O=jsxRuntime.jsxs("div",{ref:h,className:chunkQDDCYCBV_cjs.q("fixed inset-0 z-50",t==="modal"&&"flex items-center justify-center"),role:"dialog","aria-modal":"true","aria-labelledby":"sources-title",children:[jsxRuntime.jsx("div",{className:chunkQDDCYCBV_cjs.q("absolute inset-0 bg-black/40 dark:bg-black/60 transition-opacity",r?"opacity-100":"opacity-0"),onClick:W,"aria-hidden":"true"}),t==="drawer"?jsxRuntime.jsxs("div",{ref:k,className:chunkQDDCYCBV_cjs.q("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:[jsxRuntime.jsx("div",{className:"flex justify-center py-2",children:jsxRuntime.jsx("div",{className:"w-10 h-1 bg-gray-300 dark:bg-gray-600 rounded-full"})}),A(),jsxRuntime.jsx("div",{className:"overflow-y-auto flex-1",children:C()})]}):jsxRuntime.jsxs("div",{ref:k,className:chunkQDDCYCBV_cjs.q("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(),jsxRuntime.jsx("div",{className:"overflow-y-auto flex-1",children:C()})]})]});return reactDom.createPortal(O,document.body)});je.displayName="SourcesListComponent";var gr=ze.memo(ye),fr=ze.memo(Te),xr=ze.memo(je);function hr(e){let t=new Map;for(let r of e){if(!r.url)continue;let n=r.domain||X(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||Re(r.url),faviconUrl:r.faviconUrl,citationNumbers:r.citationNumber?[r.citationNumber]:[]});}return Array.from(t.values())}function yr(e=[]){let[t,r]=ze.useState(e),[n,a]=ze.useState(false),o=ze.useCallback(s=>{r(c=>c.some(l=>l.url===s.url)?c:[...c,s]);},[]),i=ze.useCallback(s=>{r(c=>c.filter(u=>u.id!==s));},[]),d=ze.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 ft(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||Ue(a.url)||"Unknown Source",sourceDomain:a.domain||Ue(a.url),sourceFavicon:a.faviconUrl||void 0,citations:n,additionalCount:n.length-1}})}function Ue(e){if(e)try{return new URL(e).hostname.replace(/^www\./,"")}catch{return}}function br(e){let t=e?.status;return !t||t==="pending"||t==="loading"?{color:"text-gray-400",icon:jsxRuntime.jsx(se,{}),label:"Verifying"}:t==="not_found"?{color:"text-amber-500",icon:jsxRuntime.jsx(ie,{}),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:jsxRuntime.jsx(re,{}),label:"Partial match"}:{color:"text-green-500",icon:jsxRuntime.jsx(re,{}),label:"Verified"}}function We({item:e,isLast:t=false,onClick:r,onReadMore:n,className:a}){let{citation:o,verification:i}=e,d=br(i),s=o.siteName||o.domain||Ue(o.url)||"Source",c=o.title||o.keySpan||o.fullPhrase,u=o.description||i?.actualContentSnippet||i?.verifiedMatchSnippet,l=o.faviconUrl,g=ze.useCallback(()=>{r?.(e);},[e,r]),x=ze.useCallback(m=>{m.stopPropagation(),n?.(e);},[e,n]);return jsxRuntime.jsx("div",{className:chunkQDDCYCBV_cjs.i("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:m=>{(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),g());},children:jsxRuntime.jsxs("div",{className:"flex items-start gap-3",children:[jsxRuntime.jsx("div",{className:"flex-shrink-0 mt-0.5",children:l?jsxRuntime.jsx("img",{src:l,alt:"",className:"w-5 h-5 rounded object-contain",loading:"lazy",onError:m=>{m.target.style.display="none";}}):jsxRuntime.jsx("div",{className:"w-5 h-5 rounded bg-gray-200 dark:bg-gray-700 flex items-center justify-center",children:jsxRuntime.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:s.charAt(0).toUpperCase()})})}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5",children:[jsxRuntime.jsx("span",{className:"text-xs font-medium text-gray-500 dark:text-gray-400",children:s}),jsxRuntime.jsx("span",{className:chunkQDDCYCBV_cjs.i("inline-flex w-3 h-3",d.color,i?.status==="pending"||i?.status==="loading"?"animate-spin":""),title:d.label,children:d.icon})]}),c&&jsxRuntime.jsx("h4",{className:"mt-1 text-sm font-medium text-gray-900 dark:text-gray-100 line-clamp-2",children:c}),u&&jsxRuntime.jsxs("p",{className:"mt-1 text-sm text-gray-600 dark:text-gray-400 line-clamp-2",children:[u,n&&u.length>100&&jsxRuntime.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 kr({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]=ze.useState(false),x=ze.useMemo(()=>r.flatMap(h=>h.citations),[r]),m=ze.useMemo(()=>!a||l?x:x.slice(0,o),[x,a,l,o]),I=ze.useMemo(()=>!a||l?[]:x.slice(o),[x,a,l,o]);if(ze__namespace.default.useEffect(()=>{if(!e)return;let h=k=>{k.key==="Escape"&&t();};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[e,t]),!e)return null;let B=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/40 z-[9998] animate-in fade-in-0 duration-150",onClick:t,"aria-hidden":"true"}),jsxRuntime.jsxs("div",{className:chunkQDDCYCBV_cjs.i("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"&&jsxRuntime.jsx("div",{className:"flex justify-center pt-3 pb-1",children:jsxRuntime.jsx("div",{className:"w-10 h-1 rounded-full bg-gray-300 dark:bg-gray-600"})}),jsxRuntime.jsxs("div",{className:"px-4 py-3 border-b border-gray-200 dark:border-gray-700 flex items-center justify-between",children:[jsxRuntime.jsx("h2",{className:"text-base font-semibold text-gray-900 dark:text-gray-100",children:n}),jsxRuntime.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:jsxRuntime.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:jsxRuntime.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),jsxRuntime.jsx("div",{className:"overflow-y-auto max-h-[calc(80vh-100px)]",children:m.length===0?jsxRuntime.jsx("div",{className:"px-4 py-8 text-center text-gray-500 dark:text-gray-400",children:"No citations to display"}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[m.map((h,k)=>u?jsxRuntime.jsx(ze__namespace.default.Fragment,{children:u(h)},h.citationKey):jsxRuntime.jsx(We,{item:h,isLast:k===m.length-1&&I.length===0,onClick:i,onReadMore:d},h.citationKey)),I.length>0&&!l&&jsxRuntime.jsx("div",{className:"px-4 py-3 border-t border-gray-200 dark:border-gray-700",children:jsxRuntime.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 (",I.length,")"]})}),l&&I.map((h,k)=>u?jsxRuntime.jsx(ze__namespace.default.Fragment,{children:u(h)},h.citationKey):jsxRuntime.jsx(We,{item:h,isLast:k===I.length-1,onClick:i,onReadMore:d},h.citationKey))]})})]})]});return reactDom.createPortal(B,document.body)}function Cr(){let[e,t]=ze.useState(false),[r,n]=ze.useState([]),a=ze.useCallback(()=>t(true),[]),o=ze.useCallback(()=>t(false),[]),i=ze.useCallback(()=>t(g=>!g),[]),d=ze.useCallback(g=>{n(x=>x.some(m=>m.citationKey===g.citationKey)?x:[...x,g]);},[]),s=ze.useCallback(g=>{n(x=>x.filter(m=>m.citationKey!==g));},[]),c=ze.useCallback(()=>{n([]);},[]),u=ze.useCallback(g=>{n(g);},[]),l=ze.useMemo(()=>ft(r),[r]);return {isOpen:e,openDrawer:a,closeDrawer:o,toggleDrawer:i,citations:r,citationGroups:l,addCitation:d,removeCitation:s,clearCitations:c,setCitations:u}}
5
+ Object.defineProperty(exports,"CITATION_X_PADDING",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.r}});Object.defineProperty(exports,"CITATION_Y_PADDING",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.s}});Object.defineProperty(exports,"classNames",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.q}});Object.defineProperty(exports,"generateCitationInstanceId",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.m}});Object.defineProperty(exports,"generateCitationKey",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.k}});Object.defineProperty(exports,"getCitationDisplayText",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.n}});Object.defineProperty(exports,"getCitationKeySpanText",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.p}});Object.defineProperty(exports,"getCitationNumber",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.o}});Object.defineProperty(exports,"isUrlCitation",{enumerable:true,get:function(){return chunkQDDCYCBV_cjs.j}});exports.CheckIcon=re;exports.CitationComponent=Me;exports.CitationDrawer=kr;exports.CitationDrawerItemComponent=We;exports.CloseIcon=Wt;exports.DeepCitationIcon=zt;exports.ExternalLinkIcon=Ut;exports.LinkIcon=Vt;exports.MemoizedCitationComponent=lr;exports.MemoizedSourcesListComponent=xr;exports.MemoizedSourcesListItem=gr;exports.MemoizedSourcesTrigger=fr;exports.SourcesListComponent=je;exports.SourcesListItem=ye;exports.SourcesTrigger=Te;exports.SpinnerIcon=se;exports.WarningIcon=ie;exports.detectSourceType=Re;exports.extractDomain=X;exports.getPlatformName=Be;exports.groupCitationsBySource=ft;exports.isAccessibleStatus=Rt;exports.isBlockedStatus=Xe;exports.isErrorStatus=Ye;exports.isRedirectedStatus=Bt;exports.isVerifiedStatus=Tt;exports.sourceCitationsToListItems=hr;exports.useCitationDrawer=Cr;exports.useSourcesList=yr;
@@ -1,5 +1,5 @@
1
- import {j,l,p,h}from'../chunk-3PE4VRVE.js';export{q as CITATION_X_PADDING,r as CITATION_Y_PADDING,p as classNames,l as generateCitationInstanceId,j as generateCitationKey,m as getCitationDisplayText,o as getCitationKeySpanText,n as getCitationNumber,i as isUrlCitation}from'../chunk-3PE4VRVE.js';import'../chunk-O2XFH626.js';import*as ze from'react';import ze__default,{forwardRef,useMemo,useCallback,memo,useState,useRef,useEffect}from'react';import {jsxs,Fragment,jsx}from'react/jsx-runtime';import {createPortal}from'react-dom';import*as F from'@radix-ui/react-popover';function X(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e.replace(/^https?:\/\/(www\.)?/,"").split("/")[0]}}function Oe(e,t){return e.length<=t?e:e.slice(0,t-1)+"\u2026"}function _t(e){try{let t=new URL(e),r=t.pathname+t.search;return r==="/"?"":r}catch{return ""}}var Ge={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 Xe(e){return e.startsWith("blocked_")}function Ye(e){return e.startsWith("error_")}function Rt(e){return e==="verified"||e==="partial"||e==="accessible"||e==="redirected_valid"}function Bt(e){return e==="redirected"||e==="redirected_valid"}function Tt(e){return e==="verified"||e==="partial"||e==="redirected_valid"}var jt=({status:e,errorMessage:t})=>{let r=Ge[e];return jsx("span",{className:p("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})})},we=({url:e,faviconUrl:t})=>{let r=X(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";}})},Ze=forwardRef(({urlMeta:e,citation:t,children:r,className:n,variant:a="chip",showFullUrlOnHover:o=true,showFavicon:i=true,showTitle:d=false,maxDisplayLength:s=30,renderBlockedIndicator:c,onUrlClick:u,eventHandlers:l$1,preventTooltips:g=false},x)=>{let{url:m,domain:I,title:B,fetchStatus:h,faviconUrl:k,errorMessage:N}=e,S=useMemo(()=>t||{value:m,fullPhrase:B||m},[t,m,B]),M=useMemo(()=>j(S),[S]),T=useMemo(()=>l(M),[M]),W=useMemo(()=>I||X(m),[I,m]),A=useMemo(()=>_t(m),[m]),C=useMemo(()=>{if(d&&B)return Oe(B,s);let D=A?Oe(A,s-W.length-1):"";return D?`${W}${D}`:W},[d,B,W,A,s]),U=Ge[h],O=Xe(h),v=Ye(h),P=h==="verified",E=h==="partial",H=h==="pending",de=useCallback(D=>{D.preventDefault(),D.stopPropagation(),u?u(m,D):window.open(m,"_blank","noopener,noreferrer"),l$1?.onClick?.(S,M,D);},[u,m,l$1,S,M]),ue=useCallback(()=>{l$1?.onMouseEnter?.(S,M);},[l$1,S,M]),Q=useCallback(()=>{l$1?.onMouseLeave?.(S,M);},[l$1,S,M]),$=()=>O||v?c?c(h,N):jsx(jt,{status:h,errorMessage:N}):P?jsx("span",{className:"text-[0.85em] text-green-600 dark:text-green-500","aria-hidden":"true",title:"Verified",children:"\u2713"}):E?jsx("span",{className:"text-[0.85em] text-amber-600 dark:text-amber-500","aria-hidden":"true",title:"Partial match",children:"~"}):H?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":M,"data-citation-instance":T,"data-url":m,"data-fetch-status":h,"data-variant":"chip",className:p("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",U.className,n),title:o?m:void 0,onMouseEnter:g?void 0:ue,onMouseLeave:g?void 0:Q,onMouseDown:de,onClick:D=>D.stopPropagation(),role:"link","aria-label":`Link to ${W}: ${U.label}`,children:[i&&jsx(we,{url:m,faviconUrl:k}),jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:C}),$()]})]}):a==="inline"?jsxs(Fragment,{children:[r,jsxs("a",{ref:x,href:m,"data-citation-id":M,"data-citation-instance":T,"data-fetch-status":h,"data-variant":"inline",className:p("inline-flex items-center gap-1 cursor-pointer transition-colors no-underline border-b border-dotted border-current",U.className,n),title:o?m:void 0,onMouseEnter:g?void 0:ue,onMouseLeave:g?void 0:Q,onClick:D=>{D.preventDefault(),de(D);},target:"_blank",rel:"noopener noreferrer","aria-label":`Link to ${W}: ${U.label}`,children:[i&&jsx(we,{url:m,faviconUrl:k}),jsx("span",{children:C}),$()]})]}):jsxs(Fragment,{children:[r,jsxs("span",{ref:x,"data-citation-id":M,"data-citation-instance":T,"data-url":m,"data-fetch-status":h,"data-variant":"bracket",className:p("cursor-pointer transition-colors",U.className,n),title:o?m:void 0,onMouseEnter:g?void 0:ue,onMouseLeave:g?void 0:Q,onMouseDown:de,onClick:D=>D.stopPropagation(),role:"link","aria-label":`Link to ${W}: ${U.label}`,children:["[",i&&jsx(we,{url:m,faviconUrl:k}),jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:C}),$(),"]"]})]})});Ze.displayName="UrlCitationComponent";memo(Ze);var zt=({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"})]}),re=({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"})}),ie=({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"})}),se=({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}})]}),Vt=({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"})]}),Ut=({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"})]}),Wt=({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 At(...e){return e.filter(Boolean).join(" ")}var Qe=F.Root,et=F.Trigger;var Pe=ze.forwardRef(({className:e,align:t="center",sideOffset:r=8,...n},a)=>jsx(F.Portal,{children:jsx(F.Content,{ref:a,align:t,sideOffset:r,className:At("z-[9998] rounded-lg border bg-white shadow-xl outline-none","w-fit max-w-[min(600px,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})}));Pe.displayName=F.Content.displayName;function ot(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=Ht(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}),it(u)}function Ht(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 $t(d,e,t)}function $t(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.unshift({value:t[a],count:1});i>0&&(a===u?(o--,n.unshift({value:r[o],added:true,count:1})):(a--,n.unshift({value:t[a],removed:true,count:1})));}return n}function it(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 tt(e){if(!e)return [];let t=[],r="";for(let n=0;n<e.length;n++){let a=e[n];r+=a,a===`
1
+ import {k,m,q,i}from'../chunk-OT5T6R53.js';export{r as CITATION_X_PADDING,s as CITATION_Y_PADDING,q as classNames,m as generateCitationInstanceId,k as generateCitationKey,n as getCitationDisplayText,p as getCitationKeySpanText,o as getCitationNumber,j as isUrlCitation}from'../chunk-OT5T6R53.js';import'../chunk-O2XFH626.js';import*as ze from'react';import ze__default,{forwardRef,useMemo,useCallback,memo,useState,useRef,useEffect}from'react';import {jsxs,Fragment,jsx}from'react/jsx-runtime';import {createPortal}from'react-dom';import*as F from'@radix-ui/react-popover';function X(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e.replace(/^https?:\/\/(www\.)?/,"").split("/")[0]}}function Oe(e,t){return e.length<=t?e:e.slice(0,t-1)+"\u2026"}function _t(e){try{let t=new URL(e),r=t.pathname+t.search;return r==="/"?"":r}catch{return ""}}var Ge={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 Xe(e){return e.startsWith("blocked_")}function Ye(e){return e.startsWith("error_")}function Rt(e){return e==="verified"||e==="partial"||e==="accessible"||e==="redirected_valid"}function Bt(e){return e==="redirected"||e==="redirected_valid"}function Tt(e){return e==="verified"||e==="partial"||e==="redirected_valid"}var jt=({status:e,errorMessage:t})=>{let r=Ge[e];return jsx("span",{className:q("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})})},we=({url:e,faviconUrl:t})=>{let r=X(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";}})},Ze=forwardRef(({urlMeta:e,citation:t,children:r,className:n,variant:a="chip",showFullUrlOnHover:o=true,showFavicon:i=true,showTitle:d=false,maxDisplayLength:s=30,renderBlockedIndicator:c,onUrlClick:u,eventHandlers:l,preventTooltips:g=false},x)=>{let{url:m$1,domain:I,title:B,fetchStatus:h,faviconUrl:k$1,errorMessage:N}=e,S=useMemo(()=>t||{value:m$1,fullPhrase:B||m$1},[t,m$1,B]),M=useMemo(()=>k(S),[S]),T=useMemo(()=>m(M),[M]),W=useMemo(()=>I||X(m$1),[I,m$1]),A=useMemo(()=>_t(m$1),[m$1]),C=useMemo(()=>{if(d&&B)return Oe(B,s);let D=A?Oe(A,s-W.length-1):"";return D?`${W}${D}`:W},[d,B,W,A,s]),U=Ge[h],O=Xe(h),v=Ye(h),P=h==="verified",E=h==="partial",H=h==="pending",de=useCallback(D=>{D.preventDefault(),D.stopPropagation(),u?u(m$1,D):window.open(m$1,"_blank","noopener,noreferrer"),l?.onClick?.(S,M,D);},[u,m$1,l,S,M]),ue=useCallback(()=>{l?.onMouseEnter?.(S,M);},[l,S,M]),Q=useCallback(()=>{l?.onMouseLeave?.(S,M);},[l,S,M]),$=()=>O||v?c?c(h,N):jsx(jt,{status:h,errorMessage:N}):P?jsx("span",{className:"text-[0.85em] text-green-600 dark:text-green-500","aria-hidden":"true",title:"Verified",children:"\u2713"}):E?jsx("span",{className:"text-[0.85em] text-amber-600 dark:text-amber-500","aria-hidden":"true",title:"Partial match",children:"~"}):H?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":M,"data-citation-instance":T,"data-url":m$1,"data-fetch-status":h,"data-variant":"chip",className:q("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",U.className,n),title:o?m$1:void 0,onMouseEnter:g?void 0:ue,onMouseLeave:g?void 0:Q,onMouseDown:de,onClick:D=>D.stopPropagation(),role:"link","aria-label":`Link to ${W}: ${U.label}`,children:[i&&jsx(we,{url:m$1,faviconUrl:k$1}),jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:C}),$()]})]}):a==="inline"?jsxs(Fragment,{children:[r,jsxs("a",{ref:x,href:m$1,"data-citation-id":M,"data-citation-instance":T,"data-fetch-status":h,"data-variant":"inline",className:q("inline-flex items-center gap-1 cursor-pointer transition-colors no-underline border-b border-dotted border-current",U.className,n),title:o?m$1:void 0,onMouseEnter:g?void 0:ue,onMouseLeave:g?void 0:Q,onClick:D=>{D.preventDefault(),de(D);},target:"_blank",rel:"noopener noreferrer","aria-label":`Link to ${W}: ${U.label}`,children:[i&&jsx(we,{url:m$1,faviconUrl:k$1}),jsx("span",{children:C}),$()]})]}):jsxs(Fragment,{children:[r,jsxs("span",{ref:x,"data-citation-id":M,"data-citation-instance":T,"data-url":m$1,"data-fetch-status":h,"data-variant":"bracket",className:q("cursor-pointer transition-colors",U.className,n),title:o?m$1:void 0,onMouseEnter:g?void 0:ue,onMouseLeave:g?void 0:Q,onMouseDown:de,onClick:D=>D.stopPropagation(),role:"link","aria-label":`Link to ${W}: ${U.label}`,children:["[",i&&jsx(we,{url:m$1,faviconUrl:k$1}),jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:C}),$(),"]"]})]})});Ze.displayName="UrlCitationComponent";memo(Ze);var zt=({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"})]}),re=({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"})}),ie=({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"})}),se=({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}})]}),Vt=({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"})]}),Ut=({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"})]}),Wt=({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 At(...e){return e.filter(Boolean).join(" ")}var Qe=F.Root,et=F.Trigger;var Pe=ze.forwardRef(({className:e,align:t="center",sideOffset:r=8,...n},a)=>jsx(F.Portal,{children:jsx(F.Content,{ref:a,align:t,sideOffset:r,className:At("z-[9998] rounded-lg border bg-white shadow-xl outline-none","w-fit max-w-[min(600px,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})}));Pe.displayName=F.Content.displayName;function ot(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=Ht(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}),it(u)}function Ht(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 $t(d,e,t)}function $t(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.unshift({value:t[a],count:1});i>0&&(a===u?(o--,n.unshift({value:r[o],added:true,count:1})):(a--,n.unshift({value:t[a],removed:true,count:1})));}return n}function it(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 tt(e){if(!e)return [];let t=[],r="";for(let n=0;n<e.length;n++){let a=e[n];r+=a,a===`
2
2
  `&&(t.push(r),r="");}return r.length>0&&t.push(r),t}var rt="a-zA-Z0-9_\\u00AD\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C6\\u02C8-\\u02D7\\u02DE-\\u02FF\\u1E00-\\u1EFF",Ft=new RegExp(`[${rt}]+|\\s+|[^${rt}]`,"gu");function at(e){return e?e.match(Ft)||[]:[]}function nt(e,t){let r=0;for(;r<e.length&&r<t.length&&e[r]===t[r];)r++;return e.slice(0,r)}function Se(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 Kt(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=nt(a.value,o.value).match(/^\s*/)?.[0]||"",s=a.value.slice(d.length),c=o.value.slice(d.length),l=Se(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=Se(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&&Se(s,i).length===i.length){t.push({value:n.value.slice(i.length),removed:true,count:1});continue}if(d&&c&&nt(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 it(t)}function st(e,t){let r=tt(e),n=tt(t);return ot(r,n)}function lt(e,t){let r=at(e),n=at(t),a=ot(r,n);return Kt(a)}var ct=(e="",t="")=>useMemo(()=>{let r=(e||"").trim().replace(/\r\n/g,`
3
3
  `),n=(t||"").trim().replace(/\r\n/g,`
4
- `),a=st(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=lt(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]);function Zt(e){switch(e){case "chip":case "text":case "brackets":return "keySpan";case "source":return "source";default:return "number"}}function Jt(e){return e.replace(/^\[+\s*/,"").replace(/\s*\]+$/,"")}function qt(e,t,r){if(t==="indicator")return "";if(t==="keySpan"){let n=e.keySpan?.toString()||e.citationNumber?.toString()||r||"1";return Jt(n)}return t==="source"?e.siteName||e.domain||e.keySpan?.toString()||"Source":e.citationNumber?.toString()||"1"}function Qt(e){return e.isVerified&&!e.isPartialMatch?"Verified":e.isPartialMatch?"Partial Match":e.isMiss?"Not Found":e.isPending?"Verifying...":""}function er(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 tr({src:e,alt:t,onClose:r}){return useEffect(()=>{let n=a=>{a.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 rr=()=>jsx("span",{className:"inline-flex relative ml-0.5 size-2 text-green-600 dark:text-green-500","aria-hidden":"true",children:jsx(re,{})}),ar=()=>jsx("span",{className:"inline-flex relative ml-0.5 size-2 text-amber-600 dark:text-amber-500","aria-hidden":"true",children:jsx(re,{})}),nr=()=>jsx("span",{className:"inline-flex ml-1 size-2 animate-spin text-gray-400 dark:text-gray-500","aria-hidden":"true",children:jsx(se,{})}),or=()=>jsx("span",{className:"inline-flex relative ml-0.5 size-2 text-amber-500 dark:text-amber-400","aria-hidden":"true",children:jsx(ie,{})});function ir({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 sr({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)return jsxs("div",{className:"p-2",children:[jsxs("button",{type:"button",className:"group block cursor-zoom-in relative",onClick:m=>{m.preventDefault(),m.stopPropagation(),n?.();},"aria-label":"Click to view full size",children:[jsx("img",{src:t.verificationImageBase64,alt:"Citation verification",className:"max-w-full h-auto object-contain rounded-md bg-gray-50 dark:bg-gray-800",loading:"lazy"}),jsx("span",{className:"absolute inset-0 flex items-center justify-center bg-black/0 group-hover:bg-black/5 dark:group-hover:bg-white/5 transition-colors rounded-md",children:jsx("span",{className:"opacity-0 group-hover:opacity-100 transition-opacity text-xs text-gray-600 dark:text-gray-300 bg-white/90 dark:bg-gray-800/90 px-2 py-1 rounded shadow-sm",children:"Click to expand"})})]}),(s||c)&&jsx(dt,{citation:e,verification:t,status:r})]});if(a||u){let m=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(se,{})}),"Searching..."]}),m&&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:['"',m.length>80?m.slice(0,80)+"\u2026":m,'"']}),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(ie,{})}),"Not found: ",e.keySpan||e.fullPhrase]}),jsx(ir,{citation:e,verification:t,isExpanded:o,onExpandChange:i})]});let l=Qt(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:h("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(dt,{citation:e,verification:t,status:r})]})}function dt({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}=ct(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,m=t?.verifiedPageNumber,I=x!=null&&m!=null&&x!==m;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((B,h)=>jsx("span",{children:B.parts.map((k,N)=>{let S=`p-${h}-${N}`;return k.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:k.value},S):k.added?jsx("span",{className:"bg-green-200 dark:bg-green-900/50 text-green-700 dark:text-green-300",title:"Actual text found",children:k.value},S):jsx("span",{children:k.value},S)})},`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,I&&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 ",m]})]}),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 Me=forwardRef(({citation:e,children:t,className:r,fallbackDisplay:n,verification:a,isLoading:o=false,variant:i="brackets",content:d,eventHandlers:s,behaviorConfig:c,isMobile:u=false,renderIndicator:l$1,renderContent:g,popoverPosition:x="top",renderPopoverContent:m,additionalCount:I,faviconUrl:B},h$1)=>{let k=useMemo(()=>d||Zt(i),[d,i]),[N,S]=useState(false),[M,T]=useState(null),[W,A]=useState(false),C=useMemo(()=>j(e),[e]),U=useMemo(()=>l(C),[C]),O=useMemo(()=>er(a),[a]),{isMiss:v,isPartialMatch:P,isVerified:E,isPending:H}=O,de=5e3,[ue,Q]=useState(false),$=useRef(null),D=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",z=(o||H)&&!D&&!ue;useEffect(()=>($.current&&(clearTimeout($.current),$.current=null),(o||H)&&!D?(Q(false),$.current=setTimeout(()=>{Q(true);},de)):Q(false),()=>{$.current&&clearTimeout($.current);}),[o,H,D]);let G=useMemo(()=>qt(e,k,n),[e,k,n]),J=useCallback(()=>({citation:e,citationKey:C,verification:a??null,isTooltipExpanded:N,isImageExpanded:!!M,hasImage:!!a?.verificationImageBase64}),[e,C,a,N,M]),Ae=useCallback(w=>{w.setImageExpanded!==void 0&&(typeof w.setImageExpanded=="string"?T(w.setImageExpanded):w.setImageExpanded===true&&a?.verificationImageBase64?T(a.verificationImageBase64):w.setImageExpanded===false&&T(null));},[a?.verificationImageBase64]),xt=useCallback(w=>{w.preventDefault(),w.stopPropagation();let te=J();if(c?.onClick){let me=c.onClick(te,w);me&&typeof me=="object"&&Ae(me),s?.onClick?.(e,C,w);return}if(s?.onClick){s.onClick(e,C,w);return}a?.verificationImageBase64?T(a.verificationImageBase64):v&&A(me=>!me);},[c,s,e,C,a?.verificationImageBase64,v,J,Ae]),He=150,ee=useRef(null),be=useRef(false),q=useCallback(()=>{ee.current&&(clearTimeout(ee.current),ee.current=null);},[]),ht=useCallback(()=>{q(),S(true),c?.onHover?.onEnter&&c.onHover.onEnter(J()),s?.onMouseEnter?.(e,C);},[s,c,e,C,J,q]),yt=useCallback(()=>{q(),ee.current=setTimeout(()=>{be.current||(S(false),c?.onHover?.onLeave&&c.onHover.onLeave(J()),s?.onMouseLeave?.(e,C));},He);},[s,c,e,C,J,q]),vt=useCallback(()=>{q(),be.current=true;},[q]),bt=useCallback(()=>{be.current=false,q(),ee.current=setTimeout(()=>{S(false),c?.onHover?.onLeave&&c.onHover.onLeave(J()),s?.onMouseLeave?.(e,C);},He);},[s,c,e,C,J,q]);useEffect(()=>()=>{ee.current&&clearTimeout(ee.current);},[]);let kt=useCallback(w=>{u&&(w.preventDefault(),w.stopPropagation(),s?.onTouchEnd?.(e,C,w));},[s,e,C,u]);if(n!=null&&k==="keySpan"&&v)return jsx("span",{className:h("text-gray-400 dark:text-gray-500",r),children:n});let ke=h((E||P)&&i==="brackets"&&"text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 hover:underline",v&&"opacity-70 line-through text-gray-400 dark:text-gray-500",z&&"text-gray-500 dark:text-gray-400"),ae=()=>l$1?l$1(O):z?jsx(nr,{}):E&&!P?jsx(rr,{}):P?jsx(ar,{}):v?jsx(or,{}):null,$e=()=>{if(g)return g({citation:e,status:O,citationKey:C,displayText:G,isMergedDisplay:k==="keySpan"});if(k==="indicator")return jsx("span",{children:ae()});if(i==="chip"){let w=h(E&&!P&&!z&&"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",P&&!z&&"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",v&&!z&&"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400 line-through",z&&"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400",!E&&!v&&!z&&"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400");return jsxs("span",{className:h("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-sm font-medium",w),children:[jsx("span",{className:"max-w-60 overflow-hidden text-ellipsis whitespace-nowrap",children:G}),ae()]})}if(i==="superscript"){let w=h(E&&!P&&!z&&"text-green-600 dark:text-green-500",P&&!z&&"text-amber-600 dark:text-amber-500",v&&!z&&"text-red-500 dark:text-red-400 line-through",z&&"text-gray-400 dark:text-gray-500",!E&&!v&&!z&&"text-blue-600 dark:text-blue-400");return jsxs("sup",{className:h("text-xs font-medium transition-colors hover:underline",w),children:["[",G,ae(),"]"]})}if(i==="text")return jsxs("span",{className:ke,children:[G,ae()]});if(i==="minimal")return jsxs("span",{className:h("max-w-80 overflow-hidden text-ellipsis",ke),children:[G,ae()]});if(i==="source"){let w=B||e.faviconUrl;return jsxs("span",{className:h("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:[w&&jsx("img",{src:w,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:G}),I!==void 0&&I>0&&jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:["+",I]})]})}return jsxs("span",{className:h("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:h("max-w-80 overflow-hidden text-ellipsis",ke),children:[G,ae()]}),"]"]})},Ct=!(x==="hidden")&&(a&&(a.verificationImageBase64||a.verifiedMatchSnippet)||z||H||o||v),wt=!!a?.verificationImageBase64,Fe=M?jsx(tr,{src:M,alt:"Citation verification - full size",onClose:()=>T(null)}):null,Ke={"data-citation-id":C,"data-citation-instance":U,className:h("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",wt&&"cursor-zoom-in",r),onMouseEnter:ht,onMouseLeave:yt,onClick:xt,onTouchEndCapture:u?kt:void 0,"aria-label":G?`[${G}]`:void 0};if(Ct){let w=m?m({citation:e,verification:a??null,status:O}):jsx(sr,{citation:e,verification:a??null,status:O,isLoading:o||z,isPhrasesExpanded:W,onPhrasesExpandChange:A,onImageClick:()=>{a?.verificationImageBase64&&T(a.verificationImageBase64);}});return jsxs(Fragment,{children:[t,jsxs(Qe,{open:N,children:[jsx(et,{asChild:true,children:jsx("span",{ref:h$1,...Ke,children:$e()})}),jsx(Pe,{side:x==="bottom"?"bottom":"top",onPointerDownOutside:te=>te.preventDefault(),onInteractOutside:te=>te.preventDefault(),onMouseEnter:vt,onMouseLeave:bt,children:w})]}),Fe]})}return jsxs(Fragment,{children:[t,jsx("span",{ref:h$1,...Ke,children:$e()}),Fe]})});Me.displayName="CitationComponent";var lr=memo(Me);function pt(e,t){return t||`https://www.google.com/s2/favicons?domain=${X(e)}&sz=32`}function Re(e){if(!e.startsWith("http://")&&!e.startsWith("https://"))return "unknown";try{let t=X(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 Be(e,t){let r=(t||X(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 ur=()=>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"})]}),mr=()=>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"})}),pr=()=>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 m=useCallback(N=>{s?s({id:e,url:t,title:r,domain:n,sourceType:a,faviconUrl:o,citationNumbers:i,verificationStatus:d},N):window.open(t,"_blank","noopener,noreferrer");},[s,e,t,r,n,a,o,i,d]),I=useMemo(()=>Be(t,n),[t,n]),B=useMemo(()=>pt(t,o),[t,o]),h=useMemo(()=>a||Re(t),[a,t]),k=()=>{if(!u||!d)return null;let S={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:p("text-sm ml-1",S.className),"aria-label":d,children:S.icon})};return jsxs("div",{ref:x,"data-source-id":e,"data-source-type":h,className:p("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:m,role:"link",tabIndex:0,onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.preventDefault(),m(N));},"aria-label":`${r} from ${I}`,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:B,alt:"",className:"w-5 h-5 rounded",width:20,height:20,loading:"lazy",onError:N=>{N.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}),k()]}),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:I}),l&&i&&i.length>0&&jsxs("div",{className:"flex items-center gap-1",children:[i.slice(0,3).map(N=>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:N},N)),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(mr,{})})]})});ye.displayName="SourcesListItem";var Te=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:p("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:pt(c.url,c.faviconUrl),alt:"",className:p("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]})]})]})});Te.displayName="SourcesTrigger";var je=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:m,renderEmpty:I,renderLoading:B},h)=>{let k=useRef(null),[N,S]=useState(false);useEffect(()=>{if(!r||t==="inline")return;let v=P=>{P.key==="Escape"&&n?.(false);};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[r,n,t]),useEffect(()=>{S(true);},[]);let M=useMemo(()=>{if(!x)return null;let v={};for(let P of e){let E=P.domain||X(P.url);v[E]||(v[E]=[]),v[E].push(P);}return v},[e,x]),T=useCallback(()=>{n?.(false);},[n]),W=useCallback(v=>{v.target===v.currentTarget&&T();},[T]),A=()=>{let{title:v="Sources",showCloseButton:P=true,showCount:E=true,renderHeader:H}=a;return H?H({title:v,count:e.length,onClose:T}):jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-200 dark:border-gray-700",children:[P&&t!=="inline"&&jsx("button",{type:"button",onClick:T,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(ur,{})}),jsxs("h2",{className:"text-base font-semibold text-gray-900 dark:text-gray-100 flex-1 text-center",children:[v,E&&jsxs("span",{className:"ml-2 text-sm font-normal text-gray-500 dark:text-gray-400",children:["(",e.length,")"]})]}),P&&t!=="inline"&&jsx("div",{className:"w-8"})]})},C=()=>o?B?B():jsxs("div",{className:"flex items-center justify-center py-8 text-gray-500 dark:text-gray-400",children:[jsx(pr,{}),jsx("span",{className:"ml-2 text-sm",children:"Loading sources..."})]}):e.length===0?I?I():jsx("div",{className:"flex items-center justify-center py-8 text-gray-500 dark:text-gray-400 text-sm",children:i}):x&&M?jsx("div",{className:c,children:Object.entries(M).map(([v,P])=>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:Be(P[0].url,v)}),P.map((E,H)=>m?m(E,H):jsx(ye,{...E,onClick:u,showVerificationIndicator:l,showCitationBadges:g},E.id))]},v))}):jsx("div",{className:c,children:e.map((v,P)=>m?m(v,P):jsx(ye,{...v,onClick:u,showVerificationIndicator:l,showCitationBadges:g},v.id))}),U=d?{maxHeight:typeof d=="number"?`${d}px`:d}:void 0;if(t==="inline")return r?jsxs("div",{ref:h,className:p("bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700",s),style:U,children:[A(),jsx("div",{className:"overflow-y-auto",style:U,children:C()})]}):null;if(t==="panel")return r?jsxs("div",{ref:h,className:p("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:U||{maxHeight:"400px"},children:C()})]}):null;if(!N||!r)return null;let O=jsxs("div",{ref:h,className:p("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:p("absolute inset-0 bg-black/40 dark:bg-black/60 transition-opacity",r?"opacity-100":"opacity-0"),onClick:W,"aria-hidden":"true"}),t==="drawer"?jsxs("div",{ref:k,className:p("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:C()})]}):jsxs("div",{ref:k,className:p("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:C()})]})]});return createPortal(O,document.body)});je.displayName="SourcesListComponent";var gr=memo(ye),fr=memo(Te),xr=memo(je);function hr(e){let t=new Map;for(let r of e){if(!r.url)continue;let n=r.domain||X(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||Re(r.url),faviconUrl:r.faviconUrl,citationNumbers:r.citationNumber?[r.citationNumber]:[]});}return Array.from(t.values())}function yr(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 ft(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||Ue(a.url)||"Unknown Source",sourceDomain:a.domain||Ue(a.url),sourceFavicon:a.faviconUrl||void 0,citations:n,additionalCount:n.length-1}})}function Ue(e){if(e)try{return new URL(e).hostname.replace(/^www\./,"")}catch{return}}function br(e){let t=e?.status;return !t||t==="pending"||t==="loading"?{color:"text-gray-400",icon:jsx(se,{}),label:"Verifying"}:t==="not_found"?{color:"text-amber-500",icon:jsx(ie,{}),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(re,{}),label:"Partial match"}:{color:"text-green-500",icon:jsx(re,{}),label:"Verified"}}function We({item:e,isLast:t=false,onClick:r,onReadMore:n,className:a}){let{citation:o,verification:i}=e,d=br(i),s=o.siteName||o.domain||Ue(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(m=>{m.stopPropagation(),n?.(e);},[e,n]);return jsx("div",{className:h("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:m=>{(m.key==="Enter"||m.key===" ")&&(m.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:m=>{m.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:h("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 kr({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]),m=useMemo(()=>!a||l?x:x.slice(0,o),[x,a,l,o]),I=useMemo(()=>!a||l?[]:x.slice(o),[x,a,l,o]);if(ze__default.useEffect(()=>{if(!e)return;let h=k=>{k.key==="Escape"&&t();};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[e,t]),!e)return null;let B=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:h("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:m.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:[m.map((h,k)=>u?jsx(ze__default.Fragment,{children:u(h)},h.citationKey):jsx(We,{item:h,isLast:k===m.length-1&&I.length===0,onClick:i,onReadMore:d},h.citationKey)),I.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 (",I.length,")"]})}),l&&I.map((h,k)=>u?jsx(ze__default.Fragment,{children:u(h)},h.citationKey):jsx(We,{item:h,isLast:k===I.length-1,onClick:i,onReadMore:d},h.citationKey))]})})]})]});return createPortal(B,document.body)}function Cr(){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(m=>m.citationKey===g.citationKey)?x:[...x,g]);},[]),s=useCallback(g=>{n(x=>x.filter(m=>m.citationKey!==g));},[]),c=useCallback(()=>{n([]);},[]),u=useCallback(g=>{n(g);},[]),l=useMemo(()=>ft(r),[r]);return {isOpen:e,openDrawer:a,closeDrawer:o,toggleDrawer:i,citations:r,citationGroups:l,addCitation:d,removeCitation:s,clearCitations:c,setCitations:u}}
4
+ `),a=st(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=lt(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]);function Zt(e){switch(e){case "chip":case "text":case "brackets":return "keySpan";case "source":return "source";default:return "number"}}function Jt(e){return e.replace(/^\[+\s*/,"").replace(/\s*\]+$/,"")}function qt(e,t,r){if(t==="indicator")return "";if(t==="keySpan"){let n=e.keySpan?.toString()||e.citationNumber?.toString()||r||"1";return Jt(n)}return t==="source"?e.siteName||e.domain||e.keySpan?.toString()||"Source":e.citationNumber?.toString()||"1"}function Qt(e){return e.isVerified&&!e.isPartialMatch?"Verified":e.isPartialMatch?"Partial Match":e.isMiss?"Not Found":e.isPending?"Verifying...":""}function er(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 tr({src:e,alt:t,onClose:r}){return useEffect(()=>{let n=a=>{a.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 rr=()=>jsx("span",{className:"inline-flex relative ml-0.5 size-2 text-green-600 dark:text-green-500","aria-hidden":"true",children:jsx(re,{})}),ar=()=>jsx("span",{className:"inline-flex relative ml-0.5 size-2 text-amber-600 dark:text-amber-500","aria-hidden":"true",children:jsx(re,{})}),nr=()=>jsx("span",{className:"inline-flex ml-1 size-2 animate-spin text-gray-400 dark:text-gray-500","aria-hidden":"true",children:jsx(se,{})}),or=()=>jsx("span",{className:"inline-flex relative ml-0.5 size-2 text-amber-500 dark:text-amber-400","aria-hidden":"true",children:jsx(ie,{})});function ir({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 sr({citation:e,verification:t,status:r,onImageClick:n,isLoading:a=false,isPhrasesExpanded:o,onPhrasesExpandChange:i$1}){let d=t?.verificationImageBase64,{isMiss:s,isPartialMatch:c,isPending:u}=r;if(d)return jsxs("div",{className:"p-2",children:[jsxs("button",{type:"button",className:"group block cursor-zoom-in relative",onClick:m=>{m.preventDefault(),m.stopPropagation(),n?.();},"aria-label":"Click to view full size",children:[jsx("img",{src:t.verificationImageBase64,alt:"Citation verification",className:"max-w-full h-auto object-contain rounded-md bg-gray-50 dark:bg-gray-800",loading:"lazy"}),jsx("span",{className:"absolute inset-0 flex items-center justify-center bg-black/0 group-hover:bg-black/5 dark:group-hover:bg-white/5 transition-colors rounded-md",children:jsx("span",{className:"opacity-0 group-hover:opacity-100 transition-opacity text-xs text-gray-600 dark:text-gray-300 bg-white/90 dark:bg-gray-800/90 px-2 py-1 rounded shadow-sm",children:"Click to expand"})})]}),(s||c)&&jsx(dt,{citation:e,verification:t,status:r})]});if(a||u){let m=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(se,{})}),"Searching..."]}),m&&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:['"',m.length>80?m.slice(0,80)+"\u2026":m,'"']}),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(ie,{})}),"Not found: ",e.keySpan||e.fullPhrase]}),jsx(ir,{citation:e,verification:t,isExpanded:o,onExpandChange:i$1})]});let l=Qt(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:i("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(dt,{citation:e,verification:t,status:r})]})}function dt({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}=ct(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,m=t?.verifiedPageNumber,I=x!=null&&m!=null&&x!==m;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((B,h)=>jsx("span",{children:B.parts.map((k,N)=>{let S=`p-${h}-${N}`;return k.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:k.value},S):k.added?jsx("span",{className:"bg-green-200 dark:bg-green-900/50 text-green-700 dark:text-green-300",title:"Actual text found",children:k.value},S):jsx("span",{children:k.value},S)})},`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,I&&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 ",m]})]}),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 Me=forwardRef(({citation:e,children:t,className:r,fallbackDisplay:n,verification:a,isLoading:o=false,variant:i$1="brackets",content:d,eventHandlers:s,behaviorConfig:c,isMobile:u=false,renderIndicator:l,renderContent:g,popoverPosition:x="top",renderPopoverContent:m$1,additionalCount:I,faviconUrl:B},h)=>{let k$1=useMemo(()=>d||Zt(i$1),[d,i$1]),[N,S]=useState(false),[M,T]=useState(null),[W,A]=useState(false),C=useMemo(()=>k(e),[e]),U=useMemo(()=>m(C),[C]),O=useMemo(()=>er(a),[a]),{isMiss:v,isPartialMatch:P,isVerified:E,isPending:H}=O,de=5e3,[ue,Q]=useState(false),$=useRef(null),D=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",z=(o||H)&&!D&&!ue;useEffect(()=>($.current&&(clearTimeout($.current),$.current=null),(o||H)&&!D?(Q(false),$.current=setTimeout(()=>{Q(true);},de)):Q(false),()=>{$.current&&clearTimeout($.current);}),[o,H,D]);let G=useMemo(()=>qt(e,k$1,n),[e,k$1,n]),J=useCallback(()=>({citation:e,citationKey:C,verification:a??null,isTooltipExpanded:N,isImageExpanded:!!M,hasImage:!!a?.verificationImageBase64}),[e,C,a,N,M]),Ae=useCallback(w=>{w.setImageExpanded!==void 0&&(typeof w.setImageExpanded=="string"?T(w.setImageExpanded):w.setImageExpanded===true&&a?.verificationImageBase64?T(a.verificationImageBase64):w.setImageExpanded===false&&T(null));},[a?.verificationImageBase64]),xt=useCallback(w=>{w.preventDefault(),w.stopPropagation();let te=J();if(c?.onClick){let me=c.onClick(te,w);me&&typeof me=="object"&&Ae(me),s?.onClick?.(e,C,w);return}if(s?.onClick){s.onClick(e,C,w);return}a?.verificationImageBase64?T(a.verificationImageBase64):v&&A(me=>!me);},[c,s,e,C,a?.verificationImageBase64,v,J,Ae]),He=150,ee=useRef(null),be=useRef(false),q=useCallback(()=>{ee.current&&(clearTimeout(ee.current),ee.current=null);},[]),ht=useCallback(()=>{q(),S(true),c?.onHover?.onEnter&&c.onHover.onEnter(J()),s?.onMouseEnter?.(e,C);},[s,c,e,C,J,q]),yt=useCallback(()=>{q(),ee.current=setTimeout(()=>{be.current||(S(false),c?.onHover?.onLeave&&c.onHover.onLeave(J()),s?.onMouseLeave?.(e,C));},He);},[s,c,e,C,J,q]),vt=useCallback(()=>{q(),be.current=true;},[q]),bt=useCallback(()=>{be.current=false,q(),ee.current=setTimeout(()=>{S(false),c?.onHover?.onLeave&&c.onHover.onLeave(J()),s?.onMouseLeave?.(e,C);},He);},[s,c,e,C,J,q]);useEffect(()=>()=>{ee.current&&clearTimeout(ee.current);},[]);let kt=useCallback(w=>{u&&(w.preventDefault(),w.stopPropagation(),s?.onTouchEnd?.(e,C,w));},[s,e,C,u]);if(n!=null&&k$1==="keySpan"&&v)return jsx("span",{className:i("text-gray-400 dark:text-gray-500",r),children:n});let ke=i((E||P)&&i$1==="brackets"&&"text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 hover:underline",v&&"opacity-70 line-through text-gray-400 dark:text-gray-500",z&&"text-gray-500 dark:text-gray-400"),ae=()=>l?l(O):z?jsx(nr,{}):E&&!P?jsx(rr,{}):P?jsx(ar,{}):v?jsx(or,{}):null,$e=()=>{if(g)return g({citation:e,status:O,citationKey:C,displayText:G,isMergedDisplay:k$1==="keySpan"});if(k$1==="indicator")return jsx("span",{children:ae()});if(i$1==="chip"){let w=i(E&&!P&&!z&&"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",P&&!z&&"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",v&&!z&&"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400 line-through",z&&"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400",!E&&!v&&!z&&"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400");return jsxs("span",{className:i("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-sm font-medium",w),children:[jsx("span",{className:"max-w-60 overflow-hidden text-ellipsis whitespace-nowrap",children:G}),ae()]})}if(i$1==="superscript"){let w=i(E&&!P&&!z&&"text-green-600 dark:text-green-500",P&&!z&&"text-amber-600 dark:text-amber-500",v&&!z&&"text-red-500 dark:text-red-400 line-through",z&&"text-gray-400 dark:text-gray-500",!E&&!v&&!z&&"text-blue-600 dark:text-blue-400");return jsxs("sup",{className:i("text-xs font-medium transition-colors hover:underline",w),children:["[",G,ae(),"]"]})}if(i$1==="text")return jsxs("span",{className:ke,children:[G,ae()]});if(i$1==="minimal")return jsxs("span",{className:i("max-w-80 overflow-hidden text-ellipsis",ke),children:[G,ae()]});if(i$1==="source"){let w=B||e.faviconUrl;return jsxs("span",{className:i("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:[w&&jsx("img",{src:w,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:G}),I!==void 0&&I>0&&jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:["+",I]})]})}return jsxs("span",{className:i("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:i("max-w-80 overflow-hidden text-ellipsis",ke),children:[G,ae()]}),"]"]})},Ct=!(x==="hidden")&&(a&&(a.verificationImageBase64||a.verifiedMatchSnippet)||z||H||o||v),wt=!!a?.verificationImageBase64,Fe=M?jsx(tr,{src:M,alt:"Citation verification - full size",onClose:()=>T(null)}):null,Ke={"data-citation-id":C,"data-citation-instance":U,className:i("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",wt&&"cursor-zoom-in",r),onMouseEnter:ht,onMouseLeave:yt,onClick:xt,onTouchEndCapture:u?kt:void 0,"aria-label":G?`[${G}]`:void 0};if(Ct){let w=m$1?m$1({citation:e,verification:a??null,status:O}):jsx(sr,{citation:e,verification:a??null,status:O,isLoading:o||z,isPhrasesExpanded:W,onPhrasesExpandChange:A,onImageClick:()=>{a?.verificationImageBase64&&T(a.verificationImageBase64);}});return jsxs(Fragment,{children:[t,jsxs(Qe,{open:N,children:[jsx(et,{asChild:true,children:jsx("span",{ref:h,...Ke,children:$e()})}),jsx(Pe,{side:x==="bottom"?"bottom":"top",onPointerDownOutside:te=>te.preventDefault(),onInteractOutside:te=>te.preventDefault(),onMouseEnter:vt,onMouseLeave:bt,children:w})]}),Fe]})}return jsxs(Fragment,{children:[t,jsx("span",{ref:h,...Ke,children:$e()}),Fe]})});Me.displayName="CitationComponent";var lr=memo(Me);function pt(e,t){return t||`https://www.google.com/s2/favicons?domain=${X(e)}&sz=32`}function Re(e){if(!e.startsWith("http://")&&!e.startsWith("https://"))return "unknown";try{let t=X(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 Be(e,t){let r=(t||X(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 ur=()=>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"})]}),mr=()=>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"})}),pr=()=>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 m=useCallback(N=>{s?s({id:e,url:t,title:r,domain:n,sourceType:a,faviconUrl:o,citationNumbers:i,verificationStatus:d},N):window.open(t,"_blank","noopener,noreferrer");},[s,e,t,r,n,a,o,i,d]),I=useMemo(()=>Be(t,n),[t,n]),B=useMemo(()=>pt(t,o),[t,o]),h=useMemo(()=>a||Re(t),[a,t]),k=()=>{if(!u||!d)return null;let S={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:q("text-sm ml-1",S.className),"aria-label":d,children:S.icon})};return jsxs("div",{ref:x,"data-source-id":e,"data-source-type":h,className:q("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:m,role:"link",tabIndex:0,onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.preventDefault(),m(N));},"aria-label":`${r} from ${I}`,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:B,alt:"",className:"w-5 h-5 rounded",width:20,height:20,loading:"lazy",onError:N=>{N.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}),k()]}),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:I}),l&&i&&i.length>0&&jsxs("div",{className:"flex items-center gap-1",children:[i.slice(0,3).map(N=>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:N},N)),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(mr,{})})]})});ye.displayName="SourcesListItem";var Te=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:q("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:pt(c.url,c.faviconUrl),alt:"",className:q("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]})]})]})});Te.displayName="SourcesTrigger";var je=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:m,renderEmpty:I,renderLoading:B},h)=>{let k=useRef(null),[N,S]=useState(false);useEffect(()=>{if(!r||t==="inline")return;let v=P=>{P.key==="Escape"&&n?.(false);};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[r,n,t]),useEffect(()=>{S(true);},[]);let M=useMemo(()=>{if(!x)return null;let v={};for(let P of e){let E=P.domain||X(P.url);v[E]||(v[E]=[]),v[E].push(P);}return v},[e,x]),T=useCallback(()=>{n?.(false);},[n]),W=useCallback(v=>{v.target===v.currentTarget&&T();},[T]),A=()=>{let{title:v="Sources",showCloseButton:P=true,showCount:E=true,renderHeader:H}=a;return H?H({title:v,count:e.length,onClose:T}):jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-200 dark:border-gray-700",children:[P&&t!=="inline"&&jsx("button",{type:"button",onClick:T,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(ur,{})}),jsxs("h2",{className:"text-base font-semibold text-gray-900 dark:text-gray-100 flex-1 text-center",children:[v,E&&jsxs("span",{className:"ml-2 text-sm font-normal text-gray-500 dark:text-gray-400",children:["(",e.length,")"]})]}),P&&t!=="inline"&&jsx("div",{className:"w-8"})]})},C=()=>o?B?B():jsxs("div",{className:"flex items-center justify-center py-8 text-gray-500 dark:text-gray-400",children:[jsx(pr,{}),jsx("span",{className:"ml-2 text-sm",children:"Loading sources..."})]}):e.length===0?I?I():jsx("div",{className:"flex items-center justify-center py-8 text-gray-500 dark:text-gray-400 text-sm",children:i}):x&&M?jsx("div",{className:c,children:Object.entries(M).map(([v,P])=>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:Be(P[0].url,v)}),P.map((E,H)=>m?m(E,H):jsx(ye,{...E,onClick:u,showVerificationIndicator:l,showCitationBadges:g},E.id))]},v))}):jsx("div",{className:c,children:e.map((v,P)=>m?m(v,P):jsx(ye,{...v,onClick:u,showVerificationIndicator:l,showCitationBadges:g},v.id))}),U=d?{maxHeight:typeof d=="number"?`${d}px`:d}:void 0;if(t==="inline")return r?jsxs("div",{ref:h,className:q("bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700",s),style:U,children:[A(),jsx("div",{className:"overflow-y-auto",style:U,children:C()})]}):null;if(t==="panel")return r?jsxs("div",{ref:h,className:q("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:U||{maxHeight:"400px"},children:C()})]}):null;if(!N||!r)return null;let O=jsxs("div",{ref:h,className:q("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:q("absolute inset-0 bg-black/40 dark:bg-black/60 transition-opacity",r?"opacity-100":"opacity-0"),onClick:W,"aria-hidden":"true"}),t==="drawer"?jsxs("div",{ref:k,className:q("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:C()})]}):jsxs("div",{ref:k,className:q("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:C()})]})]});return createPortal(O,document.body)});je.displayName="SourcesListComponent";var gr=memo(ye),fr=memo(Te),xr=memo(je);function hr(e){let t=new Map;for(let r of e){if(!r.url)continue;let n=r.domain||X(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||Re(r.url),faviconUrl:r.faviconUrl,citationNumbers:r.citationNumber?[r.citationNumber]:[]});}return Array.from(t.values())}function yr(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 ft(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||Ue(a.url)||"Unknown Source",sourceDomain:a.domain||Ue(a.url),sourceFavicon:a.faviconUrl||void 0,citations:n,additionalCount:n.length-1}})}function Ue(e){if(e)try{return new URL(e).hostname.replace(/^www\./,"")}catch{return}}function br(e){let t=e?.status;return !t||t==="pending"||t==="loading"?{color:"text-gray-400",icon:jsx(se,{}),label:"Verifying"}:t==="not_found"?{color:"text-amber-500",icon:jsx(ie,{}),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(re,{}),label:"Partial match"}:{color:"text-green-500",icon:jsx(re,{}),label:"Verified"}}function We({item:e,isLast:t=false,onClick:r,onReadMore:n,className:a}){let{citation:o,verification:i$1}=e,d=br(i$1),s=o.siteName||o.domain||Ue(o.url)||"Source",c=o.title||o.keySpan||o.fullPhrase,u=o.description||i$1?.actualContentSnippet||i$1?.verifiedMatchSnippet,l=o.faviconUrl,g=useCallback(()=>{r?.(e);},[e,r]),x=useCallback(m=>{m.stopPropagation(),n?.(e);},[e,n]);return jsx("div",{className:i("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:m=>{(m.key==="Enter"||m.key===" ")&&(m.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:m=>{m.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:i("inline-flex w-3 h-3",d.color,i$1?.status==="pending"||i$1?.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 kr({isOpen:e,onClose:t,citationGroups:r,title:n="Citations",showMoreSection:a=true,maxVisibleItems:o=3,onCitationClick:i$1,onReadMore:d,className:s,position:c="bottom",renderCitationItem:u}){let[l,g]=useState(false),x=useMemo(()=>r.flatMap(h=>h.citations),[r]),m=useMemo(()=>!a||l?x:x.slice(0,o),[x,a,l,o]),I=useMemo(()=>!a||l?[]:x.slice(o),[x,a,l,o]);if(ze__default.useEffect(()=>{if(!e)return;let h=k=>{k.key==="Escape"&&t();};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[e,t]),!e)return null;let B=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:i("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:m.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:[m.map((h,k)=>u?jsx(ze__default.Fragment,{children:u(h)},h.citationKey):jsx(We,{item:h,isLast:k===m.length-1&&I.length===0,onClick:i$1,onReadMore:d},h.citationKey)),I.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 (",I.length,")"]})}),l&&I.map((h,k)=>u?jsx(ze__default.Fragment,{children:u(h)},h.citationKey):jsx(We,{item:h,isLast:k===I.length-1,onClick:i$1,onReadMore:d},h.citationKey))]})})]})]});return createPortal(B,document.body)}function Cr(){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(m=>m.citationKey===g.citationKey)?x:[...x,g]);},[]),s=useCallback(g=>{n(x=>x.filter(m=>m.citationKey!==g));},[]),c=useCallback(()=>{n([]);},[]),u=useCallback(g=>{n(g);},[]),l=useMemo(()=>ft(r),[r]);return {isOpen:e,openDrawer:a,closeDrawer:o,toggleDrawer:i,citations:r,citationGroups:l,addCitation:d,removeCitation:s,clearCitations:c,setCitations:u}}
5
5
  export{re as CheckIcon,Me as CitationComponent,kr as CitationDrawer,We as CitationDrawerItemComponent,Wt as CloseIcon,zt as DeepCitationIcon,Ut as ExternalLinkIcon,Vt as LinkIcon,lr as MemoizedCitationComponent,xr as MemoizedSourcesListComponent,gr as MemoizedSourcesListItem,fr as MemoizedSourcesTrigger,je as SourcesListComponent,ye as SourcesListItem,Te as SourcesTrigger,se as SpinnerIcon,ie as WarningIcon,Re as detectSourceType,X as extractDomain,Be as getPlatformName,ft as groupCitationsBySource,Rt as isAccessibleStatus,Xe as isBlockedStatus,Ye as isErrorStatus,Bt as isRedirectedStatus,Tt as isVerifiedStatus,hr as sourceCitationsToListItems,Cr as useCitationDrawer,yr as useSourcesList};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepcitation/deepcitation-js",
3
- "version": "1.1.40",
3
+ "version": "1.1.41",
4
4
  "description": "DeepCitation JavaScript SDK for deterministic AI citation verification",
5
5
  "type": "module",
6
6
  "private": false,
@@ -1 +0,0 @@
1
- function E(t){return new TextEncoder().encode(t)}function Z(t){let e=1732584193,i=4023233417,r=2562383102,n=271733878,o=3285377520,p=t.length,a=p*8,c=p+1+8,u=Math.ceil(c/64)*64,s=new ArrayBuffer(u),C=new Uint8Array(s),d=new DataView(s);C.set(t),C[p]=128,d.setUint32(u-8,Math.floor(a/4294967296),false),d.setUint32(u-4,a>>>0,false);let l=new Uint32Array(80);for(let x=0;x<u;x+=64){for(let g=0;g<16;g++)l[g]=d.getUint32(x+g*4,false);for(let g=16;g<80;g++){let I=l[g-3]^l[g-8]^l[g-14]^l[g-16];l[g]=I<<1|I>>>31;}let f=e,h=i,_=r,k=n,S=o;for(let g=0;g<80;g++){let I,m;g<20?(I=h&_|~h&k,m=1518500249):g<40?(I=h^_^k,m=1859775393):g<60?(I=h&_|h&k|_&k,m=2400959708):(I=h^_^k,m=3395469782);let b=(f<<5|f>>>27)+I+S+m+l[g]>>>0;S=k,k=_,_=(h<<30|h>>>2)>>>0,h=f,f=b;}e=e+f>>>0,i=i+h>>>0,r=r+_>>>0,n=n+k>>>0,o=o+S>>>0;}let y=x=>x.toString(16).padStart(8,"0");return y(e)+y(i)+y(r)+y(n)+y(o)}function P(t){try{if(!t)return "";let e=typeof t=="string"?t:JSON.stringify(t);return Z(E(e))}catch(e){console.error("Error in making the hash:",e);}return ""}function Y(...t){return t.filter(Boolean).join(" ")}function U(t){return t.type==="url"||typeof t.url=="string"&&t.url.length>0}function A(t){let e=t.pageNumber||v(t.startPageKey),i=[t.attachmentId||"",e?.toString()||"",t.fullPhrase||"",t.keySpan?.toString()||"",t.lineIds?.join(",")||"",t.timestamps?.startTime||"",t.timestamps?.endTime||""];return U(t)&&i.push(t.url||"",t.title||"",t.domain||""),P(i.join("|")).slice(0,16)}function j(t){let e=[t.attachmentId||"",t.label||"",t.verifiedFullPhrase||"",t.verifiedKeySpan||"",t.verifiedLineIds?.join(",")||"",t.verifiedPageNumber?.toString()||"",t.verifiedTimestamps?.startTime||"",t.verifiedTimestamps?.endTime||"",t.verifiedMatchSnippet||"",t.hitIndexWithinPage?.toString()||""];return P(e.join("|")).slice(0,16)}function Q(t){let e=Math.random().toString(36).slice(2,11);return `${t}-${e}`}function tt(t,e={}){let{fallbackDisplay:i}=e;return t.keySpan?.toString()||t.citationNumber?.toString()||i||"1"}function et(t){return t.citationNumber?.toString()||"1"}function nt(t){return t.keySpan?.toString()||""}function it(...t){return t.filter(Boolean).join(" ")}var rt=4,st=1;function D(t){if(!t)return;let e=[],i=t.split(",");for(let r of i){let n=r.trim();if(n)if(n.includes("-")){let[o,p]=n.split("-"),a=parseInt(o,10),c=parseInt(p,10);if(!isNaN(a)&&!isNaN(c)&&a<=c)for(let u=a;u<=c;u++)e.push(u);else isNaN(a)||e.push(a);}else {let o=parseInt(n,10);isNaN(o)||e.push(o);}}if(e.length!==0)return [...new Set(e)].sort((r,n)=>r-n)}function R(t){let e=t?.status,i=e==="not_found",r=e==="found_phrase_missed_value",n=e==="found_key_span_only",o=e==="partial_text_found"||e==="found_on_other_page"||e==="found_on_other_line"||e==="first_word_found";return {isVerified:e==="found"||n||o||r,isMiss:i,isPartialMatch:o,isPending:e==="pending"||e==="loading"||!e}}var B=(t,e,i,r)=>{let n=m=>m?m.replace(/^['"]|['"]$/g,"").replace(/\\'/g,"'"):void 0,o=i?.current?i.current++:void 0,p=t.substring(0,t.indexOf("<cite")),a=t.includes("/>")?t.slice(t.indexOf("/>")+2):"",c=t.substring(t.indexOf("<cite"),t.indexOf("/>")+2),u=(m,b)=>{for(let O of b){let L=new RegExp(`${O}='((?:[^'\\\\]|\\\\.)*)'`),K=m.match(L);if(K)return K[1]}},s=u(c,["attachment_id","attachmentId","file_id","fileId"]),C=s?.length===20?s:e||s,d=u(c,["start_page_key","startPageKey","start_page"]),l,y;if(d){let m=d.match(/page[\_a-zA-Z]*(\d+)_index_(\d+)/);m&&(l=parseInt(m[1]),y=parseInt(m[2]));}let x=n(u(c,["full_phrase","fullPhrase"])),f=n(u(c,["key_span","keySpan"])),h=n(u(c,["reasoning"])),_=n(u(c,["value"])),k;try{let b=u(c,["line_ids","lineIds"])?.replace(/[A-Za-z_[\](){}:]/g,"");k=b?D(b):void 0;}catch(m){r&&console.error("Error parsing lineIds",m);}let S=u(c,["timestamps"]),g;if(S){let[m,b]=S.split("-")||[];g={startTime:m,endTime:b};}let I={attachmentId:C,pageNumber:l,startPageKey:`page_number_${l||1}_index_${y||0}`,fullPhrase:x,keySpan:f||_,citationNumber:o,lineIds:k,beforeCite:p,timestamps:g,reasoning:h};return {beforeCite:p,afterCite:a,citation:I}},J=(t,e)=>{if(!t)return null;let i=t.fullPhrase??t.full_phrase,r=t.startPageKey??t.start_page_key,n=t.keySpan??t.key_span,o=t.lineIds??t.line_ids,p=t.attachmentId??t.attachment_id??t.fileId??t.file_id,a=t.reasoning,c=t.value;if(!i)return null;let u;if(r){let d=r.match(/page[_a-zA-Z]*(\d+)_index_(\d+)/i);if(d)u=parseInt(d[1],10);else {let l=r.match(/^(\d+)_(\d+)$/);l&&(u=parseInt(l[1],10));}}let s=o?.length?[...o].sort((d,l)=>d-l):void 0;return {attachmentId:p,pageNumber:u,fullPhrase:i,citationNumber:e,lineIds:s,keySpan:n||c,reasoning:a}},V=t=>typeof t=="object"&&t!==null&&("fullPhrase"in t||"full_phrase"in t||"startPageKey"in t||"start_page_key"in t||"keySpan"in t||"key_span"in t||"lineIds"in t||"line_ids"in t),N=t=>Array.isArray(t)?t.length>0&&t.some(V):typeof t=="object"&&t!==null?V(t):false,M=t=>{let e={},i=Array.isArray(t)?t:[t],r=1;for(let n of i){let o=J(n,r++);if(o&&o.fullPhrase){let p=A(o);e[p]=o;}}return e},w=(t,e)=>{if(!(!t||typeof t!="object")){if(t.citation&&N(t.citation)){let i=Array.isArray(t.citation)?t.citation:[t.citation];e.push(...i);}if(t.citations&&N(t.citations)){let i=Array.isArray(t.citations)?t.citations:[t.citations];e.push(...i);}if(Array.isArray(t))for(let i of t)w(i,e);else for(let i of Object.keys(t))i!=="citation"&&i!=="citations"&&w(t[i],e);}},T=t=>{let e=$(t),i=/<cite\s+[^>]*\/>/g,r=e.match(i);if(!r||r.length===0)return {};let n={},o={current:1};for(let p of r){let{citation:a}=B(p,void 0,o);if(a&&a.fullPhrase){let c=A(a);n[c]=a;}}return n},lt=t=>{if(!t)return {};let e={};if(typeof t=="object"){if(N(t)){let n=M(t);Object.assign(e,n);}else {let n=[];if(w(t,n),n.length>0){let o=M(n);Object.assign(e,o);}}let i=JSON.stringify(t),r=T(i);Object.assign(e,r);}else if(typeof t=="string"){let i=T(t);Object.assign(e,i);}return e};function ut(t){let e=new Map,i=Array.isArray(t)?t.map((r,n)=>[A(r)||String(n+1),r]):Object.entries(t);for(let[r,n]of i){let o=n.attachmentId||"";e.has(o)||e.set(o,{}),e.get(o)[r]=n;}return e}function pt(t){let e={},i=Array.isArray(t)?t.map((r,n)=>[A(r)||String(n+1),r]):Object.entries(t);for(let[r,n]of i){let o=n.attachmentId||"";e[o]||(e[o]={}),e[o][r]=n;}return e}var F=t=>{let e={},i=/([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*(['"])((?:[^'"\\]|\\.)*)\2/g,r;for(;(r=i.exec(t))!==null;){let n=r[1].toLowerCase().replace(/([a-z])([A-Z])/g,"$1_$2").toLowerCase(),o=r[3],p=n==="fileid"||n==="file_id"||n==="attachmentid"?"attachment_id":n==="keyspan"?"key_span":n==="fullphrase"?"full_phrase":n==="lineids"?"line_ids":n==="startpagekey"||n==="start_pagekey"?"start_page_key":n;e[p]=o;}return e},W=t=>{if(!t)return "\u25CC";let e=R(t);return e.isPending?"\u25CC":e.isMiss?"\u2717":e.isPartialMatch?"\u26A0":e.isVerified?"\u2713":"\u25CC"},H=(t,e={})=>{let{leaveKeySpanBehind:i=false,verifications:r,showVerificationStatus:n=false}=e,o=0,p=/<cite\s+[^>]*?\/>/g;return t.replace(p,a=>{o++;let c=F(a),u="";if(i&&c.key_span&&(u=c.key_span.replace(/\\'/g,"'").replace(/\\"/g,'"')),n&&r){let s,C=String(o);if(s=r[C],!s&&c.attachment_id){for(let[,l]of Object.entries(r))if(l.attachmentId===c.attachment_id){s=l;break}}let d=W(s);u=u?`${u}${d}`:d;}return u})},dt=(t,e)=>H(t,{leaveKeySpanBehind:e}),mt=t=>t.replace(/<page_number_\d+_index_\d+>/g,"").replace(/<\/page_number_\d+_index_\d+>/g,"").trim(),ht=t=>{let e=/<line id="[^"]*">|<\/line>/g;return t.replace(e,"")},v=t=>{if(!t)return null;let e=t.match(/\d+/)?.[0];return e?parseInt(e):null},$=t=>{let e=t?.trim()||"",i=e.split(/(<cite[\s\S]*?(?:\/>|<\/cite>))/gm);return i.length<=1?z(e):(e=i.map(r=>r.startsWith("<cite")?z(r):r).join(""),e)},z=t=>{let e=t;e=e.replace(/><\/cite>/g,"/>");let i=p=>{let a=p.toLowerCase();return a==="fullphrase"||a==="full_phrase"?"full_phrase":a==="lineids"||a==="line_ids"?"line_ids":a==="startpagekey"||a==="start_pagekey"||a==="start_page_key"?"start_page_key":a==="fileid"||a==="file_id"||a==="attachmentid"||a==="attachment_id"?"attachment_id":a==="keyspan"||a==="key_span"?"key_span":a==="reasoning"||a==="value"?a:a==="timestamps"||a==="timestamp"||a==="timestamps"?"timestamps":a},r=p=>p.replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&"),n=/(fullPhrase|full_phrase|keySpan|key_span|reasoning|value)\s*=\s*(['"])([\s\S]*?)(?=\s+(?:line_ids|lineIds|timestamps|fileId|file_id|attachmentId|attachment_id|start_page_key|start_pageKey|startPageKey|keySpan|key_span|reasoning|value|full_phrase)|\s*\/?>)/gm;e=e.replace(n,(p,a,c,u)=>{let s=u;return s.endsWith(c)&&(s=s.slice(0,-1)),s=s.replace(/(\r?\n)+/g," "),s=r(s),s=s.replace(/(\*|_){2,}/g,""),s=s.replace(/\\\\'/g,"'"),s=s.replace(/\\'/g,"'"),s=s.replace(/'/g,"\\'"),s=s.replace(/\\\\"/g,'"'),s=s.replace(/\\"/g,'"'),s=s.replace(/"/g,'\\"'),s=s.replace(/\*/g,""),`${i(a)}='${s}'`}),e=e.replace(/(line_ids|lineIds|timestamps)=['"]?([\[\]\(\){}A-Za-z0-9_\-, ]+)['"]?(\s*\/?>|\s+)/gm,(p,a,c,u)=>{let s=c.replace(/[A-Za-z\[\]\(\){}]/g,"");return s=s.replace(/(\d+)-(\d+)/g,(C,d,l)=>{let y=parseInt(d,10),x=parseInt(l,10),f=[];if(y<=x)for(let h=y;h<=x;h++)f.push(h);else f.push(y);return f.join(",")}),s=s.replace(/,+/g,",").replace(/^,|,$/g,""),`${i(a)}='${s}'${u}`});let o=p=>{let a=/([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(['"])((?:[^'"\\\n]|\\.)*)(?:\2)/g,c={},u;for(;u=a.exec(p);){let f=u[1],h=u[3],_=i(f);c[_]=h;}let s=Object.keys(c);if(s.length===0)return p;let C=typeof c.timestamps=="string"&&c.timestamps.length>0,d=s.filter(f=>f.startsWith("start_page")),l=[];c.attachment_id&&l.push("attachment_id"),C?(c.full_phrase&&l.push("full_phrase"),c.key_span&&l.push("key_span"),l.push("timestamps")):(d.includes("start_page_key")&&l.push("start_page_key"),d.filter(f=>f!=="start_page_key").sort().forEach(f=>l.push(f)),c.full_phrase&&l.push("full_phrase"),c.key_span&&l.push("key_span"),c.line_ids&&l.push("line_ids")),c.reasoning&&l.push("reasoning"),c.value&&l.push("value");let y=new Set(l);return s.filter(f=>!y.has(f)).sort().forEach(f=>l.push(f)),`<cite ${l.map(f=>`${f}='${c[f]}'`).join(" ")} />`};return e=e.replace(/<cite\b[\s\S]*?\/>/gm,p=>o(p)),e};export{H as a,dt as b,mt as c,ht as d,v as e,$ as f,P as g,Y as h,U as i,A as j,j as k,Q as l,tt as m,et as n,nt as o,it as p,rt as q,st as r,R as s,B as t,lt as u,ut as v,pt as w};
@@ -1 +0,0 @@
1
- 'use strict';function E(t){return new TextEncoder().encode(t)}function Z(t){let e=1732584193,i=4023233417,r=2562383102,n=271733878,o=3285377520,p=t.length,a=p*8,c=p+1+8,u=Math.ceil(c/64)*64,s=new ArrayBuffer(u),C=new Uint8Array(s),d=new DataView(s);C.set(t),C[p]=128,d.setUint32(u-8,Math.floor(a/4294967296),false),d.setUint32(u-4,a>>>0,false);let l=new Uint32Array(80);for(let x=0;x<u;x+=64){for(let g=0;g<16;g++)l[g]=d.getUint32(x+g*4,false);for(let g=16;g<80;g++){let I=l[g-3]^l[g-8]^l[g-14]^l[g-16];l[g]=I<<1|I>>>31;}let f=e,h=i,_=r,k=n,S=o;for(let g=0;g<80;g++){let I,m;g<20?(I=h&_|~h&k,m=1518500249):g<40?(I=h^_^k,m=1859775393):g<60?(I=h&_|h&k|_&k,m=2400959708):(I=h^_^k,m=3395469782);let b=(f<<5|f>>>27)+I+S+m+l[g]>>>0;S=k,k=_,_=(h<<30|h>>>2)>>>0,h=f,f=b;}e=e+f>>>0,i=i+h>>>0,r=r+_>>>0,n=n+k>>>0,o=o+S>>>0;}let y=x=>x.toString(16).padStart(8,"0");return y(e)+y(i)+y(r)+y(n)+y(o)}function P(t){try{if(!t)return "";let e=typeof t=="string"?t:JSON.stringify(t);return Z(E(e))}catch(e){console.error("Error in making the hash:",e);}return ""}function Y(...t){return t.filter(Boolean).join(" ")}function U(t){return t.type==="url"||typeof t.url=="string"&&t.url.length>0}function A(t){let e=t.pageNumber||v(t.startPageKey),i=[t.attachmentId||"",e?.toString()||"",t.fullPhrase||"",t.keySpan?.toString()||"",t.lineIds?.join(",")||"",t.timestamps?.startTime||"",t.timestamps?.endTime||""];return U(t)&&i.push(t.url||"",t.title||"",t.domain||""),P(i.join("|")).slice(0,16)}function j(t){let e=[t.attachmentId||"",t.label||"",t.verifiedFullPhrase||"",t.verifiedKeySpan||"",t.verifiedLineIds?.join(",")||"",t.verifiedPageNumber?.toString()||"",t.verifiedTimestamps?.startTime||"",t.verifiedTimestamps?.endTime||"",t.verifiedMatchSnippet||"",t.hitIndexWithinPage?.toString()||""];return P(e.join("|")).slice(0,16)}function Q(t){let e=Math.random().toString(36).slice(2,11);return `${t}-${e}`}function tt(t,e={}){let{fallbackDisplay:i}=e;return t.keySpan?.toString()||t.citationNumber?.toString()||i||"1"}function et(t){return t.citationNumber?.toString()||"1"}function nt(t){return t.keySpan?.toString()||""}function it(...t){return t.filter(Boolean).join(" ")}var rt=4,st=1;function D(t){if(!t)return;let e=[],i=t.split(",");for(let r of i){let n=r.trim();if(n)if(n.includes("-")){let[o,p]=n.split("-"),a=parseInt(o,10),c=parseInt(p,10);if(!isNaN(a)&&!isNaN(c)&&a<=c)for(let u=a;u<=c;u++)e.push(u);else isNaN(a)||e.push(a);}else {let o=parseInt(n,10);isNaN(o)||e.push(o);}}if(e.length!==0)return [...new Set(e)].sort((r,n)=>r-n)}function R(t){let e=t?.status,i=e==="not_found",r=e==="found_phrase_missed_value",n=e==="found_key_span_only",o=e==="partial_text_found"||e==="found_on_other_page"||e==="found_on_other_line"||e==="first_word_found";return {isVerified:e==="found"||n||o||r,isMiss:i,isPartialMatch:o,isPending:e==="pending"||e==="loading"||!e}}var B=(t,e,i,r)=>{let n=m=>m?m.replace(/^['"]|['"]$/g,"").replace(/\\'/g,"'"):void 0,o=i?.current?i.current++:void 0,p=t.substring(0,t.indexOf("<cite")),a=t.includes("/>")?t.slice(t.indexOf("/>")+2):"",c=t.substring(t.indexOf("<cite"),t.indexOf("/>")+2),u=(m,b)=>{for(let O of b){let L=new RegExp(`${O}='((?:[^'\\\\]|\\\\.)*)'`),K=m.match(L);if(K)return K[1]}},s=u(c,["attachment_id","attachmentId","file_id","fileId"]),C=s?.length===20?s:e||s,d=u(c,["start_page_key","startPageKey","start_page"]),l,y;if(d){let m=d.match(/page[\_a-zA-Z]*(\d+)_index_(\d+)/);m&&(l=parseInt(m[1]),y=parseInt(m[2]));}let x=n(u(c,["full_phrase","fullPhrase"])),f=n(u(c,["key_span","keySpan"])),h=n(u(c,["reasoning"])),_=n(u(c,["value"])),k;try{let b=u(c,["line_ids","lineIds"])?.replace(/[A-Za-z_[\](){}:]/g,"");k=b?D(b):void 0;}catch(m){r&&console.error("Error parsing lineIds",m);}let S=u(c,["timestamps"]),g;if(S){let[m,b]=S.split("-")||[];g={startTime:m,endTime:b};}let I={attachmentId:C,pageNumber:l,startPageKey:`page_number_${l||1}_index_${y||0}`,fullPhrase:x,keySpan:f||_,citationNumber:o,lineIds:k,beforeCite:p,timestamps:g,reasoning:h};return {beforeCite:p,afterCite:a,citation:I}},J=(t,e)=>{if(!t)return null;let i=t.fullPhrase??t.full_phrase,r=t.startPageKey??t.start_page_key,n=t.keySpan??t.key_span,o=t.lineIds??t.line_ids,p=t.attachmentId??t.attachment_id??t.fileId??t.file_id,a=t.reasoning,c=t.value;if(!i)return null;let u;if(r){let d=r.match(/page[_a-zA-Z]*(\d+)_index_(\d+)/i);if(d)u=parseInt(d[1],10);else {let l=r.match(/^(\d+)_(\d+)$/);l&&(u=parseInt(l[1],10));}}let s=o?.length?[...o].sort((d,l)=>d-l):void 0;return {attachmentId:p,pageNumber:u,fullPhrase:i,citationNumber:e,lineIds:s,keySpan:n||c,reasoning:a}},V=t=>typeof t=="object"&&t!==null&&("fullPhrase"in t||"full_phrase"in t||"startPageKey"in t||"start_page_key"in t||"keySpan"in t||"key_span"in t||"lineIds"in t||"line_ids"in t),N=t=>Array.isArray(t)?t.length>0&&t.some(V):typeof t=="object"&&t!==null?V(t):false,M=t=>{let e={},i=Array.isArray(t)?t:[t],r=1;for(let n of i){let o=J(n,r++);if(o&&o.fullPhrase){let p=A(o);e[p]=o;}}return e},w=(t,e)=>{if(!(!t||typeof t!="object")){if(t.citation&&N(t.citation)){let i=Array.isArray(t.citation)?t.citation:[t.citation];e.push(...i);}if(t.citations&&N(t.citations)){let i=Array.isArray(t.citations)?t.citations:[t.citations];e.push(...i);}if(Array.isArray(t))for(let i of t)w(i,e);else for(let i of Object.keys(t))i!=="citation"&&i!=="citations"&&w(t[i],e);}},T=t=>{let e=$(t),i=/<cite\s+[^>]*\/>/g,r=e.match(i);if(!r||r.length===0)return {};let n={},o={current:1};for(let p of r){let{citation:a}=B(p,void 0,o);if(a&&a.fullPhrase){let c=A(a);n[c]=a;}}return n},lt=t=>{if(!t)return {};let e={};if(typeof t=="object"){if(N(t)){let n=M(t);Object.assign(e,n);}else {let n=[];if(w(t,n),n.length>0){let o=M(n);Object.assign(e,o);}}let i=JSON.stringify(t),r=T(i);Object.assign(e,r);}else if(typeof t=="string"){let i=T(t);Object.assign(e,i);}return e};function ut(t){let e=new Map,i=Array.isArray(t)?t.map((r,n)=>[A(r)||String(n+1),r]):Object.entries(t);for(let[r,n]of i){let o=n.attachmentId||"";e.has(o)||e.set(o,{}),e.get(o)[r]=n;}return e}function pt(t){let e={},i=Array.isArray(t)?t.map((r,n)=>[A(r)||String(n+1),r]):Object.entries(t);for(let[r,n]of i){let o=n.attachmentId||"";e[o]||(e[o]={}),e[o][r]=n;}return e}var F=t=>{let e={},i=/([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*(['"])((?:[^'"\\]|\\.)*)\2/g,r;for(;(r=i.exec(t))!==null;){let n=r[1].toLowerCase().replace(/([a-z])([A-Z])/g,"$1_$2").toLowerCase(),o=r[3],p=n==="fileid"||n==="file_id"||n==="attachmentid"?"attachment_id":n==="keyspan"?"key_span":n==="fullphrase"?"full_phrase":n==="lineids"?"line_ids":n==="startpagekey"||n==="start_pagekey"?"start_page_key":n;e[p]=o;}return e},W=t=>{if(!t)return "\u25CC";let e=R(t);return e.isPending?"\u25CC":e.isMiss?"\u2717":e.isPartialMatch?"\u26A0":e.isVerified?"\u2713":"\u25CC"},H=(t,e={})=>{let{leaveKeySpanBehind:i=false,verifications:r,showVerificationStatus:n=false}=e,o=0,p=/<cite\s+[^>]*?\/>/g;return t.replace(p,a=>{o++;let c=F(a),u="";if(i&&c.key_span&&(u=c.key_span.replace(/\\'/g,"'").replace(/\\"/g,'"')),n&&r){let s,C=String(o);if(s=r[C],!s&&c.attachment_id){for(let[,l]of Object.entries(r))if(l.attachmentId===c.attachment_id){s=l;break}}let d=W(s);u=u?`${u}${d}`:d;}return u})},dt=(t,e)=>H(t,{leaveKeySpanBehind:e}),mt=t=>t.replace(/<page_number_\d+_index_\d+>/g,"").replace(/<\/page_number_\d+_index_\d+>/g,"").trim(),ht=t=>{let e=/<line id="[^"]*">|<\/line>/g;return t.replace(e,"")},v=t=>{if(!t)return null;let e=t.match(/\d+/)?.[0];return e?parseInt(e):null},$=t=>{let e=t?.trim()||"",i=e.split(/(<cite[\s\S]*?(?:\/>|<\/cite>))/gm);return i.length<=1?z(e):(e=i.map(r=>r.startsWith("<cite")?z(r):r).join(""),e)},z=t=>{let e=t;e=e.replace(/><\/cite>/g,"/>");let i=p=>{let a=p.toLowerCase();return a==="fullphrase"||a==="full_phrase"?"full_phrase":a==="lineids"||a==="line_ids"?"line_ids":a==="startpagekey"||a==="start_pagekey"||a==="start_page_key"?"start_page_key":a==="fileid"||a==="file_id"||a==="attachmentid"||a==="attachment_id"?"attachment_id":a==="keyspan"||a==="key_span"?"key_span":a==="reasoning"||a==="value"?a:a==="timestamps"||a==="timestamp"||a==="timestamps"?"timestamps":a},r=p=>p.replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&"),n=/(fullPhrase|full_phrase|keySpan|key_span|reasoning|value)\s*=\s*(['"])([\s\S]*?)(?=\s+(?:line_ids|lineIds|timestamps|fileId|file_id|attachmentId|attachment_id|start_page_key|start_pageKey|startPageKey|keySpan|key_span|reasoning|value|full_phrase)|\s*\/?>)/gm;e=e.replace(n,(p,a,c,u)=>{let s=u;return s.endsWith(c)&&(s=s.slice(0,-1)),s=s.replace(/(\r?\n)+/g," "),s=r(s),s=s.replace(/(\*|_){2,}/g,""),s=s.replace(/\\\\'/g,"'"),s=s.replace(/\\'/g,"'"),s=s.replace(/'/g,"\\'"),s=s.replace(/\\\\"/g,'"'),s=s.replace(/\\"/g,'"'),s=s.replace(/"/g,'\\"'),s=s.replace(/\*/g,""),`${i(a)}='${s}'`}),e=e.replace(/(line_ids|lineIds|timestamps)=['"]?([\[\]\(\){}A-Za-z0-9_\-, ]+)['"]?(\s*\/?>|\s+)/gm,(p,a,c,u)=>{let s=c.replace(/[A-Za-z\[\]\(\){}]/g,"");return s=s.replace(/(\d+)-(\d+)/g,(C,d,l)=>{let y=parseInt(d,10),x=parseInt(l,10),f=[];if(y<=x)for(let h=y;h<=x;h++)f.push(h);else f.push(y);return f.join(",")}),s=s.replace(/,+/g,",").replace(/^,|,$/g,""),`${i(a)}='${s}'${u}`});let o=p=>{let a=/([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(['"])((?:[^'"\\\n]|\\.)*)(?:\2)/g,c={},u;for(;u=a.exec(p);){let f=u[1],h=u[3],_=i(f);c[_]=h;}let s=Object.keys(c);if(s.length===0)return p;let C=typeof c.timestamps=="string"&&c.timestamps.length>0,d=s.filter(f=>f.startsWith("start_page")),l=[];c.attachment_id&&l.push("attachment_id"),C?(c.full_phrase&&l.push("full_phrase"),c.key_span&&l.push("key_span"),l.push("timestamps")):(d.includes("start_page_key")&&l.push("start_page_key"),d.filter(f=>f!=="start_page_key").sort().forEach(f=>l.push(f)),c.full_phrase&&l.push("full_phrase"),c.key_span&&l.push("key_span"),c.line_ids&&l.push("line_ids")),c.reasoning&&l.push("reasoning"),c.value&&l.push("value");let y=new Set(l);return s.filter(f=>!y.has(f)).sort().forEach(f=>l.push(f)),`<cite ${l.map(f=>`${f}='${c[f]}'`).join(" ")} />`};return e=e.replace(/<cite\b[\s\S]*?\/>/gm,p=>o(p)),e};exports.a=H;exports.b=dt;exports.c=mt;exports.d=ht;exports.e=v;exports.f=$;exports.g=P;exports.h=Y;exports.i=U;exports.j=A;exports.k=j;exports.l=Q;exports.m=tt;exports.n=et;exports.o=nt;exports.p=it;exports.q=rt;exports.r=st;exports.s=R;exports.t=B;exports.u=lt;exports.v=ut;exports.w=pt;