@plait/draw 0.1.0-next.5 → 0.1.0-next.7
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/generators/geometry-shape.generator.mjs +22 -0
- package/esm2022/generators/line-active.generator.mjs +36 -0
- package/esm2022/generators/line.generator.mjs +45 -0
- package/esm2022/geometry.component.mjs +7 -5
- package/esm2022/interfaces/element.mjs +6 -0
- package/esm2022/interfaces/geometry.mjs +1 -1
- package/esm2022/interfaces/index.mjs +2 -1
- package/esm2022/interfaces/line.mjs +1 -1
- package/esm2022/line.component.mjs +3 -3
- package/esm2022/plugins/with-draw-fragment.mjs +5 -10
- package/esm2022/plugins/with-draw-hotkey.mjs +7 -3
- package/esm2022/plugins/with-draw.mjs +4 -4
- package/esm2022/plugins/with-geometry-create.mjs +2 -2
- package/esm2022/plugins/with-line-bound-reaction.mjs +2 -2
- package/esm2022/plugins/with-line-create.mjs +2 -2
- package/esm2022/plugins/with-line-text.mjs +3 -3
- package/esm2022/utils/geometry.mjs +2 -2
- package/esm2022/utils/index.mjs +2 -1
- package/esm2022/utils/line.mjs +18 -13
- package/esm2022/utils/style/index.mjs +2 -0
- package/esm2022/utils/style/stroke.mjs +21 -0
- package/fesm2022/plait-draw.mjs +43 -25
- package/fesm2022/plait-draw.mjs.map +1 -1
- package/geometry.component.d.ts +1 -1
- package/interfaces/element.d.ts +4 -0
- package/interfaces/geometry.d.ts +1 -1
- package/interfaces/index.d.ts +1 -0
- package/interfaces/line.d.ts +1 -1
- package/line.component.d.ts +2 -2
- package/package.json +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/line.d.ts +3 -1
- package/utils/style/index.d.ts +1 -0
- package/utils/{geometry-style → style}/stroke.d.ts +2 -1
- package/esm2022/generator/geometry-shape.generator.mjs +0 -22
- package/esm2022/generator/line-active.generator.mjs +0 -36
- package/esm2022/generator/line.generator.mjs +0 -43
- package/esm2022/utils/geometry-style/stroke.mjs +0 -17
- /package/{generator → generators}/geometry-shape.generator.d.ts +0 -0
- /package/{generator → generators}/line-active.generator.d.ts +0 -0
- /package/{generator → generators}/line.generator.d.ts +0 -0
package/fesm2022/plait-draw.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { PlaitElement, RectangleClient, PlaitBoard, setStrokeLinecap, isPointInP
|
|
|
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, Direction, getDirectionByPoint, getPoints, getPointOnPolyline, getFactorByPoints, getDirectionFactor, Generator, normalizeShapePoints, 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';
|
|
@@ -65,6 +65,12 @@ const PlaitLine = {
|
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
+
var StrokeStyle;
|
|
69
|
+
(function (StrokeStyle) {
|
|
70
|
+
StrokeStyle["solid"] = "solid";
|
|
71
|
+
StrokeStyle["dashed"] = "dashed";
|
|
72
|
+
})(StrokeStyle || (StrokeStyle = {}));
|
|
73
|
+
|
|
68
74
|
const PlaitDrawElement = {
|
|
69
75
|
isGeometry: (value) => {
|
|
70
76
|
return value.type === 'geometry';
|
|
@@ -147,6 +153,9 @@ const getFillByElement = (element) => {
|
|
|
147
153
|
const getLineDashByElement = (element) => {
|
|
148
154
|
return element.strokeStyle === 'dashed' ? [8, 8 + getStrokeWidthByElement(element)] : undefined;
|
|
149
155
|
};
|
|
156
|
+
const getStrokeStyleByElement = (element) => {
|
|
157
|
+
return element.strokeStyle || StrokeStyle.solid;
|
|
158
|
+
};
|
|
150
159
|
|
|
151
160
|
const DiamondEngine = {
|
|
152
161
|
draw(board, rectangle, options) {
|
|
@@ -420,6 +429,12 @@ const createLineElement = (shape, points, source, target, options) => {
|
|
|
420
429
|
...options
|
|
421
430
|
};
|
|
422
431
|
};
|
|
432
|
+
const getLinePoints = (board, element) => {
|
|
433
|
+
return element.shape === LineShape.elbow ? getElbowPoints(board, element) : getStraightPoints(board, element);
|
|
434
|
+
};
|
|
435
|
+
const getStraightPoints = (board, element) => {
|
|
436
|
+
return [getSourcePoint(board, element), getTargetPoint(board, element)];
|
|
437
|
+
};
|
|
423
438
|
const getElbowPoints = (board, element) => {
|
|
424
439
|
if (element.points.length === 2) {
|
|
425
440
|
const source = getSourcePoint(board, element);
|
|
@@ -460,18 +475,18 @@ const getHitLineTextIndex = (board, element, point) => {
|
|
|
460
475
|
const isHitLineText = (board, element, point) => {
|
|
461
476
|
return getHitLineTextIndex(board, element, point) !== -1;
|
|
462
477
|
};
|
|
463
|
-
const
|
|
478
|
+
const drawLine = (board, element) => {
|
|
464
479
|
const strokeWidth = getStrokeWidthByElement(element);
|
|
465
480
|
const strokeColor = getStrokeColorByElement(element);
|
|
466
481
|
const strokeLineDash = getLineDashByElement(element);
|
|
467
482
|
const options = { stroke: strokeColor, strokeWidth, strokeLineDash };
|
|
468
483
|
const lineG = createG();
|
|
469
|
-
const points =
|
|
470
|
-
const
|
|
471
|
-
const path =
|
|
484
|
+
const points = getLinePoints(board, element);
|
|
485
|
+
const line = PlaitBoard.getRoughSVG(board).linearPath(points, options);
|
|
486
|
+
const path = line.querySelector('path');
|
|
472
487
|
path?.setAttribute('mask', `url(#${element.id})`);
|
|
473
|
-
setPathStrokeLinecap(
|
|
474
|
-
lineG.appendChild(
|
|
488
|
+
setPathStrokeLinecap(line, 'square');
|
|
489
|
+
lineG.appendChild(line);
|
|
475
490
|
const arrow = drawLineArrow(element, points, options);
|
|
476
491
|
arrow && lineG.appendChild(arrow);
|
|
477
492
|
return lineG;
|
|
@@ -489,8 +504,7 @@ const drawLineArrow = (element, points, options) => {
|
|
|
489
504
|
}
|
|
490
505
|
if (PlaitLine.isTargetMark(element, LineMarkerType.arrow)) {
|
|
491
506
|
const _endPoint = points[points.length - 1];
|
|
492
|
-
const
|
|
493
|
-
const directionFactor = getDirectionFactor(arrowDirection);
|
|
507
|
+
const directionFactor = getFactorByPoints(points[points.length - 2], _endPoint);
|
|
494
508
|
const endPoint = [
|
|
495
509
|
_endPoint[0] + BOUNDED_HANDLE_OFFSET * directionFactor.x,
|
|
496
510
|
_endPoint[1] + BOUNDED_HANDLE_OFFSET * directionFactor.y
|
|
@@ -547,7 +561,7 @@ const getHitConnectorPoint = (movingPoint, hitElement, rectangle) => {
|
|
|
547
561
|
};
|
|
548
562
|
const getLineTextRectangle = (board, element, index) => {
|
|
549
563
|
const text = element.texts[index];
|
|
550
|
-
const elbowPoints =
|
|
564
|
+
const elbowPoints = getLinePoints(board, element);
|
|
551
565
|
const point = getPointOnPolyline(elbowPoints, text.position);
|
|
552
566
|
return {
|
|
553
567
|
x: point[0] - text.width / 2,
|
|
@@ -765,6 +779,7 @@ class GeometryComponent extends PlaitPluginElementComponent {
|
|
|
765
779
|
this.textManage.updateRectangle();
|
|
766
780
|
}
|
|
767
781
|
initializeTextManage() {
|
|
782
|
+
const plugins = this.board.getPluginOptions(WithTextPluginKey).textPlugins;
|
|
768
783
|
this.textManage = new TextManage(this.board, this.viewContainerRef, {
|
|
769
784
|
getRectangle: () => {
|
|
770
785
|
return getTextRectangle(this.element);
|
|
@@ -782,7 +797,8 @@ class GeometryComponent extends PlaitPluginElementComponent {
|
|
|
782
797
|
getMaxWidth: () => {
|
|
783
798
|
const width = getTextRectangle(this.element).width;
|
|
784
799
|
return this.element?.autoSize ? GeometryThreshold.defaultTextMaxWidth : width;
|
|
785
|
-
}
|
|
800
|
+
},
|
|
801
|
+
textPlugins: plugins
|
|
786
802
|
});
|
|
787
803
|
}
|
|
788
804
|
ngOnDestroy() {
|
|
@@ -812,7 +828,8 @@ class LineShapeGenerator extends Generator {
|
|
|
812
828
|
let lineG;
|
|
813
829
|
switch (shape) {
|
|
814
830
|
case LineShape.elbow:
|
|
815
|
-
|
|
831
|
+
case LineShape.straight:
|
|
832
|
+
lineG = drawLine(this.board, element);
|
|
816
833
|
drawMask(this.board, lineG, element);
|
|
817
834
|
break;
|
|
818
835
|
default:
|
|
@@ -824,7 +841,8 @@ class LineShapeGenerator extends Generator {
|
|
|
824
841
|
function drawMask(board, g, element) {
|
|
825
842
|
const mask = createMask();
|
|
826
843
|
mask.setAttribute('id', element.id);
|
|
827
|
-
|
|
844
|
+
mask.setAttribute('maskUnits', 'userSpaceOnUse');
|
|
845
|
+
const points = getLinePoints(board, element);
|
|
828
846
|
let rectangle = getRectangleByPoints(points);
|
|
829
847
|
rectangle = RectangleClient.getOutlineRectangle(rectangle, -3);
|
|
830
848
|
const maskRect = createRect(rectangle, {
|
|
@@ -1023,7 +1041,11 @@ const withDrawHotkey = (board) => {
|
|
|
1023
1041
|
const selectedElements = getSelectedElements(board);
|
|
1024
1042
|
const isSingleSelection = selectedElements.length === 1;
|
|
1025
1043
|
const targetElement = selectedElements[0];
|
|
1026
|
-
if (!isVirtualKey(event) &&
|
|
1044
|
+
if (!isVirtualKey(event) &&
|
|
1045
|
+
!isDelete(event) &&
|
|
1046
|
+
!isSpaceHotkey(event) &&
|
|
1047
|
+
isSingleSelection &&
|
|
1048
|
+
PlaitDrawElement.isGeometry(targetElement)) {
|
|
1027
1049
|
event.preventDefault();
|
|
1028
1050
|
PlaitElement.getComponent(targetElement).editText();
|
|
1029
1051
|
return;
|
|
@@ -1247,21 +1269,17 @@ const insertClipboardData = (board, elements, startPoint) => {
|
|
|
1247
1269
|
|
|
1248
1270
|
const withDrawFragment = (baseBoard) => {
|
|
1249
1271
|
const board = baseBoard;
|
|
1250
|
-
const {
|
|
1251
|
-
board.
|
|
1272
|
+
const { getDeletedFragment, setFragment, insertFragment } = board;
|
|
1273
|
+
board.getDeletedFragment = (data) => {
|
|
1252
1274
|
const drawElements = getSelectedDrawElements(board);
|
|
1253
1275
|
if (drawElements.length) {
|
|
1254
1276
|
const lines = getBoardLines(board);
|
|
1255
1277
|
const geometryElements = drawElements.filter(value => PlaitDrawElement.isGeometry(value));
|
|
1256
1278
|
const lineElements = drawElements.filter(value => PlaitDrawElement.isLine(value));
|
|
1257
1279
|
const boundLineElements = lines.filter(line => geometryElements.find(geometry => PlaitLine.isBoundElementOfSource(line, geometry) || PlaitLine.isBoundElementOfTarget(line, geometry)));
|
|
1258
|
-
|
|
1259
|
-
...geometryElements,
|
|
1260
|
-
...lineElements,
|
|
1261
|
-
...boundLineElements.filter(line => !lineElements.includes(line))
|
|
1262
|
-
]);
|
|
1280
|
+
data.push(...[...geometryElements, ...lineElements, ...boundLineElements.filter(line => !lineElements.includes(line))]);
|
|
1263
1281
|
}
|
|
1264
|
-
|
|
1282
|
+
return getDeletedFragment(data);
|
|
1265
1283
|
};
|
|
1266
1284
|
board.setFragment = (data, rectangle) => {
|
|
1267
1285
|
const targetDrawElements = getSelectedDrawElements(board);
|
|
@@ -1569,7 +1587,7 @@ const withLineText = (board) => {
|
|
|
1569
1587
|
return PlaitDrawElement.isLine(element);
|
|
1570
1588
|
})[0];
|
|
1571
1589
|
if (hitTarget) {
|
|
1572
|
-
const points =
|
|
1590
|
+
const points = getLinePoints(board, hitTarget);
|
|
1573
1591
|
const point = getNearestPointBetweenPointAndSegments(clickPoint, points);
|
|
1574
1592
|
const texts = hitTarget.texts?.length ? [...hitTarget.texts] : [];
|
|
1575
1593
|
const textIndex = getHitLineTextIndex(board, hitTarget, clickPoint);
|
|
@@ -1642,7 +1660,7 @@ const withDraw = (board) => {
|
|
|
1642
1660
|
return RectangleClient.isHit(rangeRectangle, client);
|
|
1643
1661
|
}
|
|
1644
1662
|
if (PlaitDrawElement.isLine(element)) {
|
|
1645
|
-
const points =
|
|
1663
|
+
const points = getLinePoints(board, element);
|
|
1646
1664
|
const strokeWidth = getStrokeWidthByElement(element);
|
|
1647
1665
|
const isHitText = isHitLineText(board, element, range.focus);
|
|
1648
1666
|
const isHit = isHitPolyLine(points, range.focus, strokeWidth, 3) || isHitText;
|
|
@@ -1671,5 +1689,5 @@ const withDraw = (board) => {
|
|
|
1671
1689
|
* Generated bundle index. Do not edit.
|
|
1672
1690
|
*/
|
|
1673
1691
|
|
|
1674
|
-
export { DefaultGeometryActiveStyle, DefaultGeometryProperty, DefaultGeometryStyle, DefaultTextProperty, DrawPointerType, GeometryComponent, GeometryPointer, GeometryShape, GeometryThreshold, LineComponent, LineMarkerType, LineShape, PlaitDrawElement, PlaitGeometry, PlaitLine, ShapeDefaultSpace, createGeometryElement, createLineElement, drawBoundMask,
|
|
1692
|
+
export { DefaultGeometryActiveStyle, DefaultGeometryProperty, DefaultGeometryStyle, DefaultTextProperty, DrawPointerType, GeometryComponent, GeometryPointer, GeometryShape, GeometryThreshold, LineComponent, LineMarkerType, LineShape, PlaitDrawElement, PlaitGeometry, PlaitLine, ShapeDefaultSpace, StrokeStyle, createGeometryElement, createLineElement, drawBoundMask, drawGeometry, drawLine, drawLineArrow, 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 };
|
|
1675
1693
|
//# sourceMappingURL=plait-draw.mjs.map
|