@plait/draw 0.38.0 → 0.40.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.
@@ -1,5 +1,5 @@
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';
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, Transforms, clearSelectedElement, addSelectedElement, BoardTransforms, PlaitPointerType, arrowPoints, createPath, distanceBetweenPointAndPoint, drawLinearPath, rotate, depthFirstRecursion, getIsRecursionFunc, getElementById, Direction, catmullRomFitting, distanceBetweenPointAndSegments, createMask, createRect, findElements, Point, getSelectedElements, isPolylineHitRectangle, Path, PlaitNode, BOARD_TO_HOST, transformPoint, toPoint, isSelectionMoving, RgbaToHEX, PlaitPluginElementComponent, preventTouchMove, setClipboardData, getDataFromClipboard, getHitElementByPoint, CursorClass, temporaryDisableSelection, PRESS_AND_MOVE_BUFFER } from '@plait/core';
2
+ import { getRectangleByPoints, getMemorizedLatest, memorizeLatest, RESIZE_HANDLE_DIAMETER, getExtendPoint, getFactorByPoints, Generator, getRectangleResizeHandleRefs, 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
3
  import { Alignment, buildText, DEFAULT_FONT_SIZE, getTextSize, AlignEditor, TextManage, getTextFromClipboard } from '@plait/text';
4
4
  import { pointsOnBezierCurves } from 'points-on-curve';
5
5
  import * as i0 from '@angular/core';
@@ -1090,7 +1090,7 @@ const StoredDataEngine = {
1090
1090
  draw(board, rectangle, options) {
1091
1091
  const rs = PlaitBoard.getRoughSVG(board);
1092
1092
  const shape = rs.path(`M${rectangle.x + rectangle.width / 10} ${rectangle.y} L${rectangle.x + rectangle.width} ${rectangle.y} A ${rectangle.width /
1093
- 10} ${rectangle.height / 2}, 1, 0, 0,${rectangle.x + rectangle.width} ${rectangle.y + rectangle.height} L${rectangle.x +
1093
+ 10} ${rectangle.height / 2}, 0, 0, 0,${rectangle.x + rectangle.width} ${rectangle.y + rectangle.height} L${rectangle.x +
1094
1094
  rectangle.width / 10} ${rectangle.y + rectangle.height}A ${rectangle.width / 10} ${rectangle.height /
1095
1095
  2}, 0, 0, 1,${rectangle.x + rectangle.width / 10} ${rectangle.y}`, { ...options, fillStyle: 'solid' });
1096
1096
  setStrokeLinecap(shape, 'round');
@@ -1210,6 +1210,79 @@ const LINE_AUTO_COMPLETE_OPACITY = 0.6;
1210
1210
  const LINE_AUTO_COMPLETE_HOVERED_OPACITY = 0.8;
1211
1211
  const LINE_AUTO_COMPLETE_HOVERED_DIAMETER = 10;
1212
1212
 
1213
+ const SHAPE_MAX_LENGTH = 6;
1214
+ const memorizedShape = new WeakMap();
1215
+ const getMemorizeKey = (element) => {
1216
+ let key = '';
1217
+ switch (true) {
1218
+ case PlaitDrawElement.isText(element): {
1219
+ key = MemorizeKey.text;
1220
+ break;
1221
+ }
1222
+ case PlaitDrawElement.isBasicShape(element): {
1223
+ key = MemorizeKey.basicShape;
1224
+ break;
1225
+ }
1226
+ case PlaitDrawElement.isFlowchart(element): {
1227
+ key = MemorizeKey.flowchart;
1228
+ break;
1229
+ }
1230
+ case PlaitDrawElement.isLine(element): {
1231
+ key = MemorizeKey.line;
1232
+ break;
1233
+ }
1234
+ }
1235
+ return key;
1236
+ };
1237
+ const getLineMemorizedLatest = () => {
1238
+ const properties = getMemorizedLatest(MemorizeKey.line);
1239
+ delete properties?.text;
1240
+ return { ...properties } || {};
1241
+ };
1242
+ const getMemorizedLatestByPointer = (pointer) => {
1243
+ let memorizeKey = '';
1244
+ if (PlaitDrawElement.isBasicShape({ shape: pointer })) {
1245
+ memorizeKey = pointer === BasicShapes.text ? MemorizeKey.text : MemorizeKey.basicShape;
1246
+ }
1247
+ else {
1248
+ memorizeKey = MemorizeKey.flowchart;
1249
+ }
1250
+ const properties = { ...getMemorizedLatest(memorizeKey) } || {};
1251
+ const textProperties = { ...properties.text } || {};
1252
+ delete properties.text;
1253
+ return { textProperties, geometryProperties: properties };
1254
+ };
1255
+ const memorizeLatestText = (element, operations) => {
1256
+ const memorizeKey = getMemorizeKey(element);
1257
+ let textMemory = getMemorizedLatest(memorizeKey)?.text || {};
1258
+ const setNodeOperation = operations.find(operation => operation.type === 'set_node');
1259
+ if (setNodeOperation) {
1260
+ const newProperties = setNodeOperation.newProperties;
1261
+ textMemory = { ...textMemory, ...newProperties };
1262
+ memorizeLatest(memorizeKey, 'text', textMemory);
1263
+ }
1264
+ };
1265
+ const memorizeLatestShape = (board, shape) => {
1266
+ const shapes = memorizedShape.has(board) ? memorizedShape.get(board) : [];
1267
+ const shapeIndex = shapes.indexOf(shape);
1268
+ if (shape === BasicShapes.text || shapeIndex === 0) {
1269
+ return;
1270
+ }
1271
+ if (shapeIndex !== -1) {
1272
+ shapes.splice(shapeIndex, 1);
1273
+ }
1274
+ else {
1275
+ if (shapes.length === SHAPE_MAX_LENGTH) {
1276
+ shapes.pop();
1277
+ }
1278
+ }
1279
+ shapes.unshift(shape);
1280
+ memorizedShape.set(board, shapes);
1281
+ };
1282
+ const getMemorizedLatestShape = (board) => {
1283
+ return memorizedShape.get(board);
1284
+ };
1285
+
1213
1286
  const createGeometryElement = (shape, points, text, options = {}, textProperties = {}) => {
1214
1287
  let textOptions = {};
1215
1288
  let alignment = Alignment.center;
@@ -1409,6 +1482,26 @@ const getDefaultTextPoints = (board, centerPoint, fontSize) => {
1409
1482
  const property = getDefaultTextShapeProperty(board, fontSize);
1410
1483
  return getPointsByCenterPoint(centerPoint, property.width, property.height);
1411
1484
  };
1485
+ const insertElement = (board, element) => {
1486
+ memorizeLatestShape(board, element.shape);
1487
+ Transforms.insertNode(board, element, [board.children.length]);
1488
+ clearSelectedElement(board);
1489
+ addSelectedElement(board, element);
1490
+ BoardTransforms.updatePointerType(board, PlaitPointerType.selection);
1491
+ };
1492
+ const createDefaultText = (board, points) => {
1493
+ const memorizedLatest = getMemorizedLatestByPointer(BasicShapes.text);
1494
+ const property = getDefaultTextShapeProperty(board, memorizedLatest.textProperties['font-size']);
1495
+ return createGeometryElement(BasicShapes.text, points, DefaultTextProperty.text, memorizedLatest.geometryProperties, { ...memorizedLatest.textProperties, textHeight: property.height });
1496
+ };
1497
+ const createDefaultGeometry = (board, points, shape) => {
1498
+ const memorizedLatest = getMemorizedLatestByPointer(shape);
1499
+ const textHeight = getDefaultTextShapeProperty(board, memorizedLatest.textProperties['font-size']).height;
1500
+ return createGeometryElement(shape, points, '', {
1501
+ strokeWidth: DefaultBasicShapeProperty.strokeWidth,
1502
+ ...memorizedLatest.geometryProperties
1503
+ }, { ...memorizedLatest.textProperties, textHeight });
1504
+ };
1412
1505
 
1413
1506
  const ARROW_LENGTH = 20;
1414
1507
  const drawLineArrow = (element, points, options) => {
@@ -1564,79 +1657,6 @@ const getHitOutlineGeometry = (board, point, offset = 0) => {
1564
1657
  return geometry;
1565
1658
  };
1566
1659
 
1567
- const SHAPE_MAX_LENGTH = 6;
1568
- const memorizedShape = new WeakMap();
1569
- const getMemorizeKey = (element) => {
1570
- let key = '';
1571
- switch (true) {
1572
- case PlaitDrawElement.isText(element): {
1573
- key = MemorizeKey.text;
1574
- break;
1575
- }
1576
- case PlaitDrawElement.isBasicShape(element): {
1577
- key = MemorizeKey.basicShape;
1578
- break;
1579
- }
1580
- case PlaitDrawElement.isFlowchart(element): {
1581
- key = MemorizeKey.flowchart;
1582
- break;
1583
- }
1584
- case PlaitDrawElement.isLine(element): {
1585
- key = MemorizeKey.line;
1586
- break;
1587
- }
1588
- }
1589
- return key;
1590
- };
1591
- const getLineMemorizedLatest = () => {
1592
- const properties = getMemorizedLatest(MemorizeKey.line);
1593
- delete properties?.text;
1594
- return { ...properties } || {};
1595
- };
1596
- const getMemorizedLatestByPointer = (pointer) => {
1597
- let memorizeKey = '';
1598
- if (PlaitDrawElement.isBasicShape({ shape: pointer })) {
1599
- memorizeKey = pointer === BasicShapes.text ? MemorizeKey.text : MemorizeKey.basicShape;
1600
- }
1601
- else {
1602
- memorizeKey = MemorizeKey.flowchart;
1603
- }
1604
- const properties = { ...getMemorizedLatest(memorizeKey) } || {};
1605
- const textProperties = { ...properties.text } || {};
1606
- delete properties.text;
1607
- return { textProperties, geometryProperties: properties };
1608
- };
1609
- const memorizeLatestText = (element, operations) => {
1610
- const memorizeKey = getMemorizeKey(element);
1611
- let textMemory = getMemorizedLatest(memorizeKey)?.text || {};
1612
- const setNodeOperation = operations.find(operation => operation.type === 'set_node');
1613
- if (setNodeOperation) {
1614
- const newProperties = setNodeOperation.newProperties;
1615
- textMemory = { ...textMemory, ...newProperties };
1616
- memorizeLatest(memorizeKey, 'text', textMemory);
1617
- }
1618
- };
1619
- const memorizeLatestShape = (board, shape) => {
1620
- const shapes = memorizedShape.has(board) ? memorizedShape.get(board) : [];
1621
- const shapeIndex = shapes.indexOf(shape);
1622
- if (shape === BasicShapes.text || shapeIndex === 0) {
1623
- return;
1624
- }
1625
- if (shapeIndex !== -1) {
1626
- shapes.splice(shapeIndex, 1);
1627
- }
1628
- else {
1629
- if (shapes.length === SHAPE_MAX_LENGTH) {
1630
- shapes.pop();
1631
- }
1632
- }
1633
- shapes.unshift(shape);
1634
- memorizedShape.set(board, shapes);
1635
- };
1636
- const getMemorizedLatestShape = (board) => {
1637
- return memorizedShape.get(board);
1638
- };
1639
-
1640
1660
  const createLineElement = (shape, points, source, target, texts, options) => {
1641
1661
  return {
1642
1662
  id: idCreator(),
@@ -1659,7 +1679,11 @@ const getLinePoints = (board, element) => {
1659
1679
  return getCurvePoints(board, element);
1660
1680
  }
1661
1681
  default: {
1662
- return PlaitLine.getPoints(board, element);
1682
+ const points = PlaitLine.getPoints(board, element);
1683
+ const handleRefPair = getLineHandleRefPair(board, element);
1684
+ points[0] = handleRefPair.source.point;
1685
+ points[points.length - 1] = handleRefPair.target.point;
1686
+ return points;
1663
1687
  }
1664
1688
  }
1665
1689
  };
@@ -1810,7 +1834,7 @@ const getHitLineTextIndex = (board, element, point) => {
1810
1834
  const texts = element.texts;
1811
1835
  if (!texts.length)
1812
1836
  return -1;
1813
- const points = getElbowPoints(board, element);
1837
+ const points = getLinePoints(board, element);
1814
1838
  return texts.findIndex(text => {
1815
1839
  const center = getPointOnPolyline(points, text.position);
1816
1840
  const rectangle = {
@@ -2212,19 +2236,69 @@ class GeometryShapeGenerator extends Generator {
2212
2236
  }
2213
2237
  }
2214
2238
 
2215
- const insertGeometry = (board, points, shape) => {
2216
- let newElement = createGeometryElement(shape, points, '', {
2217
- strokeWidth: DefaultBasicShapeProperty.strokeWidth
2239
+ const resizeLine = (board, options, path) => {
2240
+ Transforms.setNode(board, options, path);
2241
+ };
2242
+ const setLineTexts = (board, element, texts) => {
2243
+ const path = PlaitBoard.findPath(board, element);
2244
+ Transforms.setNode(board, { texts }, path);
2245
+ };
2246
+ const removeLineText = (board, element, index) => {
2247
+ const path = PlaitBoard.findPath(board, element);
2248
+ const texts = element.texts?.length ? [...element.texts] : [];
2249
+ const newTexts = [...texts];
2250
+ newTexts.splice(index, 1);
2251
+ Transforms.setNode(board, { texts: newTexts }, path);
2252
+ };
2253
+ const setLineMark = (board, element, handleKey, marker) => {
2254
+ const path = PlaitBoard.findPath(board, element);
2255
+ let handle = handleKey === LineHandleKey.source ? element.source : element.target;
2256
+ handle = { ...handle, marker };
2257
+ memorizeLatest(MemorizeKey.line, handleKey, marker);
2258
+ Transforms.setNode(board, { [handleKey]: handle }, path);
2259
+ };
2260
+ const collectRefs = (board, geometry, refs) => {
2261
+ const lines = findElements(board, {
2262
+ match: (element) => {
2263
+ if (PlaitDrawElement.isLine(element)) {
2264
+ return element.source.boundId === geometry.id || element.target.boundId === geometry.id;
2265
+ }
2266
+ return false;
2267
+ },
2268
+ recursion: element => true
2218
2269
  });
2219
- Transforms.insertNode(board, newElement, [board.children.length]);
2220
- clearSelectedElement(board);
2221
- addSelectedElement(board, newElement);
2270
+ if (lines.length) {
2271
+ lines.forEach(line => {
2272
+ const isSourceBound = line.source.boundId === geometry.id;
2273
+ const handle = isSourceBound ? 'source' : 'target';
2274
+ const object = { ...line[handle] };
2275
+ const linePoints = getLinePoints(board, line);
2276
+ const point = isSourceBound ? linePoints[0] : linePoints[linePoints.length - 1];
2277
+ object.connection = transformPointToConnection(board, point, geometry);
2278
+ const path = PlaitBoard.findPath(board, line);
2279
+ const index = refs.findIndex(obj => Path.equals(obj.path, path));
2280
+ if (index === -1) {
2281
+ refs.push({
2282
+ property: {
2283
+ [handle]: object
2284
+ },
2285
+ path
2286
+ });
2287
+ }
2288
+ else {
2289
+ refs[index].property = { ...refs[index].property, [handle]: object };
2290
+ }
2291
+ });
2292
+ }
2293
+ };
2294
+
2295
+ const insertGeometry = (board, points, shape) => {
2296
+ const newElement = createDefaultGeometry(board, points, shape);
2297
+ insertElement(board, newElement);
2222
2298
  };
2223
2299
  const insertText = (board, points, text = '文本') => {
2224
- let newElement = createGeometryElement(BasicShapes.text, points, text);
2225
- Transforms.insertNode(board, newElement, [board.children.length]);
2226
- clearSelectedElement(board);
2227
- addSelectedElement(board, newElement);
2300
+ const newElement = createDefaultText(board, points);
2301
+ insertElement(board, newElement);
2228
2302
  };
2229
2303
  const resizeGeometry = (board, points, textHeight, path) => {
2230
2304
  const normalizePoints = normalizeShapePoints(points);
@@ -2236,9 +2310,21 @@ const resizeGeometry = (board, points, textHeight, path) => {
2236
2310
  }
2237
2311
  Transforms.setNode(board, newProperties, path);
2238
2312
  };
2239
- const transformShape = (board, element, shape) => {
2240
- const path = PlaitBoard.findPath(board, element);
2241
- Transforms.setNode(board, { shape }, path);
2313
+ const switchGeometryShape = (board, shape) => {
2314
+ const selectedElements = getSelectedElements(board);
2315
+ const refs = [];
2316
+ selectedElements.forEach(item => {
2317
+ if (PlaitDrawElement.isGeometry(item) && !PlaitDrawElement.isText(item)) {
2318
+ const path = PlaitBoard.findPath(board, item);
2319
+ Transforms.setNode(board, { shape }, path);
2320
+ collectRefs(board, { ...item, shape }, refs);
2321
+ }
2322
+ });
2323
+ if (refs.length) {
2324
+ refs.forEach(ref => {
2325
+ DrawTransforms.resizeLine(board, ref.property, ref.path);
2326
+ });
2327
+ }
2242
2328
  };
2243
2329
 
2244
2330
  const normalizePoints = (board, element, width, textHeight) => {
@@ -2313,28 +2399,6 @@ const insertImage = (board, imageItem, startPoint) => {
2313
2399
  Transforms.addSelectionWithTemporaryElements(board, [imageElement]);
2314
2400
  };
2315
2401
 
2316
- const resizeLine = (board, options, path) => {
2317
- Transforms.setNode(board, options, path);
2318
- };
2319
- const setLineTexts = (board, element, texts) => {
2320
- const path = PlaitBoard.findPath(board, element);
2321
- Transforms.setNode(board, { texts }, path);
2322
- };
2323
- const removeLineText = (board, element, index) => {
2324
- const path = PlaitBoard.findPath(board, element);
2325
- const texts = element.texts?.length ? [...element.texts] : [];
2326
- const newTexts = [...texts];
2327
- newTexts.splice(index, 1);
2328
- Transforms.setNode(board, { texts: newTexts }, path);
2329
- };
2330
- const setLineMark = (board, element, handleKey, marker) => {
2331
- const path = PlaitBoard.findPath(board, element);
2332
- let handle = handleKey === LineHandleKey.source ? element.source : element.target;
2333
- handle = { ...handle, marker };
2334
- memorizeLatest(MemorizeKey.line, handleKey, marker);
2335
- Transforms.setNode(board, { [handleKey]: handle }, path);
2336
- };
2337
-
2338
2402
  const DrawTransforms = {
2339
2403
  setText,
2340
2404
  insertGeometry,
@@ -2346,7 +2410,7 @@ const DrawTransforms = {
2346
2410
  removeLineText,
2347
2411
  setLineMark,
2348
2412
  insertImage,
2349
- transformShape
2413
+ switchGeometryShape
2350
2414
  };
2351
2415
 
2352
2416
  class LineAutoCompleteGenerator extends Generator {
@@ -2588,9 +2652,13 @@ class LineActiveGenerator extends Generator {
2588
2652
  function getMiddlePoints(board, element) {
2589
2653
  const result = [];
2590
2654
  const shape = element.shape;
2655
+ const hideBuffer = 10;
2591
2656
  if (shape === LineShape.straight) {
2592
2657
  const points = PlaitLine.getPoints(board, element);
2593
2658
  for (let i = 0; i < points.length - 1; i++) {
2659
+ const distance = distanceBetweenPointAndPoint(...points[i], ...points[i + 1]);
2660
+ if (distance < hideBuffer)
2661
+ continue;
2594
2662
  result.push([(points[i][0] + points[i + 1][0]) / 2, (points[i][1] + points[i + 1][1]) / 2]);
2595
2663
  }
2596
2664
  }
@@ -2608,6 +2676,9 @@ function getMiddlePoints(board, element) {
2608
2676
  const startIndex = pointsOnBezier.findIndex(point => point[0] === points[i][0] && point[1] === points[i][1]);
2609
2677
  const endIndex = pointsOnBezier.findIndex(point => point[0] === points[i + 1][0] && point[1] === points[i + 1][1]);
2610
2678
  const middleIndex = Math.round((startIndex + endIndex) / 2);
2679
+ const distance = distanceBetweenPointAndPoint(...points[i], ...points[i + 1]);
2680
+ if (distance < hideBuffer)
2681
+ continue;
2611
2682
  result.push(pointsOnBezier[middleIndex]);
2612
2683
  }
2613
2684
  }
@@ -2811,7 +2882,7 @@ const withGeometryCreateByDrag = (board) => {
2811
2882
  if (pointer === BasicShapes.text) {
2812
2883
  const property = getDefaultTextShapeProperty(board, memorizedLatest.textProperties['font-size']);
2813
2884
  const points = getPointsByCenterPoint(movingPoint, property.width, property.height);
2814
- temporaryElement = createGeometryElement(BasicShapes.text, points, DefaultTextProperty.text, memorizedLatest.geometryProperties, { ...memorizedLatest.textProperties, textHeight: property.height });
2885
+ temporaryElement = createDefaultText(board, points);
2815
2886
  if (!fakeCreateTextRef) {
2816
2887
  const textManage = new TextManage(board, PlaitBoard.getComponent(board).viewContainerRef, {
2817
2888
  getRectangle: () => {
@@ -2837,11 +2908,7 @@ const withGeometryCreateByDrag = (board) => {
2837
2908
  }
2838
2909
  else {
2839
2910
  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 });
2911
+ temporaryElement = createDefaultGeometry(board, points, pointer);
2845
2912
  geometryGenerator.processDrawing(temporaryElement, geometryShapeG);
2846
2913
  PlaitBoard.getElementActiveHost(board).append(geometryShapeG);
2847
2914
  }
@@ -2891,11 +2958,8 @@ const withGeometryCreateByDrawing = (board) => {
2891
2958
  const memorizedLatest = getMemorizedLatestByPointer(pointer);
2892
2959
  const property = getDefaultTextShapeProperty(board, memorizedLatest.textProperties['font-size']);
2893
2960
  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);
2961
+ const textElement = createDefaultText(board, points);
2962
+ insertElement(board, textElement);
2899
2963
  start = null;
2900
2964
  }
2901
2965
  }
@@ -2910,12 +2974,7 @@ const withGeometryCreateByDrawing = (board) => {
2910
2974
  const pointer = PlaitBoard.getPointer(board);
2911
2975
  if (drawMode && pointer !== BasicShapes.text) {
2912
2976
  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 });
2977
+ temporaryElement = createDefaultGeometry(board, points, pointer);
2919
2978
  geometryGenerator.processDrawing(temporaryElement, geometryShapeG);
2920
2979
  PlaitBoard.getElementActiveHost(board).append(geometryShapeG);
2921
2980
  }
@@ -2930,12 +2989,7 @@ const withGeometryCreateByDrawing = (board) => {
2930
2989
  const pointer = PlaitBoard.getPointer(board);
2931
2990
  if (pointer !== BasicShapes.text) {
2932
2991
  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 });
2992
+ temporaryElement = createDefaultGeometry(board, points, pointer);
2939
2993
  }
2940
2994
  }
2941
2995
  }
@@ -2951,13 +3005,6 @@ const withGeometryCreateByDrawing = (board) => {
2951
3005
  };
2952
3006
  return board;
2953
3007
  };
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
3008
 
2962
3009
  const buildClipboardData = (board, elements, startPoint) => {
2963
3010
  return elements.map(element => {
@@ -3297,7 +3344,7 @@ const withLineResize = (board) => {
3297
3344
  element: value,
3298
3345
  handle: handleRef.handle
3299
3346
  };
3300
- pointIndex = handleRef.index;
3347
+ pointIndex = handleRef.handle === LineResizeHandle.addHandle ? handleRef.index + 1 : handleRef.index;
3301
3348
  }
3302
3349
  });
3303
3350
  return result;
@@ -3308,10 +3355,10 @@ const withLineResize = (board) => {
3308
3355
  let points = [...resizeRef.element.points];
3309
3356
  let source = { ...resizeRef.element.source };
3310
3357
  let target = { ...resizeRef.element.target };
3358
+ const hitElement = getHitOutlineGeometry(board, resizeState.endTransformPoint, REACTION_MARGIN);
3311
3359
  if (resizeRef.handle === LineResizeHandle.source || resizeRef.handle === LineResizeHandle.target) {
3312
3360
  const object = resizeRef.handle === LineResizeHandle.source ? source : target;
3313
3361
  points[pointIndex] = resizeState.endTransformPoint;
3314
- const hitElement = getHitOutlineGeometry(board, resizeState.endTransformPoint, REACTION_MARGIN);
3315
3362
  if (hitElement) {
3316
3363
  object.connection = transformPointToConnection(board, resizeState.endTransformPoint, hitElement);
3317
3364
  object.boundId = hitElement.id;
@@ -3319,21 +3366,21 @@ const withLineResize = (board) => {
3319
3366
  else {
3320
3367
  object.connection = undefined;
3321
3368
  object.boundId = undefined;
3322
- if (points.length === 2) {
3323
- let movingPoint = points[pointIndex];
3324
- const drawPoints = getLinePoints(board, resizeRef.element);
3325
- const index = pointIndex === 0 ? drawPoints.length - 1 : 0;
3326
- const otherPoint = drawPoints[index];
3327
- points[pointIndex] = alignPoints(otherPoint, movingPoint);
3328
- }
3329
3369
  }
3330
3370
  }
3331
3371
  else if (resizeRef.handle === LineResizeHandle.addHandle) {
3332
- points.splice(pointIndex + 1, 0, resizeState.endTransformPoint);
3372
+ points.splice(pointIndex, 0, resizeState.endTransformPoint);
3333
3373
  }
3334
3374
  else {
3335
3375
  points[pointIndex] = resizeState.endTransformPoint;
3336
3376
  }
3377
+ if (!hitElement) {
3378
+ points.forEach((point, index) => {
3379
+ if (index === pointIndex)
3380
+ return;
3381
+ points[pointIndex] = alignPoints(point, points[pointIndex]);
3382
+ });
3383
+ }
3337
3384
  DrawTransforms.resizeLine(board, { points, source, target }, resizeRef.path);
3338
3385
  }
3339
3386
  };
@@ -3545,7 +3592,7 @@ const withLineAutoCompleteReaction = (board) => {
3545
3592
  return board;
3546
3593
  };
3547
3594
 
3548
- const withLineAutoCompletePluginKey = 'plait-line-auto-complete-plugin-key';
3595
+ const WithLineAutoCompletePluginKey = 'plait-line-auto-complete-plugin-key';
3549
3596
  const withLineAutoComplete = (board) => {
3550
3597
  const { pointerDown, pointerMove, pointerUp } = board;
3551
3598
  let startPoint = null;
@@ -3586,7 +3633,7 @@ const withLineAutoComplete = (board) => {
3586
3633
  Transforms.insertNode(board, temporaryElement, [board.children.length]);
3587
3634
  clearSelectedElement(board);
3588
3635
  addSelectedElement(board, temporaryElement);
3589
- const afterComplete = board.getPluginOptions(withLineAutoCompletePluginKey)
3636
+ const afterComplete = board.getPluginOptions(WithLineAutoCompletePluginKey)
3590
3637
  ?.afterComplete;
3591
3638
  afterComplete && afterComplete(temporaryElement);
3592
3639
  }
@@ -3603,6 +3650,53 @@ const withLineAutoComplete = (board) => {
3603
3650
  return board;
3604
3651
  };
3605
3652
 
3653
+ const withLineTextMove = (board) => {
3654
+ let textIndex = 0;
3655
+ const movableBuffer = 100;
3656
+ const options = {
3657
+ key: 'line-text',
3658
+ canResize: () => {
3659
+ return true;
3660
+ },
3661
+ detect: (point) => {
3662
+ let result = null;
3663
+ const line = getHitElementByPoint(board, point, (element) => {
3664
+ return PlaitDrawElement.isLine(element);
3665
+ });
3666
+ if (line) {
3667
+ const index = getHitLineTextIndex(board, line, point);
3668
+ const hitComponent = PlaitElement.getComponent(line);
3669
+ const textManage = hitComponent.textManages[index];
3670
+ if (index !== -1 && !textManage.isEditing) {
3671
+ textIndex = index;
3672
+ return { element: line, handle: ResizeHandle.e };
3673
+ }
3674
+ }
3675
+ return result;
3676
+ },
3677
+ onResize: (resizeRef, resizeState) => {
3678
+ const element = resizeRef.element;
3679
+ if (element) {
3680
+ const movingPoint = resizeState.endTransformPoint;
3681
+ const points = getLinePoints(board, element);
3682
+ const distance = distanceBetweenPointAndSegments(points, movingPoint);
3683
+ if (distance <= movableBuffer) {
3684
+ const point = getNearestPointBetweenPointAndSegments(movingPoint, points, false);
3685
+ const position = getRatioByPoint(points, point);
3686
+ const texts = [...element.texts];
3687
+ texts[textIndex] = {
3688
+ ...texts[textIndex],
3689
+ position
3690
+ };
3691
+ DrawTransforms.setLineTexts(board, element, texts);
3692
+ }
3693
+ }
3694
+ }
3695
+ };
3696
+ withResize(board, options);
3697
+ return board;
3698
+ };
3699
+
3606
3700
  const withDraw = (board) => {
3607
3701
  const { drawElement, getRectangle, isRectangleHit, isHit, isMovable, isAlign } = board;
3608
3702
  board.drawElement = (context) => {
@@ -3672,12 +3766,12 @@ const withDraw = (board) => {
3672
3766
  }
3673
3767
  return isAlign(element);
3674
3768
  };
3675
- return withLineAutoCompleteReaction(withLineText(withLineBoundReaction(withLineResize(withGeometryResize(withLineCreateByDraw(withLineAutoComplete(withGeometryCreateByDrag(withGeometryCreateByDrawing(withDrawFragment(withDrawHotkey(board)))))))))));
3769
+ return withLineTextMove(withLineAutoCompleteReaction(withLineText(withLineBoundReaction(withLineResize(withGeometryResize(withLineCreateByDraw(withLineAutoComplete(withGeometryCreateByDrag(withGeometryCreateByDrawing(withDrawFragment(withDrawHotkey(board))))))))))));
3676
3770
  };
3677
3771
 
3678
3772
  /**
3679
3773
  * Generated bundle index. Do not edit.
3680
3774
  */
3681
3775
 
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 };
3776
+ 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, WithLineAutoCompletePluginKey, alignPoints, createDefaultFlowchart, createDefaultGeometry, createDefaultText, 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, insertElement, isHitDrawElement, isHitLineText, isHitPolyLine, isRectangleHitDrawElement, isTextExceedingBounds, memorizeLatestShape, memorizeLatestText, transformOpsToPoints, transformPointToConnection, withDraw, withLineAutoComplete };
3683
3777
  //# sourceMappingURL=plait-draw.mjs.map