@plait/draw 0.74.0 → 0.75.0-next.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.
@@ -1,9 +1,9 @@
1
- import { ACTIVE_STROKE_WIDTH, DEFAULT_COLOR, ThemeColorMode, PlaitElement, RectangleClient, getSelectedElements, idCreator, catmullRomFitting, PlaitBoard, createG, drawLinearPath, setStrokeLinecap, distanceBetweenPointAndSegments, HIT_DISTANCE_BUFFER, isPointInPolygon, isPolylineHitRectangle, rotatePointsByAngle, rotateAntiPointsByElement, distanceBetweenPointAndPoint, Transforms, clearSelectedElement, addSelectedElement, BoardTransforms, PlaitPointerType, depthFirstRecursion, getIsRecursionFunc, SNAPPING_STROKE_WIDTH, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, drawCircle, createDebugGenerator, Point, arrowPoints, createPath, rotate, findElements, createMask, createRect, getElementById, rotatePointsByElement, PlaitNode, hasValidAngle, toViewBoxPoint, toHostPoint, Direction, rotatePoints, getRectangleByElements, getSelectionAngle, rotatedDataPoints, isAxisChangedByAngle, isSelectionMoving, drawRectangle, getRectangleByAngle, getSnapRectangles, getTripleAxis, getMinPointDelta, SNAP_TOLERANCE, drawPointSnapLines, drawSolidLines, getNearestPointBetweenPointAndSegments, isPointInEllipse, getNearestPointBetweenPointAndEllipse, getEllipseTangentSlope, getVectorFromPointAndSlope, drawRoundRectangle, isPointInRoundRectangle, setPathStrokeLinecap, getCrossingPointsBetweenEllipseAndSegment, drawLine, Path, RgbaToHEX, SELECTION_RECTANGLE_CLASS_NAME, getHitElementByPoint, WritableClipboardOperationType, WritableClipboardType, addOrCreateClipboardContext, setAngleForG, CursorClass, temporaryDisableSelection, PRESS_AND_MOVE_BUFFER, isMainPointer, throttleRAF, getAngleBetweenPoints, normalizeAngle, degreesToRadians, rotateElements, MERGING, ROTATE_HANDLE_CLASS_NAME, isSelectedElement, isDragging } from '@plait/core';
2
- import { DEFAULT_FILL, Alignment, WithTextPluginKey, TextManage, getMemorizedLatest, memorizeLatest, getPointOnPolyline, buildText, Generator, getStrokeLineDash, StrokeStyle, sortElementsByArea, isFilled, getTextEditorsByElement, removeDuplicatePoints, generateElbowLineRoute, simplifyOrthogonalPoints, getExtendPoint, getUnitVectorByPointAndPoint, getPointByVectorComponent, RESIZE_HANDLE_DIAMETER, measureElement, DEFAULT_FONT_FAMILY, getFirstTextManage, ActiveGenerator, isSourceAndTargetIntersect, getPoints, DEFAULT_ROUTE_MARGIN, normalizeShapePoints, getFirstTextEditor, resetPointsAfterResize, getDirectionByVector, getRectangleResizeHandleRefs, getRotatedResizeCursorClassByAngle, ROTATE_HANDLE_DISTANCE_TO_ELEMENT, ROTATE_HANDLE_SIZE, isCornerHandle, getIndexByResizeHandle, withResize, drawHandle, getSymmetricHandleIndex, getResizeHandlePointByIndex, getDirectionFactorByDirectionComponent, buildClipboardData as buildClipboardData$1, insertClipboardData as insertClipboardData$1, getCrossingPointsBetweenPointAndSegment, isPointOnSegment, getDirectionByPointOfRectangle, getDirectionFactor, rotateVector, getOppositeDirection, rotateVectorAnti90, getSourceAndTargetOuterRectangle, getNextPoint, PRIMARY_COLOR, CommonElementFlavour, canResize, drawPrimaryHandle, drawFillPrimaryHandle, isVirtualKey, isDelete, isSpaceHotkey, isDndMode, isDrawingMode, getElementsText, acceptImageTypes, getElementOfFocusedImage, buildImage, isResizingByCondition, getRatioByPoint, getTextManages, ImageGenerator, ResizeHandle, addRotating, removeRotating, drawRotateHandle } from '@plait/common';
1
+ import { ACTIVE_STROKE_WIDTH, DEFAULT_COLOR, ThemeColorMode, PlaitElement, RectangleClient, getSelectedElements, idCreator, catmullRomFitting, PlaitBoard, createG, drawLinearPath, setStrokeLinecap, distanceBetweenPointAndSegments, HIT_DISTANCE_BUFFER, isPointInPolygon, isLineHitRectangle, rotatePointsByAngle, rotateAntiPointsByElement, distanceBetweenPointAndPoint, Transforms, clearSelectedElement, addSelectedElement, BoardTransforms, PlaitPointerType, depthFirstRecursion, getIsRecursionFunc, SNAPPING_STROKE_WIDTH, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, drawCircle, createDebugGenerator, Point, arrowPoints, createPath, rotate, findElements, createMask, createRect, getElementById, rotatePointsByElement, PlaitNode, hasValidAngle, toViewBoxPoint, toHostPoint, Direction, rotatePoints, getRectangleByElements, getSelectionAngle, rotatedDataPoints, isAxisChangedByAngle, isSelectionMoving, drawRectangle, getRectangleByAngle, getSnapRectangles, getTripleAxis, getMinPointDelta, SNAP_TOLERANCE, drawPointSnapLines, drawSolidLines, getNearestPointBetweenPointAndSegments, isPointInEllipse, getNearestPointBetweenPointAndEllipse, getEllipseTangentSlope, getVectorFromPointAndSlope, drawRoundRectangle, isPointInRoundRectangle, setPathStrokeLinecap, getCrossingPointsBetweenEllipseAndSegment, drawLine, Path, RgbaToHEX, SELECTION_RECTANGLE_CLASS_NAME, getHitElementByPoint, WritableClipboardOperationType, WritableClipboardType, addOrCreateClipboardContext, setAngleForG, CursorClass, temporaryDisableSelection, PRESS_AND_MOVE_BUFFER, isMainPointer, throttleRAF, getAngleBetweenPoints, normalizeAngle, degreesToRadians, rotateElements, MERGING, ROTATE_HANDLE_CLASS_NAME, isSelectedElement, isDragging } from '@plait/core';
2
+ import { DEFAULT_FILL, Alignment, WithTextPluginKey, TextManage, getMemorizedLatest, memorizeLatest, getPointOnPolyline, buildText, Generator, getStrokeLineDash, StrokeStyle, getFirstTextEditor, sortElementsByArea, isFilled, getTextEditorsByElement, removeDuplicatePoints, generateElbowLineRoute, simplifyOrthogonalPoints, getExtendPoint, getUnitVectorByPointAndPoint, getPointByVectorComponent, RESIZE_HANDLE_DIAMETER, measureElement, DEFAULT_FONT_FAMILY, getFirstTextManage, ActiveGenerator, isSourceAndTargetIntersect, getPoints, DEFAULT_ROUTE_MARGIN, normalizeShapePoints, resetPointsAfterResize, getDirectionByVector, getRectangleResizeHandleRefs, getRotatedResizeCursorClassByAngle, ROTATE_HANDLE_DISTANCE_TO_ELEMENT, ROTATE_HANDLE_SIZE, isCornerHandle, getIndexByResizeHandle, withResize, drawHandle, getSymmetricHandleIndex, getResizeHandlePointByIndex, getDirectionFactorByDirectionComponent, buildClipboardData as buildClipboardData$1, insertClipboardData as insertClipboardData$1, getCrossingPointsBetweenPointAndSegment, isPointOnSegment, getDirectionByPointOfRectangle, getDirectionFactor, rotateVector, getOppositeDirection, rotateVectorAnti90, getSourceAndTargetOuterRectangle, getNextPoint, PRIMARY_COLOR, CommonElementFlavour, canResize, drawPrimaryHandle, drawFillPrimaryHandle, isVirtualKey, isDelete, isSpaceHotkey, isDndMode, isDrawingMode, getElementsText, acceptImageTypes, getElementOfFocusedImage, buildImage, isResizingByCondition, getRatioByPoint, getTextManages, ImageGenerator, ResizeHandle, addRotating, removeRotating, drawRotateHandle } from '@plait/common';
3
3
  import { pointsOnBezierCurves } from 'points-on-curve';
