@plait/draw 0.1.0-next.10 → 0.1.0-next.11
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/line-active.generator.mjs +52 -0
- package/{esm2020 → esm2022}/geometry.component.mjs +4 -4
- package/esm2022/line.component.mjs +160 -0
- package/esm2022/plugins/with-draw-fragment.mjs +61 -0
- package/esm2022/plugins/with-draw.mjs +72 -0
- package/{esm2020 → esm2022}/utils/clipboard.mjs +2 -1
- package/{fesm2020 → fesm2022}/plait-draw.mjs +66 -35
- package/fesm2022/plait-draw.mjs.map +1 -0
- package/generators/line-active.generator.d.ts +1 -0
- package/line.component.d.ts +1 -0
- package/package.json +5 -11
- package/plugins/with-draw-fragment.d.ts +2 -0
- package/styles/styles.scss +2 -2
- package/esm2020/generators/line-active.generator.mjs +0 -36
- package/esm2020/line.component.mjs +0 -152
- package/esm2020/plugins/with-draw-fragment.mjs +0 -52
- package/esm2020/plugins/with-draw.mjs +0 -73
- 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}/constants/pointer.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/geometry.mjs +0 -0
- /package/{esm2020 → esm2022}/interfaces/index.mjs +0 -0
- /package/{esm2020 → esm2022}/interfaces/line.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/engine/diamond.mjs +0 -0
- /package/{esm2020 → esm2022}/utils/engine/ellipse.mjs +0 -0
- /package/{esm2020 → esm2022}/utils/engine/index.mjs +0 -0
- /package/{esm2020 → esm2022}/utils/engine/parallelogram.mjs +0 -0
- /package/{esm2020 → esm2022}/utils/engine/rectangle.mjs +0 -0
- /package/{esm2020 → esm2022}/utils/engine/round-rectangle.mjs +0 -0
- /package/{esm2020 → esm2022}/utils/geometry.mjs +0 -0
- /package/{esm2020 → esm2022}/utils/index.mjs +0 -0
- /package/{esm2020 → esm2022}/utils/line-arrow.mjs +0 -0
- /package/{esm2020 → esm2022}/utils/line.mjs +0 -0
- /package/{esm2020 → esm2022}/utils/position/geometry.mjs +0 -0
- /package/{esm2020 → esm2022}/utils/position/line.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
|
@@ -2,7 +2,7 @@ import { PlaitElement, ACTIVE_STROKE_WIDTH, RectangleClient, PlaitBoard, setStro
|
|
|
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, 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';
|
|
5
|
+
import { getRectangleByPoints, getFactorByPoints, Direction, getDirectionByPoint, getPoints, getPointOnPolyline, 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';
|
|
@@ -923,10 +923,10 @@ class GeometryComponent extends CommonPluginElement {
|
|
|
923
923
|
this.destroy$.next();
|
|
924
924
|
this.destroy$.complete();
|
|
925
925
|
}
|
|
926
|
+
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 }); }
|
|
927
|
+
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
928
|
}
|
|
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: [{
|
|
929
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: GeometryComponent, decorators: [{
|
|
930
930
|
type: Component,
|
|
931
931
|
args: [{
|
|
932
932
|
selector: 'plait-draw-geometry',
|
|
@@ -955,6 +955,10 @@ class LineShapeGenerator extends Generator {
|
|
|
955
955
|
}
|
|
956
956
|
|
|
957
957
|
class LineActiveGenerator extends Generator {
|
|
958
|
+
constructor() {
|
|
959
|
+
super(...arguments);
|
|
960
|
+
this.hasResizeHandle = false;
|
|
961
|
+
}
|
|
958
962
|
canDraw(element, data) {
|
|
959
963
|
if (data.selected) {
|
|
960
964
|
return true;
|
|
@@ -965,24 +969,35 @@ class LineActiveGenerator extends Generator {
|
|
|
965
969
|
}
|
|
966
970
|
baseDraw(element, data) {
|
|
967
971
|
const activeG = createG();
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
972
|
+
if (this.hasResizeHandle) {
|
|
973
|
+
activeG.classList.add('active');
|
|
974
|
+
activeG.classList.add('line-handle');
|
|
975
|
+
const sourcePoint = getSourcePoint(this.board, element);
|
|
976
|
+
const targetPoint = getTargetPoint(this.board, element);
|
|
977
|
+
const sourceCircle = drawCircle(PlaitBoard.getRoughSVG(this.board), sourcePoint, RESIZE_HANDLE_DIAMETER, {
|
|
978
|
+
stroke: '#999999',
|
|
979
|
+
strokeWidth: 1,
|
|
980
|
+
fill: '#FFF',
|
|
981
|
+
fillStyle: 'solid'
|
|
982
|
+
});
|
|
983
|
+
const targetCircle = drawCircle(PlaitBoard.getRoughSVG(this.board), targetPoint, RESIZE_HANDLE_DIAMETER, {
|
|
984
|
+
stroke: '#999999',
|
|
985
|
+
strokeWidth: 1,
|
|
986
|
+
fill: '#FFF',
|
|
987
|
+
fillStyle: 'solid'
|
|
988
|
+
});
|
|
989
|
+
activeG.appendChild(targetCircle);
|
|
990
|
+
activeG.appendChild(sourceCircle);
|
|
991
|
+
}
|
|
992
|
+
else {
|
|
993
|
+
const points = getLinePoints(this.board, element);
|
|
994
|
+
const activeRectangle = getRectangleByPoints(points);
|
|
995
|
+
const strokeG = drawRectangle(this.board, activeRectangle, {
|
|
996
|
+
stroke: PRIMARY_COLOR,
|
|
997
|
+
strokeWidth: DefaultGeometryActiveStyle.selectionStrokeWidth
|
|
998
|
+
});
|
|
999
|
+
activeG.appendChild(strokeG);
|
|
1000
|
+
}
|
|
986
1001
|
return activeG;
|
|
987
1002
|
}
|
|
988
1003
|
}
|
|
@@ -1041,11 +1056,18 @@ class LineComponent extends PlaitPluginElementComponent {
|
|
|
1041
1056
|
this.updateTextRectangle();
|
|
1042
1057
|
return;
|
|
1043
1058
|
}
|
|
1044
|
-
|
|
1045
|
-
|
|
1059
|
+
if (!isSelectionMoving(this.board)) {
|
|
1060
|
+
this.activeGenerator.hasResizeHandle = this.hasResizeHandle();
|
|
1046
1061
|
this.activeGenerator.draw(this.element, PlaitBoard.getElementActiveHost(this.board), { selected: this.selected });
|
|
1047
1062
|
}
|
|
1048
1063
|
}
|
|
1064
|
+
hasResizeHandle() {
|
|
1065
|
+
const selectedElements = getSelectedElements(this.board);
|
|
1066
|
+
if (PlaitBoard.hasBeenTextEditing(this.board) && PlaitDrawElement.isText(this.element)) {
|
|
1067
|
+
return false;
|
|
1068
|
+
}
|
|
1069
|
+
return selectedElements.length === 1 && !isSelectionMoving(this.board);
|
|
1070
|
+
}
|
|
1049
1071
|
initializeTextManages() {
|
|
1050
1072
|
if (this.element.texts?.length) {
|
|
1051
1073
|
this.element.texts.forEach((text, index) => {
|
|
@@ -1117,10 +1139,10 @@ class LineComponent extends PlaitPluginElementComponent {
|
|
|
1117
1139
|
this.destroy$.next();
|
|
1118
1140
|
this.destroy$.complete();
|
|
1119
1141
|
}
|
|
1142
|
+
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 }); }
|
|
1143
|
+
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
1144
|
}
|
|
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: [{
|
|
1145
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: LineComponent, decorators: [{
|
|
1124
1146
|
type: Component,
|
|
1125
1147
|
args: [{
|
|
1126
1148
|
selector: 'plait-draw-line',
|
|
@@ -1358,6 +1380,7 @@ const insertClipboardData = (board, elements, startPoint) => {
|
|
|
1358
1380
|
element.points = element.points.map(point => [startPoint[0] + point[0], startPoint[1] + point[1]]);
|
|
1359
1381
|
Transforms.insertNode(board, element, [board.children.length]);
|
|
1360
1382
|
});
|
|
1383
|
+
Transforms.addSelectionWithTemporaryElements(board, elements);
|
|
1361
1384
|
};
|
|
1362
1385
|
|
|
1363
1386
|
const withDrawFragment = (baseBoard) => {
|
|
@@ -1366,21 +1389,26 @@ const withDrawFragment = (baseBoard) => {
|
|
|
1366
1389
|
board.getDeletedFragment = (data) => {
|
|
1367
1390
|
const drawElements = getSelectedDrawElements(board);
|
|
1368
1391
|
if (drawElements.length) {
|
|
1369
|
-
const lines = getBoardLines(board);
|
|
1370
1392
|
const geometryElements = drawElements.filter(value => PlaitDrawElement.isGeometry(value));
|
|
1371
1393
|
const lineElements = drawElements.filter(value => PlaitDrawElement.isLine(value));
|
|
1372
|
-
const boundLineElements =
|
|
1394
|
+
const boundLineElements = getBoundedLineElements(board, geometryElements).filter(line => !lineElements.includes(line));
|
|
1373
1395
|
data.push(...[...geometryElements, ...lineElements, ...boundLineElements.filter(line => !lineElements.includes(line))]);
|
|
1374
1396
|
}
|
|
1375
1397
|
return getDeletedFragment(data);
|
|
1376
1398
|
};
|
|
1377
|
-
board.setFragment = (data, rectangle) => {
|
|
1399
|
+
board.setFragment = (data, rectangle, type) => {
|
|
1378
1400
|
const targetDrawElements = getSelectedDrawElements(board);
|
|
1401
|
+
let boundLineElements = [];
|
|
1379
1402
|
if (targetDrawElements.length) {
|
|
1380
|
-
|
|
1403
|
+
if (type === 'cut') {
|
|
1404
|
+
const geometryElements = targetDrawElements.filter(value => PlaitDrawElement.isGeometry(value));
|
|
1405
|
+
const lineElements = targetDrawElements.filter(value => PlaitDrawElement.isLine(value));
|
|
1406
|
+
boundLineElements = getBoundedLineElements(board, geometryElements).filter(line => !lineElements.includes(line));
|
|
1407
|
+
}
|
|
1408
|
+
const elements = buildClipboardData(board, [...targetDrawElements, ...boundLineElements], rectangle ? [rectangle.x, rectangle.y] : [0, 0]);
|
|
1381
1409
|
setClipboardData(data, elements);
|
|
1382
1410
|
}
|
|
1383
|
-
setFragment(data, rectangle);
|
|
1411
|
+
setFragment(data, rectangle, type);
|
|
1384
1412
|
};
|
|
1385
1413
|
board.insertFragment = (data, targetPoint) => {
|
|
1386
1414
|
const elements = getDataFromClipboard(data);
|
|
@@ -1404,6 +1432,10 @@ const withDrawFragment = (baseBoard) => {
|
|
|
1404
1432
|
};
|
|
1405
1433
|
return board;
|
|
1406
1434
|
};
|
|
1435
|
+
const getBoundedLineElements = (board, geometries) => {
|
|
1436
|
+
const lines = getBoardLines(board);
|
|
1437
|
+
return lines.filter(line => geometries.find(geometry => PlaitLine.isBoundElementOfSource(line, geometry) || PlaitLine.isBoundElementOfTarget(line, geometry)));
|
|
1438
|
+
};
|
|
1407
1439
|
|
|
1408
1440
|
const DefaultLineStyle = {
|
|
1409
1441
|
strokeWidth: 2,
|
|
@@ -1736,9 +1768,8 @@ const withDraw = (board) => {
|
|
|
1736
1768
|
return getRectangleByPoints(element.points);
|
|
1737
1769
|
}
|
|
1738
1770
|
if (PlaitDrawElement.isLine(element)) {
|
|
1739
|
-
const
|
|
1740
|
-
|
|
1741
|
-
return getRectangleByPoints([source, target]);
|
|
1771
|
+
const points = getLinePoints(board, element);
|
|
1772
|
+
return getRectangleByPoints(points);
|
|
1742
1773
|
}
|
|
1743
1774
|
return getRectangle(element);
|
|
1744
1775
|
};
|