@hilux/ngx-motion 1.0.15 → 1.1.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 (34) hide show
  1. package/README.md +385 -30
  2. package/ng-package.json +7 -0
  3. package/package.json +38 -51
  4. package/src/lib/components/motion-one-presence.component.ts +116 -0
  5. package/src/lib/constants/motion-defaults.constants.ts +41 -0
  6. package/src/lib/directives/motion-animate.directive.ts +55 -0
  7. package/src/lib/directives/motion-if.directive.ts +138 -0
  8. package/src/lib/directives/motion-one.directive.backup.ts +1591 -0
  9. package/src/lib/directives/motion-one.directive.ts +1154 -0
  10. package/src/lib/directives/motion-presence.directive.ts +145 -0
  11. package/src/lib/services/motion-animation-options.service.ts +142 -0
  12. package/src/lib/services/motion-animation.service.ts +86 -0
  13. package/src/lib/services/motion-browser-safe.ts +64 -0
  14. package/src/lib/services/motion-gesture.service.ts +141 -0
  15. package/src/lib/services/motion-inview.service.ts +91 -0
  16. package/src/lib/services/motion-one.service.ts +424 -0
  17. package/src/lib/services/motion-stagger.service.ts +70 -0
  18. package/src/lib/services/motion-timeline.service.ts +182 -0
  19. package/src/lib/types/motion-animation.types.ts +46 -0
  20. package/src/lib/utils/color.utils.ts +54 -0
  21. package/src/lib/utils/easing.utils.ts +77 -0
  22. package/src/lib/utils/index.ts +7 -0
  23. package/src/lib/utils/style-extraction.utils.ts +70 -0
  24. package/src/lib/utils/timing.utils.ts +61 -0
  25. package/src/lib/utils/transform.utils.ts +112 -0
  26. package/src/lib/utils/variant.utils.ts +55 -0
  27. package/src/public-api.ts +21 -0
  28. package/tsconfig.lib.json +17 -0
  29. package/tsconfig.lib.prod.json +11 -0
  30. package/tsconfig.spec.json +15 -0
  31. package/main.38a76835f287cd47.js +0 -1
  32. package/polyfills.d01a0142b6650731.js +0 -1
  33. package/runtime.aacc6cb1e6befba3.js +0 -1
  34. package/tailwind.config.js +0 -260
package/README.md CHANGED
@@ -1,59 +1,414 @@
1
- # ng motion poc
1
+ # @hilux/ngx-motion
2
2
 
3
- This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 19.2.5.
3
+ Angular directive for Motion One animations with Framer Motion-like API.
4
4
 
5
- ## Development server
6
-
7
- To start a local development server, run:
5
+ ## Installation
8
6
 
9
7
  ```bash
10
- ng serve
8
+ npm install ngx-motion motion
11
9
  ```
12
10
 
13
- Once the server is running, open your browser and navigate to `http://localhost:4200/`. The application will automatically reload whenever you modify any of the source files.
11
+ ## Usage
14
12
 
15
- ## Code scaffolding
13
+ Import the directive in your component:
16
14
 
17
- Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
15
+ ```typescript
16
+ import { MotionOneDirective } from '@hilux/ngx-motion';
18
17
 
19
- ```bash
20
- ng generate component component-name
18
+ @Component({
19
+ selector: 'app-example',
20
+ standalone: true,
21
+ imports: [MotionOneDirective],
22
+ template: `
23
+ <div
24
+ motionone
25
+ [initial]="{ opacity: 0, y: 50 }"
26
+ [animate]="{ opacity: 1, y: 0 }"
27
+ [transition]="{ duration: 0.5 }"
28
+ >
29
+ Animated content
30
+ </div>
31
+ `
32
+ })
33
+ export class ExampleComponent {}
21
34
  ```
22
35
 
23
- For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
36
+ ## Features
24
37
 
25
- ```bash
26
- ng generate --help
38
+ - ✅ **Motion One Integration**: Built on top of the performant Motion One animation library
39
+ - ✅ **Framer Motion API**: Familiar API for React developers
40
+ - ✅ **TypeScript Support**: Full type safety with TypeScript
41
+ - ✅ **Server-Side Rendering**: Compatible with Angular Universal
42
+ - ✅ **Stagger Animations**: Built-in support for staggered animations
43
+ - ✅ **Timeline Support**: Create complex sequential animations
44
+ - ✅ **Conditional Rendering**: `motionIf` directive for animated presence
45
+ - ✅ **Gesture Support**: whileHover, whileTap, whileFocus animations
46
+
47
+ ## API Reference
48
+
49
+ ### Animation State Inputs
50
+
51
+ | Input | Type | Default | Description |
52
+ |-------|------|---------|-------------|
53
+ | `initial` | `VariantWithTransition \| string` | `{}` | Initial animation state when element mounts |
54
+ | `animate` | `VariantWithTransition \| string` | `{}` | Target animation state to animate to |
55
+ | `exit` | `VariantWithTransition \| string` | `{}` | Animation state when element unmounts |
56
+ | `inView` | `VariantWithTransition` | `{}` | Animation state when element enters viewport |
57
+ | `whileHover` | `VariantWithTransition` | `{}` | Animation state while hovering over element |
58
+ | `whileTap` | `VariantWithTransition` | `{}` | Animation state while pressing/tapping element |
59
+ | `whileFocus` | `VariantWithTransition` | `{}` | Animation state while element is focused |
60
+ | `whileInView` | `VariantWithTransition` | `{}` | Animation state while element is in viewport |
61
+
62
+ ### Timing & Easing Inputs
63
+
64
+ | Input | Type | Default | Description |
65
+ |-------|------|---------|-------------|
66
+ | `duration` | `number` | `0.3` | Default animation duration in seconds |
67
+ | `delay` | `number` | `0` | Default delay before animation starts in seconds |
68
+ | `exitDelay` | `number` | `0` | Delay before exit animation starts in seconds |
69
+ | `easing` | `string \| number[] \| SpringConfig` | `'ease'` | Default easing function for animations |
70
+
71
+ ### Children Animation Inputs
72
+
73
+ | Input | Type | Default | Description |
74
+ |-------|------|---------|-------------|
75
+ | `delayChildren` | `number` | `0` | Delay before children animations start in seconds |
76
+ | `staggerChildren` | `number` | `1` | Time between each child animation start in seconds |
77
+ | `staggerDirection` | `number` | `1` | Direction of stagger (1 = forward, -1 = reverse) |
78
+
79
+ ### Advanced Inputs
80
+
81
+ | Input | Type | Default | Description |
82
+ |-------|------|---------|-------------|
83
+ | `variants` | `Record<string, VariantWithTransition>` | `{}` | Named animation variants for reusable states |
84
+ | `transition` | `TransitionOptions \| Record<string, TransitionOptions>` | `{}` | Transition configuration (overrides individual timing inputs) |
85
+ | `timeline` | `TimelineStep[]` | `undefined` | Sequential animation timeline for complex animations |
86
+ | `repeat` | `boolean` | `false` | Whether to repeat the animation infinitely |
87
+ | `offset` | `string` | `'0px'` | Intersection observer margin for inView detection |
88
+
89
+ ### Output Events
90
+
91
+ | Output | Type | Description |
92
+ |--------|------|-------------|
93
+ | `animationComplete` | `EventEmitter<void>` | Emitted when animation completes |
94
+
95
+ ## Type Definitions
96
+
97
+ ### VariantWithTransition
98
+ ```typescript
99
+ interface VariantWithTransition {
100
+ [key: string]: any;
101
+ transition?: TransitionOptions;
102
+ at?: number; // Delay in seconds before this variant triggers
103
+ }
27
104
  ```
28
105
 
