@logicflow/core 2.0.0-beta.1 → 2.0.0-beta.10
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/.turbo/turbo-build$colon$dev.log +2 -2
- package/.turbo/turbo-build.log +9 -9
- package/__tests__/bugs/1545-spec.test.ts +19 -15
- package/__tests__/util/edge.test.ts +57 -57
- package/dist/index.min.js +9 -3
- package/es/LogicFlow.d.ts +88 -40
- package/es/LogicFlow.js +38 -33
- package/es/LogicFlow.js.map +1 -1
- package/es/algorithm/edge.js.map +1 -1
- package/es/algorithm/index.d.ts +2 -0
- package/es/algorithm/index.js +2 -0
- package/es/algorithm/index.js.map +1 -1
- package/es/algorithm/outline.d.ts +1 -1
- package/es/common/drag.d.ts +51 -0
- package/es/common/drag.js +145 -0
- package/es/common/drag.js.map +1 -0
- package/es/common/history.d.ts +28 -0
- package/es/common/history.js +92 -0
- package/es/common/history.js.map +1 -0
- package/es/common/index.d.ts +5 -0
- package/es/common/index.js +6 -0
- package/es/common/index.js.map +1 -0
- package/es/common/keyboard.d.ts +34 -0
- package/es/common/keyboard.js +80 -0
- package/es/common/keyboard.js.map +1 -0
- package/es/common/matrix.d.ts +30 -0
- package/es/common/matrix.js +155 -0
- package/es/common/matrix.js.map +1 -0
- package/es/common/vector.d.ts +23 -0
- package/es/common/vector.js +97 -0
- package/es/common/vector.js.map +1 -0
- package/es/constant/index.d.ts +39 -2
- package/es/constant/index.js +41 -1
- package/es/constant/index.js.map +1 -1
- package/es/event/eventArgs.d.ts +103 -25
- package/es/event/eventEmitter.d.ts +2 -2
- package/es/event/eventEmitter.js +0 -1
- package/es/event/eventEmitter.js.map +1 -1
- package/es/index.d.ts +6 -1
- package/es/index.js +6 -1
- package/es/index.js.map +1 -1
- package/es/keyboard/index.d.ts +1 -0
- package/es/keyboard/index.js +1 -0
- package/es/keyboard/index.js.map +1 -1
- package/es/keyboard/shortcut.d.ts +8 -0
- package/es/keyboard/shortcut.js +70 -8
- package/es/keyboard/shortcut.js.map +1 -1
- package/es/model/BaseModel.d.ts +16 -7
- package/es/model/EditConfigModel.d.ts +97 -36
- package/es/model/EditConfigModel.js +169 -82
- package/es/model/EditConfigModel.js.map +1 -1
- package/es/model/GraphModel.d.ts +36 -14
- package/es/model/GraphModel.js +60 -10
- package/es/model/GraphModel.js.map +1 -1
- package/es/model/SnaplineModel.d.ts +2 -0
- package/es/model/TransformModel.js +1 -1
- package/es/model/TransformModel.js.map +1 -1
- package/es/model/edge/BaseEdgeModel.d.ts +21 -17
- package/es/model/edge/BaseEdgeModel.js +64 -42
- package/es/model/edge/BaseEdgeModel.js.map +1 -1
- package/es/model/edge/BezierEdgeModel.d.ts +5 -3
- package/es/model/edge/BezierEdgeModel.js +7 -3
- package/es/model/edge/BezierEdgeModel.js.map +1 -1
- package/es/model/edge/LineEdgeModel.d.ts +2 -0
- package/es/model/edge/LineEdgeModel.js +2 -1
- package/es/model/edge/LineEdgeModel.js.map +1 -1
- package/es/model/edge/PolylineEdgeModel.d.ts +5 -3
- package/es/model/edge/PolylineEdgeModel.js +22 -15
- package/es/model/edge/PolylineEdgeModel.js.map +1 -1
- package/es/model/node/BaseNodeModel.d.ts +42 -14
- package/es/model/node/BaseNodeModel.js +62 -48
- package/es/model/node/BaseNodeModel.js.map +1 -1
- package/es/model/node/CircleNodeModel.d.ts +4 -3
- package/es/model/node/CircleNodeModel.js +4 -7
- package/es/model/node/CircleNodeModel.js.map +1 -1
- package/es/model/node/DiamondNodeModel.d.ts +5 -4
- package/es/model/node/DiamondNodeModel.js +4 -6
- package/es/model/node/DiamondNodeModel.js.map +1 -1
- package/es/model/node/EllipseNodeModel.d.ts +5 -4
- package/es/model/node/EllipseNodeModel.js +4 -6
- package/es/model/node/EllipseNodeModel.js.map +1 -1
- package/es/model/node/HtmlNodeModel.d.ts +4 -5
- package/es/model/node/HtmlNodeModel.js +2 -12
- package/es/model/node/HtmlNodeModel.js.map +1 -1
- package/es/model/node/PolygonNodeModel.d.ts +5 -4
- package/es/model/node/PolygonNodeModel.js +4 -7
- package/es/model/node/PolygonNodeModel.js.map +1 -1
- package/es/model/node/RectNodeModel.d.ts +7 -5
- package/es/model/node/RectNodeModel.js +10 -7
- package/es/model/node/RectNodeModel.js.map +1 -1
- package/es/model/node/TextNodeModel.d.ts +17 -9
- package/es/model/node/TextNodeModel.js +2 -1
- package/es/model/node/TextNodeModel.js.map +1 -1
- package/es/options.d.ts +6 -3
- package/es/options.js +2 -11
- package/es/options.js.map +1 -1
- package/es/tool/MultipleSelectTool.d.ts +1 -1
- package/es/tool/MultipleSelectTool.js +5 -5
- package/es/tool/MultipleSelectTool.js.map +1 -1
- package/es/tool/TextEditTool.d.ts +3 -3
- package/es/tool/TextEditTool.js +2 -2
- package/es/tool/TextEditTool.js.map +1 -1
- package/es/tool/index.d.ts +24 -2
- package/es/tool/index.js +82 -2
- package/es/tool/index.js.map +1 -1
- package/es/util/drag.d.ts +5 -5
- package/es/util/drag.js +3 -1
- package/es/util/drag.js.map +1 -1
- package/es/util/edge.d.ts +9 -2
- package/es/util/edge.js +23 -12
- package/es/util/edge.js.map +1 -1
- package/es/util/index.d.ts +1 -0
- package/es/util/index.js +1 -0
- package/es/util/index.js.map +1 -1
- package/es/util/node.d.ts +8 -7
- package/es/util/node.js +26 -7
- package/es/util/node.js.map +1 -1
- package/es/util/resize.d.ts +32 -0
- package/es/util/resize.js +197 -0
- package/es/util/resize.js.map +1 -0
- package/es/view/Anchor.d.ts +6 -7
- package/es/view/Anchor.js +6 -3
- package/es/view/Anchor.js.map +1 -1
- package/es/view/Control.d.ts +1 -1
- package/es/view/Control.js +88 -39
- package/es/view/Control.js.map +1 -1
- package/es/view/Graph.d.ts +5 -1
- package/es/view/Graph.js +43 -3
- package/es/view/Graph.js.map +1 -1
- package/es/view/Rotate.js +2 -1
- package/es/view/Rotate.js.map +1 -1
- package/es/view/behavior/index.d.ts +2 -0
- package/es/view/behavior/index.js +3 -0
- package/es/view/behavior/index.js.map +1 -0
- package/es/view/behavior/snapline.d.ts +3 -0
- package/es/{tool → view/behavior}/snapline.js +0 -1
- package/es/view/behavior/snapline.js.map +1 -0
- package/es/view/edge/AdjustPoint.js +12 -23
- package/es/view/edge/AdjustPoint.js.map +1 -1
- package/es/view/edge/BaseEdge.d.ts +2 -2
- package/es/view/edge/BaseEdge.js +30 -22
- package/es/view/edge/BaseEdge.js.map +1 -1
- package/es/view/node/BaseNode.d.ts +4 -4
- package/es/view/node/BaseNode.js +33 -24
- package/es/view/node/BaseNode.js.map +1 -1
- package/es/view/node/CircleNode.d.ts +1 -1
- package/es/view/node/CircleNode.js.map +1 -1
- package/es/view/node/DiamondNode.d.ts +1 -1
- package/es/view/node/DiamondNode.js.map +1 -1
- package/es/view/node/EllipseNode.d.ts +1 -1
- package/es/view/node/EllipseNode.js.map +1 -1
- package/es/view/node/HtmlNode.d.ts +1 -1
- package/es/view/node/HtmlNode.js +2 -2
- package/es/view/node/HtmlNode.js.map +1 -1
- package/es/view/node/PolygonNode.d.ts +1 -1
- package/es/view/node/PolygonNode.js.map +1 -1
- package/es/view/node/RectNode.d.ts +1 -1
- package/es/view/node/RectNode.js.map +1 -1
- package/es/view/node/TextNode.d.ts +1 -1
- package/es/view/node/TextNode.js +1 -1
- package/es/view/node/TextNode.js.map +1 -1
- package/es/view/overlay/CanvasOverlay.js +5 -4
- package/es/view/overlay/CanvasOverlay.js.map +1 -1
- package/es/view/overlay/ToolOverlay.d.ts +1 -1
- package/es/view/overlay/ToolOverlay.js +1 -1
- package/es/view/overlay/ToolOverlay.js.map +1 -1
- package/es/view/shape/Circle.d.ts +9 -1
- package/es/view/shape/Circle.js +5 -5
- package/es/view/shape/Circle.js.map +1 -1
- package/es/view/shape/Ellipse.d.ts +10 -1
- package/es/view/shape/Ellipse.js +5 -5
- package/es/view/shape/Ellipse.js.map +1 -1
- package/es/view/shape/Line.d.ts +14 -1
- package/es/view/shape/Line.js +5 -7
- package/es/view/shape/Line.js.map +1 -1
- package/es/view/shape/Path.d.ts +3 -2
- package/es/view/shape/Path.js +3 -3
- package/es/view/shape/Path.js.map +1 -1
- package/es/view/shape/Polygon.d.ts +5 -3
- package/es/view/shape/Polygon.js +6 -6
- package/es/view/shape/Polygon.js.map +1 -1
- package/es/view/shape/Polyline.d.ts +7 -1
- package/es/view/shape/Polyline.js +8 -6
- package/es/view/shape/Polyline.js.map +1 -1
- package/es/view/shape/Rect.d.ts +11 -13
- package/es/view/shape/Rect.js +6 -9
- package/es/view/shape/Rect.js.map +1 -1
- package/es/view/shape/Text.d.ts +19 -1
- package/es/view/shape/Text.js +28 -21
- package/es/view/shape/Text.js.map +1 -1
- package/es/view/text/BaseText.d.ts +12 -15
- package/es/view/text/BaseText.js +43 -29
- package/es/view/text/BaseText.js.map +1 -1
- package/es/view/text/LineText.d.ts +19 -7
- package/es/view/text/LineText.js +62 -54
- package/es/view/text/LineText.js.map +1 -1
- package/lib/LogicFlow.d.ts +88 -40
- package/lib/LogicFlow.js +40 -35
- package/lib/LogicFlow.js.map +1 -1
- package/lib/algorithm/edge.js.map +1 -1
- package/lib/algorithm/index.d.ts +2 -0
- package/lib/algorithm/index.js +17 -1
- package/lib/algorithm/index.js.map +1 -1
- package/lib/algorithm/outline.d.ts +1 -1
- package/lib/common/drag.d.ts +51 -0
- package/lib/common/drag.js +148 -0
- package/lib/common/drag.js.map +1 -0
- package/lib/common/history.d.ts +28 -0
- package/lib/common/history.js +95 -0
- package/lib/common/history.js.map +1 -0
- package/lib/common/index.d.ts +5 -0
- package/lib/common/index.js +22 -0
- package/lib/common/index.js.map +1 -0
- package/lib/common/keyboard.d.ts +34 -0
- package/lib/common/keyboard.js +86 -0
- package/lib/common/keyboard.js.map +1 -0
- package/lib/common/matrix.d.ts +30 -0
- package/lib/common/matrix.js +158 -0
- package/lib/common/matrix.js.map +1 -0
- package/lib/common/vector.d.ts +23 -0
- package/lib/common/vector.js +101 -0
- package/lib/common/vector.js.map +1 -0
- package/lib/constant/index.d.ts +39 -2
- package/lib/constant/index.js +42 -2
- package/lib/constant/index.js.map +1 -1
- package/lib/event/eventArgs.d.ts +103 -25
- package/lib/event/eventEmitter.d.ts +2 -2
- package/lib/event/eventEmitter.js +0 -1
- package/lib/event/eventEmitter.js.map +1 -1
- package/lib/index.d.ts +6 -1
- package/lib/index.js +7 -2
- package/lib/index.js.map +1 -1
- package/lib/keyboard/index.d.ts +1 -0
- package/lib/keyboard/index.js +15 -0
- package/lib/keyboard/index.js.map +1 -1
- package/lib/keyboard/shortcut.d.ts +8 -0
- package/lib/keyboard/shortcut.js +75 -9
- package/lib/keyboard/shortcut.js.map +1 -1
- package/lib/model/BaseModel.d.ts +16 -7
- package/lib/model/EditConfigModel.d.ts +97 -36
- package/lib/model/EditConfigModel.js +168 -81
- package/lib/model/EditConfigModel.js.map +1 -1
- package/lib/model/GraphModel.d.ts +36 -14
- package/lib/model/GraphModel.js +59 -9
- package/lib/model/GraphModel.js.map +1 -1
- package/lib/model/SnaplineModel.d.ts +2 -0
- package/lib/model/TransformModel.js +1 -1
- package/lib/model/TransformModel.js.map +1 -1
- package/lib/model/edge/BaseEdgeModel.d.ts +21 -17
- package/lib/model/edge/BaseEdgeModel.js +61 -39
- package/lib/model/edge/BaseEdgeModel.js.map +1 -1
- package/lib/model/edge/BezierEdgeModel.d.ts +5 -3
- package/lib/model/edge/BezierEdgeModel.js +6 -2
- package/lib/model/edge/BezierEdgeModel.js.map +1 -1
- package/lib/model/edge/LineEdgeModel.d.ts +2 -0
- package/lib/model/edge/LineEdgeModel.js +2 -1
- package/lib/model/edge/LineEdgeModel.js.map +1 -1
- package/lib/model/edge/PolylineEdgeModel.d.ts +5 -3
- package/lib/model/edge/PolylineEdgeModel.js +21 -14
- package/lib/model/edge/PolylineEdgeModel.js.map +1 -1
- package/lib/model/node/BaseNodeModel.d.ts +42 -14
- package/lib/model/node/BaseNodeModel.js +60 -46
- package/lib/model/node/BaseNodeModel.js.map +1 -1
- package/lib/model/node/CircleNodeModel.d.ts +4 -3
- package/lib/model/node/CircleNodeModel.js +4 -7
- package/lib/model/node/CircleNodeModel.js.map +1 -1
- package/lib/model/node/DiamondNodeModel.d.ts +5 -4
- package/lib/model/node/DiamondNodeModel.js +4 -6
- package/lib/model/node/DiamondNodeModel.js.map +1 -1
- package/lib/model/node/EllipseNodeModel.d.ts +5 -4
- package/lib/model/node/EllipseNodeModel.js +4 -6
- package/lib/model/node/EllipseNodeModel.js.map +1 -1
- package/lib/model/node/HtmlNodeModel.d.ts +4 -5
- package/lib/model/node/HtmlNodeModel.js +2 -12
- package/lib/model/node/HtmlNodeModel.js.map +1 -1
- package/lib/model/node/PolygonNodeModel.d.ts +5 -4
- package/lib/model/node/PolygonNodeModel.js +4 -7
- package/lib/model/node/PolygonNodeModel.js.map +1 -1
- package/lib/model/node/RectNodeModel.d.ts +7 -5
- package/lib/model/node/RectNodeModel.js +10 -7
- package/lib/model/node/RectNodeModel.js.map +1 -1
- package/lib/model/node/TextNodeModel.d.ts +17 -9
- package/lib/model/node/TextNodeModel.js +2 -1
- package/lib/model/node/TextNodeModel.js.map +1 -1
- package/lib/options.d.ts +6 -3
- package/lib/options.js +2 -11
- package/lib/options.js.map +1 -1
- package/lib/tool/MultipleSelectTool.d.ts +1 -1
- package/lib/tool/MultipleSelectTool.js +5 -5
- package/lib/tool/MultipleSelectTool.js.map +1 -1
- package/lib/tool/TextEditTool.d.ts +3 -3
- package/lib/tool/TextEditTool.js +4 -4
- package/lib/tool/TextEditTool.js.map +1 -1
- package/lib/tool/index.d.ts +24 -2
- package/lib/tool/index.js +85 -15
- package/lib/tool/index.js.map +1 -1
- package/lib/util/drag.d.ts +5 -5
- package/lib/util/drag.js +3 -1
- package/lib/util/drag.js.map +1 -1
- package/lib/util/edge.d.ts +9 -2
- package/lib/util/edge.js +27 -15
- package/lib/util/edge.js.map +1 -1
- package/lib/util/index.d.ts +1 -0
- package/lib/util/index.js +1 -0
- package/lib/util/index.js.map +1 -1
- package/lib/util/node.d.ts +8 -7
- package/lib/util/node.js +28 -9
- package/lib/util/node.js.map +1 -1
- package/lib/util/resize.d.ts +32 -0
- package/lib/util/resize.js +204 -0
- package/lib/util/resize.js.map +1 -0
- package/lib/view/Anchor.d.ts +6 -7
- package/lib/view/Anchor.js +5 -2
- package/lib/view/Anchor.js.map +1 -1
- package/lib/view/Control.d.ts +1 -1
- package/lib/view/Control.js +87 -38
- package/lib/view/Control.js.map +1 -1
- package/lib/view/Graph.d.ts +5 -1
- package/lib/view/Graph.js +42 -2
- package/lib/view/Graph.js.map +1 -1
- package/lib/view/Rotate.js +2 -1
- package/lib/view/Rotate.js.map +1 -1
- package/lib/view/behavior/index.d.ts +2 -0
- package/lib/view/behavior/index.js +19 -0
- package/lib/view/behavior/index.js.map +1 -0
- package/lib/view/behavior/snapline.d.ts +3 -0
- package/lib/{tool → view/behavior}/snapline.js +0 -1
- package/lib/view/behavior/snapline.js.map +1 -0
- package/lib/view/edge/AdjustPoint.js +11 -22
- package/lib/view/edge/AdjustPoint.js.map +1 -1
- package/lib/view/edge/BaseEdge.d.ts +2 -2
- package/lib/view/edge/BaseEdge.js +29 -21
- package/lib/view/edge/BaseEdge.js.map +1 -1
- package/lib/view/node/BaseNode.d.ts +4 -4
- package/lib/view/node/BaseNode.js +32 -23
- package/lib/view/node/BaseNode.js.map +1 -1
- package/lib/view/node/CircleNode.d.ts +1 -1
- package/lib/view/node/CircleNode.js.map +1 -1
- package/lib/view/node/DiamondNode.d.ts +1 -1
- package/lib/view/node/DiamondNode.js.map +1 -1
- package/lib/view/node/EllipseNode.d.ts +1 -1
- package/lib/view/node/EllipseNode.js.map +1 -1
- package/lib/view/node/HtmlNode.d.ts +1 -1
- package/lib/view/node/HtmlNode.js +2 -2
- package/lib/view/node/HtmlNode.js.map +1 -1
- package/lib/view/node/PolygonNode.d.ts +1 -1
- package/lib/view/node/PolygonNode.js.map +1 -1
- package/lib/view/node/RectNode.d.ts +1 -1
- package/lib/view/node/RectNode.js.map +1 -1
- package/lib/view/node/TextNode.d.ts +1 -1
- package/lib/view/node/TextNode.js +1 -1
- package/lib/view/node/TextNode.js.map +1 -1
- package/lib/view/overlay/CanvasOverlay.js +5 -4
- package/lib/view/overlay/CanvasOverlay.js.map +1 -1
- package/lib/view/overlay/ToolOverlay.d.ts +1 -1
- package/lib/view/overlay/ToolOverlay.js +1 -1
- package/lib/view/overlay/ToolOverlay.js.map +1 -1
- package/lib/view/shape/Circle.d.ts +9 -1
- package/lib/view/shape/Circle.js +5 -5
- package/lib/view/shape/Circle.js.map +1 -1
- package/lib/view/shape/Ellipse.d.ts +10 -1
- package/lib/view/shape/Ellipse.js +5 -5
- package/lib/view/shape/Ellipse.js.map +1 -1
- package/lib/view/shape/Line.d.ts +14 -1
- package/lib/view/shape/Line.js +5 -7
- package/lib/view/shape/Line.js.map +1 -1
- package/lib/view/shape/Path.d.ts +3 -2
- package/lib/view/shape/Path.js +3 -3
- package/lib/view/shape/Path.js.map +1 -1
- package/lib/view/shape/Polygon.d.ts +5 -3
- package/lib/view/shape/Polygon.js +6 -6
- package/lib/view/shape/Polygon.js.map +1 -1
- package/lib/view/shape/Polyline.d.ts +7 -1
- package/lib/view/shape/Polyline.js +8 -6
- package/lib/view/shape/Polyline.js.map +1 -1
- package/lib/view/shape/Rect.d.ts +11 -13
- package/lib/view/shape/Rect.js +6 -9
- package/lib/view/shape/Rect.js.map +1 -1
- package/lib/view/shape/Text.d.ts +19 -1
- package/lib/view/shape/Text.js +29 -21
- package/lib/view/shape/Text.js.map +1 -1
- package/lib/view/text/BaseText.d.ts +12 -15
- package/lib/view/text/BaseText.js +46 -29
- package/lib/view/text/BaseText.js.map +1 -1
- package/lib/view/text/LineText.d.ts +19 -7
- package/lib/view/text/LineText.js +62 -57
- package/lib/view/text/LineText.js.map +1 -1
- package/package.json +2 -1
- package/src/LogicFlow.tsx +163 -79
- package/src/algorithm/edge.ts +1 -0
- package/src/algorithm/index.ts +2 -0
- package/src/algorithm/outline.ts +2 -2
- package/src/common/drag.ts +219 -0
- package/src/common/history.ts +108 -0
- package/src/common/index.ts +6 -0
- package/src/common/keyboard.ts +108 -0
- package/src/common/matrix.ts +122 -0
- package/src/common/vector.ts +93 -0
- package/src/constant/index.ts +43 -1
- package/src/event/eventArgs.ts +173 -34
- package/src/event/eventEmitter.ts +2 -3
- package/src/index.ts +6 -1
- package/src/keyboard/index.ts +2 -0
- package/src/keyboard/shortcut.ts +79 -8
- package/src/model/BaseModel.ts +18 -7
- package/src/model/EditConfigModel.ts +209 -97
- package/src/model/GraphModel.ts +64 -9
- package/src/model/TransformModel.ts +1 -1
- package/src/model/edge/BaseEdgeModel.ts +75 -44
- package/src/model/edge/BezierEdgeModel.ts +7 -6
- package/src/model/edge/LineEdgeModel.ts +2 -0
- package/src/model/edge/PolylineEdgeModel.ts +24 -18
- package/src/model/node/BaseNodeModel.ts +72 -47
- package/src/model/node/CircleNodeModel.ts +8 -7
- package/src/model/node/DiamondNodeModel.ts +9 -6
- package/src/model/node/EllipseNodeModel.ts +9 -6
- package/src/model/node/HtmlNodeModel.ts +8 -7
- package/src/model/node/PolygonNodeModel.ts +9 -7
- package/src/model/node/RectNodeModel.ts +16 -8
- package/src/model/node/TextNodeModel.ts +14 -1
- package/src/options.ts +11 -15
- package/src/tool/MultipleSelectTool.tsx +6 -6
- package/src/tool/TextEditTool.tsx +3 -3
- package/src/tool/index.ts +96 -2
- package/src/util/drag.ts +22 -6
- package/src/util/edge.ts +39 -13
- package/src/util/index.ts +1 -0
- package/src/util/node.ts +36 -13
- package/src/util/resize.ts +286 -0
- package/src/view/Anchor.tsx +7 -5
- package/src/view/Control.tsx +93 -62
- package/src/view/Graph.tsx +21 -4
- package/src/view/Rotate.tsx +2 -1
- package/src/view/behavior/index.ts +2 -0
- package/src/{tool → view/behavior}/snapline.ts +3 -4
- package/src/view/edge/AdjustPoint.tsx +35 -49
- package/src/view/edge/BaseEdge.tsx +65 -45
- package/src/view/node/BaseNode.tsx +55 -28
- package/src/view/node/CircleNode.tsx +3 -1
- package/src/view/node/DiamondNode.tsx +3 -1
- package/src/view/node/EllipseNode.tsx +3 -1
- package/src/view/node/HtmlNode.tsx +5 -3
- package/src/view/node/PolygonNode.tsx +3 -1
- package/src/view/node/RectNode.tsx +3 -1
- package/src/view/node/TextNode.tsx +4 -2
- package/src/view/overlay/CanvasOverlay.tsx +5 -4
- package/src/view/overlay/ToolOverlay.tsx +1 -1
- package/src/view/shape/Circle.tsx +21 -7
- package/src/view/shape/Ellipse.tsx +20 -6
- package/src/view/shape/Line.tsx +24 -9
- package/src/view/shape/Path.tsx +9 -6
- package/src/view/shape/Polygon.tsx +13 -10
- package/src/view/shape/Polyline.tsx +20 -8
- package/src/view/shape/Rect.tsx +19 -19
- package/src/view/shape/Text.tsx +64 -33
- package/src/view/text/BaseText.tsx +76 -42
- package/src/view/text/LineText.tsx +94 -80
- package/tsconfig.json +1 -1
- package/es/tool/snapline.d.ts +0 -3
- package/es/tool/snapline.js.map +0 -1
- package/es/tool/tool.d.ts +0 -22
- package/es/tool/tool.js +0 -43
- package/es/tool/tool.js.map +0 -1
- package/lib/tool/snapline.d.ts +0 -3
- package/lib/tool/snapline.js.map +0 -1
- package/lib/tool/tool.d.ts +0 -22
- package/lib/tool/tool.js +0 -49
- package/lib/tool/tool.js.map +0 -1
- package/src/tool/tool.ts +0 -66
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { noop } from 'lodash-es'
|
|
2
|
+
import { Model } from '../model'
|
|
3
|
+
import { EventType } from '../constant'
|
|
4
|
+
import EventEmitter from '../event/eventEmitter'
|
|
5
|
+
|
|
6
|
+
// TODO:这种方式在同构项目中,会报错,该如何解决(是否要求用户控制在浏览器环境时才初始化)
|
|
7
|
+
// const DOC: any = window?.document
|
|
8
|
+
const LEFT_MOUSE_BUTTON_CODE = 0
|
|
9
|
+
|
|
10
|
+
export type IDragParams = {
|
|
11
|
+
deltaX: number
|
|
12
|
+
deltaY: number
|
|
13
|
+
event: MouseEvent | null
|
|
14
|
+
[key: string]: unknown
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type ICreateDragParams = {
|
|
18
|
+
onDragStart?: (params: Partial<IDragParams>) => void
|
|
19
|
+
onDragging?: (param: IDragParams) => void
|
|
20
|
+
onDragEnd?: (param: Partial<IDragParams>) => void
|
|
21
|
+
step?: number
|
|
22
|
+
isStopPropagation?: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type IStepperDragProps = {
|
|
26
|
+
eventType?:
|
|
27
|
+
| 'NODE'
|
|
28
|
+
| 'BLANK'
|
|
29
|
+
| 'SELECTION'
|
|
30
|
+
| 'ADJUST_POINT'
|
|
31
|
+
| 'TEXT'
|
|
32
|
+
| 'LABEL'
|
|
33
|
+
| ''
|
|
34
|
+
eventCenter?: EventEmitter
|
|
35
|
+
model?: Model.BaseModel
|
|
36
|
+
data?: Record<string, unknown>
|
|
37
|
+
[key: string]: unknown
|
|
38
|
+
} & Partial<ICreateDragParams>
|
|
39
|
+
/**
|
|
40
|
+
* 支持拖拽时按步长进行移动
|
|
41
|
+
* REMIND:在绘制的过程中因为放大缩小,移动的真实 step 是变化的
|
|
42
|
+
*/
|
|
43
|
+
export class StepperDrag {
|
|
44
|
+
// 初始化
|
|
45
|
+
onDragStart: (params: Partial<IDragParams>) => void
|
|
46
|
+
onDragging: (params: IDragParams) => void
|
|
47
|
+
onDragEnd: (params: Partial<IDragParams>) => void
|
|
48
|
+
|
|
49
|
+
step: number
|
|
50
|
+
isStopPropagation: boolean
|
|
51
|
+
eventType:
|
|
52
|
+
| 'NODE'
|
|
53
|
+
| 'BLANK'
|
|
54
|
+
| 'SELECTION'
|
|
55
|
+
| 'ADJUST_POINT'
|
|
56
|
+
| 'TEXT'
|
|
57
|
+
| 'LABEL'
|
|
58
|
+
| ''
|
|
59
|
+
eventCenter?: EventEmitter
|
|
60
|
+
model?: Model.BaseModel
|
|
61
|
+
data?: Record<string, unknown>
|
|
62
|
+
|
|
63
|
+
// 运行时
|
|
64
|
+
isDragging: boolean = false
|
|
65
|
+
isStartDrag: boolean = false
|
|
66
|
+
|
|
67
|
+
startX: number = 0
|
|
68
|
+
startY: number = 0
|
|
69
|
+
totalDeltaX: number = 0
|
|
70
|
+
totalDeltaY: number = 0
|
|
71
|
+
|
|
72
|
+
startTime?: number
|
|
73
|
+
constructor({
|
|
74
|
+
onDragStart = noop,
|
|
75
|
+
onDragging = noop,
|
|
76
|
+
onDragEnd = noop,
|
|
77
|
+
step = 1,
|
|
78
|
+
eventType = '',
|
|
79
|
+
isStopPropagation = true,
|
|
80
|
+
eventCenter,
|
|
81
|
+
model,
|
|
82
|
+
data,
|
|
83
|
+
}: IStepperDragProps) {
|
|
84
|
+
this.onDragStart = onDragStart
|
|
85
|
+
this.onDragging = onDragging
|
|
86
|
+
this.onDragEnd = onDragEnd
|
|
87
|
+
this.step = step
|
|
88
|
+
this.eventType = eventType
|
|
89
|
+
this.isStopPropagation = isStopPropagation
|
|
90
|
+
this.eventCenter = eventCenter
|
|
91
|
+
this.model = model
|
|
92
|
+
this.data = data
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
setStep(step: number) {
|
|
96
|
+
this.step = step
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
handleMouseMove = (e: MouseEvent) => {
|
|
100
|
+
if (this.isStopPropagation) e.stopPropagation()
|
|
101
|
+
if (!this.isStartDrag) return
|
|
102
|
+
|
|
103
|
+
this.totalDeltaX += e.clientX - this.startX
|
|
104
|
+
this.totalDeltaY += e.clientY - this.startY
|
|
105
|
+
this.startX = e.clientX
|
|
106
|
+
this.startY = e.clientY
|
|
107
|
+
|
|
108
|
+
if (
|
|
109
|
+
this.step <= 1 ||
|
|
110
|
+
Math.abs(this.totalDeltaX) > this.step ||
|
|
111
|
+
Math.abs(this.totalDeltaY) > this.step
|
|
112
|
+
) {
|
|
113
|
+
const remainderX = this.totalDeltaX % this.step
|
|
114
|
+
const remainderY = this.totalDeltaY % this.step
|
|
115
|
+
|
|
116
|
+
const deltaX = this.totalDeltaX - remainderX
|
|
117
|
+
const deltaY = this.totalDeltaY - remainderY
|
|
118
|
+
|
|
119
|
+
this.totalDeltaX = remainderX
|
|
120
|
+
this.totalDeltaY = remainderY
|
|
121
|
+
|
|
122
|
+
const elementData = this.model?.getData()
|
|
123
|
+
// REMIND: 为了区分点击和拖动,在鼠标没有拖动时,不触发 dragstart。
|
|
124
|
+
if (!this.isDragging) {
|
|
125
|
+
if (this.eventType) {
|
|
126
|
+
this.eventCenter?.emit(EventType[`${this.eventType}_DRAGSTART`], {
|
|
127
|
+
e,
|
|
128
|
+
data: this.data || elementData,
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
this.onDragStart({ event: e })
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
this.isDragging = true
|
|
135
|
+
// REMIND: 为了让 dragstart 和 drag 不在同一个事件循环中,将 drag 事件放在下一个任务队列中。
|
|
136
|
+
// TODO: 测试用例是否可覆盖???
|
|
137
|
+
Promise.resolve().then(() => {
|
|
138
|
+
this.onDragging({ deltaX, deltaY, event: e })
|
|
139
|
+
if (this.eventType) {
|
|
140
|
+
this.eventCenter?.emit(EventType[`${this.eventType}_MOUSEMOVE`], {
|
|
141
|
+
e,
|
|
142
|
+
data: this.data || elementData,
|
|
143
|
+
})
|
|
144
|
+
this.eventCenter?.emit(EventType[`${this.eventType}_DRAG`], {
|
|
145
|
+
e,
|
|
146
|
+
data: this.data || elementData,
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
handleMouseUp = (e: MouseEvent) => {
|
|
154
|
+
const DOC: any = window?.document
|
|
155
|
+
|
|
156
|
+
this.isStartDrag = false
|
|
157
|
+
if (this.isStopPropagation) e.stopPropagation()
|
|
158
|
+
|
|
159
|
+
// fix: issue#568, 如果 onDragging 在下一个时间循环中触发,而 drop 在当前事件循环,会出现问题
|
|
160
|
+
Promise.resolve().then(() => {
|
|
161
|
+
DOC?.removeEventListener('mousemove', this.handleMouseMove, true)
|
|
162
|
+
DOC?.removeEventListener('mouseup', this.handleMouseUp, true)
|
|
163
|
+
|
|
164
|
+
const elementData = this.model?.getData()
|
|
165
|
+
if (this.eventType) {
|
|
166
|
+
this.eventCenter?.emit(EventType[`${this.eventType}_MOUSEUP`], {
|
|
167
|
+
e,
|
|
168
|
+
data: this.data || elementData,
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (!this.isDragging) return
|
|
173
|
+
this.isDragging = false
|
|
174
|
+
this.onDragEnd({ event: e })
|
|
175
|
+
if (this.eventType) {
|
|
176
|
+
this.eventCenter?.emit(EventType[`${this.eventType}_DROP`], {
|
|
177
|
+
e,
|
|
178
|
+
data: this.data || elementData,
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
})
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
handleMouseDown = (e: MouseEvent) => {
|
|
185
|
+
const DOC: any = window?.document
|
|
186
|
+
|
|
187
|
+
// issue: LogicFlow交流群-3群 8.10 号抛出的事件相关的问题,是否是这引起的???
|
|
188
|
+
if (e.button !== LEFT_MOUSE_BUTTON_CODE) return
|
|
189
|
+
if (this.isStopPropagation) e.stopPropagation()
|
|
190
|
+
|
|
191
|
+
this.isStartDrag = true
|
|
192
|
+
this.startX = e.clientX
|
|
193
|
+
this.startY = e.clientY
|
|
194
|
+
|
|
195
|
+
DOC?.addEventListener('mousemove', this.handleMouseMove, true)
|
|
196
|
+
DOC?.addEventListener('mouseup', this.handleMouseUp, true)
|
|
197
|
+
|
|
198
|
+
const elementData = this.model?.getData()
|
|
199
|
+
if (this.eventType) {
|
|
200
|
+
this.eventCenter?.emit(EventType[`${this.eventType}_MOUSEDOWN`], {
|
|
201
|
+
e,
|
|
202
|
+
data: this.data || elementData,
|
|
203
|
+
})
|
|
204
|
+
}
|
|
205
|
+
this.startTime = new Date().getTime()
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
cancelDrag = () => {
|
|
209
|
+
const DOC: any = window?.document
|
|
210
|
+
|
|
211
|
+
DOC?.removeEventListener('mousemove', this.handleMouseMove, true)
|
|
212
|
+
DOC?.removeEventListener('mouseup', this.handleMouseUp, true)
|
|
213
|
+
|
|
214
|
+
this.onDragEnd({ event: null })
|
|
215
|
+
this.isDragging = false
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export default StepperDrag
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { cloneDeep, debounce, isEqual, last } from 'lodash-es'
|
|
2
|
+
import { deepObserve, IDisposer } from 'mobx-utils'
|
|
3
|
+
import { LogicFlow } from '../LogicFlow'
|
|
4
|
+
// import { EventType } from '../constant'
|
|
5
|
+
import { GraphModel } from '../model'
|
|
6
|
+
import EventEmitter from '../event/eventEmitter'
|
|
7
|
+
|
|
8
|
+
export type HistoryData = LogicFlow.GraphConfigData
|
|
9
|
+
|
|
10
|
+
export class History {
|
|
11
|
+
undos: HistoryData[] = []
|
|
12
|
+
redos: HistoryData[] = []
|
|
13
|
+
stopWatch: IDisposer | null = null
|
|
14
|
+
curData: HistoryData | null = null
|
|
15
|
+
maxSize: number = 50
|
|
16
|
+
// 发生数据变化后,最多再等 500ms,把距离上次的数据变更存储起来。
|
|
17
|
+
// 所以 waitTime 值越小,History 对数据变化越敏感,存的 undos 数据就越细
|
|
18
|
+
waitTime: number = 100
|
|
19
|
+
eventCenter: EventEmitter
|
|
20
|
+
|
|
21
|
+
constructor(eventCenter: EventEmitter) {
|
|
22
|
+
this.eventCenter = eventCenter
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
add(data: HistoryData) {
|
|
26
|
+
if (isEqual(last(this.undos), data)) return
|
|
27
|
+
this.undos.push(data)
|
|
28
|
+
|
|
29
|
+
// 因为 undo 的时候会触发 add.
|
|
30
|
+
// 所以需要区分这个 add 是 undo 触发的还是用户正常操作触发的
|
|
31
|
+
// 如果是用户正常操作触发的,需要清空 redos
|
|
32
|
+
if (!isEqual(this.curData, data)) {
|
|
33
|
+
this.redos = []
|
|
34
|
+
}
|
|
35
|
+
// this.eventCenter.emit(EventType.HISTORY_CHANGE, {
|
|
36
|
+
// data: {
|
|
37
|
+
// undos: this.undos,
|
|
38
|
+
// redos: this.redos,
|
|
39
|
+
// undoAble: this.undos.length > 1,
|
|
40
|
+
// redoAble: this.redos.length > 0,
|
|
41
|
+
// },
|
|
42
|
+
// })
|
|
43
|
+
|
|
44
|
+
if (this.undos.length > this.maxSize) {
|
|
45
|
+
this.undos.shift()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
undoAble() {
|
|
50
|
+
return this.undos.length > 1
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* undo 方法触发:
|
|
55
|
+
* graphModel 重新渲染 nodes 和 edges
|
|
56
|
+
* graphModel 发生变化,触发 watch
|
|
57
|
+
* watch 触发 add
|
|
58
|
+
*/
|
|
59
|
+
undo() {
|
|
60
|
+
if (!this.undoAble()) return
|
|
61
|
+
const preData = this.undos.pop()
|
|
62
|
+
if (preData) {
|
|
63
|
+
this.redos.push(preData)
|
|
64
|
+
}
|
|
65
|
+
const curData = this.undos.pop()
|
|
66
|
+
if (curData) {
|
|
67
|
+
this.curData = cloneDeep(curData)
|
|
68
|
+
}
|
|
69
|
+
return curData
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
redoAble() {
|
|
73
|
+
return this.redos.length > 0
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
redo() {
|
|
77
|
+
if (!this.redoAble()) return
|
|
78
|
+
const curData = this.redos.pop()
|
|
79
|
+
if (curData) {
|
|
80
|
+
this.curData = cloneDeep(curData)
|
|
81
|
+
}
|
|
82
|
+
return curData
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
watch(model: GraphModel) {
|
|
86
|
+
this.stopWatch && this.stopWatch()
|
|
87
|
+
|
|
88
|
+
// 把当前 watch 的 model 转换一下数据存起来,无需清空 redos
|
|
89
|
+
const historyData = model.modelToHistoryData()
|
|
90
|
+
if (historyData) {
|
|
91
|
+
this.undos.push(historyData)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
this.stopWatch = deepObserve(
|
|
95
|
+
model,
|
|
96
|
+
debounce(() => {
|
|
97
|
+
// 数据变更后,把最新的当前 model 数据存起来,并清空 redos
|
|
98
|
+
// 因为这个回调函数的触发,一般是用户交互而引起的,所以按照正常逻辑需要清空 redos
|
|
99
|
+
const data = model.modelToHistoryData()
|
|
100
|
+
if (data) {
|
|
101
|
+
this.add(data)
|
|
102
|
+
}
|
|
103
|
+
}, this.waitTime),
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export default History
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import Mousetrap, { MousetrapInstance } from 'mousetrap'
|
|
2
|
+
import { forEach, isArray } from 'lodash-es'
|
|
3
|
+
import LogicFlow from '..'
|
|
4
|
+
|
|
5
|
+
export class Keyboard {
|
|
6
|
+
private target: HTMLElement
|
|
7
|
+
readonly mousetrap: MousetrapInstance
|
|
8
|
+
options: Required<Keyboard.Options>
|
|
9
|
+
|
|
10
|
+
constructor(options: Keyboard.Options) {
|
|
11
|
+
const { lf } = options
|
|
12
|
+
if (!options.keyboard) {
|
|
13
|
+
options.keyboard = { enabled: false }
|
|
14
|
+
}
|
|
15
|
+
this.options = options as Required<Keyboard.Options>
|
|
16
|
+
this.target = lf.container
|
|
17
|
+
this.mousetrap = new Mousetrap(this.target)
|
|
18
|
+
|
|
19
|
+
if (options.keyboard?.enabled) {
|
|
20
|
+
this.enable(true)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
protected formatKey(key: string) {
|
|
25
|
+
return key
|
|
26
|
+
.toLowerCase()
|
|
27
|
+
.replace(/\s/g, '')
|
|
28
|
+
.replace('delete', 'del')
|
|
29
|
+
.replace('cmd', 'command')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private getKeys(keys: string | string[]) {
|
|
33
|
+
return (isArray(keys) ? keys : [keys]).map((key) => this.formatKey(key))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get disabled() {
|
|
37
|
+
return this.options.keyboard?.enabled !== true
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
on(
|
|
41
|
+
keys: string | string[],
|
|
42
|
+
callback: Keyboard.HandlerFunc,
|
|
43
|
+
action?: Keyboard.ActionType,
|
|
44
|
+
) {
|
|
45
|
+
this.mousetrap.bind(this.getKeys(keys), callback, action)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
off(keys: string | string[], action?: Keyboard.ActionType) {
|
|
49
|
+
this.mousetrap.unbind(this.getKeys(keys), action)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
enable(force: boolean) {
|
|
53
|
+
if (this.disabled || force) {
|
|
54
|
+
this.options.keyboard.enabled = true
|
|
55
|
+
if (this.target instanceof HTMLElement) {
|
|
56
|
+
this.target.setAttribute('tabindex', '-1')
|
|
57
|
+
// 去掉节点被选中时 container 出现的边框
|
|
58
|
+
this.target.style.outline = 'none'
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
disable() {
|
|
64
|
+
if (!this.disabled) {
|
|
65
|
+
this.options.keyboard.enabled = false
|
|
66
|
+
if (this.target instanceof HTMLElement) {
|
|
67
|
+
this.target.removeAttribute('tabindex')
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
initShortcuts() {
|
|
73
|
+
const { shortcuts } = this.options.keyboard
|
|
74
|
+
if (shortcuts) {
|
|
75
|
+
if (isArray(shortcuts)) {
|
|
76
|
+
forEach(shortcuts, ({ keys, callback, action }) => {
|
|
77
|
+
this.on(keys, callback, action)
|
|
78
|
+
})
|
|
79
|
+
} else {
|
|
80
|
+
const { keys, callback, action } = shortcuts
|
|
81
|
+
this.on(keys, callback, action)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export namespace Keyboard {
|
|
88
|
+
export type ActionType = 'keypress' | 'keydown' | 'keyup'
|
|
89
|
+
export type HandlerFunc = (e: KeyboardEvent) => void
|
|
90
|
+
|
|
91
|
+
export interface Shortcut {
|
|
92
|
+
keys: string | string[]
|
|
93
|
+
callback: HandlerFunc
|
|
94
|
+
action?: ActionType
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface KeyboardDef {
|
|
98
|
+
enabled: boolean
|
|
99
|
+
shortcuts?: Shortcut | Shortcut[]
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface Options {
|
|
103
|
+
lf: LogicFlow
|
|
104
|
+
keyboard?: KeyboardDef
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export default Keyboard
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Vector } from './vector'
|
|
2
|
+
|
|
3
|
+
export class Matrix extends Array {
|
|
4
|
+
rows: number
|
|
5
|
+
columns: number
|
|
6
|
+
|
|
7
|
+
constructor(...vectors: any[]) {
|
|
8
|
+
super(vectors.length)
|
|
9
|
+
this.fill(new Array(3))
|
|
10
|
+
vectors.forEach((v: any, index: number) => {
|
|
11
|
+
this[index] = v
|
|
12
|
+
})
|
|
13
|
+
this.columns = vectors[0].length
|
|
14
|
+
this.rows = vectors.length
|
|
15
|
+
Object.setPrototypeOf(this, Matrix.prototype)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
getRow(index: number) {
|
|
19
|
+
return this[index]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getColumn(index: number) {
|
|
23
|
+
return [...this.map((row: number[]) => row[index])]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 转置
|
|
27
|
+
transpose() {
|
|
28
|
+
const rows: any[] = []
|
|
29
|
+
for (let i = 0; i < this.columns; i++) {
|
|
30
|
+
rows.push(this.getColumn(i))
|
|
31
|
+
}
|
|
32
|
+
return new Matrix(...rows)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 叉乘
|
|
36
|
+
cross(m1: Matrix) {
|
|
37
|
+
const arr = new Array(this.rows).fill('').map((): any => [])
|
|
38
|
+
if (this.columns === m1.rows) {
|
|
39
|
+
for (let i = 0; i < this.rows; i++) {
|
|
40
|
+
const row = this.getRow(i)
|
|
41
|
+
for (let j = 0; j < m1.columns; j++) {
|
|
42
|
+
const column = m1.getColumn(j)
|
|
43
|
+
arr[i][j] = row.reduce(
|
|
44
|
+
(prev: number, r: number, index: number) =>
|
|
45
|
+
prev + r * column[index],
|
|
46
|
+
0,
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return new Matrix(...arr)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 返回二维坐标(降维)
|
|
55
|
+
to2D() {
|
|
56
|
+
return this.map((item: any) => [item[0], item[1]])
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
toString(): string {
|
|
60
|
+
const [[a, b], [c, d], [e, f]] = this
|
|
61
|
+
return `matrix(${a} ${b} ${c} ${d} ${e} ${f})`
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
translate(tx: number, ty: number): Matrix {
|
|
65
|
+
return this.cross(new TranslateMatrix(tx, ty))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
rotate(angle: number): Matrix {
|
|
69
|
+
return this.cross(new RotateMatrix(angle))
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
scale(sx: number, sy: number): Matrix {
|
|
73
|
+
return this.cross(new ScaleMatrix(sx, sy))
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export class RotateMatrix extends Matrix {
|
|
78
|
+
constructor(theta: number) {
|
|
79
|
+
super(
|
|
80
|
+
new Vector(+Math.cos(theta).toFixed(2), +Math.sin(theta).toFixed(2), 0),
|
|
81
|
+
new Vector(-Math.sin(theta).toFixed(2), +Math.cos(theta).toFixed(2), 0),
|
|
82
|
+
new Vector(0, 0, 1),
|
|
83
|
+
)
|
|
84
|
+
Object.setPrototypeOf(this, RotateMatrix.prototype)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
inverse() {
|
|
88
|
+
return this.transpose()
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export class ScaleMatrix extends Matrix {
|
|
93
|
+
private readonly sx: number
|
|
94
|
+
private readonly sy: number
|
|
95
|
+
|
|
96
|
+
constructor(sx: number, sy: number) {
|
|
97
|
+
super(new Vector(sx, 0, 0), new Vector(0, sy, 0), new Vector(0, 0, 1))
|
|
98
|
+
this.sx = sx
|
|
99
|
+
this.sy = sy
|
|
100
|
+
Object.setPrototypeOf(this, ScaleMatrix.prototype)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
inverse() {
|
|
104
|
+
return new ScaleMatrix(1 / this.sx, 1 / this.sy)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export class TranslateMatrix extends Matrix {
|
|
109
|
+
private readonly tx: number
|
|
110
|
+
private readonly ty: number
|
|
111
|
+
|
|
112
|
+
constructor(tx: number, ty: number) {
|
|
113
|
+
super(new Vector(1, 0, 0), new Vector(0, 1, 0), new Vector(tx, ty, 1))
|
|
114
|
+
this.tx = tx
|
|
115
|
+
this.ty = ty
|
|
116
|
+
Object.setPrototypeOf(this, TranslateMatrix.prototype)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
inverse() {
|
|
120
|
+
return new TranslateMatrix(-this.tx, -this.ty)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
function isVector(a1: any, a2: any): boolean {
|
|
2
|
+
return a1 instanceof Vector && a2 instanceof Vector
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
class Base extends Array {
|
|
6
|
+
x: number
|
|
7
|
+
y: number
|
|
8
|
+
z: number
|
|
9
|
+
|
|
10
|
+
constructor(x: number, y: number, z: number) {
|
|
11
|
+
super(3)
|
|
12
|
+
this[0] = x
|
|
13
|
+
this[1] = y
|
|
14
|
+
this[2] = z
|
|
15
|
+
this.x = x
|
|
16
|
+
this.y = y
|
|
17
|
+
this.z = z
|
|
18
|
+
Object.setPrototypeOf(this, Base.prototype)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
add(v1: Vector | Point): Vector | Point {
|
|
22
|
+
if (isVector(this, v1)) {
|
|
23
|
+
return new Vector(this.x + v1.x, this.y + v1.y)
|
|
24
|
+
}
|
|
25
|
+
const z = this.z + v1.z
|
|
26
|
+
return new Point((this.x + v1.x) / z, (this.y + v1.y) / z)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
subtract(v1: Vector | Point): Vector | Point {
|
|
30
|
+
if (isVector(this, v1)) {
|
|
31
|
+
return new Vector(this.x - v1.x, this.y - v1.y)
|
|
32
|
+
}
|
|
33
|
+
const z = this.z - v1.z
|
|
34
|
+
return z === 0
|
|
35
|
+
? new Vector(this.x - v1.x, this.y - v1.y)
|
|
36
|
+
: new Point((this.x - v1.x) / z, (this.y - v1.y) / z)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
class Vector extends Base {
|
|
41
|
+
constructor(x: number, y: number, z?: number) {
|
|
42
|
+
super(x, y, z ?? 0)
|
|
43
|
+
Object.setPrototypeOf(this, Vector.prototype)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
toString(): string {
|
|
47
|
+
return 'Vector'
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
dot(v1: Vector) {
|
|
51
|
+
return v1.reduce((prev, cur, index) => prev + cur * this[index])
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
cross(v1: Vector) {
|
|
55
|
+
return new Vector(
|
|
56
|
+
this.y * v1.z - this.z * v1.y,
|
|
57
|
+
this.z * v1.x - this.x * v1.z,
|
|
58
|
+
this.x * v1.y - this.y * v1.x,
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getLength() {
|
|
63
|
+
return Math.hypot(this.x, this.y)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
normalize() {
|
|
67
|
+
const len = this.getLength()
|
|
68
|
+
return new Vector(this.x / len, this.y / len)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
crossZ(v1: Vector) {
|
|
72
|
+
return this.x * v1.y - this.y * v1.x
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
angle(v1: Vector) {
|
|
76
|
+
const negative = this.crossZ(v1)
|
|
77
|
+
const r = Math.acos(this.normalize().dot(v1.normalize()))
|
|
78
|
+
return negative >= 0 ? r : -r
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
class Point extends Base {
|
|
83
|
+
constructor(x: number, y: number) {
|
|
84
|
+
super(x, y, 1)
|
|
85
|
+
Object.setPrototypeOf(this, Point.prototype)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
toString(): string {
|
|
89
|
+
return 'Point'
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { Vector, Point }
|
package/src/constant/index.ts
CHANGED
|
@@ -109,11 +109,48 @@ export enum EventType {
|
|
|
109
109
|
SELECTION_CONTEXTMENU = 'selection:contextmenu',
|
|
110
110
|
CONNECTION_NOT_ALLOWED = 'connection:not-allowed',
|
|
111
111
|
|
|
112
|
+
// Text events
|
|
113
|
+
TEXT_MOUSEDOWN = 'text:mousedown',
|
|
114
|
+
TEXT_DRAGSTART = 'text:dragstart',
|
|
115
|
+
TEXT_DRAG = 'text:drag',
|
|
116
|
+
TEXT_DROP = 'text:drop',
|
|
117
|
+
TEXT_CLICK = 'text:click',
|
|
118
|
+
TEXT_DBCLICK = 'text:dbclick',
|
|
119
|
+
TEXT_BLUR = 'text:blur',
|
|
120
|
+
TEXT_MOUSEMOVE = 'text:mousemove',
|
|
121
|
+
TEXT_MOUSEUP = 'text:mouseup',
|
|
122
|
+
TEXT_FOCUS = 'text:focus',
|
|
123
|
+
TEXT_ADD = 'text:add',
|
|
124
|
+
TEXT_UPDATE = 'text:update',
|
|
125
|
+
TEXT_CLEAR = 'text:clear',
|
|
126
|
+
|
|
127
|
+
// label events
|
|
128
|
+
LABEL_MOUSEDOWN = 'label:mousedown',
|
|
129
|
+
LABEL_DRAGSTART = 'label:dragstart',
|
|
130
|
+
LABEL_DRAG = 'label:drag',
|
|
131
|
+
LABEL_DROP = 'label:drop',
|
|
132
|
+
LABEL_CLICK = 'label:click',
|
|
133
|
+
LABEL_DBCLICK = 'label:dbclick',
|
|
134
|
+
LABEL_BLUR = 'label:blur',
|
|
135
|
+
LABEL_MOUSEMOVE = 'label:mousemove',
|
|
136
|
+
LABEL_MOUSEUP = 'label:mouseup',
|
|
137
|
+
LABEL_FOCUS = 'label:focus',
|
|
138
|
+
LABEL_ADD = 'label:add',
|
|
139
|
+
LABEL_UPDATE = 'label:update',
|
|
140
|
+
LABEL_CLEAR = 'label:clear',
|
|
141
|
+
LABEL_DELETE = 'label:delete',
|
|
142
|
+
LABEL_SHOULD_ADD = 'label:should-add',
|
|
143
|
+
LABEL_BATCH_ADD = 'label:batch-add',
|
|
144
|
+
LABEL_SHOULD_UPDATE = 'label:should-update',
|
|
145
|
+
LABEL_SHOULD_DELETE = 'label:should-delete',
|
|
146
|
+
LABEL_BATCH_DELETE = 'label:batch-delete',
|
|
147
|
+
LABEL_NOT_ALLOWED_ADD = 'label:not-allowed-add',
|
|
148
|
+
|
|
112
149
|
// Other events
|
|
113
150
|
HISTORY_CHANGE = 'history:change',
|
|
114
|
-
TEXT_UPDATE = 'text:update',
|
|
115
151
|
GRAPH_TRANSFORM = 'graph:transform',
|
|
116
152
|
GRAPH_RENDERED = 'graph:rendered',
|
|
153
|
+
GRAPH_UPDATED = 'graph:updated',
|
|
117
154
|
}
|
|
118
155
|
|
|
119
156
|
export enum OverlapMode {
|
|
@@ -125,3 +162,8 @@ export enum SegmentDirection {
|
|
|
125
162
|
HORIZONTAL = 'horizontal',
|
|
126
163
|
VERTICAL = 'vertical',
|
|
127
164
|
}
|
|
165
|
+
|
|
166
|
+
export enum TextMode {
|
|
167
|
+
TEXT = 'text',
|
|
168
|
+
LABEL = 'label',
|
|
169
|
+
}
|