From 62e20aa2478cd4f9a49c641be550c0bbef808bea Mon Sep 17 00:00:00 2001 From: dwelle <5153846+dwelle@users.noreply.github.com> Date: Fri, 27 Jun 2025 14:48:59 +0200 Subject: [PATCH] improve debug --- .../components/FreedrawDebugSliders.tsx | 66 ++++++++++++++++++- packages/excalidraw/components/App.tsx | 22 +++++-- 2 files changed, 81 insertions(+), 7 deletions(-) diff --git a/excalidraw-app/components/FreedrawDebugSliders.tsx b/excalidraw-app/components/FreedrawDebugSliders.tsx index 2666a6f99a..b5a665265f 100644 --- a/excalidraw-app/components/FreedrawDebugSliders.tsx +++ b/excalidraw-app/components/FreedrawDebugSliders.tsx @@ -1,6 +1,11 @@ -import { DRAWING_CONFIGS } from "@excalidraw/element"; +import { DRAWING_CONFIGS, isFreeDrawElement } from "@excalidraw/element"; import { useState, useEffect } from "react"; +import { useUIAppState } from "@excalidraw/excalidraw/context/ui-appState"; +import { useExcalidrawElements } from "@excalidraw/excalidraw/components/App"; + +import { round } from "../../packages/math/src"; + export const FreedrawDebugSliders = () => { const [streamline, setStreamline] = useState( DRAWING_CONFIGS.default.variable.streamline, @@ -14,7 +19,10 @@ export const FreedrawDebugSliders = () => { window.h = {} as any; } if (!window.h.debugFreedraw) { - window.h.debugFreedraw = DRAWING_CONFIGS.default.variable; + window.h.debugFreedraw = { + enabled: true, + ...DRAWING_CONFIGS.default.variable, + }; } setStreamline(window.h.debugFreedraw.streamline); @@ -35,6 +43,29 @@ export const FreedrawDebugSliders = () => { } }; + const [enabled, setEnabled] = useState( + window.h?.debugFreedraw?.enabled ?? true, + ); + + // counter incrasing each 50ms + const [, setCounter] = useState(0); + useEffect(() => { + const interval = setInterval(() => { + setCounter((prev) => prev + 1); + }, 50); + + return () => clearInterval(interval); + }, []); + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const elements = useExcalidrawElements(); + const appState = useUIAppState(); + + const newFreedrawElement = + appState.newElement && isFreeDrawElement(appState.newElement) + ? appState.newElement + : null; + return (
{ fontFamily: "monospace", }} > + {newFreedrawElement && ( +
+ pressures:{" "} + {newFreedrawElement.simulatePressure + ? "simulated" + : JSON.stringify( + newFreedrawElement.pressures + .slice(-4) + .map((x) => round(x, 2)) + .join(" ") || [], + )}{" "} + ({round(window.__lastPressure__ || 0, 2) || "?"}) +
+ )} +
+ +