@plait/common 0.45.0 → 0.48.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,4 +1,4 @@
1
- import { createG, RectangleClient, drawRectangle, drawCircle, PlaitBoard, createForeignObject, updateForeignObject, ResizeCursorClass, setDragging, Direction, distanceBetweenPointAndPoint, Point, hotkeys, PlaitElement, PlaitContextService, downScale, getSelectedElements, Transforms, PlaitPointerType, isMainPointer, transformPoint, toPoint, preventTouchMove, PRESS_AND_MOVE_BUFFER, MERGING, throttleRAF, handleTouchTarget, PlaitPluginElementComponent, isSelectionMoving, ACTIVE_STROKE_WIDTH } from '@plait/core';
1
+ import { createG, RectangleClient, drawRectangle, drawCircle, PlaitBoard, createForeignObject, updateForeignObject, ResizeCursorClass, setDragging, Direction, distanceBetweenPointAndPoint, Point, hotkeys, PlaitElement, PlaitContextService, downScale, getSelectedElements, Transforms, getRectangleByElements, MERGING, PlaitPointerType, isMainPointer, transformPoint, toPoint, preventTouchMove, PRESS_AND_MOVE_BUFFER, throttleRAF, handleTouchTarget, PlaitPluginElementComponent, isSelectionMoving, ACTIVE_STROKE_WIDTH } from '@plait/core';
2
2
  import { isKeyHotkey } from 'is-hotkey';
3
3
  import { PlaitMarkEditor } from '@plait/text';
4
4
  import * as i0 from '@angular/core';
@@ -44,7 +44,12 @@ class Generator {
44
44
  this.g.replaceWith(g);
45
45
  }
46
46
  else {
47
- parentG.appendChild(g);
47
+ if (this.options?.prepend) {
48
+ parentG.prepend(g);
49
+ }
50
+ else {
51
+ parentG.appendChild(g);
52
+ }
48
53
  }
49
54
  this.g = g;
50
55
  }
