14a66956d7
* implement line editing * line editing with rotation * ensure adding new points is disabled on point dragging * fix hotkey replacement * don't paint bounding box when creating new multipoint * tweak points style, account for zoom and z-index * don't persist editingLinearElement to localStorage * don't mutate on noop points updates * account for rotation when adding new point * ensure clicking on points doesn't deselect element * tweak history handling around editingline element * update snapshots * refactor pointerMove handling * factor out point dragging * factor out pointerDown * improve positioning with rotation * revert to use roughjs for calculating points bounds * migrate from storing editingLinearElement.element to id * make GlobalScene.getElement into O(1) * use Alt for adding new points * fix adding and deleting a point with rotation * disable resize handlers & bounding box on line edit Co-authored-by: daishi <daishi@axlight.com>
78 lines
1.9 KiB
TypeScript
78 lines
1.9 KiB
TypeScript
import { Point } from "../types";
|
|
import { FONT_FAMILY } from "../constants";
|
|
|
|
export type GroupId = string;
|
|
|
|
type _ExcalidrawElementBase = Readonly<{
|
|
id: string;
|
|
x: number;
|
|
y: number;
|
|
strokeColor: string;
|
|
backgroundColor: string;
|
|
fillStyle: string;
|
|
strokeWidth: number;
|
|
strokeStyle: "solid" | "dashed" | "dotted";
|
|
roughness: number;
|
|
opacity: number;
|
|
width: number;
|
|
height: number;
|
|
angle: number;
|
|
seed: number;
|
|
version: number;
|
|
versionNonce: number;
|
|
isDeleted: boolean;
|
|
groupIds: readonly GroupId[];
|
|
}>;
|
|
|
|
export type ExcalidrawSelectionElement = _ExcalidrawElementBase & {
|
|
type: "selection";
|
|
};
|
|
/**
|
|
* These are elements that don't have any additional properties.
|
|
*/
|
|
export type ExcalidrawGenericElement =
|
|
| ExcalidrawSelectionElement
|
|
| (_ExcalidrawElementBase & {
|
|
type: "rectangle" | "diamond" | "ellipse";
|
|
});
|
|
|
|
/**
|
|
* ExcalidrawElement should be JSON serializable and (eventually) contain
|
|
* no computed data. The list of all ExcalidrawElements should be shareable
|
|
* between peers and contain no state local to the peer.
|
|
*/
|
|
export type ExcalidrawElement =
|
|
| ExcalidrawGenericElement
|
|
| ExcalidrawTextElement
|
|
| ExcalidrawLinearElement;
|
|
|
|
export type NonDeleted<TElement extends ExcalidrawElement> = TElement & {
|
|
isDeleted: false;
|
|
};
|
|
|
|
export type NonDeletedExcalidrawElement = NonDeleted<ExcalidrawElement>;
|
|
|
|
export type ExcalidrawTextElement = _ExcalidrawElementBase &
|
|
Readonly<{
|
|
type: "text";
|
|
fontSize: number;
|
|
fontFamily: FontFamily;
|
|
text: string;
|
|
baseline: number;
|
|
textAlign: TextAlign;
|
|
}>;
|
|
|
|
export type ExcalidrawLinearElement = _ExcalidrawElementBase &
|
|
Readonly<{
|
|
type: "arrow" | "line" | "draw";
|
|
points: readonly Point[];
|
|
lastCommittedPoint?: Point | null;
|
|
}>;
|
|
|
|
export type PointerType = "mouse" | "pen" | "touch";
|
|
|
|
export type TextAlign = "left" | "center" | "right";
|
|
|
|
export type FontFamily = keyof typeof FONT_FAMILY;
|
|
export type FontString = string & { _brand: "fontString" };
|