snapshot of https://github.com/excalidraw/excalidraw.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Tests / test (push) Failing after 15s
Some checks failed
Tests / test (push) Failing after 15s
This commit is contained in:
111
packages/excalidraw/renderer/renderNewElementScene.ts
Normal file
111
packages/excalidraw/renderer/renderNewElementScene.ts
Normal file
@@ -0,0 +1,111 @@
|
||||
import { throttleRAF } from "@excalidraw/common";
|
||||
|
||||
import {
|
||||
getTargetFrame,
|
||||
isInvisiblySmallElement,
|
||||
renderElement,
|
||||
shouldApplyFrameClip,
|
||||
} from "@excalidraw/element";
|
||||
|
||||
import {
|
||||
bootstrapCanvas,
|
||||
getNormalizedCanvasDimensions,
|
||||
snapScrollToDevicePixels,
|
||||
} from "./helpers";
|
||||
|
||||
import { frameClip } from "./staticScene";
|
||||
|
||||
import type { NewElementSceneRenderConfig } from "../scene/types";
|
||||
|
||||
const _renderNewElementScene = ({
|
||||
canvas,
|
||||
rc,
|
||||
newElement,
|
||||
elementsMap,
|
||||
allElementsMap,
|
||||
scale,
|
||||
appState: unsnappedAppState,
|
||||
renderConfig,
|
||||
}: NewElementSceneRenderConfig) => {
|
||||
if (canvas) {
|
||||
// the same whole-device-pixel scroll the static scene draws at
|
||||
const appState = snapScrollToDevicePixels(unsnappedAppState, scale);
|
||||
const [normalizedWidth, normalizedHeight] = getNormalizedCanvasDimensions(
|
||||
canvas,
|
||||
scale,
|
||||
);
|
||||
|
||||
const context = bootstrapCanvas({
|
||||
canvas,
|
||||
scale,
|
||||
normalizedWidth,
|
||||
normalizedHeight,
|
||||
});
|
||||
|
||||
context.save();
|
||||
|
||||
// Apply zoom
|
||||
context.scale(appState.zoom.value, appState.zoom.value);
|
||||
|
||||
if (newElement && newElement.type !== "selection") {
|
||||
// e.g. when creating arrows and we're still below the arrow drag distance
|
||||
// threshold
|
||||
// (for now we skip render only with elements while we're creating to be
|
||||
// safe)
|
||||
if (isInvisiblySmallElement(newElement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const frameId = newElement.frameId || appState.frameToHighlight?.id;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
const renderTargetElement = newElement;
|
||||
|
||||
renderElement(
|
||||
renderTargetElement,
|
||||
elementsMap,
|
||||
allElementsMap,
|
||||
rc,
|
||||
context,
|
||||
renderConfig,
|
||||
appState,
|
||||
);
|
||||
} else {
|
||||
context.clearRect(0, 0, normalizedWidth, normalizedHeight);
|
||||
}
|
||||
|
||||
context.restore();
|
||||
}
|
||||
};
|
||||
|
||||
export const renderNewElementSceneThrottled = throttleRAF(
|
||||
(config: NewElementSceneRenderConfig) => {
|
||||
_renderNewElementScene(config);
|
||||
},
|
||||
);
|
||||
|
||||
export const renderNewElementScene = (
|
||||
renderConfig: NewElementSceneRenderConfig,
|
||||
throttle?: boolean,
|
||||
) => {
|
||||
if (throttle) {
|
||||
renderNewElementSceneThrottled(renderConfig);
|
||||
return;
|
||||
}
|
||||
|
||||
_renderNewElementScene(renderConfig);
|
||||
};
|
||||
Reference in New Issue
Block a user