29
- ## Building
106
+ ### TransitionOptions
107
+ ```typescript
108
+ interface TransitionOptions {
109
+ duration?: number;
110
+ delay?: number;
111
+ ease?: string | number[] | { type: 'spring'; stiffness?: number; damping?: number };
112
+ repeat?: number | boolean;
113
+ repeatType?: 'loop' | 'mirror' | 'reverse' | 'forwards' | 'pingPong';
114
+ repeatDelay?: number;
115
+ staggerChildren?: number;
116
+ staggerDirection?: number;
117
+ when?: 'beforeChildren' | 'afterChildren' | 'together';
118
+ delayChildren?: number;
119
+ times?: number[]; // Keyframe timing array (0-1)
120
+ }
121
+ ```
30
122
 
31
- To build the project run:
123
+ ### TimelineStep
124
+ ```typescript
125
+ interface TimelineStep {
126
+ prop: string; // CSS property to animate
127
+ keyframes?: any[] | any; // Keyframe values
128
+ to?: any; // End value
129
+ duration: number; // Duration in seconds
130
+ delay?: number; // Delay in seconds
131
+ ease?: string | number[] | SpringConfig;
132
+ atTime?: number; // Absolute start time relative to element start
133
+ times?: number[]; // Keyframe timing array (0-1)
134
+ repeat?: number | boolean;
135
+ repeatType?: 'loop' | 'mirror' | 'reverse' | 'forwards' | 'pingPong';
136
+ repeatDelay?: number;
137
+ }
138
+ ```
32
139
 
