From c72c47f0cda8bab06d1eb34bac7493912e392b33 Mon Sep 17 00:00:00 2001 From: Ryan Di Date: Mon, 16 Jun 2025 17:19:55 +1000 Subject: [PATCH] remove debug and provide value for stylus --- excalidraw-app/App.tsx | 2 - .../components/FreedrawDebugSliders.tsx | 89 ------------------- packages/element/src/freedraw.ts | 5 ++ packages/excalidraw/components/App.tsx | 15 +--- .../tests/__snapshots__/history.test.tsx.snap | 30 +++++-- .../regressionTests.test.tsx.snap | 18 +++- .../data/__snapshots__/restore.test.ts.snap | 6 +- 7 files changed, 53 insertions(+), 112 deletions(-) delete mode 100644 excalidraw-app/components/FreedrawDebugSliders.tsx diff --git a/excalidraw-app/App.tsx b/excalidraw-app/App.tsx index 40c14ca3e3..932743ddfd 100644 --- a/excalidraw-app/App.tsx +++ b/excalidraw-app/App.tsx @@ -134,7 +134,6 @@ import DebugCanvas, { } from "./components/DebugCanvas"; import { AIComponents } from "./components/AI"; import { ExcalidrawPlusIframeExport } from "./ExcalidrawPlusIframeExport"; -import { FreedrawDebugSliders } from "./components/FreedrawDebugSliders"; import "./index.scss"; @@ -1143,7 +1142,6 @@ const ExcalidrawWrapper = () => { ref={debugCanvasRef} /> )} - ); diff --git a/excalidraw-app/components/FreedrawDebugSliders.tsx b/excalidraw-app/components/FreedrawDebugSliders.tsx deleted file mode 100644 index 85d843e9a9..0000000000 --- a/excalidraw-app/components/FreedrawDebugSliders.tsx +++ /dev/null @@ -1,89 +0,0 @@ -import { DRAWING_CONFIGS } from "@excalidraw/element"; -import { useState, useEffect } from "react"; - -export const FreedrawDebugSliders = () => { - const [streamline, setStreamline] = useState( - DRAWING_CONFIGS.default.streamline, - ); - const [simplify, setSimplify] = useState( - DRAWING_CONFIGS.default.simplify, - ); - - useEffect(() => { - if (!window.h) { - window.h = {} as any; - } - if (!window.h.debugFreedraw) { - window.h.debugFreedraw = DRAWING_CONFIGS.default; - } - - setStreamline(window.h.debugFreedraw.streamline); - setSimplify(window.h.debugFreedraw.simplify); - }, []); - - const handleStreamlineChange = (value: number) => { - setStreamline(value); - if (window.h && window.h.debugFreedraw) { - window.h.debugFreedraw.streamline = value; - } - }; - - const handleSimplifyChange = (value: number) => { - setSimplify(value); - if (window.h && window.h.debugFreedraw) { - window.h.debugFreedraw.simplify = value; - } - }; - - return ( -
-
- -
-
- -
-
- ); -}; diff --git a/packages/element/src/freedraw.ts b/packages/element/src/freedraw.ts index 5d4696049f..7f984f6d31 100644 --- a/packages/element/src/freedraw.ts +++ b/packages/element/src/freedraw.ts @@ -11,6 +11,11 @@ import type { ExcalidrawFreeDrawElement } from "./types"; export const DRAWING_CONFIGS = { default: { streamline: 0.25, + simplify: 0.25, + }, + // for optimal performance, we use a lower streamline and simplify + stylus: { + streamline: 0.1, simplify: 0.1, }, } as const; diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx index 6edfb88d2f..d7750e4dd5 100644 --- a/packages/excalidraw/components/App.tsx +++ b/packages/excalidraw/components/App.tsx @@ -7594,11 +7594,9 @@ class App extends React.Component { simulatePressure, drawingConfigs: { pressureSensitivity: this.state.currentItemPressureSensitivity, - streamline: - window.h?.debugFreedraw?.streamline ?? - DRAWING_CONFIGS.default.streamline, - simplify: - window.h?.debugFreedraw?.simplify ?? DRAWING_CONFIGS.default.simplify, + ...(event.pointerType === "pen" + ? DRAWING_CONFIGS.stylus + : DRAWING_CONFIGS.default), }, locked: false, frameId: topLayerFrame ? topLayerFrame.id : null, @@ -11382,10 +11380,6 @@ declare global { app: InstanceType; history: History; store: Store; - debugFreedraw?: { - streamline: number; - simplify: number; - }; }; } } @@ -11394,9 +11388,6 @@ export const createTestHook = () => { if (isTestEnv() || isDevEnv()) { window.h = window.h || ({} as Window["h"]); - // Initialize debug freedraw parameters - window.h.debugFreedraw = window.h.debugFreedraw || DRAWING_CONFIGS.default; - Object.defineProperties(window.h, { elements: { configurable: true, diff --git a/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap index dd02103fb9..70dff4bd64 100644 --- a/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap +++ b/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap @@ -8910,6 +8910,11 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte "backgroundColor": "transparent", "boundElements": null, "customData": undefined, + "drawingConfigs": { + "pressureSensitivity": 1, + "simplify": "0.25000", + "streamline": "0.25000", + }, "fillStyle": "solid", "frameId": null, "groupIds": [], @@ -8942,7 +8947,6 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte 50, ], ], - "pressureSensitivity": 1, "pressures": [], "roughness": 1, "roundness": null, @@ -9015,6 +9019,11 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte "backgroundColor": "transparent", "boundElements": null, "customData": undefined, + "drawingConfigs": { + "pressureSensitivity": 1, + "simplify": "0.25000", + "streamline": "0.25000", + }, "fillStyle": "solid", "frameId": null, "groupIds": [], @@ -9046,7 +9055,6 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte 50, ], ], - "pressureSensitivity": 1, "pressures": [], "roughness": 1, "roundness": null, @@ -12064,6 +12072,11 @@ exports[`history > singleplayer undo/redo > should create entry when selecting f "backgroundColor": "transparent", "boundElements": null, "customData": undefined, + "drawingConfigs": { + "pressureSensitivity": 1, + "simplify": "0.25000", + "streamline": "0.25000", + }, "fillStyle": "solid", "frameId": null, "groupIds": [], @@ -12092,7 +12105,6 @@ exports[`history > singleplayer undo/redo > should create entry when selecting f 10, ], ], - "pressureSensitivity": 1, "pressures": [], "roughness": 1, "roundness": null, @@ -12115,6 +12127,11 @@ exports[`history > singleplayer undo/redo > should create entry when selecting f "backgroundColor": "transparent", "boundElements": null, "customData": undefined, + "drawingConfigs": { + "pressureSensitivity": 1, + "simplify": "0.25000", + "streamline": "0.25000", + }, "fillStyle": "solid", "frameId": null, "groupIds": [], @@ -12143,7 +12160,6 @@ exports[`history > singleplayer undo/redo > should create entry when selecting f 10, ], ], - "pressureSensitivity": 1, "pressures": [], "roughness": 1, "roundness": null, @@ -12256,6 +12272,11 @@ exports[`history > singleplayer undo/redo > should create entry when selecting f "backgroundColor": "transparent", "boundElements": null, "customData": undefined, + "drawingConfigs": { + "pressureSensitivity": 1, + "simplify": "0.25000", + "streamline": "0.25000", + }, "fillStyle": "solid", "frameId": null, "groupIds": [], @@ -12283,7 +12304,6 @@ exports[`history > singleplayer undo/redo > should create entry when selecting f 10, ], ], - "pressureSensitivity": 1, "pressures": [], "roughness": 1, "roundness": null, diff --git a/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap index 3fbebddd7a..86ef418bdd 100644 --- a/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap +++ b/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap @@ -6877,6 +6877,11 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack "backgroundColor": "transparent", "boundElements": null, "customData": undefined, + "drawingConfigs": { + "pressureSensitivity": 1, + "simplify": "0.25000", + "streamline": "0.25000", + }, "fillStyle": "solid", "frameId": null, "groupIds": [], @@ -6904,7 +6909,6 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack 10, ], ], - "pressureSensitivity": 1, "pressures": [], "roughness": 1, "roundness": null, @@ -9152,6 +9156,11 @@ exports[`regression tests > key 7 selects freedraw tool > [end of test] undo sta "backgroundColor": "transparent", "boundElements": null, "customData": undefined, + "drawingConfigs": { + "pressureSensitivity": 1, + "simplify": "0.25000", + "streamline": "0.25000", + }, "fillStyle": "solid", "frameId": null, "groupIds": [], @@ -9179,7 +9188,6 @@ exports[`regression tests > key 7 selects freedraw tool > [end of test] undo sta 10, ], ], - "pressureSensitivity": 1, "pressures": [], "roughness": 1, "roundness": null, @@ -10156,6 +10164,11 @@ exports[`regression tests > key p selects freedraw tool > [end of test] undo sta "backgroundColor": "transparent", "boundElements": null, "customData": undefined, + "drawingConfigs": { + "pressureSensitivity": 1, + "simplify": "0.25000", + "streamline": "0.25000", + }, "fillStyle": "solid", "frameId": null, "groupIds": [], @@ -10183,7 +10196,6 @@ exports[`regression tests > key p selects freedraw tool > [end of test] undo sta 10, ], ], - "pressureSensitivity": 1, "pressures": [], "roughness": 1, "roundness": null, diff --git a/packages/excalidraw/tests/data/__snapshots__/restore.test.ts.snap b/packages/excalidraw/tests/data/__snapshots__/restore.test.ts.snap index cc9e0b987d..c389dc629e 100644 --- a/packages/excalidraw/tests/data/__snapshots__/restore.test.ts.snap +++ b/packages/excalidraw/tests/data/__snapshots__/restore.test.ts.snap @@ -170,6 +170,11 @@ exports[`restoreElements > should restore freedraw element correctly 1`] = ` "backgroundColor": "transparent", "boundElements": [], "customData": undefined, + "drawingConfigs": { + "pressureSensitivity": 1, + "simplify": "0.10000", + "streamline": "0.25000", + }, "fillStyle": "solid", "frameId": null, "groupIds": [], @@ -191,7 +196,6 @@ exports[`restoreElements > should restore freedraw element correctly 1`] = ` 10, ], ], - "pressureSensitivity": 1, "pressures": [], "roughness": 1, "roundness": {