refactor: separate elements logic into a standalone package (#9285)

This commit is contained in:
Marcel Mraz
2025-03-26 15:24:59 +01:00
committed by GitHub
parent a18f059188
commit 432a46ef9e
372 changed files with 3466 additions and 2466 deletions

View File

@@ -1,4 +1,4 @@
import { THEME, THEME_FILTER } from "../constants";
import { THEME, THEME_FILTER } from "@excalidraw/common";
import type { StaticCanvasRenderConfig } from "../scene/types";
import type { StaticCanvasAppState, AppState } from "../types";

View File

@@ -1,72 +1,66 @@
import oc from "open-color";
import {
pointFrom,
type GlobalPoint,
type LocalPoint,
type Radians,
} from "@excalidraw/math";
import oc from "open-color";
import { getClientColor, renderRemoteCursors } from "../clients";
import {
DEFAULT_TRANSFORM_HANDLE_SPACING,
FRAME_STYLE,
THEME,
} from "../constants";
import {
getElementAbsoluteCoords,
getTransformHandlesFromCoords,
getTransformHandles,
getCommonBounds,
} from "../element";
arrayToMap,
invariant,
throttleRAF,
} from "@excalidraw/common";
import {
BINDING_HIGHLIGHT_OFFSET,
BINDING_HIGHLIGHT_THICKNESS,
maxBindingGap,
} from "../element/binding";
import { LinearElementEditor } from "../element/linearElementEditor";
} from "@excalidraw/element/binding";
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import {
getOmitSidesForDevice,
getTransformHandles,
getTransformHandlesFromCoords,
shouldShowBoundingBox,
} from "../element/transformHandles";
} from "@excalidraw/element/transformHandles";
import {
isElbowArrow,
isFrameLikeElement,
isImageElement,
isLinearElement,
isTextElement,
} from "../element/typeChecks";
} from "@excalidraw/element/typeChecks";
import { getCornerRadius } from "@excalidraw/element/shapes";
import { renderSelectionElement } from "@excalidraw/element/renderElement";
import {
isSelectedViaGroup,
getSelectedGroupIds,
getElementsInGroup,
selectGroupsFromGivenElements,
} from "../groups";
import { renderSelectionElement } from "../renderer/renderElement";
import { renderSnaps } from "../renderer/renderSnaps";
import { roundRect } from "../renderer/roundRect";
import {
getScrollBars,
SCROLLBAR_COLOR,
SCROLLBAR_WIDTH,
} from "../scene/scrollbars";
import { getCornerRadius } from "../shapes";
import { type InteractiveCanvasAppState } from "../types";
import { arrayToMap, invariant, throttleRAF } from "../utils";
} from "@excalidraw/element/groups";
import {
bootstrapCanvas,
fillCircle,
getNormalizedCanvasDimensions,
} from "./helpers";
getCommonBounds,
getElementAbsoluteCoords,
} from "@excalidraw/element/bounds";
import type {
SuggestedBinding,
SuggestedPointBinding,
} from "../element/binding";
} from "@excalidraw/element/binding";
import type {
TransformHandles,
TransformHandleType,
} from "../element/transformHandles";
} from "@excalidraw/element/transformHandles";
import type {
ElementsMap,
ExcalidrawBindableElement,
@@ -77,7 +71,25 @@ import type {
ExcalidrawTextElement,
GroupId,
NonDeleted,
} from "../element/types";
} from "@excalidraw/element/types";
import { renderSnaps } from "../renderer/renderSnaps";
import { roundRect } from "../renderer/roundRect";
import {
getScrollBars,
SCROLLBAR_COLOR,
SCROLLBAR_WIDTH,
} from "../scene/scrollbars";
import { type InteractiveCanvasAppState } from "../types";
import { getClientColor, renderRemoteCursors } from "../clients";
import {
bootstrapCanvas,
fillCircle,
getNormalizedCanvasDimensions,
} from "./helpers";
import type {
InteractiveCanvasRenderConfig,
InteractiveSceneRenderConfig,

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,8 @@
import { throttleRAF } from "../utils";
import { throttleRAF } from "@excalidraw/common";
import { renderElement } from "@excalidraw/element/renderElement";
import { bootstrapCanvas, getNormalizedCanvasDimensions } from "./helpers";
import { renderElement } from "./renderElement";
import type { NewElementSceneRenderConfig } from "../scene/types";

View File

@@ -1,6 +1,6 @@
import { pointFrom, type GlobalPoint, type LocalPoint } from "@excalidraw/math";
import { THEME } from "../constants";
import { THEME } from "@excalidraw/common";
import type { PointSnapLine, PointerSnapLine } from "../snapping";
import type { InteractiveCanvasAppState } from "../types";

View File

@@ -1,33 +1,36 @@
import {
EXTERNAL_LINK_IMG,
ELEMENT_LINK_IMG,
getLinkHandleFromCoords,
} from "../components/hyperlink/helpers";
import { FRAME_STYLE } from "../constants";
import { getElementAbsoluteCoords } from "../element";
import { isElementLink } from "../element/elementLink";
import { createPlaceholderEmbeddableLabel } from "../element/embeddable";
import { getBoundTextElement } from "../element/textElement";
import { FRAME_STYLE, throttleRAF } from "@excalidraw/common";
import { isElementLink } from "@excalidraw/element/elementLink";
import { createPlaceholderEmbeddableLabel } from "@excalidraw/element/embeddable";
import { getBoundTextElement } from "@excalidraw/element/textElement";
import {
isEmbeddableElement,
isIframeLikeElement,
isTextElement,
} from "../element/typeChecks";
} from "@excalidraw/element/typeChecks";
import {
elementOverlapsWithFrame,
getTargetFrame,
shouldApplyFrameClip,
} from "../frame";
import { renderElement } from "../renderer/renderElement";
import { throttleRAF } from "../utils";
} from "@excalidraw/element/frame";
import { bootstrapCanvas, getNormalizedCanvasDimensions } from "./helpers";
import { renderElement } from "@excalidraw/element/renderElement";
import { getElementAbsoluteCoords } from "@excalidraw/element/bounds";
import type {
ElementsMap,
ExcalidrawFrameLikeElement,
NonDeletedExcalidrawElement,
} from "../element/types";
} from "@excalidraw/element/types";
import {
EXTERNAL_LINK_IMG,
ELEMENT_LINK_IMG,
getLinkHandleFromCoords,
} from "../components/hyperlink/helpers";
import { bootstrapCanvas, getNormalizedCanvasDimensions } from "./helpers";
import type {
StaticCanvasRenderConfig,
StaticSceneRenderConfig,

View File

@@ -3,39 +3,50 @@ import {
MAX_DECIMALS_FOR_SVG_EXPORT,
MIME_TYPES,
SVG_NS,
} from "../constants";
import { normalizeLink, toValidURL } from "../data/url";
import { getElementAbsoluteCoords, hashString } from "../element";
import { getUncroppedWidthAndHeight } from "../element/cropElement";
getFontFamilyString,
isRTL,
isTestEnv,
getVerticalOffset,
} from "@excalidraw/common";
import { normalizeLink, toValidURL } from "@excalidraw/common";
import { hashString } from "@excalidraw/element";
import { getUncroppedWidthAndHeight } from "@excalidraw/element/cropElement";
import {
createPlaceholderEmbeddableLabel,
getEmbedLink,
} from "../element/embeddable";
import { LinearElementEditor } from "../element/linearElementEditor";
} from "@excalidraw/element/embeddable";
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import {
getBoundTextElement,
getContainerElement,
} from "../element/textElement";
import { getLineHeightInPx } from "../element/textMeasurements";
} from "@excalidraw/element/textElement";
import { getLineHeightInPx } from "@excalidraw/element/textMeasurements";
import {
isArrowElement,
isIframeLikeElement,
isInitializedImageElement,
isTextElement,
} from "../element/typeChecks";
import { getVerticalOffset } from "../fonts";
import { getContainingFrame } from "../frame";
import { ShapeCache } from "../scene/ShapeCache";
import { getCornerRadius, isPathALoop } from "../shapes";
import { getFontFamilyString, isRTL, isTestEnv } from "../utils";
} from "@excalidraw/element/typeChecks";
import { getFreeDrawSvgPath, IMAGE_INVERT_FILTER } from "./renderElement";
import { getContainingFrame } from "@excalidraw/element/frame";
import { getCornerRadius, isPathALoop } from "@excalidraw/element/shapes";
import { ShapeCache } from "@excalidraw/element/ShapeCache";
import {
getFreeDrawSvgPath,
IMAGE_INVERT_FILTER,
} from "@excalidraw/element/renderElement";
import { getElementAbsoluteCoords } from "@excalidraw/element/bounds";
import type {
ExcalidrawElement,
ExcalidrawTextElementWithContainer,
NonDeletedExcalidrawElement,
} from "../element/types";
} from "@excalidraw/element/types";
import type { RenderableElementsMap, SVGRenderConfig } from "../scene/types";
import type { AppState, BinaryFiles } from "../types";
import type { Drawable } from "roughjs/bin/core";