@anaralabs/lector 3.4.0 → 3.5.0
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 +92 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +386 -36
- package/package.json +1 -1
|
@@ -16,8 +16,42 @@ import { ReactNode } from 'react';
|
|
|
16
16
|
import { RefAttributes } from 'react';
|
|
17
17
|
import { StoreApi } from 'zustand';
|
|
18
18
|
import type { TypedArray } from 'pdfjs-dist/types/src/display/api';
|
|
19
|
+
import { UseBoundStore } from 'zustand';
|
|
20
|
+
import { useFloating } from '@floating-ui/react';
|
|
21
|
+
import { useInteractions } from '@floating-ui/react';
|
|
19
22
|
import { Virtualizer } from '@tanstack/react-virtual';
|
|
20
23
|
|
|
24
|
+
declare interface Annotation {
|
|
25
|
+
id: string;
|
|
26
|
+
pageNumber: number;
|
|
27
|
+
highlights: Array<{
|
|
28
|
+
height: number;
|
|
29
|
+
left: number;
|
|
30
|
+
top: number;
|
|
31
|
+
width: number;
|
|
32
|
+
pageNumber: number;
|
|
33
|
+
}>;
|
|
34
|
+
comment?: string;
|
|
35
|
+
color?: string;
|
|
36
|
+
createdAt: Date;
|
|
37
|
+
updatedAt: Date;
|
|
38
|
+
}
|
|
39
|
+
export { Annotation }
|
|
40
|
+
export { Annotation as Annotation_alias_1 }
|
|
41
|
+
|
|
42
|
+
export declare const AnnotationHighlightLayer: ({ className, style, renderTooltipContent, focusedAnnotationId, onAnnotationClick, }: AnnotationHighlightLayerProps) => JSX.Element;
|
|
43
|
+
|
|
44
|
+
declare interface AnnotationHighlightLayerProps {
|
|
45
|
+
className?: string;
|
|
46
|
+
style?: React.CSSProperties;
|
|
47
|
+
renderTooltipContent?: (props: {
|
|
48
|
+
annotation: Annotation;
|
|
49
|
+
onClose: () => void;
|
|
50
|
+
}) => React.ReactNode;
|
|
51
|
+
focusedAnnotationId?: string;
|
|
52
|
+
onAnnotationClick?: (annotation: Annotation) => void;
|
|
53
|
+
}
|
|
54
|
+
|
|
21
55
|
/**
|
|
22
56
|
* AnnotationLayer renders PDF annotations like links, highlights, and form fields.
|
|
23
57
|
*
|
|
@@ -47,6 +81,24 @@ declare interface AnnotationLayerParams {
|
|
|
47
81
|
jumpOptions?: Parameters<ReturnType<typeof usePdfJump>['jumpToPage']>[1];
|
|
48
82
|
}
|
|
49
83
|
|
|
84
|
+
declare interface AnnotationState {
|
|
85
|
+
annotations: Annotation[];
|
|
86
|
+
addAnnotation: (annotation: Omit<Annotation, "id" | "createdAt" | "updatedAt">) => void;
|
|
87
|
+
updateAnnotation: (id: string, updates: Partial<Annotation>) => void;
|
|
88
|
+
deleteAnnotation: (id: string) => void;
|
|
89
|
+
setAnnotations: (annotations: Annotation[]) => void;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export declare const AnnotationTooltip: ({ annotation, children, tooltipContent, onOpenChange, isOpen: controlledIsOpen, }: AnnotationTooltipProps) => JSX.Element;
|
|
93
|
+
|
|
94
|
+
declare interface AnnotationTooltipProps {
|
|
95
|
+
annotation: Annotation;
|
|
96
|
+
children: React.ReactNode;
|
|
97
|
+
tooltipContent: React.ReactNode;
|
|
98
|
+
onOpenChange?: (open: boolean) => void;
|
|
99
|
+
isOpen?: boolean;
|
|
100
|
+
}
|
|
101
|
+
|
|
50
102
|
/**
|
|
51
103
|
* Calculates the highlight rectangles for a given text match.
|
|
52
104
|
*
|
|
@@ -310,6 +362,44 @@ export declare const Thumbnails: ({ children, ...props }: HTMLProps<HTMLDivEleme
|
|
|
310
362
|
|
|
311
363
|
export declare const TotalPages: ({ ...props }: HTMLProps<HTMLDivElement>) => JSX.Element;
|
|
312
364
|
|
|
365
|
+
export declare const useAnnotationActions: ({ annotation, onClose, }: UseAnnotationActionsProps) => UseAnnotationActionsReturn;
|
|
366
|
+
|
|
367
|
+
declare interface UseAnnotationActionsProps {
|
|
368
|
+
annotation: Annotation;
|
|
369
|
+
onClose?: () => void;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
declare interface UseAnnotationActionsReturn {
|
|
373
|
+
comment: string;
|
|
374
|
+
isEditing: boolean;
|
|
375
|
+
setComment: (comment: string) => void;
|
|
376
|
+
setIsEditing: (isEditing: boolean) => void;
|
|
377
|
+
handleSaveComment: () => void;
|
|
378
|
+
handleColorChange: (color: string) => void;
|
|
379
|
+
handleCancelEdit: () => void;
|
|
380
|
+
colors: string[];
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
declare const useAnnotations: UseBoundStore<StoreApi<AnnotationState>>;
|
|
384
|
+
export { useAnnotations }
|
|
385
|
+
export { useAnnotations as useAnnotations_alias_1 }
|
|
386
|
+
|
|
387
|
+
export declare const useAnnotationTooltip: ({ annotation, onOpenChange, }: UseAnnotationTooltipProps) => UseAnnotationTooltipReturn;
|
|
388
|
+
|
|
389
|
+
declare interface UseAnnotationTooltipProps {
|
|
390
|
+
annotation: Annotation;
|
|
391
|
+
onOpenChange?: (open: boolean) => void;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
declare interface UseAnnotationTooltipReturn {
|
|
395
|
+
isOpen: boolean;
|
|
396
|
+
setIsOpen: (open: boolean) => void;
|
|
397
|
+
refs: ReturnType<typeof useFloating>["refs"];
|
|
398
|
+
floatingStyles: ReturnType<typeof useFloating>["floatingStyles"];
|
|
399
|
+
getFloatingProps: ReturnType<typeof useInteractions>["getFloatingProps"];
|
|
400
|
+
getReferenceProps: ReturnType<typeof useInteractions>["getReferenceProps"];
|
|
401
|
+
}
|
|
402
|
+
|
|
313
403
|
declare const usePdf: <T>(selector: (state: PDFState) => T) => T;
|
|
314
404
|
export { usePdf }
|
|
315
405
|
export { usePdf as usePdf_alias_1 }
|
|
@@ -355,6 +445,8 @@ declare const usePDFOutline: () => {
|
|
|
355
445
|
items: Array<any>;
|
|
356
446
|
}[] | undefined;
|
|
357
447
|
|
|
448
|
+
export declare const usePDFPageNumber: () => number;
|
|
449
|
+
|
|
358
450
|
export declare const useSearch: () => {
|
|
359
451
|
textContent: {
|
|
360
452
|
pageNumber: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { AnnotationTooltip } from './_tsup-dts-rollup.js';
|
|
2
|
+
export { AnnotationHighlightLayer } from './_tsup-dts-rollup.js';
|
|
1
3
|
export { AnnotationLayer } from './_tsup-dts-rollup.js';
|
|
2
4
|
export { CanvasLayer } from './_tsup-dts-rollup.js';
|
|
3
5
|
export { ColoredHighlightLayer } from './_tsup-dts-rollup.js';
|
|
@@ -26,7 +28,10 @@ export { SearchResult } from './_tsup-dts-rollup.js';
|
|
|
26
28
|
export { SearchResults } from './_tsup-dts-rollup.js';
|
|
27
29
|
export { useSearch } from './_tsup-dts-rollup.js';
|
|
28
30
|
export { calculateHighlightRects } from './_tsup-dts-rollup.js';
|
|
31
|
+
export { Annotation } from './_tsup-dts-rollup.js';
|
|
32
|
+
export { useAnnotations } from './_tsup-dts-rollup.js';
|
|
29
33
|
export { LinkService } from './_tsup-dts-rollup.js';
|
|
34
|
+
export { usePDFPageNumber } from './_tsup-dts-rollup.js';
|
|
30
35
|
export { useSelectionDimensions } from './_tsup-dts-rollup.js';
|
|
31
36
|
export { ColoredHighlight } from './_tsup-dts-rollup.js';
|
|
32
37
|
export { HighlightRect } from './_tsup-dts-rollup.js';
|
package/dist/index.js
CHANGED
|
@@ -1,30 +1,16 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
3
|
+
import React, { createContext, forwardRef, useCallback, useContext, useState, useRef, useEffect, cloneElement, createRef, useLayoutEffect } from 'react';
|
|
4
|
+
import { useFloating, autoUpdate, offset, shift, useDismiss, useInteractions, flip } from '@floating-ui/react';
|
|
5
5
|
import { useVirtualizer, elementScroll, debounce } from '@tanstack/react-virtual';
|
|
6
|
-
import { useStore, createStore } from 'zustand';
|
|
6
|
+
import { create, useStore, createStore } from 'zustand';
|
|
7
7
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
8
|
-
import { useDebounce } from 'use-debounce';
|
|
9
8
|
import { v4 } from 'uuid';
|
|
10
|
-
import {
|
|
9
|
+
import { AnnotationLayer, TextLayer, getDocument } from 'pdfjs-dist';
|
|
10
|
+
import { useDebounce } from 'use-debounce';
|
|
11
11
|
import { Slot } from '@radix-ui/react-slot';
|
|
12
12
|
|
|
13
|
-
//
|
|
14
|
-
function r(e) {
|
|
15
|
-
var t, f, n = "";
|
|
16
|
-
if ("string" == typeof e || "number" == typeof e) n += e;
|
|
17
|
-
else if ("object" == typeof e) if (Array.isArray(e)) {
|
|
18
|
-
var o = e.length;
|
|
19
|
-
for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
|
|
20
|
-
} else for (f in e) e[f] && (n && (n += " "), n += f);
|
|
21
|
-
return n;
|
|
22
|
-
}
|
|
23
|
-
function clsx() {
|
|
24
|
-
for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
|
|
25
|
-
return n;
|
|
26
|
-
}
|
|
27
|
-
var clsx_default = clsx;
|
|
13
|
+
// src/components/annotation-tooltip.tsx
|
|
28
14
|
|
|
29
15
|
// src/lib/clamp.ts
|
|
30
16
|
var clamp = (value, min, max) => {
|
|
@@ -146,6 +132,373 @@ var PDFStore = createZustandContext(
|
|
|
146
132
|
);
|
|
147
133
|
var usePdf = (selector) => useStore(PDFStore.useContext(), selector);
|
|
148
134
|
|
|
135
|
+
// src/hooks/useAnnotationTooltip.ts
|
|
136
|
+
var defaultRect = {
|
|
137
|
+
width: 0,
|
|
138
|
+
height: 0,
|
|
139
|
+
x: 0,
|
|
140
|
+
y: 0,
|
|
141
|
+
top: 0,
|
|
142
|
+
right: 0,
|
|
143
|
+
bottom: 0,
|
|
144
|
+
left: 0
|
|
145
|
+
};
|
|
146
|
+
var useAnnotationTooltip = ({
|
|
147
|
+
annotation,
|
|
148
|
+
onOpenChange
|
|
149
|
+
}) => {
|
|
150
|
+
const isNewAnnotation = Date.now() - new Date(annotation.createdAt).getTime() < 1e3;
|
|
151
|
+
const [isOpen, setIsOpen] = useState(isNewAnnotation);
|
|
152
|
+
const viewportRef = usePdf((state) => state.viewportRef);
|
|
153
|
+
const {
|
|
154
|
+
refs,
|
|
155
|
+
floatingStyles,
|
|
156
|
+
context
|
|
157
|
+
} = useFloating({
|
|
158
|
+
placement: "top",
|
|
159
|
+
open: isOpen,
|
|
160
|
+
onOpenChange: (open) => {
|
|
161
|
+
setIsOpen(open);
|
|
162
|
+
onOpenChange?.(open);
|
|
163
|
+
},
|
|
164
|
+
whileElementsMounted: autoUpdate,
|
|
165
|
+
middleware: [
|
|
166
|
+
offset(10),
|
|
167
|
+
flip({
|
|
168
|
+
crossAxis: false
|
|
169
|
+
}),
|
|
170
|
+
shift({ padding: 8 })
|
|
171
|
+
]
|
|
172
|
+
});
|
|
173
|
+
const dismiss = useDismiss(context);
|
|
174
|
+
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
|
|
175
|
+
const updateTooltipPosition = useCallback(() => {
|
|
176
|
+
if (!annotation.highlights.length) return;
|
|
177
|
+
const lastHighlight = annotation.highlights[annotation.highlights.length - 1];
|
|
178
|
+
refs.setReference({
|
|
179
|
+
getBoundingClientRect: () => {
|
|
180
|
+
const viewportElement = viewportRef.current;
|
|
181
|
+
if (!viewportElement || !lastHighlight) return defaultRect;
|
|
182
|
+
const pageElement = viewportElement.querySelector(`[data-page-number="${annotation.pageNumber}"]`);
|
|
183
|
+
if (!pageElement) return defaultRect;
|
|
184
|
+
const pageRect = pageElement.getBoundingClientRect();
|
|
185
|
+
const left = pageRect.left + lastHighlight.left;
|
|
186
|
+
const top = pageRect.top + lastHighlight.top;
|
|
187
|
+
const width = lastHighlight.width;
|
|
188
|
+
const height = lastHighlight.height;
|
|
189
|
+
return {
|
|
190
|
+
width,
|
|
191
|
+
height,
|
|
192
|
+
x: left,
|
|
193
|
+
y: top,
|
|
194
|
+
top,
|
|
195
|
+
right: left + width,
|
|
196
|
+
bottom: top + height,
|
|
197
|
+
left
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}, [annotation.highlights, annotation.pageNumber, refs, viewportRef]);
|
|
202
|
+
useEffect(() => {
|
|
203
|
+
updateTooltipPosition();
|
|
204
|
+
const handleScroll = () => {
|
|
205
|
+
requestAnimationFrame(updateTooltipPosition);
|
|
206
|
+
};
|
|
207
|
+
const handleResize = () => {
|
|
208
|
+
requestAnimationFrame(updateTooltipPosition);
|
|
209
|
+
};
|
|
210
|
+
if (viewportRef.current) {
|
|
211
|
+
viewportRef.current.addEventListener("scroll", handleScroll, {
|
|
212
|
+
passive: true
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
window.addEventListener("resize", handleResize, { passive: true });
|
|
216
|
+
return () => {
|
|
217
|
+
if (viewportRef.current) {
|
|
218
|
+
viewportRef.current.removeEventListener("scroll", handleScroll);
|
|
219
|
+
}
|
|
220
|
+
window.removeEventListener("resize", handleResize);
|
|
221
|
+
};
|
|
222
|
+
}, [updateTooltipPosition, viewportRef]);
|
|
223
|
+
return {
|
|
224
|
+
isOpen,
|
|
225
|
+
setIsOpen,
|
|
226
|
+
refs,
|
|
227
|
+
floatingStyles,
|
|
228
|
+
getFloatingProps,
|
|
229
|
+
getReferenceProps
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
var AnnotationTooltip = ({
|
|
233
|
+
annotation,
|
|
234
|
+
children,
|
|
235
|
+
tooltipContent,
|
|
236
|
+
onOpenChange,
|
|
237
|
+
isOpen: controlledIsOpen
|
|
238
|
+
}) => {
|
|
239
|
+
const {
|
|
240
|
+
isOpen: uncontrolledIsOpen,
|
|
241
|
+
setIsOpen,
|
|
242
|
+
refs,
|
|
243
|
+
floatingStyles,
|
|
244
|
+
getFloatingProps,
|
|
245
|
+
getReferenceProps
|
|
246
|
+
} = useAnnotationTooltip({
|
|
247
|
+
annotation,
|
|
248
|
+
onOpenChange
|
|
249
|
+
});
|
|
250
|
+
const isOpen = controlledIsOpen ?? uncontrolledIsOpen;
|
|
251
|
+
const handleClick = useCallback(() => {
|
|
252
|
+
if (controlledIsOpen === void 0) {
|
|
253
|
+
setIsOpen(!isOpen);
|
|
254
|
+
}
|
|
255
|
+
}, [controlledIsOpen, isOpen, setIsOpen]);
|
|
256
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
257
|
+
/* @__PURE__ */ jsx(
|
|
258
|
+
"div",
|
|
259
|
+
{
|
|
260
|
+
ref: refs.setReference,
|
|
261
|
+
onClick: handleClick,
|
|
262
|
+
...getReferenceProps(),
|
|
263
|
+
children
|
|
264
|
+
}
|
|
265
|
+
),
|
|
266
|
+
isOpen && /* @__PURE__ */ jsx(
|
|
267
|
+
"div",
|
|
268
|
+
{
|
|
269
|
+
ref: refs.setFloating,
|
|
270
|
+
className: "bg-white shadow-lg rounded-lg p-3 z-50 min-w-[200px]",
|
|
271
|
+
style: {
|
|
272
|
+
...floatingStyles,
|
|
273
|
+
position: "fixed",
|
|
274
|
+
zIndex: 9999
|
|
275
|
+
},
|
|
276
|
+
...getFloatingProps(),
|
|
277
|
+
children: tooltipContent
|
|
278
|
+
}
|
|
279
|
+
)
|
|
280
|
+
] });
|
|
281
|
+
};
|
|
282
|
+
var useAnnotations = create((set) => ({
|
|
283
|
+
annotations: [],
|
|
284
|
+
addAnnotation: (annotation) => set((state) => ({
|
|
285
|
+
annotations: [
|
|
286
|
+
...state.annotations,
|
|
287
|
+
{
|
|
288
|
+
...annotation,
|
|
289
|
+
id: v4(),
|
|
290
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
291
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
292
|
+
}
|
|
293
|
+
]
|
|
294
|
+
})),
|
|
295
|
+
updateAnnotation: (id, updates) => set((state) => ({
|
|
296
|
+
annotations: state.annotations.map(
|
|
297
|
+
(annotation) => annotation.id === id ? {
|
|
298
|
+
...annotation,
|
|
299
|
+
...updates,
|
|
300
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
301
|
+
} : annotation
|
|
302
|
+
)
|
|
303
|
+
})),
|
|
304
|
+
deleteAnnotation: (id) => set((state) => ({
|
|
305
|
+
annotations: state.annotations.filter((annotation) => annotation.id !== id)
|
|
306
|
+
})),
|
|
307
|
+
setAnnotations: (annotations) => set({ annotations })
|
|
308
|
+
}));
|
|
309
|
+
var PDFPageNumberContext = createContext(0);
|
|
310
|
+
var usePDFPageNumber = () => {
|
|
311
|
+
return useContext(PDFPageNumberContext);
|
|
312
|
+
};
|
|
313
|
+
var useAnnotationActions = ({
|
|
314
|
+
annotation,
|
|
315
|
+
onClose
|
|
316
|
+
}) => {
|
|
317
|
+
const { updateAnnotation } = useAnnotations();
|
|
318
|
+
const [comment, setComment] = useState(annotation.comment || "");
|
|
319
|
+
const [isEditing, setIsEditing] = useState(false);
|
|
320
|
+
const handleSaveComment = useCallback(() => {
|
|
321
|
+
updateAnnotation(annotation.id, { comment });
|
|
322
|
+
setIsEditing(false);
|
|
323
|
+
onClose?.();
|
|
324
|
+
}, [annotation.id, comment, updateAnnotation, onClose]);
|
|
325
|
+
const handleColorChange = useCallback(
|
|
326
|
+
(color) => {
|
|
327
|
+
updateAnnotation(annotation.id, { color });
|
|
328
|
+
onClose?.();
|
|
329
|
+
},
|
|
330
|
+
[annotation.id, updateAnnotation, onClose]
|
|
331
|
+
);
|
|
332
|
+
const handleCancelEdit = useCallback(() => {
|
|
333
|
+
setIsEditing(false);
|
|
334
|
+
onClose?.();
|
|
335
|
+
}, [onClose]);
|
|
336
|
+
const colors = [
|
|
337
|
+
"rgba(255, 255, 0, 0.3)",
|
|
338
|
+
// Yellow
|
|
339
|
+
"rgba(0, 255, 0, 0.3)",
|
|
340
|
+
// Green
|
|
341
|
+
"rgba(255, 182, 193, 0.3)",
|
|
342
|
+
// Pink
|
|
343
|
+
"rgba(135, 206, 235, 0.3)"
|
|
344
|
+
// Sky Blue
|
|
345
|
+
];
|
|
346
|
+
return {
|
|
347
|
+
comment,
|
|
348
|
+
isEditing,
|
|
349
|
+
setComment,
|
|
350
|
+
setIsEditing,
|
|
351
|
+
handleSaveComment,
|
|
352
|
+
handleColorChange,
|
|
353
|
+
handleCancelEdit,
|
|
354
|
+
colors
|
|
355
|
+
};
|
|
356
|
+
};
|
|
357
|
+
var DefaultAnnotationTooltipContent = ({
|
|
358
|
+
annotation,
|
|
359
|
+
onClose
|
|
360
|
+
}) => {
|
|
361
|
+
const {
|
|
362
|
+
comment,
|
|
363
|
+
isEditing,
|
|
364
|
+
setComment,
|
|
365
|
+
setIsEditing,
|
|
366
|
+
handleSaveComment,
|
|
367
|
+
handleColorChange,
|
|
368
|
+
handleCancelEdit,
|
|
369
|
+
colors
|
|
370
|
+
} = useAnnotationActions({
|
|
371
|
+
annotation,
|
|
372
|
+
onClose
|
|
373
|
+
});
|
|
374
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
375
|
+
/* @__PURE__ */ jsx("div", { className: "flex gap-2", children: colors.map((color) => /* @__PURE__ */ jsx(
|
|
376
|
+
"button",
|
|
377
|
+
{
|
|
378
|
+
className: "w-6 h-6 rounded",
|
|
379
|
+
style: { backgroundColor: color },
|
|
380
|
+
onClick: () => handleColorChange(color)
|
|
381
|
+
},
|
|
382
|
+
color
|
|
383
|
+
)) }),
|
|
384
|
+
isEditing ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
385
|
+
/* @__PURE__ */ jsx(
|
|
386
|
+
"textarea",
|
|
387
|
+
{
|
|
388
|
+
value: comment,
|
|
389
|
+
onChange: (e) => setComment(e.target.value),
|
|
390
|
+
className: "border rounded p-2 text-sm",
|
|
391
|
+
placeholder: "Add a comment...",
|
|
392
|
+
rows: 3
|
|
393
|
+
}
|
|
394
|
+
),
|
|
395
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
396
|
+
/* @__PURE__ */ jsx(
|
|
397
|
+
"button",
|
|
398
|
+
{
|
|
399
|
+
onClick: handleCancelEdit,
|
|
400
|
+
className: "px-2 py-1 text-sm text-gray-600 hover:text-gray-800",
|
|
401
|
+
children: "Cancel"
|
|
402
|
+
}
|
|
403
|
+
),
|
|
404
|
+
/* @__PURE__ */ jsx(
|
|
405
|
+
"button",
|
|
406
|
+
{
|
|
407
|
+
onClick: handleSaveComment,
|
|
408
|
+
className: "px-2 py-1 text-sm bg-blue-500 text-white rounded hover:bg-blue-600",
|
|
409
|
+
children: "Save"
|
|
410
|
+
}
|
|
411
|
+
)
|
|
412
|
+
] })
|
|
413
|
+
] }) : /* @__PURE__ */ jsx("div", { children: annotation.comment ? /* @__PURE__ */ jsx("div", { className: "text-sm text-gray-700", children: annotation.comment }) : /* @__PURE__ */ jsx(
|
|
414
|
+
"button",
|
|
415
|
+
{
|
|
416
|
+
onClick: () => setIsEditing(true),
|
|
417
|
+
className: "text-sm text-blue-500 hover:text-blue-600",
|
|
418
|
+
children: "Add comment"
|
|
419
|
+
}
|
|
420
|
+
) })
|
|
421
|
+
] });
|
|
422
|
+
};
|
|
423
|
+
var AnnotationHighlightLayer = ({
|
|
424
|
+
className,
|
|
425
|
+
style,
|
|
426
|
+
renderTooltipContent,
|
|
427
|
+
focusedAnnotationId,
|
|
428
|
+
onAnnotationClick
|
|
429
|
+
}) => {
|
|
430
|
+
const { annotations } = useAnnotations();
|
|
431
|
+
const pageNumber = usePDFPageNumber();
|
|
432
|
+
const pageAnnotations = annotations.filter(
|
|
433
|
+
(annotation) => annotation.pageNumber === pageNumber
|
|
434
|
+
);
|
|
435
|
+
return /* @__PURE__ */ jsx("div", { className, style, children: pageAnnotations.map((annotation) => /* @__PURE__ */ jsx(
|
|
436
|
+
AnnotationTooltip,
|
|
437
|
+
{
|
|
438
|
+
annotation,
|
|
439
|
+
isOpen: focusedAnnotationId === annotation.id,
|
|
440
|
+
onOpenChange: (open) => {
|
|
441
|
+
if (open && onAnnotationClick) {
|
|
442
|
+
onAnnotationClick(annotation);
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
tooltipContent: renderTooltipContent ? renderTooltipContent({
|
|
446
|
+
annotation,
|
|
447
|
+
onClose: () => {
|
|
448
|
+
}
|
|
449
|
+
}) : /* @__PURE__ */ jsx(
|
|
450
|
+
DefaultAnnotationTooltipContent,
|
|
451
|
+
{
|
|
452
|
+
annotation,
|
|
453
|
+
onClose: () => {
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
),
|
|
457
|
+
children: /* @__PURE__ */ jsx(
|
|
458
|
+
"div",
|
|
459
|
+
{
|
|
460
|
+
style: { cursor: "pointer" },
|
|
461
|
+
onClick: () => onAnnotationClick?.(annotation),
|
|
462
|
+
children: annotation.highlights.map((highlight, index) => /* @__PURE__ */ jsx(
|
|
463
|
+
"div",
|
|
464
|
+
{
|
|
465
|
+
style: {
|
|
466
|
+
position: "absolute",
|
|
467
|
+
top: highlight.top,
|
|
468
|
+
left: highlight.left,
|
|
469
|
+
width: highlight.width,
|
|
470
|
+
height: highlight.height,
|
|
471
|
+
backgroundColor: annotation.color || "rgba(255, 255, 0, 0.3)",
|
|
472
|
+
transition: "background-color 0.2s ease",
|
|
473
|
+
cursor: "pointer",
|
|
474
|
+
opacity: focusedAnnotationId === annotation.id ? 1 : 0.5
|
|
475
|
+
}
|
|
476
|
+
},
|
|
477
|
+
index
|
|
478
|
+
))
|
|
479
|
+
}
|
|
480
|
+
)
|
|
481
|
+
},
|
|
482
|
+
annotation.id
|
|
483
|
+
)) });
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
// ../../node_modules/.pnpm/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs
|
|
487
|
+
function r(e) {
|
|
488
|
+
var t, f, n = "";
|
|
489
|
+
if ("string" == typeof e || "number" == typeof e) n += e;
|
|
490
|
+
else if ("object" == typeof e) if (Array.isArray(e)) {
|
|
491
|
+
var o = e.length;
|
|
492
|
+
for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
|
|
493
|
+
} else for (f in e) e[f] && (n && (n += " "), n += f);
|
|
494
|
+
return n;
|
|
495
|
+
}
|
|
496
|
+
function clsx() {
|
|
497
|
+
for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
|
|
498
|
+
return n;
|
|
499
|
+
}
|
|
500
|
+
var clsx_default = clsx;
|
|
501
|
+
|
|
149
502
|
// src/lib/cancellable.ts
|
|
150
503
|
var cancellable = (promise) => {
|
|
151
504
|
let isCancelled = false;
|
|
@@ -184,9 +537,9 @@ var usePdfJump = () => {
|
|
|
184
537
|
const finalOptions = { ...defaultOptions, ...options };
|
|
185
538
|
virtualizer.scrollToIndex(pageIndex - 1, finalOptions);
|
|
186
539
|
};
|
|
187
|
-
const jumpToOffset = (
|
|
540
|
+
const jumpToOffset = (offset3) => {
|
|
188
541
|
if (!virtualizer) return;
|
|
189
|
-
virtualizer.scrollToOffset(
|
|
542
|
+
virtualizer.scrollToOffset(offset3, {
|
|
190
543
|
align: "start",
|
|
191
544
|
behavior: "smooth"
|
|
192
545
|
});
|
|
@@ -387,10 +740,6 @@ var PDFLinkServiceContext = createContext(defaultLinkService);
|
|
|
387
740
|
var usePDFLinkService = () => {
|
|
388
741
|
return useContext(PDFLinkServiceContext);
|
|
389
742
|
};
|
|
390
|
-
var PDFPageNumberContext = createContext(0);
|
|
391
|
-
var usePDFPageNumber = () => {
|
|
392
|
-
return useContext(PDFPageNumberContext);
|
|
393
|
-
};
|
|
394
743
|
var useVisibility = ({
|
|
395
744
|
elementRef
|
|
396
745
|
}) => {
|
|
@@ -1336,6 +1685,7 @@ var Page = ({
|
|
|
1336
1685
|
style: {
|
|
1337
1686
|
...style,
|
|
1338
1687
|
"--scale-factor": 1,
|
|
1688
|
+
"--total-scale-factor": 1,
|
|
1339
1689
|
position: "relative",
|
|
1340
1690
|
width,
|
|
1341
1691
|
height
|
|
@@ -1442,21 +1792,21 @@ var useObserveElement = () => {
|
|
|
1442
1792
|
if (!targetWindow) {
|
|
1443
1793
|
return;
|
|
1444
1794
|
}
|
|
1445
|
-
let
|
|
1795
|
+
let offset3 = 0;
|
|
1446
1796
|
const fallback = instance.options.useScrollendEvent && supportsScrollend ? () => void 0 : debounce(
|
|
1447
1797
|
targetWindow,
|
|
1448
1798
|
() => {
|
|
1449
|
-
cb(
|
|
1799
|
+
cb(offset3, false);
|
|
1450
1800
|
},
|
|
1451
1801
|
instance.options.isScrollingResetDelay
|
|
1452
1802
|
);
|
|
1453
1803
|
const createHandler = (isScrolling) => () => {
|
|
1454
1804
|
const { horizontal, isRtl } = instance.options;
|
|
1455
|
-
|
|
1805
|
+
offset3 = horizontal ? element["scrollLeft"] * (isRtl && -1 || 1) : element["scrollTop"];
|
|
1456
1806
|
const zoom = store.getState().zoom;
|
|
1457
|
-
|
|
1807
|
+
offset3 = offset3 / zoom;
|
|
1458
1808
|
fallback();
|
|
1459
|
-
cb(
|
|
1809
|
+
cb(offset3, isScrolling);
|
|
1460
1810
|
};
|
|
1461
1811
|
const handler = createHandler(true);
|
|
1462
1812
|
const endHandler = createHandler(false);
|
|
@@ -1477,8 +1827,8 @@ var useScrollFn = () => {
|
|
|
1477
1827
|
const scrollToFn = useCallback(
|
|
1478
1828
|
(_offset, canSmooth, instance) => {
|
|
1479
1829
|
const zoom = store.getState().zoom;
|
|
1480
|
-
const
|
|
1481
|
-
elementScroll(
|
|
1830
|
+
const offset3 = _offset * zoom;
|
|
1831
|
+
elementScroll(offset3, canSmooth, instance);
|
|
1482
1832
|
},
|
|
1483
1833
|
[store]
|
|
1484
1834
|
);
|
|
@@ -2593,10 +2943,10 @@ var PinchEngine = class extends Engine {
|
|
|
2593
2943
|
}
|
|
2594
2944
|
computeMovement() {
|
|
2595
2945
|
const {
|
|
2596
|
-
offset:
|
|
2946
|
+
offset: offset3,
|
|
2597
2947
|
lastOffset
|
|
2598
2948
|
} = this.state;
|
|
2599
|
-
this.state.movement = [
|
|
2949
|
+
this.state.movement = [offset3[0] / lastOffset[0], offset3[1] - lastOffset[1]];
|
|
2600
2950
|
}
|
|
2601
2951
|
axisIntent() {
|
|
2602
2952
|
const state = this.state;
|
|
@@ -4153,4 +4503,4 @@ function mergeAdjacentRects(rects) {
|
|
|
4153
4503
|
return merged;
|
|
4154
4504
|
}
|
|
4155
4505
|
|
|
4156
|
-
export { AnnotationLayer2 as AnnotationLayer, CanvasLayer, ColoredHighlightLayer, CurrentPage, CurrentZoom, CustomLayer, HighlightLayer, LinkService, NextPage, Outline, OutlineChildItems, OutlineItem, Page, Pages, PreviousPage, Root, Search, SelectionTooltip, TextLayer2 as TextLayer, Thumbnail, Thumbnails, TotalPages, ZoomIn, ZoomOut, calculateHighlightRects, usePdf, usePdfJump, useSearch, useSelectionDimensions };
|
|
4506
|
+
export { AnnotationHighlightLayer, AnnotationLayer2 as AnnotationLayer, AnnotationTooltip, CanvasLayer, ColoredHighlightLayer, CurrentPage, CurrentZoom, CustomLayer, HighlightLayer, LinkService, NextPage, Outline, OutlineChildItems, OutlineItem, Page, Pages, PreviousPage, Root, Search, SelectionTooltip, TextLayer2 as TextLayer, Thumbnail, Thumbnails, TotalPages, ZoomIn, ZoomOut, calculateHighlightRects, useAnnotations, usePDFPageNumber, usePdf, usePdfJump, useSearch, useSelectionDimensions };
|