33
- ```bash
34
- ng build
140
+ ## Examples
141
+
142
+ ### Basic Animation
143
+ ```html
144
+ <div
145
+ motionone
146
+ [initial]="{ opacity: 0, scale: 0.8 }"
147
+ [animate]="{ opacity: 1, scale: 1 }"
148
+ [duration]="0.5"
149
+ [easing]="'ease-out'"
150
+ >
151
+ Fade and scale in
152
+ </div>
35
153
  ```
36
154
 
37
- This will compile your project and store the build artifacts in the `dist/` directory. By default, the production build optimizes your application for performance and speed.
155
+ ### Hover Interactions
156
+ ```html
157
+ <button
158
+ motionone
159
+ [initial]="{ scale: 1 }"
160
+ [whileHover]="{ scale: 1.05 }"
161
+ [whileTap]="{ scale: 0.95 }"
162
+ [transition]="{ type: 'spring', stiffness: 400, damping: 17 }"
163
+ >
164
+ Interactive Button
165
+ </button>
166
+ ```
38
167
 
39
- ## Running unit tests
168
+ ### Stagger Children
169
+ ```html
170
+ <div
171
+ motionone
172
+ [initial]="{ opacity: 0 }"
173
+ [animate]="{ opacity: 1 }"
174
+ [staggerChildren]="0.1"
175
+ [delayChildren]="0.3"
176
+ >
177
+ <div motionone [initial]="{ x: -50, opacity: 0 }" [animate]="{ x: 0, opacity: 1 }">Item 1</div>
178
+ <div motionone [initial]="{ x: -50, opacity: 0 }" [animate]="{ x: 0, opacity: 1 }">Item 2</div>
179
+ <div motionone [initial]="{ x: -50, opacity: 0 }" [animate]="{ x: 0, opacity: 1 }">Item 3</div>
180
+ </div>
181
+ ```
40
182
 
41
- To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
183
+ ### Using Variants
184
+ ```typescript
185
+ @Component({
186
+ template: `
187
+ <div
188
+ motionone
189
+ [variants]="containerVariants"
190
+ [initial]="'hidden'"
191
+ [animate]="'visible'"
192
+ >
193
+ <div motionone [variants]="itemVariants">Item 1</div>
194
+ <div motionone [variants]="itemVariants">Item 2</div>
195
+ </div>
196
+ `
197
+ })
198
+ export class VariantsExample {
199
+ containerVariants = {
200
+ hidden: { opacity: 0 },
201
+ visible: {
202
+ opacity: 1,
203
+ transition: {
204
+ staggerChildren: 0.2,
205
+ delayChildren: 0.1
206
+ }
207
+ }
208
+ };
42
209
 
43
- ```bash
44
- ng test
210
+ itemVariants = {
211
+ hidden: { x: -20, opacity: 0 },
212
+ visible: {
213
+ x: 0,
214
+ opacity: 1,
215
+ transition: {
216
+ duration: 0.6,
217
+ ease: [0.33, 1, 0.68, 1]
218
+ }
219
+ }
220
+ };
221
+ }
45
222
  ```
46
223
 
47
- ## Running end-to-end tests
224
+ ### Timeline Animation
48
225
 
49
- For end-to-end (e2e) testing, run:
226
+ Timeline animations allow you to orchestrate multiple properties with precise timing control. Each timeline step can have different durations, delays, and easing functions.
50
227
 
51
- ```bash
52
- ng e2e
228
+ ```typescript
229
+ @Component({
230
+ template: `
231
+ <div
232
+ motionone
233
+ [timeline]="complexTimeline"
234
+ [animate]="{ opacity: 1 }"
235
+ (animationComplete)="onAnimationComplete()"
236
+ >
237
+ Complex sequenced animation
238
+ </div>
239
+ `
240
+ })
241
+ export class TimelineExample {
242
+ complexTimeline: TimelineStep[] = [
243
+ { prop: 'x', to: 100, duration: 1, atTime: 0 },
244
+ { prop: 'rotate', to: 180, duration: 0.5, atTime: 0.5 },
245
+ { prop: 'scale', to: 1.2, duration: 0.3, atTime: 1.2 },
246
+ { prop: 'opacity', keyframes: [0, 1, 0.5, 1], duration: 2, atTime: 0.8 }
247
+ ];
248
+
249
+ onAnimationComplete() {
250
+ console.log('Timeline animation completed!');
251
+ }
252
+ }
253
+ ```
254
+
255
+ ### Advanced Timeline Example (From Demo)
256
+
257
+ This example demonstrates a complex multi-property timeline animation with overlapping animations:
258
+
259
+ ```html
260
+ <div class="h-12 bg-blue-600" style="width:40px"
261
+ motionone
262
+ [timeline]="[
263
+ {
264
+ prop: 'width',
265
+ keyframes: ['40px','160px','80px'],
266
+ duration: 1.2,
267
+ atTime: 0.0,
268
+ ease: 'ease-out',
269
+ times: [0, 0.7, 1]
270
+ },
271
+ {
272
+ prop: 'backgroundColor',
273
+ keyframes: ['#f00','#0f0','#00f'],
274
+ duration: 5.0,
275
+ atTime: 0.5,
276
+ ease: 'ease-in',
277
+ times: [0, 0.4, 1]
278
+ },
279
+ {
280
+ prop: 'transform',
281
+ keyframes: ['scaleY(0.5)','scaleY(1)','scaleY(10)'],
282
+ duration: 6.0,
283
+ atTime: 0,
284
+ ease: { type:'spring', stiffness:100, damping:10 },
285
+ times: [0, 4, 5]
286
+ }
287
+ ]">
288
+ </div>
289
+ ```
290
+
291
+ **This timeline creates:**
292
+ 1. **Width Animation** (0.0s → 1.2s): Element width morphs from 40px → 160px → 80px with ease-out timing
293
+ 2. **Color Transition** (0.5s → 5.5s): Background color cycles through red → green → blue starting 0.5s later
294
+ 3. **Scale Transform** (0.0s → 6.0s): Vertical scaling from 0.5 → 1 → 10 with spring physics
295
+
296
+ **Key Timeline Features:**
297
+ - **Overlapping Animations**: Multiple properties animate simultaneously with different timings
298
+ - **Custom Keyframe Timing**: `times` array controls when each keyframe occurs (0-1 normalized)
299
+ - **Mixed Easing**: Different easing functions per property (ease-out, ease-in, spring)
300
+ - **Absolute Timing**: `atTime` sets when each animation begins relative to timeline start
301
+ - **Duration Independence**: Each property can have completely different durations
302
+
303
+ ### Conditional Rendering with motionIf
304
+ ```html
305
+ <div *motionIf="isVisible">
306
+ <div
307
+ motionone
308
+ [initial]="{ scale: 0, opacity: 0 }"
309
+ [animate]="{ scale: 1, opacity: 1 }"
310
+ [exit]="{ scale: 0, opacity: 0, transition: { duration: 0.2 } }"
311
+ [transition]="{ duration: 0.3, ease: 'backOut' }"
312
+ >
313
+ This will animate in and out smoothly!
314
+ </div>
315
+ </div>
316
+ ```
317
+
318
+ ### Spring Physics
319
+ ```html
320
+ <div
321
+ motionone
322
+ [initial]="{ y: -100 }"
323
+ [animate]="{ y: 0 }"
324
+ [easing]="{ type: 'spring', stiffness: 300, damping: 20 }"
325
+ >
326
+ Bouncy spring animation
327
+ </div>
328
+ ```
329
+
330
+ ### Scroll-triggered Animation
331
+ ```html
332
+ <div
333
+ motionone
334
+ [initial]="{ opacity: 0, y: 50 }"
335
+ [whileInView]="{ opacity: 1, y: 0 }"
336
+ [transition]="{ duration: 0.6 }"
337
+ [offset]="'-100px'"
338
+ >
339
+ Animates when scrolled into view
340
+ </div>
341
+ ```
342
+
343
+ ## Directives
344
+
345
+ ### motionone
346
+ Main animation directive for creating smooth, performant animations.
347
+
348
+ ### motionIf
349
+ Structural directive for conditional rendering with enter/exit animations:
350
+
351
+ ```html
352
+ <div *motionIf="condition">
353
+ Content with enter/exit animations
354
+ </div>
53
355
  ```
54
356
 
55
- Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
357
+ ## Easing Options
358
+
359
+ ### Built-in Easings
360
+ - `'ease'` - Default CSS ease
361
+ - `'ease-in'` - CSS ease-in
362
+ - `'ease-out'` - CSS ease-out
363
+ - `'ease-in-out'` - CSS ease-in-out
364
+ - `'linear'` - Linear timing
365
+
366
+ ### Custom Cubic Bezier
367
+ ```typescript
368
+ [0.4, 0, 0.2, 1] // Custom cubic bezier curve
369
+ ```
370
+
371
+ ### Spring Physics
372
+ ```typescript
373
+ {
374
+ type: 'spring',
375
+ stiffness: 400, // Spring stiffness (higher = snappier)
376
+ damping: 17 // Spring damping (higher = less bouncy)
377
+ }
378
+ ```
379
+
380
+ ## Transform Properties
381
+
382
+ The directive supports convenient transform shortcuts:
383
+ - `x`, `y` - Translate in pixels
384
+ - `scale`, `scaleX`, `scaleY` - Scale transforms
385
+ - `rotate` - Rotation in degrees
386
+ - `transform` - Raw transform string (for advanced use)
387
+
388
+ ## Color Animation
389
+
390
+ Supports smooth color transitions:
391
+ ```typescript
392
+ {
393
+ backgroundColor: ['#ff0000', '#00ff00', '#0000ff'], // Keyframe colors
394
+ color: '#ffffff' // Single color value
395
+ }
396
+ ```
397
+
398
+ ## Performance Notes
399
+
400
+ - Uses Motion One's optimized animation engine
401
+ - Automatically promotes animations to the GPU when beneficial
402
+ - Minimal bundle size impact
403
+ - Tree-shakeable exports
404
+
405
+ ## Browser Support
406
+
407
+ - Chrome 80+
408
+ - Firefox 76+
409
+ - Safari 13+
410
+ - Edge 80+
56
411
 
57
- ## Additional Resources
412
+ ## License
58
413
 
59
- For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
414
+ MIT
@@ -0,0 +1,7 @@
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
+ }
package/package.json CHANGED
@@ -1,65 +1,52 @@
1
1
  {
2
2
  "name": "@hilux/ngx-motion",
3
- "version": "1.0.15",
4
- "main": "index.js",
5
- "types": "index.d.ts",
6
- "files": [
7
- "*.ts",
8
- "*.js",
9
- "*.d.ts"
3
+ "version": "1.1.1",
4
+ "description": "Angular directive for Motion One animations",
5
+ "author": "Hilux",
6
+ "keywords": [
7
+ "angular",
8
+ "animation",
9
+ "motion",
10
+ "directive",
11
+ "motion-one",
12
+ "ngx"
10
13
  ],
11
- "publishConfig": {
12
- "registry": "https://registry.npmjs.org/"
13
- },
14
+ "homepage": "https://github.com/rs-components/ng-motion-demo",
14
15
  "repository": {
15
16
  "type": "git",
16
- "url": "https://github.com/rs-components/ng-motion-demo.git"
17
+ "url": "git+https://github.com/rs-components/ng-motion-demo.git"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "license": "MIT",
23
+ "peerDependencies": {
24
+ "@angular/common": "^19.0.0",
25
+ "@angular/core": "^19.0.0",
26
+ "@angular/router": "^19.0.0",
27
+ "motion": "^12.0.0",
28
+ "rxjs": "~7.8.0"
29
+ },
30
+ "dependencies": {
31
+ "tslib": "^2.3.0"
32
+ },
33
+ "devDependencies": {
34
+ "@angular/common": "^19.0.0",
35
+ "@angular/core": "^19.0.0",
36
+ "@angular/router": "^19.0.0",
37
+ "motion": "^12.0.0",
38
+ "rxjs": "~7.8.0"
17
39
  },
18
40
  "scripts": {
19
41
  "ng": "ng",
20
42
  "start": "ng serve",
21
43
  "build": "ng build",
44
+ "build:lib": "ng build ngx-motion",
22
45
  "watch": "ng build --watch --configuration development",
23
46
  "test": "ng test",
24
- "serve:ssr:ng-motion-poc": "node dist/ng-motion-poc/server/server.mjs"
47
+ "serve:ssr:ng-motion-poc": "node dist/ng-motion-poc/server/server.mjs",
48
+ "publish:lib": "ng build && cd dist/ngx-motion && npm publish",
49
+ "pack:lib": "ng build && cd dist/ngx-motion && npm pack"
25
50
  },
26
- "dependencies": {
27
- "@angular/common": "^19.2.0",
28
- "@angular/compiler": "^19.2.0",
29
- "@angular/core": "^19.2.0",
30
- "@angular/forms": "^19.2.0",
31
- "@angular/platform-browser": "^19.2.0",
32
- "@angular/platform-browser-dynamic": "^19.2.0",
33
- "@angular/platform-server": "^19.2.0",
34
- "@angular/router": "^19.2.0",
35
- "@angular/ssr": "^19.2.5",
36
- "express": "^4.18.2",
37
- "rxjs": "~7.8.0",
38
- "three": "^0.164.1",
39
- "tslib": "^2.3.0",
40
- "tweakpane": "^4.0.5",
41
- "zone.js": "~0.15.0"
42
- },
43
- "devDependencies": {
44
- "@angular-devkit/build-angular": "^19.2.5",
45
- "@angular/cli": "^19.2.5",
46
- "@angular/compiler-cli": "^19.2.0",
47
- "@types/express": "^4.17.17",
48
- "@types/jasmine": "~5.1.0",
49
- "@types/node": "^18.18.0",
50
- "@types/three": "^0.155.0",
51
- "@types/webgl2": "0.0.7",
52
- "angular-cli-ghpages": "^2.0.3",
53
- "autoprefixer": "^10.4.21",
54
- "jasmine-core": "~5.6.0",
55
- "karma": "~6.4.0",
56
- "karma-chrome-launcher": "~3.2.0",
57
- "karma-coverage": "~2.2.0",
58
- "karma-jasmine": "~5.1.0",
59
- "karma-jasmine-html-reporter": "~2.1.0",
60
- "motion": "^12.4.10",
61
- "postcss": "^8.5.3",
62
- "tailwindcss": "^3.4.17",
63
- "typescript": "~5.7.2"
64
- }
51
+ "sideEffects": false
65
52
  }
@@ -0,0 +1,116 @@
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
+ }