Revert "remove debug and provide value for stylus"

This reverts commit c72c47f0cd.

# Conflicts:
#	packages/element/src/freedraw.ts
#	packages/excalidraw/tests/__snapshots__/history.test.tsx.snap
#	packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap
This commit is contained in:
dwelle
2025-06-26 22:20:01 +02:00
parent b1f3cc50ee
commit 8ceb55dd02
4 changed files with 103 additions and 8 deletions

View File

@ -134,6 +134,7 @@ import DebugCanvas, {
} from "./components/DebugCanvas";
import { AIComponents } from "./components/AI";
import { ExcalidrawPlusIframeExport } from "./ExcalidrawPlusIframeExport";
import { FreedrawDebugSliders } from "./components/FreedrawDebugSliders";
import "./index.scss";
@ -1142,6 +1143,7 @@ const ExcalidrawWrapper = () => {
ref={debugCanvasRef}
/>
)}
<FreedrawDebugSliders />
</Excalidraw>
</div>
);

View File

@ -0,0 +1,88 @@
import { DRAWING_CONFIGS } from "@excalidraw/element";
import { useState, useEffect } from "react";
export const FreedrawDebugSliders = () => {
const [streamline, setStreamline] = useState<number>(
DRAWING_CONFIGS.default.streamline,
);
const [simplify, setSimplify] = useState<number>(
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 (
<div
style={{
position: "absolute",
bottom: "10px",
left: "50%",
transform: "translateX(-50%)",
zIndex: 9999,
padding: "10px",
borderRadius: "8px",
border: "1px solid #ccc",
display: "flex",
flexDirection: "column",
gap: "8px",
fontSize: "12px",
fontFamily: "monospace",
}}
>
<div>
<label>
Streamline: {streamline.toFixed(2)}
<br />
<input
type="range"
min="0"
max="1"
step="0.01"
value={streamline}
onChange={(e) => handleStreamlineChange(parseFloat(e.target.value))}
style={{ width: "150px" }}
/>
</label>
</div>
<div>
<label>
Simplify: {simplify.toFixed(2)}
<br />
<input
type="range"
min="0"
max="1"
step="0.01"
value={simplify}
onChange={(e) => handleSimplifyChange(parseFloat(e.target.value))}
style={{ width: "150px" }}
/>
</label>
</div>
</div>
);
};

View File

@ -7594,9 +7594,11 @@ class App extends React.Component<AppProps, AppState> {
simulatePressure,
drawingConfigs: {
pressureSensitivity: this.state.currentItemPressureSensitivity,
...(event.pointerType === "pen"
? DRAWING_CONFIGS.stylus
: DRAWING_CONFIGS.default),
streamline:
window.h?.debugFreedraw?.streamline ??
DRAWING_CONFIGS.default.streamline,
simplify:
window.h?.debugFreedraw?.simplify ?? DRAWING_CONFIGS.default.simplify,
},
locked: false,
frameId: topLayerFrame ? topLayerFrame.id : null,
@ -11380,6 +11382,10 @@ declare global {
app: InstanceType<typeof App>;
history: History;
store: Store;
debugFreedraw?: {
streamline: number;
simplify: number;
};
};
}
}
@ -11388,6 +11394,9 @@ 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,

View File

@ -170,11 +170,6 @@ 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": [],
@ -196,6 +191,7 @@ exports[`restoreElements > should restore freedraw element correctly 1`] = `
10,
],
],
"pressureSensitivity": 1,
"pressures": [],
"roughness": 1,
"roundness": {