tweak fade api a little bit

This commit is contained in:
barnabasmolnar
2026-06-03 19:15:52 +02:00
parent db73e30eae
commit d5aad6202d
3 changed files with 54 additions and 18 deletions
+31 -2
View File
@@ -843,7 +843,7 @@ class App extends React.Component<AppProps, AppState> {
clear: this.resetHistory,
},
scrollToContent: this.scrollToContent,
fadeElement: this.fadeElement,
fadeElements: this.fadeElements,
cancelFadeElement: this.cancelFadeElement,
clearElementOpacityOverrides: this.clearElementOpacityOverrides,
getSceneElements: this.getSceneElements,
@@ -4714,7 +4714,7 @@ class App extends React.Component<AppProps, AppState> {
},
);
public fadeElement = ({
private fadeElement = ({
id,
from,
to = 100,
@@ -4763,6 +4763,35 @@ class App extends React.Component<AppProps, AppState> {
this.syncFadeElementAnimations();
};
public fadeElements = ({
elements,
from,
to = 100,
duration = 250,
delay = 0,
stagger = 0,
}: {
elements: readonly (ExcalidrawElement | ExcalidrawElement["id"])[];
from?: number;
to?: number;
duration?: number;
delay?: number;
stagger?: number;
}) => {
const normalizedDelay = Math.max(delay, 0);
const normalizedStagger = Math.max(stagger, 0);
elements.forEach((element, index) => {
this.fadeElement({
id: typeof element === "string" ? element : element.id,
from,
to,
duration,
delay: normalizedDelay + index * normalizedStagger,
});
});
};
public cancelFadeElement = (id: string) => {
if (!this.elementFadeStates.delete(id)) {
return;
+1 -1
View File
@@ -967,7 +967,7 @@ export interface ExcalidrawImperativeAPI {
getFiles: () => InstanceType<typeof App>["files"];
getName: InstanceType<typeof App>["getName"];
scrollToContent: InstanceType<typeof App>["scrollToContent"];
fadeElement: InstanceType<typeof App>["fadeElement"];
fadeElements: InstanceType<typeof App>["fadeElements"];
cancelFadeElement: InstanceType<typeof App>["cancelFadeElement"];
clearElementOpacityOverrides: InstanceType<
typeof App