swup 3.1.1 → 4.0.0-rc.20
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 +94 -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 +53 -45
- package/dist/types/helpers/Location.d.ts +10 -7
- package/dist/types/helpers/delegateEvent.d.ts +2 -2
- package/dist/types/helpers/matchPath.d.ts +3 -0
- package/dist/types/helpers.d.ts +1 -4
- package/dist/types/index.d.ts +7 -4
- package/dist/types/modules/Cache.d.ts +14 -14
- 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__/cache.test.d.ts +1 -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 +5 -2
- package/dist/types/modules/fetchPage.d.ts +23 -3
- package/dist/types/modules/getAnchorElement.d.ts +2 -1
- package/dist/types/modules/leavePage.d.ts +5 -2
- package/dist/types/modules/plugins.d.ts +7 -0
- package/dist/types/modules/renderPage.d.ts +6 -6
- 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/package.json +13 -9
- package/src/Swup.ts +172 -182
- package/src/__test__/index.test.ts +8 -3
- package/src/helpers/Location.ts +12 -9
- package/src/helpers/__test__/matchPath.test.ts +54 -0
- package/src/helpers/delegateEvent.ts +3 -2
- package/src/helpers/matchPath.ts +22 -0
- package/src/helpers.ts +2 -5
- package/src/index.ts +36 -4
- package/src/modules/Cache.ts +43 -33
- package/src/modules/Classes.ts +48 -0
- package/src/modules/Context.ts +121 -0
- package/src/modules/Hooks.ts +413 -0
- package/src/modules/__test__/cache.test.ts +142 -0
- package/src/modules/__test__/hooks.test.ts +263 -0
- package/src/modules/__test__/replaceContent.test.ts +92 -0
- package/src/modules/awaitAnimations.ts +169 -0
- package/src/modules/enterPage.ts +23 -17
- package/src/modules/fetchPage.ts +74 -29
- package/src/modules/getAnchorElement.ts +2 -1
- package/src/modules/leavePage.ts +26 -20
- package/src/modules/plugins.ts +7 -2
- package/src/modules/renderPage.ts +52 -33
- package/src/modules/replaceContent.ts +33 -16
- package/src/modules/visit.ts +143 -0
- package/src/utils/index.ts +25 -5
- 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/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/loadPage.d.ts +0 -15
- package/dist/types/modules/transitions.d.ts +0 -6
- package/readme.md +0 -60
- package/src/helpers/cleanupAnimationClasses.ts +0 -8
- package/src/helpers/fetch.ts +0 -33
- package/src/helpers/getDataFromHtml.ts +0 -39
- package/src/helpers/markSwupElements.ts +0 -16
- package/src/modules/__test__/events.test.ts +0 -72
- package/src/modules/events.ts +0 -92
- package/src/modules/getAnimationPromises.ts +0 -183
- package/src/modules/getPageData.ts +0 -24
- package/src/modules/loadPage.ts +0 -81
- package/src/modules/transitions.ts +0 -10
- /package/dist/types/{modules/__test__/events.test.d.ts → helpers/__test__/matchPath.test.d.ts} +0 -0
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import Swup, { Options } from './Swup.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import Swup, { type Options } from './Swup.js';
|
|
2
|
+
import type { CacheData } from './modules/Cache.js';
|
|
3
|
+
import type { Context, FromContext, ToContext, AnimationContext, ScrollContext, HistoryContext } from './modules/Context.js';
|
|
4
|
+
import type { Plugin } from './modules/plugins.js';
|
|
5
|
+
import type { HookDefinitions, HookName, HookOptions, HookUnregister, Handler } from './modules/Hooks.js';
|
|
6
|
+
import type { Path } from 'path-to-regexp';
|
|
4
7
|
export default Swup;
|
|
5
8
|
export * from './helpers.js';
|
|
6
9
|
export * from './utils.js';
|
|
7
|
-
export type { Options, Plugin, Handler };
|
|
10
|
+
export type { Options, Plugin, CacheData, Context, FromContext, ToContext, AnimationContext, ScrollContext, HistoryContext, HookDefinitions, HookName, HookOptions, HookUnregister, Handler, Path };
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import Swup from '../Swup.js';
|
|
2
|
-
import { PageData } from './
|
|
3
|
-
export interface
|
|
4
|
-
url: string;
|
|
5
|
-
responseURL: string;
|
|
2
|
+
import { PageData } from './fetchPage.js';
|
|
3
|
+
export interface CacheData extends PageData {
|
|
6
4
|
}
|
|
7
5
|
export declare class Cache {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
swup: Swup;
|
|
6
|
+
private swup;
|
|
7
|
+
private pages;
|
|
11
8
|
constructor(swup: Swup);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
get size(): number;
|
|
10
|
+
get all(): Map<string, CacheData>;
|
|
11
|
+
has(url: string): boolean;
|
|
12
|
+
get(url: string): CacheData | undefined;
|
|
13
|
+
set(url: string, page: CacheData): void;
|
|
14
|
+
update(url: string, page: CacheData): void;
|
|
15
|
+
delete(url: string): void;
|
|
16
|
+
clear(): void;
|
|
17
|
+
prune(predicate: (url: string, page: CacheData) => boolean): void;
|
|
18
|
+
private resolve;
|
|
19
19
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Swup from '../Swup.js';
|
|
2
|
+
export declare class Classes {
|
|
3
|
+
swup: Swup;
|
|
4
|
+
swupClasses: string[];
|
|
5
|
+
constructor(swup: Swup);
|
|
6
|
+
get selectors(): string[];
|
|
7
|
+
get selector(): string;
|
|
8
|
+
get targets(): HTMLElement[];
|
|
9
|
+
add(...classes: string[]): void;
|
|
10
|
+
remove(...classes: string[]): void;
|
|
11
|
+
clear(): void;
|
|
12
|
+
private isSwupClass;
|
|
13
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import Swup, { Options } from '../Swup.js';
|
|
2
|
+
import { HistoryAction, HistoryDirection } from './visit.js';
|
|
3
|
+
export interface Context<TEvent = Event> {
|
|
4
|
+
/** The previous page, about to leave */
|
|
5
|
+
from: FromContext;
|
|
6
|
+
/** The next page, about to enter */
|
|
7
|
+
to: ToContext;
|
|
8
|
+
/** The content containers, about to be replaced */
|
|
9
|
+
containers: Options['containers'];
|
|
10
|
+
/** Information about animated page transitions */
|
|
11
|
+
animation: AnimationContext;
|
|
12
|
+
/** What triggered this visit */
|
|
13
|
+
trigger: TriggerContext<TEvent>;
|
|
14
|
+
/** Browser history behavior on this visit */
|
|
15
|
+
history: HistoryContext;
|
|
16
|
+
/** Scroll behavior on this visit */
|
|
17
|
+
scroll: ScrollContext;
|
|
18
|
+
}
|
|
19
|
+
export interface FromContext {
|
|
20
|
+
/** The URL of the previous page */
|
|
21
|
+
url: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ToContext {
|
|
24
|
+
/** The URL of the next page */
|
|
25
|
+
url?: string;
|
|
26
|
+
/** The HTML content of the next page */
|
|
27
|
+
html?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface AnimationContext {
|
|
30
|
+
/** Whether this visit is animated. Default: `true` */
|
|
31
|
+
animate: boolean;
|
|
32
|
+
/** Whether to wait for the next page to load before starting the animation. Default: `false` */
|
|
33
|
+
wait: boolean;
|
|
34
|
+
/** Name of a custom animation to run. */
|
|
35
|
+
name?: string;
|
|
36
|
+
/** Elements on which to add animation classes. Default: `html` element */
|
|
37
|
+
scope: 'html' | 'containers' | string[];
|
|
38
|
+
/** Selector for detecting animation timing. Default: `[class*="transition-"]` */
|
|
39
|
+
selector: Options['animationSelector'];
|
|
40
|
+
}
|
|
41
|
+
export interface ScrollContext {
|
|
42
|
+
/** Whether to reset the scroll position after the visit. Default: `true` */
|
|
43
|
+
reset: boolean;
|
|
44
|
+
/** Anchor element to scroll to on the next page. */
|
|
45
|
+
target?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface TriggerContext<TEvent = Event> {
|
|
48
|
+
/** DOM element that triggered this visit. */
|
|
49
|
+
el?: Element;
|
|
50
|
+
/** DOM event that triggered this visit. */
|
|
51
|
+
event?: TEvent;
|
|
52
|
+
}
|
|
53
|
+
export interface HistoryContext {
|
|
54
|
+
/** History action to perform: `push` for creating a new history entry, `replace` for replacing the current entry. Default: `push` */
|
|
55
|
+
action: HistoryAction;
|
|
56
|
+
/** Whether this visit was triggered by a browser history navigation. */
|
|
57
|
+
popstate: boolean;
|
|
58
|
+
/** The direction of travel in case of a browser history navigation: backward or forward. */
|
|
59
|
+
direction: HistoryDirection | undefined;
|
|
60
|
+
}
|
|
61
|
+
export interface ContextInitOptions {
|
|
62
|
+
to: string | undefined;
|
|
63
|
+
from?: string;
|
|
64
|
+
hash?: string;
|
|
65
|
+
animate?: boolean;
|
|
66
|
+
animation?: string;
|
|
67
|
+
targets?: string[];
|
|
68
|
+
el?: Element;
|
|
69
|
+
event?: Event;
|
|
70
|
+
action?: HistoryAction;
|
|
71
|
+
resetScroll?: boolean;
|
|
72
|
+
}
|
|
73
|
+
export declare function createContext(this: Swup, { to, from, hash: target, animate, animation: name, el, event, action, resetScroll: reset }: ContextInitOptions): Context;
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { DelegateEvent } from 'delegate-it';
|
|
2
|
+
import Swup from '../Swup.js';
|
|
3
|
+
import { Context } from './Context.js';
|
|
4
|
+
import { FetchOptions, PageData } from './fetchPage.js';
|
|
5
|
+
import { AnimationDirection } from './awaitAnimations.js';
|
|
6
|
+
export interface HookDefinitions {
|
|
7
|
+
'animation:out:start': undefined;
|
|
8
|
+
'animation:out:end': undefined;
|
|
9
|
+
'animation:in:start': undefined;
|
|
10
|
+
'animation:in:end': undefined;
|
|
11
|
+
'animation:skip': undefined;
|
|
12
|
+
'animation:await': {
|
|
13
|
+
direction: AnimationDirection;
|
|
14
|
+
};
|
|
15
|
+
'cache:clear': undefined;
|
|
16
|
+
'cache:set': {
|
|
17
|
+
page: PageData;
|
|
18
|
+
};
|
|
19
|
+
'content:replace': {
|
|
20
|
+
page: PageData;
|
|
21
|
+
};
|
|
22
|
+
'content:scroll': {
|
|
23
|
+
options: ScrollIntoViewOptions;
|
|
24
|
+
};
|
|
25
|
+
'enable': undefined;
|
|
26
|
+
'disable': undefined;
|
|
27
|
+
'fetch:request': {
|
|
28
|
+
url: string;
|
|
29
|
+
options: FetchOptions;
|
|
30
|
+
};
|
|
31
|
+
'fetch:error': {
|
|
32
|
+
url: string;
|
|
33
|
+
status: number;
|
|
34
|
+
response: Response;
|
|
35
|
+
};
|
|
36
|
+
'history:popstate': {
|
|
37
|
+
event: PopStateEvent;
|
|
38
|
+
};
|
|
39
|
+
'link:click': {
|
|
40
|
+
el: HTMLAnchorElement;
|
|
41
|
+
event: DelegateEvent<MouseEvent>;
|
|
42
|
+
};
|
|
43
|
+
'link:self': undefined;
|
|
44
|
+
'link:anchor': {
|
|
45
|
+
hash: string;
|
|
46
|
+
options: ScrollIntoViewOptions;
|
|
47
|
+
};
|
|
48
|
+
'link:newtab': {
|
|
49
|
+
href: string;
|
|
50
|
+
};
|
|
51
|
+
'page:request': {
|
|
52
|
+
url: string;
|
|
53
|
+
options: FetchOptions;
|
|
54
|
+
};
|
|
55
|
+
'page:load': {
|
|
56
|
+
page: PageData;
|
|
57
|
+
cache?: boolean;
|
|
58
|
+
};
|
|
59
|
+
'page:view': {
|
|
60
|
+
url: string;
|
|
61
|
+
title: string;
|
|
62
|
+
};
|
|
63
|
+
'visit:start': undefined;
|
|
64
|
+
'visit:end': undefined;
|
|
65
|
+
}
|
|
66
|
+
export type HookArguments<T extends HookName> = HookDefinitions[T];
|
|
67
|
+
export type HookName = keyof HookDefinitions;
|
|
68
|
+
export type Handler<T extends HookName> = (
|
|
69
|
+
/** The global context object for the current visit */
|
|
70
|
+
context: Context,
|
|
71
|
+
/** The local arguments passed into the handler */
|
|
72
|
+
args: HookArguments<T>,
|
|
73
|
+
/** The default handler to be executed, available if replacing an internal hook handler */
|
|
74
|
+
defaultHandler?: Handler<T>) => Promise<any> | void;
|
|
75
|
+
export type Handlers = {
|
|
76
|
+
[K in HookName]: Handler<K>[];
|
|
77
|
+
};
|
|
78
|
+
export type HookUnregister = () => void;
|
|
79
|
+
export type HookOptions = {
|
|
80
|
+
/** Execute the hook once, then remove the handler */
|
|
81
|
+
once?: boolean;
|
|
82
|
+
/** Execute the hook before the internal default handler */
|
|
83
|
+
before?: boolean;
|
|
84
|
+
/** Set a priority for when to execute this hook. Lower numbers execute first. Default: `0` */
|
|
85
|
+
priority?: number;
|
|
86
|
+
/** Replace the internal default handler with this hook handler */
|
|
87
|
+
replace?: boolean;
|
|
88
|
+
};
|
|
89
|
+
export type HookRegistration<T extends HookName> = {
|
|
90
|
+
id: number;
|
|
91
|
+
hook: T;
|
|
92
|
+
handler: Handler<T>;
|
|
93
|
+
} & HookOptions;
|
|
94
|
+
type HookLedger<T extends HookName> = Map<Handler<T>, HookRegistration<T>>;
|
|
95
|
+
interface HookRegistry extends Map<HookName, HookLedger<HookName>> {
|
|
96
|
+
get<K extends HookName>(key: K): HookLedger<K> | undefined;
|
|
97
|
+
set<K extends HookName>(key: K, value: HookLedger<K>): this;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Hook registry.
|
|
101
|
+
*
|
|
102
|
+
* Create, trigger and handle hooks.
|
|
103
|
+
*
|
|
104
|
+
*/
|
|
105
|
+
export declare class Hooks {
|
|
106
|
+
protected swup: Swup;
|
|
107
|
+
protected registry: HookRegistry;
|
|
108
|
+
readonly hooks: HookName[];
|
|
109
|
+
constructor(swup: Swup);
|
|
110
|
+
/**
|
|
111
|
+
* Create ledgers for all core hooks.
|
|
112
|
+
*/
|
|
113
|
+
protected init(): void;
|
|
114
|
+
/**
|
|
115
|
+
* Register a new hook.
|
|
116
|
+
*/
|
|
117
|
+
create(hook: HookName): void;
|
|
118
|
+
/**
|
|
119
|
+
* Check if a hook is registered.
|
|
120
|
+
*/
|
|
121
|
+
has(hook: HookName): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Get the ledger with all registrations for a hook.
|
|
124
|
+
*/
|
|
125
|
+
protected get<T extends HookName>(hook: T): HookLedger<T> | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* Remove all handlers of all hooks.
|
|
128
|
+
*/
|
|
129
|
+
clear(): void;
|
|
130
|
+
/**
|
|
131
|
+
* Register a new hook handler.
|
|
132
|
+
* @param hook Name of the hook to listen for
|
|
133
|
+
* @param handler The handler function to execute
|
|
134
|
+
* @param options Object to specify how and when the handler is executed
|
|
135
|
+
* Available options:
|
|
136
|
+
* - `once`: Only execute the handler once
|
|
137
|
+
* - `before`: Execute the handler before the default handler
|
|
138
|
+
* - `priority`: Specify the order in which the handlers are executed
|
|
139
|
+
* - `replace`: Replace the default handler with this handler
|
|
140
|
+
* @returns A function to unregister the handler
|
|
141
|
+
*/
|
|
142
|
+
on<T extends HookName>(hook: T, handler: Handler<T>): HookUnregister;
|
|
143
|
+
on<T extends HookName>(hook: T, handler: Handler<T>, options: HookOptions): HookUnregister;
|
|
144
|
+
/**
|
|
145
|
+
* Register a new hook handler to run before the default handler.
|
|
146
|
+
* Shortcut for `hooks.on(hook, handler, { before: true })`.
|
|
147
|
+
* @param hook Name of the hook to listen for
|
|
148
|
+
* @param handler The handler function to execute
|
|
149
|
+
* @param options Any other event options (see `hooks.on()` for details)
|
|
150
|
+
* @returns A function to unregister the handler
|
|
151
|
+
* @see on
|
|
152
|
+
*/
|
|
153
|
+
before<T extends HookName>(hook: T, handler: Handler<T>): HookUnregister;
|
|
154
|
+
before<T extends HookName>(hook: T, handler: Handler<T>, options: HookOptions): HookUnregister;
|
|
155
|
+
/**
|
|
156
|
+
* Register a new hook handler to replace the default handler.
|
|
157
|
+
* Shortcut for `hooks.on(hook, handler, { replace: true })`.
|
|
158
|
+
* @param hook Name of the hook to listen for
|
|
159
|
+
* @param handler The handler function to execute instead of the default handler
|
|
160
|
+
* @param options Any other event options (see `hooks.on()` for details)
|
|
161
|
+
* @returns A function to unregister the handler
|
|
162
|
+
* @see on
|
|
163
|
+
*/
|
|
164
|
+
replace<T extends HookName>(hook: T, handler: Handler<T>): HookUnregister;
|
|
165
|
+
replace<T extends HookName>(hook: T, handler: Handler<T>, options: HookOptions): HookUnregister;
|
|
166
|
+
/**
|
|
167
|
+
* Register a new hook handler to run once.
|
|
168
|
+
* Shortcut for `hooks.on(hook, handler, { once: true })`.
|
|
169
|
+
* @param hook Name of the hook to listen for
|
|
170
|
+
* @param handler The handler function to execute
|
|
171
|
+
* @param options Any other event options (see `hooks.on()` for details)
|
|
172
|
+
* @see on
|
|
173
|
+
*/
|
|
174
|
+
once<T extends HookName>(hook: T, handler: Handler<T>): HookUnregister;
|
|
175
|
+
once<T extends HookName>(hook: T, handler: Handler<T>, options: HookOptions): HookUnregister;
|
|
176
|
+
/**
|
|
177
|
+
* Unregister a hook handler.
|
|
178
|
+
* @param hook Name of the hook the handler is registered for
|
|
179
|
+
* @param handler The handler function that was registered.
|
|
180
|
+
* If omitted, all handlers for the hook will be removed.
|
|
181
|
+
*/
|
|
182
|
+
off<T extends HookName>(hook: T): void;
|
|
183
|
+
off<T extends HookName>(hook: T, handler: Handler<T>): void;
|
|
184
|
+
/**
|
|
185
|
+
* Trigger a hook asynchronously, executing its default handler and all registered handlers.
|
|
186
|
+
* Will execute all handlers in order and `await` any `Promise`s they return.
|
|
187
|
+
* @param hook Name of the hook to trigger
|
|
188
|
+
* @param args Arguments to pass to the handler
|
|
189
|
+
* @param defaultHandler A default implementation of this hook to execute
|
|
190
|
+
* @returns The resolved return value of the executed default handler
|
|
191
|
+
*/
|
|
192
|
+
trigger<T extends HookName>(hook: T, args?: HookArguments<T>, defaultHandler?: Handler<T>): Promise<any>;
|
|
193
|
+
/**
|
|
194
|
+
* Trigger a hook synchronously, executing its default handler and all registered handlers.
|
|
195
|
+
* Will execute all handlers in order, but will **not** `await` any `Promise`s they return.
|
|
196
|
+
* @param hook Name of the hook to trigger
|
|
197
|
+
* @param args Arguments to pass to the handler
|
|
198
|
+
* @param defaultHandler A default implementation of this hook to execute
|
|
199
|
+
* @returns The (possibly unresolved) return value of the executed default handler
|
|
200
|
+
*/
|
|
201
|
+
triggerSync<T extends HookName>(hook: T, args?: HookArguments<T>, defaultHandler?: Handler<T>): any;
|
|
202
|
+
/**
|
|
203
|
+
* Execute the handlers for a hook, in order, as `Promise`s that will be `await`ed.
|
|
204
|
+
* @param registrations The registrations (handler + options) to execute
|
|
205
|
+
* @param args Arguments to pass to the handler
|
|
206
|
+
*/
|
|
207
|
+
execute<T extends HookName>(registrations: HookRegistration<T>[], args?: HookArguments<T>, defaultHandler?: Handler<T>): Promise<any>;
|
|
208
|
+
/**
|
|
209
|
+
* Execute the handlers for a hook, in order, without `await`ing any returned `Promise`s.
|
|
210
|
+
* @param registrations The registrations (handler + options) to execute
|
|
211
|
+
* @param args Arguments to pass to the handler
|
|
212
|
+
*/
|
|
213
|
+
executeSync<T extends HookName>(registrations: HookRegistration<T>[], args?: HookArguments<T>, defaultHandler?: Handler<T>): any[];
|
|
214
|
+
/**
|
|
215
|
+
* Get all registered handlers for a hook, sorted by priority and registration order.
|
|
216
|
+
* @param hook Name of the hook
|
|
217
|
+
* @param defaultHandler The optional default handler of this hook
|
|
218
|
+
* @returns An object with the handlers sorted into `before` and `after` arrays,
|
|
219
|
+
* as well as a flag indicating if the original handler was replaced
|
|
220
|
+
*/
|
|
221
|
+
getHandlers<T extends HookName>(hook: T, defaultHandler?: Handler<T>): {
|
|
222
|
+
found: boolean;
|
|
223
|
+
before: HookRegistration<T>[];
|
|
224
|
+
handler: HookRegistration<T>[];
|
|
225
|
+
after: HookRegistration<T>[];
|
|
226
|
+
replaced: boolean;
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* Sort two hook registrations by priority and registration order.
|
|
230
|
+
* @param a The registration object to compare
|
|
231
|
+
* @param b The other registration object to compare with
|
|
232
|
+
* @returns The sort direction
|
|
233
|
+
*/
|
|
234
|
+
sortRegistrations<T extends HookName>(a: HookRegistration<T>, b: HookRegistration<T>): number;
|
|
235
|
+
/**
|
|
236
|
+
* Trigger a custom event on the `document`. Prefixed with `swup:`
|
|
237
|
+
* @param hook Name of the hook to trigger.
|
|
238
|
+
*/
|
|
239
|
+
dispatchDomEvent<T extends HookName>(hook: T, args?: HookArguments<T>): void;
|
|
240
|
+
}
|
|
241
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import Swup, { Options } from '../Swup.js';
|
|
2
|
+
declare const TRANSITION = "transition";
|
|
3
|
+
declare const ANIMATION = "animation";
|
|
4
|
+
type AnimationTypes = typeof TRANSITION | typeof ANIMATION;
|
|
5
|
+
export type AnimationDirection = 'in' | 'out';
|
|
6
|
+
/**
|
|
7
|
+
* Return a Promise that resolves when all animations are done on the page.
|
|
8
|
+
*
|
|
9
|
+
* @note We don't make use of the `direction` argument, but it's required by JS plugin
|
|
10
|
+
*/
|
|
11
|
+
export declare function awaitAnimations(this: Swup, { elements, selector }: {
|
|
12
|
+
selector: Options['animationSelector'];
|
|
13
|
+
elements?: NodeListOf<HTMLElement> | HTMLElement[];
|
|
14
|
+
direction?: AnimationDirection;
|
|
15
|
+
}): Promise<void>;
|
|
16
|
+
export declare function getTransitionInfo(element: Element, expectedType?: AnimationTypes): {
|
|
17
|
+
type: AnimationTypes | null;
|
|
18
|
+
timeout: number;
|
|
19
|
+
propCount: number;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import Swup from '../Swup.js';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Perform the in/enter animation of the next page.
|
|
4
|
+
* @returns Promise<void>
|
|
5
|
+
*/
|
|
6
|
+
export declare const enterPage: (this: Swup) => Promise<void>;
|
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
import Swup from '../Swup.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export interface PageData {
|
|
3
|
+
url: string;
|
|
4
|
+
html: string;
|
|
5
|
+
}
|
|
6
|
+
export interface FetchOptions extends RequestInit {
|
|
7
|
+
method?: 'GET' | 'POST';
|
|
8
|
+
body?: string | FormData | URLSearchParams;
|
|
9
|
+
headers?: Record<string, string>;
|
|
10
|
+
}
|
|
11
|
+
export declare class FetchError extends Error {
|
|
12
|
+
url: string;
|
|
13
|
+
status: number;
|
|
14
|
+
constructor(message: string, details: {
|
|
15
|
+
url: string;
|
|
16
|
+
status: number;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Fetch a page from the server, return it and cache it.
|
|
21
|
+
*/
|
|
22
|
+
export declare function fetchPage(this: Swup, url: URL | string, options?: FetchOptions & {
|
|
23
|
+
triggerHooks?: boolean;
|
|
24
|
+
}): Promise<PageData>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Find the anchor element for a given hash.
|
|
3
|
-
* @see https://html.spec.whatwg.org/#find-a-potential-indicated-element
|
|
4
3
|
*
|
|
5
4
|
* @param hash Hash with or without leading '#'
|
|
6
5
|
* @returns The element, if found, or null.
|
|
6
|
+
*
|
|
7
|
+
* @see https://html.spec.whatwg.org/#find-a-potential-indicated-element
|
|
7
8
|
*/
|
|
8
9
|
export declare const getAnchorElement: (hash: string) => Element | null;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import Swup from '../Swup.js';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Perform the out/leave animation of the current page.
|
|
4
|
+
* @returns Promise<void>
|
|
5
|
+
*/
|
|
6
|
+
export declare const leavePage: (this: Swup) => Promise<void>;
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import Swup from '../Swup.js';
|
|
2
2
|
export type Plugin = {
|
|
3
|
+
/** Name of this plugin */
|
|
3
4
|
name: string;
|
|
5
|
+
/** Identify as a swup plugin */
|
|
4
6
|
isSwupPlugin: true;
|
|
7
|
+
/** Run on mount */
|
|
5
8
|
mount: () => void;
|
|
9
|
+
/** Run on unmount */
|
|
6
10
|
unmount: () => void;
|
|
11
|
+
/** The swup instance that mounted this plugin */
|
|
7
12
|
swup?: Swup;
|
|
13
|
+
/** Version of this plugin. Currently not in use, defined here for backward compatiblity. */
|
|
8
14
|
version?: string;
|
|
15
|
+
/** Version requirements of this plugin. Example: `{ swup: '>=4' }` */
|
|
9
16
|
requires?: Record<string, string>;
|
|
10
17
|
_beforeMount?: () => void;
|
|
11
18
|
_afterUnmount?: () => void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Swup from '../Swup.js';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare const renderPage: (this: Swup,
|
|
2
|
+
import { PageData } from './fetchPage.js';
|
|
3
|
+
/**
|
|
4
|
+
* Render the next page: replace the content and update scroll position.
|
|
5
|
+
* @returns Promise<void>
|
|
6
|
+
*/
|
|
7
|
+
export declare const renderPage: (this: Swup, requestedUrl: string, page: PageData) => Promise<void>;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
+
import Swup, { Options } from '../Swup.js';
|
|
2
|
+
import { PageData } from './fetchPage.js';
|
|
1
3
|
/**
|
|
2
4
|
* Perform the replacement of content after loading a page.
|
|
3
5
|
*
|
|
4
|
-
*
|
|
6
|
+
* It takes an object with the page data as returned from `fetchPage` and a list
|
|
7
|
+
* of container selectors to replace.
|
|
5
8
|
*
|
|
6
|
-
*
|
|
7
|
-
* return a Promise that resolves once all content has been replaced and the
|
|
8
|
-
* site is ready to start animating in the new page.
|
|
9
|
-
*
|
|
10
|
-
* @param {object} page The page object
|
|
11
|
-
* @returns Promise
|
|
9
|
+
* @returns Whether all containers were replaced.
|
|
12
10
|
*/
|
|
13
|
-
export declare const replaceContent: (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}) => Promise<void>;
|
|
11
|
+
export declare const replaceContent: (this: Swup, { html }: PageData, { containers }?: {
|
|
12
|
+
containers: Options['containers'];
|
|
13
|
+
}) => boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import Swup from '../Swup.js';
|
|
2
|
+
import { FetchOptions } from './fetchPage.js';
|
|
3
|
+
import { ContextInitOptions } from './Context.js';
|
|
4
|
+
export type HistoryAction = 'push' | 'replace';
|
|
5
|
+
export type HistoryDirection = 'forwards' | 'backwards';
|
|
6
|
+
type VisitOptions = {
|
|
7
|
+
/** Whether this visit is animated. Default: `true` */
|
|
8
|
+
animate?: boolean;
|
|
9
|
+
/** Name of a custom animation to run. */
|
|
10
|
+
animation?: string;
|
|
11
|
+
/** History action to perform: `push` for creating a new history entry, `replace` for replacing the current entry. Default: `push` */
|
|
12
|
+
history?: HistoryAction;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Navigate to a new URL.
|
|
16
|
+
* @param url The URL to navigate to.
|
|
17
|
+
* @param options Options for how to perform this visit.
|
|
18
|
+
* @returns Promise<void>
|
|
19
|
+
*/
|
|
20
|
+
export declare function visit(this: Swup, url: string, options?: VisitOptions & FetchOptions, context?: Omit<ContextInitOptions, 'to'>): void;
|
|
21
|
+
/**
|
|
22
|
+
* Start a visit to a new URL.
|
|
23
|
+
*
|
|
24
|
+
* Internal method that assumes the global context has already been set up.
|
|
25
|
+
*
|
|
26
|
+
* As a user, you should call `swup.visit(url)` instead.
|
|
27
|
+
*
|
|
28
|
+
* @param url The URL to navigate to.
|
|
29
|
+
* @param options Options for how to perform this visit.
|
|
30
|
+
* @returns Promise<void>
|
|
31
|
+
*/
|
|
32
|
+
export declare function performVisit(this: Swup, url: string, options?: VisitOptions & FetchOptions): Promise<void>;
|
|
33
|
+
export {};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare const query: (selector: string, context?: Document | Element) => HTMLElement | null;
|
|
2
2
|
export declare const queryAll: (selector: string, context?: Document | Element) => HTMLElement[];
|
|
3
|
-
export declare const nextTick: (
|
|
3
|
+
export declare const nextTick: () => Promise<void>;
|
|
4
|
+
export declare function isPromise<T>(obj: any): obj is PromiseLike<T>;
|
|
5
|
+
export declare function runAsPromise(func: Function, args?: any[], ctx?: any): Promise<any>;
|
|
4
6
|
export declare const escapeCssIdentifier: (ident: string) => string;
|
|
5
7
|
export declare const toMs: (s: string) => number;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swup",
|
|
3
3
|
"amdName": "Swup",
|
|
4
|
-
"version": "
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "4.0.0-rc.20",
|
|
5
|
+
"description": "Versatile and extensible page transition library for server-rendered websites",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"source": "./src/Swup.ts",
|
|
8
8
|
"main": "./dist/Swup.cjs",
|
|
@@ -29,11 +29,12 @@
|
|
|
29
29
|
"format": "npm run lint:ts && npm run lint:prettier -- --write",
|
|
30
30
|
"lint:ts": "tsc --noEmit --skipLibCheck",
|
|
31
31
|
"lint:prettier": "prettier 'src/**/*.ts'",
|
|
32
|
-
"
|
|
32
|
+
"prepublishOnly": "npm run build",
|
|
33
33
|
"postinstall": "opencollective-postinstall || true",
|
|
34
34
|
"test": "npm run test:unit && npm run test:e2e",
|
|
35
35
|
"test:ci": "npm run test:unit && npm run test:e2e:ci",
|
|
36
36
|
"test:unit": "vitest run --config ./vitest/vitest.config.ts",
|
|
37
|
+
"test:unit:watch": "vitest --config ./vitest/vitest.config.ts",
|
|
37
38
|
"test:e2e": "start-server-and-test test:e2e:start 8274 cy:run",
|
|
38
39
|
"test:e2e:ci": "start-server-and-test test:e2e:start 8274 cy:run:record",
|
|
39
40
|
"test:e2e:dev": "start-server-and-test test:e2e:start 8274 cy:open",
|
|
@@ -49,32 +50,35 @@
|
|
|
49
50
|
"license": "MIT",
|
|
50
51
|
"repository": {
|
|
51
52
|
"type": "git",
|
|
52
|
-
"url": "https://github.com/
|
|
53
|
+
"url": "https://github.com/swup/swup.git"
|
|
53
54
|
},
|
|
54
55
|
"keywords": [
|
|
55
56
|
"css",
|
|
56
|
-
"animation",
|
|
57
57
|
"page",
|
|
58
|
-
"transition"
|
|
58
|
+
"transition",
|
|
59
|
+
"animation"
|
|
59
60
|
],
|
|
60
61
|
"dependencies": {
|
|
61
62
|
"delegate-it": "^6.0.0",
|
|
62
|
-
"opencollective-postinstall": "^2.0.2"
|
|
63
|
+
"opencollective-postinstall": "^2.0.2",
|
|
64
|
+
"path-to-regexp": "^6.2.1"
|
|
63
65
|
},
|
|
64
66
|
"devDependencies": {
|
|
65
67
|
"@babel/preset-typescript": "^7.18.6",
|
|
66
68
|
"@cypress/code-coverage": "^3.10.0",
|
|
67
69
|
"@swup/browserslist-config": "^1.0.0",
|
|
68
70
|
"@swup/prettier-config": "^1.0.0",
|
|
71
|
+
"@types/jsdom": "^21.1.1",
|
|
69
72
|
"cypress": "^12.3.0",
|
|
70
73
|
"http-server": "^14.1.1",
|
|
71
74
|
"husky": "^8.0.0",
|
|
72
75
|
"istanbul-lib-coverage": "^3.2.0",
|
|
76
|
+
"jsdom": "^22.1.0",
|
|
73
77
|
"microbundle": "^0.15.0",
|
|
74
78
|
"nyc": "^15.1.0",
|
|
75
79
|
"prettier": "^2.8.2",
|
|
76
|
-
"start-server-and-test": "^
|
|
77
|
-
"vitest": "^0.
|
|
80
|
+
"start-server-and-test": "^2.0.0",
|
|
81
|
+
"vitest": "^0.31.2"
|
|
78
82
|
},
|
|
79
83
|
"collective": {
|
|
80
84
|
"type": "opencollective",
|