Commit ab80d33
authored
feat: center image zooming on the cursor (SableClient#602)
<!-- Please read
https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before
submitting your pull request -->
### Description
This PR makes the image zooming via double-click or mouse wheel centered
on the cursor position rather than the center of the image.
Clicking the zoom % label (between + and - buttons) now resets the image
zoom and pan.
Zooming was also changed from being additive to multiplicative, which
makes the "zooming speed" feel consistent.
In the process of doing this I merged the zoom and pan state into one,
making it possible to change them at the same time.
The `setPan` and `setZoom` functions were recreated for compatibility.
`resetTransforms` was added for convenience.
`handleWheel` was moved from the ImageViewer into the image gestures
hook.
#### Type of change
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update
### Checklist:
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
### AI disclosure:
- [ ] Partially AI assisted (clarify which code was AI assisted and
briefly explain what it does).
- [ ] Fully AI generated (explain what all the generated code does in
moderate detail).
<!-- Write any explanation required here, but do not generate the
explanation using AI!! You must prove you understand what the code in
this PR does. -->File tree
6 files changed
+206
-56
lines changed- .changeset
- src/app
- components
- Pdf-viewer
- image-viewer
- hooks
6 files changed
+206
-56
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
43 | 49 | | |
44 | 50 | | |
45 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | 2 | | |
4 | 3 | | |
| |||
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 16 | + | |
| 17 | + | |
21 | 18 | | |
22 | 19 | | |
23 | 20 | | |
24 | 21 | | |
25 | 22 | | |
26 | 23 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | 24 | | |
40 | 25 | | |
41 | 26 | | |
| |||
54 | 39 | | |
55 | 40 | | |
56 | 41 | | |
57 | | - | |
58 | | - | |
| 42 | + | |
| 43 | + | |
59 | 44 | | |
60 | 45 | | |
61 | 46 | | |
62 | 47 | | |
63 | 48 | | |
64 | 49 | | |
65 | 50 | | |
66 | | - | |
67 | | - | |
| 51 | + | |
| 52 | + | |
68 | 53 | | |
69 | 54 | | |
70 | | - | |
71 | | - | |
| 55 | + | |
| 56 | + | |
72 | 57 | | |
73 | 58 | | |
74 | 59 | | |
| |||
104 | 89 | | |
105 | 90 | | |
106 | 91 | | |
107 | | - | |
| 92 | + | |
108 | 93 | | |
109 | 94 | | |
110 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
3 | 28 | | |
4 | | - | |
5 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
6 | 33 | | |
7 | 34 | | |
8 | 35 | | |
| |||
11 | 38 | | |
12 | 39 | | |
13 | 40 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
28 | 106 | | |
29 | | - | |
30 | | - | |
| 107 | + | |
| 108 | + | |
31 | 109 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
37 | 117 | | |
38 | 118 | | |
39 | 119 | | |
| |||
53 | 133 | | |
54 | 134 | | |
55 | 135 | | |
56 | | - | |
57 | | - | |
| 136 | + | |
| 137 | + | |
58 | 138 | | |
59 | 139 | | |
60 | 140 | | |
61 | | - | |
| 141 | + | |
62 | 142 | | |
63 | 143 | | |
64 | 144 | | |
| |||
86 | 166 | | |
87 | 167 | | |
88 | 168 | | |
89 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
90 | 181 | | |
91 | 182 | | |
92 | 183 | | |
93 | | - | |
94 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
95 | 237 | | |
96 | 238 | | |
97 | | - | |
98 | | - | |
| 239 | + | |
99 | 240 | | |
100 | 241 | | |
| 242 | + | |
101 | 243 | | |
102 | 244 | | |
| 245 | + | |
| 246 | + | |
103 | 247 | | |
104 | 248 | | |
105 | 249 | | |
| |||
0 commit comments