From e2c2218f6263a58b134b57d7c83e1d9a67bc5927 Mon Sep 17 00:00:00 2001 From: Marcel Mraz Date: Mon, 17 Mar 2025 17:01:19 +0100 Subject: [PATCH] Partialy fixing element package --- packages/common/index.ts | 2 + packages/common/src/binary-heap.ts | 2 +- packages/element/global.d.ts | 9 ++ packages/element/index.ts | 42 ++++++--- packages/element/{ => src}/binding.ts | 26 ++++-- packages/element/{ => src}/bounds.ts | 17 ++-- packages/element/{ => src}/collision.ts | 10 +- packages/element/{ => src}/containerCache.ts | 0 packages/element/{ => src}/cropElement.ts | 0 packages/element/{ => src}/distance.ts | 1 + packages/element/{ => src}/dragElements.ts | 24 +++-- packages/element/{ => src}/elbowArrow.ts | 16 +++- packages/element/{ => src}/elementLink.ts | 12 ++- packages/element/{ => src}/embeddable.ts | 13 ++- packages/element/{ => src}/flowchart.ts | 17 ++-- packages/element/{ => src}/frame.ts | 93 +++++++++++++++---- packages/element/{ => src}/heading.ts | 0 packages/element/{ => src}/image.ts | 9 +- .../element/{ => src}/linearElementEditor.ts | 51 ++++++---- packages/element/{ => src}/mutateElement.ts | 13 ++- packages/element/{ => src}/newElement.ts | 30 +++--- packages/element/{ => src}/resizeElements.ts | 20 ++-- packages/element/{ => src}/resizeTest.ts | 5 +- packages/element/{ => src}/shapes.ts | 2 +- .../{ => src}/showSelectedShapeActions.ts | 5 +- packages/element/{ => src}/sizeHelpers.ts | 9 +- packages/element/{ => src}/sortElements.ts | 2 +- packages/element/{ => src}/textElement.ts | 15 +-- .../element/{ => src}/textMeasurements.ts | 6 +- packages/element/{ => src}/textWrapping.ts | 2 +- .../element/{ => src}/transformHandles.ts | 17 ++-- packages/element/{ => src}/typeChecks.ts | 9 +- packages/element/{ => src}/types.ts | 5 +- packages/element/{ => src}/utils.ts | 4 +- packages/element/{ => tests}/bounds.test.ts | 9 +- .../element/{ => tests}/elbowArrow.test.tsx | 28 +++--- .../element/{ => tests}/flowchart.test.tsx | 17 ++-- .../element/{ => tests}/newElement.test.ts | 13 ++- .../element/{ => tests}/sizeHelpers.test.ts | 4 +- .../element/{ => tests}/sortElements.test.ts | 8 +- .../element/{ => tests}/textElement.test.ts | 10 +- .../element/{ => tests}/textWrapping.test.ts | 4 +- .../element/{ => tests}/typeChecks.test.ts | 4 +- packages/tsconfig.base.json | 2 +- tsconfig.json | 2 +- 45 files changed, 383 insertions(+), 206 deletions(-) create mode 100644 packages/element/global.d.ts rename packages/element/{ => src}/binding.ts (99%) rename packages/element/{ => src}/bounds.ts (99%) rename packages/element/{ => src}/collision.ts (97%) rename packages/element/{ => src}/containerCache.ts (100%) rename packages/element/{ => src}/cropElement.ts (100%) rename packages/element/{ => src}/distance.ts (99%) rename packages/element/{ => src}/dragElements.ts (97%) rename packages/element/{ => src}/elbowArrow.ts (99%) rename packages/element/{ => src}/elementLink.ts (88%) rename packages/element/{ => src}/embeddable.ts (97%) rename packages/element/{ => src}/flowchart.ts (98%) rename packages/element/{ => src}/frame.ts (91%) rename packages/element/{ => src}/heading.ts (100%) rename packages/element/{ => src}/image.ts (96%) rename packages/element/{ => src}/linearElementEditor.ts (99%) rename packages/element/{ => src}/mutateElement.ts (96%) rename packages/element/{ => src}/newElement.ts (98%) rename packages/element/{ => src}/resizeElements.ts (99%) rename packages/element/{ => src}/resizeTest.ts (98%) rename packages/element/{ => src}/shapes.ts (99%) rename packages/element/{ => src}/showSelectedShapeActions.ts (83%) rename packages/element/{ => src}/sizeHelpers.ts (97%) rename packages/element/{ => src}/sortElements.ts (98%) rename packages/element/{ => src}/textElement.ts (98%) rename packages/element/{ => src}/textMeasurements.ts (98%) rename packages/element/{ => src}/textWrapping.ts (99%) rename packages/element/{ => src}/transformHandles.ts (98%) rename packages/element/{ => src}/typeChecks.ts (97%) rename packages/element/{ => src}/types.ts (99%) rename packages/element/{ => src}/utils.ts (99%) rename packages/element/{ => tests}/bounds.test.ts (95%) rename packages/element/{ => tests}/elbowArrow.test.tsx (93%) rename packages/element/{ => tests}/flowchart.test.tsx (97%) rename packages/element/{ => tests}/newElement.test.ts (96%) rename packages/element/{ => tests}/sizeHelpers.test.ts (96%) rename packages/element/{ => tests}/sortElements.test.ts (97%) rename packages/element/{ => tests}/textElement.test.ts (95%) rename packages/element/{ => tests}/textWrapping.test.ts (99%) rename packages/element/{ => tests}/typeChecks.test.ts (93%) diff --git a/packages/common/index.ts b/packages/common/index.ts index 7fb63a890..ac31c5878 100644 --- a/packages/common/index.ts +++ b/packages/common/index.ts @@ -1,7 +1,9 @@ +export * from "./src/binary-heap"; export * from "./src/colors"; export * from "./src/constants"; export * from "./src/keys"; export * from "./src/points"; +export * from "./src/promise-pool"; export * from "./src/random"; export * from "./src/url"; export * from "./src/utils"; diff --git a/packages/common/src/binary-heap.ts b/packages/common/src/binary-heap.ts index 0bacadceb..788a05c22 100644 --- a/packages/common/src/binary-heap.ts +++ b/packages/common/src/binary-heap.ts @@ -1,4 +1,4 @@ -export default class BinaryHeap { +export class BinaryHeap { private content: T[] = []; constructor(private scoreFunction: (node: T) => number) {} diff --git a/packages/element/global.d.ts b/packages/element/global.d.ts new file mode 100644 index 000000000..2f3f0e133 --- /dev/null +++ b/packages/element/global.d.ts @@ -0,0 +1,9 @@ +interface ImportMetaEnv { + MODE: string; + DEV: string; + PROD: string; +} + +interface ImportMeta { + readonly env: ImportMetaEnv; +} diff --git a/packages/element/index.ts b/packages/element/index.ts index abe84e031..7eea01992 100644 --- a/packages/element/index.ts +++ b/packages/element/index.ts @@ -1,11 +1,17 @@ -import { isInvisiblySmallElement } from "./sizeHelpers"; -import { isLinearElementType } from "./typeChecks"; +import { isInvisiblySmallElement } from "./src/sizeHelpers"; +import { isLinearElementType } from "./src/typeChecks"; import type { ExcalidrawElement, NonDeletedExcalidrawElement, NonDeleted, -} from "./types"; +} from "./src/types"; + +export { + aabbForElement, + getElementShape, + pointInsideBounds, +} from "./src/shapes"; export { newElement, @@ -15,7 +21,8 @@ export { newArrowElement, newImageElement, duplicateElement, -} from "./newElement"; +} from "./src/newElement"; + export { getElementAbsoluteCoords, getElementBounds, @@ -23,39 +30,48 @@ export { getDiamondPoints, getArrowheadPoints, getClosestElementBounds, -} from "./bounds"; +} from "./src/bounds"; export { OMIT_SIDES_FOR_MULTIPLE_ELEMENTS, getTransformHandlesFromCoords, getTransformHandles, -} from "./transformHandles"; +} from "./src/transformHandles"; + export { resizeTest, getCursorForResizingElement, getElementWithTransformHandleType, getTransformHandleTypeFromCoords, -} from "./resizeTest"; +} from "./src/resizeTest"; + export { transformElements, getResizeOffsetXY, getResizeArrowDirection, -} from "./resizeElements"; +} from "./src/resizeElements"; + export { dragSelectedElements, getDragOffsetXY, dragNewElement, -} from "./dragElements"; -export { isTextElement, isExcalidrawElement } from "./typeChecks"; -export { redrawTextBoundingBox, getTextFromElements } from "./textElement"; +} from "./src/dragElements"; + +export { isTextElement, isExcalidrawElement } from "./src/typeChecks"; +export { redrawTextBoundingBox, getTextFromElements } from "./src/textElement"; + export { getPerfectElementSize, getLockedLinearCursorAlignSize, isInvisiblySmallElement, resizePerfectLineForNWHandler, getNormalizedDimensions, -} from "./sizeHelpers"; -export { showSelectedShapeActions } from "./showSelectedShapeActions"; +} from "./src/sizeHelpers"; + +export { showSelectedShapeActions } from "./src/showSelectedShapeActions"; + +export * from "./src/frame"; +export * from "./src/shapes"; /** * @deprecated unsafe, use hashElementsVersion instead diff --git a/packages/element/binding.ts b/packages/element/src/binding.ts similarity index 99% rename from packages/element/binding.ts rename to packages/element/src/binding.ts index fa472d211..cc52d94b8 100644 --- a/packages/element/binding.ts +++ b/packages/element/src/binding.ts @@ -1,3 +1,10 @@ +import { + KEYS, + arrayToMap, + isBindingFallthroughEnabled, + tupleToCoors, +} from "@excalidraw/common"; + import { lineSegment, pointFrom, @@ -16,17 +23,20 @@ import { round, PRECISION, } from "@excalidraw/math"; + +import { + aabbForElement, + getElementShape, + pointInsideBounds, +} from "@excalidraw/element"; + import { isPointOnShape } from "@excalidraw/utils/collision"; import type { LocalPoint, Radians } from "@excalidraw/math"; -import { KEYS } from "../keys"; -import { aabbForElement, getElementShape, pointInsideBounds } from "../shapes"; -import { - arrayToMap, - isBindingFallthroughEnabled, - tupleToCoors, -} from "../utils"; +import type Scene from "@excalidraw/excalidraw/scene/Scene"; + +import type { AppState } from "@excalidraw/excalidraw/types"; import { getCenterForBounds, @@ -79,8 +89,6 @@ import type { SceneElementsMap, FixedPointBinding, } from "./types"; -import type Scene from "../scene/Scene"; -import type { AppState } from "../types"; export type SuggestedBinding = | NonDeleted diff --git a/packages/element/bounds.ts b/packages/element/src/bounds.ts similarity index 99% rename from packages/element/bounds.ts rename to packages/element/src/bounds.ts index bb1cf7a0a..0fc428a5a 100644 --- a/packages/element/bounds.ts +++ b/packages/element/src/bounds.ts @@ -1,3 +1,7 @@ +import rough from "roughjs/bin/rough"; + +import { rescalePoints, arrayToMap, invariant } from "@excalidraw/common"; + import { degreesToRadians, lineSegment, @@ -6,8 +10,10 @@ import { pointFromArray, pointRotateRads, } from "@excalidraw/math"; + import { getCurvePathOps } from "@excalidraw/utils/geometry/shape"; -import rough from "roughjs/bin/rough"; +import { generateRoughOptions } from "@excalidraw/excalidraw/scene/Shape"; +import { ShapeCache } from "@excalidraw/excalidraw/scene/ShapeCache"; import type { Degrees, @@ -17,10 +23,9 @@ import type { Radians, } from "@excalidraw/math"; -import { rescalePoints } from "@excalidraw/excalidraw/points"; -import { generateRoughOptions } from "@excalidraw/excalidraw/scene/Shape"; -import { ShapeCache } from "@excalidraw/excalidraw/scene/ShapeCache"; -import { arrayToMap, invariant } from "@excalidraw/excalidraw/utils"; +import type { AppState } from "@excalidraw/excalidraw/types"; + +import type { Mutable } from "@excalidraw/excalidraw/utility-types"; import { LinearElementEditor } from "./linearElementEditor"; import { getBoundTextElement, getContainerElement } from "./textElement"; @@ -32,8 +37,6 @@ import { isTextElement, } from "./typeChecks"; -import type { AppState } from "../types"; -import type { Mutable } from "../utility-types"; import type { ExcalidrawElement, ExcalidrawLinearElement, diff --git a/packages/element/collision.ts b/packages/element/src/collision.ts similarity index 97% rename from packages/element/collision.ts rename to packages/element/src/collision.ts index a86cbd62f..1e223709f 100644 --- a/packages/element/collision.ts +++ b/packages/element/src/collision.ts @@ -1,3 +1,4 @@ +import { isTransparent } from "@excalidraw/common"; import { curveIntersectLineSegment, isPointWithinBounds, @@ -8,13 +9,17 @@ import { pointRotateRads, pointsEqual, } from "@excalidraw/math"; + import { ellipse, ellipseLineIntersectionPoints, } from "@excalidraw/math/ellipse"; + 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, @@ -22,10 +27,10 @@ import type { Polygon, Radians, } from "@excalidraw/math"; + import type { GeometricShape } from "@excalidraw/utils/geometry/shape"; -import { getBoundTextShape, isPathALoop } from "../shapes"; -import { isTransparent } from "../utils"; +import type { FrameNameBounds } from "@excalidraw/excalidraw/types"; import { getElementBounds } from "./bounds"; import { @@ -47,7 +52,6 @@ import type { ExcalidrawRectangleElement, ExcalidrawRectanguloidElement, } from "./types"; -import type { FrameNameBounds } from "../types"; export const shouldTestInside = (element: ExcalidrawElement) => { if (element.type === "arrow") { diff --git a/packages/element/containerCache.ts b/packages/element/src/containerCache.ts similarity index 100% rename from packages/element/containerCache.ts rename to packages/element/src/containerCache.ts diff --git a/packages/element/cropElement.ts b/packages/element/src/cropElement.ts similarity index 100% rename from packages/element/cropElement.ts rename to packages/element/src/cropElement.ts diff --git a/packages/element/distance.ts b/packages/element/src/distance.ts similarity index 99% rename from packages/element/distance.ts rename to packages/element/src/distance.ts index 038233555..d9db939e4 100644 --- a/packages/element/distance.ts +++ b/packages/element/src/distance.ts @@ -4,6 +4,7 @@ import { pointFrom, pointRotateRads, } from "@excalidraw/math"; + import { ellipse, ellipseDistanceFromPoint } from "@excalidraw/math/ellipse"; import type { GlobalPoint, Radians } from "@excalidraw/math"; diff --git a/packages/element/dragElements.ts b/packages/element/src/dragElements.ts similarity index 97% rename from packages/element/dragElements.ts rename to packages/element/src/dragElements.ts index 4cc408b21..8881369c3 100644 --- a/packages/element/dragElements.ts +++ b/packages/element/src/dragElements.ts @@ -1,6 +1,17 @@ -import { TEXT_AUTOWRAP_THRESHOLD } from "../constants"; -import { getGridPoint } from "../snapping"; -import { getFontString } from "../utils"; +import { + TEXT_AUTOWRAP_THRESHOLD, + getGridPoint, + getFontString, +} from "@excalidraw/common"; + +import type { + AppState, + NormalizedZoomValue, + NullableGridSize, + PointerDownState, +} from "@excalidraw/excalidraw/types"; + +import type Scene from "@excalidraw/excalidraw/scene/Scene"; import { updateBoundElements } from "./binding"; import { getCommonBounds } from "./bounds"; @@ -18,13 +29,6 @@ import { import type { Bounds } from "./bounds"; import type { NonDeletedExcalidrawElement } from "./types"; -import type Scene from "../scene/Scene"; -import type { - AppState, - NormalizedZoomValue, - NullableGridSize, - PointerDownState, -} from "../types"; export const dragSelectedElements = ( pointerDownState: PointerDownState, diff --git a/packages/element/elbowArrow.ts b/packages/element/src/elbowArrow.ts similarity index 99% rename from packages/element/elbowArrow.ts rename to packages/element/src/elbowArrow.ts index 5b8dc3813..09e137657 100644 --- a/packages/element/elbowArrow.ts +++ b/packages/element/src/elbowArrow.ts @@ -13,10 +13,17 @@ import { type LocalPoint, } from "@excalidraw/math"; -import BinaryHeap from "../binaryheap"; -import { getSizeFromPoints } from "../points"; -import { aabbForElement, pointInsideBounds } from "../shapes"; -import { invariant, isAnyTrue, tupleToCoors } from "../utils"; +import { + BinaryHeap, + invariant, + isAnyTrue, + tupleToCoors, + getSizeFromPoints, +} from "@excalidraw/common"; + +import { aabbForElement, pointInsideBounds } from "@excalidraw/element"; + +import type { AppState } from "@excalidraw/excalidraw/types"; import { bindPointToSnapToElementOutline, @@ -57,7 +64,6 @@ import type { FixedSegment, NonDeletedExcalidrawElement, } from "./types"; -import type { AppState } from "../types"; type GridAddress = [number, number] & { _brand: "gridaddress" }; diff --git a/packages/element/elementLink.ts b/packages/element/src/elementLink.ts similarity index 88% rename from packages/element/elementLink.ts rename to packages/element/src/elementLink.ts index 79b689c93..559aab962 100644 --- a/packages/element/elementLink.ts +++ b/packages/element/src/elementLink.ts @@ -2,12 +2,14 @@ * Create and link between shapes. */ -import { ELEMENT_LINK_KEY } from "../constants"; -import { normalizeLink } from "../data/url"; -import { elementsAreInSameGroup } from "../groups"; +import { + ELEMENT_LINK_KEY, + normalizeLink, + elementsAreInSameGroup, +} from "@excalidraw/common"; -import type { AppProps, AppState } from "../types"; -import type { ExcalidrawElement } from "./types"; +import type { AppProps, AppState } from "@excalidraw/excalidraw/types"; +import type { ExcalidrawElement } from "@excalidraw/element/types"; export const defaultGetElementLinkFromSelection: Exclude< AppProps["generateLinkForSelection"], diff --git a/packages/element/embeddable.ts b/packages/element/src/embeddable.ts similarity index 97% rename from packages/element/embeddable.ts rename to packages/element/src/embeddable.ts index 3fcb19b00..16ac97f65 100644 --- a/packages/element/embeddable.ts +++ b/packages/element/src/embeddable.ts @@ -1,12 +1,17 @@ -import { FONT_FAMILY, VERTICAL_ALIGN } from "../constants"; -import { escapeDoubleQuotes, getFontString } from "../utils"; +import { + FONT_FAMILY, + VERTICAL_ALIGN, + escapeDoubleQuotes, + getFontString, +} from "@excalidraw/common"; + +import type { ExcalidrawProps } from "@excalidraw/excalidraw/types"; +import type { MarkRequired } from "@excalidraw/excalidraw/utility-types"; import { newTextElement } from "./newElement"; import { wrapText } from "./textWrapping"; import { isIframeElement } from "./typeChecks"; -import type { ExcalidrawProps } from "../types"; -import type { MarkRequired } from "../utility-types"; import type { ExcalidrawElement, ExcalidrawIframeLikeElement, diff --git a/packages/element/flowchart.ts b/packages/element/src/flowchart.ts similarity index 98% rename from packages/element/flowchart.ts rename to packages/element/src/flowchart.ts index 9880f27af..664b25a1c 100644 --- a/packages/element/flowchart.ts +++ b/packages/element/src/flowchart.ts @@ -1,9 +1,14 @@ -import { pointFrom, type LocalPoint } from "@excalidraw/math"; +import { + elementOverlapsWithFrame, + elementsAreInFrameBounds, +} from "@excalidraw/element"; +import { KEYS, invariant, toBrandedType } from "@excalidraw/common"; +import { aabbForElement } from "@excalidraw/element"; -import { elementOverlapsWithFrame, elementsAreInFrameBounds } from "../frame"; -import { KEYS } from "../keys"; -import { aabbForElement } from "../shapes"; -import { invariant, toBrandedType } from "../utils"; +import type { + AppState, + PendingExcalidrawElements, +} from "@excalidraw/excalidraw/types"; import { bindLinearElement } from "./binding"; import { updateElbowArrowPoints } from "./elbowArrow"; @@ -35,8 +40,6 @@ import { type OrderedExcalidrawElement, } from "./types"; -import type { AppState, PendingExcalidrawElements } from "../types"; - type LinkDirection = "up" | "right" | "down" | "left"; const VERTICAL_OFFSET = 100; diff --git a/packages/element/frame.ts b/packages/element/src/frame.ts similarity index 91% rename from packages/element/frame.ts rename to packages/element/src/frame.ts index 448ea239e..edeb360fe 100644 --- a/packages/element/frame.ts +++ b/packages/element/src/frame.ts @@ -1,24 +1,22 @@ +import { arrayToMap } from "@excalidraw/common"; import { isPointWithinBounds, pointFrom } from "@excalidraw/math"; import { doLineSegmentsIntersect, elementsOverlappingBBox, + getCommonBounds, } from "@excalidraw/utils"; import { - getCommonBounds, - getElementAbsoluteCoords, - isTextElement, -} from "./element"; -import { getElementLineSegments } from "./element/bounds"; -import { mutateElement } from "./element/mutateElement"; + getElementsInGroup, + selectGroupsFromGivenElements, +} from "@excalidraw/excalidraw/groups"; + import { - getBoundTextElement, - getContainerElement, -} from "./element/textElement"; -import { isFrameElement, isFrameLikeElement } from "./element/typeChecks"; -import { getElementsInGroup, selectGroupsFromGivenElements } from "../excalidraw/groups"; -import { getElementsWithinSelection, getSelectedElements } from "../excalidraw/scene"; -import { arrayToMap } from "./utils"; + getElementsWithinSelection, + getSelectedElements, +} from "@excalidraw/excalidraw/scene"; + +import { getElementAbsoluteCoords, isTextElement } from "@excalidraw/element"; import type { ElementsMap, @@ -27,14 +25,22 @@ import type { ExcalidrawFrameLikeElement, NonDeleted, NonDeletedExcalidrawElement, -} from "./element/types"; -import type { ExcalidrawElementsIncludingDeleted } from "../excalidraw/scene/Scene"; +} from "@excalidraw/element/types"; + +import type { ExcalidrawElementsIncludingDeleted } from "@excalidraw/excalidraw/scene/Scene"; + import type { AppClassProperties, AppState, StaticCanvasAppState, -} from "../excalidraw/types"; -import type { ReadonlySetLike } from "../excalidraw/utility-types"; +} from "@excalidraw/excalidraw/types"; + +import type { ReadonlySetLike } from "@excalidraw/excalidraw/utility-types"; + +import { getElementLineSegments } from "./bounds"; +import { mutateElement } from "./mutateElement"; +import { getBoundTextElement, getContainerElement } from "./textElement"; +import { isFrameElement, isFrameLikeElement } from "./typeChecks"; // --------------------------- Frame State ------------------------------------ export const bindElementsToFramesAfterDuplication = ( @@ -99,6 +105,59 @@ export const getElementsCompletelyInFrame = ( element.frameId === frame.id, ); +export const isElementContainingFrame = ( + element: ExcalidrawElement, + frame: ExcalidrawFrameLikeElement, + elementsMap: ElementsMap, +) => { + return getElementsWithinSelection([frame], element, elementsMap).some( + (e) => e.id === frame.id, + ); +}; + +export const getElementsIntersectingFrame = ( + elements: readonly ExcalidrawElement[], + frame: ExcalidrawFrameLikeElement, +) => { + const elementsMap = arrayToMap(elements); + return elements.filter((element) => + isElementIntersectingFrame(element, frame, elementsMap), + ); +}; + +export const elementsAreInFrameBounds = ( + elements: readonly ExcalidrawElement[], + frame: ExcalidrawFrameLikeElement, + elementsMap: ElementsMap, +) => { + const [frameX1, frameY1, frameX2, frameY2] = getElementAbsoluteCoords( + frame, + elementsMap, + ); + + const [elementX1, elementY1, elementX2, elementY2] = + getCommonBounds(elements); + + return ( + frameX1 <= elementX1 && + frameY1 <= elementY1 && + frameX2 >= elementX2 && + frameY2 >= elementY2 + ); +}; + +export const elementOverlapsWithFrame = ( + element: ExcalidrawElement, + frame: ExcalidrawFrameLikeElement, + elementsMap: ElementsMap, +) => { + return ( + elementsAreInFrameBounds([element], frame, elementsMap) || + isElementIntersectingFrame(element, frame, elementsMap) || + isElementContainingFrame(element, frame, elementsMap) + ); +}; + export const isCursorInFrame = ( cursorCoords: { x: number; diff --git a/packages/element/heading.ts b/packages/element/src/heading.ts similarity index 100% rename from packages/element/heading.ts rename to packages/element/src/heading.ts diff --git a/packages/element/image.ts b/packages/element/src/image.ts similarity index 96% rename from packages/element/image.ts rename to packages/element/src/image.ts index 0d5f9fb5a..562b48904 100644 --- a/packages/element/image.ts +++ b/packages/element/src/image.ts @@ -2,11 +2,16 @@ // ExcalidrawImageElement & related helpers // ----------------------------------------------------------------------------- -import { MIME_TYPES, SVG_NS } from "../constants"; +import { MIME_TYPES, SVG_NS } from "@excalidraw/common"; + +import type { + AppClassProperties, + DataURL, + BinaryFiles, +} from "@excalidraw/excalidraw/types"; import { isInitializedImageElement } from "./typeChecks"; -import type { AppClassProperties, DataURL, BinaryFiles } from "../types"; import type { ExcalidrawElement, FileId, diff --git a/packages/element/linearElementEditor.ts b/packages/element/src/linearElementEditor.ts similarity index 99% rename from packages/element/linearElementEditor.ts rename to packages/element/src/linearElementEditor.ts index f9b23f048..020f70a76 100644 --- a/packages/element/linearElementEditor.ts +++ b/packages/element/src/linearElementEditor.ts @@ -8,22 +8,46 @@ import { pointDistance, vectorFromPoint, } from "@excalidraw/math"; + import { getCurvePathOps } from "@excalidraw/utils/geometry/shape"; -import type { Radians } from "@excalidraw/math"; +import { + DRAGGING_THRESHOLD, + KEYS, + shouldRotateWithDiscreteAngle, + getGridPoint, + invariant, + tupleToCoors, +} from "@excalidraw/common"; +import { ShapeCache } from "@excalidraw/excalidraw/scene/ShapeCache"; -import { DRAGGING_THRESHOLD } from "../constants"; -import { KEYS, shouldRotateWithDiscreteAngle } from "../keys"; -import { ShapeCache } from "../scene/ShapeCache"; import { getBezierCurveLength, getBezierXY, getControlPointsForBezierCurve, isPathALoop, mapIntervalToBezierT, -} from "../shapes"; -import { getGridPoint } from "../snapping"; -import { invariant, tupleToCoors } from "../utils"; +} from "@excalidraw/element"; + +import type { Radians } from "@excalidraw/math"; + +import type Scene from "@excalidraw/excalidraw/scene/Scene"; + +import type { + AppState, + PointerCoords, + InteractiveCanvasAppState, + AppClassProperties, + NullableGridSize, + Zoom, +} from "@excalidraw/excalidraw/types"; + +import type { Mutable } from "@excalidraw/excalidraw/utility-types"; + +import { + getElementAbsoluteCoords, + getLockedLinearCursorAlignSize, +} from "../index"; import { bindOrUnbindLinearElement, @@ -40,8 +64,6 @@ import { isFixedPointBinding, } from "./typeChecks"; -import { getElementAbsoluteCoords, getLockedLinearCursorAlignSize } from "."; - import type { Bounds } from "./bounds"; import type { NonDeleted, @@ -57,17 +79,6 @@ import type { FixedSegment, ExcalidrawElbowArrowElement, } from "./types"; -import type Scene from "../scene/Scene"; -import type { Store } from "../store"; -import type { - AppState, - PointerCoords, - InteractiveCanvasAppState, - AppClassProperties, - NullableGridSize, - Zoom, -} from "../types"; -import type { Mutable } from "../utility-types"; const editorMidPointsCache: { version: number | null; diff --git a/packages/element/mutateElement.ts b/packages/element/src/mutateElement.ts similarity index 96% rename from packages/element/mutateElement.ts rename to packages/element/src/mutateElement.ts index fc96ec312..3f0604354 100644 --- a/packages/element/mutateElement.ts +++ b/packages/element/src/mutateElement.ts @@ -1,16 +1,21 @@ +import { + getSizeFromPoints, + randomInteger, + getUpdatedTimestamp, + toBrandedType, +} from "@excalidraw/common"; + import type { Radians } from "@excalidraw/math"; -import { getSizeFromPoints } from "../points"; -import { randomInteger } from "../random"; +import type { Mutable } from "@excalidraw/excalidraw/utility-types"; + import Scene from "../scene/Scene"; import { ShapeCache } from "../scene/ShapeCache"; -import { getUpdatedTimestamp, toBrandedType } from "../utils"; import { updateElbowArrowPoints } from "./elbowArrow"; import { isElbowArrow } from "./typeChecks"; import type { ExcalidrawElement, NonDeletedSceneElementsMap } from "./types"; -import type { Mutable } from "../utility-types"; export type ElementUpdate = Omit< Partial, diff --git a/packages/element/newElement.ts b/packages/element/src/newElement.ts similarity index 98% rename from packages/element/newElement.ts rename to packages/element/src/newElement.ts index d11c4c20f..84396dd10 100644 --- a/packages/element/newElement.ts +++ b/packages/element/src/newElement.ts @@ -1,5 +1,3 @@ -import type { Radians } from "@excalidraw/math"; - import { DEFAULT_ELEMENT_PROPS, DEFAULT_FONT_FAMILY, @@ -8,16 +6,28 @@ import { DEFAULT_VERTICAL_ALIGN, ORIG_ID, VERTICAL_ALIGN, -} from "../constants"; -import { getLineHeight } from "../fonts"; -import { getNewGroupIdsForDuplication } from "../groups"; -import { randomInteger, randomId } from "../random"; -import { + randomInteger, + randomId, + getNewGroupIdsForDuplication, arrayToMap, getFontString, getUpdatedTimestamp, isTestEnv, -} from "../utils"; +} from "@excalidraw/common"; + +import { getLineHeight } from "@excalidraw/excalidraw/fonts/FontMetadata"; + +import type { Radians } from "@excalidraw/math"; + +import type { AppState } from "@excalidraw/excalidraw/types"; + +import type { + MarkOptional, + Merge, + Mutable, +} from "@excalidraw/excalidraw/utility-types"; + +import { getElementAbsoluteCoords } from "../index"; import { getResizedElementAbsoluteCoords } from "./bounds"; import { bumpVersion, newElementWith } from "./mutateElement"; @@ -25,8 +35,6 @@ import { getBoundTextMaxWidth } from "./textElement"; import { normalizeText, measureText } from "./textMeasurements"; import { wrapText } from "./textWrapping"; -import { getElementAbsoluteCoords } from "."; - import type { ExcalidrawElement, ExcalidrawImageElement, @@ -50,8 +58,6 @@ import type { FixedSegment, ExcalidrawElbowArrowElement, } from "./types"; -import type { AppState } from "../types"; -import type { MarkOptional, Merge, Mutable } from "../utility-types"; export type ElementConstructorOpts = MarkOptional< Omit, diff --git a/packages/element/resizeElements.ts b/packages/element/src/resizeElements.ts similarity index 99% rename from packages/element/resizeElements.ts rename to packages/element/src/resizeElements.ts index cd51b8bd5..b69edb837 100644 --- a/packages/element/resizeElements.ts +++ b/packages/element/src/resizeElements.ts @@ -8,12 +8,21 @@ import { type LocalPoint, } from "@excalidraw/math"; +import { + MIN_FONT_SIZE, + SHIFT_LOCKING_ANGLE, + isInGroup, + rescalePoints, + getFontString, +} from "@excalidraw/common"; + import type { GlobalPoint } from "@excalidraw/math"; -import { MIN_FONT_SIZE, SHIFT_LOCKING_ANGLE } from "../constants"; -import { isInGroup } from "../groups"; -import { rescalePoints } from "../points"; -import { getFontString } from "../utils"; +import type Scene from "@excalidraw/excalidraw/scene/Scene"; + +import type { PointerDownState } from "@excalidraw/excalidraw/types"; + +import type { Mutable } from "@excalidraw/excalidraw/utility-types"; import { getArrowLocalFixedPoints, updateBoundElements } from "./binding"; import { @@ -67,9 +76,6 @@ import type { SceneElementsMap, ExcalidrawElbowArrowElement, } from "./types"; -import type Scene from "../scene/Scene"; -import type { PointerDownState } from "../types"; -import type { Mutable } from "../utility-types"; // Returns true when transform (resizing/rotation) happened export const transformElements = ( diff --git a/packages/element/resizeTest.ts b/packages/element/src/resizeTest.ts similarity index 98% rename from packages/element/resizeTest.ts rename to packages/element/src/resizeTest.ts index 1eb36d0b2..411dcf9a7 100644 --- a/packages/element/resizeTest.ts +++ b/packages/element/src/resizeTest.ts @@ -5,9 +5,11 @@ import { type Radians, } from "@excalidraw/math"; +import { SIDE_RESIZING_THRESHOLD } from "@excalidraw/common"; + import type { GlobalPoint, LineSegment, LocalPoint } from "@excalidraw/math"; -import { SIDE_RESIZING_THRESHOLD } from "../constants"; +import type { AppState, Device, Zoom } from "@excalidraw/excalidraw/types"; import { getElementAbsoluteCoords } from "./bounds"; import { @@ -18,7 +20,6 @@ import { } from "./transformHandles"; import { isImageElement, isLinearElement } from "./typeChecks"; -import type { AppState, Device, Zoom } from "../types"; import type { Bounds } from "./bounds"; import type { TransformHandleType, diff --git a/packages/element/shapes.ts b/packages/element/src/shapes.ts similarity index 99% rename from packages/element/shapes.ts rename to packages/element/src/shapes.ts index 0e0069f09..820d3cbff 100644 --- a/packages/element/shapes.ts +++ b/packages/element/src/shapes.ts @@ -41,7 +41,7 @@ import type { import type { NormalizedZoomValue, Zoom } from "./types"; /** - * get the pure geometric shape of an excalidraw element + * get the pure geometric shape of an excalidraw elementw * which is then used for hit detection */ export const getElementShape = ( diff --git a/packages/element/showSelectedShapeActions.ts b/packages/element/src/showSelectedShapeActions.ts similarity index 83% rename from packages/element/showSelectedShapeActions.ts rename to packages/element/src/showSelectedShapeActions.ts index 44c2e75c3..32e9d4c76 100644 --- a/packages/element/showSelectedShapeActions.ts +++ b/packages/element/src/showSelectedShapeActions.ts @@ -1,6 +1,7 @@ -import { getSelectedElements } from "../scene"; +import { getSelectedElements } from "@excalidraw/excalidraw/scene"; + +import type { UIAppState } from "@excalidraw/excalidraw/types"; -import type { UIAppState } from "../types"; import type { NonDeletedExcalidrawElement } from "./types"; export const showSelectedShapeActions = ( diff --git a/packages/element/sizeHelpers.ts b/packages/element/src/sizeHelpers.ts similarity index 97% rename from packages/element/sizeHelpers.ts rename to packages/element/src/sizeHelpers.ts index 33b13e188..7a84dadba 100644 --- a/packages/element/sizeHelpers.ts +++ b/packages/element/src/sizeHelpers.ts @@ -1,12 +1,15 @@ -import { SHIFT_LOCKING_ANGLE } from "../constants"; -import { viewportCoordsToSceneCoords } from "../utils"; +import { + SHIFT_LOCKING_ANGLE, + viewportCoordsToSceneCoords, +} from "@excalidraw/common"; + +import type { AppState, Offsets, Zoom } from "@excalidraw/excalidraw/types"; import { getCommonBounds, getElementBounds } from "./bounds"; import { mutateElement } from "./mutateElement"; import { isFreeDrawElement, isLinearElement } from "./typeChecks"; import type { ElementsMap, ExcalidrawElement } from "./types"; -import type { AppState, Offsets, Zoom } from "../types"; // TODO: remove invisible elements consistently actions, so that invisible elements are not recorded by the store, exported, broadcasted or persisted // - perhaps could be as part of a standalone 'cleanup' action, in addition to 'finalize' diff --git a/packages/element/sortElements.ts b/packages/element/src/sortElements.ts similarity index 98% rename from packages/element/sortElements.ts rename to packages/element/src/sortElements.ts index d395adf2f..c98ff9d52 100644 --- a/packages/element/sortElements.ts +++ b/packages/element/src/sortElements.ts @@ -1,4 +1,4 @@ -import { arrayToMapWithIndex } from "../utils"; +import { arrayToMapWithIndex } from "@excalidraw/common"; import type { ExcalidrawElement } from "./types"; diff --git a/packages/element/textElement.ts b/packages/element/src/textElement.ts similarity index 98% rename from packages/element/textElement.ts rename to packages/element/src/textElement.ts index 9893ba5d6..05d5fd6ce 100644 --- a/packages/element/textElement.ts +++ b/packages/element/src/textElement.ts @@ -5,8 +5,15 @@ import { DEFAULT_FONT_SIZE, TEXT_ALIGN, VERTICAL_ALIGN, -} from "../constants"; -import { getFontString, arrayToMap } from "../utils"; + getFontString, + arrayToMap, +} from "@excalidraw/common"; + +import type { AppState } from "@excalidraw/excalidraw/types"; + +import type { ExtractSetType } from "@excalidraw/excalidraw/utility-types"; + +import { isTextElement } from "../index"; import { resetOriginalContainerCache, @@ -18,8 +25,6 @@ import { measureText } from "./textMeasurements"; import { wrapText } from "./textWrapping"; import { isBoundToContainer, isArrowElement } from "./typeChecks"; -import { isTextElement } from "."; - import type { MaybeTransformHandleType } from "./transformHandles"; import type { ElementsMap, @@ -30,8 +35,6 @@ import type { ExcalidrawTextElementWithContainer, NonDeletedExcalidrawElement, } from "./types"; -import type { AppState } from "../types"; -import type { ExtractSetType } from "../utility-types"; export const redrawTextBoundingBox = ( textElement: ExcalidrawTextElement, diff --git a/packages/element/textMeasurements.ts b/packages/element/src/textMeasurements.ts similarity index 98% rename from packages/element/textMeasurements.ts rename to packages/element/src/textMeasurements.ts index 840896cfc..5e790261d 100644 --- a/packages/element/textMeasurements.ts +++ b/packages/element/src/textMeasurements.ts @@ -2,8 +2,10 @@ import { BOUND_TEXT_PADDING, DEFAULT_FONT_SIZE, DEFAULT_FONT_FAMILY, -} from "../constants"; -import { getFontString, isTestEnv, normalizeEOL } from "../utils"; + getFontString, + isTestEnv, + normalizeEOL, +} from "@excalidraw/common"; import type { FontString, ExcalidrawTextElement } from "./types"; diff --git a/packages/element/textWrapping.ts b/packages/element/src/textWrapping.ts similarity index 99% rename from packages/element/textWrapping.ts rename to packages/element/src/textWrapping.ts index 5df7051c0..eb83f6d22 100644 --- a/packages/element/textWrapping.ts +++ b/packages/element/src/textWrapping.ts @@ -1,4 +1,4 @@ -import { ENV } from "../constants"; +import { ENV } from "@excalidraw/common"; import { charWidth, getLineWidth } from "./textMeasurements"; diff --git a/packages/element/transformHandles.ts b/packages/element/src/transformHandles.ts similarity index 98% rename from packages/element/transformHandles.ts rename to packages/element/src/transformHandles.ts index ab5691df8..f2b0cd278 100644 --- a/packages/element/transformHandles.ts +++ b/packages/element/src/transformHandles.ts @@ -1,12 +1,18 @@ -import { pointFrom, pointRotateRads } from "@excalidraw/math"; - -import type { Radians } from "@excalidraw/math"; - import { DEFAULT_TRANSFORM_HANDLE_SPACING, isAndroid, isIOS, -} from "../constants"; +} from "@excalidraw/common"; + +import { pointFrom, pointRotateRads } from "@excalidraw/math"; + +import type { Radians } from "@excalidraw/math"; + +import type { + Device, + InteractiveCanvasAppState, + Zoom, +} from "@excalidraw/excalidraw/types"; import { getElementAbsoluteCoords } from "./bounds"; import { @@ -16,7 +22,6 @@ import { isLinearElement, } from "./typeChecks"; -import type { Device, InteractiveCanvasAppState, Zoom } from "../types"; import type { Bounds } from "./bounds"; import type { ElementsMap, diff --git a/packages/element/typeChecks.ts b/packages/element/src/typeChecks.ts similarity index 97% rename from packages/element/typeChecks.ts rename to packages/element/src/typeChecks.ts index 77ac38f9d..4e7030e2d 100644 --- a/packages/element/typeChecks.ts +++ b/packages/element/src/typeChecks.ts @@ -1,8 +1,9 @@ -import { ROUNDNESS } from "../constants"; -import { assertNever } from "../utils"; +import { ROUNDNESS, assertNever } from "@excalidraw/common"; + +import type { ElementOrToolType } from "@excalidraw/excalidraw/types"; + +import type { MarkNonNullable } from "@excalidraw/excalidraw/utility-types"; -import type { ElementOrToolType } from "../types"; -import type { MarkNonNullable } from "../utility-types"; import type { Bounds } from "./bounds"; import type { ExcalidrawElement, diff --git a/packages/element/types.ts b/packages/element/src/types.ts similarity index 99% rename from packages/element/types.ts rename to packages/element/src/types.ts index 49ad800af..1066e7a5d 100644 --- a/packages/element/types.ts +++ b/packages/element/src/types.ts @@ -6,13 +6,14 @@ import type { TEXT_ALIGN, THEME, VERTICAL_ALIGN, -} from "../constants"; +} from "@excalidraw/common"; + import type { MakeBrand, MarkNonNullable, Merge, ValueOf, -} from "../utility-types"; +} from "@excalidraw/excalidraw/utility-types"; export type ChartType = "bar" | "line"; export type FillStyle = "hachure" | "cross-hatch" | "solid" | "zigzag"; diff --git a/packages/element/utils.ts b/packages/element/src/utils.ts similarity index 99% rename from packages/element/utils.ts rename to packages/element/src/utils.ts index 8992850dc..7042b5d8f 100644 --- a/packages/element/utils.ts +++ b/packages/element/src/utils.ts @@ -12,9 +12,9 @@ import { import type { Curve, LineSegment } from "@excalidraw/math"; -import { getCornerRadius } from "../shapes"; +import { getCornerRadius } from "./shapes"; -import { getDiamondPoints } from "."; +import { getDiamondPoints } from "./bounds"; import type { ExcalidrawDiamondElement, diff --git a/packages/element/bounds.test.ts b/packages/element/tests/bounds.test.ts similarity index 95% rename from packages/element/bounds.test.ts rename to packages/element/tests/bounds.test.ts index 936ebf797..22c669f28 100644 --- a/packages/element/bounds.test.ts +++ b/packages/element/tests/bounds.test.ts @@ -1,13 +1,12 @@ import { pointFrom } from "@excalidraw/math"; +import { arrayToMap, ROUNDNESS } from "@excalidraw/common"; + import type { LocalPoint } from "@excalidraw/math"; -import { ROUNDNESS } from "../constants"; -import { arrayToMap } from "../utils"; +import { getElementAbsoluteCoords, getElementBounds } from "../src/bounds"; -import { getElementAbsoluteCoords, getElementBounds } from "./bounds"; - -import type { ExcalidrawElement, ExcalidrawLinearElement } from "./types"; +import type { ExcalidrawElement, ExcalidrawLinearElement } from "../src/types"; const _ce = ({ x, diff --git a/packages/element/elbowArrow.test.tsx b/packages/element/tests/elbowArrow.test.tsx similarity index 93% rename from packages/element/elbowArrow.test.tsx rename to packages/element/tests/elbowArrow.test.tsx index 91e280d30..ccec88353 100644 --- a/packages/element/elbowArrow.test.tsx +++ b/packages/element/tests/elbowArrow.test.tsx @@ -1,31 +1,33 @@ +import { ARROW_TYPE } from "@excalidraw/common"; import { pointFrom } from "@excalidraw/math"; -import React from "react"; +import { Excalidraw, mutateElement } from "@excalidraw/excalidraw"; -import type { LocalPoint } from "@excalidraw/math"; +import Scene from "@excalidraw/excalidraw/scene/Scene"; +import { actionSelectAll } from "@excalidraw/excalidraw/actions"; +import { actionDuplicateSelection } from "@excalidraw/excalidraw/actions/actionDuplicateSelection"; + +import { API } from "@excalidraw/excalidraw/tests/helpers/api"; +import { Pointer, UI } from "@excalidraw/excalidraw/tests/helpers/ui"; -import "../../utils/test-utils"; -import { actionSelectAll } from "../actions"; -import { actionDuplicateSelection } from "../actions/actionDuplicateSelection"; -import { ARROW_TYPE } from "../constants"; -import { Excalidraw, mutateElement } from "../index"; -import Scene from "../scene/Scene"; -import { API } from "../tests/helpers/api"; -import { Pointer, UI } from "../tests/helpers/ui"; import { act, fireEvent, GlobalTestState, queryByTestId, render, -} from "../tests/test-utils"; +} from "@excalidraw/excalidraw/tests/test-utils"; -import { bindLinearElement } from "./binding"; +import { bindLinearElement } from "@excalidraw/element/binding"; + +import type { LocalPoint } from "@excalidraw/math"; import type { ExcalidrawArrowElement, ExcalidrawBindableElement, ExcalidrawElbowArrowElement, -} from "./types"; +} from "@excalidraw/element/types"; + +import "../../utils/test-utils"; const { h } = window; diff --git a/packages/element/flowchart.test.tsx b/packages/element/tests/flowchart.test.tsx similarity index 97% rename from packages/element/flowchart.test.tsx rename to packages/element/tests/flowchart.test.tsx index bc026e7d7..931462c5e 100644 --- a/packages/element/flowchart.test.tsx +++ b/packages/element/tests/flowchart.test.tsx @@ -1,9 +1,14 @@ -import { Excalidraw } from "../index"; -import { KEYS } from "../keys"; -import { reseed } from "../random"; -import { API } from "../tests/helpers/api"; -import { UI, Keyboard, Pointer } from "../tests/helpers/ui"; -import { render, unmountComponent } from "../tests/test-utils"; +import { KEYS } from "@excalidraw/common"; +import { reseed } from "@excalidraw/common"; + +import { Excalidraw } from "@excalidraw/excalidraw"; + +import { API } from "@excalidraw/excalidraw/tests/helpers/api"; +import { UI, Keyboard, Pointer } from "@excalidraw/excalidraw/tests/helpers/ui"; +import { + render, + unmountComponent, +} from "@excalidraw/excalidraw/tests/test-utils"; unmountComponent(); diff --git a/packages/element/newElement.test.ts b/packages/element/tests/newElement.test.ts similarity index 96% rename from packages/element/newElement.test.ts rename to packages/element/tests/newElement.test.ts index 418ede1be..748c43702 100644 --- a/packages/element/newElement.test.ts +++ b/packages/element/tests/newElement.test.ts @@ -1,15 +1,14 @@ import { pointFrom } from "@excalidraw/math"; +import { FONT_FAMILY, ROUNDNESS, isPrimitive } from "@excalidraw/common"; +import { API } from "@excalidraw/excalidraw/tests/helpers/api"; + import type { LocalPoint } from "@excalidraw/math"; -import { FONT_FAMILY, ROUNDNESS } from "../constants"; -import { API } from "../tests/helpers/api"; -import { isPrimitive } from "../utils"; +import { mutateElement } from "../src/mutateElement"; +import { duplicateElement, duplicateElements } from "../src/newElement"; -import { mutateElement } from "./mutateElement"; -import { duplicateElement, duplicateElements } from "./newElement"; - -import type { ExcalidrawLinearElement } from "./types"; +import type { ExcalidrawLinearElement } from "../src/types"; const assertCloneObjects = (source: any, clone: any) => { for (const key in clone) { diff --git a/packages/element/sizeHelpers.test.ts b/packages/element/tests/sizeHelpers.test.ts similarity index 96% rename from packages/element/sizeHelpers.test.ts rename to packages/element/tests/sizeHelpers.test.ts index c882e1f3c..89e3da850 100644 --- a/packages/element/sizeHelpers.test.ts +++ b/packages/element/tests/sizeHelpers.test.ts @@ -1,8 +1,8 @@ import { vi } from "vitest"; -import * as constants from "../constants"; +import * as constants from "@excalidraw/common"; -import { getPerfectElementSize } from "./sizeHelpers"; +import { getPerfectElementSize } from "../src/sizeHelpers"; const EPSILON_DIGITS = 3; // Needed so that we can mock the value of constants which is done in diff --git a/packages/element/sortElements.test.ts b/packages/element/tests/sortElements.test.ts similarity index 97% rename from packages/element/sortElements.test.ts rename to packages/element/tests/sortElements.test.ts index 5f7c4b2e6..509e5e9d0 100644 --- a/packages/element/sortElements.test.ts +++ b/packages/element/tests/sortElements.test.ts @@ -1,9 +1,9 @@ -import { API } from "../tests/helpers/api"; +import { API } from "@excalidraw/excalidraw/tests/helpers/api"; -import { mutateElement } from "./mutateElement"; -import { normalizeElementOrder } from "./sortElements"; +import { mutateElement } from "../src/mutateElement"; +import { normalizeElementOrder } from "../src/sortElements"; -import type { ExcalidrawElement } from "./types"; +import type { ExcalidrawElement } from "../src/types"; const assertOrder = ( elements: readonly ExcalidrawElement[], diff --git a/packages/element/textElement.test.ts b/packages/element/tests/textElement.test.ts similarity index 95% rename from packages/element/textElement.test.ts rename to packages/element/tests/textElement.test.ts index 9da7c79a4..9ff485d24 100644 --- a/packages/element/textElement.test.ts +++ b/packages/element/tests/textElement.test.ts @@ -1,17 +1,17 @@ import { getLineHeight } from "@excalidraw/excalidraw/fonts/FontMetadata"; +import { API } from "@excalidraw/excalidraw/tests/helpers/api"; -import { FONT_FAMILY } from "../constants"; -import { API } from "../tests/helpers/api"; +import { FONT_FAMILY } from "@excalidraw/common"; import { computeContainerDimensionForBoundText, getContainerCoords, getBoundTextMaxWidth, getBoundTextMaxHeight, -} from "./textElement"; -import { detectLineHeight, getLineHeightInPx } from "./textMeasurements"; +a} from "../src/textElement"; +import { detectLineHeight, getLineHeightInPx } from "../src/textMeasurements"; -import type { ExcalidrawTextElementWithContainer } from "./types"; +import type { ExcalidrawTextElementWithContainer } from "../src/types"; describe("Test measureText", () => { describe("Test getContainerCoords", () => { diff --git a/packages/element/textWrapping.test.ts b/packages/element/tests/textWrapping.test.ts similarity index 99% rename from packages/element/textWrapping.test.ts rename to packages/element/tests/textWrapping.test.ts index 357736a2e..87c96a4c9 100644 --- a/packages/element/textWrapping.test.ts +++ b/packages/element/tests/textWrapping.test.ts @@ -1,6 +1,6 @@ -import { wrapText, parseTokens } from "./textWrapping"; +import { wrapText, parseTokens } from "../src/textWrapping"; -import type { FontString } from "./types"; +import type { FontString } from "../src/types"; describe("Test wrapText", () => { // font is irrelevant as jsdom does not support FontFace API diff --git a/packages/element/typeChecks.test.ts b/packages/element/tests/typeChecks.test.ts similarity index 93% rename from packages/element/typeChecks.test.ts rename to packages/element/tests/typeChecks.test.ts index 44e4dd755..6be81aaa6 100644 --- a/packages/element/typeChecks.test.ts +++ b/packages/element/tests/typeChecks.test.ts @@ -1,6 +1,6 @@ -import { API } from "../tests/helpers/api"; +import { API } from "@excalidraw/excalidraw/tests/helpers/api"; -import { hasBoundTextElement } from "./typeChecks"; +import { hasBoundTextElement } from "../src/typeChecks"; describe("Test TypeChecks", () => { describe("Test hasBoundTextElement", () => { diff --git a/packages/tsconfig.base.json b/packages/tsconfig.base.json index 643fe7bc0..fa8c1ed6e 100644 --- a/packages/tsconfig.base.json +++ b/packages/tsconfig.base.json @@ -15,7 +15,7 @@ "@excalidraw/common": ["./common/index.ts"], "@excalidraw/common/*": ["./common/src/*"], "@excalidraw/element": ["./element/index.ts"], - "@excalidraw/element/*": ["./element/*"], + "@excalidraw/element/*": ["./element/src/*"], "@excalidraw/excalidraw": ["./excalidraw/index.tsx"], "@excalidraw/excalidraw/*": ["./excalidraw/*"], "@excalidraw/math": ["./math/index.ts"], diff --git a/tsconfig.json b/tsconfig.json index d5d6cecad..8fe3e2bdd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,7 +24,7 @@ "@excalidraw/excalidraw": ["./packages/excalidraw/index.tsx"], "@excalidraw/excalidraw/*": ["./packages/excalidraw/*"], "@excalidraw/element": ["./packages/element/index.ts"], - "@excalidraw/element/*": ["./packages/element/*"], + "@excalidraw/element/*": ["./packages/element/src/*"], "@excalidraw/math": ["./packages/math/index.ts"], "@excalidraw/math/*": ["./packages/math/src/*"], "@excalidraw/utils": ["./packages/utils/index.ts"],