pagewave 1.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/KeyFramePreset.css +20 -0
- package/OverlayPreset.css +121 -0
- package/guide.txt +56 -0
- package/package.json +22 -0
- package/sw.js +37 -0
- package/transition.js +452 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
:root{
|
|
2
|
+
--div-color: #293241;
|
|
3
|
+
}
|
|
4
|
+
@keyframes bubble {
|
|
5
|
+
from{
|
|
6
|
+
width: 100%;
|
|
7
|
+
height: 100%;
|
|
8
|
+
position: absolute;
|
|
9
|
+
background-color: var(--div-color);
|
|
10
|
+
clip-path: circle(0%);
|
|
11
|
+
top: 0;
|
|
12
|
+
}
|
|
13
|
+
to{
|
|
14
|
+
width: 100%;
|
|
15
|
+
height: 100%;
|
|
16
|
+
position: absolute;
|
|
17
|
+
background-color: var(--div-color);
|
|
18
|
+
clip-path: circle(100%);
|
|
19
|
+
top: 0;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
@keyframes fall {
|
|
23
|
+
from{
|
|
24
|
+
height: 0%;
|
|
25
|
+
width: 100%;
|
|
26
|
+
position: absolute;
|
|
27
|
+
top: 0;
|
|
28
|
+
background-color: var(--div-color);
|
|
29
|
+
}
|
|
30
|
+
to{
|
|
31
|
+
height: 100%;
|
|
32
|
+
width: 100%;
|
|
33
|
+
position: absolute;
|
|
34
|
+
top: 0;
|
|
35
|
+
background-color: var(--div-color);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
@keyframes rise {
|
|
39
|
+
from{
|
|
40
|
+
height: 0%;
|
|
41
|
+
width: 100%;
|
|
42
|
+
position: absolute;
|
|
43
|
+
bottom: 0;
|
|
44
|
+
background-color: var(--div-color);
|
|
45
|
+
}
|
|
46
|
+
to{
|
|
47
|
+
height: 100%;
|
|
48
|
+
width: 100%;
|
|
49
|
+
position: absolute;
|
|
50
|
+
bottom: 0;
|
|
51
|
+
background-color: var(--div-color);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
@keyframes leftcurtain{
|
|
55
|
+
from{
|
|
56
|
+
height: 100%;
|
|
57
|
+
width: 0%;
|
|
58
|
+
position: absolute;
|
|
59
|
+
top: 0;
|
|
60
|
+
background-color: var(--div-color);
|
|
61
|
+
}
|
|
62
|
+
to{
|
|
63
|
+
height: 100%;
|
|
64
|
+
width: 50%;
|
|
65
|
+
position: absolute;
|
|
66
|
+
top: 0;
|
|
67
|
+
background-color: var(--div-color);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
@keyframes rightcurtain{
|
|
71
|
+
from{
|
|
72
|
+
height: 100%;
|
|
73
|
+
width: 0%;
|
|
74
|
+
position: absolute;
|
|
75
|
+
right: 0;
|
|
76
|
+
top: 0;
|
|
77
|
+
background-color: var(--div-color);
|
|
78
|
+
}
|
|
79
|
+
to{
|
|
80
|
+
height: 100%;
|
|
81
|
+
width: 50%;
|
|
82
|
+
position: absolute;
|
|
83
|
+
right: 0;
|
|
84
|
+
top: 0;
|
|
85
|
+
background-color: var(--div-color);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
@keyframes inverseSlide{
|
|
89
|
+
from{
|
|
90
|
+
height: 100%;
|
|
91
|
+
width: 0%;
|
|
92
|
+
position: absolute;
|
|
93
|
+
right: 0;
|
|
94
|
+
top: 0;
|
|
95
|
+
background-color: var(--div-color);
|
|
96
|
+
}
|
|
97
|
+
to{
|
|
98
|
+
height: 100%;
|
|
99
|
+
width: 100%;
|
|
100
|
+
position: absolute;
|
|
101
|
+
right: 0;
|
|
102
|
+
top: 0;
|
|
103
|
+
background-color: var(--div-color);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
@keyframes slide {
|
|
107
|
+
from{
|
|
108
|
+
height: 100%;
|
|
109
|
+
width: 0%;
|
|
110
|
+
position: absolute;
|
|
111
|
+
top: 0;
|
|
112
|
+
background-color: var(--div-color);
|
|
113
|
+
}
|
|
114
|
+
to{
|
|
115
|
+
height: 100%;
|
|
116
|
+
width: 100%;
|
|
117
|
+
position: absolute;
|
|
118
|
+
top: 0;
|
|
119
|
+
background-color: var(--div-color);
|
|
120
|
+
}
|
|
121
|
+
}
|
package/guide.txt
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Types of Animation Containers:
|
|
2
|
+
-KeyFramePreset
|
|
3
|
+
-KeyFrameCustom
|
|
4
|
+
-StyleTransition
|
|
5
|
+
-OverlayPreset
|
|
6
|
+
-OverlayCustom
|
|
7
|
+
-MultiElementAnimation
|
|
8
|
+
|
|
9
|
+
Preset Types:
|
|
10
|
+
-Overlay Presets
|
|
11
|
+
-Keyframe Presets
|
|
12
|
+
|
|
13
|
+
Animation Function:
|
|
14
|
+
-AnimatePageTransition
|
|
15
|
+
|
|
16
|
+
Listener Functions:
|
|
17
|
+
-ListenForChange
|
|
18
|
+
-SendPoint
|
|
19
|
+
-EndPoint
|
|
20
|
+
|
|
21
|
+
Hooks:
|
|
22
|
+
-animateSF - animation start forward
|
|
23
|
+
-animateSR - animation start reverse
|
|
24
|
+
-animateEF - animation end forward
|
|
25
|
+
-animateER - animation end reverse
|
|
26
|
+
-animateSSP - start of send point listen
|
|
27
|
+
-animateESP - end of send point listen
|
|
28
|
+
-animateSEP - start of end point listen
|
|
29
|
+
-animateEPNSW - end point no service worker exists
|
|
30
|
+
-animateEEP - end of end point
|
|
31
|
+
-animateEPNA - end point no animation played
|
|
32
|
+
|
|
33
|
+
Features:
|
|
34
|
+
-Built-in animations
|
|
35
|
+
-Hooks
|
|
36
|
+
-Doesn't touch history or use push state, allowing
|
|
37
|
+
for you to use it with routers like sveltekit
|
|
38
|
+
-Manual page transition animations can be run to avoid
|
|
39
|
+
conflicts with any frameworks
|
|
40
|
+
-Customizable ids for divs to avoid conflict with elements
|
|
41
|
+
in your body
|
|
42
|
+
-Allows for custom overlay animations, keyframe animations, or
|
|
43
|
+
transition animations
|
|
44
|
+
-Separate listener animations for different types of animations
|
|
45
|
+
-Separate types of links for overlay or other animations
|
|
46
|
+
|
|
47
|
+
What I Learned:
|
|
48
|
+
-Expanded knowledge on HTML, JS, and CSS Knowledge
|
|
49
|
+
-Session storage
|
|
50
|
+
-Service workers
|
|
51
|
+
-Polymorphism
|
|
52
|
+
-Event dispatcher
|
|
53
|
+
|
|
54
|
+
Common Issues:
|
|
55
|
+
-White Flash
|
|
56
|
+
-Issues with using absolute positioning on main content and calling overlay animations
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pagewave",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "NPM Package for implementing page transitions in both SSR and CSR apps",
|
|
5
|
+
"main": "transition.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"page",
|
|
11
|
+
"transition",
|
|
12
|
+
"animation",
|
|
13
|
+
"ssr",
|
|
14
|
+
"csr"
|
|
15
|
+
],
|
|
16
|
+
"author": "Daniel Pagano",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/toasterstrudelz/pagewave.git"
|
|
21
|
+
}
|
|
22
|
+
}
|
package/sw.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const CACHE_NAME = "Page Transition SW";
|
|
2
|
+
let pageCache = [
|
|
3
|
+
"transition.js",
|
|
4
|
+
"OverlayPreset.css",
|
|
5
|
+
"KeyFramePreset.css",
|
|
6
|
+
];
|
|
7
|
+
self.addEventListener("fetch", (e) => {
|
|
8
|
+
e.respondWith(
|
|
9
|
+
caches.match(e.request).then(
|
|
10
|
+
(response) => {
|
|
11
|
+
if(response){
|
|
12
|
+
return response;
|
|
13
|
+
}
|
|
14
|
+
return fetch(e.request);
|
|
15
|
+
}
|
|
16
|
+
)
|
|
17
|
+
)
|
|
18
|
+
});
|
|
19
|
+
self.addEventListener("install", (e) => {
|
|
20
|
+
e.waitUntil(
|
|
21
|
+
caches.open(CACHE_NAME).then(
|
|
22
|
+
(cache) => {return cache.addAll(pageCache);}
|
|
23
|
+
)
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
self.addEventListener("message", (event) => {
|
|
27
|
+
fetch(event.data).then((response) => {
|
|
28
|
+
if (!response.ok) {
|
|
29
|
+
throw new TypeError("Bad response status");
|
|
30
|
+
}
|
|
31
|
+
caches.open(CACHE_NAME).then(
|
|
32
|
+
(cache) => {return cache.put(event.data, response);}
|
|
33
|
+
)
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
});
|
package/transition.js
ADDED
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
let defaultOptions = {
|
|
2
|
+
mainContentIdName: "main-content",
|
|
3
|
+
overlayClass: "a-overlay",
|
|
4
|
+
animationClass: "a-animation",
|
|
5
|
+
pageAnimationDelay: 200,
|
|
6
|
+
useServiceWorker: true,
|
|
7
|
+
runAnimationOnPageReload: false,
|
|
8
|
+
runAnimationOnCrossSite: false,
|
|
9
|
+
pageRevealDelay: 0,
|
|
10
|
+
leavePageOnLink: true,
|
|
11
|
+
pageBlockerId: "pageBlocker",
|
|
12
|
+
classToIgnoreLink: "ignore-click",
|
|
13
|
+
animateIgnoredLinks: false,
|
|
14
|
+
animateSelfLink: true,
|
|
15
|
+
loadEvent: "DOMContentLoaded",
|
|
16
|
+
}
|
|
17
|
+
let finalOptions = {
|
|
18
|
+
mainContentIdName: "main-content",
|
|
19
|
+
overlayClass: "a-overlay",
|
|
20
|
+
animationClass: "a-animation",
|
|
21
|
+
pageAnimationDelay: 200,
|
|
22
|
+
useServiceWorker: true,
|
|
23
|
+
runAnimationOnPageReload: false,
|
|
24
|
+
runAnimationOnCrossSite: false,
|
|
25
|
+
pageRevealDelay: 0,
|
|
26
|
+
leavePageOnClick: true,
|
|
27
|
+
pageBlockerId: "pageBlocker",
|
|
28
|
+
classToIgnoreLink: "ignore-click",
|
|
29
|
+
animateIgnoredLinks: false,
|
|
30
|
+
animateSelfLink: true,
|
|
31
|
+
loadEvent: "DOMContentLoaded",
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function SetUp(options = {}) {
|
|
35
|
+
//Merge default options with user options
|
|
36
|
+
finalOptions = { ...defaultOptions, ...options };
|
|
37
|
+
//Import css files into HTNL document
|
|
38
|
+
let cssFiles = ["OverlayPreset.css", "KeyFramePreset.css"];
|
|
39
|
+
for (let i = 0; i < cssFiles.length; i++) {
|
|
40
|
+
let link = document.createElement('link');
|
|
41
|
+
link.rel = 'stylesheet';
|
|
42
|
+
link.type = 'text/css';
|
|
43
|
+
link.href = cssFiles[i];
|
|
44
|
+
document.getElementsByTagName('HEAD')[0].appendChild(link);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.SetUp = SetUp;
|
|
48
|
+
const overlayType = Object.freeze({
|
|
49
|
+
slide: Symbol("slide"),
|
|
50
|
+
inverseSlide: Symbol("inverseSlide"),
|
|
51
|
+
curtain: Symbol("curtain"),
|
|
52
|
+
rise: Symbol("rise"),
|
|
53
|
+
fall: Symbol("fall"),
|
|
54
|
+
bubble: Symbol("bubble"),
|
|
55
|
+
});
|
|
56
|
+
exports.overlayType = overlayType;
|
|
57
|
+
const keyframeType = Object.freeze({
|
|
58
|
+
fade: Symbol("fade"),
|
|
59
|
+
fadeaway: Symbol("fadeaway"),
|
|
60
|
+
});
|
|
61
|
+
exports.keyframeType = keyframeType;
|
|
62
|
+
|
|
63
|
+
function ApplyAnimation(element, animationName, duration, timing, direction) {
|
|
64
|
+
element.style.animation = `${animationName} ${duration}ms ${timing} both ${direction}`;
|
|
65
|
+
if (direction == "reverse") {
|
|
66
|
+
let currentAnimation = null;
|
|
67
|
+
element.getAnimations().forEach((animation) => {
|
|
68
|
+
if (currentAnimation == null && animation.animationName == animationName) {
|
|
69
|
+
currentAnimation = animation;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
function handleAnimation(event) {
|
|
73
|
+
if (event.animationName == animationName) {
|
|
74
|
+
let animationKeyframes = currentAnimation.effect;
|
|
75
|
+
let kfValues = Object.values(animationKeyframes.getKeyframes()[0]);
|
|
76
|
+
let kfKeys = Object.keys(animationKeyframes.getKeyframes()[0]);
|
|
77
|
+
let animationProperties = kfValues.slice(3, kfValues.length - 1);
|
|
78
|
+
let animationKeys = kfKeys.slice(3, kfValues.length - 1);
|
|
79
|
+
for (let i = 0; i < animationKeys.length; i++) {
|
|
80
|
+
element.style[animationKeys[i]] = animationProperties[i].toString();
|
|
81
|
+
}
|
|
82
|
+
element.style.animation = "";
|
|
83
|
+
element.removeEventListener("animationend", handleAnimation);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
element.addEventListener("animationend", handleAnimation,);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function CallHook(hookName, details) {
|
|
90
|
+
const event = new CustomEvent(hookName, {
|
|
91
|
+
detail: details
|
|
92
|
+
});
|
|
93
|
+
window.dispatchEvent(event);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
class KeyFramePreset {
|
|
97
|
+
constructor(kfType, duration, timing = "linear") {
|
|
98
|
+
this.kfType = kfType;
|
|
99
|
+
this.duration = duration;
|
|
100
|
+
this.timing = timing;
|
|
101
|
+
}
|
|
102
|
+
handle(direction) {
|
|
103
|
+
const animationMap = {
|
|
104
|
+
fade: "fade",
|
|
105
|
+
fadeaway: "fadeaway"
|
|
106
|
+
};
|
|
107
|
+
if (animationMap[this.kfType.description]) {
|
|
108
|
+
AnimatePageTransition(new KeyFrameCustom(animationMap[this.kfType.description], this.duration, this.timing), direction);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.KeyFramePreset = KeyFramePreset;
|
|
113
|
+
class KeyFrameCustom {
|
|
114
|
+
constructor(animationName, duration, timing = "linear") {
|
|
115
|
+
this.animationName = animationName;
|
|
116
|
+
this.duration = duration;
|
|
117
|
+
this.timing = timing;
|
|
118
|
+
}
|
|
119
|
+
handle(direction, mainElement) {
|
|
120
|
+
mainElement.hidden = false;
|
|
121
|
+
ApplyAnimation(mainElement, this.animationName, this.duration, this.timing, direction)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.KeyFrameCustom = KeyFrameCustom;
|
|
125
|
+
class StyleTransition {
|
|
126
|
+
constructor(styleString, duration, startValue, endValue, timing = "linear") {
|
|
127
|
+
this.styleString = styleString;
|
|
128
|
+
this.duration = duration;
|
|
129
|
+
this.startValue = startValue
|
|
130
|
+
this.endValue = endValue;
|
|
131
|
+
this.timing = timing;
|
|
132
|
+
}
|
|
133
|
+
handle(direction, mainElement) {
|
|
134
|
+
if (direction == "normal") {
|
|
135
|
+
mainElement.style[this.styleString] = this.startValue;
|
|
136
|
+
mainElement.style.transition = this.styleString + " " + this.duration.toString() + "ms " + this.timing;
|
|
137
|
+
mainElement.style[this.styleString] = this.endValue;
|
|
138
|
+
} else if (direction == "reverse") {
|
|
139
|
+
mainElement.style[this.styleString] = this.endValue;
|
|
140
|
+
mainElement.style.transition = this.styleString + " " + this.duration.toString() + "ms " + this.timing;
|
|
141
|
+
setTimeout(
|
|
142
|
+
() => {
|
|
143
|
+
mainElement.style[this.styleString] = this.startValue;
|
|
144
|
+
}, 40
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.StyleTransition = StyleTransition;
|
|
151
|
+
class MultiElementAnimation {
|
|
152
|
+
constructor(animateableObjects, duration, timing = "linear", mainElementAnimation = "") {
|
|
153
|
+
this.animateableObjects = animateableObjects;
|
|
154
|
+
this.duration = duration;
|
|
155
|
+
this.timing = timing;
|
|
156
|
+
this.mainElementAnimation = mainElementAnimation;
|
|
157
|
+
}
|
|
158
|
+
handle(direction, mainElement) {
|
|
159
|
+
mainElement.hidden = false;
|
|
160
|
+
let timing = this.timing;
|
|
161
|
+
for (const [selector, animationName] of Object.entries(this.animateableObjects)) {
|
|
162
|
+
document.querySelectorAll(selector).forEach(element => ApplyAnimation(element, animationName, this.duration, timing, direction));
|
|
163
|
+
}
|
|
164
|
+
if (this.mainElementAnimation != "") {
|
|
165
|
+
ApplyAnimation(mainElement, this.mainElementAnimation, this.duration, timing, direction);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.MultiElementAnimation = MultiElementAnimation;
|
|
170
|
+
class OverlayPreset {
|
|
171
|
+
constructor(oType, duration, color, timing = "linear") {
|
|
172
|
+
this.duration = duration;
|
|
173
|
+
this.color = color;
|
|
174
|
+
this.oType = oType;
|
|
175
|
+
this.timing = timing;
|
|
176
|
+
}
|
|
177
|
+
handle(direction) {
|
|
178
|
+
const overlayMap = {
|
|
179
|
+
slide: { firstOverlayElement: "slide" },
|
|
180
|
+
inverseSlide: { firstOverlayElement: "inverseSlide" },
|
|
181
|
+
curtain: { firstOverlayElement: "rightcurtain", secondOverlayElement: "leftcurtain" },
|
|
182
|
+
rise: { firstOverlayElement: "rise" },
|
|
183
|
+
fall: { firstOverlayElement: "fall" },
|
|
184
|
+
bubble: { firstOverlayElement: "bubble" }
|
|
185
|
+
};
|
|
186
|
+
if (overlayMap[this.oType.description]) {
|
|
187
|
+
AnimatePageTransition(new OverlayCustom(overlayMap[this.oType.description], this.duration, this.color, this.timing), direction);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
exports.OverlayPreset = OverlayPreset;
|
|
192
|
+
class OverlayCustom {
|
|
193
|
+
constructor(divAnimationObject, duration, color, timing = "linear", mainElementAnimation = "") {
|
|
194
|
+
this.divAnimationObject = divAnimationObject;
|
|
195
|
+
this.duration = duration;
|
|
196
|
+
this.color = color;
|
|
197
|
+
this.timing = timing;
|
|
198
|
+
this.mainElementAnimation = mainElementAnimation;
|
|
199
|
+
}
|
|
200
|
+
handle(direction, mainElement) {
|
|
201
|
+
var r = document.querySelector(':root');
|
|
202
|
+
r.style.setProperty('--div-color', this.color);
|
|
203
|
+
let timing = this.timing;
|
|
204
|
+
/*
|
|
205
|
+
function RemoveDiv(event) {
|
|
206
|
+
if (event.target.animateName == event.animationName) {
|
|
207
|
+
event.target.removeEventListener("animationend", RemoveDiv);
|
|
208
|
+
event.target.remove();
|
|
209
|
+
}
|
|
210
|
+
}*/
|
|
211
|
+
for (const [className, animationName] of Object.entries(this.divAnimationObject)) {
|
|
212
|
+
let divElement = document.createElement("div");
|
|
213
|
+
divElement.className = className;
|
|
214
|
+
divElement.style.animation = `${animationName} ${this.duration.toString()}ms ${timing} both ${direction}`;
|
|
215
|
+
mainElement.appendChild(divElement);
|
|
216
|
+
//divElement.animateName = animationName;
|
|
217
|
+
//divElement.addEventListener("animationend", RemoveDiv);
|
|
218
|
+
}
|
|
219
|
+
if (this.mainElementAnimation != "") {
|
|
220
|
+
mainElement.style.animation = `${this.mainElementAnimation} ${this.duration.toString()}ms ${timing} both ${direction}`;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
exports.OverlayCustom = OverlayCustom;
|
|
225
|
+
/*
|
|
226
|
+
function AddFileToCache(file) {
|
|
227
|
+
if ("serviceWorker" in navigator) {
|
|
228
|
+
if (navigator.serviceWorker.controller) {
|
|
229
|
+
if (navigator.serviceWorker.controller.scriptURL.slice(-5) == "sw.js") {
|
|
230
|
+
navigator.serviceWorker.controller.postMessage(file);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}*/
|
|
235
|
+
|
|
236
|
+
function AddServiceWorker() {
|
|
237
|
+
if (!finalOptions.useServiceWorker) {
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
let isServiceWorker = false;
|
|
241
|
+
if ("serviceWorker" in navigator) {
|
|
242
|
+
if (navigator.serviceWorker.controller) {
|
|
243
|
+
if (navigator.serviceWorker.controller.scriptURL.slice(-5) == "sw.js") {
|
|
244
|
+
isServiceWorker = true;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
navigator.serviceWorker.register("sw.js");
|
|
248
|
+
}
|
|
249
|
+
return isServiceWorker;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function isNavigationFromSameSite() {
|
|
253
|
+
const referrer = document.referrer;
|
|
254
|
+
if (referrer == "") {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
const currentHost = window.location.hostname;
|
|
258
|
+
const referrerHost = new URL(referrer).hostname;
|
|
259
|
+
|
|
260
|
+
return referrerHost === currentHost;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function IsOverlay(transitionStyle) {
|
|
264
|
+
if (transitionStyle instanceof OverlayPreset || transitionStyle instanceof OverlayCustom) {
|
|
265
|
+
return true;
|
|
266
|
+
} else if (transitionStyle instanceof StyleTransition || transitionStyle instanceof KeyFrameCustom || transitionStyle instanceof KeyFramePreset || transitionStyle instanceof MultiElementAnimation) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
exports.IsOverlay = IsOverlay;
|
|
271
|
+
function WaitForElementLoad(selector, functionToExecute) {
|
|
272
|
+
if(document.querySelector(selector) != null){
|
|
273
|
+
functionToExecute(document.querySelector(selector));
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
const observer = new MutationObserver((mutations) => {
|
|
277
|
+
mutations.forEach((mutation) => {
|
|
278
|
+
mutation.addedNodes.forEach((node) => {
|
|
279
|
+
if (node.matches && node.matches(selector)) {
|
|
280
|
+
observer.disconnect(); // Stop observing
|
|
281
|
+
functionToExecute(node); // Handle the element
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
// Start observing the document body for child additions
|
|
287
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
288
|
+
}
|
|
289
|
+
exports.WaitForElementLoad = WaitForElementLoad;
|
|
290
|
+
function ListenForChange(aStyle, aOverlay = aStyle, aAnimation = aStyle, leaveFunction = (link) => {window.location = link;}) {
|
|
291
|
+
EndPoint(aStyle, aOverlay, aAnimation, leaveFunction);
|
|
292
|
+
SendPoint(aStyle, aOverlay, aAnimation);
|
|
293
|
+
}
|
|
294
|
+
exports.ListenForChange = ListenForChange;
|
|
295
|
+
function SendPoint(aStyle, aOverlay = aStyle, aAnimation = aStyle, leaveFunction = (link) => {window.location = link;}) {
|
|
296
|
+
let allowAnimate = AddServiceWorker();
|
|
297
|
+
|
|
298
|
+
function HandleClickAnimation(e) {
|
|
299
|
+
//console.log(e.target.tagName, e.target.classList, e.target.href == window.location.href, finalOptions.animateSelfLink)
|
|
300
|
+
if (e.target.tagName.toLowerCase() == "a" && !(e.target.classList.contains(finalOptions.classToIgnoreLink)) && !(e.target.href == window.location.href && !finalOptions.animateSelfLink)) {
|
|
301
|
+
e.preventDefault();
|
|
302
|
+
let duration = aStyle.duration;
|
|
303
|
+
CallHook("animateSSP", { style: aStyle, overlayStyle: aOverlay, animationStyle: aAnimation, clickEvent: e });
|
|
304
|
+
if (e.target.classList.contains(finalOptions.overlayClass)) {
|
|
305
|
+
AnimatePageTransition(aOverlay, "normal");
|
|
306
|
+
duration = aOverlay.duration;
|
|
307
|
+
} else if (e.target.classList.contains(finalOptions.animationClass)) {
|
|
308
|
+
AnimatePageTransition(aAnimation, "normal");
|
|
309
|
+
duration = aAnimation.duration;
|
|
310
|
+
} else {
|
|
311
|
+
AnimatePageTransition(aStyle, "normal");
|
|
312
|
+
duration = aStyle.duration;
|
|
313
|
+
}
|
|
314
|
+
setTimeout(
|
|
315
|
+
() => {
|
|
316
|
+
CallHook("animateESP", { style: aStyle, overlayStyle: aOverlay, animationStyle: aAnimation, clickEvent: e });
|
|
317
|
+
window.removeEventListener("click", HandleClickAnimation);
|
|
318
|
+
if (finalOptions.leavePageOnClick) {
|
|
319
|
+
leaveFunction(e.target.href);
|
|
320
|
+
}
|
|
321
|
+
}, parseInt(duration)
|
|
322
|
+
);
|
|
323
|
+
} else if (e.target.classList.contains(finalOptions.classToIgnoreLink) || (e.target.href == window.location.href && !finalOptions.animateSelfLink)) {
|
|
324
|
+
sessionStorage.setItem("animationType", "ignore");
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function AddListeners() {
|
|
330
|
+
window.addEventListener("click", HandleClickAnimation);
|
|
331
|
+
}
|
|
332
|
+
if (allowAnimate) {
|
|
333
|
+
AddListeners();
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
window.addEventListener(finalOptions.loadEvent, () => {
|
|
337
|
+
AddListeners();
|
|
338
|
+
}, { once: true });
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
exports.SendPoint = SendPoint;
|
|
342
|
+
function EndPoint(aStyle, aOverlay = aStyle, aAnimation = aStyle) {
|
|
343
|
+
if (aOverlay != aStyle || aAnimation != aStyle) {
|
|
344
|
+
if (sessionStorage.getItem("animationType") === "true") {
|
|
345
|
+
aStyle = aOverlay;
|
|
346
|
+
} else if (sessionStorage.getItem("animationType") === "false") {
|
|
347
|
+
aStyle = aAnimation;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
function RevealPage(opposite = false) {
|
|
351
|
+
if (Boolean(IsOverlay(aStyle) ^ opposite)) {
|
|
352
|
+
if (document.getElementById(finalOptions.pageBlockerId) == null) {
|
|
353
|
+
WaitForElementLoad(
|
|
354
|
+
"#" + finalOptions.pageBlockerId, () => {
|
|
355
|
+
if (document.getElementById(finalOptions.pageBlockerId) != null) {
|
|
356
|
+
document.getElementById(finalOptions.pageBlockerId).remove();
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
);
|
|
360
|
+
} else {
|
|
361
|
+
document.getElementById(finalOptions.pageBlockerId).remove();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
else if(Boolean(!IsOverlay(aStyle) ^ opposite)) {
|
|
365
|
+
if (document.getElementById(finalOptions.mainContentIdName) == null) {
|
|
366
|
+
WaitForElementLoad(
|
|
367
|
+
"#" + finalOptions.mainContentIdName, () => {
|
|
368
|
+
document.getElementById(finalOptions.mainContentIdName).hidden = false;
|
|
369
|
+
}
|
|
370
|
+
);
|
|
371
|
+
} else {
|
|
372
|
+
document.getElementById(finalOptions.mainContentIdName).hidden = false;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
let allowAnimate = AddServiceWorker();
|
|
378
|
+
//console.log("allow animating");
|
|
379
|
+
if (IsOverlay(aStyle)) {
|
|
380
|
+
RevealPage(true);
|
|
381
|
+
let pageBlocker = document.createElement('div');
|
|
382
|
+
pageBlocker.id = finalOptions.pageBlockerId;
|
|
383
|
+
pageBlocker.style.cssText = `position: absolute; width: 100%; height: 100%; z-index: 100; top: 0; background-color: ${aStyle.color}`
|
|
384
|
+
document.body.append(pageBlocker);
|
|
385
|
+
} else {
|
|
386
|
+
RevealPage(true);
|
|
387
|
+
if (document.getElementById(finalOptions.mainContentIdName) == null) {
|
|
388
|
+
WaitForElementLoad(
|
|
389
|
+
"#" + finalOptions.mainContentIdName, () => {
|
|
390
|
+
document.getElementById(finalOptions.mainContentIdName).hidden = true;
|
|
391
|
+
}
|
|
392
|
+
);
|
|
393
|
+
} else {
|
|
394
|
+
document.getElementById(finalOptions.mainContentIdName).hidden = true;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
//console.log(allowAnimate, !(!finalOptions.animateIgnoredLinks && sessionStorage.getItem("animationType") == "ignore"), !(!finalOptions.animateSelfLink && sessionStorage.getItem("animationType") == "ignore"))
|
|
398
|
+
if (allowAnimate && !(!finalOptions.animateIgnoredLinks && sessionStorage.getItem("animationType") == "ignore") && !(!finalOptions.animateSelfLink && sessionStorage.getItem("animationType") == "ignore")) {
|
|
399
|
+
window.addEventListener(finalOptions.loadEvent, (e) => {
|
|
400
|
+
e.stopPropagation();
|
|
401
|
+
CallHook("animateSEP", { style: aStyle });
|
|
402
|
+
//console.log(window.performance.getEntriesByType("navigation")[0].type, isNavigationFromSameSite(), finalOptions.runAnimationOnCrossSite)
|
|
403
|
+
if ((window.performance.getEntriesByType("navigation")[0].type != "reload" || finalOptions.runAnimationOnPageReload) && (isNavigationFromSameSite() || finalOptions.runAnimationOnCrossSite)) {
|
|
404
|
+
setTimeout(
|
|
405
|
+
() => {
|
|
406
|
+
AnimatePageTransition(aStyle, "reverse");
|
|
407
|
+
setTimeout(
|
|
408
|
+
() => {
|
|
409
|
+
CallHook("animateEEP", { style: aStyle });
|
|
410
|
+
RevealPage();
|
|
411
|
+
}, finalOptions.pageRevealDelay
|
|
412
|
+
);
|
|
413
|
+
}, finalOptions.pageAnimationDelay
|
|
414
|
+
);
|
|
415
|
+
} else {
|
|
416
|
+
CallHook("animateEPNA", { style: aStyle })
|
|
417
|
+
RevealPage();
|
|
418
|
+
}
|
|
419
|
+
}, { once: true });
|
|
420
|
+
} else {
|
|
421
|
+
window.addEventListener(finalOptions.loadEvent, () => {
|
|
422
|
+
CallHook("animateEPNSW", { style: aStyle })
|
|
423
|
+
RevealPage();
|
|
424
|
+
}, { once: true });
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
exports.EndPoint = EndPoint;
|
|
428
|
+
function AnimatePageTransition(aStyle, direction = "normal") {
|
|
429
|
+
let mainElement = document.getElementById(finalOptions.mainContentIdName);
|
|
430
|
+
if (!(aStyle instanceof OverlayPreset) && !(aStyle instanceof KeyFramePreset)) {
|
|
431
|
+
sessionStorage.setItem("animationType", IsOverlay(aStyle).toString());
|
|
432
|
+
if (direction == "normal") {
|
|
433
|
+
CallHook("animateSF", { style: aStyle, ele: mainElement, });
|
|
434
|
+
} else if (direction == "reverse") {
|
|
435
|
+
CallHook("animateSR", { style: aStyle, ele: mainElement, });
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
aStyle.handle(direction, mainElement);
|
|
439
|
+
if (!(aStyle instanceof OverlayPreset) && !(aStyle instanceof KeyFramePreset)) {
|
|
440
|
+
setTimeout(
|
|
441
|
+
() => {
|
|
442
|
+
if (direction == "normal") {
|
|
443
|
+
CallHook("animateEF", { style: aStyle, ele: mainElement, });
|
|
444
|
+
} else if (direction == "reverse") {
|
|
445
|
+
CallHook("animateER", { style: aStyle, ele: mainElement, });
|
|
446
|
+
}
|
|
447
|
+
}, aStyle.duration
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
}
|
|
452
|
+
exports.AnimatePageTransition = AnimatePageTransition;
|