remove debug and provide value for stylus

This commit is contained in:
Ryan Di
2025-06-16 17:19:55 +10:00
parent 37b75263f8
commit c72c47f0cd
7 changed files with 53 additions and 112 deletions

View File

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

View File

@ -1,89 +0,0 @@
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,
background: "rgba(255, 255, 255, 0.9)",
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

@ -11,6 +11,11 @@ import type { ExcalidrawFreeDrawElement } from "./types";
export const DRAWING_CONFIGS = { export const DRAWING_CONFIGS = {
default: { default: {
streamline: 0.25, streamline: 0.25,
simplify: 0.25,
},
// for optimal performance, we use a lower streamline and simplify
stylus: {
streamline: 0.1,
simplify: 0.1, simplify: 0.1,
}, },
} as const; } as const;

View File

@ -7594,11 +7594,9 @@ class App extends React.Component<AppProps, AppState> {
simulatePressure, simulatePressure,
drawingConfigs: { drawingConfigs: {
pressureSensitivity: this.state.currentItemPressureSensitivity, pressureSensitivity: this.state.currentItemPressureSensitivity,
streamline: ...(event.pointerType === "pen"
window.h?.debugFreedraw?.streamline ?? ? DRAWING_CONFIGS.stylus
DRAWING_CONFIGS.default.streamline, : DRAWING_CONFIGS.default),
simplify:
window.h?.debugFreedraw?.simplify ?? DRAWING_CONFIGS.default.simplify,
}, },
locked: false, locked: false,
frameId: topLayerFrame ? topLayerFrame.id : null, frameId: topLayerFrame ? topLayerFrame.id : null,
@ -11382,10 +11380,6 @@ declare global {
app: InstanceType<typeof App>; app: InstanceType<typeof App>;
history: History; history: History;
store: Store; store: Store;
debugFreedraw?: {
streamline: number;
simplify: number;
};
}; };
} }
} }
@ -11394,9 +11388,6 @@ export const createTestHook = () => {
if (isTestEnv() || isDevEnv()) { if (isTestEnv() || isDevEnv()) {
window.h = window.h || ({} as Window["h"]); window.h = window.h || ({} as Window["h"]);
// Initialize debug freedraw parameters
window.h.debugFreedraw = window.h.debugFreedraw || DRAWING_CONFIGS.default;
Object.defineProperties(window.h, { Object.defineProperties(window.h, {
elements: { elements: {
configurable: true, configurable: true,

View File

@ -8910,6 +8910,11 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte
"backgroundColor": "transparent", "backgroundColor": "transparent",
"boundElements": null, "boundElements": null,
"customData": undefined, "customData": undefined,
"drawingConfigs": {
"pressureSensitivity": 1,
"simplify": "0.25000",
"streamline": "0.25000",
},
"fillStyle": "solid", "fillStyle": "solid",
"frameId": null, "frameId": null,
"groupIds": [], "groupIds": [],
@ -8942,7 +8947,6 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte
50, 50,
], ],
], ],
"pressureSensitivity": 1,
"pressures": [], "pressures": [],
"roughness": 1, "roughness": 1,
"roundness": null, "roundness": null,
@ -9015,6 +9019,11 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte
"backgroundColor": "transparent", "backgroundColor": "transparent",
"boundElements": null, "boundElements": null,
"customData": undefined, "customData": undefined,
"drawingConfigs": {
"pressureSensitivity": 1,
"simplify": "0.25000",
"streamline": "0.25000",
},
"fillStyle": "solid", "fillStyle": "solid",
"frameId": null, "frameId": null,
"groupIds": [], "groupIds": [],
@ -9046,7 +9055,6 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte
50, 50,
], ],
], ],
"pressureSensitivity": 1,
"pressures": [], "pressures": [],
"roughness": 1, "roughness": 1,
"roundness": null, "roundness": null,
@ -12064,6 +12072,11 @@ exports[`history > singleplayer undo/redo > should create entry when selecting f
"backgroundColor": "transparent", "backgroundColor": "transparent",
"boundElements": null, "boundElements": null,
"customData": undefined, "customData": undefined,
"drawingConfigs": {
"pressureSensitivity": 1,
"simplify": "0.25000",
"streamline": "0.25000",
},
"fillStyle": "solid", "fillStyle": "solid",
"frameId": null, "frameId": null,
"groupIds": [], "groupIds": [],
@ -12092,7 +12105,6 @@ exports[`history > singleplayer undo/redo > should create entry when selecting f
10, 10,
], ],
], ],
"pressureSensitivity": 1,
"pressures": [], "pressures": [],
"roughness": 1, "roughness": 1,
"roundness": null, "roundness": null,
@ -12115,6 +12127,11 @@ exports[`history > singleplayer undo/redo > should create entry when selecting f
"backgroundColor": "transparent", "backgroundColor": "transparent",
"boundElements": null, "boundElements": null,
"customData": undefined, "customData": undefined,
"drawingConfigs": {
"pressureSensitivity": 1,
"simplify": "0.25000",
"streamline": "0.25000",
},
"fillStyle": "solid", "fillStyle": "solid",
"frameId": null, "frameId": null,
"groupIds": [], "groupIds": [],
@ -12143,7 +12160,6 @@ exports[`history > singleplayer undo/redo > should create entry when selecting f
10, 10,
], ],
], ],
"pressureSensitivity": 1,
"pressures": [], "pressures": [],
"roughness": 1, "roughness": 1,
"roundness": null, "roundness": null,
@ -12256,6 +12272,11 @@ exports[`history > singleplayer undo/redo > should create entry when selecting f
"backgroundColor": "transparent", "backgroundColor": "transparent",
"boundElements": null, "boundElements": null,
"customData": undefined, "customData": undefined,
"drawingConfigs": {
"pressureSensitivity": 1,
"simplify": "0.25000",
"streamline": "0.25000",
},
"fillStyle": "solid", "fillStyle": "solid",
"frameId": null, "frameId": null,
"groupIds": [], "groupIds": [],
@ -12283,7 +12304,6 @@ exports[`history > singleplayer undo/redo > should create entry when selecting f
10, 10,
], ],
], ],
"pressureSensitivity": 1,
"pressures": [], "pressures": [],
"roughness": 1, "roughness": 1,
"roundness": null, "roundness": null,

