swup 2.0.18 → 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.
Files changed (151) hide show
  1. package/dist/helpers.cjs +2 -0
  2. package/dist/helpers.cjs.map +1 -0
  3. package/dist/helpers.modern.js +2 -0
  4. package/dist/helpers.modern.js.map +1 -0
  5. package/dist/helpers.module.js +2 -0
  6. package/dist/helpers.module.js.map +1 -0
  7. package/dist/index.cjs +2 -0
  8. package/dist/index.cjs.map +1 -0
  9. package/dist/index.modern.js +2 -0
  10. package/dist/index.modern.js.map +1 -0
  11. package/dist/index.module.js +2 -0
  12. package/dist/index.module.js.map +1 -0
  13. package/dist/index.umd.js +3 -0
  14. package/dist/index.umd.js.map +1 -0
  15. package/dist/src/config/version.d.ts +5 -0
  16. package/dist/src/helpers/Location.d.ts +31 -0
  17. package/dist/src/helpers/classify.d.ts +2 -0
  18. package/dist/src/helpers/cleanupAnimationClasses.d.ts +2 -0
  19. package/dist/src/helpers/createHistoryRecord.d.ts +2 -0
  20. package/dist/src/helpers/delegateEvent.d.ts +8 -0
  21. package/dist/src/helpers/fetch.d.ts +6 -0
  22. package/dist/src/helpers/getCurrentUrl.d.ts +4 -0
  23. package/dist/src/helpers/getDataFromHtml.d.ts +8 -0
  24. package/dist/src/helpers/index.d.ts +11 -0
  25. package/dist/src/helpers/markSwupElements.d.ts +2 -0
  26. package/dist/src/helpers/updateHistoryRecord.d.ts +2 -0
  27. package/dist/src/helpers/versionSatisfies.d.ts +12 -0
  28. package/dist/src/helpers.d.ts +1 -0
  29. package/dist/src/index.d.ts +97 -0
  30. package/dist/src/modules/Cache.d.ts +20 -0
  31. package/dist/src/modules/enterPage.d.ts +6 -0
  32. package/dist/src/modules/getAnchorElement.d.ts +2 -0
  33. package/dist/src/modules/getAnimationPromises.d.ts +7 -0
  34. package/dist/src/modules/getPageData.d.ts +7 -0
  35. package/dist/src/modules/leavePage.d.ts +7 -0
  36. package/dist/src/modules/loadPage.d.ts +4 -0
  37. package/dist/src/modules/off.d.ts +4 -0
  38. package/dist/src/modules/on.d.ts +4 -0
  39. package/dist/src/modules/plugins.d.ts +13 -0
  40. package/dist/src/modules/renderPage.d.ts +7 -0
  41. package/dist/src/modules/replaceContent.d.ts +17 -0
  42. package/dist/src/modules/triggerEvent.d.ts +4 -0
  43. package/dist/src/modules/updateTransition.d.ts +3 -0
  44. package/dist/src/src/config/version.d.ts +5 -0
  45. package/dist/src/src/helpers/Location.d.ts +31 -0
  46. package/dist/src/src/helpers/classify.d.ts +2 -0
  47. package/dist/src/src/helpers/cleanupAnimationClasses.d.ts +2 -0
  48. package/dist/src/src/helpers/createHistoryRecord.d.ts +2 -0
  49. package/dist/src/src/helpers/delegateEvent.d.ts +8 -0
  50. package/dist/src/src/helpers/fetch.d.ts +6 -0
  51. package/dist/src/src/helpers/getCurrentUrl.d.ts +4 -0
  52. package/dist/src/src/helpers/getDataFromHtml.d.ts +8 -0
  53. package/dist/src/src/helpers/index.d.ts +11 -0
  54. package/dist/src/src/helpers/markSwupElements.d.ts +2 -0
  55. package/dist/src/src/helpers/updateHistoryRecord.d.ts +2 -0
  56. package/dist/src/src/helpers/versionSatisfies.d.ts +12 -0
  57. package/dist/src/src/helpers.d.ts +1 -0
  58. package/dist/src/src/index.d.ts +103 -0
  59. package/dist/src/src/modules/Cache.d.ts +20 -0
  60. package/dist/src/src/modules/enterPage.d.ts +6 -0
  61. package/dist/src/src/modules/getAnchorElement.d.ts +2 -0
  62. package/dist/src/src/modules/getAnimationPromises.d.ts +7 -0
  63. package/dist/src/src/modules/getPageData.d.ts +7 -0
  64. package/dist/src/src/modules/leavePage.d.ts +7 -0
  65. package/dist/src/src/modules/loadPage.d.ts +7 -0
  66. package/dist/src/src/modules/off.d.ts +4 -0
  67. package/dist/src/src/modules/on.d.ts +6 -0
  68. package/dist/src/src/modules/plugins.d.ts +14 -0
  69. package/dist/src/src/modules/renderPage.d.ts +7 -0
  70. package/dist/src/src/modules/replaceContent.d.ts +17 -0
  71. package/dist/src/src/modules/triggerEvent.d.ts +4 -0
  72. package/dist/src/src/modules/updateTransition.d.ts +3 -0
  73. package/dist/src/src/utils/index.d.ts +5 -0
  74. package/dist/src/src/utils.d.ts +1 -0
  75. package/dist/src/types.d.ts +12 -0
  76. package/dist/src/utils/index.d.ts +5 -0
  77. package/dist/src/utils.d.ts +1 -0
  78. package/dist/types.cjs +2 -0
  79. package/dist/types.cjs.map +1 -0
  80. package/dist/types.modern.js +2 -0
  81. package/dist/types.modern.js.map +1 -0
  82. package/dist/types.module.js +2 -0
  83. package/dist/types.module.js.map +1 -0
  84. package/dist/utils.cjs +2 -0
  85. package/dist/utils.cjs.map +1 -0
  86. package/dist/utils.modern.js +2 -0
  87. package/dist/utils.modern.js.map +1 -0
  88. package/dist/utils.module.js +2 -0
  89. package/dist/utils.module.js.map +1 -0
  90. package/package.json +44 -21
  91. package/readme.md +52 -36
  92. package/src/config/version.ts +13 -0
  93. package/src/helpers/Location.ts +44 -0
  94. package/src/helpers/classify.ts +13 -0
  95. package/src/helpers/cleanupAnimationClasses.ts +10 -0
  96. package/src/helpers/createHistoryRecord.ts +14 -0
  97. package/src/helpers/delegateEvent.ts +23 -0
  98. package/src/helpers/fetch.ts +35 -0
  99. package/src/helpers/getCurrentUrl.ts +5 -0
  100. package/src/helpers/getDataFromHtml.ts +41 -0
  101. package/src/helpers/index.ts +11 -0
  102. package/src/helpers/markSwupElements.ts +18 -0
  103. package/src/helpers/updateHistoryRecord.ts +18 -0
  104. package/src/helpers/versionSatisfies.ts +50 -0
  105. package/src/helpers.ts +4 -0
  106. package/src/index.ts +369 -0
  107. package/src/modules/Cache.ts +57 -0
  108. package/src/modules/enterPage.ts +28 -0
  109. package/src/modules/fetchPage.ts +35 -0
  110. package/src/modules/getAnchorElement.ts +19 -0
  111. package/src/modules/getAnimationPromises.ts +176 -0
  112. package/src/modules/getPageData.ts +26 -0
  113. package/src/modules/leavePage.ts +33 -0
  114. package/src/modules/loadPage.ts +54 -0
  115. package/src/modules/off.ts +23 -0
  116. package/src/modules/on.ts +35 -0
  117. package/src/modules/plugins.ts +58 -0
  118. package/src/modules/renderPage.ts +52 -0
  119. package/src/modules/replaceContent.ts +28 -0
  120. package/src/modules/triggerEvent.ts +23 -0
  121. package/src/modules/updateTransition.ts +7 -0
  122. package/src/utils/index.ts +32 -0
  123. package/src/utils.ts +4 -0
  124. package/cypress.config.js +0 -13
  125. package/dist/swup.js +0 -1519
  126. package/dist/swup.min.js +0 -1
  127. package/lib/helpers/Link.js +0 -56
  128. package/lib/helpers/classify.js +0 -18
  129. package/lib/helpers/cleanupAnimationClasses.js +0 -18
  130. package/lib/helpers/createHistoryRecord.js +0 -14
  131. package/lib/helpers/fetch.js +0 -41
  132. package/lib/helpers/getCurrentUrl.js +0 -10
  133. package/lib/helpers/getDataFromHtml.js +0 -43
  134. package/lib/helpers/index.js +0 -64
  135. package/lib/helpers/markSwupElements.js +0 -24
  136. package/lib/helpers/normalizeUrl.js +0 -17
  137. package/lib/helpers/transitionEnd.js +0 -14
  138. package/lib/helpers/transitionProperty.js +0 -14
  139. package/lib/index.js +0 -305
  140. package/lib/modules/Cache.js +0 -66
  141. package/lib/modules/getAnchorElement.js +0 -25
  142. package/lib/modules/getAnimationPromises.js +0 -43
  143. package/lib/modules/getPageData.js +0 -26
  144. package/lib/modules/loadPage.js +0 -118
  145. package/lib/modules/off.js +0 -34
  146. package/lib/modules/on.js +0 -14
  147. package/lib/modules/plugins.js +0 -54
  148. package/lib/modules/renderPage.js +0 -76
  149. package/lib/modules/triggerEvent.js +0 -21
  150. package/lib/modules/updateTransition.js +0 -15
  151. 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,6 @@
