From 40ff1b08aec730de059ea44d5195904232411657 Mon Sep 17 00:00:00 2001 From: Marcel Mraz Date: Thu, 20 Mar 2025 13:50:36 +0100 Subject: [PATCH] Fx imports and most tests --- packages/common/src/colors.ts | 2 +- packages/common/src/font-metadata.ts | 4 +- packages/common/src/index.ts | 1 + packages/common/src/keys.ts | 4 +- packages/common/src/queue.ts | 6 +- packages/common/src/utils.ts | 7 +- packages/element/src/Shape.ts | 25 +++---- packages/element/src/ShapeCache.ts | 7 +- packages/element/src/align.ts | 17 +++-- packages/element/src/binding.ts | 8 +-- packages/element/src/bounds.ts | 4 +- packages/element/src/collision.ts | 3 +- packages/element/src/distribute.ts | 8 +-- packages/element/src/elbowArrow.ts | 4 +- packages/element/src/elementLink.ts | 3 +- packages/element/src/flowchart.ts | 7 +- packages/element/src/fractionalIndex.ts | 8 +-- packages/element/src/frame.ts | 32 +++++---- packages/element/src/groups.ts | 22 +++--- packages/element/src/index.ts | 14 ---- packages/element/src/linearElementEditor.ts | 24 ++++--- packages/element/src/newElement.ts | 7 +- packages/element/src/renderElement.ts | 71 ++++++++++--------- packages/element/src/selection.ts | 14 ++-- packages/element/src/shapes.ts | 3 +- packages/element/src/textElement.ts | 8 ++- packages/element/src/zindex.ts | 19 +++-- packages/element/tests/binding.test.tsx | 4 +- packages/element/tests/elbowArrow.test.tsx | 10 +-- packages/element/tests/frame.test.tsx | 2 +- packages/element/tests/resize.test.tsx | 15 ++-- packages/element/tests/textElement.test.ts | 2 +- packages/element/tests/zindex.test.tsx | 10 +-- .../excalidraw/actions/actionBoundText.tsx | 4 +- packages/excalidraw/actions/actionCanvas.tsx | 6 +- .../actions/actionDuplicateSelection.tsx | 4 +- .../excalidraw/actions/actionFinalize.tsx | 3 +- packages/excalidraw/actions/actionFrame.ts | 4 +- packages/excalidraw/actions/actionMenu.tsx | 7 +- .../excalidraw/actions/actionProperties.tsx | 12 ++-- .../excalidraw/actions/actionSelectAll.ts | 4 +- packages/excalidraw/actions/actionStyles.ts | 13 ++-- .../actions/actionTextAutoResize.ts | 3 +- packages/excalidraw/charts.ts | 7 +- packages/excalidraw/components/App.tsx | 54 ++++++++------ .../components/ElementCanvasButtons.tsx | 2 +- packages/excalidraw/components/LayerUI.tsx | 2 +- packages/excalidraw/components/MobileMenu.tsx | 2 +- packages/excalidraw/components/SearchMenu.tsx | 5 +- .../excalidraw/components/Stats/FontSize.tsx | 11 ++- .../components/Stats/MultiDimension.tsx | 5 +- .../components/Stats/MultiFontSize.tsx | 11 ++- .../components/Stats/MultiPosition.tsx | 4 +- .../components/Stats/stats.test.tsx | 6 +- packages/excalidraw/data/library.ts | 3 +- packages/excalidraw/data/restore.ts | 13 ++-- packages/excalidraw/data/transform.ts | 13 ++-- packages/excalidraw/fonts/Fonts.ts | 3 +- packages/excalidraw/index.tsx | 6 +- .../excalidraw/renderer/interactiveScene.ts | 14 ++-- packages/excalidraw/renderer/staticScene.ts | 3 +- .../excalidraw/renderer/staticSvgScene.ts | 4 +- packages/excalidraw/scene/export.ts | 4 +- packages/excalidraw/scene/scroll.ts | 10 +-- packages/excalidraw/scene/scrollbars.ts | 4 +- packages/excalidraw/store.ts | 4 +- packages/excalidraw/tests/clipboard.test.tsx | 4 +- packages/excalidraw/tests/flip.test.tsx | 4 +- packages/excalidraw/tests/helpers/api.ts | 4 +- packages/utils/geometry/shape.ts | 3 +- 70 files changed, 335 insertions(+), 305 deletions(-) diff --git a/packages/common/src/colors.ts b/packages/common/src/colors.ts index 42d7bc710..84d04bcf4 100644 --- a/packages/common/src/colors.ts +++ b/packages/common/src/colors.ts @@ -1,6 +1,6 @@ import oc from "open-color"; -import type { Merge } from "@excalidraw/common/utility-types"; +import type { Merge } from "./utility-types"; // FIXME can't put to utils.ts rn because of circular dependency const pick = , K extends readonly (keyof R)[]>( diff --git a/packages/common/src/font-metadata.ts b/packages/common/src/font-metadata.ts index b70c0e36c..8cc59c4d7 100644 --- a/packages/common/src/font-metadata.ts +++ b/packages/common/src/font-metadata.ts @@ -1,10 +1,10 @@ -import { FONT_FAMILY, FONT_FAMILY_FALLBACKS } from "@excalidraw/common"; - import type { ExcalidrawTextElement, FontFamilyValues, } from "@excalidraw/element/types"; +import { FONT_FAMILY, FONT_FAMILY_FALLBACKS } from "."; + /** * Encapsulates font metrics with additional font metadata. * */ diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index 1ae86610d..d896ba98e 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -2,6 +2,7 @@ export * from "./binary-heap"; export * from "./colors"; export * from "./constants"; export * from "./font-metadata"; +export * from "./queue"; export * from "./keys"; export * from "./points"; export * from "./promise-pool"; diff --git a/packages/common/src/keys.ts b/packages/common/src/keys.ts index 255d986fd..948e7f568 100644 --- a/packages/common/src/keys.ts +++ b/packages/common/src/keys.ts @@ -1,7 +1,7 @@ -import type { ValueOf } from "@excalidraw/common/utility-types"; - import { isDarwin } from "./constants"; +import type { ValueOf } from "./utility-types"; + export const CODES = { EQUAL: "Equal", MINUS: "Minus", diff --git a/packages/common/src/queue.ts b/packages/common/src/queue.ts index 85edb6e64..2043f5e06 100644 --- a/packages/common/src/queue.ts +++ b/packages/common/src/queue.ts @@ -1,8 +1,8 @@ -import { promiseTry, resolvablePromise } from "@excalidraw/common"; +import { promiseTry, resolvablePromise } from "."; -import type { ResolvablePromise } from "@excalidraw/common"; +import type { ResolvablePromise } from "."; -import type { MaybePromise } from "@excalidraw/common/utility-types"; +import type { MaybePromise } from "./utility-types"; type Job = (...args: TArgs) => MaybePromise; diff --git a/packages/common/src/utils.ts b/packages/common/src/utils.ts index be530c480..549f830cd 100644 --- a/packages/common/src/utils.ts +++ b/packages/common/src/utils.ts @@ -14,11 +14,6 @@ import type { Zoom, } from "@excalidraw/excalidraw/types"; -import type { - MaybePromise, - ResolutionType, -} from "@excalidraw/common/utility-types"; - import { COLOR_PALETTE } from "./colors"; import { DEFAULT_VERSION, @@ -28,6 +23,8 @@ import { WINDOWS_EMOJI_FALLBACK_FONT, } from "./constants"; +import type { MaybePromise, ResolutionType } from "./utility-types"; + import type { EVENT } from "./constants"; let mockDateTime: string | null = null; diff --git a/packages/element/src/Shape.ts b/packages/element/src/Shape.ts index 3f84fe28b..4def41957 100644 --- a/packages/element/src/Shape.ts +++ b/packages/element/src/Shape.ts @@ -2,18 +2,25 @@ import { simplify } from "points-on-curve"; import { pointFrom, pointDistance, type LocalPoint } from "@excalidraw/math"; import { ROUGHNESS, isTransparent, assertNever } from "@excalidraw/common"; -import { getDiamondPoints, getArrowheadPoints } from "@excalidraw/element"; -import { headingForPointIsHorizontal } from "@excalidraw/element/heading"; -import { getCornerRadius, isPathALoop } from "@excalidraw/element/shapes"; + +import type { Mutable } from "@excalidraw/common/utility-types"; + +import type { EmbedsValidationStatus } from "@excalidraw/excalidraw/types"; +import type { ElementShapes } from "@excalidraw/excalidraw/scene/types"; + import { isElbowArrow, isEmbeddableElement, isIframeElement, isIframeLikeElement, isLinearElement, -} from "@excalidraw/element/typeChecks"; +} from "./typeChecks"; +import { getCornerRadius, isPathALoop } from "./shapes"; +import { headingForPointIsHorizontal } from "./heading"; -import type { Mutable } from "@excalidraw/common/utility-types"; +import { canChangeRoundness } from "./comparisons"; +import { generateFreeDrawShape } from "./renderElement"; +import { getArrowheadPoints, getDiamondPoints } from "./bounds"; import type { ExcalidrawElement, @@ -21,13 +28,7 @@ import type { ExcalidrawSelectionElement, ExcalidrawLinearElement, Arrowhead, -} from "@excalidraw/element/types"; - -import type { EmbedsValidationStatus } from "@excalidraw/excalidraw/types"; -import type { ElementShapes } from "@excalidraw/excalidraw/scene/types"; - -import { canChangeRoundness } from "./comparisons"; -import { generateFreeDrawShape } from "./renderElement"; +} from "./types"; import type { Drawable, Options } from "roughjs/bin/core"; import type { RoughGenerator } from "roughjs/bin/generator"; diff --git a/packages/element/src/ShapeCache.ts b/packages/element/src/ShapeCache.ts index 517dc69f4..8f0c94324 100644 --- a/packages/element/src/ShapeCache.ts +++ b/packages/element/src/ShapeCache.ts @@ -2,11 +2,6 @@ import { RoughGenerator } from "roughjs/bin/generator"; import { COLOR_PALETTE } from "@excalidraw/common"; -import type { - ExcalidrawElement, - ExcalidrawSelectionElement, -} from "@excalidraw/element/types"; - import type { AppState, EmbedsValidationStatus, @@ -20,6 +15,8 @@ import { _generateElementShape } from "./Shape"; import { elementWithCanvasCache } from "./renderElement"; +import type { ExcalidrawElement, ExcalidrawSelectionElement } from "./types"; + import type { Drawable } from "roughjs/bin/core"; export class ShapeCache { diff --git a/packages/element/src/align.ts b/packages/element/src/align.ts index e96c631f0..61535b434 100644 --- a/packages/element/src/align.ts +++ b/packages/element/src/align.ts @@ -1,14 +1,13 @@ -import { updateBoundElements } from "@excalidraw/element/binding"; -import { getCommonBoundingBox } from "@excalidraw/element/bounds"; -import { mutateElement } from "@excalidraw/element/mutateElement"; - -import { getMaximumGroups } from "@excalidraw/element/groups"; - -import type { BoundingBox } from "@excalidraw/element/bounds"; -import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types"; - import type Scene from "@excalidraw/excalidraw/scene/Scene"; +import { updateBoundElements } from "./binding"; +import { getCommonBoundingBox } from "./bounds"; +import { mutateElement } from "./mutateElement"; +import { getMaximumGroups } from "./groups"; + +import type { BoundingBox } from "./bounds"; +import type { ElementsMap, ExcalidrawElement } from "./types"; + export interface Alignment { position: "start" | "center" | "end"; axis: "x" | "y"; diff --git a/packages/element/src/binding.ts b/packages/element/src/binding.ts index cc52d94b8..6b0c91b6f 100644 --- a/packages/element/src/binding.ts +++ b/packages/element/src/binding.ts @@ -24,12 +24,6 @@ import { PRECISION, } from "@excalidraw/math"; -import { - aabbForElement, - getElementShape, - pointInsideBounds, -} from "@excalidraw/element"; - import { isPointOnShape } from "@excalidraw/utils/collision"; import type { LocalPoint, Radians } from "@excalidraw/math"; @@ -70,6 +64,8 @@ import { isTextElement, } from "./typeChecks"; +import { aabbForElement, getElementShape, pointInsideBounds } from "./shapes"; + import type { Bounds } from "./bounds"; import type { ElementUpdate } from "./mutateElement"; import type { diff --git a/packages/element/src/bounds.ts b/packages/element/src/bounds.ts index ccc8b7b4a..8cf04c4cd 100644 --- a/packages/element/src/bounds.ts +++ b/packages/element/src/bounds.ts @@ -12,8 +12,6 @@ import { } from "@excalidraw/math"; import { getCurvePathOps } from "@excalidraw/utils/geometry/shape"; -import { generateRoughOptions } from "@excalidraw/element/Shape"; -import { ShapeCache } from "@excalidraw/element/ShapeCache"; import type { Degrees, @@ -27,6 +25,8 @@ import type { AppState } from "@excalidraw/excalidraw/types"; import type { Mutable } from "@excalidraw/common/utility-types"; +import { ShapeCache } from "./ShapeCache"; +import { generateRoughOptions } from "./Shape"; import { LinearElementEditor } from "./linearElementEditor"; import { getBoundTextElement, getContainerElement } from "./textElement"; import { diff --git a/packages/element/src/collision.ts b/packages/element/src/collision.ts index 1e223709f..258c0dbc8 100644 --- a/packages/element/src/collision.ts +++ b/packages/element/src/collision.ts @@ -18,8 +18,6 @@ import { import { isPointInShape, isPointOnShape } from "@excalidraw/utils/collision"; import { getPolygonShape } from "@excalidraw/utils/geometry/shape"; -import { getBoundTextShape, isPathALoop } from "@excalidraw/element/shapes"; - import type { GlobalPoint, LineSegment, @@ -32,6 +30,7 @@ import type { GeometricShape } from "@excalidraw/utils/geometry/shape"; import type { FrameNameBounds } from "@excalidraw/excalidraw/types"; +import { getBoundTextShape, isPathALoop } from "./shapes"; import { getElementBounds } from "./bounds"; import { hasBoundTextElement, diff --git a/packages/element/src/distribute.ts b/packages/element/src/distribute.ts index deb7b4d85..da79837da 100644 --- a/packages/element/src/distribute.ts +++ b/packages/element/src/distribute.ts @@ -1,9 +1,9 @@ -import { getCommonBoundingBox } from "@excalidraw/element/bounds"; -import { newElementWith } from "@excalidraw/element/mutateElement"; +import { getCommonBoundingBox } from "./bounds"; +import { newElementWith } from "./mutateElement"; -import { getMaximumGroups } from "@excalidraw/element/groups"; +import { getMaximumGroups } from "./groups"; -import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types"; +import type { ElementsMap, ExcalidrawElement } from "./types"; export interface Distribution { space: "between"; diff --git a/packages/element/src/elbowArrow.ts b/packages/element/src/elbowArrow.ts index 09e137657..173ea9b34 100644 --- a/packages/element/src/elbowArrow.ts +++ b/packages/element/src/elbowArrow.ts @@ -21,8 +21,6 @@ import { getSizeFromPoints, } from "@excalidraw/common"; -import { aabbForElement, pointInsideBounds } from "@excalidraw/element"; - import type { AppState } from "@excalidraw/excalidraw/types"; import { @@ -54,6 +52,8 @@ import { type SceneElementsMap, } from "./types"; +import { aabbForElement, pointInsideBounds } from "./shapes"; + import type { Bounds } from "./bounds"; import type { Heading } from "./heading"; import type { diff --git a/packages/element/src/elementLink.ts b/packages/element/src/elementLink.ts index fe242666c..8781e696d 100644 --- a/packages/element/src/elementLink.ts +++ b/packages/element/src/elementLink.ts @@ -5,10 +5,11 @@ import { ELEMENT_LINK_KEY, normalizeLink } from "@excalidraw/common"; import type { AppProps, AppState } from "@excalidraw/excalidraw/types"; -import type { ExcalidrawElement } from "@excalidraw/element/types"; import { elementsAreInSameGroup } from "./groups"; +import type { ExcalidrawElement } from "./types"; + export const defaultGetElementLinkFromSelection: Exclude< AppProps["generateLinkForSelection"], undefined diff --git a/packages/element/src/flowchart.ts b/packages/element/src/flowchart.ts index cc642d383..2eac014fa 100644 --- a/packages/element/src/flowchart.ts +++ b/packages/element/src/flowchart.ts @@ -1,9 +1,4 @@ -import { - elementOverlapsWithFrame, - elementsAreInFrameBounds, -} from "@excalidraw/element"; import { KEYS, invariant, toBrandedType } from "@excalidraw/common"; -import { aabbForElement } from "@excalidraw/element"; import { pointFrom, type LocalPoint } from "@excalidraw/math"; @@ -26,6 +21,8 @@ import { import { LinearElementEditor } from "./linearElementEditor"; import { mutateElement } from "./mutateElement"; import { newArrowElement, newElement } from "./newElement"; +import { aabbForElement } from "./shapes"; +import { elementsAreInFrameBounds, elementOverlapsWithFrame } from "./frame"; import { isBindableElement, isElbowArrow, diff --git a/packages/element/src/fractionalIndex.ts b/packages/element/src/fractionalIndex.ts index c2d7b93ab..bbe739f29 100644 --- a/packages/element/src/fractionalIndex.ts +++ b/packages/element/src/fractionalIndex.ts @@ -2,15 +2,15 @@ import { generateNKeysBetween } from "fractional-indexing"; import { arrayToMap } from "@excalidraw/common"; -import { mutateElement } from "@excalidraw/element/mutateElement"; -import { getBoundTextElement } from "@excalidraw/element/textElement"; -import { hasBoundTextElement } from "@excalidraw/element/typeChecks"; +import { mutateElement } from "./mutateElement"; +import { getBoundTextElement } from "./textElement"; +import { hasBoundTextElement } from "./typeChecks"; import type { ExcalidrawElement, FractionalIndex, OrderedExcalidrawElement, -} from "@excalidraw/element/types"; +} from "./types"; export class InvalidFractionalIndexError extends Error { public code = "ELEMENT_HAS_INVALID_INDEX" as const; diff --git a/packages/element/src/frame.ts b/packages/element/src/frame.ts index de138f6a8..576961236 100644 --- a/packages/element/src/frame.ts +++ b/packages/element/src/frame.ts @@ -5,17 +5,6 @@ import { elementsOverlappingBBox, } from "@excalidraw/utils"; -import { getElementAbsoluteCoords, isTextElement } from "@excalidraw/element"; - -import type { - ElementsMap, - ElementsMapOrArray, - ExcalidrawElement, - ExcalidrawFrameLikeElement, - NonDeleted, - NonDeletedExcalidrawElement, -} from "@excalidraw/element/types"; - import type { ExcalidrawElementsIncludingDeleted } from "@excalidraw/excalidraw/scene/Scene"; import type { @@ -29,10 +18,27 @@ import type { ReadonlySetLike } from "@excalidraw/common/utility-types"; import { getElementsWithinSelection, getSelectedElements } from "./selection"; import { getElementsInGroup, selectGroupsFromGivenElements } from "./groups"; -import { getElementLineSegments, getCommonBounds } from "./bounds"; +import { + getElementLineSegments, + getCommonBounds, + getElementAbsoluteCoords, +} from "./bounds"; import { mutateElement } from "./mutateElement"; import { getBoundTextElement, getContainerElement } from "./textElement"; -import { isFrameElement, isFrameLikeElement } from "./typeChecks"; +import { + isFrameElement, + isFrameLikeElement, + isTextElement, +} from "./typeChecks"; + +import type { + ElementsMap, + ElementsMapOrArray, + ExcalidrawElement, + ExcalidrawFrameLikeElement, + NonDeleted, + NonDeletedExcalidrawElement, +} from "./types"; // --------------------------- Frame State ------------------------------------ export const bindElementsToFramesAfterDuplication = ( diff --git a/packages/element/src/groups.ts b/packages/element/src/groups.ts index db0edef2c..7bb3466eb 100644 --- a/packages/element/src/groups.ts +++ b/packages/element/src/groups.ts @@ -1,4 +1,13 @@ -import { getBoundTextElement } from "@excalidraw/element/textElement"; +import type { + AppClassProperties, + AppState, + InteractiveCanvasAppState, +} from "@excalidraw/excalidraw/types"; +import type { Mutable } from "@excalidraw/common/utility-types"; + +import { getBoundTextElement } from "./textElement"; + +import { makeNextSelectedElementIds, getSelectedElements } from "./selection"; import type { GroupId, @@ -7,16 +16,7 @@ import type { NonDeletedExcalidrawElement, ElementsMapOrArray, ElementsMap, -} from "@excalidraw/element/types"; - -import type { - AppClassProperties, - AppState, - InteractiveCanvasAppState, -} from "@excalidraw/excalidraw/types"; -import type { Mutable } from "@excalidraw/common/utility-types"; - -import { makeNextSelectedElementIds, getSelectedElements } from "./selection"; +} from "./types"; export const selectGroup = ( groupId: GroupId, diff --git a/packages/element/src/index.ts b/packages/element/src/index.ts index 12024a10f..d7edec8ae 100644 --- a/packages/element/src/index.ts +++ b/packages/element/src/index.ts @@ -7,20 +7,6 @@ import type { NonDeleted, } from "./types"; -export * from "./bounds"; -export * from "./dragElements"; -export * from "./frame"; -export * from "./mutateElement"; -export * from "./newElement"; -export * from "./resizeElements"; -export * from "./resizeTest"; -export * from "./shapes"; -export * from "./showSelectedShapeActions"; -export * from "./textElement"; -export * from "./typeChecks"; -export * from "./transformHandles"; -export * from "./sizeHelpers"; - /** * @deprecated unsafe, use hashElementsVersion instead */ diff --git a/packages/element/src/linearElementEditor.ts b/packages/element/src/linearElementEditor.ts index 72e068a14..eddae8ff3 100644 --- a/packages/element/src/linearElementEditor.ts +++ b/packages/element/src/linearElementEditor.ts @@ -20,14 +20,6 @@ import { tupleToCoors, } from "@excalidraw/common"; -import { - getBezierCurveLength, - getBezierXY, - getControlPointsForBezierCurve, - isPathALoop, - mapIntervalToBezierT, -} from "@excalidraw/element"; - import type { Store } from "@excalidraw/excalidraw/store"; import type { Radians } from "@excalidraw/math"; @@ -50,7 +42,11 @@ import { getHoveredElementForBinding, isBindingEnabled, } from "./binding"; -import { getElementPointsCoords, getMinMaxXYFromCurvePathOps } from "./bounds"; +import { + getElementAbsoluteCoords, + getElementPointsCoords, + getMinMaxXYFromCurvePathOps, +} from "./bounds"; import { headingIsHorizontal, vectorToHeading } from "./heading"; import { mutateElement } from "./mutateElement"; import { getBoundTextElement, handleBindTextResize } from "./textElement"; @@ -62,7 +58,15 @@ import { import { ShapeCache } from "./ShapeCache"; -import { getElementAbsoluteCoords, getLockedLinearCursorAlignSize } from "./"; +import { + isPathALoop, + getBezierCurveLength, + getControlPointsForBezierCurve, + mapIntervalToBezierT, + getBezierXY, +} from "./shapes"; + +import { getLockedLinearCursorAlignSize } from "./sizeHelpers"; import type { Bounds } from "./bounds"; import type { diff --git a/packages/element/src/newElement.ts b/packages/element/src/newElement.ts index db5a8126f..c8cc056f0 100644 --- a/packages/element/src/newElement.ts +++ b/packages/element/src/newElement.ts @@ -25,15 +25,16 @@ import type { Mutable, } from "@excalidraw/common/utility-types"; -import { getResizedElementAbsoluteCoords } from "./bounds"; +import { + getElementAbsoluteCoords, + getResizedElementAbsoluteCoords, +} from "./bounds"; import { bumpVersion, newElementWith } from "./mutateElement"; import { getBoundTextMaxWidth } from "./textElement"; import { normalizeText, measureText } from "./textMeasurements"; import { wrapText } from "./textWrapping"; import { getNewGroupIdsForDuplication } from "./groups"; -import { getElementAbsoluteCoords } from "."; - import type { ExcalidrawElement, ExcalidrawImageElement, diff --git a/packages/element/src/renderElement.ts b/packages/element/src/renderElement.ts index b52e0a29b..c8091e8ed 100644 --- a/packages/element/src/renderElement.ts +++ b/packages/element/src/renderElement.ts @@ -15,41 +15,6 @@ import { isRTL, getVerticalOffset, } from "@excalidraw/common"; -import { getElementAbsoluteCoords } from "@excalidraw/element/bounds"; -import { getUncroppedImageElement } from "@excalidraw/element/cropElement"; -import { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; -import { - getBoundTextElement, - getContainerCoords, - getContainerElement, - getBoundTextMaxHeight, - getBoundTextMaxWidth, -} from "@excalidraw/element/textElement"; -import { getLineHeightInPx } from "@excalidraw/element/textMeasurements"; -import { - isTextElement, - isLinearElement, - isFreeDrawElement, - isInitializedImageElement, - isArrowElement, - hasBoundTextElement, - isMagicFrameElement, - isImageElement, -} from "@excalidraw/element/typeChecks"; -import { getContainingFrame } from "@excalidraw/element/frame"; -import { getCornerRadius } from "@excalidraw/element/shapes"; - -import type { - ExcalidrawElement, - ExcalidrawTextElement, - NonDeletedExcalidrawElement, - ExcalidrawFreeDrawElement, - ExcalidrawImageElement, - ExcalidrawTextElementWithContainer, - ExcalidrawFrameLikeElement, - NonDeletedSceneElementsMap, - ElementsMap, -} from "@excalidraw/element/types"; import type { AppState, @@ -67,8 +32,44 @@ import type { InteractiveCanvasRenderConfig, } from "@excalidraw/excalidraw/scene/types"; +import { getElementAbsoluteCoords } from "./bounds"; +import { getUncroppedImageElement } from "./cropElement"; +import { LinearElementEditor } from "./linearElementEditor"; +import { + getBoundTextElement, + getContainerCoords, + getContainerElement, + getBoundTextMaxHeight, + getBoundTextMaxWidth, +} from "./textElement"; +import { getLineHeightInPx } from "./textMeasurements"; +import { + isTextElement, + isLinearElement, + isFreeDrawElement, + isInitializedImageElement, + isArrowElement, + hasBoundTextElement, + isMagicFrameElement, + isImageElement, +} from "./typeChecks"; +import { getContainingFrame } from "./frame"; +import { getCornerRadius } from "./shapes"; + import { ShapeCache } from "./ShapeCache"; +import type { + ExcalidrawElement, + ExcalidrawTextElement, + NonDeletedExcalidrawElement, + ExcalidrawFreeDrawElement, + ExcalidrawImageElement, + ExcalidrawTextElementWithContainer, + ExcalidrawFrameLikeElement, + NonDeletedSceneElementsMap, + ElementsMap, +} from "./types"; + import type { StrokeOptions } from "perfect-freehand"; import type { RoughCanvas } from "roughjs/bin/canvas"; diff --git a/packages/element/src/selection.ts b/packages/element/src/selection.ts index c582c32e8..a76703920 100644 --- a/packages/element/src/selection.ts +++ b/packages/element/src/selection.ts @@ -1,12 +1,5 @@ import { isShallowEqual } from "@excalidraw/common"; -import type { - ElementsMap, - ElementsMapOrArray, - ExcalidrawElement, - NonDeletedExcalidrawElement, -} from "@excalidraw/element/types"; - import type { AppState, InteractiveCanvasAppState, @@ -21,6 +14,13 @@ import { getFrameChildren, } from "./frame"; +import type { + ElementsMap, + ElementsMapOrArray, + ExcalidrawElement, + NonDeletedExcalidrawElement, +} from "./types"; + /** * Frames and their containing elements are not to be selected at the same time. * Given an array of selected elements, if there are frames and their containing elements diff --git a/packages/element/src/shapes.ts b/packages/element/src/shapes.ts index 61e355742..43b06ad98 100644 --- a/packages/element/src/shapes.ts +++ b/packages/element/src/shapes.ts @@ -32,9 +32,8 @@ import { LinearElementEditor } from "./linearElementEditor"; import { getBoundTextElement } from "./textElement"; import { ShapeCache } from "./ShapeCache"; -import { getElementAbsoluteCoords } from "./"; +import { getElementAbsoluteCoords, type Bounds } from "./bounds"; -import type { Bounds } from "./bounds"; import type { ElementsMap, ExcalidrawElement, diff --git a/packages/element/src/textElement.ts b/packages/element/src/textElement.ts index f2e0ae7a3..93ccb74aa 100644 --- a/packages/element/src/textElement.ts +++ b/packages/element/src/textElement.ts @@ -21,9 +21,11 @@ import { LinearElementEditor } from "./linearElementEditor"; import { mutateElement } from "./mutateElement"; import { measureText } from "./textMeasurements"; import { wrapText } from "./textWrapping"; -import { isBoundToContainer, isArrowElement } from "./typeChecks"; - -import { isTextElement } from "./"; +import { + isBoundToContainer, + isArrowElement, + isTextElement, +} from "./typeChecks"; import type { MaybeTransformHandleType } from "./transformHandles"; import type { diff --git a/packages/element/src/zindex.ts b/packages/element/src/zindex.ts index 743956e92..e09142e4a 100644 --- a/packages/element/src/zindex.ts +++ b/packages/element/src/zindex.ts @@ -1,22 +1,19 @@ -import { isFrameLikeElement } from "@excalidraw/element/typeChecks"; - import { arrayToMap, findIndex, findLastIndex } from "@excalidraw/common"; -import { getElementsInGroup } from "@excalidraw/element/groups"; - -import { syncMovedIndices } from "@excalidraw/element/fractionalIndex"; - -import type { - ExcalidrawElement, - ExcalidrawFrameLikeElement, -} from "@excalidraw/element/types"; - import type { AppState } from "@excalidraw/excalidraw/types"; import type Scene from "@excalidraw/excalidraw/scene/Scene"; +import { isFrameLikeElement } from "./typeChecks"; + +import { getElementsInGroup } from "./groups"; + +import { syncMovedIndices } from "./fractionalIndex"; + import { getSelectedElements } from "./selection"; +import type { ExcalidrawElement, ExcalidrawFrameLikeElement } from "./types"; + const isOfTargetFrame = (element: ExcalidrawElement, frameId: string) => { return element.frameId === frameId || element.id === frameId; }; diff --git a/packages/element/tests/binding.test.tsx b/packages/element/tests/binding.test.tsx index 57b88cb17..f57d7793a 100644 --- a/packages/element/tests/binding.test.tsx +++ b/packages/element/tests/binding.test.tsx @@ -3,13 +3,15 @@ import { KEYS, arrayToMap } from "@excalidraw/common"; import { pointFrom } from "@excalidraw/math"; import { actionWrapTextInContainer } from "@excalidraw/excalidraw/actions/actionBoundText"; -import { getTransformHandles } from "@excalidraw/element/transformHandles"; + import { Excalidraw, isLinearElement } from "@excalidraw/excalidraw"; import { API } from "@excalidraw/excalidraw/tests/helpers/api"; import { UI, Pointer, Keyboard } from "@excalidraw/excalidraw/tests/helpers/ui"; import { fireEvent, render } from "@excalidraw/excalidraw/tests/test-utils"; +import { getTransformHandles } from "../src/transformHandles"; + const { h } = window; const mouse = new Pointer("mouse"); diff --git a/packages/element/tests/elbowArrow.test.tsx b/packages/element/tests/elbowArrow.test.tsx index ccec88353..dbace93b6 100644 --- a/packages/element/tests/elbowArrow.test.tsx +++ b/packages/element/tests/elbowArrow.test.tsx @@ -17,17 +17,17 @@ import { render, } from "@excalidraw/excalidraw/tests/test-utils"; -import { bindLinearElement } from "@excalidraw/element/binding"; - import type { LocalPoint } from "@excalidraw/math"; +import { bindLinearElement } from "../src/binding"; + +import "../../utils/test-utils"; + import type { ExcalidrawArrowElement, ExcalidrawBindableElement, ExcalidrawElbowArrowElement, -} from "@excalidraw/element/types"; - -import "../../utils/test-utils"; +} from "../src/types"; const { h } = window; diff --git a/packages/element/tests/frame.test.tsx b/packages/element/tests/frame.test.tsx index cd52db409..47f2160ac 100644 --- a/packages/element/tests/frame.test.tsx +++ b/packages/element/tests/frame.test.tsx @@ -10,7 +10,7 @@ import { render, } from "@excalidraw/excalidraw/tests/test-utils"; -import type { ExcalidrawElement } from "@excalidraw/element/types"; +import type { ExcalidrawElement } from "../src/types"; const { h } = window; const mouse = new Pointer("mouse"); diff --git a/packages/element/tests/resize.test.tsx b/packages/element/tests/resize.test.tsx index d9606e617..f3804e2a2 100644 --- a/packages/element/tests/resize.test.tsx +++ b/packages/element/tests/resize.test.tsx @@ -1,10 +1,4 @@ import { pointFrom } from "@excalidraw/math"; -import React from "react"; - -import { getElementPointsCoords } from "@excalidraw/element/bounds"; -import { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; -import { resizeSingleElement } from "@excalidraw/element/resizeElements"; -import { isLinearElement } from "@excalidraw/element/typeChecks"; import { Excalidraw } from "@excalidraw/excalidraw"; import { @@ -23,12 +17,17 @@ import { import type { LocalPoint } from "@excalidraw/math"; -import type { Bounds } from "@excalidraw/element/bounds"; +import { isLinearElement } from "../src/typeChecks"; +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, ExcalidrawLinearElement, -} from "@excalidraw/element/types"; +} from "../src/types"; unmountComponent(); diff --git a/packages/element/tests/textElement.test.ts b/packages/element/tests/textElement.test.ts index 08ff1a367..5c10681a7 100644 --- a/packages/element/tests/textElement.test.ts +++ b/packages/element/tests/textElement.test.ts @@ -1,4 +1,4 @@ -import { getLineHeight } from "@excalidraw/common/font-metadata"; +import { getLineHeight } from "@excalidraw/common"; import { API } from "@excalidraw/excalidraw/tests/helpers/api"; import { FONT_FAMILY } from "@excalidraw/common"; diff --git a/packages/element/tests/zindex.test.tsx b/packages/element/tests/zindex.test.tsx index 67c197a8c..997cb56f8 100644 --- a/packages/element/tests/zindex.test.tsx +++ b/packages/element/tests/zindex.test.tsx @@ -1,5 +1,3 @@ -import { selectGroupsForSelectedElements } from "@excalidraw/element/groups"; - import { reseed } from "@excalidraw/common"; import { @@ -20,13 +18,15 @@ import { unmountComponent, } from "@excalidraw/excalidraw/tests/test-utils"; +import type { AppState } from "@excalidraw/excalidraw/types"; + +import { selectGroupsForSelectedElements } from "../src/groups"; + import type { ExcalidrawElement, ExcalidrawFrameElement, ExcalidrawSelectionElement, -} from "@excalidraw/element/types"; - -import type { AppState } from "@excalidraw/excalidraw/types"; +} from "../src/types"; unmountComponent(); diff --git a/packages/excalidraw/actions/actionBoundText.tsx b/packages/excalidraw/actions/actionBoundText.tsx index dda0c527e..7cb10c045 100644 --- a/packages/excalidraw/actions/actionBoundText.tsx +++ b/packages/excalidraw/actions/actionBoundText.tsx @@ -6,7 +6,6 @@ import { arrayToMap, getFontString, } from "@excalidraw/common"; -import { isTextElement, newElement } from "@excalidraw/element"; import { getOriginalContainerHeightFromCache, resetOriginalContainerCache, @@ -23,6 +22,7 @@ import { import { hasBoundTextElement, isTextBindableContainer, + isTextElement, isUsingAdaptiveRadius, } from "@excalidraw/element/typeChecks"; @@ -31,6 +31,8 @@ import { measureText } from "@excalidraw/element/textMeasurements"; import { syncMovedIndices } from "@excalidraw/element/fractionalIndex"; +import { newElement } from "@excalidraw/element/newElement"; + import type { ExcalidrawElement, ExcalidrawLinearElement, diff --git a/packages/excalidraw/actions/actionCanvas.tsx b/packages/excalidraw/actions/actionCanvas.tsx index 0f3e0bb3e..0aa83944f 100644 --- a/packages/excalidraw/actions/actionCanvas.tsx +++ b/packages/excalidraw/actions/actionCanvas.tsx @@ -13,11 +13,9 @@ import { KEYS, } from "@excalidraw/common"; -import { getCommonBounds, getNonDeletedElements } from "@excalidraw/element"; - +import { getNonDeletedElements } from "@excalidraw/element"; import { newElementWith } from "@excalidraw/element/mutateElement"; - -import type { SceneBounds } from "@excalidraw/element/bounds"; +import { getCommonBounds, type SceneBounds } from "@excalidraw/element/bounds"; import type { ExcalidrawElement } from "@excalidraw/element/types"; diff --git a/packages/excalidraw/actions/actionDuplicateSelection.tsx b/packages/excalidraw/actions/actionDuplicateSelection.tsx index 3584ff7d6..5e3296ad7 100644 --- a/packages/excalidraw/actions/actionDuplicateSelection.tsx +++ b/packages/excalidraw/actions/actionDuplicateSelection.tsx @@ -8,7 +8,7 @@ import { invariant, } from "@excalidraw/common"; -import { duplicateElement, getNonDeletedElements } from "@excalidraw/element"; +import { getNonDeletedElements } from "@excalidraw/element"; import { fixBindingsAfterDuplication } from "@excalidraw/element/binding"; @@ -44,6 +44,8 @@ import { getSelectedElements, } from "@excalidraw/element/selection"; +import { duplicateElement } from "@excalidraw/element/newElement"; + import type { ExcalidrawElement } from "@excalidraw/element/types"; import { ToolButton } from "../components/ToolButton"; diff --git a/packages/excalidraw/actions/actionFinalize.tsx b/packages/excalidraw/actions/actionFinalize.tsx index 8626815ec..984961656 100644 --- a/packages/excalidraw/actions/actionFinalize.tsx +++ b/packages/excalidraw/actions/actionFinalize.tsx @@ -1,6 +1,5 @@ import { pointFrom } from "@excalidraw/math"; -import { isInvisiblySmallElement } from "@excalidraw/element"; import { maybeBindLinearElement, bindOrUnbindLinearElement, @@ -15,6 +14,8 @@ import { import { KEYS, arrayToMap, updateActiveTool } from "@excalidraw/common"; import { isPathALoop } from "@excalidraw/element/shapes"; +import { isInvisiblySmallElement } from "@excalidraw/element/sizeHelpers"; + import { t } from "../i18n"; import { resetCursor } from "../cursor"; import { done } from "../components/icons"; diff --git a/packages/excalidraw/actions/actionFrame.ts b/packages/excalidraw/actions/actionFrame.ts index ab5088edd..13d57b2a1 100644 --- a/packages/excalidraw/actions/actionFrame.ts +++ b/packages/excalidraw/actions/actionFrame.ts @@ -1,4 +1,4 @@ -import { getCommonBounds, getNonDeletedElements } from "@excalidraw/element"; +import { getNonDeletedElements } from "@excalidraw/element"; import { mutateElement } from "@excalidraw/element/mutateElement"; import { newFrameElement } from "@excalidraw/element/newElement"; import { isFrameLikeElement } from "@excalidraw/element/typeChecks"; @@ -12,6 +12,8 @@ import { KEYS, updateActiveTool } from "@excalidraw/common"; import { getElementsInGroup } from "@excalidraw/element/groups"; +import { getCommonBounds } from "@excalidraw/element/bounds"; + import type { ExcalidrawElement } from "@excalidraw/element/types"; import { setCursorForShape } from "../cursor"; diff --git a/packages/excalidraw/actions/actionMenu.tsx b/packages/excalidraw/actions/actionMenu.tsx index cc029499d..67863e020 100644 --- a/packages/excalidraw/actions/actionMenu.tsx +++ b/packages/excalidraw/actions/actionMenu.tsx @@ -1,9 +1,8 @@ import { KEYS } from "@excalidraw/common"; -import { - showSelectedShapeActions, - getNonDeletedElements, -} from "@excalidraw/element"; +import { getNonDeletedElements } from "@excalidraw/element"; + +import { showSelectedShapeActions } from "@excalidraw/element/showSelectedShapeActions"; import { ToolButton } from "../components/ToolButton"; import { HamburgerMenuIcon, HelpIconThin, palette } from "../components/icons"; diff --git a/packages/excalidraw/actions/actionProperties.tsx b/packages/excalidraw/actions/actionProperties.tsx index eeb693d9a..673063d42 100644 --- a/packages/excalidraw/actions/actionProperties.tsx +++ b/packages/excalidraw/actions/actionProperties.tsx @@ -22,11 +22,7 @@ import { getLineHeight, } from "@excalidraw/common"; -import { - getNonDeletedElements, - isTextElement, - redrawTextBoundingBox, -} from "@excalidraw/element"; +import { getNonDeletedElements } from "@excalidraw/element"; import { bindLinearElement, @@ -43,13 +39,17 @@ import { newElementWith, } from "@excalidraw/element/mutateElement"; -import { getBoundTextElement } from "@excalidraw/element/textElement"; +import { + getBoundTextElement, + redrawTextBoundingBox, +} from "@excalidraw/element/textElement"; import { isArrowElement, isBoundToContainer, isElbowArrow, isLinearElement, + isTextElement, isUsingAdaptiveRadius, } from "@excalidraw/element/typeChecks"; diff --git a/packages/excalidraw/actions/actionSelectAll.ts b/packages/excalidraw/actions/actionSelectAll.ts index f38e580ca..d7775774a 100644 --- a/packages/excalidraw/actions/actionSelectAll.ts +++ b/packages/excalidraw/actions/actionSelectAll.ts @@ -1,6 +1,6 @@ -import { getNonDeletedElements, isTextElement } from "@excalidraw/element"; +import { getNonDeletedElements } from "@excalidraw/element"; import { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; -import { isLinearElement } from "@excalidraw/element/typeChecks"; +import { isLinearElement, isTextElement } from "@excalidraw/element/typeChecks"; import { KEYS } from "@excalidraw/common"; diff --git a/packages/excalidraw/actions/actionStyles.ts b/packages/excalidraw/actions/actionStyles.ts index b87b7b7d9..ed3c91e30 100644 --- a/packages/excalidraw/actions/actionStyles.ts +++ b/packages/excalidraw/actions/actionStyles.ts @@ -7,12 +7,6 @@ import { getLineHeight, } from "@excalidraw/common"; -import { - isTextElement, - isExcalidrawElement, - redrawTextBoundingBox, -} from "@excalidraw/element"; - import { newElementWith } from "@excalidraw/element/mutateElement"; import { @@ -21,9 +15,14 @@ import { getDefaultRoundnessTypeForElement, isFrameLikeElement, isArrowElement, + isExcalidrawElement, + isTextElement, } from "@excalidraw/element/typeChecks"; -import { getBoundTextElement } from "@excalidraw/element/textElement"; +import { + getBoundTextElement, + redrawTextBoundingBox, +} from "@excalidraw/element/textElement"; import type { ExcalidrawTextElement } from "@excalidraw/element/types"; diff --git a/packages/excalidraw/actions/actionTextAutoResize.ts b/packages/excalidraw/actions/actionTextAutoResize.ts index 5230955f3..4a36cab40 100644 --- a/packages/excalidraw/actions/actionTextAutoResize.ts +++ b/packages/excalidraw/actions/actionTextAutoResize.ts @@ -1,9 +1,10 @@ import { getFontString } from "@excalidraw/common"; -import { isTextElement } from "@excalidraw/element"; import { newElementWith } from "@excalidraw/element/mutateElement"; import { measureText } from "@excalidraw/element/textMeasurements"; +import { isTextElement } from "@excalidraw/element/typeChecks"; + import { getSelectedElements } from "../scene"; import { CaptureUpdateAction } from "../store"; diff --git a/packages/excalidraw/charts.ts b/packages/excalidraw/charts.ts index 467c8136e..98d39a3d5 100644 --- a/packages/excalidraw/charts.ts +++ b/packages/excalidraw/charts.ts @@ -9,11 +9,12 @@ import { VERTICAL_ALIGN, randomId, } from "@excalidraw/common"; + import { - newElement, - newLinearElement, newTextElement, -} from "@excalidraw/element"; + newLinearElement, + newElement, +} from "@excalidraw/element/newElement"; import type { Radians } from "@excalidraw/math"; diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx index 996fc9215..76b94516f 100644 --- a/packages/excalidraw/components/App.tsx +++ b/packages/excalidraw/components/App.tsx @@ -77,30 +77,9 @@ import { } from "@excalidraw/common"; import { - dragNewElement, - dragSelectedElements, - duplicateElement, getCommonBounds, - getCursorForResizingElement, - getDragOffsetXY, - getElementWithTransformHandleType, - getNormalizedDimensions, - getResizeArrowDirection, - getResizeOffsetXY, - getLockedLinearCursorAlignSize, - getTransformHandleTypeFromCoords, - isInvisiblySmallElement, - isNonDeletedElement, - isTextElement, - newElement, - newLinearElement, - newTextElement, - newImageElement, - transformElements, - refreshTextDimensions, - redrawTextBoundingBox, getElementAbsoluteCoords, -} from "@excalidraw/element"; +} from "@excalidraw/element/bounds"; import { bindOrUnbindLinearElement, @@ -132,6 +111,12 @@ import { newMagicFrameElement, newIframeElement, newArrowElement, + duplicateElement, + newElement, + newImageElement, + newLinearElement, + newTextElement, + refreshTextDimensions, } from "@excalidraw/element/newElement"; import { @@ -154,11 +139,15 @@ import { isElbowArrow, isFlowchartNodeElement, isBindableElement, + isTextElement, } from "@excalidraw/element/typeChecks"; import { + getLockedLinearCursorAlignSize, + getNormalizedDimensions, isElementCompletelyInViewport, isElementInViewport, + isInvisiblySmallElement, } from "@excalidraw/element/sizeHelpers"; import { @@ -216,6 +205,7 @@ import { getContainerCenter, getContainerElement, isValidTextContainer, + redrawTextBoundingBox, } from "@excalidraw/element/textElement"; import { shouldShowBoundingBox } from "@excalidraw/element/transformHandles"; @@ -295,6 +285,26 @@ import { makeNextSelectedElementIds, } from "@excalidraw/element/selection"; +import { + getResizeOffsetXY, + getResizeArrowDirection, + transformElements, +} from "@excalidraw/element/resizeElements"; + +import { + getCursorForResizingElement, + getElementWithTransformHandleType, + getTransformHandleTypeFromCoords, +} from "@excalidraw/element/resizeTest"; + +import { + dragNewElement, + dragSelectedElements, + getDragOffsetXY, +} from "@excalidraw/element/dragElements"; + +import { isNonDeletedElement } from "@excalidraw/element"; + import type { LocalPoint, Radians } from "@excalidraw/math"; import type { diff --git a/packages/excalidraw/components/ElementCanvasButtons.tsx b/packages/excalidraw/components/ElementCanvasButtons.tsx index 0069b327e..424c4f3b4 100644 --- a/packages/excalidraw/components/ElementCanvasButtons.tsx +++ b/packages/excalidraw/components/ElementCanvasButtons.tsx @@ -1,5 +1,5 @@ import { sceneCoordsToViewportCoords } from "@excalidraw/common"; -import { getElementAbsoluteCoords } from "@excalidraw/element"; +import { getElementAbsoluteCoords } from "@excalidraw/element/bounds"; import type { ElementsMap, diff --git a/packages/excalidraw/components/LayerUI.tsx b/packages/excalidraw/components/LayerUI.tsx index 340d3b84c..b5491dedd 100644 --- a/packages/excalidraw/components/LayerUI.tsx +++ b/packages/excalidraw/components/LayerUI.tsx @@ -11,7 +11,7 @@ import { import { mutateElement } from "@excalidraw/element/mutateElement"; -import { showSelectedShapeActions } from "@excalidraw/element"; +import { showSelectedShapeActions } from "@excalidraw/element/showSelectedShapeActions"; import { ShapeCache } from "@excalidraw/element/ShapeCache"; diff --git a/packages/excalidraw/components/MobileMenu.tsx b/packages/excalidraw/components/MobileMenu.tsx index 454c0f64e..6e75b5992 100644 --- a/packages/excalidraw/components/MobileMenu.tsx +++ b/packages/excalidraw/components/MobileMenu.tsx @@ -1,6 +1,6 @@ import React from "react"; -import { showSelectedShapeActions } from "@excalidraw/element"; +import { showSelectedShapeActions } from "@excalidraw/element/showSelectedShapeActions"; import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types"; diff --git a/packages/excalidraw/components/SearchMenu.tsx b/packages/excalidraw/components/SearchMenu.tsx index b9fab72c5..3e0b31a69 100644 --- a/packages/excalidraw/components/SearchMenu.tsx +++ b/packages/excalidraw/components/SearchMenu.tsx @@ -5,8 +5,6 @@ import { Fragment, memo, useEffect, useRef, useState } from "react"; import { CLASSES, EVENT } from "@excalidraw/common"; -import { isTextElement, newTextElement } from "@excalidraw/element"; - import { isElementCompletelyInViewport } from "@excalidraw/element/sizeHelpers"; import { measureText } from "@excalidraw/element/textMeasurements"; @@ -18,6 +16,9 @@ import { getFontString, } from "@excalidraw/common"; +import { newTextElement } from "@excalidraw/element/newElement"; +import { isTextElement } from "@excalidraw/element/typeChecks"; + import type { ExcalidrawTextElement } from "@excalidraw/element/types"; import { atom, useAtom } from "../editor-jotai"; diff --git a/packages/excalidraw/components/Stats/FontSize.tsx b/packages/excalidraw/components/Stats/FontSize.tsx index 18195fa37..90bdee564 100644 --- a/packages/excalidraw/components/Stats/FontSize.tsx +++ b/packages/excalidraw/components/Stats/FontSize.tsx @@ -1,7 +1,12 @@ -import { isTextElement, redrawTextBoundingBox } from "@excalidraw/element"; import { mutateElement } from "@excalidraw/element/mutateElement"; -import { getBoundTextElement } from "@excalidraw/element/textElement"; -import { hasBoundTextElement } from "@excalidraw/element/typeChecks"; +import { + getBoundTextElement, + redrawTextBoundingBox, +} from "@excalidraw/element/textElement"; +import { + hasBoundTextElement, + isTextElement, +} from "@excalidraw/element/typeChecks"; import type { ExcalidrawElement, diff --git a/packages/excalidraw/components/Stats/MultiDimension.tsx b/packages/excalidraw/components/Stats/MultiDimension.tsx index cb27c93ee..b482611af 100644 --- a/packages/excalidraw/components/Stats/MultiDimension.tsx +++ b/packages/excalidraw/components/Stats/MultiDimension.tsx @@ -2,7 +2,6 @@ import { pointFrom, type GlobalPoint } from "@excalidraw/math"; import { useMemo } from "react"; import { MIN_WIDTH_OR_HEIGHT } from "@excalidraw/common"; -import { getCommonBounds, isTextElement } from "@excalidraw/element"; import { updateBoundElements } from "@excalidraw/element/binding"; import { mutateElement } from "@excalidraw/element/mutateElement"; import { @@ -14,6 +13,10 @@ import { handleBindTextResize, } from "@excalidraw/element/textElement"; +import { isTextElement } from "@excalidraw/element/typeChecks"; + +import { getCommonBounds } from "@excalidraw/utils"; + import type { ElementsMap, ExcalidrawElement, diff --git a/packages/excalidraw/components/Stats/MultiFontSize.tsx b/packages/excalidraw/components/Stats/MultiFontSize.tsx index 0ad90bb2f..6bac4bd3c 100644 --- a/packages/excalidraw/components/Stats/MultiFontSize.tsx +++ b/packages/excalidraw/components/Stats/MultiFontSize.tsx @@ -1,7 +1,12 @@ -import { isTextElement, redrawTextBoundingBox } from "@excalidraw/element"; import { mutateElement } from "@excalidraw/element/mutateElement"; -import { getBoundTextElement } from "@excalidraw/element/textElement"; -import { hasBoundTextElement } from "@excalidraw/element/typeChecks"; +import { + getBoundTextElement, + redrawTextBoundingBox, +} from "@excalidraw/element/textElement"; +import { + hasBoundTextElement, + isTextElement, +} from "@excalidraw/element/typeChecks"; import { isInGroup } from "@excalidraw/element/groups"; diff --git a/packages/excalidraw/components/Stats/MultiPosition.tsx b/packages/excalidraw/components/Stats/MultiPosition.tsx index c722eccbc..98058efec 100644 --- a/packages/excalidraw/components/Stats/MultiPosition.tsx +++ b/packages/excalidraw/components/Stats/MultiPosition.tsx @@ -1,7 +1,9 @@ import { pointFrom, pointRotateRads } from "@excalidraw/math"; import { useMemo } from "react"; -import { getCommonBounds, isTextElement } from "@excalidraw/element"; +import { isTextElement } from "@excalidraw/element/typeChecks"; + +import { getCommonBounds } from "@excalidraw/element/bounds"; import type { ElementsMap, diff --git a/packages/excalidraw/components/Stats/stats.test.tsx b/packages/excalidraw/components/Stats/stats.test.tsx index 722b16469..fc94da056 100644 --- a/packages/excalidraw/components/Stats/stats.test.tsx +++ b/packages/excalidraw/components/Stats/stats.test.tsx @@ -3,12 +3,12 @@ import { act, fireEvent, queryByTestId } from "@testing-library/react"; import React from "react"; import { vi } from "vitest"; -import { getCommonBounds, isTextElement } from "@excalidraw/element"; - import { setDateTimeForTests, reseed } from "@excalidraw/common"; import { isInGroup } from "@excalidraw/element/groups"; +import { isTextElement } from "@excalidraw/element/typeChecks"; + import type { Degrees } from "@excalidraw/math"; import type { @@ -17,7 +17,7 @@ import type { ExcalidrawTextElement, } from "@excalidraw/element/types"; -import { Excalidraw, mutateElement } from "../.."; +import { Excalidraw, getCommonBounds, mutateElement } from "../.."; import { actionGroup } from "../../actions"; import { t } from "../../i18n"; import * as StaticScene from "../../renderer/staticScene"; diff --git a/packages/excalidraw/data/library.ts b/packages/excalidraw/data/library.ts index 052932335..74252657e 100644 --- a/packages/excalidraw/data/library.ts +++ b/packages/excalidraw/data/library.ts @@ -13,14 +13,13 @@ import { promiseTry, resolvablePromise, toValidURL, + Queue, } from "@excalidraw/common"; import { hashElementsVersion, hashString } from "@excalidraw/element"; import { getCommonBoundingBox } from "@excalidraw/element/bounds"; -import { Queue } from "@excalidraw/common/queue"; - import type { ExcalidrawElement } from "@excalidraw/element/types"; import type { MaybePromise } from "@excalidraw/common/utility-types"; diff --git a/packages/excalidraw/data/restore.ts b/packages/excalidraw/data/restore.ts index 030a22fb8..21dfbad95 100644 --- a/packages/excalidraw/data/restore.ts +++ b/packages/excalidraw/data/restore.ts @@ -18,12 +18,7 @@ import { normalizeLink, getLineHeight, } from "@excalidraw/common"; -import { - getNonDeletedElements, - getNormalizedDimensions, - isInvisiblySmallElement, - refreshTextDimensions, -} from "@excalidraw/element"; +import { getNonDeletedElements } from "@excalidraw/element"; import { normalizeFixedPoint } from "@excalidraw/element/binding"; import { updateElbowArrowPoints, @@ -44,6 +39,10 @@ import { import { syncInvalidIndices } from "@excalidraw/element/fractionalIndex"; +import { refreshTextDimensions } from "@excalidraw/element/newElement"; + +import { getNormalizedDimensions } from "@excalidraw/element/sizeHelpers"; + import type { LocalPoint, Radians } from "@excalidraw/math"; import type { @@ -72,6 +71,8 @@ import { getNormalizedZoom, } from "../scene"; +import { isInvisiblySmallElement } from ".."; + import type { AppState, BinaryFiles, LibraryItem } from "../types"; import type { ImportedDataState, LegacyAppState } from "./types"; diff --git a/packages/excalidraw/data/transform.ts b/packages/excalidraw/data/transform.ts index 255996f94..9def9f5fc 100644 --- a/packages/excalidraw/data/transform.ts +++ b/packages/excalidraw/data/transform.ts @@ -15,17 +15,14 @@ import { toBrandedType, getLineHeight, } from "@excalidraw/common"; -import { - getCommonBounds, - newElement, - newLinearElement, - redrawTextBoundingBox, -} from "@excalidraw/element"; + import { bindLinearElement } from "@excalidraw/element/binding"; import { newArrowElement, + newElement, newFrameElement, newImageElement, + newLinearElement, newMagicFrameElement, newTextElement, } from "@excalidraw/element/newElement"; @@ -37,6 +34,8 @@ import { isArrowElement } from "@excalidraw/element/typeChecks"; import { syncInvalidIndices } from "@excalidraw/element/fractionalIndex"; +import { redrawTextBoundingBox } from "@excalidraw/element/textElement"; + import type { ElementConstructorOpts } from "@excalidraw/element/newElement"; import type { @@ -62,6 +61,8 @@ import type { import type { MarkOptional } from "@excalidraw/common/utility-types"; +import { getCommonBounds } from ".."; + export type ValidLinearElement = { type: "arrow" | "line"; x: number; diff --git a/packages/excalidraw/fonts/Fonts.ts b/packages/excalidraw/fonts/Fonts.ts index 5b035254f..79b5ea1af 100644 --- a/packages/excalidraw/fonts/Fonts.ts +++ b/packages/excalidraw/fonts/Fonts.ts @@ -5,7 +5,6 @@ import { WINDOWS_EMOJI_FALLBACK_FONT, getFontFamilyFallbacks, } from "@excalidraw/common"; -import { isTextElement } from "@excalidraw/element"; import { getContainerElement } from "@excalidraw/element/textElement"; import { charWidth } from "@excalidraw/element/textMeasurements"; import { containsCJK } from "@excalidraw/element/textWrapping"; @@ -20,6 +19,8 @@ import { import { ShapeCache } from "@excalidraw/element/ShapeCache"; +import { isTextElement } from "@excalidraw/element/typeChecks"; + import type { ExcalidrawElement, ExcalidrawTextElement, diff --git a/packages/excalidraw/index.tsx b/packages/excalidraw/index.tsx index 40f22de8f..5ea746754 100644 --- a/packages/excalidraw/index.tsx +++ b/packages/excalidraw/index.tsx @@ -215,10 +215,12 @@ export { getSceneVersion, hashElementsVersion, hashString, - isInvisiblySmallElement, getNonDeletedElements, - getTextFromElements, } from "@excalidraw/element"; + +export { getTextFromElements } from "@excalidraw/element/textElement"; +export { isInvisiblySmallElement } from "@excalidraw/element/sizeHelpers"; + export { defaultLang, useI18n, languages } from "./i18n"; export { restore, diff --git a/packages/excalidraw/renderer/interactiveScene.ts b/packages/excalidraw/renderer/interactiveScene.ts index 8ef9f859d..59ce1df00 100644 --- a/packages/excalidraw/renderer/interactiveScene.ts +++ b/packages/excalidraw/renderer/interactiveScene.ts @@ -14,12 +14,7 @@ import { invariant, throttleRAF, } from "@excalidraw/common"; -import { - getElementAbsoluteCoords, - getTransformHandlesFromCoords, - getTransformHandles, - getCommonBounds, -} from "@excalidraw/element"; + import { BINDING_HIGHLIGHT_OFFSET, BINDING_HIGHLIGHT_THICKNESS, @@ -28,6 +23,8 @@ import { import { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; import { getOmitSidesForDevice, + getTransformHandles, + getTransformHandlesFromCoords, shouldShowBoundingBox, } from "@excalidraw/element/transformHandles"; import { @@ -49,6 +46,11 @@ import { selectGroupsFromGivenElements, } from "@excalidraw/element/groups"; +import { + getCommonBounds, + getElementAbsoluteCoords, +} from "@excalidraw/element/bounds"; + import type { SuggestedBinding, SuggestedPointBinding, diff --git a/packages/excalidraw/renderer/staticScene.ts b/packages/excalidraw/renderer/staticScene.ts index 9a84145ec..16743ff91 100644 --- a/packages/excalidraw/renderer/staticScene.ts +++ b/packages/excalidraw/renderer/staticScene.ts @@ -1,5 +1,4 @@ import { FRAME_STYLE, throttleRAF } from "@excalidraw/common"; -import { getElementAbsoluteCoords } from "@excalidraw/element"; import { isElementLink } from "@excalidraw/element/elementLink"; import { createPlaceholderEmbeddableLabel } from "@excalidraw/element/embeddable"; import { getBoundTextElement } from "@excalidraw/element/textElement"; @@ -16,6 +15,8 @@ import { import { renderElement } from "@excalidraw/element/renderElement"; +import { getElementAbsoluteCoords } from "@excalidraw/element/bounds"; + import type { ElementsMap, ExcalidrawFrameLikeElement, diff --git a/packages/excalidraw/renderer/staticSvgScene.ts b/packages/excalidraw/renderer/staticSvgScene.ts index 413613a44..0d3f5bad9 100644 --- a/packages/excalidraw/renderer/staticSvgScene.ts +++ b/packages/excalidraw/renderer/staticSvgScene.ts @@ -9,7 +9,7 @@ import { getVerticalOffset, } from "@excalidraw/common"; import { normalizeLink, toValidURL } from "@excalidraw/common"; -import { getElementAbsoluteCoords, hashString } from "@excalidraw/element"; +import { hashString } from "@excalidraw/element"; import { getUncroppedWidthAndHeight } from "@excalidraw/element/cropElement"; import { createPlaceholderEmbeddableLabel, @@ -39,6 +39,8 @@ import { IMAGE_INVERT_FILTER, } from "@excalidraw/element/renderElement"; +import { getElementAbsoluteCoords } from "@excalidraw/element/bounds"; + import type { ExcalidrawElement, ExcalidrawTextElementWithContainer, diff --git a/packages/excalidraw/scene/export.ts b/packages/excalidraw/scene/export.ts index 9d08f23ec..229992354 100644 --- a/packages/excalidraw/scene/export.ts +++ b/packages/excalidraw/scene/export.ts @@ -15,8 +15,6 @@ import { toBrandedType, } from "@excalidraw/common"; -import { newTextElement } from "@excalidraw/element"; - import { getCommonBounds, getElementAbsoluteCoords, @@ -42,6 +40,8 @@ import { syncInvalidIndices } from "@excalidraw/element/fractionalIndex"; import { type Mutable } from "@excalidraw/common/utility-types"; +import { newTextElement } from "@excalidraw/element/newElement"; + import type { Bounds } from "@excalidraw/element/bounds"; import type { diff --git a/packages/excalidraw/scene/scroll.ts b/packages/excalidraw/scene/scroll.ts index 81504122a..a99ad075f 100644 --- a/packages/excalidraw/scene/scroll.ts +++ b/packages/excalidraw/scene/scroll.ts @@ -1,13 +1,13 @@ -import { - getCommonBounds, - getClosestElementBounds, - getVisibleElements, -} from "@excalidraw/element"; +import { getVisibleElements } from "@excalidraw/element"; import { sceneCoordsToViewportCoords, viewportCoordsToSceneCoords, } from "@excalidraw/common"; +import { getClosestElementBounds } from "@excalidraw/element/bounds"; + +import { getCommonBounds } from "@excalidraw/element/bounds"; + import type { ExcalidrawElement } from "@excalidraw/element/types"; import type { AppState, Offsets, PointerCoords, Zoom } from "../types"; diff --git a/packages/excalidraw/scene/scrollbars.ts b/packages/excalidraw/scene/scrollbars.ts index 142127e52..4fa4349f2 100644 --- a/packages/excalidraw/scene/scrollbars.ts +++ b/packages/excalidraw/scene/scrollbars.ts @@ -1,7 +1,7 @@ -import { getCommonBounds } from "@excalidraw/element"; - import { getGlobalCSSVariable } from "@excalidraw/common"; +import { getCommonBounds } from "@excalidraw/element/bounds"; + import type { ExcalidrawElement } from "@excalidraw/element/types"; import { getLanguage } from "../i18n"; diff --git a/packages/excalidraw/store.ts b/packages/excalidraw/store.ts index 48820eac5..5b3fc13d1 100644 --- a/packages/excalidraw/store.ts +++ b/packages/excalidraw/store.ts @@ -1,6 +1,6 @@ import { ENV, isShallowEqual } from "@excalidraw/common"; -import { deepCopyElement, newElementWith } from "@excalidraw/element"; +import { deepCopyElement } from "@excalidraw/element/newElement"; import type { OrderedExcalidrawElement } from "@excalidraw/element/types"; @@ -11,6 +11,8 @@ import { AppStateChange, ElementsChange } from "./change"; import { Emitter } from "./emitter"; +import { newElementWith } from "."; + import type { AppState, ObservedAppState } from "./types"; // hidden non-enumerable property for runtime checks diff --git a/packages/excalidraw/tests/clipboard.test.tsx b/packages/excalidraw/tests/clipboard.test.tsx index 8afa1bdc6..47d493da7 100644 --- a/packages/excalidraw/tests/clipboard.test.tsx +++ b/packages/excalidraw/tests/clipboard.test.tsx @@ -1,12 +1,12 @@ import React from "react"; import { vi } from "vitest"; -import { getElementBounds } from "@excalidraw/element"; - import { getLineHeightInPx } from "@excalidraw/element/textMeasurements"; import { KEYS, arrayToMap, getLineHeight } from "@excalidraw/common"; +import { getElementBounds } from "@excalidraw/element/bounds"; + import { createPasteEvent, serializeAsClipboardJSON } from "../clipboard"; import { Excalidraw } from "../index"; diff --git a/packages/excalidraw/tests/flip.test.tsx b/packages/excalidraw/tests/flip.test.tsx index 5a9ba41c7..5c3f3e295 100644 --- a/packages/excalidraw/tests/flip.test.tsx +++ b/packages/excalidraw/tests/flip.test.tsx @@ -3,9 +3,9 @@ import React from "react"; import { vi } from "vitest"; import { ROUNDNESS, KEYS, arrayToMap, cloneJSON } from "@excalidraw/common"; -import { getElementAbsoluteCoords } from "@excalidraw/element"; -import { newLinearElement } from "@excalidraw/element"; import { getBoundTextElementPosition } from "@excalidraw/element/textElement"; +import { getElementAbsoluteCoords } from "@excalidraw/element/bounds"; +import { newLinearElement } from "@excalidraw/element/newElement"; import type { LocalPoint } from "@excalidraw/math"; diff --git a/packages/excalidraw/tests/helpers/api.ts b/packages/excalidraw/tests/helpers/api.ts index 00f3fc638..2c72aa8e5 100644 --- a/packages/excalidraw/tests/helpers/api.ts +++ b/packages/excalidraw/tests/helpers/api.ts @@ -6,16 +6,18 @@ import { pointFrom, type LocalPoint, type Radians } from "@excalidraw/math"; import { DEFAULT_VERTICAL_ALIGN, ROUNDNESS } from "@excalidraw/common"; -import { newElement, newTextElement, newLinearElement } from "@excalidraw/element"; import { mutateElement } from "@excalidraw/element/mutateElement"; import { newArrowElement, + newElement, newEmbeddableElement, newFrameElement, newFreeDrawElement, newIframeElement, newImageElement, + newLinearElement, newMagicFrameElement, + newTextElement, } from "@excalidraw/element/newElement"; import { isLinearElementType } from "@excalidraw/element/typeChecks"; diff --git a/packages/utils/geometry/shape.ts b/packages/utils/geometry/shape.ts index 49ee76a07..0c802ff53 100644 --- a/packages/utils/geometry/shape.ts +++ b/packages/utils/geometry/shape.ts @@ -12,7 +12,6 @@ * to pure shapes */ -import { getElementAbsoluteCoords } from "@excalidraw/element"; import { invariant } from "@excalidraw/common"; import { curve, @@ -35,6 +34,8 @@ import { } from "@excalidraw/math"; import { pointsOnBezierCurves } from "points-on-curve"; +import { getElementAbsoluteCoords } from "@excalidraw/element/bounds"; + import type { ElementsMap, ExcalidrawBindableElement,