@@ -15,6 +15,8 @@ import {Coordinate} from './utils/coordinate.js';
1515export class LayerManager {
1616 /** The layer elements being dragged are appended to. */
1717 private dragLayer : SVGGElement | undefined ;
18+ /** The layer elements being animated are appended to. */
19+ private animationLayer : SVGGElement | undefined ;
1820 /** The layers elements not being dragged are appended to. */
1921 private layers = new Map < number , SVGGElement > ( ) ;
2022
@@ -26,6 +28,7 @@ export class LayerManager {
2628 // been appended yet.
2729 if ( injectionDiv ) {
2830 this . dragLayer = this . createDragLayer ( injectionDiv ) ;
31+ this . animationLayer = this . createAnimationLayer ( injectionDiv ) ;
2932 }
3033
3134 // We construct these manually so we can add the css class for backwards
@@ -48,6 +51,35 @@ export class LayerManager {
4851 return dom . createSvgElement ( Svg . G , { } , svg ) ;
4952 }
5053
54+ private createAnimationLayer ( injectionDiv : Element ) {
55+ const svg = dom . createSvgElement ( Svg . SVG , {
56+ 'class' : 'blocklyAnimationLayer' ,
57+ 'xmlns' : dom . SVG_NS ,
58+ 'xmlns:html' : dom . HTML_NS ,
59+ 'xmlns:xlink' : dom . XLINK_NS ,
60+ 'version' : '1.1' ,
61+ } ) ;
62+ injectionDiv . append ( svg ) ;
63+ return dom . createSvgElement ( Svg . G , { } , svg ) ;
64+ }
65+
66+ /**
67+ * Appends the element to the animation layer. The animation layer doesn't
68+ * move when the workspace moves, so e.g. delete animations don't move
69+ * when a block delete triggers a workspace resize.
70+ *
71+ * @internal
72+ */
73+ appendToAnimationLayer ( elem : IRenderedElement ) {
74+ const currentTransform = this . dragLayer ?. getAttribute ( 'transform' ) ;
75+ // Only update the current transform when appending, so animations don't
76+ // move if the workspace moves.
77+ if ( currentTransform ) {
78+ this . animationLayer ?. setAttribute ( 'transform' , currentTransform ) ;
79+ }
80+ this . animationLayer ?. appendChild ( elem . getSvgRoot ( ) ) ;
81+ }
82+
5183 /**
5284 * Translates layers when the workspace is dragged or zoomed.
5385 *
0 commit comments