swup 4.0.0-rc.14 → 4.0.0-rc.21
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 +100 -0
- package/dist/Swup.cjs +1 -1
- package/dist/Swup.cjs.map +1 -1
- package/dist/Swup.modern.js +1 -1
- package/dist/Swup.modern.js.map +1 -1
- package/dist/Swup.module.js +1 -1
- package/dist/Swup.module.js.map +1 -1
- package/dist/Swup.umd.js +1 -1
- package/dist/Swup.umd.js.map +1 -1
- package/dist/types/Swup.d.ts +62 -54
- package/dist/types/helpers/Location.d.ts +10 -7
- package/dist/types/helpers/delegateEvent.d.ts +3 -5
- package/dist/types/helpers/matchPath.d.ts +3 -0
- package/dist/types/helpers.d.ts +7 -10
- package/dist/types/index.d.ts +9 -6
- package/dist/types/modules/Cache.d.ts +15 -15
- package/dist/types/modules/Classes.d.ts +13 -0
- package/dist/types/modules/Context.d.ts +73 -0
- package/dist/types/modules/Hooks.d.ts +241 -0
- package/dist/types/modules/__test__/hooks.test.d.ts +1 -0
- package/dist/types/modules/__test__/replaceContent.test.d.ts +1 -0
- package/dist/types/modules/awaitAnimations.d.ts +21 -0
- package/dist/types/modules/enterPage.d.ts +6 -3
- package/dist/types/modules/fetchPage.d.ts +24 -4
- package/dist/types/modules/getAnchorElement.d.ts +8 -0
- package/dist/types/modules/leavePage.d.ts +6 -3
- package/dist/types/modules/plugins.d.ts +12 -5
- package/dist/types/modules/renderPage.d.ts +7 -7
- package/dist/types/modules/replaceContent.d.ts +8 -11
- package/dist/types/modules/visit.d.ts +33 -0
- package/dist/types/utils/index.d.ts +3 -1
- package/dist/types/utils.d.ts +1 -1
- package/package.json +7 -6
- package/src/Swup.ts +83 -65
- package/src/__test__/index.test.ts +3 -3
- package/src/helpers/Location.ts +2 -2
- package/src/helpers/delegateEvent.ts +2 -2
- package/src/helpers.ts +0 -1
- package/src/index.ts +34 -4
- package/src/modules/Cache.ts +2 -2
- package/src/modules/Classes.ts +48 -0
- package/src/modules/Context.ts +49 -19
- package/src/modules/Hooks.ts +103 -83
- package/src/modules/__test__/cache.test.ts +6 -6
- package/src/modules/__test__/hooks.test.ts +111 -40
- package/src/modules/__test__/replaceContent.test.ts +92 -0
- package/src/modules/{getAnimationPromises.ts → awaitAnimations.ts} +13 -18
- package/src/modules/enterPage.ts +21 -17
- package/src/modules/fetchPage.ts +12 -12
- package/src/modules/getAnchorElement.ts +2 -1
- package/src/modules/leavePage.ts +16 -12
- package/src/modules/plugins.ts +11 -8
- package/src/modules/renderPage.ts +28 -18
- package/src/modules/replaceContent.ts +24 -16
- package/src/modules/visit.ts +143 -0
- package/src/utils/index.ts +1 -2
- package/dist/types/helpers/cleanupAnimationClasses.d.ts +0 -2
- package/dist/types/helpers/fetch.d.ts +0 -5
- package/dist/types/helpers/getDataFromHtml.d.ts +0 -7
- package/dist/types/helpers/markSwupElements.d.ts +0 -1
- package/dist/types/modules/destroy.d.ts +0 -2
- package/dist/types/modules/enable.d.ts +0 -2
- package/dist/types/modules/events.d.ts +0 -33
- package/dist/types/modules/getAnimationPromises.d.ts +0 -7
- package/dist/types/modules/getPageData.d.ts +0 -6
- package/dist/types/modules/handleLinkToSamePage.d.ts +0 -2
- package/dist/types/modules/isSameResolvedUrl.d.ts +0 -8
- package/dist/types/modules/linkClickHandler.d.ts +0 -3
- package/dist/types/modules/loadPage.d.ts +0 -12
- package/dist/types/modules/off.d.ts +0 -3
- package/dist/types/modules/on.d.ts +0 -5
- package/dist/types/modules/popStateHandler.d.ts +0 -2
- package/dist/types/modules/resolveUrl.d.ts +0 -7
- package/dist/types/modules/shouldIgnoreVisit.d.ts +0 -4
- package/dist/types/modules/transitions.d.ts +0 -6
- package/dist/types/modules/triggerEvent.d.ts +0 -3
- package/dist/types/modules/triggerWillOpenNewWindow.d.ts +0 -2
- package/dist/types/modules/updateTransition.d.ts +0 -2
- package/readme.md +0 -78
- package/src/helpers/cleanupAnimationClasses.ts +0 -8
- package/src/modules/loadPage.ts +0 -99
- /package/dist/types/{modules/__test__/events.test.d.ts → helpers/__test__/matchPath.test.d.ts} +0 -0
- /package/dist/types/modules/__test__/{fetchPage.test.d.ts → cache.test.d.ts} +0 -0
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import Swup from '../Swup';
|
|
2
|
-
import delegate from 'delegate-it';
|
|
3
|
-
type HandlersEventMap = {
|
|
4
|
-
animationInDone: undefined;
|
|
5
|
-
animationInStart: undefined;
|
|
6
|
-
animationOutDone: undefined;
|
|
7
|
-
animationOutStart: undefined;
|
|
8
|
-
animationSkipped: undefined;
|
|
9
|
-
clickLink: delegate.Event<MouseEvent>;
|
|
10
|
-
contentReplaced: PopStateEvent | undefined;
|
|
11
|
-
disabled: undefined;
|
|
12
|
-
enabled: undefined;
|
|
13
|
-
openPageInNewTab: delegate.Event<MouseEvent>;
|
|
14
|
-
pageLoaded: undefined;
|
|
15
|
-
pageRetrievedFromCache: undefined;
|
|
16
|
-
pageView: PopStateEvent | undefined;
|
|
17
|
-
popState: PopStateEvent;
|
|
18
|
-
samePage: delegate.Event<MouseEvent>;
|
|
19
|
-
samePageWithHash: delegate.Event<MouseEvent>;
|
|
20
|
-
serverError: undefined;
|
|
21
|
-
transitionStart: PopStateEvent | undefined;
|
|
22
|
-
transitionEnd: PopStateEvent | undefined;
|
|
23
|
-
willReplaceContent: PopStateEvent | undefined;
|
|
24
|
-
};
|
|
25
|
-
type AvailableEventNames = keyof HandlersEventMap;
|
|
26
|
-
export type Handler<T extends keyof HandlersEventMap> = (event: HandlersEventMap[T]) => void;
|
|
27
|
-
export type Handlers = {
|
|
28
|
-
[Key in keyof HandlersEventMap]: Handler<Key>[];
|
|
29
|
-
};
|
|
30
|
-
export declare function on<TEventType extends AvailableEventNames>(this: Swup, event: TEventType, handler: Handler<TEventType>): void;
|
|
31
|
-
export declare function off<TEventType extends AvailableEventNames>(this: Swup, event?: TEventType, handler?: Handler<TEventType>): void;
|
|
32
|
-
export declare function triggerEvent<TEventType extends AvailableEventNames>(this: Swup, eventName: TEventType, originalEvent?: HandlersEventMap[TEventType]): void;
|
|
33
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import Swup from '../Swup';
|
|
2
|
-
export declare function getAnimationPromises(this: Swup, animationType: 'in' | 'out'): Promise<void>[];
|
|
3
|
-
export declare function getTransitionInfo(element: Element, expectedType?: 'animation' | 'transition' | null): {
|
|
4
|
-
type: string | null;
|
|
5
|
-
timeout: number;
|
|
6
|
-
propCount: number;
|
|
7
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { InternalSwup } from '../Swup';
|
|
2
|
-
/**
|
|
3
|
-
* Compares the resolved version of two paths and returns true if they are the same
|
|
4
|
-
* @param {string} url1
|
|
5
|
-
* @param {string} url2
|
|
6
|
-
* @returns {boolean}
|
|
7
|
-
*/
|
|
8
|
-
export declare const isSameResolvedUrl: (this: InternalSwup, url1: string, url2: string) => boolean;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import Swup from '../Swup';
|
|
2
|
-
export type TransitionOptions = {
|
|
3
|
-
url: string;
|
|
4
|
-
customTransition?: string;
|
|
5
|
-
};
|
|
6
|
-
export type PageLoadOptions = {
|
|
7
|
-
url: string;
|
|
8
|
-
event?: PopStateEvent;
|
|
9
|
-
customTransition?: string;
|
|
10
|
-
};
|
|
11
|
-
export declare function loadPage(this: Swup, data: TransitionOptions): void;
|
|
12
|
-
export declare function performPageLoad(this: Swup, data: PageLoadOptions): void;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import Swup from '../Swup';
|
|
2
|
-
export type EventType = 'animationInDone' | 'animationInStart' | 'animationOutDone' | 'animationOutStart' | 'animationSkipped' | 'clickLink' | 'contentReplaced' | 'disabled' | 'enabled' | 'openPageInNewTab' | 'pageLoaded' | 'pageRetrievedFromCache' | 'pageView' | 'popState' | 'samePage' | 'samePageWithHash' | 'serverError' | 'transitionStart' | 'transitionEnd' | 'willReplaceContent';
|
|
3
|
-
export type Handler = (event?: Event) => void;
|
|
4
|
-
export type Handlers = Record<EventType, Handler[]>;
|
|
5
|
-
export declare const on: (this: Swup, event: EventType, handler: Handler) => void;
|
package/readme.md
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
<br>
|
|
2
|
-
|
|
3
|
-
<p align="center">
|
|
4
|
-
<img width="280" alt="swup" src="https://swup.js.org/assets/images/swup-logo.svg">
|
|
5
|
-
</p>
|
|
6
|
-
|
|
7
|
-
<p align="center">
|
|
8
|
-
<a href="https://www.npmjs.com/package/swup"><img src="https://img.shields.io/npm/v/swup.svg" alt="npm version"></a>
|
|
9
|
-
<a href="https://bundlephobia.com/package/swup"><img src="https://img.shields.io/bundlephobia/minzip/swup?label=size" alt="Bundle size"></a>
|
|
10
|
-
<a href="https://github.com/gmrchk/swup/blob/master/LICENSE"><img src="https://img.shields.io/github/license/gmrchk/swup.svg" alt="License"></a>
|
|
11
|
-
<a href="https://www.npmjs.com/package/swup"><img src="https://img.shields.io/npm/dt/swup.svg" alt="npm downloads"></a>
|
|
12
|
-
<a href="https://github.com/swup/swup/actions/workflows/e2e-tests.yml"><img src="https://img.shields.io/github/actions/workflow/status/swup/swup/e2e-tests.yml?branch=master&label=tests" alt="Test status"></a>
|
|
13
|
-
</p>
|
|
14
|
-
|
|
15
|
-
<br>
|
|
16
|
-
|
|
17
|
-
# Swup
|
|
18
|
-
|
|
19
|
-
Versatile and extensible page transition library for server-side rendered websites
|
|
20
|
-
|
|
21
|
-
[Features](#features) •
|
|
22
|
-
[Documentation](https://swup.js.org/getting-started) •
|
|
23
|
-
[Plugins](https://swup.js.org/plugins) •
|
|
24
|
-
[Themes](https://swup.js.org/themes) •
|
|
25
|
-
[Discussions](https://github.com/swup/swup/discussions)
|
|
26
|
-
|
|
27
|
-
## Overview
|
|
28
|
-
|
|
29
|
-
Swup adds page transitions to server-side rendered websites. It manages the complete lifecycle of a
|
|
30
|
-
page visit by intercepting link clicks, loading the new page in the background and smoothly
|
|
31
|
-
transitioning between the old and new content.
|
|
32
|
-
|
|
33
|
-
Its goal is to make it effortless to add page transitions to a site, while providing lots of other
|
|
34
|
-
quality-of-life improvements.
|
|
35
|
-
|
|
36
|
-
## Features
|
|
37
|
-
|
|
38
|
-
- ✏️ Works out of the box with [minimal markup](https://swup.js.org/getting-started/example/)
|
|
39
|
-
- ✨ Auto-detects [CSS transitions](https://swup.js.org/getting-started/how-it-works/) for perfect timing
|
|
40
|
-
- 🔗 Updates URLs and preserves native [browser history](https://swup.js.org/options/#animatehistorybrowsing)
|
|
41
|
-
- 🏓 Manages scroll position between pages and anchor jump links
|
|
42
|
-
- 🚀 Uses a [cache](https://swup.js.org/api/cache/) to speed up subsequent page loads
|
|
43
|
-
- 📡 Offers [hooks](https://swup.js.org/hooks/) to customize and extend the page load lifecycle
|
|
44
|
-
- 🔌 Has a powerful [plugin system](https://swup.js.org/plugins/) and many official and third-party plugins
|
|
45
|
-
- 🎨 Provides ready-to-go [themes](https://swup.js.org/themes/) to get started quickly
|
|
46
|
-
|
|
47
|
-
## Plugins
|
|
48
|
-
|
|
49
|
-
Swup is small by design. Extended features can be added via [plugins](https://swup.js.org/plugins/):
|
|
50
|
-
|
|
51
|
-
- Display a [progress bar](https://swup.js.org/plugins/progress-plugin/) while loading
|
|
52
|
-
- Enable [smooth scrolling](https://swup.js.org/plugins/scroll-plugin/) between visits
|
|
53
|
-
- Update [meta tags and stylesheets](https://swup.js.org/plugins/head-plugin/) after page loads
|
|
54
|
-
- Add support for [preloading pages](https://swup.js.org/plugins/preload-plugin/) in the background
|
|
55
|
-
- Improve [accessibility](https://swup.js.org/plugins/a11y-plugin/) for screen readers
|
|
56
|
-
- Perform your [animations in JS](https://swup.js.org/plugins/js-plugin/) instead of CSS transitions
|
|
57
|
-
- Animate [form submissions](https://swup.js.org/plugins/forms-plugin/)
|
|
58
|
-
- Get help in [debug mode](https://swup.js.org/plugins/debug-plugin/)
|
|
59
|
-
|
|
60
|
-
Check out the list of [all official plugins](https://swup.js.org/plugins/) as well as
|
|
61
|
-
[third-party integrations](https://swup.js.org/third-party-integrations/).
|
|
62
|
-
|
|
63
|
-
## Examples
|
|
64
|
-
|
|
65
|
-
<img src="https://user-images.githubusercontent.com/9338324/49190360-50125480-f372-11e8-89e9-d2fb091a2240.gif" width="100%">
|
|
66
|
-
|
|
67
|
-
Take a look at [Sites using swup](https://github.com/swup/swup/discussions/333) for more examples.
|
|
68
|
-
|
|
69
|
-
## Having trouble?
|
|
70
|
-
|
|
71
|
-
If you're having trouble implementing swup, check out the [Common Issues](https://swup.js.org/other/common-issues) section of the docs, look at [closed issues](https://github.com/gmrchk/swup/issues?q=is%3Aissue+is%3Aclosed) or create a [new discussion](https://github.com/swup/swup/discussions/new).
|
|
72
|
-
|
|
73
|
-
## Want to Contribute?
|
|
74
|
-
|
|
75
|
-
<a href="https://github.com/swup/swup/discussions/424">We're looking for maintainers!</a> 👀
|
|
76
|
-
|
|
77
|
-
Become a sponsor on [Open Collective](https://opencollective.com/swup) or support development through
|
|
78
|
-
[GitHub sponsors](https://github.com/sponsors/gmrchk).
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export const isSwupClass = (className: string): boolean =>
|
|
2
|
-
/^to-/.test(className) || ['is-changing', 'is-rendering', 'is-popstate'].includes(className);
|
|
3
|
-
|
|
4
|
-
export const cleanupAnimationClasses = (): void => {
|
|
5
|
-
const htmlClasses = document.documentElement.className.split(' ');
|
|
6
|
-
const removeClasses = htmlClasses.filter(isSwupClass);
|
|
7
|
-
document.documentElement.classList.remove(...removeClasses);
|
|
8
|
-
};
|
package/src/modules/loadPage.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import Swup from '../Swup.js';
|
|
2
|
-
import { createHistoryRecord, updateHistoryRecord, getCurrentUrl, Location } from '../helpers.js';
|
|
3
|
-
import { FetchOptions } from '../modules/fetchPage.js';
|
|
4
|
-
import { ContextInitOptions } from './Context.js';
|
|
5
|
-
|
|
6
|
-
export type HistoryAction = 'push' | 'replace';
|
|
7
|
-
|
|
8
|
-
export type PageLoadOptions = {
|
|
9
|
-
animate?: boolean;
|
|
10
|
-
transition?: string;
|
|
11
|
-
history?: HistoryAction;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export function loadPage(
|
|
15
|
-
this: Swup,
|
|
16
|
-
url: string,
|
|
17
|
-
options: PageLoadOptions & FetchOptions = {},
|
|
18
|
-
context: Omit<ContextInitOptions, 'to'> = {}
|
|
19
|
-
) {
|
|
20
|
-
// Check if the visit should be ignored
|
|
21
|
-
if (this.shouldIgnoreVisit(url)) {
|
|
22
|
-
window.location.href = url;
|
|
23
|
-
} else {
|
|
24
|
-
const { url: to, hash } = Location.fromUrl(url);
|
|
25
|
-
this.context = this.createContext({ ...context, to, hash });
|
|
26
|
-
this.performPageLoad(to, options);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export async function performPageLoad(
|
|
31
|
-
this: Swup,
|
|
32
|
-
url: string,
|
|
33
|
-
options: PageLoadOptions & FetchOptions = {}
|
|
34
|
-
) {
|
|
35
|
-
if (typeof url !== 'string') {
|
|
36
|
-
throw new Error(`loadPage requires a URL parameter`);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const { url: requestedUrl } = Location.fromUrl(url);
|
|
40
|
-
const { transition, animate, history: historyAction } = options;
|
|
41
|
-
options.referrer = options.referrer || this.currentPageUrl;
|
|
42
|
-
|
|
43
|
-
if (animate === false) {
|
|
44
|
-
this.context.transition.animate = false;
|
|
45
|
-
}
|
|
46
|
-
if (historyAction) {
|
|
47
|
-
this.context.history.action = historyAction;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (!this.context.transition.animate) {
|
|
51
|
-
document.documentElement.classList.remove('is-animating');
|
|
52
|
-
this.cleanupAnimationClasses();
|
|
53
|
-
} else if (transition) {
|
|
54
|
-
this.context.transition.name = transition;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
await this.hooks.trigger('transitionStart');
|
|
59
|
-
const animationPromise = this.leavePage();
|
|
60
|
-
const pagePromise = this.hooks.trigger(
|
|
61
|
-
'loadPage',
|
|
62
|
-
{ url, options },
|
|
63
|
-
async (context, { url, options, page }) => await (page || this.fetchPage(url, options))
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
// create history record if this is not a popstate call (with or without anchor)
|
|
67
|
-
if (!this.context.history.popstate) {
|
|
68
|
-
const newUrl = url + (this.context.scroll.target || '');
|
|
69
|
-
if (this.context.history.action === 'replace') {
|
|
70
|
-
updateHistoryRecord(newUrl);
|
|
71
|
-
} else {
|
|
72
|
-
createHistoryRecord(newUrl);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
this.currentPageUrl = getCurrentUrl();
|
|
77
|
-
|
|
78
|
-
// when everything is ready, render the page
|
|
79
|
-
const [page] = await Promise.all([pagePromise, animationPromise]);
|
|
80
|
-
this.renderPage(requestedUrl, page);
|
|
81
|
-
} catch (error: unknown) {
|
|
82
|
-
// Return early if error is undefined (probably aborted preload request)
|
|
83
|
-
if (!error) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Log to console as we swallow almost all hook errors
|
|
88
|
-
console.error(error);
|
|
89
|
-
|
|
90
|
-
// Rewrite `skipPopStateHandling` to redirect manually when `history.go` is processed
|
|
91
|
-
this.options.skipPopStateHandling = () => {
|
|
92
|
-
window.location.href = requestedUrl;
|
|
93
|
-
return true;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
// Go back to the actual page we're still at
|
|
97
|
-
history.go(-1);
|
|
98
|
-
}
|
|
99
|
-
}
|
/package/dist/types/{modules/__test__/events.test.d.ts → helpers/__test__/matchPath.test.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|