@deepcitation/deepcitation-js 1.1.22 → 1.1.23

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.
@@ -1,7 +1,6 @@
1
1
  import React, { type ReactNode } from "react";
2
2
  import type { CitationStatus } from "../types/citation.js";
3
3
  import type { Verification } from "../types/verification.js";
4
- import type { SearchState } from "../types/search.js";
5
4
  import type { BaseCitationProps, CitationVariant as CitationVariantType, CitationEventHandlers } from "./types.js";
6
5
  /**
7
6
  * Shared props for all citation variant components.
@@ -9,8 +8,6 @@ import type { BaseCitationProps, CitationVariant as CitationVariantType, Citatio
9
8
  export interface CitationVariantProps extends BaseCitationProps {
10
9
  /** Found citation highlight location data */
11
10
  verification?: Verification | null;
12
- /** Current search state for the citation */
13
- searchState?: SearchState | null;
14
11
  /** Event handlers */
15
12
  eventHandlers?: CitationEventHandlers;
16
13
  /** Whether on mobile device */
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Popover component built on Radix UI primitives.
3
+ * This is a shadcn-style component - copy/paste friendly.
4
+ *
5
+ * @see https://ui.shadcn.com/docs/components/popover
6
+ * @see https://www.radix-ui.com/primitives/docs/components/popover
7
+ */
8
+ import * as React from "react";
9
+ import * as PopoverPrimitive from "@radix-ui/react-popover";
10
+ declare const Popover: React.FC<PopoverPrimitive.PopoverProps>;
11
+ declare const PopoverTrigger: React.ForwardRefExoticComponent<PopoverPrimitive.PopoverTriggerProps & React.RefAttributes<HTMLButtonElement>>;
12
+ declare const PopoverAnchor: React.ForwardRefExoticComponent<PopoverPrimitive.PopoverAnchorProps & React.RefAttributes<HTMLDivElement>>;
13
+ declare const PopoverPortal: React.FC<PopoverPrimitive.PopoverPortalProps>;
14
+ declare const PopoverContent: React.ForwardRefExoticComponent<Omit<PopoverPrimitive.PopoverContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
15
+ export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor, PopoverPortal };
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Popover component built on Radix UI primitives.
4
+ * This is a shadcn-style component - copy/paste friendly.
5
+ *
6
+ * @see https://ui.shadcn.com/docs/components/popover
7
+ * @see https://www.radix-ui.com/primitives/docs/components/popover
8
+ */
9
+ import * as React from "react";
10
+ import * as PopoverPrimitive from "@radix-ui/react-popover";
11
+ function cn(...classes) {
12
+ return classes.filter(Boolean).join(" ");
13
+ }
14
+ const Popover = PopoverPrimitive.Root;
15
+ const PopoverTrigger = PopoverPrimitive.Trigger;
16
+ const PopoverAnchor = PopoverPrimitive.Anchor;
17
+ const PopoverPortal = PopoverPrimitive.Portal;
18
+ const PopoverContent = React.forwardRef(({ className, align = "center", sideOffset = 4, ...props }, ref) => (_jsx(PopoverPrimitive.Portal, { children: _jsx(PopoverPrimitive.Content, { ref: ref, align: align, sideOffset: sideOffset, className: cn("z-50 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", className), ...props }) })));
19
+ PopoverContent.displayName = PopoverPrimitive.Content.displayName;
20
+ export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor, PopoverPortal };
@@ -5,14 +5,12 @@
5
5
  import React, { type ReactNode, type HTMLAttributes, type MouseEvent, type TouchEvent } from "react";
6
6
  import type { Citation as CitationType, CitationStatus } from "../types/citation.js";
7
7
  import type { Verification } from "../types/verification.js";
