feat: improved freedraw (#3512)
Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
@ -3,6 +3,7 @@ import {
|
||||
ExcalidrawGenericElement,
|
||||
ExcalidrawTextElement,
|
||||
ExcalidrawLinearElement,
|
||||
ExcalidrawFreeDrawElement,
|
||||
} from "../../element/types";
|
||||
import { newElement, newTextElement, newLinearElement } from "../../element";
|
||||
import { DEFAULT_VERTICAL_ALIGN } from "../../constants";
|
||||
@ -12,6 +13,7 @@ import fs from "fs";
|
||||
import util from "util";
|
||||
import path from "path";
|
||||
import { getMimeType } from "../../data/blob";
|
||||
import { newFreeDrawElement } from "../../element/newElement";
|
||||
|
||||
const readFile = util.promisify(fs.readFile);
|
||||
|
||||
@ -81,8 +83,10 @@ export class API {
|
||||
verticalAlign?: T extends "text"
|
||||
? ExcalidrawTextElement["verticalAlign"]
|
||||
: never;
|
||||
}): T extends "arrow" | "line" | "draw"
|
||||
}): T extends "arrow" | "line"
|
||||
? ExcalidrawLinearElement
|
||||
: T extends "freedraw"
|
||||
? ExcalidrawFreeDrawElement
|
||||
: T extends "text"
|
||||
? ExcalidrawTextElement
|
||||
: ExcalidrawGenericElement => {
|
||||
@ -125,11 +129,17 @@ export class API {
|
||||
verticalAlign: rest.verticalAlign ?? DEFAULT_VERTICAL_ALIGN,
|
||||
});
|
||||
break;
|
||||
case "freedraw":
|
||||
element = newFreeDrawElement({
|
||||
type: type as "freedraw",
|
||||
simulatePressure: true,
|
||||
...base,
|
||||
});
|
||||
break;
|
||||
case "arrow":
|
||||
case "line":
|
||||
case "draw":
|
||||
element = newLinearElement({
|
||||
type: type as "arrow" | "line" | "draw",
|
||||
type: type as "arrow" | "line",
|
||||
startArrowhead: null,
|
||||
endArrowhead: null,
|
||||
...base,
|
||||
|
@ -213,14 +213,14 @@ export class UI {
|
||||
height?: number;
|
||||
angle?: number;
|
||||
} = {},
|
||||
): (T extends "arrow" | "line" | "draw"
|
||||
): (T extends "arrow" | "line" | "freedraw"
|
||||
? ExcalidrawLinearElement
|
||||
: T extends "text"
|
||||
? ExcalidrawTextElement
|
||||
: ExcalidrawElement) & {
|
||||
/** Returns the actual, current element from the elements array, instead
|
||||
of the proxy */
|
||||
get(): T extends "arrow" | "line" | "draw"
|
||||
get(): T extends "arrow" | "line" | "freedraw"
|
||||
? ExcalidrawLinearElement
|
||||
: T extends "text"
|
||||
? ExcalidrawTextElement
|
||||
|
Reference in New Issue
Block a user