swup 4.0.0-rc.30 → 4.0.0

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.
@@ -1,16 +1,13 @@
1
1
  import { DelegateEvent } from 'delegate-it';
2
- import { delegateEvent, getCurrentUrl } from './helpers.js';
3
2
  import { DelegateEventUnsubscribe } from './helpers/delegateEvent.js';
4
3
  import { Cache } from './modules/Cache.js';
5
4
  import { Classes } from './modules/Classes.js';
6
5
  import { Visit, createVisit } from './modules/Visit.js';
7
6
  import { Hooks } from './modules/Hooks.js';
8
- import { getAnchorElement } from './modules/getAnchorElement.js';
9
7
  import { awaitAnimations } from './modules/awaitAnimations.js';
10
8
  import { navigate, performNavigation } from './modules/navigate.js';
11
9
  import { fetchPage } from './modules/fetchPage.js';
12
- import { replaceContent } from './modules/replaceContent.js';
13
- import { use, unuse, findPlugin, Plugin } from './modules/plugins.js';
10
+ import { unuse, findPlugin, Plugin } from './modules/plugins.js';
14
11
  import { isSameResolvedUrl, resolveUrl } from './modules/resolveUrl.js';
15
12
  /** Options for customizing swup's behavior. */
16
13
  export type Options = {
@@ -40,18 +37,18 @@ export type Options = {
40
37
  /** Callback for telling swup to ignore certain popstate events. */
41
38
  skipPopStateHandling: (event: any) => boolean;
42
39
  };
43
- /** Interface for Swup page transition library. */
44
- export interface SwupCore {
40
+ /** Swup page transition library. */
41
+ export default class Swup {
45
42
  /** Library version */
46
43
  readonly version: string;
47
44
  /** Options passed into the instance */
48
45
  options: Options;
49
46
  /** Default options before merging user options */
50
- readonly defaults: Readonly<Options>;
47
+ readonly defaults: Options;
51
48
  /** Registered plugin instances */
52
- readonly plugins: Plugin[];
49
+ plugins: Plugin[];
53
50
  /** Data about the current visit */
54
- readonly visit: Visit;
51
+ visit: Visit;
55
52
  /** Cache instance */
56
53
  readonly cache: Cache;
57
54
  /** Hook registry */
@@ -60,12 +57,12 @@ export interface SwupCore {
60
57
  readonly classes: Classes;
61
58
  /** URL of the currently visible page */
62
59
  currentPageUrl: string;
63
- /** Enable the instance */
64
- enable(): Promise<void>;
65
- /** Disable the instance and clean up */
66
- destroy(): Promise<void>;
60
+ /** Index of the current history entry */
61
+ protected currentHistoryIndex: number;
62
+ /** Delegated event subscription handle */
63
+ protected clickDelegate?: DelegateEventUnsubscribe;
67
64
  /** Install a plugin */
68
- use: typeof use;
65
+ use: (this: Swup, plugin: unknown) => Plugin[] | undefined;
69
66
  /** Uninstall a plugin */
70
67
  unuse: typeof unuse;
71
68
  /** Find a plugin by name or instance */
@@ -74,59 +71,34 @@ export interface SwupCore {
74
71
  log: (message: string, context?: any) => void;
75
72
  /** Navigate to a new URL */
76
73
  navigate: typeof navigate;
77
- /** Replace the content after page load */
78
- replaceContent: typeof replaceContent;
74
+ /** Actually perform a navigation */
75
+ protected performNavigation: typeof performNavigation;
76
+ /** Create a new context for this visit */
77
+ protected createVisit: typeof createVisit;
79
78
  /** Register a delegated event listener */
80
- delegateEvent: typeof delegateEvent;
79
+ delegateEvent: <Selector extends string, TEvent extends keyof GlobalEventHandlersEventMap>(selector: Selector, type: TEvent, callback: import("delegate-it").DelegateEventHandler<GlobalEventHandlersEventMap[TEvent], Element>, options?: import("delegate-it").DelegateOptions | undefined) => DelegateEventUnsubscribe;
81
80
  /** Fetch a page from the server */
82
81
  fetchPage: typeof fetchPage;
83
82
  /** Resolve when animations on the page finish */
84
83
  awaitAnimations: typeof awaitAnimations;
85
- /** Find the anchor element for a given hash */
86
- getAnchorElement: typeof getAnchorElement;
87
- /** Get the current page URL */
88
- getCurrentUrl: typeof getCurrentUrl;
89
- /** Resolve a URL to its final location */
90
- resolveUrl(url: string): string;
91
- }
92
- /** Swup page transition library. */
93
- export default class Swup implements SwupCore {
94
- version: string;
95
- options: Options;
96
- plugins: Plugin[];
97
- cache: Cache;
98
- hooks: Hooks;
99
- visit: Visit;
100
- classes: Classes;
101
- currentPageUrl: string;
102
- getCurrentUrl: ({ hash }?: {
103
- hash?: boolean | undefined;
104
- }) => string;
105
- use: (this: Swup, plugin: unknown) => Plugin[] | undefined;
106
- unuse: typeof unuse;
107
- findPlugin: typeof findPlugin;
108
- log: () => void;
109
- getAnchorElement: (hash: string) => Element | null;
110
- navigate: typeof navigate;
111
- protected performNavigation: typeof performNavigation;
112
- delegateEvent: <Selector extends string, TEvent extends keyof GlobalEventHandlersEventMap>(selector: Selector, type: TEvent, callback: import("delegate-it").DelegateEventHandler<GlobalEventHandlersEventMap[TEvent], Element>, options?: import("delegate-it").DelegateOptions | undefined) => DelegateEventUnsubscribe;
113
- fetchPage: typeof fetchPage;
114
- awaitAnimations: typeof awaitAnimations;
115
84
  protected renderPage: (this: Swup, requestedUrl: string, page: import("./modules/fetchPage.js").PageData) => Promise<void>;
85
+ /** Replace the content after page load */
116
86
  replaceContent: (this: Swup, { html }: import("./modules/fetchPage.js").PageData, { containers }?: {
117
87
  containers: string[];
118
88
  }) => boolean;
119
89
  protected animatePageIn: (this: Swup) => Promise<void>;
120
90
  protected animatePageOut: (this: Swup) => Promise<void>;
121
91
  protected scrollToContent: (this: Swup) => boolean;
122
- protected createVisit: typeof createVisit;
92
+ /** Find the anchor element for a given hash */
93
+ getAnchorElement: (hash: string) => Element | null;
94
+ /** Get the current page URL */
95
+ getCurrentUrl: ({ hash }?: {
96
+ hash?: boolean | undefined;
97
+ }) => string;
98
+ /** Resolve a URL to its final location */
123
99
  resolveUrl: typeof resolveUrl;
100
+ /** Check if two URLs resolve to the same location */
124
101
  protected isSameResolvedUrl: typeof isSameResolvedUrl;
125
- readonly defaults: Options;
126
- /** Index of the current history entry */
127
- protected currentHistoryIndex: number;
128
- /** Delegated event subscription handle */
129
- protected clickDelegate?: DelegateEventUnsubscribe;
130
102
  constructor(options?: Partial<Options>);
131
103
  protected checkRequirements(): boolean;
132
104
  /** Enable this instance, adding listeners and classnames. */
@@ -1,6 +1,6 @@
1
1
  import type { Path } from 'path-to-regexp';
2
2
  import Swup from './Swup.js';
3
- import type { SwupCore, Options } from './Swup.js';
3
+ import type { Options } from './Swup.js';
4
4
  import type { CacheData } from './modules/Cache.js';
5
5
  import type { Visit, VisitFrom, VisitTo, VisitAnimation, VisitScroll, VisitHistory } from './modules/Visit.js';
6
6
  import type { HookDefinitions, HookName, HookOptions, HookUnregister, Handler } from './modules/Hooks.js';
@@ -8,4 +8,4 @@ import type { Plugin } from './modules/plugins.js';
8
8
  export default Swup;
9
9
  export * from './helpers.js';
10
10
  export * from './utils.js';
11
- export { SwupCore, Options, Plugin, CacheData, Visit, VisitFrom, VisitTo, VisitAnimation, VisitScroll, VisitHistory, HookDefinitions, HookName, HookOptions, HookUnregister, Handler, Path };
11
+ export type { Swup, Options, Plugin, CacheData, Visit, VisitFrom, VisitTo, VisitAnimation, VisitScroll, VisitHistory, HookDefinitions, HookName, HookOptions, HookUnregister, Handler, Path };
@@ -7,9 +7,9 @@ export interface CacheData extends PageData {
7
7
  */
8
8
  export declare class Cache {
9
9
  /** Swup instance this cache belongs to */
10
- private swup;
10
+ protected swup: Swup;
11
11
  /** Cached pages, indexed by URL */
12
- private pages;
12
+ protected pages: Map<string, CacheData>;
13
13
  constructor(swup: Swup);
14
14
  /** Number of cached pages in memory. */
15
15
  get size(): number;
@@ -30,5 +30,5 @@ export declare class Cache {
30
30
  /** Remove all cache entries that return true for a given predicate function. */
31
31
  prune(predicate: (url: string, page: CacheData) => boolean): void;
32
32
  /** Resolve URLs by making them local and letting swup resolve them. */
33
- private resolve;
33
+ protected resolve(urlToResolve: string): string;
34
34
  }
@@ -1,13 +1,13 @@
1
1
  import Swup from '../Swup.js';
2
2
  export declare class Classes {
3
- swup: Swup;
4
- swupClasses: string[];
3
+ protected swup: Swup;
4
+ protected swupClasses: string[];
5
5
  constructor(swup: Swup);
6
- get selectors(): string[];
7
- get selector(): string;
8
- get targets(): HTMLElement[];
6
+ protected get selectors(): string[];
7
+ protected get selector(): string;
8
+ protected get targets(): HTMLElement[];
9
9
  add(...classes: string[]): void;
10
10
  remove(...classes: string[]): void;
11
11
  clear(): void;
12
- private isSwupClass;
12
+ protected isSwupClass(className: string): boolean;
13
13
  }
@@ -213,13 +213,13 @@ export declare class Hooks {
213
213
  * @param registrations The registrations (handler + options) to execute
214
214
  * @param args Arguments to pass to the handler
215
215
  */
216
- private run;
216
+ protected run<T extends HookName>(registrations: HookRegistration<T>[], args?: HookArguments<T>): Promise<any>;
217
217
  /**
218
218
  * Execute the handlers for a hook, in order, without `await`ing any returned `Promise`s.
219
219
  * @param registrations The registrations (handler + options) to execute
220
220
  * @param args Arguments to pass to the handler
221
221
  */
222
- private runSync;
222
+ protected runSync<T extends HookName>(registrations: HookRegistration<T>[], args?: HookArguments<T>): any[];
223
223
  /**
224
224
  * Get all registered handlers for a hook, sorted by priority and registration order.
225
225
  * @param hook Name of the hook
@@ -227,18 +227,24 @@ export declare class Hooks {
227
227
  * @returns An object with the handlers sorted into `before` and `after` arrays,
228
228
  * as well as a flag indicating if the original handler was replaced
229
229
  */
230
- private getHandlers;
230
+ protected getHandlers<T extends HookName>(hook: T, defaultHandler?: Handler<T>): {
231
+ found: boolean;
232
+ before: HookRegistration<T>[];
233
+ handler: HookRegistration<T>[];
234
+ after: HookRegistration<T>[];
235
+ replaced: boolean;
236
+ };
231
237
  /**
232
238
  * Sort two hook registrations by priority and registration order.
233
239
  * @param a The registration object to compare
234
240
  * @param b The other registration object to compare with
235
241
  * @returns The sort direction
236
242
  */
237
- private sortRegistrations;
243
+ protected sortRegistrations<T extends HookName>(a: HookRegistration<T>, b: HookRegistration<T>): number;
238
244
  /**
239
245
  * Dispatch a custom event on the `document` for a hook. Prefixed with `swup:`
240
246
  * @param hook Name of the hook.
241
247
  */
242
- private dispatchDomEvent;
248
+ protected dispatchDomEvent<T extends HookName>(hook: T, args?: HookArguments<T>): void;
243
249
  }
244
250
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "swup",
3
3
  "amdName": "Swup",
4
- "version": "4.0.0-rc.30",
4
+ "version": "4.0.0",
5
5
  "description": "Versatile and extensible page transition library for server-rendered websites",
6
6
  "type": "module",
7
7
  "source": "./src/Swup.ts",
package/src/Swup.ts CHANGED
@@ -48,18 +48,35 @@ export type Options = {
48
48
  skipPopStateHandling: (event: any) => boolean;
49
49
  };
50
50
 
51
- /** Interface for Swup page transition library. */
52
- export interface SwupCore {
51
+ const defaults: Options = {
52
+ animateHistoryBrowsing: false,
53
+ animationSelector: '[class*="transition-"]',
54
+ animationScope: 'html',
55
+ cache: true,
56
+ containers: ['#swup'],
57
+ ignoreVisit: (url, { el, event } = {}) => !!el?.closest('[data-no-swup]'),
58
+ linkSelector: 'a[href]',
59
+ plugins: [],
60
+ resolveUrl: (url) => url,
61
+ requestHeaders: {
62
+ 'X-Requested-With': 'swup',
63
+ 'Accept': 'text/html, application/xhtml+xml'
64
+ },
65
+ skipPopStateHandling: (event) => event.state?.source !== 'swup'
66
+ };
67
+
68
+ /** Swup page transition library. */
69
+ export default class Swup {
53
70
  /** Library version */
54
- readonly version: string;
71
+ readonly version: string = version;
55
72
  /** Options passed into the instance */
56
73
  options: Options;
57
74
  /** Default options before merging user options */
58
- readonly defaults: Readonly<Options>;
75
+ readonly defaults: Options = defaults;
59
76
  /** Registered plugin instances */
60
- readonly plugins: Plugin[];
77
+ plugins: Plugin[] = [];
61
78
  /** Data about the current visit */
62
- readonly visit: Visit;
79
+ visit: Visit;
63
80
  /** Cache instance */
64
81
  readonly cache: Cache;
65
82
  /** Hook registry */
@@ -67,101 +84,50 @@ export interface SwupCore {
67
84
  /** Animation class manager */
68
85
  readonly classes: Classes;
69
86
  /** URL of the currently visible page */
70
- currentPageUrl: string;
71
-
72
- /** Enable the instance */
73
- enable(): Promise<void>;
74
- /** Disable the instance and clean up */
75
- destroy(): Promise<void>;
87
+ currentPageUrl: string = getCurrentUrl();
88
+ /** Index of the current history entry */
89
+ protected currentHistoryIndex = 1;
90
+ /** Delegated event subscription handle */
91
+ protected clickDelegate?: DelegateEventUnsubscribe;
76
92
 
77
93
  /** Install a plugin */
78
- use: typeof use;
94
+ use = use;
79
95
  /** Uninstall a plugin */
80
- unuse: typeof unuse;
96
+ unuse = unuse;
81
97
  /** Find a plugin by name or instance */
82
- findPlugin: typeof findPlugin;
98
+ findPlugin = findPlugin;
83
99
 
84
100
  /** Log a message. Has no effect unless debug plugin is installed */
85
- log: (message: string, context?: any) => void;
101
+ log: (message: string, context?: any) => void = () => {};
86
102
 
87
103
  /** Navigate to a new URL */
88
- navigate: typeof navigate;
89
- /** Replace the content after page load */
90
- replaceContent: typeof replaceContent;
91
- /** Register a delegated event listener */
92
- delegateEvent: typeof delegateEvent;
93
- /** Fetch a page from the server */
94
- fetchPage: typeof fetchPage;
95
- /** Resolve when animations on the page finish */
96
- awaitAnimations: typeof awaitAnimations;
97
- /** Find the anchor element for a given hash */
98
- getAnchorElement: typeof getAnchorElement;
99
-
100
- /** Get the current page URL */
101
- getCurrentUrl: typeof getCurrentUrl;
102
- /** Resolve a URL to its final location */
103
- resolveUrl(url: string): string;
104
- }
105
-
106
- /** Swup page transition library. */
107
- export default class Swup implements SwupCore {
108
- version = version;
109
- options: Options;
110
- plugins: Plugin[] = [];
111
- cache: Cache;
112
- hooks: Hooks;
113
- visit: Visit;
114
- classes: Classes;
115
-
116
- currentPageUrl = getCurrentUrl();
117
- getCurrentUrl = getCurrentUrl;
118
-
119
- use = use;
120
- unuse = unuse;
121
- findPlugin = findPlugin;
122
-
123
- log = () => {};
124
-
125
- getAnchorElement = getAnchorElement;
126
-
127
104
  navigate = navigate;
105
+ /** Actually perform a navigation */
128
106
  protected performNavigation = performNavigation;
107
+ /** Create a new context for this visit */
108
+ protected createVisit = createVisit;
109
+ /** Register a delegated event listener */
129
110
  delegateEvent = delegateEvent;
111
+ /** Fetch a page from the server */
130
112
  fetchPage = fetchPage;
113
+ /** Resolve when animations on the page finish */
131
114
  awaitAnimations = awaitAnimations;
132
115
  protected renderPage = renderPage;
116
+ /** Replace the content after page load */
133
117
  replaceContent = replaceContent;
134
118
  protected animatePageIn = animatePageIn;
135
119
  protected animatePageOut = animatePageOut;
136
120
  protected scrollToContent = scrollToContent;
121
+ /** Find the anchor element for a given hash */
122
+ getAnchorElement = getAnchorElement;
137
123
 
138
- protected createVisit = createVisit;
124
+ /** Get the current page URL */
125
+ getCurrentUrl = getCurrentUrl;
126
+ /** Resolve a URL to its final location */
139
127
  resolveUrl = resolveUrl;
128
+ /** Check if two URLs resolve to the same location */
140
129
  protected isSameResolvedUrl = isSameResolvedUrl;
141
130
 
142
- readonly defaults: Options = {
143
- animateHistoryBrowsing: false,
144
- animationSelector: '[class*="transition-"]',
145
- animationScope: 'html',
146
- cache: true,
147
- containers: ['#swup'],
148
- ignoreVisit: (url, { el, event } = {}) => !!el?.closest('[data-no-swup]'),
149
- linkSelector: 'a[href]',
150
- plugins: [],
151
- resolveUrl: (url) => url,
152
- requestHeaders: {
153
- 'X-Requested-With': 'swup',
154
- 'Accept': 'text/html, application/xhtml+xml'
155
- },
156
- skipPopStateHandling: (event) => event.state?.source !== 'swup'
157
- };
158
-
159
- /** Index of the current history entry */
160
- protected currentHistoryIndex = 1;
161
-
162
- /** Delegated event subscription handle */
163
- protected clickDelegate?: DelegateEventUnsubscribe;
164
-
165
131
  constructor(options: Partial<Options> = {}) {
166
132
  // Merge defaults and options
167
133
  this.options = { ...this.defaults, ...options };
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { Path } from 'path-to-regexp';
2
2
 
3
3
  import Swup from './Swup.js';
4
- import type { SwupCore, Options } from './Swup.js';
4
+ import type { Options } from './Swup.js';
5
5
  import type { CacheData } from './modules/Cache.js';
6
6
  import type {
7
7
  Visit,
@@ -23,8 +23,8 @@ import type { Plugin } from './modules/plugins.js';
23
23
  export default Swup;
24
24
  export * from './helpers.js';
25
25
  export * from './utils.js';
26
- export {
27
- SwupCore,
26
+ export type {
27
+ Swup,
28
28
  Options,
29
29
  Plugin,
30
30
  CacheData,
@@ -9,10 +9,10 @@ export interface CacheData extends PageData {}
9
9
  */
10
10
  export class Cache {
11
11
  /** Swup instance this cache belongs to */
12
- private swup: Swup;
12
+ protected swup: Swup;
13
13
 
14
14
  /** Cached pages, indexed by URL */
15
- private pages: Map<string, CacheData> = new Map();
15
+ protected pages: Map<string, CacheData> = new Map();
16
16
 
17
17
  constructor(swup: Swup) {
18
18
  this.swup = swup;
@@ -29,17 +29,17 @@ export class Cache {
29
29
  }
30
30
 
31
31
  /** Check if the given URL has been cached. */
32
- public has(url: string): boolean {
32
+ has(url: string): boolean {
33
33
  return this.pages.has(this.resolve(url));
34
34
  }
35
35
 
36
36
  /** Return the cached page object if cached. */
37
- public get(url: string): CacheData | undefined {
37
+ get(url: string): CacheData | undefined {
38
38
  return this.pages.get(this.resolve(url));
39
39
  }
40
40
 
41
41
  /** Create a cache record for the specified URL. */
42
- public set(url: string, page: CacheData) {
42
+ set(url: string, page: CacheData) {
43
43
  url = this.resolve(url);
44
44
  page = { ...page, url };
45
45
  this.pages.set(url, page);
@@ -47,25 +47,25 @@ export class Cache {
47
47
  }
48
48
 
49
49
  /** Update a cache record, overwriting or adding custom data. */
50
- public update(url: string, page: CacheData) {
50
+ update(url: string, page: CacheData) {
51
51
  url = this.resolve(url);
52
52
  page = { ...this.get(url), ...page, url };
53
53
  this.pages.set(url, page);
54
54
  }
55
55
 
56
56
  /** Delete a cache record. */
57
- public delete(url: string): void {
57
+ delete(url: string): void {
58
58
  this.pages.delete(this.resolve(url));
59
59
  }
60
60
 
61
61
  /** Empty the cache. */
62
- public clear(): void {
62
+ clear(): void {
63
63
  this.pages.clear();
64
64
  this.swup.hooks.callSync('cache:clear');
65
65
  }
66
66
 
67
67
  /** Remove all cache entries that return true for a given predicate function. */
68
- public prune(predicate: (url: string, page: CacheData) => boolean): void {
68
+ prune(predicate: (url: string, page: CacheData) => boolean): void {
69
69
  this.pages.forEach((page, url) => {
70
70
  if (predicate(url, page)) {
71
71
  this.delete(url);
@@ -74,7 +74,7 @@ export class Cache {
74
74
  }
75
75
 
76
76
  /** Resolve URLs by making them local and letting swup resolve them. */
77
- private resolve(urlToResolve: string): string {
77
+ protected resolve(urlToResolve: string): string {
78
78
  const { url } = Location.fromUrl(urlToResolve);
79
79
  return this.swup.resolveUrl(url);
80
80
  }
@@ -2,15 +2,14 @@ import Swup from '../Swup.js';
2
2
  import { queryAll } from '../utils.js';
3
3
 
4
4
  export class Classes {
5
- public swup: Swup;
6
-
7
- swupClasses = ['to-', 'is-changing', 'is-rendering', 'is-popstate', 'is-animating'];
5
+ protected swup: Swup;
6
+ protected swupClasses = ['to-', 'is-changing', 'is-rendering', 'is-popstate', 'is-animating'];
8
7
 
9
8
  constructor(swup: Swup) {
10
9
  this.swup = swup;
11
10
  }
12
11
 
13
- get selectors(): string[] {
12
+ protected get selectors(): string[] {
14
13
  const { scope } = this.swup.visit.animation;
15
14
  if (scope === 'containers') return this.swup.visit.containers;
16
15
  if (scope === 'html') return ['html'];
@@ -18,31 +17,31 @@ export class Classes {
18
17
  return [];
19
18
  }
20
19
 
21
- get selector(): string {
20
+ protected get selector(): string {
22
21
  return this.selectors.join(',');
23
22
  }
24
23
 
25
- get targets(): HTMLElement[] {
24
+ protected get targets(): HTMLElement[] {
26
25
  if (!this.selector.trim()) return [];
27
26
  return queryAll(this.selector) as HTMLElement[];
28
27
  }
29
28
 
30
- public add(...classes: string[]): void {
29
+ add(...classes: string[]): void {
31
30
  this.targets.forEach((target) => target.classList.add(...classes));
32
31
  }
33
32
 
34
- public remove(...classes: string[]): void {
33
+ remove(...classes: string[]): void {
35
34
  this.targets.forEach((target) => target.classList.remove(...classes));
36
35
  }
37
36
 
38
- public clear(): void {
37
+ clear(): void {
39
38
  this.targets.forEach((target) => {
40
39
  const remove = target.className.split(' ').filter((c) => this.isSwupClass(c));
41
40
  target.classList.remove(...remove);
42
41
  });
43
42
  }
44
43
 
45
- private isSwupClass(className: string): boolean {
44
+ protected isSwupClass(className: string): boolean {
46
45
  return this.swupClasses.some((c) => className.startsWith(c));
47
46
  }
48
47
  }
@@ -326,7 +326,7 @@ export class Hooks {
326
326
  * @param registrations The registrations (handler + options) to execute
327
327
  * @param args Arguments to pass to the handler
328
328
  */
329
- private async run<T extends HookName>(
329
+ protected async run<T extends HookName>(
330
330
  registrations: HookRegistration<T>[],
331
331
  args?: HookArguments<T>
332
332
  ): Promise<any> {
@@ -346,7 +346,7 @@ export class Hooks {
346
346
  * @param registrations The registrations (handler + options) to execute
347
347
  * @param args Arguments to pass to the handler
348
348
  */
349
- private runSync<T extends HookName>(
349
+ protected runSync<T extends HookName>(
350
350
  registrations: HookRegistration<T>[],
351
351
  args?: HookArguments<T>
352
352
  ): any[] {
@@ -374,7 +374,7 @@ export class Hooks {
374
374
  * @returns An object with the handlers sorted into `before` and `after` arrays,
375
375
  * as well as a flag indicating if the original handler was replaced
376
376
  */
377
- private getHandlers<T extends HookName>(hook: T, defaultHandler?: Handler<T>) {
377
+ protected getHandlers<T extends HookName>(hook: T, defaultHandler?: Handler<T>) {
378
378
  const ledger = this.get(hook);
379
379
  if (!ledger) {
380
380
  return { found: false, before: [], handler: [], after: [], replaced: false };
@@ -422,7 +422,7 @@ export class Hooks {
422
422
  * @param b The other registration object to compare with
423
423
  * @returns The sort direction
424
424
  */
425
- private sortRegistrations<T extends HookName>(
425
+ protected sortRegistrations<T extends HookName>(
426
426
  a: HookRegistration<T>,
427
427
  b: HookRegistration<T>
428
428
  ): number {
@@ -435,7 +435,7 @@ export class Hooks {
435
435
  * Dispatch a custom event on the `document` for a hook. Prefixed with `swup:`
436
436
  * @param hook Name of the hook.
437
437
  */
438
- private dispatchDomEvent<T extends HookName>(hook: T, args?: HookArguments<T>): void {
438
+ protected dispatchDomEvent<T extends HookName>(hook: T, args?: HookArguments<T>): void {
439
439
  const detail = { hook, args, visit: this.swup.visit };
440
440
  document.dispatchEvent(new CustomEvent(`swup:${hook}`, { detail }));
441
441
  }
@@ -1,4 +1,4 @@
1
- import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest';
1
+ import { describe, expect, it, vi, afterEach } from 'vitest';
2
2
  import Swup from '../../Swup.js';
3
3
  import type { PageData } from '../fetchPage.js';
4
4
  import { JSDOM } from 'jsdom';