= {
id: "vWrqOAfkind2qcm7LDAGZ",
diff --git a/packages/excalidraw/tests/flip.test.tsx b/packages/excalidraw/tests/flip.test.tsx
index 9d9f686114..22a6c67f86 100644
--- a/packages/excalidraw/tests/flip.test.tsx
+++ b/packages/excalidraw/tests/flip.test.tsx
@@ -1,18 +1,30 @@
-import { pointFrom, type Radians } from "@excalidraw/math";
import React from "react";
import { vi } from "vitest";
+import { ROUNDNESS, KEYS, arrayToMap, cloneJSON } from "@excalidraw/common";
+
+import { pointFrom, type Radians } from "@excalidraw/math";
+
+import { getBoundTextElementPosition } from "@excalidraw/element/textElement";
+import { getElementAbsoluteCoords } from "@excalidraw/element/bounds";
+import { newLinearElement } from "@excalidraw/element/newElement";
+
import type { LocalPoint } from "@excalidraw/math";
+import type {
+ ExcalidrawElement,
+ ExcalidrawImageElement,
+ ExcalidrawLinearElement,
+ ExcalidrawTextElementWithContainer,
+ FileId,
+} from "@excalidraw/element/types";
+
import { actionFlipHorizontal, actionFlipVertical } from "../actions";
import { createPasteEvent } from "../clipboard";
-import { ROUNDNESS } from "../constants";
-import { getElementAbsoluteCoords } from "../element";
-import { newLinearElement } from "../element";
-import { getBoundTextElementPosition } from "../element/textElement";
import { Excalidraw } from "../index";
-import { KEYS } from "../keys";
-import { arrayToMap, cloneJSON } from "../utils";
+
+// Importing to spy on it and mock the implementation (mocking does not work with simple vi.mock for some reason)
+import * as blobModule from "../data/blob";
import { API } from "./helpers/api";
import { UI, Pointer, Keyboard } from "./helpers/ui";
@@ -25,25 +37,17 @@ import {
waitFor,
} from "./test-utils";
-import type {
- ExcalidrawElement,
- ExcalidrawImageElement,
- ExcalidrawLinearElement,
- ExcalidrawTextElementWithContainer,
- FileId,
-} from "../element/types";
import type { NormalizedZoomValue } from "../types";
const { h } = window;
const mouse = new Pointer("mouse");
-vi.mock("../data/blob", async (actual) => {
- const orig: Object = await actual();
- return {
- ...orig,
- resizeImageFile: (imageFile: File) => imageFile,
- generateIdFromFile: () => "fileId" as FileId,
- };
+beforeEach(() => {
+ const generateIdSpy = vi.spyOn(blobModule, "generateIdFromFile");
+ const resizeFileSpy = vi.spyOn(blobModule, "resizeImageFile");
+
+ generateIdSpy.mockImplementation(() => Promise.resolve("fileId" as FileId));
+ resizeFileSpy.mockImplementation((file: File) => Promise.resolve(file));
});
beforeEach(async () => {
diff --git a/packages/excalidraw/tests/helpers/api.ts b/packages/excalidraw/tests/helpers/api.ts
index 2aa9ee9998..09aa308a5d 100644
--- a/packages/excalidraw/tests/helpers/api.ts
+++ b/packages/excalidraw/tests/helpers/api.ts
@@ -4,29 +4,26 @@ import util from "util";
import { pointFrom, type LocalPoint, type Radians } from "@excalidraw/math";
-import { getDefaultAppState } from "../../appState";
-import { createTestHook } from "../../components/App";
-import { DEFAULT_VERTICAL_ALIGN, ROUNDNESS } from "../../constants";
-import { getMimeType } from "../../data/blob";
-import { newElement, newTextElement, newLinearElement } from "../../element";
-import { mutateElement } from "../../element/mutateElement";
+import { DEFAULT_VERTICAL_ALIGN, ROUNDNESS, assertNever } from "@excalidraw/common";
+
+import { mutateElement } from "@excalidraw/element/mutateElement";
import {
newArrowElement,
+ newElement,
newEmbeddableElement,
newFrameElement,
newFreeDrawElement,
newIframeElement,
newImageElement,
+ newLinearElement,
newMagicFrameElement,
-} from "../../element/newElement";
-import { isLinearElementType } from "../../element/typeChecks";
-import { selectGroupsForSelectedElements } from "../../groups";
-import { getSelectedElements } from "../../scene/selection";
-import { assertNever } from "../../utils";
-import { GlobalTestState, createEvent, fireEvent, act } from "../test-utils";
+ newTextElement,
+} from "@excalidraw/element/newElement";
+
+import { isLinearElementType } from "@excalidraw/element/typeChecks";
+import { getSelectedElements } from "@excalidraw/element/selection";
+import { selectGroupsForSelectedElements } from "@excalidraw/element/groups";
-import type { Action } from "../../actions/types";
-import type App from "../../components/App";
import type {
ExcalidrawElement,
ExcalidrawGenericElement,
@@ -41,9 +38,19 @@ import type {
ExcalidrawElbowArrowElement,
ExcalidrawArrowElement,
FixedSegment,
-} from "../../element/types";
+} from "@excalidraw/element/types";
+
+import type { Mutable } from "@excalidraw/common/utility-types";
+
+import { getMimeType } from "../../data/blob";
+import { createTestHook } from "../../components/App";
+import { getDefaultAppState } from "../../appState";
+import { GlobalTestState, createEvent, fireEvent, act } from "../test-utils";
+
+import type { Action } from "../../actions/types";
+import type App from "../../components/App";
import type { AppState } from "../../types";
-import type { Mutable } from "../../utility-types";
+
const readFile = util.promisify(fs.readFile);
// so that window.h is available when App.tsx is not imported as well.
diff --git a/packages/excalidraw/tests/helpers/ui.ts b/packages/excalidraw/tests/helpers/ui.ts
index a72e3fa74a..c328ae105a 100644
--- a/packages/excalidraw/tests/helpers/ui.ts
+++ b/packages/excalidraw/tests/helpers/ui.ts
@@ -1,11 +1,11 @@
import { pointFrom, pointRotateRads } from "@excalidraw/math";
-import type { GlobalPoint, LocalPoint, Radians } from "@excalidraw/math";
-
-import { createTestHook } from "../../components/App";
-import { getCommonBounds, getElementPointsCoords } from "../../element/bounds";
-import { cropElement } from "../../element/cropElement";
-import { mutateElement } from "../../element/mutateElement";
+import {
+ getCommonBounds,
+ getElementPointsCoords,
+} from "@excalidraw/element/bounds";
+import { cropElement } from "@excalidraw/element/cropElement";
+import { mutateElement } from "@excalidraw/element/mutateElement";
import {
getTransformHandles,
getTransformHandlesFromCoords,
@@ -13,21 +13,18 @@ import {
OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,
type TransformHandle,
type TransformHandleDirection,
-} from "../../element/transformHandles";
+} from "@excalidraw/element/transformHandles";
import {
isLinearElement,
isFreeDrawElement,
isTextElement,
isFrameLikeElement,
-} from "../../element/typeChecks";
-import { KEYS } from "../../keys";
-import { arrayToMap } from "../../utils";
-import { getTextEditor } from "../queries/dom";
-import { act, fireEvent, GlobalTestState, screen } from "../test-utils";
+} from "@excalidraw/element/typeChecks";
+import { KEYS, arrayToMap } from "@excalidraw/common";
-import { API } from "./api";
+import type { GlobalPoint, LocalPoint, Radians } from "@excalidraw/math";
-import type { TransformHandleType } from "../../element/transformHandles";
+import type { TransformHandleType } from "@excalidraw/element/transformHandles";
import type {
ExcalidrawElement,
ExcalidrawLinearElement,
@@ -39,7 +36,14 @@ import type {
ExcalidrawTextContainer,
ExcalidrawTextElementWithContainer,
ExcalidrawImageElement,
-} from "../../element/types";
+} from "@excalidraw/element/types";
+
+import { createTestHook } from "../../components/App";
+import { getTextEditor } from "../queries/dom";
+import { act, fireEvent, GlobalTestState, screen } from "../test-utils";
+
+import { API } from "./api";
+
import type { ToolType } from "../../types";
// so that window.h is available when App.tsx is not imported as well.
diff --git a/packages/excalidraw/tests/history.test.tsx b/packages/excalidraw/tests/history.test.tsx
index 6e7066b902..8dd65c7a5f 100644
--- a/packages/excalidraw/tests/history.test.tsx
+++ b/packages/excalidraw/tests/history.test.tsx
@@ -8,10 +8,35 @@ import {
import { vi } from "vitest";
import { pointFrom } from "@excalidraw/math";
+import { newElementWith } from "@excalidraw/element/mutateElement";
+
+import {
+ EXPORT_DATA_TYPES,
+ MIME_TYPES,
+ ORIG_ID,
+ KEYS,
+ arrayToMap,
+ COLOR_PALETTE,
+ DEFAULT_ELEMENT_BACKGROUND_COLOR_INDEX,
+ DEFAULT_ELEMENT_STROKE_COLOR_INDEX,
+} from "@excalidraw/common";
+
+import "@excalidraw/utils/test-utils";
+
import type { LocalPoint, Radians } from "@excalidraw/math";
+import type {
+ ExcalidrawElbowArrowElement,
+ ExcalidrawFrameElement,
+ ExcalidrawGenericElement,
+ ExcalidrawLinearElement,
+ ExcalidrawTextElement,
+ FixedPointBinding,
+ FractionalIndex,
+ SceneElementsMap,
+} from "@excalidraw/element/types";
+
import "../global.d.ts";
-import "../../utils/test-utils";
import {
actionSendBackward,
@@ -23,17 +48,8 @@ import { actionToggleViewMode } from "../actions/actionToggleViewMode";
import { getDefaultAppState } from "../appState";
import { HistoryEntry } from "../history";
import { Excalidraw } from "../index";
-import { KEYS } from "../keys";
import * as StaticScene from "../renderer/staticScene";
-import { EXPORT_DATA_TYPES, MIME_TYPES, ORIG_ID } from "../constants";
import { Snapshot, CaptureUpdateAction } from "../store";
-import { arrayToMap } from "../utils";
-import {
- COLOR_PALETTE,
- DEFAULT_ELEMENT_BACKGROUND_COLOR_INDEX,
- DEFAULT_ELEMENT_STROKE_COLOR_INDEX,
-} from "../colors";
-import { newElementWith } from "../element/mutateElement";
import { AppStateChange, ElementsChange } from "../change";
import { API } from "./helpers/api";
@@ -47,16 +63,6 @@ import {
getCloneByOrigId,
} from "./test-utils";
-import type {
- ExcalidrawElbowArrowElement,
- ExcalidrawFrameElement,
- ExcalidrawGenericElement,
- ExcalidrawLinearElement,
- ExcalidrawTextElement,
- FixedPointBinding,
- FractionalIndex,
- SceneElementsMap,
-} from "../element/types";
import type { AppState } from "../types";
const { h } = window;
diff --git a/packages/excalidraw/tests/library.test.tsx b/packages/excalidraw/tests/library.test.tsx
index b084d835bb..d2b6c13c8f 100644
--- a/packages/excalidraw/tests/library.test.tsx
+++ b/packages/excalidraw/tests/library.test.tsx
@@ -2,18 +2,21 @@ import { act, queryByTestId } from "@testing-library/react";
import React from "react";
import { vi } from "vitest";
-import { MIME_TYPES, ORIG_ID } from "../constants";
+import { MIME_TYPES, ORIG_ID } from "@excalidraw/common";
+
+import { getCommonBoundingBox } from "@excalidraw/element/bounds";
+
+import type { ExcalidrawGenericElement } from "@excalidraw/element/types";
+
import { parseLibraryJSON } from "../data/blob";
import { serializeLibraryAsJSON } from "../data/json";
import { distributeLibraryItemsOnSquareGrid } from "../data/library";
-import { getCommonBoundingBox } from "../element/bounds";
import { Excalidraw } from "../index";
import { API } from "./helpers/api";
import { UI } from "./helpers/ui";
import { fireEvent, getCloneByOrigId, render, waitFor } from "./test-utils";
-import type { ExcalidrawGenericElement } from "../element/types";
import type { LibraryItem, LibraryItems } from "../types";
const { h } = window;
diff --git a/packages/excalidraw/tests/linearElementEditor.test.tsx b/packages/excalidraw/tests/linearElementEditor.test.tsx
index 162dbb3f0c..741799d3be 100644
--- a/packages/excalidraw/tests/linearElementEditor.test.tsx
+++ b/packages/excalidraw/tests/linearElementEditor.test.tsx
@@ -3,23 +3,35 @@ import { act, queryByTestId, queryByText } from "@testing-library/react";
import React from "react";
import { vi } from "vitest";
-import type { GlobalPoint } from "@excalidraw/math";
+import {
+ ROUNDNESS,
+ VERTICAL_ALIGN,
+ KEYS,
+ reseed,
+ arrayToMap,
+} from "@excalidraw/common";
-import { ROUNDNESS, VERTICAL_ALIGN } from "../constants";
-import { LinearElementEditor } from "../element/linearElementEditor";
+import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import {
getBoundTextElementPosition,
getBoundTextMaxWidth,
-} from "../element/textElement";
-import * as textElementUtils from "../element/textElement";
-import { wrapText } from "../element/textWrapping";
+} from "@excalidraw/element/textElement";
+import * as textElementUtils from "@excalidraw/element/textElement";
+import { wrapText } from "@excalidraw/element/textWrapping";
+
+import type { GlobalPoint } from "@excalidraw/math";
+
+import type {
+ ExcalidrawElement,
+ ExcalidrawLinearElement,
+ ExcalidrawTextElementWithContainer,
+ FontString,
+} from "@excalidraw/element/types";
+
import { Excalidraw, mutateElement } from "../index";
-import { KEYS } from "../keys";
-import { reseed } from "../random";
import * as InteractiveCanvas from "../renderer/interactiveScene";
import * as StaticScene from "../renderer/staticScene";
import { API } from "../tests/helpers/api";
-import { arrayToMap } from "../utils";
import { Keyboard, Pointer, UI } from "./helpers/ui";
import {
@@ -30,13 +42,6 @@ import {
unmountComponent,
} from "./test-utils";
-import type {
- ExcalidrawElement,
- ExcalidrawLinearElement,
- ExcalidrawTextElementWithContainer,
- FontString,
-} from "../element/types";
-
const renderInteractiveScene = vi.spyOn(
InteractiveCanvas,
"renderInteractiveScene",
diff --git a/packages/excalidraw/tests/move.test.tsx b/packages/excalidraw/tests/move.test.tsx
index 855496f44f..77fc7e57db 100644
--- a/packages/excalidraw/tests/move.test.tsx
+++ b/packages/excalidraw/tests/move.test.tsx
@@ -1,23 +1,26 @@
import React from "react";
import { vi } from "vitest";
-import "../../utils/test-utils";
-import { bindOrUnbindLinearElement } from "../element/binding";
-import { Excalidraw } from "../index";
-import { KEYS } from "../keys";
-import { reseed } from "../random";
-import * as InteractiveCanvas from "../renderer/interactiveScene";
-import * as StaticScene from "../renderer/staticScene";
+import { bindOrUnbindLinearElement } from "@excalidraw/element/binding";
-import { UI, Pointer, Keyboard } from "./helpers/ui";
-import { render, fireEvent, act, unmountComponent } from "./test-utils";
+import { KEYS, reseed } from "@excalidraw/common";
+
+import "@excalidraw/utils/test-utils";
import type {
ExcalidrawLinearElement,
NonDeleted,
ExcalidrawRectangleElement,
-} from "../element/types";
-import type Scene from "../scene/Scene";
+} from "@excalidraw/element/types";
+
+import type Scene from "@excalidraw/excalidraw/scene/Scene";
+
+import { Excalidraw } from "../index";
+import * as InteractiveCanvas from "../renderer/interactiveScene";
+import * as StaticScene from "../renderer/staticScene";
+
+import { UI, Pointer, Keyboard } from "./helpers/ui";
+import { render, fireEvent, act, unmountComponent } from "./test-utils";
unmountComponent();
diff --git a/packages/excalidraw/tests/multiPointCreate.test.tsx b/packages/excalidraw/tests/multiPointCreate.test.tsx
index 5cbce49668..cde3c7f983 100644
--- a/packages/excalidraw/tests/multiPointCreate.test.tsx
+++ b/packages/excalidraw/tests/multiPointCreate.test.tsx
@@ -1,9 +1,12 @@
import React from "react";
import { vi } from "vitest";
+import { KEYS, reseed } from "@excalidraw/common";
+
+import type { ExcalidrawLinearElement } from "@excalidraw/element/types";
+
import { Excalidraw } from "../index";
-import { KEYS } from "../keys";
-import { reseed } from "../random";
+
import * as InteractiveCanvas from "../renderer/interactiveScene";
import * as StaticScene from "../renderer/staticScene";
@@ -15,8 +18,6 @@ import {
unmountComponent,
} from "./test-utils";
-import type { ExcalidrawLinearElement } from "../element/types";
-
unmountComponent();
const renderInteractiveScene = vi.spyOn(
diff --git a/packages/excalidraw/tests/packages/events.test.tsx b/packages/excalidraw/tests/packages/events.test.tsx
index 3e79239c8e..bc4441c40d 100644
--- a/packages/excalidraw/tests/packages/events.test.tsx
+++ b/packages/excalidraw/tests/packages/events.test.tsx
@@ -1,8 +1,9 @@
import React from "react";
import { vi } from "vitest";
+import { resolvablePromise } from "@excalidraw/common";
+
import { Excalidraw, CaptureUpdateAction } from "../../index";
-import { resolvablePromise } from "../../utils";
import { API } from "../helpers/api";
import { Pointer } from "../helpers/ui";
import { render } from "../test-utils";
diff --git a/packages/excalidraw/tests/queries/toolQueries.ts b/packages/excalidraw/tests/queries/toolQueries.ts
index ed168735dc..8413bf5fb9 100644
--- a/packages/excalidraw/tests/queries/toolQueries.ts
+++ b/packages/excalidraw/tests/queries/toolQueries.ts
@@ -1,8 +1,8 @@
import { queries, buildQueries } from "@testing-library/react";
-import { TOOL_TYPE } from "../../constants";
+import { TOOL_TYPE } from "@excalidraw/common";
-import type { ToolType } from "../../types";
+import type { ToolType } from "@excalidraw/excalidraw/types";
const _getAllByToolName = (container: HTMLElement, tool: ToolType | "lock") => {
const toolTitle = tool === "lock" ? "lock" : TOOL_TYPE[tool];
diff --git a/packages/excalidraw/tests/regressionTests.test.tsx b/packages/excalidraw/tests/regressionTests.test.tsx
index 42d726f1d9..68765024eb 100644
--- a/packages/excalidraw/tests/regressionTests.test.tsx
+++ b/packages/excalidraw/tests/regressionTests.test.tsx
@@ -1,12 +1,14 @@
import React from "react";
import { vi } from "vitest";
-import { FONT_FAMILY } from "../constants";
+import { FONT_FAMILY, CODES, KEYS, reseed } from "@excalidraw/common";
+
+import { setDateTimeForTests } from "@excalidraw/common";
+
+import type { ExcalidrawElement } from "@excalidraw/element/types";
+
import { Excalidraw } from "../index";
-import { CODES, KEYS } from "../keys";
-import { reseed } from "../random";
import * as StaticScene from "../renderer/staticScene";
-import { setDateTimeForTests } from "../utils";
import { API } from "./helpers/api";
import { Keyboard, Pointer, UI } from "./helpers/ui";
@@ -19,8 +21,6 @@ import {
unmountComponent,
} from "./test-utils";
-import type { ExcalidrawElement } from "../element/types";
-
const { h } = window;
const renderStaticScene = vi.spyOn(StaticScene, "renderStaticScene");
diff --git a/packages/excalidraw/tests/rotate.test.tsx b/packages/excalidraw/tests/rotate.test.tsx
index 2c678f45b9..9687b08f25 100644
--- a/packages/excalidraw/tests/rotate.test.tsx
+++ b/packages/excalidraw/tests/rotate.test.tsx
@@ -1,8 +1,9 @@
import React from "react";
import { expect } from "vitest";
+import { reseed } from "@excalidraw/common";
+
import { Excalidraw } from "../index";
-import { reseed } from "../random";
import { UI } from "./helpers/ui";
import { render, unmountComponent } from "./test-utils";
diff --git a/packages/excalidraw/tests/scene/export.test.ts b/packages/excalidraw/tests/scene/export.test.ts
index 43c37eb283..3187e2c40a 100644
--- a/packages/excalidraw/tests/scene/export.test.ts
+++ b/packages/excalidraw/tests/scene/export.test.ts
@@ -1,6 +1,13 @@
import { exportToCanvas, exportToSvg } from "@excalidraw/utils";
-import { FONT_FAMILY, FRAME_STYLE } from "../../constants";
+import { FONT_FAMILY, FRAME_STYLE } from "@excalidraw/common";
+
+import type {
+ ExcalidrawTextElement,
+ FractionalIndex,
+ NonDeletedExcalidrawElement,
+} from "@excalidraw/element/types";
+
import { prepareElementsForExport } from "../../data";
import * as exportUtils from "../../scene/export";
import {
@@ -11,12 +18,6 @@ import {
} from "../fixtures/elementFixture";
import { API } from "../helpers/api";
-import type {
- ExcalidrawTextElement,
- FractionalIndex,
- NonDeletedExcalidrawElement,
-} from "../../element/types";
-
describe("exportToSvg", () => {
const ELEMENT_HEIGHT = 100;
const ELEMENT_WIDTH = 100;
diff --git a/packages/excalidraw/tests/scroll.test.tsx b/packages/excalidraw/tests/scroll.test.tsx
index 2ccc4546fd..ef5eb3dbf7 100644
--- a/packages/excalidraw/tests/scroll.test.tsx
+++ b/packages/excalidraw/tests/scroll.test.tsx
@@ -1,7 +1,8 @@
import React from "react";
+import { KEYS } from "@excalidraw/common";
+
import { Excalidraw } from "../index";
-import { KEYS } from "../keys";
import { API } from "./helpers/api";
import { Keyboard } from "./helpers/ui";
diff --git a/packages/excalidraw/tests/search.test.tsx b/packages/excalidraw/tests/search.test.tsx
index d3622d4b1a..3a42cff627 100644
--- a/packages/excalidraw/tests/search.test.tsx
+++ b/packages/excalidraw/tests/search.test.tsx
@@ -1,16 +1,21 @@
import React from "react";
-import { CANVAS_SEARCH_TAB, CLASSES, DEFAULT_SIDEBAR } from "../constants";
+import {
+ CANVAS_SEARCH_TAB,
+ CLASSES,
+ DEFAULT_SIDEBAR,
+ KEYS,
+} from "@excalidraw/common";
+
+import type { ExcalidrawTextElement } from "@excalidraw/element/types";
+
import { Excalidraw } from "../index";
-import { KEYS } from "../keys";
import { API } from "./helpers/api";
import { Keyboard } from "./helpers/ui";
import { updateTextEditor } from "./queries/dom";
import { act, render, waitFor } from "./test-utils";
-import type { ExcalidrawTextElement } from "../element/types";
-
const { h } = window;
const querySearchInput = async () => {
diff --git a/packages/excalidraw/tests/selection.test.tsx b/packages/excalidraw/tests/selection.test.tsx
index d93d3eff53..10f4f7ad98 100644
--- a/packages/excalidraw/tests/selection.test.tsx
+++ b/packages/excalidraw/tests/selection.test.tsx
@@ -1,12 +1,13 @@
import React from "react";
import { vi } from "vitest";
+import { KEYS, reseed } from "@excalidraw/common";
+
+import { SHAPES } from "../components/shapes";
+
import { Excalidraw } from "../index";
-import { KEYS } from "../keys";
-import { reseed } from "../random";
import * as InteractiveCanvas from "../renderer/interactiveScene";
import * as StaticScene from "../renderer/staticScene";
-import { SHAPES } from "../shapes";
import { API } from "./helpers/api";
import { Keyboard, Pointer, UI } from "./helpers/ui";
diff --git a/packages/excalidraw/tests/shortcuts.test.tsx b/packages/excalidraw/tests/shortcuts.test.tsx
index ee2234ecc8..d4d1cb0def 100644
--- a/packages/excalidraw/tests/shortcuts.test.tsx
+++ b/packages/excalidraw/tests/shortcuts.test.tsx
@@ -1,7 +1,8 @@
import React from "react";
+import { KEYS } from "@excalidraw/common";
+
import { Excalidraw } from "../index";
-import { KEYS } from "../keys";
import { API } from "./helpers/api";
import { Keyboard } from "./helpers/ui";
diff --git a/packages/excalidraw/tests/test-utils.ts b/packages/excalidraw/tests/test-utils.ts
index 73b3409827..b2b8aff9c9 100644
--- a/packages/excalidraw/tests/test-utils.ts
+++ b/packages/excalidraw/tests/test-utils.ts
@@ -9,10 +9,15 @@ import {
} from "@testing-library/react";
import ansi from "ansicolor";
+import { ORIG_ID, arrayToMap } from "@excalidraw/common";
+
+import { getSelectedElements } from "@excalidraw/element/selection";
+
+import type { ExcalidrawElement } from "@excalidraw/element/types";
+
+import type { AllPossibleKeys } from "@excalidraw/common/utility-types";
+
import { STORAGE_KEYS } from "../../../excalidraw-app/app_constants";
-import { ORIG_ID } from "../constants";
-import { getSelectedElements } from "../scene/selection";
-import { arrayToMap } from "../utils";
import { UI } from "./helpers/ui";
import * as toolQueries from "./queries/toolQueries";
@@ -20,8 +25,6 @@ import * as toolQueries from "./queries/toolQueries";
import type { RenderResult, RenderOptions } from "@testing-library/react";
import type { ImportedDataState } from "../data/types";
-import type { ExcalidrawElement } from "../element/types";
-import type { AllPossibleKeys } from "../utility-types";
export { cleanup as unmountComponent };
diff --git a/packages/excalidraw/tests/tool.test.tsx b/packages/excalidraw/tests/tool.test.tsx
index f70d1ccdd1..f7c101c1da 100644
--- a/packages/excalidraw/tests/tool.test.tsx
+++ b/packages/excalidraw/tests/tool.test.tsx
@@ -1,7 +1,8 @@
import React from "react";
+import { resolvablePromise } from "@excalidraw/common";
+
import { Excalidraw } from "../index";
-import { resolvablePromise } from "../utils";
import { Pointer } from "./helpers/ui";
import { act, render } from "./test-utils";
diff --git a/packages/excalidraw/tests/utils.test.ts b/packages/excalidraw/tests/utils.test.ts
index 34944faaa0..2dc8c00972 100644
--- a/packages/excalidraw/tests/utils.test.ts
+++ b/packages/excalidraw/tests/utils.test.ts
@@ -1,4 +1,4 @@
-import { isTransparent } from "../utils";
+import { isTransparent } from "@excalidraw/common";
describe("Test isTransparent", () => {
it("should return true when color is rgb transparent", () => {
diff --git a/packages/excalidraw/tests/viewMode.test.tsx b/packages/excalidraw/tests/viewMode.test.tsx
index c190ee0e3b..0a94055c79 100644
--- a/packages/excalidraw/tests/viewMode.test.tsx
+++ b/packages/excalidraw/tests/viewMode.test.tsx
@@ -1,8 +1,8 @@
import React from "react";
-import { CURSOR_TYPE } from "../constants";
+import { CURSOR_TYPE, KEYS } from "@excalidraw/common";
+
import { Excalidraw } from "../index";
-import { KEYS } from "../keys";
import { API } from "./helpers/api";
import { Keyboard, Pointer, UI } from "./helpers/ui";
diff --git a/packages/excalidraw/tsconfig.json b/packages/excalidraw/tsconfig.json
index f61b8d0af4..82cc2c2377 100644
--- a/packages/excalidraw/tsconfig.json
+++ b/packages/excalidraw/tsconfig.json
@@ -1,24 +1,6 @@
{
+ "extends": "../tsconfig.base.json",
"compilerOptions": {
- "outDir": "./dist/types",
- "target": "ESNext",
- "strict": true,
- "skipLibCheck": true,
- "declaration": true,
- "allowSyntheticDefaultImports": true,
- "module": "ESNext",
- "moduleResolution": "Node",
- "resolveJsonModule": true,
- "jsx": "react-jsx",
- "emitDeclarationOnly": true,
- "paths": {
- "@excalidraw/excalidraw": ["../excalidraw/index.tsx"],
- "@excalidraw/utils": ["../utils/index.ts"],
- "@excalidraw/math": ["../math/index.ts"],
- "@excalidraw/excalidraw/*": ["../excalidraw/*"],
- "@excalidraw/utils/*": ["../utils/*"],
- "@excalidraw/math/*": ["../math/*"]
- }
- },
- "exclude": ["**/*.test.*", "tests", "types", "examples", "dist"]
+ "outDir": "./dist/types"
+ }
}
diff --git a/packages/excalidraw/types.ts b/packages/excalidraw/types.ts
index 64c0ac2989..31ce332f8d 100644
--- a/packages/excalidraw/types.ts
+++ b/packages/excalidraw/types.ts
@@ -1,19 +1,16 @@
-import type { Action } from "./actions/types";
-import type { Spreadsheet } from "./charts";
-import type { ClipboardData } from "./clipboard";
-import type App from "./components/App";
-import type Library from "./data/library";
-import type { FileSystemHandle } from "./data/filesystem";
-import type { IMAGE_MIME_TYPES, MIME_TYPES } from "./constants";
-import type { ContextMenuItems } from "./components/ContextMenu";
-import type { SnapLine } from "./snapping";
-import type { Merge, MaybePromise, ValueOf, MakeBrand } from "./utility-types";
-import type { CaptureUpdateActionType } from "./store";
-import type { UserIdleState } from "./constants";
-import type { ImportedDataState } from "./data/types";
-import type { SuggestedBinding } from "./element/binding";
-import type { LinearElementEditor } from "./element/linearElementEditor";
-import type { MaybeTransformHandleType } from "./element/transformHandles";
+import type {
+ IMAGE_MIME_TYPES,
+ UserIdleState,
+ throttleRAF,
+ MIME_TYPES,
+} from "@excalidraw/common";
+
+import type { SuggestedBinding } from "@excalidraw/element/binding";
+
+import type { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
+
+import type { MaybeTransformHandleType } from "@excalidraw/element/transformHandles";
+
import type {
PointerType,
ExcalidrawLinearElement,
@@ -37,10 +34,28 @@ import type {
ExcalidrawIframeLikeElement,
OrderedExcalidrawElement,
ExcalidrawNonSelectionElement,
-} from "./element/types";
+} from "@excalidraw/element/types";
+
+import type {
+ Merge,
+ MaybePromise,
+ ValueOf,
+ MakeBrand,
+} from "@excalidraw/common/utility-types";
+
+import type { Action } from "./actions/types";
+import type { Spreadsheet } from "./charts";
+import type { ClipboardData } from "./clipboard";
+import type App from "./components/App";
+import type Library from "./data/library";
+import type { FileSystemHandle } from "./data/filesystem";
+import type { ContextMenuItems } from "./components/ContextMenu";
+import type { SnapLine } from "./snapping";
+import type { CaptureUpdateActionType } from "./store";
+import type { ImportedDataState } from "./data/types";
+
import type { Language } from "./i18n";
import type { isOverScrollBars } from "./scene/scrollbars";
-import type { throttleRAF } from "./utils";
import type React from "react";
import type { JSX } from "react";
diff --git a/packages/excalidraw/visualdebug.ts b/packages/excalidraw/visualdebug.ts
index 6b70148649..9ad1490d1d 100644
--- a/packages/excalidraw/visualdebug.ts
+++ b/packages/excalidraw/visualdebug.ts
@@ -6,12 +6,12 @@ import {
type LocalPoint,
} from "@excalidraw/math";
+import { isBounds } from "@excalidraw/element/typeChecks";
+
import type { Curve } from "@excalidraw/math";
import type { LineSegment } from "@excalidraw/utils";
-import { isBounds } from "./element/typeChecks";
-
-import type { Bounds } from "./element/bounds";
+import type { Bounds } from "@excalidraw/element/bounds";
// The global data holder to collect the debug operations
declare global {
diff --git a/packages/excalidraw/vite-env.d.ts b/packages/excalidraw/vite-env.d.ts
index 4292e3b6a6..3c53906ab2 100644
--- a/packages/excalidraw/vite-env.d.ts
+++ b/packages/excalidraw/vite-env.d.ts
@@ -24,6 +24,8 @@ interface ImportMetaEnv {
// whether to disable live reload / HMR. Usuaully what you want to do when
// debugging Service Workers.
VITE_APP_DEV_DISABLE_LIVE_RELOAD: string;
+ // To enable bounding box for text containers
+ VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX: string;
FAST_REFRESH: string;
@@ -34,8 +36,6 @@ interface ImportMetaEnv {
//Debug flags
- // To enable bounding box for text containers
- VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX: string;
VITE_APP_DISABLE_SENTRY: string;
// Set this flag to false if you want to open the overlay by default
VITE_APP_COLLAPSE_OVERLAY: string;
diff --git a/packages/excalidraw/workers.ts b/packages/excalidraw/workers.ts
index f5964d0884..38efda1024 100644
--- a/packages/excalidraw/workers.ts
+++ b/packages/excalidraw/workers.ts
@@ -1,5 +1,6 @@
+import { debounce } from "@excalidraw/common";
+
import { WorkerInTheMainChunkError, WorkerUrlNotDefinedError } from "./errors";
-import { debounce } from "./utils";
class IdleWorker {
public instance: Worker;
diff --git a/packages/excalidraw/element/textWysiwyg.test.tsx b/packages/excalidraw/wysiwyg/textWysiwyg.test.tsx
similarity index 99%
rename from packages/excalidraw/element/textWysiwyg.test.tsx
rename to packages/excalidraw/wysiwyg/textWysiwyg.test.tsx
index 11c700e330..959c5a0129 100644
--- a/packages/excalidraw/element/textWysiwyg.test.tsx
+++ b/packages/excalidraw/wysiwyg/textWysiwyg.test.tsx
@@ -1,10 +1,22 @@
-import { pointFrom } from "@excalidraw/math";
import { queryByText } from "@testing-library/react";
-import React from "react";
-import { FONT_FAMILY, TEXT_ALIGN, VERTICAL_ALIGN } from "../constants";
+import { pointFrom } from "@excalidraw/math";
+import { getOriginalContainerHeightFromCache } from "@excalidraw/element/containerCache";
+
+import {
+ CODES,
+ KEYS,
+ FONT_FAMILY,
+ TEXT_ALIGN,
+ VERTICAL_ALIGN,
+} from "@excalidraw/common";
+
+import type {
+ ExcalidrawTextElement,
+ ExcalidrawTextElementWithContainer,
+} from "@excalidraw/element/types";
+
import { Excalidraw } from "../index";
-import { CODES, KEYS } from "../keys";
import { API } from "../tests/helpers/api";
import { Keyboard, Pointer, UI } from "../tests/helpers/ui";
import { getTextEditor, updateTextEditor } from "../tests/queries/dom";
@@ -20,13 +32,6 @@ import {
restoreOriginalGetBoundingClientRect,
} from "../tests/test-utils";
-import { getOriginalContainerHeightFromCache } from "./containerCache";
-
-import type {
- ExcalidrawTextElement,
- ExcalidrawTextElementWithContainer,
-} from "./types";
-
unmountComponent();
const tab = " ";
diff --git a/packages/excalidraw/element/textWysiwyg.tsx b/packages/excalidraw/wysiwyg/textWysiwyg.tsx
similarity index 97%
rename from packages/excalidraw/element/textWysiwyg.tsx
rename to packages/excalidraw/wysiwyg/textWysiwyg.tsx
index b31798687c..b1610125f3 100644
--- a/packages/excalidraw/element/textWysiwyg.tsx
+++ b/packages/excalidraw/wysiwyg/textWysiwyg.tsx
@@ -1,31 +1,21 @@
import {
- actionResetZoom,
- actionZoomIn,
- actionZoomOut,
-} from "../actions/actionCanvas";
-import {
- actionDecreaseFontSize,
- actionIncreaseFontSize,
-} from "../actions/actionProperties";
-import { parseClipboard } from "../clipboard";
-import { CLASSES, POINTER_BUTTON } from "../constants";
-import { CODES, KEYS } from "../keys";
-import Scene from "../scene/Scene";
-import {
+ CODES,
+ KEYS,
+ CLASSES,
+ POINTER_BUTTON,
isWritableElement,
getFontString,
getFontFamilyString,
isTestEnv,
-} from "../utils";
-
-import { actionSaveToActiveFile } from "../actions";
+} from "@excalidraw/common";
import {
originalContainerCache,
updateOriginalContainerCache,
-} from "./containerCache";
-import { LinearElementEditor } from "./linearElementEditor";
-import { bumpVersion, mutateElement } from "./mutateElement";
+} from "@excalidraw/element/containerCache";
+
+import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
+import { bumpVersion, mutateElement } from "@excalidraw/element/mutateElement";
import {
getBoundTextElementId,
getContainerElement,
@@ -36,22 +26,37 @@ import {
computeContainerDimensionForBoundText,
computeBoundTextPosition,
getBoundTextElement,
-} from "./textElement";
-import { getTextWidth } from "./textMeasurements";
-import { normalizeText } from "./textMeasurements";
-import { wrapText } from "./textWrapping";
+} from "@excalidraw/element/textElement";
+import { getTextWidth } from "@excalidraw/element/textMeasurements";
+import { normalizeText } from "@excalidraw/element/textMeasurements";
+import { wrapText } from "@excalidraw/element/textWrapping";
import {
isArrowElement,
isBoundToContainer,
isTextElement,
-} from "./typeChecks";
+} from "@excalidraw/element/typeChecks";
import type {
ExcalidrawElement,
ExcalidrawLinearElement,
ExcalidrawTextElementWithContainer,
ExcalidrawTextElement,
-} from "./types";
+} from "@excalidraw/element/types";
+
+import { actionSaveToActiveFile } from "../actions";
+
+import Scene from "../scene/Scene";
+import { parseClipboard } from "../clipboard";
+import {
+ actionDecreaseFontSize,
+ actionIncreaseFontSize,
+} from "../actions/actionProperties";
+import {
+ actionResetZoom,
+ actionZoomIn,
+ actionZoomOut,
+} from "../actions/actionCanvas";
+
import type App from "../components/App";
import type { AppState } from "../types";
diff --git a/packages/math/CHANGELOG.md b/packages/math/CHANGELOG.md
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/packages/math/README.md b/packages/math/README.md
index eaa163037b..348a9de07f 100644
--- a/packages/math/README.md
+++ b/packages/math/README.md
@@ -17,5 +17,3 @@ With PNPM, similarly install the package with this command:
```bash
pnpm add @excalidraw/math
```
-
-## API
diff --git a/packages/math/package.json b/packages/math/package.json
index a60c971191..aef877f451 100644
--- a/packages/math/package.json
+++ b/packages/math/package.json
@@ -54,6 +54,6 @@
"repository": "https://github.com/excalidraw/excalidraw",
"scripts": {
"gen:types": "rm -rf types && tsc",
- "build:esm": "rm -rf dist && node ../../scripts/buildMath.js && yarn gen:types"
+ "build:esm": "rm -rf dist && node ../../scripts/buildBase.js && yarn gen:types"
}
}
diff --git a/packages/math/angle.ts b/packages/math/src/angle.ts
similarity index 100%
rename from packages/math/angle.ts
rename to packages/math/src/angle.ts
diff --git a/packages/math/curve.ts b/packages/math/src/curve.ts
similarity index 98%
rename from packages/math/curve.ts
rename to packages/math/src/curve.ts
index cd466bbc78..a79fb43a19 100644
--- a/packages/math/curve.ts
+++ b/packages/math/src/curve.ts
@@ -1,8 +1,9 @@
+import type { Bounds } from "@excalidraw/element/bounds";
+
import { isPoint, pointDistance, pointFrom } from "./point";
import { rectangle, rectangleIntersectLineSegment } from "./rectangle";
import type { Curve, GlobalPoint, LineSegment, LocalPoint } from "./types";
-import type { Bounds } from "../excalidraw/element/bounds";
/**
*
diff --git a/packages/math/ellipse.ts b/packages/math/src/ellipse.ts
similarity index 100%
rename from packages/math/ellipse.ts
rename to packages/math/src/ellipse.ts
diff --git a/packages/math/index.ts b/packages/math/src/index.ts
similarity index 100%
rename from packages/math/index.ts
rename to packages/math/src/index.ts
diff --git a/packages/math/line.ts b/packages/math/src/line.ts
similarity index 100%
rename from packages/math/line.ts
rename to packages/math/src/line.ts
diff --git a/packages/math/point.ts b/packages/math/src/point.ts
similarity index 100%
rename from packages/math/point.ts
rename to packages/math/src/point.ts
diff --git a/packages/math/polygon.ts b/packages/math/src/polygon.ts
similarity index 100%
rename from packages/math/polygon.ts
rename to packages/math/src/polygon.ts
diff --git a/packages/math/range.ts b/packages/math/src/range.ts
similarity index 97%
rename from packages/math/range.ts
rename to packages/math/src/range.ts
index dee3d7edfc..1b292344ee 100644
--- a/packages/math/range.ts
+++ b/packages/math/src/range.ts
@@ -1,4 +1,4 @@
-import { toBrandedType } from "@excalidraw/excalidraw/utils";
+import { toBrandedType } from "@excalidraw/common";
import type { InclusiveRange } from "./types";
diff --git a/packages/math/rectangle.ts b/packages/math/src/rectangle.ts
similarity index 100%
rename from packages/math/rectangle.ts
rename to packages/math/src/rectangle.ts
diff --git a/packages/math/segment.ts b/packages/math/src/segment.ts
similarity index 100%
rename from packages/math/segment.ts
rename to packages/math/src/segment.ts
diff --git a/packages/math/triangle.ts b/packages/math/src/triangle.ts
similarity index 100%
rename from packages/math/triangle.ts
rename to packages/math/src/triangle.ts
diff --git a/packages/math/types.ts b/packages/math/src/types.ts
similarity index 100%
rename from packages/math/types.ts
rename to packages/math/src/types.ts
diff --git a/packages/math/utils.ts b/packages/math/src/utils.ts
similarity index 100%
rename from packages/math/utils.ts
rename to packages/math/src/utils.ts
diff --git a/packages/math/vector.ts b/packages/math/src/vector.ts
similarity index 100%
rename from packages/math/vector.ts
rename to packages/math/src/vector.ts
diff --git a/packages/math/curve.test.ts b/packages/math/tests/curve.test.ts
similarity index 94%
rename from packages/math/curve.test.ts
rename to packages/math/tests/curve.test.ts
index 8d60a73465..7395620968 100644
--- a/packages/math/curve.test.ts
+++ b/packages/math/tests/curve.test.ts
@@ -1,13 +1,13 @@
-import "../utils/test-utils";
+import "@excalidraw/utils/test-utils";
import {
curve,
curveClosestPoint,
curveIntersectLineSegment,
curvePointDistance,
-} from "./curve";
-import { pointFrom } from "./point";
-import { lineSegment } from "./segment";
+} from "../src/curve";
+import { pointFrom } from "../src/point";
+import { lineSegment } from "../src/segment";
describe("Math curve", () => {
describe("line segment intersection", () => {
diff --git a/packages/math/ellipse.test.ts b/packages/math/tests/ellipse.test.ts
similarity index 94%
rename from packages/math/ellipse.test.ts
rename to packages/math/tests/ellipse.test.ts
index bcaab2a5de..4fa0d4e59f 100644
--- a/packages/math/ellipse.test.ts
+++ b/packages/math/tests/ellipse.test.ts
@@ -4,12 +4,12 @@ import {
ellipseIncludesPoint,
ellipseTouchesPoint,
ellipseLineIntersectionPoints,
-} from "./ellipse";
-import { line } from "./line";
-import { pointFrom } from "./point";
-import { lineSegment } from "./segment";
+} from "../src/ellipse";
+import { line } from "../src/line";
+import { pointFrom } from "../src/point";
+import { lineSegment } from "../src/segment";
-import type { Ellipse, GlobalPoint } from "./types";
+import type { Ellipse, GlobalPoint } from "../src/types";
describe("point and ellipse", () => {
it("point on ellipse", () => {
diff --git a/packages/math/line.test.ts b/packages/math/tests/line.test.ts
similarity index 88%
rename from packages/math/line.test.ts
rename to packages/math/tests/line.test.ts
index 0e6bb1cc8f..c8915a466c 100644
--- a/packages/math/line.test.ts
+++ b/packages/math/tests/line.test.ts
@@ -1,5 +1,5 @@
-import { line, linesIntersectAt } from "./line";
-import { pointFrom } from "./point";
+import { line, linesIntersectAt } from "../src/line";
+import { pointFrom } from "../src/point";
describe("line-line intersections", () => {
it("should correctly detect intersection at origin", () => {
diff --git a/packages/math/point.test.ts b/packages/math/tests/point.test.ts
similarity index 84%
rename from packages/math/point.test.ts
rename to packages/math/tests/point.test.ts
index 0ed59ee9ab..3f3ee15cd5 100644
--- a/packages/math/point.test.ts
+++ b/packages/math/tests/point.test.ts
@@ -1,6 +1,6 @@
-import { pointFrom, pointRotateRads } from "./point";
+import { pointFrom, pointRotateRads } from "../src/point";
-import type { Radians } from "./types";
+import type { Radians } from "../src/types";
describe("rotate", () => {
it("should rotate over (x2, y2) and return the rotated coordinates for (x1, y1)", () => {
diff --git a/packages/math/range.test.ts b/packages/math/tests/range.test.ts
similarity index 99%
rename from packages/math/range.test.ts
rename to packages/math/tests/range.test.ts
index fb4b6a38d3..9808f77f41 100644
--- a/packages/math/range.test.ts
+++ b/packages/math/tests/range.test.ts
@@ -1,4 +1,4 @@
-import { rangeInclusive, rangeIntersection, rangesOverlap } from "./range";
+import { rangeInclusive, rangeIntersection, rangesOverlap } from "../src/range";
describe("range overlap", () => {
const range1_4 = rangeInclusive(1, 4);
diff --git a/packages/math/segment.test.ts b/packages/math/tests/segment.test.ts
similarity index 82%
rename from packages/math/segment.test.ts
rename to packages/math/tests/segment.test.ts
index 4237a3c855..6b29bba591 100644
--- a/packages/math/segment.test.ts
+++ b/packages/math/tests/segment.test.ts
@@ -1,5 +1,5 @@
-import { pointFrom } from "./point";
-import { lineSegment, lineSegmentIntersectionPoints } from "./segment";
+import { pointFrom } from "../src/point";
+import { lineSegment, lineSegmentIntersectionPoints } from "../src/segment";
describe("line-segment intersections", () => {
it("should correctly detect intersection", () => {
diff --git a/packages/math/vector.test.ts b/packages/math/tests/vector.test.ts
similarity index 88%
rename from packages/math/vector.test.ts
rename to packages/math/tests/vector.test.ts
index 145c909535..820f604003 100644
--- a/packages/math/vector.test.ts
+++ b/packages/math/tests/vector.test.ts
@@ -1,4 +1,4 @@
-import { isVector } from ".";
+import { isVector } from "../src/vector";
describe("Vector", () => {
test("isVector", () => {
diff --git a/packages/math/tsconfig.json b/packages/math/tsconfig.json
index f61b8d0af4..82cc2c2377 100644
--- a/packages/math/tsconfig.json
+++ b/packages/math/tsconfig.json
@@ -1,24 +1,6 @@
{
+ "extends": "../tsconfig.base.json",
"compilerOptions": {
- "outDir": "./dist/types",
- "target": "ESNext",
- "strict": true,
- "skipLibCheck": true,
- "declaration": true,
- "allowSyntheticDefaultImports": true,
- "module": "ESNext",
- "moduleResolution": "Node",
- "resolveJsonModule": true,
- "jsx": "react-jsx",
- "emitDeclarationOnly": true,
- "paths": {
- "@excalidraw/excalidraw": ["../excalidraw/index.tsx"],
- "@excalidraw/utils": ["../utils/index.ts"],
- "@excalidraw/math": ["../math/index.ts"],
- "@excalidraw/excalidraw/*": ["../excalidraw/*"],
- "@excalidraw/utils/*": ["../utils/*"],
- "@excalidraw/math/*": ["../math/*"]
- }
- },
- "exclude": ["**/*.test.*", "tests", "types", "examples", "dist"]
+ "outDir": "./dist/types"
+ }
}
diff --git a/packages/tsconfig.base.json b/packages/tsconfig.base.json
new file mode 100644
index 0000000000..18f7fcb361
--- /dev/null
+++ b/packages/tsconfig.base.json
@@ -0,0 +1,27 @@
+{
+ "compilerOptions": {
+ "target": "ESNext",
+ "strict": true,
+ "skipLibCheck": true,
+ "declaration": true,
+ "allowSyntheticDefaultImports": true,
+ "module": "ESNext",
+ "moduleResolution": "Node",
+ "resolveJsonModule": true,
+ "jsx": "react-jsx",
+ "emitDeclarationOnly": true,
+ "paths": {
+ "@excalidraw/common": ["./common/src/index.ts"],
+ "@excalidraw/common/*": ["./common/src/*"],
+ "@excalidraw/element": ["./element/src/index.ts"],
+ "@excalidraw/element/*": ["./element/src/*"],
+ "@excalidraw/excalidraw": ["./excalidraw/index.tsx"],
+ "@excalidraw/excalidraw/*": ["./excalidraw/*"],
+ "@excalidraw/math": ["./math/src/index.ts"],
+ "@excalidraw/math/*": ["./math/src/*"],
+ "@excalidraw/utils": ["./utils/src/index.ts"],
+ "@excalidraw/utils/*": ["./utils/src/*"]
+ }
+ },
+ "exclude": ["**/*.test.*", "tests", "types", "examples", "dist"]
+}
diff --git a/packages/utils/bbox.ts b/packages/utils/src/bbox.ts
similarity index 96%
rename from packages/utils/bbox.ts
rename to packages/utils/src/bbox.ts
index 61c75a6687..a561281563 100644
--- a/packages/utils/bbox.ts
+++ b/packages/utils/src/bbox.ts
@@ -5,7 +5,7 @@ import {
type LocalPoint,
} from "@excalidraw/math";
-import type { Bounds } from "@excalidraw/excalidraw/element/bounds";
+import type { Bounds } from "@excalidraw/element/bounds";
export type LineSegment = [P, P];
diff --git a/packages/utils/collision.ts b/packages/utils/src/collision.ts
similarity index 96%
rename from packages/utils/collision.ts
rename to packages/utils/src/collision.ts
index f90019418e..b7c155f663 100644
--- a/packages/utils/collision.ts
+++ b/packages/utils/src/collision.ts
@@ -12,13 +12,9 @@ import {
import type { Curve } from "@excalidraw/math";
-import {
- pointInEllipse,
- pointOnEllipse,
- type GeometricShape,
-} from "./geometry/shape";
+import { pointInEllipse, pointOnEllipse } from "./shape";
-import type { Polycurve, Polyline } from "./geometry/shape";
+import type { Polycurve, Polyline, GeometricShape } from "./shape";
// check if the given point is considered on the given shape's border
export const isPointOnShape = (
diff --git a/packages/utils/export.ts b/packages/utils/src/export.ts
similarity index 98%
rename from packages/utils/export.ts
rename to packages/utils/src/export.ts
index 6de25c62bf..4559fe1af8 100644
--- a/packages/utils/export.ts
+++ b/packages/utils/src/export.ts
@@ -1,10 +1,10 @@
+import { MIME_TYPES } from "@excalidraw/common";
import { getDefaultAppState } from "@excalidraw/excalidraw/appState";
import {
copyBlobToClipboardAsPng,
copyTextToSystemClipboard,
copyToClipboard,
} from "@excalidraw/excalidraw/clipboard";
-import { MIME_TYPES } from "@excalidraw/excalidraw/constants";
import { encodePngMetadata } from "@excalidraw/excalidraw/data/image";
import { serializeAsJSON } from "@excalidraw/excalidraw/data/json";
import { restore } from "@excalidraw/excalidraw/data/restore";
@@ -17,7 +17,7 @@ import type {
ExcalidrawElement,
ExcalidrawFrameLikeElement,
NonDeleted,
-} from "@excalidraw/excalidraw/element/types";
+} from "@excalidraw/element/types";
import type { AppState, BinaryFiles } from "@excalidraw/excalidraw/types";
export { MIME_TYPES };
diff --git a/packages/utils/index.ts b/packages/utils/src/index.ts
similarity index 52%
rename from packages/utils/index.ts
rename to packages/utils/src/index.ts
index 2a929134e4..58830b356d 100644
--- a/packages/utils/index.ts
+++ b/packages/utils/src/index.ts
@@ -1,4 +1,4 @@
export * from "./export";
export * from "./withinBounds";
export * from "./bbox";
-export { getCommonBounds } from "@excalidraw/excalidraw/element/bounds";
+export { getCommonBounds } from "@excalidraw/element/bounds";
diff --git a/packages/utils/geometry/shape.ts b/packages/utils/src/shape.ts
similarity index 98%
rename from packages/utils/geometry/shape.ts
rename to packages/utils/src/shape.ts
index ea3cde3f60..b750c232e7 100644
--- a/packages/utils/geometry/shape.ts
+++ b/packages/utils/src/shape.ts
@@ -11,9 +11,9 @@
* also included in this file are methods for converting an Excalidraw element or a Drawable from roughjs
* to pure shapes
*/
+import { pointsOnBezierCurves } from "points-on-curve";
-import { getElementAbsoluteCoords } from "@excalidraw/excalidraw/element";
-import { invariant } from "@excalidraw/excalidraw/utils";
+import { invariant } from "@excalidraw/common";
import {
curve,
lineSegment,
@@ -33,7 +33,8 @@ import {
type GlobalPoint,
type LocalPoint,
} from "@excalidraw/math";
-import { pointsOnBezierCurves } from "points-on-curve";
+
+import { getElementAbsoluteCoords } from "@excalidraw/element/bounds";
import type {
ElementsMap,
@@ -50,7 +51,7 @@ import type {
ExcalidrawRectangleElement,
ExcalidrawSelectionElement,
ExcalidrawTextElement,
-} from "@excalidraw/excalidraw/element/types";
+} from "@excalidraw/element/types";
import type { Curve, LineSegment, Polygon, Radians } from "@excalidraw/math";
import type { Drawable, Op } from "roughjs/bin/core";
diff --git a/packages/utils/test-utils.ts b/packages/utils/src/test-utils.ts
similarity index 100%
rename from packages/utils/test-utils.ts
rename to packages/utils/src/test-utils.ts
diff --git a/packages/utils/withinBounds.ts b/packages/utils/src/withinBounds.ts
similarity index 94%
rename from packages/utils/withinBounds.ts
rename to packages/utils/src/withinBounds.ts
index 71bc78969d..0e1cf38a61 100644
--- a/packages/utils/withinBounds.ts
+++ b/packages/utils/src/withinBounds.ts
@@ -1,12 +1,12 @@
-import { getElementBounds } from "@excalidraw/excalidraw/element/bounds";
+import { arrayToMap } from "@excalidraw/common";
+import { getElementBounds } from "@excalidraw/element/bounds";
import {
isArrowElement,
isExcalidrawElement,
isFreeDrawElement,
isLinearElement,
isTextElement,
-} from "@excalidraw/excalidraw/element/typeChecks";
-import { arrayToMap } from "@excalidraw/excalidraw/utils";
+} from "@excalidraw/element/typeChecks";
import {
rangeIncludesValue,
pointFrom,
@@ -14,13 +14,13 @@ import {
rangeInclusive,
} from "@excalidraw/math";
-import type { Bounds } from "@excalidraw/excalidraw/element/bounds";
+import type { Bounds } from "@excalidraw/element/bounds";
import type {
ExcalidrawElement,
ExcalidrawFreeDrawElement,
ExcalidrawLinearElement,
NonDeletedExcalidrawElement,
-} from "@excalidraw/excalidraw/element/types";
+} from "@excalidraw/element/types";
import type { LocalPoint } from "@excalidraw/math";
type Element = NonDeletedExcalidrawElement;
diff --git a/packages/utils/__snapshots__/export.test.ts.snap b/packages/utils/tests/__snapshots__/export.test.ts.snap
similarity index 100%
rename from packages/utils/__snapshots__/export.test.ts.snap
rename to packages/utils/tests/__snapshots__/export.test.ts.snap
diff --git a/packages/utils/__snapshots__/utils.test.ts.snap b/packages/utils/tests/__snapshots__/utils.test.ts.snap
similarity index 100%
rename from packages/utils/__snapshots__/utils.test.ts.snap
rename to packages/utils/tests/__snapshots__/utils.test.ts.snap
diff --git a/packages/utils/collision.test.ts b/packages/utils/tests/collision.test.ts
similarity index 96%
rename from packages/utils/collision.test.ts
rename to packages/utils/tests/collision.test.ts
index 24f96e9857..35bc28b34e 100644
--- a/packages/utils/collision.test.ts
+++ b/packages/utils/tests/collision.test.ts
@@ -9,9 +9,9 @@ import {
import type { Curve, Degrees, GlobalPoint } from "@excalidraw/math";
-import { pointOnCurve, pointOnPolyline } from "./collision";
+import { pointOnCurve, pointOnPolyline } from "../src/collision";
-import type { Polyline } from "./geometry/shape";
+import type { Polyline } from "../src/shape";
describe("point and curve", () => {
const c: Curve = curve(
diff --git a/packages/utils/export.test.ts b/packages/utils/tests/export.test.ts
similarity index 97%
rename from packages/utils/export.test.ts
rename to packages/utils/tests/export.test.ts
index 86bbe80b7f..47b9398ab7 100644
--- a/packages/utils/export.test.ts
+++ b/packages/utils/tests/export.test.ts
@@ -1,9 +1,9 @@
-import { MIME_TYPES } from "@excalidraw/excalidraw/constants";
+import { MIME_TYPES } from "@excalidraw/common";
import * as mockedSceneExportUtils from "@excalidraw/excalidraw/scene/export";
import { diagramFactory } from "@excalidraw/excalidraw/tests/fixtures/diagramFixture";
import { vi } from "vitest";
-import * as utils from ".";
+import * as utils from "../src";
const exportToSvgSpy = vi.spyOn(mockedSceneExportUtils, "exportToSvg");
diff --git a/packages/utils/geometry/geometry.test.ts b/packages/utils/tests/geometry.test.ts
similarity index 98%
rename from packages/utils/geometry/geometry.test.ts
rename to packages/utils/tests/geometry.test.ts
index 6ddab71b0a..8a2f95d3fc 100644
--- a/packages/utils/geometry/geometry.test.ts
+++ b/packages/utils/tests/geometry.test.ts
@@ -15,7 +15,7 @@ import type {
Radians,
} from "@excalidraw/math";
-import { pointInEllipse, pointOnEllipse, type Ellipse } from "./shape";
+import { pointInEllipse, pointOnEllipse, type Ellipse } from "../src/shape";
describe("point and line", () => {
// const l: Line = line(point(1, 0), point(1, 2));
diff --git a/packages/utils/utils.unmocked.test.ts b/packages/utils/tests/utils.unmocked.test.ts
similarity index 98%
rename from packages/utils/utils.unmocked.test.ts
rename to packages/utils/tests/utils.unmocked.test.ts
index 417eabda1e..b77bc37d1c 100644
--- a/packages/utils/utils.unmocked.test.ts
+++ b/packages/utils/tests/utils.unmocked.test.ts
@@ -4,7 +4,7 @@ import { API } from "@excalidraw/excalidraw/tests/helpers/api";
import type { ImportedDataState } from "@excalidraw/excalidraw/data/types";
-import * as utils from "./index";
+import * as utils from "../src";
// NOTE this test file is using the actual API, unmocked. Hence splitting it
// from the other test file, because I couldn't figure out how to test
diff --git a/packages/utils/withinBounds.test.ts b/packages/utils/tests/withinBounds.test.ts
similarity index 98%
rename from packages/utils/withinBounds.test.ts
rename to packages/utils/tests/withinBounds.test.ts
index b07d0bc338..d1af75de86 100644
--- a/packages/utils/withinBounds.test.ts
+++ b/packages/utils/tests/withinBounds.test.ts
@@ -1,12 +1,12 @@
import { API } from "@excalidraw/excalidraw/tests/helpers/api";
-import type { Bounds } from "@excalidraw/excalidraw/element/bounds";
+import type { Bounds } from "@excalidraw/element/bounds";
import {
elementPartiallyOverlapsWithOrContainsBBox,
elementsOverlappingBBox,
isElementInsideBBox,
-} from "./withinBounds";
+} from "../src/withinBounds";
const makeElement = (x: number, y: number, width: number, height: number) =>
API.createElement({
diff --git a/packages/utils/tsconfig.json b/packages/utils/tsconfig.json
index f61b8d0af4..82cc2c2377 100644
--- a/packages/utils/tsconfig.json
+++ b/packages/utils/tsconfig.json
@@ -1,24 +1,6 @@
{
+ "extends": "../tsconfig.base.json",
"compilerOptions": {
- "outDir": "./dist/types",
- "target": "ESNext",
- "strict": true,
- "skipLibCheck": true,
- "declaration": true,
- "allowSyntheticDefaultImports": true,
- "module": "ESNext",
- "moduleResolution": "Node",
- "resolveJsonModule": true,
- "jsx": "react-jsx",
- "emitDeclarationOnly": true,
- "paths": {
- "@excalidraw/excalidraw": ["../excalidraw/index.tsx"],
- "@excalidraw/utils": ["../utils/index.ts"],
- "@excalidraw/math": ["../math/index.ts"],
- "@excalidraw/excalidraw/*": ["../excalidraw/*"],
- "@excalidraw/utils/*": ["../utils/*"],
- "@excalidraw/math/*": ["../math/*"]
- }
- },
- "exclude": ["**/*.test.*", "tests", "types", "examples", "dist"]
+ "outDir": "./dist/types"
+ }
}
diff --git a/scripts/buildMath.js b/scripts/buildBase.js
similarity index 77%
rename from scripts/buildMath.js
rename to scripts/buildBase.js
index ba421b48cb..336b498235 100644
--- a/scripts/buildMath.js
+++ b/scripts/buildBase.js
@@ -1,27 +1,27 @@
const path = require("path");
const { build } = require("esbuild");
-const { sassPlugin } = require("esbuild-sass-plugin");
// contains all dependencies bundled inside
const getConfig = (outdir) => ({
outdir,
bundle: true,
format: "esm",
- entryPoints: ["index.ts"],
+ entryPoints: ["src/index.ts"],
entryNames: "[name]",
assetNames: "[dir]/[name]",
alias: {
+ "@excalidraw/common": path.resolve(__dirname, "../packages/common/src"),
+ "@excalidraw/element": path.resolve(__dirname, "../packages/element/src"),
"@excalidraw/excalidraw": path.resolve(__dirname, "../packages/excalidraw"),
- "@excalidraw/utils": path.resolve(__dirname, "../packages/utils"),
- "@excalidraw/math": path.resolve(__dirname, "../packages/math"),
+ "@excalidraw/math": path.resolve(__dirname, "../packages/math/src"),
+ "@excalidraw/utils": path.resolve(__dirname, "../packages/utils/src"),
},
});
function buildDev(config) {
return build({
...config,
- plugins: [sassPlugin()],
sourcemap: true,
define: {
"import.meta.env": JSON.stringify({ DEV: true }),
@@ -32,7 +32,6 @@ function buildDev(config) {
function buildProd(config) {
return build({
...config,
- plugins: [sassPlugin()],
minify: true,
define: {
"import.meta.env": JSON.stringify({ PROD: true }),
@@ -42,10 +41,10 @@ function buildProd(config) {
const createESMRawBuild = async () => {
// development unminified build with source maps
- buildDev(getConfig("dist/dev"));
+ await buildDev(getConfig("dist/dev"));
// production minified build without sourcemaps
- buildProd(getConfig("dist/prod"));
+ await buildProd(getConfig("dist/prod"));
};
(async () => {
diff --git a/scripts/buildPackage.js b/scripts/buildPackage.js
index 3dd15eecae..baf20615f6 100644
--- a/scripts/buildPackage.js
+++ b/scripts/buildPackage.js
@@ -28,9 +28,11 @@ const getConfig = (outdir) => ({
assetNames: "[dir]/[name]",
chunkNames: "[dir]/[name]-[hash]",
alias: {
+ "@excalidraw/common": path.resolve(__dirname, "../packages/common/src"),
+ "@excalidraw/element": path.resolve(__dirname, "../packages/element/src"),
"@excalidraw/excalidraw": path.resolve(__dirname, "../packages/excalidraw"),
- "@excalidraw/utils": path.resolve(__dirname, "../packages/utils"),
- "@excalidraw/math": path.resolve(__dirname, "../packages/math"),
+ "@excalidraw/math": path.resolve(__dirname, "../packages/math/src"),
+ "@excalidraw/utils": path.resolve(__dirname, "../packages/utils/src"),
},
loader: {
".woff2": "file",
diff --git a/scripts/buildUtils.js b/scripts/buildUtils.js
index b5718f57e0..1cf3ffbaaf 100644
--- a/scripts/buildUtils.js
+++ b/scripts/buildUtils.js
@@ -10,13 +10,15 @@ const getConfig = (outdir) => ({
outdir,
bundle: true,
format: "esm",
- entryPoints: ["index.ts"],
+ entryPoints: ["src/index.ts"],
entryNames: "[name]",
assetNames: "[dir]/[name]",
alias: {
+ "@excalidraw/common": path.resolve(__dirname, "../packages/common/src"),
+ "@excalidraw/element": path.resolve(__dirname, "../packages/element/src"),
"@excalidraw/excalidraw": path.resolve(__dirname, "../packages/excalidraw"),
- "@excalidraw/utils": path.resolve(__dirname, "../packages/utils"),
- "@excalidraw/math": path.resolve(__dirname, "../packages/math"),
+ "@excalidraw/math": path.resolve(__dirname, "../packages/math/src"),
+ "@excalidraw/utils": path.resolve(__dirname, "../packages/utils/src"),
},
});
@@ -49,10 +51,10 @@ function buildProd(config) {
const createESMRawBuild = async () => {
// development unminified build with source maps
- buildDev(getConfig("dist/dev"));
+ await buildDev(getConfig("dist/dev"));
// production minified build without sourcemaps
- buildProd(getConfig("dist/prod"));
+ await buildProd(getConfig("dist/prod"));
};
(async () => {
diff --git a/tsconfig.json b/tsconfig.json
index 3eded705f5..45a29dd618 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -19,12 +19,16 @@
"jsx": "react-jsx",
"baseUrl": ".",
"paths": {
+ "@excalidraw/common": ["./packages/common/src/index.ts"],
+ "@excalidraw/common/*": ["./packages/common/src/*"],
"@excalidraw/excalidraw": ["./packages/excalidraw/index.tsx"],
- "@excalidraw/utils": ["./packages/utils/index.ts"],
- "@excalidraw/math": ["./packages/math/index.ts"],
"@excalidraw/excalidraw/*": ["./packages/excalidraw/*"],
- "@excalidraw/utils/*": ["./packages/utils/*"],
- "@excalidraw/math/*": ["./packages/math/*"]
+ "@excalidraw/element": ["./packages/element/src/index.ts"],
+ "@excalidraw/element/*": ["./packages/element/src/*"],
+ "@excalidraw/math": ["./packages/math/src/index.ts"],
+ "@excalidraw/math/*": ["./packages/math/src/*"],
+ "@excalidraw/utils": ["./packages/utils/src/index.ts"],
+ "@excalidraw/utils/*": ["./packages/utils/src/*"]
}
},
"include": ["packages", "excalidraw-app"],
diff --git a/vitest.config.mts b/vitest.config.mts
index f9d7d255ee..353f84ccfc 100644
--- a/vitest.config.mts
+++ b/vitest.config.mts
@@ -5,6 +5,22 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
resolve: {
alias: [
+ {
+ find: /^@excalidraw\/common$/,
+ replacement: path.resolve(__dirname, "./packages/common/src/index.ts"),
+ },
+ {
+ find: /^@excalidraw\/common\/(.*?)/,
+ replacement: path.resolve(__dirname, "./packages/common/src/$1"),
+ },
+ {
+ find: /^@excalidraw\/element$/,
+ replacement: path.resolve(__dirname, "./packages/element/src/index.ts"),
+ },
+ {
+ find: /^@excalidraw\/element\/(.*?)/,
+ replacement: path.resolve(__dirname, "./packages/element/src/$1"),
+ },
{
find: /^@excalidraw\/excalidraw$/,
replacement: path.resolve(__dirname, "./packages/excalidraw/index.tsx"),
@@ -13,21 +29,21 @@ export default defineConfig({
find: /^@excalidraw\/excalidraw\/(.*?)/,
replacement: path.resolve(__dirname, "./packages/excalidraw/$1"),
},
- {
- find: /^@excalidraw\/utils$/,
- replacement: path.resolve(__dirname, "./packages/utils/index.ts"),
- },
- {
- find: /^@excalidraw\/utils\/(.*?)/,
- replacement: path.resolve(__dirname, "./packages/utils/$1"),
- },
{
find: /^@excalidraw\/math$/,
- replacement: path.resolve(__dirname, "./packages/math/index.ts"),
+ replacement: path.resolve(__dirname, "./packages/math/src/index.ts"),
},
{
find: /^@excalidraw\/math\/(.*?)/,
- replacement: path.resolve(__dirname, "./packages/math/$1"),
+ replacement: path.resolve(__dirname, "./packages/math/src/$1"),
+ },
+ {
+ find: /^@excalidraw\/utils$/,
+ replacement: path.resolve(__dirname, "./packages/utils/src/index.ts"),
+ },
+ {
+ find: /^@excalidraw\/utils\/(.*?)/,
+ replacement: path.resolve(__dirname, "./packages/utils/src/$1"),
},
],
},