| 41 | } |
| 42 | |
| 43 | override async apply(): Promise<void> { |
| 44 | const currentPosition = this.element.data('position'); |
| 45 | const position = (this._statement as string).match(/at\s(\S*)/); |
| 46 | |
| 47 | const oldClasses = [...this.element.get(0).classList]; |
| 48 | |
| 49 | for (const oldClass of oldClasses) { |
| 50 | if (oldClass !== currentPosition || position instanceof Array) { |
| 51 | this.element.removeClass(oldClass); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | if (position instanceof Array) { |
| 56 | // If it was, we'll set that position to the character |
| 57 | const [at, positionClass] = position; |
| 58 | this.element.data('position', positionClass); |
| 59 | } |
| 60 | |
| 61 | this.element.addClass('animated'); |
| 62 | |
| 63 | const durationPosition = this.classes.indexOf('duration'); |
| 64 | |
| 65 | if (durationPosition > -1) { |
| 66 | this.element.style('animation-duration', this.classes[durationPosition + 1]); |
| 67 | } else { |
| 68 | this.element.style('animation-duration', ''); |
| 69 | } |
| 70 | |
| 71 | if (this.classes.length > 0) { |
| 72 | for (const newClass of this.classes) { |
| 73 | this.element.addClass(newClass); |
| 74 | } |
| 75 | this.element.data('visibility', 'invisible'); |
| 76 | this.element.on('animationend', (e: any) => { |
| 77 | if (e.target.dataset.visibility === 'invisible') { |
| 78 | // Remove only if the animation ends while the element is not visible |
| 79 | e.target.remove(); |
| 80 | } |
| 81 | }); |
| 82 | } else { |
| 83 | this.element.remove(); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | override async didApply(): Promise<ActionApplyResult> { |
| 88 | const show = this.engine.state('images').filter((item: string) => { |