Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-zoom-pan-pinch

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-zoom-pan-pinch - npm Package Compare versions

Comparing version 3.1.1 to 3.2.0

2

dist/src/core/bounds/bounds.utils.d.ts

@@ -6,2 +6,4 @@ import { BoundsType, PositionType, ReactZoomPanPinchContext } from "../../models";

export declare const calculateBounds: (contextInstance: ReactZoomPanPinchContext, newScale: number) => BoundsType;
export declare function clamp(v: number, min: number, max: number): number;
export declare function rubberbandIfOutOfBounds(position: number, min: number, max: number, constant?: number): number;
/**

@@ -8,0 +10,0 @@ * Keeps value between given bounds, used for limiting view to given boundaries

2

package.json
{
"name": "react-zoom-pan-pinch",
"version": "3.1.1",
"version": "3.2.0",
"description": "Zoom and pan html elements in easy way",

@@ -5,0 +5,0 @@ "author": "prc5",

@@ -94,2 +94,32 @@ /* eslint-disable no-param-reassign */

export function clamp(v: number, min: number, max: number) {
return Math.max(min, Math.min(v, max));
}
// Based on @aholachek ;)
// https://twitter.com/chpwn/status/285540192096497664
// iOS constant = 0.55
// https://medium.com/@nathangitter/building-fluid-interfaces-ios-swift-9732bb934bf5
function rubberband(distance: number, dimension: number, constant: number) {
if (dimension === 0 || Math.abs(dimension) === Infinity)
return distance ** (constant * 5);
return (distance * dimension * constant) / (dimension + constant * distance);
}
export function rubberbandIfOutOfBounds(
position: number,
min: number,
max: number,
constant = 0.15,
) {
if (constant === 0) return clamp(position, min, max);
if (position < min)
return -rubberband(min - position, max - min, constant) + min;
if (position > max)
return +rubberband(position - max, max - min, constant) + max;
return position;
}
/**

@@ -144,4 +174,15 @@ * Keeps value between given bounds, used for limiting view to given boundaries

const rubberbandX = rubberbandIfOutOfBounds(
positionX,
minPositionX,
maxPositionX,
);
const rubberbandY = rubberbandIfOutOfBounds(
positionY,
minPositionY,
maxPositionY,
);
const x = boundLimiter(
positionX,
rubberbandX,
minPositionX - paddingX,

@@ -153,3 +194,3 @@ maxPositionX + paddingX,

const y = boundLimiter(
positionY,
rubberbandY,
minPositionY - paddingY,

@@ -156,0 +197,0 @@ maxPositionY + paddingY,

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc