refactor: export everything from @excalidraw/element, don't import from subpaths (#9466)

* Don't import from subpaths

* Fix tests, move related tests to element
This commit is contained in:
Marcel Mraz
2025-05-09 23:01:33 +02:00
committed by GitHub
parent a8ebe514da
commit 7e41026812
129 changed files with 517 additions and 541 deletions
@@ -1,7 +1,7 @@
import { LIBRARY_DISABLED_TYPES, randomId } from "@excalidraw/common";
import { deepCopyElement } from "@excalidraw/element/duplicate";
import { deepCopyElement } from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import { t } from "../i18n";
+5 -5
View File
@@ -1,18 +1,18 @@
import { getNonDeletedElements } from "@excalidraw/element";
import { isFrameLikeElement } from "@excalidraw/element/typeChecks";
import { isFrameLikeElement } from "@excalidraw/element";
import { updateFrameMembershipOfSelectedElements } from "@excalidraw/element/frame";
import { updateFrameMembershipOfSelectedElements } from "@excalidraw/element";
import { KEYS, arrayToMap, getShortcutKey } from "@excalidraw/common";
import { alignElements } from "@excalidraw/element/align";
import { alignElements } from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import type { ExcalidrawElement } from "@excalidraw/element/types";
import type { Alignment } from "@excalidraw/element/align";
import type { Alignment } from "@excalidraw/element";
import { ToolButton } from "../components/ToolButton";
import {
@@ -10,14 +10,14 @@ import {
getOriginalContainerHeightFromCache,
resetOriginalContainerCache,
updateOriginalContainerCache,
} from "@excalidraw/element/containerCache";
} from "@excalidraw/element";
import {
computeBoundTextPosition,
computeContainerDimensionForBoundText,
getBoundTextElement,
redrawTextBoundingBox,
} from "@excalidraw/element/textElement";
} from "@excalidraw/element";
import {
hasBoundTextElement,
@@ -25,15 +25,15 @@ import {
isTextBindableContainer,
isTextElement,
isUsingAdaptiveRadius,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { measureText } from "@excalidraw/element/textMeasurements";
import { measureText } from "@excalidraw/element";
import { syncMovedIndices } from "@excalidraw/element/fractionalIndex";
import { syncMovedIndices } from "@excalidraw/element";
import { newElement } from "@excalidraw/element/newElement";
import { newElement } from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import type {
ExcalidrawElement,
+3 -3
View File
@@ -14,10 +14,10 @@ import {
} from "@excalidraw/common";
import { getNonDeletedElements } from "@excalidraw/element";
import { newElementWith } from "@excalidraw/element/mutateElement";
import { getCommonBounds, type SceneBounds } from "@excalidraw/element/bounds";
import { newElementWith } from "@excalidraw/element";
import { getCommonBounds, type SceneBounds } from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import type { ExcalidrawElement } from "@excalidraw/element/types";
@@ -1,9 +1,9 @@
import { isTextElement } from "@excalidraw/element/typeChecks";
import { getTextFromElements } from "@excalidraw/element/textElement";
import { isTextElement } from "@excalidraw/element";
import { getTextFromElements } from "@excalidraw/element";
import { CODES, KEYS, isFirefox } from "@excalidraw/common";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import {
copyTextToSystemClipboard,
@@ -1,6 +1,6 @@
import { isImageElement } from "@excalidraw/element/typeChecks";
import { isImageElement } from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import type { ExcalidrawImageElement } from "@excalidraw/element/types";
@@ -1,23 +1,23 @@
import { KEYS, updateActiveTool } from "@excalidraw/common";
import { getNonDeletedElements } from "@excalidraw/element";
import { fixBindingsAfterDeletion } from "@excalidraw/element/binding";
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import { newElementWith } from "@excalidraw/element/mutateElement";
import { getContainerElement } from "@excalidraw/element/textElement";
import { fixBindingsAfterDeletion } from "@excalidraw/element";
import { LinearElementEditor } from "@excalidraw/element";
import { newElementWith } from "@excalidraw/element";
import { getContainerElement } from "@excalidraw/element";
import {
isBoundToContainer,
isElbowArrow,
isFrameLikeElement,
} from "@excalidraw/element/typeChecks";
import { getFrameChildren } from "@excalidraw/element/frame";
} from "@excalidraw/element";
import { getFrameChildren } from "@excalidraw/element";
import {
getElementsInGroup,
selectGroupsForSelectedElements,
} from "@excalidraw/element/groups";
} from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import type { ExcalidrawElement } from "@excalidraw/element/types";
@@ -1,18 +1,18 @@
import { getNonDeletedElements } from "@excalidraw/element";
import { isFrameLikeElement } from "@excalidraw/element/typeChecks";
import { isFrameLikeElement } from "@excalidraw/element";
import { CODES, KEYS, arrayToMap, getShortcutKey } from "@excalidraw/common";
import { updateFrameMembershipOfSelectedElements } from "@excalidraw/element/frame";
import { updateFrameMembershipOfSelectedElements } from "@excalidraw/element";
import { distributeElements } from "@excalidraw/element/distribute";
import { distributeElements } from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import type { ExcalidrawElement } from "@excalidraw/element/types";
import type { Distribution } from "@excalidraw/element/distribute";
import type { Distribution } from "@excalidraw/element";
import { ToolButton } from "../components/ToolButton";
import {
@@ -7,18 +7,18 @@ import {
import { getNonDeletedElements } from "@excalidraw/element";
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import { LinearElementEditor } from "@excalidraw/element";
import {
getSelectedElements,
getSelectionStateForElements,
} from "@excalidraw/element/selection";
} from "@excalidraw/element";
import { syncMovedIndices } from "@excalidraw/element/fractionalIndex";
import { syncMovedIndices } from "@excalidraw/element";
import { duplicateElements } from "@excalidraw/element/duplicate";
import { duplicateElements } from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import { ToolButton } from "../components/ToolButton";
import { DuplicateIcon } from "../components/icons";
@@ -2,9 +2,9 @@ import {
canCreateLinkFromElements,
defaultGetElementLinkFromSelection,
getLinkIdAndTypeFromSelection,
} from "@excalidraw/element/elementLink";
} from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import { copyTextToSystemClipboard } from "../clipboard";
import { copyIcon, elementLinkIcon } from "../components/icons";
@@ -1,10 +1,10 @@
import { KEYS, arrayToMap } from "@excalidraw/common";
import { newElementWith } from "@excalidraw/element/mutateElement";
import { newElementWith } from "@excalidraw/element";
import { isFrameLikeElement } from "@excalidraw/element/typeChecks";
import { isFrameLikeElement } from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import type { ExcalidrawElement } from "@excalidraw/element/types";
@@ -1,6 +1,6 @@
import { updateActiveTool } from "@excalidraw/common";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import { setCursorForShape } from "../cursor";
+1 -1
View File
@@ -7,7 +7,7 @@ import {
import { getNonDeletedElements } from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import type { Theme } from "@excalidraw/element/types";
@@ -3,20 +3,17 @@ import { pointFrom } from "@excalidraw/math";
import {
maybeBindLinearElement,
bindOrUnbindLinearElement,
} from "@excalidraw/element/binding";
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
} from "@excalidraw/element";
import { LinearElementEditor } from "@excalidraw/element";
import {
isBindingElement,
isLinearElement,
} from "@excalidraw/element/typeChecks";
import { isBindingElement, isLinearElement } from "@excalidraw/element";
import { KEYS, arrayToMap, updateActiveTool } from "@excalidraw/common";
import { isPathALoop } from "@excalidraw/element/shapes";
import { isPathALoop } from "@excalidraw/element";
import { isInvisiblySmallElement } from "@excalidraw/element/sizeHelpers";
import { isInvisiblySmallElement } from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import { t } from "../i18n";
import { resetCursor } from "../cursor";
+8 -8
View File
@@ -2,20 +2,20 @@ import { getNonDeletedElements } from "@excalidraw/element";
import {
bindOrUnbindLinearElements,
isBindingEnabled,
} from "@excalidraw/element/binding";
import { getCommonBoundingBox } from "@excalidraw/element/bounds";
import { newElementWith } from "@excalidraw/element/mutateElement";
import { deepCopyElement } from "@excalidraw/element/duplicate";
import { resizeMultipleElements } from "@excalidraw/element/resizeElements";
} from "@excalidraw/element";
import { getCommonBoundingBox } from "@excalidraw/element";
import { newElementWith } from "@excalidraw/element";
import { deepCopyElement } from "@excalidraw/element";
import { resizeMultipleElements } from "@excalidraw/element";
import {
isArrowElement,
isElbowArrow,
isLinearElement,
} from "@excalidraw/element/typeChecks";
import { updateFrameMembershipOfSelectedElements } from "@excalidraw/element/frame";
} from "@excalidraw/element";
import { updateFrameMembershipOfSelectedElements } from "@excalidraw/element";
import { CODES, KEYS, arrayToMap } from "@excalidraw/common";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import type {
ExcalidrawArrowElement,
+8 -8
View File
@@ -1,20 +1,20 @@
import { getNonDeletedElements } from "@excalidraw/element";
import { mutateElement } from "@excalidraw/element/mutateElement";
import { newFrameElement } from "@excalidraw/element/newElement";
import { isFrameLikeElement } from "@excalidraw/element/typeChecks";
import { mutateElement } from "@excalidraw/element";
import { newFrameElement } from "@excalidraw/element";
import { isFrameLikeElement } from "@excalidraw/element";
import {
addElementsToFrame,
removeAllElementsFromFrame,
} from "@excalidraw/element/frame";
import { getFrameChildren } from "@excalidraw/element/frame";
} from "@excalidraw/element";
import { getFrameChildren } from "@excalidraw/element";
import { KEYS, updateActiveTool } from "@excalidraw/common";
import { getElementsInGroup } from "@excalidraw/element/groups";
import { getElementsInGroup } from "@excalidraw/element";
import { getCommonBounds } from "@excalidraw/element/bounds";
import { getCommonBounds } from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import type { ExcalidrawElement } from "@excalidraw/element/types";
+6 -6
View File
@@ -1,8 +1,8 @@
import { getNonDeletedElements } from "@excalidraw/element";
import { newElementWith } from "@excalidraw/element/mutateElement";
import { newElementWith } from "@excalidraw/element";
import { isBoundToContainer } from "@excalidraw/element/typeChecks";
import { isBoundToContainer } from "@excalidraw/element";
import {
frameAndChildrenSelectedTogether,
@@ -12,7 +12,7 @@ import {
groupByFrameLikes,
removeElementsFromFrame,
replaceAllElementsInFrame,
} from "@excalidraw/element/frame";
} from "@excalidraw/element";
import { KEYS, randomId, arrayToMap, getShortcutKey } from "@excalidraw/common";
@@ -24,11 +24,11 @@ import {
addToGroup,
removeFromSelectedGroups,
isElementInGroup,
} from "@excalidraw/element/groups";
} from "@excalidraw/element";
import { syncMovedIndices } from "@excalidraw/element/fractionalIndex";
import { syncMovedIndices } from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import type {
ExcalidrawElement,
@@ -1,8 +1,8 @@
import { isWindows, KEYS, matchKey, arrayToMap } from "@excalidraw/common";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import { orderByFractionalIndex } from "@excalidraw/element/fractionalIndex";
import { orderByFractionalIndex } from "@excalidraw/element";
import type { SceneElementsMap } from "@excalidraw/element/types";
@@ -1,10 +1,10 @@
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import { LinearElementEditor } from "@excalidraw/element";
import { isElbowArrow, isLinearElement } from "@excalidraw/element/typeChecks";
import { isElbowArrow, isLinearElement } from "@excalidraw/element";
import { arrayToMap } from "@excalidraw/common";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import type { ExcalidrawLinearElement } from "@excalidraw/element/types";
+2 -2
View File
@@ -1,8 +1,8 @@
import { isEmbeddableElement } from "@excalidraw/element/typeChecks";
import { isEmbeddableElement } from "@excalidraw/element";
import { KEYS, getShortcutKey } from "@excalidraw/common";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import { ToolButton } from "../components/ToolButton";
import { getContextMenuLabel } from "../components/hyperlink/Hyperlink";
+2 -2
View File
@@ -2,9 +2,9 @@ import { KEYS } from "@excalidraw/common";
import { getNonDeletedElements } from "@excalidraw/element";
import { showSelectedShapeActions } from "@excalidraw/element/showSelectedShapeActions";
import { showSelectedShapeActions } from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import { ToolButton } from "../components/ToolButton";
import { HamburgerMenuIcon, HelpIconThin, palette } from "../components/icons";
@@ -1,6 +1,6 @@
import clsx from "clsx";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import { getClientColor } from "../clients";
import { Avatar } from "../components/Avatar";
@@ -30,16 +30,16 @@ import {
calculateFixedPointForElbowArrowBinding,
getHoveredElementForBinding,
updateBoundElements,
} from "@excalidraw/element/binding";
} from "@excalidraw/element";
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import { LinearElementEditor } from "@excalidraw/element";
import { newElementWith } from "@excalidraw/element/mutateElement";
import { newElementWith } from "@excalidraw/element";
import {
getBoundTextElement,
redrawTextBoundingBox,
} from "@excalidraw/element/textElement";
} from "@excalidraw/element";
import {
isArrowElement,
@@ -48,13 +48,13 @@ import {
isLinearElement,
isTextElement,
isUsingAdaptiveRadius,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { hasStrokeColor } from "@excalidraw/element/comparisons";
import { hasStrokeColor } from "@excalidraw/element";
import { updateElbowArrowPoints } from "@excalidraw/element/elbowArrow";
import { updateElbowArrowPoints } from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import type { LocalPoint } from "@excalidraw/math";
@@ -70,9 +70,9 @@ import type {
VerticalAlign,
} from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import type { CaptureUpdateActionType } from "@excalidraw/element/store";
import type { CaptureUpdateActionType } from "@excalidraw/element";
import { trackEvent } from "../analytics";
import { ButtonIconSelect } from "../components/ButtonIconSelect";
@@ -1,12 +1,12 @@
import { getNonDeletedElements } from "@excalidraw/element";
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import { isLinearElement, isTextElement } from "@excalidraw/element/typeChecks";
import { LinearElementEditor } from "@excalidraw/element";
import { isLinearElement, isTextElement } from "@excalidraw/element";
import { arrayToMap, KEYS } from "@excalidraw/common";
import { selectGroupsForSelectedElements } from "@excalidraw/element/groups";
import { selectGroupsForSelectedElements } from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import type { ExcalidrawElement } from "@excalidraw/element/types";
+4 -4
View File
@@ -7,7 +7,7 @@ import {
getLineHeight,
} from "@excalidraw/common";
import { newElementWith } from "@excalidraw/element/mutateElement";
import { newElementWith } from "@excalidraw/element";
import {
hasBoundTextElement,
@@ -17,14 +17,14 @@ import {
isArrowElement,
isExcalidrawElement,
isTextElement,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import {
getBoundTextElement,
redrawTextBoundingBox,
} from "@excalidraw/element/textElement";
} from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import type { ExcalidrawTextElement } from "@excalidraw/element/types";
@@ -1,11 +1,11 @@
import { getFontString } from "@excalidraw/common";
import { newElementWith } from "@excalidraw/element/mutateElement";
import { measureText } from "@excalidraw/element/textMeasurements";
import { newElementWith } from "@excalidraw/element";
import { measureText } from "@excalidraw/element";
import { isTextElement } from "@excalidraw/element/typeChecks";
import { isTextElement } from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import { getSelectedElements } from "../scene";
@@ -1,6 +1,6 @@
import { CODES, KEYS } from "@excalidraw/common";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import { gridIcon } from "../components/icons";
@@ -1,6 +1,6 @@
import { CODES, KEYS } from "@excalidraw/common";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import { magnetIcon } from "../components/icons";
@@ -5,7 +5,7 @@ import {
DEFAULT_SIDEBAR,
} from "@excalidraw/common";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import { searchIcon } from "../components/icons";
@@ -1,4 +1,4 @@
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import type { ExcalidrawElement } from "@excalidraw/element/types";
@@ -1,6 +1,6 @@
import { CODES, KEYS } from "@excalidraw/common";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import { abacusIcon } from "../components/icons";
@@ -1,6 +1,6 @@
import { CODES, KEYS } from "@excalidraw/common";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import { eyeIcon } from "../components/icons";
@@ -1,6 +1,6 @@
import { CODES, KEYS } from "@excalidraw/common";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import { coffeeIcon } from "../components/icons";
+2 -2
View File
@@ -5,9 +5,9 @@ import {
moveOneRight,
moveAllLeft,
moveAllRight,
} from "@excalidraw/element/zindex";
} from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import {
BringForwardIcon,
+1 -1
View File
@@ -3,7 +3,7 @@ import type {
OrderedExcalidrawElement,
} from "@excalidraw/element/types";
import type { CaptureUpdateActionType } from "@excalidraw/element/store";
import type { CaptureUpdateActionType } from "@excalidraw/element";
import type {
AppClassProperties,
+1 -1
View File
@@ -15,7 +15,7 @@ import {
newTextElement,
newLinearElement,
newElement,
} from "@excalidraw/element/newElement";
} from "@excalidraw/element";
import type { Radians } from "@excalidraw/math";
+4 -4
View File
@@ -7,14 +7,14 @@ import {
isPromiseLike,
} from "@excalidraw/common";
import { mutateElement } from "@excalidraw/element/mutateElement";
import { deepCopyElement } from "@excalidraw/element/duplicate";
import { mutateElement } from "@excalidraw/element";
import { deepCopyElement } from "@excalidraw/element";
import {
isFrameLikeElement,
isInitializedImageElement,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { getContainingFrame } from "@excalidraw/element/frame";
import { getContainingFrame } from "@excalidraw/element";
import type {
ExcalidrawElement,
+3 -3
View File
@@ -11,7 +11,7 @@ import {
import {
shouldAllowVerticalAlign,
suppportsHorizontalAlign,
} from "@excalidraw/element/textElement";
} from "@excalidraw/element";
import {
hasBoundTextElement,
@@ -19,9 +19,9 @@ import {
isImageElement,
isLinearElement,
isTextElement,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { hasStrokeColor, toolIsArrow } from "@excalidraw/element/comparisons";
import { hasStrokeColor, toolIsArrow } from "@excalidraw/element";
import type {
ExcalidrawElement,
+32 -44
View File
@@ -104,10 +104,7 @@ import {
Emitter,
} from "@excalidraw/common";
import {
getCommonBounds,
getElementAbsoluteCoords,
} from "@excalidraw/element/bounds";
import { getCommonBounds, getElementAbsoluteCoords } from "@excalidraw/element";
import {
bindOrUnbindLinearElement,
@@ -120,11 +117,11 @@ import {
shouldEnableBindingForPointerEvent,
updateBoundElements,
getSuggestedBindingsForArrows,
} from "@excalidraw/element/binding";
} from "@excalidraw/element";
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import { LinearElementEditor } from "@excalidraw/element";
import { newElementWith } from "@excalidraw/element/mutateElement";
import { newElementWith } from "@excalidraw/element";
import {
newFrameElement,
@@ -138,12 +135,9 @@ import {
newLinearElement,
newTextElement,
refreshTextDimensions,
} from "@excalidraw/element/newElement";
} from "@excalidraw/element";
import {
deepCopyElement,
duplicateElements,
} from "@excalidraw/element/duplicate";
import { deepCopyElement, duplicateElements } from "@excalidraw/element";
import {
hasBoundTextElement,
@@ -166,7 +160,7 @@ import {
isFlowchartNodeElement,
isBindableElement,
isTextElement,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import {
getLockedLinearCursorAlignSize,
@@ -174,28 +168,28 @@ import {
isElementCompletelyInViewport,
isElementInViewport,
isInvisiblySmallElement,
} from "@excalidraw/element/sizeHelpers";
} from "@excalidraw/element";
import {
getBoundTextShape,
getCornerRadius,
getElementShape,
isPathALoop,
} from "@excalidraw/element/shapes";
} from "@excalidraw/element";
import {
createSrcDoc,
embeddableURLValidator,
maybeParseEmbedSrc,
getEmbedLink,
} from "@excalidraw/element/embeddable";
} from "@excalidraw/element";
import {
getInitializedImageElements,
loadHTMLImageElement,
normalizeSVG,
updateImageCache as _updateImageCache,
} from "@excalidraw/element/image";
} from "@excalidraw/element";
import {
getBoundTextElement,
@@ -203,9 +197,9 @@ import {
getContainerElement,
isValidTextContainer,
redrawTextBoundingBox,
} from "@excalidraw/element/textElement";
} from "@excalidraw/element";
import { shouldShowBoundingBox } from "@excalidraw/element/transformHandles";
import { shouldShowBoundingBox } from "@excalidraw/element";
import {
getFrameChildren,
@@ -222,30 +216,27 @@ import {
getFrameLikeTitle,
getElementsOverlappingFrame,
filterElementsEligibleAsFrameChildren,
} from "@excalidraw/element/frame";
} from "@excalidraw/element";
import {
hitElementBoundText,
hitElementBoundingBoxOnly,
hitElementItself,
} from "@excalidraw/element/collision";
} from "@excalidraw/element";
import { getVisibleSceneBounds } from "@excalidraw/element/bounds";
import { getVisibleSceneBounds } from "@excalidraw/element";
import {
FlowChartCreator,
FlowChartNavigator,
getLinkDirectionFromKey,
} from "@excalidraw/element/flowchart";
} from "@excalidraw/element";
import { cropElement } from "@excalidraw/element/cropElement";
import { cropElement } from "@excalidraw/element";
import { wrapText } from "@excalidraw/element/textWrapping";
import { wrapText } from "@excalidraw/element";
import {
isElementLink,
parseElementLinkFromURL,
} from "@excalidraw/element/elementLink";
import { isElementLink, parseElementLinkFromURL } from "@excalidraw/element";
import {
isMeasureTextSupported,
@@ -255,11 +246,11 @@ import {
getApproxMinLineWidth,
getApproxMinLineHeight,
getMinTextElementWidth,
} from "@excalidraw/element/textMeasurements";
} from "@excalidraw/element";
import { ShapeCache } from "@excalidraw/element/ShapeCache";
import { ShapeCache } from "@excalidraw/element";
import { getRenderOpacity } from "@excalidraw/element/renderElement";
import { getRenderOpacity } from "@excalidraw/element";
import {
editGroupForSelectedElement,
@@ -269,44 +260,41 @@ import {
isElementInGroup,
isSelectedViaGroup,
selectGroupsForSelectedElements,
} from "@excalidraw/element/groups";
} from "@excalidraw/element";
import {
syncInvalidIndices,
syncMovedIndices,
} from "@excalidraw/element/fractionalIndex";
import { syncInvalidIndices, syncMovedIndices } from "@excalidraw/element";
import {
excludeElementsInFramesFromSelection,
getSelectionStateForElements,
makeNextSelectedElementIds,
} from "@excalidraw/element/selection";
} from "@excalidraw/element";
import {
getResizeOffsetXY,
getResizeArrowDirection,
transformElements,
} from "@excalidraw/element/resizeElements";
} from "@excalidraw/element";
import {
getCursorForResizingElement,
getElementWithTransformHandleType,
getTransformHandleTypeFromCoords,
} from "@excalidraw/element/resizeTest";
} from "@excalidraw/element";
import {
dragNewElement,
dragSelectedElements,
getDragOffsetXY,
} from "@excalidraw/element/dragElements";
} from "@excalidraw/element";
import { isNonDeletedElement } from "@excalidraw/element";
import Scene from "@excalidraw/element/Scene";
import { Scene } from "@excalidraw/element";
import { Store, CaptureUpdateAction } from "@excalidraw/element/store";
import { Store, CaptureUpdateAction } from "@excalidraw/element";
import type { ElementUpdate } from "@excalidraw/element/mutateElement";
import type { ElementUpdate } from "@excalidraw/element";
import type { LocalPoint, Radians } from "@excalidraw/math";
@@ -1,6 +1,6 @@
import { type ReactNode, useEffect, useMemo, useRef, useState } from "react";
import { updateElbowArrowPoints } from "@excalidraw/element/elbowArrow";
import { updateElbowArrowPoints } from "@excalidraw/element";
import { pointFrom, pointRotateRads, type LocalPoint } from "@excalidraw/math";
@@ -13,21 +13,21 @@ import {
isLinearElement,
isSharpArrow,
isUsingAdaptiveRadius,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import {
getCommonBoundingBox,
getElementAbsoluteCoords,
} from "@excalidraw/element/bounds";
} from "@excalidraw/element";
import {
getBoundTextElement,
getBoundTextMaxHeight,
getBoundTextMaxWidth,
redrawTextBoundingBox,
} from "@excalidraw/element/textElement";
} from "@excalidraw/element";
import { wrapText } from "@excalidraw/element/textWrapping";
import { wrapText } from "@excalidraw/element";
import {
assertNever,
@@ -37,17 +37,19 @@ import {
updateActiveTool,
} from "@excalidraw/common";
import { measureText } from "@excalidraw/element/textMeasurements";
import { measureText } from "@excalidraw/element";
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import { LinearElementEditor } from "@excalidraw/element";
import {
newArrowElement,
newElement,
newLinearElement,
} from "@excalidraw/element/newElement";
} from "@excalidraw/element";
import { ShapeCache } from "@excalidraw/element/ShapeCache";
import { ShapeCache } from "@excalidraw/element";
import { updateBindings } from "@excalidraw/element";
import type {
ConvertibleGenericTypes,
@@ -66,7 +68,7 @@ import type {
FixedSegment,
} from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import {
bumpVersion,
@@ -76,7 +78,6 @@ import {
} from "..";
import { trackEvent } from "../analytics";
import { atom, editorJotaiStore, useSetAtom } from "../editor-jotai";
import { updateBindings } from "../../element/src/binding";
import "./ConvertElementTypePopup.scss";
import { ToolButton } from "./ToolButton";
@@ -1,5 +1,5 @@
import { sceneCoordsToViewportCoords } from "@excalidraw/common";
import { getElementAbsoluteCoords } from "@excalidraw/element/bounds";
import { getElementAbsoluteCoords } from "@excalidraw/element";
import type {
ElementsMap,
@@ -5,11 +5,11 @@ import { normalizeLink, KEYS } from "@excalidraw/common";
import {
defaultGetElementLinkFromSelection,
getLinkIdAndTypeFromSelection,
} from "@excalidraw/element/elementLink";
} from "@excalidraw/element";
import type { ExcalidrawElement } from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import { t } from "../i18n";
import { getSelectedElements } from "../scene";
@@ -6,11 +6,11 @@ import {
isLinearElement,
isTextBindableContainer,
isTextElement,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { getShortcutKey } from "@excalidraw/common";
import { isNodeInFlowchart } from "@excalidraw/element/flowchart";
import { isNodeInFlowchart } from "@excalidraw/element";
import { t } from "../i18n";
import { isEraserActive } from "../appState";
+3 -3
View File
@@ -10,11 +10,11 @@ import {
isShallowEqual,
} from "@excalidraw/common";
import { mutateElement } from "@excalidraw/element/mutateElement";
import { mutateElement } from "@excalidraw/element";
import { showSelectedShapeActions } from "@excalidraw/element/showSelectedShapeActions";
import { showSelectedShapeActions } from "@excalidraw/element";
import { ShapeCache } from "@excalidraw/element/ShapeCache";
import { ShapeCache } from "@excalidraw/element";
import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types";
@@ -8,7 +8,7 @@ import React, {
import { MIME_TYPES, arrayToMap } from "@excalidraw/common";
import { duplicateElements } from "@excalidraw/element/duplicate";
import { duplicateElements } from "@excalidraw/element";
import { serializeLibraryAsJSON } from "../data/json";
import { useLibraryCache } from "../hooks/useLibraryItemSvg";
@@ -1,6 +1,6 @@
import React from "react";
import { showSelectedShapeActions } from "@excalidraw/element/showSelectedShapeActions";
import { showSelectedShapeActions } from "@excalidraw/element";
import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types";
@@ -11,9 +11,9 @@ import {
getLineHeight,
} from "@excalidraw/common";
import { isElementCompletelyInViewport } from "@excalidraw/element/sizeHelpers";
import { isElementCompletelyInViewport } from "@excalidraw/element";
import { measureText } from "@excalidraw/element/textMeasurements";
import { measureText } from "@excalidraw/element";
import {
KEYS,
@@ -22,11 +22,8 @@ import {
getFontString,
} from "@excalidraw/common";
import { newTextElement } from "@excalidraw/element/newElement";
import {
isFrameLikeElement,
isTextElement,
} from "@excalidraw/element/typeChecks";
import { newTextElement } from "@excalidraw/element";
import { isTextElement, isFrameLikeElement } from "@excalidraw/element";
import { getDefaultFrameName } from "@excalidraw/element/frame";
@@ -1,18 +1,18 @@
import { degreesToRadians, radiansToDegrees } from "@excalidraw/math";
import { getBoundTextElement } from "@excalidraw/element/textElement";
import { isArrowElement, isElbowArrow } from "@excalidraw/element/typeChecks";
import { getBoundTextElement } from "@excalidraw/element";
import { isArrowElement, isElbowArrow } from "@excalidraw/element";
import { updateBindings } from "@excalidraw/element";
import type { Degrees } from "@excalidraw/math";
import type { ExcalidrawElement } from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import { angleIcon } from "../icons";
import { updateBindings } from "../../../element/src/binding";
import DragInput from "./DragInput";
import { getStepSizedValue, isPropertyEditable } from "./utils";
@@ -1,4 +1,4 @@
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import { getNormalizedGridStep } from "../../scene";
@@ -4,13 +4,13 @@ import { MIN_WIDTH_OR_HEIGHT } from "@excalidraw/common";
import {
MINIMAL_CROP_SIZE,
getUncroppedWidthAndHeight,
} from "@excalidraw/element/cropElement";
import { resizeSingleElement } from "@excalidraw/element/resizeElements";
import { isImageElement } from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { resizeSingleElement } from "@excalidraw/element";
import { isImageElement } from "@excalidraw/element";
import type { ExcalidrawElement } from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import DragInput from "./DragInput";
import { getStepSizedValue, isPropertyEditable } from "./utils";
@@ -3,13 +3,13 @@ import { useEffect, useRef, useState } from "react";
import { EVENT, KEYS, cloneJSON } from "@excalidraw/common";
import { deepCopyElement } from "@excalidraw/element/duplicate";
import { deepCopyElement } from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element/store";
import { CaptureUpdateAction } from "@excalidraw/element";
import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import { useApp } from "../App";
import { InlineIcon } from "../InlineIcon";
@@ -1,18 +1,15 @@
import {
getBoundTextElement,
redrawTextBoundingBox,
} from "@excalidraw/element/textElement";
import {
hasBoundTextElement,
isTextElement,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { hasBoundTextElement, isTextElement } from "@excalidraw/element";
import type {
ExcalidrawElement,
ExcalidrawTextElement,
} from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import { fontSizeIcon } from "../icons";
@@ -1,15 +1,15 @@
import { degreesToRadians, radiansToDegrees } from "@excalidraw/math";
import { getBoundTextElement } from "@excalidraw/element/textElement";
import { isArrowElement } from "@excalidraw/element/typeChecks";
import { getBoundTextElement } from "@excalidraw/element";
import { isArrowElement } from "@excalidraw/element";
import { isInGroup } from "@excalidraw/element/groups";
import { isInGroup } from "@excalidraw/element";
import type { Degrees } from "@excalidraw/math";
import type { ExcalidrawElement } from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import { angleIcon } from "../icons";
@@ -2,17 +2,14 @@ import { pointFrom, type GlobalPoint } from "@excalidraw/math";
import { useMemo } from "react";
import { MIN_WIDTH_OR_HEIGHT } from "@excalidraw/common";
import { updateBoundElements } from "@excalidraw/element/binding";
import { updateBoundElements } from "@excalidraw/element";
import {
rescalePointsInElement,
resizeSingleElement,
} from "@excalidraw/element/resizeElements";
import {
getBoundTextElement,
handleBindTextResize,
} from "@excalidraw/element/textElement";
} from "@excalidraw/element";
import { getBoundTextElement, handleBindTextResize } from "@excalidraw/element";
import { isTextElement } from "@excalidraw/element/typeChecks";
import { isTextElement } from "@excalidraw/element";
import { getCommonBounds } from "@excalidraw/utils";
@@ -22,7 +19,7 @@ import type {
NonDeletedSceneElementsMap,
} from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import DragInput from "./DragInput";
import { getAtomicUnits, getStepSizedValue, isPropertyEditable } from "./utils";
@@ -1,13 +1,10 @@
import {
getBoundTextElement,
redrawTextBoundingBox,
} from "@excalidraw/element/textElement";
import {
hasBoundTextElement,
isTextElement,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { hasBoundTextElement, isTextElement } from "@excalidraw/element";
import { isInGroup } from "@excalidraw/element/groups";
import { isInGroup } from "@excalidraw/element";
import type {
ExcalidrawElement,
@@ -15,7 +12,7 @@ import type {
NonDeletedSceneElementsMap,
} from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import { fontSizeIcon } from "../icons";
@@ -1,13 +1,13 @@
import { pointFrom, pointRotateRads } from "@excalidraw/math";
import { useMemo } from "react";
import { isTextElement } from "@excalidraw/element/typeChecks";
import { isTextElement } from "@excalidraw/element";
import { getCommonBounds } from "@excalidraw/element/bounds";
import { getCommonBounds } from "@excalidraw/element";
import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import StatsDragInput from "./DragInput";
import {
@@ -3,12 +3,12 @@ import { clamp, pointFrom, pointRotateRads, round } from "@excalidraw/math";
import {
getFlipAdjustedCropPosition,
getUncroppedWidthAndHeight,
} from "@excalidraw/element/cropElement";
import { isImageElement } from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { isImageElement } from "@excalidraw/element";
import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import StatsDragInput from "./DragInput";
import { getStepSizedValue, moveElement, STEP_SIZE } from "./utils";
@@ -4,13 +4,13 @@ import throttle from "lodash.throttle";
import { useEffect, useMemo, useState, memo } from "react";
import { STATS_PANELS } from "@excalidraw/common";
import { getCommonBounds } from "@excalidraw/element/bounds";
import { getUncroppedWidthAndHeight } from "@excalidraw/element/cropElement";
import { isElbowArrow, isImageElement } from "@excalidraw/element/typeChecks";
import { getCommonBounds } from "@excalidraw/element";
import { getUncroppedWidthAndHeight } from "@excalidraw/element";
import { isElbowArrow, isImageElement } from "@excalidraw/element";
import { frameAndChildrenSelectedTogether } from "@excalidraw/element/frame";
import { frameAndChildrenSelectedTogether } from "@excalidraw/element";
import { elementsAreInSameGroup } from "@excalidraw/element/groups";
import { elementsAreInSameGroup } from "@excalidraw/element";
import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types";
@@ -5,9 +5,9 @@ import { vi } from "vitest";
import { setDateTimeForTests, reseed } from "@excalidraw/common";
import { isInGroup } from "@excalidraw/element/groups";
import { isInGroup } from "@excalidraw/element";
import { isTextElement } from "@excalidraw/element/typeChecks";
import { isTextElement } from "@excalidraw/element";
import type { Degrees } from "@excalidraw/math";
+7 -10
View File
@@ -1,18 +1,17 @@
import { pointFrom, pointRotateRads } from "@excalidraw/math";
import { getBoundTextElement } from "@excalidraw/element/textElement";
import {
isFrameLikeElement,
isTextElement,
} from "@excalidraw/element/typeChecks";
import { getBoundTextElement } from "@excalidraw/element";
import { isFrameLikeElement, isTextElement } from "@excalidraw/element";
import {
getSelectedGroupIds,
getElementsInGroup,
isInGroup,
} from "@excalidraw/element/groups";
} from "@excalidraw/element";
import { getFrameChildren } from "@excalidraw/element/frame";
import { getFrameChildren } from "@excalidraw/element";
import { updateBindings } from "@excalidraw/element";
import type { Radians } from "@excalidraw/math";
@@ -22,9 +21,7 @@ import type {
NonDeletedExcalidrawElement,
} from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import { updateBindings } from "../../../element/src/binding";
import type { Scene } from "@excalidraw/element";
import type { AppState } from "../../types";
@@ -10,16 +10,13 @@ import {
import { EVENT, HYPERLINK_TOOLTIP_DELAY, KEYS } from "@excalidraw/common";
import { getElementAbsoluteCoords } from "@excalidraw/element/bounds";
import { getElementAbsoluteCoords } from "@excalidraw/element";
import { hitElementBoundingBox } from "@excalidraw/element/collision";
import { hitElementBoundingBox } from "@excalidraw/element";
import { isElementLink } from "@excalidraw/element/elementLink";
import { isElementLink } from "@excalidraw/element";
import {
getEmbedLink,
embeddableURLValidator,
} from "@excalidraw/element/embeddable";
import { getEmbedLink, embeddableURLValidator } from "@excalidraw/element";
import {
sceneCoordsToViewportCoords,
@@ -29,9 +26,9 @@ import {
normalizeLink,
} from "@excalidraw/common";
import { isEmbeddableElement } from "@excalidraw/element/typeChecks";
import { isEmbeddableElement } from "@excalidraw/element";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import type {
ElementsMap,
@@ -1,14 +1,14 @@
import { pointFrom, pointRotateRads } from "@excalidraw/math";
import { MIME_TYPES } from "@excalidraw/common";
import { getElementAbsoluteCoords } from "@excalidraw/element/bounds";
import { hitElementBoundingBox } from "@excalidraw/element/collision";
import { getElementAbsoluteCoords } from "@excalidraw/element";
import { hitElementBoundingBox } from "@excalidraw/element";
import { DEFAULT_LINK_SIZE } from "@excalidraw/element/renderElement";
import { DEFAULT_LINK_SIZE } from "@excalidraw/element";
import type { GlobalPoint, Radians } from "@excalidraw/math";
import type { Bounds } from "@excalidraw/element/bounds";
import type { Bounds } from "@excalidraw/element";
import type {
ElementsMap,
NonDeletedExcalidrawElement,
+2 -2
View File
@@ -10,9 +10,9 @@ import {
import { getNonDeletedElements } from "@excalidraw/element";
import { isFrameLikeElement } from "@excalidraw/element/typeChecks";
import { isFrameLikeElement } from "@excalidraw/element";
import { getElementsOverlappingFrame } from "@excalidraw/element/frame";
import { getElementsOverlappingFrame } from "@excalidraw/element";
import type {
ExcalidrawElement,
+1 -1
View File
@@ -19,7 +19,7 @@ import {
import { hashElementsVersion, hashString } from "@excalidraw/element";
import { getCommonBoundingBox } from "@excalidraw/element/bounds";
import { getCommonBoundingBox } from "@excalidraw/element";
import type { ExcalidrawElement } from "@excalidraw/element/types";
+1 -1
View File
@@ -6,7 +6,7 @@ import {
orderByFractionalIndex,
syncInvalidIndices,
validateFractionalIndices,
} from "@excalidraw/element/fractionalIndex";
} from "@excalidraw/element";
import type { OrderedExcalidrawElement } from "@excalidraw/element/types";
+11 -11
View File
@@ -19,15 +19,15 @@ import {
getLineHeight,
} from "@excalidraw/common";
import { getNonDeletedElements } from "@excalidraw/element";
import { normalizeFixedPoint } from "@excalidraw/element/binding";
import { normalizeFixedPoint } from "@excalidraw/element";
import {
updateElbowArrowPoints,
validateElbowPoints,
} 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";
} from "@excalidraw/element";
import { LinearElementEditor } from "@excalidraw/element";
import { bumpVersion } from "@excalidraw/element";
import { getContainerElement } from "@excalidraw/element";
import { detectLineHeight } from "@excalidraw/element";
import {
isArrowBoundToElement,
isArrowElement,
@@ -36,15 +36,15 @@ import {
isLinearElement,
isTextElement,
isUsingAdaptiveRadius,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { syncInvalidIndices } from "@excalidraw/element/fractionalIndex";
import { syncInvalidIndices } from "@excalidraw/element";
import { refreshTextDimensions } from "@excalidraw/element/newElement";
import { refreshTextDimensions } from "@excalidraw/element";
import { getNormalizedDimensions } from "@excalidraw/element/sizeHelpers";
import { getNormalizedDimensions } from "@excalidraw/element";
import { isInvisiblySmallElement } from "@excalidraw/element/sizeHelpers";
import { isInvisiblySmallElement } from "@excalidraw/element";
import type { LocalPoint, Radians } from "@excalidraw/math";
+10 -13
View File
@@ -16,7 +16,7 @@ import {
getLineHeight,
} from "@excalidraw/common";
import { bindLinearElement } from "@excalidraw/element/binding";
import { bindLinearElement } from "@excalidraw/element";
import {
newArrowElement,
newElement,
@@ -25,24 +25,21 @@ import {
newLinearElement,
newMagicFrameElement,
newTextElement,
} from "@excalidraw/element/newElement";
import {
measureText,
normalizeText,
} from "@excalidraw/element/textMeasurements";
import { isArrowElement } from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { measureText, normalizeText } from "@excalidraw/element";
import { isArrowElement } from "@excalidraw/element";
import { syncInvalidIndices } from "@excalidraw/element/fractionalIndex";
import { syncInvalidIndices } from "@excalidraw/element";
import { redrawTextBoundingBox } from "@excalidraw/element/textElement";
import { redrawTextBoundingBox } from "@excalidraw/element";
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import { LinearElementEditor } from "@excalidraw/element";
import { getCommonBounds } from "@excalidraw/element/bounds";
import { getCommonBounds } from "@excalidraw/element";
import Scene from "@excalidraw/element/Scene";
import { Scene } from "@excalidraw/element";
import type { ElementConstructorOpts } from "@excalidraw/element/newElement";
import type { ElementConstructorOpts } from "@excalidraw/element";
import type {
ExcalidrawArrowElement,
+6 -9
View File
@@ -1,21 +1,18 @@
import { arrayToMap, easeOut, THEME } from "@excalidraw/common";
import { getElementLineSegments } from "@excalidraw/element/bounds";
import { getElementLineSegments } from "@excalidraw/element";
import {
lineSegment,
lineSegmentIntersectionPoints,
pointFrom,
} from "@excalidraw/math";
import { getElementsInGroup } from "@excalidraw/element/groups";
import { getElementsInGroup } from "@excalidraw/element";
import { getElementShape } from "@excalidraw/element/shapes";
import { shouldTestInside } from "@excalidraw/element/collision";
import { getElementShape } from "@excalidraw/element";
import { shouldTestInside } from "@excalidraw/element";
import { isPointInShape } from "@excalidraw/utils/collision";
import {
hasBoundTextElement,
isBoundToContainer,
} from "@excalidraw/element/typeChecks";
import { getBoundTextElementId } from "@excalidraw/element/textElement";
import { hasBoundTextElement, isBoundToContainer } from "@excalidraw/element";
import { getBoundTextElementId } from "@excalidraw/element";
import type { GeometricShape } from "@excalidraw/utils/shape";
import type {
+6 -6
View File
@@ -5,9 +5,9 @@ import {
WINDOWS_EMOJI_FALLBACK_FONT,
getFontFamilyFallbacks,
} from "@excalidraw/common";
import { getContainerElement } from "@excalidraw/element/textElement";
import { charWidth } from "@excalidraw/element/textMeasurements";
import { containsCJK } from "@excalidraw/element/textWrapping";
import { getContainerElement } from "@excalidraw/element";
import { charWidth } from "@excalidraw/element";
import { containsCJK } from "@excalidraw/element";
import {
FONT_METADATA,
@@ -17,9 +17,9 @@ import {
promiseTry,
} from "@excalidraw/common";
import { ShapeCache } from "@excalidraw/element/ShapeCache";
import { ShapeCache } from "@excalidraw/element";
import { isTextElement } from "@excalidraw/element/typeChecks";
import { isTextElement } from "@excalidraw/element";
import type {
ExcalidrawElement,
@@ -28,7 +28,7 @@ import type {
import type { ValueOf } from "@excalidraw/common/utility-types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import { CascadiaFontFaces } from "./Cascadia";
import { ComicShannsFontFaces } from "./ComicShanns";
+1 -1
View File
@@ -5,7 +5,7 @@ import {
StoreChange,
StoreDelta,
type Store,
} from "@excalidraw/element/store";
} from "@excalidraw/element";
import type { SceneElementsMap } from "@excalidraw/element/types";
+9 -12
View File
@@ -222,8 +222,8 @@ export {
getNonDeletedElements,
} from "@excalidraw/element";
export { getTextFromElements } from "@excalidraw/element/textElement";
export { isInvisiblySmallElement } from "@excalidraw/element/sizeHelpers";
export { getTextFromElements } from "@excalidraw/element";
export { isInvisiblySmallElement } from "@excalidraw/element";
export { defaultLang, useI18n, languages } from "./i18n";
export {
@@ -248,9 +248,9 @@ export {
loadSceneOrLibraryFromBlob,
loadLibraryFromBlob,
} from "./data/blob";
export { getFreeDrawSvgPath } from "@excalidraw/element/renderElement";
export { getFreeDrawSvgPath } from "@excalidraw/element";
export { mergeLibraryItems, getLibraryItemsHash } from "./data/library";
export { isLinearElement } from "@excalidraw/element/typeChecks";
export { isLinearElement } from "@excalidraw/element";
export {
FONT_FAMILY,
@@ -266,9 +266,9 @@ export {
mutateElement,
newElementWith,
bumpVersion,
} from "@excalidraw/element/mutateElement";
} from "@excalidraw/element";
export { CaptureUpdateAction } from "@excalidraw/element/store";
export { CaptureUpdateAction } from "@excalidraw/element";
export { parseLibraryTokensFromUrl, useHandleLibrary } from "./data/library";
@@ -292,10 +292,7 @@ export { TTDDialogTrigger } from "./components/TTDDialog/TTDDialogTrigger";
export { zoomToFitBounds } from "./actions/actionCanvas";
export { convertToExcalidrawElements } from "./data/transform";
export {
getCommonBounds,
getVisibleSceneBounds,
} from "@excalidraw/element/bounds";
export { getCommonBounds, getVisibleSceneBounds } from "@excalidraw/element";
export {
elementsOverlappingBBox,
@@ -305,6 +302,6 @@ export {
export { DiagramToCodePlugin } from "./components/DiagramToCodePlugin/DiagramToCodePlugin";
export { getDataURL } from "./data/blob";
export { isElementLink } from "@excalidraw/element/elementLink";
export { isElementLink } from "@excalidraw/element";
export { setCustomTextMetricsProvider } from "@excalidraw/element/textMeasurements";
export { setCustomTextMetricsProvider } from "@excalidraw/element";
+6 -6
View File
@@ -4,18 +4,18 @@ import {
pointFrom,
} from "@excalidraw/math";
import { getElementLineSegments } from "@excalidraw/element/bounds";
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import { getElementLineSegments } from "@excalidraw/element";
import { LinearElementEditor } from "@excalidraw/element";
import {
isFrameLikeElement,
isLinearElement,
isTextElement,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { getFrameChildren } from "@excalidraw/element/frame";
import { selectGroupsForSelectedElements } from "@excalidraw/element/groups";
import { getFrameChildren } from "@excalidraw/element";
import { selectGroupsForSelectedElements } from "@excalidraw/element";
import { getContainerElement } from "@excalidraw/element/textElement";
import { getContainerElement } from "@excalidraw/element";
import { arrayToMap, easeOut } from "@excalidraw/common";
+3 -3
View File
@@ -1,8 +1,8 @@
import { elementCenterPoint, THEME, THEME_FILTER } from "@excalidraw/common";
import { FIXED_BINDING_DISTANCE } from "@excalidraw/element/binding";
import { getDiamondPoints } from "@excalidraw/element/bounds";
import { getCornerRadius } from "@excalidraw/element/shapes";
import { FIXED_BINDING_DISTANCE } from "@excalidraw/element";
import { getDiamondPoints } from "@excalidraw/element";
import { getCornerRadius } from "@excalidraw/element";
import {
bezierEquation,
@@ -15,48 +15,42 @@ import {
throttleRAF,
} from "@excalidraw/common";
import {
FIXED_BINDING_DISTANCE,
maxBindingGap,
} from "@excalidraw/element/binding";
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import { FIXED_BINDING_DISTANCE, maxBindingGap } from "@excalidraw/element";
import { LinearElementEditor } from "@excalidraw/element";
import {
getOmitSidesForDevice,
getTransformHandles,
getTransformHandlesFromCoords,
shouldShowBoundingBox,
} from "@excalidraw/element/transformHandles";
} from "@excalidraw/element";
import {
isElbowArrow,
isFrameLikeElement,
isImageElement,
isLinearElement,
isTextElement,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { renderSelectionElement } from "@excalidraw/element/renderElement";
import { renderSelectionElement } from "@excalidraw/element";
import {
getElementsInGroup,
getSelectedGroupIds,
isSelectedViaGroup,
selectGroupsFromGivenElements,
} from "@excalidraw/element/groups";
} from "@excalidraw/element";
import {
getCommonBounds,
getElementAbsoluteCoords,
} from "@excalidraw/element/bounds";
import { getCommonBounds, getElementAbsoluteCoords } from "@excalidraw/element";
import type {
SuggestedBinding,
SuggestedPointBinding,
} from "@excalidraw/element/binding";
} from "@excalidraw/element";
import type {
TransformHandles,
TransformHandleType,
} from "@excalidraw/element/transformHandles";
} from "@excalidraw/element";
import type {
ElementsMap,
@@ -1,6 +1,6 @@
import { throttleRAF } from "@excalidraw/common";
import { renderElement } from "@excalidraw/element/renderElement";
import { renderElement } from "@excalidraw/element";
import { bootstrapCanvas, getNormalizedCanvasDimensions } from "./helpers";
+7 -7
View File
@@ -1,21 +1,21 @@
import { FRAME_STYLE, throttleRAF } from "@excalidraw/common";
import { isElementLink } from "@excalidraw/element/elementLink";
import { createPlaceholderEmbeddableLabel } from "@excalidraw/element/embeddable";
import { getBoundTextElement } from "@excalidraw/element/textElement";
import { isElementLink } from "@excalidraw/element";
import { createPlaceholderEmbeddableLabel } from "@excalidraw/element";
import { getBoundTextElement } from "@excalidraw/element";
import {
isEmbeddableElement,
isIframeLikeElement,
isTextElement,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import {
elementOverlapsWithFrame,
getTargetFrame,
shouldApplyFrameClip,
} from "@excalidraw/element/frame";
} from "@excalidraw/element";
import { renderElement } from "@excalidraw/element/renderElement";
import { renderElement } from "@excalidraw/element";
import { getElementAbsoluteCoords } from "@excalidraw/element/bounds";
import { getElementAbsoluteCoords } from "@excalidraw/element";
import type {
ElementsMap,
+11 -17
View File
@@ -10,36 +10,30 @@ import {
} from "@excalidraw/common";
import { normalizeLink, toValidURL } from "@excalidraw/common";
import { hashString } from "@excalidraw/element";
import { getUncroppedWidthAndHeight } from "@excalidraw/element/cropElement";
import { getUncroppedWidthAndHeight } from "@excalidraw/element";
import {
createPlaceholderEmbeddableLabel,
getEmbedLink,
} from "@excalidraw/element/embeddable";
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import {
getBoundTextElement,
getContainerElement,
} from "@excalidraw/element/textElement";
import { getLineHeightInPx } from "@excalidraw/element/textMeasurements";
} from "@excalidraw/element";
import { LinearElementEditor } from "@excalidraw/element";
import { getBoundTextElement, getContainerElement } from "@excalidraw/element";
import { getLineHeightInPx } from "@excalidraw/element";
import {
isArrowElement,
isIframeLikeElement,
isInitializedImageElement,
isTextElement,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { getContainingFrame } from "@excalidraw/element/frame";
import { getContainingFrame } from "@excalidraw/element";
import { getCornerRadius, isPathALoop } from "@excalidraw/element/shapes";
import { getCornerRadius, isPathALoop } from "@excalidraw/element";
import { ShapeCache } from "@excalidraw/element/ShapeCache";
import { ShapeCache } from "@excalidraw/element";
import {
getFreeDrawSvgPath,
IMAGE_INVERT_FILTER,
} from "@excalidraw/element/renderElement";
import { getFreeDrawSvgPath, IMAGE_INVERT_FILTER } from "@excalidraw/element";
import { getElementAbsoluteCoords } from "@excalidraw/element/bounds";
import { getElementAbsoluteCoords } from "@excalidraw/element";
import type {
ExcalidrawElement,
+3 -3
View File
@@ -1,5 +1,5 @@
import { isElementInViewport } from "@excalidraw/element/sizeHelpers";
import { isImageElement } from "@excalidraw/element/typeChecks";
import { isElementInViewport } from "@excalidraw/element";
import { isImageElement } from "@excalidraw/element";
import { memoize, toBrandedType } from "@excalidraw/common";
@@ -9,7 +9,7 @@ import type {
NonDeletedExcalidrawElement,
} from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import type { Scene } from "@excalidraw/element";
import { renderInteractiveSceneThrottled } from "../renderer/interactiveScene";
import { renderStaticSceneThrottled } from "../renderer/staticScene";
+8 -11
View File
@@ -15,34 +15,31 @@ import {
toBrandedType,
} from "@excalidraw/common";
import {
getCommonBounds,
getElementAbsoluteCoords,
} from "@excalidraw/element/bounds";
import { getCommonBounds, getElementAbsoluteCoords } from "@excalidraw/element";
import {
getInitializedImageElements,
updateImageCache,
} from "@excalidraw/element/image";
} from "@excalidraw/element";
import { newElementWith } from "@excalidraw/element/mutateElement";
import { newElementWith } from "@excalidraw/element";
import { isFrameLikeElement } from "@excalidraw/element/typeChecks";
import { isFrameLikeElement } from "@excalidraw/element";
import {
getElementsOverlappingFrame,
getFrameLikeElements,
getFrameLikeTitle,
getRootElements,
} from "@excalidraw/element/frame";
} from "@excalidraw/element";
import { syncInvalidIndices } from "@excalidraw/element/fractionalIndex";
import { syncInvalidIndices } from "@excalidraw/element";
import { type Mutable } from "@excalidraw/common/utility-types";
import { newTextElement } from "@excalidraw/element/newElement";
import { newTextElement } from "@excalidraw/element";
import type { Bounds } from "@excalidraw/element/bounds";
import type { Bounds } from "@excalidraw/element";
import type {
ExcalidrawElement,
+2 -2
View File
@@ -4,7 +4,7 @@ export {
getCommonAttributeOfSelectedElements,
getSelectedElements,
getTargetElements,
} from "@excalidraw/element/selection";
} from "@excalidraw/element";
export { calculateScrollCenter } from "./scroll";
export {
hasBackground,
@@ -12,7 +12,7 @@ export {
hasStrokeStyle,
canHaveArrowheads,
canChangeRoundness,
} from "@excalidraw/element/comparisons";
} from "@excalidraw/element";
export {
getNormalizedZoom,
getNormalizedGridSize,
+2 -2
View File
@@ -4,9 +4,9 @@ import {
viewportCoordsToSceneCoords,
} from "@excalidraw/common";
import { getClosestElementBounds } from "@excalidraw/element/bounds";
import { getClosestElementBounds } from "@excalidraw/element";
import { getCommonBounds } from "@excalidraw/element/bounds";
import { getCommonBounds } from "@excalidraw/element";
import type { ExcalidrawElement } from "@excalidraw/element/types";
+1 -1
View File
@@ -1,6 +1,6 @@
import { getGlobalCSSVariable } from "@excalidraw/common";
import { getCommonBounds } from "@excalidraw/element/bounds";
import { getCommonBounds } from "@excalidraw/element";
import { getLanguage } from "../i18n";
+6 -9
View File
@@ -12,23 +12,20 @@ import {
getCommonBounds,
getDraggedElementsBounds,
getElementAbsoluteCoords,
} from "@excalidraw/element/bounds";
import {
isBoundToContainer,
isFrameLikeElement,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { isBoundToContainer, isFrameLikeElement } from "@excalidraw/element";
import { getMaximumGroups } from "@excalidraw/element/groups";
import { getMaximumGroups } from "@excalidraw/element";
import {
getSelectedElements,
getVisibleAndNonSelectedElements,
} from "@excalidraw/element/selection";
} from "@excalidraw/element";
import type { InclusiveRange } from "@excalidraw/math";
import type { Bounds } from "@excalidraw/element/bounds";
import type { MaybeTransformHandleType } from "@excalidraw/element/transformHandles";
import type { Bounds } from "@excalidraw/element";
import type { MaybeTransformHandleType } from "@excalidraw/element";
import type {
ElementsMap,
ExcalidrawElement,
@@ -1,57 +0,0 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Test Linear Elements > Test bound text element > should bind text to arrow when clicked on arrow and enter pressed 1`] = `
"Online whiteboard
collaboration made
easy"
`;
exports[`Test Linear Elements > Test bound text element > should bind text to arrow when double clicked 1`] = `
"Online whiteboard
collaboration made
easy"
`;
exports[`Test Linear Elements > Test bound text element > should match styles for text editor 1`] = `
<textarea
class="excalidraw-wysiwyg"
data-type="wysiwyg"
dir="auto"
style="position: absolute; display: inline-block; min-height: 1em; backface-visibility: hidden; margin: 0px; padding: 0px; border: 0px; outline: 0; resize: none; background: transparent; overflow: hidden; z-index: var(--zIndex-wysiwyg); word-break: break-word; white-space: pre-wrap; overflow-wrap: break-word; box-sizing: content-box; width: 10.5px; height: 26.25px; left: 35px; top: 7.5px; transform: translate(0px, 0px) scale(1) rotate(0deg); text-align: center; vertical-align: middle; color: rgb(30, 30, 30); opacity: 1; filter: var(--theme-filter); max-height: 992.5px; font: Emoji 20px 20px; line-height: 1.25; font-family: Excalifont, Xiaolai, Segoe UI Emoji;"
tabindex="0"
wrap="off"
/>
`;
exports[`Test Linear Elements > Test bound text element > should resize and position the bound text and bounding box correctly when 3 pointer arrow element resized 2`] = `
"Online whiteboard
collaboration made
easy"
`;
exports[`Test Linear Elements > Test bound text element > should resize and position the bound text and bounding box correctly when 3 pointer arrow element resized 6`] = `
"Online whiteboard
collaboration made easy"
`;
exports[`Test Linear Elements > Test bound text element > should resize and position the bound text correctly when 2 pointer linear element resized 2`] = `
"Online whiteboard
collaboration made
easy"
`;
exports[`Test Linear Elements > Test bound text element > should resize and position the bound text correctly when 2 pointer linear element resized 5`] = `
"Online whiteboard
collaboration made easy"
`;
exports[`Test Linear Elements > Test bound text element > should wrap the bound text when arrow bound container moves 1`] = `
"Online whiteboard
collaboration made easy"
`;
exports[`Test Linear Elements > Test bound text element > should wrap the bound text when arrow bound container moves 2`] = `
"Online whiteboard
collaboration made
easy"
`;
+2 -2
View File
@@ -1,11 +1,11 @@
import React from "react";
import { vi } from "vitest";
import { getLineHeightInPx } from "@excalidraw/element/textMeasurements";
import { getLineHeightInPx } from "@excalidraw/element";
import { KEYS, arrayToMap, getLineHeight } from "@excalidraw/common";
import { getElementBounds } from "@excalidraw/element/bounds";
import { getElementBounds } from "@excalidraw/element";
import { createPasteEvent, serializeAsClipboardJSON } from "../clipboard";
@@ -1,350 +0,0 @@
import React from "react";
import { vi } from "vitest";
import { KEYS, cloneJSON } from "@excalidraw/common";
import { duplicateElement } from "@excalidraw/element/duplicate";
import type {
ExcalidrawImageElement,
ImageCrop,
} from "@excalidraw/element/types";
import { Excalidraw, exportToCanvas, exportToSvg } from "..";
import { actionFlipHorizontal, actionFlipVertical } from "../actions";
import { API } from "./helpers/api";
import { Keyboard, Pointer, UI } from "./helpers/ui";
import { act, GlobalTestState, render, unmountComponent } from "./test-utils";
import type { NormalizedZoomValue } from "../types";
const { h } = window;
const mouse = new Pointer("mouse");
beforeEach(async () => {
unmountComponent();
mouse.reset();
localStorage.clear();
sessionStorage.clear();
vi.clearAllMocks();
Object.assign(document, {
elementFromPoint: () => GlobalTestState.canvas,
});
await render(<Excalidraw autoFocus={true} handleKeyboardGlobally={true} />);
API.setAppState({
zoom: {
value: 1 as NormalizedZoomValue,
},
});
const image = API.createElement({ type: "image", width: 200, height: 100 });
API.setElements([image]);
API.setAppState({
selectedElementIds: {
[image.id]: true,
},
});
});
const generateRandomNaturalWidthAndHeight = (image: ExcalidrawImageElement) => {
const initialWidth = image.width;
const initialHeight = image.height;
const scale = 1 + Math.random() * 5;
return {
naturalWidth: initialWidth * scale,
naturalHeight: initialHeight * scale,
};
};
const compareCrops = (cropA: ImageCrop, cropB: ImageCrop) => {
(Object.keys(cropA) as [keyof ImageCrop]).forEach((key) => {
const propA = cropA[key];
const propB = cropB[key];
expect(propA as number).toBeCloseTo(propB as number);
});
};
describe("Enter and leave the crop editor", () => {
it("enter the editor by double clicking", () => {
const image = h.elements[0];
expect(h.state.croppingElementId).toBe(null);
mouse.doubleClickOn(image);
expect(h.state.croppingElementId).not.toBe(null);
expect(h.state.croppingElementId).toBe(image.id);
});
it("enter the editor by pressing enter", () => {
const image = h.elements[0];
expect(h.state.croppingElementId).toBe(null);
Keyboard.keyDown(KEYS.ENTER);
expect(h.state.croppingElementId).not.toBe(null);
expect(h.state.croppingElementId).toBe(image.id);
});
it("leave the editor by clicking outside", () => {
const image = h.elements[0];
Keyboard.keyDown(KEYS.ENTER);
expect(h.state.croppingElementId).not.toBe(null);
mouse.click(image.x - 20, image.y - 20);
expect(h.state.croppingElementId).toBe(null);
});
it("leave the editor by pressing escape", () => {
const image = h.elements[0];
mouse.doubleClickOn(image);
expect(h.state.croppingElementId).not.toBe(null);
Keyboard.keyDown(KEYS.ESCAPE);
expect(h.state.croppingElementId).toBe(null);
});
});
describe("Crop an image", () => {
it("Cropping changes the dimension", async () => {
const image = h.elements[0] as ExcalidrawImageElement;
const initialWidth = image.width;
const initialHeight = image.height;
const { naturalWidth, naturalHeight } =
generateRandomNaturalWidthAndHeight(image);
UI.crop(image, "w", naturalWidth, naturalHeight, [initialWidth / 2, 0]);
expect(image.width).toBeLessThan(initialWidth);
UI.crop(image, "n", naturalWidth, naturalHeight, [0, initialHeight / 2]);
expect(image.height).toBeLessThan(initialHeight);
});
it("Cropping has minimal sizes", async () => {
const image = h.elements[0] as ExcalidrawImageElement;
const initialWidth = image.width;
const initialHeight = image.height;
const { naturalWidth, naturalHeight } =
generateRandomNaturalWidthAndHeight(image);
UI.crop(image, "w", naturalWidth, naturalHeight, [initialWidth, 0]);
expect(image.width).toBeLessThan(initialWidth);
expect(image.width).toBeGreaterThan(0);
UI.crop(image, "w", naturalWidth, naturalHeight, [-initialWidth, 0]);
UI.crop(image, "n", naturalWidth, naturalHeight, [0, initialHeight]);
expect(image.height).toBeLessThan(initialHeight);
expect(image.height).toBeGreaterThan(0);
});
it("Preserve aspect ratio", async () => {
let image = h.elements[0] as ExcalidrawImageElement;
const initialWidth = image.width;
const initialHeight = image.height;
const { naturalWidth, naturalHeight } =
generateRandomNaturalWidthAndHeight(image);
UI.crop(image, "w", naturalWidth, naturalHeight, [initialWidth / 3, 0]);
let resizedWidth = image.width;
let resizedHeight = image.height;
// max height, cropping should not change anything
UI.crop(
image,
"w",
naturalWidth,
naturalHeight,
[-initialWidth / 3, 0],
true,
);
expect(image.width).toBeCloseTo(resizedWidth, 10);
expect(image.height).toBeCloseTo(resizedHeight, 10);
// re-crop to initial state
UI.crop(image, "w", naturalWidth, naturalHeight, [-initialWidth / 3, 0]);
// change crop height and width
UI.crop(image, "s", naturalWidth, naturalHeight, [0, -initialHeight / 2]);
UI.crop(image, "e", naturalWidth, naturalHeight, [-initialWidth / 3, 0]);
resizedWidth = image.width;
resizedHeight = image.height;
// test corner handle aspect ratio preserving
UI.crop(image, "se", naturalWidth, naturalHeight, [initialWidth, 0], true);
expect(image.width / image.height).toBe(resizedWidth / resizedHeight);
expect(image.width).toBeLessThanOrEqual(initialWidth + 0.0001);
expect(image.height).toBeLessThanOrEqual(initialHeight + 0.0001);
// reset
image = API.createElement({ type: "image", width: 200, height: 100 });
API.setElements([image]);
API.setAppState({
selectedElementIds: {
[image.id]: true,
},
});
// 50 x 50 square
UI.crop(image, "nw", naturalWidth, naturalHeight, [150, 50]);
UI.crop(image, "n", naturalWidth, naturalHeight, [0, -100], true);
expect(image.width).toBeCloseTo(image.height);
// image is at the corner, not space to its right to expand, should not be able to resize
expect(image.height).toBeCloseTo(50);
UI.crop(image, "nw", naturalWidth, naturalHeight, [-150, -100], true);
expect(image.width).toBeCloseTo(image.height);
// max height should be reached
expect(image.height).toBeCloseTo(initialHeight);
expect(image.width).toBeCloseTo(initialHeight);
});
});
describe("Cropping and other features", async () => {
it("Cropping works independently of duplication", async () => {
const image = h.elements[0] as ExcalidrawImageElement;
const initialWidth = image.width;
const initialHeight = image.height;
const { naturalWidth, naturalHeight } =
generateRandomNaturalWidthAndHeight(image);
UI.crop(image, "nw", naturalWidth, naturalHeight, [
initialWidth / 2,
initialHeight / 2,
]);
Keyboard.keyDown(KEYS.ESCAPE);
const duplicatedImage = duplicateElement(null, new Map(), image);
act(() => {
h.app.scene.insertElement(duplicatedImage);
});
expect(duplicatedImage.width).toBe(image.width);
expect(duplicatedImage.height).toBe(image.height);
UI.crop(duplicatedImage, "nw", naturalWidth, naturalHeight, [
-initialWidth / 2,
-initialHeight / 2,
]);
expect(duplicatedImage.width).toBe(initialWidth);
expect(duplicatedImage.height).toBe(initialHeight);
const resizedWidth = image.width;
const resizedHeight = image.height;
expect(image.width).not.toBe(duplicatedImage.width);
expect(image.height).not.toBe(duplicatedImage.height);
UI.crop(duplicatedImage, "se", naturalWidth, naturalHeight, [
-initialWidth / 1.5,
-initialHeight / 1.5,
]);
expect(duplicatedImage.width).not.toBe(initialWidth);
expect(image.width).toBe(resizedWidth);
expect(duplicatedImage.height).not.toBe(initialHeight);
expect(image.height).toBe(resizedHeight);
});
it("Resizing should not affect crop", async () => {
const image = h.elements[0] as ExcalidrawImageElement;
const initialWidth = image.width;
const initialHeight = image.height;
const { naturalWidth, naturalHeight } =
generateRandomNaturalWidthAndHeight(image);
UI.crop(image, "nw", naturalWidth, naturalHeight, [
initialWidth / 2,
initialHeight / 2,
]);
const cropBeforeResizing = image.crop;
const cropBeforeResizingCloned = cloneJSON(image.crop) as ImageCrop;
expect(cropBeforeResizing).not.toBe(null);
UI.crop(image, "e", naturalWidth, naturalHeight, [200, 0]);
expect(cropBeforeResizing).toBe(image.crop);
compareCrops(cropBeforeResizingCloned, image.crop!);
UI.resize(image, "s", [0, -100]);
expect(cropBeforeResizing).toBe(image.crop);
compareCrops(cropBeforeResizingCloned, image.crop!);
UI.resize(image, "ne", [-50, -50]);
expect(cropBeforeResizing).toBe(image.crop);
compareCrops(cropBeforeResizingCloned, image.crop!);
});
it("Flipping does not change crop", async () => {
const image = h.elements[0] as ExcalidrawImageElement;
const initialWidth = image.width;
const initialHeight = image.height;
const { naturalWidth, naturalHeight } =
generateRandomNaturalWidthAndHeight(image);
mouse.doubleClickOn(image);
expect(h.state.croppingElementId).not.toBe(null);
UI.crop(image, "nw", naturalWidth, naturalHeight, [
initialWidth / 2,
initialHeight / 2,
]);
Keyboard.keyDown(KEYS.ESCAPE);
const cropBeforeResizing = image.crop;
const cropBeforeResizingCloned = cloneJSON(image.crop) as ImageCrop;
API.executeAction(actionFlipHorizontal);
expect(image.crop).toBe(cropBeforeResizing);
compareCrops(cropBeforeResizingCloned, image.crop!);
API.executeAction(actionFlipVertical);
expect(image.crop).toBe(cropBeforeResizing);
compareCrops(cropBeforeResizingCloned, image.crop!);
});
it("Exports should preserve crops", async () => {
const image = h.elements[0] as ExcalidrawImageElement;
const initialWidth = image.width;
const initialHeight = image.height;
const { naturalWidth, naturalHeight } =
generateRandomNaturalWidthAndHeight(image);
mouse.doubleClickOn(image);
expect(h.state.croppingElementId).not.toBe(null);
UI.crop(image, "nw", naturalWidth, naturalHeight, [
initialWidth / 2,
initialHeight / 4,
]);
Keyboard.keyDown(KEYS.ESCAPE);
const widthToHeightRatio = image.width / image.height;
const canvas = await exportToCanvas({
elements: [image],
// @ts-ignore
appState: h.state,
files: h.app.files,
exportPadding: 0,
});
const exportedCanvasRatio = canvas.width / canvas.height;
expect(widthToHeightRatio).toBeCloseTo(exportedCanvasRatio);
const svg = await exportToSvg({
elements: [image],
// @ts-ignore
appState: h.state,
files: h.app.files,
exportPadding: 0,
});
const svgWidth = svg.getAttribute("width");
const svgHeight = svg.getAttribute("height");
expect(svgWidth).toBeDefined();
expect(svgHeight).toBeDefined();
const exportedSvgRatio = Number(svgWidth) / Number(svgHeight);
expect(widthToHeightRatio).toBeCloseTo(exportedSvgRatio);
});
});
@@ -1,4 +1,4 @@
import { syncInvalidIndices } from "@excalidraw/element/fractionalIndex";
import { syncInvalidIndices } from "@excalidraw/element";
import { randomInteger, cloneJSON } from "@excalidraw/common";
@@ -3,8 +3,8 @@ import { vi } from "vitest";
import { DEFAULT_SIDEBAR, FONT_FAMILY, ROUNDNESS } from "@excalidraw/common";
import { newElementWith } from "@excalidraw/element/mutateElement";
import * as sizeHelpers from "@excalidraw/element/sizeHelpers";
import { newElementWith } from "@excalidraw/element";
import * as sizeHelpers from "@excalidraw/element";
import type {
ExcalidrawElement,
+3 -3
View File
@@ -5,9 +5,9 @@ import { ROUNDNESS, KEYS, arrayToMap, cloneJSON } from "@excalidraw/common";
import { pointFrom, type Radians } from "@excalidraw/math";
import { getBoundTextElementPosition } from "@excalidraw/element/textElement";
import { getElementAbsoluteCoords } from "@excalidraw/element/bounds";
import { newLinearElement } from "@excalidraw/element/newElement";
import { getBoundTextElementPosition } from "@excalidraw/element";
import { getElementAbsoluteCoords } from "@excalidraw/element";
import { newLinearElement } from "@excalidraw/element";
import type { LocalPoint } from "@excalidraw/math";
+4 -4
View File
@@ -17,11 +17,11 @@ import {
newLinearElement,
newMagicFrameElement,
newTextElement,
} from "@excalidraw/element/newElement";
} from "@excalidraw/element";
import { isLinearElementType } from "@excalidraw/element/typeChecks";
import { getSelectedElements } from "@excalidraw/element/selection";
import { selectGroupsForSelectedElements } from "@excalidraw/element/groups";
import { isLinearElementType } from "@excalidraw/element";
import { getSelectedElements } from "@excalidraw/element";
import { selectGroupsForSelectedElements } from "@excalidraw/element";
import type {
ExcalidrawElement,
+5 -8
View File
@@ -1,10 +1,7 @@
import { pointFrom, pointRotateRads } from "@excalidraw/math";
import {
getCommonBounds,
getElementPointsCoords,
} from "@excalidraw/element/bounds";
import { cropElement } from "@excalidraw/element/cropElement";
import { getCommonBounds, getElementPointsCoords } from "@excalidraw/element";
import { cropElement } from "@excalidraw/element";
import {
getTransformHandles,
getTransformHandlesFromCoords,
@@ -12,18 +9,18 @@ import {
OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,
type TransformHandle,
type TransformHandleDirection,
} from "@excalidraw/element/transformHandles";
} from "@excalidraw/element";
import {
isLinearElement,
isFreeDrawElement,
isTextElement,
isFrameLikeElement,
} from "@excalidraw/element/typeChecks";
} from "@excalidraw/element";
import { KEYS, arrayToMap, elementCenterPoint } from "@excalidraw/common";
import type { GlobalPoint, LocalPoint, Radians } from "@excalidraw/math";
import type { TransformHandleType } from "@excalidraw/element/transformHandles";
import type { TransformHandleType } from "@excalidraw/element";
import type {
ExcalidrawElement,
ExcalidrawLinearElement,
+3 -3
View File
@@ -8,7 +8,7 @@ import {
import { vi } from "vitest";
import { pointFrom } from "@excalidraw/math";
import { newElementWith } from "@excalidraw/element/mutateElement";
import { newElementWith } from "@excalidraw/element";
import {
EXPORT_DATA_TYPES,
@@ -23,9 +23,9 @@ import {
import "@excalidraw/utils/test-utils";
import { ElementsDelta, AppStateDelta } from "@excalidraw/element/delta";
import { ElementsDelta, AppStateDelta } from "@excalidraw/element";
import { CaptureUpdateAction, StoreDelta } from "@excalidraw/element/store";
import { CaptureUpdateAction, StoreDelta } from "@excalidraw/element";
import type { LocalPoint, Radians } from "@excalidraw/math";
+1 -1
View File
@@ -22,7 +22,7 @@ import {
type ElementsSegmentsMap,
} from "@excalidraw/math";
import { getElementLineSegments } from "@excalidraw/element/bounds";
import { getElementLineSegments } from "@excalidraw/element";
import type { ExcalidrawElement } from "@excalidraw/element/types";
+1 -1
View File
@@ -4,7 +4,7 @@ import { vi } from "vitest";
import { MIME_TYPES, ORIG_ID } from "@excalidraw/common";
import { getCommonBoundingBox } from "@excalidraw/element/bounds";
import { getCommonBoundingBox } from "@excalidraw/element";
import type { ExcalidrawGenericElement } from "@excalidraw/element/types";
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,7 +1,7 @@
import React from "react";
import { vi } from "vitest";
import { bindOrUnbindLinearElement } from "@excalidraw/element/binding";
import { bindOrUnbindLinearElement } from "@excalidraw/element";
import { KEYS, reseed } from "@excalidraw/common";
+1 -1
View File
@@ -11,7 +11,7 @@ import ansi from "ansicolor";
import { ORIG_ID, arrayToMap } from "@excalidraw/common";
import { getSelectedElements } from "@excalidraw/element/selection";
import { getSelectedElements } from "@excalidraw/element";
import type { ExcalidrawElement } from "@excalidraw/element/types";
+4 -4
View File
@@ -5,11 +5,11 @@ import type {
MIME_TYPES,
} from "@excalidraw/common";
import type { SuggestedBinding } from "@excalidraw/element/binding";
import type { SuggestedBinding } from "@excalidraw/element";
import type { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import type { LinearElementEditor } from "@excalidraw/element";
import type { MaybeTransformHandleType } from "@excalidraw/element/transformHandles";
import type { MaybeTransformHandleType } from "@excalidraw/element";
import type {
PointerType,
@@ -47,7 +47,7 @@ import type {
CaptureUpdateActionType,
DurableIncrement,
EphemeralIncrement,
} from "@excalidraw/element/store";
} from "@excalidraw/element";
import type { Action } from "./actions/types";
import type { Spreadsheet } from "./charts";
+2 -2
View File
@@ -6,12 +6,12 @@ import {
type LocalPoint,
} from "@excalidraw/math";
import { isBounds } from "@excalidraw/element/typeChecks";
import { isBounds } from "@excalidraw/element";
import type { Curve } from "@excalidraw/math";
import type { LineSegment } from "@excalidraw/utils";
import type { Bounds } from "@excalidraw/element/bounds";
import type { Bounds } from "@excalidraw/element";
// The global data holder to collect the debug operations
declare global {
@@ -1,7 +1,7 @@
import { queryByText } from "@testing-library/react";
import { pointFrom } from "@excalidraw/math";
import { getOriginalContainerHeightFromCache } from "@excalidraw/element/containerCache";
import { getOriginalContainerHeightFromCache } from "@excalidraw/element";
import {
CODES,

Some files were not shown because too many files have changed in this diff Show More