@deepcitation/deepcitation-js 1.1.26 → 1.1.28
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.
- package/LICENSE +21 -21
- package/README.md +253 -253
- package/lib/chunk-2IZXUOQR.js +66 -0
- package/lib/chunk-4FGOHQFP.cjs +66 -0
- package/lib/chunk-CFXDRAJL.cjs +1 -0
- package/lib/chunk-DEUSSEFH.js +2 -0
- package/lib/chunk-F2MMVEVC.cjs +1 -0
- package/lib/chunk-J7U6YFOI.cjs +2 -0
- package/lib/chunk-O2XFH626.js +1 -0
- package/lib/chunk-RQPZSRID.js +1 -0
- package/lib/client/index.cjs +1 -0
- package/lib/client/{DeepCitation.d.ts → index.d.cts} +159 -3
- package/lib/client/index.d.ts +342 -2
- package/lib/client/index.js +1 -1
- package/lib/index.cjs +1 -0
- package/lib/index.d.cts +127 -0
- package/lib/index.d.ts +126 -23
- package/lib/index.js +1 -22
- package/lib/prompts/index.cjs +1 -0
- package/lib/prompts/index.d.cts +196 -0
- package/lib/prompts/index.d.ts +196 -3
- package/lib/prompts/index.js +1 -3
- package/lib/react/index.cjs +4 -0
- package/lib/react/index.js +4 -18
- package/lib/types/index.cjs +1 -0
- package/lib/types/index.d.cts +96 -0
- package/lib/types/index.d.ts +96 -11
- package/lib/types/index.js +1 -7
- package/package.json +62 -10
- package/lib/client/DeepCitation.js +0 -374
- package/lib/client/types.d.ts +0 -154
- package/lib/client/types.js +0 -1
- package/lib/parsing/normalizeCitation.d.ts +0 -5
- package/lib/parsing/normalizeCitation.js +0 -198
- package/lib/parsing/parseCitation.d.ts +0 -79
- package/lib/parsing/parseCitation.js +0 -431
- package/lib/parsing/parseWorkAround.d.ts +0 -2
- package/lib/parsing/parseWorkAround.js +0 -73
- package/lib/prompts/citationPrompts.d.ts +0 -138
- package/lib/prompts/citationPrompts.js +0 -168
- package/lib/prompts/promptCompression.d.ts +0 -14
- package/lib/prompts/promptCompression.js +0 -127
- package/lib/prompts/types.d.ts +0 -4
- package/lib/prompts/types.js +0 -1
- package/lib/react/CitationComponent.d.ts +0 -93
- package/lib/react/CitationComponent.js +0 -371
- package/lib/react/CitationVariants.d.ts +0 -132
- package/lib/react/CitationVariants.js +0 -284
- package/lib/react/DiffDisplay.d.ts +0 -10
- package/lib/react/DiffDisplay.js +0 -33
- package/lib/react/Popover.d.ts +0 -15
- package/lib/react/Popover.js +0 -20
- package/lib/react/UrlCitationComponent.d.ts +0 -83
- package/lib/react/UrlCitationComponent.js +0 -224
- package/lib/react/VerificationTabs.d.ts +0 -10
- package/lib/react/VerificationTabs.js +0 -36
- package/lib/react/icons.d.ts +0 -18
- package/lib/react/icons.js +0 -16
- package/lib/react/index.d.ts +0 -16
- package/lib/react/primitives.d.ts +0 -101
- package/lib/react/primitives.js +0 -193
- package/lib/react/types.d.ts +0 -283
- package/lib/react/types.js +0 -1
- package/lib/react/useSmartDiff.d.ts +0 -16
- package/lib/react/useSmartDiff.js +0 -64
- package/lib/react/utils.d.ts +0 -43
- package/lib/react/utils.js +0 -89
- package/lib/types/boxes.d.ts +0 -11
- package/lib/types/boxes.js +0 -1
- package/lib/types/citation.d.ts +0 -39
- package/lib/types/citation.js +0 -1
- package/lib/types/search.d.ts +0 -19
- package/lib/types/search.js +0 -1
- package/lib/types/verification.d.ts +0 -27
- package/lib/types/verification.js +0 -11
- package/lib/utils/diff.d.ts +0 -60
- package/lib/utils/diff.js +0 -414
- package/lib/utils/sha.d.ts +0 -10
- package/lib/utils/sha.js +0 -108
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunk4FGOHQFP_cjs=require('../chunk-4FGOHQFP.cjs');require('../chunk-F2MMVEVC.cjs');Object.defineProperty(exports,"AV_CITATION_MARKDOWN_SYNTAX_PROMPT",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.b}});Object.defineProperty(exports,"CITATION_AV_BASED_JSON_OUTPUT_FORMAT",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.h}});Object.defineProperty(exports,"CITATION_AV_REMINDER",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.d}});Object.defineProperty(exports,"CITATION_JSON_OUTPUT_FORMAT",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.g}});Object.defineProperty(exports,"CITATION_MARKDOWN_SYNTAX_PROMPT",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.a}});Object.defineProperty(exports,"CITATION_REMINDER",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.c}});Object.defineProperty(exports,"compressPromptIds",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.i}});Object.defineProperty(exports,"decompressPromptIds",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.j}});Object.defineProperty(exports,"wrapCitationPrompt",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.f}});Object.defineProperty(exports,"wrapSystemCitationPrompt",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.e}});
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
declare const CITATION_MARKDOWN_SYNTAX_PROMPT = "\n<citation-instructions priority=\"critical\">\n## REQUIRED: Citation Format\n\nYou MUST cite sources using this exact syntax:\n\n<cite attachment_id='ID' reasoning='why this supports the claim' key_span='1-3 key words' full_phrase='verbatim quote' start_page_key='page_number_N_index_I' line_ids='X-Y' />\n\n### Syntax Rules (MUST follow)\n\n1. **attachment_id**: Use the exact ID from the source document\n2. **reasoning**: Brief explanation of why this citation supports your claim (think first!)\n3. **key_span**: The 1-3 most important words from full_phrase\n4. **full_phrase**: Copy text VERBATIM from source. Escape quotes (\\') and newlines (\\n).\n5. **start_page_key**: ONLY use format `page_number_N_index_I` from page tags (e.g., `<page_number_1_index_0>`). Never extract page numbers from document content.\n6. **line_ids**: Inclusive range (e.g., '2-6' or '4'). Infer intermediate lines since only every 5th line is shown.\n\n### Placement Rules\n\n- Place <cite /> inline, typically at the end of a claim\n- One citation per distinct idea, concept, or value (a sentence citing 3 different values needs 3 citations)\n- Do NOT group citations at the end of the document\n- The <cite /> tag is self-closing - never use <cite>...</cite>\n\n### Example\n\nThe company reported strong growth<cite attachment_id='abc123' reasoning='directly states revenue growth percentage' key_span='increased 45%' full_phrase='Revenue increased 45% year-over-year to $2.3 billion' start_page_key='page_number_2_index_1' line_ids='12-14' />\n\n</citation-instructions>\n";
|
|
2
|
+
declare const AV_CITATION_MARKDOWN_SYNTAX_PROMPT = "\n<citation-instructions priority=\"critical\">\n## REQUIRED: Audio/Video Citation Format\n\nYou MUST cite sources using this exact syntax:\n\n<cite attachment_id='ID' reasoning='why this supports the claim' key_span='1-3 key words' full_phrase='verbatim transcript quote' timestamps='HH:MM:SS.SSS-HH:MM:SS.SSS' />\n\n### Syntax Rules (MUST follow)\n\n1. **attachment_id**: Use the exact ID from the source\n2. **reasoning**: Brief explanation of why this citation supports your claim (think first!)\n3. **key_span**: The 1-3 most important words from full_phrase\n4. **full_phrase**: Copy transcript text VERBATIM. Escape quotes (\\') and newlines (\\n).\n5. **timestamps**: Start and end time with milliseconds (e.g., '00:01:23.456-00:01:45.789')\n\n### Placement Rules\n\n- Place <cite /> inline, typically at the end of a claim\n- One citation per distinct idea, concept, or value (a sentence citing 3 different values needs 3 citations)\n- Do NOT group citations at the end of the document\n- The <cite /> tag is self-closing - never use <cite>...</cite>\n\n</citation-instructions>\n";
|
|
3
|
+
/**
|
|
4
|
+
* A brief reminder to reinforce citation requirements in user messages.
|
|
5
|
+
* Use this when you want to add emphasis without repeating full instructions.
|
|
6
|
+
*/
|
|
7
|
+
declare const CITATION_REMINDER = "<citation-reminder>Remember: You MUST use <cite /> tags with all required attributes for every claim from source documents.</citation-reminder>";
|
|
8
|
+
/**
|
|
9
|
+
* Audio/video version of the citation reminder.
|
|
10
|
+
*/
|
|
11
|
+
declare const CITATION_AV_REMINDER = "<citation-reminder>Remember: You MUST use <cite /> tags with timestamps for every claim from source media.</citation-reminder>";
|
|
12
|
+
interface WrapSystemPromptOptions {
|
|
13
|
+
/** The original system prompt to wrap with citation instructions */
|
|
14
|
+
systemPrompt: string;
|
|
15
|
+
/** Whether to use audio/video citation format (with timestamps) instead of text-based (with line IDs) */
|
|
16
|
+
isAudioVideo?: boolean;
|
|
17
|
+
}
|
|
18
|
+
interface WrapCitationPromptOptions {
|
|
19
|
+
/** The original system prompt to wrap with citation instructions */
|
|
20
|
+
systemPrompt: string;
|
|
21
|
+
/** The original user prompt */
|
|
22
|
+
userPrompt: string;
|
|
23
|
+
/** The extracted file text with metadata (from uploadFile response). Can be a single string or array for multiple files. */
|
|
24
|
+
deepTextPromptPortion?: string | string[];
|
|
25
|
+
/** Whether to use audio/video citation format (with timestamps) instead of text-based (with line IDs) */
|
|
26
|
+
isAudioVideo?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Whether to add a citation reminder to the user prompt.
|
|
29
|
+
* Useful for reinforcing citation requirements.
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
addUserReminder?: boolean;
|
|
33
|
+
}
|
|
34
|
+
interface WrapCitationPromptResult {
|
|
35
|
+
/** Enhanced system prompt with citation instructions */
|
|
36
|
+
enhancedSystemPrompt: string;
|
|
37
|
+
/** Enhanced user prompt (currently passed through unchanged) */
|
|
38
|
+
enhancedUserPrompt: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Wraps your existing system prompt with DeepCitation's citation syntax instructions.
|
|
42
|
+
* This enables LLMs to output verifiable citations that can be checked against source documents.
|
|
43
|
+
*
|
|
44
|
+
* ## Why We Wrap (Instructions at Start + Reminder at End)
|
|
45
|
+
*
|
|
46
|
+
* This function places full citation instructions at the **start** of your system prompt
|
|
47
|
+
* and a brief reminder at the **end**. This "wrap" strategy is intentional and based on
|
|
48
|
+
* two key principles:
|
|
49
|
+
*
|
|
50
|
+
* ### 1. Recency Effect (RE2)
|
|
51
|
+
* LLMs exhibit a "recency bias" where instructions closer to the end of the context
|
|
52
|
+
* window have stronger influence on output. The reminder at the end reinforces citation
|
|
53
|
+
* requirements right before generation begins.
|
|
54
|
+
*
|
|
55
|
+
* ### 2. Chain-of-Thought (CoT) Attribute Ordering
|
|
56
|
+
* The citation attributes are ordered to encourage the model to "think first":
|
|
57
|
+
* `attachment_id` → `reasoning` → `key_span` → `full_phrase` → `start_page_key` → `line_ids`
|
|
58
|
+
*
|
|
59
|
+
* By placing `reasoning` early, the model must articulate WHY it's citing before
|
|
60
|
+
* specifying WHAT it's citing, leading to more accurate and relevant citations.
|
|
61
|
+
*
|
|
62
|
+
* ### Why Not Just Append?
|
|
63
|
+
* In large system prompts, appended instructions can get "lost" in the middle of the
|
|
64
|
+
* effective context. Prepending ensures citation instructions have high priority,
|
|
65
|
+
* while the reminder leverages recency for reinforcement.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* import { wrapSystemCitationPrompt } from '@deepcitation/deepcitation-js';
|
|
70
|
+
*
|
|
71
|
+
* const systemPrompt = "You are a helpful assistant that analyzes documents.";
|
|
72
|
+
* const enhanced = wrapSystemCitationPrompt({ systemPrompt });
|
|
73
|
+
*
|
|
74
|
+
* // Use enhanced prompt with your LLM
|
|
75
|
+
* const response = await openai.chat.completions.create({
|
|
76
|
+
* messages: [{ role: "system", content: enhanced }],
|
|
77
|
+
* // ...
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
declare function wrapSystemCitationPrompt(options: WrapSystemPromptOptions): string;
|
|
82
|
+
/**
|
|
83
|
+
* Wraps both system and user prompts with DeepCitation's citation syntax instructions.
|
|
84
|
+
* This is the recommended way to prepare prompts for citation verification.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* import { wrapCitationPrompt } from '@deepcitation/deepcitation-js';
|
|
89
|
+
*
|
|
90
|
+
* // Single file
|
|
91
|
+
* const { enhancedSystemPrompt, enhancedUserPrompt } = wrapCitationPrompt({
|
|
92
|
+
* systemPrompt: "You are a helpful assistant.",
|
|
93
|
+
* userPrompt: "Analyze this document and summarize it.",
|
|
94
|
+
* deepTextPromptPortion, // from uploadFile response
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* // Multiple files
|
|
98
|
+
* const { enhancedSystemPrompt, enhancedUserPrompt } = wrapCitationPrompt({
|
|
99
|
+
* systemPrompt: "You are a helpful assistant.",
|
|
100
|
+
* userPrompt: "Compare these documents.",
|
|
101
|
+
* deepTextPromptPortion: [deepTextPromptPortion1, deepTextPromptPortion2], // array of file texts
|
|
102
|
+
* });
|
|
103
|
+
*
|
|
104
|
+
* // Use enhanced prompts with your LLM
|
|
105
|
+
* const response = await llm.chat({
|
|
106
|
+
* messages: [
|
|
107
|
+
* { role: "system", content: enhancedSystemPrompt },
|
|
108
|
+
* { role: "user", content: enhancedUserPrompt },
|
|
109
|
+
* ],
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
declare function wrapCitationPrompt(options: WrapCitationPromptOptions): WrapCitationPromptResult;
|
|
114
|
+
declare const CITATION_JSON_OUTPUT_FORMAT: {
|
|
115
|
+
type: string;
|
|
116
|
+
properties: {
|
|
117
|
+
attachmentId: {
|
|
118
|
+
type: string;
|
|
119
|
+
};
|
|
120
|
+
reasoning: {
|
|
121
|
+
type: string;
|
|
122
|
+
description: string;
|
|
123
|
+
};
|
|
124
|
+
keySpan: {
|
|
125
|
+
type: string;
|
|
126
|
+
description: string;
|
|
127
|
+
};
|
|
128
|
+
fullPhrase: {
|
|
129
|
+
type: string;
|
|
130
|
+
description: string;
|
|
131
|
+
};
|
|
132
|
+
startPageKey: {
|
|
133
|
+
type: string;
|
|
134
|
+
description: string;
|
|
135
|
+
};
|
|
136
|
+
lineIds: {
|
|
137
|
+
type: string;
|
|
138
|
+
items: {
|
|
139
|
+
type: string;
|
|
140
|
+
};
|
|
141
|
+
description: string;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
required: string[];
|
|
145
|
+
};
|
|
146
|
+
declare const CITATION_AV_BASED_JSON_OUTPUT_FORMAT: {
|
|
147
|
+
type: string;
|
|
148
|
+
properties: {
|
|
149
|
+
attachmentId: {
|
|
150
|
+
type: string;
|
|
151
|
+
};
|
|
152
|
+
startPageKey: {
|
|
153
|
+
type: string;
|
|
154
|
+
description: string;
|
|
155
|
+
};
|
|
156
|
+
fullPhrase: {
|
|
157
|
+
type: string;
|
|
158
|
+
description: string;
|
|
159
|
+
};
|
|
160
|
+
timestamps: {
|
|
161
|
+
type: string;
|
|
162
|
+
properties: {
|
|
163
|
+
startTime: {
|
|
164
|
+
type: string;
|
|
165
|
+
};
|
|
166
|
+
endTime: {
|
|
167
|
+
type: string;
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
required: string[];
|
|
171
|
+
description: string;
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
required: string[];
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
interface CompressedResult<T> {
|
|
178
|
+
compressed: T;
|
|
179
|
+
prefixMap: Record<string, string>;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Compress all occurrences of `ids` inside `obj`, returning a new object
|
|
184
|
+
* plus the `prefixMap` needed to decompress.
|
|
185
|
+
*/
|
|
186
|
+
declare function compressPromptIds<T>(obj: T, ids: string[] | undefined): CompressedResult<T>;
|
|
187
|
+
/**
|
|
188
|
+
* Decompress all minimal prefixes back into their full IDs,
|
|
189
|
+
* using the `prefixMap` returned from `compressPromptIds`.
|
|
190
|
+
*
|
|
191
|
+
* If you pass in a string, it will return a string.
|
|
192
|
+
* If you pass in an object, it will JSON‑serialize and parse it back.
|
|
193
|
+
*/
|
|
194
|
+
declare function decompressPromptIds<T>(compressed: T | string, prefixMap: Record<string, string>): T | string;
|
|
195
|
+
|
|
196
|
+
export { AV_CITATION_MARKDOWN_SYNTAX_PROMPT, CITATION_AV_BASED_JSON_OUTPUT_FORMAT, CITATION_AV_REMINDER, CITATION_JSON_OUTPUT_FORMAT, CITATION_MARKDOWN_SYNTAX_PROMPT, CITATION_REMINDER, type CompressedResult, type WrapCitationPromptOptions, type WrapCitationPromptResult, type WrapSystemPromptOptions, compressPromptIds, decompressPromptIds, wrapCitationPrompt, wrapSystemCitationPrompt };
|
package/lib/prompts/index.d.ts
CHANGED
|
@@ -1,3 +1,196 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
declare const CITATION_MARKDOWN_SYNTAX_PROMPT = "\n<citation-instructions priority=\"critical\">\n## REQUIRED: Citation Format\n\nYou MUST cite sources using this exact syntax:\n\n<cite attachment_id='ID' reasoning='why this supports the claim' key_span='1-3 key words' full_phrase='verbatim quote' start_page_key='page_number_N_index_I' line_ids='X-Y' />\n\n### Syntax Rules (MUST follow)\n\n1. **attachment_id**: Use the exact ID from the source document\n2. **reasoning**: Brief explanation of why this citation supports your claim (think first!)\n3. **key_span**: The 1-3 most important words from full_phrase\n4. **full_phrase**: Copy text VERBATIM from source. Escape quotes (\\') and newlines (\\n).\n5. **start_page_key**: ONLY use format `page_number_N_index_I` from page tags (e.g., `<page_number_1_index_0>`). Never extract page numbers from document content.\n6. **line_ids**: Inclusive range (e.g., '2-6' or '4'). Infer intermediate lines since only every 5th line is shown.\n\n### Placement Rules\n\n- Place <cite /> inline, typically at the end of a claim\n- One citation per distinct idea, concept, or value (a sentence citing 3 different values needs 3 citations)\n- Do NOT group citations at the end of the document\n- The <cite /> tag is self-closing - never use <cite>...</cite>\n\n### Example\n\nThe company reported strong growth<cite attachment_id='abc123' reasoning='directly states revenue growth percentage' key_span='increased 45%' full_phrase='Revenue increased 45% year-over-year to $2.3 billion' start_page_key='page_number_2_index_1' line_ids='12-14' />\n\n</citation-instructions>\n";
|
|
2
|
+
declare const AV_CITATION_MARKDOWN_SYNTAX_PROMPT = "\n<citation-instructions priority=\"critical\">\n## REQUIRED: Audio/Video Citation Format\n\nYou MUST cite sources using this exact syntax:\n\n<cite attachment_id='ID' reasoning='why this supports the claim' key_span='1-3 key words' full_phrase='verbatim transcript quote' timestamps='HH:MM:SS.SSS-HH:MM:SS.SSS' />\n\n### Syntax Rules (MUST follow)\n\n1. **attachment_id**: Use the exact ID from the source\n2. **reasoning**: Brief explanation of why this citation supports your claim (think first!)\n3. **key_span**: The 1-3 most important words from full_phrase\n4. **full_phrase**: Copy transcript text VERBATIM. Escape quotes (\\') and newlines (\\n).\n5. **timestamps**: Start and end time with milliseconds (e.g., '00:01:23.456-00:01:45.789')\n\n### Placement Rules\n\n- Place <cite /> inline, typically at the end of a claim\n- One citation per distinct idea, concept, or value (a sentence citing 3 different values needs 3 citations)\n- Do NOT group citations at the end of the document\n- The <cite /> tag is self-closing - never use <cite>...</cite>\n\n</citation-instructions>\n";
|
|
3
|
+
/**
|
|
4
|
+
* A brief reminder to reinforce citation requirements in user messages.
|
|
5
|
+
* Use this when you want to add emphasis without repeating full instructions.
|
|
6
|
+
*/
|
|
7
|
+
declare const CITATION_REMINDER = "<citation-reminder>Remember: You MUST use <cite /> tags with all required attributes for every claim from source documents.</citation-reminder>";
|
|
8
|
+
/**
|
|
9
|
+
* Audio/video version of the citation reminder.
|
|
10
|
+
*/
|
|
11
|
+
declare const CITATION_AV_REMINDER = "<citation-reminder>Remember: You MUST use <cite /> tags with timestamps for every claim from source media.</citation-reminder>";
|
|
12
|
+
interface WrapSystemPromptOptions {
|
|
13
|
+
/** The original system prompt to wrap with citation instructions */
|
|
14
|
+
systemPrompt: string;
|
|
15
|
+
/** Whether to use audio/video citation format (with timestamps) instead of text-based (with line IDs) */
|
|
16
|
+
isAudioVideo?: boolean;
|
|
17
|
+
}
|
|
18
|
+
interface WrapCitationPromptOptions {
|
|
19
|
+
/** The original system prompt to wrap with citation instructions */
|
|
20
|
+
systemPrompt: string;
|
|
21
|
+
/** The original user prompt */
|
|
22
|
+
userPrompt: string;
|
|
23
|
+
/** The extracted file text with metadata (from uploadFile response). Can be a single string or array for multiple files. */
|
|
24
|
+
deepTextPromptPortion?: string | string[];
|
|
25
|
+
/** Whether to use audio/video citation format (with timestamps) instead of text-based (with line IDs) */
|
|
26
|
+
isAudioVideo?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Whether to add a citation reminder to the user prompt.
|
|
29
|
+
* Useful for reinforcing citation requirements.
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
addUserReminder?: boolean;
|
|
33
|
+
}
|
|
34
|
+
interface WrapCitationPromptResult {
|
|
35
|
+
/** Enhanced system prompt with citation instructions */
|
|
36
|
+
enhancedSystemPrompt: string;
|
|
37
|
+
/** Enhanced user prompt (currently passed through unchanged) */
|
|
38
|
+
enhancedUserPrompt: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Wraps your existing system prompt with DeepCitation's citation syntax instructions.
|
|
42
|
+
* This enables LLMs to output verifiable citations that can be checked against source documents.
|
|
43
|
+
*
|
|
44
|
+
* ## Why We Wrap (Instructions at Start + Reminder at End)
|
|
45
|
+
*
|
|
46
|
+
* This function places full citation instructions at the **start** of your system prompt
|
|
47
|
+
* and a brief reminder at the **end**. This "wrap" strategy is intentional and based on
|
|
48
|
+
* two key principles:
|
|
49
|
+
*
|
|
50
|
+
* ### 1. Recency Effect (RE2)
|
|
51
|
+
* LLMs exhibit a "recency bias" where instructions closer to the end of the context
|
|
52
|
+
* window have stronger influence on output. The reminder at the end reinforces citation
|
|
53
|
+
* requirements right before generation begins.
|
|
54
|
+
*
|
|
55
|
+
* ### 2. Chain-of-Thought (CoT) Attribute Ordering
|
|
56
|
+
* The citation attributes are ordered to encourage the model to "think first":
|
|
57
|
+
* `attachment_id` → `reasoning` → `key_span` → `full_phrase` → `start_page_key` → `line_ids`
|
|
58
|
+
*
|
|
59
|
+
* By placing `reasoning` early, the model must articulate WHY it's citing before
|
|
60
|
+
* specifying WHAT it's citing, leading to more accurate and relevant citations.
|
|
61
|
+
*
|
|
62
|
+
* ### Why Not Just Append?
|
|
63
|
+
* In large system prompts, appended instructions can get "lost" in the middle of the
|
|
64
|
+
* effective context. Prepending ensures citation instructions have high priority,
|
|
65
|
+
* while the reminder leverages recency for reinforcement.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* import { wrapSystemCitationPrompt } from '@deepcitation/deepcitation-js';
|
|
70
|
+
*
|
|
71
|
+
* const systemPrompt = "You are a helpful assistant that analyzes documents.";
|
|
72
|
+
* const enhanced = wrapSystemCitationPrompt({ systemPrompt });
|
|
73
|
+
*
|
|
74
|
+
* // Use enhanced prompt with your LLM
|
|
75
|
+
* const response = await openai.chat.completions.create({
|
|
76
|
+
* messages: [{ role: "system", content: enhanced }],
|
|
77
|
+
* // ...
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
declare function wrapSystemCitationPrompt(options: WrapSystemPromptOptions): string;
|
|
82
|
+
/**
|
|
83
|
+
* Wraps both system and user prompts with DeepCitation's citation syntax instructions.
|
|
84
|
+
* This is the recommended way to prepare prompts for citation verification.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* import { wrapCitationPrompt } from '@deepcitation/deepcitation-js';
|
|
89
|
+
*
|
|
90
|
+
* // Single file
|
|
91
|
+
* const { enhancedSystemPrompt, enhancedUserPrompt } = wrapCitationPrompt({
|
|
92
|
+
* systemPrompt: "You are a helpful assistant.",
|
|
93
|
+
* userPrompt: "Analyze this document and summarize it.",
|
|
94
|
+
* deepTextPromptPortion, // from uploadFile response
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* // Multiple files
|
|
98
|
+
* const { enhancedSystemPrompt, enhancedUserPrompt } = wrapCitationPrompt({
|
|
99
|
+
* systemPrompt: "You are a helpful assistant.",
|
|
100
|
+
* userPrompt: "Compare these documents.",
|
|
101
|
+
* deepTextPromptPortion: [deepTextPromptPortion1, deepTextPromptPortion2], // array of file texts
|
|
102
|
+
* });
|
|
103
|
+
*
|
|
104
|
+
* // Use enhanced prompts with your LLM
|
|
105
|
+
* const response = await llm.chat({
|
|
106
|
+
* messages: [
|
|
107
|
+
* { role: "system", content: enhancedSystemPrompt },
|
|
108
|
+
* { role: "user", content: enhancedUserPrompt },
|
|
109
|
+
* ],
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
declare function wrapCitationPrompt(options: WrapCitationPromptOptions): WrapCitationPromptResult;
|
|
114
|
+
declare const CITATION_JSON_OUTPUT_FORMAT: {
|
|
115
|
+
type: string;
|
|
116
|
+
properties: {
|
|
117
|
+
attachmentId: {
|
|
118
|
+
type: string;
|
|
119
|
+
};
|
|
120
|
+
reasoning: {
|
|
121
|
+
type: string;
|
|
122
|
+
description: string;
|
|
123
|
+
};
|
|
124
|
+
keySpan: {
|
|
125
|
+
type: string;
|
|
126
|
+
description: string;
|
|
127
|
+
};
|
|
128
|
+
fullPhrase: {
|
|
129
|
+
type: string;
|
|
130
|
+
description: string;
|
|
131
|
+
};
|
|
132
|
+
startPageKey: {
|
|
133
|
+
type: string;
|
|
134
|
+
description: string;
|
|
135
|
+
};
|
|
136
|
+
lineIds: {
|
|
137
|
+
type: string;
|
|
138
|
+
items: {
|
|
139
|
+
type: string;
|
|
140
|
+
};
|
|
141
|
+
description: string;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
required: string[];
|
|
145
|
+
};
|
|
146
|
+
declare const CITATION_AV_BASED_JSON_OUTPUT_FORMAT: {
|
|
147
|
+
type: string;
|
|
148
|
+
properties: {
|
|
149
|
+
attachmentId: {
|
|
150
|
+
type: string;
|
|
151
|
+
};
|
|
152
|
+
startPageKey: {
|
|
153
|
+
type: string;
|
|
154
|
+
description: string;
|
|
155
|
+
};
|
|
156
|
+
fullPhrase: {
|
|
157
|
+
type: string;
|
|
158
|
+
description: string;
|
|
159
|
+
};
|
|
160
|
+
timestamps: {
|
|
161
|
+
type: string;
|
|
162
|
+
properties: {
|
|
163
|
+
startTime: {
|
|
164
|
+
type: string;
|
|
165
|
+
};
|
|
166
|
+
endTime: {
|
|
167
|
+
type: string;
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
required: string[];
|
|
171
|
+
description: string;
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
required: string[];
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
interface CompressedResult<T> {
|
|
178
|
+
compressed: T;
|
|
179
|
+
prefixMap: Record<string, string>;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Compress all occurrences of `ids` inside `obj`, returning a new object
|
|
184
|
+
* plus the `prefixMap` needed to decompress.
|
|
185
|
+
*/
|
|
186
|
+
declare function compressPromptIds<T>(obj: T, ids: string[] | undefined): CompressedResult<T>;
|
|
187
|
+
/**
|
|
188
|
+
* Decompress all minimal prefixes back into their full IDs,
|
|
189
|
+
* using the `prefixMap` returned from `compressPromptIds`.
|
|
190
|
+
*
|
|
191
|
+
* If you pass in a string, it will return a string.
|
|
192
|
+
* If you pass in an object, it will JSON‑serialize and parse it back.
|
|
193
|
+
*/
|
|
194
|
+
declare function decompressPromptIds<T>(compressed: T | string, prefixMap: Record<string, string>): T | string;
|
|
195
|
+
|
|
196
|
+
export { AV_CITATION_MARKDOWN_SYNTAX_PROMPT, CITATION_AV_BASED_JSON_OUTPUT_FORMAT, CITATION_AV_REMINDER, CITATION_JSON_OUTPUT_FORMAT, CITATION_MARKDOWN_SYNTAX_PROMPT, CITATION_REMINDER, type CompressedResult, type WrapCitationPromptOptions, type WrapCitationPromptResult, type WrapSystemPromptOptions, compressPromptIds, decompressPromptIds, wrapCitationPrompt, wrapSystemCitationPrompt };
|
package/lib/prompts/index.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./citationPrompts.js";
|
|
3
|
-
export * from "./types.js";
|
|
1
|
+
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-2IZXUOQR.js';import'../chunk-O2XFH626.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
'use strict';var Ce=require('react'),jsxRuntime=require('react/jsx-runtime'),reactDom=require('react-dom'),R=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 Ce__namespace=/*#__PURE__*/_interopNamespace(Ce);var R__namespace=/*#__PURE__*/_interopNamespace(R);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 jsxRuntime.jsx("span",{className:j("inline-flex items-center gap-1",n.className),title:t||n.label,"aria-label":n.label,children:jsxRuntime.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 jsxRuntime.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=Ce.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=Ce.useMemo(()=>t||{value:g,fullPhrase:P||g},[t,g,P]),c=Ce.useMemo(()=>Z(y),[y]),I=Ce.useMemo(()=>G(c),[c]),N=Ce.useMemo(()=>S||ae(g),[S,g]),M=Ce.useMemo(()=>Ze(g),[g]),B=Ce.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=Ce.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=Ce.useCallback(()=>{m?.onMouseEnter?.(y,c);},[m,y,c]),F=Ce.useCallback(()=>{m?.onMouseLeave?.(y,c);},[m,y,c]),$=()=>A||L?o?o(f,_):jsxRuntime.jsx(Xe,{status:f,errorMessage:_}):V?jsxRuntime.jsx("span",{className:"text-[0.85em] text-green-600 dark:text-green-500","aria-hidden":"true",title:"Verified",children:"\u2713"}):J?jsxRuntime.jsx("span",{className:"text-[0.85em] text-amber-600 dark:text-amber-500","aria-hidden":"true",title:"Partial match",children:"~"}):q?jsxRuntime.jsx("span",{className:"opacity-70","aria-hidden":"true",children:"\u2026"}):null;return a==="chip"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[n,jsxRuntime.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&&jsxRuntime.jsx(te,{url:g,faviconUrl:b}),jsxRuntime.jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:B}),$()]})]}):a==="inline"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[n,jsxRuntime.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&&jsxRuntime.jsx(te,{url:g,faviconUrl:b}),jsxRuntime.jsx("span",{children:B}),$()]})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[n,jsxRuntime.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&&jsxRuntime.jsx(te,{url:g,faviconUrl:b}),jsxRuntime.jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:B}),$(),"]"]})]})});ve.displayName="UrlCitationComponent";Ce.memo(ve);var Je=({className:e})=>jsxRuntime.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:[jsxRuntime.jsx("path",{d:"M7 3 L3 3 L3 21 L7 21"}),jsxRuntime.jsx("path",{d:"M17 3 L21 3 L21 21 L17 21"})]}),Y=({className:e})=>jsxRuntime.jsx("svg",{className:w("w-[0.7em] h-[0.7em]",e),viewBox:"0 0 256 256",fill:"currentColor","aria-hidden":"true",children:jsxRuntime.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})=>jsxRuntime.jsx("svg",{className:w("w-[0.7em] h-[0.7em]",e),viewBox:"0 0 256 256",fill:"currentColor","aria-hidden":"true",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"})}),ie=({className:e})=>jsxRuntime.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:[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"})]});function Ye(...e){return e.filter(Boolean).join(" ")}var ke=R__namespace.Root,Pe=R__namespace.Trigger;var se=Ce__namespace.forwardRef(({className:e,align:t="center",sideOffset:n=4,...r},a)=>jsxRuntime.jsx(R__namespace.Portal,{children:jsxRuntime.jsx(R__namespace.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__namespace.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="")=>Ce.useMemo(()=>{let n=(e||"").trim().replace(/\r\n/g,`
|
|
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 Ce.useEffect(()=>{let r=a=>{a.key==="Escape"&&n();};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[n]),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",onClick:n,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",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 mt=()=>jsxRuntime.jsx("span",{className:"inline-flex relative ml-0.5 text-green-600 dark:text-green-500","aria-hidden":"true",children:jsxRuntime.jsx(Y,{})}),gt=()=>jsxRuntime.jsx("span",{className:"inline-flex relative ml-0.5 text-amber-600 dark:text-amber-500","aria-hidden":"true",children:jsxRuntime.jsx(Y,{})}),ft=()=>jsxRuntime.jsx("span",{className:"inline-flex ml-1 text-gray-400 dark:text-gray-500","aria-hidden":"true",children:jsxRuntime.jsx(ie,{})}),ht=()=>jsxRuntime.jsx("span",{className:"inline-flex relative ml-0.5 text-red-500 dark:text-red-400","aria-hidden":"true",children:jsxRuntime.jsx(re,{})});function xt({citation:e,verification:t,status:n,onImageClick:r}){let a=t?.verificationImageBase64,{isMiss:i,isPartialMatch:s}=n;if(a)return jsxRuntime.jsxs("div",{className:"p-1",children:[jsxRuntime.jsx("button",{type:"button",className:"block cursor-zoom-in",onClick:p=>{p.preventDefault(),p.stopPropagation(),r?.();},"aria-label":"Click to view full size",children:jsxRuntime.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)&&jsxRuntime.jsx(Re,{citation:e,verification:t,status:n})]});let u=dt(n),l=t?.verifiedMatchSnippet,o=t?.verifiedPageNumber;return !l&&!u?null:jsxRuntime.jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[200px] max-w-[400px]",children:[u&&jsxRuntime.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&&jsxRuntime.jsxs("span",{className:"text-sm text-gray-700 dark:text-gray-300 italic",children:['"',t.verifiedMatchSnippet,'"']}),o&&o>0&&jsxRuntime.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Page ",o]}),(i||s)&&jsxRuntime.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?jsxRuntime.jsxs("div",{className:"mt-2 pt-2 border-t border-gray-200 dark:border-gray-700 text-xs space-y-2",children:[i&&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:i.length>100?i.slice(0,100)+"\u2026":i})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Found"}),jsxRuntime.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"})]})]}):jsxRuntime.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?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:o?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:i.length>100?i.slice(0,100)+"\u2026":i})]}),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:s.length>100?s.slice(0,100)+"\u2026":s})]})]}):u.map((P,f)=>jsxRuntime.jsx("span",{children:P.parts.map((b,_)=>{let y=`p-${f}-${_}`;return b.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:b.value},y):b.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:b.value},y):jsxRuntime.jsx("span",{children:b.value},y)})},`block-${f}`))})]}):i&&!l?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:i.length>100?i.slice(0,100)+"\u2026":i})]}):null,S&&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:v})," \u2192 ",g]})]}),x&&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:p?.join(", ")})," \u2192 ",m?.join(", ")]})]})]})}var le=Ce.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=Ce.useMemo(()=>u||ot(s),[u,s]),[f,b]=Ce.useState(false),[_,y]=Ce.useState(null),c=Ce.useMemo(()=>Z(e),[e]),I=Ce.useMemo(()=>G(c),[c]),N=Ce.useMemo(()=>ut(a),[a]),{isMiss:M,isPartialMatch:B,isVerified:E,isPending:A}=N,L=Ce.useMemo(()=>ct(e,P,r),[e,P,r]),V=Ce.useCallback(()=>({citation:e,citationKey:c,verification:a??null,isTooltipExpanded:f,isImageExpanded:!!_,hasImage:!!a?.verificationImageBase64}),[e,c,a,f,_]),J=Ce.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=Ce.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=Ce.useCallback(()=>{b(true),o?.onHover?.onEnter&&o.onHover.onEnter(V()),l?.onMouseEnter?.(e,c);},[l,o,e,c,V]),O=Ce.useCallback(()=>{b(false),o?.onHover?.onLeave&&o.onHover.onLeave(V()),l?.onMouseLeave?.(e,c);},[l,o,e,c,V]),F=Ce.useCallback(k=>{p&&(k.preventDefault(),k.stopPropagation(),l?.onTouchEnd?.(e,c,k));},[l,e,c,p]);if(r!=null&&P==="keySpan"&&M)return jsxRuntime.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?jsxRuntime.jsx(ft,{}):M?jsxRuntime.jsx(ht,{}):B?jsxRuntime.jsx(gt,{}):E?jsxRuntime.jsx(mt,{}):null,ce=()=>{if(x)return x({citation:e,status:N,citationKey:c,displayText:L,isMergedDisplay:P==="keySpan"});if(P==="indicator")return jsxRuntime.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 jsxRuntime.jsxs("span",{className:w("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-sm font-medium",k),children:[jsxRuntime.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 jsxRuntime.jsxs("sup",{className:w("text-xs font-medium transition-colors hover:underline",k),children:["[",L,C(),"]"]})}return s==="text"?jsxRuntime.jsxs("span",{className:$,children:[L,C()]}):s==="minimal"?jsxRuntime.jsxs("span",{className:w("max-w-80 overflow-hidden text-ellipsis",$),children:[L,C()]}):jsxRuntime.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:["[",jsxRuntime.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=_?jsxRuntime.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}):jsxRuntime.jsx(xt,{citation:e,verification:a??null,status:N,onImageClick:()=>{a?.verificationImageBase64&&y(a.verificationImageBase64);}});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[t,jsxRuntime.jsxs(ke,{open:f,children:[jsxRuntime.jsx(Pe,{asChild:true,children:jsxRuntime.jsx("span",{ref:S,...ue,children:ce()})}),jsxRuntime.jsx(se,{side:v==="bottom"?"bottom":"top",onPointerDownOutside:H=>H.preventDefault(),onInteractOutside:H=>H.preventDefault(),children:k})]}),de]})}return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[t,jsxRuntime.jsx("span",{ref:S,...ue,children:ce()}),de]})});le.displayName="CitationComponent";var vt=Ce.memo(le);exports.CITATION_X_PADDING=Ke;exports.CITATION_Y_PADDING=Oe;exports.CheckIcon=Y;exports.CitationComponent=le;exports.DeepCitationIcon=Je;exports.MemoizedCitationComponent=vt;exports.SpinnerIcon=ie;exports.WarningIcon=re;exports.classNames=j;exports.extractDomain=ae;exports.generateCitationInstanceId=G;exports.generateCitationKey=Z;exports.getCitationDisplayText=ze;exports.getCitationKeySpanText=Te;exports.getCitationNumber=We;exports.isBlockedStatus=he;exports.isErrorStatus=xe;exports.isVerifiedStatus=Ge;
|
package/lib/react/index.js
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Note: UI components have been moved to a shadcn-style copy-paste pattern.
|
|
5
|
-
* See the documentation at https://deepcitation.com/docs/components for
|
|
6
|
-
* ready-to-use React components.
|
|
7
|
-
*
|
|
8
|
-
* This module exports utilities and types that are useful for building
|
|
9
|
-
* your own citation components.
|
|
10
|
-
*
|
|
11
|
-
* @packageDocumentation
|
|
12
|
-
*/
|
|
13
|
-
// URL Utilities - For handling URL citation metadata
|
|
14
|
-
export { extractDomain, isBlockedStatus, isErrorStatus, isVerifiedStatus, } from "./UrlCitationComponent.js";
|
|
15
|
-
// Utilities - For generating citation keys and display text
|
|
16
|
-
export { generateCitationKey, generateCitationInstanceId, getCitationDisplayText, getCitationKeySpanText, classNames, CITATION_X_PADDING, CITATION_Y_PADDING, } from "./utils.js";
|
|
17
|
-
// Components
|
|
18
|
-
export { CitationComponent, MemoizedCitationComponent, } from "./CitationComponent.js";
|
|
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,`
|
|
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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunkCFXDRAJL_cjs=require('../chunk-CFXDRAJL.cjs');require('../chunk-F2MMVEVC.cjs');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}});
|