index.ts 2.1 KB

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