types.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { Point } from "../types";
  2. import { FONT_FAMILY } from "../constants";
  3. export type GroupId = string;
  4. type _ExcalidrawElementBase = Readonly<{
  5. id: string;
  6. x: number;
  7. y: number;
  8. strokeColor: string;
  9. backgroundColor: string;
  10. fillStyle: string;
  11. strokeWidth: number;
  12. strokeStyle: "solid" | "dashed" | "dotted";
  13. roughness: number;
  14. opacity: number;
  15. width: number;
  16. height: number;
  17. angle: number;
  18. seed: number;
  19. version: number;
  20. versionNonce: number;
  21. isDeleted: boolean;
  22. groupIds: GroupId[];
  23. }>;
  24. export type ExcalidrawSelectionElement = _ExcalidrawElementBase & {
  25. type: "selection";
  26. };
  27. /**
  28. * These are elements that don't have any additional properties.
  29. */
  30. export type ExcalidrawGenericElement =
  31. | ExcalidrawSelectionElement
  32. | (_ExcalidrawElementBase & {
  33. type: "rectangle" | "diamond" | "ellipse";
  34. });
  35. /**
  36. * ExcalidrawElement should be JSON serializable and (eventually) contain
  37. * no computed data. The list of all ExcalidrawElements should be shareable
  38. * between peers and contain no state local to the peer.
  39. */
  40. export type ExcalidrawElement =
  41. | ExcalidrawGenericElement
  42. | ExcalidrawTextElement
  43. | ExcalidrawLinearElement;
  44. export type NonDeleted<TElement extends ExcalidrawElement> = TElement & {
  45. isDeleted: false;
  46. };
  47. export type NonDeletedExcalidrawElement = NonDeleted<ExcalidrawElement>;
  48. export type ExcalidrawTextElement = _ExcalidrawElementBase &
  49. Readonly<{
  50. type: "text";
  51. fontSize: number;
  52. fontFamily: FontFamily;
  53. text: string;
  54. baseline: number;
  55. textAlign: TextAlign;
  56. }>;
  57. export type ExcalidrawLinearElement = _ExcalidrawElementBase &
  58. Readonly<{
  59. type: "arrow" | "line" | "draw";
  60. points: Point[];
  61. lastCommittedPoint?: Point | null;
  62. }>;
  63. export type PointerType = "mouse" | "pen" | "touch";
  64. export type TextAlign = "left" | "center" | "right";
  65. export type FontFamily = keyof typeof FONT_FAMILY;
  66. export type FontString = string & { _brand: "fontString" };