From f472af04a975d0988f44b2fb3c7f5d1d3b2de121 Mon Sep 17 00:00:00 2001 From: barnabasmolnar Date: Tue, 2 Jun 2026 19:06:32 +0200 Subject: [PATCH] [WIP] Initial implem of fade animating elements. --- .../with-nextjs/src/excalidrawWrapper.tsx | 2 + .../components/ExampleApp.tsx | 60 +++++- .../with-script-in-browser/initialData.tsx | 48 +++-- packages/element/src/renderElement.ts | 33 +++- packages/excalidraw/components/App.tsx | 175 +++++++++++++++++- packages/excalidraw/index.tsx | 2 + packages/excalidraw/renderer/staticScene.ts | 16 +- packages/excalidraw/scene/types.ts | 4 + packages/excalidraw/types.ts | 10 + 9 files changed, 327 insertions(+), 23 deletions(-) diff --git a/examples/with-nextjs/src/excalidrawWrapper.tsx b/examples/with-nextjs/src/excalidrawWrapper.tsx index fab4df6512..0fbf62af0f 100644 --- a/examples/with-nextjs/src/excalidrawWrapper.tsx +++ b/examples/with-nextjs/src/excalidrawWrapper.tsx @@ -1,4 +1,5 @@ "use client"; + import * as excalidrawLib from "@excalidraw/excalidraw"; import { Excalidraw } from "@excalidraw/excalidraw"; @@ -13,6 +14,7 @@ const ExcalidrawWrapper: React.FC = () => { appTitle={"Excalidraw with Nextjs Example"} useCustom={(api: any, args?: any[]) => {}} excalidrawLib={excalidrawLib} + showFadeDemo={true} > diff --git a/examples/with-script-in-browser/components/ExampleApp.tsx b/examples/with-script-in-browser/components/ExampleApp.tsx index 294a11a58d..135dc74499 100644 --- a/examples/with-script-in-browser/components/ExampleApp.tsx +++ b/examples/with-script-in-browser/components/ExampleApp.tsx @@ -70,6 +70,7 @@ export interface AppProps { customArgs?: any[]; children: React.ReactNode; excalidrawLib: typeof TExcalidraw; + showFadeDemo?: boolean; } export default function ExampleApp({ @@ -78,6 +79,7 @@ export default function ExampleApp({ customArgs, children, excalidrawLib, + showFadeDemo = false, }: AppProps) { const { exportToCanvas, @@ -116,6 +118,8 @@ export default function ExampleApp({ {}, ); const [comment, setComment] = useState(null); + const [hideAllForFadeDemo, setHideAllForFadeDemo] = useState(showFadeDemo); + const [fadeDemoNextIndex, setFadeDemoNextIndex] = useState(0); const initialStatePromiseRef = useRef<{ promise: ResolvablePromise; @@ -178,7 +182,8 @@ export default function ExampleApp({ const newElement = cloneElement( Excalidraw, { - excalidrawAPI: (api: ExcalidrawImperativeAPI) => setExcalidrawAPI(api), + onExcalidrawAPI: (api: ExcalidrawImperativeAPI | null) => + setExcalidrawAPI(api), initialData: initialStatePromiseRef.current.promise, onChange: ( elements: NonDeletedExcalidrawElement[], @@ -208,6 +213,7 @@ export default function ExampleApp({ onPointerDown, onScrollChange: rerenderCommentIcons, validateEmbeddable: true, + resolveRenderOpacity: hideAllForFadeDemo ? () => 0 : undefined, }, <> {excalidrawAPI && ( @@ -664,6 +670,58 @@ export default function ExampleApp({ > Reset Scene + {showFadeDemo && ( + <> + + + + )}