@plait/draw 0.1.0-next.7 → 0.1.0-next.9
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/constants/geometry.mjs +4 -3
- package/esm2022/generators/geometry-shape.generator.mjs +4 -3
- package/esm2022/generators/line.generator.mjs +3 -26
- package/esm2022/geometry.component.mjs +18 -9
- package/esm2022/interfaces/geometry.mjs +5 -2
- package/esm2022/interfaces/line.mjs +9 -1
- package/esm2022/plugins/with-draw.mjs +2 -2
- package/esm2022/plugins/with-geometry-create.mjs +4 -5
- package/esm2022/plugins/with-geometry-resize.mjs +5 -5
- package/esm2022/plugins/with-line-bound-reaction.mjs +5 -7
- package/esm2022/plugins/with-line-create.mjs +3 -3
- package/esm2022/public-api.mjs +2 -1
- package/esm2022/transforms/index.mjs +4 -3
- package/esm2022/transforms/line.mjs +8 -1
- package/esm2022/utils/geometry.mjs +8 -8
- package/esm2022/utils/line-arrow.mjs +89 -0
- package/esm2022/utils/line.mjs +41 -41
- package/esm2022/utils/style/stroke.mjs +5 -2
- package/fesm2022/plait-draw.mjs +184 -94
- package/fesm2022/plait-draw.mjs.map +1 -1
- package/geometry.component.d.ts +4 -4
- package/interfaces/geometry.d.ts +1 -0
- package/interfaces/line.d.ts +8 -1
- package/package.json +1 -1
- package/public-api.d.ts +1 -0
- package/transforms/index.d.ts +1 -0
- package/transforms/line.d.ts +2 -1
- package/utils/geometry.d.ts +1 -1
- package/utils/line-arrow.d.ts +4 -0
- package/utils/line.d.ts +0 -2
package/fesm2022/plait-draw.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { PlaitElement, RectangleClient, PlaitBoard, setStrokeLinecap, isPointInPolygon, getNearestPointBetweenPointAndSegments, isPointInEllipse, drawRectangle, drawRoundRectangle, isPointInRoundRectangle, idCreator, createG, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, drawCircle,
|
|
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, getElementById, 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, Direction, getDirectionByPoint, getPoints, getPointOnPolyline,
|
|
5
|
+
import { getRectangleByPoints, getFactorByPoints, Direction, getDirectionByPoint, getPoints, getPointOnPolyline, getDirectionFactor, Generator, normalizeShapePoints, CommonPluginElement, ActiveGenerator, WithTextPluginKey, RESIZE_HANDLE_DIAMETER, 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';
|
|
@@ -18,9 +18,12 @@ var GeometryShape;
|
|
|
18
18
|
})(GeometryShape || (GeometryShape = {}));
|
|
19
19
|
const PlaitGeometry = {
|
|
20
20
|
getTextEditor(element) {
|
|
21
|
+
return PlaitGeometry.getTextManage(element).componentRef.instance.editor;
|
|
22
|
+
},
|
|
23
|
+
getTextManage(element) {
|
|
21
24
|
const component = PlaitElement.getComponent(element);
|
|
22
25
|
if (component) {
|
|
23
|
-
return component.textManage
|
|
26
|
+
return component.textManage;
|
|
24
27
|
}
|
|
25
28
|
throw new Error('can not get correctly component in get text editor');
|
|
26
29
|
}
|
|
@@ -30,6 +33,9 @@ var LineMarkerType;
|
|
|
30
33
|
(function (LineMarkerType) {
|
|
31
34
|
LineMarkerType["arrow"] = "arrow";
|
|
32
35
|
LineMarkerType["none"] = "none";
|
|
36
|
+
LineMarkerType["openTriangle"] = "open-triangle";
|
|
37
|
+
LineMarkerType["solidTriangle"] = "solid-triangle";
|
|
38
|
+
LineMarkerType["sharpArrow"] = "sharp-arrow";
|
|
33
39
|
})(LineMarkerType || (LineMarkerType = {}));
|
|
34
40
|
var LineShape;
|
|
35
41
|
(function (LineShape) {
|
|
@@ -37,6 +43,11 @@ var LineShape;
|
|
|
37
43
|
LineShape["curve"] = "curve";
|
|
38
44
|
LineShape["elbow"] = "elbow";
|
|
39
45
|
})(LineShape || (LineShape = {}));
|
|
46
|
+
var LineHandleKey;
|
|
47
|
+
(function (LineHandleKey) {
|
|
48
|
+
LineHandleKey["source"] = "source";
|
|
49
|
+
LineHandleKey["target"] = "target";
|
|
50
|
+
})(LineHandleKey || (LineHandleKey = {}));
|
|
40
51
|
const PlaitLine = {
|
|
41
52
|
getTextEditors(element) {
|
|
42
53
|
const component = PlaitElement.getComponent(element);
|
|
@@ -101,8 +112,8 @@ const DefaultGeometryStyle = {
|
|
|
101
112
|
fill: 'none'
|
|
102
113
|
};
|
|
103
114
|
const DefaultGeometryActiveStyle = {
|
|
104
|
-
strokeWidth:
|
|
105
|
-
selectionStrokeWidth:
|
|
115
|
+
strokeWidth: ACTIVE_STROKE_WIDTH,
|
|
116
|
+
selectionStrokeWidth: ACTIVE_STROKE_WIDTH
|
|
106
117
|
};
|
|
107
118
|
const DefaultGeometryProperty = {
|
|
108
119
|
width: 100,
|
|
@@ -139,6 +150,9 @@ const GeometryPointer = [
|
|
|
139
150
|
];
|
|
140
151
|
|
|
141
152
|
const getStrokeWidthByElement = (element) => {
|
|
153
|
+
if (PlaitDrawElement.isText(element)) {
|
|
154
|
+
return 0;
|
|
155
|
+
}
|
|
142
156
|
const strokeWidth = element.strokeWidth || DefaultGeometryStyle.strokeWidth;
|
|
143
157
|
return strokeWidth;
|
|
144
158
|
};
|
|
@@ -365,20 +379,20 @@ const getPointsByCenterPoint = (point, width, height) => {
|
|
|
365
379
|
};
|
|
366
380
|
const getTextRectangle = (element) => {
|
|
367
381
|
const elementRectangle = getRectangleByPoints(element.points);
|
|
382
|
+
const strokeWidth = getStrokeWidthByElement(element);
|
|
368
383
|
const height = element.textHeight;
|
|
369
|
-
const width = elementRectangle.width - ShapeDefaultSpace.rectangleAndText * 2;
|
|
384
|
+
const width = elementRectangle.width - ShapeDefaultSpace.rectangleAndText * 2 - strokeWidth * 2;
|
|
370
385
|
return {
|
|
371
386
|
height,
|
|
372
387
|
width: width > 0 ? width : 0,
|
|
373
|
-
x: elementRectangle.x + ShapeDefaultSpace.rectangleAndText,
|
|
388
|
+
x: elementRectangle.x + ShapeDefaultSpace.rectangleAndText + strokeWidth,
|
|
374
389
|
y: elementRectangle.y + (elementRectangle.height - height) / 2
|
|
375
390
|
};
|
|
376
391
|
};
|
|
377
392
|
const drawBoundMask = (board, element) => {
|
|
378
393
|
const G = createG();
|
|
379
394
|
const rectangle = getRectangleByPoints(element.points);
|
|
380
|
-
const
|
|
381
|
-
const activeRectangle = RectangleClient.getOutlineRectangle(rectangle, -offset);
|
|
395
|
+
const activeRectangle = RectangleClient.inflate(rectangle, ACTIVE_STROKE_WIDTH);
|
|
382
396
|
const maskG = drawGeometry(board, activeRectangle, element.shape, {
|
|
383
397
|
stroke: SELECTION_BORDER_COLOR,
|
|
384
398
|
strokeWidth: 1,
|
|
@@ -401,9 +415,9 @@ const drawBoundMask = (board, element) => {
|
|
|
401
415
|
const drawGeometry = (board, outerRectangle, shape, options) => {
|
|
402
416
|
return getEngine(shape).draw(board, outerRectangle, options);
|
|
403
417
|
};
|
|
404
|
-
const getNearestPoint = (element, point,
|
|
418
|
+
const getNearestPoint = (element, point, inflateDelta = 0) => {
|
|
405
419
|
const rectangle = getRectangleByPoints(element.points);
|
|
406
|
-
const activeRectangle = RectangleClient.
|
|
420
|
+
const activeRectangle = RectangleClient.inflate(rectangle, inflateDelta);
|
|
407
421
|
return getEngine(element.shape).getNearestPoint(activeRectangle, point);
|
|
408
422
|
};
|
|
409
423
|
const getCenterPointsOnPolygon = (points) => {
|
|
@@ -415,7 +429,91 @@ const getCenterPointsOnPolygon = (points) => {
|
|
|
415
429
|
return centerPoint;
|
|
416
430
|
};
|
|
417
431
|
|
|
418
|
-
const
|
|
432
|
+
const drawLineArrow = (element, points, options) => {
|
|
433
|
+
const arrowG = createG();
|
|
434
|
+
if (PlaitLine.isSourceMark(element, LineMarkerType.none) && PlaitLine.isTargetMark(element, LineMarkerType.none)) {
|
|
435
|
+
return null;
|
|
436
|
+
}
|
|
437
|
+
if (!PlaitLine.isSourceMark(element, LineMarkerType.none)) {
|
|
438
|
+
const sourceArrow = getArrow(element, element.source.marker, points[1], points[0], options);
|
|
439
|
+
sourceArrow && arrowG.appendChild(sourceArrow);
|
|
440
|
+
}
|
|
441
|
+
if (!PlaitLine.isTargetMark(element, LineMarkerType.none)) {
|
|
442
|
+
const arrow = getArrow(element, element.target.marker, points[points.length - 2], points[points.length - 1], options);
|
|
443
|
+
arrow && arrowG.appendChild(arrow);
|
|
444
|
+
}
|
|
445
|
+
return arrowG;
|
|
446
|
+
};
|
|
447
|
+
const getArrow = (element, marker, source, target, options) => {
|
|
448
|
+
let targetArrow;
|
|
449
|
+
switch (marker) {
|
|
450
|
+
case LineMarkerType.openTriangle: {
|
|
451
|
+
targetArrow = drawOpenTriangle(element, source, target, options);
|
|
452
|
+
break;
|
|
453
|
+
}
|
|
454
|
+
case LineMarkerType.solidTriangle: {
|
|
455
|
+
targetArrow = drawSolidTriangle(source, target, options);
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
case LineMarkerType.arrow: {
|
|
459
|
+
targetArrow = drawArrow(element, source, target, options);
|
|
460
|
+
break;
|
|
461
|
+
}
|
|
462
|
+
case LineMarkerType.sharpArrow: {
|
|
463
|
+
targetArrow = drawSharpArrow(source, target, options);
|
|
464
|
+
break;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
return targetArrow;
|
|
468
|
+
};
|
|
469
|
+
const drawSharpArrow = (source, target, options) => {
|
|
470
|
+
const directionFactor = getFactorByPoints(source, target);
|
|
471
|
+
const startPoint = target;
|
|
472
|
+
// const startPoint: Point = [
|
|
473
|
+
// target[0],
|
|
474
|
+
// target[1]
|
|
475
|
+
// ];
|
|
476
|
+
const { pointLeft, pointRight } = arrowPoints(source, target, 12, 20);
|
|
477
|
+
const g = createG();
|
|
478
|
+
const path = createPath();
|
|
479
|
+
let polylinePath = `M${pointRight[0]},${pointRight[1]}A8,8,20,0,1,${pointLeft[0]},${pointLeft[1]}L${startPoint[0]},${startPoint[1]}Z`;
|
|
480
|
+
path.setAttribute('d', polylinePath);
|
|
481
|
+
path.setAttribute('stroke', `${options?.stroke}`);
|
|
482
|
+
path.setAttribute('stroke-width', `${options?.strokeWidth}`);
|
|
483
|
+
path.setAttribute('fill', `${options?.stroke}`);
|
|
484
|
+
g.appendChild(path);
|
|
485
|
+
return g;
|
|
486
|
+
};
|
|
487
|
+
const drawArrow = (element, source, target, options) => {
|
|
488
|
+
const directionFactor = getFactorByPoints(source, target);
|
|
489
|
+
const strokeWidth = getStrokeWidthByElement(element);
|
|
490
|
+
const endPoint = [
|
|
491
|
+
target[0] + strokeWidth * directionFactor.x / 2,
|
|
492
|
+
target[1] + strokeWidth * directionFactor.y / 2
|
|
493
|
+
];
|
|
494
|
+
const middlePoint = [endPoint[0] - 8 * directionFactor.x, endPoint[1] - 8 * directionFactor.y];
|
|
495
|
+
const { pointLeft, pointRight } = arrowPoints(source, endPoint, 12, 30);
|
|
496
|
+
const arrowG = drawLinearPath([pointLeft, endPoint, pointRight, middlePoint], { ...options, fill: options.stroke }, true);
|
|
497
|
+
const path = arrowG.querySelector('path');
|
|
498
|
+
path.setAttribute('stroke-linejoin', 'round');
|
|
499
|
+
return arrowG;
|
|
500
|
+
};
|
|
501
|
+
const drawSolidTriangle = (source, target, options) => {
|
|
502
|
+
const endPoint = target;
|
|
503
|
+
const { pointLeft, pointRight } = arrowPoints(source, endPoint, 12, 30);
|
|
504
|
+
return drawLinearPath([pointLeft, endPoint, pointRight], { ...options, fill: options.stroke }, true);
|
|
505
|
+
};
|
|
506
|
+
const drawOpenTriangle = (element, source, target, options) => {
|
|
507
|
+
const directionFactor = getFactorByPoints(source, target);
|
|
508
|
+
const strokeWidth = getStrokeWidthByElement(element);
|
|
509
|
+
const endPoint = [
|
|
510
|
+
target[0] + strokeWidth * directionFactor.x / 2,
|
|
511
|
+
target[1] + strokeWidth * directionFactor.y / 2
|
|
512
|
+
];
|
|
513
|
+
const { pointLeft, pointRight } = arrowPoints(source, endPoint, 12, 40);
|
|
514
|
+
return drawLinearPath([pointLeft, endPoint, pointRight], options);
|
|
515
|
+
};
|
|
516
|
+
|
|
419
517
|
const createLineElement = (shape, points, source, target, options) => {
|
|
420
518
|
return {
|
|
421
519
|
id: idCreator(),
|
|
@@ -482,42 +580,43 @@ const drawLine = (board, element) => {
|
|
|
482
580
|
const options = { stroke: strokeColor, strokeWidth, strokeLineDash };
|
|
483
581
|
const lineG = createG();
|
|
484
582
|
const points = getLinePoints(board, element);
|
|
485
|
-
const line =
|
|
486
|
-
|
|
487
|
-
path?.setAttribute('mask', `url(#${element.id})`);
|
|
488
|
-
setPathStrokeLinecap(line, 'square');
|
|
583
|
+
const line = drawLinearPath(points, options);
|
|
584
|
+
line.setAttribute('mask', `url(#${element.id})`);
|
|
489
585
|
lineG.appendChild(line);
|
|
490
|
-
const
|
|
586
|
+
const { mask, maskTargetFillRect } = drawMask(board, element);
|
|
587
|
+
lineG.appendChild(mask);
|
|
588
|
+
line.appendChild(maskTargetFillRect);
|
|
589
|
+
const arrow = drawLineArrow(element, points, { stroke: strokeColor, strokeWidth });
|
|
491
590
|
arrow && lineG.appendChild(arrow);
|
|
492
591
|
return lineG;
|
|
493
592
|
};
|
|
494
|
-
|
|
495
|
-
const
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
const
|
|
507
|
-
const
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
};
|
|
593
|
+
function drawMask(board, element) {
|
|
594
|
+
const mask = createMask();
|
|
595
|
+
mask.setAttribute('id', element.id);
|
|
596
|
+
const points = getLinePoints(board, element);
|
|
597
|
+
let rectangle = getRectangleByPoints(points);
|
|
598
|
+
rectangle = RectangleClient.getOutlineRectangle(rectangle, -30);
|
|
599
|
+
const maskFillRect = createRect(rectangle, {
|
|
600
|
+
fill: 'white'
|
|
601
|
+
});
|
|
602
|
+
mask.appendChild(maskFillRect);
|
|
603
|
+
const texts = element.texts;
|
|
604
|
+
texts.forEach((text, index) => {
|
|
605
|
+
const textRectangle = getLineTextRectangle(board, element, index);
|
|
606
|
+
const rect = createRect(textRectangle, {
|
|
607
|
+
fill: 'black'
|
|
608
|
+
});
|
|
609
|
+
mask.appendChild(rect);
|
|
610
|
+
});
|
|
611
|
+
//撑开 line
|
|
612
|
+
const maskTargetFillRect = createRect(rectangle);
|
|
613
|
+
maskTargetFillRect.setAttribute('opacity', '0');
|
|
614
|
+
return { mask, maskTargetFillRect };
|
|
615
|
+
}
|
|
518
616
|
const getSourcePoint = (board, element) => {
|
|
519
617
|
if (element.source.boundId) {
|
|
520
|
-
const
|
|
618
|
+
const strokeWidth = getStrokeWidthByElement(element);
|
|
619
|
+
const connectionOffset = PlaitLine.isSourceMark(element, LineMarkerType.none) ? 0 : strokeWidth;
|
|
521
620
|
const boundElement = getElementById(board, element.source.boundId);
|
|
522
621
|
return boundElement ? getConnectionPoint(boundElement, element.source.connection, connectionOffset) : element.points[0];
|
|
523
622
|
}
|
|
@@ -525,7 +624,8 @@ const getSourcePoint = (board, element) => {
|
|
|
525
624
|
};
|
|
526
625
|
const getTargetPoint = (board, element) => {
|
|
527
626
|
if (element.target.boundId) {
|
|
528
|
-
const
|
|
627
|
+
const strokeWidth = getStrokeWidthByElement(element);
|
|
628
|
+
const connectionOffset = PlaitLine.isTargetMark(element, LineMarkerType.none) ? 0 : strokeWidth;
|
|
529
629
|
const boundElement = getElementById(board, element.target.boundId);
|
|
530
630
|
return boundElement
|
|
531
631
|
? getConnectionPoint(boundElement, element.target.connection, connectionOffset)
|
|
@@ -535,18 +635,16 @@ const getTargetPoint = (board, element) => {
|
|
|
535
635
|
};
|
|
536
636
|
const getConnectionPoint = (geometry, connection, offset) => {
|
|
537
637
|
const rectangle = getRectangleByPoints(geometry.points);
|
|
538
|
-
const strokeWidth = getStrokeWidthByElement(geometry);
|
|
539
638
|
const directionFactor = getDirectionFactor(getDirectionByPoint(connection, Direction.bottom));
|
|
540
639
|
return [
|
|
541
|
-
rectangle.x + rectangle.width * connection[0] +
|
|
542
|
-
rectangle.y + rectangle.height * connection[1] +
|
|
640
|
+
rectangle.x + rectangle.width * connection[0] + directionFactor.x * offset,
|
|
641
|
+
rectangle.y + rectangle.height * connection[1] + directionFactor.y * offset
|
|
543
642
|
];
|
|
544
643
|
};
|
|
545
644
|
const transformPointToConnection = (board, point, hitElement) => {
|
|
546
|
-
const offset = (getStrokeWidthByElement(hitElement) + 1) / 2;
|
|
547
645
|
let rectangle = getRectangleByPoints(hitElement.points);
|
|
548
|
-
rectangle = RectangleClient.
|
|
549
|
-
let nearestPoint = getNearestPoint(hitElement, point,
|
|
646
|
+
rectangle = RectangleClient.inflate(rectangle, ACTIVE_STROKE_WIDTH);
|
|
647
|
+
let nearestPoint = getNearestPoint(hitElement, point, ACTIVE_STROKE_WIDTH);
|
|
550
648
|
const hitConnector = getHitConnectorPoint(nearestPoint, hitElement, rectangle);
|
|
551
649
|
nearestPoint = hitConnector ? hitConnector : nearestPoint;
|
|
552
650
|
return [(nearestPoint[0] - rectangle.x) / rectangle.width, (nearestPoint[1] - rectangle.y) / rectangle.height];
|
|
@@ -595,7 +693,7 @@ class GeometryShapeGenerator extends Generator {
|
|
|
595
693
|
return true;
|
|
596
694
|
}
|
|
597
695
|
baseDraw(element, data) {
|
|
598
|
-
const
|
|
696
|
+
const rectangle = getRectangleByPoints(element.points);
|
|
599
697
|
const shape = element.shape;
|
|
600
698
|
if (shape === GeometryShape.text) {
|
|
601
699
|
return;
|
|
@@ -604,7 +702,7 @@ class GeometryShapeGenerator extends Generator {
|
|
|
604
702
|
const strokeColor = getStrokeColorByElement(element);
|
|
605
703
|
const fill = getFillByElement(element);
|
|
606
704
|
const strokeLineDash = getLineDashByElement(element);
|
|
607
|
-
return drawGeometry(this.board,
|
|
705
|
+
return drawGeometry(this.board, RectangleClient.inflate(rectangle, -strokeWidth), shape, { stroke: strokeColor, strokeWidth, fill, strokeLineDash });
|
|
608
706
|
}
|
|
609
707
|
}
|
|
610
708
|
|
|
@@ -698,6 +796,12 @@ const removeLineText = (board, element, index) => {
|
|
|
698
796
|
newTexts.splice(index, 1);
|
|
699
797
|
Transforms.setNode(board, { texts: newTexts }, path);
|
|
700
798
|
};
|
|
799
|
+
const setLineMark = (board, element, handleKey, marker) => {
|
|
800
|
+
const path = PlaitBoard.findPath(board, element);
|
|
801
|
+
let handle = handleKey === LineHandleKey.source ? element.source : element.target;
|
|
802
|
+
handle = { ...handle, marker };
|
|
803
|
+
Transforms.setNode(board, { [handleKey]: handle }, path);
|
|
804
|
+
};
|
|
701
805
|
|
|
702
806
|
const DrawTransforms = {
|
|
703
807
|
setText,
|
|
@@ -707,10 +811,14 @@ const DrawTransforms = {
|
|
|
707
811
|
setTextSize,
|
|
708
812
|
resizeLine,
|
|
709
813
|
setLineTexts,
|
|
710
|
-
removeLineText
|
|
814
|
+
removeLineText,
|
|
815
|
+
setLineMark
|
|
711
816
|
};
|
|
712
817
|
|
|
713
|
-
class GeometryComponent extends
|
|
818
|
+
class GeometryComponent extends CommonPluginElement {
|
|
819
|
+
get textManage() {
|
|
820
|
+
return this.getTextManages()[0];
|
|
821
|
+
}
|
|
714
822
|
constructor(viewContainerRef, cdr) {
|
|
715
823
|
super(cdr);
|
|
716
824
|
this.viewContainerRef = viewContainerRef;
|
|
@@ -728,12 +836,18 @@ class GeometryComponent extends PlaitPluginElementComponent {
|
|
|
728
836
|
return DefaultGeometryActiveStyle.selectionStrokeWidth;
|
|
729
837
|
}
|
|
730
838
|
},
|
|
839
|
+
getStrokeOpacity: () => {
|
|
840
|
+
const selectedElements = getSelectedElements(this.board);
|
|
841
|
+
if (selectedElements.length === 1 && !isSelectionMoving(this.board)) {
|
|
842
|
+
return 1;
|
|
843
|
+
}
|
|
844
|
+
else {
|
|
845
|
+
return 0.5;
|
|
846
|
+
}
|
|
847
|
+
},
|
|
731
848
|
getRectangle: (element) => {
|
|
732
849
|
return getRectangleByPoints(element.points);
|
|
733
850
|
},
|
|
734
|
-
getStrokeWidthByElement: (element) => {
|
|
735
|
-
return getStrokeWidthByElement(element);
|
|
736
|
-
},
|
|
737
851
|
hasResizeHandle: () => {
|
|
738
852
|
const selectedElements = getSelectedElements(this.board);
|
|
739
853
|
if (PlaitBoard.hasBeenTextEditing(this.board) && PlaitDrawElement.isText(this.element)) {
|
|
@@ -780,7 +894,7 @@ class GeometryComponent extends PlaitPluginElementComponent {
|
|
|
780
894
|
}
|
|
781
895
|
initializeTextManage() {
|
|
782
896
|
const plugins = this.board.getPluginOptions(WithTextPluginKey).textPlugins;
|
|
783
|
-
|
|
897
|
+
const manage = new TextManage(this.board, this.viewContainerRef, {
|
|
784
898
|
getRectangle: () => {
|
|
785
899
|
return getTextRectangle(this.element);
|
|
786
900
|
},
|
|
@@ -800,6 +914,7 @@ class GeometryComponent extends PlaitPluginElementComponent {
|
|
|
800
914
|
},
|
|
801
915
|
textPlugins: plugins
|
|
802
916
|
});
|
|
917
|
+
this.initializeTextManages([manage]);
|
|
803
918
|
}
|
|
804
919
|
ngOnDestroy() {
|
|
805
920
|
super.ngOnDestroy();
|
|
@@ -830,7 +945,6 @@ class LineShapeGenerator extends Generator {
|
|
|
830
945
|
case LineShape.elbow:
|
|
831
946
|
case LineShape.straight:
|
|
832
947
|
lineG = drawLine(this.board, element);
|
|
833
|
-
drawMask(this.board, lineG, element);
|
|
834
948
|
break;
|
|
835
949
|
default:
|
|
836
950
|
break;
|
|
@@ -838,27 +952,6 @@ class LineShapeGenerator extends Generator {
|
|
|
838
952
|
return lineG;
|
|
839
953
|
}
|
|
840
954
|
}
|
|
841
|
-
function drawMask(board, g, element) {
|
|
842
|
-
const mask = createMask();
|
|
843
|
-
mask.setAttribute('id', element.id);
|
|
844
|
-
mask.setAttribute('maskUnits', 'userSpaceOnUse');
|
|
845
|
-
const points = getLinePoints(board, element);
|
|
846
|
-
let rectangle = getRectangleByPoints(points);
|
|
847
|
-
rectangle = RectangleClient.getOutlineRectangle(rectangle, -3);
|
|
848
|
-
const maskRect = createRect(rectangle, {
|
|
849
|
-
fill: 'white'
|
|
850
|
-
});
|
|
851
|
-
mask.appendChild(maskRect);
|
|
852
|
-
const texts = element.texts;
|
|
853
|
-
texts.forEach((text, index) => {
|
|
854
|
-
const textRectangle = getLineTextRectangle(board, element, index);
|
|
855
|
-
const rect = createRect(textRectangle, {
|
|
856
|
-
fill: 'black'
|
|
857
|
-
});
|
|
858
|
-
mask.appendChild(rect);
|
|
859
|
-
});
|
|
860
|
-
g.appendChild(mask);
|
|
861
|
-
}
|
|
862
955
|
|
|
863
956
|
class LineActiveGenerator extends Generator {
|
|
864
957
|
canDraw(element, data) {
|
|
@@ -1110,7 +1203,7 @@ const withGeometryCreateByDrag = (board) => {
|
|
|
1110
1203
|
}
|
|
1111
1204
|
geometryShapeG?.remove();
|
|
1112
1205
|
geometryShapeG = null;
|
|
1113
|
-
preventTouchMove(board, false);
|
|
1206
|
+
preventTouchMove(board, event, false);
|
|
1114
1207
|
pointerUp(event);
|
|
1115
1208
|
};
|
|
1116
1209
|
return board;
|
|
@@ -1134,8 +1227,8 @@ const withGeometryCreateByDraw = (board) => {
|
|
|
1134
1227
|
if (isGeometryPointer && isDrawingMode(board)) {
|
|
1135
1228
|
const point = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
|
|
1136
1229
|
start = point;
|
|
1137
|
-
preventTouchMove(board, true);
|
|
1138
1230
|
const pointer = PlaitBoard.getPointer(board);
|
|
1231
|
+
preventTouchMove(board, event, true);
|
|
1139
1232
|
if (pointer === DrawPointerType.text) {
|
|
1140
1233
|
const points = getDefaultGeometryPoints(pointer, point);
|
|
1141
1234
|
const textElement = createGeometryElement(GeometryShape.text, points, DefaultTextProperty.text);
|
|
@@ -1144,7 +1237,6 @@ const withGeometryCreateByDraw = (board) => {
|
|
|
1144
1237
|
addSelectedElement(board, textElement);
|
|
1145
1238
|
BoardTransforms.updatePointerType(board, PlaitPointerType.selection);
|
|
1146
1239
|
start = null;
|
|
1147
|
-
preventTouchMove(board, false);
|
|
1148
1240
|
}
|
|
1149
1241
|
}
|
|
1150
1242
|
pointerDown(event);
|
|
@@ -1193,7 +1285,7 @@ const withGeometryCreateByDraw = (board) => {
|
|
|
1193
1285
|
geometryShapeG = null;
|
|
1194
1286
|
start = null;
|
|
1195
1287
|
temporaryElement = null;
|
|
1196
|
-
preventTouchMove(board, false);
|
|
1288
|
+
preventTouchMove(board, event, false);
|
|
1197
1289
|
pointerUp(event);
|
|
1198
1290
|
};
|
|
1199
1291
|
return board;
|
|
@@ -1358,7 +1450,7 @@ const withLineCreateByDraw = (board) => {
|
|
|
1358
1450
|
sourceRef.connection = transformPointToConnection(board, point, hitElement);
|
|
1359
1451
|
sourceRef.boundId = hitElement.id;
|
|
1360
1452
|
}
|
|
1361
|
-
preventTouchMove(board, true);
|
|
1453
|
+
preventTouchMove(board, event, true);
|
|
1362
1454
|
}
|
|
1363
1455
|
pointerDown(event);
|
|
1364
1456
|
};
|
|
@@ -1393,7 +1485,7 @@ const withLineCreateByDraw = (board) => {
|
|
|
1393
1485
|
sourceRef = {};
|
|
1394
1486
|
targetRef = {};
|
|
1395
1487
|
temporaryElement = null;
|
|
1396
|
-
preventTouchMove(board, false);
|
|
1488
|
+
preventTouchMove(board, event, false);
|
|
1397
1489
|
pointerUp(event);
|
|
1398
1490
|
};
|
|
1399
1491
|
return board;
|
|
@@ -1417,7 +1509,7 @@ const withGeometryResize = (board) => {
|
|
|
1417
1509
|
},
|
|
1418
1510
|
detect: (point) => {
|
|
1419
1511
|
const selectedGeometryElements = getSelectedGeometryElements(board);
|
|
1420
|
-
if (selectedGeometryElements.length !== 1) {
|
|
1512
|
+
if (selectedGeometryElements.length !== 1 || getSelectedElements(board).length !== 1) {
|
|
1421
1513
|
return null;
|
|
1422
1514
|
}
|
|
1423
1515
|
const target = selectedGeometryElements[0];
|
|
@@ -1455,8 +1547,7 @@ const withGeometryResize = (board) => {
|
|
|
1455
1547
|
];
|
|
1456
1548
|
}
|
|
1457
1549
|
points = normalizeShapePoints(points, isShift);
|
|
1458
|
-
const
|
|
1459
|
-
const { height: textHeight } = component.textManage.getSize();
|
|
1550
|
+
const { height: textHeight } = PlaitGeometry.getTextManage(resizeRef.element).getSize();
|
|
1460
1551
|
DrawTransforms.resizeGeometry(board, points, textHeight, resizeRef.path);
|
|
1461
1552
|
}
|
|
1462
1553
|
};
|
|
@@ -1553,15 +1644,14 @@ const withLineBoundReaction = (board) => {
|
|
|
1553
1644
|
const hitElement = getHitOutlineGeometry(board, movingPoint, -4);
|
|
1554
1645
|
if (hitElement) {
|
|
1555
1646
|
boundShapeG = drawBoundMask(board, hitElement);
|
|
1556
|
-
|
|
1557
|
-
let nearestPoint = getNearestPoint(hitElement, movingPoint, offset);
|
|
1647
|
+
let nearestPoint = getNearestPoint(hitElement, movingPoint, ACTIVE_STROKE_WIDTH);
|
|
1558
1648
|
const rectangle = getRectangleByPoints(hitElement.points);
|
|
1559
|
-
const activeRectangle = RectangleClient.
|
|
1649
|
+
const activeRectangle = RectangleClient.inflate(rectangle, ACTIVE_STROKE_WIDTH);
|
|
1560
1650
|
const hitConnector = getHitConnectorPoint(nearestPoint, hitElement, activeRectangle);
|
|
1561
1651
|
nearestPoint = hitConnector ? hitConnector : nearestPoint;
|
|
1562
1652
|
const circleG = drawCircle(PlaitBoard.getRoughSVG(board), nearestPoint, 6, {
|
|
1563
1653
|
stroke: SELECTION_BORDER_COLOR,
|
|
1564
|
-
strokeWidth:
|
|
1654
|
+
strokeWidth: ACTIVE_STROKE_WIDTH,
|
|
1565
1655
|
fill: SELECTION_BORDER_COLOR,
|
|
1566
1656
|
fillStyle: 'solid'
|
|
1567
1657
|
});
|
|
@@ -1678,7 +1768,7 @@ const withDraw = (board) => {
|
|
|
1678
1768
|
return true;
|
|
1679
1769
|
}
|
|
1680
1770
|
if (PlaitDrawElement.isLine(element)) {
|
|
1681
|
-
return !element.source.boundId && !element.
|
|
1771
|
+
return !element.source.boundId && !element.target.boundId;
|
|
1682
1772
|
}
|
|
1683
1773
|
return isMovable(element);
|
|
1684
1774
|
};
|
|
@@ -1689,5 +1779,5 @@ const withDraw = (board) => {
|
|
|
1689
1779
|
* Generated bundle index. Do not edit.
|
|
1690
1780
|
*/
|
|
1691
1781
|
|
|
1692
|
-
export { DefaultGeometryActiveStyle, DefaultGeometryProperty, DefaultGeometryStyle, DefaultTextProperty, DrawPointerType, GeometryComponent, GeometryPointer, GeometryShape, GeometryThreshold, LineComponent, LineMarkerType, LineShape, PlaitDrawElement, PlaitGeometry, PlaitLine, ShapeDefaultSpace, StrokeStyle, createGeometryElement, createLineElement, drawBoundMask, drawGeometry, drawLine,
|
|
1782
|
+
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, getSourcePoint, getStraightPoints, getStrokeColorByElement, getStrokeStyleByElement, getStrokeWidthByElement, getTargetPoint, getTextRectangle, isHitLineText, isHitPolyLine, transformPointToConnection, withDraw };
|
|
1693
1783
|
//# sourceMappingURL=plait-draw.mjs.map
|