@plait/draw 0.37.0 → 0.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2022/plugins/with-geometry-create.mjs +20 -32
- package/esm2022/transforms/geometry.mjs +3 -3
- package/esm2022/utils/geometry.mjs +29 -11
- package/esm2022/utils/memorize.mjs +2 -2
- package/fesm2022/plait-draw.mjs +227 -220
- package/fesm2022/plait-draw.mjs.map +1 -1
- package/package.json +1 -1
- package/plugins/with-geometry-create.d.ts +1 -7
- package/utils/geometry.d.ts +10 -2
package/fesm2022/plait-draw.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { PlaitElement, ACTIVE_STROKE_WIDTH, ThemeColorMode, PlaitBoard, setStrokeLinecap, isPointInPolygon, getNearestPointBetweenPointAndSegments, RectangleClient, isPointInEllipse, drawRectangle, drawRoundRectangle, isPointInRoundRectangle,
|
|
2
|
-
import { getRectangleByPoints,
|
|
3
|
-
import {
|
|
4
|
-
import { isKeyHotkey } from 'is-hotkey';
|
|
5
|
-
import * as i0 from '@angular/core';
|
|
6
|
-
import { NgZone, Component, ChangeDetectionStrategy } from '@angular/core';
|
|
1
|
+
import { PlaitElement, ACTIVE_STROKE_WIDTH, ThemeColorMode, PlaitBoard, setStrokeLinecap, isPointInPolygon, getNearestPointBetweenPointAndSegments, RectangleClient, isPointInEllipse, drawRectangle, drawRoundRectangle, isPointInRoundRectangle, idCreator, createG, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, drawCircle, distanceBetweenPointAndSegment, arrowPoints, createPath, distanceBetweenPointAndPoint, drawLinearPath, rotate, depthFirstRecursion, getIsRecursionFunc, getElementById, Direction, catmullRomFitting, distanceBetweenPointAndSegments, createMask, createRect, findElements, Point, getSelectedElements, isPolylineHitRectangle, Transforms, clearSelectedElement, addSelectedElement, PlaitNode, BOARD_TO_HOST, transformPoint, toPoint, isSelectionMoving, RgbaToHEX, PlaitPluginElementComponent, preventTouchMove, BoardTransforms, PlaitPointerType, setClipboardData, getDataFromClipboard, getHitElementByPoint, CursorClass, temporaryDisableSelection, PRESS_AND_MOVE_BUFFER } from '@plait/core';
|
|
2
|
+
import { getRectangleByPoints, RESIZE_HANDLE_DIAMETER, getExtendPoint, getFactorByPoints, Generator, getRectangleResizeHandleRefs, getMemorizedLatest, memorizeLatest, getDirectionByVector, getOppositeDirection, getDirectionFactor, DEFAULT_ROUTE_MARGIN, reduceRouteMargin, getNextPoint, generateElbowLineRoute, getPoints, removeDuplicatePoints, getPointByVector, getPointOnPolyline, getDirectionByPointOfRectangle, rotateVectorAnti90, TRANSPARENT, normalizeShapePoints, PRIMARY_COLOR, CommonPluginElement, ActiveGenerator, WithTextPluginKey, isVirtualKey, isDelete, isSpaceHotkey, isDndMode, isDrawingMode, acceptImageTypes, getElementOfFocusedImage, buildImage, ResizeHandle, withResize, isResizingByCondition, getRatioByPoint, ImageGenerator } from '@plait/common';
|
|
3
|
+
import { Alignment, buildText, DEFAULT_FONT_SIZE, getTextSize, AlignEditor, TextManage, getTextFromClipboard } from '@plait/text';
|
|
7
4
|
import { pointsOnBezierCurves } from 'points-on-curve';
|
|
5
|
+
import * as i0 from '@angular/core';
|
|
6
|
+
import { Component, ChangeDetectionStrategy, NgZone } from '@angular/core';
|
|
8
7
|
import { Subject } from 'rxjs';
|
|
8
|
+
import { isKeyHotkey } from 'is-hotkey';
|
|
9
9
|
import { Node } from 'slate';
|
|
10
10
|
|
|
11
11
|
var BasicShapes;
|
|
@@ -1200,208 +1200,6 @@ const getShape = (value) => {
|
|
|
1200
1200
|
return value.shape;
|
|
1201
1201
|
};
|
|
1202
1202
|
|
|
1203
|
-
class GeometryShapeGenerator extends Generator {
|
|
1204
|
-
canDraw(element, data) {
|
|
1205
|
-
return true;
|
|
1206
|
-
}
|
|
1207
|
-
draw(element, data) {
|
|
1208
|
-
const rectangle = getRectangleByPoints(element.points);
|
|
1209
|
-
const shape = element.shape;
|
|
1210
|
-
if (shape === BasicShapes.text) {
|
|
1211
|
-
return;
|
|
1212
|
-
}
|
|
1213
|
-
const strokeWidth = getStrokeWidthByElement(element);
|
|
1214
|
-
const strokeColor = getStrokeColorByElement(this.board, element);
|
|
1215
|
-
const fill = getFillByElement(this.board, element);
|
|
1216
|
-
const strokeLineDash = getLineDashByElement(element);
|
|
1217
|
-
return drawGeometry(this.board, RectangleClient.inflate(rectangle, -strokeWidth), shape, {
|
|
1218
|
-
stroke: strokeColor,
|
|
1219
|
-
strokeWidth,
|
|
1220
|
-
fill,
|
|
1221
|
-
strokeLineDash
|
|
1222
|
-
});
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
|
|
1226
|
-
const withGeometryCreateByDrag = (board) => {
|
|
1227
|
-
const { pointerMove, pointerUp } = board;
|
|
1228
|
-
let geometryShapeG = null;
|
|
1229
|
-
let temporaryElement = null;
|
|
1230
|
-
let fakeCreateTextRef = null;
|
|
1231
|
-
board.pointerMove = (event) => {
|
|
1232
|
-
geometryShapeG?.remove();
|
|
1233
|
-
geometryShapeG = createG();
|
|
1234
|
-
const geometryGenerator = new GeometryShapeGenerator(board);
|
|
1235
|
-
const geometryPointers = getGeometryPointers();
|
|
1236
|
-
const isGeometryPointer = PlaitBoard.isInPointer(board, geometryPointers);
|
|
1237
|
-
const dragMode = isGeometryPointer && isDndMode(board);
|
|
1238
|
-
const movingPoint = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
|
|
1239
|
-
const pointer = PlaitBoard.getPointer(board);
|
|
1240
|
-
if (dragMode) {
|
|
1241
|
-
const memorizedLatest = getMemorizedLatestByPointer(pointer);
|
|
1242
|
-
if (pointer === BasicShapes.text) {
|
|
1243
|
-
const points = getDefaultGeometryPoints(board, pointer, movingPoint, memorizedLatest.textProperties['font-size']);
|
|
1244
|
-
temporaryElement = createGeometryElement(board, BasicShapes.text, points, DefaultTextProperty.text, memorizedLatest.geometryProperties, memorizedLatest.textProperties);
|
|
1245
|
-
if (!fakeCreateTextRef) {
|
|
1246
|
-
const textManage = new TextManage(board, PlaitBoard.getComponent(board).viewContainerRef, {
|
|
1247
|
-
getRectangle: () => {
|
|
1248
|
-
return getTextRectangle(temporaryElement);
|
|
1249
|
-
}
|
|
1250
|
-
});
|
|
1251
|
-
PlaitBoard.getComponent(board)
|
|
1252
|
-
.viewContainerRef.injector.get(NgZone)
|
|
1253
|
-
.run(() => {
|
|
1254
|
-
textManage.draw(temporaryElement.text);
|
|
1255
|
-
});
|
|
1256
|
-
fakeCreateTextRef = {
|
|
1257
|
-
g: createG(),
|
|
1258
|
-
textManage
|
|
1259
|
-
};
|
|
1260
|
-
PlaitBoard.getHost(board).append(fakeCreateTextRef.g);
|
|
1261
|
-
fakeCreateTextRef.g.append(textManage.g);
|
|
1262
|
-
}
|
|
1263
|
-
else {
|
|
1264
|
-
fakeCreateTextRef.textManage.updateRectangle();
|
|
1265
|
-
fakeCreateTextRef.g.append(fakeCreateTextRef.textManage.g);
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
else {
|
|
1269
|
-
const points = getDefaultGeometryPoints(board, pointer, movingPoint);
|
|
1270
|
-
temporaryElement = createGeometryElement(board, pointer, points, '', {
|
|
1271
|
-
strokeWidth: DefaultBasicShapeProperty.strokeWidth,
|
|
1272
|
-
...memorizedLatest.geometryProperties
|
|
1273
|
-
}, memorizedLatest.textProperties);
|
|
1274
|
-
geometryGenerator.processDrawing(temporaryElement, geometryShapeG);
|
|
1275
|
-
PlaitBoard.getElementActiveHost(board).append(geometryShapeG);
|
|
1276
|
-
}
|
|
1277
|
-
}
|
|
1278
|
-
pointerMove(event);
|
|
1279
|
-
};
|
|
1280
|
-
board.pointerUp = (event) => {
|
|
1281
|
-
const geometryPointers = getGeometryPointers();
|
|
1282
|
-
const isGeometryPointer = PlaitBoard.isInPointer(board, geometryPointers);
|
|
1283
|
-
const dragMode = isGeometryPointer && isDndMode(board);
|
|
1284
|
-
if (dragMode && temporaryElement) {
|
|
1285
|
-
insertElement(board, temporaryElement);
|
|
1286
|
-
fakeCreateTextRef?.textManage.destroy();
|
|
1287
|
-
fakeCreateTextRef?.g.remove();
|
|
1288
|
-
fakeCreateTextRef = null;
|
|
1289
|
-
}
|
|
1290
|
-
geometryShapeG?.remove();
|
|
1291
|
-
geometryShapeG = null;
|
|
1292
|
-
preventTouchMove(board, event, false);
|
|
1293
|
-
pointerUp(event);
|
|
1294
|
-
};
|
|
1295
|
-
return board;
|
|
1296
|
-
};
|
|
1297
|
-
const withGeometryCreateByDrawing = (board) => {
|
|
1298
|
-
const { pointerDown, pointerMove, pointerUp, keydown, keyup } = board;
|
|
1299
|
-
let start = null;
|
|
1300
|
-
let geometryShapeG = null;
|
|
1301
|
-
let temporaryElement = null;
|
|
1302
|
-
let isShift = false;
|
|
1303
|
-
board.keydown = (event) => {
|
|
1304
|
-
isShift = isKeyHotkey('shift', event);
|
|
1305
|
-
keydown(event);
|
|
1306
|
-
};
|
|
1307
|
-
board.keyup = (event) => {
|
|
1308
|
-
isShift = false;
|
|
1309
|
-
keyup(event);
|
|
1310
|
-
};
|
|
1311
|
-
board.pointerDown = (event) => {
|
|
1312
|
-
const geometryPointers = getGeometryPointers();
|
|
1313
|
-
const isGeometryPointer = PlaitBoard.isInPointer(board, geometryPointers);
|
|
1314
|
-
if (!PlaitBoard.isReadonly(board) && isGeometryPointer && isDrawingMode(board)) {
|
|
1315
|
-
const point = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
|
|
1316
|
-
start = point;
|
|
1317
|
-
const pointer = PlaitBoard.getPointer(board);
|
|
1318
|
-
preventTouchMove(board, event, true);
|
|
1319
|
-
if (pointer === BasicShapes.text) {
|
|
1320
|
-
const memorizedLatest = getMemorizedLatestByPointer(pointer);
|
|
1321
|
-
const points = getDefaultGeometryPoints(board, pointer, point, memorizedLatest.textProperties['font-size']);
|
|
1322
|
-
const textElement = createGeometryElement(board, BasicShapes.text, points, DefaultTextProperty.text, memorizedLatest.geometryProperties, memorizedLatest.textProperties);
|
|
1323
|
-
Transforms.insertNode(board, textElement, [board.children.length]);
|
|
1324
|
-
clearSelectedElement(board);
|
|
1325
|
-
addSelectedElement(board, textElement);
|
|
1326
|
-
BoardTransforms.updatePointerType(board, PlaitPointerType.selection);
|
|
1327
|
-
start = null;
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
pointerDown(event);
|
|
1331
|
-
};
|
|
1332
|
-
board.pointerMove = (event) => {
|
|
1333
|
-
geometryShapeG?.remove();
|
|
1334
|
-
geometryShapeG = createG();
|
|
1335
|
-
const geometryGenerator = new GeometryShapeGenerator(board);
|
|
1336
|
-
const drawMode = !!start;
|
|
1337
|
-
const movingPoint = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
|
|
1338
|
-
const pointer = PlaitBoard.getPointer(board);
|
|
1339
|
-
if (drawMode && pointer !== BasicShapes.text) {
|
|
1340
|
-
const points = normalizeShapePoints([start, movingPoint], isShift);
|
|
1341
|
-
const memorizedLatest = getMemorizedLatestByPointer(pointer);
|
|
1342
|
-
temporaryElement = createGeometryElement(board, pointer, points, '', {
|
|
1343
|
-
strokeWidth: DefaultBasicShapeProperty.strokeWidth,
|
|
1344
|
-
...memorizedLatest.geometryProperties
|
|
1345
|
-
}, memorizedLatest.textProperties);
|
|
1346
|
-
geometryGenerator.processDrawing(temporaryElement, geometryShapeG);
|
|
1347
|
-
PlaitBoard.getElementActiveHost(board).append(geometryShapeG);
|
|
1348
|
-
}
|
|
1349
|
-
pointerMove(event);
|
|
1350
|
-
};
|
|
1351
|
-
board.pointerUp = (event) => {
|
|
1352
|
-
const isDrawMode = !!start;
|
|
1353
|
-
if (isDrawMode) {
|
|
1354
|
-
const targetPoint = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
|
|
1355
|
-
const { width, height } = RectangleClient.toRectangleClient([start, targetPoint]);
|
|
1356
|
-
if (Math.hypot(width, height) === 0) {
|
|
1357
|
-
const pointer = PlaitBoard.getPointer(board);
|
|
1358
|
-
const points = getDefaultGeometryPoints(board, pointer, targetPoint);
|
|
1359
|
-
if (pointer !== BasicShapes.text) {
|
|
1360
|
-
const memorizedLatest = getMemorizedLatestByPointer(pointer);
|
|
1361
|
-
temporaryElement = createGeometryElement(board, pointer, points, '', {
|
|
1362
|
-
strokeWidth: DefaultBasicShapeProperty.strokeWidth,
|
|
1363
|
-
...memorizedLatest.geometryProperties
|
|
1364
|
-
}, memorizedLatest.textProperties);
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
if (temporaryElement) {
|
|
1369
|
-
insertElement(board, temporaryElement);
|
|
1370
|
-
}
|
|
1371
|
-
geometryShapeG?.remove();
|
|
1372
|
-
geometryShapeG = null;
|
|
1373
|
-
start = null;
|
|
1374
|
-
temporaryElement = null;
|
|
1375
|
-
preventTouchMove(board, event, false);
|
|
1376
|
-
pointerUp(event);
|
|
1377
|
-
};
|
|
1378
|
-
return board;
|
|
1379
|
-
};
|
|
1380
|
-
const getDefaultGeometryPoints = (board, pointer, targetPoint, fontSize) => {
|
|
1381
|
-
const defaultProperty = getGeometryDefaultProperty(board, pointer, fontSize);
|
|
1382
|
-
return getPointsByCenterPoint(targetPoint, defaultProperty.width, defaultProperty.height);
|
|
1383
|
-
};
|
|
1384
|
-
const getGeometryDefaultProperty = (board, pointer, fontSize) => {
|
|
1385
|
-
const isText = pointer === BasicShapes.text;
|
|
1386
|
-
const isFlowChart = getFlowchartPointers().includes(pointer);
|
|
1387
|
-
if (isText) {
|
|
1388
|
-
return getDefaultTextShapeProperty(board, fontSize);
|
|
1389
|
-
}
|
|
1390
|
-
else if (isFlowChart) {
|
|
1391
|
-
return getDefaultFlowchartProperty(pointer);
|
|
1392
|
-
}
|
|
1393
|
-
else {
|
|
1394
|
-
return DefaultBasicShapeProperty;
|
|
1395
|
-
}
|
|
1396
|
-
};
|
|
1397
|
-
const insertElement = (board, element) => {
|
|
1398
|
-
memorizeLatestShape(board, element.shape);
|
|
1399
|
-
Transforms.insertNode(board, element, [board.children.length]);
|
|
1400
|
-
clearSelectedElement(board);
|
|
1401
|
-
addSelectedElement(board, element);
|
|
1402
|
-
BoardTransforms.updatePointerType(board, PlaitPointerType.selection);
|
|
1403
|
-
};
|
|
1404
|
-
|
|
1405
1203
|
const DefaultLineStyle = {
|
|
1406
1204
|
strokeWidth: 2,
|
|
1407
1205
|
strokeColor: '#000'
|
|
@@ -1412,17 +1210,19 @@ const LINE_AUTO_COMPLETE_OPACITY = 0.6;
|
|
|
1412
1210
|
const LINE_AUTO_COMPLETE_HOVERED_OPACITY = 0.8;
|
|
1413
1211
|
const LINE_AUTO_COMPLETE_HOVERED_DIAMETER = 10;
|
|
1414
1212
|
|
|
1415
|
-
const createGeometryElement = (
|
|
1213
|
+
const createGeometryElement = (shape, points, text, options = {}, textProperties = {}) => {
|
|
1416
1214
|
let textOptions = {};
|
|
1417
1215
|
let alignment = Alignment.center;
|
|
1216
|
+
let textHeight = DefaultTextProperty.height;
|
|
1418
1217
|
if (shape === BasicShapes.text) {
|
|
1419
1218
|
textOptions = { autoSize: true };
|
|
1420
1219
|
alignment = undefined;
|
|
1421
1220
|
}
|
|
1422
1221
|
textProperties = { ...textProperties };
|
|
1423
1222
|
textProperties?.align && (alignment = textProperties?.align);
|
|
1223
|
+
textProperties?.textHeight && (textHeight = textProperties?.textHeight);
|
|
1424
1224
|
delete textProperties?.align;
|
|
1425
|
-
|
|
1225
|
+
delete textProperties?.textHeight;
|
|
1426
1226
|
return {
|
|
1427
1227
|
id: idCreator(),
|
|
1428
1228
|
type: 'geometry',
|
|
@@ -1508,7 +1308,7 @@ const getEdgeOnPolygonByPoint = (corners, point) => {
|
|
|
1508
1308
|
const getDefaultFlowchartProperty = (symbol) => {
|
|
1509
1309
|
return DefaultFlowchartPropertyMap[symbol];
|
|
1510
1310
|
};
|
|
1511
|
-
const createDefaultFlowchart = (
|
|
1311
|
+
const createDefaultFlowchart = (point) => {
|
|
1512
1312
|
const decisionProperty = getDefaultFlowchartProperty(FlowchartSymbols.decision);
|
|
1513
1313
|
const processProperty = getDefaultFlowchartProperty(FlowchartSymbols.process);
|
|
1514
1314
|
const terminalProperty = getDefaultFlowchartProperty(FlowchartSymbols.terminal);
|
|
@@ -1518,15 +1318,15 @@ const createDefaultFlowchart = (board, point) => {
|
|
|
1518
1318
|
const lineOptions = {
|
|
1519
1319
|
strokeWidth: DefaultLineStyle.strokeWidth
|
|
1520
1320
|
};
|
|
1521
|
-
const startElement = createGeometryElement(
|
|
1321
|
+
const startElement = createGeometryElement(FlowchartSymbols.terminal, getDefaultGeometryPoints(FlowchartSymbols.terminal, point), '开始', options);
|
|
1522
1322
|
const processPoint1 = [point[0], point[1] + terminalProperty.height / 2 + 55 + processProperty.height / 2];
|
|
1523
|
-
const processElement1 = createGeometryElement(
|
|
1323
|
+
const processElement1 = createGeometryElement(FlowchartSymbols.process, getDefaultGeometryPoints(FlowchartSymbols.process, processPoint1), '过程', options);
|
|
1524
1324
|
const decisionPoint = [processPoint1[0], processPoint1[1] + processProperty.height / 2 + 55 + decisionProperty.height / 2];
|
|
1525
|
-
const decisionElement = createGeometryElement(
|
|
1325
|
+
const decisionElement = createGeometryElement(FlowchartSymbols.decision, getDefaultGeometryPoints(FlowchartSymbols.decision, decisionPoint), '过程', options);
|
|
1526
1326
|
const processPoint2 = [decisionPoint[0] + decisionProperty.width / 2 + 75 + processProperty.width / 2, decisionPoint[1]];
|
|
1527
|
-
const processElement2 = createGeometryElement(
|
|
1327
|
+
const processElement2 = createGeometryElement(FlowchartSymbols.process, getDefaultGeometryPoints(FlowchartSymbols.process, processPoint2), '过程', options);
|
|
1528
1328
|
const endPoint = [decisionPoint[0], decisionPoint[1] + decisionProperty.height / 2 + 95 + terminalProperty.height / 2];
|
|
1529
|
-
const endElement = createGeometryElement(
|
|
1329
|
+
const endElement = createGeometryElement(FlowchartSymbols.terminal, getDefaultGeometryPoints(FlowchartSymbols.terminal, endPoint), '结束', options);
|
|
1530
1330
|
const line1 = createLineElement(LineShape.elbow, [
|
|
1531
1331
|
[0, 0],
|
|
1532
1332
|
[0, 0]
|
|
@@ -1592,6 +1392,23 @@ const getDefaultTextShapeProperty = (board, fontSize) => {
|
|
|
1592
1392
|
text: '文本'
|
|
1593
1393
|
};
|
|
1594
1394
|
};
|
|
1395
|
+
const getDefaultGeometryPoints = (pointer, centerPoint) => {
|
|
1396
|
+
const defaultProperty = getDefaultGeometryProperty(pointer);
|
|
1397
|
+
return getPointsByCenterPoint(centerPoint, defaultProperty.width, defaultProperty.height);
|
|
1398
|
+
};
|
|
1399
|
+
const getDefaultGeometryProperty = (pointer) => {
|
|
1400
|
+
const isFlowChart = getFlowchartPointers().includes(pointer);
|
|
1401
|
+
if (isFlowChart) {
|
|
1402
|
+
return getDefaultFlowchartProperty(pointer);
|
|
1403
|
+
}
|
|
1404
|
+
else {
|
|
1405
|
+
return DefaultBasicShapeProperty;
|
|
1406
|
+
}
|
|
1407
|
+
};
|
|
1408
|
+
const getDefaultTextPoints = (board, centerPoint, fontSize) => {
|
|
1409
|
+
const property = getDefaultTextShapeProperty(board, fontSize);
|
|
1410
|
+
return getPointsByCenterPoint(centerPoint, property.width, property.height);
|
|
1411
|
+
};
|
|
1595
1412
|
|
|
1596
1413
|
const ARROW_LENGTH = 20;
|
|
1597
1414
|
const drawLineArrow = (element, points, options) => {
|
|
@@ -1785,7 +1602,7 @@ const getMemorizedLatestByPointer = (pointer) => {
|
|
|
1785
1602
|
memorizeKey = MemorizeKey.flowchart;
|
|
1786
1603
|
}
|
|
1787
1604
|
const properties = { ...getMemorizedLatest(memorizeKey) } || {};
|
|
1788
|
-
const textProperties = properties.text || {};
|
|
1605
|
+
const textProperties = { ...properties.text } || {};
|
|
1789
1606
|
delete properties.text;
|
|
1790
1607
|
return { textProperties, geometryProperties: properties };
|
|
1791
1608
|
};
|
|
@@ -2372,8 +2189,31 @@ const PlaitDrawElement = {
|
|
|
2372
2189
|
}
|
|
2373
2190
|
};
|
|
2374
2191
|
|
|
2192
|
+
class GeometryShapeGenerator extends Generator {
|
|
2193
|
+
canDraw(element, data) {
|
|
2194
|
+
return true;
|
|
2195
|
+
}
|
|
2196
|
+
draw(element, data) {
|
|
2197
|
+
const rectangle = getRectangleByPoints(element.points);
|
|
2198
|
+
const shape = element.shape;
|
|
2199
|
+
if (shape === BasicShapes.text) {
|
|
2200
|
+
return;
|
|
2201
|
+
}
|
|
2202
|
+
const strokeWidth = getStrokeWidthByElement(element);
|
|
2203
|
+
const strokeColor = getStrokeColorByElement(this.board, element);
|
|
2204
|
+
const fill = getFillByElement(this.board, element);
|
|
2205
|
+
const strokeLineDash = getLineDashByElement(element);
|
|
2206
|
+
return drawGeometry(this.board, RectangleClient.inflate(rectangle, -strokeWidth), shape, {
|
|
2207
|
+
stroke: strokeColor,
|
|
2208
|
+
strokeWidth,
|
|
2209
|
+
fill,
|
|
2210
|
+
strokeLineDash
|
|
2211
|
+
});
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
|
|
2375
2215
|
const insertGeometry = (board, points, shape) => {
|
|
2376
|
-
let newElement = createGeometryElement(
|
|
2216
|
+
let newElement = createGeometryElement(shape, points, '', {
|
|
2377
2217
|
strokeWidth: DefaultBasicShapeProperty.strokeWidth
|
|
2378
2218
|
});
|
|
2379
2219
|
Transforms.insertNode(board, newElement, [board.children.length]);
|
|
@@ -2381,7 +2221,7 @@ const insertGeometry = (board, points, shape) => {
|
|
|
2381
2221
|
addSelectedElement(board, newElement);
|
|
2382
2222
|
};
|
|
2383
2223
|
const insertText = (board, points, text = '文本') => {
|
|
2384
|
-
let newElement = createGeometryElement(
|
|
2224
|
+
let newElement = createGeometryElement(BasicShapes.text, points, text);
|
|
2385
2225
|
Transforms.insertNode(board, newElement, [board.children.length]);
|
|
2386
2226
|
clearSelectedElement(board);
|
|
2387
2227
|
addSelectedElement(board, newElement);
|
|
@@ -2952,6 +2792,173 @@ const withDrawHotkey = (board) => {
|
|
|
2952
2792
|
return board;
|
|
2953
2793
|
};
|
|
2954
2794
|
|
|
2795
|
+
const withGeometryCreateByDrag = (board) => {
|
|
2796
|
+
const { pointerMove, pointerUp } = board;
|
|
2797
|
+
let geometryShapeG = null;
|
|
2798
|
+
let temporaryElement = null;
|
|
2799
|
+
let fakeCreateTextRef = null;
|
|
2800
|
+
board.pointerMove = (event) => {
|
|
2801
|
+
geometryShapeG?.remove();
|
|
2802
|
+
geometryShapeG = createG();
|
|
2803
|
+
const geometryGenerator = new GeometryShapeGenerator(board);
|
|
2804
|
+
const geometryPointers = getGeometryPointers();
|
|
2805
|
+
const isGeometryPointer = PlaitBoard.isInPointer(board, geometryPointers);
|
|
2806
|
+
const dragMode = isGeometryPointer && isDndMode(board);
|
|
2807
|
+
const movingPoint = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
|
|
2808
|
+
const pointer = PlaitBoard.getPointer(board);
|
|
2809
|
+
if (dragMode) {
|
|
2810
|
+
const memorizedLatest = getMemorizedLatestByPointer(pointer);
|
|
2811
|
+
if (pointer === BasicShapes.text) {
|
|
2812
|
+
const property = getDefaultTextShapeProperty(board, memorizedLatest.textProperties['font-size']);
|
|
2813
|
+
const points = getPointsByCenterPoint(movingPoint, property.width, property.height);
|
|
2814
|
+
temporaryElement = createGeometryElement(BasicShapes.text, points, DefaultTextProperty.text, memorizedLatest.geometryProperties, { ...memorizedLatest.textProperties, textHeight: property.height });
|
|
2815
|
+
if (!fakeCreateTextRef) {
|
|
2816
|
+
const textManage = new TextManage(board, PlaitBoard.getComponent(board).viewContainerRef, {
|
|
2817
|
+
getRectangle: () => {
|
|
2818
|
+
return getTextRectangle(temporaryElement);
|
|
2819
|
+
}
|
|
2820
|
+
});
|
|
2821
|
+
PlaitBoard.getComponent(board)
|
|
2822
|
+
.viewContainerRef.injector.get(NgZone)
|
|
2823
|
+
.run(() => {
|
|
2824
|
+
textManage.draw(temporaryElement.text);
|
|
2825
|
+
});
|
|
2826
|
+
fakeCreateTextRef = {
|
|
2827
|
+
g: createG(),
|
|
2828
|
+
textManage
|
|
2829
|
+
};
|
|
2830
|
+
PlaitBoard.getHost(board).append(fakeCreateTextRef.g);
|
|
2831
|
+
fakeCreateTextRef.g.append(textManage.g);
|
|
2832
|
+
}
|
|
2833
|
+
else {
|
|
2834
|
+
fakeCreateTextRef.textManage.updateRectangle();
|
|
2835
|
+
fakeCreateTextRef.g.append(fakeCreateTextRef.textManage.g);
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
else {
|
|
2839
|
+
const points = getDefaultGeometryPoints(pointer, movingPoint);
|
|
2840
|
+
const textHeight = getDefaultTextShapeProperty(board, memorizedLatest.textProperties['font-size']).height;
|
|
2841
|
+
temporaryElement = createGeometryElement(pointer, points, '', {
|
|
2842
|
+
strokeWidth: DefaultBasicShapeProperty.strokeWidth,
|
|
2843
|
+
...memorizedLatest.geometryProperties
|
|
2844
|
+
}, { ...memorizedLatest.textProperties, textHeight });
|
|
2845
|
+
geometryGenerator.processDrawing(temporaryElement, geometryShapeG);
|
|
2846
|
+
PlaitBoard.getElementActiveHost(board).append(geometryShapeG);
|
|
2847
|
+
}
|
|
2848
|
+
}
|
|
2849
|
+
pointerMove(event);
|
|
2850
|
+
};
|
|
2851
|
+
board.pointerUp = (event) => {
|
|
2852
|
+
const geometryPointers = getGeometryPointers();
|
|
2853
|
+
const isGeometryPointer = PlaitBoard.isInPointer(board, geometryPointers);
|
|
2854
|
+
const dragMode = isGeometryPointer && isDndMode(board);
|
|
2855
|
+
if (dragMode && temporaryElement) {
|
|
2856
|
+
insertElement(board, temporaryElement);
|
|
2857
|
+
fakeCreateTextRef?.textManage.destroy();
|
|
2858
|
+
fakeCreateTextRef?.g.remove();
|
|
2859
|
+
fakeCreateTextRef = null;
|
|
2860
|
+
}
|
|
2861
|
+
geometryShapeG?.remove();
|
|
2862
|
+
geometryShapeG = null;
|
|
2863
|
+
preventTouchMove(board, event, false);
|
|
2864
|
+
pointerUp(event);
|
|
2865
|
+
};
|
|
2866
|
+
return board;
|
|
2867
|
+
};
|
|
2868
|
+
const withGeometryCreateByDrawing = (board) => {
|
|
2869
|
+
const { pointerDown, pointerMove, pointerUp, keydown, keyup } = board;
|
|
2870
|
+
let start = null;
|
|
2871
|
+
let geometryShapeG = null;
|
|
2872
|
+
let temporaryElement = null;
|
|
2873
|
+
let isShift = false;
|
|
2874
|
+
board.keydown = (event) => {
|
|
2875
|
+
isShift = isKeyHotkey('shift', event);
|
|
2876
|
+
keydown(event);
|
|
2877
|
+
};
|
|
2878
|
+
board.keyup = (event) => {
|
|
2879
|
+
isShift = false;
|
|
2880
|
+
keyup(event);
|
|
2881
|
+
};
|
|
2882
|
+
board.pointerDown = (event) => {
|
|
2883
|
+
const geometryPointers = getGeometryPointers();
|
|
2884
|
+
const isGeometryPointer = PlaitBoard.isInPointer(board, geometryPointers);
|
|
2885
|
+
if (!PlaitBoard.isReadonly(board) && isGeometryPointer && isDrawingMode(board)) {
|
|
2886
|
+
const point = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
|
|
2887
|
+
start = point;
|
|
2888
|
+
const pointer = PlaitBoard.getPointer(board);
|
|
2889
|
+
preventTouchMove(board, event, true);
|
|
2890
|
+
if (pointer === BasicShapes.text) {
|
|
2891
|
+
const memorizedLatest = getMemorizedLatestByPointer(pointer);
|
|
2892
|
+
const property = getDefaultTextShapeProperty(board, memorizedLatest.textProperties['font-size']);
|
|
2893
|
+
const points = getPointsByCenterPoint(point, property.width, property.height);
|
|
2894
|
+
const textElement = createGeometryElement(BasicShapes.text, points, DefaultTextProperty.text, memorizedLatest.geometryProperties, { ...memorizedLatest.textProperties, textHeight: property.height });
|
|
2895
|
+
Transforms.insertNode(board, textElement, [board.children.length]);
|
|
2896
|
+
clearSelectedElement(board);
|
|
2897
|
+
addSelectedElement(board, textElement);
|
|
2898
|
+
BoardTransforms.updatePointerType(board, PlaitPointerType.selection);
|
|
2899
|
+
start = null;
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
pointerDown(event);
|
|
2903
|
+
};
|
|
2904
|
+
board.pointerMove = (event) => {
|
|
2905
|
+
geometryShapeG?.remove();
|
|
2906
|
+
geometryShapeG = createG();
|
|
2907
|
+
const geometryGenerator = new GeometryShapeGenerator(board);
|
|
2908
|
+
const drawMode = !!start;
|
|
2909
|
+
const movingPoint = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
|
|
2910
|
+
const pointer = PlaitBoard.getPointer(board);
|
|
2911
|
+
if (drawMode && pointer !== BasicShapes.text) {
|
|
2912
|
+
const points = normalizeShapePoints([start, movingPoint], isShift);
|
|
2913
|
+
const memorizedLatest = getMemorizedLatestByPointer(pointer);
|
|
2914
|
+
const textHeight = getDefaultTextShapeProperty(board, memorizedLatest.textProperties['font-size']).height;
|
|
2915
|
+
temporaryElement = createGeometryElement(pointer, points, '', {
|
|
2916
|
+
strokeWidth: DefaultBasicShapeProperty.strokeWidth,
|
|
2917
|
+
...memorizedLatest.geometryProperties
|
|
2918
|
+
}, { ...memorizedLatest.textProperties, textHeight });
|
|
2919
|
+
geometryGenerator.processDrawing(temporaryElement, geometryShapeG);
|
|
2920
|
+
PlaitBoard.getElementActiveHost(board).append(geometryShapeG);
|
|
2921
|
+
}
|
|
2922
|
+
pointerMove(event);
|
|
2923
|
+
};
|
|
2924
|
+
board.pointerUp = (event) => {
|
|
2925
|
+
const isDrawMode = !!start;
|
|
2926
|
+
if (isDrawMode) {
|
|
2927
|
+
const targetPoint = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
|
|
2928
|
+
const { width, height } = RectangleClient.toRectangleClient([start, targetPoint]);
|
|
2929
|
+
if (Math.hypot(width, height) === 0) {
|
|
2930
|
+
const pointer = PlaitBoard.getPointer(board);
|
|
2931
|
+
if (pointer !== BasicShapes.text) {
|
|
2932
|
+
const points = getDefaultGeometryPoints(pointer, targetPoint);
|
|
2933
|
+
const memorizedLatest = getMemorizedLatestByPointer(pointer);
|
|
2934
|
+
const textHeight = getDefaultTextShapeProperty(board, memorizedLatest.textProperties['font-size']).height;
|
|
2935
|
+
temporaryElement = createGeometryElement(pointer, points, '', {
|
|
2936
|
+
strokeWidth: DefaultBasicShapeProperty.strokeWidth,
|
|
2937
|
+
...memorizedLatest.geometryProperties
|
|
2938
|
+
}, { ...memorizedLatest.textProperties, textHeight });
|
|
2939
|
+
}
|
|
2940
|
+
}
|
|
2941
|
+
}
|
|
2942
|
+
if (temporaryElement) {
|
|
2943
|
+
insertElement(board, temporaryElement);
|
|
2944
|
+
}
|
|
2945
|
+
geometryShapeG?.remove();
|
|
2946
|
+
geometryShapeG = null;
|
|
2947
|
+
start = null;
|
|
2948
|
+
temporaryElement = null;
|
|
2949
|
+
preventTouchMove(board, event, false);
|
|
2950
|
+
pointerUp(event);
|
|
2951
|
+
};
|
|
2952
|
+
return board;
|
|
2953
|
+
};
|
|
2954
|
+
const insertElement = (board, element) => {
|
|
2955
|
+
memorizeLatestShape(board, element.shape);
|
|
2956
|
+
Transforms.insertNode(board, element, [board.children.length]);
|
|
2957
|
+
clearSelectedElement(board);
|
|
2958
|
+
addSelectedElement(board, element);
|
|
2959
|
+
BoardTransforms.updatePointerType(board, PlaitPointerType.selection);
|
|
2960
|
+
};
|
|
2961
|
+
|
|
2955
2962
|
const buildClipboardData = (board, elements, startPoint) => {
|
|
2956
2963
|
return elements.map(element => {
|
|
2957
2964
|
if (PlaitDrawElement.isGeometry(element) || PlaitDrawElement.isImage(element)) {
|
|
@@ -3672,5 +3679,5 @@ const withDraw = (board) => {
|
|
|
3672
3679
|
* Generated bundle index. Do not edit.
|
|
3673
3680
|
*/
|
|
3674
3681
|
|
|
3675
|
-
export { BasicShapes, DEFAULT_IMAGE_WIDTH, DefaultBasicShapeProperty, DefaultConnectorProperty, DefaultDataProperty, DefaultDecisionProperty, DefaultFlowchartProperty, DefaultFlowchartPropertyMap, DefaultGeometryActiveStyle, DefaultGeometryStyle, DefaultManualInputProperty, DefaultMergeProperty, DefaultTextProperty, DrawThemeColors, DrawTransforms, FlowchartSymbols, GeometryComponent, GeometryThreshold, LineComponent, LineHandleKey, LineMarkerType, LineShape, MemorizeKey, PlaitDrawElement, PlaitGeometry, PlaitLine, Q2C, REACTION_MARGIN, ShapeDefaultSpace, StrokeStyle, alignPoints, createDefaultFlowchart, createGeometryElement, createLineElement, drawBoundMask, drawGeometry, drawLine, getAutoCompletePoints, getBasicPointers, getBoardLines, getCenterPointsOnPolygon, getConnectionPoint, getCurvePoints, getDefaultFlowchartProperty, getDefaultTextShapeProperty, getDrawDefaultStrokeColor, getEdgeOnPolygonByPoint, getElbowPoints, getFillByElement, getFlowchartDefaultFill, getFlowchartPointers, getGeometryPointers, getHitConnectorPoint, getHitIndexOfAutoCompletePoint, getHitLineTextIndex, getLineDashByElement, getLineHandleRefPair, getLineMemorizedLatest, getLinePointers, getLinePoints, getLineTextRectangle, getMemorizeKey, getMemorizedLatestByPointer, getMemorizedLatestShape, getNearestPoint, getPointsByCenterPoint, getSelectedDrawElements, getSelectedGeometryElements, getSelectedImageElements, getSelectedLineElements, getStrokeColorByElement, getStrokeStyleByElement, getStrokeWidthByElement, getTextRectangle, getVectorByConnection, handleLineCreating, isHitDrawElement, isHitLineText, isHitPolyLine, isRectangleHitDrawElement, isTextExceedingBounds, memorizeLatestShape, memorizeLatestText, transformOpsToPoints, transformPointToConnection, withDraw };
|
|
3682
|
+
export { BasicShapes, DEFAULT_IMAGE_WIDTH, DefaultBasicShapeProperty, DefaultConnectorProperty, DefaultDataProperty, DefaultDecisionProperty, DefaultFlowchartProperty, DefaultFlowchartPropertyMap, DefaultGeometryActiveStyle, DefaultGeometryStyle, DefaultManualInputProperty, DefaultMergeProperty, DefaultTextProperty, DrawThemeColors, DrawTransforms, FlowchartSymbols, GeometryComponent, GeometryThreshold, LineComponent, LineHandleKey, LineMarkerType, LineShape, MemorizeKey, PlaitDrawElement, PlaitGeometry, PlaitLine, Q2C, REACTION_MARGIN, ShapeDefaultSpace, StrokeStyle, alignPoints, createDefaultFlowchart, createGeometryElement, createLineElement, drawBoundMask, drawGeometry, drawLine, getAutoCompletePoints, getBasicPointers, getBoardLines, getCenterPointsOnPolygon, getConnectionPoint, getCurvePoints, getDefaultFlowchartProperty, getDefaultGeometryPoints, getDefaultGeometryProperty, getDefaultTextPoints, getDefaultTextShapeProperty, getDrawDefaultStrokeColor, getEdgeOnPolygonByPoint, getElbowPoints, getFillByElement, getFlowchartDefaultFill, getFlowchartPointers, getGeometryPointers, getHitConnectorPoint, getHitIndexOfAutoCompletePoint, getHitLineTextIndex, getLineDashByElement, getLineHandleRefPair, getLineMemorizedLatest, getLinePointers, getLinePoints, getLineTextRectangle, getMemorizeKey, getMemorizedLatestByPointer, getMemorizedLatestShape, getNearestPoint, getPointsByCenterPoint, getSelectedDrawElements, getSelectedGeometryElements, getSelectedImageElements, getSelectedLineElements, getStrokeColorByElement, getStrokeStyleByElement, getStrokeWidthByElement, getTextRectangle, getVectorByConnection, handleLineCreating, isHitDrawElement, isHitLineText, isHitPolyLine, isRectangleHitDrawElement, isTextExceedingBounds, memorizeLatestShape, memorizeLatestText, transformOpsToPoints, transformPointToConnection, withDraw };
|
|
3676
3683
|
//# sourceMappingURL=plait-draw.mjs.map
|