mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Moved ShapeCache in element
This commit is contained in:
parent
875450a0a1
commit
931d03d514
23 changed files with 84 additions and 54 deletions
3
packages/element/global.d.ts
vendored
3
packages/element/global.d.ts
vendored
|
@ -2,6 +2,9 @@ interface ImportMetaEnv {
|
|||
MODE: string;
|
||||
DEV: string;
|
||||
PROD: string;
|
||||
|
||||
// To enable bounding box for text containers
|
||||
VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX: string;
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { pointFrom, pointDistance, type LocalPoint } from "@excalidraw/math";
|
||||
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 {
|
||||
isElbowArrow,
|
||||
isEmbeddableElement,
|
||||
|
@ -12,8 +13,6 @@ import {
|
|||
isLinearElement,
|
||||
} from "@excalidraw/element/typeChecks";
|
||||
|
||||
import { getCornerRadius, isPathALoop } from "@excalidraw/element/shapes";
|
||||
|
||||
import type {
|
||||
ExcalidrawElement,
|
||||
NonDeletedExcalidrawElement,
|
||||
|
@ -22,12 +21,12 @@ import type {
|
|||
Arrowhead,
|
||||
} from "@excalidraw/element/types";
|
||||
|
||||
import { generateFreeDrawShape } from "../renderer/renderElement";
|
||||
import type { EmbedsValidationStatus } from "@excalidraw/excalidraw/types";
|
||||
import type { ElementShapes } from "@excalidraw/excalidraw/scene/types";
|
||||
|
||||
import { canChangeRoundness } from "./comparisons";
|
||||
import { generateFreeDrawShape } from "./renderElement";
|
||||
|
||||
import type { EmbedsValidationStatus } from "../types";
|
||||
import type { ElementShapes } from "./types";
|
||||
import type { Drawable, Options } from "roughjs/bin/core";
|
||||
import type { RoughGenerator } from "roughjs/bin/generator";
|
||||
import type { Point as RoughPoint } from "roughjs/bin/geometry";
|
|
@ -7,12 +7,19 @@ import type {
|
|||
ExcalidrawSelectionElement,
|
||||
} from "@excalidraw/element/types";
|
||||
|
||||
import { elementWithCanvasCache } from "../renderer/renderElement";
|
||||
import type {
|
||||
AppState,
|
||||
EmbedsValidationStatus,
|
||||
} from "@excalidraw/excalidraw/types";
|
||||
import type {
|
||||
ElementShape,
|
||||
ElementShapes,
|
||||
} from "@excalidraw/excalidraw/scene/types";
|
||||
|
||||
import { _generateElementShape } from "./Shape";
|
||||
|
||||
import type { AppState, EmbedsValidationStatus } from "../types";
|
||||
import type { ElementShape, ElementShapes } from "./types";
|
||||
import { elementWithCanvasCache } from "./renderElement";
|
||||
|
||||
import type { Drawable } from "roughjs/bin/core";
|
||||
|
||||
export class ShapeCache {
|
|
@ -12,8 +12,7 @@ import {
|
|||
} from "@excalidraw/math";
|
||||
|
||||
import { getCurvePathOps } from "@excalidraw/utils/geometry/shape";
|
||||
import { generateRoughOptions } from "@excalidraw/excalidraw/scene/Shape";
|
||||
import { ShapeCache } from "@excalidraw/excalidraw/scene/ShapeCache";
|
||||
import { generateRoughOptions } from "@excalidraw/element/Shape";
|
||||
|
||||
import type {
|
||||
Degrees,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import type { ElementOrToolType } from "../types";
|
||||
import type { ElementOrToolType } from "@excalidraw/excalidraw/types";
|
||||
|
||||
export const hasBackground = (type: ElementOrToolType) =>
|
||||
type === "rectangle" ||
|
|
@ -19,7 +19,6 @@ import {
|
|||
invariant,
|
||||
tupleToCoors,
|
||||
} from "@excalidraw/common";
|
||||
import { ShapeCache } from "@excalidraw/excalidraw/scene/ShapeCache";
|
||||
|
||||
import {
|
||||
getBezierCurveLength,
|
||||
|
@ -29,6 +28,8 @@ import {
|
|||
mapIntervalToBezierT,
|
||||
} from "@excalidraw/element";
|
||||
|
||||
import type { Store } from "@excalidraw/excalidraw/store";
|
||||
|
||||
import type { Radians } from "@excalidraw/math";
|
||||
|
||||
import type Scene from "@excalidraw/excalidraw/scene/Scene";
|
||||
|
@ -59,6 +60,8 @@ import {
|
|||
isFixedPointBinding,
|
||||
} from "./typeChecks";
|
||||
|
||||
import { ShapeCache } from "./ShapeCache";
|
||||
|
||||
import { getElementAbsoluteCoords, getLockedLinearCursorAlignSize } from "./";
|
||||
|
||||
import type { Bounds } from "./bounds";
|
||||
|
|
|
@ -10,7 +10,8 @@ import type { Radians } from "@excalidraw/math";
|
|||
import type { Mutable } from "@excalidraw/excalidraw/utility-types";
|
||||
|
||||
import Scene from "../scene/Scene";
|
||||
import { ShapeCache } from "../scene/ShapeCache";
|
||||
|
||||
import { ShapeCache } from "./ShapeCache";
|
||||
|
||||
import { updateElbowArrowPoints } from "./elbowArrow";
|
||||
import { isElbowArrow } from "./typeChecks";
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { isRightAngleRads } from "@excalidraw/math";
|
||||
import { getStroke } from "perfect-freehand";
|
||||
import rough from "roughjs/bin/rough";
|
||||
import { getStroke } from "perfect-freehand";
|
||||
|
||||
import { isRightAngleRads } from "@excalidraw/math";
|
||||
|
||||
import {
|
||||
BOUND_TEXT_PADDING,
|
||||
|
@ -37,6 +38,9 @@ import {
|
|||
import { getContainingFrame } from "@excalidraw/element/frame";
|
||||
import { getCornerRadius } from "@excalidraw/element/shapes";
|
||||
|
||||
// TODO: consider separating
|
||||
import { getVerticalOffset } from "@excalidraw/excalidraw/fonts/FontMetadata";
|
||||
|
||||
import type {
|
||||
ExcalidrawElement,
|
||||
ExcalidrawTextElement,
|
||||
|
@ -49,15 +53,6 @@ import type {
|
|||
ElementsMap,
|
||||
} from "@excalidraw/element/types";
|
||||
|
||||
import { getDefaultAppState } from "../appState";
|
||||
import { getVerticalOffset } from "../fonts/FontMetadata";
|
||||
import { ShapeCache } from "../scene/ShapeCache";
|
||||
|
||||
import type {
|
||||
StaticCanvasRenderConfig,
|
||||
RenderableElementsMap,
|
||||
InteractiveCanvasRenderConfig,
|
||||
} from "../scene/types";
|
||||
import type {
|
||||
AppState,
|
||||
StaticCanvasAppState,
|
||||
|
@ -65,7 +60,17 @@ import type {
|
|||
InteractiveCanvasAppState,
|
||||
ElementsPendingErasure,
|
||||
PendingExcalidrawElements,
|
||||
} from "../types";
|
||||
NormalizedZoomValue,
|
||||
} from "@excalidraw/excalidraw/types";
|
||||
|
||||
import type {
|
||||
StaticCanvasRenderConfig,
|
||||
RenderableElementsMap,
|
||||
InteractiveCanvasRenderConfig,
|
||||
} from "@excalidraw/excalidraw/scene/types";
|
||||
|
||||
import { ShapeCache } from "./ShapeCache";
|
||||
|
||||
import type { StrokeOptions } from "perfect-freehand";
|
||||
import type { RoughCanvas } from "roughjs/bin/canvas";
|
||||
|
||||
|
@ -76,8 +81,6 @@ import type { RoughCanvas } from "roughjs/bin/canvas";
|
|||
export const IMAGE_INVERT_FILTER =
|
||||
"invert(100%) hue-rotate(180deg) saturate(1.25)";
|
||||
|
||||
const defaultAppState = getDefaultAppState();
|
||||
|
||||
const isPendingImageElement = (
|
||||
element: ExcalidrawElement,
|
||||
renderConfig: StaticCanvasRenderConfig,
|
||||
|
@ -537,7 +540,11 @@ const generateElementWithCanvas = (
|
|||
renderConfig: StaticCanvasRenderConfig,
|
||||
appState: StaticCanvasAppState,
|
||||
) => {
|
||||
const zoom: Zoom = renderConfig ? appState.zoom : defaultAppState.zoom;
|
||||
const zoom: Zoom = renderConfig
|
||||
? appState.zoom
|
||||
: {
|
||||
value: 1 as NormalizedZoomValue,
|
||||
};
|
||||
const prevElementWithCanvas = elementWithCanvasCache.get(element);
|
||||
const shouldRegenerateBecauseZoom =
|
||||
prevElementWithCanvas &&
|
|
@ -30,7 +30,7 @@ import type { NormalizedZoomValue, Zoom } from "@excalidraw/excalidraw/types";
|
|||
import { shouldTestInside } from "./collision";
|
||||
import { LinearElementEditor } from "./linearElementEditor";
|
||||
import { getBoundTextElement } from "./textElement";
|
||||
import { ShapeCache } from "./scene/ShapeCache";
|
||||
import { ShapeCache } from "./ShapeCache";
|
||||
|
||||
import { getElementAbsoluteCoords } from "./";
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@ import {
|
|||
isUsingAdaptiveRadius,
|
||||
} from "@excalidraw/element/typeChecks";
|
||||
|
||||
import { hasStrokeColor } from "@excalidraw/element/comparisons";
|
||||
|
||||
import type { LocalPoint } from "@excalidraw/math";
|
||||
|
||||
import type {
|
||||
|
@ -128,7 +130,6 @@ import {
|
|||
getTargetElements,
|
||||
isSomeElementSelected,
|
||||
} from "../scene";
|
||||
import { hasStrokeColor } from "../scene/comparisons";
|
||||
import { CaptureUpdateAction } from "../store";
|
||||
|
||||
import { register } from "./register";
|
||||
|
|
|
@ -21,6 +21,8 @@ import {
|
|||
isTextElement,
|
||||
} from "@excalidraw/element/typeChecks";
|
||||
|
||||
import { hasStrokeColor, toolIsArrow } from "@excalidraw/element/comparisons";
|
||||
|
||||
import type {
|
||||
ExcalidrawElement,
|
||||
ExcalidrawElementType,
|
||||
|
@ -43,7 +45,6 @@ import {
|
|||
hasStrokeStyle,
|
||||
hasStrokeWidth,
|
||||
} from "../scene";
|
||||
import { hasStrokeColor, toolIsArrow } from "../scene/comparisons";
|
||||
|
||||
import { SHAPES } from "./shapes";
|
||||
|
||||
|
|
|
@ -270,6 +270,10 @@ import {
|
|||
getMinTextElementWidth,
|
||||
} from "@excalidraw/element/textMeasurements";
|
||||
|
||||
import { ShapeCache } from "@excalidraw/element/ShapeCache";
|
||||
|
||||
import { getRenderOpacity } from "@excalidraw/element/renderElement";
|
||||
|
||||
import type { LocalPoint, Radians } from "@excalidraw/math";
|
||||
|
||||
import type {
|
||||
|
@ -428,7 +432,6 @@ import {
|
|||
} from "../snapping";
|
||||
import { convertToExcalidrawElements } from "../data/transform";
|
||||
import { Renderer } from "../scene/Renderer";
|
||||
import { ShapeCache } from "../scene/ShapeCache";
|
||||
import {
|
||||
setEraserCursor,
|
||||
setCursor,
|
||||
|
@ -441,7 +444,6 @@ import { Store, CaptureUpdateAction } from "../store";
|
|||
import { AnimatedTrail } from "../animated-trail";
|
||||
import { LaserTrails } from "../laser-trails";
|
||||
import { withBatchedUpdates, withBatchedUpdatesThrottled } from "../reactUtils";
|
||||
import { getRenderOpacity } from "../renderer/renderElement";
|
||||
import { textWysiwyg } from "../wysiwyg/textWysiwyg";
|
||||
import { isOverScrollBars } from "../scene/scrollbars";
|
||||
import { syncInvalidIndices, syncMovedIndices } from "../fractionalIndex";
|
||||
|
|
|
@ -13,9 +13,10 @@ import { mutateElement } from "@excalidraw/element/mutateElement";
|
|||
|
||||
import { showSelectedShapeActions } from "@excalidraw/element";
|
||||
|
||||
import { ShapeCache } from "@excalidraw/element/ShapeCache";
|
||||
|
||||
import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types";
|
||||
|
||||
import { ShapeCache } from "../scene/ShapeCache";
|
||||
import Scene from "../scene/Scene";
|
||||
import { actionToggleStats } from "../actions";
|
||||
import { trackEvent } from "../analytics";
|
||||
|
|
|
@ -4,6 +4,8 @@ import { MIME_TYPES } from "@excalidraw/common";
|
|||
import { getElementAbsoluteCoords } from "@excalidraw/element/bounds";
|
||||
import { hitElementBoundingBox } from "@excalidraw/element/collision";
|
||||
|
||||
import { DEFAULT_LINK_SIZE } from "@excalidraw/element/renderElement";
|
||||
|
||||
import type { GlobalPoint, Radians } from "@excalidraw/math";
|
||||
|
||||
import type { Bounds } from "@excalidraw/element/bounds";
|
||||
|
@ -12,8 +14,6 @@ import type {
|
|||
NonDeletedExcalidrawElement,
|
||||
} from "@excalidraw/element/types";
|
||||
|
||||
import { DEFAULT_LINK_SIZE } from "../../renderer/renderElement";
|
||||
|
||||
import type { AppState, UIAppState } from "../../types";
|
||||
|
||||
export const EXTERNAL_LINK_IMG = document.createElement("img");
|
||||
|
|
|
@ -12,13 +12,13 @@ import { containsCJK } from "@excalidraw/element/textWrapping";
|
|||
|
||||
import { getFontString, PromisePool, promiseTry } from "@excalidraw/common";
|
||||
|
||||
import { ShapeCache } from "@excalidraw/element/ShapeCache";
|
||||
|
||||
import type {
|
||||
ExcalidrawElement,
|
||||
ExcalidrawTextElement,
|
||||
} from "@excalidraw/element/types";
|
||||
|
||||
import { ShapeCache } from "../scene/ShapeCache";
|
||||
|
||||
import { CascadiaFontFaces } from "./Cascadia";
|
||||
import { ComicShannsFontFaces } from "./ComicShanns";
|
||||
import { EmojiFontFaces } from "./Emoji";
|
||||
|
|
|
@ -242,7 +242,7 @@ export {
|
|||
loadSceneOrLibraryFromBlob,
|
||||
loadLibraryFromBlob,
|
||||
} from "./data/blob";
|
||||
export { getFreeDrawSvgPath } from "./renderer/renderElement";
|
||||
export { getFreeDrawSvgPath } from "@excalidraw/element/renderElement";
|
||||
export { mergeLibraryItems, getLibraryItemsHash } from "./data/library";
|
||||
export { isLinearElement } from "@excalidraw/element/typeChecks";
|
||||
|
||||
|
|
|
@ -40,6 +40,8 @@ import {
|
|||
|
||||
import { getCornerRadius } from "@excalidraw/element/shapes";
|
||||
|
||||
import { renderSelectionElement } from "@excalidraw/element/renderElement";
|
||||
|
||||
import type {
|
||||
SuggestedBinding,
|
||||
SuggestedPointBinding,
|
||||
|
@ -68,7 +70,6 @@ import {
|
|||
getElementsInGroup,
|
||||
selectGroupsFromGivenElements,
|
||||
} from "../groups";
|
||||
import { renderSelectionElement } from "../renderer/renderElement";
|
||||
import { renderSnaps } from "../renderer/renderSnaps";
|
||||
import { roundRect } from "../renderer/roundRect";
|
||||
import {
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
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";
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@ import {
|
|||
shouldApplyFrameClip,
|
||||
} from "@excalidraw/element/frame";
|
||||
|
||||
import { renderElement } from "@excalidraw/element/renderElement";
|
||||
|
||||
import type {
|
||||
ElementsMap,
|
||||
ExcalidrawFrameLikeElement,
|
||||
|
@ -25,7 +27,6 @@ import {
|
|||
ELEMENT_LINK_IMG,
|
||||
getLinkHandleFromCoords,
|
||||
} from "../components/hyperlink/helpers";
|
||||
import { renderElement } from "../renderer/renderElement";
|
||||
|
||||
import { bootstrapCanvas, getNormalizedCanvasDimensions } from "./helpers";
|
||||
|
||||
|
|
|
@ -31,6 +31,13 @@ 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 type {
|
||||
ExcalidrawElement,
|
||||
ExcalidrawTextElementWithContainer,
|
||||
|
@ -38,9 +45,6 @@ import type {
|
|||
} from "@excalidraw/element/types";
|
||||
|
||||
import { getVerticalOffset } from "../fonts/FontMetadata";
|
||||
import { ShapeCache } from "../scene/ShapeCache";
|
||||
|
||||
import { getFreeDrawSvgPath, IMAGE_INVERT_FILTER } from "./renderElement";
|
||||
|
||||
import type { RenderableElementsMap, SVGRenderConfig } from "../scene/types";
|
||||
import type { AppState, BinaryFiles } from "../types";
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
import throttle from "lodash.throttle";
|
||||
|
||||
import { ENV } from "@excalidraw/common";
|
||||
import {
|
||||
ENV,
|
||||
randomInteger,
|
||||
arrayToMap,
|
||||
toBrandedType,
|
||||
} from "@excalidraw/common";
|
||||
import { isNonDeletedElement } from "@excalidraw/element";
|
||||
import { isFrameLikeElement } from "@excalidraw/element/typeChecks";
|
||||
|
||||
import { randomInteger } from "@excalidraw/common";
|
||||
import { arrayToMap } from "@excalidraw/common";
|
||||
import { toBrandedType } from "@excalidraw/common";
|
||||
|
||||
import type { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
|
||||
import type {
|
||||
ExcalidrawElement,
|
||||
|
|
|
@ -12,7 +12,7 @@ export {
|
|||
hasStrokeStyle,
|
||||
canHaveArrowheads,
|
||||
canChangeRoundness,
|
||||
} from "./comparisons";
|
||||
} from "@excalidraw/element/comparisons";
|
||||
export {
|
||||
getNormalizedZoom,
|
||||
getNormalizedGridSize,
|
||||
|
|
2
packages/excalidraw/vite-env.d.ts
vendored
2
packages/excalidraw/vite-env.d.ts
vendored
|
@ -34,8 +34,6 @@ interface ImportMetaEnv {
|
|||
|
||||
//Debug flags
|
||||
|
||||
// To enable bounding box for text containers
|
||||
VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX: string;
|
||||
VITE_APP_DISABLE_SENTRY: string;
|
||||
// Set this flag to false if you want to open the overlay by default
|
||||
VITE_APP_COLLAPSE_OVERLAY: string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue