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