mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-12 20:10:09 +02:00
rename drawingConfigs
to freedrawOptions
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { DRAWING_CONFIGS, isFreeDrawElement } from "@excalidraw/element";
|
import { STROKE_OPTIONS, isFreeDrawElement } from "@excalidraw/element";
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
|
|
||||||
import { useUIAppState } from "@excalidraw/excalidraw/context/ui-appState";
|
import { useUIAppState } from "@excalidraw/excalidraw/context/ui-appState";
|
||||||
@@ -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.streamline,
|
STROKE_OPTIONS.default.streamline,
|
||||||
);
|
);
|
||||||
const [simplify, setSimplify] = useState<number>(
|
const [simplify, setSimplify] = useState<number>(
|
||||||
DRAWING_CONFIGS.default.simplify,
|
STROKE_OPTIONS.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,
|
...STROKE_OPTIONS.default,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,7 +8,7 @@ import type { StrokeOptions } from "perfect-freehand";
|
|||||||
|
|
||||||
import type { ExcalidrawFreeDrawElement, PointerType } from "./types";
|
import type { ExcalidrawFreeDrawElement, PointerType } from "./types";
|
||||||
|
|
||||||
export const DRAWING_CONFIGS: Record<
|
export const STROKE_OPTIONS: Record<
|
||||||
PointerType | "default",
|
PointerType | "default",
|
||||||
{ streamline: number; simplify: number }
|
{ streamline: number; simplify: number }
|
||||||
> = {
|
> = {
|
||||||
@@ -33,8 +33,8 @@ export const DRAWING_CONFIGS: Record<
|
|||||||
|
|
||||||
export const getFreedrawConfig = (eventType: string | null | undefined) => {
|
export const getFreedrawConfig = (eventType: string | null | undefined) => {
|
||||||
return (
|
return (
|
||||||
DRAWING_CONFIGS[(eventType as PointerType | null) || "default"] ||
|
STROKE_OPTIONS[(eventType as PointerType | null) || "default"] ||
|
||||||
DRAWING_CONFIGS.default
|
STROKE_OPTIONS.default
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ const calculateVelocityBasedPressure = (
|
|||||||
export const getFreedrawStroke = (element: ExcalidrawFreeDrawElement) => {
|
export const getFreedrawStroke = (element: ExcalidrawFreeDrawElement) => {
|
||||||
// Compose points as [x, y, pressure]
|
// Compose points as [x, y, pressure]
|
||||||
let points: [number, number, number][];
|
let points: [number, number, number][];
|
||||||
if (element.drawingConfigs?.fixedStrokeWidth) {
|
if (element.freedrawOptions?.fixedStrokeWidth) {
|
||||||
points = element.points.map(
|
points = element.points.map(
|
||||||
([x, y]: LocalPoint): [number, number, number] => [x, y, 1],
|
([x, y]: LocalPoint): [number, number, number] => [x, y, 1],
|
||||||
);
|
);
|
||||||
@@ -90,7 +90,7 @@ export const getFreedrawStroke = (element: ExcalidrawFreeDrawElement) => {
|
|||||||
calculateVelocityBasedPressure(
|
calculateVelocityBasedPressure(
|
||||||
element.points,
|
element.points,
|
||||||
i,
|
i,
|
||||||
element.drawingConfigs?.fixedStrokeWidth,
|
element.freedrawOptions?.fixedStrokeWidth,
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
@@ -105,16 +105,16 @@ export const getFreedrawStroke = (element: ExcalidrawFreeDrawElement) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const streamline =
|
const streamline =
|
||||||
element.drawingConfigs?.streamline ?? DRAWING_CONFIGS.default.streamline;
|
element.freedrawOptions?.streamline ?? STROKE_OPTIONS.default.streamline;
|
||||||
const simplify =
|
const simplify =
|
||||||
element.drawingConfigs?.simplify ?? DRAWING_CONFIGS.default.simplify;
|
element.freedrawOptions?.simplify ?? STROKE_OPTIONS.default.simplify;
|
||||||
|
|
||||||
const laser = new LaserPointer({
|
const laser = new LaserPointer({
|
||||||
size: element.strokeWidth,
|
size: element.strokeWidth,
|
||||||
streamline,
|
streamline,
|
||||||
simplify,
|
simplify,
|
||||||
sizeMapping: ({ pressure: t }) => {
|
sizeMapping: ({ pressure: t }) => {
|
||||||
if (element.drawingConfigs?.fixedStrokeWidth) {
|
if (element.freedrawOptions?.fixedStrokeWidth) {
|
||||||
return 0.6;
|
return 0.6;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ export const getFreeDrawSvgPath = (
|
|||||||
element: ExcalidrawFreeDrawElement,
|
element: ExcalidrawFreeDrawElement,
|
||||||
): string => {
|
): string => {
|
||||||
// legacy, for backwards compatibility
|
// legacy, for backwards compatibility
|
||||||
if (element.drawingConfigs === null) {
|
if (element.freedrawOptions === null) {
|
||||||
return _legacy_getFreeDrawSvgPath(element);
|
return _legacy_getFreeDrawSvgPath(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -445,7 +445,7 @@ export const newFreeDrawElement = (
|
|||||||
points?: ExcalidrawFreeDrawElement["points"];
|
points?: ExcalidrawFreeDrawElement["points"];
|
||||||
simulatePressure: boolean;
|
simulatePressure: boolean;
|
||||||
pressures?: ExcalidrawFreeDrawElement["pressures"];
|
pressures?: ExcalidrawFreeDrawElement["pressures"];
|
||||||
drawingConfigs?: ExcalidrawFreeDrawElement["drawingConfigs"];
|
strokeOptions?: ExcalidrawFreeDrawElement["freedrawOptions"];
|
||||||
} & ElementConstructorOpts,
|
} & ElementConstructorOpts,
|
||||||
): NonDeleted<ExcalidrawFreeDrawElement> => {
|
): NonDeleted<ExcalidrawFreeDrawElement> => {
|
||||||
return {
|
return {
|
||||||
@@ -454,7 +454,7 @@ export const newFreeDrawElement = (
|
|||||||
pressures: opts.pressures || [],
|
pressures: opts.pressures || [],
|
||||||
simulatePressure: opts.simulatePressure,
|
simulatePressure: opts.simulatePressure,
|
||||||
lastCommittedPoint: null,
|
lastCommittedPoint: null,
|
||||||
drawingConfigs: opts.drawingConfigs || {
|
freedrawOptions: opts.strokeOptions || {
|
||||||
fixedStrokeWidth: true,
|
fixedStrokeWidth: true,
|
||||||
streamline: 0.25,
|
streamline: 0.25,
|
||||||
simplify: 0.1,
|
simplify: 0.1,
|
||||||
|
@@ -808,12 +808,12 @@ const generateElementShape = (
|
|||||||
|
|
||||||
if (isPathALoop(element.points)) {
|
if (isPathALoop(element.points)) {
|
||||||
const points =
|
const points =
|
||||||
element.drawingConfigs === null
|
element.freedrawOptions === null
|
||||||
? simplify(element.points as LocalPoint[], 0.75)
|
? simplify(element.points as LocalPoint[], 0.75)
|
||||||
: simplify(element.points as LocalPoint[], 1.5);
|
: simplify(element.points as LocalPoint[], 1.5);
|
||||||
|
|
||||||
shape =
|
shape =
|
||||||
element.drawingConfigs === null
|
element.freedrawOptions === null
|
||||||
? generator.curve(points, {
|
? generator.curve(points, {
|
||||||
...generateRoughOptions(element),
|
...generateRoughOptions(element),
|
||||||
stroke: "none",
|
stroke: "none",
|
||||||
|
@@ -380,7 +380,7 @@ export type ExcalidrawFreeDrawElement = _ExcalidrawElementBase &
|
|||||||
pressures: readonly number[];
|
pressures: readonly number[];
|
||||||
simulatePressure: boolean;
|
simulatePressure: boolean;
|
||||||
lastCommittedPoint: LocalPoint | null;
|
lastCommittedPoint: LocalPoint | null;
|
||||||
drawingConfigs: {
|
freedrawOptions: {
|
||||||
streamline?: number;
|
streamline?: number;
|
||||||
simplify?: number;
|
simplify?: number;
|
||||||
fixedStrokeWidth?: boolean;
|
fixedStrokeWidth?: boolean;
|
||||||
|
@@ -686,8 +686,8 @@ export const actionChangePressureSensitivity = register({
|
|||||||
const updatedElements = changeProperty(elements, appState, (el) => {
|
const updatedElements = changeProperty(elements, appState, (el) => {
|
||||||
if (isFreeDrawElement(el)) {
|
if (isFreeDrawElement(el)) {
|
||||||
return newElementWith(el, {
|
return newElementWith(el, {
|
||||||
drawingConfigs: {
|
freedrawOptions: {
|
||||||
...el.drawingConfigs,
|
...el.freedrawOptions,
|
||||||
fixedStrokeWidth: value,
|
fixedStrokeWidth: value,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -709,7 +709,7 @@ export const actionChangePressureSensitivity = register({
|
|||||||
freedraws.length > 0
|
freedraws.length > 0
|
||||||
? reduceToCommonValue(
|
? reduceToCommonValue(
|
||||||
freedraws,
|
freedraws,
|
||||||
(element) => element.drawingConfigs?.fixedStrokeWidth,
|
(element) => element.freedrawOptions?.fixedStrokeWidth,
|
||||||
) ?? null
|
) ?? null
|
||||||
: appState.currentItemFixedStrokeWidth;
|
: appState.currentItemFixedStrokeWidth;
|
||||||
|
|
||||||
|
@@ -232,7 +232,7 @@ import {
|
|||||||
hitElementBoundingBox,
|
hitElementBoundingBox,
|
||||||
isLineElement,
|
isLineElement,
|
||||||
isSimpleArrow,
|
isSimpleArrow,
|
||||||
DRAWING_CONFIGS,
|
STROKE_OPTIONS,
|
||||||
getFreedrawConfig,
|
getFreedrawConfig,
|
||||||
} from "@excalidraw/element";
|
} from "@excalidraw/element";
|
||||||
|
|
||||||
@@ -7494,7 +7494,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
opacity: this.state.currentItemOpacity,
|
opacity: this.state.currentItemOpacity,
|
||||||
roundness: null,
|
roundness: null,
|
||||||
simulatePressure,
|
simulatePressure,
|
||||||
drawingConfigs: {
|
strokeOptions: {
|
||||||
fixedStrokeWidth: this.state.currentItemFixedStrokeWidth,
|
fixedStrokeWidth: this.state.currentItemFixedStrokeWidth,
|
||||||
streamline:
|
streamline:
|
||||||
(window.h?.debugFreedraw?.enabled
|
(window.h?.debugFreedraw?.enabled
|
||||||
@@ -11171,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),
|
...(window.h.debugFreedraw || STROKE_OPTIONS.default),
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.defineProperties(window.h, {
|
Object.defineProperties(window.h, {
|
||||||
|
@@ -303,7 +303,7 @@ const restoreElement = (
|
|||||||
simulatePressure: element.simulatePressure,
|
simulatePressure: element.simulatePressure,
|
||||||
pressures: element.pressures,
|
pressures: element.pressures,
|
||||||
// legacy, for backwards compatibility
|
// legacy, for backwards compatibility
|
||||||
drawingConfigs: element.drawingConfigs ?? null,
|
freedrawOptions: element.freedrawOptions ?? null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
case "image":
|
case "image":
|
||||||
|
Reference in New Issue
Block a user