swup 2.0.19 → 3.0.0-rc.1
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/dist/helpers.cjs +2 -0
- package/dist/helpers.cjs.map +1 -0
- package/dist/helpers.modern.js +2 -0
- package/dist/helpers.modern.js.map +1 -0
- package/dist/helpers.module.js +2 -0
- package/dist/helpers.module.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.modern.js +2 -0
- package/dist/index.modern.js.map +1 -0
- package/dist/index.module.js +2 -0
- package/dist/index.module.js.map +1 -0
- package/dist/index.umd.js +3 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/src/config/version.d.ts +5 -0
- package/dist/src/helpers/Location.d.ts +31 -0
- package/dist/src/helpers/classify.d.ts +2 -0
- package/dist/src/helpers/cleanupAnimationClasses.d.ts +2 -0
- package/dist/src/helpers/createHistoryRecord.d.ts +2 -0
- package/dist/src/helpers/delegateEvent.d.ts +8 -0
- package/dist/src/helpers/fetch.d.ts +6 -0
- package/dist/src/helpers/getCurrentUrl.d.ts +4 -0
- package/dist/src/helpers/getDataFromHtml.d.ts +8 -0
- package/dist/src/helpers/index.d.ts +11 -0
- package/dist/src/helpers/markSwupElements.d.ts +2 -0
- package/dist/src/helpers/updateHistoryRecord.d.ts +2 -0
- package/dist/src/helpers/versionSatisfies.d.ts +12 -0
- package/dist/src/helpers.d.ts +1 -0
- package/dist/src/index.d.ts +97 -0
- package/dist/src/modules/Cache.d.ts +20 -0
- package/dist/src/modules/enterPage.d.ts +6 -0
- package/dist/src/modules/getAnchorElement.d.ts +2 -0
- package/dist/src/modules/getAnimationPromises.d.ts +7 -0
- package/dist/src/modules/getPageData.d.ts +7 -0
- package/dist/src/modules/leavePage.d.ts +7 -0
- package/dist/src/modules/loadPage.d.ts +4 -0
- package/dist/src/modules/off.d.ts +4 -0
- package/dist/src/modules/on.d.ts +4 -0
- package/dist/src/modules/plugins.d.ts +13 -0
- package/dist/src/modules/renderPage.d.ts +7 -0
- package/dist/src/modules/replaceContent.d.ts +17 -0
- package/dist/src/modules/triggerEvent.d.ts +4 -0
- package/dist/src/modules/updateTransition.d.ts +3 -0
- package/dist/src/src/config/version.d.ts +5 -0
- package/dist/src/src/helpers/Location.d.ts +31 -0
- package/dist/src/src/helpers/classify.d.ts +2 -0
- package/dist/src/src/helpers/cleanupAnimationClasses.d.ts +2 -0
- package/dist/src/src/helpers/createHistoryRecord.d.ts +2 -0
- package/dist/src/src/helpers/delegateEvent.d.ts +8 -0
- package/dist/src/src/helpers/fetch.d.ts +6 -0
- package/dist/src/src/helpers/getCurrentUrl.d.ts +4 -0
- package/dist/src/src/helpers/getDataFromHtml.d.ts +8 -0
- package/dist/src/src/helpers/index.d.ts +11 -0
- package/dist/src/src/helpers/markSwupElements.d.ts +2 -0
- package/dist/src/src/helpers/updateHistoryRecord.d.ts +2 -0
- package/dist/src/src/helpers/versionSatisfies.d.ts +12 -0
- package/dist/src/src/helpers.d.ts +1 -0
- package/dist/src/src/index.d.ts +103 -0
- package/dist/src/src/modules/Cache.d.ts +20 -0
- package/dist/src/src/modules/enterPage.d.ts +6 -0
- package/dist/src/src/modules/getAnchorElement.d.ts +2 -0
- package/dist/src/src/modules/getAnimationPromises.d.ts +7 -0
- package/dist/src/src/modules/getPageData.d.ts +7 -0
- package/dist/src/src/modules/leavePage.d.ts +7 -0
- package/dist/src/src/modules/loadPage.d.ts +7 -0
- package/dist/src/src/modules/off.d.ts +4 -0
- package/dist/src/src/modules/on.d.ts +6 -0
- package/dist/src/src/modules/plugins.d.ts +14 -0
- package/dist/src/src/modules/renderPage.d.ts +7 -0
- package/dist/src/src/modules/replaceContent.d.ts +17 -0
- package/dist/src/src/modules/triggerEvent.d.ts +4 -0
- package/dist/src/src/modules/updateTransition.d.ts +3 -0
- package/dist/src/src/utils/index.d.ts +5 -0
- package/dist/src/src/utils.d.ts +1 -0
- package/dist/src/types.d.ts +12 -0
- package/dist/src/utils/index.d.ts +5 -0
- package/dist/src/utils.d.ts +1 -0
- package/dist/types.cjs +2 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.modern.js +2 -0
- package/dist/types.modern.js.map +1 -0
- package/dist/types.module.js +2 -0
- package/dist/types.module.js.map +1 -0
- package/dist/utils.cjs +2 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.modern.js +2 -0
- package/dist/utils.modern.js.map +1 -0
- package/dist/utils.module.js +2 -0
- package/dist/utils.module.js.map +1 -0
- package/package.json +41 -23
- package/readme.md +52 -36
- package/src/config/version.ts +13 -0
- package/src/helpers/Location.ts +44 -0
- package/src/helpers/classify.ts +13 -0
- package/src/helpers/cleanupAnimationClasses.ts +10 -0
- package/src/helpers/createHistoryRecord.ts +14 -0
- package/src/helpers/delegateEvent.ts +23 -0
- package/src/helpers/fetch.ts +35 -0
- package/src/helpers/getCurrentUrl.ts +5 -0
- package/src/helpers/getDataFromHtml.ts +41 -0
- package/src/helpers/index.ts +11 -0
- package/src/helpers/markSwupElements.ts +18 -0
- package/src/helpers/updateHistoryRecord.ts +18 -0
- package/src/helpers/versionSatisfies.ts +50 -0
- package/src/helpers.ts +4 -0
- package/src/index.ts +369 -0
- package/src/modules/Cache.ts +57 -0
- package/src/modules/enterPage.ts +28 -0
- package/src/modules/fetchPage.ts +35 -0
- package/src/modules/getAnchorElement.ts +19 -0
- package/src/modules/getAnimationPromises.ts +176 -0
- package/src/modules/getPageData.ts +26 -0
- package/src/modules/leavePage.ts +33 -0
- package/src/modules/loadPage.ts +54 -0
- package/src/modules/off.ts +23 -0
- package/src/modules/on.ts +35 -0
- package/src/modules/plugins.ts +58 -0
- package/src/modules/renderPage.ts +52 -0
- package/src/modules/replaceContent.ts +28 -0
- package/src/modules/triggerEvent.ts +23 -0
- package/src/modules/updateTransition.ts +7 -0
- package/src/utils/index.ts +32 -0
- package/src/utils.ts +4 -0
- package/.editorconfig +0 -19
- package/cypress.config.js +0 -14
- package/dist/swup.js +0 -1524
- package/dist/swup.min.js +0 -1
- package/lib/helpers/Link.js +0 -56
- package/lib/helpers/classify.js +0 -18
- package/lib/helpers/cleanupAnimationClasses.js +0 -18
- package/lib/helpers/createHistoryRecord.js +0 -14
- package/lib/helpers/fetch.js +0 -41
- package/lib/helpers/getCurrentUrl.js +0 -10
- package/lib/helpers/getDataFromHtml.js +0 -43
- package/lib/helpers/index.js +0 -64
- package/lib/helpers/markSwupElements.js +0 -24
- package/lib/helpers/normalizeUrl.js +0 -17
- package/lib/helpers/transitionEnd.js +0 -14
- package/lib/helpers/transitionProperty.js +0 -14
- package/lib/index.js +0 -305
- package/lib/modules/Cache.js +0 -66
- package/lib/modules/getAnchorElement.js +0 -25
- package/lib/modules/getAnimationPromises.js +0 -43
- package/lib/modules/getPageData.js +0 -26
- package/lib/modules/loadPage.js +0 -123
- package/lib/modules/off.js +0 -34
- package/lib/modules/on.js +0 -14
- package/lib/modules/plugins.js +0 -54
- package/lib/modules/renderPage.js +0 -76
- package/lib/modules/triggerEvent.js +0 -21
- package/lib/modules/updateTransition.js +0 -15
- package/lib/utils/index.js +0 -32
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import Cache from './modules/Cache.js';
|
|
2
|
+
import getAnimationPromises from './modules/getAnimationPromises.js';
|
|
3
|
+
import { Plugin } from "./modules/plugins";
|
|
4
|
+
import { Handlers, Transition } from "./types";
|
|
5
|
+
import delegate from "delegate-it";
|
|
6
|
+
import { Unsubscribe } from "./helpers/delegateEvent";
|
|
7
|
+
export type Options = {
|
|
8
|
+
animateHistoryBrowsing: boolean;
|
|
9
|
+
animationSelector: string | false;
|
|
10
|
+
linkSelector: string;
|
|
11
|
+
cache: boolean;
|
|
12
|
+
containers: string[];
|
|
13
|
+
requestHeaders: Record<string, string>;
|
|
14
|
+
plugins: Plugin[];
|
|
15
|
+
skipPopStateHandling: (event: any) => boolean;
|
|
16
|
+
ignoreVisit: (href: string, { el }: {
|
|
17
|
+
el?: Element;
|
|
18
|
+
}) => boolean;
|
|
19
|
+
resolveUrl: (url: string) => string;
|
|
20
|
+
};
|
|
21
|
+
type DelegatedListeners = {
|
|
22
|
+
click?: Unsubscribe;
|
|
23
|
+
};
|
|
24
|
+
export default class Swup {
|
|
25
|
+
version: string;
|
|
26
|
+
_handlers: Handlers;
|
|
27
|
+
scrollToElement: string | null;
|
|
28
|
+
preloadPromise: (Promise<any> & {
|
|
29
|
+
route: string;
|
|
30
|
+
}) | null;
|
|
31
|
+
options: Options;
|
|
32
|
+
plugins: Plugin[];
|
|
33
|
+
transition: Transition;
|
|
34
|
+
cache: Cache;
|
|
35
|
+
currentPageUrl: string;
|
|
36
|
+
delegatedListeners: DelegatedListeners;
|
|
37
|
+
boundPopStateHandler: (event: PopStateEvent) => void;
|
|
38
|
+
loadPage: (this: Swup, data: import("./types").TransitionOptions, popstate: PopStateEvent | null) => void;
|
|
39
|
+
leavePage: (this: Swup, data: import("./types").TransitionOptions, { popstate, skipTransition }?: {
|
|
40
|
+
popstate: PopStateEvent | null;
|
|
41
|
+
skipTransition?: boolean | undefined;
|
|
42
|
+
}) => Promise<void>[];
|
|
43
|
+
renderPage: (this: Swup, page: import("./modules/Cache.js").PageRecord, { popstate, skipTransition }?: {
|
|
44
|
+
popstate: PopStateEvent | null;
|
|
45
|
+
skipTransition?: boolean | undefined;
|
|
46
|
+
}) => void;
|
|
47
|
+
replaceContent: ({ blocks, title }: {
|
|
48
|
+
blocks: string[];
|
|
49
|
+
title: string;
|
|
50
|
+
}) => Promise<void>;
|
|
51
|
+
enterPage: (this: Swup, { popstate, skipTransition }: {
|
|
52
|
+
popstate?: PopStateEvent | undefined;
|
|
53
|
+
skipTransition?: boolean | undefined;
|
|
54
|
+
}) => Promise<void>[];
|
|
55
|
+
triggerEvent: (this: Swup, eventName: import("./types").EventType, originalEvent?: PopStateEvent | MouseEvent | undefined) => void;
|
|
56
|
+
delegateEvent: <Selector extends string, TEvent extends keyof GlobalEventHandlersEventMap>(selector: Selector, type: TEvent, callback: delegate.EventHandler<GlobalEventHandlersEventMap[TEvent], Element>, { base, ...eventOptions }?: {
|
|
57
|
+
base?: Document | undefined;
|
|
58
|
+
}) => Unsubscribe;
|
|
59
|
+
on: (this: Swup, event: import("./types").EventType, handler: import("./types").Handler) => void;
|
|
60
|
+
off: (this: Swup, event?: import("./types").EventType | undefined, handler?: import("./types").Handler | undefined) => void;
|
|
61
|
+
updateTransition: (this: Swup, from: string, to: string, custom?: string | undefined) => void;
|
|
62
|
+
getAnimationPromises: typeof getAnimationPromises;
|
|
63
|
+
getPageData: (this: Swup, request: XMLHttpRequest) => import("./modules/getPageData.js").PageData | null;
|
|
64
|
+
getAnchorElement: (hash: string) => Element | null;
|
|
65
|
+
log: (message: string, context?: any) => void;
|
|
66
|
+
use: (this: Swup, plugin: Plugin) => Plugin[] | undefined;
|
|
67
|
+
unuse: (this: Swup, plugin: Plugin) => Plugin[] | undefined;
|
|
68
|
+
findPlugin: (this: Swup, pluginName: string) => Plugin | undefined;
|
|
69
|
+
getCurrentUrl: ({ hash }?: {
|
|
70
|
+
hash?: boolean | undefined;
|
|
71
|
+
}) => string;
|
|
72
|
+
cleanupAnimationClasses: () => void;
|
|
73
|
+
constructor(setOptions: Partial<Options>);
|
|
74
|
+
enable(): void;
|
|
75
|
+
destroy(): void;
|
|
76
|
+
shouldIgnoreVisit(href: string, { el }?: {
|
|
77
|
+
el?: Element;
|
|
78
|
+
}): boolean;
|
|
79
|
+
linkClickHandler(event: delegate.Event<MouseEvent>): void;
|
|
80
|
+
handleLinkToSamePage(url: string, hash: string, event: MouseEvent): void;
|
|
81
|
+
triggerWillOpenNewWindow(triggerEl: Element): boolean;
|
|
82
|
+
popStateHandler(event: PopStateEvent): void;
|
|
83
|
+
/**
|
|
84
|
+
* Utility function to validate and run the global option 'resolveUrl'
|
|
85
|
+
* @param {string} url
|
|
86
|
+
* @returns {string} the resolved url
|
|
87
|
+
*/
|
|
88
|
+
resolveUrl(url: string): string;
|
|
89
|
+
/**
|
|
90
|
+
* Compares the resolved version of two paths and returns true if they are the same
|
|
91
|
+
* @param {string} url1
|
|
92
|
+
* @param {string} url2
|
|
93
|
+
* @returns {boolean}
|
|
94
|
+
*/
|
|
95
|
+
isSameResolvedUrl(url1: string, url2: string): boolean;
|
|
96
|
+
}
|
|
97
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Swup from '../index';
|
|
2
|
+
import { PageData } from './getPageData';
|
|
3
|
+
export interface PageRecord extends PageData {
|
|
4
|
+
url: string;
|
|
5
|
+
responseURL: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class Cache {
|
|
8
|
+
pages: Record<string, PageRecord>;
|
|
9
|
+
last: PageRecord | null;
|
|
10
|
+
swup: Swup;
|
|
11
|
+
constructor(swup: Swup);
|
|
12
|
+
getCacheUrl(url: string): string;
|
|
13
|
+
cacheUrl(page: PageRecord): void;
|
|
14
|
+
getPage(url: string): PageRecord;
|
|
15
|
+
getCurrentPage(): PageRecord;
|
|
16
|
+
exists(url: string): boolean;
|
|
17
|
+
empty(): void;
|
|
18
|
+
remove(url: string): void;
|
|
19
|
+
}
|
|
20
|
+
export default Cache;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Swup from '../index';
|
|
2
|
+
export default function getAnimationPromises(this: Swup): Promise<void>[];
|
|
3
|
+
export declare function getTransitionInfo(element: Element, expectedType?: 'animation' | 'transition' | null): {
|
|
4
|
+
type: string | null;
|
|
5
|
+
timeout: number;
|
|
6
|
+
propCount: number;
|
|
7
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Swup from '../index';
|
|
2
|
+
import { PageHtmlData } from '../helpers/getDataFromHtml';
|
|
3
|
+
export type PageData = PageHtmlData & {
|
|
4
|
+
responseURL: string;
|
|
5
|
+
};
|
|
6
|
+
declare const getPageData: (this: Swup, request: XMLHttpRequest) => PageData | null;
|
|
7
|
+
export default getPageData;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Swup from '../index';
|
|
2
|
+
import { TransitionOptions } from '../types';
|
|
3
|
+
declare const leavePage: (this: Swup, data: TransitionOptions, { popstate, skipTransition }?: {
|
|
4
|
+
popstate: PopStateEvent | null;
|
|
5
|
+
skipTransition?: boolean | undefined;
|
|
6
|
+
}) => Promise<void>[];
|
|
7
|
+
export default leavePage;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Swup from '../index';
|
|
2
|
+
export type Plugin = {
|
|
3
|
+
name: string;
|
|
4
|
+
mount: () => void;
|
|
5
|
+
unmount: () => void;
|
|
6
|
+
isSwupPlugin: true;
|
|
7
|
+
swup?: Swup;
|
|
8
|
+
_beforeMount?: () => void;
|
|
9
|
+
_afterUnmount?: () => void;
|
|
10
|
+
};
|
|
11
|
+
export declare const use: (this: Swup, plugin: Plugin) => Plugin[] | undefined;
|
|
12
|
+
export declare const unuse: (this: Swup, plugin: Plugin) => Plugin[] | undefined;
|
|
13
|
+
export declare const findPlugin: (this: Swup, pluginName: string) => Plugin | undefined;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Swup from '../index';
|
|
2
|
+
import { PageRecord } from './Cache';
|
|
3
|
+
declare const renderPage: (this: Swup, page: PageRecord, { popstate, skipTransition }?: {
|
|
4
|
+
popstate: PopStateEvent | null;
|
|
5
|
+
skipTransition?: boolean | undefined;
|
|
6
|
+
}) => void;
|
|
7
|
+
export default renderPage;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Perform the replacement of content after loading a page.
|
|
3
|
+
*
|
|
4
|
+
* This method can be replaced or augmented by plugins to allow pausing.
|
|
5
|
+
*
|
|
6
|
+
* It takes an object with the page data as return from `getPageData` and has to
|
|
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
|
|
12
|
+
*/
|
|
13
|
+
declare const replaceContent: ({ blocks, title }: {
|
|
14
|
+
blocks: string[];
|
|
15
|
+
title: string;
|
|
16
|
+
}) => Promise<void>;
|
|
17
|
+
export default replaceContent;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A helper for creating a Location from either an element
|
|
3
|
+
* or a URL object/string
|
|
4
|
+
*
|
|
5
|
+
* Note: this could be implemented as a class inheriting from URL
|
|
6
|
+
* Except: Babel will add tons of boilerplate for ES6 classes + getters
|
|
7
|
+
* So for now it's implemented as an augmented URL object with custom getter
|
|
8
|
+
*
|
|
9
|
+
* class Location extends URL {
|
|
10
|
+
* get url() {
|
|
11
|
+
* return this.pathname + this.search;
|
|
12
|
+
* }
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
export default class Location extends URL {
|
|
17
|
+
constructor(url: string, base?: string);
|
|
18
|
+
get url(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Instantiate a Location from an element's href attribute
|
|
21
|
+
* @param {Element} el
|
|
22
|
+
* @return new Location instance
|
|
23
|
+
*/
|
|
24
|
+
static fromElement(el: HTMLAnchorElement): Location;
|
|
25
|
+
/**
|
|
26
|
+
* Instantiate a Location from a URL object or string
|
|
27
|
+
* @param {URL|string} url
|
|
28
|
+
* @return new Location instance
|
|
29
|
+
*/
|
|
30
|
+
static fromUrl(url: string): Location;
|
|
31
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import delegate from 'delegate-it';
|
|
2
|
+
export type Unsubscribe = {
|
|
3
|
+
destroy: () => void;
|
|
4
|
+
};
|
|
5
|
+
declare const delegateEvent: <Selector extends string, TEvent extends keyof GlobalEventHandlersEventMap>(selector: Selector, type: TEvent, callback: delegate.EventHandler<GlobalEventHandlersEventMap[TEvent], Element>, { base, ...eventOptions }?: {
|
|
6
|
+
base?: Document | undefined;
|
|
7
|
+
}) => Unsubscribe;
|
|
8
|
+
export default delegateEvent;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TransitionOptions } from '../modules/loadPage';
|
|
2
|
+
import { Options } from '../index';
|
|
3
|
+
declare const fetch: (setOptions: TransitionOptions & {
|
|
4
|
+
headers: Options['requestHeaders'];
|
|
5
|
+
}, callback: (request: XMLHttpRequest) => void) => XMLHttpRequest;
|
|
6
|
+
export default fetch;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { default as classify } from './classify.js';
|
|
2
|
+
export { default as createHistoryRecord } from './createHistoryRecord.js';
|
|
3
|
+
export { default as updateHistoryRecord } from './updateHistoryRecord.js';
|
|
4
|
+
export { default as delegateEvent } from './delegateEvent.js';
|
|
5
|
+
export { default as getDataFromHtml } from './getDataFromHtml.js';
|
|
6
|
+
export { default as fetch } from './fetch.js';
|
|
7
|
+
export { default as getCurrentUrl } from './getCurrentUrl.js';
|
|
8
|
+
export { default as Location } from './Location.js';
|
|
9
|
+
export { default as markSwupElements } from './markSwupElements.js';
|
|
10
|
+
export { default as cleanupAnimationClasses } from './cleanupAnimationClasses.js';
|
|
11
|
+
export { default as versionSatisfies } from './versionSatisfies.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a version satisfies all given version requirements
|
|
3
|
+
*
|
|
4
|
+
* versionSatisfies('2.1.0', ['>=2', '<4']) // true
|
|
5
|
+
* versionSatisfies('2.1.0', ['5']) // false
|
|
6
|
+
*
|
|
7
|
+
* @param {string} installed Installed version
|
|
8
|
+
* @param {Array.<string>} requirements Array of requirements that must be satisfied
|
|
9
|
+
* @returns boolean
|
|
10
|
+
*/
|
|
11
|
+
export declare const versionSatisfies: (installed: string, requirements: string[]) => boolean;
|
|
12
|
+
export default versionSatisfies;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './helpers/index.js';
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import Cache from './modules/Cache.js';
|
|
2
|
+
import getAnimationPromises from './modules/getAnimationPromises.js';
|
|
3
|
+
import { unuse, findPlugin } from './modules/plugins.js';
|
|
4
|
+
import { Plugin } from './modules/plugins';
|
|
5
|
+
import { Handlers } from './modules/on';
|
|
6
|
+
import delegate from 'delegate-it';
|
|
7
|
+
import { Unsubscribe } from './helpers/delegateEvent';
|
|
8
|
+
export type Transition = {
|
|
9
|
+
from?: string;
|
|
10
|
+
to?: string;
|
|
11
|
+
custom?: string;
|
|
12
|
+
};
|
|
13
|
+
type DelegatedListeners = {
|
|
14
|
+
click?: Unsubscribe;
|
|
15
|
+
};
|
|
16
|
+
export type Options = {
|
|
17
|
+
animateHistoryBrowsing: boolean;
|
|
18
|
+
animationSelector: string | false;
|
|
19
|
+
linkSelector: string;
|
|
20
|
+
cache: boolean;
|
|
21
|
+
containers: string[];
|
|
22
|
+
requestHeaders: Record<string, string>;
|
|
23
|
+
plugins: Plugin[];
|
|
24
|
+
skipPopStateHandling: (event: any) => boolean;
|
|
25
|
+
ignoreVisit: (href: string, { el }: {
|
|
26
|
+
el?: Element;
|
|
27
|
+
}) => boolean;
|
|
28
|
+
resolveUrl: (url: string) => string;
|
|
29
|
+
};
|
|
30
|
+
export default class Swup {
|
|
31
|
+
version: string;
|
|
32
|
+
_handlers: Handlers;
|
|
33
|
+
scrollToElement: string | null;
|
|
34
|
+
preloadPromise: (Promise<any> & {
|
|
35
|
+
route: string;
|
|
36
|
+
}) | null;
|
|
37
|
+
options: Options;
|
|
38
|
+
plugins: Plugin[];
|
|
39
|
+
transition: Transition;
|
|
40
|
+
cache: Cache;
|
|
41
|
+
currentPageUrl: string;
|
|
42
|
+
delegatedListeners: DelegatedListeners;
|
|
43
|
+
boundPopStateHandler: (event: PopStateEvent) => void;
|
|
44
|
+
loadPage: (this: Swup, data: import("./modules/loadPage.js").TransitionOptions, popstate: PopStateEvent | null) => void;
|
|
45
|
+
leavePage: (this: Swup, data: import("./modules/loadPage.js").TransitionOptions, { popstate, skipTransition }?: {
|
|
46
|
+
popstate: PopStateEvent | null;
|
|
47
|
+
skipTransition?: boolean | undefined;
|
|
48
|
+
}) => Promise<void>[];
|
|
49
|
+
renderPage: (this: Swup, page: import("./modules/Cache.js").PageRecord, { popstate, skipTransition }?: {
|
|
50
|
+
popstate: PopStateEvent | null;
|
|
51
|
+
skipTransition?: boolean | undefined;
|
|
52
|
+
}) => void;
|
|
53
|
+
replaceContent: ({ blocks, title }: {
|
|
54
|
+
blocks: string[];
|
|
55
|
+
title: string;
|
|
56
|
+
}) => Promise<void>;
|
|
57
|
+
enterPage: (this: Swup, { popstate, skipTransition }: {
|
|
58
|
+
popstate?: PopStateEvent | undefined;
|
|
59
|
+
skipTransition?: boolean | undefined;
|
|
60
|
+
}) => Promise<void>[];
|
|
61
|
+
triggerEvent: (this: Swup, eventName: import("./modules/on.js").EventType, originalEvent?: PopStateEvent | MouseEvent | undefined) => void;
|
|
62
|
+
delegateEvent: <Selector extends string, TEvent extends keyof GlobalEventHandlersEventMap>(selector: Selector, type: TEvent, callback: delegate.EventHandler<GlobalEventHandlersEventMap[TEvent], Element>, { base, ...eventOptions }?: {
|
|
63
|
+
base?: Document | undefined;
|
|
64
|
+
}) => Unsubscribe;
|
|
65
|
+
on: (this: Swup, event: import("./modules/on.js").EventType, handler: import("./modules/on.js").Handler) => void;
|
|
66
|
+
off: (this: Swup, event?: import("./modules/on.js").EventType | undefined, handler?: import("./modules/on.js").Handler | undefined) => void;
|
|
67
|
+
updateTransition: (this: Swup, from: string, to: string, custom?: string | undefined) => void;
|
|
68
|
+
getAnimationPromises: typeof getAnimationPromises;
|
|
69
|
+
getPageData: (this: Swup, request: XMLHttpRequest) => import("./modules/getPageData.js").PageData | null;
|
|
70
|
+
getAnchorElement: (hash: string) => Element | null;
|
|
71
|
+
log: (message: string, context?: any) => void;
|
|
72
|
+
use: (this: Swup, plugin: Plugin) => Plugin[] | undefined;
|
|
73
|
+
unuse: typeof unuse;
|
|
74
|
+
findPlugin: typeof findPlugin;
|
|
75
|
+
getCurrentUrl: ({ hash }?: {
|
|
76
|
+
hash?: boolean | undefined;
|
|
77
|
+
}) => string;
|
|
78
|
+
cleanupAnimationClasses: () => void;
|
|
79
|
+
constructor(setOptions: Partial<Options>);
|
|
80
|
+
enable(): void;
|
|
81
|
+
destroy(): void;
|
|
82
|
+
shouldIgnoreVisit(href: string, { el }?: {
|
|
83
|
+
el?: Element;
|
|
84
|
+
}): boolean;
|
|
85
|
+
linkClickHandler(event: delegate.Event<MouseEvent>): void;
|
|
86
|
+
handleLinkToSamePage(url: string, hash: string, event: MouseEvent): void;
|
|
87
|
+
triggerWillOpenNewWindow(triggerEl: Element): boolean;
|
|
88
|
+
popStateHandler(event: PopStateEvent): void;
|
|
89
|
+
/**
|
|
90
|
+
* Utility function to validate and run the global option 'resolveUrl'
|
|
91
|
+
* @param {string} url
|
|
92
|
+
* @returns {string} the resolved url
|
|
93
|
+
*/
|
|
94
|
+
resolveUrl(url: string): string;
|
|
95
|
+
/**
|
|
96
|
+
* Compares the resolved version of two paths and returns true if they are the same
|
|
97
|
+
* @param {string} url1
|
|
98
|
+
* @param {string} url2
|
|
99
|
+
* @returns {boolean}
|
|
100
|
+
*/
|
|
101
|
+
isSameResolvedUrl(url1: string, url2: string): boolean;
|
|
102
|
+
}
|
|
103
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Swup from '../index';
|
|
2
|
+
import { PageData } from './getPageData';
|
|
3
|
+
export interface PageRecord extends PageData {
|
|
4
|
+
url: string;
|
|
5
|
+
responseURL: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class Cache {
|
|
8
|
+
pages: Record<string, PageRecord>;
|
|
9
|
+
last: PageRecord | null;
|
|
10
|
+
swup: Swup;
|
|
11
|
+
constructor(swup: Swup);
|
|
12
|
+
getCacheUrl(url: string): string;
|
|
13
|
+
cacheUrl(page: PageRecord): void;
|
|
14
|
+
getPage(url: string): PageRecord;
|
|
15
|
+
getCurrentPage(): PageRecord;
|
|
16
|
+
exists(url: string): boolean;
|
|
17
|
+
empty(): void;
|
|
18
|
+
remove(url: string): void;
|
|
19
|
+
}
|
|
20
|
+
export default Cache;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Swup from '../index';
|
|
2
|
+
export default 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
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Swup from '../index';
|
|
2
|
+
import { PageHtmlData } from '../helpers/getDataFromHtml';
|
|
3
|
+
export type PageData = PageHtmlData & {
|
|
4
|
+
responseURL: string;
|
|
5
|
+
};
|
|
6
|
+
declare const getPageData: (this: Swup, request: XMLHttpRequest) => PageData | null;
|
|
7
|
+
export default getPageData;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Swup from '../index';
|
|
2
|
+
import { TransitionOptions } from './loadPage';
|
|
3
|
+
declare const leavePage: (this: Swup, data: TransitionOptions, { popstate, skipTransition }?: {
|
|
4
|
+
popstate: PopStateEvent | null;
|
|
5
|
+
skipTransition?: boolean | undefined;
|
|
6
|
+
}) => Promise<void>[];
|
|
7
|
+
export default leavePage;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import Swup from '../index';
|
|
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
|
+
declare const on: (this: Swup, event: EventType, handler: Handler) => void;
|
|
6
|
+
export default on;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Swup from '../index';
|
|
2
|
+
export type Plugin = {
|
|
3
|
+
name: string;
|
|
4
|
+
mount: () => void;
|
|
5
|
+
unmount: () => void;
|
|
6
|
+
isSwupPlugin: true;
|
|
7
|
+
swup?: Swup;
|
|
8
|
+
_beforeMount?: () => void;
|
|
9
|
+
_afterUnmount?: () => void;
|
|
10
|
+
_checkRequirements?: () => boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare const use: (this: Swup, plugin: Plugin) => Plugin[] | undefined;
|
|
13
|
+
export declare function unuse(this: Swup, pluginOrName: Plugin | string): Plugin[] | undefined;
|
|
14
|
+
export declare function findPlugin(this: Swup, pluginOrName: Plugin | string): Plugin | undefined;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Swup from '../index';
|
|
2
|
+
import { PageRecord } from './Cache';
|
|
3
|
+
declare const renderPage: (this: Swup, page: PageRecord, { popstate, skipTransition }?: {
|
|
4
|
+
popstate: PopStateEvent | null;
|
|
5
|
+
skipTransition?: boolean | undefined;
|
|
6
|
+
}) => void;
|
|
7
|
+
export default renderPage;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Perform the replacement of content after loading a page.
|
|
3
|
+
*
|
|
4
|
+
* This method can be replaced or augmented by plugins to allow pausing.
|
|
5
|
+
*
|
|
6
|
+
* It takes an object with the page data as return from `getPageData` and has to
|
|
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
|
|
12
|
+
*/
|
|
13
|
+
declare const replaceContent: ({ blocks, title }: {
|
|
14
|
+
blocks: string[];
|
|
15
|
+
title: string;
|
|
16
|
+
}) => Promise<void>;
|
|
17
|
+
export default replaceContent;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const query: (selector: string, context?: Document | Element) => HTMLElement | null;
|
|
2
|
+
export declare const queryAll: (selector: string, context?: Document | Element) => HTMLElement[];
|
|
3
|
+
export declare const nextTick: (callback: () => void) => void;
|
|
4
|
+
export declare const escapeCssIdentifier: (ident: string) => string;
|
|
5
|
+
export declare const toMs: (s: string) => number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './utils/index.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type EventType = 'animationInDone' | 'animationInStart' | 'animationOutDone' | 'animationOutStart' | 'animationSkipped' | 'clickLink' | 'contentReplaced' | 'disabled' | 'enabled' | 'openPageInNewTab' | 'pageLoaded' | 'pageRetrievedFromCache' | 'pageView' | 'popState' | 'samePage' | 'samePageWithHash' | 'serverError' | 'transitionStart' | 'transitionEnd' | 'willReplaceContent';
|
|
2
|
+
export type Handler = (event?: Event) => void;
|
|
3
|
+
export type Handlers = Record<EventType, Handler[]>;
|
|
4
|
+
export type Transition = {
|
|
5
|
+
from?: string;
|
|
6
|
+
to?: string;
|
|
7
|
+
custom?: string;
|
|
8
|
+
};
|
|
9
|
+
export type TransitionOptions = {
|
|
10
|
+
url: string;
|
|
11
|
+
customTransition?: string;
|
|
12
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const query: (selector: string, context?: Document | Element) => HTMLElement | null;
|
|
2
|
+
export declare const queryAll: (selector: string, context?: Document | Element) => HTMLElement[];
|
|
3
|
+
export declare const nextTick: (callback: () => void) => void;
|
|
4
|
+
export declare const escapeCssIdentifier: (ident: string) => string;
|
|
5
|
+
export declare const toMs: (s: string) => number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './utils/index.js';
|
package/dist/types.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|