@anaralabs/lector 3.5.1 → 3.5.2
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 +4 -2
- package/dist/index.js +65 -31
- package/package.json +1 -1
|
@@ -39,7 +39,7 @@ declare interface Annotation {
|
|
|
39
39
|
export { Annotation }
|
|
40
40
|
export { Annotation as Annotation_alias_1 }
|
|
41
41
|
|
|
42
|
-
export declare const AnnotationHighlightLayer: ({ className, style, renderTooltipContent, focusedAnnotationId, onAnnotationClick, }: AnnotationHighlightLayerProps) => JSX.Element;
|
|
42
|
+
export declare const AnnotationHighlightLayer: ({ className, style, renderTooltipContent, tooltipClassName, focusedAnnotationId, onAnnotationClick, }: AnnotationHighlightLayerProps) => JSX.Element;
|
|
43
43
|
|
|
44
44
|
declare interface AnnotationHighlightLayerProps {
|
|
45
45
|
className?: string;
|
|
@@ -50,6 +50,7 @@ declare interface AnnotationHighlightLayerProps {
|
|
|
50
50
|
}) => React.ReactNode;
|
|
51
51
|
focusedAnnotationId?: string;
|
|
52
52
|
onAnnotationClick?: (annotation: Annotation) => void;
|
|
53
|
+
tooltipClassName?: string;
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
/**
|
|
@@ -89,7 +90,7 @@ declare interface AnnotationState {
|
|
|
89
90
|
setAnnotations: (annotations: Annotation[]) => void;
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
export declare const AnnotationTooltip: ({ annotation, children, tooltipContent, onOpenChange, isOpen: controlledIsOpen, }: AnnotationTooltipProps) => JSX.Element;
|
|
93
|
+
export declare const AnnotationTooltip: ({ annotation, children, tooltipContent, onOpenChange, className, isOpen: controlledIsOpen, }: AnnotationTooltipProps) => JSX.Element;
|
|
93
94
|
|
|
94
95
|
declare interface AnnotationTooltipProps {
|
|
95
96
|
annotation: Annotation;
|
|
@@ -97,6 +98,7 @@ declare interface AnnotationTooltipProps {
|
|
|
97
98
|
tooltipContent: React.ReactNode;
|
|
98
99
|
onOpenChange?: (open: boolean) => void;
|
|
99
100
|
isOpen?: boolean;
|
|
101
|
+
className?: string;
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
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';
|
|
@@ -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
|
};
|
|
@@ -315,6 +347,7 @@ var AnnotationHighlightLayer = ({
|
|
|
315
347
|
className,
|
|
316
348
|
style,
|
|
317
349
|
renderTooltipContent,
|
|
350
|
+
tooltipClassName,
|
|
318
351
|
focusedAnnotationId,
|
|
319
352
|
onAnnotationClick
|
|
320
353
|
}) => {
|
|
@@ -327,6 +360,7 @@ var AnnotationHighlightLayer = ({
|
|
|
327
360
|
AnnotationTooltip,
|
|
328
361
|
{
|
|
329
362
|
annotation,
|
|
363
|
+
className: tooltipClassName,
|
|
330
364
|
isOpen: focusedAnnotationId === annotation.id,
|
|
331
365
|
onOpenChange: (open) => {
|
|
332
366
|
if (open && onAnnotationClick) {
|