@hilux/ngx-motion 1.1.2 → 2.0.1

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.
Files changed (33) hide show
  1. package/README.md +137 -57
  2. package/fesm2022/hilux-ngx-motion.mjs +2020 -0
  3. package/fesm2022/hilux-ngx-motion.mjs.map +1 -0
  4. package/package.json +35 -31
  5. package/types/hilux-ngx-motion.d.ts +782 -0
  6. package/ng-package.json +0 -7
  7. package/src/lib/components/motion-one-presence.component.ts +0 -116
  8. package/src/lib/constants/motion-defaults.constants.ts +0 -41
  9. package/src/lib/directives/motion-animate.directive.ts +0 -55
  10. package/src/lib/directives/motion-if.directive.ts +0 -138
  11. package/src/lib/directives/motion-one.directive.backup.ts +0 -1591
  12. package/src/lib/directives/motion-one.directive.ts +0 -1154
  13. package/src/lib/directives/motion-presence.directive.ts +0 -145
  14. package/src/lib/services/motion-animation-options.service.ts +0 -142
  15. package/src/lib/services/motion-animation.service.ts +0 -86
  16. package/src/lib/services/motion-browser-safe.ts +0 -64
  17. package/src/lib/services/motion-gesture.service.ts +0 -141
  18. package/src/lib/services/motion-inview.service.ts +0 -91
  19. package/src/lib/services/motion-one.service.ts +0 -424
  20. package/src/lib/services/motion-stagger.service.ts +0 -70
  21. package/src/lib/services/motion-timeline.service.ts +0 -182
  22. package/src/lib/types/motion-animation.types.ts +0 -46
  23. package/src/lib/utils/color.utils.ts +0 -54
  24. package/src/lib/utils/easing.utils.ts +0 -77
  25. package/src/lib/utils/index.ts +0 -7
  26. package/src/lib/utils/style-extraction.utils.ts +0 -70
  27. package/src/lib/utils/timing.utils.ts +0 -61
  28. package/src/lib/utils/transform.utils.ts +0 -112
  29. package/src/lib/utils/variant.utils.ts +0 -55
  30. package/src/public-api.ts +0 -21
  31. package/tsconfig.lib.json +0 -17
  32. package/tsconfig.lib.prod.json +0 -11
  33. package/tsconfig.spec.json +0 -15
