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
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
8
|
-
|
|
9
|
-
var _helpers = require('../helpers');
|
|
10
|
-
|
|
11
|
-
var renderPage = function renderPage(page, popstate) {
|
|
12
|
-
var _this = this;
|
|
13
|
-
|
|
14
|
-
document.documentElement.classList.remove('is-leaving');
|
|
15
|
-
|
|
16
|
-
var isCurrentPage = this.getCurrentUrl() === page.url;
|
|
17
|
-
if (!isCurrentPage) return;
|
|
18
|
-
|
|
19
|
-
// replace state in case the url was redirected
|
|
20
|
-
var url = new _helpers.Link(page.responseURL).getPath();
|
|
21
|
-
if (window.location.pathname !== url) {
|
|
22
|
-
window.history.replaceState({
|
|
23
|
-
url: url,
|
|
24
|
-
random: Math.random(),
|
|
25
|
-
source: 'swup'
|
|
26
|
-
}, document.title, url);
|
|
27
|
-
|
|
28
|
-
// save new record for redirected url
|
|
29
|
-
this.cache.cacheUrl(_extends({}, page, { url: url }));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// only add for non-popstate transitions
|
|
33
|
-
if (!popstate || this.options.animateHistoryBrowsing) {
|
|
34
|
-
document.documentElement.classList.add('is-rendering');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
this.triggerEvent('willReplaceContent', popstate);
|
|
38
|
-
// replace blocks
|
|
39
|
-
for (var i = 0; i < page.blocks.length; i++) {
|
|
40
|
-
document.body.querySelector('[data-swup="' + i + '"]').outerHTML = page.blocks[i];
|
|
41
|
-
}
|
|
42
|
-
// set title
|
|
43
|
-
document.title = page.title;
|
|
44
|
-
this.triggerEvent('contentReplaced', popstate);
|
|
45
|
-
this.triggerEvent('pageView', popstate);
|
|
46
|
-
|
|
47
|
-
// empty cache if it's disabled (because pages could be preloaded and stuff)
|
|
48
|
-
if (!this.options.cache) {
|
|
49
|
-
this.cache.empty();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// start animation IN
|
|
53
|
-
setTimeout(function () {
|
|
54
|
-
if (!popstate || _this.options.animateHistoryBrowsing) {
|
|
55
|
-
_this.triggerEvent('animationInStart');
|
|
56
|
-
document.documentElement.classList.remove('is-animating');
|
|
57
|
-
}
|
|
58
|
-
}, 10);
|
|
59
|
-
|
|
60
|
-
// handle end of animation
|
|
61
|
-
if (!popstate || this.options.animateHistoryBrowsing) {
|
|
62
|
-
var animationPromises = this.getAnimationPromises('in');
|
|
63
|
-
Promise.all(animationPromises).then(function () {
|
|
64
|
-
_this.triggerEvent('animationInDone');
|
|
65
|
-
_this.triggerEvent('transitionEnd', popstate);
|
|
66
|
-
_this.cleanupAnimationClasses();
|
|
67
|
-
});
|
|
68
|
-
} else {
|
|
69
|
-
this.triggerEvent('transitionEnd', popstate);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// reset scroll-to element
|
|
73
|
-
this.scrollToElement = null;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
exports.default = renderPage;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var triggerEvent = function triggerEvent(eventName, originalEvent) {
|
|
7
|
-
// call saved handlers with "on" method and pass originalEvent object if available
|
|
8
|
-
this._handlers[eventName].forEach(function (handler) {
|
|
9
|
-
try {
|
|
10
|
-
handler(originalEvent);
|
|
11
|
-
} catch (error) {
|
|
12
|
-
console.error(error);
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
// trigger event on document with prefix "swup:"
|
|
17
|
-
var event = new CustomEvent('swup:' + eventName, { detail: eventName });
|
|
18
|
-
document.dispatchEvent(event);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
exports.default = triggerEvent;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var updateTransition = function updateTransition(from, to, custom) {
|
|
7
|
-
// transition routes
|
|
8
|
-
this.transition = {
|
|
9
|
-
from: from,
|
|
10
|
-
to: to,
|
|
11
|
-
custom: custom
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
exports.default = updateTransition;
|
package/lib/utils/index.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var query = exports.query = function query(selector) {
|
|
7
|
-
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document;
|
|
8
|
-
|
|
9
|
-
if (typeof selector !== 'string') {
|
|
10
|
-
return selector;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return context.querySelector(selector);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
var queryAll = exports.queryAll = function queryAll(selector) {
|
|
17
|
-
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document;
|
|
18
|
-
|
|
19
|
-
if (typeof selector !== 'string') {
|
|
20
|
-
return selector;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return Array.prototype.slice.call(context.querySelectorAll(selector));
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
var escapeCssIdentifier = exports.escapeCssIdentifier = function escapeCssIdentifier(ident) {
|
|
27
|
-
if (window.CSS && window.CSS.escape) {
|
|
28
|
-
return CSS.escape(ident);
|
|
29
|
-
} else {
|
|
30
|
-
return ident;
|
|
31
|
-
}
|
|
32
|
-
};
|