swup 4.6.1 → 4.7.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.
- 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 +5 -2
- package/dist/types/Swup.d.ts.map +1 -1
- package/dist/types/helpers/delegateEvent.d.ts.map +1 -1
- package/dist/types/helpers/getCurrentUrl.d.ts +1 -1
- package/dist/types/helpers/getCurrentUrl.d.ts.map +1 -1
- package/dist/types/helpers/matchPath.d.ts.map +1 -1
- package/dist/types/modules/Visit.d.ts +2 -0
- package/dist/types/modules/Visit.d.ts.map +1 -1
- package/dist/types/modules/awaitAnimations.d.ts +10 -1
- package/dist/types/modules/awaitAnimations.d.ts.map +1 -1
- package/dist/types/modules/navigate.d.ts.map +1 -1
- package/dist/types/modules/renderPage.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +7 -0
- package/dist/types/utils/index.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/Swup.ts +7 -3
- package/src/modules/Visit.ts +4 -2
- package/src/modules/awaitAnimations.ts +15 -22
- package/src/modules/navigate.ts +11 -17
- package/src/modules/renderPage.ts +5 -4
- package/src/utils/index.ts +14 -0
package/dist/types/Swup.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type DelegateEvent } from 'delegate-it';
|
|
2
|
+
import { Location } from './helpers.js';
|
|
2
3
|
import { type DelegateEventUnsubscribe } from './helpers/delegateEvent.js';
|
|
3
4
|
import { Cache } from './modules/Cache.js';
|
|
4
5
|
import { Classes } from './modules/Classes.js';
|
|
@@ -61,8 +62,10 @@ export default class Swup {
|
|
|
61
62
|
readonly hooks: Hooks;
|
|
62
63
|
/** Animation class manager */
|
|
63
64
|
readonly classes: Classes;
|
|
64
|
-
/**
|
|
65
|
-
|
|
65
|
+
/** Location of the currently visible page */
|
|
66
|
+
location: Location;
|
|
67
|
+
/** URL of the currently visible page @deprecated Use swup.location.url instead */
|
|
68
|
+
get currentPageUrl(): string;
|
|
66
69
|
/** Index of the current history entry */
|
|
67
70
|
protected currentHistoryIndex: number;
|
|
68
71
|
/** Delegated event subscription handle */
|
package/dist/types/Swup.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Swup.d.ts","sourceRoot":"","sources":["../../src/Swup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Swup.d.ts","sourceRoot":"","sources":["../../src/Swup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAIjD,OAAO,EAAgC,QAAQ,EAAuB,MAAM,cAAc,CAAC;AAC3F,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAE3E,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,KAAK,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,KAAK,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACjG,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAMnD,OAAO,EAAO,KAAK,EAAE,UAAU,EAAE,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE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AmB;IAC5C,+CAA+C;IAC/C,gBAAgB,gDAAoB;IAEpC,+BAA+B;IAC/B,aAAa;;iBAAiB;IAC9B,0CAA0C;IAC1C,UAAU,oBAAc;IACxB,qDAAqD;IACrD,SAAS,CAAC,iBAAiB,2BAAqB;gBAEpC,OAAO,GAAE,OAAO,CAAC,OAAO,CAAM;IAiB1C,6DAA6D;IACvD,MAAM;IAwCZ,gEAAgE;IAC1D,OAAO;IAwBb,uFAAuF;IACvF,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,GAAE;QAAE,EAAE,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAA;KAAO;IAsBnF,SAAS,CAAC,eAAe,CAAC,KAAK,EAAE,aAAa,CAAC,UAAU,CAAC;IAiE1D,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,aAAa;IA4C7C,iFAAiF;IACjF,SAAS,CAAC,wBAAwB,CAAC,SAAS,EAAE,OAAO;CAMrD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delegateEvent.d.ts","sourceRoot":"","sources":["../../../src/helpers/delegateEvent.ts"],"names":[],"mappings":"AAAA,OAAiB,EAChB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EAEpB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAEpE,MAAM,MAAM,wBAAwB,GAAG;IACtC,OAAO,EAAE,MAAM,IAAI,CAAC;CACpB,CAAC;AAEF,2CAA2C;AAC3C,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"delegateEvent.d.ts","sourceRoot":"","sources":["../../../src/helpers/delegateEvent.ts"],"names":[],"mappings":"AAAA,OAAiB,EAChB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EAEpB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAEpE,MAAM,MAAM,wBAAwB,GAAG;IACtC,OAAO,EAAE,MAAM,IAAI,CAAC;CACpB,CAAC;AAEF,2CAA2C;AAC3C,eAAO,MAAM,aAAa,6LAKf,QAAQ,QACZ,MAAM,YACF,qBAAqB,2BAA2B,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,YACnE,eAAe,KACvB,wBAKF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCurrentUrl.d.ts","sourceRoot":"","sources":["../../../src/helpers/getCurrentUrl.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,eAAO,MAAM,aAAa
|
|
1
|
+
{"version":3,"file":"getCurrentUrl.d.ts","sourceRoot":"","sources":["../../../src/helpers/getCurrentUrl.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,eAAO,MAAM,aAAa,cAAc;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,KAAQ,MAEjE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matchPath.d.ts","sourceRoot":"","sources":["../../../src/helpers/matchPath.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,IAAI,EACJ,YAAY,EACZ,qBAAqB,EACrB,uBAAuB,EACvB,aAAa,EACb,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC;AAErB,oFAAoF;AACpF,eAAO,MAAM,SAAS,oCACf,IAAI,YACA,YAAY,GAAG,qBAAqB,GAAG,uBAAuB,
|
|
1
|
+
{"version":3,"file":"matchPath.d.ts","sourceRoot":"","sources":["../../../src/helpers/matchPath.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,IAAI,EACJ,YAAY,EACZ,qBAAqB,EACrB,uBAAuB,EACvB,aAAa,EACb,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC;AAErB,oFAAoF;AACpF,eAAO,MAAM,SAAS,oCACf,IAAI,YACA,YAAY,GAAG,qBAAqB,GAAG,uBAAuB,KACtE,cAAc,CAAC,CAMjB,CAAC"}
|
|
@@ -5,6 +5,8 @@ import type { HistoryAction, HistoryDirection } from './navigate.js';
|
|
|
5
5
|
export interface VisitFrom {
|
|
6
6
|
/** The URL of the previous page */
|
|
7
7
|
url: string;
|
|
8
|
+
/** The hash of the previous page */
|
|
9
|
+
hash?: string;
|
|
8
10
|
}
|
|
9
11
|
export interface VisitTo {
|
|
10
12
|
/** The URL of the next page */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Visit.d.ts","sourceRoot":"","sources":["../../../src/modules/Visit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAErE,kDAAkD;AAGlD,MAAM,WAAW,SAAS;IACzB,mCAAmC;IACnC,GAAG,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"Visit.d.ts","sourceRoot":"","sources":["../../../src/modules/Visit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAErE,kDAAkD;AAGlD,MAAM,WAAW,SAAS;IACzB,mCAAmC;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,OAAO;IACvB,+BAA+B;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,gCAAgC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wCAAwC;IACxC,IAAI,CAAC,EAAE,MAAM,C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;IACzC,EAAE,EAAE,MAAM,CAAC;IAGX,wCAAwC;IACxC,IAAI,EAAE,SAAS,CAAC;IAChB,oCAAoC;IACpC,EAAE,EAAE,OAAO,CAAC;IACZ,mDAAmD;IACnD,UAAU,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAClC,kDAAkD;IAClD,SAAS,EAAE,cAAc,CAAC;IAC1B,gCAAgC;IAChC,OAAO,EAAE,YAAY,CAAC;IACtB,oCAAoC;IACpC,KAAK,EAAE,UAAU,CAAC;IAClB,6CAA6C;IAC7C,OAAO,EAAE,YAAY,CAAC;IACtB,oCAAoC;IACpC,MAAM,EAAE,WAAW,CAAC;gBAER,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,gBAAgB;IA2CjD,8DAA8D;IAC9D,IAAI,IAAI,IAAI,OAAO,CAElB;CACD;AAED,iCAAiC;AACjC,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,gBAAgB,GAAG,KAAK,CAExE"}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import type Swup from '../Swup.js';
|
|
2
2
|
import type { Options } from '../Swup.js';
|
|
3
|
+
declare const TRANSITION = "transition";
|
|
4
|
+
declare const ANIMATION = "animation";
|
|
5
|
+
type AnimationType = typeof TRANSITION | typeof ANIMATION;
|
|
6
|
+
type AnimationProperty = 'Delay' | 'Duration';
|
|
7
|
+
type AnimationStyleKey = `${AnimationType}${AnimationProperty}` | 'transitionProperty';
|
|
3
8
|
export type AnimationDirection = 'in' | 'out';
|
|
4
9
|
/**
|
|
5
10
|
* Return a Promise that resolves when all CSS animations and transitions
|
|
6
11
|
* are done on the page. Filters by selector or takes elements directly.
|
|
7
12
|
*/
|
|
8
|
-
export declare function awaitAnimations(this: Swup, {
|
|
13
|
+
export declare function awaitAnimations(this: Swup, { selector, elements }: {
|
|
9
14
|
selector: Options['animationSelector'];
|
|
10
15
|
elements?: NodeListOf<HTMLElement> | HTMLElement[];
|
|
11
16
|
}): Promise<void>;
|
|
17
|
+
export declare function getStyleProperties(styles: CSSStyleDeclaration, key: AnimationStyleKey): string[];
|
|
18
|
+
export declare function calculateTimeout(delays: string[], durations: string[]): number;
|
|
19
|
+
export declare function toMs(time: string): number;
|
|
20
|
+
export {};
|
|
12
21
|
//# sourceMappingURL=awaitAnimations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"awaitAnimations.d.ts","sourceRoot":"","sources":["../../../src/modules/awaitAnimations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"awaitAnimations.d.ts","sourceRoot":"","sources":["../../../src/modules/awaitAnimations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,QAAA,MAAM,UAAU,eAAe,CAAC;AAChC,QAAA,MAAM,SAAS,cAAc,CAAC;AAE9B,KAAK,aAAa,GAAG,OAAO,UAAU,GAAG,OAAO,SAAS,CAAC;AAE1D,KAAK,iBAAiB,GAAG,OAAO,GAAG,UAAU,CAAC;AAC9C,KAAK,iBAAiB,GAAG,GAAG,aAAa,GAAG,iBAAiB,EAAE,GAAG,oBAAoB,CAAC;AAEvF,MAAM,MAAM,kBAAkB,GAAG,IAAI,GAAG,KAAK,CAAC;AAE9C;;;GAGG;AACH,wBAAsB,eAAe,CACpC,IAAI,EAAE,IAAI,EACV,EACC,QAAQ,EACR,QAAQ,EACR,EAAE;IACF,QAAQ,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACvC,QAAQ,CAAC,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,WAAW,EAAE,CAAC;CACnD,GACC,OAAO,CAAC,IAAI,CAAC,CA+Bf;AA2ED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,mBAAmB,EAAE,GAAG,EAAE,iBAAiB,GAAG,MAAM,EAAE,CAEhG;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,CAM9E;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigate.d.ts","sourceRoot":"","sources":["../../../src/modules/navigate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAc,KAAK,YAAY,EAAiB,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,KAAK,EAAc,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"navigate.d.ts","sourceRoot":"","sources":["../../../src/modules/navigate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAc,KAAK,YAAY,EAAiB,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,KAAK,EAAc,MAAM,YAAY,CAAC;AAI3E,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,SAAS,CAAC;AAC/C,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,WAAW,CAAC;AACxD,MAAM,MAAM,sBAAsB,GAAG,QAAQ,GAAG,UAAU,CAAC;AAC3D,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAEtE,wCAAwC;AACxC,KAAK,iBAAiB,GAAG;IACxB,sDAAsD;IACtD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qIAAqI;IACrI,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,iEAAiE;IACjE,KAAK,CAAC,EAAE,YAAY,CAAC;CACrB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,QAAQ,CACvB,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,iBAAiB,GAAG,YAAiB,EAC9C,IAAI,GAAE,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAM,QAgBvC;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,iBAAiB,CACtC,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,EACZ,OAAO,GAAE,iBAAiB,GAAG,YAAiB,GAC5C,OAAO,CAAC,IAAI,CAAC,CAuKf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderPage.d.ts","sourceRoot":"","sources":["../../../src/modules/renderPage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAc,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAEpD;;GAEG;AACH,eAAO,MAAM,UAAU,SAAyB,IAAI,SAAS,KAAK,QAAQ,QAAQ,KAAG,QAAQ,IAAI,
|
|
1
|
+
{"version":3,"file":"renderPage.d.ts","sourceRoot":"","sources":["../../../src/modules/renderPage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAc,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAEpD;;GAEG;AACH,eAAO,MAAM,UAAU,SAAyB,IAAI,SAAS,KAAK,QAAQ,QAAQ,KAAG,QAAQ,IAAI,CA0ChG,CAAC"}
|
|
@@ -13,4 +13,11 @@ export declare function runAsPromise(func: Function, args?: unknown[]): Promise<
|
|
|
13
13
|
* @see https://stackoverflow.com/a/21665117/3759615
|
|
14
14
|
*/
|
|
15
15
|
export declare function forceReflow(element?: HTMLElement): void;
|
|
16
|
+
/**
|
|
17
|
+
* Read data attribute from closest element with that attribute.
|
|
18
|
+
*
|
|
19
|
+
* Returns `undefined` if no element is found or attribute is missing.
|
|
20
|
+
* Returns `true` if attribute is present without a value.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getContextualAttr(el: Element | undefined, attr: string): string | boolean | undefined;
|
|
16
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,eAAO,MAAM,KAAK,aAAc,MAAM,YAAW,QAAQ,GAAG,OAAO,uBAElE,CAAC;AAEF,0CAA0C;AAC1C,eAAO,MAAM,QAAQ,aACV,MAAM,YACP,QAAQ,GAAG,OAAO,KACzB,WAAW,EAEb,CAAC;AAEF,gEAAgE;AAChE,eAAO,MAAM,QAAQ,QAAO,QAAQ,IAAI,CAQvC,CAAC;AAEF,oDAAoD;AACpD,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAMhE;AAED,wFAAwF;AAExF,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CASnF;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI,CAGvD"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,eAAO,MAAM,KAAK,aAAc,MAAM,YAAW,QAAQ,GAAG,OAAO,uBAElE,CAAC;AAEF,0CAA0C;AAC1C,eAAO,MAAM,QAAQ,aACV,MAAM,YACP,QAAQ,GAAG,OAAO,KACzB,WAAW,EAEb,CAAC;AAEF,gEAAgE;AAChE,eAAO,MAAM,QAAQ,QAAO,QAAQ,IAAI,CAQvC,CAAC;AAEF,oDAAoD;AACpD,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAMhE;AAED,wFAAwF;AAExF,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CASnF;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI,CAGvD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAChC,EAAE,EAAE,OAAO,GAAG,SAAS,EACvB,IAAI,EAAE,MAAM,GACV,MAAM,GAAG,OAAO,GAAG,SAAS,CAG9B"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swup",
|
|
3
3
|
"amdName": "Swup",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.7.0",
|
|
5
5
|
"description": "Versatile and extensible page transition library for server-rendered websites",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"source": "./src/Swup.ts",
|
|
@@ -70,18 +70,18 @@
|
|
|
70
70
|
"@swup/prettier-config": "^1.0.0",
|
|
71
71
|
"@types/dom-view-transitions": "^1.0.2",
|
|
72
72
|
"@types/jsdom": "^21.1.1",
|
|
73
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
74
|
-
"@typescript-eslint/parser": "^
|
|
73
|
+
"@typescript-eslint/eslint-plugin": "^7.13.0",
|
|
74
|
+
"@typescript-eslint/parser": "^7.13.0",
|
|
75
75
|
"eslint": "^8.46.0",
|
|
76
76
|
"eslint-config-prettier": "^9.0.0",
|
|
77
|
-
"eslint-plugin-compat": "^
|
|
77
|
+
"eslint-plugin-compat": "^5.0.0",
|
|
78
78
|
"eslint-plugin-ecmascript-compat": "^3.2.0",
|
|
79
79
|
"eslint-plugin-prettier": "^5.0.1",
|
|
80
|
-
"husky": "^
|
|
80
|
+
"husky": "^9.0.11",
|
|
81
81
|
"istanbul-lib-coverage": "^3.2.0",
|
|
82
|
-
"jsdom": "^
|
|
82
|
+
"jsdom": "^24.1.0",
|
|
83
83
|
"microbundle": "^0.15.0",
|
|
84
|
-
"nyc": "^
|
|
84
|
+
"nyc": "^17.0.0",
|
|
85
85
|
"prettier": "^3.1.0",
|
|
86
86
|
"serve": "^14.2.1",
|
|
87
87
|
"typed-query-selector": "^2.11.0",
|
package/src/Swup.ts
CHANGED
|
@@ -93,8 +93,12 @@ export default class Swup {
|
|
|
93
93
|
readonly hooks: Hooks;
|
|
94
94
|
/** Animation class manager */
|
|
95
95
|
readonly classes: Classes;
|
|
96
|
-
/**
|
|
97
|
-
|
|
96
|
+
/** Location of the currently visible page */
|
|
97
|
+
location: Location = Location.fromUrl(window.location.href);
|
|
98
|
+
/** URL of the currently visible page @deprecated Use swup.location.url instead */
|
|
99
|
+
get currentPageUrl(): string {
|
|
100
|
+
return this.location.url;
|
|
101
|
+
}
|
|
98
102
|
/** Index of the current history entry */
|
|
99
103
|
protected currentHistoryIndex: number;
|
|
100
104
|
/** Delegated event subscription handle */
|
|
@@ -322,7 +326,7 @@ export default class Swup {
|
|
|
322
326
|
}
|
|
323
327
|
|
|
324
328
|
// Exit early if the resolved path hasn't changed
|
|
325
|
-
if (this.isSameResolvedUrl(getCurrentUrl(), this.
|
|
329
|
+
if (this.isSameResolvedUrl(getCurrentUrl(), this.location.url)) {
|
|
326
330
|
return;
|
|
327
331
|
}
|
|
328
332
|
|
package/src/modules/Visit.ts
CHANGED
|
@@ -8,6 +8,8 @@ import type { HistoryAction, HistoryDirection } from './navigate.js';
|
|
|
8
8
|
export interface VisitFrom {
|
|
9
9
|
/** The URL of the previous page */
|
|
10
10
|
url: string;
|
|
11
|
+
/** The hash of the previous page */
|
|
12
|
+
hash?: string;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
export interface VisitTo {
|
|
@@ -114,11 +116,11 @@ export class Visit {
|
|
|
114
116
|
scroll: VisitScroll;
|
|
115
117
|
|
|
116
118
|
constructor(swup: Swup, options: VisitInitOptions) {
|
|
117
|
-
const { to, from
|
|
119
|
+
const { to, from, hash, el, event } = options;
|
|
118
120
|
|
|
119
121
|
this.id = Math.random();
|
|
120
122
|
this.state = VisitState.CREATED;
|
|
121
|
-
this.from = { url: from };
|
|
123
|
+
this.from = { url: from ?? swup.location.url, hash: swup.location.hash };
|
|
122
124
|
this.to = { url: to, hash };
|
|
123
125
|
this.containers = swup.options.containers;
|
|
124
126
|
this.animation = {
|
|
@@ -5,10 +5,10 @@ import type { Options } from '../Swup.js';
|
|
|
5
5
|
const TRANSITION = 'transition';
|
|
6
6
|
const ANIMATION = 'animation';
|
|
7
7
|
|
|
8
|
-
type
|
|
9
|
-
type
|
|
10
|
-
type
|
|
11
|
-
type
|
|
8
|
+
type AnimationType = typeof TRANSITION | typeof ANIMATION;
|
|
9
|
+
type AnimationEndEvent = `${AnimationType}end`;
|
|
10
|
+
type AnimationProperty = 'Delay' | 'Duration';
|
|
11
|
+
type AnimationStyleKey = `${AnimationType}${AnimationProperty}` | 'transitionProperty';
|
|
12
12
|
|
|
13
13
|
export type AnimationDirection = 'in' | 'out';
|
|
14
14
|
|
|
@@ -19,8 +19,8 @@ export type AnimationDirection = 'in' | 'out';
|
|
|
19
19
|
export async function awaitAnimations(
|
|
20
20
|
this: Swup,
|
|
21
21
|
{
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
selector,
|
|
23
|
+
elements
|
|
24
24
|
}: {
|
|
25
25
|
selector: Options['animationSelector'];
|
|
26
26
|
elements?: NodeListOf<HTMLElement> | HTMLElement[];
|
|
@@ -58,7 +58,7 @@ export async function awaitAnimations(
|
|
|
58
58
|
await Promise.all(awaitedAnimations);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
function awaitAnimationsOnElement(element:
|
|
61
|
+
function awaitAnimationsOnElement(element: HTMLElement): Promise<void> | false {
|
|
62
62
|
const { type, timeout, propCount } = getTransitionInfo(element);
|
|
63
63
|
|
|
64
64
|
// Resolve immediately if no transition defined
|
|
@@ -67,7 +67,7 @@ function awaitAnimationsOnElement(element: Element): Promise<void> | false {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
return new Promise((resolve) => {
|
|
70
|
-
const endEvent = `${type}end`;
|
|
70
|
+
const endEvent: AnimationEndEvent = `${type}end`;
|
|
71
71
|
const startTime = performance.now();
|
|
72
72
|
let propsTransitioned = 0;
|
|
73
73
|
|
|
@@ -76,16 +76,12 @@ function awaitAnimationsOnElement(element: Element): Promise<void> | false {
|
|
|
76
76
|
resolve();
|
|
77
77
|
};
|
|
78
78
|
|
|
79
|
-
const onEnd
|
|
79
|
+
const onEnd = (event: TransitionEvent | AnimationEvent) => {
|
|
80
80
|
// Skip transitions on child elements
|
|
81
81
|
if (event.target !== element) {
|
|
82
82
|
return;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
if (!isTransitionOrAnimationEvent(event)) {
|
|
86
|
-
throw new Error('Not a transition or animation event.');
|
|
87
|
-
}
|
|
88
|
-
|
|
89
85
|
// Skip transitions that happened before we started listening
|
|
90
86
|
const elapsedTime = (performance.now() - startTime) / 1000;
|
|
91
87
|
if (elapsedTime < event.elapsedTime) {
|
|
@@ -109,17 +105,18 @@ function awaitAnimationsOnElement(element: Element): Promise<void> | false {
|
|
|
109
105
|
}
|
|
110
106
|
|
|
111
107
|
function getTransitionInfo(element: Element) {
|
|
112
|
-
const styles = window.getComputedStyle(element)
|
|
108
|
+
const styles = window.getComputedStyle(element);
|
|
113
109
|
|
|
114
110
|
const transitionDelays = getStyleProperties(styles, `${TRANSITION}Delay`);
|
|
115
111
|
const transitionDurations = getStyleProperties(styles, `${TRANSITION}Duration`);
|
|
116
112
|
const transitionTimeout = calculateTimeout(transitionDelays, transitionDurations);
|
|
113
|
+
|
|
117
114
|
const animationDelays = getStyleProperties(styles, `${ANIMATION}Delay`);
|
|
118
115
|
const animationDurations = getStyleProperties(styles, `${ANIMATION}Duration`);
|
|
119
116
|
const animationTimeout = calculateTimeout(animationDelays, animationDurations);
|
|
120
117
|
|
|
121
118
|
const timeout = Math.max(transitionTimeout, animationTimeout);
|
|
122
|
-
const type =
|
|
119
|
+
const type: AnimationType | null =
|
|
123
120
|
timeout > 0 ? (transitionTimeout > animationTimeout ? TRANSITION : ANIMATION) : null;
|
|
124
121
|
const propCount = type
|
|
125
122
|
? type === TRANSITION
|
|
@@ -134,15 +131,11 @@ function getTransitionInfo(element: Element) {
|
|
|
134
131
|
};
|
|
135
132
|
}
|
|
136
133
|
|
|
137
|
-
function
|
|
138
|
-
return [`${TRANSITION}end`, `${ANIMATION}end`].includes(event.type);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function getStyleProperties(styles: AnimationStyleDeclarations, key: AnimationStyleKeys): string[] {
|
|
134
|
+
export function getStyleProperties(styles: CSSStyleDeclaration, key: AnimationStyleKey): string[] {
|
|
142
135
|
return (styles[key] || '').split(', ');
|
|
143
136
|
}
|
|
144
137
|
|
|
145
|
-
function calculateTimeout(delays: string[], durations: string[]): number {
|
|
138
|
+
export function calculateTimeout(delays: string[], durations: string[]): number {
|
|
146
139
|
while (delays.length < durations.length) {
|
|
147
140
|
delays = delays.concat(delays);
|
|
148
141
|
}
|
|
@@ -150,6 +143,6 @@ function calculateTimeout(delays: string[], durations: string[]): number {
|
|
|
150
143
|
return Math.max(...durations.map((duration, i) => toMs(duration) + toMs(delays[i])));
|
|
151
144
|
}
|
|
152
145
|
|
|
153
|
-
function toMs(time: string): number {
|
|
146
|
+
export function toMs(time: string): number {
|
|
154
147
|
return parseFloat(time) * 1000;
|
|
155
148
|
}
|
package/src/modules/navigate.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import type Swup from '../Swup.js';
|
|
2
2
|
import { FetchError, type FetchOptions, type PageData } from './fetchPage.js';
|
|
3
3
|
import { type VisitInitOptions, type Visit, VisitState } from './Visit.js';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
updateHistoryRecord,
|
|
7
|
-
getCurrentUrl,
|
|
8
|
-
Location,
|
|
9
|
-
classify
|
|
10
|
-
} from '../helpers.js';
|
|
4
|
+
import { createHistoryRecord, updateHistoryRecord, Location, classify } from '../helpers.js';
|
|
5
|
+
import { getContextualAttr } from '../utils.js';
|
|
11
6
|
|
|
12
7
|
export type HistoryAction = 'push' | 'replace';
|
|
13
8
|
export type HistoryDirection = 'forwards' | 'backwards';
|
|
@@ -88,7 +83,7 @@ export async function performNavigation(
|
|
|
88
83
|
this.visit = visit;
|
|
89
84
|
|
|
90
85
|
const { el } = visit.trigger;
|
|
91
|
-
options.referrer = options.referrer || this.
|
|
86
|
+
options.referrer = options.referrer || this.location.url;
|
|
92
87
|
|
|
93
88
|
if (options.animate === false) {
|
|
94
89
|
visit.animation.animate = false;
|
|
@@ -100,14 +95,14 @@ export async function performNavigation(
|
|
|
100
95
|
}
|
|
101
96
|
|
|
102
97
|
// Get history action from option or attribute on trigger element
|
|
103
|
-
const history = options.history || el
|
|
104
|
-
if (history && ['push', 'replace'].includes(history)) {
|
|
98
|
+
const history = options.history || getContextualAttr(el, 'data-swup-history');
|
|
99
|
+
if (typeof history === 'string' && ['push', 'replace'].includes(history)) {
|
|
105
100
|
visit.history.action = history as HistoryAction;
|
|
106
101
|
}
|
|
107
102
|
|
|
108
103
|
// Get custom animation name from option or attribute on trigger element
|
|
109
|
-
const animation = options.animation || el
|
|
110
|
-
if (animation) {
|
|
104
|
+
const animation = options.animation || getContextualAttr(el, 'data-swup-animation');
|
|
105
|
+
if (typeof animation === 'string') {
|
|
111
106
|
visit.animation.name = animation;
|
|
112
107
|
}
|
|
113
108
|
|
|
@@ -123,6 +118,7 @@ export async function performNavigation(
|
|
|
123
118
|
|
|
124
119
|
try {
|
|
125
120
|
await this.hooks.call('visit:start', visit, undefined);
|
|
121
|
+
|
|
126
122
|
visit.state = VisitState.STARTED;
|
|
127
123
|
|
|
128
124
|
// Begin loading page
|
|
@@ -150,18 +146,16 @@ export async function performNavigation(
|
|
|
150
146
|
});
|
|
151
147
|
|
|
152
148
|
// Create/update history record if this is not a popstate call or leads to the same URL
|
|
149
|
+
const newUrl = visit.to.url + visit.to.hash;
|
|
153
150
|
if (!visit.history.popstate) {
|
|
154
|
-
|
|
155
|
-
const newUrl = visit.to.url + visit.to.hash;
|
|
156
|
-
if (visit.history.action === 'replace' || visit.to.url === this.currentPageUrl) {
|
|
151
|
+
if (visit.history.action === 'replace' || visit.to.url === this.location.url) {
|
|
157
152
|
updateHistoryRecord(newUrl);
|
|
158
153
|
} else {
|
|
159
154
|
this.currentHistoryIndex++;
|
|
160
155
|
createHistoryRecord(newUrl, { index: this.currentHistoryIndex });
|
|
161
156
|
}
|
|
162
157
|
}
|
|
163
|
-
|
|
164
|
-
this.currentPageUrl = getCurrentUrl();
|
|
158
|
+
this.location = Location.fromUrl(newUrl);
|
|
165
159
|
|
|
166
160
|
// Mark visit type with classes
|
|
167
161
|
if (visit.history.popstate) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { updateHistoryRecord, getCurrentUrl, classify } from '../helpers.js';
|
|
1
|
+
import { updateHistoryRecord, getCurrentUrl, classify, Location } from '../helpers.js';
|
|
2
2
|
import type Swup from '../Swup.js';
|
|
3
3
|
import type { PageData } from './fetchPage.js';
|
|
4
4
|
import { VisitState, type Visit } from './Visit.js';
|
|
@@ -17,8 +17,9 @@ export const renderPage = async function (this: Swup, visit: Visit, page: PageDa
|
|
|
17
17
|
// update state if the url was redirected
|
|
18
18
|
if (!this.isSameResolvedUrl(getCurrentUrl(), url)) {
|
|
19
19
|
updateHistoryRecord(url);
|
|
20
|
-
this.
|
|
21
|
-
visit.to.url = this.
|
|
20
|
+
this.location = Location.fromUrl(url);
|
|
21
|
+
visit.to.url = this.location.url;
|
|
22
|
+
visit.to.hash = this.location.hash;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
// replace content: allow handlers and plugins to overwrite paga data and containers
|
|
@@ -46,5 +47,5 @@ export const renderPage = async function (this: Swup, visit: Visit, page: PageDa
|
|
|
46
47
|
return this.scrollToContent(visit);
|
|
47
48
|
});
|
|
48
49
|
|
|
49
|
-
await this.hooks.call('page:view', visit, { url: this.
|
|
50
|
+
await this.hooks.call('page:view', visit, { url: this.location.url, title: document.title });
|
|
50
51
|
};
|
package/src/utils/index.ts
CHANGED
|
@@ -52,3 +52,17 @@ export function forceReflow(element?: HTMLElement): void {
|
|
|
52
52
|
element = element || document.body;
|
|
53
53
|
element?.getBoundingClientRect();
|
|
54
54
|
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Read data attribute from closest element with that attribute.
|
|
58
|
+
*
|
|
59
|
+
* Returns `undefined` if no element is found or attribute is missing.
|
|
60
|
+
* Returns `true` if attribute is present without a value.
|
|
61
|
+
*/
|
|
62
|
+
export function getContextualAttr(
|
|
63
|
+
el: Element | undefined,
|
|
64
|
+
attr: string
|
|
65
|
+
): string | boolean | undefined {
|
|
66
|
+
const target = el?.closest(`[${attr}]`);
|
|
67
|
+
return target?.hasAttribute(attr) ? target?.getAttribute(attr) || true : undefined;
|
|
68
|
+
}
|