@plait/mind 0.17.0 → 0.18.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,7 +1,7 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { Directive, Input, Component, ChangeDetectionStrategy, NgModule, NgZone, HostListener } from '@angular/core';
3
3
  import * as i2 from '@plait/core';
4
- import { DefaultThemeColor, ColorfulThemeColor, SoftThemeColor, RetroThemeColor, DarkThemeColor, StarryThemeColor, RectangleClient, PlaitElement, idCreator, isNullOrUndefined, Transforms, clearSelectedElement, addSelectedElement, PlaitNode, Path, PlaitBoard, depthFirstRecursion, drawLinearPath, drawBezierPath, createG, updateForeignObject, drawRoundRectangle, getRectangleByElements, getSelectedElements, NODE_TO_PARENT, distanceBetweenPointAndRectangle, createForeignObject, drawAbstractRoundRectangle, createText, PlaitPointerType, PlaitPluginElementComponent, NODE_TO_INDEX, PlaitModule, transformPoint, toPoint, getHitElements, distanceBetweenPointAndPoint, CLIP_BOARD_FORMAT_KEY, isMainPointer, BOARD_TO_HOST, PlaitPluginKey, throttleRAF, BoardTransforms, removeSelectedElement, PlaitHistoryBoard, hotkeys } from '@plait/core';
4
+ import { DefaultThemeColor, ColorfulThemeColor, SoftThemeColor, RetroThemeColor, DarkThemeColor, StarryThemeColor, RectangleClient, PlaitElement, idCreator, isNullOrUndefined, Transforms, clearSelectedElement, addSelectedElement, PlaitNode, Path, PlaitBoard, depthFirstRecursion, drawLinearPath, drawBezierPath, createG, updateForeignObject, drawRoundRectangle, getRectangleByElements, getSelectedElements, NODE_TO_PARENT, distanceBetweenPointAndRectangle, createForeignObject, createText, PlaitPointerType, PlaitPluginElementComponent, NODE_TO_INDEX, PlaitModule, transformPoint, toPoint, getHitElements, distanceBetweenPointAndPoint, CLIP_BOARD_FORMAT_KEY, isMainPointer, BOARD_TO_HOST, PlaitPluginKey, throttleRAF, BoardTransforms, removeSelectedElement, PlaitHistoryBoard, hotkeys } from '@plait/core';
5
5
  import { MindLayoutType, isIndentedLayout, AbstractNode, getNonAbstractChildren, isStandardLayout, isLeftLayout, isRightLayout, isVerticalLogicLayout, isHorizontalLogicLayout, isTopLayout, isBottomLayout, isHorizontalLayout, getCorrectStartEnd, getAbstractLayout, ConnectingPosition, GlobalLayout } from '@plait/layouts';
6
6
  import { TEXT_DEFAULT_HEIGHT, buildText, getTextSize, TextManage, ExitOrigin, TextModule, getTextFromClipboard } from '@plait/text';
7
7
  import { fromEvent, Subject } from 'rxjs';
@@ -659,15 +659,20 @@ const adjustNodeToRoot = (board, node) => {
659
659
  };
660
660
 
661
661
  const DefaultAbstractNodeStyle = {
662
- strokeColor: GRAY_COLOR,
663
- strokeWidth: 2,
664
662
  branchColor: GRAY_COLOR,
665
- branchWidth: 2
663
+ branchWidth: 2,
664
+ shape: {
665
+ strokeColor: GRAY_COLOR,
666
+ strokeWidth: 2
667
+ }
666
668
  };
667
669
  const DefaultNodeStyle = {
668
- strokeWidth: 3,
669
670
  branchWidth: 3,
670
- fill: 'none'
671
+ shape: {
672
+ rectangleRadius: 4,
673
+ strokeWidth: 3,
674
+ fill: 'none'
675
+ }
671
676
  };
672
677
 
673
678
  const getAvailableProperty = (board, element, propertyKey) => {
@@ -902,11 +907,15 @@ const getStrokeByMindElement = (board, element) => {
902
907
  return element.strokeColor || defaultRootStroke;
903
908
  }
904
909
  if (AbstractNode.isAbstract(element) || isChildOfAbstract(board, element)) {
905
- return element.strokeColor || DefaultAbstractNodeStyle.strokeColor;
906
- ;
910
+ return element.strokeColor || DefaultAbstractNodeStyle.shape.strokeColor;
907
911
  }
908
912
  return getAvailableProperty(board, element, 'strokeColor') || getDefaultBranchColor(board, element);
909
913
  };
