@plait/draw 0.48.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/plugins/with-geometry-create.mjs +6 -6
- package/esm2022/plugins/with-line-auto-complete-reaction.mjs +3 -3
- package/esm2022/plugins/with-line-auto-complete.mjs +4 -4
- package/esm2022/plugins/with-line-bound-reaction.mjs +3 -3
- package/esm2022/plugins/with-line-create.mjs +4 -4
- package/esm2022/plugins/with-line-text.mjs +3 -3
- package/esm2022/transforms/image.mjs +3 -4
- package/esm2022/transforms/index.mjs +3 -2
- package/esm2022/transforms/line.mjs +25 -8
- package/fesm2022/plait-draw.mjs +36 -19
- package/fesm2022/plait-draw.mjs.map +1 -1
- package/package.json +1 -1
- package/transforms/index.d.ts +2 -1
- package/transforms/line.d.ts +2 -1
- package/utils/clipboard.d.ts +1 -1
- package/utils/geometry.d.ts +1 -1
package/fesm2022/plait-draw.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ACTIVE_STROKE_WIDTH, ThemeColorMode, PlaitBoard, setStrokeLinecap, isPointInPolygon, getNearestPointBetweenPointAndSegments, RectangleClient, isPointInEllipse, drawRectangle, drawRoundRectangle, isPointInRoundRectangle, idCreator, createG, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, drawCircle, distanceBetweenPointAndSegment, Transforms, clearSelectedElement, addSelectedElement, BoardTransforms, PlaitPointerType, arrowPoints, createPath, distanceBetweenPointAndPoint, drawLinearPath, rotate, depthFirstRecursion, getIsRecursionFunc, getElementById, Direction, catmullRomFitting, distanceBetweenPointAndSegments, createMask, createRect, findElements, Point, getSelectedElements, isPolylineHitRectangle, Path, PlaitNode,
|
|
1
|
+
import { ACTIVE_STROKE_WIDTH, ThemeColorMode, PlaitBoard, setStrokeLinecap, isPointInPolygon, getNearestPointBetweenPointAndSegments, RectangleClient, isPointInEllipse, drawRectangle, drawRoundRectangle, isPointInRoundRectangle, idCreator, createG, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, drawCircle, distanceBetweenPointAndSegment, Transforms, clearSelectedElement, addSelectedElement, BoardTransforms, PlaitPointerType, arrowPoints, createPath, distanceBetweenPointAndPoint, drawLinearPath, rotate, depthFirstRecursion, getIsRecursionFunc, getElementById, Direction, catmullRomFitting, distanceBetweenPointAndSegments, createMask, createRect, findElements, Point, getSelectedElements, isPolylineHitRectangle, Path, PlaitNode, toViewBoxPoint, toHostPoint, isSelectionMoving, RgbaToHEX, PlaitElement, preventTouchMove, setClipboardData, getDataFromClipboard, getHitElementByPoint, CursorClass, temporaryDisableSelection, PRESS_AND_MOVE_BUFFER } from '@plait/core';
|
|
2
2
|
import { getRectangleByPoints, getMemorizedLatest, memorizeLatest, RESIZE_HANDLE_DIAMETER, getExtendPoint, getFactorByPoints, Generator, getRectangleResizeHandleRefs, getDirectionByVector, getOppositeDirection, getDirectionFactor, getPointByVector, reduceRouteMargin, getNextPoint, generateElbowLineRoute, getPoints, removeDuplicatePoints, getPointOnPolyline, getDirectionByPointOfRectangle, rotateVectorAnti90, TRANSPARENT, normalizeShapePoints, getFirstTextEditor, PRIMARY_COLOR, CommonPluginElement, ActiveGenerator, WithTextPluginKey, isVirtualKey, isDelete, isSpaceHotkey, isDndMode, isDrawingMode, acceptImageTypes, getElementOfFocusedImage, buildImage, ResizeHandle, getFirstTextManage, withResize, isResizingByCondition, getRatioByPoint, ImageGenerator } from '@plait/common';
|
|
3
3
|
import { Alignment, buildText, DEFAULT_FONT_SIZE, getTextSize, AlignEditor, TextManage, getTextFromClipboard } from '@plait/text';
|
|
4
4
|
import { pointsOnBezierCurves } from 'points-on-curve';
|
|
@@ -2244,12 +2244,29 @@ const removeLineText = (board, element, index) => {
|
|
|
2244
2244
|
newTexts.splice(index, 1);
|
|
2245
2245
|
Transforms.setNode(board, { texts: newTexts }, path);
|
|
2246
2246
|
};
|
|
2247
|
-
const setLineMark = (board,
|
|
2248
|
-
const path = PlaitBoard.findPath(board, element);
|
|
2249
|
-
let handle = handleKey === LineHandleKey.source ? element.source : element.target;
|
|
2250
|
-
handle = { ...handle, marker };
|
|
2247
|
+
const setLineMark = (board, handleKey, marker) => {
|
|
2251
2248
|
memorizeLatest(MemorizeKey.line, handleKey, marker);
|
|
2252
|
-
|
|
2249
|
+
const selectedElements = getSelectedLineElements(board);
|
|
2250
|
+
selectedElements.forEach((element) => {
|
|
2251
|
+
const path = PlaitBoard.findPath(board, element);
|
|
2252
|
+
let handle = handleKey === LineHandleKey.source ? element.source : element.target;
|
|
2253
|
+
handle = { ...handle, marker };
|
|
2254
|
+
Transforms.setNode(board, { [handleKey]: handle }, path);
|
|
2255
|
+
});
|
|
2256
|
+
};
|
|
2257
|
+
const setLineShape = (board, newProperties) => {
|
|
2258
|
+
const elements = getSelectedLineElements(board);
|
|
2259
|
+
elements.map(element => {
|
|
2260
|
+
const _properties = { ...newProperties };
|
|
2261
|
+
if (element.shape === newProperties.shape) {
|
|
2262
|
+
return;
|
|
2263
|
+
}
|
|
2264
|
+
if (newProperties.shape === LineShape.elbow) {
|
|
2265
|
+
_properties.points = [element.points[0], element.points[element.points.length - 1]];
|
|
2266
|
+
}
|
|
2267
|
+
const path = PlaitBoard.findPath(board, element);
|
|
2268
|
+
Transforms.setNode(board, _properties, path);
|
|
2269
|
+
});
|
|
2253
2270
|
};
|
|
2254
2271
|
const collectLineUpdatedRefsByGeometry = (board, geometry, refs) => {
|
|
2255
2272
|
const lines = findElements(board, {
|
|
@@ -2419,10 +2436,9 @@ const setTextSize = (board, element, textWidth, textHeight) => {
|
|
|
2419
2436
|
|
|
2420
2437
|
const insertImage = (board, imageItem, startPoint) => {
|
|
2421
2438
|
const { width, height, url } = imageItem;
|
|
2422
|
-
const host = BOARD_TO_HOST.get(board);
|
|
2423
2439
|
const viewportWidth = PlaitBoard.getComponent(board).nativeElement.clientWidth;
|
|
2424
2440
|
const viewportHeight = PlaitBoard.getComponent(board).nativeElement.clientHeight;
|
|
2425
|
-
const point =
|
|
2441
|
+
const point = toViewBoxPoint(board, toHostPoint(board, viewportWidth / 2, viewportHeight / 2));
|
|
2426
2442
|
const points = startPoint
|
|
2427
2443
|
? [startPoint, [startPoint[0] + width, startPoint[1] + height]]
|
|
2428
2444
|
: [
|
|
@@ -2449,6 +2465,7 @@ const DrawTransforms = {
|
|
|
2449
2465
|
setLineTexts,
|
|
2450
2466
|
removeLineText,
|
|
2451
2467
|
setLineMark,
|
|
2468
|
+
setLineShape,
|
|
2452
2469
|
insertImage,
|
|
2453
2470
|
switchGeometryShape,
|
|
2454
2471
|
connectLineToGeometry,
|
|
@@ -2915,7 +2932,7 @@ const withGeometryCreateByDrag = (board) => {
|
|
|
2915
2932
|
const geometryPointers = getGeometryPointers();
|
|
2916
2933
|
const isGeometryPointer = PlaitBoard.isInPointer(board, geometryPointers);
|
|
2917
2934
|
const dragMode = isGeometryPointer && isDndMode(board);
|
|
2918
|
-
const movingPoint =
|
|
2935
|
+
const movingPoint = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
|
|
2919
2936
|
const pointer = PlaitBoard.getPointer(board);
|
|
2920
2937
|
if (dragMode) {
|
|
2921
2938
|
const memorizedLatest = getMemorizedLatestByPointer(pointer);
|
|
@@ -2990,7 +3007,7 @@ const withGeometryCreateByDrawing = (board) => {
|
|
|
2990
3007
|
const geometryPointers = getGeometryPointers();
|
|
2991
3008
|
const isGeometryPointer = PlaitBoard.isInPointer(board, geometryPointers);
|
|
2992
3009
|
if (!PlaitBoard.isReadonly(board) && isGeometryPointer && isDrawingMode(board)) {
|
|
2993
|
-
const point =
|
|
3010
|
+
const point = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
|
|
2994
3011
|
start = point;
|
|
2995
3012
|
const pointer = PlaitBoard.getPointer(board);
|
|
2996
3013
|
preventTouchMove(board, event, true);
|
|
@@ -3010,7 +3027,7 @@ const withGeometryCreateByDrawing = (board) => {
|
|
|
3010
3027
|
geometryShapeG = createG();
|
|
3011
3028
|
const geometryGenerator = new GeometryShapeGenerator(board);
|
|
3012
3029
|
const drawMode = !!start;
|
|
3013
|
-
const movingPoint =
|
|
3030
|
+
const movingPoint = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
|
|
3014
3031
|
const pointer = PlaitBoard.getPointer(board);
|
|
3015
3032
|
if (drawMode && pointer !== BasicShapes.text) {
|
|
3016
3033
|
const points = normalizeShapePoints([start, movingPoint], isShift);
|
|
@@ -3023,7 +3040,7 @@ const withGeometryCreateByDrawing = (board) => {
|
|
|
3023
3040
|
board.pointerUp = (event) => {
|
|
3024
3041
|
const isDrawMode = !!start;
|
|
3025
3042
|
if (isDrawMode) {
|
|
3026
|
-
const targetPoint =
|
|
3043
|
+
const targetPoint = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
|
|
3027
3044
|
const { width, height } = RectangleClient.toRectangleClient([start, targetPoint]);
|
|
3028
3045
|
if (Math.hypot(width, height) === 0) {
|
|
3029
3046
|
const pointer = PlaitBoard.getPointer(board);
|
|
@@ -3188,7 +3205,7 @@ const withLineCreateByDraw = (board) => {
|
|
|
3188
3205
|
const linePointers = getLinePointers();
|
|
3189
3206
|
const isLinePointer = PlaitBoard.isInPointer(board, linePointers);
|
|
3190
3207
|
if (!PlaitBoard.isReadonly(board) && isLinePointer && isDrawingMode(board)) {
|
|
3191
|
-
const point =
|
|
3208
|
+
const point = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
|
|
3192
3209
|
start = point;
|
|
3193
3210
|
const hitElement = getHitOutlineGeometry(board, point, REACTION_MARGIN);
|
|
3194
3211
|
if (hitElement) {
|
|
@@ -3201,7 +3218,7 @@ const withLineCreateByDraw = (board) => {
|
|
|
3201
3218
|
board.pointerMove = (event) => {
|
|
3202
3219
|
lineShapeG?.remove();
|
|
3203
3220
|
lineShapeG = createG();
|
|
3204
|
-
let movingPoint =
|
|
3221
|
+
let movingPoint = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
|
|
3205
3222
|
if (start) {
|
|
3206
3223
|
const lineShape = PlaitBoard.getPointer(board);
|
|
3207
3224
|
temporaryElement = handleLineCreating(board, lineShape, start, movingPoint, sourceElement, lineShapeG);
|
|
@@ -3449,7 +3466,7 @@ const withLineBoundReaction = (board) => {
|
|
|
3449
3466
|
}
|
|
3450
3467
|
const linePointers = Object.keys(LineShape);
|
|
3451
3468
|
const isLinePointer = PlaitBoard.isInPointer(board, linePointers);
|
|
3452
|
-
const movingPoint =
|
|
3469
|
+
const movingPoint = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
|
|
3453
3470
|
const isLineResizing = isResizingByCondition(board, resizeRef => {
|
|
3454
3471
|
const { element, handle } = resizeRef;
|
|
3455
3472
|
const isSourceOrTarget = handle === LineResizeHandle.target || handle === LineResizeHandle.source;
|
|
@@ -3488,7 +3505,7 @@ const withLineText = (board) => {
|
|
|
3488
3505
|
const { dblclick } = board;
|
|
3489
3506
|
board.dblclick = (event) => {
|
|
3490
3507
|
if (!PlaitBoard.isReadonly(board)) {
|
|
3491
|
-
const clickPoint =
|
|
3508
|
+
const clickPoint = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
|
|
3492
3509
|
const hitTarget = getHitElementByPoint(board, clickPoint, (element) => {
|
|
3493
3510
|
return PlaitDrawElement.isLine(element);
|
|
3494
3511
|
});
|
|
@@ -3619,7 +3636,7 @@ const withLineAutoCompleteReaction = (board) => {
|
|
|
3619
3636
|
PlaitBoard.getBoardContainer(board).classList.remove(CursorClass.crosshair);
|
|
3620
3637
|
const selectedElements = getSelectedDrawElements(board);
|
|
3621
3638
|
const targetElement = selectedElements.length === 1 && selectedElements[0];
|
|
3622
|
-
const movingPoint =
|
|
3639
|
+
const movingPoint = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
|
|
3623
3640
|
if (!PlaitBoard.isReadonly(board) && !isSelectionMoving(board) && targetElement && PlaitDrawElement.isShape(targetElement)) {
|
|
3624
3641
|
const points = getAutoCompletePoints(targetElement);
|
|
3625
3642
|
const hitIndex = getHitIndexOfAutoCompletePoint(movingPoint, points);
|
|
@@ -3652,7 +3669,7 @@ const withLineAutoComplete = (board) => {
|
|
|
3652
3669
|
board.pointerDown = (event) => {
|
|
3653
3670
|
const selectedElements = getSelectedDrawElements(board);
|
|
3654
3671
|
const targetElement = selectedElements.length === 1 && selectedElements[0];
|
|
3655
|
-
const clickPoint =
|
|
3672
|
+
const clickPoint = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
|
|
3656
3673
|
if (!PlaitBoard.isReadonly(board) && targetElement && PlaitDrawElement.isShape(targetElement)) {
|
|
3657
3674
|
const points = getAutoCompletePoints(targetElement);
|
|
3658
3675
|
const index = getHitIndexOfAutoCompletePoint(clickPoint, points);
|
|
@@ -3669,7 +3686,7 @@ const withLineAutoComplete = (board) => {
|
|
|
3669
3686
|
board.pointerMove = (event) => {
|
|
3670
3687
|
lineShapeG?.remove();
|
|
3671
3688
|
lineShapeG = createG();
|
|
3672
|
-
let movingPoint =
|
|
3689
|
+
let movingPoint = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
|
|
3673
3690
|
if (startPoint && sourceElement) {
|
|
3674
3691
|
const distance = distanceBetweenPointAndPoint(...movingPoint, ...startPoint);
|
|
3675
3692
|
if (distance > PRESS_AND_MOVE_BUFFER) {
|