Revert "differentiate between constant/variable stroke type"

This reverts commit 0199c82e98.
This commit is contained in:
dwelle
2025-07-08 23:44:54 +02:00
parent 34bff557e3
commit 446f871536
3 changed files with 21 additions and 62 deletions

View File

@ -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<FreedrawStrokeType, { streamline: number; simplify: number }>
{ 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,

View File

@ -7479,10 +7479,7 @@ class App extends React.Component<AppProps, AppState> {
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, {