@hilux/ngx-motion 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/lib/ngx-motion.directive.ts +43 -16
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
OnDestroy,
|
|
6
6
|
Output,
|
|
7
7
|
EventEmitter,
|
|
8
|
+
AfterViewInit,
|
|
8
9
|
} from "@angular/core";
|
|
9
10
|
import {
|
|
10
11
|
AnimationBuilder,
|
|
@@ -18,12 +19,14 @@ import { MotionHostDirective} from "./ngx-motion-container.directive";
|
|
|
18
19
|
selector: "[motion]",
|
|
19
20
|
standalone: true,
|
|
20
21
|
})
|
|
21
|
-
export class MotionDirective implements OnDestroy {
|
|
22
|
+
export class MotionDirective implements OnDestroy, AfterViewInit {
|
|
22
23
|
@Input() initial: any = {};
|
|
23
24
|
@Input() animate: any = {};
|
|
24
25
|
@Input() exit: any = {};
|
|
25
26
|
@Input() duration = "0.3s";
|
|
26
27
|
@Input() easing = "ease";
|
|
28
|
+
@Input() onHover: any = {};
|
|
29
|
+
@Input() variant: string = '';
|
|
27
30
|
|
|
28
31
|
@Output() animationComplete = new EventEmitter<void>();
|
|
29
32
|
|
|
@@ -32,20 +35,16 @@ export class MotionDirective implements OnDestroy {
|
|
|
32
35
|
|
|
33
36
|
constructor(private builder: AnimationBuilder, private el: ElementRef) {}
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
this.runAnimation(this.
|
|
38
|
+
ngAfterViewInit() {
|
|
39
|
+
this.applyInitialStyles();
|
|
40
|
+
this.runAnimation(this.animate);
|
|
41
|
+
if (this.onHover) {
|
|
42
|
+
this.runAnimation(this.onHover);
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
ngOnDestroy() {
|
|
44
|
-
|
|
45
|
-
this.runExitAnimation();
|
|
46
|
-
} else {
|
|
47
|
-
this.completeAnimation();
|
|
48
|
-
}
|
|
47
|
+
this.runExitAnimation();
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
registerPresence(presence: MotionHostDirective) {
|
|
@@ -53,15 +52,39 @@ export class MotionDirective implements OnDestroy {
|
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
runAnimation(styles: any) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
let animationMetadata = [];
|
|
56
|
+
|
|
57
|
+
switch (this.variant) {
|
|
58
|
+
case 'initial':
|
|
59
|
+
animationMetadata = [
|
|
60
|
+
style(this.initial),
|
|
61
|
+
animate(`${this.duration} ${this.easing}`, style(this.animate)),
|
|
62
|
+
];
|
|
63
|
+
break;
|
|
64
|
+
case 'animate':
|
|
65
|
+
animationMetadata = [
|
|
66
|
+
style(this.initial),
|
|
67
|
+
animate(`${this.duration} ${this.easing}`, style(this.animate)),
|
|
68
|
+
];
|
|
69
|
+
break;
|
|
70
|
+
case 'exit':
|
|
71
|
+
animationMetadata = [
|
|
72
|
+
style(this.animate),
|
|
73
|
+
animate(`${this.duration} ${this.easing}`, style(this.exit)),
|
|
74
|
+
];
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
animationMetadata = [
|
|
78
|
+
style(this.initial),
|
|
79
|
+
animate(`${this.duration} ${this.easing}`, style(this.animate)),
|
|
80
|
+
];
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
60
83
|
|
|
84
|
+
const animation = this.builder.build(animationMetadata);
|
|
61
85
|
if (this.player) {
|
|
62
86
|
this.player.destroy();
|
|
63
87
|
}
|
|
64
|
-
|
|
65
88
|
this.player = animation.create(this.el.nativeElement);
|
|
66
89
|
this.player.play();
|
|
67
90
|
}
|
|
@@ -95,4 +118,8 @@ export class MotionDirective implements OnDestroy {
|
|
|
95
118
|
getDuration(): number {
|
|
96
119
|
return parseFloat(this.duration) * 1000; // Convert to milliseconds
|
|
97
120
|
}
|
|
121
|
+
|
|
122
|
+
private applyInitialStyles() {
|
|
123
|
+
Object.assign(this.el.nativeElement.style, this.initial);
|
|
124
|
+
}
|
|
98
125
|
}
|