react-zoom-pan-pinch 3.2.0 → 3.3.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/dist/index.cjs.js +16 -31
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.esm.js +16 -31
- package/dist/index.esm.js.map +1 -1
- package/dist/src/models/context.model.d.ts +3 -0
- package/package.json +1 -1
- package/src/components/transform-component/transform-component.tsx +5 -2
- package/src/components/transform-wrapper/transform-wrapper.tsx +0 -3
- package/src/constants/state.constants.ts +3 -0
- package/src/core/bounds/bounds.utils.ts +2 -13
- package/src/core/instance.core.ts +4 -0
- package/src/models/context.model.ts +3 -0
- package/src/stories/docs/props.tsx +18 -0
package/dist/index.cjs.js
CHANGED
|
@@ -224,28 +224,6 @@ var calculateBounds = function (contextInstance, newScale) {
|
|
|
224
224
|
var bounds = getBounds(wrapperWidth, newContentWidth, newDiffWidth, wrapperHeight, newContentHeight, newDiffHeight, Boolean(centerZoomedOut));
|
|
225
225
|
return bounds;
|
|
226
226
|
};
|
|
227
|
-
function clamp(v, min, max) {
|
|
228
|
-
return Math.max(min, Math.min(v, max));
|
|
229
|
-
}
|
|
230
|
-
// Based on @aholachek ;)
|
|
231
|
-
// https://twitter.com/chpwn/status/285540192096497664
|
|
232
|
-
// iOS constant = 0.55
|
|
233
|
-
// https://medium.com/@nathangitter/building-fluid-interfaces-ios-swift-9732bb934bf5
|
|
234
|
-
function rubberband(distance, dimension, constant) {
|
|
235
|
-
if (dimension === 0 || Math.abs(dimension) === Infinity)
|
|
236
|
-
return Math.pow(distance, (constant * 5));
|
|
237
|
-
return (distance * dimension * constant) / (dimension + constant * distance);
|
|
238
|
-
}
|
|
239
|
-
function rubberbandIfOutOfBounds(position, min, max, constant) {
|
|
240
|
-
if (constant === void 0) { constant = 0.15; }
|
|
241
|
-
if (constant === 0)
|
|
242
|
-
return clamp(position, min, max);
|
|
243
|
-
if (position < min)
|
|
244
|
-
return -rubberband(min - position, max - min, constant) + min;
|
|
245
|
-
if (position > max)
|
|
246
|
-
return +rubberband(position - max, max - min, constant) + max;
|
|
247
|
-
return position;
|
|
248
|
-
}
|
|
249
227
|
/**
|
|
250
228
|
* Keeps value between given bounds, used for limiting view to given boundaries
|
|
251
229
|
* 1# eg. boundLimiter(2, 0, 3, true) => 2
|
|
@@ -276,10 +254,8 @@ function getMouseBoundedPosition(positionX, positionY, bounds, limitToBounds, pa
|
|
|
276
254
|
paddingX = paddingValueX;
|
|
277
255
|
paddingY = paddingValueY;
|
|
278
256
|
}
|
|
279
|
-
var
|
|
280
|
-
var
|
|
281
|
-
var x = boundLimiter(rubberbandX, minPositionX - paddingX, maxPositionX + paddingX, limitToBounds);
|
|
282
|
-
var y = boundLimiter(rubberbandY, minPositionY - paddingY, maxPositionY + paddingY, limitToBounds);
|
|
257
|
+
var x = boundLimiter(positionX, minPositionX - paddingX, maxPositionX + paddingX, limitToBounds);
|
|
258
|
+
var y = boundLimiter(positionY, minPositionY - paddingY, maxPositionY + paddingY, limitToBounds);
|
|
283
259
|
return { x: x, y: y };
|
|
284
260
|
}
|
|
285
261
|
|
|
@@ -699,6 +675,9 @@ var initialSetup = {
|
|
|
699
675
|
velocityDisabled: false,
|
|
700
676
|
lockAxisX: false,
|
|
701
677
|
lockAxisY: false,
|
|
678
|
+
allowLeftClickPan: true,
|
|
679
|
+
allowMiddleClickPan: true,
|
|
680
|
+
allowRightClickPan: true,
|
|
702
681
|
activationKeys: [],
|
|
703
682
|
excluded: [],
|
|
704
683
|
},
|
|
@@ -1457,6 +1436,12 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1457
1436
|
var keysPressed = _this.isPressingKeys(_this.setup.panning.activationKeys);
|
|
1458
1437
|
if (!keysPressed)
|
|
1459
1438
|
return;
|
|
1439
|
+
if (event.button === 0 && !_this.setup.panning.allowLeftClickPan)
|
|
1440
|
+
return;
|
|
1441
|
+
if (event.button === 1 && !_this.setup.panning.allowMiddleClickPan)
|
|
1442
|
+
return;
|
|
1443
|
+
if (event.button === 2 && !_this.setup.panning.allowRightClickPan)
|
|
1444
|
+
return;
|
|
1460
1445
|
event.preventDefault();
|
|
1461
1446
|
event.stopPropagation();
|
|
1462
1447
|
handleCancelAnimation(_this);
|
|
@@ -1706,9 +1691,6 @@ var TransformWrapper = React__default["default"].forwardRef(function (props, ref
|
|
|
1706
1691
|
React.useImperativeHandle(ref, function () { return getControls(instance); }, [instance]);
|
|
1707
1692
|
React.useEffect(function () {
|
|
1708
1693
|
instance.update(props);
|
|
1709
|
-
return function () {
|
|
1710
|
-
instance.cleanupWindowEvents();
|
|
1711
|
-
};
|
|
1712
1694
|
}, [instance, props]);
|
|
1713
1695
|
return React__default["default"].createElement(Context.Provider, { value: instance }, content);
|
|
1714
1696
|
});
|
|
@@ -1924,16 +1906,19 @@ styleInject(css_248z);
|
|
|
1924
1906
|
|
|
1925
1907
|
var TransformComponent = function (_a) {
|
|
1926
1908
|
var children = _a.children, _b = _a.wrapperClass, wrapperClass = _b === void 0 ? "" : _b, _c = _a.contentClass, contentClass = _c === void 0 ? "" : _c, wrapperStyle = _a.wrapperStyle, contentStyle = _a.contentStyle, _d = _a.wrapperProps, wrapperProps = _d === void 0 ? {} : _d, _e = _a.contentProps, contentProps = _e === void 0 ? {} : _e;
|
|
1927
|
-
var
|
|
1909
|
+
var _f = React.useContext(Context), init = _f.init, cleanupWindowEvents = _f.cleanupWindowEvents;
|
|
1928
1910
|
var wrapperRef = React.useRef(null);
|
|
1929
1911
|
var contentRef = React.useRef(null);
|
|
1930
1912
|
React.useEffect(function () {
|
|
1931
1913
|
var wrapper = wrapperRef.current;
|
|
1932
1914
|
var content = contentRef.current;
|
|
1933
1915
|
if (wrapper !== null && content !== null && init) {
|
|
1934
|
-
init(wrapper, content);
|
|
1916
|
+
init === null || init === void 0 ? void 0 : init(wrapper, content);
|
|
1935
1917
|
}
|
|
1936
1918
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1919
|
+
return function () {
|
|
1920
|
+
cleanupWindowEvents === null || cleanupWindowEvents === void 0 ? void 0 : cleanupWindowEvents();
|
|
1921
|
+
};
|
|
1937
1922
|
}, []);
|
|
1938
1923
|
return (React__default["default"].createElement("div", __assign({}, wrapperProps, { ref: wrapperRef, className: "react-transform-wrapper ".concat(styles.wrapper, " ").concat(wrapperClass), style: wrapperStyle }),
|
|
1939
1924
|
React__default["default"].createElement("div", __assign({}, contentProps, { ref: contentRef, className: "react-transform-component ".concat(styles.content, " ").concat(contentClass), style: contentStyle }), children)));
|