diff --git a/excalidraw-app/vite.config.mts b/excalidraw-app/vite.config.mts index 627b75710..f10e742f5 100644 --- a/excalidraw-app/vite.config.mts +++ b/excalidraw-app/vite.config.mts @@ -47,14 +47,6 @@ export default defineConfig(({ mode }) => { 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/src/index.ts"), @@ -63,6 +55,14 @@ export default defineConfig(({ mode }) => { find: /^@excalidraw\/math\/(.*?)/, 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"), + }, ], }, build: { diff --git a/packages/element/src/bounds.ts b/packages/element/src/bounds.ts index 8cf04c4cd..bab1a1871 100644 --- a/packages/element/src/bounds.ts +++ b/packages/element/src/bounds.ts @@ -11,7 +11,7 @@ import { pointRotateRads, } from "@excalidraw/math"; -import { getCurvePathOps } from "@excalidraw/utils/geometry/shape"; +import { getCurvePathOps } from "@excalidraw/utils/shape"; import type { Degrees, diff --git a/packages/element/src/collision.ts b/packages/element/src/collision.ts index 258c0dbc8..1c830b6f3 100644 --- a/packages/element/src/collision.ts +++ b/packages/element/src/collision.ts @@ -16,7 +16,7 @@ import { } from "@excalidraw/math/ellipse"; import { isPointInShape, isPointOnShape } from "@excalidraw/utils/collision"; -import { getPolygonShape } from "@excalidraw/utils/geometry/shape"; +import { getPolygonShape } from "@excalidraw/utils/shape"; import type { GlobalPoint, @@ -26,7 +26,7 @@ import type { Radians, } from "@excalidraw/math"; -import type { GeometricShape } from "@excalidraw/utils/geometry/shape"; +import type { GeometricShape } from "@excalidraw/utils/shape"; import type { FrameNameBounds } from "@excalidraw/excalidraw/types"; diff --git a/packages/element/src/linearElementEditor.ts b/packages/element/src/linearElementEditor.ts index 3f157f3d8..b960ab4b4 100644 --- a/packages/element/src/linearElementEditor.ts +++ b/packages/element/src/linearElementEditor.ts @@ -9,7 +9,7 @@ import { vectorFromPoint, } from "@excalidraw/math"; -import { getCurvePathOps } from "@excalidraw/utils/geometry/shape"; +import { getCurvePathOps } from "@excalidraw/utils/shape"; import { DRAGGING_THRESHOLD, @@ -20,7 +20,7 @@ import { tupleToCoors, } from "@excalidraw/common"; -// TODO: remove the dependency on the scene +// TODO: remove direct dependency on the scene, should be passed in or injected instead import Scene from "@excalidraw/excalidraw/scene/Scene"; import type { Store } from "@excalidraw/excalidraw/store"; diff --git a/packages/element/src/mutateElement.ts b/packages/element/src/mutateElement.ts index 7de80ef43..5cff9a58a 100644 --- a/packages/element/src/mutateElement.ts +++ b/packages/element/src/mutateElement.ts @@ -5,7 +5,7 @@ import { toBrandedType, } from "@excalidraw/common"; -// TODO_SEP: should be passed in or injected instead +// TODO: remove direct dependency on the scene, should be passed in or injected instead import Scene from "@excalidraw/excalidraw/scene/Scene"; import type { Radians } from "@excalidraw/math"; diff --git a/packages/element/src/shapes.ts b/packages/element/src/shapes.ts index 43b06ad98..1d6e13340 100644 --- a/packages/element/src/shapes.ts +++ b/packages/element/src/shapes.ts @@ -23,7 +23,7 @@ import { getFreedrawShape, getPolygonShape, type GeometricShape, -} from "@excalidraw/utils/geometry/shape"; +} from "@excalidraw/utils/shape"; import type { NormalizedZoomValue, Zoom } from "@excalidraw/excalidraw/types"; diff --git a/packages/element/tests/elbowArrow.test.tsx b/packages/element/tests/elbowArrow.test.tsx index eb50249d4..b8b5a8b85 100644 --- a/packages/element/tests/elbowArrow.test.tsx +++ b/packages/element/tests/elbowArrow.test.tsx @@ -17,12 +17,12 @@ import { render, } from "@excalidraw/excalidraw/tests/test-utils"; +import "@excalidraw/utils/test-utils"; + import type { LocalPoint } from "@excalidraw/math"; import { bindLinearElement } from "../src/binding"; -import "../../utils/test-utils"; - import type { ExcalidrawArrowElement, ExcalidrawBindableElement, diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx index ef8fdd48a..f8f15e81b 100644 --- a/packages/excalidraw/components/App.tsx +++ b/packages/excalidraw/components/App.tsx @@ -18,7 +18,7 @@ import { vectorNormalize, } from "@excalidraw/math"; import { isPointInShape } from "@excalidraw/utils/collision"; -import { getSelectionBoxShape } from "@excalidraw/utils/geometry/shape"; +import { getSelectionBoxShape } from "@excalidraw/utils/shape"; import { COLOR_PALETTE, diff --git a/packages/excalidraw/components/UserList.scss b/packages/excalidraw/components/UserList.scss index fdcadef7e..025f4d16e 100644 --- a/packages/excalidraw/components/UserList.scss +++ b/packages/excalidraw/components/UserList.scss @@ -1,4 +1,4 @@ -@import "../css/variables.module"; +@import "../css/variables.module.scss"; .excalidraw { --avatar-size: 1.75rem; diff --git a/packages/excalidraw/tests/history.test.tsx b/packages/excalidraw/tests/history.test.tsx index c26204f3a..8dd65c7a5 100644 --- a/packages/excalidraw/tests/history.test.tsx +++ b/packages/excalidraw/tests/history.test.tsx @@ -21,6 +21,8 @@ import { DEFAULT_ELEMENT_STROKE_COLOR_INDEX, } from "@excalidraw/common"; +import "@excalidraw/utils/test-utils"; + import type { LocalPoint, Radians } from "@excalidraw/math"; import type { @@ -35,7 +37,6 @@ import type { } from "@excalidraw/element/types"; import "../global.d.ts"; -import "../../utils/test-utils"; import { actionSendBackward, diff --git a/packages/excalidraw/tests/move.test.tsx b/packages/excalidraw/tests/move.test.tsx index 823056da8..cf05e072d 100644 --- a/packages/excalidraw/tests/move.test.tsx +++ b/packages/excalidraw/tests/move.test.tsx @@ -5,6 +5,8 @@ import { bindOrUnbindLinearElement } from "@excalidraw/element/binding"; import { KEYS, reseed } from "@excalidraw/common"; +import "@excalidraw/utils/test-utils"; + import type { ExcalidrawLinearElement, NonDeleted, @@ -17,7 +19,6 @@ import { Excalidraw } from "../index"; import * as InteractiveCanvas from "../renderer/interactiveScene"; import * as StaticScene from "../renderer/staticScene"; -import "../../utils/test-utils"; import { UI, Pointer, Keyboard } from "./helpers/ui"; import { render, fireEvent, act, unmountComponent } from "./test-utils"; diff --git a/packages/math/tests/curve.test.ts b/packages/math/tests/curve.test.ts index 753ab5bef..739562096 100644 --- a/packages/math/tests/curve.test.ts +++ b/packages/math/tests/curve.test.ts @@ -1,4 +1,4 @@ -import "../../utils/test-utils"; +import "@excalidraw/utils/test-utils"; import { curve, diff --git a/packages/tsconfig.base.json b/packages/tsconfig.base.json index cde00d3fc..18f7fcb36 100644 --- a/packages/tsconfig.base.json +++ b/packages/tsconfig.base.json @@ -19,8 +19,8 @@ "@excalidraw/excalidraw/*": ["./excalidraw/*"], "@excalidraw/math": ["./math/src/index.ts"], "@excalidraw/math/*": ["./math/src/*"], - "@excalidraw/utils": ["./utils/index.ts"], - "@excalidraw/utils/*": ["./utils/*"] + "@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 100% rename from packages/utils/bbox.ts rename to packages/utils/src/bbox.ts 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 f90019418..47431511b 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, type GeometricShape } from "./shape"; -import type { Polycurve, Polyline } from "./geometry/shape"; +import type { Polycurve, Polyline } 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 100% rename from packages/utils/export.ts rename to packages/utils/src/export.ts diff --git a/packages/utils/index.ts b/packages/utils/src/index.ts similarity index 100% rename from packages/utils/index.ts rename to packages/utils/src/index.ts diff --git a/packages/utils/geometry/shape.ts b/packages/utils/src/shape.ts similarity index 100% rename from packages/utils/geometry/shape.ts rename to packages/utils/src/shape.ts 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 100% rename from packages/utils/withinBounds.ts rename to packages/utils/src/withinBounds.ts 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 24f96e985..35bc28b34 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 99% rename from packages/utils/export.test.ts rename to packages/utils/tests/export.test.ts index 8566315b6..47b9398ab 100644 --- a/packages/utils/export.test.ts +++ b/packages/utils/tests/export.test.ts @@ -3,7 +3,7 @@ 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 6ddab71b0..8a2f95d3f 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 417eabda1..b77bc37d1 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 99% rename from packages/utils/withinBounds.test.ts rename to packages/utils/tests/withinBounds.test.ts index bbc0aa62a..d1af75de8 100644 --- a/packages/utils/withinBounds.test.ts +++ b/packages/utils/tests/withinBounds.test.ts @@ -6,7 +6,7 @@ import { elementPartiallyOverlapsWithOrContainsBBox, elementsOverlappingBBox, isElementInsideBBox, -} from "./withinBounds"; +} from "../src/withinBounds"; const makeElement = (x: number, y: number, width: number, height: number) => API.createElement({ diff --git a/scripts/buildPackage.js b/scripts/buildPackage.js index bfe96ddc2..baf20615f 100644 --- a/scripts/buildPackage.js +++ b/scripts/buildPackage.js @@ -32,7 +32,7 @@ const getConfig = (outdir) => ({ "@excalidraw/element": path.resolve(__dirname, "../packages/element/src"), "@excalidraw/excalidraw": path.resolve(__dirname, "../packages/excalidraw"), "@excalidraw/math": path.resolve(__dirname, "../packages/math/src"), - "@excalidraw/utils": path.resolve(__dirname, "../packages/utils"), + "@excalidraw/utils": path.resolve(__dirname, "../packages/utils/src"), }, loader: { ".woff2": "file", diff --git a/scripts/buildShared.js b/scripts/buildShared.js index 19ac5d049..01db34c24 100644 --- a/scripts/buildShared.js +++ b/scripts/buildShared.js @@ -10,7 +10,7 @@ const getConfig = (outdir) => ({ outdir, bundle: true, format: "esm", - entryPoints: ["index.ts"], + entryPoints: ["src/index.ts"], entryNames: "[name]", assetNames: "[dir]/[name]", alias: { @@ -18,7 +18,7 @@ const getConfig = (outdir) => ({ "@excalidraw/element": path.resolve(__dirname, "../packages/element/src"), "@excalidraw/excalidraw": path.resolve(__dirname, "../packages/excalidraw"), "@excalidraw/math": path.resolve(__dirname, "../packages/math/src"), - "@excalidraw/utils": path.resolve(__dirname, "../packages/utils"), + "@excalidraw/utils": path.resolve(__dirname, "../packages/utils/src"), }, }); diff --git a/tsconfig.json b/tsconfig.json index 1cde33248..45a29dd61 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,8 +27,8 @@ "@excalidraw/element/*": ["./packages/element/src/*"], "@excalidraw/math": ["./packages/math/src/index.ts"], "@excalidraw/math/*": ["./packages/math/src/*"], - "@excalidraw/utils": ["./packages/utils/index.ts"], - "@excalidraw/utils/*": ["./packages/utils/*"] + "@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 4f230090e..353f84ccf 100644 --- a/vitest.config.mts +++ b/vitest.config.mts @@ -29,14 +29,6 @@ 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/src/index.ts"), @@ -45,6 +37,14 @@ export default defineConfig({ find: /^@excalidraw\/math\/(.*?)/, 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"), + }, ], }, //@ts-ignore