1
+ import Swup from '../index';
2
+ declare const enterPage: (this: Swup, { popstate, skipTransition }: {
3
+ popstate?: PopStateEvent | undefined;
4
+ skipTransition?: boolean | undefined;
5
+ }) => Promise<void>[];
6
+ export default enterPage;
@@ -0,0 +1,2 @@
1
+ declare const getAnchorElement: (hash: string) => Element | null;
2
+ export default getAnchorElement;
@@ -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,4 @@
1
+ import Swup from '../index';
2
+ import { TransitionOptions } from '../types';
3
+ declare const loadPage: (this: Swup, data: TransitionOptions, popstate: PopStateEvent | null) => void;
4
+ export default loadPage;
@@ -0,0 +1,4 @@
1
+ import Swup from '../index';
2
+ import { EventType, Handler } from '../types';
3
+ declare const off: (this: Swup, event?: EventType, handler?: Handler) => void;
4
+ export default off;
@@ -0,0 +1,4 @@
1
+ import { EventType, Handler } from '../types';
2
+ import Swup from '../index';
3
+ declare const on: (this: Swup, event: EventType, handler: Handler) => void;
4
+ export default on;
@@ -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,4 @@
1
+ import { EventType } from '../types';
2
+ import Swup from '../index';
3
+ declare const triggerEvent: (this: Swup, eventName: EventType, originalEvent?: PopStateEvent | MouseEvent) => void;
4
+ export default triggerEvent;
@@ -0,0 +1,3 @@
1
+ import Swup from '../index';
2
+ declare const updateTransition: (this: Swup, from: string, to: string, custom?: string) => void;
3
+ export default updateTransition;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Import swup's current version from package.json
3
+ */
4
+ declare const _default: string;
5
+ export default _default;
@@ -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,2 @@
1
+ declare const classify: (text: string, fallback?: string) => string;
2
+ export default classify;
@@ -0,0 +1,2 @@
1
+ declare const cleanupAnimationClasses: () => void;
2
+ export default cleanupAnimationClasses;
@@ -0,0 +1,2 @@
1
+ declare const createHistoryRecord: (url: string, customData?: Record<string, unknown>) => void;
2
+ export default createHistoryRecord;
@@ -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,4 @@
1
+ declare const getCurrentUrl: ({ hash }?: {
2
+ hash?: boolean | undefined;
3
+ }) => string;
4
+ export default getCurrentUrl;
@@ -0,0 +1,8 @@
1
+ export type PageHtmlData = {
2
+ title: string;
3
+ originalContent: string;
4
+ blocks: string[];
5
+ pageClass?: string;
6
+ };
7
+ declare const getDataFromHtml: (html: string, containers: string[]) => PageHtmlData;
8
+ export default getDataFromHtml;
@@ -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,2 @@
1
+ declare const markSwupElements: (element: Element, containers: string[]) => void;
2
+ export default markSwupElements;
@@ -0,0 +1,2 @@
1
+ declare const updateHistoryRecord: (url?: string | null, customData?: Record<string, unknown>) => void;
2
+ export default updateHistoryRecord;
@@ -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,6 @@
1
+ import Swup from '../index';
2
+ declare const enterPage: (this: Swup, { popstate, skipTransition }: {
3
+ popstate?: PopStateEvent | undefined;
4
+ skipTransition?: boolean | undefined;
5
+ }) => Promise<void>[];
6
+ export default enterPage;
@@ -0,0 +1,2 @@
1
+ declare const getAnchorElement: (hash: string) => Element | null;
2
+ export default getAnchorElement;
@@ -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,7 @@
1
+ import Swup from '../index';
2
+ export type TransitionOptions = {
3
+ url: string;
4
+ customTransition?: string;
5
+ };
6
+ declare const loadPage: (this: Swup, data: TransitionOptions, popstate: PopStateEvent | null) => void;
7
+ export default loadPage;
@@ -0,0 +1,4 @@
1
+ import Swup from '../index';
2
+ import { EventType, Handler } from './on';
3
+ declare const off: (this: Swup, event?: EventType, handler?: Handler) => void;
4
+ export default off;
@@ -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,4 @@
1
+ import { EventType } from './on';
2
+ import Swup from '../index';
3
+ declare const triggerEvent: (this: Swup, eventName: EventType, originalEvent?: PopStateEvent | MouseEvent) => void;
4
+ export default triggerEvent;
@@ -0,0 +1,3 @@
1
+ import Swup from '../index';
2
+ declare const updateTransition: (this: Swup, from: string, to: string, custom?: string) => void;
3
+ export default updateTransition;
@@ -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,2 @@
1
+
2
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=types.modern.js.map