914
+ const getStrokeWidthByElement = (board, element) => {
915
+ const strokeWidth = element.strokeWidth ||
916
+ (AbstractNode.isAbstract(element) ? DefaultAbstractNodeStyle.shape.strokeWidth : DefaultNodeStyle.shape.strokeWidth);
917
+ return strokeWidth;
918
+ };
910
919
  const getShapeByElement = (board, element) => {
911
920
  const shape = getAvailableProperty(board, element, 'shape');
912
921
  return shape || MindElementShape.roundRectangle;
@@ -1345,7 +1354,7 @@ function drawLogicLink(board, parent, node, isHorizontal, defaultStroke = null,
1345
1354
  const branchWidth = defaultStrokeWidth || getBranchWidthByMindElement(board, parent.origin);
1346
1355
  const hasStraightLine = branchShape === BranchShape.polyline ? true : !parent.origin.isRoot;
1347
1356
  const parentShape = getShapeByElement(board, parent.origin);
1348
- const shape = node.origin.shape ? node.origin.shape : parentShape;
1357
+ const shape = getShapeByElement(board, node.origin);
1349
1358
  const hasUnderlineShape = shape === MindElementShape.underline;
1350
1359
  const hasUnderlineShapeOfParent = parentShape === MindElementShape.underline;
1351
1360
  const nodeClient = getRectangleByNode(node);
@@ -2035,15 +2044,15 @@ function drawRoundRectangleByNode(board, node) {
2035
2044
  }
2036
2045
  function drawRoundRectangleByElement(board, nodeRectangle, element) {
2037
2046
  const defaultRootFill = getMindThemeColor(board).rootFill;
2038
- const fill = element.fill ? element.fill : element.isRoot ? defaultRootFill : DefaultNodeStyle.fill;
2047
+ const fill = element.fill ? element.fill : element.isRoot ? defaultRootFill : DefaultNodeStyle.shape.fill;
2039
2048
  const stroke = getStrokeByMindElement(board, element);
2040
- const strokeWidth = element.strokeWidth ? element.strokeWidth : DefaultNodeStyle.strokeWidth;
2049
+ const strokeWidth = getStrokeWidthByElement(board, element);
2041
2050
  const nodeG = drawRoundRectangle(PlaitBoard.getRoughSVG(board), nodeRectangle.x, nodeRectangle.y, nodeRectangle.x + nodeRectangle.width, nodeRectangle.y + nodeRectangle.height, {
2042
2051
  stroke,
2043
2052
  strokeWidth,
2044
2053
  fill,
2045
2054
  fillStyle: 'solid'
2046
- });
2055
+ }, false, DefaultNodeStyle.shape.rectangleRadius);
2047
2056
  return nodeG;
2048
2057
  }
2049
2058
 
@@ -2561,6 +2570,48 @@ function handleBoardClass(board, activeHandlePosition, isHorizontal) {
2561
2570
  PlaitBoard.getBoardContainer(board).classList.remove('abstract-resizing-vertical');
2562
2571
  }
2563
2572
  }