@@ -711,8 +716,8 @@ class AStar {
711
716
  current.node.adjacentNodes.forEach(next => {
712
717
  let newCost = costSoFar.get(current.node) + this.heuristic(next.data, current.node.data);
713
718
  const previousNode = this.cameFrom.get(current.node);
714
- // 拐点权重,出现拐点则 cost + 1 以避免拐点路径
715
- // 以三点一线确定是否出现拐点
719
+ // Inflection point weight, if an inflection point occurs, cost + 1 to avoid the inflection point path
720
+ // Three points on a line to determine whether there is an inflection point
716
721
  const previousPoint = previousNode ? previousNode.data : previousStart;
717
722
  const x = previousPoint[0] === current?.node.data[0] && previousPoint[0] === next.data[0];
718
723
  const y = previousPoint[1] === current?.node.data[1] && previousPoint[1] === next.data[1];
@@ -796,12 +801,12 @@ const generateElbowLineRoute = (options) => {
796
801
  aStar.search(nextSourcePoint, nextTargetPoint, options.sourcePoint);
797
802
  let route = aStar.getRoute(nextSourcePoint, nextTargetPoint);
798
803
  route = [options.sourcePoint, ...route, nextTargetPoint, options.targetPoint];
799
- // 中线纠正: 基于水平中线/垂直中线纠正最短路径 route
800
- // 1. 找水平中线(xAxis)/垂直中线(yAxis
801
- // 2. route 中找到和 xAxis/yAxis 相交的点、在 route 中找和 xAxis/yAxis 平行的线段
802
- // 3. 基于步骤上一步找到的相交点和平行线构建矩形
803
- // 4. 判断矩形是否和元素相交,不相交则可以基于上步构建的矩形进行中线的映射
804
- // 5. 判断映射中线后的路径是否符合约束条件(拐点数据不能增加)
804
+ // Centerline correction: Correct the shortest path route based on the horizontal centerline/vertical centerline
805
+ // 1. Find the horizontal center line (xAxis)/vertical center line (yAxis)
806
+ // 2. Find the point that intersects xAxis/yAxis in route, and find the line segment parallel to xAxis/yAxis in route
807
+ // 3. Construct a rectangle based on the intersection points and parallel lines found in the previous step.
808
+ // 4. Determine whether the rectangle intersects with the element. If it does not intersect, the center line can be mapped based on the rectangle constructed in the previous step.
809
+ // 5. Determine whether the path after mapping the center line meets the constraints (inflection point cannot be increased)
805
810
  const isHitX = RectangleClient.isHitX(options.sourceOuterRectangle, options.targetOuterRectangle);
806
811
  const isHitY = RectangleClient.isHitY(options.sourceOuterRectangle, options.targetOuterRectangle);
807
812
  const xAxis = isHitX ? undefined : RectangleClient.getGapCenter(options.sourceOuterRectangle, options.targetOuterRectangle, true);
@@ -833,7 +838,7 @@ const adjust = (route, options) => {
833
838
  const { parallelPaths, pointOfHit, sourceRectangle, targetRectangle } = options;
834
839
  let result = null;
835
840
  parallelPaths.forEach(parallelPath => {
836
- // 构建矩形
841
+ // Construct a rectangle
837
842
  const tempRect = RectangleClient.toRectangleClient([pointOfHit, parallelPath[0], parallelPath[1]]);
838
843
  if (!RectangleClient.isHit(tempRect, sourceRectangle) && !RectangleClient.isHit(tempRect, targetRectangle)) {
839
844
  const getCornerCount = (path) => {
@@ -1075,6 +1080,73 @@ const PropertyTransforms = {
1075
1080
  setStrokeColor
1076
1081
  };
1077
1082
 
1083
+ const alignTop = (board) => {
1084
+ function getOffset(outerRectangle, rectangle) {
1085
+ return [0, outerRectangle.y - rectangle.y];
1086
+ }
1087
+ setOffset(board, getOffset);
1088
+ };
1089
+ const alignHorizontalCenter = (board) => {
1090
+ function getOffset(outerRectangle, rectangle) {
1091
+ const outerCenter = outerRectangle.y + outerRectangle.height / 2;
1092
+ const elementCenter = rectangle.y + rectangle.height / 2;
1093
+ return [0, outerCenter - elementCenter];
1094
+ }
1095
+ setOffset(board, getOffset);
1096
+ };
1097
+ const alignBottom = (board) => {
1098
+ function getOffset(outerRectangle, rectangle) {
1099
+ return [0, outerRectangle.y + outerRectangle.height - (rectangle.y + rectangle.height)];
1100
+ }
1101
+ setOffset(board, getOffset);
1102
+ };
1103
+ const alignLeft = (board) => {
1104
+ function getOffset(outerRectangle, rectangle) {
1105
+ return [outerRectangle.x - rectangle.x, 0];
1106
+ }
1107
+ setOffset(board, getOffset);
1108
+ };
1109
+ const alignVerticalCenter = (board) => {
1110
+ function getOffset(outerRectangle, rectangle) {
1111
+ const outerCenter = outerRectangle.x + outerRectangle.width / 2;
1112
+ const elementCenter = rectangle.x + rectangle.width / 2;
1113
+ return [outerCenter - elementCenter, 0];
1114
+ }
1115
+ setOffset(board, getOffset);
1116
+ };
1117
+ const alignRight = (board) => {
1118
+ function getOffset(outerRectangle, rectangle) {
1119
+ return [outerRectangle.x + outerRectangle.width - (rectangle.x + rectangle.width), 0];
1120
+ }
1121
+ setOffset(board, getOffset);
1122
+ };
1123
+ function setOffset(board, getOffset) {
1124
+ let elements = getSelectedElements(board);
1125
+ elements = elements.filter(element => board.children.includes(element));
1126
+ const outerRectangle = getRectangleByElements(board, elements, false);
1127
+ elements.forEach(element => {
1128
+ if (!element.points)
1129
+ return;
1130
+ const path = PlaitBoard.findPath(board, element);
1131
+ const rectangle = board.getRectangle(element);
1132
+ const offset = getOffset(outerRectangle, rectangle);
1133
+ const newPoints = element.points.map(p => [p[0] + offset[0], p[1] + offset[1]]);
1134
+ Transforms.setNode(board, {
1135
+ points: newPoints
1136
+ }, path);
1137
+ MERGING.set(board, true);
1138
+ });
1139
+ MERGING.set(board, false);
1140
+ }
1141
+ const AlignTransform = {
1142
+ alignTop,
1143
+ alignHorizontalCenter,
1144
+ alignBottom,
1145
+ alignLeft,
1146
+ alignVerticalCenter,
1147
+ alignRight
1148
+ };
1149
+
1078
1150
  const normalizeShapePoints = (points, shift = false) => {
1079
1151
  let start = points[0];
1080
1152
  let end = points[1];
@@ -1130,7 +1202,8 @@ const withResize = (board, options) => {
1130
1202
  if (startPoint && resizeDetectResult && !isResizing(board)) {
1131
1203
  // prevent text from being selected
1132
1204
  event.preventDefault();
1133
- const endPoint = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
1205
+ const endPoint = [event.x, event.y];
1206
+ ;
1134
1207
  const distance = distanceBetweenPointAndPoint(startPoint[0], startPoint[1], endPoint[0], endPoint[1]);
1135
1208
  if (distance > PRESS_AND_MOVE_BUFFER) {
1136
1209
  addResizing(board, resizeRef, options.key);
@@ -1310,5 +1383,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
1310
1383
  * Generated bundle index. Do not edit.
1311
1384
  */
1312
1385
 
1313
- export { AStar, ActiveGenerator, BASE, BoardCreationMode, CommonPluginElement, DEFAULT_ROUTE_MARGIN, Generator, IS_RESIZING, ImageBaseComponent, ImageGenerator, MediaKeys, PICTURE_ACCEPTED_UPLOAD_SIZE, PRIMARY_COLOR, PointGraph, PointNode, PriorityQueue, PropertyTransforms, RESIZE_HANDLE_DIAMETER, ResizeHandle, TRANSPARENT, WithCommonPluginKey, WithTextPluginKey, acceptImageTypes, addElementOfFocusedImage, addResizing, buildImage, calculatePolylineLength, createGraph, generateElbowLineRoute, getCreationMode, getDirection, getDirectionBetweenPointAndPoint, getDirectionByPointOfRectangle, getDirectionByVector, getDirectionFactor, getEdgeCenter, getElementOfFocusedImage, getExtendPoint, getFactorByPoints, getFirstTextEditor, getFirstTextManage, getGraphPoints, getMemorizedLatest, getNextPoint, getOppositeDirection, getPointByVector, getPointOnPolyline, getPoints, getRatioByPoint, getRectangleByPoints, getRectangleResizeHandleRefs, getTextEditors, getTextManages, getTextMarksByElement, hasAfterDraw, isDelete, isDndMode, isDrawingMode, isEnterHotkey, isExpandHotkey, isPointOnLineSegment, isResizing, isResizingByCondition, isSpaceHotkey, isTabHotkey, isVirtualKey, memorizeLatest, normalizeShapePoints, reduceRouteMargin, removeDuplicatePoints, removeElementOfFocusedImage, removeResizing, rotateVectorAnti90, routeAdjust, selectImage, setCreationMode, setProperty, withResize };
1386
+ export { AStar, ActiveGenerator, AlignTransform, BASE, BoardCreationMode, CommonPluginElement, DEFAULT_ROUTE_MARGIN, Generator, IS_RESIZING, ImageBaseComponent, ImageGenerator, MediaKeys, PICTURE_ACCEPTED_UPLOAD_SIZE, PRIMARY_COLOR, PointGraph, PointNode, PriorityQueue, PropertyTransforms, RESIZE_HANDLE_DIAMETER, ResizeHandle, TRANSPARENT, WithCommonPluginKey, WithTextPluginKey, acceptImageTypes, addElementOfFocusedImage, addResizing, alignBottom, alignHorizontalCenter, alignLeft, alignRight, alignTop, alignVerticalCenter, buildImage, calculatePolylineLength, createGraph, generateElbowLineRoute, getCreationMode, getDirection, getDirectionBetweenPointAndPoint, getDirectionByPointOfRectangle, getDirectionByVector, getDirectionFactor, getEdgeCenter, getElementOfFocusedImage, getExtendPoint, getFactorByPoints, getFirstTextEditor, getFirstTextManage, getGraphPoints, getMemorizedLatest, getNextPoint, getOppositeDirection, getPointByVector, getPointOnPolyline, getPoints, getRatioByPoint, getRectangleByPoints, getRectangleResizeHandleRefs, getTextEditors, getTextManages, getTextMarksByElement, hasAfterDraw, isDelete, isDndMode, isDrawingMode, isEnterHotkey, isExpandHotkey, isPointOnLineSegment, isResizing, isResizingByCondition, isSpaceHotkey, isTabHotkey, isVirtualKey, memorizeLatest, normalizeShapePoints, reduceRouteMargin, removeDuplicatePoints, removeElementOfFocusedImage, removeResizing, rotateVectorAnti90, routeAdjust, selectImage, setCreationMode, setProperty, withResize };
1314
1387
  //# sourceMappingURL=plait-common.mjs.map