@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
@@ -0,0 +1,2020 @@
1
+ import * as i0 from "@angular/core";
2
+ import { ChangeDetectorRef, DOCUMENT, DestroyRef, Directive, ElementRef, EventEmitter, HostListener, Inject, Injectable, Input, NgZone, Output, PLATFORM_ID, TemplateRef, ViewContainerRef, inject, signal } from "@angular/core";
3
+ import { isPlatformBrowser } from "@angular/common";
4
+ import { Subject, timer } from "rxjs";
5
+ import { map, take } from "rxjs/operators";
6
+ import { animate, easeIn, easeInOut, easeOut, inView, spring, stagger } from "motion";
7
+ var MotionOneService = class MotionOneService {
8
+ document;
9
+ platformId;
10
+ ngZone;
11
+ motionElements = [];
12
+ _scrollYProgress = signal(0, ...ngDevMode ? [{ debugName: "_scrollYProgress" }] : /* istanbul ignore next */ []);
13
+ removeScrollListener = null;
14
+ get scrollYProgress() {
15
+ this.ensureScrollListener();
16
+ return this._scrollYProgress;
17
+ }
18
+ totalExitDuration = 0;
19
+ exitAnimationsComplete = new Subject();
20
+ enterAnimationsComplete = new Subject();
21
+ activeExitAnimations = /* @__PURE__ */ new Map();
22
+ activeEnterAnimations = /* @__PURE__ */ new Map();
23
+ constructor(document, platformId, ngZone) {
24
+ this.document = document;
25
+ this.platformId = platformId;
26
+ this.ngZone = ngZone;
27
+ }
28
+ ngOnDestroy() {
29
+ this.removeScrollListener?.();
30
+ this.removeScrollListener = null;
31
+ this.exitAnimationsComplete.complete();
32
+ this.enterAnimationsComplete.complete();
33
+ }
34
+ updateTotalExitDuration() {
35
+ this.totalExitDuration = 0;
36
+ }
37
+ ensureScrollListener() {
38
+ if (this.removeScrollListener || !isPlatformBrowser(this.platformId)) return;
39
+ let frame = 0;
40
+ const onScroll = () => {
41
+ if (frame) return;
42
+ frame = requestAnimationFrame(() => {
43
+ frame = 0;
44
+ this.updateScrollProgress();
45
+ });
46
+ };
47
+ this.ngZone.runOutsideAngular(() => window.addEventListener("scroll", onScroll, { passive: true }));
48
+ this.removeScrollListener = () => {
49
+ window.removeEventListener("scroll", onScroll);
50
+ if (frame) cancelAnimationFrame(frame);
51
+ };
52
+ onScroll();
53
+ }
54
+ updateScrollProgress() {
55
+ if (!isPlatformBrowser(this.platformId)) return;
56
+ const doc = this.document.documentElement;
57
+ const scrollTop = window.scrollY || doc.scrollTop;
58
+ const scrollHeight = doc.scrollHeight - doc.clientHeight;
59
+ const progress = scrollHeight > 0 ? Math.round(scrollTop / scrollHeight * 100) : 0;
60
+ this._scrollYProgress.set(progress);
61
+ }
62
+ registerMotionElement(element) {
63
+ this.motionElements.push(element);
64
+ this.updateTotalExitDuration();
65
+ }
66
+ unregisterMotionElement(element) {
67
+ this.motionElements = this.motionElements.filter((e) => e !== element);
68
+ this.updateTotalExitDuration();
69
+ }
70
+ getMotionElements() {
71
+ return this.motionElements;
72
+ }
73
+ getAllElementsByRoute(route) {
74
+ return this.motionElements.filter((element) => element.route === route);
75
+ }
76
+ cancelAllAnimations() {
77
+ if (!isPlatformBrowser(this.platformId)) return;
78
+ this.motionElements.forEach((motion) => {
79
+ motion.cancel();
80
+ });
81
+ }
82
+ runAllEnterAnimations() {
83
+ if (!isPlatformBrowser(this.platformId)) return;
84
+ this.motionElements.forEach((motion) => {
85
+ motion.runInitAnimation();
86
+ });
87
+ }
88
+ runAllExitAnimations() {
89
+ if (!isPlatformBrowser(this.platformId)) return;
90
+ this.motionElements.forEach((motion) => {
91
+ motion.runExitAnimation();
92
+ });
93
+ }
94
+ getExitAnimationsComplete(route) {
95
+ if (!isPlatformBrowser(this.platformId)) return timer(0).pipe(take(1), map(() => true));
96
+ const exitDuration = this.getLongestExitDurationForRoute(route);
97
+ if (exitDuration === 0 || this.getAllElementsByRoute(route).length === 0) return timer(0).pipe(take(1), map(() => true));
98
+ return timer(exitDuration * 1e3).pipe(take(1), map(() => true));
99
+ }
100
+ getEnterAnimationsComplete(route) {
101
+ if (!isPlatformBrowser(this.platformId)) return timer(0).pipe(take(1), map(() => true));
102
+ const enterDuration = this.getLongestEnterDurationForRoute(route);
103
+ if (enterDuration === 0 || this.getAllElementsByRoute(route).length === 0) return timer(0).pipe(take(1), map(() => true));
104
+ return timer(enterDuration * 1e3).pipe(take(1), map(() => true));
105
+ }
106
+ startExitAnimationsForRoute(route) {
107
+ if (!isPlatformBrowser(this.platformId)) return;
108
+ const elements = this.getAllElementsByRoute(route);
109
+ this.activeExitAnimations.set(route, elements.length);
110
+ if (elements.length === 0) {
111
+ this.completeExitAnimationsForRoute(route);
112
+ return;
113
+ }
114
+ elements.forEach((element) => {
115
+ element.runExitAnimation();
116
+ });
117
+ const exitDuration = this.getLongestExitDurationForRoute(route);
118
+ setTimeout(() => {
119
+ this.completeExitAnimationsForRoute(route);
120
+ }, exitDuration * 1e3);
121
+ }
122
+ startEnterAnimationsForRoute(route) {
123
+ if (!isPlatformBrowser(this.platformId)) return;
124
+ const elements = this.getAllElementsByRoute(route);
125
+ this.activeEnterAnimations.set(route, elements.length);
126
+ if (elements.length === 0) {
127
+ this.completeEnterAnimationsForRoute(route);
128
+ return;
129
+ }
130
+ elements.forEach((element) => {
131
+ element.runInitAnimation();
132
+ });
133
+ const enterDuration = this.getLongestEnterDurationForRoute(route);
134
+ setTimeout(() => {
135
+ this.completeEnterAnimationsForRoute(route);
136
+ }, enterDuration * 1e3);
137
+ }
138
+ completeExitAnimationsForRoute(route) {
139
+ this.activeExitAnimations.delete(route);
140
+ this.exitAnimationsComplete.next(route);
141
+ }
142
+ completeEnterAnimationsForRoute(route) {
143
+ this.activeEnterAnimations.delete(route);
144
+ this.enterAnimationsComplete.next(route);
145
+ }
146
+ areExitAnimationsComplete(route) {
147
+ return !this.activeExitAnimations.has(route);
148
+ }
149
+ areEnterAnimationsComplete(route) {
150
+ return !this.activeEnterAnimations.has(route);
151
+ }
152
+ runAllExitAnimationsForRoute(route) {
153
+ if (!isPlatformBrowser(this.platformId)) return [];
154
+ this.startExitAnimationsForRoute(route);
155
+ return this.getAllElementsByRoute(route);
156
+ }
157
+ runAllEnterAnimationsForRoute(route) {
158
+ if (!isPlatformBrowser(this.platformId)) return [];
159
+ this.startEnterAnimationsForRoute(route);
160
+ return this.getAllElementsByRoute(route);
161
+ }
162
+ getLongestExitDurationForRoute(route) {
163
+ return 0;
164
+ }
165
+ getLongestEnterDurationForRoute(route) {
166
+ if (!isPlatformBrowser(this.platformId)) return 0;
167
+ if (this.motionElements.length === 0) return 0;
168
+ const elements = this.getAllElementsByRoute(route);
169
+ if (elements.length === 0) return 0;
170
+ const durations = elements.map((motion) => {
171
+ return motion.getDuration();
172
+ });
173
+ return durations.length > 0 ? Math.max(...durations) : 0;
174
+ }
175
+ getLongestEnterDuration() {
176
+ if (!isPlatformBrowser(this.platformId)) return 0;
177
+ if (this.motionElements.length === 0) return 0;
178
+ const durations = this.motionElements.map((motion) => {
179
+ return motion.getDuration();
180
+ });
181
+ return durations.length > 0 ? Math.max(...durations) : 0;
182
+ }
183
+ static ɵfac = i0.ɵɵngDeclareFactory({
184
+ minVersion: "12.0.0",
185
+ version: "22.3.2",
186
+ ngImport: i0,
187
+ type: MotionOneService,
188
+ deps: [
189
+ { token: DOCUMENT },
190
+ { token: PLATFORM_ID },
191
+ { token: NgZone }
192
+ ],
193
+ target: i0.ɵɵFactoryTarget.Injectable
194
+ });
195
+ static ɵprov = i0.ɵɵngDeclareInjectable({
196
+ minVersion: "12.0.0",
197
+ version: "22.3.2",
198
+ ngImport: i0,
199
+ type: MotionOneService,
200
+ providedIn: "root"
201
+ });
202
+ };
203
+ i0.ɵɵngDeclareClassMetadata({
204
+ minVersion: "12.0.0",
205
+ version: "22.3.2",
206
+ ngImport: i0,
207
+ type: MotionOneService,
208
+ decorators: [{
209
+ type: Injectable,
210
+ args: [{ providedIn: "root" }]
211
+ }],
212
+ ctorParameters: () => [
213
+ {
214
+ type: Document,
215
+ decorators: [{
216
+ type: Inject,
217
+ args: [DOCUMENT]
218
+ }]
219
+ },
220
+ {
221
+ type: Object,
222
+ decorators: [{
223
+ type: Inject,
224
+ args: [PLATFORM_ID]
225
+ }]
226
+ },
227
+ { type: NgZone }
228
+ ]
229
+ });
230
+ const noopControls = () => ({ stop: () => {} });
231
+ const linear = (t) => t;
232
+ var MotionAnimationService = class MotionAnimationService {
233
+ platformId = inject(PLATFORM_ID);
234
+ ngZone = inject(NgZone);
235
+ isBrowser = isPlatformBrowser(this.platformId);
236
+ animate(target, keyframes, options) {
237
+ if (!this.isBrowser) return noopControls();
238
+ try {
239
+ return this.ngZone.runOutsideAngular(() => animate(target, keyframes, options));
240
+ } catch (e) {
241
+ console.error("[ngx-motion] Error in animate:", e);
242
+ return noopControls();
243
+ }
244
+ }
245
+ inView(element, onStart, options) {
246
+ if (!this.isBrowser) return () => {};
247
+ return this.ngZone.runOutsideAngular(() => inView(element, (el, entry) => onStart(entry), options));
248
+ }
249
+ get easeIn() {
250
+ return this.isBrowser ? easeIn : linear;
251
+ }
252
+ get easeOut() {
253
+ return this.isBrowser ? easeOut : linear;
254
+ }
255
+ get easeInOut() {
256
+ return this.isBrowser ? easeInOut : linear;
257
+ }
258
+ stagger(duration, options) {
259
+ if (!this.isBrowser) return 0;
260
+ try {
261
+ return stagger(duration, options);
262
+ } catch (e) {
263
+ console.error("[ngx-motion] Error in stagger:", e);
264
+ return 0;
265
+ }
266
+ }
267
+ get spring() {
268
+ return (options) => {
269
+ if (!this.isBrowser) return linear;
270
+ try {
271
+ const generator = spring({
272
+ stiffness: options?.stiffness ?? 100,
273
+ damping: options?.damping ?? 10
274
+ });
275
+ if (typeof generator === "function") return generator;
276
+ } catch {}
277
+ return easeInOut;
278
+ };
279
+ }
280
+ static ɵfac = i0.ɵɵngDeclareFactory({
281
+ minVersion: "12.0.0",
282
+ version: "22.3.2",
283
+ ngImport: i0,
284
+ type: MotionAnimationService,
285
+ deps: [],
286
+ target: i0.ɵɵFactoryTarget.Injectable
287
+ });
288
+ static ɵprov = i0.ɵɵngDeclareInjectable({
289
+ minVersion: "12.0.0",
290
+ version: "22.3.2",
291
+ ngImport: i0,
292
+ type: MotionAnimationService,
293
+ providedIn: "root"
294
+ });
295
+ };
296
+ i0.ɵɵngDeclareClassMetadata({
297
+ minVersion: "12.0.0",
298
+ version: "22.3.2",
299
+ ngImport: i0,
300
+ type: MotionAnimationService,
301
+ decorators: [{
302
+ type: Injectable,
303
+ args: [{ providedIn: "root" }]
304
+ }]
305
+ });
306
+ function getEasing(easingString, motionAnimation) {
307
+ if (!easingString) return motionAnimation.easeInOut;
308
+ if (Array.isArray(easingString)) return easingString;
309
+ if (typeof easingString === "object" && "type" in easingString && easingString.type === "spring") return motionAnimation.spring({
310
+ stiffness: easingString.stiffness || 100,
311
+ damping: easingString.damping || 10
312
+ });
313
+ if (typeof easingString === "string") {
314
+ if (easingString === "ease-in") return motionAnimation.easeIn;
315
+ if (easingString === "ease-out") return motionAnimation.easeOut;
316
+ if (easingString === "ease-in-out" || easingString === "ease") return motionAnimation.easeInOut;
317
+ if (easingString === "spring") return motionAnimation.spring();
318
+ }
319
+ return motionAnimation.easeInOut;
320
+ }
321
+ function mapRepeatTypeToDirection(repeatType) {
322
+ if (!repeatType) return void 0;
323
+ if (repeatType === "forwards" || repeatType === "loop") return "normal";
324
+ if (repeatType === "reverse") return "reverse";
325
+ if (repeatType === "pingPong" || repeatType === "mirror") return "alternate";
326
+ return "normal";
327
+ }
328
+ function getRepeatValue(transitionObj, fallbackRepeat) {
329
+ if (transitionObj.repeat !== void 0) {
330
+ if (transitionObj.repeat === true) return Infinity;
331
+ else if (typeof transitionObj.repeat === "number") return transitionObj.repeat;
332
+ }
333
+ return fallbackRepeat ? Infinity : 0;
334
+ }
335
+ var MotionAnimationOptionsService = class MotionAnimationOptionsService {
336
+ motionAnimation;
337
+ constructor(motionAnimation) {
338
+ this.motionAnimation = motionAnimation;
339
+ }
340
+ getAnimationOptions(config) {
341
+ const stateTransition = config.targetState?.transition ?? config.animateState?.transition;
342
+ const globalTransition = config.transition;
343
+ const transitionObj = stateTransition || globalTransition || {};
344
+ const delay = config.staggerDelay !== void 0 && config.staggerDelay >= 0 ? config.staggerDelay : transitionObj.delay ?? config.delay;
345
+ const easeInput = transitionObj.type === "spring" ? {
346
+ type: "spring",
347
+ stiffness: transitionObj.stiffness,
348
+ damping: transitionObj.damping
349
+ } : transitionObj.ease ?? config.easing;
350
+ let targetHasKeyframeArrays = false;
351
+ if (config.targetState) for (const k of Object.keys(config.targetState)) {
352
+ if (k === "transition" || k === "at") continue;
353
+ const v = config.targetState[k];
354
+ if (Array.isArray(v)) {
355
+ targetHasKeyframeArrays = true;
356
+ break;
357
+ }
358
+ }
359
+ if (easeInput && typeof easeInput === "object" && "type" in easeInput && easeInput.type === "spring" && !targetHasKeyframeArrays) {
360
+ const springOptions = {
361
+ type: "spring",
362
+ stiffness: easeInput.stiffness ?? 100,
363
+ damping: easeInput.damping ?? 10,
364
+ delay,
365
+ repeat: getRepeatValue(transitionObj, config.repeat),
366
+ repeatDelay: transitionObj.repeatDelay,
367
+ onComplete: config.onComplete
368
+ };
369
+ const direction = mapRepeatTypeToDirection(transitionObj.repeatType);
370
+ if (direction) springOptions.direction = direction;
371
+ if (transitionObj.repeatType) springOptions.repeatType = transitionObj.repeatType;
372
+ return springOptions;
373
+ }
374
+ const ease = getEasing(easeInput, this.motionAnimation);
375
+ const options = {
376
+ duration: transitionObj.duration ?? config.duration,
377
+ delay,
378
+ repeat: getRepeatValue(transitionObj, config.repeat),
379
+ repeatDelay: transitionObj.repeatDelay,
380
+ onComplete: config.onComplete
381
+ };
382
+ const direction = mapRepeatTypeToDirection(transitionObj.repeatType);
383
+ if (direction) options.direction = direction;
384
+ if (transitionObj.repeatType) options.repeatType = transitionObj.repeatType;
385
+ options.easing = ease;
386
+ options.ease = ease;
387
+ return options;
388
+ }
389
+ getStaggerValue(animateState, transition, defaultStaggerChildren = 0) {
390
+ return (animateState?.transition || transition || {}).staggerChildren ?? defaultStaggerChildren;
391
+ }
392
+ getDelayChildren(animateState, transition, defaultDelayChildren = 0) {
393
+ return (animateState?.transition || transition || {}).delayChildren ?? defaultDelayChildren;
394
+ }
395
+ getStaggerDirection(animateState, transition, defaultStaggerDirection = 1) {
396
+ return (animateState?.transition || transition || {}).staggerDirection ?? defaultStaggerDirection;
397
+ }
398
+ getWhen(animateState, transition) {
399
+ return (animateState?.transition || transition || {}).when ?? "together";
400
+ }
401
+ static ɵfac = i0.ɵɵngDeclareFactory({
402
+ minVersion: "12.0.0",
403
+ version: "22.3.2",
404
+ ngImport: i0,
405
+ type: MotionAnimationOptionsService,
406
+ deps: [{ token: MotionAnimationService }],
407
+ target: i0.ɵɵFactoryTarget.Injectable
408
+ });
409
+ static ɵprov = i0.ɵɵngDeclareInjectable({
410
+ minVersion: "12.0.0",
411
+ version: "22.3.2",
412
+ ngImport: i0,
413
+ type: MotionAnimationOptionsService,
414
+ providedIn: "root"
415
+ });
416
+ };
417
+ i0.ɵɵngDeclareClassMetadata({
418
+ minVersion: "12.0.0",
419
+ version: "22.3.2",
420
+ ngImport: i0,
421
+ type: MotionAnimationOptionsService,
422
+ decorators: [{
423
+ type: Injectable,
424
+ args: [{ providedIn: "root" }]
425
+ }],
426
+ ctorParameters: () => [{ type: MotionAnimationService }]
427
+ });
428
+ function normalizeTimes(times, duration) {
429
+ if (!times || times.length === 0) return void 0;
430
+ if (!times.some((t) => t > 1)) return times;
431
+ const maxT = Math.max(...times);
432
+ const safeDuration = Math.max(duration, 1e-6);
433
+ const divisor = maxT > safeDuration * 1.001 ? maxT : safeDuration;
434
+ return times.map((t) => {
435
+ const v = t / divisor;
436
+ return v < 0 ? 0 : v > 1 ? 1 : v;
437
+ });
438
+ }
439
+ function calculateStaggerDelay(index, totalChildren, staggerValue, direction) {
440
+ let staggerIndex;
441
+ if (direction >= 0) staggerIndex = index;
442
+ else staggerIndex = totalChildren - 1 - index;
443
+ return staggerIndex * staggerValue;
444
+ }
445
+ function calculateTotalStaggerDuration(childCount, staggerValue, baseDelay, delayChildren) {
446
+ return baseDelay + delayChildren + childCount * staggerValue;
447
+ }
448
+ var MotionStaggerService = class MotionStaggerService {
449
+ calculateChildDelay(index, config) {
450
+ const staggerDelay = calculateStaggerDelay(index, config.childCount, config.staggerValue, config.staggerDirection);
451
+ return config.parentDelay + config.delayChildren + staggerDelay;
452
+ }
453
+ calculateAllChildDelays(config) {
454
+ const delays = [];
455
+ for (let i = 0; i < config.childCount; i++) delays.push(this.calculateChildDelay(i, config));
456
+ return delays;
457
+ }
458
+ calculateTotalDuration(config) {
459
+ return calculateTotalStaggerDuration(config.childCount, config.staggerValue, config.parentDelay, config.delayChildren);
460
+ }
461
+ getStaggerIndex(index, childCount, direction) {
462
+ if (direction >= 0) return index;
463
+ else return childCount - 1 - index;
464
+ }
465
+ static ɵfac = i0.ɵɵngDeclareFactory({
466
+ minVersion: "12.0.0",
467
+ version: "22.3.2",
468
+ ngImport: i0,
469
+ type: MotionStaggerService,
470
+ deps: [],
471
+ target: i0.ɵɵFactoryTarget.Injectable
472
+ });
473
+ static ɵprov = i0.ɵɵngDeclareInjectable({
474
+ minVersion: "12.0.0",
475
+ version: "22.3.2",
476
+ ngImport: i0,
477
+ type: MotionStaggerService,
478
+ providedIn: "root"
479
+ });
480
+ };
481
+ i0.ɵɵngDeclareClassMetadata({
482
+ minVersion: "12.0.0",
483
+ version: "22.3.2",
484
+ ngImport: i0,
485
+ type: MotionStaggerService,
486
+ decorators: [{
487
+ type: Injectable,
488
+ args: [{ providedIn: "root" }]
489
+ }]
490
+ });
491
+ const MOTION_DEFAULTS = {
492
+ DURATION: .3,
493
+ DELAY: 0,
494
+ EXIT_DELAY: 0,
495
+ DELAY_CHILDREN: 0,
496
+ EASING: "ease",
497
+ OFFSET: "0px",
498
+ STAGGER_CHILDREN: 0,
499
+ STAGGER_DIRECTION: 1,
500
+ REPEAT: false,
501
+ INVIEW_THRESHOLD: .1,
502
+ INVIEW_DELAY: 50,
503
+ INVIEW_MARGIN: "0px",
504
+ INVIEW_ROOT_MARGIN: "0px",
505
+ RESET_TIMEOUT: 10,
506
+ STAGGER_TIMEOUT: 50
507
+ };
508
+ const TRANSFORM_PROPERTIES = [
509
+ "x",
510
+ "y",
511
+ "rotate",
512
+ "scale",
513
+ "scaleX",
514
+ "scaleY"
515
+ ];
516
+ const COLOR_PROPERTIES = [
517
+ "backgroundColor",
518
+ "color",
519
+ "borderColor"
520
+ ];
521
+ const EXCLUDED_PROPERTIES = ["transition", "at"];
522
+ var MotionInViewService = class MotionInViewService {
523
+ platformId;
524
+ constructor(platformId) {
525
+ this.platformId = platformId;
526
+ }
527
+ createObserver(callback, config = {}) {
528
+ if (!isPlatformBrowser(this.platformId)) return null;
529
+ const observerConfig = {
530
+ root: config.root ?? null,
531
+ rootMargin: config.rootMargin ?? MOTION_DEFAULTS.INVIEW_ROOT_MARGIN,
532
+ threshold: config.threshold ?? MOTION_DEFAULTS.INVIEW_THRESHOLD
533
+ };
534
+ return new IntersectionObserver(callback, observerConfig);
535
+ }
536
+ createRunInViewObserver(element, onEntry, onExit) {
537
+ return this.createObserver((entries) => {
538
+ entries.forEach((entry) => {
539
+ if (entry.isIntersecting) onEntry();
540
+ else onExit();
541
+ });
542
+ }, {
543
+ root: null,
544
+ rootMargin: MOTION_DEFAULTS.INVIEW_ROOT_MARGIN,
545
+ threshold: MOTION_DEFAULTS.INVIEW_THRESHOLD
546
+ });
547
+ }
548
+ parseMargin(margin) {
549
+ if (!margin) return MOTION_DEFAULTS.INVIEW_MARGIN;
550
+ return margin;
551
+ }
552
+ isSupported() {
553
+ if (!isPlatformBrowser(this.platformId)) return false;
554
+ return "IntersectionObserver" in window;
555
+ }
556
+ disconnect(observer) {
557
+ if (observer) observer.disconnect();
558
+ }
559
+ static ɵfac = i0.ɵɵngDeclareFactory({
560
+ minVersion: "12.0.0",
561
+ version: "22.3.2",
562
+ ngImport: i0,
563
+ type: MotionInViewService,
564
+ deps: [{ token: PLATFORM_ID }],
565
+ target: i0.ɵɵFactoryTarget.Injectable
566
+ });
567
+ static ɵprov = i0.ɵɵngDeclareInjectable({
568
+ minVersion: "12.0.0",
569
+ version: "22.3.2",
570
+ ngImport: i0,
571
+ type: MotionInViewService,
572
+ providedIn: "root"
573
+ });
574
+ };
575
+ i0.ɵɵngDeclareClassMetadata({
576
+ minVersion: "12.0.0",
577
+ version: "22.3.2",
578
+ ngImport: i0,
579
+ type: MotionInViewService,
580
+ decorators: [{
581
+ type: Injectable,
582
+ args: [{ providedIn: "root" }]
583
+ }],
584
+ ctorParameters: () => [{
585
+ type: Object,
586
+ decorators: [{
587
+ type: Inject,
588
+ args: [PLATFORM_ID]
589
+ }]
590
+ }]
591
+ });
592
+ function isColorProperty(key) {
593
+ return COLOR_PROPERTIES.includes(key);
594
+ }
595
+ function normalizeColor(color) {
596
+ if (color == null) return "";
597
+ if (typeof color !== "string") try {
598
+ return String(color);
599
+ } catch {
600
+ return "";
601
+ }
602
+ if (color.startsWith("rgb") || color.startsWith("#")) return color;
603
+ return {
604
+ aqua: "#00ffff",
605
+ red: "#ff0000",
606
+ blue: "#0000ff",
607
+ green: "#008000",
608
+ yellow: "#ffff00",
609
+ purple: "#800080",
610
+ orange: "#ffa500",
611
+ black: "#000000",
612
+ white: "#ffffff"
613
+ }[color] || color;
614
+ }
615
+ function normalizeColorValue(value) {
616
+ if (Array.isArray(value)) return value.map((v) => normalizeColor(v));
617
+ return normalizeColor(value);
618
+ }
619
+ const TRANSITION_OPTION_KEYS = /* @__PURE__ */ new Set([
620
+ "duration",
621
+ "delay",
622
+ "ease",
623
+ "easing",
624
+ "type",
625
+ "stiffness",
626
+ "damping",
627
+ "mass",
628
+ "bounce",
629
+ "velocity",
630
+ "restSpeed",
631
+ "restDelta",
632
+ "repeat",
633
+ "repeatType",
634
+ "repeatDelay",
635
+ "staggerChildren",
636
+ "staggerDirection",
637
+ "delayChildren",
638
+ "when",
639
+ "times"
640
+ ]);
641
+ var MotionTimelineService = class MotionTimelineService {
642
+ motionAnimation;
643
+ ngZone = inject(NgZone);
644
+ constructor(motionAnimation) {
645
+ this.motionAnimation = motionAnimation;
646
+ }
647
+ runTimeline(element, timeline, targetState, baseDelay, duration, easing, repeat, onComplete) {
648
+ const controls = [];
649
+ let maxEnd = 0;
650
+ const timelinePropsSet = new Set(timeline.map((s) => s.prop));
651
+ const nonTimelineTarget = {};
652
+ Object.keys(targetState).forEach((k) => {
653
+ if (k === "transition" || k === "at") return;
654
+ if (!timelinePropsSet.has(k)) nonTimelineTarget[k] = targetState[k];
655
+ });
656
+ if (Object.keys(nonTimelineTarget).length > 0) {
657
+ const options = {
658
+ duration,
659
+ delay: baseDelay,
660
+ easing,
661
+ ease: easing,
662
+ repeat: repeat ? Infinity : 0
663
+ };
664
+ const ctl = this.motionAnimation.animate(element, nonTimelineTarget, options);
665
+ controls.push(ctl);
666
+ const nonEnd = (options.delay ?? 0) + (options.duration ?? duration);
667
+ if (nonEnd > maxEnd) maxEnd = nonEnd;
668
+ }
669
+ timeline.forEach((step) => {
670
+ const start = baseDelay + (step.atTime ?? 0) + (step.delay ?? 0);
671
+ const stepDuration = step.duration;
672
+ const value = step.keyframes !== void 0 ? step.keyframes : step.to;
673
+ const ease = getEasing(step.ease ?? easing, this.motionAnimation);
674
+ const options = {
675
+ duration: stepDuration,
676
+ delay: start,
677
+ easing: ease,
678
+ ease
679
+ };
680
+ if (step.repeat !== void 0) options.repeat = step.repeat === true ? Infinity : step.repeat;
681
+ if (step.repeatDelay !== void 0) options.repeatDelay = step.repeatDelay;
682
+ const dir = mapRepeatTypeToDirection(step.repeatType);
683
+ if (dir) options.direction = dir;
684
+ if (step.repeatType) options.repeatType = step.repeatType;
685
+ if (step.times) options.offset = normalizeTimes(step.times, stepDuration);
686
+ const end = start + stepDuration;
687
+ if (end > maxEnd) maxEnd = end;
688
+ let v = value;
689
+ if (isColorProperty(step.prop)) v = normalizeColorValue(v);
690
+ const target = { [step.prop]: v };
691
+ const control = this.motionAnimation.animate(element, target, options);
692
+ controls.push(control);
693
+ });
694
+ if (onComplete) this.ngZone.runOutsideAngular(() => setTimeout(() => onComplete(), maxEnd * 1e3));
695
+ return {
696
+ controls,
697
+ maxEnd
698
+ };
699
+ }
700
+ runPerPropertyAnimations(element, targetState, baseDelay, duration, easing, repeat, onComplete) {
701
+ const controls = [];
702
+ const transitionMap = targetState.transition;
703
+ const props = Object.keys(targetState).filter((k) => k !== "transition" && k !== "at");
704
+ let maxEnd = 0;
705
+ props.forEach((prop) => {
706
+ const value = targetState[prop];
707
+ const conf = transitionMap?.[prop] || {};
708
+ const delay = baseDelay + (conf.delay ?? 0);
709
+ const ease = getEasing(conf.ease ?? easing, this.motionAnimation);
710
+ const propDuration = conf.duration ?? duration;
711
+ const options = {
712
+ duration: propDuration,
713
+ delay,
714
+ easing: ease,
715
+ ease,
716
+ repeat: conf.repeat !== void 0 ? getRepeatValue(conf, repeat) : repeat ? Infinity : 0,
717
+ repeatDelay: conf.repeatDelay
718
+ };
719
+ const dir = mapRepeatTypeToDirection(conf.repeatType);
720
+ if (dir) options.direction = dir;
721
+ if (conf.repeatType) options.repeatType = conf.repeatType;
722
+ const times = conf.times;
723
+ if (times && Array.isArray(times)) options.offset = normalizeTimes(times, propDuration);
724
+ const end = delay + propDuration;
725
+ if (end > maxEnd) maxEnd = end;
726
+ let finalValue = value;
727
+ if (isColorProperty(prop)) finalValue = normalizeColorValue(value);
728
+ const target = { [prop]: finalValue };
729
+ const control = this.motionAnimation.animate(element, target, options);
730
+ controls.push(control);
731
+ });
732
+ if (onComplete) this.ngZone.runOutsideAngular(() => setTimeout(() => onComplete(), maxEnd * 1e3));
733
+ return {
734
+ controls,
735
+ maxEnd
736
+ };
737
+ }
738
+ isPerPropertyTransition(transition) {
739
+ if (!transition || typeof transition !== "object" || Array.isArray(transition)) return false;
740
+ const keys = Object.keys(transition);
741
+ if (keys.length === 0) return false;
742
+ return keys.every((key) => !TRANSITION_OPTION_KEYS.has(key) && transition[key] !== null && typeof transition[key] === "object" && !Array.isArray(transition[key]));
743
+ }
744
+ static ɵfac = i0.ɵɵngDeclareFactory({
745
+ minVersion: "12.0.0",
746
+ version: "22.3.2",
747
+ ngImport: i0,
748
+ type: MotionTimelineService,
749
+ deps: [{ token: MotionAnimationService }],
750
+ target: i0.ɵɵFactoryTarget.Injectable
751
+ });
752
+ static ɵprov = i0.ɵɵngDeclareInjectable({
753
+ minVersion: "12.0.0",
754
+ version: "22.3.2",
755
+ ngImport: i0,
756
+ type: MotionTimelineService,
757
+ providedIn: "root"
758
+ });
759
+ };
760
+ i0.ɵɵngDeclareClassMetadata({
761
+ minVersion: "12.0.0",
762
+ version: "22.3.2",
763
+ ngImport: i0,
764
+ type: MotionTimelineService,
765
+ decorators: [{
766
+ type: Injectable,
767
+ args: [{ providedIn: "root" }]
768
+ }],
769
+ ctorParameters: () => [{ type: MotionAnimationService }]
770
+ });
771
+ var MotionGestureService = class MotionGestureService {
772
+ gestureStates = /* @__PURE__ */ new Map();
773
+ MIN_GESTURE_INTERVAL = 50;
774
+ shouldAllowGesture(elementId, gestureType) {
775
+ const state = this.gestureStates.get(elementId);
776
+ if (!state) return true;
777
+ if (state.gestureType !== gestureType) return true;
778
+ return Date.now() - state.startTime >= this.MIN_GESTURE_INTERVAL;
779
+ }
780
+ startGesture(elementId, gestureType, targetState, controls) {
781
+ const existingState = this.gestureStates.get(elementId);
782
+ if (existingState?.controls) try {
783
+ existingState.controls.stop();
784
+ } catch (e) {}
785
+ this.gestureStates.set(elementId, {
786
+ isAnimating: true,
787
+ gestureType,
788
+ targetState,
789
+ controls,
790
+ startTime: Date.now()
791
+ });
792
+ }
793
+ endGesture(elementId) {
794
+ const state = this.gestureStates.get(elementId);
795
+ if (state) {
796
+ state.isAnimating = false;
797
+ state.gestureType = null;
798
+ state.targetState = null;
799
+ }
800
+ }
801
+ getGestureState(elementId) {
802
+ return this.gestureStates.get(elementId);
803
+ }
804
+ cancelGesture(elementId) {
805
+ const state = this.gestureStates.get(elementId);
806
+ if (state?.controls && state.isAnimating) try {
807
+ state.controls.stop();
808
+ this.endGesture(elementId);
809
+ return true;
810
+ } catch (e) {}
811
+ return false;
812
+ }
813
+ isGestureActive(elementId, gestureType) {
814
+ const state = this.gestureStates.get(elementId);
815
+ if (!state || !state.isAnimating) return false;
816
+ if (gestureType) return state.gestureType === gestureType;
817
+ return true;
818
+ }
819
+ clearElement(elementId) {
820
+ this.cancelGesture(elementId);
821
+ this.gestureStates.delete(elementId);
822
+ }
823
+ clearAll() {
824
+ this.gestureStates.forEach((_, elementId) => {
825
+ this.cancelGesture(elementId);
826
+ });
827
+ this.gestureStates.clear();
828
+ }
829
+ static ɵfac = i0.ɵɵngDeclareFactory({
830
+ minVersion: "12.0.0",
831
+ version: "22.3.2",
832
+ ngImport: i0,
833
+ type: MotionGestureService,
834
+ deps: [],
835
+ target: i0.ɵɵFactoryTarget.Injectable
836
+ });
837
+ static ɵprov = i0.ɵɵngDeclareInjectable({
838
+ minVersion: "12.0.0",
839
+ version: "22.3.2",
840
+ ngImport: i0,
841
+ type: MotionGestureService,
842
+ providedIn: "root"
843
+ });
844
+ };
845
+ i0.ɵɵngDeclareClassMetadata({
846
+ minVersion: "12.0.0",
847
+ version: "22.3.2",
848
+ ngImport: i0,
849
+ type: MotionGestureService,
850
+ decorators: [{
851
+ type: Injectable,
852
+ args: [{ providedIn: "root" }]
853
+ }]
854
+ });
855
+ function isTransformProperty(key) {
856
+ return TRANSFORM_PROPERTIES.includes(key);
857
+ }
858
+ function extractStyleProperties(variant) {
859
+ if (!variant) return {};
860
+ const result = {};
861
+ for (const key in variant) {
862
+ if (EXCLUDED_PROPERTIES.includes(key)) continue;
863
+ if (key === "transform") {
864
+ result["transform"] = variant[key];
865
+ continue;
866
+ }
867
+ if (isTransformProperty(key)) result[key] = variant[key];
868
+ else applyStyleProperty(result, key, variant[key]);
869
+ }
870
+ return result;
871
+ }
872
+ function applyStyleProperty(result, key, value) {
873
+ if (isColorProperty(key)) result[key] = normalizeColorValue(value);
874
+ else result[key] = value;
875
+ }
876
+ const TRANSFORM_ORDER = [
877
+ "transformPerspective",
878
+ "x",
879
+ "y",
880
+ "z",
881
+ "translateX",
882
+ "translateY",
883
+ "translateZ",
884
+ "scale",
885
+ "scaleX",
886
+ "scaleY",
887
+ "rotate",
888
+ "rotateX",
889
+ "rotateY",
890
+ "rotateZ",
891
+ "skew",
892
+ "skewX",
893
+ "skewY"
894
+ ];
895
+ const TRANSFORM_KEYS = new Set(TRANSFORM_ORDER);
896
+ function withUnit(key, value) {
897
+ if (typeof value !== "number") return String(value);
898
+ if (key === "transformPerspective" || key === "x" || key === "y" || key === "z" || key.startsWith("translate")) return `${value}px`;
899
+ if (key.startsWith("rotate") || key.startsWith("skew")) return `${value}deg`;
900
+ return String(value);
901
+ }
902
+ function transformFunction(key, value) {
903
+ const v = withUnit(key, value);
904
+ switch (key) {
905
+ case "transformPerspective": return `perspective(${v})`;
906
+ case "x": return `translateX(${v})`;
907
+ case "y": return `translateY(${v})`;
908
+ case "z": return `translateZ(${v})`;
909
+ default: return `${key}(${v})`;
910
+ }
911
+ }
912
+ function firstFrame(value) {
913
+ return Array.isArray(value) ? value[0] : value;
914
+ }
915
+ function applyInlineStyles(el, styles) {
916
+ if (!el?.style || !styles) return;
917
+ const transforms = [];
918
+ let rawTransform;
919
+ for (const key of Object.keys(styles)) {
920
+ const value = firstFrame(styles[key]);
921
+ if (value === void 0 || value === null) continue;
922
+ if (key === "transform") rawTransform = String(value);
923
+ else if (!TRANSFORM_KEYS.has(key)) el.style[key] = value;
924
+ }
925
+ for (const key of TRANSFORM_ORDER) if (key in styles) {
926
+ const value = firstFrame(styles[key]);
927
+ if (value !== void 0 && value !== null) transforms.push(transformFunction(key, value));
928
+ }
929
+ if (rawTransform !== void 0 || transforms.length > 0) el.style.transform = [rawTransform, ...transforms].filter(Boolean).join(" ");
930
+ }
931
+ function resolveVariant(variant, variants) {
932
+ if (typeof variant === "string") return variants[variant] || {};
933
+ else if (typeof variant === "object" && variant !== null) return variant;
934
+ else return {};
935
+ }
936
+ let uniqueIdCounter = 0;
937
+ const directiveByElement = /* @__PURE__ */ new WeakMap();
938
+ function nearestMotionAncestor(el, stop) {
939
+ for (let node = el.parentElement; node && node !== stop; node = node.parentElement) {
940
+ const found = directiveByElement.get(node);
941
+ if (found) return found;
942
+ }
943
+ }
944
+ var MotionOneDirective = class MotionOneDirective {
945
+ el;
946
+ motionService;
947
+ motionAnimation;
948
+ animationOptions;
949
+ staggerService;
950
+ inViewService;
951
+ timelineService;
952
+ gestureService;
953
+ platformId;
954
+ initial = {};
955
+ animate = {};
956
+ exit = {};
957
+ inView = {};
958
+ duration = MOTION_DEFAULTS.DURATION;
959
+ delay = MOTION_DEFAULTS.DELAY;
960
+ delayChildren = MOTION_DEFAULTS.DELAY_CHILDREN;
961
+ repeat = MOTION_DEFAULTS.REPEAT;
962
+ exitDelay = MOTION_DEFAULTS.EXIT_DELAY;
963
+ easing = MOTION_DEFAULTS.EASING;
964
+ offset = MOTION_DEFAULTS.OFFSET;
965
+ whileHover = {};
966
+ staggerChildren = MOTION_DEFAULTS.STAGGER_CHILDREN;
967
+ staggerDirection = MOTION_DEFAULTS.STAGGER_DIRECTION;
968
+ whileTap = {};
969
+ whileFocus = {};
970
+ whileInView = {};
971
+ runInView;
972
+ variants = {};
973
+ transition = {};
974
+ timeline;
975
+ animationComplete = new EventEmitter();
976
+ restartAnimation() {
977
+ this.cancelForReset();
978
+ const initialStyles = extractStyleProperties(this.getVariant(this.initial));
979
+ const element = this.el.nativeElement;
980
+ element.style.transition = "none";
981
+ this.setInlineStyles(initialStyles);
982
+ element.offsetHeight;
983
+ this.cancelScheduled(this.restartTimer);
984
+ this.restartTimer = this.schedule(() => {
985
+ this.restartTimer = void 0;
986
+ element.style.transition = "";
987
+ if (!this.isRunInViewEnabled) this.playAnimation(this.initial, this.animate);
988
+ }, MOTION_DEFAULTS.RESET_TIMEOUT);
989
+ }
990
+ restartTimer;
991
+ parentMotion = inject(MotionOneDirective, {
992
+ optional: true,
993
+ skipSelf: true
994
+ });
995
+ motionChildren = [];
996
+ childrenInitialized = false;
997
+ pendingFrom = null;
998
+ get childMotionDirectives() {
999
+ return this.motionChildren;
1000
+ }
1001
+ controls = null;
1002
+ childrenControls = [];
1003
+ elementId;
1004
+ hoverTimeout;
1005
+ observer;
1006
+ inViewStop = null;
1007
+ ngZone = inject(NgZone);
1008
+ gestureCleanups = [];
1009
+ attachedGestures = /* @__PURE__ */ new Set();
1010
+ pressEndCleanup = null;
1011
+ isChild = false;
1012
+ parentDirective = null;
1013
+ initialAnimationPlayed = false;
1014
+ _skipStartStylesApplication = false;
1015
+ staggerDelay = void 0;
1016
+ childrenCount = 0;
1017
+ childIndex = 0;
1018
+ isStaggeredChild = false;
1019
+ activeTimeouts = /* @__PURE__ */ new Set();
1020
+ get scrollProgress() {
1021
+ return this.motionService.scrollYProgress();
1022
+ }
1023
+ get isRunInViewEnabled() {
1024
+ return this.runInView === "once" || this.runInView === "always";
1025
+ }
1026
+ get runInViewRepeat() {
1027
+ return this.runInView === "always" ? "always" : "once";
1028
+ }
1029
+ constructor(el, motionService, motionAnimation, animationOptions, staggerService, inViewService, timelineService, gestureService, platformId) {
1030
+ this.el = el;
1031
+ this.motionService = motionService;
1032
+ this.motionAnimation = motionAnimation;
1033
+ this.animationOptions = animationOptions;
1034
+ this.staggerService = staggerService;
1035
+ this.inViewService = inViewService;
1036
+ this.timelineService = timelineService;
1037
+ this.gestureService = gestureService;
1038
+ this.platformId = platformId;
1039
+ this.elementId = `motion-${uniqueIdCounter++}`;
1040
+ this.parentMotion?.motionChildren.push(this);
1041
+ directiveByElement.set(this.el.nativeElement, this);
1042
+ if (isPlatformBrowser(this.platformId)) {
1043
+ if (!this.el.nativeElement.id) this.el.nativeElement.setAttribute("id", this.elementId);
1044
+ this.el.nativeElement._motionDirective = this;
1045
+ this.motionService.registerMotionElement(this);
1046
+ }
1047
+ }
1048
+ setInlineStyles(styles) {
1049
+ if (!styles || Object.keys(styles).length === 0) return;
1050
+ applyInlineStyles(this.el.nativeElement, styles);
1051
+ this.pendingFrom = {
1052
+ ...this.pendingFrom || {},
1053
+ ...styles
1054
+ };
1055
+ }
1056
+ animateSelf(targetStyles, options) {
1057
+ let keyframes = targetStyles;
1058
+ if (this.pendingFrom) {
1059
+ options = {
1060
+ ...options,
1061
+ velocity: 0
1062
+ };
1063
+ keyframes = { ...targetStyles };
1064
+ for (const key of Object.keys(targetStyles)) if (key in this.pendingFrom && !Array.isArray(targetStyles[key])) {
1065
+ const from = this.pendingFrom[key];
1066
+ keyframes[key] = [Array.isArray(from) ? from[0] : from, targetStyles[key]];
1067
+ }
1068
+ this.pendingFrom = null;
1069
+ }
1070
+ this.controls = this.motionAnimation.animate(this.el.nativeElement, keyframes, options);
1071
+ return this.controls;
1072
+ }
1073
+ schedule(fn, ms) {
1074
+ const timeoutId = this.ngZone.runOutsideAngular(() => setTimeout(() => {
1075
+ this.activeTimeouts.delete(timeoutId);
1076
+ fn();
1077
+ }, ms));
1078
+ this.activeTimeouts.add(timeoutId);
1079
+ return timeoutId;
1080
+ }
1081
+ cancelScheduled(timeoutId) {
1082
+ if (timeoutId === void 0 || timeoutId === null) return;
1083
+ clearTimeout(timeoutId);
1084
+ this.activeTimeouts.delete(timeoutId);
1085
+ }
1086
+ emitComplete() {
1087
+ if (this.animationComplete.observed) this.ngZone.run(() => this.animationComplete.emit());
1088
+ }
1089
+ ngOnInit() {
1090
+ this.isChild = !!this.parentMotion && !this.parentMotion.childrenInitialized;
1091
+ this.applyInitialStyles();
1092
+ if (isPlatformBrowser(this.platformId)) {
1093
+ this.syncGestureListeners();
1094
+ if (!this.isChild && !this.isRunInViewEnabled) this.playAnimation(this.initial, this.animate);
1095
+ if (!this.isStaggeredChild && (this.inView && Object.keys(this.inView).length > 0 || this.whileInView && Object.keys(this.whileInView).length > 0)) this.setupInViewAnimation();
1096
+ }
1097
+ }
1098
+ ngAfterContentInit() {
1099
+ if (!isPlatformBrowser(this.platformId)) return;
1100
+ this.schedule(() => this.initChildren(), 0);
1101
+ }
1102
+ initChildren() {
1103
+ if (this.childrenInitialized) return;
1104
+ this.childrenInitialized = true;
1105
+ this.rehomeProjectedChildren();
1106
+ const children = this.motionChildren;
1107
+ this.childrenCount = children.length;
1108
+ children.forEach((child, index) => child.setParent(this, index, children.length));
1109
+ if (this.isRunInViewEnabled && !this.isChild) {
1110
+ children.forEach((child) => child.isStaggeredChild = true);
1111
+ if (this.runInView === "always" && children.length > 0) this.setupRunInViewObserver();
1112
+ else this.setupMotionOneInView();
1113
+ return;
1114
+ }
1115
+ if (children.length === 0) return;
1116
+ if (this.getStaggerValue() === 0) children.forEach((child) => {
1117
+ if (child.isRunInViewEnabled) child.setupInViewAnimation();
1118
+ });
1119
+ else children.forEach((child) => {
1120
+ if (child.isRunInViewEnabled) child.isStaggeredChild = true;
1121
+ });
1122
+ if (!this.isChild && !this.isRunInViewEnabled) this.applyStaggerToChildren();
1123
+ }
1124
+ rehomeProjectedChildren() {
1125
+ const host = this.el.nativeElement;
1126
+ for (const child of [...this.motionChildren]) {
1127
+ const owner = nearestMotionAncestor(child.el.nativeElement, host);
1128
+ if (!owner || owner === this) continue;
1129
+ this.motionChildren.splice(this.motionChildren.indexOf(child), 1);
1130
+ child.parentMotion = owner;
1131
+ owner.adoptChild(child);
1132
+ }
1133
+ }
1134
+ adoptChild(child) {
1135
+ const list = this.motionChildren;
1136
+ const at = list.findIndex((c) => !!(child.el.nativeElement.compareDocumentPosition(c.el.nativeElement) & Node.DOCUMENT_POSITION_FOLLOWING));
1137
+ list.splice(at === -1 ? list.length : at, 0, child);
1138
+ if (this.childrenInitialized) {
1139
+ child.isChild = false;
1140
+ if (child.isRunInViewEnabled) child.setupInViewAnimation();
1141
+ else child.playAnimation(child.initial, child.animate);
1142
+ }
1143
+ }
1144
+ childrenToPlay() {
1145
+ return this.getStaggerValue() === 0 ? this.motionChildren.filter((child) => !child.isRunInViewEnabled || child.isStaggeredChild) : this.motionChildren;
1146
+ }
1147
+ playAsChild() {
1148
+ this.staggerDelay = void 0;
1149
+ try {
1150
+ if (this.motionChildren.length > 0) {
1151
+ this.initChildren();
1152
+ this.applyStaggerToChildren();
1153
+ } else this.playAnimation(this.initial, this.animate);
1154
+ } finally {
1155
+ this.staggerDelay = void 0;
1156
+ }
1157
+ }
1158
+ setParent(parent, index, totalChildren) {
1159
+ this.parentDirective = parent;
1160
+ this.isChild = true;
1161
+ this.childIndex = index;
1162
+ this.childrenCount = totalChildren;
1163
+ }
1164
+ completeResetToInitial() {
1165
+ this.forceResetToInitial();
1166
+ this.motionChildren.forEach((child) => child.completeResetToInitial());
1167
+ }
1168
+ forceResetToInitial() {
1169
+ this.cancelForReset();
1170
+ const initialStyles = extractStyleProperties(this.getVariant(this.initial));
1171
+ this.el.nativeElement.style.transition = "none";
1172
+ this.el.nativeElement.style.opacity = "";
1173
+ this.el.nativeElement.style.transform = "";
1174
+ this.setInlineStyles(initialStyles);
1175
+ this.el.nativeElement.offsetHeight;
1176
+ this.el.nativeElement.style.transition = "";
1177
+ this.initialAnimationPlayed = false;
1178
+ }
1179
+ resetToInitialIfParentHasRunInView() {
1180
+ this.forceResetToInitial();
1181
+ }
1182
+ parentExitViewportReset() {
1183
+ this.completeResetToInitial();
1184
+ }
1185
+ setupRunInViewObserver() {
1186
+ if (!isPlatformBrowser(this.platformId)) return;
1187
+ const observer = this.ngZone.runOutsideAngular(() => this.inViewService.createRunInViewObserver(this.el.nativeElement, () => this.handleViewportEntry(), () => this.handleViewportExit()));
1188
+ if (observer) {
1189
+ this.observer = observer;
1190
+ this.observer.observe(this.el.nativeElement);
1191
+ }
1192
+ }
1193
+ handleViewportEntry() {
1194
+ if (this.motionChildren.length > 0) this.applyStaggerToChildren();
1195
+ else this.playAnimation(this.initial, this.animate);
1196
+ }
1197
+ handleViewportExit() {
1198
+ if (this.runInView === "always") {
1199
+ if (this.motionChildren.length > 0) this.motionChildren.forEach((child) => {
1200
+ if (child.controls) {
1201
+ child.controls.stop();
1202
+ child.controls = null;
1203
+ }
1204
+ child.playAnimation(child.animate, child.initial);
1205
+ child.initialAnimationPlayed = false;
1206
+ });
1207
+ }
1208
+ }
1209
+ applyStaggerToChildren() {
1210
+ const staggerValue = this.getStaggerValue();
1211
+ const staggerDirection = this.getStaggerDirection();
1212
+ const delayChildren = this.animationOptions.getDelayChildren(this.getVariant(this.animate), this.transition, this.delayChildren);
1213
+ const parentDelay = this.transition?.delay ?? 0;
1214
+ const childDirectives = this.childrenToPlay();
1215
+ const childCount = childDirectives.length;
1216
+ const when = this.getWhen();
1217
+ if (when !== "afterChildren") this.runSelfAnimation();
1218
+ childDirectives.forEach((childDirective, index) => {
1219
+ const totalDelay = this.staggerService.calculateChildDelay(index, {
1220
+ childCount,
1221
+ staggerValue,
1222
+ staggerDirection,
1223
+ delayChildren,
1224
+ parentDelay
1225
+ });
1226
+ this.schedule(() => childDirective.playAsChild(), totalDelay * 1e3);
1227
+ });
1228
+ if (when === "afterChildren") {
1229
+ const totalChildrenDuration = this.staggerService.calculateTotalDuration({
1230
+ childCount,
1231
+ staggerValue,
1232
+ staggerDirection,
1233
+ delayChildren,
1234
+ parentDelay
1235
+ });
1236
+ const previous = this.staggerDelay;
1237
+ this.staggerDelay = totalChildrenDuration;
1238
+ this.runSelfAnimation();
1239
+ this.staggerDelay = previous;
1240
+ }
1241
+ }
1242
+ overrideDelay(delay) {
1243
+ this.staggerDelay = delay;
1244
+ }
1245
+ runSelfAnimation() {
1246
+ const options = this.getAnimationOptions();
1247
+ const targetStyles = extractStyleProperties(this.getVariant(this.animate));
1248
+ const startStyles = extractStyleProperties(this.getVariant(this.initial));
1249
+ if (!this.isStaggeredChild) this.setInlineStyles(startStyles);
1250
+ this.animateSelf(targetStyles, options);
1251
+ this.initialAnimationPlayed = true;
1252
+ }
1253
+ ngOnDestroy() {
1254
+ this.activeTimeouts.forEach((timeoutId) => {
1255
+ clearTimeout(timeoutId);
1256
+ });
1257
+ this.activeTimeouts.clear();
1258
+ if (this.hoverTimeout) {
1259
+ clearTimeout(this.hoverTimeout);
1260
+ this.hoverTimeout = null;
1261
+ }
1262
+ this.gestureCleanups.forEach((cleanup) => cleanup());
1263
+ this.gestureCleanups = [];
1264
+ this.attachedGestures.clear();
1265
+ this.pressEndCleanup?.();
1266
+ this.pressEndCleanup = null;
1267
+ this.gestureService.clearElement(this.elementId);
1268
+ this.stopInView();
1269
+ this.inViewService.disconnect(this.observer);
1270
+ this.observer = void 0;
1271
+ if (this.controls) {
1272
+ try {
1273
+ this.controls.stop();
1274
+ } catch (e) {}
1275
+ this.controls = null;
1276
+ }
1277
+ this.childrenControls.forEach((control) => {
1278
+ if (control) try {
1279
+ control.stop();
1280
+ } catch (e) {}
1281
+ });
1282
+ this.childrenControls = [];
1283
+ directiveByElement.delete(this.el.nativeElement);
1284
+ if (this.parentMotion) {
1285
+ const i = this.parentMotion.motionChildren.indexOf(this);
1286
+ if (i !== -1) this.parentMotion.motionChildren.splice(i, 1);
1287
+ }
1288
+ this.motionService.unregisterMotionElement(this);
1289
+ }
1290
+ ngOnChanges(changes) {
1291
+ if (changes["animate"] && changes["animate"].previousValue !== void 0) {
1292
+ const oldState = changes["animate"].previousValue;
1293
+ let newState = changes["animate"].currentValue;
1294
+ if (typeof newState === "object") this.playAnimation(oldState, newState);
1295
+ else if (typeof newState === "string" && this.variants?.[newState]) {
1296
+ newState = this.variants[newState];
1297
+ this.playAnimation(oldState, newState);
1298
+ }
1299
+ }
1300
+ if (changes["transition"] && !changes["transition"].firstChange) this.playAnimation(this.initial, this.animate);
1301
+ if ((changes["whileHover"] || changes["whileTap"] || changes["whileFocus"]) && isPlatformBrowser(this.platformId) && this.gestureListenersReady) this.syncGestureListeners();
1302
+ }
1303
+ gestureListenersReady = false;
1304
+ syncGestureListeners() {
1305
+ this.gestureListenersReady = true;
1306
+ const el = this.el.nativeElement;
1307
+ const listen = (type, handler, options) => {
1308
+ this.ngZone.runOutsideAngular(() => el.addEventListener(type, handler, options));
1309
+ this.gestureCleanups.push(() => el.removeEventListener(type, handler, options));
1310
+ };
1311
+ if (!this.attachedGestures.has("hover") && this.hasKeys(this.whileHover)) {
1312
+ this.attachedGestures.add("hover");
1313
+ listen("mouseenter", () => this.onMouseEnter());
1314
+ listen("mouseleave", () => this.onMouseLeave());
1315
+ }
1316
+ if (!this.attachedGestures.has("tap") && this.hasKeys(this.whileTap)) {
1317
+ this.attachedGestures.add("tap");
1318
+ listen("mousedown", (e) => this.onPress(e));
1319
+ listen("touchstart", (e) => this.onPress(e), { passive: true });
1320
+ }
1321
+ if (!this.attachedGestures.has("focus") && this.hasKeys(this.whileFocus)) {
1322
+ this.attachedGestures.add("focus");
1323
+ listen("focus", () => this.onFocus());
1324
+ listen("blur", () => this.onBlur());
1325
+ }
1326
+ }
1327
+ hasKeys(value) {
1328
+ return !!value && typeof value === "object" && Object.keys(value).length > 0;
1329
+ }
1330
+ cancelForReset() {
1331
+ const cancel = (c) => {
1332
+ if (!c) return;
1333
+ try {
1334
+ typeof c.cancel === "function" ? c.cancel() : c.stop();
1335
+ } catch {}
1336
+ };
1337
+ cancel(this.controls);
1338
+ this.controls = null;
1339
+ this.childrenControls.forEach(cancel);
1340
+ this.childrenControls = [];
1341
+ }
1342
+ stopInView() {
1343
+ if (this.inViewStop) {
1344
+ this.inViewStop();
1345
+ this.inViewStop = null;
1346
+ }
1347
+ }
1348
+ resetToInitialStylesBatch(directives) {
1349
+ const elements = [];
1350
+ directives.forEach((directive) => {
1351
+ directive.cancelForReset();
1352
+ const styles = extractStyleProperties(directive.getVariant(directive.initial));
1353
+ if (Object.keys(styles).length === 0) return;
1354
+ const el = directive.el.nativeElement;
1355
+ el.style.transition = "none";
1356
+ directive.setInlineStyles(styles);
1357
+ elements.push(el);
1358
+ });
1359
+ if (elements.length === 0) return;
1360
+ elements[0].offsetHeight;
1361
+ elements.forEach((el) => el.style.transition = "");
1362
+ }
1363
+ onMouseEnter() {
1364
+ if (Object.keys(this.whileHover).length > 0) {
1365
+ clearTimeout(this.hoverTimeout);
1366
+ if (!this.gestureService.shouldAllowGesture(this.elementId, "hover")) return;
1367
+ this.gestureService.cancelGesture(this.elementId);
1368
+ this.playAnimationToTarget(this.whileHover, "hover");
1369
+ }
1370
+ }
1371
+ onMouseLeave() {
1372
+ if (Object.keys(this.whileHover).length > 0) {
1373
+ clearTimeout(this.hoverTimeout);
1374
+ this.gestureService.cancelGesture(this.elementId);
1375
+ this.hoverTimeout = this.ngZone.runOutsideAngular(() => setTimeout(() => {
1376
+ if (Object.keys(this.animate).length > 0) this.playAnimationToTarget(this.animate);
1377
+ else this.playAnimationToTarget(this.initial);
1378
+ }, 100));
1379
+ }
1380
+ }
1381
+ onPress(event) {
1382
+ if (Object.keys(this.whileTap).length > 0) {
1383
+ if (!this.gestureService.shouldAllowGesture(this.elementId, "tap")) return;
1384
+ this.gestureService.cancelGesture(this.elementId);
1385
+ this.playAnimationToTarget(this.whileTap, "tap");
1386
+ if (isPlatformBrowser(this.platformId)) {
1387
+ const endEvent = event.type === "mousedown" ? "mouseup" : "touchend";
1388
+ this.pressEndCleanup?.();
1389
+ const endListener = () => {
1390
+ this.pressEndCleanup = null;
1391
+ this.gestureService.cancelGesture(this.elementId);
1392
+ if (Object.keys(this.animate).length > 0) this.playAnimationToTarget(this.animate);
1393
+ else this.playAnimationToTarget(this.initial);
1394
+ window.removeEventListener(endEvent, endListener);
1395
+ };
1396
+ this.ngZone.runOutsideAngular(() => window.addEventListener(endEvent, endListener));
1397
+ this.pressEndCleanup = () => window.removeEventListener(endEvent, endListener);
1398
+ }
1399
+ }
1400
+ }
1401
+ onFocus() {
1402
+ if (Object.keys(this.whileFocus).length > 0) {
1403
+ if (!this.gestureService.shouldAllowGesture(this.elementId, "focus")) return;
1404
+ this.gestureService.cancelGesture(this.elementId);
1405
+ this.playAnimationToTarget(this.whileFocus, "focus");
1406
+ }
1407
+ }
1408
+ onBlur() {
1409
+ if (Object.keys(this.whileFocus).length > 0) {
1410
+ this.gestureService.cancelGesture(this.elementId);
1411
+ if (Object.keys(this.animate).length > 0) this.playAnimationToTarget(this.animate);
1412
+ else this.playAnimationToTarget(this.initial);
1413
+ }
1414
+ }
1415
+ applyInitialValues() {
1416
+ this.setInlineStyles(extractStyleProperties(this.getVariant(this.initial)));
1417
+ }
1418
+ applyInitialStyles() {
1419
+ const styles = extractStyleProperties(this.getVariant(this.initial));
1420
+ if (styles && Object.keys(styles).length > 0) {
1421
+ if (this.isRunInViewEnabled && isPlatformBrowser(this.platformId)) {
1422
+ this.el.nativeElement.style.transition = "none";
1423
+ this.setInlineStyles(styles);
1424
+ this.el.nativeElement.offsetHeight;
1425
+ this.el.nativeElement.style.transition = "";
1426
+ } else this.setInlineStyles(styles);
1427
+ }
1428
+ }
1429
+ applyAnimateStyles() {
1430
+ this.setInlineStyles(extractStyleProperties(this.getVariant(this.animate)));
1431
+ }
1432
+ extractStyleProperties(variant) {
1433
+ return extractStyleProperties(variant);
1434
+ }
1435
+ getAnimationOptions(targetState) {
1436
+ return this.animationOptions.getAnimationOptions({
1437
+ targetState,
1438
+ animateState: this.getVariant(this.animate),
1439
+ staggerDelay: this.staggerDelay,
1440
+ transition: this.transition,
1441
+ delay: this.delay,
1442
+ easing: this.easing,
1443
+ duration: this.duration,
1444
+ repeat: this.repeat,
1445
+ onComplete: () => this.emitComplete()
1446
+ });
1447
+ }
1448
+ getStaggerValue() {
1449
+ return this.animationOptions.getStaggerValue(this.getVariant(this.animate), this.transition, this.staggerChildren);
1450
+ }
1451
+ getStaggerDirection() {
1452
+ return this.animationOptions.getStaggerDirection(this.getVariant(this.animate), this.transition, this.staggerDirection);
1453
+ }
1454
+ getWhen() {
1455
+ return this.animationOptions.getWhen(this.getVariant(this.animate), this.transition);
1456
+ }
1457
+ playAnimationToTarget(targetState, gestureType) {
1458
+ if (!targetState || !isPlatformBrowser(this.platformId)) return;
1459
+ const resolvedTargetState = resolveVariant(targetState, this.variants);
1460
+ if (resolvedTargetState.at !== void 0) {
1461
+ this.schedule(() => {
1462
+ this.animateToTarget(resolvedTargetState, gestureType);
1463
+ }, resolvedTargetState.at * 1e3);
1464
+ return;
1465
+ }
1466
+ this.animateToTarget(resolvedTargetState, gestureType);
1467
+ }
1468
+ playAnimation(startState, targetState, gestureType) {
1469
+ if (!targetState || !isPlatformBrowser(this.platformId)) return;
1470
+ resolveVariant(startState || this.initial, this.variants);
1471
+ const resolvedTargetState = resolveVariant(targetState || this.animate, this.variants);
1472
+ if (resolvedTargetState.at !== void 0) {
1473
+ this.schedule(() => {
1474
+ this.continueAnimation(resolvedTargetState, false, gestureType);
1475
+ }, resolvedTargetState.at * 1e3);
1476
+ return;
1477
+ }
1478
+ this.continueAnimation(resolvedTargetState, false, gestureType);
1479
+ }
1480
+ animateToTarget(resolvedTargetState, gestureType) {
1481
+ if (this.timeline && this.timeline.length > 0) {
1482
+ this.runTimeline(resolvedTargetState);
1483
+ return;
1484
+ }
1485
+ const t = resolvedTargetState.transition;
1486
+ if (this.timelineService.isPerPropertyTransition(t)) {
1487
+ this.runPerPropertyAnimations(resolvedTargetState);
1488
+ return;
1489
+ }
1490
+ const options = this.getAnimationOptions(resolvedTargetState);
1491
+ const targetStyles = extractStyleProperties(resolvedTargetState);
1492
+ this.animateSelf(targetStyles, options);
1493
+ if (gestureType) this.gestureService.startGesture(this.elementId, gestureType, typeof resolvedTargetState === "string" ? resolvedTargetState : "custom", this.controls);
1494
+ }
1495
+ continueAnimation(resolvedTargetState, isInitialAnimation, gestureType) {
1496
+ if (this.timeline && this.timeline.length > 0) {
1497
+ this.runTimeline(resolvedTargetState);
1498
+ return;
1499
+ }
1500
+ const t = resolvedTargetState.transition;
1501
+ if (this.timelineService.isPerPropertyTransition(t)) {
1502
+ this.runPerPropertyAnimations(resolvedTargetState);
1503
+ return;
1504
+ }
1505
+ if (isInitialAnimation && !this.initialAnimationPlayed) {
1506
+ if (this.getStaggerValue() > 0 && this.motionChildren.length > 0) {
1507
+ if (this.getWhen() !== "afterChildren") this.runSelfAnimation();
1508
+ return;
1509
+ }
1510
+ }
1511
+ const options = this.getAnimationOptions(resolvedTargetState);
1512
+ const targetStyles = extractStyleProperties(resolvedTargetState);
1513
+ this.animateSelf(targetStyles, options);
1514
+ if (gestureType) this.gestureService.startGesture(this.elementId, gestureType, typeof resolvedTargetState === "string" ? resolvedTargetState : "custom", this.controls);
1515
+ if (isInitialAnimation) this.initialAnimationPlayed = true;
1516
+ }
1517
+ runPerPropertyAnimations(resolvedTargetState) {
1518
+ const baseDelay = this.staggerDelay !== void 0 && this.staggerDelay >= 0 ? this.staggerDelay : resolvedTargetState.transition?.delay ?? this.delay;
1519
+ const result = this.timelineService.runPerPropertyAnimations(this.el.nativeElement, resolvedTargetState, baseDelay, this.duration, this.easing, this.repeat, () => this.emitComplete());
1520
+ this.childrenControls = result.controls;
1521
+ }
1522
+ runTimeline(resolvedTargetState) {
1523
+ const baseDelay = this.staggerDelay !== void 0 && this.staggerDelay >= 0 ? this.staggerDelay : resolvedTargetState.transition?.delay ?? this.delay;
1524
+ const result = this.timelineService.runTimeline(this.el.nativeElement, this.timeline, resolvedTargetState, baseDelay, this.duration, this.easing, this.repeat, () => this.emitComplete());
1525
+ this.childrenControls = result.controls;
1526
+ }
1527
+ setupInViewAnimation() {
1528
+ if (!isPlatformBrowser(this.platformId)) return;
1529
+ try {
1530
+ if (this.isRunInViewEnabled) this.setupMotionOneInView();
1531
+ else {
1532
+ const hasWhileInView = this.whileInView && Object.keys(this.whileInView).length > 0;
1533
+ const hasInView = this.inView && Object.keys(this.inView).length > 0;
1534
+ if (hasWhileInView) this.setupWhileInViewAnimation();
1535
+ else if (hasInView) {
1536
+ this.stopInView();
1537
+ this.inViewStop = this.motionAnimation.inView(this.el.nativeElement, () => this.runInViewAnimation(), {
1538
+ margin: this.offset,
1539
+ amount: "some"
1540
+ });
1541
+ }
1542
+ }
1543
+ } catch (error) {
1544
+ console.error("[ngx-motion] Error setting up inView observer:", error);
1545
+ }
1546
+ }
1547
+ runInViewAnimation() {
1548
+ if (this.inView && Object.keys(this.inView).length > 0) this.playAnimation(this.initial, this.inView);
1549
+ else if (this.whileInView && Object.keys(this.whileInView).length > 0) this.playAnimation(this.initial, this.whileInView);
1550
+ }
1551
+ setupWhileInViewAnimation() {
1552
+ this.stopInView();
1553
+ this.inViewStop = this.motionAnimation.inView(this.el.nativeElement, () => this.playAnimation(this.initial, this.whileInView), {
1554
+ margin: this.offset,
1555
+ amount: "some"
1556
+ });
1557
+ }
1558
+ setupMotionOneInView() {
1559
+ const margin = this.offset || MOTION_DEFAULTS.INVIEW_MARGIN;
1560
+ if (this.motionChildren.length > 0 && !this.isChild) this.setupStaggerParentInView(margin);
1561
+ else if (!this.isStaggeredChild) this.setupIndividualElementInView(margin);
1562
+ }
1563
+ setupStaggerParentInView(margin) {
1564
+ this.stopInView();
1565
+ this.inViewStop = this.motionAnimation.inView(this.el.nativeElement, () => {
1566
+ const childDirectives = this.motionChildren;
1567
+ this.resetToInitialStylesBatch([this, ...childDirectives]);
1568
+ let pending = null;
1569
+ if (childDirectives.length > 0) pending = this.schedule(() => this.applyStaggerToChildren(), MOTION_DEFAULTS.STAGGER_TIMEOUT);
1570
+ if (this.runInViewRepeat === "always") return () => {
1571
+ this.cancelScheduled(pending);
1572
+ this.resetToInitialStylesBatch([this, ...childDirectives]);
1573
+ };
1574
+ }, {
1575
+ margin,
1576
+ amount: .1
1577
+ });
1578
+ }
1579
+ setupIndividualElementInView(margin) {
1580
+ this.stopInView();
1581
+ this.inViewStop = this.motionAnimation.inView(this.el.nativeElement, () => {
1582
+ this.resetToInitialStylesBatch([this]);
1583
+ const pending = this.schedule(() => {
1584
+ this.playAnimation(this.initial, this.animate);
1585
+ }, MOTION_DEFAULTS.STAGGER_TIMEOUT);
1586
+ if (this.runInViewRepeat === "always") return () => {
1587
+ this.cancelScheduled(pending);
1588
+ this.resetToInitialStylesBatch([this]);
1589
+ };
1590
+ }, {
1591
+ margin,
1592
+ amount: .1
1593
+ });
1594
+ }
1595
+ runInitAnimation() {
1596
+ if (!isPlatformBrowser(this.platformId) || !this.initial || !this.animate) return;
1597
+ if (this.isChild && this.staggerDelay !== void 0 && this.staggerDelay >= 0) {
1598
+ if (!this._skipStartStylesApplication) {
1599
+ const startStyles = extractStyleProperties(this.getVariant(this.initial));
1600
+ const element = this.el.nativeElement;
1601
+ element.style.transition = "none";
1602
+ this.setInlineStyles(startStyles);
1603
+ } else this._skipStartStylesApplication = false;
1604
+ this.el.nativeElement.offsetHeight;
1605
+ this.schedule(() => {
1606
+ this.el.nativeElement.style.transition = "";
1607
+ this.playAnimation(this.initial, this.animate);
1608
+ }, 5);
1609
+ this.initialAnimationPlayed = true;
1610
+ } else this.playAnimation(this.initial, this.animate);
1611
+ }
1612
+ runExitAnimation() {
1613
+ if (!isPlatformBrowser(this.platformId)) return Promise.resolve();
1614
+ if (!this.exit || Object.keys(this.exit).length === 0) return Promise.resolve();
1615
+ const exitTransition = this.getVariant(this.exit).transition || this.transition || {};
1616
+ return new Promise((resolve) => {
1617
+ const exitOptions = {
1618
+ duration: exitTransition.duration ?? this.duration,
1619
+ delay: exitTransition.delay ?? this.exitDelay,
1620
+ onComplete: () => {
1621
+ this.emitComplete();
1622
+ resolve();
1623
+ }
1624
+ };
1625
+ const options = this.animationOptions.getAnimationOptions({
1626
+ targetState: this.getVariant(this.exit),
1627
+ transition: this.transition,
1628
+ delay: this.delay,
1629
+ easing: this.easing,
1630
+ duration: this.duration,
1631
+ repeat: this.repeat
1632
+ });
1633
+ exitOptions.easing = options.easing || options.ease;
1634
+ exitOptions.ease = options.ease || options.easing;
1635
+ if (this.controls) this.controls.stop();
1636
+ this.childrenControls.forEach((control) => {
1637
+ if (control) control.stop();
1638
+ });
1639
+ const exitStyles = extractStyleProperties(this.getVariant(this.exit));
1640
+ this.animateSelf(exitStyles, exitOptions);
1641
+ if (!exitOptions.duration) resolve();
1642
+ });
1643
+ }
1644
+ cancel() {
1645
+ if (this.controls) this.controls.stop();
1646
+ this.childrenControls.forEach((control) => {
1647
+ if (control) control.stop();
1648
+ });
1649
+ this.applyAnimateStyles();
1650
+ }
1651
+ getDuration() {
1652
+ if (!isPlatformBrowser(this.platformId)) return 0;
1653
+ try {
1654
+ const animateTransition = this.getVariant(this.exit)?.transition || this.transition || {};
1655
+ const duration = animateTransition.duration ?? this.duration;
1656
+ const delay = animateTransition.delay ?? this.delay;
1657
+ return (Number(duration) + Number(delay)) * 1e3;
1658
+ } catch (error) {
1659
+ console.error("Error calculating duration:", error);
1660
+ return 0;
1661
+ }
1662
+ }
1663
+ getKeyByValue(object, key) {
1664
+ return Object.keys(object).find((k) => object[k] === key);
1665
+ }
1666
+ triggerExitAnimation() {
1667
+ return this.runExitAnimation();
1668
+ }
1669
+ onMotionExit() {
1670
+ this.runExitAnimation();
1671
+ }
1672
+ getVariant(variant) {
1673
+ return resolveVariant(variant, this.variants);
1674
+ }
1675
+ static ɵfac = i0.ɵɵngDeclareFactory({
1676
+ minVersion: "12.0.0",
1677
+ version: "22.3.2",
1678
+ ngImport: i0,
1679
+ type: MotionOneDirective,
1680
+ deps: [
1681
+ { token: ElementRef },
1682
+ { token: MotionOneService },
1683
+ { token: MotionAnimationService },
1684
+ { token: MotionAnimationOptionsService },
1685
+ { token: MotionStaggerService },
1686
+ { token: MotionInViewService },
1687
+ { token: MotionTimelineService },
1688
+ { token: MotionGestureService },
1689
+ { token: PLATFORM_ID }
1690
+ ],
1691
+ target: i0.ɵɵFactoryTarget.Directive
1692
+ });
1693
+ static ɵdir = i0.ɵɵngDeclareDirective({
1694
+ minVersion: "14.0.0",
1695
+ version: "22.3.2",
1696
+ type: MotionOneDirective,
1697
+ isStandalone: true,
1698
+ selector: "[motionone]",
1699
+ inputs: {
1700
+ initial: "initial",
1701
+ animate: "animate",
1702
+ exit: "exit",
1703
+ inView: "inView",
1704
+ duration: "duration",
1705
+ delay: "delay",
1706
+ delayChildren: "delayChildren",
1707
+ repeat: "repeat",
1708
+ exitDelay: "exitDelay",
1709
+ easing: "easing",
1710
+ offset: "offset",
1711
+ whileHover: "whileHover",
1712
+ staggerChildren: "staggerChildren",
1713
+ staggerDirection: "staggerDirection",
1714
+ whileTap: "whileTap",
1715
+ whileFocus: "whileFocus",
1716
+ whileInView: "whileInView",
1717
+ runInView: "runInView",
1718
+ variants: "variants",
1719
+ transition: "transition",
1720
+ timeline: "timeline"
1721
+ },
1722
+ outputs: { animationComplete: "animationComplete" },
1723
+ host: { listeners: { "motionExit": "onMotionExit()" } },
1724
+ exportAs: ["motionone"],
1725
+ usesOnChanges: true,
1726
+ ngImport: i0
1727
+ });
1728
+ };
1729
+ i0.ɵɵngDeclareClassMetadata({
1730
+ minVersion: "12.0.0",
1731
+ version: "22.3.2",
1732
+ ngImport: i0,
1733
+ type: MotionOneDirective,
1734
+ decorators: [{
1735
+ type: Directive,
1736
+ args: [{
1737
+ selector: "[motionone]",
1738
+ standalone: true,
1739
+ exportAs: "motionone"
1740
+ }]
1741
+ }],
1742
+ ctorParameters: () => [
1743
+ { type: ElementRef },
1744
+ { type: MotionOneService },
1745
+ { type: MotionAnimationService },
1746
+ { type: MotionAnimationOptionsService },
1747
+ { type: MotionStaggerService },
1748
+ { type: MotionInViewService },
1749
+ { type: MotionTimelineService },
1750
+ { type: MotionGestureService },
1751
+ {
1752
+ type: Object,
1753
+ decorators: [{
1754
+ type: Inject,
1755
+ args: [PLATFORM_ID]
1756
+ }]
1757
+ }
1758
+ ],
1759
+ propDecorators: {
1760
+ initial: [{ type: Input }],
1761
+ animate: [{ type: Input }],
1762
+ exit: [{ type: Input }],
1763
+ inView: [{ type: Input }],
1764
+ duration: [{ type: Input }],
1765
+ delay: [{ type: Input }],
1766
+ delayChildren: [{ type: Input }],
1767
+ repeat: [{ type: Input }],
1768
+ exitDelay: [{ type: Input }],
1769
+ easing: [{ type: Input }],
1770
+ offset: [{ type: Input }],
1771
+ whileHover: [{ type: Input }],
1772
+ staggerChildren: [{ type: Input }],
1773
+ staggerDirection: [{ type: Input }],
1774
+ whileTap: [{ type: Input }],
1775
+ whileFocus: [{ type: Input }],
1776
+ whileInView: [{ type: Input }],
1777
+ runInView: [{ type: Input }],
1778
+ variants: [{ type: Input }],
1779
+ transition: [{ type: Input }],
1780
+ timeline: [{ type: Input }],
1781
+ animationComplete: [{ type: Output }],
1782
+ onMotionExit: [{
1783
+ type: HostListener,
1784
+ args: ["motionExit"]
1785
+ }]
1786
+ }
1787
+ });
1788
+ var MotionIfDirective = class MotionIfDirective {
1789
+ templateRef;
1790
+ viewContainer;
1791
+ cdr;
1792
+ hasView = false;
1793
+ currentView = null;
1794
+ motionDirectives = [];
1795
+ exitTimeout;
1796
+ constructor(templateRef, viewContainer, cdr) {
1797
+ this.templateRef = templateRef;
1798
+ this.viewContainer = viewContainer;
1799
+ this.cdr = cdr;
1800
+ }
1801
+ exiting = false;
1802
+ set motionIf(condition) {
1803
+ if (condition) {
1804
+ if (this.exiting) this.cancelExit();
1805
+ else if (!this.hasView) this.enter();
1806
+ } else if (this.hasView && !this.exiting) this.exit();
1807
+ }
1808
+ enter() {
1809
+ this.currentView = this.viewContainer.createEmbeddedView(this.templateRef);
1810
+ this.hasView = true;
1811
+ this.cdr.detectChanges();
1812
+ }
1813
+ cancelExit() {
1814
+ if (this.exitTimeout) {
1815
+ clearTimeout(this.exitTimeout);
1816
+ this.exitTimeout = null;
1817
+ }
1818
+ this.exiting = false;
1819
+ this.motionDirectives.filter((directive) => directive.exit && Object.keys(directive.exit).length > 0).forEach((directive) => directive.runInitAnimation());
1820
+ }
1821
+ exit() {
1822
+ if (!this.hasView || !this.currentView) return;
1823
+ this.motionDirectives = this.findMotionDirectives(this.currentView);
1824
+ const directivesWithExit = this.motionDirectives.filter((directive) => directive.exit && Object.keys(directive.exit).length > 0);
1825
+ if (directivesWithExit.length > 0) {
1826
+ this.exiting = true;
1827
+ directivesWithExit.forEach((directive) => directive.runExitAnimation());
1828
+ const maxDuration = Math.max(...directivesWithExit.map((d) => d.getDuration()), 300);
1829
+ if (this.exitTimeout) clearTimeout(this.exitTimeout);
1830
+ this.exitTimeout = setTimeout(() => {
1831
+ this.exitTimeout = null;
1832
+ this.clearView();
1833
+ }, maxDuration);
1834
+ } else this.clearView();
1835
+ }
1836
+ clearView() {
1837
+ if (this.hasView) {
1838
+ this.viewContainer.clear();
1839
+ this.hasView = false;
1840
+ this.exiting = false;
1841
+ this.currentView = null;
1842
+ this.motionDirectives = [];
1843
+ }
1844
+ }
1845
+ findMotionDirectives(view) {
1846
+ if (!view) return [];
1847
+ const directives = [];
1848
+ view.rootNodes.forEach((node) => {
1849
+ if (node?._motionDirective) directives.push(node._motionDirective);
1850
+ if (node?.querySelectorAll) node.querySelectorAll("[motionone]").forEach((el) => {
1851
+ if (el._motionDirective) directives.push(el._motionDirective);
1852
+ });
1853
+ });
1854
+ return directives;
1855
+ }
1856
+ ngOnDestroy() {
1857
+ if (this.exitTimeout) clearTimeout(this.exitTimeout);
1858
+ this.clearView();
1859
+ }
1860
+ static ɵfac = i0.ɵɵngDeclareFactory({
1861
+ minVersion: "12.0.0",
1862
+ version: "22.3.2",
1863
+ ngImport: i0,
1864
+ type: MotionIfDirective,
1865
+ deps: [
1866
+ { token: TemplateRef },
1867
+ { token: ViewContainerRef },
1868
+ { token: ChangeDetectorRef }
1869
+ ],
1870
+ target: i0.ɵɵFactoryTarget.Directive
1871
+ });
1872
+ static ɵdir = i0.ɵɵngDeclareDirective({
1873
+ minVersion: "14.0.0",
1874
+ version: "22.3.2",
1875
+ type: MotionIfDirective,
1876
+ isStandalone: true,
1877
+ selector: "[motionIf]",
1878
+ inputs: { motionIf: "motionIf" },
1879
+ ngImport: i0
1880
+ });
1881
+ };
1882
+ i0.ɵɵngDeclareClassMetadata({
1883
+ minVersion: "12.0.0",
1884
+ version: "22.3.2",
1885
+ ngImport: i0,
1886
+ type: MotionIfDirective,
1887
+ decorators: [{
1888
+ type: Directive,
1889
+ args: [{
1890
+ selector: "[motionIf]",
1891
+ standalone: true
1892
+ }]
1893
+ }],
1894
+ ctorParameters: () => [
1895
+ { type: TemplateRef },
1896
+ { type: ViewContainerRef },
1897
+ { type: ChangeDetectorRef }
1898
+ ],
1899
+ propDecorators: { motionIf: [{ type: Input }] }
1900
+ });
1901
+ var MotionPresenceDirective = class MotionPresenceDirective {
1902
+ templateRef;
1903
+ viewContainer;
1904
+ cdr;
1905
+ hasView = false;
1906
+ currentView = null;
1907
+ exitTimeout;
1908
+ destroyRef = inject(DestroyRef);
1909
+ motionPresenceOnEnter;
1910
+ motionPresenceOnExit;
1911
+ constructor(templateRef, viewContainer, cdr) {
1912
+ this.templateRef = templateRef;
1913
+ this.viewContainer = viewContainer;
1914
+ this.cdr = cdr;
1915
+ this.destroyRef.onDestroy(() => {
1916
+ if (this.exitTimeout) clearTimeout(this.exitTimeout);
1917
+ });
1918
+ }
1919
+ exiting = false;
1920
+ exitId = 0;
1921
+ set motionPresence(condition) {
1922
+ if (condition) {
1923
+ if (this.exiting) this.cancelExit();
1924
+ else if (!this.hasView) this.enter();
1925
+ } else if (this.hasView && !this.exiting) this.exit();
1926
+ }
1927
+ enter() {
1928
+ this.currentView = this.viewContainer.createEmbeddedView(this.templateRef);
1929
+ this.hasView = true;
1930
+ this.cdr.detectChanges();
1931
+ if (this.motionPresenceOnEnter) {
1932
+ const view = this.currentView;
1933
+ this.exitTimeout = setTimeout(() => {
1934
+ this.exitTimeout = null;
1935
+ if (this.currentView === view && !this.exiting) this.motionPresenceOnEnter?.();
1936
+ }, 0);
1937
+ }
1938
+ }
1939
+ cancelExit() {
1940
+ this.exitId++;
1941
+ this.exiting = false;
1942
+ this.motionPresenceOnEnter?.();
1943
+ this.findMotionDirectives(this.currentView).filter((directive) => directive.exit && Object.keys(directive.exit).length > 0).forEach((directive) => directive.runInitAnimation());
1944
+ }
1945
+ async exit() {
1946
+ if (!this.hasView || !this.currentView) return;
1947
+ const exitId = ++this.exitId;
1948
+ this.exiting = true;
1949
+ const exitPromises = this.findMotionDirectives(this.currentView).filter((directive) => directive.exit && Object.keys(directive.exit).length > 0).map((directive) => directive.runExitAnimation());
1950
+ if (exitPromises.length > 0) await Promise.all(exitPromises);
1951
+ if (this.motionPresenceOnExit && exitId === this.exitId) await this.motionPresenceOnExit();
1952
+ if (exitId !== this.exitId || !this.exiting) return;
1953
+ this.viewContainer.clear();
1954
+ this.hasView = false;
1955
+ this.exiting = false;
1956
+ this.currentView = null;
1957
+ }
1958
+ findMotionDirectives(view) {
1959
+ if (!view) return [];
1960
+ const directives = [];
1961
+ view.rootNodes.forEach((node) => {
1962
+ if (node?._motionDirective) directives.push(node._motionDirective);
1963
+ if (node?.querySelectorAll) node.querySelectorAll("[motionone]").forEach((el) => {
1964
+ if (el._motionDirective) directives.push(el._motionDirective);
1965
+ });
1966
+ });
1967
+ return directives;
1968
+ }
1969
+ static ɵfac = i0.ɵɵngDeclareFactory({
1970
+ minVersion: "12.0.0",
1971
+ version: "22.3.2",
1972
+ ngImport: i0,
1973
+ type: MotionPresenceDirective,
1974
+ deps: [
1975
+ { token: TemplateRef },
1976
+ { token: ViewContainerRef },
1977
+ { token: ChangeDetectorRef }
1978
+ ],
1979
+ target: i0.ɵɵFactoryTarget.Directive
1980
+ });
1981
+ static ɵdir = i0.ɵɵngDeclareDirective({
1982
+ minVersion: "14.0.0",
1983
+ version: "22.3.2",
1984
+ type: MotionPresenceDirective,
1985
+ isStandalone: true,
1986
+ selector: "[motionPresence]",
1987
+ inputs: {
1988
+ motionPresenceOnEnter: "motionPresenceOnEnter",
1989
+ motionPresenceOnExit: "motionPresenceOnExit",
1990
+ motionPresence: "motionPresence"
1991
+ },
1992
+ ngImport: i0
1993
+ });
1994
+ };
1995
+ i0.ɵɵngDeclareClassMetadata({
1996
+ minVersion: "12.0.0",
1997
+ version: "22.3.2",
1998
+ ngImport: i0,
1999
+ type: MotionPresenceDirective,
2000
+ decorators: [{
2001
+ type: Directive,
2002
+ args: [{
2003
+ selector: "[motionPresence]",
2004
+ standalone: true
2005
+ }]
2006
+ }],
2007
+ ctorParameters: () => [
2008
+ { type: TemplateRef },
2009
+ { type: ViewContainerRef },
2010
+ { type: ChangeDetectorRef }
2011
+ ],
2012
+ propDecorators: {
2013
+ motionPresenceOnEnter: [{ type: Input }],
2014
+ motionPresenceOnExit: [{ type: Input }],
2015
+ motionPresence: [{ type: Input }]
2016
+ }
2017
+ });
2018
+ export { MotionAnimationService, MotionIfDirective, MotionOneDirective, MotionOneService, MotionPresenceDirective };
2019
+
2020
+ //# sourceMappingURL=hilux-ngx-motion.mjs.map