8
- import type { SearchState } from "../types/search.js";
9
8
  interface CitationContextValue {
10
9
  citation: CitationType;
11
10
  citationKey: string;
12
11
  citationInstanceId: string;
13
12
  status: CitationStatus;
14
13
  verification: Verification | null;
15
- searchState: SearchState | null;
16
14
  config: {
17
15
  hideKeySpan: boolean;
18
16
  fallbackDisplay: string | null;
@@ -26,7 +24,6 @@ export declare function useCitationContextSafe(): CitationContextValue | null;
26
24
  export interface CitationRootProps {
27
25
  citation: CitationType;
28
26
  verification?: Verification | null;
29
- searchState?: SearchState | null;
30
27
  children: ReactNode;
31
28
  hideKeySpan?: boolean;
32
29
  fallbackDisplay?: string | null;
@@ -20,7 +20,7 @@ export function useCitationContextSafe() {
20
20
  return useContext(CitationContext);
21
21
  }
22
22
  /** Root component that provides citation context to all child primitives. */
23
- export const CitationRoot = forwardRef(({ citation, verification = null, searchState = null, children, hideKeySpan = false, fallbackDisplay = null, pendingContent = "..", className, ...props }, ref) => {
23
+ export const CitationRoot = forwardRef(({ citation, verification = null, children, hideKeySpan = false, fallbackDisplay = null, pendingContent = "..", className, ...props }, ref) => {
24
24
  const citationKey = useMemo(() => generateCitationKey(citation), [citation]);
25
25
  const citationInstanceId = useMemo(() => generateCitationInstanceId(citationKey), [citationKey]);
26
26
  const status = getCitationStatus(verification);
@@ -30,7 +30,6 @@ export const CitationRoot = forwardRef(({ citation, verification = null, searchS
30
30
  citationInstanceId,
31
31
  status,
32
32
  verification,
33
- searchState,
34
33
  config: {
35
34
  hideKeySpan,
36
35
  fallbackDisplay,
@@ -42,7 +41,6 @@ export const CitationRoot = forwardRef(({ citation, verification = null, searchS
42
41
  citationInstanceId,
43
42
  status,
44
43
  verification,
45
- searchState,
46
44
  hideKeySpan,
47
45
  fallbackDisplay,
48
46
  pendingContent,
@@ -1,6 +1,6 @@
1
1
  import type { Citation, CitationStatus } from "../types/citation.js";
2
2
  import type { Verification } from "../types/verification.js";
3
- import type { SearchState } from "../types/search.js";
3
+ import type { SearchStatus } from "../types/search.js";
4
4
  /**
5
5
  * Available citation display variants.
6
6
  *
@@ -135,8 +135,8 @@ export interface CitationContentProps extends BaseCitationProps {
135
135
  citationInstanceId: string;
136
136
  /** Found citation highlight data */
137
137
  verification: Verification | null | undefined;
138
- /** Current search state */
139
- searchState: SearchState | undefined | null;
138
+ /** Search status */
139
+ searchStatus: SearchStatus | undefined | null;
140
140
  /** Actual page number where citation was found */
141
141
  actualPageNumber?: number | null;
142
142
  /** Page number from citation data */
@@ -279,6 +279,5 @@ export interface CitationTooltipProps {
279
279
  children: React.ReactNode;
280
280
  citation: Citation;
281
281
  verification?: Verification | null;
282
- searchState?: SearchState | null;
283
282
  shouldShowTooltip: boolean;
284
283
  }
@@ -1,9 +1,17 @@
1
1
  import type { Citation } from "../types/citation.js";
2
+ import type { Verification } from "../types/verification.js";
2
3
  /**
3
4
  * Generates a unique, deterministic key for a citation based on its content.
4
- * Uses a hash of the citation's identifying properties.
5
+ * @param citation - The citation to generate a key for
6
+ * @returns A unique, deterministic key for the citation
5
7
  */
6
8
  export declare function generateCitationKey(citation: Citation): string;
9
+ /**
10
+ * Generates a unique, deterministic key for a verification based on its content.
11
+ * @param verification - The verification to generate a key for
12
+ * @returns
13
+ */
14
+ export declare function generateVerificationKey(verification: Verification): string;
7
15
  /**
8
16
  * Generates a unique instance ID for a citation component render.
9
17
  * Combines the citation key with a random suffix for uniqueness.
@@ -2,7 +2,8 @@ import { sha1Hash } from "../utils/sha.js";
2
2
  import { getCitationPageNumber } from "../parsing/normalizeCitation.js";
3
3
  /**
4
4
  * Generates a unique, deterministic key for a citation based on its content.
5
- * Uses a hash of the citation's identifying properties.
5
+ * @param citation - The citation to generate a key for
6
+ * @returns A unique, deterministic key for the citation
6
7
  */
7
8
  export function generateCitationKey(citation) {
8
9
  const pageNumber = citation.pageNumber || getCitationPageNumber(citation.startPageKey);
@@ -17,6 +18,26 @@ export function generateCitationKey(citation) {
17
18
  ];
18
19
  return sha1Hash(keyParts.join("|")).slice(0, 16);
19
20
  }
21
+ /**
22
+ * Generates a unique, deterministic key for a verification based on its content.
23
+ * @param verification - The verification to generate a key for
24
+ * @returns
25
+ */
26
+ export function generateVerificationKey(verification) {
27
+ const keyParts = [
28
+ verification.attachmentId || "",
29
+ verification.label || "",
30
+ verification.verifiedFullPhrase || "",
31
+ verification.verifiedKeySpan || "",
32
+ verification.verifiedLineIds?.join(",") || "",
33
+ verification.verifiedPageNumber?.toString() || "",
34
+ verification.verifiedTimestamps?.startTime || "",
35
+ verification.verifiedTimestamps?.endTime || "",
36
+ verification.verifiedMatchSnippet || "",
37
+ verification.hitIndexWithinPage?.toString() || "",
38
+ ];
39
+ return sha1Hash(keyParts.join("|")).slice(0, 16);
40
+ }
20
41
  /**
21
42
  * Generates a unique instance ID for a citation component render.
22
43
  * Combines the citation key with a random suffix for uniqueness.
@@ -7,5 +7,5 @@ export type { Citation, CitationStatus, VerifyCitationRequest, VerifyCitationRes
7
7
  export { DEFAULT_OUTPUT_IMAGE_FORMAT } from "./citation.js";
8
8
  export type { Verification } from "./verification.js";
9
9
  export { NOT_FOUND_VERIFICATION_INDEX, PENDING_VERIFICATION_INDEX, BLANK_VERIFICATION, } from "./verification.js";
10
- export type { SearchState, SearchStatus } from "./search.js";
10
+ export type { SearchStatus, SearchMethod, SearchAttempt } from "./search.js";
11
11
  export type { ScreenBox, PdfSpaceItem, IVertex } from "./boxes.js";
@@ -17,19 +17,3 @@ export interface SearchAttempt {
17
17
  endTime?: number;
18
18
  durationMs?: number;
19
19
  }
20
- export interface SearchState {
21
- status: SearchStatus;
22
- expectedPage?: number | null;
23
- actualPage?: number | null;
24
- expectedLineIds?: number[] | null;
25
- actualLineIds?: number[] | null;
26
- actualTimestamps?: {
27
- startTime?: string;
28
- endTime?: string;
29
- };
30
- expectedTimestamps?: {
31
- startTime?: string;
32
- endTime?: string;
33
- };
34
- searchAttempts?: SearchAttempt[];
35
- }
@@ -1,24 +1,26 @@
1
1
  import { type Citation } from "./citation.js";
2
- import { type SearchState } from "./search.js";
2
+ import { type SearchStatus, type SearchAttempt } from "./search.js";
3
3
  import { type PdfSpaceItem } from "./boxes.js";
4
4
  export declare const NOT_FOUND_VERIFICATION_INDEX = -1;
5
5
  export declare const PENDING_VERIFICATION_INDEX = -2;
6
6
  export declare const BLANK_VERIFICATION: Verification;
7
- export declare function deterministicIdFromVerification(verification: Verification): string;
8
7
  export interface Verification {
9
8
  attachmentId?: string | null;
10
9
  label?: string | null;
11
10
  citation?: Citation;
12
- searchState?: SearchState | null;
11
+ status?: SearchStatus | null;
12
+ searchAttempts?: SearchAttempt[];
13
13
  highlightColor?: string | null;
14
- pageNumber?: number | null;
15
- lineIds?: number[] | null;
16
- timestamps?: {
14
+ verifiedPageNumber?: number | null;
15
+ verifiedLineIds?: number[] | null;
16
+ verifiedTimestamps?: {
17
17
  startTime?: string;
18
18
  endTime?: string;
19
19
  } | null;
20
+ verifiedFullPhrase?: string | null;
21
+ verifiedKeySpan?: string | null;
22
+ verifiedMatchSnippet?: string | null;
20
23
  hitIndexWithinPage?: number | null;
21
- matchSnippet?: string | null;
22
24
  pdfSpaceItem?: PdfSpaceItem;
23
25
  verificationImageBase64?: string | null;
24
26
  verifiedAt?: Date;
@@ -1,17 +1,11 @@
1
- import { sha1Hash } from "../utils/sha.js";
2
1
  export const NOT_FOUND_VERIFICATION_INDEX = -1;
3
2
  export const PENDING_VERIFICATION_INDEX = -2;
4
3
  export const BLANK_VERIFICATION = {
5
4
  attachmentId: null,
6
- pageNumber: NOT_FOUND_VERIFICATION_INDEX,
7
- matchSnippet: null,
5
+ verifiedPageNumber: NOT_FOUND_VERIFICATION_INDEX,
6
+ verifiedMatchSnippet: null,
8
7
  citation: {
9
8
  pageNumber: NOT_FOUND_VERIFICATION_INDEX,
10
9
  },
11
- searchState: {
12
- status: "not_found",
13
- },
10
+ status: "not_found",
14
11
  };
15
- export function deterministicIdFromVerification(verification) {
16
- return sha1Hash(`${verification.label}-${verification.attachmentId}-${verification.pageNumber}-${verification.hitIndexWithinPage}-${verification.matchSnippet}-${verification?.hitIndexWithinPage}`);
17
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepcitation/deepcitation-js",
3
- "version": "1.1.22",
3
+ "version": "1.1.23",
4
4
  "description": "DeepCitation JavaScript SDK for deterministic AI citation verification",
5
5
  "type": "module",
6
6
  "private": false,
@@ -13,15 +13,13 @@
13
13
  },
14
14
  "main": "./lib/index.js",
15
15
  "types": "./lib/index.d.ts",
16
- "sideEffects": [
17
- "*.css"
18
- ],
16
+ "sideEffects": false,
19
17
  "files": [
20
18
  "lib",
21
19
  "LICENSE"
22
20
  ],
23
21
  "scripts": {
24
- "build": "rimraf lib && tsc && cp src/react/styles.css lib/react/styles.css",
22
+ "build": "rimraf lib && tsc",
25
23
  "build:watch": "rimraf lib && tsc --watch",
26
24
  "test": "bun test ./src/__tests__/*.test.ts ./src/__tests__/*.test.tsx",
27
25
  "test:jest": "jest",
@@ -33,18 +31,28 @@
33
31
  "engines": {
34
32
  "node": ">=22"
35
33
  },
36
- "dependencies": {
37
- "diff": "^8.0.2"
38
- },
39
34
  "peerDependencies": {
40
- "react": ">=17.0.0"
35
+ "react": ">=17.0.0",
36
+ "react-dom": ">=17.0.0",
37
+ "@radix-ui/react-popover": "^1.0.0",
38
+ "diff": "^8.0.0"
41
39
  },
42
40
  "peerDependenciesMeta": {
43
41
  "react": {
44
42
  "optional": true
43
+ },
44
+ "react-dom": {
45
+ "optional": true
46
+ },
47
+ "@radix-ui/react-popover": {
48
+ "optional": true
49
+ },
50
+ "diff": {
51
+ "optional": true
45
52
  }
46
53
  },
47
54
  "devDependencies": {
55
+ "diff": "^8.0.2",
48
56
  "@happy-dom/global-registrator": "^20.0.11",
49
57
  "@playwright/experimental-ct-react": "^1.57.0",
50
58
  "@playwright/test": "^1.57.0",
@@ -59,6 +67,7 @@
59
67
  "happy-dom": "^20.0.11",
60
68
  "jest": "^29.7.0",
61
69
  "jest-environment-jsdom": "^29.7.0",
70
+ "@radix-ui/react-popover": "^1.1.14",
62
71
  "react": "19.2.3",
63
72
  "react-dom": "19.2.3",
64
73
  "rimraf": "^5.0.5",
@@ -76,8 +85,7 @@
76
85
  "types": "./lib/react/index.d.ts",
77
86
  "import": "./lib/react/index.js",
78
87
  "require": "./lib/react/index.js"
79
- },
80
- "./react/styles.css": "./lib/react/styles.css"
88
+ }
81
89
  },
82
90
  "keywords": [
83
91
  "citation",