@deepcitation/deepcitation-js 1.1.22 → 1.1.24

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,4 +1,4 @@
1
- import * as Diff from "diff";
1
+ import { diffLines, diffWordsWithSpace } from "../utils/diff.js";
2
2
  import { useMemo } from "react";
3
3
  export const useSmartDiff = (expected = "", actual = "") => {
4
4
  return useMemo(() => {
@@ -8,7 +8,7 @@ export const useSmartDiff = (expected = "", actual = "") => {
8
8
  // 2. First Pass: Diff by LINES.
9
9
  // This isolates the "extra line" issue. The extra line becomes one "added" chunk,
10
10
  // and it prevents the tokenizer from getting confused on the rest of the text.
11
- const lineDiffs = Diff.diffLines(cleanExpected, cleanActual);
11
+ const lineDiffs = diffLines(cleanExpected, cleanActual);
12
12
  // 3. Second Pass: Process the line results to find "Modifications"
13
13
  const processedDiffs = [];
14
14
  let hasDiff = false;
@@ -21,7 +21,7 @@ export const useSmartDiff = (expected = "", actual = "") => {
21
21
  // it means this specific line changed. We should DIFF WORDS inside this line.
22
22
  if (part.removed && nextPart && nextPart.added) {
23
23
  // Run word diff ONLY on this pair of lines
24
- const wordDiffs = Diff.diffWordsWithSpace(part.value, nextPart.value);
24
+ const wordDiffs = diffWordsWithSpace(part.value, nextPart.value);
25
25
  processedDiffs.push({
26
26
  type: "modified",
27
27
  parts: wordDiffs,
@@ -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
- }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Custom diff implementation to replace the 'diff' npm package.
3
+ * This avoids dependency issues in Firebase Functions environments.
4
+ *
5
+ * Implements a Myers diff algorithm with optimizations inspired by jsdiff.
6
+ * @see https://github.com/kpdecker/jsdiff
7
+ *
8
+ * ---
9
+ *
10
+ * BSD 3-Clause License
11
+ *
12
+ * Copyright (c) 2009-2015, Kevin Decker <kpdecker@gmail.com>
13
+ * All rights reserved.
14
+ *
15
+ * Redistribution and use in source and binary forms, with or without
16
+ * modification, are permitted provided that the following conditions are met:
17
+ *
18
+ * 1. Redistributions of source code must retain the above copyright notice, this
19
+ * list of conditions and the following disclaimer.
20
+ *
21
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
22
+ * this list of conditions and the following disclaimer in the documentation
23
+ * and/or other materials provided with the distribution.
24
+ *
25
+ * 3. Neither the name of the copyright holder nor the names of its
26
+ * contributors may be used to endorse or promote products derived from
27
+ * this software without specific prior written permission.
28
+ *
29
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
33
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
+ */
40
+ export interface Change {
41
+ value: string;
42
+ added?: boolean;
43
+ removed?: boolean;
44
+ count?: number;
45
+ }
46
+ /**
47
+ * Compare two strings line by line.
48
+ * Similar to Diff.diffLines from the 'diff' package.
49
+ */
50
+ export declare function diffLines(oldStr: string, newStr: string): Change[];
51
+ /**
52
+ * Compare two strings word by word, preserving whitespace.
53
+ * Similar to Diff.diffWordsWithSpace from the 'diff' package.
54
+ *
55
+ * Features matching jsdiff:
56
+ * - Extended Unicode word character support
57
+ * - Proper tokenization (words, whitespace runs, single punctuation)
58
+ * - Whitespace deduplication in consecutive changes
59
+ */
60
+ export declare function diffWordsWithSpace(oldStr: string, newStr: string): Change[];