pagewave 1.0.4 → 1.0.6

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 CHANGED
@@ -1,331 +1,350 @@
1
-
2
- # PageWave
3
-
4
- An NPM Package for implementing page transitions in both SSR and CSR apps
5
-
6
-
7
-
8
-
9
- ## Installation
10
-
11
- Downloading the project files from Github (Recommended to allow for service worker to cache pages effectively)
12
-
13
- Install my-project with npm
14
-
15
- ```bash
16
- npm install pagewave
17
- ```
18
-
19
- If gotten from NPM, service worker doesn't get added, so the optional parameter useServiceWorker needs to be false and pages should be cached for optimal transitions.
20
-
21
- ## Features
22
-
23
- - Built-in animations
24
- - Hooks
25
- - Doesn't touch history or use push state, allowing for you to use it with routers like sveltekit
26
- - Manual page transition animations can be run to avoid conflicts with any frameworks
27
- - Customizable ids for divs to avoid conflict with elements in your body
28
- - Allows for custom overlay animations, keyframe animations, or transition animations
29
- - Separate listener animations for different types of animations
30
- - Separate types of links for overlay or other animations
31
-
32
-
33
- ## High Level Explanation
34
-
35
- This package involves two types of animations: Overlay and Keyframe.
36
- - Overlay involve colored divs that move on the screen i.e. screen wipe
37
- - Keyframe involve animations of existing animations i.e. fading away
38
-
39
- These two animations can be created through certain classes
40
- ```javascript
41
- Style Transition
42
- //Utilizes CSS transition to affect a certain value
43
- StyleTransition("opacity", 500, "1", "0")
44
-
45
- KeyFramePreset
46
- //Utilizes one of the packages presets to animate
47
- KeyFramePreset(keyframeType.fade, 250, "ease-in-out");
48
-
49
- KeyFrameCustom
50
- //Utilizes a custom animation
51
- KeyFrameCustom("move", 250, "ease-in-out");
52
-
53
- OverlayPreset
54
- //Utilizes one of the packages presets to animate Div overlay
55
- OverlayPreset(overlayType.bubble, 500, "#293241");
56
-
57
- OverlayCustom
58
- //Creates a custom animation of div(s)
59
- OverlayCustom(
60
- {
61
- "first": "rise",
62
- "second": "fall",
63
- "third": "slide",
64
- "fourth": "inverseSlide",
65
- }, 3000, "#293241", "ease-in-out"
66
- );
67
-
68
- MultiElementAnimation
69
- //Animates many elements independently in the transition
70
- MultiElementAnimation(
71
- {
72
- "h1": "move",
73
- "p": "move",
74
- ".other-header": "inverseMove",
75
- }, 1000, "linear", "fadeAll"
76
- )
77
- ```
78
-
79
- These styles of transition can be used in link clicks, page loads, and manually very easily through functions calls.
80
-
81
- ## TGetting started
82
-
83
- ```javascript
84
- //Optional parameter can be ignored if not downloaded from npm
85
- SetUp({useServiceWorker: false});
86
- ```
87
-
88
- ### Setting up an animation
89
-
90
- Tag the element that encapsulates the content with an id of 'main-content'
91
-
92
- If you can't do that, change the parameter name.
93
-
94
- ```javascript
95
- //Optional parameter can be ignored if not downloaded from npm
96
- SetUp({useServiceWorker: false});
97
-
98
- //Creates a style with preset bubble transition
99
- //Length of 500ms and color of "#293241"
100
- let aSty = new OverlayPreset(
101
- overlayType.bubble, 500, "#293241"
102
- );
103
-
104
- //Makes links use transition and plays transition on page enter
105
- ListenForChange(aSty);
106
-
107
- //Alternatively, split it up if you want different animations for each
108
-
109
- //Makes links use the transitions when going to page
110
- SendPoint(aSty);
111
-
112
- //Makes transition appear when arriving to this page
113
- EndPoint(aSty);
114
-
115
-
116
-
117
- ```
118
-
119
- ## Working with SSR
120
-
121
- Many of these features work flawlessly with CSR.
122
-
123
- However, small changes need to be made depending on what SSR you are using.
124
-
125
- I tested this with Svelte as that is what I am familiar with.
126
-
127
- #### Changes
128
-
129
- - runAnimationOnPageReload needs to be set to true, because hydrating the page only counts as a reload, not a page change
130
- - loadEvent needs to be run independently. I would change it to "load" and call the event separately using dispatch event
131
- - SetUp may not automatically import the preset CSS files, so it may need to be done manually
132
-
133
- ## Other Cool Features
134
-
135
- ### Custom Keyframe Transitions
136
-
137
- This will create an animation style, that when called:
138
-
139
- Moves h1 and p elements to the left
140
-
141
- Moves h2 and elements with 'moving' class to the right
142
-
143
- This is over 1000ms, at a 'linear' pace, and fades everything
144
-
145
- Essentially you can specify specific transitions for certain classes and a global transition for everything
146
-
147
-
148
- ```javascript
149
- SetUp();
150
-
151
- let anim = new MultiElementAnimation(
152
- {
153
- "h1": "move",
154
- "p": "move",
155
- "h2": "inverseMove",
156
- ".moving": "inverseMove",
157
- }, 1000, "linear", "fadeAll"
158
- );
159
-
160
- ListenForChange(anim);
161
-
162
- ...
163
-
164
- <style>
165
-
166
- @keyframes move {
167
- from{
168
- transform: translate(0px, 0px);
169
- color: black;
170
- opacity: 1;
171
- }
172
- to{
173
- transform: translate(-200px, 0px);
174
- opacity: 0;
175
- color: white;
176
- }
177
-
178
- }
179
- @keyframes inverseMove {
180
- from{
181
- transform: translate(0, 0px);
182
- opacity: 1;
183
- }
184
- to{
185
- transform: translate(200px, 0px);
186
- opacity: 0;
187
- }
188
-
189
- }
190
- @keyframes fadeAll {
191
- from{
192
- opacity: 1;
193
- }
194
- to{
195
- opacity: 0;
196
- }
197
- }
198
- </style>
199
-
200
- ```
201
-
202
- ### Custom Overlay Transitions
203
-
204
- The same thing can be done with overlays
205
-
206
- This will run these transitions and the overlays will have the class names of 'first', 'second', etc.
207
-
208
- Run for 3000ms, with a color of #293241 and pace of 'ease-in-out'
209
-
210
- ```javascript
211
- let aStyle = new OverlayCustom(
212
- {
213
- "first": "rise",
214
- "second": "fall",
215
- "third": "slide",
216
- "fourth": "inverseSlide",
217
- }, 3000, "#293241", "ease-in-out"
218
- );
219
-
220
- //Names are presets transitions, so check OverlayPreset.css to see the CSS
221
-
222
- ```
223
-
224
- #### Manual Transitions
225
-
226
- You can do transitions manually through the ```AnimatePageTransition(style)``` function which takes an animation style as a parameter
227
-
228
- ### Different Transitions
229
-
230
- You can have three different animations you can call in the ```SendPoint(), EndPoint(), or ListenForChange()``` function.
231
-
232
- For example:
233
- ```
234
- let defaultAnimation = ...
235
- let overlayAnimation = ...
236
- let keyframeAnimation = ...
237
- SendPoint(defaultAnimation, overlayAnimation, keyframeAnimation);
238
- ```
239
-
240
- You can specify which animation is called by adding classes to link.
241
- - a-overlay for overlayAnimation
242
- - a-animation for keyframeAnimation
243
-
244
-
245
- ### Custom Link function
246
-
247
- By default, this package uses a default function of ```window.location = link;``` for changing links. However, this can be customized in either ```SendPoint() or ListenForChange()```
248
-
249
- ```
250
- let defaultAnimation = ...
251
- let overlayAnimation = ...
252
- let keyframeAnimation = ...
253
- let linkFunction = (link) => {
254
- console.log(link);
255
- window.location = link;
256
- }
257
- SendPoint(defaultAnimation, overlayAnimation, keyframeAnimation, linkFunction);
258
- ```
259
-
260
- This is useful in SSR when the link change function is different from the default one.
261
-
262
- ### Events
263
-
264
- There are many events that can be listened to to call certain code.
265
-
266
- - animateSF - animation start, forward direction
267
- - animateSR - animation start, reverse direction
268
- - animateEF - animation end, forward direction
269
- - animateER - animation end, reverse direction
270
- - animateSSP - start of Send Point listening (when a link is clicked)
271
- - animateESP - end of Send Point listen (when the animation is handled)
272
- - animateSEP - start of end point listen (when the load event is dispatched)
273
- - animateEPNSW - end point no service worker exists (when there is no service worker and service workers are being used)
274
- - animateEEP - end of end point (when the page is revealed after an animation)
275
- - animateEPNA - end point no animation played (when the page is revealed but no animation was played)
276
-
277
-
278
-
279
- ### This program has optional parameters:
280
-
281
- #### Optional Parameter Name : Default Value
282
-
283
- ```javascript
284
- //This is the class for the content that the transition will affect/cover
285
- mainContentIdName: "main-content"
286
-
287
- //This is the class name that a button needs to cause the overlay transitions
288
- overlayClass: "a-overlay",
289
-
290
- //This is the class name that a button needs to cause the key frame transition
291
- animationClass: "a-animation",
292
-
293
- //This is the delay between the page loading and the page beginning the animation
294
- pageAnimationDelay: 200,
295
-
296
- //This is the whether to use a service worker. If using npm, service worker doesn't work, so this needs to be disabled!
297
- useServiceWorker: true,
298
-
299
- //Whether the transition should run when the page is reloaded
300
- //Sometimes needs to be enabled in SSR because of how they treat going from one page to another as reloading
301
- runAnimationOnPageReload: false,
302
-
303
- //Whether the transition should run when a link goes to a different page
304
- runAnimationOnCrossSite: false,
305
-
306
- //The delay between the animation playing and the page revealing
307
- pageRevealDelay: 0,
308
-
309
- //Whether the page should be left after animation
310
- leavePageOnLink: true,
311
-
312
- //What the ID of the element that blocks the page is
313
- pageBlockerId: "pageBlocker",
314
-
315
- //What class should be added to links to not transition
316
- classToIgnoreLink: "ignore-click",
317
-
318
- //Whether ignored links should animate
319
- animateIgnoredLinks: false,
320
-
321
- //Whether links to the same page should animate
322
- animateSelfLink: true,
323
-
324
- //The event that is checked to see that the page is loaded
325
- //Important to change on SSR because this event isn't automatically triggered
326
- loadEvent: "DOMContentLoaded",
327
- ```
328
-
329
- ## Supporting
330
-
331
- If you find this project helpful, considering starring it. I would greatly appreciate it! :)
1
+
2
+ # PageWave
3
+
4
+ An NPM Package for implementing page transitions in both SSR and CSR apps
5
+
6
+
7
+ ## Installation
8
+
9
+ Install pagewave with npm
10
+
11
+ ```bash
12
+ npm install pagewave
13
+ ```
14
+
15
+
16
+ ## Features
17
+
18
+ - Built-in animations
19
+ - Hooks
20
+ - Doesn't touch history or use push state, allowing for you to use it with routers like sveltekit
21
+ - Manual page transition animations can be run to avoid conflicts with any frameworks
22
+ - Customizable ids for divs to avoid conflict with elements in your body
23
+ - Allows for custom animations based on class name of link
24
+ - Preset transition classes to get up and running quickly
25
+ - Highly customizable transition options
26
+ - Extendable class system to create custom transition styles
27
+
28
+
29
+ ## High Level Explanation
30
+
31
+ This package involves allows a user to set up certain routes with names and have those routes triggered either by clicking on a link, loading onto a page, or manually.
32
+
33
+ Utilize transtion classes premade or custom built to handle it.
34
+
35
+ ## Getting started
36
+
37
+ At its core,
38
+
39
+ ```typescript
40
+ import { PageWave, KeyFramePreset, StyleTransition, type KeyFrameType } from 'pagewave';
41
+ import "pagewave/KeyFramePreset.css";
42
+
43
+ let keyFrameType: KeyFrameType = "fadetoright";
44
+
45
+ let fadeToRightTransition = new KeyFrameCustom(
46
+ keyFrameType, 250, "ease-in-out"
47
+ );
48
+
49
+ let defaultTransition = new StyleTransition(
50
+ "opacity", 250, "1", "0"
51
+ );
52
+
53
+ const pw: PageWave = new PageWave(
54
+ {
55
+ "fade": fadeToRightTransition
56
+ },
57
+ );
58
+
59
+ // The following code should be contained within a client function like Sveltekit onMount or React useLayoutEffect if being done in SSR
60
+
61
+ // Setups the transition to occur when loading onto page, with a default transition provided
62
+ pw.EndPoint(defaultTransition);
63
+
64
+ // Setups the transition to occur when a link is clicked, with a default transition provided
65
+ pw.SendPoint(defaultTransition);
66
+
67
+ // Called to start the endpoint
68
+ pw.CallEndPoint();
69
+ ```
70
+
71
+ In this code, there are a few points to note:
72
+ - The arguments in PageWave represent routes that are used by EndPoint and SendPoint
73
+ - For SendPoint, if a link has the class "fade", it will run the fade animation when clicked, and then go to the link. It will also save in sessionStorage the name "fade" under animationType
74
+ - This session storage is used in EndPoint as it looks for a route matching the saved value under animationType. In this code, it would look for fade and play that transition.
75
+ - Just because two pages may have "fade" defined doesn't mean that they have to play the same animation
76
+ - CallEndPoint is utilized in cases where the base event "DOMContentLoaded" isn't called on every page (like in SSR where the layout stays constant)
77
+
78
+ ### Setting up an animation
79
+
80
+ Tag the element that encapsulates the content with an id of 'main-content'
81
+
82
+ If you can't do that, change the parameter name.
83
+
84
+ ```html
85
+ <script>
86
+ import { PageWave, KeyFramePreset, StyleTransition, type KeyFrameType } from 'pagewave'
87
+ import "pagewave/OverlayPreset.css";
88
+ let keyFrameType: OverlayType = "bubble";
89
+
90
+ let bubbleTransition = new OverlayPreset(
91
+ overlayType.bubble, 500, "#293241"
92
+ );
93
+
94
+ let defaultTransition = new StyleTransition(
95
+ "opacity", 250, "1", "0"
96
+ );
97
+
98
+ const pw: PageWave = new PageWave(
99
+ {
100
+ "pagewave-bubble": bubbleTransition
101
+ },
102
+ {
103
+ // These are options. This option is unnecessary as it defaults to "main-content", but showcasing you can change it
104
+ mainContentIdName: "main-content"
105
+ }
106
+ );
107
+
108
+ // The following code should be contained within a client function like Sveltekit onMount or React useLayoutEffect if being done in SSR
109
+
110
+ // Combines Endpoint and Sendpoint if you need individual control
111
+ pw.ListenForChange(defaultTransition);
112
+ pw.CallEndPoint();
113
+
114
+ </script>
115
+
116
+ <!--The area that you want to transition must be marked with id="main-content"-->
117
+ <div id="main-content">
118
+ <h1>This is my page</h1>
119
+ <!-- This link transitions with the pagewave-bubble transition-->
120
+ <a href="..." class="pagewave-bubble">Click me to transition!</a>
121
+ </div>
122
+
123
+ ```
124
+
125
+ ## Working with SSR
126
+
127
+ Because of the nature of SSR, a few changes have to be made:
128
+ - The Send and End Points function must be run in load functions as they make reference to the window for changing the link and dispatching events
129
+ - You need to change the goto Function for SendPoint. Do this by `SendPoint(defaultTransition, () => {/* Function */})`
130
+
131
+ ## Other Cool Features
132
+
133
+ ### Custom Keyframe Transitions
134
+
135
+ This will create an animation style, that when called:
136
+
137
+ Moves h1 and p elements to the left
138
+
139
+ Moves h2 and elements with 'moving' class to the right
140
+
141
+ This is over 1000ms, at a 'linear' pace, and fades everything
142
+
143
+ Essentially you can specify specific transitions for certain classes and a global transition for everything
144
+
145
+
146
+ ```javascript
147
+ ...
148
+
149
+ let multiElementAnimation =l new MultiElementAnimation(
150
+ {
151
+ "h1": "move",
152
+ "p": "move",
153
+ "h2": "inverseMove",
154
+ ".moving": "inverseMove",
155
+ }, 1000, "linear", "fadeAll"
156
+ );
157
+
158
+ pw.ListenForChange(multiElementAnimation);
159
+
160
+ ...
161
+
162
+ <style>
163
+
164
+ @keyframes move {
165
+ from{
166
+ transform: translate(0px, 0px);
167
+ color: black;
168
+ opacity: 1;
169
+ }
170
+ to{
171
+ transform: translate(-200px, 0px);
172
+ opacity: 0;
173
+ color: white;
174
+ }
175
+
176
+ }
177
+ @keyframes inverseMove {
178
+ from{
179
+ transform: translate(0, 0px);
180
+ opacity: 1;
181
+ }
182
+ to{
183
+ transform: translate(200px, 0px);
184
+ opacity: 0;
185
+ }
186
+
187
+ }
188
+ @keyframes fadeAll {
189
+ from{
190
+ opacity: 1;
191
+ }
192
+ to{
193
+ opacity: 0;
194
+ }
195
+ }
196
+ </style>
197
+
198
+ ...
199
+
200
+ ```
201
+
202
+ ### Custom Overlay Transitions
203
+
204
+ There are a few kinds of Custom Overlays
205
+
206
+ OverlayCustom allows you to define which many different overlays and customize them. They will take the key as the class name (if you want to find it) and the value as the animation.
207
+
208
+ After the object of divs, there is
209
+ - duration
210
+ - color of divs
211
+ - timing
212
+ - animation to play while Overlay Animation plays
213
+
214
+ OverlayStyled is similar, except for two parts:
215
+ - The object is now multi level, where the key is still the class name, but the value is object consisting of the animation name and the styles to be applied to the specific div.
216
+ - After all the parameters, there is a new parameter that allows you to change the style of the blocker element. This is useful in cases like the example where since the div is a gradient, the blocker should look like that to be seamless
217
+
218
+ ```javascript
219
+ let customOverlay = new OverlayCustom(
220
+ {
221
+ "first": "rise",
222
+ "second": "fall",
223
+ "third": "slide",
224
+ "fourth": "inverseSlide",
225
+ }, 3000, "#293241", "ease-in-out", null
226
+ );
227
+
228
+ let styledOverlay = new OverlayStyled(
229
+ {
230
+ "first": {
231
+ animationName: "rise",
232
+ cssDesign: {
233
+ "background": "linear-gradient(90deg,rgba(42, 123, 155, 1) 0%, rgba(87, 199, 133, 1) 50%, rgba(237, 221, 83, 1) 100%)"
234
+ }
235
+ },
236
+ }, 3000, "#293241", "ease-in-out", null, {
237
+ "background": "linear-gradient(90deg,rgba(42, 123, 155, 1) 0%, rgba(87, 199, 133, 1) 50%, rgba(237, 221, 83, 1) 100%)"
238
+ }
239
+ )
240
+
241
+ ```
242
+
243
+ #### Manual Transitions
244
+
245
+ You can do transitions manually through the ```AnimatePageTransition(style)``` method which takes a Transitionstyle as a parameter
246
+
247
+
248
+ ### Custom Link function
249
+
250
+ By default, this package uses a default function of ```window.location = link;``` for changing links. However, this can be customized in either ```SendPoint() or ListenForChange()```
251
+
252
+ ```
253
+ let defaultAnimation = ...
254
+ let linkFunction = (link) => {
255
+ console.log(link);
256
+ window.location = link;
257
+ }
258
+ SendPoint(defaultAnimation, linkFunction);
259
+ ```
260
+
261
+ This is useful in SSR when the link change function is different from the default one.
262
+
263
+ ### Events
264
+
265
+ There are many events that can be listened to to call certain code.
266
+
267
+ - animateSF - animation start, forward direction
268
+ - animateSR - animation start, reverse direction
269
+ - animateEF - animation end, forward direction
270
+ - animateER - animation end, reverse direction
271
+ - animateSSP - start of Send Point listening (when a link is clicked)
272
+ - animateESP - end of Send Point listen (when the animation is handled)
273
+ - animateSEP - start of end point listen (when the load event is dispatched)
274
+ - animateEEP - end of end point (when the page is revealed after an animation)
275
+ - animateEPNA - end point no animation played (when the page is revealed but no animation was played)
276
+
277
+ Listen by using window.addEventListener("...", (e) => {
278
+
279
+ })
280
+
281
+ ### This program has optional parameters:
282
+
283
+ #### Optional Parameter Name : Default Value
284
+
285
+ ```javascript
286
+ //This is the class for the content that the transition will affect/cover
287
+ mainContentIdName: "main-content"
288
+
289
+ //This is the delay between the page loading and the page beginning the animation
290
+ pageAnimationDelay: 100,
291
+
292
+ //Whether the transition should run when the page is reloaded
293
+ //Sometimes needs to be enabled in SSR because of how they treat going from one page to another as reloading
294
+ runAnimationOnPageReload: false,
295
+
296
+ //Whether the transition should run when a link goes to a different page
297
+ runAnimationOnCrossSite: false,
298
+
299
+ //The delay between the animation playing and the page revealing
300
+ pageRevealDelay: 0,
301
+
302
+ //Whether the page should be left after animation
303
+ leavePageOnLink: true,
304
+
305
+ //What the ID of the element that blocks the page is
306
+ pageBlockerId: "pageBlocker",
307
+
308
+ //What class should be added to links to not transition
309
+ classToIgnoreLink: "ignore-click",
310
+
311
+ //Whether ignored links should animate
312
+ animateIgnoredLinks: false,
313
+
314
+ //Whether links to the same page should animate
315
+ animateSelfLink: true,
316
+
317
+ //The event that is checked to see that the page is loaded and what CallEndPoint dispatches
318
+ loadEvent: "DOMContentLoaded",
319
+
320
+ // When true, it will ignore transitioning on a link if no animation is found in the class list
321
+ // Otherwise, it will transition every time unless explicitly told to ignore
322
+ preferIgnore: false
323
+ ```
324
+
325
+ ## Extending with Custom Transition classes
326
+ PageWave provides many custom classes to create beautiful transitions:
327
+ - **KeyFrameCustom** for a custom transition animation on main-content
328
+ - **KeyFramePreset** to utilize premade animations for getting started quickly
329
+ - **MultiElementAnimation** to animate multiple elements and have more fine grained control
330
+ - **OverlayCustom** for a custom overlay animation
331
+ - **OverlayPreset** to utilize premade overlay animations for getting started quickly
332
+ - **OverlayStyled** to have complete control over how an overlay animation looks
333
+ - **StyleTransition** to utilize the transition css property to animate a single property
334
+
335
+ However, if you need to do something not listed here, the class system can be easily extended.
336
+
337
+ To do so, you must implement the TransitionStyleInterface which requires a few parts to be defined:
338
+ - duration: number (how long the animation lasts)
339
+ - timing: TimingType (how the animation moves)
340
+ - handle(direction: DirectionType, mainElement: HTMLElement) : void (runs the actual transition animation)
341
+ - hidePage(options: OptionsType) : void (hides the page either before or after animation)
342
+ - revealPage(options: OptionsType): void (reveals the page once animation needs to be shown)
343
+
344
+ PageWave does the rest of the work on using these functions to create seamless transitions.
345
+
346
+ If you want to use a preexisting implementation, you can use KeyFrameBase or OverlayBase which power many of their respective child classes.
347
+
348
+ ## Supporting
349
+
350
+ If you find this project helpful, considering starring ⭐ it. I would greatly appreciate it! :)