react-zoom-pan-pinch 3.4.3 → 3.5.0
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/README.md +85 -58
- package/dist/index.cjs.js +54 -7
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.esm.js +54 -8
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ type StartCoordsType = {
|
|
|
37
37
|
declare class ZoomPanPinch {
|
|
38
38
|
props: ReactZoomPanPinchProps;
|
|
39
39
|
mounted: boolean;
|
|
40
|
+
pinchLastCenterX: number | null;
|
|
41
|
+
pinchLastCenterY: number | null;
|
|
40
42
|
transformState: ReactZoomPanPinchState;
|
|
41
43
|
setup: LibrarySetup;
|
|
42
44
|
observer?: ResizeObserver;
|
|
@@ -266,6 +268,8 @@ declare const useTransformEffect: (callback: (ref: ReactZoomPanPinchContextState
|
|
|
266
268
|
|
|
267
269
|
declare const useTransformContext: () => ZoomPanPinch;
|
|
268
270
|
|
|
271
|
+
declare function useTransformComponent<T>(callback: (state: ReactZoomPanPinchContextState) => T): T;
|
|
272
|
+
|
|
269
273
|
declare const KeepScale: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
270
274
|
|
|
271
275
|
type MiniMapProps = {
|
|
@@ -294,4 +298,4 @@ declare const getTransformStyles: (x: number, y: number, scale: number) => strin
|
|
|
294
298
|
declare const getMatrixTransformStyles: (x: number, y: number, scale: number) => string;
|
|
295
299
|
declare const getCenterPosition: (scale: number, wrapperComponent: HTMLDivElement, contentComponent: HTMLDivElement) => StateType;
|
|
296
300
|
|
|
297
|
-
export { AnimationType, BoundsType, Context, KeepScale, LibrarySetup, MiniMap, MiniMapProps, PositionType, ReactZoomPanPinchComponentHelpers, ReactZoomPanPinchContentRef, ReactZoomPanPinchContext, ReactZoomPanPinchContextState, ReactZoomPanPinchHandlers, ReactZoomPanPinchProps, ReactZoomPanPinchRef, ReactZoomPanPinchRefProps, ReactZoomPanPinchState, SizeType, StateType, TransformComponent, TransformWrapper, VelocityType, getCenterPosition, getMatrixTransformStyles, getTransformStyles, useControls, useTransformContext, useTransformEffect, useTransformInit };
|
|
301
|
+
export { AnimationType, BoundsType, Context, KeepScale, LibrarySetup, MiniMap, MiniMapProps, PositionType, ReactZoomPanPinchComponentHelpers, ReactZoomPanPinchContentRef, ReactZoomPanPinchContext, ReactZoomPanPinchContextState, ReactZoomPanPinchHandlers, ReactZoomPanPinchProps, ReactZoomPanPinchRef, ReactZoomPanPinchRefProps, ReactZoomPanPinchState, SizeType, StateType, TransformComponent, TransformWrapper, VelocityType, getCenterPosition, getMatrixTransformStyles, getTransformStyles, useControls, useTransformComponent, useTransformContext, useTransformEffect, useTransformInit };
|
package/dist/index.esm.js
CHANGED
|
@@ -1195,18 +1195,34 @@ var handleWheelStop = function (contextInstance, event) {
|
|
|
1195
1195
|
}
|
|
1196
1196
|
};
|
|
1197
1197
|
|
|
1198
|
+
var getTouchCenter = function (event) {
|
|
1199
|
+
var totalX = 0;
|
|
1200
|
+
var totalY = 0;
|
|
1201
|
+
// Sum up the positions of all touches
|
|
1202
|
+
for (var i = 0; i < 2; i += 1) {
|
|
1203
|
+
totalX += event.touches[i].clientX;
|
|
1204
|
+
totalY += event.touches[i].clientY;
|
|
1205
|
+
}
|
|
1206
|
+
// Calculate the average position
|
|
1207
|
+
var x = totalX / 2;
|
|
1208
|
+
var y = totalY / 2;
|
|
1209
|
+
return { x: x, y: y };
|
|
1210
|
+
};
|
|
1198
1211
|
var handlePinchStart = function (contextInstance, event) {
|
|
1199
1212
|
var distance = getTouchDistance(event);
|
|
1200
1213
|
contextInstance.pinchStartDistance = distance;
|
|
1201
1214
|
contextInstance.lastDistance = distance;
|
|
1202
1215
|
contextInstance.pinchStartScale = contextInstance.transformState.scale;
|
|
1203
1216
|
contextInstance.isPanning = false;
|
|
1217
|
+
var center = getTouchCenter(event);
|
|
1218
|
+
contextInstance.pinchLastCenterX = center.x;
|
|
1219
|
+
contextInstance.pinchLastCenterY = center.y;
|
|
1204
1220
|
handleCancelAnimation(contextInstance);
|
|
1205
1221
|
};
|
|
1206
1222
|
var handlePinchZoom = function (contextInstance, event) {
|
|
1207
|
-
var contentComponent = contextInstance.contentComponent, pinchStartDistance = contextInstance.pinchStartDistance;
|
|
1223
|
+
var contentComponent = contextInstance.contentComponent, pinchStartDistance = contextInstance.pinchStartDistance, wrapperComponent = contextInstance.wrapperComponent;
|
|
1208
1224
|
var scale = contextInstance.transformState.scale;
|
|
1209
|
-
var _a = contextInstance.setup, limitToBounds = _a.limitToBounds, centerZoomedOut = _a.centerZoomedOut, zoomAnimation = _a.zoomAnimation;
|
|
1225
|
+
var _a = contextInstance.setup, limitToBounds = _a.limitToBounds, centerZoomedOut = _a.centerZoomedOut, zoomAnimation = _a.zoomAnimation, alignmentAnimation = _a.alignmentAnimation;
|
|
1210
1226
|
var disabled = zoomAnimation.disabled, size = zoomAnimation.size;
|
|
1211
1227
|
// if one finger starts from outside of wrapper
|
|
1212
1228
|
if (pinchStartDistance === null || !contentComponent)
|
|
@@ -1217,15 +1233,27 @@ var handlePinchZoom = function (contextInstance, event) {
|
|
|
1217
1233
|
return;
|
|
1218
1234
|
var currentDistance = getTouchDistance(event);
|
|
1219
1235
|
var newScale = calculatePinchZoom(contextInstance, currentDistance);
|
|
1220
|
-
|
|
1236
|
+
var center = getTouchCenter(event);
|
|
1237
|
+
// pan should be scale invariant.
|
|
1238
|
+
var panX = center.x - (contextInstance.pinchLastCenterX || 0);
|
|
1239
|
+
var panY = center.y - (contextInstance.pinchLastCenterY || 0);
|
|
1240
|
+
if (newScale === scale && panX === 0 && panY === 0)
|
|
1221
1241
|
return;
|
|
1242
|
+
contextInstance.pinchLastCenterX = center.x;
|
|
1243
|
+
contextInstance.pinchLastCenterY = center.y;
|
|
1222
1244
|
var bounds = handleCalculateBounds(contextInstance, newScale);
|
|
1223
1245
|
var isPaddingDisabled = disabled || size === 0 || centerZoomedOut;
|
|
1224
1246
|
var isLimitedToBounds = limitToBounds && isPaddingDisabled;
|
|
1225
1247
|
var _b = handleCalculateZoomPositions(contextInstance, midPoint.x, midPoint.y, newScale, bounds, isLimitedToBounds), x = _b.x, y = _b.y;
|
|
1226
1248
|
contextInstance.pinchMidpoint = midPoint;
|
|
1227
1249
|
contextInstance.lastDistance = currentDistance;
|
|
1228
|
-
|
|
1250
|
+
var sizeX = alignmentAnimation.sizeX, sizeY = alignmentAnimation.sizeY;
|
|
1251
|
+
var paddingValueX = getPaddingValue(contextInstance, sizeX);
|
|
1252
|
+
var paddingValueY = getPaddingValue(contextInstance, sizeY);
|
|
1253
|
+
var newPositionX = x + panX;
|
|
1254
|
+
var newPositionY = y + panY;
|
|
1255
|
+
var _c = getMouseBoundedPosition(newPositionX, newPositionY, bounds, limitToBounds, paddingValueX, paddingValueY, wrapperComponent), finalX = _c.x, finalY = _c.y;
|
|
1256
|
+
contextInstance.setTransformState(newScale, finalX, finalY);
|
|
1229
1257
|
};
|
|
1230
1258
|
var handlePinchStop = function (contextInstance) {
|
|
1231
1259
|
var pinchMidpoint = contextInstance.pinchMidpoint;
|
|
@@ -1308,6 +1336,8 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1308
1336
|
function ZoomPanPinch(props) {
|
|
1309
1337
|
var _this = this;
|
|
1310
1338
|
this.mounted = true;
|
|
1339
|
+
this.pinchLastCenterX = null;
|
|
1340
|
+
this.pinchLastCenterY = null;
|
|
1311
1341
|
this.onChangeCallbacks = new Set();
|
|
1312
1342
|
this.onInitCallbacks = new Set();
|
|
1313
1343
|
// Components
|
|
@@ -1400,10 +1430,21 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1400
1430
|
_this.setCenter();
|
|
1401
1431
|
_this.observer = new ResizeObserver(function () {
|
|
1402
1432
|
var _a;
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
(
|
|
1433
|
+
var currentWidth = contentComponent.offsetWidth;
|
|
1434
|
+
var currentHeight = contentComponent.offsetHeight;
|
|
1435
|
+
if (currentWidth > 0 || currentHeight > 0) {
|
|
1436
|
+
_this.onInitCallbacks.forEach(function (callback) {
|
|
1437
|
+
return callback(getContext(_this));
|
|
1438
|
+
});
|
|
1439
|
+
_this.setCenter();
|
|
1440
|
+
(_a = _this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
1441
|
+
}
|
|
1406
1442
|
});
|
|
1443
|
+
// if nothing about the contentComponent has changed after 5 seconds, disconnect the observer
|
|
1444
|
+
setTimeout(function () {
|
|
1445
|
+
var _a;
|
|
1446
|
+
(_a = _this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
1447
|
+
}, 5000);
|
|
1407
1448
|
// Start observing the target node for configured mutations
|
|
1408
1449
|
_this.observer.observe(contentComponent);
|
|
1409
1450
|
}
|
|
@@ -2002,5 +2043,10 @@ var useTransformEffect = function (callback) {
|
|
|
2002
2043
|
}, [callback, libraryContext]);
|
|
2003
2044
|
};
|
|
2004
2045
|
|
|
2005
|
-
|
|
2046
|
+
function useTransformComponent(callback) {
|
|
2047
|
+
var libraryContext = useTransformContext();
|
|
2048
|
+
return useMemo(function () { return callback(getState(libraryContext)); }, [libraryContext, callback]);
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
export { Context, KeepScale, MiniMap, TransformComponent, TransformWrapper, getCenterPosition, getMatrixTransformStyles, getTransformStyles, useControls, useTransformComponent, useTransformContext, useTransformEffect, useTransformInit };
|
|
2006
2052
|
//# sourceMappingURL=index.esm.js.map
|