Virtual whiteboard for sketching hand-drawn like diagrams
fix: Circular reference (#10544)
Márk Tolmácsd87620b23907
diff --git a/packages/common/src/bounds.ts b/packages/common/src/bounds.tsnew file mode 100644index 0000000000..b23462dd72--- /dev/null+++ b/packages/common/src/bounds.ts@@ -0,0 +1,17 @@+/**+ * x and y position of top left corner, x and y position of bottom right corner+ */+export type Bounds = readonly [+ minX: number,+ minY: number,+ maxX: number,+ maxY: number,+];++export const isBounds = (box: unknown): box is Bounds =>+ Array.isArray(box) &&+ box.length === 4 &&+ typeof box[0] === "number" &&+ typeof box[1] === "number" &&+ typeof box[2] === "number" &&+ typeof box[3] === "number";diff --git a/packages/common/src/index.ts b/packages/common/src/index.tsindex cb85d0435f..2539f37ec8 100644--- a/packages/common/src/index.ts+++ b/packages/common/src/index.ts@@ -1,4 +1,5 @@export * from "./binary-heap";+export * from "./bounds";export * from "./colors";export * from "./constants";export * from "./font-metadata";diff --git a/packages/common/src/visualdebug.ts b/packages/common/src/visualdebug.tsindex 993612959e..1016be52b5 100644--- a/packages/common/src/visualdebug.ts+++ b/packages/common/src/visualdebug.ts@@ -6,12 +6,10 @@ import {type LocalPoint,} from "@excalidraw/math";-import { isBounds } from "@excalidraw/element";-import type { Curve } from "@excalidraw/math";import type { LineSegment } from "@excalidraw/utils";-import type { Bounds } from "@excalidraw/element";+import { type Bounds, isBounds } from "./bounds";// The global data holder to collect the debug operationsdeclare global {diff --git a/packages/element/src/binding.ts b/packages/element/src/binding.tsindex 9197faf60b..5e55ff66e2 100644--- a/packages/element/src/binding.ts+++ b/packages/element/src/binding.ts@@ -22,10 +22,9 @@ import {} from "@excalidraw/math";import type { LineSegment, LocalPoint, Radians } from "@excalidraw/math";-import type { AppState } from "@excalidraw/excalidraw/types";-import type { MapEntry, Mutable } from "@excalidraw/common/utility-types";+import type { Bounds } from "@excalidraw/common";import {doBoundsIntersect,@@ -64,7 +63,6 @@ import { projectFixedPointOntoDiagonal } from "./utils";import type { Scene } from "./Scene";-import type { Bounds } from "./bounds";import type { ElementUpdate } from "./mutateElement";import type {BindMode,diff --git a/packages/element/src/bounds.ts b/packages/element/src/bounds.tsindex fdc851062c..0c2ce4780b 100644--- a/packages/element/src/bounds.ts+++ b/packages/element/src/bounds.ts@@ -2,6 +2,7 @@ import rough from "roughjs/bin/rough";import {arrayToMap,+ type Bounds,invariant,rescalePoints,sizeOf,@@ -78,16 +79,6 @@ export type RectangleBox = {type MaybeQuadraticSolution = [number | null, number | null] | false;-/**- * x and y position of top left corner, x and y position of bottom right corner- */-export type Bounds = readonly [- minX: number,- minY: number,- maxX: number,- maxY: number,-];-export type SceneBounds = readonly [sceneX: number,sceneY: number,diff --git a/packages/element/src/collision.ts b/packages/element/src/collision.tsindex 17dc9b1987..a96c3ebc14 100644--- a/packages/element/src/collision.ts+++ b/packages/element/src/collision.ts@@ -1,4 +1,4 @@-import { invariant, isTransparent } from "@excalidraw/common";+import { invariant, isTransparent, type Bounds } from "@excalidraw/common";import {curveIntersectLineSegment,isPointWithinBounds,@@ -29,7 +29,6 @@ import type { FrameNameBounds } from "@excalidraw/excalidraw/types";import { isPathALoop } from "./utils";import {- type Bounds,doBoundsIntersect,elementCenterPoint,getCenterForBounds,diff --git a/packages/element/src/dragElements.ts b/packages/element/src/dragElements.tsindex 9e82953cc9..796685d8f8 100644--- a/packages/element/src/dragElements.ts+++ b/packages/element/src/dragElements.ts@@ -1,4 +1,5 @@import {+ type Bounds,TEXT_AUTOWRAP_THRESHOLD,getGridPoint,getFontString,@@ -29,7 +30,6 @@ import {import type { Scene } from "./Scene";-import type { Bounds } from "./bounds";import type { ExcalidrawElement } from "./types";export const dragSelectedElements = (diff --git a/packages/element/src/elbowArrow.ts b/packages/element/src/elbowArrow.tsindex d01648e490..b0a5e935f5 100644--- a/packages/element/src/elbowArrow.ts+++ b/packages/element/src/elbowArrow.ts@@ -14,6 +14,7 @@ import {} from "@excalidraw/math";import {+ type Bounds,BinaryHeap,invariant,isAnyTrue,@@ -54,7 +55,6 @@ import {import { aabbForElement, pointInsideBounds } from "./bounds";import { getHoveredElementForBinding } from "./collision";-import type { Bounds } from "./bounds";import type { Heading } from "./heading";import type {Arrowhead,diff --git a/packages/element/src/heading.ts b/packages/element/src/heading.tsindex 1e9ab37132..a115a8f1e1 100644--- a/packages/element/src/heading.ts+++ b/packages/element/src/heading.ts@@ -1,4 +1,9 @@-import { invariant, isDevEnv, isTestEnv } from "@excalidraw/common";+import {+ invariant,+ isDevEnv,+ isTestEnv,+ type Bounds,+} from "@excalidraw/common";import {pointFrom,@@ -19,7 +24,7 @@ import type {Vector,} from "@excalidraw/math";-import { getCenterForBounds, type Bounds } from "./bounds";+import { getCenterForBounds } from "./bounds";import type { ExcalidrawBindableElement } from "./types";diff --git a/packages/element/src/linearElementEditor.ts b/packages/element/src/linearElementEditor.tsindex b8c82c0875..62f5ebbff7 100644--- a/packages/element/src/linearElementEditor.ts+++ b/packages/element/src/linearElementEditor.ts@@ -42,6 +42,7 @@ import type {NullableGridSize,Zoom,} from "@excalidraw/excalidraw/types";+import type { Bounds } from "@excalidraw/common";import {calculateFixedPointForNonElbowArrowBinding,@@ -68,7 +69,6 @@ import { isLineElement } from "./typeChecks";import type { Scene } from "./Scene";-import type { Bounds } from "./bounds";import type {NonDeleted,ExcalidrawLinearElement,diff --git a/packages/element/src/resizeTest.ts b/packages/element/src/resizeTest.tsindex 4257d4a7e8..22bb4abddf 100644--- a/packages/element/src/resizeTest.ts+++ b/packages/element/src/resizeTest.ts@@ -13,6 +13,7 @@ import {import type { GlobalPoint, LineSegment, LocalPoint } from "@excalidraw/math";import type { AppState, Zoom } from "@excalidraw/excalidraw/types";+import type { Bounds } from "@excalidraw/common";import { getElementAbsoluteCoords } from "./bounds";import {@@ -23,7 +24,6 @@ import {} from "./transformHandles";import { isImageElement, isLinearElement } from "./typeChecks";-import type { Bounds } from "./bounds";import type {TransformHandleType,TransformHandle,diff --git a/packages/element/src/transformHandles.ts b/packages/element/src/transformHandles.tsindex 0b9458da63..7ef56849ce 100644--- a/packages/element/src/transformHandles.ts+++ b/packages/element/src/transformHandles.ts@@ -11,6 +11,7 @@ import type {InteractiveCanvasAppState,Zoom,} from "@excalidraw/excalidraw/types";+import type { Bounds } from "@excalidraw/common";import { getElementAbsoluteCoords } from "./bounds";import {@@ -20,7 +21,6 @@ import {isLinearElement,} from "./typeChecks";-import type { Bounds } from "./bounds";import type {ElementsMap,ExcalidrawElement,diff --git a/packages/element/src/typeChecks.ts b/packages/element/src/typeChecks.tsindex f328ee947c..b609cc3f8a 100644--- a/packages/element/src/typeChecks.ts+++ b/packages/element/src/typeChecks.ts@@ -6,7 +6,6 @@ import type { ElementOrToolType } from "@excalidraw/excalidraw/types";import type { MarkNonNullable } from "@excalidraw/common/utility-types";-import type { Bounds } from "./bounds";import type {ExcalidrawElement,ExcalidrawTextElement,@@ -356,15 +355,6 @@ export const getDefaultRoundnessTypeForElement = (return null;};-// TODO: Move this to @excalidraw/math-export const isBounds = (box: unknown): box is Bounds =>- Array.isArray(box) &&- box.length === 4 &&- typeof box[0] === "number" &&- typeof box[1] === "number" &&- typeof box[2] === "number" &&- typeof box[3] === "number";-export const getLinearElementSubType = (element: ExcalidrawLinearElement,): ExcalidrawLinearElementSubType => {diff --git a/packages/element/tests/resize.test.tsx b/packages/element/tests/resize.test.tsxindex ab836d6a0f..b51d537e37 100644--- a/packages/element/tests/resize.test.tsx+++ b/packages/element/tests/resize.test.tsx@@ -2,6 +2,7 @@ import { pointFrom } from "@excalidraw/math";import { Excalidraw } from "@excalidraw/excalidraw";import {+ type Bounds,KEYS,getSizeFromPoints,reseed,@@ -22,7 +23,6 @@ import { resizeSingleElement } from "../src/resizeElements";import { LinearElementEditor } from "../src/linearElementEditor";import { getElementPointsCoords } from "../src/bounds";-import type { Bounds } from "../src/bounds";import type {ExcalidrawElbowArrowElement,ExcalidrawFreeDrawElement,diff --git a/packages/excalidraw/components/hyperlink/helpers.ts b/packages/excalidraw/components/hyperlink/helpers.tsindex e89ecdc554..9f68734b54 100644--- a/packages/excalidraw/components/hyperlink/helpers.ts+++ b/packages/excalidraw/components/hyperlink/helpers.ts@@ -6,7 +6,7 @@ import { hitElementBoundingBox } from "@excalidraw/element";import type { GlobalPoint, Radians } from "@excalidraw/math";-import type { Bounds } from "@excalidraw/element";+import type { Bounds } from "@excalidraw/common";import type {ElementsMap,NonDeletedExcalidrawElement,diff --git a/packages/excalidraw/eraser/index.ts b/packages/excalidraw/eraser/index.tsindex d587bb3811..cf60309886 100644--- a/packages/excalidraw/eraser/index.ts+++ b/packages/excalidraw/eraser/index.ts@@ -28,7 +28,7 @@ import { shouldTestInside } from "@excalidraw/element";import { hasBoundTextElement, isBoundToContainer } from "@excalidraw/element";import { getBoundTextElementId } from "@excalidraw/element";-import type { Bounds } from "@excalidraw/element";+import type { Bounds } from "@excalidraw/common";import type { GlobalPoint, LineSegment } from "@excalidraw/math/types";import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";diff --git a/packages/excalidraw/lasso/utils.ts b/packages/excalidraw/lasso/utils.tsindex 2cab64662b..f7eb7cba55 100644--- a/packages/excalidraw/lasso/utils.ts+++ b/packages/excalidraw/lasso/utils.ts@@ -6,8 +6,9 @@ import {polygonIncludesPointNonZero,} from "@excalidraw/math";+import { type Bounds } from "@excalidraw/common";+import {- type Bounds,computeBoundTextPosition,doBoundsIntersect,getBoundTextElement,diff --git a/packages/excalidraw/scene/export.ts b/packages/excalidraw/scene/export.tsindex f2e5b32df7..5fb4eff855 100644--- a/packages/excalidraw/scene/export.ts+++ b/packages/excalidraw/scene/export.ts@@ -39,7 +39,7 @@ import { type Mutable } from "@excalidraw/common/utility-types";import { newTextElement } from "@excalidraw/element";-import type { Bounds } from "@excalidraw/element";+import type { Bounds } from "@excalidraw/common";import type {ExcalidrawElement,diff --git a/packages/excalidraw/snapping.ts b/packages/excalidraw/snapping.tsindex cb4e8af6bb..6ea47e5bef 100644--- a/packages/excalidraw/snapping.ts+++ b/packages/excalidraw/snapping.ts@@ -24,7 +24,7 @@ import {import type { InclusiveRange } from "@excalidraw/math";-import type { Bounds } from "@excalidraw/element";+import type { Bounds } from "@excalidraw/common";import type { MaybeTransformHandleType } from "@excalidraw/element";import type {ElementsMap,diff --git a/packages/utils/src/bbox.ts b/packages/utils/src/bbox.tsindex 07dd8907ab..4450da1b8d 100644--- a/packages/utils/src/bbox.ts+++ b/packages/utils/src/bbox.ts@@ -5,7 +5,7 @@ import {type LocalPoint,} from "@excalidraw/math";-import type { Bounds } from "@excalidraw/element";+import type { Bounds } from "@excalidraw/common";export type LineSegment<P extends LocalPoint | GlobalPoint> = [P, P];diff --git a/packages/utils/src/withinBounds.ts b/packages/utils/src/withinBounds.tsindex d635655fc8..3ffab9d370 100644--- a/packages/utils/src/withinBounds.ts+++ b/packages/utils/src/withinBounds.ts@@ -1,4 +1,4 @@-import { arrayToMap } from "@excalidraw/common";+import { arrayToMap, type Bounds } from "@excalidraw/common";import { getElementBounds } from "@excalidraw/element";import {isArrowElement,@@ -14,7 +14,6 @@ import {rangeInclusive,} from "@excalidraw/math";-import type { Bounds } from "@excalidraw/element";import type {ExcalidrawElement,ExcalidrawFreeDrawElement,diff --git a/packages/utils/tests/withinBounds.test.ts b/packages/utils/tests/withinBounds.test.tsindex b05b5525b9..5849120579 100644--- a/packages/utils/tests/withinBounds.test.ts+++ b/packages/utils/tests/withinBounds.test.ts@@ -1,6 +1,6 @@import { API } from "@excalidraw/excalidraw/tests/helpers/api";-import type { Bounds } from "@excalidraw/element";+import type { Bounds } from "@excalidraw/common";import {elementPartiallyOverlapsWithOrContainsBBox,