From 446f87153629f318a1af57c65977f9fc664098ff Mon Sep 17 00:00:00 2001 From: dwelle <5153846+dwelle@users.noreply.github.com> Date: Tue, 8 Jul 2025 23:44:54 +0200 Subject: [PATCH] Revert "differentiate between constant/variable stroke type" This reverts commit 0199c82e9830736748532d35ef21f6f1b73a6961. --- .../components/FreedrawDebugSliders.tsx | 6 +- packages/element/src/freedraw.ts | 70 +++++-------------- packages/excalidraw/components/App.tsx | 7 +- 3 files changed, 21 insertions(+), 62 deletions(-) diff --git a/excalidraw-app/components/FreedrawDebugSliders.tsx b/excalidraw-app/components/FreedrawDebugSliders.tsx index b5a665265f..6a6989777c 100644 --- a/excalidraw-app/components/FreedrawDebugSliders.tsx +++ b/excalidraw-app/components/FreedrawDebugSliders.tsx @@ -8,10 +8,10 @@ import { round } from "../../packages/math/src"; export const FreedrawDebugSliders = () => { const [streamline, setStreamline] = useState( - DRAWING_CONFIGS.default.variable.streamline, + DRAWING_CONFIGS.default.streamline, ); const [simplify, setSimplify] = useState( - DRAWING_CONFIGS.default.variable.simplify, + DRAWING_CONFIGS.default.simplify, ); useEffect(() => { @@ -21,7 +21,7 @@ export const FreedrawDebugSliders = () => { if (!window.h.debugFreedraw) { window.h.debugFreedraw = { enabled: true, - ...DRAWING_CONFIGS.default.variable, + ...DRAWING_CONFIGS.default, }; } diff --git a/packages/element/src/freedraw.ts b/packages/element/src/freedraw.ts index 78cc45a6fa..ec6b1c9fa8 100644 --- a/packages/element/src/freedraw.ts +++ b/packages/element/src/freedraw.ts @@ -8,70 +8,34 @@ import type { StrokeOptions } from "perfect-freehand"; import type { ExcalidrawFreeDrawElement, PointerType } from "./types"; -type FreedrawStrokeType = "constant" | "variable"; - -export const getElementStrokeType = ( - element: ExcalidrawFreeDrawElement, -): FreedrawStrokeType => { - return element.drawingConfigs?.fixedStrokeWidth ? "constant" : "variable"; -}; - export const DRAWING_CONFIGS: Record< PointerType | "default", - Record + { streamline: number; simplify: number } > = { default: { - constant: { - streamline: 0.35, - simplify: 0.1, - }, - variable: { - streamline: 0.35, - simplify: 0.1, - }, + streamline: 0.35, + simplify: 0.1, }, mouse: { - constant: { - streamline: 0.6, - simplify: 0.1, - }, - variable: { - streamline: 0.6, - simplify: 0.1, - }, + streamline: 0.6, + simplify: 0.1, }, pen: { - constant: { - // for optimal performance, we use a lower streamline and simplify - streamline: 0.2, - simplify: 0.1, - }, - variable: { - // for optimal performance, we use a lower streamline and simplify - streamline: 0.2, - simplify: 0.1, - }, + // for optimal performance, we use a lower streamline and simplify + streamline: 0.2, + simplify: 0.1, }, touch: { - constant: { - streamline: 0.65, - simplify: 0.1, - }, - variable: { - streamline: 0.65, - simplify: 0.1, - }, + streamline: 0.65, + simplify: 0.1, }, } as const; -export const getFreedrawConfig = ( - eventType: string | null | undefined, - strokeType: FreedrawStrokeType, -): { streamline: number; simplify: number } => { - const inputConfig = +export const getFreedrawConfig = (eventType: string | null | undefined) => { + return ( DRAWING_CONFIGS[(eventType as PointerType | null) || "default"] || - DRAWING_CONFIGS.default; - return inputConfig[strokeType]; + DRAWING_CONFIGS.default + ); }; /** @@ -141,11 +105,9 @@ export const getFreedrawStroke = (element: ExcalidrawFreeDrawElement) => { } const streamline = - element.drawingConfigs?.streamline ?? - getFreedrawConfig("default", getElementStrokeType(element)).streamline; + element.drawingConfigs?.streamline ?? DRAWING_CONFIGS.default.streamline; const simplify = - element.drawingConfigs?.simplify ?? - getFreedrawConfig("default", getElementStrokeType(element)).simplify; + element.drawingConfigs?.simplify ?? DRAWING_CONFIGS.default.simplify; const laser = new LaserPointer({ size: element.strokeWidth, diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx index a4aed41e17..c35195d684 100644 --- a/packages/excalidraw/components/App.tsx +++ b/packages/excalidraw/components/App.tsx @@ -7479,10 +7479,7 @@ class App extends React.Component { window.__lastPressure__ = event.pressure; - const freedrawConfig = getFreedrawConfig( - event.pointerType, - this.state.currentItemFixedStrokeWidth ? "constant" : "variable", - ); + const freedrawConfig = getFreedrawConfig(event.pointerType); const element = newFreeDrawElement({ type: elementType, @@ -11174,7 +11171,7 @@ export const createTestHook = () => { // Initialize debug freedraw parameters window.h.debugFreedraw = { enabled: true, - ...(window.h.debugFreedraw || DRAWING_CONFIGS.default.variable), + ...(window.h.debugFreedraw || DRAWING_CONFIGS.default), }; Object.defineProperties(window.h, {