4
4
  import { TEXT_DEFAULT_HEIGHT, DEFAULT_FONT_SIZE, AlignEditor } from '@plait/text-plugins';
5
+ import { Editor, Node } from 'slate';
5
6
  import { isKeyHotkey } from 'is-hotkey';
6
- import { Node } from 'slate';
7
7
 
8
8
  var BasicShapes;
9
9
  (function (BasicShapes) {
@@ -1066,7 +1066,7 @@ const isRectangleHitElementText = (element, rectangle) => {
1066
1066
  const engine = getEngine(element.shape);
1067
1067
  if (isMultipleTextGeometry(element)) {
1068
1068
  const texts = element.texts;
1069
- return texts.some(item => {
1069
+ return texts.some((item) => {
1070
1070
  const textClient = engine.getTextRectangle(element, { id: item.id });
1071
1071
  return isRectangleHitRotatedPoints(rectangle, RectangleClient.getCornerPoints(textClient), element.angle);
1072
1072
  });
@@ -1080,7 +1080,7 @@ const isHitElementText = (element, point) => {
1080
1080
  const engine = getEngine(element.shape);
1081
1081
  if (isMultipleTextGeometry(element)) {
1082
1082
  const texts = element.texts;
1083
- return texts.some(item => {
1083
+ return texts.some((item) => {
1084
1084
  const textClient = engine.getTextRectangle(element, { id: item.id });
1085
1085
  return RectangleClient.isPointInRectangle(textClient, point);
1086
1086
  });
@@ -1090,6 +1090,13 @@ const isHitElementText = (element, point) => {
1090
1090
  return RectangleClient.isPointInRectangle(textClient, point);
1091
1091
  }
1092
1092
  };
1093
+ const isEmptyTextElement = (element) => {
1094
+ if (!isDrawElementIncludeText(element)) {
1095
+ return true;
1096
+ }
1097
+ const editor = getFirstTextEditor(element);
1098
+ return Editor.isEmpty(editor, editor.children[0]);
1099
+ };
1093
1100
  const isRectangleHitDrawElement = (board, element, selection) => {
1094
1101
  const rangeRectangle = RectangleClient.getRectangleByPoints([selection.anchor, selection.focus]);
1095
1102
  if (PlaitDrawElement.isGeometry(element)) {
@@ -1097,18 +1104,18 @@ const isRectangleHitDrawElement = (board, element, selection) => {
1097
1104
  if (isHitElement) {
1098
1105
  return isHitElement;
1099
1106
  }
1100
- return isRectangleHitElementText(element, rangeRectangle);
1107
+ return !isEmptyTextElement(element) && isRectangleHitElementText(element, rangeRectangle);
1101
1108
  }
1102
1109
  if (PlaitDrawElement.isImage(element)) {
1103
1110
  return isRectangleHitRotatedElement(board, rangeRectangle, element);
1104
1111
  }
1105
1112
  if (PlaitDrawElement.isArrowLine(element)) {
1106
1113
  const points = getArrowLinePoints(board, element);
1107
- return isPolylineHitRectangle(points, rangeRectangle);
1114
+ return isLineHitRectangle(points, rangeRectangle);
1108
1115
  }
1109
1116
  if (PlaitDrawElement.isVectorLine(element)) {
1110
1117
  const points = getVectorLinePoints(board, element);
1111
- return isPolylineHitRectangle(points, rangeRectangle, false);
1118
+ return isLineHitRectangle(points, rangeRectangle, false);
1112
1119
  }
1113
1120
  return null;
1114
1121
  };
@@ -1118,7 +1125,7 @@ const isRectangleHitRotatedElement = (board, rectangle, element) => {
1118
1125
  };
1119
1126
  const isRectangleHitRotatedPoints = (rectangle, points, angle) => {
1120
1127
  let rotatedPoints = rotatePointsByAngle(points, angle) || points;
1121
- return isPolylineHitRectangle(rotatedPoints, rectangle);
1128
+ return isLineHitRectangle(rotatedPoints, rectangle);
1122
1129
  };
1123
1130
  const getHitDrawElement = (board, elements) => {
1124
1131
  let firstFilledElement = getFirstFilledDrawElement(board, elements);
@@ -1138,7 +1145,7 @@ const getFirstFilledDrawElement = (board, elements) => {
1138
1145
  let filledElement = null;
1139
1146
  for (let i = 0; i < elements.length; i++) {
1140
1147
  const element = elements[i];
1141
- if (isCustomGeometryClosed(board, element) || isDrawElementClosed(element)) {
1148
+ if (isClosedCustomGeometry(board, element) || isClosedDrawElement(element)) {
1142
1149
  const fill = getFillByElement(board, element);
1143
1150
  if (isFilled(fill)) {
1144
1151
  filledElement = element;
@@ -1148,18 +1155,21 @@ const getFirstFilledDrawElement = (board, elements) => {
1148
1155
  }
1149
1156
  return filledElement;
1150
1157
  };
1158
+ const isFilledDrawElement = (board, element) => {
1159
+ return getFirstFilledDrawElement(board, [element]) !== null;
1160
+ };
1151
1161
  const getFirstTextOrLineElement = (elements) => {
1152
- const texts = elements.filter(item => PlaitDrawElement.isText(item));
1162
+ const texts = elements.filter((item) => PlaitDrawElement.isText(item));
1153
1163
  if (texts.length) {
1154
1164
  return texts[0];
1155
1165
  }
1156
- const lines = elements.filter(item => PlaitDrawElement.isArrowLine(item));
1166
+ const lines = elements.filter((item) => PlaitDrawElement.isArrowLine(item));
1157
1167
  if (lines.length) {
1158
1168
  return lines[0];
1159
1169
  }
1160
1170
  return null;
1161
1171
  };
1162
- const isHitDrawElement = (board, element, point) => {
1172
+ const isHitDrawElement = (board, element, point, isStrict = true) => {
1163
1173
  const rectangle = board.getRectangle(element);
1164
1174
  point = rotateAntiPointsByElement(point, element) || point;
1165
1175
  if (PlaitDrawElement.isGeometry(element)) {
@@ -1171,6 +1181,9 @@ const isHitDrawElement = (board, element, point) => {
1171
1181
  const textClient = getTextRectangle(element);
1172
1182
  return RectangleClient.isPointInRectangle(textClient, point);
1173
1183
  }
1184
+ if (!!isStrict && isEmptyTextElement(element) && !isFilledDrawElement(board, element)) {
1185
+ return false;
1186
+ }
1174
1187
  const isHitText = isHitElementText(element, point);
1175
1188
  return isHitText || engine.isInsidePoint(rectangle, point);
1176
1189
  }
@@ -1274,19 +1287,22 @@ const isDrawElementsIncludeText = (elements) => {
1274
1287
  return isDrawElementIncludeText(item);
1275
1288
  });
1276
1289
  };
1277
- const isDrawElementClosed = (element) => {
1278
- if (PlaitDrawElement.isText(element) || PlaitDrawElement.isArrowLine(element) || PlaitDrawElement.isImage(element)) {
1279
- return false;
1280
- }
1281
- if (PlaitDrawElement.isVectorLine(element)) {
1282
- return isClosedPoints(element.points);
1283
- }
1284
- if (PlaitDrawElement.isGeometry(element)) {
1285
- return isGeometryClosed(element);
1290
+ const isClosedDrawElement = (element) => {
1291
+ if (PlaitDrawElement.isDrawElement(element)) {
1292
+ if (PlaitDrawElement.isText(element) || PlaitDrawElement.isArrowLine(element) || PlaitDrawElement.isImage(element)) {
1293
+ return false;
1294
+ }
1295
+ if (PlaitDrawElement.isVectorLine(element)) {
1296
+ return isClosedPoints(element.points);
1297
+ }
1298
+ if (PlaitDrawElement.isGeometry(element)) {
1299
+ return isGeometryClosed(element);
1300
+ }
1301
+ return true;
1286
1302
  }
1287
- return true;
1303
+ return false;
1288
1304
  };
1289
- const isCustomGeometryClosed = (board, value) => {
1305
+ const isClosedCustomGeometry = (board, value) => {
1290
1306
  return PlaitDrawElement.isCustomGeometryElement(board, value) && isClosedPoints(value.points);
1291
1307
  };
1292
1308
  const getSnappingShape = (board, point) => {
@@ -1343,7 +1359,7 @@ const drawBoundReaction = (board, element, roughOptions = { hasMask: true, hasCo
1343
1359
  const maskG = drawShape(board, activeRectangle, shape, {
1344
1360
  stroke: SELECTION_BORDER_COLOR,
1345
1361
  strokeWidth: 0,
1346
- fill: isDrawElementClosed(element) ? SELECTION_FILL_COLOR : DefaultDrawStyle.fill,
1362
+ fill: isClosedDrawElement(element) ? SELECTION_FILL_COLOR : DefaultDrawStyle.fill,
1347
1363
  fillStyle: 'solid'
1348
1364
  }, drawOptions);
1349
1365
  g.appendChild(maskG);
@@ -1396,7 +1412,7 @@ const getStrokeColorByElement = (board, element) => {
1396
1412
  return strokeColor;
1397
1413
  };
1398
1414
  const getFillByElement = (board, element) => {
1399
- const defaultFill = PlaitDrawElement.isFlowchart(element) && isDrawElementClosed(element)
1415
+ const defaultFill = PlaitDrawElement.isFlowchart(element) && isClosedDrawElement(element)
1400
1416
  ? getFlowchartDefaultFill(board.theme.themeColorMode)
1401
1417
  : DefaultDrawStyle.fill;
1402
1418
  const fill = element.fill || defaultFill;
@@ -2245,7 +2261,7 @@ const getAutoCompletePoints = (element) => {
2245
2261
  return RectangleClient.getEdgeCenterPoints(rectangle);
2246
2262
  };
2247
2263
  const getHitIndexOfAutoCompletePoint = (movingPoint, points) => {
2248
- return points.findIndex(point => {
2264
+ return points.findIndex((point) => {
2249
2265
  const movingRectangle = RectangleClient.getRectangleByPoints([movingPoint]);
2250
2266
  let rectangle = RectangleClient.getRectangleByPoints([point]);
2251
2267
  rectangle = RectangleClient.inflate(rectangle, RESIZE_HANDLE_DIAMETER);
@@ -2317,14 +2333,8 @@ const createDefaultGeometry = (board, points, shape) => {
2317
2333
  const editText = (board, element, text) => {
2318
2334
  const textManage = text ? getTextManage(board, element, text) : getFirstTextManage(element);
2319
2335
  if (textManage) {
2320
- textManage.edit(() => {
2321
- // delay to avoid blinking
2322
- setTimeout(() => {
2323
- rerenderGeometryActive(board, element);
2324
- }, 200);
2325
- });
2336
+ textManage.edit(() => { });
2326
2337
  }
2327
- rerenderGeometryActive(board, element);
2328
2338
  };
2329
2339
  const rerenderGeometryActive = (board, element) => {
2330
2340
  const elementRef = PlaitElement.getElementRef(element);
@@ -2480,9 +2490,9 @@ const isSingleSelectSwimlane = (board) => {
2480
2490
  const selectedElements = getSelectedElements(board);
2481
2491
  return selectedElements && selectedElements.length === 1 && PlaitDrawElement.isSwimlane(selectedElements[0]);
2482
2492
  };
2483
- const isSingleSelectArrowLine = (board) => {
2493
+ const isSingleSelectLine = (board) => {
2484
2494
  const selectedElements = getSelectedElements(board);
2485
- return selectedElements && selectedElements.length === 1 && PlaitDrawElement.isArrowLine(selectedElements[0]);
2495
+ return selectedElements && selectedElements.length === 1 && PlaitDrawElement.isLine(selectedElements[0]);
2486
2496
  };
2487
2497
  const getSelectedSwimlane = (board) => {
2488
2498
  const selectedElements = getSelectedElements(board);
@@ -3138,7 +3148,7 @@ function withDrawResize(board) {
3138
3148
  const elements = getSelectedElements(board);
3139
3149
  return (elements.length >= 1 &&
3140
3150
  elements.every(el => (PlaitDrawElement.isDrawElement(el) || PlaitDrawElement.isCustomGeometryElement(board, el)) &&
3141
- !isSingleSelectArrowLine(board) &&
3151
+ !isSingleSelectLine(board) &&
3142
3152
  !isSingleSelectSwimlane(board)));
3143
3153
  };
3144
3154
  const options = {
@@ -6011,16 +6021,26 @@ const RequiredInterfaceEngine = {
6011
6021
  }
6012
6022
  };
6013
6023
 
6024
+ const percentage = 0.54;
6025
+ const getStartPoint = (rectangle) => {
6026
+ return [rectangle.x, rectangle.y + rectangle.height / 2];
6027
+ };
6028
+ const getEndPoint = (rectangle) => {
6029
+ return [rectangle.x + rectangle.width * percentage, rectangle.y + rectangle.height / 2];
6030
+ };
6031
+ const arcPercentage = percentage + (1 - percentage) / 2;
6032
+ const getArcCenter = (rectangle) => {
6033
+ return [rectangle.x + arcPercentage * rectangle.width, rectangle.y + rectangle.height / 2];
6034
+ };
6014
6035
  const ProvidedInterfaceEngine = {
6015
6036
  draw(board, rectangle, options) {
6016
6037
  const rs = PlaitBoard.getRoughSVG(board);
6017
- const shape = rs.path(` M${rectangle.x} ${rectangle.y + rectangle.height / 2}
6018
- H${rectangle.x + rectangle.width * 0.54}
6019
- A${(rectangle.width * 0.46) / 2} ${rectangle.height / 2}, 0, 1, 1 ${rectangle.x + rectangle.width} ${rectangle.y +
6020
- rectangle.height / 2}
6021
- A${(rectangle.width * 0.46) / 2} ${rectangle.height / 2}, 0, 1, 1 ${rectangle.x + rectangle.width * 0.54} ${rectangle.y +
6022
- rectangle.height / 2}
6023
- `, {
6038
+ const startPoint = getStartPoint(rectangle);
6039
+ const endPoint = getEndPoint(rectangle);
6040
+ const shape = rs.path(`M${startPoint[0]} ${startPoint[1]}
6041
+ H${endPoint[0]}
6042
+ A${(rectangle.width * (1 - percentage)) / 2} ${rectangle.height / 2}, 0, 1, 1 ${rectangle.x + rectangle.width} ${rectangle.y + rectangle.height / 2}
6043
+ A${(rectangle.width * (1 - percentage)) / 2} ${rectangle.height / 2}, 0, 1, 1 ${rectangle.x + rectangle.width * percentage} ${rectangle.y + rectangle.height / 2}`, {
6024
6044
  ...options,
6025
6045
  fillStyle: 'solid'
6026
6046
  });
@@ -6038,8 +6058,17 @@ const ProvidedInterfaceEngine = {
6038
6058
  return RectangleClient.getEdgeCenterPoints(rectangle);
6039
6059
  },
6040
6060
  getNearestPoint(rectangle, point) {
6041
- const nearestPoint = getNearestPointBetweenPointAndSegments(point, RectangleEngine.getCornerPoints(rectangle));
6042
- return nearestPoint;
6061
+ const startPoint = getStartPoint(rectangle);
6062
+ const endPoint = getEndPoint(rectangle);
6063
+ const nearestPointForLine = getNearestPointBetweenPointAndSegments(point, [startPoint, endPoint]);
6064
+ const distanceForLine = distanceBetweenPointAndPoint(...point, ...nearestPointForLine);
6065
+ const arcCenter = getArcCenter(rectangle);
6066
+ const nearestPointForEllipse = getNearestPointBetweenPointAndEllipse(point, arcCenter, (rectangle.width * (1 - percentage)) / 2, rectangle.height / 2);
6067
+ const distanceForEllipse = distanceBetweenPointAndPoint(...point, ...nearestPointForEllipse);
6068
+ if (distanceForLine < distanceForEllipse) {
6069
+ return nearestPointForLine;
6070
+ }
6071
+ return nearestPointForEllipse;
6043
6072
  },
6044
6073
  getTangentVectorByConnectionPoint(rectangle, pointOfRectangle) {
6045
6074
  const connectionPoint = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
@@ -7153,11 +7182,11 @@ const withDrawHotkey = (board) => {
7153
7182
  event.preventDefault();
7154
7183
  if (!PlaitBoard.isReadonly(board)) {
7155
7184
  const point = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
7156
- const hitElement = getHitElementByPoint(board, point);
7157
- if (hitElement && PlaitDrawElement.isGeometry(hitElement)) {
7185
+ const hitElement = getHitElementByPoint(board, point, undefined, false);
7186
+ if (hitElement && PlaitDrawElement.isGeometry(hitElement) && isDrawElementIncludeText(hitElement)) {
7158
7187
  if (isMultipleTextGeometry(hitElement)) {
7159
7188
  const hitText = getHitMultipleGeometryText(hitElement, point) ||
7160
- hitElement.texts.find(item => item.id.includes(GeometryCommonTextKeys.content)) ||
7189
+ hitElement.texts.find((item) => item.id.includes(GeometryCommonTextKeys.content)) ||
7161
7190
  hitElement.texts[0];
7162
7191
  editText(board, hitElement, hitText);
7163
7192
  }
@@ -8353,12 +8382,12 @@ const withTable = (board) => {
8353
8382
  }
8354
8383
  return drawElement(context);
8355
8384
  };
8356
- tableBoard.isHit = (element, point) => {
8385
+ tableBoard.isHit = (element, point, isStrict) => {
8357
8386
  if (PlaitDrawElement.isElementByTable(element)) {
8358
8387
  const client = RectangleClient.getRectangleByPoints(element.points);
8359
8388
  return RectangleClient.isPointInRectangle(client, point);
8360
8389
  }
8361
- return isHit(element, point);
8390
+ return isHit(element, point, isStrict);
8362
8391
  };
8363
8392
  tableBoard.getRectangle = (element) => {
8364
8393
  if (PlaitDrawElement.isElementByTable(element)) {
@@ -8375,7 +8404,7 @@ const withTable = (board) => {
8375
8404
  tableBoard.isRectangleHit = (element, selection) => {
8376
8405
  if (PlaitDrawElement.isElementByTable(element)) {
8377
8406
  const rangeRectangle = RectangleClient.getRectangleByPoints([selection.anchor, selection.focus]);
8378
- return isPolylineHitRectangle(element.points, rangeRectangle);
8407
+ return isLineHitRectangle(element.points, rangeRectangle);
8379
8408
  }
8380
8409
  return isRectangleHit(element, selection);
8381
8410
  };
@@ -8583,58 +8612,32 @@ const withVectorLineCreateByDraw = (board) => {
8583
8612
  const { pointerDown, pointerMove, dblClick, globalKeyDown } = board;
8584
8613
  let lineShapeG = null;
8585
8614
  let temporaryElement = null;
8586
- let vectorLineRef;
8615
+ let drawPoints = [];
8587
8616
  const vectorLineComplete = () => {
8588
- if (vectorLineRef) {
8589
- clearSelectedElement(board);
8590
- if (vectorLineRef?.element) {
8591
- addSelectedElement(board, vectorLineRef?.element);
8592
- }
8617
+ if (temporaryElement) {
8618
+ Transforms.insertNode(board, temporaryElement, [board.children.length]);
8593
8619
  }
8594
8620
  PlaitBoard.getBoardContainer(board).classList.remove(`vector-line-closed`);
8595
8621
  lineShapeG?.remove();
8596
8622
  lineShapeG = null;
8597
- vectorLineRef = null;
8598
8623
  temporaryElement = null;
8624
+ drawPoints = [];
8599
8625
  };
8600
8626
  board.pointerDown = (event) => {
8601
8627
  const penPointers = getVectorLinePointers();
8602
8628
  const isVectorLinePointer = PlaitBoard.isInPointer(board, penPointers);
8603
- if (isVectorLinePointer && !vectorLineRef) {
8604
- vectorLineRef = { shape: VectorLineShape.straight };
8605
- }
8606
- if (!PlaitBoard.isReadonly(board) && vectorLineRef && isDrawingMode(board)) {
8629
+ if (!PlaitBoard.isReadonly(board) && isVectorLinePointer && isDrawingMode(board)) {
8607
8630
  let point = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
8608
- if (!temporaryElement) {
8609
- vectorLineRef = {
8610
- ...vectorLineRef,
8611
- start: point
8612
- };
8613
- }
8614
- else {
8615
- if (!vectorLineRef.element) {
8616
- vectorLineRef.element = temporaryElement;
8617
- Transforms.insertNode(board, vectorLineRef.element, [board.children.length]);
8618
- }
8619
- else {
8620
- let points = vectorLineRef.element.points;
8621
- const isClosed = distanceBetweenPointAndPoint(...point, ...vectorLineRef.start) <= LINE_HIT_GEOMETRY_BUFFER;
8622
- if (isClosed) {
8623
- point = vectorLineRef.start;
8624
- }
8625
- if (vectorLineRef.path) {
8626
- const lastPoint = points[points.length - 1];
8627
- const distance = distanceBetweenPointAndPoint(...point, ...lastPoint);
8628
- if (distance > 2) {
8629
- Transforms.setNode(board, { points: [...points, point] }, vectorLineRef.path);
8630
- }
8631
- }
8632
- vectorLineRef.element = getElementById(board, vectorLineRef.element.id);
8633
- if (isClosed) {
8634
- vectorLineComplete();
8635
- }
8631
+ if (drawPoints.length > 1) {
8632
+ const isClosed = distanceBetweenPointAndPoint(...point, ...drawPoints[0]) <= LINE_HIT_GEOMETRY_BUFFER;
8633
+ if (isClosed) {
8634
+ drawPoints.push(drawPoints[0]);
8635
+ vectorLineComplete();
8636
+ return;
8636
8637
  }
8637
8638
  }
8639
+ drawPoints.push(point);
8640
+ return;
8638
8641
  }
8639
8642
  pointerDown(event);
8640
8643
  };
@@ -8643,36 +8646,28 @@ const withVectorLineCreateByDraw = (board) => {
8643
8646
  lineShapeG = createG();
8644
8647
  let movingPoint = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
8645
8648
  const pointer = PlaitBoard.getPointer(board);
8646
- if (pointer !== VectorLinePointerType.vectorLine) {
8647
- vectorLineComplete();
8648
- }
8649
- if (vectorLineRef && vectorLineRef.start) {
8650
- let drawPoints = [vectorLineRef.start];
8651
- if (vectorLineRef.element) {
8652
- drawPoints = [vectorLineRef.start, ...vectorLineRef.element.points];
8653
- const path = PlaitBoard.findPath(board, vectorLineRef.element);
8654
- vectorLineRef.path = path;
8655
- }
8656
- const distance = distanceBetweenPointAndPoint(...movingPoint, ...vectorLineRef.start);
8657
- if (distance <= LINE_HIT_GEOMETRY_BUFFER) {
8658
- movingPoint = vectorLineRef.start;
8659
- PlaitBoard.getBoardContainer(board).classList.add(`vector-line-closed`);
8660
- }
8661
- else {
8662
- PlaitBoard.getBoardContainer(board).classList.remove(`vector-line-closed`);
8649
+ if (pointer === VectorLinePointerType.vectorLine) {
8650
+ if (drawPoints.length > 0) {
8651
+ const distance = distanceBetweenPointAndPoint(...movingPoint, ...drawPoints[0]);
8652
+ if (distance <= LINE_HIT_GEOMETRY_BUFFER) {
8653
+ movingPoint = drawPoints[0];
8654
+ PlaitBoard.getBoardContainer(board).classList.add(`vector-line-closed`);
8655
+ }
8656
+ else {
8657
+ PlaitBoard.getBoardContainer(board).classList.remove(`vector-line-closed`);
8658
+ }
8659
+ temporaryElement = vectorLineCreating(board, VectorLineShape.straight, drawPoints, movingPoint, lineShapeG);
8663
8660
  }
8664
- temporaryElement = vectorLineCreating(board, vectorLineRef.shape, drawPoints, movingPoint, lineShapeG);
8665
8661
  }
8666
8662
  pointerMove(event);
8667
8663
  };
8668
8664
  board.dblClick = (event) => {
8665
+ console.log('l`ll be here');
8669
8666
  if (!PlaitBoard.isReadonly(board)) {
8670
- if (vectorLineRef) {
8671
- if (vectorLineRef.path) {
8672
- Transforms.setNode(board, { points: vectorLineRef?.element?.points }, vectorLineRef.path);
8673
- }
8667
+ if (temporaryElement) {
8674
8668
  vectorLineComplete();
8675
8669
  BoardTransforms.updatePointerType(board, PlaitPointerType.selection);
8670
+ return;
8676
8671
  }
8677
8672
  }
8678
8673
  dblClick(event);
@@ -8681,10 +8676,7 @@ const withVectorLineCreateByDraw = (board) => {
8681
8676
  if (!PlaitBoard.isReadonly(board)) {
8682
8677
  const isEsc = isKeyHotkey('esc', event);
8683
8678
  const isV = isKeyHotkey('v', event);
8684
- if ((isEsc || isV) && vectorLineRef) {
8685
- if (vectorLineRef.path) {
8686
- Transforms.setNode(board, { points: vectorLineRef.element?.points }, vectorLineRef.path);
8687
- }
8679
+ if ((isEsc || isV) && temporaryElement) {
8688
8680
  vectorLineComplete();
8689
8681
  if (isV) {
8690
8682
  BoardTransforms.updatePointerType(board, PlaitPointerType.selection);
@@ -8801,12 +8793,12 @@ const withDraw = (board) => {
8801
8793
  }
8802
8794
  return isRectangleHit(element, selection);
8803
8795
  };
8804
- board.isHit = (element, point) => {
8805
- const result = isHitDrawElement(board, element, point);
8796
+ board.isHit = (element, point, isStrict) => {
8797
+ const result = isHitDrawElement(board, element, point, isStrict);
8806
8798
  if (result !== null) {
8807
8799
  return result;
8808
8800
  }
8809
- return isHit(element, point);
8801
+ return isHit(element, point, isStrict);
8810
8802
  };
8811
8803
  board.getOneHitElement = elements => {
8812
8804
  const isAllDrawElements = elements.every(item => PlaitDrawElement.isDrawElement(item));
@@ -8874,5 +8866,5 @@ const withDraw = (board) => {
8874
8866
  * Generated bundle index. Do not edit.
8875
8867
  */
8876
8868
 
8877
- export { ArrowLineAutoCompleteGenerator, ArrowLineComponent, ArrowLineHandleKey, ArrowLineMarkerType, ArrowLineShape, BasicShapes, DEFAULT_IMAGE_WIDTH, DefaultActivationProperty, DefaultActorProperty, DefaultArrowProperty, DefaultAssemblyProperty, DefaultBasicShapeProperty, DefaultBasicShapePropertyMap, DefaultClassProperty, DefaultCloudProperty, DefaultCombinedFragmentProperty, DefaultComponentBoxProperty, DefaultConnectorProperty, DefaultContainerProperty, DefaultDataBaseProperty, DefaultDataProperty, DefaultDecisionProperty, DefaultDeletionProperty, DefaultDocumentProperty, DefaultDrawActiveStyle, DefaultDrawStyle, DefaultFlowchartProperty, DefaultFlowchartPropertyMap, DefaultInterfaceProperty, DefaultInternalStorageProperty, DefaultManualInputProperty, DefaultMergeProperty, DefaultMultiDocumentProperty, DefaultNoteProperty, DefaultObjectProperty, DefaultPackageProperty, DefaultPentagonArrowProperty, DefaultPortProperty, DefaultProvidedInterfaceProperty, DefaultRequiredInterfaceProperty, DefaultSwimlaneHorizontalProperty, DefaultSwimlaneHorizontalWithHeaderProperty, DefaultSwimlanePropertyMap, DefaultSwimlaneVerticalProperty, DefaultSwimlaneVerticalWithHeaderProperty, DefaultTextProperty, DefaultTwoWayArrowProperty, DefaultUMLPropertyMap, DrawThemeColors, DrawTransforms, FlowchartSymbols, GEOMETRY_NOT_CLOSED, GEOMETRY_WITHOUT_TEXT, GEOMETRY_WITH_MULTIPLE_TEXT, GeometryCommonTextKeys, GeometryComponent, GeometryShapeGenerator, GeometryThreshold, KEY_TO_TEXT_MANAGE, LINE_HIT_GEOMETRY_BUFFER, LINE_SNAPPING_BUFFER, LINE_SNAPPING_CONNECTOR_BUFFER, LineActiveGenerator, MIN_TEXT_WIDTH, MemorizeKey, MultipleTextGeometryTextKeys, PlaitArrowLine, PlaitDrawElement, PlaitGeometry, PlaitTableElement, Q2C, SELECTED_CELLS, SWIMLANE_HEADER_SIZE, ShapeDefaultSpace, SingleTextGenerator, SwimlaneDrawSymbols, SwimlaneSymbols, TableGenerator, TableSymbols, TextGenerator, UMLSymbols, VectorLineComponent, VectorLinePointerType, VectorLineShape, WithArrowLineAutoCompletePluginKey, WithDrawPluginKey, adjustSwimlaneShape, alignElbowSegment, alignPoints, buildClipboardData, buildDefaultTextsByShape, buildSwimlaneTable, clearSelectedCells, collectArrowLineUpdatedRefsByGeometry, createArrowLineElement, createCell, createDefaultCells, createDefaultFlowchart, createDefaultGeometry, createDefaultRowsOrColumns, createDefaultSwimlane, createGeometryElement, createGeometryElementWithText, createGeometryElementWithoutText, createMultipleTextGeometryElement, createTextElement, createUMLClassOrInterfaceGeometryElement, createVectorLineElement, debugGenerator$1 as debugGenerator, deleteTextManage, drawArrowLine, drawArrowLineArrow, drawBoundReaction, drawGeometry, drawShape, drawVectorLine, editCell, editText, getArrowLineHandleRefPair, getArrowLinePointers, getArrowLinePoints, getArrowLineTextRectangle, getArrowLines, getAutoCompletePoints, getBasicPointers, getCellWithPoints, getCellsRectangle, getCellsWithPoints, getCenterPointsOnPolygon$1 as getCenterPointsOnPolygon, getConnectionPoint, getCurvePoints, getDefaultBasicShapeProperty, getDefaultFlowchartProperty, getDefaultGeometryPoints, getDefaultGeometryProperty, getDefaultSwimlanePoints, getDefaultTextPoints, getDefaultUMLProperty, getDrawDefaultStrokeColor, getElbowLineRouteOptions, getElbowPoints, getFillByElement, getFirstFilledDrawElement, getFirstTextOrLineElement, getFlowchartDefaultFill, getFlowchartPointers, getGeometryAlign, getGeometryPointers, getHitCell, getHitConnection, getHitConnectorPoint, getHitDrawElement, getHitIndexOfAutoCompletePoint, getHitMultipleGeometryText, getHitShape, getIndexAndDeleteCountByKeyPoint, getLineMemorizedLatest, getMemorizeKey, getMemorizedLatestByPointer, getMemorizedLatestShape, getMidKeyPoints, getMiddlePoints, getMirrorDataPoints, getMultipleTextGeometryTextKeys, getNearestPoint, getNextRenderPoints, getNextSourceAndTargetPoints, getResizedPreviousAndNextPoint, getSelectedArrowLineElements, getSelectedCells, getSelectedCustomGeometryElements, getSelectedDrawElements, getSelectedGeometryElements, getSelectedImageElements, getSelectedSwimlane, getSelectedTableCellsEditor, getSelectedTableElements, getSelectedVectorLineElements, getSnapResizingRef, getSnapResizingRefOptions, getSnappingRef, getSnappingShape, getSourceAndTargetRectangle, getStrokeColorByElement, getStrokeStyleByElement, getStrokeWidthByElement, getSwimlaneCount, getSwimlanePointers, getTextKey, getTextManage, getTextManageByCell, getTextRectangle, getTextShapeProperty, getUMLPointers, getVectorByConnection, getVectorLinePointers, getVectorLinePoints, handleArrowLineCreating, hasIllegalElbowPoint, insertClipboardData, insertElement, isCellIncludeText, isClosedPoints, isCustomGeometryClosed, isDrawElementClosed, isDrawElementIncludeText, isDrawElementsIncludeText, isGeometryClosed, isGeometryIncludeText, isHitArrowLine, isHitArrowLineText, isHitDrawElement, isHitEdgeOfShape, isHitElementInside, isHitElementText, isHitPolyLine, isHitVectorLine, isInsideOfShape, isMultipleTextGeometry, isMultipleTextShape, isRectangleHitDrawElement, isRectangleHitElementText, isRectangleHitRotatedElement, isRectangleHitRotatedPoints, isSelfLoop, isSingleSelectArrowLine, isSingleSelectElementByTable, isSingleSelectSwimlane, isSingleSelectTable, isSingleTextGeometry, isSingleTextShape, isSwimlanePointers, isSwimlaneWithHeader, isTextExceedingBounds, isUpdatedHandleIndex, isUseDefaultOrthogonalRoute, memorizeLatestShape, memorizeLatestText, rerenderGeometryActive, setSelectedCells, setTextManage, traverseDrawShapes, updateCellIds, updateCellIdsByRowOrColumn, updateColumns, updateRowOrColumnIds, updateRows, vectorLineCreating, withArrowLineAutoComplete, withDraw };
8869
+ export { ArrowLineAutoCompleteGenerator, ArrowLineComponent, ArrowLineHandleKey, ArrowLineMarkerType, ArrowLineShape, BasicShapes, DEFAULT_IMAGE_WIDTH, DefaultActivationProperty, DefaultActorProperty, DefaultArrowProperty, DefaultAssemblyProperty, DefaultBasicShapeProperty, DefaultBasicShapePropertyMap, DefaultClassProperty, DefaultCloudProperty, DefaultCombinedFragmentProperty, DefaultComponentBoxProperty, DefaultConnectorProperty, DefaultContainerProperty, DefaultDataBaseProperty, DefaultDataProperty, DefaultDecisionProperty, DefaultDeletionProperty, DefaultDocumentProperty, DefaultDrawActiveStyle, DefaultDrawStyle, DefaultFlowchartProperty, DefaultFlowchartPropertyMap, DefaultInterfaceProperty, DefaultInternalStorageProperty, DefaultManualInputProperty, DefaultMergeProperty, DefaultMultiDocumentProperty, DefaultNoteProperty, DefaultObjectProperty, DefaultPackageProperty, DefaultPentagonArrowProperty, DefaultPortProperty, DefaultProvidedInterfaceProperty, DefaultRequiredInterfaceProperty, DefaultSwimlaneHorizontalProperty, DefaultSwimlaneHorizontalWithHeaderProperty, DefaultSwimlanePropertyMap, DefaultSwimlaneVerticalProperty, DefaultSwimlaneVerticalWithHeaderProperty, DefaultTextProperty, DefaultTwoWayArrowProperty, DefaultUMLPropertyMap, DrawThemeColors, DrawTransforms, FlowchartSymbols, GEOMETRY_NOT_CLOSED, GEOMETRY_WITHOUT_TEXT, GEOMETRY_WITH_MULTIPLE_TEXT, GeometryCommonTextKeys, GeometryComponent, GeometryShapeGenerator, GeometryThreshold, KEY_TO_TEXT_MANAGE, LINE_HIT_GEOMETRY_BUFFER, LINE_SNAPPING_BUFFER, LINE_SNAPPING_CONNECTOR_BUFFER, LineActiveGenerator, MIN_TEXT_WIDTH, MemorizeKey, MultipleTextGeometryTextKeys, PlaitArrowLine, PlaitDrawElement, PlaitGeometry, PlaitTableElement, Q2C, SELECTED_CELLS, SWIMLANE_HEADER_SIZE, ShapeDefaultSpace, SingleTextGenerator, SwimlaneDrawSymbols, SwimlaneSymbols, TableGenerator, TableSymbols, TextGenerator, UMLSymbols, VectorLineComponent, VectorLinePointerType, VectorLineShape, WithArrowLineAutoCompletePluginKey, WithDrawPluginKey, adjustSwimlaneShape, alignElbowSegment, alignPoints, buildClipboardData, buildDefaultTextsByShape, buildSwimlaneTable, clearSelectedCells, collectArrowLineUpdatedRefsByGeometry, createArrowLineElement, createCell, createDefaultCells, createDefaultFlowchart, createDefaultGeometry, createDefaultRowsOrColumns, createDefaultSwimlane, createGeometryElement, createGeometryElementWithText, createGeometryElementWithoutText, createMultipleTextGeometryElement, createTextElement, createUMLClassOrInterfaceGeometryElement, createVectorLineElement, debugGenerator$1 as debugGenerator, deleteTextManage, drawArrowLine, drawArrowLineArrow, drawBoundReaction, drawGeometry, drawShape, drawVectorLine, editCell, editText, getArrowLineHandleRefPair, getArrowLinePointers, getArrowLinePoints, getArrowLineTextRectangle, getArrowLines, getAutoCompletePoints, getBasicPointers, getCellWithPoints, getCellsRectangle, getCellsWithPoints, getCenterPointsOnPolygon$1 as getCenterPointsOnPolygon, getConnectionPoint, getCurvePoints, getDefaultBasicShapeProperty, getDefaultFlowchartProperty, getDefaultGeometryPoints, getDefaultGeometryProperty, getDefaultSwimlanePoints, getDefaultTextPoints, getDefaultUMLProperty, getDrawDefaultStrokeColor, getElbowLineRouteOptions, getElbowPoints, getFillByElement, getFirstFilledDrawElement, getFirstTextOrLineElement, getFlowchartDefaultFill, getFlowchartPointers, getGeometryAlign, getGeometryPointers, getHitCell, getHitConnection, getHitConnectorPoint, getHitDrawElement, getHitIndexOfAutoCompletePoint, getHitMultipleGeometryText, getHitShape, getIndexAndDeleteCountByKeyPoint, getLineMemorizedLatest, getMemorizeKey, getMemorizedLatestByPointer, getMemorizedLatestShape, getMidKeyPoints, getMiddlePoints, getMirrorDataPoints, getMultipleTextGeometryTextKeys, getNearestPoint, getNextRenderPoints, getNextSourceAndTargetPoints, getResizedPreviousAndNextPoint, getSelectedArrowLineElements, getSelectedCells, getSelectedCustomGeometryElements, getSelectedDrawElements, getSelectedGeometryElements, getSelectedImageElements, getSelectedSwimlane, getSelectedTableCellsEditor, getSelectedTableElements, getSelectedVectorLineElements, getSnapResizingRef, getSnapResizingRefOptions, getSnappingRef, getSnappingShape, getSourceAndTargetRectangle, getStrokeColorByElement, getStrokeStyleByElement, getStrokeWidthByElement, getSwimlaneCount, getSwimlanePointers, getTextKey, getTextManage, getTextManageByCell, getTextRectangle, getTextShapeProperty, getUMLPointers, getVectorByConnection, getVectorLinePointers, getVectorLinePoints, handleArrowLineCreating, hasIllegalElbowPoint, insertClipboardData, insertElement, isCellIncludeText, isClosedCustomGeometry, isClosedDrawElement, isClosedPoints, isDrawElementIncludeText, isDrawElementsIncludeText, isEmptyTextElement, isFilledDrawElement, isGeometryClosed, isGeometryIncludeText, isHitArrowLine, isHitArrowLineText, isHitDrawElement, isHitEdgeOfShape, isHitElementInside, isHitElementText, isHitPolyLine, isHitVectorLine, isInsideOfShape, isMultipleTextGeometry, isMultipleTextShape, isRectangleHitDrawElement, isRectangleHitElementText, isRectangleHitRotatedElement, isRectangleHitRotatedPoints, isSelfLoop, isSingleSelectElementByTable, isSingleSelectLine, isSingleSelectSwimlane, isSingleSelectTable, isSingleTextGeometry, isSingleTextShape, isSwimlanePointers, isSwimlaneWithHeader, isTextExceedingBounds, isUpdatedHandleIndex, isUseDefaultOrthogonalRoute, memorizeLatestShape, memorizeLatestText, rerenderGeometryActive, setSelectedCells, setTextManage, traverseDrawShapes, updateCellIds, updateCellIdsByRowOrColumn, updateColumns, updateRowOrColumnIds, updateRows, vectorLineCreating, withArrowLineAutoComplete, withDraw };
8878
8870
  //# sourceMappingURL=plait-draw.mjs.map