Skip to content

Commit 0314539

Browse files
committed
Animate line points
1 parent 603408a commit 0314539

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

excalidraw-app/presentation/animation.ts

+27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { isTransparent } from "@excalidraw/excalidraw/utils";
22

3+
import { isLinearElement } from "@excalidraw/excalidraw";
4+
35
import type {
46
ExcalidrawElement,
57
ExcalidrawTextElement,
@@ -143,6 +145,31 @@ const progressAnimation = (
143145
// animate animatable properties
144146
const intermediate: any = {};
145147
for (const key of Object.keys(newElement) as Array<keyof ExcalidrawElement>) {
148+
// Line points special case
149+
if (isLinearElement(oldElement) && isLinearElement(newElement)) {
150+
const oldPoints = oldElement.points;
151+
const newPoints = newElement.points;
152+
const oldPointsFilled =
153+
oldPoints.length >= newPoints.length
154+
? oldPoints
155+
: oldPoints.concat(
156+
Array(newPoints.length - oldPoints.length).fill(
157+
oldPoints[oldPoints.length - 1],
158+
),
159+
);
160+
const newPointsFilled =
161+
newPoints.length >= oldPoints.length
162+
? newPoints
163+
: newPoints.concat(
164+
Array(oldPoints.length - newPoints.length).fill(
165+
newPoints[newPoints.length - 1],
166+
),
167+
);
168+
intermediate.points = oldPointsFilled.map((p, i) => [
169+
numericalProgress(p[0], newPointsFilled[i][0], progress),
170+
numericalProgress(p[1], newPointsFilled[i][1], progress),
171+
]);
172+
}
146173
if (ANIMATABLE_PROPERTIES.has(key)) {
147174
intermediate[key] = ANIMATABLE_PROPERTIES.get(key)!(
148175
oldElement[key],

0 commit comments

Comments
 (0)