|
@@ -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"] ||
|
|
|
|
- DRAWING_CONFIGS.default
|
|
|
|
|
|
+ STROKE_OPTIONS[(eventType as PointerType | null) || "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);
|
|
}
|
|
}
|
|
|
|
|