Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: add proper zoom

Marc Seitzb1d0def2de15
diff --git a/components/view/PagesViewerNew.tsx b/components/view/PagesViewerNew.tsx
index b432d5e5..7117fc45 100644
--- a/components/view/PagesViewerNew.tsx
+++ b/components/view/PagesViewerNew.tsx
@@ -269,7 +269,7 @@ export default function PagesViewer({
if (!container) return;
const scrollPosition = container.scrollTop;
- const pageHeight = container.clientHeight;
+ const pageHeight = container.scrollHeight / numPagesWithAccountCreation;
const currentPage = Math.floor(scrollPosition / pageHeight) + 1;
const currentPageFraction = (scrollPosition % pageHeight) / pageHeight;
@@ -412,7 +412,8 @@ export default function PagesViewer({
if (isVertical) {
scrollActionRef.current = true;
const newScrollPosition =
- (pageNumber - 2) * containerRef.current!.clientHeight;
+ ((pageNumber - 2) * containerRef.current!.scrollHeight) /
+ numPagesWithAccountCreation;
containerRef.current?.scrollTo({
top: newScrollPosition,
behavior: "smooth",
@@ -427,7 +428,8 @@ export default function PagesViewer({
if (isVertical) {
scrollActionRef.current = true;
const newScrollPosition =
- (pageNumber - 2) * containerRef.current!.clientHeight;
+ ((pageNumber - 2) * containerRef.current!.scrollHeight) /
+ numPagesWithAccountCreation;
containerRef.current?.scrollTo({
top: newScrollPosition,
behavior: "smooth",
@@ -453,7 +455,8 @@ export default function PagesViewer({
if (isVertical) {
scrollActionRef.current = true;
const newScrollPosition =
- (pageNumber - 2) * containerRef.current!.clientHeight;
+ ((pageNumber - 2) * containerRef.current!.scrollHeight) /
+ numPagesWithAccountCreation;
containerRef.current?.scrollTo({
top: newScrollPosition,
behavior: "smooth",
@@ -472,7 +475,8 @@ export default function PagesViewer({
if (isVertical) {
scrollActionRef.current = true;
const newScrollPosition =
- pageNumber * containerRef.current!.clientHeight;
+ (pageNumber * containerRef.current!.scrollHeight) /
+ numPagesWithAccountCreation;
containerRef.current?.scrollTo({
top: newScrollPosition,
behavior: "smooth",
@@ -499,7 +503,10 @@ export default function PagesViewer({
if (isVertical) {
scrollActionRef.current = true;
- const newScrollPosition = pageNumber * containerRef.current!.clientHeight;
+ const newScrollPosition =
+ (pageNumber * containerRef.current!.scrollHeight) /
+ numPagesWithAccountCreation;
+ console.log("newScrollPosition", newScrollPosition);
containerRef.current?.scrollTo({
top: newScrollPosition,
behavior: "smooth",
@@ -614,21 +621,44 @@ export default function PagesViewer({
<TransformWrapper
key={index}
initialScale={scale}
- panning={{ disabled: scale === 1, velocityDisabled: true }}
- wheel={{ disabled: scale === 1 }}
+ initialPositionX={0}
+ initialPositionY={0}
+ panning={{
+ // disabled: isVertical,
+ lockAxisY: isVertical,
+ velocityDisabled: true,
+ wheelPanning: false,
+ }}
+ wheel={{ disabled: true }}
+ pinch={{ disabled: true }}
+ doubleClick={{ disabled: true }}
onZoom={(ref) => {
setScale(ref.state.scale);
}}
ref={(ref) => {
pinchRefs.current[index] = ref;
}}
+ customTransform={(x: number, y: number, scale: number) => {
+ // Keep the translateY value constant
+ if (isVertical) {
+ const transform = `translate(${x}px, ${index * y * -2}px) scale(${scale})`;
+ return transform;
+ }
+ const transform = `translate(${x}px, ${y}px) scale(${scale})`;
+ return transform;
+ }}
>
- <TransformComponent>
+ <TransformComponent
+ wrapperClass={cn(
+ isVertical && "!overflow-x-clip !overflow-y-visible",
+ )}
+ contentClass={cn(isVertical && "!w-screen")}
+ >
<div
key={index}
style={{ height: "calc(100vh - 64px)" }}
className={cn(
- "relative h-screen w-full",
+ "relative w-full",
pageNumber - 1 === index
? "block"
: !isVertical
diff --git a/components/view/nav.tsx b/components/view/nav.tsx
index 90837916..29c57387 100644
--- a/components/view/nav.tsx
+++ b/components/view/nav.tsx
@@ -8,6 +8,7 @@ import { Brand, DataroomBrand } from "@prisma/client";
import {
ArrowUpRight,
Download,
+ Minimize2Icon,
Slash,
ZoomInIcon,
ZoomOutIcon,
@@ -218,9 +219,9 @@ export default function Nav({
<div className="flex gap-1">
<Button
onClick={() =>
- documentRefs.current[pageNumber! - 1]?.zoomIn()
+ documentRefs.current.map((ref) => ref?.zoomIn())
}
- className=" bg-gray-900 text-white hover:bg-gray-900/80"
+ className="bg-gray-900 text-white hover:bg-gray-900/80"
size="icon"
title="Zoom in"
>
@@ -228,14 +229,24 @@ export default function Nav({
</Button>
<Button
onClick={() =>
- documentRefs.current[pageNumber! - 1]?.zoomOut()
+ documentRefs.current.map((ref) => ref?.zoomOut())
}
- className=" bg-gray-900 text-white hover:bg-gray-900/80"
+ className="bg-gray-900 text-white hover:bg-gray-900/80"
size="icon"
title="Zoom out"
>
<ZoomOutIcon className="h-5 w-5" />
</Button>
+ <Button
+ onClick={() =>
+ documentRefs.current.map((ref) => ref?.resetTransform())
+ }
+ className="bg-gray-900 text-white hover:bg-gray-900/80"
+ size="icon"
+ title="Reset zoom"
+ >
+ <Minimize2Icon className="h-5 w-5" />
+ </Button>
</div>
) : null}
{pageNumber && numPages ? (