@plait/draw 0.1.0-next.10 → 0.1.0-next.12
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/pointer.d.ts +5 -1
- package/esm2022/constants/pointer.mjs +27 -0
- package/esm2022/generators/line-active.generator.mjs +51 -0
- package/{esm2020 → esm2022}/geometry.component.mjs +4 -4
- package/esm2022/interfaces/geometry.mjs +27 -0
- package/esm2022/interfaces/line.mjs +56 -0
- package/esm2022/line.component.mjs +160 -0
- package/esm2022/plugins/with-draw-fragment.mjs +61 -0
- package/{esm2020 → esm2022}/plugins/with-draw.mjs +4 -5
- package/{esm2020 → esm2022}/utils/clipboard.mjs +2 -1
- package/esm2022/utils/engine/diamond.mjs +30 -0
- package/esm2022/utils/engine/ellipse.mjs +92 -0
- package/esm2022/utils/engine/index.mjs +26 -0
- package/esm2022/utils/engine/left-arrow.mjs +45 -0
- package/esm2022/utils/engine/parallelogram.mjs +39 -0
- package/esm2022/utils/engine/rectangle.mjs +26 -0
- package/esm2022/utils/engine/right-arrow.mjs +45 -0
- package/esm2022/utils/engine/round-rectangle.mjs +59 -0
- package/esm2022/utils/engine/trapezoid.mjs +40 -0
- package/esm2022/utils/engine/triangle.mjs +40 -0
- package/esm2022/utils/geometry.mjs +95 -0
- package/esm2022/utils/line.mjs +205 -0
- package/esm2022/utils/position/line.mjs +33 -0
- package/{fesm2020 → fesm2022}/plait-draw.mjs +416 -88
- package/fesm2022/plait-draw.mjs.map +1 -0
- package/generators/line-active.generator.d.ts +1 -0
- package/interfaces/geometry.d.ts +9 -2
- package/interfaces/line.d.ts +9 -2
- package/line.component.d.ts +1 -0
- package/package.json +7 -12
- package/plugins/with-draw-fragment.d.ts +2 -0
- package/styles/styles.scss +2 -2
- package/utils/engine/left-arrow.d.ts +4 -0
- package/utils/engine/parallelogram.d.ts +1 -1
- package/utils/engine/right-arrow.d.ts +4 -0
- package/utils/engine/trapezoid.d.ts +4 -0
- package/utils/engine/triangle.d.ts +4 -0
- package/utils/geometry.d.ts +1 -0
- package/utils/line.d.ts +10 -6
- package/esm2020/constants/pointer.mjs +0 -19
- package/esm2020/generators/line-active.generator.mjs +0 -36
- package/esm2020/interfaces/geometry.mjs +0 -23
- package/esm2020/interfaces/line.mjs +0 -48
- package/esm2020/line.component.mjs +0 -152
- package/esm2020/plugins/with-draw-fragment.mjs +0 -52
- package/esm2020/utils/engine/diamond.mjs +0 -22
- package/esm2020/utils/engine/ellipse.mjs +0 -55
- package/esm2020/utils/engine/index.mjs +0 -18
- package/esm2020/utils/engine/parallelogram.mjs +0 -32
- package/esm2020/utils/engine/rectangle.mjs +0 -18
- package/esm2020/utils/engine/round-rectangle.mjs +0 -49
- package/esm2020/utils/geometry.mjs +0 -84
- package/esm2020/utils/line.mjs +0 -169
- package/esm2020/utils/position/line.mjs +0 -34
- package/fesm2015/plait-draw.mjs +0 -1765
- package/fesm2015/plait-draw.mjs.map +0 -1
- package/fesm2020/plait-draw.mjs.map +0 -1
- /package/{esm2020 → esm2022}/constants/geometry.mjs +0 -0
- /package/{esm2020 → esm2022}/constants/index.mjs +0 -0
- /package/{esm2020 → esm2022}/constants/line.mjs +0 -0
- /package/{esm2020 → esm2022}/generators/geometry-shape.generator.mjs +0 -0
- /package/{esm2020 → esm2022}/generators/line.generator.mjs +0 -0
- /package/{esm2020 → esm2022}/interfaces/element.mjs +0 -0
- /package/{esm2020 → esm2022}/interfaces/index.mjs +0 -0
- /package/{esm2020 → esm2022}/interfaces/text.mjs +0 -0
- /package/{esm2020 → esm2022}/plait-draw.mjs +0 -0
- /package/{esm2020 → esm2022}/plugins/with-draw-hotkey.mjs +0 -0
- /package/{esm2020 → esm2022}/plugins/with-geometry-create.mjs +0 -0
- /package/{esm2020 → esm2022}/plugins/with-geometry-resize.mjs +0 -0
- /package/{esm2020 → esm2022}/plugins/with-line-bound-reaction.mjs +0 -0
- /package/{esm2020 → esm2022}/plugins/with-line-create.mjs +0 -0
- /package/{esm2020 → esm2022}/plugins/with-line-resize.mjs +0 -0
- /package/{esm2020 → esm2022}/plugins/with-line-text.mjs +0 -0
- /package/{esm2020 → esm2022}/public-api.mjs +0 -0
- /package/{esm2020 → esm2022}/transforms/geometry-text.mjs +0 -0
- /package/{esm2020 → esm2022}/transforms/geometry.mjs +0 -0
- /package/{esm2020 → esm2022}/transforms/index.mjs +0 -0
- /package/{esm2020 → esm2022}/transforms/line.mjs +0 -0
- /package/{esm2020 → esm2022}/utils/index.mjs +0 -0
- /package/{esm2020 → esm2022}/utils/line-arrow.mjs +0 -0
- /package/{esm2020 → esm2022}/utils/position/geometry.mjs +0 -0
- /package/{esm2020 → esm2022}/utils/selected.mjs +0 -0
- /package/{esm2020 → esm2022}/utils/style/index.mjs +0 -0
- /package/{esm2020 → esm2022}/utils/style/stroke.mjs +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { PlaitElement, ACTIVE_STROKE_WIDTH, RectangleClient, PlaitBoard, setStrokeLinecap, isPointInPolygon, getNearestPointBetweenPointAndSegments, isPointInEllipse, drawRectangle, drawRoundRectangle, isPointInRoundRectangle, idCreator, createG, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, drawCircle, arrowPoints, createPath, drawLinearPath, distanceBetweenPointAndSegments, createMask, createRect,
|
|
1
|
+
import { PlaitElement, ACTIVE_STROKE_WIDTH, RectangleClient, PlaitBoard, setStrokeLinecap, isPointInPolygon, getNearestPointBetweenPointAndSegments, isPointInEllipse, drawRectangle, drawRoundRectangle, isPointInRoundRectangle, idCreator, createG, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, drawCircle, distanceBetweenPointAndSegment, arrowPoints, createPath, drawLinearPath, getElementById, Direction, distanceBetweenPointAndSegments, createMask, createRect, findElements, getSelectedElements, Transforms, clearSelectedElement, addSelectedElement, PlaitNode, Point, isSelectionMoving, PlaitPluginElementComponent, transformPoint, toPoint, BoardTransforms, PlaitPointerType, preventTouchMove, createForeignObject, setClipboardData, getDataFromClipboard, depthFirstRecursion, getIsRecursionFunc, getHitElements, isPolylineHitRectangle } from '@plait/core';
|
|
2
2
|
import * as i0 from '@angular/core';
|
|
3
3
|
import { Component, ChangeDetectionStrategy } from '@angular/core';
|
|
4
4
|
import { Subject } from 'rxjs';
|
|
5
|
-
import { getRectangleByPoints, getFactorByPoints,
|
|
5
|
+
import { getRectangleByPoints, getFactorByPoints, getPoints, getPointOnPolyline, getDirectionByPointOfRectangle, rotateVector90, getDirectionByVector, getDirectionFactor, Generator, normalizeShapePoints, CommonPluginElement, ActiveGenerator, WithTextPluginKey, RESIZE_HANDLE_DIAMETER, PRIMARY_COLOR, isVirtualKey, isDelete, isSpaceHotkey, isDndMode, isDrawingMode, getRectangleResizeHandleRefs, ResizeHandle, withResize, isResizingByCondition, getRatioByPoint } from '@plait/common';
|
|
6
6
|
import { Alignment, buildText, AlignEditor, TextManage, DEFAULT_FONT_SIZE, getTextFromClipboard, getTextSize } from '@plait/text';
|
|
7
7
|
import { isKeyHotkey } from 'is-hotkey';
|
|
8
8
|
import { Node } from 'slate';
|
|
@@ -15,6 +15,10 @@ var GeometryShape;
|
|
|
15
15
|
GeometryShape["roundRectangle"] = "roundRectangle";
|
|
16
16
|
GeometryShape["parallelogram"] = "parallelogram";
|
|
17
17
|
GeometryShape["text"] = "text";
|
|
18
|
+
GeometryShape["triangle"] = "triangle";
|
|
19
|
+
GeometryShape["leftArrow"] = "leftArrow";
|
|
20
|
+
GeometryShape["trapezoid"] = "trapezoid";
|
|
21
|
+
GeometryShape["rightArrow"] = "rightArrow";
|
|
18
22
|
})(GeometryShape || (GeometryShape = {}));
|
|
19
23
|
const PlaitGeometry = {
|
|
20
24
|
getTextEditor(element) {
|
|
@@ -62,11 +66,19 @@ const PlaitLine = {
|
|
|
62
66
|
}
|
|
63
67
|
throw new Error('can not get correctly component in get text editor');
|
|
64
68
|
},
|
|
69
|
+
isSourceMarkOrTargetMark(line, markType, handleKey) {
|
|
70
|
+
if (handleKey === LineHandleKey.source) {
|
|
71
|
+
return line.source.marker === markType;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return line.target.marker === markType;
|
|
75
|
+
}
|
|
76
|
+
},
|
|
65
77
|
isSourceMark(line, markType) {
|
|
66
|
-
return line.source
|
|
78
|
+
return PlaitLine.isSourceMarkOrTargetMark(line, markType, LineHandleKey.source);
|
|
67
79
|
},
|
|
68
80
|
isTargetMark(line, markType) {
|
|
69
|
-
return line.target
|
|
81
|
+
return PlaitLine.isSourceMarkOrTargetMark(line, markType, LineHandleKey.target);
|
|
70
82
|
},
|
|
71
83
|
isBoundElementOfSource(line, element) {
|
|
72
84
|
return line.source.boundId === element.id;
|
|
@@ -139,6 +151,10 @@ var DrawPointerType;
|
|
|
139
151
|
DrawPointerType["roundRectangle"] = "roundRectangle";
|
|
140
152
|
DrawPointerType["parallelogram"] = "parallelogram";
|
|
141
153
|
DrawPointerType["ellipse"] = "ellipse";
|
|
154
|
+
DrawPointerType["triangle"] = "triangle";
|
|
155
|
+
DrawPointerType["leftArrow"] = "leftArrow";
|
|
156
|
+
DrawPointerType["trapezoid"] = "trapezoid";
|
|
157
|
+
DrawPointerType["rightArrow"] = "rightArrow";
|
|
142
158
|
})(DrawPointerType || (DrawPointerType = {}));
|
|
143
159
|
const GeometryPointer = [
|
|
144
160
|
DrawPointerType.rectangle,
|
|
@@ -146,7 +162,11 @@ const GeometryPointer = [
|
|
|
146
162
|
DrawPointerType.diamond,
|
|
147
163
|
DrawPointerType.ellipse,
|
|
148
164
|
DrawPointerType.parallelogram,
|
|
149
|
-
DrawPointerType.roundRectangle
|
|
165
|
+
DrawPointerType.roundRectangle,
|
|
166
|
+
DrawPointerType.triangle,
|
|
167
|
+
DrawPointerType.leftArrow,
|
|
168
|
+
DrawPointerType.trapezoid,
|
|
169
|
+
DrawPointerType.rightArrow
|
|
150
170
|
];
|
|
151
171
|
|
|
152
172
|
const getStrokeWidthByElement = (element) => {
|
|
@@ -183,9 +203,16 @@ const DiamondEngine = {
|
|
|
183
203
|
const controlPoints = RectangleClient.getEdgeCenterPoints(rectangle);
|
|
184
204
|
return isPointInPolygon(point, controlPoints);
|
|
185
205
|
},
|
|
206
|
+
getCornerPoints(rectangle) {
|
|
207
|
+
return RectangleClient.getEdgeCenterPoints(rectangle);
|
|
208
|
+
},
|
|
186
209
|
getNearestPoint(rectangle, point) {
|
|
187
|
-
|
|
188
|
-
|
|
210
|
+
return getNearestPointBetweenPointAndSegments(point, DiamondEngine.getCornerPoints(rectangle));
|
|
211
|
+
},
|
|
212
|
+
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
213
|
+
const corners = DiamondEngine.getCornerPoints(rectangle);
|
|
214
|
+
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
215
|
+
return getEdgeOnPolygonByPoint(corners, point);
|
|
189
216
|
},
|
|
190
217
|
getConnectorPoints(rectangle) {
|
|
191
218
|
return RectangleClient.getEdgeCenterPoints(rectangle);
|
|
@@ -202,10 +229,22 @@ const EllipseEngine = {
|
|
|
202
229
|
const centerPoint = [rectangle.x + rectangle.width / 2, rectangle.y + rectangle.height / 2];
|
|
203
230
|
return isPointInEllipse(point, centerPoint, rectangle.width / 2, rectangle.height / 2);
|
|
204
231
|
},
|
|
232
|
+
getCornerPoints(rectangle) {
|
|
233
|
+
return RectangleClient.getEdgeCenterPoints(rectangle);
|
|
234
|
+
},
|
|
205
235
|
getNearestPoint(rectangle, point) {
|
|
206
236
|
const centerPoint = [rectangle.x + rectangle.width / 2, rectangle.y + rectangle.height / 2];
|
|
207
237
|
return getNearestPointBetweenPointAndEllipse(point, centerPoint, rectangle.width / 2, rectangle.height / 2);
|
|
208
238
|
},
|
|
239
|
+
getTangentVectorByConnectionPoint(rectangle, pointOfRectangle) {
|
|
240
|
+
const connectionPoint = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
241
|
+
const centerPoint = [rectangle.x + rectangle.width / 2, rectangle.y + rectangle.height / 2];
|
|
242
|
+
const point = [connectionPoint[0] - centerPoint[0], -(connectionPoint[1] - centerPoint[1])];
|
|
243
|
+
const a = rectangle.width / 2;
|
|
244
|
+
const b = rectangle.height / 2;
|
|
245
|
+
const slope = getTangentSlope(point[0], point[1], a, b);
|
|
246
|
+
return getVectorBySlope(point[0], point[1], slope);
|
|
247
|
+
},
|
|
209
248
|
getConnectorPoints(rectangle) {
|
|
210
249
|
return RectangleClient.getEdgeCenterPoints(rectangle);
|
|
211
250
|
}
|
|
@@ -245,29 +284,104 @@ function getNearestPointBetweenPointAndEllipse(point, center, rx, ry, rotation =
|
|
|
245
284
|
const signY = point[1] > center[1] ? 1 : -1;
|
|
246
285
|
return [center[0] + a * tx * signX, center[1] + b * ty * signY];
|
|
247
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* the result of slope is based on Cartesian coordinate system
|
|
289
|
+
* x, y are based on the position in the Cartesian coordinate system
|
|
290
|
+
*/
|
|
291
|
+
function getTangentSlope(x, y, a, b) {
|
|
292
|
+
const k = (-b * b * x) / (a * a * y);
|
|
293
|
+
return k;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* x, y are based on the position in the Cartesian coordinate system
|
|
297
|
+
*/
|
|
298
|
+
function getVectorBySlope(x, y, slope) {
|
|
299
|
+
const deltaX = 30;
|
|
300
|
+
const deltaY = -slope * deltaX;
|
|
301
|
+
let start = [0 - deltaX, 0 - deltaY];
|
|
302
|
+
let end = [0 + deltaX, 0 + deltaY];
|
|
303
|
+
// y < 0 acts on the lower half of the x-axis, with the starting point at the top and the end point at the bottom.
|
|
304
|
+
if (y < 0) {
|
|
305
|
+
const temp = start;
|
|
306
|
+
start = end;
|
|
307
|
+
end = temp;
|
|
308
|
+
}
|
|
309
|
+
const vector = [end[0] - start[0], end[1] - start[1]];
|
|
310
|
+
return vector;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const LeftArrowEngine = {
|
|
314
|
+
draw(board, rectangle, options) {
|
|
315
|
+
const points = getLeftArrowPoints(rectangle);
|
|
316
|
+
const rs = PlaitBoard.getRoughSVG(board);
|
|
317
|
+
const polygon = rs.polygon(points, { ...options, fillStyle: 'solid' });
|
|
318
|
+
setStrokeLinecap(polygon, 'round');
|
|
319
|
+
return polygon;
|
|
320
|
+
},
|
|
321
|
+
getCornerPoints(rectangle) {
|
|
322
|
+
return getLeftArrowPoints(rectangle);
|
|
323
|
+
},
|
|
324
|
+
isHit(rectangle, point) {
|
|
325
|
+
const points = getLeftArrowPoints(rectangle);
|
|
326
|
+
return isPointInPolygon(point, points);
|
|
327
|
+
},
|
|
328
|
+
getNearestPoint(rectangle, point) {
|
|
329
|
+
const cornerPoints = getLeftArrowPoints(rectangle);
|
|
330
|
+
return getNearestPointBetweenPointAndSegments(point, cornerPoints);
|
|
331
|
+
},
|
|
332
|
+
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
333
|
+
const corners = getLeftArrowPoints(rectangle);
|
|
334
|
+
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
335
|
+
return getEdgeOnPolygonByPoint(corners, point);
|
|
336
|
+
},
|
|
337
|
+
getConnectorPoints(rectangle) {
|
|
338
|
+
return [
|
|
339
|
+
[rectangle.x, rectangle.y + rectangle.height / 2],
|
|
340
|
+
[rectangle.x + rectangle.width, rectangle.y + rectangle.height / 2]
|
|
341
|
+
];
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
const getLeftArrowPoints = (rectangle) => {
|
|
345
|
+
return [
|
|
346
|
+
[rectangle.x, rectangle.y + rectangle.height / 2],
|
|
347
|
+
[rectangle.x + rectangle.width * 0.32, rectangle.y],
|
|
348
|
+
[rectangle.x + rectangle.width * 0.32, rectangle.y + rectangle.height * 0.2],
|
|
349
|
+
[rectangle.x + rectangle.width, rectangle.y + rectangle.height * 0.2],
|
|
350
|
+
[rectangle.x + rectangle.width, rectangle.y + rectangle.height * 0.8],
|
|
351
|
+
[rectangle.x + rectangle.width * 0.32, rectangle.y + rectangle.height * 0.8],
|
|
352
|
+
[rectangle.x + rectangle.width * 0.32, rectangle.y + rectangle.height]
|
|
353
|
+
];
|
|
354
|
+
};
|
|
248
355
|
|
|
249
356
|
const ParallelogramEngine = {
|
|
250
357
|
draw(board, rectangle, options) {
|
|
251
|
-
const points =
|
|
358
|
+
const points = getParallelogramCornerPoints(rectangle);
|
|
252
359
|
const rs = PlaitBoard.getRoughSVG(board);
|
|
253
360
|
const polygon = rs.polygon(points, { ...options, fillStyle: 'solid' });
|
|
254
361
|
setStrokeLinecap(polygon, 'round');
|
|
255
362
|
return polygon;
|
|
256
363
|
},
|
|
257
364
|
isHit(rectangle, point) {
|
|
258
|
-
const parallelogramPoints =
|
|
365
|
+
const parallelogramPoints = getParallelogramCornerPoints(rectangle);
|
|
259
366
|
return isPointInPolygon(point, parallelogramPoints);
|
|
260
367
|
},
|
|
368
|
+
getCornerPoints(rectangle) {
|
|
369
|
+
return getParallelogramCornerPoints(rectangle);
|
|
370
|
+
},
|
|
261
371
|
getNearestPoint(rectangle, point) {
|
|
262
|
-
|
|
263
|
-
|
|
372
|
+
return getNearestPointBetweenPointAndSegments(point, ParallelogramEngine.getCornerPoints(rectangle));
|
|
373
|
+
},
|
|
374
|
+
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
375
|
+
const corners = getParallelogramCornerPoints(rectangle);
|
|
376
|
+
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
377
|
+
return getEdgeOnPolygonByPoint(corners, point);
|
|
264
378
|
},
|
|
265
379
|
getConnectorPoints(rectangle) {
|
|
266
|
-
const cornerPoints =
|
|
380
|
+
const cornerPoints = getParallelogramCornerPoints(rectangle);
|
|
267
381
|
return getCenterPointsOnPolygon(cornerPoints);
|
|
268
382
|
}
|
|
269
383
|
};
|
|
270
|
-
const
|
|
384
|
+
const getParallelogramCornerPoints = (rectangle) => {
|
|
271
385
|
return [
|
|
272
386
|
[rectangle.x + rectangle.width / 4, rectangle.y],
|
|
273
387
|
[rectangle.x + rectangle.width, rectangle.y],
|
|
@@ -284,15 +398,65 @@ const RectangleEngine = {
|
|
|
284
398
|
const rangeRectangle = RectangleClient.toRectangleClient([point, point]);
|
|
285
399
|
return RectangleClient.isHit(rectangle, rangeRectangle);
|
|
286
400
|
},
|
|
401
|
+
getCornerPoints(rectangle) {
|
|
402
|
+
return RectangleClient.getCornerPoints(rectangle);
|
|
403
|
+
},
|
|
287
404
|
getNearestPoint(rectangle, point) {
|
|
288
|
-
|
|
289
|
-
|
|
405
|
+
return getNearestPointBetweenPointAndSegments(point, RectangleEngine.getCornerPoints(rectangle));
|
|
406
|
+
},
|
|
407
|
+
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
408
|
+
const corners = RectangleEngine.getCornerPoints(rectangle);
|
|
409
|
+
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
410
|
+
return getEdgeOnPolygonByPoint(corners, point);
|
|
290
411
|
},
|
|
291
412
|
getConnectorPoints(rectangle) {
|
|
292
413
|
return RectangleClient.getEdgeCenterPoints(rectangle);
|
|
293
414
|
}
|
|
294
415
|
};
|
|
295
416
|
|
|
417
|
+
const RightArrowEngine = {
|
|
418
|
+
draw(board, rectangle, options) {
|
|
419
|
+
const points = getRightArrowPoints(rectangle);
|
|
420
|
+
const rs = PlaitBoard.getRoughSVG(board);
|
|
421
|
+
const polygon = rs.polygon(points, { ...options, fillStyle: 'solid' });
|
|
422
|
+
setStrokeLinecap(polygon, 'round');
|
|
423
|
+
return polygon;
|
|
424
|
+
},
|
|
425
|
+
getCornerPoints(rectangle) {
|
|
426
|
+
return getRightArrowPoints(rectangle);
|
|
427
|
+
},
|
|
428
|
+
isHit(rectangle, point) {
|
|
429
|
+
const points = getRightArrowPoints(rectangle);
|
|
430
|
+
return isPointInPolygon(point, points);
|
|
431
|
+
},
|
|
432
|
+
getNearestPoint(rectangle, point) {
|
|
433
|
+
const cornerPoints = getRightArrowPoints(rectangle);
|
|
434
|
+
return getNearestPointBetweenPointAndSegments(point, cornerPoints);
|
|
435
|
+
},
|
|
436
|
+
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
437
|
+
const corners = getRightArrowPoints(rectangle);
|
|
438
|
+
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
439
|
+
return getEdgeOnPolygonByPoint(corners, point);
|
|
440
|
+
},
|
|
441
|
+
getConnectorPoints(rectangle) {
|
|
442
|
+
return [
|
|
443
|
+
[rectangle.x, rectangle.y + rectangle.height / 2],
|
|
444
|
+
[rectangle.x + rectangle.width, rectangle.y + rectangle.height / 2]
|
|
445
|
+
];
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
const getRightArrowPoints = (rectangle) => {
|
|
449
|
+
return [
|
|
450
|
+
[rectangle.x, rectangle.y + rectangle.height * 0.2],
|
|
451
|
+
[rectangle.x + rectangle.width * 0.68, rectangle.y + rectangle.height * 0.2],
|
|
452
|
+
[rectangle.x + rectangle.width * 0.68, rectangle.y],
|
|
453
|
+
[rectangle.x + rectangle.width, rectangle.y + rectangle.height / 2],
|
|
454
|
+
[rectangle.x + rectangle.width * 0.68, rectangle.y + rectangle.height],
|
|
455
|
+
[rectangle.x + rectangle.width * 0.68, rectangle.y + rectangle.height * 0.8],
|
|
456
|
+
[rectangle.x, rectangle.y + rectangle.height * 0.8]
|
|
457
|
+
];
|
|
458
|
+
};
|
|
459
|
+
|
|
296
460
|
const RoundRectangleEngine = {
|
|
297
461
|
draw(board, rectangle, options) {
|
|
298
462
|
return drawRoundRectangle(PlaitBoard.getRoughSVG(board), rectangle.x, rectangle.y, rectangle.x + rectangle.width, rectangle.y + rectangle.height, { ...options, fillStyle: 'solid' }, false, getRoundRectangleRadius(rectangle));
|
|
@@ -300,9 +464,17 @@ const RoundRectangleEngine = {
|
|
|
300
464
|
isHit(rectangle, point) {
|
|
301
465
|
return isPointInRoundRectangle(point, rectangle, getRoundRectangleRadius(rectangle));
|
|
302
466
|
},
|
|
467
|
+
getCornerPoints(rectangle) {
|
|
468
|
+
return RectangleClient.getCornerPoints(rectangle);
|
|
469
|
+
},
|
|
303
470
|
getNearestPoint(rectangle, point) {
|
|
304
471
|
return getNearestPointBetweenPointAndRoundRectangle(point, rectangle, getRoundRectangleRadius(rectangle));
|
|
305
472
|
},
|
|
473
|
+
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
474
|
+
const corners = RectangleEngine.getCornerPoints(rectangle);
|
|
475
|
+
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
476
|
+
return getEdgeOnPolygonByPoint(corners, point);
|
|
477
|
+
},
|
|
306
478
|
getConnectorPoints(rectangle) {
|
|
307
479
|
return RectangleClient.getEdgeCenterPoints(rectangle);
|
|
308
480
|
}
|
|
@@ -340,13 +512,93 @@ function getNearestPointBetweenPointAndRoundRectangle(point, rectangle, radius)
|
|
|
340
512
|
return result;
|
|
341
513
|
}
|
|
342
514
|
|
|
515
|
+
const TrapezoidEngine = {
|
|
516
|
+
draw(board, rectangle, options) {
|
|
517
|
+
const points = getTrapezoidPoints(rectangle);
|
|
518
|
+
const rs = PlaitBoard.getRoughSVG(board);
|
|
519
|
+
const polygon = rs.polygon(points, { ...options, fillStyle: 'solid' });
|
|
520
|
+
setStrokeLinecap(polygon, 'round');
|
|
521
|
+
return polygon;
|
|
522
|
+
},
|
|
523
|
+
isHit(rectangle, point) {
|
|
524
|
+
const points = getTrapezoidPoints(rectangle);
|
|
525
|
+
return isPointInPolygon(point, points);
|
|
526
|
+
},
|
|
527
|
+
getNearestPoint(rectangle, point) {
|
|
528
|
+
const cornerPoints = getTrapezoidPoints(rectangle);
|
|
529
|
+
return getNearestPointBetweenPointAndSegments(point, cornerPoints);
|
|
530
|
+
},
|
|
531
|
+
getConnectorPoints(rectangle) {
|
|
532
|
+
const points = getTrapezoidPoints(rectangle);
|
|
533
|
+
return getCenterPointsOnPolygon(points);
|
|
534
|
+
},
|
|
535
|
+
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
536
|
+
const corners = getTrapezoidPoints(rectangle);
|
|
537
|
+
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
538
|
+
return getEdgeOnPolygonByPoint(corners, point);
|
|
539
|
+
},
|
|
540
|
+
getCornerPoints(rectangle) {
|
|
541
|
+
return getTrapezoidPoints(rectangle);
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
const getTrapezoidPoints = (rectangle) => {
|
|
545
|
+
return [
|
|
546
|
+
[rectangle.x + rectangle.width * 0.15, rectangle.y],
|
|
547
|
+
[rectangle.x + rectangle.width * 0.85, rectangle.y],
|
|
548
|
+
[rectangle.x + rectangle.width, rectangle.y + rectangle.height],
|
|
549
|
+
[rectangle.x, rectangle.y + rectangle.height]
|
|
550
|
+
];
|
|
551
|
+
};
|
|
552
|
+
|
|
553
|
+
const TriangleEngine = {
|
|
554
|
+
draw(board, rectangle, options) {
|
|
555
|
+
const points = getTrianglePoints(rectangle);
|
|
556
|
+
const rs = PlaitBoard.getRoughSVG(board);
|
|
557
|
+
const polygon = rs.polygon(points, { ...options, fillStyle: 'solid' });
|
|
558
|
+
setStrokeLinecap(polygon, 'round');
|
|
559
|
+
return polygon;
|
|
560
|
+
},
|
|
561
|
+
isHit(rectangle, point) {
|
|
562
|
+
const points = getTrianglePoints(rectangle);
|
|
563
|
+
return isPointInPolygon(point, points);
|
|
564
|
+
},
|
|
565
|
+
getNearestPoint(rectangle, point) {
|
|
566
|
+
const cornerPoints = getTrianglePoints(rectangle);
|
|
567
|
+
return getNearestPointBetweenPointAndSegments(point, cornerPoints);
|
|
568
|
+
},
|
|
569
|
+
getConnectorPoints(rectangle) {
|
|
570
|
+
const cornerPoints = getTrianglePoints(rectangle);
|
|
571
|
+
const lineCenterPoints = getCenterPointsOnPolygon(cornerPoints);
|
|
572
|
+
return [...lineCenterPoints, ...cornerPoints];
|
|
573
|
+
},
|
|
574
|
+
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
575
|
+
const corners = getTrianglePoints(rectangle);
|
|
576
|
+
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
577
|
+
return getEdgeOnPolygonByPoint(corners, point);
|
|
578
|
+
},
|
|
579
|
+
getCornerPoints(rectangle) {
|
|
580
|
+
return getTrianglePoints(rectangle);
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
const getTrianglePoints = (rectangle) => {
|
|
584
|
+
return [
|
|
585
|
+
[rectangle.x + rectangle.width / 2, rectangle.y],
|
|
586
|
+
[rectangle.x + rectangle.width, rectangle.y + rectangle.height],
|
|
587
|
+
[rectangle.x, rectangle.y + rectangle.height]
|
|
588
|
+
];
|
|
589
|
+
};
|
|
590
|
+
|
|
343
591
|
const ShapeEngineMap = {
|
|
344
592
|
[GeometryShape.rectangle]: RectangleEngine,
|
|
345
593
|
[GeometryShape.diamond]: DiamondEngine,
|
|
346
594
|
[GeometryShape.ellipse]: EllipseEngine,
|
|
347
595
|
[GeometryShape.parallelogram]: ParallelogramEngine,
|
|
348
596
|
[GeometryShape.roundRectangle]: RoundRectangleEngine,
|
|
349
|
-
[GeometryShape.text]: RectangleEngine
|
|
597
|
+
[GeometryShape.text]: RectangleEngine,
|
|
598
|
+
[GeometryShape.triangle]: TriangleEngine,
|
|
599
|
+
[GeometryShape.leftArrow]: LeftArrowEngine,
|
|
600
|
+
[GeometryShape.trapezoid]: TrapezoidEngine,
|
|
601
|
+
[GeometryShape.rightArrow]: RightArrowEngine
|
|
350
602
|
};
|
|
351
603
|
const getEngine = (shape) => {
|
|
352
604
|
return ShapeEngineMap[shape];
|
|
@@ -428,6 +680,17 @@ const getCenterPointsOnPolygon = (points) => {
|
|
|
428
680
|
}
|
|
429
681
|
return centerPoint;
|
|
430
682
|
};
|
|
683
|
+
const getEdgeOnPolygonByPoint = (corners, point) => {
|
|
684
|
+
for (let index = 1; index <= corners.length; index++) {
|
|
685
|
+
let start = corners[index - 1];
|
|
686
|
+
let end = index === corners.length ? corners[0] : corners[index];
|
|
687
|
+
const distance = distanceBetweenPointAndSegment(point[0], point[1], start[0], start[1], end[0], end[1]);
|
|
688
|
+
if (distance < 1) {
|
|
689
|
+
return [start, end];
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
return null;
|
|
693
|
+
};
|
|
431
694
|
|
|
432
695
|
const drawLineArrow = (element, points, options) => {
|
|
433
696
|
const arrowG = createG();
|
|
@@ -531,21 +794,48 @@ const getLinePoints = (board, element) => {
|
|
|
531
794
|
return element.shape === LineShape.elbow ? getElbowPoints(board, element) : getStraightPoints(board, element);
|
|
532
795
|
};
|
|
533
796
|
const getStraightPoints = (board, element) => {
|
|
534
|
-
return
|
|
797
|
+
return getLineHandlePoints(board, element);
|
|
798
|
+
};
|
|
799
|
+
const getLineHandlePoints = (board, element) => {
|
|
800
|
+
const handleRefPair = getLineHandleRefPair(board, element);
|
|
801
|
+
return [handleRefPair.source.point, handleRefPair.target.point];
|
|
802
|
+
};
|
|
803
|
+
const getLineHandleRefPair = (board, element) => {
|
|
804
|
+
const strokeWidth = getStrokeWidthByElement(element);
|
|
805
|
+
const sourceBoundElement = element.source.boundId ? getElementById(board, element.source.boundId) : undefined;
|
|
806
|
+
const targetBoundElement = element.target.boundId ? getElementById(board, element.target.boundId) : undefined;
|
|
807
|
+
let sourcePoint = sourceBoundElement ? getConnectionPoint(sourceBoundElement, element.source.connection) : element.points[0];
|
|
808
|
+
let targetPoint = targetBoundElement
|
|
809
|
+
? getConnectionPoint(targetBoundElement, element.target.connection)
|
|
810
|
+
: element.points[element.points.length - 1];
|
|
811
|
+
let sourceDirection = sourcePoint[0] < targetPoint[0] ? Direction.right : Direction.left;
|
|
812
|
+
let targetDirection = sourcePoint[0] < targetPoint[0] ? Direction.left : Direction.right;
|
|
813
|
+
const sourceHandleRef = { key: LineHandleKey.source, point: sourcePoint, direction: sourceDirection };
|
|
814
|
+
const targetHandleRef = { key: LineHandleKey.target, point: targetPoint, direction: targetDirection };
|
|
815
|
+
if (sourceBoundElement) {
|
|
816
|
+
const connectionOffset = PlaitLine.isSourceMarkOrTargetMark(element, LineMarkerType.none, LineHandleKey.source) ? 0 : strokeWidth;
|
|
817
|
+
const direction = getDirectionByBoundElementAndConnection(board, sourceBoundElement, element.source.connection);
|
|
818
|
+
sourceDirection = direction ? direction : sourceDirection;
|
|
819
|
+
sourcePoint = getConnectionPoint(sourceBoundElement, element.source.connection, sourceDirection, connectionOffset);
|
|
820
|
+
sourceHandleRef.boundElement = sourceBoundElement;
|
|
821
|
+
sourceHandleRef.direction = sourceDirection;
|
|
822
|
+
sourceHandleRef.point = sourcePoint;
|
|
823
|
+
}
|
|
824
|
+
if (targetBoundElement) {
|
|
825
|
+
const connectionOffset = PlaitLine.isSourceMarkOrTargetMark(element, LineMarkerType.none, LineHandleKey.target) ? 0 : strokeWidth;
|
|
826
|
+
const direction = getDirectionByBoundElementAndConnection(board, targetBoundElement, element.target.connection);
|
|
827
|
+
targetDirection = direction ? direction : targetDirection;
|
|
828
|
+
targetPoint = getConnectionPoint(targetBoundElement, element.target.connection, targetDirection, connectionOffset);
|
|
829
|
+
targetHandleRef.boundElement = sourceBoundElement;
|
|
830
|
+
targetHandleRef.direction = targetDirection;
|
|
831
|
+
targetHandleRef.point = targetPoint;
|
|
832
|
+
}
|
|
833
|
+
return { source: sourceHandleRef, target: targetHandleRef };
|
|
535
834
|
};
|
|
536
835
|
const getElbowPoints = (board, element) => {
|
|
537
836
|
if (element.points.length === 2) {
|
|
538
|
-
const
|
|
539
|
-
const
|
|
540
|
-
let sourceDirection = source[0] < target[0] ? Direction.right : Direction.left;
|
|
541
|
-
let targetDirection = source[0] < target[0] ? Direction.left : Direction.right;
|
|
542
|
-
if (element.source.connection) {
|
|
543
|
-
sourceDirection = getDirectionByPoint(element.source.connection, sourceDirection);
|
|
544
|
-
}
|
|
545
|
-
if (element.target.connection) {
|
|
546
|
-
targetDirection = getDirectionByPoint(element.target.connection, targetDirection);
|
|
547
|
-
}
|
|
548
|
-
const points = getPoints(source, sourceDirection, target, targetDirection, 30);
|
|
837
|
+
const handleRefPair = getLineHandleRefPair(board, element);
|
|
838
|
+
const points = getPoints(handleRefPair.source.point, handleRefPair.source.direction, handleRefPair.target.point, handleRefPair.target.direction, 30);
|
|
549
839
|
return points;
|
|
550
840
|
}
|
|
551
841
|
return element.points;
|
|
@@ -614,33 +904,42 @@ function drawMask(board, element, id) {
|
|
|
614
904
|
maskTargetFillRect.setAttribute('opacity', '0');
|
|
615
905
|
return { mask, maskTargetFillRect };
|
|
616
906
|
}
|
|
617
|
-
const
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
return
|
|
907
|
+
const getDirectionByBoundElementAndConnection = (board, boundElement, connection) => {
|
|
908
|
+
const rectangle = getRectangleByPoints(boundElement.points);
|
|
909
|
+
const engine = getEngine(boundElement.shape);
|
|
910
|
+
const direction = getDirectionByPointOfRectangle(connection);
|
|
911
|
+
if (direction) {
|
|
912
|
+
return direction;
|
|
623
913
|
}
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
914
|
+
if (engine.getEdgeByConnectionPoint) {
|
|
915
|
+
const edge = engine.getEdgeByConnectionPoint(rectangle, connection);
|
|
916
|
+
if (edge) {
|
|
917
|
+
const vector = [edge[1][0] - edge[0][0], edge[1][1] - edge[0][1]];
|
|
918
|
+
const vector90 = rotateVector90(vector);
|
|
919
|
+
const direction = getDirectionByVector(vector90);
|
|
920
|
+
return direction;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
if (engine.getTangentVectorByConnectionPoint) {
|
|
924
|
+
const vector = engine.getTangentVectorByConnectionPoint(rectangle, connection);
|
|
925
|
+
if (vector) {
|
|
926
|
+
const vector90 = rotateVector90(vector);
|
|
927
|
+
const direction = getDirectionByVector(vector90);
|
|
928
|
+
return direction;
|
|
929
|
+
}
|
|
634
930
|
}
|
|
635
|
-
return
|
|
931
|
+
return null;
|
|
636
932
|
};
|
|
637
|
-
const getConnectionPoint = (geometry, connection,
|
|
933
|
+
const getConnectionPoint = (geometry, connection, direction, delta) => {
|
|
638
934
|
const rectangle = getRectangleByPoints(geometry.points);
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
935
|
+
if (direction && delta) {
|
|
936
|
+
const directionFactor = getDirectionFactor(direction);
|
|
937
|
+
const point = RectangleClient.getConnectionPoint(rectangle, connection);
|
|
938
|
+
return [point[0] + directionFactor.x * delta, point[1] + directionFactor.y * delta];
|
|
939
|
+
}
|
|
940
|
+
else {
|
|
941
|
+
return RectangleClient.getConnectionPoint(rectangle, connection);
|
|
942
|
+
}
|
|
644
943
|
};
|
|
645
944
|
const transformPointToConnection = (board, point, hitElement) => {
|
|
646
945
|
let rectangle = getRectangleByPoints(hitElement.points);
|
|
@@ -923,10 +1222,10 @@ class GeometryComponent extends CommonPluginElement {
|
|
|
923
1222
|
this.destroy$.next();
|
|
924
1223
|
this.destroy$.complete();
|
|
925
1224
|
}
|
|
1225
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: GeometryComponent, deps: [{ token: i0.ViewContainerRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
1226
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.3", type: GeometryComponent, selector: "plait-draw-geometry", usesInheritance: true, ngImport: i0, template: ``, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
926
1227
|
}
|
|
927
|
-
|
|
928
|
-
GeometryComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.2", type: GeometryComponent, selector: "plait-draw-geometry", usesInheritance: true, ngImport: i0, template: ``, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
929
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: GeometryComponent, decorators: [{
|
|
1228
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: GeometryComponent, decorators: [{
|
|
930
1229
|
type: Component,
|
|
931
1230
|
args: [{
|
|
932
1231
|
selector: 'plait-draw-geometry',
|
|
@@ -955,6 +1254,10 @@ class LineShapeGenerator extends Generator {
|
|
|
955
1254
|
}
|
|
956
1255
|
|
|
957
1256
|
class LineActiveGenerator extends Generator {
|
|
1257
|
+
constructor() {
|
|
1258
|
+
super(...arguments);
|
|
1259
|
+
this.hasResizeHandle = false;
|
|
1260
|
+
}
|
|
958
1261
|
canDraw(element, data) {
|
|
959
1262
|
if (data.selected) {
|
|
960
1263
|
return true;
|
|
@@ -965,24 +1268,34 @@ class LineActiveGenerator extends Generator {
|
|
|
965
1268
|
}
|
|
966
1269
|
baseDraw(element, data) {
|
|
967
1270
|
const activeG = createG();
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
1271
|
+
if (this.hasResizeHandle) {
|
|
1272
|
+
activeG.classList.add('active');
|
|
1273
|
+
activeG.classList.add('line-handle');
|
|
1274
|
+
const [sourcePoint, targetPoint] = getLineHandlePoints(this.board, element);
|
|
1275
|
+
const sourceCircle = drawCircle(PlaitBoard.getRoughSVG(this.board), sourcePoint, RESIZE_HANDLE_DIAMETER, {
|
|
1276
|
+
stroke: '#999999',
|
|
1277
|
+
strokeWidth: 1,
|
|
1278
|
+
fill: '#FFF',
|
|
1279
|
+
fillStyle: 'solid'
|
|
1280
|
+
});
|
|
1281
|
+
const targetCircle = drawCircle(PlaitBoard.getRoughSVG(this.board), targetPoint, RESIZE_HANDLE_DIAMETER, {
|
|
1282
|
+
stroke: '#999999',
|
|
1283
|
+
strokeWidth: 1,
|
|
1284
|
+
fill: '#FFF',
|
|
1285
|
+
fillStyle: 'solid'
|
|
1286
|
+
});
|
|
1287
|
+
activeG.appendChild(targetCircle);
|
|
1288
|
+
activeG.appendChild(sourceCircle);
|
|
1289
|
+
}
|
|
1290
|
+
else {
|
|
1291
|
+
const points = getLinePoints(this.board, element);
|
|
1292
|
+
const activeRectangle = getRectangleByPoints(points);
|
|
1293
|
+
const strokeG = drawRectangle(this.board, activeRectangle, {
|
|
1294
|
+
stroke: PRIMARY_COLOR,
|
|
1295
|
+
strokeWidth: DefaultGeometryActiveStyle.selectionStrokeWidth
|
|
1296
|
+
});
|
|
1297
|
+
activeG.appendChild(strokeG);
|
|
1298
|
+
}
|
|
986
1299
|
return activeG;
|
|
987
1300
|
}
|
|
988
1301
|
}
|
|
@@ -1041,11 +1354,18 @@ class LineComponent extends PlaitPluginElementComponent {
|
|
|
1041
1354
|
this.updateTextRectangle();
|
|
1042
1355
|
return;
|
|
1043
1356
|
}
|
|
1044
|
-
|
|
1045
|
-
|
|
1357
|
+
if (!isSelectionMoving(this.board)) {
|
|
1358
|
+
this.activeGenerator.hasResizeHandle = this.hasResizeHandle();
|
|
1046
1359
|
this.activeGenerator.draw(this.element, PlaitBoard.getElementActiveHost(this.board), { selected: this.selected });
|
|
1047
1360
|
}
|
|
1048
1361
|
}
|
|
1362
|
+
hasResizeHandle() {
|
|
1363
|
+
const selectedElements = getSelectedElements(this.board);
|
|
1364
|
+
if (PlaitBoard.hasBeenTextEditing(this.board) && PlaitDrawElement.isText(this.element)) {
|
|
1365
|
+
return false;
|
|
1366
|
+
}
|
|
1367
|
+
return selectedElements.length === 1 && !isSelectionMoving(this.board);
|
|
1368
|
+
}
|
|
1049
1369
|
initializeTextManages() {
|
|
1050
1370
|
if (this.element.texts?.length) {
|
|
1051
1371
|
this.element.texts.forEach((text, index) => {
|
|
@@ -1117,10 +1437,10 @@ class LineComponent extends PlaitPluginElementComponent {
|
|
|
1117
1437
|
this.destroy$.next();
|
|
1118
1438
|
this.destroy$.complete();
|
|
1119
1439
|
}
|
|
1440
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: LineComponent, deps: [{ token: i0.ViewContainerRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
1441
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.3", type: LineComponent, selector: "plait-draw-line", usesInheritance: true, ngImport: i0, template: ``, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
1120
1442
|
}
|
|
1121
|
-
|
|
1122
|
-
LineComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.2", type: LineComponent, selector: "plait-draw-line", usesInheritance: true, ngImport: i0, template: ``, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
1123
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: LineComponent, decorators: [{
|
|
1443
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: LineComponent, decorators: [{
|
|
1124
1444
|
type: Component,
|
|
1125
1445
|
args: [{
|
|
1126
1446
|
selector: 'plait-draw-line',
|
|
@@ -1358,6 +1678,7 @@ const insertClipboardData = (board, elements, startPoint) => {
|
|
|
1358
1678
|
element.points = element.points.map(point => [startPoint[0] + point[0], startPoint[1] + point[1]]);
|
|
1359
1679
|
Transforms.insertNode(board, element, [board.children.length]);
|
|
1360
1680
|
});
|
|
1681
|
+
Transforms.addSelectionWithTemporaryElements(board, elements);
|
|
1361
1682
|
};
|
|
1362
1683
|
|
|
1363
1684
|
const withDrawFragment = (baseBoard) => {
|
|
@@ -1366,21 +1687,26 @@ const withDrawFragment = (baseBoard) => {
|
|
|
1366
1687
|
board.getDeletedFragment = (data) => {
|
|
1367
1688
|
const drawElements = getSelectedDrawElements(board);
|
|
1368
1689
|
if (drawElements.length) {
|
|
1369
|
-
const lines = getBoardLines(board);
|
|
1370
1690
|
const geometryElements = drawElements.filter(value => PlaitDrawElement.isGeometry(value));
|
|
1371
1691
|
const lineElements = drawElements.filter(value => PlaitDrawElement.isLine(value));
|
|
1372
|
-
const boundLineElements =
|
|
1692
|
+
const boundLineElements = getBoundedLineElements(board, geometryElements).filter(line => !lineElements.includes(line));
|
|
1373
1693
|
data.push(...[...geometryElements, ...lineElements, ...boundLineElements.filter(line => !lineElements.includes(line))]);
|
|
1374
1694
|
}
|
|
1375
1695
|
return getDeletedFragment(data);
|
|
1376
1696
|
};
|
|
1377
|
-
board.setFragment = (data, rectangle) => {
|
|
1697
|
+
board.setFragment = (data, rectangle, type) => {
|
|
1378
1698
|
const targetDrawElements = getSelectedDrawElements(board);
|
|
1699
|
+
let boundLineElements = [];
|
|
1379
1700
|
if (targetDrawElements.length) {
|
|
1380
|
-
|
|
1701
|
+
if (type === 'cut') {
|
|
1702
|
+
const geometryElements = targetDrawElements.filter(value => PlaitDrawElement.isGeometry(value));
|
|
1703
|
+
const lineElements = targetDrawElements.filter(value => PlaitDrawElement.isLine(value));
|
|
1704
|
+
boundLineElements = getBoundedLineElements(board, geometryElements).filter(line => !lineElements.includes(line));
|
|
1705
|
+
}
|
|
1706
|
+
const elements = buildClipboardData(board, [...targetDrawElements, ...boundLineElements], rectangle ? [rectangle.x, rectangle.y] : [0, 0]);
|
|
1381
1707
|
setClipboardData(data, elements);
|
|
1382
1708
|
}
|
|
1383
|
-
setFragment(data, rectangle);
|
|
1709
|
+
setFragment(data, rectangle, type);
|
|
1384
1710
|
};
|
|
1385
1711
|
board.insertFragment = (data, targetPoint) => {
|
|
1386
1712
|
const elements = getDataFromClipboard(data);
|
|
@@ -1404,6 +1730,10 @@ const withDrawFragment = (baseBoard) => {
|
|
|
1404
1730
|
};
|
|
1405
1731
|
return board;
|
|
1406
1732
|
};
|
|
1733
|
+
const getBoundedLineElements = (board, geometries) => {
|
|
1734
|
+
const lines = getBoardLines(board);
|
|
1735
|
+
return lines.filter(line => geometries.find(geometry => PlaitLine.isBoundElementOfSource(line, geometry) || PlaitLine.isBoundElementOfTarget(line, geometry)));
|
|
1736
|
+
};
|
|
1407
1737
|
|
|
1408
1738
|
const DefaultLineStyle = {
|
|
1409
1739
|
strokeWidth: 2,
|
|
@@ -1564,8 +1894,7 @@ var LineResizeHandle;
|
|
|
1564
1894
|
LineResizeHandle["target"] = "target";
|
|
1565
1895
|
})(LineResizeHandle || (LineResizeHandle = {}));
|
|
1566
1896
|
const getHitLineResizeHandleRef = (board, element, point) => {
|
|
1567
|
-
const sourcePoint =
|
|
1568
|
-
const targetPoint = getTargetPoint(board, element);
|
|
1897
|
+
const [sourcePoint, targetPoint] = getLineHandlePoints(board, element);
|
|
1569
1898
|
const sourceRectangle = {
|
|
1570
1899
|
x: sourcePoint[0] - RESIZE_HANDLE_DIAMETER / 2,
|
|
1571
1900
|
y: sourcePoint[1] - RESIZE_HANDLE_DIAMETER / 2,
|
|
@@ -1736,9 +2065,8 @@ const withDraw = (board) => {
|
|
|
1736
2065
|
return getRectangleByPoints(element.points);
|
|
1737
2066
|
}
|
|
1738
2067
|
if (PlaitDrawElement.isLine(element)) {
|
|
1739
|
-
const
|
|
1740
|
-
|
|
1741
|
-
return getRectangleByPoints([source, target]);
|
|
2068
|
+
const points = getLinePoints(board, element);
|
|
2069
|
+
return getRectangleByPoints(points);
|
|
1742
2070
|
}
|
|
1743
2071
|
return getRectangle(element);
|
|
1744
2072
|
};
|
|
@@ -1782,5 +2110,5 @@ const withDraw = (board) => {
|
|
|
1782
2110
|
* Generated bundle index. Do not edit.
|
|
1783
2111
|
*/
|
|
1784
2112
|
|
|
1785
|
-
export { DefaultGeometryActiveStyle, DefaultGeometryProperty, DefaultGeometryStyle, DefaultTextProperty, DrawPointerType, DrawTransforms, GeometryComponent, GeometryPointer, GeometryShape, GeometryThreshold, LineComponent, LineHandleKey, LineMarkerType, LineShape, PlaitDrawElement, PlaitGeometry, PlaitLine, ShapeDefaultSpace, StrokeStyle, createGeometryElement, createLineElement, drawBoundMask, drawGeometry, drawLine, getBoardLines, getCenterPointsOnPolygon, getConnectionPoint, getElbowPoints, getFillByElement, getHitConnectorPoint, getHitLineTextIndex, getLineDashByElement, getLinePoints, getLineTextRectangle, getNearestPoint, getPointsByCenterPoint, getSelectedDrawElements, getSelectedGeometryElements, getSelectedLineElements,
|
|
2113
|
+
export { DefaultGeometryActiveStyle, DefaultGeometryProperty, DefaultGeometryStyle, DefaultTextProperty, DrawPointerType, DrawTransforms, GeometryComponent, GeometryPointer, GeometryShape, GeometryThreshold, LineComponent, LineHandleKey, LineMarkerType, LineShape, PlaitDrawElement, PlaitGeometry, PlaitLine, ShapeDefaultSpace, StrokeStyle, createGeometryElement, createLineElement, drawBoundMask, drawGeometry, drawLine, getBoardLines, getCenterPointsOnPolygon, getConnectionPoint, getDirectionByBoundElementAndConnection, getEdgeOnPolygonByPoint, getElbowPoints, getFillByElement, getHitConnectorPoint, getHitLineTextIndex, getLineDashByElement, getLineHandlePoints, getLineHandleRefPair, getLinePoints, getLineTextRectangle, getNearestPoint, getPointsByCenterPoint, getSelectedDrawElements, getSelectedGeometryElements, getSelectedLineElements, getStraightPoints, getStrokeColorByElement, getStrokeStyleByElement, getStrokeWidthByElement, getTextRectangle, isHitLineText, isHitPolyLine, transformPointToConnection, withDraw };
|
|
1786
2114
|
//# sourceMappingURL=plait-draw.mjs.map
|