react-moveable
Version:
A React Component that create Moveable, Draggable, Resizable, Scalable, Rotatable, Warpable, Pinchable, Groupable.
1,669 lines (1,469 loc) • 135 kB
JavaScript
/*
Copyright (c) 2019 Daybrush
name: react-moveable
license: MIT
author: Daybrush
repository: https://github.com/daybrush/moveable/blob/master/packages/react-moveable
version: 0.13.7
*/
import * as React from 'react';
import { createElement, PureComponent } from 'react';
import { prefixCSS, prefixNames, ref, refs } from 'framework-utils';
import getAgent from '@egjs/agent';
import { isUndefined, splitUnit, isObject, splitBracket, isFunction, hasClass, isArray, dot, addClass, findIndex, removeClass } from '@daybrush/utils';
import { createIdentityMatrix, plus, getRad, getOrigin, multiplies, createOriginMatrix, convertCSStoMatrix, convertDimension, multiply, convertMatrixtoCSS, createScaleMatrix, caculate, convertPositionMatrix, minus, invert, average, rotate, createRotateMatrix, ignoreDimension, createWarpMatrix, multiplyCSS } from '@moveable/matrix';
import styler from 'react-css-styler';
import Dragger from '@daybrush/drag';
import ChildrenDiffer from '@egjs/children-differ';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function (d, b) {
d.__proto__ = b;
} || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
};
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function () {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var agent = getAgent();
var isWebkit = agent.os.name.indexOf("ios") > -1 || agent.browser.name.indexOf("safari") > -1;
var PREFIX = "moveable-";
var MOVEABLE_CSS = prefixCSS(PREFIX, "\n{\n\tposition: fixed;\n\twidth: 0;\n\theight: 0;\n\tleft: 0;\n\ttop: 0;\n\tz-index: 3000;\n}\n.control-box {\n z-index: 0;\n}\n.line, .control {\n\tleft: 0;\n\ttop: 0;\n}\n.control {\n\tposition: absolute;\n\twidth: 14px;\n\theight: 14px;\n\tborder-radius: 50%;\n\tborder: 2px solid #fff;\n\tbox-sizing: border-box;\n\tbackground: #4af;\n\tmargin-top: -7px;\n margin-left: -7px;\n z-index: 10;\n}\n.line {\n\tposition: absolute;\n\twidth: 1px;\n\theight: 1px;\n\tbackground: #4af;\n\ttransform-origin: 0px 0.5px;\n}\n.line.rotation-line {\n\theight: 40px;\n\twidth: 1px;\n\ttransform-origin: 0.5px 39.5px;\n}\n.line.rotation-line .control {\n\tborder-color: #4af;\n\tbackground:#fff;\n\tcursor: alias;\n}\n.line.vertical.bold {\n width: 2px;\n margin-left: -1px;\n}\n.line.horizontal.bold {\n height: 2px;\n margin-top: -1px;\n}\n.control.origin {\n\tborder-color: #f55;\n\tbackground: #fff;\n\twidth: 12px;\n\theight: 12px;\n\tmargin-top: -6px;\n\tmargin-left: -6px;\n\tpointer-events: none;\n}\n.direction.e, .direction.w {\n\tcursor: ew-resize;\n}\n.direction.s, .direction.n {\n\tcursor: ns-resize;\n}\n.direction.nw, .direction.se, :host.reverse .direction.ne, :host.reverse .direction.sw {\n\tcursor: nwse-resize;\n}\n.direction.ne, .direction.sw, :host.reverse .direction.nw, :host.reverse .direction.se {\n\tcursor: nesw-resize;\n}\n.group {\n z-index: -1;\n}\n.area {\n position: absolute;\n}\n.area-pieces {\n position: absolute;\n top: 0;\n left: 0;\n display: none;\n}\n.area.avoid {\n pointer-events: none;\n}\n.area.avoid+.area-pieces {\n display: block;\n}\n.area-piece {\n position: absolute;\n}\n" + (isWebkit ? ":global svg *:before {\n\tcontent:\"\";\n\ttransform-origin: inherit;\n}" : "") + "\n");
var NEARBY_POS = [[0, 1, 2], [1, 0, 3], [2, 0, 3], [3, 1, 2]];
var TINY_NUM = 0.0000001;
var MIN_SCALE = 0.000000001;
var MAX_NUM = Math.pow(10, 10);
var MIN_NUM = -MAX_NUM;
var DIRECTION_INDEXES = {
n: [0, 1],
s: [2, 3],
w: [2, 0],
e: [1, 3],
nw: [0],
ne: [1],
sw: [2],
se: [3]
};
function multiply2(pos1, pos2) {
return [pos1[0] * pos2[0], pos1[1] * pos2[1]];
}
function prefix() {
var classNames = [];
for (var _i = 0; _i < arguments.length; _i++) {
classNames[_i] = arguments[_i];
}
return prefixNames.apply(void 0, [PREFIX].concat(classNames));
}
function createIdentityMatrix3() {
return createIdentityMatrix(3);
}
function getTransformMatrix(transform) {
if (!transform || transform === "none") {
return [1, 0, 0, 1, 0, 0];
}
if (isObject(transform)) {
return transform;
}
var value = splitBracket(transform).value;
return value.split(/s*,\s*/g).map(function (v) {
return parseFloat(v);
});
}
function getAbsoluteMatrix(matrix, n, origin) {
return multiplies(n, createOriginMatrix(origin, n), matrix, createOriginMatrix(origin.map(function (a) {
return -a;
}), n));
}
function measureSVGSize(el, unit, isHorizontal) {
if (unit === "%") {
var viewBox = el.ownerSVGElement.viewBox.baseVal;
return viewBox[isHorizontal ? "width" : "height"] / 100;
}
return 1;
}
function getBeforeTransformOrigin(el) {
var relativeOrigin = getTransformOrigin(getComputedStyle(el, ":before"));
return relativeOrigin.map(function (o, i) {
var _a = splitUnit(o),
value = _a.value,
unit = _a.unit;
return value * measureSVGSize(el, unit, i === 0);
});
}
function getTransformOrigin(style) {
var transformOrigin = style.transformOrigin;
return transformOrigin ? transformOrigin.split(" ") : ["0", "0"];
}
function getOffsetInfo(el, lastParent, isParent) {
var body = document.body;
var target = !el || isParent ? el : el.parentElement;
var isEnd = false;
while (target && target !== body) {
if (lastParent === target) {
isEnd = true;
}
var _a = getComputedStyle(target),
position = _a.position,
transform = _a.transform;
if (position !== "static" || transform && transform !== "none") {
break;
}
target = target.parentElement;
}
return {
isEnd: isEnd || !target || target === body,
offsetParent: target || body
};
}
function caculateMatrixStack(target, container, prevMatrix, prevN) {
var _a;
var el = target;
var matrixes = [];
var isSVGGraphicElement = el.tagName.toLowerCase() !== "svg" && "ownerSVGElement" in el;
var originalContainer = container || document.body;
var isEnd = false;
var is3d = false;
var n = 3;
var transformOrigin;
var targetMatrix;
if (prevMatrix) {
container = target.parentElement;
}
while (el && !isEnd) {
var style = getComputedStyle(el);
var tagName = el.tagName.toLowerCase();
var position = style.position;
var isFixed = position === "fixed";
var styleTransform = style.transform;
var matrix = convertCSStoMatrix(getTransformMatrix(styleTransform));
if (!is3d && matrix.length === 16) {
is3d = true;
n = 4;
var matrixesLength = matrixes.length;
for (var i = 0; i < matrixesLength; ++i) {
matrixes[i] = convertDimension(matrixes[i], 3, 4);
}
}
if (is3d && matrix.length === 9) {
matrix = convertDimension(matrix, 3, 4);
}
var offsetLeft = el.offsetLeft;
var offsetTop = el.offsetTop;
if (isFixed) {
var containerRect = (container || document.documentElement).getBoundingClientRect();
offsetLeft -= containerRect.left;
offsetTop -= containerRect.top;
} // svg
var isSVG = isUndefined(offsetLeft);
var hasNotOffset = isSVG;
var origin = void 0; // inner svg element
if (hasNotOffset && tagName !== "svg") {
origin = isWebkit ? getBeforeTransformOrigin(el) : getTransformOrigin(style).map(function (pos) {
return parseFloat(pos);
});
hasNotOffset = false;
if (tagName === "g") {
offsetLeft = 0;
offsetTop = 0;
} else {
_a = getSVGGraphicsOffset(el, origin), offsetLeft = _a[0], offsetTop = _a[1], origin[0] = _a[2], origin[1] = _a[3];
}
} else {
origin = getTransformOrigin(style).map(function (pos) {
return parseFloat(pos);
});
}
if (tagName === "svg" && targetMatrix) {
matrixes.push(getSVGMatrix(el, n), createIdentityMatrix(n));
}
var parentElement = el.parentElement;
if (isWebkit && !hasNotOffset && !isSVG) {
var _b = getOffsetInfo(el, container),
isWebkitEnd = _b.isEnd,
offsetParent = _b.offsetParent;
parentElement = offsetParent;
offsetLeft -= (parentElement || container || document.body).offsetLeft;
offsetTop -= (parentElement || container || document.body).offsetTop;
isEnd = isEnd || isWebkitEnd;
}
matrixes.push(getAbsoluteMatrix(matrix, n, origin), createOriginMatrix([hasNotOffset ? el : offsetLeft - el.scrollLeft, hasNotOffset ? origin : offsetTop - el.scrollTop], n));
if (!targetMatrix) {
targetMatrix = matrix;
}
if (!transformOrigin) {
transformOrigin = origin;
}
if (isEnd || isFixed) {
break;
} else if (isWebkit) {
el = parentElement;
} else {
var _c = getOffsetInfo(el, container),
offsetParent = _c.offsetParent,
isOffsetEnd = _c.isEnd;
el = offsetParent;
isEnd = isOffsetEnd;
}
}
var mat = prevMatrix ? convertDimension(prevMatrix, prevN, n) : createIdentityMatrix(n);
var beforeMatrix = prevMatrix ? convertDimension(prevMatrix, prevN, n) : createIdentityMatrix(n);
var offsetMatrix = createIdentityMatrix(n);
var length = matrixes.length;
var endContainer = getOffsetInfo(originalContainer, originalContainer, true).offsetParent;
matrixes.reverse();
matrixes.forEach(function (matrix, i) {
var _a;
if (length - 2 === i) {
beforeMatrix = mat.slice();
}
if (length - 1 === i) {
offsetMatrix = mat.slice();
}
if (isObject(matrix[n - 1])) {
_a = getSVGOffset(matrix[n - 1], endContainer, n, matrix[2 * n - 1], mat, matrixes[i + 1]), matrix[n - 1] = _a[0], matrix[2 * n - 1] = _a[1];
}
mat = multiply(mat, matrix, n);
});
var isMatrix3d = !isSVGGraphicElement && is3d;
var transform = (isMatrix3d ? "matrix3d" : "matrix") + "(" + convertMatrixtoCSS(isSVGGraphicElement && targetMatrix.length === 16 ? convertDimension(targetMatrix, 4, 3) : targetMatrix) + ")";
return [beforeMatrix, offsetMatrix, mat, targetMatrix, transform, transformOrigin, is3d];
}
function getSVGMatrix(el, n) {
var clientWidth = el.clientWidth;
var clientHeight = el.clientHeight;
var viewBox = el.viewBox.baseVal;
var viewBoxWidth = viewBox.width || clientWidth;
var viewBoxHeight = viewBox.height || clientHeight;
var scaleX = clientWidth / viewBoxWidth;
var scaleY = clientHeight / viewBoxHeight;
var preserveAspectRatio = el.preserveAspectRatio.baseVal; // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio
var align = preserveAspectRatio.align; // 1 : meet 2: slice
var meetOrSlice = preserveAspectRatio.meetOrSlice;
var svgOrigin = [0, 0];
var scale = [scaleX, scaleY];
var translate = [0, 0];
if (align !== 1) {
var xAlign = (align - 2) % 3;
var yAlign = Math.floor((align - 2) / 3);
svgOrigin[0] = viewBoxWidth * xAlign / 2;
svgOrigin[1] = viewBoxHeight * yAlign / 2;
var scaleDimension = meetOrSlice === 2 ? Math.max(scaleY, scaleX) : Math.min(scaleX, scaleY);
scale[0] = scaleDimension;
scale[1] = scaleDimension;
translate[0] = (clientWidth - viewBoxWidth) / 2 * xAlign;
translate[1] = (clientHeight - viewBoxHeight) / 2 * yAlign;
}
var scaleMatrix = createScaleMatrix(scale, n);
scaleMatrix[n - 1] = translate[0], scaleMatrix[2 * n - 1] = translate[1];
return getAbsoluteMatrix(scaleMatrix, n, svgOrigin);
}
function getSVGGraphicsOffset(el, origin) {
if (!el.getBBox) {
return [0, 0];
}
var bbox = el.getBBox();
var svgElement = el.ownerSVGElement;
var viewBox = svgElement.viewBox.baseVal;
var left = bbox.x - viewBox.x;
var top = bbox.y - viewBox.y;
return [left, top, origin[0] - left, origin[1] - top];
}
function caculatePosition(matrix, pos, n) {
return caculate(matrix, convertPositionMatrix(pos, n), n);
}
function caculatePoses(matrix, width, height, n) {
var pos1 = caculatePosition(matrix, [0, 0], n);
var pos2 = caculatePosition(matrix, [width, 0], n);
var pos3 = caculatePosition(matrix, [0, height], n);
var pos4 = caculatePosition(matrix, [width, height], n);
return [pos1, pos2, pos3, pos4];
}
function getRect(poses) {
var posesX = poses.map(function (pos) {
return pos[0];
});
var posesY = poses.map(function (pos) {
return pos[1];
});
var left = Math.min.apply(Math, posesX);
var top = Math.min.apply(Math, posesY);
var right = Math.max.apply(Math, posesX);
var bottom = Math.max.apply(Math, posesY);
var rectWidth = right - left;
var rectHeight = bottom - top;
return {
left: left,
top: top,
right: right,
bottom: bottom,
width: rectWidth,
height: rectHeight
};
}
function caculateRect(matrix, width, height, n) {
var poses = caculatePoses(matrix, width, height, n);
return getRect(poses);
}
function getSVGOffset(el, container, n, origin, beforeMatrix, absoluteMatrix) {
var _a;
var _b = getSize(el),
width = _b[0],
height = _b[1];
var containerRect = container.getBoundingClientRect();
var rect = el.getBoundingClientRect();
var rectLeft = rect.left - containerRect.left + container.scrollLeft;
var rectTop = rect.top - containerRect.top + container.scrollTop;
var rectWidth = rect.width;
var rectHeight = rect.height;
var mat = multiplies(n, beforeMatrix, absoluteMatrix);
var _c = caculateRect(mat, width, height, n),
prevLeft = _c.left,
prevTop = _c.top,
prevWidth = _c.width,
prevHeight = _c.height;
var posOrigin = caculatePosition(mat, origin, n);
var prevOrigin = minus(posOrigin, [prevLeft, prevTop]);
var rectOrigin = [rectLeft + prevOrigin[0] * rectWidth / prevWidth, rectTop + prevOrigin[1] * rectHeight / prevHeight];
var offset = [0, 0];
var count = 0;
while (++count < 10) {
var inverseBeforeMatrix = invert(beforeMatrix, n);
_a = minus(caculatePosition(inverseBeforeMatrix, rectOrigin, n), caculatePosition(inverseBeforeMatrix, posOrigin, n)), offset[0] = _a[0], offset[1] = _a[1];
var mat2 = multiplies(n, beforeMatrix, createOriginMatrix(offset, n), absoluteMatrix);
var _d = caculateRect(mat2, width, height, n),
nextLeft = _d.left,
nextTop = _d.top;
var distLeft = nextLeft - rectLeft;
var distTop = nextTop - rectTop;
if (Math.abs(distLeft) < 2 && Math.abs(distTop) < 2) {
break;
}
rectOrigin[0] -= distLeft;
rectOrigin[1] -= distTop;
}
return offset.map(function (p) {
return Math.round(p);
});
}
function caculateMoveablePosition(matrix, origin, width, height) {
var is3d = matrix.length === 16;
var n = is3d ? 4 : 3;
var _a = caculatePoses(matrix, width, height, n),
_b = _a[0],
x1 = _b[0],
y1 = _b[1],
_c = _a[1],
x2 = _c[0],
y2 = _c[1],
_d = _a[2],
x3 = _d[0],
y3 = _d[1],
_e = _a[3],
x4 = _e[0],
y4 = _e[1];
var _f = caculatePosition(matrix, origin, n),
originX = _f[0],
originY = _f[1];
var left = Math.min(x1, x2, x3, x4);
var top = Math.min(y1, y2, y3, y4);
var right = Math.max(x1, x2, x3, x4);
var bottom = Math.max(y1, y2, y3, y4);
x1 = x1 - left || 0;
x2 = x2 - left || 0;
x3 = x3 - left || 0;
x4 = x4 - left || 0;
y1 = y1 - top || 0;
y2 = y2 - top || 0;
y3 = y3 - top || 0;
y4 = y4 - top || 0;
originX = originX - left || 0;
originY = originY - top || 0;
var center = [(x1 + x2 + x3 + x4) / 4, (y1 + y2 + y3 + y4) / 4];
var pos1Rad = getRad(center, [x1, y1]);
var pos2Rad = getRad(center, [x2, y2]);
var direction = pos1Rad < pos2Rad && pos2Rad - pos1Rad < Math.PI || pos1Rad > pos2Rad && pos2Rad - pos1Rad < -Math.PI ? 1 : -1;
return [[left, top, right, bottom], [originX, originY], [x1, y1], [x2, y2], [x3, y3], [x4, y4], direction];
}
function getLineStyle(pos1, pos2) {
var distX = pos2[0] - pos1[0];
var distY = pos2[1] - pos1[1];
var width = Math.sqrt(distX * distX + distY * distY);
var rad = getRad(pos1, pos2);
return {
transform: "translate(" + pos1[0] + "px, " + pos1[1] + "px) rotate(" + rad + "rad)",
width: width + "px"
};
}
function getControlTransform() {
var poses = [];
for (var _i = 0; _i < arguments.length; _i++) {
poses[_i] = arguments[_i];
}
var length = poses.length;
var x = poses.reduce(function (prev, pos) {
return prev + pos[0];
}, 0) / length;
var y = poses.reduce(function (prev, pos) {
return prev + pos[1];
}, 0) / length;
return {
transform: "translate(" + x + "px, " + y + "px)"
};
}
function getSize(target, style, isOffset, isBoxSizing) {
if (style === void 0) {
style = getComputedStyle(target);
}
if (isBoxSizing === void 0) {
isBoxSizing = isOffset || style.boxSizing === "border-box";
}
var width = target.offsetWidth;
var height = target.offsetHeight;
var hasOffset = !isUndefined(width);
if ((isOffset || isBoxSizing) && hasOffset) {
return [width, height];
}
width = target.clientWidth;
height = target.clientHeight;
if (!hasOffset && !width && !height) {
var bbox = target.getBBox();
return [bbox.width, bbox.height];
}
if (isOffset || isBoxSizing) {
var borderLeft = parseFloat(style.borderLeftWidth) || 0;
var borderRight = parseFloat(style.borderRightWidth) || 0;
var borderTop = parseFloat(style.borderTopWidth) || 0;
var borderBottom = parseFloat(style.borderBottomWidth) || 0;
return [width + borderLeft + borderRight, height + borderTop + borderBottom];
} else {
var paddingLeft = parseFloat(style.paddingLeft) || 0;
var paddingRight = parseFloat(style.paddingRight) || 0;
var paddingTop = parseFloat(style.paddingTop) || 0;
var paddingBottom = parseFloat(style.paddingBottom) || 0;
return [width - paddingLeft - paddingRight, height - paddingTop - paddingBottom];
}
}
function getTargetInfo(target, container, parentContainer, state) {
var _a, _b, _c, _d, _e;
var left = 0;
var top = 0;
var right = 0;
var bottom = 0;
var origin = [0, 0];
var pos1 = [0, 0];
var pos2 = [0, 0];
var pos3 = [0, 0];
var pos4 = [0, 0];
var offsetMatrix = createIdentityMatrix3();
var beforeMatrix = createIdentityMatrix3();
var matrix = createIdentityMatrix3();
var targetMatrix = createIdentityMatrix3();
var width = 0;
var height = 0;
var transformOrigin = [0, 0];
var direction = 1;
var beforeDirection = 1;
var is3d = false;
var targetTransform = "";
var beforeOrigin = [0, 0];
var clientRect = {
left: 0,
right: 0,
top: 0,
bottom: 0,
width: 0,
height: 0
};
var containerRect = {
left: 0,
right: 0,
top: 0,
bottom: 0,
width: 0,
height: 0
};
var prevMatrix = state ? state.beforeMatrix : undefined;
var prevN = state ? state.is3d ? 4 : 3 : undefined;
if (target) {
if (state) {
width = state.width;
height = state.height;
} else {
var style = getComputedStyle(target);
width = target.offsetWidth;
height = target.offsetHeight;
if (isUndefined(width)) {
_a = getSize(target, style, true), width = _a[0], height = _a[1];
}
}
_b = caculateMatrixStack(target, container, prevMatrix, prevN), beforeMatrix = _b[0], offsetMatrix = _b[1], matrix = _b[2], targetMatrix = _b[3], targetTransform = _b[4], transformOrigin = _b[5], is3d = _b[6];
_c = caculateMoveablePosition(matrix, transformOrigin, width, height), _d = _c[0], left = _d[0], top = _d[1], right = _d[2], bottom = _d[3], origin = _c[1], pos1 = _c[2], pos2 = _c[3], pos3 = _c[4], pos4 = _c[5], direction = _c[6];
var n = is3d ? 4 : 3;
var beforePos = [0, 0];
_e = caculateMoveablePosition(offsetMatrix, plus(transformOrigin, getOrigin(targetMatrix, n)), width, height), beforePos = _e[0], beforeOrigin = _e[1], beforeDirection = _e[6];
beforeOrigin = [beforeOrigin[0] + beforePos[0] - left, beforeOrigin[1] + beforePos[1] - top];
clientRect = getClientRect(target);
containerRect = getClientRect(getOffsetInfo(parentContainer, parentContainer, true).offsetParent || document.body.offsetParent);
}
return {
containerRect: containerRect,
beforeDirection: beforeDirection,
direction: direction,
target: target,
left: left,
top: top,
right: right,
bottom: bottom,
pos1: pos1,
pos2: pos2,
pos3: pos3,
pos4: pos4,
width: width,
height: height,
beforeMatrix: beforeMatrix,
matrix: matrix,
targetTransform: targetTransform,
offsetMatrix: offsetMatrix,
targetMatrix: targetMatrix,
is3d: is3d,
beforeOrigin: beforeOrigin,
origin: origin,
transformOrigin: transformOrigin,
clientRect: clientRect
};
}
function getClientRect(el) {
var _a = el.getBoundingClientRect(),
left = _a.left,
width = _a.width,
top = _a.top,
bottom = _a.bottom,
right = _a.right,
height = _a.height;
return {
left: left,
right: right,
top: top,
bottom: bottom,
width: width,
height: height
};
}
function getDirection(target) {
if (!target) {
return;
}
var direciton = target.getAttribute("data-direction");
if (!direciton) {
return;
}
var dir = [0, 0];
direciton.indexOf("w") > -1 && (dir[0] = -1);
direciton.indexOf("e") > -1 && (dir[0] = 1);
direciton.indexOf("n") > -1 && (dir[1] = -1);
direciton.indexOf("s") > -1 && (dir[1] = 1);
return dir;
}
function getAbsolutePoses(poses, dist) {
return [plus(dist, poses[0]), plus(dist, poses[1]), plus(dist, poses[2]), plus(dist, poses[3])];
}
function getAbsolutePosesByState(_a) {
var left = _a.left,
top = _a.top,
pos1 = _a.pos1,
pos2 = _a.pos2,
pos3 = _a.pos3,
pos4 = _a.pos4;
return getAbsolutePoses([pos1, pos2, pos3, pos4], [left, top]);
}
function throttle(num, unit) {
if (!unit) {
return num;
}
return Math.round(num / unit) * unit;
}
function throttleArray(nums, unit) {
nums.forEach(function (_, i) {
nums[i] = throttle(nums[i], unit);
});
return nums;
}
function unset(self, name) {
if (self[name]) {
self[name].unset();
self[name] = null;
}
}
function getOrientationDirection(pos, pos1, pos2) {
return (pos[0] - pos1[0]) * (pos2[1] - pos1[1]) - (pos[1] - pos1[1]) * (pos2[0] - pos1[0]);
}
function isInside(pos, pos1, pos2, pos3, pos4) {
var k1 = getOrientationDirection(pos, pos1, pos2);
var k2 = getOrientationDirection(pos, pos2, pos4);
var k3 = getOrientationDirection(pos, pos4, pos1);
var k4 = getOrientationDirection(pos, pos2, pos4);
var k5 = getOrientationDirection(pos, pos4, pos3);
var k6 = getOrientationDirection(pos, pos3, pos2);
var signs1 = [k1, k2, k3];
var signs2 = [k4, k5, k6];
if (signs1.every(function (sign) {
return sign >= 0;
}) || signs1.every(function (sign) {
return sign <= 0;
}) || signs2.every(function (sign) {
return sign >= 0;
}) || signs2.every(function (sign) {
return sign <= 0;
})) {
return true;
}
return false;
}
function fillParams(moveable, e, params) {
var datas = e.datas;
if (!datas.datas) {
datas.datas = {};
}
return __assign({}, params, {
target: moveable.state.target,
clientX: e.clientX,
clientY: e.clientY,
inputEvent: e.inputEvent,
currentTarget: moveable,
datas: datas.datas
});
}
function triggerEvent(moveable, name, params) {
return moveable.triggerEvent(name, params);
}
function getComputedStyle(el, pseudoElt) {
return window.getComputedStyle(el, pseudoElt);
}
function filterAbles(ables, methods) {
var enabledAbles = {};
var ableGroups = {};
return ables.filter(function (able) {
var name = able.name;
if (enabledAbles[name] || !methods.some(function (method) {
return able[method];
})) {
return false;
}
if (able.ableGroup) {
if (ableGroups[name]) {
return false;
}
ableGroups[name] = true;
}
enabledAbles[name] = true;
return true;
});
}
function getKeepRatioHeight(width, isWidth, ratio) {
return width * (isWidth ? ratio : 1 / ratio);
}
function getKeepRatioWidth(height, isWidth, ratio) {
return height * (isWidth ? 1 / ratio : ratio);
}
function triggerRenderStart(moveable, isGroup, e) {
var params = fillParams(moveable, e, {
isPinch: !!e.isPinch
});
var eventAffix = isGroup ? "Group" : "";
if (isGroup) {
params.targets = moveable.props.targets;
}
triggerEvent(moveable, "onRender" + eventAffix + "Start", params);
}
function triggerRender(moveable, isGroup, e) {
var params = fillParams(moveable, e, {
isPinch: !!e.isPinch
});
var eventAffix = isGroup ? "Group" : "";
if (isGroup) {
params.targets = moveable.props.targets;
}
triggerEvent(moveable, "onRender" + eventAffix, params);
}
function triggerRenderEnd(moveable, isGroup, e) {
var params = fillParams(moveable, e, {
isPinch: !!e.sPinch,
isDrag: e.isDrag
});
var eventAffix = isGroup ? "Group" : "";
if (isGroup) {
params.targets = moveable.props.targets;
}
triggerEvent(moveable, "onRender" + eventAffix + "End", params);
}
function triggerAble(moveable, ableType, eventOperation, eventAffix, eventType, e) {
var isStart = eventType === "Start";
if (isStart && eventAffix.indexOf("Control") > -1 && moveable.areaElement === e.inputEvent.target) {
return false;
}
var eventName = "" + eventOperation + eventAffix + eventType;
var conditionName = "" + eventOperation + eventAffix + "Condition";
var isEnd = eventType === "End";
if (isStart) {
moveable.updateRect(eventType, true, false);
}
var isGroup = eventAffix.indexOf("Group") > -1;
var ables = moveable[ableType];
var results = ables.filter(function (able) {
var condition = isStart && able[conditionName];
if (able[eventName] && (!condition || condition(e.inputEvent.target, moveable))) {
return able[eventName](moveable, e);
}
return false;
});
var isUpdate = results.length;
if (isStart) {
triggerRenderStart(moveable, isGroup, e);
} else if (isEnd) {
triggerRenderEnd(moveable, isGroup, e);
} else {
triggerRender(moveable, isGroup, e);
}
if (isEnd) {
moveable.state.dragger = null;
}
if (!isStart && isUpdate) {
if (results.some(function (able) {
return able.updateRect;
}) && !isGroup) {
moveable.updateRect(eventType);
} else {
moveable.updateTarget(eventType);
}
} else if (isEnd && !isUpdate) {
moveable.forceUpdate();
}
}
function getAbleDragger(moveable, target, ableType, eventAffix) {
var options = {
container: window,
pinchThreshold: moveable.props.pinchThreshold
};
["drag", "pinch"].forEach(function (eventOperation) {
["Start", "", "End"].forEach(function (eventType) {
options["" + eventOperation + eventType.toLowerCase()] = function (e) {
return triggerAble(moveable, ableType, eventOperation, eventAffix, eventType, e);
};
});
});
return new Dragger(target, options);
}
var ControlBoxElement = styler("div", MOVEABLE_CSS);
function renderLine(direction, pos1, pos2, index) {
return createElement("div", {
key: "line" + index,
className: prefix("line", "direction", direction),
"data-direction": direction,
style: getLineStyle(pos1, pos2)
});
}
var MoveableManager =
/*#__PURE__*/
function (_super) {
__extends(MoveableManager, _super);
function MoveableManager() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = {
conatainer: null,
target: null,
beforeMatrix: createIdentityMatrix3(),
matrix: createIdentityMatrix3(),
targetMatrix: createIdentityMatrix3(),
targetTransform: "",
is3d: false,
left: 0,
top: 0,
width: 0,
height: 0,
transformOrigin: [0, 0],
direction: 1,
beforeDirection: 1,
beforeOrigin: [0, 0],
origin: [0, 0],
pos1: [0, 0],
pos2: [0, 0],
pos3: [0, 0],
pos4: [0, 0],
clientRect: {
left: 0,
top: 0,
bottom: 0,
right: 0,
width: 0,
height: 0
},
containerRect: {
left: 0,
top: 0,
bottom: 0,
right: 0,
width: 0,
height: 0
}
};
_this.targetAbles = [];
_this.controlAbles = [];
return _this;
}
var __proto = MoveableManager.prototype;
__proto.render = function () {
var _a = this.props,
edge = _a.edge,
parentPosition = _a.parentPosition,
className = _a.className;
this.checkUpdate();
var _b = parentPosition || {
left: 0,
top: 0
},
parentLeft = _b.left,
parentTop = _b.top;
var _c = this.state,
left = _c.left,
top = _c.top,
pos1 = _c.pos1,
pos2 = _c.pos2,
pos3 = _c.pos3,
pos4 = _c.pos4,
target = _c.target,
direction = _c.direction;
return createElement(ControlBoxElement, {
ref: ref(this, "controlBox"),
className: prefix("control-box", direction === -1 ? "reverse" : "") + " " + className,
style: {
position: "absolute",
display: target ? "block" : "none",
transform: "translate(" + (left - parentLeft) + "px, " + (top - parentTop) + "px) translateZ(50px)"
}
}, this.renderAbles(), renderLine(edge ? "n" : "", pos1, pos2, 0), renderLine(edge ? "e" : "", pos2, pos4, 1), renderLine(edge ? "w" : "", pos1, pos3, 2), renderLine(edge ? "s" : "", pos3, pos4, 3));
};
__proto.componentDidMount = function () {
this.controlBox.getElement();
var props = this.props;
var parentMoveable = props.parentMoveable,
container = props.container;
this.updateEvent(props);
if (!container && !parentMoveable) {
this.updateRect("End", false, true);
}
};
__proto.componentDidUpdate = function (prevProps) {
this.updateEvent(prevProps);
};
__proto.componentWillUnmount = function () {
unset(this, "targetDragger");
unset(this, "controlDragger");
};
__proto.getContainer = function () {
var _a = this.props,
parentMoveable = _a.parentMoveable,
container = _a.container;
return container || parentMoveable && parentMoveable.getContainer() || this.controlBox.getElement().offsetParent;
};
__proto.isMoveableElement = function (target) {
return target && (target.getAttribute("class") || "").indexOf(PREFIX) > -1;
};
__proto.dragStart = function (e) {
if (this.targetDragger) {
this.targetDragger.onDragStart(e);
}
};
__proto.isInside = function (clientX, clientY) {
var _a = this.state,
pos1 = _a.pos1,
pos2 = _a.pos2,
pos3 = _a.pos3,
pos4 = _a.pos4,
target = _a.target;
if (!target) {
return false;
}
var _b = target.getBoundingClientRect(),
left = _b.left,
top = _b.top;
var pos = [clientX - left, clientY - top];
return isInside(pos, pos1, pos2, pos4, pos3);
};
__proto.updateRect = function (type, isTarget, isSetState) {
if (isSetState === void 0) {
isSetState = true;
}
var parentMoveable = this.props.parentMoveable;
var state = this.state;
var target = state.target || this.props.target;
var container = this.getContainer();
this.updateState(getTargetInfo(target, container, container, isTarget ? state : undefined), parentMoveable ? false : isSetState);
};
__proto.updateEvent = function (prevProps) {
var controlBoxElement = this.controlBox.getElement();
var hasTargetAble = this.targetAbles.length;
var hasControlAble = this.controlAbles.length;
var target = this.props.target;
var prevTarget = prevProps.target;
var dragArea = this.props.dragArea;
var prevDragArea = prevProps.dragArea;
var isTargetChanged = !dragArea && prevTarget !== target;
var isUnset = !hasTargetAble && this.targetDragger || isTargetChanged || prevDragArea !== dragArea;
if (isUnset) {
unset(this, "targetDragger");
this.updateState({
dragger: null
});
}
if (!hasControlAble) {
unset(this, "controlDragger");
}
if (target && hasTargetAble && !this.targetDragger) {
if (dragArea) {
this.targetDragger = getAbleDragger(this, this.areaElement, "targetAbles", "");
} else {
this.targetDragger = getAbleDragger(this, target, "targetAbles", "");
}
}
if (!this.controlDragger && hasControlAble) {
this.controlDragger = getAbleDragger(this, controlBoxElement, "controlAbles", "Control");
}
if (isUnset) {
this.unsetAbles();
}
};
__proto.updateTarget = function (type) {
this.updateRect(type, true);
};
__proto.getRect = function () {
var poses = getAbsolutePosesByState(this.state);
var pos1 = poses[0],
pos2 = poses[1],
pos3 = poses[2],
pos4 = poses[3];
var rect = getRect(poses);
var width = rect.width,
height = rect.height,
left = rect.left,
top = rect.top;
return {
width: width,
height: height,
left: left,
top: top,
pos1: pos1,
pos2: pos2,
pos3: pos3,
pos4: pos4
};
};
__proto.checkUpdate = function () {
var _a = this.props,
target = _a.target,
container = _a.container,
parentMoveable = _a.parentMoveable;
var _b = this.state,
stateTarget = _b.target,
stateContainer = _b.container;
if (!stateTarget && !target) {
return;
}
this.updateAbles();
var isChanged = stateTarget !== target || stateContainer !== container;
if (!isChanged) {
return;
}
this.updateState({
target: target,
container: container
});
if (!parentMoveable && (container || this.controlBox)) {
this.updateRect("End", false, false);
}
};
__proto.triggerEvent = function (name, e) {
var callback = this.props[name];
return callback && callback(e);
};
__proto.unsetAbles = function () {
var _this = this;
if (this.targetAbles.filter(function (able) {
if (able.unset) {
able.unset(_this);
return true;
}
return false;
}).length) {
this.forceUpdate();
}
};
__proto.updateAbles = function (ables, eventAffix) {
if (ables === void 0) {
ables = this.props.ables;
}
if (eventAffix === void 0) {
eventAffix = "";
}
var props = this.props;
var enabledAbles = ables.filter(function (able) {
return able && props[able.name];
});
var dragStart = "drag" + eventAffix + "Start";
var pinchStart = "pinch" + eventAffix + "Start";
var dragControlStart = "drag" + eventAffix + "ControlStart";
var targetAbles = filterAbles(enabledAbles, [dragStart, pinchStart]);
var controlAbles = filterAbles(enabledAbles, [dragControlStart]);
this.targetAbles = targetAbles;
this.controlAbles = controlAbles;
};
__proto.updateState = function (nextState, isSetState) {
if (isSetState) {
this.setState(nextState);
} else {
var state = this.state;
for (var name in nextState) {
state[name] = nextState[name];
}
}
};
__proto.renderAbles = function () {
var _this = this;
var props = this.props;
var ables = props.ables;
var enabledAbles = ables.filter(function (able) {
return able && props[able.name];
});
return filterAbles(enabledAbles, ["render"]).map(function (_a) {
var render = _a.render;
return render(_this, React);
});
};
MoveableManager.defaultProps = {
target: null,
container: null,
origin: true,
keepRatio: false,
edge: false,
parentMoveable: null,
parentPosition: null,
ables: [],
pinchThreshold: 20,
dragArea: false,
transformOrigin: "",
className: ""
};
return MoveableManager;
}(PureComponent);
function getRotatiion(touches) {
return getRad([touches[0].clientX, touches[0].clientY], [touches[1].clientX, touches[1].clientY]) / Math.PI * 180;
}
var Pinchable = {
name: "pinchable",
updateRect: true,
pinchStart: function (moveable, e) {
var datas = e.datas,
clientX = e.clientX,
clientY = e.clientY,
touches = e.touches,
inputEvent = e.inputEvent,
targets = e.targets;
var _a = moveable.props,
pinchable = _a.pinchable,
ables = _a.ables;
if (!pinchable) {
return false;
}
var eventName = "onPinch" + (targets ? "Group" : "") + "Start";
var controlEventName = "drag" + (targets ? "Group" : "") + "ControlStart";
var pinchAbles = (pinchable === true ? moveable.controlAbles : ables.filter(function (able) {
return pinchable.indexOf(able.name) > -1;
})).filter(function (able) {
return able.canPinch && able[controlEventName];
});
var params = fillParams(moveable, e, {});
if (targets) {
params.targets = targets;
}
var result = triggerEvent(moveable, eventName, params);
datas.isPinch = result !== false;
datas.ables = pinchAbles;
var isPinch = datas.isPinch;
if (!isPinch) {
return false;
}
var parentRotate = getRotatiion(touches);
pinchAbles.forEach(function (able) {
datas[able.name + "Datas"] = {};
var ableEvent = {
datas: datas[able.name + "Datas"],
clientX: clientX,
clientY: clientY,
inputEvent: inputEvent,
parentRotate: parentRotate,
pinchFlag: true
};
able[controlEventName](moveable, ableEvent);
});
moveable.state.snapDirection = [0, 0];
return isPinch;
},
pinch: function (moveable, e) {
var datas = e.datas,
clientX = e.clientX,
clientY = e.clientY,
pinchScale = e.scale,
distance = e.distance,
touches = e.touches,
inputEvent = e.inputEvent,
targets = e.targets;
if (!datas.isPinch) {
return;
}
var parentRotate = getRotatiion(touches);
var parentDistance = distance * (1 - 1 / pinchScale);
var params = fillParams(moveable, e, {});
if (targets) {
params.targets = targets;
}
var eventName = "onPinch" + (targets ? "Group" : "");
triggerEvent(moveable, eventName, params);
var ables = datas.ables;
var controlEventName = "drag" + (targets ? "Group" : "") + "Control";
ables.forEach(function (able) {
able[controlEventName](moveable, {
clientX: clientX,
clientY: clientY,
datas: datas[able.name + "Datas"],
inputEvent: inputEvent,
parentDistance: parentDistance,
parentRotate: parentRotate,
pinchFlag: true
});
});
return params;
},
pinchEnd: function (moveable, e) {
var datas = e.datas,
clientX = e.clientX,
clientY = e.clientY,
isPinch = e.isPinch,
inputEvent = e.inputEvent,
targets = e.targets;
if (!datas.isPinch) {
return;
}
var eventName = "onPinch" + (targets ? "Group" : "") + "End";
var params = fillParams(moveable, e, {
isDrag: isPinch
});
if (targets) {
params.targets = targets;
}
triggerEvent(moveable, eventName, params);
var ables = datas.ables;
var controlEventName = "drag" + (targets ? "Group" : "") + "ControlEnd";
ables.forEach(function (able) {
able[controlEventName](moveable, {
clientX: clientX,
clientY: clientY,
isDrag: isPinch,
datas: datas[able.name + "Datas"],
inputEvent: inputEvent,
pinchFlag: true
});
});
return isPinch;
},
pinchGroupStart: function (moveable, e) {
return this.pinchStart(moveable, __assign({}, e, {
targets: moveable.props.targets
}));
},
pinchGroup: function (moveable, e) {
return this.pinch(moveable, __assign({}, e, {
targets: moveable.props.targets
}));
},
pinchGroupEnd: function (moveable, e) {
return this.pinchEnd(moveable, __assign({}, e, {
targets: moveable.props.targets
}));
}
};
function triggerChildAble(moveable, able, type, datas, eachEvent, callback) {
var name = able.name;
var ableDatas = datas[name] || (datas[name] = []);
var isEnd = !!type.match(/End$/g);
var childs = moveable.moveables.map(function (child, i) {
var childDatas = ableDatas[i] || (ableDatas[i] = {});
var childEvent = isFunction(eachEvent) ? eachEvent(child, childDatas) : eachEvent;
var result = able[type](child, __assign({}, childEvent, {
datas: childDatas,
parentFlag: true
}));
result && callback && callback(child, childDatas, result, i);
if (isEnd) {
child.state.dragger = null;
}
return result;
});
return childs;
}
function directionCondition(target) {
return hasClass(target, prefix("direction"));
}
function setDragStart(moveable, _a) {
var datas = _a.datas;
var _b = moveable.state,
matrix = _b.matrix,
beforeMatrix = _b.beforeMatrix,
is3d = _b.is3d,
left = _b.left,
top = _b.top,
origin = _b.origin,
offsetMatrix = _b.offsetMatrix,
targetMatrix = _b.targetMatrix,
transformOrigin = _b.transformOrigin;
var n = is3d ? 4 : 3;
datas.is3d = is3d;
datas.matrix = matrix;
datas.targetMatrix = targetMatrix;
datas.beforeMatrix = beforeMatrix;
datas.offsetMatrix = offsetMatrix;
datas.transformOrigin = transformOrigin;
datas.inverseMatrix = invert(matrix, n);
datas.inverseBeforeMatrix = invert(beforeMatrix, n);
datas.absoluteOrigin = convertPositionMatrix(plus([left, top], origin), n);
datas.startDragBeforeDist = caculate(datas.inverseBeforeMatrix, datas.absoluteOrigin, n);
datas.startDragDist = caculate(datas.inverseMatrix, datas.absoluteOrigin, n);
}
function getDragDist(_a, isBefore) {
var datas = _a.datas,
distX = _a.distX,
distY = _a.distY;
var inverseBeforeMatrix = datas.inverseBeforeMatrix,
inverseMatrix = datas.inverseMatrix,
is3d = datas.is3d,
startDragBeforeDist = datas.startDragBeforeDist,
startDragDist = datas.startDragDist,
absoluteOrigin = datas.absoluteOrigin;
var n = is3d ? 4 : 3;
return minus(caculate(isBefore ? inverseBeforeMatrix : inverseMatrix, plus(absoluteOrigin, [distX, distY]), n), isBefore ? startDragBeforeDist : startDragDist);
}
function caculateTransformOrigin(transformOrigin, width, height, prevWidth, prevHeight, prevOrigin) {
if (prevWidth === void 0) {
prevWidth = width;
}
if (prevHeight === void 0) {
prevHeight = height;
}
if (prevOrigin === void 0) {
prevOrigin = [0, 0];
}
if (!transformOrigin) {
return prevOrigin;
}
return transformOrigin.map(function (pos, i) {
var _a = splitUnit(pos),
value = _a.value,
unit = _a.unit;
var prevSize = i ? prevHeight : prevWidth;
var size = i ? height : width;
if (pos === "%" || isNaN(value)) {
// no value but %
var measureRatio = prevSize ? prevOrigin[i] / prevSize : 0;
return size * measureRatio;
} else if (unit !== "%") {
return value;
}
return size * value / 100;
});
}
function getPosIndexesByDirection(direction) {
var indexes = [];
if (direction[1] >= 0) {
if (direction[0] >= 0) {
indexes.push(3);
}
if (direction[0] <= 0) {
indexes.push(2);
}
}
if (direction[1] <= 0) {
if (direction[0] >= 0) {
indexes.push(1);
}
if (direction[0] <= 0) {
indexes.push(0);
}
}
return indexes;
}
function getPosesByDirection(poses, direction) {
/*
[-1, -1](pos1) [0, -1](pos1,pos2) [1, -1](pos2)
[-1, 0](pos1, pos3) [1, 0](pos2, pos4)
[-1, 1](pos3) [0, 1](pos3, pos4) [1, 1](pos4)
*/
return getPosIndexesByDirection(direction).map(function (index) {
return poses[index];
});
}
function getPosByDirection(poses, direction) {
/*
[-1, -1](pos1) [0, -1](pos1,pos2) [1, -1](pos2)
[-1, 0](pos1, pos3) [1, 0](pos2, pos4)
[-1, 1](pos3) [0, 1](pos3, pos4) [1, 1](pos4)
*/
var nextPoses = getPosesByDirection(poses, direction);
return [average.apply(void 0, nextPoses.map(function (pos) {
return pos[0];
})), average.apply(void 0, nextPoses.map(function (pos) {
return pos[1];
}))];
}
function getPosByReverseDirection(_a, direction) {
/*
[-1, -1](pos4) [0, -1](pos3,pos4) [1, -1](pos3)
[-1, 0](pos2, pos4) [1, 0](pos3, pos1)
[-1, 1](pos2) [0, 1](pos1, pos2) [1, 1](pos1)
*/
var pos1 = _a[0],
pos2 = _a[1],
pos3 = _a[2],
pos4 = _a[3];
return getPosByDirection([pos4, pos3, pos2, pos1], direction);
}
function getStartPos(poses, direction) {
var startPos1 = poses[0],
startPos2 = poses[1],
startPos3 = poses[2],
startPos4 = poses[3];
return getPosByReverseDirection([startPos1, startPos2, startPos3, startPos4], direction);
}
function getDist(startPos, matrix, width, height, n, direction) {
var poses = caculatePoses(matrix, width, height, n);
var pos = getPosByReverseDirection(poses, direction);
var distX = startPos[0] - pos[0];
var distY = startPos[1] - pos[1];
return [distX, distY];
}
function getNextMatrix(offsetMatrix, targetMatrix, origin, n) {
return multiply(offsetMatrix, getAbsoluteMatrix(targetMatrix, n, origin), n);
}
function scaleMatrix(state, scale) {
var transformOrigin = state.transformOrigin,
offsetMatrix = state.offsetMatrix,
is3d = state.is3d,
targetMatrix = state.targetMatrix;
var n = is3d ? 4 : 3;
return getNextMatrix(offsetMatrix, multiply(targetMatrix, createScaleMatrix(scale, n), n), transformOrigin, n);
}
function getScaleDist(moveable, scale, direction, dragClient) {
var state = moveable.state;
var is3d = state.is3d,
left = state.left,
top = state.top,
width = state.width,
height = state.height;
var n = is3d ? 4 : 3;
var groupable = moveable.props.groupable;
var nextMatrix = scaleMatrix(moveable.state, scale);
var groupLeft = groupable ? left : 0;
var groupTop = groupable ? top : 0;
var startPos = dragClient ? dragClient : getStartPos(getAbsolutePosesByState(moveable.state), direction);
var dist = getDist(startPos, nextMatrix, width, height, n, direction);
return minus(dist, [groupLeft, groupTop]);
}
function getResizeDist(moveable, width, height, direction, transformOrigin, dragClient) {
var groupable = moveable.props.groupable;
var _a = moveable.state,
prevOrigin = _a.transformOrigin,
targetMatrix = _a.targetMatrix,
offsetMatrix = _a.offsetMatrix,
is3d = _a.is3d,
prevWidth = _a.width,
prevheight = _a.height,
left = _a.left,
top = _a.top;
var n = is3d ? 4 : 3;
var nextOrigin = caculateTransformOrigin(transformOrigin, width, height, prevWidth, prevheight, prevOrigin);
var groupLeft = groupable ? left : 0;
var groupTop = groupable ? top : 0;
var nextMatrix = getNextMatrix(offsetMatrix, targetMatrix, nextOrigin, n);
var startPos = dragClient ? dragClient : getStartPos(getAbsolutePosesByState(moveable.state), direction);
var dist = getDist(startPos, nextMatrix, width, height, n, direction);
return minus(dist, [groupLeft, groupTop]);
}
function snapStart(moveable) {
var state = moveable.state;
if (state.guidelines && state.guidelines.length) {
return;
}
var _a = moveable.props,
_b = _a.horizontalGuidelines,
horizontalGuidelines = _b === void 0 ? [] : _b,
_c = _a.verticalGuidelines,
verticalGuidelines = _c === void 0 ? [] : _c,
_d = _a.elementGuidelines,
elementGuidelines = _d === void 0 ? [] : _d,
bounds = _a.bounds,
snapCenter = _a.snapCenter;
if (!bounds && !horizontalGuidelines.length && !verticalGuidelines.length && !elementGuidelines.length) {
return;
}
var _e = state.containerRect,
containerWidth = _e.width,
containerHeight = _e.height,
containerTop = _e.top,
containerLeft = _e.left,
_f = state.clientRect,
clientTop = _f.top,
clientLeft = _f.left,
targetLeft = state.left,
targetTop = state.top;
var distLeft = targetLeft - (clientLeft - containerLeft);
var distTop = targetTop - (clientTop - containerTop);
var guidelines = [];
horizontalGuidelines.forEach(function (pos) {
guidelines.push({
type: "horizontal",
pos: [0, pos],
size: containerWidth
});
});
verticalGuidelines.forEach(function (pos) {
guidelines.push({
type: "vertical",
pos: [pos, 0],
size: