mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Sync panel props to editing element (#470)
* ensure panel props are sync to editing elem * ensure we don't create empty-text elements (fixes #468) * remove dead code Co-authored-by: Christopher Chedeau <vjeuxx@gmail.com>
This commit is contained in:
parent
ff7a340d2f
commit
2340dddaad
7 changed files with 159 additions and 100 deletions
|
@ -2,6 +2,9 @@ import { randomSeed } from "roughjs/bin/math";
|
|||
import nanoid from "nanoid";
|
||||
import { Drawable } from "roughjs/bin/core";
|
||||
|
||||
import { ExcalidrawElement, ExcalidrawTextElement } from "../element/types";
|
||||
import { measureText } from "../utils";
|
||||
|
||||
export function newElement(
|
||||
type: string,
|
||||
x: number,
|
||||
|
@ -35,6 +38,28 @@ export function newElement(
|
|||
return element;
|
||||
}
|
||||
|
||||
export function newTextElement(
|
||||
element: ExcalidrawElement,
|
||||
text: string,
|
||||
font: string
|
||||
) {
|
||||
const metrics = measureText(text, font);
|
||||
const textElement: ExcalidrawTextElement = {
|
||||
...element,
|
||||
type: "text",
|
||||
text: text,
|
||||
font: font,
|
||||
// Center the text
|
||||
x: element.x - metrics.width / 2,
|
||||
y: element.y - metrics.height / 2,
|
||||
width: metrics.width,
|
||||
height: metrics.height,
|
||||
baseline: metrics.baseline
|
||||
};
|
||||
|
||||
return textElement;
|
||||
}
|
||||
|
||||
export function duplicateElement(element: ReturnType<typeof newElement>) {
|
||||
const copy = { ...element };
|
||||
delete copy.shape;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue