Fx imports and most tests

This commit is contained in:
Marcel Mraz 2025-03-20 13:50:36 +01:00
parent ddac2e969a
commit 40ff1b08ae
70 changed files with 335 additions and 305 deletions

View file

@ -2,18 +2,25 @@ import { simplify } from "points-on-curve";
import { pointFrom, pointDistance, type LocalPoint } from "@excalidraw/math";
import { ROUGHNESS, isTransparent, assertNever } from "@excalidraw/common";
import { getDiamondPoints, getArrowheadPoints } from "@excalidraw/element";
import { headingForPointIsHorizontal } from "@excalidraw/element/heading";
import { getCornerRadius, isPathALoop } from "@excalidraw/element/shapes";
import type { Mutable } from "@excalidraw/common/utility-types";
import type { EmbedsValidationStatus } from "@excalidraw/excalidraw/types";
import type { ElementShapes } from "@excalidraw/excalidraw/scene/types";
import {
isElbowArrow,
isEmbeddableElement,
isIframeElement,
isIframeLikeElement,
isLinearElement,
} from "@excalidraw/element/typeChecks";
} from "./typeChecks";
import { getCornerRadius, isPathALoop } from "./shapes";
import { headingForPointIsHorizontal } from "./heading";
import type { Mutable } from "@excalidraw/common/utility-types";
import { canChangeRoundness } from "./comparisons";
import { generateFreeDrawShape } from "./renderElement";
import { getArrowheadPoints, getDiamondPoints } from "./bounds";
import type {
ExcalidrawElement,
@ -21,13 +28,7 @@ import type {
ExcalidrawSelectionElement,
ExcalidrawLinearElement,
Arrowhead,
} from "@excalidraw/element/types";
import type { EmbedsValidationStatus } from "@excalidraw/excalidraw/types";
import type { ElementShapes } from "@excalidraw/excalidraw/scene/types";
import { canChangeRoundness } from "./comparisons";
import { generateFreeDrawShape } from "./renderElement";
} from "./types";
import type { Drawable, Options } from "roughjs/bin/core";
import type { RoughGenerator } from "roughjs/bin/generator";

View file

