index.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {
  2. ExcalidrawElement,
  3. NonDeletedExcalidrawElement,
  4. NonDeleted,
  5. } from "./types";
  6. import { isInvisiblySmallElement } from "./sizeHelpers";
  7. export {
  8. newElement,
  9. newTextElement,
  10. newLinearElement,
  11. duplicateElement,
  12. } from "./newElement";
  13. export {
  14. getElementAbsoluteCoords,
  15. getElementBounds,
  16. getCommonBounds,
  17. getDiamondPoints,
  18. getArrowPoints,
  19. getLinearElementAbsoluteBounds,
  20. } from "./bounds";
  21. export {
  22. OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,
  23. handlerRectanglesFromCoords,
  24. handlerRectangles,
  25. } from "./handlerRectangles";
  26. export { hitTest } from "./collision";
  27. export {
  28. resizeTest,
  29. getCursorForResizingElement,
  30. normalizeResizeHandle,
  31. getElementWithResizeHandler,
  32. getResizeHandlerFromCoords,
  33. } from "./resizeTest";
  34. export { resizeElements, canResizeMutlipleElements } from "./resizeElements";
  35. export { isTextElement, isExcalidrawElement } from "./typeChecks";
  36. export { textWysiwyg } from "./textWysiwyg";
  37. export { redrawTextBoundingBox } from "./textElement";
  38. export {
  39. getPerfectElementSize,
  40. isInvisiblySmallElement,
  41. resizePerfectLineForNWHandler,
  42. normalizeDimensions,
  43. } from "./sizeHelpers";
  44. export { showSelectedShapeActions } from "./showSelectedShapeActions";
  45. export function getSyncableElements(elements: readonly ExcalidrawElement[]) {
  46. // There are places in Excalidraw where synthetic invisibly small elements are added and removed.
  47. // It's probably best to keep those local otherwise there might be a race condition that
  48. // gets the app into an invalid state. I've never seen it happen but I'm worried about it :)
  49. return elements.filter((el) => el.isDeleted || !isInvisiblySmallElement(el));
  50. }
  51. export function getElementMap(elements: readonly ExcalidrawElement[]) {
  52. return elements.reduce(
  53. (acc: { [key: string]: ExcalidrawElement }, element: ExcalidrawElement) => {
  54. acc[element.id] = element;
  55. return acc;
  56. },
  57. {},
  58. );
  59. }
  60. export function getDrawingVersion(elements: readonly ExcalidrawElement[]) {
  61. return elements.reduce((acc, el) => acc + el.version, 0);
  62. }
  63. export function getNonDeletedElements(elements: readonly ExcalidrawElement[]) {
  64. return (
  65. elements.filter((element) => !element.isDeleted) as
  66. readonly NonDeletedExcalidrawElement[]
  67. );
  68. }
  69. export function isNonDeletedElement<T extends ExcalidrawElement>(
  70. element: T,
  71. ): element is NonDeleted<T> {
  72. return !element.isDeleted;
  73. }