From d615c2cea1fe690ce7a6e7e047070a4a19c2425b Mon Sep 17 00:00:00 2001 From: dwelle <5153846+dwelle@users.noreply.github.com> Date: Mon, 14 Jul 2025 13:15:31 +0200 Subject: [PATCH] rename `drawingConfigs` to `freedrawOptions` --- .../components/FreedrawDebugSliders.tsx | 8 ++++---- packages/element/src/freedraw.ts | 18 +++++++++--------- packages/element/src/newElement.ts | 4 ++-- packages/element/src/shape.ts | 4 ++-- packages/element/src/types.ts | 2 +- .../excalidraw/actions/actionProperties.tsx | 6 +++--- packages/excalidraw/components/App.tsx | 6 +++--- packages/excalidraw/data/restore.ts | 2 +- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/excalidraw-app/components/FreedrawDebugSliders.tsx b/excalidraw-app/components/FreedrawDebugSliders.tsx index 6a6989777c..62ecf76911 100644 --- a/excalidraw-app/components/FreedrawDebugSliders.tsx +++ b/excalidraw-app/components/FreedrawDebugSliders.tsx @@ -1,4 +1,4 @@ -import { DRAWING_CONFIGS, isFreeDrawElement } from "@excalidraw/element"; +import { STROKE_OPTIONS, isFreeDrawElement } from "@excalidraw/element"; import { useState, useEffect } from "react"; import { useUIAppState } from "@excalidraw/excalidraw/context/ui-appState"; @@ -8,10 +8,10 @@ import { round } from "../../packages/math/src"; export const FreedrawDebugSliders = () => { const [streamline, setStreamline] = useState( - DRAWING_CONFIGS.default.streamline, + STROKE_OPTIONS.default.streamline, ); const [simplify, setSimplify] = useState( - DRAWING_CONFIGS.default.simplify, + STROKE_OPTIONS.default.simplify, ); useEffect(() => { @@ -21,7 +21,7 @@ export const FreedrawDebugSliders = () => { if (!window.h.debugFreedraw) { window.h.debugFreedraw = { enabled: true, - ...DRAWING_CONFIGS.default, + ...STROKE_OPTIONS.default, }; } diff --git a/packages/element/src/freedraw.ts b/packages/element/src/freedraw.ts index ec6b1c9fa8..cb76d10948 100644 --- a/packages/element/src/freedraw.ts +++ b/packages/element/src/freedraw.ts @@ -8,7 +8,7 @@ import type { StrokeOptions } from "perfect-freehand"; import type { ExcalidrawFreeDrawElement, PointerType } from "./types"; -export const DRAWING_CONFIGS: Record< +export const STROKE_OPTIONS: Record< PointerType | "default", { streamline: number; simplify: number } > = { @@ -33,8 +33,8 @@ export const DRAWING_CONFIGS: Record< export const getFreedrawConfig = (eventType: string | null | undefined) => { return ( - DRAWING_CONFIGS[(eventType as PointerType | null) || "default"] || - DRAWING_CONFIGS.default + STROKE_OPTIONS[(eventType as PointerType | null) || "default"] || + STROKE_OPTIONS.default ); }; @@ -78,7 +78,7 @@ const calculateVelocityBasedPressure = ( export const getFreedrawStroke = (element: ExcalidrawFreeDrawElement) => { // Compose points as [x, y, pressure] let points: [number, number, number][]; - if (element.drawingConfigs?.fixedStrokeWidth) { + if (element.freedrawOptions?.fixedStrokeWidth) { points = element.points.map( ([x, y]: LocalPoint): [number, number, number] => [x, y, 1], ); @@ -90,7 +90,7 @@ export const getFreedrawStroke = (element: ExcalidrawFreeDrawElement) => { calculateVelocityBasedPressure( element.points, i, - element.drawingConfigs?.fixedStrokeWidth, + element.freedrawOptions?.fixedStrokeWidth, ), ]); } else { @@ -105,16 +105,16 @@ export const getFreedrawStroke = (element: ExcalidrawFreeDrawElement) => { } const streamline = - element.drawingConfigs?.streamline ?? DRAWING_CONFIGS.default.streamline; + element.freedrawOptions?.streamline ?? STROKE_OPTIONS.default.streamline; const simplify = - element.drawingConfigs?.simplify ?? DRAWING_CONFIGS.default.simplify; + element.freedrawOptions?.simplify ?? STROKE_OPTIONS.default.simplify; const laser = new LaserPointer({ size: element.strokeWidth, streamline, simplify, sizeMapping: ({ pressure: t }) => { - if (element.drawingConfigs?.fixedStrokeWidth) { + if (element.freedrawOptions?.fixedStrokeWidth) { return 0.6; } @@ -143,7 +143,7 @@ export const getFreeDrawSvgPath = ( element: ExcalidrawFreeDrawElement, ): string => { // legacy, for backwards compatibility - if (element.drawingConfigs === null) { + if (element.freedrawOptions === null) { return _legacy_getFreeDrawSvgPath(element); } diff --git a/packages/element/src/newElement.ts b/packages/element/src/newElement.ts index cb0601ee05..47abf32c6a 100644 --- a/packages/element/src/newElement.ts +++ b/packages/element/src/newElement.ts @@ -445,7 +445,7 @@ export const newFreeDrawElement = ( points?: ExcalidrawFreeDrawElement["points"]; simulatePressure: boolean; pressures?: ExcalidrawFreeDrawElement["pressures"]; - drawingConfigs?: ExcalidrawFreeDrawElement["drawingConfigs"]; + strokeOptions?: ExcalidrawFreeDrawElement["freedrawOptions"]; } & ElementConstructorOpts, ): NonDeleted => { return { @@ -454,7 +454,7 @@ export const newFreeDrawElement = ( pressures: opts.pressures || [], simulatePressure: opts.simulatePressure, lastCommittedPoint: null, - drawingConfigs: opts.drawingConfigs || { + freedrawOptions: opts.strokeOptions || { fixedStrokeWidth: true, streamline: 0.25, simplify: 0.1, diff --git a/packages/element/src/shape.ts b/packages/element/src/shape.ts index 0839465a6d..a4cf69da76 100644 --- a/packages/element/src/shape.ts +++ b/packages/element/src/shape.ts @@ -808,12 +808,12 @@ const generateElementShape = ( if (isPathALoop(element.points)) { const points = - element.drawingConfigs === null + element.freedrawOptions === null ? simplify(element.points as LocalPoint[], 0.75) : simplify(element.points as LocalPoint[], 1.5); shape = - element.drawingConfigs === null + element.freedrawOptions === null ? generator.curve(points, { ...generateRoughOptions(element), stroke: "none", diff --git a/packages/element/src/types.ts b/packages/element/src/types.ts index b9717f29de..f1308b1fb2 100644 --- a/packages/element/src/types.ts +++ b/packages/element/src/types.ts @@ -380,7 +380,7 @@ export type ExcalidrawFreeDrawElement = _ExcalidrawElementBase & pressures: readonly number[]; simulatePressure: boolean; lastCommittedPoint: LocalPoint | null; - drawingConfigs: { + freedrawOptions: { streamline?: number; simplify?: number; fixedStrokeWidth?: boolean; diff --git a/packages/excalidraw/actions/actionProperties.tsx b/packages/excalidraw/actions/actionProperties.tsx index 63056e304d..bb1d71dbc8 100644 --- a/packages/excalidraw/actions/actionProperties.tsx +++ b/packages/excalidraw/actions/actionProperties.tsx @@ -686,8 +686,8 @@ export const actionChangePressureSensitivity = register({ const updatedElements = changeProperty(elements, appState, (el) => { if (isFreeDrawElement(el)) { return newElementWith(el, { - drawingConfigs: { - ...el.drawingConfigs, + freedrawOptions: { + ...el.freedrawOptions, fixedStrokeWidth: value, }, }); @@ -709,7 +709,7 @@ export const actionChangePressureSensitivity = register({ freedraws.length > 0 ? reduceToCommonValue( freedraws, - (element) => element.drawingConfigs?.fixedStrokeWidth, + (element) => element.freedrawOptions?.fixedStrokeWidth, ) ?? null : appState.currentItemFixedStrokeWidth; diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx index c35195d684..d57ddb936b 100644 --- a/packages/excalidraw/components/App.tsx +++ b/packages/excalidraw/components/App.tsx @@ -232,7 +232,7 @@ import { hitElementBoundingBox, isLineElement, isSimpleArrow, - DRAWING_CONFIGS, + STROKE_OPTIONS, getFreedrawConfig, } from "@excalidraw/element"; @@ -7494,7 +7494,7 @@ class App extends React.Component { opacity: this.state.currentItemOpacity, roundness: null, simulatePressure, - drawingConfigs: { + strokeOptions: { fixedStrokeWidth: this.state.currentItemFixedStrokeWidth, streamline: (window.h?.debugFreedraw?.enabled @@ -11171,7 +11171,7 @@ export const createTestHook = () => { // Initialize debug freedraw parameters window.h.debugFreedraw = { enabled: true, - ...(window.h.debugFreedraw || DRAWING_CONFIGS.default), + ...(window.h.debugFreedraw || STROKE_OPTIONS.default), }; Object.defineProperties(window.h, { diff --git a/packages/excalidraw/data/restore.ts b/packages/excalidraw/data/restore.ts index 9433745b9d..946365bba4 100644 --- a/packages/excalidraw/data/restore.ts +++ b/packages/excalidraw/data/restore.ts @@ -303,7 +303,7 @@ const restoreElement = ( simulatePressure: element.simulatePressure, pressures: element.pressures, // legacy, for backwards compatibility - drawingConfigs: element.drawingConfigs ?? null, + freedrawOptions: element.freedrawOptions ?? null, }); } case "image":