pagewave 1.0.3 → 1.0.5

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.
@@ -0,0 +1,126 @@
1
+ type DirectionType = "normal" | "reverse";
2
+
3
+ type OptionsType = {
4
+ mainContentIdName: string;
5
+ pageAnimationDelay: number;
6
+ runAnimationOnPageReload: boolean;
7
+ runAnimationOnCrossSite: boolean;
8
+ pageRevealDelay: number;
9
+ leavePageOnLink: boolean;
10
+ pageBlockerId: string;
11
+ classToIgnoreLink: string;
12
+ animateIgnoredLinks: boolean;
13
+ animateSelfLink: boolean;
14
+ loadEvent: "DOMContentLoaded" | "load";
15
+ preferIgnore: boolean;
16
+ };
17
+
18
+ type TimingType = "linear" | "ease" | "ease-in" | "ease-out" | "ease-in-out" | "step-start" | "step-end";
19
+
20
+ interface TransitionStyle {
21
+ duration: number;
22
+ timing?: string;
23
+ handle(direction: DirectionType, mainElement: HTMLElement): void;
24
+ hidePage(options: OptionsType): void;
25
+ revealPage(options: OptionsType): void;
26
+ }
27
+
28
+ declare class KeyFrameBase implements TransitionStyle {
29
+ duration: number;
30
+ timing: TimingType;
31
+ constructor(duration: number, timing?: TimingType);
32
+ handle(direction: DirectionType, mainElement: HTMLElement): void;
33
+ hidePage(options: OptionsType): void;
34
+ revealPage(options: OptionsType): void;
35
+ protected waitForElementLoad(selector: string, functionToExecute: (element: HTMLElement) => void): void;
36
+ protected ApplyAnimation(element: HTMLElement, animationName: string, duration: number, timing: TimingType, direction: DirectionType): void;
37
+ }
38
+
39
+ declare class KeyFrameCustom extends KeyFrameBase {
40
+ animationName: string;
41
+ constructor(animationName: string, duration: number, timing?: TimingType);
42
+ handle(direction: DirectionType, mainElement: HTMLElement): void;
43
+ }
44
+
45
+ type KeyFrameType = "fade" | "fadeaway" | "fadetoleft" | "fadetoright";
46
+
47
+ declare class KeyFramePreset extends KeyFrameCustom {
48
+ constructor(kfType: KeyFrameType, duration: number, timing?: TimingType);
49
+ handle(direction: DirectionType, mainElement: HTMLElement): void;
50
+ }
51
+
52
+ declare class MultiElementAnimation extends KeyFrameBase {
53
+ animateableObjects: {
54
+ [selector: string]: string;
55
+ };
56
+ mainElementAnimation: string;
57
+ constructor(animateableObjects: {
58
+ [selector: string]: string;
59
+ }, duration: number, timing?: TimingType, mainElementAnimation?: string);
60
+ handle(direction: DirectionType, mainElement: HTMLElement): void;
61
+ }
62
+
63
+ declare class OverlayBase implements TransitionStyle {
64
+ duration: number;
65
+ timing: TimingType;
66
+ color: string;
67
+ constructor(duration: number, color: string, timing?: TimingType);
68
+ handle(direction: DirectionType, mainElement: HTMLElement): void;
69
+ hidePage(options: OptionsType): void;
70
+ revealPage(options: OptionsType): void;
71
+ private waitForElementLoad;
72
+ }
73
+
74
+ declare class OverlayCustom extends OverlayBase {
75
+ divAnimationObject: Record<string, string>;
76
+ mainElementAnimation: KeyFrameBase | null;
77
+ constructor(divAnimationObject: Record<string, string>, duration: number, color: string, timing?: TimingType, mainElementAnimation?: KeyFrameBase | null);
78
+ handle(direction: DirectionType, mainElement: HTMLElement): void;
79
+ }
80
+
81
+ type OverlayType = "slide" | "inverseSlide" | "curtain" | "rise" | "fall" | "bubble" | "wipe";
82
+
83
+ declare class OverlayPreset extends OverlayCustom {
84
+ constructor(oType: OverlayType, duration: number, color: string, timing?: TimingType);
85
+ handle(direction: DirectionType, mainElement: HTMLElement): void;
86
+ }
87
+
88
+ type OverlayStyledDiv = {
89
+ animationName: string;
90
+ cssDesign: Partial<Record<keyof CSSStyleDeclaration, string>>;
91
+ };
92
+ declare class OverlayStyled extends OverlayBase {
93
+ divAnimationObject: Record<string, OverlayStyledDiv>;
94
+ mainElementAnimation: KeyFrameBase | null;
95
+ blockerDesign: Partial<Record<keyof CSSStyleDeclaration, string>>;
96
+ constructor(divAnimationObject: Record<string, OverlayStyledDiv>, duration: number, color: string, timing?: TimingType, mainElementAnimation?: KeyFrameBase | null, blockerDesign?: Partial<Record<keyof CSSStyleDeclaration, string>>);
97
+ hidePage(options: OptionsType): void;
98
+ handle(direction: DirectionType, mainElement: HTMLElement): void;
99
+ }
100
+
101
+ declare class PageWave {
102
+ defaultOptions: OptionsType;
103
+ finalOptions: OptionsType;
104
+ routeTransitions: Record<string, TransitionStyle>;
105
+ constructor(transitions: Record<string, TransitionStyle>, options?: {});
106
+ private CallHook;
107
+ private isNavigationFromSameSite;
108
+ private isInternalLink;
109
+ private HandleClickAnimation;
110
+ ListenForChange(defaultTransitionStyle: TransitionStyle, leaveFunction?: (link: string) => void): void;
111
+ SendPoint(defaultTransitionStyle: TransitionStyle, leaveFunction?: (link: string) => void, externalLeaveFunction?: (link: string) => void): void;
112
+ getStorageRouteTransition(defaultTransitionStyle: TransitionStyle): TransitionStyle;
113
+ EndPoint(defaultTransitionStyle: TransitionStyle): void;
114
+ CallEndPoint(): void;
115
+ AnimatePageTransition(aStyle: TransitionStyle, direction?: DirectionType): void;
116
+ }
117
+
118
+ declare class StyleTransition extends KeyFrameBase {
119
+ styleString: keyof CSSStyleDeclaration;
120
+ startValue: string;
121
+ endValue: string;
122
+ constructor(styleString: keyof CSSStyleDeclaration, duration: number, startValue: string, endValue: string, timing?: TimingType);
123
+ handle(direction: DirectionType, mainElement: HTMLElement): void;
124
+ }
125
+
126
+ export { type DirectionType, KeyFrameBase, KeyFrameCustom, KeyFramePreset, type KeyFrameType, MultiElementAnimation, type OptionsType, OverlayBase, OverlayCustom, OverlayPreset, OverlayStyled, type OverlayStyledDiv, type OverlayType, PageWave, StyleTransition, type TimingType, type TransitionStyle };
package/dist/index.js ADDED
@@ -0,0 +1,573 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ KeyFrameBase: () => KeyFrameBase,
24
+ KeyFrameCustom: () => KeyFrameCustom,
25
+ KeyFramePreset: () => KeyFramePreset,
26
+ MultiElementAnimation: () => MultiElementAnimation,
27
+ OverlayBase: () => OverlayBase,
28
+ OverlayCustom: () => OverlayCustom,
29
+ OverlayPreset: () => OverlayPreset,
30
+ OverlayStyled: () => OverlayStyled,
31
+ PageWave: () => PageWave,
32
+ StyleTransition: () => StyleTransition
33
+ });
34
+ module.exports = __toCommonJS(index_exports);
35
+
36
+ // src/classes/KeyFrameBase.ts
37
+ var KeyFrameBase = class {
38
+ duration;
39
+ timing;
40
+ constructor(duration, timing = "linear") {
41
+ this.duration = duration;
42
+ this.timing = timing;
43
+ }
44
+ handle(direction, mainElement) {
45
+ }
46
+ hidePage(options) {
47
+ for (const ele of document.getElementsByClassName("pagewave-overlay-div")) {
48
+ ele.remove();
49
+ }
50
+ const mainContent = document.getElementById(options.mainContentIdName);
51
+ if (mainContent) {
52
+ mainContent.hidden = true;
53
+ } else {
54
+ this.waitForElementLoad(
55
+ `#${options.mainContentIdName}`,
56
+ (element) => {
57
+ element.hidden = true;
58
+ }
59
+ );
60
+ }
61
+ }
62
+ revealPage(options) {
63
+ const mainContent = document.getElementById(options.mainContentIdName);
64
+ if (mainContent) {
65
+ mainContent.hidden = false;
66
+ } else {
67
+ this.waitForElementLoad(
68
+ `#${options.mainContentIdName}`,
69
+ (element) => {
70
+ element.hidden = false;
71
+ }
72
+ );
73
+ }
74
+ }
75
+ waitForElementLoad(selector, functionToExecute) {
76
+ const existingElement = document.querySelector(selector);
77
+ if (existingElement != null) {
78
+ functionToExecute(existingElement);
79
+ return;
80
+ }
81
+ const observer = new MutationObserver((mutations) => {
82
+ mutations.forEach((mutation) => {
83
+ mutation.addedNodes.forEach((node) => {
84
+ if (node.nodeType === Node.ELEMENT_NODE) {
85
+ const element = node;
86
+ if (element.matches(selector)) {
87
+ observer.disconnect();
88
+ functionToExecute(element);
89
+ }
90
+ }
91
+ });
92
+ });
93
+ });
94
+ observer.observe(document.body, { childList: true, subtree: true });
95
+ }
96
+ ApplyAnimation(element, animationName, duration, timing, direction) {
97
+ element.style.animation = `${animationName} ${duration}ms ${timing} both ${direction}`;
98
+ setTimeout(() => {
99
+ element.style.animation = "";
100
+ if (direction == "normal") {
101
+ element.hidden = true;
102
+ }
103
+ }, duration);
104
+ if (direction == "reverse") {
105
+ let handleAnimation2 = function(event) {
106
+ if (event.animationName == animationName && currentAnimation != null) {
107
+ const animationKeyframes = currentAnimation.effect;
108
+ const kfValues = Object.values(animationKeyframes.getKeyframes()[0]);
109
+ const kfKeys = Object.keys(animationKeyframes.getKeyframes()[0]);
110
+ const animationProperties = kfValues.slice(3, kfValues.length - 1);
111
+ const animationKeys = kfKeys.slice(3, kfValues.length - 1);
112
+ for (let i = 0; i < animationKeys.length; i++) {
113
+ const animationKey = animationKeys[i].toString();
114
+ const animationProperty = animationProperties[i].toString();
115
+ element.style.setProperty(animationKey, animationProperty);
116
+ }
117
+ element.style.animation = "";
118
+ element.removeEventListener("animationend", handleAnimation2);
119
+ }
120
+ };
121
+ var handleAnimation = handleAnimation2;
122
+ let currentAnimation = null;
123
+ element.getAnimations().forEach((animation) => {
124
+ if (currentAnimation == null && animation.id == animationName) {
125
+ currentAnimation = animation;
126
+ }
127
+ });
128
+ element.addEventListener("animationend", handleAnimation2);
129
+ }
130
+ }
131
+ };
132
+
133
+ // src/classes/KeyFrameCustom.ts
134
+ var KeyFrameCustom = class extends KeyFrameBase {
135
+ animationName;
136
+ constructor(animationName, duration, timing = "linear") {
137
+ super(duration, timing);
138
+ this.animationName = animationName;
139
+ }
140
+ handle(direction, mainElement) {
141
+ mainElement.hidden = false;
142
+ this.ApplyAnimation(mainElement, this.animationName, this.duration, this.timing, direction);
143
+ }
144
+ };
145
+
146
+ // src/classes/KeyFramePreset.ts
147
+ var KeyFramePreset = class extends KeyFrameCustom {
148
+ constructor(kfType, duration, timing = "linear") {
149
+ const animationMap = {
150
+ fade: "fade",
151
+ fadeaway: "fadeaway",
152
+ fadetoleft: "fadetoleft",
153
+ fadetoright: "fadetoright"
154
+ };
155
+ super(animationMap[kfType], duration, timing);
156
+ }
157
+ handle(direction, mainElement) {
158
+ super.handle(direction, mainElement);
159
+ }
160
+ };
161
+
162
+ // src/classes/MultiElementAnimation.ts
163
+ var MultiElementAnimation = class extends KeyFrameBase {
164
+ animateableObjects;
165
+ mainElementAnimation;
166
+ constructor(animateableObjects, duration, timing = "linear", mainElementAnimation = "") {
167
+ super(duration, timing);
168
+ this.animateableObjects = animateableObjects;
169
+ this.mainElementAnimation = mainElementAnimation;
170
+ }
171
+ handle(direction, mainElement) {
172
+ let timing = this.timing;
173
+ for (const [selector, animationName] of Object.entries(this.animateableObjects)) {
174
+ mainElement.querySelectorAll(selector).forEach(
175
+ (element) => {
176
+ this.ApplyAnimation(element, animationName, this.duration, timing, direction);
177
+ }
178
+ );
179
+ }
180
+ if (this.mainElementAnimation != "") {
181
+ this.ApplyAnimation(mainElement, this.mainElementAnimation, this.duration, timing, direction);
182
+ }
183
+ }
184
+ };
185
+
186
+ // src/classes/OverlayBase.ts
187
+ var OverlayBase = class {
188
+ duration;
189
+ timing;
190
+ color;
191
+ constructor(duration, color, timing = "linear") {
192
+ this.duration = duration;
193
+ this.color = color;
194
+ this.timing = timing;
195
+ }
196
+ handle(direction, mainElement) {
197
+ }
198
+ hidePage(options) {
199
+ const mainContent = document.getElementById(options.mainContentIdName);
200
+ if (document.getElementById(options.pageBlockerId)) {
201
+ const pageBlockerElement = document.getElementById(options.pageBlockerId);
202
+ pageBlockerElement.style.cssText = `position: absolute; width: 100%; height: 100%; z-index: 100; top: 0; background-color: ${this.color}`;
203
+ return;
204
+ }
205
+ for (const ele of document.getElementsByClassName("pagewave-overlay-div")) {
206
+ ele.remove();
207
+ }
208
+ const pageBlocker = document.createElement("div");
209
+ pageBlocker.id = options.pageBlockerId;
210
+ pageBlocker.style.cssText = `position: absolute; width: 100%; height: 100%; z-index: 100; top: 0; background-color: ${this.color}`;
211
+ mainContent.append(pageBlocker);
212
+ }
213
+ revealPage(options) {
214
+ const pageBlocker = document.getElementById(options.pageBlockerId);
215
+ const mainElement = document.getElementById(options.mainContentIdName);
216
+ if (mainElement) {
217
+ mainElement.hidden = false;
218
+ }
219
+ if (pageBlocker) {
220
+ pageBlocker.style.cssText = "";
221
+ } else {
222
+ this.waitForElementLoad(
223
+ `#${options.pageBlockerId}`,
224
+ (element) => {
225
+ element.style.cssText = "";
226
+ }
227
+ );
228
+ }
229
+ }
230
+ waitForElementLoad(selector, functionToExecute) {
231
+ const existingElement = document.querySelector(selector);
232
+ if (existingElement != null) {
233
+ functionToExecute(existingElement);
234
+ return;
235
+ }
236
+ const observer = new MutationObserver((mutations) => {
237
+ mutations.forEach((mutation) => {
238
+ mutation.addedNodes.forEach((node) => {
239
+ if (node.nodeType === Node.ELEMENT_NODE) {
240
+ const element = node;
241
+ if (element.matches(selector)) {
242
+ observer.disconnect();
243
+ functionToExecute(element);
244
+ }
245
+ }
246
+ });
247
+ });
248
+ });
249
+ observer.observe(document.body, { childList: true, subtree: true });
250
+ }
251
+ };
252
+
253
+ // src/classes/OverlayCustom.ts
254
+ var OverlayCustom = class extends OverlayBase {
255
+ divAnimationObject;
256
+ mainElementAnimation;
257
+ constructor(divAnimationObject, duration, color, timing = "linear", mainElementAnimation = null) {
258
+ super(duration, color, timing);
259
+ this.divAnimationObject = divAnimationObject;
260
+ this.mainElementAnimation = mainElementAnimation;
261
+ }
262
+ handle(direction, mainElement) {
263
+ for (const ele of document.getElementsByClassName("pagewave-overlay-div")) {
264
+ ele.remove();
265
+ }
266
+ const root = document.documentElement;
267
+ root.style.setProperty("--div-color", this.color);
268
+ for (const [className, animationName] of Object.entries(this.divAnimationObject)) {
269
+ const divElement = document.createElement("div");
270
+ divElement.className = className + " pagewave-overlay-div";
271
+ divElement.style.animation = `${animationName} ${this.duration}ms ${this.timing} both ${direction}`;
272
+ divElement.style.backgroundColor = this.color;
273
+ divElement.style.position = "absolute";
274
+ mainElement.appendChild(divElement);
275
+ setTimeout(() => {
276
+ if (divElement.parentElement == mainElement) {
277
+ mainElement.removeChild(divElement);
278
+ }
279
+ }, this.duration);
280
+ }
281
+ if (this.mainElementAnimation !== null) {
282
+ this.mainElementAnimation.handle(direction, mainElement);
283
+ }
284
+ }
285
+ };
286
+
287
+ // src/classes/OverlayPreset.ts
288
+ var OverlayPreset = class extends OverlayCustom {
289
+ constructor(oType, duration, color, timing = "linear") {
290
+ const overlayMap = {
291
+ slide: { firstOverlayElement: "slide" },
292
+ inverseSlide: { firstOverlayElement: "inverseSlide" },
293
+ curtain: { firstOverlayElement: "rightcurtain", secondOverlayElement: "leftcurtain" },
294
+ rise: { firstOverlayElement: "rise" },
295
+ fall: { firstOverlayElement: "fall" },
296
+ bubble: { firstOverlayElement: "bubble" },
297
+ wipe: { firstOverlayElement: "wipe" }
298
+ };
299
+ super(overlayMap[oType], duration, color, timing);
300
+ }
301
+ handle(direction, mainElement) {
302
+ super.handle(direction, mainElement);
303
+ }
304
+ };
305
+
306
+ // src/classes/OverlayStyled.ts
307
+ var OverlayStyled = class extends OverlayBase {
308
+ divAnimationObject;
309
+ mainElementAnimation;
310
+ blockerDesign;
311
+ constructor(divAnimationObject, duration, color, timing = "linear", mainElementAnimation = null, blockerDesign = {}) {
312
+ super(duration, color, timing);
313
+ this.divAnimationObject = divAnimationObject;
314
+ this.mainElementAnimation = mainElementAnimation;
315
+ this.blockerDesign = blockerDesign;
316
+ }
317
+ hidePage(options) {
318
+ const mainContent = document.getElementById(options.mainContentIdName);
319
+ if (document.getElementById(options.pageBlockerId)) {
320
+ const pageBlockerElement = document.getElementById(options.pageBlockerId);
321
+ pageBlockerElement.style.cssText = `position: absolute; width: 100%; height: 100%; z-index: 100; top: 0; background-color: ${this.color}`;
322
+ for (const [styleKey, styleValue] of Object.entries(this.blockerDesign)) {
323
+ pageBlockerElement.style[styleKey] = styleValue;
324
+ }
325
+ return;
326
+ }
327
+ for (const ele of document.getElementsByClassName("pagewave-overlay-div")) {
328
+ ele.remove();
329
+ }
330
+ const pageBlocker = document.createElement("div");
331
+ pageBlocker.id = options.pageBlockerId;
332
+ pageBlocker.style.cssText = `position: absolute; width: 100%; height: 100%; z-index: 100; top: 0; background-color: ${this.color}`;
333
+ for (const [styleKey, styleValue] of Object.entries(this.blockerDesign)) {
334
+ pageBlocker.style[styleKey] = styleValue;
335
+ }
336
+ mainContent.append(pageBlocker);
337
+ }
338
+ handle(direction, mainElement) {
339
+ for (const ele of document.getElementsByClassName("pagewave-overlay-div")) {
340
+ ele.remove();
341
+ }
342
+ const root = document.documentElement;
343
+ root.style.setProperty("--div-color", this.color);
344
+ for (const [className, divProperties] of Object.entries(this.divAnimationObject)) {
345
+ const divElement = document.createElement("div");
346
+ divElement.className = className + " pagewave-overlay-div";
347
+ divElement.style.animation = `${divProperties.animationName} ${this.duration}ms ${this.timing} both ${direction}`;
348
+ divElement.style.backgroundColor = this.color;
349
+ divElement.style.position = "absolute";
350
+ for (const [styleKey, styleValue] of Object.entries(divProperties.cssDesign)) {
351
+ divElement.style[styleKey] = styleValue;
352
+ }
353
+ mainElement.appendChild(divElement);
354
+ setTimeout(() => {
355
+ }, this.duration);
356
+ }
357
+ if (this.mainElementAnimation !== null) {
358
+ this.mainElementAnimation.handle(direction, mainElement);
359
+ }
360
+ }
361
+ };
362
+
363
+ // src/classes/PageWave.ts
364
+ var PageWave = class {
365
+ defaultOptions;
366
+ finalOptions;
367
+ routeTransitions;
368
+ constructor(transitions, options = {}) {
369
+ this.defaultOptions = {
370
+ mainContentIdName: "main-content",
371
+ pageAnimationDelay: 100,
372
+ runAnimationOnPageReload: false,
373
+ runAnimationOnCrossSite: false,
374
+ pageRevealDelay: 0,
375
+ leavePageOnLink: true,
376
+ pageBlockerId: "pageBlocker",
377
+ classToIgnoreLink: "ignore-click",
378
+ animateIgnoredLinks: false,
379
+ animateSelfLink: true,
380
+ loadEvent: "DOMContentLoaded",
381
+ preferIgnore: false
382
+ };
383
+ this.finalOptions = { ...this.defaultOptions, ...options };
384
+ this.routeTransitions = transitions;
385
+ }
386
+ CallHook(hookName, details = {}) {
387
+ const event = new CustomEvent(hookName, {
388
+ detail: details
389
+ });
390
+ window.dispatchEvent(event);
391
+ }
392
+ isNavigationFromSameSite() {
393
+ const referrer = document.referrer;
394
+ if (referrer == "") {
395
+ return false;
396
+ }
397
+ const currentHost = window.location.hostname;
398
+ const referrerHost = new URL(referrer).hostname;
399
+ return referrerHost === currentHost;
400
+ }
401
+ isInternalLink(link) {
402
+ try {
403
+ const url = new URL(link, window.location.href);
404
+ return url.hostname === window.location.hostname;
405
+ } catch (e) {
406
+ return false;
407
+ }
408
+ }
409
+ HandleClickAnimation(e, defaultTransitionStyle, leaveFunction = (link) => {
410
+ window.location.href = link;
411
+ }, externalLeaveFunction = (link) => {
412
+ window.location.href = link;
413
+ }) {
414
+ if (!e.target || !(e.target instanceof HTMLAnchorElement)) {
415
+ return;
416
+ }
417
+ e.preventDefault();
418
+ e.stopPropagation();
419
+ if (e.target.tagName.toLowerCase() == "a") {
420
+ const correctLeaveFunction = this.isInternalLink(e.target.href) ? leaveFunction : externalLeaveFunction;
421
+ const matchedRoute = Array.from(e.target.classList).find((cls) => cls in this.routeTransitions);
422
+ const shouldIgnore = this.finalOptions.preferIgnore && !matchedRoute || e.target.classList.contains(this.finalOptions.classToIgnoreLink);
423
+ if (!shouldIgnore && (e.target.href != window.location.href || this.finalOptions.animateSelfLink)) {
424
+ e.preventDefault();
425
+ let duration = defaultTransitionStyle.duration;
426
+ this.CallHook("animateSSP", { style: defaultTransitionStyle, clickEvent: e });
427
+ if (matchedRoute && matchedRoute in this.routeTransitions) {
428
+ this.AnimatePageTransition(this.routeTransitions[matchedRoute], "normal");
429
+ sessionStorage.setItem("animationType", matchedRoute);
430
+ duration = this.routeTransitions[matchedRoute].duration;
431
+ } else {
432
+ this.AnimatePageTransition(defaultTransitionStyle, "normal");
433
+ sessionStorage.setItem("animationType", "animation");
434
+ duration = defaultTransitionStyle.duration;
435
+ }
436
+ setTimeout(
437
+ () => {
438
+ this.CallHook("animateESP", { style: defaultTransitionStyle, clickEvent: e });
439
+ if (this.finalOptions.leavePageOnLink) {
440
+ correctLeaveFunction(e.target.href);
441
+ }
442
+ },
443
+ duration
444
+ );
445
+ } else if (e.target.classList.contains(this.finalOptions.classToIgnoreLink) || e.target.href == window.location.href && !this.finalOptions.animateSelfLink) {
446
+ sessionStorage.setItem("animationType", "ignore");
447
+ if (this.finalOptions.leavePageOnLink) {
448
+ correctLeaveFunction(e.target.href);
449
+ }
450
+ }
451
+ }
452
+ }
453
+ ListenForChange(defaultTransitionStyle, leaveFunction = (link) => {
454
+ window.location.href = link;
455
+ }) {
456
+ this.EndPoint(defaultTransitionStyle);
457
+ this.SendPoint(defaultTransitionStyle, leaveFunction);
458
+ }
459
+ SendPoint(defaultTransitionStyle, leaveFunction = (link) => {
460
+ window.location.href = link;
461
+ }, externalLeaveFunction = (link) => {
462
+ window.location.href = link;
463
+ }) {
464
+ const mainElement = document.getElementById(this.finalOptions.mainContentIdName);
465
+ mainElement.onclick = null;
466
+ mainElement.addEventListener("click", (e) => {
467
+ this.HandleClickAnimation(e, defaultTransitionStyle, leaveFunction, externalLeaveFunction);
468
+ });
469
+ }
470
+ getStorageRouteTransition(defaultTransitionStyle) {
471
+ const storageKey = sessionStorage.getItem("animationType");
472
+ if (storageKey != null && storageKey != "animation" && storageKey in this.routeTransitions) {
473
+ return this.routeTransitions[storageKey];
474
+ }
475
+ return defaultTransitionStyle;
476
+ }
477
+ EndPoint(defaultTransitionStyle) {
478
+ defaultTransitionStyle = this.getStorageRouteTransition(defaultTransitionStyle);
479
+ defaultTransitionStyle.hidePage(this.finalOptions);
480
+ const mainElement = document.getElementById(this.finalOptions.mainContentIdName);
481
+ mainElement.addEventListener(this.finalOptions.loadEvent, (e) => {
482
+ e.stopPropagation();
483
+ this.CallHook("animateSEP", { style: defaultTransitionStyle });
484
+ const doTransitionOnIgnoredLink = this.finalOptions.animateIgnoredLinks || sessionStorage.getItem("animationType") != "ignore";
485
+ const doAnimateOnReload = window.performance.getEntriesByType("navigation")[0]?.entryType != "reload" || this.finalOptions.runAnimationOnPageReload;
486
+ const doAnimateOnSameSite = this.isNavigationFromSameSite() || this.finalOptions.runAnimationOnCrossSite;
487
+ if (doAnimateOnReload && doAnimateOnSameSite && doTransitionOnIgnoredLink) {
488
+ setTimeout(
489
+ () => {
490
+ this.AnimatePageTransition(defaultTransitionStyle, "reverse");
491
+ setTimeout(
492
+ () => {
493
+ this.CallHook("animateEEP", { style: defaultTransitionStyle });
494
+ defaultTransitionStyle.revealPage(this.finalOptions);
495
+ },
496
+ this.finalOptions.pageRevealDelay
497
+ );
498
+ },
499
+ this.finalOptions.pageAnimationDelay
500
+ );
501
+ } else {
502
+ this.CallHook("animateEPNA", { style: defaultTransitionStyle });
503
+ defaultTransitionStyle.revealPage(this.finalOptions);
504
+ }
505
+ }, { once: true });
506
+ }
507
+ CallEndPoint() {
508
+ const dispatchEvent = new Event(this.finalOptions.loadEvent);
509
+ document.getElementById(this.finalOptions.mainContentIdName).dispatchEvent(dispatchEvent);
510
+ }
511
+ AnimatePageTransition(aStyle, direction = "normal") {
512
+ const mainElement = document.getElementById(this.finalOptions.mainContentIdName);
513
+ if (direction == "normal") {
514
+ this.CallHook("animateSF", { style: aStyle, ele: mainElement });
515
+ } else if (direction == "reverse") {
516
+ this.CallHook("animateSR", { style: aStyle, ele: mainElement });
517
+ }
518
+ aStyle.handle(direction, mainElement);
519
+ setTimeout(
520
+ () => {
521
+ if (direction == "normal") {
522
+ this.CallHook("animateEF", { style: aStyle, ele: mainElement });
523
+ } else if (direction == "reverse") {
524
+ this.CallHook("animateER", { style: aStyle, ele: mainElement });
525
+ }
526
+ },
527
+ aStyle.duration
528
+ );
529
+ }
530
+ };
531
+
532
+ // src/classes/StyleTransition.ts
533
+ var StyleTransition = class extends KeyFrameBase {
534
+ styleString;
535
+ startValue;
536
+ endValue;
537
+ constructor(styleString, duration, startValue, endValue, timing = "linear") {
538
+ super(duration, timing);
539
+ this.styleString = styleString;
540
+ this.startValue = startValue;
541
+ this.endValue = endValue;
542
+ }
543
+ handle(direction, mainElement) {
544
+ if (direction == "normal") {
545
+ mainElement.style[this.styleString] = this.startValue;
546
+ mainElement.style.transition = this.styleString.toString() + " " + this.duration.toString() + "ms " + this.timing;
547
+ mainElement.style[this.styleString] = this.endValue;
548
+ } else if (direction == "reverse") {
549
+ mainElement.style[this.styleString] = this.endValue;
550
+ mainElement.style.transition = this.styleString.toString() + " " + this.duration.toString() + "ms " + this.timing;
551
+ setTimeout(
552
+ () => {
553
+ mainElement.style[this.styleString] = this.startValue;
554
+ },
555
+ 40
556
+ );
557
+ }
558
+ }
559
+ };
560
+ // Annotate the CommonJS export names for ESM import in node:
561
+ 0 && (module.exports = {
562
+ KeyFrameBase,
563
+ KeyFrameCustom,
564
+ KeyFramePreset,
565
+ MultiElementAnimation,
566
+ OverlayBase,
567
+ OverlayCustom,
568
+ OverlayPreset,
569
+ OverlayStyled,
570
+ PageWave,
571
+ StyleTransition
572
+ });
573
+ //# sourceMappingURL=index.js.map