开源白板工具(SaaS),一体化白板,包含思维导图、流程图、自由画等。All in one open-source whiteboard tool with mind, flowchart, freehand and etc.
feat(freehand): support closed freehand and add popup for freehand (#68)
pubuzhixing8c4c6c6b989e9
diff --git a/packages/drawnix/src/components/toolbar/popup-toolbar/popup-toolbar.tsx b/packages/drawnix/src/components/toolbar/popup-toolbar/popup-toolbar.tsxindex c8433e1..b1a03e5 100644--- a/packages/drawnix/src/components/toolbar/popup-toolbar/popup-toolbar.tsx+++ b/packages/drawnix/src/components/toolbar/popup-toolbar/popup-toolbar.tsx@@ -6,12 +6,10 @@ import {isDragging,isMovingElements,isSelectionMoving,- Path,PlaitBoard,PlaitElement,SELECTION_RECTANGLE_BOUNDING_CLASS_NAME,SELECTION_RECTANGLE_CLASS_NAME,- Transforms,} from '@plait/core';import React, { useEffect, useRef, useState } from 'react';import { useBoard } from '@plait/react-board';@@ -24,25 +22,20 @@ import {} from '@plait/mind';import './popup-toolbar.scss';import {- DrawTransforms,- getMemorizeKey,- getSelectedTableCellsEditor,getStrokeColorByElement as getStrokeColorByDrawElement,+ isCustomGeometryClosed,isDrawElementClosed,isDrawElementsIncludeText,PlaitDrawElement,} from '@plait/draw';-import { CustomText, PropertyTransforms } from '@plait/common';-import {- getTextMarksByElement,- PlaitMarkEditor,- TextTransforms,-} from '@plait/text-plugins';+import { CustomText } from '@plait/common';+import { getTextMarksByElement } from '@plait/text-plugins';import { PopupFontColorButton } from './font-color-button';import { PopupStrokeButton } from './stroke-button';import { PopupFillButton } from './fill-button';import { isWhite, removeHexAlpha } from '../../../utils/color';import { NO_COLOR } from '../../../constants/color';+import { Freehand } from '../../../plugins/freehand/type';export const PopupToolbar = () => {const board = useBoard();@@ -245,6 +238,9 @@ export const hasFillProperty = (board: PlaitBoard, element: PlaitElement) => {if (MindElement.isMindElement(board, element)) {return true;}+ if (isCustomGeometryClosed(board, element)) {+ return true;+ }if (PlaitDrawElement.isDrawElement(element)) {return (PlaitDrawElement.isShapeElement(element) &&@@ -260,6 +256,9 @@ export const hasStrokeProperty = (board: PlaitBoard, element: PlaitElement) => {if (MindElement.isMindElement(board, element)) {return true;}+ if (Freehand.isFreehand(element)) {+ return true;+ }if (PlaitDrawElement.isDrawElement(element)) {return ((PlaitDrawElement.isShapeElement(element) &&diff --git a/packages/drawnix/src/plugins/freehand/freehand.generator.ts b/packages/drawnix/src/plugins/freehand/freehand.generator.tsindex fb7a0af..24db624 100644--- a/packages/drawnix/src/plugins/freehand/freehand.generator.ts+++ b/packages/drawnix/src/plugins/freehand/freehand.generator.ts@@ -14,7 +14,7 @@ export class FreehandGenerator extends Generator<Freehand> {const strokeWidth = getStrokeWidthByElement(element);const strokeColor = getStrokeColorByElement(this.board, element);const fill = getFillByElement(this.board, element);- const option: Options = { strokeWidth, stroke: strokeColor, fill };+ const option: Options = { strokeWidth, stroke: strokeColor, fill, fillStyle: 'solid' };const g = PlaitBoard.getRoughSVG(this.board).curve(gaussianSmooth(element.points, 1, 3),optiondiff --git a/packages/drawnix/src/plugins/freehand/with-freehand-create.ts b/packages/drawnix/src/plugins/freehand/with-freehand-create.tsindex dca841f..c42dae9 100644--- a/packages/drawnix/src/plugins/freehand/with-freehand-create.ts+++ b/packages/drawnix/src/plugins/freehand/with-freehand-create.ts@@ -2,6 +2,7 @@ import {PlaitBoard,Point,Transforms,+ distanceBetweenPointAndPoint,toHostPoint,toViewBoxPoint,} from '@plait/core';@@ -16,8 +17,12 @@ export const withFreehandCreate = (board: PlaitBoard) => {let isDrawing = false;+ let isSnapping = false;+let points: Point[] = [];+ let originScreenPoint: Point | null = null;+const generator = new FreehandGenerator(board);const smoother = new FreehandSmoother({@@ -30,6 +35,9 @@ export const withFreehandCreate = (board: PlaitBoard) => {const complete = (cancel?: boolean) => {if (isDrawing) {const pointer = PlaitBoard.getPointer(board) as FreehandShape;+ if (isSnapping) {+ points.push(points[0]);+ }temporaryElement = createFreehandElement(pointer, points);}if (temporaryElement && !cancel) {@@ -47,8 +55,8 @@ export const withFreehandCreate = (board: PlaitBoard) => {const isFreehandPointer = PlaitBoard.isInPointer(board, freehandPointers);if (isFreehandPointer && isDrawingMode(board)) {isDrawing = true;- const originPoint: Point = [event.x, event.y];- const smoothingPoint = smoother.process(originPoint) as Point;+ originScreenPoint = [event.x, event.y];+ const smoothingPoint = smoother.process(originScreenPoint) as Point;const point = toViewBoxPoint(board,toHostPoint(board, smoothingPoint[0], smoothingPoint[1])@@ -60,8 +68,21 @@ export const withFreehandCreate = (board: PlaitBoard) => {board.pointerMove = (event: PointerEvent) => {if (isDrawing) {- const originPoint: Point = [event.x, event.y];- const smoothingPoint = smoother.process(originPoint);+ const currentScreenPoint: Point = [event.x, event.y];+ if (+ originScreenPoint &&+ distanceBetweenPointAndPoint(+ originScreenPoint[0],+ originScreenPoint[1],+ currentScreenPoint[0],+ currentScreenPoint[1]+ ) < 8+ ) {+ isSnapping = true;+ } else {+ isSnapping = false;+ }+ const smoothingPoint = smoother.process(currentScreenPoint);if (smoothingPoint) {generator?.destroy();const newPoint = toViewBoxPoint(