@anaralabs/lector 3.5.4 → 3.5.6
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 +11 -3
- package/dist/index.js +37 -14
- package/package.json +1 -1
|
@@ -32,6 +32,7 @@ declare interface Annotation {
|
|
|
32
32
|
pageNumber: number;
|
|
33
33
|
}>;
|
|
34
34
|
color: string;
|
|
35
|
+
borderColor: string;
|
|
35
36
|
createdAt: Date;
|
|
36
37
|
updatedAt: Date;
|
|
37
38
|
comment?: string;
|
|
@@ -40,7 +41,7 @@ declare interface Annotation {
|
|
|
40
41
|
export { Annotation }
|
|
41
42
|
export { Annotation as Annotation_alias_1 }
|
|
42
43
|
|
|
43
|
-
export declare const AnnotationHighlightLayer: ({ className, style, renderTooltipContent, renderHoverTooltipContent, tooltipClassName, focusedAnnotationId, onAnnotationClick, hoverTooltipClassName }: AnnotationHighlightLayerProps) => JSX.Element;
|
|
44
|
+
export declare const AnnotationHighlightLayer: ({ className, style, renderTooltipContent, renderHoverTooltipContent, tooltipClassName, highlightClassName, focusedAnnotationId, focusedHoverAnnotationId, onAnnotationClick, hoverTooltipClassName, tooltipBubbleSize, }: AnnotationHighlightLayerProps) => JSX.Element;
|
|
44
45
|
|
|
45
46
|
declare interface AnnotationHighlightLayerProps {
|
|
46
47
|
className?: string;
|
|
@@ -54,9 +55,12 @@ declare interface AnnotationHighlightLayerProps {
|
|
|
54
55
|
onClose: () => void;
|
|
55
56
|
}) => React.ReactNode;
|
|
56
57
|
focusedAnnotationId?: string;
|
|
58
|
+
focusedHoverAnnotationId?: string;
|
|
57
59
|
onAnnotationClick?: (annotation: Annotation) => void;
|
|
58
60
|
tooltipClassName?: string;
|
|
59
61
|
hoverTooltipClassName?: string;
|
|
62
|
+
highlightClassName?: string;
|
|
63
|
+
tooltipBubbleSize?: number;
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
/**
|
|
@@ -96,7 +100,7 @@ declare interface AnnotationState {
|
|
|
96
100
|
setAnnotations: (annotations: Annotation[]) => void;
|
|
97
101
|
}
|
|
98
102
|
|
|
99
|
-
export declare const AnnotationTooltip: ({ annotation, children, tooltipContent, hoverTooltipContent, onOpenChange, className, hoverClassName, isOpen: controlledIsOpen, }: AnnotationTooltipProps) => JSX.Element;
|
|
103
|
+
export declare const AnnotationTooltip: ({ annotation, children, tooltipContent, hoverTooltipContent, onOpenChange, className, hoverClassName, isOpen: controlledIsOpen, tooltipBubbleSize, hoverIsOpen: controlledHoverIsOpen, }: AnnotationTooltipProps) => JSX.Element;
|
|
100
104
|
|
|
101
105
|
declare interface AnnotationTooltipProps {
|
|
102
106
|
annotation: Annotation;
|
|
@@ -107,6 +111,8 @@ declare interface AnnotationTooltipProps {
|
|
|
107
111
|
isOpen?: boolean;
|
|
108
112
|
className?: string;
|
|
109
113
|
hoverClassName?: string;
|
|
114
|
+
hoverIsOpen?: boolean;
|
|
115
|
+
tooltipBubbleSize: number;
|
|
110
116
|
renderHoverTooltipContent?: (props: {
|
|
111
117
|
annotation: Annotation;
|
|
112
118
|
onClose: () => void;
|
|
@@ -378,11 +384,12 @@ declare const useAnnotations: UseBoundStore<StoreApi<AnnotationState>>;
|
|
|
378
384
|
export { useAnnotations }
|
|
379
385
|
export { useAnnotations as useAnnotations_alias_1 }
|
|
380
386
|
|
|
381
|
-
export declare const useAnnotationTooltip: ({ annotation, onOpenChange, }: UseAnnotationTooltipProps) => UseAnnotationTooltipReturn;
|
|
387
|
+
export declare const useAnnotationTooltip: ({ annotation, onOpenChange, position, }: UseAnnotationTooltipProps) => UseAnnotationTooltipReturn;
|
|
382
388
|
|
|
383
389
|
declare interface UseAnnotationTooltipProps {
|
|
384
390
|
annotation: Annotation;
|
|
385
391
|
onOpenChange?: (open: boolean) => void;
|
|
392
|
+
position?: "top" | "bottom" | "left" | "right";
|
|
386
393
|
}
|
|
387
394
|
|
|
388
395
|
declare interface UseAnnotationTooltipReturn {
|
|
@@ -424,6 +431,7 @@ export declare const usePdfJump: () => {
|
|
|
424
431
|
}) => void;
|
|
425
432
|
jumpToOffset: (offset: number) => void;
|
|
426
433
|
jumpToHighlightRects: (rects: HighlightRect[], type: "pixels" | "percent", align?: "start" | "center", additionalOffset?: number) => void;
|
|
434
|
+
scrollToHighlightRects: (rects: HighlightRect[], type: "pixels" | "percent", align?: "start" | "center", additionalOffset?: number) => void;
|
|
427
435
|
};
|
|
428
436
|
|
|
429
437
|
declare const usePDFOutline: () => {
|
package/dist/index.js
CHANGED
|
@@ -146,7 +146,8 @@ var defaultRect = {
|
|
|
146
146
|
};
|
|
147
147
|
var useAnnotationTooltip = ({
|
|
148
148
|
annotation,
|
|
149
|
-
onOpenChange
|
|
149
|
+
onOpenChange,
|
|
150
|
+
position = "top"
|
|
150
151
|
}) => {
|
|
151
152
|
const isNewAnnotation = Date.now() - new Date(annotation.createdAt).getTime() < 1e3;
|
|
152
153
|
const [isOpen, setIsOpen] = useState(isNewAnnotation);
|
|
@@ -157,7 +158,7 @@ var useAnnotationTooltip = ({
|
|
|
157
158
|
floatingStyles,
|
|
158
159
|
context
|
|
159
160
|
} = useFloating({
|
|
160
|
-
placement:
|
|
161
|
+
placement: position,
|
|
161
162
|
open: isOpen,
|
|
162
163
|
onOpenChange: (open) => {
|
|
163
164
|
setIsOpen(open);
|
|
@@ -265,7 +266,9 @@ var AnnotationTooltip = ({
|
|
|
265
266
|
onOpenChange,
|
|
266
267
|
className,
|
|
267
268
|
hoverClassName,
|
|
268
|
-
isOpen: controlledIsOpen
|
|
269
|
+
isOpen: controlledIsOpen,
|
|
270
|
+
tooltipBubbleSize,
|
|
271
|
+
hoverIsOpen: controlledHoverIsOpen
|
|
269
272
|
}) => {
|
|
270
273
|
const viewportRef = usePdf((state) => state.viewportRef);
|
|
271
274
|
const closeTimeoutRef = useRef(null);
|
|
@@ -282,16 +285,18 @@ var AnnotationTooltip = ({
|
|
|
282
285
|
onOpenChange
|
|
283
286
|
});
|
|
284
287
|
const {
|
|
285
|
-
isOpen:
|
|
288
|
+
isOpen: uncontrolledHoverIsOpen,
|
|
286
289
|
setIsOpen: setHoverIsOpen,
|
|
287
290
|
refs: hoverRefs,
|
|
288
291
|
floatingStyles: hoverFloatingStyles,
|
|
289
292
|
getFloatingProps: getHoverFloatingProps,
|
|
290
293
|
getReferenceProps: getHoverReferenceProps
|
|
291
294
|
} = useAnnotationTooltip({
|
|
295
|
+
position: "bottom",
|
|
292
296
|
annotation
|
|
293
297
|
});
|
|
294
298
|
const isOpen = controlledIsOpen ?? uncontrolledIsOpen;
|
|
299
|
+
const hoverIsOpen = controlledHoverIsOpen || uncontrolledHoverIsOpen;
|
|
295
300
|
const handleClick = useCallback(() => {
|
|
296
301
|
if (controlledIsOpen === void 0) {
|
|
297
302
|
setIsOpen(!isOpen);
|
|
@@ -327,7 +332,7 @@ var AnnotationTooltip = ({
|
|
|
327
332
|
setHoverIsOpen(false);
|
|
328
333
|
}, [setHoverIsOpen]);
|
|
329
334
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
330
|
-
/* @__PURE__ */
|
|
335
|
+
/* @__PURE__ */ jsxs(
|
|
331
336
|
"div",
|
|
332
337
|
{
|
|
333
338
|
ref: (node) => {
|
|
@@ -339,7 +344,18 @@ var AnnotationTooltip = ({
|
|
|
339
344
|
onMouseLeave: handleMouseLeave,
|
|
340
345
|
...getReferenceProps(),
|
|
341
346
|
...getHoverReferenceProps(),
|
|
342
|
-
children
|
|
347
|
+
children: [
|
|
348
|
+
!isOpen && !hoverIsOpen && annotation.comment && /* @__PURE__ */ jsx("div", { className: "rounded-full", style: {
|
|
349
|
+
position: "absolute",
|
|
350
|
+
top: annotation.highlights[0]?.top ? annotation.highlights[0]?.top - tooltipBubbleSize / 2 : 0,
|
|
351
|
+
left: annotation.highlights[0]?.left ? annotation.highlights[0]?.left - tooltipBubbleSize / 2 : 0,
|
|
352
|
+
backgroundColor: annotation.borderColor,
|
|
353
|
+
height: `${tooltipBubbleSize}px`,
|
|
354
|
+
width: `${tooltipBubbleSize}px`,
|
|
355
|
+
zIndex: 50
|
|
356
|
+
} }),
|
|
357
|
+
children
|
|
358
|
+
]
|
|
343
359
|
}
|
|
344
360
|
),
|
|
345
361
|
isOpen && viewportRef.current && createPortal(
|
|
@@ -415,9 +431,12 @@ var AnnotationHighlightLayer = ({
|
|
|
415
431
|
renderTooltipContent,
|
|
416
432
|
renderHoverTooltipContent,
|
|
417
433
|
tooltipClassName,
|
|
434
|
+
highlightClassName,
|
|
418
435
|
focusedAnnotationId,
|
|
436
|
+
focusedHoverAnnotationId,
|
|
419
437
|
onAnnotationClick,
|
|
420
|
-
hoverTooltipClassName
|
|
438
|
+
hoverTooltipClassName,
|
|
439
|
+
tooltipBubbleSize = 6
|
|
421
440
|
}) => {
|
|
422
441
|
const { annotations } = useAnnotations();
|
|
423
442
|
const pageNumber = usePDFPageNumber();
|
|
@@ -431,6 +450,8 @@ var AnnotationHighlightLayer = ({
|
|
|
431
450
|
className: tooltipClassName,
|
|
432
451
|
hoverClassName: hoverTooltipClassName,
|
|
433
452
|
isOpen: focusedAnnotationId === annotation.id,
|
|
453
|
+
tooltipBubbleSize,
|
|
454
|
+
hoverIsOpen: focusedHoverAnnotationId === annotation.id,
|
|
434
455
|
onOpenChange: (open) => {
|
|
435
456
|
if (open && onAnnotationClick) {
|
|
436
457
|
onAnnotationClick(annotation);
|
|
@@ -454,16 +475,14 @@ var AnnotationHighlightLayer = ({
|
|
|
454
475
|
children: annotation.highlights.map((highlight, index) => /* @__PURE__ */ jsx(
|
|
455
476
|
"div",
|
|
456
477
|
{
|
|
478
|
+
className: highlightClassName,
|
|
457
479
|
style: {
|
|
458
480
|
position: "absolute",
|
|
459
481
|
top: highlight.top,
|
|
460
482
|
left: highlight.left,
|
|
461
483
|
width: highlight.width,
|
|
462
484
|
height: highlight.height,
|
|
463
|
-
backgroundColor: annotation.color
|
|
464
|
-
mixBlendMode: "multiply",
|
|
465
|
-
transition: "all 0.2s ease",
|
|
466
|
-
cursor: "pointer"
|
|
485
|
+
backgroundColor: annotation.color
|
|
467
486
|
},
|
|
468
487
|
"data-highlight-id": annotation.id
|
|
469
488
|
},
|
|
@@ -537,9 +556,8 @@ var usePdfJump = () => {
|
|
|
537
556
|
behavior: "smooth"
|
|
538
557
|
});
|
|
539
558
|
};
|
|
540
|
-
const
|
|
559
|
+
const scrollToHighlightRects = (rects, type, align = "start", additionalOffset = 0) => {
|
|
541
560
|
if (!virtualizer) return;
|
|
542
|
-
setHighlight(rects);
|
|
543
561
|
const firstPage = Math.min(...rects.map((rect) => rect.pageNumber));
|
|
544
562
|
const pageOffset = virtualizer.getOffsetForIndex(firstPage - 1, "start");
|
|
545
563
|
if (pageOffset === null) return;
|
|
@@ -576,7 +594,12 @@ var usePdfJump = () => {
|
|
|
576
594
|
behavior: "smooth"
|
|
577
595
|
});
|
|
578
596
|
};
|
|
579
|
-
|
|
597
|
+
const jumpToHighlightRects = (rects, type, align = "start", additionalOffset = 0) => {
|
|
598
|
+
if (!virtualizer) return;
|
|
599
|
+
setHighlight(rects);
|
|
600
|
+
scrollToHighlightRects(rects, type, align, additionalOffset);
|
|
601
|
+
};
|
|
602
|
+
return { jumpToPage, jumpToOffset, jumpToHighlightRects, scrollToHighlightRects };
|
|
580
603
|
};
|
|
581
604
|
var LinkService = class {
|
|
582
605
|
_pdfDocumentProxy;
|