yet-another-react-lightbox 1.11.0 → 1.11.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/plugins/Zoom.js +35 -22
- package/package.json +10 -10
package/dist/plugins/Zoom.js
CHANGED
|
@@ -173,11 +173,29 @@ const ZoomContainer = ({ slide, offset, rect, render, carousel, animation, zoom:
|
|
|
173
173
|
offsetY: Math.min(Math.abs(newOffsetY), Math.max(maxOffsetY, 0)) * Math.sign(newOffsetY),
|
|
174
174
|
}));
|
|
175
175
|
}, []);
|
|
176
|
+
const changeZoom = React.useCallback((value, rapid, dx, dy) => {
|
|
177
|
+
const { current } = refs;
|
|
178
|
+
const { state: { zoom }, containerRef, containerRect, maxZoom, } = current;
|
|
179
|
+
if (!containerRef.current || !containerRect)
|
|
180
|
+
return;
|
|
181
|
+
const newZoom = round(Math.min(Math.max(value + 0.001 < maxZoom ? value : maxZoom, 1), maxZoom), 5);
|
|
182
|
+
if (newZoom === zoom)
|
|
183
|
+
return;
|
|
184
|
+
if (!rapid) {
|
|
185
|
+
current.zoomAnimationStart = window.getComputedStyle(containerRef.current).transform;
|
|
186
|
+
}
|
|
187
|
+
changeOffsets(dx ? dx * (1 / zoom - 1 / newZoom) : 0, dy ? dy * (1 / zoom - 1 / newZoom) : 0, newZoom);
|
|
188
|
+
setState((prev) => ({ ...prev, zoom: newZoom }));
|
|
189
|
+
}, [changeOffsets]);
|
|
176
190
|
useLayoutEffect(() => {
|
|
177
191
|
if (refs.current.state.zoom > 1) {
|
|
192
|
+
const { maxZoom, state: { zoom: currentZoom }, } = refs.current;
|
|
193
|
+
if (currentZoom > maxZoom) {
|
|
194
|
+
changeZoom(maxZoom, true);
|
|
195
|
+
}
|
|
178
196
|
changeOffsets();
|
|
179
197
|
}
|
|
180
|
-
}, [currentControllerRect.width, currentControllerRect.height, changeOffsets]);
|
|
198
|
+
}, [currentControllerRect.width, currentControllerRect.height, changeOffsets, changeZoom]);
|
|
181
199
|
useLayoutEffect(() => {
|
|
182
200
|
var _a, _b;
|
|
183
201
|
const { current } = refs;
|
|
@@ -227,20 +245,6 @@ const ZoomContainer = ({ slide, offset, rect, render, carousel, animation, zoom:
|
|
|
227
245
|
}
|
|
228
246
|
}
|
|
229
247
|
}, [offset, state.zoom, currentMaxZoom, isMinZoom, isMaxZoom, setIsMinZoom, setIsMaxZoom]);
|
|
230
|
-
const changeZoom = React.useCallback((value, rapid, dx, dy) => {
|
|
231
|
-
const { current } = refs;
|
|
232
|
-
const { state: { zoom }, containerRef, containerRect, maxZoom, } = current;
|
|
233
|
-
if (!containerRef.current || !containerRect)
|
|
234
|
-
return;
|
|
235
|
-
const newZoom = round(Math.min(Math.max(value + 0.001 < maxZoom ? value : maxZoom, 1), maxZoom), 5);
|
|
236
|
-
if (newZoom === zoom)
|
|
237
|
-
return;
|
|
238
|
-
if (!rapid) {
|
|
239
|
-
current.zoomAnimationStart = window.getComputedStyle(containerRef.current).transform;
|
|
240
|
-
}
|
|
241
|
-
changeOffsets(dx ? dx * (1 / zoom - 1 / newZoom) : 0, dy ? dy * (1 / zoom - 1 / newZoom) : 0, newZoom);
|
|
242
|
-
setState((prev) => ({ ...prev, zoom: newZoom }));
|
|
243
|
-
}, [changeOffsets]);
|
|
244
248
|
const translateCoordinates = React.useCallback((event) => {
|
|
245
249
|
const { controllerRef } = refs.current;
|
|
246
250
|
if (controllerRef.current) {
|
|
@@ -253,9 +257,13 @@ const ZoomContainer = ({ slide, offset, rect, render, carousel, animation, zoom:
|
|
|
253
257
|
}, []);
|
|
254
258
|
const onKeyDown = React.useCallback((event) => {
|
|
255
259
|
const { state: { zoom }, zoomProps: { keyboardMoveDistance, zoomInMultiplier }, } = refs.current;
|
|
260
|
+
const preventDefault = () => {
|
|
261
|
+
event.preventDefault();
|
|
262
|
+
event.stopPropagation();
|
|
263
|
+
};
|
|
256
264
|
if (zoom > 1) {
|
|
257
265
|
const move = (deltaX, deltaY) => {
|
|
258
|
-
|
|
266
|
+
preventDefault();
|
|
259
267
|
changeOffsets(deltaX, deltaY);
|
|
260
268
|
};
|
|
261
269
|
if (event.key === "ArrowDown") {
|
|
@@ -271,14 +279,19 @@ const ZoomContainer = ({ slide, offset, rect, render, carousel, animation, zoom:
|
|
|
271
279
|
move(keyboardMoveDistance, 0);
|
|
272
280
|
}
|
|
273
281
|
}
|
|
274
|
-
|
|
275
|
-
|
|
282
|
+
const handleChangeZoom = (zoomValue) => {
|
|
283
|
+
preventDefault();
|
|
284
|
+
changeZoom(zoomValue);
|
|
285
|
+
};
|
|
286
|
+
const hasMeta = () => event.getModifierState("Meta") || event.getModifierState("OS");
|
|
287
|
+
if (event.key === "+" || (event.key === "=" && hasMeta())) {
|
|
288
|
+
handleChangeZoom(zoom * zoomInMultiplier);
|
|
276
289
|
}
|
|
277
|
-
else if (event.key === "-" || (event.key === "_" &&
|
|
278
|
-
|
|
290
|
+
else if (event.key === "-" || (event.key === "_" && hasMeta())) {
|
|
291
|
+
handleChangeZoom(zoom / zoomInMultiplier);
|
|
279
292
|
}
|
|
280
|
-
else if (event.key === "0" &&
|
|
281
|
-
|
|
293
|
+
else if (event.key === "0" && hasMeta()) {
|
|
294
|
+
handleChangeZoom(1);
|
|
282
295
|
}
|
|
283
296
|
}, [changeZoom, changeOffsets]);
|
|
284
297
|
const onWheel = React.useCallback((event) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yet-another-react-lightbox",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.1",
|
|
4
4
|
"description": "Modern React lightbox component",
|
|
5
5
|
"author": "Igor Danchenko",
|
|
6
6
|
"license": "MIT",
|
|
@@ -96,19 +96,19 @@
|
|
|
96
96
|
"@semantic-release/github": "^8.0.5",
|
|
97
97
|
"@testing-library/jest-dom": "^5.16.4",
|
|
98
98
|
"@testing-library/react": "^13.3.0",
|
|
99
|
-
"@testing-library/user-event": "^14.
|
|
100
|
-
"@types/jest": "^28.1.
|
|
99
|
+
"@testing-library/user-event": "^14.3.0",
|
|
100
|
+
"@types/jest": "^28.1.6",
|
|
101
101
|
"@types/react": "^18.0.15",
|
|
102
102
|
"@types/react-dom": "^18.0.6",
|
|
103
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
104
|
-
"@typescript-eslint/parser": "^5.
|
|
105
|
-
"autoprefixer": "^10.4.
|
|
106
|
-
"eslint": "^8.
|
|
103
|
+
"@typescript-eslint/eslint-plugin": "^5.31.0",
|
|
104
|
+
"@typescript-eslint/parser": "^5.31.0",
|
|
105
|
+
"autoprefixer": "^10.4.8",
|
|
106
|
+
"eslint": "^8.20.0",
|
|
107
107
|
"eslint-config-airbnb": "^19.0.4",
|
|
108
108
|
"eslint-config-airbnb-typescript": "^17.0.0",
|
|
109
109
|
"eslint-config-prettier": "^8.5.0",
|
|
110
110
|
"eslint-plugin-import": "^2.26.0",
|
|
111
|
-
"eslint-plugin-jsx-a11y": "^6.6.
|
|
111
|
+
"eslint-plugin-jsx-a11y": "^6.6.1",
|
|
112
112
|
"eslint-plugin-prettier": "^4.2.1",
|
|
113
113
|
"eslint-plugin-react": "^7.30.1",
|
|
114
114
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
@@ -123,8 +123,8 @@
|
|
|
123
123
|
"react": "^18.2.0",
|
|
124
124
|
"react-dom": "^18.2.0",
|
|
125
125
|
"rimraf": "^3.0.2",
|
|
126
|
-
"sass": "^1.
|
|
127
|
-
"ts-jest": "^28.0.
|
|
126
|
+
"sass": "^1.54.0",
|
|
127
|
+
"ts-jest": "^28.0.7",
|
|
128
128
|
"typescript": "^4.7.4"
|
|
129
129
|
},
|
|
130
130
|
"keywords": [
|