@deepcitation/deepcitation-js 1.1.30 → 1.1.32
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/README.md +254 -253
- package/lib/chunk-G6RPOT3H.js +2 -0
- package/lib/chunk-URRIEXFH.cjs +2 -0
- package/lib/client/index.cjs +1 -1
- package/lib/client/index.d.cts +9 -10
- package/lib/client/index.d.ts +9 -10
- package/lib/client/index.js +1 -1
- package/lib/index.cjs +1 -1
- package/lib/index.js +1 -1
- package/lib/react/index.cjs +3 -3
- package/lib/react/index.js +3 -3
- package/package.json +1 -1
- package/lib/chunk-67NZP2UZ.js +0 -2
- package/lib/chunk-CQF2MESM.cjs +0 -2
package/README.md
CHANGED
|
@@ -1,253 +1,254 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
|
|
3
|
-
# @deepcitation/deepcitation-js
|
|
4
|
-
|
|
5
|
-
**Deterministic AI citation verification. Eliminate hallucination risk by proving every AI citation against source documents.**
|
|
6
|
-
|
|
7
|
-
[](https://www.npmjs.com/package/@deepcitation/deepcitation-js)
|
|
8
|
-
[](https://opensource.org/licenses/MIT)
|
|
9
|
-
[](https://www.typescriptlang.org/)
|
|
10
|
-
|
|
11
|
-
[Documentation](https://deepcitation.com/docs) · [Get Free API Key](https://deepcitation.com/signup) · [Examples](./examples) · [Discord](https://discord.gg/deepcitation)
|
|
12
|
-
|
|
13
|
-
</div>
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
## Why DeepCitation?
|
|
18
|
-
|
|
19
|
-
LLMs hallucinate. Even when given source documents, they make up quotes, invent statistics, and cite pages that don't exist. DeepCitation solves this by **deterministically verifying every citation** against your source documents—and generating visual proof.
|
|
20
|
-
|
|
21
|
-
<div align="center">
|
|
22
|
-
<img src="./examples/assets/deepcitation-medical-demo.gif" alt="DeepCitation medical documentation demo showing verified inline citations" width="700" />
|
|
23
|
-
<br />
|
|
24
|
-
<em>Medical documentation with verified inline citations — certainty at a glance</em>
|
|
25
|
-
</div>
|
|
26
|
-
|
|
27
|
-
```
|
|
28
|
-
Before: "Revenue grew 45% [1]" → ❓ Did the LLM make this up?
|
|
29
|
-
After: "Revenue grew 45% [1]" → ✅ Verified on page 3, line 12 (with screenshot)
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Features
|
|
33
|
-
|
|
34
|
-
- **Deterministic Matching** – Every citation traced to its exact location. No fuzzy matching, no guessing.
|
|
35
|
-
- **Visual Proof** – Automated screenshots with highlighted text show exactly where citations come from.
|
|
36
|
-
- **Any LLM Provider** – Works with OpenAI, Anthropic, Google, Azure, or your own models.
|
|
37
|
-
- **React Components** – Pre-built components + composable primitives for citation UIs.
|
|
38
|
-
- **TypeScript Native** – Full type safety with comprehensive type definitions.
|
|
39
|
-
|
|
40
|
-
## Installation
|
|
41
|
-
|
|
42
|
-
```bash
|
|
43
|
-
npm install @deepcitation/deepcitation-js
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
Get a free API key at [deepcitation.com](https://deepcitation.com/signup) — no credit card required.
|
|
47
|
-
|
|
48
|
-
```bash
|
|
49
|
-
# .env
|
|
50
|
-
DEEPCITATION_API_KEY=sk-dc-your_api_key_here
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
---
|
|
54
|
-
|
|
55
|
-
## Quick Start
|
|
56
|
-
|
|
57
|
-
DeepCitation works in three steps: **Pre-Prompt**, **Post-Prompt**, and **Display**.
|
|
58
|
-
|
|
59
|
-
### Step 1: Pre-Prompt
|
|
60
|
-
|
|
61
|
-
Upload source documents and enhance your prompt with citation instructions.
|
|
62
|
-
|
|
63
|
-
```typescript
|
|
64
|
-
import { DeepCitation, wrapCitationPrompt } from "@deepcitation/deepcitation-js";
|
|
65
|
-
|
|
66
|
-
const dc = new DeepCitation({ apiKey: process.env.DEEPCITATION_API_KEY });
|
|
67
|
-
|
|
68
|
-
// Upload source files, this can be done before the user types their prompt
|
|
69
|
-
const { fileDataParts, deepTextPromptPortion } = await dc.prepareFiles([
|
|
70
|
-
{ file: pdfBuffer, filename: "report.pdf" },
|
|
71
|
-
]);
|
|
72
|
-
|
|
73
|
-
// Wrap prompts with citation instructions
|
|
74
|
-
const { enhancedSystemPrompt, enhancedUserPrompt } = wrapCitationPrompt({
|
|
75
|
-
systemPrompt: "You are a helpful assistant...",
|
|
76
|
-
userPrompt: "Analyze this document",
|
|
77
|
-
deepTextPromptPortion,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
// Call your LLM
|
|
81
|
-
const response = await llm.chat({
|
|
82
|
-
messages: [
|
|
83
|
-
{ role: "system", content: enhancedSystemPrompt },
|
|
84
|
-
{ role: "user", content: enhancedUserPrompt },
|
|
85
|
-
],
|
|
86
|
-
});
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### Step 2: Post-Prompt
|
|
90
|
-
|
|
91
|
-
Verify citations against the source documents.
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
const result = await dc.
|
|
95
|
-
llmOutput: response.content,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
- [**
|
|
203
|
-
- [**
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
-
|
|
219
|
-
-
|
|
220
|
-
-
|
|
221
|
-
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
**
|
|
231
|
-
**
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
- [
|
|
251
|
-
- [
|
|
252
|
-
- [
|
|
253
|
-
- [
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# @deepcitation/deepcitation-js
|
|
4
|
+
|
|
5
|
+
**Deterministic AI citation verification. Eliminate hallucination risk by proving every AI citation against source documents.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@deepcitation/deepcitation-js)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
[](https://www.typescriptlang.org/)
|
|
10
|
+
|
|
11
|
+
[Documentation](https://deepcitation.com/docs) · [Get Free API Key](https://deepcitation.com/signup) · [Examples](./examples) · [Discord](https://discord.gg/deepcitation)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Why DeepCitation?
|
|
18
|
+
|
|
19
|
+
LLMs hallucinate. Even when given source documents, they make up quotes, invent statistics, and cite pages that don't exist. DeepCitation solves this by **deterministically verifying every citation** against your source documents—and generating visual proof.
|
|
20
|
+
|
|
21
|
+
<div align="center">
|
|
22
|
+
<img src="./examples/assets/deepcitation-medical-demo.gif" alt="DeepCitation medical documentation demo showing verified inline citations" width="700" />
|
|
23
|
+
<br />
|
|
24
|
+
<em>Medical documentation with verified inline citations — certainty at a glance</em>
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
Before: "Revenue grew 45% [1]" → ❓ Did the LLM make this up?
|
|
29
|
+
After: "Revenue grew 45% [1]" → ✅ Verified on page 3, line 12 (with screenshot)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Features
|
|
33
|
+
|
|
34
|
+
- **Deterministic Matching** – Every citation traced to its exact location. No fuzzy matching, no guessing.
|
|
35
|
+
- **Visual Proof** – Automated screenshots with highlighted text show exactly where citations come from.
|
|
36
|
+
- **Any LLM Provider** – Works with OpenAI, Anthropic, Google, Azure, or your own models.
|
|
37
|
+
- **React Components** – Pre-built components + composable primitives for citation UIs.
|
|
38
|
+
- **TypeScript Native** – Full type safety with comprehensive type definitions.
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install @deepcitation/deepcitation-js
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Get a free API key at [deepcitation.com](https://deepcitation.com/signup) — no credit card required.
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# .env
|
|
50
|
+
DEEPCITATION_API_KEY=sk-dc-your_api_key_here
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Quick Start
|
|
56
|
+
|
|
57
|
+
DeepCitation works in three steps: **Pre-Prompt**, **Post-Prompt**, and **Display**.
|
|
58
|
+
|
|
59
|
+
### Step 1: Pre-Prompt
|
|
60
|
+
|
|
61
|
+
Upload source documents and enhance your prompt with citation instructions.
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { DeepCitation, wrapCitationPrompt } from "@deepcitation/deepcitation-js";
|
|
65
|
+
|
|
66
|
+
const dc = new DeepCitation({ apiKey: process.env.DEEPCITATION_API_KEY });
|
|
67
|
+
|
|
68
|
+
// Upload source files, this can be done before the user types their prompt
|
|
69
|
+
const { fileDataParts, deepTextPromptPortion } = await dc.prepareFiles([
|
|
70
|
+
{ file: pdfBuffer, filename: "report.pdf" },
|
|
71
|
+
]);
|
|
72
|
+
|
|
73
|
+
// Wrap prompts with citation instructions
|
|
74
|
+
const { enhancedSystemPrompt, enhancedUserPrompt } = wrapCitationPrompt({
|
|
75
|
+
systemPrompt: "You are a helpful assistant...",
|
|
76
|
+
userPrompt: "Analyze this document",
|
|
77
|
+
deepTextPromptPortion,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Call your LLM
|
|
81
|
+
const response = await llm.chat({
|
|
82
|
+
messages: [
|
|
83
|
+
{ role: "system", content: enhancedSystemPrompt },
|
|
84
|
+
{ role: "user", content: enhancedUserPrompt },
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Step 2: Post-Prompt
|
|
90
|
+
|
|
91
|
+
Verify citations against the source documents.
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const result = await dc.verifyAll({
|
|
95
|
+
llmOutput: response.content,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// result.verifications contains verification status + visual proof
|
|
99
|
+
const { verifications } = result;
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Step 3: Display
|
|
103
|
+
|
|
104
|
+
Parse the LLM output and render verified citations inline with React components.
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
import { CitationComponent } from "@deepcitation/deepcitation-js/react";
|
|
108
|
+
import {
|
|
109
|
+
parseCitation,
|
|
110
|
+
generateCitationKey,
|
|
111
|
+
} from "@deepcitation/deepcitation-js";
|
|
112
|
+
import "@deepcitation/deepcitation-js/react/styles.css";
|
|
113
|
+
|
|
114
|
+
function Response({ llmOutput, verifications }) {
|
|
115
|
+
// Split LLM output by citation tags and render inline
|
|
116
|
+
const renderWithCitations = (text: string) => {
|
|
117
|
+
const parts = text.split(/(<cite\s+[^>]*\/>)/g);
|
|
118
|
+
|
|
119
|
+
return parts.map((part, index) => {
|
|
120
|
+
if (part.startsWith("<cite")) {
|
|
121
|
+
const { citation } = parseCitation(part);
|
|
122
|
+
const citationKey = generateCitationKey(citation);
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<CitationComponent
|
|
126
|
+
key={index}
|
|
127
|
+
citation={citation}
|
|
128
|
+
verification={verifications[citationKey]}
|
|
129
|
+
/>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
return <span key={index}>{part}</span>;
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
return <div>{renderWithCitations(llmOutput)}</div>;
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Core API
|
|
143
|
+
|
|
144
|
+
### DeepCitation Client
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
const dc = new DeepCitation({
|
|
148
|
+
apiKey: string // Your API key (sk-dc-*)
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// Upload and prepare source files
|
|
152
|
+
await dc.prepareFiles(files: FileInput[])
|
|
153
|
+
|
|
154
|
+
// Convert URLs/Office docs to PDF
|
|
155
|
+
await dc.convertToPdf(urlOrOptions: string | ConvertOptions)
|
|
156
|
+
|
|
157
|
+
// Verify LLM citations (parse and verify all)
|
|
158
|
+
await dc.verifyAll({ llmOutput, outputImageFormat? })
|
|
159
|
+
|
|
160
|
+
// Verify pre-parsed citations against a specific file
|
|
161
|
+
await dc.verify(attachmentId, citations, options?)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Prompt Utilities
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
import {
|
|
168
|
+
wrapCitationPrompt, // Wrap system + user prompts
|
|
169
|
+
wrapSystemCitationPrompt, // Wrap system prompt only
|
|
170
|
+
getAllCitationsFromLlmOutput, // Extract citations from response
|
|
171
|
+
CITATION_JSON_OUTPUT_FORMAT, // JSON schema for structured output
|
|
172
|
+
} from "@deepcitation/deepcitation-js";
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### React Components
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
import {
|
|
179
|
+
CitationComponent, // Primary citation display component
|
|
180
|
+
CitationVariants, // Alternative citation styles
|
|
181
|
+
UrlCitationComponent, // For URL-based citations
|
|
182
|
+
} from "@deepcitation/deepcitation-js/react";
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Types
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
import type {
|
|
189
|
+
Citation,
|
|
190
|
+
Verification,
|
|
191
|
+
SearchStatus,
|
|
192
|
+
SearchAttempt,
|
|
193
|
+
} from "@deepcitation/deepcitation-js";
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## Examples
|
|
199
|
+
|
|
200
|
+
Check out the [examples directory](./examples) for complete, runnable examples:
|
|
201
|
+
|
|
202
|
+
- [**basic-verification**](./examples/basic-verification) – Core 3-step workflow
|
|
203
|
+
- [**support-bot**](./examples/support-bot) – Customer support bot with invisible citations
|
|
204
|
+
- [**nextjs-ai-sdk**](./examples/nextjs-ai-sdk) – Full-stack Next.js chat app
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
cd examples/basic-verification
|
|
208
|
+
npm install
|
|
209
|
+
cp .env.example .env # Add your API keys
|
|
210
|
+
npm run start:openai
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Documentation
|
|
216
|
+
|
|
217
|
+
For comprehensive documentation including:
|
|
218
|
+
- Full API reference
|
|
219
|
+
- Integration patterns
|
|
220
|
+
- Error handling
|
|
221
|
+
- Advanced React components
|
|
222
|
+
- TypeScript types
|
|
223
|
+
|
|
224
|
+
Visit **[deepcitation.com/docs](https://deepcitation.com/docs)**
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Supported File Types
|
|
229
|
+
|
|
230
|
+
**Documents:** PDF (native and scanned), URLs, Office formats (`.docx`, `.xlsx`, `.pptx`, etc.)
|
|
231
|
+
**Images:** PNG, JPEG, TIFF, WebP, AVIF, HEIC
|
|
232
|
+
**Media:** Audio and video (with timestamp-based citations)
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## Contributing
|
|
237
|
+
|
|
238
|
+
Contributions are welcome! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## License
|
|
243
|
+
|
|
244
|
+
MIT License - see [LICENSE](./LICENSE) for details.
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## Links
|
|
249
|
+
|
|
250
|
+
- [Documentation](https://deepcitation.com/docs)
|
|
251
|
+
- [Get API Key](https://deepcitation.com/signup)
|
|
252
|
+
- [Discord Community](https://discord.gg/deepcitation)
|
|
253
|
+
- [GitHub Issues](https://github.com/deepcitation/deepcitation-js/issues)
|
|
254
|
+
- [Examples](./examples)
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {i,t}from'./chunk-ETIDLMKZ.js';import {a}from'./chunk-O2XFH626.js';var C="https://api.deepcitation.com";function F(p,t){if(typeof Buffer<"u"&&Buffer.isBuffer(p)){let e=Uint8Array.from(p);return {blob:new Blob([e]),name:t||"document"}}if(p instanceof Blob)return {blob:p,name:t||(p instanceof File?p.name:"document")};throw new Error("Invalid file type. Expected File, Blob, or Buffer.")}async function c(p,t){return (await p.json().catch(()=>({})))?.error?.message||`${t} failed with status ${p.status}`}var y=class{constructor(t){a(this,"apiKey");a(this,"apiUrl");if(!t.apiKey)throw new Error("DeepCitation API key is required. Get one at https://deepcitation.com/dashboard");this.apiKey=t.apiKey,this.apiUrl=t.apiUrl?.replace(/\/$/,"")||C;}async uploadFile(t,e){let{blob:l,name:a}=F(t,e?.filename),o=new FormData;o.append("file",l,a),e?.attachmentId&&o.append("attachmentId",e.attachmentId),e?.filename&&o.append("filename",e.filename);let i=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:o});if(!i.ok)throw new Error(await c(i,"Upload"));return await i.json()}async convertToPdf(t){let e=typeof t=="string"?{url:t}:t,{url:l,file:a,filename:o,attachmentId:i}=e;if(!l&&!a)throw new Error("Either url or file must be provided");let r;if(l)r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({url:l,filename:o,attachmentId:i})});else {let{blob:f,name:n}=F(a,o),s=new FormData;s.append("file",f,n),i&&s.append("attachmentId",i),o&&s.append("filename",o),r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:s});}if(!r.ok)throw new Error(await c(r,"Conversion"));return await r.json()}async prepareConvertedFile(t){let e=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({attachmentId:t.attachmentId})});if(!e.ok)throw new Error(await c(e,"Prepare"));return await e.json()}async prepareFiles(t){if(t.length===0)return {fileDataParts:[],deepTextPromptPortion:[]};let e=t.map(({file:i,filename:r,attachmentId:f})=>this.uploadFile(i,{filename:r,attachmentId:f}).then(n=>({result:n,filename:r}))),a=(await Promise.all(e)).map(({result:i,filename:r})=>({attachmentId:i.attachmentId,deepTextPromptPortion:i.deepTextPromptPortion,filename:r||i.metadata?.filename})),o=a.map(i=>i.deepTextPromptPortion);return {fileDataParts:a,deepTextPromptPortion:o}}async verify(t,e,l){let a={};if(Array.isArray(e))for(let n of e){let s=i(n);a[s]=n;}else if(typeof e=="object"&&e!==null)if("fullPhrase"in e||"value"in e){let n=i(e);a[n]=e;}else Object.assign(a,e);else throw new Error("Invalid citations format");if(Object.keys(a).length===0)return {verifications:{}};let o=`${this.apiUrl}/verifyCitations`,i$1={data:{attachmentId:t,citations:a,outputImageFormat:l?.outputImageFormat||"avif"}},r=await fetch(o,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(i$1)});if(!r.ok)throw new Error(await c(r,"Verification"));return await r.json()}async verifyAll(t$1,e){let{llmOutput:l,outputImageFormat:a="avif"}=t$1;if(e||(e=t(l)),Object.keys(e).length===0)return {verifications:{}};let o=new Map;for(let[n,s]of Object.entries(e)){let m=s.attachmentId||"";o.has(m)||o.set(m,{}),o.get(m)[n]=s;}let i=[];for(let[n,s]of o)n&&i.push(this.verify(n,s,{outputImageFormat:a}));let r=await Promise.all(i),f={};for(let n of r)Object.assign(f,n.verifications);return {verifications:f}}};
|
|
2
|
+
export{y as a};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var chunk4HRWJSX6_cjs=require('./chunk-4HRWJSX6.cjs'),chunkF2MMVEVC_cjs=require('./chunk-F2MMVEVC.cjs');var C="https://api.deepcitation.com";function F(p,t){if(typeof Buffer<"u"&&Buffer.isBuffer(p)){let e=Uint8Array.from(p);return {blob:new Blob([e]),name:t||"document"}}if(p instanceof Blob)return {blob:p,name:t||(p instanceof File?p.name:"document")};throw new Error("Invalid file type. Expected File, Blob, or Buffer.")}async function c(p,t){return (await p.json().catch(()=>({})))?.error?.message||`${t} failed with status ${p.status}`}var y=class{constructor(t){chunkF2MMVEVC_cjs.a(this,"apiKey");chunkF2MMVEVC_cjs.a(this,"apiUrl");if(!t.apiKey)throw new Error("DeepCitation API key is required. Get one at https://deepcitation.com/dashboard");this.apiKey=t.apiKey,this.apiUrl=t.apiUrl?.replace(/\/$/,"")||C;}async uploadFile(t,e){let{blob:l,name:a}=F(t,e?.filename),o=new FormData;o.append("file",l,a),e?.attachmentId&&o.append("attachmentId",e.attachmentId),e?.filename&&o.append("filename",e.filename);let i=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:o});if(!i.ok)throw new Error(await c(i,"Upload"));return await i.json()}async convertToPdf(t){let e=typeof t=="string"?{url:t}:t,{url:l,file:a,filename:o,attachmentId:i}=e;if(!l&&!a)throw new Error("Either url or file must be provided");let r;if(l)r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({url:l,filename:o,attachmentId:i})});else {let{blob:f,name:n}=F(a,o),s=new FormData;s.append("file",f,n),i&&s.append("attachmentId",i),o&&s.append("filename",o),r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:s});}if(!r.ok)throw new Error(await c(r,"Conversion"));return await r.json()}async prepareConvertedFile(t){let e=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({attachmentId:t.attachmentId})});if(!e.ok)throw new Error(await c(e,"Prepare"));return await e.json()}async prepareFiles(t){if(t.length===0)return {fileDataParts:[],deepTextPromptPortion:[]};let e=t.map(({file:i,filename:r,attachmentId:f})=>this.uploadFile(i,{filename:r,attachmentId:f}).then(n=>({result:n,filename:r}))),a=(await Promise.all(e)).map(({result:i,filename:r})=>({attachmentId:i.attachmentId,deepTextPromptPortion:i.deepTextPromptPortion,filename:r||i.metadata?.filename})),o=a.map(i=>i.deepTextPromptPortion);return {fileDataParts:a,deepTextPromptPortion:o}}async verify(t,e,l){let a={};if(Array.isArray(e))for(let n of e){let s=chunk4HRWJSX6_cjs.i(n);a[s]=n;}else if(typeof e=="object"&&e!==null)if("fullPhrase"in e||"value"in e){let n=chunk4HRWJSX6_cjs.i(e);a[n]=e;}else Object.assign(a,e);else throw new Error("Invalid citations format");if(Object.keys(a).length===0)return {verifications:{}};let o=`${this.apiUrl}/verifyCitations`,i={data:{attachmentId:t,citations:a,outputImageFormat:l?.outputImageFormat||"avif"}},r=await fetch(o,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(!r.ok)throw new Error(await c(r,"Verification"));return await r.json()}async verifyAll(t,e){let{llmOutput:l,outputImageFormat:a="avif"}=t;if(e||(e=chunk4HRWJSX6_cjs.t(l)),Object.keys(e).length===0)return {verifications:{}};let o=new Map;for(let[n,s]of Object.entries(e)){let m=s.attachmentId||"";o.has(m)||o.set(m,{}),o.get(m)[n]=s;}let i=[];for(let[n,s]of o)n&&i.push(this.verify(n,s,{outputImageFormat:a}));let r=await Promise.all(i),f={};for(let n of r)Object.assign(f,n.verifications);return {verifications:f}}};
|
|
2
|
+
exports.a=y;
|
package/lib/client/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkURRIEXFH_cjs=require('../chunk-URRIEXFH.cjs');require('../chunk-4HRWJSX6.cjs'),require('../chunk-F2MMVEVC.cjs');Object.defineProperty(exports,"DeepCitation",{enumerable:true,get:function(){return chunkURRIEXFH_cjs.a}});
|
package/lib/client/index.d.cts
CHANGED
|
@@ -306,35 +306,34 @@ declare class DeepCitation {
|
|
|
306
306
|
* import { getAllCitationsFromLlmOutput } from '@deepcitation/deepcitation-js';
|
|
307
307
|
*
|
|
308
308
|
* const citations = getAllCitationsFromLlmOutput(llmResponse);
|
|
309
|
-
* const verified = await dc.
|
|
309
|
+
* const verified = await dc.verify(attachmentId, citations);
|
|
310
310
|
*
|
|
311
311
|
* for (const [key, result] of Object.entries(verified.verifications)) {
|
|
312
|
-
* console.log(key, result.
|
|
312
|
+
* console.log(key, result.status);
|
|
313
313
|
* // "found", "partial_text_found", "not_found", etc.
|
|
314
314
|
* }
|
|
315
315
|
* ```
|
|
316
316
|
*/
|
|
317
|
-
|
|
317
|
+
verify(attachmentId: string, citations: CitationInput, options?: VerifyCitationsOptions): Promise<VerifyCitationsResponse>;
|
|
318
318
|
/**
|
|
319
|
-
*
|
|
319
|
+
* Parse and verify all citations from LLM output.
|
|
320
320
|
* This is the recommended way to verify citations for new integrations.
|
|
321
321
|
*
|
|
322
|
-
* @param input - Object containing llmOutput and optional
|
|
322
|
+
* @param input - Object containing llmOutput and optional outputImageFormat
|
|
323
323
|
* @returns Verification results with status and proof images
|
|
324
324
|
*
|
|
325
325
|
* @example
|
|
326
326
|
* ```typescript
|
|
327
|
-
* const result = await dc.
|
|
327
|
+
* const result = await dc.verifyAll({
|
|
328
328
|
* llmOutput: response.content,
|
|
329
|
-
* fileDataParts, // From prepareFiles()
|
|
330
329
|
* });
|
|
331
330
|
*
|
|
332
|
-
* for (const [key,
|
|
333
|
-
* console.log(key,
|
|
331
|
+
* for (const [key, verification] of Object.entries(result.verifications)) {
|
|
332
|
+
* console.log(key, verification.status);
|
|
334
333
|
* }
|
|
335
334
|
* ```
|
|
336
335
|
*/
|
|
337
|
-
|
|
336
|
+
verifyAll(input: VerifyCitationsFromLlmOutput, citations?: {
|
|
338
337
|
[key: string]: Citation;
|
|
339
338
|
}): Promise<VerifyCitationsResponse>;
|
|
340
339
|
}
|
package/lib/client/index.d.ts
CHANGED
|
@@ -306,35 +306,34 @@ declare class DeepCitation {
|
|
|
306
306
|
* import { getAllCitationsFromLlmOutput } from '@deepcitation/deepcitation-js';
|
|
307
307
|
*
|
|
308
308
|
* const citations = getAllCitationsFromLlmOutput(llmResponse);
|
|
309
|
-
* const verified = await dc.
|
|
309
|
+
* const verified = await dc.verify(attachmentId, citations);
|
|
310
310
|
*
|
|
311
311
|
* for (const [key, result] of Object.entries(verified.verifications)) {
|
|
312
|
-
* console.log(key, result.
|
|
312
|
+
* console.log(key, result.status);
|
|
313
313
|
* // "found", "partial_text_found", "not_found", etc.
|
|
314
314
|
* }
|
|
315
315
|
* ```
|
|
316
316
|
*/
|
|
317
|
-
|
|
317
|
+
verify(attachmentId: string, citations: CitationInput, options?: VerifyCitationsOptions): Promise<VerifyCitationsResponse>;
|
|
318
318
|
/**
|
|
319
|
-
*
|
|
319
|
+
* Parse and verify all citations from LLM output.
|
|
320
320
|
* This is the recommended way to verify citations for new integrations.
|
|
321
321
|
*
|
|
322
|
-
* @param input - Object containing llmOutput and optional
|
|
322
|
+
* @param input - Object containing llmOutput and optional outputImageFormat
|
|
323
323
|
* @returns Verification results with status and proof images
|
|
324
324
|
*
|
|
325
325
|
* @example
|
|
326
326
|
* ```typescript
|
|
327
|
-
* const result = await dc.
|
|
327
|
+
* const result = await dc.verifyAll({
|
|
328
328
|
* llmOutput: response.content,
|
|
329
|
-
* fileDataParts, // From prepareFiles()
|
|
330
329
|
* });
|
|
331
330
|
*
|
|
332
|
-
* for (const [key,
|
|
333
|
-
* console.log(key,
|
|
331
|
+
* for (const [key, verification] of Object.entries(result.verifications)) {
|
|
332
|
+
* console.log(key, verification.status);
|
|
334
333
|
* }
|
|
335
334
|
* ```
|
|
336
335
|
*/
|
|
337
|
-
|
|
336
|
+
verifyAll(input: VerifyCitationsFromLlmOutput, citations?: {
|
|
338
337
|
[key: string]: Citation;
|
|
339
338
|
}): Promise<VerifyCitationsResponse>;
|
|
340
339
|
}
|
package/lib/client/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{a as DeepCitation}from'../chunk-
|
|
1
|
+
export{a as DeepCitation}from'../chunk-G6RPOT3H.js';import'../chunk-ETIDLMKZ.js';import'../chunk-O2XFH626.js';
|
package/lib/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkURRIEXFH_cjs=require('./chunk-URRIEXFH.cjs'),chunk4FGOHQFP_cjs=require('./chunk-4FGOHQFP.cjs'),chunkCFXDRAJL_cjs=require('./chunk-CFXDRAJL.cjs'),chunk4HRWJSX6_cjs=require('./chunk-4HRWJSX6.cjs');require('./chunk-F2MMVEVC.cjs');var Y=t=>{if(!t)return false;let e=t.trim();if(e.length<64)return false;let a=e?.[0];for(let r=1;r<e.length;r++)if(e[r]!==a)return false;return true};function z(t){t=t.trim();let e=2,a=10,r=/[.?!](?=\s+|$)/g,m,n=[];for(;(m=r.exec(t))!==null;)n.push(m.index);if(n.length<2)return t;let I=n[n.length-1],C=n[n.length-2],o=t.substring(C+1,I+1),p=o.length;if(o.trim().slice(0,-1).length<a||p<=0||t.length<p*e)return t;let c=0,s=I+1;t.endsWith(o)&&(s=t.length);let f=-1;for(;;){let i=s-p;if(i<0)break;if(t.substring(i,s)===o)c++,f=i,s=i;else break}return c>=e?t.substring(0,f)+o:t}Object.defineProperty(exports,"DeepCitation",{enumerable:true,get:function(){return chunkURRIEXFH_cjs.a}});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}});Object.defineProperty(exports,"BLANK_VERIFICATION",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.d}});Object.defineProperty(exports,"DEFAULT_OUTPUT_IMAGE_FORMAT",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.a}});Object.defineProperty(exports,"NOT_FOUND_VERIFICATION_INDEX",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.b}});Object.defineProperty(exports,"PENDING_VERIFICATION_INDEX",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.c}});Object.defineProperty(exports,"CITATION_X_PADDING",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.p}});Object.defineProperty(exports,"CITATION_Y_PADDING",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.q}});Object.defineProperty(exports,"generateCitationInstanceId",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.k}});Object.defineProperty(exports,"generateCitationKey",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.i}});Object.defineProperty(exports,"generateVerificationKey",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.j}});Object.defineProperty(exports,"getAllCitationsFromLlmOutput",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.t}});Object.defineProperty(exports,"getCitationPageNumber",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.e}});Object.defineProperty(exports,"getCitationStatus",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.r}});Object.defineProperty(exports,"groupCitationsByAttachmentId",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.u}});Object.defineProperty(exports,"groupCitationsByAttachmentIdObject",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.v}});Object.defineProperty(exports,"normalizeCitations",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.f}});Object.defineProperty(exports,"parseCitation",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.s}});Object.defineProperty(exports,"removeCitations",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.b}});Object.defineProperty(exports,"removeLineIdMetadata",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.d}});Object.defineProperty(exports,"removePageNumberMetadata",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.c}});Object.defineProperty(exports,"replaceCitations",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.a}});Object.defineProperty(exports,"sha1Hash",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.g}});exports.cleanRepeatingLastSentence=z;exports.isGeminiGarbage=Y;
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{a as DeepCitation}from'./chunk-
|
|
1
|
+
export{a as DeepCitation}from'./chunk-G6RPOT3H.js';export{b as AV_CITATION_MARKDOWN_SYNTAX_PROMPT,h as CITATION_AV_BASED_JSON_OUTPUT_FORMAT,d as CITATION_AV_REMINDER,g as CITATION_JSON_OUTPUT_FORMAT,a as CITATION_MARKDOWN_SYNTAX_PROMPT,c as CITATION_REMINDER,i as compressPromptIds,j as decompressPromptIds,f as wrapCitationPrompt,e as wrapSystemCitationPrompt}from'./chunk-2IZXUOQR.js';export{d as BLANK_VERIFICATION,a as DEFAULT_OUTPUT_IMAGE_FORMAT,b as NOT_FOUND_VERIFICATION_INDEX,c as PENDING_VERIFICATION_INDEX}from'./chunk-RQPZSRID.js';export{p as CITATION_X_PADDING,q as CITATION_Y_PADDING,k as generateCitationInstanceId,i as generateCitationKey,j as generateVerificationKey,t as getAllCitationsFromLlmOutput,e as getCitationPageNumber,r as getCitationStatus,u as groupCitationsByAttachmentId,v as groupCitationsByAttachmentIdObject,f as normalizeCitations,s as parseCitation,b as removeCitations,d as removeLineIdMetadata,c as removePageNumberMetadata,a as replaceCitations,g as sha1Hash}from'./chunk-ETIDLMKZ.js';import'./chunk-O2XFH626.js';var Y=t=>{if(!t)return false;let e=t.trim();if(e.length<64)return false;let a=e?.[0];for(let r=1;r<e.length;r++)if(e[r]!==a)return false;return true};function z(t){t=t.trim();let e=2,a=10,r=/[.?!](?=\s+|$)/g,m,n=[];for(;(m=r.exec(t))!==null;)n.push(m.index);if(n.length<2)return t;let I=n[n.length-1],C=n[n.length-2],o=t.substring(C+1,I+1),p=o.length;if(o.trim().slice(0,-1).length<a||p<=0||t.length<p*e)return t;let c=0,s=I+1;t.endsWith(o)&&(s=t.length);let f=-1;for(;;){let i=s-p;if(i<0)break;if(t.substring(i,s)===o)c++,f=i,s=i;else break}return c>=e?t.substring(0,f)+o:t}export{z as cleanRepeatingLastSentence,Y as isGeminiGarbage};
|
package/lib/react/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';var chunk4HRWJSX6_cjs=require('../chunk-4HRWJSX6.cjs');require('../chunk-F2MMVEVC.cjs');var Ie=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 Ie__namespace=/*#__PURE__*/_interopNamespace(Ie);var R__namespace=/*#__PURE__*/_interopNamespace(R);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=ke[e];return jsxRuntime.jsx("span",{className:chunk4HRWJSX6_cjs.o("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})})},ie=({url:e,faviconUrl:t})=>{let n=le(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";}})},we=Ie.forwardRef(({urlMeta:e,citation:t,children:n,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=false},P)=>{let{url:g,domain:A,title:N,fetchStatus:C,faviconUrl:w,errorMessage:B}=e,v=Ie.useMemo(()=>t||{value:g,fullPhrase:N||g},[t,g,N]),m=Ie.useMemo(()=>chunk4HRWJSX6_cjs.i(v),[v]),K=Ie.useMemo(()=>chunk4HRWJSX6_cjs.k(m),[m]),M=Ie.useMemo(()=>A||le(g),[A,g]),L=Ie.useMemo(()=>at(g),[g]),D=Ie.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=Ie.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=Ie.useCallback(()=>{p?.onMouseEnter?.(v,m);},[p,v,m]),E=Ie.useCallback(()=>{p?.onMouseLeave?.(v,m);},[p,v,m]),_=()=>Z||ee?l?l(C,B):jsxRuntime.jsx(ot,{status:C,errorMessage:B}):te?jsxRuntime.jsx("span",{className:"text-[0.85em] text-green-600 dark:text-green-500","aria-hidden":"true",title:"Verified",children:"\u2713"}):G?jsxRuntime.jsx("span",{className:"text-[0.85em] text-amber-600 dark:text-amber-500","aria-hidden":"true",title:"Partial match",children:"~"}):T?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:P,"data-citation-id":m,"data-citation-instance":K,"data-url":g,"data-fetch-status":C,"data-variant":"chip",className:chunk4HRWJSX6_cjs.o("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?void 0:y,onMouseLeave:h?void 0:E,onMouseDown:O,onClick:b=>b.stopPropagation(),role:"link","aria-label":`Link to ${M}: ${S.label}`,children:[i&&jsxRuntime.jsx(ie,{url:g,faviconUrl:w}),jsxRuntime.jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:D}),_()]})]}):a==="inline"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[n,jsxRuntime.jsxs("a",{ref:P,href:g,"data-citation-id":m,"data-citation-instance":K,"data-fetch-status":C,"data-variant":"inline",className:chunk4HRWJSX6_cjs.o("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?void 0:y,onMouseLeave:h?void 0:E,onClick:b=>{b.preventDefault(),O(b);},target:"_blank",rel:"noopener noreferrer","aria-label":`Link to ${M}: ${S.label}`,children:[i&&jsxRuntime.jsx(ie,{url:g,faviconUrl:w}),jsxRuntime.jsx("span",{children:D}),_()]})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[n,jsxRuntime.jsxs("span",{ref:P,"data-citation-id":m,"data-citation-instance":K,"data-url":g,"data-fetch-status":C,"data-variant":"bracket",className:chunk4HRWJSX6_cjs.o("cursor-pointer transition-colors",S.className,r),title:o?g:void 0,onMouseEnter:h?void 0:y,onMouseLeave:h?void 0:E,onMouseDown:O,onClick:b=>b.stopPropagation(),role:"link","aria-label":`Link to ${M}: ${S.label}`,children:["[",i&&jsxRuntime.jsx(ie,{url:g,faviconUrl:w}),jsxRuntime.jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:D}),_(),"]"]})]})});we.displayName="UrlCitationComponent";Ie.memo(we);var it=({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"})]}),Q=({className:e})=>jsxRuntime.jsx("svg",{className:chunk4HRWJSX6_cjs.h("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"})}),ce=({className:e})=>jsxRuntime.jsx("svg",{className:chunk4HRWJSX6_cjs.h("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"})}),de=({className:e})=>jsxRuntime.jsxs("svg",{className:chunk4HRWJSX6_cjs.h("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 st(...e){return e.filter(Boolean).join(" ")}var Ee=R__namespace.Root,_e=R__namespace.Trigger;var ue=Ie__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: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__namespace.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
|
|
1
|
+
'use strict';var chunk4HRWJSX6_cjs=require('../chunk-4HRWJSX6.cjs');require('../chunk-F2MMVEVC.cjs');var Ie=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 Ie__namespace=/*#__PURE__*/_interopNamespace(Ie);var R__namespace=/*#__PURE__*/_interopNamespace(R);function ue(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e.replace(/^https?:\/\/(www\.)?/,"").split("/")[0]}}function Ce(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 Ne(e){return e.startsWith("blocked_")}function Pe(e){return e.startsWith("error_")}function rt(e){return e==="verified"||e==="partial"}var ot=({status:e,errorMessage:t})=>{let n=ke[e];return jsxRuntime.jsx("span",{className:chunk4HRWJSX6_cjs.o("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})})},ce=({url:e,faviconUrl:t})=>{let n=ue(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";}})},we=Ie.forwardRef(({urlMeta:e,citation:t,children:n,className:r,variant:a="chip",showFullUrlOnHover:o=true,showFavicon:i=true,showTitle:c=false,maxDisplayLength:l=30,renderBlockedIndicator:d,onUrlClick:u,eventHandlers:p,preventTooltips:f=false},N)=>{let{url:x,domain:W,title:P,fetchStatus:b,faviconUrl:w,errorMessage:B}=e,v=Ie.useMemo(()=>t||{value:x,fullPhrase:P||x},[t,x,P]),g=Ie.useMemo(()=>chunk4HRWJSX6_cjs.i(v),[v]),G=Ie.useMemo(()=>chunk4HRWJSX6_cjs.k(g),[g]),S=Ie.useMemo(()=>W||ue(x),[W,x]),E=Ie.useMemo(()=>at(x),[x]),D=Ie.useMemo(()=>{if(c&&P)return Ce(P,l);let C=E?Ce(E,l-S.length-1):"";return C?`${S}${C}`:S},[c,P,S,E,l]),M=ke[b],$=Ne(b),ae=Pe(b),re=b==="verified",X=b==="partial",T=b==="pending",z=Ie.useCallback(C=>{C.preventDefault(),C.stopPropagation(),u?u(x,C):window.open(x,"_blank","noopener,noreferrer"),p?.onClick?.(v,g,C);},[u,x,p,v,g]),y=Ie.useCallback(()=>{p?.onMouseEnter?.(v,g);},[p,v,g]),_=Ie.useCallback(()=>{p?.onMouseLeave?.(v,g);},[p,v,g]),L=()=>$||ae?d?d(b,B):jsxRuntime.jsx(ot,{status:b,errorMessage:B}):re?jsxRuntime.jsx("span",{className:"text-[0.85em] text-green-600 dark:text-green-500","aria-hidden":"true",title:"Verified",children:"\u2713"}):X?jsxRuntime.jsx("span",{className:"text-[0.85em] text-amber-600 dark:text-amber-500","aria-hidden":"true",title:"Partial match",children:"~"}):T?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:N,"data-citation-id":g,"data-citation-instance":G,"data-url":x,"data-fetch-status":b,"data-variant":"chip",className:chunk4HRWJSX6_cjs.o("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",M.className,r),title:o?x:void 0,onMouseEnter:f?void 0:y,onMouseLeave:f?void 0:_,onMouseDown:z,onClick:C=>C.stopPropagation(),role:"link","aria-label":`Link to ${S}: ${M.label}`,children:[i&&jsxRuntime.jsx(ce,{url:x,faviconUrl:w}),jsxRuntime.jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:D}),L()]})]}):a==="inline"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[n,jsxRuntime.jsxs("a",{ref:N,href:x,"data-citation-id":g,"data-citation-instance":G,"data-fetch-status":b,"data-variant":"inline",className:chunk4HRWJSX6_cjs.o("inline-flex items-center gap-1 cursor-pointer transition-colors no-underline border-b border-dotted border-current",M.className,r),title:o?x:void 0,onMouseEnter:f?void 0:y,onMouseLeave:f?void 0:_,onClick:C=>{C.preventDefault(),z(C);},target:"_blank",rel:"noopener noreferrer","aria-label":`Link to ${S}: ${M.label}`,children:[i&&jsxRuntime.jsx(ce,{url:x,faviconUrl:w}),jsxRuntime.jsx("span",{children:D}),L()]})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[n,jsxRuntime.jsxs("span",{ref:N,"data-citation-id":g,"data-citation-instance":G,"data-url":x,"data-fetch-status":b,"data-variant":"bracket",className:chunk4HRWJSX6_cjs.o("cursor-pointer transition-colors",M.className,r),title:o?x:void 0,onMouseEnter:f?void 0:y,onMouseLeave:f?void 0:_,onMouseDown:z,onClick:C=>C.stopPropagation(),role:"link","aria-label":`Link to ${S}: ${M.label}`,children:["[",i&&jsxRuntime.jsx(ce,{url:x,faviconUrl:w}),jsxRuntime.jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:D}),L(),"]"]})]})});we.displayName="UrlCitationComponent";Ie.memo(we);var it=({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"})]}),Q=({className:e})=>jsxRuntime.jsx("svg",{className:chunk4HRWJSX6_cjs.h("w-[10px] h-[10px]",e),viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:jsxRuntime.jsx("polyline",{points:"20 6 9 17 4 12"})}),ee=({className:e})=>jsxRuntime.jsx("svg",{className:chunk4HRWJSX6_cjs.h("w-[10px] h-[10px]",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"})}),te=({className:e})=>jsxRuntime.jsxs("svg",{className:chunk4HRWJSX6_cjs.h("w-[10px] h-[10px] 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 st(...e){return e.filter(Boolean).join(" ")}var Ee=R__namespace.Root,_e=R__namespace.Trigger;var pe=Ie__namespace.forwardRef(({className:e,align:t="center",sideOffset:n=8,...r},a)=>jsxRuntime.jsx(R__namespace.Portal,{children:jsxRuntime.jsx(R__namespace.Content,{ref:a,align:t,sideOffset:n,className:st("z-50 w-auto rounded-lg border bg-white shadow-xl outline-none","max-w-[min(600px,calc(100vw-2rem))]","border-gray-200 dark:border-gray-700 dark:bg-gray-900","data-[state=open]:animate-in data-[state=closed]:animate-out","data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0","data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95","data-[side=bottom]:slide-in-from-top-2","data-[side=left]:slide-in-from-right-2","data-[side=right]:slide-in-from-left-2","data-[side=top]:slide-in-from-bottom-2",e),...r})}));pe.displayName=R__namespace.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 c=e.slice(o,r-i),l=t.slice(o,a-i);if(c.length===0&&l.length===0)return [{value:e.join(""),count:e.length}];let d=lt(c,l,n),u=[];return o>0&&u.push({value:e.slice(0,o).join(""),count:o}),u.push(...d),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},c=[];e:for(let l=0;l<=o;l++){c.push({...i});for(let d=-l;d<=l;d+=2){let u;d===-l||d!==l&&i[d-1]<i[d+1]?u=i[d+1]:u=i[d-1]+1;let p=u-d;for(;u<r&&p<a&&n(e[u],t[p]);)u++,p++;if(i[d]=u,u>=r&&p>=a)break e}}return ct(c,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 c=e[i],l=a-o,d;l===-i||l!==i&&c[l-1]<c[l+1]?d=l+1:d=l-1;let u=c[d]??0,p=u-d;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 me(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],c=Be(a.value,o.value).match(/^\s*/)?.[0]||"",l=a.value.slice(c.length),d=o.value.slice(c.length),p=me(l,d).match(/\s*$/)?.[0]||"";c&&t.push({value:c,count:1});let f=a.value.slice(c.length,a.value.length-p.length),N=o.value.slice(c.length,o.value.length-p.length);f&&t.push({value:f,removed:true,count:1}),N&&t.push({value:N,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 c=me(i,o);if(c){t.push({value:r.value.slice(c.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]||"",c=r.value.match(/\s*$/)?.[0]||"",l=a.value.match(/\s*$/)?.[0]||"",d=o.value.match(/^\s*/)?.[0]||"";if(i&&l&&me(l,i).length===i.length){t.push({value:r.value.slice(i.length),removed:true,count:1});continue}if(c&&d&&Be(c,d).length===c.length){t.push({value:r.value.slice(0,-c.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 Ae(e,t){let n=Re(e),r=Re(t),a=Ve(n,r);return ut(a)}var We=(e="",t="")=>Ie.useMemo(()=>{let n=(e||"").trim().replace(/\r\n/g,`
|
|
3
3
|
`),r=(t||"").trim().replace(/\r\n/g,`
|
|
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 Ie.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 kt=()=>jsxRuntime.jsx("span",{className:"inline-flex relative ml-0.5 text-green-600 dark:text-green-500","aria-hidden":"true",children:jsxRuntime.jsx(Q,{})}),Pt=()=>jsxRuntime.jsx("span",{className:"inline-flex relative ml-0.5 text-amber-600 dark:text-amber-500","aria-hidden":"true",children:jsxRuntime.jsx(Q,{})}),Nt=()=>jsxRuntime.jsx("span",{className:"inline-flex ml-1 text-gray-400 dark:text-gray-500","aria-hidden":"true",children:jsxRuntime.jsx(de,{})}),wt=()=>jsxRuntime.jsx("span",{className:"inline-flex relative ml-0.5 text-red-500 dark:text-red-400","aria-hidden":"true",children:jsxRuntime.jsx(ce,{})});function Mt({citation:e,verification:t,status:n,onImageClick:r}){let a=t?.verificationImageBase64,{isMiss:o,isPartialMatch:i}=n;if(a)return jsxRuntime.jsxs("div",{className:"p-1",children:[jsxRuntime.jsx("button",{type:"button",className:"block cursor-zoom-in",onClick:u=>{u.preventDefault(),u.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"})}),(o||i)&&jsxRuntime.jsx(Oe,{citation:e,verification:t,status:n})]});let d=Ct(n),s=t?.verifiedMatchSnippet,l=t?.verifiedPageNumber;return !s&&!d?null:jsxRuntime.jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[200px] max-w-[400px]",children:[d&&jsxRuntime.jsx("span",{className:chunk4HRWJSX6_cjs.h("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&&jsxRuntime.jsxs("span",{className:"text-sm text-gray-700 dark:text-gray-300 italic",children:['"',t.verifiedMatchSnippet,'"']}),l&&l>0&&jsxRuntime.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Page ",l]}),(o||i)&&jsxRuntime.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?jsxRuntime.jsxs("div",{className:"mt-2 pt-2 border-t border-gray-200 dark:border-gray-700 text-xs space-y-2",children:[o&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Expected"}),jsxRuntime.jsx("p",{className:"mt-1 p-2 bg-gray-100 dark:bg-gray-800 rounded font-mono text-[11px] break-words text-red-600 dark:text-red-400 line-through opacity-70",children:o.length>100?o.slice(0,100)+"\u2026":o})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Found"}),jsxRuntime.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:[o&&i&&s?jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Diff"}),jsxRuntime.jsx("div",{className:"mt-1 p-2 bg-gray-100 dark:bg-gray-800 rounded font-mono text-[11px] break-words text-gray-700 dark:text-gray-300",children:l?jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("span",{className:"text-gray-500 dark:text-gray-400 text-[10px]",children:["Expected:"," "]}),jsxRuntime.jsx("span",{className:"text-red-600 dark:text-red-400 line-through opacity-70",children:o.length>100?o.slice(0,100)+"\u2026":o})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("span",{className:"text-gray-500 dark:text-gray-400 text-[10px]",children:["Found:"," "]}),jsxRuntime.jsx("span",{className:"text-green-600 dark:text-green-400",children:i.length>100?i.slice(0,100)+"\u2026":i})]})]}):d.map((N,C)=>jsxRuntime.jsx("span",{children:N.parts.map((w,B)=>{let v=`p-${C}-${B}`;return w.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:w.value},v):w.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:w.value},v):jsxRuntime.jsx("span",{children:w.value},v)})},`block-${C}`))})]}):o&&!s?jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Text"}),jsxRuntime.jsx("p",{className:"mt-1 p-2 bg-gray-100 dark:bg-gray-800 rounded font-mono text-[11px] break-words text-gray-700 dark:text-gray-300",children:o.length>100?o.slice(0,100)+"\u2026":o})]}):null,A&&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:P})," \u2192 ",g]})]}),h&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Line"}),jsxRuntime.jsxs("p",{className:"mt-1 font-mono text-[11px] text-gray-700 dark:text-gray-300",children:[jsxRuntime.jsx("span",{className:"text-red-600 dark:text-red-400 line-through opacity-70",children:u?.join(", ")})," \u2192 ",p?.join(", ")]})]})]})}var xe=Ie.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,popoverPosition:P="top",renderPopoverContent:g},A)=>{let N=Ie.useMemo(()=>d||xt(i),[d,i]),[C,w]=Ie.useState(false),[B,v]=Ie.useState(null),m=Ie.useMemo(()=>chunk4HRWJSX6_cjs.i(e),[e]),K=Ie.useMemo(()=>chunk4HRWJSX6_cjs.k(m),[m]),M=Ie.useMemo(()=>bt(a),[a]),{isMiss:L,isPartialMatch:D,isVerified:S,isPending:Z}=M,ee=5e3,[te,G]=Ie.useState(false),T=Ie.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;Ie.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=Ie.useMemo(()=>vt(e,N,r),[e,N,r]),_=Ie.useCallback(()=>({citation:e,citationKey:m,verification:a??null,isTooltipExpanded:C,isImageExpanded:!!B,hasImage:!!a?.verificationImageBase64}),[e,m,a,C,B]),b=Ie.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=Ie.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,$=Ie.useRef(null),ne=Ie.useRef(false),U=Ie.useCallback(()=>{$.current&&(clearTimeout($.current),$.current=null);},[]),je=Ie.useCallback(()=>{U(),w(true),l?.onHover?.onEnter&&l.onHover.onEnter(_()),s?.onMouseEnter?.(e,m);},[s,l,e,m,_,U]),Fe=Ie.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=Ie.useCallback(()=>{U(),ne.current=true;},[U]),Ke=Ie.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]);Ie.useEffect(()=>()=>{$.current&&clearTimeout($.current);},[]);let Ze=Ie.useCallback(x=>{u&&(x.preventDefault(),x.stopPropagation(),s?.onTouchEnd?.(e,m,x));},[s,e,m,u]);if(r!=null&&N==="keySpan"&&L)return jsxRuntime.jsx("span",{className:chunk4HRWJSX6_cjs.h("text-gray-400 dark:text-gray-500",n),children:r});let ae=chunk4HRWJSX6_cjs.h((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?jsxRuntime.jsx(Nt,{}):L?jsxRuntime.jsx(wt,{}):D?jsxRuntime.jsx(Pt,{}):S?jsxRuntime.jsx(kt,{}):null,ve=()=>{if(h)return h({citation:e,status:M,citationKey:m,displayText:E,isMergedDisplay:N==="keySpan"});if(N==="indicator")return jsxRuntime.jsx("span",{children:z()});if(i==="chip"){let x=chunk4HRWJSX6_cjs.h(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 jsxRuntime.jsxs("span",{className:chunk4HRWJSX6_cjs.h("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-sm font-medium",x),children:[jsxRuntime.jsx("span",{className:"max-w-60 overflow-hidden text-ellipsis whitespace-nowrap",children:E}),z()]})}if(i==="superscript"){let x=chunk4HRWJSX6_cjs.h(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 jsxRuntime.jsxs("sup",{className:chunk4HRWJSX6_cjs.h("text-xs font-medium transition-colors hover:underline",x),children:["[",E,z(),"]"]})}return i==="text"?jsxRuntime.jsxs("span",{className:ae,children:[E,z()]}):i==="minimal"?jsxRuntime.jsxs("span",{className:chunk4HRWJSX6_cjs.h("max-w-80 overflow-hidden text-ellipsis",ae),children:[E,z()]}):jsxRuntime.jsxs("span",{className:chunk4HRWJSX6_cjs.h("inline-flex items-baseline gap-0.5 whitespace-nowrap","font-mono text-xs leading-tight","text-gray-500 dark:text-gray-400","transition-colors"),"aria-hidden":"true",children:["[",jsxRuntime.jsxs("span",{className:chunk4HRWJSX6_cjs.h("max-w-80 overflow-hidden text-ellipsis",ae),children:[E,z()]}),"]"]})},Ge=!(P==="hidden")&&a&&(a.verificationImageBase64||a.verifiedMatchSnippet),Xe=!!a?.verificationImageBase64,Ce=B?jsxRuntime.jsx(yt,{src:B,alt:"Citation verification - full size",onClose:()=>v(null)}):null,be={"data-citation-id":m,"data-citation-instance":K,className:chunk4HRWJSX6_cjs.h("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?g({citation:e,verification:a??null,status:M}):jsxRuntime.jsx(Mt,{citation:e,verification:a??null,status:M,onImageClick:()=>{a?.verificationImageBase64&&v(a.verificationImageBase64);}});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[t,jsxRuntime.jsxs(Ee,{open:C,children:[jsxRuntime.jsx(_e,{asChild:true,children:jsxRuntime.jsx("span",{ref:A,...be,children:ve()})}),jsxRuntime.jsx(ue,{side:P==="bottom"?"bottom":"top",onPointerDownOutside:X=>X.preventDefault(),onInteractOutside:X=>X.preventDefault(),onMouseEnter:He,onMouseLeave:Ke,children:x})]}),Ce]})}return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[t,jsxRuntime.jsx("span",{ref:A,...be,children:ve()}),Ce]})});xe.displayName="CitationComponent";var St=Ie.memo(xe);Object.defineProperty(exports,"CITATION_X_PADDING",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.p}});Object.defineProperty(exports,"CITATION_Y_PADDING",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.q}});Object.defineProperty(exports,"classNames",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.o}});Object.defineProperty(exports,"generateCitationInstanceId",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.k}});Object.defineProperty(exports,"generateCitationKey",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.i}});Object.defineProperty(exports,"getCitationDisplayText",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.l}});Object.defineProperty(exports,"getCitationKeySpanText",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.n}});Object.defineProperty(exports,"getCitationNumber",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.m}});exports.CheckIcon=Q;exports.CitationComponent=xe;exports.DeepCitationIcon=it;exports.MemoizedCitationComponent=St;exports.SpinnerIcon=de;exports.WarningIcon=ce;exports.extractDomain=le;exports.isBlockedStatus=Pe;exports.isErrorStatus=Ne;exports.isVerifiedStatus=rt;
|
|
4
|
+
`),a=Ue(n,r),o=[],i=false,c=0;for(let u=0;u<a.length;u++){let p=a[u],f=a[u+1];if(p.removed&&f&&f.added){let N=Ae(p.value,f.value);o.push({type:"modified",parts:N}),i=true,c+=Math.abs(p.value.length-f.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,c+=p.value.length):o.push({type:"unchanged",parts:[{value:p.value}]});}let l=Math.max(n.length,r.length),d=l===0?1:1-c/l;return {diffResult:o,hasDiff:i,similarity:d,isHighVariance:d<.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 bt(e){return e.isVerified&&!e.isPartialMatch?"Verified":e.isPartialMatch?"Partial Match":e.isMiss?"Not Found":e.isPending?"Verifying...":""}function yt(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 Ct({src:e,alt:t,onClose:n}){return Ie.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 duration-[50ms]",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 animate-in zoom-in-95 duration-[50ms]",children:jsxRuntime.jsx("img",{src:e,alt:t,className:"max-w-full max-h-[95vh] object-contain rounded-lg shadow-2xl",draggable:false})})}),document.body)}var kt=()=>jsxRuntime.jsx("span",{className:"inline-flex relative ml-0.5 text-green-600 dark:text-green-500","aria-hidden":"true",children:jsxRuntime.jsx(Q,{})}),Nt=()=>jsxRuntime.jsx("span",{className:"inline-flex relative ml-0.5 text-amber-600 dark:text-amber-500","aria-hidden":"true",children:jsxRuntime.jsx(Q,{})}),Pt=()=>jsxRuntime.jsx("span",{className:"inline-flex ml-1 text-gray-400 dark:text-gray-500","aria-hidden":"true",children:jsxRuntime.jsx(te,{})}),wt=()=>jsxRuntime.jsx("span",{className:"inline-flex relative ml-0.5 text-red-500 dark:text-red-400","aria-hidden":"true",children:jsxRuntime.jsx(ee,{})});function St({citation:e,verification:t}){let n=Ie.useMemo(()=>{let c=new Set;if(t?.searchAttempts){for(let l of t.searchAttempts)if(l.searchPhrases)for(let d of l.searchPhrases)d&&c.add(d);}return c.size===0&&(e.fullPhrase&&c.add(e.fullPhrase),e.keySpan&&c.add(e.keySpan.toString())),Array.from(c)},[e,t]),[r,a]=Ie.useState(false);if(n.length===0)return null;let o=r?n.length:1,i=n.length-1;return jsxRuntime.jsxs("div",{className:"mt-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-gray-500 dark:text-gray-400 uppercase font-medium",children:[jsxRuntime.jsxs("span",{children:["Searched ",n.length," phrase",n.length!==1?"s":""]}),i>0&&!r&&jsxRuntime.jsxs("button",{type:"button",onClick:()=>a(true),className:"text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300 lowercase",children:["+",i," more"]}),r&&i>0&&jsxRuntime.jsx("button",{type:"button",onClick:()=>a(false),className:"text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300 lowercase",children:"collapse"})]}),jsxRuntime.jsx("div",{className:"mt-1 space-y-1",children:n.slice(0,o).map((c,l)=>jsxRuntime.jsxs("p",{className:"p-2 bg-gray-100 dark:bg-gray-800 rounded font-mono text-[11px] break-words text-gray-700 dark:text-gray-300 border-l-2 border-red-400 dark:border-red-500",children:['"',c.length>80?c.slice(0,80)+"\u2026":c,'"']},l))})]})}function Mt({citation:e,verification:t,status:n,onImageClick:r,isLoading:a=false}){let o=t?.verificationImageBase64,{isMiss:i,isPartialMatch:c,isPending:l}=n;if(o)return jsxRuntime.jsxs("div",{className:"p-2",children:[jsxRuntime.jsxs("button",{type:"button",className:"group block cursor-zoom-in relative",onClick:f=>{f.preventDefault(),f.stopPropagation(),r?.();},"aria-label":"Click to view full size",children:[jsxRuntime.jsx("img",{src:t.verificationImageBase64,alt:"Citation verification",className:"max-w-full h-auto object-contain rounded-md bg-gray-50 dark:bg-gray-800",loading:"lazy"}),jsxRuntime.jsx("span",{className:"absolute inset-0 flex items-center justify-center bg-black/0 group-hover:bg-black/5 dark:group-hover:bg-white/5 transition-colors rounded-md",children:jsxRuntime.jsx("span",{className:"opacity-0 group-hover:opacity-100 transition-opacity text-xs text-gray-600 dark:text-gray-300 bg-white/90 dark:bg-gray-800/90 px-2 py-1 rounded shadow-sm",children:"Click to expand"})})]}),(i||c)&&jsxRuntime.jsx(ze,{citation:e,verification:t,status:n})]});if(a||l){let f=e.fullPhrase||e.keySpan?.toString();return jsxRuntime.jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[200px] max-w-[400px]",children:[jsxRuntime.jsxs("span",{className:"text-xs font-medium text-gray-500 dark:text-gray-400",children:[jsxRuntime.jsx(te,{className:"inline-block relative top-[0.1em] mr-1.5"}),"Searching..."]}),f&&jsxRuntime.jsxs("p",{className:"p-2 bg-gray-100 dark:bg-gray-800 rounded font-mono text-[11px] break-words text-gray-600 dark:text-gray-400 italic",children:['"',f.length>80?f.slice(0,80)+"\u2026":f,'"']}),e.pageNumber&&e.pageNumber>0&&jsxRuntime.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Looking on page ",e.pageNumber]})]})}if(i)return jsxRuntime.jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[200px] max-w-[400px]",children:[jsxRuntime.jsxs("span",{className:"text-xs font-medium text-red-600 dark:text-red-500",children:[jsxRuntime.jsx(ee,{className:"inline-block relative top-[0.1em] mr-1.5"}),"Not found in source"]}),jsxRuntime.jsx(St,{citation:e,verification:t})]});let d=bt(n),u=t?.verifiedMatchSnippet,p=t?.verifiedPageNumber;return !u&&!d?null:jsxRuntime.jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[180px] max-w-full",children:[d&&jsxRuntime.jsx("span",{className:chunk4HRWJSX6_cjs.h("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}),u&&jsxRuntime.jsxs("span",{className:"text-sm text-gray-700 dark:text-gray-300 italic",children:['"',t.verifiedMatchSnippet,'"']}),p&&p>0&&jsxRuntime.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Page ",p]}),(i||c)&&jsxRuntime.jsx(ze,{citation:e,verification:t,status:n})]})}function ze({citation:e,verification:t,status:n}){let{isMiss:r,isPartialMatch:a}=n,o=e.fullPhrase||e.keySpan?.toString()||"",i=t?.verifiedMatchSnippet||"",{diffResult:c,hasDiff:l,isHighVariance:d}=We(o,i);if(!r&&!a)return null;let u=e.lineIds,p=t?.verifiedLineIds,f=u&&p&&JSON.stringify(u)!==JSON.stringify(p),N=e.pageNumber,x=t?.verifiedPageNumber,W=N!=null&&x!=null&&N!==x;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:[o&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Expected"}),jsxRuntime.jsx("p",{className:"mt-1 p-2 bg-gray-100 dark:bg-gray-800 rounded font-mono text-[11px] break-words text-red-600 dark:text-red-400 line-through opacity-70",children:o.length>100?o.slice(0,100)+"\u2026":o})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Found"}),jsxRuntime.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:[o&&i&&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:d?jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("span",{className:"text-gray-500 dark:text-gray-400 text-[10px]",children:["Expected:"," "]}),jsxRuntime.jsx("span",{className:"text-red-600 dark:text-red-400 line-through opacity-70",children:o.length>100?o.slice(0,100)+"\u2026":o})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("span",{className:"text-gray-500 dark:text-gray-400 text-[10px]",children:["Found:"," "]}),jsxRuntime.jsx("span",{className:"text-green-600 dark:text-green-400",children:i.length>100?i.slice(0,100)+"\u2026":i})]})]}):c.map((P,b)=>jsxRuntime.jsx("span",{children:P.parts.map((w,B)=>{let v=`p-${b}-${B}`;return w.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:w.value},v):w.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:w.value},v):jsxRuntime.jsx("span",{children:w.value},v)})},`block-${b}`))})]}):o&&!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:o.length>100?o.slice(0,100)+"\u2026":o})]}):null,W&&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:N})," \u2192 ",x]})]}),f&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Line"}),jsxRuntime.jsxs("p",{className:"mt-1 font-mono text-[11px] text-gray-700 dark:text-gray-300",children:[jsxRuntime.jsx("span",{className:"text-red-600 dark:text-red-400 line-through opacity-70",children:u?.join(", ")})," \u2192 ",p?.join(", ")]})]})]})}var xe=Ie.forwardRef(({citation:e,children:t,className:n,fallbackDisplay:r,verification:a,isLoading:o=false,variant:i="brackets",content:c,eventHandlers:l,behaviorConfig:d,isMobile:u=false,renderIndicator:p,renderContent:f,popoverPosition:N="top",renderPopoverContent:x},W)=>{let P=Ie.useMemo(()=>c||xt(i),[c,i]),[b,w]=Ie.useState(false),[B,v]=Ie.useState(null),g=Ie.useMemo(()=>chunk4HRWJSX6_cjs.i(e),[e]),G=Ie.useMemo(()=>chunk4HRWJSX6_cjs.k(g),[g]),S=Ie.useMemo(()=>yt(a),[a]),{isMiss:E,isPartialMatch:D,isVerified:M,isPending:$}=S,ae=5e3,[re,X]=Ie.useState(false),T=Ie.useRef(null),z=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&&!re;Ie.useEffect(()=>(T.current&&(clearTimeout(T.current),T.current=null),(o||$)&&!z?(X(false),T.current=setTimeout(()=>{X(true);},ae)):X(false),()=>{T.current&&clearTimeout(T.current);}),[o,$,z]);let _=Ie.useMemo(()=>vt(e,P,r),[e,P,r]),L=Ie.useCallback(()=>({citation:e,citationKey:g,verification:a??null,isTooltipExpanded:b,isImageExpanded:!!B,hasImage:!!a?.verificationImageBase64}),[e,g,a,b,B]),C=Ie.useCallback(h=>{h.setImageExpanded!==void 0&&(typeof h.setImageExpanded=="string"?v(h.setImageExpanded):h.setImageExpanded===true&&a?.verificationImageBase64?v(a.verificationImageBase64):h.setImageExpanded===false&&v(null));},[a?.verificationImageBase64]),$e=Ie.useCallback(h=>{h.preventDefault(),h.stopPropagation();let Y=L();if(d?.onClick){let se=d.onClick(Y,h);se&&typeof se=="object"&&C(se),l?.onClick?.(e,g,h);return}if(l?.onClick){l.onClick(e,g,h);return}a?.verificationImageBase64&&v(a.verificationImageBase64);},[d,l,e,g,a?.verificationImageBase64,L,C]),he=150,O=Ie.useRef(null),oe=Ie.useRef(false),U=Ie.useCallback(()=>{O.current&&(clearTimeout(O.current),O.current=null);},[]),je=Ie.useCallback(()=>{U(),w(true),d?.onHover?.onEnter&&d.onHover.onEnter(L()),l?.onMouseEnter?.(e,g);},[l,d,e,g,L,U]),Fe=Ie.useCallback(()=>{U(),O.current=setTimeout(()=>{oe.current||(w(false),d?.onHover?.onLeave&&d.onHover.onLeave(L()),l?.onMouseLeave?.(e,g));},he);},[l,d,e,g,L,U]),He=Ie.useCallback(()=>{U(),oe.current=true;},[U]),Ke=Ie.useCallback(()=>{oe.current=false,U(),O.current=setTimeout(()=>{w(false),d?.onHover?.onLeave&&d.onHover.onLeave(L()),l?.onMouseLeave?.(e,g);},he);},[l,d,e,g,L,U]);Ie.useEffect(()=>()=>{O.current&&clearTimeout(O.current);},[]);let Ze=Ie.useCallback(h=>{u&&(h.preventDefault(),h.stopPropagation(),l?.onTouchEnd?.(e,g,h));},[l,e,g,u]);if(r!=null&&P==="keySpan"&&E)return jsxRuntime.jsx("span",{className:chunk4HRWJSX6_cjs.h("text-gray-400 dark:text-gray-500",n),children:r});let ie=chunk4HRWJSX6_cjs.h((M||D)&&i==="brackets"&&"text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 hover:underline",E&&"opacity-70 line-through text-gray-400 dark:text-gray-500",y&&"text-gray-500 dark:text-gray-400"),j=()=>p?p(S):y?jsxRuntime.jsx(Pt,{}):M&&!D?jsxRuntime.jsx(kt,{}):D?jsxRuntime.jsx(Nt,{}):E?jsxRuntime.jsx(wt,{}):null,ve=()=>{if(f)return f({citation:e,status:S,citationKey:g,displayText:_,isMergedDisplay:P==="keySpan"});if(P==="indicator")return jsxRuntime.jsx("span",{children:j()});if(i==="chip"){let h=chunk4HRWJSX6_cjs.h(M&&!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",E&&!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",!M&&!E&&!y&&"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400");return jsxRuntime.jsxs("span",{className:chunk4HRWJSX6_cjs.h("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-sm font-medium",h),children:[jsxRuntime.jsx("span",{className:"max-w-60 overflow-hidden text-ellipsis whitespace-nowrap",children:_}),j()]})}if(i==="superscript"){let h=chunk4HRWJSX6_cjs.h(M&&!D&&!y&&"text-green-600 dark:text-green-500",D&&!y&&"text-amber-600 dark:text-amber-500",E&&!y&&"text-red-500 dark:text-red-400 line-through",y&&"text-gray-400 dark:text-gray-500",!M&&!E&&!y&&"text-blue-600 dark:text-blue-400");return jsxRuntime.jsxs("sup",{className:chunk4HRWJSX6_cjs.h("text-xs font-medium transition-colors hover:underline",h),children:["[",_,j(),"]"]})}return i==="text"?jsxRuntime.jsxs("span",{className:ie,children:[_,j()]}):i==="minimal"?jsxRuntime.jsxs("span",{className:chunk4HRWJSX6_cjs.h("max-w-80 overflow-hidden text-ellipsis",ie),children:[_,j()]}):jsxRuntime.jsxs("span",{className:chunk4HRWJSX6_cjs.h("inline-flex items-baseline gap-0.5 whitespace-nowrap","font-mono text-xs leading-tight","text-gray-500 dark:text-gray-400","transition-colors"),"aria-hidden":"true",children:["[",jsxRuntime.jsxs("span",{className:chunk4HRWJSX6_cjs.h("max-w-80 overflow-hidden text-ellipsis",ie),children:[_,j()]}),"]"]})},Ge=!(N==="hidden")&&(a&&(a.verificationImageBase64||a.verifiedMatchSnippet)||y||$||o||E),Xe=!!a?.verificationImageBase64,be=B?jsxRuntime.jsx(Ct,{src:B,alt:"Citation verification - full size",onClose:()=>v(null)}):null,ye={"data-citation-id":g,"data-citation-instance":G,className:chunk4HRWJSX6_cjs.h("relative inline-flex items-baseline cursor-pointer","px-0.5 -mx-0.5 rounded-sm","transition-all duration-[50ms]","hover:bg-blue-500/10 dark:hover:bg-blue-400/10",Xe&&"cursor-zoom-in",n),onMouseEnter:je,onMouseLeave:Fe,onClick:$e,onTouchEndCapture:u?Ze:void 0,"aria-label":_?`[${_}]`:void 0};if(Ge){let h=x?x({citation:e,verification:a??null,status:S}):jsxRuntime.jsx(Mt,{citation:e,verification:a??null,status:S,isLoading:o||y,onImageClick:()=>{a?.verificationImageBase64&&v(a.verificationImageBase64);}});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[t,jsxRuntime.jsxs(Ee,{open:b,children:[jsxRuntime.jsx(_e,{asChild:true,children:jsxRuntime.jsx("span",{ref:W,...ye,children:ve()})}),jsxRuntime.jsx(pe,{side:N==="bottom"?"bottom":"top",onPointerDownOutside:Y=>Y.preventDefault(),onInteractOutside:Y=>Y.preventDefault(),onMouseEnter:He,onMouseLeave:Ke,children:h})]}),be]})}return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[t,jsxRuntime.jsx("span",{ref:W,...ye,children:ve()}),be]})});xe.displayName="CitationComponent";var It=Ie.memo(xe);Object.defineProperty(exports,"CITATION_X_PADDING",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.p}});Object.defineProperty(exports,"CITATION_Y_PADDING",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.q}});Object.defineProperty(exports,"classNames",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.o}});Object.defineProperty(exports,"generateCitationInstanceId",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.k}});Object.defineProperty(exports,"generateCitationKey",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.i}});Object.defineProperty(exports,"getCitationDisplayText",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.l}});Object.defineProperty(exports,"getCitationKeySpanText",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.n}});Object.defineProperty(exports,"getCitationNumber",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.m}});exports.CheckIcon=Q;exports.CitationComponent=xe;exports.DeepCitationIcon=it;exports.MemoizedCitationComponent=It;exports.SpinnerIcon=te;exports.WarningIcon=ee;exports.extractDomain=ue;exports.isBlockedStatus=Ne;exports.isErrorStatus=Pe;exports.isVerifiedStatus=rt;
|
package/lib/react/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {i,k,o,h}from'../chunk-ETIDLMKZ.js';export{p as CITATION_X_PADDING,q as CITATION_Y_PADDING,o as classNames,k as generateCitationInstanceId,i as generateCitationKey,l as getCitationDisplayText,n as getCitationKeySpanText,m as getCitationNumber}from'../chunk-ETIDLMKZ.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
|
|
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
|
|
1
|
+
import {i,k,o,h}from'../chunk-ETIDLMKZ.js';export{p as CITATION_X_PADDING,q as CITATION_Y_PADDING,o as classNames,k as generateCitationInstanceId,i as generateCitationKey,l as getCitationDisplayText,n as getCitationKeySpanText,m as getCitationNumber}from'../chunk-ETIDLMKZ.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 ue(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e.replace(/^https?:\/\/(www\.)?/,"").split("/")[0]}}function Ce(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 Ne(e){return e.startsWith("blocked_")}function Pe(e){return e.startsWith("error_")}function rt(e){return e==="verified"||e==="partial"}var ot=({status:e,errorMessage:t})=>{let n=ke[e];return jsx("span",{className:o("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})})},ce=({url:e,faviconUrl:t})=>{let n=ue(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,className:r,variant:a="chip",showFullUrlOnHover:o$1=true,showFavicon:i$1=true,showTitle:c=false,maxDisplayLength:l=30,renderBlockedIndicator:d,onUrlClick:u,eventHandlers:p,preventTooltips:f=false},N)=>{let{url:x,domain:W,title:P,fetchStatus:b,faviconUrl:w,errorMessage:B}=e,v=useMemo(()=>t||{value:x,fullPhrase:P||x},[t,x,P]),g=useMemo(()=>i(v),[v]),G=useMemo(()=>k(g),[g]),S=useMemo(()=>W||ue(x),[W,x]),E=useMemo(()=>at(x),[x]),D=useMemo(()=>{if(c&&P)return Ce(P,l);let C=E?Ce(E,l-S.length-1):"";return C?`${S}${C}`:S},[c,P,S,E,l]),M=ke[b],$=Ne(b),ae=Pe(b),re=b==="verified",X=b==="partial",T=b==="pending",z=useCallback(C=>{C.preventDefault(),C.stopPropagation(),u?u(x,C):window.open(x,"_blank","noopener,noreferrer"),p?.onClick?.(v,g,C);},[u,x,p,v,g]),y=useCallback(()=>{p?.onMouseEnter?.(v,g);},[p,v,g]),_=useCallback(()=>{p?.onMouseLeave?.(v,g);},[p,v,g]),L=()=>$||ae?d?d(b,B):jsx(ot,{status:b,errorMessage:B}):re?jsx("span",{className:"text-[0.85em] text-green-600 dark:text-green-500","aria-hidden":"true",title:"Verified",children:"\u2713"}):X?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,jsxs("span",{ref:N,"data-citation-id":g,"data-citation-instance":G,"data-url":x,"data-fetch-status":b,"data-variant":"chip",className:o("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",M.className,r),title:o$1?x:void 0,onMouseEnter:f?void 0:y,onMouseLeave:f?void 0:_,onMouseDown:z,onClick:C=>C.stopPropagation(),role:"link","aria-label":`Link to ${S}: ${M.label}`,children:[i$1&&jsx(ce,{url:x,faviconUrl:w}),jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:D}),L()]})]}):a==="inline"?jsxs(Fragment,{children:[n,jsxs("a",{ref:N,href:x,"data-citation-id":g,"data-citation-instance":G,"data-fetch-status":b,"data-variant":"inline",className:o("inline-flex items-center gap-1 cursor-pointer transition-colors no-underline border-b border-dotted border-current",M.className,r),title:o$1?x:void 0,onMouseEnter:f?void 0:y,onMouseLeave:f?void 0:_,onClick:C=>{C.preventDefault(),z(C);},target:"_blank",rel:"noopener noreferrer","aria-label":`Link to ${S}: ${M.label}`,children:[i$1&&jsx(ce,{url:x,faviconUrl:w}),jsx("span",{children:D}),L()]})]}):jsxs(Fragment,{children:[n,jsxs("span",{ref:N,"data-citation-id":g,"data-citation-instance":G,"data-url":x,"data-fetch-status":b,"data-variant":"bracket",className:o("cursor-pointer transition-colors",M.className,r),title:o$1?x:void 0,onMouseEnter:f?void 0:y,onMouseLeave:f?void 0:_,onMouseDown:z,onClick:C=>C.stopPropagation(),role:"link","aria-label":`Link to ${S}: ${M.label}`,children:["[",i$1&&jsx(ce,{url:x,faviconUrl:w}),jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:D}),L(),"]"]})]})});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:h("w-[10px] h-[10px]",e),viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:jsx("polyline",{points:"20 6 9 17 4 12"})}),ee=({className:e})=>jsx("svg",{className:h("w-[10px] h-[10px]",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"})}),te=({className:e})=>jsxs("svg",{className:h("w-[10px] h-[10px] 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 pe=Ie.forwardRef(({className:e,align:t="center",sideOffset:n=8,...r},a)=>jsx(R.Portal,{children:jsx(R.Content,{ref:a,align:t,sideOffset:n,className:st("z-50 w-auto rounded-lg border bg-white shadow-xl outline-none","max-w-[min(600px,calc(100vw-2rem))]","border-gray-200 dark:border-gray-700 dark:bg-gray-900","data-[state=open]:animate-in data-[state=closed]:animate-out","data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0","data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95","data-[side=bottom]:slide-in-from-top-2","data-[side=left]:slide-in-from-right-2","data-[side=right]:slide-in-from-left-2","data-[side=top]:slide-in-from-bottom-2",e),...r})}));pe.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 c=e.slice(o,r-i),l=t.slice(o,a-i);if(c.length===0&&l.length===0)return [{value:e.join(""),count:e.length}];let d=lt(c,l,n),u=[];return o>0&&u.push({value:e.slice(0,o).join(""),count:o}),u.push(...d),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},c=[];e:for(let l=0;l<=o;l++){c.push({...i});for(let d=-l;d<=l;d+=2){let u;d===-l||d!==l&&i[d-1]<i[d+1]?u=i[d+1]:u=i[d-1]+1;let p=u-d;for(;u<r&&p<a&&n(e[u],t[p]);)u++,p++;if(i[d]=u,u>=r&&p>=a)break e}}return ct(c,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 c=e[i],l=a-o,d;l===-i||l!==i&&c[l-1]<c[l+1]?d=l+1:d=l-1;let u=c[d]??0,p=u-d;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 me(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],c=Be(a.value,o.value).match(/^\s*/)?.[0]||"",l=a.value.slice(c.length),d=o.value.slice(c.length),p=me(l,d).match(/\s*$/)?.[0]||"";c&&t.push({value:c,count:1});let f=a.value.slice(c.length,a.value.length-p.length),N=o.value.slice(c.length,o.value.length-p.length);f&&t.push({value:f,removed:true,count:1}),N&&t.push({value:N,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 c=me(i,o);if(c){t.push({value:r.value.slice(c.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]||"",c=r.value.match(/\s*$/)?.[0]||"",l=a.value.match(/\s*$/)?.[0]||"",d=o.value.match(/^\s*/)?.[0]||"";if(i&&l&&me(l,i).length===i.length){t.push({value:r.value.slice(i.length),removed:true,count:1});continue}if(c&&d&&Be(c,d).length===c.length){t.push({value:r.value.slice(0,-c.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 Ae(e,t){let n=Re(e),r=Re(t),a=Ve(n,r);return ut(a)}var We=(e="",t="")=>useMemo(()=>{let n=(e||"").trim().replace(/\r\n/g,`
|
|
3
3
|
`),r=(t||"").trim().replace(/\r\n/g,`
|
|
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:h("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$1="brackets",content:d,eventHandlers:s,behaviorConfig:l,isMobile:u=false,renderIndicator:p,renderContent:h$1,popoverPosition:P="top",renderPopoverContent:g},A)=>{let N=useMemo(()=>d||xt(i$1),[d,i$1]),[C,w]=useState(false),[B,v]=useState(null),m=useMemo(()=>i(e),[e]),K=useMemo(()=>k(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:h("text-gray-400 dark:text-gray-500",n),children:r});let ae=h((S||D)&&i$1==="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$1==="chip"){let x=h(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:h("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$1==="superscript"){let x=h(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:h("text-xs font-medium transition-colors hover:underline",x),children:["[",E,z(),"]"]})}return i$1==="text"?jsxs("span",{className:ae,children:[E,z()]}):i$1==="minimal"?jsxs("span",{className:h("max-w-80 overflow-hidden text-ellipsis",ae),children:[E,z()]}):jsxs("span",{className:h("inline-flex items-baseline gap-0.5 whitespace-nowrap","font-mono text-xs leading-tight","text-gray-500 dark:text-gray-400","transition-colors"),"aria-hidden":"true",children:["[",jsxs("span",{className:h("max-w-80 overflow-hidden text-ellipsis",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:h("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?g({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};
|
|
4
|
+
`),a=Ue(n,r),o=[],i=false,c=0;for(let u=0;u<a.length;u++){let p=a[u],f=a[u+1];if(p.removed&&f&&f.added){let N=Ae(p.value,f.value);o.push({type:"modified",parts:N}),i=true,c+=Math.abs(p.value.length-f.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,c+=p.value.length):o.push({type:"unchanged",parts:[{value:p.value}]});}let l=Math.max(n.length,r.length),d=l===0?1:1-c/l;return {diffResult:o,hasDiff:i,similarity:d,isHighVariance:d<.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 bt(e){return e.isVerified&&!e.isPartialMatch?"Verified":e.isPartialMatch?"Partial Match":e.isMiss?"Not Found":e.isPending?"Verifying...":""}function yt(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 Ct({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 duration-[50ms]",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 animate-in zoom-in-95 duration-[50ms]",children:jsx("img",{src:e,alt:t,className:"max-w-full max-h-[95vh] object-contain rounded-lg shadow-2xl",draggable:false})})}),document.body)}var kt=()=>jsx("span",{className:"inline-flex relative ml-0.5 text-green-600 dark:text-green-500","aria-hidden":"true",children:jsx(Q,{})}),Nt=()=>jsx("span",{className:"inline-flex relative ml-0.5 text-amber-600 dark:text-amber-500","aria-hidden":"true",children:jsx(Q,{})}),Pt=()=>jsx("span",{className:"inline-flex ml-1 text-gray-400 dark:text-gray-500","aria-hidden":"true",children:jsx(te,{})}),wt=()=>jsx("span",{className:"inline-flex relative ml-0.5 text-red-500 dark:text-red-400","aria-hidden":"true",children:jsx(ee,{})});function St({citation:e,verification:t}){let n=useMemo(()=>{let c=new Set;if(t?.searchAttempts){for(let l of t.searchAttempts)if(l.searchPhrases)for(let d of l.searchPhrases)d&&c.add(d);}return c.size===0&&(e.fullPhrase&&c.add(e.fullPhrase),e.keySpan&&c.add(e.keySpan.toString())),Array.from(c)},[e,t]),[r,a]=useState(false);if(n.length===0)return null;let o=r?n.length:1,i=n.length-1;return jsxs("div",{className:"mt-2",children:[jsxs("div",{className:"flex items-center gap-2 text-[10px] text-gray-500 dark:text-gray-400 uppercase font-medium",children:[jsxs("span",{children:["Searched ",n.length," phrase",n.length!==1?"s":""]}),i>0&&!r&&jsxs("button",{type:"button",onClick:()=>a(true),className:"text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300 lowercase",children:["+",i," more"]}),r&&i>0&&jsx("button",{type:"button",onClick:()=>a(false),className:"text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300 lowercase",children:"collapse"})]}),jsx("div",{className:"mt-1 space-y-1",children:n.slice(0,o).map((c,l)=>jsxs("p",{className:"p-2 bg-gray-100 dark:bg-gray-800 rounded font-mono text-[11px] break-words text-gray-700 dark:text-gray-300 border-l-2 border-red-400 dark:border-red-500",children:['"',c.length>80?c.slice(0,80)+"\u2026":c,'"']},l))})]})}function Mt({citation:e,verification:t,status:n,onImageClick:r,isLoading:a=false}){let o=t?.verificationImageBase64,{isMiss:i,isPartialMatch:c,isPending:l}=n;if(o)return jsxs("div",{className:"p-2",children:[jsxs("button",{type:"button",className:"group block cursor-zoom-in relative",onClick:f=>{f.preventDefault(),f.stopPropagation(),r?.();},"aria-label":"Click to view full size",children:[jsx("img",{src:t.verificationImageBase64,alt:"Citation verification",className:"max-w-full h-auto object-contain rounded-md bg-gray-50 dark:bg-gray-800",loading:"lazy"}),jsx("span",{className:"absolute inset-0 flex items-center justify-center bg-black/0 group-hover:bg-black/5 dark:group-hover:bg-white/5 transition-colors rounded-md",children:jsx("span",{className:"opacity-0 group-hover:opacity-100 transition-opacity text-xs text-gray-600 dark:text-gray-300 bg-white/90 dark:bg-gray-800/90 px-2 py-1 rounded shadow-sm",children:"Click to expand"})})]}),(i||c)&&jsx(ze,{citation:e,verification:t,status:n})]});if(a||l){let f=e.fullPhrase||e.keySpan?.toString();return jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[200px] max-w-[400px]",children:[jsxs("span",{className:"text-xs font-medium text-gray-500 dark:text-gray-400",children:[jsx(te,{className:"inline-block relative top-[0.1em] mr-1.5"}),"Searching..."]}),f&&jsxs("p",{className:"p-2 bg-gray-100 dark:bg-gray-800 rounded font-mono text-[11px] break-words text-gray-600 dark:text-gray-400 italic",children:['"',f.length>80?f.slice(0,80)+"\u2026":f,'"']}),e.pageNumber&&e.pageNumber>0&&jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Looking on page ",e.pageNumber]})]})}if(i)return jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[200px] max-w-[400px]",children:[jsxs("span",{className:"text-xs font-medium text-red-600 dark:text-red-500",children:[jsx(ee,{className:"inline-block relative top-[0.1em] mr-1.5"}),"Not found in source"]}),jsx(St,{citation:e,verification:t})]});let d=bt(n),u=t?.verifiedMatchSnippet,p=t?.verifiedPageNumber;return !u&&!d?null:jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[180px] max-w-full",children:[d&&jsx("span",{className:h("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}),u&&jsxs("span",{className:"text-sm text-gray-700 dark:text-gray-300 italic",children:['"',t.verifiedMatchSnippet,'"']}),p&&p>0&&jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Page ",p]}),(i||c)&&jsx(ze,{citation:e,verification:t,status:n})]})}function ze({citation:e,verification:t,status:n}){let{isMiss:r,isPartialMatch:a}=n,o=e.fullPhrase||e.keySpan?.toString()||"",i=t?.verifiedMatchSnippet||"",{diffResult:c,hasDiff:l,isHighVariance:d}=We(o,i);if(!r&&!a)return null;let u=e.lineIds,p=t?.verifiedLineIds,f=u&&p&&JSON.stringify(u)!==JSON.stringify(p),N=e.pageNumber,x=t?.verifiedPageNumber,W=N!=null&&x!=null&&N!==x;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&&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:d?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})]})]}):c.map((P,b)=>jsx("span",{children:P.parts.map((w,B)=>{let v=`p-${b}-${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-${b}`))})]}):o&&!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:o.length>100?o.slice(0,100)+"\u2026":o})]}):null,W&&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:N})," \u2192 ",x]})]}),f&&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$1="brackets",content:c,eventHandlers:l,behaviorConfig:d,isMobile:u=false,renderIndicator:p,renderContent:f,popoverPosition:N="top",renderPopoverContent:x},W)=>{let P=useMemo(()=>c||xt(i$1),[c,i$1]),[b,w]=useState(false),[B,v]=useState(null),g=useMemo(()=>i(e),[e]),G=useMemo(()=>k(g),[g]),S=useMemo(()=>yt(a),[a]),{isMiss:E,isPartialMatch:D,isVerified:M,isPending:$}=S,ae=5e3,[re,X]=useState(false),T=useRef(null),z=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&&!re;useEffect(()=>(T.current&&(clearTimeout(T.current),T.current=null),(o||$)&&!z?(X(false),T.current=setTimeout(()=>{X(true);},ae)):X(false),()=>{T.current&&clearTimeout(T.current);}),[o,$,z]);let _=useMemo(()=>vt(e,P,r),[e,P,r]),L=useCallback(()=>({citation:e,citationKey:g,verification:a??null,isTooltipExpanded:b,isImageExpanded:!!B,hasImage:!!a?.verificationImageBase64}),[e,g,a,b,B]),C=useCallback(h=>{h.setImageExpanded!==void 0&&(typeof h.setImageExpanded=="string"?v(h.setImageExpanded):h.setImageExpanded===true&&a?.verificationImageBase64?v(a.verificationImageBase64):h.setImageExpanded===false&&v(null));},[a?.verificationImageBase64]),$e=useCallback(h=>{h.preventDefault(),h.stopPropagation();let Y=L();if(d?.onClick){let se=d.onClick(Y,h);se&&typeof se=="object"&&C(se),l?.onClick?.(e,g,h);return}if(l?.onClick){l.onClick(e,g,h);return}a?.verificationImageBase64&&v(a.verificationImageBase64);},[d,l,e,g,a?.verificationImageBase64,L,C]),he=150,O=useRef(null),oe=useRef(false),U=useCallback(()=>{O.current&&(clearTimeout(O.current),O.current=null);},[]),je=useCallback(()=>{U(),w(true),d?.onHover?.onEnter&&d.onHover.onEnter(L()),l?.onMouseEnter?.(e,g);},[l,d,e,g,L,U]),Fe=useCallback(()=>{U(),O.current=setTimeout(()=>{oe.current||(w(false),d?.onHover?.onLeave&&d.onHover.onLeave(L()),l?.onMouseLeave?.(e,g));},he);},[l,d,e,g,L,U]),He=useCallback(()=>{U(),oe.current=true;},[U]),Ke=useCallback(()=>{oe.current=false,U(),O.current=setTimeout(()=>{w(false),d?.onHover?.onLeave&&d.onHover.onLeave(L()),l?.onMouseLeave?.(e,g);},he);},[l,d,e,g,L,U]);useEffect(()=>()=>{O.current&&clearTimeout(O.current);},[]);let Ze=useCallback(h=>{u&&(h.preventDefault(),h.stopPropagation(),l?.onTouchEnd?.(e,g,h));},[l,e,g,u]);if(r!=null&&P==="keySpan"&&E)return jsx("span",{className:h("text-gray-400 dark:text-gray-500",n),children:r});let ie=h((M||D)&&i$1==="brackets"&&"text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 hover:underline",E&&"opacity-70 line-through text-gray-400 dark:text-gray-500",y&&"text-gray-500 dark:text-gray-400"),j=()=>p?p(S):y?jsx(Pt,{}):M&&!D?jsx(kt,{}):D?jsx(Nt,{}):E?jsx(wt,{}):null,ve=()=>{if(f)return f({citation:e,status:S,citationKey:g,displayText:_,isMergedDisplay:P==="keySpan"});if(P==="indicator")return jsx("span",{children:j()});if(i$1==="chip"){let h$1=h(M&&!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",E&&!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",!M&&!E&&!y&&"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400");return jsxs("span",{className:h("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-sm font-medium",h$1),children:[jsx("span",{className:"max-w-60 overflow-hidden text-ellipsis whitespace-nowrap",children:_}),j()]})}if(i$1==="superscript"){let h$1=h(M&&!D&&!y&&"text-green-600 dark:text-green-500",D&&!y&&"text-amber-600 dark:text-amber-500",E&&!y&&"text-red-500 dark:text-red-400 line-through",y&&"text-gray-400 dark:text-gray-500",!M&&!E&&!y&&"text-blue-600 dark:text-blue-400");return jsxs("sup",{className:h("text-xs font-medium transition-colors hover:underline",h$1),children:["[",_,j(),"]"]})}return i$1==="text"?jsxs("span",{className:ie,children:[_,j()]}):i$1==="minimal"?jsxs("span",{className:h("max-w-80 overflow-hidden text-ellipsis",ie),children:[_,j()]}):jsxs("span",{className:h("inline-flex items-baseline gap-0.5 whitespace-nowrap","font-mono text-xs leading-tight","text-gray-500 dark:text-gray-400","transition-colors"),"aria-hidden":"true",children:["[",jsxs("span",{className:h("max-w-80 overflow-hidden text-ellipsis",ie),children:[_,j()]}),"]"]})},Ge=!(N==="hidden")&&(a&&(a.verificationImageBase64||a.verifiedMatchSnippet)||y||$||o||E),Xe=!!a?.verificationImageBase64,be=B?jsx(Ct,{src:B,alt:"Citation verification - full size",onClose:()=>v(null)}):null,ye={"data-citation-id":g,"data-citation-instance":G,className:h("relative inline-flex items-baseline cursor-pointer","px-0.5 -mx-0.5 rounded-sm","transition-all duration-[50ms]","hover:bg-blue-500/10 dark:hover:bg-blue-400/10",Xe&&"cursor-zoom-in",n),onMouseEnter:je,onMouseLeave:Fe,onClick:$e,onTouchEndCapture:u?Ze:void 0,"aria-label":_?`[${_}]`:void 0};if(Ge){let h=x?x({citation:e,verification:a??null,status:S}):jsx(Mt,{citation:e,verification:a??null,status:S,isLoading:o||y,onImageClick:()=>{a?.verificationImageBase64&&v(a.verificationImageBase64);}});return jsxs(Fragment,{children:[t,jsxs(Ee,{open:b,children:[jsx(_e,{asChild:true,children:jsx("span",{ref:W,...ye,children:ve()})}),jsx(pe,{side:N==="bottom"?"bottom":"top",onPointerDownOutside:Y=>Y.preventDefault(),onInteractOutside:Y=>Y.preventDefault(),onMouseEnter:He,onMouseLeave:Ke,children:h})]}),be]})}return jsxs(Fragment,{children:[t,jsx("span",{ref:W,...ye,children:ve()}),be]})});xe.displayName="CitationComponent";var It=memo(xe);export{Q as CheckIcon,xe as CitationComponent,it as DeepCitationIcon,It as MemoizedCitationComponent,te as SpinnerIcon,ee as WarningIcon,ue as extractDomain,Ne as isBlockedStatus,Pe as isErrorStatus,rt as isVerifiedStatus};
|
package/package.json
CHANGED
package/lib/chunk-67NZP2UZ.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import {i,t}from'./chunk-ETIDLMKZ.js';import {a}from'./chunk-O2XFH626.js';var F="https://api.deepcitation.com";function C(p,t){if(typeof Buffer<"u"&&Buffer.isBuffer(p)){let e=Uint8Array.from(p);return {blob:new Blob([e]),name:t||"document"}}if(p instanceof Blob)return {blob:p,name:t||(p instanceof File?p.name:"document")};throw new Error("Invalid file type. Expected File, Blob, or Buffer.")}async function m(p,t){return (await p.json().catch(()=>({})))?.error?.message||`${t} failed with status ${p.status}`}var h=class{constructor(t){a(this,"apiKey");a(this,"apiUrl");if(!t.apiKey)throw new Error("DeepCitation API key is required. Get one at https://deepcitation.com/dashboard");this.apiKey=t.apiKey,this.apiUrl=t.apiUrl?.replace(/\/$/,"")||F;}async uploadFile(t,e){let{blob:l,name:n}=C(t,e?.filename),o=new FormData;o.append("file",l,n),e?.attachmentId&&o.append("attachmentId",e.attachmentId),e?.filename&&o.append("filename",e.filename);let i=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:o});if(!i.ok)throw new Error(await m(i,"Upload"));return await i.json()}async convertToPdf(t){let e=typeof t=="string"?{url:t}:t,{url:l,file:n,filename:o,attachmentId:i}=e;if(!l&&!n)throw new Error("Either url or file must be provided");let r;if(l)r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({url:l,filename:o,attachmentId:i})});else {let{blob:f,name:a}=C(n,o),s=new FormData;s.append("file",f,a),i&&s.append("attachmentId",i),o&&s.append("filename",o),r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:s});}if(!r.ok)throw new Error(await m(r,"Conversion"));return await r.json()}async prepareConvertedFile(t){let e=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({attachmentId:t.attachmentId})});if(!e.ok)throw new Error(await m(e,"Prepare"));return await e.json()}async prepareFiles(t){if(t.length===0)return {fileDataParts:[],deepTextPromptPortion:[]};let e=t.map(({file:i,filename:r,attachmentId:f})=>this.uploadFile(i,{filename:r,attachmentId:f}).then(a=>({result:a,filename:r}))),n=(await Promise.all(e)).map(({result:i,filename:r})=>({attachmentId:i.attachmentId,deepTextPromptPortion:i.deepTextPromptPortion,filename:r||i.metadata?.filename})),o=n.map(i=>i.deepTextPromptPortion);return {fileDataParts:n,deepTextPromptPortion:o}}async verifyCitations(t,e,l){let n={};if(Array.isArray(e))for(let a of e){let s=i(a);n[s]=a;}else if(typeof e=="object"&&e!==null)if("fullPhrase"in e||"value"in e){let a=i(e);n[a]=e;}else Object.assign(n,e);else throw new Error("Invalid citations format");let o=`${this.apiUrl}/verifyCitations`,i$1={data:{attachmentId:t,citations:n,outputImageFormat:l?.outputImageFormat||"avif"}},r=await fetch(o,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(i$1)});if(!r.ok)throw new Error(await m(r,"Verification"));return await r.json()}async verifyCitationsFromLlmOutput(t$1,e){let{llmOutput:l,outputImageFormat:n="avif"}=t$1;if(e||(e=t(l)),Object.keys(e).length===0)return {verifications:{}};let o=new Map;for(let[a,s]of Object.entries(e)){let c=s.attachmentId||"";o.has(c)||o.set(c,{}),o.get(c)[a]=s;}let i=[];for(let[a,s]of o)a&&i.push(this.verifyCitations(a,s,{outputImageFormat:n}));let r=await Promise.all(i),f={};for(let a of r)Object.assign(f,a.verifications);return {verifications:f}}};
|
|
2
|
-
export{h as a};
|
package/lib/chunk-CQF2MESM.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use strict';var chunk4HRWJSX6_cjs=require('./chunk-4HRWJSX6.cjs'),chunkF2MMVEVC_cjs=require('./chunk-F2MMVEVC.cjs');var F="https://api.deepcitation.com";function C(p,t){if(typeof Buffer<"u"&&Buffer.isBuffer(p)){let e=Uint8Array.from(p);return {blob:new Blob([e]),name:t||"document"}}if(p instanceof Blob)return {blob:p,name:t||(p instanceof File?p.name:"document")};throw new Error("Invalid file type. Expected File, Blob, or Buffer.")}async function m(p,t){return (await p.json().catch(()=>({})))?.error?.message||`${t} failed with status ${p.status}`}var h=class{constructor(t){chunkF2MMVEVC_cjs.a(this,"apiKey");chunkF2MMVEVC_cjs.a(this,"apiUrl");if(!t.apiKey)throw new Error("DeepCitation API key is required. Get one at https://deepcitation.com/dashboard");this.apiKey=t.apiKey,this.apiUrl=t.apiUrl?.replace(/\/$/,"")||F;}async uploadFile(t,e){let{blob:l,name:n}=C(t,e?.filename),o=new FormData;o.append("file",l,n),e?.attachmentId&&o.append("attachmentId",e.attachmentId),e?.filename&&o.append("filename",e.filename);let i=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:o});if(!i.ok)throw new Error(await m(i,"Upload"));return await i.json()}async convertToPdf(t){let e=typeof t=="string"?{url:t}:t,{url:l,file:n,filename:o,attachmentId:i}=e;if(!l&&!n)throw new Error("Either url or file must be provided");let r;if(l)r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({url:l,filename:o,attachmentId:i})});else {let{blob:f,name:a}=C(n,o),s=new FormData;s.append("file",f,a),i&&s.append("attachmentId",i),o&&s.append("filename",o),r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:s});}if(!r.ok)throw new Error(await m(r,"Conversion"));return await r.json()}async prepareConvertedFile(t){let e=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({attachmentId:t.attachmentId})});if(!e.ok)throw new Error(await m(e,"Prepare"));return await e.json()}async prepareFiles(t){if(t.length===0)return {fileDataParts:[],deepTextPromptPortion:[]};let e=t.map(({file:i,filename:r,attachmentId:f})=>this.uploadFile(i,{filename:r,attachmentId:f}).then(a=>({result:a,filename:r}))),n=(await Promise.all(e)).map(({result:i,filename:r})=>({attachmentId:i.attachmentId,deepTextPromptPortion:i.deepTextPromptPortion,filename:r||i.metadata?.filename})),o=n.map(i=>i.deepTextPromptPortion);return {fileDataParts:n,deepTextPromptPortion:o}}async verifyCitations(t,e,l){let n={};if(Array.isArray(e))for(let a of e){let s=chunk4HRWJSX6_cjs.i(a);n[s]=a;}else if(typeof e=="object"&&e!==null)if("fullPhrase"in e||"value"in e){let a=chunk4HRWJSX6_cjs.i(e);n[a]=e;}else Object.assign(n,e);else throw new Error("Invalid citations format");let o=`${this.apiUrl}/verifyCitations`,i={data:{attachmentId:t,citations:n,outputImageFormat:l?.outputImageFormat||"avif"}},r=await fetch(o,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(!r.ok)throw new Error(await m(r,"Verification"));return await r.json()}async verifyCitationsFromLlmOutput(t,e){let{llmOutput:l,outputImageFormat:n="avif"}=t;if(e||(e=chunk4HRWJSX6_cjs.t(l)),Object.keys(e).length===0)return {verifications:{}};let o=new Map;for(let[a,s]of Object.entries(e)){let c=s.attachmentId||"";o.has(c)||o.set(c,{}),o.get(c)[a]=s;}let i=[];for(let[a,s]of o)a&&i.push(this.verifyCitations(a,s,{outputImageFormat:n}));let r=await Promise.all(i),f={};for(let a of r)Object.assign(f,a.verifications);return {verifications:f}}};
|
|
2
|
-
exports.a=h;
|