(
...points: Point[]
) {
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 d90530cba..1b292344e 100644
--- a/packages/math/range.ts
+++ b/packages/math/src/range.ts
@@ -1,4 +1,5 @@
-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 99%
rename from packages/math/rectangle.ts
rename to packages/math/src/rectangle.ts
index 7dde15ded..394b5c2f8 100644
--- a/packages/math/rectangle.ts
+++ b/packages/math/src/rectangle.ts
@@ -1,5 +1,6 @@
import { pointFrom } from "./point";
import { lineSegment, lineSegmentIntersectionPoints } from "./segment";
+
import type { GlobalPoint, LineSegment, LocalPoint, Rectangle } from "./types";
export function rectangle(
diff --git a/packages/math/segment.ts b/packages/math/src/segment.ts
similarity index 99%
rename from packages/math/segment.ts
rename to packages/math/src/segment.ts
index 60943aacb..e38978b7e 100644
--- a/packages/math/segment.ts
+++ b/packages/math/src/segment.ts
@@ -5,7 +5,6 @@ import {
pointFromVector,
pointRotateRads,
} from "./point";
-import type { GlobalPoint, LineSegment, LocalPoint, Radians } from "./types";
import { PRECISION } from "./utils";
import {
vectorAdd,
@@ -15,6 +14,8 @@ import {
vectorSubtract,
} from "./vector";
+import type { GlobalPoint, LineSegment, LocalPoint, Radians } from "./types";
+
/**
* Create a line segment from two points.
*
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 94670d7ab..739562096 100644
--- a/packages/math/curve.test.ts
+++ b/packages/math/tests/curve.test.ts
@@ -1,12 +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 507cc5a1a..4fa0d4e59 100644
--- a/packages/math/ellipse.test.ts
+++ b/packages/math/tests/ellipse.test.ts
@@ -4,11 +4,12 @@ import {
ellipseIncludesPoint,
ellipseTouchesPoint,
ellipseLineIntersectionPoints,
-} from "./ellipse";
-import { line } from "./line";
-import { pointFrom } from "./point";
-import { lineSegment } from "./segment";
-import type { Ellipse, GlobalPoint } from "./types";
+} from "../src/ellipse";
+import { line } from "../src/line";
+import { pointFrom } from "../src/point";
+import { lineSegment } from "../src/segment";
+
+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 0e6bb1cc8..c8915a466 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 89cc4f8f3..3f3ee15cd 100644
--- a/packages/math/point.test.ts
+++ b/packages/math/tests/point.test.ts
@@ -1,5 +1,6 @@
-import { pointFrom, pointRotateRads } from "./point";
-import type { Radians } from "./types";
+import { pointFrom, pointRotateRads } from "../src/point";
+
+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 fb4b6a38d..9808f77f4 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 4237a3c85..6b29bba59 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 145c90953..820f60400 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 f61b8d0af..6450145b1 100644
--- a/packages/math/tsconfig.json
+++ b/packages/math/tsconfig.json
@@ -1,24 +1,8 @@
{
+ "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/*"]
- }
+ "outDir": "./dist/types"
},
+ "include": ["src/**/*", "global.d.ts"],
"exclude": ["**/*.test.*", "tests", "types", "examples", "dist"]
}
diff --git a/packages/tsconfig.base.json b/packages/tsconfig.base.json
new file mode 100644
index 000000000..b1d145ad8
--- /dev/null
+++ b/packages/tsconfig.base.json
@@ -0,0 +1,26 @@
+{
+ "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/*"]
+ }
+ }
+}
diff --git a/packages/utils/package.json b/packages/utils/package.json
index ddda1e7d6..ca3eee23e 100644
--- a/packages/utils/package.json
+++ b/packages/utils/package.json
@@ -2,18 +2,18 @@
"name": "@excalidraw/utils",
"version": "0.1.2",
"type": "module",
- "types": "./dist/types/utils/index.d.ts",
+ "types": "./dist/types/utils/src/index.d.ts",
"main": "./dist/prod/index.js",
"module": "./dist/prod/index.js",
"exports": {
".": {
- "types": "./dist/types/utils/index.d.ts",
+ "types": "./dist/types/utils/src/index.d.ts",
"development": "./dist/dev/index.js",
"production": "./dist/prod/index.js",
"default": "./dist/prod/index.js"
},
"./*": {
- "types": "./../utils/dist/types/utils/*"
+ "types": "./../utils/dist/types/utils/src/*.d.ts"
}
},
"files": [
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 19a1a5430..a56128156 100644
--- a/packages/utils/bbox.ts
+++ b/packages/utils/src/bbox.ts
@@ -4,7 +4,8 @@ import {
type GlobalPoint,
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 fb48f4e45..b7c155f66 100644
--- a/packages/utils/collision.ts
+++ b/packages/utils/src/collision.ts
@@ -1,10 +1,3 @@
-import type { Polycurve, Polyline } from "./geometry/shape";
-import {
- pointInEllipse,
- pointOnEllipse,
- type GeometricShape,
-} from "./geometry/shape";
-import type { Curve } from "@excalidraw/math";
import {
lineSegment,
pointFrom,
@@ -17,6 +10,12 @@ import {
type Polygon,
} from "@excalidraw/math";
+import type { Curve } from "@excalidraw/math";
+
+import { pointInEllipse, pointOnEllipse } from "./shape";
+
+import type { Polycurve, Polyline, GeometricShape } from "./shape";
+
// check if the given point is considered on the given shape's border
export const isPointOnShape = (
point: Point,
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 22287ce7e..4559fe1af 100644
--- a/packages/utils/export.ts
+++ b/packages/utils/src/export.ts
@@ -1,23 +1,24 @@
-import {
- exportToCanvas as _exportToCanvas,
- exportToSvg as _exportToSvg,
-} from "@excalidraw/excalidraw/scene/export";
+import { MIME_TYPES } from "@excalidraw/common";
import { getDefaultAppState } from "@excalidraw/excalidraw/appState";
-import type { AppState, BinaryFiles } from "@excalidraw/excalidraw/types";
-import type {
- ExcalidrawElement,
- ExcalidrawFrameLikeElement,
- NonDeleted,
-} from "@excalidraw/excalidraw/element/types";
-import { restore } from "@excalidraw/excalidraw/data/restore";
-import { MIME_TYPES } from "@excalidraw/excalidraw/constants";
-import { encodePngMetadata } from "@excalidraw/excalidraw/data/image";
-import { serializeAsJSON } from "@excalidraw/excalidraw/data/json";
import {
copyBlobToClipboardAsPng,
copyTextToSystemClipboard,
copyToClipboard,
} from "@excalidraw/excalidraw/clipboard";
+import { encodePngMetadata } from "@excalidraw/excalidraw/data/image";
+import { serializeAsJSON } from "@excalidraw/excalidraw/data/json";
+import { restore } from "@excalidraw/excalidraw/data/restore";
+import {
+ exportToCanvas as _exportToCanvas,
+ exportToSvg as _exportToSvg,
+} from "@excalidraw/excalidraw/scene/export";
+
+import type {
+ ExcalidrawElement,
+ ExcalidrawFrameLikeElement,
+ NonDeleted,
+} 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 2a929134e..58830b356 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 10fc06e31..b750c232e 100644
--- a/packages/utils/geometry/shape.ts
+++ b/packages/utils/src/shape.ts
@@ -11,8 +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 type { Curve, LineSegment, Polygon, Radians } from "@excalidraw/math";
+import { invariant } from "@excalidraw/common";
import {
curve,
lineSegment,
@@ -32,7 +33,9 @@ import {
type GlobalPoint,
type LocalPoint,
} from "@excalidraw/math";
-import { getElementAbsoluteCoords } from "@excalidraw/excalidraw/element";
+
+import { getElementAbsoluteCoords } from "@excalidraw/element/bounds";
+
import type {
ElementsMap,
ExcalidrawBindableElement,
@@ -48,10 +51,10 @@ import type {
ExcalidrawRectangleElement,
ExcalidrawSelectionElement,
ExcalidrawTextElement,
-} from "@excalidraw/excalidraw/element/types";
-import { pointsOnBezierCurves } from "points-on-curve";
+} from "@excalidraw/element/types";
+import type { Curve, LineSegment, Polygon, Radians } from "@excalidraw/math";
+
import type { Drawable, Op } from "roughjs/bin/core";
-import { invariant } from "@excalidraw/excalidraw/utils";
// a polyline (made up term here) is a line consisting of other line segments
// this corresponds to a straight line element in the editor but it could also
diff --git a/packages/utils/snapToShape.ts b/packages/utils/src/snapToShape.ts
similarity index 97%
rename from packages/utils/snapToShape.ts
rename to packages/utils/src/snapToShape.ts
index dbf5506c2..00b1b2c31 100644
--- a/packages/utils/snapToShape.ts
+++ b/packages/utils/src/snapToShape.ts
@@ -6,12 +6,12 @@ import type {
ExcalidrawFreeDrawElement,
ExcalidrawLinearElement,
ExcalidrawRectangleElement,
-} from "../excalidraw/element/types";
-import type { BoundingBox, Bounds } from "../excalidraw/element/bounds";
-import { getCenterForBounds, getCommonBoundingBox } from "../excalidraw/element/bounds";
-import { newArrowElement, newElement, newLinearElement } from "../excalidraw/element";
+} from "@excalidraw/element/types";
+import type { BoundingBox, Bounds } from "@excalidraw/element/bounds";
+import { getCenterForBounds, getCommonBoundingBox } from "@excalidraw/element/bounds";
+import { newArrowElement, newElement, newLinearElement } from "@excalidraw/element/newElement";
import { angleBetween, GlobalPoint, LocalPoint, perpendicularDistance, pointDistance } from "@excalidraw/math";
-import { ROUNDNESS } from "@excalidraw/excalidraw/constants";
+import { ROUNDNESS } from "@excalidraw/common";
type Shape =
| ExcalidrawRectangleElement["type"]
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 8d52eb3ad..0e1cf38a6 100644
--- a/packages/utils/withinBounds.ts
+++ b/packages/utils/src/withinBounds.ts
@@ -1,20 +1,12 @@
-import type {
- ExcalidrawElement,
- ExcalidrawFreeDrawElement,
- ExcalidrawLinearElement,
- NonDeletedExcalidrawElement,
-} from "@excalidraw/excalidraw/element/types";
+import { arrayToMap } from "@excalidraw/common";
+import { getElementBounds } from "@excalidraw/element/bounds";
import {
isArrowElement,
isExcalidrawElement,
isFreeDrawElement,
isLinearElement,
isTextElement,
-} from "@excalidraw/excalidraw/element/typeChecks";
-import type { Bounds } from "@excalidraw/excalidraw/element/bounds";
-import { getElementBounds } from "@excalidraw/excalidraw/element/bounds";
-import { arrayToMap } from "@excalidraw/excalidraw/utils";
-import type { LocalPoint } from "@excalidraw/math";
+} from "@excalidraw/element/typeChecks";
import {
rangeIncludesValue,
pointFrom,
@@ -22,6 +14,15 @@ import {
rangeInclusive,
} from "@excalidraw/math";
+import type { Bounds } from "@excalidraw/element/bounds";
+import type {
+ ExcalidrawElement,
+ ExcalidrawFreeDrawElement,
+ ExcalidrawLinearElement,
+ NonDeletedExcalidrawElement,
+} from "@excalidraw/element/types";
+import type { LocalPoint } from "@excalidraw/math";
+
type Element = NonDeletedExcalidrawElement;
type Elements = readonly 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 744bea367..35bc28b34 100644
--- a/packages/utils/collision.test.ts
+++ b/packages/utils/tests/collision.test.ts
@@ -1,4 +1,3 @@
-import type { Curve, Degrees, GlobalPoint } from "@excalidraw/math";
import {
curve,
degreesToRadians,
@@ -7,8 +6,12 @@ import {
pointFrom,
pointRotateDegs,
} from "@excalidraw/math";
-import { pointOnCurve, pointOnPolyline } from "./collision";
-import type { Polyline } from "./geometry/shape";
+
+import type { Curve, Degrees, GlobalPoint } from "@excalidraw/math";
+
+import { pointOnCurve, pointOnPolyline } from "../src/collision";
+
+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 e2af763b5..47b9398ab 100644
--- a/packages/utils/export.test.ts
+++ b/packages/utils/tests/export.test.ts
@@ -1,9 +1,9 @@
-import * as utils from ".";
+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 mockedSceneExportUtils from "@excalidraw/excalidraw/scene/export";
-import { MIME_TYPES } from "@excalidraw/excalidraw/constants";
+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 e9ad067fe..8a2f95d3f 100644
--- a/packages/utils/geometry/geometry.test.ts
+++ b/packages/utils/tests/geometry.test.ts
@@ -1,9 +1,3 @@
-import type {
- GlobalPoint,
- LineSegment,
- Polygon,
- Radians,
-} from "@excalidraw/math";
import {
pointFrom,
lineSegment,
@@ -13,7 +7,15 @@ import {
polygonIncludesPoint,
segmentsIntersectAt,
} from "@excalidraw/math";
-import { pointInEllipse, pointOnEllipse, type Ellipse } from "./shape";
+
+import type {
+ GlobalPoint,
+ LineSegment,
+ Polygon,
+ Radians,
+} from "@excalidraw/math";
+
+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 341adef95..b77bc37d1 100644
--- a/packages/utils/utils.unmocked.test.ts
+++ b/packages/utils/tests/utils.unmocked.test.ts
@@ -1,8 +1,10 @@
-import type { ImportedDataState } from "@excalidraw/excalidraw/data/types";
-import * as utils from "./index";
-import { API } from "@excalidraw/excalidraw/tests/helpers/api";
-import { decodeSvgBase64Payload } from "@excalidraw/excalidraw/scene/export";
import { decodePngMetadata } from "@excalidraw/excalidraw/data/image";
+import { decodeSvgBase64Payload } from "@excalidraw/excalidraw/scene/export";
+import { API } from "@excalidraw/excalidraw/tests/helpers/api";
+
+import type { ImportedDataState } from "@excalidraw/excalidraw/data/types";
+
+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 85354d742..d1af75de8 100644
--- a/packages/utils/withinBounds.test.ts
+++ b/packages/utils/tests/withinBounds.test.ts
@@ -1,10 +1,12 @@
-import type { Bounds } from "@excalidraw/excalidraw/element/bounds";
import { API } from "@excalidraw/excalidraw/tests/helpers/api";
+
+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 f61b8d0af..6450145b1 100644
--- a/packages/utils/tsconfig.json
+++ b/packages/utils/tsconfig.json
@@ -1,24 +1,8 @@
{
+ "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/*"]
- }
+ "outDir": "./dist/types"
},
+ "include": ["src/**/*", "global.d.ts"],
"exclude": ["**/*.test.*", "tests", "types", "examples", "dist"]
}
diff --git a/scripts/autorelease.js b/scripts/autorelease.js
index f506cf13c..6ca5af213 100644
--- a/scripts/autorelease.js
+++ b/scripts/autorelease.js
@@ -1,5 +1,6 @@
-const fs = require("fs");
const { exec, execSync } = require("child_process");
+const fs = require("fs");
+
const core = require("@actions/core");
const excalidrawDir = `${__dirname}/../packages/excalidraw`;
diff --git a/scripts/buildMath.js b/scripts/buildBase.js
similarity index 77%
rename from scripts/buildMath.js
rename to scripts/buildBase.js
index fd2f820ea..336b49823 100644
--- a/scripts/buildMath.js
+++ b/scripts/buildBase.js
@@ -1,26 +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 }),
@@ -31,7 +32,6 @@ function buildDev(config) {
function buildProd(config) {
return build({
...config,
- plugins: [sassPlugin()],
minify: true,
define: {
"import.meta.env": JSON.stringify({ PROD: true }),
@@ -41,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 653af50f2..baf20615f 100644
--- a/scripts/buildPackage.js
+++ b/scripts/buildPackage.js
@@ -1,6 +1,8 @@
const path = require("path");
+
const { build } = require("esbuild");
const { sassPlugin } = require("esbuild-sass-plugin");
+
const { parseEnvVariables } = require("../packages/excalidraw/env.cjs");
const ENV_VARS = {
@@ -26,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 65b947385..1cf3ffbaa 100644
--- a/scripts/buildUtils.js
+++ b/scripts/buildUtils.js
@@ -1,6 +1,8 @@
const path = require("path");
+
const { build } = require("esbuild");
const { sassPlugin } = require("esbuild-sass-plugin");
+
const { woff2ServerPlugin } = require("./woff2/woff2-esbuild-plugins");
// contains all dependencies bundled inside
@@ -8,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"),
},
});
@@ -47,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/scripts/prerelease.js b/scripts/prerelease.js
index 3b8080d33..005a6cf5f 100644
--- a/scripts/prerelease.js
+++ b/scripts/prerelease.js
@@ -1,5 +1,6 @@
const fs = require("fs");
const util = require("util");
+
const exec = util.promisify(require("child_process").exec);
const updateChangelog = require("./updateChangelog");
diff --git a/scripts/woff2/woff2-esbuild-plugins.js b/scripts/woff2/woff2-esbuild-plugins.js
index 19ebafc93..2116dd059 100644
--- a/scripts/woff2/woff2-esbuild-plugins.js
+++ b/scripts/woff2/woff2-esbuild-plugins.js
@@ -1,9 +1,10 @@
+const { execSync } = require("child_process");
const fs = require("fs");
const path = require("path");
-const { execSync } = require("child_process");
-const which = require("which");
-const wawoff = require("wawoff2");
+
const { Font } = require("fonteditor-core");
+const wawoff = require("wawoff2");
+const which = require("which");
/**
* Custom esbuild plugin to:
diff --git a/setupTests.ts b/setupTests.ts
index 20d2cc517..2aec616b4 100644
--- a/setupTests.ts
+++ b/setupTests.ts
@@ -1,11 +1,13 @@
+import fs from "fs";
+
// vitest.setup.ts
import "vitest-canvas-mock";
import "@testing-library/jest-dom";
-import fs from "fs";
import { vi } from "vitest";
+
import polyfill from "./packages/excalidraw/polyfill";
-import { testPolyfills } from "./packages/excalidraw/tests/helpers/polyfills";
import { yellow } from "./packages/excalidraw/tests/helpers/colorize";
+import { testPolyfills } from "./packages/excalidraw/tests/helpers/polyfills";
// mock for pep.js not working with setPointerCapture()
HTMLElement.prototype.setPointerCapture = vi.fn();
diff --git a/tsconfig.json b/tsconfig.json
index 3eded705f..45a29dd61 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 f9d7d255e..353f84ccf 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"),
},
],
},
diff --git a/yarn.lock b/yarn.lock
index 23e087849..ccd0827fb 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -5354,7 +5354,7 @@ eslint-plugin-flowtype@^8.0.3:
lodash "^4.17.21"
string-natural-compare "^3.0.1"
-eslint-plugin-import@^2.25.3:
+eslint-plugin-import@2.31.0, eslint-plugin-import@^2.25.3:
version "2.31.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.31.0.tgz#310ce7e720ca1d9c0bb3f69adfd1c6bdd7d9e0e7"
integrity sha512-ixmkI62Rbc2/w8Vfxyh1jQRTdRTF52VxwRVHl/ykPAmqG+Nb7/kNn+byLP0LxPgI7zWA16Jt82SybJInmMia3A==