@plait/common 0.47.0 → 0.49.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/esm2022/algorithms/a-star.mjs +3 -3
- package/esm2022/plugins/with-resize.mjs +5 -6
- package/esm2022/transforms/align.mjs +108 -0
- package/esm2022/transforms/index.mjs +3 -1
- package/esm2022/transforms/text.mjs +62 -0
- package/esm2022/utils/elbow-line-route.mjs +8 -8
- package/fesm2022/plait-common.mjs +181 -16
- package/fesm2022/plait-common.mjs.map +1 -1
- package/package.json +1 -1
- package/transforms/align.d.ts +20 -0
- package/transforms/index.d.ts +2 -0
- package/transforms/text.d.ts +9 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { createG, RectangleClient, drawRectangle, drawCircle, PlaitBoard, createForeignObject, updateForeignObject, ResizeCursorClass, setDragging, Direction, distanceBetweenPointAndPoint, Point, hotkeys, PlaitElement, PlaitContextService, downScale, getSelectedElements, Transforms, PlaitPointerType, isMainPointer,
|
|
1
|
+
import { createG, RectangleClient, drawRectangle, drawCircle, PlaitBoard, createForeignObject, updateForeignObject, ResizeCursorClass, setDragging, Direction, distanceBetweenPointAndPoint, Point, hotkeys, PlaitElement, PlaitContextService, downScale, getSelectedElements, Transforms, getRectangleByElements, MERGING, PlaitPointerType, isMainPointer, toViewBoxPoint, toHostPoint, preventTouchMove, PRESS_AND_MOVE_BUFFER, throttleRAF, handleTouchTarget, PlaitPluginElementComponent, isSelectionMoving, ACTIVE_STROKE_WIDTH } from '@plait/core';
|
|
2
2
|
import { isKeyHotkey } from 'is-hotkey';
|
|
3
|
-
import { PlaitMarkEditor } from '@plait/text';
|
|
3
|
+
import { PlaitMarkEditor, MarkTypes, AlignEditor } from '@plait/text';
|
|
4
|
+
import { Transforms as Transforms$1, Editor } from 'slate';
|
|
4
5
|
import * as i0 from '@angular/core';
|
|
5
6
|
import { Directive, Input } from '@angular/core';
|
|
6
7
|
|
|
@@ -716,8 +717,8 @@ class AStar {
|
|
|
716
717
|
current.node.adjacentNodes.forEach(next => {
|
|
717
718
|
let newCost = costSoFar.get(current.node) + this.heuristic(next.data, current.node.data);
|
|
718
719
|
const previousNode = this.cameFrom.get(current.node);
|
|
719
|
-
//
|
|
720
|
-
//
|
|
720
|
+
// Inflection point weight, if an inflection point occurs, cost + 1 to avoid the inflection point path
|
|
721
|
+
// Three points on a line to determine whether there is an inflection point
|
|
721
722
|
const previousPoint = previousNode ? previousNode.data : previousStart;
|
|
722
723
|
const x = previousPoint[0] === current?.node.data[0] && previousPoint[0] === next.data[0];
|
|
723
724
|
const y = previousPoint[1] === current?.node.data[1] && previousPoint[1] === next.data[1];
|
|
@@ -801,12 +802,12 @@ const generateElbowLineRoute = (options) => {
|
|
|
801
802
|
aStar.search(nextSourcePoint, nextTargetPoint, options.sourcePoint);
|
|
802
803
|
let route = aStar.getRoute(nextSourcePoint, nextTargetPoint);
|
|
803
804
|
route = [options.sourcePoint, ...route, nextTargetPoint, options.targetPoint];
|
|
804
|
-
//
|
|
805
|
-
// 1.
|
|
806
|
-
// 2.
|
|
807
|
-
// 3.
|
|
808
|
-
// 4.
|
|
809
|
-
// 5.
|
|
805
|
+
// Centerline correction: Correct the shortest path route based on the horizontal centerline/vertical centerline
|
|
806
|
+
// 1. Find the horizontal center line (xAxis)/vertical center line (yAxis)
|
|
807
|
+
// 2. Find the point that intersects xAxis/yAxis in route, and find the line segment parallel to xAxis/yAxis in route
|
|
808
|
+
// 3. Construct a rectangle based on the intersection points and parallel lines found in the previous step.
|
|
809
|
+
// 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.
|
|
810
|
+
// 5. Determine whether the path after mapping the center line meets the constraints (inflection point cannot be increased)
|
|
810
811
|
const isHitX = RectangleClient.isHitX(options.sourceOuterRectangle, options.targetOuterRectangle);
|
|
811
812
|
const isHitY = RectangleClient.isHitY(options.sourceOuterRectangle, options.targetOuterRectangle);
|
|
812
813
|
const xAxis = isHitX ? undefined : RectangleClient.getGapCenter(options.sourceOuterRectangle, options.targetOuterRectangle, true);
|
|
@@ -838,7 +839,7 @@ const adjust = (route, options) => {
|
|
|
838
839
|
const { parallelPaths, pointOfHit, sourceRectangle, targetRectangle } = options;
|
|
839
840
|
let result = null;
|
|
840
841
|
parallelPaths.forEach(parallelPath => {
|
|
841
|
-
//
|
|
842
|
+
// Construct a rectangle
|
|
842
843
|
const tempRect = RectangleClient.toRectangleClient([pointOfHit, parallelPath[0], parallelPath[1]]);
|
|
843
844
|
if (!RectangleClient.isHit(tempRect, sourceRectangle) && !RectangleClient.isHit(tempRect, targetRectangle)) {
|
|
844
845
|
const getCornerCount = (path) => {
|
|
@@ -1080,6 +1081,171 @@ const PropertyTransforms = {
|
|
|
1080
1081
|
setStrokeColor
|
|
1081
1082
|
};
|
|
1082
1083
|
|
|
1084
|
+
const alignTop = (board) => {
|
|
1085
|
+
function getOffset(outerRectangle, rectangle) {
|
|
1086
|
+
return [0, outerRectangle.y - rectangle.y];
|
|
1087
|
+
}
|
|
1088
|
+
setOffset(board, getOffset);
|
|
1089
|
+
};
|
|
1090
|
+
const alignHorizontalCenter = (board) => {
|
|
1091
|
+
function getOffset(outerRectangle, rectangle) {
|
|
1092
|
+
const outerCenter = outerRectangle.y + outerRectangle.height / 2;
|
|
1093
|
+
const elementCenter = rectangle.y + rectangle.height / 2;
|
|
1094
|
+
return [0, outerCenter - elementCenter];
|
|
1095
|
+
}
|
|
1096
|
+
setOffset(board, getOffset);
|
|
1097
|
+
};
|
|
1098
|
+
const alignBottom = (board) => {
|
|
1099
|
+
function getOffset(outerRectangle, rectangle) {
|
|
1100
|
+
return [0, outerRectangle.y + outerRectangle.height - (rectangle.y + rectangle.height)];
|
|
1101
|
+
}
|
|
1102
|
+
setOffset(board, getOffset);
|
|
1103
|
+
};
|
|
1104
|
+
const alignLeft = (board) => {
|
|
1105
|
+
function getOffset(outerRectangle, rectangle) {
|
|
1106
|
+
return [outerRectangle.x - rectangle.x, 0];
|
|
1107
|
+
}
|
|
1108
|
+
setOffset(board, getOffset);
|
|
1109
|
+
};
|
|
1110
|
+
const alignVerticalCenter = (board) => {
|
|
1111
|
+
function getOffset(outerRectangle, rectangle) {
|
|
1112
|
+
const outerCenter = outerRectangle.x + outerRectangle.width / 2;
|
|
1113
|
+
const elementCenter = rectangle.x + rectangle.width / 2;
|
|
1114
|
+
return [outerCenter - elementCenter, 0];
|
|
1115
|
+
}
|
|
1116
|
+
setOffset(board, getOffset);
|
|
1117
|
+
};
|
|
1118
|
+
const alignRight = (board) => {
|
|
1119
|
+
function getOffset(outerRectangle, rectangle) {
|
|
1120
|
+
return [outerRectangle.x + outerRectangle.width - (rectangle.x + rectangle.width), 0];
|
|
1121
|
+
}
|
|
1122
|
+
setOffset(board, getOffset);
|
|
1123
|
+
};
|
|
1124
|
+
function setOffset(board, getOffset) {
|
|
1125
|
+
let elements = getSelectedElements(board);
|
|
1126
|
+
elements = elements.filter(element => board.children.includes(element));
|
|
1127
|
+
const outerRectangle = getRectangleByElements(board, elements, false);
|
|
1128
|
+
elements.forEach(element => {
|
|
1129
|
+
if (!element.points)
|
|
1130
|
+
return;
|
|
1131
|
+
const path = PlaitBoard.findPath(board, element);
|
|
1132
|
+
const rectangle = board.getRectangle(element);
|
|
1133
|
+
const offset = getOffset(outerRectangle, rectangle);
|
|
1134
|
+
const newPoints = element.points.map(p => [p[0] + offset[0], p[1] + offset[1]]);
|
|
1135
|
+
Transforms.setNode(board, {
|
|
1136
|
+
points: newPoints
|
|
1137
|
+
}, path);
|
|
1138
|
+
MERGING.set(board, true);
|
|
1139
|
+
});
|
|
1140
|
+
MERGING.set(board, false);
|
|
1141
|
+
}
|
|
1142
|
+
const distributeHorizontal = (board) => {
|
|
1143
|
+
distribute(board, true);
|
|
1144
|
+
};
|
|
1145
|
+
const distributeVertical = (board) => {
|
|
1146
|
+
distribute(board, false);
|
|
1147
|
+
};
|
|
1148
|
+
const distribute = (board, isHorizontal) => {
|
|
1149
|
+
const axis = isHorizontal ? 'x' : 'y';
|
|
1150
|
+
const side = isHorizontal ? 'width' : 'height';
|
|
1151
|
+
const selectedElements = getSelectedElements(board).filter(element => board.children.includes(element));
|
|
1152
|
+
const refs = selectedElements.map(element => {
|
|
1153
|
+
return { element, rectangle: board.getRectangle(element) };
|
|
1154
|
+
});
|
|
1155
|
+
const outerRectangle = getRectangleByElements(board, selectedElements, false);
|
|
1156
|
+
const minRectangleRef = refs.sort((a, b) => a.rectangle[axis] - b.rectangle[axis])[0];
|
|
1157
|
+
const maxRectangleRef = refs.sort((a, b) => b.rectangle[axis] + b.rectangle[side] - (a.rectangle[axis] + a.rectangle[side]))[0];
|
|
1158
|
+
const minIndex = refs.findIndex(ref => ref === minRectangleRef);
|
|
1159
|
+
const maxIndex = refs.findIndex(ref => ref === maxRectangleRef);
|
|
1160
|
+
let distributeRefs = refs.filter((element, index) => index !== minIndex && index !== maxIndex);
|
|
1161
|
+
const sum = distributeRefs.reduce((accumulator, current) => current.rectangle[side] + accumulator, 0);
|
|
1162
|
+
const offset = (outerRectangle[side] - minRectangleRef.rectangle[side] - maxRectangleRef.rectangle[side] - sum) / (distributeRefs.length + 1);
|
|
1163
|
+
distributeRefs = distributeRefs.sort((a, b) => a.rectangle[axis] - b.rectangle[axis]);
|
|
1164
|
+
let position = minRectangleRef.rectangle[axis] + minRectangleRef.rectangle[side] + offset;
|
|
1165
|
+
for (let i = 0; i < distributeRefs.length; i++) {
|
|
1166
|
+
const rectangle = distributeRefs[i].rectangle;
|
|
1167
|
+
const moveOffset = [0, 0];
|
|
1168
|
+
const moveAxis = isHorizontal ? 0 : 1;
|
|
1169
|
+
moveOffset[moveAxis] = position - rectangle[axis];
|
|
1170
|
+
const path = PlaitBoard.findPath(board, distributeRefs[i].element);
|
|
1171
|
+
const newPoints = distributeRefs[i].element.points.map(p => [p[0] + moveOffset[0], p[1] + moveOffset[1]]);
|
|
1172
|
+
Transforms.setNode(board, {
|
|
1173
|
+
points: newPoints
|
|
1174
|
+
}, path);
|
|
1175
|
+
MERGING.set(board, true);
|
|
1176
|
+
position = position + rectangle[side] + offset;
|
|
1177
|
+
}
|
|
1178
|
+
MERGING.set(board, false);
|
|
1179
|
+
};
|
|
1180
|
+
const AlignTransform = {
|
|
1181
|
+
alignTop,
|
|
1182
|
+
alignHorizontalCenter,
|
|
1183
|
+
alignBottom,
|
|
1184
|
+
alignLeft,
|
|
1185
|
+
alignVerticalCenter,
|
|
1186
|
+
alignRight,
|
|
1187
|
+
distributeHorizontal,
|
|
1188
|
+
distributeVertical
|
|
1189
|
+
};
|
|
1190
|
+
|
|
1191
|
+
const setTextMarks = (board, mark) => {
|
|
1192
|
+
const selectedElements = getSelectedElements(board);
|
|
1193
|
+
if (selectedElements.length) {
|
|
1194
|
+
const firstEditor = getTextEditors(selectedElements[0])[0];
|
|
1195
|
+
const activeMarks = PlaitMarkEditor.getMarks(firstEditor);
|
|
1196
|
+
const elements = selectedElements.filter(element => {
|
|
1197
|
+
const editors = getTextEditors(element);
|
|
1198
|
+
return editors.some(editor => {
|
|
1199
|
+
const elementMarks = PlaitMarkEditor.getMarks(editor);
|
|
1200
|
+
return elementMarks[mark] === activeMarks[mark];
|
|
1201
|
+
});
|
|
1202
|
+
});
|
|
1203
|
+
elements.forEach(element => {
|
|
1204
|
+
const editors = getTextEditors(element);
|
|
1205
|
+
editors.forEach(editor => PlaitMarkEditor.toggleMark(editor, mark));
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1208
|
+
};
|
|
1209
|
+
const setFontSize = (board, size, defaultFontSize) => {
|
|
1210
|
+
const selectedElements = getSelectedElements(board);
|
|
1211
|
+
if (selectedElements.length) {
|
|
1212
|
+
selectedElements.forEach(element => {
|
|
1213
|
+
const editors = getTextEditors(element);
|
|
1214
|
+
const finalDefaultFontSize = typeof defaultFontSize === 'function' ? defaultFontSize(element) : defaultFontSize;
|
|
1215
|
+
editors.forEach(editor => PlaitMarkEditor.setFontSizeMark(editor, size, finalDefaultFontSize));
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
const setTextColor = (board, color, textSelection) => {
|
|
1220
|
+
const selectedElements = getSelectedElements(board);
|
|
1221
|
+
if (selectedElements?.length) {
|
|
1222
|
+
selectedElements.forEach(element => {
|
|
1223
|
+
const editors = getTextEditors(element);
|
|
1224
|
+
editors.forEach(editor => {
|
|
1225
|
+
if (textSelection) {
|
|
1226
|
+
Transforms$1.select(editor, textSelection);
|
|
1227
|
+
}
|
|
1228
|
+
if (color === 'transparent') {
|
|
1229
|
+
Editor.removeMark(editor, MarkTypes.color);
|
|
1230
|
+
}
|
|
1231
|
+
else {
|
|
1232
|
+
PlaitMarkEditor.setColorMark(editor, color);
|
|
1233
|
+
}
|
|
1234
|
+
});
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
};
|
|
1238
|
+
const setTextAlign = (board, align) => {
|
|
1239
|
+
const selectedElements = getSelectedElements(board);
|
|
1240
|
+
if (selectedElements?.length) {
|
|
1241
|
+
selectedElements.forEach(element => {
|
|
1242
|
+
const editors = getTextEditors(element);
|
|
1243
|
+
editors.forEach(editor => AlignEditor.setAlign(editor, align));
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
};
|
|
1247
|
+
const TextTransforms = { setTextAlign, setTextColor, setFontSize, setTextMarks };
|
|
1248
|
+
|
|
1083
1249
|
const normalizeShapePoints = (points, shift = false) => {
|
|
1084
1250
|
let start = points[0];
|
|
1085
1251
|
let end = points[1];
|
|
@@ -1108,7 +1274,7 @@ const withResize = (board, options) => {
|
|
|
1108
1274
|
pointerDown(event);
|
|
1109
1275
|
return;
|
|
1110
1276
|
}
|
|
1111
|
-
const point =
|
|
1277
|
+
const point = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
|
|
1112
1278
|
resizeDetectResult = options.detect(point);
|
|
1113
1279
|
if (resizeDetectResult) {
|
|
1114
1280
|
if (resizeDetectResult.cursorClass) {
|
|
@@ -1136,7 +1302,6 @@ const withResize = (board, options) => {
|
|
|
1136
1302
|
// prevent text from being selected
|
|
1137
1303
|
event.preventDefault();
|
|
1138
1304
|
const endPoint = [event.x, event.y];
|
|
1139
|
-
;
|
|
1140
1305
|
const distance = distanceBetweenPointAndPoint(startPoint[0], startPoint[1], endPoint[0], endPoint[1]);
|
|
1141
1306
|
if (distance > PRESS_AND_MOVE_BUFFER) {
|
|
1142
1307
|
addResizing(board, resizeRef, options.key);
|
|
@@ -1147,7 +1312,7 @@ const withResize = (board, options) => {
|
|
|
1147
1312
|
if (isResizing(board) && startPoint) {
|
|
1148
1313
|
// prevent text from being selected
|
|
1149
1314
|
event.preventDefault();
|
|
1150
|
-
const endTransformPoint =
|
|
1315
|
+
const endTransformPoint = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
|
|
1151
1316
|
throttleRAF(() => {
|
|
1152
1317
|
const endPoint = [event.x, event.y];
|
|
1153
1318
|
if (startPoint && resizeRef) {
|
|
@@ -1160,7 +1325,7 @@ const withResize = (board, options) => {
|
|
|
1160
1325
|
return;
|
|
1161
1326
|
}
|
|
1162
1327
|
else {
|
|
1163
|
-
const point =
|
|
1328
|
+
const point = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
|
|
1164
1329
|
const resizeDetectResult = options.detect(point);
|
|
1165
1330
|
if (resizeDetectResult) {
|
|
1166
1331
|
if (hoveDetectResult && resizeDetectResult.cursorClass !== hoveDetectResult.cursorClass) {
|
|
@@ -1316,5 +1481,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
|
|
|
1316
1481
|
* Generated bundle index. Do not edit.
|
|
1317
1482
|
*/
|
|
1318
1483
|
|
|
1319
|
-
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 };
|
|
1484
|
+
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, TextTransforms, WithCommonPluginKey, WithTextPluginKey, acceptImageTypes, addElementOfFocusedImage, addResizing, alignBottom, alignHorizontalCenter, alignLeft, alignRight, alignTop, alignVerticalCenter, buildImage, calculatePolylineLength, createGraph, distributeHorizontal, distributeVertical, 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 };
|
|
1320
1485
|
//# sourceMappingURL=plait-common.mjs.map
|