package/ng-package.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3
- "dest": "../../dist/ngx-motion",
4
- "lib": {
5
- "entryFile": "src/public-api.ts"
6
- }
7
- }
@@ -1,116 +0,0 @@
1
- import { Component, Input, AfterContentInit, OnDestroy, ViewChild, ChangeDetectorRef, Inject, PLATFORM_ID } from '@angular/core';
2
- import { isPlatformBrowser, NgIf, NgComponentOutlet } from '@angular/common';
3
- import { MotionOneService } from '../services/motion-one.service';
4
- import { Router, NavigationStart, RouterOutlet, NavigationEnd, Event, NavigationCancel, NavigationError } from '@angular/router';
5
- import { Subscription, Subject } from 'rxjs';
6
- import { OnInit } from '@angular/core';
7
-
8
- @Component({
9
- selector: 'motion-one-presence',
10
- template: `
11
- <div class="router-container">
12
- <div *ngIf="previousComponent" class="router-component previous">
13
- <ng-container *ngComponentOutlet="previousComponent"></ng-container>
14
- </div>
15
- <div class="router-component current">
16
- <ng-content></ng-content>
17
- </div>
18
- </div>
19
- `,
20
- styles: [`
21
- .router-container {
22
- position: relative;
23
- width: 100%;
24
- height: 100%;
25
- }
26
- .router-component {
27
- position: absolute;
28
- width: 100%;
29
- height: 100%;
30
- top: 0;
31
- left: 0;
32
- }
33
- .previous {
34
- z-index: 1;
35
- }
36
- .current {
37
- z-index: 2;
38
- }
39
- .debug-indicator {
40
- position: absolute;
41
- top: 10px;
42
- right: 10px;
43
- background: rgba(0,0,0,0.7);
44
- color: white;
45
- padding: 5px 10px;
46
- border-radius: 4px;
47
- font-size: 12px;
48
- z-index: 1000;
49
- }
50
- .previous-indicator {
51
- background: rgba(255,0,0,0.7);
52
- }
53
- .current-indicator {
54
- background: rgba(0,128,0,0.7);
55
- }
56
- `],
57
- standalone: true,
58
- providers: [MotionOneService],
59
- imports: [NgIf, NgComponentOutlet]
60
- })
61
- export class MotionOnePresenceComponent implements OnInit, OnDestroy {
62
- @Input() mode: 'sync' | 'wait' = 'wait';
63
-
64
- @ViewChild(RouterOutlet) routerOutlet?: RouterOutlet;
65
-
66
- previousComponent: any = null;
67
- currentComponent: any = null;
68
- private routerSubscription = new Subscription();
69
- private destroy$ = new Subject<void>();
70
- private previousRoute: string | null = null;
71
- private currentRoute: string | null = null;
72
- private exitDuration: number = 0;
73
- private isAnimating: boolean = false;
74
-
75
- constructor(
76
- private router: Router,
77
- private motionService: MotionOneService,
78
- private cdr: ChangeDetectorRef,
79
- @Inject(PLATFORM_ID) private platformId: Object
80
- ) {
81
-
82
- }
83
-
84
- ngOnInit(): void {
85
- // Listen for router events
86
- this.routerSubscription = this.router.events.subscribe((event: Event) => {
87
- if (event instanceof NavigationStart) {
88
-
89
-
90
-
91
- this.previousRoute = this.router.url;
92
- this.currentRoute = (event as NavigationStart).url;
93
-
94
- console.log(`ACI [MotionOnePresence] Navigation from ${this.previousRoute} to ${this.currentRoute}`);
95
-
96
- this.motionService.runAllExitAnimations();
97
- }
98
-
99
- if (event instanceof NavigationEnd) {
100
-
101
- this.currentRoute = event.urlAfterRedirects;
102
- console.log('ACI [MotionOnePresence] Navigation to:', this.currentRoute);
103
-
104
- // this.motionService.runAllEnterAnimations();
105
-
106
- }
107
- });
108
- }
109
-
110
-
111
- ngOnDestroy() {
112
- this.destroy$.next();
113
- this.destroy$.complete();
114
- this.routerSubscription.unsubscribe();
115
- }
116
- }
@@ -1,41 +0,0 @@
1
- /**
2
- * Default values for Motion One animations
3
- */
4
-
5
- export const MOTION_DEFAULTS = {
6
- DURATION: 0.3,
7
- DELAY: 0,
8
- EXIT_DELAY: 0,
9
- DELAY_CHILDREN: 0,
10
- EASING: 'ease',
11
- OFFSET: '0px',
12
- STAGGER_CHILDREN: 1,
13
- STAGGER_DIRECTION: 1,
14
- REPEAT: false,
15
- INVIEW_THRESHOLD: 0.1,
16
- INVIEW_DELAY: 50,
17
- INVIEW_MARGIN: '0px',
18
- INVIEW_ROOT_MARGIN: '0px',
19
- RESET_TIMEOUT: 10,
20
- STAGGER_TIMEOUT: 50,
21
- } as const;
22
-
23
- /**
24
- * Transform properties that need special handling
25
- */
26
- export const TRANSFORM_PROPERTIES = ['x', 'y', 'rotate', 'scale', 'scaleX', 'scaleY'] as const;
27
-
28
- /**
29
- * Color properties that need normalization
30
- */
31
- export const COLOR_PROPERTIES = ['backgroundColor', 'color', 'borderColor'] as const;
32
-
33
- /**
34
- * Properties that should be excluded from style extraction
35
- */
36
- export const EXCLUDED_PROPERTIES = ['transition', 'at'] as const;
37
-
38
- /**
39
- * Identity matrix for transform operations
40
- */
41
- export const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0] as const;
@@ -1,55 +0,0 @@
1
- import {
2
- Directive,
3
- Input,
4
- TemplateRef,
5
- ViewContainerRef,
6
- EmbeddedViewRef,
7
- effect,
8
- signal,
9
- DestroyRef,
10
- inject,
11
- Injector,
12
- afterNextRender
13
- } from '@angular/core';
14
-
15
- /**
16
- * Directive that integrates with Angular's control flow to provide
17
- * enter/exit animations. Works with @if, @for, and other control flow.
18
- *
19
- * Usage:
20
- * ```html
21
- * @if (show) {
22
- * <div motionAnimate [animateEnter]="enterAnimation" [animateLeave]="leaveAnimation">
23
- * Content
24
- * </div>
25
- * }
26
- * ```
27
- */
28
- @Directive({
29
- selector: '[motionAnimate]',
30
- standalone: true
31
- })
32
- export class MotionAnimateDirective {
33
- @Input() animateEnter?: () => void;
34
- @Input() animateLeave?: () => Promise<void>;
35
- @Input() animateDuration = 300;
36
-
37
- private destroyRef = inject(DestroyRef);
38
- private injector = inject(Injector);
39
-
40
- constructor() {
41
- // Trigger enter animation after render
42
- afterNextRender(() => {
43
- if (this.animateEnter) {
44
- this.animateEnter();
45
- }
46
- }, { injector: this.injector });
47
-
48
- // Setup cleanup for exit animation
49
- this.destroyRef.onDestroy(async () => {
50
- if (this.animateLeave) {
51
- await this.animateLeave();
52
- }
53
- });
54
- }
55
- }
@@ -1,138 +0,0 @@
1
- import { Directive, Input, TemplateRef, ViewContainerRef, OnDestroy, EmbeddedViewRef, ChangeDetectorRef } from '@angular/core';
2
- import { MotionOneDirective } from './motion-one.directive';
3
-
4
- /**
5
- * Structural directive for animated presence with proper enter/exit lifecycle.
6
- * Works with the existing motionone directive's animate and exit properties.
7
- *
8
- * Usage:
9
- * ```html
10
- * <div *motionIf="isVisible">
11
- * <div motionone
12
- * [initial]="{ opacity: 0, scale: 0.8 }"
13
- * [animate]="{ opacity: 1, scale: 1 }"
14
- * [exit]="{ opacity: 0, scale: 0.8 }">
15
- * Content that animates in and out
16
- * </div>
17
- * </div>
18
- * ```
19
- */
20
- @Directive({
21
- selector: '[motionIf]',
22
- standalone: true
23
- })
24
- export class MotionIfDirective implements OnDestroy {
25
- private hasView = false;
26
- private currentView: EmbeddedViewRef<any> | null = null;
27
- private motionDirectives: MotionOneDirective[] = [];
28
- private exitTimeout: any;
29
-
30
- constructor(
31
- private templateRef: TemplateRef<any>,
32
- private viewContainer: ViewContainerRef,
33
- private cdr: ChangeDetectorRef
34
- ) {}
35
-
36
- @Input() set motionIf(condition: boolean) {
37
- if (condition && !this.hasView) {
38
- this.enter();
39
- } else if (!condition && this.hasView) {
40
- this.exit();
41
- }
42
- }
43
-
44
- private enter() {
45
- // Create the view
46
- this.currentView = this.viewContainer.createEmbeddedView(this.templateRef);
47
- this.hasView = true;
48
- this.cdr.detectChanges();
49
-
50
- // Find all motion directives in the created view
51
- setTimeout(() => {
52
- this.motionDirectives = this.findMotionDirectives(this.currentView);
53
-
54
- // Trigger enter animations
55
- this.motionDirectives.forEach(directive => {
56
- if (directive.runInitAnimation) {
57
- directive.runInitAnimation();
58
- }
59
- });
60
- }, 0);
61
- }
62
-
63
- private exit() {
64
- if (!this.hasView || !this.currentView) return;
65
-
66
- // Find all motion directives that have exit animations
67
- const directivesWithExit = this.motionDirectives.filter(
68
- directive => directive.exit && Object.keys(directive.exit).length > 0
69
- );
70
-
71
- if (directivesWithExit.length > 0) {
72
- // Run all exit animations
73
- const exitPromises = directivesWithExit.map(directive =>
74
- directive.runExitAnimation()
75
- );
76
-
77
- // Get the longest duration
78
- const maxDuration = Math.max(
79
- ...directivesWithExit.map(d => d.getDuration()),
80
- 300
81
- );
82
-
83
- // Clear any existing timeout
84
- if (this.exitTimeout) {
85
- clearTimeout(this.exitTimeout);
86
- }
87
-
88
- // Remove the view after all animations complete
89
- this.exitTimeout = setTimeout(() => {
90
- this.clearView();
91
- }, maxDuration);
92
- } else {
93
- // No exit animation, remove immediately
94
- this.clearView();
95
- }
96
- }
97
-
98
- private clearView() {
99
- if (this.hasView) {
100
- this.viewContainer.clear();
101
- this.hasView = false;
102
- this.currentView = null;
103
- this.motionDirectives = [];
104
- }
105
- }
106
-
107
- private findMotionDirectives(view: EmbeddedViewRef<any> | null): MotionOneDirective[] {
108
- if (!view) return [];
109
-
110
- const directives: MotionOneDirective[] = [];
111
-
112
- view.rootNodes.forEach((node: any) => {
113
- // Check if root node has motion directive
114
- if (node?._motionDirective) {
115
- directives.push(node._motionDirective);
116
- }
117
-
118
- // Search children recursively
119
- if (node?.querySelectorAll) {
120
- const elements = node.querySelectorAll('[motionone]');
121
- elements.forEach((el: any) => {
122
- if (el._motionDirective) {
123
- directives.push(el._motionDirective);
124
- }
125
- });
126
- }
127
- });
128
-
129
- return directives;
130
- }
131
-
132
- ngOnDestroy() {
133
- if (this.exitTimeout) {
134
- clearTimeout(this.exitTimeout);
135
- }
136
- this.clearView();
137
- }
138
- }