diff --git a/packages/element/index.ts b/packages/element/index.ts index 7eea01992..afb00414b 100644 --- a/packages/element/index.ts +++ b/packages/element/index.ts @@ -7,71 +7,19 @@ import type { NonDeleted, } from "./src/types"; -export { - aabbForElement, - getElementShape, - pointInsideBounds, -} from "./src/shapes"; - -export { - newElement, - newTextElement, - refreshTextDimensions, - newLinearElement, - newArrowElement, - newImageElement, - duplicateElement, -} from "./src/newElement"; - -export { - getElementAbsoluteCoords, - getElementBounds, - getCommonBounds, - getDiamondPoints, - getArrowheadPoints, - getClosestElementBounds, -} from "./src/bounds"; - -export { - OMIT_SIDES_FOR_MULTIPLE_ELEMENTS, - getTransformHandlesFromCoords, - getTransformHandles, -} from "./src/transformHandles"; - -export { - resizeTest, - getCursorForResizingElement, - getElementWithTransformHandleType, - getTransformHandleTypeFromCoords, -} from "./src/resizeTest"; - -export { - transformElements, - getResizeOffsetXY, - getResizeArrowDirection, -} from "./src/resizeElements"; - -export { - dragSelectedElements, - getDragOffsetXY, - dragNewElement, -} from "./src/dragElements"; - -export { isTextElement, isExcalidrawElement } from "./src/typeChecks"; -export { redrawTextBoundingBox, getTextFromElements } from "./src/textElement"; - -export { - getPerfectElementSize, - getLockedLinearCursorAlignSize, - isInvisiblySmallElement, - resizePerfectLineForNWHandler, - getNormalizedDimensions, -} from "./src/sizeHelpers"; - -export { showSelectedShapeActions } from "./src/showSelectedShapeActions"; - +export * from "./src/bounds"; +export * from "./src/dragElements"; export * from "./src/frame"; +export * from "./src/mutateElement"; +export * from "./src/newElement"; +export * from "./src/resizeElements"; +export * from "./src/resizeTest"; export * from "./src/shapes"; +export * from "./src/showSelectedShapeActions"; +export * from "./src/textElement"; +export * from "./src/typeChecks"; +export * from "./src/transformHandles"; +export * from "./src/sizeHelpers"; /** * @deprecated unsafe, use hashElementsVersion instead diff --git a/packages/element/src/shapes.ts b/packages/element/src/shapes.ts index 820d3cbff..d103ace4a 100644 --- a/packages/element/src/shapes.ts +++ b/packages/element/src/shapes.ts @@ -1,3 +1,10 @@ +import { + DEFAULT_ADAPTIVE_RADIUS, + DEFAULT_PROPORTIONAL_RADIUS, + LINE_CONFIRM_THRESHOLD, + ROUNDNESS, + invariant, +} from "@excalidraw/common"; import { isPoint, pointFrom, @@ -18,27 +25,22 @@ import { type GeometricShape, } from "@excalidraw/utils/geometry/shape"; -import { - DEFAULT_ADAPTIVE_RADIUS, - DEFAULT_PROPORTIONAL_RADIUS, - LINE_CONFIRM_THRESHOLD, - ROUNDNESS, -} from "./constants"; -import { getElementAbsoluteCoords } from "./element"; -import { shouldTestInside } from "./element/collision"; -import { LinearElementEditor } from "./element/linearElementEditor"; -import { getBoundTextElement } from "./element/textElement"; -import { ShapeCache } from "./scene/ShapeCache"; -import { invariant } from "./utils"; +import type { NormalizedZoomValue, Zoom } from "@excalidraw/excalidraw/types"; -import type { Bounds } from "./element/bounds"; +import { getElementAbsoluteCoords } from "../index"; + +import { shouldTestInside } from "./collision"; +import { LinearElementEditor } from "./linearElementEditor"; +import { getBoundTextElement } from "./textElement"; +import { ShapeCache } from "./scene/ShapeCache"; + +import type { Bounds } from "./bounds"; import type { ElementsMap, ExcalidrawElement, ExcalidrawLinearElement, NonDeleted, -} from "./element/types"; -import type { NormalizedZoomValue, Zoom } from "./types"; +} from "./types"; /** * get the pure geometric shape of an excalidraw elementw diff --git a/packages/excalidraw/actions/actionAddToLibrary.ts b/packages/excalidraw/actions/actionAddToLibrary.ts index b246918a0..d8f1c65fa 100644 --- a/packages/excalidraw/actions/actionAddToLibrary.ts +++ b/packages/excalidraw/actions/actionAddToLibrary.ts @@ -1,7 +1,7 @@ -import { LIBRARY_DISABLED_TYPES } from "../constants"; -import { deepCopyElement } from "../element/newElement"; +import { LIBRARY_DISABLED_TYPES, randomId } from "@excalidraw/common"; +import { deepCopyElement } from "@excalidraw/element/newElement"; + import { t } from "../i18n"; -import { randomId } from "../random"; import { CaptureUpdateAction } from "../store"; import { register } from "./register"; diff --git a/packages/excalidraw/actions/actionAlign.tsx b/packages/excalidraw/actions/actionAlign.tsx index b42122a50..2b4b48698 100644 --- a/packages/excalidraw/actions/actionAlign.tsx +++ b/packages/excalidraw/actions/actionAlign.tsx @@ -1,3 +1,13 @@ +import { getNonDeletedElements } from "@excalidraw/element"; + +import { isFrameLikeElement } from "@excalidraw/element/typeChecks"; + +import { updateFrameMembershipOfSelectedElements } from "@excalidraw/element/frame"; + +import { KEYS, arrayToMap, getShortcutKey } from "@excalidraw/common"; + +import type { ExcalidrawElement } from "@excalidraw/element/types"; + import { alignElements } from "../align"; import { ToolButton } from "../components/ToolButton"; import { @@ -8,19 +18,15 @@ import { CenterHorizontallyIcon, CenterVerticallyIcon, } from "../components/icons"; -import { getNonDeletedElements } from "../element"; -import { isFrameLikeElement } from "../element/typeChecks"; -import { updateFrameMembershipOfSelectedElements } from "../frame"; + import { t } from "../i18n"; -import { KEYS } from "../keys"; + import { isSomeElementSelected } from "../scene"; import { CaptureUpdateAction } from "../store"; -import { arrayToMap, getShortcutKey } from "../utils"; import { register } from "./register"; import type { Alignment } from "../align"; -import type { ExcalidrawElement } from "../element/types"; import type { AppClassProperties, AppState, UIAppState } from "../types"; export const alignActionsPredicate = ( diff --git a/packages/excalidraw/actions/actionBoundText.tsx b/packages/excalidraw/actions/actionBoundText.tsx index 4da3f99a1..6a1fac903 100644 --- a/packages/excalidraw/actions/actionBoundText.tsx +++ b/packages/excalidraw/actions/actionBoundText.tsx @@ -3,38 +3,44 @@ import { ROUNDNESS, TEXT_ALIGN, VERTICAL_ALIGN, -} from "../constants"; -import { isTextElement, newElement } from "../element"; + arrayToMap, + getFontString, +} from "@excalidraw/common"; +import { isTextElement, newElement } from "@excalidraw/element"; import { getOriginalContainerHeightFromCache, resetOriginalContainerCache, updateOriginalContainerCache, -} from "../element/containerCache"; -import { mutateElement } from "../element/mutateElement"; +} from "@excalidraw/element/containerCache"; + import { computeBoundTextPosition, computeContainerDimensionForBoundText, getBoundTextElement, redrawTextBoundingBox, -} from "../element/textElement"; -import { measureText } from "../element/textMeasurements"; +} from "@excalidraw/element/textElement"; + import { hasBoundTextElement, isTextBindableContainer, isUsingAdaptiveRadius, -} from "../element/typeChecks"; -import { syncMovedIndices } from "../fractionalIndex"; -import { CaptureUpdateAction } from "../store"; -import { arrayToMap, getFontString } from "../utils"; +} from "@excalidraw/element/typeChecks"; -import { register } from "./register"; +import { mutateElement } from "@excalidraw/element/mutateElement"; +import { measureText } from "@excalidraw/element/textMeasurements"; import type { ExcalidrawElement, ExcalidrawLinearElement, ExcalidrawTextContainer, ExcalidrawTextElement, -} from "../element/types"; +} from "@excalidraw/element/types"; + +import { syncMovedIndices } from "../fractionalIndex"; +import { CaptureUpdateAction } from "../store"; + +import { register } from "./register"; + import type { AppState } from "../types"; import type { Mutable } from "../utility-types"; diff --git a/packages/excalidraw/actions/actionCanvas.tsx b/packages/excalidraw/actions/actionCanvas.tsx index f3e0a8a32..0f3e0bb3e 100644 --- a/packages/excalidraw/actions/actionCanvas.tsx +++ b/packages/excalidraw/actions/actionCanvas.tsx @@ -1,11 +1,31 @@ import { clamp, roundToStep } from "@excalidraw/math"; +import { + DEFAULT_CANVAS_BACKGROUND_PICKS, + CURSOR_TYPE, + MAX_ZOOM, + MIN_ZOOM, + THEME, + ZOOM_STEP, + getShortcutKey, + updateActiveTool, + CODES, + KEYS, +} from "@excalidraw/common"; + +import { getCommonBounds, getNonDeletedElements } from "@excalidraw/element"; + +import { newElementWith } from "@excalidraw/element/mutateElement"; + +import type { SceneBounds } from "@excalidraw/element/bounds"; + +import type { ExcalidrawElement } from "@excalidraw/element/types"; + import { getDefaultAppState, isEraserActive, isHandToolActive, } from "../appState"; -import { DEFAULT_CANVAS_BACKGROUND_PICKS } from "../colors"; import { ColorPicker } from "../components/ColorPicker/ColorPicker"; import { ToolButton } from "../components/ToolButton"; import { Tooltip } from "../components/Tooltip"; @@ -19,28 +39,16 @@ import { ZoomOutIcon, ZoomResetIcon, } from "../components/icons"; -import { - CURSOR_TYPE, - MAX_ZOOM, - MIN_ZOOM, - THEME, - ZOOM_STEP, -} from "../constants"; import { setCursor } from "../cursor"; -import { getCommonBounds, getNonDeletedElements } from "../element"; -import { newElementWith } from "../element/mutateElement"; + import { t } from "../i18n"; -import { CODES, KEYS } from "../keys"; import { getNormalizedZoom } from "../scene"; import { centerScrollOn } from "../scene/scroll"; import { getStateForZoom } from "../scene/zoom"; import { CaptureUpdateAction } from "../store"; -import { getShortcutKey, updateActiveTool } from "../utils"; import { register } from "./register"; -import type { SceneBounds } from "../element/bounds"; -import type { ExcalidrawElement } from "../element/types"; import type { AppState, Offsets } from "../types"; export const actionChangeViewBackgroundColor = register({ diff --git a/packages/excalidraw/actions/actionClipboard.tsx b/packages/excalidraw/actions/actionClipboard.tsx index 4ce3c39dd..9de6d70f4 100644 --- a/packages/excalidraw/actions/actionClipboard.tsx +++ b/packages/excalidraw/actions/actionClipboard.tsx @@ -1,3 +1,8 @@ +import { isTextElement } from "@excalidraw/element/typeChecks"; +import { getTextFromElements } from "@excalidraw/element/textElement"; + +import { CODES, KEYS, isFirefox } from "@excalidraw/common"; + import { copyTextToSystemClipboard, copyToClipboard, @@ -7,11 +12,9 @@ import { readSystemClipboard, } from "../clipboard"; import { DuplicateIcon, cutIcon, pngIcon, svgIcon } from "../components/icons"; -import { isFirefox } from "../constants"; import { exportCanvas, prepareElementsForExport } from "../data/index"; -import { getTextFromElements, isTextElement } from "../element"; import { t } from "../i18n"; -import { CODES, KEYS } from "../keys"; + import { CaptureUpdateAction } from "../store"; import { actionDeleteSelected } from "./actionDeleteSelected"; diff --git a/packages/excalidraw/actions/actionDeleteSelected.tsx b/packages/excalidraw/actions/actionDeleteSelected.tsx index fe3f8c5d7..3a0f86c85 100644 --- a/packages/excalidraw/actions/actionDeleteSelected.tsx +++ b/packages/excalidraw/actions/actionDeleteSelected.tsx @@ -1,26 +1,31 @@ -import { ToolButton } from "../components/ToolButton"; -import { TrashIcon } from "../components/icons"; -import { getNonDeletedElements } from "../element"; -import { fixBindingsAfterDeletion } from "../element/binding"; -import { LinearElementEditor } from "../element/linearElementEditor"; -import { mutateElement, newElementWith } from "../element/mutateElement"; -import { getContainerElement } from "../element/textElement"; +import { KEYS, updateActiveTool } from "@excalidraw/common"; + +import { getNonDeletedElements } from "@excalidraw/element"; +import { fixBindingsAfterDeletion } from "@excalidraw/element/binding"; +import { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; +import { + mutateElement, + newElementWith, +} from "@excalidraw/element/mutateElement"; +import { getContainerElement } from "@excalidraw/element/textElement"; import { isBoundToContainer, isElbowArrow, isFrameLikeElement, -} from "../element/typeChecks"; -import { getFrameChildren } from "../frame"; +} from "@excalidraw/element/typeChecks"; +import { getFrameChildren } from "@excalidraw/element/frame"; + +import type { ExcalidrawElement } from "@excalidraw/element/types"; + import { getElementsInGroup, selectGroupsForSelectedElements } from "../groups"; import { t } from "../i18n"; -import { KEYS } from "../keys"; import { getSelectedElements, isSomeElementSelected } from "../scene"; import { CaptureUpdateAction } from "../store"; -import { updateActiveTool } from "../utils"; +import { TrashIcon } from "../components/icons"; +import { ToolButton } from "../components/ToolButton"; import { register } from "./register"; -import type { ExcalidrawElement } from "../element/types"; import type { AppClassProperties, AppState } from "../types"; const deleteSelectedElements = ( diff --git a/packages/excalidraw/actions/actionDistribute.tsx b/packages/excalidraw/actions/actionDistribute.tsx index c96bdaa3e..7af39e955 100644 --- a/packages/excalidraw/actions/actionDistribute.tsx +++ b/packages/excalidraw/actions/actionDistribute.tsx @@ -1,22 +1,29 @@ +import { getNonDeletedElements } from "@excalidraw/element"; + +import { isFrameLikeElement } from "@excalidraw/element/typeChecks"; + +import { CODES, KEYS, arrayToMap, getShortcutKey } from "@excalidraw/common"; + +import { updateFrameMembershipOfSelectedElements } from "@excalidraw/element/frame"; + +import type { ExcalidrawElement } from "@excalidraw/element/types"; + import { ToolButton } from "../components/ToolButton"; import { DistributeHorizontallyIcon, DistributeVerticallyIcon, } from "../components/icons"; import { distributeElements } from "../distribute"; -import { getNonDeletedElements } from "../element"; -import { isFrameLikeElement } from "../element/typeChecks"; -import { updateFrameMembershipOfSelectedElements } from "../frame"; + import { t } from "../i18n"; -import { CODES, KEYS } from "../keys"; + import { isSomeElementSelected } from "../scene"; import { CaptureUpdateAction } from "../store"; -import { arrayToMap, getShortcutKey } from "../utils"; import { register } from "./register"; import type { Distribution } from "../distribute"; -import type { ExcalidrawElement } from "../element/types"; + import type { AppClassProperties, AppState } from "../types"; const enableActionGroup = (appState: AppState, app: AppClassProperties) => { diff --git a/packages/excalidraw/actions/actionDuplicateSelection.test.tsx b/packages/excalidraw/actions/actionDuplicateSelection.test.tsx index 2c1d44e92..e005949a6 100644 --- a/packages/excalidraw/actions/actionDuplicateSelection.test.tsx +++ b/packages/excalidraw/actions/actionDuplicateSelection.test.tsx @@ -1,6 +1,5 @@ -import React from "react"; +import { ORIG_ID } from "@excalidraw/common"; -import { ORIG_ID } from "../constants"; import { Excalidraw } from "../index"; import { API } from "../tests/helpers/api"; import { diff --git a/packages/excalidraw/actions/actionDuplicateSelection.tsx b/packages/excalidraw/actions/actionDuplicateSelection.tsx index ce225a1d6..0eed6ecc8 100644 --- a/packages/excalidraw/actions/actionDuplicateSelection.tsx +++ b/packages/excalidraw/actions/actionDuplicateSelection.tsx @@ -1,49 +1,60 @@ -import { ToolButton } from "../components/ToolButton"; -import { DuplicateIcon } from "../components/icons"; -import { DEFAULT_GRID_SIZE } from "../constants"; -import { duplicateElement, getNonDeletedElements } from "../element"; -import { fixBindingsAfterDuplication } from "../element/binding"; +import { + DEFAULT_GRID_SIZE, + KEYS, + arrayToMap, + castArray, + findLastIndex, + getShortcutKey, + invariant, +} from "@excalidraw/common"; + +import { duplicateElement, getNonDeletedElements } from "@excalidraw/element"; + +import { fixBindingsAfterDuplication } from "@excalidraw/element/binding"; + import { bindTextToShapeAfterDuplication, getBoundTextElement, getContainerElement, -} from "../element/textElement"; +} from "@excalidraw/element/textElement"; + import { hasBoundTextElement, isBoundToContainer, isFrameLikeElement, -} from "../element/typeChecks"; -import { normalizeElementOrder } from "../element/sortElements"; -import { LinearElementEditor } from "../element/linearElementEditor"; +} from "@excalidraw/element/typeChecks"; + +import { normalizeElementOrder } from "@excalidraw/element/sortElements"; + +import { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; + import { bindElementsToFramesAfterDuplication, getFrameChildren, -} from "../frame"; +} from "@excalidraw/element/frame"; + +import type { ExcalidrawElement } from "@excalidraw/element/types"; + +import { ToolButton } from "../components/ToolButton"; +import { DuplicateIcon } from "../components/icons"; + import { selectGroupsForSelectedElements, getSelectedGroupForElement, getElementsInGroup, } from "../groups"; import { t } from "../i18n"; -import { KEYS } from "../keys"; import { isSomeElementSelected } from "../scene"; import { excludeElementsInFramesFromSelection, getSelectedElements, } from "../scene/selection"; import { CaptureUpdateAction } from "../store"; -import { - arrayToMap, - castArray, - findLastIndex, - getShortcutKey, - invariant, -} from "../utils"; import { register } from "./register"; import type { ActionResult } from "./types"; -import type { ExcalidrawElement } from "../element/types"; + import type { AppState } from "../types"; export const actionDuplicateSelection = register({ diff --git a/packages/excalidraw/actions/actionElementLink.ts b/packages/excalidraw/actions/actionElementLink.ts index 69fc67dd3..24ea8bbd6 100644 --- a/packages/excalidraw/actions/actionElementLink.ts +++ b/packages/excalidraw/actions/actionElementLink.ts @@ -1,10 +1,11 @@ -import { copyTextToSystemClipboard } from "../clipboard"; -import { copyIcon, elementLinkIcon } from "../components/icons"; import { canCreateLinkFromElements, defaultGetElementLinkFromSelection, getLinkIdAndTypeFromSelection, -} from "../element/elementLink"; +} from "@excalidraw/element/elementLink"; + +import { copyTextToSystemClipboard } from "../clipboard"; +import { copyIcon, elementLinkIcon } from "../components/icons"; import { t } from "../i18n"; import { getSelectedElements } from "../scene"; import { CaptureUpdateAction } from "../store"; diff --git a/packages/excalidraw/actions/actionElementLock.ts b/packages/excalidraw/actions/actionElementLock.ts index 57ca1dded..79d13c63e 100644 --- a/packages/excalidraw/actions/actionElementLock.ts +++ b/packages/excalidraw/actions/actionElementLock.ts @@ -1,15 +1,18 @@ +import { KEYS, arrayToMap } from "@excalidraw/common"; + +import { newElementWith } from "@excalidraw/element/mutateElement"; + +import { isFrameLikeElement } from "@excalidraw/element/typeChecks"; + +import type { ExcalidrawElement } from "@excalidraw/element/types"; + import { LockedIcon, UnlockedIcon } from "../components/icons"; -import { newElementWith } from "../element/mutateElement"; -import { isFrameLikeElement } from "../element/typeChecks"; -import { KEYS } from "../keys"; + import { getSelectedElements } from "../scene"; import { CaptureUpdateAction } from "../store"; -import { arrayToMap } from "../utils"; import { register } from "./register"; -import type { ExcalidrawElement } from "../element/types"; - const shouldLock = (elements: readonly ExcalidrawElement[]) => elements.every((el) => !el.locked); diff --git a/packages/excalidraw/actions/actionEmbeddable.ts b/packages/excalidraw/actions/actionEmbeddable.ts index 47f3c9e98..556652240 100644 --- a/packages/excalidraw/actions/actionEmbeddable.ts +++ b/packages/excalidraw/actions/actionEmbeddable.ts @@ -1,6 +1,7 @@ +import { updateActiveTool } from "@excalidraw/common"; + import { setCursorForShape } from "../cursor"; import { CaptureUpdateAction } from "../store"; -import { updateActiveTool } from "../utils"; import { register } from "./register"; diff --git a/packages/excalidraw/actions/actionExport.tsx b/packages/excalidraw/actions/actionExport.tsx index c9d70fc46..8fcaea21b 100644 --- a/packages/excalidraw/actions/actionExport.tsx +++ b/packages/excalidraw/actions/actionExport.tsx @@ -1,3 +1,14 @@ +import { + KEYS, + DEFAULT_EXPORT_PADDING, + EXPORT_SCALES, + THEME, +} from "@excalidraw/common"; + +import { getNonDeletedElements } from "@excalidraw/element"; + +import type { Theme } from "@excalidraw/element/types"; + import { useDevice } from "../components/App"; import { CheckboxItem } from "../components/CheckboxItem"; import { DarkModeToggle } from "../components/DarkModeToggle"; @@ -5,14 +16,12 @@ import { ProjectName } from "../components/ProjectName"; import { ToolButton } from "../components/ToolButton"; import { Tooltip } from "../components/Tooltip"; import { ExportIcon, questionCircle, saveAs } from "../components/icons"; -import { DEFAULT_EXPORT_PADDING, EXPORT_SCALES, THEME } from "../constants"; import { loadFromJSON, saveAsJSON } from "../data"; import { isImageFileHandle } from "../data/blob"; import { nativeFileSystemSupported } from "../data/filesystem"; import { resaveAsImageWithScene } from "../data/resave"; -import { getNonDeletedElements } from "../element"; + import { t } from "../i18n"; -import { KEYS } from "../keys"; import { getSelectedElements, isSomeElementSelected } from "../scene"; import { getExportSize } from "../scene/export"; import { CaptureUpdateAction } from "../store"; @@ -21,8 +30,6 @@ import "../components/ToolIcon.scss"; import { register } from "./register"; -import type { Theme } from "../element/types"; - export const actionChangeProjectName = register({ name: "changeProjectName", label: "labels.fileTitle", diff --git a/packages/excalidraw/actions/actionFinalize.tsx b/packages/excalidraw/actions/actionFinalize.tsx index ac8a4e036..8626815ec 100644 --- a/packages/excalidraw/actions/actionFinalize.tsx +++ b/packages/excalidraw/actions/actionFinalize.tsx @@ -1,21 +1,25 @@ import { pointFrom } from "@excalidraw/math"; -import { ToolButton } from "../components/ToolButton"; -import { done } from "../components/icons"; -import { resetCursor } from "../cursor"; -import { isInvisiblySmallElement } from "../element"; +import { isInvisiblySmallElement } from "@excalidraw/element"; import { maybeBindLinearElement, bindOrUnbindLinearElement, -} from "../element/binding"; -import { LinearElementEditor } from "../element/linearElementEditor"; -import { mutateElement } from "../element/mutateElement"; -import { isBindingElement, isLinearElement } from "../element/typeChecks"; +} from "@excalidraw/element/binding"; +import { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; +import { mutateElement } from "@excalidraw/element/mutateElement"; +import { + isBindingElement, + isLinearElement, +} from "@excalidraw/element/typeChecks"; + +import { KEYS, arrayToMap, updateActiveTool } from "@excalidraw/common"; +import { isPathALoop } from "@excalidraw/element/shapes"; + import { t } from "../i18n"; -import { KEYS } from "../keys"; -import { isPathALoop } from "../shapes"; +import { resetCursor } from "../cursor"; +import { done } from "../components/icons"; +import { ToolButton } from "../components/ToolButton"; import { CaptureUpdateAction } from "../store"; -import { arrayToMap, updateActiveTool } from "../utils"; import { register } from "./register"; diff --git a/packages/excalidraw/actions/actionFlip.test.tsx b/packages/excalidraw/actions/actionFlip.test.tsx index e9953e02d..23e4ffc12 100644 --- a/packages/excalidraw/actions/actionFlip.test.tsx +++ b/packages/excalidraw/actions/actionFlip.test.tsx @@ -1,5 +1,4 @@ import { pointFrom } from "@excalidraw/math"; -import React from "react"; import { Excalidraw } from "../index"; import { API } from "../tests/helpers/api"; diff --git a/packages/excalidraw/actions/actionFlip.ts b/packages/excalidraw/actions/actionFlip.ts index bfc7fb721..f782a2932 100644 --- a/packages/excalidraw/actions/actionFlip.ts +++ b/packages/excalidraw/actions/actionFlip.ts @@ -1,25 +1,22 @@ -import { flipHorizontal, flipVertical } from "../components/icons"; -import { getNonDeletedElements } from "../element"; +import { getNonDeletedElements } from "@excalidraw/element"; import { bindOrUnbindLinearElements, isBindingEnabled, -} from "../element/binding"; -import { getCommonBoundingBox } from "../element/bounds"; -import { mutateElement, newElementWith } from "../element/mutateElement"; -import { deepCopyElement } from "../element/newElement"; -import { resizeMultipleElements } from "../element/resizeElements"; +} from "@excalidraw/element/binding"; +import { getCommonBoundingBox } from "@excalidraw/element/bounds"; +import { + mutateElement, + newElementWith, +} from "@excalidraw/element/mutateElement"; +import { deepCopyElement } from "@excalidraw/element/newElement"; +import { resizeMultipleElements } from "@excalidraw/element/resizeElements"; import { isArrowElement, isElbowArrow, isLinearElement, -} from "../element/typeChecks"; -import { updateFrameMembershipOfSelectedElements } from "../frame"; -import { CODES, KEYS } from "../keys"; -import { getSelectedElements } from "../scene"; -import { CaptureUpdateAction } from "../store"; -import { arrayToMap } from "../utils"; - -import { register } from "./register"; +} from "@excalidraw/element/typeChecks"; +import { updateFrameMembershipOfSelectedElements } from "@excalidraw/element/frame"; +import { CODES, KEYS, arrayToMap } from "@excalidraw/common"; import type { ExcalidrawArrowElement, @@ -27,7 +24,15 @@ import type { ExcalidrawElement, NonDeleted, NonDeletedSceneElementsMap, -} from "../element/types"; +} from "@excalidraw/element/types"; + +import { getSelectedElements } from "../scene"; +import { CaptureUpdateAction } from "../store"; + +import { flipHorizontal, flipVertical } from "../components/icons"; + +import { register } from "./register"; + import type { AppClassProperties, AppState } from "../types"; export const actionFlipHorizontal = register({ diff --git a/packages/excalidraw/actions/actionFrame.ts b/packages/excalidraw/actions/actionFrame.ts index 198994b29..6a28060d7 100644 --- a/packages/excalidraw/actions/actionFrame.ts +++ b/packages/excalidraw/actions/actionFrame.ts @@ -1,20 +1,25 @@ -import { frameToolIcon } from "../components/icons"; -import { setCursorForShape } from "../cursor"; -import { getCommonBounds, getNonDeletedElements } from "../element"; -import { mutateElement } from "../element/mutateElement"; -import { newFrameElement } from "../element/newElement"; -import { isFrameLikeElement } from "../element/typeChecks"; -import { addElementsToFrame, removeAllElementsFromFrame } from "../frame"; -import { getFrameChildren } from "../frame"; +import { getCommonBounds, getNonDeletedElements } from "@excalidraw/element"; +import { mutateElement } from "@excalidraw/element/mutateElement"; +import { newFrameElement } from "@excalidraw/element/newElement"; +import { isFrameLikeElement } from "@excalidraw/element/typeChecks"; +import { + addElementsToFrame, + removeAllElementsFromFrame, +} from "@excalidraw/element/frame"; +import { getFrameChildren } from "@excalidraw/element/frame"; + +import { KEYS, updateActiveTool } from "@excalidraw/common"; + +import type { ExcalidrawElement } from "@excalidraw/element/types"; + import { getElementsInGroup } from "../groups"; -import { KEYS } from "../keys"; +import { setCursorForShape } from "../cursor"; +import { frameToolIcon } from "../components/icons"; import { getSelectedElements } from "../scene"; import { CaptureUpdateAction } from "../store"; -import { updateActiveTool } from "../utils"; import { register } from "./register"; -import type { ExcalidrawElement } from "../element/types"; import type { AppClassProperties, AppState, UIAppState } from "../types"; const isSingleFrameSelected = ( diff --git a/packages/excalidraw/actions/actionGroup.tsx b/packages/excalidraw/actions/actionGroup.tsx index ded2f5b72..d36e33039 100644 --- a/packages/excalidraw/actions/actionGroup.tsx +++ b/packages/excalidraw/actions/actionGroup.tsx @@ -1,9 +1,9 @@ -import { ToolButton } from "../components/ToolButton"; -import { UngroupIcon, GroupIcon } from "../components/icons"; -import { getNonDeletedElements } from "../element"; -import { newElementWith } from "../element/mutateElement"; -import { isBoundToContainer } from "../element/typeChecks"; -import { syncMovedIndices } from "../fractionalIndex"; +import { getNonDeletedElements } from "@excalidraw/element"; + +import { newElementWith } from "@excalidraw/element/mutateElement"; + +import { isBoundToContainer } from "@excalidraw/element/typeChecks"; + import { frameAndChildrenSelectedTogether, getElementsInResizingFrame, @@ -12,7 +12,21 @@ import { groupByFrameLikes, removeElementsFromFrame, replaceAllElementsInFrame, -} from "../frame"; +} from "@excalidraw/element/frame"; + +import { KEYS, randomId, arrayToMap, getShortcutKey } from "@excalidraw/common"; + +import type { + ExcalidrawElement, + ExcalidrawTextElement, + OrderedExcalidrawElement, +} from "@excalidraw/element/types"; + +import { ToolButton } from "../components/ToolButton"; +import { UngroupIcon, GroupIcon } from "../components/icons"; + +import { syncMovedIndices } from "../fractionalIndex"; + import { getSelectedGroupIds, selectGroup, @@ -23,19 +37,12 @@ import { isElementInGroup, } from "../groups"; import { t } from "../i18n"; -import { KEYS } from "../keys"; -import { randomId } from "../random"; + import { isSomeElementSelected } from "../scene"; import { CaptureUpdateAction } from "../store"; -import { arrayToMap, getShortcutKey } from "../utils"; import { register } from "./register"; -import type { - ExcalidrawElement, - ExcalidrawTextElement, - OrderedExcalidrawElement, -} from "../element/types"; import type { AppClassProperties, AppState } from "../types"; const allElementsInSameGroup = (elements: readonly ExcalidrawElement[]) => { diff --git a/packages/excalidraw/actions/actionHistory.tsx b/packages/excalidraw/actions/actionHistory.tsx index da4f80219..a0dfb85df 100644 --- a/packages/excalidraw/actions/actionHistory.tsx +++ b/packages/excalidraw/actions/actionHistory.tsx @@ -1,14 +1,14 @@ +import { isWindows, KEYS, matchKey, arrayToMap } from "@excalidraw/common"; + +import type { SceneElementsMap } from "@excalidraw/element/types"; + import { ToolButton } from "../components/ToolButton"; import { UndoIcon, RedoIcon } from "../components/icons"; -import { isWindows } from "../constants"; import { HistoryChangedEvent } from "../history"; import { useEmitter } from "../hooks/useEmitter"; import { t } from "../i18n"; -import { KEYS, matchKey } from "../keys"; import { CaptureUpdateAction } from "../store"; -import { arrayToMap } from "../utils"; -import type { SceneElementsMap } from "../element/types"; import type { History } from "../history"; import type { Store } from "../store"; import type { AppClassProperties, AppState } from "../types"; diff --git a/packages/excalidraw/actions/actionLinearEditor.tsx b/packages/excalidraw/actions/actionLinearEditor.tsx index f17f0e565..56e327bd2 100644 --- a/packages/excalidraw/actions/actionLinearEditor.tsx +++ b/packages/excalidraw/actions/actionLinearEditor.tsx @@ -1,15 +1,18 @@ +import { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; + +import { isElbowArrow, isLinearElement } from "@excalidraw/element/typeChecks"; + +import type { ExcalidrawLinearElement } from "@excalidraw/element/types"; + import { DEFAULT_CATEGORIES } from "../components/CommandPalette/CommandPalette"; import { ToolButton } from "../components/ToolButton"; import { lineEditorIcon } from "../components/icons"; -import { LinearElementEditor } from "../element/linearElementEditor"; -import { isElbowArrow, isLinearElement } from "../element/typeChecks"; + import { t } from "../i18n"; import { CaptureUpdateAction } from "../store"; import { register } from "./register"; -import type { ExcalidrawLinearElement } from "../element/types"; - export const actionToggleLinearEditor = register({ name: "toggleLinearEditor", category: DEFAULT_CATEGORIES.elements, diff --git a/packages/excalidraw/actions/actionLink.tsx b/packages/excalidraw/actions/actionLink.tsx index 91d01b7a6..71426267d 100644 --- a/packages/excalidraw/actions/actionLink.tsx +++ b/packages/excalidraw/actions/actionLink.tsx @@ -1,12 +1,14 @@ +import { isEmbeddableElement } from "@excalidraw/element/typeChecks"; + +import { KEYS, getShortcutKey } from "@excalidraw/common"; + import { ToolButton } from "../components/ToolButton"; import { getContextMenuLabel } from "../components/hyperlink/Hyperlink"; import { LinkIcon } from "../components/icons"; -import { isEmbeddableElement } from "../element/typeChecks"; import { t } from "../i18n"; -import { KEYS } from "../keys"; + import { getSelectedElements } from "../scene"; import { CaptureUpdateAction } from "../store"; -import { getShortcutKey } from "../utils"; import { register } from "./register"; diff --git a/packages/excalidraw/actions/actionMenu.tsx b/packages/excalidraw/actions/actionMenu.tsx index 15b763cb9..cc029499d 100644 --- a/packages/excalidraw/actions/actionMenu.tsx +++ b/packages/excalidraw/actions/actionMenu.tsx @@ -1,8 +1,14 @@ +import { KEYS } from "@excalidraw/common"; + +import { + showSelectedShapeActions, + getNonDeletedElements, +} from "@excalidraw/element"; + import { ToolButton } from "../components/ToolButton"; import { HamburgerMenuIcon, HelpIconThin, palette } from "../components/icons"; -import { showSelectedShapeActions, getNonDeletedElements } from "../element"; import { t } from "../i18n"; -import { KEYS } from "../keys"; + import { CaptureUpdateAction } from "../store"; import { register } from "./register"; diff --git a/packages/excalidraw/actions/actionProperties.test.tsx b/packages/excalidraw/actions/actionProperties.test.tsx index c5467bb94..38419ce82 100644 --- a/packages/excalidraw/actions/actionProperties.test.tsx +++ b/packages/excalidraw/actions/actionProperties.test.tsx @@ -1,8 +1,12 @@ import { queryByTestId } from "@testing-library/react"; -import React from "react"; -import { COLOR_PALETTE, DEFAULT_ELEMENT_BACKGROUND_PICKS } from "../colors"; -import { FONT_FAMILY, STROKE_WIDTH } from "../constants"; +import { + COLOR_PALETTE, + DEFAULT_ELEMENT_BACKGROUND_PICKS, + FONT_FAMILY, + STROKE_WIDTH, +} from "@excalidraw/common"; + import { Excalidraw } from "../index"; import { API } from "../tests/helpers/api"; import { UI } from "../tests/helpers/ui"; diff --git a/packages/excalidraw/actions/actionProperties.tsx b/packages/excalidraw/actions/actionProperties.tsx index 4aa880972..43818e7bb 100644 --- a/packages/excalidraw/actions/actionProperties.tsx +++ b/packages/excalidraw/actions/actionProperties.tsx @@ -1,15 +1,72 @@ import { pointFrom } from "@excalidraw/math"; import { useEffect, useMemo, useRef, useState } from "react"; -import type { LocalPoint } from "@excalidraw/math"; - -import { trackEvent } from "../analytics"; import { DEFAULT_ELEMENT_BACKGROUND_COLOR_PALETTE, DEFAULT_ELEMENT_BACKGROUND_PICKS, DEFAULT_ELEMENT_STROKE_COLOR_PALETTE, DEFAULT_ELEMENT_STROKE_PICKS, -} from "../colors"; + ARROW_TYPE, + DEFAULT_FONT_FAMILY, + DEFAULT_FONT_SIZE, + FONT_FAMILY, + ROUNDNESS, + STROKE_WIDTH, + VERTICAL_ALIGN, + KEYS, + randomInteger, + arrayToMap, + getFontFamilyString, + getShortcutKey, + tupleToCoors, +} from "@excalidraw/common"; + +import { + getNonDeletedElements, + isTextElement, + redrawTextBoundingBox, +} from "@excalidraw/element"; + +import { + bindLinearElement, + bindPointToSnapToElementOutline, + calculateFixedPointForElbowArrowBinding, + getHoveredElementForBinding, + updateBoundElements, +} from "@excalidraw/element/binding"; + +import { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; + +import { + mutateElement, + newElementWith, +} from "@excalidraw/element/mutateElement"; + +import { getBoundTextElement } from "@excalidraw/element/textElement"; + +import { + isArrowElement, + isBoundToContainer, + isElbowArrow, + isLinearElement, + isUsingAdaptiveRadius, +} from "@excalidraw/element/typeChecks"; + +import type { LocalPoint } from "@excalidraw/math"; + +import type { + Arrowhead, + ExcalidrawBindableElement, + ExcalidrawElement, + ExcalidrawLinearElement, + ExcalidrawTextElement, + FontFamilyValues, + TextAlign, + VerticalAlign, + NonDeletedSceneElementsMap, +} from "@excalidraw/element/types"; + +import { trackEvent } from "../analytics"; import { ButtonIconSelect } from "../components/ButtonIconSelect"; import { ColorPicker } from "../components/ColorPicker/ColorPicker"; import { FontPicker } from "../components/FontPicker/FontPicker"; @@ -60,42 +117,10 @@ import { ArrowheadCrowfootOneIcon, ArrowheadCrowfootOneOrManyIcon, } from "../components/icons"; -import { - ARROW_TYPE, - DEFAULT_FONT_FAMILY, - DEFAULT_FONT_SIZE, - FONT_FAMILY, - ROUNDNESS, - STROKE_WIDTH, - VERTICAL_ALIGN, -} from "../constants"; -import { - getNonDeletedElements, - isTextElement, - redrawTextBoundingBox, -} from "../element"; -import { - bindLinearElement, - bindPointToSnapToElementOutline, - calculateFixedPointForElbowArrowBinding, - getHoveredElementForBinding, - updateBoundElements, -} from "../element/binding"; -import { LinearElementEditor } from "../element/linearElementEditor"; -import { mutateElement, newElementWith } from "../element/mutateElement"; -import { getBoundTextElement } from "../element/textElement"; -import { - isArrowElement, - isBoundToContainer, - isElbowArrow, - isLinearElement, - isUsingAdaptiveRadius, -} from "../element/typeChecks"; + import { Fonts } from "../fonts"; import { getLineHeight } from "../fonts/FontMetadata"; import { getLanguage, t } from "../i18n"; -import { KEYS } from "../keys"; -import { randomInteger } from "../random"; import { canHaveArrowheads, getCommonAttributeOfSelectedElements, @@ -105,26 +130,9 @@ import { } from "../scene"; import { hasStrokeColor } from "../scene/comparisons"; import { CaptureUpdateAction } from "../store"; -import { - arrayToMap, - getFontFamilyString, - getShortcutKey, - tupleToCoors, -} from "../utils"; import { register } from "./register"; -import type { - Arrowhead, - ExcalidrawBindableElement, - ExcalidrawElement, - ExcalidrawLinearElement, - ExcalidrawTextElement, - FontFamilyValues, - TextAlign, - VerticalAlign, - NonDeletedSceneElementsMap, -} from "../element/types"; import type { CaptureUpdateActionType } from "../store"; import type { AppClassProperties, AppState, Primitive } from "../types"; diff --git a/packages/excalidraw/actions/actionSelectAll.ts b/packages/excalidraw/actions/actionSelectAll.ts index 5f6d7eabc..8ed8d757c 100644 --- a/packages/excalidraw/actions/actionSelectAll.ts +++ b/packages/excalidraw/actions/actionSelectAll.ts @@ -1,14 +1,17 @@ -import { selectAllIcon } from "../components/icons"; -import { getNonDeletedElements, isTextElement } from "../element"; -import { LinearElementEditor } from "../element/linearElementEditor"; -import { isLinearElement } from "../element/typeChecks"; +import { getNonDeletedElements, isTextElement } from "@excalidraw/element"; +import { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; +import { isLinearElement } from "@excalidraw/element/typeChecks"; + +import { KEYS } from "@excalidraw/common"; + +import type { ExcalidrawElement } from "@excalidraw/element/types"; + import { selectGroupsForSelectedElements } from "../groups"; -import { KEYS } from "../keys"; import { CaptureUpdateAction } from "../store"; -import { register } from "./register"; +import { selectAllIcon } from "../components/icons"; -import type { ExcalidrawElement } from "../element/types"; +import { register } from "./register"; export const actionSelectAll = register({ name: "selectAll", diff --git a/packages/excalidraw/actions/actionStyles.ts b/packages/excalidraw/actions/actionStyles.ts index 8215ec0ea..ae9d4bfe4 100644 --- a/packages/excalidraw/actions/actionStyles.ts +++ b/packages/excalidraw/actions/actionStyles.ts @@ -1,33 +1,40 @@ -import { paintIcon } from "../components/icons"; import { DEFAULT_FONT_SIZE, DEFAULT_FONT_FAMILY, DEFAULT_TEXT_ALIGN, -} from "../constants"; + CODES, + KEYS, +} from "@excalidraw/common"; + import { isTextElement, isExcalidrawElement, redrawTextBoundingBox, -} from "../element"; -import { newElementWith } from "../element/mutateElement"; -import { getBoundTextElement } from "../element/textElement"; +} from "@excalidraw/element"; + +import { newElementWith } from "@excalidraw/element/mutateElement"; + import { hasBoundTextElement, canApplyRoundnessTypeToElement, getDefaultRoundnessTypeForElement, isFrameLikeElement, isArrowElement, -} from "../element/typeChecks"; +} from "@excalidraw/element/typeChecks"; + +import { getBoundTextElement } from "@excalidraw/element/textElement"; + +import type { ExcalidrawTextElement } from "@excalidraw/element/types"; + +import { paintIcon } from "../components/icons"; + import { getLineHeight } from "../fonts/FontMetadata"; import { t } from "../i18n"; -import { CODES, KEYS } from "../keys"; import { getSelectedElements } from "../scene"; import { CaptureUpdateAction } from "../store"; import { register } from "./register"; -import type { ExcalidrawTextElement } from "../element/types"; - // `copiedStyles` is exported only for tests. export let copiedStyles: string = "{}"; diff --git a/packages/excalidraw/actions/actionTextAutoResize.ts b/packages/excalidraw/actions/actionTextAutoResize.ts index b9ad7783f..5230955f3 100644 --- a/packages/excalidraw/actions/actionTextAutoResize.ts +++ b/packages/excalidraw/actions/actionTextAutoResize.ts @@ -1,9 +1,11 @@ -import { isTextElement } from "../element"; -import { newElementWith } from "../element/mutateElement"; -import { measureText } from "../element/textMeasurements"; +import { getFontString } from "@excalidraw/common"; + +import { isTextElement } from "@excalidraw/element"; +import { newElementWith } from "@excalidraw/element/mutateElement"; +import { measureText } from "@excalidraw/element/textMeasurements"; + import { getSelectedElements } from "../scene"; import { CaptureUpdateAction } from "../store"; -import { getFontString } from "../utils"; import { register } from "./register"; diff --git a/packages/excalidraw/actions/actionToggleGridMode.tsx b/packages/excalidraw/actions/actionToggleGridMode.tsx index 98360e843..9415051f3 100644 --- a/packages/excalidraw/actions/actionToggleGridMode.tsx +++ b/packages/excalidraw/actions/actionToggleGridMode.tsx @@ -1,5 +1,6 @@ +import { CODES, KEYS } from "@excalidraw/common"; + import { gridIcon } from "../components/icons"; -import { CODES, KEYS } from "../keys"; import { CaptureUpdateAction } from "../store"; import { register } from "./register"; diff --git a/packages/excalidraw/actions/actionToggleObjectsSnapMode.tsx b/packages/excalidraw/actions/actionToggleObjectsSnapMode.tsx index d51124132..ba092bff8 100644 --- a/packages/excalidraw/actions/actionToggleObjectsSnapMode.tsx +++ b/packages/excalidraw/actions/actionToggleObjectsSnapMode.tsx @@ -1,5 +1,6 @@ +import { CODES, KEYS } from "@excalidraw/common"; + import { magnetIcon } from "../components/icons"; -import { CODES, KEYS } from "../keys"; import { CaptureUpdateAction } from "../store"; import { register } from "./register"; diff --git a/packages/excalidraw/actions/actionToggleSearchMenu.ts b/packages/excalidraw/actions/actionToggleSearchMenu.ts index 75d9074c8..ce384fc66 100644 --- a/packages/excalidraw/actions/actionToggleSearchMenu.ts +++ b/packages/excalidraw/actions/actionToggleSearchMenu.ts @@ -1,6 +1,11 @@ +import { + KEYS, + CANVAS_SEARCH_TAB, + CLASSES, + DEFAULT_SIDEBAR, +} from "@excalidraw/common"; + import { searchIcon } from "../components/icons"; -import { CANVAS_SEARCH_TAB, CLASSES, DEFAULT_SIDEBAR } from "../constants"; -import { KEYS } from "../keys"; import { CaptureUpdateAction } from "../store"; import { register } from "./register"; diff --git a/packages/excalidraw/actions/actionToggleStats.tsx b/packages/excalidraw/actions/actionToggleStats.tsx index d0cdc64a3..93fd6395b 100644 --- a/packages/excalidraw/actions/actionToggleStats.tsx +++ b/packages/excalidraw/actions/actionToggleStats.tsx @@ -1,5 +1,6 @@ +import { CODES, KEYS } from "@excalidraw/common"; + import { abacusIcon } from "../components/icons"; -import { CODES, KEYS } from "../keys"; import { CaptureUpdateAction } from "../store"; import { register } from "./register"; diff --git a/packages/excalidraw/actions/actionToggleViewMode.tsx b/packages/excalidraw/actions/actionToggleViewMode.tsx index 055135263..81faa9ee6 100644 --- a/packages/excalidraw/actions/actionToggleViewMode.tsx +++ b/packages/excalidraw/actions/actionToggleViewMode.tsx @@ -1,5 +1,6 @@ +import { CODES, KEYS } from "@excalidraw/common"; + import { eyeIcon } from "../components/icons"; -import { CODES, KEYS } from "../keys"; import { CaptureUpdateAction } from "../store"; import { register } from "./register"; diff --git a/packages/excalidraw/actions/actionToggleZenMode.tsx b/packages/excalidraw/actions/actionToggleZenMode.tsx index 31c72bf95..4d45b3204 100644 --- a/packages/excalidraw/actions/actionToggleZenMode.tsx +++ b/packages/excalidraw/actions/actionToggleZenMode.tsx @@ -1,5 +1,6 @@ +import { CODES, KEYS } from "@excalidraw/common"; + import { coffeeIcon } from "../components/icons"; -import { CODES, KEYS } from "../keys"; import { CaptureUpdateAction } from "../store"; import { register } from "./register"; diff --git a/packages/excalidraw/actions/actionZindex.tsx b/packages/excalidraw/actions/actionZindex.tsx index 82d3d77da..42a79a3c0 100644 --- a/packages/excalidraw/actions/actionZindex.tsx +++ b/packages/excalidraw/actions/actionZindex.tsx @@ -1,14 +1,13 @@ +import { KEYS, CODES, getShortcutKey, isDarwin } from "@excalidraw/common"; + import { BringForwardIcon, BringToFrontIcon, SendBackwardIcon, SendToBackIcon, } from "../components/icons"; -import { isDarwin } from "../constants"; import { t } from "../i18n"; -import { KEYS, CODES } from "../keys"; import { CaptureUpdateAction } from "../store"; -import { getShortcutKey } from "../utils"; import { moveOneLeft, moveOneRight, diff --git a/packages/excalidraw/actions/manager.tsx b/packages/excalidraw/actions/manager.tsx index d3609640e..171bb5df7 100644 --- a/packages/excalidraw/actions/manager.tsx +++ b/packages/excalidraw/actions/manager.tsx @@ -1,12 +1,14 @@ import React from "react"; -import { trackEvent } from "../analytics"; -import { isPromiseLike } from "../utils"; +import { isPromiseLike } from "@excalidraw/common"; import type { ExcalidrawElement, OrderedExcalidrawElement, -} from "../element/types"; +} from "@excalidraw/element/types"; + +import { trackEvent } from "../analytics"; + import type { AppClassProperties, AppState } from "../types"; import type { Action, diff --git a/packages/excalidraw/actions/shortcuts.ts b/packages/excalidraw/actions/shortcuts.ts index 89a7c5ae2..8de465128 100644 --- a/packages/excalidraw/actions/shortcuts.ts +++ b/packages/excalidraw/actions/shortcuts.ts @@ -1,6 +1,6 @@ -import { isDarwin } from "../constants"; +import { isDarwin, getShortcutKey } from "@excalidraw/common"; + import { t } from "../i18n"; -import { getShortcutKey } from "../utils"; import type { SubtypeOf } from "../utility-types"; import type { ActionName } from "./types"; diff --git a/packages/excalidraw/actions/types.ts b/packages/excalidraw/actions/types.ts index c30f53f5e..152b9a0c7 100644 --- a/packages/excalidraw/actions/types.ts +++ b/packages/excalidraw/actions/types.ts @@ -1,7 +1,8 @@ import type { ExcalidrawElement, OrderedExcalidrawElement, -} from "../element/types"; +} from "@excalidraw/element/types"; + import type { CaptureUpdateActionType } from "../store"; import type { AppClassProperties, diff --git a/packages/excalidraw/align.ts b/packages/excalidraw/align.ts index 36e5d6603..b0b20a9ec 100644 --- a/packages/excalidraw/align.ts +++ b/packages/excalidraw/align.ts @@ -1,10 +1,12 @@ -import { updateBoundElements } from "./element/binding"; -import { getCommonBoundingBox } from "./element/bounds"; -import { mutateElement } from "./element/mutateElement"; +import { updateBoundElements } from "@excalidraw/element/binding"; +import { getCommonBoundingBox } from "@excalidraw/element/bounds"; +import { mutateElement } from "@excalidraw/element/mutateElement"; + +import type { BoundingBox } from "@excalidraw/element/bounds"; +import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types"; + import { getMaximumGroups } from "./groups"; -import type { BoundingBox } from "./element/bounds"; -import type { ElementsMap, ExcalidrawElement } from "./element/types"; import type Scene from "./scene/Scene"; export interface Alignment { diff --git a/packages/excalidraw/animated-trail.ts b/packages/excalidraw/animated-trail.ts index a20460771..286eff6f3 100644 --- a/packages/excalidraw/animated-trail.ts +++ b/packages/excalidraw/animated-trail.ts @@ -1,9 +1,12 @@ import { LaserPointer } from "@excalidraw/laser-pointer"; -import type { LaserPointerOptions } from "@excalidraw/laser-pointer"; +import { + SVG_NS, + getSvgPathFromStroke, + sceneCoordsToViewportCoords, +} from "@excalidraw/common"; -import { SVG_NS } from "./constants"; -import { getSvgPathFromStroke, sceneCoordsToViewportCoords } from "./utils"; +import type { LaserPointerOptions } from "@excalidraw/laser-pointer"; import type { AnimationFrameHandler } from "./animation-frame-handler"; import type App from "./components/App"; diff --git a/packages/excalidraw/appState.ts b/packages/excalidraw/appState.ts index acda8468b..434392ce7 100644 --- a/packages/excalidraw/appState.ts +++ b/packages/excalidraw/appState.ts @@ -1,5 +1,5 @@ -import { COLOR_PALETTE } from "./colors"; import { + COLOR_PALETTE, ARROW_TYPE, DEFAULT_ELEMENT_PROPS, DEFAULT_FONT_FAMILY, @@ -10,7 +10,7 @@ import { STATS_PANELS, THEME, DEFAULT_GRID_STEP, -} from "./constants"; +} from "@excalidraw/common"; import type { AppState, NormalizedZoomValue } from "./types"; diff --git a/packages/excalidraw/change.ts b/packages/excalidraw/change.ts index 206f3dcc7..6e5e38d88 100644 --- a/packages/excalidraw/change.ts +++ b/packages/excalidraw/change.ts @@ -1,36 +1,38 @@ -import { ENV } from "./constants"; +import { + ENV, + arrayToMap, + arrayToObject, + assertNever, + isShallowEqual, + toBrandedType, +} from "@excalidraw/common"; import { BoundElement, BindableElement, bindingProperties, updateBoundElements, -} from "./element/binding"; -import { LinearElementEditor } from "./element/linearElementEditor"; -import { mutateElement, newElementWith } from "./element/mutateElement"; +} from "@excalidraw/element/binding"; +import { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; +import { + mutateElement, + newElementWith, +} from "@excalidraw/element/mutateElement"; import { getBoundTextElementId, redrawTextBoundingBox, -} from "./element/textElement"; +} from "@excalidraw/element/textElement"; import { hasBoundTextElement, isBindableElement, isBoundToContainer, isImageElement, isTextElement, -} from "./element/typeChecks"; -import { orderByFractionalIndex, syncMovedIndices } from "./fractionalIndex"; -import { getNonDeletedGroupIds } from "./groups"; -import { getObservedAppState } from "./store"; -import { - arrayToMap, - arrayToObject, - assertNever, - isShallowEqual, - toBrandedType, -} from "./utils"; +} from "@excalidraw/element/typeChecks"; + +import type { BindableProp, BindingProp } from "@excalidraw/element/binding"; + +import type { ElementUpdate } from "@excalidraw/element/mutateElement"; -import type { BindableProp, BindingProp } from "./element/binding"; -import type { ElementUpdate } from "./element/mutateElement"; import type { ExcalidrawElement, ExcalidrawImageElement, @@ -40,7 +42,12 @@ import type { Ordered, OrderedExcalidrawElement, SceneElementsMap, -} from "./element/types"; +} from "@excalidraw/element/types"; + +import { orderByFractionalIndex, syncMovedIndices } from "./fractionalIndex"; +import { getNonDeletedGroupIds } from "./groups"; +import { getObservedAppState } from "./store"; + import type { AppState, ObservedAppState, diff --git a/packages/excalidraw/charts.ts b/packages/excalidraw/charts.ts index e54c55f28..d1a0b71d8 100644 --- a/packages/excalidraw/charts.ts +++ b/packages/excalidraw/charts.ts @@ -1,21 +1,23 @@ import { pointFrom } from "@excalidraw/math"; -import type { Radians } from "@excalidraw/math"; - import { COLOR_PALETTE, DEFAULT_CHART_COLOR_INDEX, getAllColorsSpecificShade, -} from "./colors"; -import { DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE, VERTICAL_ALIGN, -} from "./constants"; -import { newElement, newLinearElement, newTextElement } from "./element"; -import { randomId } from "./random"; + randomId, +} from "@excalidraw/common"; +import { + newElement, + newLinearElement, + newTextElement, +} from "@excalidraw/element"; -import type { NonDeletedExcalidrawElement } from "./element/types"; +import type { Radians } from "@excalidraw/math"; + +import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types"; export type ChartElements = readonly NonDeletedExcalidrawElement[]; diff --git a/packages/excalidraw/clients.ts b/packages/excalidraw/clients.ts index 6cf4613a8..9467b1362 100644 --- a/packages/excalidraw/clients.ts +++ b/packages/excalidraw/clients.ts @@ -4,7 +4,8 @@ import { COLOR_WHITE, THEME, UserIdleState, -} from "./constants"; +} from "@excalidraw/common"; + import { roundRect } from "./renderer/roundRect"; import type { InteractiveCanvasRenderConfig } from "./scene/types"; diff --git a/packages/excalidraw/clipboard.ts b/packages/excalidraw/clipboard.ts index 1b0e9942a..fe56315ac 100644 --- a/packages/excalidraw/clipboard.ts +++ b/packages/excalidraw/clipboard.ts @@ -1,25 +1,32 @@ -import { tryParseSpreadsheet, VALID_SPREADSHEET } from "./charts"; import { ALLOWED_PASTE_MIME_TYPES, EXPORT_DATA_TYPES, MIME_TYPES, -} from "./constants"; -import { createFile, isSupportedImageFileType } from "./data/blob"; -import { mutateElement } from "./element/mutateElement"; -import { deepCopyElement } from "./element/newElement"; + arrayToMap, + isMemberOf, + isPromiseLike, +} from "@excalidraw/common"; + +import { mutateElement } from "@excalidraw/element/mutateElement"; +import { deepCopyElement } from "@excalidraw/element/newElement"; import { isFrameLikeElement, isInitializedImageElement, -} from "./element/typeChecks"; -import { ExcalidrawError } from "./errors"; -import { getContainingFrame } from "./frame"; -import { arrayToMap, isMemberOf, isPromiseLike } from "./utils"; +} from "@excalidraw/element/typeChecks"; + +import { getContainingFrame } from "@excalidraw/element/frame"; -import type { Spreadsheet } from "./charts"; import type { ExcalidrawElement, NonDeletedExcalidrawElement, -} from "./element/types"; +} from "@excalidraw/element/types"; + +import { ExcalidrawError } from "./errors"; +import { createFile, isSupportedImageFileType } from "./data/blob"; +import { tryParseSpreadsheet, VALID_SPREADSHEET } from "./charts"; + +import type { Spreadsheet } from "./charts"; + import type { BinaryFiles } from "./types"; type ElementsClipboard = { diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx index f39aee8dd..4968542bc 100644 --- a/packages/excalidraw/components/App.tsx +++ b/packages/excalidraw/components/App.tsx @@ -1,3 +1,10 @@ +import clsx from "clsx"; +import throttle from "lodash.throttle"; +import { nanoid } from "nanoid"; +import React, { useContext } from "react"; +import { flushSync } from "react-dom"; +import rough from "roughjs/bin/rough"; + import { clamp, pointFrom, @@ -12,15 +19,284 @@ import { } from "@excalidraw/math"; import { isPointInShape } from "@excalidraw/utils/collision"; import { getSelectionBoxShape } from "@excalidraw/utils/geometry/shape"; -import clsx from "clsx"; -import throttle from "lodash.throttle"; -import { nanoid } from "nanoid"; -import React, { useContext } from "react"; -import { flushSync } from "react-dom"; -import rough from "roughjs/bin/rough"; + +import { + COLOR_PALETTE, + CODES, + shouldResizeFromCenter, + shouldMaintainAspectRatio, + shouldRotateWithDiscreteAngle, + isArrowKey, + KEYS, + APP_NAME, + CURSOR_TYPE, + DEFAULT_MAX_IMAGE_WIDTH_OR_HEIGHT, + DEFAULT_VERTICAL_ALIGN, + DRAGGING_THRESHOLD, + ELEMENT_SHIFT_TRANSLATE_AMOUNT, + ELEMENT_TRANSLATE_AMOUNT, + ENV, + EVENT, + FRAME_STYLE, + IMAGE_MIME_TYPES, + IMAGE_RENDER_TIMEOUT, + isBrave, + LINE_CONFIRM_THRESHOLD, + MAX_ALLOWED_FILE_BYTES, + MIME_TYPES, + MQ_MAX_HEIGHT_LANDSCAPE, + MQ_MAX_WIDTH_LANDSCAPE, + MQ_MAX_WIDTH_PORTRAIT, + MQ_RIGHT_SIDEBAR_MIN_WIDTH, + POINTER_BUTTON, + ROUNDNESS, + SCROLL_TIMEOUT, + TAP_TWICE_TIMEOUT, + TEXT_TO_CENTER_SNAP_THRESHOLD, + THEME, + THEME_FILTER, + TOUCH_CTX_MENU_TIMEOUT, + VERTICAL_ALIGN, + YOUTUBE_STATES, + ZOOM_STEP, + POINTER_EVENTS, + TOOL_TYPE, + isIOS, + supportsResizeObserver, + DEFAULT_COLLISION_THRESHOLD, + DEFAULT_TEXT_ALIGN, + ARROW_TYPE, + DEFAULT_REDUCED_GLOBAL_ALPHA, + isSafari, + isLocalLink, + normalizeLink, + toValidURL, + getGridPoint, + type EXPORT_IMAGE_TYPES, +} 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"; + +import { + bindOrUnbindLinearElement, + bindOrUnbindLinearElements, + fixBindingsAfterDeletion, + fixBindingsAfterDuplication, + getHoveredElementForBinding, + isBindingEnabled, + isLinearElementSimpleAndAlreadyBound, + maybeBindLinearElement, + shouldEnableBindingForPointerEvent, + updateBoundElements, + getSuggestedBindingsForArrows, +} from "@excalidraw/element/binding"; + +import { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; + +import { + mutateElement, + newElementWith, +} from "@excalidraw/element/mutateElement"; + +import { + deepCopyElement, + duplicateElements, + newFrameElement, + newFreeDrawElement, + newEmbeddableElement, + newMagicFrameElement, + newIframeElement, + newArrowElement, +} from "@excalidraw/element/newElement"; + +import { + hasBoundTextElement, + isArrowElement, + isBindingElement, + isBindingElementType, + isBoundToContainer, + isFrameLikeElement, + isImageElement, + isEmbeddableElement, + isInitializedImageElement, + isLinearElement, + isLinearElementType, + isUsingAdaptiveRadius, + isIframeElement, + isIframeLikeElement, + isMagicFrameElement, + isTextBindableContainer, + isElbowArrow, + isFlowchartNodeElement, + isBindableElement, +} from "@excalidraw/element/typeChecks"; + +import { + isElementCompletelyInViewport, + isElementInViewport, +} from "@excalidraw/element/sizeHelpers"; + +import { + getBoundTextShape, + getCornerRadius, + getElementShape, + isPathALoop, +} from "@excalidraw/element/shapes"; + +import { + debounce, + distance, + getFontString, + getNearestScrollableContainer, + isInputLike, + isToolIcon, + isWritableElement, + sceneCoordsToViewportCoords, + tupleToCoors, + viewportCoordsToSceneCoords, + wrapEvent, + updateObject, + updateActiveTool, + getShortcutKey, + isTransparent, + easeToValuesRAF, + muteFSAbortError, + isTestEnv, + easeOut, + updateStable, + addEventListener, + normalizeEOL, + getDateTime, + isShallowEqual, + arrayToMap, +} from "@excalidraw/common/utils"; + +import { + createSrcDoc, + embeddableURLValidator, + maybeParseEmbedSrc, + getEmbedLink, +} from "@excalidraw/element/embeddable"; + +import { + getInitializedImageElements, + loadHTMLImageElement, + normalizeSVG, + updateImageCache as _updateImageCache, +} from "@excalidraw/element/image"; + +import { + bindTextToShapeAfterDuplication, + getBoundTextElement, + getContainerCenter, + getContainerElement, + isValidTextContainer, +} from "@excalidraw/element/textElement"; + +import { shouldShowBoundingBox } from "@excalidraw/element/transformHandles"; + +import { + getFrameChildren, + isCursorInFrame, + bindElementsToFramesAfterDuplication, + addElementsToFrame, + replaceAllElementsInFrame, + removeElementsFromFrame, + getElementsInResizingFrame, + getElementsInNewFrame, + getContainingFrame, + elementOverlapsWithFrame, + updateFrameMembershipOfSelectedElements, + isElementInFrame, + getFrameLikeTitle, + getElementsOverlappingFrame, + filterElementsEligibleAsFrameChildren, +} from "@excalidraw/element/frame"; + +import { + hitElementBoundText, + hitElementBoundingBoxOnly, + hitElementItself, +} from "@excalidraw/element/collision"; + +import { getVisibleSceneBounds } from "@excalidraw/element/bounds"; + +import { + FlowChartCreator, + FlowChartNavigator, + getLinkDirectionFromKey, +} from "@excalidraw/element/flowchart"; + +import { cropElement } from "@excalidraw/element/cropElement"; + +import { wrapText } from "@excalidraw/element/textWrapping"; + +import { + isElementLink, + parseElementLinkFromURL, +} from "@excalidraw/element/elementLink"; + +import { + isMeasureTextSupported, + normalizeText, + measureText, + getLineHeightInPx, + getApproxMinLineWidth, + getApproxMinLineHeight, + getMinTextElementWidth, +} from "@excalidraw/element/textMeasurements"; import type { LocalPoint, Radians } from "@excalidraw/math"; +import type { + ExcalidrawBindableElement, + ExcalidrawElement, + ExcalidrawFreeDrawElement, + ExcalidrawGenericElement, + ExcalidrawLinearElement, + ExcalidrawTextElement, + NonDeleted, + InitializedExcalidrawImageElement, + ExcalidrawImageElement, + FileId, + NonDeletedExcalidrawElement, + ExcalidrawTextContainer, + ExcalidrawFrameLikeElement, + ExcalidrawMagicFrameElement, + ExcalidrawIframeLikeElement, + IframeData, + ExcalidrawIframeElement, + ExcalidrawEmbeddableElement, + Ordered, + MagicGenerationData, + ExcalidrawNonSelectionElement, + ExcalidrawArrowElement, +} from "@excalidraw/element/types"; + import { actionAddToLibrary, actionBringForward, @@ -77,123 +353,10 @@ import { isHandToolActive, } from "../appState"; import { copyTextToSystemClipboard, parseClipboard } from "../clipboard"; -import { - APP_NAME, - CURSOR_TYPE, - DEFAULT_MAX_IMAGE_WIDTH_OR_HEIGHT, - DEFAULT_VERTICAL_ALIGN, - DRAGGING_THRESHOLD, - ELEMENT_SHIFT_TRANSLATE_AMOUNT, - ELEMENT_TRANSLATE_AMOUNT, - ENV, - EVENT, - FRAME_STYLE, - IMAGE_MIME_TYPES, - IMAGE_RENDER_TIMEOUT, - isBrave, - LINE_CONFIRM_THRESHOLD, - MAX_ALLOWED_FILE_BYTES, - MIME_TYPES, - MQ_MAX_HEIGHT_LANDSCAPE, - MQ_MAX_WIDTH_LANDSCAPE, - MQ_MAX_WIDTH_PORTRAIT, - MQ_RIGHT_SIDEBAR_MIN_WIDTH, - POINTER_BUTTON, - ROUNDNESS, - SCROLL_TIMEOUT, - TAP_TWICE_TIMEOUT, - TEXT_TO_CENTER_SNAP_THRESHOLD, - THEME, - THEME_FILTER, - TOUCH_CTX_MENU_TIMEOUT, - VERTICAL_ALIGN, - YOUTUBE_STATES, - ZOOM_STEP, - POINTER_EVENTS, - TOOL_TYPE, - isIOS, - supportsResizeObserver, - DEFAULT_COLLISION_THRESHOLD, - DEFAULT_TEXT_ALIGN, - ARROW_TYPE, - DEFAULT_REDUCED_GLOBAL_ALPHA, - isSafari, - type EXPORT_IMAGE_TYPES, -} from "../constants"; import { exportCanvas, loadFromBlob } from "../data"; import Library, { distributeLibraryItemsOnSquareGrid } from "../data/library"; import { restore, restoreElements } from "../data/restore"; -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 "../element"; -import { - bindOrUnbindLinearElement, - bindOrUnbindLinearElements, - fixBindingsAfterDeletion, - fixBindingsAfterDuplication, - getHoveredElementForBinding, - isBindingEnabled, - isLinearElementSimpleAndAlreadyBound, - maybeBindLinearElement, - shouldEnableBindingForPointerEvent, - updateBoundElements, - getSuggestedBindingsForArrows, -} from "../element/binding"; -import { LinearElementEditor } from "../element/linearElementEditor"; -import { mutateElement, newElementWith } from "../element/mutateElement"; -import { - deepCopyElement, - duplicateElements, - newFrameElement, - newFreeDrawElement, - newEmbeddableElement, - newMagicFrameElement, - newIframeElement, - newArrowElement, -} from "../element/newElement"; -import { - hasBoundTextElement, - isArrowElement, - isBindingElement, - isBindingElementType, - isBoundToContainer, - isFrameLikeElement, - isImageElement, - isEmbeddableElement, - isInitializedImageElement, - isLinearElement, - isLinearElementType, - isUsingAdaptiveRadius, - isIframeElement, - isIframeLikeElement, - isMagicFrameElement, - isTextBindableContainer, - isElbowArrow, - isFlowchartNodeElement, - isBindableElement, -} from "../element/typeChecks"; + import { getCenter, getDistance } from "../gesture"; import { editGroupForSelectedElement, @@ -206,18 +369,7 @@ import { } from "../groups"; import { History } from "../history"; import { defaultLang, getLanguage, languages, setLanguage, t } from "../i18n"; -import { - CODES, - shouldResizeFromCenter, - shouldMaintainAspectRatio, - shouldRotateWithDiscreteAngle, - isArrowKey, - KEYS, -} from "../keys"; -import { - isElementCompletelyInViewport, - isElementInViewport, -} from "../element/sizeHelpers"; + import { calculateScrollCenter, getElementsWithinSelection, @@ -228,46 +380,7 @@ import { } from "../scene"; import Scene from "../scene/Scene"; import { getStateForZoom } from "../scene/zoom"; -import { - findShapeByKey, - getBoundTextShape, - getCornerRadius, - getElementShape, - isPathALoop, -} from "../shapes"; -import { - debounce, - distance, - getFontString, - getNearestScrollableContainer, - isInputLike, - isToolIcon, - isWritableElement, - sceneCoordsToViewportCoords, - tupleToCoors, - viewportCoordsToSceneCoords, - wrapEvent, - updateObject, - updateActiveTool, - getShortcutKey, - isTransparent, - easeToValuesRAF, - muteFSAbortError, - isTestEnv, - easeOut, - updateStable, - addEventListener, - normalizeEOL, - getDateTime, - isShallowEqual, - arrayToMap, -} from "../utils"; -import { - createSrcDoc, - embeddableURLValidator, - maybeParseEmbedSrc, - getEmbedLink, -} from "../element/embeddable"; + import { dataURLToFile, dataURLToString, @@ -284,46 +397,17 @@ import { resizeImageFile, SVGStringToFile, } from "../data/blob"; -import { - getInitializedImageElements, - loadHTMLImageElement, - normalizeSVG, - updateImageCache as _updateImageCache, -} from "../element/image"; + import { fileOpen } from "../data/filesystem"; -import { - bindTextToShapeAfterDuplication, - getBoundTextElement, - getContainerCenter, - getContainerElement, - isValidTextContainer, -} from "../element/textElement"; + import { showHyperlinkTooltip, hideHyperlinkToolip, Hyperlink, } from "../components/hyperlink/Hyperlink"; -import { isLocalLink, normalizeLink, toValidURL } from "../data/url"; -import { shouldShowBoundingBox } from "../element/transformHandles"; + import { Fonts } from "../fonts"; import { getLineHeight } from "../fonts/FontMetadata"; -import { - getFrameChildren, - isCursorInFrame, - bindElementsToFramesAfterDuplication, - addElementsToFrame, - replaceAllElementsInFrame, - removeElementsFromFrame, - getElementsInResizingFrame, - getElementsInNewFrame, - getContainingFrame, - elementOverlapsWithFrame, - updateFrameMembershipOfSelectedElements, - isElementInFrame, - getFrameLikeTitle, - getElementsOverlappingFrame, - filterElementsEligibleAsFrameChildren, -} from "../frame"; import { excludeElementsInFramesFromSelection, makeNextSelectedElementIds, @@ -341,7 +425,6 @@ import { getReferenceSnapPoints, SnapCache, isGridModeEnabled, - getGridPoint, } from "../snapping"; import { convertToExcalidrawElements } from "../data/transform"; import { Renderer } from "../scene/Renderer"; @@ -354,39 +437,16 @@ import { } from "../cursor"; import { Emitter } from "../emitter"; import { ElementCanvasButtons } from "../components/ElementCanvasButtons"; -import { COLOR_PALETTE } from "../colors"; import { Store, CaptureUpdateAction } from "../store"; import { AnimatedTrail } from "../animated-trail"; import { LaserTrails } from "../laser-trails"; import { withBatchedUpdates, withBatchedUpdatesThrottled } from "../reactUtils"; import { getRenderOpacity } from "../renderer/renderElement"; -import { - hitElementBoundText, - hitElementBoundingBoxOnly, - hitElementItself, -} from "../element/collision"; import { textWysiwyg } from "../wysiwyg/textWysiwyg"; import { isOverScrollBars } from "../scene/scrollbars"; import { syncInvalidIndices, syncMovedIndices } from "../fractionalIndex"; -import { getVisibleSceneBounds } from "../element/bounds"; + import { isMaybeMermaidDefinition } from "../mermaid"; -import { - FlowChartCreator, - FlowChartNavigator, - getLinkDirectionFromKey, -} from "../element/flowchart"; -import { cropElement } from "../element/cropElement"; -import { wrapText } from "../element/textWrapping"; -import { isElementLink, parseElementLinkFromURL } from "../element/elementLink"; -import { - isMeasureTextSupported, - normalizeText, - measureText, - getLineHeightInPx, - getApproxMinLineWidth, - getApproxMinLineHeight, - getMinTextElementWidth, -} from "../element/textMeasurements"; import { activeConfirmDialogAtom } from "./ActiveConfirmDialog"; import BraveMeasureTextError from "./BraveMeasureTextError"; @@ -407,40 +467,19 @@ import { import { MagicIcon, copyIcon, fullscreenIcon } from "./icons"; import { Toast } from "./Toast"; -import type { Action, ActionResult } from "../actions/types"; +import { findShapeByKey } from "./shapes"; + +import type { + RenderInteractiveSceneCallback, + ScrollBars, +} from "../scene/types"; + import type { PastedMixedContent } from "../clipboard"; import type { ExportedElements } from "../data"; import type { ContextMenuItems } from "./ContextMenu"; import type { FileSystemHandle } from "../data/filesystem"; import type { ExcalidrawElementSkeleton } from "../data/transform"; -import type { - ExcalidrawBindableElement, - ExcalidrawElement, - ExcalidrawFreeDrawElement, - ExcalidrawGenericElement, - ExcalidrawLinearElement, - ExcalidrawTextElement, - NonDeleted, - InitializedExcalidrawImageElement, - ExcalidrawImageElement, - FileId, - NonDeletedExcalidrawElement, - ExcalidrawTextContainer, - ExcalidrawFrameLikeElement, - ExcalidrawMagicFrameElement, - ExcalidrawIframeLikeElement, - IframeData, - ExcalidrawIframeElement, - ExcalidrawEmbeddableElement, - Ordered, - MagicGenerationData, - ExcalidrawNonSelectionElement, - ExcalidrawArrowElement, -} from "../element/types"; -import type { - RenderInteractiveSceneCallback, - ScrollBars, -} from "../scene/types"; + import type { AppClassProperties, AppProps, @@ -471,6 +510,7 @@ import type { } from "../types"; import type { ValueOf } from "../utility-types"; import type { RoughCanvas } from "roughjs/bin/canvas"; +import type { Action, ActionResult } from "../actions/types"; const AppContext = React.createContext(null!); const AppPropsContext = React.createContext(null!); diff --git a/packages/excalidraw/components/ElementCanvasButtons.tsx b/packages/excalidraw/components/ElementCanvasButtons.tsx index d15228229..0069b327e 100644 --- a/packages/excalidraw/components/ElementCanvasButtons.tsx +++ b/packages/excalidraw/components/ElementCanvasButtons.tsx @@ -1,15 +1,16 @@ -import { useExcalidrawAppState } from "../components/App"; -import { sceneCoordsToViewportCoords } from "../utils"; -import { getElementAbsoluteCoords } from "../element"; - -import "./ElementCanvasButtons.scss"; - -import type { AppState } from "../types"; +import { sceneCoordsToViewportCoords } from "@excalidraw/common"; +import { getElementAbsoluteCoords } from "@excalidraw/element"; import type { ElementsMap, NonDeletedExcalidrawElement, -} from "../element/types"; +} from "@excalidraw/element/types"; + +import { useExcalidrawAppState } from "../components/App"; + +import "./ElementCanvasButtons.scss"; + +import type { AppState } from "../types"; const CONTAINER_PADDING = 5; diff --git a/packages/excalidraw/cursor.ts b/packages/excalidraw/cursor.ts index 1aa6e52d2..7125ccedf 100644 --- a/packages/excalidraw/cursor.ts +++ b/packages/excalidraw/cursor.ts @@ -1,7 +1,8 @@ import OpenColor from "open-color"; +import { CURSOR_TYPE, MIME_TYPES, THEME } from "@excalidraw/common"; + import { isHandToolActive, isEraserActive } from "./appState"; -import { CURSOR_TYPE, MIME_TYPES, THEME } from "./constants"; import type { AppState, DataURL } from "./types"; diff --git a/packages/excalidraw/data/EditorLocalStorage.ts b/packages/excalidraw/data/EditorLocalStorage.ts index bb6eeb478..18d305315 100644 --- a/packages/excalidraw/data/EditorLocalStorage.ts +++ b/packages/excalidraw/data/EditorLocalStorage.ts @@ -1,4 +1,5 @@ -import type { EDITOR_LS_KEYS } from "../constants"; +import type { EDITOR_LS_KEYS } from "@excalidraw/common"; + import type { JSONValue } from "../types"; export class EditorLocalStorage { diff --git a/packages/excalidraw/data/blob.ts b/packages/excalidraw/data/blob.ts index 54505068f..fdfdfd6a8 100644 --- a/packages/excalidraw/data/blob.ts +++ b/packages/excalidraw/data/blob.ts @@ -1,12 +1,21 @@ import { nanoid } from "nanoid"; +import { + IMAGE_MIME_TYPES, + MIME_TYPES, + bytesToHexString, + isPromiseLike, +} from "@excalidraw/common"; + +import { clearElementsForExport } from "@excalidraw/element"; + +import type { ExcalidrawElement, FileId } from "@excalidraw/element/types"; + import { cleanAppStateForExport } from "../appState"; -import { IMAGE_MIME_TYPES, MIME_TYPES } from "../constants"; -import { clearElementsForExport } from "../element"; + import { CanvasError, ImageSceneDataError } from "../errors"; import { calculateScrollCenter } from "../scene"; import { decodeSvgBase64Payload } from "../scene/export"; -import { bytesToHexString, isPromiseLike } from "../utils"; import { base64ToString, stringToBase64, toByteString } from "./encode"; import { nativeFileSystemSupported } from "./filesystem"; @@ -14,7 +23,7 @@ import { isValidExcalidrawData, isValidLibrary } from "./json"; import { restore, restoreLibraryItems } from "./restore"; import type { FileSystemHandle } from "./filesystem"; -import type { ExcalidrawElement, FileId } from "../element/types"; + import type { AppState, DataURL, LibraryItem } from "../types"; import type { ValueOf } from "../utility-types"; import type { ImportedLibraryData } from "./types"; diff --git a/packages/excalidraw/data/encryption.ts b/packages/excalidraw/data/encryption.ts index a796d05b4..ee1a88f35 100644 --- a/packages/excalidraw/data/encryption.ts +++ b/packages/excalidraw/data/encryption.ts @@ -1,4 +1,4 @@ -import { ENCRYPTION_KEY_BITS } from "../constants"; +import { ENCRYPTION_KEY_BITS } from "@excalidraw/common"; import { blobToArrayBuffer } from "./blob"; diff --git a/packages/excalidraw/data/filesystem.ts b/packages/excalidraw/data/filesystem.ts index 0bdab68fd..0f4ae745f 100644 --- a/packages/excalidraw/data/filesystem.ts +++ b/packages/excalidraw/data/filesystem.ts @@ -4,9 +4,9 @@ import { supported as nativeFileSystemSupported, } from "browser-fs-access"; -import { EVENT, MIME_TYPES } from "../constants"; +import { EVENT, MIME_TYPES, debounce } from "@excalidraw/common"; + import { AbortError } from "../errors"; -import { debounce } from "../utils"; import type { FileSystemHandle } from "browser-fs-access"; diff --git a/packages/excalidraw/data/image.ts b/packages/excalidraw/data/image.ts index e54f7bab5..c9c84c95b 100644 --- a/packages/excalidraw/data/image.ts +++ b/packages/excalidraw/data/image.ts @@ -2,7 +2,7 @@ import tEXt from "png-chunk-text"; import encodePng from "png-chunks-encode"; import decodePng from "png-chunks-extract"; -import { EXPORT_DATA_TYPES, MIME_TYPES } from "../constants"; +import { EXPORT_DATA_TYPES, MIME_TYPES } from "@excalidraw/common"; import { blobToArrayBuffer } from "./blob"; import { encode, decode } from "./encode"; diff --git a/packages/excalidraw/data/index.ts b/packages/excalidraw/data/index.ts index 013ac5b75..ac8147e85 100644 --- a/packages/excalidraw/data/index.ts +++ b/packages/excalidraw/data/index.ts @@ -1,32 +1,39 @@ -import { - copyBlobToClipboardAsPng, - copyTextToSystemClipboard, -} from "../clipboard"; import { DEFAULT_EXPORT_PADDING, DEFAULT_FILENAME, IMAGE_MIME_TYPES, isFirefox, MIME_TYPES, -} from "../constants"; -import { getNonDeletedElements } from "../element"; -import { isFrameLikeElement } from "../element/typeChecks"; -import { getElementsOverlappingFrame } from "../frame"; + cloneJSON, +} from "@excalidraw/common"; + +import { getNonDeletedElements } from "@excalidraw/element"; + +import { isFrameLikeElement } from "@excalidraw/element/typeChecks"; + +import { getElementsOverlappingFrame } from "@excalidraw/element/frame"; + +import type { + ExcalidrawElement, + ExcalidrawFrameLikeElement, + NonDeletedExcalidrawElement, +} from "@excalidraw/element/types"; + +import { + copyBlobToClipboardAsPng, + copyTextToSystemClipboard, +} from "../clipboard"; + import { t } from "../i18n"; import { getSelectedElements, isSomeElementSelected } from "../scene"; import { exportToCanvas, exportToSvg } from "../scene/export"; -import { cloneJSON } from "../utils"; import { canvasToBlob } from "./blob"; import { fileSave } from "./filesystem"; import { serializeAsJSON } from "./json"; import type { FileSystemHandle } from "./filesystem"; -import type { - ExcalidrawElement, - ExcalidrawFrameLikeElement, - NonDeletedExcalidrawElement, -} from "../element/types"; + import type { ExportType } from "../scene/types"; import type { AppState, BinaryFiles } from "../types"; diff --git a/packages/excalidraw/data/json.ts b/packages/excalidraw/data/json.ts index c1cdd4f92..527c9e56e 100644 --- a/packages/excalidraw/data/json.ts +++ b/packages/excalidraw/data/json.ts @@ -1,17 +1,23 @@ -import { cleanAppStateForExport, clearAppStateForDatabase } from "../appState"; import { DEFAULT_FILENAME, EXPORT_DATA_TYPES, EXPORT_SOURCE, MIME_TYPES, VERSIONS, -} from "../constants"; -import { clearElementsForDatabase, clearElementsForExport } from "../element"; +} from "@excalidraw/common"; + +import { + clearElementsForDatabase, + clearElementsForExport, +} from "@excalidraw/element"; + +import type { ExcalidrawElement } from "@excalidraw/element/types"; + +import { cleanAppStateForExport, clearAppStateForDatabase } from "../appState"; import { isImageFileHandle, loadFromBlob, normalizeFile } from "./blob"; import { fileOpen, fileSave } from "./filesystem"; -import type { ExcalidrawElement } from "../element/types"; import type { AppState, BinaryFiles, LibraryItems } from "../types"; import type { ExportedDataState, diff --git a/packages/excalidraw/data/library.ts b/packages/excalidraw/data/library.ts index 76424f54a..fa5e8a8ce 100644 --- a/packages/excalidraw/data/library.ts +++ b/packages/excalidraw/data/library.ts @@ -7,29 +7,33 @@ import { EVENT, DEFAULT_SIDEBAR, LIBRARY_SIDEBAR_TAB, -} from "../constants"; -import { atom, editorJotaiStore } from "../editor-jotai"; -import { hashElementsVersion, hashString } from "../element"; -import { getCommonBoundingBox } from "../element/bounds"; -import { Emitter } from "../emitter"; -import { AbortError } from "../errors"; -import { libraryItemSvgsCache } from "../hooks/useLibraryItemSvg"; -import { t } from "../i18n"; -import { Queue } from "../queue"; -import { arrayToMap, cloneJSON, preventUnload, promiseTry, resolvablePromise, -} from "../utils"; + toValidURL, +} from "@excalidraw/common"; + +import { hashElementsVersion, hashString } from "@excalidraw/element"; + +import { getCommonBoundingBox } from "@excalidraw/element/bounds"; + +import type { ExcalidrawElement } from "@excalidraw/element/types"; + +import { atom, editorJotaiStore } from "../editor-jotai"; + +import { Emitter } from "../emitter"; +import { AbortError } from "../errors"; +import { libraryItemSvgsCache } from "../hooks/useLibraryItemSvg"; +import { t } from "../i18n"; +import { Queue } from "../queue"; import { loadLibraryFromBlob } from "./blob"; import { restoreLibraryItems } from "./restore"; -import { toValidURL } from "./url"; import type App from "../components/App"; -import type { ExcalidrawElement } from "../element/types"; + import type { LibraryItems, LibraryItem, diff --git a/packages/excalidraw/data/reconcile.ts b/packages/excalidraw/data/reconcile.ts index ef644c3aa..0a9e7d99f 100644 --- a/packages/excalidraw/data/reconcile.ts +++ b/packages/excalidraw/data/reconcile.ts @@ -1,14 +1,15 @@ import throttle from "lodash.throttle"; -import { ENV } from "../constants"; +import { ENV, arrayToMap } from "@excalidraw/common"; + +import type { OrderedExcalidrawElement } from "@excalidraw/element/types"; + import { orderByFractionalIndex, syncInvalidIndices, validateFractionalIndices, } from "../fractionalIndex"; -import { arrayToMap } from "../utils"; -import type { OrderedExcalidrawElement } from "../element/types"; import type { AppState } from "../types"; import type { MakeBrand } from "../utility-types"; diff --git a/packages/excalidraw/data/resave.ts b/packages/excalidraw/data/resave.ts index 2c448429a..188041d69 100644 --- a/packages/excalidraw/data/resave.ts +++ b/packages/excalidraw/data/resave.ts @@ -1,8 +1,9 @@ +import type { ExcalidrawElement } from "@excalidraw/element/types"; + import { getFileHandleType, isImageFileHandleType } from "./blob"; import { exportCanvas, prepareElementsForExport } from "."; -import type { ExcalidrawElement } from "../element/types"; import type { AppState, BinaryFiles } from "../types"; export const resaveAsImageWithScene = async ( diff --git a/packages/excalidraw/data/restore.ts b/packages/excalidraw/data/restore.ts index a444d426f..db6556e5f 100644 --- a/packages/excalidraw/data/restore.ts +++ b/packages/excalidraw/data/restore.ts @@ -1,8 +1,5 @@ import { isFiniteNumber, pointFrom } from "@excalidraw/math"; -import type { LocalPoint, Radians } from "@excalidraw/math"; - -import { getDefaultAppState } from "../appState"; import { DEFAULT_FONT_FAMILY, DEFAULT_TEXT_ALIGN, @@ -13,22 +10,28 @@ import { DEFAULT_ELEMENT_PROPS, DEFAULT_GRID_SIZE, DEFAULT_GRID_STEP, -} from "../constants"; + randomId, + getUpdatedTimestamp, + updateActiveTool, + arrayToMap, + getSizeFromPoints, + normalizeLink, +} from "@excalidraw/common"; import { getNonDeletedElements, getNormalizedDimensions, isInvisiblySmallElement, refreshTextDimensions, -} from "../element"; -import { normalizeFixedPoint } from "../element/binding"; +} from "@excalidraw/element"; +import { normalizeFixedPoint } from "@excalidraw/element/binding"; import { updateElbowArrowPoints, validateElbowPoints, -} from "../element/elbowArrow"; -import { LinearElementEditor } from "../element/linearElementEditor"; -import { bumpVersion } from "../element/mutateElement"; -import { getContainerElement } from "../element/textElement"; -import { detectLineHeight } from "../element/textMeasurements"; +} from "@excalidraw/element/elbowArrow"; +import { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; +import { bumpVersion } from "@excalidraw/element/mutateElement"; +import { getContainerElement } from "@excalidraw/element/textElement"; +import { detectLineHeight } from "@excalidraw/element/textMeasurements"; import { isArrowElement, isElbowArrow, @@ -36,20 +39,9 @@ import { isLinearElement, isTextElement, isUsingAdaptiveRadius, -} from "../element/typeChecks"; -import { getLineHeight } from "../fonts/FontMetadata"; -import { syncInvalidIndices } from "../fractionalIndex"; -import { randomId } from "../random"; -import { - getNormalizedGridSize, - getNormalizedGridStep, - getNormalizedZoom, -} from "../scene"; -import { getUpdatedTimestamp, updateActiveTool } from "../utils"; -import { arrayToMap } from "../utils"; -import { getSizeFromPoints } from "../points"; +} from "@excalidraw/element/typeChecks"; -import { normalizeLink } from "./url"; +import type { LocalPoint, Radians } from "@excalidraw/math"; import type { ExcalidrawArrowElement, @@ -65,7 +57,18 @@ import type { OrderedExcalidrawElement, PointBinding, StrokeRoundness, -} from "../element/types"; +} from "@excalidraw/element/types"; + +import { getDefaultAppState } from "../appState"; + +import { getLineHeight } from "../fonts/FontMetadata"; +import { syncInvalidIndices } from "../fractionalIndex"; +import { + getNormalizedGridSize, + getNormalizedGridStep, + getNormalizedZoom, +} from "../scene"; + import type { AppState, BinaryFiles, LibraryItem } from "../types"; import type { MarkOptional, Mutable } from "../utility-types"; import type { ImportedDataState, LegacyAppState } from "./types"; diff --git a/packages/excalidraw/data/transform.test.ts b/packages/excalidraw/data/transform.test.ts index 94f7b6c82..27643e7e1 100644 --- a/packages/excalidraw/data/transform.test.ts +++ b/packages/excalidraw/data/transform.test.ts @@ -1,10 +1,11 @@ import { pointFrom } from "@excalidraw/math"; import { vi } from "vitest"; +import type { ExcalidrawArrowElement } from "@excalidraw/element/types"; + import { convertToExcalidrawElements } from "./transform"; import type { ExcalidrawElementSkeleton } from "./transform"; -import type { ExcalidrawArrowElement } from "../element/types"; const opts = { regenerateIds: false }; diff --git a/packages/excalidraw/data/transform.ts b/packages/excalidraw/data/transform.ts index 07ff60a9c..f1079e33b 100644 --- a/packages/excalidraw/data/transform.ts +++ b/packages/excalidraw/data/transform.ts @@ -5,37 +5,37 @@ import { DEFAULT_FONT_SIZE, TEXT_ALIGN, VERTICAL_ALIGN, -} from "../constants"; -import { - getCommonBounds, - newElement, - newLinearElement, - redrawTextBoundingBox, -} from "../element"; -import { bindLinearElement } from "../element/binding"; -import { - newArrowElement, - newFrameElement, - newImageElement, - newMagicFrameElement, - newTextElement, -} from "../element/newElement"; -import { measureText, normalizeText } from "../element/textMeasurements"; -import { isArrowElement } from "../element/typeChecks"; -import { getLineHeight } from "../fonts/FontMetadata"; -import { syncInvalidIndices } from "../fractionalIndex"; -import { getSizeFromPoints } from "../points"; -import { randomId } from "../random"; -import { + getSizeFromPoints, + randomId, arrayToMap, assertNever, cloneJSON, getFontString, isDevEnv, toBrandedType, -} from "../utils"; +} from "@excalidraw/common"; +import { + getCommonBounds, + newElement, + newLinearElement, + redrawTextBoundingBox, +} from "@excalidraw/element"; +import { bindLinearElement } from "@excalidraw/element/binding"; +import { + newArrowElement, + newFrameElement, + newImageElement, + newMagicFrameElement, + newTextElement, +} from "@excalidraw/element/newElement"; +import { + measureText, + normalizeText, +} from "@excalidraw/element/textMeasurements"; +import { isArrowElement } from "@excalidraw/element/typeChecks"; + +import type { ElementConstructorOpts } from "@excalidraw/element/newElement"; -import type { ElementConstructorOpts } from "../element/newElement"; import type { ElementsMap, ExcalidrawArrowElement, @@ -55,7 +55,11 @@ import type { NonDeletedSceneElementsMap, TextAlign, VerticalAlign, -} from "../element/types"; +} from "@excalidraw/element/types"; + +import { getLineHeight } from "../fonts/FontMetadata"; +import { syncInvalidIndices } from "../fractionalIndex"; + import type { MarkOptional } from "../utility-types"; export type ValidLinearElement = { diff --git a/packages/excalidraw/data/types.ts b/packages/excalidraw/data/types.ts index de3436137..6878b81b1 100644 --- a/packages/excalidraw/data/types.ts +++ b/packages/excalidraw/data/types.ts @@ -1,6 +1,8 @@ +import type { VERSIONS } from "@excalidraw/common"; + +import type { ExcalidrawElement } from "@excalidraw/element/types"; + import type { cleanAppStateForExport } from "../appState"; -import type { VERSIONS } from "../constants"; -import type { ExcalidrawElement } from "../element/types"; import type { AppState, BinaryFiles, diff --git a/packages/excalidraw/distribute.ts b/packages/excalidraw/distribute.ts index 767d3802c..d5d23242d 100644 --- a/packages/excalidraw/distribute.ts +++ b/packages/excalidraw/distribute.ts @@ -1,8 +1,9 @@ -import { getCommonBoundingBox } from "./element/bounds"; -import { newElementWith } from "./element/mutateElement"; -import { getMaximumGroups } from "./groups"; +import { getCommonBoundingBox } from "@excalidraw/element/bounds"; +import { newElementWith } from "@excalidraw/element/mutateElement"; -import type { ElementsMap, ExcalidrawElement } from "./element/types"; +import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types"; + +import { getMaximumGroups } from "./groups"; export interface Distribution { space: "between"; diff --git a/packages/excalidraw/fonts/ExcalidrawFontFace.ts b/packages/excalidraw/fonts/ExcalidrawFontFace.ts index 615fef20f..8295d1015 100644 --- a/packages/excalidraw/fonts/ExcalidrawFontFace.ts +++ b/packages/excalidraw/fonts/ExcalidrawFontFace.ts @@ -1,5 +1,6 @@ +import { promiseTry } from "@excalidraw/common"; + import { subsetWoff2GlyphsByCodepoints } from "../subset/subset-main"; -import { promiseTry } from "../utils"; import { LOCAL_FONT_PROTOCOL } from "./FontMetadata"; diff --git a/packages/excalidraw/fonts/FontMetadata.ts b/packages/excalidraw/fonts/FontMetadata.ts index cc7edd40e..5ed493f2d 100644 --- a/packages/excalidraw/fonts/FontMetadata.ts +++ b/packages/excalidraw/fonts/FontMetadata.ts @@ -1,3 +1,5 @@ +import { FONT_FAMILY, FONT_FAMILY_FALLBACKS } from "@excalidraw/common"; + import type { ExcalidrawTextElement, FontFamilyValues, @@ -9,7 +11,6 @@ import { FontFamilyHeadingIcon, FontFamilyCodeIcon, } from "../components/icons"; -import { FONT_FAMILY, FONT_FAMILY_FALLBACKS } from "../constants"; import type { JSX } from "react"; diff --git a/packages/excalidraw/fonts/Fonts.ts b/packages/excalidraw/fonts/Fonts.ts index c6db51c1c..dba294546 100644 --- a/packages/excalidraw/fonts/Fonts.ts +++ b/packages/excalidraw/fonts/Fonts.ts @@ -4,13 +4,20 @@ import { CJK_HAND_DRAWN_FALLBACK_FONT, WINDOWS_EMOJI_FALLBACK_FONT, getFontFamilyFallbacks, -} from "../constants"; -import { isTextElement } from "../element"; -import { getContainerElement } from "../element/textElement"; -import { charWidth } from "../element/textMeasurements"; -import { containsCJK } from "../element/textWrapping"; +} 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"; + +import { getFontString, PromisePool, promiseTry } from "@excalidraw/common"; + +import type { + ExcalidrawElement, + ExcalidrawTextElement, +} from "@excalidraw/element/types"; + import { ShapeCache } from "../scene/ShapeCache"; -import { getFontString, PromisePool, promiseTry } from "../utils"; import { CascadiaFontFaces } from "./Cascadia"; import { ComicShannsFontFaces } from "./ComicShanns"; @@ -25,11 +32,6 @@ import { NunitoFontFaces } from "./Nunito"; import { VirgilFontFaces } from "./Virgil"; import { XiaolaiFontFaces } from "./Xiaolai"; -import type { - ExcalidrawElement, - ExcalidrawTextElement, - FontFamilyValues, -} from "../element/types"; import type Scene from "../scene/Scene"; import type { ValueOf } from "../utility-types"; diff --git a/packages/excalidraw/fractionalIndex.ts b/packages/excalidraw/fractionalIndex.ts index 8a1459ddd..d45b53bc8 100644 --- a/packages/excalidraw/fractionalIndex.ts +++ b/packages/excalidraw/fractionalIndex.ts @@ -1,16 +1,18 @@ import { generateNKeysBetween } from "fractional-indexing"; -import { mutateElement } from "./element/mutateElement"; -import { getBoundTextElement } from "./element/textElement"; -import { hasBoundTextElement } from "./element/typeChecks"; -import { InvalidFractionalIndexError } from "./errors"; -import { arrayToMap } from "./utils"; +import { mutateElement } from "@excalidraw/element/mutateElement"; +import { getBoundTextElement } from "@excalidraw/element/textElement"; +import { hasBoundTextElement } from "@excalidraw/element/typeChecks"; + +import { arrayToMap } from "@excalidraw/common"; import type { ExcalidrawElement, FractionalIndex, OrderedExcalidrawElement, -} from "./element/types"; +} from "@excalidraw/element/types"; + +import { InvalidFractionalIndexError } from "./errors"; /** * Envisioned relation between array order and fractional indices: diff --git a/packages/excalidraw/frame.test.tsx b/packages/excalidraw/frame.test.tsx index fce420c02..dac3056e7 100644 --- a/packages/excalidraw/frame.test.tsx +++ b/packages/excalidraw/frame.test.tsx @@ -1,11 +1,11 @@ +import type { ExcalidrawElement } from "@excalidraw/element/types"; + import { API } from "./tests/helpers/api"; import { Keyboard, Pointer } from "./tests/helpers/ui"; import { getCloneByOrigId, render } from "./tests/test-utils"; import { convertToExcalidrawElements, Excalidraw } from "./index"; -import type { ExcalidrawElement } from "./element/types"; - const { h } = window; const mouse = new Pointer("mouse"); diff --git a/packages/excalidraw/groups.ts b/packages/excalidraw/groups.ts index a81990832..2bf32b101 100644 --- a/packages/excalidraw/groups.ts +++ b/packages/excalidraw/groups.ts @@ -1,6 +1,4 @@ -import { getBoundTextElement } from "./element/textElement"; -import { getSelectedElements } from "./scene"; -import { makeNextSelectedElementIds } from "./scene/selection"; +import { getBoundTextElement } from "@excalidraw/element/textElement"; import type { GroupId, @@ -9,7 +7,11 @@ import type { NonDeletedExcalidrawElement, ElementsMapOrArray, ElementsMap, -} from "./element/types"; +} from "@excalidraw/element/types"; + +import { getSelectedElements } from "./scene"; +import { makeNextSelectedElementIds } from "./scene/selection"; + import type { AppClassProperties, AppState, diff --git a/packages/excalidraw/history.ts b/packages/excalidraw/history.ts index 48ea012bd..0481c8411 100644 --- a/packages/excalidraw/history.ts +++ b/packages/excalidraw/history.ts @@ -1,7 +1,8 @@ +import type { SceneElementsMap } from "@excalidraw/element/types"; + import { Emitter } from "./emitter"; import type { AppStateChange, ElementsChange } from "./change"; -import type { SceneElementsMap } from "./element/types"; import type { Snapshot } from "./store"; import type { AppState } from "./types"; diff --git a/packages/excalidraw/hooks/useCreatePortalContainer.ts b/packages/excalidraw/hooks/useCreatePortalContainer.ts index b557d7e2f..fb0d24bc3 100644 --- a/packages/excalidraw/hooks/useCreatePortalContainer.ts +++ b/packages/excalidraw/hooks/useCreatePortalContainer.ts @@ -1,7 +1,8 @@ import { useState, useLayoutEffect } from "react"; +import { THEME } from "@excalidraw/common"; + import { useDevice, useExcalidrawContainer } from "../components/App"; -import { THEME } from "../constants"; import { useUIAppState } from "../context/ui-appState"; export const useCreatePortalContainer = (opts?: { diff --git a/packages/excalidraw/hooks/useOutsideClick.ts b/packages/excalidraw/hooks/useOutsideClick.ts index 7ec2113c2..75d68f6e8 100644 --- a/packages/excalidraw/hooks/useOutsideClick.ts +++ b/packages/excalidraw/hooks/useOutsideClick.ts @@ -1,6 +1,6 @@ import { useEffect } from "react"; -import { EVENT } from "../constants"; +import { EVENT } from "@excalidraw/common"; export function useOutsideClick( ref: React.RefObject, diff --git a/packages/excalidraw/index.tsx b/packages/excalidraw/index.tsx index f9f25b530..4ff7b38c2 100644 --- a/packages/excalidraw/index.tsx +++ b/packages/excalidraw/index.tsx @@ -1,16 +1,16 @@ import React, { useEffect } from "react"; +import { DEFAULT_UI_OPTIONS, isShallowEqual } from "@excalidraw/common"; + import App from "./components/App"; import { InitializeApp } from "./components/InitializeApp"; import Footer from "./components/footer/FooterCenter"; import LiveCollaborationTrigger from "./components/live-collaboration/LiveCollaborationTrigger"; import MainMenu from "./components/main-menu/MainMenu"; import WelcomeScreen from "./components/welcome-screen/WelcomeScreen"; -import { DEFAULT_UI_OPTIONS } from "./constants"; import { defaultLang } from "./i18n"; import { EditorJotaiProvider, editorJotaiStore } from "./editor-jotai"; import polyfill from "./polyfill"; -import { isShallowEqual } from "./utils"; import "./css/app.scss"; import "./css/styles.scss"; @@ -218,7 +218,7 @@ export { isInvisiblySmallElement, getNonDeletedElements, getTextFromElements, -} from "./element"; +} from "@excalidraw/element"; export { defaultLang, useI18n, languages } from "./i18n"; export { restore, @@ -244,7 +244,7 @@ export { } from "./data/blob"; export { getFreeDrawSvgPath } from "./renderer/renderElement"; export { mergeLibraryItems, getLibraryItemsHash } from "./data/library"; -export { isLinearElement } from "./element/typeChecks"; +export { isLinearElement } from "@excalidraw/element/typeChecks"; export { FONT_FAMILY, @@ -253,13 +253,14 @@ export { ROUNDNESS, DEFAULT_LASER_COLOR, UserIdleState, -} from "./constants"; + normalizeLink, +} from "@excalidraw/common"; export { mutateElement, newElementWith, bumpVersion, -} from "./element/mutateElement"; +} from "@excalidraw/element/mutateElement"; export { CaptureUpdateAction } from "./store"; @@ -268,7 +269,7 @@ export { parseLibraryTokensFromUrl, useHandleLibrary } from "./data/library"; export { sceneCoordsToViewportCoords, viewportCoordsToSceneCoords, -} from "./utils"; +} from "@excalidraw/common"; export { Sidebar } from "./components/Sidebar/Sidebar"; export { Button } from "./components/Button"; @@ -283,10 +284,12 @@ export { DefaultSidebar } from "./components/DefaultSidebar"; export { TTDDialog } from "./components/TTDDialog/TTDDialog"; export { TTDDialogTrigger } from "./components/TTDDialog/TTDDialogTrigger"; -export { normalizeLink } from "./data/url"; export { zoomToFitBounds } from "./actions/actionCanvas"; export { convertToExcalidrawElements } from "./data/transform"; -export { getCommonBounds, getVisibleSceneBounds } from "./element/bounds"; +export { + getCommonBounds, + getVisibleSceneBounds, +} from "@excalidraw/element/bounds"; export { elementsOverlappingBBox, @@ -296,6 +299,6 @@ export { export { DiagramToCodePlugin } from "./components/DiagramToCodePlugin/DiagramToCodePlugin"; export { getDataURL } from "./data/blob"; -export { isElementLink } from "./element/elementLink"; +export { isElementLink } from "@excalidraw/element/elementLink"; -export { setCustomTextMetricsProvider } from "./element/textMeasurements"; +export { setCustomTextMetricsProvider } from "@excalidraw/element/textMeasurements"; diff --git a/packages/excalidraw/laser-trails.ts b/packages/excalidraw/laser-trails.ts index 06e6b573a..7956ae5d2 100644 --- a/packages/excalidraw/laser-trails.ts +++ b/packages/excalidraw/laser-trails.ts @@ -1,9 +1,9 @@ +import { DEFAULT_LASER_COLOR, easeOut } from "@excalidraw/common"; + import type { LaserPointerOptions } from "@excalidraw/laser-pointer"; import { AnimatedTrail } from "./animated-trail"; import { getClientColor } from "./clients"; -import { DEFAULT_LASER_COLOR } from "./constants"; -import { easeOut } from "./utils"; import type { Trail } from "./animated-trail"; import type { AnimationFrameHandler } from "./animation-frame-handler"; diff --git a/packages/excalidraw/queue.ts b/packages/excalidraw/queue.ts index b7369e5e0..387bd2d70 100644 --- a/packages/excalidraw/queue.ts +++ b/packages/excalidraw/queue.ts @@ -1,7 +1,8 @@ -import { promiseTry, resolvablePromise } from "./utils"; +import { promiseTry, resolvablePromise } from "@excalidraw/common"; + +import type { ResolvablePromise } from "@excalidraw/common"; import type { MaybePromise } from "./utility-types"; -import type { ResolvablePromise } from "./utils"; type Job = (...args: TArgs) => MaybePromise; diff --git a/packages/excalidraw/reactUtils.ts b/packages/excalidraw/reactUtils.ts index 5bc466395..a779fcfcc 100644 --- a/packages/excalidraw/reactUtils.ts +++ b/packages/excalidraw/reactUtils.ts @@ -5,7 +5,7 @@ import { version as ReactVersion } from "react"; import { unstable_batchedUpdates } from "react-dom"; -import { throttleRAF } from "./utils"; +import { throttleRAF } from "@excalidraw/common"; export const withBatchedUpdates = < TFunction extends ((event: any) => void) | (() => void), diff --git a/packages/excalidraw/renderer/helpers.ts b/packages/excalidraw/renderer/helpers.ts index 05097f95b..765ef4294 100644 --- a/packages/excalidraw/renderer/helpers.ts +++ b/packages/excalidraw/renderer/helpers.ts @@ -1,4 +1,4 @@ -import { THEME, THEME_FILTER } from "../constants"; +import { THEME, THEME_FILTER } from "@excalidraw/common"; import type { StaticCanvasRenderConfig } from "../scene/types"; import type { StaticCanvasAppState, AppState } from "../types"; diff --git a/packages/excalidraw/renderer/interactiveScene.ts b/packages/excalidraw/renderer/interactiveScene.ts index 257decd62..5fd64af5f 100644 --- a/packages/excalidraw/renderer/interactiveScene.ts +++ b/packages/excalidraw/renderer/interactiveScene.ts @@ -6,35 +6,62 @@ import { } from "@excalidraw/math"; import oc from "open-color"; -import { getClientColor, renderRemoteCursors } from "../clients"; import { DEFAULT_TRANSFORM_HANDLE_SPACING, FRAME_STYLE, THEME, -} from "../constants"; + arrayToMap, + invariant, + throttleRAF, +} from "@excalidraw/common"; import { getElementAbsoluteCoords, getTransformHandlesFromCoords, getTransformHandles, getCommonBounds, -} from "../element"; +} from "@excalidraw/element"; import { BINDING_HIGHLIGHT_OFFSET, BINDING_HIGHLIGHT_THICKNESS, maxBindingGap, -} from "../element/binding"; -import { LinearElementEditor } from "../element/linearElementEditor"; +} from "@excalidraw/element/binding"; +import { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; import { getOmitSidesForDevice, shouldShowBoundingBox, -} from "../element/transformHandles"; +} from "@excalidraw/element/transformHandles"; import { isElbowArrow, isFrameLikeElement, isImageElement, isLinearElement, isTextElement, -} from "../element/typeChecks"; +} from "@excalidraw/element/typeChecks"; + +import { getCornerRadius } from "@excalidraw/element/shapes"; + +import type { + SuggestedBinding, + SuggestedPointBinding, +} from "@excalidraw/element/binding"; + +import type { + TransformHandles, + TransformHandleType, +} from "@excalidraw/element/transformHandles"; + +import type { + ElementsMap, + ExcalidrawBindableElement, + ExcalidrawElement, + ExcalidrawFrameLikeElement, + ExcalidrawImageElement, + ExcalidrawLinearElement, + ExcalidrawTextElement, + GroupId, + NonDeleted, +} from "@excalidraw/element/types"; + import { isSelectedViaGroup, getSelectedGroupIds, @@ -49,9 +76,9 @@ import { SCROLLBAR_COLOR, SCROLLBAR_WIDTH, } from "../scene/scrollbars"; -import { getCornerRadius } from "../shapes"; import { type InteractiveCanvasAppState } from "../types"; -import { arrayToMap, invariant, throttleRAF } from "../utils"; + +import { getClientColor, renderRemoteCursors } from "../clients"; import { bootstrapCanvas, @@ -59,25 +86,6 @@ import { getNormalizedCanvasDimensions, } from "./helpers"; -import type { - SuggestedBinding, - SuggestedPointBinding, -} from "../element/binding"; -import type { - TransformHandles, - TransformHandleType, -} from "../element/transformHandles"; -import type { - ElementsMap, - ExcalidrawBindableElement, - ExcalidrawElement, - ExcalidrawFrameLikeElement, - ExcalidrawImageElement, - ExcalidrawLinearElement, - ExcalidrawTextElement, - GroupId, - NonDeleted, -} from "../element/types"; import type { InteractiveCanvasRenderConfig, InteractiveSceneRenderConfig, diff --git a/packages/excalidraw/renderer/renderElement.ts b/packages/excalidraw/renderer/renderElement.ts index 9d34cd0eb..84a013164 100644 --- a/packages/excalidraw/renderer/renderElement.ts +++ b/packages/excalidraw/renderer/renderElement.ts @@ -2,7 +2,6 @@ import { isRightAngleRads } from "@excalidraw/math"; import { getStroke } from "perfect-freehand"; import rough from "roughjs/bin/rough"; -import { getDefaultAppState } from "../appState"; import { BOUND_TEXT_PADDING, DEFAULT_REDUCED_GLOBAL_ALPHA, @@ -10,18 +9,21 @@ import { FRAME_STYLE, MIME_TYPES, THEME, -} from "../constants"; -import { getElementAbsoluteCoords } from "../element/bounds"; -import { getUncroppedImageElement } from "../element/cropElement"; -import { LinearElementEditor } from "../element/linearElementEditor"; + distance, + getFontString, + isRTL, +} 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 "../element/textElement"; -import { getLineHeightInPx } from "../element/textMeasurements"; +} from "@excalidraw/element/textElement"; +import { getLineHeightInPx } from "@excalidraw/element/textMeasurements"; import { isTextElement, isLinearElement, @@ -31,12 +33,9 @@ import { hasBoundTextElement, isMagicFrameElement, isImageElement, -} from "../element/typeChecks"; -import { getVerticalOffset } from "../fonts/FontMetadata"; -import { getContainingFrame } from "../frame"; -import { ShapeCache } from "../scene/ShapeCache"; -import { getCornerRadius } from "../shapes"; -import { distance, getFontString, isRTL } from "../utils"; +} from "@excalidraw/element/typeChecks"; +import { getContainingFrame } from "@excalidraw/element/frame"; +import { getCornerRadius } from "@excalidraw/element/shapes"; import type { ExcalidrawElement, @@ -48,7 +47,12 @@ import type { ExcalidrawFrameLikeElement, NonDeletedSceneElementsMap, ElementsMap, -} from "../element/types"; +} from "@excalidraw/element/types"; + +import { getDefaultAppState } from "../appState"; +import { getVerticalOffset } from "../fonts/FontMetadata"; +import { ShapeCache } from "../scene/ShapeCache"; + import type { StaticCanvasRenderConfig, RenderableElementsMap, diff --git a/packages/excalidraw/renderer/renderNewElementScene.ts b/packages/excalidraw/renderer/renderNewElementScene.ts index f80408366..16b191401 100644 --- a/packages/excalidraw/renderer/renderNewElementScene.ts +++ b/packages/excalidraw/renderer/renderNewElementScene.ts @@ -1,4 +1,4 @@ -import { throttleRAF } from "../utils"; +import { throttleRAF } from "@excalidraw/common"; import { bootstrapCanvas, getNormalizedCanvasDimensions } from "./helpers"; import { renderElement } from "./renderElement"; diff --git a/packages/excalidraw/renderer/renderSnaps.ts b/packages/excalidraw/renderer/renderSnaps.ts index 8c26675ac..dd131f779 100644 --- a/packages/excalidraw/renderer/renderSnaps.ts +++ b/packages/excalidraw/renderer/renderSnaps.ts @@ -1,6 +1,6 @@ import { pointFrom, type GlobalPoint, type LocalPoint } from "@excalidraw/math"; -import { THEME } from "../constants"; +import { THEME } from "@excalidraw/common"; import type { PointSnapLine, PointerSnapLine } from "../snapping"; import type { InteractiveCanvasAppState } from "../types"; diff --git a/packages/excalidraw/renderer/staticScene.ts b/packages/excalidraw/renderer/staticScene.ts index 62aeed5b9..ac19776c6 100644 --- a/packages/excalidraw/renderer/staticScene.ts +++ b/packages/excalidraw/renderer/staticScene.ts @@ -1,33 +1,34 @@ -import { - EXTERNAL_LINK_IMG, - ELEMENT_LINK_IMG, - getLinkHandleFromCoords, -} from "../components/hyperlink/helpers"; -import { FRAME_STYLE } from "../constants"; -import { getElementAbsoluteCoords } from "../element"; -import { isElementLink } from "../element/elementLink"; -import { createPlaceholderEmbeddableLabel } from "../element/embeddable"; -import { getBoundTextElement } from "../element/textElement"; +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"; import { isEmbeddableElement, isIframeLikeElement, isTextElement, -} from "../element/typeChecks"; +} from "@excalidraw/element/typeChecks"; import { elementOverlapsWithFrame, getTargetFrame, shouldApplyFrameClip, -} from "../frame"; -import { renderElement } from "../renderer/renderElement"; -import { throttleRAF } from "../utils"; - -import { bootstrapCanvas, getNormalizedCanvasDimensions } from "./helpers"; +} from "@excalidraw/element/frame"; import type { ElementsMap, ExcalidrawFrameLikeElement, NonDeletedExcalidrawElement, -} from "../element/types"; +} from "@excalidraw/element/types"; + +import { + EXTERNAL_LINK_IMG, + ELEMENT_LINK_IMG, + getLinkHandleFromCoords, +} from "../components/hyperlink/helpers"; +import { renderElement } from "../renderer/renderElement"; + +import { bootstrapCanvas, getNormalizedCanvasDimensions } from "./helpers"; + import type { StaticCanvasRenderConfig, StaticSceneRenderConfig, diff --git a/packages/excalidraw/renderer/staticSvgScene.ts b/packages/excalidraw/renderer/staticSvgScene.ts index d8496edc2..12cf9293c 100644 --- a/packages/excalidraw/renderer/staticSvgScene.ts +++ b/packages/excalidraw/renderer/staticSvgScene.ts @@ -3,39 +3,45 @@ import { MAX_DECIMALS_FOR_SVG_EXPORT, MIME_TYPES, SVG_NS, -} from "../constants"; -import { normalizeLink, toValidURL } from "../data/url"; -import { getElementAbsoluteCoords, hashString } from "../element"; -import { getUncroppedWidthAndHeight } from "../element/cropElement"; + getFontFamilyString, + isRTL, + isTestEnv, +} from "@excalidraw/common"; +import { normalizeLink, toValidURL } from "@excalidraw/common"; +import { getElementAbsoluteCoords, hashString } from "@excalidraw/element"; +import { getUncroppedWidthAndHeight } from "@excalidraw/element/cropElement"; import { createPlaceholderEmbeddableLabel, getEmbedLink, -} from "../element/embeddable"; -import { LinearElementEditor } from "../element/linearElementEditor"; +} from "@excalidraw/element/embeddable"; +import { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; import { getBoundTextElement, getContainerElement, -} from "../element/textElement"; -import { getLineHeightInPx } from "../element/textMeasurements"; +} from "@excalidraw/element/textElement"; +import { getLineHeightInPx } from "@excalidraw/element/textMeasurements"; import { isArrowElement, isIframeLikeElement, isInitializedImageElement, isTextElement, -} from "../element/typeChecks"; -import { getVerticalOffset } from "../fonts/FontMetadata"; -import { getContainingFrame } from "../frame"; -import { ShapeCache } from "../scene/ShapeCache"; -import { getCornerRadius, isPathALoop } from "../shapes"; -import { getFontFamilyString, isRTL, isTestEnv } from "../utils"; +} from "@excalidraw/element/typeChecks"; -import { getFreeDrawSvgPath, IMAGE_INVERT_FILTER } from "./renderElement"; +import { getContainingFrame } from "@excalidraw/element/frame"; + +import { getCornerRadius, isPathALoop } from "@excalidraw/element/shapes"; import type { ExcalidrawElement, ExcalidrawTextElementWithContainer, NonDeletedExcalidrawElement, -} from "../element/types"; +} from "@excalidraw/element/types"; + +import { getVerticalOffset } from "../fonts/FontMetadata"; +import { ShapeCache } from "../scene/ShapeCache"; + +import { getFreeDrawSvgPath, IMAGE_INVERT_FILTER } from "./renderElement"; + import type { RenderableElementsMap, SVGRenderConfig } from "../scene/types"; import type { AppState, BinaryFiles } from "../types"; import type { Drawable } from "roughjs/bin/core"; diff --git a/packages/excalidraw/scene/Renderer.ts b/packages/excalidraw/scene/Renderer.ts index 19a6c0b10..e22c997ed 100644 --- a/packages/excalidraw/scene/Renderer.ts +++ b/packages/excalidraw/scene/Renderer.ts @@ -1,16 +1,20 @@ -import { isElementInViewport } from "../element/sizeHelpers"; -import { isImageElement } from "../element/typeChecks"; -import { renderInteractiveSceneThrottled } from "../renderer/interactiveScene"; -import { renderStaticSceneThrottled } from "../renderer/staticScene"; -import { memoize, toBrandedType } from "../utils"; +import { isElementInViewport } from "@excalidraw/element/sizeHelpers"; +import { isImageElement } from "@excalidraw/element/typeChecks"; + +import { memoize, toBrandedType } from "@excalidraw/common"; -import type Scene from "./Scene"; -import type { RenderableElementsMap } from "./types"; import type { ExcalidrawElement, NonDeletedElementsMap, NonDeletedExcalidrawElement, -} from "../element/types"; +} from "@excalidraw/element/types"; + +import { renderInteractiveSceneThrottled } from "../renderer/interactiveScene"; +import { renderStaticSceneThrottled } from "../renderer/staticScene"; + +import type Scene from "./Scene"; +import type { RenderableElementsMap } from "./types"; + import type { AppState } from "../types"; export class Renderer { diff --git a/packages/excalidraw/scene/Scene.ts b/packages/excalidraw/scene/Scene.ts index 0eab8b80e..e9b044acb 100644 --- a/packages/excalidraw/scene/Scene.ts +++ b/packages/excalidraw/scene/Scene.ts @@ -1,21 +1,14 @@ import throttle from "lodash.throttle"; -import { ENV } from "../constants"; -import { isNonDeletedElement } from "../element"; -import { isFrameLikeElement } from "../element/typeChecks"; -import { - syncInvalidIndices, - syncMovedIndices, - validateFractionalIndices, -} from "../fractionalIndex"; -import { getElementsInGroup } from "../groups"; -import { randomInteger } from "../random"; -import { arrayToMap } from "../utils"; -import { toBrandedType } from "../utils"; +import { ENV } from "@excalidraw/common"; +import { isNonDeletedElement } from "@excalidraw/element"; +import { isFrameLikeElement } from "@excalidraw/element/typeChecks"; -import { getSelectedElements } from "./selection"; +import { randomInteger } from "@excalidraw/common"; +import { arrayToMap } from "@excalidraw/common"; +import { toBrandedType } from "@excalidraw/common"; -import type { LinearElementEditor } from "../element/linearElementEditor"; +import type { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; import type { ExcalidrawElement, NonDeletedExcalidrawElement, @@ -26,7 +19,17 @@ import type { NonDeletedSceneElementsMap, OrderedExcalidrawElement, Ordered, -} from "../element/types"; +} from "@excalidraw/element/types"; + +import { getElementsInGroup } from "../groups"; +import { + syncInvalidIndices, + syncMovedIndices, + validateFractionalIndices, +} from "../fractionalIndex"; + +import { getSelectedElements } from "./selection"; + import type { AppState } from "../types"; import type { Assert, SameType } from "../utility-types"; diff --git a/packages/excalidraw/scene/Shape.ts b/packages/excalidraw/scene/Shape.ts index 64d90b789..2d2b22ab8 100644 --- a/packages/excalidraw/scene/Shape.ts +++ b/packages/excalidraw/scene/Shape.ts @@ -1,21 +1,18 @@ import { pointFrom, pointDistance, type LocalPoint } from "@excalidraw/math"; import { simplify } from "points-on-curve"; -import { ROUGHNESS } from "../constants"; -import { getDiamondPoints, getArrowheadPoints } from "../element"; -import { headingForPointIsHorizontal } from "../element/heading"; +import { ROUGHNESS, isTransparent, assertNever } from "@excalidraw/common"; +import { getDiamondPoints, getArrowheadPoints } from "@excalidraw/element"; +import { headingForPointIsHorizontal } from "@excalidraw/element/heading"; import { isElbowArrow, isEmbeddableElement, isIframeElement, isIframeLikeElement, isLinearElement, -} from "../element/typeChecks"; -import { generateFreeDrawShape } from "../renderer/renderElement"; -import { getCornerRadius, isPathALoop } from "../shapes"; -import { isTransparent, assertNever } from "../utils"; +} from "@excalidraw/element/typeChecks"; -import { canChangeRoundness } from "./comparisons"; +import { getCornerRadius, isPathALoop } from "@excalidraw/element/shapes"; import type { ExcalidrawElement, @@ -23,7 +20,12 @@ import type { ExcalidrawSelectionElement, ExcalidrawLinearElement, Arrowhead, -} from "../element/types"; +} from "@excalidraw/element/types"; + +import { generateFreeDrawShape } from "../renderer/renderElement"; + +import { canChangeRoundness } from "./comparisons"; + import type { EmbedsValidationStatus } from "../types"; import type { ElementShapes } from "./types"; import type { Drawable, Options } from "roughjs/bin/core"; diff --git a/packages/excalidraw/scene/ShapeCache.ts b/packages/excalidraw/scene/ShapeCache.ts index c170b0a80..53f2f96d7 100644 --- a/packages/excalidraw/scene/ShapeCache.ts +++ b/packages/excalidraw/scene/ShapeCache.ts @@ -1,14 +1,16 @@ import { RoughGenerator } from "roughjs/bin/generator"; -import { COLOR_PALETTE } from "../colors"; -import { elementWithCanvasCache } from "../renderer/renderElement"; - -import { _generateElementShape } from "./Shape"; +import { COLOR_PALETTE } from "@excalidraw/common"; import type { ExcalidrawElement, ExcalidrawSelectionElement, -} from "../element/types"; +} from "@excalidraw/element/types"; + +import { elementWithCanvasCache } from "../renderer/renderElement"; + +import { _generateElementShape } from "./Shape"; + import type { AppState, EmbedsValidationStatus } from "../types"; import type { ElementShape, ElementShapes } from "./types"; import type { Drawable } from "roughjs/bin/core"; diff --git a/packages/excalidraw/scene/export.ts b/packages/excalidraw/scene/export.ts index 8ca35de2c..79463ea86 100644 --- a/packages/excalidraw/scene/export.ts +++ b/packages/excalidraw/scene/export.ts @@ -1,6 +1,5 @@ import rough from "roughjs/bin/rough"; -import { getDefaultAppState } from "../appState"; import { DEFAULT_EXPORT_PADDING, FRAME_STYLE, @@ -10,39 +9,58 @@ import { THEME_FILTER, MIME_TYPES, EXPORT_DATA_TYPES, -} from "../constants"; -import { base64ToString, decode, encode, stringToBase64 } from "../data/encode"; -import { serializeAsJSON } from "../data/json"; -import { newTextElement } from "../element"; -import { getCommonBounds, getElementAbsoluteCoords } from "../element/bounds"; + arrayToMap, + distance, + getFontString, + toBrandedType, +} from "@excalidraw/common"; + +import { newTextElement } from "@excalidraw/element"; + +import { + getCommonBounds, + getElementAbsoluteCoords, +} from "@excalidraw/element/bounds"; + import { getInitializedImageElements, updateImageCache, -} from "../element/image"; -import { newElementWith } from "../element/mutateElement"; -import { isFrameLikeElement } from "../element/typeChecks"; -import { Fonts } from "../fonts"; -import { syncInvalidIndices } from "../fractionalIndex"; +} from "@excalidraw/element/image"; + +import { newElementWith } from "@excalidraw/element/mutateElement"; + +import { isFrameLikeElement } from "@excalidraw/element/typeChecks"; + import { getElementsOverlappingFrame, getFrameLikeElements, getFrameLikeTitle, getRootElements, -} from "../frame"; -import { renderStaticScene } from "../renderer/staticScene"; -import { renderSceneToSvg } from "../renderer/staticSvgScene"; -import { type Mutable } from "../utility-types"; -import { arrayToMap, distance, getFontString, toBrandedType } from "../utils"; +} from "@excalidraw/element/frame"; + +import type { Bounds } from "@excalidraw/element/bounds"; -import type { RenderableElementsMap } from "./types"; -import type { Bounds } from "../element/bounds"; import type { ExcalidrawElement, ExcalidrawFrameLikeElement, ExcalidrawTextElement, NonDeletedExcalidrawElement, NonDeletedSceneElementsMap, -} from "../element/types"; +} from "@excalidraw/element/types"; + +import { getDefaultAppState } from "../appState"; +import { base64ToString, decode, encode, stringToBase64 } from "../data/encode"; +import { serializeAsJSON } from "../data/json"; + +import { Fonts } from "../fonts"; +import { syncInvalidIndices } from "../fractionalIndex"; + +import { renderStaticScene } from "../renderer/staticScene"; +import { renderSceneToSvg } from "../renderer/staticSvgScene"; +import { type Mutable } from "../utility-types"; + +import type { RenderableElementsMap } from "./types"; + import type { AppState, BinaryFiles } from "../types"; const truncateText = (element: ExcalidrawTextElement, maxWidth: number) => { diff --git a/packages/excalidraw/scene/normalize.ts b/packages/excalidraw/scene/normalize.ts index 0c73c5a8a..605ae2fa6 100644 --- a/packages/excalidraw/scene/normalize.ts +++ b/packages/excalidraw/scene/normalize.ts @@ -1,6 +1,6 @@ -import { clamp, round } from "@excalidraw/math"; +import { MAX_ZOOM, MIN_ZOOM } from "@excalidraw/common"; -import { MAX_ZOOM, MIN_ZOOM } from "../constants"; +import { clamp, round } from "@excalidraw/math"; import type { NormalizedZoomValue } from "../types"; diff --git a/packages/excalidraw/scene/scroll.ts b/packages/excalidraw/scene/scroll.ts index 989564eb0..81504122a 100644 --- a/packages/excalidraw/scene/scroll.ts +++ b/packages/excalidraw/scene/scroll.ts @@ -2,13 +2,14 @@ import { getCommonBounds, getClosestElementBounds, getVisibleElements, -} from "../element"; +} from "@excalidraw/element"; import { sceneCoordsToViewportCoords, viewportCoordsToSceneCoords, -} from "../utils"; +} from "@excalidraw/common"; + +import type { ExcalidrawElement } from "@excalidraw/element/types"; -import type { ExcalidrawElement } from "../element/types"; import type { AppState, Offsets, PointerCoords, Zoom } from "../types"; const isOutsideViewPort = (appState: AppState, cords: Array) => { diff --git a/packages/excalidraw/scene/scrollbars.ts b/packages/excalidraw/scene/scrollbars.ts index b44d79f2b..142127e52 100644 --- a/packages/excalidraw/scene/scrollbars.ts +++ b/packages/excalidraw/scene/scrollbars.ts @@ -1,8 +1,11 @@ -import { getCommonBounds } from "../element"; -import { getLanguage } from "../i18n"; -import { getGlobalCSSVariable } from "../utils"; +import { getCommonBounds } from "@excalidraw/element"; + +import { getGlobalCSSVariable } from "@excalidraw/common"; + +import type { ExcalidrawElement } from "@excalidraw/element/types"; + +import { getLanguage } from "../i18n"; -import type { ExcalidrawElement } from "../element/types"; import type { InteractiveCanvasAppState } from "../types"; import type { ScrollBars } from "./types"; diff --git a/packages/excalidraw/scene/selection.ts b/packages/excalidraw/scene/selection.ts index 02f8f05e7..48fd5eff1 100644 --- a/packages/excalidraw/scene/selection.ts +++ b/packages/excalidraw/scene/selection.ts @@ -1,19 +1,26 @@ -import { getElementAbsoluteCoords, getElementBounds } from "../element"; -import { isElementInViewport } from "../element/sizeHelpers"; -import { isBoundToContainer, isFrameLikeElement } from "../element/typeChecks"; +import { + getElementAbsoluteCoords, + getElementBounds, +} from "@excalidraw/element/bounds"; +import { isElementInViewport } from "@excalidraw/element/sizeHelpers"; +import { + isBoundToContainer, + isFrameLikeElement, +} from "@excalidraw/element/typeChecks"; import { elementOverlapsWithFrame, getContainingFrame, getFrameChildren, -} from "../frame"; -import { isShallowEqual } from "../utils"; +} from "@excalidraw/element/frame"; +import { isShallowEqual } from "@excalidraw/common"; import type { ElementsMap, ElementsMapOrArray, ExcalidrawElement, NonDeletedExcalidrawElement, -} from "../element/types"; +} from "@excalidraw/element/types"; + import type { AppState, InteractiveCanvasAppState } from "../types"; /** diff --git a/packages/excalidraw/scene/types.ts b/packages/excalidraw/scene/types.ts index 3c198d153..814540dfc 100644 --- a/packages/excalidraw/scene/types.ts +++ b/packages/excalidraw/scene/types.ts @@ -1,10 +1,11 @@ -import type { UserIdleState } from "../constants"; +import type { UserIdleState } from "@excalidraw/common"; import type { ExcalidrawElement, NonDeletedElementsMap, NonDeletedExcalidrawElement, NonDeletedSceneElementsMap, -} from "../element/types"; +} from "@excalidraw/element/types"; + import type { AppClassProperties, AppState, diff --git a/packages/excalidraw/snapping.ts b/packages/excalidraw/snapping.ts index f090f03f8..6b44e5407 100644 --- a/packages/excalidraw/snapping.ts +++ b/packages/excalidraw/snapping.ts @@ -7,34 +7,37 @@ import { type GlobalPoint, } from "@excalidraw/math"; -import type { InclusiveRange } from "@excalidraw/math"; - -import { TOOL_TYPE } from "./constants"; +import { TOOL_TYPE, KEYS } from "@excalidraw/common"; import { getCommonBounds, getDraggedElementsBounds, getElementAbsoluteCoords, -} from "./element/bounds"; -import { isBoundToContainer, isFrameLikeElement } from "./element/typeChecks"; +} from "@excalidraw/element/bounds"; +import { + isBoundToContainer, + isFrameLikeElement, +} from "@excalidraw/element/typeChecks"; + +import type { InclusiveRange } from "@excalidraw/math"; + +import type { Bounds } from "@excalidraw/element/bounds"; +import type { MaybeTransformHandleType } from "@excalidraw/element/transformHandles"; +import type { + ElementsMap, + ExcalidrawElement, + NonDeletedExcalidrawElement, +} from "@excalidraw/element/types"; + import { getMaximumGroups } from "./groups"; -import { KEYS } from "./keys"; import { getSelectedElements, getVisibleAndNonSelectedElements, } from "./scene/selection"; -import type { Bounds } from "./element/bounds"; -import type { MaybeTransformHandleType } from "./element/transformHandles"; -import type { - ElementsMap, - ExcalidrawElement, - NonDeletedExcalidrawElement, -} from "./element/types"; import type { AppClassProperties, AppState, KeyboardModifiersObject, - NullableGridSize, } from "./types"; const SNAP_DISTANCE = 8; diff --git a/packages/excalidraw/store.ts b/packages/excalidraw/store.ts index 8b0065884..d1f3f1d3e 100644 --- a/packages/excalidraw/store.ts +++ b/packages/excalidraw/store.ts @@ -1,12 +1,14 @@ +import { ENV, isShallowEqual } from "@excalidraw/common"; + +import { deepCopyElement, newElementWith } from "@excalidraw/element"; + +import type { OrderedExcalidrawElement } from "@excalidraw/element/types"; + import { getDefaultAppState } from "./appState"; import { AppStateChange, ElementsChange } from "./change"; -import { ENV } from "./constants"; -import { newElementWith } from "./element/mutateElement"; -import { deepCopyElement } from "./element/newElement"; -import { Emitter } from "./emitter"; -import { isShallowEqual } from "./utils"; -import type { OrderedExcalidrawElement } from "./element/types"; +import { Emitter } from "./emitter"; + import type { AppState, ObservedAppState } from "./types"; import type { ValueOf } from "./utility-types"; diff --git a/packages/excalidraw/subset/subset-main.ts b/packages/excalidraw/subset/subset-main.ts index 5f39af99c..d5e4ba7be 100644 --- a/packages/excalidraw/subset/subset-main.ts +++ b/packages/excalidraw/subset/subset-main.ts @@ -1,5 +1,6 @@ +import { isServerEnv, promiseTry } from "@excalidraw/common"; + import { WorkerInTheMainChunkError, WorkerUrlNotDefinedError } from "../errors"; -import { isServerEnv, promiseTry } from "../utils"; import { WorkerPool } from "../workers"; import type { Commands } from "./subset-shared.chunk"; diff --git a/packages/excalidraw/types.ts b/packages/excalidraw/types.ts index 64c0ac298..635829e32 100644 --- a/packages/excalidraw/types.ts +++ b/packages/excalidraw/types.ts @@ -1,19 +1,16 @@ -import type { Action } from "./actions/types"; -import type { Spreadsheet } from "./charts"; -import type { ClipboardData } from "./clipboard"; -import type App from "./components/App"; -import type Library from "./data/library"; -import type { FileSystemHandle } from "./data/filesystem"; -import type { IMAGE_MIME_TYPES, MIME_TYPES } from "./constants"; -import type { ContextMenuItems } from "./components/ContextMenu"; -import type { SnapLine } from "./snapping"; -import type { Merge, MaybePromise, ValueOf, MakeBrand } from "./utility-types"; -import type { CaptureUpdateActionType } from "./store"; -import type { UserIdleState } from "./constants"; -import type { ImportedDataState } from "./data/types"; -import type { SuggestedBinding } from "./element/binding"; -import type { LinearElementEditor } from "./element/linearElementEditor"; -import type { MaybeTransformHandleType } from "./element/transformHandles"; +import type { + IMAGE_MIME_TYPES, + UserIdleState, + throttleRAF, + MIME_TYPES, +} from "@excalidraw/common"; + +import type { SuggestedBinding } from "@excalidraw/element/binding"; + +import type { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; + +import type { MaybeTransformHandleType } from "@excalidraw/element/transformHandles"; + import type { PointerType, ExcalidrawLinearElement, @@ -37,10 +34,22 @@ import type { ExcalidrawIframeLikeElement, OrderedExcalidrawElement, ExcalidrawNonSelectionElement, -} from "./element/types"; +} from "@excalidraw/element/types"; + +import type { Action } from "./actions/types"; +import type { Spreadsheet } from "./charts"; +import type { ClipboardData } from "./clipboard"; +import type App from "./components/App"; +import type Library from "./data/library"; +import type { FileSystemHandle } from "./data/filesystem"; +import type { ContextMenuItems } from "./components/ContextMenu"; +import type { SnapLine } from "./snapping"; +import type { Merge, MaybePromise, ValueOf, MakeBrand } from "./utility-types"; +import type { CaptureUpdateActionType } from "./store"; +import type { ImportedDataState } from "./data/types"; + import type { Language } from "./i18n"; import type { isOverScrollBars } from "./scene/scrollbars"; -import type { throttleRAF } from "./utils"; import type React from "react"; import type { JSX } from "react"; diff --git a/packages/excalidraw/visualdebug.ts b/packages/excalidraw/visualdebug.ts index 6b7014864..9ad1490d1 100644 --- a/packages/excalidraw/visualdebug.ts +++ b/packages/excalidraw/visualdebug.ts @@ -6,12 +6,12 @@ import { type LocalPoint, } from "@excalidraw/math"; +import { isBounds } from "@excalidraw/element/typeChecks"; + import type { Curve } from "@excalidraw/math"; import type { LineSegment } from "@excalidraw/utils"; -import { isBounds } from "./element/typeChecks"; - -import type { Bounds } from "./element/bounds"; +import type { Bounds } from "@excalidraw/element/bounds"; // The global data holder to collect the debug operations declare global { diff --git a/packages/excalidraw/workers.ts b/packages/excalidraw/workers.ts index f5964d088..38efda102 100644 --- a/packages/excalidraw/workers.ts +++ b/packages/excalidraw/workers.ts @@ -1,5 +1,6 @@ +import { debounce } from "@excalidraw/common"; + import { WorkerInTheMainChunkError, WorkerUrlNotDefinedError } from "./errors"; -import { debounce } from "./utils"; class IdleWorker { public instance: Worker; diff --git a/packages/excalidraw/wysiwyg/textWysiwyg.test.tsx b/packages/excalidraw/wysiwyg/textWysiwyg.test.tsx index cae3d4069..959c5a012 100644 --- a/packages/excalidraw/wysiwyg/textWysiwyg.test.tsx +++ b/packages/excalidraw/wysiwyg/textWysiwyg.test.tsx @@ -1,15 +1,22 @@ +import { queryByText } from "@testing-library/react"; + import { pointFrom } from "@excalidraw/math"; import { getOriginalContainerHeightFromCache } from "@excalidraw/element/containerCache"; -import { queryByText } from "@testing-library/react"; + +import { + CODES, + KEYS, + FONT_FAMILY, + TEXT_ALIGN, + VERTICAL_ALIGN, +} from "@excalidraw/common"; import type { ExcalidrawTextElement, ExcalidrawTextElementWithContainer, } from "@excalidraw/element/types"; -import { FONT_FAMILY, TEXT_ALIGN, VERTICAL_ALIGN } from "../constants"; import { Excalidraw } from "../index"; -import { CODES, KEYS } from "../keys"; import { API } from "../tests/helpers/api"; import { Keyboard, Pointer, UI } from "../tests/helpers/ui"; import { getTextEditor, updateTextEditor } from "../tests/queries/dom"; diff --git a/packages/excalidraw/wysiwyg/textWysiwyg.tsx b/packages/excalidraw/wysiwyg/textWysiwyg.tsx index 773c0be43..d485d1d9c 100644 --- a/packages/excalidraw/wysiwyg/textWysiwyg.tsx +++ b/packages/excalidraw/wysiwyg/textWysiwyg.tsx @@ -1,3 +1,14 @@ +import { + CODES, + KEYS, + CLASSES, + POINTER_BUTTON, + isWritableElement, + getFontString, + getFontFamilyString, + isTestEnv, +} from "@excalidraw/common"; + import { originalContainerCache, updateOriginalContainerCache, @@ -32,15 +43,7 @@ import type { ExcalidrawTextElement, } from "@excalidraw/element/types"; -import { - isWritableElement, - getFontString, - getFontFamilyString, - isTestEnv, -} from "../utils"; import Scene from "../scene/Scene"; -import { CODES, KEYS } from "../keys"; -import { CLASSES, POINTER_BUTTON } from "../constants"; import { parseClipboard } from "../clipboard"; import { actionDecreaseFontSize, diff --git a/packages/excalidraw/zindex.ts b/packages/excalidraw/zindex.ts index 8ffcec5d1..d33c3166d 100644 --- a/packages/excalidraw/zindex.ts +++ b/packages/excalidraw/zindex.ts @@ -1,14 +1,17 @@ -import { isFrameLikeElement } from "./element/typeChecks"; -import { syncMovedIndices } from "./fractionalIndex"; -import { getElementsInGroup } from "./groups"; -import { getSelectedElements } from "./scene"; -import Scene from "./scene/Scene"; -import { arrayToMap, findIndex, findLastIndex } from "./utils"; +import { isFrameLikeElement } from "@excalidraw/element/typeChecks"; + +import { arrayToMap, findIndex, findLastIndex } from "@excalidraw/common"; import type { ExcalidrawElement, ExcalidrawFrameLikeElement, -} from "./element/types"; +} from "@excalidraw/element/types"; + +import { syncMovedIndices } from "./fractionalIndex"; +import { getElementsInGroup } from "./groups"; +import { getSelectedElements } from "./scene"; +import Scene from "./scene/Scene"; + import type { AppState } from "./types"; const isOfTargetFrame = (element: ExcalidrawElement, frameId: string) => {