|
1 | 1 | import { useRef, useState } from 'react'; |
2 | 2 | import raf from './raf'; |
3 | | -import { getClientSize } from './util'; |
| 3 | +// import { getClientSize } from './util'; |
4 | 4 |
|
5 | 5 | function isEqual(objA, objB) { |
6 | 6 | const keys = Object.keys(objA); |
@@ -63,7 +63,7 @@ export function useImageTransform( |
63 | 63 | minScale: number, |
64 | 64 | maxScale: number, |
65 | 65 | onTransform?: (info: { transform: TransformType; action: TransformAction }) => void, |
66 | | - currentIndex?: number, |
| 66 | + // currentIndex?: number, |
67 | 67 | ) { |
68 | 68 | const frame = useRef(null); |
69 | 69 | const queue = useRef<TransformType[]>([]); |
@@ -101,57 +101,57 @@ export function useImageTransform( |
101 | 101 |
|
102 | 102 | /** Scale according to the position of centerX and centerY */ |
103 | 103 | const dispatchZoomChange: DispatchZoomChangeFunc = (ratio, action, centerX?, centerY?, isTouch?) => { |
104 | | - const { width, height, offsetWidth, offsetHeight, offsetLeft, offsetTop } = imgRef.current[currentIndex]; |
| 104 | + // const { width, height, offsetWidth, offsetHeight, offsetLeft, offsetTop } = imgRef.current[currentIndex]; |
105 | 105 |
|
106 | | - let newRatio = ratio; |
| 106 | + // let newRatio = ratio; |
107 | 107 | let newScale = transform.scale * ratio; |
108 | 108 | if (newScale > maxScale) { |
109 | 109 | newScale = maxScale; |
110 | | - newRatio = maxScale / transform.scale; |
| 110 | + // newRatio = maxScale / transform.scale; |
111 | 111 | } else if (newScale < minScale) { |
112 | 112 | // For mobile interactions, allow scaling down to the minimum scale. |
113 | 113 | newScale = isTouch ? newScale : minScale; |
114 | | - newRatio = newScale / transform.scale; |
| 114 | + // newRatio = newScale / transform.scale; |
115 | 115 | } |
116 | 116 |
|
117 | 117 | /** Default center point scaling */ |
118 | | - const mergedCenterX = centerX ?? innerWidth / 2; |
119 | | - const mergedCenterY = centerY ?? innerHeight / 2; |
120 | | - |
121 | | - const diffRatio = newRatio - 1; |
122 | | - /** Deviation calculated from image size */ |
123 | | - const diffImgX = diffRatio * width * 0.5; |
124 | | - const diffImgY = diffRatio * height * 0.5; |
125 | | - /** The difference between the click position and the edge of the document */ |
126 | | - const diffOffsetLeft = diffRatio * (mergedCenterX - transform.x - offsetLeft); |
127 | | - const diffOffsetTop = diffRatio * (mergedCenterY - transform.y - offsetTop); |
128 | | - /** Final positioning */ |
129 | | - let newX = transform.x - (diffOffsetLeft - diffImgX); |
130 | | - let newY = transform.y - (diffOffsetTop - diffImgY); |
| 118 | + // const mergedCenterX = centerX ?? innerWidth / 2; |
| 119 | + // const mergedCenterY = centerY ?? innerHeight / 2; |
| 120 | + |
| 121 | + // const diffRatio = newRatio - 1; |
| 122 | + // /** Deviation calculated from image size */ |
| 123 | + // const diffImgX = diffRatio * width * 0.5; |
| 124 | + // const diffImgY = diffRatio * height * 0.5; |
| 125 | + // /** The difference between the click position and the edge of the document */ |
| 126 | + // const diffOffsetLeft = diffRatio * (mergedCenterX - transform.x - offsetLeft); |
| 127 | + // const diffOffsetTop = diffRatio * (mergedCenterY - transform.y - offsetTop); |
| 128 | + // /** Final positioning */ |
| 129 | + // let newX = transform.x - (diffOffsetLeft - diffImgX); |
| 130 | + // let newY = transform.y - (diffOffsetTop - diffImgY); |
131 | 131 |
|
132 | 132 | /** |
133 | 133 | * When zooming the image |
134 | 134 | * When the image size is smaller than the width and height of the window, the position is initialized |
135 | 135 | */ |
136 | | - if (ratio < 1 && newScale === 1) { |
137 | | - const mergedWidth = offsetWidth * newScale; |
138 | | - const mergedHeight = offsetHeight * newScale; |
139 | | - const { width: clientWidth, height: clientHeight } = getClientSize(); |
140 | | - if (mergedWidth <= clientWidth && mergedHeight <= clientHeight) { |
141 | | - newX = 0; |
142 | | - newY = 0; |
143 | | - } |
144 | | - } |
| 136 | + // if (ratio < 1 && newScale === 1) { |
| 137 | + // const mergedWidth = offsetWidth * newScale; |
| 138 | + // const mergedHeight = offsetHeight * newScale; |
| 139 | + // const { width: clientWidth, height: clientHeight } = getClientSize(); |
| 140 | + // if (mergedWidth <= clientWidth && mergedHeight <= clientHeight) { |
| 141 | + // newX = 0; |
| 142 | + // newY = 0; |
| 143 | + // } |
| 144 | + // } |
145 | 145 |
|
146 | 146 | if (action === 'doubleClick') { |
147 | | - newX = 0; |
148 | | - newY = 0; |
| 147 | + // newX = 0; |
| 148 | + // newY = 0; |
149 | 149 | } |
150 | 150 |
|
151 | 151 | updateTransform( |
152 | 152 | { |
153 | | - x: newX, |
154 | | - y: newY, |
| 153 | + // x: newX, |
| 154 | + // y: newY, |
155 | 155 | scale: newScale, |
156 | 156 | }, |
157 | 157 | action, |
|
0 commit comments