@anaralabs/lector 3.13.0 → 3.13.1
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/index.js +42 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1839,6 +1839,7 @@ var subscribeToViewportInvalidation = (viewport, callback) => {
|
|
|
1839
1839
|
|
|
1840
1840
|
// src/hooks/layers/useDetailCanvasLayer.tsx
|
|
1841
1841
|
var DETAIL_RENDER_IDLE_MS = 80;
|
|
1842
|
+
var ZOOM_SETTLE_MS = 250;
|
|
1842
1843
|
var useDetailCanvasLayer = ({
|
|
1843
1844
|
background,
|
|
1844
1845
|
baseCanvasRef
|
|
@@ -1858,6 +1859,14 @@ var useDetailCanvasLayer = ({
|
|
|
1858
1859
|
const recolorKey = recolor ? `dark:${darkModeColors.background},${darkModeColors.foreground}` : "light";
|
|
1859
1860
|
const paintedKeyRef = useRef(null);
|
|
1860
1861
|
const [zoom] = useDebounce(bouncyZoom, 200);
|
|
1862
|
+
const lastZoomChangeRef = useRef(
|
|
1863
|
+
store.getState().isPinching ? performance.now() : 0
|
|
1864
|
+
);
|
|
1865
|
+
const prevBouncyZoomRef = useRef(bouncyZoom);
|
|
1866
|
+
if (prevBouncyZoomRef.current !== bouncyZoom) {
|
|
1867
|
+
prevBouncyZoomRef.current = bouncyZoom;
|
|
1868
|
+
lastZoomChangeRef.current = performance.now();
|
|
1869
|
+
}
|
|
1861
1870
|
const pageDimsRef = useRef(null);
|
|
1862
1871
|
if (!pageDimsRef.current || pageDimsRef.current.proxy !== pdfPageProxy) {
|
|
1863
1872
|
const vp = pdfPageProxy.getViewport({ scale: 1 });
|
|
@@ -1893,6 +1902,10 @@ var useDetailCanvasLayer = ({
|
|
|
1893
1902
|
scheduleRender(160);
|
|
1894
1903
|
return;
|
|
1895
1904
|
}
|
|
1905
|
+
if (store.getState().isPinching || performance.now() - lastZoomChangeRef.current < ZOOM_SETTLE_MS) {
|
|
1906
|
+
scheduleRender(160);
|
|
1907
|
+
return;
|
|
1908
|
+
}
|
|
1896
1909
|
const pageContainer = baseCanvasRef.current?.parentElement ?? null;
|
|
1897
1910
|
if (!pageContainer) {
|
|
1898
1911
|
hideDetailCanvas();
|
|
@@ -3080,6 +3093,7 @@ var useTextLayer = () => {
|
|
|
3080
3093
|
const pageNumber = usePDFPageNumber();
|
|
3081
3094
|
const pdfPageProxy = usePdf((state) => state.getPdfPageProxy(pageNumber));
|
|
3082
3095
|
const viewportRef = usePdf((state) => state.viewportRef);
|
|
3096
|
+
const store = PDFStore.useContext();
|
|
3083
3097
|
useEffect(() => {
|
|
3084
3098
|
const textContainer = textContainerRef.current;
|
|
3085
3099
|
if (!textContainer) {
|
|
@@ -3184,11 +3198,22 @@ var useTextLayer = () => {
|
|
|
3184
3198
|
const show = () => {
|
|
3185
3199
|
textContainer.style.visibility = "";
|
|
3186
3200
|
};
|
|
3187
|
-
const
|
|
3201
|
+
const restoreWhenSettled = () => {
|
|
3202
|
+
settleTimer = null;
|
|
3203
|
+
if (store.getState().isPinching) {
|
|
3204
|
+
settleTimer = setTimeout(restoreWhenSettled, TEXT_SCROLL_SETTLE_MS);
|
|
3205
|
+
return;
|
|
3206
|
+
}
|
|
3207
|
+
show();
|
|
3208
|
+
};
|
|
3209
|
+
const hideAndDebounce = () => {
|
|
3188
3210
|
if (selecting) return;
|
|
3189
3211
|
textContainer.style.visibility = "hidden";
|
|
3190
3212
|
if (settleTimer) clearTimeout(settleTimer);
|
|
3191
|
-
settleTimer = setTimeout(
|
|
3213
|
+
settleTimer = setTimeout(restoreWhenSettled, TEXT_SCROLL_SETTLE_MS);
|
|
3214
|
+
};
|
|
3215
|
+
const onScroll = () => {
|
|
3216
|
+
hideAndDebounce();
|
|
3192
3217
|
};
|
|
3193
3218
|
const onPointerDown = () => {
|
|
3194
3219
|
pointerDown = true;
|
|
@@ -3220,6 +3245,19 @@ var useTextLayer = () => {
|
|
|
3220
3245
|
unsubscribe = subscribeToViewportInvalidation(scrollViewport, onScroll);
|
|
3221
3246
|
};
|
|
3222
3247
|
attachScrollSubscription();
|
|
3248
|
+
const initialState = store.getState();
|
|
3249
|
+
let prevZoom = initialState.zoom;
|
|
3250
|
+
let prevPinching = initialState.isPinching;
|
|
3251
|
+
if (prevPinching) hideAndDebounce();
|
|
3252
|
+
const unsubscribeStore = store.subscribe(
|
|
3253
|
+
(state) => {
|
|
3254
|
+
const zoomChanged = state.zoom !== prevZoom;
|
|
3255
|
+
const pinchStarted = state.isPinching && !prevPinching;
|
|
3256
|
+
prevZoom = state.zoom;
|
|
3257
|
+
prevPinching = state.isPinching;
|
|
3258
|
+
if (zoomChanged || pinchStarted) hideAndDebounce();
|
|
3259
|
+
}
|
|
3260
|
+
);
|
|
3223
3261
|
document.addEventListener("pointerdown", onPointerDown, true);
|
|
3224
3262
|
document.addEventListener("pointerup", clearPointer, true);
|
|
3225
3263
|
document.addEventListener("pointercancel", clearPointer, true);
|
|
@@ -3228,6 +3266,7 @@ var useTextLayer = () => {
|
|
|
3228
3266
|
return () => {
|
|
3229
3267
|
if (attachRaf !== null) cancelAnimationFrame(attachRaf);
|
|
3230
3268
|
unsubscribe?.();
|
|
3269
|
+
unsubscribeStore();
|
|
3231
3270
|
document.removeEventListener("pointerdown", onPointerDown, true);
|
|
3232
3271
|
document.removeEventListener("pointerup", clearPointer, true);
|
|
3233
3272
|
document.removeEventListener("pointercancel", clearPointer, true);
|
|
@@ -3236,7 +3275,7 @@ var useTextLayer = () => {
|
|
|
3236
3275
|
if (settleTimer) clearTimeout(settleTimer);
|
|
3237
3276
|
show();
|
|
3238
3277
|
};
|
|
3239
|
-
}, [viewportRef]);
|
|
3278
|
+
}, [viewportRef, store]);
|
|
3240
3279
|
return {
|
|
3241
3280
|
textContainerRef,
|
|
3242
3281
|
pageNumber: pdfPageProxy.pageNumber
|