|
1 | 1 | import { isTransparent } from "@excalidraw/excalidraw/utils";
|
2 | 2 |
|
| 3 | +import { isLinearElement } from "@excalidraw/excalidraw"; |
| 4 | + |
3 | 5 | import type {
|
4 | 6 | ExcalidrawElement,
|
5 | 7 | ExcalidrawTextElement,
|
@@ -143,6 +145,31 @@ const progressAnimation = (
|
143 | 145 | // animate animatable properties
|
144 | 146 | const intermediate: any = {};
|
145 | 147 | 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 | + } |
146 | 173 | if (ANIMATABLE_PROPERTIES.has(key)) {
|
147 | 174 | intermediate[key] = ANIMATABLE_PROPERTIES.get(key)!(
|
148 | 175 | oldElement[key],
|
|
0 commit comments