: _this.propsSize && _this.propsSize.height,
backgroundColor: 'rgba(0,0,0,0)',
_this.onResizeStart = _this.onResizeStart.bind(_this);
_this.onMouseMove = _this.onMouseMove.bind(_this);
_this.onMouseUp = _this.onMouseUp.bind(_this);
Object.defineProperty(Resizable.prototype, "parentNode", {
return this.resizable.parentNode;
Object.defineProperty(Resizable.prototype, "window", {
if (!this.resizable.ownerDocument) {
return this.resizable.ownerDocument.defaultView;
Object.defineProperty(Resizable.prototype, "propsSize", {
return this.props.size || this.props.defaultSize || DEFAULT_SIZE;
Object.defineProperty(Resizable.prototype, "size", {
if (this.resizable && this.window) {
var orgWidth = this.resizable.offsetWidth;
var orgHeight = this.resizable.offsetHeight;
// HACK: Set position `relative` to get parent size.
// This is because when re-resizable set `absolute`, I can not get base width correctly.
var orgPosition = this.resizable.style.position;
if (orgPosition !== 'relative') {
this.resizable.style.position = 'relative';
// INFO: Use original width or height if set auto.
width = this.resizable.style.width !== 'auto' ? this.resizable.offsetWidth : orgWidth;
height = this.resizable.style.height !== 'auto' ? this.resizable.offsetHeight : orgHeight;
// Restore original position
this.resizable.style.position = orgPosition;
return { width: width, height: height };
Object.defineProperty(Resizable.prototype, "sizeStyle", {
var size = this.props.size;
var getSize = function (key) {
if (typeof _this.state[key] === 'undefined' || _this.state[key] === 'auto') {
if (_this.propsSize && _this.propsSize[key] && endsWith(_this.propsSize[key].toString(), '%')) {
if (endsWith(_this.state[key].toString(), '%')) {
return _this.state[key].toString();
var parentSize = _this.getParentSize();
var value = Number(_this.state[key].toString().replace('px', ''));
var percent = (value / parentSize[key]) * 100;
return getStringSize(_this.state[key]);
var width = size && typeof size.width !== 'undefined' && !this.state.isResizing
? getStringSize(size.width)
var height = size && typeof size.height !== 'undefined' && !this.state.isResizing
? getStringSize(size.height)
return { width: width, height: height };
Resizable.prototype.getParentSize = function () {
return { width: 0, height: 0 };
return { width: this.window.innerWidth, height: this.window.innerHeight };
var base = this.appendBase();
return { width: 0, height: 0 };
// INFO: To calculate parent width with flex layout
var wrap = this.parentNode.style.flexWrap;
this.parentNode.style.flexWrap = 'wrap';
// HACK: Use relative to get parent padding size
base.style.position = 'relative';
base.style.minWidth = '100%';
height: base.offsetHeight,
this.parentNode.style.flexWrap = wrap;
Resizable.prototype.bindEvents = function () {
this.window.addEventListener('mouseup', this.onMouseUp);
this.window.addEventListener('mousemove', this.onMouseMove);
this.window.addEventListener('mouseleave', this.onMouseUp);
this.window.addEventListener('touchmove', this.onMouseMove, {
this.window.addEventListener('touchend', this.onMouseUp);
Resizable.prototype.unbindEvents = function () {
this.window.removeEventListener('mouseup', this.onMouseUp);
this.window.removeEventListener('mousemove', this.onMouseMove);
this.window.removeEventListener('mouseleave', this.onMouseUp);
this.window.removeEventListener('touchmove', this.onMouseMove, true);
this.window.removeEventListener('touchend', this.onMouseUp);
Resizable.prototype.componentDidMount = function () {
if (!this.resizable || !this.window) {
var computedStyle = this.window.getComputedStyle(this.resizable);
width: this.state.width || this.size.width,
height: this.state.height || this.size.height,
flexBasis: computedStyle.flexBasis !== 'auto' ? computedStyle.flexBasis : undefined,
Resizable.prototype.componentWillUnmount = function () {
Resizable.prototype.createSizeForCssProperty = function (newSize, kind) {
var propsSize = this.propsSize && this.propsSize[kind];
return this.state[kind] === 'auto' &&
this.state.original[kind] === newSize &&
(typeof propsSize === 'undefined' || propsSize === 'auto')
Resizable.prototype.calculateNewMaxFromBoundary = function (maxWidth, maxHeight) {
var boundsByDirection = this.props.boundsByDirection;
var direction = this.state.direction;
var widthByDirection = boundsByDirection && hasDirection('left', direction);
var heightByDirection = boundsByDirection && hasDirection('top', direction);
if (this.props.bounds === 'parent') {
var parent_1 = this.parentNode;
boundWidth = widthByDirection
? this.resizableRight - this.parentLeft
: parent_1.offsetWidth + (this.parentLeft - this.resizableLeft);
boundHeight = heightByDirection
? this.resizableBottom - this.parentTop
: parent_1.offsetHeight + (this.parentTop - this.resizableTop);
else if (this.props.bounds === 'window') {
boundWidth = widthByDirection ? this.resizableRight : this.window.innerWidth - this.resizableLeft;
boundHeight = heightByDirection ? this.resizableBottom : this.window.innerHeight - this.resizableTop;
else if (this.props.bounds) {
boundWidth = widthByDirection
? this.resizableRight - this.targetLeft
: this.props.bounds.offsetWidth + (this.targetLeft - this.resizableLeft);
boundHeight = heightByDirection
? this.resizableBottom - this.targetTop
: this.props.bounds.offsetHeight + (this.targetTop - this.resizableTop);
if (boundWidth && Number.isFinite(boundWidth)) {
maxWidth = maxWidth && maxWidth < boundWidth ? maxWidth : boundWidth;
if (boundHeight && Number.isFinite(boundHeight)) {
maxHeight = maxHeight && maxHeight < boundHeight ? maxHeight : boundHeight;
return { maxWidth: maxWidth, maxHeight: maxHeight };
Resizable.prototype.calculateNewSizeFromDirection = function (clientX, clientY) {
var scale = this.props.scale || 1;
var resizeRatio = this.props.resizeRatio || 1;
var _a = this.state, direction = _a.direction, original = _a.original;
var _b = this.props, lockAspectRatio = _b.lockAspectRatio, lockAspectRatioExtraHeight = _b.lockAspectRatioExtraHeight, lockAspectRatioExtraWidth = _b.lockAspectRatioExtraWidth;
var newWidth = original.width;
var newHeight = original.height;
var extraHeight = lockAspectRatioExtraHeight || 0;
var extraWidth = lockAspectRatioExtraWidth || 0;
if (hasDirection('right', direction)) {
newWidth = original.width + ((clientX - original.x) * resizeRatio) / scale;
newHeight = (newWidth - extraWidth) / this.ratio + extraHeight;
if (hasDirection('left', direction)) {
newWidth = original.width - ((clientX - original.x) * resizeRatio) / scale;
newHeight = (newWidth - extraWidth) / this.ratio + extraHeight;
if (hasDirection('bottom', direction)) {
newHeight = original.height + ((clientY - original.y) * resizeRatio) / scale;
newWidth = (newHeight - extraHeight) * this.ratio + extraWidth;
if (hasDirection('top', direction)) {
newHeight = original.height - ((clientY - original.y) * resizeRatio) / scale;
newWidth = (newHeight - extraHeight) * this.ratio + extraWidth;
return { newWidth: newWidth, newHeight: newHeight };
Resizable.prototype.calculateNewSizeFromAspectRatio = function (newWidth, newHeight, max, min) {
var _a = this.props, lockAspectRatio = _a.lockAspectRatio, lockAspectRatioExtraHeight = _a.lockAspectRatioExtraHeight, lockAspectRatioExtraWidth = _a.lockAspectRatioExtraWidth;
var computedMinWidth = typeof min.width === 'undefined' ? 10 : min.width;
var computedMaxWidth = typeof max.width === 'undefined' || max.width < 0 ? newWidth : max.width;
var computedMinHeight = typeof min.height === 'undefined' ? 10 : min.height;
var computedMaxHeight = typeof max.height === 'undefined' || max.height < 0 ? newHeight : max.height;
var extraHeight = lockAspectRatioExtraHeight || 0;
var extraWidth = lockAspectRatioExtraWidth || 0;
var extraMinWidth = (computedMinHeight - extraHeight) * this.ratio + extraWidth;
var extraMaxWidth = (computedMaxHeight - extraHeight) * this.ratio + extraWidth;
var extraMinHeight = (computedMinWidth - extraWidth) / this.ratio + extraHeight;
var extraMaxHeight = (computedMaxWidth - extraWidth) / this.ratio + extraHeight;
var lockedMinWidth = Math.max(computedMinWidth, extraMinWidth);
var lockedMaxWidth = Math.min(computedMaxWidth, extraMaxWidth);
var lockedMinHeight = Math.max(computedMinHeight, extraMinHeight);
var lockedMaxHeight = Math.min(computedMaxHeight, extraMaxHeight);
newWidth = clamp(newWidth, lockedMinWidth, lockedMaxWidth);
newHeight = clamp(newHeight, lockedMinHeight, lockedMaxHeight);
newWidth = clamp(newWidth, computedMinWidth, computedMaxWidth);
newHeight = clamp(newHeight, computedMinHeight, computedMaxHeight);
return { newWidth: newWidth, newHeight: newHeight };
Resizable.prototype.setBoundingClientRect = function () {
if (this.props.bounds === 'parent') {
var parent_2 = this.parentNode;
var parentRect = parent_2.getBoundingClientRect();
this.parentLeft = parentRect.left;
this.parentTop = parentRect.top;
// For target(html element) boundary
if (this.props.bounds && typeof this.props.bounds !== 'string') {
var targetRect = this.props.bounds.getBoundingClientRect();
this.targetLeft = targetRect.left;
this.targetTop = targetRect.top;
var _a = this.resizable.getBoundingClientRect(), left = _a.left, top_1 = _a.top, right = _a.right, bottom = _a.bottom;
this.resizableLeft = left;
this.resizableRight = right;
this.resizableTop = top_1;
this.resizableBottom = bottom;
Resizable.prototype.onResizeStart = function (event, direction) {
if (!this.resizable || !this.window) {
if (event.nativeEvent && isMouseEvent(event.nativeEvent)) {
clientX = event.nativeEvent.clientX;
clientY = event.nativeEvent.clientY;
// When user click with right button the resize is stuck in resizing mode
// until users clicks again, dont continue if right click is used.
// HACK: MouseEvent does not have `which` from flow-bin v0.68.
if (event.nativeEvent.which === 3) {
else if (event.nativeEvent && isTouchEvent(event.nativeEvent)) {
clientX = event.nativeEvent.touches[0].clientX;
clientY = event.nativeEvent.touches[0].clientY;
if (this.props.onResizeStart) {
var startResize = this.props.onResizeStart(event, direction, this.resizable);
if (startResize === false) {
if (typeof this.props.size.height !== 'undefined' && this.props.size.height !== this.state.height) {
this.setState({ height: this.props.size.height });
if (typeof this.props.size.width !== 'undefined' && this.props.size.width !== this.state.width) {
this.setState({ width: this.props.size.width });
// For lockAspectRatio case
typeof this.props.lockAspectRatio === 'number' ? this.props.lockAspectRatio : this.size.width / this.size.height;
var computedStyle = this.window.getComputedStyle(this.resizable);
if (computedStyle.flexBasis !== 'auto') {
var parent_3 = this.parentNode;
var dir = this.window.getComputedStyle(parent_3).flexDirection;
this.flexDir = dir.startsWith('row') ? 'row' : 'column';
flexBasis = computedStyle.flexBasis;
this.setBoundingClientRect();
height: this.size.height,
backgroundStyle: lib_assign(lib_assign({}, this.state.backgroundStyle), { cursor: this.window.getComputedStyle(event.target).cursor || 'auto' }),
Resizable.prototype.onMouseMove = function (event) {
if (!this.state.isResizing || !this.resizable || !this.window) {
if (this.window.TouchEvent && isTouchEvent(event)) {
var _a = this.props, maxWidth = _a.maxWidth, maxHeight = _a.maxHeight, minWidth = _a.minWidth, minHeight = _a.minHeight;
var clientX = isTouchEvent(event) ? event.touches[0].clientX : event.clientX;
var clientY = isTouchEvent(event) ? event.touches[0].clientY : event.clientY;
var _b = this.state, direction = _b.direction, original = _b.original, width = _b.width, height = _b.height;
var parentSize = this.getParentSize();
var max = calculateNewMax(parentSize, this.window.innerWidth, this.window.innerHeight, maxWidth, maxHeight, minWidth, minHeight);
maxHeight = max.maxHeight;
minHeight = max.minHeight;
var _c = this.calculateNewSizeFromDirection(clientX, clientY), newHeight = _c.newHeight, newWidth = _c.newWidth;
// Calculate max size from boundary settings
var boundaryMax = this.calculateNewMaxFromBoundary(maxWidth, maxHeight);
// Calculate new size from aspect ratio
var newSize = this.calculateNewSizeFromAspectRatio(newWidth, newHeight, { width: boundaryMax.maxWidth, height: boundaryMax.maxHeight }, { width: minWidth, height: minHeight });
newWidth = newSize.newWidth;
newHeight = newSize.newHeight;
var newGridWidth = snap(newWidth, this.props.grid[0]);
var newGridHeight = snap(newHeight, this.props.grid[1]);
var gap = this.props.snapGap || 0;
newWidth = gap === 0 || Math.abs(newGridWidth - newWidth) <= gap ? newGridWidth : newWidth;
newHeight = gap === 0 || Math.abs(newGridHeight - newHeight) <= gap ? newGridHeight : newHeight;
if (this.props.snap && this.props.snap.x) {
newWidth = findClosestSnap(newWidth, this.props.snap.x, this.props.snapGap);
if (this.props.snap && this.props.snap.y) {
newHeight = findClosestSnap(newHeight, this.props.snap.y, this.props.snapGap);
width: newWidth - original.width,
height: newHeight - original.height,
if (width && typeof width === 'string') {
if (endsWith(width, '%')) {
var percent = (newWidth / parentSize.width) * 100;
newWidth = percent + "%";
else if (endsWith(width, 'vw')) {
var vw = (newWidth / this.window.innerWidth) * 100;
else if (endsWith(width, 'vh')) {
var vh = (newWidth / this.window.innerHeight) * 100;
if (height && typeof height === 'string') {
if (endsWith(height, '%')) {
var percent = (newHeight / parentSize.height) * 100;
newHeight = percent + "%";
else if (endsWith(height, 'vw')) {
var vw = (newHeight / this.window.innerWidth) * 100;
else if (endsWith(height, 'vh')) {
var vh = (newHeight / this.window.innerHeight) * 100;
width: this.createSizeForCssProperty(newWidth, 'width'),
height: this.createSizeForCssProperty(newHeight, 'height'),
if (this.flexDir === 'row') {
newState.flexBasis = newState.width;
else if (this.flexDir === 'column') {
newState.flexBasis = newState.height;
if (this.props.onResize) {
this.props.onResize(event, direction, this.resizable, delta);
Resizable.prototype.onMouseUp = function (event) {
var _a = this.state, isResizing = _a.isResizing, direction = _a.direction, original = _a.original;
if (!isResizing || !this.resizable) {
width: this.size.width - original.width,
height: this.size.height - original.height,
if (this.props.onResizeStop) {
this.props.onResizeStop(event, direction, this.resizable, delta);
this.setState(this.props.size);
backgroundStyle: lib_assign(lib_assign({}, this.state.backgroundStyle), { cursor: 'auto' }),
Resizable.prototype.updateSize = function (size) {
this.setState({ width: size.width, height: size.height });
Resizable.prototype.renderResizer = function () {
var _a = this.props, enable = _a.enable, handleStyles = _a.handleStyles, handleClasses = _a.handleClasses, handleWrapperStyle = _a.handleWrapperStyle, handleWrapperClass = _a.handleWrapperClass, handleComponent = _a.handleComponent;