@ -2,11 +2,6 @@ import { RoughGenerator } from "roughjs/bin/generator";
import { COLOR_PALETTE } from "@excalidraw/common";
import type {
ExcalidrawElement,
ExcalidrawSelectionElement,
} from "@excalidraw/element/types";
import type {
AppState,
EmbedsValidationStatus,
@ -20,6 +15,8 @@ import { _generateElementShape } from "./Shape";
import { elementWithCanvasCache } from "./renderElement";
import type { ExcalidrawElement, ExcalidrawSelectionElement } from "./types";
import type { Drawable } from "roughjs/bin/core";
export class ShapeCache {

View file

@ -1,14 +1,13 @@
import { updateBoundElements } from "@excalidraw/element/binding";
import { getCommonBoundingBox } from "@excalidraw/element/bounds";
import { mutateElement } from "@excalidraw/element/mutateElement";
import { getMaximumGroups } from "@excalidraw/element/groups";
import type { BoundingBox } from "@excalidraw/element/bounds";
import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
import type Scene from "@excalidraw/excalidraw/scene/Scene";
import { updateBoundElements } from "./binding";
import { getCommonBoundingBox } from "./bounds";
import { mutateElement } from "./mutateElement";
import { getMaximumGroups } from "./groups";
import type { BoundingBox } from "./bounds";
import type { ElementsMap, ExcalidrawElement } from "./types";
export interface Alignment {
position: "start" | "center" | "end";
axis: "x" | "y";

View file

@ -24,12 +24,6 @@ import {
PRECISION,
} from "@excalidraw/math";
import {
aabbForElement,
getElementShape,
pointInsideBounds,
} from "@excalidraw/element";
import { isPointOnShape } from "@excalidraw/utils/collision";
import type { LocalPoint, Radians } from "@excalidraw/math";
@ -70,6 +64,8 @@ import {
isTextElement,
} from "./typeChecks";
import { aabbForElement, getElementShape, pointInsideBounds } from "./shapes";
import type { Bounds } from "./bounds";
import type { ElementUpdate } from "./mutateElement";
import type {

View file

@ -12,8 +12,6 @@ import {
} from "@excalidraw/math";
import { getCurvePathOps } from "@excalidraw/utils/geometry/shape";
import { generateRoughOptions } from "@excalidraw/element/Shape";
import { ShapeCache } from "@excalidraw/element/ShapeCache";
import type {
Degrees,
@ -27,6 +25,8 @@ import type { AppState } from "@excalidraw/excalidraw/types";
import type { Mutable } from "@excalidraw/common/utility-types";
import { ShapeCache } from "./ShapeCache";
import { generateRoughOptions } from "./Shape";
import { LinearElementEditor } from "./linearElementEditor";
import { getBoundTextElement, getContainerElement } from "./textElement";
import {

View file

@ -18,8 +18,6 @@ import {
import { isPointInShape, isPointOnShape } from "@excalidraw/utils/collision";
import { getPolygonShape } from "@excalidraw/utils/geometry/shape";
import { getBoundTextShape, isPathALoop } from "@excalidraw/element/shapes";
import type {
GlobalPoint,
LineSegment,
@ -32,6 +30,7 @@ import type { GeometricShape } from "@excalidraw/utils/geometry/shape";
import type { FrameNameBounds } from "@excalidraw/excalidraw/types";
import { getBoundTextShape, isPathALoop } from "./shapes";
import { getElementBounds } from "./bounds";
import {
hasBoundTextElement,

View file

@ -1,9 +1,9 @@
import { getCommonBoundingBox } from "@excalidraw/element/bounds";
import { newElementWith } from "@excalidraw/element/mutateElement";
import { getCommonBoundingBox } from "./bounds";
import { newElementWith } from "./mutateElement";
import { getMaximumGroups } from "@excalidraw/element/groups";
import { getMaximumGroups } from "./groups";
import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
import type { ElementsMap, ExcalidrawElement } from "./types";
export interface Distribution {
space: "between";

View file

@ -21,8 +21,6 @@ import {
getSizeFromPoints,
} from "@excalidraw/common";
import { aabbForElement, pointInsideBounds } from "@excalidraw/element";
import type { AppState } from "@excalidraw/excalidraw/types";
import {
@ -54,6 +52,8 @@ import {
type SceneElementsMap,
} from "./types";
import { aabbForElement, pointInsideBounds } from "./shapes";
import type { Bounds } from "./bounds";
import type { Heading } from "./heading";
import type {

View file

@ -5,10 +5,11 @@
import { ELEMENT_LINK_KEY, normalizeLink } from "@excalidraw/common";
import type { AppProps, AppState } from "@excalidraw/excalidraw/types";
import type { ExcalidrawElement } from "@excalidraw/element/types";
import { elementsAreInSameGroup } from "./groups";
import type { ExcalidrawElement } from "./types";
export const defaultGetElementLinkFromSelection: Exclude<
AppProps["generateLinkForSelection"],
undefined

View file

@ -1,9 +1,4 @@
import {
elementOverlapsWithFrame,
elementsAreInFrameBounds,
} from "@excalidraw/element";
import { KEYS, invariant, toBrandedType } from "@excalidraw/common";
import { aabbForElement } from "@excalidraw/element";
import { pointFrom, type LocalPoint } from "@excalidraw/math";
@ -26,6 +21,8 @@ import {
import { LinearElementEditor } from "./linearElementEditor";
import { mutateElement } from "./mutateElement";
import { newArrowElement, newElement } from "./newElement";
import { aabbForElement } from "./shapes";
import { elementsAreInFrameBounds, elementOverlapsWithFrame } from "./frame";
import {
isBindableElement,
isElbowArrow,

View file

@ -2,15 +2,15 @@ import { generateNKeysBetween } from "fractional-indexing";
import { arrayToMap } from "@excalidraw/common";
import { mutateElement } from "@excalidraw/element/mutateElement";
import { getBoundTextElement } from "@excalidraw/element/textElement";
import { hasBoundTextElement } from "@excalidraw/element/typeChecks";
import { mutateElement } from "./mutateElement";
import { getBoundTextElement } from "./textElement";
import { hasBoundTextElement } from "./typeChecks";
import type {
ExcalidrawElement,
FractionalIndex,
OrderedExcalidrawElement,
} from "@excalidraw/element/types";
} from "./types";
export class InvalidFractionalIndexError extends Error {
public code = "ELEMENT_HAS_INVALID_INDEX" as const;

View file

@ -5,17 +5,6 @@ import {
elementsOverlappingBBox,
} from "@excalidraw/utils";
import { getElementAbsoluteCoords, isTextElement } from "@excalidraw/element";
import type {
ElementsMap,
ElementsMapOrArray,
ExcalidrawElement,
ExcalidrawFrameLikeElement,
NonDeleted,
NonDeletedExcalidrawElement,
} from "@excalidraw/element/types";
import type { ExcalidrawElementsIncludingDeleted } from "@excalidraw/excalidraw/scene/Scene";
import type {
@ -29,10 +18,27 @@ import type { ReadonlySetLike } from "@excalidraw/common/utility-types";
import { getElementsWithinSelection, getSelectedElements } from "./selection";
import { getElementsInGroup, selectGroupsFromGivenElements } from "./groups";
import { getElementLineSegments, getCommonBounds } from "./bounds";
import {
getElementLineSegments,
getCommonBounds,
getElementAbsoluteCoords,
} from "./bounds";
import { mutateElement } from "./mutateElement";
import { getBoundTextElement, getContainerElement } from "./textElement";
import { isFrameElement, isFrameLikeElement } from "./typeChecks";
import {
isFrameElement,
isFrameLikeElement,
isTextElement,
} from "./typeChecks";
import type {
ElementsMap,
ElementsMapOrArray,
ExcalidrawElement,
ExcalidrawFrameLikeElement,
NonDeleted,
NonDeletedExcalidrawElement,
} from "./types";
// --------------------------- Frame State ------------------------------------
export const bindElementsToFramesAfterDuplication = (

View file

@ -1,4 +1,13 @@
import { getBoundTextElement } from "@excalidraw/element/textElement";
import type {
AppClassProperties,
AppState,
InteractiveCanvasAppState,
} from "@excalidraw/excalidraw/types";
import type { Mutable } from "@excalidraw/common/utility-types";
import { getBoundTextElement } from "./textElement";
import { makeNextSelectedElementIds, getSelectedElements } from "./selection";
import type {
GroupId,
@ -7,16 +16,7 @@ import type {
NonDeletedExcalidrawElement,
ElementsMapOrArray,
ElementsMap,
} from "@excalidraw/element/types";
import type {
AppClassProperties,
AppState,
InteractiveCanvasAppState,
} from "@excalidraw/excalidraw/types";
import type { Mutable } from "@excalidraw/common/utility-types";
import { makeNextSelectedElementIds, getSelectedElements } from "./selection";
} from "./types";
export const selectGroup = (
groupId: GroupId,

View file

@ -7,20 +7,6 @@ import type {
NonDeleted,
} from "./types";
export * from "./bounds";
export * from "./dragElements";
export * from "./frame";
export * from "./mutateElement";
export * from "./newElement";
export * from "./resizeElements";
export * from "./resizeTest";
export * from "./shapes";
export * from "./showSelectedShapeActions";
export * from "./textElement";
export * from "./typeChecks";
export * from "./transformHandles";
export * from "./sizeHelpers";
/**
* @deprecated unsafe, use hashElementsVersion instead
*/

View file

@ -20,14 +20,6 @@ import {
tupleToCoors,
} from "@excalidraw/common";
import {
getBezierCurveLength,
getBezierXY,
getControlPointsForBezierCurve,
isPathALoop,
mapIntervalToBezierT,
} from "@excalidraw/element";
import type { Store } from "@excalidraw/excalidraw/store";
import type { Radians } from "@excalidraw/math";
@ -50,7 +42,11 @@ import {
getHoveredElementForBinding,
isBindingEnabled,
} from "./binding";
import { getElementPointsCoords, getMinMaxXYFromCurvePathOps } from "./bounds";
import {
getElementAbsoluteCoords,
getElementPointsCoords,
getMinMaxXYFromCurvePathOps,
} from "./bounds";
import { headingIsHorizontal, vectorToHeading } from "./heading";
import { mutateElement } from "./mutateElement";
import { getBoundTextElement, handleBindTextResize } from "./textElement";
@ -62,7 +58,15 @@ import {
import { ShapeCache } from "./ShapeCache";
import { getElementAbsoluteCoords, getLockedLinearCursorAlignSize } from "./";
import {
isPathALoop,
getBezierCurveLength,
getControlPointsForBezierCurve,
mapIntervalToBezierT,
getBezierXY,
} from "./shapes";
import { getLockedLinearCursorAlignSize } from "./sizeHelpers";
import type { Bounds } from "./bounds";
import type {

View file

@ -25,15 +25,16 @@ import type {
Mutable,
} from "@excalidraw/common/utility-types";
import { getResizedElementAbsoluteCoords } from "./bounds";
import {
getElementAbsoluteCoords,
getResizedElementAbsoluteCoords,
} from "./bounds";
import { bumpVersion, newElementWith } from "./mutateElement";
import { getBoundTextMaxWidth } from "./textElement";
import { normalizeText, measureText } from "./textMeasurements";
import { wrapText } from "./textWrapping";
import { getNewGroupIdsForDuplication } from "./groups";
import { getElementAbsoluteCoords } from ".";
import type {
ExcalidrawElement,
ExcalidrawImageElement,

View file

@ -15,41 +15,6 @@ import {
isRTL,
getVerticalOffset,
} from "@excalidraw/common";
import { getElementAbsoluteCoords } from "@excalidraw/element/bounds";
import { getUncroppedImageElement } from "@excalidraw/element/cropElement";
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import {
getBoundTextElement,
getContainerCoords,
getContainerElement,
getBoundTextMaxHeight,
getBoundTextMaxWidth,
} from "@excalidraw/element/textElement";
import { getLineHeightInPx } from "@excalidraw/element/textMeasurements";
import {
isTextElement,
isLinearElement,
isFreeDrawElement,
isInitializedImageElement,
isArrowElement,
hasBoundTextElement,
isMagicFrameElement,
isImageElement,
} from "@excalidraw/element/typeChecks";
import { getContainingFrame } from "@excalidraw/element/frame";
import { getCornerRadius } from "@excalidraw/element/shapes";
import type {
ExcalidrawElement,
ExcalidrawTextElement,
NonDeletedExcalidrawElement,
ExcalidrawFreeDrawElement,
ExcalidrawImageElement,
ExcalidrawTextElementWithContainer,
ExcalidrawFrameLikeElement,
NonDeletedSceneElementsMap,
ElementsMap,
} from "@excalidraw/element/types";
import type {
AppState,
@ -67,8 +32,44 @@ import type {
InteractiveCanvasRenderConfig,
} from "@excalidraw/excalidraw/scene/types";
import { getElementAbsoluteCoords } from "./bounds";
import { getUncroppedImageElement } from "./cropElement";
import { LinearElementEditor } from "./linearElementEditor";
import {
getBoundTextElement,
getContainerCoords,
getContainerElement,
getBoundTextMaxHeight,
getBoundTextMaxWidth,
} from "./textElement";
import { getLineHeightInPx } from "./textMeasurements";
import {
isTextElement,
isLinearElement,
isFreeDrawElement,
isInitializedImageElement,
isArrowElement,
hasBoundTextElement,
isMagicFrameElement,
isImageElement,
} from "./typeChecks";
import { getContainingFrame } from "./frame";
import { getCornerRadius } from "./shapes";
import { ShapeCache } from "./ShapeCache";
import type {
ExcalidrawElement,
ExcalidrawTextElement,
NonDeletedExcalidrawElement,
ExcalidrawFreeDrawElement,
ExcalidrawImageElement,
ExcalidrawTextElementWithContainer,
ExcalidrawFrameLikeElement,
NonDeletedSceneElementsMap,
ElementsMap,
} from "./types";
import type { StrokeOptions } from "perfect-freehand";
import type { RoughCanvas } from "roughjs/bin/canvas";

View file

@ -1,12 +1,5 @@
import { isShallowEqual } from "@excalidraw/common";
import type {
ElementsMap,
ElementsMapOrArray,
ExcalidrawElement,
NonDeletedExcalidrawElement,
} from "@excalidraw/element/types";
import type {
AppState,
InteractiveCanvasAppState,
@ -21,6 +14,13 @@ import {
getFrameChildren,
} from "./frame";
import type {
ElementsMap,
ElementsMapOrArray,
ExcalidrawElement,
NonDeletedExcalidrawElement,
} from "./types";
/**
* Frames and their containing elements are not to be selected at the same time.
* Given an array of selected elements, if there are frames and their containing elements

View file

@ -32,9 +32,8 @@ import { LinearElementEditor } from "./linearElementEditor";
import { getBoundTextElement } from "./textElement";
import { ShapeCache } from "./ShapeCache";
import { getElementAbsoluteCoords } from "./";
import { getElementAbsoluteCoords, type Bounds } from "./bounds";
import type { Bounds } from "./bounds";
import type {
ElementsMap,
ExcalidrawElement,

View file

@ -21,9 +21,11 @@ import { LinearElementEditor } from "./linearElementEditor";
import { mutateElement } from "./mutateElement";
import { measureText } from "./textMeasurements";
import { wrapText } from "./textWrapping";
import { isBoundToContainer, isArrowElement } from "./typeChecks";
import { isTextElement } from "./";
import {
isBoundToContainer,
isArrowElement,
isTextElement,
} from "./typeChecks";
import type { MaybeTransformHandleType } from "./transformHandles";
import type {

View file

@ -1,22 +1,19 @@
import { isFrameLikeElement } from "@excalidraw/element/typeChecks";
import { arrayToMap, findIndex, findLastIndex } from "@excalidraw/common";
import { getElementsInGroup } from "@excalidraw/element/groups";
import { syncMovedIndices } from "@excalidraw/element/fractionalIndex";
import type {
ExcalidrawElement,
ExcalidrawFrameLikeElement,
} from "@excalidraw/element/types";
import type { AppState } from "@excalidraw/excalidraw/types";
import type Scene from "@excalidraw/excalidraw/scene/Scene";
import { isFrameLikeElement } from "./typeChecks";
import { getElementsInGroup } from "./groups";
import { syncMovedIndices } from "./fractionalIndex";
import { getSelectedElements } from "./selection";
import type { ExcalidrawElement, ExcalidrawFrameLikeElement } from "./types";
const isOfTargetFrame = (element: ExcalidrawElement, frameId: string) => {
return element.frameId === frameId || element.id === frameId;
};

View file

@ -3,13 +3,15 @@ import { KEYS, arrayToMap } from "@excalidraw/common";
import { pointFrom } from "@excalidraw/math";
import { actionWrapTextInContainer } from "@excalidraw/excalidraw/actions/actionBoundText";
import { getTransformHandles } from "@excalidraw/element/transformHandles";
import { Excalidraw, isLinearElement } from "@excalidraw/excalidraw";
import { API } from "@excalidraw/excalidraw/tests/helpers/api";
import { UI, Pointer, Keyboard } from "@excalidraw/excalidraw/tests/helpers/ui";
import { fireEvent, render } from "@excalidraw/excalidraw/tests/test-utils";
import { getTransformHandles } from "../src/transformHandles";
const { h } = window;
const mouse = new Pointer("mouse");

View file

@ -17,17 +17,17 @@ import {
render,
} from "@excalidraw/excalidraw/tests/test-utils";
import { bindLinearElement } from "@excalidraw/element/binding";
import type { LocalPoint } from "@excalidraw/math";
import { bindLinearElement } from "../src/binding";
import "../../utils/test-utils";
import type {
ExcalidrawArrowElement,
ExcalidrawBindableElement,
ExcalidrawElbowArrowElement,
} from "@excalidraw/element/types";
import "../../utils/test-utils";
} from "../src/types";
const { h } = window;

View file

@ -10,7 +10,7 @@ import {
render,
} from "@excalidraw/excalidraw/tests/test-utils";
import type { ExcalidrawElement } from "@excalidraw/element/types";
import type { ExcalidrawElement } from "../src/types";
const { h } = window;
const mouse = new Pointer("mouse");

View file

@ -1,10 +1,4 @@
import { pointFrom } from "@excalidraw/math";
import React from "react";
import { getElementPointsCoords } from "@excalidraw/element/bounds";
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import { resizeSingleElement } from "@excalidraw/element/resizeElements";
import { isLinearElement } from "@excalidraw/element/typeChecks";
import { Excalidraw } from "@excalidraw/excalidraw";
import {
@ -23,12 +17,17 @@ import {
import type { LocalPoint } from "@excalidraw/math";
import type { Bounds } from "@excalidraw/element/bounds";
import { isLinearElement } from "../src/typeChecks";
import { resizeSingleElement } from "../src/resizeElements";
import { LinearElementEditor } from "../src/linearElementEditor";
import { getElementPointsCoords } from "../src/bounds";
import type { Bounds } from "../src/bounds";
import type {
ExcalidrawElbowArrowElement,
ExcalidrawFreeDrawElement,
ExcalidrawLinearElement,
} from "@excalidraw/element/types";
} from "../src/types";
unmountComponent();

View file

@ -1,4 +1,4 @@
import { getLineHeight } from "@excalidraw/common/font-metadata";
import { getLineHeight } from "@excalidraw/common";
import { API } from "@excalidraw/excalidraw/tests/helpers/api";
import { FONT_FAMILY } from "@excalidraw/common";

View file

@ -1,5 +1,3 @@
import { selectGroupsForSelectedElements } from "@excalidraw/element/groups";
import { reseed } from "@excalidraw/common";
import {
@ -20,13 +18,15 @@ import {
unmountComponent,
} from "@excalidraw/excalidraw/tests/test-utils";
import type { AppState } from "@excalidraw/excalidraw/types";
import { selectGroupsForSelectedElements } from "../src/groups";
import type {
ExcalidrawElement,
ExcalidrawFrameElement,
ExcalidrawSelectionElement,
} from "@excalidraw/element/types";
import type { AppState } from "@excalidraw/excalidraw/types";
} from "../src/types";
unmountComponent();