@hilux/ngx-motion 1.0.3 → 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 +36 -29
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,7 +19,7 @@ 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 = {};
|
|
@@ -34,23 +35,16 @@ export class MotionDirective implements OnDestroy {
|
|
|
34
35
|
|
|
35
36
|
constructor(private builder: AnimationBuilder, private el: ElementRef) {}
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
} else {
|
|
41
|
-
this.runAnimation(this.initial);
|
|
42
|
-
}
|
|
38
|
+
ngAfterViewInit() {
|
|
39
|
+
this.applyInitialStyles();
|
|
40
|
+
this.runAnimation(this.animate);
|
|
43
41
|
if (this.onHover) {
|
|
44
42
|
this.runAnimation(this.onHover);
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
ngOnDestroy() {
|
|
49
|
-
|
|
50
|
-
this.runExitAnimation();
|
|
51
|
-
} else {
|
|
52
|
-
this.completeAnimation();
|
|
53
|
-
}
|
|
47
|
+
this.runExitAnimation();
|
|
54
48
|
}
|
|
55
49
|
|
|
56
50
|
registerPresence(presence: MotionHostDirective) {
|
|
@@ -58,19 +52,39 @@ export class MotionDirective implements OnDestroy {
|
|
|
58
52
|
}
|
|
59
53
|
|
|
60
54
|
runAnimation(styles: any) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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;
|
|
68
82
|
}
|
|
69
83
|
|
|
84
|
+
const animation = this.builder.build(animationMetadata);
|
|
70
85
|
if (this.player) {
|
|
71
86
|
this.player.destroy();
|
|
72
87
|
}
|
|
73
|
-
|
|
74
88
|
this.player = animation.create(this.el.nativeElement);
|
|
75
89
|
this.player.play();
|
|
76
90
|
}
|
|
@@ -105,14 +119,7 @@ export class MotionDirective implements OnDestroy {
|
|
|
105
119
|
return parseFloat(this.duration) * 1000; // Convert to milliseconds
|
|
106
120
|
}
|
|
107
121
|
|
|
108
|
-
private
|
|
109
|
-
|
|
110
|
-
case 'fade':
|
|
111
|
-
return { opacity: 0 };
|
|
112
|
-
case 'scale':
|
|
113
|
-
return { transform: 'scale(1.2)' };
|
|
114
|
-
default:
|
|
115
|
-
return {};
|
|
116
|
-
}
|
|
122
|
+
private applyInitialStyles() {
|
|
123
|
+
Object.assign(this.el.nativeElement.style, this.initial);
|
|
117
124
|
}
|
|
118
125
|
}
|