2573
+ function drawAbstractRoundRectangle(rs, x1, y1, x2, y2, isHorizontal, options) {
2574
+ const width = Math.abs(x1 - x2);
2575
+ const height = Math.abs(y1 - y2);
2576
+ const radius = 5;
2577
+ const handleGap = 4;
2578
+ const handleLength = 10;
2579
+ const handleSpace = handleLength + handleGap * 2;
2580
+ if (isHorizontal) {
2581
+ const handleSideLine = (width - handleSpace - radius * 2) / 2;
2582
+ const sideLine = height - radius * 2;
2583
+ return rs.path(`M${x1 + radius},${y1}
2584
+ l${handleSideLine},0
2585
+ m${handleSpace},0
2586
+ l${handleSideLine},0
2587
+ a${radius},${radius},0,0,1,${radius},${radius}
2588
+ l0,${sideLine}
2589
+ a${radius},${radius},0,0,1,-${radius},${radius}
2590
+ l-${handleSideLine},0
2591
+ m-${handleSpace},0
2592
+ l-${handleSideLine},0
2593
+ a${radius},${radius},0,0,1,-${radius},-${radius}
2594
+ l0,-${sideLine}
2595
+ a${radius},${radius},0,0,1,${radius},-${radius}`, options);
2596
+ }
2597
+ else {
2598
+ const handleSideLine = (height - handleSpace - radius * 2) / 2;
2599
+ const sideLine = width - radius * 2;
2600
+ return rs.path(`M${x1 + radius},${y1}
2601
+ l${sideLine},0
2602
+ a${radius},${radius},0,0,1,${radius},${radius}
2603
+ l0,${handleSideLine}
2604
+ m0,${handleSpace}
2605
+ l0,${handleSideLine}
2606
+ a${radius},${radius},0,0,1,-${radius},${radius}
2607
+ l-${sideLine},0
2608
+ a${radius},${radius},0,0,1,-${radius},-${radius}
2609
+ l0,-${handleSideLine}
2610
+ m0,-${handleSpace}
2611
+ l0,-${handleSideLine}
2612
+ a${radius},${radius},0,0,1,${radius},-${radius}`, options);
2613
+ }
2614
+ }
2564
2615
 
