types.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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: readonly GroupId[];
  23. boundElementIds: readonly ExcalidrawLinearElement["id"][] | null;
  24. }>;
  25. export type ExcalidrawSelectionElement = _ExcalidrawElementBase & {
  26. type: "selection";
  27. };
  28. export type ExcalidrawRectangleElement = _ExcalidrawElementBase & {
  29. type: "rectangle";
  30. };
  31. export type ExcalidrawDiamondElement = _ExcalidrawElementBase & {
  32. type: "diamond";
  33. };
  34. export type ExcalidrawEllipseElement = _ExcalidrawElementBase & {
  35. type: "ellipse";
  36. };
  37. /**
  38. * These are elements that don't have any additional properties.
  39. */
  40. export type ExcalidrawGenericElement =
  41. | ExcalidrawSelectionElement
  42. | ExcalidrawRectangleElement
  43. | ExcalidrawDiamondElement
  44. | ExcalidrawEllipseElement;
  45. /**
  46. * ExcalidrawElement should be JSON serializable and (eventually) contain
  47. * no computed data. The list of all ExcalidrawElements should be shareable
  48. * between peers and contain no state local to the peer.
  49. */
  50. export type ExcalidrawElement =
  51. | ExcalidrawGenericElement
  52. | ExcalidrawTextElement
  53. | ExcalidrawLinearElement;
  54. export type NonDeleted<TElement extends ExcalidrawElement> = TElement & {
  55. isDeleted: false;
  56. };
  57. export type NonDeletedExcalidrawElement = NonDeleted<ExcalidrawElement>;
  58. export type ExcalidrawTextElement = _ExcalidrawElementBase &
  59. Readonly<{
  60. type: "text";
  61. fontSize: number;
  62. fontFamily: FontFamily;
  63. text: string;
  64. baseline: number;
  65. textAlign: TextAlign;
  66. verticalAlign: VerticalAlign;
  67. }>;
  68. export type ExcalidrawBindableElement =
  69. | ExcalidrawRectangleElement
  70. | ExcalidrawDiamondElement
  71. | ExcalidrawEllipseElement
  72. | ExcalidrawTextElement;
  73. export type PointBinding = {
  74. elementId: ExcalidrawBindableElement["id"];
  75. focus: number;
  76. gap: number;
  77. };
  78. export type ExcalidrawLinearElement = _ExcalidrawElementBase &
  79. Readonly<{
  80. type: "arrow" | "line" | "draw";
  81. points: readonly Point[];
  82. lastCommittedPoint: Point | null;
  83. startBinding: PointBinding | null;
  84. endBinding: PointBinding | null;
  85. }>;
  86. export type PointerType = "mouse" | "pen" | "touch";
  87. export type TextAlign = "left" | "center" | "right";
  88. export type VerticalAlign = "top" | "middle";
  89. export type FontFamily = keyof typeof FONT_FAMILY;
  90. export type FontString = string & { _brand: "fontString" };