@plait/draw 0.30.0 → 0.32.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/constants/line.d.ts +1 -0
- package/esm2022/constants/line.mjs +2 -1
- package/esm2022/plugins/with-geometry-resize.mjs +50 -15
- package/esm2022/plugins/with-line-resize.mjs +28 -10
- package/esm2022/utils/hit.mjs +22 -8
- package/esm2022/utils/line-arrow.mjs +22 -17
- package/esm2022/utils/line.mjs +6 -9
- package/esm2022/utils/position/geometry.mjs +1 -1
- package/fesm2022/plait-draw.mjs +120 -51
- package/fesm2022/plait-draw.mjs.map +1 -1
- package/package.json +1 -1
- package/utils/clipboard.d.ts +1 -1
- package/utils/geometry.d.ts +1 -1
- package/utils/hit.d.ts +2 -0
- package/utils/line.d.ts +0 -1
- package/utils/position/geometry.d.ts +2 -1
package/fesm2022/plait-draw.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PlaitElement, ACTIVE_STROKE_WIDTH, PlaitBoard, setStrokeLinecap, isPointInPolygon, getNearestPointBetweenPointAndSegments, RectangleClient, isPointInEllipse, drawRectangle, drawRoundRectangle, isPointInRoundRectangle, Transforms, clearSelectedElement, addSelectedElement, PlaitNode, Point, BOARD_TO_HOST, transformPoint, toPoint, idCreator, createG, BoardTransforms, PlaitPointerType, preventTouchMove, createForeignObject, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, drawCircle, distanceBetweenPointAndSegment, arrowPoints, createPath, drawLinearPath, rotate, getElementById,
|
|
2
|
-
import { getRectangleByPoints, Generator, normalizeShapePoints, isDndMode, isDrawingMode, getFactorByPoints, getDirectionByVector, getOppositeDirection, getDirectionFactor, DEFAULT_ROUTE_MARGIN, reduceRouteMargin, getNextPoint, generateElbowLineRoute, getPoints, removeDuplicatePoints, getPointByVector, getPointOnPolyline, getDirectionByPointOfRectangle, rotateVectorAnti90, CommonPluginElement, ActiveGenerator, WithTextPluginKey, RESIZE_HANDLE_DIAMETER, PRIMARY_COLOR, isVirtualKey, isDelete, isSpaceHotkey, acceptImageTypes, getElementOfFocusedImage, buildImage, getRectangleResizeHandleRefs, ResizeHandle, withResize, isResizingByCondition, getRatioByPoint, ImageGenerator } from '@plait/common';
|
|
1
|
+
import { PlaitElement, ACTIVE_STROKE_WIDTH, PlaitBoard, setStrokeLinecap, isPointInPolygon, getNearestPointBetweenPointAndSegments, RectangleClient, isPointInEllipse, drawRectangle, drawRoundRectangle, isPointInRoundRectangle, Transforms, clearSelectedElement, addSelectedElement, PlaitNode, Point, BOARD_TO_HOST, transformPoint, toPoint, idCreator, createG, BoardTransforms, PlaitPointerType, preventTouchMove, createForeignObject, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, drawCircle, distanceBetweenPointAndSegment, arrowPoints, createPath, drawLinearPath, distanceBetweenPointAndPoint, rotate, getElementById, distanceBetweenPointAndSegments, createMask, createRect, findElements, getSelectedElements, isPolylineHitRectangle, isSelectionMoving, PlaitPluginElementComponent, setClipboardData, getDataFromClipboard, depthFirstRecursion, getIsRecursionFunc, getHitElementByPoint } from '@plait/core';
|
|
2
|
+
import { getRectangleByPoints, Generator, normalizeShapePoints, isDndMode, isDrawingMode, getExtendPoint, getFactorByPoints, getDirectionByVector, getOppositeDirection, getDirectionFactor, DEFAULT_ROUTE_MARGIN, reduceRouteMargin, getNextPoint, generateElbowLineRoute, getPoints, removeDuplicatePoints, getPointByVector, getPointOnPolyline, getDirectionByPointOfRectangle, rotateVectorAnti90, TRANSPARENT, CommonPluginElement, ActiveGenerator, WithTextPluginKey, RESIZE_HANDLE_DIAMETER, PRIMARY_COLOR, isVirtualKey, isDelete, isSpaceHotkey, acceptImageTypes, getElementOfFocusedImage, buildImage, getRectangleResizeHandleRefs, ResizeHandle, withResize, isResizingByCondition, getRatioByPoint, ImageGenerator } from '@plait/common';
|
|
3
3
|
import { AlignEditor, Alignment, DEFAULT_FONT_SIZE, buildText, TextManage, getTextFromClipboard, getTextSize } from '@plait/text';
|
|
4
4
|
import { isKeyHotkey } from 'is-hotkey';
|
|
5
5
|
import { pointsOnBezierCurves } from 'points-on-curve';
|
|
@@ -1493,6 +1493,7 @@ const DefaultLineStyle = {
|
|
|
1493
1493
|
strokeWidth: 2,
|
|
1494
1494
|
strokeColor: '#000'
|
|
1495
1495
|
};
|
|
1496
|
+
const LINE_TEXT_SPACE = 4;
|
|
1496
1497
|
|
|
1497
1498
|
const createGeometryElement = (shape, points, text, options) => {
|
|
1498
1499
|
let textOptions = {};
|
|
@@ -1649,25 +1650,28 @@ const createDefaultFlowchart = (point) => {
|
|
|
1649
1650
|
return [startElement, processElement1, decisionElement, processElement2, endElement, line1, line2, line3, line4, line5];
|
|
1650
1651
|
};
|
|
1651
1652
|
|
|
1653
|
+
const MAX_LENGTH = 100;
|
|
1652
1654
|
const drawLineArrow = (element, points, options) => {
|
|
1653
1655
|
const arrowG = createG();
|
|
1654
1656
|
if (PlaitLine.isSourceMark(element, LineMarkerType.none) && PlaitLine.isTargetMark(element, LineMarkerType.none)) {
|
|
1655
1657
|
return null;
|
|
1656
1658
|
}
|
|
1659
|
+
const strokeWidth = getStrokeWidthByElement(element);
|
|
1660
|
+
const offset = (strokeWidth * strokeWidth) / 3;
|
|
1657
1661
|
if (!PlaitLine.isSourceMark(element, LineMarkerType.none)) {
|
|
1658
|
-
const source = getExtendPoint(points[0], points[1], 24);
|
|
1662
|
+
const source = getExtendPoint(points[0], points[1], 24 + offset);
|
|
1659
1663
|
const sourceArrow = getArrow(element, { marker: element.source.marker, source, target: points[0], isSource: true }, options);
|
|
1660
1664
|
sourceArrow && arrowG.appendChild(sourceArrow);
|
|
1661
1665
|
}
|
|
1662
1666
|
if (!PlaitLine.isTargetMark(element, LineMarkerType.none)) {
|
|
1663
|
-
const source = getExtendPoint(points[points.length - 1], points[points.length - 2], 24);
|
|
1667
|
+
const source = getExtendPoint(points[points.length - 1], points[points.length - 2], 24 + offset);
|
|
1664
1668
|
const arrow = getArrow(element, { marker: element.target.marker, source, target: points[points.length - 1], isSource: false }, options);
|
|
1665
1669
|
arrow && arrowG.appendChild(arrow);
|
|
1666
1670
|
}
|
|
1667
1671
|
return arrowG;
|
|
1668
1672
|
};
|
|
1669
1673
|
const getArrow = (element, arrowOptions, options) => {
|
|
1670
|
-
const { marker,
|
|
1674
|
+
const { marker, target, source, isSource } = arrowOptions;
|
|
1671
1675
|
let targetArrow;
|
|
1672
1676
|
switch (marker) {
|
|
1673
1677
|
case LineMarkerType.openTriangle: {
|
|
@@ -1707,10 +1711,10 @@ const getArrow = (element, arrowOptions, options) => {
|
|
|
1707
1711
|
};
|
|
1708
1712
|
const drawSharpArrow = (source, target, options) => {
|
|
1709
1713
|
const startPoint = target;
|
|
1710
|
-
const { pointLeft, pointRight } = arrowPoints(source, target,
|
|
1714
|
+
const { pointLeft, pointRight } = arrowPoints(source, target, 20);
|
|
1711
1715
|
const g = createG();
|
|
1712
1716
|
const path = createPath();
|
|
1713
|
-
let polylinePath = `M${pointRight[0]},${pointRight[1]}
|
|
1717
|
+
let polylinePath = `M${pointRight[0]},${pointRight[1]}A25,25,20,0,1,${pointLeft[0]},${pointLeft[1]}L${startPoint[0]},${startPoint[1]}Z`;
|
|
1714
1718
|
path.setAttribute('d', polylinePath);
|
|
1715
1719
|
path.setAttribute('stroke', `${options?.stroke}`);
|
|
1716
1720
|
path.setAttribute('stroke-width', `${options?.strokeWidth}`);
|
|
@@ -1722,8 +1726,11 @@ const drawArrow = (element, source, target, options) => {
|
|
|
1722
1726
|
const directionFactor = getFactorByPoints(source, target);
|
|
1723
1727
|
const strokeWidth = getStrokeWidthByElement(element);
|
|
1724
1728
|
const endPoint = [target[0] + (strokeWidth * directionFactor.x) / 2, target[1] + (strokeWidth * directionFactor.y) / 2];
|
|
1725
|
-
const middlePoint = [
|
|
1726
|
-
|
|
1729
|
+
const middlePoint = [
|
|
1730
|
+
endPoint[0] - (8 + strokeWidth / 2) * directionFactor.x,
|
|
1731
|
+
endPoint[1] - (8 + strokeWidth / 2) * directionFactor.y
|
|
1732
|
+
];
|
|
1733
|
+
const { pointLeft, pointRight } = arrowPoints(source, endPoint, 30);
|
|
1727
1734
|
const arrowG = drawLinearPath([pointLeft, endPoint, pointRight, middlePoint], { ...options, fill: options.stroke }, true);
|
|
1728
1735
|
const path = arrowG.querySelector('path');
|
|
1729
1736
|
path.setAttribute('stroke-linejoin', 'round');
|
|
@@ -1731,30 +1738,30 @@ const drawArrow = (element, source, target, options) => {
|
|
|
1731
1738
|
};
|
|
1732
1739
|
const drawSolidTriangle = (source, target, options) => {
|
|
1733
1740
|
const endPoint = target;
|
|
1734
|
-
const { pointLeft, pointRight } = arrowPoints(source, endPoint,
|
|
1741
|
+
const { pointLeft, pointRight } = arrowPoints(source, endPoint, 30);
|
|
1735
1742
|
return drawLinearPath([pointLeft, endPoint, pointRight], { ...options, fill: options.stroke }, true);
|
|
1736
1743
|
};
|
|
1737
1744
|
const drawOpenTriangle = (element, source, target, options) => {
|
|
1738
1745
|
const directionFactor = getFactorByPoints(source, target);
|
|
1739
1746
|
const strokeWidth = getStrokeWidthByElement(element);
|
|
1740
1747
|
const endPoint = [target[0] + (strokeWidth * directionFactor.x) / 2, target[1] + (strokeWidth * directionFactor.y) / 2];
|
|
1741
|
-
const { pointLeft, pointRight } = arrowPoints(source, endPoint,
|
|
1748
|
+
const { pointLeft, pointRight } = arrowPoints(source, endPoint, 40);
|
|
1742
1749
|
return drawLinearPath([pointLeft, endPoint, pointRight], options);
|
|
1743
1750
|
};
|
|
1744
1751
|
const drawOneSideArrow = (source, target, side, options) => {
|
|
1745
|
-
const { pointLeft, pointRight } = arrowPoints(source, target,
|
|
1752
|
+
const { pointLeft, pointRight } = arrowPoints(source, target, 40);
|
|
1746
1753
|
return drawLinearPath([side === 'up' ? pointRight : pointLeft, target], options);
|
|
1747
1754
|
};
|
|
1748
1755
|
const drawSingleSlash = (source, target, isSource, options) => {
|
|
1749
|
-
|
|
1750
|
-
const middlePoint = getExtendPoint(target, source,
|
|
1756
|
+
const length = distanceBetweenPointAndPoint(...source, ...target);
|
|
1757
|
+
const middlePoint = getExtendPoint(target, source, length / 2);
|
|
1751
1758
|
const angle = isSource ? 120 : 60;
|
|
1752
1759
|
const start = rotate(...source, ...middlePoint, (angle * Math.PI) / 180);
|
|
1753
1760
|
const end = rotate(...target, ...middlePoint, (angle * Math.PI) / 180);
|
|
1754
1761
|
return drawLinearPath([start, end], options);
|
|
1755
1762
|
};
|
|
1756
1763
|
const drawHollowTriangleArrow = (source, target, options) => {
|
|
1757
|
-
const { pointLeft, pointRight } = arrowPoints(source, target,
|
|
1764
|
+
const { pointLeft, pointRight } = arrowPoints(source, target, 30);
|
|
1758
1765
|
return drawLinearPath([pointLeft, pointRight, target], { ...options, fill: 'white' }, true);
|
|
1759
1766
|
};
|
|
1760
1767
|
|
|
@@ -1986,7 +1993,8 @@ function drawMask(board, element, id) {
|
|
|
1986
1993
|
mask.appendChild(maskFillRect);
|
|
1987
1994
|
const texts = element.texts;
|
|
1988
1995
|
texts.forEach((text, index) => {
|
|
1989
|
-
|
|
1996
|
+
let textRectangle = getLineTextRectangle(board, element, index);
|
|
1997
|
+
textRectangle = RectangleClient.inflate(textRectangle, LINE_TEXT_SPACE * 2);
|
|
1990
1998
|
const rect = createRect(textRectangle, {
|
|
1991
1999
|
fill: 'black'
|
|
1992
2000
|
});
|
|
@@ -1995,6 +2003,7 @@ function drawMask(board, element, id) {
|
|
|
1995
2003
|
//撑开 line
|
|
1996
2004
|
const maskTargetFillRect = createRect(rectangle);
|
|
1997
2005
|
maskTargetFillRect.setAttribute('opacity', '0');
|
|
2006
|
+
maskTargetFillRect.setAttribute('fill', 'none');
|
|
1998
2007
|
return { mask, maskTargetFillRect };
|
|
1999
2008
|
}
|
|
2000
2009
|
const getConnectionPoint = (geometry, connection, direction, delta) => {
|
|
@@ -2042,12 +2051,6 @@ const getBoardLines = (board) => {
|
|
|
2042
2051
|
recursion: (element) => PlaitDrawElement.isDrawElement(element)
|
|
2043
2052
|
});
|
|
2044
2053
|
};
|
|
2045
|
-
const getExtendPoint = (source, target, extendDistance) => {
|
|
2046
|
-
const distance = distanceBetweenPointAndPoint(...source, ...target);
|
|
2047
|
-
const sin = (target[1] - source[1]) / distance;
|
|
2048
|
-
const cos = (target[0] - source[0]) / distance;
|
|
2049
|
-
return [source[0] + extendDistance * cos, source[1] + extendDistance * sin];
|
|
2050
|
-
};
|
|
2051
2054
|
// quadratic Bezier to cubic Bezier
|
|
2052
2055
|
const Q2C = (points) => {
|
|
2053
2056
|
const result = [];
|
|
@@ -2107,11 +2110,18 @@ const getSelectedImageElements = (board) => {
|
|
|
2107
2110
|
return selectedElements;
|
|
2108
2111
|
};
|
|
2109
2112
|
|
|
2113
|
+
const isTextExceedingBounds = (geometry) => {
|
|
2114
|
+
const client = getRectangleByPoints(geometry.points);
|
|
2115
|
+
if (geometry.textHeight > client.height) {
|
|
2116
|
+
return true;
|
|
2117
|
+
}
|
|
2118
|
+
return false;
|
|
2119
|
+
};
|
|
2110
2120
|
const isRectangleHitDrawElement = (board, element, selection) => {
|
|
2121
|
+
const rangeRectangle = RectangleClient.toRectangleClient([selection.anchor, selection.focus]);
|
|
2111
2122
|
if (PlaitDrawElement.isGeometry(element)) {
|
|
2112
2123
|
const client = getRectangleByPoints(element.points);
|
|
2113
|
-
|
|
2114
|
-
if (element.textHeight > client.height) {
|
|
2124
|
+
if (isTextExceedingBounds(element)) {
|
|
2115
2125
|
const textClient = getTextRectangle(element);
|
|
2116
2126
|
return RectangleClient.isHit(rangeRectangle, client) || RectangleClient.isHit(rangeRectangle, textClient);
|
|
2117
2127
|
}
|
|
@@ -2119,7 +2129,6 @@ const isRectangleHitDrawElement = (board, element, selection) => {
|
|
|
2119
2129
|
}
|
|
2120
2130
|
if (PlaitDrawElement.isImage(element)) {
|
|
2121
2131
|
const client = getRectangleByPoints(element.points);
|
|
2122
|
-
const rangeRectangle = RectangleClient.toRectangleClient([selection.anchor, selection.focus]);
|
|
2123
2132
|
return RectangleClient.isHit(rangeRectangle, client);
|
|
2124
2133
|
}
|
|
2125
2134
|
if (PlaitDrawElement.isLine(element)) {
|
|
@@ -2127,7 +2136,6 @@ const isRectangleHitDrawElement = (board, element, selection) => {
|
|
|
2127
2136
|
const strokeWidth = getStrokeWidthByElement(element);
|
|
2128
2137
|
const isHitText = isHitLineText(board, element, selection.focus);
|
|
2129
2138
|
const isHit = isHitPolyLine(points, selection.focus, strokeWidth, 3) || isHitText;
|
|
2130
|
-
const rangeRectangle = RectangleClient.toRectangleClient([selection.anchor, selection.focus]);
|
|
2131
2139
|
const isContainPolyLinePoint = points.some(point => {
|
|
2132
2140
|
return RectangleClient.isHit(rangeRectangle, RectangleClient.toRectangleClient([point, point]));
|
|
2133
2141
|
});
|
|
@@ -2139,15 +2147,24 @@ const isRectangleHitDrawElement = (board, element, selection) => {
|
|
|
2139
2147
|
const isHitDrawElement = (board, element, point) => {
|
|
2140
2148
|
if (PlaitDrawElement.isGeometry(element)) {
|
|
2141
2149
|
const fill = getFillByElement(element);
|
|
2142
|
-
|
|
2150
|
+
// when shape equals text, fill is not allowed
|
|
2151
|
+
if (fill !== DefaultGeometryStyle.fill && fill !== TRANSPARENT && !PlaitDrawElement.isText(element)) {
|
|
2143
2152
|
return isRectangleHitDrawElement(board, element, { anchor: point, focus: point });
|
|
2144
2153
|
}
|
|
2145
2154
|
else {
|
|
2155
|
+
// if shape equals text, only check text rectangle
|
|
2156
|
+
if (PlaitDrawElement.isText(element)) {
|
|
2157
|
+
const textClient = getTextRectangle(element);
|
|
2158
|
+
let isHitText = RectangleClient.isPointInRectangle(textClient, point);
|
|
2159
|
+
return isHitText;
|
|
2160
|
+
}
|
|
2146
2161
|
const strokeWidth = getStrokeWidthByElement(element);
|
|
2147
2162
|
const engine = getEngine(getShape(element));
|
|
2148
2163
|
const corners = engine.getCornerPoints(getRectangleByPoints(element.points));
|
|
2149
2164
|
const isHit = isHitPolyLine(corners, point, strokeWidth, 3);
|
|
2150
|
-
|
|
2165
|
+
const textClient = getTextRectangle(element);
|
|
2166
|
+
let isHitText = RectangleClient.isPointInRectangle(textClient, point);
|
|
2167
|
+
return isHit || isHitText;
|
|
2151
2168
|
}
|
|
2152
2169
|
}
|
|
2153
2170
|
if (PlaitDrawElement.isImage(element) || PlaitDrawElement.isLine(element)) {
|
|
@@ -2910,24 +2927,31 @@ const withGeometryResize = (board) => {
|
|
|
2910
2927
|
let points = [...resizeRef.element.points];
|
|
2911
2928
|
const rectangle = getRectangleByPoints(resizeRef.element.points);
|
|
2912
2929
|
const ratio = rectangle.height / rectangle.width;
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
if (resizeRef.handle === ResizeHandle.ne) {
|
|
2917
|
-
points = [resizeState.endTransformPoint, [resizeRef.element.points[0][0], resizeRef.element.points[1][1]]];
|
|
2918
|
-
}
|
|
2919
|
-
if (resizeRef.handle === ResizeHandle.se) {
|
|
2920
|
-
points = [resizeState.endTransformPoint, resizeRef.element.points[0]];
|
|
2921
|
-
}
|
|
2922
|
-
if (resizeRef.handle === ResizeHandle.sw) {
|
|
2923
|
-
points = [resizeState.endTransformPoint, [resizeRef.element.points[1][0], resizeRef.element.points[0][1]]];
|
|
2924
|
-
}
|
|
2925
|
-
if (isShift || PlaitDrawElement.isImage(resizeRef.element)) {
|
|
2930
|
+
const isCornerHandle = [ResizeHandle.nw, ResizeHandle.ne, ResizeHandle.se, ResizeHandle.sw].includes(resizeRef.handle);
|
|
2931
|
+
points = getPointsByResizeHandle(resizeState.endTransformPoint, resizeRef.element.points, resizeRef.handle);
|
|
2932
|
+
if ((isShift || PlaitDrawElement.isImage(resizeRef.element)) && isCornerHandle) {
|
|
2926
2933
|
const rectangle = getRectangleByPoints(points);
|
|
2927
2934
|
const factor = points[0][1] > points[1][1] ? 1 : -1;
|
|
2928
2935
|
const height = rectangle.width * ratio * factor;
|
|
2929
2936
|
points = [[resizeState.endTransformPoint[0], points[1][1] + height], points[1]];
|
|
2930
2937
|
}
|
|
2938
|
+
if ((isShift || PlaitDrawElement.isImage(resizeRef.element)) && !isCornerHandle) {
|
|
2939
|
+
const rectangle = getRectangleByPoints(points);
|
|
2940
|
+
if (resizeRef.handle === ResizeHandle.n || resizeRef.handle === ResizeHandle.s) {
|
|
2941
|
+
const newWidth = rectangle.height / ratio;
|
|
2942
|
+
const offset = (newWidth - rectangle.width) / 2;
|
|
2943
|
+
const newRectangle = RectangleClient.expand(rectangle, offset, 0);
|
|
2944
|
+
const cornerPoints = RectangleClient.getCornerPoints(newRectangle);
|
|
2945
|
+
points = [cornerPoints[0], cornerPoints[2]];
|
|
2946
|
+
}
|
|
2947
|
+
if (resizeRef.handle === ResizeHandle.e || resizeRef.handle === ResizeHandle.w) {
|
|
2948
|
+
const newHeight = rectangle.width * ratio;
|
|
2949
|
+
const offset = (newHeight - rectangle.height) / 2;
|
|
2950
|
+
const newRectangle = RectangleClient.expand(rectangle, 0, offset);
|
|
2951
|
+
const cornerPoints = RectangleClient.getCornerPoints(newRectangle);
|
|
2952
|
+
points = [cornerPoints[0], cornerPoints[2]];
|
|
2953
|
+
}
|
|
2954
|
+
}
|
|
2931
2955
|
if (PlaitDrawElement.isGeometry(resizeRef.element)) {
|
|
2932
2956
|
const { height: textHeight } = PlaitGeometry.getTextManage(resizeRef.element).getSize();
|
|
2933
2957
|
DrawTransforms.resizeGeometry(board, points, textHeight, resizeRef.path);
|
|
@@ -2941,6 +2965,34 @@ const withGeometryResize = (board) => {
|
|
|
2941
2965
|
withResize(board, options);
|
|
2942
2966
|
return board;
|
|
2943
2967
|
};
|
|
2968
|
+
const getPointsByResizeHandle = (movingPoint, elementPoints, handle) => {
|
|
2969
|
+
switch (handle) {
|
|
2970
|
+
case ResizeHandle.nw: {
|
|
2971
|
+
return [movingPoint, elementPoints[1]];
|
|
2972
|
+
}
|
|
2973
|
+
case ResizeHandle.ne: {
|
|
2974
|
+
return [movingPoint, [elementPoints[0][0], elementPoints[1][1]]];
|
|
2975
|
+
}
|
|
2976
|
+
case ResizeHandle.se: {
|
|
2977
|
+
return [movingPoint, elementPoints[0]];
|
|
2978
|
+
}
|
|
2979
|
+
case ResizeHandle.sw: {
|
|
2980
|
+
return [movingPoint, [elementPoints[1][0], elementPoints[0][1]]];
|
|
2981
|
+
}
|
|
2982
|
+
case ResizeHandle.n: {
|
|
2983
|
+
return [[elementPoints[0][0], movingPoint[1]], elementPoints[1]];
|
|
2984
|
+
}
|
|
2985
|
+
case ResizeHandle.s: {
|
|
2986
|
+
return [elementPoints[0], [elementPoints[1][0], movingPoint[1]]];
|
|
2987
|
+
}
|
|
2988
|
+
case ResizeHandle.w: {
|
|
2989
|
+
return [[movingPoint[0], elementPoints[0][1]], elementPoints[1]];
|
|
2990
|
+
}
|
|
2991
|
+
default: {
|
|
2992
|
+
return [elementPoints[0], [movingPoint[0], elementPoints[1][1]]];
|
|
2993
|
+
}
|
|
2994
|
+
}
|
|
2995
|
+
};
|
|
2944
2996
|
|
|
2945
2997
|
var LineResizeHandle;
|
|
2946
2998
|
(function (LineResizeHandle) {
|
|
@@ -3011,17 +3063,23 @@ const withLineResize = (board) => {
|
|
|
3011
3063
|
let points = [...resizeRef.element.points];
|
|
3012
3064
|
let source = { ...resizeRef.element.source };
|
|
3013
3065
|
let target = { ...resizeRef.element.target };
|
|
3014
|
-
if (resizeRef.handle === LineResizeHandle.source) {
|
|
3015
|
-
|
|
3016
|
-
const hitElement = getHitOutlineGeometry(board, resizeState.endTransformPoint, -4);
|
|
3017
|
-
source.connection = hitElement ? transformPointToConnection(board, resizeState.endTransformPoint, hitElement) : undefined;
|
|
3018
|
-
source.boundId = hitElement ? hitElement.id : undefined;
|
|
3019
|
-
}
|
|
3020
|
-
else if (resizeRef.handle === LineResizeHandle.target) {
|
|
3066
|
+
if (resizeRef.handle === LineResizeHandle.source || resizeRef.handle === LineResizeHandle.target) {
|
|
3067
|
+
const object = resizeRef.handle === LineResizeHandle.source ? source : target;
|
|
3021
3068
|
points[pointIndex] = resizeState.endTransformPoint;
|
|
3022
3069
|
const hitElement = getHitOutlineGeometry(board, resizeState.endTransformPoint, -4);
|
|
3023
|
-
|
|
3024
|
-
|
|
3070
|
+
if (hitElement) {
|
|
3071
|
+
object.connection = transformPointToConnection(board, resizeState.endTransformPoint, hitElement);
|
|
3072
|
+
object.boundId = hitElement.id;
|
|
3073
|
+
}
|
|
3074
|
+
else {
|
|
3075
|
+
object.connection = undefined;
|
|
3076
|
+
object.boundId = undefined;
|
|
3077
|
+
if (points.length === 2) {
|
|
3078
|
+
let movingPoint = points[pointIndex];
|
|
3079
|
+
const otherPoint = points[Number(!pointIndex)];
|
|
3080
|
+
points[pointIndex] = alignPoints(otherPoint, movingPoint);
|
|
3081
|
+
}
|
|
3082
|
+
}
|
|
3025
3083
|
}
|
|
3026
3084
|
else if (resizeRef.handle === LineResizeHandle.addHandle) {
|
|
3027
3085
|
points.splice(pointIndex + 1, 0, resizeState.endTransformPoint);
|
|
@@ -3035,6 +3093,17 @@ const withLineResize = (board) => {
|
|
|
3035
3093
|
withResize(board, options);
|
|
3036
3094
|
return board;
|
|
3037
3095
|
};
|
|
3096
|
+
const alignPoints = (basePoint, movingPoint) => {
|
|
3097
|
+
const offset = 3;
|
|
3098
|
+
const newPoint = [...movingPoint];
|
|
3099
|
+
if (Point.isVerticalAlign(newPoint, basePoint, offset)) {
|
|
3100
|
+
newPoint[0] = basePoint[0];
|
|
3101
|
+
}
|
|
3102
|
+
if (Point.isHorizontalAlign(newPoint, basePoint, offset)) {
|
|
3103
|
+
newPoint[1] = basePoint[1];
|
|
3104
|
+
}
|
|
3105
|
+
return newPoint;
|
|
3106
|
+
};
|
|
3038
3107
|
|
|
3039
3108
|
const withLineBoundReaction = (board) => {
|
|
3040
3109
|
const { pointerMove, pointerUp } = board;
|
|
@@ -3266,5 +3335,5 @@ const withDraw = (board) => {
|
|
|
3266
3335
|
* Generated bundle index. Do not edit.
|
|
3267
3336
|
*/
|
|
3268
3337
|
|
|
3269
|
-
export { BasicShapes, DEFAULT_IMAGE_WIDTH, DefaultBasicShapeProperty, DefaultConnectorProperty, DefaultDataProperty, DefaultDecisionProperty, DefaultFlowchartProperty, DefaultFlowchartPropertyMap, DefaultGeometryActiveStyle, DefaultGeometryStyle, DefaultManualInputProperty, DefaultMergeProperty, DefaultTextProperty, DrawTransforms, FlowchartSymbols, GeometryComponent, GeometryThreshold, LineComponent, LineHandleKey, LineMarkerType, LineShape, PlaitDrawElement, PlaitGeometry, PlaitLine, Q2C, ShapeDefaultSpace, StrokeStyle, createDefaultFlowchart, createGeometryElement, createLineElement, drawBoundMask, drawGeometry, drawLine, getBasicPointers, getBoardLines, getCenterPointsOnPolygon, getConnectionPoint, getCurvePoints, getDefaultFlowchartProperty, getEdgeOnPolygonByPoint, getElbowPoints,
|
|
3338
|
+
export { BasicShapes, DEFAULT_IMAGE_WIDTH, DefaultBasicShapeProperty, DefaultConnectorProperty, DefaultDataProperty, DefaultDecisionProperty, DefaultFlowchartProperty, DefaultFlowchartPropertyMap, DefaultGeometryActiveStyle, DefaultGeometryStyle, DefaultManualInputProperty, DefaultMergeProperty, DefaultTextProperty, DrawTransforms, FlowchartSymbols, GeometryComponent, GeometryThreshold, LineComponent, LineHandleKey, LineMarkerType, LineShape, PlaitDrawElement, PlaitGeometry, PlaitLine, Q2C, ShapeDefaultSpace, StrokeStyle, createDefaultFlowchart, createGeometryElement, createLineElement, drawBoundMask, drawGeometry, drawLine, getBasicPointers, getBoardLines, getCenterPointsOnPolygon, getConnectionPoint, getCurvePoints, getDefaultFlowchartProperty, getEdgeOnPolygonByPoint, getElbowPoints, getFillByElement, getFlowchartPointers, getGeometryPointers, getHitConnectorPoint, getHitLineTextIndex, getLineDashByElement, getLineHandleRefPair, getLinePointers, getLinePoints, getLineTextRectangle, getNearestPoint, getPointsByCenterPoint, getSelectedDrawElements, getSelectedGeometryElements, getSelectedImageElements, getSelectedLineElements, getStrokeColorByElement, getStrokeStyleByElement, getStrokeWidthByElement, getTextRectangle, getVectorByConnection, isHitDrawElement, isHitLineText, isHitPolyLine, isRectangleHitDrawElement, isTextExceedingBounds, transformOpsToPoints, transformPointToConnection, withDraw };
|
|
3270
3339
|
//# sourceMappingURL=plait-draw.mjs.map
|