2565
2616
  class NodeActiveDrawer extends BaseDrawer {
2566
2617
  canDraw(element, data) {
@@ -2579,14 +2630,13 @@ class NodeActiveDrawer extends BaseDrawer {
2579
2630
  activeG.append(this.abstractOutlineG);
2580
2631
  }
2581
2632
  const node = MindElement.getNode(element);
2582
- let { x, y, width, height } = getRectangleByNode(node);
2583
- const strokeG = drawRoundRectangle(PlaitBoard.getRoughSVG(this.board), x - 2, y - 2, x + width + 2, y + height + 2, { stroke: PRIMARY_COLOR, strokeWidth: 2, fill: '' }, true);
2633
+ const rectangle = getRectangleByNode(node);
2634
+ const activeStrokeWidth = 2;
2635
+ // add 0.1 to avoid white gap
2636
+ const offset = (getStrokeWidthByElement(this.board, element) + activeStrokeWidth) / 2 - 0.1;
2637
+ const activeRectangle = RectangleClient.getOutlineRectangle(rectangle, -offset);
2638
+ const strokeG = drawRoundRectangle(PlaitBoard.getRoughSVG(this.board), activeRectangle.x, activeRectangle.y, activeRectangle.x + activeRectangle.width, activeRectangle.y + activeRectangle.height, { stroke: PRIMARY_COLOR, strokeWidth: activeStrokeWidth, fill: '' }, true, DefaultNodeStyle.shape.rectangleRadius + offset);
2584
2639
  this.g.appendChild(strokeG);
2585
- if (!data.isEditing) {
2586
- const fillG = drawRoundRectangle(PlaitBoard.getRoughSVG(this.board), x - 2, y - 2, x + width + 2, y + height + 2, { stroke: PRIMARY_COLOR, fill: PRIMARY_COLOR, fillStyle: 'solid' }, true);
2587
- fillG.style.opacity = '0.15';
2588
- this.g.appendChild(fillG);
2589
- }
2590
2640
  return activeG;
2591
2641
  }
2592
2642
  updateAbstractOutline(element, activeHandlePosition, resizingLocation) {
@@ -3830,15 +3880,9 @@ const withMind = (board) => {
3830
3880
  board.applyTheme = (element) => {
3831
3881
  const mindElement = element;
3832
3882
  const shouldClearProperty = !PlaitBoard.isBoard(element) && (mindElement?.branchColor || mindElement?.fill || mindElement?.strokeColor);
3833
- const isAbstract = AbstractNode.isAbstract(element);
3834
3883
  if (shouldClearProperty) {
3835
3884
  const path = PlaitBoard.findPath(board, element);
3836
- if (isAbstract) {
3837
- Transforms.setNode(board, { fill: null, strokeColor: DefaultAbstractNodeStyle.strokeColor, branchColor: DefaultAbstractNodeStyle.branchColor }, path);
3838
- }
3839
- else {
3840
- Transforms.setNode(board, { fill: null, strokeColor: null, branchColor: null }, path);
3841
- }
3885
+ Transforms.setNode(board, { fill: null, strokeColor: null, branchColor: null }, path);
3842
3886
  }
3843
3887
  };
3844
3888
  board.getRectangle = element => {
@@ -3987,5 +4031,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
3987
4031
  * Generated bundle index. Do not edit.
3988
4032
  */
3989
4033
 
3990
- export { ABSTRACT_HANDLE_COLOR, ABSTRACT_HANDLE_LENGTH, ABSTRACT_HANDLE_MASK_WIDTH, ABSTRACT_INCLUDED_OUTLINE_OFFSET, AbstractHandlePosition, AbstractResizeState, BASE, BRANCH_FONT_FAMILY, BRANCH_WIDTH, BaseDrawer, BranchShape, DEFAULT_FONT_FAMILY, DefaultAbstractNodeStyle, DefaultNodeStyle, ELEMENT_TO_NODE, EXTEND_DIAMETER, EXTEND_OFFSET, GRAY_COLOR, INHERIT_ATTRIBUTE_KEYS, IS_DRAGGING, LayoutDirection, LayoutDirectionsMap, MindColorfulThemeColor, MindDarkThemeColor, MindDefaultThemeColor, MindElement, MindElementShape, MindEmojiBaseComponent, MindImageBaseComponent, MindModule, MindNode, MindNodeComponent, MindPointerType, MindQueries, MindRetroThemeColor, MindSoftThemeColor, MindStarryThemeColor, MindThemeColor, MindThemeColors, MindTransforms, NODE_MIN_WIDTH, PRIMARY_COLOR, PlaitMind, PlaitMindComponent, QUICK_INSERT_CIRCLE_COLOR, QUICK_INSERT_CIRCLE_OFFSET, QUICK_INSERT_INNER_CROSS_COLOR, ROOT_TOPIC_FONT_SIZE, ROOT_TOPIC_HEIGHT, STROKE_WIDTH, TOPIC_COLOR, TOPIC_DEFAULT_MAX_WORD_COUNT, TOPIC_FONT_SIZE, TRANSPARENT, WithMindPluginKey, addActiveOnDragOrigin, adjustAbstractToNode, adjustNodeToRoot, adjustRootToNode, canSetAbstract, copyNewNode, correctLayoutByDirection, createDefaultMind, createEmptyMind, createMindElement, deleteElementHandleAbstract, deleteElementsHandleRightNodeCount, detectDropTarget, directionCorrector, directionDetector, divideElementByParent, drawFakeDragNode, drawFakeDropNode, editTopic, extractNodesText, findLastChild, findLocationLeftIndex, getAbstractBranchColor, getAbstractBranchWidth, getAbstractHandleRectangle, getAllowedDirection, getAvailableSubLayoutsByLayoutDirections, getBehindAbstracts, getBranchColorByMindElement, getBranchDirectionsByLayouts, getBranchShapeByMindElement, getBranchWidthByMindElement, getChildrenCount, getCorrespondingAbstract, getDefaultBranchColor, getDefaultBranchColorByIndex, getDefaultLayout, getEmojiForeignRectangle, getEmojiRectangle, getFirstLevelElement, getHitAbstractHandle, getImageForeignRectangle, getInCorrectLayoutDirection, getLayoutDirection$1 as getLayoutDirection, getLayoutReverseDirection, getLocationScope, getMindThemeColor, getNextBranchColor, getOverallAbstracts, getPathByDropTarget, getRectangleByElement, getRectangleByNode, getRectangleByResizingLocation, getRelativeStartEndByAbstractRef, getRootLayout, getShapeByElement, getStrokeByMindElement, getTopicRectangleByElement, getTopicRectangleByNode, getValidAbstractRefs, handleTouchedAbstract, hasAfterDraw, hasPreviousOrNextOfDropPath, insertElementHandleAbstract, insertElementHandleRightNodeCount, insertMindElement, isChildElement, isChildOfAbstract, isChildRight, isChildUp, isCorrectLayout, isDragging, isDropStandardRight, isHitEmojis, isHitImage, isHitMindElement, isInRightBranchOfStandardLayout, isMixedLayout, isSetAbstract, isValidTarget, isVirtualKey, removeActiveOnDragOrigin, separateChildren, setIsDragging, withMind, withMindExtend };
4034
+ export { ABSTRACT_HANDLE_COLOR, ABSTRACT_HANDLE_LENGTH, ABSTRACT_HANDLE_MASK_WIDTH, ABSTRACT_INCLUDED_OUTLINE_OFFSET, AbstractHandlePosition, AbstractResizeState, BASE, BRANCH_FONT_FAMILY, BRANCH_WIDTH, BaseDrawer, BranchShape, DEFAULT_FONT_FAMILY, DefaultAbstractNodeStyle, DefaultNodeStyle, ELEMENT_TO_NODE, EXTEND_DIAMETER, EXTEND_OFFSET, GRAY_COLOR, INHERIT_ATTRIBUTE_KEYS, IS_DRAGGING, LayoutDirection, LayoutDirectionsMap, MindColorfulThemeColor, MindDarkThemeColor, MindDefaultThemeColor, MindElement, MindElementShape, MindEmojiBaseComponent, MindImageBaseComponent, MindModule, MindNode, MindNodeComponent, MindPointerType, MindQueries, MindRetroThemeColor, MindSoftThemeColor, MindStarryThemeColor, MindThemeColor, MindThemeColors, MindTransforms, NODE_MIN_WIDTH, PRIMARY_COLOR, PlaitMind, PlaitMindComponent, QUICK_INSERT_CIRCLE_COLOR, QUICK_INSERT_CIRCLE_OFFSET, QUICK_INSERT_INNER_CROSS_COLOR, ROOT_TOPIC_FONT_SIZE, ROOT_TOPIC_HEIGHT, STROKE_WIDTH, TOPIC_COLOR, TOPIC_DEFAULT_MAX_WORD_COUNT, TOPIC_FONT_SIZE, TRANSPARENT, WithMindPluginKey, addActiveOnDragOrigin, adjustAbstractToNode, adjustNodeToRoot, adjustRootToNode, canSetAbstract, copyNewNode, correctLayoutByDirection, createDefaultMind, createEmptyMind, createMindElement, deleteElementHandleAbstract, deleteElementsHandleRightNodeCount, detectDropTarget, directionCorrector, directionDetector, divideElementByParent, drawFakeDragNode, drawFakeDropNode, editTopic, extractNodesText, findLastChild, findLocationLeftIndex, getAbstractBranchColor, getAbstractBranchWidth, getAbstractHandleRectangle, getAllowedDirection, getAvailableSubLayoutsByLayoutDirections, getBehindAbstracts, getBranchColorByMindElement, getBranchDirectionsByLayouts, getBranchShapeByMindElement, getBranchWidthByMindElement, getChildrenCount, getCorrespondingAbstract, getDefaultBranchColor, getDefaultBranchColorByIndex, getDefaultLayout, getEmojiForeignRectangle, getEmojiRectangle, getFirstLevelElement, getHitAbstractHandle, getImageForeignRectangle, getInCorrectLayoutDirection, getLayoutDirection$1 as getLayoutDirection, getLayoutReverseDirection, getLocationScope, getMindThemeColor, getNextBranchColor, getOverallAbstracts, getPathByDropTarget, getRectangleByElement, getRectangleByNode, getRectangleByResizingLocation, getRelativeStartEndByAbstractRef, getRootLayout, getShapeByElement, getStrokeByMindElement, getStrokeWidthByElement, getTopicRectangleByElement, getTopicRectangleByNode, getValidAbstractRefs, handleTouchedAbstract, hasAfterDraw, hasPreviousOrNextOfDropPath, insertElementHandleAbstract, insertElementHandleRightNodeCount, insertMindElement, isChildElement, isChildOfAbstract, isChildRight, isChildUp, isCorrectLayout, isDragging, isDropStandardRight, isHitEmojis, isHitImage, isHitMindElement, isInRightBranchOfStandardLayout, isMixedLayout, isSetAbstract, isValidTarget, isVirtualKey, removeActiveOnDragOrigin, separateChildren, setIsDragging, withMind, withMindExtend };
3991
4035
  //# sourceMappingURL=plait-mind.mjs.map