@anaralabs/lector 3.7.1 → 3.7.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 +1 -1
- package/dist/index.js +102 -11
- package/package.json +4 -4
|
@@ -145,7 +145,7 @@ export declare const CanvasLayer: ({ style, background, ...props }: HTMLProps<HT
|
|
|
145
145
|
background?: string;
|
|
146
146
|
}) => JSX.Element;
|
|
147
147
|
|
|
148
|
-
export declare const clamp: (value: number,
|
|
148
|
+
export declare const clamp: (value: number, minimum: number, maximum: number) => number;
|
|
149
149
|
|
|
150
150
|
declare type CollapsibleSelection = {
|
|
151
151
|
highlights: HighlightRect[];
|
package/dist/index.js
CHANGED
|
@@ -14,8 +14,8 @@ import { useVirtualizer, elementScroll, debounce } from '@tanstack/react-virtual
|
|
|
14
14
|
// src/components/annotation-tooltip.tsx
|
|
15
15
|
|
|
16
16
|
// src/lib/clamp.ts
|
|
17
|
-
var clamp = (value,
|
|
18
|
-
return Math.min(Math.max(value,
|
|
17
|
+
var clamp = (value, minimum, maximum) => {
|
|
18
|
+
return Math.min(Math.max(value, minimum), maximum);
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
// src/lib/zoom.ts
|
|
@@ -4543,7 +4543,7 @@ function parseMergedHandlers(mergedHandlers, mergedConfig) {
|
|
|
4543
4543
|
};
|
|
4544
4544
|
}
|
|
4545
4545
|
|
|
4546
|
-
// ../../node_modules/.pnpm/@use-gesture+react@10.3.1_react@
|
|
4546
|
+
// ../../node_modules/.pnpm/@use-gesture+react@10.3.1_react@19.2.0/node_modules/@use-gesture/react/dist/use-gesture-react.esm.js
|
|
4547
4547
|
function useRecognizers(handlers, config = {}, gestureKey, nativeHandlers) {
|
|
4548
4548
|
const ctrl = React.useMemo(() => new Controller(handlers), []);
|
|
4549
4549
|
ctrl.applyHandlers(handlers, nativeHandlers);
|
|
@@ -4587,12 +4587,21 @@ var firstMemo = (first, memo, initializer) => {
|
|
|
4587
4587
|
};
|
|
4588
4588
|
|
|
4589
4589
|
// src/hooks/viewport/useViewportContainer.tsx
|
|
4590
|
+
var WHEEL_ZOOM_SENSITIVITY = 0.01;
|
|
4591
|
+
var WHEEL_INERTIA_GAP_MS = 140;
|
|
4592
|
+
var WHEEL_INERTIA_ESCAPE_FACTOR = 1.35;
|
|
4590
4593
|
var useViewportContainer = ({
|
|
4591
4594
|
containerRef,
|
|
4592
4595
|
elementWrapperRef,
|
|
4593
4596
|
elementRef
|
|
4594
4597
|
}) => {
|
|
4595
4598
|
const [origin, setOrigin] = useState([0, 0]);
|
|
4599
|
+
const wheelInertia = useRef({
|
|
4600
|
+
active: false,
|
|
4601
|
+
lastTime: 0,
|
|
4602
|
+
lastAbsDeltaY: 0,
|
|
4603
|
+
lastSign: 0
|
|
4604
|
+
});
|
|
4596
4605
|
const { maxZoom, minZoom } = usePdf((state) => state.zoomOptions);
|
|
4597
4606
|
const zoom = usePdf((state) => state.zoom);
|
|
4598
4607
|
const viewportRef = usePdf((state) => state.viewportRef);
|
|
@@ -4628,7 +4637,17 @@ var useViewportContainer = ({
|
|
|
4628
4637
|
if (transformations.current.zoom === zoom || !containerRef.current) {
|
|
4629
4638
|
return;
|
|
4630
4639
|
}
|
|
4631
|
-
const
|
|
4640
|
+
const prevZoom = transformations.current.zoom;
|
|
4641
|
+
if (!prevZoom || !Number.isFinite(prevZoom)) {
|
|
4642
|
+
transformations.current = {
|
|
4643
|
+
translateX: containerRef.current.scrollLeft,
|
|
4644
|
+
translateY: containerRef.current.scrollTop,
|
|
4645
|
+
zoom
|
|
4646
|
+
};
|
|
4647
|
+
updateTransform();
|
|
4648
|
+
return;
|
|
4649
|
+
}
|
|
4650
|
+
const dZoom = zoom / prevZoom;
|
|
4632
4651
|
transformations.current = {
|
|
4633
4652
|
translateX: containerRef.current.scrollLeft * dZoom,
|
|
4634
4653
|
translateY: containerRef.current.scrollTop * dZoom,
|
|
@@ -4645,16 +4664,67 @@ var useViewportContainer = ({
|
|
|
4645
4664
|
document.removeEventListener("gesturechange", preventDefault);
|
|
4646
4665
|
};
|
|
4647
4666
|
}, []);
|
|
4667
|
+
useEffect(() => {
|
|
4668
|
+
const container = containerRef.current;
|
|
4669
|
+
if (!container) return;
|
|
4670
|
+
const sign = (n) => n === 0 ? 0 : n > 0 ? 1 : -1;
|
|
4671
|
+
const handleWheelCapture = (event) => {
|
|
4672
|
+
const st = wheelInertia.current;
|
|
4673
|
+
const now = Date.now();
|
|
4674
|
+
const ctrl = event.ctrlKey || event.metaKey;
|
|
4675
|
+
const abs = Math.abs(event.deltaY);
|
|
4676
|
+
const s = sign(event.deltaY);
|
|
4677
|
+
if (ctrl) {
|
|
4678
|
+
st.active = true;
|
|
4679
|
+
st.lastTime = now;
|
|
4680
|
+
st.lastAbsDeltaY = abs;
|
|
4681
|
+
st.lastSign = s;
|
|
4682
|
+
event.preventDefault();
|
|
4683
|
+
return;
|
|
4684
|
+
}
|
|
4685
|
+
if (!st.active) {
|
|
4686
|
+
return;
|
|
4687
|
+
}
|
|
4688
|
+
if (now - st.lastTime > WHEEL_INERTIA_GAP_MS) {
|
|
4689
|
+
st.active = false;
|
|
4690
|
+
return;
|
|
4691
|
+
}
|
|
4692
|
+
if (st.lastSign !== 0 && s !== 0 && s !== st.lastSign) {
|
|
4693
|
+
st.active = false;
|
|
4694
|
+
return;
|
|
4695
|
+
}
|
|
4696
|
+
if (st.lastAbsDeltaY > 0 && abs > st.lastAbsDeltaY * WHEEL_INERTIA_ESCAPE_FACTOR + 1) {
|
|
4697
|
+
st.active = false;
|
|
4698
|
+
return;
|
|
4699
|
+
}
|
|
4700
|
+
st.lastTime = now;
|
|
4701
|
+
st.lastAbsDeltaY = abs;
|
|
4702
|
+
st.lastSign = s;
|
|
4703
|
+
event.preventDefault();
|
|
4704
|
+
};
|
|
4705
|
+
container.addEventListener("wheel", handleWheelCapture, {
|
|
4706
|
+
passive: false,
|
|
4707
|
+
capture: true
|
|
4708
|
+
});
|
|
4709
|
+
return () => {
|
|
4710
|
+
container.removeEventListener("wheel", handleWheelCapture, {
|
|
4711
|
+
capture: true
|
|
4712
|
+
});
|
|
4713
|
+
};
|
|
4714
|
+
}, [containerRef]);
|
|
4648
4715
|
useGesture(
|
|
4649
4716
|
{
|
|
4650
|
-
onPinch: (
|
|
4717
|
+
onPinch: (state) => {
|
|
4718
|
+
const { origin: origin2, first, movement, delta, event, memo } = state;
|
|
4719
|
+
const [ms] = movement;
|
|
4720
|
+
const [deltaScale] = delta;
|
|
4651
4721
|
const currentElement = elementRef.current;
|
|
4652
4722
|
const currentContainer = containerRef.current;
|
|
4653
4723
|
if (!currentElement || !currentContainer) return;
|
|
4654
|
-
if (!elementRef.current || !containerRef.current) return;
|
|
4655
4724
|
const newMemo = firstMemo(first, memo, () => {
|
|
4656
4725
|
const elementRect = currentElement.getBoundingClientRect();
|
|
4657
4726
|
const containerRect = currentContainer.getBoundingClientRect();
|
|
4727
|
+
const currentZoom = transformations.current.zoom;
|
|
4658
4728
|
const contentPosition = [
|
|
4659
4729
|
origin2[0] - elementRect.left,
|
|
4660
4730
|
origin2[1] - elementRect.top
|
|
@@ -4664,17 +4734,37 @@ var useViewportContainer = ({
|
|
|
4664
4734
|
origin2[1] - containerRect.top
|
|
4665
4735
|
];
|
|
4666
4736
|
setOrigin([
|
|
4667
|
-
contentPosition[0] /
|
|
4668
|
-
contentPosition[1] /
|
|
4737
|
+
contentPosition[0] / currentZoom,
|
|
4738
|
+
contentPosition[1] / currentZoom
|
|
4669
4739
|
]);
|
|
4670
4740
|
return {
|
|
4671
4741
|
contentPosition,
|
|
4672
4742
|
containerPosition,
|
|
4673
|
-
originZoom:
|
|
4674
|
-
|
|
4743
|
+
originZoom: currentZoom,
|
|
4744
|
+
lastZoom: currentZoom
|
|
4675
4745
|
};
|
|
4676
4746
|
});
|
|
4677
|
-
|
|
4747
|
+
if (first) {
|
|
4748
|
+
return newMemo;
|
|
4749
|
+
}
|
|
4750
|
+
const gestureValuesValid = Number.isFinite(ms) && ms > 0;
|
|
4751
|
+
let effectiveScale = ms;
|
|
4752
|
+
if (!gestureValuesValid) {
|
|
4753
|
+
const wheelEvent = event;
|
|
4754
|
+
if (wheelEvent?.deltaY !== void 0) {
|
|
4755
|
+
const wheelDelta = -wheelEvent.deltaY * WHEEL_ZOOM_SENSITIVITY;
|
|
4756
|
+
effectiveScale = newMemo.lastZoom / newMemo.originZoom * (1 + wheelDelta);
|
|
4757
|
+
} else if (Number.isFinite(deltaScale) && deltaScale !== 0) {
|
|
4758
|
+
effectiveScale = newMemo.lastZoom / newMemo.originZoom * (1 + deltaScale);
|
|
4759
|
+
} else {
|
|
4760
|
+
return newMemo;
|
|
4761
|
+
}
|
|
4762
|
+
}
|
|
4763
|
+
const newZoom = clamp(
|
|
4764
|
+
effectiveScale * newMemo.originZoom,
|
|
4765
|
+
minZoom,
|
|
4766
|
+
maxZoom
|
|
4767
|
+
);
|
|
4678
4768
|
const realMs = newZoom / newMemo.originZoom;
|
|
4679
4769
|
const newTranslateX = newMemo.contentPosition[0] * realMs - newMemo.containerPosition[0];
|
|
4680
4770
|
const newTranslateY = newMemo.contentPosition[1] * realMs - newMemo.containerPosition[1];
|
|
@@ -4683,6 +4773,7 @@ var useViewportContainer = ({
|
|
|
4683
4773
|
translateX: newTranslateX,
|
|
4684
4774
|
translateY: newTranslateY
|
|
4685
4775
|
};
|
|
4776
|
+
newMemo.lastZoom = newZoom;
|
|
4686
4777
|
updateTransform(true);
|
|
4687
4778
|
return newMemo;
|
|
4688
4779
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anaralabs/lector",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.3",
|
|
4
4
|
"description": "Headless PDF viewer for React",
|
|
5
5
|
"author": "andrewdr (https://github.com/andrewdoro)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"clsx": "^2.1.1",
|
|
47
47
|
"pdfjs-dist": "^4.10.38",
|
|
48
48
|
"playwright": "^1.45.3",
|
|
49
|
-
"react": "^
|
|
49
|
+
"react": "^19.1.1",
|
|
50
50
|
"size-limit": "^11.1.6",
|
|
51
51
|
"tsc-alias": "^1.8.10",
|
|
52
52
|
"tslib": "^2.6.3",
|
|
@@ -58,13 +58,13 @@
|
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"pdfjs-dist": "^4.9",
|
|
61
|
-
"react": ">=
|
|
61
|
+
"react": ">=19"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@floating-ui/react": "^0.26.28",
|
|
65
65
|
"@radix-ui/react-slot": "^1.1.0",
|
|
66
66
|
"@tanstack/react-virtual": "^3.10.9",
|
|
67
|
-
"react-dom": "
|
|
67
|
+
"react-dom": "^19.1.1",
|
|
68
68
|
"use-debounce": "^10.0.4",
|
|
69
69
|
"uuid": "^11.1.0",
|
|
70
70
|
"zustand": "^5.0.2"
|