typeChecks.ts 750 B

123456789101112131415161718192021222324252627282930
  1. import {
  2. ExcalidrawElement,
  3. ExcalidrawTextElement,
  4. ExcalidrawLinearElement,
  5. } from "./types";
  6. export function isTextElement(
  7. element: ExcalidrawElement | null,
  8. ): element is ExcalidrawTextElement {
  9. return element != null && element.type === "text";
  10. }
  11. export function isLinearElement(
  12. element?: ExcalidrawElement | null,
  13. ): element is ExcalidrawLinearElement {
  14. return (
  15. element != null && (element.type === "arrow" || element.type === "line")
  16. );
  17. }
  18. export function isExcalidrawElement(element: any): boolean {
  19. return (
  20. element?.type === "text" ||
  21. element?.type === "diamond" ||
  22. element?.type === "rectangle" ||
  23. element?.type === "ellipse" ||
  24. element?.type === "arrow" ||
  25. element?.type === "line"
  26. );
  27. }