@anaralabs/lector 3.5.1 → 3.5.3
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/dist/_tsup-dts-rollup.d.ts +8 -5
- package/dist/index.js +68 -40
- package/package.json +1 -1
|
@@ -31,15 +31,16 @@ declare interface Annotation {
|
|
|
31
31
|
width: number;
|
|
32
32
|
pageNumber: number;
|
|
33
33
|
}>;
|
|
34
|
-
|
|
35
|
-
color?: string;
|
|
34
|
+
color: string;
|
|
36
35
|
createdAt: Date;
|
|
37
36
|
updatedAt: Date;
|
|
37
|
+
comment?: string;
|
|
38
|
+
metadata?: Record<string, unknown>;
|
|
38
39
|
}
|
|
39
40
|
export { Annotation }
|
|
40
41
|
export { Annotation as Annotation_alias_1 }
|
|
41
42
|
|
|
42
|
-
export declare const AnnotationHighlightLayer: ({ className, style, renderTooltipContent, focusedAnnotationId, onAnnotationClick, }: AnnotationHighlightLayerProps) => JSX.Element;
|
|
43
|
+
export declare const AnnotationHighlightLayer: ({ className, style, renderTooltipContent, tooltipClassName, focusedAnnotationId, onAnnotationClick, }: AnnotationHighlightLayerProps) => JSX.Element;
|
|
43
44
|
|
|
44
45
|
declare interface AnnotationHighlightLayerProps {
|
|
45
46
|
className?: string;
|
|
@@ -50,6 +51,7 @@ declare interface AnnotationHighlightLayerProps {
|
|
|
50
51
|
}) => React.ReactNode;
|
|
51
52
|
focusedAnnotationId?: string;
|
|
52
53
|
onAnnotationClick?: (annotation: Annotation) => void;
|
|
54
|
+
tooltipClassName?: string;
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
/**
|
|
@@ -83,13 +85,13 @@ declare interface AnnotationLayerParams {
|
|
|
83
85
|
|
|
84
86
|
declare interface AnnotationState {
|
|
85
87
|
annotations: Annotation[];
|
|
86
|
-
addAnnotation: (annotation:
|
|
88
|
+
addAnnotation: (annotation: Annotation) => void;
|
|
87
89
|
updateAnnotation: (id: string, updates: Partial<Annotation>) => void;
|
|
88
90
|
deleteAnnotation: (id: string) => void;
|
|
89
91
|
setAnnotations: (annotations: Annotation[]) => void;
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
export declare const AnnotationTooltip: ({ annotation, children, tooltipContent, onOpenChange, isOpen: controlledIsOpen, }: AnnotationTooltipProps) => JSX.Element;
|
|
94
|
+
export declare const AnnotationTooltip: ({ annotation, children, tooltipContent, onOpenChange, className, isOpen: controlledIsOpen, }: AnnotationTooltipProps) => JSX.Element;
|
|
93
95
|
|
|
94
96
|
declare interface AnnotationTooltipProps {
|
|
95
97
|
annotation: Annotation;
|
|
@@ -97,6 +99,7 @@ declare interface AnnotationTooltipProps {
|
|
|
97
99
|
tooltipContent: React.ReactNode;
|
|
98
100
|
onOpenChange?: (open: boolean) => void;
|
|
99
101
|
isOpen?: boolean;
|
|
102
|
+
className?: string;
|
|
100
103
|
}
|
|
101
104
|
|
|
102
105
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import React, { createContext, forwardRef, useCallback, useContext, useState, useRef, useEffect, cloneElement, createRef, useLayoutEffect } from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { createPortal } from 'react-dom';
|
|
5
|
+
import { useFloating, autoUpdate, offset, shift, useDismiss, useInteractions, inline, flip } from '@floating-ui/react';
|
|
5
6
|
import { useVirtualizer, elementScroll, debounce } from '@tanstack/react-virtual';
|
|
6
7
|
import { create, useStore, createStore } from 'zustand';
|
|
7
8
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
8
|
-
import { v4 } from 'uuid';
|
|
9
9
|
import { AnnotationLayer, TextLayer, getDocument } from 'pdfjs-dist';
|
|
10
10
|
import { useDebounce } from 'use-debounce';
|
|
11
|
+
import { v4 } from 'uuid';
|
|
11
12
|
import { Slot } from '@radix-ui/react-slot';
|
|
12
13
|
|
|
13
14
|
// src/components/annotation-tooltip.tsx
|
|
@@ -150,6 +151,7 @@ var useAnnotationTooltip = ({
|
|
|
150
151
|
const isNewAnnotation = Date.now() - new Date(annotation.createdAt).getTime() < 1e3;
|
|
151
152
|
const [isOpen, setIsOpen] = useState(isNewAnnotation);
|
|
152
153
|
const viewportRef = usePdf((state) => state.viewportRef);
|
|
154
|
+
const scale = usePdf((state) => state.zoom);
|
|
153
155
|
const {
|
|
154
156
|
refs,
|
|
155
157
|
floatingStyles,
|
|
@@ -163,9 +165,11 @@ var useAnnotationTooltip = ({
|
|
|
163
165
|
},
|
|
164
166
|
whileElementsMounted: autoUpdate,
|
|
165
167
|
middleware: [
|
|
168
|
+
inline(),
|
|
166
169
|
offset(10),
|
|
167
170
|
flip({
|
|
168
|
-
crossAxis: false
|
|
171
|
+
crossAxis: false,
|
|
172
|
+
fallbackAxisSideDirection: "end"
|
|
169
173
|
}),
|
|
170
174
|
shift({ padding: 8 })
|
|
171
175
|
]
|
|
@@ -174,31 +178,54 @@ var useAnnotationTooltip = ({
|
|
|
174
178
|
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
|
|
175
179
|
const updateTooltipPosition = useCallback(() => {
|
|
176
180
|
if (!annotation.highlights.length) return;
|
|
177
|
-
const
|
|
181
|
+
const highlightRects = annotation.highlights;
|
|
182
|
+
let minLeft = Infinity;
|
|
183
|
+
let maxRight = -Infinity;
|
|
184
|
+
let minTop = Infinity;
|
|
185
|
+
let maxBottom = -Infinity;
|
|
178
186
|
refs.setReference({
|
|
179
|
-
getBoundingClientRect
|
|
187
|
+
getBoundingClientRect() {
|
|
180
188
|
const viewportElement = viewportRef.current;
|
|
181
|
-
if (!viewportElement
|
|
189
|
+
if (!viewportElement) return defaultRect;
|
|
182
190
|
const pageElement = viewportElement.querySelector(`[data-page-number="${annotation.pageNumber}"]`);
|
|
183
191
|
if (!pageElement) return defaultRect;
|
|
184
192
|
const pageRect = pageElement.getBoundingClientRect();
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
193
|
+
highlightRects.forEach((highlight) => {
|
|
194
|
+
const scaledLeft = highlight.left * scale;
|
|
195
|
+
const scaledWidth = highlight.width * scale;
|
|
196
|
+
const scaledTop = highlight.top * scale;
|
|
197
|
+
const scaledHeight = highlight.height * scale;
|
|
198
|
+
const left = pageRect.left + scaledLeft;
|
|
199
|
+
const right = left + scaledWidth;
|
|
200
|
+
const top = pageRect.top + scaledTop;
|
|
201
|
+
const bottom = top + scaledHeight;
|
|
202
|
+
minLeft = Math.min(minLeft, left);
|
|
203
|
+
maxRight = Math.max(maxRight, right);
|
|
204
|
+
minTop = Math.min(minTop, top);
|
|
205
|
+
maxBottom = Math.max(maxBottom, bottom);
|
|
206
|
+
});
|
|
207
|
+
const width = maxRight - minLeft;
|
|
208
|
+
const height = maxBottom - minTop;
|
|
209
|
+
const centerX = minLeft + width / 2;
|
|
210
|
+
const centerY = minTop + height / 2;
|
|
211
|
+
const rect = {
|
|
190
212
|
width,
|
|
191
213
|
height,
|
|
192
|
-
x:
|
|
193
|
-
y:
|
|
194
|
-
top,
|
|
195
|
-
right:
|
|
196
|
-
bottom:
|
|
197
|
-
left
|
|
214
|
+
x: centerX - width / 2,
|
|
215
|
+
y: centerY - height / 2,
|
|
216
|
+
top: centerY - height / 2,
|
|
217
|
+
right: centerX + width / 2,
|
|
218
|
+
bottom: centerY + height / 2,
|
|
219
|
+
left: centerX - width / 2
|
|
198
220
|
};
|
|
199
|
-
|
|
221
|
+
return rect;
|
|
222
|
+
},
|
|
223
|
+
getClientRects() {
|
|
224
|
+
return [this.getBoundingClientRect()];
|
|
225
|
+
},
|
|
226
|
+
contextElement: viewportRef.current || void 0
|
|
200
227
|
});
|
|
201
|
-
}, [annotation.highlights, annotation.pageNumber, refs, viewportRef]);
|
|
228
|
+
}, [annotation.highlights, annotation.pageNumber, refs, viewportRef, scale]);
|
|
202
229
|
useEffect(() => {
|
|
203
230
|
const viewport = viewportRef.current;
|
|
204
231
|
updateTooltipPosition();
|
|
@@ -235,8 +262,10 @@ var AnnotationTooltip = ({
|
|
|
235
262
|
children,
|
|
236
263
|
tooltipContent,
|
|
237
264
|
onOpenChange,
|
|
265
|
+
className,
|
|
238
266
|
isOpen: controlledIsOpen
|
|
239
267
|
}) => {
|
|
268
|
+
const viewportRef = usePdf((state) => state.viewportRef);
|
|
240
269
|
const {
|
|
241
270
|
isOpen: uncontrolledIsOpen,
|
|
242
271
|
setIsOpen,
|
|
@@ -264,19 +293,22 @@ var AnnotationTooltip = ({
|
|
|
264
293
|
children
|
|
265
294
|
}
|
|
266
295
|
),
|
|
267
|
-
isOpen &&
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
296
|
+
isOpen && viewportRef.current && createPortal(
|
|
297
|
+
/* @__PURE__ */ jsx(
|
|
298
|
+
"div",
|
|
299
|
+
{
|
|
300
|
+
ref: refs.setFloating,
|
|
301
|
+
className,
|
|
302
|
+
style: {
|
|
303
|
+
...floatingStyles,
|
|
304
|
+
position: "absolute",
|
|
305
|
+
pointerEvents: "auto"
|
|
306
|
+
},
|
|
307
|
+
...getFloatingProps(),
|
|
308
|
+
children: tooltipContent
|
|
309
|
+
}
|
|
310
|
+
),
|
|
311
|
+
viewportRef.current
|
|
280
312
|
)
|
|
281
313
|
] });
|
|
282
314
|
};
|
|
@@ -285,20 +317,14 @@ var useAnnotations = create((set) => ({
|
|
|
285
317
|
addAnnotation: (annotation) => set((state) => ({
|
|
286
318
|
annotations: [
|
|
287
319
|
...state.annotations,
|
|
288
|
-
|
|
289
|
-
...annotation,
|
|
290
|
-
id: v4(),
|
|
291
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
292
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
293
|
-
}
|
|
320
|
+
annotation
|
|
294
321
|
]
|
|
295
322
|
})),
|
|
296
323
|
updateAnnotation: (id, updates) => set((state) => ({
|
|
297
324
|
annotations: state.annotations.map(
|
|
298
325
|
(annotation) => annotation.id === id ? {
|
|
299
326
|
...annotation,
|
|
300
|
-
...updates
|
|
301
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
327
|
+
...updates
|
|
302
328
|
} : annotation
|
|
303
329
|
)
|
|
304
330
|
})),
|
|
@@ -315,6 +341,7 @@ var AnnotationHighlightLayer = ({
|
|
|
315
341
|
className,
|
|
316
342
|
style,
|
|
317
343
|
renderTooltipContent,
|
|
344
|
+
tooltipClassName,
|
|
318
345
|
focusedAnnotationId,
|
|
319
346
|
onAnnotationClick
|
|
320
347
|
}) => {
|
|
@@ -327,6 +354,7 @@ var AnnotationHighlightLayer = ({
|
|
|
327
354
|
AnnotationTooltip,
|
|
328
355
|
{
|
|
329
356
|
annotation,
|
|
357
|
+
className: tooltipClassName,
|
|
330
358
|
isOpen: focusedAnnotationId === annotation.id,
|
|
331
359
|
onOpenChange: (open) => {
|
|
332
360
|
if (open && onAnnotationClick) {
|