View File

@ -6877,6 +6877,11 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack
"backgroundColor": "transparent", "backgroundColor": "transparent",
"boundElements": null, "boundElements": null,
"customData": undefined, "customData": undefined,
"drawingConfigs": {
"pressureSensitivity": 1,
"simplify": "0.25000",
"streamline": "0.25000",
},
"fillStyle": "solid", "fillStyle": "solid",
"frameId": null, "frameId": null,
"groupIds": [], "groupIds": [],
@ -6904,7 +6909,6 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack
10, 10,
], ],
], ],
"pressureSensitivity": 1,
"pressures": [], "pressures": [],
"roughness": 1, "roughness": 1,
"roundness": null, "roundness": null,
@ -9152,6 +9156,11 @@ exports[`regression tests > key 7 selects freedraw tool > [end of test] undo sta
"backgroundColor": "transparent", "backgroundColor": "transparent",
"boundElements": null, "boundElements": null,
"customData": undefined, "customData": undefined,
"drawingConfigs": {
"pressureSensitivity": 1,
"simplify": "0.25000",
"streamline": "0.25000",
},
"fillStyle": "solid", "fillStyle": "solid",
"frameId": null, "frameId": null,
"groupIds": [], "groupIds": [],
@ -9179,7 +9188,6 @@ exports[`regression tests > key 7 selects freedraw tool > [end of test] undo sta
10, 10,
], ],
], ],
"pressureSensitivity": 1,
"pressures": [], "pressures": [],
"roughness": 1, "roughness": 1,
"roundness": null, "roundness": null,
@ -10156,6 +10164,11 @@ exports[`regression tests > key p selects freedraw tool > [end of test] undo sta
"backgroundColor": "transparent", "backgroundColor": "transparent",
"boundElements": null, "boundElements": null,
"customData": undefined, "customData": undefined,
"drawingConfigs": {
"pressureSensitivity": 1,
"simplify": "0.25000",
"streamline": "0.25000",
},
"fillStyle": "solid", "fillStyle": "solid",
"frameId": null, "frameId": null,
"groupIds": [], "groupIds": [],
@ -10183,7 +10196,6 @@ exports[`regression tests > key p selects freedraw tool > [end of test] undo sta
10, 10,
], ],
], ],
"pressureSensitivity": 1,
"pressures": [], "pressures": [],
"roughness": 1, "roughness": 1,
"roundness": null, "roundness": null,

View File

@ -170,6 +170,11 @@ exports[`restoreElements > should restore freedraw element correctly 1`] = `
"backgroundColor": "transparent", "backgroundColor": "transparent",
"boundElements": [], "boundElements": [],
"customData": undefined, "customData": undefined,
"drawingConfigs": {
"pressureSensitivity": 1,
"simplify": "0.10000",
"streamline": "0.25000",
},
"fillStyle": "solid", "fillStyle": "solid",
"frameId": null, "frameId": null,
"groupIds": [], "groupIds": [],
@ -191,7 +196,6 @@ exports[`restoreElements > should restore freedraw element correctly 1`] = `
10, 10,
], ],
], ],
"pressureSensitivity": 1,
"pressures": [], "pressures": [],
"roughness": 1, "roughness": 1,
"roundness": { "roundness": {