react-resizable 4.0.0 → 4.0.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.
Files changed (2) hide show
  1. package/build/Resizable.js +5 -11
  2. package/package.json +1 -1
@@ -44,18 +44,12 @@ class Resizable extends React.Component {
44
44
  // If constraining to min and max, we need to also fit width and height to aspect ratio.
45
45
  if (lockAspectRatio) {
46
46
  const ratio = this.props.width / this.props.height;
47
- const deltaW = width - this.props.width;
48
- const deltaH = height - this.props.height;
49
47
 
50
- // Find which coordinate was greater and should push the other toward it.
51
- // E.g.:
52
- // ratio = 1, deltaW = 10, deltaH = 5, deltaH should become 10.
53
- // ratio = 2, deltaW = 10, deltaH = 6, deltaW should become 12.
54
- if (Math.abs(deltaW) > Math.abs(deltaH * ratio)) {
55
- height = width / ratio;
56
- } else {
57
- width = height * ratio;
58
- }
48
+ // Project (width, height) onto the line w = ratio * h.
49
+ // Distributes tracking error across both axes instead of forcing one to overshoot.
50
+ // t = (w * ratio + h) / (ratio^2 + 1), new_w = t * ratio, new_h = t
51
+ height = (width * ratio + height) / (ratio * ratio + 1);
52
+ width = height * ratio;
59
53
  }
60
54
  const oldW = width,
61
55
  oldH = height;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-resizable",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "A component that is resizable with handles.",
5
5
  "main": "index.js",
6
6
  "types": "./build/index.d.ts",