mirror of
https://github.com/excalidraw/excalidraw
synced 2025-07-25 13:58:22 +08:00
Revert "differentiate between constant/variable stroke type"
This reverts commit 0199c82e98
.
This commit is contained in:
@ -8,10 +8,10 @@ import { round } from "../../packages/math/src";
|
|||||||
|
|
||||||
export const FreedrawDebugSliders = () => {
|
export const FreedrawDebugSliders = () => {
|
||||||
const [streamline, setStreamline] = useState<number>(
|
const [streamline, setStreamline] = useState<number>(
|
||||||
DRAWING_CONFIGS.default.variable.streamline,
|
DRAWING_CONFIGS.default.streamline,
|
||||||
);
|
);
|
||||||
const [simplify, setSimplify] = useState<number>(
|
const [simplify, setSimplify] = useState<number>(
|
||||||
DRAWING_CONFIGS.default.variable.simplify,
|
DRAWING_CONFIGS.default.simplify,
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -21,7 +21,7 @@ export const FreedrawDebugSliders = () => {
|
|||||||
if (!window.h.debugFreedraw) {
|
if (!window.h.debugFreedraw) {
|
||||||
window.h.debugFreedraw = {
|
window.h.debugFreedraw = {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
...DRAWING_CONFIGS.default.variable,
|
...DRAWING_CONFIGS.default,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,70 +8,34 @@ import type { StrokeOptions } from "perfect-freehand";
|
|||||||
|
|
||||||
import type { ExcalidrawFreeDrawElement, PointerType } from "./types";
|
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<
|
export const DRAWING_CONFIGS: Record<
|
||||||
PointerType | "default",
|
PointerType | "default",
|
||||||
Record<FreedrawStrokeType, { streamline: number; simplify: number }>
|
{ streamline: number; simplify: number }
|
||||||
> = {
|
> = {
|
||||||
default: {
|
default: {
|
||||||
constant: {
|
streamline: 0.35,
|
||||||
streamline: 0.35,
|
simplify: 0.1,
|
||||||
simplify: 0.1,
|
|
||||||
},
|
|
||||||
variable: {
|
|
||||||
streamline: 0.35,
|
|
||||||
simplify: 0.1,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
mouse: {
|
mouse: {
|
||||||
constant: {
|
streamline: 0.6,
|
||||||
streamline: 0.6,
|
simplify: 0.1,
|
||||||
simplify: 0.1,
|
|
||||||
},
|
|
||||||
variable: {
|
|
||||||
streamline: 0.6,
|
|
||||||
simplify: 0.1,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
pen: {
|
pen: {
|
||||||
constant: {
|
// for optimal performance, we use a lower streamline and simplify
|
||||||
// for optimal performance, we use a lower streamline and simplify
|
streamline: 0.2,
|
||||||
streamline: 0.2,
|
simplify: 0.1,
|
||||||
simplify: 0.1,
|
|
||||||
},
|
|
||||||
variable: {
|
|
||||||
// for optimal performance, we use a lower streamline and simplify
|
|
||||||
streamline: 0.2,
|
|
||||||
simplify: 0.1,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
touch: {
|
touch: {
|
||||||
constant: {
|
streamline: 0.65,
|
||||||
streamline: 0.65,
|
simplify: 0.1,
|
||||||
simplify: 0.1,
|
|
||||||
},
|
|
||||||
variable: {
|
|
||||||
streamline: 0.65,
|
|
||||||
simplify: 0.1,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const getFreedrawConfig = (
|
export const getFreedrawConfig = (eventType: string | null | undefined) => {
|
||||||
eventType: string | null | undefined,
|
return (
|
||||||
strokeType: FreedrawStrokeType,
|
|
||||||
): { streamline: number; simplify: number } => {
|
|
||||||
const inputConfig =
|
|
||||||
DRAWING_CONFIGS[(eventType as PointerType | null) || "default"] ||
|
DRAWING_CONFIGS[(eventType as PointerType | null) || "default"] ||
|
||||||
DRAWING_CONFIGS.default;
|
DRAWING_CONFIGS.default
|
||||||
return inputConfig[strokeType];
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -141,11 +105,9 @@ export const getFreedrawStroke = (element: ExcalidrawFreeDrawElement) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const streamline =
|
const streamline =
|
||||||
element.drawingConfigs?.streamline ??
|
element.drawingConfigs?.streamline ?? DRAWING_CONFIGS.default.streamline;
|
||||||
getFreedrawConfig("default", getElementStrokeType(element)).streamline;
|
|
||||||
const simplify =
|
const simplify =
|
||||||
element.drawingConfigs?.simplify ??
|
element.drawingConfigs?.simplify ?? DRAWING_CONFIGS.default.simplify;
|
||||||
getFreedrawConfig("default", getElementStrokeType(element)).simplify;
|
|
||||||
|
|
||||||
const laser = new LaserPointer({
|
const laser = new LaserPointer({
|
||||||
size: element.strokeWidth,
|
size: element.strokeWidth,
|
||||||
|
@ -7479,10 +7479,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
|
|
||||||
window.__lastPressure__ = event.pressure;
|
window.__lastPressure__ = event.pressure;
|
||||||
|
|
||||||
const freedrawConfig = getFreedrawConfig(
|
const freedrawConfig = getFreedrawConfig(event.pointerType);
|
||||||
event.pointerType,
|
|
||||||
this.state.currentItemFixedStrokeWidth ? "constant" : "variable",
|
|
||||||
);
|
|
||||||
|
|
||||||
const element = newFreeDrawElement({
|
const element = newFreeDrawElement({
|
||||||
type: elementType,
|
type: elementType,
|
||||||
@ -11174,7 +11171,7 @@ export const createTestHook = () => {
|
|||||||
// Initialize debug freedraw parameters
|
// Initialize debug freedraw parameters
|
||||||
window.h.debugFreedraw = {
|
window.h.debugFreedraw = {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
...(window.h.debugFreedraw || DRAWING_CONFIGS.default.variable),
|
...(window.h.debugFreedraw || DRAWING_CONFIGS.default),
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.defineProperties(window.h, {
|
Object.defineProperties(window.h, {
|
||||||
|
Reference in New Issue
Block a user