index.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. getCommonBounds,
  12. getDiamondPoints,
  13. getArrowPoints,
  14. getLinearElementAbsoluteBounds,
  15. } from "./bounds";
  16. export { handlerRectangles } from "./handlerRectangles";
  17. export { hitTest } from "./collision";
  18. export {
  19. resizeTest,
  20. getCursorForResizingElement,
  21. normalizeResizeHandle,
  22. } from "./resizeTest";
  23. export { isTextElement, isExcalidrawElement } from "./typeChecks";
  24. export { textWysiwyg } from "./textWysiwyg";
  25. export { redrawTextBoundingBox } from "./textElement";
  26. export {
  27. getPerfectElementSize,
  28. isInvisiblySmallElement,
  29. resizePerfectLineForNWHandler,
  30. normalizeDimensions,
  31. } from "./sizeHelpers";
  32. export { showSelectedShapeActions } from "./showSelectedShapeActions";
  33. export function getSyncableElements(elements: readonly ExcalidrawElement[]) {
  34. // There are places in Excalidraw where synthetic invisibly small elements are added and removed.
  35. // It's probably best to keep those local otherwise there might be a race condition that
  36. // gets the app into an invalid state. I've never seen it happen but I'm worried about it :)
  37. return elements.filter(el => !isInvisiblySmallElement(el));
  38. }
  39. export function getElementMap(elements: readonly ExcalidrawElement[]) {
  40. return elements.reduce(
  41. (acc: { [key: string]: ExcalidrawElement }, element: ExcalidrawElement) => {
  42. acc[element.id] = element;
  43. return acc;
  44. },
  45. {},
  46. );
  47. }
  48. export function getDrawingVersion(elements: readonly ExcalidrawElement[]) {
  49. return elements.reduce((acc, el) => acc + el.version, 0);
  50. }
  51. export function hasNonDeletedElements(elements: readonly ExcalidrawElement[]) {
  52. return elements.some(element => !element.isDeleted);
  53. }