@deepcitation/deepcitation-js 1.1.28 → 1.1.29

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,466 @@
1
+ import { Citation, Verification, SearchStatus, CitationStatus } from '../types/index.js';
2
+ export { C as CITATION_X_PADDING, c as CITATION_Y_PADDING, h as classNames, b as generateCitationInstanceId, g as generateCitationKey, d as getCitationDisplayText, f as getCitationKeySpanText, e as getCitationNumber } from '../utils-D_wxy_ni.js';
3
+ import React$1 from 'react';
4
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
+
6
+ /**
7
+ * Visual style variants for citations.
8
+ *
9
+ * | Variant | Description |
10
+ * |---------------|------------------------------------------------|
11
+ * | `chip` | Pill/badge style with background color |
12
+ * | `brackets` | [text✓] with square brackets (default) |
13
+ * | `text` | Plain text, inherits parent styling |
14
+ * | `superscript` | Small raised text like footnotes¹ |
15
+ * | `minimal` | Compact text with indicator, truncated |
16
+ */
17
+ type CitationVariant = "chip" | "brackets" | "text" | "superscript" | "minimal";
18
+ /**
19
+ * Content to display in the citation.
20
+ *
21
+ * | Content | Description |
22
+ * |---------------|------------------------------------------------|
23
+ * | `keySpan` | Descriptive text (e.g., "Revenue Growth") |
24
+ * | `number` | Citation number (e.g., "1", "2", "3") |
25
+ * | `indicator` | Only the status icon (✓/⚠), no text |
26
+ *
27
+ * Default content per variant:
28
+ * - `chip` → `keySpan`
29
+ * - `brackets` → `number`
30
+ * - `text` → `keySpan`
31
+ * - `superscript` → `number`
32
+ * - `minimal` → `number`
33
+ */
34
+ type CitationContent = "keySpan" | "number" | "indicator";
35
+ /**
36
+ * URL fetch status for URL citations.
37
+ */
38
+ type UrlFetchStatus = "verified" | "partial" | "pending" | "blocked_antibot" | "blocked_login" | "blocked_paywall" | "blocked_geo" | "blocked_rate_limit" | "error_timeout" | "error_not_found" | "error_server" | "error_network" | "unknown";
39
+ /**
40
+ * URL citation metadata.
41
+ */
42
+ interface UrlCitationMeta {
43
+ /** The full URL */
44
+ url: string;
45
+ /** Display domain (e.g., "example.com") */
46
+ domain?: string;
47
+ /** Page title if fetched */
48
+ title?: string;
49
+ /** Fetch/verification status */
50
+ fetchStatus: UrlFetchStatus;
51
+ /** When the URL was last verified */
52
+ verifiedAt?: Date | string;
53
+ /** HTTP status code if available */
54
+ httpStatus?: number;
55
+ /** Error message if applicable */
56
+ errorMessage?: string;
57
+ /** Favicon URL if available */
58
+ faviconUrl?: string;
59
+ }
60
+ /**
61
+ * Style configuration for the citation component.
62
+ * All properties are optional class name strings.
63
+ */
64
+ interface CitationStyles {
65
+ /** Container wrapper class */
66
+ container?: string;
67
+ /** Citation number bracket wrapper */
68
+ bracketWrapper?: string;
69
+ /** Inner bracket content */
70
+ bracketContent?: string;
71
+ /** Citation text/number itself */
72
+ citationText?: string;
73
+ /** Verified status indicator */
74
+ verifiedIcon?: string;
75
+ /** Partial match indicator */
76
+ partialIcon?: string;
77
+ /** Pending/loading state */
78
+ pendingText?: string;
79
+ }
80
+ /**
81
+ * State classes applied based on citation verification status
82
+ */
83
+ interface CitationStateClasses {
84
+ /** Applied when citation is verified (found in document) */
85
+ verified?: string;
86
+ /** Applied when citation is a miss (not found) */
87
+ miss?: string;
88
+ /** Applied when citation is a partial match */
89
+ partial?: string;
90
+ /** Applied when citation verification is pending */
91
+ pending?: string;
92
+ }
93
+ /**
94
+ * Cursor classes for different zoom states
95
+ */
96
+ interface CitationCursorClasses {
97
+ zoomIn?: string;
98
+ zoomOut?: string;
99
+ pointer?: string;
100
+ }
101
+ /**
102
+ * Props for the base CitationComponent
103
+ */
104
+ interface BaseCitationProps {
105
+ /** The citation data to display */
106
+ citation: Citation;
107
+ /** Child content to render before the citation bracket */
108
+ children?: React.ReactNode;
109
+ /** Additional class name for the container */
110
+ className?: string;
111
+ /** Class name for controlling inner content width */
112
+ innerWidthClassName?: string;
113
+ /**
114
+ * Visual style variant for the citation.
115
+ * @default "brackets"
116
+ */
117
+ variant?: CitationVariant;
118
+ /**
119
+ * What content to display in the citation.
120
+ * If not specified, defaults based on variant:
121
+ * - `chip` → `keySpan`
122
+ * - `brackets` → `number`
123
+ * - `text` → `keySpan`
124
+ * - `superscript` → `number`
125
+ * - `minimal` → `number`
126
+ */
127
+ content?: CitationContent;
128
+ /** Fallback display text when citation keySpan is empty */
129
+ fallbackDisplay?: string | null;
130
+ }
131
+ /**
132
+ * Visual style variants for URL citations.
133
+ */
134
+ type UrlCitationVariant = "chip" | "inline" | "bracket";
135
+ /**
136
+ * Props for URL citation component
137
+ */
138
+ interface UrlCitationProps extends Omit<BaseCitationProps, "citation" | "variant"> {
139
+ /** Visual style variant for the URL citation */
140
+ variant?: UrlCitationVariant;
141
+ /** URL metadata including fetch status */
142
+ urlMeta: UrlCitationMeta;
143
+ /** The citation data (optional, will be derived from urlMeta if not provided) */
144
+ citation?: Citation;
145
+ /** Whether to show the full URL on hover */
146
+ showFullUrlOnHover?: boolean;
147
+ /** Whether to show favicon */
148
+ showFavicon?: boolean;
149
+ /** Whether to show the page title instead of domain */
150
+ showTitle?: boolean;
151
+ /** Maximum characters for truncated display */
152
+ maxDisplayLength?: number;
153
+ /** Custom render for the blocked status indicator */
154
+ renderBlockedIndicator?: (status: UrlFetchStatus, errorMessage?: string) => React.ReactNode;
155
+ /** Click handler for the URL */
156
+ onUrlClick?: (url: string, event: React.MouseEvent) => void;
157
+ /** Event handlers for citation interactions */
158
+ eventHandlers?: CitationEventHandlers;
159
+ /** Whether tooltips should be prevented */
160
+ preventTooltips?: boolean;
161
+ }
162
+ /**
163
+ * Extended props for the citation content renderer
164
+ */
165
+ interface CitationContentProps extends BaseCitationProps {
166
+ /** Unique key for this citation */
167
+ citationKey: string;
168
+ /** Unique instance ID for this citation render */
169
+ citationInstanceId: string;
170
+ /** Found citation highlight data */
171
+ verification: Verification | null | undefined;
172
+ /** Search status */
173
+ searchStatus: SearchStatus | undefined | null;
174
+ /** Actual page number where citation was found */
175
+ actualPageNumber?: number | null;
176
+ /** Page number from citation data */
177
+ citationPageNumber?: number | null;
178
+ /** Unique highlight ID */
179
+ highlightId?: string;
180
+ /** Citation verification status */
181
+ status: CitationStatus;
182
+ /** Whether tooltips should be suppressed */
183
+ preventTooltips?: boolean;
184
+ /** Whether on mobile device */
185
+ isMobile?: boolean;
186
+ /** Style configuration */
187
+ styles?: CitationStyles;
188
+ /** State-based classes */
189
+ stateClasses?: CitationStateClasses;
190
+ /** Cursor classes */
191
+ cursorClasses?: CitationCursorClasses;
192
+ }
193
+ /**
194
+ * Render props for custom citation rendering
195
+ */
196
+ interface CitationRenderProps {
197
+ /** The citation data */
198
+ citation: Citation;
199
+ /** Citation verification status */
200
+ status: CitationStatus;
201
+ /** The citation key */
202
+ citationKey: string;
203
+ /** Display text for the citation */
204
+ displayText: string;
205
+ /** Whether this is a merged keySpan display */
206
+ isMergedDisplay: boolean;
207
+ }
208
+ /**
209
+ * Event handlers for citation interactions
210
+ */
211
+ interface CitationEventHandlers {
212
+ /** Called when mouse enters citation */
213
+ onMouseEnter?: (citation: Citation, citationKey: string) => void;
214
+ /** Called when mouse leaves citation */
215
+ onMouseLeave?: (citation: Citation, citationKey: string) => void;
216
+ /** Called when citation is clicked */
217
+ onClick?: (citation: Citation, citationKey: string, event: React.MouseEvent | React.TouchEvent) => void;
218
+ /** Called on touch end (mobile) */
219
+ onTouchEnd?: (citation: Citation, citationKey: string, event: React.TouchEvent) => void;
220
+ }
221
+ /**
222
+ * Context provided to behavior handlers for making decisions.
223
+ */
224
+ interface CitationBehaviorContext {
225
+ /** The citation data */
226
+ citation: Citation;
227
+ /** Unique key for this citation */
228
+ citationKey: string;
229
+ /** Verification result if available */
230
+ verification: Verification | null;
231
+ /** Whether the popover is currently pinned open */
232
+ isTooltipExpanded: boolean;
233
+ /** Whether the full-size image overlay is currently open */
234
+ isImageExpanded: boolean;
235
+ /** Whether a verification image is available */
236
+ hasImage: boolean;
237
+ }
238
+ /**
239
+ * Actions that can be performed by the citation component.
240
+ * These are returned by behavior handlers to control component state.
241
+ */
242
+ interface CitationBehaviorActions {
243
+ /** Pin or unpin the popover (keeps it visible without hover) */
244
+ setTooltipExpanded?: boolean;
245
+ /** Open or close the full-size image overlay */
246
+ setImageExpanded?: boolean | string;
247
+ /** Expand or collapse the search phrases list (for miss/partial states) */
248
+ setPhrasesExpanded?: boolean;
249
+ }
250
+ /**
251
+ * Configuration for click behavior.
252
+ * Return actions to perform, or `false` to prevent default behavior.
253
+ */
254
+ type CitationClickBehavior = (context: CitationBehaviorContext, event: React.MouseEvent | React.TouchEvent) => CitationBehaviorActions | false | void;
255
+ /**
256
+ * Configuration for hover behavior.
257
+ */
258
+ interface CitationHoverBehavior {
259
+ /** Called when mouse enters the citation */
260
+ onEnter?: (context: CitationBehaviorContext) => void;
261
+ /** Called when mouse leaves the citation */
262
+ onLeave?: (context: CitationBehaviorContext) => void;
263
+ }
264
+ /**
265
+ * Configuration for customizing default citation behaviors.
266
+ *
267
+ * When you provide `onClick` or `onHover`, they REPLACE the corresponding default behaviors.
268
+ * Use `eventHandlers` for side effects that should run alongside defaults.
269
+ *
270
+ * @example Custom click behavior (replaces default)
271
+ * ```tsx
272
+ * <CitationComponent
273
+ * citation={citation}
274
+ * verification={verification}
275
+ * behaviorConfig={{
276
+ * onClick: (context, event) => {
277
+ * if (context.hasImage) {
278
+ * return { setImageExpanded: true };
279
+ * }
280
+ * }
281
+ * }}
282
+ * />
283
+ * ```
284
+ *
285
+ * @example Disable click behavior entirely
286
+ * ```tsx
287
+ * <CitationComponent
288
+ * citation={citation}
289
+ * verification={verification}
290
+ * behaviorConfig={{ onClick: () => false }}
291
+ * />
292
+ * ```
293
+ */
294
+ interface CitationBehaviorConfig {
295
+ /**
296
+ * Custom click behavior handler. When provided, REPLACES the default click behavior.
297
+ *
298
+ * Return values:
299
+ * - `CitationBehaviorActions`: Apply specific state changes
300
+ * - `false`: Prevent any state changes
301
+ * - `void`/`undefined`: No state changes
302
+ */
303
+ onClick?: CitationClickBehavior;
304
+ /**
305
+ * Custom hover behavior handlers. When provided, REPLACE the default hover behavior.
306
+ */
307
+ onHover?: CitationHoverBehavior;
308
+ }
309
+ /**
310
+ * Props for the tooltip wrapper component
311
+ */
312
+ interface CitationTooltipProps {
313
+ children: React.ReactNode;
314
+ citation: Citation;
315
+ verification?: Verification | null;
316
+ shouldShowTooltip: boolean;
317
+ }
318
+
319
+ /**
320
+ * Extracts domain from URL for compact display.
321
+ */
322
+ declare function extractDomain(url: string): string;
323
+ /**
324
+ * Checks if status is a blocked status.
325
+ */
326
+ declare function isBlockedStatus(status: UrlFetchStatus): boolean;
327
+ /**
328
+ * Checks if status is an error status.
329
+ */
330
+ declare function isErrorStatus(status: UrlFetchStatus): boolean;
331
+ /**
332
+ * Checks if URL was successfully verified.
333
+ */
334
+ declare function isVerifiedStatus(status: UrlFetchStatus): boolean;
335
+
336
+ /**
337
+ * Props for the CitationComponent.
338
+ *
339
+ * ## Behavior
340
+ *
341
+ * Default interaction pattern:
342
+ * - **Hover**: Shows popover with verification image/details
343
+ * - **Click**: Opens full-size image overlay (zoom)
344
+ * - **Escape / Click outside / Click overlay**: Closes image overlay
345
+ *
346
+ * Custom behavior:
347
+ * - Use `behaviorConfig.onClick` to replace the default click behavior
348
+ * - Use `eventHandlers.onClick` to add side effects (disables default)
349
+ *
350
+ * @example Default usage
351
+ * ```tsx
352
+ * <CitationComponent
353
+ * citation={citation}
354
+ * verification={verification}
355
+ * />
356
+ * ```
357
+ *
358
+ * @example Custom click behavior
359
+ * ```tsx
360
+ * <CitationComponent
361
+ * citation={citation}
362
+ * verification={verification}
363
+ * behaviorConfig={{
364
+ * onClick: (context) => {
365
+ * // Custom action
366
+ * console.log('Clicked:', context.citationKey);
367
+ * return { setImageExpanded: true };
368
+ * }
369
+ * }}
370
+ * />
371
+ * ```
372
+ */
373
+ interface CitationComponentProps extends BaseCitationProps {
374
+ /** Verification result from the DeepCitation API */
375
+ verification?: Verification | null;
376
+ /**
377
+ * Explicitly show loading spinner. When true, displays spinner regardless
378
+ * of verification status. Use this when verification is in-flight.
379
+ */
380
+ isLoading?: boolean;
381
+ /**
382
+ * Visual style variant for the citation.
383
+ * - `chip`: Pill/badge style with background color
384
+ * - `brackets`: [text✓] with square brackets (default)
385
+ * - `text`: Plain text, inherits parent styling
386
+ * - `superscript`: Small raised text like footnotes¹
387
+ * - `minimal`: Compact text with indicator, truncated
388
+ */
389
+ variant?: CitationVariant;
390
+ /**
391
+ * What content to display in the citation.
392
+ * - `keySpan`: Descriptive text (e.g., "Revenue Growth")
393
+ * - `number`: Citation number (e.g., "1", "2", "3")
394
+ * - `indicator`: Only the status icon, no text
395
+ *
396
+ * Defaults based on variant:
397
+ * - `chip` → `keySpan`
398
+ * - `brackets` → `keySpan`
399
+ * - `text` → `keySpan`
400
+ * - `superscript` → `number`
401
+ * - `minimal` → `number`
402
+ */
403
+ content?: CitationContent;
404
+ /** Event handlers for citation interactions */
405
+ eventHandlers?: CitationEventHandlers;
406
+ /**
407
+ * Configuration for customizing default click/hover behaviors.
408
+ * Providing onClick REPLACES the default click behavior.
409
+ */
410
+ behaviorConfig?: CitationBehaviorConfig;
411
+ /** Enable mobile touch handlers */
412
+ isMobile?: boolean;
413
+ /** Custom render function for the status indicator */
414
+ renderIndicator?: (status: CitationStatus) => React$1.ReactNode;
415
+ /** Custom render function for entire citation content */
416
+ renderContent?: (props: CitationRenderProps) => React$1.ReactNode;
417
+ /** Position of popover. Use "hidden" to disable. */
418
+ popoverPosition?: "top" | "bottom" | "hidden";
419
+ /** Custom render function for popover content */
420
+ renderPopoverContent?: (props: {
421
+ citation: BaseCitationProps["citation"];
422
+ verification: Verification | null;
423
+ status: CitationStatus;
424
+ }) => React$1.ReactNode;
425
+ }
426
+ /**
427
+ * CitationComponent displays a citation with verification status.
428
+ *
429
+ * ## Interaction Pattern
430
+ *
431
+ * - **Hover**: Shows popover with verification image or details
432
+ * - **Click**: Opens full-size image overlay (if image available)
433
+ * - **Escape / Click overlay**: Closes the image overlay
434
+ *
435
+ * ## Customization
436
+ *
437
+ * Use `behaviorConfig.onClick` to completely replace the click behavior,
438
+ * or `eventHandlers.onClick` to add side effects (which disables defaults).
439
+ */
440
+ declare const CitationComponent: React$1.ForwardRefExoticComponent<CitationComponentProps & React$1.RefAttributes<HTMLSpanElement>>;
441
+ declare const MemoizedCitationComponent: React$1.NamedExoticComponent<CitationComponentProps & React$1.RefAttributes<HTMLSpanElement>>;
442
+
443
+ /**
444
+ * DeepCitation icon SVG (no dependencies)
445
+ */
446
+ declare const DeepCitationIcon: ({ className }: {
447
+ className?: string;
448
+ }) => react_jsx_runtime.JSX.Element;
449
+ /**
450
+ * Check icon SVG (no dependencies)
451
+ */
452
+ declare const CheckIcon: ({ className }: {
453
+ className?: string;
454
+ }) => react_jsx_runtime.JSX.Element;
455
+ /**
456
+ * Warning icon SVG (no dependencies)
457
+ */
458
+ declare const WarningIcon: ({ className }: {
459
+ className?: string;
460
+ }) => react_jsx_runtime.JSX.Element;
461
+ /** Spinner component for loading/pending state */
462
+ declare const SpinnerIcon: ({ className }: {
463
+ className?: string;
464
+ }) => react_jsx_runtime.JSX.Element;
465
+
466
+ export { CheckIcon, type CitationBehaviorActions, type CitationBehaviorConfig, type CitationBehaviorContext, type CitationClickBehavior, CitationComponent, type CitationComponentProps, type CitationContent, type CitationContentProps, type CitationCursorClasses, type CitationEventHandlers, type CitationHoverBehavior, type CitationRenderProps, type CitationStateClasses, type CitationStyles, type CitationTooltipProps, type CitationVariant, type CitationVariant as CitationVariantType, DeepCitationIcon, MemoizedCitationComponent, SpinnerIcon, type UrlCitationMeta, type UrlCitationProps, type UrlCitationVariant, type UrlFetchStatus, WarningIcon, extractDomain, isBlockedStatus, isErrorStatus, isVerifiedStatus };
@@ -1,4 +1,4 @@
1
- import*as Ce from'react';import {forwardRef,useMemo,useCallback,memo,useState,useEffect}from'react';import {jsxs,Fragment,jsx}from'react/jsx-runtime';import {createPortal}from'react-dom';import*as R from'@radix-ui/react-popover';function $e(e){return new TextEncoder().encode(e)}function je(e){let t=1732584193,n=4023233417,r=2562383102,a=271733878,i=3285377520,s=e.length,u=s*8,l=s+1+8,o=Math.ceil(l/64)*64,p=new ArrayBuffer(o),m=new Uint8Array(p),x=new DataView(p);m.set(e),m[s]=128,x.setUint32(o-8,Math.floor(u/4294967296),false),x.setUint32(o-4,u>>>0,false);let v=new Uint32Array(80);for(let S=0;S<o;S+=64){for(let c=0;c<16;c++)v[c]=x.getUint32(S+c*4,false);for(let c=16;c<80;c++){let I=v[c-3]^v[c-8]^v[c-14]^v[c-16];v[c]=I<<1|I>>>31;}let P=t,f=n,b=r,_=a,y=i;for(let c=0;c<80;c++){let I,N;c<20?(I=f&b|~f&_,N=1518500249):c<40?(I=f^b^_,N=1859775393):c<60?(I=f&b|f&_|b&_,N=2400959708):(I=f^b^_,N=3395469782);let M=(P<<5|P>>>27)+I+y+N+v[c]>>>0;y=_,_=b,b=(f<<30|f>>>2)>>>0,f=P,P=M;}t=t+P>>>0,n=n+f>>>0,r=r+b>>>0,a=a+_>>>0,i=i+y>>>0;}let g=S=>S.toString(16).padStart(8,"0");return g(t)+g(n)+g(r)+g(a)+g(i)}function pe(e){try{if(!e)return "";let t=typeof e=="string"?e:JSON.stringify(e);return je($e(t))}catch(t){console.error("Error in making the hash:",t);}return ""}var me=e=>{if(!e)return null;let t=e.match(/\d+/)?.[0];return t?parseInt(t):null};function w(...e){return e.filter(Boolean).join(" ")}function Z(e){let t=e.pageNumber||me(e.startPageKey),n=[e.attachmentId||"",t?.toString()||"",e.fullPhrase||"",e.keySpan?.toString()||"",e.lineIds?.join(",")||"",e.timestamps?.startTime||"",e.timestamps?.endTime||""];return pe(n.join("|")).slice(0,16)}function G(e){let t=Math.random().toString(36).slice(2,11);return `${e}-${t}`}function ze(e,t={}){let{fallbackDisplay:n}=t;return e.keySpan?.toString()||e.citationNumber?.toString()||n||"1"}function We(e){return e.citationNumber?.toString()||"1"}function Te(e){return e.keySpan?.toString()||""}function j(...e){return e.filter(Boolean).join(" ")}var Ke=4,Oe=1;function ae(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e.replace(/^https?:\/\/(www\.)?/,"").split("/")[0]}}function ge(e,t){return e.length<=t?e:e.slice(0,t-1)+"\u2026"}function Ze(e){try{let t=new URL(e),n=t.pathname+t.search;return n==="/"?"":n}catch{return ""}}var fe={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"},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 he(e){return e.startsWith("blocked_")}function xe(e){return e.startsWith("error_")}function Ge(e){return e==="verified"||e==="partial"}var Xe=({status:e,errorMessage:t})=>{let n=fe[e];return jsx("span",{className:j("inline-flex items-center gap-1",n.className),title:t||n.label,"aria-label":n.label,children:jsx("span",{className:"text-[0.9em]","aria-hidden":"true",children:n.icon})})},te=({url:e,faviconUrl:t})=>{let n=ae(e),r=t||`https://www.google.com/s2/favicons?domain=${n}&sz=16`;return jsx("img",{src:r,alt:"",className:"w-3.5 h-3.5 rounded-sm",width:14,height:14,loading:"lazy",onError:a=>{a.target.style.display="none";}})},ve=forwardRef(({urlMeta:e,citation:t,children:n,className:r,variant:a="chip",showFullUrlOnHover:i=true,showFavicon:s=true,showTitle:u=false,maxDisplayLength:l=30,renderBlockedIndicator:o,onUrlClick:p,eventHandlers:m,preventTooltips:x=false},v)=>{let{url:g,domain:S,title:P,fetchStatus:f,faviconUrl:b,errorMessage:_}=e,y=useMemo(()=>t||{value:g,fullPhrase:P||g},[t,g,P]),c=useMemo(()=>Z(y),[y]),I=useMemo(()=>G(c),[c]),N=useMemo(()=>S||ae(g),[S,g]),M=useMemo(()=>Ze(g),[g]),B=useMemo(()=>{if(u&&P)return ge(P,l);let C=M?ge(M,l-N.length-1):"";return C?`${N}${C}`:N},[u,P,N,M,l]),E=fe[f],A=he(f),L=xe(f),V=f==="verified",J=f==="partial",q=f==="pending",K=useCallback(C=>{C.preventDefault(),C.stopPropagation(),p?p(g,C):window.open(g,"_blank","noopener,noreferrer"),m?.onClick?.(y,c,C);},[p,g,m,y,c]),O=useCallback(()=>{m?.onMouseEnter?.(y,c);},[m,y,c]),F=useCallback(()=>{m?.onMouseLeave?.(y,c);},[m,y,c]),$=()=>A||L?o?o(f,_):jsx(Xe,{status:f,errorMessage:_}):V?jsx("span",{className:"text-[0.85em] text-green-600 dark:text-green-500","aria-hidden":"true",title:"Verified",children:"\u2713"}):J?jsx("span",{className:"text-[0.85em] text-amber-600 dark:text-amber-500","aria-hidden":"true",title:"Partial match",children:"~"}):q?jsx("span",{className:"opacity-70","aria-hidden":"true",children:"\u2026"}):null;return a==="chip"?jsxs(Fragment,{children:[n,jsxs("span",{ref:v,"data-citation-id":c,"data-citation-instance":I,"data-url":g,"data-fetch-status":f,"data-variant":"chip",className:j("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-sm cursor-pointer transition-colors no-underline","bg-blue-100 dark:bg-blue-900/30",E.className,r),title:i?g:void 0,onMouseEnter:x?void 0:O,onMouseLeave:x?void 0:F,onMouseDown:K,onClick:C=>C.stopPropagation(),role:"link","aria-label":`Link to ${N}: ${E.label}`,children:[s&&jsx(te,{url:g,faviconUrl:b}),jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:B}),$()]})]}):a==="inline"?jsxs(Fragment,{children:[n,jsxs("a",{ref:v,href:g,"data-citation-id":c,"data-citation-instance":I,"data-fetch-status":f,"data-variant":"inline",className:j("inline-flex items-center gap-1 cursor-pointer transition-colors no-underline border-b border-dotted border-current",E.className,r),title:i?g:void 0,onMouseEnter:x?void 0:O,onMouseLeave:x?void 0:F,onClick:C=>{C.preventDefault(),K(C);},target:"_blank",rel:"noopener noreferrer","aria-label":`Link to ${N}: ${E.label}`,children:[s&&jsx(te,{url:g,faviconUrl:b}),jsx("span",{children:B}),$()]})]}):jsxs(Fragment,{children:[n,jsxs("span",{ref:v,"data-citation-id":c,"data-citation-instance":I,"data-url":g,"data-fetch-status":f,"data-variant":"bracket",className:j("cursor-pointer transition-colors",E.className,r),title:i?g:void 0,onMouseEnter:x?void 0:O,onMouseLeave:x?void 0:F,onMouseDown:K,onClick:C=>C.stopPropagation(),role:"link","aria-label":`Link to ${N}: ${E.label}`,children:["[",s&&jsx(te,{url:g,faviconUrl:b}),jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:B}),$(),"]"]})]})});ve.displayName="UrlCitationComponent";memo(ve);var Je=({className:e})=>jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"square",shapeRendering:"crispEdges",className:e,children:[jsx("path",{d:"M7 3 L3 3 L3 21 L7 21"}),jsx("path",{d:"M17 3 L21 3 L21 21 L17 21"})]}),Y=({className:e})=>jsx("svg",{className:w("w-[0.7em] h-[0.7em]",e),viewBox:"0 0 256 256",fill:"currentColor","aria-hidden":"true",children:jsx("path",{d:"M229.66,77.66l-128,128a8,8,0,0,1-11.32,0l-56-56a8,8,0,0,1,11.32-11.32L96,188.69,218.34,66.34a8,8,0,0,1,11.32,11.32Z"})}),re=({className:e})=>jsx("svg",{className:w("w-[0.7em] h-[0.7em]",e),viewBox:"0 0 256 256",fill:"currentColor","aria-hidden":"true",children:jsx("path",{d:"M236.8,188.09,149.35,36.22h0a24.76,24.76,0,0,0-42.7,0L19.2,188.09a23.51,23.51,0,0,0,0,23.72A24.35,24.35,0,0,0,40.55,224h174.9a24.35,24.35,0,0,0,21.33-12.19A23.51,23.51,0,0,0,236.8,188.09ZM120,104a8,8,0,0,1,16,0v40a8,8,0,0,1-16,0Zm8,88a12,12,0,1,1,12-12A12,12,0,0,1,128,192Z"})}),ie=({className:e})=>jsxs("svg",{className:w("w-[0.7em] h-[0.7em] animate-spin",e),xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",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"})]});function Ye(...e){return e.filter(Boolean).join(" ")}var ke=R.Root,Pe=R.Trigger;var se=Ce.forwardRef(({className:e,align:t="center",sideOffset:n=4,...r},a)=>jsx(R.Portal,{children:jsx(R.Content,{ref:a,align:t,sideOffset:n,className:Ye("z-50 max-w-md rounded-md border bg-white p-1 shadow-md outline-none","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),...r})}));se.displayName=R.Content.displayName;function Se(e,t,n=(r,a)=>r===a){let r=e.length,a=t.length;if(r===0&&a===0)return [];if(r===0)return [{value:t.join(""),added:true,count:t.length}];if(a===0)return [{value:e.join(""),removed:true,count:e.length}];let i=0;for(;i<r&&i<a&&n(e[i],t[i]);)i++;let s=0;for(;s<r-i&&s<a-i&&n(e[r-1-s],t[a-1-s]);)s++;let u=e.slice(i,r-s),l=t.slice(i,a-s);if(u.length===0&&l.length===0)return [{value:e.join(""),count:e.length}];let o=qe(u,l,n),p=[];return i>0&&p.push({value:e.slice(0,i).join(""),count:i}),p.push(...o),s>0&&p.push({value:e.slice(r-s).join(""),count:s}),Me(p)}function qe(e,t,n){let r=e.length,a=t.length,i=r+a,s={1:0},u=[];e:for(let l=0;l<=i;l++){u.push({...s});for(let o=-l;o<=l;o+=2){let p;o===-l||o!==l&&s[o-1]<s[o+1]?p=s[o+1]:p=s[o-1]+1;let m=p-o;for(;p<r&&m<a&&n(e[p],t[m]);)p++,m++;if(s[o]=p,p>=r&&m>=a)break e}}return Qe(u,e,t)}function Qe(e,t,n){let r=[],a=t.length,i=n.length;for(let s=e.length-1;s>=0;s--){let u=e[s],l=a-i,o;l===-s||l!==s&&u[l-1]<u[l+1]?o=l+1:o=l-1;let p=u[o]??0,m=p-o;for(;a>p&&i>m;)a--,i--,r.unshift({value:t[a],count:1});s>0&&(a===p?(i--,r.unshift({value:n[i],added:true,count:1})):(a--,r.unshift({value:t[a],removed:true,count:1})));}return r}function Me(e){if(e.length===0)return [];let t=[];for(let n of e){let r=t[t.length-1];r&&r.added===n.added&&r.removed===n.removed?(r.value+=n.value,r.count=(r.count||1)+(n.count||1)):t.push({...n});}return t}function Ne(e){if(!e)return [];let t=[],n="";for(let r=0;r<e.length;r++){let a=e[r];n+=a,a===`
2
- `&&(t.push(n),n="");}return n.length>0&&t.push(n),t}var _e="a-zA-Z0-9_\\u00AD\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C6\\u02C8-\\u02D7\\u02DE-\\u02FF\\u1E00-\\u1EFF",et=new RegExp(`[${_e}]+|\\s+|[^${_e}]`,"gu");function we(e){return e?e.match(et)||[]:[]}function Ie(e,t){let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;return e.slice(0,n)}function oe(e,t){let n=0;for(;n<e.length&&n<t.length&&e[e.length-1-n]===t[t.length-1-n];)n++;return e.slice(e.length-n)}function tt(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(r.removed&&e[n+1]?.added){let a=r,i=e[n+1],u=Ie(a.value,i.value).match(/^\s*/)?.[0]||"",l=a.value.slice(u.length),o=i.value.slice(u.length),m=oe(l,o).match(/\s*$/)?.[0]||"";u&&t.push({value:u,count:1});let x=a.value.slice(u.length,a.value.length-m.length),v=i.value.slice(u.length,i.value.length-m.length);x&&t.push({value:x,removed:true,count:1}),v&&t.push({value:v,added:true,count:1}),m&&t.push({value:m,count:1}),n++;continue}if(r.added&&n>0&&!e[n-1].added&&!e[n-1].removed){let a=t[t.length-1];if(a&&!a.added&&!a.removed){let i=r.value.match(/^\s*/)?.[0]||"",s=a.value.match(/\s*$/)?.[0]||"";if(i&&s){let u=oe(s,i);if(u){t.push({value:r.value.slice(u.length),added:true,count:1});continue}}}}if(r.removed&&!e[n+1]?.added&&n>0&&!e[n-1]?.added&&!e[n-1]?.removed){let a=t[t.length-1],i=e[n+1];if(a&&i&&!i.added&&!i.removed){let s=r.value.match(/^\s*/)?.[0]||"",u=r.value.match(/\s*$/)?.[0]||"",l=a.value.match(/\s*$/)?.[0]||"",o=i.value.match(/^\s*/)?.[0]||"";if(s&&l&&oe(l,s).length===s.length){t.push({value:r.value.slice(s.length),removed:true,count:1});continue}if(u&&o&&Ie(u,o).length===u.length){t.push({value:r.value.slice(0,-u.length)||r.value,removed:true,count:1});continue}}}t.push({...r});}return Me(t)}function Ee(e,t){let n=Ne(e),r=Ne(t);return Se(n,r)}function De(e,t){let n=we(e),r=we(t),a=Se(n,r);return tt(a)}var Be=(e="",t="")=>useMemo(()=>{let n=(e||"").trim().replace(/\r\n/g,`
1
+ import {h,j,n,g}from'../chunk-QGXCOW3E.js';export{o as CITATION_X_PADDING,p as CITATION_Y_PADDING,n as classNames,j as generateCitationInstanceId,h as generateCitationKey,k as getCitationDisplayText,m as getCitationKeySpanText,l as getCitationNumber}from'../chunk-QGXCOW3E.js';import'../chunk-O2XFH626.js';import*as Ie from'react';import {forwardRef,useMemo,useCallback,memo,useState,useRef,useEffect}from'react';import {jsxs,Fragment,jsx}from'react/jsx-runtime';import {createPortal}from'react-dom';import*as R from'@radix-ui/react-popover';function le(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e.replace(/^https?:\/\/(www\.)?/,"").split("/")[0]}}function ye(e,t){return e.length<=t?e:e.slice(0,t-1)+"\u2026"}function at(e){try{let t=new URL(e),n=t.pathname+t.search;return n==="/"?"":n}catch{return ""}}var ke={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"},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 Pe(e){return e.startsWith("blocked_")}function Ne(e){return e.startsWith("error_")}function rt(e){return e==="verified"||e==="partial"}var ot=({status:e,errorMessage:t})=>{let n$1=ke[e];return jsx("span",{className:n("inline-flex items-center gap-1",n$1.className),title:t||n$1.label,"aria-label":n$1.label,children:jsx("span",{className:"text-[0.9em]","aria-hidden":"true",children:n$1.icon})})},ie=({url:e,faviconUrl:t})=>{let n=le(e),r=t||`https://www.google.com/s2/favicons?domain=${n}&sz=16`;return jsx("img",{src:r,alt:"",className:"w-3.5 h-3.5 rounded-sm",width:14,height:14,loading:"lazy",onError:a=>{a.target.style.display="none";}})},we=forwardRef(({urlMeta:e,citation:t,children:n$1,className:r,variant:a="chip",showFullUrlOnHover:o=true,showFavicon:i=true,showTitle:d=false,maxDisplayLength:s=30,renderBlockedIndicator:l,onUrlClick:u,eventHandlers:p,preventTooltips:h$1=false},P)=>{let{url:g,domain:A,title:N,fetchStatus:C,faviconUrl:w,errorMessage:B}=e,v=useMemo(()=>t||{value:g,fullPhrase:N||g},[t,g,N]),m=useMemo(()=>h(v),[v]),K=useMemo(()=>j(m),[m]),M=useMemo(()=>A||le(g),[A,g]),L=useMemo(()=>at(g),[g]),D=useMemo(()=>{if(d&&N)return ye(N,s);let b=L?ye(L,s-M.length-1):"";return b?`${M}${b}`:M},[d,N,M,L,s]),S=ke[C],Z=Pe(C),ee=Ne(C),te=C==="verified",G=C==="partial",T=C==="pending",O=useCallback(b=>{b.preventDefault(),b.stopPropagation(),u?u(g,b):window.open(g,"_blank","noopener,noreferrer"),p?.onClick?.(v,m,b);},[u,g,p,v,m]),y=useCallback(()=>{p?.onMouseEnter?.(v,m);},[p,v,m]),E=useCallback(()=>{p?.onMouseLeave?.(v,m);},[p,v,m]),_=()=>Z||ee?l?l(C,B):jsx(ot,{status:C,errorMessage:B}):te?jsx("span",{className:"text-[0.85em] text-green-600 dark:text-green-500","aria-hidden":"true",title:"Verified",children:"\u2713"}):G?jsx("span",{className:"text-[0.85em] text-amber-600 dark:text-amber-500","aria-hidden":"true",title:"Partial match",children:"~"}):T?jsx("span",{className:"opacity-70","aria-hidden":"true",children:"\u2026"}):null;return a==="chip"?jsxs(Fragment,{children:[n$1,jsxs("span",{ref:P,"data-citation-id":m,"data-citation-instance":K,"data-url":g,"data-fetch-status":C,"data-variant":"chip",className:n("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",S.className,r),title:o?g:void 0,onMouseEnter:h$1?void 0:y,onMouseLeave:h$1?void 0:E,onMouseDown:O,onClick:b=>b.stopPropagation(),role:"link","aria-label":`Link to ${M}: ${S.label}`,children:[i&&jsx(ie,{url:g,faviconUrl:w}),jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:D}),_()]})]}):a==="inline"?jsxs(Fragment,{children:[n$1,jsxs("a",{ref:P,href:g,"data-citation-id":m,"data-citation-instance":K,"data-fetch-status":C,"data-variant":"inline",className:n("inline-flex items-center gap-1 cursor-pointer transition-colors no-underline border-b border-dotted border-current",S.className,r),title:o?g:void 0,onMouseEnter:h$1?void 0:y,onMouseLeave:h$1?void 0:E,onClick:b=>{b.preventDefault(),O(b);},target:"_blank",rel:"noopener noreferrer","aria-label":`Link to ${M}: ${S.label}`,children:[i&&jsx(ie,{url:g,faviconUrl:w}),jsx("span",{children:D}),_()]})]}):jsxs(Fragment,{children:[n$1,jsxs("span",{ref:P,"data-citation-id":m,"data-citation-instance":K,"data-url":g,"data-fetch-status":C,"data-variant":"bracket",className:n("cursor-pointer transition-colors",S.className,r),title:o?g:void 0,onMouseEnter:h$1?void 0:y,onMouseLeave:h$1?void 0:E,onMouseDown:O,onClick:b=>b.stopPropagation(),role:"link","aria-label":`Link to ${M}: ${S.label}`,children:["[",i&&jsx(ie,{url:g,faviconUrl:w}),jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:D}),_(),"]"]})]})});we.displayName="UrlCitationComponent";memo(we);var it=({className:e})=>jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"square",shapeRendering:"crispEdges",className:e,children:[jsx("path",{d:"M7 3 L3 3 L3 21 L7 21"}),jsx("path",{d:"M17 3 L21 3 L21 21 L17 21"})]}),Q=({className:e})=>jsx("svg",{className:g("w-[0.7em] h-[0.7em]",e),viewBox:"0 0 256 256",fill:"currentColor","aria-hidden":"true",children:jsx("path",{d:"M229.66,77.66l-128,128a8,8,0,0,1-11.32,0l-56-56a8,8,0,0,1,11.32-11.32L96,188.69,218.34,66.34a8,8,0,0,1,11.32,11.32Z"})}),ce=({className:e})=>jsx("svg",{className:g("w-[0.7em] h-[0.7em]",e),viewBox:"0 0 256 256",fill:"currentColor","aria-hidden":"true",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"})}),de=({className:e})=>jsxs("svg",{className:g("w-[0.7em] h-[0.7em] animate-spin",e),xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",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"})]});function st(...e){return e.filter(Boolean).join(" ")}var Ee=R.Root,_e=R.Trigger;var ue=Ie.forwardRef(({className:e,align:t="center",sideOffset:n=4,...r},a)=>jsx(R.Portal,{children:jsx(R.Content,{ref:a,align:t,sideOffset:n,className:st("z-50 max-w-sm rounded-md border bg-white p-1 shadow-md outline-none","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),...r})}));ue.displayName=R.Content.displayName;function Ve(e,t,n=(r,a)=>r===a){let r=e.length,a=t.length;if(r===0&&a===0)return [];if(r===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<r&&o<a&&n(e[o],t[o]);)o++;let i=0;for(;i<r-o&&i<a-o&&n(e[r-1-i],t[a-1-i]);)i++;let d=e.slice(o,r-i),s=t.slice(o,a-i);if(d.length===0&&s.length===0)return [{value:e.join(""),count:e.length}];let l=lt(d,s,n),u=[];return o>0&&u.push({value:e.slice(0,o).join(""),count:o}),u.push(...l),i>0&&u.push({value:e.slice(r-i).join(""),count:i}),Te(u)}function lt(e,t,n){let r=e.length,a=t.length,o=r+a,i={1:0},d=[];e:for(let s=0;s<=o;s++){d.push({...i});for(let l=-s;l<=s;l+=2){let u;l===-s||l!==s&&i[l-1]<i[l+1]?u=i[l+1]:u=i[l-1]+1;let p=u-l;for(;u<r&&p<a&&n(e[u],t[p]);)u++,p++;if(i[l]=u,u>=r&&p>=a)break e}}return ct(d,e,t)}function ct(e,t,n){let r=[],a=t.length,o=n.length;for(let i=e.length-1;i>=0;i--){let d=e[i],s=a-o,l;s===-i||s!==i&&d[s-1]<d[s+1]?l=s+1:l=s-1;let u=d[l]??0,p=u-l;for(;a>u&&o>p;)a--,o--,r.unshift({value:t[a],count:1});i>0&&(a===u?(o--,r.unshift({value:n[o],added:true,count:1})):(a--,r.unshift({value:t[a],removed:true,count:1})));}return r}function Te(e){if(e.length===0)return [];let t=[];for(let n of e){let r=t[t.length-1];r&&r.added===n.added&&r.removed===n.removed?(r.value+=n.value,r.count=(r.count||1)+(n.count||1)):t.push({...n});}return t}function Le(e){if(!e)return [];let t=[],n="";for(let r=0;r<e.length;r++){let a=e[r];n+=a,a===`
2
+ `&&(t.push(n),n="");}return n.length>0&&t.push(n),t}var De="a-zA-Z0-9_\\u00AD\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C6\\u02C8-\\u02D7\\u02DE-\\u02FF\\u1E00-\\u1EFF",dt=new RegExp(`[${De}]+|\\s+|[^${De}]`,"gu");function Re(e){return e?e.match(dt)||[]:[]}function Be(e,t){let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;return e.slice(0,n)}function pe(e,t){let n=0;for(;n<e.length&&n<t.length&&e[e.length-1-n]===t[t.length-1-n];)n++;return e.slice(e.length-n)}function ut(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(r.removed&&e[n+1]?.added){let a=r,o=e[n+1],d=Be(a.value,o.value).match(/^\s*/)?.[0]||"",s=a.value.slice(d.length),l=o.value.slice(d.length),p=pe(s,l).match(/\s*$/)?.[0]||"";d&&t.push({value:d,count:1});let h=a.value.slice(d.length,a.value.length-p.length),P=o.value.slice(d.length,o.value.length-p.length);h&&t.push({value:h,removed:true,count:1}),P&&t.push({value:P,added:true,count:1}),p&&t.push({value:p,count:1}),n++;continue}if(r.added&&n>0&&!e[n-1].added&&!e[n-1].removed){let a=t[t.length-1];if(a&&!a.added&&!a.removed){let o=r.value.match(/^\s*/)?.[0]||"",i=a.value.match(/\s*$/)?.[0]||"";if(o&&i){let d=pe(i,o);if(d){t.push({value:r.value.slice(d.length),added:true,count:1});continue}}}}if(r.removed&&!e[n+1]?.added&&n>0&&!e[n-1]?.added&&!e[n-1]?.removed){let a=t[t.length-1],o=e[n+1];if(a&&o&&!o.added&&!o.removed){let i=r.value.match(/^\s*/)?.[0]||"",d=r.value.match(/\s*$/)?.[0]||"",s=a.value.match(/\s*$/)?.[0]||"",l=o.value.match(/^\s*/)?.[0]||"";if(i&&s&&pe(s,i).length===i.length){t.push({value:r.value.slice(i.length),removed:true,count:1});continue}if(d&&l&&Be(d,l).length===d.length){t.push({value:r.value.slice(0,-d.length)||r.value,removed:true,count:1});continue}}}t.push({...r});}return Te(t)}function Ue(e,t){let n=Le(e),r=Le(t);return Ve(n,r)}function We(e,t){let n=Re(e),r=Re(t),a=Ve(n,r);return ut(a)}var Ae=(e="",t="")=>useMemo(()=>{let n=(e||"").trim().replace(/\r\n/g,`
3
3
  `),r=(t||"").trim().replace(/\r\n/g,`
4
- `),a=Ee(n,r),i=[],s=false,u=0;for(let p=0;p<a.length;p++){let m=a[p],x=a[p+1];if(m.removed&&x&&x.added){let v=De(m.value,x.value);i.push({type:"modified",parts:v}),s=true,u+=Math.abs(m.value.length-x.value.length),p++;}else m.added||m.removed?(i.push({type:m.added?"added":"removed",parts:[{value:m.value,added:m.added,removed:m.removed}]}),s=true,u+=m.value.length):i.push({type:"unchanged",parts:[{value:m.value}]});}let l=Math.max(n.length,r.length),o=l===0?1:1-u/l;return {diffResult:i,hasDiff:s,similarity:o,isHighVariance:o<.6}},[e,t]);function ot(e){switch(e){case "chip":case "text":case "brackets":return "keySpan";default:return "number"}}function lt(e){return e.replace(/^\[+\s*/,"").replace(/\s*\]+$/,"")}function ct(e,t,n){if(t==="indicator")return "";if(t==="keySpan"){let r=e.keySpan?.toString()||e.citationNumber?.toString()||n||"1";return lt(r)}return e.citationNumber?.toString()||"1"}function dt(e){return e.isVerified&&!e.isPartialMatch?"Verified":e.isPartialMatch?"Partial Match":e.isMiss?"Not Found":e.isPending?"Verifying...":""}function ut(e){let t=e?.status;if(!e||!t)return {isVerified:false,isMiss:false,isPartialMatch:false,isPending:false};let n=t==="not_found",r=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:n,isPartialMatch:a,isPending:r}}function pt({src:e,alt:t,onClose:n}){return useEffect(()=>{let r=a=>{a.key==="Escape"&&n();};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[n]),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",onClick:n,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",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 mt=()=>jsx("span",{className:"inline-flex relative ml-0.5 text-green-600 dark:text-green-500","aria-hidden":"true",children:jsx(Y,{})}),gt=()=>jsx("span",{className:"inline-flex relative ml-0.5 text-amber-600 dark:text-amber-500","aria-hidden":"true",children:jsx(Y,{})}),ft=()=>jsx("span",{className:"inline-flex ml-1 text-gray-400 dark:text-gray-500","aria-hidden":"true",children:jsx(ie,{})}),ht=()=>jsx("span",{className:"inline-flex relative ml-0.5 text-red-500 dark:text-red-400","aria-hidden":"true",children:jsx(re,{})});function xt({citation:e,verification:t,status:n,onImageClick:r}){let a=t?.verificationImageBase64,{isMiss:i,isPartialMatch:s}=n;if(a)return jsxs("div",{className:"p-1",children:[jsx("button",{type:"button",className:"block cursor-zoom-in",onClick:p=>{p.preventDefault(),p.stopPropagation(),r?.();},"aria-label":"Click to view full size",children:jsx("img",{src:t.verificationImageBase64,alt:"Citation verification",className:"max-w-[700px] max-h-[500px] w-auto h-auto object-contain rounded bg-gray-50 dark:bg-gray-800",loading:"lazy"})}),(i||s)&&jsx(Re,{citation:e,verification:t,status:n})]});let u=dt(n),l=t?.verifiedMatchSnippet,o=t?.verifiedPageNumber;return !l&&!u?null:jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[200px] max-w-[400px]",children:[u&&jsx("span",{className:w("text-xs font-medium",n.isVerified&&!n.isPartialMatch&&"text-green-600 dark:text-green-500",n.isPartialMatch&&"text-amber-600 dark:text-amber-500",n.isMiss&&"text-red-600 dark:text-red-500",n.isPending&&"text-gray-500 dark:text-gray-400"),children:u}),l&&jsxs("span",{className:"text-sm text-gray-700 dark:text-gray-300 italic",children:['"',t.verifiedMatchSnippet,'"']}),o&&o>0&&jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Page ",o]}),(i||s)&&jsx(Re,{citation:e,verification:t,status:n})]})}function Re({citation:e,verification:t,status:n}){let{isMiss:r,isPartialMatch:a}=n,i=e.fullPhrase||e.keySpan?.toString()||"",s=t?.verifiedMatchSnippet||"",{diffResult:u,hasDiff:l,isHighVariance:o}=Be(i,s);if(!r&&!a)return null;let p=e.lineIds,m=t?.verifiedLineIds,x=p&&m&&JSON.stringify(p)!==JSON.stringify(m),v=e.pageNumber,g=t?.verifiedPageNumber,S=v!=null&&g!=null&&v!==g;return r?jsxs("div",{className:"mt-2 pt-2 border-t border-gray-200 dark:border-gray-700 text-xs space-y-2",children:[i&&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:i.length>100?i.slice(0,100)+"\u2026":i})]}),jsxs("div",{children:[jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Found"}),jsx("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 in source"})]})]}):jsxs("div",{className:"mt-2 pt-2 border-t border-gray-200 dark:border-gray-700 text-xs space-y-2",children:[i&&s&&l?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:o?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:i.length>100?i.slice(0,100)+"\u2026":i})]}),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:s.length>100?s.slice(0,100)+"\u2026":s})]})]}):u.map((P,f)=>jsx("span",{children:P.parts.map((b,_)=>{let y=`p-${f}-${_}`;return b.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:b.value},y):b.added?jsx("span",{className:"bg-green-200 dark:bg-green-900/50 text-green-700 dark:text-green-300",title:"Actual text found",children:b.value},y):jsx("span",{children:b.value},y)})},`block-${f}`))})]}):i&&!l?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:i.length>100?i.slice(0,100)+"\u2026":i})]}):null,S&&jsxs("div",{children:[jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Page"}),jsxs("p",{className:"mt-1 font-mono text-[11px] text-gray-700 dark:text-gray-300",children:[jsx("span",{className:"text-red-600 dark:text-red-400 line-through opacity-70",children:v})," \u2192 ",g]})]}),x&&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:p?.join(", ")})," \u2192 ",m?.join(", ")]})]})]})}var le=forwardRef(({citation:e,children:t,className:n,fallbackDisplay:r,verification:a,isLoading:i=false,variant:s="brackets",content:u,eventHandlers:l,behaviorConfig:o,isMobile:p=false,renderIndicator:m,renderContent:x,popoverPosition:v="top",renderPopoverContent:g},S)=>{let P=useMemo(()=>u||ot(s),[u,s]),[f,b]=useState(false),[_,y]=useState(null),c=useMemo(()=>Z(e),[e]),I=useMemo(()=>G(c),[c]),N=useMemo(()=>ut(a),[a]),{isMiss:M,isPartialMatch:B,isVerified:E,isPending:A}=N,L=useMemo(()=>ct(e,P,r),[e,P,r]),V=useCallback(()=>({citation:e,citationKey:c,verification:a??null,isTooltipExpanded:f,isImageExpanded:!!_,hasImage:!!a?.verificationImageBase64}),[e,c,a,f,_]),J=useCallback(k=>{k.setImageExpanded!==void 0&&(typeof k.setImageExpanded=="string"?y(k.setImageExpanded):k.setImageExpanded===true&&a?.verificationImageBase64?y(a.verificationImageBase64):k.setImageExpanded===false&&y(null));},[a?.verificationImageBase64]),q=useCallback(k=>{k.preventDefault(),k.stopPropagation();let H=V();if(o?.onClick){let Q=o.onClick(H,k);Q&&typeof Q=="object"&&J(Q),l?.onClick?.(e,c,k);return}if(l?.onClick){l.onClick(e,c,k);return}a?.verificationImageBase64&&y(a.verificationImageBase64);},[o,l,e,c,a?.verificationImageBase64,V,J]),K=useCallback(()=>{b(true),o?.onHover?.onEnter&&o.onHover.onEnter(V()),l?.onMouseEnter?.(e,c);},[l,o,e,c,V]),O=useCallback(()=>{b(false),o?.onHover?.onLeave&&o.onHover.onLeave(V()),l?.onMouseLeave?.(e,c);},[l,o,e,c,V]),F=useCallback(k=>{p&&(k.preventDefault(),k.stopPropagation(),l?.onTouchEnd?.(e,c,k));},[l,e,c,p]);if(r!=null&&P==="keySpan"&&M)return jsx("span",{className:w("text-gray-400 dark:text-gray-500",n),children:r});let $=w((E||B)&&s==="brackets"&&"text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 hover:underline",M&&"opacity-70 line-through text-gray-400 dark:text-gray-500",(i||A)&&"text-gray-500 dark:text-gray-400"),C=()=>m?m(N):i||A?jsx(ft,{}):M?jsx(ht,{}):B?jsx(gt,{}):E?jsx(mt,{}):null,ce=()=>{if(x)return x({citation:e,status:N,citationKey:c,displayText:L,isMergedDisplay:P==="keySpan"});if(P==="indicator")return jsx("span",{children:C()});if(s==="chip"){let k=w(E&&!B&&!i&&"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",B&&!i&&"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",M&&!i&&"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400 line-through",(i||A)&&"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400",!E&&!M&&!i&&!A&&"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400");return jsxs("span",{className:w("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-sm font-medium",k),children:[jsx("span",{className:"max-w-60 overflow-hidden text-ellipsis whitespace-nowrap",children:L}),C()]})}if(s==="superscript"){let k=w(E&&!B&&!i&&"text-green-600 dark:text-green-500",B&&!i&&"text-amber-600 dark:text-amber-500",M&&!i&&"text-red-500 dark:text-red-400 line-through",(i||A)&&"text-gray-400 dark:text-gray-500",!E&&!M&&!i&&!A&&"text-blue-600 dark:text-blue-400");return jsxs("sup",{className:w("text-xs font-medium transition-colors hover:underline",k),children:["[",L,C(),"]"]})}return s==="text"?jsxs("span",{className:$,children:[L,C()]}):s==="minimal"?jsxs("span",{className:w("max-w-80 overflow-hidden text-ellipsis",$),children:[L,C()]}):jsxs("span",{className:w("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:w("max-w-80 overflow-hidden text-ellipsis",$),children:[L,C()]}),"]"]})},Ve=!(v==="hidden")&&a&&(a.verificationImageBase64||a.verifiedMatchSnippet),Ue=!!a?.verificationImageBase64,de=_?jsx(pt,{src:_,alt:"Citation verification - full size",onClose:()=>y(null)}):null,ue={"data-citation-id":c,"data-citation-instance":I,className:w("relative inline-flex items-baseline cursor-pointer","px-0.5 -mx-0.5 rounded-sm","transition-all duration-150","hover:bg-blue-500/10 dark:hover:bg-blue-400/10",Ue&&"hover:cursor-zoom-in",n),onMouseEnter:K,onMouseLeave:O,onClick:q,onTouchEndCapture:p?F:void 0,"aria-label":L?`[${L}]`:void 0};if(Ve){let k=g?g({citation:e,verification:a??null,status:N}):jsx(xt,{citation:e,verification:a??null,status:N,onImageClick:()=>{a?.verificationImageBase64&&y(a.verificationImageBase64);}});return jsxs(Fragment,{children:[t,jsxs(ke,{open:f,children:[jsx(Pe,{asChild:true,children:jsx("span",{ref:S,...ue,children:ce()})}),jsx(se,{side:v==="bottom"?"bottom":"top",onPointerDownOutside:H=>H.preventDefault(),onInteractOutside:H=>H.preventDefault(),children:k})]}),de]})}return jsxs(Fragment,{children:[t,jsx("span",{ref:S,...ue,children:ce()}),de]})});le.displayName="CitationComponent";var vt=memo(le);export{Ke as CITATION_X_PADDING,Oe as CITATION_Y_PADDING,Y as CheckIcon,le as CitationComponent,Je as DeepCitationIcon,vt as MemoizedCitationComponent,ie as SpinnerIcon,re as WarningIcon,j as classNames,ae as extractDomain,G as generateCitationInstanceId,Z as generateCitationKey,ze as getCitationDisplayText,Te as getCitationKeySpanText,We as getCitationNumber,he as isBlockedStatus,xe as isErrorStatus,Ge as isVerifiedStatus};
4
+ `),a=Ue(n,r),o=[],i=false,d=0;for(let u=0;u<a.length;u++){let p=a[u],h=a[u+1];if(p.removed&&h&&h.added){let P=We(p.value,h.value);o.push({type:"modified",parts:P}),i=true,d+=Math.abs(p.value.length-h.value.length),u++;}else p.added||p.removed?(o.push({type:p.added?"added":"removed",parts:[{value:p.value,added:p.added,removed:p.removed}]}),i=true,d+=p.value.length):o.push({type:"unchanged",parts:[{value:p.value}]});}let s=Math.max(n.length,r.length),l=s===0?1:1-d/s;return {diffResult:o,hasDiff:i,similarity:l,isHighVariance:l<.6}},[e,t]);function xt(e){switch(e){case "chip":case "text":case "brackets":return "keySpan";default:return "number"}}function ht(e){return e.replace(/^\[+\s*/,"").replace(/\s*\]+$/,"")}function vt(e,t,n){if(t==="indicator")return "";if(t==="keySpan"){let r=e.keySpan?.toString()||e.citationNumber?.toString()||n||"1";return ht(r)}return e.citationNumber?.toString()||"1"}function Ct(e){return e.isVerified&&!e.isPartialMatch?"Verified":e.isPartialMatch?"Partial Match":e.isMiss?"Not Found":e.isPending?"Verifying...":""}function bt(e){let t=e?.status;if(!e||!t)return {isVerified:false,isMiss:false,isPartialMatch:false,isPending:false};let n=t==="not_found",r=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:n,isPartialMatch:a,isPending:r}}function yt({src:e,alt:t,onClose:n}){return useEffect(()=>{let r=a=>{a.key==="Escape"&&n();};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[n]),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",onClick:n,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",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 kt=()=>jsx("span",{className:"inline-flex relative ml-0.5 text-green-600 dark:text-green-500","aria-hidden":"true",children:jsx(Q,{})}),Pt=()=>jsx("span",{className:"inline-flex relative ml-0.5 text-amber-600 dark:text-amber-500","aria-hidden":"true",children:jsx(Q,{})}),Nt=()=>jsx("span",{className:"inline-flex ml-1 text-gray-400 dark:text-gray-500","aria-hidden":"true",children:jsx(de,{})}),wt=()=>jsx("span",{className:"inline-flex relative ml-0.5 text-red-500 dark:text-red-400","aria-hidden":"true",children:jsx(ce,{})});function Mt({citation:e,verification:t,status:n,onImageClick:r}){let a=t?.verificationImageBase64,{isMiss:o,isPartialMatch:i}=n;if(a)return jsxs("div",{className:"p-1",children:[jsx("button",{type:"button",className:"block cursor-zoom-in",onClick:u=>{u.preventDefault(),u.stopPropagation(),r?.();},"aria-label":"Click to view full size",children:jsx("img",{src:t.verificationImageBase64,alt:"Citation verification",className:"max-w-[700px] max-h-[500px] w-auto h-auto object-contain rounded bg-gray-50 dark:bg-gray-800",loading:"lazy"})}),(o||i)&&jsx(Oe,{citation:e,verification:t,status:n})]});let d=Ct(n),s=t?.verifiedMatchSnippet,l=t?.verifiedPageNumber;return !s&&!d?null:jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[200px] max-w-[400px]",children:[d&&jsx("span",{className:g("text-xs font-medium",n.isVerified&&!n.isPartialMatch&&"text-green-600 dark:text-green-500",n.isPartialMatch&&"text-amber-600 dark:text-amber-500",n.isMiss&&"text-red-600 dark:text-red-500",n.isPending&&"text-gray-500 dark:text-gray-400"),children:d}),s&&jsxs("span",{className:"text-sm text-gray-700 dark:text-gray-300 italic",children:['"',t.verifiedMatchSnippet,'"']}),l&&l>0&&jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Page ",l]}),(o||i)&&jsx(Oe,{citation:e,verification:t,status:n})]})}function Oe({citation:e,verification:t,status:n}){let{isMiss:r,isPartialMatch:a}=n,o=e.fullPhrase||e.keySpan?.toString()||"",i=t?.verifiedMatchSnippet||"",{diffResult:d,hasDiff:s,isHighVariance:l}=Ae(o,i);if(!r&&!a)return null;let u=e.lineIds,p=t?.verifiedLineIds,h=u&&p&&JSON.stringify(u)!==JSON.stringify(p),P=e.pageNumber,g=t?.verifiedPageNumber,A=P!=null&&g!=null&&P!==g;return r?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"}),jsx("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 in source"})]})]}):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:l?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((N,C)=>jsx("span",{children:N.parts.map((w,B)=>{let v=`p-${C}-${B}`;return w.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:w.value},v):w.added?jsx("span",{className:"bg-green-200 dark:bg-green-900/50 text-green-700 dark:text-green-300",title:"Actual text found",children:w.value},v):jsx("span",{children:w.value},v)})},`block-${C}`))})]}):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,A&&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:P})," \u2192 ",g]})]}),h&&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 ",p?.join(", ")]})]})]})}var xe=forwardRef(({citation:e,children:t,className:n,fallbackDisplay:r,verification:a,isLoading:o=false,variant:i="brackets",content:d,eventHandlers:s,behaviorConfig:l,isMobile:u=false,renderIndicator:p,renderContent:h$1,popoverPosition:P="top",renderPopoverContent:g$1},A)=>{let N=useMemo(()=>d||xt(i),[d,i]),[C,w]=useState(false),[B,v]=useState(null),m=useMemo(()=>h(e),[e]),K=useMemo(()=>j(m),[m]),M=useMemo(()=>bt(a),[a]),{isMiss:L,isPartialMatch:D,isVerified:S,isPending:Z}=M,ee=5e3,[te,G]=useState(false),T=useRef(null),O=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",y=(o||Z)&&!O&&!te;useEffect(()=>(T.current&&(clearTimeout(T.current),T.current=null),(o||Z)&&!O?(G(false),T.current=setTimeout(()=>{G(true);},ee)):G(false),()=>{T.current&&clearTimeout(T.current);}),[o,Z,O]);let E=useMemo(()=>vt(e,N,r),[e,N,r]),_=useCallback(()=>({citation:e,citationKey:m,verification:a??null,isTooltipExpanded:C,isImageExpanded:!!B,hasImage:!!a?.verificationImageBase64}),[e,m,a,C,B]),b=useCallback(x=>{x.setImageExpanded!==void 0&&(typeof x.setImageExpanded=="string"?v(x.setImageExpanded):x.setImageExpanded===true&&a?.verificationImageBase64?v(a.verificationImageBase64):x.setImageExpanded===false&&v(null));},[a?.verificationImageBase64]),ze=useCallback(x=>{x.preventDefault(),x.stopPropagation();let X=_();if(l?.onClick){let re=l.onClick(X,x);re&&typeof re=="object"&&b(re),s?.onClick?.(e,m,x);return}if(s?.onClick){s.onClick(e,m,x);return}a?.verificationImageBase64&&v(a.verificationImageBase64);},[l,s,e,m,a?.verificationImageBase64,_,b]),he=150,$=useRef(null),ne=useRef(false),U=useCallback(()=>{$.current&&(clearTimeout($.current),$.current=null);},[]),je=useCallback(()=>{U(),w(true),l?.onHover?.onEnter&&l.onHover.onEnter(_()),s?.onMouseEnter?.(e,m);},[s,l,e,m,_,U]),Fe=useCallback(()=>{U(),$.current=setTimeout(()=>{ne.current||(w(false),l?.onHover?.onLeave&&l.onHover.onLeave(_()),s?.onMouseLeave?.(e,m));},he);},[s,l,e,m,_,U]),He=useCallback(()=>{U(),ne.current=true;},[U]),Ke=useCallback(()=>{ne.current=false,U(),$.current=setTimeout(()=>{w(false),l?.onHover?.onLeave&&l.onHover.onLeave(_()),s?.onMouseLeave?.(e,m);},he);},[s,l,e,m,_,U]);useEffect(()=>()=>{$.current&&clearTimeout($.current);},[]);let Ze=useCallback(x=>{u&&(x.preventDefault(),x.stopPropagation(),s?.onTouchEnd?.(e,m,x));},[s,e,m,u]);if(r!=null&&N==="keySpan"&&L)return jsx("span",{className:g("text-gray-400 dark:text-gray-500",n),children:r});let ae=g((S||D)&&i==="brackets"&&"text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 hover:underline",L&&"opacity-70 line-through text-gray-400 dark:text-gray-500",y&&"text-gray-500 dark:text-gray-400"),z=()=>p?p(M):y?jsx(Nt,{}):L?jsx(wt,{}):D?jsx(Pt,{}):S?jsx(kt,{}):null,ve=()=>{if(h$1)return h$1({citation:e,status:M,citationKey:m,displayText:E,isMergedDisplay:N==="keySpan"});if(N==="indicator")return jsx("span",{children:z()});if(i==="chip"){let x=g(S&&!D&&!y&&"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",D&&!y&&"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",L&&!y&&"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400 line-through",y&&"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400",!S&&!L&&!y&&"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400");return jsxs("span",{className:g("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-sm font-medium",x),children:[jsx("span",{className:"max-w-60 overflow-hidden text-ellipsis whitespace-nowrap",children:E}),z()]})}if(i==="superscript"){let x=g(S&&!D&&!y&&"text-green-600 dark:text-green-500",D&&!y&&"text-amber-600 dark:text-amber-500",L&&!y&&"text-red-500 dark:text-red-400 line-through",y&&"text-gray-400 dark:text-gray-500",!S&&!L&&!y&&"text-blue-600 dark:text-blue-400");return jsxs("sup",{className:g("text-xs font-medium transition-colors hover:underline",x),children:["[",E,z(),"]"]})}return i==="text"?jsxs("span",{className:ae,children:[E,z()]}):i==="minimal"?jsxs("span",{className:g("max-w-80 overflow-hidden text-ellipsis",ae),children:[E,z()]}):jsxs("span",{className:g("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:g("max-w-80 overflow-hidden text-ellipsis",ae),children:[E,z()]}),"]"]})},Ge=!(P==="hidden")&&a&&(a.verificationImageBase64||a.verifiedMatchSnippet),Xe=!!a?.verificationImageBase64,Ce=B?jsx(yt,{src:B,alt:"Citation verification - full size",onClose:()=>v(null)}):null,be={"data-citation-id":m,"data-citation-instance":K,className:g("relative inline-flex items-baseline cursor-pointer","px-0.5 -mx-0.5 rounded-sm","transition-all duration-150","hover:bg-blue-500/10 dark:hover:bg-blue-400/10",Xe&&"hover:cursor-zoom-in",n),onMouseEnter:je,onMouseLeave:Fe,onClick:ze,onTouchEndCapture:u?Ze:void 0,"aria-label":E?`[${E}]`:void 0};if(Ge){let x=g$1?g$1({citation:e,verification:a??null,status:M}):jsx(Mt,{citation:e,verification:a??null,status:M,onImageClick:()=>{a?.verificationImageBase64&&v(a.verificationImageBase64);}});return jsxs(Fragment,{children:[t,jsxs(Ee,{open:C,children:[jsx(_e,{asChild:true,children:jsx("span",{ref:A,...be,children:ve()})}),jsx(ue,{side:P==="bottom"?"bottom":"top",onPointerDownOutside:X=>X.preventDefault(),onInteractOutside:X=>X.preventDefault(),onMouseEnter:He,onMouseLeave:Ke,children:x})]}),Ce]})}return jsxs(Fragment,{children:[t,jsx("span",{ref:A,...be,children:ve()}),Ce]})});xe.displayName="CitationComponent";var St=memo(xe);export{Q as CheckIcon,xe as CitationComponent,it as DeepCitationIcon,St as MemoizedCitationComponent,de as SpinnerIcon,ce as WarningIcon,le as extractDomain,Pe as isBlockedStatus,Ne as isErrorStatus,rt as isVerifiedStatus};
@@ -0,0 +1,45 @@
1
+ import { Citation, Verification } from './types/index.cjs';
2
+
3
+ /**
4
+ * Generates a unique, deterministic key for a citation based on its content.
5
+ * @param citation - The citation to generate a key for
6
+ * @returns A unique, deterministic key for the citation
7
+ */
8
+ declare function generateCitationKey(citation: Citation): string;
9
+ /**
10
+ * Generates a unique, deterministic key for a verification based on its content.
11
+ * @param verification - The verification to generate a key for
12
+ * @returns
13
+ */
14
+ declare function generateVerificationKey(verification: Verification): string;
15
+ /**
16
+ * Generates a unique instance ID for a citation component render.
17
+ * Combines the citation key with a random suffix for uniqueness.
18
+ */
19
+ declare function generateCitationInstanceId(citationKey: string): string;
20
+ /**
21
+ * Gets the display text for a citation (keySpan with fallback to number).
22
+ */
23
+ declare function getCitationDisplayText(citation: Citation, options?: {
24
+ fallbackDisplay?: string | null;
25
+ }): string;
26
+ /**
27
+ * Gets the citation number as a string.
28
+ */
29
+ declare function getCitationNumber(citation: Citation): string;
30
+ /**
31
+ * Gets the keySpan text from a citation.
32
+ */
33
+ declare function getCitationKeySpanText(citation: Citation): string;
34
+ /**
35
+ * Joins class names, filtering out falsy values.
36
+ * This is a minimal implementation for the base component.
37
+ */
38
+ declare function classNames(...classes: (string | undefined | null | false)[]): string;
39
+ /**
40
+ * Default padding values for citation styling.
41
+ */
42
+ declare const CITATION_X_PADDING = 4;
43
+ declare const CITATION_Y_PADDING = 1;
44
+
45
+ export { CITATION_X_PADDING as C, generateVerificationKey as a, generateCitationInstanceId as b, CITATION_Y_PADDING as c, getCitationDisplayText as d, getCitationNumber as e, getCitationKeySpanText as f, generateCitationKey as g, classNames as h };