@semiont/react-ui 0.2.33-build.85 → 0.2.33

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@semiont/react-ui",
3
- "version": "0.2.33-build.85",
3
+ "version": "0.2.33",
4
4
  "description": "React components and hooks for Semiont",
5
5
  "main": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.mts",
@@ -2,11 +2,10 @@
2
2
 
3
3
  import { useRef, useEffect, useCallback, lazy, Suspense } from 'react';
4
4
  import type { components } from '@semiont/api-client';
5
- import { getTextPositionSelector, getTextQuoteSelector, getTargetSelector, getMimeCategory, isPdfMimeType, resourceUri as toResourceUri } from '@semiont/api-client';
5
+ import { getTextPositionSelector, getTextQuoteSelector, getTargetSelector, getMimeCategory, isPdfMimeType, resourceUri as toResourceUri, extractContext, findTextWithContext } from '@semiont/api-client';
6
6
  import { ANNOTATORS } from '../../lib/annotation-registry';
7
7
  import { SvgDrawingCanvas } from '../image-annotation/SvgDrawingCanvas';
8
8
  import { useResourceAnnotations } from '../../contexts/ResourceAnnotationsContext';
9
- import { findTextWithContext } from '@semiont/api-client';
10
9
 
11
10
  // Lazy load PDF component to avoid SSR issues with browser PDF.js loading
12
11
  const PdfAnnotationCanvas = lazy(() => import('../pdf-annotation/PdfAnnotationCanvas.client').then(mod => ({ default: mod.PdfAnnotationCanvas })));
@@ -44,27 +43,6 @@ interface Props {
44
43
  annotateMode: boolean;
45
44
  }
46
45
 
47
- /**
48
- * Extract prefix and suffix context for TextQuoteSelector
49
- * Extracts up to 32 characters before and after the selected text
50
- */
51
- function extractContext(content: string, start: number, end: number): { prefix?: string; suffix?: string } {
52
- const CONTEXT_LENGTH = 32;
53
- const result: { prefix?: string; suffix?: string } = {};
54
-
55
- // Extract prefix (up to CONTEXT_LENGTH chars before start)
56
- if (start > 0) {
57
- result.prefix = content.substring(Math.max(0, start - CONTEXT_LENGTH), start);
58
- }
59
-
60
- // Extract suffix (up to CONTEXT_LENGTH chars after end)
61
- if (end < content.length) {
62
- result.suffix = content.substring(end, Math.min(content.length, end + CONTEXT_LENGTH));
63
- }
64
-
65
- return result;
66
- }
67
-
68
46
  // Segment text with annotations - uses fuzzy anchoring when available!
69
47
  function segmentTextWithAnnotations(content: string, annotations: Annotation[]): TextSegment[] {
70
48
  if (!content) {
@@ -77,16 +55,16 @@ function segmentTextWithAnnotations(content: string, annotations: Annotation[]):
77
55
  const posSelector = getTextPositionSelector(targetSelector);
78
56
  const quoteSelector = targetSelector ? getTextQuoteSelector(targetSelector) : null;
79
57
 
80
- // Try fuzzy anchoring if TextQuoteSelector with context is available
58
+ // Try fuzzy anchoring if TextQuoteSelector is available
59
+ // Pass TextPositionSelector as position hint for better fuzzy search
81
60
  let position;
82
- if (quoteSelector && (quoteSelector.prefix || quoteSelector.suffix)) {
83
- // Use fuzzy anchoring when prefix/suffix context is available
84
- // This helps when content changes or same text appears multiple times
61
+ if (quoteSelector) {
85
62
  position = findTextWithContext(
86
63
  content,
87
64
  quoteSelector.exact,
88
65
  quoteSelector.prefix,
89
- quoteSelector.suffix
66
+ quoteSelector.suffix,
67
+ posSelector?.start // Position hint for fuzzy matching
90
68
  );
91
69
  }
92
70