fix: add frame clipping to new element canvas

This commit is contained in:
Ryan Di 2025-07-28 15:12:30 +10:00
parent 37ad85cbaf
commit d2d80602e9
2 changed files with 30 additions and 2 deletions

View File

@ -1,9 +1,16 @@
import { throttleRAF } from "@excalidraw/common";
import { isInvisiblySmallElement, renderElement } from "@excalidraw/element";
import {
getTargetFrame,
isInvisiblySmallElement,
renderElement,
shouldApplyFrameClip,
} from "@excalidraw/element";
import { bootstrapCanvas, getNormalizedCanvasDimensions } from "./helpers";
import { frameClip } from "./staticScene";
import type { NewElementSceneRenderConfig } from "../scene/types";
const _renderNewElementScene = ({
@ -42,6 +49,25 @@ const _renderNewElementScene = ({
return;
}
const frameId = newElement.frameId || appState.frameToHighlight?.id;
context.save();
if (
frameId &&
appState.frameRendering.enabled &&
appState.frameRendering.clip
) {
const frame = getTargetFrame(newElement, elementsMap, appState);
if (
frame &&
shouldApplyFrameClip(newElement, frame, appState, elementsMap)
) {
frameClip(frame, context, renderConfig, appState);
}
}
renderElement(
newElement,
elementsMap,
@ -51,6 +77,8 @@ const _renderNewElementScene = ({
renderConfig,
appState,
);
context.restore();
} else {
context.clearRect(0, 0, normalizedWidth, normalizedHeight);
}

View File

@ -113,7 +113,7 @@ const strokeGrid = (
context.restore();
};
const frameClip = (
export const frameClip = (
frame: ExcalidrawFrameLikeElement,
context: CanvasRenderingContext2D,
renderConfig: StaticCanvasRenderConfig,